@sabaiway/agent-workflow-kit 14.39.0 → 14.41.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.
@@ -1,12 +1,11 @@
1
- // install-git-hooks.test.mjs — spec for the pre-commit installer (strip-the-kit round-1 folds):
2
- // the hooks path comes from git plumbing (a linked worktree resolves ITS OWN hooks path, never a
3
- // hardcoded `.git/hooks`), and an armed commit-guard line SURVIVES a flagless re-run (exactly one
4
- // strictly-parsed canonical guard line carries forward; --no-commit-guard is the only consented
5
- // disable; both flags together are a usage error; a duplicated guard line fails closed).
1
+ // install-git-hooks.test.mjs — the pre-commit installer on a deployed copy: the hooks path comes from git
2
+ // plumbing (a linked worktree resolves ITS OWN hooks path); the guard, rules-check and layout-check lines
3
+ // are carried by role, fail closed on a duplicate and refuse a bad flag value, writing nothing. Every child
4
+ // runs with each inherited GIT_* variable stripped, so a hook's environment never leaks in.
6
5
 
7
6
  import { describe, it } from 'node:test';
8
7
  import assert from 'node:assert/strict';
9
- import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, rmSync, cpSync, existsSync } from 'node:fs';
8
+ import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, rmSync, cpSync, existsSync, realpathSync } from 'node:fs';
10
9
  import { tmpdir } from 'node:os';
11
10
  import { basename, join, dirname, resolve } from 'node:path';
12
11
  import { fileURLToPath } from 'node:url';
@@ -15,118 +14,217 @@ import { spawnSync } from 'node:child_process';
15
14
  const HERE = dirname(fileURLToPath(import.meta.url));
16
15
  const INSTALLER_SRC = join(HERE, 'install-git-hooks.mjs');
17
16
  const MALFORMED_PACKAGE_JSON = '{ not json';
18
- const NAMED_PACKAGE_JSON = '{"name":"named-fixture"}';
19
- const NAMED_FIXTURE = 'named-fixture';
17
+ const [NAMED_PACKAGE_JSON, NAMED_FIXTURE] = ['{"name":"named-fixture"}', 'named-fixture'];
18
+ const WIN32 = ['--import', 'data:text/javascript,Object.defineProperty(process,"platform",{value:"win32"})'];
19
+ const BACKSLASH = String.fromCharCode(92);
20
+ const SHELL_ACTIVE = [34, 36, 96, 92, 13, 10].map((code) => String.fromCharCode(code)).filter((ch) => process.platform !== 'win32' || ch !== BACKSLASH);
21
+ const shown = (path) => (process.platform === 'win32' ? path.replaceAll(BACKSLASH, '/') : path);
22
+
23
+ const BASE_ENV = Object.fromEntries(Object.entries(process.env).filter(([key]) => !/^[Gg][Ii][Tt]_/.test(key)));
24
+ const envAt = (home) => ({
25
+ ...BASE_ENV, HOME: home, XDG_CONFIG_HOME: join(home, '.config'), LC_ALL: 'C', GIT_CONFIG_GLOBAL: '/dev/null', GIT_CONFIG_SYSTEM: '/dev/null',
26
+ GIT_CONFIG_NOSYSTEM: '1', GIT_ATTR_NOSYSTEM: '1', GIT_AUTHOR_NAME: 'p', GIT_AUTHOR_EMAIL: 'p@e', GIT_COMMITTER_NAME: 'p', GIT_COMMITTER_EMAIL: 'p@e',
27
+ });
28
+
29
+ // A child that never started or was killed has no exit status to judge — it fails the cell outright.
30
+ const spawnChecked = (command, args, cwd) => {
31
+ const r = spawnSync(command, args, { cwd, env: envAt(cwd), encoding: 'utf8' });
32
+ if (r.error) throw r.error;
33
+ if (r.signal !== null) throw new Error(`${command} was killed by ${r.signal}`);
34
+ return r;
35
+ };
36
+ const succeeds = (r) => { assert.equal(r.status, 0, r.stderr); return r; };
37
+ const git = (cwd, ...args) => succeeds(spawnChecked('git', args, cwd));
20
38
 
