cyber-sdd 0.6.1 → 0.7.1

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 (136) hide show
  1. package/.claude-plugin/plugin.json +1 -2
  2. package/.codex-plugin/plugin.json +1 -2
  3. package/agents/sdd-scanner.md +1 -1
  4. package/agents/sdd-spec-judge.md +3 -3
  5. package/agents/sdd-warden.md +8 -0
  6. package/package.json +11 -13
  7. package/plugin.json +55 -0
  8. package/skills/align-spec/README.md +3 -3
  9. package/skills/align-spec/SKILL.md +2 -2
  10. package/skills/align-spec/scripts/align-spec.mjs +6755 -0
  11. package/skills/architect-impl-governance/SKILL.md +3 -1
  12. package/skills/architect-spec-governance/SKILL.md +5 -1
  13. package/skills/blast-estimate/README.md +4 -4
  14. package/skills/blast-estimate/SKILL.md +1 -1
  15. package/skills/blast-estimate/scripts/blast-estimate.mjs +601 -0
  16. package/skills/check-field-mandates/SKILL.md +1 -1
  17. package/skills/check-field-mandates/scripts/check-field-mandates.mjs +253 -0
  18. package/skills/check-partition-quality/SKILL.md +1 -1
  19. package/skills/check-partition-quality/scripts/check-partition-quality.mjs +235 -0
  20. package/skills/check-plan-safety/README.md +3 -3
  21. package/skills/check-plan-safety/SKILL.md +3 -4
  22. package/skills/check-plan-safety/scripts/check-plan-safety.mjs +109 -0
  23. package/skills/check-plugin-manifests/SKILL.md +1 -1
  24. package/skills/check-plugin-manifests/scripts/check-plugin-manifests.mjs +250 -0
  25. package/skills/check-project-specs/README.md +3 -3
  26. package/skills/check-project-specs/SKILL.md +3 -3
  27. package/{dist/check-project-specs/scripts/check-project-specs.js → skills/check-project-specs/scripts/check-project-specs.mjs} +300 -18
  28. package/skills/check-retired-terms/README.md +2 -2
  29. package/skills/check-retired-terms/SKILL.md +4 -5
  30. package/skills/check-retired-terms/scripts/check-retired-terms.mjs +186 -0
  31. package/skills/check-scenario-overlap/README.md +2 -2
  32. package/skills/check-scenario-overlap/SKILL.md +2 -3
  33. package/{dist/check-scenario-overlap/scripts/check-scenario-overlap.js → skills/check-scenario-overlap/scripts/check-scenario-overlap.mjs} +3 -1
  34. package/skills/check-spec-references/README.md +1 -1
  35. package/skills/check-spec-references/SKILL.md +3 -3
  36. package/{dist/check-spec-references/scripts/check-spec-references.js → skills/check-spec-references/scripts/check-spec-references.mjs} +3 -1
  37. package/skills/check-spec-structure/README.md +2 -2
  38. package/skills/check-spec-structure/SKILL.md +2 -3
  39. package/{dist/check-spec-structure/scripts/check-spec-structure.js → skills/check-spec-structure/scripts/check-spec-structure.mjs} +3 -1
  40. package/skills/collision-ladder/README.md +2 -2
  41. package/skills/collision-ladder/SKILL.md +2 -2
  42. package/skills/collision-ladder/scripts/collision-ladder.mjs +7047 -0
  43. package/skills/combat-log-governance/SKILL.md +1 -1
  44. package/skills/concept-index/README.md +2 -2
  45. package/skills/concept-index/SKILL.md +2 -2
  46. package/{dist/concept-index/scripts/concept-index.js → skills/concept-index/scripts/concept-index.mjs} +3 -1
  47. package/skills/discover-plans/README.md +5 -5
  48. package/skills/discover-plans/SKILL.md +2 -2
  49. package/skills/discover-plans/scripts/discover-plans.mjs +137 -0
  50. package/skills/discover-specs/README.md +4 -4
  51. package/skills/discover-specs/SKILL.md +2 -2
  52. package/{dist/discover-specs/scripts/discover-specs.js → skills/discover-specs/scripts/discover-specs.mjs} +4 -1
  53. package/skills/doctrine-loop/SKILL.md +2 -2
  54. package/skills/formation-loop/SKILL.md +10 -0
  55. package/skills/gate-validation-governance/SKILL.md +2 -2
  56. package/skills/init/README.md +5 -5
  57. package/skills/init/SKILL.md +3 -3
  58. package/skills/init/scripts/wire-statusline.mjs +168 -0
  59. package/skills/manage-ignore/README.md +8 -8
  60. package/skills/manage-ignore/SKILL.md +2 -3
  61. package/skills/manage-ignore/scripts/manage-ignore.mjs +285 -0
  62. package/skills/manage-scenario-bridge/README.md +6 -6
  63. package/skills/manage-scenario-bridge/SKILL.md +2 -2
  64. package/skills/manage-scenario-bridge/scripts/manage-scenario-bridge.mjs +239 -0
  65. package/skills/manage-spec-anchors/README.md +7 -7
  66. package/skills/manage-spec-anchors/SKILL.md +2 -2
  67. package/skills/manage-spec-anchors/scripts/manage-spec-anchors.mjs +310 -0
  68. package/skills/mission-graph/README.md +2 -2
  69. package/skills/mission-graph/SKILL.md +10 -10
  70. package/skills/mission-graph/scripts/mission-graph.mjs +1040 -0
  71. package/skills/pause-mission/SKILL.md +2 -2
  72. package/skills/place-node/README.md +1 -1
  73. package/skills/place-node/SKILL.md +3 -3
  74. package/skills/place-node/scripts/place-node.mjs +117 -0
  75. package/skills/plan-retirement/README.md +2 -2
  76. package/skills/plan-retirement/SKILL.md +1 -1
  77. package/skills/plan-retirement/scripts/retire-plans.mjs +123 -0
  78. package/skills/resolve-governances/README.md +4 -4
  79. package/skills/resolve-governances/SKILL.md +2 -2
  80. package/skills/resolve-governances/scripts/resolve-governances.mjs +352 -0
  81. package/skills/resolve-tracking/SKILL.md +2 -2
  82. package/skills/resolve-tracking/scripts/resolve-tracking.mjs +152 -0
  83. package/skills/scaffold-project-spec/SKILL.md +3 -3
  84. package/skills/sdd/SKILL.md +1 -1
  85. package/skills/spec-gate/README.md +12 -9
  86. package/skills/spec-gate/SKILL.md +6 -6
  87. package/{dist/spec-gate/scripts/check-spec-state.js → skills/spec-gate/scripts/check-spec-state.mjs} +3 -1
  88. package/{dist/spec-gate/vendor/gherkin-cli.js → skills/spec-gate/scripts/check-suite.mjs} +319 -188
  89. package/skills/spec-gate/{vendor/gherkin-cli.mjs → scripts/classify-edit-class.mjs} +243 -209
  90. package/skills/spec-producer-governance/SKILL.md +4 -4
  91. package/skills/spec-structure-governance/README.md +4 -2
  92. package/skills/spec-structure-governance/SKILL.md +42 -7
  93. package/skills/start-mission/SKILL.md +2 -2
  94. package/skills/suite-format-governance/README.md +1 -1
  95. package/skills/suite-format-governance/SKILL.md +1 -1
  96. package/skills/touch-set-correction/README.md +5 -5
  97. package/skills/touch-set-correction/SKILL.md +2 -2
  98. package/skills/touch-set-correction/scripts/touch-set-correction.mjs +6663 -0
  99. package/skills/verify-scenarios/README.md +9 -9
  100. package/skills/verify-scenarios/SKILL.md +2 -2
  101. package/skills/verify-scenarios/scripts/verify-scenarios.mjs +6539 -0
  102. package/.plugin/pins.json +0 -3
  103. package/.plugin/plugin.json +0 -19
  104. package/dist/align-spec/scripts/align-spec.js +0 -102
  105. package/dist/spec-gate/scripts/check-suite.js +0 -317
  106. package/dist/spec-gate/scripts/classify-edit-class.js +0 -263
  107. package/skills/align-spec/scripts/align-spec.mts +0 -188
  108. package/skills/blast-estimate/scripts/blast-estimate.mts +0 -586
  109. package/skills/check-field-mandates/scripts/check-field-mandates.mts +0 -337
  110. package/skills/check-partition-quality/scripts/check-partition-quality.mts +0 -338
  111. package/skills/check-plan-safety/scripts/check-plan-safety.mts +0 -148
  112. package/skills/check-plugin-manifests/scripts/check-plugin-manifests.mts +0 -303
  113. package/skills/check-project-specs/scripts/check-project-specs.mts +0 -369
  114. package/skills/check-retired-terms/scripts/check-retired-terms.mts +0 -293
  115. package/skills/check-scenario-overlap/scripts/check-scenario-overlap.mts +0 -250
  116. package/skills/check-spec-references/scripts/check-spec-references.mts +0 -422
  117. package/skills/check-spec-structure/scripts/check-spec-structure.mts +0 -347
  118. package/skills/collision-ladder/scripts/collision-ladder.mts +0 -660
  119. package/skills/concept-index/scripts/concept-index.mts +0 -246
  120. package/skills/discover-plans/scripts/discover-plans.mts +0 -215
  121. package/skills/discover-specs/scripts/discover-specs.mts +0 -420
  122. package/skills/init/scripts/wire-statusline.mts +0 -279
  123. package/skills/manage-ignore/scripts/manage-ignore.mts +0 -297
  124. package/skills/manage-scenario-bridge/scripts/manage-scenario-bridge.mts +0 -159
  125. package/skills/manage-spec-anchors/scripts/manage-spec-anchors.mts +0 -331
  126. package/skills/mission-graph/scripts/mission-graph.mts +0 -1333
  127. package/skills/place-node/scripts/place-node.mts +0 -158
  128. package/skills/plan-retirement/scripts/retire-plans.mts +0 -199
  129. package/skills/resolve-governances/scripts/resolve-governances.mts +0 -518
  130. package/skills/resolve-tracking/scripts/resolve-tracking.mts +0 -214
  131. package/skills/spec-gate/scripts/check-spec-state.mts +0 -637
  132. package/skills/spec-gate/scripts/check-suite.mts +0 -538
  133. package/skills/spec-gate/scripts/classify-edit-class.mts +0 -414
  134. package/skills/spec-gate/vendor/gherkin-cli.d.mts +0 -2
  135. package/skills/touch-set-correction/scripts/touch-set-correction.mts +0 -420
  136. package/skills/verify-scenarios/scripts/verify-scenarios.mts +0 -470
