@llman-sdd/core 0.8.2 → 0.10.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 (89) hide show
  1. package/package.json +1 -1
  2. package/src/archive/freeze.ts +15 -15
  3. package/src/archive/frozenCard.ts +3 -2
  4. package/src/change/collect.ts +17 -14
  5. package/src/change/deps.ts +54 -0
  6. package/src/change/frontmatter.ts +36 -5
  7. package/src/change/lifecycle.ts +124 -20
  8. package/src/change/nextId.ts +21 -7
  9. package/src/config/changeId.ts +0 -6
  10. package/src/config/load.ts +36 -2
  11. package/src/config/schema.ts +3 -7
  12. package/src/context/indexStore.ts +14 -14
  13. package/src/context/sddState.ts +1 -13
  14. package/src/context/tree.ts +9 -19
  15. package/src/git/spawnGit.ts +5 -1
  16. package/src/index.ts +37 -12
  17. package/src/init/defaultConfig.ts +14 -31
  18. package/src/init/init.ts +92 -30
  19. package/src/locale.ts +33 -0
  20. package/src/project/migrations.ts +196 -60
  21. package/src/report/graph/deps.ts +3 -38
  22. package/src/report/graph/nodes.ts +13 -19
  23. package/src/report/graph/types.ts +2 -6
  24. package/src/report/show.ts +16 -8
  25. package/src/report/specHelpers.ts +22 -28
  26. package/src/review/review.ts +18 -31
  27. package/src/self/completion.ts +206 -0
  28. package/src/spec/assignSpecIds.ts +9 -1
  29. package/src/spec/authoring.ts +11 -11
  30. package/src/spec/parser.ts +3 -1
  31. package/src/templates/skills.ts +3 -23
  32. package/src/util/datedId.ts +18 -0
  33. package/src/util/fsPort.ts +24 -0
  34. package/src/util/nextNumber.ts +30 -0
  35. package/src/util/semver.ts +21 -0
  36. package/src/validation/changeCheck.ts +133 -67
  37. package/src/validation/crossRoot.ts +86 -0
  38. package/src/validation/discover.ts +22 -13
  39. package/src/validation/roots.ts +2 -5
  40. package/src/validation/validate.ts +10 -19
  41. package/src/validation/{transitions.ts → xstateTransitions.ts} +81 -69
  42. package/templates/zh-Hans/skills/llman-sdd-apply-cycle.md +9 -7
  43. package/templates/zh-Hans/skills/llman-sdd-apply.md +5 -5
  44. package/templates/zh-Hans/skills/llman-sdd-archive.md +11 -2
  45. package/templates/zh-Hans/skills/llman-sdd-continue.md +1 -1
  46. package/templates/zh-Hans/skills/llman-sdd-draft.md +1 -1
  47. package/templates/zh-Hans/skills/llman-sdd-explore.md +2 -2
  48. package/templates/zh-Hans/skills/llman-sdd-ff.md +1 -1
  49. package/templates/zh-Hans/skills/llman-sdd-propose.md +8 -6
  50. package/templates/zh-Hans/skills/llman-sdd-quick.md +1 -1
  51. package/templates/zh-Hans/skills/llman-sdd-validate.md +1 -1
  52. package/templates/zh-Hans/skills/llman-sdd-verify.md +2 -2
  53. package/templates/zh-Hans/skills/llman-sdd-wayfinder.md +1 -1
  54. package/templates/zh-Hans/units/skills/git-native-flow.md +12 -6
  55. package/templates/zh-Hans/units/skills/index-fallback.md +1 -0
  56. package/templates/zh-Hans/units/skills/structured-protocol.md +1 -6
  57. package/templates/zh-Hans/units/spec/feature-contract.md +5 -33
  58. package/src/templates/locale.ts +0 -24
  59. package/templates/en/agents-root-stub.md +0 -9
  60. package/templates/en/llmanspec-agents-stub.md +0 -6
  61. package/templates/en/skills/llman-sdd-apply-cycle.md +0 -67
  62. package/templates/en/skills/llman-sdd-apply.md +0 -117
  63. package/templates/en/skills/llman-sdd-arch-review.md +0 -58
  64. package/templates/en/skills/llman-sdd-archive.md +0 -70
  65. package/templates/en/skills/llman-sdd-continue.md +0 -34
  66. package/templates/en/skills/llman-sdd-draft.md +0 -53
  67. package/templates/en/skills/llman-sdd-explore.md +0 -64
  68. package/templates/en/skills/llman-sdd-ff.md +0 -33
  69. package/templates/en/skills/llman-sdd-graph.md +0 -56
  70. package/templates/en/skills/llman-sdd-propose.md +0 -105
  71. package/templates/en/skills/llman-sdd-quick.md +0 -41
  72. package/templates/en/skills/llman-sdd-research.md +0 -35
  73. package/templates/en/skills/llman-sdd-specs-compact.md +0 -41
  74. package/templates/en/skills/llman-sdd-validate.md +0 -28
  75. package/templates/en/skills/llman-sdd-verify.md +0 -77
  76. package/templates/en/skills/llman-sdd-wayfinder.md +0 -83
  77. package/templates/en/units/skills/cli-footer.md +0 -2
  78. package/templates/en/units/skills/ethics-governance.md +0 -6
  79. package/templates/en/units/skills/git-native-flow-brief.md +0 -10
  80. package/templates/en/units/skills/git-native-flow.md +0 -50
  81. package/templates/en/units/skills/human-readable-summary.md +0 -9
  82. package/templates/en/units/skills/stage-guard.md +0 -17
  83. package/templates/en/units/skills/structured-protocol.md +0 -24
  84. package/templates/en/units/skills/validation-hints.md +0 -20
  85. package/templates/en/units/skills/version-drift.md +0 -3
  86. package/templates/en/units/spec/feature-contract.md +0 -38
  87. package/templates/en/units/workflow/archive-freeze-guidance.md +0 -9
  88. package/templates/zh-Hans/units/skills/git-native-flow-brief.md +0 -10
  89. package/templates/zh-Hans/units/workflow/archive-freeze-guidance.md +0 -10
