@sabaiway/agent-workflow-kit 17.0.0 → 18.0.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 +39 -0
- package/README.md +2 -2
- package/SKILL.md +1 -1
- package/capability.json +1 -1
- package/package.json +1 -1
- package/references/advisor-writers.md +2 -3
- package/references/contracts.md +5 -3
- package/references/modes/gates.md +1 -1
- package/references/modes/hook.md +7 -7
- package/references/modes/recommendations.md +2 -2
- package/references/modes/state-block-guard.md +4 -0
- package/tools/apply-danger-check.mjs +27 -22
- package/tools/distribution-files/scripts.mjs +4 -2
- package/tools/gate-hook.mjs +25 -55
- package/tools/recommendations.mjs +56 -146
- package/tools/state-block-hook.mjs +6 -6
- package/tools/write-lanes.mjs +10 -12
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,45 @@ Semantically versioned ([semver](https://semver.org)), newest first. The `versio
|
|
|
4
4
|
is the current release. `upgrade` mode reads a project's `docs/ai/.workflow-version` and applies
|
|
5
5
|
every `migrations/<version>-<slug>.md` newer than it, in semver order.
|
|
6
6
|
|
|
7
|
+
## 18.0.0 — the kit's two hook files are written current within a hook you wired; `gate-hook --reseed` and three advisor items retire (AD-209)
|
|
8
|
+
|
|
9
|
+
**MAJOR: `gate-hook.mjs --reseed` is removed, and the advisor's `gate-hook.marker-stale`, `read-lane.stale` and
|
|
10
|
+
`read-lane.missing` items are gone.** Before, a placed gate hook that differed from the kit's was preserved by
|
|
11
|
+
`gate-hook --apply`; the advisor offered the reseed route, on your yes, in two states only: a declaration carrying
|
|
12
|
+
`lcovProducer`, and an enabled read-lane. A wired gate hook whose file was missing got `read-lane.missing`, whose apply
|
|
13
|
+
was `gate-hook --apply`; a wired state-block hook whose file was missing was never offered at all. Now one rule covers
|
|
14
|
+
both kit hook files, `.claude/hooks/agent-workflow-gates.mjs` and `.claude/hooks/state-block-guard.mjs`: within a hook
|
|
15
|
+
you wired (for the gate hook, a `PreToolUse` `Bash` entry running its command; for the state-block hook, a `Stop` entry
|
|
16
|
+
whose command names `state-block-guard.mjs`, whichever copy it runs — in `.claude/settings.json` or
|
|
17
|
+
`.claude/settings.local.json`), an absent file is placed and one whose bytes
|
|
18
|
+
differ is written with the body the kit writes for it, in place, with no question and no copy kept. Wiring stays
|
|
19
|
+
yours: an unwired hook keeps its `gate-hook` or `state-block` offer and your yes.
|
|
20
|
+
|
|
21
|
+
- **Two new kit items, `gate-hook.not-current` and `state-block.not-current`.** Over a wired hook whose file is absent
|
|
22
|
+
or differs, the advisor renders this `lane: kit` item, which the agent applies with no question by the kit route. Its
|
|
23
|
+
text reads `<the hook file> is absent or differs from the body the kit writes for it — written with that body, with
|
|
24
|
+
no question`, and its detail names the one file its apply writes. A stale stamp beside it is the upgrade-first skip.
|
|
25
|
+
- **`gate-hook --apply` writes a differing file.** It places an absent hook file, writes a differing one with the
|
|
26
|
+
bundled body in place, leaves a current one, and wires the entry only while it is wired in neither settings file —
|
|
27
|
+
so over a wired hook it writes the file alone. A differing file under an unwired hook is no longer refused: your yes
|
|
28
|
+
to the offer writes and wires it.
|
|
29
|
+
- **The line.** A differing kit hook file reads `differs from the body the kit writes for it — written with that body;
|
|
30
|
+
a hook of your own goes in .claude/hooks/<name>.local.mjs` (on a dry run, `would be written with that body`), from
|
|
31
|
+
both hook writers. No line says preserved or reseed.
|
|
32
|
+
- **The danger check** for a kit hook item admits only that hook file and its folders, and only while it judges the
|
|
33
|
+
hook wired; over an unwired hook it admits nothing (`refused:`, exit 1), so the no-question apply never wires a hook.
|
|
34
|
+
- **`read-lane` is the enable offer alone.** It renders while the hook is wired and the lane is off; a stale or absent
|
|
35
|
+
hook under it is written by `gate-hook.not-current` first. The `--read-lane` currency refusal now names
|
|
36
|
+
`gate-hook --apply`.
|
|
37
|
+
- **`--reseed` is gone, with no alias.** `gate-hook.mjs --reseed` now stops with `unknown argument: --reseed`, exit 2.
|
|
38
|
+
No migration note is owed: every line that printed it — the retired items `gate-hook.marker-stale` and
|
|
39
|
+
`read-lane.stale`, the writer's refusals, its diverged line and `--help` — is gone or now names `gate-hook --apply`,
|
|
40
|
+
and a script that ran `--apply --reseed` runs `gate-hook.mjs --apply`.
|
|
41
|
+
- **The texts say the same.** The writer's header and `--help`; the hook, gates, state-block-guard and recommendations
|
|
42
|
+
modes; `references/advisor-writers.md`; the README's hook and state-block-guard rows; the guide's *Reserved names and
|
|
43
|
+
channels*, which names the two hook files and gains a seventh channel, `.claude/hooks/<name>.local.mjs`, for a hook
|
|
44
|
+
of your own, which you wire.
|
|
45
|
+
|
|
7
46
|
## 17.0.0 — every kit agent file is written current with no question; `--executor` and `executor-vehicle.differing` retire (AD-208)
|
|
8
47
|
|
|
9
48
|
**MAJOR: `cheap-agents.mjs --executor` is removed, and the advisor's `executor-vehicle.differing` item is gone.** Before,
|
package/README.md
CHANGED
|
@@ -264,8 +264,8 @@ file), or run the guarded `/agent-workflow-kit uninstall`.
|
|
|
264
264
|
| `/agent-workflow-kit uninstall` | opt-in, any time | **guarded teardown** — the inverse of `init` / `setup`. Removes only what's **provably ours** (managed skill dirs + bridge wrappers; in a project, the hidden-mode git-ignore block it added + the pre-commit hook it installed); **never deletes** your `docs/ai` / `AGENTS.md` (prints the exact `rm` to run by hand) or your `.claude/settings.json` (prints an **edit** — remove the attribution key, review any velocity `permissions.*` — never an `rm`). Always `--dry-run` first; preflight-then-mutate; never commits. |
|
|
265
265
|
| `/agent-workflow-kit velocity` | Claude Code · opt-in | **onboarding velocity profile** — seeds a fixed, audited **read-only** allowlist into `.claude/settings.json` so routine read-only commands stop idling on approval prompts while you're away; every allowlist apply (flagless, `--kit-tools`, `--bridge-tier`) also seeds one `permissions.ask` rule, so all work can stay in auto mode: without it auto mode refuses a harness or kit apply (the `apply:` line of each harness or kit item the upgrade advisor renders) and you must leave auto mode for it; with it the harness shows its usual dialog — the rule allows nothing; opt-in `acceptEdits`; plus a **read-only advisory** of likely project gate commands to add by hand. Writes `.claude/settings.json`; a fourth opt-in, `--worktrees`, writes the worktrees grant into the local settings, `.claude/settings.local.json`, alone — **never** allowlists commit/push/publish, never commits. A seeded entry is a **trust posture, not a sandbox** (a runtime residual remains at the settings level — its guard ships as the opt-in `hook` command); a direct commit/push/publish still asks. `--dry-run` first. |
|
|
266
266
|
| `/agent-workflow-kit agents` | Claude Code · opt-in | **subagent vehicles** — places the five bundled subagent definitions into `.claude/agents/`: **four read-only vehicles + one full-tool `executor`**. **No read-only vehicle gets `Bash`**, and that is the load-bearing property: a read-only fan-out on a full-tool subagent shells out for facts it could have read, and every shelled command is an approval prompt you never needed to see. Three of the four ride a **cheap model** (haiku, low effort) for mechanical work — extraction sweeps, changelog fact-skeletons, gate-failure triage; the fourth, **`review-lens`**, is an ADDITIONAL independent read-only review opinion on code your configured backends have already seen (never a replacement for your plan or diff review recipe, advisory like every review; an epic is reviewed by the lens alone, whatever `epic.review` resolves to). The fifth, **`executor`** (all tools; model and effort from `docs/ai/vehicles.json`), is the ONE vehicle with a shell and the instrument behind the **Subagent** recipe: dispatched only for a bounded, file-disjoint execution / authoring / routine slice you verify afterwards — never for read-only work, never as a review backend, and it never commits. Its state (`placed` / `customized` / `unusable` / `missing`) is what a `subagent` slot's readiness resolves from. Writing code and running gates stay off the four read-only vehicles; the executor carries a bounded slice you re-verify on your main lane, and every vehicle's output is verified. Preview by default (`--apply` writes); every kit agent file (the five bundled names and each configured roster-derived lens) is **written current with no question** — an absent one placed, a differing one written with the body the kit writes for it, the executor's and the bundled `review-lens`'s (opus / high by default, set in the file's optional `review-lens` section) derived from `docs/ai/vehicles.json`, no copy kept; a link at a kit agent path stops the run naming it, nothing written; a vehicle of your own goes in `.claude/agents/<name>.local.md` with a `name:` of its own; never touches `settings*.json`, never commits. |
|
|
267
|
-
| `/agent-workflow-kit hook` | Claude Code · opt-in | **gate-approval hook** — places a self-contained PreToolUse hook (`.claude/hooks/`) and wires it into `.claude/settings.json`: a Bash command **byte-identical** to a gate you declared in `docs/ai/gates.json` (run from the project root) is auto-approved — no prompt, no idle; a seeded read-only command carrying a runtime residual (output redirection, command substitution, `--output` writes) now **asks** even where an allow rule would have silently passed it (proven live — hook `ask` overrides an allow rule). Detection is a conservative string scan, so it over-asks on a byte that is ordinary text — searching for `=>`, or a read wearing `2>/dev/null`, prompts. That is a documented open limit: 4.1.0 built three mechanisms to narrow it and removed all three in review, each counterexample kept as a test (see Mode: hook). Exact matches only, never patterns; never `deny`; a broken `gates.json` only disables auto-approval, never the guard. An opt-in **read-lane** (`--read-lane` → `docs/ai/lanes.json`, a **separate** file from `gates.json`) additionally auto-approves *compounds* of seeded read-only commands carrying no shell metaprogramming; `--apply --read-lane` verifies the placed hook is current first
|
|
268
|
-
| `/agent-workflow-kit state-block-guard` | Claude Code · opt-in | **closing-block detector** — a `Stop` hook that reads the turn's final assistant message and warns when the closing state block is defective: the «what I need from you» slot answering *nothing* (a turn that ENDS always needs a resume, so the answer is false, not merely unhelpful), or a first-person promise of imminent work in a turn that is over. Judged on the slot's first clause, so a real ask followed by a clause break and "nothing else" passes, and a promise gated on something named passes; matching is word-bounded and Unicode-aware, quoted and fenced examples are stripped, and the last STARTED block decides — an incomplete tail counts as no block rather than falling back to an earlier one. A message carrying no block at all is silent unless you pass `--require-block` — this kit does not mandate the block, and a hook that runs every turn must not warn every turn. The judgement is lexical and the mode doc names every residual it leaves. **Detection, never prevention** — a `Stop` hook cannot un-send the message it judges; what it buys is that a silent recurrence becomes a visible one. Warns via `systemMessage` and **exits 0 on every path**: never `deny`, never blocks the stop, never re-enters the model. Reads nothing but the message, makes no network call, approves nothing. Its writer is `tools/state-block-hook.mjs`: it places the self-contained hook and merges its `Stop` entry into `.claude/settings.json` by the three merge cases, keeping every foreign hook — the agent applies it on the chat yes after the danger check. |
|
|
267
|
+
| `/agent-workflow-kit hook` | Claude Code · opt-in | **gate-approval hook** — places a self-contained PreToolUse hook (`.claude/hooks/`) and wires it into `.claude/settings.json`: a Bash command **byte-identical** to a gate you declared in `docs/ai/gates.json` (run from the project root) is auto-approved — no prompt, no idle; a seeded read-only command carrying a runtime residual (output redirection, command substitution, `--output` writes) now **asks** even where an allow rule would have silently passed it (proven live — hook `ask` overrides an allow rule). Detection is a conservative string scan, so it over-asks on a byte that is ordinary text — searching for `=>`, or a read wearing `2>/dev/null`, prompts. That is a documented open limit: 4.1.0 built three mechanisms to narrow it and removed all three in review, each counterexample kept as a test (see Mode: hook). Exact matches only, never patterns; never `deny`; a broken `gates.json` only disables auto-approval, never the guard. An opt-in **read-lane** (`--read-lane` → `docs/ai/lanes.json`, a **separate** file from `gates.json`) additionally auto-approves *compounds* of seeded read-only commands carrying no shell metaprogramming; `--apply --read-lane` verifies the placed hook is current first. Within a hook you wired, its file is placed when absent and written with the kit's body when it differs, with no question and no copy kept (the upgrade's `gate-hook.not-current`); a hook of your own goes in `.claude/hooks/<name>.local.mjs`, which you wire. Preview by default; never writes `settings.local.json`; never commits. |
|
|
268
|
+
| `/agent-workflow-kit state-block-guard` | Claude Code · opt-in | **closing-block detector** — a `Stop` hook that reads the turn's final assistant message and warns when the closing state block is defective: the «what I need from you» slot answering *nothing* (a turn that ENDS always needs a resume, so the answer is false, not merely unhelpful), or a first-person promise of imminent work in a turn that is over. Judged on the slot's first clause, so a real ask followed by a clause break and "nothing else" passes, and a promise gated on something named passes; matching is word-bounded and Unicode-aware, quoted and fenced examples are stripped, and the last STARTED block decides — an incomplete tail counts as no block rather than falling back to an earlier one. A message carrying no block at all is silent unless you pass `--require-block` — this kit does not mandate the block, and a hook that runs every turn must not warn every turn. The judgement is lexical and the mode doc names every residual it leaves. **Detection, never prevention** — a `Stop` hook cannot un-send the message it judges; what it buys is that a silent recurrence becomes a visible one. Warns via `systemMessage` and **exits 0 on every path**: never `deny`, never blocks the stop, never re-enters the model. Reads nothing but the message, makes no network call, approves nothing. Its writer is `tools/state-block-hook.mjs`: it places the self-contained hook and merges its `Stop` entry into `.claude/settings.json` by the three merge cases, keeping every foreign hook — the agent applies it on the chat yes after the danger check. Within the wired hook its runtime file is written with the kit's body when absent or differing, with no question (the upgrade's `state-block.not-current`); a hook of your own goes in `.claude/hooks/<name>.local.mjs`, which you wire. |
|
|
269
269
|
| `/agent-workflow-kit bridge-settings` | opt-in, any time | **host-level bridge settings** — read or change the bridges' `KEY=VALUE` config file (`${XDG_CONFIG_HOME:-~/.config}/agent-workflow/bridge-settings.conf`), the **one place a knob survives kit upgrades** (it lives outside every kit tree; a refresh never touches it, and now states loudly if it ever overwrote a local edit). The **model each bridge runs**: `CODEX_MODEL` + `CODEX_EFFORT` (default `gpt-6.1-sol` at `high`) and `AGY_MODEL` (default `Gemini 3.8 Flash (High)`) — the read-out shows the models each installed CLI offers, and a set one is checked against that list before anything is written. Other knobs: the **codex Fast tier** (`CODEX_SERVICE_TIER=priority` — "2x speed, **increased usage**" in the catalog's own words, quality-neutral, default off — a consented spend), the codex/agy hard timeouts, the codex review byte cap, and `AGY_REVIEW_MAX_TOTAL_BYTES` (the ceiling on what an oversized agy code review may feed before it refuses pre-spend). `AGY_REVIEW_ALLOW_ADDDIR` is a **retired** compatibility key: still recognized so an existing line never warns as unknown, but it arms nothing — the writer refuses to set it and `--unset` clears it. Allowed keys + value rules come from the bundled bridge manifests. **Previews by default**; refuses an unknown key, an out-of-range value, a model or effort the catalog does not offer, or a duplicate-carrying file; writes atomically (symlink/TOCTOU-safe). Never commits, never runs a model (only the read-only catalog commands). |
|
|
270
270
|
| `/agent-workflow-kit autonomy-doctor` | opt-in, any time | **guarded sandbox provisioner "doctor"** — can this machine run the Claude sandbox, and (only with your consent) fix it: macOS Seatbelt built-in / Linux+WSL2 needs `bwrap`+`socat` / native Windows → WSL2. Flagless = **FS-only preview** (the diagnosis, the exact absolute-path command it WOULD run, the exact `--apply <pm>:<pkgs>` consent tuple — runs nothing, never claims ready); `--verify` runs the unprivileged proof (a `bwrap` user-namespace smoke + `socat -V`) — the **only** source of a Linux "ready (verified)" claim; `--apply <pm>:<pkgs>` is the consent-gated privileged install (the tuple must equal the previewed plan; everything executed resolves to absolute paths inside `/usr/bin:/bin:/usr/sbin:/sbin`; the exact command is re-printed immediately before execution), then verifies. Honest loud degrades (unknown PM, untrusted location, nested-sandbox INDETERMINATE, root-unproven) and a stated restart step. Sits **outside every velocity auto-approve tier**; never auto-runs, never writes repo files, never commits. |
|
|
271
271
|
|
package/SKILL.md
CHANGED
|
@@ -3,7 +3,7 @@ name: agent-workflow-kit
|
|
|
3
3
|
description: Deploy or upgrade a portable AI-agent memory-and-workflow system in any project. Use when the user wants to bootstrap `docs/ai/` + an entry-point `AGENTS.md` (+ `CLAUDE.md` alias) + cap/archive/index enforcement in a new or existing repo, set up the Memory Map and session protocols, install the docs-rotation pre-commit hook, or run `/agent-workflow-kit` / `/agent-workflow-kit upgrade`. Triggers on phrases like "set up the memory system", "deploy the AI workflow here", "bootstrap docs/ai", "upgrade the workflow". New to the epic, story and task tier? Run `/agent-workflow-kit tier`. A typed decision with a confidence from Jev? Run `/agent-workflow-kit jev`.
|
|
4
4
|
disable-model-invocation: true
|
|
5
5
|
metadata:
|
|
6
|
-
version: '
|
|
6
|
+
version: '18.0.0'
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
# agent-workflow-kit
|
package/capability.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sabaiway/agent-workflow-kit",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "18.0.0",
|
|
4
4
|
"description": "Portable, cross-agent memory & workflow for AI coding agents — Claude Code, Codex, Cursor, Devin Desktop. One command deploys an AGENTS.md entry point + docs/ai context with cap/archive/index enforcement into any repo.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai-agents",
|
|
@@ -25,14 +25,13 @@
|
|
|
25
25
|
| source-size.schema-1 | chat | source-size-check.mjs |
|
|
26
26
|
| source-size.layout | chat | source-size-check.mjs |
|
|
27
27
|
| gate-hook | harness | gate-hook.mjs |
|
|
28
|
-
| gate-hook.
|
|
28
|
+
| gate-hook.not-current | kit | gate-hook.mjs |
|
|
29
29
|
| commit-guard | harness | git-hooks.mjs |
|
|
30
30
|
| hook-checks | harness | git-hooks.mjs |
|
|
31
31
|
| enforcement | harness | git-hooks.mjs |
|
|
32
32
|
| read-lane | chat | gate-hook.mjs |
|
|
33
|
-
| read-lane.stale | harness | gate-hook.mjs |
|
|
34
|
-
| read-lane.missing | harness | gate-hook.mjs |
|
|
35
33
|
| state-block | harness | state-block-hook.mjs |
|
|
34
|
+
| state-block.not-current | kit | state-block-hook.mjs |
|
|
36
35
|
| mcp-channel | harness | mcp.mjs |
|
|
37
36
|
| mcp-channel.differing | harness | mcp.mjs |
|
|
38
37
|
| agents | harness | cheap-agents.mjs |
|
package/references/contracts.md
CHANGED
|
@@ -99,10 +99,11 @@ customization: every kit script, the spec layer's four pair files (`scripts/spec
|
|
|
99
99
|
included, the hook installer set, the kit rules files `docs/ai/rules/<theme>.md` and the kit agent
|
|
100
100
|
files (the five the kit bundles for `.claude/agents/` — `changelog-skeleton.md`, `executor.md`,
|
|
101
101
|
`gate-triage.md`, `mechanical-sweep.md`, `review-lens.md` — and each configured
|
|
102
|
-
`review-lens-<model>-<effort>.md`)
|
|
103
|
-
|
|
102
|
+
`review-lens-<model>-<effort>.md`) and, within a hook you wired, the kit hook files
|
|
103
|
+
`.claude/hooks/agent-workflow-gates.mjs` and `.claude/hooks/state-block-guard.mjs` are written over
|
|
104
|
+
by the next upgrade with no question and no copy kept. A declaration seeded once from a template and never
|
|
104
105
|
replaced by the upgrade's ensures (a migration rewrites one only on the user's explicit yes) is the
|
|
105
|
-
user's own file. A customization goes into one of
|
|
106
|
+
user's own file. A customization goes into one of seven channels instead:
|
|
106
107
|
|
|
107
108
|
- **Your own commit checks** go in the local hook file `scripts/pre-commit.local`: the managed
|
|
108
109
|
pre-commit hook runs it first, once the installer has run.
|
|
@@ -112,6 +113,7 @@ user's own file. A customization goes into one of six channels instead:
|
|
|
112
113
|
- **An agent's model** goes in the vehicle settings `docs/ai/vehicles.json`.
|
|
113
114
|
- **A vehicle of your own** goes in `.claude/agents/<name>.local.md` with a `name:` of its own, which
|
|
114
115
|
no review roster names; a lens of your own in a review slot keeps a stem of its own.
|
|
116
|
+
- **A hook of your own** goes in `.claude/hooks/<name>.local.mjs`, which you wire.
|
|
115
117
|
|
|
116
118
|
No path segment of a file the kit bundles and places as its own has a dot-separated part exactly
|
|
117
119
|
`local`; a path of that form is the user's, and no kit tool writes one on its own. Outside that rule:
|
|
@@ -40,7 +40,7 @@ Declared gates can also be **auto-approved** (no permission prompt on a byte-exa
|
|
|
40
40
|
|
|
41
41
|
**A declared checker is read in THREE outcomes, not two.** `gates-inert.producer-unrecognized` — no producer anywhere in the declaration, over a tracked tree the changed-line domain cannot reach: the remedies are the marker above or dropping the checker, never a `node --test` prescription and never an acknowledgement (a dead pair is broken, not narrow). `gates-inert.coverage-domain-narrow` — the pair IS live and the tree is still dominated by what the domain excludes: certification covers the assessable minority, a FACT that converges on a `coverage-domain` acknowledgement. The census is the TRACKED tree (`git ls-files`) in this same closed vocabulary; dominance is STRICT (a tie, or a lone `.d.ts` beside real JS, never fires), and a tree it cannot read is a stated skip — no census, no optimality claim. A producer declared AFTER the checker is neither outcome: it keeps the ORDERING remedy above. Each outcome's convergence and posture note live in `${CLAUDE_SKILL_DIR}/references/modes/recommendations.md`.
|
|
42
42
|
|
|
43
|
-
**A marker-carrying declaration needs a CURRENT placed hook.** The gate-approval hook restates this schema in its own baked copy and goes dark on any key it does not know (`${CLAUDE_SKILL_DIR}/references/modes/hook.md`), so a declaration carrying the key under a hook that predates it silently switches auto-approval off — every gate prompting again, no error anywhere. The condition is the key's PRESENCE: an older hook rejects a key it does not know whatever the value, so `"lcovProducer": false` darkens it exactly as `true` does. The recovery is the
|
|
43
|
+
**A marker-carrying declaration needs a CURRENT placed hook.** The gate-approval hook restates this schema in its own baked copy and goes dark on any key it does not know (`${CLAUDE_SKILL_DIR}/references/modes/hook.md`), so a declaration carrying the key under a hook that predates it silently switches auto-approval off — every gate prompting again, no error anywhere. The condition is the key's PRESENCE: an older hook rejects a key it does not know whatever the value, so `"lcovProducer": false` darkens it exactly as `true` does. The recovery is the advisor's `gate-hook.not-current` item: within the wired hook it writes the placed hook with the kit's body in place, and the agent applies it with no question after the danger check.
|
|
44
44
|
|
|
45
45
|
**`coverage=` states what the run can honestly say about coverage.** A CLOSED four-value set, always present, DETAIL only — exit code, `status=`, the receipt status, `--final` acceptance and the commit-guard disposition are untouched. `coverage=certified` — the checker consumed an lcov and ISSUED a verdict, pass **or** fail (one listing uncovered lines still reads certified and still exits 1). `coverage=not-run` — the checker ran and issued NO verdict (no lcov bytes were read, or the run holds no attestation context). `coverage=none` — no canonical checker ran here (an `--only` subset, the `--pre-review` subset). `coverage=unknown` — the run ended before the gates produced a signal (missing / empty / malformed declaration, no bash, a pre-spend refusal), or that signal is unreadable: the checker could not spawn, or its two anchored lines are missing, duplicated, or CONTRADICTORY (`attested=yes` over `lcov-sha256=none` certifies nothing) — fail closed. The value is DERIVED by cross-reading both anchored machine lines, the bytes the `--final` receipt binds, so it can never disagree with what the checker printed; the checker's table row names a withheld verdict in the same words, and a `--final` receipt RECORDS the token (`none` never rides one — a final run always selects the checker).
|
|
46
46
|
|
package/references/modes/hook.md
CHANGED
|
@@ -22,23 +22,23 @@ The opt-in **gate-approval PreToolUse hook** — the family's third `.claude/` w
|
|
|
22
22
|
|
|
23
23
|
**Trust posture (state it plainly when asking consent):** the hook removes the PROMPT only for commands the human already declared in `docs/ai/gates.json` — the same trust boundary as the `gates` runner, which executes them with the caller's privileges. **gates.json thereby becomes a privileged file**: whoever can edit it can get its commands auto-approved. An invalid declaration approves NOTHING (strict parse, exact validation parity with the runner).
|
|
24
24
|
|
|
25
|
-
**The read-lane (opt-in, AD-055 Part II).** The toggle lives in `docs/ai/lanes.json` — a **SEPARATE kit-owned strict-JSON file** (`{ "readLane": true }`); `docs/ai/gates.json`, both its validators and the byte-mirrored template are **untouched** (the gates schema has no lane/model/routing fields — that claim stays true). The hook reads `lanes.json` LIVE per call, **fail-closed**: an absent / malformed / non-object file, or a `readLane` that is not the boolean `true`, leaves the lane dark (gate auto-approval and the residual ask are unaffected). `lanes.json` becomes a **privileged file** exactly like `gates.json` — an auto-approved read chain runs **unattended** and can read any file you can (the same trust boundary as the audited read-only core velocity seeds, extended to compounds (and singles) of that core; **prompt-bypass only, never a sandbox bypass**). Enable it with `--read-lane` (below), which runs a **currency check** first: it refuses unless the PLACED hook is byte-identical to the current bundle — a **pre-1.48 hook never reads `lanes.json`**, so enabling the lane against a stale placed copy would be a silent no-op the user paid consent for. The stale-hook silent-blackout class is dead **by construction** (an old hook merely lacks the rung; nothing existing changes behavior); the currency refusal names
|
|
25
|
+
**The read-lane (opt-in, AD-055 Part II).** The toggle lives in `docs/ai/lanes.json` — a **SEPARATE kit-owned strict-JSON file** (`{ "readLane": true }`); `docs/ai/gates.json`, both its validators and the byte-mirrored template are **untouched** (the gates schema has no lane/model/routing fields — that claim stays true). The hook reads `lanes.json` LIVE per call, **fail-closed**: an absent / malformed / non-object file, or a `readLane` that is not the boolean `true`, leaves the lane dark (gate auto-approval and the residual ask are unaffected). `lanes.json` becomes a **privileged file** exactly like `gates.json` — an auto-approved read chain runs **unattended** and can read any file you can (the same trust boundary as the audited read-only core velocity seeds, extended to compounds (and singles) of that core; **prompt-bypass only, never a sandbox bypass**). Enable it with `--read-lane` (below), which runs a **currency check** first: it refuses unless the PLACED hook is byte-identical to the current bundle — a **pre-1.48 hook never reads `lanes.json`**, so enabling the lane against a stale placed copy would be a silent no-op the user paid consent for. The stale-hook silent-blackout class is dead **by construction** (an old hook merely lacks the rung; nothing existing changes behavior); the currency refusal names `gate-hook --apply --cwd <root>`, which writes the placed hook with the kit's body in place.
|
|
26
26
|
|
|
27
27
|
**Version-status routing** like the other writer modes (stamp head `4.0.0`; `--apply` enforces it in code).
|
|
28
28
|
|
|
29
29
|
Run `node ${CLAUDE_SKILL_DIR}/tools/gate-hook.mjs [--dry-run | --apply] [--cwd <dir>]`:
|
|
30
30
|
|
|
31
|
-
1. **`--dry-run` first, always** (the default — changes nothing): previews the placement and the exact settings entry it would merge. It STOPs (zero writes) on: a symlinked `.claude` / `.claude/hooks` / target file / non-regular `settings.json`; malformed settings JSON; a **malformed existing `hooks` shape** (never a merge-through-clobber); an unsafe `permissions.defaultMode` in **either** settings file
|
|
31
|
+
1. **`--dry-run` first, always** (the default — changes nothing): previews the placement and the exact settings entry it would merge. It STOPs (zero writes) on: a symlinked `.claude` / `.claude/hooks` / target file / non-regular `settings.json`; malformed settings JSON; a **malformed existing `hooks` shape** (never a merge-through-clobber); or an unsafe `permissions.defaultMode` in **either** settings file.
|
|
32
32
|
2. **Ask consent** via **`AskUserQuestion` where supported**, the no-change option first: keep prompting for gate commands, or place + wire the hook — presenting the trust posture above in plain language.
|
|
33
|
-
3. **Only on an explicit yes**, re-run with `--apply`. It places the file FIRST, then wires settings (a wired-but-missing entry would error on every Bash call); merge-don't-clobber (foreign hooks/matchers/keys and existing permissions preserved; re-apply never duplicates); **settings hot-reload — the hook is active for new Bash calls, no session restart needed**. An identical existing file is *already current*; a
|
|
33
|
+
3. **Only on an explicit yes**, re-run with `--apply`. It places the file FIRST, then wires settings (a wired-but-missing entry would error on every Bash call); merge-don't-clobber (foreign hooks/matchers/keys and existing permissions preserved; re-apply never duplicates); **settings hot-reload — the hook is active for new Bash calls, no session restart needed**. An identical existing file is *already current*; a differing one is written with the kit's body in place; the entry is wired only while it is wired in neither settings file.
|
|
34
34
|
|
|
35
|
-
**The
|
|
35
|
+
**The hook file is the kit's.** Within a wired hook, `.claude/hooks/agent-workflow-gates.mjs` is placed when absent and written with the kit's body when it differs, in place, with no question and no copy kept; a current one is left; a link or another non-regular node there is named and nothing is written, and where Node exposes no no-follow open flag (native Windows) a replace stops instead of risking a write through a link. The advisor renders that state as `gate-hook.not-current`, lane kit: the agent applies it with no question after the danger check, and over a wired hook `gate-hook --apply` writes only the file. A hook of your own goes in `.claude/hooks/<name>.local.mjs`, which you wire; no kit tool writes it.
|
|
36
36
|
4. **Hidden-mode deployments:** after apply, run the hide-footprint reconcile (`node ${CLAUDE_SKILL_DIR}/tools/hide-footprint.mjs --dir <project> --reconcile`) — `/.claude/hooks/` is in the known-footprint registry; the apply report reminds you.
|
|
37
37
|
|
|
38
|
-
**Enabling the read-lane:** `node ${CLAUDE_SKILL_DIR}/tools/gate-hook.mjs --read-lane [--dry-run | --apply] [--cwd <dir>]`. `--dry-run` (the default) previews the `lanes.json` edit, the hook-currency status, and the trust posture; `--apply --read-lane` runs the **currency check** (above), then writes `{ "readLane": true }` into `docs/ai/lanes.json` — create-if-absent, merge-preserve every key, symlink / non-regular refusal, malformed-JSON fail-closed, atomic. It **never touches** `.claude/settings.json` or `docs/ai/gates.json`. The upgrade Recommendations advisor surfaces this as the `read-lane` offer once the hook is
|
|
38
|
+
**Enabling the read-lane:** `node ${CLAUDE_SKILL_DIR}/tools/gate-hook.mjs --read-lane [--dry-run | --apply] [--cwd <dir>]`. `--dry-run` (the default) previews the `lanes.json` edit, the hook-currency status, and the trust posture; `--apply --read-lane` runs the **currency check** (above), then writes `{ "readLane": true }` into `docs/ai/lanes.json` — create-if-absent, merge-preserve every key, symlink / non-regular refusal, malformed-JSON fail-closed, atomic. It **never touches** `.claude/settings.json` or `docs/ai/gates.json`. The upgrade Recommendations advisor surfaces this as the `read-lane` offer once the hook is wired.
|
|
39
39
|
|
|
40
|
-
**Invariants:** the base flow writes ONLY `.claude/hooks/agent-workflow-gates.mjs` + `.claude/settings.json`; `--read-lane` writes ONLY `docs/ai/lanes.json` (never settings, never `gates.json`) · never `settings.local.json` · never commits · exact-match approval only (no patterns) · never `deny` · never auto-wired by `init`/`upgrade` (
|
|
40
|
+
**Invariants:** the base flow writes ONLY `.claude/hooks/agent-workflow-gates.mjs` + `.claude/settings.json`; `--read-lane` writes ONLY `docs/ai/lanes.json` (never settings, never `gates.json`) · never `settings.local.json` · never commits · exact-match approval only (no patterns) · never `deny` · never auto-wired by `init`/`upgrade` (wiring stays opt-in — the AD-011/AD-034 boundary: the upgrade with no question, and init on its one y, place or refresh the hook file of a hook the user wired, and a hook is wired only on the user's yes to its offer).
|
|
41
41
|
|
|
42
|
-
**Exit codes:** `0` done / dry-run
|
|
42
|
+
**Exit codes:** `0` done / dry-run; `1` a precondition STOP; `2` bad arguments.
|
|
43
43
|
|
|
44
44
|
**The kit's other hook.** `state-block-guard` (see `${CLAUDE_SKILL_DIR}/references/modes/state-block-guard.md`) is a separate, unrelated `Stop` hook that judges the closing state block of a turn. Its writer is `tools/state-block-hook.mjs` (the advisor's `state-block` item), it never approves or denies anything, and this mode neither places nor wires it — the two hooks share only the `.claude/` directory they live in and the hardened placement discipline the state-block writer imports from `gate-hook.mjs`.
|
|
@@ -32,13 +32,13 @@ A variant's posture note, where its key has one, is printed by `init` from this
|
|
|
32
32
|
|
|
33
33
|
- `bridge-tier` — the lane is harness and env-dependent: the agent applies the item on the chat yes after the check, writing the project `.claude/settings.json`; `init` previews `velocity-profile --bridge-tier` and applies it on the terminal y as the route the user may take instead. It wires the USED bridges from the project's effective recipes and host readiness: each used review wrapper's `code`-mode allow rule (a wrapper then runs UNATTENDED: it reads any repo file it is pointed at and sends the assembled payload to its subscription backend), the quoted grounding pre-step rule when `agy-review` is used, `codex-review *` / `agy-review *` in `sandbox.excludedCommands`, and `codex-exec *` where an execute slot delegates (no execution allow rule: it keeps its prompt). It also seeds the used bridges' declared hosts (`networkHosts`) in `sandbox.network.allowedDomains` and resolved state dirs (`writableDirs`), home-relative where under home, in `sandbox.filesystem.allowWrite`. Where the host honours the settings sandbox keys, an excluded wrapper runs outside the sandbox, every sandboxed command of the project can reach the seeded hosts, and every sandboxed command can write the seeded state dirs. The item fires while an allow rule, a `*` exclusion, a host or a state dir of a used bridge is missing. Its `recipe:` line names each missing entry by kind (allow rules, exclusions, hosts, state dirs), then what the execution wrapper `codex-exec` needs where an execute slot delegates, then, when the project settings enable the sandbox, "once added, wired where the host honors the settings sandbox keys", or "host condition unchecked" with the reason.
|
|
34
34
|
|
|
35
|
-
- `read-lane` — enabling the opt-in read-only compound lane auto-approves *compounds* (and singles) of the seeded read-only core that carry ZERO shell metaprogramming: an UNATTENDED trust extension, bounded by the audited read-only core (never a command outside it; prompt-bypass only, never a sandbox bypass) and applied regardless of which of those core commands you seeded as individual settings rules. It is a PROJECT-PERSISTENT declaration in `docs/ai/lanes.json` — every future session, subagents' Bash too where the host fires hooks on subagent Bash, and (committed) every checkout. The
|
|
35
|
+
- `read-lane` — enabling the opt-in read-only compound lane auto-approves *compounds* (and singles) of the seeded read-only core that carry ZERO shell metaprogramming: an UNATTENDED trust extension, bounded by the audited read-only core (never a command outside it; prompt-bypass only, never a sandbox bypass) and applied regardless of which of those core commands you seeded as individual settings rules. It is a PROJECT-PERSISTENT declaration in `docs/ai/lanes.json` — every future session, subagents' Bash too where the host fires hooks on subagent Bash, and (committed) every checkout. The item renders while the hook is wired and the lane is off, whatever the placed hook's bytes; its apply is the `gate-hook --read-lane` preview, whose own currency check refuses a stale hook (a pre-1.48 hook never reads `lanes.json`). A stale or absent hook under it is a planned file of the kit item `gate-hook.not-current`, applied before the offers. The agent applies the enable offer on the chat yes, and the kit item with no question after the check; `init` applies that kit item on its one y as the route the user may take instead. Risk profile: a bounded read-only trust-posture extension — no write/exec exposure beyond the audited core.
|
|
36
36
|
- `worktrees-dir` — the agent applies the item on the chat yes after the check: one `sandbox.filesystem.allowWrite` entry naming the worktrees parent itself, written to this copy's `.claude/settings.local.json` only, never the committed project settings, the parent created when missing. `init` applies it on the batch terminal yes as the route the user may take instead. Where the host honors the key, the entry widens the OS-sandbox WRITE surface to the whole parent dir: every sibling path under it (other repositories included) becomes agent-writable, for every later session and every worktree provisioned afterwards. Narrow it BEFORE the first apply: point `docs/ai/worktrees.json` `parentDir` at a dedicated dir — no apply removes an entry, so an earlier one stays until the user deletes it. A parent that is the home or holds it renders `worktrees-dir.home` instead, the user's own step. **Convergence** is two-path: a declared `sandbox.filesystem.allowWrite` entry covering the probed dir (either settings scope — `~` and `~/…` resolve against home, and coverage is path-segment-aware, so a grant on a sibling or on a child never counts), or the dir-bound acknowledgement `worktreesDirAck` in the family-owned `docs/ai/acks.json`, recorded by the `ack-write --lane worktrees-dir` line the `recipe:` line carries — the ack fallback for a host that ignores the key, run only on the user's word, instead of the grant; against a trusted host NO no ack renders. Neither is proof of write CAPABILITY: the provision preflight's real create+delete probe stays the runtime truth, and the ack is bound to the **resolved probe dir**, so the item re-fires only when that resolved dir changes. Risk profile: a real write-surface widening where honored — scope it deliberately.
|
|
37
37
|
|
|
38
38
|
- `gates-inert` — the gate matrix is DECLARED but verifies nothing, and the two causes have different remedies, so the item renders a different apply for each. **Cause A** — a canonical `coverage-check` gate with no producer gate declared BEFORE it (none at all, or one declared after it, which writes the lcov too late): the run certifies no coverage of its own — `coverage=not-run` when nothing wrote an lcov, or a verdict over STALE bytes an earlier run left in the git dir, which is worse because it reads as `coverage=certified`. The remedy needs the producer to run BEFORE the checker — declared or MOVED there. When the checker is the LAST declared gate and the project's own scripts yield an offerable producer, the fill PLACES that producer before it, so the apply is the ordinary `gates-init` dry-run preview. Otherwise — no offerable producer, or a checker that is not last — it is the user item `gates-inert.unfillable`: the user's own step is to edit `docs/ai/gates.json` (the exact producer form lives in `${CLAUDE_SKILL_DIR}/references/modes/gates.md`), because the fill never reorders entries it did not write. **Cause B** — every declared gate is one of the kit's own canonical checkers, so the matrix runs no project-verification command at all: the apply is the `gates-init` dry-run preview, the same consent-gated seeder the `gates-declaration` item renders, and after the SAME confirmation you run the `--apply` line it prints. Neither cause changes any gate result, exit code or receipt — the item adds no enforcement, only the offer. Risk profile: `docs/ai/gates.json` is a PRIVILEGED file (a declared gate is auto-approvable by the wired hook), so both causes land in the same place — where the fill can help, it declares a project-controlled command on your explicit yes; where it cannot, the edit is the user's own step.
|
|
39
39
|
|
|
40
40
|
- `source-size` — the arms differ by what the declared gate IS. **`adopted-elsewhere`** — the gate runs a DIFFERENT real copy of this checker (a vendored deployment): the practice runs, the advisor cannot resolve it as its own sibling, and the realpath anchor does not widen (that stops a lookalike). So the convergence is the ack writer's preview (`--lane source-size-copy` → `sourceSizeCopyAck`), never `--adopt`, which would mint and then be refused by the fill on the declared id. The fingerprint binds the declared claims AS AUTHORED, sorted, not resolved paths, so a second external copy re-fires it. **`id-squatter`** — a gate carries the `source-size` id and is not this checker under any reading: it claims the practice while nothing measures module size, so it is the user's own step (rename the id, or repoint the cmd at this `--check`). **`unminted`**, for both copies: a gate refusing every run over an authored or incomplete record (over an absent one the check judges layout alone), attention, and NO acknowledgement silences it; only the verb differs (with the gate declared elsewhere, `--write-baseline`). **`schema-1`** — the check stops on a minted schema-1 config, so this arm comes first: its `--write-baseline` line carries NO reason (a pinned one would launder a raise; a raise riding the move refuses and you relay it), every run until the move. **`layout`** — on a config with no layout record, the record of the piles already there comes first, as its own item: a no writes nothing and the item returns every run; its `recipe:` line names the branch states, and `source-size.layout` is applied before the `hook-checks` check line runs, whose layout line follows that record. Risk profile: `docs/ai/gates.json` is a PRIVILEGED file, so every arm here either records an acknowledgement or hands you an edit — the kit declares nothing on its own.
|
|
41
|
-
- `gate-hook` — the
|
|
41
|
+
- `gate-hook` — the offer wires the hook on the harness lane: the agent applies it on the chat yes after the check; `init` previews and applies it on the terminal yes as the route the user may take instead. Over a wired hook the key renders the kit item `gate-hook.not-current` instead: the placed hook file is absent or differs from the body the kit writes for it. An older body validates your declaration through its OWN baked copy and goes dark on a key it does not know, such as `lcovProducer` (present, whatever its value), so every gate prompts again with no error anywhere. The agent applies the kit item with no question after the check, whose result names the file with its new digest, and the old one too over a differing file; it writes only the hook file. Risk profile: the offer places a hook file and wires one settings entry; the kit item writes one hook file with the kit's body; the declaration is never touched.
|
|
42
42
|
- `enforcement` — copies the bundled `references/scripts/*.mjs` runnable scripts and their tests, then runs the project's own hook installer, which installs the pre-commit hook. The lane is harness: the agent applies the item on the chat yes after the check, whose result shows each script the kit places with its bytes and the installer it runs with its bytes; `init` applies it on the batch terminal yes as the route the user may take instead. The copy is create-only: an existing file stands and nothing is written through a link, and the offer renders only when `scripts/` is absent or a plain directory contains no bundled basename. The hook invokes `node` directly, so a committer without it on PATH gets a loud failure. The installer refuses to overwrite a pre-commit hook it did not write: an install it refuses removes the scripts this apply copied, and the item is offered again with the installer's output shown; over a pre-commit hook the installer did not write the item is not offered — its skip names the user's own step. Risk profile: local tooling and a Git hook are added on the chat yes after the check, or on init's y.
|
|
43
43
|
- `hook-checks` — the agent applies the item on the chat yes after the check; `init` applies it on the terminal y as the route the user may take instead. Risk profile: future commits stop on the rules check and, where judged, on the size check's findings — lines, aggregate and layout; over a clone with no pre-commit hook the installer writes its whole hook, so commits also stop on its docs, archive and `scripts/` test lines.
|
|
44
44
|
- `attribution` — the agent applies the item on the chat yes after the check, setting one key in the project `.claude/settings.json`; `init` applies it on the terminal y as the route the user may take instead. An existing "includeCoAuthoredBy": false already converges the item unless an "attribution" key sets a commit or PR text; a local-scope override is the user's own edit. Risk profile: one settings key, nothing widened.
|
|
@@ -100,6 +100,10 @@ stamp refusals use that writer's error codes:
|
|
|
100
100
|
present and not an array is a refusal with nothing written;
|
|
101
101
|
- the entry is merged only while no `Stop` entry of either settings file runs the runtime, so a
|
|
102
102
|
wiring you made yourself (another path, `--require-block`) counts and is never duplicated;
|
|
103
|
+
- within a wired hook the advisor renders a runtime that is absent or differs as
|
|
104
|
+
`state-block.not-current`, lane kit: the agent applies it with no question after the danger check,
|
|
105
|
+
and the writer then writes only the file. A hook of your own goes in `.claude/hooks/<name>.local.mjs`,
|
|
106
|
+
which you wire;
|
|
103
107
|
- a symlinked `.claude`, `.claude/hooks`, target or settings file, malformed settings and an unsafe
|
|
104
108
|
permission mode each refuse with nothing written; a deployment stamp behind the kit refuses
|
|
105
109
|
`--apply` (the preview still answers and notes it); the runtime is written through gate-hook's
|
|
@@ -9,14 +9,14 @@ import {
|
|
|
9
9
|
APPLY_ASK_RULE, CLAUDE_DIR, RENDER_OWNED_REDLINE_RULES,
|
|
10
10
|
SAFE_DEFAULT_MODES, SETTINGS_FILE, SETTINGS_LOCAL_FILE, UNIVERSAL_READONLY_ALLOWLIST,
|
|
11
11
|
deriveKitToolsAllowlist, detectAtRoot, mergeAutonomySettings,
|
|
12
|
-
writeAutonomyProfile, writeVelocityProfile,
|
|
12
|
+
readSettingsFile, writeAutonomyProfile, writeVelocityProfile,
|
|
13
13
|
} from './velocity-profile.mjs';
|
|
14
14
|
import { KIT_GROUNDING_TOOL, bundledSandboxRecipe, usedBridges } from './bridge-sandbox-recipe.mjs';
|
|
15
15
|
import { homeRelative, mergeAllowWrite, stateDirsOf } from './bridge-state-dirs.mjs';
|
|
16
16
|
import { nearestExistingDir, worktreesGrantDir, worktreesGrantHoldsHome } from './worktrees.mjs';
|
|
17
17
|
import { loadConfig } from './orchestration-config.mjs';
|
|
18
|
-
import { HOOK_FILE_REL, HOOKS_DIR, buildHookSettingsEntry, mergeHookEntry, writeGateHook } from './gate-hook.mjs';
|
|
19
|
-
import { STATE_BLOCK_HOOK_FILE_REL, buildStopHookEntry, mergeStopEntry, writeStateBlockHook } from './state-block-hook.mjs';
|
|
18
|
+
import { HOOK_FILE_REL, HOOKS_DIR, buildHookSettingsEntry, isHookWired, mergeHookEntry, writeGateHook } from './gate-hook.mjs';
|
|
19
|
+
import { STATE_BLOCK_HOOK_FILE_REL, buildStopHookEntry, isStopHookWired, mergeStopEntry, writeStateBlockHook } from './state-block-hook.mjs';
|
|
20
20
|
import { writeMcp } from './mcp.mjs';
|
|
21
21
|
import { ENABLED_KEY, MCP_JSON_REL, SERVERS_KEY, SERVER_NAME, allowRulesFor, buildServerEntry } from './mcp-registration.mjs';
|
|
22
22
|
import { AGENTS_DIR, agentsAccepted, kitAgentNames, writeCheapAgents } from './cheap-agents.mjs';
|
|
@@ -33,9 +33,8 @@ import { dirCovers as covers } from './declared-paths.mjs';
|
|
|
33
33
|
const TOOLS = dirname(fileURLToPath(import.meta.url));
|
|
34
34
|
const SKILL_VARIANTS = ['jev-skill', 'jev-skill.earlier'];
|
|
35
35
|
const VELOCITY_VARIANTS = ['velocity-core', 'kit-tools-tier', 'bridge-tier'];
|
|
36
|
-
const
|
|
37
|
-
const HOOK_VARIANTS = ['gate-hook',
|
|
38
|
-
const STOP = 'state-block';
|
|
36
|
+
const [GATE_KIT, STOP, STOP_KIT] = ['gate-hook.not-current', 'state-block', 'state-block.not-current'];
|
|
37
|
+
const [HOOK_VARIANTS, STOP_VARIANTS, KIT_HOOKS] = [['gate-hook', GATE_KIT], [STOP, STOP_KIT], [GATE_KIT, STOP_KIT]];
|
|
39
38
|
const MCP_VARIANTS = ['mcp-channel', 'mcp-channel.differing'];
|
|
40
39
|
const AGENTS_KIT = 'agents.not-current';
|
|
41
40
|
const AGENT_VARIANTS = ['agents', 'executor-vehicle', AGENTS_KIT];
|
|
@@ -43,7 +42,7 @@ const GIT_VARIANTS = ['enforcement', 'commit-guard', 'hook-checks'];
|
|
|
43
42
|
const WORKTREES = 'worktrees-dir';
|
|
44
43
|
const ATTRIBUTION = 'attribution';
|
|
45
44
|
const FOOTPRINT = 'footprint-global';
|
|
46
|
-
const VARIANTS = [...VELOCITY_VARIANTS, 'autonomy-render', ...HOOK_VARIANTS,
|
|
45
|
+
const VARIANTS = [...VELOCITY_VARIANTS, 'autonomy-render', ...HOOK_VARIANTS, ...STOP_VARIANTS, ...MCP_VARIANTS, ...AGENT_VARIANTS, ...SKILL_VARIANTS, ...GIT_VARIANTS, WORKTREES, ATTRIBUTION, FOOTPRINT];
|
|
47
46
|
const HOOK_KEYS = ['hooks.PreToolUse', 'hooks.Stop'];
|
|
48
47
|
const CREDENTIALS = 'sandbox.credentials.envVars';
|
|
49
48
|
const object = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
@@ -163,6 +162,15 @@ const writerFacts = (facts, deps) => ({
|
|
|
163
162
|
findWrapper: (name) => findOnPath(name, { getenv: facts.env }).state === 'present',
|
|
164
163
|
findOnPath: (name) => findOnPath(name, { getenv: facts.env }),
|
|
165
164
|
});
|
|
165
|
+
// A kit hook variant writes neither settings file, so a device there (a sandbox mask over an absent file) reads
|
|
166
|
+
// as absent; its acceptance is judged by the check from the two settings files with the writer's own predicate.
|
|
167
|
+
const SETTINGS_FILES = [SETTINGS_FILE, SETTINGS_LOCAL_FILE];
|
|
168
|
+
const unmaskedLstat = (facts) => (path, ...args) => {
|
|
169
|
+
const stat = lstatSync(path, ...args);
|
|
170
|
+
if (stat?.isCharacterDevice() && SETTINGS_FILES.some((rel) => path === join(facts.root, rel))) throw Object.assign(new Error(`ENOENT: ${path}`), { code: 'ENOENT' });
|
|
171
|
+
return stat;
|
|
172
|
+
};
|
|
173
|
+
const kitHookWired = (variant, facts) => SETTINGS_FILES.some((rel) => (variant === GATE_KIT ? isHookWired : isStopHookWired)(readSettingsFile(join(facts.root, rel), { lstat: unmaskedLstat(facts), cwd: facts.root }).data));
|
|
166
174
|
|
|
167
175
|
export const scopeOf = (variant, facts, deps = {}) => {
|
|
168
176
|
const allowed = {};
|
|
@@ -195,7 +203,7 @@ export const scopeOf = (variant, facts, deps = {}) => {
|
|
|
195
203
|
if (grantDir !== null && !worktreesGrantHoldsHome(grantDir, facts.home, facts)) {
|
|
196
204
|
set('sandbox.filesystem.allowWrite', [homeRelative(grantDir, facts.home)]);
|
|
197
205
|
}
|
|
198
|
-
if (
|
|
206
|
+
if (variant === 'gate-hook') set('hooks.PreToolUse', [buildHookSettingsEntry()]);
|
|
199
207
|
else if (variant === STOP) set('hooks.Stop', [buildStopHookEntry()]);
|
|
200
208
|
else if (MCP_VARIANTS.includes(variant)) {
|
|
201
209
|
set(`${SERVERS_KEY}.${SERVER_NAME}`, [buildServerEntry(join(facts.toolsDir, 'mcp-server.mjs'))]);
|
|
@@ -204,12 +212,12 @@ export const scopeOf = (variant, facts, deps = {}) => {
|
|
|
204
212
|
}
|
|
205
213
|
const targets = SKILL_VARIANTS.includes(variant) ? skillTargets({ home: facts.home,
|
|
206
214
|
claudeDir: facts.claudeDir ?? claudeDirOf(facts.env, facts.home, facts.platform).dir }) : [];
|
|
207
|
-
const
|
|
208
|
-
|
|
209
|
-
const directories = SKILL_VARIANTS.includes(variant) || variant === FOOTPRINT ? [] : [join(facts.root, CLAUDE_DIR)];
|
|
215
|
+
const accepted = !KIT_HOOKS.includes(variant) || kitHookWired(variant, facts);
|
|
216
|
+
const filePaths = !accepted ? [] : HOOK_VARIANTS.includes(variant) ? [join(facts.root, HOOK_FILE_REL)] : STOP_VARIANTS.includes(variant) ? [join(facts.root, STATE_BLOCK_HOOK_FILE_REL)] : [];
|
|
217
|
+
const directories = !accepted || SKILL_VARIANTS.includes(variant) || variant === FOOTPRINT ? [] : [join(facts.root, CLAUDE_DIR)];
|
|
210
218
|
const globalFile = variant === FOOTPRINT ? footprintPlan(facts, deps)?.source : undefined;
|
|
211
219
|
if (globalFile) filePaths.push(globalFile);
|
|
212
|
-
if (HOOK_VARIANTS.includes(variant) || variant
|
|
220
|
+
if (accepted && (HOOK_VARIANTS.includes(variant) || STOP_VARIANTS.includes(variant))) directories.push(join(facts.root, HOOKS_DIR));
|
|
213
221
|
if (AGENT_VARIANTS.includes(variant)) directories.push(join(facts.root, AGENTS_DIR));
|
|
214
222
|
const kitNames = variant === AGENTS_KIT ? kitAgentNames(facts.root) : [];
|
|
215
223
|
if (kitNames.length && agentsAccepted(facts.root, kitNames)) filePaths.push(...kitNames.map((name) => join(facts.root, AGENTS_DIR, name)));
|
|
@@ -248,7 +256,7 @@ const jsonAt = (path) => existsSync(path) ? JSON.parse(readFileSync(path, 'utf8'
|
|
|
248
256
|
const regularBytes = (path) => lstatSync(path, { throwIfNoEntry: false })?.isFile() ? readFileSync(path) : undefined;
|
|
249
257
|
const halted = (lines) => Object.assign(new Error(lines.join('\n')), { code: 'CHECK_HALTED', lines });
|
|
250
258
|
const maskedFiles = (variant, facts) => {
|
|
251
|
-
const paths = VELOCITY_VARIANTS.includes(variant) || variant === 'autonomy-render' ||
|
|
259
|
+
const paths = VELOCITY_VARIANTS.includes(variant) || variant === 'autonomy-render' || variant === 'gate-hook'
|
|
252
260
|
|| variant === STOP || variant === WORKTREES || variant === ATTRIBUTION ? [SETTINGS_FILE, SETTINGS_LOCAL_FILE] : MCP_VARIANTS.includes(variant) ? [MCP_JSON_REL, SETTINGS_FILE] : [];
|
|
253
261
|
return paths.flatMap((path) => lstatSync(join(facts.root, path), { throwIfNoEntry: false })?.isCharacterDevice()
|
|
254
262
|
? [`masked: ${path}`] : []);
|
|
@@ -259,7 +267,7 @@ export const plannedChange = (variant, facts, deps = {}) => {
|
|
|
259
267
|
const temporaries = [];
|
|
260
268
|
const created = [];
|
|
261
269
|
let runs = null;
|
|
262
|
-
const writerDeps = writerFacts(facts, deps);
|
|
270
|
+
const writerDeps = { ...writerFacts(facts, deps), ...(KIT_HOOKS.includes(variant) ? { lstat: unmaskedLstat(facts) } : {}) };
|
|
263
271
|
const addFile = (path, before, after) => {
|
|
264
272
|
files.push({ path, before: before ?? null, after });
|
|
265
273
|
};
|
|
@@ -287,16 +295,13 @@ export const plannedChange = (variant, facts, deps = {}) => {
|
|
|
287
295
|
const before = jsonAt(join(facts.root, SETTINGS_FILE));
|
|
288
296
|
addFile(SETTINGS_FILE, before, mergeAutonomySettings(before, render));
|
|
289
297
|
} else if (HOOK_VARIANTS.includes(variant)) {
|
|
290
|
-
const plan = writeGateHook({ cwd: facts.root, dryRun: true
|
|
298
|
+
const plan = (deps.writeGateHook ?? writeGateHook)({ cwd: facts.root, dryRun: true }, writerDeps);
|
|
291
299
|
if (plan.wirePlanned) addFile(SETTINGS_FILE, plan.projectSettings.data, mergeHookEntry(plan.projectSettings.data));
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
} else if (variant === STOP) {
|
|
296
|
-
const plan = writeStateBlockHook({ cwd: facts.root, dryRun: true }, writerDeps);
|
|
300
|
+
if (plan.placePlanned || plan.replacePlanned) writes.push({ path: join(facts.root, HOOK_FILE_REL), bytes: plan.bundleContent });
|
|
301
|
+
} else if (STOP_VARIANTS.includes(variant)) {
|
|
302
|
+
const plan = (deps.writeStateBlockHook ?? writeStateBlockHook)({ cwd: facts.root, dryRun: true }, writerDeps);
|
|
297
303
|
if (plan.mergePlanned) addFile(SETTINGS_FILE, plan.projectSettings.data, mergeStopEntry(plan.projectSettings.data));
|
|
298
|
-
|
|
299
|
-
if (['create', 'replace'].includes(plan.placement)) writes.push({ path, bytes: plan.bundleContent });
|
|
304
|
+
if (['create', 'replace'].includes(plan.placement)) writes.push({ path: join(facts.root, STATE_BLOCK_HOOK_FILE_REL), bytes: plan.bundleContent });
|
|
300
305
|
} else if (MCP_VARIANTS.includes(variant)) {
|
|
301
306
|
const result = writeMcp({ cwd: facts.root, dryRun: true, replace: variant === 'mcp-channel.differing' }, writerDeps);
|
|
302
307
|
const { plan, registration } = result;
|
|
@@ -26,6 +26,7 @@ export const SCRIPT_CHANNEL = 'a script or suite of your own under its own name
|
|
|
26
26
|
export const LOCAL_HOOK_CHANNEL = 'the local hook file scripts/pre-commit.local, which the commit hook runs first';
|
|
27
27
|
export const VEHICLE_CHANNEL = VEHICLES_REL;
|
|
28
28
|
export const AGENT_CHANNEL = '.claude/agents/<name>.local.md with a name: of its own';
|
|
29
|
+
export const HOOK_CHANNEL = '.claude/hooks/<name>.local.mjs';
|
|
29
30
|
// The family files memory copies on Node evidence alone, accepted or not (the suite derives them).
|
|
30
31
|
export const SEED_NAMES = Object.freeze(['_expect-shim.mjs', 'archive-decisions.mjs', 'archive-decisions.test.mjs', 'markdown-blocks.mjs']);
|
|
31
32
|
const ROTATOR = 'archive-decisions.mjs';
|
|
@@ -81,10 +82,11 @@ const survey = ({ cwd, kitRoot, deps, read, lstat }) => {
|
|
|
81
82
|
// A fate is `written`, `stood` (an absent file that appeared with the bundled body), `refused` (its
|
|
82
83
|
// write failed), or none: the run stopped before it, or, dry, would write it. The spec layer's pair
|
|
83
84
|
// lines are these too, through the module's index.
|
|
84
|
-
const VERBS = { prior: ['refreshed', 'refreshed to the bundled one'], custom: ['replaced', 'replaced by the bundled body'], absent: ['placed', 'placed from the bundled scripts'], derived: ['written', 'written with that body'], agent: ['written', 'written with that body'] };
|
|
85
|
-
const HEADS = { prior: 'matches a body an earlier release shipped', custom: 'differs from every body this kit knows it shipped', absent: 'absent', derived: 'differs from the body derived from the vehicle settings', agent: 'differs from the body the kit writes for it' };
|
|
85
|
+
const VERBS = { prior: ['refreshed', 'refreshed to the bundled one'], custom: ['replaced', 'replaced by the bundled body'], absent: ['placed', 'placed from the bundled scripts'], derived: ['written', 'written with that body'], agent: ['written', 'written with that body'], hook: ['written', 'written with that body'] };
|
|
86
|
+
const HEADS = { prior: 'matches a body an earlier release shipped', custom: 'differs from every body this kit knows it shipped', absent: 'absent', derived: 'differs from the body derived from the vehicle settings', agent: 'differs from the body the kit writes for it', hook: 'differs from the body the kit writes for it' };
|
|
86
87
|
const channelOf = (f) => (f.state === 'derived' ? `; its model and effort are set in ${VEHICLE_CHANNEL}`
|
|
87
88
|
: f.state === 'agent' ? `; a vehicle of your own goes in ${AGENT_CHANNEL}`
|
|
89
|
+
: f.state === 'hook' ? `; a hook of your own goes in ${HOOK_CHANNEL}`
|
|
88
90
|
: f.state === 'custom' ? `; an edit meant to last goes in ${f.name === INSTALLER_SET[0] ? LOCAL_HOOK_CHANNEL : SCRIPT_CHANNEL}` : '');
|
|
89
91
|
export const fileLine = (f, fate, dryRun) => {
|
|
90
92
|
if (fate === 'stood') return `${f.rel}: appeared while this run was placing it — the bundled body stands, nothing written`;
|
package/tools/gate-hook.mjs
CHANGED
|
@@ -23,20 +23,17 @@
|
|
|
23
23
|
// is a STOP with ZERO writes, never a merge-through-clobber;
|
|
24
24
|
// • place-then-wire ORDER — the hook file is placed BEFORE settings are wired (a
|
|
25
25
|
// wired-but-missing hook would error on every Bash call);
|
|
26
|
-
// •
|
|
27
|
-
//
|
|
28
|
-
//
|
|
29
|
-
//
|
|
30
|
-
// diverged file is REPORTED, never unwired by `--apply`. A diverged hook is never clobbered
|
|
31
|
-
// except by `--apply --reseed`, the one consented replacement: it writes the bundled bytes in
|
|
32
|
-
// place over a placed hook and wires the entry only while it is wired in neither file;
|
|
26
|
+
// • the kit's hook file is written current: placed create-only when absent, a differing one
|
|
27
|
+
// written with the bundled body in place (no copy kept), an identical one `already current`;
|
|
28
|
+
// the entry is wired only while it is wired in neither settings file, so over a wired hook the
|
|
29
|
+
// apply writes only the file. Every printed recovery of a stale hook is `gate-hook --apply`;
|
|
33
30
|
// • never writes settings.local.json; never commits.
|
|
34
31
|
//
|
|
35
32
|
// The `--read-lane` flag is a SEPARATE operation (AD-055 Part II): it enables the opt-in read-only
|
|
36
33
|
// compound lane in docs/ai/lanes.json after a currency check, and never touches settings or
|
|
37
34
|
// gates.json — see the read-lane writer section below.
|
|
38
35
|
//
|
|
39
|
-
// Exit codes: 0 done / dry-run
|
|
36
|
+
// Exit codes: 0 done / dry-run; 1 precondition
|
|
40
37
|
// STOP; 2 usage. Dependency-free beyond the kit's own internal exports, Node >= 22. No side
|
|
41
38
|
// effects on import.
|
|
42
39
|
|
|
@@ -56,6 +53,7 @@ import {
|
|
|
56
53
|
} from './velocity-profile.mjs';
|
|
57
54
|
import { assertDocsAiDeployment, writeDocsAiFileAtomic } from './atomic-write.mjs';
|
|
58
55
|
import { isDirectRun } from './direct-run.mjs';
|
|
56
|
+
import { fileLine } from './distribution-files/index.mjs';
|
|
59
57
|
import { shellQuoteArg } from './review-state.mjs';
|
|
60
58
|
|
|
61
59
|
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
@@ -100,7 +98,6 @@ const TARGET_CURRENT = 'already-current';
|
|
|
100
98
|
const TARGET_DIVERGED = 'diverged';
|
|
101
99
|
|
|
102
100
|
const USAGE = `usage: gate-hook [--dry-run | --apply] [--cwd <dir>] [--help]
|
|
103
|
-
gate-hook --reseed [--dry-run | --apply] [--cwd <dir>] (replace a placed hook with the bundle)
|
|
104
101
|
gate-hook --read-lane [--dry-run | --apply] [--cwd <dir>] (enable the opt-in read-only compound lane)
|
|
105
102
|
|
|
106
103
|
Places the bundled PreToolUse gate-approval hook to ${HOOK_FILE_REL} and wires ONE
|
|
@@ -109,15 +106,14 @@ nothing). --apply writes. The hook auto-approves byte-exact declared gate cmds
|
|
|
109
106
|
(docs/ai/gates.json, project root) and asks on seeded-read-only commands carrying the
|
|
110
107
|
documented runtime residual.
|
|
111
108
|
|
|
112
|
-
--
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
an absent hook (--apply places it) and a symlinked or non-regular one.
|
|
109
|
+
--apply places an absent hook file, writes a differing one with the bundled body in place, leaves
|
|
110
|
+
a current one, and wires the entry only while it is wired in neither settings file. A symlinked or
|
|
111
|
+
non-regular hook file is refused.
|
|
116
112
|
|
|
117
113
|
--read-lane enables the opt-in read-only COMPOUND lane in ${LANES_REL} ("${READ_LANE_KEY}": true) — the
|
|
118
114
|
hook then auto-approves compounds of the seeded read-only core carrying zero shell metaprogramming.
|
|
119
115
|
--apply --read-lane verifies the PLACED hook is the CURRENT bundle first (a pre-1.48 hook never reads
|
|
120
|
-
${LANES_REL}) and refuses otherwise, naming the
|
|
116
|
+
${LANES_REL}) and refuses otherwise, naming the route that writes it (gate-hook --apply --cwd <dir>).
|
|
121
117
|
Never touches ${SETTINGS_FILE} or docs/ai/gates.json.
|
|
122
118
|
|
|
123
119
|
Never writes ${SETTINGS_LOCAL_FILE}; never commits.`;
|
|
@@ -268,7 +264,7 @@ export const mergeHookEntry = (base) => {
|
|
|
268
264
|
return { ...root, hooks: { ...hooks, [PRE_TOOL_USE_EVENT]: [...entries, buildHookSettingsEntry()] } };
|
|
269
265
|
};
|
|
270
266
|
|
|
271
|
-
export const preflightGateHook = ({ cwd
|
|
267
|
+
export const preflightGateHook = ({ cwd }, deps = {}) => {
|
|
272
268
|
const fs = fsDeps(deps);
|
|
273
269
|
const projectDir = resolve(cwd ?? deps.cwd ?? process.cwd());
|
|
274
270
|
const bundleContent = readBundledHook(deps);
|
|
@@ -277,12 +273,6 @@ export const preflightGateHook = ({ cwd, reseed = false }, deps = {}) => {
|
|
|
277
273
|
assertDirSafe(join(projectDir, CLAUDE_DIR), CLAUDE_DIR, fs);
|
|
278
274
|
assertDirSafe(join(projectDir, HOOKS_DIR), HOOKS_DIR, fs);
|
|
279
275
|
const target = planTarget(join(projectDir, HOOK_FILE_REL), HOOK_FILE_REL, bundleContent, fs);
|
|
280
|
-
if (reseed && target.action === TARGET_PLACE) {
|
|
281
|
-
throw makeGateHookError(
|
|
282
|
-
GATE_HOOK_STALE,
|
|
283
|
-
`${HOOK_FILE_REL} is not placed — --reseed replaces a placed hook; place it with: ${applyGateHookCommand(projectDir)}`,
|
|
284
|
-
);
|
|
285
|
-
}
|
|
286
276
|
assertSettingsWritable(join(projectDir, SETTINGS_FILE), fs);
|
|
287
277
|
const projectSettings = readSettingsFile(join(projectDir, SETTINGS_FILE), { ...deps, cwd: projectDir });
|
|
288
278
|
const localSettings = readSettingsFile(join(projectDir, SETTINGS_LOCAL_FILE), { ...deps, cwd: projectDir });
|
|
@@ -301,17 +291,6 @@ export const preflightGateHook = ({ cwd, reseed = false }, deps = {}) => {
|
|
|
301
291
|
|
|
302
292
|
const wiredInProject = isHookWired(projectSettings.data);
|
|
303
293
|
const wiredInLocal = isHookWired(localSettings.data);
|
|
304
|
-
// Diverged target + our entry NOT wired anywhere = STOP on BOTH dry-run and apply: applying
|
|
305
|
-
// would wire an unknown script as a PreToolUse hook — exactly what consent must not slide
|
|
306
|
-
// past. (Diverged + already wired is the user's own standing state: report-only, below.) Under
|
|
307
|
-
// --reseed this is exactly the state the reseed replaces before it wires.
|
|
308
|
-
if (!reseed && target.action === TARGET_DIVERGED && !wiredInProject && !wiredInLocal) {
|
|
309
|
-
throw makeGateHookError(
|
|
310
|
-
GATE_HOOK_DIVERGED,
|
|
311
|
-
`${HOOK_FILE_REL} exists with DIFFERENT content and is not wired — refusing to wire an unknown script as a PreToolUse hook; reseed it from the bundle: ${applyReseedCommand(projectDir)}`,
|
|
312
|
-
);
|
|
313
|
-
}
|
|
314
|
-
|
|
315
294
|
return { projectDir, bundleContent, stamp, stampOk, target, projectSettings, localSettings, wiredInProject, wiredInLocal };
|
|
316
295
|
};
|
|
317
296
|
|
|
@@ -320,13 +299,13 @@ export const preflightGateHook = ({ cwd, reseed = false }, deps = {}) => {
|
|
|
320
299
|
export const formatJson = (data, eol) =>
|
|
321
300
|
`${JSON.stringify(data, null, SETTINGS_JSON_INDENT).replace(JSON_NEWLINE_PATTERN, eol)}${eol}`;
|
|
322
301
|
|
|
323
|
-
export const writeGateHook = ({ cwd, dryRun = true
|
|
302
|
+
export const writeGateHook = ({ cwd, dryRun = true } = {}, deps = {}) => {
|
|
324
303
|
const fs = fsDeps(deps);
|
|
325
|
-
const preflight = preflightGateHook({ cwd: cwd ?? deps.cwd ?? process.cwd()
|
|
304
|
+
const preflight = preflightGateHook({ cwd: cwd ?? deps.cwd ?? process.cwd() }, deps);
|
|
326
305
|
const placePlanned = preflight.target.action === TARGET_PLACE;
|
|
327
|
-
const
|
|
306
|
+
const replacePlanned = preflight.target.action === TARGET_DIVERGED;
|
|
328
307
|
const wirePlanned = !preflight.wiredInProject && !preflight.wiredInLocal;
|
|
329
|
-
const base = { placePlanned,
|
|
308
|
+
const base = { placePlanned, replacePlanned, wirePlanned, ...preflight };
|
|
330
309
|
if (dryRun) return { wrote: false, dryRun: true, ...base };
|
|
331
310
|
|
|
332
311
|
if (!preflight.stampOk) {
|
|
@@ -342,7 +321,7 @@ export const writeGateHook = ({ cwd, dryRun = true, reseed = false } = {}, deps
|
|
|
342
321
|
fs.mkdir(join(preflight.projectDir, HOOKS_DIR), { recursive: true });
|
|
343
322
|
writeHookFile(hookAbs, HOOK_FILE_REL, preflight.bundleContent, true, fs);
|
|
344
323
|
}
|
|
345
|
-
if (
|
|
324
|
+
if (replacePlanned) writeHookFile(hookAbs, HOOK_FILE_REL, preflight.bundleContent, false, fs); // in place: the inode stays
|
|
346
325
|
if (wirePlanned) {
|
|
347
326
|
// Re-verify the target no-follow immediately BEFORE wiring: preflight read it earlier, and an
|
|
348
327
|
// external process could have swapped it (or slipped a symlink in) between preflight and now.
|
|
@@ -362,7 +341,7 @@ export const writeGateHook = ({ cwd, dryRun = true, reseed = false } = {}, deps
|
|
|
362
341
|
UTF8,
|
|
363
342
|
);
|
|
364
343
|
}
|
|
365
|
-
return { wrote: placePlanned ||
|
|
344
|
+
return { wrote: placePlanned || replacePlanned || wirePlanned, dryRun: false, ...base };
|
|
366
345
|
};
|
|
367
346
|
|
|
368
347
|
// ── the read-lane writer (--read-lane; AD-055 Part II, Decisions 5/9) ──────────────────
|
|
@@ -372,7 +351,7 @@ export const writeGateHook = ({ cwd, dryRun = true, reseed = false } = {}, deps
|
|
|
372
351
|
// merge-preserve, symlink/non-regular refusal, malformed-JSON fail-closed, atomic), PLUS a CURRENCY
|
|
373
352
|
// CHECK (Decisions 9): --apply refuses unless the PLACED hook is byte-identical to the current
|
|
374
353
|
// bundle — enabling a lane a pre-1.48 hook can never read would be a silent no-op the user paid
|
|
375
|
-
// consent for. The refusal names the
|
|
354
|
+
// consent for. The refusal names `gate-hook --apply`, which writes the hook current.
|
|
376
355
|
|
|
377
356
|
const laneStop = (message) => makeGateHookError(GATE_HOOK_LANE, message);
|
|
378
357
|
|
|
@@ -411,7 +390,6 @@ const preflightLaneTarget = (absPath, deps) => {
|
|
|
411
390
|
};
|
|
412
391
|
|
|
413
392
|
export const applyGateHookCommand = (root) => `node ${q(GATE_HOOK_TOOL)} --apply --cwd ${q(root)}`;
|
|
414
|
-
export const applyReseedCommand = (root) => `node ${q(GATE_HOOK_TOOL)} --apply --reseed --cwd ${q(root)}`;
|
|
415
393
|
export const applyReadLaneCommand = (root) => `node ${q(GATE_HOOK_TOOL)} --read-lane --cwd ${q(root)} --apply`;
|
|
416
394
|
|
|
417
395
|
// The currency check (Decisions 9): the PLACED hook must be byte-identical to the current bundle,
|
|
@@ -434,7 +412,7 @@ const checkHookCurrency = (root, bundleContent, fs) => {
|
|
|
434
412
|
return {
|
|
435
413
|
current: false,
|
|
436
414
|
reason: `${HOOK_FILE_REL} is not the current bundle`,
|
|
437
|
-
refusal: `${HOOK_FILE_REL} is NOT the current bundle — enabling the read-lane now would be a silent no-op (a pre-1.48 hook never reads ${LANES_REL}).
|
|
415
|
+
refusal: `${HOOK_FILE_REL} is NOT the current bundle — enabling the read-lane now would be a silent no-op (a pre-1.48 hook never reads ${LANES_REL}). Write it current, then re-run with --read-lane:\n ${applyGateHookCommand(root)}`,
|
|
438
416
|
};
|
|
439
417
|
}
|
|
440
418
|
return { current: true, reason: 'the placed hook is the current bundle' };
|
|
@@ -513,7 +491,7 @@ export const formatReadLaneResult = (result) => {
|
|
|
513
491
|
lines.push(
|
|
514
492
|
result.currency.current
|
|
515
493
|
? ' hook currency: current — the lane will fire once enabled.'
|
|
516
|
-
: ` hook currency: STALE — ${result.currency.reason}; --apply will REFUSE until
|
|
494
|
+
: ` hook currency: STALE — ${result.currency.reason}; --apply will REFUSE until the hook is written current (${applyGateHookCommand(result.root)}).`,
|
|
517
495
|
);
|
|
518
496
|
if (!result.wired) {
|
|
519
497
|
lines.push(` hook wiring: NOT wired into ${SETTINGS_FILE}; --apply will REFUSE until you wire it (${applyGateHookCommand(result.root)}).`);
|
|
@@ -534,8 +512,7 @@ const TRUST_POSTURE_LINE =
|
|
|
534
512
|
const formatTargetLine = (result) => {
|
|
535
513
|
if (result.target.action === TARGET_PLACE) return ` - ${HOOK_FILE_REL}: ${result.dryRun ? 'would place' : 'placed'}`;
|
|
536
514
|
if (result.target.action === TARGET_CURRENT) return ` - ${HOOK_FILE_REL}: already current`;
|
|
537
|
-
|
|
538
|
-
return ` - ${HOOK_FILE_REL}: diverged from the bundle — preserved, never clobbered (already wired; reseed it from the bundle: ${applyReseedCommand(result.projectDir)})`;
|
|
515
|
+
return ` - ${fileLine({ rel: HOOK_FILE_REL, state: 'hook' }, result.dryRun ? undefined : 'written', result.dryRun)}`;
|
|
539
516
|
};
|
|
540
517
|
|
|
541
518
|
const formatSettingsLine = (result) => {
|
|
@@ -544,14 +521,9 @@ const formatSettingsLine = (result) => {
|
|
|
544
521
|
return ` - ${SETTINGS_FILE}: ${result.dryRun ? 'would wire' : 'wired'} the ${PRE_TOOL_USE_EVENT} "${HOOK_MATCHER}" entry`;
|
|
545
522
|
};
|
|
546
523
|
|
|
547
|
-
const RESEED_CURRENT_LINE = 'nothing to change: the placed hook is current';
|
|
548
|
-
|
|
549
524
|
export const formatResult = (result) => {
|
|
550
|
-
if (result.reseed && !result.reseedPlanned && !result.wirePlanned) return RESEED_CURRENT_LINE;
|
|
551
525
|
const lines = [
|
|
552
|
-
result.dryRun
|
|
553
|
-
? `agent-workflow gate hook — DRY RUN (no changes; re-run with --apply${result.reseed ? ' --reseed' : ''})`
|
|
554
|
-
: 'agent-workflow gate hook — APPLY',
|
|
526
|
+
result.dryRun ? 'agent-workflow gate hook — DRY RUN (no changes; re-run with --apply)' : 'agent-workflow gate hook — APPLY',
|
|
555
527
|
formatTargetLine(result),
|
|
556
528
|
formatSettingsLine(result),
|
|
557
529
|
TRUST_POSTURE_LINE,
|
|
@@ -569,14 +541,13 @@ export const formatResult = (result) => {
|
|
|
569
541
|
// ── CLI ───────────────────────────────────────────────────────────────────────────────
|
|
570
542
|
|
|
571
543
|
export const parseArgs = (argv) => {
|
|
572
|
-
const opts = { dryRunFlag: false, apply: false, cwd: undefined, help: false, readLane: false
|
|
544
|
+
const opts = { dryRunFlag: false, apply: false, cwd: undefined, help: false, readLane: false };
|
|
573
545
|
for (let i = 0; i < argv.length; i += 1) {
|
|
574
546
|
const arg = argv[i];
|
|
575
547
|
if (arg === '--help' || arg === '-h') opts.help = true;
|
|
576
548
|
else if (arg === '--dry-run') opts.dryRunFlag = true;
|
|
577
549
|
else if (arg === '--apply') opts.apply = true;
|
|
578
550
|
else if (arg === '--read-lane') opts.readLane = true;
|
|
579
|
-
else if (arg === '--reseed') opts.reseed = true;
|
|
580
551
|
else if (arg === '--cwd') {
|
|
581
552
|
i += 1;
|
|
582
553
|
if (argv[i] === undefined || argv[i].startsWith('-')) throw fail(EXIT_USAGE, '--cwd needs a directory argument');
|
|
@@ -586,8 +557,7 @@ export const parseArgs = (argv) => {
|
|
|
586
557
|
}
|
|
587
558
|
}
|
|
588
559
|
if (opts.dryRunFlag && opts.apply) throw fail(EXIT_USAGE, '--dry-run and --apply cannot be used together');
|
|
589
|
-
|
|
590
|
-
return { help: opts.help, dryRun: !opts.apply, cwd: opts.cwd, readLane: opts.readLane, reseed: opts.reseed };
|
|
560
|
+
return { help: opts.help, dryRun: !opts.apply, cwd: opts.cwd, readLane: opts.readLane };
|
|
591
561
|
};
|
|
592
562
|
|
|
593
563
|
export const main = (argv = process.argv.slice(2), deps = {}) => {
|
|
@@ -604,7 +574,7 @@ export const main = (argv = process.argv.slice(2), deps = {}) => {
|
|
|
604
574
|
log(formatReadLaneResult(laneResult));
|
|
605
575
|
return EXIT_OK;
|
|
606
576
|
}
|
|
607
|
-
const result = writeGateHook({ cwd: args.cwd ?? deps.cwd ?? process.cwd(), dryRun: args.dryRun
|
|
577
|
+
const result = writeGateHook({ cwd: args.cwd ?? deps.cwd ?? process.cwd(), dryRun: args.dryRun }, deps);
|
|
608
578
|
log(formatResult(result));
|
|
609
579
|
return EXIT_OK;
|
|
610
580
|
} catch (err) {
|
|
@@ -47,7 +47,8 @@ import {
|
|
|
47
47
|
import { loadAutonomy, isSparseSeedConfig, AUTONOMY_REL } from './autonomy-config.mjs';
|
|
48
48
|
import { deriveDoctorPlan, TRUSTED_DIRS } from './autonomy-doctor.mjs';
|
|
49
49
|
import { LANE_KIT, laneOf, applySlot, consoleArgv } from './write-lanes.mjs';
|
|
50
|
-
import { STATE_BLOCK_HOOK_COMMAND, STATE_BLOCK_HOOK_RUNTIME, isStopHookWired } from './state-block-hook.mjs';
|
|
50
|
+
import { STATE_BLOCK_HOOK_COMMAND, STATE_BLOCK_HOOK_FILE_REL, STATE_BLOCK_HOOK_RUNTIME, isStopHookWired, writeStateBlockHook } from './state-block-hook.mjs';
|
|
51
|
+
import { HOOK_FILE_REL, HOOKS_DIR, writeGateHook } from './gate-hook.mjs';
|
|
51
52
|
import { detectBackends } from './detect-backends.mjs';
|
|
52
53
|
import { isDirectRun } from './direct-run.mjs';
|
|
53
54
|
import { ACTIVITIES, resolveActivityRecipe, composeReadiness, safeLine } from './recipes.mjs';
|
|
@@ -55,8 +56,7 @@ import { surveyFamily, surveyGateHook } from './family-registry.mjs';
|
|
|
55
56
|
import { probeSandboxMasks, needsMasksApply, patternToRel } from './sandbox-masks.mjs';
|
|
56
57
|
import { shellQuoteArg } from './review-state.mjs';
|
|
57
58
|
import { isFinalCapableDeclaration } from './run-gates.mjs';
|
|
58
|
-
import { loadDeclaration, canonicalCheckerGates, coverageProducerPrecedes, isKitOwnedCheckerGate
|
|
59
|
-
import { readRegularFileNoFollow } from './fs-read-nofollow.mjs';
|
|
59
|
+
import { loadDeclaration, canonicalCheckerGates, coverageProducerPrecedes, isKitOwnedCheckerGate } from './gates-declaration.mjs';
|
|
60
60
|
// The typed channel's READ-ONLY leaf only — never tools/mcp.mjs, which reaches the write core.
|
|
61
61
|
import {
|
|
62
62
|
SERVER_NAME as MCP_SERVER_NAME,
|
|
@@ -193,17 +193,14 @@ export const SEVERITIES = Object.freeze({
|
|
|
193
193
|
'source-size.schema-1': SEVERITY_ATTENTION,
|
|
194
194
|
'source-size.layout': SEVERITY_OPTIONAL,
|
|
195
195
|
'gate-hook': SEVERITY_OPTIONAL,
|
|
196
|
-
// A
|
|
197
|
-
|
|
198
|
-
// offer to enable something.
|
|
199
|
-
'gate-hook.marker-stale': SEVERITY_ATTENTION,
|
|
196
|
+
// A wired hook's kit file absent or differing: its lane is kit, as `agents.not-current`'s.
|
|
197
|
+
'gate-hook.not-current': SEVERITY_OPTIONAL,
|
|
200
198
|
'commit-guard': SEVERITY_OPTIONAL,
|
|
201
199
|
'hook-checks': SEVERITY_OPTIONAL,
|
|
202
200
|
enforcement: SEVERITY_OPTIONAL,
|
|
203
201
|
'read-lane': SEVERITY_OPTIONAL,
|
|
204
|
-
'read-lane.stale': SEVERITY_ATTENTION,
|
|
205
|
-
'read-lane.missing': SEVERITY_ATTENTION,
|
|
206
202
|
'state-block': SEVERITY_OPTIONAL,
|
|
203
|
+
'state-block.not-current': SEVERITY_OPTIONAL,
|
|
207
204
|
'mcp-channel': SEVERITY_OPTIONAL,
|
|
208
205
|
'mcp-channel.differing': SEVERITY_ATTENTION,
|
|
209
206
|
agents: SEVERITY_OPTIONAL,
|
|
@@ -292,14 +289,13 @@ export const WHATS = Object.freeze({
|
|
|
292
289
|
'source-size.adopted-elsewhere': "the source-size gate runs a DIFFERENT copy of this checker ({n} declared) — adopted here, just not through this kit's own tool",
|
|
293
290
|
'source-size.id-squatter': 'a gate carries the source-size id but is not this checker — the practice reads as declared while nothing measures module size',
|
|
294
291
|
'gate-hook': '{n} declared gate(s) prompt per run — the gate-approval hook is not wired',
|
|
295
|
-
'gate-hook.
|
|
292
|
+
'gate-hook.not-current': `${HOOK_FILE_REL} is absent or differs from the body the kit writes for it — written with that body, with no question`,
|
|
296
293
|
'commit-guard': 'the gate matrix is final-run-capable but no commit-guard arms the pre-commit hook — a commit needs no green receipt yet',
|
|
297
294
|
'hook-checks': 'the pre-commit hook lacks this kit\'s {checks} — the kit arms each line',
|
|
298
295
|
enforcement: ENFORCEMENT_WHAT,
|
|
299
296
|
'read-lane': 'the gate hook is wired but the read-only compound lane is off — pipes/chains of seeded reads still prompt one by one',
|
|
300
|
-
'read-lane.stale': 'the read-lane is ON but the placed gate hook is stale — an old hook never reads lanes.json, so the lane is silently dark; reseed it',
|
|
301
|
-
'read-lane.missing': 'the gate hook is wired but its placed file is missing — every Bash call errors and the read-lane is dark; re-place it',
|
|
302
297
|
'state-block': 'nothing checks the closing state block — a turn that ends on «nothing needed from you», or on a promise it never started, passes unseen',
|
|
298
|
+
'state-block.not-current': `${STATE_BLOCK_HOOK_FILE_REL} is absent or differs from the body the kit writes for it — written with that body, with no question`,
|
|
303
299
|
'mcp-channel': "the kit's read-only MCP server is not registered here — path questions and literal searches stay shell strings",
|
|
304
300
|
'mcp-channel.differing': 'an "{server}" MCP entry is already declared here and DIFFERS from the registration this kit copy would write',
|
|
305
301
|
agents: '{n} bundled subagent vehicle(s) not placed (Claude Code) — {ro} read-only, {ex} the full-tool executor; the apply PREVIEWS first',
|
|
@@ -383,8 +379,11 @@ export const BENEFITS = Object.freeze({
|
|
|
383
379
|
'jev-skill': 'the TypeSafe skill for Claude Code, Codex and Antigravity CLI, one pinned verified copy per agent root, from one command you run',
|
|
384
380
|
});
|
|
385
381
|
// The arms whose gain differs from their base item's (BENEFITS stays keyed by item key).
|
|
382
|
+
const HOOK_CURRENCY_BENEFIT = 'currency — a hook you wired runs the body the kit writes for it today';
|
|
386
383
|
export const VARIANT_BENEFITS = Object.freeze({
|
|
387
384
|
'agents.not-current': 'currency — each kit agent file carries the body the kit writes for it today, model and effort where docs/ai/vehicles.json names them',
|
|
385
|
+
'gate-hook.not-current': HOOK_CURRENCY_BENEFIT,
|
|
386
|
+
'state-block.not-current': HOOK_CURRENCY_BENEFIT,
|
|
388
387
|
'source-size.layout': 'layout — piles past the layout limits become recorded, reasoned debt, so the commit hook can judge new ones once its layout line is armed',
|
|
389
388
|
});
|
|
390
389
|
|
|
@@ -613,46 +612,33 @@ const probeReviewRecipe = ({ root, deps, add, skip }) => {
|
|
|
613
612
|
}
|
|
614
613
|
};
|
|
615
614
|
|
|
616
|
-
|
|
615
|
+
// The kit arm of a WIRED hook (contract: init-project, part hook-writers): the writer's plain dry run,
|
|
616
|
+
// the call the danger check makes. A throw is the probe's stated skip; no planned place or replace
|
|
617
|
+
// renders nothing; a stale stamp beside one is the upgrade-first skip; otherwise the kit item.
|
|
618
|
+
const probeKitHook = ({ key, write, rel, root, deps, add }) => {
|
|
619
|
+
const plan = write({ cwd: root, dryRun: true }, deps);
|
|
620
|
+
if (!plan.placePlanned && !plan.replacePlanned) return;
|
|
621
|
+
if (!plan.stampOk) throw upgradeFirst(plan.stamp);
|
|
622
|
+
const variant = `${key}.not-current`;
|
|
623
|
+
add(key, WHATS[variant], formsApply(variant, root), variant, `writes: ${rel}`);
|
|
624
|
+
};
|
|
625
|
+
|
|
626
|
+
const probeGates = ({ root, deps, add, skip }) => {
|
|
617
627
|
try {
|
|
618
628
|
const sg = surveyGateHook(root, deps);
|
|
619
629
|
if (sg.error) throw new Error(sg.error);
|
|
620
|
-
if (sg.declarationPresent && sg.declaredGates === null) throw new Error(sg.declarationError ?? 'gates.json present but unreadable');
|
|
621
630
|
// An ABSENT file and the seeded-EMPTY list are equally undeclared (Segment B); the
|
|
622
631
|
// apply is the consent-gated gates-init PREVIEW (it proposes entries from the project's own
|
|
623
|
-
// scripts and writes only on an explicit yes) — never the runner.
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
}
|
|
631
|
-
if (
|
|
632
|
-
|
|
633
|
-
return;
|
|
634
|
-
}
|
|
635
|
-
// D8 — the marker REFRESH path. The placed hook validates the declaration through its OWN baked
|
|
636
|
-
// copy and goes dark on any key it does not know (auto-approval off, every gate prompts again),
|
|
637
|
-
// so a declaration carrying the marker key under a hook that predates it silently switches a
|
|
638
|
-
// CONFIGURED capability off with no error anywhere. Deliberately marker-SCOPED: a stale hook is
|
|
639
|
-
// otherwise harmless, and nagging every deployment about hook bytes is not this item's job.
|
|
640
|
-
if (!declarationCarriesMarker(root, deps)) return;
|
|
641
|
-
// Throws on a symlink / directory / unreadable target → the stated skip, never a wrong verdict.
|
|
642
|
-
// ABSENT is not this arm either: a hook that is not placed belongs to the place offers above and
|
|
643
|
-
// in the read-lane item, whose recovery actually places one.
|
|
644
|
-
if (readPlacedHookCurrency(root, deps) !== HOOK_CURRENCY.STALE) return;
|
|
645
|
-
// The writer's OWN stale recovery: `gate-hook --apply --reseed` replaces the placed hook with
|
|
646
|
-
// the bundle in place — the one consented replacement; the slot renders it behind the check.
|
|
647
|
-
// The RESULT is what the read-lane item defers to — not these conditions re-derived there. Both
|
|
648
|
-
// probes read the placed hook independently, so a hook that changes between the two reads would
|
|
649
|
-
// otherwise let each conclude the other owns it and leave a dark lane reported by nobody.
|
|
650
|
-
shared.markerStaleRendered = add(
|
|
651
|
-
'gate-hook',
|
|
652
|
-
fillTemplate(WHATS['gate-hook.marker-stale'], {}),
|
|
653
|
-
`node ${q(toolPath('gate-hook.mjs'))} --apply --reseed --cwd ${q(root)}`,
|
|
654
|
-
'gate-hook.marker-stale',
|
|
655
|
-
);
|
|
632
|
+
// scripts and writes only on an explicit yes) — never the runner. gates-init writes ONLY with
|
|
633
|
+
// --apply — the apply field stays a PURE executable command; the two-step preview semantics
|
|
634
|
+
// live in WHAT, never as prose appended to the command.
|
|
635
|
+
const undeclared = !sg.declarationPresent || sg.declaredGates === 0;
|
|
636
|
+
if (undeclared) add('gates-declaration', fillTemplate(WHATS['gates-declaration'], {}), `node ${q(toolPath('gates-init.mjs'))} --cwd ${q(root)}`);
|
|
637
|
+
// A wired hook is accepted: its kit file is written current whatever the declaration says (an
|
|
638
|
+
// unreadable one is the gates-inert probe's skip). An unwired one keeps the order of its offer.
|
|
639
|
+
if (sg.wired) return probeKitHook({ key: 'gate-hook', write: writeGateHook, rel: HOOK_FILE_REL, root, deps, add });
|
|
640
|
+
if (sg.declaredGates === null) throw new Error(sg.declarationError ?? 'gates.json present but unreadable');
|
|
641
|
+
if (!undeclared) add('gate-hook', fillTemplate(WHATS['gate-hook'], { n: sg.declaredGates }), `node ${q(toolPath('gate-hook.mjs'))} --apply --cwd ${q(root)}`);
|
|
656
642
|
} catch (err) {
|
|
657
643
|
skip('gate-hook', err);
|
|
658
644
|
}
|
|
@@ -1067,55 +1053,18 @@ export const probeEnforcement = ({ root, deps, add, skip }) => {
|
|
|
1067
1053
|
}
|
|
1068
1054
|
};
|
|
1069
1055
|
|
|
1070
|
-
// The read-lane offer (AD-055 Part II, Help-through-Recommendations): once the gate hook is
|
|
1071
|
-
//
|
|
1072
|
-
//
|
|
1073
|
-
//
|
|
1074
|
-
//
|
|
1075
|
-
//
|
|
1076
|
-
|
|
1056
|
+
// The read-lane offer (AD-055 Part II, Help-through-Recommendations): once the gate hook is WIRED,
|
|
1057
|
+
// offer to enable the opt-in read-only compound lane, whatever the placed hook's bytes — a stale or
|
|
1058
|
+
// absent hook under it is a planned file of `gate-hook.not-current`, which the kit route applies
|
|
1059
|
+
// before the offers. Mutually exclusive with the gate-hook offer BY CONSTRUCTION — that offer keys
|
|
1060
|
+
// on `!wired`, this one on `wired`. The apply is the gate-hook --read-lane PREVIEW one-liner (its
|
|
1061
|
+
// own currency check + posture note fire at the writer; it IS a consent flow). Converges once
|
|
1062
|
+
// lanes.json enables the lane.
|
|
1063
|
+
const probeReadLane = ({ root, deps, add, skip }) => {
|
|
1077
1064
|
try {
|
|
1078
1065
|
const sg = surveyGateHook(root, deps);
|
|
1079
1066
|
if (sg.error) throw new Error(sg.error);
|
|
1080
|
-
if (!sg.wired
|
|
1081
|
-
// Wired but the placed hook FILE is missing — the hook errors on every Bash call and the lane
|
|
1082
|
-
// is silently dark; surface it as attention with a place-first recovery (council R2-M2).
|
|
1083
|
-
const placeRecovery = () =>
|
|
1084
|
-
add('read-lane', fillTemplate(WHATS['read-lane.missing'], {}), `node ${q(toolPath('gate-hook.mjs'))} --apply --cwd ${q(root)}`, 'read-lane.missing');
|
|
1085
|
-
if (!sg.filePlaced || readsAbsent(deps, join(root, GATE_HOOK_REL))) {
|
|
1086
|
-
placeRecovery();
|
|
1087
|
-
return;
|
|
1088
|
-
}
|
|
1089
|
-
if (readReadLaneToggle(root, deps)) {
|
|
1090
|
-
// The lane is ON: converged IFF the placed hook is byte-current — a stale (pre-1.48) hook never
|
|
1091
|
-
// reads lanes.json, so the enabled lane is a silent no-op the user must reseed (council B7). The
|
|
1092
|
-
// reseed route pins the ABSOLUTE root (council R2-M3), so running it from any cwd can only
|
|
1093
|
-
// replace this repo's hook.
|
|
1094
|
-
const currency = readPlacedHookCurrency(root, deps);
|
|
1095
|
-
if (currency === HOOK_CURRENCY.CURRENT) return; // converged
|
|
1096
|
-
if (currency === HOOK_CURRENCY.ABSENT) {
|
|
1097
|
-
// The survey saw it placed and it is gone by the time we read it. The missing arm is the
|
|
1098
|
-
// honest report of that; a reseed recovery, which refuses an absent hook, is not.
|
|
1099
|
-
placeRecovery();
|
|
1100
|
-
return;
|
|
1101
|
-
}
|
|
1102
|
-
// ONE render per condition — and the item that renders is the one whose CAUSE is true. A hook
|
|
1103
|
-
// that postdates the read-lane but predates the marker key reads lanes.json perfectly well, so
|
|
1104
|
-
// this arm's "an old hook never reads lanes.json" would be a false diagnosis over it, while the
|
|
1105
|
-
// marker arm's is exact. Both carry the same reseed recovery, so deferring costs
|
|
1106
|
-
// the reader nothing and buys a true sentence. The condition is that the marker arm REALLY
|
|
1107
|
-
// rendered — never the conditions it would have used, re-derived here: each probe reads the
|
|
1108
|
-
// placed hook itself, so a hook changing between the two reads could otherwise have both defer
|
|
1109
|
-
// to the other and leave the dark lane reported by nobody.
|
|
1110
|
-
if (shared.markerStaleRendered === true) return;
|
|
1111
|
-
add(
|
|
1112
|
-
'read-lane',
|
|
1113
|
-
fillTemplate(WHATS['read-lane.stale'], {}),
|
|
1114
|
-
`node ${q(toolPath('gate-hook.mjs'))} --apply --reseed --cwd ${q(root)}`,
|
|
1115
|
-
'read-lane.stale',
|
|
1116
|
-
);
|
|
1117
|
-
return;
|
|
1118
|
-
}
|
|
1067
|
+
if (!sg.wired || readReadLaneToggle(root, deps)) return;
|
|
1119
1068
|
add('read-lane', fillTemplate(WHATS['read-lane'], {}), `node ${q(toolPath('gate-hook.mjs'))} --read-lane --cwd ${q(root)}`);
|
|
1120
1069
|
} catch (err) {
|
|
1121
1070
|
skip('read-lane', err);
|
|
@@ -1125,12 +1074,16 @@ const probeReadLane = ({ root, deps, add, skip, shared }) => {
|
|
|
1125
1074
|
// The state-block-guard offer (AD-075 · OPT-IN-SHIPS-INVISIBLE). This item exists because its absence
|
|
1126
1075
|
// fired: 3.14.0 shipped the detector with a mode doc, a catalog row and a README row — and no advisor
|
|
1127
1076
|
// entry — so `upgrade` reported «nothing is broken» to a user who did not have it. Its writer is
|
|
1128
|
-
// state-block-hook.mjs;
|
|
1077
|
+
// state-block-hook.mjs; acceptance is that leaf's own isStopHookWired over both settings files, and
|
|
1078
|
+
// a wired hook takes the kit arm.
|
|
1129
1079
|
const probeStateBlockHook = ({ root, deps, add, skip }) => {
|
|
1130
1080
|
try {
|
|
1131
1081
|
const project = readSettingsFile(join(root, SETTINGS_FILE), { ...deps, cwd: root });
|
|
1132
1082
|
const local = readSettingsFile(join(root, SETTINGS_LOCAL_FILE), { ...deps, cwd: root });
|
|
1133
|
-
if (isStopHookWired(project.data) || isStopHookWired(local.data))
|
|
1083
|
+
if (isStopHookWired(project.data) || isStopHookWired(local.data)) {
|
|
1084
|
+
probeKitHook({ key: 'state-block', write: writeStateBlockHook, rel: STATE_BLOCK_HOOK_FILE_REL, root, deps, add });
|
|
1085
|
+
return;
|
|
1086
|
+
}
|
|
1134
1087
|
add(
|
|
1135
1088
|
'state-block',
|
|
1136
1089
|
fillTemplate(WHATS['state-block'], {}),
|
|
@@ -1307,59 +1260,14 @@ export const recipeFingerprint = ({ hosts, dirs, home }) => {
|
|
|
1307
1260
|
// so no lane names it. The store's path, keys, lane registry and reader are ack-store.mjs.
|
|
1308
1261
|
|
|
1309
1262
|
// The opt-in read-lane toggle file (AD-055 Part II) — the SAME kit-owned docs/ai/lanes.json the
|
|
1310
|
-
// placed hook reads live. The read-lane item offers to enable it once the hook is
|
|
1263
|
+
// placed hook reads live. The read-lane item offers to enable it once the hook is wired.
|
|
1311
1264
|
export const LANES_FILE = 'docs/ai/lanes.json';
|
|
1312
1265
|
export const READ_LANE_KEY = 'readLane';
|
|
1313
1266
|
|
|
1314
|
-
// The placed gate hook + the bundled runtime the read-lane item byte-compares for currency (AD-055
|
|
1315
|
-
// Part II, council B7): an enabled lane over a STALE hook is a silent no-op — the pre-1.48 hook never
|
|
1316
|
-
// reads lanes.json — so it must surface as an ATTENTION reseed, not a silent convergence.
|
|
1317
|
-
const GATE_HOOK_REL = '.claude/hooks/agent-workflow-gates.mjs';
|
|
1318
|
-
const BUNDLED_HOOK_ABS = join(HERE, '..', 'references', 'hooks', 'gate-approve.mjs');
|
|
1319
|
-
|
|
1320
1267
|
// The state-block-guard wiring the advisor looks for is the writer leaf's own rule (any Stop entry of
|
|
1321
1268
|
// either settings file running the runtime); the two constants are re-exported for their readers.
|
|
1322
1269
|
export { STATE_BLOCK_HOOK_COMMAND, STATE_BLOCK_HOOK_RUNTIME };
|
|
1323
1270
|
|
|
1324
|
-
// The placed gate hook's currency, as the states a caller must tell APART (D8). Read through the
|
|
1325
|
-
// writer-class fail-closed no-follow primitive, never a bare readFile: a byte-compare that FOLLOWS a
|
|
1326
|
-
// symlink can call a placed hook current because something ELSE is — a wrong verdict, which is worse
|
|
1327
|
-
// than a missing one. `current` and `stale` are answers; `absent` is one the caller disposes of
|
|
1328
|
-
// itself (a hook that is not there belongs to the place offers, never to a refresh arm); a symlink,
|
|
1329
|
-
// a directory and an unreadable target all THROW into the probe's stated-skip lane.
|
|
1330
|
-
const HOOK_CURRENCY = Object.freeze({ CURRENT: 'current', STALE: 'stale', ABSENT: 'absent' });
|
|
1331
|
-
const readsAbsent = (deps, path) => {
|
|
1332
|
-
try {
|
|
1333
|
-
(deps.lstat ?? lstatSync)(path);
|
|
1334
|
-
return false;
|
|
1335
|
-
} catch (err) {
|
|
1336
|
-
return err?.code === ABSENT_CODE;
|
|
1337
|
-
}
|
|
1338
|
-
};
|
|
1339
|
-
|
|
1340
|
-
const readPlacedHookCurrency = (root, deps) => {
|
|
1341
|
-
if (readsAbsent(deps, join(root, GATE_HOOK_REL))) return HOOK_CURRENCY.ABSENT;
|
|
1342
|
-
const read = deps.readRegularFileNoFollow ?? readRegularFileNoFollow;
|
|
1343
|
-
const placed = read(join(root, GATE_HOOK_REL));
|
|
1344
|
-
if (placed.outcome === 'absent') return HOOK_CURRENCY.ABSENT;
|
|
1345
|
-
if (placed.outcome === 'foreign') {
|
|
1346
|
-
throw new Error(`${GATE_HOOK_REL} is a ${placed.className}, not a regular file — refusing to judge its currency`);
|
|
1347
|
-
}
|
|
1348
|
-
if (placed.outcome !== 'ok') throw new Error(`${GATE_HOOK_REL} is unreadable (${placed.code})`);
|
|
1349
|
-
const bundle = (deps.readFile ?? readFileSync)(deps.bundledHookPath ?? BUNDLED_HOOK_ABS, 'utf8');
|
|
1350
|
-
return placed.content === bundle ? HOOK_CURRENCY.CURRENT : HOOK_CURRENCY.STALE;
|
|
1351
|
-
};
|
|
1352
|
-
|
|
1353
|
-
// Does the declaration carry the marker KEY at all? The question is PRESENCE, never the value: an
|
|
1354
|
-
// older hook rejects a key it does not know whatever that key says, so `lcovProducer: false` — a
|
|
1355
|
-
// perfectly valid declaration the runner accepts — darkens such a hook exactly as `true` does. Asking
|
|
1356
|
-
// through the producer predicate would be wrong twice over: it answers yes for a cmd-recognized
|
|
1357
|
-
// producer that needs nothing from the hook, and no for the false marker that does.
|
|
1358
|
-
const declarationCarriesMarker = (root, deps) => {
|
|
1359
|
-
const declaration = loadDeclaration(root, deps);
|
|
1360
|
-
return declaration.outcome === 'loaded' && declaration.gates.some((gate) => Object.hasOwn(gate, LCOV_PRODUCER_KEY));
|
|
1361
|
-
};
|
|
1362
|
-
|
|
1363
1271
|
// Read the opt-in read-lane toggle for the read-lane item. An ABSENT file (or absent docs/ai) →
|
|
1364
1272
|
// false (the lane is off — offer it). `readLane === true` → enabled (converged). A parse/IO error on
|
|
1365
1273
|
// an EXISTING file, a symlinked ancestor/leaf, an escape, or a non-object root THROWS — the probe
|
|
@@ -1692,7 +1600,7 @@ export const buildRecommendations = ({ cwd, deps = {} } = {}) => {
|
|
|
1692
1600
|
// TOO LONG for the capped WHAT and outside the pure-command apply (such as the bridge-tier
|
|
1693
1601
|
// missing-entries line or the worktrees-dir ack fallback). Single-line like apply; absent otherwise.
|
|
1694
1602
|
// Returns whether the item really RENDERED. One probe's disposition depends on another's having
|
|
1695
|
-
// spoken (
|
|
1603
|
+
// spoken (executor-vehicle yields to agents.not-current), and "the conditions still look right"
|
|
1696
1604
|
// is not the same fact as "an item exists" — the shape backstop can refuse, and a condition read
|
|
1697
1605
|
// twice can answer twice.
|
|
1698
1606
|
const add = (key, what, apply, variant = key, detail = null) => {
|
|
@@ -1717,19 +1625,21 @@ export const buildRecommendations = ({ cwd, deps = {} } = {}) => {
|
|
|
1717
1625
|
return true;
|
|
1718
1626
|
};
|
|
1719
1627
|
// The per-run scratch a probe uses to tell a LATER probe what it actually did. Written by exactly
|
|
1720
|
-
// one pair today (
|
|
1628
|
+
// one pair today (executor-vehicle yields to agents.not-current) and read in the frozen PROBES
|
|
1721
1629
|
// order, so the reader can never run first.
|
|
1722
1630
|
const shared = {};
|
|
1723
|
-
// A device node reads as absent (a sandbox mask), except under .claude/agents
|
|
1724
|
-
//
|
|
1631
|
+
// A device node reads as absent (a sandbox mask), except under .claude/agents/ and at or under
|
|
1632
|
+
// .claude/hooks/: there it is the kit writer's refusal, as the danger check reads it.
|
|
1725
1633
|
const agentsDir = join(root, AGENTS_DIR) + sep;
|
|
1634
|
+
const hooksDir = join(root, HOOKS_DIR) + sep;
|
|
1635
|
+
const kitPath = (path) => String(path).startsWith(agentsDir) || `${path}${sep}`.startsWith(hooksDir);
|
|
1726
1636
|
const contentDeps = Object.create(Object.getPrototypeOf(deps), {
|
|
1727
1637
|
...Object.getOwnPropertyDescriptors(deps),
|
|
1728
1638
|
lstat: {
|
|
1729
1639
|
enumerable: true,
|
|
1730
1640
|
value: (path, ...args) => {
|
|
1731
1641
|
const stat = (deps.lstat ?? deps.lstatSync ?? lstatSync)(path, ...args);
|
|
1732
|
-
if (!
|
|
1642
|
+
if (!kitPath(path) && (stat.isCharacterDevice?.() || stat.isBlockDevice?.())) {
|
|
1733
1643
|
throw Object.assign(new Error(`${ABSENT_CODE}: ${path}`), { code: ABSENT_CODE });
|
|
1734
1644
|
}
|
|
1735
1645
|
return stat;
|
|
@@ -51,6 +51,7 @@ import {
|
|
|
51
51
|
writeHookFile,
|
|
52
52
|
} from './gate-hook.mjs';
|
|
53
53
|
import { isDirectRun } from './direct-run.mjs';
|
|
54
|
+
import { fileLine } from './distribution-files/index.mjs';
|
|
54
55
|
|
|
55
56
|
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
56
57
|
|
|
@@ -206,11 +207,10 @@ const STATE_BLOCK_CURRENT_LINE = 'nothing to change: the state-block hook is pla
|
|
|
206
207
|
const TRUST_POSTURE_LINE =
|
|
207
208
|
'trust posture: the guard reads the closing assistant message of each turn and writes one warning line; it runs a Node process on every turn end, reads nothing else, makes no network call and approves nothing.';
|
|
208
209
|
|
|
209
|
-
const PLACEMENT_LINES = Object.freeze({
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
});
|
|
210
|
+
const PLACEMENT_LINES = Object.freeze({ [PLACEMENT_CREATE]: ['would place', 'placed'], [PLACEMENT_KEEP]: ['already current', 'already current'] });
|
|
211
|
+
const placementLine = ({ placement, dryRun }) => (placement === PLACEMENT_REPLACE
|
|
212
|
+
? fileLine({ rel: STATE_BLOCK_HOOK_FILE_REL, state: 'hook' }, dryRun ? undefined : 'written', dryRun)
|
|
213
|
+
: `${STATE_BLOCK_HOOK_FILE_REL}: ${PLACEMENT_LINES[placement][dryRun ? 0 : 1]}`);
|
|
214
214
|
|
|
215
215
|
const MERGE_LINES = Object.freeze({
|
|
216
216
|
[MERGE_NO_HOOKS]: 'the hooks key with the Stop entry',
|
|
@@ -230,7 +230,7 @@ export const formatResult = (result) => {
|
|
|
230
230
|
result.dryRun
|
|
231
231
|
? 'agent-workflow state-block hook — DRY RUN (no changes; re-run with --apply)'
|
|
232
232
|
: 'agent-workflow state-block hook — APPLY',
|
|
233
|
-
` - ${
|
|
233
|
+
` - ${placementLine(result)}`,
|
|
234
234
|
formatSettingsLine(result),
|
|
235
235
|
` command: ${STATE_BLOCK_HOOK_COMMAND} (no --require-block; references/modes/state-block-guard.md says when to add it)`,
|
|
236
236
|
TRUST_POSTURE_LINE,
|
package/tools/write-lanes.mjs
CHANGED
|
@@ -35,14 +35,13 @@ export const VARIANT_LANES = Object.freeze({
|
|
|
35
35
|
'source-size.schema-1': LANE_CHAT,
|
|
36
36
|
'source-size.layout': LANE_CHAT,
|
|
37
37
|
'gate-hook': LANE_HARNESS,
|
|
38
|
-
'gate-hook.
|
|
38
|
+
'gate-hook.not-current': LANE_KIT,
|
|
39
39
|
'commit-guard': LANE_HARNESS,
|
|
40
40
|
'hook-checks': LANE_HARNESS,
|
|
41
41
|
enforcement: LANE_HARNESS,
|
|
42
42
|
'read-lane': LANE_CHAT,
|
|
43
|
-
'read-lane.stale': LANE_HARNESS,
|
|
44
|
-
'read-lane.missing': LANE_HARNESS,
|
|
45
43
|
'state-block': LANE_HARNESS,
|
|
44
|
+
'state-block.not-current': LANE_KIT,
|
|
46
45
|
'mcp-channel': LANE_HARNESS,
|
|
47
46
|
'mcp-channel.differing': LANE_HARNESS,
|
|
48
47
|
agents: LANE_HARNESS,
|
|
@@ -93,8 +92,8 @@ export const isProtectedPath = (abs, { root, home, hooksDir }) => {
|
|
|
93
92
|
|
|
94
93
|
const SETTINGS_WRITES = [SETTINGS_PATH];
|
|
95
94
|
const LOCAL_SETTINGS_WRITES = [join('.claude', 'settings.local.json')];
|
|
96
|
-
const
|
|
97
|
-
const
|
|
95
|
+
const GATE_HOOK_FILE = [join('.claude', 'hooks', 'agent-workflow-gates.mjs')];
|
|
96
|
+
const STOP_HOOK_FILE = [join('.claude', 'hooks', 'state-block-guard.mjs')];
|
|
98
97
|
const MCP_WRITES = ['.mcp.json', ...SETTINGS_WRITES];
|
|
99
98
|
const AGENT_WRITES = [join('.claude', 'agents')];
|
|
100
99
|
|
|
@@ -139,8 +138,8 @@ const createForm = (file, preview, apply, writes, envDependent = false, userStep
|
|
|
139
138
|
});
|
|
140
139
|
|
|
141
140
|
const CORE_FORM = createForm('velocity-profile.mjs', ['--cwd', '<root>'], ['--apply', '--cwd', '<root>'], SETTINGS_WRITES);
|
|
142
|
-
|
|
143
|
-
const
|
|
141
|
+
// A hook's offer writes its file and the settings entry; its kit item, over a wired hook, the file alone.
|
|
142
|
+
const hookForm = (file, writes) => createForm(file, ['--cwd', '<root>'], ['--apply', '--cwd', '<root>'], writes);
|
|
144
143
|
const AGENT_FORM = createForm('cheap-agents.mjs', ['--cwd', '<root>'], ['--apply', '--cwd', '<root>'], AGENT_WRITES);
|
|
145
144
|
const SKILL_FORM = createForm('jev-skill.mjs', ['--claude-dir', '<dir>'], ['--apply', '--claude-dir', '<dir>'], getSkillPaths, true);
|
|
146
145
|
|
|
@@ -152,11 +151,10 @@ const FORMS = Object.freeze({
|
|
|
152
151
|
['--bridge-tier', '--cwd', '<root>'], ['--apply', '--bridge-tier', '--cwd', '<root>'], SETTINGS_WRITES, true),
|
|
153
152
|
'autonomy-render': createForm('velocity-profile.mjs',
|
|
154
153
|
['--autonomy', '--cwd', '<root>'], ['--autonomy', '--apply', '--cwd', '<root>'], SETTINGS_WRITES),
|
|
155
|
-
'gate-hook':
|
|
156
|
-
'
|
|
157
|
-
'
|
|
158
|
-
'
|
|
159
|
-
'state-block': createForm('state-block-hook.mjs', ['--cwd', '<root>'], ['--apply', '--cwd', '<root>'], STOP_HOOK_WRITES),
|
|
154
|
+
'gate-hook': hookForm('gate-hook.mjs', [...GATE_HOOK_FILE, ...SETTINGS_WRITES]),
|
|
155
|
+
'gate-hook.not-current': hookForm('gate-hook.mjs', GATE_HOOK_FILE),
|
|
156
|
+
'state-block': hookForm('state-block-hook.mjs', [...STOP_HOOK_FILE, ...SETTINGS_WRITES]),
|
|
157
|
+
'state-block.not-current': hookForm('state-block-hook.mjs', STOP_HOOK_FILE),
|
|
160
158
|
'mcp-channel': createForm('mcp.mjs', ['--cwd', '<root>'], ['--apply', '--cwd', '<root>'], MCP_WRITES),
|
|
161
159
|
'mcp-channel.differing': createForm('mcp.mjs',
|
|
162
160
|
['--replace', '--cwd', '<root>'], ['--replace', '--apply', '--cwd', '<root>'], MCP_WRITES),
|