@sabaiway/agent-workflow-kit 23.11.0 → 24.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.
Files changed (159) hide show
  1. package/CHANGELOG.md +87 -0
  2. package/README.md +4 -4
  3. package/SKILL.md +1 -1
  4. package/bridges/codex-cli-bridge/SKILL.md +7 -2
  5. package/bridges/codex-cli-bridge/bin/codex-exec-jev.test.mjs +11 -6
  6. package/bridges/codex-cli-bridge/bin/codex-exec.sh +72 -33
  7. package/bridges/codex-cli-bridge/bin/codex-exec.test.mjs +111 -3
  8. package/bridges/codex-cli-bridge/bin/codex-fixtures-harness.test.mjs +16 -1
  9. package/bridges/codex-cli-bridge/bin/codex-model-posture.test.mjs +5 -3
  10. package/bridges/codex-cli-bridge/bin/codex-review.sh +1 -1
  11. package/bridges/codex-cli-bridge/capability.json +2 -2
  12. package/capability.json +1 -1
  13. package/package.json +1 -1
  14. package/references/advisor-writers.md +2 -0
  15. package/references/agents/author.md +21 -0
  16. package/references/agents/executor.md +12 -6
  17. package/references/contracts.md +4 -4
  18. package/references/hooks/gate-approve.mjs +7 -8
  19. package/references/hooks/stage-write-guard.mjs +314 -0
  20. package/references/modes/agents.md +6 -4
  21. package/references/modes/bootstrap.md +1 -1
  22. package/references/modes/control-bytes.md +38 -32
  23. package/references/modes/flow-writer.md +10 -2
  24. package/references/modes/hook.md +4 -1
  25. package/references/modes/now.md +1 -1
  26. package/references/modes/procedures.md +49 -10
  27. package/references/modes/recipes.md +7 -7
  28. package/references/modes/recommendations.md +5 -4
  29. package/references/modes/robustness-brief.md +9 -8
  30. package/references/modes/set-recipe.md +1 -1
  31. package/references/modes/state-block-guard.md +4 -3
  32. package/references/modes/status.md +1 -1
  33. package/references/modes/upgrade.md +1 -1
  34. package/references/modes/worktrees.md +28 -5
  35. package/references/rules/story-sessions.md +2 -2
  36. package/references/scripts/archives/archive-caps.mjs +1 -1
  37. package/references/scripts/archives/archive-changelog.mjs +8 -8
  38. package/references/scripts/archives/archive-decisions.mjs +7 -7
  39. package/references/scripts/archives/archive-issues.mjs +5 -5
  40. package/references/scripts/archives/rotation-conservation.mjs +2 -1
  41. package/references/scripts/docs-size/check-docs-size.mjs +15 -15
  42. package/references/scripts/family.json +2 -0
  43. package/references/scripts/gates/kit-command-gates.mjs +7 -8
  44. package/references/scripts/gates/migrate-gates.mjs +10 -10
  45. package/references/scripts/git-hooks/install-git-hooks.mjs +13 -13
  46. package/references/scripts/run.mjs +1 -2
  47. package/references/scripts/shared/index.mjs +2 -0
  48. package/references/scripts/shared/locations.mjs +103 -0
  49. package/references/scripts/spec-schema/spec-schema.mjs +2 -1
  50. package/references/templates/orchestration.json +1 -1
  51. package/tools/ack-store.mjs +2 -1
  52. package/tools/advisor-matrix.mjs +2 -1
  53. package/tools/advisor-skip/index.mjs +73 -0
  54. package/tools/apply-danger-check.mjs +20 -6
  55. package/tools/atomic-write.mjs +3 -2
  56. package/tools/attribution.mjs +2 -1
  57. package/tools/autonomy-config.mjs +2 -1
  58. package/tools/bridge-wiring.mjs +13 -11
  59. package/tools/carriers.mjs +54 -14
  60. package/tools/cheap-agents-read.mjs +28 -7
  61. package/tools/cheap-agents.mjs +15 -10
  62. package/tools/checker-gates-read.mjs +6 -5
  63. package/tools/commands.mjs +2 -2
  64. package/tools/control-bytes.mjs +43 -20
  65. package/tools/coverage-declared/config.mjs +2 -1
  66. package/tools/coverage-producer.mjs +10 -9
  67. package/tools/delegation.mjs +7 -6
  68. package/tools/detect-backends.mjs +1 -1
  69. package/tools/dispatch-baseline.mjs +2 -1
  70. package/tools/distribution-files/scripts.mjs +4 -4
  71. package/tools/doc-parity/index.mjs +46 -0
  72. package/tools/doc-parity.mjs +27 -47
  73. package/tools/ensure-configs.mjs +2 -2
  74. package/tools/ensure-ops.mjs +24 -24
  75. package/tools/ensure-specs.mjs +7 -7
  76. package/tools/epic-shape-cli.mjs +2 -2
  77. package/tools/epic-shape-ledger.mjs +5 -5
  78. package/tools/epic-shape.mjs +5 -3
  79. package/tools/epic-store.mjs +2 -1
  80. package/tools/family-members.mjs +7 -5
  81. package/tools/family-registry.mjs +36 -30
  82. package/tools/feedback-record-cli.mjs +4 -5
  83. package/tools/flow-writer.mjs +26 -15
  84. package/tools/gate-hook.mjs +33 -28
  85. package/tools/gates-declaration.mjs +2 -1
  86. package/tools/gates-init.mjs +6 -5
  87. package/tools/git-hooks.mjs +64 -41
  88. package/tools/grounding.mjs +3 -2
  89. package/tools/hide-footprint.mjs +2 -1
  90. package/tools/hook-writer/index.mjs +147 -0
  91. package/tools/init-preflight.mjs +5 -4
  92. package/tools/init-project.mjs +12 -11
  93. package/tools/inject-methodology.mjs +3 -2
  94. package/tools/jev-guide.mjs +2 -2
  95. package/tools/known-footprint.mjs +27 -25
  96. package/tools/mcp-registration.mjs +6 -5
  97. package/tools/migration-blocks.mjs +2 -1
  98. package/tools/migration-notes.mjs +2 -2
  99. package/tools/node-evidence.mjs +4 -4
  100. package/tools/now-facts.mjs +5 -5
  101. package/tools/now-status.mjs +1 -5
  102. package/tools/orchestration-config.mjs +2 -1
  103. package/tools/orchestration-readme.mjs +7 -2
  104. package/tools/plan-approval/cli.mjs +45 -0
  105. package/tools/plan-approval/entries.mjs +109 -0
  106. package/tools/plan-approval/index.mjs +2 -0
  107. package/tools/plan-approval/record.mjs +198 -0
  108. package/tools/plan-files.mjs +6 -4
  109. package/tools/plan-shape-cli.mjs +10 -64
  110. package/tools/plan-shape-facts.mjs +240 -83
  111. package/tools/plan-shape.mjs +173 -160
  112. package/tools/plan-structure/cli.mjs +79 -0
  113. package/tools/plan-structure/index.mjs +67 -0
  114. package/tools/procedures.mjs +21 -17
  115. package/tools/profile-gaps.mjs +4 -6
  116. package/tools/project-rules/rules-priors.mjs +2 -0
  117. package/tools/project-rules/themes.mjs +6 -4
  118. package/tools/recipes.mjs +44 -29
  119. package/tools/recommendations.mjs +90 -39
  120. package/tools/reference-profile.mjs +2 -2
  121. package/tools/release-scan/index.mjs +30 -0
  122. package/tools/release-scan.mjs +46 -25
  123. package/tools/renderers.mjs +14 -8
  124. package/tools/repo-lex.mjs +84 -0
  125. package/tools/robustness-brief.mjs +14 -11
  126. package/tools/sandbox-masks.mjs +6 -4
  127. package/tools/satellite-locator.mjs +3 -2
  128. package/tools/script-priors.mjs +3 -2
  129. package/tools/session-close-check.mjs +71 -15
  130. package/tools/set-flow.mjs +2 -2
  131. package/tools/set-recipe.mjs +17 -9
  132. package/tools/source-size/help.mjs +4 -4
  133. package/tools/source-size/layout.mjs +2 -1
  134. package/tools/source-size/piles.mjs +2 -2
  135. package/tools/source-size-config.mjs +3 -3
  136. package/tools/source-size-refusal.mjs +4 -3
  137. package/tools/source-size-report.mjs +41 -13
  138. package/tools/spec-check-cli.mjs +159 -21
  139. package/tools/spec-check-ops.mjs +74 -5
  140. package/tools/spec-check.mjs +54 -45
  141. package/tools/spec-coverage-cli.mjs +3 -2
  142. package/tools/stage-render/cli.mjs +231 -0
  143. package/tools/stage-render/index.mjs +340 -0
  144. package/tools/stage-render/stages.json +115 -0
  145. package/tools/stage-write-guard/cli.mjs +64 -0
  146. package/tools/stage-write-guard/index.mjs +56 -0
  147. package/tools/state-block-hook.mjs +38 -163
  148. package/tools/task-brief.mjs +8 -13
  149. package/tools/task-thread.mjs +3 -1
  150. package/tools/tier-guide-facts.mjs +23 -9
  151. package/tools/tier-preview.mjs +15 -19
  152. package/tools/transition/index.mjs +10 -9
  153. package/tools/uninstall.mjs +26 -12
  154. package/tools/vehicle-settings.mjs +2 -1
  155. package/tools/velocity-profile.mjs +5 -6
  156. package/tools/view-model.mjs +7 -4
  157. package/tools/worktree-prompt.mjs +7 -3
  158. package/tools/worktrees.mjs +235 -159
  159. package/tools/write-lanes.mjs +20 -14
