@useanvil/claude-code 0.9.1 → 0.10.0
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 +703 -0
- package/README.md +128 -38
- package/dist/Anvil +0 -0
- package/dist/claude-approve.js +23 -0
- package/dist/claude-conditions.js +19 -12
- package/dist/claude-helpers.js +9 -9
- package/dist/claude-hook-core.js +88 -80
- package/dist/claude-hook.js +38 -37
- package/dist/claude-meter.js +52 -48
- package/dist/claude-powershell.cjs +17 -17
- package/dist/claude-sync.js +26 -26
- package/dist/cli/claude-main.js +5392 -2510
- package/docs/coding-agents/YOUR-RULES.md +507 -654
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
# Anvil for Claude Code
|
|
2
2
|
|
|
3
|
-
**
|
|
3
|
+
**Let Claude Code run. Your rules, enforced.**
|
|
4
4
|
|
|
5
|
-
Anvil checks every action Claude Code takes before it
|
|
6
|
-
|
|
7
|
-
Anvil would have stopped.
|
|
5
|
+
Anvil checks every action Claude Code takes, before it runs: each command, each file it changes, each app it touches.
|
|
6
|
+
What would damage your system is blocked. What's risky to you waits for your OK. Everything else runs.
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
One command is all it takes. Coding agents have [wiped a home folder](https://news.ycombinator.com/item?id=46268222),
|
|
9
|
+
[destroyed production](https://news.ycombinator.com/item?id=47287420) and
|
|
10
|
+
[deleted a database *and* its backups](https://news.ycombinator.com/item?id=47911524), in seconds. Approving every step
|
|
11
|
+
turns into clicking yes on autopilot, and CLAUDE.md is only advice, which gets worked around.
|
|
12
|
+
|
|
13
|
+
**Anvil is the third option.** Every action is checked outside the model, against your rules. Claude can't edit them
|
|
14
|
+
or switch Anvil off, and a reworded command gets the same check. No account: it runs on your machine.
|
|
15
|
+
|
|
16
|
+
**Move fast and break nothing.** Give Claude the long jobs, let it work on its own, and ship more, without babysitting
|
|
17
|
+
every step or betting your week on one bad command.
|
|
10
18
|
|
|
11
19
|
<br>
|
|
12
20
|
|
|
@@ -26,11 +34,45 @@ database, email your customers or push to main. Nothing runs.
|
|
|
26
34
|
|
|
27
35
|
## What it does
|
|
28
36
|
|
|
29
|
-
|
|
37
|
+
On from the first action, with nothing to set up:
|
|
38
|
+
|
|
39
|
+
- **Your home folder or project, wiped?** Blocked before it runs. So is force-pushing over main.
|
|
40
|
+
- **Production changed while you sleep?** A change through a production account, a deploy to production, a
|
|
41
|
+
production database drop or a cloud teardown waits for your OK.
|
|
42
|
+
- **Your keys pasted into the chat?** A `.env`, a private key or `credentials.json` shown in the conversation waits
|
|
43
|
+
for your OK. Using it still runs.
|
|
44
|
+
|
|
45
|
+
New packages the project doesn't declare, deletes outside your project and throwing away uncommitted work wait for
|
|
46
|
+
your OK too. Everything else risky is watched: it runs, and you see what Anvil would have stopped.
|
|
47
|
+
|
|
48
|
+
<br>
|
|
49
|
+
|
|
50
|
+
## Your rules, in plain English
|
|
51
|
+
|
|
52
|
+
Say it the way you'd tell a teammate. Anvil reads it back before it applies: ✓ ready, ▲ a catch said plainly, or
|
|
53
|
+
? can't yet, with the closest rule it can do.
|
|
54
|
+
|
|
55
|
+
| The worry | Type this |
|
|
30
56
|
|---|---|
|
|
31
|
-
|
|
|
32
|
-
|
|
|
33
|
-
|
|
|
57
|
+
| Claude ships a deploy you didn't ask for | `ask before it deploys` |
|
|
58
|
+
| Your week's usage is gone by Tuesday | `80% of my weekly limit` |
|
|
59
|
+
| A cleanup "fixes" your migrations | `don't touch migrations/` |
|
|
60
|
+
| A risky change goes out without a second look | `get a second opinion before deploys` |
|
|
61
|
+
|
|
62
|
+
The last one sends Claude to Claude Code's advisor before it acts.
|
|
63
|
+
|
|
64
|
+
**Already wrote rules in CLAUDE.md?** To Claude they're advice. `anvil-claude rules import` turns them into rules
|
|
65
|
+
Anvil enforces: with your Claude Code reading, it finds 83–87% of the rule lines, says why it can't hold the rest, and
|
|
66
|
+
leaves advice where it is.
|
|
67
|
+
|
|
68
|
+
<br>
|
|
69
|
+
|
|
70
|
+
## Is it for you?
|
|
71
|
+
|
|
72
|
+
**Yes, if** you want Claude Code on autopilot: long tasks, auto mode or Bypass, sessions you don't watch. And it can
|
|
73
|
+
reach what matters: production, a cloud account, a database, your keys, your plan's limits.
|
|
74
|
+
|
|
75
|
+
**No need, if** you read and approve every command yourself. Claude Code's own prompts already do that job.
|
|
34
76
|
|
|
35
77
|
<br>
|
|
36
78
|
|
|
@@ -41,7 +83,8 @@ Anvil's lines in Claude Code lead with what happened, between two 🔹.
|
|
|
41
83
|
```
|
|
42
84
|
🔹 Anvil is on 🔹 blocking unsafe actions automatically · holding cluster, cloud and database destroys for your OK
|
|
43
85
|
› To add your own rules, run in a terminal: anvil-claude rules edit
|
|
44
|
-
🔹 Blocked by Anvil 🔹 force-pushes main
|
|
86
|
+
🔹 Blocked by Anvil 🔹 force-pushes main
|
|
87
|
+
› To change the rule, run in a terminal: anvil-claude rules edit
|
|
45
88
|
🔹 Held by Anvil for your OK 🔹 deletes a real folder
|
|
46
89
|
› To allow it once, run this in a terminal (not in this chat):
|
|
47
90
|
anvil-claude allow k3mpq7rx
|
|
@@ -67,26 +110,64 @@ Terminal panel or any terminal), never in the chat, where Claude can't run it.
|
|
|
67
110
|
`anvil-claude rules add` and `anvil-claude report` print the exact command for your settings, with yours in it:
|
|
68
111
|
`input=$(cat); printf '%s' "$input" | node "$HOME/.anvil/claude/bin/claude-sync.js" --statusline >/dev/null 2>&1;
|
|
69
112
|
printf '%s' "$input" | { your-command; }`. Dollar and token budgets don't need it.
|
|
70
|
-
- **
|
|
113
|
+
- **Where Claude Code can't ask you** (a background run, the desktop app under Bypass): on a Mac, Anvil's own window
|
|
114
|
+
shows what Claude wants to do and waits. Touch ID, or click Allow, runs it once. Elsewhere you get a code to run.
|
|
71
115
|
|
|
72
116
|
<br>
|
|
73
117
|
|
|
74
118
|
## Make it yours
|
|
75
119
|
|
|
76
|
-
**How it starts:**
|
|
77
|
-
|
|
120
|
+
**How it starts:** Anvil's own rules are on from the first action. Besides the blocks, Claude asks you before it:
|
|
121
|
+
|
|
122
|
+
- adds a package the project doesn't declare (`new-dependency`). What the project declares installs as always.
|
|
123
|
+
- deletes or moves files outside your project (`outside-folder`). Temp folders and caches run.
|
|
124
|
+
- shows a `.env`, a private key or `credentials.json` in the chat (`env-in-chat`). Using one, or listing its names, runs.
|
|
125
|
+
- throws away uncommitted work, when there is some to lose (`uncommitted`): `git reset --hard`, `git clean -f`,
|
|
126
|
+
dropping a stash.
|
|
127
|
+
- changes something through a production account, profile, context, env file, host or token (`prod-changes`). Reads
|
|
128
|
+
run.
|
|
129
|
+
- destroys a cluster, a cloud resource or a database, or prints cloud keys.
|
|
130
|
+
|
|
131
|
+
A few more guard Anvil itself, your account keys and runaway loops. Every other risky action is only watched: it runs,
|
|
132
|
+
and you see what Anvil would have stopped. The rules screen lists what is on first, in blue.
|
|
133
|
+
|
|
134
|
+
**Turn one of Anvil's off** on the rules screen: space on it asks first, and `o` turns it off. Space turns it back on.
|
|
135
|
+
Or by name: `anvil-claude off uncommitted`, and `anvil-claude enforce uncommitted` turns it back on. Only you can, in
|
|
136
|
+
your own terminal; Claude can't. Two keep the others in force, and say so: with **Change Anvil** off, Claude could turn
|
|
137
|
+
off your other rules, and with **Anything Anvil can't check** off, a command Anvil can't read runs.
|
|
138
|
+
|
|
139
|
+
**Add rules on one screen.** `anvil-claude rules edit` (or **Change your rules** on Home), then:
|
|
140
|
+
|
|
141
|
+
- **Type one** in plain English. It is added to the list, marked, and you can type the next.
|
|
142
|
+
- **Say it roughly.** Words Anvil can't read are offered the closest rule it can enforce: `max 5 helpers`, `50 a
|
|
143
|
+
day`, `save money`. Enter adds what it shows.
|
|
144
|
+
- **Import your CLAUDE.md**, or drag the file onto the window. Anvil shows each rule it can enforce and each one it
|
|
145
|
+
can't yet, with why, and saves nothing until you choose. Where Claude Code is installed, it reads the lines through
|
|
146
|
+
your own login, on your plan; `anvil-claude rules import --no-model` keeps them on your machine.
|
|
78
147
|
|
|
79
148
|
**Hold what you care about.** When a watched line keeps showing up, hold that kind: the line gives the command, and
|
|
80
|
-
Home
|
|
149
|
+
Home suggests the one it saw most. Or hold every rule at once with `anvil-claude enforce all`.
|
|
81
150
|
|
|
82
|
-
**Set a budget.** `anvil-claude rules add
|
|
151
|
+
**Set a budget.** `anvil-claude rules add 'budget: $50 a day'`. Past it, Claude Code stops before its next message or
|
|
83
152
|
action, and `anvil-claude allow <code>`, run in a terminal, lets that task go on (for that task, one more budget's
|
|
84
|
-
worth and an hour at most).
|
|
153
|
+
worth and an hour at most). Space on it on the rules screen changes its amount and period.
|
|
85
154
|
Also a week or a task, new tokens (`5M new tokens a day`), or a share of your plan (`80% of my weekly limit`). Anvil
|
|
86
155
|
checks it when you send a message, without reading the message. It can run over by about two replies per thread
|
|
87
156
|
(the reply that crosses it, the one in flight, and the one that reads the stop): usually cents, at worst a cold 1M
|
|
88
157
|
context reply, about $15–30.
|
|
89
158
|
|
|
159
|
+
**Lock a folder.** `anvil-claude rules add "block: edits to ~/Documents/"`: Anvil blocks the changes it can read, and
|
|
160
|
+
Claude Code's own sandbox can refuse the shell writes it can't. The screens say `locked`, `partly locked` or
|
|
161
|
+
`held by Anvil, not locked`, and why.
|
|
162
|
+
|
|
163
|
+
**Spend less.** `anvil-claude rules add "model: smart"`: in new terminal sessions, Sonnet works and Opus advises, where
|
|
164
|
+
your account has the advisor. The desktop app starts each session on the model picked in it, so pick Sonnet there.
|
|
165
|
+
|
|
166
|
+
**Get a second opinion.** `anvil-claude rules add "get a second opinion before deploys"`: Claude asks Claude Code's
|
|
167
|
+
advisor before its first deploy in a task. In the desktop app and background runs, the deploy can go ahead once the
|
|
168
|
+
advisor has answered; run again without asking, it is refused once more, then held for your OK. In the terminal, or
|
|
169
|
+
with no advisor in the session, each one waits for your OK.
|
|
170
|
+
|
|
90
171
|
**Every screen says what a limit does now.** `rules add`, `anvil-claude rules`, the rules screen, Home, `on` and
|
|
91
172
|
`report` show each budget, cap and model rule as it stands: one Anvil can't measure or hear here says why, with the
|
|
92
173
|
fix, never that it stops anything.
|
|
@@ -94,15 +175,17 @@ fix, never that it stops anything.
|
|
|
94
175
|
| Command | What it does |
|
|
95
176
|
|---|---|
|
|
96
177
|
| `anvil-claude` | Home: where it stands, what to do next |
|
|
97
|
-
| `anvil-claude
|
|
178
|
+
| `anvil-claude rules edit` | every rule on one screen: space changes one; type or import to add more |
|
|
179
|
+
| `anvil-claude rules add "Ask before it deploys."` | add a rule in plain words |
|
|
180
|
+
| `anvil-claude rules import` | turn the rules in your CLAUDE.md into ones Anvil enforces |
|
|
181
|
+
| `anvil-claude rules add 'budget: $50 a day'` | stop Claude Code past what it may spend |
|
|
98
182
|
| `anvil-claude report` | what it stopped this week, and what Claude spent |
|
|
99
183
|
| `anvil-claude rules` | every rule, and what it does now |
|
|
100
184
|
| `anvil-claude enforce push-main` | hold one kind of action for your OK |
|
|
185
|
+
| `anvil-claude off uncommitted` | turn off one rule; Anvil stays on |
|
|
101
186
|
| `anvil-claude enforce all` | hold every rule |
|
|
102
|
-
| `anvil-claude rules add "Ask before it deploys."` | add a rule in plain words |
|
|
103
|
-
| `anvil-claude rules add "budget: $50 a day"` | stop Claude Code past what it may spend |
|
|
104
187
|
| `anvil-claude rules add "model: opus for deploys"` | hold deploys made on another model |
|
|
105
|
-
| `anvil-claude
|
|
188
|
+
| `anvil-claude try` | see it work; nothing runs |
|
|
106
189
|
| `anvil-claude off` | take it out; your settings go back as they were |
|
|
107
190
|
|
|
108
191
|
Run these in your own terminal. Claude can't run them from inside Claude Code, so it can't switch Anvil off.
|
|
@@ -129,18 +212,19 @@ kind. Type it in plain words, or paste the command: Anvil reads a command the wa
|
|
|
129
212
|
|
|
130
213
|
| You can | For example |
|
|
131
214
|
|---|---|
|
|
132
|
-
| Hold a kind of action for your OK, or block it | `hold pushes to main` · `
|
|
133
|
-
| Narrow it to one app | `hold Stripe changes` · `never send email through Gmail` · `hold Slack posts` |
|
|
215
|
+
| Hold a kind of action for your OK, or block it | `hold pushes to main` · `ask before it deploys` · `never force-push` · `docker push` |
|
|
134
216
|
| Narrow it to a file or folder | `don't touch migrations/` · `ask before editing package-lock.json` · `hold changes to infra/` |
|
|
135
217
|
| Narrow it to one target | `hold deploys to production` · `hold pushes to main in billing-api` · `hold deletes outside the project` |
|
|
218
|
+
| Set a budget | `$50 a day` · `80% of my weekly limit` |
|
|
219
|
+
| Narrow it to one app | `hold Stripe changes` · `never send email through Gmail` · `hold Slack posts` |
|
|
136
220
|
| Hold only some of them | `hold Stripe refunds over $500` · `never email anyone outside the company` · `hold Slack posts in #general` · `hold deploys on Fridays` |
|
|
137
221
|
| Cap how often, or how much | `at most 3 deploys a day` · `at most 5 Stripe refunds a day` · `at most $2,000 of Stripe refunds a day` · `5 helper agents at once` |
|
|
138
|
-
| Set a budget | `$50 a day` · `80% of my weekly limit` |
|
|
139
222
|
| Tie an action to a model | `model: opus for deploys` · `model: haiku for exploring` |
|
|
140
223
|
|
|
141
|
-
The kinds: pushes to main,
|
|
142
|
-
|
|
143
|
-
|
|
224
|
+
The kinds: pushes to main, deploys, new dependencies, deletes, production accounts, database destroys, force-pushes,
|
|
225
|
+
throwing away uncommitted work, `.env` files, publishing, app changes, writes to other services, changes outside the
|
|
226
|
+
project, printing secrets, helper agents, paid compute, background jobs, running as root, killing processes, tunnels,
|
|
227
|
+
copying a database here, and crypto transactions.
|
|
144
228
|
|
|
145
229
|
**A narrowed rule only adds a stop, and holds what it can't read.** The box shows what still runs before you add one.
|
|
146
230
|
|
|
@@ -149,14 +233,15 @@ said plainly (an app not connected here, a category that covers every app of it
|
|
|
149
233
|
goes held too); or ? can't yet, with the closest rule Anvil can do, one key away (`rules add` prints it as a command).
|
|
150
234
|
A catch stays on the rule's row: `hold Shopify refunds` says "not connected yet" until you connect Shopify.
|
|
151
235
|
|
|
152
|
-
- **One app** covers its MCP tools, its API reached from a command (`curl -X POST https://api.stripe.com/…`) and its
|
|
153
|
-
CLI. Reads run. Anvil knows an app by your own MCP servers and connectors too, by name only.
|
|
154
236
|
- **A file or folder** covers Claude's file tools and every shell write Anvil can read (`>`, `tee`, `sed -i`, `cp`,
|
|
155
|
-
`mv`, `rm`). Reads run.
|
|
156
|
-
|
|
237
|
+
`mv`, `rm`). Reads run. Anvil itself can't see a script that builds its paths as it runs: a `block:` on a plain path
|
|
238
|
+
also locks it with Claude Code's sandbox, which can (**Lock a folder**, above). Claude Code's own `Edit(…)` rule is
|
|
239
|
+
the other way to do it, without the one-time OK.
|
|
157
240
|
- **A target** is read from the command itself: `vercel --prod`, `fly -a`, `railway -e`, `kubectl --context`, `modal -e`,
|
|
158
241
|
terraform's workspace; a push's repository from the checkout it runs in. A deploy whose command doesn't say where it
|
|
159
242
|
goes is held, and so is a tool whose default may be production.
|
|
243
|
+
- **One app** covers its MCP tools, its API reached from a command (`curl -X POST https://api.stripe.com/…`) and its
|
|
244
|
+
CLI. Reads run. Anvil knows an app by your own MCP servers and connectors too, by name only.
|
|
160
245
|
- **A condition** is read from the call itself: a money app's amount, who an email or an invite reaches (with
|
|
161
246
|
`define: my company = acme.com` for "outside the company"), one part of an app (a Slack channel, a GitHub
|
|
162
247
|
repository, a Linear team, a Jira project), or the time on this Mac's clock. What it can't read, it holds, saying why
|
|
@@ -168,21 +253,26 @@ A catch stays on the rule's row: `hold Shopify refunds` says "not connected yet"
|
|
|
168
253
|
`over 10%`, who a Slack message or a text reaches). The box offers the rule without them, which holds every one.
|
|
169
254
|
- **Other environments and regions** (`deploys to staging`, `to eu-west`). Hold production instead: staging and
|
|
170
255
|
previews run.
|
|
256
|
+
- **Commits, and pushes to other branches** (`ask before committing`, `don't push without asking`). Anvil can hold
|
|
257
|
+
pushes to main: `enforce push-main`.
|
|
171
258
|
- **Advice for Claude** (`write tests first`). That belongs in CLAUDE.md.
|
|
172
|
-
- **Everyday commands** (`npm
|
|
259
|
+
- **Everyday commands** (`npm test`, `npm ci`). They run as always. A package the project doesn't declare waits for
|
|
260
|
+
your OK.
|
|
173
261
|
|
|
174
|
-
|
|
262
|
+
Anvil's own rules are on until you turn one off. Anvil checks what Claude does, not the commands you run yourself.
|
|
175
263
|
|
|
176
264
|
<br>
|
|
177
265
|
|
|
178
266
|
## Privacy
|
|
179
267
|
|
|
180
|
-
- **
|
|
181
|
-
prompts or Claude's replies. From Claude Code's session files it picks out four things only:
|
|
182
|
-
whether you said Yes to a held action, each reply's model, token counts and cost, and when a
|
|
183
|
-
worked, never its text. From a helper launch, only its type and model.
|
|
184
|
-
- **
|
|
185
|
-
|
|
268
|
+
- **It never reads your conversation.** Anvil judges what Claude does, never what you or Claude say, and it never
|
|
269
|
+
stores or sends your prompts or Claude's replies. From Claude Code's session files it picks out four things only:
|
|
270
|
+
Claude Code's version, whether you said Yes to a held action, each reply's model, token counts and cost, and when a
|
|
271
|
+
helper agent last worked, never its text. From a helper launch, only its type and model.
|
|
272
|
+
- **Your code and commands stay on your machine.** No account and no Anvil server: what Anvil records stays in
|
|
273
|
+
`~/.anvil`, and what Claude spent is kept for 40 days. All it sends is anonymous usage counts, listed in
|
|
274
|
+
`TELEMETRY.md`; `DO_NOT_TRACK=1` turns them off. A CLAUDE.md import is read by your own Claude Code, on your login,
|
|
275
|
+
unless you add `--no-model`.
|
|
186
276
|
|
|
187
277
|
<br>
|
|
188
278
|
|
package/dist/Anvil
ADDED
|
Binary file
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import{spawn as hr,spawnSync as mr}from"child_process";import{createHash as ze,randomBytes as yr}from"crypto";import{accessSync as wr,constants as br,lstatSync as kr,rmSync as $r}from"fs";import{userInfo as vr}from"os";import{join as He}from"path";import{createHash as cl,randomBytes as Pn}from"crypto";import{readdirSync as Ln,renameSync as yt,unlinkSync as bt}from"fs";import{join as je}from"path";import{createHmac as bn,randomBytes as Oe,timingSafeEqual as kn}from"crypto";import{closeSync as at,existsSync as $n,fsyncSync as dt,linkSync as vn,mkdirSync as ct,openSync as ut,readdirSync as xn,readFileSync as Z,unlinkSync as ft,writeSync as pt}from"fs";import{basename as _n,dirname as it,join as B}from"path";var W={on:"\u25CF",watching:"\u25CB",held:"\u25A0",ok:"\u2713",blocked:"\u2715",problem:"\u25B2",next:"\u203A"};function Vt(e){if(!e){let a=u=>u;return{on:!1,bold:a,dim:a,blue:a,grey:a,amber:a,mark:a,field:a}}let t=e==="truecolor",r=a=>u=>`\x1B[${a}m${u}\x1B[0m`,n=r(t?"38;2;76;139;255":"38;5;69"),s=r(t?"38;2;130;134;150":"90"),o=r(t?"38;2;245;165;36":"38;5;214"),l=r(t?"38;2;34;197;94":"32"),i={[W.on]:n,[W.blocked]:n,[W.held]:n,[W.next]:n,[W.watching]:s,[W.problem]:o,[W.ok]:l};return{on:!0,bold:r("1"),dim:r("2"),blue:n,grey:s,amber:o,mark:a=>(i[a]??(u=>u))(a),field:a=>`\x1B[${t?"48;2;24;2;166;38;2;255;255;255":"48;5;19;97"}m${Zt(a)}\x1B[0m`}}var Ur=Vt(!1),Yt=/\u001b\[[0-9;]*m|\u001b\][^\u0007]*\u0007/g;function Zt(e){return e.replace(Yt,"")}var Ue="claude";function Ke(e=new Date){return{version:1,kill_switch:!1,default_mode:"ghost",services:{[Ue]:{actions:{}}},updated_at:e.toISOString(),day_one:!0}}var qe=[{id:"protect",verdict:"block",short:"wiping your home folder or the project",slugs:["protected"]},{id:"protect-main",verdict:"block",short:"force-pushing main",slugs:["protected"]},{id:"protect-processes",verdict:"block",short:"killing every process",slugs:["protected"]},{id:"keep-work",verdict:"hold",short:"throwing away uncommitted work",slugs:["uncommitted"]},{id:"stay-in-project",verdict:"hold",short:"deletes outside your project",slugs:["outside-folder"]},{id:"stay-out-of-prod",verdict:"hold",short:"changes aimed at production",slugs:["prod-changes"]},{id:"keep-anvil-on",verdict:"hold",short:"changes to Anvil",slugs:["agent-controls"]},{id:"stop-loops",verdict:"hold",short:"delete bursts and repeats",slugs:["delete-burst","repeat"]},{id:"stop-helper-bursts",verdict:"hold",short:"helper bursts",slugs:["helper-burst"]},{id:"keep-keys-in",verdict:"hold",short:"use of your account keys",slugs:["credentials","secrets-expose"]},{id:"keep-env-out",verdict:"hold",short:"showing secrets files in the chat",slugs:["env-in-chat"]},{id:"hold-unchecked",verdict:"hold",short:"actions it can't check",slugs:["could-not-check","too-long-to-check"]}],Xt="home and project wipes and force-pushes to main",eo=`always blocking ${Xt}`,to=new Map(qe.map(e=>[e.id,e]));var Qt=new Set(qe.flatMap(e=>e.slugs));var Se="anvil-claude";function F(e){let t=e.trim();return t===Se||t.endsWith(` ${Se}`)||t.endsWith(`/${Se}`)||/(^|[\s/])@useanvil\/claude-code(@\S+)?$/.test(t)||/(^|\s)claude$/.test(t)?t:`${t} claude`}var Je="\u{1F539}",V=e=>`${Je} ${e} ${Je}`;var en=e=>`
|
|
2
|
+
${W.next} ${e}`;var fe=e=>en(e);var Ge=(e,t)=>`they run \`${F(e)} allow\` in a terminal (not in this chat: Claude can't run it), which lists what's waiting for their OK, then ${t}`;var tn="anvil";var pe=e=>`${F(tn)} ${e}`;import{spawnSync as ki}from"child_process";import{createHash as vi}from"crypto";import{chmodSync as _i,existsSync as Si,lstatSync as Ai,mkdirSync as Ci,readdirSync as Ri,readFileSync as Oi,readlinkSync as Ei,realpathSync as Ni,rmdirSync as ji,statSync as Pi,unlinkSync as Li,writeFileSync as Ti}from"fs";import{dirname as Mi,isAbsolute as Di,join as Wi,relative as Fi,resolve as Hi}from"path";import{createHash as Js}from"crypto";import{appendFileSync as Vs,closeSync as et,constants as Qe,fstatSync as tt,mkdirSync as gn,openSync as nt,readdirSync as Ys,readFileSync as hn,readSync as rt,renameSync as mn,statSync as yn,unlinkSync as Zs,writeFileSync as wn}from"fs";import{homedir as Qs}from"os";import{dirname as ti,join as z}from"path";import{createHash as on}from"crypto";import{existsSync as ne,readdirSync as me,statSync as oe}from"fs";import{dirname as Ae,isAbsolute as To,join as w,posix as Io,resolve as re}from"path";import{posix as Eo}from"path";var rn=null;function ge(){return rn??process.platform==="win32"}function Ve(e){if(!ge())return e;let t=/^\/([a-z])(\/.*)?$/s.exec(e);if(t)return`${t[1].toUpperCase()}:${(t[2]??"/").replace(/\//g,"\\")}`;let r=/^\/unc\/(.+)$/s.exec(e);return r?`\\\\${r[1].replace(/\//g,"\\")}`:null}function H(e){return ge()?Ve(e)??e:e}function Ye(e,t,r,n,s,o){let l=d=>on("sha256").update(d).digest("hex"),i=d=>{s();try{return M(d,33554432)?.toString("utf8")??""}catch{try{let v=oe(d);return v.isFile()?`${he} ${v.ino} ${v.size} ${v.mtimeMs}`:""}catch(v){return`${he} ${v.code??""}`}}},a=dn(e,!0);if(a===null||n.has(a.gitDir))return null;let{gitDir:u,common:f,top:g}=a;n.add(u);let h=new Map,y=(d,v,_=d)=>{h.set(`${u}\0${_}`,{called:d,is:v})},x=new Set,N=new Set;for(let d of r)d.forEach((v,_)=>{if(!/(?:^|\/)git$/.test(v))return;let S=_+1;for(;d[S]?.startsWith("-");)S+=/^-[cC]$/.test(d[S])?2:1;if(d[S]&&x.add(d[S]),d[S]==="push")for(let K=S+1;K<d.length&&!d[K].startsWith("\0");K++)N.add(d[K])});let A=new Set(r.flat().filter(d=>!d.startsWith("\0"))),I=(...d)=>d.some(v=>x.has(v)),j=I("merge","rebase","reset","checkout","switch","cherry-pick","restore","revert")&&!I("fetch","pull","remote"),P=[...A].some(d=>/(?:^|\/)(?:gh|hub)$/.test(d)),C=i(w(u,"HEAD")).trim(),E=/^ref: refs\/heads\/(.+)$/.exec(C)?.[1]??null,Q=i(w(f,"packed-refs")),ee=new Map([...Q.matchAll(/^([0-9a-f]{40,64}) (\S+)$/gm)].map(d=>[d[2],d[1]]));Q.startsWith(he)&&y("its branches",Q,"packed");let c=(d,v=0)=>{if(v>5||/(^|\/)\.\.?(\/|$)|\0/.test(d))return"";let _=i(w(u,d)).trim()||i(w(f,d)).trim()||(ee.get(d)??""),S=/^ref: (.+)$/.exec(_)?.[1];return S?`${S} ${c(S,v+1)}`:_};y("the branch",C),y("the commit",c("HEAD"));let{entries:p,files:m,whole:k}=ln(a,t),R=new Set;for(let d of A)if(!d.startsWith("-"))for(let v of d.replace(/^\+/,"").split(/:|\.{2,3}/))R.add(v.replace(/[~^@].*$/,""));if(j&&(I("merge","rebase")||[...A].some(d=>/@\{(?:u|p)/i.test(d)))){let d=v=>p.filter(_=>_.section==="branch"&&_.sub===E&&_.key===v).pop()?.value??"";R.add(`${d("remote")}/${d("merge").replace("refs/heads/","")}`)}for(let d of R){if(!d||d.length>255||d==="HEAD"||/\s/.test(d))continue;let _=[.../^[A-Z][A-Z_]+$|^refs\//.test(d)?[d]:[],`refs/${d}`,`refs/tags/${d}`,...d===E?[]:[`refs/heads/${d}`],`refs/remotes/${d}`].filter(S=>S!=="refs/stash"&&(j||!S.startsWith("refs/remotes/"))).map(S=>c(S)).filter(Boolean);_.length>0&&y(JSON.stringify(d.length>60?`\u2026${d.slice(-59)}`:d),_.join(" "),`ref ${d}`)}x.has("stash")&&y("the stash",l(c("refs/stash")+i(w(f,"logs/refs/stash"))));let b=d=>[...N].some(v=>d.test(v)),O=[...b(/^--(?:all|branches|mirror)$|\*/)?["refs/heads"]:[],...b(/^--(?:tags|follow-tags|mirror)$|\*/)?["refs/tags"]:[]];if(O.length>0){let d=new Map([...ee].filter(([_])=>O.some(S=>_.startsWith(`${S}/`)))),v=(_,S)=>{s();let K=w(f,_);if(!(S>16||!ne(K)))for(let ue of me(K,{withFileTypes:!0}))ue.isDirectory()?v(`${_}/${ue.name}`,S+1):d.set(`${_}/${ue.name}`,i(w(K,ue.name)).trim())};for(let _ of O)v(_,0);y(O.includes("refs/heads")?"its branches":"its tags",l(JSON.stringify([...d].sort(([_],[S])=>_<S?-1:1))))}ne(w(f,"reftable"))&&y("its branches",l(i(w(f,"reftable/tables.list"))+i(w(u,"reftable/tables.list"))),"reftable");let $=d=>d.section==="branch"?/^(?:remote|pushremote|merge)$/.test(d.key)&&d.sub!==E&&R.has(d.sub??""):!sn.has(d.section)&&(P||d.key!=="gh-resolved");y("git's settings",l(JSON.stringify(p.filter($))+(k?"":m.map(d=>i(d).startsWith(he)?`${d} ${i(d)}`:"").join(`
|
|
3
|
+
`)))),y("git's settings",JSON.stringify(p.filter(d=>d.section==="branch"&&d.sub===E&&/^(?:remote|pushremote|merge)$/.test(d.key))),`git's settings\0${E}`);let L=p.filter(d=>d.section==="core"&&d.key==="hookspath").pop()?.value,te=L?re(g,L.startsWith("~/")&&t?w(t,L.slice(2)):L):w(f,"hooks"),Be=[];try{Be=me(te).filter(d=>!d.endsWith(".sample")&&!d.startsWith(".")).sort()}catch(d){if(!/^(ENOENT|ENOTDIR)$/.test(d.code??""))throw d}return y("git's hooks",l(JSON.stringify(Be.map(d=>[d,(oe(w(te,d),{throwIfNoEntry:!1})?.mode??0)&73,o(w(te,d))])))),h}var he="\0unread",sn=new Set(["maintenance","lfs","extensions","safe","gc","gui","gitk","color","advice"]);function ln(e,t){let r=[],n=null;try{n=an(e,t,r)}catch{}let{common:s}=e,o=["remotes","branches"].flatMap(u=>{let f=w(s,u),g=oe(f,{throwIfNoEntry:!1});return g?g.isDirectory()?me(f).sort().map(h=>w(f,h)):[f]:[]}),l=u=>{try{return M(u,32*1024*1024)?.toString("utf8")??""}catch{return""}},i=o.map(u=>({section:"remote",sub:u,key:"file",value:l(u)}));if(n)return{entries:[...n,...i],files:[...r,...o],whole:o.length===0};let a=[...new Set([...r,...Ze(e,t)])];return{entries:[...a.flatMap(u=>Xe(l(u))),...i],files:[...a,...o],whole:!1}}function Ze(e,t){let r=process.env,n=process.platform==="win32"?[w(r.ProgramFiles||"C:\\Program Files","Git","etc","gitconfig"),w(r.ProgramData||"C:\\ProgramData","Git","config")]:["/etc","/opt/homebrew/etc","/usr/local/etc","/Library/Developer/CommandLineTools/usr/share/git-core"].map(o=>`${o}/gitconfig`),s=r.GIT_CONFIG_NOSYSTEM?[]:r.GIT_CONFIG_SYSTEM?[r.GIT_CONFIG_SYSTEM]:n;return r.GIT_CONFIG_GLOBAL?s.push(r.GIT_CONFIG_GLOBAL):t&&s.push(w(r.XDG_CONFIG_HOME||w(t,".config"),"git","config"),w(t,".gitconfig")),s.push(w(e.common,"config"),w(e.gitDir,"config.worktree")),s.filter(o=>o!=="/dev/null")}function an(e,t,r=[]){let n=[],s=24,o=(i,a)=>{r.push(i);let u=--s<0||a>5?void 0:M(i,1024*1024);if(u===void 0)return!1;for(let f of Xe(u?.toString("utf8")??""))if(n.push(f),f.key==="path"&&/^include(if)?$/.test(f.section)){let g=f.value.startsWith("~/")?t&&w(t,f.value.slice(2)):!/^[~%]/.test(f.value)&&re(Ae(i),f.value);if(!g||!o(g,a+1))return!1}return!0},l=!0;for(let i of Ze(e,t))l=o(i,0)&&l;return l?n:null}function dn(e,t=!1){let r=n=>/^(ref: refs\/|[0-9a-f]{40})/.test(M(w(n,"HEAD"),4096)?.toString("utf8")??"");for(let n=re(e),s=0;s<64;s++,n=Ae(n)){let o=w(n,".git"),l=["objects","refs"].every(i=>ne(w(n,i)))&&r(n)?n:null;if(ne(o)){let i=oe(o);if(i.isDirectory())r(o)&&(l=o);else if(l=i.isFile()?/^gitdir:\s*(.+)$/m.exec(M(o,65536)?.toString("utf8")??"")?.[1]?.trim():null,!l)return null}if(l){let i=re(n,l),a=M(w(i,"commondir"),65536),u=a===null?i:re(i,a.toString("utf8").trim());for(let f of t?[]:["remotes","branches"]){let g=w(u,f);if(ne(g)&&(!oe(g).isDirectory()||me(g).length>0))return null}return{gitDir:i,common:u,top:n}}if(Ae(n)===n)return null}return null}function Xe(e){let t=[],r="",n=null;for(let s of e.replace(/\\\r?\n/g,"").split(/\r?\n/)){s=s.trim();let o=/^\[\s*([\w.-]+)(?:\s+"((?:[^"\\]|\\.)*)")?\s*\]/.exec(s);if(o){let[i,...a]=o[1].toLowerCase().split(".");r=i,n=o[2]?.replace(/\\(.)/g,"$1")??(a.length>0?a.join("."):null),s=s.slice(o[0].length).trim()}let l=/^([a-z][\w-]*)\s*(?:=(.*))?$/i.exec(s);l&&t.push({section:r,sub:n,key:l[1].toLowerCase(),value:l[2]===void 0?"true":l[2].replace(/"((?:[^"\\]|\\.)*)"|\\(.)|[#;].*$/g,(i,a,u)=>a??u??"").trim()})}return t}import{domainToASCII as Ko}from"url";var Qo="Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" ");import{existsSync as hs,readdirSync as ms,realpathSync as ys}from"fs";import{basename as bs,dirname as ks,join as $s}from"path";function se(e){return{dir:e,bin:z(e,"bin"),compiled:z(e,"compiled.json"),modes:z(e,"modes.json"),decisions:z(e,"decisions.jsonl"),install:z(e,"install.json"),state:z(e,"state"),approvals:z(e,"approvals"),counts:z(e,"counts"),backups:z(e,"backups")}}function T(e,t=8*1024*1024){try{let r=yn(e);return r.isFile()&&r.size<=t}catch(r){return r.code==="ENOENT"?null:!1}}function M(e,t=8*1024*1024){let r;try{r=nt(e,Qe.O_RDONLY|Qe.O_NONBLOCK)}catch(n){if(n.code==="ENOENT"||n.code==="ENOTDIR")return null;throw n}try{let n=tt(r);if(!n.isFile())throw new Error(`${e} is not a regular file`);if(n.size>t)throw new Error(`${e} is over ${t} bytes`);let s=Buffer.alloc(n.size),o=0;for(;o<n.size;){let l=rt(r,s,o,n.size-o,o);if(l===0)break;o+=l}return s.subarray(0,o)}finally{et(r)}}function J(e){gn(e,{recursive:!0,mode:448})}function G(e,t){if(T(e,Number.MAX_SAFE_INTEGER)!==!0)return"";let r;try{r=nt(e,"r")}catch{return""}try{let n=tt(r).size,s=Math.max(0,n-t),o=n-s;if(o<=0)return"";let l=Buffer.alloc(o);rt(r,l,0,o,s);let i=l.toString("utf8");if(s>0){let a=i.indexOf(`
|
|
4
|
+
`);i=a<0?"":i.slice(a+1)}return i}finally{et(r)}}function ye(e,t,r=384){let n=`${e}.${process.pid}.${Date.now().toString(36)}.tmp`;wn(n,t,{mode:r}),ie(n,e)}function ie(e,t){for(let r=0;;r++)try{mn(e,t);return}catch(n){let s=n.code;if(process.platform!=="win32"||r>=12||s!=="EPERM"&&s!=="EACCES"&&s!=="EBUSY")throw n;Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,20+r*10)}}function Ce(e){if(T(e)!==!0)return null;try{return JSON.parse(hn(e,"utf8"))}catch{return null}}var ri=256*1024,oi=1024*1024;var ot=[2,1,295];function st(e){let t=/^(\d{1,6})\.(\d{1,6})\.(\d{1,6})/.exec(e??"");if(!t)return!1;let r=[Number(t[1]),Number(t[2]),Number(t[3])];for(let n=0;n<3;n++)if(r[n]!==ot[n])return r[n]>ot[n];return!0}var U="_seal";function $e(e){return B(e.dir,"seal.key")}function we(e,t){return B(e.state,"lkg",t)}function D(e){let t=$e(e);if(T(t,1024)!==!0)return null;try{let r=Z(t,"utf8").trim();return/^[0-9a-f]{64}$/.test(r)?Buffer.from(r,"hex"):null}catch{return null}}function Sn(e){return D(e)?"ok":T($e(e),1024)===null?"missing":"damaged"}var ke=class extends Error{};function gt(e,t){return`Anvil's seal key (${$e(e)}) is ${t==="damaged"?"damaged":"missing"}`}function An(e){let t=D(e);if(t)return t;let r=Sn(e);if(r==="damaged"||Nn(e))throw new ke(`${gt(e,r)}; run ${pe("on")} to restore it`);let{key:n,created:s}=Cn(e,!1);return s&&Rn(e,n),n}function lt(e,t,r){let n=ut(e,r,384);try{pt(n,t),dt(n)}finally{at(n)}}function Cn(e,t){ct(e.dir,{recursive:!0,mode:448});let r=$e(e),n=B(e.dir,`.seal.key.${process.pid}.${Oe(4).toString("hex")}.tmp`);lt(n,`${Oe(32).toString("hex")}
|
|
5
|
+
`,"wx");let s=!1;try{t?ie(n,r):vn(n,r),s=!0}catch(l){let i=l.code??"";if(i!=="EEXIST"){if(t||!["EPERM","ENOTSUP","EOPNOTSUPP","ENOSYS","EXDEV"].includes(i))throw l;try{lt(r,Z(n,"utf8"),"wx"),s=!0}catch(a){if(a.code!=="EEXIST")throw a}}}finally{try{ft(n)}catch{}}let o=D(e);if(!o)throw new ke(`${gt(e,"damaged")}; run ${pe("on")} to restore it`);return{key:o,created:s}}function Rn(e,t){let r=[[e.modes,Re],[e.compiled,En],[e.install,void 0]];for(let[n,s]of r)if(T(n,8*1024*1024)===!0)try{let o=Z(n,"utf8");if(o.includes(`"${U}"`))continue;let l=JSON.parse(o);if(!l||typeof l!="object"||Array.isArray(l))continue;n===e.modes&&delete l.turned_off;let i=`${JSON.stringify(Ne(t,l),null,2)}
|
|
6
|
+
`;Y(n,i),s&&Y(we(e,s),i)}catch{}if(T(e.modes)===null&&T(we(e,Re))===null){let n=`${JSON.stringify(Ne(t,Ke()),null,2)}
|
|
7
|
+
`;Y(e.modes,n),Y(we(e,Re),n)}}function Ee(e,t=0){if(t>64)throw new Error("nested too deep to seal");return Array.isArray(e)?`[${e.map(r=>Ee(r===void 0?null:r,t+1)).join(",")}]`:e&&typeof e=="object"?`{${Object.keys(e).filter(n=>!(t===0&&n===U)&&e[n]!==void 0).sort().map(n=>`${JSON.stringify(n)}:${Ee(e[n],t+1)}`).join(",")}}`:JSON.stringify(e??null)}function ht(e,t){return bn("sha256",e).update(Ee(t)).digest("hex")}function be(e){if(!(U in e))return e;let t={...e};return delete t[U],t}function Ne(e,t){let r=be(t);return{...r,[U]:ht(e,r)}}function On(e,t){let r=t[U];if(typeof r!="string"||!/^[0-9a-f]{64}$/.test(r))return!1;let n;try{n=ht(e,t)}catch{return!1}return kn(Buffer.from(r,"hex"),Buffer.from(n,"hex"))}function Y(e,t,r=384){ct(it(e),{recursive:!0,mode:448});let n=B(it(e),`.${_n(e)}.${process.pid}.${Date.now().toString(36)}.${Oe(3).toString("hex")}.tmp`);try{let s=ut(n,"w",r);try{pt(s,t),dt(s)}finally{at(s)}ie(n,e)}catch(s){try{ft(n)}catch{}throw s}}function ve(e,t,r=8*1024*1024){let n=T(e,r);if(n===null)return{status:"missing"};if(n===!1)return{status:"unreadable"};let s;try{s=JSON.parse(Z(e,"utf8"))}catch{return{status:"unreadable"}}return!s||typeof s!="object"||Array.isArray(s)?{status:"unreadable"}:t?U in s?On(t,s)?{status:"ok",value:be(s)}:{status:"changed",value:be(s)}:{status:"unsealed",value:s}:{status:"unkeyed",value:be(s)}}function mt(e,t,r,n){let s=An(e),o=`${JSON.stringify(Ne(s,r),null,2)}
|
|
8
|
+
`;Y(t,o),n&&Y(we(e,n),o)}var Re="modes.json",En="compiled.json";function Nn(e){return $n(B(e.bin,"claude-hook.sh"))||jn(e)}function jn(e){let t=r=>{try{return xn(r).slice(0,200).some(n=>n.endsWith(".json")&&T(B(r,n),65536)===!0&&Z(B(r,n),"utf8").includes(`"${U}"`))}catch{return!1}};if(t(B(e.state,"lkg"))||t(B(e.state,"pending"))||t(e.approvals))return!0;for(let r of[e.modes,e.compiled,e.install])if(T(r,8*1024*1024)===!0)try{if(Z(r,"utf8").includes(`"${U}"`))return!0}catch{}return!1}var Tn=600*1e3,hl=1440*60*1e3;function wt(e){return je(e.state,"pending")}var In=()=>Pn(8).toString("hex");function Mn(e,t,r,n,s,o,l){let i=0;for(let{hold:a,file:u}of X(e,t,o))if(!(u===l||(a.session??null)!==(r??null)||(a.project??null)!==(n??null)||a.stops.length===0)&&a.stops.every(f=>s.some(g=>Dn(g,f))))try{bt(u),i++}catch{}return i}function Dn(e,t){return e.kind===t.kind&&(e.target??null)===(t.target??null)}function X(e,t,r){let n=[];try{n=Ln(wt(e)).filter(o=>o.endsWith(".json")).slice(0,2e3)}catch{return[]}let s=[];for(let o of n){let l=je(wt(e),o),i=ve(l,t,64*1024);i.status!=="ok"||i.value.v!==2||!Array.isArray(i.value.stops)||!(Date.parse(i.value.expires_at)>=r)||s.push({hold:i.value,file:l})}return s.sort((o,l)=>Date.parse(l.hold.created_at)-Date.parse(o.hold.created_at))}function kt(e,t,r,n){let s=`${r}.claimed-${process.pid}-${n}`;try{yt(r,s)}catch{return null}let o={v:2,id:In(),session:t.session,project:t.project,stops:t.stops,created_at:new Date(n).toISOString(),expires_at:new Date(n+Tn).toISOString()};try{J(e.approvals),mt(e,je(e.approvals,`${o.id}.json`),o)}catch(l){try{yt(s,r)}catch{}throw l}try{bt(s)}catch{}try{Mn(e,D(e),t.session,t.project,t.stops,n)}catch{}return o}import{statSync as Wn}from"fs";function $t(e){if(!e||!e.endsWith(".jsonl"))return null;for(let t of[256*1024,4*1024*1024]){let r=G(e,t),n=r.lastIndexOf('"promptId":"');if(n>=0){let o=/^"promptId":"([^"\\]{1,120})"/.exec(r.slice(n,n+140));if(o)return o[1]}let s=0;try{s=Wn(e).size}catch{return null}if(s<=t)break}return null}import{createHash as Nt}from"crypto";import{closeSync as Bn,constants as St,fstatSync as Un,lstatSync as Kn,openSync as qn,readdirSync as Jn,readSync as Gn,realpathSync as Vn,statSync as Te}from"fs";import{basename as Ie,dirname as Yn,join as At,resolve as le}from"path";import{lstatSync as Fn,readdirSync as Hn}from"fs";import{join as vt}from"path";var Pe=e=>/[*?[\]{}]/.test(e);function xt(e,t){let[r,n]=[[...e],[...t]],[s,o,l,i]=[0,0,-1,0];for(;s<r.length;)if(n[o]==="*")[l,i]=[o++,s];else if(o<n.length&&(n[o]==="?"||n[o]===r[s]))s++,o++;else{if(l<0)return!1;[o,s]=[l+1,++i]}for(;n[o]==="*";)o++;return o===n.length}var zn=4096;function _t(e,t,r=0,n=()=>{},s=o=>Hn(o)){let o=[e.slice(0,r)||"/"],l=e.slice(r);if(l.includes("**"))return null;for(let a of l.split("/").filter(Boolean)){let u=0;for(let h of a)if(h==="{")u++;else if(h==="}"&&--u<0)return null;if(u!==0)return null;let f=a.replace(/[[{].*[\]}]/,"*");if(!/[*?]/.test(f)){o=o.map(h=>vt(h,a));continue}let g=[];for(let h of o){n();let y;try{y=s(h)}catch(x){if(!/^(ENOENT|ENOTDIR)$/.test(x.code??""))return null;continue}for(let x of a.startsWith(".")?[...y,".",".."]:y)if(n(),(xt(x,f)||xt(x.normalize("NFC"),f.normalize("NFC")))&&g.push(vt(h,x)),g.length>zn)return null}o=g}let i=new Set;for(let a of new Set([e,...o])){n();try{Fn(a,{throwIfNoEntry:!1})&&i.add(a)}catch(u){if(!/^(ENOENT|ENOTDIR|ENAMETOOLONG)$/.test(u.code??""))return null}}return i.size>t?null:[...i]}var Ct="claude.bash.process.kill_by_name",Zn=1500,Xn=128,Qn=1e3,er=256*1024*1024,Rt=4,tr=/(?:\.(?:log|output|pid|lock|db|sqlite3?|(?:db|sqlite3?)-(?:wal|shm|journal))|(?<!plan)\.out)$/i,jt=/(?:^|[^\w.-])(?:git|gh|hub|glab)(?![\w.])/,Ot=/^(?:cd|pushd|-C|--?(?:cwd|prefix|dir|directory|chdir|root|project|project-dir|work-tree|git-dir))$/,nr=e=>Nt("sha256").update(e).digest("hex"),Le=e=>e.code??"",rr=e=>{try{return Te(H(e)).isDirectory()}catch{return!1}},or="\0;";function Pt(e,t,r,n=0){let s=[],o=[],l=null;for(let f of e.replace(/\$\(pwd\)|`pwd`/g,".").replace(/\$(?=['"])/g,"").split(`
|
|
9
|
+
`)){if(l!==null){let h=f.length;for(;h>0&&/[)"'`;\s]/.test(f[h-1]);)h--;f.slice(0,h).trim()===l?l=null:o[o.length-1]+=`${f}
|
|
10
|
+
`;continue}s.push(f);let g=n<Rt?/<<-?\s*(?:'([\w.-]+)'|"([\w.-]+)"|\\?([\w.-]+))/.exec(f.replace(/<<</g,"")):null;l=g?g[1]??g[2]??g[3]:null,l!==null&&o.push("")}let i=[],a=s.join(`
|
|
11
|
+
`),u=0;for(let f of a.matchAll(/(>[>|&]?\s*)?((?:"(?:[^"\\]|\\[^])*"|'[^']*'|\\[^]|[^\s"'\\`;|&<>()])+)/g)){if(r(),/[;|&\n()]/.test(a.slice(u,f.index))&&i.push(or),u=f.index+f[0].length,f[1])continue;let g=f[2].replace(/"((?:[^"\\]|\\[^])*)"|'([^']*)'|\\([^])/g,(h,y,x,N)=>y?.replace(/\\(["\\$`])/g,"$1")??x??N??"");n<Rt&&/\s/.test(g)&&o.push(g),i.push(g),t.all.add(g)}(n===0||jt.test(i.join(" ")))&&t.lines.push(i);for(let f of o)Pt(f,t,r,n+1)}function Et(e,t,r,n){let s=new Set,o=l=>{let i=l.replace(/^(?:~|\$HOME|\$\{HOME\})(?=\/|$)/,()=>t).replace(/^(?:\$PWD|\$\{PWD\})(?=\/|$)/,".").replace(/\$(?:\{([^{}]*)\}|(\w+|[@*#?]))/g,(a,u,f)=>r.get(u??f??"")??"*");i===""||i==="."||i.length>1024||/^-|[$`\0\n]/.test(i)||Pe(Ie(i))&&!/[\w-]{2,}/.test(i.replace(/[[{][^/]*[\]}]/g,""))||s.add(i)};for(let l of[e,...e.split(/[=,;@#:+]+/),e.slice(e.indexOf("=")+1),e.replace(/^.*?fileb?:\/\//,""),e.replace(/^-\w/,"")])o(l);return n&&o(`${e}.zip`),[...s]}function Lt(e,t,r=0){if(!(t.length>=2e3||r>8)){if(typeof e=="string")e.length<=1024&&!/[\n\0]/.test(e)&&t.push(e);else if(e&&typeof e=="object")for(let n of Object.values(e))Lt(n,t,r+1)}}function sr(e,t=Zn){let r=performance.now(),n=()=>{if(performance.now()-r>t)throw new Error("too much to read in time")},s=new Set;if(e.classification){let{action:c,also:p,service:m,attributes:k,why:R,findings:b}=e.classification,O=b??[{...k,action:c,service:m,why:R,host:k.host??void 0}];for(let $ of O)$.action!==Ct&&s.add(JSON.stringify([$.action,$.service,$.target,$.why,$.environment??null,$.environment_said??null,$.repo_dir??null,$.repo_remote??null,$.repo_via??null,$.host??null]));for(let $ of[c,...p])$!==Ct&&s.add($)}for(let[c,p]of Object.entries(e.touched??{}))for(let m of p)s.add(`${c} ${m}`);let o=Buffer.alloc(1024*1024),l=c=>{n();let p=null;try{let m=H(c),k=Vn(m),R=Te(k);if(R.isDirectory())return Kn(m).isSymbolicLink()?k:null;if(!R.isFile())return null;p=qn(k,St.O_RDONLY|St.O_NONBLOCK);let b=Un(p);if(!b.isFile())return null;if(b.size>er)return`${k} ${b.dev} ${b.ino} ${b.size} ${b.mtimeMs} ${b.ctimeMs}`;let O=Nt("sha256");for(let $=0,L=0;(L=Gn(p,o,0,o.length,$))>0;$+=L)O.update(o.subarray(0,L)),n();return`${k} ${O.digest("hex")}`}catch(m){if(/^(ENOENT|ENOTDIR|ENAMETOOLONG|ELOOP|EINVAL)$/.test(Le(m)))return null;if(!/^(EACCES|EPERM)$/.test(Le(m)))throw m;let k=Te(H(c),{throwIfNoEntry:!1});return`not readable ${k?.ino} ${k?.size} ${k?.mtimeMs} ${k?.ctimeMs}`}finally{p!==null&&Bn(p)}},i=new Map,a=new Set,u=c=>{let p=e.cwd&&c.startsWith(`${e.cwd}/`)?c.slice(e.cwd.length+1):c.startsWith(`${e.home}/`)?`~${c.slice(e.home.length)}`:c;return JSON.stringify(p.length>60?`\u2026${p.slice(-59)}`:p)},f=(c,p)=>{p!==null&&i.set(c,{called:u(c),is:p})},g=c=>{a.has(c)||(a.add(c),!i.has(c)&&!tr.test(c)&&c!==At(e.home,".claude.json")&&f(c,l(c)))};for(let[c,p]of Object.entries(e.scripts))f(c,nr(p));for(let c of e.unread)i.has(c)||f(c,["","package.json","index.js","index.mjs","index.cjs","index.ts","__main__.py"].map(p=>l(At(c,p))??"-").join(`
|
|
12
|
+
`));let h=[e.command??"",...Object.values(e.scripts)],y={lines:[],all:new Set};for(let c of h)Pt(c,y,n);let x=[];e.command===null&&Lt(e.input,x);let N=new Map,A=c=>c.normalize("NFC").toLowerCase(),I=c=>{let p=N.get(c);if(p===void 0){n();try{let m=Jn(H(c));p={names:m,has:new Set(m.map(A))}}catch(m){p=/^(ENOENT|ENOTDIR)$/.test(Le(m))?{names:[],has:new Set}:null}N.set(c,p)}return p},j=c=>{n();let p=I(c);if(!p)throw Object.assign(new Error("not listed"),{code:"EACCES"});return p.names},P=(c,p)=>{let m=le(c,p);return _t(m,Qn,!p.startsWith("/")&&c!=="/"&&m.startsWith(`${c}/`)?c.length:0,n,j)},C=new Map;for(let c of y.all){let[,p,m]=/^([A-Za-z_]\w*)=([^$`]+)$/.exec(c)??[];p&&C.set(p,m)}let E=new Set([le(e.cwd??"/")]),Q=/\bunzip\b/.test(h[0]);for(let c of e.classification?.findings??[e.classification?.attributes])c?.repo_dir&&E.add(le(c.repo_dir));for(let c of Object.keys(e.scripts))E.add(Yn(c));process.env.GIT_DIR&&E.add(le(e.cwd??"/",process.env.GIT_DIR));for(let c of y.lines)c.forEach((p,m)=>{let[,k,R]=/^(--?[\w-]+)=(.+)$/.exec(p)??[],b=k&&Ot.test(k)?R:m>0&&Ot.test(c[m-1])?p:null;if(b!==null){for(let O of Et(b,e.home,C,!1))for(let $ of[...E])for(let L of P($,O)??[])if(n(),rr(L)&&E.add(L),E.size>Xn)throw new Error("too many folders")}});let ee=(c,p)=>{let m=c.split("/",1)[0];for(let k of E){n();let R=le(k,c);if(p&&Pe(c)){if(!a.has(R)){for(let b of P(k,c)??[])(b===R||Ie(c).startsWith(".")||!Ie(b).startsWith("."))&&g(b);a.add(R)}}else m===""||m==="."||m===".."||I(k)?.has.has(A(m))!==!1?g(R):a.add(R);if(m==="")return}};for(let c of y.all)for(let p of Et(c,e.home,C,Q))ee(p,!0);for(let c of x)for(let p of new Set([c,c.replace(/^file:\/\//,"")]))p!==""&&ee(p.replace(/^~(?=\/)/,()=>e.home),!1);if(h.some(c=>jt.test(c))){let c=new Set,p=y.lines.map(b=>b.map(O=>O.replace(/\$(?:\{(\w+)\}|(\w+))/g,($,L,te)=>C.get(L??te??"")??$))),m=p[0],k=m.flatMap((b,O)=>/(?:^|\/)(?:git|gh|hub|glab)$/.test(b)?[m[O+1]]:[]),R=E.size>1&&(m[0]==="cd"||k.length>0&&k.every(b=>b==="-C"));for(let b of[...E].slice(R?1:0)){n();for(let[O,$]of Ye(H(b),H(e.home),p,c,n,l)??[])i.set(O,$)}}return e.model!==null&&i.set("\0model",{called:"the helper's model",is:e.model}),{does:s,uses:i,looked:a}}function ir(e,t){let[r,n,s]=[new Set,new Set,new Set];[...t.does].some(o=>!e.does.has(o))&&r.add("what it does");for(let o of new Set([...e.uses.keys(),...t.uses.keys()])){let[l,i]=[e.uses.get(o),t.uses.get(o)];if(l?.is===i?.is)continue;let{called:a}=l??i;!(l&&i)&&!(e.looked.has(o)&&t.looked.has(o))?s.add(a):(o.includes("\0")?r:n).add(a)}return r.size+n.size>0?[...r,...n]:[...s]}function lr(e,t){let r=sr(e),n=t.map(l=>ir(l,r)),s=n.at(-1)??[],o=s.length>3?` and ${s.length-3} more`:"";return{read:r,changed:n,said:s.length>0&&n.every(l=>l.length>0)?`since your yes, this changed: ${s.slice(0,3).join(", ")}${o}`:null}}import{spawn as ar}from"child_process";import{randomBytes as dr}from"crypto";import{existsSync as cr,statSync as Tt}from"fs";import{join as xe}from"path";var Me=6e4;function ur(e,t){return new Promise(r=>{let n=ar(e,[],{cwd:"/",detached:!0,stdio:["pipe","ignore","ignore"],env:{PATH:"/usr/bin:/bin"}}),s=setTimeout(r,1e3),o=()=>(clearTimeout(s),r());n.on("error",o),n.stdin.on("error",o),n.pid!==void 0&&(ye(t.mark,`${t.nonce} ${n.pid} ${Math.round(Date.now()+t.wait*1e3)}`),n.stdin.end(`${JSON.stringify(t)}
|
|
13
|
+
`,o),n.unref())})}function fr(e,t){let[,r,n]=/^[0-9a-f]{64} (\d{1,10}) (\d{1,16})$/.exec(G(e,128))??[];return Number(r)>1&&Fe(Number(r))&&Number(n)<=t}function pr(e,t){try{let r=t-Tt(e).mtimeMs,n=G(e,4096);return r>-5e3&&r<Me&&(n===""||cr(n))?Math.min(Me,Me-r)/1e3:0}catch{return 0}}async function gr(e){try{if((e.platform??process.platform)!=="darwin"||!e.env.CLAUDE_CODE_ENTRYPOINT||["CI","VITEST","SSH_CONNECTION","SSH_TTY","SSH_CLIENT","ANVIL_NO_NOTIFY"].some(u=>e.env[u])||!e.transcript||!Tt(e.transcript).isFile())return;let t=xe(e.bin,De);if(!(e.ready??_e)(t))return;let r=se(e.anvilDir),n=D(r);if(ve(r.install,n,4*1024*1024).status!=="ok")return;let s=X(r,n,e.now).find(({hold:u})=>(u.session??null)===e.session&&u.call===e.call);if(!s)return;J(r.state);let o=xe(r.state,"card"),l=xe(r.state,`notice-${(e.session??"none").replace(/[^\w-]/g,"_").slice(0,80)}`),i=fr(o,e.now),a=ae(e.why,300);await(e.start??ur)(t,{v:1,kind:"card",nonce:dr(32).toString("hex"),title:"Held for your OK",why:a.charAt(0).toUpperCase()+a.slice(1),project:We(e.cwd??"",e.home),how:e.again?"Ask Claude to try again, or run this in a terminal:":"Run this in a terminal, then tell Claude to go on:",command:`${F(e.cli)} allow`,mark:o,hold:s.file,lock:xe(r.state,"window.lock"),gap:l,wait:i?0:pr(l,e.now),seconds:Math.min(86400,Math.max(1,Math.round((Date.parse(s.hold.expires_at)-e.now)/1e3))),quiet:i})}catch{}}var De="Anvil",xr="8056c717c1922a26fcc0d797e30a24eb1c310842455884551ce01a1ea552e427",_r={10:"declined",11:"unanswered",12:"failed",13:"away",14:"busy",15:"failed",16:"failed",17:"locked",18:"turn"},Sr=42,de=2e4,Ar=700,Cr=10*6e4,Rr=3,Kt=15,Or=new RegExp("^(?:[\\p{Cc}\\p{Cf}\\p{Zl}\\p{Zp}\\p{Co}\\p{Cn}\\p{Cs}]|(?! )\\p{Zs}|[\\u034f\\u115f\\u1160\\u17b4\\u17b5\\u180b-\\u180d\\u180f\\u2800\\u3164\\uffa0\\ufe00-\\ufe0f\\ufffc]|[\\u{e0100}-\\u{e01ef}])$","u"),Er=2,Nr=24,jr=3,It=30,ce=class{text="";marks=[];lines=[];beside=!1;line=0;mark(t){this.marks.push([this.text.length,t.length]),this.text+=t}start(){this.lines.length>0&&(this.text+=`
|
|
14
|
+
`),this.lines.push(this.beside?0:this.line+=1)}skip(t){this.lines.length>0&&(this.text+=`
|
|
15
|
+
`),this.lines.push(0),this.line+=t,this.mark(`${t} empty lines`)}put(t){let r=t.split(`
|
|
16
|
+
`);for(let n=0;n<r.length;n++){if(n>0){let s=0;for(;n+s<r.length&&r[n+s]==="";)s++;if(s>jr){this.skip(s),n+=s-1;continue}this.start()}this.putLine(r[n])}}putLine(t){let r=i=>t[i]===" "||t[i]===" ",n=this.text===""||this.text.endsWith(`
|
|
17
|
+
`),s=(i,a)=>{let u=a+/^[!-~]*/.exec(t.slice(a,a+It))[0].length;return u>a&&i+u-a<=It&&(u===t.length||t[u]===" "&&!r(u+1))},o=0,l="";for(let i=0;i<t.length;){if(r(i)){let f=i;for(;r(f);)f++;let g=t.slice(i,f),h=g.length;f===t.length||h>Nr?this.mark(g.includes(" ")&&g.includes(" ")?`${h} spaces and tabs`:`${h>1?`${h} `:""}${g[0]===" "?"space":"tab"}${h>1?"s":""}`):i===0&&!n?(this.mark(g.replace(/ /g,"\xB7").replace(/\t/g,"\u21E5")),this.text+=" "):g===" "||i===0&&!g.includes(" ")&&s(h,f)?this.text+=g:(this.mark(g.includes(" ")?g.replace(/ /g,"\xB7").replace(/\t/g,"\u21E5"):"\xB7".repeat(h-1)),this.text+=" "),i=f,[l,o]=[" ",0];continue}let a=String.fromCodePoint(t.codePointAt(i));o=new RegExp("^\\p{M}$","u").test(a)?o+1:0;let u=Or.test(a)||o>0&&(o>Er||!/^[\p{L}\p{M}]$/u.test(l));if(u){let f=a.codePointAt(0);this.mark(f>65535?`\\u{${f.toString(16)}}`:`\\u${f.toString(16).padStart(4,"0")}`),o=0}else this.text+=a;l=u?"":a,i+=a.length}}};function ae(e,t){let r=new ce;return r.start(),r.put(t===void 0?e:e.trim().replace(/[ \t]*\n[ \t\n]*/g," \u21B5 ").replace(/[ \t]+/g," ")),t!==void 0&&r.text.length>t?`${Pr(r.text.slice(0,t-1))}\u2026`:r.text}var Pr=e=>e.replace(/[\ud800-\udbff]$/,"");function Lr(e,t){let r=t&&typeof t=="object"&&!Array.isArray(t)?t:null;if(!r)return null;let n=(e==="Bash"||e==="PowerShell")&&typeof r.command=="string"?r.command:null,s=Object.entries(r).filter(([l])=>n===null||!["command","description","timeout"].includes(l));if((n===null?e==="":n.trim()==="")||(n??"").length>de||s.some(([,l])=>typeof l=="string"&&l.length>de))return null;let o=new ce;o.start(),n!==null?o.put(n):o.mark(Dt(e)),o.beside=n!==null;for(let[l,i]of s){let a=typeof i=="object"&&i!==null,u=typeof i=="string"?i:JSON.stringify(i,null,2)??"null";if(l.length>Mt||u.length>de||o.text.length>de)return null;o.start(),o.mark(`${Dt(l)}${a?" (data)":""}:`),u.includes(`
|
|
18
|
+
`)?o.start():o.text+=" ",typeof i=="string"||a?o.put(u):o.mark(u)}return o.text.length>de||e.length>Mt?null:{text:o.text,marks:o.marks,lines:o.lines}}var We=(e,t)=>ae(e===t||e.startsWith(`${t}/`)?`~${e.slice(t.length)}`:e,300),Mt=200;function Dt(e){if(/^[\w.:/-]+$/.test(e))return e;let t=new ce;return t.start(),t.put(JSON.stringify(e).replace(/ {2,}/g,r=>"\\u0020".repeat(r.length))),t.text}var Tr=e=>e.charAt(0).toUpperCase()+e.slice(1);function _e(e,t=xr,r=process.platform){try{if(r!=="darwin"||!/^[0-9a-f]{64}$/.test(t)||!kr(e).isFile())return!1;wr(e,br.X_OK);let n=M(e,16*1024*1024);return n!==null&&ze("sha256").update(n).digest("hex")===t}catch{return!1}}function Ir(){let e=new Map;try{for(let r of mr("/bin/ps",["-A","-o","pid=,ppid="],{encoding:"utf8",timeout:2e3,env:{}}).stdout.split(`
|
|
19
|
+
`)){let n=/^\s*(\d+)\s+(\d+)\s*$/.exec(r);n&&e.set(Number(n[1]),Number(n[2]))}}catch{}let t=[];for(let r=process.ppid;r>1&&t.length<3;r=e.get(r)??0)t.push(r);return t}function Fe(e){try{return process.kill(e,0),!0}catch(t){return t.code==="EPERM"}}var Wt=`shown
|
|
20
|
+
`,Mr=2e4;function Dr(e,t){let r=JSON.stringify({v:1,nonce:yr(32).toString("hex"),lock:t.lock,...e}),n=`${Wt}allowed ${ze("sha256").update(r).digest("hex")}
|
|
21
|
+
`,s=Date.now()+e.seconds*1e3,o=process.hrtime.bigint(),l=()=>Number(process.hrtime.bigint()-o)/1e6,i=()=>Date.now()<s&&l()<e.seconds*1e3,a=()=>(t.needs??[]).every(Fe);return new Promise(u=>{let f={},g=!1,h=A=>{g||(g=!0,clearInterval(f.watch),u(A))};if(!_e(t.program,t.sha256,t.platform))return h("failed");let y;try{y=hr(t.program,[],{cwd:"/",stdio:["pipe","pipe","ignore"],env:{HOME:vr().homedir,PATH:"/usr/bin:/bin"}})}catch{return h("failed")}let x="",N=!1;y.stdout.setEncoding("utf8").on("data",A=>{x=(x+A).slice(0,4096),!N&&x.startsWith(Wt)&&(N=!0,t.shown?.())}),y.on("error",()=>h("failed")),y.stdin.on("error",()=>{}),y.on("close",(A,I)=>{if(!a())return h("gone");if(I!==null||A===null)return h("failed");if(A!==Sr)return h(_r[A]??"failed");if(x!==n)return h("failed");h(i()?"allowed":"unanswered")}),y.stdin.write(`${r}
|
|
22
|
+
`),f.watch=setInterval(()=>{let A=a()?!x&&l()>(t.opens??Mr)?"failed":Date.now()>s+2e3?"unanswered":null:"gone";A!==null&&(y.kill("SIGKILL"),h(A))},500)})}var qt=e=>He(e.state,"window.json");function Jt(e,t){let r=Ce(qt(e)),n=r?.unanswered;return{unanswered:typeof n=="number"&&n>0&&n<=t?n:null,nos:(Array.isArray(r?.nos)?r.nos:[]).filter(s=>s&&typeof s.s=="string"&&typeof s.k=="string"&&typeof s.t=="number"&&s.t<=t&&t-s.t<Cr)}}function Ft(e,t,r){try{J(e.state);let n=r(Jt(e,t));ye(qt(e),JSON.stringify({...n,nos:n.nos.slice(-50)}))}catch{}}function Wr(e){let t=Number(/^\d{1,3}$/.exec(e.ANVIL_HOOK_WAIT??"")?.[0]??0);return t>=Kt&&t<=600?t:null}function Fr(e){return!e.CI&&!e.SSH_CONNECTION&&!e.SSH_TTY&&!e.SSH_CLIENT&&!e.ANVIL_NO_WINDOW}var Hr={unanswered:["no one answered in time","No one answered in time"],away:["you were away","The user was away from their Mac"],locked:["your Mac was locked","The user's Mac was locked"],busy:["another approval was open the whole time","Another approval was open the whole time"]};function zr(e){if(!e)return!1;for(let t of[64*1024,2*1024*1024]){let r;try{r=G(e,t).split(`
|
|
23
|
+
`)}catch{return!1}let n=r.flatMap(s=>{if(!s.includes('"version"'))return[];try{let o=JSON.parse(s)?.version;return typeof o=="string"?[o]:[]}catch{return[]}});if(n.length>0)return n.every(s=>st(s))}return!1}async function Xl(e,t){let r=Wr(t.env);if(r===null||!Fr(t.env)||e.payload.permission_mode==="dontAsk"||!zr(e.transcript))return null;let n=He(t.bin,De);if(!(t.ready??_e)(n))return null;let s=typeof e.payload.tool_name=="string"?e.payload.tool_name:"",o=e.budget?{text:"",marks:[],lines:[]}:Lr(s,e.payload.tool_input),l=Tr(`${e.reasons.map(C=>ae(C,1/0)).join("; ")}${e.always?" \xB7 on by default":""}${e.burst?" \xB7 a yes lets it go on":""}`);if(o===null||l.length>Ar)return null;let i=se(e.anvilDir),a=e.now(),u=e.session??"",f=ze("sha256").update(JSON.stringify([e.project,e.stops,e.budget?null:[s,e.payload.tool_input]])).digest("hex").slice(0,16),g=typeof e.payload.prompt_id=="string"&&e.payload.prompt_id?e.payload.prompt_id.slice(0,120):$t(e.transcript),h=Jt(i,a),y=h.nos.filter(C=>C.s===u),x=g===null?void 0:y.find(C=>C.k===f&&C.m===g);if(x?.u&&e.budget)return null;if(x)return e.opening(),x.u?(Gt(i,e,a).length===0&&Ht(e),zt(e,"unanswered")):Bt(e,!0);if(y.length>=Rr)return null;let N=Math.floor(r-(a-t.started)/1e3);if(N<Kt||N>r||!e.budget&&!await e.look())return null;let A=typeof e.payload.cwd=="string"?e.payload.cwd:e.project??"",I={title:e.budget||e.burst?"Keep going?":"Allow this once?",why:l,detail:o.text,marks:o.marks,lines:o.lines,detail_label:"What Claude wants to do",project:We(A,t.home),reason:e.budget?"let Claude keep going past your budget":`let Claude do this: ${ae(o.text,160)}`,waiting:"Waiting",seconds:N,...h.unanswered!==null?{unanswered_seconds:Math.max(0,Math.round((a-h.unanswered)/1e3))}:{}};J(i.state);let j=await(t.show??Dr)(I,{program:n,lock:He(i.state,"window.lock"),needs:Ir(),shown:e.opening}),P=e.now();return j==="turn"?{did:"turn"}:(e.opening(),j==="gone"?{did:"held",user:"",agent:`${V("Held by Anvil")} ${e.why}. Claude Code stopped before it was answered, so nothing ran.`}:j==="failed"?null:j==="allowed"||j==="declined"?(Ut(i,e,P),Ft(i,P,C=>({unanswered:null,nos:j==="allowed"?C.nos:[...C.nos,{s:u,k:f,t:P,m:g}]})),j==="declined"?Bt(e,!1):!e.budget||Br(i,e,P)?{did:"allowed"}:null):(j==="unanswered"&&Ft(i,P,C=>({unanswered:P,nos:[...C.nos,{s:u,k:f,t:P,m:g,u:!0}]})),e.budget?null:(Ut(i,e,P),Ht(e),zt(e,j))))}function Ht(e){try{e.keep()}catch{}}function zt(e,t){let[r,n]=Hr[t];return{did:"held",user:`${V("Held by Anvil for your OK")} ${e.why} \xB7 ${r}, so nothing ran${fe("Ask Claude to try again.")}${fe(`Or run in a terminal: ${F(e.cli)} allow`)}`,agent:`${V("Held by Anvil")} ${e.why}. ${n}, so nothing ran. Do not try another way. Tell the user it is waiting for them: they can ask you to try again and answer Anvil's pop-up, or ${Ge(e.cli,"tell you to go on")}. When they say so, run exactly the same call again, with nothing added to it.`,...t==="busy"?{}:{notify:!0}}}function Bt(e,t){let r=e.budget?e.why.replace(/ · an OK lets this task go on past it$/,""):e.why,n=t?"already said no to this":"said no";return{did:t?"held":"declined",user:`${V("Not allowed")} ${r} \xB7 you ${n}, so ${e.budget?"Claude stops here":"nothing ran"}${t&&!e.budget?fe("Changed your mind? Tell Claude to try again."):""}`,agent:`${V("Held by Anvil")} ${r}. The user ${n}, so nothing ran. ${e.budget?"Stop here and tell them.":"Don't run it again or try another way. Go on with anything that doesn't need it, or ask them what to do instead."}`}}function Gt(e,t,r){try{return X(e,D(e),r).filter(({hold:n})=>(n.session??null)===t.session&&(n.project??null)===t.project&&(t.budget?JSON.stringify(n.stops)===JSON.stringify(t.stops):n.call===t.call)).map(n=>n.file)}catch{return[]}}function Ut(e,t,r){for(let n of Gt(e,t,r))$r(n,{force:!0})}function Br(e,t,r){try{let n=t.keep(),s=n?X(e,D(e),r).find(o=>o.hold.id===n):void 0;return s!==void 0&&kt(e,s.hold,s.file,r)!==null}catch{return!1}}export{Sr as ALLOWED_EXIT,_r as ENDINGS,de as MAX_SHOWN,Wt as SHOWN,De as WINDOW_PROGRAM,Fe as alive,lr as asRead,Xl as askPerson,Fr as canAskHere,Lr as detailOf,gr as heldNotice,zr as holdsWhenLate,We as placeOf,Dr as showWindow,ae as shownText,Wr as waitSeconds,_e as windowReady};
|