@sabaiway/agent-workflow-kit 21.0.0 → 22.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.
@@ -31,7 +31,9 @@
31
31
  // executes project-controlled tooling (a node_modules/.bin PATH shim intercepts under every
32
32
  // form) — the documented residual, disclosed in the preview, bounded by the two consents;
33
33
  // • a `node --test` suite body — the ONE allowlist member that produces lcov unaided — is
34
- // emitted WITH the canonical coverage reporters, so the offered checker has a producer; every
34
+ // emitted as the stable kit command's unit-tests name (spec coverage-producer), which adds the
35
+ // lcov reporter, so the offered checker has a producer — only while the project's kit folder
36
+ // holds THIS kit's run.mjs and a reporter, else it is withheld naming the upgrade; every
35
37
  // other body is emitted verbatim. The coverage-check candidate is WITHHELD (loud note) when
36
38
  // neither the offer nor the existing declaration carries a producer, and --apply refuses to
37
39
  // WRITE a declaration whose checker has no producer, is not last, or has a canonical twin:
@@ -62,8 +64,8 @@ import { fileURLToPath } from 'node:url';
62
64
  import { isDirectRun } from './direct-run.mjs';
63
65
  import { discoverGateCandidates, EXPECTED_WORKFLOW_VERSION } from './velocity-profile.mjs';
64
66
  import { GATES_REL, validateDeclaration } from './run-gates.mjs';
65
- import { canonicalCheckerGates, coverageDeclarationDefects, isKitOwnedCheckerGate } from './gates-declaration.mjs';
66
- import { COVERAGE_PRODUCER_BODY, isCoverageProducerGate } from './coverage-producer.mjs';
67
+ import { canonicalCheckerGates, coverageDeclarationDefects, coverageProducerPrecedes, isKitOwnedCheckerGate, NO_PRODUCER_REMEDY } from './gates-declaration.mjs';
68
+ import { COVERAGE_PRODUCER_BODY, guardRemedy, matchesCoverageProducer, unitTestsGuardFailure } from './coverage-producer.mjs';
67
69
  import { loadConfig } from './orchestration-config.mjs';
68
70
  import { assertDocsAiDeployment, writeDocsAiFileAtomic, lstatNoFollow } from './atomic-write.mjs';
69
71
  // The source-size practice, through its PURE READ core only (D-18): this module asks whether the
@@ -117,8 +119,9 @@ never watch/serve, never a write-mode variant) whose BODY is a member of the lit
117
119
  allowlist is offered, as the hook-free \`COREPACK_ENABLE_NETWORK=0 <pm> exec -- <body>\` form for
118
120
  the detected package manager. A gate-class script whose body is NOT in the allowlist is screened
119
121
  out with a note naming it (a command you trust can still be declared by hand); non-gate-class
120
- names are excluded silently, as always. A \`node --test\` body carries the canonical coverage
121
- reporters; the coverage-check candidate is withheld when nothing would produce the lcov it reads,
122
+ names are excluded silently, as always. A \`node --test\` body runs as ${COVERAGE_PRODUCER_BODY}
123
+ while the kit folder holds this kit's command and reporter (else it is withheld, naming
124
+ /agent-workflow-kit upgrade); the coverage-check candidate is withheld when nothing would produce the lcov it reads,
122
125
  and --apply refuses to write a checker with no producer, a checker that is not last, or a second
123
126
  canonical checker.
124
127
  ${TRUST_CHAIN_DISCLOSURE}`;
