@sabaiway/agent-workflow-kit 17.0.0 → 19.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.
@@ -23,20 +23,17 @@
23
23
  // is a STOP with ZERO writes, never a merge-through-clobber;
24
24
  // • place-then-wire ORDER — the hook file is placed BEFORE settings are wired (a
25
25
  // wired-but-missing hook would error on every Bash call);
26
- // • a target hook file with DIFFERENT content while our entry is NOT wired is a precondition
27
- // STOP for `--apply` (no file write, no settings mutation — wiring an unknown script as a
28
- // PreToolUse hook is exactly what consent must not slide past); the recovery is named: the
29
- // reseed route. An identical file is `already current`; an already-wired entry pointing at a
30
- // diverged file is REPORTED, never unwired by `--apply`. A diverged hook is never clobbered
31
- // except by `--apply --reseed`, the one consented replacement: it writes the bundled bytes in
32
- // place over a placed hook and wires the entry only while it is wired in neither file;
26
+ // • the kit's hook file is written current: placed create-only when absent, a differing one
27
+ // written with the bundled body in place (no copy kept), an identical one `already current`;
28
+ // the entry is wired only while it is wired in neither settings file, so over a wired hook the
29
+ // apply writes only the file. Every printed recovery of a stale hook is `gate-hook --apply`;
33
30
  // • never writes settings.local.json; never commits.
34
31
  //
35
32
  // The `--read-lane` flag is a SEPARATE operation (AD-055 Part II): it enables the opt-in read-only
36
33
  // compound lane in docs/ai/lanes.json after a currency check, and never touches settings or
37
34
  // gates.json — see the read-lane writer section below.
38
35
  //
39
- // Exit codes: 0 done / dry-run (incl. the report-only diverged-but-wired state); 1 precondition
36
+ // Exit codes: 0 done / dry-run; 1 precondition
40
37
  // STOP; 2 usage. Dependency-free beyond the kit's own internal exports, Node >= 22. No side
41
38
  // effects on import.
42
39
 
@@ -56,6 +53,7 @@ import {
56
53
  } from './velocity-profile.mjs';
57
54
  import { assertDocsAiDeployment, writeDocsAiFileAtomic } from './atomic-write.mjs';
58
55
  import { isDirectRun } from './direct-run.mjs';
56
+ import { fileLine } from './distribution-files/index.mjs';
59
57
  import { shellQuoteArg } from './review-state.mjs';
60
58
 
61
59
  const HERE = dirname(fileURLToPath(import.meta.url));
@@ -100,7 +98,6 @@ const TARGET_CURRENT = 'already-current';
100
98
  const TARGET_DIVERGED = 'diverged';
101
99
 
102
100
  const USAGE = `usage: gate-hook [--dry-run | --apply] [--cwd <dir>] [--help]
103
- gate-hook --reseed [--dry-run | --apply] [--cwd <dir>] (replace a placed hook with the bundle)
104
101
  gate-hook --read-lane [--dry-run | --apply] [--cwd <dir>] (enable the opt-in read-only compound lane)
105
102
 
106
103
  Places the bundled PreToolUse gate-approval hook to ${HOOK_FILE_REL} and wires ONE
@@ -109,15 +106,14 @@ nothing). --apply writes. The hook auto-approves byte-exact declared gate cmds
109
106
  (docs/ai/gates.json, project root) and asks on seeded-read-only commands carrying the
110
107
  documented runtime residual.
111
108
 
112
- --reseed replaces a PLACED hook whose bytes differ from the bundle with the bundled bytes, in
113
- place, and wires the entry only while it is wired in neither settings file; a current hook wired
114
- in either settings file is nothing to change, and a current unwired one is only wired. It refuses
115
- an absent hook (--apply places it) and a symlinked or non-regular one.
109
+ --apply places an absent hook file, writes a differing one with the bundled body in place, leaves
110
+ a current one, and wires the entry only while it is wired in neither settings file. A symlinked or
111
+ non-regular hook file is refused.
116
112
 
117
113
  --read-lane enables the opt-in read-only COMPOUND lane in ${LANES_REL} ("${READ_LANE_KEY}": true) — the
118
114
  hook then auto-approves compounds of the seeded read-only core carrying zero shell metaprogramming.
119
115
  --apply --read-lane verifies the PLACED hook is the CURRENT bundle first (a pre-1.48 hook never reads
120
- ${LANES_REL}) and refuses otherwise, naming the reseed route (gate-hook --apply --reseed --cwd <dir>).
116
+ ${LANES_REL}) and refuses otherwise, naming the route that writes it (gate-hook --apply --cwd <dir>).
121
117
  Never touches ${SETTINGS_FILE} or docs/ai/gates.json.
122
118
 
123
119
  Never writes ${SETTINGS_LOCAL_FILE}; never commits.`;
