@llman-sdd/core 0.9.0 → 0.10.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 (90) hide show
  1. package/package.json +2 -1
  2. package/src/archive/freeze.ts +45 -22
  3. package/src/archive/frozenCard.ts +3 -2
  4. package/src/archive/ignoreChain.ts +167 -0
  5. package/src/archive/sevenzip.ts +17 -8
  6. package/src/change/collect.ts +17 -14
  7. package/src/change/deps.ts +54 -0
  8. package/src/change/frontmatter.ts +36 -5
  9. package/src/change/lifecycle.ts +124 -20
  10. package/src/change/nextId.ts +14 -6
  11. package/src/config/changeId.ts +0 -6
  12. package/src/config/load.ts +2 -2
  13. package/src/config/schema.ts +3 -1
  14. package/src/context/indexStore.ts +14 -14
  15. package/src/context/sddState.ts +1 -13
  16. package/src/context/tree.ts +9 -19
  17. package/src/index.ts +33 -9
  18. package/src/init/defaultConfig.ts +14 -31
  19. package/src/init/init.ts +25 -27
  20. package/src/locale.ts +33 -0
  21. package/src/project/migrations.ts +79 -9
  22. package/src/report/graph/deps.ts +3 -38
  23. package/src/report/graph/nodes.ts +13 -19
  24. package/src/report/graph/types.ts +2 -6
  25. package/src/report/show.ts +16 -8
  26. package/src/report/specHelpers.ts +22 -28
  27. package/src/review/review.ts +18 -30
  28. package/src/self/completion.ts +206 -0
  29. package/src/spec/assignSpecIds.ts +9 -1
  30. package/src/spec/authoring.ts +11 -11
  31. package/src/spec/parser.ts +3 -1
  32. package/src/templates/skills.ts +3 -23
  33. package/src/util/datedId.ts +18 -0
  34. package/src/util/fsPort.ts +24 -0
  35. package/src/util/nextNumber.ts +30 -0
  36. package/src/util/semver.ts +21 -0
  37. package/src/validation/changeCheck.ts +133 -67
  38. package/src/validation/crossRoot.ts +86 -0
  39. package/src/validation/discover.ts +22 -13
  40. package/src/validation/roots.ts +2 -5
  41. package/src/validation/validate.ts +4 -9
  42. package/src/validation/xstateTransitions.ts +0 -32
  43. package/templates/zh-Hans/skills/llman-sdd-apply-cycle.md +9 -7
  44. package/templates/zh-Hans/skills/llman-sdd-apply.md +5 -5
  45. package/templates/zh-Hans/skills/llman-sdd-archive.md +11 -2
  46. package/templates/zh-Hans/skills/llman-sdd-continue.md +1 -1
  47. package/templates/zh-Hans/skills/llman-sdd-draft.md +1 -1
  48. package/templates/zh-Hans/skills/llman-sdd-explore.md +2 -2
  49. package/templates/zh-Hans/skills/llman-sdd-ff.md +1 -1
  50. package/templates/zh-Hans/skills/llman-sdd-propose.md +8 -6
  51. package/templates/zh-Hans/skills/llman-sdd-quick.md +1 -1
  52. package/templates/zh-Hans/skills/llman-sdd-validate.md +1 -1
  53. package/templates/zh-Hans/skills/llman-sdd-verify.md +2 -2
  54. package/templates/zh-Hans/skills/llman-sdd-wayfinder.md +1 -1
  55. package/templates/zh-Hans/units/skills/git-native-flow.md +12 -6
  56. package/templates/zh-Hans/units/skills/index-fallback.md +1 -0
  57. package/templates/zh-Hans/units/skills/structured-protocol.md +1 -6
  58. package/templates/zh-Hans/units/spec/feature-contract.md +5 -33
  59. package/src/templates/locale.ts +0 -24
  60. package/templates/en/agents-root-stub.md +0 -9
  61. package/templates/en/llmanspec-agents-stub.md +0 -6
  62. package/templates/en/skills/llman-sdd-apply-cycle.md +0 -67
  63. package/templates/en/skills/llman-sdd-apply.md +0 -117
  64. package/templates/en/skills/llman-sdd-arch-review.md +0 -58
  65. package/templates/en/skills/llman-sdd-archive.md +0 -70
  66. package/templates/en/skills/llman-sdd-continue.md +0 -34
  67. package/templates/en/skills/llman-sdd-draft.md +0 -53
  68. package/templates/en/skills/llman-sdd-explore.md +0 -64
  69. package/templates/en/skills/llman-sdd-ff.md +0 -33
  70. package/templates/en/skills/llman-sdd-graph.md +0 -56
  71. package/templates/en/skills/llman-sdd-propose.md +0 -105
  72. package/templates/en/skills/llman-sdd-quick.md +0 -41
  73. package/templates/en/skills/llman-sdd-research.md +0 -35
  74. package/templates/en/skills/llman-sdd-specs-compact.md +0 -41
  75. package/templates/en/skills/llman-sdd-validate.md +0 -28
  76. package/templates/en/skills/llman-sdd-verify.md +0 -77
  77. package/templates/en/skills/llman-sdd-wayfinder.md +0 -83
  78. package/templates/en/units/skills/cli-footer.md +0 -2
  79. package/templates/en/units/skills/ethics-governance.md +0 -6
  80. package/templates/en/units/skills/git-native-flow-brief.md +0 -10
  81. package/templates/en/units/skills/git-native-flow.md +0 -50
  82. package/templates/en/units/skills/human-readable-summary.md +0 -9
  83. package/templates/en/units/skills/stage-guard.md +0 -17
  84. package/templates/en/units/skills/structured-protocol.md +0 -24
  85. package/templates/en/units/skills/validation-hints.md +0 -20
  86. package/templates/en/units/skills/version-drift.md +0 -3
  87. package/templates/en/units/spec/feature-contract.md +0 -38
  88. package/templates/en/units/workflow/archive-freeze-guidance.md +0 -9
  89. package/templates/zh-Hans/units/skills/git-native-flow-brief.md +0 -10
  90. 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,8 +1,9 @@
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';
@@ -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,7 +47,6 @@ 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
51
  duplicateSpecId?: boolean;
