@sabaiway/agent-workflow-kit 15.1.0 → 16.1.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.
@@ -19,7 +19,7 @@
19
19
  // (the lens from its review-lens section, opus and high by default), replacing the earlier body;
20
20
  // an identical file is `already current` (idempotent re-run);
21
21
  // • writes ONLY under .claude/agents/ — never settings.json / settings.local.json, never
22
- // commits.
22
+ // commits; `--executor` plans and writes the executor alone (the advisor's kit item).
23
23
  //
24
24
  // Claude-Code-specific (like velocity): .claude/agents/ is a Claude Code surface; other agent
25
25
  // hosts ignore it. In a HIDDEN-mode deployment, run the hide-footprint reconcile after apply so
@@ -42,6 +42,7 @@ import { deriveLensTemplate, lensVehicleSpec } from './review-roster-resolve.mjs
42
42
  import { loadVehicles, resolveExecutor, resolveReviewLens } from './vehicle-settings.mjs';
43
43
  import { safeLine } from './carriers.mjs';
44
44
  import { writeContainedFileAtomic } from './atomic-write.mjs';
45
+ import { fileLine } from './distribution-files/index.mjs';
45
46
  // The READ core, never a second copy: the bundle, the placement plan and the executor survey live
46
47
  // there so the read-only advisor graph can reach them without reaching this writer.
