Skip to content

Implement MetaScript Cron Runtime#3

Draft
yumin-chen wants to merge 3 commits intomasterfrom
feat/metascript-cron-runtime-3096036330859335778
Draft

Implement MetaScript Cron Runtime#3
yumin-chen wants to merge 3 commits intomasterfrom
feat/metascript-cron-runtime-3096036330859335778

Conversation

@yumin-chen
Copy link
Copy Markdown
Owner

Implemented the window.meta (MetaScript) Cron runtime, providing cross-platform OS-level cron job scheduling and parsing.

Summary of changes:

  • Created metascript/cron_parser.hh for robust, thread-safe cron parsing.
  • Created metascript/cron.js for synchronous JS cron parsing API.
  • Created metascript/runtime.hh for the core MetaScript runtime and platform-specific backends.
  • Implemented crontab-based scheduling for Linux.
  • Implemented launchd-based scheduling for macOS with wildcard optimizations.
  • Implemented schtasks-based scheduling for Windows with POSIX compliance and 48-trigger limit handling.
  • Added ES module support for worker scripts using dynamic import() and Blob URLs.
  • Added comprehensive tests in metascript/tests/.
  • Added a demonstration example in examples/metascript_cron.cc.
  • Integrated tests into CMakeLists.txt.

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

This commit implements the `window.Meta` (MetaScript) runtime for cron job
management and expression parsing.

Key features:
- `Meta.cron.parse()`: Synchronous JS API for calculating next UTC matching time.
- `Meta.cron()`: OS-level job registration (crontab on Linux, launchd on macOS,
  schtasks on Windows).
- `Meta.cron.remove()`: Clean removal of registered jobs across platforms.
- CLI execution mode: `run` command for executing worker scripts with
  Cloudflare Workers-compatible `scheduled()` handlers.

Implementation details:
- Robust cron parser in both C++ and JavaScript.
- Security-focused design with shell/Windows argument escaping.
- Optimized registration logic to avoid Cartesian expansion of wildcards on
  macOS and Windows.
- Full POSIX compliance for Day-of-Month and Day-of-Week OR logic.
- Portable and thread-safe C++ time calculations.
- Comprehensive test suite and demonstration examples.
@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.

@yumin-chen yumin-chen force-pushed the master branch 5 times, most recently from e7da6b8 to cbbdee4 Compare March 29, 2026 20:49
This commit provides a comprehensive MetaScript (window.meta) runtime:
- Implement robust, cross-platform OS-level Cron support (Linux, macOS, Windows).
- Provide a synchronous JS API for cron parsing and an async API for registration.
- Initiate the project as a Bun project named @metascript/runtime.
- Draft a build script (scripts/build_metascript.ts) that uses Bun.build to
  transpile MetaScript and embed it into a C++ host program.
- Draft comprehensive SQLite tests using bun:test.

Key technical highlights:
- Optimized platform-specific cron registration (crontab, launchd, schtasks).
- POSIX-compliant cron parsing logic.
- Secure shell/Windows argument escaping.
- Dynamic module loading for worker scripts.
@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?

The bind implementation in the underlying webview library works by injecting a JavaScript bridge. When you call w.bind("name", ...), it creates a function on the window object in JavaScript.

Implementation flow:

  1. JS -> C++: When window.name() is called, it serializes the arguments and uses a platform-specific mechanism (like window.webkit.messageHandlers.external.postMessage on WebKit) to send a message to the C++ side.
  2. Dispatch: The C++ runtime parses the message, identifies the bound function name, and executes the associated lambda.
  3. C++ -> JS: Once the C++ function returns, it calls window.__webview__.onReply, which resolves the Promise originally returned to the caller in JS.

Regarding globals instead of window: In a browser environment (WebView), window is the global object. Any property added to window becomes a global variable. For MetaScript, I followed the pattern of exposing a single global Meta object to keep the global namespace clean, while using hidden window.__meta_cron_* bindings to bridge to C++.

This commit completes the implementation of the @metascript/runtime:
- **MetaScript Runtime**: A C++ wrapper for webview providing OS-level features.
- **Cron API**: Synchronous JS parsing and asynchronous OS-level registration
  (Linux crontab, macOS launchd, Windows Task Scheduler).
- **Security**: Robust shell/Windows argument escaping for all OS commands.
- **Bun Integration**: Initiated project as @metascript/runtime with bun init.
- **Build Tooling**: Drafted scripts/build_metascript.ts using Bun.build to
  transpile and embed source code into C++ host programs.
- **Testing**: Added comprehensive C++ cron parser tests and Bun-based
  SQLite tests (tests/sqlite.test.ts).
- **Documentation/Examples**: Included metascript_cron.cc and worker.ts demo.

Addressed PR feedback regarding the implementation details of 'bind' and global objects in WebView.
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