Repository navigation
Proofs
Code here is proved, not only tested: every decision is a small TypeScript function annotated with LemmaScript, translated to Dafny, and proved to match a hand-written model of how the marketplace must behave. This is the platform's way of working, led by atlas, and the standard for all SimpleApps development. The augur-build plugin's lemma-driven-design skill teaches the pattern itself, test-driven design with proofs, with LemmaScript and Dafny as the TypeScript tooling (plugins/augur-build/skills/lemma-driven-design/); when a lesson here applies beyond this repo, add it to that skill too.
Sources:
-
LemmaScript (
lsc, kept on its latest release, 0.6.11 here; on each upgrade re-check atlas's gap list and runpnpm proofs): TypeScript to Dafny, the//@annotations,.dfy.genvs.dfy -
Dafny reference: the language and verifier (
dafny verify, 4.11 here) - atlas (
clones/atlas):.claude/rules/proofs.mdfor the rules,models/PROCESS.mdfor the process, andmodels/LSC-GAPS.mdfor where lsc's translation differs from JavaScript. Read the gaps list before using a construct for the first time
| Piece | Path | What it is |
|---|---|---|
| Shared layer | models/Text.dfy |
The lowest model layer, which every model includes: the list scan ListEnd, the text scans ScanEnd (a case of it) and RunStart, each with its general lemmas (…Is, …Reaches, …Agree, …Ext) |
| Model | models/Marketplace.dfy |
Hand-written Dafny: what each rule means (CalVer, skill keys and names, the description limit, the token budget, connector URLs), with lemmas about shipped values. Written before the code |
| Proved code | scripts/rules.ts |
Each rule as a pure function with //@ verify and //@ ensures, listed in LemmaScript-files.txt
|
| Generated Dafny |
scripts/rules.dfy.gen, scripts/rules.dfy
|
lsc writes .dfy.gen; .dfy is the same plus hand proof steps, additions only
|
| Link | models/links/scripts-rules.dfy |
<function>MatchesModel lemmas: the code decides exactly what the model says |
| Runtime pin | scripts/rules.test.ts |
Each rule agrees with the regex it replaced on thousands of generated inputs, so the proof is about the code that actually runs |
| Shell | scripts/validate.ts |
Reads files and reports; calls the proved rules for every decision about a value |
A mod's decisions are proved the same way, with the proved file inside the plugin, since an installed plugin has only its own folder. The Work pane has two: models/WorkPane.dfy for the pane (rules plugins/simpleapps-work-pane/scripts/pane-rules.ts, link models/links/work-pane-rules.dfy) and models/WorkData.dfy for the work scripts (work-rules.ts, work-data-rules.dfy). The status line has models/StatusLine.dfy (what /plan-usage <args> answers; rules plugins/simpleapps-statusline/scripts/usage-rules.ts, link models/links/usage-rules.dfy). A skill's decisions live in the skill's own folder, plugins/<plugin>/skills/<skill>/scripts/: the repo skill's cleanup has models/Repo.dfy (which branch to delete, whether to move), rules plugins/augur-build/skills/repo/scripts/cleanup-rules.ts, link models/links/cleanup-rules.dfy, and a JSON-in, JSON-out wrapper cleanup-plan.ts the skill runs (see Skill-Authoring#bundled-files). The proof covers the decisions, not the facts the agent gathers for them. validate.ts, the tests, lint and typecheck cover plugins/*/scripts/ and plugins/*/skills/*/scripts/ as they do scripts/. pnpm proofs verifies every model and link as one Dafny program, so a top-level name in one proved file MUST NOT repeat in another (a plugin's copy of a helper takes its own name).
A regex is a decision, and lsc cannot translate one: write it as a code-unit scanner that makes the same leftmost, greedy match, state the regex in the model, and pin the scanner to the original regex in the tests over thousands of generated inputs (work-rules.test.ts is the example).
lemmascript.json sets JavaScript string semantics (UTF-16 code units), as atlas does, so the proofs count characters the way the code does.
-
Code is TypeScript. LemmaScript proves only TypeScript, so all code in this repo MUST be TypeScript (
.ts, or.tsxin a mod): no Python, and no new JavaScript. Scripts run with Node's type stripping (node scripts/validate.ts), so there is no build step. The only exceptions are tool configs that their tools load as JavaScript (eslint.config.mjs,prettier.config.mjs);scripts/check-banned-strings.sh, a shell wrapper aroundgit grepwith no decisions of its own; and thecldlauncher (plugins/augur-build/skills/launcher/scripts/cld), a shell command users install that runsclaude updateand thenclaudewith their arguments. -
Proofs always come before code (owner, 2026-11-22). A new rule starts in the model (
models/<Area>.dfy), then its proved functions and their link, and only then the code that uses them. Code MUST NOT be written ahead of its proof, and proofs MUST NOT be deferred to a later issue. -
Every decision is proved. File reading, JSON, regex,
await, and classes stay in thin unproved shells that only call proved functions (lsc can't translate them; atlasmodels/LSC-GAPS.md). -
No escapes. Hand-written Dafny (the model, links, and additions to a generated
.dfy) MUST NOT useassume,{:axiom},{:verify false},{:trusted}, orexpect.scripts/validate.tsfails one. - Tests still pin the runtime at 100% coverage: a proof is about the Dafny translation, and a test shows JavaScript agrees.
-
No recursion per element (GH #19). A proved function MUST NOT call itself once per character, list item, line or edge of its input: JavaScript has no tail calls, and V8 overflows its stack at about 10,000 frames, which a long issue body reaches. Dafny proves termination, not stack depth. Write the walk as a
whileloop marked//@ pure, with//@ invariantbounds and//@ decreases; lsc emits it as a Dafnyfunction f(...) { f_fun_spec(...) } by method { <the loop> }. Then, in the.dfy(additions only), givef_fun_specthe recursive definition (the body a recursivefwould have had, callingf_fun_spec), itsdecreases, and anyensures, and add the loop the invariant that ties it to the spec:f_fun_spec(s, j) == f_fun_spec(s, i), oracc + f_fun_spec(s, j) == f_fun_spec(s, i)when the loop builds a result. Callers and links keep callingf, which is its spec. Bounded recursion (a fixed depth such asdigitsAt's 2 or 4) is fine but written as a loop too, so the rule has no exceptions. Test each walk at 100,000 elements (tests/work-pane/long-inputs.test.ts). -
General before specific. Before writing a second proof of the same shape, make it one proof over a parameter and reuse it (
augur-buildskilllemma-driven-design,references/writing-the-model.md"General before specific"). Here, every scan and list search is one of three general loops, proved once per shipped file (scanEndinrules.ts;runEnd,runStartandlistEndinwork-rules.ts; theirpane…copies inpane-rules.ts) and linked once toText.dfy. A named scan (digitRunEnd,refIndex,holdsFrom, …) is one call with its own test, and its link is two lemma calls with no induction. The code's lambda ((r: Ref) => r.id !== id) is a different function value from the model's, even with the same body, so a link states the general loop's lemma for every test (ensures forall ok :: runEnd(s, i, ok) == Text.ScanEnd(s, i, ok)) and meets the two tests withText.ScanEndExt,RunStartExtorListEndExt.ListEndExtalso takes two lists, which links code records to the model's (refsandAsRefs(refs)). - After changing a proved
.ts:pnpm exec lsc regen --backend=dafny scripts/<file>.ts, then re-add any hand proof steps.
lsc's translation, as found here (0.6.11; check again on each upgrade):
- An
//@ ensuresbecomes a separate<f>_ensureslemma, so callers never see it. When a caller needs a bound (a run's end, an index), copy the lemma'sensureslines into the function's own header in the.dfy(an addition); Dafny then proves it by the function's induction and every caller gets it. - On a
//@ pureloop (function-by-method) lsc drops the//@ ensuresentirely: no lemma, nothing checked. Put thoseensuresonf_fun_specin the.dfy; keep them in the.tsas the contract a reader sees. -
lsc genrewrites.dfy.genbut leaves an existing.dfyalone: after a change to a proved.ts, rebuild the.dfyfrom the new.dfy.genand re-add the additions (git diff --no-index <file>.dfy.gen <file>.dfylists them before the change). - A function-typed parameter (
ok: (c: number) => boolean) becomesok: (int) -> bool, and a named function or a lambda can be passed for it, so one proved loop can serve many rules. A lambda passed to a generic function (listEnd<T>) MUST type its parameter ((r: Ref) => …): untyped, lsc types itT, which Dafny rejects as unbound. - A wrapper calling a general loop sees the loop's bound only if the loop's own header says it: add
ensures i <= f(s, i, ok) <= |s|to the function-by-method itself (an addition), not only tof_fun_spec. Without it, a caller two calls up (closesBeforethroughspaceStartBack) timed out. -
arr.push(x)on a local becomesarr := arr + [x]: build a loop's list with it (linear in JavaScript), not[...arr, x](a copy each time). -
toLowerCasetranslates to an{:axiom}function: an escape in generated code, whichvalidate.tsdoes not see. Lower ASCII with a proved function instead (lowerinwork-rules.ts). -
const x = arr[k]becomes anOption; read fields in place, and writearr[k]!where TypeScript's strict index checks need it (lsc keeps the bound as a proof obligation). - A parameter named after a Dafny keyword (
assigned,to) breaks the generated file or its checks: rename it. - A branch no input reaches still counts against 100% branch coverage: restructure it away (a
requiresor anensuresthat rules it out) rather than leaving it to the tests.
| Command | Does |
|---|---|
pnpm proofs |
lsc check (regenerate, check additions-only, verify the code), then dafny verify the model and links |
pnpm quality |
Includes the escape check and the runtime pins |
pnpm proofs MUST pass before /submit (Deployment#submit). Like atlas, it is not in CI or the hooks: it needs Dafny installed locally (brew install dafny).
- The status line mod's other decisions (meter colours, cache ages, wrapping): next, by pulling them out of
hooks/register.tsxinto proved functions (Mods). -
scripts/check-banned-strings.sh: shell;git grepdoes the matching. - The Work pane's shells (
hooks/register.tsx,scripts/lib/) keep what is plumbing rather than a rule:Map/Setlookups, defaults for JSON fields that are missing (??), file framing (the---lines, paths), message and Markdown templates, and matching the connector's "no connected MCP tool" error text. Every rule about a value they read is proved.