cyber-sdd 0.7.0 → 0.7.2

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 (150) hide show
  1. package/.claude-plugin/plugin.json +1 -2
  2. package/.codex-plugin/plugin.json +1 -2
  3. package/CHANGELOG.md +320 -0
  4. package/agents/sdd-scanner.md +1 -1
  5. package/package.json +11 -12
  6. package/plugin.json +55 -0
  7. package/skills/align-spec/SKILL.md +1 -1
  8. package/skills/align-spec/scripts/align-spec.mjs +6755 -12
  9. package/skills/blast-estimate/README.md +3 -3
  10. package/skills/blast-estimate/scripts/blast-estimate.mjs +601 -12
  11. package/skills/check-field-mandates/scripts/check-field-mandates.mjs +253 -12
  12. package/skills/check-partition-quality/scripts/check-partition-quality.mjs +235 -12
  13. package/skills/check-plan-safety/SKILL.md +2 -3
  14. package/skills/check-plan-safety/scripts/check-plan-safety.mjs +109 -12
  15. package/skills/check-plugin-manifests/scripts/check-plugin-manifests.mjs +250 -12
  16. package/skills/check-project-specs/SKILL.md +1 -1
  17. package/skills/check-project-specs/scripts/check-project-specs.mjs +593 -12
  18. package/skills/check-retired-terms/SKILL.md +2 -3
  19. package/skills/check-retired-terms/scripts/check-retired-terms.mjs +186 -12
  20. package/skills/check-scenario-overlap/SKILL.md +1 -2
  21. package/skills/check-scenario-overlap/scripts/check-scenario-overlap.mjs +177 -12
  22. package/skills/check-spec-references/SKILL.md +2 -2
  23. package/skills/check-spec-references/scripts/check-spec-references.mjs +287 -12
  24. package/skills/check-spec-structure/SKILL.md +1 -2
  25. package/skills/check-spec-structure/scripts/check-spec-structure.mjs +243 -12
  26. package/skills/collision-ladder/README.md +2 -2
  27. package/skills/collision-ladder/scripts/collision-ladder.mjs +7047 -12
  28. package/skills/combat-log-governance/SKILL.md +1 -1
  29. package/skills/concept-index/SKILL.md +1 -1
  30. package/skills/concept-index/scripts/concept-index.mjs +183 -12
  31. package/skills/discover-plans/README.md +3 -3
  32. package/skills/discover-plans/SKILL.md +1 -1
  33. package/skills/discover-plans/scripts/discover-plans.mjs +137 -12
  34. package/skills/discover-specs/README.md +3 -3
  35. package/skills/discover-specs/SKILL.md +1 -1
  36. package/skills/discover-specs/scripts/discover-specs.mjs +321 -12
  37. package/skills/doctrine-loop/SKILL.md +1 -1
  38. package/skills/gate-validation-governance/SKILL.md +1 -1
  39. package/skills/init/README.md +2 -2
  40. package/skills/init/scripts/wire-statusline.mjs +168 -12
  41. package/skills/manage-ignore/README.md +3 -3
  42. package/skills/manage-ignore/SKILL.md +1 -2
  43. package/skills/manage-ignore/scripts/manage-ignore.mjs +285 -12
  44. package/skills/manage-scenario-bridge/README.md +3 -3
  45. package/skills/manage-scenario-bridge/SKILL.md +1 -1
  46. package/skills/manage-scenario-bridge/scripts/manage-scenario-bridge.mjs +239 -12
  47. package/skills/manage-spec-anchors/README.md +3 -3
  48. package/skills/manage-spec-anchors/SKILL.md +1 -1
  49. package/skills/manage-spec-anchors/scripts/manage-spec-anchors.mjs +310 -12
  50. package/skills/mission-graph/README.md +2 -2
  51. package/skills/mission-graph/SKILL.md +1 -1
  52. package/skills/mission-graph/scripts/mission-graph.mjs +1040 -12
  53. package/skills/pause-mission/SKILL.md +1 -1
  54. package/skills/place-node/SKILL.md +2 -2
  55. package/skills/place-node/scripts/place-node.mjs +117 -12
  56. package/skills/plan-retirement/README.md +2 -2
  57. package/skills/plan-retirement/scripts/retire-plans.mjs +123 -12
  58. package/skills/resolve-governances/README.md +3 -3
  59. package/skills/resolve-governances/SKILL.md +1 -1
  60. package/skills/resolve-governances/scripts/resolve-governances.mjs +352 -12
  61. package/skills/resolve-tracking/SKILL.md +1 -1
  62. package/skills/resolve-tracking/scripts/resolve-tracking.mjs +152 -12
  63. package/skills/scaffold-project-spec/SKILL.md +1 -1
  64. package/skills/spec-gate/README.md +12 -9
  65. package/skills/spec-gate/SKILL.md +2 -2
  66. package/skills/spec-gate/scripts/check-spec-state.mjs +422 -12
  67. package/skills/spec-gate/scripts/check-suite.mjs +6500 -12
  68. package/skills/spec-gate/scripts/classify-edit-class.mjs +6579 -12
  69. package/skills/spec-producer-governance/SKILL.md +2 -2
  70. package/skills/start-mission/SKILL.md +1 -1
  71. package/skills/suite-format-governance/README.md +1 -1
  72. package/skills/suite-format-governance/SKILL.md +1 -1
  73. package/skills/touch-set-correction/README.md +5 -5
  74. package/skills/touch-set-correction/SKILL.md +1 -1
  75. package/skills/touch-set-correction/scripts/touch-set-correction.mjs +6663 -12
  76. package/skills/verify-scenarios/README.md +6 -6
  77. package/skills/verify-scenarios/scripts/verify-scenarios.mjs +6539 -12
  78. package/.plugin/pins.json +0 -3
  79. package/.plugin/plugin.json +0 -19
  80. package/dist/align-spec/scripts/align-spec.js +0 -102
  81. package/dist/check-project-specs/scripts/check-project-specs.js +0 -312
  82. package/dist/check-scenario-overlap/scripts/check-scenario-overlap.js +0 -175
  83. package/dist/check-spec-references/scripts/check-spec-references.js +0 -285
  84. package/dist/check-spec-structure/scripts/check-spec-structure.js +0 -241
  85. package/dist/concept-index/scripts/concept-index.js +0 -181
  86. package/dist/discover-specs/scripts/discover-specs.js +0 -318
  87. package/dist/spec-gate/scripts/check-spec-state.js +0 -420
  88. package/dist/spec-gate/scripts/check-suite.js +0 -317
  89. package/dist/spec-gate/scripts/classify-edit-class.js +0 -263
  90. package/dist/spec-gate/vendor/gherkin-cli.js +0 -6369
  91. package/skills/align-spec/scripts/align-spec.bundle.mjs +0 -6753
  92. package/skills/align-spec/scripts/align-spec.mts +0 -188
  93. package/skills/blast-estimate/scripts/blast-estimate.bundle.mjs +0 -593
  94. package/skills/blast-estimate/scripts/blast-estimate.mts +0 -586
  95. package/skills/check-field-mandates/scripts/check-field-mandates.bundle.mjs +0 -251
  96. package/skills/check-field-mandates/scripts/check-field-mandates.mts +0 -337
  97. package/skills/check-partition-quality/scripts/check-partition-quality.bundle.mjs +0 -233
  98. package/skills/check-partition-quality/scripts/check-partition-quality.mts +0 -338
  99. package/skills/check-plan-safety/scripts/check-plan-safety.bundle.mjs +0 -107
  100. package/skills/check-plan-safety/scripts/check-plan-safety.mts +0 -148
  101. package/skills/check-plugin-manifests/scripts/check-plugin-manifests.bundle.mjs +0 -248
  102. package/skills/check-plugin-manifests/scripts/check-plugin-manifests.mts +0 -303
  103. package/skills/check-project-specs/scripts/check-project-specs.bundle.mjs +0 -584
  104. package/skills/check-project-specs/scripts/check-project-specs.mts +0 -370
  105. package/skills/check-retired-terms/scripts/check-retired-terms.bundle.mjs +0 -184
  106. package/skills/check-retired-terms/scripts/check-retired-terms.mts +0 -293
  107. package/skills/check-scenario-overlap/scripts/check-scenario-overlap.bundle.mjs +0 -175
  108. package/skills/check-scenario-overlap/scripts/check-scenario-overlap.mts +0 -250
  109. package/skills/check-spec-references/scripts/check-spec-references.bundle.mjs +0 -285
  110. package/skills/check-spec-references/scripts/check-spec-references.mts +0 -422
  111. package/skills/check-spec-structure/scripts/check-spec-structure.bundle.mjs +0 -241
  112. package/skills/check-spec-structure/scripts/check-spec-structure.mts +0 -347
  113. package/skills/collision-ladder/scripts/collision-ladder.bundle.mjs +0 -7041
  114. package/skills/collision-ladder/scripts/collision-ladder.mts +0 -662
  115. package/skills/concept-index/scripts/concept-index.bundle.mjs +0 -181
  116. package/skills/concept-index/scripts/concept-index.mts +0 -246
  117. package/skills/discover-plans/scripts/discover-plans.bundle.mjs +0 -135
  118. package/skills/discover-plans/scripts/discover-plans.mts +0 -215
  119. package/skills/discover-specs/scripts/discover-specs.bundle.mjs +0 -319
  120. package/skills/discover-specs/scripts/discover-specs.mts +0 -420
  121. package/skills/init/scripts/wire-statusline.bundle.mjs +0 -166
  122. package/skills/init/scripts/wire-statusline.mts +0 -279
  123. package/skills/manage-ignore/scripts/manage-ignore.bundle.mjs +0 -244
  124. package/skills/manage-ignore/scripts/manage-ignore.mts +0 -297
  125. package/skills/manage-scenario-bridge/scripts/manage-scenario-bridge.bundle.mjs +0 -237
  126. package/skills/manage-scenario-bridge/scripts/manage-scenario-bridge.mts +0 -159
  127. package/skills/manage-spec-anchors/scripts/manage-spec-anchors.bundle.mjs +0 -308
  128. package/skills/manage-spec-anchors/scripts/manage-spec-anchors.mts +0 -331
  129. package/skills/mission-graph/scripts/mission-graph.bundle.mjs +0 -1038
  130. package/skills/mission-graph/scripts/mission-graph.mts +0 -1333
  131. package/skills/place-node/scripts/place-node.bundle.mjs +0 -115
  132. package/skills/place-node/scripts/place-node.mts +0 -158
  133. package/skills/plan-retirement/scripts/retire-plans.bundle.mjs +0 -121
  134. package/skills/plan-retirement/scripts/retire-plans.mts +0 -205
  135. package/skills/resolve-governances/scripts/resolve-governances.bundle.mjs +0 -350
  136. package/skills/resolve-governances/scripts/resolve-governances.mts +0 -518
  137. package/skills/resolve-tracking/scripts/resolve-tracking.bundle.mjs +0 -150
  138. package/skills/resolve-tracking/scripts/resolve-tracking.mts +0 -214
  139. package/skills/spec-gate/scripts/check-spec-state.bundle.mjs +0 -420
  140. package/skills/spec-gate/scripts/check-spec-state.mts +0 -637
  141. package/skills/spec-gate/scripts/check-suite.bundle.mjs +0 -6498
  142. package/skills/spec-gate/scripts/check-suite.mts +0 -538
  143. package/skills/spec-gate/scripts/classify-edit-class.bundle.mjs +0 -6577
  144. package/skills/spec-gate/scripts/classify-edit-class.mts +0 -414
  145. package/skills/spec-gate/vendor/gherkin-cli.d.mts +0 -2
  146. package/skills/spec-gate/vendor/gherkin-cli.mjs +0 -6545
  147. package/skills/touch-set-correction/scripts/touch-set-correction.bundle.mjs +0 -6655
  148. package/skills/touch-set-correction/scripts/touch-set-correction.mts +0 -429
  149. package/skills/verify-scenarios/scripts/verify-scenarios.bundle.mjs +0 -6537
  150. package/skills/verify-scenarios/scripts/verify-scenarios.mts +0 -470
