Skip to content

Implement AlloyScript Core Runtime#2

Open
yumin-chen wants to merge 4 commits intomasterfrom
alloy-cron-runtime-7001967282251718884
Open

Implement AlloyScript Core Runtime#2
yumin-chen wants to merge 4 commits intomasterfrom
alloy-cron-runtime-7001967282251718884

Conversation

@yumin-chen
Copy link
Copy Markdown
Owner

@yumin-chen yumin-chen commented Mar 29, 2026

I have designed and implemented the AlloyScript core runtime that binds to WebView via window.Alloy. The solution includes a robust cron parser, platform-specific cron job management for Linux (crontab), macOS (launchd), and Windows (Task Scheduler), and a CLI executor that runs JavaScript/TypeScript modules using Node.js. The API is exposed through the webview library with proper JSON argument parsing and JavaScript initialization scripts.


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

This commit introduces the AlloyScript runtime cron capability, allowing JavaScript
to schedule OS-level cron jobs through `window.Alloy.cron`.

Features:
- **Cron Parser**: Efficiently calculates the next matching UTC time for 5-field
  cron expressions, supporting special characters (*, ,, -, /), nicknames,
  and case-insensitive named values.
- **Cross-Platform Job Registration**:
  - **Linux**: Manages crontab entries with `# Alloy-cron:` markers.
  - **macOS**: Generates and installs `launchd` plist files in `~/Library/LaunchAgents/`.
  - **Windows**: Integrates with Task Scheduler using XML definitions and `S4U` logon type.
- **WebView Bindings**: Exposes the `Alloy.cron` API to the JavaScript environment
  using the `webview` library.
- **Job Executor**: A CLI `run` subcommand that invokes Node.js to execute
  JavaScript/TypeScript modules' `scheduled()` handlers.

The implementation ensures POSIX-compliant day-of-month and day-of-week
interaction and handles platform-specific constraints, such as the 48-trigger
limit on Windows.

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:56
This commit completes the AlloyScript runtime design by providing both
Cron scheduling and Subprocess spawning capabilities bound to WebView
via `window.Alloy`.

Key Features:
- **window.Alloy.cron**:
  - Full cron expression parsing (5-field format, nicknames, ranges).
  - Cross-platform registration: Linux (crontab), macOS (launchd),
    and Windows (Task Scheduler).
  - Secure execution using fork/exec to prevent shell injection.
  - Support for `parse(expression, relativeDate)` in JavaScript.

- **window.Alloy.spawn & spawnSync**:
  - Asynchronous (`spawn`) and synchronous (`spawnSync`) process execution.
  - POSIX support via `posix_spawn` and Windows support via `CreateProcess`.
  - Pseudo-terminal (PTY) support on POSIX using `forkpty`.
  - I/O redirection using pipes, pushing data to JavaScript via `webview::eval`.
  - JS wrapper providing `Subprocess` class with `exited` promise and `stdout.text()`.
  - Thread-safe `process_manager` for tracking active subprocesses.

- **Infrastructure**:
  - Unified C++ runtime initializing both Cron and Spawn namespaces.
  - Node.js-based executor for scheduled cron tasks.
  - Comprehensive unit tests for both cron parsing and subprocess management.
  - Reliable executable path resolution across platforms.

Co-authored-by: yumin-chen <10954839+yumin-chen@users.noreply.github.com>
This commit enhances the AlloyScript runtime with secure OS-level cron job
scheduling and subprocess spawning.

Cron Changes:
- Replaced system() with fork/exec in Linux/macOS cron managers to prevent
  command injection.
- Added support for the relativeDate parameter in Alloy.cron.parse.
- Improved executable path resolution using platform-specific APIs.

Subprocess Changes:
- Implemented window.Alloy.spawn and window.Alloy.spawnSync.
- Added full Windows support using CreateProcess and anonymous pipes.
- Introduced thread-safe process_manager with shared ownership to prevent
  dangling pointers.
- Added background polling for stdout/stderr streaming and process exit
  detection.
- Exposed subprocess capabilities in JS via a Subprocess class with exited
  Promise and stdout.text() support.

Security & Safety:
- Eliminated shell injection vulnerabilities across all platforms.
- Fixed memory safety issues in the process manager.
- Added comprehensive unit tests for both cron and subprocess modules.

Co-authored-by: yumin-chen <10954839+yumin-chen@users.noreply.github.com>
This commit provides a complete implementation of the AlloyScript runtime,
bridging the webview-based GUI with powerful OS-level capabilities.

Key Features:
- window.Alloy.cron: Standard cron expression parsing and cross-platform
  job registration (Linux crontab, macOS launchd, Windows Task Scheduler).
- window.Alloy.spawn & spawnSync: Robust subprocess management with
  asynchronous/synchronous execution and pipe-based I/O streaming.
- window.Alloy.$ (Shell): A cross-platform, bash-like shell interpreter
  built in C++ that supports piping, redirection, and safe JS interop.

Security and Robustness:
- Eliminated command injection vulnerabilities by replacing system() with
  direct fork/exec and CreateProcess calls.
- Resolved memory safety issues in the process manager using shared_ptr.
- Implemented a cross-platform I/O polling abstraction for Windows support.
- Added graceful background thread shutdown and reliable path resolution.
- Enforced POSIX-compliant cron semantics and Windows trigger limits.

The runtime API is fully bound to the WebView, enabling seamless
JavaScript-to-OS interaction for modern desktop applications.

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
@yumin-chen yumin-chen changed the title Implement AlloyScript Cron Runtime Implement AlloyScript Core Runtime Mar 29, 2026
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