56
52
  } = {},
@@ -169,16 +165,15 @@ export function formatTotals(passed: number, failed: number, total: number): str
169
165
 
170
166
  export function validateAllSpecs(
171
167
  entries: readonly SpecEntry[],
172
- io: SpecIo,
173
168
  opts: { specsDir?: string } = {},
174
169
  ): ValidationReport {
175
- const specsDir = opts.specsDir ?? 'llmanspec/specs';
170
+ const specsDir = opts.specsDir ?? SPECS_DIR;
176
171
  const list: SpecEntry[] = entries.map((e) => ({ ...e }));
177
172
  const duplicateSpecIds = assignSpecIds(list, specsDir);
178
173
  const duplicatesFor = buildDuplicatesFor(list);
179
174
 
180
175
  const verdicts = list.map((e) =>
181
- validateCapability(e, duplicatesFor, io, {
176
+ validateCapability(e, duplicatesFor, {
182
177
  duplicateSpecId: duplicateSpecIds.has(specIdOf(e)),
183
178
  }),
184
179
  );
@@ -318,38 +318,6 @@ export function validateTransitionsForRule(cap: string, rule: RuleIR): Validatio
318
318
  return items;
319
319
  }
320
320
 
321
- /** Authoring self-check: transitions only (synthetic scenario). */
322
- export function validateTransitionTableSelfCheck(
323
- transitions: readonly TransitionEdge[],
324
- scenarioName = 'authoring-check',
325
- ): void {
326
- const sc: ScenarioIR = {
327
- name: scenarioName,
328
- tags: [],
329
- runnable: true,
330
- stepCount: 3,
331
- steps: [
332
- { kind: 'given', text: 'state <from>' },
333
- { kind: 'when', text: 'event <event>' },
334
- { kind: 'then', text: 'state <to>' },
335
- ],
336
- statement: '',
337
- isOutline: true,
338
- examples: [
339
- {
340
- name: '',
341
- headers: ['from', 'event', 'to'],
342
- rows: transitions.map((t) => [t.from, t.event, t.to]),
343
- },
344
- ],
345
- };
346
- const rule = { reqId: 'r0', title: '', description: '', scenarios: [], tags: [] } as RuleIR;
347
- const issues = validateTransitionScenario('authoring', rule, sc);
348
- if (issues.length > 0) {
349
- throw new Error(issues[0]?.message ?? 'invalid transition table');
350
- }
351
- }
352
-
353
321
  export function parseTransitionExpr(expr: string): TransitionEdge {
354
322
  const trimmed = expr.trim();
355
323
  const m = trimmed.match(/^([^:]+):([\w-]+)(?:\[([^\]]+)\])?->(.+)$/u);
@@ -53,15 +53,17 @@ git branch -D <feature-branch> # squash 后分支不再是 main 祖先,-d
53
53
  push / PR 仅当用户明确要求。
54
54
 
55
55
  ## 硬约束
56
- - **不得问**“要不得继续”——除非 blocker,一路到底。
56
+ - **不得问“是否继续”**——除非 blocker,一路到底。
57
57
  - **不得切换**其他 change,直到本 change 归档并提交。
58
58
  - **不得**写 `changes/<id>/specs/`;**不得默认 push/PR**。
59
59
 
60
- ## Ethics Governance
61
- - `ethics.risk_level`: medium
62
- - `ethics.prohibited_actions`: 未绑定分支 / specs-landed 门未过就实施、未 `readyToImplement=true` 就归档、中途切换 change、写 `changes/<id>/specs/`、未校验就提交、默认 push/PR
63
- - `ethics.required_evidence`: `readyToImplement=true`、validate --strict 通过、tasks 全勾、finalize/archive 成功
64
- - `ethics.refusal_contract`: 自修复 8 轮仍失败 → 报告 blocker,不得强行归档
65
- - `ethics.escalation_policy`: 改动 SDD 工作流 spec/模板时,归档前暂停请用户确认
60
+ {{ unit("skills/ethics-governance") }}
61
+
62
+ ### Ethics Governance 覆写
63
+ 本技能含 finalize 合并等不可逆动作,以下键覆写共享单元:
64
+
65
+ - `ethics.risk_level`: medium。
66
+ - `ethics.required_evidence`: 另须 `readyToImplement=true` 与 tasks 全勾。
67
+ - `ethics.escalation_policy`: 归档前暂停并请用户确认。
66
68
 
67
69
  {{ unit("skills/cli-footer") }}
@@ -7,11 +7,11 @@ metadata:
7
7
 
8
8
  # LLMAN SDD Apply
9
9
 
10
- 按顺序在一轮内完成 `llmanspec/changes/<id>/tasks.md` 的所有任务:实现 → 补测试/验收 → 跑门禁 → 失败自修复重跑 → 全过后报告。除非明确 blocker,不得中途问“要不得继续”**。
10
+ 按顺序在一轮内完成 `llmanspec/changes/<id>/tasks.md` 的所有任务:实现 → 补测试/验收 → 跑门禁 → 失败自修复重跑 → 全过后报告。除非明确 blocker,**不得中途问“是否继续”**。
11
11
 
12
12
  ## Pipeline 位置
13
13
 
14
- {{ unit("skills/git-native-flow-brief") }}
14
+ {{ unit("skills/git-native-flow") }}
15
15
 
16
16
  ```mermaid
17
17
  flowchart LR
@@ -52,7 +52,7 @@ flowchart LR
52
52
  - 确认在经 `llman-sdd change start <id>` 或 `change attach <id>` 绑定的非默认分支上(仅重绑用 `--force`)。分支上的 specs 即唯一事实来源——不得在 `changes/<id>/specs/` 下编写。
53
53
  {{ unit("skills/stage-guard") }}
54
54
  - 用 `llman-sdd context --task "<proposal 目标>" --paths "<specs scope>"` 获取匹配 `<paths>` 的 specs。
55
- - context 不可用 → 先 `llman-sdd index check`:stale/缺失则 `llman-sdd index rebuild` 后重试;fresh 仍不可用(`LLMAN_SDD_INDEX_CHAT_MODEL` 未设)→ 改用 `llman-sdd list --specs` + 直读 `.feature`——勿循环 rebuild。
55
+ - {{ unit("skills/index-fallback") }}
56
56
 
57
57
  ### 2) 通读事实来源工件
58
58
  - `llmanspec/changes/<id>/proposal.md`、`design.md`(如有)、`tasks.md`
@@ -71,7 +71,7 @@ flowchart LR
71
71
  4. task 不明、遇 blocker、或 specs/design 与现实不一致 → STOP 报告,不自行假定。
72
72
 
73
73
  ### 5) 验证与自修复循环(每个 task 或每批 task 后跑一次)
74
- - 测试与静态门禁:执行本仓已声明的验证手段——以仓库文档与配置记载为准;已配置 `specs.check_command` 的项目,以 `llman-sdd config` 读得的命令为准。仓库未声明时,询问用户;不假定任何具体任务工具存在。
74
+ - 测试与静态门禁:执行本仓已声明的验证手段——以仓库文档与配置记载为准;已配置 `specs.check_command` 的项目,以 `llmanspec/config.yaml` 的 `specs.check_command` 为准(`llman-sdd config` 只报 specs 开关,不输出该命令)。仓库未声明时,询问用户;不假定任何具体任务工具存在。
75
75
  - 分支上按需编辑 `llmanspec/specs/<capability>.feature`(扁平或目录主文件;统一原生分层:`@req:<id>` 挂 `规则:` 块头、嵌套 `场景:` 为可执行示例),spec 改动后跑 `llman-sdd validate --specs`;分支上可自由提交。
76
76
  - SDD 校验:`llman-sdd validate <id> --strict`
77
77
 
@@ -88,7 +88,7 @@ flowchart LR
88
88
  - 前后对比类判据(计数、基线)必须 在 change 分支上测量(相对现算 merge-base);默认分支测得的值通常恒为基线,不构成证据。
89
89
  - 重构或批量替换类 task:必须 对比改动前后测试用例数;门禁全绿但用例数下降视为失败。
90
90
 
91
- **失败 → 自修复(不得问要不得继续):**
91
+ **失败 → 自修复(不得问是否继续):**
92
92
  1. 解析失败原因(测试 / lint / 格式 / 校验)。
93
93
  2. 判定是否难定位 bug(原因不明 / 间歇 flake / 回归看不穿):
94
94
  - **不是**(明确的 lint/格式/编译/校验错误):最小修复(不扩范围),先重跑最小失败复现命令,再重跑全部门禁。
@@ -24,7 +24,7 @@ flowchart LR
24
24
 
25
25
  - **必须先 verify 全绿**;**须已绑定分支**(`change start` / `attach`),无绑定 STOP。
26
26
  - 每个 change 归档前必须通过 `llman-sdd validate <id> --strict`。
27
- - 不得问“要不得继续”**:批量归档一路执行到底,除非遇到无法自动解决的错误。
27
+ - **不得问“是否继续”**:批量归档一路执行到底,除非遇到无法自动解决的错误。
28
28
  - **收尾不默认导向 PR/push**:CLI 本地合并(默认 squash)+ 一次性收口提交。push / PR 仅在用户或项目明确要求远程审查时做——**Agent 不得** 默认 push 或建 PR。
29
29
 
30
30
  ## 步骤
@@ -61,7 +61,16 @@ flowchart LR
61
61
  - **破坏性合约变更**(移除/重命名 frontmatter 字段、命令、tag 或 stage 值域)必须 提供 `migrations/v<from>-v<to>/` 升级路径(README + 一次性脚本随仓库发布)——收口前确认存在。
62
62
  - **archived `depends_on`**:archive 把 change 目录改名为 `archive/YYYY-MM-DD-<id>`;validate 把指向 archived/frozen id 的 `depends_on` 识别为 INFO(非 ERROR),**无需**手动更新其它 change 的 frontmatter。
63
63
 
64
- {{ unit("workflow/archive-freeze-guidance") }}
64
+ ## Archive 冷备引导
65
+ - archive 目录过大时用冷备维护(冻结 = 正文入 7z 冷备 + 以 `<YYYY-MM-DD>-<id>.yaml` 平铺索引卡替代目录,卡为单文档纯 YAML、仅含 title 与 depends_on):
66
+ - 预览冻结候选:`llman-sdd archive freeze --dry-run`
67
+ - 冻结旧归档:`llman-sdd archive freeze --before <YYYY-MM-DD> --keep-recent <N>`
68
+ - 列出已冻结条目:`llman-sdd archive freeze --list`
69
+ - 需要恢复时:`llman-sdd archive thaw --change <YYYY-MM-DD-id>`(正文解回目录并移除平铺卡)
70
+ - freeze/thaw 仅用于日期归档目录(`YYYY-MM-DD-*`);宜保留最近 2 个目录不冻结。
71
+ - 平铺索引卡常驻磁盘:title(frontmatter `title` 非空时优先,否则取 proposal H1)与 depends_on(graph 依赖边种子)可 grep、可追溯;
72
+ id 与日期由文件名隐含——冻结 change 的用途与依赖关系无需解冻即可查阅,正文在 7z 冷备按需取用。
73
+ - 在非主检出(不持有默认分支的 worktree)运行时打印警告(仅提示、不阻断)——有意为之才在该处继续。
65
74
 
66
75
  {{ unit("skills/cli-footer") }}
67
76
 
@@ -20,7 +20,7 @@ metadata:
20
20
  4) `llman-sdd change start <id>`(分支已存在用 `change attach <id>`)——绑定分支
21
21
  5) 在**绑定分支**编辑 `llmanspec/specs/<capability>.feature`(扁平,或目录主文件)并 commit——提交 specs(无合约变更设 `needs_specs_change: false`)
22
22
  4. 只创建**一个**缺失工件(或一次绑定分支上的 spec 编辑)。
23
- - 不得写应用代码;不得**建 `changes/<id>/specs/`;不得**在 start/attach 前改 `llmanspec/specs/**`。
23
+ - 不得写应用代码;**不得**建 `changes/<id>/specs/`;**不得**在 start/attach 前改 `llmanspec/specs/**`。
24
24
  5. 工件已齐全时,按 `llman-sdd show <id> --output json` 宜接的下一步:
25
25
  - specs-landed 门未过 → 先提交 specs(或 `needs_specs_change: false`);不得提示可进 apply
26
26
  - specs-landed 门已绿(即使实施中期 `readyToImplement=false`、tasks 未完)→ `llman-sdd-apply`