@@ -0,0 +1,314 @@
1
+ #!/usr/bin/env node
2
+ // stage-write-guard.mjs — the kit's PreToolUse stage write guard, placed at .claude/hooks/stage-write-guard.mjs
3
+ // (docs/ai/specs/kit/stage-write-guard.md). Self-contained: node: modules only, no effect unless run as the hook.
4
+
5
+ import { spawnSync } from 'node:child_process';
6
+ import { closeSync, constants as fsConstants, fstatSync, lstatSync, openSync, readFileSync, readlinkSync, realpathSync } from 'node:fs';
7
+ import { homedir } from 'node:os';
8
+ import { basename, dirname, extname, isAbsolute, join, relative, resolve, sep } from 'node:path';
9
+ import { fileURLToPath } from 'node:url';
10
+
11
+ // generated from agent-workflow-memory/references/scripts/shared/locations.mjs and agent-workflow-kit/tools/stage-render/ (index.mjs, stages.json) by scripts/sync-mirrors.mjs; do not edit
12
+ const DOCS = "docs";
13
+ const DOCS_TREE = "docs/ai";
14
+ const PLANS = "docs/plans";
15
+ const ORCHESTRATION = "docs/ai/orchestration.json";
16
+ const STAGE_GUARD_HOOK = ".claude/hooks/stage-write-guard.mjs";
17
+ const STAGE_RECORD_BASENAME = "agent-workflow-stage.json";
18
+ const SLOT_FILE_NAME = "next-session.json";
19
+ const RENDER_LINE = "node <kit>/tools/stage-render/cli.mjs docs/plans/next-session.json";
20
+ const STAGE_IDS = ["epic","design-consult","spec-and-plan","waiting-on-approval","tests","code","diff-review","split-modules","split-edits","pause","empty-queue"];
21
+ // end of the generated locations
22
+
23
+ const PATH_FIELDS = Object.freeze({ Write: 'file_path', Edit: 'file_path', MultiEdit: 'file_path', NotebookEdit: 'notebook_path' });
24
+ const HOOK_EVENT_NAME = 'PreToolUse';
25
+ const DENY = 'deny';
26
+ const UTF8 = 'utf8';
27
+
28
+ const GIT = 'git';
29
+ const GIT_ARGS = Object.freeze(['rev-parse', '--show-toplevel', '--absolute-git-dir']);
30
+ const GIT_COMMAND = [GIT, ...GIT_ARGS].join(' ');
31
+ const GIT_VARIABLE = /^git_/iu;
32
+ const GIT_ANSWERED_EXIT = 128;
33
+ const NOT_A_REPOSITORY = /^fatal: not a git repository\b/mu;
34
+ const NO_WORK_TREE = /^fatal: this operation must be run in a work tree\b/mu;
35
+ const GIT_OUTPUT_CEILING = 1024 * 1024;
36
+ const GIT_TIMEOUT_MS = 10_000;
37
+ const GIT_ANSWER_LINES = 3;
38
+ const STDERR_SHOWN = 200;
39
+
40
+ const RUN_TREE = 'tree';
41
+ const RUN_NONE = 'none';
42
+ const RUN_FAILED = 'failed';
43
+
44
+ const RECORD_SCHEMA = 1;
45
+ const RECORD_KEYS = Object.freeze(['schema', 'slotFile', 'stage', 'writes']);
46
+ const WRITES_ANY = 'any';
47
+ const WRITES_AUTHORING = 'authoring';
48
+ const JSON_STRING = /"(?:[^"\\]|\\.)*"/gu;
49
+ const FOLLOWED_BY_COLON = /^\s*:/u;
50
+ const READ_FLAGS = fsConstants.O_RDONLY | (fsConstants.O_NOFOLLOW ?? 0) | (fsConstants.O_NONBLOCK ?? 0);
51
+
52
+ const MARKDOWN = '.md';
53
+ const JSON_FILE = '.json';
54
+ const TEXT_FILE = '.txt';
55
+ const DOT_DOT = '..';
56
+ const RAW_SEGMENT_SEPARATOR = /[\\/]/u;
57
+ const CONFIG_HOME = '.claude';
58
+ const MEMORY_PROJECTS = 'projects';
59
+ const MEMORY_DIR = 'memory';
60
+ const HOST_PLANS = 'plans';
61
+ const MEMORY_NOTE_DEPTH = 4;
62
+ const HOST_PLAN_DEPTH = 2;
63
+
64
+ const GUARD_PREFIX = `stage guard (${STAGE_GUARD_HOOK})`;
65
+ const RENDER_SENTENCE = `code and tests are written only after the render of an approved plan's tests, code, split-edits or diff-review stage: ${RENDER_LINE}`;
66
+
67
+ const isPlainObject = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
68
+ const failed = (failure) => ({ kind: RUN_FAILED, failure });
69
+ const codeOf = (error) => error?.code ?? error?.message ?? String(error);
70
+
71
+ const lstatOrNull = (path) => {
72
+ try {
73
+ return lstatSync(path);
74
+ } catch (error) {
75
+ if (error?.code === 'ENOENT') return null;
76
+ throw error;
77
+ }
78
+ };
79
+
80
+ const realPathOf = (path) => {
81
+ try {
82
+ return realpathSync(path);
83
+ } catch (error) {
84
+ if (error?.code !== 'ENOENT') throw error;
85
+ }
86
+ const entry = lstatOrNull(path);
87
+ if (entry?.isSymbolicLink()) return realPathOf(resolve(dirname(path), readlinkSync(path)));
88
+ if (entry !== null) throw new Error(`${path}: present but without a real path`);
89
+ const parent = dirname(path);
90
+ if (parent === path) throw new Error(`${path}: no existing ancestor`);
91
+ return join(realPathOf(parent), basename(path));
92
+ };
93
+
94
+ const realOrNull = (path) => {
95
+ try {
96
+ return realpathSync(path);
97
+ } catch {
98
+ return null;
99
+ }
100
+ };
101
+
102
+ const deepestExisting = (path) => {
103
+ if (lstatOrNull(path) !== null) return path;
104
+ const parent = dirname(path);
105
+ if (parent === path) throw new Error(`${path}: no existing ancestor`);
106
+ return deepestExisting(parent);
107
+ };
108
+
109
+ const readNoFollow = (path) => {
110
+ const descriptor = openSync(path, READ_FLAGS);
111
+ try {
112
+ if (!fstatSync(descriptor).isFile()) throw new Error('not a regular file');
113
+ return new TextDecoder(UTF8, { fatal: true, ignoreBOM: true }).decode(readFileSync(descriptor));
114
+ } finally {
115
+ closeSync(descriptor);
116
+ }
117
+ };
118
+
119
+ const gitEnvOf = (env) => ({ ...Object.fromEntries(Object.entries(env).filter(([key]) => !GIT_VARIABLE.test(key))), LC_ALL: 'C' });
120
+
121
+ const readGitAnswer = (dir, stdout) => {
122
+ const lines = stdout.split('\n');
123
+ if (lines.length !== GIT_ANSWER_LINES || lines[2] !== '' || !lines.slice(0, 2).every((line) => isAbsolute(line))) {
124
+ return failed(`${GIT_COMMAND} in ${dir} answered no work tree and git directory`);
125
+ }
126
+ try {
127
+ const gitDir = realpathSync(lines[1]);
128
+ return { kind: RUN_TREE, root: realpathSync(lines[0]), gitDir, recordPath: join(gitDir, STAGE_RECORD_BASENAME) };
129
+ } catch (error) {
130
+ return failed(`${GIT_COMMAND} in ${dir} answered a path without a real path (${codeOf(error)})`);
131
+ }
132
+ };
133
+
134
+ const runGit = (dir, env) => {
135
+ const result = spawnSync(GIT, GIT_ARGS, {
136
+ cwd: dir, env: gitEnvOf(env), encoding: UTF8, maxBuffer: GIT_OUTPUT_CEILING, timeout: GIT_TIMEOUT_MS,
137
+ stdio: ['ignore', 'pipe', 'pipe'], windowsHide: true,
138
+ });
139
+ if (result.error) return failed(`${GIT_COMMAND} in ${dir} could not run (${codeOf(result.error)})`);
140
+ if (result.signal) return failed(`${GIT_COMMAND} in ${dir} was killed by ${result.signal}`);
141
+ if (result.status === 0) return readGitAnswer(dir, result.stdout);
142
+ const stderr = result.stderr ?? '';
143
+ if (result.status === GIT_ANSWERED_EXIT && (NOT_A_REPOSITORY.test(stderr) || NO_WORK_TREE.test(stderr))) return { kind: RUN_NONE };
144
+ return failed(`${GIT_COMMAND} in ${dir} exited ${result.status}: ${stderr.trim().slice(0, STDERR_SHOWN)}`);
145
+ };
146
+
147
+ const runsFor = (cwd, realTarget, env) => {
148
+ const targetDir = deepestExisting(dirname(realTarget));
149
+ const cwdRun = runGit(cwd, env);
150
+ return realOrNull(cwd) === targetDir ? [cwdRun] : [cwdRun, runGit(targetDir, env)];
151
+ };
152
+
153
+ const holdsDotDot = (rawPath) => rawPath.split(RAW_SEGMENT_SEPARATOR).includes(DOT_DOT);
154
+ const segmentsUnder = (base, path) => {
155
+ const rel = relative(base, path);
156
+ if (rel === '' || isAbsolute(rel)) return null;
157
+ const segments = rel.split(sep);
158
+ return segments[0] === DOT_DOT ? null : segments;
159
+ };
160
+
161
+ const configDirOf = (env) => {
162
+ const configured = env.CLAUDE_CONFIG_DIR;
163
+ if (typeof configured === 'string' && isAbsolute(configured)) return configured;
164
+ return join(typeof env.HOME === 'string' && isAbsolute(env.HOME) ? env.HOME : homedir(), CONFIG_HOME);
165
+ };
166
+
167
+ const isHarnessDocument = (rawPath, target, env) => {
168
+ try {
169
+ const realTarget = realPathOf(target);
170
+ if (holdsDotDot(rawPath) || extname(realTarget) !== MARKDOWN) return false;
171
+ const segments = segmentsUnder(realPathOf(configDirOf(env)), realTarget);
172
+ if (segments === null) return false;
173
+ return (segments.length === MEMORY_NOTE_DEPTH && segments[0] === MEMORY_PROJECTS && segments[2] === MEMORY_DIR)
174
+ || (segments.length === HOST_PLAN_DEPTH && segments[0] === HOST_PLANS);
175
+ } catch {
176
+ return false;
177
+ }
178
+ };
179
+
180
+ const isUnder = (rel, dir) => rel.startsWith(`${dir}/`);
181
+ const isCanonicalRel = (value) => value.split('/').every((segment) => segment !== '' && segment !== '.' && segment !== DOT_DOT);
182
+
183
+ const configuredPaths = (root) => {
184
+ try {
185
+ const flow = JSON.parse(readNoFollow(join(root, ORCHESTRATION)))?.flow;
186
+ if (!isPlainObject(flow)) return [];
187
+ return [flow.debtQueue, flow.convergenceSummary].filter((value) => typeof value === 'string' && !value.includes('\\')
188
+ && isCanonicalRel(value) && isUnder(value, DOCS) && extname(value) === MARKDOWN);
189
+ } catch {
190
+ return [];
191
+ }
192
+ };
193
+
194
+ const isProjectAuthoring = (root, realTarget) => {
195
+ const segments = segmentsUnder(root, realTarget);
196
+ if (segments === null) return false;
197
+ const rel = segments.join('/');
198
+ const extension = extname(rel);
199
+ if (isUnder(rel, DOCS_TREE) && (extension === MARKDOWN || extension === JSON_FILE)) return true;
200
+ if (isUnder(rel, PLANS) && (extension === MARKDOWN || extension === TEXT_FILE)) return true;
201
+ if (rel === `${PLANS}/${SLOT_FILE_NAME}`) return true;
202
+ return configuredPaths(root).includes(rel);
203
+ };
204
+
205
+ const memberNamesOf = (text) => [...text.matchAll(JSON_STRING)]
206
+ .filter((token) => FOLLOWED_BY_COLON.test(text.slice(token.index + token[0].length)))
207
+ .map((token) => JSON.parse(token[0]));
208
+
209
+ const isRecordShape = (record, text) => isPlainObject(record)
210
+ && memberNamesOf(text).sort().join() === RECORD_KEYS.join()
211
+ && record.schema === RECORD_SCHEMA
212
+ && (record.stage === null || STAGE_IDS.includes(record.stage))
213
+ && record.slotFile === `${PLANS}/${SLOT_FILE_NAME}`
214
+ && (record.writes === WRITES_ANY || record.writes === WRITES_AUTHORING);
215
+
216
+ const readRecord = (recordPath, entry) => {
217
+ if (!entry.isFile()) return { unreadable: entry.isSymbolicLink() ? 'a link' : 'not a regular file' };
218
+ try {
219
+ const text = readNoFollow(recordPath);
220
+ const record = JSON.parse(text);
221
+ return isRecordShape(record, text) ? { record } : { unreadable: 'not a stage record of schema 1' };
222
+ } catch (error) {
223
+ return { unreadable: codeOf(error) };
224
+ }
225
+ };
226
+
227
+ const presentRecords = (runs) => {
228
+ const trees = runs.filter(({ kind }) => kind === RUN_TREE);
229
+ return trees.filter((tree, index) => trees.findIndex(({ gitDir }) => gitDir === tree.gitDir) === index)
230
+ .flatMap((tree) => {
231
+ try {
232
+ const entry = lstatOrNull(tree.recordPath);
233
+ return entry === null ? [] : [{ tree, ...readRecord(tree.recordPath, entry) }];
234
+ } catch (error) {
235
+ return [{ tree, unreadable: codeOf(error) }];
236
+ }
237
+ });
238
+ };
239
+
240
+ const denial = (target, cause) => `${GUARD_PREFIX}: ${target} is refused: ${cause}; ${RENDER_SENTENCE}`;
241
+ const stageCause = ({ stage, slotFile }) => (stage === null
242
+ ? `the last render recorded no stage for slot file ${slotFile}, which writes only authoring documents`
243
+ : `the recorded stage ${stage} (slot file ${slotFile}) writes only authoring documents`);
244
+
245
+ const judgeRecord = (target, present, isAuthoring) => {
246
+ if (present.unreadable !== undefined) {
247
+ return isAuthoring() ? null : denial(target, `the stage record ${present.tree.recordPath} cannot be read (${present.unreadable})`);
248
+ }
249
+ if (present.record.writes === WRITES_ANY || isAuthoring()) return null;
250
+ return denial(target, stageCause(present.record));
251
+ };
252
+
253
+ const judgeWrite = ({ rawPath, cwd }, target, harnessDocument, env) => {
254
+ const realTarget = realPathOf(target);
255
+ const runs = runsFor(cwd, realTarget, env);
256
+ const failure = runs.find(({ kind }) => kind === RUN_FAILED);
257
+ if (failure !== undefined) return harnessDocument ? null : denial(target, failure.failure);
258
+ const present = presentRecords(runs);
259
+ const landing = runs.at(-1);
260
+ const isAuthoring = () => harnessDocument
261
+ || (!holdsDotDot(rawPath) && landing.kind === RUN_TREE && isProjectAuthoring(landing.root, realTarget));
262
+ return present.map((record) => judgeRecord(target, record, isAuthoring)).find((reason) => reason !== null) ?? null;
263
+ };
264
+
265
+ const decideWrite = (request, env) => {
266
+ const validCwd = typeof request.cwd === 'string' && isAbsolute(request.cwd);
267
+ const target = isAbsolute(request.rawPath) ? resolve(request.rawPath) : validCwd ? resolve(request.cwd, request.rawPath) : null;
268
+ const harnessDocument = target !== null && isHarnessDocument(request.rawPath, target, env);
269
+ try {
270
+ if (target === null || !validCwd) throw new Error('the payload names no absolute cwd');
271
+ return judgeWrite(request, target, harnessDocument, env);
272
+ } catch (error) {
273
+ return harnessDocument ? null : denial(target ?? request.rawPath, `the guard could not judge the write (${codeOf(error)})`);
274
+ }
275
+ };
276
+
277
+ const readWriteRequest = (text) => {
278
+ try {
279
+ const payload = JSON.parse(text);
280
+ if (!isPlainObject(payload) || !Object.hasOwn(PATH_FIELDS, payload.tool_name) || !isPlainObject(payload.tool_input)) return null;
281
+ const rawPath = payload.tool_input[PATH_FIELDS[payload.tool_name]];
282
+ return typeof rawPath === 'string' && rawPath !== '' ? { rawPath, cwd: payload.cwd } : null;
283
+ } catch {
284
+ return null;
285
+ }
286
+ };
287
+
288
+ const formatDeny = (reason) => JSON.stringify({
289
+ hookSpecificOutput: { hookEventName: HOOK_EVENT_NAME, permissionDecision: DENY, permissionDecisionReason: reason },
290
+ });
291
+
292
+ const readStdin = async () => {
293
+ const chunks = [];
294
+ for await (const chunk of process.stdin) chunks.push(chunk);
295
+ return Buffer.concat(chunks).toString(UTF8);
296
+ };
297
+
298
+ const main = async () => {
299
+ const request = readWriteRequest(await readStdin().catch(() => ''));
300
+ if (request === null) return;
301
+ const reason = decideWrite(request, process.env);
302
+ if (reason !== null) process.stdout.write(`${formatDeny(reason)}\n`);
303
+ };
304
+
305
+ const isDirectRun = (() => {
306
+ const invoked = process.argv[1];
307
+ if (!invoked) return false;
308
+ try {
309
+ return realpathSync(invoked) === realpathSync(fileURLToPath(import.meta.url));
310
+ } catch {
311
+ return false;
312
+ }
313
+ })();
314
+ if (isDirectRun) main().catch(() => {});
@@ -3,7 +3,7 @@
3
3
  <!-- opt-in-capability: agents -->
