@useanvil/claude-code 0.0.0-stage → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,2027 @@
1
+ # Changelog
2
+
3
+ All notable changes to `@useanvil/sdk` are documented here. The format follows
4
+ [Keep a Changelog](https://keepachangelog.com/), and this project adheres to
5
+ [Semantic Versioning](https://semver.org/).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [0.8.1] — Anvil for Claude Code: a security review's fixes
10
+
11
+ A review of Anvil for Claude Code and the hosted routes it syncs to (2026-11-23) looked for every way the agent could
12
+ switch Anvil off, approve itself, or show a person something other than what they approve. Each fix below has a test
13
+ that fails on 0.8.0.
14
+
15
+ - **A copy or an unpack into the home folder is a change to Anvil's own controls.** `ditto -x -k payload.zip ~`,
16
+ `python3 -m zipfile -e a.zip ~`, `rsync -a dir/ ~/` and `cp -R dir/. ~` could replace Anvil's hook unseen, in every
17
+ mode. They are held by the always-on floor now; copying one folder by its own name (`cp -R dir ~`) still runs.
18
+ - **A block stays a block.** A command named like one of JavaScript's built-ins (`toString; rm -rf ~`) crashed the
19
+ check, and the block became a hold one Yes released. So did a 13,000-deep JSON body read by an amount rule.
20
+ - **Anvil answers before Claude Code gives up on it.** A named pipe called `.gitattributes`, a 200 MB patch, or an
21
+ amount 110,000 digits long kept the hook past Claude Code's 5 s limit, and the plugin then ran the command. Those are
22
+ held at once now, and the plugin's hook fails closed, as `anvil-claude on`'s does.
23
+ - **Only you can approve or switch Anvil off.** A command left running after the session (a Makefile or a git hook
24
+ with `nohup … /usr/bin/time anvil-claude ghost all &`, or a terminal made by `script`) passed as you. Now the program
25
+ it runs under must be your terminal: an app, ssh, tmux or a terminal emulator.
26
+ - **An OK is for that exact call.** An OK for an edit or an MCP call released a different edit of the same file
27
+ (`disableAllHooks`); now it releases only what was held. Bash holds work as before.
28
+ - **What you approve is what runs.** A held command, a file name or an MCP argument could carry terminal escapes that
29
+ drew a different command in the list you approve from, or wrote your clipboard. Such characters are shown, never
30
+ acted on, everywhere Anvil prints them, and a rules.md line that has one is never applied.
31
+ - **A project's rules.md is applied by `sync` only.** The rules screen applied a cloned repository's never-applied
32
+ `.anvil/rules.md` on Enter without showing it. Enter now applies only your own file's edits; a project's file goes
33
+ through `sync`, which shows every line.
34
+ - **`anvil-claude status` runs nothing a repository wrote.** In a clone whose `.claude/settings.local.json` named
35
+ Anvil's hook, `status` ran that file's command to test it.
36
+ - **Secrets stay out of reports and the hold list:** `aws ssm put-parameter --value`, `az keyvault secret set`,
37
+ `twine -p`, `echo … | sudo -S`, `--password-stdin`, httpie headers, `anv_`, `hf_`, `dop_v1_` and PyPI tokens.
38
+ - **Your workspace key goes only over https** (or to a local test address), and never comes back in an error.
39
+ - **The hook's own git calls run no program a repository configures** (fsmonitor, git hooks).
40
+ - **The dashboard shows what a workspace key sends as text.** A decision's action, key and reason were rendered as
41
+ HTML in two views; markup sent with any key ran in the owner's dashboard. Values the ledger can't hold (a NUL, an
42
+ amount over 2,147,483,647, a time in year 9999) are refused with a 400 instead of jamming the ledger queue.
43
+
44
+ ## [0.8.0] — Anvil for Claude Code: budgets, helper and model rules, and every screen says what each can do
45
+
46
+ ### Anvil for Claude Code on Windows: built, in testing (2026-11-19)
47
+
48
+ - **Windows is built end to end, and stays behind a name until it has run on Windows.** `anvil-claude on` turns it on
49
+ there with `ANVIL_WINDOWS_PREVIEW=1`; without it, it says Windows is in testing and changes nothing. The acceptance
50
+ run, and the three lines that turn it on for everyone, are in `docs/coding-agents/WINDOWS.md`.
51
+ - **Claude Code's PowerShell tool is checked.** A PowerShell command is read as the shell line that does the same
52
+ things, so every rule, block and condition judges it as it judges Bash; one Anvil can't read is held. So is a line
53
+ handed to Windows' shells and starters any way (`-EncodedCommand`, `/c`, a script file, stdin, `Start-Process`,
54
+ `wmic process call create`, a scheduled task's `/tr`, `forfiles /c`), and a `.ps1` or `.bat` the session wrote.
55
+ - **Windows' places are the floor's, by any spelling:** drive roots, `C:\Windows`, `C:\Program Files`, `C:\Users`,
56
+ the home folder and its own folders, raw disks (`C:\Users\Me.`, `FileSystem::C:\Users\Me` and `\\.\C:` included);
57
+ `format`, `diskpart`, deleting restore points and `wsl --unregister` are blocked. Registry start-up keys (the
58
+ person's environment and cmd's AutoRun too), `setx`, services, Defender, the firewall, `robocopy /mir`,
59
+ `taskkill /fi` and emptying the Recycle Bin are named.
60
+ - **Hooks with no shell:** on Windows `on` writes Claude Code's exec form (Node and its arguments), whose loader holds
61
+ a call when the hook is missing, damaged or crashes. Claude Code 2.1.310 or later; `on` refuses an older one, and
62
+ says so when it can't tell which one runs.
63
+ - **`off` and the other switches refuse from inside a session on Windows too:** by Claude Code's marker, Claude Code
64
+ among the parents, or a command no one types at that WMI, a scheduled task or an ended shell left behind.
65
+ - **macOS and Linux judge as before:** every one of this Mac's 143,211 real Claude Code calls since Oct 1 is judged
66
+ the same by the branch and its base (`scripts/coding-agents/windows-posix-equivalence.mts`).
67
+
68
+ ### The rules box never reads a line turned around (2026-11-19)
69
+
70
+ Found by three independent attacks (on a rewrite step that was then held: its sealed sets missed the bar). Each was a
71
+ line the box read as a stop on the very part the words leave out, or offered that as the closest. A rule only stops
72
+ what it names, so each is can't yet now; no reading of the 2,880 DEV lines changed (per line, against the box before).
73
+
74
+ - **Words that let part of a stop through**: "don't hold Stripe refunds under $50", "Stripe refunds under $50 don't
75
+ need my OK", "hold all Stripe refunds, ones under $50 have my ok", "… under $50 are good to go", "hold emails except
76
+ to acme.com". Where a stop on the whole was said first, that stop is offered (every refund: broader, never the part).
77
+ - **Everything but one thing**: "block anything but deploys", "block everything minus deploys", "hold every action
78
+ that isn't a deploy", "block everything, deploys are fine", "hold everything, let deploys through", "Claude may only
79
+ deploy", "hold non-Stripe refunds", "hold refunds that aren't from Stripe": never a stop on deploys or Stripe, nor a
80
+ closest on them ("Anvil can't stop everything but one thing"). "Anyone but acme.com" is still anyone outside
81
+ acme.com, "not over $500" still $500 or less, "Slack posts should only go out during work hours" still offers Slack
82
+ posts.
83
+ - **A part said as the one left out**: "emails that don't go to clients need my ok", "hold Slack posts that don't go in
84
+ #general", "hold pushes that don't go to main".
85
+ - **A condition said only in what happens**: "hold every deploy, claude keeps shipping on weekends" no longer holds just
86
+ weekend deploys. One pointed back at ("deploying after 9:30pm has burned us twice. hold those") is still read.
87
+ - **An inbox an email comes from**: "hold emails from the support@acme.com inbox" held emails *to* support@acme.com; it
88
+ is can't yet now (Anvil reads who a send goes to, not who it comes from), as "emails sent from …" already was.
89
+
90
+ ### The rules screen, redesigned: a box to type a rule in, four keys (2026-11-17)
91
+
92
+ - **Add a rule by typing it.** Between Always on and your rules sits an Add a rule box, in the product blue: type
93
+ "hold pushes to main", "never force-push", "at most 3 deploys a day" or "$50 a day", and under the box Anvil
94
+ says what it will do ("✓ every deploy waits for your OK"); enter adds it. Faint examples sit under the box until
95
+ the words are understood, and nothing typed is called an error until you press enter. Words Anvil's own reader
96
+ can't place go, on enter, to your Claude Code (Haiku, through your own login), once.
97
+ - **Four keys instead of eleven:** ↑↓ choose, space change, enter add, esc done. ⌫ twice removes a line you wrote
98
+ (one press only asks); type `import` to bring in CLAUDE.md. Each change is saved as it is made: there is no save key
99
+ to forget.
100
+ - **Sorted:** what is on first (blocks, then holds), then caps, budgets, model and helper rules, then what is watched,
101
+ then what is off, each section with room around it and a faint word on what it means.
102
+ - **The file is in the footer**, a link where the terminal opens one: `~/.anvil/rules.md` is plain Markdown, like
103
+ CLAUDE.md, to edit, keep or share. Edited outside the screen, the box says so and enter applies it, as `sync` does.
104
+ - **Proof is its own screen** (`anvil-claude proof`), no longer a tab: the rules screen is for changing rules.
105
+
106
+ ### Turning a rule you wrote down, in one key (2026-11-18)
107
+
108
+ - **Space now turns your own rules down as well as up.** On the rules screen, a rule you wrote used to only go
109
+ stronger with space; to watch it or switch it off you had to delete it and type it again. Now space changes its own
110
+ line and says so ("changed hold: deploys → off: deploys"): hold → off → watch → hold for a kind, a block to a hold
111
+ first, hold ↔ watch for a rule on one app, file or target. ⌫ twice still removes it, and the selected row says both.
112
+ A change that would make the line one Anvil can't use (an always-on kind watched) is refused, saying why; anything
113
+ else keeping the kind stronger is said, never hidden.
114
+
115
+ ### Who a send reaches, said honestly; words your rules can define (2026-11-18)
116
+
117
+ - **"Emails to clients" no longer quietly means every email.** Typed in the rules box or `rules add`, a send narrowed by
118
+ who it reaches ("hold emails to clients", "never email bob@acme.com", "Gmail sends to anyone outside my company") is
119
+ ? Can't yet: "Anvil can't narrow emails Claude sends by recipient yet ("clients")", with every send of it offered,
120
+ one key away. Written by hand in rules.md, the line holds every send, its catch said first ("It holds them whoever
121
+ they go to"), and its row says "every recipient": a line you wrote never stops holding what it held. Lines that were
122
+ refused for words Anvil couldn't place ("never email bob@acme.com") now hold every email, and say so.
123
+ - **`define:` lines.** `- define: clients = @acme.com, @globex.com` gives a word your rules use one meaning, listed under
124
+ your rules on both screens. A project's rules read yours, the project's own winning. (What each word means is read by
125
+ the conditions built next: amounts, recipients, part of an app, time. docs/coding-agents/IMPROVEMENTS-TO-CUSTOM-RULES-FOR-CLAUDE.md.)
126
+
127
+ ### Rule conditions: an amount, who a send reaches, part of an app, a time (2026-11-18)
128
+
129
+ - **A rule can carry a condition, and holds only when it holds.** "hold Stripe refunds over $500", "never email anyone
130
+ outside the company", "hold Slack posts in #general", "hold deploys on Fridays": each reads Ready in the box and
131
+ `rules add`, saying what still runs. A condition only narrows the stop its rule adds, and one Anvil can't read holds
132
+ the call, saying why. Two on one rule ("Stripe refunds over $500 on Fridays") must both hold.
133
+ - **An amount** on Stripe's, PayPal's and Square's refunds, charges, payments, payouts and transfers: over, at least or
134
+ under, in its currency, each field from the app's published schema. A full refund, another currency or a variable
135
+ holds. A refund's currency is read as yours only where you said it: `define: my currency = USD`.
136
+ - **Who a send reaches**, on emails and calendar invites: an address, a domain, a word you define (`define: clients =
137
+ @globex.com, @initech.com`), or anyone outside your company (`define: my company = acme.com`). A reply, a draft sent by
138
+ its id, a list or a relay holds. This replaces the Can't yet above: typed, a word not yet defined says what to write;
139
+ written by hand, what can't be read holds every send, its catch first.
140
+ - **Part of an app**: a Slack channel, a GitHub repository, a Linear team, a Jira project. Slack's and Linear's ids are
141
+ learned from Claude Code's own replies in its logs on this Mac (nothing is sent anywhere), and read again on `sync`
142
+ and as the rules screen opens. A gh command that names no repository is placed by the checkout it runs in.
143
+ - **A time**, on any rule: days, hours, nights across midnight, work hours (`define: work hours = Mon–Fri 9am–6pm`), on
144
+ the Mac's own clock. A time zone the clock can't read holds.
145
+ - **The money cap.** "at most $2,000 of Stripe refunds a day" adds up what each refund moves, and holds the one that
146
+ would go over. An amount it can't read holds and takes no place; one you OK counts the whole cap.
147
+ - **No cost when unused.** The conditions' code loads only when your rules have a condition, so the hook Claude Code
148
+ starts on every tool call stays its size.
149
+ - **Also:** `mailx`, `mutt`, `msmtp` and `swaks` are sends ("never send emails" holds them); "no more than $500 of
150
+ refunds a day" typed is a cap, and `rules add` takes a cap the box reads; what a rule learns of your apps (an id, a
151
+ reconnected connector) reaches the hook on `sync`.
152
+ - **The box reads a rule however you ask for it (2026-11-19).** "I want to approve every Stripe refund over $500",
153
+ "Refunds in Stripe above $1,750 — please check with me", "If Claude refunds more than $650 on Stripe, ask me first",
154
+ "weekends: no pushes to main", "I'd like a heads up whenever Claude posts in #general", "dont deploy on Fridays":
155
+ each reads as the rule it says, with the verb it says (a wish to approve holds, a heads-up watches, "isn't allowed"
156
+ blocks). The asking is only ever taken off: a condition inside it is read as before, never dropped. Also: "I'd like
157
+ X to wait for me", "X should wait", "X needs my say-so", "X, just log them", "X can go through but log them", "Gmail
158
+ shouldn't be emailing outsiders", "make gmail hold anything sent to …", "deny X", "so basically …", a sentence about
159
+ you around the rule. The strongest verb you say wins ("need my OK and should be monitored" holds), and "unless …"
160
+ stays with the rule (Can't yet, never dropped). Measured on fresh sets written by people who never saw the reader:
161
+ short, direct rules read well; plain speech is often Can't yet, with the closest rule, never a weaker one.
162
+ - **Money on more apps.** PayPal invoices by their whole total, and Shopify's refunds. Stripe's and Square's invoices
163
+ stay can't yet: no call that sends or pays one names its total. A Shopify refund is read in your currency, as a
164
+ Stripe refund is (`define: my currency`), and its catch says so.
165
+ - **Fixed: a POST is a read only by its whole body.** A body holding a `"query"` key anywhere (a GraphQL read's) was
166
+ taken for a read, so a refund sent with one ran under every rule. Now a body is a read only when it is a GraphQL
167
+ query or a JSON-RPC read and nothing else. Also held now: curl's URL globs (`{a,b}`, `[1-20]`, which send many
168
+ requests), a money field a form or a query names in a way Anvil can't place, PayPal's invoice updates, an invoice's
169
+ own currency, a tip.
170
+ - **Each condition reads more of how people say it.** Amounts: "north of $6k", "that top £12,000", "a thousand
171
+ dollars", "pay out", "issue refunds"; a share or an amount on what moves no money ("deploys over $500") offers the
172
+ rule without it. Recipients: "outside acme", "non-acme addresses", "people at other companies", lawyers, the board;
173
+ "back to the customer" and "to the attendees" narrow nothing, so the rule holds every one. Part of an app: "anything
174
+ Claude posts to #exec", "the Acme Slack workspace", "over in Jira". Time: a time said first, plan and package names
175
+ ("the Night Owl plan") never read as a time, dates said as can't yet.
176
+
177
+ ### Every rule you type gets one of three answers, said first (2026-11-18)
178
+
179
+ - **Ready, catch, or can't yet.** The rules box, `rules add`, the rule's row and `sync` answer every typed rule in one
180
+ of three states, in the same words. ✓ Ready: it does what you asked. ▲ Catch: it works, with one difference said
181
+ before anything else: an app that isn't connected here ("this covers its API now, and its tools once you connect
182
+ it"), a category that covers every app of it Anvil knows ("the 23 email apps Anvil knows, not just Gmail"), a rule on production that holds a
183
+ deploy which doesn't say where it goes, a command read as its whole kind. Enter adds it anyway, and the row keeps
184
+ the catch ("not connected yet") until it no longer holds. ? Can't yet: what Anvil can't do (a channel, a team or
185
+ repo by name, an amount, a time, an exception, two apps, an app nobody knows), and the closest rule it can, one key
186
+ away: enter adds it, `rules add` prints it as the command to run. A closest is never narrower than what you typed.
187
+ - **`rules add` reads a rule on one app, a file or folder, or one target as the box does.** It refused "hold Stripe
188
+ refunds" before ("name the app"), and turned "never send emails" into a watch on every write to an outside API. A
189
+ line written as rules.md writes it ("hold: Stripe refunds") is added as written.
190
+ - **A time or a condition on a kind** ("hold deploys on Fridays") is a can't yet in the box, offering the kind at any
191
+ time, so the line added says what it does. One written by hand into rules.md still holds every one, as before.
192
+ - **The reader:** a named part of an app ("Linear issues in the Payments team", "the billing-api repo"), "pause" as
193
+ asking first, "schedule" and "book" for calendars, a category named in the singular ("any texting app"), "without
194
+ my say", advice that names an app ("be careful with payments"), and 40 more widely used apps with their API hosts
195
+ (Freshdesk, Okta, Chargebee, TikTok, Mailjet and others), so a rule on one not connected is a catch, not a refusal.
196
+ - **Measured on sets nobody building it saw:** 79 and 81 of 90 on the first two written for the three states
197
+ (87.8% and 90.0%), and 84 and 87 of 90 (93.3% and
198
+ 96.7%) on two more written after the fixes their misses showed, scored once on the reviewed reader.
199
+ - An app connected while the rules screen is open is read again (its catch goes), at the cost of four file checks.
200
+ - **Whole on any screen.** On an 80×24 terminal a catch, the rule and what enter does all fit under the box; where a
201
+ screen has room for one line, that line says the whole state ("▲ Catch: not connected yet enter adds it anyway"),
202
+ never a sentence cut off. Found by the walkthrough in a real terminal.
203
+ - **An independent review found 13 faults, each fixed and pinned (say-the-catch.test.ts):** the apps added today made a
204
+ category's rule let a connector known by its id run (Help Scout's replies, Gusto's payroll): they never do now, and
205
+ the ones that send email or move money joined their category; "leaving" said of emails is their send; a category
206
+ says what it covers ("the apps Anvil knows"), never "any app"; a line applied before as a rule on its kinds stays
207
+ that rule (none holds less after an upgrade); a closest never drops words or reads back as less; `rules add` never
208
+ writes a line twice; a row's catch comes from the rules as applied; phrases like "the service now" or "base camp"
209
+ are no app; two API hosts (Brex, Constant Contact).
210
+
211
+ ### A rule on one app, one file or folder, or one target (2026-11-18)
212
+
213
+ - **One app or service:** `hold Stripe changes`, `never send email through Gmail`, `hold Slack posts`. One line covers
214
+ the app's MCP tools, its API reached from a command (`curl -X POST https://api.stripe.com/…`) and its CLI. Reads run.
215
+ Anvil knows an app by its server's name, your claude.ai connectors, the Claude app's connectors (by the names the app
216
+ keeps for their ids), its API's host and its CLI: names only, never a server's command or key. An app nothing here is
217
+ is refused with the one it may be ("did you mean Stripe?").
218
+ - **A cap on one app:** `at most 5 Stripe refunds a day` holds the sixth and counts nothing else.
219
+ - **One file or folder:** `don't touch migrations/`, `ask before editing package-lock.json`. It holds Claude's file
220
+ tools and every shell write Anvil can read (`>`, `tee`, `sed -i`, `cp`, `mv`, `rm`, a link into the folder); reads run.
221
+ A write Anvil can't read is held when the command names the folder. A secrets file is the secrets kinds' already, and
222
+ the line says so.
223
+ - **One target:** `hold deploys to production` (from the command itself: `vercel --prod`/`--target`, `fly -a`,
224
+ `railway -e`, `kubectl --context`, `modal -e`, terraform's workspace, `gh workflow run` by its name and inputs,
225
+ ansible's inventory, docker on another machine); `hold database destroys on the production database`; `hold pushes to
226
+ main in billing-api` (from the checkout the push runs in); `hold deletes outside the project`. A tool whose default
227
+ may be production, and a deploy Anvil can't place, are held: "Anvil can't tell which environment this deploys to".
228
+ - **A narrowed rule only adds a stop.** Over 2,000+ calls (the corpus, the MCP tools, every part's attack lines) no
229
+ verdict is weaker with every kind of narrowed rule set than without (tests/coding-agents/narrowed-all.test.ts).
230
+ - **The box shows what still runs** under a narrowed rule, and what it matched: "Stripe reads run · app: stripe (your
231
+ MCP server "stripe-live" · api.stripe.com · the stripe CLI)". Asking for your OK in words is the hold verb: "never
232
+ deploy to live without asking", "Stripe refunds need my approval".
233
+ - **Replay says what each narrowed rule let through,** not only what it stopped: "Stripe changes: stopped 12 calls ·
234
+ let 117 of the same kind run that a rule on the whole kind would have held".
235
+ - **Measured on seven sealed sets** (anvil-sealed-sets/: written by people who never saw the readers, kept outside every
236
+ checkout, scored once at integration; tests/coding-agents/typed-rules-sealed.test.ts). First score → after the misses
237
+ were read by pattern and fixed where general: apps 50 → 71 and 57 → 74 of 90 (every miss left is an app Anvil knows
238
+ that isn't connected here, which the spec reads as a rule, or a family read for one app); paths 72 → 90 and
239
+ 73 → 90; targets 60 → 85 and 56 → 84; deploy commands as "hold deploys to production" treats them 78 → 87 of 90,
240
+ with 8 production deploys let through at first (`vercel --target production`, `gh workflow run deploy.yml`,
241
+ `ansible-playbook`, docker on a remote host, none then read as a deploy) and 0 since.
242
+ - **On this Mac's last 30 days** (read-only): the app rules hold 60 of the 177 calls a hold on every app change would;
243
+ a rule on five folders removes 89% of the holds a hold on every write would make, and lets none into the folders
244
+ through; "deploys to production" removes few here (6 of 116: most deploys on this Mac are production, and a folder
245
+ named "…-prod-…" reads as production), each let-through checked by hand.
246
+ - **Fixed on the way:** a curl that wrote to a decoy URL first and Stripe's second ran under "hold Stripe changes";
247
+ Replay judged only a line's first part; `ImageMagick -delete` and a script only checked were read as deploys.
248
+
249
+ ### Narrowed rules: the shared core, and "deletes outside the project" (2026-11-17)
250
+
251
+ - **A rule can name part of a kind** (docs/coding-agents/IMPROVING-CUSTOM-RULES.md): `hold deletes outside the
252
+ project` holds a recursive delete whose target is outside the project folder, and lets the ones inside it run. It
253
+ is its own rule, beside the kind's (never a hold on every delete), listed under On on the rules screen, in `rules`,
254
+ Home and `report`, removed with ⌫ twice or `rules remove narrow-delete-outside`, and named in the held message
255
+ ("your rule "deletes outside the project" (~/.anvil/rules.md line 1)").
256
+ - **What it can't read, it holds:** a delete whose target Anvil can't place (`rm -rf "$DIR"`) is held, and the message
257
+ says what couldn't be read. A narrowed rule only ever adds a stop: over every call in the fixture corpus, no verdict
258
+ is weaker with narrowed rules than without (tests/coding-agents/narrowed-core.test.ts).
259
+ - **Built for the three parts that follow** (one app, one file or folder, one target): each narrowing's reader and
260
+ match live in their own files, so they can be built side by side.
261
+
262
+ ### The box reads what people type, and says why when it can't add it (2026-11-17)
263
+
264
+ - **A command is read the way the hook reads it** when Claude runs it: `docker push` holds a publish, `kubectl delete`
265
+ a deploy (not every delete), `crontab -e` a background job. The same in the box, `rules add` and a rules.md edited by
266
+ hand, so a line means one thing wherever it was written.
267
+ - **More of how people say it:** "ask before it deploys" holds, "don't let Claude force push" blocks; "delete the
268
+ database" is a database destroy, "copy the production database" a copy; more names for every kind.
269
+ - **What can't be a rule says why, and what to type instead:** a command Anvil lets run (`npm install`), one app
270
+ (`Stripe refunds`: try `app changes`), one file or folder, or advice for Claude (CLAUDE.md's). Words narrower than
271
+ their kind say so: "✓ every deploy waits for your OK, not just "fridays"".
272
+ - **Measured:** two sets of 90 lines written by people who never saw the reader, each scored once: 80 and 85 of 90,
273
+ where the reader before read 46 and 40 (tests/coding-agents/typed-rules.test.ts).
274
+ - **The README and `help rules` say what a rule covers and what it can't yet.**
275
+ - On an 80×24 terminal the Always on box folds to one line so your rules have the room; taller, it shows whole.
276
+ - Fixed on the way: a line typed as "hold pushes to main" was written `hold: hold pushes to main`; a count that names
277
+ a kind ("at most 3 publishes a day") was read as a hold, not a cap; a damaged mode file was said as "every kind is
278
+ switched on"; every box with a note in its border drew that border a column short.
279
+
280
+ ### Its own command: `anvil-claude`, beside the SDK's `anvil` (2026-11-17)
281
+
282
+ - **`@useanvil/claude-code` installs as `anvil-claude`**, and never takes the SDK's `anvil`. Both packages declared
283
+ `anvil`, so npm refused the second global install of the two (`EEXIST`), in either order, and the SDK's own pages
284
+ install it globally. Now they install side by side and neither touches the other's command or files.
285
+ `anvil-claude <sub>` is `anvil claude <sub>` (`anvil-claude on`, `anvil-claude rules edit`, `anvil-claude allow
286
+ <code>`); `npx @useanvil/claude-code on` the same through npx; `anvil-claude claude on` still works.
287
+ - **Every command Anvil prints is the one you have**: `anvil claude …` from the SDK, `anvil-claude …` from the small
288
+ package, `npx @useanvil/claude-code …` through npx, in every screen, held message and fix line.
289
+ `anvil-claude help rules` prints the guide in its own words.
290
+ - **The hook holds the agent switching Anvil off through the new command too**, in every form: `anvil-claude off`,
291
+ `npx @useanvil/claude-code ghost all`, `node …/@useanvil/claude-code/dist/cli.js allow …`,
292
+ `node $(which anvil-claude) off`, `xargs anvil-claude`, and a sync under another key.
293
+ - The dashboard's sign-in stays the SDK's (`anvil-claude login` runs `npx @useanvil/sdk login`, its latest): the small
294
+ package can be released without the SDK.
295
+
296
+ ### Runaway helpers held from the first call, and one OK per burst (2026-11-17)
297
+
298
+ - **More than 20 helper launches in 10 minutes in one session wait for your OK**, on every install, whatever the modes
299
+ say: a new always-on hold, "Stop runaway helpers". Each helper bills while it runs and can launch more, so a loop of
300
+ them spends fast. Measured first on four weeks of real sessions: work never launched more than 6 helpers in a minute
301
+ or 24 in 10 minutes, and this would have held 1 task in 1,440. Launches by helpers count in their session.
302
+ - **One OK lets a burst go on.** For helper bursts and delete bursts alike, your OK (`anvil claude allow`, or Yes in
303
+ Claude Code's prompt) starts the count again, so a burst you want asks once. Before, every call past the limit asked
304
+ again until the window passed. A No asks again; so does a prompt not yet answered.
305
+ - **The Always on box says the meter counts:** "Counts what every Claude Code session spends", with today's figure on
306
+ the rules screen. `report` and `/anvil` say it too.
307
+ - Replay counts a burst once. A table compiled before this release says its helper-burst stop is missing until
308
+ `anvil claude on` runs again (an upgrade does that on your first command).
309
+
310
+ ### Your plan budget in the desktop app, and budgets that stop at their number (2026-11-16)
311
+
312
+ - **A plan budget works in the desktop app.** `budget: 80% of my weekly limit` could only be measured where Claude
313
+ Code's status line ran (the terminal); the desktop app runs none. Anvil now asks Claude Code's own `/usage` for your
314
+ plan's use where no status line feeds it: in the background, a few seconds, no model call and nothing spent, at most
315
+ every 5 minutes (2 near your budget), only while a plan budget is set. It asks the Claude Code running the session,
316
+ with a clean environment and nothing saved; Anvil never reads your sign-in. `rules add` and `report` ask at once, so
317
+ they show where your week stands ("Now: 38% of your week · budget 30% · read just now"). Checked live on the desktop
318
+ app's own Claude Code (2.1.325): the first message started the read, the next was refused before the model.
319
+ - **A budget stops at its number, not a few replies past it.** Anvil acts between steps, so a reply under way always
320
+ ends. Each check now also counts what's running (two replies of the main chat and of each helper running, priced as
321
+ their latest replies, a finished helper nothing; at a launch, each new helper's first reply and the launches let
322
+ through just before it), and holds when that could pass the budget: "today's budget is nearly spent: 15K of 20K new
323
+ tokens, and what's running could pass it", or "the helpers starting could pass today's budget: 4K of 20K new tokens
324
+ used". Measured live with three helpers launched at once against 20K new tokens a day: 39,993 before (100% over);
325
+ now it ends at or under 20K. The guess about replies already running counts for at most half a budget, so it never
326
+ holds before half is used.
327
+ - **A helper reporting back continues the task.** Claude Code sends each helper's report to the message hook as a
328
+ message of its own (measured in the desktop app). Anvil took it for yours: a task budget began again at every report
329
+ and a spent budget refused the report, dropping work already paid for. Now it continues the task and is never refused;
330
+ the next action is held.
331
+ - **A launch is priced as helpers really start.** The desktop app's helpers start at 42K new tokens each (they carry its
332
+ connectors' tools), not 10–20K: a launch is now priced by helpers' own first replies on this computer, at their own
333
+ model, and a session's first reply (Claude Code's instructions written once) no longer prices the replies after it.
334
+ In the terminal, a session's first reply is counted while it is still being written (it reaches the disk only after
335
+ its tool calls are checked): a cold-cache run with three helpers ended 14% over its budget that way.
336
+ - **Every session counts.** A day's or a week's budget is shared by every Claude Code session on your computer; each
337
+ now also counts the others' work in progress (their replies running, their helpers, the launches they're making), so
338
+ two busy sessions can't pass it together. A task's budget stays its own. Measured live with two sessions launching
339
+ helpers at once: 23% over before; after, the right number of helpers starts and the day ends within one reply of its
340
+ budget (0.3–2% past it, the last replies reading the holds).
341
+ - **A helper is priced as it will cache.** A helper starting within 5 minutes of another (on the same model) reads its
342
+ instructions from Claude Code's cache and costs about half a cold one; launches are now priced that way, what helpers
343
+ cost is remembered past a week, and a launch held on a guess (no helper run on this computer yet) says so. The guess
344
+ itself is now priced from the session's own first prompt (it took a mid-session one, up to 380K for a 42K helper):
345
+ over 189 real tasks, a first helper is held when the task would have fit 4% / 3% / 1% of the time at 1.25× / 1.5× /
346
+ 2× its cost, was 15% / 11% / 7%.
347
+ - **A helper's hand-back is never held.** Held near a budget, a helper retried its hand-back and ended with no report;
348
+ a budget now never holds a step that only ends or reports the work (the hand-back, the desktop app's end-of-turn box
349
+ and task list). And Claude tells you to run `anvil claude allow` alone when something waits: it lists what's waiting,
350
+ so you don't need to find the code in the desktop app's folded notice.
351
+ - **Your own status line needs no change.** The line `on`, `rules add` and `report` printed for it is gone: the plan
352
+ is read from `/usage` instead.
353
+ - **Clearer words.** A change refused inside Claude Code puts the command on a line of its own (it wrapped mid-command);
354
+ rule conflicts read as one sentence; Home and `report` say the kill switch first; Proof says "action at your budget".
355
+
356
+ ### From the desktop check (2026-11-15)
357
+
358
+ - **`model: never haiku` holds in a session that starts on Haiku.** The desktop app's model picker before a session's
359
+ first message, and `claude --model haiku`, start Claude Code on that model with no switch for Anvil to refuse, so
360
+ the session ran. Now a message on a model your rules say never is refused before it reaches the model, with the way
361
+ to switch ("Switch first (the model picker, or /model opus), then send your message again"). A switch Anvil lets
362
+ through is remembered, so the next message goes on.
363
+ - **Every step says where it runs.** A held action or a refused message read "keep going once: anvil claude allow
364
+ nwr22kqx", which left it open whether that went in the chat. Each step a message asks of you now says it runs in a
365
+ terminal (not in this chat), puts a one-time code on a line of its own to copy, and says what comes after ("Then
366
+ send your message again", "Then tell Claude to go on"). The same for the session's first line, a problem's fix, the
367
+ status line and the desktop notice.
368
+
369
+ ### Every screen says what a limit can do
370
+
371
+ - **One answer for every screen.** `rules add`, `anvil claude rules`, the rules screen, Home, `on` and `report` say
372
+ what each budget, cap, helper and model rule does now: it holds; it can't be measured, and why; Claude Code doesn't
373
+ tell Anvil what it needs, and which Claude Code (by version and path) keeps that out; or nothing checks it here
374
+ (Anvil not on, not in this folder, hooks turned off, the kill switch, the meter file missing). Each comes with its
375
+ fix. Nothing says "past it, Claude Code stops" for a limit that can't.
376
+ - **A plan budget an API key can't fill** says so, with a dollar budget as the fix. (Your own status line: see 2026-11-16
377
+ above.)
378
+ - **The rules screen fits 80×24**, with any number of rules: one list scrolls around the cursor (kinds, then caps,
379
+ budgets, model and helper rules), the title, the always-on stops and the keys stay in view, and no line runs past
380
+ the screen. A limit's state wraps under its own column, never cut.
381
+ - **Only what holds here.** `anvil claude rules` and the rules screen list the rules in force in this folder, label a
382
+ project's ("this project only"), and count another project's instead of listing them as if they held here. `report`
383
+ from a folder a project install doesn't cover says Anvil isn't on there. `anvil claude statusline` says it isn't
384
+ working when its hook can't start, as Home does.
385
+ - **`on --project` keeps your status line.** It adds Anvil's only where no status line shows in that project already.
386
+ - **Help says what each limit needs:** Claude Code 2.1.304 for model rules, 2.1.318 to refuse a message, start a task
387
+ budget, count helpers and refuse a `/model` switch; the desktop app has no status line; the plugin route checks
388
+ actions only. `anvil claude help rules` prints the guide (a package's path to it ran past 80 columns).
389
+ - **Amounts near a budget never round up to it** ($49.60 of $50, $9.99 of $10, $50.40 past it), and Home never says
390
+ "Claude stops" under the kill switch or while an OK you gave still runs ("going on with your OK until 4:12 PM").
391
+ - **Smaller truths.** Proof's worst line leads with how it went ("watched, so it ran"). A rules.md line missing its
392
+ colon is told the line it meant (`- budget: $5 a day`), and `- model opus for deploys` is reported, never ignored. A
393
+ model rule says which kinds its words cover ("pushes" is a push to main and a force-push). `anvil claude rules` shows
394
+ the id `rules remove` takes. A budget hold that can't be recorded names the folder and the fix. `report` names a
395
+ missing meter file as a problem. A person who never turned Anvil on is told "isn't on yet", and Proof says nothing
396
+ has been checked rather than an all-clear.
397
+ - **Found by an independent review, fixed before the release:** a status line that already feeds Anvil is never told it
398
+ doesn't; a hook whose files are gone makes every limit "not checked"; quiet events count only from the settings
399
+ Claude Code reads in that folder; a spent budget leads Home over an OK on another; long paths wrap within their column
400
+ and are never cut; the status line command a person copies works when theirs ends in a comment; the rules screen fits
401
+ 11 rows and up, a note included; the message gate never waits on a named pipe.
402
+ - **The guide that ships is for you.** `YOUR-RULES.md` is the user's guide (what each limit needs, your own status
403
+ line, what Anvil doesn't do); the build record that was in it is `YOUR-RULES-RECORD.md`, in the repository only.
404
+
405
+ ### Added
406
+
407
+ - **What Claude Code spent.** The status line adds today's dollars (`🔹 Anvil on 🔹 14 checked · $3.10 today`), or on a
408
+ Claude plan the share of the week used (`41% of week`). `anvil claude report` shows today and this week (from
409
+ Monday) in dollars and new tokens, and the Proof tab a Spend line for its window. Dollars are Claude Code's own figure where its
410
+ status line ran, and Anvil's estimate at list price (marked `~`) for sessions it didn't see, such as the desktop
411
+ app's. It keeps each reply's model and token counts in `~/.anvil` for 40 days, never its text, and sends nothing.
412
+ - **Upgrades finish themselves.** After `npm i -g` of a newer Anvil, the first command you run in your own terminal
413
+ (Home included) puts the new hook in place, for each place `on` was run, and says so once. Only an intact older build
414
+ is replaced: a damaged install is reported as before, an older package never replaces a newer hook, and nothing
415
+ changes from inside Claude Code. The session start now names an update of any of the hook's files, not only the hook.
416
+ - **Budgets.** `anvil claude rules add "budget: $50 a day"` (also a week or a task, `5M new tokens a day`, or
417
+ `80% of my weekly limit`) sets what Claude Code may spend. At 80% it says so once; spent, the next message is refused
418
+ before it reaches the model and the next action is held, each with a one-time code, and `anvil claude allow <code>`
419
+ lets that task go on. A budget it can't measure (a plan's share with no status line reading yet) is never enforced,
420
+ and every screen says so; Claude can't feed the meter (its hook files run by hand, or `anvil claude statusline`, are
421
+ held). Home, `report`, `anvil claude rules` and the rules screen show where each stands, and Proof counts the stops
422
+ it made ("your budget"). Budgets live in your own `~/.anvil/rules.md`, and the message hook never reads the message. A cap line that reads as a budget (`cap: $50 a day`) says which to write.
423
+ - **Four quiet hook entries** (Claude Code 2.1.318 or later): a prompt, a helper agent starting or stopping, and a
424
+ model switch. Each answers nothing and never blocks, except a message sent past a budget you set and a switch to a
425
+ model your rules say never; `off` takes them out with the rest. Whatever breaks in Anvil, they let the message, the
426
+ helper or the switch through.
427
+ - **The main chat's model.** `model: opus for deploys` (any kind of action) holds a call made on another model
428
+ ("deploys need Opus; this session is Sonnet · switch: /model opus"); after `/model opus` the next try runs. The
429
+ model is read from the request line Claude Code writes as each request goes out (2.1.304 or later), so it is that
430
+ reply's own, and a helper's call is judged by the helper's model. `model: never opus[1m]` refuses that switch through
431
+ Claude Code's PreModelSwitch hook (the terminal's `/model`, the desktop app's picker, an SDK's `set_model`). Anvil
432
+ never switches the main chat's model itself.
433
+ - **`anvil claude rules` lists caps, budgets, helper and model rules** in a box of their own, each with what it does
434
+ now. Before, they showed only on the rules screen.
435
+ - **Helper agents: model and caps.** A rules.md line `model: haiku for exploring` (or `sonnet for helper agents`)
436
+ runs the helpers Claude launches on that model, whatever Claude asked for (checked live: Claude asked for Sonnet, the
437
+ helper ran on Haiku). `cap: at most 5 helper agents at once` holds the next launch until one finishes, counted per
438
+ session from the new entries; Claude is told to wait, not retry. `cap: 20 helper agents an hour` is an ordinary cap.
439
+ A fork keeps the session's model, and Anvil says so. `anvil claude try`, the rules screen, Proof and help show them.
440
+
441
+ ### Bounded OKs and caps
442
+
443
+ - **A budget's OK reaches no further than it says.** `anvil claude allow` past a budget lets that task go on in this
444
+ window only (a new day, week or plan window asks again), up to one more budget's worth, and for an hour at most;
445
+ each action it lets through is recorded. Claude is told of the OK with your next message, so it goes on instead of
446
+ waiting.
447
+ - **The helper cap holds with your own ask rule.** `permissions.ask: ["Agent"]` no longer turns `cap: at most N helper
448
+ agents at once` off. A launch asked in Claude Code's prompt keeps its place until you answer, and a No gives it back.
449
+ A workflow's helpers count. A helper counts until 30 minutes after its transcript last changed (it was 5), long
450
+ enough for a long test run.
451
+ - **Codes don't outlive their call.** A newer OK, or the call running, makes the older codes for the same call in that
452
+ session moot.
453
+ - **A missing meter file is said.** `anvil claude on` won't finish without `claude-meter.js`. If it goes missing, the
454
+ hook says once a session that budgets and model rules can't be checked, and Home and the rules screens say so
455
+ instead of "Claude stops".
456
+ - **The overshoot, stated honestly.** A budget can run over by about two replies per thread plus the reply that reads
457
+ the hold, not "one reply" (BUDGETS.md has the measured bound).
458
+
459
+ ### Fixed: what Claude Code spent is counted whole, from its own figures, and scoped
460
+
461
+ - **Workflow agents count.** The Workflow tool's agents (`<session>/subagents/workflows/…`) are read like helper
462
+ agents: their tokens and dollars reach budgets, `report` and Proof, and a model rule reads their model.
463
+ - **Claude Code's own cost record.** When a process ends, Claude Code writes its running total into the session file
464
+ (side requests such as titles and compactions, and helpers, included). That process's dollars are now Claude Code's
465
+ own, for the desktop app, `claude -p` and an IDE too; Anvil's list-price estimate (`~`) is left only for a process
466
+ still running. A chain of resumed processes, a fork's copy of its parent's record and the status line beside a
467
+ record count each dollar once.
468
+ - **A model with no price says so.** A dollar budget reads "can't measure: no price for claude-opus-6" instead of
469
+ ~$0.00 (its tokens still count); a gateway's model id (`anthropic/claude-opus-5-5`) counts as the model it names.
470
+ - **A plan reading is this session's account's, and shows its age.** Readings are kept per account (from the session
471
+ file's latest process, else its config folder), never another's. Over an hour old, or from before its window reset,
472
+ a plan budget reads "can't measure (last reading 6 days ago)", unless the reading is already past the budget (a
473
+ window's use never falls: it holds until the reset); Home, the rules screen, `report`, Proof and the status line
474
+ show each share's age.
475
+ - **Week budgets count the whole window** from the first check (files changed since it began, 32 MB a round), and say
476
+ "can't measure yet" while files are still unread; a task budget waits only for its own session's files.
477
+ - **A session resumed elsewhere keeps its dollars, counted once**: a new process's first reading no longer covers
478
+ replies another process made; spend in the desktop app or `claude -p` between two terminal days counts in its own
479
+ days, not again in the next; a resume after a process that ended without a record counts only what it added. A
480
+ ledger line cut short by a full disk no longer swallows the next one. A Mythos session is told apart by model rules.
481
+
482
+ ## [0.7.0] — Anvil for Claude Code: see what your agent did, stop the risky few, and watch it from your dashboard
483
+
484
+ Not yet published. (0.6.0 was never published: local builds carried it, so this release takes the next number.) Anvil
485
+ now sits in front of Claude Code itself: a few stops are always on from the first call, everything else starts in
486
+ ghost, and every stop reaches the same dashboard and receipts the SDK uses.
487
+
488
+ ### Added
489
+
490
+ - **`anvil replay`** reads this machine's Claude Code history (`~/.claude/projects`) and shows what
491
+ Anvil would have stopped: a report page and a five-line summary. What it finds stays on the machine,
492
+ apart from one anonymous count (TELEMETRY.md).
493
+ - **`anvil claude on | off | status | proof | enforce | ghost | allow | rules | sync`** puts a hook in front of
494
+ every Claude Code tool call. From the first call it blocks wiping your home folder or the project and
495
+ force-pushing main, and holds changes to Anvil or Claude Code's own settings, use of your account keys, delete
496
+ bursts and calls it can't check (`anvil claude rules` lists them); everything else starts in ghost. `enforce`
497
+ holds the risky kinds (push to main, deploy, publish, secrets, …) for your OK; `allow <code>` lets one held call
498
+ run once; `off` puts `settings.json` back as it was (or, if it changed since, removes only Anvil's hooks), and
499
+ `off --purge` also deletes what Anvil kept on the machine. The hook never touches the network.
500
+ - **Anvil's switches are yours**: `on`, `off`, `ghost`, `allow`, `sync` and changes to your rules run only in your
501
+ own terminal, never from inside a Claude Code session, and every change is on the record (`status`, the Proof tab).
502
+ - **Fails closed**: a check that stalls holds the call (Claude Code 2.1.295+), and `status` names an older Claude
503
+ Code that would let it run.
504
+ - **The Proof tab** (`anvil claude proof`, or tab in `anvil claude`): what Anvil stopped and why, worst first.
505
+ - **Your rules and caps** in `~/.anvil/rules.md` and a project's `.anvil/rules.md` (`hold:`, `block:`, `watch:`,
506
+ `off:`, `cap: at most 3 deploys a day`): `docs/coding-agents/YOUR-RULES.md`.
507
+ - **Your rules from CLAUDE.md**: `anvil claude rules import` reads them with your own Claude Code and
508
+ shows each rule beside its line before saving; `rules add "<sentence>"` adds one.
509
+ - **Dashboard sync** (signed in with `anvil login`): stops reach the workspace within seconds and mode
510
+ flips come back within a minute, through a background process the hook starts; offline, stops wait
511
+ and arrive once. Each stop carries the kind of action, verdict, mode, Anvil rule name and time, the
512
+ machine's label and a short session id; never a command, path or project name. Machines carry a label (`anvil claude on --machine <name>`).
513
+ The actions sidebar groups them under **Claude Code**, with a filter.
514
+ - **A Claude Code plugin** in this repo (`plugins/anvil`; installable once the repository is public): the same hook
515
+ with its own baseline rules,
516
+ `/anvil` (mode, rules, today's counts, the dashboard), the anvil-protect skill and the MCP server.
517
+ Where `anvil claude on` already covers a session, the plugin's hook steps aside.
518
+ - **`TELEMETRY.md`**: three anonymous usage counts (`claude_on`, `replay_run`,
519
+ `decisions_daily`), each shown in a notice before the first send.
520
+
521
+ ### Changed
522
+
523
+ - `POST /v1/decision` accepts the Claude Code hook as a source (`claude_code_hook`, `claude.*` actions
524
+ only, its own stop codes) and a `held` outcome. The SDK pre-flight's contract is unchanged.
525
+ - The CLI honours `DO_NOT_TRACK` for every usage event.
526
+ - The control plane's usage counter keeps the three new event names.
527
+ - **Anvil for Claude Code on its own**: `@useanvil/claude-code` (about 400 KB, no dependencies) has the same `anvil
528
+ claude`, and the README leads with it. Its `anvil replay`, `login` and `open` run the SDK of the same release.
529
+ - **Where it runs**: macOS and Linux · Node 20+ · Claude Code 2.1.295 or later. On Windows `anvil claude on` says so and
530
+ changes nothing; `@useanvil/claude-code` declares the platforms it installs on.
531
+ - **Fits the terminal**: every line `anvil claude` and `anvil replay` print fits 80 columns, broken at a space and never
532
+ inside a word or a command to copy. Piped output keeps whole lines.
533
+ - **Errors say what failed**: one line naming what failed and why, with `--debug` for the details and where to tell us.
534
+ No stack trace unless asked.
535
+ - **`off --purge` checks first**: a file it can't delete changes nothing, and it names the file and the fix.
536
+ - **Replay says what was measured**: on 1,433 real commands the rules had never seen, with every rule on, they
537
+ stopped 94 in 100 of the risky ones and 7 in 100 of the safe ones.
538
+ - **The same bytes from every clean build**: two clean clones of one commit pack identical tarballs.
539
+ - `CHANGELOG.md` ships in both packages, and nothing either one links needs access to the repository.
540
+
541
+ ## [0.5.6] — A stuck claim has a way out, a held payment reaches a person, and no screen reports a lever it never read
542
+
543
+ Published 2026-09-20. Forty-five commits, in three strands. The **durability loop closes**: a
544
+ durable claim that got stuck now has an exit that is not `psql`, and a settle can only ever touch
545
+ the claim its own caller took. **A held payment reaches a person**: a confirmation gate with no
546
+ webhook falls back to email, and every surface says so when a gate would reach nobody at all. And
547
+ the theme 0.5.4 and 0.5.5 ran on — **a surface may not state what the read behind it could not
548
+ support** — reached the last screens that still could: the sidebar under an operator lever, and
549
+ the deploy report.
550
+
551
+ ### Added
552
+
553
+ - **`anvil db settle-claim <key>` — a stuck durable idempotency claim finally has an exit that is
554
+ not a DBA with `psql`.** It applies the reclaim sweep's own classifier to ONE named row, inside a
555
+ single transaction that takes the audit-chain lock first and touches the claim last, so a
556
+ concurrent `/v1/guard` never waits behind it. Who ran it and why land in the audit ledger in that
557
+ same transaction, under a key no money reader can mistake for evidence. It refuses rather than
558
+ guesses: a claim younger than an hour, one whose lease is live, one re-taken mid-review, and —
559
+ the case that matters — one whose only failure receipt predates the attempt now holding the key,
560
+ which would otherwise reopen a key on another attempt's evidence. `--list` shows what is stuck,
561
+ `--dry-run` shows what it would do, and a database without migration 029 answers "cannot look
562
+ here yet" rather than "nothing is stuck".
563
+ - **`anvil doctor` names a service-key mismatch between this app and the plane it reports to**
564
+ (D5-M36). A key minted for one service, used by an app that declares another, produced modes
565
+ that silently never applied; the check names both sides, says which one this process is, and
566
+ prints a remedy that is true for the layout it found.
567
+ - **A confirmation gate that would reach nobody says so at the moment it is armed.** Arming a gate
568
+ on a workspace with no webhook and no proven email address is the one configuration where a held
569
+ payment waits for a person who is never told. The warning is raised where the decision is made,
570
+ not discovered later by a customer whose payment sat.
571
+ - **`/v1/deploy-report` names retired environment variables still set on the service**, and
572
+ `anvil doctor --deploy` gains a `no-retired-env` check that reads it. A variable nothing reads
573
+ any more is not an error — but an operator who believes it still does is one config change from
574
+ a surprise.
575
+ - **The dashboard names the workspace whose decision is in force**, or says plainly that it cannot
576
+ tell, instead of implying the one you are looking at.
577
+ - **Docs: "Where is my API key?"** — where the line lives, how to copy only the value, why Verify
578
+ asks for it, and what to do when it is gone. Placed after Quickstart, where people hit it.
579
+
580
+ ### Fixed
581
+
582
+ - **A degraded claim settle could fail ANOTHER caller's in-flight claim, and re-open a key whose
583
+ money was moving.** Under `ANVIL_DURABLE_CLAIM_FAIL_MODE=closed`, `/v1/guard`'s cleanup for a
584
+ claim it could not confirm settled by `(workspace, key)` alone — and 250ms, the budget that
585
+ triggers it, is also what a caller gets while queued behind another caller's row lock. So the
586
+ cleanup could wait out that lock and stamp `failed` on the winner's row, which is the one status
587
+ the re-claim clause admits: the key re-opened mid-flight and the next retry was granted. The
588
+ settle is now bound to the `lock_token` its own caller minted. A process may settle only a claim
589
+ it can prove it owns. **Latent on the default `open` fail mode**, which is why it had not fired.
590
+ - **`/v1/complete` left the claim `pending` when its lock token was already gone.** The token is
591
+ consumed with a GETDEL, so no retry of the completion could ever settle that row and only
592
+ `anvil db settle-claim` could clear it. It now ends the claim as `unknown` — found by the token,
593
+ scoped to the workspace, and only while the row is still pending, so a duplicate completion
594
+ after a successful one stays a no-op and a key whose money may have moved is never re-opened.
595
+ - **The sidebar reported "enforcing — live" for a flip the runtime had pinned to ghost.** A global
596
+ kill switch and an operator cap each hold every action in ghost at read time, and the write path
597
+ read neither — so on the surface people use most, the dashboard claimed enforcement while
598
+ nothing was blocking. Every surface now reports the mode IN FORCE, and a release of the lever
599
+ hands each row back the mode that is actually running, restoring only decisions somebody stored
600
+ rather than inherited defaults.
601
+ - **A held payment could reach nobody at all.** A confirmation gate with no webhook configured had
602
+ no fallback, and a webhook that failed had no second path. Holds now reach a proven email
603
+ address when the webhook is absent or fails, and one reach authority answers "who would this
604
+ reach?" for every surface, rather than four of them holding separate opinions. A burst of holds
605
+ no longer becomes a burst of mail: past a workspace's budget for one window, a single
606
+ "Anvil held N more" email stands in for the rest, and that summary survives a restart — it is
607
+ flushed on the next boot, re-entering the workspace it was held for. A Resend 429 is retried
608
+ once, honouring `Retry-After` only when the wait fits inside the send's own time bound.
609
+ - **A capped flip rehearsed enforcement and then snapped back.** The row painted enforce
610
+ optimistically and the answer corrected it a moment later, so telling the truth looked like a
611
+ glitch. A flip a known lever cannot let land is no longer animated; the write still goes through,
612
+ the stored intent still applies the moment the lever lifts, and the row catches up from the
613
+ answer if the lever turns out to be gone. The toast says "saved · ghost is what runs" rather
614
+ than reading like an error on a write that worked, and explains the lever once per session
615
+ instead of repeating the paragraph on every action.
616
+ - **The dashboard's Verify box rejected a pasted `.env` line.** Copying a key out of `.env` copies
617
+ `ANVIL_API_KEY=anv_live_…`, and the box answered "not recognized" — a puzzle with exactly one
618
+ answer. The prefix and surrounding quotes are now stripped, and both the hint and the rejection
619
+ name the file and the way back (`anvil keys rotate`).
620
+ - **A reachable control plane lost to a stale cached ghost.** A cached mode from an earlier
621
+ unreachable moment outranked a plane that was answering again, so an action stayed in ghost
622
+ after control was restored.
623
+ - **`anvil doctor`'s service-key remedy was wrong in three ways** — it advised a flip that would
624
+ not write under the app's own service, advised unsetting a service it should not, and claimed a
625
+ dashboard could set modes it can neither set nor show for that app.
626
+ - **Concurrent rotations of one docs log rotated it more than once**, shifting a batch past the
627
+ generation an operator would look in.
628
+
629
+ ### Changed
630
+
631
+ - **The warning printed when a claim settle does not land names `anvil db settle-claim`** instead
632
+ of pointing at a reclaim sweep. The sweep is a command, not a daemon: nothing runs it on a
633
+ schedule, so an operator sent to look for one would never find it.
634
+ - **The enforce-weekly recap and the blast-radius documentation** stop describing a 429 as holding
635
+ an unconfigured tenant. It never did — such a call runs in ghost — and the operations docs now
636
+ say what actually happens.
637
+
638
+ ## [0.5.5] — `anvil key --field` writes a key that runs, and no surface reports a lever it never read
639
+
640
+ Published 2026-09-18. Thirty-eight commits, in two strands. The fixes that landed after 0.5.4 was
641
+ cut, led by one that broke the first command of the quickstart: `anvil key --field` wrote a key
642
+ that threw on every call, and in a JavaScript file wrote one that would not even parse. And the
643
+ theme 0.5.4 started — **a surface may not state what the read
644
+ behind it could not support** — extended from degraded reads to the operator LEVERS that silently
645
+ outrank a write.
646
+
647
+ ### Fixed
648
+
649
+ - **`anvil key --field` wrote a key that threw on the first call — and, in a JavaScript file, one
650
+ that did not parse.** The rewrite emitted `(args) => key.for(…args[0]…)`, but `wrap()` calls a key
651
+ factory with a `WrappedCallContext` — `{ thisArg, args }` — so `args[0]` indexed the context, came
652
+ back `undefined`, and the field read threw on every call to the action the command had just
653
+ "fixed". It also wrote a TypeScript cast, `(args[0] as { ticketId: string })`, into `.js` files,
654
+ which Node refuses to load. `anvil key` and the `protect` codemod now build key factories through
655
+ one shared emitter, the file's own language decides whether the key carries a cast, and candidate
656
+ fields come from the wrapped function's own signature, or from the intersection of its call sites
657
+ when it states none.
658
+ - **⚠ BEHAVIOUR CHANGE for a self-hosted Postgres ledger.** The enforce weekly recap
659
+ (`anvil ghost enforce-weekly`) read the audit ledger with no workspace scope, so on a
660
+ multi-tenant ledger one tenant's email described every tenant's traffic. It now passes
661
+ `workspaceId`, defaulting to `callersOwnWorkspaceId()`. **On a JSONL ledger, or a Postgres one
662
+ with no `ANVIL_WORKSPACE_ID`, nothing changes.** On a Postgres ledger with a *real*
663
+ `ANVIL_WORKSPACE_ID`, pre-tenancy rows written before that column existed (`workspace_id IS
664
+ NULL`) now fall outside the report — Postgres matches a real workspace strictly and adds
665
+ `OR workspace_id IS NULL` only for the DEFAULT workspace. The recap can therefore show fewer
666
+ watched calls and less protected money than the week before the upgrade. That is the deliberate
667
+ WS2/WS3 tenancy semantic, and it is the correct direction — but it is a number an operator
668
+ reads, so it is called out rather than left to be discovered.
669
+ - **The offline rule templates offered a cap 100× too small.** `TEMPLATE_PRIMITIVE_FALLBACKS` —
670
+ the table each dashboard falls back to when `/api/primitives/schema` has no entry for a
671
+ primitive — carried `{amount:1000}` and `{amount:50}` with no `unit`. Untagged money is MINOR
672
+ by contract on both sides of the wire, so the picker handed out a $10.00 amount cap and a $0.50
673
+ workflow budget under cards reading $1,000 and $50 — and `defaultParamsForSpec` clones defaults
674
+ straight into the rule that gets SAVED, so it persisted a policy nobody authored.
675
+ `check:money-format` gains CHECK 6 so no money default can ship untagged again.
676
+ - **A mode write told the caller and every other open dashboard different things.** With the
677
+ global kill switch armed, the HTTP response correctly reported `runtimeMode: 'ghost'` while the
678
+ SSE frame carried the raw intent, so every *other* open dashboard was told the action was
679
+ enforcing. No frame carried `runtimeApplied` at all, so a flip whose control-store write failed
680
+ was indistinguishable on the wire from one that landed.
681
+ - **An operator-capped workspace was told its Enforce flip worked.** A ceiling of `observe`
682
+ (migration 020) pins every action to ghost, and the write path never read it, so a capped tenant
683
+ got a 200 and "your runtime picks it up on the next call". Nothing would enforce.
684
+ - **A dry run of a call that was already released predicted `pending_approval`** — with an approve
685
+ link to an id that 404s. `guard({ dryRun: true })` now makes the same redemption lookup a real
686
+ call makes (a read: nothing is spent, held or written) and predicts `already_released`. Ghost-mode
687
+ calls skip it as before; that is the hot observe path. The shipped type comments also stop saying
688
+ a dry run reserves and refunds spend — it does neither.
689
+ - **The "someone is blocked" alert could go out from a sandbox domain.** It forwarded a sender only
690
+ when `RESEND_FROM_EMAIL` was set in the environment it was handed, leaving the mail layer to fall
691
+ back to the process's own — so a process with a sandbox sender in its `.env` sent the one email
692
+ that says someone is stuck from a domain Anvil does not own, where it bounces or lands in spam.
693
+ The sender is now resolved once, falls back to Anvil's default, and is always forwarded.
694
+ - **Ghost analysis of a large single-entity export was quadratic.** One entity with k records made
695
+ `summarizeEntity` O(k²) and blocked the inline connector path: 1,000 records took 1.4s and 2,000
696
+ took 4.3s. It is linear now — 15ms and 52ms — with byte-identical output.
697
+ - **`strandedEnforce` counted tenants who were not stranded.** The count read only
698
+ `hosted_policies` and never joined `workspaces.enforcement_ceiling`, so an operator-capped
699
+ workspace — which enforces nothing — was reported as enforcing without a policy, while the
700
+ sibling `cappedWorkspaces` counted the same account. The two are described in the code as
701
+ mirrors and were overlapping.
702
+
703
+ ### Added
704
+
705
+ - **The Anvil Deployed page, served by `anvil serve` at `/managed`**, with its booking intake at
706
+ `POST /api/deployed-lead`. Both are public routes. The intake is rate-limited and size-capped, and
707
+ answers `200` only once the lead is durably committed — `400`, `429` and `503` otherwise — because
708
+ the person submitting it is waiting to learn whether they reached anyone. On a production plane
709
+ with no durable store configured it answers `503`, not a `200` for a lead the next deploy would
710
+ erase. The build now fails if any page the server can serve is missing from the tarball:
711
+ this one was a single line from shipping as a 404.
712
+
713
+ ### Changed
714
+
715
+ - The dashboards now surface a "saved, but not yet live" notice when a mode change is persisted
716
+ but the runtime has not taken it, naming the lever — kill switch, operator cap, or an
717
+ unreachable control store — instead of always blaming the store.
718
+
719
+ ## [0.5.4] — Every degraded read says so, and an outage is never money saved
720
+
721
+ Published 2026-09-10. Forty-two commits. The theme is one sentence: **a surface may not state what the
722
+ read behind it could not support.** Several of these were places Anvil's own outages were being
723
+ reported back to you as value it delivered.
724
+
725
+ ### Fixed
726
+
727
+ - **A spend-cap store outage was billed to you as money Anvil saved.** When the cumulative spend-cap
728
+ store was unreachable, Anvil failed closed — correctly — but wrote the receipt as
729
+ `spend_per_user` / `spend_per_workflow`, the codes a *real* cap breach uses. Those count as a policy
730
+ decision, so an outage landed in the prevented totals on the Impact page, in `anvil audit stats` and
731
+ in `anvil cc`. There is now a `spend_store_unavailable` code, classified as an availability event and
732
+ excluded from every money figure, exactly like `dedup_store_unavailable`.
733
+ - **Approval metadata on a *blocked* receipt was read as a release.** Approval fields are stamped on
734
+ every terminal status, so a call Anvil successfully **stopped** was being narrated as money a human
735
+ let through — outranking every later stop. Only a non-`blocked` status counts as a release now.
736
+ - **`anvil cc` printed a confident `Kill switch Off` over an armed switch.** It read the control config
737
+ through a swallowed rejection, so a Redis outage rendered as an all-clear. It now reads with
738
+ provenance and has three states; `anvil control show` was fixed the same way in 0.5.3.
739
+ - **An MCP client was told the emergency stop was off during an outage** — the same defect, one surface
740
+ over.
741
+ - **A degraded read could render as clean** on the Impact page, the actions sidebar and the workspace
742
+ bridge. A rejection is not an answer: an unreadable store now reports itself rather than borrowing
743
+ the empty state, and an all-clear is a positive claim no outage can earn.
744
+ - **The plane published a mode it could not read**, and a wrapped-call badge worked the mode out for
745
+ itself instead of asking the authority. An operator cap now outranks the file entry and is never
746
+ blamed on the customer.
747
+ - **A symlinked `dist/` meant the server never called `listen()`** — on every branch.
748
+ - **A policy Anvil could not load was invisible to every money surface.**
749
+ - **A human's decision no longer dies with a call a later rule refuses.**
750
+
751
+ ### Added
752
+
753
+ - **A lease on the durable idempotency claim, and a sweep that reclaims stuck ones.** A claim carries a
754
+ 15-minute lease, renewed by the keepalive that already runs. The sweep settles an expired claim as
755
+ `unknown` — it does **not** reopen the key, because an expired lease is not evidence the money didn't
756
+ move. Reopening would trade a stuck key for a double charge.
757
+ - **Migration 029** (`lease_expires_at` on `anvil_idempotency_claims`). Self-hosted deployments should
758
+ run it; hosted customers need nothing. A database **without** it still works — claims are written with
759
+ a NULL lease, which the sweep reads as "no lease information", never as expired.
760
+ - **`anvil audit stats` says when a read was capped.** It stops at the store's ceiling (10,000 records)
761
+ and now prints every figure as `N+` instead of computing "all time" from the newest ten thousand.
762
+
763
+ ## [0.5.3] — The money, control and approval fixes reach the SDK
764
+
765
+ Published 2026-09-08. No API changes: this release exists because the published package had drifted
766
+ 170 commits behind the deployed product, so fixes that were live on Anvil Cloud were unreachable by
767
+ `npm i`. Everything below was already running in production; this is the version that puts it in
768
+ your `node_modules`.
769
+
770
+ ### Fixed
771
+
772
+ - **A refused compensating refund was written to the ledger as executed.** A rollback step that
773
+ Anvil refused still recorded a terminal `executed` receipt, so the ledger claimed a refund had
774
+ gone out that never did.
775
+ - **`anvil cc` billed ghost would-blocks as money Anvil protected.** Ghost observations are
776
+ hypothetical by construction; counting them as prevented damage overstated the figure on the one
777
+ surface operators read during an incident.
778
+ - **`anvil control show` could print a confident `OFF` it was unable to back.** A flushed or
779
+ unreachable control store resolved to a default config whose `kill_switch` is `false`, so an
780
+ operator whose switch was **armed** was told it was off. It now reports
781
+ `Kill switch UNKNOWN — the control store could not be read`. (The `anvil cc` control centre
782
+ still has this defect — see [Running in Production](https://anvilcontrol.ai/docs/running-in-production#6-when-it-breaks-the-runbook).)
783
+ - **A restore under an armed kill switch reported stored intent rather than what was in force.**
784
+ Restoring a previous posture while the switch was on echoed back the modes you had asked for, not
785
+ the ghost every action was actually resolving to.
786
+ - **The money tile and its own drawer disagreed.** Two figures, one number: the drawer now prints
787
+ what the tile sorted by.
788
+ - **An unclassified receipt was counted as a ghost catch.** A receipt Anvil could not attribute is
789
+ not evidence of damage prevented, and no longer inflates the caught count.
790
+ - **The approval backlog alert could not drain.** An already-released hold left the alert armed, so
791
+ the "calls are waiting" banner stayed up after every call had been dealt with.
792
+ - **`anvil_failed_open` did not exist in the published package at all** (7 files on the deployed
793
+ tree, 0 at 0.5.2) — so a call that ran unprotected through a fail-open had no code naming it.
794
+
795
+ ## [0.5.2] — A deduped retry hands back the result it deduplicated
796
+
797
+ ### Fixed
798
+
799
+ - **A deduped retry answered `result: null` while the original result sat one field away.** When a
800
+ call was recognised as a duplicate, Anvil returned a receipt whose `replay` artifact carried the
801
+ original value and a summary saying "Exact original result is available for duplicate replay" —
802
+ next to a `resultReplayable: false` flag insisting it was not. The obvious caller line,
803
+ `(await wrappedRefund(t)).result.refundId`, therefore **threw on the retry**: the exact path Anvil
804
+ exists to make safe. `result` and `resultReplayable` are now derived from the artifact in one
805
+ place, so the contract "result stays null unless resultReplayable is true" is structurally true
806
+ rather than separately maintained. Only an `exact` replay hands back a value; a `projection` is a
807
+ caller-authored subset and a `reference` is a provider id, and returning either as `result` would
808
+ hand back something that is not what `execute()` returned while claiming it is.
809
+ - **First run never played on a fresh machine, and `anvil protect` dead-ended.** A cached workspace
810
+ key counted as "this user has onboarded", but `anvil login` and `anvil open`'s auto-pair both mint
811
+ one *without wrapping anything* — so the documented order (install → open → protect) armed every
812
+ first-run gate before the user reached the command those gates exist for. Pairing is not wrapping:
813
+ the gates now read a marker written only after a wrap actually lands.
814
+ - **An unknown command printed the entire reference.** `anvil home` and any other typo fell through
815
+ to the full usage dump — 114 lines on stderr with no error line anywhere, so the useful part
816
+ scrolled off an 80×24 terminal. You now get a headline, one did-you-mean, and where to get more.
817
+ - **`anvil open` re-offered pairing on every run.** If you never finished pairing, it opened two
818
+ tabs and waited 45 seconds again, forever. It now asks at most once a day, records the attempt
819
+ *before* it waits so a Ctrl-C cannot re-trigger it, and does not burn the cooldown when it could
820
+ not reach the control plane. The first Ctrl-C abandons only the pairing; a second still exits.
821
+ - **A workspace's "guarded calls" counted Anvil's own sign-up traffic.** Pairing wrote two internal
822
+ funnel rows, and the usage totals, per-action breakdown and recent feed had no action filter — so
823
+ a brand-new account was told it had made two guarded calls. Internal actions are now excluded
824
+ everywhere a tenant's own traffic is reported.
825
+
826
+ ### Added
827
+
828
+ - **`anvil key <action>`** — answers "is this action's idempotency key actually right?" from
829
+ recorded traffic: whether a duplicate has ever been caught on it, whether the key is too broad
830
+ (distinct calls collapsing onto one key), and `--field <name>` to narrow it. `--json` for scripts.
831
+ - **Currency travels with the amount** on guard records, resolved the same way by every writer, so
832
+ a record and the plane that judged it can never disagree about which unit a number was in.
833
+
834
+ ## [0.5.1] — A guard holds the process open until it has actually decided
835
+
836
+ ### Fixed
837
+
838
+ - **A guarded call could exit mid-decision and report success.** If your `execute()` resolved off
839
+ work that does not itself hold the event loop — an unref'd timer, and in practice a cron job, a
840
+ migration, a CLI or a serverless invocation winding down — the process could leave *after* your
841
+ side effect landed but *before* Anvil recorded it. The call reported success for a decision it
842
+ never finished making. Measured on the previous build, three runs of three. A guard now holds the
843
+ process open from entry until it settles, so the side effect and the record of it cannot come
844
+ apart.
845
+ - **An unreachable Redis stopped the process from exiting at all.** ioredis schedules reconnects on
846
+ an ordinary timer, and nothing was releasing it, so a script that finished its work sat in the
847
+ reconnect backoff until something killed it. Controlled comparison, same script and build, only
848
+ the Redis URL differing: a reachable Redis exited in 883ms, an unreachable one had to be forced
849
+ out at 9.7 seconds. It now exits on its own.
850
+ - **Ghost mode's receipt, journal and audit writes could be lost on the way out.** They were queued
851
+ on a timer that did not hold the process, and had been surviving only because the Redis socket
852
+ happened to keep every process alive by accident. Once processes started exiting promptly, the
853
+ journal row stopped landing. Ghost's entire output is those writes, so they are now held until
854
+ they complete.
855
+
856
+ ### Added
857
+
858
+ - **GitHub, Twilio and Resend are live connectors.** Auto-instrumentation covers them the way it
859
+ already covered Stripe, verified against the genuinely published packages — `@octokit/rest` 22.0.1
860
+ under real `plugin-retry` and `plugin-throttling`, `twilio` 6.1.0 in both ESM and CJS, and
861
+ `resend` 6.19.0 — with no network and no credentials. An unsupported version is refused with a
862
+ reason and the underlying call keeps working, confirmed against `@octokit/rest` 20.x, which the
863
+ adapter leaves byte-for-byte alone.
864
+
865
+ ---
866
+
867
+ ## [0.5.0] — The machine key is created at pickup
868
+
869
+ ### Changed
870
+
871
+ - **Approving a pairing now records intent; the key is created when a machine collects it.** A key used to exist the instant you clicked Approve — a full redirect before anything could receive it — so any interruption stranded a live credential nobody held. A pairing that is approved and never collected now writes nothing at all: no orphan key, nothing in `anvil keys list`, nothing to clean up. Just run `anvil login` again.
872
+ - Tokens minted by the previous build are still honoured, so pairings in flight across the deploy completed normally.
873
+
874
+ ### Added
875
+
876
+ - **`npm run reap:orphaned-keys`** retires credentials created before this change. Read-only by default; never empties a workspace; refuses a cutoff in the future.
877
+ - Pairing counters (`minted` / `claimed` / `claimFailedAfterBurn`) on `/v1/deploy-report` and in `anvil doctor --deploy`, backed by Redis so they stay meaningful behind a load balancer.
878
+
879
+ ### Fixed
880
+
881
+ - **`/v1/install/claim` had been sharing the anonymous signup rate limit** — ten attempts an hour for an entire office behind one NAT. It now has its own ceiling (`ANVIL_INSTALL_CLAIM_MAX_PER_HOUR`, default 60/hr) and the `429` says how long to wait.
882
+ - Pairing health is a 15-minute window rather than a lifetime counter, so a single transient blip no longer marks a deploy unhealthy until it is redeployed.
883
+
884
+ ---
885
+
886
+ ## [0.4.2] — Approve completes the pairing
887
+
888
+ ### Fixed
889
+
890
+ - **The Approve button did nothing in real browsers.** A Content-Security-Policy `form-action` directive covered the form's POST but not the redirect that answers it, so the browser silently dropped the last hop home: no error, no message, a tab that sat there and a terminal that waited forever. Every server-side test passed throughout, because `fetch()` does not enforce CSP.
891
+ - The 120-second consent window now visibly drains, so you can see how long you have.
892
+
893
+ ---
894
+
895
+ ## [0.4.1] — The pairing Approve button actually works
896
+
897
+ ### Fixed
898
+
899
+ - **Approve returned `403 origin_not_allowed` for every real user.** The consent page shipped `Referrer-Policy: no-referrer`, and a form POST from a no-referrer page sends its Origin as the literal string `"null"` — which no allowlist matches. Pairing was completely broken in the browser while every server-side probe stayed green.
900
+ - Approve and Cancel are now centred peers rather than a button and a stray link, and "Wrong account?" is out of the fine print.
901
+
902
+ ---
903
+
904
+ ## [0.4.0] — `anvil login` joins a machine to your account
905
+
906
+ ### Added
907
+
908
+ - **`anvil login`** — pair a machine with your Anvil account in one browser round trip. Both sides show a code you compare before approving, and the machine gets **its own key**, labelled `cli:<hostname>`, that you can revoke on its own. It never rotates your other keys and never disconnects an editor. `--paste` and `--token` cover SSH, containers, and CI; `ANVIL_API_KEY` still outranks any pairing.
909
+ - **`anvil logout`** — unpair a machine, with the option to revoke its key server-side (`--revoke`) or clear every cached account (`--all`).
910
+ - **Sign-in creates your workspace.** Signing in at the dashboard now provisions the workspace itself, so `no_workspace` is unreachable for a signed-in user.
911
+ - `anvil doctor` reports account posture: whether this machine is paired, as whom, and whether its key is still live.
912
+
913
+ ### Changed
914
+
915
+ - The paired identity is first-class across the CLI. Credential resolution is **environment > paired identity > nothing**, so CI keeps working exactly as before.
916
+
917
+ ### Fixed
918
+
919
+ - `anvil keys` told a freshly paired user there was no workspace to manage keys for, and returned a raw stack trace under `--json` where it promised an envelope.
920
+ - `anvil open`'s auto-pair no longer borrows a failure exit code, no longer claims "needs a browser" when only stdin is piped, and gives up after 45 seconds instead of holding your terminal for five minutes.
921
+ - `anvil protect` recovers from "this email already has a workspace" by offering to pair the machine, instead of describing the dead end.
922
+ - The docs site is built for the `/docs` path it is actually served at, so its links and stylesheet resolve.
923
+
924
+ ---
925
+
926
+ ## [0.3.8] — First-run fixes reach the CLI
927
+
928
+ Both of these had been fixed on main for a day, and neither was in anyone's hands: `npx @useanvil/sdk` serves the published version. Both were reported by a first-time user.
929
+
930
+ ### Fixed
931
+
932
+ - **A brand-new workspace showed an action nobody had protected.** The dashboard link the CLI opens fabricated `payment.charge` into itself, so a fresh account arrived at a row that said "Waiting for your first protected call" — for a call that did not exist.
933
+ - **`anvil open` no longer boots a local control plane.** It used to start one and send you there, which meant a hosted user landed on a freshly-started empty server they could not sign in to. A local plane is opened only when one is already serving.
934
+
935
+ ---
936
+
937
+ ## [0.3.7] — Removal for everyone, the editor connects, and Anvil can see your code
938
+
939
+ ### Added
940
+
941
+ - **`anvil remove <action>`** — take an action off your dashboard and the wrapper back out of your code, without an editor. It asks the control plane first, so a refusal or an unreachable plane leaves your code completely untouched.
942
+ - **Connect editor** — one click from the dashboard connects VS Code or Cursor. You never see a credential and you never paste one.
943
+ - **The code map** — the CLI publishes where your protected calls live (paths and line numbers, never your source) so the dashboard can point at them. `anvil sync` refreshes it, `anvil sync --forget` deletes it, `ANVIL_NO_CODE_MAP=1` prevents it.
944
+ - **Suggestions in "+ Protect new"** — the card now proposes risky *unprotected* calls it found, phrased as guesses and capped at three, so someone who doesn't know what to type has somewhere to start.
945
+ - Bare `anvil` is a hub that prints and exits; `anvil open` is the one way to the dashboard.
946
+
947
+ ### Changed
948
+
949
+ - **Removal finishes on the click.** It leaves a tombstone rather than deleting the entry — deleting it would let a still-wrapped call fall back to the workspace default and start blocking live traffic.
950
+ - **The always-on floor is real, and ghost evaluates it.** The retry-storm guard used to live inside policy evaluation, so a tenant with no policy never reached it and ghost was excluded entirely. Enforce with no policy no longer holds every call; it applies the floor and marks the call `floorOnly`.
951
+ - **Ghost sees what enforce would stop.** Spend caps used to return "allowed" in ghost before examining any cap, so you could watch a clean week under a limit you were already blowing. Ghost now evaluates caps against its own window and reserves nothing.
952
+
953
+ ### Fixed
954
+
955
+ - The ghost report's headline counted every action while naming one — "33 confirmed duplicate `refunds.create` executions" for a log holding 11 of them — and folded read-only lookups into a figure presented as money at risk.
956
+ - Two matcher bugs made coverage look better than it was: a call like `stripe.charges.create` matched nothing, and a wrap's lowercased action name hid leftover camelCase calls in the same file.
957
+ - A verdict is history: the decision log stopped relabelling past verdicts from the action's current mode.
958
+
959
+ ---
960
+
961
+ ## [0.3.6] — One paste-safe placeholder, and a scan that says why it found nothing
962
+
963
+ ### Fixed
964
+
965
+ - **The command Anvil printed could not be pasted.** `<your.action>` uses shell redirection characters, so `npx @useanvil/sdk protect <your.action>` is a parse error in both zsh and bash. Every surface now shares one placeholder.
966
+ - **Arrow keys corrupted the action name.** An up-arrow left a stray `a` in the buffer, so the next thing you typed produced a different action than the one you meant — silently wrapped.
967
+ - **Twilio was invisible to the call scanner**, because comms detection required the literal word `send` and Twilio's send API is `messages.create`.
968
+
969
+ ### Added
970
+
971
+ - `anvil protect` now says *why* a scan found nothing, rather than reporting an empty result.
972
+
973
+ ---
974
+
975
+ ## [0.3.5] — The CommonJS hosted crash
976
+
977
+ ### Fixed
978
+
979
+ - **Every CommonJS consumer's first hosted `guard()` call threw.** Resolving the SDK's own version used a construct a CommonJS bundle cannot express, so it threw while building request headers — on the exact call a new user makes first, in ghost, the mode that is contractually incapable of blocking anything. Six shipped bundles carried it.
980
+ - A migration runner reported "All migrations applied successfully" on a run that applied 8 of 22 files. The schema was never wrong; the message was.
981
+
982
+ ---
983
+
984
+ ## [0.3.4] — V1: the money path, tenancy, approver identity and the ledger
985
+
986
+ Four workstreams shipped in this release; each keeps its own section below.
987
+
988
+ ### Hosted enforcement parity: one brain, many bodies
989
+
990
+ ### Fixed — an approval authorized a key, not an act (spec §6 Step 6)
991
+
992
+ - **An approved $50 refund released a $50,000 one.** `lookupApproved` matched on
993
+ `computeApprovalId(action, key)` alone and released whatever turned up next under that key,
994
+ so an agent whose refund was approved could retry the same key for any amount, or repoint it
995
+ at a different recipient, and the gate opened. The approval record already stored the amount
996
+ and the counterparty; nothing ever read them. It now compares the **presented act** against
997
+ the approved one and refuses on any mismatch — and refusing does **not** consume the
998
+ approval, or an attacker replaying an approved key at a new amount would gain a
999
+ denial-of-service on the legitimate call by burning the operator's real decision.
1000
+ - **One human decision authorized unlimited executions.** The approved record sat in Redis for
1001
+ its whole TTL (up to 24h) releasing every call that reused the key. Approvals are now
1002
+ single-use, redeemed by compare-and-delete so two racing retries cannot both be released.
1003
+ - **The act is recorded for every hold**, not only the axes that fired: a trigger-word hold on
1004
+ a $10 refund stores the amount too, because the escalation this resists does not care which
1005
+ axis held the call. Records written before this ships still release — they are compared on
1006
+ whatever they can prove — so approvals already in flight are not invalidated mid-window.
1007
+ - **A dashboard dry-run was writing real holds.** `/api/test-policy` and `/api/replay` pass
1008
+ `simulate: true`, which `evalConfirmationGate` ignored: previewing a policy put a genuine
1009
+ pending record in the operator's queue and fired `ANVIL_APPROVAL_WEBHOOK_URL`, paging a human
1010
+ about a payment that never happened. Previews now validate exactly as a real call does and
1011
+ neither write a hold nor spend an approval.
1012
+
1013
+ ### Fixed — a human's rejection did not survive the next retry (spec §6 Step 6)
1014
+
1015
+ - **Reject, and the agent's next retry undid it.** Nothing read the rejected key, so
1016
+ `evalConfirmationGate` found no *approved* record and called `recordPending`, writing a fresh
1017
+ pending under the same deterministic id. The record flipped `rejected` → `pending` and
1018
+ reappeared in the operator's queue as though nobody had decided. A refusal survived exactly
1019
+ until the next retry — seconds, for an agent. The mirror of the approval defect above: one was
1020
+ too durable, the other not durable at all.
1021
+ - **It got worse with `pending`, not better.** The new verdict was telling the caller *"a person
1022
+ is looking at this — retry in 5s"* about a decision already made, so the agent polled forever
1023
+ and every poll re-queued the item. A refused call now answers **`blocked`**, and the reason
1024
+ names who refused it, when, and that retrying will not release it.
1025
+ - **The refusal cannot be overridden by the party it refused.** The check runs *before* the
1026
+ `approval_field` metadata bypass, which is a field the calling agent controls.
1027
+ - **Act-scoped, like approvals.** A materially different request — another amount, another
1028
+ recipient — is held afresh for a new human decision rather than inheriting someone else's
1029
+ refusal. Never auto-allowed: nudging the amount buys another hold, not an escape. Bounded by
1030
+ the rejected record's TTL, so an idempotency key is never permanently stranded.
1031
+
1032
+ ### Added — hosted holds now reach a human, per tenant (spec §6 Step 6)
1033
+
1034
+ - **A held payment notified nobody on the hosted plane.** The notification was already built and
1035
+ correct; its URL came from `ANVIL_APPROVAL_WEBHOOK_URL`, a **process-wide** variable read
1036
+ inside whichever process runs `recordPending`. Locally that is the customer's own process. On
1037
+ hosted it is Anvil's, so a tenant could not configure hold alerts at all — money froze and the
1038
+ only signal was someone happening to open the dashboard.
1039
+ - **The obvious fix would have been a cross-tenant leak.** Setting that variable on a
1040
+ multi-tenant server would POST every tenant's holds — action names, amounts, subject and
1041
+ initiator labels — to a single endpoint. The api-server now installs a **per-workspace
1042
+ resolver**, and once installed the env var is never consulted again; a resolver that fails
1043
+ sends nothing rather than falling back.
1044
+ - **`workspaces.approval_webhook_url` / `_secret`** (migration 014) mirror `retry_dispatch_url`
1045
+ and reuse the same `validatePublicWebhookUrl` — private hosts, non-http(s) schemes, embedded
1046
+ credentials, malformed URLs — re-validated on read as well as write. Signed HMAC-SHA256 under
1047
+ its own domain prefix (`anvil.approval.v1:`) so the secret cannot cross-replay from the retry
1048
+ webhook, and the dispatch refuses redirects. Deliberately a separate sink: `retry_dispatch_url`
1049
+ is a COMMAND endpoint, this is an ALERT endpoint.
1050
+ - `GET`/`POST`/`DELETE /api/settings/approval-webhook`, matching the retry-webhook contract so
1051
+ operators learn one pattern. The secret is returned once and never re-exposed on read.
1052
+
1053
+ ### Fixed — `gate:local` could never be green
1054
+
1055
+ - **One suite had failed in every gate run ever recorded** (seven logs, back to before this
1056
+ workstream), for a structural reason rather than a flaky one. `gate:local` runs in a throwaway
1057
+ git worktree and **symlinks** `dist/` instead of rebuilding it;
1058
+ `tests/ghost-come-back-loop.test.ts` simulates an npm install by `cpSync`-ing dist to a temp
1059
+ dir and spawning `dist/server.js` from there. `cpSync` preserves symlinks, so `argv[1]` sat
1060
+ under `/tmp` while `import.meta.url` resolved back to the original — the server's
1061
+ `isDirectEntry` check decided it was not the entry point and exited **without listening and
1062
+ without stderr**. A 40-second boot timeout with no error attached, which is why it survived so
1063
+ long. Fixed with `dereference: true`, proved by A/B in the gate's exact shape.
1064
+ - This matters beyond one file: CI is billing-blocked, `gate:local` is the only gate, and a gate
1065
+ that can never be green is a gate people stop reading.
1066
+
1067
+ ### Added — the receipt now says WHO authorized the payment (spec §6 Step 6)
1068
+
1069
+ - **A hold is the one decision where a person takes responsibility for money moving**, and after
1070
+ they approved, the executed call's audit record was byte-identical to any other allow. The
1071
+ approver, the approval id and whether their identity was *verified* lived only in the policy
1072
+ change log, keyed by nothing the receipt carried — so "show me who approved this payment"
1073
+ needed two logs and a timestamp correlation. `AnvilResponse.humanApproval` and
1074
+ `AuditRecord.humanApproval` now carry it, on **both** transports, through the same path Step 7
1075
+ built for `runtimeEvaluatedPrimitives` rather than a second mechanism.
1076
+ - **`actorVerified` is never inferred upward at any hop.** It is `true` only for a literal
1077
+ `true` — from a trusted proxy at approval time, over the wire, into the record, onto the
1078
+ screen. A compliance trail that lets a typed name read as a validated identity is worse than
1079
+ one that admits the difference.
1080
+ - **Rendered.** The Impact drill-down and the Actions decision log both show an "Approved by"
1081
+ row — hidden entirely when nobody had to approve, which is nearly every call; an empty row
1082
+ would imply a human signed off on all of them.
1083
+ - **The hosted receipt is sanitized as network input.** A malformed one drops *whole*: a partial
1084
+ receipt naming an approval with no approver still reads as evidence.
1085
+
1086
+ ### Added — end-to-end proof of the whole approval chain
1087
+
1088
+ - `tests/integration/hosted-approvals-e2e.test.ts` drives hold → `pending` → approve → release
1089
+ against the **real** spawned api-server on real Postgres and Redis. It asserts directly the
1090
+ identity the two planes had silently disagreed about — that `api_keys.workspace_id` and
1091
+ `resolveWorkspaceIdForEmail(email)` resolve to the same tenant — and that a held call does
1092
+ **not** claim the idempotency key. That last one is the quiet killer: a hold that claimed the
1093
+ key would return `duplicate` forever, so no approval could release anything, and the feature
1094
+ would be dead on arrival with every unit test still green.
1095
+
1096
+ ### Added — `pending`: the wire can say "a person is looking at this"
1097
+
1098
+ - **A fourth `/v1/guard` verdict** carrying the approval id, the reason axes and a poll
1099
+ interval. A hold and a block are different events: a block is final, a hold is the same
1100
+ request succeeding once someone acts. Collapsing them left an agent unable to tell "never
1101
+ going to work" from "try again in a moment".
1102
+ - **Sent only to clients that declare `accepts_pending`.** An older SDK receiving an
1103
+ unrecognised status falls through to `failMode` — and open **executes**, running the very
1104
+ call a human is being asked to authorize. The handshake means the server can deploy ahead of
1105
+ its clients. The caller-facing object deliberately does not fork: a hosted hold lands as
1106
+ `status: 'blocked'` + `blockedBy: 'confirmation_required'` + `policyDetails`, exactly as the
1107
+ local engine already returns it, so Step 3's parity survives Step 6.
1108
+
1109
+ ### Fixed — the approval queue was invisible to the operator who had to act on it
1110
+
1111
+ - **The two planes name the same tenant differently.** The hosted guard API writes holds under
1112
+ `workspaces.id` (a UUID); the dashboard read under `deriveWorkspaceId(email)`
1113
+ (`ws_<base32>`). Those key spaces never intersect, so a hosted tenant's held payment was
1114
+ written where their own dashboard could not see it and the queue rendered **empty** — which
1115
+ reads exactly like "nothing to approve". Both routes now bridge through the same
1116
+ `resolveWorkspaceIdForEmail` the usage and audit surfaces use.
1117
+ - **"Trust this recipient" had the same bug one layer down.** The counterparty seen-set is
1118
+ namespaced identically, so approving-with-trust wrote where the runtime never looks and the
1119
+ next call was held again. The standalone `/api/counterparty` routes had it too.
1120
+ - **An unbridgeable workspace is now said out loud.** The list endpoint reports
1121
+ `store_healthy: false` (the existing "this list is not a fact" contract, already rendered as
1122
+ a warning by both surfaces) rather than an empty all-clear; approve/reject and the trust
1123
+ mutations return **503 and change nothing**, because a silent no-op on a money release is
1124
+ worse than an error — the person walks away believing they acted.
1125
+
1126
+ ### Fixed — the hosted transport enforced two of fifteen rules and said "Enforcing"
1127
+
1128
+ - **`stripUnsupportedForHosted` is gone.** When `ANVIL_API_KEY` is set — which
1129
+ `anvil protect` writes into every onboarding customer's `.env` — `guard()` went over the
1130
+ wire to the api-server, which called the real `evaluatePolicy()` but first ran a
1131
+ fourteen-line filter that deleted `spend_caps`, `workflow_limits` and custom rules, then
1132
+ reduced `rules[]` to an **allowlist of two**: `amount_cap` and `metadata_required`. It
1133
+ also omitted `key` and `workflow` from the evaluation context, leaving the retry-storm
1134
+ floor and every cumulative rule dormant. Thirteen of fifteen authored rules were inert on
1135
+ the documented path, while the dashboard kept saying "Enforcing" — because that badge came
1136
+ from a process-wide environment flag rather than from what the runtime evaluated. The
1137
+ filter is replaced by `stripExcludedForHosted`, a **denylist of one**: customer code, which
1138
+ by design never executes inside Anvil's process (it runs in the caller's own, as an SDK
1139
+ pre-flight). `HOSTED_ENFORCED_PRIMITIVES` is now *derived* from the primitive registry
1140
+ minus that denylist, so a new primitive is enforced on both transports the day it ships and
1141
+ an exclusion is a deliberate, reviewable act rather than something to remember.
1142
+ - **`webhook` was the sharpest leg, and it fails in the worst direction.** The wire never
1143
+ carried webhook data, and `webhook_signature` is DORMANT without it *by contract* — a
1144
+ dormant rule allows. So a hosted `webhook.deliver` call with a missing or forged signature
1145
+ **executed**, while the identical local call blocked; in ghost, the tenant got a report
1146
+ saying the call was fine and flipped to enforce on the strength of it.
1147
+ - **Two live wire-fidelity bugs, both found by running the transport arm for the first
1148
+ time.** `api-client.ts` read only `opts.service` and never the configured `ANVIL_SERVICE`,
1149
+ so `service_blocklist` blocked locally and ALLOWED hosted on the same call — and the
1150
+ custom-rule pre-flight, which does read it, judged a different service than the hosted
1151
+ plane. Separately, `reason`/`blockedBy` were gated to `status === 'blocked'`, so a hosted
1152
+ duplicate returned `blockedBy: null` where the local engine reports `dedup_replay`; hosted
1153
+ tenants' caught duplicates were invisible to the dashboard's dedup filter and its per-rule
1154
+ fire counter — the exact bug the local path had already been fixed for.
1155
+ - **Spend reservations are released, not orphaned.** `evaluatePolicy()` returns only
1156
+ `measured.result` and discards the reservation handle, so enabling cumulative caps through
1157
+ it would have taken budget with no way to give it back — blocking a tenant from spending
1158
+ money they never spent, on the first hosted call against any policy with a cap. The hosted
1159
+ evaluator now uses `evaluatePolicyWithLatency` and releases what it reserved, because this
1160
+ transport has no completion handshake yet. The cap degrades to a per-call ceiling rather
1161
+ than leaking; accumulation remains the open Step 5 work, and its harness stays red for it.
1162
+
1163
+ ### Fixed — every degradation on the hosted money path resolved toward *allow*
1164
+
1165
+ - **A hosted call that could not be evaluated now HOLDS instead of executing.** An evaluator
1166
+ exception was caught, logged as *"degrading to idempotency-only"*, and the call ran
1167
+ unprotected — on an action whose dashboard said **Enforcing**. Enabling the stateful
1168
+ primitives made that far more reachable than it had been, because the evaluator now reaches
1169
+ Redis for rate windows and spend counters, so a store blip throws on the money path.
1170
+ `evaluateHostedDecision` no longer throws at all: every failure is classified
1171
+ (`snapshot_missing`, `snapshot_unreadable`, `policy_invalid`, `policy_eval_failed`) and
1172
+ returned as a decision the caller holds on, audits, and counts. **The polarity is per mode** —
1173
+ enforce holds, ghost carries on, because ghost that changes behaviour is itself a defect.
1174
+ - **An enforce action with no activated policy held instead of waving the call through.** This
1175
+ state is reachable through the product: a dashboard mode-flip writes `control_config` while
1176
+ the snapshot upsert COALESCEs a null policy, so flipping to Enforce before activating a
1177
+ policy left nothing to enforce — and every call executed under a green badge. The refusal now
1178
+ names the gap.
1179
+ - **The default hosted customer failed OPEN on every Anvil blip, and `ANVIL_FAIL_MODE=closed`
1180
+ could not reach them.** The SDK read `ANVIL_MODE !== 'enforce'` as ghost intent, folding
1181
+ *"I declared ghost"* together with *"I declared nothing"* — and `anvil protect` writes
1182
+ `ANVIL_API_KEY`, never `ANVIL_MODE`, because hosted mode lives in the dashboard. So the
1183
+ undeclared bucket is where the documented onboarding path puts everyone. Undeclared now
1184
+ behaves as enforce, matching what the local engine already does with the same absent
1185
+ variable. An explicitly-ghost client is unchanged: ghost never blocks.
1186
+ - **The same collapse double-executed retried charges.** An undeclared client sent
1187
+ `mode: 'ghost'` on the wire, so a server with no snapshot to resolve stamped its duplicate
1188
+ verdict `ghost` — and the SDK observed-and-**executed** a key the server held a receipt for.
1189
+ The local engine refused the identical duplicate. Only a client that has said the word
1190
+ "ghost" now gets behaviour that can run a side effect twice.
1191
+ - **A degradation hold left no trace.** A policy block wrote a full audit record; a
1192
+ dependency-degradation hold wrote nothing, so the customer saw a failure and the operator saw
1193
+ an empty log. `recordDegradationHold()` now fires at every hold on **both** transports with
1194
+ one shared `blockedBy: 'anvil_unavailable'` code and the degraded dependency in `reason`.
1195
+
1196
+ ### Changed — the Enforcing badge is a report from the runtime, not an env var
1197
+
1198
+ - **`ANVIL_ENFORCEMENT_BACKING` no longer decides what the dashboard claims.** It is a
1199
+ configuration value describing intent; the badge is supposed to be a fact about what the
1200
+ runtime just did. A primitive could silently stop enforcing and no surface would know, because
1201
+ no surface was asking. `evaluateHostedDecision` now returns the primitives it **actually**
1202
+ evaluated, threaded into the `/v1/guard` response and both audit receipts, and
1203
+ `resolveRuntimeTruth` narrows the badge to the signed-in workspace's own set.
1204
+ - **"Actually" excludes three things**, each a way the badge could have kept lying with better
1205
+ provenance: a rule that does not apply to this action, a rule after a block (the loop
1206
+ short-circuits — it genuinely did not run), and a **dormant** rule — a `tool_call_cap` with no
1207
+ workflow, a `webhook_signature` with no request body — which ran, could not decide, and allowed
1208
+ for a reason unrelated to safety.
1209
+ - **Not knowing falls back to the capability set.** A signed-out visitor, a failed snapshot read
1210
+ or an unconfigured database is not evidence about a customer's policy, and downgrading a real
1211
+ tenant's badge on Anvil's own ignorance would be a new lie pointing the other way. An empty set
1212
+ is honoured only when a policy was genuinely read.
1213
+ - **`anvil doctor --deploy` gains `enforced-primitives-consistent`.** The control-plane advertises
1214
+ a set of primitives to customers; the api-server now reports the set it can back, and a
1215
+ mismatch is a hard FAIL naming the primitives. Previously `enforcement-truth-consistent` could
1216
+ only compare a boolean, so a control-plane advertising a rule an older api-server had never
1217
+ heard of reconciled clean while that rule was inert.
1218
+
1219
+ ### Added — `AnvilResponse.runtimeEvaluatedPrimitives`: what actually checked your call
1220
+
1221
+ - The runtime measured honestly and **the SDK threw it away**. `api-client.ts` only ever *wrote*
1222
+ `evaluated_primitives` (reporting its own local decision up via `/v1/decision`) and never read
1223
+ the field off a `/v1/guard` response — so a developer could not ask the one question they have
1224
+ after a surprising call, on the transport `anvil protect` puts every customer on.
1225
+ - **One field, both transports, one meaning.** Locally the runtime is the engine in your process;
1226
+ hosted it is the plane. Disjoint from `locallyEvaluatedPrimitives`, which names the layer the
1227
+ hosted plane structurally refuses to run — two actors, two fields, because `whereEnforced()`
1228
+ depends on telling them apart.
1229
+ - **The hosted value is sanitized on the way in** — strings only, snake_case, bounded on count and
1230
+ length, deduped, absent rather than `[]` when unusable. It is network input landing on a field
1231
+ customers log and assert on; a stale proxy or hostile host must not be able to put free text in
1232
+ something read as a fact about their own protection.
1233
+ - Present on allow, block and duplicate — the server evaluates *before* it claims, so a retried
1234
+ call really was checked. Absent on the fail-open path, where the plane never answered.
1235
+
1236
+ ### Added — "Checked by" on the decision log: what actually ran on each call
1237
+
1238
+ - A row could say *blocked by `amount_cap`* and not answer the next question — **what else was
1239
+ checked?** A held call was worse in reverse: it named the degraded dependency and never said
1240
+ what had run before the hold. Both surfaces now render the runtime's per-call report from the
1241
+ audit record they already write.
1242
+ - **The chips carry the mode colour**, which design.md §2.3 calls never-decorative: grey means
1243
+ the rule *observed* this call, blue means it could have *stopped* it.
1244
+ - **The row hides when a record carries no report** rather than rendering empty. An older record
1245
+ means we do not know what ran — not that nothing ran — and "Checked by —" would read as
1246
+ "checked by nothing", which is the same species of lie this whole workstream removes.
1247
+
1248
+ ### Fixed — the hosted spend cap did not exist; now it accumulates
1249
+
1250
+ - **A $100/day cap admitted three committed $60 charges.** Measured against a real api-server:
1251
+ the hosted plane never reserved, never committed and never accumulated, and wrote **zero**
1252
+ spend keys to Redis — while the dashboard showed the cap configured and the local transport
1253
+ enforced it on the identical policy. Note the polarity: this is not the orphaned-reservation
1254
+ leak that gets worried about, which at least fails *safe* by over-blocking. It failed **open**.
1255
+ - **The lifecycle is wired end to end.** The evaluator hands its reservations to the caller, the
1256
+ api-server carries them on the **lock token** — already scoped to the completion window and
1257
+ already `getdel`-consumed exactly once, so a double-commit is structurally impossible — and
1258
+ `/v1/complete` commits on `executed`, refunds on `failed`. Every other exit (duplicate, error,
1259
+ refusal) releases. The rule is "will the customer's code run?", which is deliberately **not**
1260
+ "was it blocked": a ghost would-block still executes, and releasing there would hide a ghost
1261
+ tenant's spend from the very cap they are measuring before trusting it.
1262
+ - **The reservation TTL now outlives the completion window** (660s vs the lock token's 600s).
1263
+ Equal TTLs let a reservation be reaped while a legitimate completion was in flight — the commit
1264
+ would find nothing and a real spend would vanish from the counter, leaving the cap
1265
+ under-counting in the customer's favour. A cap may over-block; it must never under-count.
1266
+ - **The reaper runs on the api-server.** `sweepExpiredReservations` already existed but lived
1267
+ only in the SDK's reconciliation worker, which the api box does not run — so an orphaned
1268
+ reservation was held until its TTL and never counted. It now sweeps every 60s and ships
1269
+ `anvil_spend_reaper_total` from day one: a rising recovery rate means completions are being
1270
+ lost, which is a problem well before any cap is wrong.
1271
+
1272
+ ### Added — `check:stranded-enforce`, so "who does this deploy break?" is answerable first
1273
+
1274
+ - The hold above is a **live** change for any tenant already enforcing an action they have no
1275
+ policy for. `npm run check:stranded-enforce` lists them from the api's Postgres and exits 1 if
1276
+ there are any — and **2, never 0, when it cannot read**, because a preflight that reports a
1277
+ clean bill of health it did not verify is the same fail-open polarity Step 4 removes.
1278
+ Kill-switched tenants are reported separately: not held today, held the moment the switch
1279
+ lifts. `--allow-stranded=N` exists for an operator who has already contacted them.
1280
+ - The count is also **standing**, because any future mode-flip re-creates the state: the api's
1281
+ `/v1/deploy-report` carries `strandedEnforce` (a count, never workspace ids — that endpoint is
1282
+ unauthenticated) and `anvil doctor --deploy` warns on it without failing the verdict. The
1283
+ runtime is correct there; the customer's configuration is what needs a human.
1284
+
1285
+ ### Changed — `ANVIL_HOSTED_POLICY_EVAL` is retired; `ANVIL_HOSTED_FAIL_MODE` replaces it
1286
+
1287
+ - **Hosted policy evaluation is unconditional.** The flag silently disabled *all* policy
1288
+ evaluation on one box, invisible from the customer's seat where the dashboard went on saying
1289
+ "Enforcing" — an outage waiting for a misconfiguration. It is no longer read; a leftover
1290
+ value is called out at boot and by `anvil doctor --deploy` rather than left looking
1291
+ load-bearing. This closes the doctor's hard-FAIL over-claim branch **by construction**.
1292
+ - **`ANVIL_HOSTED_FAIL_MODE`** (`closed` default / `graceful` / `open`) governs only what
1293
+ happens once evaluation has already failed. It reuses the SDK's `resolveRedisFailMode`, so
1294
+ the two sides of the wire cannot drift, and every path through it writes an audit record and
1295
+ increments `fail_open_total` — choosing `open` cannot be quiet.
1296
+ - **`AnvilStatus` gains `'unavailable'`** — held, not blocked, not unknown. It reports as
1297
+ `unknown` in the Impact/CLI/usage projections and deliberately **not** as `blocked`: a block
1298
+ is the product working and is counted as customer value, so folding Anvil's own outages into
1299
+ that number would let a bad Postgres afternoon look like a productive one. The precise rate
1300
+ lives in `anvil_guard_verdicts_total{verdict="unavailable"}`, its own series.
1301
+
1302
+ ### Added — the parity harness now gates, and the gate now runs the money-path lane
1303
+
1304
+ - **`tests/parity/differential.test.ts` (78 tests) moved into the blocking lane**, and
1305
+ `tests/parity/baseline.ts` — the checked-in list of excused divergences — is now an **empty
1306
+ array**. The suite passes under `ANVIL_PARITY_STRICT=1`, which ignores that file entirely.
1307
+ - **`tests/parity/transport-differential.test.ts` runs for the first time.** It reported 38
1308
+ of 38 SKIPPED for want of a real stack while simultaneously being declared red-on-purpose —
1309
+ both readings wrong in the same direction. It now runs **37 passing tests** against a real
1310
+ api-server on live Postgres + Redis, and is registered in `REQUIRED_PROOFS`, so the lane
1311
+ fails rather than shrinks if it ever self-skips again.
1312
+ - Proven by injection rather than assumed: restoring the allowlist reds 29 evaluator tests,
1313
+ dropping `key` from the eval context reds 8, and deleting `workflow` from the `/v1/guard`
1314
+ body reds 3 transport cases *naming that field*. All three restore to green.
1315
+ - **`npm run gate:local` now runs the live-Postgres lane.** With GitHub Actions
1316
+ billing-blocked, `gate:local` is the only gate — and it ran only the redis-only lane, while
1317
+ **five of the six `REQUIRED_PROOFS`** are scheduled solely by `test:postgres`: the
1318
+ crown-jewel no-double-charge dedup, the two-tenant isolation E2E, the workspace-stamped
1319
+ audit plane, the StatusStore conformance suite, and the new transport arm. Those had gated
1320
+ nothing since Actions went quiet. The gate now probes for a reachable database by
1321
+ *connecting* (not by checking whether a variable is set), arms the same
1322
+ `ANVIL_REQUIRE_POSTGRES_TESTS=1` tripwire CI used, and reports **PARTIAL** — never GREEN —
1323
+ when it cannot run, naming each proof that did not execute.
1324
+
1325
+ ### Security
1326
+
1327
+ - **`/v1/guard` validates the new structured context and refuses rather than narrows.**
1328
+ Carrying `workflow` and `webhook` means accepting untrusted structured input on the money
1329
+ path; `src/hosted-guard-context.ts` answers **400** on a malformed field instead of dropping
1330
+ it, because silently continuing without it is the same defect class one layer down. Absent
1331
+ stays free. It is a separate leaf module so it is unit-testable — `src/api-server.ts` calls
1332
+ `start()` at module scope and cannot be imported by a test.
1333
+ - **`currentAttempt` is deliberately not read off the wire.** A client-supplied attempt count
1334
+ is a client-supplied way to defeat its own `max_retries` cap. Absent, the rule falls back to
1335
+ `workflow.retryCount`, exactly as the local engine does under the same absence.
1336
+
1337
+ ## [0.3.4] (continued) — Ghost perimeter closed; tenancy boundary fails closed; custom-code naming pinned
1338
+
1339
+ ### Security — the ghost server's perimeter is closed
1340
+
1341
+ - **`src/server.ts` had no authentication concept at all, and it is the service on
1342
+ `go.anvilcontrol.ai`.** `grep -c ANVIL_CONTROL_TOKEN src/server.ts` returned 0 across
1343
+ 5,455 lines; the request handler's entire prologue was CORS, security headers, a
1344
+ cache-control header and an OPTIONS 204. Confirmed live while writing this entry, with
1345
+ status codes only: `GET /anvil/actions/dashboard` returned **27,080 bytes** of real
1346
+ feed — durable keys, cent amounts, verdicts, current enforcement mode — and `GET /app`
1347
+ returned **2,014,172 bytes** of the full product dashboard, both to an anonymous
1348
+ `curl`. In the same ungated router sat `POST /anvil/actions/mode` and
1349
+ `POST /anvil/ghost/enforce` (which flip enforcement, the second one bypassing the
1350
+ five-character downgrade-reason gate its sibling enforces) and `POST /anvil/ghost/wrap`,
1351
+ a filesystem walk that **rewrites source files** on the container. CORS never helped:
1352
+ it governs what a browser may *read* cross-origin, not whether the request runs.
1353
+ There is now **one prefix gate** at the top of `handleRequest`, above every route, so a
1354
+ route added under `/anvil/` tomorrow is closed the moment it exists — auth at the
1355
+ router prefix, not a per-handler list someone forgets to append to, which is exactly
1356
+ how this happened (the identical `/anvil/*` surface on the control plane has been gated
1357
+ since it was written; only the ghost twin was forgotten, and only the gated copy had
1358
+ tests). The ladder is byte-for-byte the control plane's, so an operator holds one
1359
+ secret: a configured `ANVIL_CONTROL_TOKEN` / `POLICY_IMPORT_TOKEN` is enforced in every
1360
+ environment; production with no token **fails closed** (401), overridable only by the
1361
+ explicit `ANVIL_ALLOW_INSECURE_PROD=true` assertion that a proxy authenticates; and
1362
+ non-production with no token stays **open**, so the local `npx` walkthrough is
1363
+ untouched. `?token=` authorizes reads only and is banked into an
1364
+ `HttpOnly; Secure; SameSite=Strict` session on a page navigation — a URL-parameter
1365
+ token must never flip enforcement, because that is reachable from any link on the
1366
+ internet.
1367
+ - **`/app` now forwards to the sign-in-gated control plane** instead of serving the ghost
1368
+ server's own ungated copy of the dashboard, joining `/tour`, `/intro` and `/start` in
1369
+ `ONBOARDING_FUNNEL_PATHS`. In single-service dev the target resolves to this server's
1370
+ own origin, so `/app` is still served locally and nothing local changed.
1371
+ - **Cookies are Secure by default.** `buildCookieAttributes()` defaulted `secure` to
1372
+ false, and the two call sites relying on that default — the ghost session cookie and
1373
+ the Stripe Connect OAuth `state` cookie, which *is* a CSRF double-submit token —
1374
+ therefore shipped without `Secure` over real HTTPS, so one plaintext request disclosed
1375
+ them. The default is now `IS_PROD`, so a new cookie cannot repeat the omission.
1376
+ - **The guard API ships security headers.** `src/security-headers.ts` had exactly one
1377
+ importer, so `api.anvilcontrol.ai` — the host carrying every `anv_live_` bearer key and
1378
+ every money decision — served no HSTS, no nosniff and no framing policy. A new
1379
+ `apiSecurityHeaders()` (stricter than the ghost variant: `DENY` framing,
1380
+ `default-src 'none'`, `cross-origin-resource-policy: same-origin`) is applied once at
1381
+ the `router()` choke point, so JSON, metrics text and the error paths are all covered.
1382
+ - **The wrap endpoint's filesystem walk is bounded, and honest when it stops.** It is
1383
+ **synchronous**, so while it runs the ghost server's event loop is stopped and every
1384
+ other request — health probe included — waits behind it. The old bound guarded whether
1385
+ to enqueue a directory on the *file* count, which a million-directory tree never trips;
1386
+ pointing it at `/tmp` stalled the process for minutes (measured). It now bounds
1387
+ directories, files and wall-clock, and returns `scan-truncated` / `partial: true` rather
1388
+ than letting "we stopped looking" read as "your project has no call site". Symlinked
1389
+ directories were already skipped by `withFileTypes`; there is now a test that says so.
1390
+ - **The perimeter is now proven against STATE, not status codes.** Every original assertion
1391
+ was about a *response*, which is not the product's claim: "POST /anvil/actions/mode returns
1392
+ 401" and "an anonymous caller cannot weaken your protection" are different sentences, and a
1393
+ refactor that moved the write earlier — into a body-parse side effect, a middleware, or a
1394
+ handler hoisted above the gate — would have kept all of them green while a stranger
1395
+ downgraded a tenant from enforce to ghost. The suite now seeds `enforce`, runs the attack,
1396
+ and reads the resolved mode back; it does the same for `POST /anvil/ghost/enforce` (the
1397
+ sibling that takes a bare boolean and never asks for the downgrade reason), and for
1398
+ `POST /anvil/ghost/wrap` it asserts the source file is **byte-identical** with no `.anvil-bak`
1399
+ written. Each is a positive/negative pair — the same operation with the operator credential
1400
+ *does* take effect — because "unchanged" proves nothing when the fixture was inert or the
1401
+ read-back was stale. Both halves were needed: the first fixture used a camelCase call the
1402
+ codemod patches but the endpoint's safety check rejects, so the refused-wrap assertion was
1403
+ passing for the wrong reason. Verified by mutation: hoisting an enforcement write above the
1404
+ gate turns exactly these three red, each naming its consequence, while every status-code
1405
+ assertion stays green.
1406
+ - **…and in the posture the service actually ships in.** Reading state back needs a credential,
1407
+ so the block above exercises the `token` branch — but the ghost service carries no control
1408
+ token today, which means production will run `fail-closed`. That branch is now covered by two
1409
+ processes sharing one control store: a dev-mode reader seeds and observes, the token-less
1410
+ production box takes the attack. Mutation testing also caught this pair silently passing at
1411
+ first: the reader was serving a 3-second-stale cache (`ANVIL_CONTROL_CACHE_TTL_MS`), so the
1412
+ attacker's write had landed and the observer still reported "unchanged" — the exact false
1413
+ green the pairs exist to prevent, found only because the mutation was run.
1414
+ - **A green blocking lane can no longer skip its crown jewels.** `verifyRequiredProofs` — which
1415
+ reads vitest's JSON report and fails a lane whose declared proof produced zero passing tests —
1416
+ was wired only into `run-lane-files.mjs` (the service lanes). The blocking lane had no such
1417
+ check, so a proof renamed, moved or globbed out would shrink the lane silently. It is wired in
1418
+ now, blocking-lane only, and `tests/ghost-server-perimeter.test.ts` is a declared proof with a
1419
+ floor of 60. **The first implementation contained the very bug it exists to prevent**: it
1420
+ asked whether the proof was still in the lane's scheduled file list, so renaming the file
1421
+ removed it from the list, which switched the check off, which reported green. Ownership now
1422
+ comes from the manifest (`laneFor`), never from what the lane happened to collect. Verified by
1423
+ running the real runner against a scratch lane: proof present → exit 0; gutted below its floor
1424
+ → exit 1; renamed with an otherwise perfectly green lane → exit 1.
1425
+ - **`REQUIRED_PROOFS` itself is gated.** An entry nobody can execute is worse than no entry: it
1426
+ reads as coverage while providing none — the same defect the quarantine's filename globs were,
1427
+ one level up. `check:ci-quarantine` now refuses a proof whose file does not exist, that no lane
1428
+ collects, that is also declared red-on-purpose, that is duplicated, that carries a zero floor or
1429
+ no stated claim, or that is quarantined without any service lane scheduling it (the flaky lane
1430
+ is continue-on-error, so a proof living only there is a declaration with no gate behind it).
1431
+ - **Three new gates, and they were red against production before this shipped.**
1432
+ `scripts/check-ghost-perimeter.mjs` (wired into `npm run verify` and CI) parses
1433
+ `src/server.ts` and fails the build if the gate stops running above every route, stops
1434
+ failing closed in production, loses constant-time comparison, lets a query token
1435
+ authorize a write, or if any mutating route is neither perimeter-gated nor carrying a
1436
+ written-down reason it is public. `tests/ghost-server-perimeter.test.ts` boots the real
1437
+ server in all three postures and **parses the route list out of the source** rather than
1438
+ hand-writing it, so a new route is probed the moment it exists. And
1439
+ `check:serving-drift` gained live assertions that `go.anvilcontrol.ai/anvil/*` is 401
1440
+ and `/app` is a 302 — both of which fail against production today and describe the fix
1441
+ in their own failure text.
1442
+
1443
+ ### Everything else
1444
+
1445
+ - **The latency harness fired real money-path calls at production without anyone
1446
+ typing a flag. It can't now.** `scripts/spike-hosted-parity.mjs` read its remote
1447
+ credential as `--api-key` *falling back to* `process.env.ANVIL_API_KEY` — and the
1448
+ harness imports `src/policy.js` for its fixture validators, which pulls in
1449
+ `src/config.ts`, which autoloads the repo's `.env`, which is where `anvil protect`
1450
+ writes that variable. So simply running the read-only transit measurement from a
1451
+ normal checkout fired 25 real `/v1/guard` calls at a live tenant: receipts, usage
1452
+ rows, idempotency claims and completions, with the flag that was supposed to be the
1453
+ consent left untyped. `--base <url>` alone now measures transit against an
1454
+ unauthenticated static endpoint and writes nothing; the writing phase requires
1455
+ consent that had to be typed (`--api-key`, or `ANVIL_SPIKE_API_KEY` — a name nothing
1456
+ in this repo, no `.env` and no deploy sets), and a bare `ANVIL_API_KEY` is ignored
1457
+ *and said to be ignored*. `resolveRemoteApiKey()` is a pure exported function so the
1458
+ most consequential branch in that file is provable in a unit test instead of by
1459
+ observing the damage.
1460
+ - **"Could not be evaluated" was being reported as "BLOWN".** The server-side budget
1461
+ verdict was a boolean computed as `samples > 0 && inside…`, so a run that collected
1462
+ no `Server-Timing` samples printed a latency *failure* for a run that measured no
1463
+ latency at all. It is now three-valued (`inside` / `blown` / `unmeasurable` /
1464
+ `skipped`), and the exit code reads `ok === false` rather than `!ok`. Not
1465
+ hypothetical: the deployed api-server predates the header, so the first honest
1466
+ measurement against it would have reported a fabricated regression.
1467
+ - **Transit was computed by subtracting percentiles, which is not how percentiles
1468
+ work.** `p95(end-to-end) − p95(server-side)` assumes the call with the 95th-percentile
1469
+ end-to-end is the call with the 95th-percentile server time. Where a response carries
1470
+ `Server-Timing`, both halves are known for the *same* request, so per-call transit is
1471
+ now collected directly and summarised. The old figure is retained under its old name
1472
+ so previously-reported numbers stay readable.
1473
+ - **End-to-end latency is now measured against the real deployment, per origin.**
1474
+ Everything measured before was server-side processing over loopback. The harness's
1475
+ remote mode is real: it reports the edge it reached, the transit reference, the
1476
+ cold-connection cost (a caller's *first* call pays DNS + TCP + TLS — measured at
1477
+ +52.6ms, which is 71% of the 125ms budget), and a per-origin verdict that
1478
+ distinguishes a measurement from a bound from a genuine unknown. Results live in
1479
+ `scripts/spike-parity-origins.json` and generate the table in the rollout doc;
1480
+ `npm run check:parity-origins` fails if the doc drifts from the record, so a number
1481
+ in a markdown table can no longer be true only on the day it was typed.
1482
+ - **…and those measurements now expire.** Proving the doc matches the record proves
1483
+ nothing about the record still matching reality: a deployment can change region, gain
1484
+ a replica or move behind a different edge without one line of this repo changing,
1485
+ while the rollout doc keeps quoting numbers nobody has re-checked. Every origin row
1486
+ carries a **90-day shelf life**, and a measurement past it — or a declared-but-never
1487
+ -measured origin past its `dueBy` — fails `check:parity-origins` and a blocking-lane
1488
+ test until it is re-taken. The remedy is one command that needs no credential and
1489
+ writes nothing, which is what stops this becoming a gate someone deletes. A stale row
1490
+ reports `ok: null` rather than `false`, because an expired measurement is *unknown*,
1491
+ not *bad*; and the rendered table carries dates rather than ages, so the
1492
+ byte-compared doc cannot drift a little every night and red the gate having detected
1493
+ only the passage of time.
1494
+ - **The pre-flight's coverage set is now derived from the code that evaluates, not
1495
+ declared beside it.** `PREFLIGHT_COVERED_PRIMITIVES` was a hand-written array, and
1496
+ `coveredPrimitivesFor()` a second hand-written copy of the same predicate — so the
1497
+ invariant guarding hosted customers ("the pre-flight covers every primitive the
1498
+ hosted plane excludes") compared one hand-maintained list against another. That
1499
+ proves *"it appears in an array someone maintains"*, never *"it is actually
1500
+ evaluated"*, and the two come apart silently in the direction that matters: add an
1501
+ entry without wiring the evaluation and the tripwire stays green while the gap it
1502
+ exists to detect is wide open. Since hosted structurally refuses to execute customer
1503
+ code (a threat-model decision, not a deferral), the pre-flight is the only thing
1504
+ between "hosted excludes it" and "it is enforced nowhere", with the dashboard still
1505
+ rendering the rule as active. There is now one table — `CUSTOMER_CODE_SURFACES` in
1506
+ `src/policy.ts` — that `evaluateCustomRuleCodeOnly()` iterates to decide what to run,
1507
+ and the covered set, the per-call coverage report and `policyDeclaresCustomRuleCode()`
1508
+ are all read off it. Deleting a surface's evaluation turns the invariant red with the
1509
+ primitive named. Ten deliberate regressions were run against the new suite (hand-written
1510
+ literal, gutted evaluation, deleted surface, lost `continue`, lost ghost demotion,
1511
+ hand-written coverage report, lost ghost observation, hosted claiming customer code,
1512
+ and hosted no longer stripping either surface) and all ten fail loudly.
1513
+ - **The latency harness measures under concurrency, times the block path, and reports a
1514
+ delta.** Three narrowings, each of which made the number mean less than it looked.
1515
+ It fired **serially**, so a single event loop and a small pg pool were never contended
1516
+ and the reported p99 was a floor rather than a customer experience — the queuing and
1517
+ pool saturation that appear at 50 in-flight are structurally invisible at 1, and the
1518
+ 40ms budget exists to make hosted enforcement viable on a *payment* path, which is
1519
+ concurrent by definition. It measured only the **allow** path, while `handleGuard`'s
1520
+ block path does strictly more work (a blocked receipt written, a block counter observed)
1521
+ and is the branch a customer hits during an incident. And it **compared nothing**: a PR
1522
+ that doubled guard latency printed `p95 2.7ms → 5.4ms`, still said INSIDE BUDGET, and
1523
+ nobody looked — the artifact moved the archaeology from a commit message to a JSON file
1524
+ without removing it. `--concurrency N` (default 1, so every prior number stays
1525
+ comparable) warms up through the same scheduler so the pool warms under the shape being
1526
+ measured; the block path gets its own row and is never averaged in; and a committed
1527
+ `scripts/spike-parity-baseline.json` drives a printed delta that flags a p99 at ≥1.5×,
1528
+ on the tail with headroom and still non-blocking. A missing baseline reports **not
1529
+ compared**, never `1.0×`; a baseline from a different concurrency or mode is refused
1530
+ rather than compared against a different experiment; and `--update-baseline` is explicit,
1531
+ so moving the reference is a reviewable line in a PR rather than CI silently ratcheting
1532
+ it to whatever the last merge did. The scheduler and the comparison are unit-tested in
1533
+ the blocking lane against an in-process HTTP stub — real sockets and a real
1534
+ `Server-Timing` parse, no Postgres, no Redis, no api-server.
1535
+ - **…and the measurement it enabled, which found something.** Run against a real
1536
+ api-server + Redis + Postgres: server-side p50 tracks concurrency almost exactly
1537
+ linearly (`≈0.55ms × N`) and **p95 crosses the 40ms budget between 25 and 50 in-flight
1538
+ requests** — the signature of a serialized resource rather than spare capacity, and the
1539
+ condition the parity spec said to watch for. Recorded with its caveats (one box ran both
1540
+ the load generator and the server, so it is a lower bound on capacity) in
1541
+ `docs/HOSTED_ENFORCEMENT_PARITY_V1_SPEC.md` §Step 1, next to the rollout gate that has
1542
+ to argue from it. The block path turns out to be consistently *faster* than allow,
1543
+ because an enforce block refuses before claiming the idempotency key.
1544
+ - **The regression flag it shipped with was wrong, and the measurement proved it.** Three
1545
+ passes of one unchanged commit produced p95 = 5.85 / 2.04 / 14.17ms — a 7× spread from
1546
+ nothing, because the box was still settling from an unrelated test run. A `p99 ≥ 1.5×`
1547
+ threshold on that fires constantly, which the spec warns gets a latency gate disabled
1548
+ inside a week; it also set a threshold before having any variance data, which the same
1549
+ spec explicitly says not to do. `--update-baseline` now records the **median of N passes
1550
+ plus the observed spread**, and a run is flagged only when it lands outside that spread
1551
+ *and* past the factor. A baseline with no variance data reports the delta and flags
1552
+ nothing. The baseline lives at `scripts/spike-parity-baseline.json`,
1553
+ beside the script that owns it and following `scripts/egress-perf-baseline.json` —
1554
+ NOT under `artifacts/`, which is runtime output that `check:clean-state` correctly
1555
+ refuses to let anyone commit. The baseline also records a stable, non-identifying HOST
1556
+ fingerprint (platform / arch / cores / CPU model / Node major) and refuses a comparison
1557
+ across machines — a CI runner and a laptop are both `concurrency=1, mode=local`, so
1558
+ without it the first CI delta would report different silicon as a code regression.
1559
+ - **The local evaluator now runs the same customer-code dispatch as the hosted pre-flight.**
1560
+ Deriving the coverage set from a table is only worth something if that table is the one
1561
+ everybody uses, and it was not: `evaluatePolicyWithLatency` called the two customer-code
1562
+ helpers by hand at two more sites — the rules branch and the legacy-limits branch — each
1563
+ followed by its own copy of "carry the audit evidence forward on the allow path". Three
1564
+ copies of one ordering, one short-circuit and one evidence-merge, so a surface added to
1565
+ the table would have evaluated on the hosted transport and silently done nothing locally.
1566
+ The second branch was also unreachable for any policy that came off disk (the loader
1567
+ requires a `limits` entry per allowed action), i.e. dead code nothing would have noticed
1568
+ rotting. There is now one loop, `evaluateCustomCodeIfDeclared` and `runCustomPolicyRule`
1569
+ have exactly one call site each, and that is pinned structurally. One behaviour was
1570
+ unified on purpose: the two paths short-circuited on different facts — the evaluator on
1571
+ the mode-demoted `blocked`, the pre-flight on the pre-demotion `wouldBlock` — which agree
1572
+ in enforce but diverge in ghost, where the local path fell through to the legacy handler
1573
+ after the sandbox had already would-blocked and reported a rule enforce would never have
1574
+ reached. Both stop at `wouldBlock` now. No call changes outcome (ghost blocks nothing
1575
+ either way; enforce is byte-identical); only the observation gets truer.
1576
+ - **A hosted tenant is no longer told their working custom rule is inert.** The dashboard
1577
+ drove the custom-rule row off `enforced_on_your_runtime`, which asks only about the
1578
+ BACKING runtime — and for customer code the honest hosted answer is permanently `false`,
1579
+ because the hosted plane strips it from every snapshot by design. So a rule that was
1580
+ blocking calls on every request read "compiles clean · runs when enforcement is live".
1581
+ That is the mirror of the bug the runtime-truth contract exists to prevent: an underclaim
1582
+ rather than an overclaim, and the more corrosive direction, because a customer who
1583
+ believes a control is inert either turns it off or stops trusting every other badge
1584
+ beside it. Closed as a SECOND fact rather than a widened first one — the api-server
1585
+ genuinely does not evaluate customer code, so `enforcedPrimitives` must not claim it.
1586
+ `RuntimeTruth.sdkEvaluatedPrimitives` is supplied from the derived surface table (not a
1587
+ re-typed list; `runtime-truth.ts` stays a dependency-free leaf), `whereEnforced()` answers
1588
+ `runtime | sdk | nowhere`, and `isPrimitiveEnforced()` keeps its exact original meaning so
1589
+ no existing caller moves. And the claim is corroborated rather than asserted:
1590
+ `enforced_where` is architectural and stays true for a customer running an SDK too old to
1591
+ have the pre-flight, so `/api/custom-rules/health` also reports `sdk_preflight_observed`,
1592
+ read off the `locallyEvaluatedPrimitives` the SDK itself wrote onto a receipt — which
1593
+ cannot exist unless the pre-flight actually ran. Present tense only when a receipt backs
1594
+ it; three-valued, so "no receipts yet" renders as neither claim. That evidence scan reads
1595
+ a **bounded tail** (512KB) rather than the whole audit log: the dashboard polls this
1596
+ endpoint every 10 seconds and an audit log is append-only, so a whole-file read gets
1597
+ slower and hungrier every day a deploy runs — the same unbounded-journal-read defect the
1598
+ receipt store already had to fix. The first version of this shipped the unbounded read and
1599
+ a timing assertion that failed to catch it (12MB reads in ~50ms, so no threshold a test
1600
+ can afford discriminates); the property is now pinned at the source, with the test saying
1601
+ plainly why it cannot be pinned behaviourally.
1602
+ - **…and the two other surfaces that carried the same half-answer.** The calm
1603
+ not-enforcing banner said "Observing, not enforcing. … Nothing is blocked yet." — a
1604
+ claim about the whole product that stops being true on a hosted backing, where the SDK
1605
+ pre-flight is blocking calls on the customer's own machine. It now amends that sentence
1606
+ when the SDK covers something, from the same derived set the rule row uses, and keeps the
1607
+ original wording on a backing we cannot place (so the fix is not a blanket claim). And
1608
+ the per-rule chip rendered "observed · not blocking here" for anything the runtime does
1609
+ not cover — correct for an approval rule on hosted, wrong for customer code — so it gains
1610
+ a `sdkEvaluatesPrimitive()` sibling mirroring `whereEnforced()`, with the runtime
1611
+ predicate untouched so no existing badge changed meaning. Both are pinned by a jsdom test
1612
+ that runs the shipping functions; the first version of the chip check was a
1613
+ source-substring assertion that a rename walked straight through, and the mutation pass
1614
+ caught it.
1615
+ - **The "no gap between hosted and the pre-flight" tripwire was inert on this branch,
1616
+ and now is not.** It read a hosted DENYLIST that does not exist yet (Step 3 has not
1617
+ landed), found none, and asserted only that the module was still an array. Restated as
1618
+ a partition that is checkable on the current allowlist: no customer-code primitive may
1619
+ appear in the hosted enforced set, and `stripUnsupportedForHosted()` must physically
1620
+ delete both customer-code surfaces from every snapshot. Adding `custom_code_rule` to
1621
+ the hosted list — which would put "Enforcing" on a dashboard row for a rule the runtime
1622
+ strips — now fails the suite.
1623
+ - **`Server-Timing: app;dur` on every api-server response.** The hosted-parity budget is
1624
+ two numbers because only one of them is ours: server-side processing is what this code
1625
+ controls, and the rest of a customer's end-to-end latency is transit. Without the header
1626
+ the same 300ms reads as "the evaluator got slow" and as "the caller is a continent
1627
+ away", and only one is a bug to fix here. Stamped once at the socket edge — before
1628
+ routing, before auth — so it covers the auth hop and the policy-snapshot read, which are
1629
+ the two places a regression would hide, and emitted on the unauthenticated surfaces and
1630
+ error paths too, so `curl -i` verifies the split without a key.
1631
+ - **`npm run spike:parity` — the Step-1 latency measurement is repeatable and recorded.**
1632
+ The harness that produced the numbers the parity spec turns on was a script someone ran
1633
+ once, referenced by no `package.json` entry and no workflow, on a branch this one is not.
1634
+ It now runs from `package.json` and from a **non-blocking** `spike-parity` CI job on the
1635
+ same Postgres + Redis containers the blocking lane provisions, writing p50/p95/p99 to the
1636
+ job summary and a JSON report as an artifact. Non-blocking is deliberate: a latency gate
1637
+ that flakes on shared runners gets disabled within a week, which is worse than no gate.
1638
+ Three things make the number honest rather than merely present — the fixture is run
1639
+ through the REAL policy and control-config validators before it is used (a rejected
1640
+ policy makes the api-server degrade to idempotency-only, and an abbreviated control
1641
+ config is coerced to ghost, either of which reports a beautiful latency for an evaluator
1642
+ that never ran); the presence of the stateful primitives is asserted so the fixture
1643
+ cannot be quietly trimmed; and enforcement expectations are derived from
1644
+ `src/hosted-primitives.ts` rather than hardcoded, so a primitive the runtime *claims* but
1645
+ does not hold is reported as an OVERCLAIM and exits non-zero.
1646
+
1647
+ - **A receipt now proves its amount at the currency's own exponent.**
1648
+ `buildReceiptValueProof` — the evidence surface behind `anvil verify` and the
1649
+ exported `ReceiptValueProof`, the thing an operator shows someone else — took the
1650
+ receipt's currency, handed it to `Intl` with `style: 'currency'`, and then divided
1651
+ the MINOR amount by a hardcoded 100. Right for USD, wrong for every other
1652
+ exponent: a 500-sen JPY charge proved itself as "¥5" and a 5,000-fils BHD one as
1653
+ "BHD 5.00" instead of "BHD 5.000". The currency was already in hand; only the
1654
+ exponent was missing. Routed through the shared formatter with the rest.
1655
+ - **`check:money-format` now catches the shape that produced it.** A new rule fails
1656
+ the build when a function ACCEPTS a currency and still divides by a literal 100 —
1657
+ the caller has said the amount might not be dollars, so ignoring the exponent is
1658
+ a bug rather than a simplification. Deliberately narrow: a blanket "/100 near
1659
+ money" rule matches 13 places in this tree, every one a correct USD-only
1660
+ formatter over a `*_cents` field with no currency in scope, and a gate that cries
1661
+ wolf gets bypassed. Both instances the narrow rule caught (`moneyShort` in the
1662
+ api-server, `formatAmountInCurrency` in proof.ts) are fixed, so it enforces at
1663
+ zero false positives.
1664
+
1665
+ - **A looser rule can no longer switch a configured legacy ceiling off.** With the
1666
+ rule-vs-rule ordering defect closed, one path was left where *adding* a rule
1667
+ still widened a money policy: `limits[action].max_amount` went inert the moment
1668
+ any `amount_cap` rule applied, so a legacy $50 ceiling that gained a looser
1669
+ $5,000 rule started allowing $5,000 charges — 100x wider, one rule, no ordering
1670
+ required. Legacy is now a candidate in the same strictest-wins fold: it always
1671
+ enforces, and `EffectiveConfig.amountCap` reports whichever ceiling actually
1672
+ decides, so the displayed number stays the enforced one. Precedence still means
1673
+ what it should — a rule replaces the legacy field as the thing the dashboard
1674
+ names and the operator edits, and the loader's warning now points at
1675
+ `scripts/migrate-legacy-policies.mjs` instead of telling operators to delete one
1676
+ of the two (advice that could delete the stricter one). `workflow_limits.max_spend`
1677
+ gets the projection half of the same fix: it already enforced unconditionally
1678
+ (guard.ts turns on spend accounting from it alone), so the dashboard could show a
1679
+ looser rule's budget while the runtime stopped the workflow at the legacy one.
1680
+ Verified against the differential parity corpus: 33 expected-red divergences
1681
+ before and after, none new — hosted and local agree by construction, since hosted
1682
+ keeps `limits[].max_amount` through `stripUnsupportedForHosted` and calls the
1683
+ same `evaluatePolicy`.
1684
+ - **`npm run smoke:pack` now proves the shipped scripts can reach their siblings.**
1685
+ `scripts/policy-diff.mjs` — which the control plane imports to build the
1686
+ activation-consent diff — has a hard top-level import of
1687
+ `scripts/anvil-money-format.browser.js`. A sibling reached by relative import is
1688
+ invisible to every other probe: no entry point pulls it in, the export map never
1689
+ mentions it, and `npm run build` does not touch it. Drop it from package.json
1690
+ `files` and policy ACTIVATION dies with `ERR_MODULE_NOT_FOUND` for every
1691
+ installed consumer, from a green build. Pack-smoke now imports each such script
1692
+ from the installed tarball and asserts the helper renders 100000 USD minor as
1693
+ `$1,000.00`.
1694
+
1695
+ - **Money units and rule composition: three unconditional fail-open defects on the
1696
+ money path are closed.** None needed an outage, a misconfiguration or an attacker —
1697
+ only a customer writing two rules in the natural order.
1698
+ - **Rule order no longer drops the stricter cap.** `amount_cap` is declared
1699
+ `composable`, but the resolver took the first match with `.find()` and the runtime
1700
+ let any unscoped rule re-use that single resolved cap. A policy of
1701
+ `[$5,000 cap, $500 cap]` **allowed a $4,000 charge**; reversed, it blocked — and
1702
+ unscoped-first is exactly what the prose importer emits. `computeEffectiveConfig`
1703
+ now folds every applicable rule into `EffectiveConfig.amountCaps` and reports the
1704
+ **strictest** as `amountCap`; `evalAmountCap` looks its own rule up by id, so each
1705
+ cap enforces its own ceiling and the verdict composes as "all must pass". The same
1706
+ strictest-wins fold now covers every composable primitive. This makes the docs'
1707
+ long-standing promise — "adding a rule can only tighten a policy, never quietly
1708
+ weaken it" — true.
1709
+ - **A workflow spend cap no longer permits 100× its ceiling.** `evalWorkflowSpendCap`
1710
+ divided the caller's `spendCents` by 100 and compared the result against a
1711
+ minor-unit cap, on the branch `anvil.guard()` reaches whenever `spendByCurrency`
1712
+ is absent — the default. A $1,000-per-run cap allowed $100,000. Both spend
1713
+ counters are now compared minor-against-minor, and `WorkflowExecutionState`'s doc
1714
+ comment (which claimed `spendByCurrency` was *major*) matches the runtime.
1715
+ - **The dashboard no longer displays money 100× too large.** Every served page
1716
+ rendered an `amount_currency` object as `$` plus the raw minor integer — including
1717
+ the **"Activate these policy changes?" consent diff**, so an operator approved
1718
+ `$100,000` and was protected at `$1,000`. All money now routes through one
1719
+ exponent-aware helper: `src/primitives/money-format.ts` for the TypeScript tree
1720
+ (replacing five separate copies of the ISO-4217 exponent table) and a generated
1721
+ twin inlined into every served page. New `npm run check:money-format` gate fails
1722
+ the build on drift, on a page that hand-rolls a formatter, or on a second exponent
1723
+ table; `npm run fix:money-format` re-inlines the canonical helper.
1724
+ - **Also fixed while in here:** a `unit: 'major'` cap of `20.15` refused a `$20.15`
1725
+ charge (IEEE-754: `20.15 * 100` is `2014.9999999999998`); the redundancy modal ranked
1726
+ a `unit:'major'` rule above an equally strict minor-authored one and offered to delete
1727
+ the rule that was actually enforcing, and could mark a cap "dead" against a rule in a
1728
+ currency it does not enforce against; `confirmation_gate.amount_over` rendered raw
1729
+ minor units in the policy API, the ops dashboard, the approval webhook and the
1730
+ approval card; and `workflow_spend_cap` went silently dormant when it had no spend
1731
+ counter to read, while its sibling workflow primitives already announced it.
1732
+
1733
+ - **Forgetting the tenant boundary entirely is now caught too, not just a wrong id.**
1734
+ A code path that never opens a workspace context still resolved every per-tenant key
1735
+ to the shared `ws_default` namespace — the same cross-tenant pooling as a wrong id,
1736
+ reached by a different mistake. `namespaceKey()` now refuses that in production
1737
+ (`AnvilWorkspaceContextMissingError`, `code: 'WORKSPACE_CONTEXT_MISSING'`, exported)
1738
+ and warns once per store family in dev — but **only after this process has opened a
1739
+ real tenant context**, so a single-tenant self-host, the SDK's own `guard()` path, the
1740
+ CLI and readiness/boot probes (all of which read tenant stores with no context by
1741
+ design) are never affected. New `runOutsideWorkspace('why', …)` is the explicit escape
1742
+ hatch for genuinely fleet-wide work (a cross-tenant sweep, a boot read). The error
1743
+ names the store family only — never the caller-supplied key, which can carry a
1744
+ customer id.
1745
+ - **A workspace id Anvil does not recognise is now refused in production, not shared.**
1746
+ `runInWorkspace()` used to coerce an unrecognised tenant id to the reserved
1747
+ `ws_default` namespace — silently, with no error and no log. That is the wrong
1748
+ polarity for a tenancy boundary: the coerced request still returns 200 while every
1749
+ tenant's spend counters, approval queue and counterparty trust pool into one
1750
+ namespace. Under `NODE_ENV=production` it now throws `AnvilWorkspaceBoundaryError`
1751
+ (exported from the package, `code: 'WORKSPACE_BOUNDARY'`), naming the *shape* of the
1752
+ id it received rather than echoing the value. Dev and test keep the old coercion, so
1753
+ local single-tenant runs and un-wrapped SDK paths degrade instead of crashing.
1754
+ **Only reachable if a caller skips validation:** both shipped entry points already
1755
+ validate first, so no supported configuration changes behaviour.
1756
+ - **`runInWorkspace(undefined)` no longer throws a raw `TypeError`.** A nullish context
1757
+ is now just another unrecognised id — coerced in dev/test, refused in production —
1758
+ so the fail-safe half of the contract actually holds where it was meant to.
1759
+ - **The custom-rules health endpoint asked the wrong question.**
1760
+ `/api/custom-rules/health` reported `enforced_on_your_runtime` by asking whether the
1761
+ runtime enforces `custom_code` — the *authoring* primitive id — against lists built
1762
+ from *runtime* ids (`custom_code_rule`). It answered correctly only by accident. It
1763
+ now asks with the runtime id, so it cannot start over-claiming that customer code
1764
+ runs on a runtime that strips it.
1765
+ - **A hand-edited Anvil export no longer 500s the importer.** The `anvil_rules_json`
1766
+ round-trip carrier is the one place a rules array enters the importer without the
1767
+ parser producing it, and a malformed entry (missing `source`, unknown primitive,
1768
+ `null`) crashed policy import with an opaque error. Unusable entries are now refused
1769
+ individually and surfaced as visible notes — good rules in the same file still
1770
+ import, and nothing is dropped without a trace.
1771
+
1772
+ ## [0.3.4] (continued) — Operability and legal floor
1773
+
1774
+ The instrument panel, the paperwork, and a backup you can prove. None of this fixes a
1775
+ specific defect, which is why it was last — but without it you cannot *detect* an
1776
+ incident, *recover* from one, or *sell* around either.
1777
+
1778
+ - **The package has a license.** `npm view @useanvil/sdk` returned nothing for `license`,
1779
+ `repository`, `bugs`, `author`, or `homepage`, so npm rendered it all-rights-reserved
1780
+ and every serious design partner's legal review stopped there. Added a `LICENSE`
1781
+ (**BUSL-1.1**, with a production-use grant that has no seat or volume limit and a
1782
+ Change Date of 2030-07-29 to MPL-2.0) plus all five metadata fields. Chosen
1783
+ deliberately and reversibly: the npm tarball already ships the full `src/**/*.ts`
1784
+ (the control plane runs from source under `tsx`), so a permissive license would have
1785
+ irrevocably open-sourced the hosted product, while BUSL is a published, SCA-resolvable
1786
+ license that can be relaxed later and never tightened. `LICENSE` and `SECURITY.md` now
1787
+ ship in the tarball and count as publish-affecting in `check:release`.
1788
+ - **There is somewhere to report a vulnerability.** New `SECURITY.md`: a monitored
1789
+ address, per-stage response commitments (1 business day to acknowledge, 3 to triage,
1790
+ 7 days for anything that moves money incorrectly), safe harbour, and an explicit scope
1791
+ that names the anonymous ghost intake as the highest-value target. It says out loud
1792
+ that there is no paid bounty and that redaction is pattern-based, not DLP.
1793
+ - **The money path has telemetry.** `/metrics` exposed four `anvil_replay_*` families —
1794
+ the dashboard *sandbox* — and not one counter for `/v1/guard`. You could not answer,
1795
+ ever, after the fact: *how many guard calls executed money unguarded today?* New
1796
+ `anvil_guard_*` families cover requests, verdicts, blocks by primitive **and mode**
1797
+ (so a ghost fleet stops reporting zero blocks while catching plenty), dedup claims —
1798
+ with `duplicate_unresolved` separated from `duplicate_executed`, the only place the
1799
+ difference between "we stopped a re-execution" and "nobody proved the first one ran"
1800
+ survives — policy-eval outcomes, and **fail-opens**. The per-workspace rate limiter and
1801
+ hosted policy evaluation both degrade open by design; both were completely silent.
1802
+ Workspace labels are a `sha256` digest with bounded cardinality and a visible overflow
1803
+ counter, because `/metrics` is unauthenticated and sits outside the tenant boundary.
1804
+ - **Readiness is watchable.** The api-server — the box that moves money — had no
1805
+ readiness probe at all. Added unauthenticated `GET|HEAD /v1/ready` + `/readyz`: 503
1806
+ when Redis (probed with a real SET/GET/DEL, because the money path *writes*
1807
+ idempotency claims) or Postgres is unreachable, with a posture-only body carrying no
1808
+ hostname, port, or driver text. `npm run monitor` now probes readiness alongside
1809
+ liveness and raises a distinct critical alert for "UP but NOT READY". `railway.toml`
1810
+ still health-checks the shallow `/v1/health` **on purpose** — readiness-gating a
1811
+ single-replica deploy would block the deploy that fixes the outage — and
1812
+ `docs/DEPLOY.md`, which claimed otherwise, now says what the code does.
1813
+ - **Backup is no longer a markdown file.** `preflight:golive`'s backup gate passed when
1814
+ `ANVIL_POSTGRES_URL` was set **and `docs/BACKUP_AND_RECOVERY.md` existed on disk** —
1815
+ both true on a box that had never taken a dump. `npm run backup:pg` now writes a
1816
+ receipt to `anvil_backup_runs` (migration 013) on every run, **failures included**,
1817
+ and the gate reads *that*: it blocks unless a dump succeeded in the last 48 h and a
1818
+ restore drill passed in the last 100 days. Added `npm run backup:pg:if-due` for a
1819
+ cheap frequent cron and `npm run drill:restore`, which restores into a scratch
1820
+ database, times it, compares row counts against the live source, and computes the
1821
+ concrete **RESTORE GRACE** deadline (`hold ANVIL_FAIL_MODE=graceful until <ts>`)
1822
+ instead of leaving the one unskippable step to a human's memory at 3am. It refuses any
1823
+ target that is not obviously scratch, with no override flag. A real drill has been run
1824
+ and timed; the number is in `docs/BACKUP_AND_RECOVERY.md`.
1825
+ - **The wire is versioned.** `makeAuthHeaders` sent only `Authorization` and
1826
+ `Content-Type`, so a guard call could not be attributed to a client build — which
1827
+ mattered the day `0.3.3` shipped broken and the only move was to publish and hope
1828
+ people read a changelog. Every hosted call now carries `x-anvil-sdk-version`, counted
1829
+ per workspace. Two opt-in floors, both unset by default: `ANVIL_SDK_WARN_BELOW` adds a
1830
+ `Warning` header, `ANVIL_SDK_MIN_VERSION` returns `426` on `/v1/guard` — never on
1831
+ `/v1/complete`, where refusing would strand an executed action's key `pending`. An
1832
+ absent or unparseable version is never refused, and the two stay distinguishable in
1833
+ the counters (`absent` vs `invalid`).
1834
+ - **The ghost intake says what it does with your logs.** The anonymous intake accepts
1835
+ pasted production logs plus live third-party credentials, and the only thing the screen
1836
+ said about any of it was "No training by default. Deletion guarantees for uploaded
1837
+ logs." — vague, and an overclaim, since nothing implements a deletion guarantee because
1838
+ nothing writes the log down. Replaced with a real disclosure rendered from the running
1839
+ config (`src/ghost/data-disclosure.ts`): what is collected, that redaction is
1840
+ best-effort and not DLP, whether **this** deployment forwards a redacted excerpt to a
1841
+ model provider — reading *both* gates, since the ghost server's `GHOST_ENABLE_AI`
1842
+ overrides `GHOST_AI_ENABLED` — and how long anything lives. The in-page default is the
1843
+ broader wording, so a failed injection over-discloses rather than under-discloses.
1844
+
1845
+ ## [0.3.4] (continued) — Custom rules on hosted
1846
+
1847
+ - **Your custom rules now run when `ANVIL_API_KEY` is set.** They used to be
1848
+ silently discarded on the hosted transport: the guard call went to Anvil, which
1849
+ never evaluates custom rule code, so the rule you wrote never got a say. The SDK
1850
+ now evaluates them **in your own process, before the hosted call** — same engine,
1851
+ same sandbox, same fail-closed behavior, reading the files already in your repo.
1852
+ If a rule blocks, the call stops locally and no network request is made at all.
1853
+ Hosted gets all fifteen primitives; this one just runs on your side of the wire,
1854
+ and your rule code never leaves your machine.
1855
+ - **Blocks show up in your dashboard.** A locally-decided block is reported to Anvil
1856
+ so it appears in Decisions and Impact alongside every other verdict, instead of
1857
+ only existing in your process. Ghost-mode would-blocks are reported too — that is
1858
+ the whole point of a ghost rollout. Reporting is best-effort and never gates a
1859
+ call: if it fails, the verdict still stands and your local audit log still has it.
1860
+ - **The dashboard decides whether a custom rule blocks**, not your `.env`. The
1861
+ per-action mode you flipped in Anvil governs the custom rule exactly as it governs
1862
+ your amount caps, so you can no longer end up with fourteen primitives enforcing
1863
+ and your custom rule quietly observing. If Anvil is unreachable, it falls back to
1864
+ this process's `ANVIL_MODE` — the previous behavior, never worse.
1865
+ - **Fails closed, in enforce.** A declared rule whose file is missing, a rule the
1866
+ sandbox validator rejects, a policy that declares rules but will not load, or a
1867
+ custom-rule engine that will not import all HOLD the call. Ghost observes and
1868
+ never blocks anything.
1869
+ - **Costs effectively nothing.** Measured p95 for a workspace with no local policy —
1870
+ the common hosted case — is 0.006ms; with one custom rule, 0.9ms. A benchmark in
1871
+ the suite keeps it that way.
1872
+ - Set `ANVIL_CUSTOM_RULE_PREFLIGHT=off` to disable the local evaluation. It says so
1873
+ loudly in your logs while it is off, because nothing else evaluates custom rules.
1874
+
1875
+ ## [0.3.3] — Withdrawn: a broken release
1876
+
1877
+ **Do not use this version.** It shipped a codemod that emitted an ESM `import` into CommonJS files
1878
+ unconditionally — a hard `SyntaxError` in the project shape `npm init -y` produces — so it corrupted
1879
+ the first file it touched and then reported success. It also shipped a double-wrap that broke
1880
+ `safe.protect`. Both were fixed in 0.3.4.
1881
+
1882
+ It was published from a commit that is not in this repository, which is why there is no tag for it
1883
+ and no fuller account here. Two things exist because of it: `x-anvil-sdk-version` on every hosted
1884
+ call, so "which tenants are still on the broken one?" has an answer; and a release check that
1885
+ refuses to publish at or below the current `latest`.
1886
+
1887
+ ---
1888
+
1889
+ ## [0.3.2] — Slimmer install
1890
+
1891
+ - **Excluded source maps from the published package** (`!dist/**/*.map`). Maps are
1892
+ debug-only and never loaded at runtime; dropping them cuts the unpacked package
1893
+ from ~80 MB to ~33 MB, so `npx @useanvil/sdk protect …` downloads and starts
1894
+ noticeably faster. No behavior change — the build still emits maps locally.
1895
+
1896
+ ## [0.3.1] — First-run polish
1897
+
1898
+ - **Get Access page:** back to one clean command — removed the action-name and
1899
+ beta-code input boxes; the command shows a real example (`payment.charge`) the
1900
+ CLI recognizes and routes into the call picker. Clearer escape hatch: *"Rather
1901
+ explore without installing? Try Ghost mode →"*. Professional spacing.
1902
+ - **protect welcome menu** reads as a here/there pair: *Wrap `charge` in the CLI*
1903
+ or *Protect `charge` in your control plane (recommended)*, with your action
1904
+ interpolated into both.
1905
+ - **Placeholder paste always animates.** Pasting the featured command (the
1906
+ `<your.action>` / `payment.charge` placeholder) always plays the full
1907
+ spinning-anvil cinematic, then routes into the call picker to replace it with
1908
+ your real call — no longer rate-limited on a repeat paste.
1909
+
1910
+ ## [0.3.0] — CLI first-run
1911
+
1912
+ A new user can paste one command and be guided all the way into their control
1913
+ plane; a returning user is recognized on any machine. This release makes the CLI
1914
+ onboarding, help, and returning-user experience work end to end.
1915
+
1916
+ ### Added
1917
+
1918
+ - **One-command onboarding.** `npx @useanvil/sdk protect <your.action>` plays the
1919
+ spinning-anvil intro, shows a two-choice menu (wrap here / open control plane),
1920
+ scans your project for the risky call, wraps it, and opens the browser to a
1921
+ guided tour of Actions → Policy → Impact that ends on your dashboard.
1922
+ - **Returning-user identity.** `anvil open` now shows `✓ Signed in as <you> ·
1923
+ workspace <name>`, and a bare `anvil` prints a status stripe instead of the
1924
+ first-run card once you have a key — even on a new machine (identity is derived
1925
+ from a cached/hosted key, not a per-machine marker). Honors `ANVIL_HIDE_IDENTITY`.
1926
+ - **`GET /v1/whoami`** on the hosted API — the CLI's bounded, degrade-gracefully
1927
+ identity check behind the returning-user surfaces.
1928
+ - **Cross-platform project auto-scan.** `anvil protect` finds your project under
1929
+ locale-translated Desktop/Documents folders, OneDrive (personal + business),
1930
+ macOS iCloud Drive, and WSL — not just English `~/Desktop`.
1931
+ - **Help discoverability.** `anvil --help` and every command's `--help` print to
1932
+ stdout (pipeable); `anvil help <command>` (git-style) works; `anvil status` and
1933
+ the full command list are visible.
1934
+
1935
+ ### Changed
1936
+
1937
+ - Bare `anvil` opens your control plane for a returning user (was a static card).
1938
+ - The featured protect welcome + its two-choice menu replay on every interactive
1939
+ paste of the website command (only the heavy animation is rate-limited).
1940
+ - The browser tour is personalized to the action you wrapped.
1941
+
1942
+ ### Fixed
1943
+
1944
+ - **`anvil serve` boots from the published tarball.** `scripts/policy-import-server.mjs`
1945
+ imported `docs-pii-scrub.mjs` / `docs-dead-end-rotate.mjs` that were missing from
1946
+ the package `files` allowlist, so the installed dashboard crashed on boot; both
1947
+ are now shipped (guarded by `npm run smoke:pack`).
1948
+ - `anvil open` reliably boots a local control plane when one isn't running, and
1949
+ says plainly when it falls through to hosted.
1950
+ - `anvil protect --json` / `--yes` are script-safe: never hang on a prompt, always
1951
+ emit a valid envelope, and honor an explicit project directory.
1952
+ - `anvil --help` no longer prints the first-run splash ahead of the reference.
1953
+
1954
+ ## [0.2.0] — Money-path hardening
1955
+
1956
+ This release tightens the money path so the "wrap a charge, never double-charge"
1957
+ promise holds by default. It contains a **breaking change** to enforce mode.
1958
+
1959
+ ### Changed (BREAKING)
1960
+
1961
+ - **Enforce mode now fails CLOSED on a money action guarded without an `amount`.**
1962
+ A money-named action (`payment.charge`, `payment.refund`, `payout.*`, …, per
1963
+ `isPaymentActionName`) guarded in `enforce` mode **without** an `amount` now throws
1964
+ `AnvilMoneyAmountRequiredError` instead of only warning. Spend-cap reservation and the
1965
+ money-moving durability signal both key off the amount, so without it a payment runs
1966
+ half-protected — a silent gap in a money guarantee is worse than a loud error.
1967
+
1968
+ - **Migration:** pass `amount` (integer cents) on money actions. This is almost always
1969
+ what you want and unblocks spend caps.
1970
+ - **Opt out** for a *legitimately* amount-less money call (a full refund, a capture-all):
1971
+ `guard({ …, allowAmountless: true })` per call, or `ANVIL_ALLOW_AMOUNTLESS_MONEY=1`
1972
+ globally. Both downgrade the throw to a warning.
1973
+ - **Unaffected:** `ghost` mode (never throws — it observes and warns), dry runs, calls
1974
+ that already pass an `amount`, and non-money actions.
1975
+ - **"Enforce" means the RESOLVED mode the action actually runs in**, not just the process
1976
+ `ANVIL_MODE`. A per-action **ghost** override (from the control config / dashboard) or an
1977
+ active **kill switch** resolves the action to observe-only, so this check downgrades to a
1978
+ warning there — an action you've deliberately set to ghost is never walled by the
1979
+ amount requirement, and enforcement still fails closed wherever the action truly enforces.
1980
+ (On the hosted-API transport the per-tenant mode is resolved server-side; the client
1981
+ fails fast on its own declared `ANVIL_MODE` before dispatch.)
1982
+ - The old opt-in `ANVIL_REQUIRE_MONEY_AMOUNT` is removed — its behavior is now the default.
1983
+ - Run `anvil doctor` to see your current money-amount posture.
1984
+
1985
+ - **Ghost mode no longer throws on non-durable money; it degrades to a labeled
1986
+ observation.** A money-moving action guarded in `ghost` mode with an `amount` but no
1987
+ durable (Postgres) receipts used to throw `AnvilSetupError`. It now **executes and is
1988
+ recorded**, with `response.nonDurable === true` and a one-time warning — honestly labeled
1989
+ as *not double-charge-safe until Postgres*. Enforce mode still fails closed on non-durable
1990
+ money (unchanged). This lets a first-run, Redis-only developer see their observations
1991
+ instead of hitting a wall.
1992
+
1993
+ - **Enforce mode now fails CLOSED on a money movement routed through `safe.data.egress`.**
1994
+ The egress gate is a PII/data-classification layer that deliberately has **no** idempotency
1995
+ engine and no spend cap, so a money-moving call through it (a payment-named action, or any
1996
+ call carrying an `amount`) is not double-charge-safe even with Postgres — a retry re-executes
1997
+ the side effect. In `enforce` mode it now throws the new `AnvilMoneyViaEgressError` instead
1998
+ of warning-and-running, closing a gap where the WS1 fail-closed guarantees above were
1999
+ silently void on the egress path.
2000
+
2001
+ - **Migration:** route the money movement through `guard()` (idempotency engine + spend
2002
+ caps) and run the egress classification as a separate step.
2003
+ - **Unaffected:** `ghost` mode (observes and labels the receipt `nonDurable: true`), and
2004
+ non-money egress calls (`data.egress` with no `amount`) — the common case — are untouched.
2005
+
2006
+ ### Added
2007
+
2008
+ - `AnvilResponse.nonDurable?: boolean` — set on a ghost-mode money observation recorded
2009
+ without durable receipts.
2010
+ - **The non-durable observation is now surfaced honestly.** `nonDurable` rides into the
2011
+ durable audit record (`AuditRecord.nonDurable`, JSONL/Redis — no Postgres migration),
2012
+ so it is tamper-evident when audit signing is enabled (it is inside the HMAC hash). The
2013
+ Actions decision log renders a quiet grey chip — *"recorded · not double-charge-safe until
2014
+ Postgres"* — on those rows, and "Copy JSON" carries a matching `non_durable: true`. The
2015
+ label appears only on genuine ghost non-durable money observations; it never overclaims.
2016
+ - `GuardOptions.allowAmountless?: boolean` — per-call opt-out of the enforce-mode
2017
+ amount requirement (see above).
2018
+ - `AnvilMoneyViaEgressError` (code `MONEY_VIA_EGRESS`) — thrown when a money movement is
2019
+ routed through `safe.data.egress` in enforce mode (see BREAKING above). Exported from the
2020
+ package root; catchable by type or `err.code`.
2021
+ - **A malformed `amount` is now a typed, catchable error on `guard()` too.** A non-finite,
2022
+ negative, or non-integer `amount` throws `AnvilInvalidProtectionInputError`
2023
+ (`field: 'amount'`, code `INVALID_PROTECTION_INPUT`) instead of a bare `Error`, matching the
2024
+ `safe.protect()` path — so a caller's input-error handling catches both money entrypoints by
2025
+ type, and a client 400 stays distinguishable from a server 500. `safe.protect()` now also
2026
+ rejects a non-integer amount (e.g. `49.99` for `$49.99`), which it previously accepted —
2027
+ keeping the two money entrypoints in exact agreement on what a valid amount is.