@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.
Files changed (94) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/README.md +7 -5
  3. package/SKILL.md +1 -1
  4. package/bin/install.mjs +10 -11
  5. package/capability.json +1 -1
  6. package/launchers/windsurf-workflow.md +3 -1
  7. package/package.json +5 -2
  8. package/references/contracts.md +9 -9
  9. package/references/modes/bootstrap.md +3 -3
  10. package/references/modes/commit-guard.md +1 -1
  11. package/references/modes/gates.md +1 -1
  12. package/references/modes/recommendations.md +2 -2
  13. package/references/modes/upgrade.md +4 -4
  14. package/references/scripts/{archive-caps.mjs → archives/archive-caps.mjs} +1 -1
  15. package/references/scripts/{archive-changelog.mjs → archives/archive-changelog.mjs} +7 -9
  16. package/references/scripts/{archive-decisions.mjs → archives/archive-decisions.mjs} +13 -10
  17. package/references/scripts/{archive-issues.mjs → archives/archive-issues.mjs} +7 -8
  18. package/references/scripts/{check-docs-size.mjs → docs-size/check-docs-size.mjs} +3 -4
  19. package/references/scripts/docs-size/index.mjs +2 -0
  20. package/references/scripts/family.json +43 -0
  21. package/references/scripts/family.mjs +90 -0
  22. package/references/scripts/gates/kit-command-gates.mjs +117 -0
  23. package/references/scripts/{migrate-gates.mjs → gates/migrate-gates.mjs} +30 -13
  24. package/references/scripts/{install-git-hooks.mjs → git-hooks/install-git-hooks.mjs} +50 -38
  25. package/references/scripts/run.mjs +74 -0
  26. package/references/scripts/shared/index.mjs +3 -0
  27. package/references/scripts/shared/project-root.mjs +11 -0
  28. package/references/scripts/spec-schema/index.mjs +2 -0
  29. package/references/shared/composition-handoff.md +1 -1
  30. package/references/shared/deploy-tail.md +2 -2
  31. package/references/templates/SPEC_TEMPLATE.md +1 -1
  32. package/references/templates/adr-record.md +3 -3
  33. package/tools/apply-danger-check.mjs +9 -5
  34. package/tools/atomic-write.mjs +3 -1
  35. package/tools/checker-gates-read.mjs +4 -1
  36. package/tools/direct-run.mjs +2 -0
  37. package/tools/distribution-files/retired.mjs +99 -0
  38. package/tools/distribution-files/scripts.mjs +67 -52
  39. package/tools/ensure-configs.mjs +21 -21
  40. package/tools/ensure-ops.mjs +60 -18
  41. package/tools/ensure-specs.mjs +82 -47
  42. package/tools/ensure-vocabulary.mjs +4 -4
  43. package/tools/epic-shape-cli.mjs +1 -1
  44. package/tools/epic-shape-ledger.mjs +1 -1
  45. package/tools/epic-shape.mjs +1 -1
  46. package/tools/family-registry.mjs +3 -1
  47. package/tools/feedback-record-cli.mjs +1 -1
  48. package/tools/fold-scope.mjs +2 -2
  49. package/tools/gates-declaration.mjs +8 -4
  50. package/tools/git-hooks.mjs +90 -65
  51. package/tools/jev-connect.mjs +1 -1
  52. package/tools/jev-guide.mjs +1 -1
  53. package/tools/jev-skill.mjs +1 -1
  54. package/tools/known-footprint.mjs +7 -29
  55. package/tools/node-evidence.mjs +29 -15
  56. package/tools/now-cli.mjs +1 -1
  57. package/tools/payload-prune.mjs +53 -58
  58. package/tools/plan-shape-cli.mjs +1 -1
  59. package/tools/plan-shape.mjs +1 -1
  60. package/tools/project-rules/rules-record.mjs +1 -1
  61. package/tools/queue-audit-cli.mjs +1 -1
  62. package/tools/queue-audit.mjs +2 -2
  63. package/tools/queue-purge-archive.mjs +1 -1
  64. package/tools/queue-purge-cli.mjs +1 -1
  65. package/tools/queue-purge.mjs +1 -1
  66. package/tools/recommendations.mjs +22 -19
  67. package/tools/script-priors.mjs +31 -3
  68. package/tools/source-size/piles.mjs +1 -1
  69. package/tools/spec-adoption.mjs +1 -1
  70. package/tools/spec-check-ops.mjs +2 -2
  71. package/tools/spec-check.mjs +2 -2
  72. package/tools/spec-coverage.mjs +1 -1
  73. package/tools/tier-guide.mjs +1 -1
  74. package/tools/transition/index.mjs +1 -1
  75. package/tools/upgrade-runlist.mjs +1 -1
  76. package/tools/write-lanes.mjs +2 -2
  77. package/references/scripts/_expect-shim.mjs +0 -41
  78. package/references/scripts/archive-caps.test.mjs +0 -321
  79. package/references/scripts/archive-changelog.test.mjs +0 -560
  80. package/references/scripts/archive-conservation.test.mjs +0 -466
  81. package/references/scripts/archive-decisions.test.mjs +0 -1503
  82. package/references/scripts/archive-issues.test.mjs +0 -825
  83. package/references/scripts/archiver-structure.test.mjs +0 -84
  84. package/references/scripts/check-docs-size-cli.test.mjs +0 -325
  85. package/references/scripts/check-docs-size-ensure.test.mjs +0 -360
  86. package/references/scripts/check-docs-size.test.mjs +0 -395
  87. package/references/scripts/install-git-hooks-repo-exec.test.mjs +0 -185
  88. package/references/scripts/install-git-hooks.test.mjs +0 -241
  89. package/references/scripts/markdown-blocks.test.mjs +0 -310
  90. package/references/scripts/migrate-gates-branches.test.mjs +0 -302
  91. package/references/scripts/migrate-gates.test.mjs +0 -517
  92. package/references/scripts/spec-schema.test.mjs +0 -352
  93. /package/references/scripts/{markdown-blocks.mjs → shared/markdown-blocks.mjs} +0 -0
  94. /package/references/scripts/{spec-schema.mjs → spec-schema/spec-schema.mjs} +0 -0
