@llman-sdd/core 0.10.1 → 0.12.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 (119) hide show
  1. package/package.json +11 -8
  2. package/src/archive/freeze.ts +41 -15
  3. package/src/archive/frozenCard.ts +57 -9
  4. package/src/archive/ignoreChain.ts +2 -6
  5. package/src/archive/sevenzip.ts +0 -1
  6. package/src/change/closeOutHarness.ts +17 -0
  7. package/src/change/collect.ts +0 -5
  8. package/src/change/frontmatter.ts +15 -7
  9. package/src/change/id.ts +0 -2
  10. package/src/change/lifecycle.ts +53 -94
  11. package/src/config/changeId.ts +0 -2
  12. package/src/config/load.ts +0 -4
  13. package/src/config/schema.ts +24 -13
  14. package/src/config/surface.ts +2 -12
  15. package/src/context/sddState.ts +23 -18
  16. package/src/git/spawnGit.ts +0 -3
  17. package/src/hints/jitHints.ts +82 -0
  18. package/src/index.ts +462 -39
  19. package/src/init/defaultConfig.ts +4 -13
  20. package/src/init/init.ts +108 -36
  21. package/src/init/skillCheck.ts +60 -0
  22. package/src/init/uncommentConfig.ts +909 -0
  23. package/src/locale.ts +0 -2
  24. package/src/project/migrateNotes.ts +0 -9
  25. package/src/project/migrations.ts +151 -9
  26. package/src/report/graph/analysis.ts +0 -4
  27. package/src/report/graph/nodes.ts +0 -6
  28. package/src/report/show.ts +7 -23
  29. package/src/report/specHelpers.ts +10 -14
  30. package/src/review/review.ts +0 -12
  31. package/src/spec/assignSpecIds.ts +0 -3
  32. package/src/spec/authoring.ts +16 -24
  33. package/src/spec/ir.ts +14 -5
  34. package/src/spec/keywords.ts +0 -2
  35. package/src/spec/machineKey.ts +49 -0
  36. package/src/spec/migrateNative.ts +4 -18
  37. package/src/spec/parser.ts +10 -19
  38. package/src/spec/reqRef.ts +135 -0
  39. package/src/studio/changeScope.ts +50 -0
  40. package/src/studio/changeScopeDiff.ts +195 -0
  41. package/src/studio/contracts.ts +493 -0
  42. package/src/studio/decisionTree.ts +206 -0
  43. package/src/studio/deeplink.ts +116 -0
  44. package/src/studio/demos.ts +167 -0
  45. package/src/studio/diff.ts +494 -0
  46. package/src/studio/drift.ts +738 -0
  47. package/src/studio/extract.ts +360 -0
  48. package/src/studio/featureSync.ts +592 -0
  49. package/src/studio/forest.ts +570 -0
  50. package/src/studio/index.ts +32 -0
  51. package/src/studio/model.ts +254 -0
  52. package/src/studio/revisions.ts +476 -0
  53. package/src/studio/search.ts +337 -0
  54. package/src/studio/store.ts +811 -0
  55. package/src/studio/sync.ts +912 -0
  56. package/src/studio/textfold.ts +72 -0
  57. package/src/studio/time.ts +107 -0
  58. package/src/studio/validate.ts +363 -0
  59. package/src/templates/embedded.ts +4 -6
  60. package/src/templates/engine.ts +1 -1
  61. package/src/templates/skills.ts +76 -51
  62. package/src/theorems/guard.ts +52 -0
  63. package/src/theorems/index.ts +56 -0
  64. package/src/theorems/migrate.ts +133 -0
  65. package/src/theorems/schema.ts +67 -0
  66. package/src/theorems/scope.ts +68 -0
  67. package/src/theorems/serialize.ts +60 -0
  68. package/src/theorems/transactionMachine.ts +247 -0
  69. package/src/theorems/validate.ts +141 -0
  70. package/src/util/nextNumber.ts +0 -2
  71. package/src/validation/changeCheck.ts +0 -24
  72. package/src/validation/flowAndNesting.ts +434 -0
  73. package/src/validation/harness.ts +108 -65
  74. package/src/validation/validate.ts +26 -12
  75. package/src/validation/xstateTransitions.ts +483 -184
  76. package/templates/zh-Hans/llmanspec-agents-stub.md +17 -2
  77. package/templates/zh-Hans/skills/llman-sdd-autopilot/SKILL.md +34 -0
  78. package/templates/zh-Hans/skills/llman-sdd-change/SKILL.md +44 -0
  79. package/templates/zh-Hans/skills/llman-sdd-change/playbooks/archive.md +15 -0
  80. package/templates/zh-Hans/skills/llman-sdd-change/playbooks/draft.md +9 -0
  81. package/templates/zh-Hans/skills/llman-sdd-review/SKILL.md +71 -0
  82. package/templates/zh-Hans/skills/llman-sdd-specs/SKILL.md +70 -0
  83. package/templates/zh-Hans/skills/llman-sdd-specs/playbooks/compact.md +12 -0
  84. package/templates/zh-Hans/skills/llman-sdd-specs/playbooks/doctor.md +26 -0
  85. package/templates/zh-Hans/skills/llman-sdd-specs/references/graph-dsl.md +33 -0
  86. package/templates/zh-Hans/skills/llman-sdd-studio/SKILL.md +33 -0
  87. package/templates/zh-Hans/skills/llman-sdd-studio/playbooks/collab.md +20 -0
  88. package/templates/zh-Hans/skills/llman-sdd-studio/playbooks/drift.md +52 -0
  89. package/templates/zh-Hans/skills/llman-sdd-studio/playbooks/onboard.md +33 -0
  90. package/templates/zh-Hans/units/skills/cli-footer.md +2 -2
  91. package/src/context/indexStore.ts +0 -171
  92. package/src/context/retrieve.ts +0 -332
  93. package/src/context/tree.ts +0 -112
  94. package/templates/zh-Hans/agents-root-stub.md +0 -9
  95. package/templates/zh-Hans/skills/llman-sdd-apply-cycle.md +0 -69
  96. package/templates/zh-Hans/skills/llman-sdd-apply.md +0 -117
  97. package/templates/zh-Hans/skills/llman-sdd-arch-review.md +0 -58
  98. package/templates/zh-Hans/skills/llman-sdd-archive.md +0 -79
  99. package/templates/zh-Hans/skills/llman-sdd-continue.md +0 -34
  100. package/templates/zh-Hans/skills/llman-sdd-draft.md +0 -53
  101. package/templates/zh-Hans/skills/llman-sdd-explore.md +0 -64
  102. package/templates/zh-Hans/skills/llman-sdd-ff.md +0 -33
  103. package/templates/zh-Hans/skills/llman-sdd-graph.md +0 -56
  104. package/templates/zh-Hans/skills/llman-sdd-propose.md +0 -107
  105. package/templates/zh-Hans/skills/llman-sdd-quick.md +0 -41
  106. package/templates/zh-Hans/skills/llman-sdd-research.md +0 -35
  107. package/templates/zh-Hans/skills/llman-sdd-specs-compact.md +0 -41
  108. package/templates/zh-Hans/skills/llman-sdd-validate.md +0 -28
  109. package/templates/zh-Hans/skills/llman-sdd-verify.md +0 -77
  110. package/templates/zh-Hans/skills/llman-sdd-wayfinder.md +0 -83
  111. package/templates/zh-Hans/units/skills/ethics-governance.md +0 -6
  112. package/templates/zh-Hans/units/skills/git-native-flow.md +0 -56
  113. package/templates/zh-Hans/units/skills/human-readable-summary.md +0 -9
  114. package/templates/zh-Hans/units/skills/index-fallback.md +0 -1
  115. package/templates/zh-Hans/units/skills/stage-guard.md +0 -17
  116. package/templates/zh-Hans/units/skills/structured-protocol.md +0 -19
  117. package/templates/zh-Hans/units/skills/validation-hints.md +0 -20
  118. package/templates/zh-Hans/units/skills/version-drift.md +0 -3
  119. package/templates/zh-Hans/units/spec/feature-contract.md +0 -8
