User commands: sandboxed JavaScript host in a web worker #244

closed cmc opened this on 2026-11-27 06:00 UTC · feature · milestone 8 Automation and extension

Discussion

cmc 2026-11-27 06:00 UTC

Phase 1 of the user-commands plan in docs/plans/2026-11-27-user-commands.md (#173). No user-visible feature on its own; #245 builds on it.

Build the engine that runs user commands, following the PythonBlocks pattern (Sources/OrgApp/PythonBlocks.swift), not the in-process JSContext of JavaScriptBlocks:

  • A Web Worker in a hidden WKWebView, kept warm while an editor is open and unloaded when idle.
  • A WKURLSchemeHandler that serves the host page and ES modules from the configuration folder's commands/ only, resolving symlinks before checking.
  • No network or file access: Content-Security-Policy: default-src 'none' with scripts only from the scheme, on the page and on every script response; a WKContentRuleList blocking all other loads; fetch, XMLHttpRequest, WebSocket, EventSource, importScripts, indexedDB and caches deleted from the worker's globals before user code loads.
  • A run takes a module path, an exported function name and a JSON context, and resolves with a JSON result or an error. Calls from the worker back to the app (prompts, messages) go through a reply message handler.
  • Timeout per run (default 2 s, at most 30 s, time in a prompt excluded) and cancel: both terminate the worker and start a new one.
  • webViewWebContentProcessDidTerminate fails the running command with a message and recreates the web view.
  • Measure and record in the MR: first start, warm round trip, and a round trip carrying a 1 MB buffer.

Tests: a script that loops forever is stopped at the timeout and the next run works; fetch, XMLHttpRequest and an import from outside commands/ all fail; a symlink out of commands/ is refused.

Platforms: Mac (download and Mac App Store builds), iOS. Depends on: nothing.

referenced in commit c98c5d987c by cmc: User-written commands: recommendation and plan

2026-11-27 06:01 UTC

closed by cmc in commit 72f19c1f37: Command host: user commands in a sandboxed web worker

2026-11-27 08:01 UTC
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form