4
4
  <!-- opt-in-capability: executor-vehicle -->
5
5
 
6
- The opt-in **subagent-vehicle writer** — the family's second `.claude/` writer, on the velocity discipline. It places the **five** bundled subagent definitions (`references/agents/*.md`) into the project's `.claude/agents/`: **four read-only vehicles** and **one** full-tool `executor`. **Claude-Code-specific** (like velocity): other agent hosts ignore `.claude/agents/`.
6
+ The opt-in **subagent-vehicle writer** — the family's second `.claude/` writer, on the velocity discipline. It places the bundled subagent definitions (`references/agents/*.md`) into the project's `.claude/agents/`: **four read-only vehicles**, the no-shell `author` and **one** full-tool `executor`. **Claude-Code-specific** (like velocity): other agent hosts ignore `.claude/agents/`.
7
7
 
8
8
  **Every READ-ONLY vehicle grants READ-ONLY tools and NO `Bash`** — that is the load-bearing property, not a detail. A read-only fan-out on a full-tool vehicle shells out for facts it could have read, and each shelled command is an approval prompt the maintainer never needed to see; a vehicle with no shell structurally cannot do that. Two lanes ride on it:
9
9
 
@@ -12,11 +12,13 @@ The opt-in **subagent-vehicle writer** — the family's second `.claude/` writer
12
12
 
