ADR 0003 — How custom logic runs
Status: accepted for rung 1; rungs 2 and 3 designed, not built (2026-11-22)
Context
Arbitrary Swift must never be evaluated in the PRISM or satellite process. Most app logic (filter, compute, validate, write a record) does not need a general-purpose language.
Decision — a ladder
- Declarative actions + a small typed expression language (V1, built).
- Actions are a closed set interpreted by the runtime:
setState,navigate,createRecord,updateRecord,deleteRecord,importCSV,exportCSV,showNotification,validate,sequence/when. - Expressions are pure and total: literals, state/record/query references, arithmetic, comparison, boolean logic, a conditional, and a fixed library of functions (
sum,count,avg,min,max,round,abs,lower,upper,contains,concat,length,formatCurrency,formatNumber,formatDate,month,year,today,coalesce,if). No loops, no recursion, no I/O, no reflection. Evaluation has a node budget, so an expression cannot hang the UI. - Data access is a declarative query object compiled to parameterized SQL over identifiers validated against the blueprint schema. Expressions never contain SQL.
- This rung runs in-process because it cannot express anything outside its own sandbox by construction.
- Actions are a closed set interpreted by the runtime:
- Scripts in a separate constrained process (post-V1). A worker with no ambient file or network access, CPU/memory/time quotas, talking over a typed pipe. Adding a script runtime is on the ask-first list.
- Real Swift generation only in the Tier C export (post-V1).
Consequences
- In V1 "generated logic" means generated expressions and actions; they are validated, labeled with
provenance.source = "agent", and covered by blueprint tests. Thecode.*agent tools answer with a structurednot_availableerror. - Requests the catalog and rung 1 cannot express are reported to the user as not implemented instead of being faked.