@llman-sdd/cli 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/cli-shared.ts +196 -42
- package/src/commands/archive.ts +61 -58
- package/src/commands/change.ts +321 -210
- package/src/commands/config.ts +35 -29
- package/src/commands/context.ts +67 -41
- package/src/commands/graph.ts +33 -21
- package/src/commands/index.ts +28 -18
- package/src/commands/init.ts +3 -3
- package/src/commands/list.ts +24 -18
- package/src/commands/project.ts +55 -14
- package/src/commands/review.ts +27 -24
- package/src/commands/self.ts +156 -0
- package/src/commands/show.ts +73 -37
- package/src/commands/spec.ts +152 -141
- package/src/commands/validate.ts +153 -82
- package/src/io.ts +7 -0
- package/src/main.ts +55 -50
- package/src/program.ts +83 -0
- package/src/progress.ts +14 -6
package/src/commands/config.ts
CHANGED
|
@@ -1,47 +1,53 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
2
3
|
|
|
3
|
-
import { renderConfigOverview,
|
|
4
|
+
import { renderConfigOverview, skillsJson } from '@llman-sdd/core';
|
|
4
5
|
import type { Command } from 'commander';
|
|
5
6
|
|
|
6
7
|
import {
|
|
7
8
|
addReportOutputOptions,
|
|
8
|
-
|
|
9
|
+
addSpecDirOption,
|
|
10
|
+
emitReport,
|
|
11
|
+
resolveCommandRoot,
|
|
9
12
|
skillDesc,
|
|
10
13
|
warnLegacyBddOnce,
|
|
14
|
+
type CliContext,
|
|
11
15
|
} from '../cli-shared.ts';
|
|
12
16
|
|
|
13
|
-
export function registerConfig(program: Command): void {
|
|
14
|
-
const configCmd = program
|
|
15
|
-
.command('config')
|
|
16
|
-
.description('Project configuration commands (view/edit config.yaml)');
|
|
17
|
+
export function registerConfig(program: Command, ctx: CliContext): void {
|
|
18
|
+
const configCmd = program.command('config');
|
|
17
19
|
|
|
18
|
-
configCmd.description('Print a read-only llmanspec/config.yaml overview')
|
|
19
|
-
|
|
20
|
+
configCmd.description('Print a read-only llmanspec/config.yaml overview');
|
|
21
|
+
addSpecDirOption(configCmd);
|
|
22
|
+
configCmd.action((options: { directory?: string }) => {
|
|
23
|
+
const root = resolveCommandRoot(ctx, options.directory);
|
|
24
|
+
const source = readFileSync(join(root, 'llmanspec', 'config.yaml'), 'utf8');
|
|
20
25
|
warnLegacyBddOnce(source);
|
|
21
26
|
console.log(renderConfigOverview(source).join('\n'));
|
|
22
27
|
});
|
|
23
28
|
|
|
24
29
|
const skills = configCmd.command('skills').description('Manage extra_skills (non-interactive)');
|
|
25
30
|
addReportOutputOptions(skills);
|
|
26
|
-
skills
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
+
);
|
|
47
53
|
}
|
package/src/commands/context.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
2
3
|
|
|
3
4
|
import {
|
|
5
|
+
discoverSpecs,
|
|
4
6
|
loadTreeWithAutoRebuild,
|
|
5
7
|
resolveChatConfig,
|
|
6
8
|
runContextRetrieval,
|
|
@@ -8,55 +10,79 @@ import {
|
|
|
8
10
|
} from '@llman-sdd/core';
|
|
9
11
|
import type { Command } from 'commander';
|
|
10
12
|
|
|
11
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
CliError,
|
|
15
|
+
addSpecDirOption,
|
|
16
|
+
reRootContext,
|
|
17
|
+
resolveBackend,
|
|
18
|
+
type CliContext,
|
|
19
|
+
} from '../cli-shared.ts';
|
|
12
20
|
import { progressNote } from '../progress.ts';
|
|
13
21
|
|
|
14
22
|
// (err path below converted to CliError; resolveBackend may also throw CliError)
|
|
15
23
|
|
|
16
|
-
export function registerContext(program: Command): void {
|
|
17
|
-
program
|
|
24
|
+
export function registerContext(program: Command, ctx: CliContext): void {
|
|
25
|
+
const context = program
|
|
18
26
|
.command('context')
|
|
19
27
|
.description('Get specs relevant to a task (agent-oriented, pageindex agentic retrieval)')
|
|
20
28
|
.option('--task <task>', 'natural language task description')
|
|
21
29
|
.option('--paths <paths>', 'comma-separated file paths')
|
|
22
30
|
.option('--top <n>', 'max entries per tier', '5')
|
|
23
31
|
.option('--backend <name>', 'retrieval backend (pageindex only)')
|
|
24
|
-
.action(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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);
|
|
62
88
|
}
|
package/src/commands/graph.ts
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import { graphMermaid } from '@llman-sdd/core';
|
|
2
2
|
import type { Command } from 'commander';
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
cliMaxScanDepth,
|
|
6
|
+
CliError,
|
|
7
|
+
type CliContext,
|
|
8
|
+
addSpecDirOption,
|
|
9
|
+
resolveCommandRoot,
|
|
10
|
+
} from '../cli-shared.ts';
|
|
5
11
|
|
|
6
|
-
export function registerGraph(program: Command): void {
|
|
7
|
-
program
|
|
12
|
+
export function registerGraph(program: Command, ctx: CliContext): void {
|
|
13
|
+
const graph = program
|
|
8
14
|
.command('graph')
|
|
9
15
|
.description('Generate a change dependency graph (mermaid)')
|
|
10
16
|
.argument('[change]', 'seed change id (BFS over depends_on)')
|
|
@@ -13,23 +19,29 @@ export function registerGraph(program: Command): void {
|
|
|
13
19
|
.option(
|
|
14
20
|
'--depth <n>',
|
|
15
21
|
'expansion depth: 0 = scope only, 1 = direct deps (default), N = recursive',
|
|
16
|
-
)
|
|
17
|
-
.action(
|
|
18
|
-
(change: string | undefined, options: { format: string; scope?: string; depth?: string }) => {
|
|
19
|
-
if (options.format !== 'mermaid') {
|
|
20
|
-
throw new CliError(`unsupported --format: ${options.format} (mermaid only)`, 2);
|
|
21
|
-
}
|
|
22
|
-
const depth = options.depth !== undefined ? Number(options.depth) : undefined;
|
|
23
|
-
if (depth !== undefined && (!Number.isInteger(depth) || depth < 0)) {
|
|
24
|
-
throw new CliError(`invalid --depth: ${options.depth}`);
|
|
25
|
-
}
|
|
26
|
-
const graphOpts = {
|
|
27
|
-
scope: options.scope,
|
|
28
|
-
depth: depth ?? 1,
|
|
29
|
-
seed: change,
|
|
30
|
-
maxScanDepth: cliMaxScanDepth(program),
|
|
31
|
-
};
|
|
32
|
-
console.log(graphMermaid(newIo(), process.cwd(), graphOpts).join('\n'));
|
|
33
|
-
},
|
|
34
22
|
);
|
|
23
|
+
addSpecDirOption(graph);
|
|
24
|
+
graph.action(
|
|
25
|
+
(
|
|
26
|
+
change: string | undefined,
|
|
27
|
+
options: { format: string; scope?: string; depth?: string; directory?: string },
|
|
28
|
+
) => {
|
|
29
|
+
if (options.format !== 'mermaid') {
|
|
30
|
+
throw new CliError(`unsupported --format: ${options.format} (mermaid only)`, 2);
|
|
31
|
+
}
|
|
32
|
+
const depth = options.depth !== undefined ? Number(options.depth) : undefined;
|
|
33
|
+
if (depth !== undefined && (!Number.isInteger(depth) || depth < 0)) {
|
|
34
|
+
throw new CliError(`invalid --depth: ${options.depth}`, 2);
|
|
35
|
+
}
|
|
36
|
+
const graphOpts = {
|
|
37
|
+
scope: options.scope,
|
|
38
|
+
depth: depth ?? 1,
|
|
39
|
+
seed: change,
|
|
40
|
+
maxScanDepth: cliMaxScanDepth(program),
|
|
41
|
+
};
|
|
42
|
+
console.log(
|
|
43
|
+
graphMermaid(ctx.io, resolveCommandRoot(ctx, options.directory), graphOpts).join('\n'),
|
|
44
|
+
);
|
|
45
|
+
},
|
|
46
|
+
);
|
|
35
47
|
}
|
package/src/commands/index.ts
CHANGED
|
@@ -1,43 +1,53 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
|
|
3
|
+
import { checkIndexFreshness, discoverSpecs, rebuildIndex } from '@llman-sdd/core';
|
|
2
4
|
import type { Command } from 'commander';
|
|
3
5
|
|
|
4
6
|
import {
|
|
5
7
|
addReportOutputOptions,
|
|
8
|
+
addSpecDirOption,
|
|
9
|
+
emitReport,
|
|
6
10
|
exitWith,
|
|
7
|
-
|
|
8
|
-
newIo,
|
|
11
|
+
reRootContext,
|
|
9
12
|
resolveBackend,
|
|
10
|
-
|
|
13
|
+
type CliContext,
|
|
11
14
|
} from '../cli-shared.ts';
|
|
12
15
|
|
|
13
|
-
export function registerIndex(program: Command): void {
|
|
16
|
+
export function registerIndex(program: Command, ctx: CliContext): void {
|
|
14
17
|
const indexCmd = program
|
|
15
18
|
.command('index')
|
|
16
19
|
.description('Index management commands (rebuild, check freshness)');
|
|
17
20
|
|
|
18
|
-
indexCmd
|
|
21
|
+
const rebuild = indexCmd
|
|
19
22
|
.command('rebuild')
|
|
20
23
|
.description('Rebuild the pageindex tree from spec IR (no LLM)')
|
|
21
24
|
.option('--backend <name>', 'index backend (pageindex only)')
|
|
22
|
-
.action((options: { backend?: string }) => {
|
|
25
|
+
.action((options: { backend?: string; directory?: string }) => {
|
|
23
26
|
resolveBackend(options.backend);
|
|
24
|
-
|
|
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), {
|
|
25
33
|
chatModel: process.env.LLMAN_SDD_INDEX_CHAT_MODEL ?? '',
|
|
26
34
|
});
|
|
27
35
|
for (const line of result.lines.slice(0, -1)) console.error(line);
|
|
28
36
|
if (result.lines.length > 0) console.log(result.lines.at(-1));
|
|
29
37
|
});
|
|
38
|
+
addSpecDirOption(rebuild);
|
|
30
39
|
|
|
31
40
|
const check = indexCmd.command('check').description('Check index freshness without rebuilding');
|
|
32
41
|
addReportOutputOptions(check);
|
|
33
|
-
check
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
+
);
|
|
43
53
|
}
|
package/src/commands/init.ts
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
} from '@llman-sdd/core';
|
|
11
11
|
import type { Command } from 'commander';
|
|
12
12
|
|
|
13
|
-
import { CliError, templateIo, version } from '../cli-shared.ts';
|
|
13
|
+
import { CliError, templateIo, version, type CliContext } from '../cli-shared.ts';
|
|
14
14
|
import { makeCliGit, makeIo } from '../io.ts';
|
|
15
15
|
import { progressNote } from '../progress.ts';
|
|
16
16
|
|
|
@@ -24,7 +24,7 @@ function isRepoRootInstance(root: string): boolean {
|
|
|
24
24
|
return toplevel === null || resolve(toplevel) === root;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
export function registerInit(program: Command): void {
|
|
27
|
+
export function registerInit(program: Command, _ctx: CliContext): void {
|
|
28
28
|
program
|
|
29
29
|
.command('init')
|
|
30
30
|
.description('Initialize llmanspec in your project (--update to refresh existing)')
|
|
@@ -36,7 +36,7 @@ export function registerInit(program: Command): void {
|
|
|
36
36
|
)
|
|
37
37
|
.option(
|
|
38
38
|
'--locale <locale>',
|
|
39
|
-
'locale for generated templates (explicit config.yaml locale wins; fills a missing key; built-in default
|
|
39
|
+
'locale for generated templates (explicit config.yaml locale wins; fills a missing key; built-in default zh-Hans)',
|
|
40
40
|
)
|
|
41
41
|
.option('--lang <locale>', 'alias of --locale')
|
|
42
42
|
.action(
|
package/src/commands/list.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
|
|
1
3
|
import {
|
|
2
4
|
collectChanges,
|
|
3
5
|
collectSpecs,
|
|
@@ -5,26 +7,29 @@ import {
|
|
|
5
7
|
renderChangesList,
|
|
6
8
|
renderSpecsJson,
|
|
7
9
|
renderSpecsList,
|
|
10
|
+
discoverSpecs,
|
|
8
11
|
} from '@llman-sdd/core';
|
|
9
12
|
import type { Command } from 'commander';
|
|
10
13
|
|
|
11
14
|
import {
|
|
15
|
+
addSpecDirOption,
|
|
12
16
|
CliError,
|
|
13
17
|
assertCompactJsonPairing,
|
|
14
18
|
addReportOutputOptions,
|
|
15
19
|
cliMaxScanDepth,
|
|
16
|
-
|
|
17
|
-
newIo,
|
|
20
|
+
resolveCommandRoot,
|
|
18
21
|
resolveOutMode,
|
|
22
|
+
type CliContext,
|
|
19
23
|
} from '../cli-shared.ts';
|
|
20
24
|
|
|
21
|
-
export function registerList(program: Command): void {
|
|
25
|
+
export function registerList(program: Command, ctx: CliContext): void {
|
|
22
26
|
const list = program
|
|
23
27
|
.command('list')
|
|
24
28
|
.description('List changes or specs')
|
|
25
29
|
.option('--specs', 'list specs instead of changes')
|
|
26
30
|
.option('--sort <order>', 'recent (mtime desc, default) | name');
|
|
27
31
|
addReportOutputOptions(list);
|
|
32
|
+
addSpecDirOption(list);
|
|
28
33
|
list.action(
|
|
29
34
|
(options: {
|
|
30
35
|
specs?: boolean;
|
|
@@ -32,37 +37,38 @@ export function registerList(program: Command): void {
|
|
|
32
37
|
compactJson?: boolean;
|
|
33
38
|
output?: string;
|
|
34
39
|
sort?: string;
|
|
40
|
+
directory?: string;
|
|
35
41
|
}) => {
|
|
36
|
-
|
|
42
|
+
assertCompactJsonPairing(options);
|
|
37
43
|
if (options.sort !== undefined && options.sort !== 'recent' && options.sort !== 'name') {
|
|
38
|
-
throw new CliError(`invalid --sort: ${options.sort}
|
|
44
|
+
throw new CliError(`invalid --sort: ${options.sort}`, 2);
|
|
39
45
|
}
|
|
46
|
+
// T18/T30: shared pipeline; compact is the single-point minified
|
|
47
|
+
// JSON.stringify (r76) — no per-command newline stripping.
|
|
48
|
+
const mode = resolveOutMode(options.output, options.json, options.compactJson);
|
|
40
49
|
const emit = (text: string): void => {
|
|
41
|
-
console.log(
|
|
50
|
+
console.log(text);
|
|
42
51
|
};
|
|
43
52
|
if (options.specs) {
|
|
44
|
-
const
|
|
45
|
-
const
|
|
53
|
+
const root = resolveCommandRoot(ctx, options.directory);
|
|
54
|
+
const summaries = collectSpecs(discoverSpecs(join(root, 'llmanspec', 'specs'), ctx.io));
|
|
46
55
|
emit(
|
|
47
|
-
|
|
48
|
-
?
|
|
49
|
-
:
|
|
56
|
+
mode === 'human'
|
|
57
|
+
? renderSpecsList(summaries).join('\n')
|
|
58
|
+
: renderSpecsJson(summaries, mode),
|
|
50
59
|
);
|
|
51
60
|
return;
|
|
52
61
|
}
|
|
53
|
-
let changes = collectChanges(
|
|
62
|
+
let changes = collectChanges(ctx.io, resolveCommandRoot(ctx, options.directory), new Date(), {
|
|
54
63
|
maxScanDepth: cliMaxScanDepth(program),
|
|
55
64
|
});
|
|
56
65
|
if (options.sort === 'name') {
|
|
57
66
|
changes = [...changes].toSorted((a, b) => a.name.localeCompare(b.name));
|
|
58
67
|
}
|
|
59
68
|
emit(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
? renderChangesJson(changes, changesMode)
|
|
64
|
-
: renderChangesList(changes, new Date()).join('\n');
|
|
65
|
-
})(),
|
|
69
|
+
mode === 'human'
|
|
70
|
+
? renderChangesList(changes, new Date()).join('\n')
|
|
71
|
+
: renderChangesJson(changes, mode),
|
|
66
72
|
);
|
|
67
73
|
},
|
|
68
74
|
);
|
package/src/commands/project.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { existsSync, readFileSync, readdirSync, statSync, writeFileSync } from '
|
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
|
+
DEFAULT_LOCALE,
|
|
5
6
|
buildReqRegistry,
|
|
6
7
|
compareVersions,
|
|
7
8
|
isValidVersion,
|
|
@@ -16,7 +17,14 @@ import {
|
|
|
16
17
|
} from '@llman-sdd/core';
|
|
17
18
|
import type { Command } from 'commander';
|
|
18
19
|
|
|
19
|
-
import {
|
|
20
|
+
import {
|
|
21
|
+
CliError,
|
|
22
|
+
addSpecDirOption,
|
|
23
|
+
loadCliConfig,
|
|
24
|
+
loadRootSpecEntries,
|
|
25
|
+
type CliContext,
|
|
26
|
+
resolveRootSpecsDir,
|
|
27
|
+
} from '../cli-shared.ts';
|
|
20
28
|
|
|
21
29
|
interface MigrateOptions {
|
|
22
30
|
kind?: string;
|
|
@@ -24,6 +32,7 @@ interface MigrateOptions {
|
|
|
24
32
|
toVersion?: string;
|
|
25
33
|
versionExpr?: string;
|
|
26
34
|
dryRun?: boolean;
|
|
35
|
+
directory?: string;
|
|
27
36
|
}
|
|
28
37
|
|
|
29
38
|
/** Resolve the playbook range from --from-version/--to-version or the
|
|
@@ -39,6 +48,7 @@ function resolvePromptRange(options: MigrateOptions): {
|
|
|
39
48
|
if (options.versionExpr !== undefined && hasNew) {
|
|
40
49
|
throw new CliError(
|
|
41
50
|
'--version-expr is deprecated and conflicts with --from-version/--to-version; pass only the new flags',
|
|
51
|
+
2,
|
|
42
52
|
);
|
|
43
53
|
}
|
|
44
54
|
if (options.versionExpr !== undefined) {
|
|
@@ -46,13 +56,14 @@ function resolvePromptRange(options: MigrateOptions): {
|
|
|
46
56
|
if (parsed === null) {
|
|
47
57
|
throw new CliError(
|
|
48
58
|
`invalid --version-expr: ${options.versionExpr} (expected '<from>-><to>', e.g. '0.7.5->0.8.0')`,
|
|
59
|
+
2,
|
|
49
60
|
);
|
|
50
61
|
}
|
|
51
62
|
return { ...parsed, viaExpr: true };
|
|
52
63
|
}
|
|
53
64
|
if (!hasNew) return null;
|
|
54
65
|
if (options.fromVersion === undefined || options.toVersion === undefined) {
|
|
55
|
-
throw new CliError('--from-version and --to-version must be given together (x.y.z)');
|
|
66
|
+
throw new CliError('--from-version and --to-version must be given together (x.y.z)', 2);
|
|
56
67
|
}
|
|
57
68
|
return { from: options.fromVersion, to: options.toVersion, viaExpr: false };
|
|
58
69
|
}
|
|
@@ -71,27 +82,35 @@ function collectFeatureFiles(paths: string[]): string[] {
|
|
|
71
82
|
return out;
|
|
72
83
|
}
|
|
73
84
|
|
|
74
|
-
export function registerProject(program: Command): void {
|
|
85
|
+
export function registerProject(program: Command, ctx: CliContext): void {
|
|
75
86
|
const project = program.command('project').description('Project management commands');
|
|
76
87
|
|
|
77
|
-
project
|
|
88
|
+
const dedupe = project
|
|
78
89
|
.command('dedupe-req-ids')
|
|
79
90
|
.description('Remap globally duplicated req ids (report with --dry-run)')
|
|
80
91
|
.option('--dry-run', 'report the remap plan without writing')
|
|
81
|
-
.action((options: { dryRun?: boolean }) => {
|
|
92
|
+
.action((options: { dryRun?: boolean; directory?: string }) => {
|
|
82
93
|
// dedupe registry covers requirement handles (`@req` on 规则: headers) only;
|
|
83
94
|
// duplicates follow the occurrence model (同文件内共用或跨文件均算)
|
|
84
|
-
|
|
95
|
+
// r115: the instance root (--directory, else the nearest at or above cwd)
|
|
96
|
+
// scopes the registry AND the write plan — never the launch dir alone.
|
|
97
|
+
const entries = loadRootSpecEntries(options.directory, ctx.io);
|
|
85
98
|
const { duplicates } = buildReqRegistry(entries);
|
|
86
99
|
if (duplicates.length === 0) {
|
|
87
100
|
console.log('No colliding req_id values in llmanspec/specs.');
|
|
88
101
|
return;
|
|
89
102
|
}
|
|
90
|
-
const io =
|
|
103
|
+
const io = ctx.io;
|
|
91
104
|
// r43: --dry-run is zero-side-effect — plan only, never write.
|
|
92
|
-
const plan = planDedupe(
|
|
93
|
-
|
|
94
|
-
|
|
105
|
+
const plan = planDedupe(
|
|
106
|
+
entries,
|
|
107
|
+
io,
|
|
108
|
+
resolveRootSpecsDir(options.directory, ctx.io),
|
|
109
|
+
duplicates,
|
|
110
|
+
{
|
|
111
|
+
apply: !options.dryRun,
|
|
112
|
+
},
|
|
113
|
+
);
|
|
95
114
|
// predecessor output: `{cap}: {from} → {to}` per remap (prefix in dry-run) + count line.
|
|
96
115
|
for (const item of plan) {
|
|
97
116
|
const cap = item.remapFile.replace(/^.*specs\//u, '').replace(/\.feature$/u, '');
|
|
@@ -100,8 +119,9 @@ export function registerProject(program: Command): void {
|
|
|
100
119
|
}
|
|
101
120
|
console.log(`${plan.length} remapping(s)${options.dryRun ? ' (dry-run)' : ''}`);
|
|
102
121
|
});
|
|
122
|
+
addSpecDirOption(dedupe);
|
|
103
123
|
|
|
104
|
-
project
|
|
124
|
+
const migrate = project
|
|
105
125
|
.command('migrate')
|
|
106
126
|
.description(
|
|
107
127
|
'Migration hub: legacy collaboration notes, versioned agent playbooks, spec-header strip',
|
|
@@ -116,7 +136,21 @@ export function registerProject(program: Command): void {
|
|
|
116
136
|
)
|
|
117
137
|
.option('--dry-run', 'strip-legacy-headers: report affected files without writing')
|
|
118
138
|
.action((action: string | undefined, options: MigrateOptions) => {
|
|
119
|
-
|
|
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
|
+
if (
|
|
143
|
+
action === undefined &&
|
|
144
|
+
(options.versionExpr !== undefined ||
|
|
145
|
+
options.fromVersion !== undefined ||
|
|
146
|
+
options.toVersion !== undefined)
|
|
147
|
+
) {
|
|
148
|
+
throw new CliError(
|
|
149
|
+
'project migrate range flags require the prompt action (llman-sdd project migrate prompt)',
|
|
150
|
+
2,
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
const locale = loadCliConfig()?.locale ?? DEFAULT_LOCALE;
|
|
120
154
|
if (action === 'prompt') {
|
|
121
155
|
const range = resolvePromptRange(options);
|
|
122
156
|
if (range === null) {
|
|
@@ -131,12 +165,16 @@ export function registerProject(program: Command): void {
|
|
|
131
165
|
}
|
|
132
166
|
for (const v of [range.from, range.to]) {
|
|
133
167
|
if (!isValidVersion(v)) {
|
|
134
|
-
throw new CliError(
|
|
168
|
+
throw new CliError(
|
|
169
|
+
`invalid version '${v}': expected x.y.z (e.g. 0.9.0), got '${v}'`,
|
|
170
|
+
2,
|
|
171
|
+
);
|
|
135
172
|
}
|
|
136
173
|
}
|
|
137
174
|
if (compareVersions(range.from, range.to) >= 0) {
|
|
138
175
|
throw new CliError(
|
|
139
176
|
`invalid range: --from-version (${range.from}) must be less than --to-version (${range.to})`,
|
|
177
|
+
2,
|
|
140
178
|
);
|
|
141
179
|
}
|
|
142
180
|
if (range.viaExpr) {
|
|
@@ -158,7 +196,7 @@ export function registerProject(program: Command): void {
|
|
|
158
196
|
'strip-legacy-headers takes no --kind/--version-expr/--from-version/--to-version',
|
|
159
197
|
);
|
|
160
198
|
}
|
|
161
|
-
const targets = collectFeatureFiles([
|
|
199
|
+
const targets = collectFeatureFiles([resolveRootSpecsDir(options.directory, ctx.io)]);
|
|
162
200
|
let touched = 0;
|
|
163
201
|
let removed = 0;
|
|
164
202
|
for (const file of targets) {
|
|
@@ -180,6 +218,7 @@ export function registerProject(program: Command): void {
|
|
|
180
218
|
if (action !== undefined) {
|
|
181
219
|
throw new CliError(
|
|
182
220
|
`unknown migrate action: ${action} (expected: prompt | strip-legacy-headers)`,
|
|
221
|
+
2,
|
|
183
222
|
);
|
|
184
223
|
}
|
|
185
224
|
if (options.kind === undefined) {
|
|
@@ -191,8 +230,10 @@ export function registerProject(program: Command): void {
|
|
|
191
230
|
if (note === null) {
|
|
192
231
|
throw new CliError(
|
|
193
232
|
`unknown migration kind: ${options.kind} (expected: toon2features | specs-flatten)`,
|
|
233
|
+
2,
|
|
194
234
|
);
|
|
195
235
|
}
|
|
196
236
|
console.log(note);
|
|
197
237
|
});
|
|
238
|
+
addSpecDirOption(migrate);
|
|
198
239
|
}
|