13
13
  Writing code, running gates, and user-facing copy never move to these four vehicles.
14
14
 
15
- **The fifth vehicle, `executor`, is the ONE full-tool one** (model and effort from `docs/ai/vehicles.json` — `opus` / `high` by default — and every tool, a shell included). It is the instrument behind the **Subagent** recipe, dispatched ONLY for a **bounded, file-disjoint slice** the orchestrator verifies afterwards by running its suites: a slice of execution (`plan-execution.execute`), a plan/contract authoring brief (`plan-authoring.author`), an authoring-round fold (`plan-authoring.fold`), a bounded chore (`routine.carrier`), an epic brief (`epic.author`), or one prompt the orchestrator wrote from one ledger row, run inside its Files (`task.execute`); `task.author` dispatches no slice, since the orchestrator writes each row's prompt itself. It **never commits** (no git write at all), is **never a review backend**, is **never a bridge substitute**, and is **never dispatched for read-only work** — a sweep, an inventory or a review rides a read-only vehicle instead.
15
+ **The `executor` is the ONE full-tool vehicle** (model and effort from `docs/ai/vehicles.json` — `opus` / `high` by default — and every tool, a shell included). It is the instrument behind the **Subagent** recipe for carry slots, dispatched ONLY for a **bounded, file-disjoint slice** the orchestrator verifies afterwards by running its suites: a slice of execution (`plan-execution.execute`), a write-capable chore (`routine.carrier`), or one prompt the orchestrator wrote from one ledger row, run inside its Files (`task.execute`); `task.author` dispatches no slice, since the orchestrator writes each row's prompt itself. It **never commits** (no git write at all), is **never a review backend**, is **never a bridge substitute**, and is **never dispatched for read-only work** — a sweep, an inventory or a review rides a read-only vehicle instead.
16
16
 
