@sabaiway/agent-workflow-kit 14.47.0 → 14.49.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 +49 -0
- package/SKILL.md +1 -1
- package/capability.json +1 -1
- package/migrations/3.0.0-hardened-core-loop.md +2 -3
- package/package.json +1 -1
- package/references/contracts.md +27 -2
- package/references/modes/upgrade.md +3 -3
- package/references/scripts/archive-decisions.mjs +316 -112
- package/tools/distribution-files/scripts.mjs +79 -90
- package/tools/ensure-configs.mjs +23 -23
- package/tools/ensure-ops.mjs +2 -2
- package/tools/ensure-vocabulary.mjs +7 -7
- package/tools/git-hooks.mjs +1 -1
- package/tools/script-priors.mjs +4 -2
- package/tools/upgrade-runlist.mjs +1 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// scripts.mjs — the upgrade's `scripts` op: every kit script of a deployment, the hook installer set
|
|
2
2
|
// included, kept current by the one rule. Each family file is surveyed by proof before any write:
|
|
3
|
-
// absent, current, prior (a body SCRIPT_PRIORS catalogs for its name) or edited.
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
3
|
+
// absent, current, prior (a body SCRIPT_PRIORS catalogs for its name) or edited. On every plain run a
|
|
4
|
+
// prior is refreshed, an edited one replaced in place and an absent one placed create-only, with no
|
|
5
|
+
// question and no copy kept; a current one is left. The installer set is written first; on an older
|
|
6
|
+
// ADR layout the decisions group is held back, the migration named. It never imports ensure-specs.mjs
|
|
7
|
+
// or ensure-configs.mjs: the CLI composes this op from the module's index, and ensure-specs.mjs takes
|
|
8
|
+
// its channel from there.
|
|
9
9
|
//
|
|
10
10
|
// Dependency-free, Node >= 22. Every fs primitive is injectable (deps.*). No side effects on import.
|
|
11
11
|
|
|
@@ -15,8 +15,7 @@ import { lstatNoFollow, writeContainedFileAtomic, writeProjectFileCreateOnly } f
|
|
|
15
15
|
import { composeFailure, composeOutcome, nodeEvidenceRefusal, probeSeedTarget, tmpNote } from '../ensure-ops.mjs';
|
|
16
16
|
import { surveyAdrLayoutStrict } from '../family-registry.mjs';
|
|
17
17
|
import { BUNDLED_SCRIPT_NAMES } from '../node-evidence.mjs';
|
|
18
|
-
import { CHECKER_PAIR, INSTALLER_SET, READER_PAIR, SCRIPT_PRIORS, classifyDeployedScript
|
|
19
|
-
import { keptAsidePath } from './kept-aside.mjs';
|
|
18
|
+
import { CHECKER_PAIR, INSTALLER_SET, READER_PAIR, SCRIPT_PRIORS, classifyDeployedScript } from '../script-priors.mjs';
|
|
20
19
|
|
|
21
20
|
const OP = 'scripts';
|
|
22
21
|
const SCRIPTS_DIR = 'scripts';
|
|
@@ -26,10 +25,13 @@ export const SCRIPT_CHANNEL = 'a script or suite of your own under its own name
|
|
|
26
25
|
export const LOCAL_HOOK_CHANNEL = 'the local hook file scripts/pre-commit.local, which the commit hook runs first';
|
|
27
26
|
// The family files whose bytes import or read archive-decisions.mjs, plus that file (the suite derives it).
|
|
28
27
|
export const DECISIONS_GROUP = Object.freeze(['archive-decisions.mjs', 'archive-decisions.test.mjs', 'archiver-structure.test.mjs']);
|
|
28
|
+
// The family files memory copies on Node evidence alone, accepted or not (the suite derives them).
|
|
29
|
+
export const SEED_NAMES = Object.freeze(['_expect-shim.mjs', 'archive-decisions.mjs', 'archive-decisions.test.mjs', 'markdown-blocks.mjs']);
|
|
29
30
|
const OLD_ADR_LAYOUTS = new Set(['old', 'old-unrotated']);
|
|
30
31
|
const PAIRS = new Set([...READER_PAIR, ...CHECKER_PAIR]);
|
|
31
32
|
// The family in write order: the installer set, then every other bundled name in code-unit order.
|
|
32
33
|
const FAMILY = Object.freeze([...INSTALLER_SET, ...BUNDLED_SCRIPT_NAMES.filter((name) => !PAIRS.has(name) && !INSTALLER_SET.includes(name)).sort()]);
|
|
34
|
+
const LOCAL_IMPORT = /(?:from|import)\s*\(?\s*'\.\/([^']+)'/g;
|
|
33
35
|
|
|
34
36
|
const causeOf = (err) => String((err && err.message) || err);
|
|
35
37
|
const relOf = (name) => `${SCRIPTS_DIR}/${name}`;
|
|
@@ -38,8 +40,16 @@ const wrongKind = (rel, kind) => composeFailure(OP, 'wrong-node-kind', `${rel}:
|
|
|
38
40
|
|
|
39
41
|
// ── the survey: the component first, then every family file by proof, nothing written ────────────
|
|
40
42
|
|
|
41
|
-
//
|
|
42
|
-
//
|
|
43
|
+
// The seed files a run of a component that is not accepted judges: each standing one, and every seed
|
|
44
|
+
// file reached from one through its bundled `./` imports, so every seed file the run leaves loads.
|
|
45
|
+
const seedClosure = (standing, bundleOf) => {
|
|
46
|
+
const reached = new Set(standing);
|
|
47
|
+
for (const name of reached) for (const [, dep] of bundleOf(name).toString('utf8').matchAll(LOCAL_IMPORT)) if (SEED_NAMES.includes(dep)) reached.add(dep);
|
|
48
|
+
return reached;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// → { refusal } | { notPlaced } | { files, accepted, layout, layoutError }. A family path of another node
|
|
52
|
+
// kind is judged before the component, so a linked family file never reads as not-placed.
|
|
43
53
|
const survey = ({ cwd, kitRoot, deps, read, lstat }) => {
|
|
44
54
|
const dir = lstatNoFollow(join(cwd, SCRIPTS_DIR), lstat);
|
|
45
55
|
if (dir === null) return { notPlaced: true };
|
|
@@ -48,60 +58,55 @@ const survey = ({ cwd, kitRoot, deps, read, lstat }) => {
|
|
|
48
58
|
const wrong = probes.find((f) => f.probe.wrongKind);
|
|
49
59
|
if (wrong) return { refusal: wrongKind(wrong.rel, wrong.probe.wrongKind) };
|
|
50
60
|
if (!probes.some((f) => f.probe.present)) return { notPlaced: true };
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
61
|
+
const accepted = probes.some((f) => f.probe.present && !SEED_NAMES.includes(f.name));
|
|
62
|
+
const bundles = new Map();
|
|
63
|
+
for (const { name, rel } of probes) {
|
|
54
64
|
try {
|
|
55
|
-
|
|
65
|
+
bundles.set(name, read(join(kitRoot, ...BUNDLED, name)));
|
|
56
66
|
} catch (err) {
|
|
57
67
|
return { refusal: composeFailure(OP, 'bundle-unreadable', `${rel}: the bundled script could not be read, so nothing was written — reinstall the kit. ${causeOf(err)}`) };
|
|
58
68
|
}
|
|
59
|
-
const bytes = probe.present ? read(join(cwd, rel)) : undefined;
|
|
60
|
-
files.push({ name, rel, bundle, bytes, state: probe.present ? classifyDeployedScript(bytes, name, bundle, deps.priors ?? SCRIPT_PRIORS) : 'absent' });
|
|
61
69
|
}
|
|
70
|
+
const judged = accepted ? new Set(FAMILY) : seedClosure(probes.filter((f) => f.probe.present).map((f) => f.name), (name) => bundles.get(name));
|
|
71
|
+
const files = probes.filter((f) => judged.has(f.name)).map(({ name, rel, probe }) => {
|
|
72
|
+
const bytes = probe.present ? read(join(cwd, rel)) : undefined;
|
|
73
|
+
return { name, rel, bundle: bundles.get(name), state: probe.present ? classifyDeployedScript(bytes, name, bundles.get(name), deps.priors ?? SCRIPT_PRIORS) : 'absent' };
|
|
74
|
+
});
|
|
62
75
|
try {
|
|
63
|
-
return { files, layout: surveyAdrLayoutStrict(cwd, deps) };
|
|
76
|
+
return { files, accepted, layout: surveyAdrLayoutStrict(cwd, deps) };
|
|
64
77
|
} catch (err) {
|
|
65
|
-
return { files, layoutError: causeOf(err) };
|
|
78
|
+
return { files, accepted, layoutError: causeOf(err) };
|
|
66
79
|
}
|
|
67
80
|
};
|
|
68
81
|
|
|
69
|
-
const entryOf = (f) => ({
|
|
70
|
-
rel: f.rel,
|
|
71
|
-
...(f.state === 'absent' ? { absent: true } : { sha256: digestOf(f.bytes), bytes: f.bytes }),
|
|
72
|
-
channel: f.name === INSTALLER_SET[0] ? LOCAL_HOOK_CHANNEL : SCRIPT_CHANNEL,
|
|
73
|
-
hookRun: true,
|
|
74
|
-
});
|
|
75
|
-
|
|
76
82
|
// ── the lines (composed from what HAPPENED: each file's state and the fate of its write) ─────────
|
|
77
83
|
|
|
78
|
-
// A fate is `written`, `stood` (
|
|
79
|
-
//
|
|
80
|
-
const
|
|
81
|
-
const
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if (f.state === 'absent') return `${f.rel}: ${{ written: "placed from the bundled scripts on the user's yes", stood: 'appeared while this run was placing it — the bundled body stands, nothing written' }[fate] ?? 'absent — not placed'}`;
|
|
88
|
-
const kept = keptOf(f.rel);
|
|
89
|
-
return `${f.rel}: ${fate === 'written' ? `carried an edit — kept aside at ${kept}, then replaced by the bundled body on the user's yes` : `carries an edit — not replaced${kept ? `; its copy kept aside at ${kept} stays` : ''}`}`;
|
|
84
|
+
// A fate is `written`, `stood` (an absent file that appeared with the bundled body), `refused` (its
|
|
85
|
+
// write failed), or none: the run stopped before it, or, dry, would write it.
|
|
86
|
+
const VERBS = { prior: ['refreshed', 'refreshed to the bundled one'], custom: ['replaced', 'replaced by the bundled body'], absent: ['placed', 'placed from the bundled scripts'] };
|
|
87
|
+
const HEADS = { prior: 'matches a body an earlier release shipped', custom: 'differs from every body this kit knows it shipped', absent: 'absent' };
|
|
88
|
+
const fileLine = (f, fate, dryRun) => {
|
|
89
|
+
if (fate === 'stood') return `${f.rel}: appeared while this run was placing it — the bundled body stands, nothing written`;
|
|
90
|
+
const [verb, done] = VERBS[f.state];
|
|
91
|
+
const tail = fate === 'written' ? done : dryRun ? `would be ${done}` : `not ${verb}; ${fate === 'refused' ? 'its write was refused (above)' : 'the run stopped before it'}`;
|
|
92
|
+
return `${f.rel}: ${HEADS[f.state]} — ${tail}${f.state === 'custom' ? `; an edit meant to last goes in ${f.name === INSTALLER_SET[0] ? LOCAL_HOOK_CHANNEL : SCRIPT_CHANNEL}` : ''}`;
|
|
90
93
|
};
|
|
91
94
|
const heldLine = (layout) => `${SCRIPTS_DIR}/: ${DECISIONS_GROUP.slice(0, -1).join(', ')} and ${DECISIONS_GROUP.at(-1)} are held back while this project is on the older ADR layout (${layout}) — run the opt-in /agent-workflow-kit migrate-adr-store (it previews, and never commits); the next upgrade judges them`;
|
|
95
|
+
const NOT_ACCEPTED = `${SCRIPTS_DIR}/: the enforcement scripts were not accepted in this project, so no other kit script is placed`;
|
|
96
|
+
// The hook-run line, once after the file lines of a run that wrote (or, dry, would write) a file.
|
|
97
|
+
const hookLine = (accepted, dryRun) => (accepted
|
|
98
|
+
? (dryRun ? 'the commit hook runs the files named above, so writing them may stop the next commit' : 'the commit hook runs the files written above, so they may stop the next commit')
|
|
99
|
+
: (dryRun ? 'if a commit hook runs the files named above, writing them may stop the next commit' : 'if a commit hook runs the files written above, they may stop the next commit'));
|
|
92
100
|
const partialNote = (count) => (count > 0 ? [`the writes stopped PARTWAY — the ${count} file(s) named above were already written and are NOT rolled back`] : []);
|
|
93
101
|
|
|
94
102
|
// ── the writes ────────────────────────────────────────────────────────────────────────────────────
|
|
95
103
|
|
|
96
|
-
// One write per file in write order: a prior refreshed
|
|
97
|
-
//
|
|
98
|
-
const writeAll = ({ cwd, files, deps, read
|
|
104
|
+
// One write per file in write order: a prior refreshed and an edit replaced by the atomic write, an
|
|
105
|
+
// absent file written create-only. → { fates, notes, failure? }
|
|
106
|
+
const writeAll = ({ cwd, files, deps, read }) => {
|
|
99
107
|
const fates = new Map();
|
|
100
108
|
const notes = [];
|
|
101
109
|
for (const f of files) {
|
|
102
|
-
if (f.state === 'custom' && digestOf(read(join(cwd, f.rel))) !== bound.get(f.rel)) {
|
|
103
|
-
return { fates, notes, failure: ['race-unresolved', `${f.rel}: changed after this run read it — left as it stands and nothing further written`] };
|
|
104
|
-
}
|
|
105
110
|
let result;
|
|
106
111
|
try {
|
|
107
112
|
result = f.state === 'absent'
|
|
@@ -114,6 +119,7 @@ const writeAll = ({ cwd, files, deps, read, bound }) => {
|
|
|
114
119
|
notes.push(...tmpNote(f.rel, result.tmpLeftBehind));
|
|
115
120
|
if (f.state === 'absent' && !result.created) {
|
|
116
121
|
if (classifyDeployedScript(read(join(cwd, f.rel)), f.name, f.bundle) !== 'current') {
|
|
122
|
+
fates.set(f.rel, 'refused');
|
|
117
123
|
return { fates, notes, failure: ['race-unresolved', `${f.rel}: appeared while this run was placing it and does not carry the bundled body — nothing further written, re-run when the tree is settled`] };
|
|
118
124
|
}
|
|
119
125
|
fates.set(f.rel, 'stood');
|
|
@@ -122,25 +128,19 @@ const writeAll = ({ cwd, files, deps, read, bound }) => {
|
|
|
122
128
|
return { fates, notes };
|
|
123
129
|
};
|
|
124
130
|
|
|
125
|
-
//
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
const priors = set.filter((f) => f.state === 'prior');
|
|
134
|
-
const { fates, notes, failure } = dryRun ? { fates: new Map(), notes: [] } : writeAll({ cwd, files: priors, deps, read });
|
|
135
|
-
const lines = set.map((f) => (f.state === 'prior' ? fileLine(f, fates.get(f.rel), { dryRun }) : `${f.rel}: ${WAITS}`));
|
|
136
|
-
const written = [...fates.values()].filter((fate) => fate === 'written').length;
|
|
137
|
-
if (failure) return composeFailure(OP, failure[0], failure[1], ...lines, ...notes, ...partialNote(written));
|
|
138
|
-
return composeFailure(OP, 'adr-layout-unverifiable', `${SCRIPTS_DIR}/: the ADR-store layout could not be read (${layoutError}), so the other kit scripts wait for the layout`, ...lines, ...notes);
|
|
131
|
+
// One run over the files it is handed: every one that is not current written in order, its lines,
|
|
132
|
+
// then the hook-run line once when a file was (or, dry, would be) written.
|
|
133
|
+
const writeRun = ({ cwd, files, accepted, dryRun, deps, read }) => {
|
|
134
|
+
const due = files.filter((f) => f.state !== 'current');
|
|
135
|
+
const { fates, notes, failure } = dryRun ? { fates: new Map(), notes: [] } : writeAll({ cwd, files: due, deps, read });
|
|
136
|
+
const written = due.filter((f) => fates.get(f.rel) === 'written');
|
|
137
|
+
const hook = (dryRun ? due.length > 0 : written.length > 0) ? [hookLine(accepted, dryRun)] : [];
|
|
138
|
+
return { due, fates, failure, written, lines: due.map((f) => fileLine(f, fates.get(f.rel), dryRun)), tail: [...hook, ...notes, ...(failure ? partialNote(written.length) : [])] };
|
|
139
139
|
};
|
|
140
140
|
|
|
141
141
|
// ── the op ────────────────────────────────────────────────────────────────────────────────────────
|
|
142
142
|
|
|
143
|
-
export const ensureScripts = ({ cwd, kitRoot, dryRun = false, deps = {}
|
|
143
|
+
export const ensureScripts = ({ cwd, kitRoot, dryRun = false, deps = {} }) => {
|
|
144
144
|
const lstat = deps.lstat ?? lstatSync;
|
|
145
145
|
const read = deps.readFile ?? readFileSync;
|
|
146
146
|
const refusal = nodeEvidenceRefusal(OP, cwd, lstat);
|
|
@@ -148,38 +148,27 @@ export const ensureScripts = ({ cwd, kitRoot, dryRun = false, deps = {}, replace
|
|
|
148
148
|
const found = survey({ cwd, kitRoot, deps, read, lstat });
|
|
149
149
|
if (found.refusal) return found.refusal;
|
|
150
150
|
if (found.notPlaced) return composeOutcome(OP, 'not-placed', [`${SCRIPTS_DIR}/: no kit script stands in it, so none is placed`], false);
|
|
151
|
-
|
|
151
|
+
const { files, accepted } = found;
|
|
152
|
+
const declined = accepted ? [] : [NOT_ACCEPTED];
|
|
153
|
+
|
|
154
|
+
// An unreadable layout: on an accepted component the installer set alone is kept current.
|
|
155
|
+
if (found.layoutError !== undefined) {
|
|
156
|
+
const layoutLine = `${SCRIPTS_DIR}/: the ADR-store layout could not be read (${found.layoutError}), so the other kit scripts wait for the layout`;
|
|
157
|
+
const set = accepted ? files.filter((f) => INSTALLER_SET.includes(f.name)) : [];
|
|
158
|
+
const r = writeRun({ cwd, files: set, accepted, dryRun, deps, read });
|
|
159
|
+
if (r.failure) return composeFailure(OP, r.failure[0], r.failure[1], ...r.lines, layoutLine, ...r.tail);
|
|
160
|
+
return composeFailure(OP, 'adr-layout-unverifiable', layoutLine, ...r.lines, ...r.tail);
|
|
161
|
+
}
|
|
152
162
|
|
|
153
|
-
// The survey completed: its entries ride every outcome from here on, a failed one included.
|
|
154
163
|
const held = OLD_ADR_LAYOUTS.has(found.layout);
|
|
155
|
-
const live =
|
|
156
|
-
const
|
|
157
|
-
const
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
const loud = (cause, ...lines) => ({ ...composeFailure(OP, cause, ...lines), entries });
|
|
166
|
-
if (bound && !sameEntries(entries, replace.entries)) {
|
|
167
|
-
return loud('race-unresolved', 'the kit scripts to place or replace are not the set the yes was given for (another set or other bytes), so nothing was written', ...linesOf(new Map()));
|
|
168
|
-
}
|
|
169
|
-
const due = live.filter((f) => f.state === 'prior' || (bound && (f.state === 'custom' || f.state === 'absent')));
|
|
170
|
-
const tokenOf = (fates) => {
|
|
171
|
-
const landed = (state) => due.some((f) => f.state === state && fates.get(f.rel) === 'written');
|
|
172
|
-
if (held) return 'old-adr-layout-migration-instructed';
|
|
173
|
-
if (!bound && entries.length > 0) return 'pending';
|
|
174
|
-
if (landed('absent')) return 'seeded';
|
|
175
|
-
if (dryRun ? due.length > 0 : landed('prior') || landed('custom')) return dryRun ? 'would-refresh' : 'refreshed';
|
|
176
|
-
return 'already-present';
|
|
177
|
-
};
|
|
178
|
-
if (dryRun) return ok(tokenOf(new Map()), linesOf(new Map()));
|
|
179
|
-
const { fates, notes, failure } = writeAll({ cwd, files: due, deps, read, bound });
|
|
180
|
-
if (failure) {
|
|
181
|
-
const written = [...fates.values()].filter((fate) => fate === 'written').length;
|
|
182
|
-
return loud(failure[0], failure[1], ...linesOf(fates), ...notes, ...partialNote(written));
|
|
183
|
-
}
|
|
184
|
-
return ok(tokenOf(fates), [...linesOf(fates), ...notes]);
|
|
164
|
+
const live = files.filter((f) => !(held && DECISIONS_GROUP.includes(f.name)));
|
|
165
|
+
const current = live.filter((f) => f.state === 'current').length;
|
|
166
|
+
const r = writeRun({ cwd, files: live, accepted, dryRun, deps, read });
|
|
167
|
+
const body = [...r.lines, ...(current > 0 ? [`${SCRIPTS_DIR}/: ${current} other kit scripts are already the bundled body — nothing written`] : []), ...(held ? [heldLine(found.layout)] : []), ...declined];
|
|
168
|
+
if (r.failure) return composeFailure(OP, r.failure[0], r.failure[1], ...body, ...r.tail);
|
|
169
|
+
const landed = (state) => (dryRun ? r.due : r.written).some((f) => f.state === state);
|
|
170
|
+
const token = held ? 'old-adr-layout-migration-instructed'
|
|
171
|
+
: landed('absent') ? (dryRun ? 'would-seed' : 'seeded')
|
|
172
|
+
: landed('prior') || landed('custom') ? (dryRun ? 'would-refresh' : 'refreshed') : 'already-present';
|
|
173
|
+
return composeOutcome(OP, token, [...body, ...r.tail], false);
|
|
185
174
|
};
|
package/tools/ensure-configs.mjs
CHANGED
|
@@ -6,8 +6,9 @@
|
|
|
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/<every kit script>
|
|
10
|
-
// + the installer set
|
|
9
|
+
// scripts scripts/<every kit script> once a kit script outside the seed names stands there, every file not current
|
|
10
|
+
// + the installer set written with no question and no copy kept; installer set first; on a
|
|
11
|
+
// declined offer only the standing seed files and the modules they import
|
|
11
12
|
// specs scripts/<spec layer> reader + checker pairs seeded when absent, refreshed only on
|
|
12
13
|
// + docs/ai/specs/index.md a shipped prior body, an edited one replaced only on the
|
|
13
14
|
// user's yes; store root seeded behind a current checker
|
|
@@ -28,10 +29,10 @@
|
|
|
28
29
|
// • The ops run in a FIXED order and one op's failure NEVER skips the rest: every op reports its own
|
|
29
30
|
// token, and the exit is non-zero when any of them failed. The one exception is the replace run
|
|
30
31
|
// (--replace-custom <digest>), which distribution-files/ runs: each edit kept aside, then the
|
|
31
|
-
// owning
|
|
32
|
+
// owning op (specs), then index only when none failed.
|
|
32
33
|
// • ONE replace block, after every op's lines and before the failure footer, over the union the
|
|
33
|
-
// replace run recomputes: the files whose write waits for the user's yes, and the one
|
|
34
|
-
//
|
|
34
|
+
// replace run recomputes: the spec-layer files whose write waits for the user's yes, and the one
|
|
35
|
+
// command for it.
|
|
35
36
|
// • The deployment gate runs ONCE, before any op: an absent/symlinked docs/ai stops the whole run
|
|
36
37
|
// with the gate's own message rather than one copy of it per op.
|
|
37
38
|
//
|
|
@@ -57,7 +58,7 @@ const KIT_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
|
57
58
|
// consumer) because the executor, scripts, spec-layer and rules ensures import ensure-ops.mjs for their outcome door and probes.
|
|
58
59
|
export const ENSURE_IMPLEMENTATIONS = Object.freeze({ ...OWN_IMPLEMENTATIONS, executor: ensureExecutor, scripts: ensureScripts, specs: ensureSpecs, rules: ensureRules });
|
|
59
60
|
// The ops whose writes wait for the user's yes and so own the replace run, in ENSURE_OPS order.
|
|
60
|
-
const OWNING_OPS = ['
|
|
61
|
+
const OWNING_OPS = ['specs'];
|
|
61
62
|
|
|
62
63
|
const EXIT_OK = 0;
|
|
63
64
|
const EXIT_FAILED = 1;
|
|
@@ -71,7 +72,7 @@ const REPEATED_ONLY = '--only was passed more than once — this selector names
|
|
|
71
72
|
const unknownOp = (value) => `--only ${value}: no such operation (${ENSURE_OPS.join(' | ')}) — nothing was run`;
|
|
72
73
|
const EMPTY_REPLACE = '--replace-custom needs the digest its replace line printed — an empty value names no file to replace';
|
|
73
74
|
const REPEATED_REPLACE = '--replace-custom was passed more than once — a replace run carries exactly ONE digest';
|
|
74
|
-
const REPLACE_WITH_ONLY = '--replace-custom runs the
|
|
75
|
+
const REPLACE_WITH_ONLY = '--replace-custom runs the spec layer, then the navigator, so it cannot be combined with --only — nothing was run';
|
|
75
76
|
const REPLACE_WITH_DRY_RUN = "--replace-custom writes on the user's yes, so it cannot be combined with --dry-run — nothing was run";
|
|
76
77
|
|
|
77
78
|
const HELP = `ensure-configs — the nine stamp-independent upgrade ensures, as ONE command.
|
|
@@ -82,13 +83,12 @@ Usage:
|
|
|
82
83
|
|
|
83
84
|
--reconcile required — run the nine ensures (${ENSURE_OPS.join(', ')})
|
|
84
85
|
--dry-run report what each ensure WOULD do; write nothing
|
|
85
|
-
--only <op> run EXACTLY ONE of them (an unknown, missing or repeated value is a usage error)
|
|
86
|
-
scripts or specs, a write-free survey of the other owning op feeds the replace block
|
|
86
|
+
--only <op> run EXACTLY ONE of them (an unknown, missing or repeated value is a usage error)
|
|
87
87
|
--replace-custom <digest>
|
|
88
88
|
the replace run the replace block prints, run only on the user's yes: every edit its
|
|
89
|
-
digest names is kept aside under .agent-workflow/kept-aside/, then the
|
|
90
|
-
|
|
91
|
-
--
|
|
89
|
+
digest names is kept aside under .agent-workflow/kept-aside/, then the spec layer
|
|
90
|
+
replaces and places its files, then index runs when nothing failed (not with --only or
|
|
91
|
+
--dry-run; an empty value is a usage error)
|
|
92
92
|
--cwd <dir> the target project (default: the current directory)
|
|
93
93
|
--help, -h this help
|
|
94
94
|
|
|
@@ -105,10 +105,13 @@ the project's own checker judges the navigator and a write it rejects is put bac
|
|
|
105
105
|
The executor ensure writes nothing: a placed .claude/agents/executor.md whose bytes differ from the
|
|
106
106
|
body derived from docs/ai/vehicles.json is pending — the advisor's executor-vehicle.differing item
|
|
107
107
|
changes it on your yes; an absent file is never placed here.
|
|
108
|
-
A fifth
|
|
109
|
-
kit script, the hook installer and its two suites
|
|
110
|
-
|
|
111
|
-
|
|
108
|
+
A fifth writes too: once a kit script outside the seed names stands in scripts/, the enforcement-script
|
|
109
|
+
ensure writes every kit script that is not the bundled body, the hook installer and its two suites
|
|
110
|
+
first, with no question and no copy kept: a body a release shipped is refreshed, an edited one replaced
|
|
111
|
+
(its line names where an edit meant to last goes) and an absent one placed; on a project that
|
|
112
|
+
declined the enforcement offer, its standing seed files are kept current the same way, with an
|
|
113
|
+
absent module they import placed, and no other kit script is placed; on an older ADR-store layout
|
|
114
|
+
the decisions files are held back and the opt-in migration is named.
|
|
112
115
|
|
|
113
116
|
Exit codes: 0 every op fine; 1 an op failed (its line says so) or there is no deployment here; 2 usage.`;
|
|
114
117
|
|
|
@@ -171,19 +174,16 @@ const runOne = (op, args) => {
|
|
|
171
174
|
// Run every op in ENSURE_OPS order. A throw from one op becomes THAT op's failed outcome — the
|
|
172
175
|
// remaining ops still run, because a project missing its gate declaration should not also be left
|
|
173
176
|
// without its autonomy seed just because the first ensure hit an unreadable file. → { outcomes, block }:
|
|
174
|
-
// the block is the union the replace run recomputes
|
|
175
|
-
//
|
|
176
|
-
//
|
|
177
|
-
// index only when none failed, and its block is non-empty only when the digest no longer matches.
|
|
177
|
+
// the block is the union the replace run recomputes, the entries of the owning op. The replace run is
|
|
178
|
+
// the one exception, handed to runReplace: it keeps every edit aside, runs the owning op, then index
|
|
179
|
+
// only when it did not fail, and its block is non-empty only when the digest no longer matches.
|
|
178
180
|
export const runEnsures = ({ cwd, kitRoot, dryRun, deps, only, replaceCustom }) => {
|
|
179
181
|
if (replaceCustom !== undefined) {
|
|
180
182
|
const owning = OWNING_OPS.map((op) => ({ op, run: (args) => runOne(op, args) }));
|
|
181
183
|
return runReplace({ cwd, kitRoot, digest: replaceCustom, owning, index: (args) => runOne('index', args), deps });
|
|
182
184
|
}
|
|
183
185
|
const outcomes = (only ? [only] : ENSURE_OPS).map((op) => runOne(op, { cwd, kitRoot, dryRun, deps }));
|
|
184
|
-
|
|
185
|
-
const shown = [...outcomes, ...surveys.filter((o) => o.failed)].sort((a, b) => ENSURE_OPS.indexOf(a.op) - ENSURE_OPS.indexOf(b.op));
|
|
186
|
-
return { outcomes: shown, block: [...outcomes, ...surveys].flatMap((o) => o.entries ?? []) };
|
|
186
|
+
return { outcomes, block: outcomes.flatMap((o) => o.entries ?? []) };
|
|
187
187
|
};
|
|
188
188
|
|
|
189
189
|
const render = ({ outcomes, block }, { dryRun, only, replace, kitRoot, cwd }) => {
|
package/tools/ensure-ops.mjs
CHANGED
|
@@ -18,8 +18,8 @@
|
|
|
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 (the refusal the kit-script and spec-layer ensures
|
|
21
|
-
// share, below; the kit scripts' rule —
|
|
22
|
-
//
|
|
21
|
+
// share, below; the kit scripts' rule — every kit script written with no question and no copy
|
|
22
|
+
// kept — lives in distribution-files/scripts.mjs).
|
|
23
23
|
// • A failed op is a non-zero signal, never a line that reads like success.
|
|
24
24
|
//
|
|
25
25
|
// Dependency-free, Node >= 22. Every fs primitive is injectable (deps.*). No side effects on import.
|
|
@@ -9,19 +9,19 @@
|
|
|
9
9
|
|
|
10
10
|
// The FIXED order the CLI runs them in — the order references/modes/upgrade.md already prescribed.
|
|
11
11
|
// `specs` sits after `scripts` (its reader pair is a scripts/ seed too) and BEFORE `index`: the store
|
|
12
|
-
// root it seeds is a docs/ai file the navigator must count. `
|
|
13
|
-
//
|
|
14
|
-
//
|
|
12
|
+
// root it seeds is a docs/ai file the navigator must count. `specs` alone owns the replace run: its
|
|
13
|
+
// edited files are written only on the user's yes, while `scripts` writes every kit script with no
|
|
14
|
+
// question.
|
|
15
15
|
// `executor` follows `vehicles`: its body is derived from the settings file that op seeds.
|
|
16
16
|
// `rules` follows `specs` and precedes `index`: the rules files it lays are docs/ai files the navigator counts.
|
|
17
17
|
export const ENSURE_OPS = Object.freeze(['orchestration', 'gates', 'autonomy', 'vehicles', 'executor', 'scripts', 'specs', 'rules', 'index']);
|
|
18
18
|
|
|
19
19
|
// Tokens that assert a WRITE happened. --dry-run may never emit one of these (the CLI's contract test
|
|
20
20
|
// walks this set), and each has exactly one `would-` counterpart below. `refreshed` is the spec-layer
|
|
21
|
-
// ensure's pair refresh (reader or checker) or the scripts ensure's
|
|
22
|
-
// script on a body a release shipped, rewritten to the bundled one
|
|
23
|
-
// absent kit script placed
|
|
24
|
-
//
|
|
21
|
+
// ensure's pair refresh (reader or checker) or the scripts ensure's write of a kit script — a deployed
|
|
22
|
+
// script on a body a release shipped, or an edited one, rewritten to the bundled one on a plain run, an
|
|
23
|
+
// absent kit script placed (`seeded`); an edited spec-layer file is replaced only by the replace run the
|
|
24
|
+
// user's yes starts (--replace-custom, over the spec layer).
|
|
25
25
|
export const WRITE_TOKENS = Object.freeze(['seeded', 'note-refreshed', 'refreshed', 'regenerated']);
|
|
26
26
|
export const DRY_RUN_TOKENS = Object.freeze(['would-seed', 'would-refresh-note', 'would-refresh', 'would-regenerate']);
|
|
27
27
|
|
package/tools/git-hooks.mjs
CHANGED
|
@@ -34,7 +34,7 @@ const sha = (bytes) => createHash('sha256').update(bytes).digest('hex');
|
|
|
34
34
|
const usageError = (message) => Object.assign(new Error(message), { exitCode: EXIT_USAGE });
|
|
35
35
|
const refusal = (message) => Object.assign(new Error(message), { exitCode: EXIT_REFUSED });
|
|
36
36
|
// The one route the two re-read lines end with: an installer that left a passed line out is not the kit's current body.
|
|
37
|
-
export const UPGRADE_ROUTE = "/agent-workflow-kit upgrade
|
|
37
|
+
export const UPGRADE_ROUTE = "/agent-workflow-kit upgrade writes the kit's current installer over any other installer body, with no question; if it stops on another cause, resolve the cause it names and run it again; then apply this item again";
|
|
38
38
|
|
|
39
39
|
const nodeAt = (path, lstat) => {
|
|
40
40
|
try {
|
package/tools/script-priors.mjs
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
// into a project's `scripts/`, as sha256 digests, and the ONE classifier a refresh asks before it
|
|
3
3
|
// replaces a deployed script — the spec-layer ensure for its pairs and the upgrade's `scripts` ensure
|
|
4
4
|
// for every other kit script: `current` (byte-equal to the bundled copy) · `prior` (a body a release
|
|
5
|
-
// shipped, never edited since) · `custom` (anything else —
|
|
6
|
-
//
|
|
5
|
+
// shipped, never edited since) · `custom` (anything else — replaced on the plain run by the scripts op,
|
|
6
|
+
// and by the user's yes for the spec-layer pairs alone). The lens-region idiom (AD-041) over whole
|
|
7
|
+
// script bodies.
|
|
7
8
|
//
|
|
8
9
|
// Append discipline: when a release changes one of PRIOR_FILES, append the OUTGOING body's row here
|
|
9
10
|
// in the same release and copy its bytes to test/fixtures/script-priors/<firstShipped>/<file>.txt —
|
|
@@ -58,6 +59,7 @@ export const SCRIPT_PRIORS = Object.freeze([
|
|
|
58
59
|
prior('install-git-hooks.mjs', '8.3.0', '8.3.0', 'aa21b3dcbfc48ea1db7a33ed5a5c8cf30d911b266386b67159288cd12d28bc38'),
|
|
59
60
|
prior('install-git-hooks.test.mjs', '8.3.0', '8.3.0', '058ac6de4dd5f83c4f09c8afd72ef2bfda365a9aea55bddd0089ce89a4e941e2'),
|
|
60
61
|
prior('install-git-hooks-repo-exec.test.mjs', '8.3.0', '8.3.0', 'd5a3253fa0cd088733b927f2a7187c6484298f11dec48f6f63953e380b071c9a'),
|
|
62
|
+
prior('archive-decisions.mjs', '8.1.3', '8.4.0', '2e1c378fe8a395440dc17a712643a549487e87f958f9d6ec5922dced876421ad'),
|
|
61
63
|
]);
|
|
62
64
|
|
|
63
65
|
export const digestOf = (bytes) => createHash('sha256').update(bytes).digest('hex');
|
|
@@ -34,7 +34,7 @@ export const UPGRADE_RUNLIST = Object.freeze([
|
|
|
34
34
|
entry(
|
|
35
35
|
'configs',
|
|
36
36
|
'node ${CLAUDE_SKILL_DIR}/tools/ensure-configs.mjs --reconcile --cwd <project>',
|
|
37
|
-
"a replace line → ONE yes naming every file its block names, each edit's kept-aside copy and that the bundled body replaces it, asked even on a non-zero exit; on the yes run the printed line, then STOP if that run fails or an op it does not re-run failed; on a no STOP on any failed op. The printed line: node ${CLAUDE_SKILL_DIR}/tools/ensure-configs.mjs --reconcile --replace-custom <digest> --cwd <project>",
|
|
37
|
+
"a replace line → ONE yes naming every spec-layer file its block names, each edit's kept-aside copy and that the bundled body replaces it, asked even on a non-zero exit; on the yes run the printed line, then STOP if that run fails or an op it does not re-run failed; on a no STOP on any failed op. The printed line: node ${CLAUDE_SKILL_DIR}/tools/ensure-configs.mjs --reconcile --replace-custom <digest> --cwd <project>",
|
|
38
38
|
[
|
|
39
39
|
'seeded',
|
|
40
40
|
'note-refreshed',
|