@@ -268,7 +264,7 @@ export const mergeHookEntry = (base) => {
268
264
  return { ...root, hooks: { ...hooks, [PRE_TOOL_USE_EVENT]: [...entries, buildHookSettingsEntry()] } };
269
265
  };
270
266
 
271
- export const preflightGateHook = ({ cwd, reseed = false }, deps = {}) => {
267
+ export const preflightGateHook = ({ cwd }, deps = {}) => {
272
268
  const fs = fsDeps(deps);
273
269
  const projectDir = resolve(cwd ?? deps.cwd ?? process.cwd());
274
270
  const bundleContent = readBundledHook(deps);
@@ -277,12 +273,6 @@ export const preflightGateHook = ({ cwd, reseed = false }, deps = {}) => {
277
273
  assertDirSafe(join(projectDir, CLAUDE_DIR), CLAUDE_DIR, fs);
278
274
  assertDirSafe(join(projectDir, HOOKS_DIR), HOOKS_DIR, fs);
279
275
  const target = planTarget(join(projectDir, HOOK_FILE_REL), HOOK_FILE_REL, bundleContent, fs);
280
- if (reseed && target.action === TARGET_PLACE) {
281
- throw makeGateHookError(
282
- GATE_HOOK_STALE,
283
- `${HOOK_FILE_REL} is not placed — --reseed replaces a placed hook; place it with: ${applyGateHookCommand(projectDir)}`,
284
- );
285
- }
286
276
  assertSettingsWritable(join(projectDir, SETTINGS_FILE), fs);
287
277
  const projectSettings = readSettingsFile(join(projectDir, SETTINGS_FILE), { ...deps, cwd: projectDir });
288
278
  const localSettings = readSettingsFile(join(projectDir, SETTINGS_LOCAL_FILE), { ...deps, cwd: projectDir });
@@ -301,17 +291,6 @@ export const preflightGateHook = ({ cwd, reseed = false }, deps = {}) => {
301
291
 
302
292
  const wiredInProject = isHookWired(projectSettings.data);
303
293
  const wiredInLocal = isHookWired(localSettings.data);
304
- // Diverged target + our entry NOT wired anywhere = STOP on BOTH dry-run and apply: applying
305
- // would wire an unknown script as a PreToolUse hook — exactly what consent must not slide
306
- // past. (Diverged + already wired is the user's own standing state: report-only, below.) Under
307
- // --reseed this is exactly the state the reseed replaces before it wires.
308
- if (!reseed && target.action === TARGET_DIVERGED && !wiredInProject && !wiredInLocal) {
309
- throw makeGateHookError(
310
- GATE_HOOK_DIVERGED,
311
- `${HOOK_FILE_REL} exists with DIFFERENT content and is not wired — refusing to wire an unknown script as a PreToolUse hook; reseed it from the bundle: ${applyReseedCommand(projectDir)}`,
312
- );
313
- }
314
-
315
294
  return { projectDir, bundleContent, stamp, stampOk, target, projectSettings, localSettings, wiredInProject, wiredInLocal };
316
295
  };
317
296
 
@@ -320,13 +299,13 @@ export const preflightGateHook = ({ cwd, reseed = false }, deps = {}) => {
320
299
  export const formatJson = (data, eol) =>
321
300
  `${JSON.stringify(data, null, SETTINGS_JSON_INDENT).replace(JSON_NEWLINE_PATTERN, eol)}${eol}`;
322
301
 
323
- export const writeGateHook = ({ cwd, dryRun = true, reseed = false } = {}, deps = {}) => {
302
+ export const writeGateHook = ({ cwd, dryRun = true } = {}, deps = {}) => {
324
303
  const fs = fsDeps(deps);
325
- const preflight = preflightGateHook({ cwd: cwd ?? deps.cwd ?? process.cwd(), reseed }, deps);
304
+ const preflight = preflightGateHook({ cwd: cwd ?? deps.cwd ?? process.cwd() }, deps);
326
305
  const placePlanned = preflight.target.action === TARGET_PLACE;
327
- const reseedPlanned = reseed && preflight.target.action === TARGET_DIVERGED;
306
+ const replacePlanned = preflight.target.action === TARGET_DIVERGED;
328
307
  const wirePlanned = !preflight.wiredInProject && !preflight.wiredInLocal;
329
- const base = { placePlanned, reseedPlanned, wirePlanned, reseed, ...preflight };
308
+ const base = { placePlanned, replacePlanned, wirePlanned, ...preflight };
330
309
  if (dryRun) return { wrote: false, dryRun: true, ...base };
331
310
 
332
311
  if (!preflight.stampOk) {
@@ -342,7 +321,7 @@ export const writeGateHook = ({ cwd, dryRun = true, reseed = false } = {}, deps
342
321
  fs.mkdir(join(preflight.projectDir, HOOKS_DIR), { recursive: true });
343
322
  writeHookFile(hookAbs, HOOK_FILE_REL, preflight.bundleContent, true, fs);
344
323
  }
345
- if (reseedPlanned) writeHookFile(hookAbs, HOOK_FILE_REL, preflight.bundleContent, false, fs); // in place: the inode stays
324
+ if (replacePlanned) writeHookFile(hookAbs, HOOK_FILE_REL, preflight.bundleContent, false, fs); // in place: the inode stays
346
325
  if (wirePlanned) {
347
326
  // Re-verify the target no-follow immediately BEFORE wiring: preflight read it earlier, and an
348
327
  // external process could have swapped it (or slipped a symlink in) between preflight and now.
@@ -362,7 +341,7 @@ export const writeGateHook = ({ cwd, dryRun = true, reseed = false } = {}, deps
362
341
  UTF8,
363
342
  );
364
343
  }
365
- return { wrote: placePlanned || reseedPlanned || wirePlanned, dryRun: false, ...base };
344
+ return { wrote: placePlanned || replacePlanned || wirePlanned, dryRun: false, ...base };
366
345
  };
367
346
 
368
347
  // ── the read-lane writer (--read-lane; AD-055 Part II, Decisions 5/9) ──────────────────
@@ -372,7 +351,7 @@ export const writeGateHook = ({ cwd, dryRun = true, reseed = false } = {}, deps
372
351
  // merge-preserve, symlink/non-regular refusal, malformed-JSON fail-closed, atomic), PLUS a CURRENCY
373
352
  // CHECK (Decisions 9): --apply refuses unless the PLACED hook is byte-identical to the current
374
353
  // bundle — enabling a lane a pre-1.48 hook can never read would be a silent no-op the user paid
375
- // consent for. The refusal names the reseed route.
354
+ // consent for. The refusal names `gate-hook --apply`, which writes the hook current.
376
355
 
377
356
  const laneStop = (message) => makeGateHookError(GATE_HOOK_LANE, message);
378
357
 
@@ -411,7 +390,6 @@ const preflightLaneTarget = (absPath, deps) => {
411
390
  };
412
391
 
413
392
  export const applyGateHookCommand = (root) => `node ${q(GATE_HOOK_TOOL)} --apply --cwd ${q(root)}`;
414
- export const applyReseedCommand = (root) => `node ${q(GATE_HOOK_TOOL)} --apply --reseed --cwd ${q(root)}`;
415
393
  export const applyReadLaneCommand = (root) => `node ${q(GATE_HOOK_TOOL)} --read-lane --cwd ${q(root)} --apply`;
416
394
 
417
395
  // The currency check (Decisions 9): the PLACED hook must be byte-identical to the current bundle,
@@ -434,7 +412,7 @@ const checkHookCurrency = (root, bundleContent, fs) => {
434
412
  return {
435
413
  current: false,
436
414
  reason: `${HOOK_FILE_REL} is not the current bundle`,
437
- refusal: `${HOOK_FILE_REL} is NOT the current bundle — enabling the read-lane now would be a silent no-op (a pre-1.48 hook never reads ${LANES_REL}). Reseed it, then re-run with --read-lane:\n ${applyReseedCommand(root)}`,
415
+ refusal: `${HOOK_FILE_REL} is NOT the current bundle — enabling the read-lane now would be a silent no-op (a pre-1.48 hook never reads ${LANES_REL}). Write it current, then re-run with --read-lane:\n ${applyGateHookCommand(root)}`,
438
416
  };
439
417
  }
440
418
  return { current: true, reason: 'the placed hook is the current bundle' };
@@ -513,7 +491,7 @@ export const formatReadLaneResult = (result) => {
513
491
  lines.push(
514
492
  result.currency.current
515
493
  ? ' hook currency: current — the lane will fire once enabled.'
516
- : ` hook currency: STALE — ${result.currency.reason}; --apply will REFUSE until you reseed the placed hook.`,
494
+ : ` hook currency: STALE — ${result.currency.reason}; --apply will REFUSE until the hook is written current (${applyGateHookCommand(result.root)}).`,
517
495
  );
518
496
  if (!result.wired) {
519
497
  lines.push(` hook wiring: NOT wired into ${SETTINGS_FILE}; --apply will REFUSE until you wire it (${applyGateHookCommand(result.root)}).`);
@@ -534,8 +512,7 @@ const TRUST_POSTURE_LINE =
534
512
  const formatTargetLine = (result) => {
535
513
  if (result.target.action === TARGET_PLACE) return ` - ${HOOK_FILE_REL}: ${result.dryRun ? 'would place' : 'placed'}`;
536
514
  if (result.target.action === TARGET_CURRENT) return ` - ${HOOK_FILE_REL}: already current`;
537
- if (result.reseed) return ` - ${HOOK_FILE_REL}: ${result.dryRun ? 'would replace' : 'replaced'} with the bundle (it differed from the bundled runtime)`;
538
- return ` - ${HOOK_FILE_REL}: diverged from the bundle — preserved, never clobbered (already wired; reseed it from the bundle: ${applyReseedCommand(result.projectDir)})`;
515
+ return ` - ${fileLine({ rel: HOOK_FILE_REL, state: 'hook' }, result.dryRun ? undefined : 'written', result.dryRun)}`;
539
516
  };
540
517
 
541
518
  const formatSettingsLine = (result) => {
@@ -544,14 +521,9 @@ const formatSettingsLine = (result) => {
544
521
  return ` - ${SETTINGS_FILE}: ${result.dryRun ? 'would wire' : 'wired'} the ${PRE_TOOL_USE_EVENT} "${HOOK_MATCHER}" entry`;
545
522
  };
546
523
 
547
- const RESEED_CURRENT_LINE = 'nothing to change: the placed hook is current';
548
-
549
524
  export const formatResult = (result) => {
550
- if (result.reseed && !result.reseedPlanned && !result.wirePlanned) return RESEED_CURRENT_LINE;
551
525
  const lines = [
552
- result.dryRun
553
- ? `agent-workflow gate hook — DRY RUN (no changes; re-run with --apply${result.reseed ? ' --reseed' : ''})`
554
- : 'agent-workflow gate hook — APPLY',
526
+ result.dryRun ? 'agent-workflow gate hook — DRY RUN (no changes; re-run with --apply)' : 'agent-workflow gate hook — APPLY',
555
527
  formatTargetLine(result),
556
528
  formatSettingsLine(result),
557
529
  TRUST_POSTURE_LINE,
@@ -569,14 +541,13 @@ export const formatResult = (result) => {
569
541
  // ── CLI ───────────────────────────────────────────────────────────────────────────────
570
542
 
571
543
  export const parseArgs = (argv) => {
572
- const opts = { dryRunFlag: false, apply: false, cwd: undefined, help: false, readLane: false, reseed: false };
544
+ const opts = { dryRunFlag: false, apply: false, cwd: undefined, help: false, readLane: false };
573
545
  for (let i = 0; i < argv.length; i += 1) {
574
546
  const arg = argv[i];
575
547
  if (arg === '--help' || arg === '-h') opts.help = true;
576
548
  else if (arg === '--dry-run') opts.dryRunFlag = true;
577
549
  else if (arg === '--apply') opts.apply = true;
578
550
  else if (arg === '--read-lane') opts.readLane = true;
579
- else if (arg === '--reseed') opts.reseed = true;
580
551
  else if (arg === '--cwd') {
581
552
  i += 1;
582
553
  if (argv[i] === undefined || argv[i].startsWith('-')) throw fail(EXIT_USAGE, '--cwd needs a directory argument');
@@ -586,8 +557,7 @@ export const parseArgs = (argv) => {
586
557
  }
587
558
  }
588
559
  if (opts.dryRunFlag && opts.apply) throw fail(EXIT_USAGE, '--dry-run and --apply cannot be used together');
589
- if (opts.reseed && opts.readLane) throw fail(EXIT_USAGE, '--reseed and --read-lane cannot be used together');
590
- return { help: opts.help, dryRun: !opts.apply, cwd: opts.cwd, readLane: opts.readLane, reseed: opts.reseed };
560
+ return { help: opts.help, dryRun: !opts.apply, cwd: opts.cwd, readLane: opts.readLane };
591
561
  };
592
562
 
593
563
  export const main = (argv = process.argv.slice(2), deps = {}) => {
@@ -604,7 +574,7 @@ export const main = (argv = process.argv.slice(2), deps = {}) => {
604
574
  log(formatReadLaneResult(laneResult));
605
575
  return EXIT_OK;
606
576
  }
607
- const result = writeGateHook({ cwd: args.cwd ?? deps.cwd ?? process.cwd(), dryRun: args.dryRun, reseed: args.reseed }, deps);
577
+ const result = writeGateHook({ cwd: args.cwd ?? deps.cwd ?? process.cwd(), dryRun: args.dryRun }, deps);
608
578
  log(formatResult(result));
609
579
  return EXIT_OK;
610
580
  } catch (err) {
@@ -61,7 +61,7 @@ export const JEV_ERROR_MEANINGS = Object.freeze({
61
61
 
62
62
  // ── the vendor skill (part jev-skill) ─────────────────────────────────────────────────────────────
63
63
  // Each target file name -> the name the kit ships it under. The shipped SKILL.md is renamed so no agent
64
- // walking the kit's own tree (a skill folder itself) loads the vendor's text before the user's --apply.
64
+ // walking the kit's own tree (a skill folder itself) loads the vendor's text before an --apply places it.
65
65
  export const SKILL_FILES = Object.freeze({ 'SKILL.md': 'SKILL.md.pinned', LICENSE: 'LICENSE' });
66
66
  // Newest first; a release that moves the pin puts the new entry first and removes none.
67
67
  export const SKILL_PINS = Object.freeze([Object.freeze({
@@ -144,6 +144,9 @@ export const skillState = (target, io) => {
144
144
  }
145
145
  };
146
146
 
147
+ // The component is accepted exactly when a judged target reads current or earlier: a copy at a kit pin.
148
+ export const skillAccepted = (judged) => judged.some(({ state }) => state === 'current' || state === 'earlier');
149
+
147
150
  // The skill command's apply line, always with the Claude Code dir its caller resolved; '' when a path holds a control byte.
148
151
  export const skillLine = (toolsDir, platform, claudeDir) => {
149
152
  if ([...`${toolsDir}${claudeDir}`].some(isControl)) return '';
@@ -1,9 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
  // spec:jev-guide — docs/ai/specs/kit/jev-guide/jev-skill.md
3
3
  // The one command that installs the vendor's Jev skill, pinned and digest-checked, as a verified COPY into
4
- // the three agent skill roots. The USER runs it with --apply in a terminal of their own after their yes in
5
- // the chat; without --apply it is a read-only dry run. It reads no secret, needs no terminal, opens no
6
- // connection, never writes through a link below a base, and never removes what it did not mint this run.
4
+ // the three agent skill roots. Its --apply comes by four routes: the advisor's kit item, with no question
5
+ // beside a copy at a kit pin; the offer, on the chat yes after the danger check; init, on its terminal y;
6
+ // and the user's own terminal. Without --apply it is a read-only dry run. It reads no secret, needs no
7
+ // terminal, opens no connection, never writes through a link below a base, and never removes a leftover it
8
+ // did not mint this run.
7
9
  import { createHash } from 'node:crypto';
8
10
  import { lstatSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
9
11
  import { homedir } from 'node:os';
@@ -125,7 +127,7 @@ export const applyTarget = (entry, io) => {
125
127
  io.rm(aside, { recursive: true, force: true });
126
128
  } catch (error) { kept = codeOf(error); }
127
129
  }
128
- if (kept !== null) lines.push(`kept aside: ${printable(join(aside, 'typesafe-ai'))} — ${kept}`);
130
+ if (kept !== null) lines.push(`leftover: ${printable(join(aside, 'typesafe-ai'))} — ${kept}`);
129
131
  }
130
132
  return { lines, outcome: 'refused' };
131
133
  };
@@ -168,7 +170,7 @@ export const applyTarget = (entry, io) => {
168
170
  const old = { base: aside, path: join(aside, 'typesafe-ai') };
169
171
  const verified = skillState(old, io);
170
172
  if (verified.state === 'earlier') io.rm(aside, { recursive: true, force: true });
171
- else lines.push(`kept aside: ${printable(old.path)} — it reads ${verified.state}`);
173
+ else lines.push(`leftover: ${printable(old.path)} — it reads ${verified.state}`);
172
174
  lines.unshift(`replaced: ${path} (${entry.tag} → ${io.pins[0].tag})`);
173
175
  return { lines, outcome: 'replaced' };
174
176
  } catch (error) {