@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
@@ -12,6 +12,8 @@
12
12
 
13
13
  import { closeSync, constants as fsConstants, fstatSync, lstatSync, openSync, readSync, readlinkSync, realpathSync, statSync } from 'node:fs';
14
14
  import { spawnSync } from 'node:child_process';
15
+ import { composeUsageRefusal } from '../references/scripts/shared/index.mjs';
16
+ import { composeCheckerBlock, runCheckerTail } from './checker-block/index.mjs';
15
17
  import { isDirectRun } from './direct-run.mjs';
16
18
  import { probeRegularFileNoFollow, readFileBytesNoFollowCapped } from './fs-read-nofollow.mjs';
17
19
  import { GIT_MAX_BUFFER, parseIndexEntries, resolveGitLocation, withGitPath } from './git-env.mjs';
@@ -36,15 +38,25 @@ const USAGE = `usage: node control-bytes.mjs [--check] [--cwd <dir>]
36
38
  --check the gate spelling; the plain run prints the same report and shares the exit table
37
39
  exit 0 clean · 1 a finding or a refusal · 2 usage`;
38
40
 
41
+ const CHECKER_NAME = 'control-bytes';
42
+ const WORK_TREE_REMEDY = 'clear the cause the finding above names, then re-run';
43
+ const CONTROL_BYTE_REMEDY = 'rename each path whose name contains a refused byte, retarget each symlink whose target contains a refused byte, replace every refused byte in text content with an escape in source, and mark any affected binary file binary in .gitattributes, then re-run';
44
+ const PATH_REMEDY = 'settle each path above as its finding says, then re-run';
45
+ const UNEXPECTED_REMEDY = 'fix the cause the stack below names, then re-run';
46
+
39
47
  const NUL = Buffer.from([0]);
40
48
  const render = renderPathForDisplay;
41
49
  // Every DYNAMIC diagnostic (a location cause, git stderr, an fs error code, a user argument) rides
42
50
  // the same renderer as paths before it reaches a line — SAFE (never a raw byte or U+FFFD), while
43
51
  // injectivity is promised for NAMES only: a string-originated diagnostic folds invalid bytes first.
44
52
  const safe = (text) => render(Buffer.isBuffer(text) ? text : Buffer.from(String(text), 'utf8'));
45
- const refusalLine = (message) => `control-bytes: REFUSED — ${message}`;
46
- const absent = (path, tracked) => `${render(path)}: absent (${tracked ? 'tracked but missing from the work tree — stage the deletion with git rm or git add -A, or it' : 'git named it, it'} vanished before the read)`;
47
- const unreadable = (path, why) => `${render(path)}: unreadable (${safe(why)})`;
53
+ const refuseWorkTree = (root, text) => ({ code: 1, lines: composeCheckerBlock({
54
+ name: CHECKER_NAME, root, failed: 'the work tree could not be judged',
55
+ findings: [{ path: '.', text }], remedies: [WORK_TREE_REMEDY],
56
+ }) });
57
+ const pathFinding = (path, text) => ({ path: render(path), text });
58
+ const absent = (path, tracked) => pathFinding(path, `absent (${tracked ? 'tracked but missing from the work tree — stage the deletion with git rm or git add -A, or it' : 'git named it, it'} vanished before the read)`);
59
+ const unreadable = (path, why) => pathFinding(path, `unreadable (${safe(why)})`);
48
60
  const hexByte = (byte) => `0x${byte.toString(16).padStart(2, '0')}`;
49
61
  const errorCode = (err) => err?.code ?? err?.message ?? String(err);
50
62
 