@@ -1,11 +1,14 @@
1
1
  import { stageFor, walkActiveChangeDirs } from '../change/collect.ts';
2
+ import { readDepsStrict } from '../change/deps.ts';
2
3
  import {
3
4
  extractFrontmatter,
4
5
  readBinding,
5
6
  readFrontmatterTitle,
6
7
  readNeedsSpecsChange,
8
+ DEFAULT_SPECS_PREFIX,
7
9
  specsLanded,
8
10
  } from '../change/frontmatter.ts';
11
+ import { CHANGES_DIR } from '../change/lifecycle.ts';
9
12
  import { CLOSE_OUT_TASK_HINT, closeOutTaskLines, parseTaskCheckboxes } from '../change/tasks.ts';
10
13
  /**
11
14
  * Change-domain validation (predecessor `commands/validate.rs` change path parity):
@@ -13,6 +16,24 @@ import { CLOSE_OUT_TASK_HINT, closeOutTaskLines, parseTaskCheckboxes } from '../
13
16
  * INFO, pattern gate and task gates. IO + git injected (pure).
14
17
  */
15
18
  import type { GitLike } from '../git/spawnGit.ts';
19
+ import { datedCardIdOf, datedIdOf } from '../util/datedId.ts';
20
+
21
+ /**
22
+ * r87/r91 single archive-entry grammar: a dated directory `YYYY-MM-DD-<id>` or
23
+ * a flattened card `YYYY-MM-DD-<id>.yaml` yields its id; anything else is null.
24
+ * The uniqueness gate, the archived-membership probe and the per-root value
25
+ * collection MUST agree on this split (predecessor hand-rolled `slice(11)` /
26
+ * `.yaml` stripping in three places).
27
+ */
28
+ function archivedEntryId(name: string): string | null {
29
+ // Card form first: `2026-02-02-card.yaml` must yield `card`, not `card.yaml`.
30
+ const card = datedCardIdOf(name, '.yaml');
31
+ if (card !== null) return card;
32
+ // Then the directory grammar on the card suffix stripped, so a card name
33
+ // without an id (`2026-02-02-.yaml`) stays unparsed instead of yielding
34
+ // `.yaml` (the predecessor form produced '' there and skipped it).
35
+ return datedIdOf(name.endsWith('.yaml') ? name.slice(0, -'.yaml'.length) : name);
36
+ }
16
37
 
