@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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@llman-sdd/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.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.
|
|
30
|
+
"@llman-sdd/core": "0.10.0",
|
|
31
31
|
"commander": "^15.0.0"
|
|
32
32
|
},
|
|
33
33
|
"engines": {
|
package/src/cli-shared.ts
CHANGED
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
* readers, change-id resolution, output-mode helpers and misc constants.
|
|
4
4
|
* Command modules depend one-way on this file; it must not import any of them.
|
|
5
5
|
*/
|
|
6
|
+
import { spawnSync } from 'node:child_process';
|
|
6
7
|
import { existsSync, readFileSync } from 'node:fs';
|
|
7
|
-
import { join } from 'node:path';
|
|
8
|
+
import { isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
8
9
|
|
|
9
10
|
import {
|
|
10
11
|
discoverSpecs,
|
|
@@ -15,18 +16,38 @@ import {
|
|
|
15
16
|
readSddState,
|
|
16
17
|
resolveChangeId,
|
|
17
18
|
resolveInstanceRoot,
|
|
19
|
+
renderMachine,
|
|
18
20
|
semverLt,
|
|
21
|
+
specsPrefixOfInstance,
|
|
19
22
|
type TemplateIo,
|
|
20
23
|
} from '@llman-sdd/core';
|
|
21
24
|
import type { Command } from 'commander';
|
|
22
25
|
|
|
23
26
|
import pkg from '../package.json' with { type: 'json' };
|
|
24
|
-
import { makeIo } from './io.ts';
|
|
27
|
+
import { makeCliGit, makeIo } from './io.ts';
|
|
25
28
|
|
|
26
29
|
// Re-exported so leaf consumers (e.g. regression gates under tests/) can type
|
|
27
30
|
// against the commander surface without resolving 'commander' themselves.
|
|
28
31
|
export type { Command } from 'commander';
|
|
29
32
|
|
|
33
|
+
/**
|
|
34
|
+
* T21 CliContext (cli r108): the per-run resolution injected into every
|
|
35
|
+
* registerXxx — terminal IO, git port, instance root and working directory.
|
|
36
|
+
* Constructed once by `makeCliContext` at assembly time; command bodies take
|
|
37
|
+
* io/git/root from here instead of reading process state ad hoc.
|
|
38
|
+
*/
|
|
39
|
+
export interface CliContext {
|
|
40
|
+
io: ReturnType<typeof makeIo>;
|
|
41
|
+
git: ReturnType<typeof makeCliGit>;
|
|
42
|
+
root: string;
|
|
43
|
+
cwd: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Build the run context for `cwd` (defaults to the launch directory). */
|
|
47
|
+
export function makeCliContext(cwd: string = process.cwd()): CliContext {
|
|
48
|
+
return { io: makeIo(cwd), git: makeCliGit(cwd), root: cwd, cwd };
|
|
49
|
+
}
|
|
50
|
+
|
|
30
51
|
// Version SSOT is this package's package.json (inlined at compile time — a
|
|
31
52
|
// single-file binary has no on-disk package.json to read); binary builds
|
|
32
53
|
// additionally override it through the LLMAN_SDD_VERSION define injected by
|
|
@@ -45,22 +66,20 @@ const baseVersion = process.env.LLMAN_SDD_VERSION ?? pkg.version;
|
|
|
45
66
|
let dirtySuffix: string | null | undefined;
|
|
46
67
|
|
|
47
68
|
function computeDirtySuffix(): string {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
return '';
|
|
63
|
-
}
|
|
69
|
+
// Dual-runtime surface: `node:child_process.spawnSync` (not `Bun.spawnSync`).
|
|
70
|
+
// It reports a missing git binary through `error` and a non-zero exit through
|
|
71
|
+
// `status` instead of throwing, so the degradation is explicit — a wide catch
|
|
72
|
+
// around this block would also swallow ReferenceError from the parsing below.
|
|
73
|
+
const probe = spawnSync('git', ['status', '--porcelain'], {
|
|
74
|
+
cwd: import.meta.dirname,
|
|
75
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
76
|
+
});
|
|
77
|
+
if (probe.error !== undefined || probe.status !== 0) return '';
|
|
78
|
+
const lines = (probe.stdout?.toString() ?? '')
|
|
79
|
+
.split('\n')
|
|
80
|
+
.map((l) => l.trim())
|
|
81
|
+
.filter((l) => l !== '');
|
|
82
|
+
return lines.length > 0 ? `+dirty.${lines.length}` : '';
|
|
64
83
|
}
|
|
65
84
|
|
|
66
85
|
export function versionDisplay(): string {
|
|
@@ -109,29 +128,46 @@ export function exitWith(code: number): void {
|
|
|
109
128
|
process.exitCode = code;
|
|
110
129
|
}
|
|
111
130
|
|
|
112
|
-
/** Parse all capability specs under llmanspec/specs via core discovery. */
|
|
113
|
-
export function loadSpecEntries(): ReturnType<typeof discoverSpecs> {
|
|
114
|
-
return discoverSpecs('llmanspec/specs', newIo());
|
|
115
|
-
}
|
|
116
|
-
|
|
117
131
|
/**
|
|
118
132
|
* Per-root specs dir (r94): the nearest llmanspec/ instance at or above the
|
|
119
133
|
* start dir (--directory override). Identity 'llmanspec/specs' when the cwd
|
|
120
134
|
* is itself the instance root — legacy relative output paths stay
|
|
121
135
|
* byte-identical there.
|
|
122
136
|
*/
|
|
123
|
-
export function resolveRootSpecsDir(
|
|
124
|
-
|
|
125
|
-
|
|
137
|
+
export function resolveRootSpecsDir(
|
|
138
|
+
directory?: string,
|
|
139
|
+
io: ReturnType<typeof makeIo> = newIo(),
|
|
140
|
+
): string {
|
|
141
|
+
// r115: the default start is the io's own anchor, NOT the ambient cwd — a
|
|
142
|
+
// re-rooted io (reRootContext) must discover its own instance, otherwise
|
|
143
|
+
// every re-rooted read silently falls back to the launch directory.
|
|
144
|
+
const start = directory ?? io.root;
|
|
145
|
+
const root = resolveInstanceRoot(start, io);
|
|
126
146
|
if (root === null) {
|
|
127
|
-
throw new CliError(`no
|
|
147
|
+
throw new CliError(`no llmanspec root at or above: ${start}`);
|
|
128
148
|
}
|
|
129
|
-
|
|
149
|
+
// r115: the legacy relative identity is only valid when the resolved
|
|
150
|
+
// instance IS this io's own anchor (the single-root default) — there the
|
|
151
|
+
// returned path means `llmanspec/specs` relative to that very anchor, never
|
|
152
|
+
// to the ambient cwd. Every other instance is addressed absolutely, so a
|
|
153
|
+
// caller consuming the result with its own io cannot re-join a
|
|
154
|
+
// launch-relative path into a non-existent directory (which would silently
|
|
155
|
+
// empty the registry and turn a red gate green).
|
|
156
|
+
const absolute = isAbsolute(root) ? root : resolve(io.root, root);
|
|
157
|
+
return sameDir(absolute, io.root) ? 'llmanspec/specs' : join(absolute, 'llmanspec', 'specs');
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** Path identity by absolute resolution (`a` and `b` denote the same directory). */
|
|
161
|
+
function sameDir(a: string, b: string): boolean {
|
|
162
|
+
return resolve(a) === resolve(b);
|
|
130
163
|
}
|
|
131
164
|
|
|
132
165
|
/** Spec entries of the resolved instance root (per-root registry, r94). */
|
|
133
|
-
export function loadRootSpecEntries(
|
|
134
|
-
|
|
166
|
+
export function loadRootSpecEntries(
|
|
167
|
+
directory?: string,
|
|
168
|
+
io: ReturnType<typeof makeIo> = newIo(),
|
|
169
|
+
): ReturnType<typeof discoverSpecs> {
|
|
170
|
+
return discoverSpecs(resolveRootSpecsDir(directory, io), io);
|
|
135
171
|
}
|
|
136
172
|
|
|
137
173
|
/** One-time legacy `bdd:` migration warning — printed to stderr by the first
|
|
@@ -187,12 +223,13 @@ export function noteVersionDriftOnce(root: string = process.cwd()): void {
|
|
|
187
223
|
);
|
|
188
224
|
}
|
|
189
225
|
|
|
190
|
-
export function loadCliConfig(): ReturnType<typeof loadConfig> | null {
|
|
191
|
-
|
|
192
|
-
|
|
226
|
+
export function loadCliConfig(root: string = process.cwd()): ReturnType<typeof loadConfig> | null {
|
|
227
|
+
const configPath = join(root, 'llmanspec', 'config.yaml');
|
|
228
|
+
if (!existsSync(configPath)) return null;
|
|
229
|
+
const detail = loadConfigDetail(readFileSync(configPath, 'utf8'));
|
|
193
230
|
warnLegacyBdd(detail.legacyBddElevated);
|
|
194
231
|
warnLegacyCheckTransitions(detail.legacyCheckTransitionsStripped);
|
|
195
|
-
noteVersionDriftOnce();
|
|
232
|
+
if (root === process.cwd()) noteVersionDriftOnce();
|
|
196
233
|
return detail.config;
|
|
197
234
|
}
|
|
198
235
|
|
|
@@ -211,11 +248,12 @@ export function cliMaxScanDepth(program: Command): number {
|
|
|
211
248
|
* unified exit renders the single `Error: <message>` line and exit code 1).
|
|
212
249
|
*/
|
|
213
250
|
export function resolveChangeIdOrExit(
|
|
251
|
+
ctx: CliContext,
|
|
214
252
|
program: Command,
|
|
215
253
|
input: string,
|
|
216
254
|
opts: { suppressHint?: boolean } = {},
|
|
217
255
|
): { id: string; viaPrefix: boolean } {
|
|
218
|
-
const resolved = resolveChangeId(
|
|
256
|
+
const resolved = resolveChangeId(ctx.io, ctx.root, input, {
|
|
219
257
|
maxScanDepth: cliMaxScanDepth(program),
|
|
220
258
|
});
|
|
221
259
|
if (resolved.viaPrefix && opts.suppressHint !== true) {
|
|
@@ -240,7 +278,10 @@ export function addReportOutputOptions(cmd: Command, opts: { outputHint?: string
|
|
|
240
278
|
opts.outputHint ?? 'report format: toon (default) | json | compact-json | human',
|
|
241
279
|
)
|
|
242
280
|
.option('--json', 'emit structured JSON (v1 compatibility alias)')
|
|
243
|
-
.option(
|
|
281
|
+
.option(
|
|
282
|
+
'--compact-json',
|
|
283
|
+
'single-line JSON alias; must pair with --json (not with --output toon|human)',
|
|
284
|
+
);
|
|
244
285
|
}
|
|
245
286
|
|
|
246
287
|
/**
|
|
@@ -275,11 +316,15 @@ export function assertCompactJsonPairing(options: {
|
|
|
275
316
|
compactJson?: boolean;
|
|
276
317
|
json?: boolean;
|
|
277
318
|
output?: string;
|
|
278
|
-
}):
|
|
279
|
-
|
|
280
|
-
|
|
319
|
+
}): void {
|
|
320
|
+
// r76: `--compact-json` is a pairing modifier of `--json`. Standalone use is
|
|
321
|
+
// rejected; combining with an explicit `--output toon|human` is ambiguous
|
|
322
|
+
// (two modes requested) and equally a usage error.
|
|
323
|
+
if (options.compactJson === true && options.json !== true) {
|
|
324
|
+
if (options.output === undefined || options.output === 'toon' || options.output === 'human') {
|
|
325
|
+
throw new CliError('--compact-json requires --json', 2);
|
|
326
|
+
}
|
|
281
327
|
}
|
|
282
|
-
return true;
|
|
283
328
|
}
|
|
284
329
|
|
|
285
330
|
export const SKILL_DESCRIPTIONS: Record<string, string> = {
|
|
@@ -293,14 +338,123 @@ export const SKILL_DESCRIPTIONS: Record<string, string> = {
|
|
|
293
338
|
export const skillDesc = (name: string): string => SKILL_DESCRIPTIONS[name] ?? '';
|
|
294
339
|
|
|
295
340
|
export function resolveBackend(flag: string | undefined): 'pageindex' {
|
|
296
|
-
|
|
341
|
+
// r57 normalization: trim, lowercase, `page-index` alias; blank values
|
|
342
|
+
// (unset flag / empty env) collapse to the pageindex default.
|
|
343
|
+
const raw = flag ?? process.env.LLMAN_SDD_INDEX_BACKEND ?? '';
|
|
344
|
+
const chosen = raw.trim() === '' ? 'pageindex' : raw.trim().toLowerCase();
|
|
297
345
|
if (chosen === 'rag') {
|
|
298
346
|
throw new Error(
|
|
299
347
|
'Backend `rag` is no longer supported. Use the default pageindex backend instead:\nSet `LLMAN_SDD_INDEX_CHAT_MODEL` to a tool-calling chat model, then\nrun `llman-sdd index rebuild`.',
|
|
300
348
|
);
|
|
301
349
|
}
|
|
302
|
-
|
|
350
|
+
const normalized = chosen === 'page-index' ? 'pageindex' : chosen;
|
|
351
|
+
if (normalized !== 'pageindex') {
|
|
303
352
|
throw new Error(`Unsupported backend: ${chosen}`);
|
|
304
353
|
}
|
|
305
354
|
return 'pageindex';
|
|
306
355
|
}
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* Tolerant specs-dir half of the root fork (show gates trailer): bare
|
|
359
|
+
* changes-only workspaces have no resolvable instance root; there the legacy
|
|
360
|
+
* relative identity is kept so discovery yields an empty set (predecessor
|
|
361
|
+
* behavior) instead of failing the change path.
|
|
362
|
+
*
|
|
363
|
+
* r115: the dir is derived from the ALREADY re-anchored context alone. The
|
|
364
|
+
* resolved instance root decides the registry, so the two output faces of one
|
|
365
|
+
* command cannot disagree; re-resolving `--directory` from the launch context
|
|
366
|
+
* would return a launch-relative path that the re-anchored io re-joins into a
|
|
367
|
+
* non-existent directory, silently emptying the gate.
|
|
368
|
+
*/
|
|
369
|
+
export function resolveRootSpecsDirTolerant(ctx: CliContext): string {
|
|
370
|
+
try {
|
|
371
|
+
return resolveRootSpecsDir(undefined, ctx.io);
|
|
372
|
+
} catch {
|
|
373
|
+
return 'llmanspec/specs';
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* r115/r116/r118: re-root a command context onto the resolved instance root.
|
|
379
|
+
* Start = `--directory` when given, else the launch root, through the shared
|
|
380
|
+
* operator (nearest valid instance at or above it). The returned io/git are
|
|
381
|
+
* anchored at that root, so root-relative read AND write paths (e.g. the
|
|
382
|
+
* `llmanspec/.context` index store) stay inside the resolved instance instead
|
|
383
|
+
* of the launch directory. When the launch directory already is the instance
|
|
384
|
+
* — every single-root invocation — the original context is returned untouched,
|
|
385
|
+
* so byte parity holds by construction.
|
|
386
|
+
*/
|
|
387
|
+
export function reRootContext(ctx: CliContext, directory?: string): CliContext {
|
|
388
|
+
const resolved = resolveCommandRoot(ctx, directory);
|
|
389
|
+
const root = isAbsolute(resolved) ? resolved : resolve(ctx.cwd, resolved);
|
|
390
|
+
if (root === ctx.root) return ctx;
|
|
391
|
+
return { io: makeIo(root), git: makeCliGit(root), root, cwd: ctx.cwd };
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* r108/r109: the single root-resolution operator. Start = `--directory` when
|
|
396
|
+
* given, else the launch root; resolves the nearest instance at or above it
|
|
397
|
+
* (the launch root itself when it already is one — single-root byte parity).
|
|
398
|
+
* Throws the shared domain error when no instance exists at or above start.
|
|
399
|
+
*/
|
|
400
|
+
export function resolveCommandRoot(ctx: CliContext, directory?: string): string {
|
|
401
|
+
// r109/r115: the start is absolutized at this CLI boundary — a relative
|
|
402
|
+
// `--directory` (`packages`, `..`, `.`) is relative to the process cwd, and
|
|
403
|
+
// the core walk-up cannot climb above a single-segment relative name (its
|
|
404
|
+
// parent is the empty string, which terminates the walk). The returned root
|
|
405
|
+
// is therefore always absolute, so every downstream path/io join stays
|
|
406
|
+
// single-anchored. The error keeps the user's own spelling of the start.
|
|
407
|
+
const given = directory ?? ctx.root;
|
|
408
|
+
const root = resolveInstanceRoot(resolve(given), ctx.io);
|
|
409
|
+
if (root === null) throw new CliError(`no llmanspec root at or above: ${given}`);
|
|
410
|
+
return root;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* r109: the shared `--directory <path>` instance-root override, one declared
|
|
415
|
+
* surface mounted on every command that resolves a root.
|
|
416
|
+
*/
|
|
417
|
+
export function addSpecDirOption(cmd: Command): void {
|
|
418
|
+
cmd.option(
|
|
419
|
+
'--directory <path>',
|
|
420
|
+
'instance root resolution start (default: nearest llmanspec/ at or above cwd)',
|
|
421
|
+
);
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* r119: the specs-landed prefix for ctx's instance root — the same
|
|
426
|
+
* git-toplevel-relative derivation as the r118 number harvest
|
|
427
|
+
* (`harvestForRoot`), so the close-out gate and the harvest can never
|
|
428
|
+
* disagree about which `llmanspec/` tree a change belongs to. Forward slashes
|
|
429
|
+
* always: git diff --name-only emits them on every platform.
|
|
430
|
+
*/
|
|
431
|
+
export function instanceDirRelFor(ctx: CliContext): string {
|
|
432
|
+
const top = ctx.git.runOpt(['rev-parse', '--show-toplevel']) ?? ctx.root;
|
|
433
|
+
return relative(top, resolve(ctx.root)).split(sep).join('/');
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
export function specsPrefixFor(ctx: CliContext): string {
|
|
437
|
+
return specsPrefixOfInstance(instanceDirRelFor(ctx));
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* T18 emitReport (design 2.2): the single output pipeline for report commands
|
|
442
|
+
* — pairing guard, out-mode resolution, machine render, human fallback. The
|
|
443
|
+
* machine branch always `console.log`s the rendered payload; `humanFn` (when
|
|
444
|
+
* given) produces the human text instead. Byte-for-byte identical to the
|
|
445
|
+
* per-command logic it replaces.
|
|
446
|
+
*/
|
|
447
|
+
export function emitReport(
|
|
448
|
+
ir: unknown,
|
|
449
|
+
options: { output?: string; json?: boolean; compactJson?: boolean },
|
|
450
|
+
humanFn?: () => string,
|
|
451
|
+
): void {
|
|
452
|
+
assertCompactJsonPairing(options);
|
|
453
|
+
const mode = resolveOutMode(options.output, options.json, options.compactJson);
|
|
454
|
+
if (mode === 'human') {
|
|
455
|
+
if (humanFn === undefined) throw new CliError('human renderer missing for human mode', 2);
|
|
456
|
+
console.log(humanFn());
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
console.log(renderMachine(ir, mode));
|
|
460
|
+
}
|
package/src/commands/archive.ts
CHANGED
|
@@ -12,16 +12,16 @@ import {
|
|
|
12
12
|
} from '@llman-sdd/core';
|
|
13
13
|
import type { Command } from 'commander';
|
|
14
14
|
|
|
15
|
-
import {
|
|
16
|
-
import { makeCliGit
|
|
15
|
+
import { addSpecDirOption, reRootContext, type CliContext } from '../cli-shared.ts';
|
|
16
|
+
import { makeCliGit } from '../io.ts';
|
|
17
17
|
import { progressNote } from '../progress.ts';
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* r24: warn (never block) when freeze/thaw runs outside the main checkout —
|
|
21
21
|
* the worktree NOT holding the default branch. Probe failures skip silently.
|
|
22
22
|
*/
|
|
23
|
-
function warnIfNotMainCheckout(
|
|
24
|
-
const warning = nonMainCheckoutWarning(probeMainCheckout(
|
|
23
|
+
function warnIfNotMainCheckout(git: ReturnType<typeof makeCliGit>): void {
|
|
24
|
+
const warning = nonMainCheckoutWarning(probeMainCheckout(git));
|
|
25
25
|
if (warning !== null) console.log(warning);
|
|
26
26
|
}
|
|
27
27
|
|
|
@@ -40,53 +40,52 @@ function makeEmbeddedSevenZip(): Promise<SevenZipPort> {
|
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
export function registerArchive(program: Command): void {
|
|
43
|
+
export function registerArchive(program: Command, ctx: CliContext): void {
|
|
44
44
|
const archive = program
|
|
45
45
|
.command('archive')
|
|
46
46
|
.description(
|
|
47
|
-
'Archive workflow commands (cold backup).
|
|
47
|
+
'Archive workflow commands (cold backup). Seal a change with `llman-sdd change finalize` first',
|
|
48
48
|
);
|
|
49
49
|
|
|
50
|
-
archive
|
|
50
|
+
const freeze = archive
|
|
51
51
|
.command('freeze')
|
|
52
52
|
.description('Freeze dated archived changes into a single 7z cold backup')
|
|
53
53
|
.option('--before <date>', 'freeze entries older than this date (YYYY-MM-DD)')
|
|
54
54
|
.option('--keep-recent <n>', 'keep N most recent candidates unfrozen', '0')
|
|
55
55
|
.option('--dry-run', 'list candidates without freezing')
|
|
56
|
-
.option('--list', 'list entries already in the cold-backup archive')
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
);
|
|
56
|
+
.option('--list', 'list entries already in the cold-backup archive');
|
|
57
|
+
addSpecDirOption(freeze);
|
|
58
|
+
freeze.action(
|
|
59
|
+
async (options: {
|
|
60
|
+
before?: string;
|
|
61
|
+
keepRecent: string;
|
|
62
|
+
dryRun?: boolean;
|
|
63
|
+
list?: boolean;
|
|
64
|
+
directory?: string;
|
|
65
|
+
}) => {
|
|
66
|
+
// r118: the cold-backup reads and writes stay inside the resolved
|
|
67
|
+
// instance root (`llmanspec/changes/archive`), never the launch cwd.
|
|
68
|
+
const rctx = reRootContext(ctx, options.directory);
|
|
69
|
+
const root = rctx.root;
|
|
70
|
+
warnIfNotMainCheckout(ctx.git);
|
|
71
|
+
const sz = await makeEmbeddedSevenZip();
|
|
72
|
+
const io = rctx.io;
|
|
73
|
+
if (options.list) {
|
|
74
|
+
for (const line of await runList(io, sz, root)) console.log(line);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
// 7z 压缩可能耗时 — 进度提示防止看上去卡住(B1);dry-run/list 不走压缩
|
|
78
|
+
if (!options.dryRun) progressNote('freeze.pack', root);
|
|
79
|
+
const result = await runFreeze(io, sz, root, {
|
|
80
|
+
before: options.before,
|
|
81
|
+
keepRecent: Number(options.keepRecent),
|
|
82
|
+
dryRun: options.dryRun,
|
|
83
|
+
});
|
|
84
|
+
for (const line of result.lines) console.log(line);
|
|
85
|
+
},
|
|
86
|
+
);
|
|
88
87
|
|
|
89
|
-
archive
|
|
88
|
+
const thaw = archive
|
|
90
89
|
.command('thaw')
|
|
91
90
|
.description('Restore archived change directories from the cold-backup archive')
|
|
92
91
|
.requiredOption(
|
|
@@ -98,22 +97,26 @@ export function registerArchive(program: Command): void {
|
|
|
98
97
|
},
|
|
99
98
|
[] as string[],
|
|
100
99
|
)
|
|
101
|
-
.option('--dest <path>', 'restore into this directory (created when missing)')
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
100
|
+
.option('--dest <path>', 'restore into this directory (created when missing)');
|
|
101
|
+
addSpecDirOption(thaw);
|
|
102
|
+
thaw.action(async (options: { change: string[]; dest?: string; directory?: string }) => {
|
|
103
|
+
const rctx = reRootContext(ctx, options.directory);
|
|
104
|
+
if (options.dest !== undefined) {
|
|
105
|
+
mkdirSync(resolve(options.dest), { recursive: true });
|
|
106
|
+
}
|
|
107
|
+
const root = rctx.root;
|
|
108
|
+
warnIfNotMainCheckout(ctx.git);
|
|
109
|
+
const sz = await makeEmbeddedSevenZip();
|
|
110
|
+
const io = rctx.io;
|
|
111
|
+
// r116 exemption: `--dest` is a user-supplied path and keeps its
|
|
112
|
+
// cwd-literal meaning. Core resolves it against the (possibly re-rooted)
|
|
113
|
+
// instance io, so hand it over already made absolute — single-root
|
|
114
|
+
// invocations keep the literal spelling untouched.
|
|
115
|
+
const dest =
|
|
116
|
+
options.dest === undefined || rctx.root === ctx.root ? options.dest : resolve(options.dest);
|
|
117
|
+
// 7z 解包可能耗时 — 进度提示防止看上去卡住(B1)
|
|
118
|
+
progressNote('thaw.unpack', root);
|
|
119
|
+
const result = await runThaw(io, sz, root, options.change, { dest });
|
|
120
|
+
for (const line of result.lines) console.log(line);
|
|
121
|
+
});
|
|
119
122
|
}
|