@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
|
@@ -0,0 +1,479 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
THEOREMS_DIR_REL,
|
|
5
|
+
renderMachine,
|
|
6
|
+
selectTheoremsByTag,
|
|
7
|
+
selectTheoremsForPaths,
|
|
8
|
+
type TheoremEntry,
|
|
9
|
+
} from '@llman-sdd/core';
|
|
10
|
+
import type { Command } from 'commander';
|
|
11
|
+
|
|
12
|
+
import {
|
|
13
|
+
CliError,
|
|
14
|
+
addReportOutputOptions,
|
|
15
|
+
addSpecDirOption,
|
|
16
|
+
assertCompactJsonPairing,
|
|
17
|
+
formatNotFound,
|
|
18
|
+
resolveCommandRoot,
|
|
19
|
+
resolveOutMode,
|
|
20
|
+
type CliContext,
|
|
21
|
+
type OutMode,
|
|
22
|
+
} from '../cli-shared.ts';
|
|
23
|
+
import { resolveBaseRef } from '../theorems/base.ts';
|
|
24
|
+
import { isUnhealthy } from '../theorems/diagnose.ts';
|
|
25
|
+
import { tokenizeCommand } from '../theorems/os-lock.ts';
|
|
26
|
+
import { quietAction } from '../theorems/quiet.ts';
|
|
27
|
+
import { makeCommandRunner } from '../theorems/runner.ts';
|
|
28
|
+
import { loadTheoremWorkspace, type LoadedTheoremWorkspace } from '../theorems/workspace.ts';
|
|
29
|
+
import { registerTheoremWrites } from './theorem-write.ts';
|
|
30
|
+
|
|
31
|
+
export const THEOREM_READ_ONLY_NOTICE = [
|
|
32
|
+
'Human Theorems are project-level read-only invariants owned exclusively by humans.',
|
|
33
|
+
'Priority: HIGHEST. Do NOT edit, delete, or bypass files under llmanspec/theorems/.',
|
|
34
|
+
'If a requirement or change conflicts with a `severity: hard` theorem, STOP immediately and escalate to the human.',
|
|
35
|
+
].join('\n');
|
|
36
|
+
|
|
37
|
+
function untrackedTheoremFiles(ctx: CliContext): string[] {
|
|
38
|
+
const out = ctx.git.runOpt(['status', '--porcelain', '--', THEOREMS_DIR_REL]) ?? '';
|
|
39
|
+
const files: string[] = [];
|
|
40
|
+
for (const line of out.split('\n')) {
|
|
41
|
+
if (!line.startsWith('?? ')) continue;
|
|
42
|
+
files.push(line.slice(3).trim());
|
|
43
|
+
}
|
|
44
|
+
return files;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function loadFor(ctx: CliContext, directory: string | undefined): LoadedTheoremWorkspace {
|
|
48
|
+
const root = resolveCommandRoot(ctx, directory);
|
|
49
|
+
return loadTheoremWorkspace({
|
|
50
|
+
io: ctx.io,
|
|
51
|
+
root,
|
|
52
|
+
run: makeCommandRunner({ cwd: root }),
|
|
53
|
+
platform: currentPlatformFor(),
|
|
54
|
+
untrackedFiles: untrackedTheoremFiles(ctx),
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function currentPlatformFor(): 'linux' | 'darwin' | 'win32' {
|
|
59
|
+
const platform = process.platform;
|
|
60
|
+
return platform === 'darwin' || platform === 'win32' ? platform : 'linux';
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function selectTheorems(
|
|
64
|
+
theorems: readonly TheoremEntry[],
|
|
65
|
+
options: { forPaths?: string[]; tag?: string; includeDeprecated?: boolean },
|
|
66
|
+
): TheoremEntry[] {
|
|
67
|
+
let selected = [...theorems];
|
|
68
|
+
if (options.includeDeprecated !== true) {
|
|
69
|
+
selected = selected.filter((theorem) => theorem.status === 'active');
|
|
70
|
+
}
|
|
71
|
+
if (options.forPaths !== undefined && options.forPaths.length > 0) {
|
|
72
|
+
selected = selectTheoremsForPaths(selected, options.forPaths);
|
|
73
|
+
}
|
|
74
|
+
if (options.tag !== undefined) selected = selectTheoremsByTag(selected, options.tag);
|
|
75
|
+
return selected;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function theoremDto(theorem: TheoremEntry, strength: string): Record<string, unknown> {
|
|
79
|
+
return {
|
|
80
|
+
id: theorem.id,
|
|
81
|
+
title: theorem.title,
|
|
82
|
+
statement: theorem.statement,
|
|
83
|
+
rationale: theorem.rationale,
|
|
84
|
+
severity: theorem.severity,
|
|
85
|
+
status: theorem.status,
|
|
86
|
+
scope: theorem.scope ?? [],
|
|
87
|
+
tags: theorem.tags,
|
|
88
|
+
verify: theorem.verify ?? null,
|
|
89
|
+
filePath: theorem.filePath,
|
|
90
|
+
lockStrength: strength,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function registerList(theorem: Command, ctx: CliContext): void {
|
|
95
|
+
const list = theorem
|
|
96
|
+
.command('list')
|
|
97
|
+
.description('List Human Theorems (read-only, scope-accurate recall)')
|
|
98
|
+
.option('--for <path...>', 'only theorems whose scope covers these paths')
|
|
99
|
+
.option('--changed', 'only theorems whose scope covers files changed in this branch')
|
|
100
|
+
.option('--tag <tag>', 'only theorems carrying this tag')
|
|
101
|
+
.option('--include-deprecated', 'also show theorems with status: deprecated');
|
|
102
|
+
addReportOutputOptions(list);
|
|
103
|
+
addSpecDirOption(list);
|
|
104
|
+
list.action(
|
|
105
|
+
(options: {
|
|
106
|
+
for?: string[];
|
|
107
|
+
changed?: boolean;
|
|
108
|
+
tag?: string;
|
|
109
|
+
includeDeprecated?: boolean;
|
|
110
|
+
output?: string;
|
|
111
|
+
json?: boolean;
|
|
112
|
+
compactJson?: boolean;
|
|
113
|
+
directory?: string;
|
|
114
|
+
}) => {
|
|
115
|
+
assertCompactJsonPairing(options);
|
|
116
|
+
const mode = resolveOutMode(options.output, options.json, options.compactJson);
|
|
117
|
+
const workspace = loadFor(ctx, options.directory);
|
|
118
|
+
const forPaths = options.changed === true ? changedPaths(ctx) : options.for;
|
|
119
|
+
const theorems = selectTheorems(workspace.theorems, {
|
|
120
|
+
...(forPaths !== undefined ? { forPaths } : {}),
|
|
121
|
+
...(options.tag !== undefined ? { tag: options.tag } : {}),
|
|
122
|
+
...(options.includeDeprecated !== undefined
|
|
123
|
+
? { includeDeprecated: options.includeDeprecated }
|
|
124
|
+
: {}),
|
|
125
|
+
});
|
|
126
|
+
emitList(theorems, workspace, mode);
|
|
127
|
+
},
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function changedPaths(ctx: CliContext): string[] {
|
|
132
|
+
const base = resolveBaseRef(ctx);
|
|
133
|
+
if (base === null) return [];
|
|
134
|
+
const out = ctx.git.runOpt(['diff', '--name-only', base, 'HEAD']) ?? '';
|
|
135
|
+
return out
|
|
136
|
+
.split('\n')
|
|
137
|
+
.map((line) => line.trim())
|
|
138
|
+
.filter((line) => line !== '');
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function emitList(
|
|
142
|
+
theorems: readonly TheoremEntry[],
|
|
143
|
+
workspace: LoadedTheoremWorkspace,
|
|
144
|
+
mode: OutMode,
|
|
145
|
+
): void {
|
|
146
|
+
const items = theorems.map((theorem) =>
|
|
147
|
+
theoremDto(theorem, workspace.lockStrengthByFile[theorem.filePath] ?? 'none'),
|
|
148
|
+
);
|
|
149
|
+
if (mode === 'human') {
|
|
150
|
+
console.log(THEOREM_READ_ONLY_NOTICE);
|
|
151
|
+
console.log('');
|
|
152
|
+
if (items.length === 0) {
|
|
153
|
+
console.log('No Human Theorems matched.');
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
console.log(`Human Theorems (${String(items.length)}):`);
|
|
157
|
+
for (const item of items) {
|
|
158
|
+
console.log(
|
|
159
|
+
` - theorem:${String(item.id)} (${String(item.title)}) [${String(item.severity)}]`,
|
|
160
|
+
);
|
|
161
|
+
console.log(` ${String(item.filePath)} (lock: ${String(item.lockStrength)})`);
|
|
162
|
+
}
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
console.log(
|
|
166
|
+
renderMachine(
|
|
167
|
+
{ notice: THEOREM_READ_ONLY_NOTICE, stateCode: workspace.diagnosis.code, items },
|
|
168
|
+
mode,
|
|
169
|
+
),
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function registerShow(theorem: Command, ctx: CliContext): void {
|
|
174
|
+
const show = theorem
|
|
175
|
+
.command('show')
|
|
176
|
+
.description('Show one Human Theorem with its OS lock state')
|
|
177
|
+
.argument('<id>', 'theorem id');
|
|
178
|
+
addReportOutputOptions(show);
|
|
179
|
+
addSpecDirOption(show);
|
|
180
|
+
show.action(
|
|
181
|
+
(
|
|
182
|
+
id: string,
|
|
183
|
+
options: { output?: string; json?: boolean; compactJson?: boolean; directory?: string },
|
|
184
|
+
) => {
|
|
185
|
+
assertCompactJsonPairing(options);
|
|
186
|
+
const mode = resolveOutMode(options.output, options.json, options.compactJson);
|
|
187
|
+
const workspace = loadFor(ctx, options.directory);
|
|
188
|
+
const theoremEntry = workspace.theorems.find((entry) => entry.id === id);
|
|
189
|
+
if (theoremEntry === undefined) {
|
|
190
|
+
throw new CliError(
|
|
191
|
+
formatNotFound(
|
|
192
|
+
'theorem',
|
|
193
|
+
id,
|
|
194
|
+
workspace.theorems.map((entry) => entry.id),
|
|
195
|
+
),
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
const dto = theoremDto(
|
|
199
|
+
theoremEntry,
|
|
200
|
+
workspace.lockStrengthByFile[theoremEntry.filePath] ?? 'none',
|
|
201
|
+
);
|
|
202
|
+
if (mode === 'human') {
|
|
203
|
+
console.log(`theorem:${theoremEntry.id} — ${theoremEntry.title}`);
|
|
204
|
+
console.log(` severity: ${theoremEntry.severity}`);
|
|
205
|
+
console.log(` status: ${theoremEntry.status}`);
|
|
206
|
+
console.log(` file: ${theoremEntry.filePath}`);
|
|
207
|
+
console.log(` lock: ${String(dto.lockStrength)}`);
|
|
208
|
+
if (theoremEntry.scope !== undefined) {
|
|
209
|
+
console.log(` scope: ${theoremEntry.scope.join(', ')}`);
|
|
210
|
+
}
|
|
211
|
+
console.log('');
|
|
212
|
+
console.log(`Statement: ${theoremEntry.statement}`);
|
|
213
|
+
console.log(`Rationale: ${theoremEntry.rationale}`);
|
|
214
|
+
if (theoremEntry.verify !== undefined) {
|
|
215
|
+
console.log(
|
|
216
|
+
`Verify: ${theoremEntry.verify.command} (timeout ${String(theoremEntry.verify.timeout_sec)}s)`,
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
console.log(renderMachine(dto, mode));
|
|
222
|
+
},
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function registerCheck(theorem: Command, ctx: CliContext): void {
|
|
227
|
+
const check = theorem
|
|
228
|
+
.command('check')
|
|
229
|
+
.description('Validate theorems (YAML/Zod/id, legacy leftovers, locks, verify)')
|
|
230
|
+
.option('--strict', 'require the directory to exist with at least one active theorem')
|
|
231
|
+
.option('--require-locked', 'every theorem file must be natively locked')
|
|
232
|
+
.option('--run-verify', 'execute each verify.command under its timeout')
|
|
233
|
+
.option('--base <ref>', 'base ref for the changed-theorems check (default: merge-base)')
|
|
234
|
+
.option('--deny-changes', 'fail when theorems changed relative to the base ref')
|
|
235
|
+
.option(
|
|
236
|
+
'-q, --quiet',
|
|
237
|
+
'silent gate mode: no output on healthy pass, lock reminder on degraded states',
|
|
238
|
+
);
|
|
239
|
+
addReportOutputOptions(check);
|
|
240
|
+
addSpecDirOption(check);
|
|
241
|
+
check.action(
|
|
242
|
+
(options: {
|
|
243
|
+
strict?: boolean;
|
|
244
|
+
requireLocked?: boolean;
|
|
245
|
+
runVerify?: boolean;
|
|
246
|
+
base?: string;
|
|
247
|
+
denyChanges?: boolean;
|
|
248
|
+
quiet?: boolean;
|
|
249
|
+
output?: string;
|
|
250
|
+
json?: boolean;
|
|
251
|
+
compactJson?: boolean;
|
|
252
|
+
directory?: string;
|
|
253
|
+
}) => {
|
|
254
|
+
if (
|
|
255
|
+
options.quiet === true &&
|
|
256
|
+
(options.json === true ||
|
|
257
|
+
options.compactJson === true ||
|
|
258
|
+
options.output === 'json' ||
|
|
259
|
+
options.output === 'compact-json')
|
|
260
|
+
) {
|
|
261
|
+
throw new CliError(
|
|
262
|
+
'--quiet cannot be combined with --json, --compact-json, or --output json|compact-json',
|
|
263
|
+
2,
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
assertCompactJsonPairing(options);
|
|
267
|
+
const mode = resolveOutMode(options.output, options.json, options.compactJson);
|
|
268
|
+
const outcome = runTheoremCheckDetailed(ctx, options);
|
|
269
|
+
const result = outcome.result;
|
|
270
|
+
if (options.quiet === true) {
|
|
271
|
+
const action = quietAction(result, outcome.culprits);
|
|
272
|
+
if (action.kind === 'silent') return;
|
|
273
|
+
if (action.kind === 'reminder') {
|
|
274
|
+
console.error(action.message);
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
if (mode === 'human') {
|
|
279
|
+
for (const failure of result.failures) console.error(` - ${failure}`);
|
|
280
|
+
console.log(
|
|
281
|
+
result.ok
|
|
282
|
+
? `Human Theorems check passed (${String(result.theoremCount)} theorem(s), state ${result.stateCode}).`
|
|
283
|
+
: `Human Theorems check failed (${String(result.failures.length)} issue(s), state ${result.stateCode}).`,
|
|
284
|
+
);
|
|
285
|
+
} else {
|
|
286
|
+
console.log(renderMachine(result, mode));
|
|
287
|
+
}
|
|
288
|
+
if (!result.ok) throw new CliError('theorem check failed');
|
|
289
|
+
},
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export interface TheoremCheckResult {
|
|
294
|
+
ok: boolean;
|
|
295
|
+
theoremCount: number;
|
|
296
|
+
stateCode: string;
|
|
297
|
+
failures: string[];
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
export interface TheoremCheckOptions {
|
|
301
|
+
strict?: boolean;
|
|
302
|
+
requireLocked?: boolean;
|
|
303
|
+
runVerify?: boolean;
|
|
304
|
+
base?: string;
|
|
305
|
+
denyChanges?: boolean;
|
|
306
|
+
directory?: string;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
export interface TheoremCheckOutcome {
|
|
310
|
+
result: TheoremCheckResult;
|
|
311
|
+
culprits: string[];
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
export function runTheoremCheckDetailed(
|
|
315
|
+
ctx: CliContext,
|
|
316
|
+
options: TheoremCheckOptions,
|
|
317
|
+
): TheoremCheckOutcome {
|
|
318
|
+
const workspace = loadFor(ctx, options.directory);
|
|
319
|
+
const failures: string[] = workspace.validation.issues.map(
|
|
320
|
+
(issue) => `${issue.filePath}: ${issue.message}`,
|
|
321
|
+
);
|
|
322
|
+
|
|
323
|
+
for (const legacy of workspace.legacyFiles) {
|
|
324
|
+
failures.push(`${legacy}: legacy theorem file detected — run \`llman-sdd theorem migrate\``);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
if (options.strict === true) {
|
|
328
|
+
if (!workspace.directoryExists) {
|
|
329
|
+
failures.push(`strict mode requires ${THEOREMS_DIR_REL}/ to exist`);
|
|
330
|
+
} else if (!workspace.theorems.some((entry) => entry.status === 'active')) {
|
|
331
|
+
failures.push('strict mode requires at least one active theorem');
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
if (options.requireLocked === true) {
|
|
336
|
+
for (const entry of workspace.theorems) {
|
|
337
|
+
if (workspace.lockStrengthByFile[entry.filePath] !== 'strong') {
|
|
338
|
+
failures.push(`${entry.filePath}: not natively locked`);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
if (options.denyChanges === true) {
|
|
344
|
+
const changed = changedTheoremFiles(ctx, options.base);
|
|
345
|
+
if (changed.length > 0) {
|
|
346
|
+
failures.push(
|
|
347
|
+
`changes under \`${THEOREMS_DIR_REL}/\` detected relative to ${options.base ?? 'merge-base'}: ${changed.join(', ')}`,
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
if (options.runVerify === true) {
|
|
353
|
+
for (const entry of workspace.theorems) {
|
|
354
|
+
if (entry.status !== 'active' || entry.verify === undefined) continue;
|
|
355
|
+
const outcome = runVerifyCommand(ctx, entry.verify.command, entry.verify.timeout_sec * 1000);
|
|
356
|
+
if (outcome.timedOut) {
|
|
357
|
+
failures.push(
|
|
358
|
+
`${entry.filePath}: verify timed out after ${String(entry.verify.timeout_sec)}s`,
|
|
359
|
+
);
|
|
360
|
+
} else if (outcome.status !== 0) {
|
|
361
|
+
failures.push(`${entry.filePath}: verify failed (exit ${String(outcome.status)})`);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
return {
|
|
367
|
+
result: {
|
|
368
|
+
ok: failures.length === 0,
|
|
369
|
+
theoremCount: workspace.theorems.length,
|
|
370
|
+
stateCode: workspace.diagnosis.code,
|
|
371
|
+
failures,
|
|
372
|
+
},
|
|
373
|
+
culprits: workspace.diagnosis.culprits,
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
export function runTheoremCheck(ctx: CliContext, options: TheoremCheckOptions): TheoremCheckResult {
|
|
378
|
+
return runTheoremCheckDetailed(ctx, options).result;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
function runVerifyCommand(
|
|
382
|
+
ctx: CliContext,
|
|
383
|
+
command: string,
|
|
384
|
+
timeoutMs: number,
|
|
385
|
+
): { status: number; timedOut: boolean } {
|
|
386
|
+
const tokens = tokenizeCommand(command);
|
|
387
|
+
const binary = tokens[0];
|
|
388
|
+
if (binary === undefined) return { status: 1, timedOut: false };
|
|
389
|
+
const result = spawnSync(binary, tokens.slice(1), {
|
|
390
|
+
cwd: ctx.root,
|
|
391
|
+
encoding: 'utf8',
|
|
392
|
+
timeout: timeoutMs,
|
|
393
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
394
|
+
});
|
|
395
|
+
const timedOut = result.error !== undefined || result.status === null;
|
|
396
|
+
return { status: result.status ?? 1, timedOut };
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
export function changedTheoremFiles(ctx: CliContext, base: string | undefined): string[] {
|
|
400
|
+
const ref = resolveBaseRef(ctx, base);
|
|
401
|
+
if (ref === null) return [];
|
|
402
|
+
const committed =
|
|
403
|
+
ctx.git.runOpt(['diff', '--name-only', ref, 'HEAD', '--', THEOREMS_DIR_REL]) ?? '';
|
|
404
|
+
const dirty = ctx.git.runOpt(['status', '--porcelain', '--', THEOREMS_DIR_REL]) ?? '';
|
|
405
|
+
const files = new Set<string>();
|
|
406
|
+
for (const line of committed.split('\n')) {
|
|
407
|
+
const trimmed = line.trim();
|
|
408
|
+
if (trimmed !== '') files.add(trimmed);
|
|
409
|
+
}
|
|
410
|
+
for (const line of dirty.split('\n')) {
|
|
411
|
+
const trimmed = line.slice(3).trim();
|
|
412
|
+
if (trimmed !== '') files.add(trimmed);
|
|
413
|
+
}
|
|
414
|
+
return [...files].toSorted();
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
function statusPayload(ctx: CliContext, directory: string | undefined): Record<string, unknown> {
|
|
418
|
+
const workspace = loadFor(ctx, directory);
|
|
419
|
+
return {
|
|
420
|
+
platform: workspace.capability.platform,
|
|
421
|
+
capabilitySupported: workspace.capability.supported,
|
|
422
|
+
mechanism: workspace.capability.mechanism,
|
|
423
|
+
stateCode: workspace.diagnosis.code,
|
|
424
|
+
culprits: workspace.diagnosis.culprits,
|
|
425
|
+
recovery: workspace.diagnosis.recovery,
|
|
426
|
+
directoryExists: workspace.directoryExists,
|
|
427
|
+
theoremCount: workspace.theorems.length,
|
|
428
|
+
legacyFiles: workspace.legacyFiles,
|
|
429
|
+
files: workspace.theorems.map((theorem) => ({
|
|
430
|
+
filePath: theorem.filePath,
|
|
431
|
+
lockStrength: workspace.lockStrengthByFile[theorem.filePath] ?? 'none',
|
|
432
|
+
})),
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
function registerStatus(theorem: Command, ctx: CliContext, name: 'status' | 'doctor'): void {
|
|
437
|
+
const cmd = theorem
|
|
438
|
+
.command(name)
|
|
439
|
+
.description(
|
|
440
|
+
name === 'doctor'
|
|
441
|
+
? 'Diagnose the theorem workspace (non-zero exit on an unhealthy state)'
|
|
442
|
+
: 'Report theorem workspace state and native lock capability',
|
|
443
|
+
);
|
|
444
|
+
addReportOutputOptions(cmd);
|
|
445
|
+
addSpecDirOption(cmd);
|
|
446
|
+
cmd.action(
|
|
447
|
+
(options: { output?: string; json?: boolean; compactJson?: boolean; directory?: string }) => {
|
|
448
|
+
assertCompactJsonPairing(options);
|
|
449
|
+
const mode = resolveOutMode(options.output, options.json, options.compactJson);
|
|
450
|
+
const payload = statusPayload(ctx, options.directory);
|
|
451
|
+
if (mode === 'human') {
|
|
452
|
+
console.log(`platform: ${String(payload.platform)} (${String(payload.mechanism)})`);
|
|
453
|
+
console.log(`state: ${String(payload.stateCode)}`);
|
|
454
|
+
console.log(`theorems: ${String(payload.theoremCount)}`);
|
|
455
|
+
console.log(`recovery: ${String(payload.recovery)}`);
|
|
456
|
+
for (const file of payload.files as Array<{ filePath: string; lockStrength: string }>) {
|
|
457
|
+
console.log(` - ${file.filePath} (lock: ${file.lockStrength})`);
|
|
458
|
+
}
|
|
459
|
+
} else {
|
|
460
|
+
console.log(renderMachine(payload, mode));
|
|
461
|
+
}
|
|
462
|
+
if (name === 'doctor' && isUnhealthy(payload.stateCode as never)) {
|
|
463
|
+
throw new CliError(`unhealthy theorem state: ${String(payload.stateCode)}`);
|
|
464
|
+
}
|
|
465
|
+
},
|
|
466
|
+
);
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
export function registerTheorem(program: Command, ctx: CliContext): void {
|
|
470
|
+
const theorem = program
|
|
471
|
+
.command('theorem')
|
|
472
|
+
.description('Inspect human-owned read-only invariants (llmanspec/theorems/)');
|
|
473
|
+
registerList(theorem, ctx);
|
|
474
|
+
registerShow(theorem, ctx);
|
|
475
|
+
registerCheck(theorem, ctx);
|
|
476
|
+
registerStatus(theorem, ctx, 'status');
|
|
477
|
+
registerStatus(theorem, ctx, 'doctor');
|
|
478
|
+
registerTheoremWrites(theorem, ctx);
|
|
479
|
+
}
|