@sabaiway/agent-workflow-kit 14.40.0 → 14.42.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.
- package/CHANGELOG.md +54 -0
- package/SKILL.md +1 -1
- package/capability.json +1 -1
- package/package.json +1 -1
- package/references/advisor-writers.md +2 -0
- package/references/modes/bootstrap.md +1 -0
- package/references/modes/recommendations.md +9 -8
- package/references/modes/upgrade.md +2 -2
- package/references/scripts/install-git-hooks-repo-exec.test.mjs +56 -6
- package/references/scripts/install-git-hooks.mjs +60 -4
- package/references/scripts/install-git-hooks.test.mjs +173 -75
- package/tools/apply-danger-check.mjs +16 -6
- package/tools/ensure-configs.mjs +6 -3
- package/tools/ensure-ops.mjs +68 -20
- package/tools/ensure-vocabulary.mjs +3 -3
- package/tools/git-hooks.mjs +146 -20
- package/tools/node-evidence.mjs +10 -2
- package/tools/recommendations.mjs +60 -4
- package/tools/script-priors.mjs +19 -8
- package/tools/source-size/index.mjs +6 -0
- package/tools/source-size/setup.mjs +40 -0
- package/tools/source-size-check.mjs +11 -7
- package/tools/source-size-core.mjs +24 -5
- package/tools/write-lanes.mjs +6 -2
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
// install-git-hooks.test.mjs —
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
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
|
|
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) =>
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
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
|
-
|
|
57
|
-
assert.equal(malformed.status, 0, malformed.stderr);
|
|
86
|
+
installs(root);
|
|
58
87
|
assert.ok(readHook(root).split('\n').includes(expected));
|
|
59
|
-
|
|
60
|
-
});
|
|
88
|
+
}));
|
|
61
89
|
|
|
62
|
-
it('a named package.json wins
|
|
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
|
-
|
|
66
|
-
assert.equal(result.status, 0, result.stderr);
|
|
92
|
+
installs(root);
|
|
67
93
|
assert.ok(readHook(root).split('\n').includes(markerFor(NAMED_FIXTURE)));
|
|
68
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
-
|
|
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
|
-
|
|
105
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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(
|
|
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
|
-
|
|
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
|
|
226
|
-
|
|
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
|
|
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);
|
package/tools/ensure-configs.mjs
CHANGED
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
// autonomy docs/ai/autonomy.json seed-if-missing (same)
|
|
7
7
|
// vehicles docs/ai/vehicles.json seed-if-missing (same)
|
|
8
8
|
// executor .claude/agents/executor.md judged against docs/ai/vehicles.json, never written: a differing body is pending
|
|
9
|
-
// scripts scripts/<ADR enforcement>
|
|
9
|
+
// scripts scripts/<ADR enforcement> the hook installer and its two suites refreshed as one set on a shipped
|
|
10
|
+
// + the installer set prior body (an edited member keeps all three); ADR seeds seed-if-missing, layout detect first
|
|
10
11
|
// specs scripts/<spec layer> reader + checker pairs seeded when absent, refreshed only on
|
|
11
12
|
// + docs/ai/specs/index.md a shipped prior body, an edited one replaced only on the
|
|
12
13
|
// user's yes; store root seeded behind a current checker
|
|
@@ -96,8 +97,10 @@ the project's own checker judges the navigator and a write it rejects is put bac
|
|
|
96
97
|
The executor ensure writes nothing: a placed .claude/agents/executor.md whose bytes differ from the
|
|
97
98
|
body derived from docs/ai/vehicles.json is pending — the advisor's executor-vehicle.differing item
|
|
98
99
|
changes it on your yes; an absent file is never placed here.
|
|
99
|
-
|
|
100
|
-
|
|
100
|
+
A fifth refreshes too: the enforcement-script ensure refreshes the hook installer with its two suites
|
|
101
|
+
as one set on every Node deployment, whatever its ADR layout, only while each refreshed file is a body a
|
|
102
|
+
release shipped (an edited member keeps all three; an absent one is never placed); then it detects an
|
|
103
|
+
older ADR-store layout and instructs the opt-in migration instead of seeding the ADR files.
|
|
101
104
|
|
|
102
105
|
Exit codes: 0 every op fine; 1 an op failed (its line says so) or there is no deployment here; 2 usage.`;
|
|
103
106
|
|
package/tools/ensure-ops.mjs
CHANGED
|
@@ -18,8 +18,9 @@
|
|
|
18
18
|
// orchestration-write.mjs — the file's one writer. Nothing here re-derives either.
|
|
19
19
|
// • Every token names a state this run PROVED. `already-present` follows a probe; `skipped-no-node-evidence`
|
|
20
20
|
// names every Node probe that answered absent; an ADR-layout read that fails is `adr-layout-unverifiable` and
|
|
21
|
-
//
|
|
22
|
-
// tree as `none`, which here would mean seeding a rotator beside a store nobody could inspect)
|
|
21
|
+
// seeds no ADR file (the STRICT survey, fail-closed — the lenient status wrapper reads an unreadable
|
|
22
|
+
// tree as `none`, which here would mean seeding a rotator beside a store nobody could inspect); the
|
|
23
|
+
// installer set's refresh runs before and independent of that read, and its lines stand either way.
|
|
23
24
|
// • A failed op is a non-zero signal, never a line that reads like success.
|
|
24
25
|
//
|
|
25
26
|
// Dependency-free, Node >= 22. Every fs primitive is injectable (deps.*). No side effects on import.
|
|
@@ -29,14 +30,14 @@ import { spawnSync } from 'node:child_process';
|
|
|
29
30
|
import { join } from 'node:path';
|
|
30
31
|
import { CANON_README, CONFIG_REL, SEED_CONFIG, loadConfig, normalizeCanonical, refreshReadme } from './orchestration-config.mjs';
|
|
31
32
|
import { seedConfig, writeConfig } from './orchestration-write.mjs';
|
|
32
|
-
import { lstatNoFollow, writeDocsAiFileAtomic, writeProjectFileCreateOnly } from './atomic-write.mjs';
|
|
33
|
+
import { lstatNoFollow, writeContainedFileAtomic, writeDocsAiFileAtomic, writeProjectFileCreateOnly } from './atomic-write.mjs';
|
|
33
34
|
import { GATES_REL } from './gates-declaration.mjs';
|
|
34
35
|
import { AUTONOMY_REL } from './autonomy-config.mjs';
|
|
35
36
|
import { VEHICLES_REL } from './vehicle-settings.mjs';
|
|
36
37
|
import { surveyAdrLayoutStrict } from './family-registry.mjs';
|
|
37
38
|
import { ENSURE_TOKENS, FAILURE_CAUSES, SEED_SCRIPTS } from './ensure-vocabulary.mjs';
|
|
38
39
|
import { NODE_EVIDENCE, describeNodeProbes, probeNodeEvidence } from './node-evidence.mjs';
|
|
39
|
-
import { classifyDeployedScript } from './script-priors.mjs';
|
|
40
|
+
import { INSTALLER_SET, classifyDeployedScript } from './script-priors.mjs';
|
|
40
41
|
import { parseFrontmatter } from '../references/scripts/check-docs-size.mjs';
|
|
41
42
|
|
|
42
43
|
// The closed vocabulary lives in its own PURE leaf so the read-only doc-parity lint can bind the
|
|
@@ -229,33 +230,83 @@ export const nodeEvidenceRefusal = (op, cwd, lstat) => {
|
|
|
229
230
|
|
|
230
231
|
const OLD_ADR_LAYOUTS = new Set(['old', 'old-unrotated']);
|
|
231
232
|
|
|
232
|
-
// The scripts ensure
|
|
233
|
-
// so is the difference between a failure the reader can act on and one they
|
|
234
|
-
// — the CLI's summary
|
|
233
|
+
// The scripts ensure writes file by file, so a failure PARTWAY leaves earlier writes (refreshed set members,
|
|
234
|
+
// copied seeds) in place. Saying so is the difference between a failure the reader can act on and one they
|
|
235
|
+
// read as "nothing happened" — the CLI's summary claims nothing about writes; this line states the truth.
|
|
236
|
+
const REFRESHED = ' — refreshed to the bundled one';
|
|
235
237
|
const partialNote = (lines) => {
|
|
236
|
-
const copied = lines.filter((line) => line.includes(': copied from the bundled scripts')).length;
|
|
238
|
+
const copied = lines.filter((line) => line.includes(': copied from the bundled scripts') || line.endsWith(REFRESHED)).length;
|
|
237
239
|
return copied > 0 ? [`the copying stopped PARTWAY — the ${copied} file(s) named above were already copied and are NOT rolled back`] : [];
|
|
238
240
|
};
|
|
239
241
|
|
|
242
|
+
// ── the installer set: refreshed as ONE, before and independent of the ADR-layout read ──────────
|
|
243
|
+
|
|
244
|
+
// The deployed suites test the installer beside them, so the three move together: an edited member withholds
|
|
245
|
+
// all three, a prior one is replaced in INSTALLER_SET order (installer first), an absent one stays absent, and
|
|
246
|
+
// with none present nothing is read. → { refusal } or { lines, refreshed, withheld }, each line what this run did.
|
|
247
|
+
const WITHHELD = 'left as it stands because an edited member withholds the set';
|
|
248
|
+
const PRIOR_FATES = { written: REFRESHED, would: ' — would be refreshed to the bundled one', stopped: ' — not refreshed; the run stopped before it', refused: ' — not refreshed; its write was refused (above)' };
|
|
249
|
+
const SET_LINES = {
|
|
250
|
+
absent: () => 'absent — not placed by this op',
|
|
251
|
+
current: (withheld) => (withheld ? WITHHELD : 'already the bundled body — nothing written'),
|
|
252
|
+
custom: () => 'carries an edited body — preserved verbatim; an edited member withholds the set, so none of the three is refreshed',
|
|
253
|
+
prior: (withheld, fate) => (withheld ? WITHHELD : `matches a body an earlier release shipped${PRIOR_FATES[fate]}`),
|
|
254
|
+
};
|
|
255
|
+
const refreshInstallerSet = ({ cwd, kitRoot, dryRun, deps, read, lstat }) => {
|
|
256
|
+
const members = INSTALLER_SET.map((name) => ({ name, rel: `${SCRIPTS_DIR}/${name}`, state: 'absent', probe: probeSeedTarget(join(cwd, SCRIPTS_DIR, name), lstat) }));
|
|
257
|
+
if (!members.some((m) => m.probe.present)) return { lines: [], refreshed: false, withheld: false };
|
|
258
|
+
const wrong = members.find((m) => m.probe.wrongKind);
|
|
259
|
+
if (wrong) return { refusal: loud('scripts', 'wrong-node-kind', `${wrong.rel}: exists but is ${wrong.probe.wrongKind} — nothing was read or written; resolve it by hand, then re-run`) };
|
|
260
|
+
for (const m of members.filter((f) => f.probe.present)) {
|
|
261
|
+
try {
|
|
262
|
+
m.bundle = read(join(kitRoot, 'references', 'scripts', m.name));
|
|
263
|
+
} catch (err) {
|
|
264
|
+
return { refusal: loud('scripts', 'bundle-unreadable', `${m.rel}: the bundled script could not be read, so nothing was written — reinstall the kit. ${causeOf(err)}`) };
|
|
265
|
+
}
|
|
266
|
+
m.state = classifyDeployedScript(read(join(cwd, m.rel)), m.name, m.bundle);
|
|
267
|
+
}
|
|
268
|
+
const withheld = members.some((m) => m.state === 'custom');
|
|
269
|
+
const priors = withheld ? [] : members.filter((m) => m.state === 'prior');
|
|
270
|
+
const fates = new Map();
|
|
271
|
+
const notes = [];
|
|
272
|
+
const linesNow = () => [...members.map((m) => `${m.rel}: ${SET_LINES[m.state](withheld, fates.get(m.rel) ?? (dryRun ? 'would' : 'stopped'))}`), ...notes];
|
|
273
|
+
for (const m of dryRun ? [] : priors) {
|
|
274
|
+
try {
|
|
275
|
+
notes.push(...tmpNote(m.rel, writeContainedFileAtomic(cwd, join(cwd, m.rel), m.bundle, deps, { label: m.rel }).tmpLeftBehind));
|
|
276
|
+
} catch (err) {
|
|
277
|
+
fates.set(m.rel, 'refused');
|
|
278
|
+
const lines = linesNow();
|
|
279
|
+
return { refusal: loud('scripts', 'write-refused', `${m.rel}: ${causeOf(err)}`, ...lines, ...partialNote(lines)) };
|
|
280
|
+
}
|
|
281
|
+
fates.set(m.rel, 'written');
|
|
282
|
+
}
|
|
283
|
+
return { lines: linesNow(), refreshed: priors.length > 0, withheld };
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
// The op's ONE token after the instructed migration: a seed, then the set's refresh, then an edited set kept.
|
|
287
|
+
const scriptsToken = (seeded, set, dryRun) => {
|
|
288
|
+
if (seeded) return dryRun ? 'would-seed' : 'seeded';
|
|
289
|
+
if (set.refreshed) return dryRun ? 'would-refresh' : 'refreshed';
|
|
290
|
+
return set.withheld ? 'customized-preserved' : 'already-present';
|
|
291
|
+
};
|
|
292
|
+
|
|
240
293
|
export const ensureScripts = ({ cwd, kitRoot, dryRun = false, deps = {} }) => {
|
|
241
294
|
const lstat = deps.lstat ?? lstatSync;
|
|
242
295
|
const read = deps.readFile ?? readFileSync;
|
|
243
296
|
const refusal = nodeEvidenceRefusal('scripts', cwd, lstat);
|
|
244
297
|
if (refusal) return refusal;
|
|
298
|
+
const set = refreshInstallerSet({ cwd, kitRoot, dryRun, deps, read, lstat });
|
|
299
|
+
if (set.refusal) return set.refusal;
|
|
245
300
|
let layout;
|
|
246
301
|
try {
|
|
247
302
|
layout = surveyAdrLayoutStrict(cwd, deps);
|
|
248
303
|
} catch (err) {
|
|
249
|
-
return loud('scripts', 'adr-layout-unverifiable', `${SCRIPTS_DIR}/: the ADR-store layout could not be read, so
|
|
304
|
+
return loud('scripts', 'adr-layout-unverifiable', `${SCRIPTS_DIR}/: the ADR-store layout could not be read, so the ADR files were not seeded — a rotator seeded beside an un-migrated store reds the ADR gate. ${causeOf(err)}`, ...set.lines, ...partialNote(set.lines));
|
|
250
305
|
}
|
|
251
306
|
if (OLD_ADR_LAYOUTS.has(layout)) {
|
|
252
|
-
return ok(
|
|
253
|
-
'scripts',
|
|
254
|
-
'old-adr-layout-migration-instructed',
|
|
255
|
-
`${SCRIPTS_DIR}/: this project is still on the older ADR layout (${layout}) — nothing written. Run the opt-in /agent-workflow-kit migrate-adr-store (it previews, and never commits); the seed lands on the next upgrade.`,
|
|
256
|
-
);
|
|
307
|
+
return ok('scripts', 'old-adr-layout-migration-instructed', ...set.lines, `${SCRIPTS_DIR}/: this project is still on the older ADR layout (${layout}) — the ADR files were not seeded. Run the opt-in /agent-workflow-kit migrate-adr-store (it previews, and never commits); the seed lands on the next upgrade.`);
|
|
257
308
|
}
|
|
258
|
-
const lines = [];
|
|
309
|
+
const lines = [...set.lines];
|
|
259
310
|
let anyCreated = false;
|
|
260
311
|
for (const name of SEED_SCRIPTS) {
|
|
261
312
|
const rel = `${SCRIPTS_DIR}/${name}`;
|
|
@@ -290,11 +341,8 @@ export const ensureScripts = ({ cwd, kitRoot, dryRun = false, deps = {} }) => {
|
|
|
290
341
|
lines.push(result.created ? `${rel}: copied from the bundled scripts` : `${rel}: appeared while this run was seeding it — the existing file stands`);
|
|
291
342
|
lines.push(...tmpNote(rel, result.tmpLeftBehind));
|
|
292
343
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
return outcome('scripts', wouldSeed ? 'would-seed' : 'already-present', lines, false);
|
|
296
|
-
}
|
|
297
|
-
return outcome('scripts', anyCreated ? 'seeded' : 'already-present', lines, false);
|
|
344
|
+
const seeded = dryRun ? lines.some((line) => line.includes('would be copied')) : anyCreated;
|
|
345
|
+
return outcome('scripts', scriptsToken(seeded, set, dryRun), lines, false);
|
|
298
346
|
};
|
|
299
347
|
|
|
300
348
|
// ── docs/ai/index.md — the GENERATED navigator, regenerated when missing or stale ───────────────
|
|
@@ -16,9 +16,9 @@ export const ENSURE_OPS = Object.freeze(['orchestration', 'gates', 'autonomy', '
|
|
|
16
16
|
|
|
17
17
|
// Tokens that assert a WRITE happened. --dry-run may never emit one of these (the CLI's contract test
|
|
18
18
|
// walks this set), and each has exactly one `would-` counterpart below. `refreshed` is the spec-layer
|
|
19
|
-
// ensure's pair refresh (reader or checker)
|
|
20
|
-
// rewritten to the bundled one; a custom body is rewritten only by
|
|
21
|
-
// starts (--replace-custom), never by a plain run.
|
|
19
|
+
// ensure's pair refresh (reader or checker) or the scripts ensure's installer-set refresh — a deployed
|
|
20
|
+
// script on a body a release shipped, rewritten to the bundled one; a custom body is rewritten only by
|
|
21
|
+
// the replace run the user's yes starts (--replace-custom, the spec layer's), never by a plain run.
|
|
22
22
|
export const WRITE_TOKENS = Object.freeze(['seeded', 'note-refreshed', 'refreshed', 'regenerated']);
|
|
23
23
|
export const DRY_RUN_TOKENS = Object.freeze(['would-seed', 'would-refresh-note', 'would-refresh', 'would-regenerate']);
|
|
24
24
|
|