@sabaiway/agent-workflow-kit 23.12.0 → 24.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 +58 -0
- package/README.md +4 -4
- package/SKILL.md +1 -1
- package/bridges/codex-cli-bridge/SKILL.md +7 -2
- package/bridges/codex-cli-bridge/bin/codex-exec-jev.test.mjs +11 -6
- package/bridges/codex-cli-bridge/bin/codex-exec.sh +72 -33
- package/bridges/codex-cli-bridge/bin/codex-exec.test.mjs +111 -3
- package/bridges/codex-cli-bridge/bin/codex-fixtures-harness.test.mjs +16 -1
- package/bridges/codex-cli-bridge/bin/codex-model-posture.test.mjs +5 -3
- package/bridges/codex-cli-bridge/bin/codex-review.sh +1 -1
- package/bridges/codex-cli-bridge/capability.json +2 -2
- package/capability.json +1 -1
- package/package.json +1 -1
- package/references/advisor-writers.md +2 -0
- package/references/agents/author.md +21 -0
- package/references/agents/executor.md +12 -6
- package/references/contracts.md +4 -4
- package/references/hooks/gate-approve.mjs +7 -8
- package/references/hooks/stage-write-guard.mjs +314 -0
- package/references/modes/agents.md +6 -4
- package/references/modes/bootstrap.md +1 -1
- package/references/modes/flow-writer.md +10 -2
- package/references/modes/hook.md +4 -1
- package/references/modes/now.md +1 -1
- package/references/modes/procedures.md +49 -10
- package/references/modes/recipes.md +7 -7
- package/references/modes/recommendations.md +4 -3
- package/references/modes/robustness-brief.md +9 -8
- package/references/modes/set-recipe.md +1 -1
- package/references/modes/state-block-guard.md +4 -3
- package/references/modes/status.md +1 -1
- package/references/modes/upgrade.md +1 -1
- package/references/modes/worktrees.md +28 -5
- package/references/rules/story-sessions.md +2 -2
- package/references/scripts/archives/archive-caps.mjs +1 -1
- package/references/scripts/archives/archive-changelog.mjs +8 -8
- package/references/scripts/archives/archive-decisions.mjs +7 -7
- package/references/scripts/archives/archive-issues.mjs +5 -5
- package/references/scripts/archives/rotation-conservation.mjs +2 -1
- package/references/scripts/docs-size/check-docs-size.mjs +15 -15
- package/references/scripts/family.json +2 -0
- package/references/scripts/gates/kit-command-gates.mjs +7 -8
- package/references/scripts/gates/migrate-gates.mjs +10 -10
- package/references/scripts/git-hooks/install-git-hooks.mjs +13 -13
- package/references/scripts/run.mjs +1 -2
- package/references/scripts/shared/index.mjs +2 -0
- package/references/scripts/shared/locations.mjs +103 -0
- package/references/scripts/spec-schema/spec-schema.mjs +2 -1
- package/references/templates/orchestration.json +1 -1
- package/tools/ack-store.mjs +2 -1
- package/tools/apply-danger-check.mjs +20 -6
- package/tools/atomic-write.mjs +3 -2
- package/tools/attribution.mjs +2 -1
- package/tools/autonomy-config.mjs +2 -1
- package/tools/bridge-wiring.mjs +13 -11
- package/tools/carriers.mjs +54 -14
- package/tools/cheap-agents-read.mjs +28 -7
- package/tools/cheap-agents.mjs +15 -10
- package/tools/checker-gates-read.mjs +6 -5
- package/tools/commands.mjs +2 -2
- package/tools/coverage-declared/config.mjs +2 -1
- package/tools/coverage-producer.mjs +10 -9
- package/tools/delegation.mjs +7 -6
- package/tools/detect-backends.mjs +1 -1
- package/tools/dispatch-baseline.mjs +2 -1
- package/tools/distribution-files/scripts.mjs +4 -4
- package/tools/ensure-configs.mjs +2 -2
- package/tools/ensure-ops.mjs +24 -24
- package/tools/ensure-specs.mjs +7 -7
- package/tools/epic-shape-cli.mjs +2 -2
- package/tools/epic-shape-ledger.mjs +5 -5
- package/tools/epic-shape.mjs +5 -3
- package/tools/epic-store.mjs +2 -1
- package/tools/family-members.mjs +7 -5
- package/tools/family-registry.mjs +36 -30
- package/tools/feedback-record-cli.mjs +4 -5
- package/tools/flow-writer.mjs +26 -15
- package/tools/gate-hook.mjs +33 -28
- package/tools/gates-declaration.mjs +2 -1
- package/tools/gates-init.mjs +6 -5
- package/tools/git-hooks.mjs +64 -41
- package/tools/grounding.mjs +3 -2
- package/tools/hide-footprint.mjs +2 -1
- package/tools/hook-writer/index.mjs +147 -0
- package/tools/init-preflight.mjs +5 -4
- package/tools/init-project.mjs +12 -11
- package/tools/inject-methodology.mjs +3 -2
- package/tools/jev-guide.mjs +2 -2
- package/tools/known-footprint.mjs +27 -25
- package/tools/mcp-registration.mjs +6 -5
- package/tools/migration-blocks.mjs +2 -1
- package/tools/migration-notes.mjs +2 -2
- package/tools/node-evidence.mjs +4 -4
- package/tools/now-facts.mjs +5 -5
- package/tools/now-status.mjs +1 -5
- package/tools/orchestration-config.mjs +2 -1
- package/tools/orchestration-readme.mjs +7 -2
- package/tools/plan-approval/cli.mjs +45 -0
- package/tools/plan-approval/entries.mjs +109 -0
- package/tools/plan-approval/index.mjs +2 -0
- package/tools/plan-approval/record.mjs +198 -0
- package/tools/plan-files.mjs +6 -4
- package/tools/plan-shape-cli.mjs +10 -64
- package/tools/plan-shape-facts.mjs +240 -83
- package/tools/plan-shape.mjs +173 -160
- package/tools/plan-structure/cli.mjs +79 -0
- package/tools/plan-structure/index.mjs +67 -0
- package/tools/procedures.mjs +21 -17
- package/tools/profile-gaps.mjs +4 -6
- package/tools/project-rules/rules-priors.mjs +2 -0
- package/tools/project-rules/themes.mjs +6 -4
- package/tools/recipes.mjs +44 -29
- package/tools/recommendations.mjs +84 -33
- package/tools/reference-profile.mjs +2 -2
- package/tools/renderers.mjs +14 -8
- package/tools/repo-lex.mjs +84 -0
- package/tools/robustness-brief.mjs +14 -11
- package/tools/satellite-locator.mjs +3 -2
- package/tools/script-priors.mjs +3 -2
- package/tools/session-close-check.mjs +71 -15
- package/tools/set-flow.mjs +2 -2
- package/tools/set-recipe.mjs +17 -9
- package/tools/source-size/help.mjs +4 -4
- package/tools/source-size/layout.mjs +2 -1
- package/tools/source-size/piles.mjs +2 -2
- package/tools/source-size-config.mjs +3 -3
- package/tools/source-size-refusal.mjs +4 -3
- package/tools/source-size-report.mjs +41 -13
- package/tools/spec-check-cli.mjs +159 -21
- package/tools/spec-check-ops.mjs +74 -5
- package/tools/spec-check.mjs +54 -45
- package/tools/spec-coverage-cli.mjs +3 -2
- package/tools/stage-render/cli.mjs +231 -0
- package/tools/stage-render/index.mjs +340 -0
- package/tools/stage-render/stages.json +115 -0
- package/tools/stage-write-guard/cli.mjs +64 -0
- package/tools/stage-write-guard/index.mjs +56 -0
- package/tools/state-block-hook.mjs +38 -163
- package/tools/task-brief.mjs +8 -13
- package/tools/task-thread.mjs +3 -1
- package/tools/tier-guide-facts.mjs +23 -9
- package/tools/tier-preview.mjs +15 -19
- package/tools/transition/index.mjs +10 -9
- package/tools/uninstall.mjs +26 -12
- package/tools/vehicle-settings.mjs +2 -1
- package/tools/velocity-profile.mjs +5 -6
- package/tools/view-model.mjs +7 -4
- package/tools/worktree-prompt.mjs +7 -3
- package/tools/worktrees.mjs +235 -159
- package/tools/write-lanes.mjs +20 -14
package/tools/spec-check-cli.mjs
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
//
|
|
5
5
|
// node spec-check-cli.mjs --op modify=docs/ai/specs/login.md [--op ...] [--root <dir>]
|
|
6
6
|
// node spec-check-cli.mjs --ops-file docs/plans/spec-ops.list
|
|
7
|
+
// node spec-check-cli.mjs --plan docs/plans/<name>.md [--root <dir>]
|
|
7
8
|
// node spec-check-cli.mjs --all
|
|
8
9
|
//
|
|
9
10
|
// `--op` and `--ops-file` UNION and dedup by identity; `--all` is exclusive of both. The register
|
|
@@ -19,32 +20,38 @@
|
|
|
19
20
|
// unreadable register, a --root that is not a directory, or an --all run with no store root.
|
|
20
21
|
// Dependency-free, Node >= 22.
|
|
21
22
|
|
|
22
|
-
import { lstatSync, readdirSync,
|
|
23
|
-
import { resolve } from 'node:path';
|
|
23
|
+
import { lstatSync, readdirSync, realpathSync } from 'node:fs';
|
|
24
|
+
import { basename, dirname, posix, relative, resolve, sep } from 'node:path';
|
|
25
|
+
import { readSpecDocument } from '../references/scripts/spec-schema/index.mjs';
|
|
26
|
+
import { dirCovers } from './declared-paths.mjs';
|
|
24
27
|
import { isDirectRun } from './direct-run.mjs';
|
|
25
|
-
import { readRegularFileNoFollow } from './fs-read-nofollow.mjs';
|
|
26
|
-
import {
|
|
28
|
+
import { describeNonRegular, lstatNoFollowRead, readRegularFileNoFollow } from './fs-read-nofollow.mjs';
|
|
29
|
+
import { PLANS_REL } from './plan-files.mjs';
|
|
30
|
+
import { expandSweepPaths, isSweep, readPlansInFlight } from './plan-shape-facts.mjs';
|
|
31
|
+
import { SPEC_OPS_GRAMMAR, getRevisionHomePath, getRevisionStorePath, listingParentOf, parsePlanSpecOps, parseSpecOps } from './spec-check-ops.mjs';
|
|
27
32
|
import { checkSpecs } from './spec-check.mjs';
|
|
28
33
|
|
|
29
|
-
const { verbs, separator, storePrefix } = SPEC_OPS_GRAMMAR;
|
|
34
|
+
const { verbs, separator, storePrefix, storeRoot, suffix } = SPEC_OPS_GRAMMAR;
|
|
30
35
|
|
|
31
36
|
const HELP = `spec-check — judge the feature-spec store against what this session says it changed.
|
|
32
37
|
|
|
33
38
|
Usage:
|
|
34
39
|
node spec-check-cli.mjs [--root <dir>] --op <op> [--op <op> ...]
|
|
35
40
|
node spec-check-cli.mjs [--root <dir>] --ops-file <file>
|
|
41
|
+
node spec-check-cli.mjs [--root <dir>] --plan docs/plans/<name>.md
|
|
36
42
|
node spec-check-cli.mjs [--root <dir>] --all
|
|
37
43
|
|
|
38
44
|
An op is one of ${verbs.slice(0, -1).map((v) => `${v}=<path>`).join(' | ')} | rename=<old>${separator}<new>, and every
|
|
39
45
|
path is a POSIX repo-relative .md document inside ${storePrefix} whose segments are kebab slugs.
|
|
40
|
-
Nothing is normalized away and the store root is never an op
|
|
41
|
-
one accepted spelling.
|
|
46
|
+
Nothing is normalized away and the store root is never an --op or --ops-file target (--plan judges
|
|
47
|
+
it by a modify row), so one document has exactly one accepted spelling.
|
|
42
48
|
|
|
43
49
|
--op repeatable; unions --ops-file and dedups by identity.
|
|
44
50
|
--ops-file one op per line; blank lines and # comments parse away. Never defaulted — name the
|
|
45
51
|
register this session wrote (e.g. docs/plans/spec-ops.list).
|
|
52
|
+
--plan judge the named in-flight plan's store rows and revisions. Exclusive of --op, --ops-file and --all.
|
|
46
53
|
--all judge the WHOLE store instead: reachability (unlisted child vs orphan), acyclicity,
|
|
47
|
-
store-wide slug uniqueness and module overlap. Exclusive of
|
|
54
|
+
store-wide slug uniqueness and module overlap. Exclusive of --op, --ops-file and --plan.
|
|
48
55
|
--root the repo root the paths are relative to (default: the process cwd).
|
|
49
56
|
|
|
50
57
|
The check is advisory — nothing records that it ran, so a skipped or late call is indistinguishable
|
|
@@ -52,7 +59,7 @@ from one made before the edit.
|
|
|
52
59
|
|
|
53
60
|
Exit codes: 0 ACCEPT; 1 findings; 2 usage (bad flag or op, unreadable register, bad --root).`;
|
|
54
61
|
|
|
55
|
-
const FLAGS = ['op', 'ops-file', 'all', 'root'];
|
|
62
|
+
const FLAGS = ['op', 'ops-file', 'plan', 'all', 'root'];
|
|
56
63
|
const REPEATABLE = ['op'];
|
|
57
64
|
const BOOLEAN = ['all'];
|
|
58
65
|
|
|
@@ -71,6 +78,7 @@ const parseArgs = (argv) => {
|
|
|
71
78
|
let value = eq === -1 ? argv[i + 1] : arg.slice(eq + 1);
|
|
72
79
|
if (eq === -1) i += 1;
|
|
73
80
|
if (value === undefined || (eq === -1 && value.startsWith('--'))) throw new Error(`--${name} requires a value`);
|
|
81
|
+
if (name === 'plan' && opts.plan !== undefined) throw new Error('--plan takes exactly one plan');
|
|
74
82
|
if (REPEATABLE.includes(name)) opts[name].push(value);
|
|
75
83
|
else opts[name] = value;
|
|
76
84
|
}
|
|
@@ -111,43 +119,173 @@ export const list = (path) => {
|
|
|
111
119
|
// exactly the alias the frozen grammar denies. The ops parser refuses that whitespace out loud.
|
|
112
120
|
const opsFileLines = (text) => text.split(/\r?\n/).filter((line) => line.trim() !== '' && !line.trim().startsWith('#'));
|
|
113
121
|
|
|
122
|
+
const causeOf = (error) => error?.code ?? error?.message ?? String(error);
|
|
123
|
+
const pathError = (path, message) => Object.assign(new Error(message), { path });
|
|
124
|
+
const readContent = (path) => {
|
|
125
|
+
const { outcome, code, className, content } = readRegularFileNoFollow(path);
|
|
126
|
+
if (outcome !== 'ok') throw pathError(path, `cannot read (${code ?? className ?? (outcome === 'absent' ? 'ENOENT' : outcome)})`);
|
|
127
|
+
return content;
|
|
128
|
+
};
|
|
129
|
+
const isPlanSpelling = (path) => path === `${PLANS_REL}/${posix.basename(path)}` &&
|
|
130
|
+
path.endsWith(suffix) && posix.basename(path).length > suffix.length && !/[\\\0]/.test(path);
|
|
131
|
+
const repoPath = (root, path) => relative(root, path).split(sep).join('/');
|
|
132
|
+
|
|
133
|
+
const proveRevisionHome = (root, home, ops, files) => {
|
|
134
|
+
const homePath = resolve(root, home);
|
|
135
|
+
const status = lstatNoFollowRead(homePath);
|
|
136
|
+
if (status === null) return;
|
|
137
|
+
const rootReal = realpathSync(root);
|
|
138
|
+
const roles = new Map(ops.map(({ verb, target }) => [target, verb]));
|
|
139
|
+
const proveDirectory = (path, status) => {
|
|
140
|
+
if (!status.isDirectory()) throw pathError(path, `expected a plain directory, found ${describeNonRegular(status)}`);
|
|
141
|
+
if (!dirCovers(root, path) || !dirCovers(rootReal, realpathSync(path))) throw pathError(path, 'directory resolves outside the root');
|
|
142
|
+
};
|
|
143
|
+
const proveParents = (path) => {
|
|
144
|
+
if (path === root) return;
|
|
145
|
+
proveParents(dirname(path));
|
|
146
|
+
proveDirectory(path, lstatSync(path));
|
|
147
|
+
};
|
|
148
|
+
const readStore = (rel, allowAbsent = false) => {
|
|
149
|
+
const path = resolve(root, rel);
|
|
150
|
+
proveParents(dirname(path));
|
|
151
|
+
const status = lstatNoFollowRead(path);
|
|
152
|
+
if (status === null && allowAbsent) return null;
|
|
153
|
+
if (!status?.isFile()) throw pathError(path, `expected a regular store document, found ${status === null ? 'ENOENT' : describeNonRegular(status)}`);
|
|
154
|
+
const content = readContent(path);
|
|
155
|
+
return { ...readSpecDocument(content, rel.slice(storePrefix.length)), content };
|
|
156
|
+
};
|
|
157
|
+
const admit = (path) => {
|
|
158
|
+
const rel = getRevisionStorePath(home, repoPath(root, path));
|
|
159
|
+
const role = roles.get(rel);
|
|
160
|
+
if (rel === storeRoot || (role !== 'modify' && role !== 'add')) throw pathError(path, 'no eligible store row for this home file');
|
|
161
|
+
const content = readContent(path);
|
|
162
|
+
const { kind } = readSpecDocument(content, rel.slice(storePrefix.length));
|
|
163
|
+
const parent = listingParentOf(rel);
|
|
164
|
+
if (role === 'add' ? kind !== 'part' || roles.get(parent) !== 'modify' : kind !== 'spec' && kind !== 'part') {
|
|
165
|
+
throw pathError(path, 'expected a contract revision or a new part beside a root the plan modifies');
|
|
166
|
+
}
|
|
167
|
+
const stored = readStore(rel, role === 'add');
|
|
168
|
+
if (role === 'modify' && stored.kind !== kind) throw pathError(resolve(root, rel), 'the store document and its revision must have the same kind');
|
|
169
|
+
if (role === 'add' && stored !== null && stored.content !== content) throw pathError(resolve(root, rel), 'store and home bytes differ');
|
|
170
|
+
const contract = kind === 'part' ? readStore(parent) : stored;
|
|
171
|
+
const isLandedCopy = (target, document) => {
|
|
172
|
+
const source = resolve(root, home, target.slice(storePrefix.length));
|
|
173
|
+
return lstatNoFollowRead(source)?.isFile() === true && readContent(source) === document.content;
|
|
174
|
+
};
|
|
175
|
+
const landed = stored?.content === content || isLandedCopy(kind === 'part' ? parent : rel, contract);
|
|
176
|
+
if (contract.kind !== 'spec' || (contract.status !== 'live' && !landed) ||
|
|
177
|
+
(role === 'modify' && kind === 'part' && !contract.structure?.parts.some(({ target }) => target === `./${basename(rel)}`))) {
|
|
178
|
+
throw pathError(path, 'the home document must revise or belong to a live contract in the store');
|
|
179
|
+
}
|
|
180
|
+
files.set(rel, path);
|
|
181
|
+
};
|
|
182
|
+
const walk = (path, status) => {
|
|
183
|
+
proveDirectory(path, status);
|
|
184
|
+
for (const name of readdirSync(path)) {
|
|
185
|
+
const entry = resolve(path, name);
|
|
186
|
+
const status = lstatSync(entry);
|
|
187
|
+
if (status.isDirectory()) walk(entry, status);
|
|
188
|
+
else if (status.isFile()) admit(entry);
|
|
189
|
+
else throw pathError(entry, `expected a plain directory or regular file, found ${describeNonRegular(status)}`);
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
proveParents(dirname(homePath));
|
|
193
|
+
walk(homePath, status);
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
const storeIO = { read: readRegularFileNoFollow, probe, realpath, list };
|
|
197
|
+
const overlayStore = (root, files, ops) => {
|
|
198
|
+
const revisions = new Map([...files].map(([path, source]) => [resolve(root, path), source]));
|
|
199
|
+
const deleted = new Set(ops.filter(({ verb }) => verb === 'remove').map(({ target }) => resolve(root, target)));
|
|
200
|
+
const additions = new Map();
|
|
201
|
+
for (const path of revisions.keys()) {
|
|
202
|
+
const parent = dirname(path);
|
|
203
|
+
additions.set(parent, [...(additions.get(parent) ?? []), basename(path)]);
|
|
204
|
+
}
|
|
205
|
+
const sourceOf = (path) => revisions.get(resolve(path)) ?? path;
|
|
206
|
+
const removed = (path) => deleted.has(resolve(path)) && probe(path) === 'file';
|
|
207
|
+
return {
|
|
208
|
+
read: (path) => removed(path) ? { outcome: 'absent' } : readRegularFileNoFollow(sourceOf(path)),
|
|
209
|
+
probe: (path) => removed(path) ? 'absent' : probe(sourceOf(path)),
|
|
210
|
+
realpath: (path) => removed(path) ? null : realpath(sourceOf(path)),
|
|
211
|
+
list: (path) => {
|
|
212
|
+
const names = list(path);
|
|
213
|
+
if (names === null) return null;
|
|
214
|
+
return [...new Set([...names, ...(additions.get(resolve(path)) ?? [])])].filter((name) => !removed(resolve(path, name)));
|
|
215
|
+
},
|
|
216
|
+
};
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
const showVerdict = ({ exit: code, lines }) => {
|
|
220
|
+
const output = lines.join('\n');
|
|
221
|
+
return code === 2 ? { code, stdout: '', stderr: output } : { code, stdout: output, stderr: '' };
|
|
222
|
+
};
|
|
223
|
+
|
|
114
224
|
// main(argv, deps) -> { code, stdout, stderr }. Never calls process.exit itself (the direct-run
|
|
115
225
|
// guard does), and never reads anything the caller did not point it at.
|
|
116
226
|
export const main = (argv, deps = {}) => {
|
|
117
227
|
if (argv.includes('--help') || argv.includes('-h')) return { code: 0, stdout: HELP, stderr: '' };
|
|
118
|
-
const read = deps.readFileSync ??
|
|
228
|
+
const read = deps.readFileSync ?? readContent;
|
|
119
229
|
const cwd = deps.cwd ?? (() => process.cwd());
|
|
120
230
|
const usage = (message) => ({ code: 2, stdout: '', stderr: `spec-check: ${message}` });
|
|
121
|
-
let opts;
|
|
122
231
|
try {
|
|
123
|
-
opts = parseArgs(argv);
|
|
232
|
+
const opts = parseArgs(argv);
|
|
233
|
+
return checkArgs(opts, cwd(), read, usage);
|
|
124
234
|
} catch (err) {
|
|
125
|
-
return usage(err
|
|
235
|
+
return usage(err?.message ?? causeOf(err));
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
const checkArgs = (opts, workingDir, read, usage) => {
|
|
240
|
+
const planLane = opts.plan !== undefined;
|
|
241
|
+
if (planLane && (opts.all || opts.op.length > 0 || opts['ops-file'] !== undefined)) {
|
|
242
|
+
return usage('--plan is exclusive of --all, --op and --ops-file');
|
|
126
243
|
}
|
|
244
|
+
if (planLane && !isPlanSpelling(opts.plan)) return usage(`--plan "${opts.plan}" must use the spelling ${PLANS_REL}/<name>${suffix} relative to --root`);
|
|
127
245
|
if (opts.all && (opts.op.length > 0 || opts['ops-file'])) {
|
|
128
246
|
return usage('--all judges the whole store and is exclusive of --op and --ops-file — run one lane or the other');
|
|
129
247
|
}
|
|
130
|
-
const root = resolve(
|
|
131
|
-
if (probe(root) !== 'dir') return usage(`--root "${opts.root ??
|
|
248
|
+
const root = resolve(workingDir, opts.root ?? '.');
|
|
249
|
+
if (probe(root) !== 'dir') return usage(`--root "${opts.root ?? workingDir}" is not a directory`);
|
|
250
|
+
const readPlans = () => readPlansInFlight(root).plans;
|
|
251
|
+
const plans = planLane ? readPlans() : undefined;
|
|
252
|
+
const plan = plans?.find(({ identity }) => identity === opts.plan);
|
|
253
|
+
if (planLane && !plan) return usage(`${opts.plan} is not an in-flight plan`);
|
|
254
|
+
if (plan && !plan.accepted) return usage(plan.result.findings
|
|
255
|
+
.map(({ line, code, message }) => `${plan.identity}:${line}: ${code} — ${message}`).join('\nspec-check: '));
|
|
132
256
|
let specs = [...opts.op];
|
|
133
257
|
if (opts['ops-file']) {
|
|
134
|
-
const register = resolve(
|
|
258
|
+
const register = resolve(workingDir, opts['ops-file']);
|
|
135
259
|
try {
|
|
136
260
|
specs = [...specs, ...opsFileLines(read(register, 'utf8'))];
|
|
137
261
|
} catch (err) {
|
|
138
|
-
return usage(`--ops-file "${opts['ops-file']}" is unreadable — ${(err
|
|
262
|
+
return usage(`--ops-file "${opts['ops-file']}" is unreadable — ${causeOf(err)}`);
|
|
139
263
|
}
|
|
140
264
|
}
|
|
141
265
|
let ops = [];
|
|
142
266
|
if (!opts.all) {
|
|
143
|
-
const parsed = parseSpecOps(specs);
|
|
267
|
+
const parsed = plan ? parsePlanSpecOps(plan.rows, isSweep, (sweep) => expandSweepPaths(root, [sweep])[sweep]) : parseSpecOps(specs);
|
|
144
268
|
if (parsed.errors.length > 0) {
|
|
145
|
-
return usage(parsed.errors.map((e) => `${e.code} — ${e.message}`).join('\nspec-check: '));
|
|
269
|
+
return usage(parsed.errors.map((e) => `${plan ? `${plan.identity}: ` : ''}${e.code} — ${e.message}`).join('\nspec-check: '));
|
|
146
270
|
}
|
|
147
271
|
ops = parsed.ops;
|
|
148
272
|
}
|
|
149
|
-
|
|
150
|
-
return {
|
|
273
|
+
if (plan) return checkPlan(root, plan.identity, ops, plans);
|
|
274
|
+
return showVerdict(checkSpecs({ root, ops, all: Boolean(opts.all), plans: readPlans }, storeIO));
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
const checkPlan = (root, plan, ops, plans) => {
|
|
278
|
+
const homePath = getRevisionHomePath(plan);
|
|
279
|
+
const files = new Map();
|
|
280
|
+
try {
|
|
281
|
+
proveRevisionHome(root, homePath, ops, files);
|
|
282
|
+
} catch (err) {
|
|
283
|
+
const path = err?.path ? repoPath(root, err.path) : homePath;
|
|
284
|
+
return { code: 1, stdout: `spec-check: REFUSE — revision home\n ${path}: revision-home — ${causeOf(err)}`, stderr: '' };
|
|
285
|
+
}
|
|
286
|
+
if (ops.length === 0) return { code: 0, stdout: 'spec-check: ACCEPT — the plan names no store document', stderr: '' };
|
|
287
|
+
const home = { plan, paths: [...files.keys()] };
|
|
288
|
+
return showVerdict(checkSpecs({ root, ops, plans, home }, overlayStore(root, files, ops)));
|
|
151
289
|
};
|
|
152
290
|
|
|
153
291
|
if (isDirectRun(import.meta.url)) {
|
package/tools/spec-check-ops.mjs
CHANGED
|
@@ -18,12 +18,15 @@
|
|
|
18
18
|
// source of the prefix, the navigator filename or the slug pattern. Pure strings in, ops out — the
|
|
19
19
|
// filesystem belongs to spec-check.mjs. Dependency-free, Node >= 22.
|
|
20
20
|
|
|
21
|
+
import { sep } from 'node:path';
|
|
21
22
|
import { SPEC_SCHEMA } from '../references/scripts/spec-schema/index.mjs';
|
|
22
23
|
|
|
23
24
|
const STORE = SPEC_SCHEMA.storePrefix;
|
|
24
25
|
const NAV = SPEC_SCHEMA.navigatorFile;
|
|
25
26
|
const SUFFIX = '.md';
|
|
26
27
|
const SEPARATOR = ':';
|
|
28
|
+
const HOME_SUFFIX = '.specs';
|
|
29
|
+
const PLAN_OP_VERBS = Object.freeze({ create: 'add', modify: 'modify', delete: 'remove' });
|
|
27
30
|
|
|
28
31
|
export const SPEC_OPS_GRAMMAR = Object.freeze({
|
|
29
32
|
verbs: Object.freeze(['add', 'modify', 'remove', 'rename']),
|
|
@@ -43,7 +46,7 @@ const VERBS = SPEC_OPS_GRAMMAR.verbs;
|
|
|
43
46
|
// The ONE target judgement, ordered from the most literal defect to the most structural. The store
|
|
44
47
|
// PREFIX is asked before the dot segments on purpose: `./docs/ai/specs/x.md` is not a store path
|
|
45
48
|
// that needs normalizing, it is a path outside the store, and saying so is the honest refusal.
|
|
46
|
-
const targetDefect = (target) => {
|
|
49
|
+
const targetDefect = (target, allowStoreRoot = false) => {
|
|
47
50
|
if (target.includes('\\')) return { code: 'op-target', reason: 'a backslash is not a path separator here' };
|
|
48
51
|
if (DRIVE_RE.test(target)) return { code: 'op-target', reason: 'a drive letter is not a repo-relative path' };
|
|
49
52
|
if (target.startsWith('/')) return { code: 'op-target', reason: 'an absolute path is not repo-relative' };
|
|
@@ -54,7 +57,7 @@ const targetDefect = (target) => {
|
|
|
54
57
|
return { code: 'op-target', reason: 'a dot segment is never resolved away — write the path as it is' };
|
|
55
58
|
}
|
|
56
59
|
if (!target.endsWith(SUFFIX)) return { code: 'op-target', reason: `a spec document is a ${SUFFIX} file` };
|
|
57
|
-
if (target === SPEC_OPS_GRAMMAR.storeRoot) {
|
|
60
|
+
if (target === SPEC_OPS_GRAMMAR.storeRoot && !allowStoreRoot) {
|
|
58
61
|
return { code: 'op-root', reason: 'the store root is the navigator, never an op target' };
|
|
59
62
|
}
|
|
60
63
|
const segments = target.slice(STORE.length).split('/');
|
|
@@ -94,7 +97,7 @@ const roleConflict = (roles) => SHAPES[[...roles].sort().join(',')] ?? 'two role
|
|
|
94
97
|
// parseSpecOps(specs) -> { ops, errors }. Every op is judged, so one call names EVERY defect; any
|
|
95
98
|
// error at all empties `ops` — a partially-understood change set would attest a post-state nobody
|
|
96
99
|
// declared.
|
|
97
|
-
|
|
100
|
+
const parseOps = (specs, fromPlan) => {
|
|
98
101
|
const errors = [];
|
|
99
102
|
const ops = [];
|
|
100
103
|
const seen = new Set();
|
|
@@ -130,7 +133,7 @@ export const parseSpecOps = (specs) => {
|
|
|
130
133
|
errors.push({ code: 'op-grammar', message: `"${spec}" — rename takes <old>${SEPARATOR}<new>: exactly one separator "${SEPARATOR}"` });
|
|
131
134
|
continue;
|
|
132
135
|
}
|
|
133
|
-
const defect = sides.map(targetDefect).find(Boolean);
|
|
136
|
+
const defect = sides.map((side) => targetDefect(side, fromPlan && verb === 'modify')).find(Boolean);
|
|
134
137
|
if (defect) {
|
|
135
138
|
errors.push({ code: defect.code, message: `"${spec}" — ${defect.reason}` });
|
|
136
139
|
continue;
|
|
@@ -148,12 +151,32 @@ export const parseSpecOps = (specs) => {
|
|
|
148
151
|
ops.push({ verb, target: payload });
|
|
149
152
|
}
|
|
150
153
|
}
|
|
151
|
-
if (errors.length === 0 && ops.length === 0) {
|
|
154
|
+
if (!fromPlan && errors.length === 0 && ops.length === 0) {
|
|
152
155
|
errors.push({ code: 'op-empty', message: 'no op to judge — name at least one --op or --ops-file entry, or run --all' });
|
|
153
156
|
}
|
|
154
157
|
return { ops: errors.length > 0 ? [] : ops, errors };
|
|
155
158
|
};
|
|
156
159
|
|
|
160
|
+
export const parseSpecOps = (specs) => parseOps(specs, false);
|
|
161
|
+
|
|
162
|
+
const reachesStore = (path, isSweep, expand) => {
|
|
163
|
+
const segments = path.split('/');
|
|
164
|
+
const lead = segments.slice(0, segments.findIndex(isSweep)).join('/');
|
|
165
|
+
if (`${lead}/`.startsWith(STORE)) return true;
|
|
166
|
+
return (lead === '' || STORE.startsWith(`${lead}/`)) && expand(path).some((match) => match.startsWith(STORE));
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
export const parsePlanSpecOps = (rows, isSweep, expand) => {
|
|
170
|
+
const sweep = rows.find(({ path }) => isSweep(path) && reachesStore(path, isSweep, expand));
|
|
171
|
+
if (sweep) {
|
|
172
|
+
const message = `${sweep.id} ${sweep.path}: --plan judges one store document per row; name each store document in its own row`;
|
|
173
|
+
return { ops: [], errors: [{ code: 'op-sweep', message }] };
|
|
174
|
+
}
|
|
175
|
+
return parseOps(rows
|
|
176
|
+
.filter(({ path }) => path.startsWith(STORE) && path.endsWith(SUFFIX))
|
|
177
|
+
.map(({ verb, path }) => `${PLAN_OP_VERBS[verb]}=${path}`), true);
|
|
178
|
+
};
|
|
179
|
+
|
|
157
180
|
// buildClosure(ops) -> [{ path, roles }] sorted: every op path PLUS the document that lists it.
|
|
158
181
|
// A listing parent that is itself an op target keeps its op role; two ops under one parent name it
|
|
159
182
|
// once; ops under different parents name both.
|
|
@@ -179,3 +202,49 @@ export const buildClosure = (ops) => {
|
|
|
179
202
|
.map(([path, roles]) => ({ path, roles }))
|
|
180
203
|
.sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));
|
|
181
204
|
};
|
|
205
|
+
|
|
206
|
+
export const parsePendingModulePath = (claimed) => {
|
|
207
|
+
const kind = claimed.endsWith('/') ? 'dir' : 'file';
|
|
208
|
+
const path = kind === 'dir' ? claimed.slice(0, -1) : claimed;
|
|
209
|
+
const valid = path.split('/').every((segment) => segment !== '' && segment !== '.' && segment !== '..');
|
|
210
|
+
return valid ? { path, kind } : null;
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
const pendingModulePlan = ({ identity, rows }) => ({
|
|
214
|
+
identity,
|
|
215
|
+
creates: rows.filter(({ verb }) => verb === 'create').map(({ path }) => path),
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
export const selectPendingModulePlans = (plans = [], { path, status, home }) => {
|
|
219
|
+
const revision = home?.paths.includes(path);
|
|
220
|
+
if (!revision && status !== 'draft') return { plan: null, refusedPlans: [] };
|
|
221
|
+
const documentVerb = revision ? 'modify' : 'create';
|
|
222
|
+
const candidates = plans.filter(({ identity, rows }) => (!revision || identity === home.plan) &&
|
|
223
|
+
rows.some((row) => row.verb === documentVerb && row.path === path));
|
|
224
|
+
const accepted = candidates.filter(({ accepted }) => accepted === true);
|
|
225
|
+
return {
|
|
226
|
+
plan: accepted.length === 1 ? pendingModulePlan(accepted[0]) : null,
|
|
227
|
+
refusedPlans: candidates.filter(({ accepted }) => accepted === false).map(pendingModulePlan),
|
|
228
|
+
};
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
const isStrictDescendant = (path, directory) => path !== directory &&
|
|
232
|
+
path.startsWith(directory.endsWith(sep) ? directory : `${directory}${sep}`);
|
|
233
|
+
|
|
234
|
+
export const hasPendingModuleCover = (canonicalPath, kind, canonicalCreates) => {
|
|
235
|
+
const cover = canonicalCreates.filter((path) => kind === 'dir' ? isStrictDescendant(path, canonicalPath) : path === canonicalPath);
|
|
236
|
+
return cover.length > 0 && !cover.some((file) => canonicalCreates.some((path) => isStrictDescendant(file, path)));
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
export const getRevisionHomePath = (plan, storePath) => {
|
|
240
|
+
const home = `${plan.slice(0, -SUFFIX.length)}${HOME_SUFFIX}`;
|
|
241
|
+
if (storePath === undefined) return home;
|
|
242
|
+
return targetDefect(storePath, true) === null ? `${home}/${storePath.slice(STORE.length)}` : null;
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
export const getRevisionStorePath = (home, homePath) => {
|
|
246
|
+
const prefix = `${home}/`;
|
|
247
|
+
if (!homePath.startsWith(prefix)) return null;
|
|
248
|
+
const target = `${STORE}${homePath.slice(prefix.length)}`;
|
|
249
|
+
return targetDefect(target, true) === null ? target : null;
|
|
250
|
+
};
|
package/tools/spec-check.mjs
CHANGED
|
@@ -1,29 +1,8 @@
|
|
|
1
|
-
// spec-check.mjs —
|
|
2
|
-
//
|
|
3
|
-
// It answers ONE question per document: given what the session says it changed, does the store on
|
|
4
|
-
// disk say the same thing? The change source is EXPLICIT (parsed ops, never git), and "well-formed"
|
|
5
|
-
// has no second definition here — every per-document verdict is RELAYED from the ONE reader
|
|
6
|
-
// (references/scripts/spec-schema/index.mjs) and its 2a `structure` extraction. This module adds only what
|
|
7
|
-
// text alone cannot decide: does the post-state on disk match the declared op, is the document
|
|
8
|
-
// listed by its parent, does its scenario marker really occur once in the file it names, and — under
|
|
9
|
-
// --all — the five invariants that span documents.
|
|
10
|
-
//
|
|
11
|
-
// Two lanes:
|
|
12
|
-
// session the closure of the declared ops (targets + their listing parents), judged per document.
|
|
13
|
-
// --all every document under the store, plus: unlisted child (DISTINCT from orphan),
|
|
14
|
-
// acyclicity, store-wide slug uniqueness, module overlap. An ABSENT store root refuses.
|
|
15
|
-
//
|
|
16
|
-
// FAIL-CLOSED before every read. Containment is judged lexically AND by realpath over each
|
|
17
|
-
// path-bearing field, and the parents of a leaf are judged BEFORE the leaf is opened. The LEAF read
|
|
18
|
-
// itself is descriptor-bound and no-follow (the CLI half passes fs-read-nofollow.mjs in), so a
|
|
19
|
-
// pathname swapped after the probe cannot change the bytes judged. A mid-run PARENT swap is a
|
|
20
|
-
// STATED non-goal: this is an advisory checker, not a custody mechanism.
|
|
21
|
-
//
|
|
22
|
-
// No IO of its own: { read, probe, realpath, list } are injected. Dependency-free, Node >= 22.
|
|
1
|
+
// spec-check.mjs — see docs/ai/specs/kit/spec-layer/spec-check.md.
|
|
23
2
|
|
|
24
|
-
import { dirname as pathDirname, isAbsolute, relative, sep } from 'node:path';
|
|
3
|
+
import { dirname as pathDirname, isAbsolute, join, relative, sep } from 'node:path';
|
|
25
4
|
import { SPEC_SCHEMA, readSpecDocument, classifyPath } from '../references/scripts/spec-schema/index.mjs';
|
|
26
|
-
import { SPEC_OPS_GRAMMAR, buildClosure, listingParentOf, slugOf } from './spec-check-ops.mjs';
|
|
5
|
+
import { SPEC_OPS_GRAMMAR, buildClosure, listingParentOf, slugOf, parsePendingModulePath, selectPendingModulePlans, hasPendingModuleCover } from './spec-check-ops.mjs';
|
|
27
6
|
|
|
28
7
|
const STORE = SPEC_OPS_GRAMMAR.storePrefix;
|
|
29
8
|
const NAV = SPEC_OPS_GRAMMAR.navigator;
|
|
@@ -35,11 +14,9 @@ const STORE_DIR = STORE.slice(0, -1);
|
|
|
35
14
|
// as a regular file, so a state that has changed underneath since is a fact to state, never a
|
|
36
15
|
// document to drop quietly from a store the run would otherwise call clean.
|
|
37
16
|
const DECLARED_STATE = Object.freeze({ add: 'file', modify: 'file', 'rename-to': 'file', remove: 'absent', 'rename-from': 'absent', present: 'file' });
|
|
38
|
-
const missing = () => {
|
|
39
|
-
throw new Error('spec-check: an IO dependency was not injected — this module owns no filesystem of its own');
|
|
40
|
-
};
|
|
17
|
+
const missing = () => { throw new Error('spec-check: an IO dependency was not injected — this module owns no filesystem of its own'); };
|
|
41
18
|
|
|
42
|
-
const dirOf = (rel) => rel.slice(0, rel.lastIndexOf('/'));
|
|
19
|
+
const dirOf = (rel) => rel.slice(0, Math.max(rel.lastIndexOf('/'), 0));
|
|
43
20
|
const leafOf = (rel) => rel.slice(rel.lastIndexOf('/') + 1);
|
|
44
21
|
const bare = (rel) => (rel.endsWith('/') ? rel.slice(0, -1) : rel);
|
|
45
22
|
const lineCount = (text) => text.replace(/\n$/, '').split('\n').length;
|
|
@@ -156,15 +133,25 @@ const judgeEdges = (doc, ctx) => {
|
|
|
156
133
|
}
|
|
157
134
|
};
|
|
158
135
|
|
|
136
|
+
const canonicalGround = (path, ctx, ancestor = false, state = ctx.io.probe(ctx.at(path))) => {
|
|
137
|
+
const { io, at, rootReal } = ctx;
|
|
138
|
+
const absent = state === 'absent' && path !== '';
|
|
139
|
+
const real = absent ? canonicalGround(dirOf(path), ctx, true) : io.realpath(at(path));
|
|
140
|
+
if (real === null || !contained(rootReal, real)) return null;
|
|
141
|
+
if (absent) return join(real, leafOf(path));
|
|
142
|
+
const kind = state === 'symlink' ? io.probe(real) : state;
|
|
143
|
+
return kind === 'dir' || (!ancestor && kind === 'file') ? real : null;
|
|
144
|
+
};
|
|
145
|
+
|
|
159
146
|
// The per-document judgement, identical in both lanes: the relayed reader rules, the kind's own
|
|
160
147
|
// line cap, the listed edges, the D4 scenario bindings and the containment of every path it names.
|
|
161
|
-
const judgeDocument = (doc, ctx) => {
|
|
148
|
+
const judgeDocument = (doc, ctx, groundOnly = false) => {
|
|
162
149
|
const { io, at, rootReal, add } = ctx;
|
|
163
150
|
const { path, verdict } = doc;
|
|
164
151
|
if (verdict === null) return;
|
|
165
|
-
for (const error of verdict.errors) add('reader', path, `${error.rule}: ${error.message}`, { readerRule: error.rule });
|
|
152
|
+
for (const error of verdict.errors) if (!groundOnly || verdict.structure === null || error.rule.startsWith('module-')) add('reader', path, `${error.rule}: ${error.message}`, { readerRule: error.rule });
|
|
166
153
|
const cap = SPEC_SCHEMA.maxLines[verdict.kind];
|
|
167
|
-
if (cap !== undefined && doc.lines > cap) {
|
|
154
|
+
if (!groundOnly && cap !== undefined && doc.lines > cap) {
|
|
168
155
|
add('threshold', path, `${doc.lines} lines over the ${verdict.kind} cap of ${cap} — promote it to <slug>/index.md + parts`);
|
|
169
156
|
}
|
|
170
157
|
const structure = verdict.structure;
|
|
@@ -176,21 +163,28 @@ const judgeDocument = (doc, ctx) => {
|
|
|
176
163
|
const wantDir = claimed.endsWith('/');
|
|
177
164
|
const target = bare(claimed);
|
|
178
165
|
const real = io.realpath(at(target));
|
|
179
|
-
if (real
|
|
180
|
-
add('module', path, `the module path ${claimed} names ground that is not there`);
|
|
181
|
-
continue;
|
|
182
|
-
}
|
|
183
|
-
if (!contained(rootReal, real)) {
|
|
166
|
+
if (real !== null && !contained(rootReal, real)) {
|
|
184
167
|
add('contained', path, `the module path ${claimed} resolves outside the root (${real})`);
|
|
185
168
|
continue;
|
|
186
169
|
}
|
|
187
170
|
const state = io.probe(at(target));
|
|
171
|
+
if (real === null || state === 'absent') {
|
|
172
|
+
const canonical = state === 'absent' && parsePendingModulePath(claimed) && canonicalGround(target, ctx, false, state);
|
|
173
|
+
const { plan, refusedPlans } = selectPendingModulePlans(canonical ? ctx.plans : [], { path, status: verdict.status, home: ctx.home });
|
|
174
|
+
const covers = ({ creates }) => canonical && hasPendingModuleCover(canonical, wantDir ? 'dir' : 'file', creates
|
|
175
|
+
.filter((path) => classifyPath(path) === 'file' && parsePendingModulePath(path)).map((path) => canonicalGround(path, ctx)).filter(Boolean));
|
|
176
|
+
if (plan && covers(plan)) doc.ground.push(canonical);
|
|
177
|
+
else add('module', path, [`the module path ${claimed} names ground that is not there`,
|
|
178
|
+
...refusedPlans.filter(covers).map(({ identity }) => `structurally refused plan: ${identity}`)].join('; '));
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
188
181
|
if (state !== (wantDir ? 'dir' : 'file')) {
|
|
189
182
|
add('module', path, `the module path ${claimed} is "${state}", not the ${wantDir ? 'directory' : 'file'} it declares`);
|
|
190
183
|
continue;
|
|
191
184
|
}
|
|
192
185
|
doc.ground.push(real);
|
|
193
186
|
}
|
|
187
|
+
if (groundOnly) return;
|
|
194
188
|
judgeEdges(doc, ctx);
|
|
195
189
|
for (const scenario of structure.scenarios) {
|
|
196
190
|
if (scenario.binding === null) continue;
|
|
@@ -226,19 +220,22 @@ const judgeDocument = (doc, ctx) => {
|
|
|
226
220
|
// The listing judgement — a SESSION-lane rule: the document the ops touched must be listed by its
|
|
227
221
|
// parent exactly once after an add/modify/rename-to, and not at all after a remove/rename-from.
|
|
228
222
|
// Under --all the reachability invariants below own this ground instead, so it never doubles up.
|
|
229
|
-
const judgeListing = (doc, docs, add) => {
|
|
223
|
+
const judgeListing = (doc, docs, add, home) => {
|
|
230
224
|
const declared = doc.roles.map((role) => DECLARED_STATE[role]).find(Boolean);
|
|
231
225
|
if (!declared) return;
|
|
232
226
|
const parent = listingParentOf(doc.path);
|
|
233
227
|
if (parent === null) return;
|
|
234
228
|
const holder = docs.get(parent);
|
|
229
|
+
const revised = home?.paths.includes(parent) && holder?.verdict?.kind === 'spec' && dirOf(parent) === dirOf(doc.path);
|
|
230
|
+
if (doc.roles.includes('present') && !revised) return;
|
|
235
231
|
const link = expectedLink(doc.path, parent);
|
|
232
|
+
if (declared === 'absent' && holder?.roles.includes('remove') && holder.state === 'absent') return;
|
|
236
233
|
if (!holder || holder.state !== 'file' || holder.verdict === null) {
|
|
237
234
|
add('listed', doc.path, `its listing parent ${parent} cannot be read, so nothing states whether ${link} is listed`);
|
|
238
235
|
return;
|
|
239
236
|
}
|
|
240
237
|
const found = linkTargetsOf(holder).filter((target) => target === link).length;
|
|
241
|
-
if (declared === 'file' && found !== 1) add('listed', doc.path, `${parent} lists ${link} ${found} time(s) — a present document is listed exactly once`);
|
|
238
|
+
if (declared === 'file' && found !== 1) add(revised && found === 0 ? 'unlisted-child' : 'listed', doc.path, `${parent} lists ${link} ${found} time(s) — a present document is listed exactly once`);
|
|
242
239
|
if (declared === 'absent' && found !== 0) add('listed', doc.path, `${parent} still lists ${link} — a removed document is listed by nobody`);
|
|
243
240
|
};
|
|
244
241
|
|
|
@@ -327,6 +324,9 @@ const judgeStore = (docs, ctx) => {
|
|
|
327
324
|
for (const [slug, paths] of bySlug) {
|
|
328
325
|
if (paths.length > 1) for (const rel of paths) add('slug-unique', rel, `the slug "${slug}" is claimed by ${paths.length} documents (${paths.join(', ')}) — a slug is store-wide`);
|
|
329
326
|
}
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
const judgeOverlap = (docs, add, targets) => {
|
|
330
330
|
// PROVEN canonical ground only (judgeDocument) — a path that never resolved is not compared as if
|
|
331
331
|
// it had. Nesting is asked with the platform's own path model — `dirname` walked upward, never a
|
|
332
332
|
// hand-rolled separator rule — and it is asked ONCE PER PATH rather than once per pair: the store
|
|
@@ -346,7 +346,7 @@ const judgeStore = (docs, ctx) => {
|
|
|
346
346
|
// Any separator those paths might themselves contain makes the key non-injective, and the pair
|
|
347
347
|
// that collides would be dropped in silence.
|
|
348
348
|
const note = (one, other, claimed) => {
|
|
349
|
-
if (one === other) return;
|
|
349
|
+
if (one === other || (targets && !targets.has(one) && !targets.has(other))) return;
|
|
350
350
|
const [a, b] = [one, other].sort();
|
|
351
351
|
const key = JSON.stringify([a, b]);
|
|
352
352
|
if (!pairs.has(key)) pairs.set(key, { a, b, claimed });
|
|
@@ -364,17 +364,19 @@ const judgeStore = (docs, ctx) => {
|
|
|
364
364
|
}
|
|
365
365
|
};
|
|
366
366
|
|
|
367
|
-
// checkSpecs({ root, ops, all }, deps) -> { verdict, exit, findings, documents, lines }.
|
|
367
|
+
// checkSpecs({ root, ops, all, plans, home }, deps) -> { verdict, exit, findings, documents, lines }.
|
|
368
368
|
// Exit 0 ACCEPT · 1 one or more findings · 2 a refusal about the RUN itself (an unresolvable root,
|
|
369
369
|
// an absent store root under --all) — the CLI prints the lines and returns the code.
|
|
370
|
-
export const checkSpecs = ({ root, ops = [], all = false } = {}, deps = {}) => {
|
|
370
|
+
export const checkSpecs = ({ root, ops = [], all = false, plans, home } = {}, deps = {}) => {
|
|
371
371
|
const io = { read: missing, probe: missing, realpath: missing, list: missing, ...deps };
|
|
372
372
|
const at = (rel) => (rel === '' ? root : `${root}/${rel}`);
|
|
373
373
|
const rootReal = io.realpath(root);
|
|
374
374
|
if (rootReal === null) return refusal(`--root "${root}" does not resolve to a directory — nothing can be judged against it`);
|
|
375
375
|
const findings = [];
|
|
376
376
|
const add = (rule, path, message, extra = {}) => findings.push({ rule, path, message, ...extra });
|
|
377
|
-
const
|
|
377
|
+
const planCache = {};
|
|
378
|
+
const filterPlans = (predicate) => (planCache.plans ??= plans()).filter(predicate);
|
|
379
|
+
const ctx = { io, at, rootReal, add, plans: typeof plans === 'function' ? { filter: filterPlans } : plans, home: all ? undefined : home };
|
|
378
380
|
if (all && io.probe(at(STORE_ROOT)) !== 'file') {
|
|
379
381
|
return refusal(`the store root ${STORE_ROOT} is not a regular file — an --all run over no store would report an empty clean store, so it refuses instead`);
|
|
380
382
|
}
|
|
@@ -383,9 +385,16 @@ export const checkSpecs = ({ root, ops = [], all = false } = {}, deps = {}) => {
|
|
|
383
385
|
// the empty-closure usage error would throw away the only thing the run learned, so the usage
|
|
384
386
|
// refusal is the SESSION lane's alone.
|
|
385
387
|
if (closure.length === 0 && findings.length === 0) return refusal('no document to judge — the op closure is empty');
|
|
386
|
-
const
|
|
387
|
-
|
|
388
|
+
const targets = new Set(closure.map(({ path }) => path));
|
|
389
|
+
const removed = new Set(ctx.home ? ops.filter(({ verb }) => verb === 'remove').map(({ target }) => at(target)) : []);
|
|
390
|
+
const storePaths = ctx.home ? [...new Set([...walkStore(ctx), ...ctx.home.paths])] : [];
|
|
391
|
+
const entries = closure.concat(storePaths.filter((path) => !targets.has(path)).map((path) => ({ path, roles: ['present'] })));
|
|
392
|
+
if (removed.size > 0) ctx.io = { ...io, probe: (path, state = io.probe(path)) => removed.has(path) && state === 'file' ? 'absent' : state };
|
|
393
|
+
const docs = readClosure(entries, ctx);
|
|
394
|
+
for (const doc of docs.values()) judgeDocument(doc, ctx, !targets.has(doc.path));
|
|
388
395
|
if (all) judgeStore(docs, ctx);
|
|
389
|
-
else for (const doc of docs.values()) judgeListing(doc, docs, add);
|
|
396
|
+
else for (const doc of docs.values()) judgeListing(doc, docs, add, ctx.home);
|
|
397
|
+
if (all || (ctx.home && !findings.some(({ rule }) => rule === 'census') &&
|
|
398
|
+
entries.every(({ path, roles }) => roles.includes('remove') || docs.get(path)?.verdict?.structure))) judgeOverlap(docs, add, all ? undefined : targets);
|
|
390
399
|
return verdictOf(findings, closure.length, all ? 'the whole store' : `${ops.length} op(s)`);
|
|
391
400
|
};
|
|
@@ -7,11 +7,12 @@
|
|
|
7
7
|
|
|
8
8
|
import { readFileSync, readdirSync, writeFileSync } from 'node:fs';
|
|
9
9
|
import { join, relative, sep } from 'node:path';
|
|
10
|
+
import { SPEC_COVERAGE, SPEC_STORE } from '../references/scripts/shared/index.mjs';
|
|
10
11
|
import { isDirectRun } from './direct-run.mjs';
|
|
11
12
|
import { claimsOf, formatFindings, judgeCoverage, settleAfter } from './spec-coverage.mjs';
|
|
12
13
|
|
|
13
|
-
export const SCOPE_PATH = join(
|
|
14
|
-
export const STORE_ROOT = join(
|
|
14
|
+
export const SCOPE_PATH = join(SPEC_COVERAGE);
|
|
15
|
+
export const STORE_ROOT = join(SPEC_STORE);
|
|
15
16
|
const REASON_MAX_BYTES = 300;
|
|
16
17
|
|
|
17
18
|
const HELP = `spec-coverage — every shipped tool is governed by a contract, or the debt names it.
|