@sabaiway/agent-workflow-kit 23.11.0 → 24.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. package/CHANGELOG.md +87 -0
  2. package/README.md +4 -4
  3. package/SKILL.md +1 -1
  4. package/bridges/codex-cli-bridge/SKILL.md +7 -2
  5. package/bridges/codex-cli-bridge/bin/codex-exec-jev.test.mjs +11 -6
  6. package/bridges/codex-cli-bridge/bin/codex-exec.sh +72 -33
  7. package/bridges/codex-cli-bridge/bin/codex-exec.test.mjs +111 -3
  8. package/bridges/codex-cli-bridge/bin/codex-fixtures-harness.test.mjs +16 -1
  9. package/bridges/codex-cli-bridge/bin/codex-model-posture.test.mjs +5 -3
  10. package/bridges/codex-cli-bridge/bin/codex-review.sh +1 -1
  11. package/bridges/codex-cli-bridge/capability.json +2 -2
  12. package/capability.json +1 -1
  13. package/package.json +1 -1
  14. package/references/advisor-writers.md +2 -0
  15. package/references/agents/author.md +21 -0
  16. package/references/agents/executor.md +12 -6
  17. package/references/contracts.md +4 -4
  18. package/references/hooks/gate-approve.mjs +7 -8
  19. package/references/hooks/stage-write-guard.mjs +314 -0
  20. package/references/modes/agents.md +6 -4
  21. package/references/modes/bootstrap.md +1 -1
  22. package/references/modes/control-bytes.md +38 -32
  23. package/references/modes/flow-writer.md +10 -2
  24. package/references/modes/hook.md +4 -1
  25. package/references/modes/now.md +1 -1
  26. package/references/modes/procedures.md +49 -10
  27. package/references/modes/recipes.md +7 -7
  28. package/references/modes/recommendations.md +5 -4
  29. package/references/modes/robustness-brief.md +9 -8
  30. package/references/modes/set-recipe.md +1 -1
  31. package/references/modes/state-block-guard.md +4 -3
  32. package/references/modes/status.md +1 -1
  33. package/references/modes/upgrade.md +1 -1
  34. package/references/modes/worktrees.md +28 -5
  35. package/references/rules/story-sessions.md +2 -2
  36. package/references/scripts/archives/archive-caps.mjs +1 -1
  37. package/references/scripts/archives/archive-changelog.mjs +8 -8
  38. package/references/scripts/archives/archive-decisions.mjs +7 -7
  39. package/references/scripts/archives/archive-issues.mjs +5 -5
  40. package/references/scripts/archives/rotation-conservation.mjs +2 -1
  41. package/references/scripts/docs-size/check-docs-size.mjs +15 -15
  42. package/references/scripts/family.json +2 -0
  43. package/references/scripts/gates/kit-command-gates.mjs +7 -8
  44. package/references/scripts/gates/migrate-gates.mjs +10 -10
  45. package/references/scripts/git-hooks/install-git-hooks.mjs +13 -13
  46. package/references/scripts/run.mjs +1 -2
  47. package/references/scripts/shared/index.mjs +2 -0
  48. package/references/scripts/shared/locations.mjs +103 -0
  49. package/references/scripts/spec-schema/spec-schema.mjs +2 -1
  50. package/references/templates/orchestration.json +1 -1
  51. package/tools/ack-store.mjs +2 -1
  52. package/tools/advisor-matrix.mjs +2 -1
  53. package/tools/advisor-skip/index.mjs +73 -0
  54. package/tools/apply-danger-check.mjs +20 -6
  55. package/tools/atomic-write.mjs +3 -2
  56. package/tools/attribution.mjs +2 -1
  57. package/tools/autonomy-config.mjs +2 -1
  58. package/tools/bridge-wiring.mjs +13 -11
  59. package/tools/carriers.mjs +54 -14
  60. package/tools/cheap-agents-read.mjs +28 -7
  61. package/tools/cheap-agents.mjs +15 -10
  62. package/tools/checker-gates-read.mjs +6 -5
  63. package/tools/commands.mjs +2 -2
  64. package/tools/control-bytes.mjs +43 -20
  65. package/tools/coverage-declared/config.mjs +2 -1
  66. package/tools/coverage-producer.mjs +10 -9
  67. package/tools/delegation.mjs +7 -6
  68. package/tools/detect-backends.mjs +1 -1
  69. package/tools/dispatch-baseline.mjs +2 -1
  70. package/tools/distribution-files/scripts.mjs +4 -4
  71. package/tools/doc-parity/index.mjs +46 -0
  72. package/tools/doc-parity.mjs +27 -47
  73. package/tools/ensure-configs.mjs +2 -2
  74. package/tools/ensure-ops.mjs +24 -24
  75. package/tools/ensure-specs.mjs +7 -7
  76. package/tools/epic-shape-cli.mjs +2 -2
  77. package/tools/epic-shape-ledger.mjs +5 -5
  78. package/tools/epic-shape.mjs +5 -3
  79. package/tools/epic-store.mjs +2 -1
  80. package/tools/family-members.mjs +7 -5
  81. package/tools/family-registry.mjs +36 -30
  82. package/tools/feedback-record-cli.mjs +4 -5
  83. package/tools/flow-writer.mjs +26 -15
  84. package/tools/gate-hook.mjs +33 -28
  85. package/tools/gates-declaration.mjs +2 -1
  86. package/tools/gates-init.mjs +6 -5
  87. package/tools/git-hooks.mjs +64 -41
  88. package/tools/grounding.mjs +3 -2
  89. package/tools/hide-footprint.mjs +2 -1
  90. package/tools/hook-writer/index.mjs +147 -0
  91. package/tools/init-preflight.mjs +5 -4
  92. package/tools/init-project.mjs +12 -11
  93. package/tools/inject-methodology.mjs +3 -2
  94. package/tools/jev-guide.mjs +2 -2
  95. package/tools/known-footprint.mjs +27 -25
  96. package/tools/mcp-registration.mjs +6 -5
  97. package/tools/migration-blocks.mjs +2 -1
  98. package/tools/migration-notes.mjs +2 -2
  99. package/tools/node-evidence.mjs +4 -4
  100. package/tools/now-facts.mjs +5 -5
  101. package/tools/now-status.mjs +1 -5
  102. package/tools/orchestration-config.mjs +2 -1
  103. package/tools/orchestration-readme.mjs +7 -2
  104. package/tools/plan-approval/cli.mjs +45 -0
  105. package/tools/plan-approval/entries.mjs +109 -0
  106. package/tools/plan-approval/index.mjs +2 -0
  107. package/tools/plan-approval/record.mjs +198 -0
  108. package/tools/plan-files.mjs +6 -4
  109. package/tools/plan-shape-cli.mjs +10 -64
  110. package/tools/plan-shape-facts.mjs +240 -83
  111. package/tools/plan-shape.mjs +173 -160
  112. package/tools/plan-structure/cli.mjs +79 -0
  113. package/tools/plan-structure/index.mjs +67 -0
  114. package/tools/procedures.mjs +21 -17
  115. package/tools/profile-gaps.mjs +4 -6
  116. package/tools/project-rules/rules-priors.mjs +2 -0
  117. package/tools/project-rules/themes.mjs +6 -4
  118. package/tools/recipes.mjs +44 -29
  119. package/tools/recommendations.mjs +90 -39
  120. package/tools/reference-profile.mjs +2 -2
  121. package/tools/release-scan/index.mjs +30 -0
  122. package/tools/release-scan.mjs +46 -25
  123. package/tools/renderers.mjs +14 -8
  124. package/tools/repo-lex.mjs +84 -0
  125. package/tools/robustness-brief.mjs +14 -11
  126. package/tools/sandbox-masks.mjs +6 -4
  127. package/tools/satellite-locator.mjs +3 -2
  128. package/tools/script-priors.mjs +3 -2
  129. package/tools/session-close-check.mjs +71 -15
  130. package/tools/set-flow.mjs +2 -2
  131. package/tools/set-recipe.mjs +17 -9
  132. package/tools/source-size/help.mjs +4 -4
  133. package/tools/source-size/layout.mjs +2 -1
  134. package/tools/source-size/piles.mjs +2 -2
  135. package/tools/source-size-config.mjs +3 -3
  136. package/tools/source-size-refusal.mjs +4 -3
  137. package/tools/source-size-report.mjs +41 -13
  138. package/tools/spec-check-cli.mjs +159 -21
  139. package/tools/spec-check-ops.mjs +74 -5
  140. package/tools/spec-check.mjs +54 -45
  141. package/tools/spec-coverage-cli.mjs +3 -2
  142. package/tools/stage-render/cli.mjs +231 -0
  143. package/tools/stage-render/index.mjs +340 -0
  144. package/tools/stage-render/stages.json +115 -0
  145. package/tools/stage-write-guard/cli.mjs +64 -0
  146. package/tools/stage-write-guard/index.mjs +56 -0
  147. package/tools/state-block-hook.mjs +38 -163
  148. package/tools/task-brief.mjs +8 -13
  149. package/tools/task-thread.mjs +3 -1
  150. package/tools/tier-guide-facts.mjs +23 -9
  151. package/tools/tier-preview.mjs +15 -19
  152. package/tools/transition/index.mjs +10 -9
  153. package/tools/uninstall.mjs +26 -12
  154. package/tools/vehicle-settings.mjs +2 -1
  155. package/tools/velocity-profile.mjs +5 -6
  156. package/tools/view-model.mjs +7 -4
  157. package/tools/worktree-prompt.mjs +7 -3
  158. package/tools/worktrees.mjs +235 -159
  159. package/tools/write-lanes.mjs +20 -14
