SPB Git

Repository Public License

0003-custom-logic.md 2.0 KB

# 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

  1. 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.
  2. 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.
  3. 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. The code.* agent tools answer with a structured not_available error.
  • Requests the catalog and rung 1 cannot express are reported to the user as not implemented instead of being faked.
Files main
Menu

Theme