@@ -123,34 +135,34 @@ export const main = (argv, deps = {}) => {
123
135
  const run = deps.spawn ?? spawnSync;
124
136
  const env = deps.env ?? process.env;
125
137
  const opts = parseArgs(argv, io);
126
- if (opts.error) return { code: 2, lines: [`control-bytes: usage — ${opts.error}`, USAGE] };
138
+ if (opts.error) return { code: 2, lines: composeUsageRefusal({ name: CHECKER_NAME, failed: opts.error, usage: USAGE }) };
127
139
  const cwd = opts.cwd ?? deps.cwd ?? process.cwd();
128
140
  const location = resolveGitLocation(cwd, { spawn: run, env, realpath: io.realpath });
129
- if (location.state !== 'work-tree') return { code: 1, lines: [refusalLine(`the git location is ${location.state} — ${safe(location.cause)}`)] };
141
+ if (location.state !== 'work-tree') return refuseWorkTree(cwd, `the git location is ${location.state} — ${safe(location.cause)}`);
130
142
  const top = location.top;
131
143
  const git = (args, input, ok) => gitQuery(run, args, { cwd: top, env, input }, ok);
132
144
  const tracked = git(TRACKED_ARGV);
133
- if (tracked.failure) return { code: 1, lines: [refusalLine(tracked.failure)] };
145
+ if (tracked.failure) return refuseWorkTree(top, tracked.failure);
134
146
  const entries = parseIndexEntries(tracked.stdout);
135
147
  const unmerged = entries.filter((e) => e.stage !== 0).length;
136
- if (unmerged > 0) return { code: 1, lines: [refusalLine(`the git index is UNMERGED (${unmerged} conflict-stage entr(ies)) — resolve the conflict, then re-run`)] };
148
+ if (unmerged > 0) return refuseWorkTree(top, `the git index is UNMERGED (${unmerged} conflict-stage entr(ies)) — resolve the conflict, then re-run`);
137
149
  const others = git(UNTRACKED_ARGV);
138
- if (others.failure) return { code: 1, lines: [refusalLine(others.failure)] };
150
+ if (others.failure) return refuseWorkTree(top, others.failure);
139
151
  const domain = [...entries.map((e) => ({ path: e.path, mode: e.mode })), ...splitZ(others.stdout).map((path) => ({ path, mode: null }))]
140
152
  .sort((a, b) => Buffer.compare(a.path, b.path));
141
- if (domain.length === 0) return { code: 1, lines: [refusalLine(`the domain is EMPTY — no tracked and no untracked-not-ignored path under ${render(Buffer.from(top))}`)] };
153
+ if (domain.length === 0) return refuseWorkTree(top, `the domain is EMPTY — no tracked and no untracked-not-ignored path under ${render(Buffer.from(top))}`);
142
154
  const attributes = git(ATTRIBUTES_ARGV, Buffer.concat(domain.flatMap((d) => [d.path, NUL])));
143
- if (attributes.failure) return { code: 1, lines: [refusalLine(attributes.failure)] };
155
+ if (attributes.failure) return refuseWorkTree(top, attributes.failure);
144
156
  const skipByAttribute = attributeSkips(attributes.stdout);
145
157
  // core.symlinks: exit 1 = unset = git's default (true); `false` = the host materialises a tracked
146
158
  // symlink as a regular file holding the target bytes — refusing it there would refuse forever.
147
159
  const symlinks = git(SYMLINKS_ARGV, undefined, [0, 1]);
148
- if (symlinks.failure) return { code: 1, lines: [refusalLine(symlinks.failure)] };
160
+ if (symlinks.failure) return refuseWorkTree(top, symlinks.failure);
149
161
  const symlinksMaterialised = symlinks.stdout.toString('utf8').trim() === 'false';
150
162
  // Sparse checkouts: a tracked path whose skip-worktree bit is set (`ls-files -v`, a tag that
151
163
  // uppercases to S — core-evidence's rule) may be ABSENT by design: a counted skip, never a refusal.
152
164
  const sparse = git(SPARSE_ARGV);
153
- if (sparse.failure) return { code: 1, lines: [refusalLine(sparse.failure)] };
165
+ if (sparse.failure) return refuseWorkTree(top, sparse.failure);
154
166
  const sparseSkip = new Set();
155
167
  for (const record of splitZ(sparse.stdout)) {
156
168
  if (record.length > 2 && String.fromCharCode(record[0]).toUpperCase() === 'S') sparseSkip.add(record.subarray(2).toString('hex'));
@@ -168,7 +180,7 @@ export const main = (argv, deps = {}) => {
168
180
  if (first === -1) first = i;
169
181
  count += 1;
170
182
  }
171
- if (first !== -1) findings.push(`${render(path)} ${surface} offset ${first}: ${hexByte(bytes[first])}${count > 1 ? ` (+${count - 1} more)` : ''}`);
183
+ if (first !== -1) findings.push(pathFinding(path, `${surface} offset ${first}: ${hexByte(bytes[first])}${count > 1 ? ` (+${count - 1} more)` : ''}`));
172
184
  };
173
185
  // An ABSENT path: a sparse (skip-worktree) tracked one is a counted skip; every other refuses.
174
186
  const settleAbsent = (path, tracked) => {
@@ -181,7 +193,7 @@ export const main = (argv, deps = {}) => {
181
193
  if (read.bytes) judge(read.bytes, surface, path);
182
194
  return true;
183
195
  }
184
- if (read.outcome === 'over-cap') refusals.push(`${render(path)}: over the read cap (${READ_CAP} bytes) — the gate read cap+1 bytes on the descriptor and stopped; ${surface === 'content' ? 'declare the path binary in .gitattributes or shrink it' : 'restore the link or shorten its target'}`);
196
+ if (read.outcome === 'over-cap') refusals.push(pathFinding(path, `over the read cap (${READ_CAP} bytes) — the gate read cap+1 bytes on the descriptor and stopped; ${surface === 'content' ? 'declare the path binary in .gitattributes or shrink it' : 'restore the link or shorten its target'}`));
185
197
  else if (read.outcome === 'absent') settleAbsent(path, tracked);
186
198
  else if (read.outcome === 'foreign') refusals.push(unreadable(path, `a ${read.className} where git named a ${named}`));
187
199
  else refusals.push(unreadable(path, read.code));
@@ -251,14 +263,25 @@ export const main = (argv, deps = {}) => {
251
263
  `control-bytes: work tree ${render(Buffer.from(top))}`,
252
264
  `paths judged: ${domain.length} · skipped by attribute: ${skippedByAttribute.length} · skipped by kind: ${skippedByKind} · findings: ${findings.length}`,
253
265
  ...skippedByAttribute.map((path) => `skipped by attribute: ${render(path)}`),
254
- ...findings,
255
- ...refusals.map(refusalLine),
256
266
  ];
257
- return { code: findings.length > 0 || refusals.length > 0 ? 1 : 0, lines };
267
+ const classes = [];
268
+ const remedies = [];
269
+ if (findings.length) {
270
+ classes.push(`${findings.length} control-byte finding(s)`);
271
+ remedies.push(CONTROL_BYTE_REMEDY);
272
+ }
273
+ if (refusals.length) {
274
+ classes.push(`${refusals.length} path(s) not judged`);
275
+ remedies.push(PATH_REMEDY);
276
+ }
277
+ if (!classes.length) return { code: 0, lines };
278
+ return { code: 1, lines: composeCheckerBlock({
279
+ name: CHECKER_NAME, root: top, failed: classes.join('; '),
280
+ findings: [...findings, ...refusals], remedies, after: lines,
281
+ }) };
258
282
  };
259
283
 
260
284
  if (isDirectRun(import.meta.url)) {
261
- const result = main(process.argv.slice(2));
262
- (result.code === 2 ? process.stderr : process.stdout).write(`${result.lines.join('\n')}\n`);
263
- process.exitCode = result.code;
285
+ runCheckerTail({ name: CHECKER_NAME, exitCode: 1, remedy: UNEXPECTED_REMEDY },
286
+ () => main(process.argv.slice(2)), process);
264
287
  }
@@ -1,11 +1,12 @@
1
1
  import { createHash } from 'node:crypto';
2
2
  import { lstatSync } from 'node:fs';
3
3
  import { join } from 'node:path';
4
+ import { COVERAGE_DECLARED } from '../../references/scripts/shared/index.mjs';
4
5
  import { classifyChangedPath } from '../changed-surface.mjs';
5
6
  import { isLineUnsafe } from '../source-size-refusal.mjs';
6
7
  import { readFileBytesNoFollow } from '../fs-read-nofollow.mjs';
7
8
 
8
- export const COVERAGE_DECLARED_REL = 'docs/ai/coverage-declared.json';
9
+ export const COVERAGE_DECLARED_REL = COVERAGE_DECLARED;
9
10
  export const DECLARED_REASON_MAX_BYTES = 300;
10
11
 
11
12
  const SHAPE = '{ "schema": 1, "_README"?: string, "entries": [{ "path": string, "reason": string }, ...] }';
@@ -1,20 +1,21 @@
1
1
  // coverage-producer.mjs — the kit's half of the shared coverage-producer vocabulary (spec
2
2
  // coverage-producer): the one command body the suite gate runs, the move list of the flag sets
3
3
  // earlier kits wrote, and the CLOSED predicate deciding whether a declared gate cmd actually WRITES
4
- // the lcov the canonical checker reads. A LEAF — imports nothing, so every consumer (gates-init,
5
- // gates-declaration, the advisor) decides through ONE predicate.
4
+ // the lcov the canonical checker reads. The region uses four imported location and command names.
5
+ // Every consumer decides through ONE predicate.
6
6
  // Dependency-free, Node >= 22. No side effects on import.
7
7
 
8
+ import { KIT_COMMAND, KIT_FOLDER } from '../references/scripts/shared/index.mjs';
9
+ import { UNIT_TESTS_NAME, UNIT_TESTS_REPORTER } from '../references/scripts/run.mjs';
10
+
8
11
  // coverage-producer canon >>> BEGIN drift-guarded region
9
- // Authored TWICE, byte-identically: in the memory substrate's references/scripts/migrate-gates.mjs
10
- // and in the composition root's tools/coverage-producer.mjs. Neither side imports the other — the
11
- // substrate is standalone and must not depend on the root, and the root must not import mirrored
12
- // bytes — so a TEXT drift guard beside the root's copy holds them equal. Edit BOTH, then re-run the
13
- // mirror sync.
12
+ // Authored twice, byte-identically. Each host imports the four names above this region, and neither
13
+ // imports the other. A text drift guard beside the kit's copy keeps the regions equal.
14
+ // Edit both copies, then sync the mirror.
14
15
  //
15
16
  // The ONE producer form the kit writes: the stable kit command's unit-tests name (spec kit-command) —
16
17
  // the Node test runner with the lcov reporter under AW_GIT_DIR and the kit test reporter on stdout.
17
- export const COVERAGE_PRODUCER_BODY = 'node scripts/agent-workflow/run.mjs unit-tests';
18
+ export const COVERAGE_PRODUCER_BODY = `node ${KIT_COMMAND} ${UNIT_TESTS_NAME}`;
18
19
 
19
20
  // The reporter flag sets earlier kits wrote after `node --test`, newest first, byte for byte: a MOVE
20
21
  // LIST the gate migration switches onto the body above, never read as a producer.
@@ -93,7 +94,7 @@ export const retiredProducerFormOf = (cmd) => {
93
94
  // unitTestsGuardFailure → the guard on every write of the body: run.mjs a regular file equal to `ownRun`, then the reporter
94
95
  // a regular file, every folder on the way a directory (lstat: a link fails); null, or the first failing path and kind,
95
96
  // worded by guardRemedy with the caller's upgrade.
96
- const GUARD_PATHS = Object.freeze(['scripts/agent-workflow/run.mjs', 'scripts/agent-workflow/test-reporter/reporter.mjs']);
97
+ const GUARD_PATHS = Object.freeze([KIT_COMMAND, `${KIT_FOLDER}/${UNIT_TESTS_REPORTER}`]);
97
98
  export const unitTestsGuardFailure = (projectDir, ownRun, { lstatSync, readFileSync }) => {
98
99
  for (const rel of GUARD_PATHS) {
99
100
  const parts = rel.split('/');
@@ -9,7 +9,8 @@
9
9
  // Pure (dependency-injectable validator + fs), dependency-free, Node >= 22.
10
10
 
11
11
  import { statSync } from 'node:fs';
12
- import { join, resolve } from 'node:path';
12
+ import { join, posix, resolve } from 'node:path';
13
+ import { AGENTS_FILE, DOCS_TREE, MEMORY_STAMP, RULES, WORKFLOW_STAMP } from '../references/scripts/shared/index.mjs';
13
14
  import { isDirectRun } from './direct-run.mjs';
14
15
  import { validateManifest, VALID } from './manifest/validate.mjs';
15
16
 
@@ -86,10 +87,10 @@ export const handoffPlan = (delegate) =>
86
87
  delegate
87
88
  ? {
88
89
  mode: 'delegate',
89
- memoryWrites: ['docs/ai/', 'AGENTS.md', 'docs/ai/.memory-version'],
90
+ memoryWrites: [`${DOCS_TREE}/`, AGENTS_FILE, MEMORY_STAMP],
90
91
  // The kit block and the rules themes run AFTER the substrate deploy, over memory's seed.
91
- kitWrites: ['AGENTS.md kit block', 'docs/ai/rules/ theme files', 'docs/ai/.workflow-version'],
92
- stampsPresent: ['.memory-version', '.workflow-version'],
92
+ kitWrites: [`${AGENTS_FILE} kit block`, `${RULES}/ theme files`, WORKFLOW_STAMP],
93
+ stampsPresent: [posix.basename(MEMORY_STAMP), posix.basename(WORKFLOW_STAMP)],
93
94
  memoryRaisesCommitGate: false,
94
95
  commitGate: 'kit-only-after-injection',
95
96
  }
@@ -98,8 +99,8 @@ export const handoffPlan = (delegate) =>
98
99
  memoryWrites: [],
99
100
  // Fallback ships the kit's OWN AGENTS.md; the kit block is written into it exactly as on the
100
101
  // delegate path, so both paths end with the same block.
101
- kitWrites: ['docs/ai/', 'AGENTS.md', 'AGENTS.md kit block', 'docs/ai/rules/ theme files', 'docs/ai/.workflow-version'],
102
- stampsPresent: ['.workflow-version'],
102
+ kitWrites: [`${DOCS_TREE}/`, AGENTS_FILE, `${AGENTS_FILE} kit block`, `${RULES}/ theme files`, WORKFLOW_STAMP],
103
+ stampsPresent: [posix.basename(WORKFLOW_STAMP)],
103
104
  memoryRaisesCommitGate: false,
104
105
  commitGate: 'kit-only-after-injection',
105
106
  };
@@ -80,7 +80,7 @@ const RAW_BACKENDS = [
80
80
  'codex-exec --resume-last [--nonce <n>] <plan-file|->',
81
81
  'codex-exec --resume <session-id> [--nonce <n>] <plan-file|->',
82
82
  ],
83
- receipt: "side effect — a NONCED run mints ONE exec receipt beside the delegation store: the dispatch nonce seam is the AW_DISPATCH_NONCE environment value or its plain-argument equivalent --nonce <n>, recognised ONLY before the prompt operand (after the operand or a literal '--' it is passthrough payload, never a flag), under the safe grammar [A-Za-z0-9._-]{1,64} — anything else, a duplicate, or a flag disagreeing with a non-empty env value refuses PRE-SPEND. The store directory resolves exactly as the kit's delegation store does: the dirname of an ABSOLUTE AW_DELEGATION_STORE (a relative one, or one ending in a path separator, refuses), else the git common dir. The artifact is agent-workflow-exec-receipt-<backendLength>-<backend>-<nonce>.json in two states: 'reserved' is written atomically and NO-CLOBBER immediately before the CLI runs — that write IS the nonce reservation, so a second dispatch on the same nonce, or an already-taken report name, refuses BEFORE any spend — and 'terminal' replaces it in place at exit. A nonced run also refuses pre-spend when no timeout/gtimeout binary can cap it (an accounted dispatch that cannot be capped can never honour the terminal-exit rule; a nonce-LESS run still warns and runs uncapped), when node is missing (the mint core), and when the prompt rides on stdin instead of a contract FILE — contractDigest is computed BY THIS WRAPPER from the dispatch file it was actually handed, so the kit can refuse a run that executed a different contract than the one it opened. That digest is taken from the SAME bytes already read as the prompt, never a second open of the path: two reads leave a window in which the file can be swapped, and the run would then execute one contract while its receipt claimed the digest of another. The header's own nonce must EQUAL the dispatch nonce — 'dispatch open' copies the nonce FROM the header, so a disagreeing --nonce could only reserve an identity no return would ever absorb, and it refuses pre-spend. A contract file edited BETWEEN 'dispatch open' and the run is caught at ABSORB by the contractDigest comparison, not pre-spend: the wrapper never reads the ledger, and that boundary is what the whole lane rests on. At exit the wrapper FIRST re-reads its reservation and verifies its own opaque owner token — a foreign owner refuses having published NOTHING, neither report nor receipt — THEN writes the delegate's final message atomically to agent-workflow-exec-report-<backendLength>-<backend>-<nonce>.txt, THEN re-verifies the owner and REPLACES the reservation with the terminal receipt {schema, kind, state, backend, nonce, owner, contractDigest, wrapperVersion, posture {model, effort, tier}, capS, killGraceS, sessionId, exitStatus, outcome, reportDigest, reportLength, timestamp}: the report is complete on disk before any artifact says the run arrived. capS and killGraceS are the cap the run ACTUALLY applied. outcome is the wrapper's own SUBSET of the ledger's vocabulary — exit 0 with a session id -> success, exit 0 without one -> missing-identity, ANY nonzero exit including the timeout codes 124 and 137 -> transport-failure; every orchestrator judgment is recorded at absorb time, never claimed here. The session id is captured BEFORE outcome branching, so a FAILED run records one too; in resume mode it is the validated resume id. FAIL-CLOSED, deliberately NOT the review lane's warn-only receipt: a publication that cannot complete exits nonzero with a DISTINCT status, and the message states only what the run can still prove. 70: the reservation could not be verified BEFORE any publication — NOTHING was published, not the report and not the receipt, and because the artifact found there belongs to another run it is never a '--no-receipt' source. 71: a publication stopped after that point — either the report write failed (nothing beyond the reservation was published; the '--no-receipt' absorb then records reportLength 0, ineligible by the name empty-report) or the report IS on disk and the terminal receipt was not completed (the absorb reads it, report-if-present). The post-report lane never claims the reservation still stands, because after that point its fate is no longer something this run observed. Every lane names the tree as partial/dirtied rather than untouched. A nonce-LESS invocation is byte-unchanged: no reservation, no receipt, no artifact, and it needs no node.",
83
+ receipt: "side effect — a NONCED run mints ONE exec receipt beside the delegation store: the dispatch nonce seam is the AW_DISPATCH_NONCE environment value or its plain-argument equivalent --nonce <n>, recognised ONLY before the prompt operand (after the operand or a literal '--' it is passthrough payload, never a flag), under the safe grammar [A-Za-z0-9._-]{1,64} — anything else, a duplicate, or a flag disagreeing with a non-empty env value refuses PRE-SPEND. The store directory resolves exactly as the kit's delegation store does: the dirname of an ABSOLUTE AW_DELEGATION_STORE (a relative one, or one ending in a path separator, refuses), else the git common dir. The artifact is agent-workflow-exec-receipt-<backendLength>-<backend>-<nonce>.json in two states: 'reserved' is written atomically and NO-CLOBBER immediately before the CLI runs — that write IS the nonce reservation, so a second dispatch on the same nonce, or an already-taken report name, refuses BEFORE any spend — and 'terminal' replaces it in place at exit. A nonced run also refuses pre-spend when no timeout/gtimeout binary can cap it (an accounted dispatch that cannot be capped can never honour the terminal-exit rule; a nonce-LESS run still warns and runs uncapped), when node is missing (the mint core), and when the prompt rides on stdin instead of a contract FILE — contractDigest is computed BY THIS WRAPPER from the dispatch file it was actually handed, so the kit can refuse a run that executed a different contract than the one it opened. That digest is taken from the SAME bytes already read as the prompt, never a second open of the path: two reads leave a window in which the file can be swapped, and the run would then execute one contract while its receipt claimed the digest of another. The header's own nonce must EQUAL the dispatch nonce — 'dispatch open' copies the nonce FROM the header, so a disagreeing --nonce could only reserve an identity no return would ever absorb, and it refuses pre-spend. A contract file edited BETWEEN 'dispatch open' and the run is caught at ABSORB by the contractDigest comparison, not pre-spend: the wrapper never reads the ledger, and that boundary is what the whole lane rests on. At exit the wrapper FIRST re-reads its reservation and verifies its own opaque owner token — a foreign owner refuses having published NOTHING, neither report nor receipt — THEN writes the delegate's final message atomically to agent-workflow-exec-report-<backendLength>-<backend>-<nonce>.txt, THEN re-verifies the owner and REPLACES the reservation with the terminal receipt {schema, kind, state, backend, nonce, owner, contractDigest, wrapperVersion, posture {model, effort, tier}, capS, killGraceS, sessionId, exitStatus, outcome, reportDigest, reportLength, timestamp}: the report is complete on disk before any artifact says the run arrived. capS and killGraceS are the cap the run ACTUALLY applied. outcome is the wrapper's own SUBSET of the ledger's vocabulary — exit 0 with a session id -> success, exit 0 without one -> missing-identity, ANY nonzero exit including the timeout codes 124 and 137 -> transport-failure; every orchestrator judgment is recorded at absorb time, never claimed here. The session id is captured BEFORE outcome branching, so a FAILED run records one too; in resume mode it is the validated resume id. FAIL-CLOSED, deliberately NOT the review lane's warn-only receipt: a publication that cannot complete exits nonzero with a DISTINCT status, and the message states only what the run can still prove. 70: the reservation could not be verified BEFORE any publication — NOTHING was published, not the report and not the receipt, and because the artifact found there belongs to another run it is never a '--no-receipt' source. 71: a publication stopped after that point — either the report write failed (nothing beyond the reservation was published; the '--no-receipt' absorb then records reportLength 0, ineligible by the name empty-report) or the report IS on disk and the terminal receipt was not completed (the absorb reads it, report-if-present). The post-report lane never claims the reservation still stands, because after that point its fate is no longer something this run observed. Every lane names the tree as partial/dirtied rather than untouched. A nonced run also refuses pre-spend, reserving nothing, unless its contract file carries exactly one top-level aw-plan-approval block of exactly plan, approval and check whose check (the kit's tools/plan-approval/cli.mjs check <plan> --digest <approval>) exits 0, so a nonced run never starts unless the approval record matches the block's own plan and approval; the kit's tools/stage-render/cli.mjs --dispatch <plan> prints that block. A nonce-LESS invocation is byte-unchanged: no reservation, no receipt, no artifact, and it needs no node.",
84
84
  passthrough: {
85
85
  policy: 'guarded',
86
86
  blocked: ['-c*', '--config*', '-s*', '--sandbox*', '--dangerously-bypass-approvals-and-sandbox', '--dangerously-bypass-hook-trust', '--full-auto', '--oss', '--local-provider*', '-p*', '--profile*', '-m*', '--model*', '-o*', '--output-last-message*', '--json*', '--color*', '--output-schema*', '--ephemeral*'],
@@ -9,6 +9,7 @@ import { tmpdir } from 'node:os';
9
9
  import { join, dirname, basename, relative } from 'node:path';
10
10
  import { spawnSync } from 'node:child_process';
11
11
  import { createHash } from 'node:crypto';
12
+ import { MCP_FILE, PLANS, SETTINGS, SETTINGS_LOCAL } from '../references/scripts/shared/index.mjs';
12
13
  import { computeFingerprintPayload, isTreeClean, isNeverCommittableStat } from './core-evidence.mjs';
13
14
  import { KIT_OWN_PATHS, KNOWN_FOOTPRINT, patternToProbe, isDirPattern, expandGlob, isGlobPattern } from './known-footprint.mjs';
14
15
  import { GIT_MAX_BUFFER, resolveGitLocation, withGitPath } from './git-env.mjs';
@@ -17,7 +18,7 @@ const TEMP_PREFIX = 'aw-dispatch-baseline-';
17
18
  const INDEX_NAME = 'index';
18
19
  const HASH_ALGORITHM = 'sha256';
19
20
  const PAYLOAD_DIFF_ARGS = ['--no-ext-diff', '--no-textconv', '--ignore-submodules=none'];
20
- const SCOPE_EXCLUSIONS = ['/docs/plans/', '/.claude/settings.json', '/.claude/settings.local.json', '/.mcp.json'];
21
+ const SCOPE_EXCLUSIONS = [`/${PLANS}/`, `/${SETTINGS}`, `/${SETTINGS_LOCAL}`, `/${MCP_FILE}`];
21
22
  const MISSING_PATH_CODES = ['ENOENT', 'ENOTDIR'];
22
23
  const ABSENT_HEAD_STATUS = 1;
23
24
  const CHECK_IGNORE_CLEAR_STATUS = 1;
@@ -5,8 +5,8 @@
5
5
  // surveyed by proof before any write: absent, current, prior (a body the catalog lists for its manifest
6
6
  // path) or edited. On every plain run a prior is refreshed, an edited one replaced in place and an
7
7
  // absent one placed create-only, with no question and no copy kept; a current one is left. A project
8
- // that did not accept the enforcement scripts gets every seed entry, the rotator and what it loads. The
9
- // installer is written first, then every file after the family files it imports; after the last write
8
+ // that did not accept the enforcement scripts gets every seed entry, the rotator and what it loads.
9
+ // Every file is written after the family files it imports; after the last write
10
10
  // the project's own rotator brings the ADR store current (`--ensure-current`); last, retired.mjs removes
11
11
  // the kit's old flat files from scripts/ (distribution-files, part flat-move). It never imports
12
12
  // ensure-specs.mjs or ensure-configs.mjs: the CLI composes this op from the module's index, and
@@ -41,8 +41,8 @@ const wrongKind = (rel, kind) => composeFailure(OP, 'wrong-node-kind', `${rel}:
41
41
 
42
42
  // ── the survey: the component first, then every family file by proof, nothing written ────────────
43
43
 
44
- // The installer first (it imports nothing), then each file after every family file it imports.
45
- const inWriteOrder = (files) => [...files.filter((f) => f.rel === INSTALLER_REL), ...dependenciesFirst(files.filter((f) => f.rel !== INSTALLER_REL))];
44
+ // The installer follows the same dependency order as every other family file.
45
+ const inWriteOrder = (files) => dependenciesFirst(files);
46
46
 
47
47
  // Each folder on the way, lstat-ed without following a link: → { refusal } | {}.
48
48
  const surveyFolders = (cwd, family, lstat) => {
@@ -0,0 +1,46 @@
1
+ import { composeCheckerBlock } from '../checker-block/index.mjs';
2
+ import { resolveKitDoc } from '../advisor-matrix.mjs';
3
+
4
+ export const CHECKER_NAME = 'doc-parity';
5
+ const DRIFT_REMEDY = 'update each doc above in the same edit as the code it binds, then re-run';
6
+
7
+ const structureLine = (structure) =>
8
+ ` ${structure.ok ? '✓' : '✗'} ${structure.constant} → ${structure.files[0].rel}${structure.ok ? '' : ` — ${structure.files[0].reason}`}`;
9
+
10
+ export const formatHuman = (results, structure) => {
11
+ const lines = ['doc-parity — code constants ⟷ references/modes/*.md contract (read-only, BUGFREE-3)'];
12
+ for (const r of results) {
13
+ for (const f of r.files) {
14
+ lines.push(` ${f.ok ? '✓' : '✗'} ${r.constant} → ${f.rel}${f.ok ? '' : ` — ${f.reason}`}`);
15
+ }
16
+ }
17
+ lines.push(structureLine(structure));
18
+ const failed = results.flatMap((r) => r.files.filter((f) => !f.ok).map((f) => `${r.constant} @ ${f.rel}`));
19
+ // The summary verdict derives from BOTH halves. A PASS token computed from the bindings alone read
20
+ // as a green report while the structure check below it said FAIL — the one surface that lied.
21
+ const green = failed.length === 0 && structure.ok;
22
+ lines.push(` check: ${green ? 'PASS' : 'FAIL'} — ${failed.length === 0 ? `${results.length} binding(s) consistent` : `${failed.length} drifted binding(s): ${failed.join('; ')}`}, structure ${structure.ok ? 'PASS' : 'FAIL'}`);
23
+ return lines.join('\n');
24
+ };
25
+
26
+ export const formatCheckPass = (results) =>
27
+ `doc-parity check: PASS — ${results.length} binding(s) consistent; the advisor matrix structure corresponds`;
28
+
29
+ const driftFinding = (constant, { rel, reason }) => ({
30
+ path: resolveKitDoc(rel), text: `${constant} — ${reason}`,
31
+ });
32
+
33
+ export const composeDriftBlock = ({ results, structure, cwd }) => {
34
+ const drifted = results.filter(({ ok }) => !ok);
35
+ const classes = [];
36
+ if (drifted.length) classes.push(`${drifted.length} drifted binding(s)`);
37
+ const findings = drifted.flatMap(({ constant, files }) =>
38
+ files.filter(({ ok }) => !ok).map((file) => driftFinding(constant, file)));
39
+ if (!structure.ok) {
40
+ classes.push('the advisor matrix structure drifted');
41
+ findings.push(driftFinding(structure.constant, structure.files[0]));
42
+ }
43
+ return composeCheckerBlock({
44
+ name: CHECKER_NAME, root: cwd, failed: classes.join('; '), findings, remedies: [DRIFT_REMEDY],
45
+ });
46
+ };
@@ -19,7 +19,11 @@
19
19
  // Read-only: never writes, never commits, never runs a subscription CLI, spawns nothing. Dependency-
20
20
  // free, Node >= 22. No side effects on import (the isDirectRun idiom).
21
21
 
22
+ import { resolve } from 'node:path';
23
+ import { composeUsageRefusal } from '../references/scripts/shared/index.mjs';
22
24
  import { EXIT as DOCTOR_EXIT, STATUS as DOCTOR_STATUS, TRUSTED_DIRS as DOCTOR_TRUSTED_DIRS } from './autonomy-doctor.mjs';
25
+ import { runCheckerTail } from './checker-block/index.mjs';
26
+ import { CHECKER_NAME, formatHuman, formatCheckPass, composeDriftBlock } from './doc-parity/index.mjs';
23
27
  import {
24
28
  RECOMMENDATIONS_SECTION_HEADER,
25
29
  RECOMMENDATIONS_EMPTY_LINE,
@@ -96,9 +100,6 @@ const STATUS_DOC = 'references/modes/status.md';
96
100
  // its table in, and a second copy here is exactly the drift this lint exists to catch.
97
101
  const DISPATCH_DOC = ADVISOR_MATRIX_DOC;
98
102
 
99
- // A typed usage failure (exit 2) for the CLI parser — the codebase's typed-error idiom (no classes).
100
- const usageFail = (message) => Object.assign(new Error(message), { exitCode: 2 });
101
-
102
103
  // ── the closed binding registry ──────────────────────────────────────────────────────
103
104
  // Each binding: { constant, value (live), token (value rendered into the doc's exact phrasing),
104
105
  // files[] (the contract docs that MUST carry the token) }. The token phrasings match the current
@@ -281,30 +282,12 @@ export { ADVISOR_MATRIX_DOC, ADVISOR_MATRIX_BEGIN, ADVISOR_MATRIX_END, parseAdvi
281
282
  // relative to the kit root.
282
283
  export const checkParity = (bindings = BINDINGS, readText = defaultReadText) => bindings.map((b) => checkBinding(b, readText));
283
284
 
284
- // ── rendering ───────────────────────────────────────────────────────────────────────
285
- const structureLine = (structure) =>
286
- ` ${structure.ok ? '✓' : '✗'} ${structure.constant} → ${structure.files[0].rel}${structure.ok ? '' : ` — ${structure.files[0].reason}`}`;
287
-
288
- const formatHuman = (results, structure) => {
289
- const lines = ['doc-parity — code constants ⟷ references/modes/*.md contract (read-only, BUGFREE-3)'];
290
- for (const r of results) {
291
- for (const f of r.files) {
292
- lines.push(` ${f.ok ? '✓' : '✗'} ${r.constant} → ${f.rel}${f.ok ? '' : ` — ${f.reason}`}`);
293
- }
294
- }
295
- lines.push(structureLine(structure));
296
- const failed = results.flatMap((r) => r.files.filter((f) => !f.ok).map((f) => `${r.constant} @ ${f.rel}`));
297
- // The summary verdict derives from BOTH halves. A PASS token computed from the bindings alone read
298
- // as a green report while the structure check below it said FAIL — the one surface that lied.
299
- const green = failed.length === 0 && structure.ok;
300
- lines.push(` check: ${green ? 'PASS' : 'FAIL'} — ${failed.length === 0 ? `${results.length} binding(s) consistent` : `${failed.length} drifted binding(s): ${failed.join('; ')}`}, structure ${structure.ok ? 'PASS' : 'FAIL'}`);
301
- return lines.join('\n');
302
- };
285
+ const UNEXPECTED_REMEDY = 'fix the cause the stack below names, then re-run';
286
+ const USAGE = 'Usage:\n node doc-parity.mjs [--check | --json]';
303
287
 
304
288
  const HELP = `doc-parity — deterministic doc-drift lint for the agent-workflow family (BUGFREE-3 / AD-049).
305
289
 
306
- Usage:
307
- node doc-parity.mjs [--check | --json]
290
+ ${USAGE}
308
291
 
309
292
  A CLOSED, exported registry binds each live code constant — the autonomy-doctor contract (the EXIT
310
293
  table, the status tokens, the trusted-dir allowlist), the recommendations/upgrade presentation
@@ -346,32 +329,29 @@ Read-only: never writes, never commits, spawns nothing. Exit codes: 0 pass (or p
346
329
  const KNOWN_ARGS = new Set(['--help', '-h', '--check', '--json']);
347
330
 
348
331
  export const main = (argv, ctx = {}) => {
332
+ if (argv.includes('--help') || argv.includes('-h')) return { code: 0, stdout: HELP, stderr: '' };
333
+ const unknown = argv.find((argument) => !KNOWN_ARGS.has(argument));
334
+ if (unknown !== undefined) {
335
+ const lines = composeUsageRefusal({ name: CHECKER_NAME, failed: `unknown argument: ${JSON.stringify(unknown)}`, usage: USAGE });
336
+ return { code: 2, stdout: lines.join('\n'), stderr: '' };
337
+ }
349
338
  const readText = ctx.readText ?? defaultReadText;
350
- try {
351
- if (argv.includes('--help') || argv.includes('-h')) return { code: 0, stdout: HELP, stderr: '' };
352
- const unknown = argv.find((a) => !KNOWN_ARGS.has(a));
353
- if (unknown !== undefined) throw usageFail(`unknown argument: ${unknown}`);
354
- const results = checkParity(BINDINGS, readText);
355
- const structure = checkMatrixStructure(readText);
356
- const failed = results.filter((r) => !r.ok);
357
- const green = failed.length === 0 && structure.ok;
358
- if (argv.includes('--json')) {
359
- return { code: argv.includes('--check') && !green ? 1 : 0, stdout: JSON.stringify({ results, structure, ok: green }, null, 2), stderr: '' };
360
- }
361
- if (argv.includes('--check')) {
362
- const bindingReason = failed.length === 0 ? `${results.length} binding(s) consistent` : `${failed.length} drifted binding(s): ${failed.map((r) => r.constant).join(', ')} — update the contract doc(s) in the SAME edit as the code`;
363
- const structureReason = structure.ok ? 'the advisor matrix structure corresponds' : `the advisor matrix structure DRIFTED — ${structure.files[0].reason}`;
364
- return { code: green ? 0 : 1, stdout: `doc-parity check: ${green ? 'PASS' : 'FAIL'} — ${bindingReason}; ${structureReason}`, stderr: '' };
365
- }
366
- return { code: 0, stdout: formatHuman(results, structure), stderr: '' };
367
- } catch (err) {
368
- return { code: err.exitCode ?? 1, stdout: '', stderr: `doc-parity: ${err.message}` };
339
+ const results = checkParity(BINDINGS, readText);
340
+ const structure = checkMatrixStructure(readText);
341
+ const green = results.every(({ ok }) => ok) && structure.ok;
342
+ const check = argv.includes('--check');
343
+ if (argv.includes('--json')) {
344
+ return { code: check && !green ? 1 : 0, stdout: JSON.stringify({ results, structure, ok: green }, null, 2), stderr: '' };
345
+ }
346
+ if (check) {
347
+ if (green) return { code: 0, stdout: formatCheckPass(results), stderr: '' };
348
+ const lines = composeDriftBlock({ results, structure, cwd: resolve(ctx.cwd ?? process.cwd()) });
349
+ return { code: 1, stdout: lines.join('\n'), stderr: '' };
369
350
  }
351
+ return { code: 0, stdout: formatHuman(results, structure), stderr: '' };
370
352
  };
371
353
 
372
354
  if (isDirectRun(import.meta.url)) {
373
- const r = main(process.argv.slice(2));
374
- if (r.stdout) process.stdout.write(r.stdout.endsWith('\n') ? r.stdout : `${r.stdout}\n`);
375
- if (r.stderr) process.stderr.write(r.stderr.endsWith('\n') ? r.stderr : `${r.stderr}\n`);
376
- process.exitCode = r.code;
355
+ runCheckerTail({ name: CHECKER_NAME, exitCode: 1, remedy: UNEXPECTED_REMEDY },
356
+ () => main(process.argv.slice(2)), process);
377
357
  }
@@ -10,7 +10,7 @@
10
10
  // + docs/ai/specs/index.md a shipped prior refreshed, an edited one replaced, an absent
11
11
  // one placed; then the store root seeded create-only
12
12
  // scripts scripts/<every kit script> once a kit script outside the seed names, or the old flat installer, stands there, every file not current
13
- // + the installer set written with no question and no copy kept; installer set first; on a
13
+ // + the installer set written with no question and no copy kept; on a
14
14
  // declined offer every seed file, the rotator included, and no other;
15
15
  // then the project's rotator brings the ADR store current (--ensure-current)
16
16
  // rules docs/ai/rules/<theme>.md the kit file seeded, refreshed on a shipped prior body, or any
@@ -86,7 +86,7 @@ The executor ensure writes nothing: a placed .claude/agents/executor.md whose by
86
86
  body derived from docs/ai/vehicles.json is pending and an absent one is not placed here — the
87
87
  advisor's agents item writes the derived body.
88
88
  A fifth writes too: once a kit script outside the seed names stands in scripts/agent-workflow/, or the hook installer under its old
89
- flat name in scripts/, the enforcement-script ensure writes every kit script that is not the bundled body, the hook installer first,
89
+ flat name in scripts/, the enforcement-script ensure writes every kit script that is not the bundled body,
90
90
  with no question and no copy kept: a body a release shipped is refreshed, an edited one replaced (its line names where an edit meant
91
91
  to last goes) and an absent one placed; on a project that declined the enforcement offer, every seed file, the rotator included,
92
92
  is kept current the same way, an absent one placed, and no other kit script is placed; after the writes the project's