17
38
  export type ChangeIssueLevel = 'ERROR' | 'WARNING' | 'INFO';
18
39
 
@@ -53,6 +74,36 @@ export const STAGE_ORDER = ['draft', 'designed', 'planned', 'full'] as const;
53
74
  * `2026-01-01-the-other` must NOT satisfy id `other`). A missing
54
75
  * `archive/` dir reads as empty and never throws.
55
76
  */
77
+ /**
78
+ * T29 shared change-id pattern gate: one compile+match+diagnostic pair for the
79
+ * structural issue list and the streaming push form (same wording, same
80
+ * 'change-id' anchor).
81
+ */
82
+ function patternGate(
83
+ id: string,
84
+ pattern: string | null | undefined,
85
+ ): { level: 'ERROR'; path: 'change-id'; message: string }[] {
86
+ if (!pattern) return [];
87
+ const out: { level: 'ERROR'; path: 'change-id'; message: string }[] = [];
88
+ try {
89
+ const re = new RegExp(pattern, 'u');
90
+ if (!re.test(id)) {
91
+ out.push({
92
+ level: 'ERROR',
93
+ path: 'change-id',
94
+ message: `Change id '${id}' does not match change_id.pattern '${pattern}' (active changes only; archived changes are not re-checked).`,
95
+ });
96
+ }
97
+ } catch (error) {
98
+ out.push({
99
+ level: 'ERROR',
100
+ path: 'change-id',
101
+ message: `change_id.pattern is not a valid regular expression: ${(error as Error).message}`,
102
+ });
103
+ }
104
+ return out;
105
+ }
106
+
56
107
  function resolveChangeRef(
57
108
  io: ChangeFsIoLite,
58
109
  changesRoot: string,
@@ -66,11 +117,7 @@ function resolveChangeRef(
66
117
  const archive = `${changesRoot}/archive`;
67
118
  const entries = io.exists(archive) && io.isDirectory(archive) ? io.listDir(archive) : [];
68
119
  // `YYYY-MM-DD-` is 11 chars; the remainder must equal the id exactly.
69
- const archived = entries.some((name) => {
70
- if (!/^\d{4}-\d{2}-\d{2}-/u.test(name)) return false;
71
- const base = name.endsWith('.yaml') ? name.slice(0, -'.yaml'.length) : name;
72
- return base.slice(11) === id;
73
- });
120
+ const archived = entries.some((name) => archivedEntryId(name) === id);
74
121
  return archived ? 'archived' : 'unknown';
75
122
  }
76
123
 
@@ -89,10 +136,8 @@ export function checkGlobalChangeIdUniqueness(io: ChangeFsIoLite, changesRoot: s
89
136
  counts.set(name, (counts.get(name) ?? 0) + 1);
90
137
  });
91
138
  for (const name of entries) {
92
- if (!/^\d{4}-\d{2}-\d{2}-/u.test(name)) continue;
93
- const base = name.endsWith('.yaml') ? name.slice(0, -'.yaml'.length) : name;
94
- const id = base.slice(11);
95
- if (id === '') continue;
139
+ const id = archivedEntryId(name);
140
+ if (id === null || id === '') continue;
96
141
  counts.set(id, (counts.get(id) ?? 0) + 1);
97
142
  }
98
143
  return [...counts]
@@ -101,6 +146,30 @@ export function checkGlobalChangeIdUniqueness(io: ChangeFsIoLite, changesRoot: s
101
146
  .toSorted((a, b) => a.localeCompare(b));
102
147
  }
103
148
 