17
- **Its readiness is the vehicle FILE.** `surveyExecutorVehicle` answers exactly one of four states: **`placed`** (bytes equal to the body derived from `docs/ai/vehicles.json` at `.claude/agents/executor.md`), **`customized`** (a readable regular file whose frontmatter names `executor` and whose tools are not read-only), **`unusable`** (a symlink, a non-regular or unreadable file, one failing that check, or an unreadable `docs/ai/vehicles.json` — with the reason), **`missing`**. `placed` and `customized` are dispatchable; on `unusable` or `missing` a `subagent` slot **degrades to Solo** with a reason naming this mode's apply command (and `docs/ai/vehicles.json` when that file is unreadable). `/agent-workflow-kit status` shows the state in its `agents` block and the deployment advisor raises it when a configured slot names `subagent` and the vehicle is `unusable` or `missing` — that item is **`executor-vehicle`** (attention-class: a configured declaration that is broken). It yields to the `agents` key's `agents.not-current`, which writes the executor in a placed component — a regular executor whose bytes differ, the check failing or not — so the two never render for one tree; over a component not placed the `agents` offer places the executor and `executor-vehicle` names the solo degrade beside it. It is a claim about the FILE, never about the host: a Claude Code lane, like this mode itself.
17
+ **The author vehicle** (`author`, `opus` / `high`) has `Read, Grep, Glob, Write, Edit` and no shell. It drafts a plan or a contract from the orchestrator's brief (`plan-authoring.author`), folds a round's findings into that plan or contract (`plan-authoring.fold`) or drafts the epic file from its brief (`epic.author`); the orchestrator reviews the returned draft as its own. It never runs commands, writes code or tests, serves as a reviewer or commits.
18
18
 
19
- **Every kit agent file is written current with no question.** The kit agent files are the five bundled names and every configured roster-derived lens `review-lens-<model>-<effort>.md`; an absent one is placed, one whose bytes differ is written with the body the kit writes for it, no copy kept, and a current one is left. Every other file under `.claude/agents/` is yours and no kit tool writes it: a vehicle of your own goes in `.claude/agents/<name>.local.md` with a `name:` of its own (Claude Code knows a subagent by its `name:` alone).
19
+ **Readiness is the vehicle FILE.** `surveyExecutorVehicle` answers exactly one of four states: **`placed`** (bytes equal to the body derived from `docs/ai/vehicles.json` at `.claude/agents/executor.md`), **`customized`** (a readable regular file whose frontmatter names `executor` and whose tools are not read-only), **`unusable`** (a symlink, a non-regular or unreadable file, one failing that check, or an unreadable `docs/ai/vehicles.json` — with the reason), **`missing`**. `placed` and `customized` are dispatchable; on `unusable` or `missing` a carry slot set to `subagent` **degrades to Solo** with a reason naming this mode's apply command (and `docs/ai/vehicles.json` when that file is unreadable). `surveyAuthorVehicle` answers `placed` (bytes at `.claude/agents/author.md` equal to the bundled template), `stale` (differing bytes with one tools line naming only the five tools), `widened` (other differing bytes, naming the tool or the absent, empty or repeated tools line), `unusable` (a link, non-regular or unreadable path or missing bundle template, with the reason), or `missing`. Only `placed` is ready; otherwise the author slot resolves to Solo naming the author vehicle and this mode's apply command. `/agent-workflow-kit status` shows both states in its `agents` block; the deployment advisor raises **`executor-vehicle`** (attention: a configured declaration that is broken) when a slot names `subagent` and its role's vehicle is not ready. It yields to `agents.not-current`, which writes missing or differing regular kit agent files in a placed component, including a regular executor whose bytes differ, the check failing or not. Over a component not placed, the `agents` offer places the vehicles and `executor-vehicle` names the solo degrade beside it. Readiness is a claim about the FILE, never the host: Claude Code loads agent files at session start, so a placed or rewritten author vehicle acts from the next session. Dispatch only when this session's agent list shows `author` with exactly the five tools; otherwise carry the slice solo and say so, never on another subagent.
20
+
21
+ **Every kit agent file is written current with no question.** The kit agent files are the bundled names and every configured roster-derived lens `review-lens-<model>-<effort>.md`; an absent one is placed, one whose bytes differ is written with the body the kit writes for it, no copy kept, and a current one is left. Every other file under `.claude/agents/` is yours and no kit tool writes it: a vehicle of your own goes in `.claude/agents/<name>.local.md` with a `name:` of its own (Claude Code knows a subagent by its `name:` alone).
20
22
 
21
23
  Run `node ${CLAUDE_SKILL_DIR}/tools/cheap-agents.mjs [--dry-run | --apply] [--cwd <dir>]`:
22
24
 
