@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
@@ -12,7 +12,17 @@ import {
12
12
  worktreeList,
13
13
  type GitLike,
14
14
  } from '../git/spawnGit.ts';
15
- import { readBinding, writeBinding } from './frontmatter.ts';
15
+ import { type FsPort } from '../util/fsPort.ts';
16
+ import {
17
+ extractFrontmatter,
18
+ instanceDirRelOf,
19
+ readBinding,
20
+ readNeedsSpecsChange,
21
+ DEFAULT_SPECS_PREFIX,
22
+ specsLanded,
23
+ writeBinding,
24
+ type ChangeBinding,
25
+ } from './frontmatter.ts';
16
26
  /**
17
27
  * Change lifecycle (change-lifecycle capability): new / start / attach /
18
28
  * finalize with the predecessor git-native contract (r14-r16). All effects flow
@@ -23,14 +33,7 @@ import { readBinding, writeBinding } from './frontmatter.ts';
23
33
  import { DRAFT_PROPOSAL_TEMPLATE, deriveChangeId } from './id.ts';
24
34
  import { CLOSE_OUT_TASK_HINT, closeOutTaskLines, parseTaskCheckboxes } from './tasks.ts';
25
35
 
26
- export interface FsIo {
27
- exists(path: string): boolean;
28
- readText(path: string): string;
29
- /** writeText creates parent directories as needed. */
30
- writeText(path: string, content: string): void;
31
- rename(from: string, to: string): void;
32
- listDir(path: string): string[];
33
- }
36
+ export type FsIo = Pick<FsPort, 'exists' | 'readText' | 'writeText' | 'rename' | 'listDir'>;
34
37
 
35
38
  export class LifecycleError extends Error {}
36
39
 
@@ -45,6 +48,8 @@ const onDefaultBranch = (cmd: string, def: string): string =>
45
48
  const dirtyTree = (cmd: string): string => `\`${cmd}\` requires a clean working tree`;
46
49
 
47
50
  export const CHANGES_DIR = 'llmanspec/changes';
51
+ /** Instance-relative live-specs dir (single SSOT with CHANGES_DIR). */
52
+ export const SPECS_DIR = 'llmanspec/specs';
48
53
  const proposalPath = (id: string): string => `${CHANGES_DIR}/${id}/proposal.md`;
49
54
 
50
55
  /** `change new [id] --from DESC --force`: derive a legal id and write the draft shell. */
@@ -170,6 +175,8 @@ export function startChange(
170
175
  worktreeRoot?: string;
171
176
  /** Config sdd.worktree_naming. */
172
177
  worktreeNaming?: 'id' | 'hash';
178
+ /** r119: instance dir relative to the git toplevel ('' at the repo root). */
179
+ instanceDirRel?: string;
173
180
  } = {},
