@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,14 +1,16 @@
1
1
  /**
2
- * Versioned migration registry (project migrate, drop-review-stamp-and-scope
3
- * follow-up): one entry per supported upgrade path. Prompt bodies are English
2
+ * Per-version migration registry (project migrate, migrate-prompt-per-version):
3
+ * each release declares its own migration items, and a range query `(from, to]`
4
+ * aggregates every registered version in between. Prompt bodies are English
4
5
  * per the house language convention (CLI output language) and are meant to be
5
6
  * handed to any agent verbatim — steps are executable commands, checks are
6
7
  * user-verifiable assertions. Pure: no IO, no clock.
7
8
  */
9
+ import { compareSemver as compareVersions } from '../util/semver.ts';
8
10
 
9
- export interface MigrationEntry {
10
- /** Registry key, shape `<from>-><to>` (exact-match lookup). */
11
- id: string;
11
+ export { compareVersions };
12
+
13
+ export interface MigrationItem {
12
14
  title: string;
13
15
  /** Agent-executable commands, in order. */
14
16
  steps: readonly string[];
@@ -16,86 +18,220 @@ export interface MigrationEntry {
16
18
  checks: readonly string[];
17
19
  }
18
20
 
19
- export const MIGRATIONS: readonly MigrationEntry[] = [
21
+ export interface MigrationDoc {
22
+ /** Release version this migration set belongs to, `x.y.z`. */
23
+ version: string;
24
+ items: readonly MigrationItem[];
25
+ }
26
+
27
+ export const MIGRATIONS: readonly MigrationDoc[] = [
20
28
  {
21
- id: '0.8.1->0.9.0',
22
- title: 'Retire `# capability:` header; assign spec ids from paths (r101)',
23
- steps: [
24
- 'Run `llman-sdd project migrate strip-legacy-headers --dry-run` to preview spec header strips.',
25
- 'Run `llman-sdd project migrate strip-legacy-headers` to remove `# capability:` (and any remaining `# scope:` / `# reviewed-through:`) lines.',
26
- 'Ensure each `功能:` / `Feature:` title equals the assigned spec id (`llman-sdd list --specs` for ids).',
27
- 'Run `llman-sdd init --update` to refresh managed skills and feature-contract guidance.',
28
- 'Run `llman-sdd validate --all --strict` — it must pass.',
29
- ],
30
- checks: [
31
- 'No `# capability:` lines remain under `llmanspec/specs/**`.',
32
- 'Each spec file `功能:` title matches `llman-sdd show <spec-id>` id.',
33
- '`llman-sdd list --specs` reports stable ids for flat and directory layouts.',
29
+ version: '0.8.0',
30
+ items: [
31
+ {
32
+ title: 'Governance metadata retirement (`# reviewed-through:` stamp & `# scope:` header)',
33
+ steps: [
34
+ 'Run `llman-sdd project migrate strip-legacy-headers --dry-run` to preview the affected spec files.',
35
+ 'Run `llman-sdd project migrate strip-legacy-headers` to strip legacy `# scope:` / `# reviewed-through:` / `# capability:` header comment lines (idempotent).',
36
+ 'Run `llman-sdd init --update` to refresh the managed AGENTS blocks and agent skills.',
37
+ 'Run `llman-sdd validate --all --strict` — it must pass.',
38
+ ],
39
+ checks: [
40
+ 'No `# scope:` / `# reviewed-through:` header lines remain under `llmanspec/specs/**`.',
41
+ '`llman-sdd review` signal kinds are exactly unbound / locked / validate (no `stale`).',
42
+ '`llman-sdd validate --specs --json` output carries no `staleness` key.',
43
+ 'A subsequent `llman-sdd` invocation prints no version-drift NOTE.',
44
+ ],
45
+ },
34
46
  ],
35
47
  },
36
48
  {
37
- id: '0.7.5->0.8.0',
38
- title: 'Governance metadata retirement (`# reviewed-through:` stamp & `# scope:` header)',
39
- steps: [
40
- 'Run `llman-sdd project migrate strip-legacy-headers --dry-run` to preview the affected spec files.',
41
- 'Run `llman-sdd project migrate strip-legacy-headers` to strip legacy `# scope:` / `# reviewed-through:` / `# capability:` header comment lines (idempotent).',
42
- 'Run `llman-sdd init --update` to refresh the managed AGENTS blocks and agent skills.',
43
- 'Run `llman-sdd validate --all --strict` — it must pass.',
49
+ version: '0.9.0',
50
+ items: [
51
+ {
52
+ title: 'Retire `# capability:` header; assign spec ids from paths (r101)',
53
+ steps: [
54
+ 'Run `llman-sdd project migrate strip-legacy-headers --dry-run` to preview spec header strips.',
55
+ 'Run `llman-sdd project migrate strip-legacy-headers` to remove `# capability:` (and any remaining `# scope:` / `# reviewed-through:`) lines.',
56
+ 'Ensure each `功能:` / `Feature:` title equals the assigned spec id (`llman-sdd list --specs` for ids).',
57
+ 'Run `llman-sdd init --update` to refresh managed skills and feature-contract guidance.',
58
+ 'Run `llman-sdd validate --all --strict` — it must pass.',
59
+ ],
60
+ checks: [
61
+ 'No `# capability:` lines remain under `llmanspec/specs/**`.',
62
+ 'Each spec file `功能:` title matches `llman-sdd show <spec-id>` id.',
63
+ '`llman-sdd list --specs` reports stable ids for flat and directory layouts.',
64
+ ],
65
+ },
66
+ {
67
+ title: '`specs.check_transitions` removed — transition validation is tag-scoped',
68
+ steps: [
69
+ 'Delete `specs.check_transitions` from `llmanspec/config.yaml` (any leftover value is stripped at load with a WARNING).',
70
+ 'Tag example tables that merely look like transition tables with `@no-transitions` on the scenario outline.',
71
+ 'Tag real transition tables whose column names miss the sniff aliases with `@transitions` to force validation.',
72
+ 'Run `llman-sdd spec transitions` for the authoritative aliases, tags and E1–E4 gates.',
73
+ 'Run `llman-sdd validate --all --strict` — it must pass.',
74
+ ],
75
+ checks: [
76
+ '`llmanspec/config.yaml` carries no `specs.check_transitions` key and loading prints no strip WARNING.',
77
+ 'Untagged example tables hitting at least two of the from/event/to alias families pass E1–E4.',
78
+ ],
79
+ },
80
+ {
81
+ title: 'init locale precedence chain and per-workspace `--update` sweep',
82
+ steps: [
83
+ 'Add an explicit `locale:` key to `llmanspec/config.yaml` (e.g. `locale: zh-Hans`) to pin the rendering language and silence the missing-key WARNING.',
84
+ 'Run `llman-sdd init --update` from any instance root — it refreshes managed blocks of every discovered root in the workspace (skills stay repo-root only).',
85
+ 'Run `llman-sdd validate --all --strict` — it must pass.',
86
+ ],
87
+ checks: [
88
+ '`llmanspec/config.yaml` carries an explicit `locale:` key; `init --update` prints no locale WARNING.',
89
+ 'Managed AGENTS.md blocks render in the configured locale across every workspace instance.',
90
+ ],
91
+ },
44
92
  ],
45
- checks: [
46
- 'No `# scope:` / `# reviewed-through:` header lines remain under `llmanspec/specs/**`.',
47
- '`llman-sdd review` signal kinds are exactly unbound / locked / validate (no `stale`).',
48
- '`llman-sdd validate --specs --json` output carries no `staleness` key.',
49
- 'A subsequent `llman-sdd` invocation prints no version-drift NOTE.',
93
+ },
94
+ {
95
+ version: '0.10.0',
96
+ items: [
97
+ {
98
+ title:
99
+ 'Templates go zh-Hans single-track: the `en` tree is gone and unknown locales normalize to `zh-Hans`',
100
+ steps: [
101
+ 'Optionally pin `locale: zh-Hans` in `llmanspec/config.yaml` — `en` and any unknown value now render Chinese.',
102
+ 'Run `llman-sdd init --update` and commit the refreshed managed AGENTS blocks and `.agents/skills/**`.',
103
+ 'Re-run `llman-sdd spec skeleton <name>` where a skeleton dialect matters — it now emits `# language: zh-CN`.',
104
+ 'Run `llman-sdd validate --all --strict` — it must pass.',
105
+ ],
106
+ checks: [
107
+ 'No English-rendered managed block or skill remains after `init --update`.',
108
+ '`llman-sdd spec skeleton <name>` emits `# language: zh-CN`.',
109
+ 'A missing template resource makes `init` fail instead of silently skipping.',
110
+ ],
111
+ },
112
+ {
113
+ title:
114
+ 'Close-out gate tightened: a change whose contract is unchanged can no longer be closed out',
115
+ steps: [
116
+ 'For a change that touches the contract, land and commit your `llmanspec/specs/**` edits on the bound branch before closing out.',
117
+ 'Set `needs_specs_change: false` in `proposal.md` frontmatter only when the change genuinely needs no contract edit.',
118
+ 'Keep `tasks.md` fully checked whenever the file exists.',
119
+ 'Run `llman-sdd change finalize <id>` (or `archive`) — the gate runs before any merge and writes nothing on failure.',
120
+ ],
121
+ checks: [
122
+ '`llman-sdd change finalize <id>` on a spec-unlanded change fails with zero writes.',
123
+ 'A change that landed its specs, or declared `needs_specs_change: false`, still closes out cleanly.',
124
+ ],
125
+ },
126
+ {
127
+ title:
128
+ 'Usage errors now exit 2 (bare parent groups, missing arguments, invalid enum values)',
129
+ steps: [
130
+ 'Update scripts that keyed on exit code 1 for missing arguments or invalid enum values — those now exit 2.',
131
+ 'Expect bare invocation of the five pure parent groups (`change`, `spec`, `project`, `archive`, `index`) to print a usage error and exit 2; `config` keeps its overview action.',
132
+ 'Root bare invocation (`llman-sdd`) still exits 0, but help now goes to stdout.',
133
+ 'Run `llman-sdd validate --all --strict` — it must pass.',
134
+ ],
135
+ checks: [
136
+ '`llman-sdd change` exits 2 and `llman-sdd` exits 0 with help on stdout.',
137
+ '`llman-sdd list --sort bogus` exits 2 (previously 1); domain errors still exit 1.',
138
+ ],
139
+ },
140
+ {
141
+ title:
142
+ 'Read-only commands resolve the nearest instance root (`--directory` on every command)',
143
+ steps: [
144
+ 'Note that `list`, `show`, `graph`, `review`, `config`, `index` and `context` now start from `--directory <path>` (default cwd) and walk up to the nearest instance root.',
145
+ 'Re-check scripts that invoked read-only commands from a subdirectory — they no longer return empty results or leak `ENOENT`.',
146
+ 'Use `--directory <path>` on any command to pin the root explicitly.',
147
+ 'Run `llman-sdd validate --all --strict` — it must pass.',
148
+ ],
149
+ checks: [
150
+ 'From a subdirectory, `llman-sdd list` and `llman-sdd config` match the repo-root output.',
151
+ 'With no instance root above, the error is `no llmanspec root at or above <path>` (never `ENOENT`).',
152
+ 'A single-root repo keeps byte-identical output.',
153
+ ],
154
+ },
155
+ {
156
+ title:
157
+ '`--backend` normalization: empty values, case and the `page-index` alias are accepted',
158
+ steps: [
159
+ 'No action required — an empty `--backend`, an empty `LLMAN_SDD_INDEX_BACKEND`, `PAGEINDEX`, `page-index` and padded values now all select the pageindex backend.',
160
+ 'Keep using `index rebuild --backend` / `context --backend` unchanged.',
161
+ 'Run `llman-sdd validate --all --strict` — it must pass.',
162
+ ],
163
+ checks: [
164
+ '`llman-sdd index rebuild --backend page-index` and an empty `--backend` succeed (previously exit 1).',
165
+ 'A legacy `rag/` directory never satisfies pageindex freshness.',
166
+ ],
167
+ },
50
168
  ],
51
169
  },
52
170
  ];
53
171
 
172
+ const VERSION_RE = /^\d+\.\d+\.\d+$/u;
54
173
  const EXPR_RE = /^\d+\.\d+\.\d+->\d+\.\d+\.\d+$/u;
55
174
 
56
- /** Exact-match lookup; null when the expr is well-formed but unknown. */
57
- export function findMigration(expr: string): MigrationEntry | null {
58
- return MIGRATIONS.find((m) => m.id === expr) ?? null;
175
+ export function isValidVersion(version: string): boolean {
176
+ return VERSION_RE.test(version);
59
177
  }
60
178
 
61
- export function knownMigrationIds(): string[] {
62
- return MIGRATIONS.map((m) => m.id);
179
+ /** Versions `(from, to]` that carry registered migrations, ascending. */
180
+ export function resolveMigrations(from: string, to: string): MigrationDoc[] {
181
+ return MIGRATIONS.filter(
182
+ (d) => compareVersions(d.version, from) > 0 && compareVersions(d.version, to) <= 0,
183
+ ).toSorted((a, b) => compareVersions(a.version, b.version));
63
184
  }
64
185
 
65
- export function isValidMigrationExpr(expr: string): boolean {
66
- return EXPR_RE.test(expr);
186
+ /** Parse a deprecated `'<from>-><to>'` expression; null when malformed. */
187
+ export function parseVersionExpr(expr: string): { from: string; to: string } | null {
188
+ if (!EXPR_RE.test(expr)) return null;
189
+ const [from, to] = expr.split('->') as [string, string];
190
+ return { from, to };
67
191
  }
68
192
 
69
- /** Agent-facing playbook for one migration — deterministic, English. */
70
- export function migrationPrompt(entry: MigrationEntry): string {
71
- const steps = entry.steps.map((s, i) => `${i + 1}. ${s}`).join('\n');
72
- const checks = entry.checks.map((c) => `- [ ] ${c}`).join('\n');
73
- return [
74
- `# Migration playbook: ${entry.id}`,
75
- '',
76
- `${entry.title}.`,
77
- '',
78
- '## Steps',
79
- '',
80
- steps,
81
- '',
82
- '## Verification checklist',
83
- '',
84
- checks,
85
- '',
86
- ].join('\n');
193
+ export function knownMigrationVersions(): string[] {
194
+ return MIGRATIONS.map((d) => d.version);
195
+ }
196
+
197
+ /** Agent-facing playbook for a range — deterministic, English. */
198
+ export function migrationPrompt(from: string, to: string): string {
199
+ const docs = resolveMigrations(from, to);
200
+ if (docs.length === 0) {
201
+ return `No documented migrations for ${from} -> ${to}.\n`;
202
+ }
203
+ const sections = docs.map((doc) => {
204
+ const items = doc.items.map((item) => {
205
+ const steps = item.steps.map((s, i) => `${i + 1}. ${s}`).join('\n');
206
+ const checks = item.checks.map((c) => `- [ ] ${c}`).join('\n');
207
+ return [
208
+ `### ${item.title}`,
209
+ '',
210
+ '#### Steps',
211
+ '',
212
+ steps,
213
+ '',
214
+ '#### Verification checklist',
215
+ '',
216
+ checks,
217
+ '',
218
+ ].join('\n');
219
+ });
220
+ return [`## ${doc.version}`, '', items.join('\n')].join('\n');
221
+ });
222
+ return [`# Migration playbook: ${from} -> ${to}`, '', sections.join('\n---\n\n'), ''].join('\n');
87
223
  }
88
224
 
89
225
  /** Lines appended to the bare `project migrate` overview. */
90
226
  export function migrationOverviewLines(): string[] {
91
- const ids = knownMigrationIds()
92
- .map((id) => ` - ${id}`)
227
+ const versions = knownMigrationVersions()
228
+ .map((v) => ` - ${v}`)
93
229
  .join('\n');
94
230
  return [
95
231
  '',
96
232
  'Versioned migration playbooks (agent-readable, via `project migrate prompt`):',
97
- ids,
98
- "Usage: llman-sdd project migrate prompt --version-expr '<from>-><to>'",
233
+ versions,
234
+ 'Usage: llman-sdd project migrate prompt --from-version <from> --to-version <to>',
99
235
  'Mechanical spec-header strip: llman-sdd project migrate strip-legacy-headers [--dry-run]',
100
236
  ];
101
237
  }
@@ -1,41 +1,6 @@
1
- /** Extract depends_on entries (flow + block styles, r30). */
2
- import { extractFrontmatter } from '../../change/frontmatter.ts';
3
-
4
- /**
5
- * r54 dual-format card reading: a fence-free frozen card is a plain YAML doc
6
- * whose FIRST line opens with `title:`/`depends_on:` — feed the whole text to
7
- * the same depends_on scan. Proposal.md bodies never open with those keys, so
8
- * no misfire.
9
- */
10
- function cardYamlSource(input: string): string | null {
11
- const firstLine = input.trimStart().split('\n')[0] ?? '';
12
- return /^(title|depends_on):/u.test(firstLine) ? input : null;
13
- }
1
+ /** Extract depends_on entries (r30): lenient policy over the shared reader. */
2
+ import { readDepsLenient } from '../../change/deps.ts';
14
3
 
15
4
  export function parseDeps(proposal: string): string[] {
16
- const fm = extractFrontmatter(proposal) ?? cardYamlSource(proposal);
17
- const deps: string[] = [];
18
- if (!fm) return deps;
19
- let inDeps = false;
20
- for (const line of fm.split('\n')) {
21
- const flow = line.match(/^depends_on:\s*\[([^\]]*)\]\s*$/u);
22
- if (flow) {
23
- for (const item of flow[1]?.split(',') ?? []) {
24
- const dep = item.trim().replaceAll(/^['"]|['"]$/gu, '');
25
- if (dep !== '' && !/^[0-9]+$/u.test(dep)) deps.push(dep);
26
- }
27
- inDeps = false;
28
- continue;
29
- }
30
- if (/^depends_on:\s*$/u.test(line)) {
31
- inDeps = true;
32
- continue;
33
- }
34
- if (inDeps) {
35
- const m = line.match(/^\s*-\s+(\S+)/u);
36
- if (m?.[1] && !/^[0-9]+$/u.test(m[1])) deps.push(m[1]);
37
- else if (line.trim() !== '') inDeps = false;
38
- }
39
- }
40
- return deps;
5
+ return readDepsLenient(proposal);
41
6
  }
@@ -1,10 +1,11 @@
1
1
  import { frozenCardIdOf, isFrozenCard } from '../../archive/frozenCard.ts';
2
+ import { walkActiveChangeDirs } from '../../change/collect.ts';
2
3
  import { CHANGES_DIR } from '../../change/lifecycle.ts';
4
+ import { datedIdOf } from '../../util/datedId.ts';
3
5
  import type { GraphFsIo, GraphNode, ScopeKind } from './types.ts';
4
6
 
5
7
  function extractArchivedId(name: string): string | null {
6
- const m = name.match(/^\d{4}-\d{2}-\d{2}-(.+)$/u);
7
- return m ? (m[1] ?? null) : null;
8
+ return datedIdOf(name);
8
9
  }
9
10
 
10
11
  /** Active nodes: dirs (recursively, depth-limited) with a proposal.md (r58). */
@@ -13,24 +14,17 @@ export function collectActiveNodes(
13
14
  root: string,
14
15
  maxScanDepth?: number,
15
16
  ): GraphNode[] {
17
+ // T23: the active-change traversal is the shared walk (change/collect) —
18
+ // graph nodes are just its (dir, name) pairs mapped to the node shape.
16
19
  const out: GraphNode[] = [];
17
- const changesDir = `${root}/${CHANGES_DIR}`;
18
- if (!io.exists(changesDir) || !io.isDirectory(changesDir)) return out;
19
- const maxDepth = maxScanDepth ?? 8;
20
- const visit = (dir: string, depth: number): void => {
21
- if (depth > maxDepth) return;
22
- for (const name of io.listDir(dir).toSorted()) {
23
- if (name === 'archive' || name.startsWith('.')) continue;
24
- const child = `${dir}/${name}`;
25
- if (!io.isDirectory(child)) continue;
26
- if (io.exists(`${child}/proposal.md`)) {
27
- out.push({ id: name, archived: false, present: true });
28
- } else if (depth < maxDepth) {
29
- visit(child, depth + 1);
30
- }
31
- }
32
- };
33
- visit(changesDir, 1);
20
+ walkActiveChangeDirs(
21
+ io,
22
+ `${root}/${CHANGES_DIR}`,
23
+ (_dir, name) => {
24
+ out.push({ id: name, archived: false, present: true });
25
+ },
26
+ { maxScanDepth },
27
+ );
34
28
  return out;
35
29
  }
36
30
 
@@ -1,9 +1,5 @@
1
- export interface GraphFsIo {
2
- exists(path: string): boolean;
3
- readText(path: string): string;
4
- listDir(path: string): string[];
5
- isDirectory(path: string): boolean;
6
- }
1
+ import { type FsPort } from '../../util/fsPort.ts';
2
+ export type GraphFsIo = Pick<FsPort, 'exists' | 'readText' | 'listDir' | 'isDirectory'>;
7
3
 
8
4
  export interface GraphNode {
9
5
  id: string;
@@ -1,8 +1,9 @@
1
- import { countTasks, firstH1, stageFor, type ChangeFsIo } from '../change/collect.ts';
1
+ import { changeTitle, countTasks, stageFor, type ChangeFsIo } from '../change/collect.ts';
2
2
  import {
3
3
  extractFrontmatter,
4
4
  readBinding,
5
5
  readNeedsSpecsChange,
6
+ DEFAULT_SPECS_PREFIX,
6
7
  specsLanded as specsLandedOf,
7
8
  } from '../change/frontmatter.ts';
8
9
  import { CHANGES_DIR } from '../change/lifecycle.ts';
@@ -25,6 +26,8 @@ export interface ShowDeps {
25
26
  git: GitLike;
26
27
  root: string;
27
28
  specsDir: string;
29
+ /** r119: instance-relative specs prefix of this root (specs-landed gate). */
30
+ specsPrefix?: string;
28
31
  }
29
32
 
30
33
  export function showChangeJson(
@@ -62,14 +65,16 @@ export function showChangeJson(
62
65
  const onBoundBranch = binding !== null && current === binding.branch;
63
66
 
64
67
  // specs landing: bound changes must have touched llmanspec/specs/ since base
68
+ // (r119: judged under THIS instance's prefix, not the repo-root literal)
69
+ const specsPrefix = deps.specsPrefix ?? DEFAULT_SPECS_PREFIX;
65
70
  let landedOnBranch = false;
66
71
  if (binding !== null) {
67
- landedOnBranch = specsLandedOf(git, binding);
72
+ landedOnBranch = specsLandedOf(git, binding, specsPrefix);
68
73
  }
69
74
  const needsSpecsChange = readNeedsSpecsChange(extractFrontmatter(proposal));
70
75
 
71
76
  const tasksDone = total > 0 && completed >= total;
72
- const specReport = validateAllSpecs(discoverSpecs(deps.specsDir, io), io);
77
+ const specReport = validateAllSpecs(discoverSpecs(deps.specsDir, io));
73
78
  const validateOk = !specReport.failed && (total === 0 || tasksDone);
74
79
 
75
80
  const stageHint = !hasDesign
@@ -79,10 +84,13 @@ export function showChangeJson(
79
84
  : stage === 'planned'
80
85
  ? 'bind via `llman-sdd change start <id>` (planned → full)'
81
86
  : '';
82
- const tasksHint =
83
- total > 0 && completed < total
87
+ // T34: a missing tasks.md has nothing to check off — the hint says so
88
+ // instead of the legacy "complete or check off remaining tasks".
89
+ const tasksHint = hasTasks
90
+ ? total > 0 && completed < total
84
91
  ? `${total - completed} unchecked tasks`
85
- : 'complete or check off remaining tasks';
92
+ : 'complete or check off remaining tasks'
93
+ : 'no tasks.md — seal-off needs no checked tasks';
86
94
 
87
95
  const gateChecks = [
88
96
  {
@@ -106,7 +114,7 @@ export function showChangeJson(
106
114
  hint:
107
115
  landedOnBranch || !needsSpecsChange
108
116
  ? ''
109
- : 'edit live specs on the bound branch and commit (or set needs_specs_change to false)',
117
+ : `edit live specs under ${specsPrefix} on the bound branch and commit (or set needs_specs_change to false)`,
110
118
  },
111
119
  {
112
120
  name: 'tasks-done',
@@ -123,7 +131,7 @@ export function showChangeJson(
123
131
  return {
124
132
  id,
125
133
  path: id,
126
- title: firstH1(proposal),
134
+ title: changeTitle(proposal),
127
135
  stage,
128
136
  artifacts,
129
137
  readyToImplement: gateChecks.every((g) => g.pass),
@@ -1,38 +1,30 @@
1
- import { assignSpecIds } from '../spec/assignSpecIds.ts';
2
- import { officialKeywords, officialKeywordsOrEn } from '../spec/keywords.ts';
3
- import { localeToGherkinLang, parseCapability } from '../spec/parser.ts';
4
- import { buildReqRegistry } from '../spec/reqRegistry.ts';
5
1
  /**
6
2
  * Spec authoring helpers (peripheral-commands capability, r22):
7
3
  * skeleton generation + global next req id. Pure, IO injected.
8
4
  */
9
- import { localeFallbacks } from '../templates/locale.ts';
5
+ import { localeFallbacks } from '../locale.ts';
6
+ import { assignSpecIds } from '../spec/assignSpecIds.ts';
7
+ import { officialKeywords, officialKeywordsOrEn } from '../spec/keywords.ts';
8
+ import { localeToGherkinLang, parseCapability } from '../spec/parser.ts';
9
+ import { buildReqRegistry } from '../spec/reqRegistry.ts';
10
+ import { type FsPort } from '../util/fsPort.ts';
11
+ import { nextNumber } from '../util/nextNumber.ts';
12
+ import { discoverFeatureFiles } from '../validation/discover.ts';
10
13
  import type { SpecEntry } from '../validation/validate.ts';
11
14
 
12
- export interface SpecHelperIo {
13
- exists(path: string): boolean;
14
- readText(path: string): string;
15
- writeText(path: string, content: string): void;
16
- mkdirp(path: string): void;
17
- isDirectory(path: string): boolean;
18
- listDir(path: string): string[];
19
- }
15
+ export type SpecHelperIo = Pick<
16
+ FsPort,
17
+ 'exists' | 'readText' | 'writeText' | 'mkdirp' | 'isDirectory' | 'listDir'
18
+ >;
20
19
 
21
20
  function collectSpecEntries(io: SpecHelperIo, specsDir: string): SpecEntry[] {
22
- const entries: SpecEntry[] = [];
23
- const walk = (dir: string): void => {
24
- if (!io.exists(dir)) return;
25
- for (const name of io.listDir(dir)) {
26
- const full = `${dir}/${name}`;
27
- if (name.endsWith('.feature')) {
28
- entries.push({ fileName: full, doc: parseCapability(io.readText(full), full) });
29
- } else if (io.isDirectory(full)) {
30
- walk(full);
31
- }
32
- }
33
- };
34
- walk(specsDir);
35
- assignSpecIds(entries, specsDir);
21
+ // T24: shared discovery — identical ordering/norm as the hash walk.
22
+ const normDir = specsDir.replace(/\\/g, '/').replace(/\/$/u, '');
23
+ const entries = discoverFeatureFiles(normDir, io).map((path) => ({
24
+ fileName: path,
25
+ doc: parseCapability(io.readText(path), path),
26
+ }));
27
+ assignSpecIds(entries, normDir);
36
28
  return entries;
37
29
  }
38
30
 
@@ -49,7 +41,9 @@ export function nextReqId(io: SpecHelperIo, specsDir: string): string {
49
41
  const used = [...buildReqRegistry(entries).byId.keys()].map((reqId) =>
50
42
  Math.trunc(Number(reqId.replace(/^r/u, ''))),
51
43
  );
52
- return `r${Math.max(0, ...used) + 1}`;
44
+ // SSOT: the numeric-id allocator primitive (unify-numeric-id-allocation) —
45
+ // never a second max+1 fold. Same source as change sequence numbers.
46
+ return `r${nextNumber(used)}`;
53
47
  }
54
48
 
55
49
  export function skeletonContent(capability: string, reqId: string, locale: string): string {
@@ -1,9 +1,10 @@
1
- import { ruleHasRunnableScenario, specIdOf } from '../spec/ir.ts';
2
1
  /**
3
2
  * Review aggregation (review-freeze capability, r23): five-signal review over
4
3
  * spec IR + validate sweep. Port of predecessor sdd/review.rs observable contract.
5
4
  */
6
- import { validateAllSpecs, type SpecEntry, type SpecIo } from '../validation/validate.ts';
5
+ import { collectUnboundRequirements } from '../report/unbound.ts';
6
+ import { specIdOf } from '../spec/ir.ts';
7
+ import { validateAllSpecs, type SpecEntry } from '../validation/validate.ts';
7
8
 
8
9
  export type ReviewKind = 'unbound' | 'locked' | 'validate';
9
10
 
@@ -22,7 +23,6 @@ export interface ReviewInput {
22
23
  activeChanges?: readonly { name: string; completedTasks: number; totalTasks: number }[];
23
24
  /** Restrict per-capability signals (unbound) to this capability. */
24
25
  capability?: string;
25
- checkTransitions?: boolean;
26
26
  }
27
27
 
28
28
  export interface ReviewResult {
@@ -32,7 +32,7 @@ export interface ReviewResult {
32
32
  exitCode: number;
33
33
  }
34
34
 
35
- export function buildReview(input: ReviewInput, io: SpecIo): ReviewResult {
35
+ export function buildReview(input: ReviewInput): ReviewResult {
36
36
  const { entries, boundChangeCount } = input;
37
37
  const strictChangeFails = (input.activeChanges ?? []).filter(
38
38
  (c) => c.totalTasks > 0 && c.completedTasks < c.totalTasks,
@@ -42,41 +42,29 @@ export function buildReview(input: ReviewInput, io: SpecIo): ReviewResult {
42
42
  signals.push({ kind, capability, count, detail });
43
43
  };
44
44
 
45
- const sweep = validateAllSpecs(entries, io, { checkTransitions: input.checkTransitions });
45
+ const sweep = validateAllSpecs(entries);
46
46
  const sorted = [...entries].toSorted((a, b) => a.fileName.localeCompare(b.fileName));
47
47
 
48
+ // T29: unbound counting is the shared collector (report/unbound) keyed by
49
+ // capability — one definition of "rule without runnable scenario".
50
+ const unboundByCap = new Map<string, number>();
51
+ for (const u of collectUnboundRequirements(entries)) {
52
+ unboundByCap.set(u.capability, (unboundByCap.get(u.capability) ?? 0) + 1);
53
+ }
48
54
  for (const entry of sorted) {
49
55
  const cap = specIdOf(entry);
50
56
  // r33: per-capability signals honor the --capability filter; locked and
51
57
  // validate stay global regardless.
52
58
  if (input.capability !== undefined && cap !== input.capability) continue;
53
- // Native model: rules are `规则:` blocks; a rule without any runnable
54
- // nested scenario is unbound (not bound to real logic — 0 scenarios or
55
- // all @skip/@experimental/stepless). Top-level scenarios outside any rule
56
- // are plain feature-level examples with no special signal.
57
- const unbound = entry.doc.rules.filter((r) => !ruleHasRunnableScenario(r)).length;
58
-
59
- push('unbound', cap, unbound);
59
+ push('unbound', cap, unboundByCap.get(cap) ?? 0);
60
60
  }
61
61
 
62
62
  const failed = sweep.verdicts.filter((v) => !v.ok);
63
63
  const sweepFailedCount = failed.length;
64
- // predecessor sweep = `validate --all --strict --no-check`: pending tasks escalate a
65
- // change to FAIL, and that feeds the review critical count.
66
- for (const c of strictChangeFails) {
67
- failed.push({
68
- fileName: c.name,
69
- capability: c.name,
70
- ok: false,
71
- items: [
72
- {
73
- level: 'ERROR',
74
- id: `${c.name}/tasks`,
75
- message: `${c.totalTasks - c.completedTasks} unchecked tasks`,
76
- },
77
- ],
78
- });
79
- }
64
+ // T35: unchecked tasks are work-in-progress noise, not contract breakage —
65
+ // they degrade to a warningCount contribution instead of the critical count
66
+ // (locked/unbound signals stay untouched).
67
+ const taskWarnings = strictChangeFails.length;
80
68
  // predecessor parity: `count` is the removed locked-rule-confirmation concept (always
81
69
  // 0 now); the detail text carries the bound-change count separately.
82
70
  push(
@@ -103,9 +91,8 @@ export function buildReview(input: ReviewInput, io: SpecIo): ReviewResult {
103
91
  [sweepDetail, strictDetail].filter(Boolean).join('; ') || 'ok',
104
92
  );
105
93
 
106
- const warningCount = signals
107
- .filter((s) => s.kind === 'unbound')
108
- .reduce((acc, s) => acc + s.count, 0);
94
+ const warningCount =
95
+ signals.filter((s) => s.kind === 'unbound').reduce((acc, s) => acc + s.count, 0) + taskWarnings;
109
96
  const criticalCount = failed.length;
110
97
 
111
98
  const lines: string[] = [`Review: critical=${criticalCount} warning=${warningCount}`];