@sabaiway/agent-workflow-kit 20.2.0 → 22.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.
- package/CHANGELOG.md +85 -0
- package/README.md +7 -5
- package/SKILL.md +1 -1
- package/bin/install.mjs +10 -11
- package/capability.json +1 -1
- package/launchers/windsurf-workflow.md +3 -1
- package/migrations/3.0.0-hardened-core-loop.md +7 -6
- package/package.json +5 -2
- package/references/advisor-writers.md +1 -1
- package/references/contracts.md +11 -10
- package/references/modes/bootstrap.md +3 -3
- package/references/modes/commit-guard.md +1 -1
- package/references/modes/gates.md +2 -2
- package/references/modes/recommendations.md +3 -3
- package/references/modes/upgrade.md +6 -6
- package/references/scripts/{archive-caps.mjs → archives/archive-caps.mjs} +1 -1
- package/references/scripts/{archive-changelog.mjs → archives/archive-changelog.mjs} +7 -9
- package/references/scripts/{archive-decisions.mjs → archives/archive-decisions.mjs} +13 -10
- package/references/scripts/{archive-issues.mjs → archives/archive-issues.mjs} +7 -8
- package/references/scripts/{check-docs-size.mjs → docs-size/check-docs-size.mjs} +3 -4
- package/references/scripts/docs-size/index.mjs +2 -0
- package/references/scripts/family.json +45 -0
- package/references/scripts/family.mjs +90 -0
- package/references/scripts/gates/kit-command-gates.mjs +117 -0
- package/references/scripts/{migrate-gates.mjs → gates/migrate-gates.mjs} +263 -182
- package/references/scripts/{install-git-hooks.mjs → git-hooks/install-git-hooks.mjs} +50 -38
- package/references/scripts/run.mjs +90 -0
- package/references/scripts/shared/index.mjs +3 -0
- package/references/scripts/shared/project-root.mjs +11 -0
- package/references/scripts/spec-schema/index.mjs +2 -0
- package/references/scripts/test-reporter/reporter.mjs +130 -0
- package/references/shared/composition-handoff.md +1 -1
- package/references/shared/deploy-tail.md +2 -2
- package/references/templates/SPEC_TEMPLATE.md +1 -1
- package/references/templates/adr-record.md +3 -3
- package/tools/apply-danger-check.mjs +9 -5
- package/tools/atomic-write.mjs +3 -1
- package/tools/coverage-producer.mjs +76 -41
- package/tools/direct-run.mjs +2 -0
- package/tools/distribution-files/retired.mjs +99 -0
- package/tools/distribution-files/scripts.mjs +68 -52
- package/tools/ensure-configs.mjs +21 -21
- package/tools/ensure-ops.mjs +60 -18
- package/tools/ensure-specs.mjs +85 -47
- package/tools/ensure-vocabulary.mjs +4 -4
- package/tools/epic-shape-cli.mjs +1 -1
- package/tools/epic-shape-ledger.mjs +1 -1
- package/tools/epic-shape.mjs +1 -1
- package/tools/family-registry.mjs +3 -1
- package/tools/feedback-record-cli.mjs +1 -1
- package/tools/fold-scope.mjs +2 -2
- package/tools/gates-declaration.mjs +22 -14
- package/tools/gates-init.mjs +33 -17
- package/tools/git-hooks.mjs +90 -65
- package/tools/jev-connect.mjs +1 -1
- package/tools/jev-guide.mjs +1 -1
- package/tools/jev-skill.mjs +1 -1
- package/tools/known-footprint.mjs +7 -29
- package/tools/node-evidence.mjs +29 -15
- package/tools/now-cli.mjs +1 -1
- package/tools/payload-prune.mjs +53 -58
- package/tools/plan-shape-cli.mjs +1 -1
- package/tools/plan-shape.mjs +1 -1
- package/tools/project-rules/rules-record.mjs +1 -1
- package/tools/queue-audit-cli.mjs +1 -1
- package/tools/queue-audit.mjs +2 -2
- package/tools/queue-purge-archive.mjs +1 -1
- package/tools/queue-purge-cli.mjs +1 -1
- package/tools/queue-purge.mjs +1 -1
- package/tools/recommendations.mjs +37 -25
- package/tools/script-priors.mjs +31 -3
- package/tools/source-size/piles.mjs +1 -1
- package/tools/spec-adoption.mjs +1 -1
- package/tools/spec-check-ops.mjs +2 -2
- package/tools/spec-check.mjs +2 -2
- package/tools/spec-coverage.mjs +1 -1
- package/tools/tier-guide.mjs +1 -1
- package/tools/transition/index.mjs +1 -1
- package/tools/upgrade-runlist.mjs +3 -3
- package/tools/write-lanes.mjs +2 -2
- package/references/scripts/_expect-shim.mjs +0 -41
- package/references/scripts/archive-caps.test.mjs +0 -321
- package/references/scripts/archive-changelog.test.mjs +0 -560
- package/references/scripts/archive-conservation.test.mjs +0 -466
- package/references/scripts/archive-decisions.test.mjs +0 -1503
- package/references/scripts/archive-issues.test.mjs +0 -825
- package/references/scripts/archiver-structure.test.mjs +0 -84
- package/references/scripts/check-docs-size-cli.test.mjs +0 -325
- package/references/scripts/check-docs-size-ensure.test.mjs +0 -360
- package/references/scripts/check-docs-size.test.mjs +0 -395
- package/references/scripts/install-git-hooks-repo-exec.test.mjs +0 -185
- package/references/scripts/install-git-hooks.test.mjs +0 -241
- package/references/scripts/markdown-blocks.test.mjs +0 -310
- package/references/scripts/migrate-gates-branches.test.mjs +0 -302
- package/references/scripts/migrate-gates.test.mjs +0 -517
- package/references/scripts/spec-schema.test.mjs +0 -352
- /package/references/scripts/{markdown-blocks.mjs → shared/markdown-blocks.mjs} +0 -0
- /package/references/scripts/{spec-schema.mjs → spec-schema/spec-schema.mjs} +0 -0
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// Idempotent installer for the project's git hooks.
|
|
2
|
+
// Idempotent installer for the project's git hooks: `node scripts/agent-workflow/run.mjs install-git-hooks`.
|
|
3
3
|
//
|
|
4
4
|
// Installs the `pre-commit` hook running the docs cap-validator + index-freshness
|
|
5
|
-
// gate + changelog/issues rotation-freshness checks
|
|
6
|
-
//
|
|
7
|
-
// `index.md` navigator cannot silently fall out of sync,
|
|
8
|
-
//
|
|
5
|
+
// gate + changelog/issues/decisions rotation-freshness checks, each through the stable kit
|
|
6
|
+
// command `node scripts/agent-workflow/run.mjs <name>`, so docs files cannot drift over their declared
|
|
7
|
+
// `maxLines`, the auto-generated `index.md` navigator cannot silently fall out of sync, and
|
|
8
|
+
// stale archive entries never reach a commit. The hook runs no suite.
|
|
9
9
|
// First after `set -e` it runs the project's own `scripts/pre-commit.local` with bash when present.
|
|
10
10
|
//
|
|
11
|
+
// The project root is three levels above this file's own folder (scripts/agent-workflow/git-hooks/):
|
|
12
|
+
// the installer imports nothing, so the bytes a danger check binds are the bytes the run executes.
|
|
13
|
+
//
|
|
11
14
|
// The hooks location comes from git's OWN answer (`git rev-parse --git-path hooks`) — a linked
|
|
12
15
|
// worktree resolves ITS OWN hooks path (its `.git` is a FILE; a hardcoded `.git/hooks` would
|
|
13
16
|
// miss or mis-write).
|
|
@@ -29,32 +32,26 @@
|
|
|
29
32
|
// and is carried forward by flagless re-runs exactly as the guard is; no flag disarms either.
|
|
30
33
|
//
|
|
31
34
|
// Package-manager-agnostic: the hook calls the scripts via `node` directly (no pnpm/npm
|
|
32
|
-
// assumption). Re-running is safe — the script
|
|
33
|
-
//
|
|
35
|
+
// assumption). Re-running is safe — the script reads a hook as its own when a line of it, one
|
|
36
|
+
// trailing carriage return dropped, ends with `:install-git-hooks.mjs` (the MAGIC_MARKER names no
|
|
37
|
+
// project, and an older project-named marker still reads as managed) and rewrites only that file.
|
|
34
38
|
//
|
|
35
39
|
// To bypass once (only when truly justified): `git commit --no-verify`.
|
|
36
40
|
|
|
37
41
|
import { writeFile, readFile, mkdir, chmod } from 'node:fs/promises';
|
|
38
|
-
import { existsSync,
|
|
42
|
+
import { existsSync, realpathSync } from 'node:fs';
|
|
39
43
|
import { dirname, resolve, basename } from 'node:path';
|
|
40
44
|
import { fileURLToPath } from 'node:url';
|
|
41
45
|
import { spawnSync } from 'node:child_process';
|
|
42
46
|
|
|
43
47
|
const __filename = fileURLToPath(import.meta.url);
|
|
44
48
|
const __dirname = dirname(__filename);
|
|
45
|
-
const ROOT = resolve(__dirname, '..');
|
|
46
|
-
|
|
47
|
-
const readProjectName = () => {
|
|
48
|
-
try {
|
|
49
|
-
const pkg = JSON.parse(readFileSync(resolve(ROOT, 'package.json'), 'utf8'));
|
|
50
|
-
if (pkg.name) return pkg.name;
|
|
51
|
-
} catch {
|
|
52
|
-
/* no package.json — fall back to repo dir basename */
|
|
53
|
-
}
|
|
54
|
-
return basename(ROOT);
|
|
55
|
-
};
|
|
49
|
+
const ROOT = resolve(__dirname, '..', '..', '..');
|
|
56
50
|
|
|
57
|
-
const MAGIC_MARKER =
|
|
51
|
+
export const MAGIC_MARKER = '# agent-workflow:install-git-hooks.mjs';
|
|
52
|
+
const MARKER_TAIL = ':install-git-hooks.mjs';
|
|
53
|
+
// A hook is this installer's when a line of it, one trailing carriage return dropped, ends with the marker tail.
|
|
54
|
+
export const isManaged = (hook) => hook.split('\n').some((l) => l.replace(/\r$/, '').endsWith(MARKER_TAIL));
|
|
58
55
|
|
|
59
56
|
// git's own hooks location (worktree-correct), or null outside a git checkout.
|
|
60
57
|
const gitHooksDir = () => {
|
|
@@ -133,7 +130,7 @@ const resolveRoleFlag = (argv, { flag, file }) => {
|
|
|
133
130
|
// leaves it out, more than one fails CLOSED naming the role.
|
|
134
131
|
const carriedRolePath = (existingHook, { role, re }) => {
|
|
135
132
|
if (existingHook === null) return null;
|
|
136
|
-
const matches = existingHook.split('\n').map((l) => re.exec(l)).filter(Boolean);
|
|
133
|
+
const matches = existingHook.split('\n').map((l) => re.exec(l.replace(/\r$/, ''))).filter(Boolean);
|
|
137
134
|
if (matches.length > 1) {
|
|
138
135
|
console.error(`[install-git-hooks] the managed pre-commit hook carries ${matches.length} ${role} lines — ambiguous; remove the duplicates by hand and re-run (refusing to guess)`);
|
|
139
136
|
process.exit(1);
|
|
@@ -146,7 +143,7 @@ const carriedRolePath = (existingHook, { role, re }) => {
|
|
|
146
143
|
// ambiguous and fails CLOSED (an installer must never guess which line was the real guard).
|
|
147
144
|
const carriedGuardPath = (existingHook) => {
|
|
148
145
|
if (existingHook === null) return null;
|
|
149
|
-
const matches = existingHook.split('\n').map((l) => GUARD_LINE_RE.exec(l)).filter(Boolean);
|
|
146
|
+
const matches = existingHook.split('\n').map((l) => GUARD_LINE_RE.exec(l.replace(/\r$/, ''))).filter(Boolean);
|
|
150
147
|
if (matches.length > 1) {
|
|
151
148
|
console.error(`[install-git-hooks] the managed pre-commit hook carries ${matches.length} commit-guard --check lines — ambiguous; remove the duplicates by hand and re-run (refusing to guess)`);
|
|
152
149
|
process.exit(1);
|
|
@@ -156,20 +153,23 @@ const carriedGuardPath = (existingHook) => {
|
|
|
156
153
|
|
|
157
154
|
const preCommitContent = (guardPath, rolePaths = []) => `#!/usr/bin/env bash
|
|
158
155
|
${MAGIC_MARKER}
|
|
159
|
-
# Auto-installed by scripts/install-git-hooks
|
|
156
|
+
# Auto-installed by node scripts/agent-workflow/run.mjs install-git-hooks (run it by hand or from the kit).
|
|
160
157
|
# Runs the docs cap-validator + index-freshness gate + rotation-freshness checks
|
|
161
|
-
#
|
|
162
|
-
#
|
|
163
|
-
#
|
|
158
|
+
# before every commit, so files cannot drift over their declared maxLines, the
|
|
159
|
+
# auto-generated index.md cannot silently go stale, and stale archive entries
|
|
160
|
+
# never reach a commit.
|
|
164
161
|
set -e
|
|
165
162
|
# Your own commit checks go in scripts/pre-commit.local; it runs first, with bash, when present.
|
|
166
163
|
if [ -f scripts/pre-commit.local ]; then bash scripts/pre-commit.local; fi
|
|
167
|
-
|
|
168
|
-
node scripts/
|
|
169
|
-
node scripts/
|
|
170
|
-
node scripts/
|
|
171
|
-
node scripts/
|
|
172
|
-
node
|
|
164
|
+
if [ -f scripts/agent-workflow/run.mjs ]; then
|
|
165
|
+
node scripts/agent-workflow/run.mjs docs-size
|
|
166
|
+
node scripts/agent-workflow/run.mjs docs-size --check-index
|
|
167
|
+
node scripts/agent-workflow/run.mjs archive-changelog --check
|
|
168
|
+
node scripts/agent-workflow/run.mjs archive-issues --check
|
|
169
|
+
node scripts/agent-workflow/run.mjs archive-decisions --check
|
|
170
|
+
else
|
|
171
|
+
echo "scripts/agent-workflow/run.mjs is not in this checkout — the kit's docs and archive checks are skipped for this commit; merge the commit that adds scripts/agent-workflow/, or run the kit's upgrade in this checkout"
|
|
172
|
+
fi
|
|
173
173
|
${rolePaths.map((path, at) => (path ? `node "${path}" --check # ${ROLES[at].role}\n` : '')).join('')}${guardPath ? `node "${guardPath}" --check\n` : ''}`;
|
|
174
174
|
|
|
175
175
|
const main = async () => {
|
|
@@ -185,7 +185,7 @@ const main = async () => {
|
|
|
185
185
|
let existing = null;
|
|
186
186
|
if (existsSync(preCommitPath)) {
|
|
187
187
|
existing = await readFile(preCommitPath, 'utf8');
|
|
188
|
-
if (!existing
|
|
188
|
+
if (!isManaged(existing)) {
|
|
189
189
|
console.warn(
|
|
190
190
|
`[install-git-hooks] WARNING: ${preCommitPath} exists and was not installed by this script. Refusing to overwrite — remove or merge it manually.`,
|
|
191
191
|
);
|
|
@@ -205,11 +205,23 @@ const main = async () => {
|
|
|
205
205
|
await writeFile(preCommitPath, content, 'utf8');
|
|
206
206
|
await chmod(preCommitPath, 0o755);
|
|
207
207
|
console.log(
|
|
208
|
-
`[install-git-hooks] installed ${preCommitPath} (docs caps + index freshness + archive checks
|
|
208
|
+
`[install-git-hooks] installed ${preCommitPath} (docs caps + index freshness + archive checks${rolePaths.map((path, at) => (path ? ` + ${ROLES[at].role}` : '')).join('')}${guardPath ? ' + commit guard' : ''}).`,
|
|
209
209
|
);
|
|
210
210
|
};
|
|
211
211
|
|
|
212
|
-
main()
|
|
213
|
-
|
|
214
|
-
process.
|
|
215
|
-
|
|
212
|
+
// Run main() only when executed directly, never on import; compare by REAL path so a symlinked entry still runs.
|
|
213
|
+
const isDirectRun = (() => {
|
|
214
|
+
const invoked = process.argv[1];
|
|
215
|
+
if (!invoked) return false;
|
|
216
|
+
try {
|
|
217
|
+
return realpathSync(invoked) === realpathSync(__filename);
|
|
218
|
+
} catch {
|
|
219
|
+
return false;
|
|
220
|
+
}
|
|
221
|
+
})();
|
|
222
|
+
if (isDirectRun) {
|
|
223
|
+
main().catch((err) => {
|
|
224
|
+
console.error(err);
|
|
225
|
+
process.exit(1);
|
|
226
|
+
});
|
|
227
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// run.mjs — the stable kit command (spec kit-command): `node scripts/agent-workflow/run.mjs <name> [arguments...]`
|
|
3
|
+
// runs the named kit check with every argument unchanged, and `unit-tests` runs the Node test runner with the lcov
|
|
4
|
+
// reporter and the kit test reporter. The names are frozen; the files behind them are the kit's.
|
|
5
|
+
// Dependency-free, Node >= 22. No side effects on import.
|
|
6
|
+
|
|
7
|
+
import { realpathSync, statSync } from 'node:fs';
|
|
8
|
+
import { dirname, join } from 'node:path';
|
|
9
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
10
|
+
import { spawnSync } from 'node:child_process';
|
|
11
|
+
|
|
12
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
13
|
+
const HERE = dirname(__filename);
|
|
14
|
+
|
|
15
|
+
export const KIT_COMMAND_PATH = 'scripts/agent-workflow/run.mjs';
|
|
16
|
+
export const KIT_COMMANDS = Object.freeze({
|
|
17
|
+
'docs-size': 'docs-size/check-docs-size.mjs',
|
|
18
|
+
'archive-changelog': 'archives/archive-changelog.mjs',
|
|
19
|
+
'archive-issues': 'archives/archive-issues.mjs',
|
|
20
|
+
'archive-decisions': 'archives/archive-decisions.mjs',
|
|
21
|
+
'install-git-hooks': 'git-hooks/install-git-hooks.mjs',
|
|
22
|
+
});
|
|
23
|
+
export const UNIT_TESTS_NAME = 'unit-tests';
|
|
24
|
+
export const UNIT_TESTS_REPORTER = 'test-reporter/reporter.mjs';
|
|
25
|
+
|
|
26
|
+
const NAMES = [...Object.keys(KIT_COMMANDS), UNIT_TESTS_NAME];
|
|
27
|
+
const PREFIX = '[run]';
|
|
28
|
+
const USAGE = `Usage: node ${KIT_COMMAND_PATH} <name> [arguments...]
|
|
29
|
+
Runs the named kit check with every argument after the name, unchanged; ${UNIT_TESTS_NAME} runs the Node test runner
|
|
30
|
+
with the lcov reporter and the kit test reporter over the arguments. Names: ${NAMES.join(', ')}.
|
|
31
|
+
`;
|
|
32
|
+
|
|
33
|
+
const isRegularFile = (path) => statSync(path, { throwIfNoEntry: false })?.isFile() === true;
|
|
34
|
+
|
|
35
|
+
// The runner's flags for unit-tests: the lcov under the git dir run-gates exports, the kit reporter on stdout.
|
|
36
|
+
const unitTestsFlags = (gitDir, reporter) => ['--test', '--experimental-test-coverage', '--test-reporter=lcov',
|
|
37
|
+
`--test-reporter-destination=${gitDir}/agent-workflow-lcov.info`, `--test-reporter=${pathToFileURL(reporter).href}`,
|
|
38
|
+
'--test-reporter-destination=stdout'];
|
|
39
|
+
|
|
40
|
+
export const main = (argv = process.argv.slice(2), deps = {}) => {
|
|
41
|
+
const { spawn = spawnSync, isFile = isRegularFile, stdout = process.stdout, stderr = process.stderr, env = process.env } = deps;
|
|
42
|
+
const [name, ...args] = argv;
|
|
43
|
+
if (name === undefined) {
|
|
44
|
+
stderr.write(USAGE);
|
|
45
|
+
return 2;
|
|
46
|
+
}
|
|
47
|
+
if (name === '--help' || name === '-h') {
|
|
48
|
+
stdout.write(USAGE);
|
|
49
|
+
return 0;
|
|
50
|
+
}
|
|
51
|
+
const unitTests = name === UNIT_TESTS_NAME;
|
|
52
|
+
if (!unitTests && !Object.hasOwn(KIT_COMMANDS, name)) {
|
|
53
|
+
stderr.write(`${PREFIX} unknown name ${JSON.stringify(name)} — the known names are ${NAMES.join(', ')}\n`);
|
|
54
|
+
return 2;
|
|
55
|
+
}
|
|
56
|
+
const target = unitTests ? UNIT_TESTS_REPORTER : KIT_COMMANDS[name];
|
|
57
|
+
const file = join(HERE, ...target.split('/'));
|
|
58
|
+
if (!isFile(file)) {
|
|
59
|
+
stderr.write(`${PREFIX} ${name}: scripts/agent-workflow/${target} is not a file of this deployment\n`);
|
|
60
|
+
return 1;
|
|
61
|
+
}
|
|
62
|
+
if (unitTests && !env.AW_GIT_DIR) {
|
|
63
|
+
stderr.write(`${PREFIX} ${name}: AW_GIT_DIR is unset or empty — run-gates exports it; the lcov has no destination\n`);
|
|
64
|
+
return 1;
|
|
65
|
+
}
|
|
66
|
+
const runArgs = unitTests ? [...unitTestsFlags(env.AW_GIT_DIR, file), ...args] : [file, ...args];
|
|
67
|
+
const result = spawn(process.execPath, runArgs, { stdio: 'inherit' });
|
|
68
|
+
const what = unitTests ? 'the test runner' : 'the check';
|
|
69
|
+
if (result.error) {
|
|
70
|
+
stderr.write(`${PREFIX} ${name}: cannot run ${what} (${result.error.message})\n`);
|
|
71
|
+
return 1;
|
|
72
|
+
}
|
|
73
|
+
if (result.signal) {
|
|
74
|
+
stderr.write(`${PREFIX} ${name}: ${what} was killed by ${result.signal}\n`);
|
|
75
|
+
return 1;
|
|
76
|
+
}
|
|
77
|
+
return result.status ?? 1;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
// Run main() only when executed directly, never on import; compare by REAL path so a symlinked entry still runs.
|
|
81
|
+
const isDirectRun = (() => {
|
|
82
|
+
const invoked = process.argv[1];
|
|
83
|
+
if (!invoked) return false;
|
|
84
|
+
try {
|
|
85
|
+
return realpathSync(invoked) === realpathSync(__filename);
|
|
86
|
+
} catch {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
})();
|
|
90
|
+
if (isDirectRun) process.exitCode = main();
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// project-root.mjs — the one project-root finder of the script family (spec script-family).
|
|
2
|
+
//
|
|
3
|
+
// A module file sits in <root>/scripts/agent-workflow/<module>/ in a deployment and in
|
|
4
|
+
// <pkg>/references/scripts/<module>/ in the canon, so the root is the directory three levels above the
|
|
5
|
+
// module file's own directory in both. Dependency-free, Node >= 22. No side effects on import.
|
|
6
|
+
|
|
7
|
+
import { dirname, resolve } from 'node:path';
|
|
8
|
+
import { fileURLToPath } from 'node:url';
|
|
9
|
+
|
|
10
|
+
// `moduleUrl` is a module's import.meta.url (a URL or its href).
|
|
11
|
+
export const findProjectRoot = (moduleUrl) => resolve(dirname(fileURLToPath(moduleUrl)), '..', '..', '..');
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// reporter.mjs — the kit test reporter (spec test-reporter): a `node --test --test-reporter=<this file>`
|
|
2
|
+
// run prints each failing test's block and one totals line, read from the runner's own events, never its text.
|
|
3
|
+
//
|
|
4
|
+
// The default export alone: an async generator over the runner's event stream that yields text. Each event is
|
|
5
|
+
// rendered under its own guard and the totals line always closes the output, so the reporter never throws and
|
|
6
|
+
// never ends the run; it sets no exit code. Dependency-free, Node >= 22. No side effects on import.
|
|
7
|
+
|
|
8
|
+
import { readFileSync } from 'node:fs';
|
|
9
|
+
import { isAbsolute, relative, resolve, sep } from 'node:path';
|
|
10
|
+
import { fileURLToPath } from 'node:url';
|
|
11
|
+
import { inspect } from 'node:util';
|
|
12
|
+
|
|
13
|
+
const QUIET_FAILURES = new Set(['subtestsFailed', 'cancelledByParent']);
|
|
14
|
+
const TOTAL_KEYS = ['tests', 'pass', 'fail', 'cancelled', 'skipped', 'todo'];
|
|
15
|
+
const CLOSING_KEYS = new Set([...TOTAL_KEYS, 'suites', 'duration_ms']);
|
|
16
|
+
const ERROR_HEAD = /^[A-Za-z_$][\w$]*(?: \[[\w$]+\])?: /;
|
|
17
|
+
const FRAME = /^\s*at (?:.*?\()?(.+?):(\d+):(\d+)\)?$/;
|
|
18
|
+
const VALUE_CAP = 500;
|
|
19
|
+
|
|
20
|
+
const isObject = (value) => typeof value === 'object' && value !== null;
|
|
21
|
+
const firstLine = (value) => String(value ?? '').split('\n')[0];
|
|
22
|
+
const toPath = (file) => (String(file).startsWith('file:') ? fileURLToPath(String(file)) : String(file));
|
|
23
|
+
const absolute = (file) => resolve(toPath(file ?? ''));
|
|
24
|
+
const shown = (file) => (file === undefined || file === null ? '?' : relative(process.cwd(), absolute(file)));
|
|
25
|
+
|
|
26
|
+
// An error's first line, or its fallback when the error's own cannot be read.
|
|
27
|
+
const errorLine = (error) => {
|
|
28
|
+
try {
|
|
29
|
+
return firstLine(isObject(error) ? error.message ?? String(error) : error);
|
|
30
|
+
} catch {
|
|
31
|
+
return 'an unreadable error';
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// One line by util.inspect, cut at the cap with an ellipsis.
|
|
36
|
+
const show = (value) => {
|
|
37
|
+
const text = inspect(value, { breakLength: Infinity }).replace(/\n\s*/g, ' ');
|
|
38
|
+
return text.length > VALUE_CAP ? `${text.slice(0, VALUE_CAP)}…` : text;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// The first frame inside the working directory and under no node_modules, with its source text when readable.
|
|
42
|
+
const codeLine = (stack) => {
|
|
43
|
+
for (const frame of String(stack ?? '').split('\n')) {
|
|
44
|
+
const match = FRAME.exec(frame);
|
|
45
|
+
if (!match || !(match[1].startsWith('file:') || isAbsolute(match[1]))) continue;
|
|
46
|
+
const file = absolute(match[1]);
|
|
47
|
+
const inside = relative(process.cwd(), file);
|
|
48
|
+
if (!inside || isAbsolute(inside) || inside.split(sep).some((part) => part === '..' || part === 'node_modules')) continue;
|
|
49
|
+
let text = '';
|
|
50
|
+
try {
|
|
51
|
+
text = readFileSync(file, 'utf8').split(/\r?\n/)[Number(match[2]) - 1]?.trim() ?? '';
|
|
52
|
+
} catch { /* the location alone */ }
|
|
53
|
+
return ` at ${inside}:${match[2]}:${match[3]}${text ? ` ${text}` : ''}`;
|
|
54
|
+
}
|
|
55
|
+
return null;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// The error-head line of a file's standard error, else its first non-blank line.
|
|
59
|
+
const stderrLine = (chunks) => {
|
|
60
|
+
const lines = chunks.join('').split('\n').map((line) => line.trim()).filter(Boolean);
|
|
61
|
+
return lines.find((line) => ERROR_HEAD.test(line) && !line.startsWith('at ')) ?? lines[0];
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const renderFailure = (data, names, stderr) => {
|
|
65
|
+
const error = data.details?.error;
|
|
66
|
+
const cause = error?.cause ?? error;
|
|
67
|
+
const path = [...Array.from({ length: data.nesting ?? 0 }, (_, at) => names[at] ?? '?'), data.name].join(' > ');
|
|
68
|
+
const klass = isObject(cause) && typeof cause.name === 'string' && cause.name ? `${cause.name}: ` : '';
|
|
69
|
+
const lines = [`FAIL ${shown(data.file)}:${data.line ?? '?'} ${path}`, ` ${error?.failureType ?? '?'}: ${klass}${firstLine(isObject(cause) ? cause.message : cause)}`];
|
|
70
|
+
if (isObject(cause) && Object.hasOwn(cause, 'expected') && Object.hasOwn(cause, 'actual')) {
|
|
71
|
+
lines.push(` expected: ${show(cause.expected)}`, ` actual: ${show(cause.actual)}`);
|
|
72
|
+
}
|
|
73
|
+
const at = isObject(cause) ? codeLine(cause.stack) : null;
|
|
74
|
+
if (at) lines.push(at);
|
|
75
|
+
const fileLevel = (data.nesting ?? 0) === 0 && typeof data.name === 'string' && absolute(data.name) === absolute(data.file);
|
|
76
|
+
const line = fileLevel && stderr ? stderrLine(stderr) : undefined;
|
|
77
|
+
if (line) lines.push(` stderr: ${line}`);
|
|
78
|
+
return `${lines.join('\n')}\n`;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export default async function* testReporter(source) {
|
|
82
|
+
const names = new Map();
|
|
83
|
+
const stderr = new Map();
|
|
84
|
+
const totals = {};
|
|
85
|
+
const kept = [];
|
|
86
|
+
let green = null;
|
|
87
|
+
let failed = false;
|
|
88
|
+
const read = (event) => {
|
|
89
|
+
const { type, data } = event ?? {};
|
|
90
|
+
if (type === 'test:start') {
|
|
91
|
+
const key = absolute(data.file);
|
|
92
|
+
names.set(key, names.get(key) ?? []).get(key)[data.nesting] = data.name;
|
|
93
|
+
} else if (type === 'test:stderr') {
|
|
94
|
+
const key = absolute(data.file);
|
|
95
|
+
stderr.set(key, stderr.get(key) ?? []).get(key).push(String(data.message ?? ''));
|
|
96
|
+
} else if (type === 'test:summary') {
|
|
97
|
+
if (data.file === undefined) green = data.success === true;
|
|
98
|
+
} else if (type === 'test:diagnostic') {
|
|
99
|
+
const [key, value] = String(data.message ?? '').split(' ');
|
|
100
|
+
if (data.file === undefined && CLOSING_KEYS.has(key)) {
|
|
101
|
+
if (TOTAL_KEYS.includes(key)) totals[key] = value;
|
|
102
|
+
} else {
|
|
103
|
+
kept.push(`diagnostic: ${firstLine(data.message)}\n`);
|
|
104
|
+
}
|
|
105
|
+
} else if (type === 'test:fail' && !data.todo && !data.skip && !QUIET_FAILURES.has(data.details?.error?.failureType)) {
|
|
106
|
+
failed = true;
|
|
107
|
+
return renderFailure(data, names.get(absolute(data.file)) ?? [], stderr.get(absolute(data.file)));
|
|
108
|
+
}
|
|
109
|
+
return null;
|
|
110
|
+
};
|
|
111
|
+
try {
|
|
112
|
+
for await (const event of source) {
|
|
113
|
+
let text;
|
|
114
|
+
try {
|
|
115
|
+
text = read(event);
|
|
116
|
+
} catch (error) {
|
|
117
|
+
text = `reporter: an event could not be rendered (${errorLine(error)})\n`;
|
|
118
|
+
}
|
|
119
|
+
if (text) yield text;
|
|
120
|
+
}
|
|
121
|
+
} catch (error) {
|
|
122
|
+
yield `reporter: the event stream ended with an error (${errorLine(error)})\n`;
|
|
123
|
+
}
|
|
124
|
+
const red = green === null ? Number(totals.fail) > 0 || Number(totals.cancelled) > 0 : !green;
|
|
125
|
+
if (red) {
|
|
126
|
+
yield* kept;
|
|
127
|
+
if (!failed && kept.length === 0) yield 'reporter: the run failed and no test reported a failure\n';
|
|
128
|
+
}
|
|
129
|
+
yield `${TOTAL_KEYS.map((key) => `${key} ${totals[key] ?? '?'}`).join(' · ')}\n`;
|
|
130
|
+
}
|
|
@@ -35,7 +35,7 @@ refused with their line numbers, nothing written: the upgrade STOPs.
|
|
|
35
35
|
a GENERATED artifact the entry point declares always-loaded, and the deploy may have just
|
|
36
36
|
written a `docs/ai` file — so the finalizer runs at the LAST `docs/ai` mutation of the deploy,
|
|
37
37
|
before the stamp and the report. ONE command:
|
|
38
|
-
`node ${CLAUDE_SKILL_DIR}/references/scripts/check-docs-size.mjs --ensure-index --root=<project>`.
|
|
38
|
+
`node ${CLAUDE_SKILL_DIR}/references/scripts/docs-size/check-docs-size.mjs --ensure-index --root=<project>`.
|
|
39
39
|
Relay its one outcome line (*regenerated* / *already current*); a `write-refused` (the write) or
|
|
40
40
|
`probe-failed` (the tree could not be read) line names the offending path and is a loud STOP,
|
|
41
41
|
never a note. It is idempotent, so an earlier run in the
|
|
@@ -4,12 +4,12 @@ The non-obvious traps — scan these before bootstrapping or upgrading. Each is
|
|
|
4
4
|
|
|
5
5
|
- **Source vs target directory.** Templates and scripts are read from the skill's own dir (`${CLAUDE_SKILL_DIR}/` in Claude Code, the `SKILL.md` folder elsewhere). The **working directory is the target project** — never write kernel files back into the skill.
|
|
6
6
|
- **The `Co-Authored-By` trailer is added by the harness, not by prose.** When attribution is `off`, a doc directive alone won't stop it — for Claude Code the advisor's `attribution` item sets the harness setting in the project's `.claude/settings.json`, on the user's yes after its check. Other tools: disable their equivalent co-author/footer setting.
|
|
7
|
-
- **Hidden mode must never touch `package.json`.** Editing it is a *tracked* change and leaks the whole system. Hidden mode wires nothing into `package.json`; the pre-commit hook (untracked in `.git/hooks/`) calls `node scripts
|
|
7
|
+
- **Hidden mode must never touch `package.json`.** Editing it is a *tracked* change and leaks the whole system. Hidden mode wires nothing into `package.json`; the pre-commit hook (untracked in `.git/hooks/`) calls `node scripts/agent-workflow/run.mjs <name>` directly. After hiding, **verify `git status` shows the artifacts as ignored**.
|
|
8
8
|
- **Hidden mode is project-local, and the hide tool owns the known footprint.** `tools/hide-footprint.mjs` writes **one managed block** in the **project-local `.git/info/exclude`** — never the machine-global `core.excludesFile` (which would silently affect every repo on the host; **AD-014** amends **AD-006**; only its `--remove-global` mode, the `footprint-global` item, edits that file). It hides the kit's own artifacts **and** the known external AI/agent footprint (the `KNOWN_FOOTPRINT` table in [contracts](${CLAUDE_SKILL_DIR}/references/contracts.md#visibility-contract)). A **tracked** file is **never silently un-tracked** — the tool prints the `git rm --cached` it will not run. Never leak its internal marker / asks terms to the user; translate every outcome to plain language.
|
|
9
9
|
- **`CLAUDE.md` is a symlink, not a copy.** `ln -s AGENTS.md CLAUDE.md` — single source, no duplication. A copy drifts; a symlink can't.
|
|
10
10
|
- **Never overwrite an existing entry point or hook.** If `AGENTS.md` / `CLAUDE.md` already exist, **stop and ask** the user to merge vs replace — don't clobber. A non-marker hook stays; moving it aside is the user's step.
|
|
11
11
|
- **Unrecognized invocations are read-only.** Only a **known** subcommand reaches its mode; the **bare** invocation bootstraps (and an existing `docs/ai/` makes it ask upgrade-vs-bootstrap first, never overwrite); **any other / ambiguous** token routes to `help` (read-only). A garbage invocation never writes. The mapping is pinned by `tools/commands.mjs` `routeInvocation` (unit-tested) — don't hand-route around it.
|
|
12
|
-
- **Enforcement is offered on every project.** The dependency-free scripts are available because the agent host already runs the navigator; for the offer, the only skip condition is that the agent host cannot run them. The hook calls `node scripts
|
|
12
|
+
- **Enforcement is offered on every project.** The dependency-free scripts are available because the agent host already runs the navigator; for the offer, the only skip condition is that the agent host cannot run them. The hook calls `node scripts/agent-workflow/run.mjs <name>`, so a committer without `node` on PATH gets the hook's own loud failure. **A skip names a PROVEN fact, never a proxy:** upgrade ensures judge Node by EVIDENCE — Node evidence is a regular root `package.json`, or a regular file, every folder above it a plain directory, at one of the kit's flat script names in `scripts/` or at a deployed path in `scripts/agent-workflow/`; `skipped-no-node-evidence` only when the probe finds none, its line listing every probe that answered absent; a reason the tool could disprove is a tool defect. **A skip line that contradicts the observed tree is raised as a finding in the report, never pasted as neutral** — report the contradiction with the proven fact and do not build on the skip.
|
|
13
13
|
- **Conversational language never translates artifacts.** It governs *dialogue only*. Code, identifiers, paths, commands, log output, abbreviations, and every deployed `docs/ai/` / `AGENTS.md` file stay in their source language. See [Communication contract](${CLAUDE_SKILL_DIR}/references/contracts.md#communication-contract).
|
|
14
14
|
- **Never auto-commit.** Report quality-gate results and wait for explicit approval — in both modes.
|
|
15
15
|
- **Never leak kit internals to the user — and a tool-COMPOSED user-facing line holds the same bar at the source.** No ADR ids, tool / function / operation names (`reconcile`, `inject`, `ensureSlot`), marker / slot / fragment / anchor terminology, or verbatim tool stderr **inside the human sentence** of anything the user reads. Translate every tool outcome into plain language a third-party user — who has never read this `SKILL.md` — can understand and act on (e.g. the kit-block refusal report in `${CLAUDE_SKILL_DIR}/references/modes/upgrade.md` step 3). The composed lines themselves are **user-grade** language: machine tokens and tool self-labels belong to the **machine-line channel** — the `[run-gates] status=…` grammar (`${CLAUDE_SKILL_DIR}/references/modes/gates.md`), a line's leading self-label/prefix, or a runnable command/path the user can act on — never mid-sentence; alarm words (`PARTIALLY`, `incomplete`, `failed`, `broken`, `persists`) render only in outcomes gated on a **detected abnormal condition**. ONE designed exception, stated not implied: the configuration ensures' LEADING outcome token — one closed-vocabulary token, a failure's closed cause word opening its detail line — is that contract's own machine slot, not a leak. The **verbatim**-paste contract stays: the agent pastes tool-composed outcome lines as written and never re-composes their facts — the lines are user-grade at the source, so pasting them verbatim IS the plain language.
|
|
@@ -16,7 +16,7 @@ revision: 1
|
|
|
16
16
|
> (the slug mirrors the feature-slice or module name, `^[a-z0-9]+(-[a-z0-9]+)*$`) and replace every
|
|
17
17
|
> section. NOT deployed on bootstrap — it stays in the skill home like `adr-record.md`. The full
|
|
18
18
|
> schema (kinds, statuses, transitions, promotion, precedence) is the engine canon `references/specs.md`;
|
|
19
|
-
> the deployed reader `scripts/spec-schema.mjs` is what decides well-formed.
|
|
19
|
+
> the deployed reader `scripts/agent-workflow/spec-schema/spec-schema.mjs` is what decides well-formed.
|
|
20
20
|
|
|
21
21
|
## Contract
|
|
22
22
|
|
|
@@ -65,8 +65,8 @@ the **new** ADR; governance is then computed automatically (no predecessor-file
|
|
|
65
65
|
|
|
66
66
|
## Commands
|
|
67
67
|
|
|
68
|
-
- `node scripts/archive-decisions
|
|
68
|
+
- `node scripts/agent-workflow/run.mjs archive-decisions` — rotate: explode the oldest HOT entries beyond the cap into
|
|
69
69
|
`adr/` records, then regenerate the navigator + `docs/ai/index.md`.
|
|
70
|
-
- `node scripts/
|
|
70
|
+
- `node scripts/agent-workflow/run.mjs archive-decisions --write-navigator` — regenerate `docs/ai/adr/log.md` (and the
|
|
71
71
|
index) after authoring an ADR or editing a supersession, so `--check` stays green.
|
|
72
|
-
- `node scripts/
|
|
72
|
+
- `node scripts/agent-workflow/run.mjs archive-decisions --check` — verify HOT cap + store integrity + navigator freshness.
|
|
@@ -24,7 +24,7 @@ import { planFor } from './jev-skill.mjs';
|
|
|
24
24
|
import { SKILL_FILES, claudeDirOf, skillAccepted, skillState, skillTargets } from './jev-facts.mjs';
|
|
25
25
|
import { findOnPath } from './detect-backends.mjs';
|
|
26
26
|
import { consoleArgv } from './write-lanes.mjs';
|
|
27
|
-
import {
|
|
27
|
+
import { DEPLOYED_SCRIPTS, INSTALLER_REL, formatPlan, planGitHooks } from './git-hooks.mjs';
|
|
28
28
|
import { ATTRIBUTION_HIDDEN, ATTRIBUTION_KEY, writeAttribution } from './attribution.mjs';
|
|
29
29
|
import { globalRemovalOf, planGlobalRemoval } from './hide-footprint.mjs';
|
|
30
30
|
import { isDirectRun } from './direct-run.mjs';
|
|
@@ -232,14 +232,18 @@ export const scopeOf = (variant, facts, deps = {}) => {
|
|
|
232
232
|
for (let at = target.root; at !== target.base && covers(target.base, at); at = dirname(at)) directories.push(at);
|
|
233
233
|
filePaths.push(target.path);
|
|
234
234
|
}
|
|
235
|
-
const scripts = join(facts.root, SCRIPTS_REL);
|
|
236
235
|
if (GIT_VARIANTS.includes(variant)) {
|
|
237
|
-
|
|
238
|
-
|
|
236
|
+
// Each deployed path under the kit folder, and each folder on its way below the root.
|
|
237
|
+
const copies = variant === 'hook-checks' ? [] : DEPLOYED_SCRIPTS.map(({ deployed }) => join(facts.root, deployed));
|
|
238
|
+
directories.splice(0);
|
|
239
|
+
for (const path of copies) {
|
|
240
|
+
for (let at = dirname(path); at !== facts.root && covers(facts.root, at) && !directories.includes(at); at = dirname(at)) directories.push(at);
|
|
241
|
+
}
|
|
242
|
+
filePaths.push(...copies);
|
|
239
243
|
}
|
|
240
244
|
const rules = ['--rules-check', join(facts.toolsDir, 'project-rules', 'rules-cli.mjs')];
|
|
241
245
|
const layout = ['--layout-check', join(facts.toolsDir, 'source-size-check.mjs')];
|
|
242
|
-
const flagSets = variant === 'hook-checks' ? [rules, layout, [...rules, ...layout]]
|
|
246
|
+
const flagSets = variant === 'hook-checks' ? [[], rules, layout, [...rules, ...layout]]
|
|
243
247
|
: variant === 'commit-guard' ? [['--commit-guard', join(facts.toolsDir, 'commit-guard.mjs')]] : [[]];
|
|
244
248
|
const runs = GIT_VARIANTS.includes(variant) ? flagSets.map((flags) => ['node', INSTALLER_REL, ...flags]) : [];
|
|
245
249
|
return {
|
package/tools/atomic-write.mjs
CHANGED
|
@@ -201,9 +201,11 @@ export const writeHostConfigFileAtomic = (dir, filename, body, deps = {}, opts =
|
|
|
201
201
|
// writeProjectFileCreateOnly(root, rel, body, deps, opts) → { writtenPath: rel, created }. Gate =
|
|
202
202
|
// create+verify the target's PARENT dir inside the project (a symlinked `scripts/` is a STOP, not a
|
|
203
203
|
// write through it); root = the project dir; the write is create-only, so an existing file is left
|
|
204
|
-
// exactly as it is and `created` says so.
|
|
204
|
+
// exactly as it is and `created` says so. The folders above the parent are walked for a link first, so
|
|
205
|
+
// the parent's `mkdir -p` never makes a folder through one.
|
|
205
206
|
export const writeProjectFileCreateOnly = (root, rel, body, deps = {}, opts = {}) => {
|
|
206
207
|
const dst = join(root, rel);
|
|
208
|
+
if (dirname(dst) !== root) assertContainedRealPath(root, dirname(dirname(dst)), { lstat: deps.lstat ?? lstatSync });
|
|
207
209
|
assertCreatableDirSafe(dirname(dst), deps, opts);
|
|
208
210
|
const { created, tmpLeftBehind } = writeContainedFileAtomic(root, dst, body, deps, { ...opts, createOnly: true, label: rel });
|
|
209
211
|
return { writtenPath: rel, created, tmpLeftBehind };
|