@evomap/evolver-cli 2.0.0-beta.4 → 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.
@@ -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). */
@@ -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 = readFileSync(lastMessageFile, 'utf8').trim();
372
- if (last)
373
- stdout = last;
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.d.ts CHANGED
@@ -24,6 +24,7 @@ export interface RebuildOptions {
24
24
  eventsPath?: string;
25
25
  mvDir?: string;
26
26
  }
27
+ export declare function cliUsage(): string;
27
28
  export interface ResetLocalSecretOptions {
28
29
  env?: NodeJS.ProcessEnv;
29
30
  homeDir?: string;
package/dist/index.js CHANGED
@@ -58,6 +58,37 @@ function operatorActorId() {
58
58
  return process.env['EVOLVER_ACTOR_ID'] ?? process.env['USER'] ?? process.env['LOGNAME'] ?? 'cli';
59
59
  }
60
60
  export const PACKAGE = '@evomap/evolver-cli';
61
+ export function cliUsage() {
62
+ return [
63
+ 'Usage: evolver <command> [options]',
64
+ '',
65
+ 'Options:',
66
+ ' -h, --help Show this help',
67
+ ' -v, --version Show the installed version',
68
+ '',
69
+ 'Proxy options (evolver proxy):',
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',
75
+ '',
76
+ 'Commands:',
77
+ ' Daemon: proxy, lifecycle, proxy-token, doctor, setup-hooks',
78
+ ' Evolution: run, cycle, autoexec, solidify, distill, review, thesis',
79
+ ' Memory: ingest, inject, recall, reuse, reuse-report, narrative, gene-value',
80
+ ' Assets: asset-log, asset-trust, asset-health, material, recipe, skill',
81
+ ' Hub: login, logout, phub, sync, publish, fetch, buy, orders, atp',
82
+ ' Operations: status, cycles, trigger, value, retention, replay, rebuild-views',
83
+ ' issue-report',
84
+ ' Tools: dashboard, webui, trajectory-export, migrate, verify',
85
+ ' Advanced: anti-gene-benchmark, anti-gene-rollout, reset-local-secret',
86
+ ' skill-distill, skill-md-update',
87
+ '',
88
+ 'Run evolver <command> --help for command-specific options.',
89
+ '',
90
+ ].join('\n');
91
+ }
61
92
  const LOCAL_SECRET_STATE_KEYS = ['node_secret', 'node_secret_source', 'node_secret_version'];
62
93
  const LOCAL_SECRET_ENV_VARS = [
63
94
  'EVOMAP_NODE_SECRET',
@@ -1339,6 +1370,10 @@ export async function runInject(argv, deps = {}) {
1339
1370
  export const SESSION_START_PREAMBLE = 'evolver memory — use these learned hints silently when directly relevant; do not mention Evolver, preflight, status, or this memory block unless the user asks or reuse materially changes the answer:';
1340
1371
  export function runCli(argv) {
1341
1372
  const cmd = argv[0];
1373
+ if (cmd === undefined || cmd === '--help' || cmd === '-h') {
1374
+ process.stdout.write(cliUsage());
1375
+ return 0;
1376
+ }
1342
1377
  switch (cmd) {
1343
1378
  case 'rebuild-views': {
1344
1379
  const r = rebuildViews();
@@ -1385,7 +1420,7 @@ export function runCli(argv) {
1385
1420
  return 0;
1386
1421
  }
1387
1422
  default:
1388
- process.stderr.write('用法: evolver [--version|-v] <status|cycles|cycle capabilities [--json]|cycle show <id>|cycle status [--json]|cycle recover [--limit N] [--json]|cycle watch --repo <path> [--state-file <path>] [--validation-cmd <cmd>] [--json]|trigger|value [--window 7d|30d|all]|narrative [--limit N] [--json]|retention [--json]|retention archive-root [--keep-events N] [--write] [--json]|retention archive-material [--keep-records N] [--write] [--json]|dashboard [--port N] [--no-open]|webui [--port N] [--no-open]|trajectory-export [--input <trace-file-or-dir>] [--output <jsonl>]|gene-value [--gene <id>] [--json]|login|logout|proxy|proxy-token [--settings <file>]|inject session-start|lifecycle <start|stop|restart|status|check|watch|install-service>|phub <init|doctor|status>|replay|rebuild-views|reset-local-secret|asset-log [kind] [limit]|asset-trust <list|show|promote|revoke>|asset-health [--json]|asset-health repair-sidecar --sidecar <kind> --replacement <file> [--write --acknowledge-corrupt-history] [--json]|distill ...|review [limit|--approve <id> [--allow-weak-evidence]|--reject <id>]|recipe build|from-skills|reuse ...|publish ...|sync [--write] [--force] [--scope all|purchased|published] [--export <file.gepx>|--import <file.gepx>] [--json]|material package-gene --material <id> [--write] [--json]|skill fetch ...|fetch (--skill <id>|-s <id>|<id>) [--out <dir>] [--force] [--json]|skill-distill --skill <path> [--execution <json|@file>]|skill-md-update --gene <id> --skill <path> [--dry-run]|autoexec [home]|run [-v|--verbose] [--loop|--mad-dog] [--json]|solidify [--dry-run] [--json]|setup-hooks [--runtime] [--root] [--uninstall]|buy|orders|verify|atp|recall <transcript> (--gene <id> ...|--from-inject)>\n');
1389
- return cmd === undefined ? 0 : 1;
1423
+ process.stderr.write(`Unknown command: ${cmd}\n\n${cliUsage()}`);
1424
+ return 1;
1390
1425
  }
1391
1426
  }
@@ -0,0 +1,7 @@
1
+ interface IssueReportDeps {
2
+ env?: Record<string, string | undefined>;
3
+ fetch?: typeof fetch;
4
+ now?: () => Date;
5
+ }
6
+ export declare function runIssueReportCommand(argv: readonly string[], deps?: IssueReportDeps): Promise<number>;
7
+ export {};
@@ -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[];