@@ -222,11 +225,15 @@ export const execCmdFor = (pm, body) => {
222
225
 
223
226
  // The coverage PRODUCER wiring (Decision 1 — closed-world here too). `node --test` is the only
224
227
  // allowlist body that produces lcov with no extra dependency, so it is the only body the offer
225
- // extends with the reporter flags; every other body is emitted verbatim and produces none (an
226
- // optional-dependency coverage flag set would be speculation about the project's own tooling).
228
+ // rewrites — into the stable kit command's unit-tests name; every other body is emitted verbatim
229
+ // and produces none (an optional-dependency coverage flag set would be speculation about the
230
+ // project's own tooling).
227
231
  const COVERAGE_PRODUCING_BODY = 'node --test';
228
232
  const emittedBodyOf = (body) => (body === COVERAGE_PRODUCING_BODY ? COVERAGE_PRODUCER_BODY : body);
229
233
 
234
+ // The unit-tests guard reads the project's kit folder against THIS kit's bundled run.mjs.
235
+ const KIT_RUN = join(HERE, '..', 'references', 'scripts', 'run.mjs');
236
+
230
237
  export const kebabIdOf = (name) =>
231
238
  String(name)
232
239
  .toLowerCase()
@@ -276,6 +283,8 @@ const deriveScripts = (cwd, deps = {}) => {
276
283
  const entries = [];
277
284
  const screenedIds = [];
278
285
  const withheld = [];
286
+ const guardWithheld = [];
287
+ let guard;
279
288
  for (const c of named) {
280
289
  const id = kebabIdOf(c.scriptName);
281
290
  if (!id || seen.has(id)) continue; // an empty or duplicate derived id never enters the offer
@@ -286,12 +295,16 @@ const deriveScripts = (cwd, deps = {}) => {
286
295
  continue;
287
296
  }
288
297
  const emitted = emittedBodyOf(body);
298
+ if (emitted !== body && (guard === undefined ? (guard = unitTestsGuardFailure(cwd, KIT_RUN, { lstatSync, readFileSync })) : guard) !== null) {
299
+ guardWithheld.push({ id, ...guard });
300
+ continue;
301
+ }
289
302
  const { cmd, note } = execCmdFor(pm, emitted);
290
303
  if (cmd === null) {
291
304
  withheld.push({ id, note });
292
305
  continue;
293
306
  }
294
- const coverage = emitted === body ? '' : ' (+ the lcov reporters the coverage checker reads)';
307
+ const coverage = emitted === body ? '' : ' (through the stable kit command, + the lcov reporter the coverage checker reads)';
295
308
  entries.push({ id, title: `Project script ${c.scriptName}: ${body}${coverage}`, cmd });
296
309
  }
297
310
  const notes = [];
@@ -304,7 +317,10 @@ const deriveScripts = (cwd, deps = {}) => {
304
317
  if (withheld.length) {
305
318
  notes.push(`${withheld.length} script gate(s) withheld: ${withheld.map((w) => w.id).join(', ')} — ${withheld[0].note}`);
306
319
  }
307
- return { entries, notes };
320
+ for (const { id, path, kind } of guardWithheld) {
321
+ notes.push(`script gate ${id} withheld: its node --test body runs as ${COVERAGE_PRODUCER_BODY}, and ${path} ${guardRemedy(kind, '/agent-workflow-kit upgrade')}`);
322
+ }
323
+ return { entries, notes, guardWithheld: guardWithheld.map(({ id, path }) => ({ id, path })) };
308
324
  };
309
325
 
310
326
  export const deriveScriptEntries = (cwd, deps = {}) => deriveScripts(cwd, deps).entries;
@@ -533,17 +549,15 @@ export const buildOffer = (cwd, deps = {}) => {
533
549
  // a declaration the user already wrote by hand, so the rule reads the merged picture; a
534
550
  // declaration this preview cannot read degrades to a stated note, never to a silent withhold.
535
551
  const existing = declaredGatesBestEffort(cwd, deps);
536
- // Both sides ask the ONE gate-level predicate. The offer side can only ever be a recognized cmd
537
- // (this preview never EMITS the marker — it offers nothing it cannot verify), but a declaration
538
- // the user wrote by hand may carry it, and the two sides must not answer through two predicates.
552
+ // The offered entries carry no marker and no claim, so the closed cmd world screens them; every
553
+ // declared row is asked the ONE row question (readsAsCoverageProducer, through
554
+ // coverageProducerPrecedes over the whole list), so a row claiming the checker never produces.
539
555
  const producerPresent =
540
- scripts.entries.some((entry) => isCoverageProducerGate(entry)) ||
541
- existing.gates.some((gate) => isCoverageProducerGate(gate));
556
+ scripts.entries.some((entry) => matchesCoverageProducer(entry.cmd)) ||
557
+ coverageProducerPrecedes(existing.gates, existing.gates.length, cwd);
542
558
  const withholdCoverage = cc.candidate !== null && !producerPresent;
543
559
  const coverageNote = withholdCoverage
544
- ? `the coverage-check candidate was withheld: nothing would PRODUCE the lcov it reads — no offered or ` +
545
- `declared gate carries the canonical coverage reporters, and a checker with no producer passes while ` +
546
- `verifying nothing (declare a suite gate per references/modes/gates.md, then re-run)`
560
+ ? `the coverage-check candidate was withheld: no declared gate is a producer this kit reads, and none is offered — ${NO_PRODUCER_REMEDY}`
547
561
  : cc.note;
548
562
  // ALWAYS stated, not only when it changed the withhold: the preview would otherwise promise an
549
563
  // applicable offer over a declaration --apply is certain to refuse.
@@ -573,6 +587,8 @@ export const buildOffer = (cwd, deps = {}) => {
573
587
  return {
574
588
  entries: [...scripts.entries, ...candidates],
575
589
  notes: [...scripts.notes, noVerificationNote, unreadableNote, rs.note, fc.note, ss.note, coverageNote].filter(Boolean),
590
+ // The script gates the unit-tests guard withheld, { id, path }: the signal the advisor reads, never the note's text.
591
+ guardWithheld: scripts.guardWithheld,
576
592
  };
577
593
  };
578
594
 
@@ -1,11 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
  // The kit block — the composition root's only mutation of a deployed AGENTS.md. ONE block between two
3
3
  // marker lines holds the precedence line, the read line, the installed engine's three fragments (read
4
- // LIVE, no bundled copy) and the rules-themes table. The block is written current on every run with no
5
- // question and no copy kept; outside it nothing is written or found. An absent or invalid engine is a
6
- // STOP; malformed marker lines are refused with their line numbers. Pure string functions plus one
7
- // return-code entry point; dependency-free, Node >= 22. Contract: docs/ai/specs/kit/install/entry-pointers.md.
4
+ // LIVE, no bundled copy), the rules-themes table, import lines and fallback sentence. The block is
5
+ // written current on every run with no question and no copy kept; outside it nothing is written or
6
+ // found. An absent or invalid engine is a STOP; malformed marker lines are refused with their line
7
+ // numbers. Pure string functions plus one return-code entry point; dependency-free, Node >= 22.
8
+ // Contract: docs/ai/specs/kit/install/entry-pointers.md.
8
9
 
10
+ import { basename, dirname, isAbsolute, join, resolve } from 'node:path';
9
11
  import { isDirectRun } from './direct-run.mjs';
10
12
  import { normalizeCanonical } from './orchestration-config.mjs';
11
13
  import { PRECEDENCE_LINE, THEMES, themePaths } from './project-rules/index.mjs';
@@ -16,6 +18,8 @@ import {
16
18
  export const BLOCK_START = '<!-- workflow:kit:start -->';
17
19
  export const BLOCK_END = '<!-- workflow:kit:end -->';
18
20
  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 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.';
19
23
  export const SKIP_PREFIX = 'Kit text not supplied by the installed engine:';
20
24
  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/";
21
25
 
@@ -24,6 +28,10 @@ const CRLF = '\r\n';
24
28
  const BOM = '\uFEFF';
25
29
  const INSTALL = 'npx @sabaiway/agent-workflow-engine@latest init';
26
30
  const TAG = '[inject-methodology]';
31
+ const CLAUDE_PREFIX = `${TAG} CLAUDE.md is not a symlink to AGENTS.md: automatic loading of the kit block in Claude Code is not guaranteed; `;
32
+ const CLAUDE_ABSENT = 'make CLAUDE.md the link to AGENTS.md.';
33
+ const CLAUDE_MOVE = 'move its text into AGENTS.md outside the kit block, then make CLAUDE.md the link to AGENTS.md.';
34
+ const MAX_LINKS = 40;
27
35
 
28
36
  // The three engine fragments in block order; a valid engine lacking one but methodology leaves a skip line.
29
37
  const FRAGMENTS = Object.freeze([
@@ -81,17 +89,34 @@ export const findKitBlock = (text) => {
81
89
  const skipLine = (name) => `${SKIP_PREFIX} ${name} — refresh it with ${INSTALL}`;
82
90
  const effectiveOf = (theme) => themePaths(theme.name).effective;
83
91
 
84
- // composeKitBlock({ fragments, themes, lacking? }) → the block in LF form; a fragment that is not a
85
- // string, and a theme named in lacking, each leave a skip line.
86
- export const composeKitBlock = ({ fragments, themes, lacking = [] }) => {
92
+ // composeKitParts({ fragments, themes, lacking? }) → the block's parts in order; a fragment that is not a
93
+ // string, and a theme named in lacking, each leave a skip line, and a lacking theme has no row and no import line.
94
+ const composeKitParts = ({ fragments, themes, lacking = [] }) => {
87
95
  const texts = FRAGMENTS.map(({ id, name }) => (typeof fragments[id] === 'string'
88
96
  ? fragments[id].replace(/\r\n/gu, LF).trim()
89
97
  : skipLine(name)));
90
- const rows = themes.filter((theme) => !lacking.includes(theme.name))
91
- .map((theme) => `| [\`${effectiveOf(theme)}\`](./${effectiveOf(theme)}) | ${theme.readWhen} |`);
98
+ const shipped = themes.filter((theme) => !lacking.includes(theme.name));
99
+ const rows = shipped.map((theme) => `| [\`${effectiveOf(theme)}\`](./${effectiveOf(theme)}) | ${theme.readWhen} |`);
92
100
  const table = ['| Rules theme | Read when |', '|---|---|', ...rows].join(LF);
93
101
  const skips = themes.filter((theme) => lacking.includes(theme.name)).map((theme) => skipLine(themeName(theme.name)));
94
- return [BLOCK_START, PRECEDENCE_LINE, READ_LINE, ...texts, table, ...skips, BLOCK_END].join(LF + LF);
102
+ const imports = [...MEMORY_IMPORTS, ...shipped.map(effectiveOf)].map((path) => `@${path}`).join(LF);
103
+ return [BLOCK_START, PRECEDENCE_LINE, READ_LINE, ...texts, table, ...skips, imports, FALLBACK_LINE, BLOCK_END];
104
+ };
105
+ // composeKitBlock({ fragments, themes, lacking? }) → the block in LF form, one blank line between parts.
106
+ export const composeKitBlock = (input) => composeKitParts(input).join(LF + LF);
107
+
108
+ // findOpenFence(text, importLine) → the 1-based line of the first opener above importLine no later line closes, or null.
109
+ const findOpenFence = (text, importLine) => {
110
+ const lines = text.split(LF);
111
+ const cursor = { index: 0 };
112
+ for (; cursor.index < importLine - 1; cursor.index += 1) {
113
+ const open = opensFence(lines[cursor.index]);
114
+ if (!open) continue;
115
+ const close = lines.findIndex((line, at) => at > cursor.index && closesFence(line, open));
116
+ if (close === -1) return cursor.index + 1;
117
+ cursor.index = close;
118
+ }
119
+ return null;
95
120
  };
96
121
 
97
122
  // The byte offset where 1-based line n starts, and where its content ends (before its CR and LF).
@@ -154,10 +179,14 @@ const readEngineParts = ({ env, home, logError }) => {
154
179
  return { fragments, lacking };
155
180
  };
156
181
 
157
- // runCli(argv, { env, home }) → { code, stdout, stderr }; never exits. `reconcile <AGENTS.md>` is the one form.
182
+ // runCli(argv, { env, home, lstat, readlink, realpath }) → { code, stdout, stderr }; never exits.
183
+ // `reconcile <AGENTS.md>` checks CLAUDE.md before writing; reports fallback, open fence and link last.
158
184
  export const runCli = async (argv, deps = {}) => {
159
- const { readFile, writeFile, rename, rm } = await import('node:fs/promises');
160
- const { dirname, basename, join, resolve } = await import('node:path');
185
+ const fs = await import('node:fs/promises');
186
+ const { readFile, writeFile, rename, rm } = fs;
187
+ const lstat = deps.lstat ?? fs.lstat;
188
+ const readlink = deps.readlink ?? fs.readlink;
189
+ const realpath = deps.realpath ?? fs.realpath;
161
190
  const { homedir } = await import('node:os');
162
191
  const env = deps.env ?? process.env;
163
192
  const home = deps.home ?? homedir();
@@ -175,6 +204,27 @@ export const runCli = async (argv, deps = {}) => {
175
204
  return result(2);
176
205
  }
177
206
  const target = resolve(argv[1]);
207
+ const checkClaudeLink = async (own) => {
208
+ const state = { hop: join(dirname(own), 'CLAUDE.md'), links: 0, checkingEntry: true };
209
+ while (state.hop !== own) {
210
+ state.checkingEntry = true;
211
+ try {
212
+ const stat = await lstat(state.hop);
213
+ if (!stat.isSymbolicLink()) return CLAUDE_MOVE;
214
+ state.checkingEntry = false;
215
+ // Joined without resolve(): a `..` after a directory link is the native realpath's to follow, as the kernel does.
216
+ const link = await readlink(state.hop);
217
+ const next = isAbsolute(link) ? link : `${dirname(state.hop)}/${link}`;
218
+ state.hop = join(await realpath(dirname(next)), basename(next));
219
+ state.links += 1;
220
+ if (state.links > MAX_LINKS) return CLAUDE_MOVE;
221
+ } catch (err) {
222
+ if (!['ENOENT', 'ENOTDIR', 'ELOOP'].includes(err.code)) throw err;
223
+ return err.code === 'ENOENT' && state.checkingEntry && state.links === 0 ? CLAUDE_ABSENT : CLAUDE_MOVE;
224
+ }
225
+ }
226
+ return null;
227
+ };
178
228
  const writeAtomic = async (out) => {
179
229
  const tmp = join(dirname(target), `.${basename(target)}.tmp-${process.pid}-${Date.now()}`);
180
230
  try {
@@ -188,16 +238,25 @@ export const runCli = async (argv, deps = {}) => {
188
238
  try {
189
239
  const text = await readFile(target, 'utf8');
190
240
  const { fragments, lacking } = readEngineParts({ env, home, logError });
191
- const block = composeKitBlock({ fragments, themes: THEMES, lacking });
241
+ const parts = composeKitParts({ fragments, themes: THEMES, lacking });
242
+ const block = parts.join(LF + LF);
192
243
  const judged = reconcileKitBlock(text, block);
193
244
  if (judged.status === 'refused') {
194
245
  logError(refusalLine(judged.lines));
195
246
  return result(1);
196
247
  }
248
+ const own = join(await realpath(dirname(target)), basename(target));
249
+ const claude = await checkClaudeLink(own);
197
250
  if (judged.status !== 'current') await writeAtomic(judged.text);
198
251
  log(OUTCOME[judged.status]);
199
252
  const skipped = [...FRAGMENTS.filter(({ id }) => typeof fragments[id] !== 'string').map(({ name }) => name), ...lacking.map(themeName)];
200
253
  skipped.forEach((name) => log(noteLine(name)));
254
+ if (judged.status !== 'current') log(`${TAG} note: ${FALLBACK_LINE}`);
255
+ // The import part is the third part from the end: its first line follows the earlier parts and one blank line.
256
+ const importOffset = parts.slice(0, -3).join(LF + LF).split(LF).length + 1;
257
+ const opener = findOpenFence(judged.text, findKitBlock(judged.text).start + importOffset);
258
+ if (opener !== null) log(`${TAG} note: an unclosed code fence on line ${opener} runs over the kit block's import lines, so Claude Code reads them as code; close it.`);
259
+ if (claude !== null) log(CLAUDE_PREFIX + claude);
201
260
  return result(0);
202
261
  } catch (err) {
203
262
  if (err[EXIT] !== undefined) return result(err[EXIT]);
@@ -56,14 +56,14 @@ import { surveyFamily, surveyGateHook } from './family-registry.mjs';
56
56
  import { probeSandboxMasks, needsMasksApply, patternToRel } from './sandbox-masks.mjs';
57
57
  import { shellQuoteArg } from './review-state.mjs';
58
58
  import { isFinalCapableDeclaration } from './run-gates.mjs';
59
- import { loadDeclaration, canonicalCheckerGates, coverageProducerPrecedes, isKitOwnedCheckerGate } from './gates-declaration.mjs';
59
+ import { loadDeclaration, canonicalCheckerGates, coverageProducerPrecedes, isKitOwnedCheckerGate, movableEarlierForm } from './gates-declaration.mjs';
60
60
  // The typed channel's READ-ONLY leaf only — never tools/mcp.mjs, which reaches the write core.
61
61
  import {
62
62
  SERVER_NAME as MCP_SERVER_NAME,
63
63
  STATE as MCP_STATE,
64
64
  readRegistration,
65
65
  } from './mcp-registration.mjs';
66
- import { matchesCoverageProducer, isCoverageProducerGate } from './coverage-producer.mjs';
66
+ import { matchesCoverageProducer } from './coverage-producer.mjs';
67
67
  // How much of the TRACKED tree the changed-line coverage domain can assess at all — the fact that
68
68
  // turns "the checker certifies" into "the checker certifies the assessable minority".
69
69
  import { takeCensus, censusFact, CENSUS_VERDICT } from './tracked-tree-census.mjs';
@@ -266,7 +266,7 @@ export const composeVerdict = ({ attention, optional, skipped, kit = 0 }) => {
266
266
  // banned tokens), never a fixture-coverage gamble. A pure-placeholder template marks a WHAT whose
267
267
  // content is fully dynamic (capped at composition by truncation-with-count) — except `profile-gap`, whose
268
268
  // WHAT is never truncated: the leaf's suite pins every composed WHAT under the cap.
269
- const GATES_INERT_WHAT = 'the declared coverage checker ({id}) has no producer before it — it certifies nothing this run, or reads a stale lcov';
269
+ const GATES_INERT_WHAT = 'the declared coverage checker ({id}): no gate before it is a producer this kit reads';
270
270
  export const WHATS = Object.freeze({
271
271
  'velocity-core': 'routine read-only commands still prompt — {n} audited read-only allowlist entr(ies) not seeded',
272
272
  'velocity-core.rule': 'auto mode refuses a harness apply, so work cannot stay in auto mode — the apply ask rule is not seeded',
@@ -693,7 +693,7 @@ export const probeGatesInert = ({ root, deps, add, skip }) => {
693
693
  // ORDER decides, through the declaration's own shared predicate: a producer declared AFTER the
694
694
  // checker leaves it just as inert as no producer at all (it reads nothing, or stale bytes), and
695
695
  // only --final refuses that shape — a plain run reports every gate PASS.
696
- if (coverageProducerPrecedes(gates, gates.indexOf(checkers[0]))) {
696
+ if (coverageProducerPrecedes(gates, gates.indexOf(checkers[0]), root)) {
697
697
  // The pair is LIVE, and that is exactly where the DOMAIN question becomes the honest one: the
698
698
  // checker's changed-line domain is `.mjs/.cjs/.js` by design, so on a tree dominated by what
699
699
  // that domain excludes, "certified" means "certified over the assessable minority". An
@@ -728,7 +728,16 @@ export const probeGatesInert = ({ root, deps, add, skip }) => {
728
728
  // arm's sentence would be false over it. An offer computation that throws reaches the probe's
729
729
  // stated-skip lane, which is the honest answer to "can the fill help here" when nobody knows.
730
730
  const declaredIds = new Set(gates.map((gate) => gate.id));
731
- const offered = buildOffer(root, deps).entries.filter((entry) => matchesCoverageProducer(entry.cmd));
731
+ const offer = buildOffer(root, deps);
732
+ // A gate an earlier kit wrote that the upgrade moves, anywhere in the declaration, or a `node --test`
733
+ // script the offer withheld on its unit-tests guard: the upgrade is the remedy, in place of the fill
734
+ // preview and of both user arms below — it moves the gate with no question, or a line of its report
735
+ // names what stops it; the advisor predicts nothing about the run (spec coverage-producer, the remedy route).
736
+ if (movableEarlierForm(gates) || offer.guardWithheld.length > 0) {
737
+ add('gates-inert', fillTemplate(WHATS['gates-inert'], { id: truncatedTo(oneLineOf(checkers[0].id), templateBudget(WHATS['gates-inert'])) }), '/agent-workflow-kit upgrade');
738
+ return;
739
+ }
740
+ const offered = offer.entries.filter((entry) => matchesCoverageProducer(entry.cmd));
732
741
  const producer = offered.find((entry) => !declaredIds.has(entry.id));
733
742
  // The dead pair on a tree the recognized producer set cannot speak for. It is deliberately NOT
734
743
  // the ordering arm: a producer that EXISTS but sits after the checker is one MOVE away from
@@ -754,7 +763,7 @@ export const probeGatesInert = ({ root, deps, add, skip }) => {
754
763
  // a recognizable producer the offer never carries. The arm therefore says only what it knows —
755
764
  // nothing declares one and nothing offers one — and its apply names that gap, because the
756
765
  // remedy there is a hand-declared gate rather than the marker.
757
- if (offered.length === 0 && !gates.some((gate) => !checkers.includes(gate) && isCoverageProducerGate(gate))) {
766
+ if (offered.length === 0 && !coverageProducerPrecedes(gates, gates.length, root)) {
758
767
  // An UNAVAILABLE census is NOT a skip here. The dead pair is a defect on any tree, and the
759
768
  // arm below states it truthfully — falling through keeps a non-git deployment byte-identical
760
769
  // to what it saw before this outcome existed, and still renders an item, so the flow-optimal
@@ -52,9 +52,9 @@ export const UPGRADE_RUNLIST = Object.freeze([
52
52
  ),
53
53
  entry(
54
54
  'gates-migration',
55
- 'node ${CLAUDE_SKILL_DIR}/references/scripts/gates/migrate-gates.mjs --kit-tools ${CLAUDE_SKILL_DIR}/tools --cwd <project>',
56
- 'preview first — apply only on an explicit yes, re-run with --apply',
57
- ['preview', 'INERT', 'CUSTOMIZED'],
55
+ 'node ${CLAUDE_SKILL_DIR}/references/scripts/gates/migrate-gates.mjs --kit-tools ${CLAUDE_SKILL_DIR}/tools --cwd <project> --apply',
56
+ 'the coverage-check add alone: on the user\'s explicit yes, run its printed OFFER line, the same command with --apply --add-checker',
57
+ ['SWITCH', 'EXTEND', 'REMOVE', 'KEPT', 'CUSTOMIZED', 'OFFER'],
58
58
  ),
59
59
  entry(
60
60
  'bridges',