@llman-sdd/cli 0.10.1 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +13 -5
- package/src/cli-shared.ts +87 -62
- package/src/commands/archive.ts +4 -19
- package/src/commands/change.ts +132 -172
- package/src/commands/config.ts +1 -29
- package/src/commands/init.ts +39 -11
- package/src/commands/list.ts +0 -2
- package/src/commands/project.ts +25 -115
- package/src/commands/review.ts +0 -1
- package/src/commands/self.ts +3 -1
- package/src/commands/show.ts +8 -46
- package/src/commands/spec.ts +6 -86
- package/src/commands/studio.ts +1315 -0
- package/src/commands/studioMcp.ts +862 -0
- package/src/commands/studioShared.ts +87 -0
- package/src/commands/theorem-write.ts +608 -0
- package/src/commands/theorem.ts +479 -0
- package/src/commands/validate.ts +108 -47
- package/src/io.ts +0 -1
- package/src/main.ts +3 -18
- package/src/program.ts +16 -16
- package/src/progress.ts +1 -3
- package/src/studio-server/changeScope.ts +295 -0
- package/src/studio-server/hub.ts +98 -0
- package/src/studio-server/negotiate.ts +60 -0
- package/src/studio-server/security.ts +71 -0
- package/src/studio-server/server.ts +1694 -0
- package/src/studio-server/static.ts +184 -0
- package/src/studio-server/syncDisk.ts +116 -0
- package/src/theorems/base.ts +53 -0
- package/src/theorems/diagnose.ts +90 -0
- package/src/theorems/draft.ts +252 -0
- package/src/theorems/os-lock.ts +364 -0
- package/src/theorems/paths.ts +11 -0
- package/src/theorems/prompts.ts +79 -0
- package/src/theorems/quiet.ts +21 -0
- package/src/theorems/runner.ts +48 -0
- package/src/theorems/transaction.ts +272 -0
- package/src/theorems/workspace.ts +103 -0
- package/studio-dist/index.html +14 -0
- package/studio-dist/static/css/index.00cf48cf.css +1 -0
- package/studio-dist/static/js/610.51883f69.js +218 -0
- package/studio-dist/static/js/610.51883f69.js.LICENSE.txt +26 -0
- package/studio-dist/static/js/index.c5f7c530.js +13 -0
- package/studio-dist/static/js/lib-react.a4b07007.js +2 -0
- package/studio-dist/static/js/lib-react.a4b07007.js.LICENSE.txt +49 -0
- package/src/commands/context.ts +0 -88
- package/src/commands/index.ts +0 -53
package/src/commands/change.ts
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { lstatSync, readdirSync } from 'node:fs';
|
|
2
|
-
import {
|
|
2
|
+
import { isAbsolute, join, relative, resolve } from 'node:path';
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
5
|
CLOSE_OUT_TASK_HINT,
|
|
6
|
+
THEOREMS_DIR_REL,
|
|
6
7
|
closeOutTaskLines,
|
|
7
8
|
archiveChange,
|
|
8
|
-
|
|
9
|
+
archiveTaskGate,
|
|
9
10
|
changeDiff,
|
|
10
11
|
changeDiffInfo,
|
|
11
12
|
defaultBranch,
|
|
12
13
|
deriveChangeId,
|
|
13
|
-
finalizeChange,
|
|
14
14
|
harvestAcrossWorktrees,
|
|
15
|
-
|
|
15
|
+
hintForChangeNew,
|
|
16
|
+
hintForChangeStart,
|
|
16
17
|
isCleanTree,
|
|
17
18
|
newChange,
|
|
18
19
|
renderChangeIdTemplate,
|
|
@@ -20,11 +21,12 @@ import {
|
|
|
20
21
|
startChange,
|
|
21
22
|
validateAllSpecs,
|
|
22
23
|
decideCloseOutHarness,
|
|
24
|
+
decideCloseOutDangling,
|
|
23
25
|
extractFrontmatter,
|
|
24
26
|
readNeedsSpecsChange,
|
|
25
27
|
type GitLike,
|
|
26
28
|
} from '@llman-sdd/core';
|
|
27
|
-
import {
|
|
29
|
+
import type { Command } from 'commander';
|
|
28
30
|
|
|
29
31
|
import {
|
|
30
32
|
CliError,
|
|
@@ -37,14 +39,15 @@ import {
|
|
|
37
39
|
resolveChangeIdOrExit,
|
|
38
40
|
type CliContext,
|
|
39
41
|
addReportOutputOptions,
|
|
42
|
+
emitCliHint,
|
|
40
43
|
emitReport,
|
|
41
44
|
resolveOutMode,
|
|
42
45
|
} from '../cli-shared.ts';
|
|
43
46
|
import { makeCliHarnessRunner } from '../harness.ts';
|
|
47
|
+
import { isPromptAborted, makeInquirerPromptPort } from '../theorems/prompts.ts';
|
|
48
|
+
import { changedTheoremFiles } from './theorem.ts';
|
|
44
49
|
|
|
45
50
|
function runValidateSweep(ctx: CliContext): boolean {
|
|
46
|
-
// r118: the sweep validates the resolved instance root's registry, not the
|
|
47
|
-
// launch directory's (`ctx` here is already the re-rooted context).
|
|
48
51
|
const report = validateAllSpecs(loadRootSpecEntries(ctx.root, ctx.io));
|
|
49
52
|
return report.verdicts.some((v) => !v.ok);
|
|
50
53
|
}
|
|
@@ -83,17 +86,17 @@ function warnBaseBranchDeviation(
|
|
|
83
86
|
|
|
84
87
|
/** r81: run or refuse the spec verification command before any merge or rename. */
|
|
85
88
|
function enforceCloseOutHarness(ctx: CliContext, id: string, noCheck: boolean): void {
|
|
86
|
-
// r118: the proposal is read and the harness runs at the resolved instance
|
|
87
|
-
// root (root-relative io), never at the launch directory.
|
|
88
89
|
const proposalPath = `llmanspec/changes/${id}/proposal.md`;
|
|
89
90
|
const proposal = ctx.io.exists(proposalPath) ? ctx.io.readText(proposalPath) : '';
|
|
90
91
|
const needsSpecsChange = readNeedsSpecsChange(extractFrontmatter(proposal));
|
|
91
|
-
const
|
|
92
|
+
const specs = loadCliConfig(ctx.root)?.specs;
|
|
93
|
+
const runCommand = specs?.check_command ?? null;
|
|
94
|
+
const nested = process.env.LLMAN_SDD_HARNESS_ACTIVE === '1';
|
|
92
95
|
const decision = decideCloseOutHarness({
|
|
93
96
|
noCheck,
|
|
94
97
|
needsSpecsChange,
|
|
95
98
|
runCommand,
|
|
96
|
-
nested
|
|
99
|
+
nested,
|
|
97
100
|
});
|
|
98
101
|
if (decision.kind === 'abort') {
|
|
99
102
|
throw new CliError(`close-out aborted: ${decision.message}`);
|
|
@@ -101,12 +104,27 @@ function enforceCloseOutHarness(ctx: CliContext, id: string, noCheck: boolean):
|
|
|
101
104
|
if (decision.kind === 'skip') {
|
|
102
105
|
if (decision.announce) console.error('spec check skipped: --no-check');
|
|
103
106
|
if (decision.warning !== undefined) console.error(`[WARNING] ${decision.warning}`);
|
|
104
|
-
|
|
107
|
+
} else {
|
|
108
|
+
const result = makeCliHarnessRunner().run(decision.command, ctx.root);
|
|
109
|
+
if (result.spawnError !== undefined || result.exitCode !== 0) {
|
|
110
|
+
const why = result.spawnError ?? `exit ${result.exitCode}`;
|
|
111
|
+
throw new CliError(`close-out aborted: spec check failed (${why})`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const dangling = decideCloseOutDangling({
|
|
115
|
+
noCheck,
|
|
116
|
+
needsSpecsChange,
|
|
117
|
+
danglingCommand: specs?.check_dangling_bdd_command ?? null,
|
|
118
|
+
nested,
|
|
119
|
+
});
|
|
120
|
+
if (dangling.kind === 'abort') {
|
|
121
|
+
throw new CliError(`close-out aborted: ${dangling.message}`);
|
|
105
122
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
123
|
+
if (dangling.kind === 'skip') return;
|
|
124
|
+
const danglingResult = makeCliHarnessRunner().run(dangling.command, ctx.root);
|
|
125
|
+
if (danglingResult.spawnError !== undefined || danglingResult.exitCode !== 0) {
|
|
126
|
+
const why = danglingResult.spawnError ?? `exit ${danglingResult.exitCode}`;
|
|
127
|
+
throw new CliError(`close-out aborted: dangling bdd check failed (${why})`);
|
|
110
128
|
}
|
|
111
129
|
}
|
|
112
130
|
|
|
@@ -129,12 +147,6 @@ function harvestIo(top: string): {
|
|
|
129
147
|
isDirectory: (p: string) => boolean;
|
|
130
148
|
} {
|
|
131
149
|
const at = (p: string): string => (isAbsolute(p) ? p : join(top, p));
|
|
132
|
-
// r109/r35: a linked worktree without the instance directory is "absent",
|
|
133
|
-
// not an error — an unguarded lstat/readdir would leak a bare `ENOENT:
|
|
134
|
-
// ... lstat '<worktree>/llmanspec'` and abort the whole harvest. Only
|
|
135
|
-
// absence stays silent: this adapter also serves the primary tree, and the
|
|
136
|
-
// core layer's warning channel (`cannot list <dir>`, r35) exists precisely
|
|
137
|
-
// for real read errors (EACCES, ELOOP), so those MUST propagate.
|
|
138
150
|
const isAbsent = (error: unknown): boolean => {
|
|
139
151
|
const code = (error as NodeJS.ErrnoException | null)?.code;
|
|
140
152
|
return code === 'ENOENT' || code === 'ENOTDIR';
|
|
@@ -183,8 +195,6 @@ function deriveNewId(ctx: CliContext, description: string, verb: string | undefi
|
|
|
183
195
|
const template = cliConfig?.change_id?.template;
|
|
184
196
|
if (template) {
|
|
185
197
|
const { verb: v, subject } = splitVerb(slug, verb);
|
|
186
|
-
// unify-numeric-id-allocation: the template variable consumes the same
|
|
187
|
-
// worktree-union collector as `change next-id` — one survey, one max+1.
|
|
188
198
|
return renderChangeIdTemplate(template, {
|
|
189
199
|
llman_sdd_unique_id: harvestForRoot(ctx).nextNumber,
|
|
190
200
|
verb: v,
|
|
@@ -199,10 +209,45 @@ function deriveNewId(ctx: CliContext, description: string, verb: string | undefi
|
|
|
199
209
|
return slug;
|
|
200
210
|
}
|
|
201
211
|
|
|
212
|
+
export async function enforceArchiveTheoremGate(
|
|
213
|
+
changed: readonly string[],
|
|
214
|
+
options: {
|
|
215
|
+
interactive?: boolean;
|
|
216
|
+
confirm?: (message: string) => Promise<boolean>;
|
|
217
|
+
/** Warning printer (tests inject a no-op); defaults to console.error. */
|
|
218
|
+
warn?: (line: string) => void;
|
|
219
|
+
} = {},
|
|
220
|
+
): Promise<void> {
|
|
221
|
+
if (changed.length === 0) return;
|
|
222
|
+
const list = changed.join(', ');
|
|
223
|
+
const interactive =
|
|
224
|
+
options.interactive ?? (process.stdin.isTTY === true && process.stdout.isTTY === true);
|
|
225
|
+
if (!interactive) {
|
|
226
|
+
throw new CliError(
|
|
227
|
+
`changes under \`${THEOREMS_DIR_REL}/\` detected relative to merge-base: ${list}. Agent workflows must not modify Human Theorems. Ask a human to review and commit theorem updates separately, or resolve the conflict before archiving.`,
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
const warn = options.warn ?? console.error;
|
|
231
|
+
warn(
|
|
232
|
+
`[WARNING] this archive carries \`${THEOREMS_DIR_REL}/\` changes relative to the merge base: ${list}`,
|
|
233
|
+
);
|
|
234
|
+
warn('Human Theorems are human-owned. Confirm only if you personally reviewed these changes.');
|
|
235
|
+
let confirmed: boolean;
|
|
236
|
+
try {
|
|
237
|
+
const confirm =
|
|
238
|
+
options.confirm ??
|
|
239
|
+
(async (message: string) => (await makeInquirerPromptPort()).confirm(message));
|
|
240
|
+
confirmed = await confirm('Archive anyway with these theorem changes?');
|
|
241
|
+
} catch (error) {
|
|
242
|
+
if (isPromptAborted(error)) confirmed = false;
|
|
243
|
+
else throw error;
|
|
244
|
+
}
|
|
245
|
+
if (!confirmed) throw new CliError('archive cancelled: theorem changes were not confirmed');
|
|
246
|
+
}
|
|
202
247
|
export function registerChange(program: Command, ctx: CliContext): void {
|
|
203
248
|
const change = program
|
|
204
249
|
.command('change')
|
|
205
|
-
.description('Change lifecycle: new / start /
|
|
250
|
+
.description('Change lifecycle: new / start / next-id / diff / archive');
|
|
206
251
|
|
|
207
252
|
const newCmd = change
|
|
208
253
|
.command('new')
|
|
@@ -227,8 +272,6 @@ export function registerChange(program: Command, ctx: CliContext): void {
|
|
|
227
272
|
if ((id === undefined) === (options.from === undefined)) {
|
|
228
273
|
throw new CliError('<CHANGE> and --from are mutually exclusive; pass one or the other');
|
|
229
274
|
}
|
|
230
|
-
// r118: the draft is created inside the nearest instance root, never in
|
|
231
|
-
// a cwd-literal `llmanspec/` (and an instance-less path is a domain error).
|
|
232
275
|
const rctx = reRootContext(ctx, options.directory);
|
|
233
276
|
if (options.dryRun) {
|
|
234
277
|
console.log(id ?? deriveNewId(rctx, options.from as string, options.verb));
|
|
@@ -239,16 +282,18 @@ export function registerChange(program: Command, ctx: CliContext): void {
|
|
|
239
282
|
console.log(`derived change id: ${derived}`);
|
|
240
283
|
const result = newChange(rctx.io, { id: derived, force: options.force });
|
|
241
284
|
console.log(`./${result.path}`);
|
|
285
|
+
emitCliHint(hintForChangeNew(derived), 'human');
|
|
242
286
|
return;
|
|
243
287
|
}
|
|
244
288
|
const result = newChange(rctx.io, { id, force: options.force });
|
|
245
289
|
console.log(`./${result.path}`);
|
|
290
|
+
emitCliHint(hintForChangeNew(id as string), 'human');
|
|
246
291
|
},
|
|
247
292
|
);
|
|
248
293
|
|
|
249
294
|
const startCmd = change
|
|
250
295
|
.command('start')
|
|
251
|
-
.description('
|
|
296
|
+
.description('Create sdd/<id> on the default branch, or bind the current feature branch')
|
|
252
297
|
.argument('<id>')
|
|
253
298
|
.option(
|
|
254
299
|
'--branch-prefix <prefix>',
|
|
@@ -256,8 +301,9 @@ export function registerChange(program: Command, ctx: CliContext): void {
|
|
|
256
301
|
)
|
|
257
302
|
.option(
|
|
258
303
|
'--base <branch>',
|
|
259
|
-
'explicit fork-source branch to record (must be an existing local branch
|
|
304
|
+
'explicit fork-source branch to record (must be an existing local branch)',
|
|
260
305
|
)
|
|
306
|
+
.option('--force', 'rebind an already attached change to the current branch')
|
|
261
307
|
.option(
|
|
262
308
|
'--worktree',
|
|
263
309
|
'create the branch in a dedicated worktree (sdd.worktree_root / sdd.worktree_naming config) instead of switching this checkout',
|
|
@@ -266,7 +312,13 @@ export function registerChange(program: Command, ctx: CliContext): void {
|
|
|
266
312
|
startCmd.action(
|
|
267
313
|
(
|
|
268
314
|
id: string,
|
|
269
|
-
options: {
|
|
315
|
+
options: {
|
|
316
|
+
branchPrefix?: string;
|
|
317
|
+
base?: string;
|
|
318
|
+
force?: boolean;
|
|
319
|
+
worktree?: boolean;
|
|
320
|
+
directory?: string;
|
|
321
|
+
},
|
|
270
322
|
) => {
|
|
271
323
|
const rctx = reRootContext(ctx, options.directory);
|
|
272
324
|
const resolved = resolveChangeIdOrExit(rctx, program, id);
|
|
@@ -275,11 +327,10 @@ export function registerChange(program: Command, ctx: CliContext): void {
|
|
|
275
327
|
const result = startChange(git, rctx.io, resolved.id, {
|
|
276
328
|
branchPrefix: options.branchPrefix ?? config?.sdd?.branch_prefix ?? 'sdd/',
|
|
277
329
|
base: options.base,
|
|
330
|
+
force: options.force,
|
|
278
331
|
worktree: options.worktree,
|
|
279
332
|
worktreeRoot: config?.sdd?.worktree_root ?? undefined,
|
|
280
333
|
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
334
|
instanceDirRel: instanceDirRelFor(rctx),
|
|
284
335
|
});
|
|
285
336
|
warnBaseBranchDeviation(git, result);
|
|
@@ -287,32 +338,7 @@ export function registerChange(program: Command, ctx: CliContext): void {
|
|
|
287
338
|
`started change \`${resolved.id}\` → branch \`${result.branch}\` base \`${result.baseSha}\` base-branch \`${result.baseBranch}\``,
|
|
288
339
|
);
|
|
289
340
|
if (result.worktreePath !== undefined) console.log(`worktree ${result.worktreePath}`);
|
|
290
|
-
|
|
291
|
-
);
|
|
292
|
-
|
|
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
|
-
);
|
|
341
|
+
emitCliHint(hintForChangeStart(resolved.id), 'human');
|
|
316
342
|
},
|
|
317
343
|
);
|
|
318
344
|
|
|
@@ -323,14 +349,8 @@ export function registerChange(program: Command, ctx: CliContext): void {
|
|
|
323
349
|
addSpecDirOption(nextId);
|
|
324
350
|
nextId.action(
|
|
325
351
|
(options: { json?: boolean; output?: string; compactJson?: boolean; directory?: string }) => {
|
|
326
|
-
// r35/r118: the scan covers the resolved instance tree plus every linked
|
|
327
|
-
// git worktree's own copy of it (degrades to the current tree when
|
|
328
|
-
// worktree list fails).
|
|
329
352
|
const rctx = reRootContext(ctx, options.directory);
|
|
330
353
|
const harvest = harvestForRoot(rctx);
|
|
331
|
-
// r35: the human face is exactly the two legacy lines (bare default and
|
|
332
|
-
// explicit `--output human`); machine modes render the harvest IR through
|
|
333
|
-
// the shared pipeline.
|
|
334
354
|
const human = (): string => {
|
|
335
355
|
const lines: string[] = [];
|
|
336
356
|
if (harvest.maxNumber === null) lines.push('no numbered change dirs found in tree');
|
|
@@ -348,23 +368,26 @@ export function registerChange(program: Command, ctx: CliContext): void {
|
|
|
348
368
|
|
|
349
369
|
const archiveCmd = change
|
|
350
370
|
.command('archive')
|
|
351
|
-
.description(
|
|
352
|
-
'Independent seal-off: task gates + merge + archive rename + commit (cold backup: `llman-sdd archive freeze`)',
|
|
353
|
-
)
|
|
371
|
+
.description('Validate, merge the feature branch, archive docs, and close out')
|
|
354
372
|
.argument('<id>')
|
|
355
|
-
.option('--into <branch>', 'target
|
|
356
|
-
.option(
|
|
357
|
-
|
|
358
|
-
|
|
373
|
+
.option('--into <branch>', 'merge target override (defaults to base_branch)')
|
|
374
|
+
.option(
|
|
375
|
+
'--method <method>',
|
|
376
|
+
'merge method: squash | ff (default: sdd.merge_method config, then squash)',
|
|
377
|
+
)
|
|
378
|
+
.option('--no-check', 'skip the pre-merge validation sweep')
|
|
379
|
+
.option('--no-commit', 'skip the close-out commit (manual/CI history)')
|
|
380
|
+
.option('--dry-run', 'print the rename plan only');
|
|
359
381
|
addSpecDirOption(archiveCmd);
|
|
360
382
|
archiveCmd.action(
|
|
361
|
-
(
|
|
383
|
+
async (
|
|
362
384
|
id: string,
|
|
363
385
|
options: {
|
|
364
386
|
into?: string;
|
|
365
387
|
method?: string;
|
|
388
|
+
check?: boolean;
|
|
389
|
+
commit?: boolean;
|
|
366
390
|
dryRun?: boolean;
|
|
367
|
-
force?: boolean;
|
|
368
391
|
directory?: string;
|
|
369
392
|
},
|
|
370
393
|
) => {
|
|
@@ -372,7 +395,6 @@ export function registerChange(program: Command, ctx: CliContext): void {
|
|
|
372
395
|
const rctx = reRootContext(ctx, options.directory);
|
|
373
396
|
const resolved = resolveChangeIdOrExit(rctx, program, id);
|
|
374
397
|
id = resolved.id;
|
|
375
|
-
const io = rctx.io;
|
|
376
398
|
if (options.dryRun) {
|
|
377
399
|
const date = new Date().toISOString().slice(0, 10);
|
|
378
400
|
console.log(
|
|
@@ -380,46 +402,52 @@ export function registerChange(program: Command, ctx: CliContext): void {
|
|
|
380
402
|
);
|
|
381
403
|
return;
|
|
382
404
|
}
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
if (
|
|
386
|
-
|
|
387
|
-
const
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
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
|
-
}
|
|
405
|
+
const tasksPath = `llmanspec/changes/${id}/tasks.md`;
|
|
406
|
+
const gate = archiveTaskGate(rctx.io.exists(tasksPath) ? rctx.io.readText(tasksPath) : null);
|
|
407
|
+
if (gate.blocked) {
|
|
408
|
+
console.error(`Archive blocked: ${gate.pendingLines.length} unchecked task(s).`);
|
|
409
|
+
for (const line of gate.pendingLines) {
|
|
410
|
+
console.error(` - [ ] ${line.replace(/^-\s+\[ \]\s*/u, '').trim()}`);
|
|
411
|
+
}
|
|
412
|
+
const closeOut = closeOutTaskLines(gate.pendingLines);
|
|
413
|
+
if (closeOut.length > 0) {
|
|
400
414
|
console.error(
|
|
401
|
-
|
|
415
|
+
` task "${closeOut[0]?.replace(/^-\s+\[ \]\s*/u, '').trim() ?? ''}" looks like a close-out step; ${CLOSE_OUT_TASK_HINT}`,
|
|
402
416
|
);
|
|
403
|
-
throw new Error('archive blocked by unchecked tasks');
|
|
404
417
|
}
|
|
405
|
-
|
|
406
|
-
|
|
418
|
+
throw new CliError('archive blocked by unchecked tasks');
|
|
419
|
+
}
|
|
420
|
+
if (options.check !== false) {
|
|
421
|
+
const failed = runValidateSweep(rctx);
|
|
422
|
+
if (failed) {
|
|
423
|
+
throw new CliError('archive aborted: validation sweep failed (use --no-check to skip)');
|
|
407
424
|
}
|
|
425
|
+
await enforceArchiveTheoremGate(changedTheoremFiles(rctx, undefined));
|
|
426
|
+
}
|
|
427
|
+
if (!isCleanTree(ctx.git)) {
|
|
428
|
+
throw new CliError('`change archive` requires a clean working tree');
|
|
408
429
|
}
|
|
409
|
-
enforceCloseOutHarness(rctx, id, false);
|
|
410
|
-
const
|
|
430
|
+
enforceCloseOutHarness(rctx, id, options.check === false);
|
|
431
|
+
const config = loadCliConfig(rctx.root);
|
|
432
|
+
const method = options.method ?? config?.sdd?.merge_method ?? 'squash';
|
|
433
|
+
const result = archiveChange(ctx.git, rctx.io, id, {
|
|
411
434
|
into: options.into,
|
|
412
|
-
method:
|
|
413
|
-
force: options.force,
|
|
435
|
+
method: method as 'squash' | 'ff',
|
|
414
436
|
skipCleanTree: true,
|
|
415
437
|
today: new Date().toISOString().slice(0, 10),
|
|
416
|
-
|
|
438
|
+
noCommit: options.commit === false,
|
|
417
439
|
specsPrefix: specsPrefixFor(rctx),
|
|
418
440
|
});
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
441
|
+
for (const w of result.warnings) console.error(`[WARNING] ${w}`);
|
|
442
|
+
if (options.commit === false) {
|
|
443
|
+
console.log(
|
|
444
|
+
`archived \`${id}\` → ${result.archiveDir} on ${result.target} (close-out commit skipped — run: git add -A && git commit -m "archive(sdd): ${id}")`,
|
|
445
|
+
);
|
|
446
|
+
} else {
|
|
447
|
+
console.log(
|
|
448
|
+
`archived \`${id}\` → ${result.archiveDir} (commit "${result.commitSubject}" on ${result.target})`,
|
|
449
|
+
);
|
|
450
|
+
}
|
|
423
451
|
if (result.executedIn !== null) {
|
|
424
452
|
console.log(`executed in target worktree ${result.executedIn}`);
|
|
425
453
|
}
|
|
@@ -452,10 +480,6 @@ export function registerChange(program: Command, ctx: CliContext): void {
|
|
|
452
480
|
const git = ctx.git;
|
|
453
481
|
const diff = changeDiff(git, rctx.io, id);
|
|
454
482
|
if (options.exportPatch !== undefined) {
|
|
455
|
-
// writeText creates parent dirs — exporting into a fresh path like
|
|
456
|
-
// out/change.patch must not ENOENT. Export wins over any output mode.
|
|
457
|
-
// r116 exemption: the export path is a user-supplied argument and keeps
|
|
458
|
-
// its cwd-literal meaning.
|
|
459
483
|
ctx.io.writeText(options.exportPatch, diff);
|
|
460
484
|
console.log(`wrote ${options.exportPatch}`);
|
|
461
485
|
return;
|
|
@@ -464,72 +488,8 @@ export function registerChange(program: Command, ctx: CliContext): void {
|
|
|
464
488
|
emitReport(changeDiffInfo(git, rctx.io, id), options);
|
|
465
489
|
return;
|
|
466
490
|
}
|
|
467
|
-
// T37: an empty diff says so instead of printing nothing.
|
|
468
491
|
if (diff.trim() === '') console.log('no differences against the base (empty diff)');
|
|
469
492
|
else console.log(diff);
|
|
470
493
|
},
|
|
471
494
|
);
|
|
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
495
|
}
|
package/src/commands/config.ts
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
|
|
4
|
-
import { renderConfigOverview
|
|
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
|
}
|
package/src/commands/init.ts
CHANGED
|
@@ -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,25 +40,50 @@ 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: {
|
|
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
|
+
const result = checkSkillVersions(skills, version);
|
|
79
|
+
if (!result.ok) throw new CliError(result.message, 1);
|
|
80
|
+
console.log(result.message);
|
|
81
|
+
return;
|
|
54
82
|
}
|
|
55
83
|
const io = makeIo(root);
|
|
56
84
|
const warn = (message: string): void => {
|
|
57
85
|
console.error(message);
|
|
58
86
|
};
|
|
59
|
-
// r106 new-instance notice: creating a fresh instance below an existing
|
|
60
|
-
// one is legal (r93 逐根构造) but usually a cwd mistake — surface both.
|
|
61
87
|
if (!isValidRoot(join(root, 'llmanspec'), io)) {
|
|
62
88
|
const ancestor = resolveInstanceRoot(root, io);
|
|
63
89
|
if (ancestor !== null) {
|
|
@@ -67,21 +93,17 @@ export function registerInit(program: Command, _ctx: CliContext): void {
|
|
|
67
93
|
}
|
|
68
94
|
}
|
|
69
95
|
const repoRootInstance = isRepoRootInstance(root);
|
|
70
|
-
// 模板生成/子根扫块可能耗时 — 进度提示防止看上去卡住(B1)
|
|
71
96
|
progressNote('init.generate', root);
|
|
72
97
|
const result = runInit(io, templateIo, {
|
|
73
98
|
update: options.update ?? false,
|
|
74
99
|
locale: options.locale ?? options.lang,
|
|
75
100
|
version,
|
|
76
101
|
skills: options.skills === true || repoRootInstance,
|
|
102
|
+
uncomment: repoRootInstance,
|
|
77
103
|
onWarning: warn,
|
|
78
104
|
});
|
|
79
105
|
let swept = '';
|
|
80
106
|
if (options.update ?? false) {
|
|
81
|
-
// r93 --update sweep, per-workspace from any instance root: refresh
|
|
82
|
-
// managed blocks of every root discovered from the repo toplevel
|
|
83
|
-
// (outside a repo: from the target). Blocks only; skills stay a
|
|
84
|
-
// repo-root surface.
|
|
85
107
|
const toplevel = makeCliGit(root).runOpt(['rev-parse', '--show-toplevel']);
|
|
86
108
|
const sweepStart = toplevel !== null ? resolve(toplevel) : root;
|
|
87
109
|
const subRoots = discoverRoots(sweepStart, makeIo(sweepStart)).filter(
|
|
@@ -96,7 +118,13 @@ export function registerInit(program: Command, _ctx: CliContext): void {
|
|
|
96
118
|
if (refreshed.length > 0) swept = `, blocks refreshed: ${refreshed.join(', ')}`;
|
|
97
119
|
}
|
|
98
120
|
const removed = result.removed.length > 0 ? `, removed: ${result.removed.join(', ')}` : '';
|
|
99
|
-
|
|
121
|
+
const uncommentNote =
|
|
122
|
+
result.uncomment?.changed === true
|
|
123
|
+
? `, ${result.uncomment.path} patched (+${String(result.uncomment.addedPreserve.length)} preserve, +${String(result.uncomment.addedExclude.length)} exclude)`
|
|
124
|
+
: '';
|
|
125
|
+
console.log(
|
|
126
|
+
`initialized llmanspec (${result.skills.length} skills${removed}${swept}${uncommentNote})`,
|
|
127
|
+
);
|
|
100
128
|
},
|
|
101
129
|
);
|
|
102
130
|
}
|
package/src/commands/list.ts
CHANGED
|
@@ -43,8 +43,6 @@ export function registerList(program: Command, ctx: CliContext): void {
|
|
|
43
43
|
if (options.sort !== undefined && options.sort !== 'recent' && options.sort !== 'name') {
|
|
44
44
|
throw new CliError(`invalid --sort: ${options.sort}`, 2);
|
|
45
45
|
}
|
|
46
|
-
// T18/T30: shared pipeline; compact is the single-point minified
|
|
47
|
-
// JSON.stringify (r76) — no per-command newline stripping.
|
|
48
46
|
const mode = resolveOutMode(options.output, options.json, options.compactJson);
|
|
49
47
|
const emit = (text: string): void => {
|
|
50
48
|
console.log(text);
|