@@ -15,6 +15,7 @@
15
15
  //
16
16
  // Dependency-free, Node >= 22. No writes, no side effects on import.
17
17
 
18
+ import { AGENT_RULES, RULES_EFFECTIVE } from '../references/scripts/shared/index.mjs';
18
19
  import { SOURCE_SIZE_CONFIG_REL, SOURCE_SIZE_WARNING_PREFIX, SOURCE_SIZE_WHY, configPathFor, escapeForLine, isLineUnsafe, jsonForLine } from './source-size-refusal.mjs';
19
20
  import { KIT_FOLDER_ROOT, SOURCE_SIZE_SCHEMA, practiceFacts } from './source-size-config.mjs';
20
21
  import { SOURCE_SIZE_TOOL_PATH, dqUnsafePath } from './source-size-gate-cmd.mjs';
@@ -32,9 +33,10 @@ const namedConfig = (cwd) => escapeForLine(configPathFor(cwd));
32
33
  // `_README` byte-equal to one of them with the text of the schema it writes and carries any other verbatim.
33
34
  export const SCHEMA1_TEMPLATE_README = 'Source-size practice: declared scope + thresholds + the recorded ratchet. Authored keys: schema, defaults, roots, exclude, extensions. Machine keys: baseline, aggregate — each recorded entry carries a reason, and a recorded size is debt, not permission. Strict JSON — unknown keys refused.';
34
35
  export const SCHEMA2_TEMPLATE_README = 'Source-size practice: declared scope + the recorded ratchet; the limits are the kit\'s, kept in its code. Authored keys: schema, roots, exclude, extensions, limits (a project\'s reasoned overrides of a kit limit). Machine keys: baseline, aggregate, layout — each recorded entry carries a reason, and a recorded size is debt, not permission. Strict JSON — unknown keys refused.';
35
- export const TEMPLATE_README = 'Source-size practice: declared scope + the recorded ratchet; the limits are the kit\'s, kept in its code. Authored keys: schema, roots, exclude, extensions, limits (a project\'s reasoned overrides of a kit limit). Machine keys: baseline, layout — each recorded entry carries a reason, and a recorded size is debt, not permission. Strict JSON — unknown keys refused.';
36
+ const REVISION_12_TEMPLATE_README = 'Source-size practice: declared scope + the recorded ratchet; the limits are the kit\'s, kept in its code. Authored keys: schema, roots, exclude, extensions, limits (a project\'s reasoned overrides of a kit limit). Machine keys: baseline, layout — each recorded entry carries a reason, and a recorded size is debt, not permission. Strict JSON — unknown keys refused.';
37
+ export const TEMPLATE_README = 'Source-size practice: declared scope + the recorded ratchet; the limits are the kit\'s, kept in its code. Authored keys: schema, roots, exclude, extensions, limits (a project\'s reasoned overrides of a kit limit). Machine keys: baseline, layout — each recorded entry is an exception with its own reason, never permission to grow. Strict JSON — unknown keys refused.';
36
38
  export const TEMPLATE_READMES = Object.freeze({ schema1: SCHEMA1_TEMPLATE_README, schema2: SCHEMA2_TEMPLATE_README });