@@ -26,7 +26,7 @@ Requires: ${CLAUDE_SKILL_DIR}/references/shared/report-footer.md · ${CLAUDE_SKI
26
26
  5. **Entry-point doc.** If `AGENTS.md` / `CLAUDE.md` already exist (step-1 recon), do **not** overwrite — show the user and ask whether to merge or replace. Otherwise create `AGENTS.md` (the cross-agent standard — Codex / Cursor / Devin Desktop / Copilot read it natively) from `${CLAUDE_SKILL_DIR}/references/templates/AGENTS.md`, and symlink `CLAUDE.md -> AGENTS.md` (`ln -s AGENTS.md CLAUDE.md`) for Claude Code — single source, no duplication. For nested context, add a subdir `AGENTS.md` (+ a `CLAUDE.md` symlink beside it for Claude Code).
27
27
  6. **Deploy `docs/ai/`.** Create every `docs/ai/` file + `pages/` + the seed `adr/` store + the seed `specs/` store from `${CLAUDE_SKILL_DIR}/references/templates/` (the template loop deploys every template except `AGENTS.md`, `adr-record.md` and `SPEC_TEMPLATE.md` — the latter two are skill-home authoring references, never deployed). This deploys the HOT ADR window **`docs/ai/decisions.md`** and the seed navigator **`docs/ai/adr/log.md`** (its `adr/` subdir copies in wholesale), the spec store root **`docs/ai/specs/index.md`** (its `specs/` subdir copies in wholesale), the `.md` docs, **and** the four seeded, user-editable strict-JSON configs: **`docs/ai/orchestration.json`** (the per-project recipe defaults the `procedures` advisor reads), **`docs/ai/gates.json`** (the project's gate declaration — seeded as the no-consent EMPTY list; FILLING it is the consented `gates-init` preview, `${CLAUDE_SKILL_DIR}/references/modes/gates.md`), **`docs/ai/autonomy.json`** (the per-project autonomy policy — seeded SPARSE with the onboarding note only, so it is exactly the computed defaults until the user declares levels via `/agent-workflow-kit set-autonomy` or by hand), and **`docs/ai/vehicles.json`** (the executor vehicle's model, effort and fallback as a setting the kit's readers resolve into one posture; the placed executor's body follows it, and the bundled review lens's model and effort, `opus` / `high` by default, follow its optional `review-lens` section — seeded once, hand-edited, never clobbered). Keep each `.md` file's frontmatter (`type / lastUpdated / scope / staleAfter / owner / maxLines`); the `.json` seeds carry no frontmatter (the docs cap-validator globs `*.md` only, so they are inherently skipped).
28
28
  7. **Fill templates** per the table below. **Then materialize the navigator, as the last `docs/ai` step:** the entry point declares `docs/ai/index.md` always-loaded and it is a GENERATED artifact with no template, so run `node ${CLAUDE_SKILL_DIR}/references/scripts/docs-size/check-docs-size.mjs --ensure-index --root=<project>` and relay its one outcome line (`ensure-index: regenerated` / `already-current`, or a `write-refused` / `probe-failed` line naming the offending path — either is a STOP: resolve it before reporting the deploy, since the navigator the entry point declares does not exist yet). The generator runs from **this skill's own directory**, so a project with **no Node runtime** is covered too: the agent host runs it, and step 8's copy is not a precondition.
29
- 8. **Offer enforcement on every project, preview-first.** Explain in one line that the dependency-free Node scripts are available because the agent host already runs their step-7 navigator; the only skip condition is that the agent host cannot run them. Run the `enforcement` item's check line, `node ${CLAUDE_SKILL_DIR}/tools/apply-danger-check.mjs --variant enforcement --cwd <project>`: its result is the preview — each script the kit places into the kit folder `scripts/agent-workflow/` with its bytes and the installer it runs with its bytes. Ask once on that result; on a yes copy them by its apply line with that digest, run by the consent route of `${CLAUDE_SKILL_DIR}/references/modes/recommendations.md`: the copy is create-only and the project's installer installs the pre-commit hook. On a no, skip the hook and say so; a check that refuses (exit 1 or 3) or an apply that exits 6 leaves no script the kit placed — say so with its output and fill the command slots as on a no. On a no the docs command slots name no project-local command — fill `env_commands.md` and the `Docs caps + index freshness` row of `AGENTS.md` with the same note: the caps + index gate run from the agent's own skill copy (the step-7 `--root=<project>` form) and the archive rotations need the scripts deployed. Never write the skill's absolute path into a deployed doc. They self-configure (project name from `package.json` or, without one, the directory basename; hierarchical/on-demand sections auto-discovered). The hook calls `node scripts/agent-workflow/run.mjs <name>` directly, so a committer without `node` on PATH gets the hook's own loud failure.
29
+ 8. **Offer enforcement on every project, preview-first.** Explain in one line that the dependency-free Node scripts are available because the agent host already runs their step-7 navigator; the only skip condition is that the agent host cannot run them. Run the `enforcement` item's check line, `node ${CLAUDE_SKILL_DIR}/tools/apply-danger-check.mjs --variant enforcement --cwd <project>`: its result is the preview — each script the kit places into the kit folder `scripts/agent-workflow/` with its own SHA-256 digest, and the installer command with one SHA-256 digest that binds every deployed path to its file bytes or its absence. Ask once on that result; on a yes copy them by its apply line with the result's closing `digest:`, run by the consent route of `${CLAUDE_SKILL_DIR}/references/modes/recommendations.md`: the copy is create-only and the project's installer installs the pre-commit hook. On a no, skip the hook and say so; a check that refuses (exit 1 or 3) or an apply that exits 6 leaves no script the kit placed — say so with its output and fill the command slots as on a no. On a no the docs command slots name no project-local command — fill `env_commands.md` and the `Docs caps + index freshness` row of `AGENTS.md` with the same note: the caps + index gate run from the agent's own skill copy (the step-7 `--root=<project>` form) and the archive rotations need the scripts deployed. Never write the skill's absolute path into a deployed doc. They self-configure (project name from `package.json` or, without one, the directory basename; hierarchical/on-demand sections auto-discovered). The hook calls `node scripts/agent-workflow/run.mjs <name>` directly, so a committer without `node` on PATH gets the hook's own loud failure.
30
30
  9. **Wire / hide** per visibility (see [Visibility contract](${CLAUDE_SKILL_DIR}/references/contracts.md#visibility-contract)). The pre-commit hook is the installer's decision at step 8's apply; over a pre-commit hook the installer did not write, that apply exits 6 with the installer's output naming the hook, and moving it aside is the user's own step. Once the gate declaration is final-run-capable, the advisor's `commit-guard` item binds commits to the green `run-gates --final` receipt; it is applied the same way, its check line first.
31
31
  - **visible** — when a `package.json` exists and step 8's apply exited 0, wire its scripts (never create one for this); add the minimal `.gitignore` either way. **Do not run the hide tool.**
32
32
  - **hidden** — run the kit's hide writer (one managed block in the **project-local** `.git/info/exclude`, covering the kit's own artifacts **and** every known AI/agent tool's footprint — never the machine-global excludes): `node ${CLAUDE_SKILL_DIR}/tools/hide-footprint.mjs --dir <project> --dry-run` **first** (changes nothing, prints the plan), then the same without `--dry-run`. Handle what it surfaces, in plain language (never the tool's internal terms):
@@ -19,8 +19,9 @@ any byte in 0x00–0x08, 0x0B, 0x0C, 0x0E–0x1F or 0x7F refuses; TAB, LF and CR
19
19
  bytes; bytes at or above 0x80 are not judged (UTF-8 validity and C1 controls are not this tool's
20
20
  business). A finding names the path, the surface, the byte offset and the byte in hex; the render is
21
21
  injective — bytes decode as UTF-8 where valid, a control or line-separator code point (and a valid
22
- U+FFFD) renders as `\u{XXXX}`, an invalid byte as `\xNN`, a backslash as `\\` — so no output line carries a raw control
23
- byte or U+FFFD and two names differing only in an unrenderable byte render differently.
22
+ U+FFFD) renders as `\u{XXXX}`, an invalid byte as `\xNN`, a backslash as `\\` — so no line `main` returns carries a
23
+ raw control byte or U+FFFD (the guard's error block keeps the error's first line and stack as they are) and two
24
+ names differing only in an unrenderable byte render differently.
24
25
 
25
26
  **Binary by KIND, never by guess.** A path whose git attribute says `binary` or `-diff` has its
26
27
  CONTENT skipped by kind and is NAMED in the summary (one `git check-attr --stdin -z binary diff`
@@ -36,35 +37,40 @@ kind and counted — name judged, no content surface. On a host that materialise
36
37
  Run `node ${CLAUDE_SKILL_DIR}/tools/control-bytes.mjs [--check] [--cwd <dir>]` (`--cwd` anchors at
37
38
  that directory's work-tree root):
38
39
 
39
- 1. Plain run → the human report: the work-tree root, the counts (paths judged · skipped by attribute,
40
- each named · skipped by kind · findings), then every finding as one line
41
- `<path> <surface> offset <n>: 0x<hex>` (`(+N more)` when that surface carries more than one) —
42
- under the SAME exit table as `--check`: the plain run is never a silent 0.
43
- 2. **`--check`** → the gate spelling: the same report (counts, the named attribute skips, the
44
- finding lines), then the gate exit code. **Exit 0** clean. **Exit 1** on a finding OR on a refusal —
45
- refusals never pass and never skip silently, each with its own message: an UNREADABLE path
46
- (EACCES, EIO, a descriptor whose kind disagrees with the named kind — distinct from an ABSENT
47
- path git named that vanished before the read; a TRACKED absent path with the skip-worktree bit is
48
- a sparse checkout, skipped by kind and counted); a git command that fails, is killed by a signal or
49
- is not on PATH; an UNMERGED index; an EMPTY domain; a file over the read cap (16 MiB — read as at
50
- most cap+1 bytes on the descriptor, never trusting the fstat size, so a file that grows after the
51
- fstat still refuses; the message names the cap and the path); a git LOCATION that is not a work
52
- tree. The location is a closed table of six states shared with the fingerprint and index
53
- consumers through the kit's git-location leaf, judged on the REALPATH identity of the git dir,
54
- the common dir and the work-tree top under the ambient env against the discovery from cwd with
55
- every variable whose upper-cased name starts with `GIT_` removed (a case-insensitive host honours
56
- `git_dir` too): `work-tree` (all three agree) proceeds; `not-a-repository` (git
57
- itself answers not-a-git-repository, exit 128); `error` (ENOENT, a synchronous throw, a signal, a
58
- realpath that cannot resolve, any other non-zero or unparsable answer); `redirected` (any of the
59
- three differs — `GIT_WORK_TREE` at a second tree with the same git dir, or `GIT_COMMON_DIR` at a
60
- second repository); `no-work-tree` (the git
61
- dir agrees but `--show-toplevel` fails: bare, or cwd inside `.git`); `env-only` (the ambient env
62
- reaches a repository the stripped discovery does not) — each refuses by its own state name. A
63
- pre-commit hook's own env (`GIT_INDEX_FILE`, `GIT_PREFIX`, `GIT_CONFIG_PARAMETERS`,
64
- `GIT_EXEC_PATH`) agrees and passes: the check is agreement, never a variable ban. **Exit 2**
65
- usage — every operand is validated at parse; an unknown argument is usage. Every content read is
66
- descriptor-bound (open, fstat, read on the descriptor), never a path read that a symlink swap
67
- could redirect.
40
+ 1. Plain run → clean: the report (the work-tree root; paths judged · skipped by attribute · skipped by
41
+ kind · findings; one `skipped by attribute: <path>` line per such path). Red: ONE block on standard
42
+ output, nothing on standard error, under the SAME exit table as `--check` (never a silent 0): the
43
+ verdict line `control-bytes: FAIL —` naming each class present, with counts for control-byte findings
44
+ and paths not judged, each finding `<path>: <surface> offset <n>: 0x<hex>` (`(+N more)` for more), each
45
+ path not judged `<path>: <why>`, one `control-bytes: REMEDY —` line per class, then the report; the work
46
+ tree not judged stands alone (step 2: no count, nothing after its remedy). A path that is no plain place
47
+ (escaped, holding a colon, opening with a space, with an empty, `.` or `..` segment, equal to `control-bytes`, or matching the text before `: ` on a report line) stands at `.`, the path leading its text.
48
+ 2. **`--check`** → the gate spelling: the same output, then the gate exit code. **Exit 0** clean.
49
+ **Exit 1** on a finding OR on a refusal — refusals never pass and never skip silently, each with its
50
+ own message; a failed git query, an unmerged index, an empty domain or a location that is no work
51
+ tree is the work tree not judged: one finding at `.` carrying the message, one remedy line, nothing
52
+ after. The refusals: an UNREADABLE path (EACCES, EIO, a descriptor whose kind disagrees with the
53
+ named kind — distinct from an ABSENT path git named that vanished before the read; a TRACKED absent
54
+ path with the skip-worktree bit is a sparse checkout, skipped by kind and counted); a git command
55
+ that fails, is killed by a signal or is not on PATH; an UNMERGED index; an EMPTY domain; a file over
56
+ the read cap (16 MiB — read as at most cap+1 bytes on the descriptor, never trusting the fstat size,
57
+ so a file that grows after the fstat still refuses; the message names the cap and the path); a git
58
+ LOCATION that is not a work tree. The location is a closed table of six states shared with the
59
+ fingerprint and index consumers through the kit's git-location leaf, judged on the REALPATH identity
60
+ of the git dir, the common dir and the work-tree top under the ambient env against the discovery
61
+ from cwd with every variable whose upper-cased name starts with `GIT_` removed (a case-insensitive
62
+ host honours `git_dir` too): `work-tree` (all three agree) proceeds; `not-a-repository` (git itself
63
+ answers not-a-git-repository, exit 128); `error` (ENOENT, a synchronous throw, a signal, a realpath
64
+ that cannot resolve, any other non-zero or unparsable answer); `redirected` (any of the three
65
+ differs — `GIT_WORK_TREE` at a second tree with the same git dir, or `GIT_COMMON_DIR` at a second
66
+ repository); `no-work-tree` (the git dir agrees but `--show-toplevel` fails: bare, or cwd inside
67
+ `.git`); `env-only` (the ambient env reaches a repository the stripped discovery does not) — each
68
+ refuses by its own state name. A pre-commit hook's own env (`GIT_INDEX_FILE`, `GIT_PREFIX`,
69
+ `GIT_CONFIG_PARAMETERS`, `GIT_EXEC_PATH`) agrees and passes: the check is agreement, never a variable
70
+ ban. **Exit 2** usage — every operand is validated at parse; an unknown argument is usage: the verdict
71
+ line names what was wrong, then the usage text. An error the tool does not answer for prints the
72
+ guard's block (the verdict line naming the error, the remedy line, the stack), exit 1. Every content
73
+ read is descriptor-bound (open, fstat, read on the descriptor), never a path a symlink swap redirects.
68
74
  3. **Declare it as a gate — never without consent (AD-021/D9).** `node
69
75
  ${CLAUDE_SKILL_DIR}/tools/checker-gates.mjs --cwd <project> --only control-bytes --apply` writes
70
76
  this one entry while the kit offers it; without `--only control-bytes --apply` the same command
@@ -79,7 +85,7 @@ that directory's work-tree root):
79
85
  **Honest bounds (stated, accepted):** the work tree is judged at the moment of the read — a byte
80
86
  written after the run is caught on the next run, which is why the gate belongs in the pre-commit
81
87
  matrix; the attribute is the only "binary" signal, so a binary file with no attribute refuses until
82
- the project declares it; the tool reports and never edits — the remedy is the escape in source; a
88
+ the project declares it; the tool reports and never edits; a
83
89
  checkout PATH that is itself not valid UTF-8 is unreachable by any Node consumer (cwd is a string
84
90
  before git ever answers) and a non-UTF-8 LINKED git dir or common dir path refuses as `error` — a
85
91
  stated bound, not a case this tool judges; `O_NOFOLLOW` guards the
@@ -28,7 +28,15 @@ Run **`node ${CLAUDE_SKILL_DIR}/tools/flow-writer.mjs <arm> …`** — the arm s
28
28
 
29
29
  `round-open` mints the round record BEFORE any backend runs — per `--backend` a fresh nonce + receipts watermark; stdout prints one `dispatch backend=<b> nonce=<n> watermark=<w>` line per dispatch (pass the nonce as `--nonce <n>` on the wrapper invocation — the plain-argument lane onto the `AW_REVIEW_NONCE` seam; hand the pair to `receipt-deadline`).
30
30
 
31
- Every round after the first requires an authoritative walk-carrying attestation at the preceding round's `{planId, cycle, stepId, round}` and the CURRENT tree's `{base, fingerprint}` when the adopted plan has a judgeable ledger row; `--justification` may lift that absence as an echoed input, and the ABSENCE of the attestation is its durable trail. At `cap reached` or `crossover`, every blocking item from the latest head's landed receipts must be covered by equal item digest: uncovered items print verbatim, enumeration failure is an advisory plus the existing disposition floor, and a lost manifest is covered only by `custody-lost`; this cap refusal is never lifted by `--justification`.
31
+ An adopted plan owes a walk when its structural judgment finds a valid row or `retired-size-field`.
32
+ For such a plan every round after the first requires an authoritative walk-carrying attestation at
33
+ the preceding round's `{planId, cycle, stepId, round}` and the CURRENT tree's `{base, fingerprint}`.
34
+ The missing-walk refusal names `retired-size-field` when present. `--walk` names the blocking
35
+ structural codes when it refuses the plan. `--justification` may lift a missing walk as an echoed
36
+ input, and the absence of the attestation is its durable trail. At `cap reached` or `crossover`, every
37
+ blocking item from the latest head's landed receipts must be covered by equal item digest: uncovered
38
+ items print verbatim, enumeration failure is an advisory plus the existing disposition floor, and a
39
+ lost manifest is covered only by `custody-lost`; this cap refusal is never lifted by `--justification`.
32
40
 
33
41
  Both lock-free and locked `round-open` checks run cap → walk → completeness floor. Boundary invocations need `--step`; `--new-cycle` opens the next cycle; a fingerprint move opens a new round.
34
42
 
@@ -40,7 +48,7 @@ For `round-land`, exactly one fresh code-artifact non-probe line of the dispatch
40
48
 
41
49
  Operand shapes: a positional operand may follow a literal `--` and a value flag accepts `--flag=<value>` — the lanes a leading-dash id or value rides; the checker's printed recoveries compose exactly these shapes. Every arm computes its **tree context** (owner, base, fingerprint; cycle/round from the chain walk) — you never hand-supply tree identity. Chain arms **refuse a foreign worktree's chain** (#57): move a chain only from the worktree that adopted it.
42
50
 
43
- **Round-machinery caps (enforced at the arms; the store owns transition legality):** HARD_MAX **3 rounds per {cycle, step}** and **1 post-freeze unfreeze per cycle**. The walk obligation holds when the adopted plan's ledger parses with at least one valid row; a plan with no judgeable row owes no walk. Both lock-free and locked round-open checks run cap → walk → completeness floor. The justification predicate is `overCap || walkRefusalFired`: a non-empty justification lifts only a design-cap or missing-walk refusal and is echoed; an in-cap invocation with its walk satisfied refuses it as usage. The blocking-item cap is independent and never lifted. A `custody-lost` entry is recordable whenever the carrier loss is real. One-way door: records carrying `walk`, the queued proof trio, `escalated`, or `custody-lost` require kit >= 11 to read; pre-rung records remain valid.
51
+ **Round-machinery caps (enforced at the arms; the store owns transition legality):** HARD_MAX **3 rounds per {cycle, step}** and **1 post-freeze unfreeze per cycle**. The justification predicate is `overCap || walkRefusalFired`: a non-empty justification lifts only a design-cap or missing-walk refusal and is echoed; an in-cap invocation with its walk satisfied refuses it as usage. The blocking-item cap is independent and never lifted. A `custody-lost` entry is recordable whenever the carrier loss is real. One-way door: records carrying `walk`, the queued proof trio, `escalated`, or `custody-lost` require kit >= 11 to read; pre-rung records remain valid.
44
52
 
45
53
  **Exit codes:** `0` success (incl. the `write-plan-id` idempotent no-op); `2` usage; `1` refusal (a store STOP verbatim, a derivation failure, or the missing checkpoint flag).
46
54
 
@@ -2,6 +2,7 @@
2
2
 
3
3
  <!-- opt-in-capability: gate-hook -->
4
4
  <!-- opt-in-capability: read-lane -->
5
+ <!-- opt-in-capability: stage-guard -->
5
6
 
6
7
  The opt-in **gate-approval PreToolUse hook** — the family's third `.claude/` writer (velocity discipline), and the shipped closure of the velocity trust-posture residual (**AD-021 scope C, probe-proven in AD-037**). It places a **self-contained** hook runtime at `.claude/hooks/agent-workflow-gates.mjs` (no kit imports — it keeps working if the kit is uninstalled) and wires ONE `PreToolUse` `"Bash"` entry into `.claude/settings.json`. Per Bash call the hook then walks a decision ladder, first match wins:
7
8
 
@@ -41,4 +42,6 @@ Run `node ${CLAUDE_SKILL_DIR}/tools/gate-hook.mjs [--dry-run | --apply] [--cwd <
41
42
 
42
43
  **Exit codes:** `0` done / dry-run; `1` a precondition STOP; `2` bad arguments.
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`.
45
+ **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 takes from `gate-hook.mjs` through the kit's hook writer `tools/hook-writer/index.mjs`.
46
+
47
+ **The kit's third hook.** The stage write guard (`.claude/hooks/stage-write-guard.mjs`) is a `PreToolUse` hook on the edit tools (`Write|Edit|MultiEdit|NotebookEdit`) that refuses a write outside the authoring documents while the stage last rendered writes no code — a deny, never a prompt or an approval. Its writer is `tools/stage-write-guard/cli.mjs`, running on the same hook writer (the advisor's `stage-guard` offer, and over a wired guard the kit item `stage-guard.not-current`); this mode neither places nor wires it.
@@ -15,7 +15,7 @@ The four blocks keep this order:
15
15
  3. **QUEUE** — every work-carrying row (live, parked, ambiguous) under the full line-numbered heading path it carries, with per-class counts covering every row of the bucket, terminal and record included, and names rather than ids. Only a path through `## Pending / backlog` calls its position priority; every other bucket is archive and calls it position.
16
16
  4. **CAMPAIGN** — source-size config state (`absent`, `authored`, `minted`), caps, roots and recorded over-cap files. An absent opt-in config is a rendered state.
17
17
 
18
- Evidence alone sets a ledger status: the row's path and verb, then the path fact, changed set and exclusion fact. The plan's prose never sets a status. A checked box or terminal marker is only a claim; when evidence contradicts it, print the claim beside the evidence-derived status. Keep anomaly and current red-proof annotations beside the same status too. Every status line names its evidence source.
18
+ Evidence alone sets a ledger status: the row's path and verb, then the path fact, changed set and exclusion fact. The plan's prose never sets a status. A checked box or terminal marker is only a claim; when evidence contradicts it, print the claim beside the evidence-derived status. Keep current red-proof annotations beside the same status too. Every status line names its evidence source.
19
19
 
20
20
  A block that cannot be derived is `WITHHELD` and prints its cause on one line. NOW has two halves, plans and tree, each independently a value or `WITHHELD`; NOW itself is `WITHHELD` only when both are. Render every other block normally.
21
21