@evomap/evolver-cli 2.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/antiGeneBenchmark.d.ts +9 -0
- package/dist/antiGeneBenchmark.js +173 -0
- package/dist/antiGeneRollout.d.ts +14 -0
- package/dist/antiGeneRollout.js +276 -0
- package/dist/atp.d.ts +122 -0
- package/dist/atp.js +413 -0
- package/dist/atpAutoDeliver.d.ts +53 -0
- package/dist/atpAutoDeliver.js +197 -0
- package/dist/atpAutobuyPrompt.d.ts +48 -0
- package/dist/atpAutobuyPrompt.js +109 -0
- package/dist/autoDistillAntiGene.d.ts +63 -0
- package/dist/autoDistillAntiGene.js +396 -0
- package/dist/autoDistillLlm.d.ts +94 -0
- package/dist/autoDistillLlm.js +510 -0
- package/dist/autoDistillTranscript.d.ts +87 -0
- package/dist/autoDistillTranscript.js +364 -0
- package/dist/autoRecall.d.ts +25 -0
- package/dist/autoRecall.js +80 -0
- package/dist/autoexec.d.ts +237 -0
- package/dist/autoexec.js +1041 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +7 -0
- package/dist/cliContracts.d.ts +72 -0
- package/dist/cliContracts.js +815 -0
- package/dist/commands.d.ts +9 -0
- package/dist/commands.js +10 -0
- package/dist/cursorRewrite.d.ts +42 -0
- package/dist/cursorRewrite.js +65 -0
- package/dist/cycleConsumer.d.ts +42 -0
- package/dist/cycleConsumer.js +519 -0
- package/dist/daemonLoop.d.ts +33 -0
- package/dist/daemonLoop.js +72 -0
- package/dist/dispatch.d.ts +10 -0
- package/dist/dispatch.js +75 -0
- package/dist/distillObserver.d.ts +33 -0
- package/dist/distillObserver.js +146 -0
- package/dist/distillPrimitives.d.ts +48 -0
- package/dist/distillPrimitives.js +142 -0
- package/dist/doctor.d.ts +54 -0
- package/dist/doctor.js +931 -0
- package/dist/geneValue.d.ts +37 -0
- package/dist/geneValue.js +97 -0
- package/dist/index.d.ts +193 -0
- package/dist/index.js +1135 -0
- package/dist/lifecycle.d.ts +75 -0
- package/dist/lifecycle.js +859 -0
- package/dist/login.d.ts +10 -0
- package/dist/login.js +38 -0
- package/dist/migrate/divergenceAudit.d.ts +29 -0
- package/dist/migrate/divergenceAudit.js +37 -0
- package/dist/migrate/fieldMap.d.ts +18 -0
- package/dist/migrate/fieldMap.js +68 -0
- package/dist/migrate/v1Import.d.ts +16 -0
- package/dist/migrate/v1Import.js +118 -0
- package/dist/phub.d.ts +18 -0
- package/dist/phub.js +284 -0
- package/dist/recall.d.ts +26 -0
- package/dist/recall.js +162 -0
- package/dist/recipe.d.ts +61 -0
- package/dist/recipe.js +564 -0
- package/dist/reflectionObserver.d.ts +8 -0
- package/dist/reflectionObserver.js +6 -0
- package/dist/reuse.d.ts +48 -0
- package/dist/reuse.js +300 -0
- package/dist/reuseReport.d.ts +20 -0
- package/dist/reuseReport.js +255 -0
- package/dist/reviewFilter.d.ts +4 -0
- package/dist/reviewFilter.js +6 -0
- package/dist/runtimeSessionSource.d.ts +9 -0
- package/dist/runtimeSessionSource.js +29 -0
- package/dist/setupHooks.d.ts +2 -0
- package/dist/setupHooks.js +410 -0
- package/dist/skill2gep.d.ts +144 -0
- package/dist/skill2gep.js +321 -0
- package/dist/skillDistill.d.ts +75 -0
- package/dist/skillDistill.js +342 -0
- package/dist/solo/breaker.d.ts +14 -0
- package/dist/solo/breaker.js +21 -0
- package/dist/solo/gitGuard.d.ts +17 -0
- package/dist/solo/gitGuard.js +62 -0
- package/dist/solo/mode.d.ts +12 -0
- package/dist/solo/mode.js +55 -0
- package/dist/thesis.d.ts +43 -0
- package/dist/thesis.js +179 -0
- package/dist/trajectoryExport.d.ts +1 -0
- package/dist/trajectoryExport.js +895 -0
- package/dist/valueDigest.d.ts +33 -0
- package/dist/valueDigest.js +94 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +14 -0
- package/package.json +38 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { assetstore, events } from '@evomap/evolver-core';
|
|
2
|
+
export interface AntiGeneBenchmarkCommandDeps {
|
|
3
|
+
store?: assetstore.AssetStoreProvider;
|
|
4
|
+
review?: assetstore.ReviewLedger;
|
|
5
|
+
readEvents?: (eventsPath?: string) => events.ReportEvent[];
|
|
6
|
+
now?: () => number;
|
|
7
|
+
log?: (line: string) => void;
|
|
8
|
+
}
|
|
9
|
+
export declare function runAntiGeneBenchmarkCommand(argv: readonly string[], deps?: AntiGeneBenchmarkCommandDeps): Promise<number>;
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { mkdtempSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { join, resolve } from 'node:path';
|
|
4
|
+
import { assetstore, benchmark, events } from '@evomap/evolver-core';
|
|
5
|
+
const usage = '用法: evolver anti-gene-benchmark --suite <file> [--assets <dir>] [--review-dir <dir>] [--events <file>] [--json] [--min-samples N] [--min-failure-delta D]\n'
|
|
6
|
+
+ ' 或: evolver anti-gene-benchmark --report <events-file> [--json]\n';
|
|
7
|
+
function parseFlags(argv) {
|
|
8
|
+
const out = { json: false };
|
|
9
|
+
for (let i = 0; i < argv.length; i++) {
|
|
10
|
+
const arg = argv[i];
|
|
11
|
+
if (arg === '--json')
|
|
12
|
+
out.json = true;
|
|
13
|
+
else if (arg === '--suite')
|
|
14
|
+
out.suite = valueAfter(argv, ++i);
|
|
15
|
+
else if (arg === '--assets')
|
|
16
|
+
out.assets = valueAfter(argv, ++i);
|
|
17
|
+
else if (arg === '--review-dir')
|
|
18
|
+
out.reviewDir = valueAfter(argv, ++i);
|
|
19
|
+
else if (arg === '--events')
|
|
20
|
+
out.events = valueAfter(argv, ++i);
|
|
21
|
+
else if (arg === '--report')
|
|
22
|
+
out.report = valueAfter(argv, ++i);
|
|
23
|
+
else if (arg === '--min-samples')
|
|
24
|
+
out.minSamples = Number(argv[++i]);
|
|
25
|
+
else if (arg === '--min-failure-delta')
|
|
26
|
+
out.minFailureDelta = Number(argv[++i]);
|
|
27
|
+
}
|
|
28
|
+
return out;
|
|
29
|
+
}
|
|
30
|
+
function valueAfter(argv, index) {
|
|
31
|
+
const value = argv[index];
|
|
32
|
+
return value !== undefined && !value.startsWith('--') ? value : undefined;
|
|
33
|
+
}
|
|
34
|
+
function strings(value) {
|
|
35
|
+
return Array.isArray(value) && value.every((item) => typeof item === 'string') ? value : null;
|
|
36
|
+
}
|
|
37
|
+
function outcome(value) {
|
|
38
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
39
|
+
return null;
|
|
40
|
+
const row = value;
|
|
41
|
+
if (row['status'] !== 'success' && row['status'] !== 'failed')
|
|
42
|
+
return null;
|
|
43
|
+
const out = { status: row['status'] };
|
|
44
|
+
if (typeof row['repeatedFailure'] === 'boolean')
|
|
45
|
+
out.repeatedFailure = row['repeatedFailure'];
|
|
46
|
+
if (typeof row['overblocked'] === 'boolean')
|
|
47
|
+
out.overblocked = row['overblocked'];
|
|
48
|
+
if (typeof row['score'] === 'number' && Number.isFinite(row['score']))
|
|
49
|
+
out.score = row['score'];
|
|
50
|
+
if (typeof row['reason'] === 'string')
|
|
51
|
+
out.reason = row['reason'];
|
|
52
|
+
return out;
|
|
53
|
+
}
|
|
54
|
+
function parseSuite(value) {
|
|
55
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
56
|
+
throw new Error('suite must be an object');
|
|
57
|
+
const row = value;
|
|
58
|
+
if (typeof row['name'] !== 'string' || row['name'].trim().length === 0)
|
|
59
|
+
throw new Error('suite.name must be a non-empty string');
|
|
60
|
+
if (!Array.isArray(row['tasks']) || row['tasks'].length === 0)
|
|
61
|
+
throw new Error('suite.tasks must be a non-empty array');
|
|
62
|
+
return {
|
|
63
|
+
name: row['name'],
|
|
64
|
+
tasks: row['tasks'].map((task, index) => {
|
|
65
|
+
if (!task || typeof task !== 'object' || Array.isArray(task))
|
|
66
|
+
throw new Error(`tasks[${index}] must be an object`);
|
|
67
|
+
const t = task;
|
|
68
|
+
if (typeof t['id'] !== 'string' || t['id'].trim().length === 0)
|
|
69
|
+
throw new Error(`tasks[${index}].id must be a non-empty string`);
|
|
70
|
+
const signals = strings(t['signals']);
|
|
71
|
+
if (!signals || signals.length === 0)
|
|
72
|
+
throw new Error(`tasks[${index}].signals must be a non-empty string array`);
|
|
73
|
+
const outcomes = t['outcomes'];
|
|
74
|
+
if (!outcomes || typeof outcomes !== 'object' || Array.isArray(outcomes))
|
|
75
|
+
throw new Error(`tasks[${index}].outcomes must be an object`);
|
|
76
|
+
const outcomeRow = outcomes;
|
|
77
|
+
const baseline = outcome(outcomeRow['baseline']);
|
|
78
|
+
const antiGene = outcome(outcomeRow['antiGene']);
|
|
79
|
+
if (!baseline)
|
|
80
|
+
throw new Error(`tasks[${index}].outcomes.baseline must have status success|failed`);
|
|
81
|
+
if (!antiGene)
|
|
82
|
+
throw new Error(`tasks[${index}].outcomes.antiGene must have status success|failed`);
|
|
83
|
+
const expectedAntiWarnings = strings(t['expectedAntiWarnings']);
|
|
84
|
+
return {
|
|
85
|
+
id: t['id'],
|
|
86
|
+
signals,
|
|
87
|
+
...(typeof t['target'] === 'string' ? { target: t['target'] } : {}),
|
|
88
|
+
...(typeof t['expectedEffect'] === 'string' ? { expectedEffect: t['expectedEffect'] } : {}),
|
|
89
|
+
...(typeof t['category'] === 'string' ? { category: t['category'] } : {}),
|
|
90
|
+
...(typeof t['summary'] === 'string' ? { summary: t['summary'] } : {}),
|
|
91
|
+
...(typeof t['confidence'] === 'number' && Number.isFinite(t['confidence']) ? { confidence: t['confidence'] } : {}),
|
|
92
|
+
...(expectedAntiWarnings ? { expectedAntiWarnings } : {}),
|
|
93
|
+
outcomes: { baseline, antiGene },
|
|
94
|
+
};
|
|
95
|
+
}),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
function readSuite(path) {
|
|
99
|
+
return parseSuite(JSON.parse(readFileSync(resolve(path), 'utf8')));
|
|
100
|
+
}
|
|
101
|
+
function pct(value) {
|
|
102
|
+
return `${(value * 100).toFixed(0)}%`;
|
|
103
|
+
}
|
|
104
|
+
function printReport(report, log) {
|
|
105
|
+
log(`anti-gene-benchmark [${report.suite}]: ${report.tasks} task(s) -> ${report.verdict}`);
|
|
106
|
+
log(` baseline failures=${report.baseline.failures}/${report.baseline.n} (${pct(report.baseline.failureRate)}) repeated=${report.baseline.repeatedFailures}`);
|
|
107
|
+
log(` antiGene failures=${report.antiGene.failures}/${report.antiGene.n} (${pct(report.antiGene.failureRate)}) repeated=${report.antiGene.repeatedFailures} warnings=${report.antiGene.observedWarnings}`);
|
|
108
|
+
log(` delta failure=${(report.failureDelta * 100).toFixed(1)}pt missingWarnings=${report.missingExpectedWarnings} overblocked=${report.overblocked}`);
|
|
109
|
+
}
|
|
110
|
+
function jsonReplacer(_key, value) {
|
|
111
|
+
return typeof value === 'number' && !Number.isFinite(value) ? String(value) : value;
|
|
112
|
+
}
|
|
113
|
+
async function runReportMode(flags, deps, log) {
|
|
114
|
+
if (!flags.report) {
|
|
115
|
+
process.stderr.write(usage);
|
|
116
|
+
return 1;
|
|
117
|
+
}
|
|
118
|
+
const evts = (deps.readEvents ?? events.readEvents)(resolve(flags.report));
|
|
119
|
+
const report = benchmark.latestAntiGeneBenchmarkReport(evts);
|
|
120
|
+
if (!report) {
|
|
121
|
+
process.stderr.write('anti-gene-benchmark: no anti_gene.benchmark_result event found\n');
|
|
122
|
+
return 1;
|
|
123
|
+
}
|
|
124
|
+
if (flags.json)
|
|
125
|
+
log(JSON.stringify(report, jsonReplacer));
|
|
126
|
+
else
|
|
127
|
+
printReport(report, log);
|
|
128
|
+
return 0;
|
|
129
|
+
}
|
|
130
|
+
export async function runAntiGeneBenchmarkCommand(argv, deps = {}) {
|
|
131
|
+
const flags = parseFlags(argv);
|
|
132
|
+
const log = deps.log ?? ((line) => process.stdout.write(`${line}\n`));
|
|
133
|
+
if (flags.report !== undefined)
|
|
134
|
+
return runReportMode(flags, deps, log);
|
|
135
|
+
if (!flags.suite) {
|
|
136
|
+
process.stderr.write(usage);
|
|
137
|
+
return 1;
|
|
138
|
+
}
|
|
139
|
+
if (flags.minSamples !== undefined && (!Number.isFinite(flags.minSamples) || flags.minSamples < 1)) {
|
|
140
|
+
process.stderr.write('anti-gene-benchmark: --min-samples must be >= 1\n');
|
|
141
|
+
return 1;
|
|
142
|
+
}
|
|
143
|
+
if (flags.minFailureDelta !== undefined && (!Number.isFinite(flags.minFailureDelta) || flags.minFailureDelta < 0)) {
|
|
144
|
+
process.stderr.write('anti-gene-benchmark: --min-failure-delta must be >= 0\n');
|
|
145
|
+
return 1;
|
|
146
|
+
}
|
|
147
|
+
let suite;
|
|
148
|
+
try {
|
|
149
|
+
suite = readSuite(flags.suite);
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
process.stderr.write(`anti-gene-benchmark: cannot read --suite (${error instanceof Error ? error.message : String(error)})\n`);
|
|
153
|
+
return 1;
|
|
154
|
+
}
|
|
155
|
+
const assetsDir = flags.assets ? resolve(flags.assets) : events.assetsDir();
|
|
156
|
+
const reviewDir = flags.reviewDir ? resolve(flags.reviewDir) : assetsDir;
|
|
157
|
+
const store = deps.store ?? new assetstore.LocalJsonlProvider(assetsDir);
|
|
158
|
+
const review = deps.review ?? new assetstore.ReviewLedger(reviewDir, deps.now);
|
|
159
|
+
const eventsPath = flags.events ? resolve(flags.events) : join(mkdtempSync(join(tmpdir(), 'anti-gene-benchmark-events-')), 'root_events.jsonl');
|
|
160
|
+
const report = await benchmark.runAntiGeneBenchmark(suite, { store, review }, {
|
|
161
|
+
eventsPath,
|
|
162
|
+
now: deps.now,
|
|
163
|
+
...(flags.minSamples !== undefined ? { minSamples: flags.minSamples } : {}),
|
|
164
|
+
...(flags.minFailureDelta !== undefined ? { minFailureDelta: flags.minFailureDelta } : {}),
|
|
165
|
+
});
|
|
166
|
+
if (flags.json)
|
|
167
|
+
log(JSON.stringify({ ...report, eventsPath }, jsonReplacer));
|
|
168
|
+
else {
|
|
169
|
+
printReport(report, log);
|
|
170
|
+
log(` events: ${eventsPath}`);
|
|
171
|
+
}
|
|
172
|
+
return 0;
|
|
173
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { assetstore, benchmark, events } from '@evomap/evolver-core';
|
|
2
|
+
export interface AntiGeneRolloutCommandDeps {
|
|
3
|
+
store?: assetstore.AssetStoreProvider;
|
|
4
|
+
review?: assetstore.ReviewLedger;
|
|
5
|
+
readEvents?: (eventsPath?: string) => events.ReportEvent[];
|
|
6
|
+
makeExecute?: benchmark.AntiGeneRolloutExecuteFactory;
|
|
7
|
+
now?: () => number;
|
|
8
|
+
log?: (line: string) => void;
|
|
9
|
+
}
|
|
10
|
+
export declare function parseAntiGeneRolloutValidationCommand(commandLine: string): {
|
|
11
|
+
cmd: string;
|
|
12
|
+
args: string[];
|
|
13
|
+
} | null;
|
|
14
|
+
export declare function runAntiGeneRolloutCommand(argv: readonly string[], deps?: AntiGeneRolloutCommandDeps): Promise<number>;
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import { existsSync, mkdtempSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { join, resolve } from 'node:path';
|
|
4
|
+
import { spawn } from 'node:child_process';
|
|
5
|
+
import { assetstore, benchmark, events, exec } from '@evomap/evolver-core';
|
|
6
|
+
const usage = '用法: evolver anti-gene-rollout --suite <file> --repo <path> [--assets <dir>] [--review-dir <dir>] [--events <file>] [--runner claude|codex] [--json] [--min-samples N] [--min-failure-delta D]\n'
|
|
7
|
+
+ ' 或: evolver anti-gene-rollout --report <events-file> [--json]\n';
|
|
8
|
+
function parseFlags(argv) {
|
|
9
|
+
const out = { json: false };
|
|
10
|
+
for (let i = 0; i < argv.length; i++) {
|
|
11
|
+
const arg = argv[i];
|
|
12
|
+
if (arg === '--json')
|
|
13
|
+
out.json = true;
|
|
14
|
+
else if (arg === '--suite')
|
|
15
|
+
out.suite = valueAfter(argv, ++i);
|
|
16
|
+
else if (arg === '--repo')
|
|
17
|
+
out.repo = valueAfter(argv, ++i);
|
|
18
|
+
else if (arg === '--assets')
|
|
19
|
+
out.assets = valueAfter(argv, ++i);
|
|
20
|
+
else if (arg === '--review-dir')
|
|
21
|
+
out.reviewDir = valueAfter(argv, ++i);
|
|
22
|
+
else if (arg === '--events')
|
|
23
|
+
out.events = valueAfter(argv, ++i);
|
|
24
|
+
else if (arg === '--report')
|
|
25
|
+
out.report = valueAfter(argv, ++i);
|
|
26
|
+
else if (arg === '--runner')
|
|
27
|
+
out.runner = valueAfter(argv, ++i);
|
|
28
|
+
else if (arg === '--min-samples')
|
|
29
|
+
out.minSamples = Number(argv[++i]);
|
|
30
|
+
else if (arg === '--min-failure-delta')
|
|
31
|
+
out.minFailureDelta = Number(argv[++i]);
|
|
32
|
+
}
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
function valueAfter(argv, index) {
|
|
36
|
+
const value = argv[index];
|
|
37
|
+
return value !== undefined && !value.startsWith('--') ? value : undefined;
|
|
38
|
+
}
|
|
39
|
+
function strings(value) {
|
|
40
|
+
return Array.isArray(value) && value.every((item) => typeof item === 'string') ? value : null;
|
|
41
|
+
}
|
|
42
|
+
function parseSuite(value) {
|
|
43
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
44
|
+
throw new Error('suite must be an object');
|
|
45
|
+
const row = value;
|
|
46
|
+
if (typeof row['name'] !== 'string' || row['name'].trim().length === 0)
|
|
47
|
+
throw new Error('suite.name must be a non-empty string');
|
|
48
|
+
const validation = row['validation'] === undefined ? undefined : strings(row['validation']);
|
|
49
|
+
if (row['validation'] !== undefined && !validation)
|
|
50
|
+
throw new Error('suite.validation must be a string array when present');
|
|
51
|
+
if (!Array.isArray(row['tasks']) || row['tasks'].length === 0)
|
|
52
|
+
throw new Error('suite.tasks must be a non-empty array');
|
|
53
|
+
return {
|
|
54
|
+
name: row['name'],
|
|
55
|
+
...(validation ? { validation } : {}),
|
|
56
|
+
tasks: row['tasks'].map((task, index) => {
|
|
57
|
+
if (!task || typeof task !== 'object' || Array.isArray(task))
|
|
58
|
+
throw new Error(`tasks[${index}] must be an object`);
|
|
59
|
+
const t = task;
|
|
60
|
+
if (typeof t['id'] !== 'string' || t['id'].trim().length === 0)
|
|
61
|
+
throw new Error(`tasks[${index}].id must be a non-empty string`);
|
|
62
|
+
const signals = strings(t['signals']);
|
|
63
|
+
if (!signals || signals.length === 0)
|
|
64
|
+
throw new Error(`tasks[${index}].signals must be a non-empty string array`);
|
|
65
|
+
const expectedAntiWarnings = strings(t['expectedAntiWarnings']);
|
|
66
|
+
if (t['expectedAntiWarnings'] !== undefined && !expectedAntiWarnings)
|
|
67
|
+
throw new Error(`tasks[${index}].expectedAntiWarnings must be a string array when present`);
|
|
68
|
+
return {
|
|
69
|
+
id: t['id'],
|
|
70
|
+
signals,
|
|
71
|
+
...(typeof t['target'] === 'string' ? { target: t['target'] } : {}),
|
|
72
|
+
...(typeof t['expectedEffect'] === 'string' ? { expectedEffect: t['expectedEffect'] } : {}),
|
|
73
|
+
...(typeof t['category'] === 'string' ? { category: t['category'] } : {}),
|
|
74
|
+
...(typeof t['summary'] === 'string' ? { summary: t['summary'] } : {}),
|
|
75
|
+
...(typeof t['confidence'] === 'number' && Number.isFinite(t['confidence']) ? { confidence: t['confidence'] } : {}),
|
|
76
|
+
...(expectedAntiWarnings ? { expectedAntiWarnings } : {}),
|
|
77
|
+
};
|
|
78
|
+
}),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function readSuite(path) {
|
|
82
|
+
return parseSuite(JSON.parse(readFileSync(resolve(path), 'utf8')));
|
|
83
|
+
}
|
|
84
|
+
function pct(value) {
|
|
85
|
+
return `${(value * 100).toFixed(0)}%`;
|
|
86
|
+
}
|
|
87
|
+
function printReport(report, log) {
|
|
88
|
+
log(`anti-gene-rollout [${report.suite}]: ${report.tasks} task(s) -> ${report.verdict}`);
|
|
89
|
+
log(` baseline failures=${report.baseline.failures}/${report.baseline.n} (${pct(report.baseline.failureRate)}) repeated=${report.baseline.repeatedFailures}`);
|
|
90
|
+
log(` antiGene failures=${report.antiGene.failures}/${report.antiGene.n} (${pct(report.antiGene.failureRate)}) repeated=${report.antiGene.repeatedFailures} warnings=${report.antiGene.observedWarnings}`);
|
|
91
|
+
log(` delta failure=${(report.failureDelta * 100).toFixed(1)}pt missingWarnings=${report.missingExpectedWarnings} overblocked=${report.overblocked}`);
|
|
92
|
+
}
|
|
93
|
+
function jsonReplacer(_key, value) {
|
|
94
|
+
return typeof value === 'number' && !Number.isFinite(value) ? String(value) : value;
|
|
95
|
+
}
|
|
96
|
+
export function parseAntiGeneRolloutValidationCommand(commandLine) {
|
|
97
|
+
const raw = commandLine.trim();
|
|
98
|
+
if (!raw)
|
|
99
|
+
return null;
|
|
100
|
+
const parsed = repairUnquotedWindowsExePath(raw, parseCommandLine(raw));
|
|
101
|
+
const cmd = parsed[0];
|
|
102
|
+
return cmd ? { cmd, args: parsed.slice(1) } : null;
|
|
103
|
+
}
|
|
104
|
+
function repairUnquotedWindowsExePath(value, parsed) {
|
|
105
|
+
if (process.platform !== 'win32' || parsed.length === 0)
|
|
106
|
+
return parsed;
|
|
107
|
+
const first = parsed[0];
|
|
108
|
+
if (/\.exe$/i.test(first))
|
|
109
|
+
return parsed;
|
|
110
|
+
const exeEnd = value.toLowerCase().indexOf('.exe');
|
|
111
|
+
if (exeEnd < 0)
|
|
112
|
+
return parsed;
|
|
113
|
+
const command = value.slice(0, exeEnd + 4).trim();
|
|
114
|
+
if (!/^[A-Za-z]:\\/.test(command) && !command.startsWith('\\\\'))
|
|
115
|
+
return parsed;
|
|
116
|
+
if (!existsSync(command))
|
|
117
|
+
return parsed;
|
|
118
|
+
const rest = value.slice(exeEnd + 4).trim();
|
|
119
|
+
return rest ? [command, ...parseCommandLine(rest)] : [command];
|
|
120
|
+
}
|
|
121
|
+
function parseCommandLine(value) {
|
|
122
|
+
const out = [];
|
|
123
|
+
let current = '';
|
|
124
|
+
let quote = null;
|
|
125
|
+
let escaped = false;
|
|
126
|
+
for (let i = 0; i < value.length; i += 1) {
|
|
127
|
+
const ch = value[i];
|
|
128
|
+
if (escaped) {
|
|
129
|
+
current += ch;
|
|
130
|
+
escaped = false;
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
if (ch === '\\' && quote !== "'") {
|
|
134
|
+
const next = value[i + 1];
|
|
135
|
+
if (next !== undefined && (/\s/.test(next) || next === '"' || next === "'" || next === '\\')) {
|
|
136
|
+
escaped = true;
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
current += ch;
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
if ((ch === '"' || ch === "'") && quote === null) {
|
|
143
|
+
quote = ch;
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
if (ch === quote) {
|
|
147
|
+
quote = null;
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
if (/\s/.test(ch) && quote === null) {
|
|
151
|
+
if (current) {
|
|
152
|
+
out.push(current);
|
|
153
|
+
current = '';
|
|
154
|
+
}
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
current += ch;
|
|
158
|
+
}
|
|
159
|
+
if (quote !== null)
|
|
160
|
+
throw new Error('unterminated quote in suite.validation command');
|
|
161
|
+
if (escaped)
|
|
162
|
+
current += '\\';
|
|
163
|
+
if (current)
|
|
164
|
+
out.push(current);
|
|
165
|
+
return out;
|
|
166
|
+
}
|
|
167
|
+
function validationCommand(commandLine, cwd) {
|
|
168
|
+
let parsed;
|
|
169
|
+
try {
|
|
170
|
+
parsed = parseAntiGeneRolloutValidationCommand(commandLine);
|
|
171
|
+
}
|
|
172
|
+
catch {
|
|
173
|
+
return Promise.resolve(1);
|
|
174
|
+
}
|
|
175
|
+
if (!parsed)
|
|
176
|
+
return Promise.resolve(1);
|
|
177
|
+
return new Promise((resolveCode) => {
|
|
178
|
+
const child = spawn(parsed.cmd, parsed.args, { cwd, shell: false });
|
|
179
|
+
child.on('close', (code) => resolveCode(code ?? -1));
|
|
180
|
+
child.on('error', () => resolveCode(-1));
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
function liveMakeExecute(repo, runner, validation) {
|
|
184
|
+
return ({ store, review }) => {
|
|
185
|
+
const validate = async (_mutation, _decision, cwd) => {
|
|
186
|
+
for (const command of validation) {
|
|
187
|
+
if (await validationCommand(command, cwd) !== 0)
|
|
188
|
+
return { passed: false, score: 0.2 };
|
|
189
|
+
}
|
|
190
|
+
return { passed: true, score: 0.95 };
|
|
191
|
+
};
|
|
192
|
+
return exec.makeSafeExecute(repo, store, {
|
|
193
|
+
allowedRoots: [repo],
|
|
194
|
+
...(runner ? { runner } : {}),
|
|
195
|
+
}, {
|
|
196
|
+
review,
|
|
197
|
+
validate,
|
|
198
|
+
validationCmds: validation,
|
|
199
|
+
});
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
async function runReportMode(flags, deps, log) {
|
|
203
|
+
if (!flags.report) {
|
|
204
|
+
process.stderr.write(usage);
|
|
205
|
+
return 1;
|
|
206
|
+
}
|
|
207
|
+
const evts = (deps.readEvents ?? events.readEvents)(resolve(flags.report));
|
|
208
|
+
const report = benchmark.latestAntiGeneRolloutReport(evts);
|
|
209
|
+
if (!report) {
|
|
210
|
+
process.stderr.write('anti-gene-rollout: no anti_gene.rollout_result event found\n');
|
|
211
|
+
return 1;
|
|
212
|
+
}
|
|
213
|
+
if (flags.json)
|
|
214
|
+
log(JSON.stringify(report, jsonReplacer));
|
|
215
|
+
else
|
|
216
|
+
printReport(report, log);
|
|
217
|
+
return 0;
|
|
218
|
+
}
|
|
219
|
+
export async function runAntiGeneRolloutCommand(argv, deps = {}) {
|
|
220
|
+
const flags = parseFlags(argv);
|
|
221
|
+
const log = deps.log ?? ((line) => process.stdout.write(`${line}\n`));
|
|
222
|
+
if (flags.report !== undefined)
|
|
223
|
+
return runReportMode(flags, deps, log);
|
|
224
|
+
if (!flags.suite) {
|
|
225
|
+
process.stderr.write(usage);
|
|
226
|
+
return 1;
|
|
227
|
+
}
|
|
228
|
+
if (flags.minSamples !== undefined && (!Number.isFinite(flags.minSamples) || flags.minSamples < 1)) {
|
|
229
|
+
process.stderr.write('anti-gene-rollout: --min-samples must be >= 1\n');
|
|
230
|
+
return 1;
|
|
231
|
+
}
|
|
232
|
+
if (flags.minFailureDelta !== undefined && (!Number.isFinite(flags.minFailureDelta) || flags.minFailureDelta < 0)) {
|
|
233
|
+
process.stderr.write('anti-gene-rollout: --min-failure-delta must be >= 0\n');
|
|
234
|
+
return 1;
|
|
235
|
+
}
|
|
236
|
+
if (flags.runner !== undefined && flags.runner !== 'claude' && flags.runner !== 'codex') {
|
|
237
|
+
process.stderr.write('anti-gene-rollout: --runner must be claude or codex\n');
|
|
238
|
+
return 1;
|
|
239
|
+
}
|
|
240
|
+
let suite;
|
|
241
|
+
try {
|
|
242
|
+
suite = readSuite(flags.suite);
|
|
243
|
+
}
|
|
244
|
+
catch (error) {
|
|
245
|
+
process.stderr.write(`anti-gene-rollout: cannot read --suite (${error instanceof Error ? error.message : String(error)})\n`);
|
|
246
|
+
return 1;
|
|
247
|
+
}
|
|
248
|
+
const injected = deps.makeExecute !== undefined;
|
|
249
|
+
if (!injected && !flags.repo) {
|
|
250
|
+
process.stderr.write('anti-gene-rollout: live rollout requires --repo <allowlisted> so the exec bridge has an explicit allowed root\n');
|
|
251
|
+
return 1;
|
|
252
|
+
}
|
|
253
|
+
if (!injected && (!Array.isArray(suite.validation) || suite.validation.length === 0)) {
|
|
254
|
+
process.stderr.write('anti-gene-rollout: live rollout requires a non-empty suite.validation[] external verifier; refusing to trust agent self-report\n');
|
|
255
|
+
return 1;
|
|
256
|
+
}
|
|
257
|
+
const assetsDir = flags.assets ? resolve(flags.assets) : events.assetsDir();
|
|
258
|
+
const reviewDir = flags.reviewDir ? resolve(flags.reviewDir) : assetsDir;
|
|
259
|
+
const store = deps.store ?? new assetstore.LocalJsonlProvider(assetsDir);
|
|
260
|
+
const review = deps.review ?? new assetstore.ReviewLedger(reviewDir, deps.now);
|
|
261
|
+
const eventsPath = flags.events ? resolve(flags.events) : join(mkdtempSync(join(tmpdir(), 'anti-gene-rollout-events-')), 'root_events.jsonl');
|
|
262
|
+
const makeExecute = deps.makeExecute ?? liveMakeExecute(resolve(flags.repo), flags.runner, suite.validation);
|
|
263
|
+
const report = await benchmark.runAntiGeneRollout(suite, { store, review, makeExecute }, {
|
|
264
|
+
eventsPath,
|
|
265
|
+
now: deps.now,
|
|
266
|
+
...(flags.minSamples !== undefined ? { minSamples: flags.minSamples } : {}),
|
|
267
|
+
...(flags.minFailureDelta !== undefined ? { minFailureDelta: flags.minFailureDelta } : {}),
|
|
268
|
+
});
|
|
269
|
+
if (flags.json)
|
|
270
|
+
log(JSON.stringify({ ...report, eventsPath }, jsonReplacer));
|
|
271
|
+
else {
|
|
272
|
+
printReport(report, log);
|
|
273
|
+
log(` events: ${eventsPath}`);
|
|
274
|
+
}
|
|
275
|
+
return 0;
|
|
276
|
+
}
|
package/dist/atp.d.ts
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { AtpHubClient } from '@evomap/evolver-adapter-public';
|
|
2
|
+
import type { AtpListProofsOptions, AtpOrderOptions, AtpResult, AtpRole, AtpRoutingMode, AtpVerifyAction, AtpVerifyMode } from '@evomap/evolver-adapter-public';
|
|
3
|
+
type ParseResult<T> = {
|
|
4
|
+
ok: true;
|
|
5
|
+
opts: T;
|
|
6
|
+
} | {
|
|
7
|
+
ok: false;
|
|
8
|
+
error: string;
|
|
9
|
+
};
|
|
10
|
+
type LogFn = (line: string) => void;
|
|
11
|
+
export interface BuyOptions {
|
|
12
|
+
capabilities: string[];
|
|
13
|
+
budget: number;
|
|
14
|
+
question: string;
|
|
15
|
+
routingMode: AtpRoutingMode;
|
|
16
|
+
verifyMode: AtpVerifyMode;
|
|
17
|
+
noWait: boolean;
|
|
18
|
+
timeoutMs: number;
|
|
19
|
+
pollIntervalMs?: number;
|
|
20
|
+
}
|
|
21
|
+
export interface OrdersOptions {
|
|
22
|
+
role: AtpRole;
|
|
23
|
+
status: string | null;
|
|
24
|
+
limit: number;
|
|
25
|
+
jsonOut: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface VerifyOptions {
|
|
28
|
+
orderId: string;
|
|
29
|
+
action: AtpVerifyAction;
|
|
30
|
+
}
|
|
31
|
+
export interface AtpOptions {
|
|
32
|
+
sub: 'enable' | 'disable' | 'status';
|
|
33
|
+
}
|
|
34
|
+
export interface AtpCliDeps {
|
|
35
|
+
client?: AtpCliClient;
|
|
36
|
+
env?: NodeJS.ProcessEnv;
|
|
37
|
+
log?: LogFn;
|
|
38
|
+
err?: LogFn;
|
|
39
|
+
sleep?: (ms: number) => Promise<void>;
|
|
40
|
+
consentPath?: string;
|
|
41
|
+
now?: () => Date;
|
|
42
|
+
}
|
|
43
|
+
export interface AtpCliClient {
|
|
44
|
+
placeOrder(opts: AtpOrderOptions): Promise<AtpResult>;
|
|
45
|
+
getOrderStatus(orderId: string): Promise<AtpResult>;
|
|
46
|
+
listProofs(opts: AtpListProofsOptions): Promise<AtpResult>;
|
|
47
|
+
verifyDelivery(orderId: string, action: AtpVerifyAction | string): Promise<AtpResult>;
|
|
48
|
+
}
|
|
49
|
+
export interface AtpConsent {
|
|
50
|
+
enabled: boolean;
|
|
51
|
+
source: 'env' | 'ack' | 'default';
|
|
52
|
+
ackPath: string;
|
|
53
|
+
}
|
|
54
|
+
export declare function parseBuyArgs(args: readonly string[]): ParseResult<BuyOptions>;
|
|
55
|
+
export declare function parseOrdersArgs(args: readonly string[]): ParseResult<OrdersOptions>;
|
|
56
|
+
export declare function parseVerifyArgs(args: readonly string[]): ParseResult<VerifyOptions>;
|
|
57
|
+
export declare function parseAtpArgs(args: readonly string[]): ParseResult<AtpOptions>;
|
|
58
|
+
export declare function runBuy(opts: BuyOptions, deps?: AtpCliDeps): Promise<{
|
|
59
|
+
exitCode: number;
|
|
60
|
+
data?: unknown;
|
|
61
|
+
error?: string;
|
|
62
|
+
}>;
|
|
63
|
+
export declare function runOrders(opts: OrdersOptions, deps?: AtpCliDeps): Promise<{
|
|
64
|
+
exitCode: number;
|
|
65
|
+
data?: unknown;
|
|
66
|
+
error?: string;
|
|
67
|
+
}>;
|
|
68
|
+
export declare function runVerify(opts: VerifyOptions, deps?: AtpCliDeps): Promise<{
|
|
69
|
+
exitCode: number;
|
|
70
|
+
data?: unknown;
|
|
71
|
+
error?: string;
|
|
72
|
+
}>;
|
|
73
|
+
export declare function runAtp(opts: AtpOptions, deps?: AtpCliDeps): Promise<{
|
|
74
|
+
exitCode: number;
|
|
75
|
+
data?: unknown;
|
|
76
|
+
envOverride?: 'on' | 'off';
|
|
77
|
+
error?: string;
|
|
78
|
+
}>;
|
|
79
|
+
export declare function runBuyCommand(argv: readonly string[]): Promise<number>;
|
|
80
|
+
export declare function runOrdersCommand(argv: readonly string[]): Promise<number>;
|
|
81
|
+
export declare function runVerifyCommand(argv: readonly string[]): Promise<number>;
|
|
82
|
+
export declare function runAtpCommand(argv: readonly string[]): Promise<number>;
|
|
83
|
+
export declare function createAtpClientFromEnv(env?: NodeJS.ProcessEnv): AtpHubClient;
|
|
84
|
+
export declare function resolveAtpHome(env?: NodeJS.ProcessEnv): string;
|
|
85
|
+
export declare function atpConsentPath(env?: NodeJS.ProcessEnv): string;
|
|
86
|
+
export declare function getAtpConsent(env?: NodeJS.ProcessEnv, ackPath?: string): AtpConsent;
|
|
87
|
+
/** Thrown when an autonomous (non-explicit) spend is attempted without recorded/enabled auto-spend consent (#177). */
|
|
88
|
+
export declare class AtpSpendConsentError extends Error {
|
|
89
|
+
readonly source: AtpConsent['source'];
|
|
90
|
+
constructor(source: AtpConsent['source']);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* THE single enforced consent gate every ATP spend path MUST pass through (#177). One door, two callers:
|
|
94
|
+
* - explicit (a human ran `evolver buy`) → the invocation IS the consent, allowed through.
|
|
95
|
+
* - autonomous (future auto-buy / autoexec auto-order / swarm purchase) → must have getAtpConsent().enabled,
|
|
96
|
+
* else refused. This keeps consent enforcement UPSTREAM of money movement instead of a read-only status bit
|
|
97
|
+
* each caller might forget to check (the latent money-safety hole autogame-17 flagged). Any new autonomous
|
|
98
|
+
* spending path is required to call this (NOT client.placeOrder directly) — see placeAtpOrderWithConsent.
|
|
99
|
+
*/
|
|
100
|
+
export declare function assertAtpSpendConsent(opts?: {
|
|
101
|
+
explicit?: boolean;
|
|
102
|
+
env?: NodeJS.ProcessEnv;
|
|
103
|
+
consentPath?: string;
|
|
104
|
+
}): void;
|
|
105
|
+
/**
|
|
106
|
+
* Place an ATP order through the enforced consent gate (#177) — the composition layer money movement goes
|
|
107
|
+
* through so consent can't be bypassed. Manual `buy` passes explicit:true; an autonomous caller omits it and is
|
|
108
|
+
* gated by recorded/env consent. Throws AtpSpendConsentError before any order is placed when refused.
|
|
109
|
+
*/
|
|
110
|
+
export declare function placeAtpOrderWithConsent(client: Pick<AtpCliClient, 'placeOrder'>, order: AtpOrderOptions, consent?: {
|
|
111
|
+
explicit?: boolean;
|
|
112
|
+
env?: NodeJS.ProcessEnv;
|
|
113
|
+
consentPath?: string;
|
|
114
|
+
}): Promise<AtpResult>;
|
|
115
|
+
export declare function setAtpConsent(enabled: boolean, ackPath?: string, now?: () => Date): {
|
|
116
|
+
enabled: boolean;
|
|
117
|
+
acknowledged_at: string;
|
|
118
|
+
version: 1;
|
|
119
|
+
};
|
|
120
|
+
export declare function resolveAtpSenderId(env?: NodeJS.ProcessEnv): string | undefined;
|
|
121
|
+
export declare function printAtpUsage(): string;
|
|
122
|
+
export {};
|