@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,147 @@
1
+ // hook-writer/index.mjs — docs/ai/specs/kit/hook-writer.md
2
+
3
+ import { join, resolve } from 'node:path';
4
+ import {
5
+ CLAUDE_DIR,
6
+ EXPECTED_WORKFLOW_VERSION,
7
+ SETTINGS_FILE,
8
+ SETTINGS_LOCAL_FILE,
9
+ WORKFLOW_STAMP,
10
+ readSettingsFile,
11
+ } from '../velocity-profile.mjs';
12
+ import {
13
+ GATE_HOOK_DIVERGED,
14
+ HOOKS_DIR,
15
+ assertDirSafe,
16
+ assertHooksShape,
17
+ assertSafeModes,
18
+ assertSettingsWritable,
19
+ assertStampCurrent,
20
+ formatJson,
21
+ fsDeps,
22
+ makeGateHookError,
23
+ planTarget,
24
+ readBundledHook,
25
+ readStamp,
26
+ writeHookFile,
27
+ } from '../gate-hook.mjs';
28
+ import { fileLine } from '../distribution-files/index.mjs';
29
+
30
+ const UTF8 = 'utf8';
31
+ const LF = '\n';
32
+
33
+ const PLACEMENT_CREATE = 'create';
34
+ const PLACEMENT_KEEP = 'keep';
35
+ const PLACEMENT_REPLACE = 'replace';
36
+ const PLACEMENT_OF = Object.freeze({ place: PLACEMENT_CREATE, 'already-current': PLACEMENT_KEEP, diverged: PLACEMENT_REPLACE });
37
+ const TARGET_CURRENT = 'already-current';
38
+
39
+ const MERGE_NO_HOOKS = 'no-hooks';
40
+ const MERGE_NO_EVENT = 'no-event';
41
+ const MERGE_APPEND = 'append';
42
+
43
+ const PLACEMENT_LINES = Object.freeze({ [PLACEMENT_CREATE]: ['would place', 'placed'], [PLACEMENT_KEEP]: ['already current', 'already current'] });
44
+ const HEADER_DRY_RUN = 'DRY RUN (no changes; re-run with --apply)';
45
+ const HEADER_APPLY = 'APPLY';
46
+ const FILE_STATE_HOOK = 'hook';
47
+ const FILE_WRITTEN = 'written';
48
+
49
+ const isJsonObject = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
50
+
51
+ const mergeCaseOf = (data, event) => {
52
+ if (!isJsonObject(data) || data.hooks === undefined) return MERGE_NO_HOOKS;
53
+ return data.hooks[event] === undefined ? MERGE_NO_EVENT : MERGE_APPEND;
54
+ };
55
+
56
+ export const mergeHookEntryInto = (base, event, entry) => {
57
+ const root = isJsonObject(base) ? base : {};
58
+ const hooks = isJsonObject(root.hooks) ? root.hooks : {};
59
+ const entries = Array.isArray(hooks[event]) ? hooks[event] : [];
60
+ return { ...root, hooks: { ...hooks, [event]: [...entries, entry] } };
61
+ };
62
+
63
+ const preflight = (hook, projectDir, deps) => {
64
+ const fs = fsDeps(deps);
65
+ const bundleContent = readBundledHook({ ...deps, bundlePath: deps.bundlePath ?? hook.bundlePath });
66
+ const stamp = readStamp(join(projectDir, WORKFLOW_STAMP), fs);
67
+ assertDirSafe(join(projectDir, CLAUDE_DIR), CLAUDE_DIR, fs);
68
+ assertDirSafe(join(projectDir, HOOKS_DIR), HOOKS_DIR, fs);
69
+ const target = planTarget(join(projectDir, hook.fileRel), hook.fileRel, bundleContent, fs);
70
+ assertSettingsWritable(join(projectDir, SETTINGS_FILE), fs);
71
+ const projectSettings = readSettingsFile(join(projectDir, SETTINGS_FILE), { ...deps, cwd: projectDir });
72
+ const localSettings = readSettingsFile(join(projectDir, SETTINGS_LOCAL_FILE), { ...deps, cwd: projectDir });
73
+ if (hook.refusesUnsafeModes) assertSafeModes(projectSettings.data, localSettings.data, hook.lines.bypassReason);
74
+ assertHooksShape(projectSettings.data, SETTINGS_FILE, hook.event);
75
+ return {
76
+ projectDir,
77
+ bundleContent,
78
+ stamp,
79
+ stampOk: stamp === EXPECTED_WORKFLOW_VERSION,
80
+ placement: PLACEMENT_OF[target.action],
81
+ projectSettings,
82
+ localSettings,
83
+ wiredInProject: hook.isWired(projectSettings.data),
84
+ wiredInLocal: hook.isWired(localSettings.data),
85
+ mergeCase: mergeCaseOf(projectSettings.data, hook.event),
86
+ };
87
+ };
88
+
89
+ const wireEntry = (hook, plan, fs) => {
90
+ const hookAbs = join(plan.projectDir, hook.fileRel);
91
+ const placed = planTarget(hookAbs, hook.fileRel, plan.bundleContent, fs);
92
+ if (placed.action !== TARGET_CURRENT) {
93
+ throw makeGateHookError(
94
+ GATE_HOOK_DIVERGED,
95
+ `${hook.fileRel} changed after placement — refusing to wire an unknown script as a ${hook.event} hook (no settings change made); re-run`,
96
+ );
97
+ }
98
+ fs.writeFile(
99
+ join(plan.projectDir, SETTINGS_FILE),
100
+ formatJson(mergeHookEntryInto(plan.projectSettings.data ?? {}, hook.event, hook.entry), plan.projectSettings.eol ?? LF),
101
+ UTF8,
102
+ );
103
+ };
104
+
105
+ export const writeKitHook = (hook, { cwd, dryRun = true } = {}, deps = {}) => {
106
+ const fs = fsDeps(deps);
107
+ const plan = preflight(hook, resolve(cwd ?? deps.cwd ?? process.cwd()), deps);
108
+ const placePlanned = plan.placement !== PLACEMENT_KEEP;
109
+ const mergePlanned = !plan.wiredInProject && !plan.wiredInLocal;
110
+ const base = { placePlanned, mergePlanned, ...plan };
111
+ if (dryRun) return { wrote: false, dryRun: true, ...base };
112
+
113
+ assertStampCurrent(plan.stamp);
114
+ const creates = plan.placement === PLACEMENT_CREATE;
115
+ if (creates) fs.mkdir(join(plan.projectDir, HOOKS_DIR), { recursive: true });
116
+ if (placePlanned) writeHookFile(join(plan.projectDir, hook.fileRel), hook.fileRel, plan.bundleContent, creates, fs);
117
+ if (mergePlanned) wireEntry(hook, plan, fs);
118
+ return { wrote: placePlanned || mergePlanned, dryRun: false, ...base };
119
+ };
120
+
121
+ const placementLine = (hook, { placement, dryRun }) => (placement === PLACEMENT_REPLACE
122
+ ? fileLine({ rel: hook.fileRel, state: FILE_STATE_HOOK }, dryRun ? undefined : FILE_WRITTEN, dryRun)
123
+ : `${hook.fileRel}: ${PLACEMENT_LINES[placement][dryRun ? 0 : 1]}`);
124
+
125
+ const settingsLine = (hook, result) => {
126
+ if (result.wiredInProject) return ` - ${SETTINGS_FILE}: already wired`;
127
+ if (result.wiredInLocal) return ` - ${SETTINGS_FILE}: already wired via ${SETTINGS_LOCAL_FILE} — not duplicated`;
128
+ return ` - ${SETTINGS_FILE}: ${result.dryRun ? 'would add' : 'added'} ${hook.lines.merge[result.mergeCase]}`;
129
+ };
130
+
131
+ export const formatKitHookResult = (hook, result) => {
132
+ if (!result.placePlanned && !result.mergePlanned) return hook.lines.nothingToChange;
133
+ const lines = [
134
+ `agent-workflow ${hook.lines.title} — ${result.dryRun ? HEADER_DRY_RUN : HEADER_APPLY}`,
135
+ ` - ${placementLine(hook, result)}`,
136
+ settingsLine(hook, result),
137
+ ...(hook.lines.commandNote === undefined ? [] : [` ${hook.lines.commandNote}`]),
138
+ hook.lines.trustPosture,
139
+ ];
140
+ if (!result.stampOk) {
141
+ lines.push(`note: no current deployment stamp found (${result.stamp ?? 'none'}) — --apply will refuse until init/upgrade runs.`);
142
+ }
143
+ if (!result.dryRun && result.mergePlanned) {
144
+ lines.push(`settings hot-reload: ${hook.lines.reload} — no session restart needed.`);
145
+ }
146
+ return lines.join(LF);
147
+ };
@@ -1,5 +1,6 @@
1
1
  import { closeSync, constants, lstatSync, openSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
+ import { GIT_CONFIG, MCP_FILE, SETTINGS, SETTINGS_LOCAL } from '../references/scripts/shared/index.mjs';
3
4
 
4
5
  export const AGENT_SESSION_MARKERS = Object.freeze([
5
6
  'CLAUDECODE',
@@ -78,10 +79,10 @@ export const preflightInit = ({ root = null, home, env = process.env, io = {} })
78
79
  const paths = [join(home, '.claude/settings.json')];
79
80
  if (root !== null) {
80
81
  paths.push(
81
- join(root, '.claude/settings.json'),
82
- join(root, '.claude/settings.local.json'),
83
- join(root, '.mcp.json'),
84
- join(root, '.git/config'),
82
+ join(root, SETTINGS),
83
+ join(root, SETTINGS_LOCAL),
84
+ join(root, MCP_FILE),
85
+ join(root, GIT_CONFIG),
85
86
  );
86
87
  }
87
88
  for (const path of paths) {
@@ -4,6 +4,7 @@ import { homedir } from 'node:os';
4
4
  import { basename, dirname, join, resolve, sep } from 'node:path';
5
5
  import { createInterface } from 'node:readline/promises';
6
6
  import { fileURLToPath } from 'node:url';
7
+ import { AGENTS_DIR, DOCS_TREE, GIT_CONFIG, GIT_DIR, GIT_HOOKS, HOOKS_DIR, MCP_FILE, SETTINGS as SETTINGS_LOCATION, SETTINGS_LOCAL, WORKFLOW_STAMP } from '../references/scripts/shared/index.mjs';
7
8
  import { checkApply } from './apply-danger-check.mjs';
8
9
  import { resolveGitHooksPath } from './commit-guard.mjs';
9
10
  import { dirCovers } from './declared-paths.mjs';
@@ -19,8 +20,8 @@ const INSIDE_LINE = 'you are inside an agent; run this in your own terminal';
19
20
  const APPLY_PROMPT = 'apply? y/N: ';
20
21
  const RUN_NONE = 'y applies every preview above (a sudo install asks once more on its own line); run none of their commands yourself';
21
22
  const RESTART_LINE = 'restart the agent from this folder: init changed its configuration';
22
- const SETTINGS = ['.claude/settings.json', '.claude/settings.local.json', '.mcp.json', '.git/config'];
23
- const FILE_DIRS = ['.claude/agents', '.claude/hooks'];
23
+ const SETTINGS = [SETTINGS_LOCATION, SETTINGS_LOCAL, MCP_FILE, GIT_CONFIG];
24
+ const FILE_DIRS = [AGENTS_DIR, HOOKS_DIR];
24
25
  // The record key whose state is the sorted *.json names of its directory, so a created file is a change.
25
26
  const JSON_NAMES = '*.json';
26
27
  const DANGLING = new Set(['ENOENT', 'ENOTDIR', 'ELOOP']);
@@ -42,12 +43,12 @@ export const findProject = ({ cwd, lstat = lstatSync }) => {
42
43
  const candidates = [];
43
44
  const visit = (root) => {
44
45
  const io = { lstat };
45
- if (readStat(join(root, 'docs/ai'), io)?.isDirectory()) {
46
- const shape = readStat(join(root, 'docs/ai/.workflow-version'), io) ? 'stamped' : 'pre-versioned';
46
+ if (readStat(join(root, DOCS_TREE), io)?.isDirectory()) {
47
+ const shape = readStat(join(root, WORKFLOW_STAMP), io) ? 'stamped' : 'pre-versioned';
47
48
  candidates.push({ root, shape });
48
49
  }
49
50
  const parent = dirname(root);
50
- if (!readStat(join(root, '.git'), io) && parent !== root) visit(parent);
51
+ if (!readStat(join(root, GIT_DIR), io) && parent !== root) visit(parent);
51
52
  };
52
53
  visit(resolve(cwd));
53
54
  return { candidates };
@@ -57,8 +58,8 @@ const readEntries = (dir, io) => readStat(dir, io)?.isDirectory() ? io.readdir(d
57
58
  const collectPaths = ({ root, home, hooksDir }, io) => {
58
59
  const paths = [join(home, '.claude/settings.json')];
59
60
  if (root === null) return paths;
60
- const docs = join(root, 'docs/ai');
61
- paths.push(...SETTINGS.map((path) => join(root, path)), join(docs, '.workflow-version'), join(docs, JSON_NAMES));
61
+ const docs = join(root, DOCS_TREE);
62
+ paths.push(...SETTINGS.map((path) => join(root, path)), join(root, WORKFLOW_STAMP), join(docs, JSON_NAMES));
62
63
  for (const dir of [...FILE_DIRS.map((path) => join(root, path)), hooksDir]) {
63
64
  paths.push(dir, ...readEntries(dir, io).map((name) => join(dir, name)));
64
65
  }
@@ -139,7 +140,7 @@ const findMasks = (paths, facts, io, print) => {
139
140
  const masks = new Set();
140
141
  const root = facts.root ?? facts.cwd;
141
142
  for (const path of new Set(paths)) {
142
- if (!isProtectedPath(path, { root, home: facts.home, hooksDir: join(root, '.git/hooks') })) continue;
143
+ if (!isProtectedPath(path, { root, home: facts.home, hooksDir: join(root, GIT_HOOKS) })) continue;
143
144
  const stat = readStat(path, io);
144
145
  if (!stat?.isFile() || stat.size !== 0 || (stat.mode & 0o222) !== 0) continue;
145
146
  masks.add(path);
@@ -241,7 +242,7 @@ const previewQueue = async (context, queue) => {
241
242
 
242
243
  const isConfiguration = (path, root) => root !== null && (
243
244
  SETTINGS.slice(0, 3).some((rel) => path === join(root, rel))
244
- || ['.claude/agents', '.claude/hooks'].some((rel) => path === join(root, rel) || path.startsWith(join(root, rel) + sep))
245
+ || FILE_DIRS.some((rel) => path === join(root, rel) || path.startsWith(join(root, rel) + sep))
245
246
  );
246
247
 
247
248
  // The record is the state the first preview reads: taken before any preview, compared before each apply.
@@ -333,7 +334,7 @@ const gateStamp = (candidate, context) => {
333
334
  if (candidate.root === null) return null;
334
335
  const stamp = (() => {
335
336
  try {
336
- return String(context.io.readFile(join(candidate.root, 'docs/ai/.workflow-version'), 'utf8')).trim();
337
+ return String(context.io.readFile(join(candidate.root, WORKFLOW_STAMP), 'utf8')).trim();
337
338
  } catch {
338
339
  return null;
339
340
  }
@@ -369,7 +370,7 @@ export const runInitProject = async (deps) => {
369
370
  }
370
371
  const root = gateStamp(candidate, context);
371
372
  // The hooks dir git itself reports (a linked worktree's or core.hooksPath), as the advisor reads it.
372
- const hooksDir = root === null ? null : (deps.gitHooksPath ?? resolveGitHooksPath)(root) ?? join(root, '.git/hooks');
373
+ const hooksDir = root === null ? null : (deps.gitHooksPath ?? resolveGitHooksPath)(root) ?? join(root, GIT_HOOKS);
373
374
  context.facts = { toolsDir: deps.toolsDir, root, env: deps.env, home: deps.home, platform: deps.platform, tuple: undefined, hooksDir };
374
375
  context.recommend ??= (root, facts) => buildRecommendations({ cwd: root ?? deps.cwd,
375
376
  deps: { ...io, env: deps.env, getenv: deps.env, home: deps.home, platform: deps.platform,
@@ -8,6 +8,7 @@
8
8
  // Contract: docs/ai/specs/kit/install/entry-pointers.md.
9
9
 
10
10
  import { basename, dirname, isAbsolute, join, resolve } from 'node:path';
11
+ import { AGENT_RULES, CLAUDE_FILE, HANDOVER } from '../references/scripts/shared/index.mjs';
11
12
  import { isDirectRun } from './direct-run.mjs';
12
13
  import { normalizeCanonical } from './orchestration-config.mjs';
13
14
  import { PRECEDENCE_LINE, THEMES, themePaths } from './project-rules/index.mjs';
@@ -18,7 +19,7 @@ import {
18
19
  export const BLOCK_START = '<!-- workflow:kit:start -->';
19
20
  export const BLOCK_END = '<!-- workflow:kit:end -->';
20
21
  export const READ_LINE = 'Read `docs/ai/index.md` after this file; read `docs/ai/agent_rules.md` before any code change.';
21
- export const MEMORY_IMPORTS = Object.freeze(['docs/ai/handover.md', 'docs/ai/agent_rules.md']);
22
+ export const MEMORY_IMPORTS = Object.freeze([HANDOVER, AGENT_RULES]);
22
23
  export const FALLBACK_LINE = 'Claude Code loads the content of the `@` files above at a start in the project root with no dialog, and at a start in a subfolder once its one-time per-repository approval was answered Yes in an interactive session; if their content is not in your context, read each `@` path above from disk before anything else.';
23
24
  export const SKIP_PREFIX = 'Kit text not supplied by the installed engine:';
24
25
  export const BLOCK_ROUTE = "text of your own goes outside the two workflow:kit comment lines; a change to a kit rule goes in its theme's file under docs/ai/rules/local/";
@@ -205,7 +206,7 @@ export const runCli = async (argv, deps = {}) => {
205
206
  }
206
207
  const target = resolve(argv[1]);
207
208
  const checkClaudeLink = async (own) => {
208
- const state = { hop: join(dirname(own), 'CLAUDE.md'), links: 0, checkingEntry: true };
209
+ const state = { hop: join(dirname(own), CLAUDE_FILE), links: 0, checkingEntry: true };
209
210
  while (state.hop !== own) {
210
211
  state.checkingEntry = true;
211
212
  try {
@@ -4,7 +4,7 @@ import { lstatSync, readFileSync, readdirSync, statSync } from 'node:fs';
4
4
  import { homedir, hostname } from 'node:os';
5
5
  import { basename, dirname, join, resolve } from 'node:path';
6
6
  import { fileURLToPath } from 'node:url';
7
- import { fail } from '../references/scripts/shared/index.mjs';
7
+ import { AGENTS_SKILLS, SKILLS_DIR, fail } from '../references/scripts/shared/index.mjs';
8
8
  import { isDirectRun } from './direct-run.mjs';
9
9
  import { AFTER_INSTALL, KEY_VARIABLE, NO_APPLY_LINE, RESTART_STEP, SKILL_PINS, claudeDirOf, connectLine, keySet, placeOf, printable, skillLine, skillState, skillTargets } from './jev-facts.mjs';
10
10
 
@@ -107,7 +107,7 @@ const homeOf = (io) => {
107
107
  const placeFor = (io, env, platform) => placeOf({ env, platform,
108
108
  hostname: io.hostname ?? (() => { try { return hostname(); } catch { return ''; } })(),
109
109
  container: io.container ?? statIs('/.dockerenv', 'file') });
110
- const skillPaths = (dir, home) => [...new Set([join(dir, '.claude', 'skills'), join(dir, '.agents', 'skills'),
110
+ const skillPaths = (dir, home) => [...new Set([join(dir, SKILLS_DIR), join(dir, AGENTS_SKILLS),
111
111
  ...(home === '' ? [] : [join(home, '.claude', 'skills'), join(home, '.codex', 'skills'), join(home, '.cursor', 'skills')])]
112
112
  .map((root) => join(root, SKILL_FILE)))];
113
113
 
@@ -8,8 +8,8 @@
8
8
  // Copilot, Aider, Continue, …) that would otherwise leak into a commit. Only the
9
9
  // ones PRESENT on disk become candidates (no pre-emptive hiding of absent paths).
10
10
  //
11
- // Source of truth is here, not an on-disk manifest (the AD-008 `KNOWN_BACKENDS` pattern): a foreign
12
- // tool's footprint has no file in the kit tarball to read, so the per-tool facts must live in-tool.
11
+ // The per-tool footprint facts live here (the AD-008 `KNOWN_BACKENDS` pattern). The project paths
12
+ // that the patterns are built from come from the shared index and node-evidence.mjs.
13
13
  // The drift-guard test (known-footprint.test.mjs) keeps the registry honest — a frozen snapshot +
14
14
  // count sentinel + intrinsic invariants (anchoring, uniqueness, disjointness, no subsumption) — and
15
15
  // references/contracts.md carries the human-readable mirror table, kept in sync by review.
@@ -19,7 +19,9 @@
19
19
  // node-evidence.mjs's, the kit's one door to the script family (which reads its manifest on import).
20
20
 
21
21
  import { readdirSync, statSync } from 'node:fs';
22
+ import { AGENTS_DIR, AGENTS_FILE, AIDER_CHAT_HISTORY, AIDER_CONF, AIDER_INPUT_HISTORY, ANTIGRAVITY_FILE, CLAUDE_FILE, CODEIUM_DIR, CONTINUE_DIR, CURSORRULES, CURSOR_RULES, DOCS_TREE, GEMINI_FILE, GITHUB_DIR, HOOKS_DIR, MCP_FILE, PLANS, SETTINGS, SETTINGS_LOCAL, SKILLS_DIR, WINDSURFRULES, WINDSURF_DIR } from '../references/scripts/shared/index.mjs';
22
23
  import { KIT_SCRIPTS_DIR } from './node-evidence.mjs';
24
+ import { escapeRegExp } from './repo-lex.mjs';
23
25
 
24
26
  // A typed STOP — a deliberate refusal we surface (never a silent skip, never a fail-open). Shared by
25
27
  // the writer tool (hide-footprint.mjs imports it) so both speak one error vocabulary. The codebase's
@@ -47,14 +49,14 @@ export const stop = (message, fields = {}) =>
47
49
  // `scripts/<name>` is listed, because the upgrade's scripts op removes the kit's old flat files in the
48
50
  // run that places the kit folder (distribution-files, part flat-move: the window it leaves is stated there).
49
51
  export const KIT_OWN_PATHS = [
50
- '/AGENTS.md',
51
- '/CLAUDE.md',
52
- '/docs/ai/',
52
+ `/${AGENTS_FILE}`,
53
+ `/${CLAUDE_FILE}`,
54
+ `/${DOCS_TREE}/`,
53
55
  `/${KIT_SCRIPTS_DIR}/`,
54
- '/docs/plans/',
55
- '/.claude/settings.local.json',
56
- '/.claude/settings.json',
57
- '/.mcp.json',
56
+ `/${PLANS}/`,
57
+ `/${SETTINGS_LOCAL}`,
58
+ `/${SETTINGS}`,
59
+ `/${MCP_FILE}`,
58
60
  ];
59
61
 
60
62
  // Every OTHER tool's footprint. `falsePositiveRisk` flags a name generic/ambiguous enough that a
@@ -62,21 +64,21 @@ export const KIT_OWN_PATHS = [
62
64
  // `glob:true` marks the ONE reviewed wildcard (`/.github/copilot-*`) — it is expanded against the
63
65
  // filesystem (expandGlob) to concrete present files before any git probe; never fed to ls-files.
64
66
  export const KNOWN_FOOTPRINT = [
65
- { pattern: '/.claude/skills/', owner: 'Claude Code', type: 'dir', falsePositiveRisk: false, note: 'local-dev skills; absorbs the AD-013 one-off' },
66
- { pattern: '/.claude/agents/', owner: 'Claude Code', type: 'dir', falsePositiveRisk: false, note: 'project subagent definitions (incl. the kit-placed cheap-lane vehicles)' },
67
- { pattern: '/.claude/hooks/', owner: 'Claude Code', type: 'dir', falsePositiveRisk: false, note: 'project hooks (incl. the kit-placed gate-approval hook)' },
68
- { pattern: '/.cursor/rules/', owner: 'Cursor', type: 'dir', falsePositiveRisk: false, note: 'project rule files' },
69
- { pattern: '/.cursorrules', owner: 'Cursor (legacy)', type: 'file', falsePositiveRisk: true, note: 'legacy single-file rules' },
70
- { pattern: '/.codeium/', owner: 'Codeium/Windsurf', type: 'dir', falsePositiveRisk: false, note: 'home-scoped launchers live under ~/, out of scope' },
71
- { pattern: '/.windsurf/', owner: 'Windsurf (Devin)', type: 'dir', falsePositiveRisk: false, note: 'project config dir' },
72
- { pattern: '/.windsurfrules', owner: 'Windsurf', type: 'file', falsePositiveRisk: true, note: 'legacy single-file rules' },
73
- { pattern: '/GEMINI.md', owner: 'Gemini/Antigravity', type: 'file', falsePositiveRisk: true, note: 'context file; generic name' },
74
- { pattern: '/.antigravity.md', owner: 'Antigravity', type: 'file', falsePositiveRisk: true, note: 'context file' },
75
- { pattern: '/.github/copilot-*', owner: 'GitHub Copilot', type: 'file', falsePositiveRisk: true, glob: true, note: 'covers copilot-instructions.md; the one reviewed glob' },
76
- { pattern: '/.aider.conf.yml', owner: 'Aider', type: 'file', falsePositiveRisk: false, note: 'config' },
77
- { pattern: '/.aider.chat.history.md', owner: 'Aider', type: 'file', falsePositiveRisk: false, note: 'chat history' },
78
- { pattern: '/.aider.input.history', owner: 'Aider', type: 'file', falsePositiveRisk: false, note: 'input history' },
79
- { pattern: '/.continue/', owner: 'Continue', type: 'dir', falsePositiveRisk: false, note: 'project config dir' },
67
+ { pattern: `/${SKILLS_DIR}/`, owner: 'Claude Code', type: 'dir', falsePositiveRisk: false, note: 'local-dev skills; absorbs the AD-013 one-off' },
68
+ { pattern: `/${AGENTS_DIR}/`, owner: 'Claude Code', type: 'dir', falsePositiveRisk: false, note: 'project subagent definitions (incl. the kit-placed cheap-lane vehicles)' },
69
+ { pattern: `/${HOOKS_DIR}/`, owner: 'Claude Code', type: 'dir', falsePositiveRisk: false, note: 'project hooks (incl. the kit-placed gate-approval hook)' },
70
+ { pattern: `/${CURSOR_RULES}/`, owner: 'Cursor', type: 'dir', falsePositiveRisk: false, note: 'project rule files' },
71
+ { pattern: `/${CURSORRULES}`, owner: 'Cursor (legacy)', type: 'file', falsePositiveRisk: true, note: 'legacy single-file rules' },
72
+ { pattern: `/${CODEIUM_DIR}/`, owner: 'Codeium/Windsurf', type: 'dir', falsePositiveRisk: false, note: 'home-scoped launchers live under ~/, out of scope' },
73
+ { pattern: `/${WINDSURF_DIR}/`, owner: 'Windsurf (Devin)', type: 'dir', falsePositiveRisk: false, note: 'project config dir' },
74
+ { pattern: `/${WINDSURFRULES}`, owner: 'Windsurf', type: 'file', falsePositiveRisk: true, note: 'legacy single-file rules' },
75
+ { pattern: `/${GEMINI_FILE}`, owner: 'Gemini/Antigravity', type: 'file', falsePositiveRisk: true, note: 'context file; generic name' },
76
+ { pattern: `/${ANTIGRAVITY_FILE}`, owner: 'Antigravity', type: 'file', falsePositiveRisk: true, note: 'context file' },
77
+ { pattern: `/${GITHUB_DIR}/copilot-*`, owner: 'GitHub Copilot', type: 'file', falsePositiveRisk: true, glob: true, note: 'covers copilot-instructions.md; the one reviewed glob' },
78
+ { pattern: `/${AIDER_CONF}`, owner: 'Aider', type: 'file', falsePositiveRisk: false, note: 'config' },
79
+ { pattern: `/${AIDER_CHAT_HISTORY}`, owner: 'Aider', type: 'file', falsePositiveRisk: false, note: 'chat history' },
80
+ { pattern: `/${AIDER_INPUT_HISTORY}`, owner: 'Aider', type: 'file', falsePositiveRisk: false, note: 'input history' },
81
+ { pattern: `/${CONTINUE_DIR}/`, owner: 'Continue', type: 'dir', falsePositiveRisk: false, note: 'project config dir' },
80
82
  ];
81
83
 
82
84
  // ── pure pattern helpers ────────────────────────────────────────────────────────
@@ -107,7 +109,7 @@ export const patternToProbe = (pattern) => {
107
109
  // Turn a basename glob (`copilot-*`) into an anchored regex. Only a single-level `*` is supported
108
110
  // (no `**`, no `/`): split on `*`, regex-escape each literal segment, then join with `.*`.
109
111
  const basenameGlobToRegExp = (glob) => {
110
- const parts = glob.split('*').map((seg) => seg.replace(/[.+?^${}()|[\]\\]/g, '\\$&'));
112
+ const parts = glob.split('*').map(escapeRegExp);
111
113
  return new RegExp(`^${parts.join('.*')}$`);
112
114
  };
113
115
 
@@ -5,8 +5,8 @@
5
5
  //
6
6
  // Split out for the reason bridge-settings-read.mjs was (bridges 2.3.0, D6): a read-only consumer
7
7
  // that imports the writer pulls in the atomic-write core, which read-graph-purity.test.mjs forbids.
8
- // That is also why the two settings-path literals are NOT imported from velocity-profile.mjs (a
9
- // write module) — the equality is pinned by a test instead.
8
+ // The two settings paths come from the shared index. A test pins their equality with the paths
9
+ // velocity-profile.mjs uses.
10
10
  //
11
11
  // It reads through fs-read-nofollow.mjs rather than velocity's readSettingsFile because that reader
12
12
  // follows a symlink: a symlinked `.mcp.json` whose TARGET is a perfect registration would report
@@ -38,15 +38,16 @@
38
38
 
39
39
  import { join } from 'node:path';
40
40
  import { fileURLToPath } from 'node:url';
41
+ import { CLAUDE_DIR, MCP_FILE, SETTINGS } from '../references/scripts/shared/index.mjs';
41
42
  import { describeNonRegular, lstatNoFollowRead, readRegularFileNoFollow } from './fs-read-nofollow.mjs';
42
43
  import { refuseDirectRun } from './direct-run.mjs';
43
44
  import { SERVER_NAME, TOOLS } from './mcp-server.mjs';
44
45
 
45
46
  export { SERVER_NAME };
46
47
 
47
- export const MCP_JSON_REL = '.mcp.json';
48
- export const CLAUDE_DIR_REL = '.claude';
49
- export const SETTINGS_REL = '.claude/settings.json';
48
+ export const MCP_JSON_REL = MCP_FILE;
49
+ export const CLAUDE_DIR_REL = CLAUDE_DIR;
50
+ export const SETTINGS_REL = SETTINGS;
50
51
  export const SERVERS_KEY = 'mcpServers';
51
52
  export const ENABLED_KEY = 'enabledMcpjsonServers';
52
53
  // OUT OF SCOPE, deliberately and by name: `disabledMcpjsonServers`. A server listed there is rejected
@@ -2,6 +2,7 @@
2
2
  import { lstatSync, readFileSync } from 'node:fs';
3
3
  import { dirname, resolve } from 'node:path';
4
4
  import { fileURLToPath } from 'node:url';
5
+ import { AGENTS_FILE } from '../references/scripts/shared/index.mjs';
5
6
  import { writeContainedFileAtomic } from './atomic-write.mjs';
6
7
  import { isDirectRun } from './direct-run.mjs';
7
8
 
@@ -154,7 +155,7 @@ const runBlocks = (options, deps) => {
154
155
  const template = readTemplate(deps.templatePath ?? TEMPLATE_PATH, deps);
155
156
  if (template.error) return template.error;
156
157
  const root = resolve(options.cwd);
157
- const destination = resolve(root, 'AGENTS.md');
158
+ const destination = resolve(root, AGENTS_FILE);
158
159
  const document = readDocument(destination, deps);
159
160
  if (document.error) return document.error;
160
161
  const plan = planBlocks({ ...options, text: document.text, spans: template.spans });
@@ -1,11 +1,11 @@
1
1
  import { lstatSync, readdirSync, readFileSync } from 'node:fs';
2
2
  import { dirname, join, resolve } from 'node:path';
3
3
  import { fileURLToPath } from 'node:url';
4
+ import { WORKFLOW_STAMP } from '../references/scripts/shared/index.mjs';
4
5
  import { EXPECTED_WORKFLOW_VERSION } from './cheap-agents-read.mjs';
5
6
  import { isDirectRun } from './direct-run.mjs';
6
7
 
7
8
  const NOTES_DIR = resolve(dirname(fileURLToPath(import.meta.url)), '..', 'migrations');
8
- const STAMP_PATH = 'docs/ai/.workflow-version';
9
9
  const VERSION_PATTERN = /^[0-9]+[.][0-9]+[.][0-9]+$/u;
10
10
  const SLUG_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/u;
11
11
  const CONTROL_PATTERN = /[\p{Cc}\p{Zl}\p{Zp}]/gu;
@@ -193,7 +193,7 @@ export const main = (argv, deps = {}) => {
193
193
  readFileSync: deps.readFileSync ?? readFileSync,
194
194
  readdirSync: deps.readdirSync ?? readdirSync,
195
195
  };
196
- const stamp = readStamp(resolve(argv[1], STAMP_PATH), fs);
196
+ const stamp = readStamp(resolve(argv[1], WORKFLOW_STAMP), fs);
197
197
  if (stamp.refusal) {
198
198
  return stamp.refusal;
199
199
  }
@@ -5,7 +5,7 @@ import { lstatSync } from 'node:fs';
5
5
  import { join, posix } from 'node:path';
6
6
  import { readFamily } from '../references/scripts/family.mjs';
7
7
  import { KIT_COMMANDS } from '../references/scripts/run.mjs';
8
- import { KIT_FOLDER_ROOT } from './source-size-config.mjs';
8
+ import { KIT_FOLDER, PACKAGE_JSON, SCRIPTS } from '../references/scripts/shared/index.mjs';
9
9
 
10
10
  export const NODE_EVIDENCE = Object.freeze({
11
11
  PACKAGE_JSON: 'package-json',
@@ -14,9 +14,9 @@ export const NODE_EVIDENCE = Object.freeze({
14
14
  UNREADABLE: 'unreadable',
15
15
  });
16
16
 
17
- export const PACKAGE_JSON_REL = 'package.json';
18
- export const SCRIPTS_DIR = 'scripts';
19
- export const KIT_SCRIPTS_DIR = KIT_FOLDER_ROOT;
17
+ export const PACKAGE_JSON_REL = PACKAGE_JSON;
18
+ export const SCRIPTS_DIR = SCRIPTS;
19
+ export const KIT_SCRIPTS_DIR = KIT_FOLDER;
20
20
 
21
21
  export const INSTALLER_REL = posix.join(KIT_SCRIPTS_DIR, KIT_COMMANDS['install-git-hooks']);
22
22
 
@@ -1,5 +1,6 @@
1
1
  import { spawnSync } from 'node:child_process';
2
2
  import { join } from 'node:path';
3
+ import { QUEUE } from '../references/scripts/shared/index.mjs';
3
4
  import { buildSummaryState, isTreeClean } from './core-evidence.mjs';
4
5
  import { readRegularFileNoFollow } from './fs-read-nofollow.mjs';
5
6
  import { resolveGitLocation } from './git-env.mjs';
@@ -8,7 +9,6 @@ import { loadSourceSizeConfig, practiceFacts } from './source-size-config.mjs';
8
9
  import { gatherPlanFacts, readSummaryFacts } from './now-plan-facts.mjs';
9
10
  import { isWithheld } from './now-status.mjs';
10
11
 
11
- const QUEUE_REL = 'docs/plans/queue.md';
12
12
  const BLOCKS = Object.freeze(['plans', 'tree', 'queue', 'campaign']);
13
13
 
14
14
  const attempt = (label, read) => {
@@ -20,10 +20,10 @@ const attempt = (label, read) => {
20
20
  };
21
21
 
22
22
  const readQueueFacts = (cwd, deps) => {
23
- const read = readRegularFileNoFollow(join(cwd, QUEUE_REL), deps.io ?? {});
24
- if (read.outcome !== 'ok') throw new Error(`${QUEUE_REL} is not a readable regular file (${read.className ?? read.code ?? read.outcome})`);
25
- const { rows, counts, total } = auditQueue(read.content, { label: QUEUE_REL });
26
- return { path: QUEUE_REL, rows, counts, total };
23
+ const read = readRegularFileNoFollow(join(cwd, QUEUE), deps.io ?? {});
24
+ if (read.outcome !== 'ok') throw new Error(`${QUEUE} is not a readable regular file (${read.className ?? read.code ?? read.outcome})`);
25
+ const { rows, counts, total } = auditQueue(read.content, { label: QUEUE });
26
+ return { path: QUEUE, rows, counts, total };
27
27
  };
28
28
 
29
29
  // The practice is opt-in: an absent declaration is a rendered STATE, only an unreadable one is withheld.
@@ -11,7 +11,6 @@ export const NOW_STATUS = Object.freeze({
11
11
 
12
12
  export const NOW_ANNOTATION = Object.freeze({
13
13
  CLAIM: 'claim',
14
- ANOMALY: 'anomaly',
15
14
  RED_PROOF: 'red-proof',
16
15
  });
17
16
 
@@ -61,13 +60,10 @@ const getAnnotations = (row, evidence, status) => {
61
60
  const claim = readProseClaim(row.raw) && status !== NOW_STATUS.LANDED
62
61
  ? [{ kind: NOW_ANNOTATION.CLAIM, text: 'claimed done' }]
63
62
  : [];
64
- const overBudget = row.budgetLines && evidence.pathFact?.kind === 'regular' && evidence.pathFact.lines > row.budgetLines
65
- ? [{ kind: NOW_ANNOTATION.ANOMALY, text: `over budget ${evidence.pathFact.lines}/${row.budgetLines}` }]
66
- : [];
67
63
  const redProof = evidence.redProof
68
64
  ? [{ kind: NOW_ANNOTATION.RED_PROOF, text: evidence.redProof.currency ?? String(evidence.redProof) }]
69
65
  : [];
70
- return [...claim, ...overBudget, ...redProof];
66
+ return [...claim, ...redProof];
71
67
  };
72
68
 
73
69
  // A set has no single post-state, so a sweep row is reduced only under modify: the verb refuses it before any evidence arm.
@@ -20,6 +20,7 @@
20
20
 
21
21
  import { readFileSync, lstatSync } from 'node:fs';
22
22
  import { join } from 'node:path';
23
+ import { ORCHESTRATION } from '../references/scripts/shared/index.mjs';
23
24
  import { ACTIVITIES, SLOT_RECIPES } from './recipes.mjs';
24
25
  import { refuseDirectRun } from './direct-run.mjs';
25
26
  import { validateRoster } from './review-roster.mjs';
@@ -35,7 +36,7 @@ export { CANON_README, KNOWN_PRIOR_README, normalizeCanonical, refreshIfCanonica
35
36
 
36
37
  // The hand-editable / agent-writable, per-project config (strict JSON). cwd-relative — the error prefix
37
38
  // uses this rel path so a user sees a path they can open, never an absolute temp/host path.
38
- export const CONFIG_REL = 'docs/ai/orchestration.json';
39
+ export const CONFIG_REL = ORCHESTRATION;
39
40
 
40
41
  // A tagged failure: a plain Error carrying the intended process exit code (2 usage / 1 config). Avoids
41
42
  // a class (project rule) while letting a CLI main() map a throw to the right code in one place. Shared
@@ -65,7 +65,7 @@ const FOUR_SEED_README = FOUR_README.replace(
65
65
  "Every slot seeded below is 'solo' — no execution backend required. A slot the seed leaves silent takes the computed default stated further down: 'feedback-triage.review' is reviewed as soon as a review backend is ready (solo until then); 'plan-authoring.author', 'plan-authoring.fold' and 'routine.carrier' stay 'solo', and 'routine.parallel' stays 'on'.",
66
66
  );
67
67
 
68
- export const CANON_README = FOUR_SEED_README
68
+ const SIX_SEED_README = FOUR_SEED_README
69
69
  .replace("Four activities are configured independently, and so is each slot within them: 'plan-authoring' (slots author, fold, review), 'plan-execution' (slots execute, review), 'routine' (slots carrier, parallel) and 'feedback-triage' (slot review).",
70
70
  "Six activities are configured independently, and so is each slot within them: 'plan-authoring' (slots author, fold, review), 'plan-execution' (slots execute, review), 'routine' (slots carrier, parallel), 'feedback-triage' (slot review), 'epic' (slots author, review) and 'task' (slots author, execute).")
71
71
  .replace("the carrier slots 'plan-authoring.author', 'plan-authoring.fold' and 'routine.carrier' accept solo | subagent.",
@@ -73,7 +73,12 @@ export const CANON_README = FOUR_SEED_README
73
73
  .replace("'feedback-triage.review' is reviewed as soon as a review backend is ready (solo until then); 'plan-authoring.author', 'plan-authoring.fold' and 'routine.carrier' stay 'solo',",
74
74
  "'feedback-triage.review' is reviewed as soon as a review backend is ready (solo until then), and so is 'epic.review'; 'plan-authoring.author', 'plan-authoring.fold', 'routine.carrier', 'epic.author', 'task.author' and 'task.execute' stay 'solo',");
75
75
 
76
- export const KNOWN_PRIOR_README = Object.freeze([V1_README, V2_README, V3_README, ROSTER_README, FOLD_README, FOUR_README, FOUR_SEED_README]);
76
+ export const CANON_README = SIX_SEED_README.replace(
77
+ "'subagent' needs the executor vehicle placed in this project — the composition root's `agents` writer places it; without it the slot resolves to solo with the reason stated.",
78
+ "'subagent' needs the author vehicle for 'plan-authoring.author', 'plan-authoring.fold' and 'epic.author', and the executor vehicle for every other subagent slot — the composition root's `agents` writer places both; without its role's ready vehicle the slot resolves to solo with the reason stated.",
79
+ );
80
+
81
+ export const KNOWN_PRIOR_README = Object.freeze([V1_README, V2_README, V3_README, ROSTER_README, FOLD_README, FOUR_README, FOUR_SEED_README, SIX_SEED_README]);
77
82
 
78
83
  export const refreshReadme = (config) => {
79
84
  if (config == null || typeof config !== 'object' || Array.isArray(config)) return { config, changed: false };
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { isDirectRun } from '../direct-run.mjs';
4
+ import { isHex64 } from '../flow-vocabulary.mjs';
5
+ import { RECORD, CHECK, ESSENCE_FLAG, DIGEST_FLAG, EXIT_ACCEPT, EXIT_REFUSE, EXIT_USAGE, LINE_ENDING,
6
+ OUTCOME_LINES, isOperand, readApproval, recordApproval } from './record.mjs';
7
+
8
+ export { OUTCOME_LINES, readApproval };
9
+
10
+ const parseArgs = (argv) => {
11
+ const [command, plan, flag, value, ...extra] = argv;
12
+ if (!isOperand(plan) || extra.length) return null;
13
+ if (command === RECORD && flag === ESSENCE_FLAG && isOperand(value)) return { command, plan, essenceFile: value };
14
+ if (command === CHECK && (argv.length === 2 || (flag === DIGEST_FLAG && isHex64(value)))) {
15
+ return { command, plan, approval: value };
16
+ }
17
+ return null;
18
+ };
19
+
20
+ const writeLine = (write, line) => write(`${line}${LINE_ENDING}`);
21
+
22
+ export const main = (argv = process.argv.slice(2), io = {}) => {
23
+ const cwd = io.cwd ?? process.cwd();
24
+ const env = io.env ?? process.env;
25
+ const stdout = io.stdout ?? ((text) => process.stdout.write(text));
26
+ const stderr = io.stderr ?? ((text) => process.stderr.write(text));
27
+ const args = parseArgs(argv);
28
+ if (args === null) {
29
+ writeLine(stderr, OUTCOME_LINES.usage());
30
+ return EXIT_USAGE;
31
+ }
32
+ const { command, plan, approval, essenceFile } = args;
33
+ const result = command === RECORD ? recordApproval(cwd, env, plan, essenceFile) : readApproval({ cwd, env, plan, approval });
34
+ for (const line of result.malformedLines ?? []) writeLine(stderr, OUTCOME_LINES.malformed(result.recordPath, line));
35
+ if (result.exitCode === EXIT_ACCEPT) {
36
+ writeLine(stdout, result.written ? OUTCOME_LINES.recorded(plan, result.entry.approval, result.recordPath)
37
+ : OUTCOME_LINES.accepted(plan, (result.match ?? result.entry).approval));
38
+ } else {
39
+ writeLine(stderr, result.exitCode === EXIT_REFUSE ? OUTCOME_LINES.refused(plan, result.reason) : OUTCOME_LINES.error(plan, result.reason));
40
+ for (const finding of result.verdict?.result.findings ?? []) writeLine(stderr, OUTCOME_LINES.finding(plan, finding));
41
+ }
42
+ return result.exitCode;
43
+ };
44
+
45
+ if (isDirectRun(import.meta.url)) process.exitCode = main();