174
181
  ): StartResult {
175
182
  const path = proposalPath(id);
@@ -220,12 +227,18 @@ export function startChange(
220
227
  // checkout stays byte-identical (zero writes through the original io).
221
228
  // The clean-tree gate guaranteed the proposal is committed at HEAD, so it
222
229
  // is present in the fresh worktree; a missing one rolls everything back.
223
- const wtIo = ioAt(io, worktreePath);
230
+ // r119: the io is anchored at the INSTANCE root; redirecting into the new
231
+ // worktree must re-attach that offset relative to its toplevel (a sub-root
232
+ // change's proposal lives at <wt>/<rel>/llmanspec/changes/<id>), same
233
+ // shape as the mergeRenameCommit holder redirect.
234
+ const instanceDirRel = opts.instanceDirRel ?? '';
235
+ const wtRoot = instanceDirRel === '' ? worktreePath : `${worktreePath}/${instanceDirRel}`;
236
+ const wtIo = ioAt(io, wtRoot);
224
237
  if (!wtIo.exists(path)) {
225
238
  git.run(['worktree', 'remove', '--force', worktreePath]);
226
239
  git.run(['branch', '-D', branch]);
227
240
  throw new LifecycleError(
228
- `proposal not found in the new worktree: ${worktreePath}/${path} — commit the change docs before \`change start --worktree\``,
241
+ `proposal not found in the new worktree: ${wtRoot}/${path} — commit the change docs before \`change start --worktree\``,
229
242
  );
230
243
  }
231
244
  const baseSha = mergeBase(gitAt(git, worktreePath), 'HEAD', baseBranch);
@@ -309,31 +322,91 @@ export function archiveTaskGate(tasksMd: string | null): ArchiveTaskGate {
309
322
  return { blocked: false, pendingLines: [] };
310
323
  }
311
324
 
325
+ /**
326
+ * T34 close-out gate (decision D): seal-off requires the specs-landed verdict
327
+ * (`specsLanded || !needsSpecsChange`) plus every checked task when tasks.md
328
+ * exists. `reason === null` means pass; otherwise it is the human message.
329
+ * Zero-write: callers run this before any merge/rename/commit.
330
+ */
331
+ export function closeOutGate(change: {
332
+ git: GitLike;
333
+ io: FsIo;
334
+ id: string;
335
+ binding: ChangeBinding | null;
336
+ /** r119: instance-relative specs prefix of the change's own root. */
337
+ specsPrefix?: string;
338
+ }): { ok: boolean; reason: string | null } {
339
+ const { git, io, id, binding } = change;
340
+ const specsPrefix = change.specsPrefix ?? DEFAULT_SPECS_PREFIX;
341
+ // task gate first: the unchecked list is the most actionable feedback and
342
+ // keeps the predecessor "blocked by unchecked tasks" surface primary.
343
+ const tasksPath = `${CHANGES_DIR}/${id}/tasks.md`;
344
+ const gate = archiveTaskGate(io.exists(tasksPath) ? io.readText(tasksPath) : null);
345
+ if (gate.blocked) {
346
+ const closeOutLines = closeOutTaskLines(gate.pendingLines);
347
+ return {
348
+ ok: false,
349
+ reason: [
350
+ `close-out blocked by unchecked tasks (${gate.pendingLines.length} pending)`,
351
+ ...gate.pendingLines,
352
+ ...(closeOutLines.length > 0
353
+ ? [
354
+ `task "${closeOutLines[0]?.replace(/^-\s+\[ \]\s*/u, '').trim() ?? ''}" looks like a close-out step; ${CLOSE_OUT_TASK_HINT}`,
355
+ ]
356
+ : []),
357
+ ].join('\n'),
358
+ };
359
+ }
360
+ const proposal = io.readText(`${CHANGES_DIR}/${id}/proposal.md`);
361
+ const needsSpecsChange = readNeedsSpecsChange(extractFrontmatter(proposal));
362
+ if (binding !== null) {
363
+ const landed = specsLanded(git, binding, specsPrefix);
364
+ if (!landed && needsSpecsChange) {
365
+ return {
366
+ ok: false,
367
+ reason: `close-out blocked: no changes under ${specsPrefix} on the bound branch (or set needs_specs_change to false)`,
368
+ };
369
+ }
370
+ }
371
+ return { ok: true, reason: null };
372
+ }
373
+
312
374
  /** `change finalize`: merge (squash default) + archive rename + close-out commit. */
313
375
  export function finalizeChange(
314
376
  git: GitLike,
315
377
  io: FsIo,
316
378
  id: string,
317
- opts: { into?: string; method?: 'squash' | 'ff'; today: string; noCommit?: boolean },
379
+ opts: {
380
+ into?: string;
381
+ method?: 'squash' | 'ff';
382
+ today: string;
383
+ noCommit?: boolean;
384
+ /** r119: instance-relative specs prefix of the change's own root. */
385
+ specsPrefix?: string;
386
+ },
318
387
  ): FinalizeResult {
319
388
  const path = proposalPath(id);
320
389
  const binding = readBinding(io.readText(path));
321
390
  if (binding === null) {
322
391
  throw new LifecycleError(`change \`${id}\` has no branch binding — run start/attach first`);
323
392
  }
324
- // r40 task gate before any write (B23: finalize shares the archive task gate).
393
+ // T34 close-out gate before any write: specs-landed verdict + task gate.
394
+ const closeOut = closeOutGate({ git, io, id, binding, specsPrefix: opts.specsPrefix });
395
+ if (!closeOut.ok) {
396
+ throw new LifecycleError(closeOut.reason as string);
397
+ }
398
+ // r40 unchecked-task detail lines (D9 close-out pseudo-task hint).
325
399
  const tasksPath = `${CHANGES_DIR}/${id}/tasks.md`;
326
400
  const gate = archiveTaskGate(io.exists(tasksPath) ? io.readText(tasksPath) : null);
327
401
  if (gate.blocked) {
328
- // D9: point at a close-out pseudo-task with the single shared hint.
329
- const closeOut = closeOutTaskLines(gate.pendingLines);
402
+ const closeOutLines = closeOutTaskLines(gate.pendingLines);
330
403
  throw new LifecycleError(
331
404
  [
332
405
  `finalize blocked by unchecked tasks (${gate.pendingLines.length} pending)`,
333
406
  ...gate.pendingLines,
334
- ...(closeOut.length > 0
407
+ ...(closeOutLines.length > 0
335
408
  ? [
336
- `task "${closeOut[0]?.replace(/^-\s+\[ \]\s*/u, '').trim() ?? ''}" looks like a close-out step; ${CLOSE_OUT_TASK_HINT}`,
409
+ `task "${closeOutLines[0]?.replace(/^-\s+\[ \]\s*/u, '').trim() ?? ''}" looks like a close-out step; ${CLOSE_OUT_TASK_HINT}`,
337
410
  ]
338
411
  : []),
339
412
  ].join('\n'),
@@ -347,7 +420,17 @@ export function finalizeChange(
347
420
  }
348
421
  const method = opts.method ?? 'squash';
349
422
  const target = opts.into ?? binding.baseBranch ?? defaultBranch(git);
350
- return mergeRenameCommit(git, io, id, binding.branch, target, method, opts.today, opts.noCommit);
423
+ return mergeRenameCommit(
424
+ git,
425
+ io,
426
+ id,
427
+ binding.branch,
428
+ target,
429
+ method,
430
+ opts.today,
431
+ opts.noCommit,
432
+ instanceDirRelOf(opts.specsPrefix ?? DEFAULT_SPECS_PREFIX),
433
+ );
351
434
  }
352
435
 
353
436
  /** r69: GitLike view bound to another worktree via `git -C <path>` prefixing. */
@@ -388,6 +471,8 @@ function mergeRenameCommit(
388
471
  method: 'squash' | 'ff',
389
472
  today: string,
390
473
  noCommit?: boolean,
474
+ /** r119: instance dir relative to the git toplevel ('' at the repo root). */
475
+ instanceDirRel = '',
391
476
  ): FinalizeResult {
392
477
  const warnings: string[] = [];
393
478
  // r69: when the target branch is checked out in another worktree, `git
@@ -411,7 +496,11 @@ function mergeRenameCommit(
411
496
  );
412
497
  }
413
498
  execGit = gitAt(git, holder);
414
- execIo = ioAt(io, holder);
499
+ // r119/W1: the io is anchored at the INSTANCE root; redirecting onto the
500
+ // holding worktree must re-attach the instance offset relative to its
501
+ // toplevel, or a sub-root rename would target <holder>/llmanspec (the
502
+ // repo-root instance) and fail ENOENT mid-close-out (merge already run).
503
+ execIo = ioAt(io, instanceDirRel === '' ? holder : `${holder}/${instanceDirRel}`);
415
504
  executedIn = holder;
416
505
  }
417
506
  // r96: in-place close-out — merging a branch into itself is always a no-op
@@ -463,6 +552,8 @@ export function archiveChange(
463
552
  /** CLI already enforced a clean tree before the acceptance command ran. */
464
553
  skipCleanTree?: boolean;
465
554
  today: string;
555
+ /** r119: instance-relative specs prefix of the change's own root. */
556
+ specsPrefix?: string;
466
557
  },
467
558
  ): FinalizeResult {
468
559
  const path = proposalPath(id);
@@ -471,6 +562,9 @@ export function archiveChange(
471
562
  throw new LifecycleError(`change \`${id}\` has no branch binding — run start/attach first`);
472
563
  }
473
564
  if (!opts.force) {
565
+ // T34: shared close-out verdict before any write (archive honors --force).
566
+ const closeOut = closeOutGate({ git, io, id, binding, specsPrefix: opts.specsPrefix });
567
+ if (!closeOut.ok) throw new LifecycleError(closeOut.reason as string);
474
568
  const tasksPath = `${CHANGES_DIR}/${id}/tasks.md`;
475
569
  const gate = archiveTaskGate(io.exists(tasksPath) ? io.readText(tasksPath) : null);
476
570
  if (gate.blocked) {
@@ -507,7 +601,17 @@ export function archiveChange(
507
601
  }
508
602
  const method = opts.method ?? 'squash';
509
603
  const target = opts.into ?? binding?.baseBranch ?? defaultBranch(git);
510
- return mergeRenameCommit(git, io, id, binding?.branch as string, target, method, opts.today);
604
+ return mergeRenameCommit(
605
+ git,
606
+ io,
607
+ id,
608
+ binding?.branch as string,
609
+ target,
610
+ method,
611
+ opts.today,
612
+ undefined,
613
+ instanceDirRelOf(opts.specsPrefix ?? DEFAULT_SPECS_PREFIX),
614
+ );
511
615
  }
512
616
 
513
617
  /** `change diff <id>`: full diff of the bound branch vs base. */
@@ -8,6 +8,7 @@
8
8
  */
9
9
 
10
10
  import { worktreeList, type GitLike } from '../git/spawnGit.ts';
11
+ import { maxUsedNumber, nextNumber } from '../util/nextNumber.ts';
11
12
 
12
13
  export interface NextIdIo {
13
14
  listDir(path: string): string[];
@@ -63,8 +64,7 @@ export function collectNumbers(
63
64
 
64
65
  export function harvestUniqueNumbers(io: NextIdIo, root: string): IdHarvest {
65
66
  const { numbers, warnings } = collectNumbers(io, root);
66
- const maxNumber = numbers.length > 0 ? Math.max(...numbers) : null;
67
- return { maxNumber, nextNumber: maxNumber === null ? 1 : maxNumber + 1, warnings };
67
+ return { maxNumber: maxUsedNumber(numbers), nextNumber: nextNumber(numbers), warnings };
68
68
  }
69
69
 
70
70
  /**
@@ -76,8 +76,17 @@ export function harvestUniqueNumbers(io: NextIdIo, root: string): IdHarvest {
76
76
  * r35 (issue #8): `prunable` worktree entries and kept entries whose
77
77
  * `llmanspec/` directory is absent count as empty trees — silently skipped,
78
78
  * never warned; only real read errors reach warnings.
79
+ *
80
+ * r118: `instanceDirRel` is the harvested instance directory *relative to each
81
+ * worktree root* (`llmanspec` for the repo-root instance, e.g.
82
+ * `packages/tui/llmanspec` for a sub-project instance). Linked worktrees share
83
+ * one layout, so the same relative path addresses each checkout's own instance.
79
84
  */
80
- export function harvestAcrossWorktrees(git: GitLike, io: NextIdIo, root: string): IdHarvest {
85
+ export function harvestAcrossWorktrees(
86
+ git: GitLike,
87
+ io: NextIdIo,
88
+ instanceDirRel: string,
89
+ ): IdHarvest {
81
90
  const warnings: string[] = [];
82
91
  let paths: string[] | null;
83
92
  try {
@@ -97,7 +106,7 @@ export function harvestAcrossWorktrees(git: GitLike, io: NextIdIo, root: string)
97
106
  `worktree list failed: ${(error as Error).message} — scanned the current tree only`,
98
107
  );
99
108
  }
100
- const trees = paths === null ? [root] : paths.map((p) => `${p}/llmanspec`);
109
+ const trees = paths === null ? [instanceDirRel] : paths.map((p) => `${p}/${instanceDirRel}`);
101
110
  const perTree = trees
102
111
  .filter((at) => io.isDirectory(at))
103
112
  .map((at) => ({ at, ...collectNumbers(io, at) }));
@@ -117,6 +126,5 @@ export function harvestAcrossWorktrees(git: GitLike, io: NextIdIo, root: string)
117
126
  }
118
127
  }
119
128
  const all = perTree.flatMap((tree) => tree.numbers);
120
- const maxNumber = all.length > 0 ? Math.max(...all) : null;
121
- return { maxNumber, nextNumber: maxNumber === null ? 1 : maxNumber + 1, warnings };
129
+ return { maxNumber: maxUsedNumber(all), nextNumber: nextNumber(all), warnings };
122
130
  }
@@ -4,7 +4,6 @@
4
4
  * template rendering (Strict via templates/engine.ts) with the predecessor preset vars.
5
5
  */
6
6
 
7
- import { harvestUniqueNumbers, type NextIdIo } from '../change/nextId.ts';
8
7
  import { renderTemplate } from '../templates/engine.ts';
9
8
 
10
9
  export class ChangeIdError extends Error {}
@@ -58,11 +57,6 @@ export function renderChangeIdTemplate(template: string, vars: ChangeIdVars): st
58
57
  return rendered;
59
58
  }
60
59
 
61
- /** Whole-tree next free number for the llman_sdd_unique_id preset var. */
62
- export function nextUniqueNumber(io: NextIdIo, llmanspecRoot: string): number {
63
- return harvestUniqueNumbers(io, llmanspecRoot).nextNumber;
64
- }
65
-
66
60
  const VERB_TABLE = ['add', 'update', 'remove', 'refactor', 'fix'] as const;
67
61
 
68
62
  /**
@@ -91,8 +91,8 @@ export function stripLegacyCheckTransitions(data: unknown): { data: unknown; str
91
91
  * Load + validate, returning the parsed config and whether a legacy `bdd:`
92
92
  * section was elevated. The CLI surfaces the migration warning from the flag.
93
93
  * `localeExplicit` reports whether the raw mapping carried a `locale` key at
94
- * all — the schema default ('en') erases that distinction, but init needs it
95
- * for the effective-locale precedence chain (init-generators r50).
94
+ * all — the schema default (r18-normalized `zh-Hans`) erases that distinction,
95
+ * but init needs it for the effective-locale precedence chain (init-generators r50).
96
96
  */
97
97
  export function loadConfigDetail(source: string): {
98
98
  config: SddConfig;
@@ -6,6 +6,8 @@
6
6
  */
7
7
  import { z } from 'zod';
8
8
 
9
+ import { DEFAULT_LOCALE } from '../locale.ts';
10
+
9
11
  export const EXTRA_SKILLS = [
10
12
  'llman-sdd-continue',
11
13
  'llman-sdd-ff',
@@ -74,7 +76,7 @@ export const changeIdSchema = z.object({
74
76
 
75
77
  export const sddConfigSchema = z.object({
76
78
  schema: z.literal('spec-driven').describe('Schema identifier. Must be "spec-driven".'),
77
- locale: z.string().default('en').describe('Locale used for SDD templates and skills.'),
79
+ locale: z.string().default(DEFAULT_LOCALE).describe('Locale used for SDD templates and skills.'),
78
80
  extra_skills: z
79
81
  .array(z.enum(EXTRA_SKILLS))
80
82
  .nullish()
@@ -1,3 +1,4 @@
1
+ import { type FsPort } from '../util/fsPort.ts';
1
2
  /**
2
3
  * Index orchestration (context-index capability, r26): rebuild writes the
3
4
  * pageindex tree under a create-new lock; check compares the stored spec_hash
@@ -12,20 +13,19 @@ export const TREE_JSON_REL = `${PAGEINDEX_DIR_REL}/tree.json`;
12
13
  export const REBUILD_LOCK_REL = `${PAGEINDEX_DIR_REL}/.rebuild.lock`;
13
14
  const LOCK_MAX_AGE_MS = 6 * 60 * 60 * 1000;
14
15
 
15
- export interface IndexIo {
16
- exists(path: string): boolean;
17
- readText(path: string): string;
18
- writeText(path: string, content: string): void;
19
- remove(path: string): void;
20
- isDirectory(path: string): boolean;
21
- listDir(path: string): string[];
22
- mkdirp(path: string): void;
23
- processAlive(pid: number): boolean;
24
- /** Current process id for the rebuild lock (side effect injected, r3). */
25
- currentPid(): number;
26
- /** Wall clock for lock timestamps / staleness (side effect injected, r3). */
27
- now(): Date;
28
- }
16
+ export type IndexIo = Pick<
17
+ FsPort,
18
+ | 'exists'
19
+ | 'readText'
20
+ | 'writeText'
21
+ | 'remove'
22
+ | 'isDirectory'
23
+ | 'listDir'
24
+ | 'mkdirp'
25
+ | 'processAlive'
26
+ | 'currentPid'
27
+ | 'now'
28
+ >;
29
29
 
30
30
  export interface RebuildOpts {
31
31
  chatModel: string;
@@ -46,16 +46,4 @@ export function readSddState(io: Pick<StateIo, 'exists' | 'readText'>): SddState
46
46
  }
47
47
  }
48
48
 
49
- const dot = (v: string): number => Math.trunc(Number(v)) || 0;
50
-
51
- /** Numeric semver-major.minor.patch compare; non-numeric segments compare 0. */
52
- export function semverLt(a: string, b: string): boolean {
53
- const pa = a.split('.');
54
- const pb = b.split('.');
55
- for (let i = 0; i < 3; i++) {
56
- const ai = dot(pa[i] ?? '0');
57
- const bi = dot(pb[i] ?? '0');
58
- if (ai !== bi) return ai < bi;
59
- }
60
- return false;
61
- }
49
+ export { semverLt } from '../util/semver.ts';
@@ -4,9 +4,10 @@
4
4
  * predecessor's tree.json so retrieval IDs stay comparable.
5
5
  */
6
6
  import { createHash } from 'node:crypto';
7
- import { join } from 'node:path';
8
7
 
9
8
  import { specIdOf } from '../spec/ir.ts';
9
+ import { type FsPort } from '../util/fsPort.ts';
10
+ import { discoverFeatureFiles } from '../validation/discover.ts';
10
11
  import type { SpecEntry } from '../validation/validate.ts';
11
12
 
12
13
  export const TREE_VERSION = 1;
@@ -96,27 +97,16 @@ export function buildTreeIndex(
96
97
  };
97
98
  }
98
99
 
99
- export interface HashIo {
100
- exists(p: string): boolean;
101
- isDirectory(p: string): boolean;
102
- listDir(p: string): string[];
103
- readText(p: string): string;
104
- }
100
+ export type HashIo = Pick<FsPort, 'exists' | 'isDirectory' | 'listDir' | 'readText'>;
105
101
 
106
102
  /** sha256 over all .feature files, sorted by path (r26 freshness anchor). */
107
103
  export function computeSpecHash(specsDir: string, io: HashIo): string {
108
104
  const hash = createHash('sha256');
109
- const walk = (dir: string): void => {
110
- if (!io.exists(dir) || !io.isDirectory(dir)) return;
111
- for (const name of io.listDir(dir).toSorted()) {
112
- const full = join(dir, name);
113
- if (io.isDirectory(full)) walk(full);
114
- else if (name.endsWith('.feature')) {
115
- hash.update(full);
116
- hash.update(io.readText(full));
117
- }
118
- }
119
- };
120
- walk(specsDir);
105
+ // T24: shared discovery — the hashed path set/order is exactly the parser's,
106
+ // so editing specs cannot desynchronize freshness from parse coverage.
107
+ for (const full of discoverFeatureFiles(specsDir.replace(/\\/g, '/').replace(/\/$/u, ''), io)) {
108
+ hash.update(full);
109
+ hash.update(io.readText(full));
110
+ }
121
111
  return hash.digest('hex');
122
112
  }
package/src/index.ts CHANGED
@@ -18,7 +18,6 @@ export {
18
18
  export {
19
19
  ChangeIdError,
20
20
  compileChangeIdPattern,
21
- nextUniqueNumber,
22
21
  renderChangeIdTemplate,
23
22
  } from './config/changeId.ts';
24
23
  export { renderConfigOverview, skillsJson } from './config/surface.ts';
@@ -92,7 +91,6 @@ export {
92
91
  } from './spec/authoring.ts';
93
92
  export type {
94
93
  SpecEntry,
95
- SpecIo,
96
94
  SpecVerdict,
97
95
  ValidationItem,
98
96
  ValidationLevel,
@@ -101,14 +99,9 @@ export type {
101
99
  export { validateAllSpecs, validateCapability } from './validation/validate.ts';
102
100
  export { buildDuplicatesFor, formatTotals } from './validation/validate.ts';
103
101
  export {
104
- ESCAPE_TRANSITIONS_TAG,
105
- FORCE_TRANSITIONS_TAG,
106
102
  TRANSITIONS_INTROSPECTION,
107
103
  isTransitionOutline,
108
- parseTransitionExpr,
109
- resolveTransitionDecision,
110
104
  type TransitionDecision,
111
- validateTransitionScenario,
112
105
  type TransitionEdge,
113
106
  } from './validation/xstateTransitions.ts';
114
107
  export { splitVerb } from './config/changeId.ts';
@@ -116,6 +109,7 @@ export {
116
109
  checkChangeDoc,
117
110
  validateChange,
118
111
  checkGlobalChangeIdUniqueness,
112
+ collectChangeIdValues,
119
113
  STAGE_ORDER,
120
114
  type ChangeCheckConfig,
121
115
  type ChangeCheckInput,
@@ -133,6 +127,12 @@ export {
133
127
  type RootEntry,
134
128
  type RootsIo,
135
129
  } from './validation/roots.ts';
130
+ export {
131
+ computeCrossRootCollisions,
132
+ type CrossRootCollision,
133
+ type CrossRootNamespace,
134
+ type RootNamespaceValues,
135
+ } from './validation/crossRoot.ts';
136
136
  export {
137
137
  expandRunCommand,
138
138
  runHarnessForSpecs,
@@ -148,6 +148,7 @@ export {
148
148
  extractFrontmatter,
149
149
  readFrontmatterTitle,
150
150
  readNeedsSpecsChange,
151
+ specsPrefixOfInstance,
151
152
  } from './change/frontmatter.ts';
152
153
  export {
153
154
  GitError,
@@ -192,7 +193,7 @@ export {
192
193
  archiveTaskGate,
193
194
  changeDiffInfo,
194
195
  } from './change/lifecycle.ts';
195
- export { normalizeLocale, localeFallbacks } from './templates/locale.ts';
196
+ export { normalizeLocale, localeFallbacks, DEFAULT_LOCALE } from './locale.ts';
196
197
  export {
197
198
  MAX_UNIT_NESTING_DEPTH,
198
199
  renderTemplate,
@@ -202,7 +203,6 @@ export {
202
203
  export {
203
204
  ETHICS_KEYS,
204
205
  buildTemplateVars,
205
- effectiveCheckCommand,
206
206
  enforceEthicsGovernance,
207
207
  loadLocaleResource,
208
208
  loadSkillTemplates,
@@ -227,6 +227,7 @@ export {
227
227
  type InitResult,
228
228
  } from './init/init.ts';
229
229
  export {
230
+ changeTitle,
230
231
  collectChanges,
231
232
  statusFor,
232
233
  stageFor,
@@ -287,6 +288,14 @@ export {
287
288
  frozenCardName,
288
289
  isFrozenCard,
289
290
  } from './archive/frozenCard.ts';
291
+ export {
292
+ IgnoreChainError,
293
+ collectFilteredEntries,
294
+ discoverIgnoreRoot,
295
+ type CollectFilteredOpts,
296
+ type FilteredCandidate,
297
+ type IgnoreChainIo,
298
+ } from './archive/ignoreChain.ts';
290
299
  export {
291
300
  buildReview,
292
301
  renderReviewHtml,
@@ -336,3 +345,18 @@ export {
336
345
  type TierEntry,
337
346
  type TreeToolDeps,
338
347
  } from './context/retrieve.ts';
348
+ export { maxUsedNumber, nextNumber } from './util/nextNumber.ts';
349
+ export {
350
+ COMPLETION_BIN,
351
+ COMPLETION_MARKER_END,
352
+ COMPLETION_MARKER_START,
353
+ COMPLETION_SHELLS,
354
+ collectFlags,
355
+ completionBlock,
356
+ isCompletionShell,
357
+ renderCompletionScript,
358
+ resolveBashRc,
359
+ upsertCompletionBlock,
360
+ type CompletionCommandSpec,
361
+ type CompletionShell,
362
+ } from './self/completion.ts';
@@ -1,39 +1,13 @@
1
1
  /**
2
- * Default llmanspec/config.yaml templates, extracted verbatim from predecessor
3
- * (crates/llman-sdd/src/sdd/project/config.rs DEFAULT_CONFIG_EN/ZH_HANS).
2
+ * Default llmanspec/config.yaml body (init-generators r19/r50): one built-in
3
+ * locale (zh-Hans), ported from the predecessor (crates/llman-sdd/src/sdd/
4
+ * project/config.rs DEFAULT_CONFIG_ZH_HANS).
4
5
  */
6
+ import { DEFAULT_LOCALE } from '../locale.ts';
7
+
5
8
  export const LLMANSPEC_SCHEMA_URL =
6
9
  'https://raw.githubusercontent.com/StrayDragon/llman/main/artifacts/schema/configs/en/llmanspec-config.schema.json';
7
10
 
8
- export const DEFAULT_CONFIG_EN = `schema: spec-driven
9
- locale: en
10
-
11
- # Optional extra skills (disabled by default, uncomment to enable).
12
- # On \`llman-sdd init --update\`, managed candidates are:
13
- # default workflow skills + entries listed here (extra_skills extend).
14
- # Then \`.agents/skills/llman-sdd-*\` is scanned: anything not in that candidate
15
- # set is removed first, then candidates are written/updated. Only the
16
- # \`llman-sdd-\` prefix is touched (custom skills without that prefix are kept).
17
- # Deprecated shipped skills (e.g. removed from defaults) are cleaned this way.
18
- # extra_skills:
19
- # - llman-sdd-continue
20
- # - llman-sdd-ff
21
- # - llman-sdd-validate
22
- # - llman-sdd-arch-review
23
- # - llman-sdd-wayfinder
24
- # - llman-sdd-research
25
-
26
- # Spec verification (optional, uncomment to enable)
27
- # specs:
28
- # framework: pytest-bdd
29
- # # Filtered runners: include {feature_*} so validate --all/--specs runs per capability.
30
- # # check_command: "pytest {feature_dir} -k {feature_name} -v"
31
- # # Project-wide runners (no placeholders): validate --all/--specs runs the suite once (batch-once).
32
- # # check_command: "cargo test --features bdd"
33
- # # verify_prompt: |
34
- # # Map test failures to requirement IDs.
35
- `;
36
-
37
11
  export const DEFAULT_CONFIG_ZH_HANS = `schema: spec-driven
38
12
  locale: zh-Hans
39
13
 
@@ -67,3 +41,12 @@ export function prependSchemaHeader(content: string, schemaUrl: string): string
67
41
  if (content === '') return `${header}\n`;
68
42
  return `${header}\n${content}`;
69
43
  }
44
+
45
+ /**
46
+ * Built-in default config bodies by normalized locale. The lookup keeps the
47
+ * single-source shape of the locale chain (r18/r50): a locale is normalized
48
+ * first, then resolved; no exact-string comparison on the raw input.
49
+ */
50
+ export const DEFAULT_CONFIGS: Readonly<Record<string, string>> = {
51
+ [DEFAULT_LOCALE]: DEFAULT_CONFIG_ZH_HANS,
52
+ };