@@ -34,11 +34,11 @@ alone, which matched almost nothing on a real tree. It stays **mention-based** b
34
34
  dependency is `ssa-lowering` / `collision-ladder` territory.
35
35
 
36
36
  - **Skill contract:** [`SKILL.md`](./SKILL.md)
37
- - **Script:** [`scripts/blast-estimate.mts`](./scripts/blast-estimate.mts)
38
- - **Tests:** [`scripts/blast-estimate.test.mts`](./scripts/blast-estimate.test.mts) (`node:test`) —
37
+ - **Script:** [`scripts/blast-estimate.mjs`](./scripts/blast-estimate.mjs)
38
+ - **Tests:** [`src/blast-estimate/blast-estimate.test.mts`](../../src/blast-estimate/blast-estimate.test.mts) (`node:test`) —
39
39
  one test per frozen scenario, titled `scenario: <verbatim frozen scenario name>`.
40
40
  - **Live-corpus smoke check:**
41
- [`scripts/blast-estimate.smoke.test.mts`](./scripts/blast-estimate.smoke.test.mts) — **not** bound
41
+ [`src/blast-estimate/blast-estimate.smoke.test.mts`](../../src/blast-estimate/blast-estimate.smoke.test.mts) — **not** bound
42
42
  to any frozen scenario. The frozen suite mandates constructed corpora, so it is structurally blind