21
39
  // The installer anchors ROOT at <its dir>/.. — deploy it into a fixture's scripts/ like a consumer.
22
40
  const mkProject = () => {
23
- const root = mkdtempSync(join(tmpdir(), 'install-hooks-'));
24
- const g = (...a) => spawnSync('git', a, { cwd: root, encoding: 'utf8' });
41
+ const root = realpathSync(mkdtempSync(join(tmpdir(), 'install-hooks-')));
42
+ const g = (...a) => git(root, ...a);
25
43
  g('init', '-q');
26
- g('config', 'user.email', 'p@e');
27
- g('config', 'user.name', 'p');
28
44
  mkdirSync(join(root, 'scripts'), { recursive: true });
29
45
  cpSync(INSTALLER_SRC, join(root, 'scripts', 'install-git-hooks.mjs'));
30
46
  writeFileSync(join(root, 'guard.mjs'), '// a stand-in commit-guard tool\n');
31
47
  writeFileSync(join(root, 'base.txt'), 'base\n');
32
- g('add', '-A');
33
- g('commit', '-qm', 'base');
48
+ for (const args of [['add', '-A'], ['commit', '-qm', 'base']]) g(...args);
34
49
  return { root, g };
35
50
  };
51
+ const inProject = (cell) => () => { const fx = mkProject(); try { cell(fx); } finally { rmSync(fx.root, { recursive: true, force: true }); } };
36
52
 
37
- const runInstaller = (root, args = []) =>
38
- spawnSync('node', [join(root, 'scripts', 'install-git-hooks.mjs'), ...args], { cwd: root, encoding: 'utf8' });
39
-
40
- const hooksPathOf = (root) => {
41
- const r = spawnSync('git', ['rev-parse', '--git-path', 'hooks'], { cwd: root, encoding: 'utf8' });
42
- return resolve(root, r.stdout.trim());
43
- };
53
+ const runInstaller = (root, args = [], pre = []) =>
54
+ spawnChecked(process.execPath, [...pre, join(root, 'scripts', 'install-git-hooks.mjs'), ...args], root);
55
+ const installs = (...a) => succeeds(runInstaller(...a));
44
56
 
57
+ const hooksPathOf = (root) => resolve(root, git(root, 'rev-parse', '--git-path', 'hooks').stdout.trim());
45
58
  const markerFor = (name) => `# ${name}:install-git-hooks.mjs`;
46
59
  const readHook = (root) => readFileSync(join(hooksPathOf(root), 'pre-commit'), 'utf8');
60
+ const stub = (root, rel) => (mkdirSync(dirname(join(root, rel)), { recursive: true }), writeFileSync(join(root, rel), '// a stand-in tool\n'), join(root, rel));
47
61
 