@@ -1,420 +0,0 @@
1
- #!/usr/bin/env node
2
- // touch-set-correction — a post-hoc, read-only reconciliation of a Mission's DECLARED touch-set
3
- // (the pre-work guess used to keep the mission-graph's WAW frontier apart) against its ACTUAL
4
- // touch-set (recovered from `git diff base..head`). It composes three tools — `git diff` (changed
5
- // files), `resolve-governances` (each file's artifact-type, best-effort), and `gherkin-cli diff`
6
- // (a touched .feature's changed scenarios) — into one three-way split (confirmed / missed /
7
- // over-declared) plus the corrected touch-set (= the actual touched set). The touch-set-correction
8
- // node of the SDD project spec (repo-only) carries the full contract.
9
- //
10
- // Architecture — pure derivation kept apart from IO, on purpose (mission-graph.mts's convention):
11
- // - isFeature / fileToNode / reconcile / assembleCorrection are PURE: they take and return plain
12
- // data — no fs/network access. Tests exercise these directly over CONSTRUCTED fixtures — never
13
- // a live git diff or the live mission-graph store.
14
- // - readChangedFiles / resolveArtifactType / changedScenarios / collectChangedFiles /
15
- // discoverLayouts are the thin IO SEAM: they shell out to `git`, `resolve-governances.mts`, and
16
- // the pinned `gherkin-cli` `diff` (the same differ classify-edit-class.mts uses —
17
- // this tool never reimplements a differ). NOT unit-tested (binary/fs boundary) — the tested
18
- // logic is everything downstream of the file list.
19
- // - main() is a thin CLI: argv -> collectChangedFiles + assembleCorrection, rendering TOON by
20
- // default or `--format json`.
21
- //
22
- // This tool is READ-ONLY with respect to the mission graph: it never writes to it. The graph's
23
- // single writer appends the corrected touch-set at Mission retirement (deferred, F3). It also does
24
- // NOT classify a collision hard/soft, run the finer-than-node ladder, descend to region/hunk tier,
25
- // or do SSA lowering (all deferred, issue #189 remainder).
26
- //
27
- // Pure functions are exported for node:test; running the file directly drives the CLI.
28
-
29
- import { execFileSync } from 'node:child_process'
30
- import { readFileSync, realpathSync } from 'node:fs'
31
- import { dirname, join, relative, resolve, sep } from 'node:path'
32
- import { fileURLToPath, pathToFileURL } from 'node:url'
33
- import { diff as gherkinDiff, type ReadsGitDiff } from '../../spec-gate/vendor/gherkin-cli.mjs'
34
-
35
- // ── Types ──
36
-
37
- export interface ProjectLayout {
38
- project: string
39
- roots: string[]
40
- }
41
-
42
- /** A changed file with its resolved annotations — the IO seam fills these in; tests construct them. */
43
- export interface ChangedFile {
44
- path: string
45
- artifactType: string
46
- changedScenarios: string[]
47
- }
48
-
49
- export interface FileEntry {
50
- path: string
51
- node: string | null
52
- artifactType: string
53
- changedScenarios: string[]
54
- }
55
-
56
- /** One changed file under a node, with the artifact-type resolved for it (best-effort — `unknown`
57
- * when it does not resolve). The per-file annotation the frozen "carries the artifact-type"
58
- * contract requires observable in the output. */
59
- export interface NodeFile {
60
- path: string
61
- artifactType: string
62
- }
63
-
64
- export interface NodeDetail {
65
- node: string
66
- files: NodeFile[]
67
- changedScenarios: string[]
68
- }
69
-
70
- export interface Reconciliation {
71
- confirmed: string[]
72
- missed: string[]
73
- overDeclared: string[]
74
- corrected: string[]
75
- }
76
-
77
- export interface Correction extends Reconciliation {
78
- nodes: NodeDetail[]
79
- unmapped: string[]
80
- }
81
-
82
- // ── Pure derivations ──
83
-
84
- /** The scenario-rung gate is STRUCTURAL — the `.feature` extension — never the resolved
85
- * artifact-type (a `.feature` with an unresolved artifact-type still gets scenario detail; a
86
- * non-`.feature` with a resolved artifact-type never does). */
87
- export function isFeature(path: string): boolean {
88
- return path.endsWith('.feature')
89
- }
90
-
91
- function stripTrailingSlash(root: string): string {
92
- return root.endsWith('/') ? root.slice(0, -1) : root
93
- }
94
-
95
- /**
96
- * fileToNode — capability-first work-area recovery. For each project's root, if `path` sits under
97
- * `root/`, the CAPABILITY is the first path segment after the matched root; the node is
98
- * `project/capability`. Matches the LONGEST matching root prefix across every project + root (so a
99
- * deeper root like `plugins/sdd/skills` wins over a shallower `plugins/sdd`, when both are
100
- * declared). Returns null when no root matches — the file is unmapped.
101
- */
102
- export function fileToNode(path: string, projects: ProjectLayout[]): string | null {
103
- let best: { project: string; capability: string; rootLen: number } | null = null
104
- for (const p of projects) {
105
- for (const rawRoot of p.roots) {
106
- const root = stripTrailingSlash(rawRoot)
107
- const prefix = root === '' ? '' : `${root}/`
108
- if (prefix === '' || !path.startsWith(prefix)) continue
109
- const rest = path.slice(prefix.length)
110
- const capability = rest.split('/')[0]
111
- if (!capability) continue
112
- if (best === null || prefix.length > best.rootLen) {
113
- best = { project: p.project, capability, rootLen: prefix.length }
114
- }
115
- }
116
- }
117
- return best ? `${best.project}/${best.capability}` : null
118
- }
119
-
120
- function sortedUnique(values: readonly string[]): string[] {
121
- return [...new Set(values)].sort()
122
- }
123
-
124
- /**
125
- * reconcile — the declared-vs-actual three-way split: confirmed = declared ∩ actual, missed =
126
- * actual − declared, overDeclared = declared − actual. The corrected touch-set is simply the
127
- * actual set — the real change is the ground truth. Every list de-duplicated and sorted, so a
128
- * fixed input always reconciles to the same answer in the same order.
129
- */
130
- export function reconcile(declared: string[], actual: string[]): Reconciliation {
131
- const declaredSet = new Set(declared)
132
- const actualSet = new Set(actual)
133
- return {
134
- confirmed: sortedUnique(declared.filter((d) => actualSet.has(d))),
135
- missed: sortedUnique(actual.filter((a) => !declaredSet.has(a))),
136
- overDeclared: sortedUnique(declared.filter((d) => !actualSet.has(d))),
137
- corrected: sortedUnique(actual),
138
- }
139
- }
140
-
141
- /**
142
- * assembleCorrection — the whole pure assembly. Builds a FileEntry per changed file (node via
143
- * fileToNode; changedScenarios gated by isFeature — belt-and-suspenders: a non-.feature never
144
- * records scenario detail even if fed some), collects the unmapped paths and the actual (non-null,
145
- * de-duplicated) node set, groups per-node file + scenario detail, and reconciles declared against
146
- * actual. Deterministic + stably ordered for fixed inputs — no fs/network access of its own.
147
- */
148
- export function assembleCorrection(declared: string[], files: ChangedFile[], projects: ProjectLayout[]): Correction {
149
- const entries: FileEntry[] = files.map((f) => ({
150
- path: f.path,
151
- node: fileToNode(f.path, projects),
152
- artifactType: f.artifactType,
153
- changedScenarios: isFeature(f.path) ? f.changedScenarios : [],
154
- }))
155
-
156
- const unmapped = sortedUnique(entries.filter((e) => e.node === null).map((e) => e.path))
157
- const actual = sortedUnique(
158
- entries.filter((e): e is FileEntry & { node: string } => e.node !== null).map((e) => e.node),
159
- )
160
-
161
- const nodes: NodeDetail[] = actual.map((node) => {
162
- const nodeEntries = entries.filter((e) => e.node === node)
163
- // One NodeFile per distinct path (first artifact-type wins on the rare duplicate path), sorted
164
- // by path — so the per-file artifact-type rides through into the returned record, deterministically.
165
- const byPath = new Map<string, string>()
166
- for (const e of nodeEntries) if (!byPath.has(e.path)) byPath.set(e.path, e.artifactType)
167
- const files: NodeFile[] = [...byPath.entries()]
168
- .map(([path, artifactType]) => ({ path, artifactType }))
169
- .sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0))
170
- return {
171
- node,
172
- files,
173
- changedScenarios: sortedUnique(nodeEntries.flatMap((e) => e.changedScenarios)),
174
- }
175
- })
176
-
177
- return { ...reconcile(declared, actual), nodes, unmapped }
178
- }
179
-
180
- // ── IO seam (thin — network/binary/fs boundary; not unit-tested, mirrors classify-edit-class.mts) ──
181
-
182
- /** Reads the changed-file list of `base..head` via `git diff --name-status`. A rename records its
183
- * NEW path only. On any git failure (absent binary, bad refs, not a repo) returns []. */
184
- export function readChangedFiles(base: string, head: string, cwd: string): { path: string; status: string }[] {
185
- let out: string
186
- try {
187
- out = execFileSync('git', ['diff', '--name-status', `${base}..${head}`], {
188
- encoding: 'utf8',
189
- cwd,
190
- stdio: ['ignore', 'pipe', 'ignore'],
191
- })
192
- } catch {
193
- return []
194
- }
195
- const results: { path: string; status: string }[] = []
196
- for (const line of out.split('\n')) {
197
- if (line.trim() === '') continue
198
- const rename = /^R\d+\t([^\t]+)\t([^\t]+)$/.exec(line)
199
- if (rename) {
200
- results.push({ path: rename[2], status: 'R' })
201
- continue
202
- }
203
- const m = /^(\S+)\t(.+)$/.exec(line)
204
- if (m) results.push({ path: m[2], status: m[1] })
205
- }
206
- return results
207
- }
208
-
209
- const HERE = dirname(fileURLToPath(import.meta.url))
210
- const RESOLVE_GOVERNANCES_PATH = join(HERE, '..', '..', 'resolve-governances', 'scripts', 'resolve-governances.mts')
211
-
212
- /** Resolves one file's artifact-type via `resolve-governances --path` (best-effort — its own
213
- * no-match "classify by convention" case). On ANY failure (absent tool, bad JSON, non-zero exit)
214
- * returns 'unknown' — never throws. */
215
- export function resolveArtifactType(path: string, root: string, cwd: string): string {
216
- try {
217
- const out = execFileSync('node', [RESOLVE_GOVERNANCES_PATH, '--root', root, '--path', path, '--format', 'json'], {
218
- encoding: 'utf8',
219
- cwd,
220
- stdio: ['ignore', 'pipe', 'ignore'],
221
- })
222
- const parsed = JSON.parse(out) as { artifactType?: string | null }
223
- return parsed.artifactType ?? 'unknown'
224
- } catch {
225
- return 'unknown'
226
- }
227
- }
228
-
229
- // `diff`'s default reader resolves paths against `process.cwd()` and derives git's own cwd
230
- // from that resolved location (`git ls-files --full-name` to recover the repo-relative path) —
231
- // this reader is that same algorithm, re-pointed at `cwd` (same seam classify-edit-class.mts
232
- // uses), so it stays robust to a caller whose relative-path bookkeeping doesn't line up with its
233
- // own `cwd`. Any failure (bad ref, unreadable file) surfaces as `undefined` text, which the differ
234
- // reads as "absent" — the outer `changedScenarios` catch-all is this call site's real fail-open
235
- // boundary, so a thrown `GitError` here is caught there rather than escalated.
236
- const cwdReader =
237
- (cwd: string): ReadsGitDiff['readDiff'] =>
238
- (file, base) => {
239
- const abs = resolve(cwd, file)
240
- const dir = dirname(abs)
241
- let head: string | undefined
242
- try {
243
- head = readFileSync(abs, 'utf8')
244
- } catch {
245
- head = undefined
246
- }
247
- const gitIo = {
248
- cwd: dir,
249
- encoding: 'utf8' as const,
250
- stdio: ['ignore', 'pipe', 'ignore'] as ['ignore', 'pipe', 'ignore'],
251
- }
252
- let rel: string
253
- try {
254
- rel = execFileSync('git', ['ls-files', '--full-name', '--', abs], gitIo).trim()
255
- } catch {
256
- return { head, base: undefined }
257
- }
258
- if (rel === '') {
259
- try {
260
- const top = execFileSync('git', ['rev-parse', '--show-toplevel'], gitIo).trim()
261
- rel = relative(top, abs).split(sep).join('/')
262
- } catch {
263
- return { head, base: undefined }
264
- }
265
- }
266
- let baseText: string | undefined
267
- try {
268
- baseText = execFileSync('git', ['show', `${base}:${rel}`], gitIo)
269
- } catch {
270
- baseText = undefined
271
- }
272
- return { head, base: baseText }
273
- }
274
-
275
- /** The changed scenario names of a touched `.feature`, via the pinned `gherkin-cli`
276
- * `diff` (same tool classify-edit-class.mts uses — never a reimplemented differ). Gated
277
- * by isFeature — a non-.feature never calls out. On any failure returns []. Reads any `.feature`
278
- * regardless of freeze — the freeze gate is a separate concern (spec-gate), not this tool's
279
- * business. */
280
- export function changedScenarios(base: string, path: string, cwd: string): string[] {
281
- if (!isFeature(path)) return []
282
- try {
283
- const { files } = gherkinDiff([path], { base, full: true }, { readDiff: cwdReader(cwd) })
284
- const fileResult = files.find((f) => f.file === path) ?? files[0]
285
- return (fileResult?.scenarios ?? []).filter((s) => s.change !== 'unchanged').map((s) => s.name)
286
- } catch {
287
- return []
288
- }
289
- }
290
-
291
- /** Composes the three IO calls per changed file into the ChangedFile list `assembleCorrection`
292
- * consumes. */
293
- export function collectChangedFiles(base: string, head: string, root: string, cwd: string): ChangedFile[] {
294
- const changed = readChangedFiles(base, head, cwd)
295
- return changed.map(({ path }) => ({
296
- path,
297
- artifactType: resolveArtifactType(path, root, cwd),
298
- changedScenarios: changedScenarios(base, path, cwd),
299
- }))
300
- }
301
-
302
- const DISCOVER_SPECS_PATH = join(HERE, '..', '..', 'discover-specs', 'scripts', 'discover-specs.mts')
303
-
304
- interface DiscoveredSpec {
305
- path: string
306
- name: string
307
- projectPath: string
308
- }
309
-
310
- /** Best-effort project-layout discovery via `discover-specs`: each project's spec-path plus an
311
- * impl-root convention (`plugins/<p>` → also `plugins/<p>/skills`; `packages/<p>` → also
312
- * `packages/<p>/src`; else the project-path itself). `--layout` (CLI) overrides this entirely. On
313
- * any failure returns []. */
314
- export function discoverLayouts(root: string, cwd: string): ProjectLayout[] {
315
- try {
316
- const out = execFileSync('node', [DISCOVER_SPECS_PATH, '--root', root, '--format', 'json'], {
317
- encoding: 'utf8',
318
- cwd,
319
- stdio: ['ignore', 'pipe', 'ignore'],
320
- })
321
- const specs = JSON.parse(out) as DiscoveredSpec[]
322
- return specs.map((s) => {
323
- const roots = [s.path]
324
- const projectPath = s.projectPath ?? ''
325
- const pluginsMatch = /^plugins\/([^/]+)$/.exec(projectPath)
326
- const packagesMatch = /^packages\/([^/]+)$/.exec(projectPath)
327
- if (pluginsMatch) roots.push(`plugins/${pluginsMatch[1]}/skills`)
328
- else if (packagesMatch) roots.push(`packages/${packagesMatch[1]}/src`)
329
- else if (projectPath) roots.push(projectPath)
330
- return { project: s.name, roots }
331
- })
332
- } catch {
333
- return []
334
- }
335
- }
336
-
337
- // ── Render (TOON — the token-efficient tabular form the repo's other sdd engines emit) ──
338
-
339
- function toonQuote(v: string): string {
340
- if (v === '' || /[",;]/.test(v) || v !== v.trim()) return `"${v.replace(/"/g, '""')}"`
341
- return v
342
- }
343
-
344
- export function renderCorrectionToon(correction: Correction): string {
345
- const lines: string[] = []
346
- lines.push(`corrected[${correction.corrected.length}]: ${correction.corrected.map(toonQuote).join(';')}`)
347
- lines.push(`confirmed[${correction.confirmed.length}]: ${correction.confirmed.map(toonQuote).join(';')}`)
348
- lines.push(`missed[${correction.missed.length}]: ${correction.missed.map(toonQuote).join(';')}`)
349
- lines.push(`overDeclared[${correction.overDeclared.length}]: ${correction.overDeclared.map(toonQuote).join(';')}`)
350
- lines.push(`nodes[${correction.nodes.length}]{node,files,changedScenarios}:`)
351
- for (const n of correction.nodes) {
352
- const files = n.files.map((f) => `${f.path}(${f.artifactType})`).join(';')
353
- lines.push(` ${toonQuote(n.node)},"${files}","${n.changedScenarios.join(';')}"`)
354
- }
355
- lines.push(`unmapped[${correction.unmapped.length}]: ${correction.unmapped.map(toonQuote).join(';')}`)
356
- return lines.join('\n')
357
- }
358
-
359
- // ── CLI ──
360
-
361
- function flag(argv: string[], name: string): string | undefined {
362
- const i = argv.indexOf(name)
363
- return i === -1 ? undefined : argv[i + 1]
364
- }
365
-
366
- function allFlags(argv: string[], name: string): string[] {
367
- const out: string[] = []
368
- for (let i = 0; i < argv.length; i++) {
369
- if (argv[i] === name && argv[i + 1] !== undefined) out.push(argv[i + 1])
370
- }
371
- return out
372
- }
373
-
374
- function splitCsv(v: string | undefined): string[] {
375
- if (v === undefined || v === '') return []
376
- return v
377
- .split(',')
378
- .map((s) => s.trim())
379
- .filter((s) => s.length > 0)
380
- }
381
-
382
- /** Parses one `--layout '<project>:<root1>,<root2>'` flag value into a ProjectLayout. */
383
- export function parseLayoutFlag(value: string): ProjectLayout | null {
384
- const idx = value.indexOf(':')
385
- if (idx === -1) return null
386
- const project = value.slice(0, idx).trim()
387
- const roots = splitCsv(value.slice(idx + 1))
388
- if (project === '' || roots.length === 0) return null
389
- return { project, roots }
390
- }
391
-
392
- export function main(argv: string[]): number {
393
- const base = flag(argv, '--base')
394
- if (base === undefined) {
395
- process.stderr.write('touch-set-correction: --base <ref> is required\n')
396
- return 1
397
- }
398
- const head = flag(argv, '--head') ?? 'HEAD'
399
- const root = flag(argv, '--root') ?? '.'
400
- const declared = splitCsv(flag(argv, '--declared'))
401
- const format = flag(argv, '--format') === 'json' ? 'json' : 'toon'
402
-
403
- const layoutFlags = allFlags(argv, '--layout')
404
- const layouts =
405
- layoutFlags.length > 0
406
- ? layoutFlags.map(parseLayoutFlag).filter((l): l is ProjectLayout => l !== null)
407
- : discoverLayouts(root, root)
408
-
409
- const files = collectChangedFiles(base, head, root, root)
410
- const correction = assembleCorrection(declared, files, layouts)
411
-
412
- process.stdout.write(
413
- `${format === 'json' ? JSON.stringify(correction, null, 2) : renderCorrectionToon(correction)}\n`,
414
- )
415
- return 0
416
- }
417
-
418
- if (process.argv[1] && import.meta.url === pathToFileURL(realpathSync(process.argv[1])).href) {
419
- process.exit(main(process.argv.slice(2)))
420
- }