@llman-sdd/cli 0.7.4 → 0.8.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/commands/project.ts +112 -17
- package/src/commands/review.ts +2 -7
- package/src/commands/validate.ts +2 -84
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@llman-sdd/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Spec-driven development workflow CLI (the `llman-sdd` command)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"build": "bun run ./scripts/build-binary.ts"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@llman-sdd/core": "0.7.
|
|
30
|
+
"@llman-sdd/core": "0.7.5",
|
|
31
31
|
"commander": "^15.0.0"
|
|
32
32
|
},
|
|
33
33
|
"engines": {
|
package/src/commands/project.ts
CHANGED
|
@@ -1,8 +1,36 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { existsSync, readFileSync, readdirSync, statSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
buildReqRegistry,
|
|
6
|
+
findMigration,
|
|
7
|
+
isValidMigrationExpr,
|
|
8
|
+
migrateNoteFor,
|
|
9
|
+
migrateOverviewFor,
|
|
10
|
+
migrationOverviewLines,
|
|
11
|
+
migrationPrompt,
|
|
12
|
+
knownMigrationIds,
|
|
13
|
+
planDedupe,
|
|
14
|
+
stripLegacyHeaderLines,
|
|
15
|
+
} from '@llman-sdd/core';
|
|
2
16
|
import type { Command } from 'commander';
|
|
3
17
|
|
|
4
18
|
import { CliError, loadCliConfig, loadSpecEntries, newIo } from '../cli-shared.ts';
|
|
5
19
|
|
|
20
|
+
function collectFeatureFiles(paths: string[]): string[] {
|
|
21
|
+
const out: string[] = [];
|
|
22
|
+
const walk = (p: string): void => {
|
|
23
|
+
const st = statSync(p);
|
|
24
|
+
if (st.isDirectory()) {
|
|
25
|
+
for (const e of readdirSync(p)) walk(join(p, e));
|
|
26
|
+
} else if (p.endsWith('.feature')) out.push(p);
|
|
27
|
+
};
|
|
28
|
+
for (const p of paths) {
|
|
29
|
+
if (existsSync(p)) walk(p);
|
|
30
|
+
}
|
|
31
|
+
return out;
|
|
32
|
+
}
|
|
33
|
+
|
|
6
34
|
export function registerProject(program: Command): void {
|
|
7
35
|
const project = program.command('project').description('Project management commands');
|
|
8
36
|
|
|
@@ -35,20 +63,87 @@ export function registerProject(program: Command): void {
|
|
|
35
63
|
|
|
36
64
|
project
|
|
37
65
|
.command('migrate')
|
|
38
|
-
.description(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
66
|
+
.description(
|
|
67
|
+
'Migration hub: legacy collaboration notes, versioned agent playbooks, spec-header strip',
|
|
68
|
+
)
|
|
69
|
+
.argument('[action]', 'prompt | strip-legacy-headers')
|
|
70
|
+
.option('--kind <kind>', 'legacy collaboration notes: toon2features | specs-flatten')
|
|
71
|
+
.option('--version-expr <expr>', "migration playbook selector, e.g. '0.7.5->0.8.0'")
|
|
72
|
+
.option('--dry-run', 'strip-legacy-headers: report affected files without writing')
|
|
73
|
+
.action(
|
|
74
|
+
(
|
|
75
|
+
action: string | undefined,
|
|
76
|
+
options: { kind?: string; versionExpr?: string; dryRun?: boolean },
|
|
77
|
+
) => {
|
|
78
|
+
const locale = loadCliConfig()?.locale ?? 'en';
|
|
79
|
+
if (action === 'prompt') {
|
|
80
|
+
const expr = options.versionExpr;
|
|
81
|
+
if (expr === undefined) {
|
|
82
|
+
console.log(
|
|
83
|
+
[
|
|
84
|
+
'Migration playbook selector is required.',
|
|
85
|
+
`Known migrations: ${knownMigrationIds().join(', ')}`,
|
|
86
|
+
"Usage: llman-sdd project migrate prompt --version-expr '<from>-><to>'",
|
|
87
|
+
].join('\n'),
|
|
88
|
+
);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (!isValidMigrationExpr(expr)) {
|
|
92
|
+
throw new CliError(
|
|
93
|
+
`invalid --version-expr: ${expr} (expected '<from>-><to>', e.g. '0.7.5->0.8.0')`,
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
const migration = findMigration(expr);
|
|
97
|
+
if (migration === null) {
|
|
98
|
+
throw new CliError(
|
|
99
|
+
`unknown migration: ${expr} (known: ${knownMigrationIds().join(', ')})`,
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
console.log(migrationPrompt(migration));
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
if (action === 'strip-legacy-headers') {
|
|
106
|
+
if (options.kind !== undefined || options.versionExpr !== undefined) {
|
|
107
|
+
throw new CliError('strip-legacy-headers takes no --kind/--version-expr');
|
|
108
|
+
}
|
|
109
|
+
const targets = collectFeatureFiles(['llmanspec/specs']);
|
|
110
|
+
let touched = 0;
|
|
111
|
+
let removed = 0;
|
|
112
|
+
for (const file of targets) {
|
|
113
|
+
const source = readFileSync(file, 'utf8');
|
|
114
|
+
const result = stripLegacyHeaderLines(source);
|
|
115
|
+
if (result.removed === 0) continue;
|
|
116
|
+
touched++;
|
|
117
|
+
removed += result.removed;
|
|
118
|
+
console.log(
|
|
119
|
+
`[strip] ${file}: ${result.removed} line(s)${options.dryRun === true ? ' (dry-run)' : ''}`,
|
|
120
|
+
);
|
|
121
|
+
if (options.dryRun !== true) writeFileSync(file, result.content, 'utf8');
|
|
122
|
+
}
|
|
123
|
+
const mode = options.dryRun === true ? ' (dry-run)' : '';
|
|
124
|
+
console.log(
|
|
125
|
+
`strip-legacy-headers: ${touched} file(s), ${removed} line(s) removed${mode}`,
|
|
126
|
+
);
|
|
127
|
+
console.log('next: re-run `llman-sdd init --update` to refresh skills and templates');
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
if (action !== undefined) {
|
|
131
|
+
throw new CliError(
|
|
132
|
+
`unknown migrate action: ${action} (expected: prompt | strip-legacy-headers)`,
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
if (options.kind === undefined) {
|
|
136
|
+
console.log(migrateOverviewFor(locale));
|
|
137
|
+
console.log(migrationOverviewLines().join('\n'));
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const note = migrateNoteFor(options.kind, locale);
|
|
141
|
+
if (note === null) {
|
|
142
|
+
throw new CliError(
|
|
143
|
+
`unknown migration kind: ${options.kind} (expected: toon2features | specs-flatten)`,
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
console.log(note);
|
|
147
|
+
},
|
|
148
|
+
);
|
|
54
149
|
}
|
package/src/commands/review.ts
CHANGED
|
@@ -21,12 +21,11 @@ import {
|
|
|
21
21
|
resolveOutMode,
|
|
22
22
|
templateIo,
|
|
23
23
|
} from '../cli-shared.ts';
|
|
24
|
-
import { makeCliGit } from '../io.ts';
|
|
25
24
|
|
|
26
25
|
export function registerReview(program: Command): void {
|
|
27
26
|
const review = program
|
|
28
27
|
.command('review')
|
|
29
|
-
.description('Aggregate review: unbound
|
|
28
|
+
.description('Aggregate review: unbound signals plus a validate sweep');
|
|
30
29
|
|
|
31
30
|
review.option('--capability <capability>', 'restrict the sweep to one capability/spec id');
|
|
32
31
|
addReportOutputOptions(review);
|
|
@@ -51,7 +50,7 @@ export function registerReview(program: Command): void {
|
|
|
51
50
|
const activeChanges = collectChanges(io, process.cwd(), new Date(), {
|
|
52
51
|
maxScanDepth: cliMaxScanDepth(program),
|
|
53
52
|
});
|
|
54
|
-
// B17:
|
|
53
|
+
// B17: 墙钟由 CLI 注入,core 不直读 new Date()
|
|
55
54
|
const now = new Date();
|
|
56
55
|
const result = buildReview(
|
|
57
56
|
{
|
|
@@ -59,10 +58,6 @@ export function registerReview(program: Command): void {
|
|
|
59
58
|
boundChangeCount: activeChanges.filter((c) => c.hasBinding).length,
|
|
60
59
|
activeChanges,
|
|
61
60
|
capability: options.capability,
|
|
62
|
-
git: makeCliGit(process.cwd()),
|
|
63
|
-
root: process.cwd(),
|
|
64
|
-
specsDir: 'llmanspec/specs',
|
|
65
|
-
baseRefEnv: process.env.LLMANSPEC_BASE_REF,
|
|
66
61
|
},
|
|
67
62
|
io,
|
|
68
63
|
);
|
package/src/commands/validate.ts
CHANGED
|
@@ -1,29 +1,22 @@
|
|
|
1
1
|
import { relative } from 'node:path';
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
-
applyStrict,
|
|
5
4
|
buildDuplicatesFor,
|
|
6
5
|
checkGlobalChangeIdUniqueness,
|
|
7
6
|
collectChanges,
|
|
8
7
|
currentBranch,
|
|
9
8
|
defaultBranch,
|
|
10
9
|
discoverRoots,
|
|
11
|
-
evaluateStaleness,
|
|
12
10
|
formatTotals,
|
|
13
|
-
notApplicableStaleness,
|
|
14
11
|
renderMachine,
|
|
15
12
|
resolveInstanceRoot,
|
|
16
13
|
runHarnessForSpecs,
|
|
17
|
-
scopeCrossings,
|
|
18
|
-
specRelFor,
|
|
19
14
|
specIdOf,
|
|
20
15
|
STAGE_ORDER,
|
|
21
16
|
validateCapability,
|
|
22
17
|
validateChange,
|
|
23
18
|
type ChangeIssue,
|
|
24
19
|
type HarnessGate,
|
|
25
|
-
type RootEntry,
|
|
26
|
-
type StalenessInfo,
|
|
27
20
|
} from '@llman-sdd/core';
|
|
28
21
|
import type { Command } from 'commander';
|
|
29
22
|
|
|
@@ -48,7 +41,6 @@ interface VItem {
|
|
|
48
41
|
valid: boolean;
|
|
49
42
|
issues: ChangeIssue[];
|
|
50
43
|
durationMs: number;
|
|
51
|
-
staleness: StalenessInfo;
|
|
52
44
|
matchedViaPrefix: boolean;
|
|
53
45
|
}
|
|
54
46
|
|
|
@@ -57,34 +49,16 @@ function compareItems(a: VItem, b: VItem): number {
|
|
|
57
49
|
return a.id < b.id ? -1 : a.id > b.id ? 1 : a.type.localeCompare(b.type);
|
|
58
50
|
}
|
|
59
51
|
|
|
60
|
-
/**
|
|
61
|
-
* Multi-root context of the specs being validated (r91-r92): `repoRelPrefix`
|
|
62
|
-
* lifts instance-root-relative scopes into repo-relative paths for the
|
|
63
|
-
* staleness diff match ('' when the instance root is the git toplevel —
|
|
64
|
-
* byte-identical legacy behavior); `otherRoots` feeds the single-ownership
|
|
65
|
-
* crossings that surface as ERROR issues.
|
|
66
|
-
*/
|
|
67
|
-
export interface InstanceContext {
|
|
68
|
-
repoRelPrefix: string;
|
|
69
|
-
otherRoots: RootEntry[];
|
|
70
|
-
}
|
|
71
|
-
|
|
72
52
|
function specV1Items(
|
|
73
53
|
opts: {
|
|
74
54
|
strict?: boolean;
|
|
75
55
|
harness?: HarnessGate;
|
|
76
56
|
harnessOnlyIds?: string[];
|
|
77
|
-
instance?: InstanceContext;
|
|
78
57
|
},
|
|
79
58
|
entries: ReturnType<typeof loadSpecEntries> = loadSpecEntries(),
|
|
80
59
|
): VItem[] {
|
|
81
60
|
const io = newIo();
|
|
82
|
-
const git = makeCliGit(process.cwd());
|
|
83
61
|
const duplicatesFor = buildDuplicatesFor(entries);
|
|
84
|
-
const liftScope = (scope: string): string =>
|
|
85
|
-
opts.instance !== undefined && opts.instance.repoRelPrefix !== ''
|
|
86
|
-
? `${opts.instance.repoRelPrefix}/${scope}`
|
|
87
|
-
: scope;
|
|
88
62
|
|
|
89
63
|
const items: VItem[] = [];
|
|
90
64
|
for (const entry of entries) {
|
|
@@ -92,42 +66,17 @@ function specV1Items(
|
|
|
92
66
|
const verdict = validateCapability(entry as never, duplicatesFor, io, {
|
|
93
67
|
strict: opts.strict === true,
|
|
94
68
|
});
|
|
95
|
-
const
|
|
96
|
-
const specRel = specRelFor(entry.fileName);
|
|
97
|
-
const staleness = evaluateStaleness({
|
|
98
|
-
git,
|
|
99
|
-
root: process.cwd(),
|
|
100
|
-
specRel,
|
|
101
|
-
scope: scopes.map(liftScope),
|
|
102
|
-
reviewedThrough: entry.doc.header.reviewedThrough,
|
|
103
|
-
baseRefEnv: process.env.LLMANSPEC_BASE_REF,
|
|
104
|
-
});
|
|
105
|
-
let issues: ChangeIssue[] = verdict.items.map((i) => ({
|
|
69
|
+
const issues: ChangeIssue[] = verdict.items.map((i) => ({
|
|
106
70
|
level: i.level,
|
|
107
71
|
path: i.id,
|
|
108
72
|
message: i.message,
|
|
109
73
|
}));
|
|
110
|
-
if (opts.instance !== undefined) {
|
|
111
|
-
for (const crossing of scopeCrossings(scopes, process.cwd(), opts.instance.otherRoots)) {
|
|
112
|
-
issues = [
|
|
113
|
-
...issues,
|
|
114
|
-
{
|
|
115
|
-
level: 'ERROR',
|
|
116
|
-
path: 'single-ownership',
|
|
117
|
-
message: `scope '${crossing.scope}' crosses sub-root '${crossing.rootDir}' — migrate these specs into that root or narrow the scope (one path, one root)`,
|
|
118
|
-
},
|
|
119
|
-
];
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
if (opts.strict === true) issues = [...issues, ...applyStrict(staleness.issues)];
|
|
123
|
-
else issues = [...issues, ...staleness.issues];
|
|
124
74
|
items.push({
|
|
125
75
|
id: cap,
|
|
126
76
|
type: 'spec',
|
|
127
77
|
valid: issues.every((i) => i.level !== 'ERROR'),
|
|
128
78
|
issues,
|
|
129
79
|
durationMs: 0,
|
|
130
|
-
staleness: staleness.info,
|
|
131
80
|
matchedViaPrefix: false,
|
|
132
81
|
});
|
|
133
82
|
}
|
|
@@ -179,7 +128,6 @@ function changeV1Items(names: string[], opts: { stage?: string; strict?: boolean
|
|
|
179
128
|
valid: res.valid,
|
|
180
129
|
issues: res.issues,
|
|
181
130
|
durationMs: 0,
|
|
182
|
-
staleness: notApplicableStaleness(),
|
|
183
131
|
matchedViaPrefix: false,
|
|
184
132
|
});
|
|
185
133
|
}
|
|
@@ -206,7 +154,6 @@ function changeV1Items(names: string[], opts: { stage?: string; strict?: boolean
|
|
|
206
154
|
valid: false,
|
|
207
155
|
issues: [issue],
|
|
208
156
|
durationMs: 0,
|
|
209
|
-
staleness: notApplicableStaleness(),
|
|
210
157
|
matchedViaPrefix: false,
|
|
211
158
|
});
|
|
212
159
|
}
|
|
@@ -215,16 +162,6 @@ function changeV1Items(names: string[], opts: { stage?: string; strict?: boolean
|
|
|
215
162
|
return items;
|
|
216
163
|
}
|
|
217
164
|
|
|
218
|
-
function printStalenessLines(info: StalenessInfo): void {
|
|
219
|
-
if (info.status === 'NOTAPPLICABLE') return;
|
|
220
|
-
console.log(`Staleness: ${info.status}`);
|
|
221
|
-
if (info.touchedPaths.length > 0)
|
|
222
|
-
console.log(`Touched scope paths: ${info.touchedPaths.join(', ')}`);
|
|
223
|
-
if (info.specUpdated) console.log('Spec file updated since base.');
|
|
224
|
-
if (info.dirty) console.log('Working tree is dirty; results may be unreliable.');
|
|
225
|
-
for (const note of info.notes) console.log(`Note: ${note}`);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
165
|
function renderValidateText(items: VItem[]): void {
|
|
229
166
|
const passed = items.filter((i) => i.valid).length;
|
|
230
167
|
const failed = items.length - passed;
|
|
@@ -237,7 +174,6 @@ function renderValidateText(items: VItem[]): void {
|
|
|
237
174
|
console.error(` [${issue.level}] ${issue.path}: ${issue.message}`);
|
|
238
175
|
}
|
|
239
176
|
}
|
|
240
|
-
if (item.type === 'spec') printStalenessLines(item.staleness);
|
|
241
177
|
}
|
|
242
178
|
console.log(formatTotals(passed, failed, items.length));
|
|
243
179
|
}
|
|
@@ -247,19 +183,6 @@ function gitToplevelOrCwd(): string {
|
|
|
247
183
|
return toplevel ?? process.cwd();
|
|
248
184
|
}
|
|
249
185
|
|
|
250
|
-
/**
|
|
251
|
-
* Multi-root context of the cwd instance (r91-r92): empty otherRoots + ''
|
|
252
|
-
* prefix when run at a lone root — legacy byte-identical behavior.
|
|
253
|
-
*/
|
|
254
|
-
function instanceContextFor(maxDepth: number): InstanceContext {
|
|
255
|
-
const toplevel = gitToplevelOrCwd();
|
|
256
|
-
const otherRoots = discoverRoots(toplevel, newIo(), { maxDepth }).filter(
|
|
257
|
-
(r) => r.rootDir !== process.cwd(),
|
|
258
|
-
);
|
|
259
|
-
const repoRelPrefix = toplevel === process.cwd() ? '' : relative(toplevel, process.cwd());
|
|
260
|
-
return { repoRelPrefix, otherRoots };
|
|
261
|
-
}
|
|
262
|
-
|
|
263
186
|
interface RootReport {
|
|
264
187
|
root: string;
|
|
265
188
|
items: VItem[];
|
|
@@ -294,7 +217,7 @@ function renderValidateReport(items: VItem[], mode: 'json' | 'compact-json' | 't
|
|
|
294
217
|
}
|
|
295
218
|
|
|
296
219
|
const SPEC_NEXT_STEPS = [
|
|
297
|
-
'- Ensure each .feature starts with "# capability:"
|
|
220
|
+
'- Ensure each .feature starts with "# capability:" and "# purpose:" header comments',
|
|
298
221
|
'- Each requirement MUST include at least one scenario object',
|
|
299
222
|
'- Re-run with --json to see structured report',
|
|
300
223
|
];
|
|
@@ -425,7 +348,6 @@ export function registerValidate(program: Command): void {
|
|
|
425
348
|
const items = specV1Items({
|
|
426
349
|
strict: options.strict,
|
|
427
350
|
harness: makeHarnessGate(options),
|
|
428
|
-
instance: instanceContextFor(maxDepth),
|
|
429
351
|
});
|
|
430
352
|
const visible = keepInfo ? items : items.map(stripInfo);
|
|
431
353
|
if (visible.some((i) => !i.valid)) anyFail = true;
|
|
@@ -488,7 +410,6 @@ export function registerValidate(program: Command): void {
|
|
|
488
410
|
strict: options.strict,
|
|
489
411
|
harness,
|
|
490
412
|
harnessOnlyIds: [item],
|
|
491
|
-
instance: instanceContextFor(maxDepth),
|
|
492
413
|
},
|
|
493
414
|
entries,
|
|
494
415
|
);
|
|
@@ -511,7 +432,6 @@ export function registerValidate(program: Command): void {
|
|
|
511
432
|
console.error('Next steps:');
|
|
512
433
|
for (const s of SPEC_NEXT_STEPS) console.error(s);
|
|
513
434
|
}
|
|
514
|
-
if (shown.type === 'spec') printStalenessLines(shown.staleness);
|
|
515
435
|
if (!shown.valid) console.error('Error: validation failed');
|
|
516
436
|
exitWith(shown.valid ? 0 : 1);
|
|
517
437
|
return;
|
|
@@ -547,7 +467,6 @@ export function registerValidate(program: Command): void {
|
|
|
547
467
|
valid: res.valid,
|
|
548
468
|
issues: res.issues,
|
|
549
469
|
durationMs: 0,
|
|
550
|
-
staleness: notApplicableStaleness(),
|
|
551
470
|
matchedViaPrefix: resolved.viaPrefix,
|
|
552
471
|
}),
|
|
553
472
|
],
|
|
@@ -586,7 +505,6 @@ export function registerValidate(program: Command): void {
|
|
|
586
505
|
specV1Items({
|
|
587
506
|
strict: options.strict,
|
|
588
507
|
harness,
|
|
589
|
-
instance: instanceContextFor(maxDepth),
|
|
590
508
|
}),
|
|
591
509
|
);
|
|
592
510
|
}
|