@sabaiway/agent-workflow-kit 20.1.0 → 21.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 +62 -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/package.json +5 -2
- package/references/contracts.md +9 -9
- package/references/modes/bootstrap.md +3 -3
- package/references/modes/commit-guard.md +1 -1
- package/references/modes/gates.md +1 -1
- package/references/modes/recommendations.md +2 -2
- package/references/modes/upgrade.md +4 -4
- 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 +43 -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} +30 -13
- package/references/scripts/{install-git-hooks.mjs → git-hooks/install-git-hooks.mjs} +50 -38
- package/references/scripts/run.mjs +74 -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/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/checker-gates-read.mjs +4 -1
- package/tools/direct-run.mjs +2 -0
- package/tools/distribution-files/retired.mjs +99 -0
- package/tools/distribution-files/scripts.mjs +67 -52
- package/tools/ensure-configs.mjs +21 -21
- package/tools/ensure-ops.mjs +60 -18
- package/tools/ensure-specs.mjs +82 -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 +8 -4
- 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 +22 -19
- 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 +1 -1
- 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
package/tools/git-hooks.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// git-hooks.mjs — the thin writer of the three git-hook items (`enforcement`, `commit-guard`,
|
|
3
|
-
// `hook-checks`): it copies the
|
|
4
|
-
//
|
|
3
|
+
// `hook-checks`): it copies the deployed scripts create-only into the kit folder and spawns the project's
|
|
4
|
+
// own installer (INSTALLER_REL) as it stands, which decides the hook at the write. The leaf
|
|
5
5
|
// decides nothing about the hook: the danger check binds the copies and the installer bytes this dry run
|
|
6
6
|
// answers, never git's hooks dir. It is also the home of the one pre-commit reader, which the
|
|
7
7
|
// commit-guard and hook-checks applies run after the installer to verify the arm.
|
|
@@ -11,18 +11,17 @@ import { spawnSync } from 'node:child_process';
|
|
|
11
11
|
import { dirname, join, resolve } from 'node:path';
|
|
12
12
|
import { fileURLToPath } from 'node:url';
|
|
13
13
|
import { writeProjectFileCreateOnly } from './atomic-write.mjs';
|
|
14
|
-
import {
|
|
14
|
+
import { DEPLOYED_SCRIPTS, INSTALLER_REL, NODE_EVIDENCE_SCRIPTS, SCRIPTS_DIR } from './node-evidence.mjs';
|
|
15
15
|
import { shellQuoteArg } from './repo-lex.mjs';
|
|
16
16
|
import { GIT_MAX_BUFFER } from './git-env.mjs';
|
|
17
|
+
import { KIT_COMMAND_PATH, KIT_COMMANDS } from '../references/scripts/run.mjs';
|
|
17
18
|
import { isDirectRun } from './direct-run.mjs';
|
|
18
19
|
import { checkRules } from './project-rules/index.mjs';
|
|
19
20
|
import { readLayoutSetup } from './source-size-core.mjs';
|
|
20
21
|
|
|
21
22
|
const TOOLS = dirname(fileURLToPath(import.meta.url));
|
|
22
23
|
export const SCRIPTS_REL = SCRIPTS_DIR;
|
|
23
|
-
export {
|
|
24
|
-
const bundleDir = (toolsDir) => join(toolsDir, '..', 'references', 'scripts');
|
|
25
|
-
const INSTALLER_NAME = 'install-git-hooks.mjs';
|
|
24
|
+
export { DEPLOYED_SCRIPTS, INSTALLER_REL };
|
|
26
25
|
|
|
27
26
|
const EXIT_OK = 0;
|
|
28
27
|
const EXIT_INCOMPLETE = 1;
|
|
@@ -44,8 +43,18 @@ const nodeAt = (path, lstat) => {
|
|
|
44
43
|
throw error;
|
|
45
44
|
}
|
|
46
45
|
};
|
|
46
|
+
// The rollback's read: a path it cannot lstat is never one it removes.
|
|
47
|
+
const nodeOrNull = (path, lstat) => {
|
|
48
|
+
try {
|
|
49
|
+
return nodeAt(path, lstat);
|
|
50
|
+
} catch {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
47
54
|
const isPlainDir = (node) => node !== null && node.isDirectory() && !node.isSymbolicLink();
|
|
48
55
|
const isFile = (node) => node !== null && node.isFile() && !node.isSymbolicLink();
|
|
56
|
+
// Each folder between the root and rel, shallowest first: scripts/, the kit folder, a module folder.
|
|
57
|
+
const foldersOf = (rel) => rel.split('/').slice(0, -1).map((_, at, parts) => parts.slice(0, at + 1).join('/'));
|
|
49
58
|
|
|
50
59
|
// The absolute hooks dir git itself reports (a linked worktree's own, core.hooksPath), or null outside a git tree.
|
|
51
60
|
export const resolveGitHooksPath = (projectDir, env = process.env) => {
|
|
@@ -54,8 +63,9 @@ export const resolveGitHooksPath = (projectDir, env = process.env) => {
|
|
|
54
63
|
return resolve(projectDir, result.stdout.toString('utf8').replace(/\r?\n$/, ''));
|
|
55
64
|
};
|
|
56
65
|
|
|
57
|
-
export const INSTALLER_MARKER_RE = /:install-git-hooks\.mjs
|
|
66
|
+
export const INSTALLER_MARKER_RE = /:install-git-hooks\.mjs\r?$/m;
|
|
58
67
|
const escapeRe = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
68
|
+
const COMMAND_LINE_RE = new RegExp(`^node ${escapeRe(KIT_COMMAND_PATH)} docs-size\\r?$`, 'm');
|
|
59
69
|
// Armed means the exact line the installer writes on the kit's own guard path; a commented or lookalike line is not.
|
|
60
70
|
export const canonicalGuardLineRe = (toolsDir = TOOLS) => new RegExp(`^node "${escapeRe(join(toolsDir, 'commit-guard.mjs'))}" --check$`, 'm');
|
|
61
71
|
|
|
@@ -88,7 +98,7 @@ const roleStates = (hook, toolsDir, platform) => Object.fromEntries(ROLES.flatMa
|
|
|
88
98
|
|
|
89
99
|
// The one reader of git's pre-commit: whose hook it is, and which canonical lines arm it.
|
|
90
100
|
export const readPreCommitState = (root, deps = {}) => {
|
|
91
|
-
const unarmed = (fields) => ({ ...fields, armed: false, ...roleStates(null) });
|
|
101
|
+
const unarmed = (fields) => ({ ...fields, armed: false, command: false, ...roleStates(null) });
|
|
92
102
|
const hooksPath = (deps.gitHooksPath ?? resolveGitHooksPath)(root, deps.env);
|
|
93
103
|
if (hooksPath === null) return unarmed({ state: 'no-hooks-dir' });
|
|
94
104
|
const path = join(hooksPath, 'pre-commit');
|
|
@@ -101,9 +111,13 @@ export const readPreCommitState = (root, deps = {}) => {
|
|
|
101
111
|
return unarmed({ state: 'unreadable', code: error?.code ?? String(error?.message ?? error), path });
|
|
102
112
|
}
|
|
103
113
|
return { state: INSTALLER_MARKER_RE.test(hook) ? 'managed' : 'unmanaged', armed: canonicalGuardLineRe(deps.toolsDir).test(hook),
|
|
104
|
-
...roleStates(hook, deps.toolsDir ?? TOOLS, deps.platform) };
|
|
114
|
+
command: COMMAND_LINE_RE.test(hook), ...roleStates(hook, deps.toolsDir ?? TOOLS, deps.platform) };
|
|
105
115
|
};
|
|
106
116
|
|
|
117
|
+
export const missingHookCommandFile = (root, deps = {}) => [INSTALLER_REL, KIT_COMMAND_PATH,
|
|
118
|
+
...Object.values(KIT_COMMANDS).map((target) => join(dirname(KIT_COMMAND_PATH), target))]
|
|
119
|
+
.map((rel) => join(root, rel)).find((path) => !isFile(nodeAt(path, deps.lstat ?? lstatSync)));
|
|
120
|
+
|
|
107
121
|
// The two read-only answers the hook-checks dry run and the advisor's probe ask, on the tree on disk.
|
|
108
122
|
export const hookCheckAnswers = (root, deps = {}) => {
|
|
109
123
|
const verdicts = (deps.checkRules ?? checkRules)(root, deps);
|
|
@@ -124,94 +138,102 @@ export const unsafeToolsPath = (toolsDir, platform) => (ROLES.some(({ tool }) =>
|
|
|
124
138
|
? `the kit's tools path ${toolsDir} carries ", $, a backtick, a backslash, CR or LF — a hook line would not run the file it names` : null);
|
|
125
139
|
|
|
126
140
|
// hook-checks: the lines it arms, from the two answers and the hook; the installer runs as it stands.
|
|
127
|
-
const planHookChecks = ({ root, toolsDir, installer,
|
|
128
|
-
if (!
|
|
141
|
+
const planHookChecks = ({ root, toolsDir, installer, installerNode, lstat, readFile, deps }) => {
|
|
142
|
+
if (!isFile(installerNode)) throw refusal(`${installer} is absent — nothing here places the hook installer`);
|
|
129
143
|
const unsafe = unsafeToolsPath(toolsDir, deps.platform);
|
|
130
144
|
if (unsafe !== null) throw refusal(unsafe);
|
|
131
145
|
const hook = readPreCommitState(root, { toolsDir, platform: deps.platform, gitHooksPath: deps.gitHooksPath });
|
|
132
146
|
if (hook.state === 'unreadable') throw refusal(`${hook.path} is unreadable (${hook.code}) — the pre-commit hook cannot be judged`);
|
|
133
147
|
if (hook.state === 'no-hooks-dir') throw refusal('nothing to plan — git reports no hooks dir here (not a git checkout), so there is no hook to arm');
|
|
148
|
+
const switchCommand = hook.state === 'managed' && !hook.command;
|
|
149
|
+
const missing = switchCommand ? missingHookCommandFile(root, { lstat }) : undefined;
|
|
150
|
+
if (missing) throw refusal(`${missing} is not a regular file — re-run /agent-workflow-kit upgrade, then apply this item again`);
|
|
134
151
|
const answers = hookCheckAnswers(root, deps);
|
|
135
152
|
const roles = plannedRoles(answers, hook);
|
|
136
|
-
if (roles.length === 0) {
|
|
153
|
+
if (roles.length === 0 && !switchCommand) {
|
|
137
154
|
throw refusal(`nothing to plan — ${ROLES.map(({ key, role }) => `the ${role} line: ${hook[`${key}Armed`] ? 'armed' : `not armable (${answers[key].why})`}`).join('; ')}`);
|
|
138
155
|
}
|
|
139
156
|
const flags = roles.flatMap(({ flag, tool }) => [flag, tool(toolsDir)]);
|
|
140
|
-
return { root, variant: 'hook-checks',
|
|
157
|
+
return { root, variant: 'hook-checks', folders: [], copies: [], switchCommand, roles: roles.map(({ key }) => key),
|
|
141
158
|
runs: { argv: ['node', installer, ...flags], shown: ['node', INSTALLER_REL, ...flags], bytes: readFile(installer) } };
|
|
142
159
|
};
|
|
143
160
|
|
|
144
161
|
// The dry run: what the apply copies and the installer it runs, with the bytes of each.
|
|
145
162
|
export const planGitHooks = ({ root, variant, toolsDir = TOOLS, lstat = lstatSync, readFile = readFileSync, ...deps }) => {
|
|
146
|
-
const
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
const path = join(
|
|
153
|
-
const node = nodeAt(path, lstat);
|
|
154
|
-
if (node !== null && !
|
|
155
|
-
|
|
163
|
+
const enforcing = variant === 'enforcement';
|
|
164
|
+
const nodes = new Map();
|
|
165
|
+
const folders = [];
|
|
166
|
+
// Never beneath an absent folder: a folder on the way absent, every path under it is absent.
|
|
167
|
+
const probe = (rel, isKind, kind) => {
|
|
168
|
+
if (nodes.has(rel)) return nodes.get(rel);
|
|
169
|
+
const path = join(root, rel);
|
|
170
|
+
const node = foldersOf(rel).some((folder) => nodes.get(folder) === null) ? null : nodeAt(path, lstat);
|
|
171
|
+
if (node !== null && !isKind(node)) throw refusal(`${path} is not ${kind}`);
|
|
172
|
+
nodes.set(rel, node);
|
|
173
|
+
return node;
|
|
174
|
+
};
|
|
175
|
+
for (const rel of enforcing ? DEPLOYED_SCRIPTS.map(({ deployed }) => deployed) : [INSTALLER_REL]) {
|
|
176
|
+
for (const folder of foldersOf(rel)) if (!nodes.has(folder)) (folders.push(folder), probe(folder, isPlainDir, 'a plain directory'));
|
|
177
|
+
probe(rel, isFile, 'a regular file');
|
|
156
178
|
}
|
|
157
179
|
const installer = join(root, INSTALLER_REL);
|
|
158
|
-
if (variant === 'hook-checks') return planHookChecks({ root, toolsDir, installer,
|
|
159
|
-
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
const placed = copies.find(({
|
|
165
|
-
if (!placed && !isFile(
|
|
180
|
+
if (variant === 'hook-checks') return planHookChecks({ root, toolsDir, installer, installerNode: nodes.get(INSTALLER_REL), lstat, readFile, deps });
|
|
181
|
+
// A flat evidence name is no copy path: another node kind there is not evidence, never a refusal.
|
|
182
|
+
const evidence = (rel) => (nodes.has(rel) ? isFile(nodes.get(rel)) : nodes.get(SCRIPTS_REL) !== null && isFile(nodeAt(join(root, rel), lstat)));
|
|
183
|
+
const deployed = enforcing && NODE_EVIDENCE_SCRIPTS.some((name) => evidence(`${SCRIPTS_REL}/${name}`));
|
|
184
|
+
const copies = enforcing && !deployed ? DEPLOYED_SCRIPTS.map(({ deployed: rel, bundled }) =>
|
|
185
|
+
({ rel, path: join(root, rel), action: 'created', bytes: readFile(join(toolsDir, '..', bundled)) })) : [];
|
|
186
|
+
const placed = copies.find(({ rel }) => rel === INSTALLER_REL);
|
|
187
|
+
if (!placed && !isFile(nodes.get(INSTALLER_REL))) throw refusal(`${installer} is absent — nothing here places the hook installer`);
|
|
166
188
|
const guard = variant === 'commit-guard' ? ['--commit-guard', join(toolsDir, 'commit-guard.mjs')] : [];
|
|
167
189
|
return {
|
|
168
190
|
root,
|
|
169
191
|
variant,
|
|
170
|
-
|
|
192
|
+
folders: copies.length === 0 ? [] : folders.filter((folder) => nodes.get(folder) === null),
|
|
171
193
|
copies,
|
|
172
194
|
runs: { argv: ['node', installer, ...guard], shown: ['node', INSTALLER_REL, ...guard], bytes: placed ? placed.bytes : readFile(installer) },
|
|
173
195
|
};
|
|
174
196
|
};
|
|
175
197
|
|
|
176
198
|
export const formatPlan = (plan) => [
|
|
177
|
-
...plan.copies.map(({
|
|
199
|
+
...plan.copies.map(({ rel, action, bytes }) => `copy: ${rel} ${action}${action === 'created' ? ` sha256:${sha(bytes)}` : ''}`),
|
|
178
200
|
`runs: ${plan.runs.shown.map(shellQuoteArg).join(' ')} sha256:${sha(plan.runs.bytes)}`,
|
|
179
201
|
];
|
|
180
202
|
|
|
181
|
-
// Removes exactly the files this run created, then
|
|
182
|
-
//
|
|
203
|
+
// Removes exactly the files this run created, then each folder this run created, deepest first, when it is
|
|
204
|
+
// empty; a path is removed only while every folder above it is the plain directory this apply observed,
|
|
205
|
+
// and every path it cannot remove is answered for the caller to name.
|
|
183
206
|
const rollBack = (plan, created, io) => {
|
|
184
|
-
const scripts = join(plan.root, SCRIPTS_REL);
|
|
185
207
|
const left = [];
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
continue;
|
|
193
|
-
}
|
|
208
|
+
const observed = (folder) => {
|
|
209
|
+
const node = nodeOrNull(join(plan.root, folder), io.lstat);
|
|
210
|
+
return isPlainDir(node) && node.ino === created.inos.get(folder);
|
|
211
|
+
};
|
|
212
|
+
const intact = (rel) => foldersOf(rel).every(observed);
|
|
213
|
+
const remove = (path, act) => {
|
|
194
214
|
try {
|
|
195
|
-
|
|
215
|
+
act(path);
|
|
196
216
|
} catch {
|
|
197
217
|
left.push(path);
|
|
198
218
|
}
|
|
219
|
+
};
|
|
220
|
+
for (const { rel, path } of created.files) {
|
|
221
|
+
if (intact(rel) && isFile(nodeOrNull(path, io.lstat))) remove(path, io.unlink);
|
|
222
|
+
else left.push(path);
|
|
199
223
|
}
|
|
200
|
-
|
|
201
|
-
const
|
|
224
|
+
for (const folder of created.folders.filter((rel) => created.inos.has(rel)).reverse()) {
|
|
225
|
+
const path = join(plan.root, folder);
|
|
226
|
+
if (!intact(folder) || !observed(folder)) {
|
|
227
|
+
left.push(path);
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
202
230
|
let empty = false;
|
|
203
231
|
try {
|
|
204
|
-
empty =
|
|
232
|
+
empty = io.readdir(path).length === 0;
|
|
205
233
|
} catch {
|
|
206
234
|
empty = false;
|
|
207
235
|
}
|
|
208
|
-
if (empty)
|
|
209
|
-
try {
|
|
210
|
-
io.rmdir(scripts);
|
|
211
|
-
} catch {
|
|
212
|
-
left.push(scripts);
|
|
213
|
-
}
|
|
214
|
-
} else if (!isPlainDir(dir) || dir.ino !== created.dirIno) left.push(scripts);
|
|
236
|
+
if (empty) remove(path, io.rmdir);
|
|
215
237
|
}
|
|
216
238
|
return left;
|
|
217
239
|
};
|
|
@@ -225,6 +247,7 @@ const applyHookChecks = (plan, resolved) => {
|
|
|
225
247
|
const failure = child.status !== 0 ? `installer exited ${child.status ?? child.signal ?? child.error?.code}`
|
|
226
248
|
: hook.state === 'no-hooks-dir' ? null
|
|
227
249
|
: hook.state === 'unreadable' ? `${preCommit} is unreadable (${hook.code}) after the installer exited 0`
|
|
250
|
+
: plan.switchCommand && !hook.command ? `${preCommit} carries no kit-command line after the installer exited 0 — ${UPGRADE_ROUTE}`
|
|
228
251
|
: ROLES.filter(({ key }) => plan.roles.includes(key)).map(({ key, role }) => (!hook[`${key}Armed`]
|
|
229
252
|
? `${preCommit} carries no ${role} line after the installer exited 0 — ${UPGRADE_ROUTE}`
|
|
230
253
|
: hook[`${key}Foreign`] ? `${preCommit} still carries a ${role} line on a path other than this kit's after the installer exited 0` : null)).find(Boolean) ?? null;
|
|
@@ -238,30 +261,32 @@ export const applyGitHooks = (plan, io = {}) => {
|
|
|
238
261
|
log: console.log, error: console.error, writeFile: writeProjectFileCreateOnly, toolsDir: TOOLS, platform: process.platform,
|
|
239
262
|
spawn: (argv, options) => spawnSync(argv[0], argv.slice(1), options), ...io };
|
|
240
263
|
if (plan.variant === 'hook-checks') return applyHookChecks(plan, resolved);
|
|
241
|
-
|
|
264
|
+
// A folder the dry run found absent and that still is absent here is one this run creates; a plan with no copies names none.
|
|
265
|
+
const created = { files: [], inos: new Map(), folders: (plan.folders ?? []).filter((rel) => nodeOrNull(join(plan.root, rel), resolved.lstat) === null) };
|
|
242
266
|
const leftovers = [];
|
|
243
267
|
const fail = (lines) => {
|
|
244
268
|
for (const line of lines) resolved.error(line);
|
|
245
269
|
for (const path of [...rollBack(plan, created, resolved), ...leftovers]) resolved.error(`not removed: ${path}`);
|
|
246
270
|
return EXIT_INCOMPLETE;
|
|
247
271
|
};
|
|
248
|
-
const
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
272
|
+
const noteFolders = (rel) => {
|
|
273
|
+
for (const folder of foldersOf(rel).filter((at) => !created.inos.has(at))) {
|
|
274
|
+
const node = nodeOrNull(join(plan.root, folder), resolved.lstat);
|
|
275
|
+
if (isPlainDir(node)) created.inos.set(folder, node.ino);
|
|
276
|
+
}
|
|
252
277
|
};
|
|
253
278
|
for (const copy of plan.copies.filter(({ action }) => action === 'created')) {
|
|
254
279
|
let result;
|
|
255
280
|
try {
|
|
256
|
-
result = resolved.writeFile(plan.root,
|
|
281
|
+
result = resolved.writeFile(plan.root, copy.rel, copy.bytes);
|
|
257
282
|
} catch (error) {
|
|
258
|
-
|
|
259
|
-
return fail([error?.message ?? String(error)]);
|
|
283
|
+
noteFolders(copy.rel);
|
|
284
|
+
return fail([`${copy.path}: ${error?.message ?? String(error)}`]);
|
|
260
285
|
}
|
|
261
|
-
|
|
286
|
+
noteFolders(copy.rel);
|
|
262
287
|
if (result.tmpLeftBehind) leftovers.push(result.tmpLeftBehind);
|
|
263
288
|
if (!result.created) return fail([`${copy.path} appeared after the check — the file found there stands`]);
|
|
264
|
-
created.push(copy
|
|
289
|
+
created.files.push(copy);
|
|
265
290
|
}
|
|
266
291
|
const child = resolved.spawn(plan.runs.argv, { cwd: plan.root, env: resolved.env, stdio: 'inherit' });
|
|
267
292
|
if (child.status !== 0) return fail([`installer exited ${child.status ?? child.signal ?? child.error?.code}`]);
|
package/tools/jev-connect.mjs
CHANGED
|
@@ -10,7 +10,7 @@ import { spawnSync } from 'node:child_process';
|
|
|
10
10
|
import { lstatSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
11
11
|
import { homedir } from 'node:os';
|
|
12
12
|
import { basename, dirname, isAbsolute, join, relative, sep } from 'node:path';
|
|
13
|
-
import { fail } from '../references/scripts/
|
|
13
|
+
import { fail } from '../references/scripts/shared/index.mjs';
|
|
14
14
|
import { isDirectRun } from './direct-run.mjs';
|
|
15
15
|
import { JEV_ENDPOINT, JEV_ERROR_MEANINGS, JEV_SAMPLE_BODY, KEY_VARIABLE, RESTART_STEP } from './jev-facts.mjs';
|
|
16
16
|
|
package/tools/jev-guide.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import { lstatSync, readFileSync, readdirSync, statSync } from 'node:fs';
|
|
|
4
4
|
import { homedir, hostname } from 'node:os';
|
|
5
5
|
import { basename, dirname, join, resolve } from 'node:path';
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
|
-
import { fail } from '../references/scripts/
|
|
7
|
+
import { fail } from '../references/scripts/shared/index.mjs';
|
|
8
8
|
import { isDirectRun } from './direct-run.mjs';
|
|
9
9
|
import { AFTER_INSTALL, KEY_VARIABLE, NO_APPLY_LINE, RESTART_STEP, SKILL_PINS, claudeDirOf, connectLine, keySet, placeOf, printable, skillLine, skillState, skillTargets } from './jev-facts.mjs';
|
|
10
10
|
|
package/tools/jev-skill.mjs
CHANGED
|
@@ -11,7 +11,7 @@ import { lstatSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, renameSyn
|
|
|
11
11
|
import { homedir } from 'node:os';
|
|
12
12
|
import { dirname, join, posix, win32 } from 'node:path';
|
|
13
13
|
import { fileURLToPath } from 'node:url';
|
|
14
|
-
import { fail } from '../references/scripts/
|
|
14
|
+
import { fail } from '../references/scripts/shared/index.mjs';
|
|
15
15
|
import { isDirectRun } from './direct-run.mjs';
|
|
16
16
|
import { AFTER_INSTALL, NO_APPLY_LINE, SKILL_FILES, SKILL_PINS, claudeDirOf, printable, skillLine, skillState,
|
|
17
17
|
skillTargets } from './jev-facts.mjs';
|
|
@@ -15,9 +15,11 @@
|
|
|
15
15
|
// references/contracts.md carries the human-readable mirror table, kept in sync by review.
|
|
16
16
|
//
|
|
17
17
|
// Pure, dependency-free, Node >= 22. The only fs touch is expandGlob (readdir/stat of a glob parent),
|
|
18
|
-
// injected so the registry stays unit-testable without the real filesystem
|
|
18
|
+
// injected so the registry stays unit-testable without the real filesystem; the kit folder's path is
|
|
19
|
+
// node-evidence.mjs's, the kit's one door to the script family (which reads its manifest on import).
|
|
19
20
|
|
|
20
21
|
import { readdirSync, statSync } from 'node:fs';
|
|
22
|
+
import { KIT_SCRIPTS_DIR } from './node-evidence.mjs';
|
|
21
23
|
|
|
22
24
|
// A typed STOP — a deliberate refusal we surface (never a silent skip, never a fail-open). Shared by
|
|
23
25
|
// the writer tool (hide-footprint.mjs imports it) so both speak one error vocabulary. The codebase's
|
|
@@ -41,38 +43,14 @@ export const stop = (message, fields = {}) =>
|
|
|
41
43
|
// follow-up-reconcile gap this entry closes. Never provisioned into a worktree (worktrees.mjs). `/docs/plans/` + both `.claude/settings*.json` are listed because a pure
|
|
42
44
|
// hidden deploy has no tracked `.gitignore`; the classifier drops any candidate a tracked `.gitignore`
|
|
43
45
|
// already covers, so in a repo that DOES track those ignores they are never re-written.
|
|
44
|
-
// The
|
|
45
|
-
// `
|
|
46
|
-
//
|
|
46
|
+
// The kit folder is the kit's whole, so one directory pattern covers every file placed in it; no flat
|
|
47
|
+
// `scripts/<name>` is listed, because the upgrade's scripts op removes the kit's old flat files in the
|
|
48
|
+
// run that places the kit folder (distribution-files, part flat-move: the window it leaves is stated there).
|
|
47
49
|
export const KIT_OWN_PATHS = [
|
|
48
50
|
'/AGENTS.md',
|
|
49
51
|
'/CLAUDE.md',
|
|
50
52
|
'/docs/ai/',
|
|
51
|
-
|
|
52
|
-
'/scripts/archive-caps.mjs',
|
|
53
|
-
'/scripts/archive-caps.test.mjs',
|
|
54
|
-
'/scripts/archive-changelog.mjs',
|
|
55
|
-
'/scripts/archive-changelog.test.mjs',
|
|
56
|
-
'/scripts/archive-conservation.test.mjs',
|
|
57
|
-
'/scripts/archive-decisions.mjs',
|
|
58
|
-
'/scripts/archive-decisions.test.mjs',
|
|
59
|
-
'/scripts/archive-issues.mjs',
|
|
60
|
-
'/scripts/archive-issues.test.mjs',
|
|
61
|
-
'/scripts/archiver-structure.test.mjs',
|
|
62
|
-
'/scripts/check-docs-size-cli.test.mjs',
|
|
63
|
-
'/scripts/check-docs-size-ensure.test.mjs',
|
|
64
|
-
'/scripts/check-docs-size.mjs',
|
|
65
|
-
'/scripts/check-docs-size.test.mjs',
|
|
66
|
-
'/scripts/install-git-hooks-repo-exec.test.mjs',
|
|
67
|
-
'/scripts/install-git-hooks.mjs',
|
|
68
|
-
'/scripts/install-git-hooks.test.mjs',
|
|
69
|
-
'/scripts/markdown-blocks.mjs',
|
|
70
|
-
'/scripts/markdown-blocks.test.mjs',
|
|
71
|
-
'/scripts/migrate-gates-branches.test.mjs',
|
|
72
|
-
'/scripts/migrate-gates.mjs',
|
|
73
|
-
'/scripts/migrate-gates.test.mjs',
|
|
74
|
-
'/scripts/spec-schema.mjs',
|
|
75
|
-
'/scripts/spec-schema.test.mjs',
|
|
53
|
+
`/${KIT_SCRIPTS_DIR}/`,
|
|
76
54
|
'/docs/plans/',
|
|
77
55
|
'/.claude/settings.local.json',
|
|
78
56
|
'/.claude/settings.json',
|
package/tools/node-evidence.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
// node-evidence.mjs — does Node PROVABLY run in this project tree? Contract: docs/ai/specs/kit/node-evidence.md.
|
|
2
2
|
// Pure over an injectable lstat; no writes, no side effects on import. Dependency-free, Node >= 22.
|
|
3
3
|
|
|
4
|
-
import { lstatSync
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { lstatSync } from 'node:fs';
|
|
5
|
+
import { join, posix } from 'node:path';
|
|
6
|
+
import { readFamily } from '../references/scripts/family.mjs';
|
|
7
|
+
import { KIT_FOLDER_ROOT } from './source-size-config.mjs';
|
|
7
8
|
|
|
8
9
|
export const NODE_EVIDENCE = Object.freeze({
|
|
9
10
|
PACKAGE_JSON: 'package-json',
|
|
@@ -14,16 +15,18 @@ export const NODE_EVIDENCE = Object.freeze({
|
|
|
14
15
|
|
|
15
16
|
export const PACKAGE_JSON_REL = 'package.json';
|
|
16
17
|
export const SCRIPTS_DIR = 'scripts';
|
|
17
|
-
export const
|
|
18
|
+
export const KIT_SCRIPTS_DIR = KIT_FOLDER_ROOT;
|
|
18
19
|
|
|
19
|
-
//
|
|
20
|
-
//
|
|
21
|
-
//
|
|
22
|
-
export const
|
|
23
|
-
.
|
|
20
|
+
// The kit's one door to the script family: the mirrored manifest's deployed entries, each with its
|
|
21
|
+
// manifest path, module and seed flag, its deployed path in the kit folder and its bundled path in this
|
|
22
|
+
// kit. A manifest the reader refuses fails this module's import with the reader's message.
|
|
23
|
+
export const DEPLOYED_SCRIPTS = Object.freeze(readFamily().filter(({ role }) => role === 'deployed').map(({ path, module, seed }) =>
|
|
24
|
+
Object.freeze({ path, module, seed, deployed: `${KIT_SCRIPTS_DIR}/${path}`, bundled: `references/scripts/${path}` })));
|
|
25
|
+
export const INSTALLER_REL = DEPLOYED_SCRIPTS.find(({ module }) => module === 'git-hooks').deployed;
|
|
24
26
|
|
|
25
|
-
// The runnable
|
|
26
|
-
|
|
27
|
+
// The nine flat runnable names probed before the kit folder (frozen, so a flat deployment keeps its
|
|
28
|
+
// evidence), then the deployed manifest paths, sorted — each relative to scripts/.
|
|
29
|
+
const FLAT_SCRIPTS = [
|
|
27
30
|
'archive-caps.mjs',
|
|
28
31
|
'archive-changelog.mjs',
|
|
29
32
|
'archive-decisions.mjs',
|
|
@@ -33,6 +36,11 @@ export const NODE_EVIDENCE_SCRIPTS = Object.freeze([
|
|
|
33
36
|
'markdown-blocks.mjs',
|
|
34
37
|
'migrate-gates.mjs',
|
|
35
38
|
'spec-schema.mjs',
|
|
39
|
+
];
|
|
40
|
+
const KIT_UNDER_SCRIPTS = posix.relative(SCRIPTS_DIR, KIT_SCRIPTS_DIR);
|
|
41
|
+
export const NODE_EVIDENCE_SCRIPTS = Object.freeze([
|
|
42
|
+
...FLAT_SCRIPTS,
|
|
43
|
+
...DEPLOYED_SCRIPTS.map(({ path }) => path).sort().map((path) => `${KIT_UNDER_SCRIPTS}/${path}`),
|
|
36
44
|
]);
|
|
37
45
|
|
|
38
46
|
export const NODE_EVIDENCE_PROBES = Object.freeze([PACKAGE_JSON_REL, ...NODE_EVIDENCE_SCRIPTS.map((name) => `${SCRIPTS_DIR}/${name}`)]);
|
|
@@ -46,10 +54,16 @@ const answer = (state, evidence, wrongKind, extra = {}) =>
|
|
|
46
54
|
// probeNodeEvidence(cwd, lstat) -> { state, evidence, probed, wrongKind, error? }: the first regular file
|
|
47
55
|
// among the probes answers; a probe failing with anything but ENOENT answers unreadable at once; a path of
|
|
48
56
|
// the wrong node kind is not evidence — it is recorded in `wrongKind` and the walk continues. lstat does
|
|
49
|
-
// not follow the LEAF but walks THROUGH a symlinked
|
|
50
|
-
//
|
|
57
|
+
// not follow the LEAF but walks THROUGH a symlinked folder, whose files are not this tree's — so scripts/,
|
|
58
|
+
// the kit folder and each module folder are proven plain, once each, before any script beneath counts.
|
|
51
59
|
export const probeNodeEvidence = (cwd, lstat = lstatSync) => {
|
|
52
60
|
const wrongKind = [];
|
|
61
|
+
const folders = new Map();
|
|
62
|
+
const plainFolder = (rel) => {
|
|
63
|
+
if (!folders.has(rel)) folders.set(rel, probeKind(rel, 'dir') === 'dir');
|
|
64
|
+
return folders.get(rel);
|
|
65
|
+
};
|
|
66
|
+
const foldersOf = (rel) => rel.split('/').slice(1, -1).map((_, at, parts) => [SCRIPTS_DIR, ...parts.slice(0, at + 1)].join('/'));
|
|
53
67
|
const probeKind = (rel, wanted) => {
|
|
54
68
|
let st;
|
|
55
69
|
try {
|
|
@@ -64,9 +78,9 @@ export const probeNodeEvidence = (cwd, lstat = lstatSync) => {
|
|
|
64
78
|
};
|
|
65
79
|
try {
|
|
66
80
|
if (probeKind(PACKAGE_JSON_REL, 'file') === 'file') return answer(NODE_EVIDENCE.PACKAGE_JSON, PACKAGE_JSON_REL, wrongKind);
|
|
67
|
-
if (
|
|
81
|
+
if (plainFolder(SCRIPTS_DIR)) {
|
|
68
82
|
for (const rel of NODE_EVIDENCE_PROBES.slice(1)) {
|
|
69
|
-
if (probeKind(rel, 'file') === 'file') return answer(NODE_EVIDENCE.DEPLOYED_SCRIPTS, rel, wrongKind);
|
|
83
|
+
if (foldersOf(rel).every(plainFolder) && probeKind(rel, 'file') === 'file') return answer(NODE_EVIDENCE.DEPLOYED_SCRIPTS, rel, wrongKind);
|
|
70
84
|
}
|
|
71
85
|
}
|
|
72
86
|
} catch (err) {
|
package/tools/now-cli.mjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// facts in now-facts.mjs, the phrases in now-render.mjs.
|
|
4
4
|
|
|
5
5
|
import { resolve } from 'node:path';
|
|
6
|
-
import { fail } from '../references/scripts/
|
|
6
|
+
import { fail } from '../references/scripts/shared/index.mjs';
|
|
7
7
|
import { isDirectRun } from './direct-run.mjs';
|
|
8
8
|
import { FORMATS, detectSurface } from './surface.mjs';
|
|
9
9
|
import { gatherNowFacts } from './now-facts.mjs';
|