37
- export const EARLIER_TEMPLATE_READMES = Object.freeze([SCHEMA1_TEMPLATE_README, SCHEMA2_TEMPLATE_README]);
39
+ export const EARLIER_TEMPLATE_READMES = Object.freeze([SCHEMA1_TEMPLATE_README, SCHEMA2_TEMPLATE_README, REVISION_12_TEMPLATE_README]);
38
40
 
39
41
  // The authoring template (D-5): GENERIC, and INERT by construction — its roots/extensions carry
40
42
  // placeholders the validator refuses, so it can never be pasted into an empty-green scope.
@@ -82,7 +84,9 @@ const WITHHELD_LINE = 'source-size: no paste-ready command is printed — this p
82
84
  // The withheld fallback is the reader's ONLY remaining instruction, so it has to be the instruction
83
85
  // for what they were actually doing. Sending an adoption to the regenerator would leave them with a
84
86
  // record and no gate — half an adoption, handed over as the way out — so the lane is per MODE.
85
- const WITHHELD_LANE = 'Run the regenerator yourself with the working directory set to this project (source-size-check.mjs --write-baseline, plus --reason "<text>" for any raise), or record each size by hand below, your reason in place of the placeholder.';
87
+ const regenerationMode = (layout) => (layout ? '--write-baseline --layout' : '--write-baseline');
88
+ const withheldLane = (layout = false) => `Run the regenerator yourself with the working directory set to this project (source-size-check.mjs ${regenerationMode(layout)}, plus --reason "<text>" for any raise).`;
89
+ const WITHHELD_LANE = withheldLane();
86
90
  const WITHHELD_ADOPT_LANE = `Run source-size-check.mjs --adopt --reason "${INITIAL_ADOPTION_REASON}" yourself, with the working directory set to this project — it mints the record and declares the gate in one step.`;
87
91
 
88
92
  // → { command, withheld }: exactly one of the two is non-null. ONE renderer for every mode this tool
@@ -93,9 +97,12 @@ const rendered = (cwd, mode, reason) => {
93
97
  if (paths.some(dqUnsafePath)) return { command: null, withheld: WITHHELD_SHELL };
94
98
  return { command: `node "${SOURCE_SIZE_TOOL_PATH}" ${mode} --cwd "${cwd}"${reason === undefined ? '' : ` --reason "${reason}"`}`, withheld: null };
95
99
  };
96
- const regenerator = (cwd, reason, layout = false) => rendered(cwd, layout ? '--write-baseline --layout' : '--write-baseline', reason);
100
+ const regenerator = (cwd, reason, layout = false) => rendered(cwd, regenerationMode(layout), reason);
97
101
 
98
102
  const SPLIT_QUALITY_FOCUS = 'source-size: REVIEW FOCUS — a recorded size went DOWN or disappeared: check that this is real decomposition and not the same coupling spread across more files (paste this line into the review dispatch focus).';
103
+ const RAISE_FOCUS_END = 'judge whether the project\'s code rules were kept for that file; a reason naming a debt row holds an old file grown outside its story\'s scope (paste this line into the review dispatch focus).';
104
+ const RAISE_REVIEW_FOCUS = `source-size: REVIEW FOCUS — this write RAISED a recorded size: read each raised entry's reason and ${RAISE_FOCUS_END}`;
105
+ const HAND_RECORD_FOCUS = `source-size: REVIEW FOCUS — the entries above RAISE a recorded size once recorded by hand: give the review each one's recorded and new value and its reason, read each reason and ${RAISE_FOCUS_END}`;
99
106
 
100
107
  // Rendered refusals close with WHY. Thrown stops and usage refusals carry no WHY line; the command
101
108
  // line composes them, each with the remedy of its exit class (usage carries only its help lines).
@@ -106,7 +113,7 @@ const refusal = (lines) => [...lines, WHY_LINE];
106
113
  // absent one records nothing to summarize.
107
114
  const practiceLine = (config) => {
108
115
  const facts = practiceFacts(config);
109
- return `source-size: practice — caps ${facts.maxLines} lines · ${facts.maxLineBytes} bytes per line over ${facts.roots} declared root(s) · ${facts.recordedFiles} file(s) carry a recorded size (debt, not permission): growth past a record takes a reasoned bump, and a record above the tree or gone warns until the regeneration lowers or removes it.`;
116
+ return `source-size: practice — caps ${facts.maxLines} lines · ${facts.maxLineBytes} bytes per line over ${facts.roots} declared root(s) · ${facts.recordedFiles} file(s) carry a recorded size, each an exception with its reason: growth the regeneration would raise stops and takes a reason, asking again whether the project's code rules were kept; a record above the tree or gone warns until the regeneration lowers or removes it.`;
110
117
  };
111
118
 