43
43
  to whether the engine measures real reach on a real tree; three defects reached an impl gate
44
44
  green-on-all-21 for exactly that reason. This asserts live properties (never magic numbers) and is
@@ -1,12 +1,601 @@
1
- // Launcher for the engine of the same name. Run it as `node <skill>/scripts/<engine>.mjs`.
2
- // A checkout runs the .mts source. An npm install keeps the skill under node_modules, where Node
3
- // will not strip types, so it runs the self-contained bundle built for the package.
4
- import { spawnSync } from 'node:child_process'
5
- import { fileURLToPath } from 'node:url'
6
-
7
- const self = fileURLToPath(import.meta.url)
8
- const installed = /[\\/]node_modules[\\/]/.test(self)
9
- const target = self.replace(/\.mjs$/, installed ? '.bundle.mjs' : '.mts')
10
- const run = spawnSync(process.execPath, [...process.execArgv, target, ...process.argv.slice(2)], { stdio: 'inherit' })
11
- if (run.error) throw run.error
12
- process.exitCode = run.status ?? 1
1
+ #!/usr/bin/env node
2
+ // Compiled by `universal-plugin plugin build` from src/blast-estimate/blast-estimate.mts. Edit the source, not this file.
3
+ globalThis.__SKILL_SCRIPT__ = {"package":null,"bin":null,"version":"0.7.2","entry":"skills/blast-estimate/scripts/blast-estimate.mjs","commands":{}};
4
+ import { readFileSync, readdirSync, realpathSync, statSync } from "node:fs";
5
+ import { dirname, join, relative } from "node:path";
6
+ import { fileURLToPath, pathToFileURL } from "node:url";
7
+ import { execFileSync } from "node:child_process";
8
+ //#region src/sibling-engine.mts
9
+ /** The path of `<skill>/<engine>` for an engine running from the file `here`. */
10
+ function siblingEngine(here, skill, engine) {
11
+ if (here.endsWith(".mts")) return join(dirname(here), "..", skill, `${engine}.mts`);
12
+ return join(dirname(here), "..", "..", skill, "scripts", `${engine}.mjs`);
13
+ }
14
+ //#endregion
15
+ //#region src/vendor/gherkin-cli.mjs
16
+ var TokenType;
17
+ (function(TokenType) {
18
+ TokenType[TokenType["None"] = 0] = "None";
19
+ TokenType[TokenType["EOF"] = 1] = "EOF";
20
+ TokenType[TokenType["Empty"] = 2] = "Empty";
21
+ TokenType[TokenType["Comment"] = 3] = "Comment";
22
+ TokenType[TokenType["TagLine"] = 4] = "TagLine";
23
+ TokenType[TokenType["FeatureLine"] = 5] = "FeatureLine";
24
+ TokenType[TokenType["RuleLine"] = 6] = "RuleLine";
25
+ TokenType[TokenType["BackgroundLine"] = 7] = "BackgroundLine";
26
+ TokenType[TokenType["ScenarioLine"] = 8] = "ScenarioLine";
27
+ TokenType[TokenType["ExamplesLine"] = 9] = "ExamplesLine";
28
+ TokenType[TokenType["StepLine"] = 10] = "StepLine";
29
+ TokenType[TokenType["DocStringSeparator"] = 11] = "DocStringSeparator";
30
+ TokenType[TokenType["TableRow"] = 12] = "TableRow";
31
+ TokenType[TokenType["Language"] = 13] = "Language";
32
+ TokenType[TokenType["Other"] = 14] = "Other";
33
+ })(TokenType || (TokenType = {}));
34
+ var RuleType;
35
+ (function(RuleType) {
36
+ RuleType[RuleType["None"] = 0] = "None";
37
+ RuleType[RuleType["_EOF"] = 1] = "_EOF";
38
+ RuleType[RuleType["_Empty"] = 2] = "_Empty";
39
+ RuleType[RuleType["_Comment"] = 3] = "_Comment";
40
+ RuleType[RuleType["_TagLine"] = 4] = "_TagLine";
41
+ RuleType[RuleType["_FeatureLine"] = 5] = "_FeatureLine";
42
+ RuleType[RuleType["_RuleLine"] = 6] = "_RuleLine";
43
+ RuleType[RuleType["_BackgroundLine"] = 7] = "_BackgroundLine";
44
+ RuleType[RuleType["_ScenarioLine"] = 8] = "_ScenarioLine";
45
+ RuleType[RuleType["_ExamplesLine"] = 9] = "_ExamplesLine";
46
+ RuleType[RuleType["_StepLine"] = 10] = "_StepLine";
47
+ RuleType[RuleType["_DocStringSeparator"] = 11] = "_DocStringSeparator";
48
+ RuleType[RuleType["_TableRow"] = 12] = "_TableRow";
49
+ RuleType[RuleType["_Language"] = 13] = "_Language";
50
+ RuleType[RuleType["_Other"] = 14] = "_Other";
51
+ RuleType[RuleType["GherkinDocument"] = 15] = "GherkinDocument";
52
+ RuleType[RuleType["Feature"] = 16] = "Feature";
53
+ RuleType[RuleType["FeatureHeader"] = 17] = "FeatureHeader";
54
+ RuleType[RuleType["Rule"] = 18] = "Rule";
55
+ RuleType[RuleType["RuleHeader"] = 19] = "RuleHeader";
56
+ RuleType[RuleType["Background"] = 20] = "Background";
57
+ RuleType[RuleType["ScenarioDefinition"] = 21] = "ScenarioDefinition";
58
+ RuleType[RuleType["Scenario"] = 22] = "Scenario";
59
+ RuleType[RuleType["ExamplesDefinition"] = 23] = "ExamplesDefinition";
60
+ RuleType[RuleType["Examples"] = 24] = "Examples";
61
+ RuleType[RuleType["ExamplesTable"] = 25] = "ExamplesTable";
62
+ RuleType[RuleType["Step"] = 26] = "Step";
63
+ RuleType[RuleType["StepArg"] = 27] = "StepArg";
64
+ RuleType[RuleType["DataTable"] = 28] = "DataTable";
65
+ RuleType[RuleType["DocString"] = 29] = "DocString";
66
+ RuleType[RuleType["Tags"] = 30] = "Tags";
67
+ RuleType[RuleType["DescriptionHelper"] = 31] = "DescriptionHelper";
68
+ RuleType[RuleType["Description"] = 32] = "Description";
69
+ })(RuleType || (RuleType = {}));
70
+ var AttachmentContentEncoding;
71
+ (function(AttachmentContentEncoding) {
72
+ AttachmentContentEncoding["IDENTITY"] = "IDENTITY";
73
+ AttachmentContentEncoding["BASE64"] = "BASE64";
74
+ })(AttachmentContentEncoding || (AttachmentContentEncoding = {}));
75
+ var HookType;
76
+ (function(HookType) {
77
+ HookType["BEFORE_TEST_RUN"] = "BEFORE_TEST_RUN";
78
+ HookType["AFTER_TEST_RUN"] = "AFTER_TEST_RUN";
79
+ HookType["BEFORE_TEST_CASE"] = "BEFORE_TEST_CASE";
80
+ HookType["AFTER_TEST_CASE"] = "AFTER_TEST_CASE";
81
+ HookType["BEFORE_TEST_STEP"] = "BEFORE_TEST_STEP";
82
+ HookType["AFTER_TEST_STEP"] = "AFTER_TEST_STEP";
83
+ })(HookType || (HookType = {}));
84
+ var PickleStepType;
85
+ (function(PickleStepType) {
86
+ PickleStepType["UNKNOWN"] = "Unknown";
87
+ PickleStepType["CONTEXT"] = "Context";
88
+ PickleStepType["ACTION"] = "Action";
89
+ PickleStepType["OUTCOME"] = "Outcome";
90
+ })(PickleStepType || (PickleStepType = {}));
91
+ var SourceMediaType;
92
+ (function(SourceMediaType) {
93
+ SourceMediaType["TEXT_X_CUCUMBER_GHERKIN_PLAIN"] = "text/x.cucumber.gherkin+plain";
94
+ SourceMediaType["TEXT_X_CUCUMBER_GHERKIN_MARKDOWN"] = "text/x.cucumber.gherkin+markdown";
95
+ })(SourceMediaType || (SourceMediaType = {}));
96
+ var StepDefinitionPatternType;
97
+ (function(StepDefinitionPatternType) {
98
+ StepDefinitionPatternType["CUCUMBER_EXPRESSION"] = "CUCUMBER_EXPRESSION";
99
+ StepDefinitionPatternType["REGULAR_EXPRESSION"] = "REGULAR_EXPRESSION";
100
+ })(StepDefinitionPatternType || (StepDefinitionPatternType = {}));
101
+ var StepKeywordType;
102
+ (function(StepKeywordType) {
103
+ StepKeywordType["UNKNOWN"] = "Unknown";
104
+ StepKeywordType["CONTEXT"] = "Context";
105
+ StepKeywordType["ACTION"] = "Action";
106
+ StepKeywordType["OUTCOME"] = "Outcome";
107
+ StepKeywordType["CONJUNCTION"] = "Conjunction";
108
+ })(StepKeywordType || (StepKeywordType = {}));
109
+ var TestStepResultStatus;
110
+ (function(TestStepResultStatus) {
111
+ TestStepResultStatus["UNKNOWN"] = "UNKNOWN";
112
+ TestStepResultStatus["PASSED"] = "PASSED";
113
+ TestStepResultStatus["SKIPPED"] = "SKIPPED";
114
+ TestStepResultStatus["PENDING"] = "PENDING";
115
+ TestStepResultStatus["UNDEFINED"] = "UNDEFINED";
116
+ TestStepResultStatus["AMBIGUOUS"] = "AMBIGUOUS";
117
+ TestStepResultStatus["FAILED"] = "FAILED";
118
+ })(TestStepResultStatus || (TestStepResultStatus = {}));
119
+ var KeywordPrefix;
120
+ (function(KeywordPrefix) {
121
+ KeywordPrefix["BULLET"] = "^(\\s*[*+-]\\s*)";
122
+ KeywordPrefix["HEADER"] = "^(#{1,6}\\s)";
123
+ })(KeywordPrefix || (KeywordPrefix = {}));
124
+ StepKeywordType.UNKNOWN, PickleStepType.UNKNOWN, StepKeywordType.CONTEXT, PickleStepType.CONTEXT, StepKeywordType.ACTION, PickleStepType.ACTION, StepKeywordType.OUTCOME, PickleStepType.OUTCOME, StepKeywordType.CONJUNCTION;
125
+ //#endregion
126
+ //#region src/touch-set-correction/touch-set-correction.mts
127
+ function stripTrailingSlash$1(root) {
128
+ return root.endsWith("/") ? root.slice(0, -1) : root;
129
+ }
130
+ /**
131
+ * fileToNode — capability-first work-area recovery. For each project's root, if `path` sits under
132
+ * `root/`, the CAPABILITY is the first path segment after the matched root; the node is
133
+ * `project/capability`. Matches the LONGEST matching root prefix across every project + root (so a
134
+ * deeper root like `plugins/sdd/skills` wins over a shallower `plugins/sdd`, when both are
135
+ * declared). Returns null when no root matches — the file is unmapped.
136
+ */
137
+ function fileToNode(path, projects) {
138
+ let best = null;
139
+ for (const p of projects) for (const rawRoot of p.roots) {
140
+ const root = stripTrailingSlash$1(rawRoot);
141
+ const prefix = root === "" ? "" : `${root}/`;
142
+ if (prefix === "" || !path.startsWith(prefix)) continue;
143
+ const capability = path.slice(prefix.length).split("/")[0];
144
+ if (!capability) continue;
145
+ if (best === null || prefix.length > best.rootLen) best = {
146
+ project: p.project,
147
+ capability,
148
+ rootLen: prefix.length
149
+ };
150
+ }
151
+ return best ? `${best.project}/${best.capability}` : null;
152
+ }
153
+ const HERE = fileURLToPath(import.meta.url);
154
+ siblingEngine(HERE, "resolve-governances", "resolve-governances");
155
+ const DISCOVER_SPECS_PATH = siblingEngine(HERE, "discover-specs", "discover-specs");
156
+ /** Best-effort project-layout discovery via `discover-specs`: each project's spec-path plus an
157
+ * impl-root convention (`plugins/<p>` → also `plugins/<p>/skills`; `packages/<p>` → also
158
+ * `packages/<p>/src`; else the project-path itself). `--layout` (CLI) overrides this entirely. On
159
+ * any failure returns []. */
160
+ function discoverLayouts(root, cwd) {
161
+ try {
162
+ const out = execFileSync("node", [
163
+ DISCOVER_SPECS_PATH,
164
+ "--root",
165
+ root,
166
+ "--format",
167
+ "json"
168
+ ], {
169
+ encoding: "utf8",
170
+ cwd,
171
+ stdio: [
172
+ "ignore",
173
+ "pipe",
174
+ "ignore"
175
+ ]
176
+ });
177
+ return JSON.parse(out).map((s) => {
178
+ const roots = [s.path];
179
+ const projectPath = s.projectPath ?? "";
180
+ const pluginsMatch = /^plugins\/([^/]+)$/.exec(projectPath);
181
+ const packagesMatch = /^packages\/([^/]+)$/.exec(projectPath);
182
+ if (pluginsMatch) roots.push(`plugins/${pluginsMatch[1]}/skills`);
183
+ else if (packagesMatch) roots.push(`packages/${packagesMatch[1]}/src`);
184
+ else if (projectPath) roots.push(projectPath);
185
+ return {
186
+ project: s.name,
187
+ roots
188
+ };
189
+ });
190
+ } catch {
191
+ return [];
192
+ }
193
+ }
194
+ if (process.argv[1] && false);
195
+ //#endregion
196
+ //#region src/blast-estimate/blast-estimate.mts
197
+ const SKIP_DIRS = /* @__PURE__ */ new Set([
198
+ "node_modules",
199
+ ".git",
200
+ "dist",
201
+ ".turbo",
202
+ ".next",
203
+ "coverage"
204
+ ]);
205
+ const SENSITIVE_PATHS_FILE = ".agents/sdd/sensitive-paths.toml";
206
+ /** Every repo-relative file path under `dir` (recursively), skipping build/vendor noise. Paths are
207
+ * made relative with `path.relative`, never string-sliced: `join('.', x)` normalizes the `./` away,
208
+ * so slicing by `root.length` silently corrupts every path under a RELATIVE root (`--root .`, the
209
+ * CLI's default) while working fine under an absolute one. */
210
+ function walkFiles(dir, root, out) {
211
+ let entries;
212
+ try {
213
+ entries = readdirSync(dir, { withFileTypes: true });
214
+ } catch {
215
+ return;
216
+ }
217
+ for (const entry of entries) {
218
+ if (SKIP_DIRS.has(entry.name)) continue;
219
+ const full = join(dir, entry.name);
220
+ if (entry.isDirectory()) walkFiles(full, root, out);
221
+ else out.push(relative(root, full).replace(/\\/g, "/"));
222
+ }
223
+ }
224
+ /**
225
+ * discoverWorkAreas — the corpus's work areas, grouped by node id, over the DECLARED layouts. Walks
226
+ * every root of every project, maps each file through touch-set-correction's pure `fileToNode`, and
227
+ * groups by the node it names. Because a node's roots include BOTH its spec root and its impl root,
228
+ * one node's file set spans both trees — which is exactly what makes fan-in measure real dependency
229
+ * rather than spec-prose cross-reference. A file that maps to no node (`fileToNode` returns null —
230
+ * the existing "unmapped" concept) is dropped from the area map, never invented into an atom.
231
+ *
232
+ * Values are repo-relative paths; `root` is the repo root they are resolved against.
233
+ */
234
+ function discoverWorkAreas(layouts, root) {
235
+ const byNode = /* @__PURE__ */ new Map();
236
+ const seen = /* @__PURE__ */ new Set();
237
+ for (const layout of layouts) for (const rawRoot of layout.roots) {
238
+ const rel = rawRoot.replace(/\/+$/, "");
239
+ const files = [];
240
+ walkFiles(join(root, rel), root, files);
241
+ for (const path of files) {
242
+ if (seen.has(path)) continue;
243
+ seen.add(path);
244
+ const node = fileToNode(path, layouts);
245
+ if (node === null) continue;
246
+ const bucket = byNode.get(node);
247
+ if (bucket) bucket.push(path);
248
+ else byNode.set(node, [path]);
249
+ }
250
+ }
251
+ return byNode;
252
+ }
253
+ function escapeRegExp(s) {
254
+ return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
255
+ }
256
+ /** Left boundary: a reference must not start mid-token. */
257
+ const LB = "(?:^|[^\\w/:.-])";
258
+ function stripTrailingSlash(s) {
259
+ return s.replace(/\/+$/, "");
260
+ }
261
+ /** The reference forms that name `nodeId` unambiguously from ANYWHERE (each is project-qualified):
262
+ * the bare id (`sdd/spec-gate`), the skill-style ref (`sdd:spec-gate`), and a path under any of the
263
+ * project's declared roots, at any nesting depth (`plugins/sdd/skills/spec-gate/`,
264
+ * `.agents/specs/sdd/authoring/spec-gate/`). */
265
+ function globalReferencePattern(project, capability, roots) {
266
+ const alts = [`${LB}${escapeRegExp(`${project}/${capability}`)}(?![\\w-])`, `${LB}${escapeRegExp(`${project}:${capability}`)}(?![\\w-])`];
267
+ for (const root of roots) alts.push(`${escapeRegExp(stripTrailingSlash(root))}/(?:[\\w.-]+/)*${escapeRegExp(capability)}/`);
268
+ return new RegExp(alts.join("|"));
269
+ }
270
+ /** The relative-link form (`../spec-gate/`, `../../authoring/spec-gate/`) — a sibling-node link. It
271
+ * carries no project, so it is only counted from a file in the SAME project; otherwise two projects
272
+ * sharing a capability name (`manage`, `design`) would cross-credit each other's fan-in. */
273
+ function relativeReferencePattern(capability) {
274
+ return new RegExp(`(?:\\.\\./)+(?:[\\w.-]+/)*${escapeRegExp(capability)}/`);
275
+ }
276
+ function projectRoots(project, layouts) {
277
+ return layouts.filter((l) => l.project === project).flatMap((l) => l.roots);
278
+ }
279
+ /**
280
+ * computeFanInMap — centrality for the requested areas: area A's fan-in is the number of OTHER areas
281
+ * holding at least one file that REFERENCES A in any of the forms the corpus actually uses (see
282
+ * `globalReferencePattern` / `relativeReferencePattern`). Because a node's file set spans its spec
283
+ * AND impl roots, a reference from an implementation file counts exactly as spec prose does — fan-in
284
+ * measures the project's real lean on an area. An area's own files never count toward its own fan-in.
285
+ *
286
+ * `targets` defaults to every known area; passing only the areas actually being scored keeps the CLI
287
+ * cheap (a one-area touch-set costs 1 pattern × N files instead of 229 × N). Each file is read at
288
+ * most once, and an owner already credited for a target is skipped.
289
+ */
290
+ function computeFanInMap(byNode, root, layouts, targets) {
291
+ const ids = targets ?? [...byNode.keys()];
292
+ const specs = ids.map((id) => {
293
+ const slash = id.indexOf("/");
294
+ const project = id.slice(0, slash);
295
+ const capability = id.slice(slash + 1);
296
+ return {
297
+ id,
298
+ project,
299
+ global: globalReferencePattern(project, capability, projectRoots(project, layouts)),
300
+ relative: relativeReferencePattern(capability)
301
+ };
302
+ });
303
+ const referencers = new Map(ids.map((id) => [id, /* @__PURE__ */ new Set()]));
304
+ for (const [owner, files] of byNode) {
305
+ const ownerProject = projectOf(owner);
306
+ for (const rel of files) {
307
+ let text;
308
+ try {
309
+ text = readFileSync(join(root, rel), "utf8");
310
+ } catch {
311
+ continue;
312
+ }
313
+ for (const spec of specs) {
314
+ if (spec.id === owner) continue;
315
+ const seen = referencers.get(spec.id);
316
+ if (seen?.has(owner)) continue;
317
+ if (spec.global.test(text) || ownerProject === spec.project && spec.relative.test(text)) seen?.add(owner);
318
+ }
319
+ }
320
+ }
321
+ return new Map(ids.map((id) => [id, referencers.get(id)?.size ?? 0]));
322
+ }
323
+ /**
324
+ * Parses the opt-in `.agents/sdd/sensitive-paths.toml`: a `sensitive = [ "id", ... ]` string array.
325
+ *
326
+ * LINE-anchored and lenient, matching manage-spec-anchors' `anchors = [ … ]` parser byte for byte in
327
+ * shape — a leading comment, a trailing comment, or a neighbouring key are ordinary TOML and must
328
+ * parse. An earlier whole-file-anchored regex rejected all three, so a perfectly valid file that
329
+ * marked an area computed no level at all.
330
+ *
331
+ * An EMPTY file is `[]` (a real "nothing marked" declaration). A file with no `sensitive` array at
332
+ * all throws — that is genuinely malformed, and an unreadable marking is not evidence of no
333
+ * markings.
334
+ */
335
+ function parseSensitivePaths(text) {
336
+ if (text.trim() === "") return [];
337
+ const m = /(^|\n)\s*sensitive\s*=\s*\[([\s\S]*?)\]/.exec(text);
338
+ if (!m) throw new Error("expected a `sensitive = [...]` array");
339
+ const out = [];
340
+ for (const q of m[2].matchAll(/"([^"]*)"|'([^']*)'/g)) out.push((q[1] ?? q[2]).trim());
341
+ return out.filter((s) => s !== "");
342
+ }
343
+ /** Reads the opt-in sensitive-paths file. **Absent** (ENOENT) = `{ ok: true, marked: [] }` — no area
344
+ * is sensitive, and that is NOT an error. Anything else — present-but-unparseable, unreadable
345
+ * (permissions), or not a regular file — = `{ ok: false, error }`, and the caller computes no level.
346
+ *
347
+ * ONLY ENOENT is benign. A bare `catch` here would swallow EACCES and a directory-at-the-path into
348
+ * "no markings", which fails in the DANGEROUS direction: the estimate silently UNDER-calls blast on
349
+ * exactly the areas a project took the trouble to mark. A read that cannot classify must fail loud,
350
+ * never default to the safe-looking answer — the same duty the absent-vs-unparseable scenarios draw:
351
+ * an unreadable marking is not evidence of no markings. */
352
+ function readSensitivePaths(corpusRoot) {
353
+ const file = join(corpusRoot, SENSITIVE_PATHS_FILE);
354
+ let text;
355
+ try {
356
+ if (!statSync(file).isFile()) return {
357
+ ok: false,
358
+ error: `${SENSITIVE_PATHS_FILE} is not a regular file`
359
+ };
360
+ text = readFileSync(file, "utf8");
361
+ } catch (err) {
362
+ if (err.code === "ENOENT") return {
363
+ ok: true,
364
+ marked: []
365
+ };
366
+ return {
367
+ ok: false,
368
+ error: `${SENSITIVE_PATHS_FILE} is unreadable: ${err.message}`
369
+ };
370
+ }
371
+ try {
372
+ return {
373
+ ok: true,
374
+ marked: parseSensitivePaths(text)
375
+ };
376
+ } catch (err) {
377
+ return {
378
+ ok: false,
379
+ error: `${SENSITIVE_PATHS_FILE} is unreadable: ${err.message}`
380
+ };
381
+ }
382
+ }
383
+ function countScore(n) {
384
+ if (n <= 1) return 0;
385
+ if (n <= 3) return 1;
386
+ return 3;
387
+ }
388
+ const COVERAGE_SCORE = 3;
389
+ function centralityScore(fanIn) {
390
+ if (fanIn <= 0) return 0;
391
+ if (fanIn <= 2) return 1;
392
+ if (fanIn <= 6) return 2;
393
+ return 3;
394
+ }
395
+ const SENSITIVITY_SCORE = 2;
396
+ function levelFromScore(score) {
397
+ if (score >= 3) return "high";
398
+ if (score >= 1) return "medium";
399
+ return "low";
400
+ }
401
+ /** The project a work area belongs to — the first segment of its `project/capability` id. */
402
+ function projectOf(nodeId) {
403
+ return nodeId.split("/")[0];
404
+ }
405
+ /**
406
+ * projectsCoveredEntirely — the touched projects whose EVERY work area is in the touch-set, among
407
+ * projects holding >= 2 work areas. Coverage is relative reach: it asks what fraction of a project
408
+ * is disturbed, where `count` only asks how many areas in absolute terms. A project with a single
409
+ * work area never qualifies (see the guard note above).
410
+ *
411
+ * "Every work area of its project" means every area the LAYOUTS declare — `byNode` is the discovered
412
+ * area map keyed by node id, so a project's area set is its nodes across all of its declared roots
413
+ * (spec + impl), not whatever a directory walk happened to find.
414
+ */
415
+ function projectsCoveredEntirely(resolved, byNode) {
416
+ const areasByProject = /* @__PURE__ */ new Map();
417
+ for (const node of byNode.keys()) {
418
+ const p = projectOf(node);
419
+ const areas = areasByProject.get(p);
420
+ if (areas) areas.push(node);
421
+ else areasByProject.set(p, [node]);
422
+ }
423
+ const resolvedSet = new Set(resolved);
424
+ const covered = [];
425
+ for (const project of new Set(resolved.map(projectOf))) {
426
+ const areas = areasByProject.get(project) ?? [];
427
+ if (areas.length < 2) continue;
428
+ if (areas.every((a) => resolvedSet.has(a))) covered.push(project);
429
+ }
430
+ return covered.sort();
431
+ }
432
+ /** The pure scoring step, once `count`/`maxFanIn`/`sensitiveAreas`/`projectWide` are known. Exported
433
+ * so the ordering-property scenarios (hub-vs-leaf, marked-vs-unmarked) can be driven directly. */
434
+ function scoreBlast(count, maxFanIn, sensitiveAreas, projectWide = []) {
435
+ return {
436
+ level: levelFromScore(Math.max(countScore(count), projectWide.length > 0 ? COVERAGE_SCORE : 0) + centralityScore(maxFanIn) + (sensitiveAreas.length > 0 ? SENSITIVITY_SCORE : 0)),
437
+ reasons: {
438
+ count,
439
+ maxFanIn,
440
+ sensitiveAreas,
441
+ projectWide
442
+ }
443
+ };
444
+ }
445
+ const ORDER = [
446
+ "low",
447
+ "medium",
448
+ "high"
449
+ ];
450
+ /** Lines the computed level up against the hand-typed declared one. An absent or `unknown` declared
451
+ * blast is not an error — it is `no-declared`, and the computed level still stands on its own. */
452
+ function lineUp(computed, declared) {
453
+ if (declared === void 0 || declared === "unknown") return {
454
+ outcome: "no-declared",
455
+ computed
456
+ };
457
+ const di = ORDER.indexOf(declared);
458
+ const ci = ORDER.indexOf(computed);
459
+ if (di === ci) return {
460
+ outcome: "agrees",
461
+ computed,
462
+ declared
463
+ };
464
+ if (di < ci) return {
465
+ outcome: "under-called",
466
+ computed,
467
+ declared
468
+ };
469
+ return {
470
+ outcome: "over-called",
471
+ computed,
472
+ declared
473
+ };
474
+ }
475
+ /**
476
+ * estimateBlast — the whole derivation, over INJECTED layouts. Discovers the corpus's work areas by
477
+ * mapping every file under every declared root through touch-set-correction's pure `fileToNode`,
478
+ * resolves the touch-set against those areas (unresolved areas are surfaced, never dropped), reads
479
+ * the opt-in sensitive-paths file (fails loud on a malformed one — computed/reasons/lineUp all come
480
+ * back null, `error` names why), and — when at least one area resolved — scores
481
+ * breadth × centrality × sensitivity and lines the result up against `opts.declared`. A touch-set
482
+ * that resolves to zero known areas (including the empty touch-set) computes `unknown`: nothing
483
+ * touched is not evidence of low reach.
484
+ *
485
+ * Layouts are INJECTED rather than discovered here: `fileToNode` is pure, so tests construct layouts
486
+ * as fixtures over a constructed corpus (the frozen suite's "never the live corpus" preamble holds),
487
+ * while the CLI sources them from `discoverLayouts`.
488
+ */
489
+ function estimateBlast(touchSet, layouts, opts = {}) {
490
+ const root = opts.root ?? ".";
491
+ const byNode = discoverWorkAreas(layouts, root);
492
+ const known = new Set(byNode.keys());
493
+ const unique = [...new Set(touchSet)];
494
+ const resolved = unique.filter((a) => known.has(a));
495
+ const unresolved = unique.filter((a) => !known.has(a));
496
+ const sensitive = readSensitivePaths(root);
497
+ if (!sensitive.ok) return {
498
+ touchSet,
499
+ resolved,
500
+ unresolved,
501
+ computed: null,
502
+ reasons: null,
503
+ lineUp: null,
504
+ error: sensitive.error
505
+ };
506
+ if (resolved.length === 0) return {
507
+ touchSet,
508
+ resolved,
509
+ unresolved,
510
+ computed: "unknown",
511
+ reasons: {
512
+ count: 0,
513
+ maxFanIn: 0,
514
+ sensitiveAreas: [],
515
+ projectWide: []
516
+ },
517
+ lineUp: null
518
+ };
519
+ const markedSet = new Set(sensitive.marked);
520
+ const fanInMap = computeFanInMap(byNode, root, layouts, resolved);
521
+ const maxFanIn = Math.max(...resolved.map((a) => fanInMap.get(a) ?? 0));
522
+ const sensitiveAreas = resolved.filter((a) => markedSet.has(a));
523
+ const projectWide = projectsCoveredEntirely(resolved, byNode);
524
+ const { level, reasons } = scoreBlast(resolved.length, maxFanIn, sensitiveAreas, projectWide);
525
+ return {
526
+ touchSet,
527
+ resolved,
528
+ unresolved,
529
+ computed: level,
530
+ reasons,
531
+ lineUp: lineUp(level, opts.declared)
532
+ };
533
+ }
534
+ function toonQuote(v) {
535
+ if (v === "" || /[",;]/.test(v) || v !== v.trim()) return `"${v.replace(/"/g, "\"\"")}"`;
536
+ return v;
537
+ }
538
+ function renderResultToon(r) {
539
+ if (r.error) return [`blast-estimate: error="${r.error}"`, `unresolved[${r.unresolved.length}]: ${r.unresolved.map(toonQuote).join(";")}`].join("\n");
540
+ const lines = [];
541
+ const lu = r.lineUp;
542
+ const lineUpPart = lu ? lu.outcome === "no-declared" ? "lineup=no-declared" : `lineup=${lu.outcome}(declared=${lu.declared})` : "lineup=n/a";
543
+ lines.push(`blast-estimate: computed=${r.computed} ${lineUpPart}`);
544
+ if (r.reasons) lines.push(`reasons: count=${r.reasons.count} maxFanIn=${r.reasons.maxFanIn} sensitiveAreas=[${r.reasons.sensitiveAreas.join(";")}] projectWide=[${r.reasons.projectWide.join(";")}]`);
545
+ lines.push(`resolved[${r.resolved.length}]: ${r.resolved.map(toonQuote).join(";")}`);
546
+ lines.push(`unresolved[${r.unresolved.length}]: ${r.unresolved.map(toonQuote).join(";")}`);
547
+ return lines.join("\n");
548
+ }
549
+ function flag(argv, name) {
550
+ const i = argv.indexOf(name);
551
+ return i === -1 ? void 0 : argv[i + 1];
552
+ }
553
+ function allFlags(argv, name) {
554
+ const out = [];
555
+ for (let i = 0; i < argv.length; i++) if (argv[i] === name && argv[i + 1] !== void 0) out.push(argv[i + 1]);
556
+ return out;
557
+ }
558
+ function splitCsv(v) {
559
+ if (v === void 0 || v === "") return [];
560
+ return v.split(",").map((s) => s.trim()).filter((s) => s.length > 0);
561
+ }
562
+ /** Parses one `--layout '<project>:<root1>,<root2>'` flag value into a ProjectLayout (the same shape
563
+ * and flag touch-set-correction accepts, so the two tools take identical layout overrides). */
564
+ function parseLayoutFlag(value) {
565
+ const idx = value.indexOf(":");
566
+ if (idx === -1) return null;
567
+ const project = value.slice(0, idx).trim();
568
+ const roots = splitCsv(value.slice(idx + 1));
569
+ if (project === "" || roots.length === 0) return null;
570
+ return {
571
+ project,
572
+ roots
573
+ };
574
+ }
575
+ /** The legal `--declared` values, exactly. Returns `null` for anything else so the CLI can fail loud
576
+ * rather than let an unranked value masquerade as "below everything". Case-sensitive on purpose: the
577
+ * store writes these lowercase, and quietly accepting `High` would invite a second spelling. */
578
+ function parseDeclared(raw) {
579
+ return raw === "low" || raw === "medium" || raw === "high" || raw === "unknown" ? raw : null;
580
+ }
581
+ function main(argv) {
582
+ const root = flag(argv, "--root") ?? ".";
583
+ const touchSet = splitCsv(flag(argv, "--touch-set"));
584
+ const declaredRaw = flag(argv, "--declared");
585
+ const declared = declaredRaw === void 0 ? void 0 : parseDeclared(declaredRaw);
586
+ if (declared === null) {
587
+ process.stderr.write(`blast-estimate: --declared must be one of low, medium, high, unknown (got "${declaredRaw}")\n`);
588
+ return 1;
589
+ }
590
+ const format = flag(argv, "--format") === "json" ? "json" : "toon";
591
+ const layoutFlags = allFlags(argv, "--layout");
592
+ const result = estimateBlast(touchSet, layoutFlags.length > 0 ? layoutFlags.map(parseLayoutFlag).filter((l) => l !== null) : discoverLayouts(root, root), {
593
+ root,
594
+ declared
595
+ });
596
+ process.stdout.write(`${format === "json" ? JSON.stringify(result, null, 2) : renderResultToon(result)}\n`);
597
+ return result.error ? 1 : 0;
598
+ }
599
+ if (process.argv[1] && import.meta.url === pathToFileURL(realpathSync(process.argv[1])).href) process.exit(main(process.argv.slice(2)));
600
+ //#endregion
601
+ export { computeFanInMap, discoverWorkAreas, estimateBlast, levelFromScore, lineUp, main, parseDeclared, parseLayoutFlag, parseSensitivePaths, projectsCoveredEntirely, readSensitivePaths, renderResultToon, scoreBlast };