@llman-sdd/cli 0.10.1 → 0.11.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@llman-sdd/cli",
3
- "version": "0.10.1",
3
+ "version": "0.11.0",
4
4
  "description": "Spec-driven development workflow CLI (the `llman-sdd` command)",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -27,8 +27,8 @@
27
27
  "build": "bun run ./scripts/build-binary.ts"
28
28
  },
29
29
  "dependencies": {
30
- "@llman-sdd/core": "0.10.1",
31
- "commander": "^15.0.0"
30
+ "@llman-sdd/core": "0.11.0",
31
+ "commander": "^15.1.0"
32
32
  },
33
33
  "engines": {
34
34
  "bun": ">=1.4.0",
package/src/cli-shared.ts CHANGED
@@ -50,12 +50,12 @@ export function makeCliContext(cwd: string = process.cwd()): CliContext {
50
50
 
51
51
  // Version SSOT is this package's package.json (inlined at compile time — a
52
52
  // single-file binary has no on-disk package.json to read); binary builds
53
- // additionally override it through the LLMAN_SDD_VERSION define injected by
53
+ // additionally override it through the LLMAN_SDD_DEV_BUILD_VERSION define injected by
54
54
  // scripts/build-binary.ts (git tag > package version).
55
55
 
56
56
  // Injected at binary build time by scripts/build-binary.ts; falls back to the
57
57
  // package version when running from source.
58
- const baseVersion = process.env.LLMAN_SDD_VERSION ?? pkg.version;
58
+ const baseVersion = process.env.LLMAN_SDD_DEV_BUILD_VERSION ?? pkg.version;
59
59
 
60
60
  /**
61
61
  * Dev-tree marker (`+dirty.N`): appended when the checkout has uncommitted
@@ -92,12 +92,12 @@ export const version: string = baseVersion;
92
92
 
93
93
  // Compiled single-file binaries have no on-disk templates and Bun <= 1.4.x has
94
94
  // no embedding mechanism, so scripts/build-binary.ts injects the template
95
- // table through the literal define `process.env.LLMAN_SDD_EMBEDDED_TEMPLATES`
95
+ // table through the literal define `process.env.LLMAN_SDD_DEV_BUILD_EMBEDDED_TEMPLATES`
96
96
  // (define only rewrites literal member access — the read must stay here, not
97
97
  // in core); every non-compiled run keeps reading the real filesystem (npm/
98
98
  // source/Node). Both init and `review --export-html` resolve through this one
99
99
  // seam.
100
- const embedded = embeddedTemplates(process.env.LLMAN_SDD_EMBEDDED_TEMPLATES);
100
+ const embedded = embeddedTemplates(process.env.LLMAN_SDD_DEV_BUILD_EMBEDDED_TEMPLATES);
101
101
  export const templateIo: TemplateIo = embedded
102
102
  ? makeEmbeddedTemplateIo(embedded)
103
103
  : {
@@ -219,7 +219,7 @@ export function noteVersionDriftOnce(root: string = process.cwd()): void {
219
219
  if (state === null) return;
220
220
  if (!semverLt(state.cli_version, version)) return;
221
221
  console.error(
222
- `[NOTE] this project was scaffolded with llman-sdd ${state.cli_version}; installed CLI is ${version}. Skill templates/behaviour may have changed — review the changelog and run \`llman-sdd init --update\`.`,
222
+ `[NOTE] this project was scaffolded with llman-sdd ${state.cli_version}; installed CLI is ${version}. Run \`llman-sdd init --check\` and, if it reports a mismatch, \`llman-sdd init --update\`.`,
223
223
  );
224
224
  }
225
225
 
@@ -337,23 +337,6 @@ export const SKILL_DESCRIPTIONS: Record<string, string> = {
337
337
  };
338
338
  export const skillDesc = (name: string): string => SKILL_DESCRIPTIONS[name] ?? '';
339
339
 
340
- export function resolveBackend(flag: string | undefined): 'pageindex' {
341
- // r57 normalization: trim, lowercase, `page-index` alias; blank values
342
- // (unset flag / empty env) collapse to the pageindex default.
343
- const raw = flag ?? process.env.LLMAN_SDD_INDEX_BACKEND ?? '';
344
- const chosen = raw.trim() === '' ? 'pageindex' : raw.trim().toLowerCase();
345
- if (chosen === 'rag') {
346
- throw new Error(
347
- 'Backend `rag` is no longer supported. Use the default pageindex backend instead:\nSet `LLMAN_SDD_INDEX_CHAT_MODEL` to a tool-calling chat model, then\nrun `llman-sdd index rebuild`.',
348
- );
349
- }
350
- const normalized = chosen === 'page-index' ? 'pageindex' : chosen;
351
- if (normalized !== 'pageindex') {
352
- throw new Error(`Unsupported backend: ${chosen}`);
353
- }
354
- return 'pageindex';
355
- }
356
-
357
340
  /**
358
341
  * Tolerant specs-dir half of the root fork (show gates trailer): bare
359
342
  * changes-only workspaces have no resolvable instance root; there the legacy
@@ -28,26 +28,20 @@ function warnIfNotMainCheckout(git: ReturnType<typeof makeCliGit>): void {
28
28
  /**
29
29
  * Compiled binaries have no on-disk 7zz.wasm (Emscripten would probe $bunfs
30
30
  * and abort), so scripts/build-binary.ts injects it as base64 through the
31
- * literal define `process.env.LLMAN_SDD_EMBEDDED_7ZZ_WASM_B64` (define only
31
+ * literal define `process.env.LLMAN_SDD_DEV_BUILD_EMBEDDED_7ZZ_WASM_B64` (define only
32
32
  * rewrites literal member access — the read must stay here, not in core);
33
33
  * unset in source/npm/Node runs → the 7z-wasm glue loads the .wasm from disk.
34
34
  * Directory creation for extraction is likewise injected (core stays pure).
35
35
  */
36
36
  function makeEmbeddedSevenZip(): Promise<SevenZipPort> {
37
37
  return makeWasmSevenZip({
38
- wasmB64: process.env.LLMAN_SDD_EMBEDDED_7ZZ_WASM_B64,
38
+ wasmB64: process.env.LLMAN_SDD_DEV_BUILD_EMBEDDED_7ZZ_WASM_B64,
39
39
  mkdirp: (dir) => mkdirSync(dir, { recursive: true }),
40
40
  });
41
41
  }
42
42
 
43
43
  export function registerArchive(program: Command, ctx: CliContext): void {
44
- const archive = program
45
- .command('archive')
46
- .description(
47
- 'Archive workflow commands (cold backup). Seal a change with `llman-sdd change finalize` first',
48
- );
49
-
50
- const freeze = archive
44
+ const freeze = program
51
45
  .command('freeze')
52
46
  .description('Freeze dated archived changes into a single 7z cold backup')
53
47
  .option('--before <date>', 'freeze entries older than this date (YYYY-MM-DD)')
@@ -97,7 +91,7 @@ export function registerArchive(program: Command, ctx: CliContext): void {
97
91
  },
98
92
  );
99
93
 
100
- const thaw = archive
94
+ const thaw = program
101
95
  .command('thaw')
102
96
  .description('Restore archived change directories from the cold-backup archive')
103
97
  .requiredOption(
@@ -1,18 +1,16 @@
1
1
  import { lstatSync, readdirSync } from 'node:fs';
2
- import { basename, isAbsolute, join, relative, resolve } from 'node:path';
2
+ import { isAbsolute, join, relative, resolve } from 'node:path';
3
3
 
4
4
  import {
5
5
  CLOSE_OUT_TASK_HINT,
6
6
  closeOutTaskLines,
7
7
  archiveChange,
8
- attachChange,
8
+ archiveTaskGate,
9
9
  changeDiff,
10
10
  changeDiffInfo,
11
11
  defaultBranch,
12
12
  deriveChangeId,
13
- finalizeChange,
14
13
  harvestAcrossWorktrees,
15
- archiveTaskGate,
16
14
  isCleanTree,
17
15
  newChange,
18
16
  renderChangeIdTemplate,
@@ -24,7 +22,7 @@ import {
24
22
  readNeedsSpecsChange,
25
23
  type GitLike,
26
24
  } from '@llman-sdd/core';
27
- import { Option, type Command } from 'commander';
25
+ import type { Command } from 'commander';
28
26
 
29
27
  import {
30
28
  CliError,
@@ -202,7 +200,7 @@ function deriveNewId(ctx: CliContext, description: string, verb: string | undefi
202
200
  export function registerChange(program: Command, ctx: CliContext): void {
203
201
  const change = program
204
202
  .command('change')
205
- .description('Change lifecycle: new / start / attach / next-id / diff / finalize');
203
+ .description('Change lifecycle: new / start / next-id / diff / archive');
206
204
 
207
205
  const newCmd = change
208
206
  .command('new')
@@ -248,7 +246,7 @@ export function registerChange(program: Command, ctx: CliContext): void {
248
246
 
249
247
  const startCmd = change
250
248
  .command('start')
251
- .description('Bind the change to a new feature branch (clean tree + default branch gates)')
249
+ .description('Create sdd/<id> on the default branch, or bind the current feature branch')
252
250
  .argument('<id>')
253
251
  .option(
254
252
  '--branch-prefix <prefix>',
@@ -256,8 +254,9 @@ export function registerChange(program: Command, ctx: CliContext): void {
256
254
  )
257
255
  .option(
258
256
  '--base <branch>',
259
- 'explicit fork-source branch to record (must be an existing local branch differing from the new branch; exempts the default-branch gate)',
257
+ 'explicit fork-source branch to record (must be an existing local branch)',
260
258
  )
259
+ .option('--force', 'rebind an already attached change to the current branch')
261
260
  .option(
262
261
  '--worktree',
263
262
  'create the branch in a dedicated worktree (sdd.worktree_root / sdd.worktree_naming config) instead of switching this checkout',
@@ -266,7 +265,13 @@ export function registerChange(program: Command, ctx: CliContext): void {
266
265
  startCmd.action(
267
266
  (
268
267
  id: string,
269
- options: { branchPrefix?: string; base?: string; worktree?: boolean; directory?: string },
268
+ options: {
269
+ branchPrefix?: string;
270
+ base?: string;
271
+ force?: boolean;
272
+ worktree?: boolean;
273
+ directory?: string;
274
+ },
270
275
  ) => {
271
276
  const rctx = reRootContext(ctx, options.directory);
272
277
  const resolved = resolveChangeIdOrExit(rctx, program, id);
@@ -275,11 +280,10 @@ export function registerChange(program: Command, ctx: CliContext): void {
275
280
  const result = startChange(git, rctx.io, resolved.id, {
276
281
  branchPrefix: options.branchPrefix ?? config?.sdd?.branch_prefix ?? 'sdd/',
277
282
  base: options.base,
283
+ force: options.force,
278
284
  worktree: options.worktree,
279
285
  worktreeRoot: config?.sdd?.worktree_root ?? undefined,
280
286
  worktreeNaming: config?.sdd?.worktree_naming ?? undefined,
281
- // r119: the worktree redirect keeps the instance offset (sub-root
282
- // start --worktree binds the SAME instance inside the new worktree).
283
287
  instanceDirRel: instanceDirRelFor(rctx),
284
288
  });
285
289
  warnBaseBranchDeviation(git, result);
@@ -290,32 +294,6 @@ export function registerChange(program: Command, ctx: CliContext): void {
290
294
  },
291
295
  );
292
296
 
293
- const attachCmd = change
294
- .command('attach')
295
- .description('Bind the change to the current feature branch')
296
- .argument('<id>')
297
- .option('--force', 'rebind an already attached change to the current branch')
298
- .option(
299
- '--base <branch>',
300
- 'explicit fork-point branch to record (must be an existing local branch)',
301
- );
302
- addSpecDirOption(attachCmd);
303
- attachCmd.action(
304
- (id: string, options: { force?: boolean; base?: string; directory?: string }) => {
305
- const rctx = reRootContext(ctx, options.directory);
306
- const resolved = resolveChangeIdOrExit(rctx, program, id);
307
- const git = ctx.git;
308
- const result = attachChange(git, rctx.io, resolved.id, {
309
- force: options.force,
310
- base: options.base,
311
- });
312
- warnBaseBranchDeviation(git, result);
313
- console.log(
314
- `attached change \`${resolved.id}\` → branch \`${result.branch}\` base \`${result.baseSha}\` base-branch \`${result.baseBranch}\``,
315
- );
316
- },
317
- );
318
-
319
297
  const nextId = change
320
298
  .command('next-id')
321
299
  .description('Preview the next free change id number (read-only)');
@@ -348,14 +326,16 @@ export function registerChange(program: Command, ctx: CliContext): void {
348
326
 
349
327
  const archiveCmd = change
350
328
  .command('archive')
351
- .description(
352
- 'Independent seal-off: task gates + merge + archive rename + commit (cold backup: `llman-sdd archive freeze`)',
353
- )
329
+ .description('Validate, merge the feature branch, archive docs, and close out')
354
330
  .argument('<id>')
355
- .option('--into <branch>', 'target branch to merge into')
356
- .option('--method <method>', 'merge method: squash | ff')
357
- .option('--dry-run', 'print the rename plan only')
358
- .addOption(new Option('--force', 'skip task and git gates').hideHelp());
331
+ .option('--into <branch>', 'merge target override (defaults to base_branch)')
332
+ .option(
333
+ '--method <method>',
334
+ 'merge method: squash | ff (default: sdd.merge_method config, then squash)',
335
+ )
336
+ .option('--no-check', 'skip the pre-merge validation sweep')
337
+ .option('--no-commit', 'skip the close-out commit (manual/CI history)')
338
+ .option('--dry-run', 'print the rename plan only');
359
339
  addSpecDirOption(archiveCmd);
360
340
  archiveCmd.action(
361
341
  (
@@ -363,8 +343,9 @@ export function registerChange(program: Command, ctx: CliContext): void {
363
343
  options: {
364
344
  into?: string;
365
345
  method?: string;
346
+ check?: boolean;
347
+ commit?: boolean;
366
348
  dryRun?: boolean;
367
- force?: boolean;
368
349
  directory?: string;
369
350
  },
370
351
  ) => {
@@ -372,7 +353,6 @@ export function registerChange(program: Command, ctx: CliContext): void {
372
353
  const rctx = reRootContext(ctx, options.directory);
373
354
  const resolved = resolveChangeIdOrExit(rctx, program, id);
374
355
  id = resolved.id;
375
- const io = rctx.io;
376
356
  if (options.dryRun) {
377
357
  const date = new Date().toISOString().slice(0, 10);
378
358
  console.log(
@@ -380,46 +360,51 @@ export function registerChange(program: Command, ctx: CliContext): void {
380
360
  );
381
361
  return;
382
362
  }
383
- // r40 task gate: single core implementation (archiveTaskGate); the
384
- // CLI only renders the blocked output + options list, byte-identical.
385
- if (!options.force) {
386
- const tasksPath = `llmanspec/changes/${id}/tasks.md`;
387
- const gate = archiveTaskGate(io.exists(tasksPath) ? io.readText(tasksPath) : null);
388
- if (gate.blocked) {
389
- console.error(`Archive blocked: ${gate.pendingLines.length} unchecked task(s).`);
390
- for (const line of gate.pendingLines) {
391
- console.error(` - [ ] ${line.replace(/^-\s+\[ \]\s*/u, '').trim()}`);
392
- }
393
- // D9: point at a close-out pseudo-task with the single shared hint.
394
- const closeOut = closeOutTaskLines(gate.pendingLines);
395
- if (closeOut.length > 0) {
396
- console.error(
397
- ` task "${closeOut[0]?.replace(/^-\s+\[ \]\s*/u, '').trim() ?? ''}" looks like a close-out step; ${CLOSE_OUT_TASK_HINT}`,
398
- );
399
- }
363
+ const tasksPath = `llmanspec/changes/${id}/tasks.md`;
364
+ const gate = archiveTaskGate(rctx.io.exists(tasksPath) ? rctx.io.readText(tasksPath) : null);
365
+ if (gate.blocked) {
366
+ console.error(`Archive blocked: ${gate.pendingLines.length} unchecked task(s).`);
367
+ for (const line of gate.pendingLines) {
368
+ console.error(` - [ ] ${line.replace(/^-\s+\[ \]\s*/u, '').trim()}`);
369
+ }
370
+ const closeOut = closeOutTaskLines(gate.pendingLines);
371
+ if (closeOut.length > 0) {
400
372
  console.error(
401
- 'Options:\n 1. Complete the remaining tasks\n 2. Use --force to archive anyway (not recommended)',
373
+ ` task "${closeOut[0]?.replace(/^-\s+\[ \]\s*/u, '').trim() ?? ''}" looks like a close-out step; ${CLOSE_OUT_TASK_HINT}`,
402
374
  );
403
- throw new Error('archive blocked by unchecked tasks');
404
375
  }
405
- if (!isCleanTree(ctx.git)) {
406
- throw new CliError('`change archive` requires a clean working tree');
376
+ throw new CliError('archive blocked by unchecked tasks');
377
+ }
378
+ if (options.check !== false) {
379
+ const failed = runValidateSweep(rctx);
380
+ if (failed) {
381
+ throw new CliError('archive aborted: validation sweep failed (use --no-check to skip)');
407
382
  }
408
383
  }
409
- enforceCloseOutHarness(rctx, id, false);
410
- const result = archiveChange(ctx.git, io, id, {
384
+ if (!isCleanTree(ctx.git)) {
385
+ throw new CliError('`change archive` requires a clean working tree');
386
+ }
387
+ enforceCloseOutHarness(rctx, id, options.check === false);
388
+ const config = loadCliConfig(rctx.root);
389
+ const method = options.method ?? config?.sdd?.merge_method ?? 'squash';
390
+ const result = archiveChange(ctx.git, rctx.io, id, {
411
391
  into: options.into,
412
- method: options.method as 'squash' | 'ff' | undefined,
413
- force: options.force,
392
+ method: method as 'squash' | 'ff',
414
393
  skipCleanTree: true,
415
394
  today: new Date().toISOString().slice(0, 10),
416
- // r119: judge specs-landing under the change's own instance root.
395
+ noCommit: options.commit === false,
417
396
  specsPrefix: specsPrefixFor(rctx),
418
397
  });
419
- // node:path.basename — platform-aware (win32 backslashes would defeat
420
- // a hand-rolled lastIndexOf('/')).
421
- const archiveName = basename(result.archiveDir ?? '');
422
- console.log(`Change '${id}' archived as '${archiveName}'.`);
398
+ for (const w of result.warnings) console.error(`[WARNING] ${w}`);
399
+ if (options.commit === false) {
400
+ console.log(
401
+ `archived \`${id}\` → ${result.archiveDir} on ${result.target} (close-out commit skipped — run: git add -A && git commit -m "archive(sdd): ${id}")`,
402
+ );
403
+ } else {
404
+ console.log(
405
+ `archived \`${id}\` → ${result.archiveDir} (commit "${result.commitSubject}" on ${result.target})`,
406
+ );
407
+ }
423
408
  if (result.executedIn !== null) {
424
409
  console.log(`executed in target worktree ${result.executedIn}`);
425
410
  }
@@ -469,67 +454,4 @@ export function registerChange(program: Command, ctx: CliContext): void {
469
454
  else console.log(diff);
470
455
  },
471
456
  );
472
-
473
- const finalizeCmd = change
474
- .command('finalize')
475
- .description('Validate, merge the feature branch, archive docs, close out with one commit')
476
- .argument('<id>')
477
- .option('--into <branch>', 'merge target override (defaults to base_branch)')
478
- .option(
479
- '--method <method>',
480
- 'merge method: squash | ff (default: sdd.merge_method config, then squash)',
481
- )
482
- .option('--no-check', 'skip the pre-merge validation sweep')
483
- .option('--no-commit', 'skip the close-out commit (manual/CI history)');
484
- addSpecDirOption(finalizeCmd);
485
- finalizeCmd.action(
486
- (
487
- id: string,
488
- options: {
489
- into?: string;
490
- method?: string;
491
- check?: boolean;
492
- commit?: boolean;
493
- directory?: string;
494
- },
495
- ) => {
496
- assertMergeMethod(options.method);
497
- const rctx = reRootContext(ctx, options.directory);
498
- if (options.check !== false) {
499
- const failed = runValidateSweep(rctx);
500
- if (failed) {
501
- throw new CliError('finalize aborted: validation sweep failed (use --no-check to skip)');
502
- }
503
- }
504
- const resolved = resolveChangeIdOrExit(rctx, program, id);
505
- id = resolved.id;
506
- enforceCloseOutHarness(rctx, id, options.check === false);
507
- const config = loadCliConfig(rctx.root);
508
- const method = options.method ?? config?.sdd?.merge_method ?? 'squash';
509
- const result = finalizeChange(ctx.git, rctx.io, id, {
510
- into: options.into,
511
- method: method as 'squash' | 'ff',
512
- today: new Date().toISOString().slice(0, 10),
513
- noCommit: options.commit === false,
514
- // r119: judge specs-landing under the change's own instance root.
515
- specsPrefix: specsPrefixFor(rctx),
516
- });
517
- for (const w of result.warnings) console.error(`[WARNING] ${w}`);
518
- if (options.commit === false) {
519
- console.log(
520
- `finalized \`${id}\` → ${result.archiveDir} on ${result.target} (close-out commit skipped — run: git add -A && git commit -m "archive(sdd): ${id}")`,
521
- );
522
- if (result.executedIn !== null) {
523
- console.log(`executed in target worktree ${result.executedIn}`);
524
- }
525
- return;
526
- }
527
- console.log(
528
- `finalized \`${id}\` → ${result.archiveDir} (commit "${result.commitSubject}" on ${result.target})`,
529
- );
530
- if (result.executedIn !== null) {
531
- console.log(`executed in target worktree ${result.executedIn}`);
532
- }
533
- },
534
- );
535
457
  }
@@ -1,15 +1,12 @@
1
1
  import { readFileSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
3
 
4
- import { renderConfigOverview, skillsJson } from '@llman-sdd/core';
4
+ import { renderConfigOverview } from '@llman-sdd/core';
5
5
  import type { Command } from 'commander';
6
6
 
7
7
  import {
8
- addReportOutputOptions,
9
8
  addSpecDirOption,
10
- emitReport,
11
9
  resolveCommandRoot,
12
- skillDesc,
13
10
  warnLegacyBddOnce,
14
11
  type CliContext,
15
12
  } from '../cli-shared.ts';
@@ -25,29 +22,4 @@ export function registerConfig(program: Command, ctx: CliContext): void {
25
22
  warnLegacyBddOnce(source);
26
23
  console.log(renderConfigOverview(source).join('\n'));
27
24
  });
28
-
29
- const skills = configCmd.command('skills').description('Manage extra_skills (non-interactive)');
30
- addReportOutputOptions(skills);
31
- addSpecDirOption(skills);
32
- skills.action(
33
- (options: { json?: boolean; output?: string; compactJson?: boolean; directory?: string }) => {
34
- const root = resolveCommandRoot(ctx, options.directory);
35
- const path = join(root, 'llmanspec', 'config.yaml');
36
- const source = readFileSync(path, 'utf8');
37
- warnLegacyBddOnce(source);
38
- const info = skillsJson(source);
39
- emitReport(info, options, () => {
40
- const { enabled, available } = info;
41
- const lines: string[] = ['Enabled optional skills:'];
42
- if (enabled.length === 0) lines.push(' (none)');
43
- else for (const s of enabled) lines.push(` [x] ${s}`);
44
- lines.push('');
45
- lines.push('Available but not enabled:');
46
- for (const s of available) {
47
- if (!enabled.includes(s)) lines.push(` [ ] ${s} — ${skillDesc(s)}`);
48
- }
49
- return lines.join('\n');
50
- });
51
- },
52
- );
53
25
  }
@@ -1,4 +1,4 @@
1
- import { mkdirSync } from 'node:fs';
1
+ import { mkdirSync, readdirSync, readFileSync } from 'node:fs';
2
2
  import { join, resolve } from 'node:path';
3
3
 
4
4
  import {
@@ -7,6 +7,7 @@ import {
7
7
  refreshSubRootBlocks,
8
8
  resolveInstanceRoot,
9
9
  runInit,
10
+ checkSkillVersions,
10
11
  } from '@llman-sdd/core';
11
12
  import type { Command } from 'commander';
12
13
 
@@ -39,18 +40,47 @@ export function registerInit(program: Command, _ctx: CliContext): void {
39
40
  'locale for generated templates (explicit config.yaml locale wins; fills a missing key; built-in default zh-Hans)',
40
41
  )
41
42
  .option('--lang <locale>', 'alias of --locale')
43
+ .option('--check', 'check installed llman-sdd skill versions against this CLI (no writes)')
42
44
  .action(
43
45
  (
44
46
  path: string | undefined,
45
- options: { update?: boolean; skills?: boolean; locale?: string; lang?: string },
47
+ options: {
48
+ update?: boolean;
49
+ skills?: boolean;
50
+ locale?: string;
51
+ lang?: string;
52
+ check?: boolean;
53
+ },
46
54
  ) => {
47
55
  if (options.locale !== undefined && options.lang !== undefined) {
48
56
  throw new CliError('--locale and --lang are mutually exclusive (they are aliases)');
49
57
  }
58
+ if (options.check === true && options.update === true) {
59
+ throw new CliError('--check and --update are mutually exclusive');
60
+ }
50
61
  let root = process.cwd();
51
62
  if (path !== undefined) {
52
63
  root = resolve(path);
53
- mkdirSync(root, { recursive: true });
64
+ if (options.check !== true) mkdirSync(root, { recursive: true });
65
+ }
66
+ if (options.check === true) {
67
+ const skillsDir = join(root, '.agents', 'skills');
68
+ const skills: { name: string; markdown: string }[] = [];
69
+ try {
70
+ for (const name of readdirSync(skillsDir)) {
71
+ if (!name.startsWith('llman-sdd-')) continue;
72
+ skills.push({
73
+ name,
74
+ markdown: readFileSync(join(skillsDir, name, 'SKILL.md'), 'utf8'),
75
+ });
76
+ }
77
+ } catch {
78
+ // missing directory is an empty install
79
+ }
80
+ const result = checkSkillVersions(skills, version);
81
+ if (!result.ok) throw new CliError(result.message, 1);
82
+ console.log(result.message);
83
+ return;
54
84
  }
55
85
  const io = makeIo(root);
56
86
  const warn = (message: string): void => {
@@ -1,19 +1,16 @@
1
- import { existsSync, readFileSync, readdirSync, statSync, writeFileSync } from 'node:fs';
2
- import { join } from 'node:path';
3
-
4
1
  import {
2
+ ARCHIVE_DIR_REL,
5
3
  DEFAULT_LOCALE,
6
4
  buildReqRegistry,
7
5
  compareVersions,
8
6
  isValidVersion,
9
- migrateNoteFor,
10
7
  migrateOverviewFor,
11
8
  migrationOverviewLines,
12
9
  migrationPrompt,
13
10
  knownMigrationVersions,
14
- parseVersionExpr,
15
11
  planDedupe,
16
- stripLegacyHeaderLines,
12
+ planUnfenceLegacyCards,
13
+ unfenceLegacyCards,
17
14
  } from '@llman-sdd/core';
18
15
  import type { Command } from 'commander';
19
16
 
@@ -22,64 +19,26 @@ import {
22
19
  addSpecDirOption,
23
20
  loadCliConfig,
24
21
  loadRootSpecEntries,
22
+ reRootContext,
25
23
  type CliContext,
26
24
  resolveRootSpecsDir,
27
25
  } from '../cli-shared.ts';
28
26
 
29
27
  interface MigrateOptions {
30
- kind?: string;
31
28
  fromVersion?: string;
32
29
  toVersion?: string;
33
- versionExpr?: string;
34
30
  dryRun?: boolean;
35
31
  directory?: string;
36
32
  }
37
33
 
38
- /** Resolve the playbook range from --from-version/--to-version or the
39
- * deprecated --version-expr (r100): conflict → ERROR, missing half → ERROR,
40
- * malformed version → ERROR, from >= to → ERROR. Returns null when no
41
- * selector was given at all (caller prints usage). */
42
- function resolvePromptRange(options: MigrateOptions): {
43
- from: string;
44
- to: string;
45
- viaExpr: boolean;
46
- } | null {
34
+ /** Resolve the playbook range from --from-version/--to-version. */
35
+ function resolvePromptRange(options: MigrateOptions): { from: string; to: string } | null {
47
36
  const hasNew = options.fromVersion !== undefined || options.toVersion !== undefined;
48
- if (options.versionExpr !== undefined && hasNew) {
49
- throw new CliError(
50
- '--version-expr is deprecated and conflicts with --from-version/--to-version; pass only the new flags',
51
- 2,
52
- );
53
- }
54
- if (options.versionExpr !== undefined) {
55
- const parsed = parseVersionExpr(options.versionExpr);
56
- if (parsed === null) {
57
- throw new CliError(
58
- `invalid --version-expr: ${options.versionExpr} (expected '<from>-><to>', e.g. '0.7.5->0.8.0')`,
59
- 2,
60
- );
61
- }
62
- return { ...parsed, viaExpr: true };
63
- }
64
37
  if (!hasNew) return null;
65
38
  if (options.fromVersion === undefined || options.toVersion === undefined) {
66
39
  throw new CliError('--from-version and --to-version must be given together (x.y.z)', 2);
67
40
  }
68
- return { from: options.fromVersion, to: options.toVersion, viaExpr: false };
69
- }
70
-
71
- function collectFeatureFiles(paths: string[]): string[] {
72
- const out: string[] = [];
73
- const walk = (p: string): void => {
74
- const st = statSync(p);
75
- if (st.isDirectory()) {
76
- for (const e of readdirSync(p)) walk(join(p, e));
77
- } else if (p.endsWith('.feature')) out.push(p);
78
- };
79
- for (const p of paths) {
80
- if (existsSync(p)) walk(p);
81
- }
82
- return out;
41
+ return { from: options.fromVersion, to: options.toVersion };
83
42
  }
84
43
 
85
44
  export function registerProject(program: Command, ctx: CliContext): void {
@@ -123,27 +82,15 @@ export function registerProject(program: Command, ctx: CliContext): void {
123
82
 
124
83
  const migrate = project
125
84
  .command('migrate')
126
- .description(
127
- 'Migration hub: legacy collaboration notes, versioned agent playbooks, spec-header strip',
128
- )
129
- .argument('[action]', 'prompt | strip-legacy-headers')
130
- .option('--kind <kind>', 'legacy collaboration notes: toon2features | specs-flatten')
85
+ .description('Migration hub: versioned agent playbooks and frozen-card unfence')
86
+ .argument('[action]', 'prompt | frozen-cards-unfence')
131
87
  .option('--from-version <version>', 'migration playbook range start, exclusive (x.y.z)')
132
88
  .option('--to-version <version>', 'migration playbook range end, inclusive (x.y.z)')
133
- .option(
134
- '--version-expr <expr>',
135
- "deprecated — use --from-version/--to-version instead (e.g. '0.7.5->0.8.0')",
136
- )
137
- .option('--dry-run', 'strip-legacy-headers: report affected files without writing')
89
+ .option('--dry-run', 'frozen-cards-unfence: report without writing')
138
90
  .action((action: string | undefined, options: MigrateOptions) => {
139
- // T36: version-range flags without an action are a usage error (rc 2),
140
- // not a silent no-op — the error names the action that consumes them.
141
- // `--kind` alone stays the legacy no-action form (overview / kind note).
142
91
  if (
143
92
  action === undefined &&
144
- (options.versionExpr !== undefined ||
145
- options.fromVersion !== undefined ||
146
- options.toVersion !== undefined)
93
+ (options.fromVersion !== undefined || options.toVersion !== undefined)
147
94
  ) {
148
95
  throw new CliError(
149
96
  'project migrate range flags require the prompt action (llman-sdd project migrate prompt)',
@@ -177,63 +124,32 @@ export function registerProject(program: Command, ctx: CliContext): void {
177
124
  2,
178
125
  );
179
126
  }
180
- if (range.viaExpr) {
181
- console.error(
182
- '[WARNING] --version-expr is deprecated; use --from-version/--to-version instead.',
183
- );
184
- }
185
127
  console.log(migrationPrompt(range.from, range.to));
186
128
  return;
187
129
  }
188
- if (action === 'strip-legacy-headers') {
189
- if (
190
- options.kind !== undefined ||
191
- options.versionExpr !== undefined ||
192
- options.fromVersion !== undefined ||
193
- options.toVersion !== undefined
194
- ) {
195
- throw new CliError(
196
- 'strip-legacy-headers takes no --kind/--version-expr/--from-version/--to-version',
197
- );
130
+ if (action === 'frozen-cards-unfence') {
131
+ if (options.fromVersion !== undefined || options.toVersion !== undefined) {
132
+ throw new CliError('frozen-cards-unfence takes no --from-version/--to-version');
198
133
  }
199
- const targets = collectFeatureFiles([resolveRootSpecsDir(options.directory, ctx.io)]);
200
- let touched = 0;
201
- let removed = 0;
202
- for (const file of targets) {
203
- const source = readFileSync(file, 'utf8');
204
- const result = stripLegacyHeaderLines(source);
205
- if (result.removed === 0) continue;
206
- touched++;
207
- removed += result.removed;
208
- console.log(
209
- `[strip] ${file}: ${result.removed} line(s)${options.dryRun === true ? ' (dry-run)' : ''}`,
210
- );
211
- if (options.dryRun !== true) writeFileSync(file, result.content, 'utf8');
134
+ const rctx = reRootContext(ctx, options.directory);
135
+ if (options.dryRun === true) {
136
+ const hits = planUnfenceLegacyCards(rctx.io, ARCHIVE_DIR_REL);
137
+ for (const rel of hits) console.log(`[unfence] ${rel} (dry-run)`);
138
+ console.log(`frozen-cards-unfence: ${hits.length} card(s) would change (dry-run)`);
139
+ return;
212
140
  }
213
- const mode = options.dryRun === true ? ' (dry-run)' : '';
214
- console.log(`strip-legacy-headers: ${touched} file(s), ${removed} line(s) removed${mode}`);
215
- console.log('next: re-run `llman-sdd init --update` to refresh skills and templates');
141
+ const changed = unfenceLegacyCards(rctx.io, ARCHIVE_DIR_REL);
142
+ console.log(`frozen-cards-unfence: ${changed} card(s) normalized to single-document YAML`);
216
143
  return;
217
144
  }
218
145
  if (action !== undefined) {
219
146
  throw new CliError(
220
- `unknown migrate action: ${action} (expected: prompt | strip-legacy-headers)`,
221
- 2,
222
- );
223
- }
224
- if (options.kind === undefined) {
225
- console.log(migrateOverviewFor(locale));
226
- console.log(migrationOverviewLines().join('\n'));
227
- return;
228
- }
229
- const note = migrateNoteFor(options.kind, locale);
230
- if (note === null) {
231
- throw new CliError(
232
- `unknown migration kind: ${options.kind} (expected: toon2features | specs-flatten)`,
147
+ `unknown migrate action: ${action} (expected: prompt | frozen-cards-unfence)`,
233
148
  2,
234
149
  );
235
150
  }
236
- console.log(note);
151
+ console.log(migrateOverviewFor(locale));
152
+ console.log(migrationOverviewLines().join('\n'));
237
153
  });
238
154
  addSpecDirOption(migrate);
239
155
  }
@@ -1,14 +1,11 @@
1
- import { existsSync, readdirSync, statSync, writeFileSync } from 'node:fs';
1
+ import { existsSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
- import { createInterface } from 'node:readline';
4
3
 
5
4
  import {
6
5
  DEFAULT_LOCALE,
7
6
  addReq,
8
7
  addScenario,
9
8
  buildUnboundFeed,
10
- hasNativeRules,
11
- migrateNativeSource,
12
9
  nextReqId,
13
10
  resolveReq,
14
11
  scaffoldSpec,
@@ -29,39 +26,11 @@ import {
29
26
  type CliContext,
30
27
  } from '../cli-shared.ts';
31
28
 
32
- /** Walk paths collecting .feature files (directories recurse). */
33
- function collectFeatureFiles(paths: string[]): string[] {
34
- const files: string[] = [];
35
- const walk = (dir: string): void => {
36
- for (const name of readdirSync(dir).toSorted()) {
37
- const full = join(dir, name);
38
- if (statSync(full).isDirectory()) walk(full);
39
- else if (name.endsWith('.feature')) files.push(full);
40
- }
41
- };
42
- for (const p of paths) {
43
- if (!existsSync(p)) throw new CliError(`path not found: ${p}`);
44
- if (statSync(p).isDirectory()) walk(p);
45
- else files.push(p);
46
- }
47
- return files;
48
- }
49
-
50
- function confirmInteractive(question: string): Promise<boolean> {
51
- const rl = createInterface({ input: process.stdin, output: process.stdout });
52
- return new Promise((resolve) => {
53
- rl.question(question, (answer) => {
54
- rl.close();
55
- resolve(answer.trim().toLowerCase() === 'y');
56
- });
57
- });
58
- }
59
-
60
29
  export function registerSpec(program: Command, ctx: CliContext): void {
61
30
  const spec = program.command('spec').description('Spec authoring helpers');
62
31
 
63
32
  const skeleton = spec
64
- .command('skeleton')
33
+ .command('new')
65
34
  .description('Generate a single-track spec skeleton for a capability')
66
35
  .argument('<capability>')
67
36
  .option('--force', 'overwrite an existing spec file');
@@ -162,53 +131,6 @@ export function registerSpec(program: Command, ctx: CliContext): void {
162
131
  },
163
132
  );
164
133
 
165
- const migrateNative = spec
166
- .command('migrate-native')
167
- .description('Migrate legacy tag-based .feature files to the native 规则:/场景: layout')
168
- .argument('[paths...]', 'feature files or directories (default: llmanspec/specs)')
169
- .option('--dry-run', 'print the migration plan without writing')
170
- .option('-y, --yes', 'proceed without per-file confirmation');
171
- addSpecDirOption(migrateNative);
172
- migrateNative.action(
173
- async (paths: string[], options: { dryRun?: boolean; yes?: boolean; directory?: string }) => {
174
- // r116: 显式传入的路径按参数原义处理(豁免);缺省目标才经根发现算子
175
- const targets = collectFeatureFiles(
176
- paths.length > 0 ? paths : [resolveRootSpecsDir(options.directory, ctx.io)],
177
- );
178
- const io = ctx.io;
179
- let migrated = 0;
180
- let skipped = 0;
181
- for (const file of targets) {
182
- const source = io.readText(file);
183
- // already native? layout detection via the official parser
184
- if (hasNativeRules(source)) {
185
- skipped++;
186
- if (options.dryRun) console.log(`[skip] ${file} (already native)`);
187
- continue;
188
- }
189
- const result = migrateNativeSource(source);
190
- if (!result.ok) {
191
- console.error(`[error] ${file}: ${result.message}`);
192
- continue;
193
- }
194
- const line = `[migrate] ${file}: ${result.rules} rule(s), ${result.scenarios} scenario(s)`;
195
- if (options.dryRun) {
196
- console.log(`${line} (dry-run)`);
197
- migrated++;
198
- continue;
199
- }
200
- if (options.yes || (await confirmInteractive(`${line}. Write? (y/N) `))) {
201
- writeFileSync(file, result.content, 'utf8');
202
- console.log(line);
203
- migrated++;
204
- } else {
205
- console.log(`[skip] ${file} (declined)`);
206
- }
207
- }
208
- console.log(`migrate-native: ${migrated} file(s) migrated, ${skipped} already native`);
209
- },
210
- );
211
-
212
134
  const resolveReqCmd = spec
213
135
  .command('resolve-req')
214
136
  .description('Resolve an rN to its capability and statement')
package/src/program.ts CHANGED
@@ -15,9 +15,7 @@ import { CliError, versionDisplay, type CliContext } from './cli-shared.ts';
15
15
  import { registerArchive } from './commands/archive.ts';
16
16
  import { registerChange } from './commands/change.ts';
17
17
  import { registerConfig } from './commands/config.ts';
18
- import { registerContext } from './commands/context.ts';
19
18
  import { registerGraph } from './commands/graph.ts';
20
- import { registerIndex } from './commands/index.ts';
21
19
  import { registerInit } from './commands/init.ts';
22
20
  import { registerList } from './commands/list.ts';
23
21
  import { registerProject } from './commands/project.ts';
@@ -61,14 +59,12 @@ export function createProgram(ctx: CliContext): Command {
61
59
  registerArchive(program, ctx);
62
60
  registerReview(program, ctx);
63
61
  registerConfig(program, ctx);
64
- registerIndex(program, ctx);
65
- registerContext(program, ctx);
66
62
  registerSelf(program, ctx);
67
63
 
68
64
  // cli r75: pure parent groups (no default action of their own) reject bare
69
65
  // calls as usage errors — commander's missing-action help on stderr, rc 2
70
66
  // via missingParameter/…; `config` keeps its default action (overview, rc 0).
71
- for (const name of ['change', 'spec', 'project', 'archive', 'index', 'self']) {
67
+ for (const name of ['change', 'spec', 'project', 'self']) {
72
68
  const group = program.commands.find((c) => c.name() === name);
73
69
  if (group === undefined) continue;
74
70
  group.action(() => {
@@ -1,88 +0,0 @@
1
- import { readFileSync } from 'node:fs';
2
- import { join } from 'node:path';
3
-
4
- import {
5
- discoverSpecs,
6
- loadTreeWithAutoRebuild,
7
- resolveChatConfig,
8
- runContextRetrieval,
9
- unavailableResult,
10
- } from '@llman-sdd/core';
11
- import type { Command } from 'commander';
12
-
13
- import {
14
- CliError,
15
- addSpecDirOption,
16
- reRootContext,
17
- resolveBackend,
18
- type CliContext,
19
- } from '../cli-shared.ts';
20
- import { progressNote } from '../progress.ts';
21
-
22
- // (err path below converted to CliError; resolveBackend may also throw CliError)
23
-
24
- export function registerContext(program: Command, ctx: CliContext): void {
25
- const context = program
26
- .command('context')
27
- .description('Get specs relevant to a task (agent-oriented, pageindex agentic retrieval)')
28
- .option('--task <task>', 'natural language task description')
29
- .option('--paths <paths>', 'comma-separated file paths')
30
- .option('--top <n>', 'max entries per tier', '5')
31
- .option('--backend <name>', 'retrieval backend (pageindex only)')
32
- .action(
33
- async (options: {
34
- task?: string;
35
- paths?: string;
36
- top?: string;
37
- backend?: string;
38
- directory?: string;
39
- }) => {
40
- resolveBackend(options.backend);
41
- if (!options.task && !options.paths) {
42
- throw new CliError('at least one of --task or --paths is required');
43
- }
44
- const config = resolveChatConfig(process.env as Record<string, string | undefined>);
45
- // r62: lazy refresh runs BEFORE the chat-model gate (predecessor r97 — the index
46
- // self-heals even when retrieval subsequently fails with api_error).
47
- // r115/r116: the resolved instance root decides every read AND write target,
48
- // so the index store lands in the --directory instance, not the launch dir.
49
- const rctx = reRootContext(ctx, options.directory);
50
- const specsDir = join(rctx.root, 'llmanspec', 'specs');
51
- const refresh = loadTreeWithAutoRebuild(
52
- rctx.io,
53
- specsDir,
54
- discoverSpecs(specsDir, rctx.io),
55
- {
56
- chatModel: process.env.LLMAN_SDD_INDEX_CHAT_MODEL ?? '',
57
- },
58
- );
59
- if (refresh.tree === null || refresh.error !== null) {
60
- const failed = unavailableResult();
61
- failed.status.errorKind = 'index_rebuild_failed';
62
- failed.status.qualityNote =
63
- refresh.error ?? 'index rebuild failed — run `llman-sdd index rebuild`';
64
- console.log(JSON.stringify(failed, null, 2));
65
- return;
66
- }
67
- const tree = refresh.tree;
68
- if (config === null) {
69
- // predecessor parity: unavailable/error JSON on stdout, exit 0.
70
- console.log(JSON.stringify(unavailableResult(), null, 2));
71
- return;
72
- }
73
- // LLM 链路可能是秒级 — 进度提示防止看上去卡住(B1)
74
- progressNote('context.retrieve', rctx.root);
75
- const result = await runContextRetrieval({
76
- config,
77
- task: options.task ?? '',
78
- paths: options.paths,
79
- top: Number(options.top),
80
- tree,
81
- readFile: (p) => readFileSync(p, 'utf8'),
82
- root: rctx.root,
83
- });
84
- console.log(JSON.stringify(result, null, 2));
85
- },
86
- );
87
- addSpecDirOption(context);
88
- }
@@ -1,53 +0,0 @@
1
- import { join } from 'node:path';
2
-
3
- import { checkIndexFreshness, discoverSpecs, rebuildIndex } from '@llman-sdd/core';
4
- import type { Command } from 'commander';
5
-
6
- import {
7
- addReportOutputOptions,
8
- addSpecDirOption,
9
- emitReport,
10
- exitWith,
11
- reRootContext,
12
- resolveBackend,
13
- type CliContext,
14
- } from '../cli-shared.ts';
15
-
16
- export function registerIndex(program: Command, ctx: CliContext): void {
17
- const indexCmd = program
18
- .command('index')
19
- .description('Index management commands (rebuild, check freshness)');
20
-
21
- const rebuild = indexCmd
22
- .command('rebuild')
23
- .description('Rebuild the pageindex tree from spec IR (no LLM)')
24
- .option('--backend <name>', 'index backend (pageindex only)')
25
- .action((options: { backend?: string; directory?: string }) => {
26
- resolveBackend(options.backend);
27
- // r115/r116: resolve the instance root once and anchor io at it — the
28
- // pageindex store is written through root-relative paths, which must land
29
- // in the --directory instance rather than the launch directory.
30
- const rctx = reRootContext(ctx, options.directory);
31
- const specsDir = join(rctx.root, 'llmanspec', 'specs');
32
- const result = rebuildIndex(rctx.io, specsDir, discoverSpecs(specsDir, rctx.io), {
33
- chatModel: process.env.LLMAN_SDD_INDEX_CHAT_MODEL ?? '',
34
- });
35
- for (const line of result.lines.slice(0, -1)) console.error(line);
36
- if (result.lines.length > 0) console.log(result.lines.at(-1));
37
- });
38
- addSpecDirOption(rebuild);
39
-
40
- const check = indexCmd.command('check').description('Check index freshness without rebuilding');
41
- addReportOutputOptions(check);
42
- addSpecDirOption(check);
43
- check.action(
44
- (options: { output?: string; json?: boolean; compactJson?: boolean; directory?: string }) => {
45
- const rctx = reRootContext(ctx, options.directory);
46
- const result = checkIndexFreshness(rctx.io, join(rctx.root, 'llmanspec', 'specs'));
47
- emitReport({ fresh: result.fresh, notes: result.lines }, options, () =>
48
- result.lines.join('\n'),
49
- );
50
- if (!result.fresh) exitWith(1);
51
- },
52
- );
53
- }