149
+ /**
150
+ * r87/r91: the change-id domain of one instance root — active leaf dir names
151
+ * plus the ids split out of archived `<YYYY-MM-DD>-<id>` entries (dirs and
152
+ * flattened `.yaml` cards). De-duplicated and sorted (`checkGlobalChangeIdUniqueness`
153
+ * above stays the in-root counting gate); the cross-root observation consumes
154
+ * one list per root.
155
+ */
156
+ export function collectChangeIdValues(
157
+ io: ChangeFsIoLite,
158
+ changesRoot: string,
159
+ opts: { maxScanDepth?: number } = {},
160
+ ): string[] {
161
+ const values = new Set<string>();
162
+ walkActiveChangeDirs(io, changesRoot, (_dir, name) => values.add(name), opts);
163
+ const archive = `${changesRoot}/archive`;
164
+ if (io.exists(archive) && io.isDirectory(archive)) {
165
+ for (const name of io.listDir(archive)) {
166
+ const id = archivedEntryId(name);
167
+ if (id !== null && id !== '') values.add(id);
168
+ }
169
+ }
170
+ return [...values].toSorted((a, b) => (a < b ? -1 : a > b ? 1 : 0));
171
+ }
172
+
104
173
  export type StageGate = (typeof STAGE_ORDER)[number];
105
174
 
106
175
  export interface ChangeCheckResult {
@@ -134,24 +203,7 @@ export function checkChangeDoc(
134
203
  message: 'change has no branch binding (not started/attached)',
135
204
  });
136
205
  }
137
- if (config.change_id_pattern) {
138
- try {
139
- const re = new RegExp(config.change_id_pattern, 'u');
140
- if (!re.test(input.name)) {
141
- issues.push({
142
- level: 'ERROR',
143
- path: 'change-id',
144
- message: `Change id '${input.name}' does not match change_id.pattern '${config.change_id_pattern}' (active changes only; archived changes are not re-checked).`,
145
- });
146
- }
147
- } catch (error) {
148
- issues.push({
149
- level: 'ERROR',
150
- path: 'change-id',
151
- message: `change_id.pattern is not a valid regular expression: ${(error as Error).message}`,
152
- });
153
- }
154
- }
206
+ issues.push(...patternGate(input.name, config.change_id_pattern));
155
207
  return { id: input.name, valid: issues.every((i) => i.level !== 'ERROR'), issues };
156
208
  }
157
209
 