@@ -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 bundled scripts create-only and spawns the project's own
4
- // scripts/install-git-hooks.mjs as it stands, which decides the hook at the write. The leaf
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 { BUNDLED_SCRIPT_NAMES, INSTALLER_REL, NODE_EVIDENCE_SCRIPTS, SCRIPTS_DIR } from './node-evidence.mjs';
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 { BUNDLED_SCRIPT_NAMES, INSTALLER_REL };
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$/m;
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, scriptsNode, kinds, readFile, deps }) => {
128
- if (!isPlainDir(scriptsNode) || kinds.get(INSTALLER_NAME) !== 'file') throw refusal(`${installer} is absent — nothing here places the hook installer`);
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', scriptsCreated: false, copies: [], roles: roles.map(({ key }) => key),
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 scripts = join(root, SCRIPTS_REL);
147
- const scriptsNode = nodeAt(scripts, lstat);
148
- if (scriptsNode !== null && !isPlainDir(scriptsNode)) throw refusal(`${scripts} is not a plain directory`);
149
- const kinds = new Map();
150
- const names = variant === 'enforcement' ? BUNDLED_SCRIPT_NAMES : [INSTALLER_REL.slice(SCRIPTS_REL.length + 1)];
151
- for (const name of scriptsNode === null ? [] : names) {
152
- const path = join(scripts, name);
153
- const node = nodeAt(path, lstat);
154
- if (node !== null && !isFile(node)) throw refusal(`${path} is not a regular file`);
155
- kinds.set(name, node === null ? 'absent' : 'file');
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, scriptsNode, kinds, readFile, deps });
159
- const deployed = NODE_EVIDENCE_SCRIPTS.some((name) => kinds.get(name) === 'file');
160
- const copies = variant === 'enforcement' && !deployed ? BUNDLED_SCRIPT_NAMES.map((name) => {
161
- if (kinds.get(name) === 'file') return { name, path: join(scripts, name), action: 'kept' };
162
- return { name, path: join(scripts, name), action: 'created', bytes: readFile(join(bundleDir(toolsDir), name)) };
163
- }) : [];
164
- const placed = copies.find(({ path, action }) => path === installer && action === 'created');
165
- if (!placed && !isFile(nodeAt(installer, lstat))) throw refusal(`${installer} is absent — nothing here places the hook installer`);
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
- scriptsCreated: scriptsNode === null,
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(({ name, action, bytes }) => `copy: ${SCRIPTS_REL}/${name} ${action}${action === 'created' ? ` sha256:${sha(bytes)}` : ''}`),
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 scripts/ when this run created it and it is empty;
182
- // every path it cannot remove is answered for the caller to name.
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 dirNow = () => nodeAt(scripts, io.lstat);
187
- for (const path of created) {
188
- const dir = dirNow();
189
- const node = nodeAt(path, io.lstat);
190
- if (!isPlainDir(dir) || dir.ino !== created.dirIno || !isFile(node)) {
191
- left.push(path);
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
- io.unlink(path);
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
- if (plan.scriptsCreated && created.dirIno !== undefined) {
201
- const dir = dirNow();
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 = isPlainDir(dir) && dir.ino === created.dirIno && io.readdir(scripts).length === 0;
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
- const created = [];
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 scripts = join(plan.root, SCRIPTS_REL);
249
- const noteDir = () => {
250
- const dir = nodeAt(scripts, resolved.lstat);
251
- if (created.dirIno === undefined && isPlainDir(dir)) created.dirIno = dir.ino;
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, `${SCRIPTS_REL}/${copy.name}`, copy.bytes);
281
+ result = resolved.writeFile(plan.root, copy.rel, copy.bytes);
257
282
  } catch (error) {
258
- noteDir();
259
- return fail([error?.message ?? String(error)]);
283
+ noteFolders(copy.rel);
284
+ return fail([`${copy.path}: ${error?.message ?? String(error)}`]);
260
285
  }
261
- noteDir();
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.path);
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}`]);
@@ -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/markdown-blocks.mjs';
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
 
@@ -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/markdown-blocks.mjs';
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
 
@@ -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/markdown-blocks.mjs';
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 enumeration must cover EVERY file the deploy copies into `scripts/` (bootstrap step 8 copies
45
- // `references/scripts/*.mjs` + `*.test.mjs` wholesale): a name missing here is a file a hidden
46
- // deployment leaves visible in `git status` — the exact leak this registry exists to prevent.
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
- '/scripts/_expect-shim.mjs',
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',
@@ -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, readdirSync } from 'node:fs';
5
- import { dirname, join } from 'node:path';
6
- import { fileURLToPath } from 'node:url';
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 INSTALLER_REL = `${SCRIPTS_DIR}/install-git-hooks.mjs`;
18
+ export const KIT_SCRIPTS_DIR = KIT_FOLDER_ROOT;
18
19
 
19
- // Every *.mjs of the kit's references/scripts/, sorted, the tests and the shim included: what the
20
- // enforcement copy places. Read from this kit copy at import, so a module the git-hooks leaf's own
21
- // imports reach names the bundle without importing that leaf back.
22
- export const BUNDLED_SCRIPT_NAMES = Object.freeze(readdirSync(join(dirname(fileURLToPath(import.meta.url)), '..', 'references', 'scripts'))
23
- .filter((name) => name.endsWith('.mjs')).sort());
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 scripts the bootstrap copies from references/scripts/ — pinned against the bundle by the suite.
26
- export const NODE_EVIDENCE_SCRIPTS = Object.freeze([
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 scripts/, whose files are not this tree's — so the
50
- // directory is proven plain before any script inside it counts.
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 (probeKind(SCRIPTS_DIR, 'dir') === 'dir') {
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/markdown-blocks.mjs';
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';