47
48
  import {
@@ -56,7 +57,6 @@ import {
56
57
  CHEAP_AGENTS_CONFIG,
57
58
  CHEAP_AGENTS_VEHICLES,
58
59
  EXECUTOR_VEHICLE,
59
- REVIEW_LENS_VEHICLE,
60
60
  executorTemplate,
61
61
  reviewLensTemplate,
62
62
  makeCheapAgentsError,
@@ -99,7 +99,7 @@ const EXIT_USAGE = 2;
99
99
  // never silent).
100
100
  export const FALLBACK_LENS_ADDITIONAL_ONLY = 'review-lens is an ADDITIONAL read-only review opinion, not a replacement for your plan or diff review recipe.';
101
101
 
102
- const USAGE = `usage: cheap-agents [--dry-run | --apply] [--cwd <dir>] [--help]
102
+ const USAGE = `usage: cheap-agents [--dry-run | --apply] [--executor] [--cwd <dir>] [--help]
103
103
 
104
104
  Places the bundled subagent definitions into the project's ${AGENTS_DIR}/. Four vehicles grant NO
105
105
  shell: three ride a cheap model (haiku/low) for mechanical work — extraction sweeps, changelog
@@ -112,7 +112,9 @@ Configured derived review lenses are planned and placed beside the bundled vehic
112
112
  An existing file with DIFFERENT content is preserved and reported, never overwritten, except the executor
113
113
  and the review lens. The executor's model and effort come from docs/ai/vehicles.json, the review lens's
114
114
  from its review-lens section there (opus and high by default), and a placed executor or review-lens.md
115
- whose bytes differ from its derived body is re-derived on --apply (the earlier body is replaced, never preserved).`;
115
+ whose bytes differ from its derived body is re-derived on --apply (the earlier body is replaced, never preserved).
116
+ --executor plans the executor alone and reads no orchestration config, so its --apply writes
117
+ ${AGENTS_DIR}/executor.md and no other file.`;
116
118
 
117
119
  export const fail = (exitCode, message) => Object.assign(new Error(message), { exitCode });
118
120
 
@@ -132,11 +134,12 @@ const refuseSymlinkedRoot = (projectDir, deps) => {
132
134
  if (stat.isSymbolicLink()) throw makeCheapAgentsError(CHEAP_AGENTS_SYMLINK, `the project root ${root} is a symlink — refusing to write through it`);
133
135
  };
134
136
 
135
- export const preflightCheapAgents = ({ cwd, derived = [] }, deps = {}) => {
137
+ // alone: plan the derived templates only (the --executor form), no bundled vehicle beside them.
138
+ export const preflightCheapAgents = ({ cwd, derived = [], alone = false }, deps = {}) => {
136
139
  const fs = readFsDeps(deps);
137
140
  const projectDir = cwd ?? process.cwd();
138
141
  refuseSymlinkedRoot(projectDir, deps);
139
- const templatesByName = new Map(readBundledAgents(deps).map((template) => [template.name, template]));
142
+ const templatesByName = new Map(alone ? [] : readBundledAgents(deps).map((template) => [template.name, template]));
140
143
  for (const template of derived) templatesByName.set(template.name, template);
141
144
  const templates = [...templatesByName.values()];
142
145
  const stamp = readStamp(join(projectDir, WORKFLOW_STAMP), fs);
@@ -178,20 +181,21 @@ const configuredDerivedTemplates = (cwd, deps) => {
178
181
  return [...templates.values()];
179
182
  };
180
183
 
181
- export const applyCheapAgentsCommand = (root) =>
182
- `node ${shellQuoteArg(fileURLToPath(import.meta.url))} --apply --cwd ${shellQuoteArg(root)}`;
184
+ export const applyCheapAgentsCommand = (root, executorOnly = false) =>
185
+ `node ${shellQuoteArg(fileURLToPath(import.meta.url))} --apply${executorOnly ? ' --executor' : ''} --cwd ${shellQuoteArg(root)}`;
183
186
 
184
187
  // ── the writer ────────────────────────────────────────────────────────────────────────
185
188
 
186
- export const writeCheapAgents = ({ cwd, dryRun = true } = {}, deps = {}) => {
189
+ // executorOnly (--executor): the executor template alone, no orchestration config read.
190
+ export const writeCheapAgents = ({ cwd, dryRun = true, executorOnly = false } = {}, deps = {}) => {
187
191
  const fs = writeFsDeps(deps);
188
192
  const projectDir = cwd ?? process.cwd();
189
193
  refuseSymlinkedRoot(projectDir, deps);
190
194
  const { posture, lensPosture } = loadPosturesOrStop(projectDir, deps);
191
- const derived = [
195
+ const derived = executorOnly ? [executorTemplate(posture, deps)] : [
192
196
  executorTemplate(posture, deps), reviewLensTemplate(lensPosture, deps), ...configuredDerivedTemplates(projectDir, deps),
193
197
  ];
194
- const preflight = preflightCheapAgents({ cwd: projectDir, derived }, deps);
198
+ const preflight = { executorOnly, ...preflightCheapAgents({ cwd: projectDir, derived, alone: executorOnly }, deps) };
195
199
  if (dryRun) return { wrote: false, dryRun: true, posture, lensPosture, ...preflight };
196
200
 
197
201
  if (!preflight.stampOk) {
@@ -217,12 +221,19 @@ export const writeCheapAgents = ({ cwd, dryRun = true } = {}, deps = {}) => {
217
221
  const ACTION_LABEL = {
218
222
  place: 'place',
219
223
  'already-current': 'already current',
220
- 're-derive': 're-derived — a hand edit was replaced; set the model in docs/ai/vehicles.json',
221
224
  'customized-preserved': 'customized — preserved (delete the file to reseed from the bundle)',
222
225
  };
223
226
  const LENS_REDERIVE_LABEL = 're-derived — the earlier body was replaced; set its model and effort in docs/ai/vehicles.json';
224
- const labelOf = (item) =>
225
- (item.action === 're-derive' && item.name === REVIEW_LENS_VEHICLE ? LENS_REDERIVE_LABEL : ACTION_LABEL[item.action]);
227
+ // The executor's re-derive line is the distribution-files composer's, over the state `derived`.
228
+ const rowLine = (item, dryRun) => {
229
+ if (item.action === 're-derive' && item.name === EXECUTOR_VEHICLE) {
230
+ return fileLine({ rel: item.rel, name: item.name, state: 'derived' }, dryRun ? undefined : 'written', dryRun);
231
+ }
232
+ const verb = dryRun && item.action === 'place' ? 'would place'
233
+ : dryRun && item.action === 're-derive' ? 'would re-derive'
234
+ : item.action === 're-derive' ? LENS_REDERIVE_LABEL : ACTION_LABEL[item.action];
235
+ return `${item.rel}: ${verb}`;
236
+ };
226
237
 
227
238
  export const formatResult = (result) => {
228
239
  const { posture, lensPosture } = result;
@@ -231,29 +242,29 @@ export const formatResult = (result) => {
231
242
  ? 'agent-workflow subagent vehicles — DRY RUN (no changes)'
232
243
  : 'agent-workflow subagent vehicles — APPLY',
233
244
  ];
234
- for (const item of result.plan) {
235
- const verb = result.dryRun && item.action === 'place' ? 'would place'
236
- : result.dryRun && item.action === 're-derive' ? 'would re-derive' : labelOf(item);
237
- lines.push(` - ${item.rel}: ${verb}`);
238
- }
245
+ for (const item of result.plan) lines.push(` - ${rowLine(item, result.dryRun)}`);
239
246
  if (!result.stampOk) {
240
247
  lines.push(`note: no current deployment stamp found (${result.stamp ?? 'none'}) — --apply will refuse until init/upgrade runs.`);
241
248
  }
242
- const readOnlyCount = result.plan.filter((item) => item.name !== EXECUTOR_VEHICLE).length;
243
- lines.push(
244
- `${readOnlyCount} vehicles are Claude Code subagents with READ-ONLY tools and NO shell as bundled or derived (a customized file keeps whatever it grants) — so a fan-out on the shipped templates can never turn into a wave of approval prompts.`,
245
- `three of those ride the cheap lane (model: haiku, effort: low) for mechanical work; ${FALLBACK_LENS_ADDITIONAL_ONLY}`,
246
- 'executor is the one FULL-TOOL vehicle: dispatched only for a bounded execution, authoring, or write-capable routine slice the orchestrator verifies, never for read-only work, and it never commits.',
247
- `executor posture: model=${safeLine(posture.model)} effort=${safeLine(posture.effort)} fallback=${safeLine(posture.fallback)} (source: ${safeLine(posture.source)}) — set in docs/ai/vehicles.json`,
248
- `review-lens posture: model=${safeLine(lensPosture.model)} effort=${safeLine(lensPosture.effort)} (source: ${safeLine(lensPosture.source)}) — set in docs/ai/vehicles.json`,
249
- );
249
+ if (!result.executorOnly) {
250
+ const readOnlyCount = result.plan.filter((item) => item.name !== EXECUTOR_VEHICLE).length;
251
+ lines.push(
252
+ `${readOnlyCount} vehicles are Claude Code subagents with READ-ONLY tools and NO shell as bundled or derived (a customized file keeps whatever it grants) — so a fan-out on the shipped templates can never turn into a wave of approval prompts.`,
253
+ `three of those ride the cheap lane (model: haiku, effort: low) for mechanical work; ${FALLBACK_LENS_ADDITIONAL_ONLY}`,
254
+ 'executor is the one FULL-TOOL vehicle: dispatched only for a bounded execution, authoring, or write-capable routine slice the orchestrator verifies, never for read-only work, and it never commits.',
255
+ );
256
+ }
257
+ lines.push(`executor posture: model=${safeLine(posture.model)} effort=${safeLine(posture.effort)} fallback=${safeLine(posture.fallback)} (source: ${safeLine(posture.source)}) — set in docs/ai/vehicles.json`);
258
+ if (!result.executorOnly) {
259
+ lines.push(`review-lens posture: model=${safeLine(lensPosture.model)} effort=${safeLine(lensPosture.effort)} (source: ${safeLine(lensPosture.source)}) — set in docs/ai/vehicles.json`);
260
+ }
250
261
  // A preview must print the EXACT command that applies it. The advisor renders this dry-run as an
251
262
  // item's one-liner, and that flow's contract is "run the printed command, no improvisation" — a
252
263
  // bare "re-run with --apply" would leave the caller to reconstruct --cwd and its quoting.
253
264
  if (result.dryRun && result.plan.some((item) => item.action === 'place' || item.action === 're-derive')) {
254
- lines.push(`to apply, run exactly: ${applyCheapAgentsCommand(result.projectDir)}`);
265
+ lines.push(`to apply, run exactly: ${applyCheapAgentsCommand(result.projectDir, result.executorOnly)}`);
255
266
  }
256
- if (!result.dryRun && result.wrote) {
267
+ if (!result.dryRun && result.wrote && !result.executorOnly) {
257
268
  lines.push('hidden-mode note: if this deployment is hidden, run the hide-footprint reconcile so the placed files stay out of `git status`.');
258
269
  }
259
270
  return lines.join('\n');
@@ -262,12 +273,13 @@ export const formatResult = (result) => {
262
273
  // ── CLI ───────────────────────────────────────────────────────────────────────────────
263
274
 
264
275
  export const parseArgs = (argv) => {
265
- const opts = { dryRunFlag: false, apply: false, cwd: undefined, help: false };
276
+ const opts = { dryRunFlag: false, apply: false, executorOnly: false, cwd: undefined, help: false };
266
277
  for (let i = 0; i < argv.length; i += 1) {
267
278
  const arg = argv[i];
268
279
  if (arg === '--help' || arg === '-h') opts.help = true;
269
280
  else if (arg === '--dry-run') opts.dryRunFlag = true;
270
281
  else if (arg === '--apply') opts.apply = true;
282
+ else if (arg === '--executor') opts.executorOnly = true;
271
283
  else if (arg === '--cwd') {
272
284
  i += 1;
273
285
  if (argv[i] === undefined || argv[i].startsWith('-')) throw fail(EXIT_USAGE, '--cwd needs a directory argument');
@@ -277,7 +289,7 @@ export const parseArgs = (argv) => {
277
289
  }
278
290
  }
279
291
  if (opts.dryRunFlag && opts.apply) throw fail(EXIT_USAGE, '--dry-run and --apply cannot be used together');
280
- return { help: opts.help, dryRun: !opts.apply, cwd: opts.cwd };
292
+ return { help: opts.help, dryRun: !opts.apply, executorOnly: opts.executorOnly, cwd: opts.cwd };
281
293
  };
282
294
 
283
295
  export const main = (argv = process.argv.slice(2), deps = {}) => {
@@ -289,7 +301,7 @@ export const main = (argv = process.argv.slice(2), deps = {}) => {
289
301
  log(USAGE);
290
302
  return EXIT_OK;
291
303
  }
292
- const result = writeCheapAgents({ cwd: args.cwd ?? process.cwd(), dryRun: args.dryRun }, deps);
304
+ const result = writeCheapAgents({ cwd: args.cwd ?? process.cwd(), dryRun: args.dryRun, executorOnly: args.executorOnly }, deps);
293
305
  log(formatResult(result));
294
306
  return EXIT_OK;
295
307
  } catch (err) {
@@ -2,5 +2,4 @@
2
2
  // import, each the very export of the leaf that owns it. No kit module outside this directory
3
3
  // imports a leaf directly.
4
4
 
5
- export { keptAsidePath, replaceBlock, runReplace } from './replace-set.mjs';
6
- export { SCRIPT_CHANNEL, ensureScripts } from './scripts.mjs';
5
+ export { SCRIPT_CHANNEL, ensureScripts, fileLine, hookLine } from './scripts.mjs';
@@ -5,7 +5,7 @@
5
5
  // question and no copy kept; a current one is left. The installer set is written first; after the last
6
6
  // write the project's own rotator brings the ADR store current (`--ensure-current`). It never imports
7
7
  // ensure-specs.mjs or ensure-configs.mjs: the CLI composes this op from the module's index, and
8
- // ensure-specs.mjs takes its channel from there.
8
+ // ensure-specs.mjs takes its channel and its lines from there.
9
9
  //
10
10
  // Dependency-free, Node >= 22. Every fs primitive and the spawn are injectable (deps.*). No side effects on import.
11
11
 
@@ -16,6 +16,7 @@ import { lstatNoFollow, writeContainedFileAtomic, writeProjectFileCreateOnly } f
16
16
  import { composeFailure, composeOutcome, nodeEvidenceRefusal, probeSeedTarget, tmpNote } from '../ensure-ops.mjs';
17
17
  import { BUNDLED_SCRIPT_NAMES } from '../node-evidence.mjs';
18
18
  import { CHECKER_PAIR, INSTALLER_SET, READER_PAIR, SCRIPT_PRIORS, classifyDeployedScript } from '../script-priors.mjs';
19
+ import { VEHICLES_REL } from '../vehicle-settings.mjs';
19
20
 
20
21
  const OP = 'scripts';
21
22
  const SCRIPTS_DIR = 'scripts';
@@ -23,6 +24,7 @@ const BUNDLED = ['references', 'scripts'];
23
24
  // Where an edit meant to last goes: the installer's in the local hook file, every other file's beside it.
24
25
  export const SCRIPT_CHANNEL = 'a script or suite of your own under its own name in scripts/, or a config the script reads';
25
26
  export const LOCAL_HOOK_CHANNEL = 'the local hook file scripts/pre-commit.local, which the commit hook runs first';
27
+ export const VEHICLE_CHANNEL = VEHICLES_REL;
26
28
  // The family files memory copies on Node evidence alone, accepted or not (the suite derives them).
27
29
  export const SEED_NAMES = Object.freeze(['_expect-shim.mjs', 'archive-decisions.mjs', 'archive-decisions.test.mjs', 'markdown-blocks.mjs']);
28
30
  const ROTATOR = 'archive-decisions.mjs';
@@ -76,18 +78,21 @@ const survey = ({ cwd, kitRoot, deps, read, lstat }) => {
76
78
  // ── the lines (composed from what HAPPENED: each file's state and the fate of its write) ─────────
77
79
 
78
80
  // A fate is `written`, `stood` (an absent file that appeared with the bundled body), `refused` (its
79
- // write failed), or none: the run stopped before it, or, dry, would write it.
80
- const VERBS = { prior: ['refreshed', 'refreshed to the bundled one'], custom: ['replaced', 'replaced by the bundled body'], absent: ['placed', 'placed from the bundled scripts'] };
81
- const HEADS = { prior: 'matches a body an earlier release shipped', custom: 'differs from every body this kit knows it shipped', absent: 'absent' };
82
- const fileLine = (f, fate, dryRun) => {
81
+ // write failed), or none: the run stopped before it, or, dry, would write it. The spec layer's pair
82
+ // lines are these too, through the module's index.
83
+ const VERBS = { prior: ['refreshed', 'refreshed to the bundled one'], custom: ['replaced', 'replaced by the bundled body'], absent: ['placed', 'placed from the bundled scripts'], derived: ['written', 'written with that body'] };
84
+ const HEADS = { prior: 'matches a body an earlier release shipped', custom: 'differs from every body this kit knows it shipped', absent: 'absent', derived: 'differs from the body derived from the vehicle settings' };
85
+ const channelOf = (f) => (f.state === 'derived' ? `; its model and effort are set in ${VEHICLE_CHANNEL}`
86
+ : f.state === 'custom' ? `; an edit meant to last goes in ${f.name === INSTALLER_SET[0] ? LOCAL_HOOK_CHANNEL : SCRIPT_CHANNEL}` : '');
87
+ export const fileLine = (f, fate, dryRun) => {
83
88
  if (fate === 'stood') return `${f.rel}: appeared while this run was placing it — the bundled body stands, nothing written`;
84
89
  const [verb, done] = VERBS[f.state];
85
90
  const tail = fate === 'written' ? done : dryRun ? `would be ${done}` : `not ${verb}; ${fate === 'refused' ? 'its write was refused (above)' : 'the run stopped before it'}`;
86
- return `${f.rel}: ${HEADS[f.state]} — ${tail}${f.state === 'custom' ? `; an edit meant to last goes in ${f.name === INSTALLER_SET[0] ? LOCAL_HOOK_CHANNEL : SCRIPT_CHANNEL}` : ''}`;
91
+ return `${f.rel}: ${HEADS[f.state]} — ${tail}${channelOf(f)}`;
87
92
  };
88
93
  const NOT_ACCEPTED = `${SCRIPTS_DIR}/: the enforcement scripts were not accepted in this project, so no other kit script is placed`;
89
94
  // The hook-run line, once after the file lines of a run that wrote (or, dry, would write) a file.
90
- const hookLine = (accepted, dryRun) => (accepted
95
+ export const hookLine = (accepted, dryRun) => (accepted
91
96
  ? (dryRun ? 'the commit hook runs the files named above, so writing them may stop the next commit' : 'the commit hook runs the files written above, so they may stop the next commit')
92
97
  : (dryRun ? 'if a commit hook runs the files named above, writing them may stop the next commit' : 'if a commit hook runs the files written above, they may stop the next commit'));
93
98
  const partialNote = (count) => (count > 0 ? [`the writes stopped PARTWAY — the ${count} file(s) named above were already written and are NOT rolled back`] : []);
@@ -10,9 +10,9 @@
10
10
  // + the installer set written with no question and no copy kept; installer set first; on a
11
11
  // declined offer only the standing seed files and the modules they import;
12
12
  // then the project's rotator brings the ADR store current (--ensure-current)
13
- // specs scripts/<spec layer> reader + checker pairs seeded when absent, refreshed only on
14
- // + docs/ai/specs/index.md a shipped prior body, an edited one replaced only on the
15
- // user's yes; store root seeded behind a current checker
13
+ // specs scripts/<spec layer> reader + checker pairs, with no question and no copy kept:
14
+ // + docs/ai/specs/index.md a shipped prior refreshed, an edited one replaced, an absent
15
+ // one placed; then the store root seeded create-only
16
16
  // rules docs/ai/rules/<theme>.md the kit file seeded, refreshed on a shipped prior body, or any
17
17
  // + effective/ + sources.json other body replaced, with no question and no copy kept; with no
18
18
  // local file the effective copy and its record rebuilt; with one
@@ -29,12 +29,7 @@
29
29
  // • --reconcile is REQUIRED. A bare run is a usage error, so nothing writes by accident.
30
30
  // • --dry-run reports `would-*` tokens and writes nothing — never a write token.
31
31
  // • The ops run in a FIXED order and one op's failure NEVER skips the rest: every op reports its own
32
- // token, and the exit is non-zero when any of them failed. The one exception is the replace run
33
- // (--replace-custom <digest>), which distribution-files/ runs: each edit kept aside, then the
34
- // owning op (specs), then index only when none failed.
35
- // • ONE replace block, after every op's lines and before the failure footer, over the union the
36
- // replace run recomputes: the spec-layer files whose write waits for the user's yes, and the one
37
- // command for it.
32
+ // token, and the exit is non-zero when any of them failed.
38
33
  // • The deployment gate runs ONCE, before any op: an absent/symlinked docs/ai stops the whole run
39
34
  // with the gate's own message rather than one copy of it per op.
40
35
  //
@@ -52,15 +47,13 @@ import { ensureExecutor } from './ensure-executor.mjs';
52
47
  import { ENSURE_OPS, OWN_IMPLEMENTATIONS, failedOutcome } from './ensure-ops.mjs';
53
48
  import { ensureSpecs } from './ensure-specs.mjs';
54
49
  import { ensureRules } from './project-rules/index.mjs';
55
- import { ensureScripts, replaceBlock, runReplace } from './distribution-files/index.mjs';
50
+ import { ensureScripts } from './distribution-files/index.mjs';
56
51
 
57
52
  const KIT_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..');
58
53
 
59
54
  // The op table this CLI walks — name → implementation, in ENSURE_OPS order. Composed HERE (the one
60
55
  // consumer) because the executor, scripts, spec-layer and rules ensures import ensure-ops.mjs for their outcome door and probes.
61
56
  export const ENSURE_IMPLEMENTATIONS = Object.freeze({ ...OWN_IMPLEMENTATIONS, executor: ensureExecutor, scripts: ensureScripts, specs: ensureSpecs, rules: ensureRules });
62
- // The ops whose writes wait for the user's yes and so own the replace run, in ENSURE_OPS order.
63
- const OWNING_OPS = ['specs'];
64
57
 
65
58
  const EXIT_OK = 0;
66
59
  const EXIT_FAILED = 1;
@@ -72,34 +65,24 @@ const EMPTY_CWD = '--cwd needs a path argument (an empty value would silently me
72
65
  const EMPTY_ONLY = `--only needs one operation name (${ENSURE_OPS.join(' | ')}) — an empty value would silently widen the run`;
73
66
  const REPEATED_ONLY = '--only was passed more than once — this selector names exactly ONE operation';
74
67
  const unknownOp = (value) => `--only ${value}: no such operation (${ENSURE_OPS.join(' | ')}) — nothing was run`;
75
- const EMPTY_REPLACE = '--replace-custom needs the digest its replace line printed — an empty value names no file to replace';
76
- const REPEATED_REPLACE = '--replace-custom was passed more than once — a replace run carries exactly ONE digest';
77
- const REPLACE_WITH_ONLY = '--replace-custom runs the spec layer, then the navigator, so it cannot be combined with --only — nothing was run';
78
- const REPLACE_WITH_DRY_RUN = "--replace-custom writes on the user's yes, so it cannot be combined with --dry-run — nothing was run";
79
68
 
80
69
  const HELP = `ensure-configs — the nine stamp-independent upgrade ensures, as ONE command.
81
70
 
82
71
  Usage:
83
72
  node ensure-configs.mjs --reconcile [--dry-run] [--only <op>] [--cwd <project>]
84
- node ensure-configs.mjs --reconcile --replace-custom <digest> [--cwd <project>]
85
73
 
86
74
  --reconcile required — run the nine ensures (${ENSURE_OPS.join(', ')})
87
75
  --dry-run report what each ensure WOULD do; write nothing
88
76
  --only <op> run EXACTLY ONE of them (an unknown, missing or repeated value is a usage error)
89
- --replace-custom <digest>
90
- the replace run the replace block prints, run only on the user's yes: every edit its
91
- digest names is kept aside under .agent-workflow/kept-aside/, then the spec layer
92
- replaces and places its files, then index runs when nothing failed (not with --only or
93
- --dry-run; an empty value is a usage error)
94
77
  --cwd <dir> the target project (default: the current directory)
95
78
  --help, -h this help
96
79
 
97
80
  Every SEED is CREATE-ONLY: an existing file is preserved byte-for-byte, never clobbered and never
98
81
  refreshed in place. Four ops refresh instead: the orchestration onboarding note, only while it still
99
82
  matches a canonical the kit shipped (your own wording is preserved verbatim); the spec-layer reader
100
- and checker pairs, only while a file's bytes are a body a release shipped (an edited file is
101
- preserved, the writes that depend on it — the spec store root included — are withheld behind it,
102
- and ONE printed replace block keeps every edit aside and replaces it only on the user's yes); the project rules
83
+ and checker pairs, with no question and no copy kept: a body a release shipped is refreshed, an
84
+ edited one replaced (its line names where an edit meant to last goes) and an absent one placed,
85
+ the reader pair, then the checker pair, then the spec store root seeded create-only; the project rules
103
86
  kit file, refreshed while its bytes are a body a release shipped and any other body replaced by the template,
104
87
  with no question and no copy kept, the effective file rebuilt as its copy and recorded where no local file
105
88
  exists; and the navigator index — a GENERATED artifact, regenerated
@@ -107,7 +90,7 @@ whenever it is missing or stale; where a module the project's hook loads is not
107
90
  the project's own checker judges the navigator and a write it rejects is put back byte for byte.
108
91
  The executor ensure writes nothing: a placed .claude/agents/executor.md whose bytes differ from the
109
92
  body derived from docs/ai/vehicles.json is pending — the advisor's executor-vehicle.differing item
110
- changes it on your yes; an absent file is never placed here.
93
+ writes the derived body with no question; an absent file is never placed here.
111
94
  A fifth writes too: once a kit script outside the seed names stands in scripts/, the enforcement-script
112
95
  ensure writes every kit script that is not the bundled body, the hook installer and its two suites
113
96
  first, with no question and no copy kept: a body a release shipped is refreshed, an edited one replaced
@@ -121,7 +104,7 @@ Exit codes: 0 every op fine; 1 an op failed (its line says so) or there is no de
121
104
  // argv → { reconcile, dryRun, cwd, help }. Order-independent; an unknown flag or a missing --cwd
122
105
  // value is a usage error, never a silently-ignored argument.
123
106
  export const parseArgs = (argv) => {
124
- const out = { reconcile: false, dryRun: false, cwd: undefined, only: undefined, replaceCustom: undefined, help: false };
107
+ const out = { reconcile: false, dryRun: false, cwd: undefined, only: undefined, help: false };
125
108
  for (let i = 0; i < argv.length; i += 1) {
126
109
  const a = argv[i];
127
110
  if (a === '--help' || a === '-h') out.help = true;
@@ -138,13 +121,6 @@ export const parseArgs = (argv) => {
138
121
  if (!ENSURE_OPS.includes(value)) throw fail(EXIT_USAGE, unknownOp(value));
139
122
  out.only = value;
140
123
  if (!inline) i += 1;
141
- } else if (a === '--replace-custom' || a.startsWith('--replace-custom=')) {
142
- if (out.replaceCustom !== undefined) throw fail(EXIT_USAGE, REPEATED_REPLACE);
143
- const inline = a.startsWith('--replace-custom=');
144
- const value = inline ? a.slice('--replace-custom='.length) : argv[i + 1];
145
- if (value === undefined || value === '' || (!inline && value.startsWith('-'))) throw fail(EXIT_USAGE, EMPTY_REPLACE);
146
- out.replaceCustom = value;
147
- if (!inline) i += 1;
148
124
  } else if (a === '--cwd') {
149
125
  // An EMPTY value resolves to the ambient cwd — a writing CLI would then act on a different
150
126
  // project than the caller named, silently. Both spellings refuse it.
@@ -161,8 +137,6 @@ export const parseArgs = (argv) => {
161
137
  if (!out.help && !out.reconcile) {
162
138
  throw fail(EXIT_USAGE, 'nothing to do — pass --reconcile (see --help). This tool never writes without it.');
163
139
  }
164
- if (out.replaceCustom !== undefined && out.only !== undefined) throw fail(EXIT_USAGE, REPLACE_WITH_ONLY);
165
- if (out.replaceCustom !== undefined && out.dryRun) throw fail(EXIT_USAGE, REPLACE_WITH_DRY_RUN);
166
140
  return out;
167
141
  };
168
142
 
@@ -176,30 +150,19 @@ const runOne = (op, args) => {
176
150
 
177
151
  // Run every op in ENSURE_OPS order. A throw from one op becomes THAT op's failed outcome — the
178
152
  // remaining ops still run, because a project missing its gate declaration should not also be left
179
- // without its autonomy seed just because the first ensure hit an unreadable file. → { outcomes, block }:
180
- // the block is the union the replace run recomputes, the entries of the owning op. The replace run is
181
- // the one exception, handed to runReplace: it keeps every edit aside, runs the owning op, then index
182
- // only when it did not fail, and its block is non-empty only when the digest no longer matches.
183
- export const runEnsures = ({ cwd, kitRoot, dryRun, deps, only, replaceCustom }) => {
184
- if (replaceCustom !== undefined) {
185
- const owning = OWNING_OPS.map((op) => ({ op, run: (args) => runOne(op, args) }));
186
- return runReplace({ cwd, kitRoot, digest: replaceCustom, owning, index: (args) => runOne('index', args), deps });
187
- }
188
- const outcomes = (only ? [only] : ENSURE_OPS).map((op) => runOne(op, { cwd, kitRoot, dryRun, deps }));
189
- return { outcomes, block: outcomes.flatMap((o) => o.entries ?? []) };
190
- };
153
+ // without its autonomy seed just because the first ensure hit an unreadable file. → the outcomes.
154
+ export const runEnsures = ({ cwd, kitRoot, dryRun, deps, only }) =>
155
+ (only ? [only] : ENSURE_OPS).map((op) => runOne(op, { cwd, kitRoot, dryRun, deps }));
191
156
 
192
- const render = ({ outcomes, block }, { dryRun, only, replace, kitRoot, cwd }) => {
157
+ const render = (outcomes, { dryRun, only }) => {
193
158
  // The banner names the tool + the flag it ran under (both machine tokens the L2 rule exempts);
194
159
  // the failure footer is a user-grade sentence — the composed-lines guard scans both.
195
- const scope = only ? `, --only ${only}` : replace ? ', --replace-custom' : '';
160
+ const scope = only ? `, --only ${only}` : '';
196
161
  const lines = [dryRun ? `ensure-configs (--reconcile${scope}, dry run — nothing written)` : `ensure-configs (--reconcile${scope})`];
197
162
  for (const o of outcomes) {
198
163
  lines.push(` ${o.op}: ${o.token}`);
199
164
  for (const detail of o.lines) lines.push(` ${detail}`);
200
165
  }
201
- const blockLines = replaceBlock(block, { kitRoot, cwd });
202
- if (blockLines.length > 0) lines.push('', ...blockLines.map((line) => ` ${line}`));
203
166
  if (outcomes.some((o) => o.failed)) {
204
167
  // No blanket claim about what was written: an op that copies file by file can stop PARTWAY, and
205
168
  // its own lines are the only accurate account of what landed.
@@ -218,10 +181,10 @@ export const main = (argv = [], ctx = {}) => {
218
181
  // reconcile, and one identical STOP per op would read as that many separate problems.
219
182
  assertDocsAiDeployment(cwd, deps, { noun: 'the project configuration', rel: 'under docs/ai' });
220
183
  const kitRoot = ctx.kitRoot ?? KIT_ROOT;
221
- const run = runEnsures({ cwd, kitRoot, dryRun: args.dryRun, deps, only: args.only, replaceCustom: args.replaceCustom });
184
+ const outcomes = runEnsures({ cwd, kitRoot, dryRun: args.dryRun, deps, only: args.only });
222
185
  return {
223
- code: run.outcomes.some((o) => o.failed) ? EXIT_FAILED : EXIT_OK,
224
- stdout: render(run, { dryRun: args.dryRun, only: args.only, replace: args.replaceCustom !== undefined, kitRoot, cwd }),
186
+ code: outcomes.some((o) => o.failed) ? EXIT_FAILED : EXIT_OK,
187
+ stdout: render(outcomes, { dryRun: args.dryRun, only: args.only }),
225
188
  stderr: '',
226
189
  };
227
190
  } catch (err) {
@@ -1,7 +1,7 @@
1
1
  // ensure-executor.mjs — the EIGHTH upgrade ensure, fifth in the fixed order right after `vehicles`:
2
2
  // the placed executor vehicle (.claude/agents/executor.md) judged against the body derived from
3
3
  // docs/ai/vehicles.json. It never writes: the agents writer PLACES the vehicle on consent, and a placed
4
- // body that differs is reported `pending` — the advisor's executor-vehicle.differing item re-derives it.
4
+ // body that differs is reported `pending` — the advisor's executor-vehicle.differing item writes it.
5
5
  //
6
6
  // The state table, in the order the cells are proven:
7
7
  // | cell | .claude, .claude/agents | placed path | docs/ai/vehicles.json | answer | read before answering |
@@ -66,5 +66,5 @@ export const ensureExecutor = ({ cwd, kitRoot, deps = {} }) => {
66
66
  if (!executorBodyDiffers(cwd, bundleDeps)) {
67
67
  return ok('already-current', [`${EXECUTOR_VEHICLE_REL}: the body derived from ${VEHICLES_REL} (model=${posture.model}, effort=${posture.effort}, source ${posture.source}) — nothing written`]);
68
68
  }
69
- return ok('pending', [`${EXECUTOR_VEHICLE_REL}: differs from the body derived from ${VEHICLES_REL} — nothing written; the advisor's executor-vehicle.differing item re-derives it on your yes`]);
69
+ return ok('pending', [`${EXECUTOR_VEHICLE_REL}: differs from the body derived from ${VEHICLES_REL} — nothing written; the advisor's executor-vehicle.differing item, which the agent applies with no question, writes the derived body`]);
70
70
  };
@@ -253,6 +253,7 @@ const describeExitWithOutput = (result, subject = 'it') => `${subject} exited ${
253
253
  const HOOK_MODULES = ['check-docs-size.mjs', 'spec-schema.mjs'];
254
254
  const KEPT_JUDGE = `the project's own checker (${SCRIPTS_DIR}/check-docs-size.mjs --check-index)`;
255
255
  const KEPT_FITS = `in sync under ${KEPT_JUDGE} and within the maxLines it stamps`;
256
+ const KEPT_ROUTE = "the spec layer's write of the bundled modules the project's hook loads, then this step again";
256
257
  const KEPT_PROBE_TIMEOUT_MS = 30_000;
257
258
  const countLines = (text) => text.split('\n').length - (text.endsWith('\n') ? 1 : 0);
258
259
  const readStampedCap = (text) => { const value = parseFrontmatter(text)?.maxLines; const cap = value ? Number(value) : NaN; return Number.isNaN(cap) ? undefined : cap; };
@@ -298,14 +299,12 @@ const putBackIndex = (cwd, found, deps) => {
298
299
  return null;
299
300
  };
300
301
 
301
- const ensureKeptIndex = ({ cwd, kitRoot, drive, spawn, read, lstat, deps, hook }) => {
302
+ const ensureKeptIndex = ({ cwd, drive, spawn, read, lstat, deps }) => {
302
303
  const judge = () => judgeKept({ cwd, spawn, read, lstat, deps });
303
304
  const reportUnanswered = (verdict, after) => loud('index', 'index-probe-failed', `${INDEX_REL}: ${KEPT_JUDGE} could not be launched or did not answer in time (${verdict.error}) — ${after}`);
304
305
  const first = judge();
305
306
  if (first.error) return reportUnanswered(first, 'nothing was written');
306
307
  if (first.accepted) return ok('index', 'already-current', `${INDEX_REL}: ${KEPT_FITS} — nothing written`);
307
- const custom = [...hook, ...['check-docs-size.test.mjs', 'spec-schema.test.mjs'].map((name) => surveyHookModule(cwd, kitRoot, name, read, lstat))].filter((entry) => entry.state === 'custom').map((entry) => entry.rel).sort();
308
- const route = custom.length > 0 ? `the replace line printed for the spec layer (${custom.join(', ')}), run on the user's yes` : "the spec layer's refresh of the modules the project's hook loads, then this step again";
309
308
  const found = lstatNoFollow(join(cwd, INDEX_REL), lstat) === null ? null : read(join(cwd, INDEX_REL));
310
309
  const restored = found === null ? 'the navigator was put back: found absent, it was removed again' : 'the navigator was put back byte for byte';
311
310
  const restoreThen = (failure, compose) => {
@@ -323,7 +322,7 @@ const ensureKeptIndex = ({ cwd, kitRoot, drive, spawn, read, lstat, deps, hook }
323
322
  try { second = judge(); } catch (err) { return restoreThen(`the navigator could not be read back (${causeOf(err)})`, () => loud('index', 'unexpected-error', `${INDEX_REL}: the navigator could not be read back after the bundled write (${causeOf(err)}) — ${restored}`)); }
324
323
  if (second.error) return restoreThen(`${KEPT_JUDGE} could not answer (${second.error})`, () => reportUnanswered(second, restored));
325
324
  if (second.accepted) return ok('index', 'regenerated', `${INDEX_REL}: written by the bundled generator — ${KEPT_FITS}`);
326
- return restoreThen(null, () => ok('index', 'customized-preserved', `${INDEX_REL}: ${KEPT_JUDGE} rejected the bundled render on ${second.half} (${second.said}), and the navigator as found did not pass it either (${first.half}) — ${restored}. The route: ${route}`));
325
+ return restoreThen(null, () => ok('index', 'customized-preserved', `${INDEX_REL}: ${KEPT_JUDGE} rejected the bundled render on ${second.half} (${second.said}), and the navigator as found did not pass it either (${first.half}) — ${restored}. The route: ${KEPT_ROUTE}`));
327
326
  };
328
327
 
329
328
  const buildKeptDryRunNote = (hook) =>
@@ -348,7 +347,7 @@ export const ensureIndex = ({ cwd, kitRoot, dryRun = false, deps = {} }) => {
348
347
  const kept = hook[0].state !== 'absent' && !hook.every((entry) => entry.state === 'current');
349
348
  const unreadable = kept && hook.find((entry) => entry.state === 'bundle-unreadable');
350
349
  if (unreadable) return loud('index', 'bundle-unreadable', `${unreadable.rel}: the bundled module could not be read, so nothing was written — reinstall the kit. ${unreadable.error}`);
351
- if (kept && !dryRun) return ensureKeptIndex({ cwd, kitRoot, drive, spawn, read, lstat, deps, hook });
350
+ if (kept && !dryRun) return ensureKeptIndex({ cwd, drive, spawn, read, lstat, deps });
352
351
  const dryNote = kept ? [buildKeptDryRunNote(hook)] : [];
353
352
  if (dryRun) {
354
353
  const check = drive('--check-index');