112
119
  export const absentRefusalLines = (cwd) => refusal([
@@ -160,15 +167,16 @@ const PREDATING_KIT_STOPS = (schema) => `a kit that predates schema ${schema} st
160
167
  const BAND = (f) => `over the limit ${f.allowed} but within its band (up to ${f.ceiling})`;
161
168
  const NAMED_PATHS = 3;
162
169
  const namedPaths = (paths) => `${paths.slice(0, NAMED_PATHS).map(escapeForLine).join(', ')}${paths.length > NAMED_PATHS ? ` and ${paths.length - NAMED_PATHS} more` : ''}`;
170
+ const RECORDED_EXCEPTION_ENDING = 'a recorded exception holds the size it was reasoned for, not growth past it';
163
171
 
164
172
  // A stop: the regeneration would raise.
165
173
  const FINDING_LINE = Object.freeze({
166
174
  'over-default': (f) => `${f.rel}: ${f.dimension} ${f.actual} exceeds the declared default ${f.allowed} beyond its band (up to ${f.ceiling})`,
167
- grew: (f) => `${f.rel}: ${f.dimension} ${f.actual} exceeds its recorded baseline ${f.recorded} — recorded debt is not permission to grow`,
175
+ grew: (f) => `${f.rel}: ${f.dimension} ${f.actual} exceeds its recorded baseline ${f.recorded} — ${RECORDED_EXCEPTION_ENDING}`,
168
176
  'root-unrecorded': (f) => `${f.root}: declared root carries NO recorded files count (${f.actual} files measured) — the layout record must mirror the declared roots exactly`,
169
177
  'root-grew': (f) => `${f.root}: files ${f.actual} exceeds its recorded ${f.recorded} beyond its band (up to ${f.ceiling})`,
170
178
  'dir-over': (f) => `${f.dir}: ${f.dimension} ${f.actual} exceeds the limit ${f.allowed} beyond its band (up to ${f.ceiling})`,
171
- 'dir-grew': (f) => `${f.dir}: ${f.dimension} ${f.actual} exceeds its recorded ${f.recorded} — recorded debt is not permission to grow`,
179
+ 'dir-grew': (f) => `${f.dir}: ${f.dimension} ${f.actual} exceeds its recorded ${f.recorded} — ${RECORDED_EXCEPTION_ENDING}`,
172
180
  });
173
181
 
174
182
  // A warning: printed on every run, exit 0, until the value or its record comes back within its limit.
@@ -219,20 +227,40 @@ const findingPart = (finding) => {
219
227
  const emptyRootLines = (verdict) => verdict.scope.emptyRoots.map((rel) =>
220
228
  `source-size: NOTE — the declared root "${escapeForLine(rel)}" matches no tracked file with a declared extension${verdict.scope.kitFolderRoots.includes(rel) ? ` outside the kit's own folder ${KIT_FOLDER_ROOT}` : ''}`);
221
229
 
230
+ const CODE_RULE_QUESTIONS = [
231
+ `for each place above, ask first whether the project's code rules were kept; consult ${AGENT_RULES} and ${RULES_EFFECTIVE} where present`,
232
+ 'a broken rule: fix the code along its own seam; the rules kept and the size justified: record it as an exception with its reason, written by whoever runs the write, never asked of the user',
233
+ 'never split or compress a file for the number',
234
+ 'an old file grown in work about something else, its rules not kept: write a debt row and record the raise with a reason that names the row, never reworking the file outside that work\'s scope',
235
+ ];
236
+ const HAND_RECORD_REMEDIES = [
237
+ 'record each raised file by hand under "baseline", with that file\'s own reason: the entries below',
238
+ 'only where one reason fits every raise of this run, regenerate instead:',
239
+ ];
240
+ const HAND_RECORD_LEAD = 'Each placeholder below is replaced by that file\'s own reason; the validator accepts the rest of these bytes as they are:';
241
+ const REGENERATION_RAISES = 'This regeneration RAISES a recorded value, so the reason is REQUIRED — it is recorded in the entry it raises, and it is what the commit message and the CHANGELOG restate.';
242
+
222
243
  export const checkStopBlock = ({ cwd, verdict, absent = false }) => {
223
244
  const stops = stopsOf(verdict.findings);
224
245
  const warnings = warningsOf(verdict.findings);
225
246
  const entries = suggestedEntryLines(verdict);
247
+ const hasRaisedFiles = entries.length > 0;
248
+ const limitFired = stops.some((finding) => finding.kind !== 'root-unrecorded');
226
249
  const { command, withheld } = regenerator(cwd, GROWTH_REASON_PLACEHOLDER);
227
250
  return {
228
251
  failed: escapeLeadingSpace(`${stops.length} finding(s) ${absent ? `under the kit's values (${namedConfig(cwd)} is absent)` : `against ${namedConfig(cwd)}`}`),
229
252
  findings: stops.map(findingPart),
230
- remedies: [command ?? WITHHELD_LANE],
253
+ remedies: [
254
+ ...(limitFired ? CODE_RULE_QUESTIONS : []),
255
+ ...(hasRaisedFiles ? HAND_RECORD_REMEDIES : []),
256
+ command ?? WITHHELD_LANE,
257
+ ],
231
258
  after: refusal([
232
259
  ...emptyRootLines(verdict), ...warningLines(warnings),
233
- ...(command === null ? [withheld] : ['This regeneration RAISES a recorded value, so the reason is REQUIRED — it is recorded in the entry it raises, and it is what the commit message and the CHANGELOG restate.']),
234
- ...(command !== null && entries.length > 0 ? ['Or record each size by hand under "baseline" — replace the placeholder with your reason; the validator accepts the rest of these bytes as they are:'] : []),
235
- ...entries, ...(hasLoweredRecord(warnings) ? [SPLIT_QUALITY_FOCUS] : []),
260
+ command === null ? withheld : REGENERATION_RAISES,
261
+ ...(hasRaisedFiles ? [HAND_RECORD_LEAD, ...entries] : []),
262
+ ...(hasLoweredRecord(warnings) ? [SPLIT_QUALITY_FOCUS] : []),
263
+ ...(hasRaisedFiles ? [HAND_RECORD_FOCUS] : []),
236
264
  ]),
237
265
  };
238
266
  };
@@ -268,7 +296,7 @@ export const deltaLines = (deltas) => deltas.map(
268
296
  // A run that starts the layout record says so in the command it prints, or pasting it would not.
269
297
  const regenerationRefusal = (lead, cwd, deltas, layout) => {
270
298
  const { command, withheld } = regenerator(cwd, GROWTH_REASON_PLACEHOLDER, layout);
271
- return refusal([lead, ...deltaLines(deltas), command === null ? `${withheld} ${WITHHELD_LANE}` : ` ${command}`]);
299
+ return refusal([lead, ...deltaLines(deltas), command === null ? `${withheld} ${withheldLane(layout)}` : ` ${command}`]);
272
300
  };
273
301
 
274
302
  export const reasonRequiredLines = (cwd, deltas, { layout = false } = {}) => regenerationRefusal(
@@ -375,7 +403,7 @@ export const writtenLines = ({ cwd, deltas, reason, changed }) => {
375
403
  return [
376
404
  `source-size: baseline regenerated — ${deltas.length} change(s) in ${namedConfig(cwd)}:`,
377
405
  ...deltaLines(deltas),
378
- ...(reason === undefined ? [] : [`reason: ${reason}`]),
406
+ ...(reason === undefined ? [] : [`reason: ${reason}`, RAISE_REVIEW_FOCUS]),
379
407
  ];
380
408
  };
381
409
 
@@ -4,6 +4,7 @@
4
4
  //
5
5
  // node spec-check-cli.mjs --op modify=docs/ai/specs/login.md [--op ...] [--root <dir>]
6
6
  // node spec-check-cli.mjs --ops-file docs/plans/spec-ops.list
7
+ // node spec-check-cli.mjs --plan docs/plans/<name>.md [--root <dir>]
7
8
  // node spec-check-cli.mjs --all
8
9
  //
9
10
  // `--op` and `--ops-file` UNION and dedup by identity; `--all` is exclusive of both. The register
@@ -19,32 +20,38 @@
19
20
  // unreadable register, a --root that is not a directory, or an --all run with no store root.
20
21
  // Dependency-free, Node >= 22.
21
22
 
22
- import { lstatSync, readdirSync, readFileSync, realpathSync } from 'node:fs';
23
- import { resolve } from 'node:path';
23
+ import { lstatSync, readdirSync, realpathSync } from 'node:fs';
24
+ import { basename, dirname, posix, relative, resolve, sep } from 'node:path';
25
+ import { readSpecDocument } from '../references/scripts/spec-schema/index.mjs';
26
+ import { dirCovers } from './declared-paths.mjs';
24
27
  import { isDirectRun } from './direct-run.mjs';
25
- import { readRegularFileNoFollow } from './fs-read-nofollow.mjs';
26
- import { SPEC_OPS_GRAMMAR, parseSpecOps } from './spec-check-ops.mjs';
28
+ import { describeNonRegular, lstatNoFollowRead, readRegularFileNoFollow } from './fs-read-nofollow.mjs';
29
+ import { PLANS_REL } from './plan-files.mjs';
30
+ import { expandSweepPaths, isSweep, readPlansInFlight } from './plan-shape-facts.mjs';
31
+ import { SPEC_OPS_GRAMMAR, getRevisionHomePath, getRevisionStorePath, listingParentOf, parsePlanSpecOps, parseSpecOps } from './spec-check-ops.mjs';
27
32
  import { checkSpecs } from './spec-check.mjs';
28
33
 
29
- const { verbs, separator, storePrefix } = SPEC_OPS_GRAMMAR;
34
+ const { verbs, separator, storePrefix, storeRoot, suffix } = SPEC_OPS_GRAMMAR;
30
35
 
31
36
  const HELP = `spec-check — judge the feature-spec store against what this session says it changed.
32
37
 
33
38
  Usage:
34
39
  node spec-check-cli.mjs [--root <dir>] --op <op> [--op <op> ...]
35
40
  node spec-check-cli.mjs [--root <dir>] --ops-file <file>
41
+ node spec-check-cli.mjs [--root <dir>] --plan docs/plans/<name>.md
36
42
  node spec-check-cli.mjs [--root <dir>] --all
37
43
 
38
44
  An op is one of ${verbs.slice(0, -1).map((v) => `${v}=<path>`).join(' | ')} | rename=<old>${separator}<new>, and every
39
45
  path is a POSIX repo-relative .md document inside ${storePrefix} whose segments are kebab slugs.
40
- Nothing is normalized away and the store root is never an op target, so one document has exactly
41
- one accepted spelling.
46
+ Nothing is normalized away and the store root is never an --op or --ops-file target (--plan judges
47
+ it by a modify row), so one document has exactly one accepted spelling.
42
48
 
43
49
  --op repeatable; unions --ops-file and dedups by identity.
44
50
  --ops-file one op per line; blank lines and # comments parse away. Never defaulted — name the
45
51
  register this session wrote (e.g. docs/plans/spec-ops.list).
52
+ --plan judge the named in-flight plan's store rows and revisions. Exclusive of --op, --ops-file and --all.
46
53
  --all judge the WHOLE store instead: reachability (unlisted child vs orphan), acyclicity,
47
- store-wide slug uniqueness and module overlap. Exclusive of both op sources.
54
+ store-wide slug uniqueness and module overlap. Exclusive of --op, --ops-file and --plan.
48
55
  --root the repo root the paths are relative to (default: the process cwd).
49
56
 
50
57
  The check is advisory — nothing records that it ran, so a skipped or late call is indistinguishable
@@ -52,7 +59,7 @@ from one made before the edit.
52
59
 
53
60
  Exit codes: 0 ACCEPT; 1 findings; 2 usage (bad flag or op, unreadable register, bad --root).`;
54
61
 
55
- const FLAGS = ['op', 'ops-file', 'all', 'root'];
62
+ const FLAGS = ['op', 'ops-file', 'plan', 'all', 'root'];
56
63
  const REPEATABLE = ['op'];
57
64
  const BOOLEAN = ['all'];
58
65
 
@@ -71,6 +78,7 @@ const parseArgs = (argv) => {
71
78
  let value = eq === -1 ? argv[i + 1] : arg.slice(eq + 1);
72
79
  if (eq === -1) i += 1;
73
80
  if (value === undefined || (eq === -1 && value.startsWith('--'))) throw new Error(`--${name} requires a value`);
81
+ if (name === 'plan' && opts.plan !== undefined) throw new Error('--plan takes exactly one plan');
74
82
  if (REPEATABLE.includes(name)) opts[name].push(value);
75
83
  else opts[name] = value;
76
84
  }
@@ -111,43 +119,173 @@ export const list = (path) => {
111
119
  // exactly the alias the frozen grammar denies. The ops parser refuses that whitespace out loud.
112
120
  const opsFileLines = (text) => text.split(/\r?\n/).filter((line) => line.trim() !== '' && !line.trim().startsWith('#'));
113
121
 
122
+ const causeOf = (error) => error?.code ?? error?.message ?? String(error);
123
+ const pathError = (path, message) => Object.assign(new Error(message), { path });
124
+ const readContent = (path) => {
125
+ const { outcome, code, className, content } = readRegularFileNoFollow(path);
126
+ if (outcome !== 'ok') throw pathError(path, `cannot read (${code ?? className ?? (outcome === 'absent' ? 'ENOENT' : outcome)})`);
127
+ return content;
128
+ };
129
+ const isPlanSpelling = (path) => path === `${PLANS_REL}/${posix.basename(path)}` &&
130
+ path.endsWith(suffix) && posix.basename(path).length > suffix.length && !/[\\\0]/.test(path);
131
+ const repoPath = (root, path) => relative(root, path).split(sep).join('/');
132
+
133
+ const proveRevisionHome = (root, home, ops, files) => {
134
+ const homePath = resolve(root, home);
135
+ const status = lstatNoFollowRead(homePath);
136
+ if (status === null) return;
137
+ const rootReal = realpathSync(root);
138
+ const roles = new Map(ops.map(({ verb, target }) => [target, verb]));
139
+ const proveDirectory = (path, status) => {
140
+ if (!status.isDirectory()) throw pathError(path, `expected a plain directory, found ${describeNonRegular(status)}`);
141
+ if (!dirCovers(root, path) || !dirCovers(rootReal, realpathSync(path))) throw pathError(path, 'directory resolves outside the root');
142
+ };
143
+ const proveParents = (path) => {
144
+ if (path === root) return;
145
+ proveParents(dirname(path));
146
+ proveDirectory(path, lstatSync(path));
147
+ };
148
+ const readStore = (rel, allowAbsent = false) => {
149
+ const path = resolve(root, rel);
150
+ proveParents(dirname(path));
151
+ const status = lstatNoFollowRead(path);
152
+ if (status === null && allowAbsent) return null;
153
+ if (!status?.isFile()) throw pathError(path, `expected a regular store document, found ${status === null ? 'ENOENT' : describeNonRegular(status)}`);
154
+ const content = readContent(path);
155
+ return { ...readSpecDocument(content, rel.slice(storePrefix.length)), content };
156
+ };
157
+ const admit = (path) => {
158
+ const rel = getRevisionStorePath(home, repoPath(root, path));
159
+ const role = roles.get(rel);
160
+ if (rel === storeRoot || (role !== 'modify' && role !== 'add')) throw pathError(path, 'no eligible store row for this home file');
161
+ const content = readContent(path);
162
+ const { kind } = readSpecDocument(content, rel.slice(storePrefix.length));
163
+ const parent = listingParentOf(rel);
164
+ if (role === 'add' ? kind !== 'part' || roles.get(parent) !== 'modify' : kind !== 'spec' && kind !== 'part') {
165
+ throw pathError(path, 'expected a contract revision or a new part beside a root the plan modifies');
166
+ }
167
+ const stored = readStore(rel, role === 'add');
168
+ if (role === 'modify' && stored.kind !== kind) throw pathError(resolve(root, rel), 'the store document and its revision must have the same kind');
169
+ if (role === 'add' && stored !== null && stored.content !== content) throw pathError(resolve(root, rel), 'store and home bytes differ');
170
+ const contract = kind === 'part' ? readStore(parent) : stored;
171
+ const isLandedCopy = (target, document) => {
172
+ const source = resolve(root, home, target.slice(storePrefix.length));
173
+ return lstatNoFollowRead(source)?.isFile() === true && readContent(source) === document.content;
174
+ };
175
+ const landed = stored?.content === content || isLandedCopy(kind === 'part' ? parent : rel, contract);
176
+ if (contract.kind !== 'spec' || (contract.status !== 'live' && !landed) ||
177
+ (role === 'modify' && kind === 'part' && !contract.structure?.parts.some(({ target }) => target === `./${basename(rel)}`))) {
178
+ throw pathError(path, 'the home document must revise or belong to a live contract in the store');
179
+ }
180
+ files.set(rel, path);
181
+ };
182
+ const walk = (path, status) => {
183
+ proveDirectory(path, status);
184
+ for (const name of readdirSync(path)) {
185
+ const entry = resolve(path, name);
186
+ const status = lstatSync(entry);
187
+ if (status.isDirectory()) walk(entry, status);
188
+ else if (status.isFile()) admit(entry);
189
+ else throw pathError(entry, `expected a plain directory or regular file, found ${describeNonRegular(status)}`);
190
+ }
191
+ };
192
+ proveParents(dirname(homePath));
193
+ walk(homePath, status);
194
+ };
195
+
196
+ const storeIO = { read: readRegularFileNoFollow, probe, realpath, list };
197
+ const overlayStore = (root, files, ops) => {
198
+ const revisions = new Map([...files].map(([path, source]) => [resolve(root, path), source]));
199
+ const deleted = new Set(ops.filter(({ verb }) => verb === 'remove').map(({ target }) => resolve(root, target)));
200
+ const additions = new Map();
201
+ for (const path of revisions.keys()) {
202
+ const parent = dirname(path);
203
+ additions.set(parent, [...(additions.get(parent) ?? []), basename(path)]);
204
+ }
205
+ const sourceOf = (path) => revisions.get(resolve(path)) ?? path;
206
+ const removed = (path) => deleted.has(resolve(path)) && probe(path) === 'file';
207
+ return {
208
+ read: (path) => removed(path) ? { outcome: 'absent' } : readRegularFileNoFollow(sourceOf(path)),
209
+ probe: (path) => removed(path) ? 'absent' : probe(sourceOf(path)),
210
+ realpath: (path) => removed(path) ? null : realpath(sourceOf(path)),
211
+ list: (path) => {
212
+ const names = list(path);
213
+ if (names === null) return null;
214
+ return [...new Set([...names, ...(additions.get(resolve(path)) ?? [])])].filter((name) => !removed(resolve(path, name)));
215
+ },
216
+ };
217
+ };
218
+
219
+ const showVerdict = ({ exit: code, lines }) => {
220
+ const output = lines.join('\n');
221
+ return code === 2 ? { code, stdout: '', stderr: output } : { code, stdout: output, stderr: '' };
222
+ };
223
+
114
224
  // main(argv, deps) -> { code, stdout, stderr }. Never calls process.exit itself (the direct-run
115
225
  // guard does), and never reads anything the caller did not point it at.
116
226
  export const main = (argv, deps = {}) => {
117
227
  if (argv.includes('--help') || argv.includes('-h')) return { code: 0, stdout: HELP, stderr: '' };
118
- const read = deps.readFileSync ?? readFileSync;
228
+ const read = deps.readFileSync ?? readContent;
119
229
  const cwd = deps.cwd ?? (() => process.cwd());
120
230
  const usage = (message) => ({ code: 2, stdout: '', stderr: `spec-check: ${message}` });
121
- let opts;
122
231
  try {
123
- opts = parseArgs(argv);
232
+ const opts = parseArgs(argv);
233
+ return checkArgs(opts, cwd(), read, usage);
124
234
  } catch (err) {
125
- return usage(err.message);
235
+ return usage(err?.message ?? causeOf(err));
236
+ }
237
+ };
238
+
239
+ const checkArgs = (opts, workingDir, read, usage) => {
240
+ const planLane = opts.plan !== undefined;
241
+ if (planLane && (opts.all || opts.op.length > 0 || opts['ops-file'] !== undefined)) {
242
+ return usage('--plan is exclusive of --all, --op and --ops-file');
126
243
  }
244
+ if (planLane && !isPlanSpelling(opts.plan)) return usage(`--plan "${opts.plan}" must use the spelling ${PLANS_REL}/<name>${suffix} relative to --root`);
127
245
  if (opts.all && (opts.op.length > 0 || opts['ops-file'])) {
128
246
  return usage('--all judges the whole store and is exclusive of --op and --ops-file — run one lane or the other');
129
247
  }
130
- const root = resolve(cwd(), opts.root ?? '.');
131
- if (probe(root) !== 'dir') return usage(`--root "${opts.root ?? cwd()}" is not a directory`);
248
+ const root = resolve(workingDir, opts.root ?? '.');
249
+ if (probe(root) !== 'dir') return usage(`--root "${opts.root ?? workingDir}" is not a directory`);
250
+ const readPlans = () => readPlansInFlight(root).plans;
251
+ const plans = planLane ? readPlans() : undefined;
252
+ const plan = plans?.find(({ identity }) => identity === opts.plan);
253
+ if (planLane && !plan) return usage(`${opts.plan} is not an in-flight plan`);
254
+ if (plan && !plan.accepted) return usage(plan.result.findings
255
+ .map(({ line, code, message }) => `${plan.identity}:${line}: ${code} — ${message}`).join('\nspec-check: '));
132
256
  let specs = [...opts.op];
133
257
  if (opts['ops-file']) {
134
- const register = resolve(cwd(), opts['ops-file']);
258
+ const register = resolve(workingDir, opts['ops-file']);
135
259
  try {
136
260
  specs = [...specs, ...opsFileLines(read(register, 'utf8'))];
137
261
  } catch (err) {
138
- return usage(`--ops-file "${opts['ops-file']}" is unreadable — ${(err && err.message) || err}`);
262
+ return usage(`--ops-file "${opts['ops-file']}" is unreadable — ${causeOf(err)}`);
139
263
  }
140
264
  }
141
265
  let ops = [];
142
266
  if (!opts.all) {
143
- const parsed = parseSpecOps(specs);
267
+ const parsed = plan ? parsePlanSpecOps(plan.rows, isSweep, (sweep) => expandSweepPaths(root, [sweep])[sweep]) : parseSpecOps(specs);
144
268
  if (parsed.errors.length > 0) {
145
- return usage(parsed.errors.map((e) => `${e.code} — ${e.message}`).join('\nspec-check: '));
269
+ return usage(parsed.errors.map((e) => `${plan ? `${plan.identity}: ` : ''}${e.code} — ${e.message}`).join('\nspec-check: '));
146
270
  }
147
271
  ops = parsed.ops;
148
272
  }
149
- const decided = checkSpecs({ root, ops, all: Boolean(opts.all) }, { read: readRegularFileNoFollow, probe, realpath, list });
150
- return { code: decided.exit, stdout: decided.lines.join('\n'), stderr: '' };
273
+ if (plan) return checkPlan(root, plan.identity, ops, plans);
274
+ return showVerdict(checkSpecs({ root, ops, all: Boolean(opts.all), plans: readPlans }, storeIO));
275
+ };
276
+
277
+ const checkPlan = (root, plan, ops, plans) => {
278
+ const homePath = getRevisionHomePath(plan);
279
+ const files = new Map();
280
+ try {
281
+ proveRevisionHome(root, homePath, ops, files);
282
+ } catch (err) {
283
+ const path = err?.path ? repoPath(root, err.path) : homePath;
284
+ return { code: 1, stdout: `spec-check: REFUSE — revision home\n ${path}: revision-home — ${causeOf(err)}`, stderr: '' };
285
+ }
286
+ if (ops.length === 0) return { code: 0, stdout: 'spec-check: ACCEPT — the plan names no store document', stderr: '' };
287
+ const home = { plan, paths: [...files.keys()] };
288
+ return showVerdict(checkSpecs({ root, ops, plans, home }, overlayStore(root, files, ops)));
151
289
  };
152
290
 
153
291
  if (isDirectRun(import.meta.url)) {
@@ -18,12 +18,15 @@
18
18
  // source of the prefix, the navigator filename or the slug pattern. Pure strings in, ops out — the
19
19
  // filesystem belongs to spec-check.mjs. Dependency-free, Node >= 22.
20
20
 
21
+ import { sep } from 'node:path';
21
22
  import { SPEC_SCHEMA } from '../references/scripts/spec-schema/index.mjs';
22
23
 
23
24
  const STORE = SPEC_SCHEMA.storePrefix;
24
25
  const NAV = SPEC_SCHEMA.navigatorFile;
25
26
  const SUFFIX = '.md';
26
27
  const SEPARATOR = ':';
28
+ const HOME_SUFFIX = '.specs';
29
+ const PLAN_OP_VERBS = Object.freeze({ create: 'add', modify: 'modify', delete: 'remove' });
27
30
 
28
31
  export const SPEC_OPS_GRAMMAR = Object.freeze({
29
32
  verbs: Object.freeze(['add', 'modify', 'remove', 'rename']),
@@ -43,7 +46,7 @@ const VERBS = SPEC_OPS_GRAMMAR.verbs;
43
46
  // The ONE target judgement, ordered from the most literal defect to the most structural. The store
44
47
  // PREFIX is asked before the dot segments on purpose: `./docs/ai/specs/x.md` is not a store path
45
48
  // that needs normalizing, it is a path outside the store, and saying so is the honest refusal.
46
- const targetDefect = (target) => {
49
+ const targetDefect = (target, allowStoreRoot = false) => {
47
50
  if (target.includes('\\')) return { code: 'op-target', reason: 'a backslash is not a path separator here' };
48
51
  if (DRIVE_RE.test(target)) return { code: 'op-target', reason: 'a drive letter is not a repo-relative path' };
49
52
  if (target.startsWith('/')) return { code: 'op-target', reason: 'an absolute path is not repo-relative' };
@@ -54,7 +57,7 @@ const targetDefect = (target) => {
54
57
  return { code: 'op-target', reason: 'a dot segment is never resolved away — write the path as it is' };
55
58
  }
56
59
  if (!target.endsWith(SUFFIX)) return { code: 'op-target', reason: `a spec document is a ${SUFFIX} file` };
57
- if (target === SPEC_OPS_GRAMMAR.storeRoot) {
60
+ if (target === SPEC_OPS_GRAMMAR.storeRoot && !allowStoreRoot) {
58
61
  return { code: 'op-root', reason: 'the store root is the navigator, never an op target' };
59
62
  }
60
63
  const segments = target.slice(STORE.length).split('/');
@@ -94,7 +97,7 @@ const roleConflict = (roles) => SHAPES[[...roles].sort().join(',')] ?? 'two role
94
97
  // parseSpecOps(specs) -> { ops, errors }. Every op is judged, so one call names EVERY defect; any
95
98
  // error at all empties `ops` — a partially-understood change set would attest a post-state nobody
96
99
  // declared.
97
- export const parseSpecOps = (specs) => {
100
+ const parseOps = (specs, fromPlan) => {
98
101
  const errors = [];
99
102
  const ops = [];
100
103
  const seen = new Set();
@@ -130,7 +133,7 @@ export const parseSpecOps = (specs) => {
130
133
  errors.push({ code: 'op-grammar', message: `"${spec}" — rename takes <old>${SEPARATOR}<new>: exactly one separator "${SEPARATOR}"` });
131
134
  continue;
132
135
  }
133
- const defect = sides.map(targetDefect).find(Boolean);
136
+ const defect = sides.map((side) => targetDefect(side, fromPlan && verb === 'modify')).find(Boolean);
134
137
  if (defect) {
135
138
  errors.push({ code: defect.code, message: `"${spec}" — ${defect.reason}` });
136
139
  continue;
@@ -148,12 +151,32 @@ export const parseSpecOps = (specs) => {
148
151
  ops.push({ verb, target: payload });
149
152
  }
150
153
  }
151
- if (errors.length === 0 && ops.length === 0) {
154
+ if (!fromPlan && errors.length === 0 && ops.length === 0) {
152
155
  errors.push({ code: 'op-empty', message: 'no op to judge — name at least one --op or --ops-file entry, or run --all' });
153
156
  }
154
157
  return { ops: errors.length > 0 ? [] : ops, errors };
155
158
  };
156
159
 
160
+ export const parseSpecOps = (specs) => parseOps(specs, false);
161
+
162
+ const reachesStore = (path, isSweep, expand) => {
163
+ const segments = path.split('/');
164
+ const lead = segments.slice(0, segments.findIndex(isSweep)).join('/');
165
+ if (`${lead}/`.startsWith(STORE)) return true;
166
+ return (lead === '' || STORE.startsWith(`${lead}/`)) && expand(path).some((match) => match.startsWith(STORE));
167
+ };
168
+
169
+ export const parsePlanSpecOps = (rows, isSweep, expand) => {
170
+ const sweep = rows.find(({ path }) => isSweep(path) && reachesStore(path, isSweep, expand));
171
+ if (sweep) {
172
+ const message = `${sweep.id} ${sweep.path}: --plan judges one store document per row; name each store document in its own row`;
173
+ return { ops: [], errors: [{ code: 'op-sweep', message }] };
174
+ }
175
+ return parseOps(rows
176
+ .filter(({ path }) => path.startsWith(STORE) && path.endsWith(SUFFIX))
177
+ .map(({ verb, path }) => `${PLAN_OP_VERBS[verb]}=${path}`), true);
178
+ };
179
+
157
180
  // buildClosure(ops) -> [{ path, roles }] sorted: every op path PLUS the document that lists it.
158
181
  // A listing parent that is itself an op target keeps its op role; two ops under one parent name it
159
182
  // once; ops under different parents name both.
@@ -179,3 +202,49 @@ export const buildClosure = (ops) => {
179
202
  .map(([path, roles]) => ({ path, roles }))
180
203
  .sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));
181
204
  };
205
+
206
+ export const parsePendingModulePath = (claimed) => {
207
+ const kind = claimed.endsWith('/') ? 'dir' : 'file';
208
+ const path = kind === 'dir' ? claimed.slice(0, -1) : claimed;
209
+ const valid = path.split('/').every((segment) => segment !== '' && segment !== '.' && segment !== '..');
210
+ return valid ? { path, kind } : null;
211
+ };
212
+
213
+ const pendingModulePlan = ({ identity, rows }) => ({
214
+ identity,
215
+ creates: rows.filter(({ verb }) => verb === 'create').map(({ path }) => path),
216
+ });
217
+
218
+ export const selectPendingModulePlans = (plans = [], { path, status, home }) => {
219
+ const revision = home?.paths.includes(path);
220
+ if (!revision && status !== 'draft') return { plan: null, refusedPlans: [] };
221
+ const documentVerb = revision ? 'modify' : 'create';
222
+ const candidates = plans.filter(({ identity, rows }) => (!revision || identity === home.plan) &&
223
+ rows.some((row) => row.verb === documentVerb && row.path === path));
224
+ const accepted = candidates.filter(({ accepted }) => accepted === true);
225
+ return {
226
+ plan: accepted.length === 1 ? pendingModulePlan(accepted[0]) : null,
227
+ refusedPlans: candidates.filter(({ accepted }) => accepted === false).map(pendingModulePlan),
228
+ };
229
+ };
230
+
231
+ const isStrictDescendant = (path, directory) => path !== directory &&
232
+ path.startsWith(directory.endsWith(sep) ? directory : `${directory}${sep}`);
233
+
234
+ export const hasPendingModuleCover = (canonicalPath, kind, canonicalCreates) => {
235
+ const cover = canonicalCreates.filter((path) => kind === 'dir' ? isStrictDescendant(path, canonicalPath) : path === canonicalPath);
236
+ return cover.length > 0 && !cover.some((file) => canonicalCreates.some((path) => isStrictDescendant(file, path)));
237
+ };
238
+
239
+ export const getRevisionHomePath = (plan, storePath) => {
240
+ const home = `${plan.slice(0, -SUFFIX.length)}${HOME_SUFFIX}`;
241
+ if (storePath === undefined) return home;
242
+ return targetDefect(storePath, true) === null ? `${home}/${storePath.slice(STORE.length)}` : null;
243
+ };
244
+
245
+ export const getRevisionStorePath = (home, homePath) => {
246
+ const prefix = `${home}/`;
247
+ if (!homePath.startsWith(prefix)) return null;
248
+ const target = `${STORE}${homePath.slice(prefix.length)}`;
249
+ return targetDefect(target, true) === null ? target : null;
250
+ };