48
- describe('install-git-hooks \u2014 beside no package.json, or a malformed one, the marker names the directory basename', () => {
49
- it('no package.json, then a MALFORMED one \u2014 the marker names the directory basename', () => {
50
- const { root } = mkProject();
62
+ // The hook the 4.0.0-8.2.1 installer body writes with no guard: the six docs and scripts lines.
63
+ const plainHook = (root) => `#!/usr/bin/env bash
64
+ ${markerFor(basename(root))}
65
+ # Auto-installed by scripts/install-git-hooks.mjs (run it from "prepare" or by hand).
66
+ # Runs the docs cap-validator + index-freshness gate + rotation-freshness checks
67
+ # + the scripts/ test suite before every commit, so files cannot drift over their
68
+ # declared maxLines, the auto-generated index.md cannot silently go stale, stale
69
+ # archive entries never reach a commit, and regressions to the scripts are caught.
70
+ set -e
71
+ node scripts/check-docs-size.mjs
72
+ node scripts/check-docs-size.mjs --check-index
73
+ node scripts/archive-changelog.mjs --check
74
+ node scripts/archive-issues.mjs --check
75
+ node scripts/archive-decisions.mjs --check
76
+ node --test scripts/*.test.mjs
77
+ `;
78
+ const line = (path, role) => `node "${role ? shown(path) : path}" --check${role ? ` # ${role}` : ''}\n`;
79
+
80
+ describe('install-git-hooks — beside no package.json, or a malformed one, the marker names the directory basename', () => {
81
+ it('no package.json, then a MALFORMED one — the marker names the directory basename', inProject(({ root }) => {
51
82
  const expected = markerFor(basename(root));
52
- const absent = runInstaller(root);
53
- assert.equal(absent.status, 0, absent.stderr);
83
+ installs(root);
54
84
  assert.ok(readHook(root).split('\n').includes(expected));
55
85
  writeFileSync(join(root, 'package.json'), MALFORMED_PACKAGE_JSON);
56
- const malformed = runInstaller(root);
57
- assert.equal(malformed.status, 0, malformed.stderr);
86
+ installs(root);
58
87
  assert.ok(readHook(root).split('\n').includes(expected));
59
- rmSync(root, { recursive: true, force: true });
60
- });
88
+ }));
61
89
 
62
- it('a named package.json wins \u2014 the marker carries its name', () => {
63
- const { root } = mkProject();
90
+ it('a named package.json wins — the marker carries its name', inProject(({ root }) => {
64
91
  writeFileSync(join(root, 'package.json'), NAMED_PACKAGE_JSON);
65
- const result = runInstaller(root);
66
- assert.equal(result.status, 0, result.stderr);
92
+ installs(root);
67
93
  assert.ok(readHook(root).split('\n').includes(markerFor(NAMED_FIXTURE)));
68
- rmSync(root, { recursive: true, force: true });
69
- });
94
+ }));
70
95
  });
71
96
 
72
97
  describe('install-git-hooks — the hooks path comes from git plumbing (C7)', () => {
73
- it('a normal repo installs at the git-path hooks location', () => {
74
- const { root } = mkProject();
75
- const r = runInstaller(root);
76
- assert.equal(r.status, 0, r.stderr);
98
+ it('a normal repo installs at the git-path hooks location', inProject(({ root }) => {
99
+ installs(root);
77
100
  assert.ok(existsSync(join(hooksPathOf(root), 'pre-commit')), 'the hook lands where git says hooks live');
78
- rmSync(root, { recursive: true, force: true });
79
- });
101
+ }));
80
102
 
81
- it('a LINKED WORKTREE installs at ITS OWN git-path hooks (never a hardcoded <worktree>/.git/hooks)', () => {
82
- const { root, g } = mkProject();
103
+ it('a LINKED WORKTREE installs at ITS OWN git-path hooks (never a hardcoded <worktree>/.git/hooks)', inProject(({ root, g }) => {
83
104
  const wt = join(root, '..', `wt-${Date.now() % 1e6}`);
84
105
  g('worktree', 'add', '-q', wt);
85
- mkdirSync(join(wt, 'scripts'), { recursive: true });
86
- cpSync(INSTALLER_SRC, join(wt, 'scripts', 'install-git-hooks.mjs'));
87
- const r = runInstaller(wt);
88
- assert.equal(r.status, 0, r.stderr);
89
- const expected = join(hooksPathOf(wt), 'pre-commit');
90
- assert.ok(existsSync(expected), `the worktree hook lands at git's own answer (${expected})`);
91
- assert.ok(!existsSync(join(wt, '.git', 'hooks', 'pre-commit')), 'never a literal <worktree>/.git/hooks (a worktree .git is a FILE)');
92
- rmSync(wt, { recursive: true, force: true });
93
- rmSync(root, { recursive: true, force: true });
94
- });
106
+ try {
107
+ mkdirSync(join(wt, 'scripts'), { recursive: true });
108
+ cpSync(INSTALLER_SRC, join(wt, 'scripts', 'install-git-hooks.mjs'));
109
+ installs(wt);
110
+ const expected = join(hooksPathOf(wt), 'pre-commit');
111
+ assert.ok(existsSync(expected), `the worktree hook lands at git's own answer (${expected})`);
112
+ assert.ok(!existsSync(join(wt, '.git', 'hooks', 'pre-commit')), 'never a literal <worktree>/.git/hooks (a worktree .git is a FILE)');
113
+ } finally {
114
+ rmSync(wt, { recursive: true, force: true });
115
+ }
116
+ }));
95
117
  });
96
118
 
97
119
  describe('install-git-hooks — the commit-guard arm persists (C8)', () => {
98
- it('an armed guard SURVIVES a later flagless re-run (carried forward from the managed hook)', () => {
99
- const { root } = mkProject();
120
+ it('an armed guard SURVIVES a later flagless re-run (carried forward from the managed hook)', inProject(({ root }) => {
100
121
  assert.equal(runInstaller(root, ['--commit-guard', 'guard.mjs']).status, 0);
101
- const armed = readFileSync(join(hooksPathOf(root), 'pre-commit'), 'utf8');
102
- assert.match(armed, /guard\.mjs" --check/, 'the guard line is written armed');
122
+ assert.match(readHook(root), /guard\.mjs" --check/, 'the guard line is written armed');
103
123
  assert.equal(runInstaller(root).status, 0, 'the flagless canonical re-run succeeds');
104
- const after = readFileSync(join(hooksPathOf(root), 'pre-commit'), 'utf8');
105
- assert.match(after, /guard\.mjs" --check/, 'the armed guard line survives a flagless re-run');
106
- rmSync(root, { recursive: true, force: true });
107
- });
124
+ assert.match(readHook(root), /guard\.mjs" --check/, 'the armed guard line survives a flagless re-run');
125
+ }));
108
126
 
109
- it('--no-commit-guard is the ONLY consented disable; combining both flags is a usage error', () => {
110
- const { root } = mkProject();
127
+ it('--no-commit-guard is the ONLY consented disable; combining both flags is a usage error', inProject(({ root }) => {
111
128
  assert.equal(runInstaller(root, ['--commit-guard', 'guard.mjs']).status, 0);
112
129
  assert.equal(runInstaller(root, ['--no-commit-guard']).status, 0);
113
- const after = readFileSync(join(hooksPathOf(root), 'pre-commit'), 'utf8');
114
- assert.doesNotMatch(after, /" --check$/m, 'the guard line is removed on the explicit disable');
130
+ assert.doesNotMatch(readHook(root), /" --check$/m, 'the guard line is removed on the explicit disable');
115
131
  const both = runInstaller(root, ['--commit-guard', 'guard.mjs', '--no-commit-guard']);
116
132
  assert.equal(both.status, 2, 'both flags together are a usage error, never an order-dependent pick');
117
- rmSync(root, { recursive: true, force: true });
118
- });
133
+ }));
119
134
 
120
- it('a DUPLICATED/malformed guard line in the managed hook fails CLOSED on a flagless re-run', () => {
121
- const { root } = mkProject();
135
+ it('a DUPLICATED/malformed guard line in the managed hook fails CLOSED on a flagless re-run', inProject(({ root }) => {
122
136
  assert.equal(runInstaller(root, ['--commit-guard', 'guard.mjs']).status, 0);
123
- const hookPath = join(hooksPathOf(root), 'pre-commit');
124
- const armed = readFileSync(hookPath, 'utf8');
137
+ const armed = readHook(root);
125
138
  const guardLine = armed.split('\n').find((l) => /" --check$/.test(l));
126
- writeFileSync(hookPath, `${armed}${guardLine}\n`); // duplicate the guard line
139
+ writeFileSync(join(hooksPathOf(root), 'pre-commit'), `${armed}${guardLine}\n`); // duplicate the guard line
127
140
  const r = runInstaller(root);
128
141
  assert.equal(r.status, 1, 'two guard lines are ambiguous — fail closed, never guess');
129
142
  assert.match(r.stderr, /guard/i);
130
- rmSync(root, { recursive: true, force: true });
131
- });
143
+ }));
144
+ });
145
+
146
+ describe('spec:init-project/S58 install-git-hooks — the rules-check and layout-check lines on a deployed copy', () => {
147
+ it('each flag writes its resolved path and role comment, ordered docs, rules, layout, guard; a flagless re-run keeps all three; --commit-guard replaces and --no-commit-guard drops the guard alone', inProject(({ root }) => {
148
+ const [rules, layout, guard, guard2] = ['tools/rules-cli.mjs', 'tools/source-size-check.mjs', 'guard.mjs', 'g2/guard.mjs'].map((rel) => stub(root, rel));
149
+ installs(root, ['--commit-guard', 'guard.mjs']);
150
+ installs(root, ['--layout-check', 'tools/source-size-check.mjs']);
151
+ installs(root, ['--rules-check', rules]);
152
+ const armed = plainHook(root) + line(rules, 'rules-check') + line(layout, 'layout-check');
153
+ assert.equal(readHook(root), armed + line(guard), 'each arming run carried the other armed lines');
154
+ assert.match(installs(root).stdout, /already up to date/, 'a flagless re-run keeps all three');
155
+ assert.equal(readHook(root), armed + line(guard));
156
+ installs(root, ['--commit-guard', guard2]);
157
+ assert.equal(readHook(root), armed + line(guard2), '--commit-guard replaces the guard line alone');
158
+ installs(root, ['--no-commit-guard']);
159
+ assert.equal(readHook(root), armed, '--no-commit-guard drops the guard line alone');
160
+ }));
161
+
162
+ it('a legacy guard line whose file name is rules-cli.mjs keeps the guard role beside a rules line', inProject(({ root }) => {
163
+ const [legacy, rules] = ['legacy/rules-cli.mjs', 'tools/rules-cli.mjs'].map((rel) => stub(root, rel));
164
+ installs(root, ['--commit-guard', legacy]);
165
+ installs(root, ['--rules-check', rules]);
166
+ const expected = plainHook(root) + line(rules, 'rules-check') + line(legacy);
167
+ assert.equal(readHook(root), expected);
168
+ installs(root);
169
+ assert.equal(readHook(root), expected, 'the flagless re-run keeps the legacy line as the guard');
170
+ }));
171
+
172
+ it('two lines of one role exit 1 naming that role, the hook unchanged', inProject(({ root }) => {
173
+ installs(root, ['--rules-check', stub(root, 'tools/rules-cli.mjs'), '--layout-check', stub(root, 'tools/source-size-check.mjs')]);
174
+ const armed = readHook(root);
175
+ for (const role of ['rules-check', 'layout-check']) {
176
+ const roleLine = armed.split('\n').find((l) => l.endsWith(` --check # ${role}`));
177
+ assert.ok(roleLine, `the ${role} line is armed`);
178
+ writeFileSync(join(hooksPathOf(root), 'pre-commit'), `${armed}${roleLine}\n`);
179
+ const r = runInstaller(root);
180
+ assert.equal(r.status, 1, r.stderr);
181
+ assert.match(r.stderr, new RegExp(`carries 2 ${role} lines`));
182
+ assert.equal(readHook(root), `${armed}${roleLine}\n`);
183
+ }
184
+ }));
185
+
186
+ it('over a hook with no rules or layout line, a flagless and a --commit-guard run write the 4.0.0-8.2.1 bytes', inProject(({ root }) => {
187
+ installs(root);
188
+ assert.equal(readHook(root), plainHook(root));
189
+ installs(root, ['--commit-guard', 'guard.mjs']);
190
+ assert.equal(readHook(root), plainHook(root) + line(join(root, 'guard.mjs')));
191
+ }));
192
+
193
+ it('a wrong file name, a shell-active path or a missing value exits 2, a missing file exits 1, each writing nothing', inProject(({ root }) => {
194
+ const [rules, layout] = ['tools/rules-cli.mjs', 'tools/source-size-check.mjs'].map((rel) => stub(root, rel));
195
+ installs(root, ['--commit-guard', 'guard.mjs']);
196
+ const before = readHook(root);
197
+ const cases = [
198
+ [['--rules-check', layout], 2, /--rules-check takes a path to rules-cli\.mjs/],
199
+ [['--layout-check', rules], 2, /--layout-check takes a path to source-size-check\.mjs/],
200
+ ...SHELL_ACTIVE.flatMap((ch, at) => [
201
+ [['--rules-check', join(root, `r${at}${ch}x`, 'rules-cli.mjs')], 2, /a backslash, CR or LF/],
202
+ [['--layout-check', join(root, `l${at}${ch}x`, 'source-size-check.mjs')], 2, /a backslash, CR or LF/],
203
+ ]),
204
+ [['--rules-check', join(root, 'nowhere', 'rules-cli.mjs')], 1, /does not exist/],
205
+ [['--layout-check', join(root, 'nowhere', 'source-size-check.mjs')], 1, /does not exist/],
206
+ [['--rules-check'], 2, /--rules-check needs a path/],
207
+ [['--layout-check'], 2, /--layout-check needs a path/],
208
+ ];
209
+ for (const [args, status, message] of cases) {
210
+ const r = runInstaller(root, args);
211
+ assert.equal(r.status, status, `${JSON.stringify(args)}: ${r.stderr}`);
212
+ assert.match(r.stderr, message);
213
+ assert.equal(readHook(root), before, `${JSON.stringify(args)} wrote nothing`);
214
+ }
215
+ }));
216
+
217
+ it('an ordinary win32 path, its separators made /, arms and a flagless re-run carries it; on posix it is the backslash refusal', inProject(({ root }) => {
218
+ installs(root);
219
+ const given = `${root}/a${BACKSLASH}b/rules-cli.mjs`;
220
+ const armedAt = stub(root, 'a/b/rules-cli.mjs');
221
+ if (process.platform !== 'win32') { // there the backslash is refused, writing nothing
222
+ const posix = runInstaller(root, ['--rules-check', given]);
223
+ assert.deepEqual([posix.status, /a backslash, CR or LF/.test(posix.stderr), readHook(root)], [2, true, plainHook(root)], posix.stderr);
224
+ }
225
+ installs(root, ['--rules-check', given], WIN32);
226
+ assert.equal(readHook(root), plainHook(root) + line(armedAt, 'rules-check'));
227
+ assert.match(installs(root).stdout, /already up to date/, 'the flagless re-run recognises the win32-armed line');
228
+ assert.equal(readHook(root), plainHook(root) + line(armedAt, 'rules-check'));
229
+ }));
132
230
  });
@@ -26,6 +26,7 @@ import { findOnPath } from './detect-backends.mjs';
26
26
  import { consoleArgv } from './write-lanes.mjs';
27
27
  import { BUNDLED_SCRIPT_NAMES, INSTALLER_REL, SCRIPTS_REL, formatPlan, planGitHooks } from './git-hooks.mjs';
28
28
  import { ATTRIBUTION_HIDDEN, ATTRIBUTION_KEY, writeAttribution } from './attribution.mjs';
29
+ import { classifyDeployedScript } from './script-priors.mjs';
29
30
  import { globalRemovalOf, planGlobalRemoval } from './hide-footprint.mjs';
30
31
  import { isDirectRun } from './direct-run.mjs';
31
32
  import { dirCovers as covers } from './declared-paths.mjs';
@@ -38,7 +39,7 @@ const HOOK_VARIANTS = ['gate-hook', 'read-lane.missing', ...RESEED_VARIANTS];
38
39
  const STOP = 'state-block';
39
40
  const MCP_VARIANTS = ['mcp-channel', 'mcp-channel.differing'];
40
41
  const AGENT_VARIANTS = ['agents', 'executor-vehicle', 'executor-vehicle.differing'];
41
- const GIT_VARIANTS = ['enforcement', 'commit-guard'];
42
+ const GIT_VARIANTS = ['enforcement', 'commit-guard', 'hook-checks'];
42
43
  const WORKTREES = 'worktrees-dir';
43
44
  const ATTRIBUTION = 'attribution';
44
45
  const FOOTPRINT = 'footprint-global';
@@ -219,13 +220,16 @@ export const scopeOf = (variant, facts, deps = {}) => {
219
220
  }
220
221
  const scripts = join(facts.root, SCRIPTS_REL);
221
222
  if (GIT_VARIANTS.includes(variant)) {
222
- directories.splice(0, directories.length, scripts);
223
- filePaths.push(...BUNDLED_SCRIPT_NAMES.map((name) => join(scripts, name)));
223
+ directories.splice(0, directories.length, ...(variant === 'hook-checks' ? [] : [scripts]));
224
+ filePaths.push(...(variant === 'hook-checks' ? [join(facts.root, INSTALLER_REL)] : BUNDLED_SCRIPT_NAMES.map((name) => join(scripts, name))));
224
225
  }
225
- const runs = GIT_VARIANTS.includes(variant) ? ['node', INSTALLER_REL,
226
- ...(variant === 'commit-guard' ? ['--commit-guard', join(facts.toolsDir, 'commit-guard.mjs')] : [])] : null;
226
+ const rules = ['--rules-check', join(facts.toolsDir, 'project-rules', 'rules-cli.mjs')];
227
+ const layout = ['--layout-check', join(facts.toolsDir, 'source-size-check.mjs')];
228
+ const flagSets = variant === 'hook-checks' ? [rules, layout, [...rules, ...layout]]
229
+ : variant === 'commit-guard' ? [['--commit-guard', join(facts.toolsDir, 'commit-guard.mjs')]] : [[]];
230
+ const runs = GIT_VARIANTS.includes(variant) ? flagSets.map((flags) => ['node', INSTALLER_REL, ...flags]) : [];
227
231
  return {
228
- admitsRun: (argv) => runs !== null && equal(argv, runs),
232
+ admitsRun: (argv) => runs.some((run) => equal(argv, run)),
229
233
  admits: ({ path, key, change, value }) => {
230
234
  const correctFile = key.startsWith(`${SERVERS_KEY}.`) ? path === MCP_JSON_REL
231
235
  : path === (variant === WORKTREES ? SETTINGS_LOCAL_FILE : SETTINGS_FILE);
@@ -314,6 +318,12 @@ export const plannedChange = (variant, facts, deps = {}) => {
314
318
  } else if (GIT_VARIANTS.includes(variant)) {
315
319
  const plan = (deps.planGitHooks ?? planGitHooks)({ root: facts.root, variant, toolsDir: facts.toolsDir });
316
320
  for (const copy of plan.copies.filter(({ action }) => action === 'created')) writes.push({ path: copy.path, bytes: copy.bytes });
321
+ if (plan.refresh) {
322
+ // The one replace hook-checks makes: the bundled installer's bytes over a catalogued prior body.
323
+ const bundled = readFileSync(join(facts.toolsDir, '..', 'references', INSTALLER_REL));
324
+ const { path, bytes, replaces } = plan.refresh;
325
+ writes.push({ path, bytes, replaces, matches: bundled.equals(bytes) && classifyDeployedScript(replaces, basename(INSTALLER_REL), bundled) === 'prior' });
326
+ }
317
327
  runs = { argv: plan.runs.shown, line: formatPlan(plan).at(-1) };
318
328
  } else if (variant === WORKTREES) {
319
329
  const plan = writeVelocityProfile({ cwd: facts.root, dryRun: true, worktrees: true }, writerDeps);
@@ -425,12 +425,12 @@ export const flowCheckCandidate = (cwd, deps = {}) => {
425
425
  };
426
426
 
427
427
  // The conditional SOURCE-SIZE candidate — keyed on the practice's own declaration rather than on a
428
- // recipe: the gate is offered ONLY over a MINTED docs/ai/source-size.json, because on any other
429
- // state the checker REFUSES by design (an absent config has no declared scope; an authored or
430
- // half-written one records nothing yet), and a declared gate that refuses is a matrix this preview
431
- // would have reddened on the user's behalf. The two states are told apart out loud: a project that
432
- // never declared the practice hears nothing (there is no offer to make), while one that authored it
433
- // and stopped short hears WHY the gate is not offered yet — the mint is the step it is missing.
428
+ // recipe: the gate is offered ONLY over a MINTED schema-2 docs/ai/source-size.json. Over an authored
429
+ // or half-written one the checker REFUSES by design, and a declared gate that refuses is a matrix
430
+ // this preview would have reddened on the user's behalf; a minted schema-1 one is withheld naming its
431
+ // --write-baseline move. A project that never declared the practice hears nothing here, while one
432
+ // that authored it and stopped short hears WHY the gate is not offered yet — the mint is the step it
433
+ // is missing.
434
434
  // A path is unrenderable when EITHER guard fires, and both are asked ONCE, before anything about
435
435
  // this candidate is printed. They are the same question wearing two coats: double-quoting cannot
436
436
  // survive a shell-active byte, and a line-unsafe byte cannot be printed at all — U+2028 quotes
@@ -441,8 +441,9 @@ const unrenderableToolPath = (text) => isLineUnsafe(text) || DQ_UNSAFE_PATH_PATT
441
441
  export const sourceSizeCandidate = (cwd, deps = {}) => {
442
442
  const toolPath = deps.sourceSizeTool ?? SOURCE_SIZE_TOOL_PATH;
443
443
  try {
444
- const { state } = loadSourceSizeConfig(resolve(cwd), deps);
444
+ const { state, config } = loadSourceSizeConfig(resolve(cwd), deps);
445
445
  if (state === 'absent') return { candidate: null, note: null };
446
+ const schema1 = state === 'minted' && config.schema === 1;
446
447
  // Asked BEFORE the state branches: every branch below prints this path, so a check that only one
447
448
  // of them performs is a guard the other silently lacks.
448
449
  if (unrenderableToolPath(toolPath)) {
@@ -451,7 +452,7 @@ export const sourceSizeCandidate = (cwd, deps = {}) => {
451
452
  // The advice still follows the STATE: over an unminted record a hand-declared gate is red on
452
453
  // every run, so pointing there would hand the reader their next failure as the way out.
453
454
  const lane = state === 'minted'
454
- ? 'declare the gate by hand'
455
+ ? `${schema1 ? 'move the record to schema 2 first — run source-size-check.mjs --write-baseline with the working directory set to this project, then ' : ''}declare the gate by hand`
455
456
  : `mint the record first — run source-size-check.mjs --adopt --reason "${INITIAL_ADOPTION_REASON}" with the working directory set to this project, then declare the gate by hand`;
456
457
  return {
457
458
  candidate: null,
@@ -479,6 +480,14 @@ export const sourceSizeCandidate = (cwd, deps = {}) => {
479
480
  `${recovery}, then re-run this preview`,
480
481
  };
481
482
  }
483
+ // A minted schema-1 record stops the check until the writer moves it; the move takes no reason.
484
+ if (schema1) {
485
+ const project = resolve(cwd);
486
+ return {
487
+ candidate: null,
488
+ note: `the source-size candidate was withheld: the declared practice is schema 1, which the check stops on until it is moved — ${unrenderableToolPath(project) ? 'run source-size-check.mjs --write-baseline yourself, with the working directory set to this project (no command is printed: this project\'s path cannot be rendered into one)' : `run node "${toolPath}" --write-baseline --cwd "${project}"`}, then re-run this preview`,
489
+ };
490
+ }
482
491
  return {
483
492
  candidate: {
484
493
  id: SOURCE_SIZE_GATE_ID,