Skip to content

Implement window.meta (MetaScript) runtime for WebView#1

Open
yumin-chen wants to merge 8 commits intomasterfrom
feat/metascript-runtime-v1-10457583970443846286
Open

Implement window.meta (MetaScript) runtime for WebView#1
yumin-chen wants to merge 8 commits intomasterfrom
feat/metascript-runtime-v1-10457583970443846286

Conversation

@yumin-chen
Copy link
Copy Markdown
Owner

This change introduces a MetaScript-inspired window.meta runtime to the webview library. It enables web applications to spawn child processes, interact with them via standard streams (stdin, stdout, stderr), and use pseudo-terminals (PTY) for interactive sessions.

Key components:

  • C++ SubprocessManager: Manages child process lifecycle, captures output using GLib/GTK event loops, and provides bindings for spawning and terminal control.
  • JavaScript Bridge: Injects a window.meta object into the WebView, providing an API that closely matches the requested specification, including support for ReadableStream based output.
  • PTY Support: Leverages forkpty on Linux to support interactive terminal applications like bash.
  • Examples and Tests: Provides a new example demonstrating the runtime and unit tests ensuring core spawning logic works correctly.

PR created automatically by Jules for task 10457583970443846286 started by @yumin-chen

- Added SubprocessManager in core/include/webview/meta.hh to handle process spawning (fork, forkpty) and I/O monitoring (GIOChannel, g_child_watch).
- Implemented JS bridge in core/include/webview/detail/meta_js.hh defining the window.meta API, Subprocess, and Terminal classes.
- Added a comprehensive demo in examples/meta_runtime.cc.
- Included unit tests in core/tests/src/meta_tests.cc for spawn and spawnSync.
- Updated CMakeLists.txt to include new components.

Co-authored-by: yumin-chen <10954839+yumin-chen@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

google-labs-jules bot and others added 3 commits March 29, 2026 15:49
- Added SubprocessManager in core/include/webview/meta.hh with POSIX spawn, PTY support, and GLib IO monitoring.
- Implemented robust handle-based process management to prevent race conditions and memory leaks.
- Used Base64 encoding for safe binary data transfer across the JS bridge.
- Added support for `cwd` in subprocess options.
- Provided a spec-compliant JS API in core/include/webview/detail/meta_js.hh, including ReadableStream support.
- Included comprehensive unit and functional tests in core/tests/src/meta_tests.cc.
- Added a demonstration example in examples/meta_runtime.cc.

Co-authored-by: yumin-chen <10954839+yumin-chen@users.noreply.github.com>
…or architecture

- Refactored SubprocessManager to centralize JS bindings via a `bind(webview&)` method.
- Implemented robust handle-based process management and I/O streaming.
- Used Base64 encoding for safe binary data transfer between C++ and JS.
- Improved JS API spec-compliance, including Terminal constructor and ReadableStream support.
- Added support for `cwd` and process cleanup to prevent memory leaks.
- Ensured portability across POSIX systems (Linux/macOS) with proper guards.
- Integrated comprehensive functional and unit tests.
- Provided a clean demonstration example in examples/meta_runtime.cc.

Co-authored-by: yumin-chen <10954839+yumin-chen@users.noreply.github.com>
- Introduced SubprocessManager as a host orchestrator providing native OS capacities.
- Implemented window.meta.cron.parse in JS for next-occurrence calculation.
- Added native cron job registration/removal using crontab (Linux).
- Enhanced process spawning with Base64 safety and handle-based management.
- Implemented spec-compliant Subprocess and Terminal classes.
- Added comprehensive unit and functional tests for Cron and Spawn.
- Provided a full demonstration example with CLI support for cron triggers.

Co-authored-by: yumin-chen <10954839+yumin-chen@users.noreply.github.com>
@yumin-chen yumin-chen force-pushed the master branch 5 times, most recently from e7da6b8 to cbbdee4 Compare March 29, 2026 20:49
google-labs-jules bot and others added 3 commits March 29, 2026 21:53
…e build script

- Initialized Bun project (@metascript/runtime).
- Extracted JS/TS runtime logic to `src/runtime.ts`.
- Created a C++ host orchestrator `src/host.cpp` that embeds the transpiled JS.
- Developed `build.ts` to bundle MetaScript source code and compile native binaries.
- Added comprehensive unit tests in `tests/spawn.test.ts` using `bun:test`.
- Maintained core OS capabilities (Process, PTY, Cron) in `core/include/webview/meta.hh`.

Co-authored-by: yumin-chen <10954839+yumin-chen@users.noreply.github.com>
…upport

- Introduced `SubprocessManager` in `meta.hh` as a host orchestrator for OS operations.
- Implemented `window.meta` JS API in `src/runtime.ts` with TypeScript support.
- Added native GUI component bridge (Linux/GTK) for Window, Button, and Layouts.
- Implemented OS-level Cron job registration (Linux/crontab) and calculation logic.
- Created `build.ts` for bundling MetaScript source into native binary executables.
- Added a full host orchestrator in `src/host.cpp` with Cron execution support.
- Ensured binary data safety across the WebView bridge using Base64 encoding.
- Included comprehensive unit and functional tests for the new runtime.

Co-authored-by: yumin-chen <10954839+yumin-chen@users.noreply.github.com>
Introduces AlloyScript (`window.Alloy`), a runtime for WebView that provides:
- Subprocess management (`spawn`, `spawnSync`) with PTY and async streaming.
- Inter-Process Communication (IPC) for spawned processes.
- Native GUI bridge for platform widgets (Windows, Buttons, Layouts).
- Cron job management for scheduled tasks.
- Bun-powered build system to bundle and embed JS into a C++ host.

The implementation includes a robust C++ backend (`meta.hh`), a TypeScript
runtime (`runtime.ts`), and a standalone host orchestrator. Verified with
unit tests and functional GUI/Cron demonstrations.

Co-authored-by: yumin-chen <10954839+yumin-chen@users.noreply.github.com>
@yumin-chen
Copy link
Copy Markdown
Owner Author

Explain to me the implementation details of bind =>it is not possible to bind globals instead of window?

@google-labs-jules
Copy link
Copy Markdown

Explain to me the implementation details of bind =>it is not possible to bind globals instead of window?

In the context of a WebView, window is the global execution context. The webview::bind method from the underlying C++ library works by injecting a proxy function into this global context. When you call w.bind("name", ...), it effectively creates window.name (which is also just name in the global scope). To keep the global namespace clean, I've used the __alloy_ prefix for these raw bindings and then encapsulated them within a single window.Alloy (or globalThis.Alloy) object in the TypeScript runtime. So while the 'entry point' for the bridge must be on the global object for the WebView to see it, the user-facing API is neatly namespaced.

…address PR feedback

- Updated runtime.ts to use `globalThis` instead of `window` for better compatibility with non-browser JS environments (like Web Workers or Node-like environments if applicable).
- Refined the explanation of the binding mechanism in response to PR comments.
- Ensured namespacing of internal bindings to keep the global scope clean.

Co-authored-by: yumin-chen <10954839+yumin-chen@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant