@evomap/evolver-cli 2.0.0-beta.5 → 2.0.0-beta.6
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/dist/autoDistillLlm.d.ts +6 -0
- package/dist/autoDistillLlm.js +40 -6
- package/dist/dispatch.js +2 -0
- package/dist/doctor.js +16 -0
- package/dist/index.js +6 -4
- package/dist/issueReport.d.ts +7 -0
- package/dist/issueReport.js +291 -0
- package/dist/materialSnapshot.d.ts +24 -0
- package/dist/materialSnapshot.js +234 -12
- package/dist/recipe.js +7 -1
- package/dist/reuse.d.ts +7 -2
- package/dist/reuse.js +39 -2
- package/dist/setupHooks.d.ts +5 -0
- package/dist/setupHooks.js +230 -14
- package/package.json +7 -7
package/dist/autoDistillLlm.d.ts
CHANGED
|
@@ -30,6 +30,7 @@ export interface LlmDistillRunnerResult {
|
|
|
30
30
|
exitCode: number | null;
|
|
31
31
|
stdout: string;
|
|
32
32
|
stderr?: string;
|
|
33
|
+
stdoutTruncated?: boolean;
|
|
33
34
|
}
|
|
34
35
|
export type LlmDistillRunner = (prompt: string, ctx: {
|
|
35
36
|
cwd: string;
|
|
@@ -80,6 +81,11 @@ export declare function runClaudeDistill(prompt: string, ctx: {
|
|
|
80
81
|
* `--output-last-message <file>`: capture ONLY the final assistant message (the gene JSON), avoiding codex's stdout
|
|
81
82
|
* preamble/token-count noise. Prompt arrives via stdin (the trailing `-`). Verified live against codex-cli 0.137.0. */
|
|
82
83
|
export declare function codexDistillArgs(cwd: string, lastMessageFile: string, model?: string): string[];
|
|
84
|
+
/** Read Codex's final-message file without allowing that subprocess-owned file to bypass output bounds. */
|
|
85
|
+
export declare function readBoundedDistillOutputFile(path: string, maxBytes?: number): {
|
|
86
|
+
text: string;
|
|
87
|
+
truncated: boolean;
|
|
88
|
+
};
|
|
83
89
|
/** Distill a prompt with `codex exec` (read-only). Reads the clean final message from --output-last-message so
|
|
84
90
|
* parseDistillOutput sees a bare gene JSON; falls back to raw stdout (pickGeneObject scans it) if the file is absent.
|
|
85
91
|
* Windows: codex is a `.cmd` npm shim, so route through resolveSpawnCommand (shell-free). */
|
package/dist/autoDistillLlm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
-
import { existsSync, mkdirSync, readFileSync, realpathSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { closeSync, existsSync, mkdirSync, openSync, readFileSync, readSync, realpathSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
3
3
|
import { tmpdir } from 'node:os';
|
|
4
4
|
import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
5
5
|
import { algo, assetstore, events, exec, hub, verify } from '@evomap/evolver-core';
|
|
@@ -338,7 +338,7 @@ export async function runClaudeDistill(prompt, ctx) {
|
|
|
338
338
|
const env = exec.scrubAgentEnv(ctx.env, { allowPrefixes: exec.getRunnerSpec('claude').envAllow.prefixes });
|
|
339
339
|
try {
|
|
340
340
|
const r = await exec.spawnCapture('claude', args, { cwd: ctx.cwd, timeoutMs: ctx.timeoutMs, input: prompt, env });
|
|
341
|
-
return { exitCode: r.code, stdout: r.stdout, stderr: r.stderr };
|
|
341
|
+
return { exitCode: r.code, stdout: r.stdout, stderr: r.stderr, stdoutTruncated: r.stdoutTruncated };
|
|
342
342
|
}
|
|
343
343
|
catch (e) {
|
|
344
344
|
return { exitCode: null, stdout: '', stderr: e instanceof Error ? e.message : String(e) };
|
|
@@ -356,6 +356,30 @@ export function codexDistillArgs(cwd, lastMessageFile, model) {
|
|
|
356
356
|
args.push('-');
|
|
357
357
|
return args;
|
|
358
358
|
}
|
|
359
|
+
/** Read Codex's final-message file without allowing that subprocess-owned file to bypass output bounds. */
|
|
360
|
+
export function readBoundedDistillOutputFile(path, maxBytes = exec.DEFAULT_MAX_CAPTURE_BYTES) {
|
|
361
|
+
if (!Number.isSafeInteger(maxBytes) || maxBytes < 256)
|
|
362
|
+
throw new RangeError('maxBytes must be an integer >= 256');
|
|
363
|
+
const fd = openSync(path, 'r');
|
|
364
|
+
try {
|
|
365
|
+
const buffer = Buffer.allocUnsafe(maxBytes + 1);
|
|
366
|
+
let offset = 0;
|
|
367
|
+
while (offset < buffer.length) {
|
|
368
|
+
const read = readSync(fd, buffer, offset, buffer.length - offset, null);
|
|
369
|
+
if (read === 0)
|
|
370
|
+
break;
|
|
371
|
+
offset += read;
|
|
372
|
+
}
|
|
373
|
+
const truncated = offset > maxBytes;
|
|
374
|
+
return {
|
|
375
|
+
text: truncated ? '' : buffer.subarray(0, offset).toString('utf8').trim(),
|
|
376
|
+
truncated,
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
finally {
|
|
380
|
+
closeSync(fd);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
359
383
|
/** Distill a prompt with `codex exec` (read-only). Reads the clean final message from --output-last-message so
|
|
360
384
|
* parseDistillOutput sees a bare gene JSON; falls back to raw stdout (pickGeneObject scans it) if the file is absent.
|
|
361
385
|
* Windows: codex is a `.cmd` npm shim, so route through resolveSpawnCommand (shell-free). */
|
|
@@ -367,13 +391,20 @@ export async function runCodexDistill(prompt, ctx) {
|
|
|
367
391
|
try {
|
|
368
392
|
const r = await exec.spawnCapture(resolved.cmd, resolved.args, { cwd: ctx.cwd, timeoutMs: ctx.timeoutMs, input: prompt, env });
|
|
369
393
|
let stdout = r.stdout;
|
|
394
|
+
let stdoutTruncated = r.stdoutTruncated;
|
|
370
395
|
try {
|
|
371
|
-
const last =
|
|
372
|
-
if (last)
|
|
373
|
-
stdout =
|
|
396
|
+
const last = readBoundedDistillOutputFile(lastMessageFile);
|
|
397
|
+
if (last.truncated) {
|
|
398
|
+
stdout = '';
|
|
399
|
+
stdoutTruncated = true;
|
|
400
|
+
}
|
|
401
|
+
else if (last.text) {
|
|
402
|
+
stdout = last.text;
|
|
403
|
+
stdoutTruncated = false;
|
|
404
|
+
}
|
|
374
405
|
}
|
|
375
406
|
catch { /* file absent (codex failed early) → keep raw stdout for pickGeneObject */ }
|
|
376
|
-
return { exitCode: r.code, stdout, stderr: r.stderr };
|
|
407
|
+
return { exitCode: r.code, stdout, stderr: r.stderr, stdoutTruncated };
|
|
377
408
|
}
|
|
378
409
|
catch (e) {
|
|
379
410
|
return { exitCode: null, stdout: '', stderr: e instanceof Error ? e.message : String(e) };
|
|
@@ -467,6 +498,9 @@ export async function autoDistillLlm(options) {
|
|
|
467
498
|
// permanently exhaust this data hash after MAX_ATTEMPTS — the exact silent stall this exemption prevents.
|
|
468
499
|
return { ok: false, mode, reason: llm.exitCode === null ? 'claude_spawn_error' : 'claude_nonzero_exit', dataHash: input.dataHash };
|
|
469
500
|
}
|
|
501
|
+
if (llm.stdoutTruncated) {
|
|
502
|
+
return { ok: false, mode, reason: 'llm_output_truncated', dataHash: input.dataHash };
|
|
503
|
+
}
|
|
470
504
|
const raw = parseDistillOutput(llm.stdout);
|
|
471
505
|
const candidate0 = asGeneCandidate(raw);
|
|
472
506
|
if (!candidate0) {
|
package/dist/dispatch.js
CHANGED
|
@@ -28,6 +28,7 @@ import { runCycleCommand } from './cycleConsumer.js';
|
|
|
28
28
|
import { runProxyToken } from './proxyToken.js';
|
|
29
29
|
import { runMaterialCommand } from './materialPackage.js';
|
|
30
30
|
import { runDashboardCommand } from './dashboard.js';
|
|
31
|
+
import { runIssueReportCommand } from './issueReport.js';
|
|
31
32
|
import { runAssetTrustCommand } from './assetTrust.js';
|
|
32
33
|
import { runAssetHealthCommand } from './assetHealth.js';
|
|
33
34
|
import { runV1FetchCompat, runV1RunCompat, runV1SolidifyCompat, runV1WebuiCompat } from './v1Compat.js';
|
|
@@ -71,6 +72,7 @@ export const ASYNC_COMMANDS = {
|
|
|
71
72
|
'anti-gene-benchmark': runAntiGeneBenchmarkCommand,
|
|
72
73
|
'anti-gene-rollout': runAntiGeneRolloutCommand,
|
|
73
74
|
dashboard: runDashboardCommand,
|
|
75
|
+
'issue-report': runIssueReportCommand,
|
|
74
76
|
'asset-trust': runAssetTrustCommand,
|
|
75
77
|
'asset-health': runAssetHealthCommand,
|
|
76
78
|
proxy: runProxyCommand,
|
package/dist/doctor.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
// (heartbeat, proxy path) touch the proxy and are a SEPARATE, gated step — not here.
|
|
5
5
|
import { readFileSync, existsSync, statSync } from 'node:fs';
|
|
6
6
|
import { isAbsolute, join } from 'node:path';
|
|
7
|
+
import { events, issueReporter } from '@evomap/evolver-core';
|
|
7
8
|
import { expandHomePath, parseEnvFile } from '@evomap/evolver-mcp';
|
|
8
9
|
import { formatMemoryGraphOperatorStatus, loadMemoryGraphOperatorStatus } from './localMemoryGraph.js';
|
|
9
10
|
// Secrets that must live ONLY behind the EVOLVER_ENV_FILE pointer — never inlined into a runtime config (#217).
|
|
@@ -923,6 +924,21 @@ export async function runDoctor(argv, deps = {}) {
|
|
|
923
924
|
}
|
|
924
925
|
const checks = runDoctorChecks({ ...deps, profile: f.profile, ...(f.root !== undefined ? { configRoot: f.root } : {}) });
|
|
925
926
|
const failed = checks.some((c) => c.status === 'fail');
|
|
927
|
+
if (failed) {
|
|
928
|
+
try {
|
|
929
|
+
const input = issueReporter.issueReportInputFromDoctor(checks.map(({ name, status }) => ({ name, status })));
|
|
930
|
+
if (input) {
|
|
931
|
+
issueReporter.createIssueDraft(input, {
|
|
932
|
+
rootDir: join(events.evomapHome(deps.env ?? process.env), 'evolution', 'issue-reporter'),
|
|
933
|
+
workspaceScope: f.root ?? process.cwd(),
|
|
934
|
+
env: deps.env ?? process.env,
|
|
935
|
+
});
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
catch {
|
|
939
|
+
// Local draft reporting must never change the doctor command surface.
|
|
940
|
+
}
|
|
941
|
+
}
|
|
926
942
|
if (f.json) {
|
|
927
943
|
process.stdout.write(`${JSON.stringify({ ok: !failed, profile: f.profile, checks })}\n`);
|
|
928
944
|
}
|
package/dist/index.js
CHANGED
|
@@ -67,10 +67,11 @@ export function cliUsage() {
|
|
|
67
67
|
' -v, --version Show the installed version',
|
|
68
68
|
'',
|
|
69
69
|
'Proxy options (evolver proxy):',
|
|
70
|
-
' --home <dir>
|
|
71
|
-
' --
|
|
72
|
-
' --
|
|
73
|
-
' --
|
|
70
|
+
' --home <dir> Root for assets, store, settings, and traces',
|
|
71
|
+
' --evomap-home <dir> Identity home for node_id/node_secret; defaults to --home',
|
|
72
|
+
' --store <path> Mailbox store path',
|
|
73
|
+
' --settings <path> Proxy settings file',
|
|
74
|
+
' --env-file <path> Environment file',
|
|
74
75
|
'',
|
|
75
76
|
'Commands:',
|
|
76
77
|
' Daemon: proxy, lifecycle, proxy-token, doctor, setup-hooks',
|
|
@@ -79,6 +80,7 @@ export function cliUsage() {
|
|
|
79
80
|
' Assets: asset-log, asset-trust, asset-health, material, recipe, skill',
|
|
80
81
|
' Hub: login, logout, phub, sync, publish, fetch, buy, orders, atp',
|
|
81
82
|
' Operations: status, cycles, trigger, value, retention, replay, rebuild-views',
|
|
83
|
+
' issue-report',
|
|
82
84
|
' Tools: dashboard, webui, trajectory-export, migrate, verify',
|
|
83
85
|
' Advanced: anti-gene-benchmark, anti-gene-rollout, reset-local-secret',
|
|
84
86
|
' skill-distill, skill-md-update',
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { events, issueReporter } from '@evomap/evolver-core';
|
|
3
|
+
import { loadEnvFileFromEnv } from '@evomap/evolver-mcp';
|
|
4
|
+
import { runDoctorChecks } from './doctor.js';
|
|
5
|
+
import { getCliVersion } from './version.js';
|
|
6
|
+
const GITHUB_FETCH_TIMEOUT_MS = 15_000;
|
|
7
|
+
function parseFlags(argv) {
|
|
8
|
+
const flags = {
|
|
9
|
+
json: false,
|
|
10
|
+
cycleIds: [],
|
|
11
|
+
eventIds: [],
|
|
12
|
+
traceIds: [],
|
|
13
|
+
steps: [],
|
|
14
|
+
diagnosticCodes: [],
|
|
15
|
+
approved: false,
|
|
16
|
+
notCreated: false,
|
|
17
|
+
abandon: false,
|
|
18
|
+
};
|
|
19
|
+
for (let index = 0; index < argv.length; index++) {
|
|
20
|
+
const arg = argv[index];
|
|
21
|
+
const next = () => argv[++index];
|
|
22
|
+
if (arg === '--root')
|
|
23
|
+
flags.root = next() ?? flags.root;
|
|
24
|
+
else if (arg === '--json')
|
|
25
|
+
flags.json = true;
|
|
26
|
+
else if (arg === '--source')
|
|
27
|
+
flags.source = next();
|
|
28
|
+
else if (arg === '--error-class')
|
|
29
|
+
flags.errorClass = next();
|
|
30
|
+
else if (arg === '--failure-class')
|
|
31
|
+
flags.failureClass = next();
|
|
32
|
+
else if (arg === '--cycle') {
|
|
33
|
+
const value = next();
|
|
34
|
+
if (value)
|
|
35
|
+
flags.cycleIds.push(value);
|
|
36
|
+
}
|
|
37
|
+
else if (arg === '--event') {
|
|
38
|
+
const value = next();
|
|
39
|
+
if (value)
|
|
40
|
+
flags.eventIds.push(value);
|
|
41
|
+
}
|
|
42
|
+
else if (arg === '--trace') {
|
|
43
|
+
const value = next();
|
|
44
|
+
if (value)
|
|
45
|
+
flags.traceIds.push(value);
|
|
46
|
+
}
|
|
47
|
+
else if (arg === '--step') {
|
|
48
|
+
const value = next();
|
|
49
|
+
if (value)
|
|
50
|
+
flags.steps.push(value);
|
|
51
|
+
}
|
|
52
|
+
else if (arg === '--diagnostic') {
|
|
53
|
+
const value = next();
|
|
54
|
+
if (value)
|
|
55
|
+
flags.diagnosticCodes.push(value);
|
|
56
|
+
}
|
|
57
|
+
else if (arg === '--repo')
|
|
58
|
+
flags.repo = next();
|
|
59
|
+
else if (arg === '--approve')
|
|
60
|
+
flags.approved = true;
|
|
61
|
+
else if (arg === '--not-created')
|
|
62
|
+
flags.notCreated = true;
|
|
63
|
+
else if (arg === '--abandon')
|
|
64
|
+
flags.abandon = true;
|
|
65
|
+
else if (arg === '--issue-number') {
|
|
66
|
+
const value = Number(next());
|
|
67
|
+
if (Number.isInteger(value) && value > 0)
|
|
68
|
+
flags.issueNumber = value;
|
|
69
|
+
}
|
|
70
|
+
else if (arg === '--issue-url')
|
|
71
|
+
flags.issueUrl = next();
|
|
72
|
+
}
|
|
73
|
+
return flags;
|
|
74
|
+
}
|
|
75
|
+
function reporterOptions(flags, env, deps) {
|
|
76
|
+
const envRoot = env['EVOLVER_ISSUE_REPORT_ROOT']?.trim();
|
|
77
|
+
return {
|
|
78
|
+
rootDir: flags.root ?? (envRoot || join(events.evomapHome(env), 'evolution', 'issue-reporter')),
|
|
79
|
+
workspaceScope: process.cwd(),
|
|
80
|
+
env,
|
|
81
|
+
now: deps.now,
|
|
82
|
+
logger: (entry) => process.stderr.write(`[issue-report] fingerprint=${entry.fingerprint} status=${entry.status}${entry.errorClass ? ` error_class=${entry.errorClass}` : ''}\n`),
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function writeResult(value, json) {
|
|
86
|
+
process.stdout.write(json ? `${JSON.stringify(value)}\n` : `${String(value)}\n`);
|
|
87
|
+
}
|
|
88
|
+
function publicDraftState(draft) {
|
|
89
|
+
return { fingerprint: draft.fingerprint, status: draft.status };
|
|
90
|
+
}
|
|
91
|
+
function publicSubmitResult(result) {
|
|
92
|
+
return {
|
|
93
|
+
status: result.status,
|
|
94
|
+
...('errorClass' in result ? { errorClass: result.errorClass } : {}),
|
|
95
|
+
draft: publicDraftState(result.draft),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
function githubTransport(token, fetchFn) {
|
|
99
|
+
return {
|
|
100
|
+
async listOpenIssues(input) {
|
|
101
|
+
const controller = new AbortController();
|
|
102
|
+
const timer = setTimeout(() => controller.abort(), GITHUB_FETCH_TIMEOUT_MS);
|
|
103
|
+
timer.unref?.();
|
|
104
|
+
try {
|
|
105
|
+
const response = await fetchFn(`https://api.github.com/repos/${input.repo}/issues?state=open&per_page=${input.perPage}&page=${input.page}`, {
|
|
106
|
+
method: 'GET',
|
|
107
|
+
signal: controller.signal,
|
|
108
|
+
headers: {
|
|
109
|
+
accept: 'application/vnd.github+json',
|
|
110
|
+
authorization: `Bearer ${token}`,
|
|
111
|
+
'user-agent': 'evolver-v2-safe-issue-reporter',
|
|
112
|
+
'x-github-api-version': '2022-11-28',
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
if (!response.ok)
|
|
116
|
+
throw new issueReporter.GithubIssueTransportError('not_created');
|
|
117
|
+
const payload = await response.json();
|
|
118
|
+
if (!Array.isArray(payload))
|
|
119
|
+
throw new issueReporter.GithubIssueTransportError('not_created');
|
|
120
|
+
return {
|
|
121
|
+
issues: payload.map((item) => {
|
|
122
|
+
const record = item;
|
|
123
|
+
return {
|
|
124
|
+
number: Number(record['number']),
|
|
125
|
+
url: String(record['html_url'] ?? ''),
|
|
126
|
+
body: typeof record['body'] === 'string' ? record['body'] : '',
|
|
127
|
+
isPullRequest: record['pull_request'] !== undefined,
|
|
128
|
+
};
|
|
129
|
+
}),
|
|
130
|
+
hasNextPage: /<[^>]+>;\s*rel="next"/.test(response.headers.get('link') ?? ''),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
finally {
|
|
134
|
+
clearTimeout(timer);
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
async createIssue(input) {
|
|
138
|
+
const controller = new AbortController();
|
|
139
|
+
const timer = setTimeout(() => controller.abort(), GITHUB_FETCH_TIMEOUT_MS);
|
|
140
|
+
timer.unref?.();
|
|
141
|
+
try {
|
|
142
|
+
const response = await fetchFn(`https://api.github.com/repos/${input.repo}/issues`, {
|
|
143
|
+
method: 'POST',
|
|
144
|
+
signal: controller.signal,
|
|
145
|
+
headers: {
|
|
146
|
+
accept: 'application/vnd.github+json',
|
|
147
|
+
authorization: `Bearer ${token}`,
|
|
148
|
+
'content-type': 'application/json',
|
|
149
|
+
'user-agent': 'evolver-v2-safe-issue-reporter',
|
|
150
|
+
'x-github-api-version': '2022-11-28',
|
|
151
|
+
},
|
|
152
|
+
body: JSON.stringify({ title: input.title, body: input.body }),
|
|
153
|
+
});
|
|
154
|
+
if (!response.ok) {
|
|
155
|
+
throw new issueReporter.GithubIssueTransportError(response.status >= 400 && response.status < 500 ? 'not_created' : 'ambiguous');
|
|
156
|
+
}
|
|
157
|
+
const payload = await response.json();
|
|
158
|
+
return { number: Number(payload.number), url: String(payload.html_url ?? '') };
|
|
159
|
+
}
|
|
160
|
+
finally {
|
|
161
|
+
clearTimeout(timer);
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
export async function runIssueReportCommand(argv, deps = {}) {
|
|
167
|
+
const action = argv[0];
|
|
168
|
+
const fingerprint = argv[1];
|
|
169
|
+
const flags = parseFlags(argv.slice(action === 'submit' || action === 'reject' || action === 'resolve' ? 2 : 1));
|
|
170
|
+
const env = { ...(deps.env ?? process.env) };
|
|
171
|
+
if (action === 'submit' || action === 'resolve') {
|
|
172
|
+
const envLoad = loadEnvFileFromEnv(env);
|
|
173
|
+
if (envLoad.error) {
|
|
174
|
+
process.stderr.write('issue_report_env_file_error\n');
|
|
175
|
+
return 1;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
const options = reporterOptions(flags, env, { ...deps, env });
|
|
179
|
+
if (action === 'draft') {
|
|
180
|
+
let input = null;
|
|
181
|
+
if (flags.cycleIds[0]) {
|
|
182
|
+
input = issueReporter.issueReportInputFromCycle(events.readEvents(), flags.cycleIds[0]);
|
|
183
|
+
}
|
|
184
|
+
else if (flags.source === 'doctor') {
|
|
185
|
+
input = issueReporter.issueReportInputFromDoctor(runDoctorChecks().map(({ name, status }) => ({ name, status })));
|
|
186
|
+
}
|
|
187
|
+
else if (issueReporter.isIssueReportSource(flags.source) && flags.errorClass) {
|
|
188
|
+
input = {
|
|
189
|
+
source: flags.source,
|
|
190
|
+
errorClass: flags.errorClass,
|
|
191
|
+
failureClass: flags.failureClass,
|
|
192
|
+
cycleIds: flags.cycleIds,
|
|
193
|
+
eventIds: flags.eventIds,
|
|
194
|
+
traceIds: flags.traceIds,
|
|
195
|
+
reproductionSteps: flags.steps,
|
|
196
|
+
diagnosticCodes: flags.diagnosticCodes,
|
|
197
|
+
version: getCliVersion(),
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
if (!input) {
|
|
201
|
+
process.stderr.write('用法: evolver issue-report draft (--cycle <id> | --source <doctor|review|event|cycle_failure> --error-class <class>) [--json]\n');
|
|
202
|
+
return 1;
|
|
203
|
+
}
|
|
204
|
+
if (flags.traceIds.length > 0) {
|
|
205
|
+
input.traceIds = [...(input.traceIds ?? []), ...flags.traceIds];
|
|
206
|
+
}
|
|
207
|
+
input.version ??= getCliVersion();
|
|
208
|
+
const result = issueReporter.createIssueDraft(input, options);
|
|
209
|
+
writeResult(flags.json ? result : `${result.status}: ${result.draft.fingerprint}`, flags.json);
|
|
210
|
+
return 0;
|
|
211
|
+
}
|
|
212
|
+
if ((action === 'submit' || action === 'reject' || action === 'resolve') && fingerprint) {
|
|
213
|
+
const lookup = issueReporter.lookupIssueDraft(options.rootDir, fingerprint);
|
|
214
|
+
if (lookup.status !== 'found') {
|
|
215
|
+
if (flags.json && /^[a-f0-9]{20}$/.test(fingerprint)) {
|
|
216
|
+
writeResult({
|
|
217
|
+
status: 'failed',
|
|
218
|
+
errorClass: lookup.status === 'missing' ? 'draft_not_found' : 'unsafe_draft',
|
|
219
|
+
draft: { fingerprint, status: 'draft' },
|
|
220
|
+
}, true);
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
process.stderr.write('issue draft not found\n');
|
|
224
|
+
}
|
|
225
|
+
return 1;
|
|
226
|
+
}
|
|
227
|
+
const { draft } = lookup;
|
|
228
|
+
if (action === 'resolve') {
|
|
229
|
+
const repo = flags.repo ?? env['EVOLVER_ISSUE_REPO'];
|
|
230
|
+
const resolution = flags.notCreated
|
|
231
|
+
? { outcome: 'not_created' }
|
|
232
|
+
: flags.abandon
|
|
233
|
+
? { outcome: 'abandoned' }
|
|
234
|
+
: flags.issueNumber && flags.issueUrl && repo
|
|
235
|
+
? { outcome: 'submitted', issueNumber: flags.issueNumber, url: flags.issueUrl, repo }
|
|
236
|
+
: null;
|
|
237
|
+
if (!resolution) {
|
|
238
|
+
process.stderr.write('resolve requires --not-created, --abandon, or --issue-number/--issue-url/--repo\n');
|
|
239
|
+
return 1;
|
|
240
|
+
}
|
|
241
|
+
try {
|
|
242
|
+
const resolved = issueReporter.resolveIssueSubmission(fingerprint, resolution, options);
|
|
243
|
+
writeResult(flags.json ? publicDraftState(resolved) : `${resolved.status}: ${resolved.fingerprint}`, flags.json);
|
|
244
|
+
return 0;
|
|
245
|
+
}
|
|
246
|
+
catch (error) {
|
|
247
|
+
const errorClass = error instanceof issueReporter.IssueDraftConflictError
|
|
248
|
+
? error.errorClass
|
|
249
|
+
: 'invalid_resolution';
|
|
250
|
+
writeResult(flags.json ? { status: 'failed', errorClass, draft: publicDraftState(draft) } : `failed: ${draft.fingerprint}`, flags.json);
|
|
251
|
+
return 1;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
if (action === 'reject') {
|
|
255
|
+
let rejected;
|
|
256
|
+
try {
|
|
257
|
+
rejected = issueReporter.rejectIssueDraft(draft, options);
|
|
258
|
+
}
|
|
259
|
+
catch (error) {
|
|
260
|
+
if (!(error instanceof issueReporter.IssueDraftConflictError))
|
|
261
|
+
throw error;
|
|
262
|
+
const result = {
|
|
263
|
+
status: 'rate_limited',
|
|
264
|
+
errorClass: error.errorClass,
|
|
265
|
+
draft: publicDraftState(draft),
|
|
266
|
+
};
|
|
267
|
+
writeResult(flags.json ? result : `${result.status}: ${draft.fingerprint}`, flags.json);
|
|
268
|
+
return 1;
|
|
269
|
+
}
|
|
270
|
+
writeResult(flags.json ? publicDraftState(rejected) : `${rejected.status}: ${rejected.fingerprint}`, flags.json);
|
|
271
|
+
return rejected.status === 'submitted' ? 1 : 0;
|
|
272
|
+
}
|
|
273
|
+
const repo = flags.repo ?? env['EVOLVER_ISSUE_REPO'];
|
|
274
|
+
const token = env['GITHUB_TOKEN'] ?? env['GH_TOKEN'];
|
|
275
|
+
const operatorPolicy = env['EVOLVER_ISSUE_SUBMIT_POLICY']?.trim().toLowerCase() === 'allow';
|
|
276
|
+
if (!repo || !token) {
|
|
277
|
+
process.stderr.write('submit requires --repo and GITHUB_TOKEN/GH_TOKEN\n');
|
|
278
|
+
return 1;
|
|
279
|
+
}
|
|
280
|
+
const result = await issueReporter.submitIssueDraft(draft, {
|
|
281
|
+
repo,
|
|
282
|
+
approved: flags.approved || operatorPolicy,
|
|
283
|
+
approvalSource: operatorPolicy ? 'operator_policy' : flags.approved ? 'human' : undefined,
|
|
284
|
+
transport: githubTransport(token, deps.fetch ?? fetch),
|
|
285
|
+
}, options);
|
|
286
|
+
writeResult(flags.json ? publicSubmitResult(result) : `${result.status}: ${result.draft.fingerprint}`, flags.json);
|
|
287
|
+
return result.status === 'submitted' || result.status === 'already_submitted' ? 0 : 1;
|
|
288
|
+
}
|
|
289
|
+
process.stderr.write('用法: evolver issue-report <draft|submit|reject|resolve> ...\n');
|
|
290
|
+
return 1;
|
|
291
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { schema } from '@evomap/evolver-core';
|
|
2
|
+
import { type RuntimeSessionEvidenceCoverage, type RuntimeSessionEvidenceCounts, type RuntimeSessionEvidenceGapCode, type RuntimeSessionEvidenceSummary } from '@evomap/evolver-runtime-adapters';
|
|
2
3
|
import { type RuntimeSessionSource } from './runtimeSessionSource.js';
|
|
3
4
|
export declare const MATERIAL_RUNTIME_SESSION_SNAPSHOT_SCHEMA = "evolver.material.runtime_session_snapshot.v1";
|
|
4
5
|
interface SnapshotTurn {
|
|
@@ -12,6 +13,7 @@ interface SnapshotSource {
|
|
|
12
13
|
agent: string;
|
|
13
14
|
label: string;
|
|
14
15
|
sessionId?: string;
|
|
16
|
+
evidenceSummary: RuntimeSessionEvidenceSummary;
|
|
15
17
|
turns: SnapshotTurn[];
|
|
16
18
|
}
|
|
17
19
|
export interface RuntimeSessionMaterialSnapshotV1 {
|
|
@@ -19,11 +21,33 @@ export interface RuntimeSessionMaterialSnapshotV1 {
|
|
|
19
21
|
sourceKind: 'runtime_session';
|
|
20
22
|
kind: 'session_log';
|
|
21
23
|
sources: SnapshotSource[];
|
|
24
|
+
sourceCount: number;
|
|
25
|
+
omittedSourceCount: number;
|
|
26
|
+
omittedEvidenceAggregate?: RuntimeSessionEvidenceAggregate;
|
|
22
27
|
truncated: boolean;
|
|
23
28
|
maxChars: number;
|
|
24
29
|
}
|
|
30
|
+
export interface RuntimeSessionEvidenceSummarySource {
|
|
31
|
+
agent: string;
|
|
32
|
+
label: string;
|
|
33
|
+
sessionId?: string;
|
|
34
|
+
evidenceSummary: RuntimeSessionEvidenceSummary;
|
|
35
|
+
}
|
|
36
|
+
export interface RuntimeSessionEvidenceAggregate {
|
|
37
|
+
sourceCount: number;
|
|
38
|
+
coverageCounts: Record<RuntimeSessionEvidenceCoverage, number>;
|
|
39
|
+
counts: RuntimeSessionEvidenceCounts;
|
|
40
|
+
gapCodes: RuntimeSessionEvidenceGapCode[];
|
|
41
|
+
}
|
|
42
|
+
export interface RuntimeSessionEvidenceSummaryCollection {
|
|
43
|
+
sourceCount: number;
|
|
44
|
+
omittedSourceCount: number;
|
|
45
|
+
summaries: RuntimeSessionEvidenceSummarySource[];
|
|
46
|
+
omittedEvidenceAggregate?: RuntimeSessionEvidenceAggregate;
|
|
47
|
+
}
|
|
25
48
|
export declare function buildRuntimeSessionMaterialSnapshot(sources: readonly RuntimeSessionSource[], maxChars?: number): RuntimeSessionMaterialSnapshotV1;
|
|
26
49
|
export declare function runtimeSessionSourcesFromMaterialPayload(payload: unknown): RuntimeSessionSource[];
|
|
50
|
+
export declare function runtimeSessionEvidenceSummariesFromMaterialPayload(payload: unknown): RuntimeSessionEvidenceSummaryCollection | null;
|
|
27
51
|
export declare function materialHasRuntimeSessionSnapshot(material: schema.Material): boolean;
|
|
28
52
|
export declare function materialSourceAvailable(material: schema.Material): boolean;
|
|
29
53
|
export declare function runtimeSessionSourcesForMaterial(material: schema.Material, readSource?: (path: string) => string): RuntimeSessionSource[];
|
package/dist/materialSnapshot.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { existsSync } from 'node:fs';
|
|
2
2
|
import { hub, schema } from '@evomap/evolver-core';
|
|
3
|
+
import { summarizeSessionEvidence, } from '@evomap/evolver-runtime-adapters';
|
|
3
4
|
import { parseRuntimeSessionSources } from './runtimeSessionSource.js';
|
|
4
5
|
export const MATERIAL_RUNTIME_SESSION_SNAPSHOT_SCHEMA = 'evolver.material.runtime_session_snapshot.v1';
|
|
5
6
|
const DEFAULT_MATERIAL_SNAPSHOT_MAX_CHARS = 24 * 1024;
|
|
7
|
+
const SNAPSHOT_AGENT_MAX_CHARS = 64;
|
|
8
|
+
const SNAPSHOT_IDENTITY_MAX_CHARS = 256;
|
|
9
|
+
const SNAPSHOT_SOURCE_MAX_COUNT = 32;
|
|
10
|
+
const SNAPSHOT_TURN_MAX_COUNT = 256;
|
|
6
11
|
function isRecord(value) {
|
|
7
12
|
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
8
13
|
}
|
|
@@ -20,19 +25,169 @@ function snapshotTurnText(turn) {
|
|
|
20
25
|
function fitsInline(snapshot) {
|
|
21
26
|
return Buffer.byteLength(JSON.stringify(snapshot), 'utf8') <= schema.MATERIAL_PAYLOAD_INLINE_MAX_BYTES;
|
|
22
27
|
}
|
|
28
|
+
function snapshotIdentity(value, maxChars) {
|
|
29
|
+
return hub.redactString(value).replace(/\s+/g, ' ').trim().slice(0, maxChars);
|
|
30
|
+
}
|
|
31
|
+
function appendEvidenceAggregate(aggregate, summary) {
|
|
32
|
+
const coverageCounts = aggregate
|
|
33
|
+
? { ...aggregate.coverageCounts }
|
|
34
|
+
: { complete: 0, partial: 0, empty: 0 };
|
|
35
|
+
coverageCounts[summary.coverage] += 1;
|
|
36
|
+
const counts = {};
|
|
37
|
+
for (const key of EVIDENCE_COUNT_KEYS) {
|
|
38
|
+
counts[key] = (aggregate?.counts[key] ?? 0) + summary.counts[key];
|
|
39
|
+
}
|
|
40
|
+
const gapCodes = [];
|
|
41
|
+
if (coverageCounts.empty > 0)
|
|
42
|
+
gapCodes.push('empty_session');
|
|
43
|
+
if (counts.missingToolResults > 0)
|
|
44
|
+
gapCodes.push('missing_tool_result');
|
|
45
|
+
if (counts.unmatchedToolResults > 0)
|
|
46
|
+
gapCodes.push('unmatched_tool_result');
|
|
47
|
+
return {
|
|
48
|
+
sourceCount: (aggregate?.sourceCount ?? 0) + 1,
|
|
49
|
+
coverageCounts,
|
|
50
|
+
counts,
|
|
51
|
+
gapCodes,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
const EVIDENCE_COUNT_KEYS = [
|
|
55
|
+
'nonMetaTurns',
|
|
56
|
+
'toolCalls',
|
|
57
|
+
'toolResults',
|
|
58
|
+
'matchedToolResults',
|
|
59
|
+
'missingToolResults',
|
|
60
|
+
'unmatchedToolResults',
|
|
61
|
+
'failedToolResults',
|
|
62
|
+
];
|
|
63
|
+
const EVIDENCE_GAP_CODES = new Set([
|
|
64
|
+
'empty_session',
|
|
65
|
+
'missing_tool_result',
|
|
66
|
+
'unmatched_tool_result',
|
|
67
|
+
]);
|
|
68
|
+
function evidenceSummaryFromSnapshot(value) {
|
|
69
|
+
if (!isRecord(value) || !isRecord(value['counts']) || !Array.isArray(value['gapCodes']))
|
|
70
|
+
return null;
|
|
71
|
+
const coverage = value['coverage'];
|
|
72
|
+
if (coverage !== 'complete' && coverage !== 'partial' && coverage !== 'empty')
|
|
73
|
+
return null;
|
|
74
|
+
const counts = {};
|
|
75
|
+
for (const key of EVIDENCE_COUNT_KEYS) {
|
|
76
|
+
const count = value['counts'][key];
|
|
77
|
+
if (!Number.isSafeInteger(count) || count < 0)
|
|
78
|
+
return null;
|
|
79
|
+
counts[key] = count;
|
|
80
|
+
}
|
|
81
|
+
const gapCodes = value['gapCodes'];
|
|
82
|
+
if (!gapCodes.every((gap) => (typeof gap === 'string' && EVIDENCE_GAP_CODES.has(gap))))
|
|
83
|
+
return null;
|
|
84
|
+
if (new Set(gapCodes).size !== gapCodes.length
|
|
85
|
+
|| counts.toolCalls + counts.toolResults > counts.nonMetaTurns
|
|
86
|
+
|| counts.matchedToolResults > counts.toolCalls
|
|
87
|
+
|| counts.matchedToolResults > counts.toolResults
|
|
88
|
+
|| counts.missingToolResults !== counts.toolCalls - counts.matchedToolResults
|
|
89
|
+
|| counts.unmatchedToolResults !== counts.toolResults - counts.matchedToolResults
|
|
90
|
+
|| counts.failedToolResults > counts.toolResults)
|
|
91
|
+
return null;
|
|
92
|
+
const expectedGaps = [];
|
|
93
|
+
if (counts.nonMetaTurns === 0)
|
|
94
|
+
expectedGaps.push('empty_session');
|
|
95
|
+
else {
|
|
96
|
+
if (counts.missingToolResults > 0)
|
|
97
|
+
expectedGaps.push('missing_tool_result');
|
|
98
|
+
if (counts.unmatchedToolResults > 0)
|
|
99
|
+
expectedGaps.push('unmatched_tool_result');
|
|
100
|
+
}
|
|
101
|
+
const expectedCoverage = counts.nonMetaTurns === 0
|
|
102
|
+
? 'empty'
|
|
103
|
+
: expectedGaps.length > 0 ? 'partial' : 'complete';
|
|
104
|
+
if (coverage !== expectedCoverage
|
|
105
|
+
|| gapCodes.length !== expectedGaps.length
|
|
106
|
+
|| gapCodes.some((gap, index) => gap !== expectedGaps[index]))
|
|
107
|
+
return null;
|
|
108
|
+
return { coverage, counts, gapCodes: [...gapCodes] };
|
|
109
|
+
}
|
|
110
|
+
function evidenceAggregateFromSnapshot(value) {
|
|
111
|
+
if (!isRecord(value)
|
|
112
|
+
|| !Number.isSafeInteger(value['sourceCount'])
|
|
113
|
+
|| value['sourceCount'] <= 0
|
|
114
|
+
|| !isRecord(value['coverageCounts'])
|
|
115
|
+
|| !isRecord(value['counts'])
|
|
116
|
+
|| !Array.isArray(value['gapCodes']))
|
|
117
|
+
return null;
|
|
118
|
+
const sourceCount = value['sourceCount'];
|
|
119
|
+
const coverageCounts = {};
|
|
120
|
+
for (const coverage of ['complete', 'partial', 'empty']) {
|
|
121
|
+
const count = value['coverageCounts'][coverage];
|
|
122
|
+
if (!Number.isSafeInteger(count) || count < 0)
|
|
123
|
+
return null;
|
|
124
|
+
coverageCounts[coverage] = count;
|
|
125
|
+
}
|
|
126
|
+
if (coverageCounts.complete + coverageCounts.partial + coverageCounts.empty !== sourceCount)
|
|
127
|
+
return null;
|
|
128
|
+
const counts = {};
|
|
129
|
+
for (const key of EVIDENCE_COUNT_KEYS) {
|
|
130
|
+
const count = value['counts'][key];
|
|
131
|
+
if (!Number.isSafeInteger(count) || count < 0)
|
|
132
|
+
return null;
|
|
133
|
+
counts[key] = count;
|
|
134
|
+
}
|
|
135
|
+
const gapCodes = value['gapCodes'];
|
|
136
|
+
if (!gapCodes.every((gap) => (typeof gap === 'string' && EVIDENCE_GAP_CODES.has(gap))) || new Set(gapCodes).size !== gapCodes.length
|
|
137
|
+
|| counts.toolCalls + counts.toolResults > counts.nonMetaTurns
|
|
138
|
+
|| counts.matchedToolResults > counts.toolCalls
|
|
139
|
+
|| counts.matchedToolResults > counts.toolResults
|
|
140
|
+
|| counts.missingToolResults !== counts.toolCalls - counts.matchedToolResults
|
|
141
|
+
|| counts.unmatchedToolResults !== counts.toolResults - counts.matchedToolResults
|
|
142
|
+
|| counts.failedToolResults > counts.toolResults)
|
|
143
|
+
return null;
|
|
144
|
+
const nonEmptySourceCount = coverageCounts.complete + coverageCounts.partial;
|
|
145
|
+
const structuralGapCount = counts.missingToolResults + counts.unmatchedToolResults;
|
|
146
|
+
if (counts.nonMetaTurns < nonEmptySourceCount
|
|
147
|
+
|| (coverageCounts.empty === sourceCount && counts.nonMetaTurns !== 0)
|
|
148
|
+
|| (coverageCounts.partial > 0) !== (structuralGapCount > 0)
|
|
149
|
+
|| structuralGapCount < coverageCounts.partial)
|
|
150
|
+
return null;
|
|
151
|
+
const expectedGaps = [];
|
|
152
|
+
if (coverageCounts.empty > 0)
|
|
153
|
+
expectedGaps.push('empty_session');
|
|
154
|
+
if (counts.missingToolResults > 0)
|
|
155
|
+
expectedGaps.push('missing_tool_result');
|
|
156
|
+
if (counts.unmatchedToolResults > 0)
|
|
157
|
+
expectedGaps.push('unmatched_tool_result');
|
|
158
|
+
if (gapCodes.length !== expectedGaps.length
|
|
159
|
+
|| gapCodes.some((gap, index) => gap !== expectedGaps[index]))
|
|
160
|
+
return null;
|
|
161
|
+
return { sourceCount, coverageCounts, counts, gapCodes: [...gapCodes] };
|
|
162
|
+
}
|
|
23
163
|
export function buildRuntimeSessionMaterialSnapshot(sources, maxChars = DEFAULT_MATERIAL_SNAPSHOT_MAX_CHARS) {
|
|
24
|
-
const safeMaxChars =
|
|
164
|
+
const safeMaxChars = Number.isFinite(maxChars)
|
|
165
|
+
? Math.max(0, Math.min(Math.trunc(maxChars), DEFAULT_MATERIAL_SNAPSHOT_MAX_CHARS))
|
|
166
|
+
: 0;
|
|
25
167
|
let remaining = safeMaxChars;
|
|
26
168
|
let truncated = false;
|
|
169
|
+
let retainedTurnCount = 0;
|
|
170
|
+
let omittedEvidenceAggregate;
|
|
27
171
|
const snapshotSources = [];
|
|
28
172
|
for (const source of sources) {
|
|
173
|
+
const evidenceSummary = summarizeSessionEvidence({ turns: source.turns });
|
|
174
|
+
if (snapshotSources.length >= SNAPSHOT_SOURCE_MAX_COUNT) {
|
|
175
|
+
omittedEvidenceAggregate = appendEvidenceAggregate(omittedEvidenceAggregate, evidenceSummary);
|
|
176
|
+
truncated = true;
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
29
179
|
const turns = [];
|
|
30
180
|
for (const turn of source.turns) {
|
|
181
|
+
if (retainedTurnCount >= SNAPSHOT_TURN_MAX_COUNT) {
|
|
182
|
+
truncated = true;
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
31
185
|
const rawText = snapshotTurnText(turn);
|
|
32
186
|
const trimmed = trimText(rawText, remaining);
|
|
33
187
|
remaining -= trimmed.used;
|
|
34
188
|
truncated = truncated || trimmed.truncated;
|
|
35
189
|
if (trimmed.text.length > 0) {
|
|
190
|
+
retainedTurnCount += 1;
|
|
36
191
|
turns.push({
|
|
37
192
|
role: turn.role,
|
|
38
193
|
text: trimmed.text,
|
|
@@ -46,29 +201,41 @@ export function buildRuntimeSessionMaterialSnapshot(sources, maxChars = DEFAULT_
|
|
|
46
201
|
break;
|
|
47
202
|
}
|
|
48
203
|
}
|
|
204
|
+
const safeSessionId = source.sessionId
|
|
205
|
+
? snapshotIdentity(source.sessionId, SNAPSHOT_IDENTITY_MAX_CHARS)
|
|
206
|
+
: '';
|
|
49
207
|
snapshotSources.push({
|
|
50
|
-
agent: source.agent,
|
|
51
|
-
label: source.label,
|
|
52
|
-
...(
|
|
208
|
+
agent: snapshotIdentity(source.agent, SNAPSHOT_AGENT_MAX_CHARS) || 'unknown',
|
|
209
|
+
label: snapshotIdentity(source.label, SNAPSHOT_IDENTITY_MAX_CHARS) || 'unknown',
|
|
210
|
+
...(safeSessionId ? { sessionId: safeSessionId } : {}),
|
|
211
|
+
evidenceSummary,
|
|
53
212
|
turns,
|
|
54
213
|
});
|
|
55
|
-
if (remaining <= 0)
|
|
56
|
-
break;
|
|
57
214
|
}
|
|
58
215
|
const snapshot = {
|
|
59
216
|
schema: MATERIAL_RUNTIME_SESSION_SNAPSHOT_SCHEMA,
|
|
60
217
|
sourceKind: 'runtime_session',
|
|
61
218
|
kind: 'session_log',
|
|
62
219
|
sources: snapshotSources,
|
|
63
|
-
|
|
220
|
+
sourceCount: sources.length,
|
|
221
|
+
omittedSourceCount: omittedEvidenceAggregate?.sourceCount ?? 0,
|
|
222
|
+
...(omittedEvidenceAggregate ? { omittedEvidenceAggregate } : {}),
|
|
223
|
+
truncated: truncated || omittedEvidenceAggregate !== undefined,
|
|
64
224
|
maxChars: safeMaxChars,
|
|
65
225
|
};
|
|
226
|
+
// Source and turn caps make this loop constant-bounded even for very large Cursor databases.
|
|
66
227
|
while (!fitsInline(snapshot) && snapshot.sources.length > 0) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
228
|
+
let sourceWithTurns = snapshot.sources.length - 1;
|
|
229
|
+
while (sourceWithTurns >= 0 && snapshot.sources[sourceWithTurns]?.turns.length === 0) {
|
|
230
|
+
sourceWithTurns -= 1;
|
|
231
|
+
}
|
|
232
|
+
if (sourceWithTurns >= 0)
|
|
233
|
+
snapshot.sources[sourceWithTurns].turns.pop();
|
|
234
|
+
else {
|
|
235
|
+
const omitted = snapshot.sources.pop();
|
|
236
|
+
snapshot.omittedEvidenceAggregate = appendEvidenceAggregate(snapshot.omittedEvidenceAggregate, omitted.evidenceSummary);
|
|
237
|
+
snapshot.omittedSourceCount += 1;
|
|
238
|
+
}
|
|
72
239
|
snapshot.truncated = true;
|
|
73
240
|
}
|
|
74
241
|
return snapshot;
|
|
@@ -122,6 +289,61 @@ export function runtimeSessionSourcesFromMaterialPayload(payload) {
|
|
|
122
289
|
.map(sourceFromSnapshot)
|
|
123
290
|
.filter((source) => source !== null);
|
|
124
291
|
}
|
|
292
|
+
export function runtimeSessionEvidenceSummariesFromMaterialPayload(payload) {
|
|
293
|
+
if (!isRecord(payload))
|
|
294
|
+
return null;
|
|
295
|
+
if (payload['schema'] !== MATERIAL_RUNTIME_SESSION_SNAPSHOT_SCHEMA)
|
|
296
|
+
return null;
|
|
297
|
+
if (payload['sourceKind'] !== 'runtime_session' || payload['kind'] !== 'session_log')
|
|
298
|
+
return null;
|
|
299
|
+
const sources = Array.isArray(payload['sources']) ? payload['sources'] : [];
|
|
300
|
+
const hasCountMetadata = payload['sourceCount'] !== undefined || payload['omittedSourceCount'] !== undefined;
|
|
301
|
+
const sourceCount = hasCountMetadata ? payload['sourceCount'] : sources.length;
|
|
302
|
+
const omittedSourceCount = hasCountMetadata ? payload['omittedSourceCount'] : 0;
|
|
303
|
+
if (!Number.isSafeInteger(sourceCount)
|
|
304
|
+
|| sourceCount < sources.length
|
|
305
|
+
|| !Number.isSafeInteger(omittedSourceCount)
|
|
306
|
+
|| omittedSourceCount < 0
|
|
307
|
+
|| omittedSourceCount !== sourceCount - sources.length)
|
|
308
|
+
return null;
|
|
309
|
+
const omittedEvidenceAggregate = payload['omittedEvidenceAggregate'] === undefined
|
|
310
|
+
? undefined
|
|
311
|
+
: evidenceAggregateFromSnapshot(payload['omittedEvidenceAggregate']);
|
|
312
|
+
if (omittedSourceCount > 0) {
|
|
313
|
+
if (!omittedEvidenceAggregate || omittedEvidenceAggregate.sourceCount !== omittedSourceCount)
|
|
314
|
+
return null;
|
|
315
|
+
}
|
|
316
|
+
else if (payload['omittedEvidenceAggregate'] !== undefined)
|
|
317
|
+
return null;
|
|
318
|
+
const summaries = sources.flatMap((source) => {
|
|
319
|
+
if (!isRecord(source)
|
|
320
|
+
|| typeof source['agent'] !== 'string'
|
|
321
|
+
|| !source['agent'].trim()
|
|
322
|
+
|| typeof source['label'] !== 'string'
|
|
323
|
+
|| !source['label'].trim())
|
|
324
|
+
return [];
|
|
325
|
+
const summary = evidenceSummaryFromSnapshot(source['evidenceSummary']);
|
|
326
|
+
if (!summary)
|
|
327
|
+
return [];
|
|
328
|
+
const sessionId = typeof source['sessionId'] === 'string' && source['sessionId'].trim()
|
|
329
|
+
? source['sessionId']
|
|
330
|
+
: undefined;
|
|
331
|
+
return [{
|
|
332
|
+
agent: source['agent'],
|
|
333
|
+
label: source['label'],
|
|
334
|
+
...(sessionId ? { sessionId } : {}),
|
|
335
|
+
evidenceSummary: summary,
|
|
336
|
+
}];
|
|
337
|
+
});
|
|
338
|
+
if (hasCountMetadata && summaries.length !== sources.length)
|
|
339
|
+
return null;
|
|
340
|
+
return {
|
|
341
|
+
sourceCount: sourceCount,
|
|
342
|
+
omittedSourceCount: omittedSourceCount,
|
|
343
|
+
summaries,
|
|
344
|
+
...(omittedEvidenceAggregate ? { omittedEvidenceAggregate } : {}),
|
|
345
|
+
};
|
|
346
|
+
}
|
|
125
347
|
export function materialHasRuntimeSessionSnapshot(material) {
|
|
126
348
|
return runtimeSessionSourcesFromMaterialPayload(material.payload).length > 0;
|
|
127
349
|
}
|
package/dist/recipe.js
CHANGED
|
@@ -701,10 +701,16 @@ function resolveRecipeHubCredentials(env) {
|
|
|
701
701
|
* the next recipe run (H3). Kept env-pure (no events.evomapHome()) so reset stays hermetic under an injected env.
|
|
702
702
|
*/
|
|
703
703
|
export function explicitRecipeHomes(env) {
|
|
704
|
+
// Identity-first order (#555 T2): EVOMAP_HOME is THE identity home and outranks the state root
|
|
705
|
+
// (EVOLVER_HOME). This order decides BOTH the read fall-through AND rotatePersistDir (= homes[0]),
|
|
706
|
+
// so under the evox agentDir split (EVOMAP_HOME=<agentDir>/evomap, EVOLVER_HOME=<agentDir>/evolver)
|
|
707
|
+
// a hub-rotated secret persists into the evomap dir the desktop actually reads — the old
|
|
708
|
+
// EVOLVER_HOME-first order would strand it in the state root and split-brain the node on rotation.
|
|
709
|
+
// Read-your-writes holds because read and persist share this one order; single-home setups are unchanged.
|
|
704
710
|
const explicit = [
|
|
711
|
+
env['EVOMAP_HOME'],
|
|
705
712
|
env['EVOMAP_DIR'],
|
|
706
713
|
env['EVOLVER_HOME'],
|
|
707
|
-
env['EVOMAP_HOME'],
|
|
708
714
|
];
|
|
709
715
|
return uniqueStrings(explicit.map((value) => value?.trim()).filter((value) => Boolean(value)));
|
|
710
716
|
}
|
package/dist/reuse.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { assetstore, hub as hubNs } from '@evomap/evolver-core';
|
|
2
2
|
import type { ConnectPublicOptions, PublicHubCapability } from '@evomap/evolver-adapter-public';
|
|
3
3
|
declare const REUSE_CONTRACT = "reuse.v1";
|
|
4
|
-
export type ReuseStatus = 'ok' | 'dry_run' | 'invalid_arg' | 'missing_id' | 'unsupported' | 'not_found' | 'unauthorized' | 'unavailable' | 'network' | 'internal_error';
|
|
4
|
+
export type ReuseStatus = 'ok' | 'dry_run' | 'invalid_arg' | 'missing_id' | 'unsupported' | 'not_found' | 'unauthorized' | 'unavailable' | 'network' | 'rate_limited' | 'internal_error';
|
|
5
5
|
/** The stable reuse.v1 machine contract printed to stdout on success AND failure. Field set is locked by the
|
|
6
6
|
* consumer (evox-desktop `evolverReuseEnvelope`, #1008): { ok, contract, status, reason, message }. */
|
|
7
7
|
export interface ReuseEnvelope {
|
|
@@ -11,9 +11,14 @@ export interface ReuseEnvelope {
|
|
|
11
11
|
reason: string;
|
|
12
12
|
message: string;
|
|
13
13
|
}
|
|
14
|
-
/** Minimal hub surface this command needs:
|
|
14
|
+
/** Minimal hub surface this command needs: a single fetch-by-id, plus an optional trust-establishing hello
|
|
15
|
+
* (PublicHubCapability satisfies both; a bare fetcher in tests may omit hello). */
|
|
15
16
|
type AssetByIdFetcher = {
|
|
16
17
|
fetchAssetById(assetId: string): Promise<assetstore.AssetRecord | null>;
|
|
18
|
+
hello?(opts: {
|
|
19
|
+
rotate: boolean;
|
|
20
|
+
evolverVersion?: string;
|
|
21
|
+
}): Promise<unknown>;
|
|
17
22
|
};
|
|
18
23
|
export interface ReuseCliDeps {
|
|
19
24
|
store?: assetstore.AssetStoreProvider;
|
package/dist/reuse.js
CHANGED
|
@@ -14,6 +14,7 @@ import { assetstore, events, hub as hubNs, wire } from '@evomap/evolver-core';
|
|
|
14
14
|
import { AuthError, HubClientError, HubUnreachableError, connectPublicHub, isHubDryRunEnabled } from '@evomap/evolver-adapter-public';
|
|
15
15
|
import { loadEnvFileFromEnv } from '@evomap/evolver-mcp';
|
|
16
16
|
import { createRecipeHubFromEnv } from './recipe.js';
|
|
17
|
+
import { getCliVersion } from './version.js';
|
|
17
18
|
const REUSE_CONTRACT = 'reuse.v1';
|
|
18
19
|
const MAX_ID_LENGTH = 200;
|
|
19
20
|
const REUSE_USAGE = [
|
|
@@ -86,6 +87,11 @@ export async function runReuseCommand(argv, deps = {}) {
|
|
|
86
87
|
}
|
|
87
88
|
// 3) Pull the global asset by id, write it into the local recall library (put dedups → idempotent on repeat).
|
|
88
89
|
const hub = deps.hub ?? createRecipeHubFromEnv(env, deps.connectHub ?? connectPublicHub);
|
|
90
|
+
// One-shot CLIs never heartbeat, so the hub may hold no env fingerprint for this node and its anti-abuse
|
|
91
|
+
// layer then 403s /a2a/fetch (`bulk_fetch_blocked: IP antibody`, #555). A fingerprinted hello
|
|
92
|
+
// (rotate:false — never requests secret rotation) establishes that trust first. Best-effort by design:
|
|
93
|
+
// a hello failure must not block the fetch — the fetch's own error path classifies precisely.
|
|
94
|
+
await establishReuseTrust(hub);
|
|
89
95
|
const asset = await hub.fetchAssetById(opts.id);
|
|
90
96
|
if (!asset)
|
|
91
97
|
return emit({ ok: false, status: 'not_found', message: `asset ${opts.id} not found on the hub` }, ctx);
|
|
@@ -232,17 +238,48 @@ function logReuse(deps, opts, asset, source) {
|
|
|
232
238
|
extra: { source },
|
|
233
239
|
});
|
|
234
240
|
}
|
|
241
|
+
async function establishReuseTrust(hub) {
|
|
242
|
+
if (typeof hub.hello !== 'function')
|
|
243
|
+
return;
|
|
244
|
+
try {
|
|
245
|
+
await hub.hello({ rotate: false, evolverVersion: getCliVersion() });
|
|
246
|
+
}
|
|
247
|
+
catch { /* fetch decides the outcome */ }
|
|
248
|
+
}
|
|
249
|
+
const ANTI_ABUSE_BLOCK_MESSAGE = 'hub anti-abuse temporarily blocked asset fetch for this node; keep the local Evolver proxy running so the node builds trust, then retry';
|
|
250
|
+
function antiAbuseOutcome() {
|
|
251
|
+
return { ok: false, status: 'rate_limited', message: ANTI_ABUSE_BLOCK_MESSAGE };
|
|
252
|
+
}
|
|
253
|
+
function isAntiAbuseFetchBlock(status, code) {
|
|
254
|
+
return status === 403 && code !== undefined && /antibody|bulk_fetch|anti[-_]?abuse/i.test(code);
|
|
255
|
+
}
|
|
256
|
+
function hubErrorField(body) {
|
|
257
|
+
if (!body || typeof body !== 'object')
|
|
258
|
+
return undefined;
|
|
259
|
+
const err = body['error'];
|
|
260
|
+
return typeof err === 'string' ? err : undefined;
|
|
261
|
+
}
|
|
235
262
|
function mapError(e) {
|
|
236
|
-
if (e instanceof AuthError)
|
|
263
|
+
if (e instanceof AuthError) {
|
|
264
|
+
// hubFetch raises AuthError for BOTH 401 and 403, so the hub's anti-abuse 403
|
|
265
|
+
// (`bulk_fetch_blocked: IP antibody active`) used to be misreported as "log in" — it is an
|
|
266
|
+
// abuse-control block on a perfectly healthy credential, not an auth failure (#555).
|
|
267
|
+
if (isAntiAbuseFetchBlock(e.status, e.errorCode))
|
|
268
|
+
return antiAbuseOutcome();
|
|
237
269
|
return { ok: false, status: 'unauthorized', message: 'hub authentication failed; run `evolver login` or set EVOMAP_NODE_SECRET' };
|
|
270
|
+
}
|
|
238
271
|
if (e instanceof HubUnreachableError)
|
|
239
272
|
return { ok: false, status: 'network', message: 'hub is unreachable' };
|
|
240
273
|
if (e instanceof HubClientError) {
|
|
274
|
+
if (e.status === 429)
|
|
275
|
+
return { ok: false, status: 'rate_limited', message: 'hub rate limited the request; retry later' };
|
|
276
|
+
if (isAntiAbuseFetchBlock(e.status, hubErrorField(e.body)))
|
|
277
|
+
return antiAbuseOutcome();
|
|
241
278
|
if (e.status === 401 || e.status === 403)
|
|
242
279
|
return { ok: false, status: 'unauthorized', message: 'hub authentication failed; run `evolver login` or set EVOMAP_NODE_SECRET' };
|
|
243
280
|
if (e.status === 404)
|
|
244
281
|
return { ok: false, status: 'not_found', message: 'asset not found on the hub' };
|
|
245
|
-
if (e.status
|
|
282
|
+
if (e.status >= 500)
|
|
246
283
|
return { ok: false, status: 'network', message: 'hub is temporarily unavailable' };
|
|
247
284
|
return { ok: false, status: 'internal_error', message: 'hub rejected the reuse request' };
|
|
248
285
|
}
|
package/dist/setupHooks.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
import { type InstallScope } from '@evomap/evolver-mcp';
|
|
1
2
|
import { assetstore } from '@evomap/evolver-core';
|
|
2
3
|
import { maybeEmitNonGitWorkspaceNotice } from './nonGitWorkspaceNotice.js';
|
|
3
4
|
interface SetupHooksDeps {
|
|
4
5
|
emitNonGitWorkspaceNotice?: typeof maybeEmitNonGitWorkspaceNotice;
|
|
6
|
+
runtimeAvailable?: (runtime: 'opencode' | 'kiro', configRoot: string, scope: InstallScope) => boolean;
|
|
5
7
|
}
|
|
8
|
+
export declare function commandNamesForPath(command: string, platform: NodeJS.Platform, pathExt: string | undefined): string[];
|
|
9
|
+
export declare function safeSetupOperationError(error: unknown): string;
|
|
10
|
+
export declare function safeSetupResultError(error: unknown): string;
|
|
6
11
|
export declare function runSetupHooks(argv: readonly string[], store?: assetstore.AssetStoreProvider, review?: assetstore.ReviewLedger, deps?: SetupHooksDeps): Promise<number>;
|
|
7
12
|
export {};
|
package/dist/setupHooks.js
CHANGED
|
@@ -4,10 +4,12 @@
|
|
|
4
4
|
// (the real device-wide scope); `--scope=project` (default) writes the project's own .mcp.json. Deny-nothing:
|
|
5
5
|
// it only writes the runtime's own config, is idempotent, refuses symlinked adapter paths, and `--uninstall`
|
|
6
6
|
// cleanly removes only evolver's entries.
|
|
7
|
-
import { planInjection, installInjection, uninstallInjection, runtimeSupport, renderManualWiring, renderServiceGuidance, SETUP_RUNTIMES, SERVICE_TARGETS } from '@evomap/evolver-mcp';
|
|
7
|
+
import { planInjection, installInjection, uninstallInjection, runtimeSupport, renderManualWiring, renderServiceGuidance, SETUP_RUNTIMES, SERVICE_TARGETS, kiroConfigRoot, resolveOpenCodeConfig, McpConfigConflictError, McpConfigOwnershipError, McpConfigVerificationError, McpServerValidationError } from '@evomap/evolver-mcp';
|
|
8
8
|
import { assetstore, events } from '@evomap/evolver-core';
|
|
9
|
-
import { readFileSync } from 'node:fs';
|
|
9
|
+
import { accessSync, constants, existsSync, readFileSync, statSync } from 'node:fs';
|
|
10
10
|
import { createRequire } from 'node:module';
|
|
11
|
+
import { homedir } from 'node:os';
|
|
12
|
+
import { delimiter, dirname, isAbsolute, join, relative, sep } from 'node:path';
|
|
11
13
|
import { fileURLToPath } from 'node:url';
|
|
12
14
|
import { currentTopCursorGenes } from './cursorRewrite.js';
|
|
13
15
|
import { resolveProxyBinPath, resolveStableNodePath } from './lifecycle.js';
|
|
@@ -34,7 +36,133 @@ function parseFlags(argv) {
|
|
|
34
36
|
}
|
|
35
37
|
return out;
|
|
36
38
|
}
|
|
37
|
-
const USAGE = `usage: evolver setup-hooks [--runtime=${SETUP_RUNTIMES.join('|')}] [--scope=user|project|global] [--root=<dir>] [--env-file=<path>] [--profile-descriptor=<json>] [--service=${SERVICE_TARGETS.join('|')}] [--uninstall] [--force] [--json] [--hook-command="evolver inject session-start"] [--server-command=<cmd>] [--server-args=a,b] [--service-command=<cmd>] [--service-args=a,b]\n`;
|
|
39
|
+
const USAGE = `usage: evolver setup-hooks [--runtime=${SETUP_RUNTIMES.join('|')}] [--scope=user|project|global] [--root=<dir>] [--env-file=<path>] [--profile-descriptor=<json>] [--service=${SERVICE_TARGETS.join('|')}] [--uninstall] [--dry-run] [--force] [--json] [--hook-command="evolver inject session-start"] [--server-command=<cmd>] [--server-args=a,b] [--service-command=<cmd>] [--service-args=a,b]\n`;
|
|
40
|
+
export function commandNamesForPath(command, platform, pathExt) {
|
|
41
|
+
if (platform !== 'win32' || /\.[^\\/]+$/.test(command))
|
|
42
|
+
return [command];
|
|
43
|
+
const extensions = (pathExt?.trim() || '.COM;.EXE;.BAT;.CMD')
|
|
44
|
+
.split(';')
|
|
45
|
+
.map((extension) => extension.trim())
|
|
46
|
+
.filter((extension) => /^\.?[A-Za-z\d]+$/.test(extension))
|
|
47
|
+
.map((extension) => extension.startsWith('.') ? extension : `.${extension}`);
|
|
48
|
+
return [command, ...extensions.map((extension) => `${command}${extension}`)];
|
|
49
|
+
}
|
|
50
|
+
function commandOnPath(command) {
|
|
51
|
+
const names = commandNamesForPath(command, process.platform, process.env['PATHEXT']);
|
|
52
|
+
for (const directory of (process.env['PATH'] ?? '').split(delimiter).filter(Boolean)) {
|
|
53
|
+
for (const name of names) {
|
|
54
|
+
try {
|
|
55
|
+
const candidate = join(directory, name);
|
|
56
|
+
if (!statSync(candidate).isFile())
|
|
57
|
+
continue;
|
|
58
|
+
accessSync(candidate, constants.X_OK);
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
// Continue searching PATH.
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
function defaultRuntimeAvailable(runtime, configRoot, scope) {
|
|
69
|
+
if (runtime === 'opencode') {
|
|
70
|
+
const resolution = resolveOpenCodeConfig({
|
|
71
|
+
configRoot,
|
|
72
|
+
scope,
|
|
73
|
+
homeDir: homedir(),
|
|
74
|
+
xdgConfigHome: process.env['XDG_CONFIG_HOME'],
|
|
75
|
+
opencodeConfig: process.env['OPENCODE_CONFIG'],
|
|
76
|
+
opencodeConfigDir: process.env['OPENCODE_CONFIG_DIR'],
|
|
77
|
+
});
|
|
78
|
+
return commandOnPath('opencode') || (resolution.evidencePaths ?? [resolution.configPath]).some(existsSync);
|
|
79
|
+
}
|
|
80
|
+
const pathOptions = {
|
|
81
|
+
configRoot,
|
|
82
|
+
homeDir: homedir(),
|
|
83
|
+
kiroHome: process.env['KIRO_HOME'],
|
|
84
|
+
};
|
|
85
|
+
const evidenceRoots = scope === 'project'
|
|
86
|
+
? [
|
|
87
|
+
kiroConfigRoot({ ...pathOptions, scope: 'project' }),
|
|
88
|
+
kiroConfigRoot({ ...pathOptions, scope: 'user' }),
|
|
89
|
+
]
|
|
90
|
+
: [kiroConfigRoot({ ...pathOptions, scope: 'user' })];
|
|
91
|
+
return commandOnPath('kiro') || commandOnPath('kiro-cli') || evidenceRoots.some(existsSync);
|
|
92
|
+
}
|
|
93
|
+
function displaySetupPath(path, configRoot, scope) {
|
|
94
|
+
if (scope === 'user') {
|
|
95
|
+
const home = homedir();
|
|
96
|
+
const homePath = safeRelativePath(home, path);
|
|
97
|
+
if (homePath === '')
|
|
98
|
+
return '~';
|
|
99
|
+
if (homePath !== undefined)
|
|
100
|
+
return `~/${homePath.replaceAll('\\', '/')}`;
|
|
101
|
+
}
|
|
102
|
+
const projectPath = safeProjectRelativePath(configRoot, path);
|
|
103
|
+
if (projectPath === '')
|
|
104
|
+
return '.';
|
|
105
|
+
return projectPath !== undefined ? projectPath.replaceAll('\\', '/') : '<config-path>';
|
|
106
|
+
}
|
|
107
|
+
function safeRelativePath(root, path) {
|
|
108
|
+
const candidate = relative(root, path);
|
|
109
|
+
if (isAbsolute(candidate) || candidate === '..' || candidate.startsWith(`..${sep}`))
|
|
110
|
+
return undefined;
|
|
111
|
+
return candidate;
|
|
112
|
+
}
|
|
113
|
+
function safeProjectRelativePath(root, path) {
|
|
114
|
+
const descendant = safeRelativePath(root, path);
|
|
115
|
+
if (descendant !== undefined)
|
|
116
|
+
return descendant;
|
|
117
|
+
return safeRelativePath(dirname(path), root) === undefined ? undefined : relative(root, path);
|
|
118
|
+
}
|
|
119
|
+
function displayResultPaths(paths, configRoot, scope) {
|
|
120
|
+
return paths?.map((path) => displaySetupPath(path, configRoot, scope));
|
|
121
|
+
}
|
|
122
|
+
export function safeSetupOperationError(error) {
|
|
123
|
+
if (error instanceof McpConfigConflictError)
|
|
124
|
+
return error.message;
|
|
125
|
+
if (error instanceof McpConfigOwnershipError)
|
|
126
|
+
return error.message;
|
|
127
|
+
if (error instanceof McpConfigVerificationError) {
|
|
128
|
+
return error.restored
|
|
129
|
+
? '[setup-hooks] runtime configuration verification failed; the previous configuration was restored.'
|
|
130
|
+
: '[setup-hooks] runtime configuration verification failed; rollback could not be confirmed. Inspect the runtime config before retrying.';
|
|
131
|
+
}
|
|
132
|
+
if (error instanceof McpServerValidationError)
|
|
133
|
+
return error.message;
|
|
134
|
+
const name = error instanceof Error ? error.name : '';
|
|
135
|
+
switch (name) {
|
|
136
|
+
case 'McpConfigConflictError': return '[setup-hooks] existing Evolver configuration conflicts; use --force to replace only the Evolver entry.';
|
|
137
|
+
case 'McpConfigOwnershipError': return '[setup-hooks] Evolver ownership metadata is ambiguous or no longer matches the runtime configuration; inspect it before retrying.';
|
|
138
|
+
case 'McpConfigShapeError': return '[setup-hooks] runtime configuration has an invalid JSON shape.';
|
|
139
|
+
case 'McpConfigVerificationError': return error.restored === true
|
|
140
|
+
? '[setup-hooks] runtime configuration verification failed; the previous configuration was restored.'
|
|
141
|
+
: '[setup-hooks] runtime configuration verification failed; rollback could not be confirmed. Inspect the runtime config before retrying.';
|
|
142
|
+
case 'McpConfigChangedError': return '[setup-hooks] runtime configuration changed during the operation; retry after the runtime finishes writing it.';
|
|
143
|
+
case 'EmptySharedConfigError': return '[setup-hooks] runtime configuration is empty; repair or remove it before retrying.';
|
|
144
|
+
case 'UnparseableConfigError': return '[setup-hooks] runtime configuration is not valid JSON; repair it before retrying.';
|
|
145
|
+
case 'SymlinkRefusedError': return '[setup-hooks] refused an unsafe symbolic-link configuration path.';
|
|
146
|
+
default: return '[setup-hooks] runtime configuration operation failed.';
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
export function safeSetupResultError(error) {
|
|
150
|
+
if (typeof error !== 'string')
|
|
151
|
+
return safeSetupOperationError(error);
|
|
152
|
+
const reason = error.replace(/\s+/g, ' ').trim();
|
|
153
|
+
const passive = reason.match(/^passive runtime ([a-z0-9][a-z0-9-]{0,63}): no tool injection$/);
|
|
154
|
+
const unimplementedInstall = reason.match(/^installer not yet implemented for ([a-z0-9][a-z0-9-]{0,63}) \(supported: [a-z0-9, -]+\)$/);
|
|
155
|
+
const unimplementedUninstall = reason.match(/^uninstall not implemented for ([a-z0-9][a-z0-9-]{0,63})$/);
|
|
156
|
+
const runtime = passive?.[1] ?? unimplementedInstall?.[1] ?? unimplementedUninstall?.[1];
|
|
157
|
+
if (!runtime || !SETUP_RUNTIMES.includes(runtime)) {
|
|
158
|
+
return safeSetupOperationError(error);
|
|
159
|
+
}
|
|
160
|
+
if (passive)
|
|
161
|
+
return `[setup-hooks] passive runtime ${runtime}: no tool injection`;
|
|
162
|
+
if (unimplementedInstall)
|
|
163
|
+
return `[setup-hooks] installer not yet implemented for ${runtime}`;
|
|
164
|
+
return `[setup-hooks] uninstall not implemented for ${runtime}`;
|
|
165
|
+
}
|
|
38
166
|
const PROFILE_DESCRIPTOR_FLAG = 'profile-descriptor';
|
|
39
167
|
const SECRET_ASSIGNMENT_RE = /\b(?:A2A_NODE_SECRET|EVOMAP_ENTERPRISE_TOKEN|EVOMAP_PRIVATE_HUB_TOKEN|EVOMAP_NODE_SECRET|EVOLVER_IPC_TOKEN|EVOLVER_LLM_TOKEN|PHUB_ENTERPRISE_TOKEN|PRIVATE_HUB_ENTERPRISE_TOKEN)\b\s*[:=]\s*["']?[^"'\s<]+/;
|
|
40
168
|
const INLINE_BEARER_RE = /\bBearer\s+(?!<|\$|%|REDACTED\b|TOKEN\b|token\b|env:)[A-Za-z0-9._~+/=-]{12,}/i;
|
|
@@ -306,19 +434,57 @@ export async function runSetupHooks(argv, store, review, deps = {}) {
|
|
|
306
434
|
const configRoot = typeof f['root'] === 'string' ? f['root'] : process.cwd();
|
|
307
435
|
// claude-code: user scope targets ~/.claude.json regardless of --root; project scope uses configRoot.
|
|
308
436
|
const scope = scopeResult.scope;
|
|
437
|
+
if (f['dry-run'] === true && runtime !== 'opencode' && runtime !== 'kiro') {
|
|
438
|
+
const error = `--dry-run is currently supported for opencode and kiro setup only; no config was written.`;
|
|
439
|
+
if (json)
|
|
440
|
+
emit({ runtime, outcome: 'error', files: [], error });
|
|
441
|
+
else
|
|
442
|
+
process.stderr.write(`${error}\n`);
|
|
443
|
+
return 1;
|
|
444
|
+
}
|
|
309
445
|
if (support.outcome === 'installed' && f['uninstall']) {
|
|
310
|
-
|
|
446
|
+
let r;
|
|
447
|
+
try {
|
|
448
|
+
r = uninstallInjection(runtime, {
|
|
449
|
+
configRoot,
|
|
450
|
+
scope,
|
|
451
|
+
homeDir: homedir(),
|
|
452
|
+
kiroHome: process.env['KIRO_HOME'],
|
|
453
|
+
xdgConfigHome: process.env['XDG_CONFIG_HOME'],
|
|
454
|
+
opencodeConfig: process.env['OPENCODE_CONFIG'],
|
|
455
|
+
opencodeConfigDir: process.env['OPENCODE_CONFIG_DIR'],
|
|
456
|
+
dryRun: f['dry-run'] === true,
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
catch (error) {
|
|
460
|
+
const message = safeSetupOperationError(error);
|
|
461
|
+
if (json)
|
|
462
|
+
emit({ runtime, action: 'uninstall', files: [], error: message });
|
|
463
|
+
else
|
|
464
|
+
process.stderr.write(`${message}\n`);
|
|
465
|
+
return 1;
|
|
466
|
+
}
|
|
467
|
+
const files = displayResultPaths(r.files, configRoot, scope) ?? [];
|
|
468
|
+
const backups = displayResultPaths(r.backups, configRoot, scope);
|
|
311
469
|
if (!r.ok) {
|
|
470
|
+
const message = safeSetupResultError(r.error);
|
|
312
471
|
if (json)
|
|
313
|
-
emit({ runtime, action: 'uninstall', files: [], error:
|
|
472
|
+
emit({ runtime, action: 'uninstall', files: [], error: message });
|
|
314
473
|
else
|
|
315
|
-
process.stderr.write(`${
|
|
474
|
+
process.stderr.write(`${message}\n`);
|
|
316
475
|
return 1;
|
|
317
476
|
}
|
|
477
|
+
if (r.dryRun) {
|
|
478
|
+
if (json)
|
|
479
|
+
emit({ runtime, action: 'uninstall', files, backups, dryRun: true });
|
|
480
|
+
else
|
|
481
|
+
process.stdout.write(files.length ? `dry-run: would remove evolver from: ${files.join(', ')}\n` : 'dry-run: nothing to remove\n');
|
|
482
|
+
return 0;
|
|
483
|
+
}
|
|
318
484
|
if (json)
|
|
319
|
-
emit({ runtime, action: 'uninstall', files
|
|
485
|
+
emit({ runtime, action: 'uninstall', files, backups });
|
|
320
486
|
else
|
|
321
|
-
process.stdout.write(
|
|
487
|
+
process.stdout.write(files.length ? `removed evolver from: ${files.join(', ')}\n` : 'nothing to remove\n');
|
|
322
488
|
return 0;
|
|
323
489
|
}
|
|
324
490
|
const profileDescriptor = profileDescriptorFromFlag(f);
|
|
@@ -360,6 +526,28 @@ export async function runSetupHooks(argv, store, review, deps = {}) {
|
|
|
360
526
|
return 0;
|
|
361
527
|
}
|
|
362
528
|
const server = buildServer(f, descriptor);
|
|
529
|
+
if ((runtime === 'opencode' || runtime === 'kiro') && f['dry-run'] !== true) {
|
|
530
|
+
let runtimeDetected;
|
|
531
|
+
try {
|
|
532
|
+
runtimeDetected = (deps.runtimeAvailable ?? defaultRuntimeAvailable)(runtime, configRoot, scope);
|
|
533
|
+
}
|
|
534
|
+
catch (error) {
|
|
535
|
+
const message = safeSetupOperationError(error);
|
|
536
|
+
if (json)
|
|
537
|
+
emit({ runtime, outcome: 'error', files: [], error: message });
|
|
538
|
+
else
|
|
539
|
+
process.stderr.write(`${message}\n`);
|
|
540
|
+
return 1;
|
|
541
|
+
}
|
|
542
|
+
if (!runtimeDetected) {
|
|
543
|
+
const error = `${runtime} runtime was not detected; install or launch ${runtime === 'opencode' ? 'OpenCode' : 'Kiro'} first, then rerun. No config was written.`;
|
|
544
|
+
if (json)
|
|
545
|
+
emit({ runtime, outcome: 'error', files: [], error });
|
|
546
|
+
else
|
|
547
|
+
process.stderr.write(`${error}\n`);
|
|
548
|
+
return 1;
|
|
549
|
+
}
|
|
550
|
+
}
|
|
363
551
|
if (runtime === 'cursor')
|
|
364
552
|
(deps.emitNonGitWorkspaceNotice ?? maybeEmitNonGitWorkspaceNotice)({ cwd: configRoot });
|
|
365
553
|
// cursor seeds .cursor/rules/evolver.mdc with the CURRENT top REVIEW-APPROVED genes so the file is useful
|
|
@@ -376,6 +564,12 @@ export async function runSetupHooks(argv, store, review, deps = {}) {
|
|
|
376
564
|
...(typeof f['hook-command'] === 'string' ? { hookCommand: f['hook-command'] } : {}),
|
|
377
565
|
...(cursorGenes ? { genes: cursorGenes } : {}),
|
|
378
566
|
force: f['force'] === true,
|
|
567
|
+
dryRun: f['dry-run'] === true,
|
|
568
|
+
homeDir: homedir(),
|
|
569
|
+
kiroHome: process.env['KIRO_HOME'],
|
|
570
|
+
xdgConfigHome: process.env['XDG_CONFIG_HOME'],
|
|
571
|
+
opencodeConfig: process.env['OPENCODE_CONFIG'],
|
|
572
|
+
opencodeConfigDir: process.env['OPENCODE_CONFIG_DIR'],
|
|
379
573
|
});
|
|
380
574
|
}
|
|
381
575
|
catch (e) {
|
|
@@ -383,7 +577,7 @@ export async function runSetupHooks(argv, store, review, deps = {}) {
|
|
|
383
577
|
// `unsupported` runtime. Reporting `unsupported` here would tell a bootstrapper the runtime isn't supported and
|
|
384
578
|
// make it stop trying, when the real cause is operational. `error` is a CLI result status (the attempt failed),
|
|
385
579
|
// distinct from the support-matrix `unsupported` (an unrecognized runtime id) (Bugbot #264).
|
|
386
|
-
const msg =
|
|
580
|
+
const msg = safeSetupOperationError(e);
|
|
387
581
|
if (json)
|
|
388
582
|
emit({ runtime, outcome: 'error', files: [], error: msg });
|
|
389
583
|
else
|
|
@@ -392,22 +586,44 @@ export async function runSetupHooks(argv, store, review, deps = {}) {
|
|
|
392
586
|
}
|
|
393
587
|
if (!r.ok) {
|
|
394
588
|
// Same reasoning for an ok:false install result: a failed install of a supported runtime is `error`, not `unsupported`.
|
|
589
|
+
const message = safeSetupResultError(r.error);
|
|
395
590
|
if (json)
|
|
396
|
-
emit({ runtime, outcome: 'error', files: [], error:
|
|
591
|
+
emit({ runtime, outcome: 'error', files: [], error: message });
|
|
397
592
|
else
|
|
398
|
-
process.stderr.write(`${
|
|
593
|
+
process.stderr.write(`${message}\n`);
|
|
399
594
|
return 1;
|
|
400
595
|
}
|
|
596
|
+
const files = displayResultPaths(r.files, configRoot, scope) ?? [];
|
|
597
|
+
const backups = displayResultPaths(r.backups, configRoot, scope);
|
|
598
|
+
if (r.dryRun) {
|
|
599
|
+
if (json) {
|
|
600
|
+
emit({
|
|
601
|
+
runtime,
|
|
602
|
+
outcome: 'installed',
|
|
603
|
+
files,
|
|
604
|
+
backups,
|
|
605
|
+
dryRun: true,
|
|
606
|
+
...(r.alreadyInstalled ? { alreadyInstalled: true } : {}),
|
|
607
|
+
});
|
|
608
|
+
}
|
|
609
|
+
else if (r.alreadyInstalled) {
|
|
610
|
+
process.stdout.write('dry-run: evolver already installed (no changes)\n');
|
|
611
|
+
}
|
|
612
|
+
else {
|
|
613
|
+
process.stdout.write(`dry-run: would install evolver (${r.mode}) → ${files.join(', ')}\n`);
|
|
614
|
+
}
|
|
615
|
+
return 0;
|
|
616
|
+
}
|
|
401
617
|
if (r.alreadyInstalled) {
|
|
402
618
|
if (json)
|
|
403
|
-
emit({ runtime, outcome: 'installed', files
|
|
619
|
+
emit({ runtime, outcome: 'installed', files, alreadyInstalled: true });
|
|
404
620
|
else
|
|
405
621
|
process.stdout.write('evolver already installed (use --force to reinstall)\n');
|
|
406
622
|
return 0;
|
|
407
623
|
}
|
|
408
624
|
if (json)
|
|
409
|
-
emit({ runtime, outcome: 'installed', files: r.
|
|
625
|
+
emit({ runtime, outcome: 'installed', files, backups, mode: r.mode, verified: r.verified });
|
|
410
626
|
else
|
|
411
|
-
process.stdout.write(`installed evolver (${r.mode}) → ${
|
|
627
|
+
process.stdout.write(`installed evolver (${r.mode}) → ${files.join(', ')}\n`);
|
|
412
628
|
return 0;
|
|
413
629
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@evomap/evolver-cli",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.6",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "evolver CLI (status/watch/cycles/rebuild-views/...)",
|
|
@@ -20,12 +20,12 @@
|
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@evomap/evolver-core": "2.0.0-beta.
|
|
24
|
-
"@evomap/evolver-adapter-public": "2.0.0-beta.
|
|
25
|
-
"@evomap/evolver-mcp": "2.0.0-beta.
|
|
26
|
-
"@evomap/evolver-proxy": "2.0.0-beta.
|
|
27
|
-
"@evomap/evolver-runtime-adapters": "2.0.0-beta.
|
|
28
|
-
"@evomap/evolver-webui": "2.0.0-beta.
|
|
23
|
+
"@evomap/evolver-core": "2.0.0-beta.6",
|
|
24
|
+
"@evomap/evolver-adapter-public": "2.0.0-beta.6",
|
|
25
|
+
"@evomap/evolver-mcp": "2.0.0-beta.6",
|
|
26
|
+
"@evomap/evolver-proxy": "2.0.0-beta.6",
|
|
27
|
+
"@evomap/evolver-runtime-adapters": "2.0.0-beta.6",
|
|
28
|
+
"@evomap/evolver-webui": "2.0.0-beta.6"
|
|
29
29
|
},
|
|
30
30
|
"repository": {
|
|
31
31
|
"type": "git",
|