SPB Git

Repository Public License

0009-scripts-and-on-demand-components.md 3.9 KB

# ADR 0009 — Scripts and on-demand components run in an in-process JavaScriptCore sandbox

Status: accepted (2026-11-22). Supersedes rung 2 of ADR 0003 ("scripts in a separate constrained process").

# Context

The owner asked (2026-11-22) for apps whose functionality is not capped by the catalog, and for components created on demand. ADR 0003 limited V1 to declarative actions and expressions, and put a script runtime on the ask-first list; the owner's live instruction is that ask being answered. Requests such as a game board, a seating chart or a custom visualisation cannot be expressed by a fixed catalog of any size.

# Decision

  • Language and engine: JavaScript on the system's JavaScriptCore framework. No dependency is added and no code is downloaded; the engine ships with macOS.
  • Two artifacts in the blueprint, both labeled provenance.generated = true:
    • prism.script — global functions, called by the runScript action and by the expression function js('name', …).
    • prism.component — the definition of an on-demand component: declared props and events (the same contract shape as a catalog manifest) and a source with render(props) returning a declarative view tree. Instances are ordinary objects of type custom.<id>, validated against the declared contract by the same validator as catalog components.
  • Confinement. The context is a bare JavaScriptCore VM: it has no file, network, process, timer or module API. The only bridge is one host function, behind which AppRuntime offers: app state (declared keys only), per-instance local state, the app's own tables (through the same store and permission checks as actions), notifications, navigation, events and logging. Values cross as JSON text. Function names are checked to be plain identifiers before any lookup.
  • Rendering is read-only. While render or a js() expression runs, every mutating host call throws; so a view can never change state during a view update, and an expression stays pure.
  • Time limit. Each entry into the VM is cut off after 0.5 s with JavaScriptCore's execution watchdog (JSContextGroupSetExecutionTimeLimit). That function is exported by the framework but absent from its public headers, so it is looked up with dlsym at run time; when it is missing the engine reports hasTimeLimit == false, the runtime logs it, and scripts run without a limit. A test proves an endless loop is stopped on the current OS.
  • Permission. An app that carries a script or a definition must declare logic.scripts; the builder tools add it and it appears on the approval and publish screens like any other permission. Without it nothing is loaded.
  • Catalog first stays the rule (hard rule 3): component.define and logic.createScript are refused until the catalog has been consulted, the system prompt tells the builder to search first, and catalog coverage drops below 100 % for every custom instance, so generated parts are visible.

# Why in-process rather than a worker process

A view tree must be produced synchronously during a SwiftUI update, and handlers must act on the same state and database as the rest of the runtime. A worker process would need an asynchronous protocol for both, for a language that already has no ambient authority inside JavaScriptCore. The cost of this choice: a script shares the app's memory (no memory quota), and the time limit depends on an undeclared symbol.

# Consequences

  • Not sandboxed by the OS: confinement rests on JavaScriptCore having no ambient API and on the single host bridge. A JavaScriptCore vulnerability would be reachable by generated code; generated code comes from the builder model and is shown to the owner (code.read, Evolve diff).
  • No network, no file access, no memory quota, no async/timers inside scripts (ticks are driven by the runtime). Network access would be a new permission and a threat-model change: an owner decision, not taken here.
  • Satellites embed the same engine; runtime version is 1.1.0.
Files main
Menu

Theme