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
WKURLSchemeHandlerthat serves the host page and ES modules from the configuration folder'scommands/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; aWKContentRuleListblocking all other loads;fetch,XMLHttpRequest,WebSocket,EventSource,importScripts,indexedDBandcachesdeleted 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.
webViewWebContentProcessDidTerminatefails 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