@llman-sdd/cli 0.9.0 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/cli-shared.ts +196 -42
- package/src/commands/archive.ts +70 -55
- 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/spec.ts
CHANGED
|
@@ -3,13 +3,13 @@ import { join } from 'node:path';
|
|
|
3
3
|
import { createInterface } from 'node:readline';
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
|
+
DEFAULT_LOCALE,
|
|
6
7
|
addReq,
|
|
7
8
|
addScenario,
|
|
8
9
|
buildUnboundFeed,
|
|
9
10
|
hasNativeRules,
|
|
10
11
|
migrateNativeSource,
|
|
11
12
|
nextReqId,
|
|
12
|
-
renderMachine,
|
|
13
13
|
resolveReq,
|
|
14
14
|
scaffoldSpec,
|
|
15
15
|
TRANSITIONS_INTROSPECTION,
|
|
@@ -19,12 +19,14 @@ import type { Command } from 'commander';
|
|
|
19
19
|
|
|
20
20
|
import {
|
|
21
21
|
addReportOutputOptions,
|
|
22
|
+
addSpecDirOption,
|
|
22
23
|
CliError,
|
|
23
24
|
loadCliConfig,
|
|
24
25
|
loadRootSpecEntries,
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
emitReport,
|
|
27
|
+
resolveCommandRoot,
|
|
27
28
|
resolveRootSpecsDir,
|
|
29
|
+
type CliContext,
|
|
28
30
|
} from '../cli-shared.ts';
|
|
29
31
|
|
|
30
32
|
/** Walk paths collecting .feature files (directories recurse). */
|
|
@@ -55,80 +57,77 @@ function confirmInteractive(question: string): Promise<boolean> {
|
|
|
55
57
|
});
|
|
56
58
|
}
|
|
57
59
|
|
|
58
|
-
export function registerSpec(program: Command): void {
|
|
60
|
+
export function registerSpec(program: Command, ctx: CliContext): void {
|
|
59
61
|
const spec = program.command('spec').description('Spec authoring helpers');
|
|
60
62
|
|
|
61
|
-
spec
|
|
63
|
+
const skeleton = spec
|
|
62
64
|
.command('skeleton')
|
|
63
65
|
.description('Generate a single-track spec skeleton for a capability')
|
|
64
66
|
.argument('<capability>')
|
|
65
|
-
.option('--force', 'overwrite an existing spec file')
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
force: options.force,
|
|
79
|
-
});
|
|
80
|
-
console.log(`wrote ${written}`);
|
|
67
|
+
.option('--force', 'overwrite an existing spec file');
|
|
68
|
+
addSpecDirOption(skeleton);
|
|
69
|
+
skeleton.action((capability: string, options: { force?: boolean; directory?: string }) => {
|
|
70
|
+
// r109/r115: locale 属命中实例根的配置,`--directory` 指向子根时不得读启动根
|
|
71
|
+
const locale =
|
|
72
|
+
loadCliConfig(resolveCommandRoot(ctx, options.directory))?.locale ?? DEFAULT_LOCALE;
|
|
73
|
+
const specsDir = resolveRootSpecsDir(options.directory, ctx.io);
|
|
74
|
+
const path = join(specsDir, `${capability}.feature`);
|
|
75
|
+
if (!options.force && existsSync(path)) {
|
|
76
|
+
throw new CliError(`spec already exists: ${path} (use --force to overwrite)`);
|
|
77
|
+
}
|
|
78
|
+
const written = scaffoldSpec(ctx.io, specsDir, capability, locale, {
|
|
79
|
+
force: options.force,
|
|
81
80
|
});
|
|
81
|
+
console.log(`wrote ${written}`);
|
|
82
|
+
});
|
|
82
83
|
|
|
83
|
-
spec
|
|
84
|
+
const nextReq = spec
|
|
84
85
|
.command('next-req-id')
|
|
85
|
-
.description('Allocate the next global req id (max in use + 1, rN)')
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
else console.log(reqId);
|
|
95
|
-
});
|
|
86
|
+
.description('Allocate the next global req id (max in use + 1, rN)');
|
|
87
|
+
addReportOutputOptions(nextReq, { outputHint: 'json {reqId}; toon default' });
|
|
88
|
+
addSpecDirOption(nextReq);
|
|
89
|
+
nextReq.action(
|
|
90
|
+
(options: { json?: boolean; output?: string; compactJson?: boolean; directory?: string }) => {
|
|
91
|
+
const reqId = nextReqId(ctx.io, resolveRootSpecsDir(options.directory, ctx.io));
|
|
92
|
+
emitReport({ reqId }, options, () => reqId);
|
|
93
|
+
},
|
|
94
|
+
);
|
|
96
95
|
|
|
97
|
-
spec
|
|
96
|
+
const addReqCmd = spec
|
|
98
97
|
.command('add-req')
|
|
99
98
|
.alias('add-requirement')
|
|
100
99
|
.description('Append a 规则: block (with @req handle) to a capability spec')
|
|
101
100
|
.argument('<capability>')
|
|
102
101
|
.argument('<req_id>')
|
|
103
102
|
.requiredOption('--title <title>', 'rule title')
|
|
104
|
-
.requiredOption(
|
|
105
|
-
|
|
106
|
-
'
|
|
107
|
-
'instance root resolution start (default: nearest llmanspec/ at or above cwd)',
|
|
108
|
-
)
|
|
109
|
-
.action(
|
|
110
|
-
(
|
|
111
|
-
capability: string,
|
|
112
|
-
reqId: string,
|
|
113
|
-
options: { title: string; statement: string; directory?: string },
|
|
114
|
-
) => {
|
|
115
|
-
const io = newIo();
|
|
116
|
-
const path = addReq(
|
|
117
|
-
io,
|
|
118
|
-
resolveRootSpecsDir(options.directory),
|
|
119
|
-
loadRootSpecEntries(options.directory),
|
|
120
|
-
{
|
|
121
|
-
capability,
|
|
122
|
-
reqId,
|
|
123
|
-
title: options.title,
|
|
124
|
-
statement: options.statement,
|
|
125
|
-
},
|
|
126
|
-
);
|
|
127
|
-
console.log(path);
|
|
128
|
-
},
|
|
103
|
+
.requiredOption(
|
|
104
|
+
'--statement <statement>',
|
|
105
|
+
'rule statement (free text; multiple lines via \\n)',
|
|
129
106
|
);
|
|
107
|
+
addSpecDirOption(addReqCmd);
|
|
108
|
+
addReqCmd.action(
|
|
109
|
+
(
|
|
110
|
+
capability: string,
|
|
111
|
+
reqId: string,
|
|
112
|
+
options: { title: string; statement: string; directory?: string },
|
|
113
|
+
) => {
|
|
114
|
+
const io = ctx.io;
|
|
115
|
+
const path = addReq(
|
|
116
|
+
io,
|
|
117
|
+
resolveRootSpecsDir(options.directory, ctx.io),
|
|
118
|
+
loadRootSpecEntries(options.directory, ctx.io),
|
|
119
|
+
{
|
|
120
|
+
capability,
|
|
121
|
+
reqId,
|
|
122
|
+
title: options.title,
|
|
123
|
+
statement: options.statement,
|
|
124
|
+
},
|
|
125
|
+
);
|
|
126
|
+
console.log(path);
|
|
127
|
+
},
|
|
128
|
+
);
|
|
130
129
|
|
|
131
|
-
spec
|
|
130
|
+
const addScenarioCmd = spec
|
|
132
131
|
.command('add-scenario')
|
|
133
132
|
.description('Insert a nested 场景: under the named rule in a spec')
|
|
134
133
|
.argument('<capability>')
|
|
@@ -136,45 +135,47 @@ export function registerSpec(program: Command): void {
|
|
|
136
135
|
.argument('<scenario_id>')
|
|
137
136
|
.option('--given <given>', 'Given step (optional)')
|
|
138
137
|
.requiredOption('--when <when>', 'When step')
|
|
139
|
-
.requiredOption('--then <then>', 'Then step')
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
console.log(path);
|
|
166
|
-
},
|
|
167
|
-
);
|
|
138
|
+
.requiredOption('--then <then>', 'Then step');
|
|
139
|
+
addSpecDirOption(addScenarioCmd);
|
|
140
|
+
addScenarioCmd.action(
|
|
141
|
+
(
|
|
142
|
+
capability: string,
|
|
143
|
+
reqId: string,
|
|
144
|
+
scenarioId: string,
|
|
145
|
+
options: { given?: string; when: string; then: string; directory?: string },
|
|
146
|
+
) => {
|
|
147
|
+
const io = ctx.io;
|
|
148
|
+
const path = addScenario(
|
|
149
|
+
io,
|
|
150
|
+
resolveRootSpecsDir(options.directory, ctx.io),
|
|
151
|
+
loadRootSpecEntries(options.directory, ctx.io),
|
|
152
|
+
{
|
|
153
|
+
capability,
|
|
154
|
+
reqId,
|
|
155
|
+
scenarioId,
|
|
156
|
+
given: options.given,
|
|
157
|
+
when: options.when,
|
|
158
|
+
thenText: options.then,
|
|
159
|
+
},
|
|
160
|
+
);
|
|
161
|
+
console.log(path);
|
|
162
|
+
},
|
|
163
|
+
);
|
|
168
164
|
|
|
169
|
-
spec
|
|
165
|
+
const migrateNative = spec
|
|
170
166
|
.command('migrate-native')
|
|
171
167
|
.description('Migrate legacy tag-based .feature files to the native 规则:/场景: layout')
|
|
172
168
|
.argument('[paths...]', 'feature files or directories (default: llmanspec/specs)')
|
|
173
169
|
.option('--dry-run', 'print the migration plan without writing')
|
|
174
|
-
.option('-y, --yes', 'proceed without per-file confirmation')
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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;
|
|
178
179
|
let migrated = 0;
|
|
179
180
|
let skipped = 0;
|
|
180
181
|
for (const file of targets) {
|
|
@@ -205,70 +206,80 @@ export function registerSpec(program: Command): void {
|
|
|
205
206
|
}
|
|
206
207
|
}
|
|
207
208
|
console.log(`migrate-native: ${migrated} file(s) migrated, ${skipped} already native`);
|
|
208
|
-
}
|
|
209
|
+
},
|
|
210
|
+
);
|
|
209
211
|
|
|
210
|
-
spec
|
|
212
|
+
const resolveReqCmd = spec
|
|
211
213
|
.command('resolve-req')
|
|
212
214
|
.description('Resolve an rN to its capability and statement')
|
|
213
|
-
.argument('<req_id>')
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
)
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
console.log('harness:');
|
|
228
|
-
for (const h of resolved.harness) console.log(` - ${h}`);
|
|
229
|
-
});
|
|
215
|
+
.argument('<req_id>');
|
|
216
|
+
addSpecDirOption(resolveReqCmd);
|
|
217
|
+
resolveReqCmd.action((reqId: string, options: { directory?: string }) => {
|
|
218
|
+
const resolved = resolveReq(loadRootSpecEntries(options.directory, ctx.io), reqId);
|
|
219
|
+
if (resolved === null) {
|
|
220
|
+
throw new CliError(`req id not found: ${reqId}`);
|
|
221
|
+
}
|
|
222
|
+
console.log(`reqId: ${resolved.reqId}`);
|
|
223
|
+
console.log(`capability: ${resolved.capability}`);
|
|
224
|
+
console.log(`title: ${resolved.title}`);
|
|
225
|
+
console.log(`statement: ${resolved.statement.replaceAll('\n', ' ')}`);
|
|
226
|
+
console.log('harness:');
|
|
227
|
+
for (const h of resolved.harness) console.log(` - ${h}`);
|
|
228
|
+
});
|
|
230
229
|
|
|
231
|
-
spec
|
|
230
|
+
const transitions = spec
|
|
232
231
|
.command('transitions')
|
|
233
|
-
.description('Show transition-table validation rules: alias families, tags, gates')
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
232
|
+
.description('Show transition-table validation rules: alias families, tags, gates');
|
|
233
|
+
addSpecDirOption(transitions);
|
|
234
|
+
transitions.action((options: { directory?: string }) => {
|
|
235
|
+
// r109: 本命令输出为静态内省,无实例根语义;仍按「豁免外全部命令声明并接受
|
|
236
|
+
// --directory」声明该选项,并仅在显式给出时经同一根发现算子校验(无实例报域错误)。
|
|
237
|
+
if (options.directory !== undefined) resolveCommandRoot(ctx, options.directory);
|
|
238
|
+
const info = TRANSITIONS_INTROSPECTION;
|
|
239
|
+
console.log('columns:');
|
|
240
|
+
for (const fam of info.columnFamilies) {
|
|
241
|
+
const optional = 'optional' in fam && fam.optional ? ' (optional)' : '';
|
|
242
|
+
console.log(` ${fam.role}${optional}: ${fam.aliases.join(' | ')}`);
|
|
243
|
+
}
|
|
244
|
+
console.log(`discovery: ${info.discovery}`);
|
|
245
|
+
console.log('tags:');
|
|
246
|
+
for (const t of info.tags) console.log(` ${t.tag} — ${t.semantics}`);
|
|
247
|
+
console.log('gates:');
|
|
248
|
+
for (const g of info.gates) console.log(` - ${g}`);
|
|
249
|
+
});
|
|
247
250
|
|
|
248
251
|
const unbound = spec
|
|
249
252
|
.command('unbound')
|
|
250
253
|
.description('List unbound requirements (no runnable nested scenario) for implementation')
|
|
251
254
|
.option('--limit <N>', 'max entries to return (default 1; 0 = all)');
|
|
252
255
|
addReportOutputOptions(unbound);
|
|
256
|
+
addSpecDirOption(unbound);
|
|
253
257
|
unbound.action(
|
|
254
|
-
(options: {
|
|
258
|
+
(options: {
|
|
259
|
+
limit?: string;
|
|
260
|
+
output?: string;
|
|
261
|
+
json?: boolean;
|
|
262
|
+
compactJson?: boolean;
|
|
263
|
+
directory?: string;
|
|
264
|
+
}) => {
|
|
255
265
|
const raw = options.limit ?? '1';
|
|
256
266
|
if (!/^\d+$/u.test(raw)) {
|
|
257
267
|
throw new CliError(`invalid --limit: ${raw} (non-negative integer)`, 2);
|
|
258
268
|
}
|
|
259
269
|
const limit = Number(raw);
|
|
260
|
-
const feed: UnboundFeed = buildUnboundFeed(
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
270
|
+
const feed: UnboundFeed = buildUnboundFeed(
|
|
271
|
+
loadRootSpecEntries(options.directory, ctx.io),
|
|
272
|
+
limit,
|
|
273
|
+
);
|
|
274
|
+
emitReport(feed, options, () => {
|
|
275
|
+
const lines = [`spec unbound: ${feed.returned} shown of ${feed.total} total`];
|
|
276
|
+
for (const r of feed.requirements) {
|
|
277
|
+
lines.push(` - [${r.reqId}] ${r.featurePath} :: ${r.title}`);
|
|
278
|
+
for (const line of r.statement.split('\n')) lines.push(` ${line}`);
|
|
279
|
+
}
|
|
280
|
+
if (feed.hint !== '') lines.push(feed.hint);
|
|
281
|
+
return lines.join('\n');
|
|
282
|
+
});
|
|
272
283
|
},
|
|
273
284
|
);
|
|
274
285
|
}
|