@@ -37,8 +37,6 @@ export type FsIo = Pick<FsPort, 'exists' | 'readText' | 'writeText' | 'rename' |
37
37
 
38
38
  export class LifecycleError extends Error {}
39
39
 
40
- // r74: single git-gate message family shared by start/attach/finalize/archive
41
- // (stable substrings for matching; no internal requirement ids in output).
42
40
  const detachedHead = (cmd: string): string =>
43
41
  `\`${cmd}\` refuses a detached HEAD; check out a branch first`;
44
42
  const notOnBoundBranch = (cmd: string, bound: string, current: string | null): string =>
@@ -64,8 +62,6 @@ export function newChange(
64
62
  `change proposal already exists: ./${path} (pass --force to overwrite)`,
65
63
  );
66
64
  }
67
- // r99: skeleton carries a non-empty title placeholder so a fresh draft
68
- // passes the title gate; agents rewrite it when filling the proposal.
69
65
  io.writeText(path, `---\ndepends_on: []\ntitle: TODO\n---\n\n${DRAFT_PROPOSAL_TEMPLATE}`);
70
66
  return { id, path };
71
67
  }
@@ -73,10 +69,10 @@ export function newChange(
73
69
  export interface StartResult {
74
70
  branch: string;
75
71
  baseBranch: string;
76
- /** Where the recorded base_branch came from (r95 deviation warning input). */
77
- baseSource: 'flag' | 'worktree' | 'default';
72
+ /** Where the recorded base_branch came from. */
73
+ baseSource: AttachBaseSource | 'worktree';
78
74
  baseSha: string;
79
- /** Absolute worktree path when started with --worktree (r68); undefined on the classic path. */
75
+ /** Absolute worktree path when started with --worktree; undefined when binding the current branch. */
80
76
  worktreePath?: string;
81
77
  }
82
78
 
@@ -124,7 +120,7 @@ function resolveWorktreePath(
124
120
  naming: 'id' | 'hash' | undefined,
125
121
  ): string {
126
122
  const toplevel = git.run(['rev-parse', '--show-toplevel']);
127
- // git rev-parse --show-toplevel emits forward-slash paths even on win32
123
+ // git rev-parse --show-toplevel emits forward-slash paths even on win32 ~keep
128
124
  // (git-for-Windows normalizes) — POSIX by contract; keep '/'-splitting.
129
125
  const cut = toplevel.lastIndexOf('/');
130
126
  const basename = toplevel.slice(cut + 1);
@@ -177,13 +173,29 @@ export function startChange(
177
173
  worktreeNaming?: 'id' | 'hash';
178
174
  /** r119: instance dir relative to the git toplevel ('' at the repo root). */
179
175
  instanceDirRel?: string;
176
+ /** Rebind when the change is already attached to a branch. */
177
+ force?: boolean;
180
178
  } = {},
181
179
  ): StartResult {
182
180
  const path = proposalPath(id);
183
181
  if (!io.exists(path)) throw new LifecycleError(`proposal not found: ${path}`);
182
+ const here = currentBranch(git);
183
+ if (
184
+ !opts.worktree &&
185
+ here !== null &&
186
+ here !== '' &&
187
+ here !== defaultBranch(git) &&
188
+ !opts.force
189
+ ) {
190
+ const existing = readBinding(io.readText(path));
191
+ if (existing !== null) {
192
+ throw new LifecycleError(
193
+ `change \`${id}\` already attached to branch \`${existing.branch}\` (base ${existing.baseSha}); pass --force to rebind`,
194
+ );
195
+ }
196
+ }
184
197
  const dirty = dirtyCount(git);
185
198
  if (dirty > 0) throw new LifecycleError(dirtyTree('change start'));
186
- const here = currentBranch(git);
187
199
  if (here === null) throw new LifecycleError(detachedHead('change start'));
188
200
  const branchPrefix = opts.branchPrefix ?? 'sdd/';
189
201
  const branch = `${branchPrefix}${id}`;
@@ -192,9 +204,16 @@ export function startChange(
192
204
  assertLocalBase(git, opts.base, branch, 'new');
193
205
  }
194
206
 
195
- // r68 fork-source resolution: --base explicit > current branch (worktree
196
- // mode records the actual source, which may be a non-default branch) >
197
- // default branch. The classic path keeps the r14 default-branch gate.
207
+ if (!opts.worktree && here !== defaultBranch(git)) {
208
+ const bound = attachChange(git, io, id, { force: opts.force, base: opts.base });
209
+ return {
210
+ branch: bound.branch,
211
+ baseBranch: bound.baseBranch,
212
+ baseSource: bound.baseSource,
213
+ baseSha: bound.baseSha,
214
+ };
215
+ }
216
+
198
217
  let baseBranch: string;
199
218
  let baseSource: StartResult['baseSource'];
200
219
  if (opts.base !== undefined) {
@@ -206,11 +225,6 @@ export function startChange(
206
225
  } else {
207
226
  baseBranch = defaultBranch(git);
208
227
  baseSource = 'default';
209
- if (here !== baseBranch) {
210
- throw new LifecycleError(
211
- `already on non-default branch \`${here}\`; use \`change attach\` to bind it, or switch to the default branch before \`change start\``,
212
- );
213
- }
214
228
  }
215
229
 
216
230
  let worktreePath: string | undefined;
@@ -223,14 +237,6 @@ export function startChange(
223
237
  throw new LifecycleError(`worktree path already exists: ${worktreePath}`);
224
238
  }
225
239
  git.run(['worktree', 'add', '-b', branch, worktreePath]);
226
- // r68: the binding lands in the NEW worktree's proposal — the initiating
227
- // checkout stays byte-identical (zero writes through the original io).
228
- // The clean-tree gate guaranteed the proposal is committed at HEAD, so it
229
- // is present in the fresh worktree; a missing one rolls everything back.
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
240
  const instanceDirRel = opts.instanceDirRel ?? '';
235
241
  const wtRoot = instanceDirRel === '' ? worktreePath : `${worktreePath}/${instanceDirRel}`;
236
242
  const wtIo = ioAt(io, wtRoot);
@@ -269,14 +275,11 @@ export function attachChange(
269
275
  }
270
276
  const branch = currentBranch(git);
271
277
  if (branch === null || branch === '') {
272
- throw new LifecycleError(detachedHead('change attach'));
278
+ throw new LifecycleError(detachedHead('change start'));
273
279
  }
274
280
  if (opts.base !== undefined) {
275
281
  assertLocalBase(git, opts.base, branch, 'bound');
276
282
  }
277
- // r95 fork-source resolution: --base explicit > probeForkSource
278
- // (branch.<name>.base > local upstream) > default branch. No signal means
279
- // status quo (issue #7 compatibility: "无法推导维持现状").
280
283
  const fork =
281
284
  opts.base !== undefined
282
285
  ? { branch: opts.base, source: 'flag' as const }
@@ -286,7 +289,7 @@ export function attachChange(
286
289
  });
287
290
  if (branch === fork.branch) {
288
291
  throw new LifecycleError(
289
- `${onDefaultBranch('change attach', branch)}; create or switch to a feature branch, or use \`change start\``,
292
+ `${onDefaultBranch('change start', branch)}; create or switch to a feature branch before binding the current checkout`,
290
293
  );
291
294
  }
292
295
  const baseSha = mergeBase(git, branch, fork.branch);
@@ -338,8 +341,6 @@ export function closeOutGate(change: {
338
341
  }): { ok: boolean; reason: string | null } {
339
342
  const { git, io, id, binding } = change;
340
343
  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
344
  const tasksPath = `${CHANGES_DIR}/${id}/tasks.md`;
344
345
  const gate = archiveTaskGate(io.exists(tasksPath) ? io.readText(tasksPath) : null);
345
346
  if (gate.blocked) {
@@ -388,14 +389,12 @@ export function finalizeChange(
388
389
  const path = proposalPath(id);
389
390
  const binding = readBinding(io.readText(path));
390
391
  if (binding === null) {
391
- throw new LifecycleError(`change \`${id}\` has no branch binding — run start/attach first`);
392
+ throw new LifecycleError(`change \`${id}\` has no branch binding — run \`change start\` first`);
392
393
  }
393
- // T34 close-out gate before any write: specs-landed verdict + task gate.
394
394
  const closeOut = closeOutGate({ git, io, id, binding, specsPrefix: opts.specsPrefix });
395
395
  if (!closeOut.ok) {
396
396
  throw new LifecycleError(closeOut.reason as string);
397
397
  }
398
- // r40 unchecked-task detail lines (D9 close-out pseudo-task hint).
399
398
  const tasksPath = `${CHANGES_DIR}/${id}/tasks.md`;
400
399
  const gate = archiveTaskGate(io.exists(tasksPath) ? io.readText(tasksPath) : null);
401
400
  if (gate.blocked) {
@@ -412,11 +411,9 @@ export function finalizeChange(
412
411
  ].join('\n'),
413
412
  );
414
413
  }
415
- // r15 (predecessor r94): finalize runs on the bound branch — any other branch must
416
- // fail before any write (no switch, no merge, no rename).
417
414
  const current = currentBranch(git);
418
415
  if (current !== binding.branch) {
419
- throw new LifecycleError(notOnBoundBranch('change finalize', binding.branch, current));
416
+ throw new LifecycleError(notOnBoundBranch('change archive', binding.branch, current));
420
417
  }
421
418
  const method = opts.method ?? 'squash';
422
419
  const target = opts.into ?? binding.baseBranch ?? defaultBranch(git);
@@ -475,9 +472,6 @@ function mergeRenameCommit(
475
472
  instanceDirRel = '',
476
473
  ): FinalizeResult {
477
474
  const warnings: string[] = [];
478
- // r69: when the target branch is checked out in another worktree, `git
479
- // switch` there would fail outright — run every write (switch / merge /
480
- // rename / commit) inside the holding worktree instead.
481
475
  const here = git.runOpt(['rev-parse', '--show-toplevel']);
482
476
  const holder = holderOfWorktree(git, target);
483
477
  let execGit = git;
@@ -496,18 +490,9 @@ function mergeRenameCommit(
496
490
  );
497
491
  }
498
492
  execGit = gitAt(git, 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
493
  execIo = ioAt(io, instanceDirRel === '' ? holder : `${holder}/${instanceDirRel}`);
504
494
  executedIn = holder;
505
495
  }
506
- // r96: in-place close-out — merging a branch into itself is always a no-op
507
- // ("Already up to date."), so skip the merge and say so instead of running a
508
- // silent self-merge. The switch still runs (a no-op when already there) so
509
- // escape hatches like `archive --force` from a foreign branch land the
510
- // rename and close-out commit on the bound branch, not the current one.
511
496
  execGit.run(['switch', target]);
512
497
  if (target === featureBranch) {
513
498
  warnings.push('in-place close-out: merge target is the bound branch itself; merge skipped');
@@ -540,7 +525,7 @@ function mergeRenameCommit(
540
525
  return { target, archiveDir, warnings, commitSubject, executedIn };
541
526
  }
542
527
 
543
- /** `change archive`: independent seal-off with task + strict git gates (r39/r40). */
528
+ /** `change archive`: task gates, clean tree, merge, rename, optional close-out commit. */
544
529
  export function archiveChange(
545
530
  git: GitLike,
546
531
  io: FsIo,
@@ -548,68 +533,42 @@ export function archiveChange(
548
533
  opts: {
549
534
  into?: string;
550
535
  method?: 'squash' | 'ff';
551
- force?: boolean;
552
536
  /** CLI already enforced a clean tree before the acceptance command ran. */
553
537
  skipCleanTree?: boolean;
554
538
  today: string;
539
+ noCommit?: boolean;
555
540
  /** r119: instance-relative specs prefix of the change's own root. */
556
541
  specsPrefix?: string;
557
542
  },
558
543
  ): FinalizeResult {
559
544
  const path = proposalPath(id);
560
545
  const binding = readBinding(io.readText(path));
561
- if (!opts.force && binding === null) {
562
- throw new LifecycleError(`change \`${id}\` has no branch binding — run start/attach first`);
546
+ if (binding === null) {
547
+ throw new LifecycleError(`change \`${id}\` has no branch binding — run \`change start\` first`);
563
548
  }
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);
568
- const tasksPath = `${CHANGES_DIR}/${id}/tasks.md`;
569
- const gate = archiveTaskGate(io.exists(tasksPath) ? io.readText(tasksPath) : null);
570
- if (gate.blocked) {
571
- // D9: when a pending unchecked task starts with a close-out verb, append
572
- // the same remediation hint as the validate WARNING (single constant).
573
- const closeOut = closeOutTaskLines(gate.pendingLines);
574
- throw new LifecycleError(
575
- [
576
- `archive blocked by unchecked tasks (${gate.pendingLines.length} pending)`,
577
- ...gate.pendingLines,
578
- ...(closeOut.length > 0
579
- ? [
580
- `task "${closeOut[0]?.replace(/^-\s+\[ \]\s*/u, '').trim() ?? ''}" looks like a close-out step; ${CLOSE_OUT_TASK_HINT}`,
581
- ]
582
- : []),
583
- ].join('\n'),
584
- );
585
- }
586
- const current = currentBranch(git);
587
- if (current === null || current === '')
588
- throw new LifecycleError(detachedHead('change archive'));
589
- if (current !== binding?.branch) {
590
- throw new LifecycleError(
591
- notOnBoundBranch('change archive', (binding?.branch ?? '') as string, current),
592
- );
593
- }
594
- if (current === defaultBranch(git)) {
595
- throw new LifecycleError(onDefaultBranch('change archive', current));
596
- }
597
- if (!opts.skipCleanTree && !isCleanTree(git))
598
- throw new LifecycleError(dirtyTree('change archive'));
599
- } else if (binding === null) {
600
- throw new LifecycleError(`change \`${id}\` has no branch binding — cannot merge`);
549
+ const closeOut = closeOutGate({ git, io, id, binding, specsPrefix: opts.specsPrefix });
550
+ if (!closeOut.ok) throw new LifecycleError(closeOut.reason as string);
551
+ const current = currentBranch(git);
552
+ if (current === null || current === '') throw new LifecycleError(detachedHead('change archive'));
553
+ if (current !== binding.branch) {
554
+ throw new LifecycleError(notOnBoundBranch('change archive', binding.branch, current));
601
555
  }
556
+ if (current === defaultBranch(git)) {
557
+ throw new LifecycleError(onDefaultBranch('change archive', current));
558
+ }
559
+ if (!opts.skipCleanTree && !isCleanTree(git))
560
+ throw new LifecycleError(dirtyTree('change archive'));
602
561
  const method = opts.method ?? 'squash';
603
- const target = opts.into ?? binding?.baseBranch ?? defaultBranch(git);
562
+ const target = opts.into ?? binding.baseBranch ?? defaultBranch(git);
604
563
  return mergeRenameCommit(
605
564
  git,
606
565
  io,
607
566
  id,
608
- binding?.branch as string,
567
+ binding.branch,
609
568
  target,
610
569
  method,
611
570
  opts.today,
612
- undefined,
571
+ opts.noCommit,
613
572
  instanceDirRelOf(opts.specsPrefix ?? DEFAULT_SPECS_PREFIX),
614
573
  );
615
574
  }
@@ -37,8 +37,6 @@ export interface ChangeIdVars {
37
37
  * autoescape:false — this file no longer imports the adapter directly.
38
38
  */
39
39
  export function renderChangeIdTemplate(template: string, vars: ChangeIdVars): string {
40
- // Named pre-check (predecessor parity): referencing an unprovided variable errors with
41
- // the variable name and the preset list, instead of a generic render error.
42
40
  const provided = new Set(
43
41
  Object.keys(vars).filter((k) => vars[k as keyof ChangeIdVars] !== undefined),
44
42
  );
@@ -120,16 +120,12 @@ export function loadConfigDetail(source: string): {
120
120
  });
121
121
  throw new ConfigValidationError(issues);
122
122
  }
123
- // r59: compile change_id.pattern at load time so EVERY config-reading
124
123
  // command path (archive/skeleton/review included) fails fast on an invalid
125
- // regex instead of silently passing it through.
126
124
  const pattern = result.data.change_id?.pattern;
127
125
  if (pattern !== undefined && pattern !== null && pattern !== '') {
128
126
  try {
129
127
  compileChangeIdPattern(pattern);
130
128
  } catch (error) {
131
- // ChangeIdError message already carries the change_id.pattern path and
132
- // the regex engine's original error.
133
129
  throw new ConfigValidationError([(error as Error).message]);
134
130
  }
135
131
  }
@@ -8,15 +8,6 @@ import { z } from 'zod';
8
8
 
9
9
  import { DEFAULT_LOCALE } from '../locale.ts';
10
10
 
11
- export const EXTRA_SKILLS = [
12
- 'llman-sdd-continue',
13
- 'llman-sdd-ff',
14
- 'llman-sdd-validate',
15
- 'llman-sdd-arch-review',
16
- 'llman-sdd-wayfinder',
17
- 'llman-sdd-research',
18
- ] as const;
19
-
20
11
  export const specsSchema = z.object({
21
12
  framework: z
22
13
  .string()
@@ -31,6 +22,12 @@ export const specsSchema = z.object({
31
22
  'Spec verification command executed by validate for spec targets (opt-in via --check; default skips). Placeholders: {feature_path}, {feature_dir}, {feature_name}; without placeholders it runs once per validate invocation (batch-once). Legacy `bdd.run_command` is elevated onto this key at load time.',
32
23
  ),
33
24
  verify_prompt: z.string().nullish().describe('Extra prompt text injected during verify phase.'),
25
+ check_dangling_bdd_command: z
26
+ .string()
27
+ .nullish()
28
+ .describe(
29
+ 'Optional project-owned dangling-BDD check (unused step/scenario glue). Same placeholders and batch-once as check_command. Executed by validate --check and change archive when set; unset skips with no warning. Not derived from framework.',
30
+ ),
34
31
  });
35
32
 
36
33
  export const archiveSchema = z.object({
@@ -74,13 +71,24 @@ export const changeIdSchema = z.object({
74
71
  .describe('Template rendered by `change new --from` with preset vars.'),
75
72
  });
76
73
 
74
+ export const reviewSchema = z.object({
75
+ handoff_mode: z
76
+ .enum(['ask', 'inline', 'file'])
77
+ .default('ask')
78
+ .describe(
79
+ 'Independent review prompt handoff mode when subagent dispatch is unavailable: "ask" (default), "inline", or "file".',
80
+ ),
81
+ handoff_file: z
82
+ .string()
83
+ .nullish()
84
+ .describe(
85
+ 'Target file path written when review.handoff_mode is "file". Default: ".llman-sdd/review-handoff.md".',
86
+ ),
87
+ });
88
+
77
89
  export const sddConfigSchema = z.object({
78
90
  schema: z.literal('spec-driven').describe('Schema identifier. Must be "spec-driven".'),
79
91
  locale: z.string().default(DEFAULT_LOCALE).describe('Locale used for SDD templates and skills.'),
80
- extra_skills: z
81
- .array(z.enum(EXTRA_SKILLS))
82
- .nullish()
83
- .describe('Additional optional SDD skills to enable (extend candidates on init --update).'),
84
92
  archive: archiveSchema
85
93
  .nullish()
86
94
  .describe('Archive behaviour settings (defer tracking, completion gates).'),
@@ -95,6 +103,9 @@ export const sddConfigSchema = z.object({
95
103
  change_id: changeIdSchema
96
104
  .nullish()
97
105
  .describe('Optional machine-readable change id naming convention.'),
106
+ review: reviewSchema
107
+ .nullish()
108
+ .describe('Independent review handoff preferences for single-session environments.'),
98
109
  });
99
110
 
100
111
  export type SddConfig = z.output<typeof sddConfigSchema>;
@@ -1,29 +1,19 @@
1
1
  /**
2
- * `config` command surface (r37/r38): read-only overview rendering and the
3
- * skills listing shape (the extra_skills write path was removed with
4
- * config-command r38).
2
+ * `config` command surface: read-only overview. Skill install is `init --update`.
5
3
  */
6
4
 
7
5
  import { loadConfig } from './load.ts';
8
- import { EXTRA_SKILLS } from './schema.ts';
9
6
 
10
- /** Render the five-element overview (predecessor parity wording). */
7
+ /** Render the overview (schema, locale, specs, archive). */
11
8
  export function renderConfigOverview(source: string): string[] {
12
9
  const config = loadConfig(source);
13
- const enabled = (config.extra_skills ?? []).length;
14
10
  const archive = config.archive;
15
11
  const archiveConfigured =
16
12
  archive !== null && archive !== undefined && archive.strict_defer === true;
17
13
  return [
18
14
  `schema: ${config.schema}`,
19
15
  `locale: ${config.locale}`,
20
- `extra_skills (enabled/total): ${enabled} / ${EXTRA_SKILLS.length}`,
21
16
  `specs: ${config.specs ? 'on' : 'off'}`,
22
17
  `archive: ${archiveConfigured ? 'configured' : 'default'}`,
23
18
  ];
24
19
  }
25
-
26
- /** Shape of `config skills --json` (predecessor parity). */
27
- export function skillsJson(source: string): { enabled: string[]; available: readonly string[] } {
28
- return { enabled: [...(loadConfig(source).extra_skills ?? [])], available: EXTRA_SKILLS };
29
- }
@@ -1,13 +1,13 @@
1
1
  /**
2
- * Scaffold-state record (version-awareness capability): init stamps the CLI
3
- * version that rendered the project so later runs can detect drift. All paths
4
- * ROOT-RELATIVE through the injected IO; corrupt/missing state is silent-OK
5
- * (the notice is best-effort, never load-bearing).
2
+ * Scaffold-state record (version-awareness): init stamps the CLI version that
3
+ * rendered the project so later runs can detect drift. The stamp lives at
4
+ * `llmanspec/.sdd-state.json`. Reads fall back to the previous
5
+ * `llmanspec/.context/sdd-state.json` and never delete it. Writes only the
6
+ * new path. Corrupt or missing state is silent-OK.
6
7
  */
7
8
 
8
- import { CONTEXT_DIR_REL } from './indexStore.ts';
9
-
10
- export const SDD_STATE_REL = `${CONTEXT_DIR_REL}/sdd-state.json`;
9
+ export const SDD_STATE_REL = 'llmanspec/.sdd-state.json';
10
+ export const LEGACY_SDD_STATE_REL = 'llmanspec/.context/sdd-state.json';
11
11
 
12
12
  export interface SddState {
13
13
  /** llman-sdd version that last rendered this project (init / --update). */
@@ -21,18 +21,9 @@ type StateIo = {
21
21
  mkdirp(path: string): void;
22
22
  };
23
23
 
24
- /** Persist the scaffold version (called from runInit after config resolution). */
25
- export function writeSddState(io: StateIo, version: string): void {
26
- io.mkdirp(CONTEXT_DIR_REL);
27
- const state: SddState = { cli_version: version };
28
- io.writeText(SDD_STATE_REL, `${JSON.stringify(state, null, 2)}\n`);
29
- }
30
-
31
- /** Read the recorded version; null when absent/corrupt (silent-OK contract). */
32
- export function readSddState(io: Pick<StateIo, 'exists' | 'readText'>): SddState | null {
33
- if (!io.exists(SDD_STATE_REL)) return null;
24
+ function parseState(raw: string): SddState | null {
34
25
  try {
35
- const parsed: unknown = JSON.parse(io.readText(SDD_STATE_REL));
26
+ const parsed: unknown = JSON.parse(raw);
36
27
  if (
37
28
  typeof parsed === 'object' &&
38
29
  parsed !== null &&
@@ -46,4 +37,18 @@ export function readSddState(io: Pick<StateIo, 'exists' | 'readText'>): SddState
46
37
  }
47
38
  }
48
39
 
40
+ /** Persist the scaffold version. Does not touch the legacy path. */
41
+ export function writeSddState(io: StateIo, version: string): void {
42
+ io.mkdirp('llmanspec');
43
+ const state: SddState = { cli_version: version };
44
+ io.writeText(SDD_STATE_REL, `${JSON.stringify(state, null, 2)}\n`);
45
+ }
46
+
47
+ /** Read the recorded version: new path, then the legacy path. */
48
+ export function readSddState(io: Pick<StateIo, 'exists' | 'readText'>): SddState | null {
49
+ if (io.exists(SDD_STATE_REL)) return parseState(io.readText(SDD_STATE_REL));
50
+ if (io.exists(LEGACY_SDD_STATE_REL)) return parseState(io.readText(LEGACY_SDD_STATE_REL));
51
+ return null;
52
+ }
53
+
49
54
  export { semverLt } from '../util/semver.ts';
@@ -66,8 +66,6 @@ export function localBranchExists(git: GitLike, name: string): boolean {
66
66
  * (r16 resolution order, not a tie-breaker) — because the user explicitly
67
67
  * configured it; anything else falls through to the chain untouched.
68
68
  */
69
- // Local-only default-branch probe (no origin consultation) lives in callers that
70
- // need it; this resolver honors explicit user config first (r16 order).
71
69
  export function defaultBranch(git: GitLike): string {
72
70
  const preferred = git.runOpt(['config', '--get', 'init.defaultBranch']);
73
71
  if (preferred !== null && preferred !== '' && localBranchExists(git, preferred)) {
@@ -163,7 +161,6 @@ export function worktreeList(git: GitLike): WorktreeEntry[] {
163
161
  } else if (line.startsWith('prunable')) {
164
162
  current.prunable = true;
165
163
  }
166
- // `detached` / `bare` marker lines leave branch null on purpose.
167
164
  }
168
165
  if (current !== null) entries.push(current);
169
166
  return entries;
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Pure event-driven contextual CLI hints (Just-in-Time hints, cli r203).
3
+ * Zero IO: core computes single-line next/fix hints and machine-mode gating;
4
+ * CLI renders them to stderr in non-JSON modes so stdout remains pure.
5
+ */
6
+
7
+ export type CliHintKind = 'next' | 'fix';
8
+
9
+ export interface CliHint {
10
+ readonly kind: CliHintKind;
11
+ readonly text: string;
12
+ }
13
+
14
+ export type HintOutputMode = 'toon' | 'json' | 'compact-json' | 'human';
15
+
16
+ /** JSON and compact-json modes must stay 100% pure machine payloads. */
17
+ export function shouldEmitCliHint(mode: HintOutputMode): boolean {
18
+ return mode !== 'json' && mode !== 'compact-json';
19
+ }
20
+
21
+ export function formatCliHint(hint: CliHint): string {
22
+ return `${hint.kind}: ${hint.text}`;
23
+ }
24
+
25
+ export function hintForChangeNew(id: string): CliHint {
26
+ return {
27
+ kind: 'next',
28
+ text: `run \`llman-sdd change start ${id}\` to bind a feature branch (design.md and tasks.md are optional)`,
29
+ };
30
+ }
31
+
32
+ export function hintForChangeStart(id: string): CliHint {
33
+ return {
34
+ kind: 'next',
35
+ text: `edit llmanspec/specs/** on this branch and commit (or set needs_specs_change: false); run \`llman-sdd validate ${id} --check --strict\` when ready`,
36
+ };
37
+ }
38
+
39
+ export function hintForValidateCheckPass(handoffMode?: 'ask' | 'inline' | 'file'): CliHint {
40
+ const mode = handoffMode ?? 'ask';
41
+ return {
42
+ kind: 'next',
43
+ text: `for non-trivial changes, run independent read-only review via llman-sdd-review (single-session review.handoff_mode: ${mode})`,
44
+ };
45
+ }
46
+
47
+ const STUDIO_DIAGNOSTIC_HINTS: Readonly<Record<string, string>> = {
48
+ E1: 'E1: ensure every state/flow table uses valid zh-Hans column headers and non-empty source/target cells',
49
+ E2: 'E2: remove duplicate transition edges or add a distinct condition/branch label',
50
+ E3: 'E3: fix disconnected or unreachable states/steps so all nodes connect from the initial entry',
51
+ E4: 'E4: ensure every terminal path reaches an explicit end state or `[结束:X]` node',
52
+ F3: 'F3: ensure `@flow` outlines have 0 GWT steps and use `当前步骤 | 分支 | 下一步` columns',
53
+ N6: 'N6: align subgraph `[结束:X]` terminal labels with the parent reference node outgoing branch names',
54
+ A1: 'A1: a leaf node without a 引用 pointer must carry a non-empty 人类说明 — fill it in, or add `@req:<id>[#<场景名>]` to expand a child machine',
55
+ };
56
+
57
+ export function hintForStudioDiagnostic(code: string): CliHint | null {
58
+ const text = STUDIO_DIAGNOSTIC_HINTS[code];
59
+ return text === undefined ? null : { kind: 'fix', text };
60
+ }
61
+
62
+ export function hintForValidationIssue(message: string): CliHint | null {
63
+ if (message.includes('# purpose:')) {
64
+ return {
65
+ kind: 'fix',
66
+ text: 'add a `# purpose: <one-line summary>` header comment at the top of the .feature file',
67
+ };
68
+ }
69
+ if (message.includes('Why section') || message.includes('What Changes section')) {
70
+ return {
71
+ kind: 'fix',
72
+ text: 'add both `## Why` and `## What Changes` headings to proposal.md',
73
+ };
74
+ }
75
+ if (message.includes('unchecked task')) {
76
+ return {
77
+ kind: 'fix',
78
+ text: 'complete or check off remaining tasks in tasks.md (or remove close-out pseudo-tasks)',
79
+ };
80
+ }
81
+ return null;
82
+ }