@@ -178,15 +230,15 @@ export function validateChange(
178
230
  root: string,
179
231
  id: string,
180
232
  config: ChangeValidationConfig,
181
- opts: { stage?: StageGate; strict?: boolean; git?: GitLike } = {},
233
+ opts: { stage?: StageGate; strict?: boolean; git?: GitLike; specsPrefix?: string } = {},
182
234
  ): ChangeCheckResult {
183
235
  const issues: ChangeIssue[] = [];
184
236
  const push = (level: ChangeIssueLevel, path: string, message: string): void => {
185
237
  issues.push({ level, path, message });
186
238
  };
187
239
 
188
- const dir = `${root}/llmanspec/changes/${id}/`;
189
- const baseDir = `${root}/llmanspec/changes`;
240
+ const dir = `${root}/${CHANGES_DIR}/${id}/`;
241
+ const baseDir = `${root}/${CHANGES_DIR}`;
190
242
  const proposal = `${dir}proposal.md`;
191
243
  // Probed once here: shared by the stage inference below and the --stage
192
244
  // artifact gate at the end (predecessor issue order preserved).
@@ -199,13 +251,42 @@ export function validateChange(
199
251
  const fm = extractFrontmatter(text) ?? '';
200
252
  const fmLines = fm.split('\n').map((l) => l.trim());
201
253
 
202
- for (const key of ['depends_on', 'blocks'] as const) {
203
- const lineIdx = fmLines.findIndex((l) => l.startsWith(`${key}:`));
204
- if (lineIdx === -1) continue;
205
- const value = (fmLines[lineIdx] ?? '').slice(key.length + 1).trim();
254
+ // T22: depends_on rides the single reader (strict policy) — quoting, block
255
+ // /flow styles and numeric entries collapse into one parse. `blocks` keeps
256
+ // the structural line scan (no shared reader; list-of-strings only).
257
+ const deps = readDepsStrict(text);
258
+ if (deps.kind === 'malformed') {
259
+ push(
260
+ 'ERROR',
261
+ 'proposal.md/frontmatter.depends_on',
262
+ 'proposal.md depends_on must be a list of change ID strings',
263
+ );
264
+ } else {
265
+ for (const item of deps.items) {
266
+ if (item === '') continue;
267
+ if (/^\d/u.test(item)) {
268
+ push(
269
+ 'ERROR',
270
+ 'proposal.md/frontmatter.depends_on',
271
+ 'proposal.md depends_on must be a list of change ID strings',
272
+ );
273
+ continue;
274
+ }
275
+ if (resolveChangeRef(io, baseDir, item) === 'unknown') {
276
+ push(
277
+ 'ERROR',
278
+ 'proposal.md/frontmatter.depends_on',
279
+ `proposal.md depends_on references unknown change: ${item}`,
280
+ );
281
+ }
282
+ }
283
+ }
284
+ const blocksLineIdx = fmLines.findIndex((l) => l.startsWith('blocks:'));
285
+ if (blocksLineIdx !== -1) {
286
+ const value = (fmLines[blocksLineIdx] ?? '').slice('blocks:'.length).trim();
206
287
  let items: string[] = [];
207
288
  if (value === '') {
208
- for (const l of fmLines.slice(lineIdx + 1)) {
289
+ for (const l of fmLines.slice(blocksLineIdx + 1)) {
209
290
  if (l.startsWith('- ')) items.push(l.slice(2).trim());
210
291
  else if (l === '') continue;
211
292
  else break;
@@ -214,31 +295,31 @@ export function validateChange(
214
295
  items = value
215
296
  .slice(1, -1)
216
297
  .split(',')
217
- .map((s) => s.trim())
218
- .filter((s) => s !== '');
298
+ .map((b) => b.trim())
299
+ .filter((b) => b !== '');
219
300
  } else {
220
301
  push(
221
302
  'ERROR',
222
- `proposal.md/frontmatter.${key}`,
223
- `proposal.md ${key} must be a list of change ID strings`,
303
+ 'proposal.md/frontmatter.blocks',
304
+ 'proposal.md blocks must be a list of change ID strings',
224
305
  );
225
- continue;
306
+ items = [];
226
307
  }
227
308
  for (const item of items) {
228
309
  if (item === '') continue;
229
310
  if (/^\d/u.test(item)) {
230
311
  push(
231
312
  'ERROR',
232
- `proposal.md/frontmatter.${key}`,
233
- `proposal.md ${key} must be a list of change ID strings`,
313
+ 'proposal.md/frontmatter.blocks',
314
+ 'proposal.md blocks must be a list of change ID strings',
234
315
  );
235
316
  continue;
236
317
  }
237
318
  if (resolveChangeRef(io, baseDir, item) === 'unknown') {
238
319
  push(
239
320
  'ERROR',
240
- `proposal.md/frontmatter.${key}`,
241
- `proposal.md ${key} references unknown change: ${item}`,
321
+ 'proposal.md/frontmatter.blocks',
322
+ `proposal.md blocks references unknown change: ${item}`,
242
323
  );
243
324
  }
244
325
  }
@@ -310,38 +391,23 @@ export function validateChange(
310
391
  // r63: Full-but-not-ready WARNING with skill guidance (predecessor r1 surface).
311
392
  if (opts.git !== undefined && binding !== null && stage === 'full') {
312
393
  const needs = readNeedsSpecsChange(fm);
313
- const landed = specsLanded(opts.git, binding);
394
+ // r119: judged under the change's own instance prefix.
395
+ const specsPrefix = opts.specsPrefix ?? DEFAULT_SPECS_PREFIX;
396
+ const landed = specsLanded(opts.git, binding, specsPrefix);
314
397
  if (!landed && needs) {
315
398
  push(
316
399
  'WARNING',
317
400
  'proposal.md',
318
- `specs not landed: change bound to \`${binding.branch}\` but no changes under \`llmanspec/specs/\` on its bound branch. Edit live specs there and commit (or set \`needs_specs_change\` to false in the frontmatter if this change has no live contract edits). Skill: llman-sdd-propose — do NOT re-run change start when already attached; start llman-sdd-apply once the specs-landed gate passes (see \`llman-sdd show <id>\` gateChecks).`,
401
+ `specs not landed: change bound to \`${binding.branch}\` but no changes under \`${specsPrefix}\` on its bound branch. Edit live specs there and commit (or set \`needs_specs_change\` to false in the frontmatter if this change has no live contract edits). Skill: llman-sdd-propose — do NOT re-run change start when already attached; start llman-sdd-apply once the specs-landed gate passes (see \`llman-sdd show <id>\` gateChecks).`,
319
402
  );
320
403
  }
321
404
  }
322
405
  }
323
406
 
324
- // pattern gate (predecessor change-id path). loadConfig compiles the pattern first
325
- // on the CLI path; this branch defends direct core callers that build a
326
- // ChangeCheckConfig without going through loadConfig.
327
- if (config.change_id_pattern) {
328
- try {
329
- const re = new RegExp(config.change_id_pattern, 'u');
330
- if (!re.test(id)) {
331
- push(
332
- 'ERROR',
333
- 'change-id',
334
- `Change id '${id}' does not match change_id.pattern '${config.change_id_pattern}' (active changes only; archived changes are not re-checked).`,
335
- );
336
- }
337
- } catch (error) {
338
- push(
339
- 'ERROR',
340
- 'change-id',
341
- `change_id.pattern is not a valid regular expression: ${(error as Error).message}`,
342
- );
343
- }
344
- }
407
+ // pattern gate (predecessor change-id path). loadConfig compiles the pattern
408
+ // first on the CLI path; this defends direct core callers that bypass it.
409
+ for (const issue of patternGate(id, config.change_id_pattern))
410
+ push(issue.level, issue.path, issue.message);
345
411
 
346
412
  // stage gate (predecessor --stage: artifact presence per gate).
347
413
  if (opts.stage !== undefined) {
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Cross-root same-value observation (validation r91 shape / scope-boundaries
3
+ * r114 requirement): the aggregate `validate --all-roots` report carries one
4
+ * `{namespace, value, roots[]}` entry per id shared by two or more instance
5
+ * roots, plus a summary count. Pure — the caller injects the per-root values.
6
+ *
7
+ * Single root is not an observation: fewer than two roots returns `undefined`
8
+ * so the field is never emitted (not even as an empty array) and single-root
9
+ * output stays byte-identical (r91 iron rule).
10
+ */
11
+
12
+ export type CrossRootNamespace = 'spec' | 'req' | 'change';
13
+
14
+ /** The subset of r91's declared namespace order: spec → req → change. */
15
+ const NAMESPACE_ORDER: readonly CrossRootNamespace[] = ['spec', 'req', 'change'];
16
+
17
+ const NAMESPACE_RANK: ReadonlyMap<CrossRootNamespace, number> = new Map(
18
+ NAMESPACE_ORDER.map((namespace, index) => [namespace, index]),
19
+ );
20
+
21
+ /** One instance root's id values, labelled as the aggregate reports it. */
22
+ export interface RootNamespaceValues {
23
+ /** Root label (repo-relative path; `.` for the discovery start root). */
24
+ root: string;
25
+ /** Capability (spec) ids of this root. */
26
+ specIds: readonly string[];
27
+ /** `@req:<id>` handles of this root. */
28
+ reqIds: readonly string[];
29
+ /** Change ids (active leaf names + archived base ids, r87 enumeration). */
30
+ changeIds: readonly string[];
31
+ }
32
+
33
+ export interface CrossRootCollision {
34
+ namespace: CrossRootNamespace;
35
+ value: string;
36
+ /** Roots carrying `value`, by root-relative-path order. */
37
+ roots: string[];
38
+ }
39
+
40
+ /** Code-unit comparison: deterministic regardless of host locale/ICU. */
41
+ function compareStrings(a: string, b: string): number {
42
+ return a < b ? -1 : a > b ? 1 : 0;
43
+ }
44
+
45
+ /**
46
+ * `{namespace, value, roots[]}` for every id present in ≥ 2 roots, sorted by
47
+ * namespace (r91 declaration order) then value, roots by relative-path order.
48
+ * Returns `undefined` for fewer than two roots (single-root omission, r91).
49
+ */
50
+ export function computeCrossRootCollisions(
51
+ facts: readonly RootNamespaceValues[],
52
+ ): CrossRootCollision[] | undefined {
53
+ if (facts.length < 2) return undefined;
54
+ const buckets = new Map<
55
+ string,
56
+ { namespace: CrossRootNamespace; value: string; roots: Set<string> }
57
+ >();
58
+ for (const fact of facts) {
59
+ const perNamespace: readonly (readonly [CrossRootNamespace, readonly string[]])[] = [
60
+ ['spec', fact.specIds],
61
+ ['req', fact.reqIds],
62
+ ['change', fact.changeIds],
63
+ ];
64
+ for (const [namespace, values] of perNamespace) {
65
+ for (const value of new Set(values)) {
66
+ if (value === '') continue;
67
+ const key = `${namespace}\u0000${value}`;
68
+ const bucket = buckets.get(key) ?? { namespace, value, roots: new Set<string>() };
69
+ bucket.roots.add(fact.root);
70
+ buckets.set(key, bucket);
71
+ }
72
+ }
73
+ }
74
+ return [...buckets.values()]
75
+ .filter((bucket) => bucket.roots.size > 1)
76
+ .map((bucket) => ({
77
+ namespace: bucket.namespace,
78
+ value: bucket.value,
79
+ roots: [...bucket.roots].toSorted(compareStrings),
80
+ }))
81
+ .toSorted(
82
+ (a, b) =>
83
+ (NAMESPACE_RANK.get(a.namespace) ?? 0) - (NAMESPACE_RANK.get(b.namespace) ?? 0) ||
84
+ compareStrings(a.value, b.value),
85
+ );
86
+ }
@@ -1,19 +1,34 @@
1
1
  import { assignSpecIds } from '../spec/assignSpecIds.ts';
2
2
  import { parseCapability } from '../spec/parser.ts';
3
+ import { type FsPort } from '../util/fsPort.ts';
3
4
  /**
4
5
  * Spec discovery (validation capability): walk llmanspec/specs/** for
5
6
  * .feature files via injected IO — core stays filesystem-free.
6
7
  */
7
8
  import type { SpecEntry } from './validate.ts';
8
9
 
9
- export interface DiscoveryIo {
10
- exists(path: string): boolean;
11
- isDirectory(path: string): boolean;
12
- listDir(path: string): string[];
13
- readText(path: string): string;
14
- }
10
+ export type DiscoveryIo = Pick<FsPort, 'exists' | 'isDirectory' | 'listDir' | 'readText'>;
15
11
 
16
12
  export function discoverSpecs(specsDir: string, io: DiscoveryIo): SpecEntry[] {
13
+ const normDir = specsDir.replace(/\\/g, '/').replace(/\/$/u, '');
14
+ const entries = discoverFeatureFiles(normDir, io).map((path) => ({
15
+ fileName: path,
16
+ doc: parseCapability(io.readText(path), path),
17
+ }));
18
+ assignSpecIds(entries, normDir);
19
+ return entries;
20
+ }
21
+
22
+ /**
23
+ * T24 single .feature discovery: sorted depth-first walk, `/`-joined paths
24
+ * under the backslash-normalized root. The freshness hash (context/tree) and
25
+ * the specHelpers loader delegate here so ordering and path shape cannot drift
26
+ * (spec-hash stability / index freshness depend on this exact order).
27
+ */
28
+ export function discoverFeatureFiles(
29
+ normDir: string,
30
+ io: Pick<DiscoveryIo, 'exists' | 'isDirectory' | 'listDir'>,
31
+ ): string[] {
17
32
  const walk = (dir: string): string[] => {
18
33
  if (!io.exists(dir) || !io.isDirectory(dir)) return [];
19
34
  const out: string[] = [];
@@ -24,11 +39,5 @@ export function discoverSpecs(specsDir: string, io: DiscoveryIo): SpecEntry[] {
24
39
  }
25
40
  return out;
26
41
  };
27
- const normDir = specsDir.replace(/\\/g, '/').replace(/\/$/u, '');
28
- const entries = walk(normDir).map((path) => ({
29
- fileName: path,
30
- doc: parseCapability(io.readText(path), path),
31
- }));
32
- assignSpecIds(entries, normDir);
33
- return entries;
42
+ return walk(normDir);
34
43
  }
@@ -1,3 +1,4 @@
1
+ import { type FsPort } from '../util/fsPort.ts';
1
2
  /**
2
3
  * Instance-root discovery (subproject-llmanspec-discovery, r91-r92): the
3
4
  * unified-root axiom — every llman-sdd operation targets one llmanspec/
@@ -6,11 +7,7 @@
6
7
  * shape. Pure: filesystem access only through the injected IO.
7
8
  */
8
9
 
9
- export interface RootsIo {
10
- exists(path: string): boolean;
11
- isDirectory(path: string): boolean;
12
- listDir(path: string): string[];
13
- }
10
+ export type RootsIo = Pick<FsPort, 'exists' | 'isDirectory' | 'listDir'>;
14
11
 
15
12
  export interface RootEntry {
16
13
  /** Directory containing the llmanspec/ instance (the instance root). */
@@ -1,14 +1,15 @@
1
+ import { SPECS_DIR } from '../change/lifecycle.ts';
1
2
  /**
2
3
  * Validation engine (validation capability): aggregates Phase-2 parse errors
3
4
  * plus the verdict-equivalent gates (r11/r12, ordered to match predecessor
4
5
  * `spec/validation.rs` observable issue order). Pure — filesystem access is
5
- * injected via SpecIo.
6
+ * pure.
6
7
  */
7
8
  import { assignSpecIds } from '../spec/assignSpecIds.ts';
8
9
  import type { CapabilityDoc } from '../spec/ir.ts';
9
10
  import { ruleHasRunnableScenario, specIdOf } from '../spec/ir.ts';
10
11
  import { buildReqRegistry } from '../spec/reqRegistry.ts';
11
- import { validateTransitionsForRule } from './transitions.ts';
12
+ import { validateTransitionsForRule } from './xstateTransitions.ts';
12
13
 
13
14
  export type ValidationLevel = 'ERROR' | 'WARNING' | 'INFO';
14
15
 
@@ -26,10 +27,6 @@ export interface SpecEntry {
26
27
  specId?: string;
27
28
  }
28
29
 
29
- export interface SpecIo {
30
- exists(path: string): boolean;
31
- }
32
-
33
30
  export interface SpecVerdict {
34
31
  fileName: string;
35
32
  capability: string;
@@ -50,11 +47,8 @@ const coveragePath = (cap: string): string => `${cap}/coverage`;
50
47
  export function validateCapability(
51
48
  entry: SpecEntry,
52
49
  duplicatesFor: (reqId: string) => boolean,
53
- _io: SpecIo,
54
50
  opts: {
55
- strict?: boolean;
56
51
  duplicateSpecId?: boolean;
57
- checkTransitions?: boolean;
58
52
  } = {},
59
53
  ): SpecVerdict {
60
54
  const { doc } = entry;
@@ -134,11 +128,10 @@ export function validateCapability(
134
128
  );
135
129
  }
136
130
 
137
- if (opts.checkTransitions === true) {
138
- for (const rule of rules) {
139
- for (const item of validateTransitionsForRule(cap, rule, true)) {
140
- push(item.level, item.id, item.message);
141
- }
131
+ // Transition-table gates (r104) are tag-scoped per scenario — no config switch.
132
+ for (const rule of rules) {
133
+ for (const item of validateTransitionsForRule(cap, rule)) {
134
+ push(item.level, item.id, item.message);
142
135
  }
143
136
  }
144
137
 
@@ -172,18 +165,16 @@ export function formatTotals(passed: number, failed: number, total: number): str
172
165
 
173
166
  export function validateAllSpecs(
174
167
  entries: readonly SpecEntry[],
175
- io: SpecIo,
176
- opts: { specsDir?: string; checkTransitions?: boolean } = {},
168
+ opts: { specsDir?: string } = {},
177
169
  ): ValidationReport {
178
- const specsDir = opts.specsDir ?? 'llmanspec/specs';
170
+ const specsDir = opts.specsDir ?? SPECS_DIR;
179
171
  const list: SpecEntry[] = entries.map((e) => ({ ...e }));
180
172
  const duplicateSpecIds = assignSpecIds(list, specsDir);
181
173
  const duplicatesFor = buildDuplicatesFor(list);
182
174
 
183
175
  const verdicts = list.map((e) =>
184
- validateCapability(e, duplicatesFor, io, {
176
+ validateCapability(e, duplicatesFor, {
185
177
  duplicateSpecId: duplicateSpecIds.has(specIdOf(e)),
186
- checkTransitions: opts.checkTransitions,
187
178
  }),
188
179
  );
189
180