@metaharness/darwin 0.1.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/LICENSE +21 -0
- package/README.md +221 -0
- package/SECURITY.md +200 -0
- package/dist/archive.d.ts +89 -0
- package/dist/archive.d.ts.map +1 -0
- package/dist/archive.js +220 -0
- package/dist/archive.js.map +1 -0
- package/dist/bench/gates.d.ts +19 -0
- package/dist/bench/gates.d.ts.map +1 -0
- package/dist/bench/gates.js +82 -0
- package/dist/bench/gates.js.map +1 -0
- package/dist/bench/index.d.ts +11 -0
- package/dist/bench/index.d.ts.map +1 -0
- package/dist/bench/index.js +25 -0
- package/dist/bench/index.js.map +1 -0
- package/dist/bench/lineage.d.ts +60 -0
- package/dist/bench/lineage.d.ts.map +1 -0
- package/dist/bench/lineage.js +166 -0
- package/dist/bench/lineage.js.map +1 -0
- package/dist/bench/metrics.d.ts +32 -0
- package/dist/bench/metrics.d.ts.map +1 -0
- package/dist/bench/metrics.js +52 -0
- package/dist/bench/metrics.js.map +1 -0
- package/dist/bench/promotion.d.ts +21 -0
- package/dist/bench/promotion.d.ts.map +1 -0
- package/dist/bench/promotion.js +109 -0
- package/dist/bench/promotion.js.map +1 -0
- package/dist/bench/risk.d.ts +45 -0
- package/dist/bench/risk.d.ts.map +1 -0
- package/dist/bench/risk.js +71 -0
- package/dist/bench/risk.js.map +1 -0
- package/dist/bench/runner.d.ts +53 -0
- package/dist/bench/runner.d.ts.map +1 -0
- package/dist/bench/runner.js +131 -0
- package/dist/bench/runner.js.map +1 -0
- package/dist/bench/score.d.ts +16 -0
- package/dist/bench/score.d.ts.map +1 -0
- package/dist/bench/score.js +83 -0
- package/dist/bench/score.js.map +1 -0
- package/dist/bench/stats.d.ts +26 -0
- package/dist/bench/stats.d.ts.map +1 -0
- package/dist/bench/stats.js +74 -0
- package/dist/bench/stats.js.map +1 -0
- package/dist/bench/suite.d.ts +16 -0
- package/dist/bench/suite.d.ts.map +1 -0
- package/dist/bench/suite.js +59 -0
- package/dist/bench/suite.js.map +1 -0
- package/dist/bench/types.d.ts +135 -0
- package/dist/bench/types.d.ts.map +1 -0
- package/dist/bench/types.js +16 -0
- package/dist/bench/types.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +125 -0
- package/dist/cli.js.map +1 -0
- package/dist/evolve.d.ts +11 -0
- package/dist/evolve.d.ts.map +1 -0
- package/dist/evolve.js +129 -0
- package/dist/evolve.js.map +1 -0
- package/dist/generator.d.ts +9 -0
- package/dist/generator.d.ts.map +1 -0
- package/dist/generator.js +46 -0
- package/dist/generator.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/mutator.d.ts +61 -0
- package/dist/mutator.d.ts.map +1 -0
- package/dist/mutator.js +193 -0
- package/dist/mutator.js.map +1 -0
- package/dist/openrouter-mutator.d.ts +32 -0
- package/dist/openrouter-mutator.d.ts.map +1 -0
- package/dist/openrouter-mutator.js +81 -0
- package/dist/openrouter-mutator.js.map +1 -0
- package/dist/repo_profiler.d.ts +8 -0
- package/dist/repo_profiler.d.ts.map +1 -0
- package/dist/repo_profiler.js +127 -0
- package/dist/repo_profiler.js.map +1 -0
- package/dist/safety.d.ts +45 -0
- package/dist/safety.d.ts.map +1 -0
- package/dist/safety.js +191 -0
- package/dist/safety.js.map +1 -0
- package/dist/sandbox.d.ts +24 -0
- package/dist/sandbox.d.ts.map +1 -0
- package/dist/sandbox.js +153 -0
- package/dist/sandbox.js.map +1 -0
- package/dist/scorer.d.ts +26 -0
- package/dist/scorer.d.ts.map +1 -0
- package/dist/scorer.js +168 -0
- package/dist/scorer.js.map +1 -0
- package/dist/templates.d.ts +37 -0
- package/dist/templates.d.ts.map +1 -0
- package/dist/templates.js +309 -0
- package/dist/templates.js.map +1 -0
- package/dist/types.d.ts +123 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +13 -0
- package/dist/types.js.map +1 -0
- package/package.json +57 -0
package/dist/evolve.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
//
|
|
3
|
+
// The evolution loop (ADR-070). Ties the pieces together:
|
|
4
|
+
//
|
|
5
|
+
// profile → baseline → (mutate → sandbox → score → archive)* → promote/select
|
|
6
|
+
//
|
|
7
|
+
// Population variants are evaluated with BOUNDED concurrency (no unbounded fan-out),
|
|
8
|
+
// under an optional per-generation cost-proxy budget (the circuit breaker of
|
|
9
|
+
// ADR-072). Selection samples from the WHOLE archive on a stalled generation
|
|
10
|
+
// (ADR-073) rather than dead-ending — a weak ancestor can still seed a branch.
|
|
11
|
+
import { mkdir, writeFile } from 'node:fs/promises';
|
|
12
|
+
import { join } from 'node:path';
|
|
13
|
+
import { Archive } from './archive.js';
|
|
14
|
+
import { generateBaselineHarness } from './generator.js';
|
|
15
|
+
import { createChildVariant, DeterministicMutator } from './mutator.js';
|
|
16
|
+
import { profileRepo } from './repo_profiler.js';
|
|
17
|
+
import { runVariantTasks } from './sandbox.js';
|
|
18
|
+
import { scoreVariant } from './scorer.js';
|
|
19
|
+
const DEFAULT_CONCURRENCY = 4;
|
|
20
|
+
const DEFAULT_TASK_TIMEOUT_MS = 120_000;
|
|
21
|
+
/** Run async `fn` over `items` with at most `limit` in flight at once. Order-preserving. */
|
|
22
|
+
export async function mapLimit(items, limit, fn) {
|
|
23
|
+
const results = new Array(items.length);
|
|
24
|
+
let next = 0;
|
|
25
|
+
const width = Math.max(1, Math.min(limit, items.length));
|
|
26
|
+
const workers = Array.from({ length: width }, async () => {
|
|
27
|
+
for (;;) {
|
|
28
|
+
const i = next++;
|
|
29
|
+
if (i >= items.length)
|
|
30
|
+
break;
|
|
31
|
+
results[i] = await fn(items[i], i);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
await Promise.all(workers);
|
|
35
|
+
return results;
|
|
36
|
+
}
|
|
37
|
+
async function ensureWorkRoot(workRoot) {
|
|
38
|
+
await mkdir(join(workRoot, 'variants'), { recursive: true });
|
|
39
|
+
await mkdir(join(workRoot, 'runs'), { recursive: true });
|
|
40
|
+
await mkdir(join(workRoot, 'reports'), { recursive: true });
|
|
41
|
+
}
|
|
42
|
+
/** Run + score one variant. Pure of archive mutation (caller commits results). */
|
|
43
|
+
async function evaluateVariant(variant, profile, cfg, parentScore) {
|
|
44
|
+
const timeout = cfg.taskTimeoutMs ?? DEFAULT_TASK_TIMEOUT_MS;
|
|
45
|
+
const traces = await runVariantTasks(variant, profile, cfg.tasks, {
|
|
46
|
+
taskTimeoutMs: timeout,
|
|
47
|
+
});
|
|
48
|
+
const score = scoreVariant(variant.id, traces, parentScore, cfg.promotionDelta, timeout);
|
|
49
|
+
return { variant, traces, score };
|
|
50
|
+
}
|
|
51
|
+
/** Cost proxy for the breaker: cumulative variant-seconds in a generation. */
|
|
52
|
+
function traceSeconds(traces) {
|
|
53
|
+
return traces.reduce((s, t) => s + t.durationMs, 0) / 1000;
|
|
54
|
+
}
|
|
55
|
+
async function commit(archive, workRoot, evalResult) {
|
|
56
|
+
await writeFile(join(workRoot, 'runs', `${evalResult.variant.id}.json`), JSON.stringify({ traces: evalResult.traces, score: evalResult.score }, null, 2), 'utf8');
|
|
57
|
+
archive.setScore(evalResult.variant.id, evalResult.score);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Run a full Darwin Mode evolution. Returns the baseline, the winning record,
|
|
61
|
+
* the whole archive, and the winner's lineage. Side effects are confined to the
|
|
62
|
+
* `<workRoot>/.metaharness`-style tree (variants, runs, reports, archive.json,
|
|
63
|
+
* lineage.json).
|
|
64
|
+
*/
|
|
65
|
+
export async function evolve(config) {
|
|
66
|
+
await ensureWorkRoot(config.workRoot);
|
|
67
|
+
const profile = await profileRepo(config.repoRoot);
|
|
68
|
+
const archive = new Archive(join(config.workRoot, 'archive.json'));
|
|
69
|
+
await archive.load();
|
|
70
|
+
const seed = config.seed ?? 0;
|
|
71
|
+
const concurrency = config.concurrency ?? DEFAULT_CONCURRENCY;
|
|
72
|
+
// ADR-071: pluggable generator. Default deterministic; config.generator can
|
|
73
|
+
// be an LLM-backed CodeGenerator (e.g. OpenRouterMutator) — same safety gate.
|
|
74
|
+
const mutator = config.generator ?? new DeterministicMutator(seed);
|
|
75
|
+
// --- baseline ---
|
|
76
|
+
const baseline = await generateBaselineHarness(profile, config.workRoot);
|
|
77
|
+
archive.addVariant(baseline);
|
|
78
|
+
const baselineEval = await evaluateVariant(baseline, profile, config, null);
|
|
79
|
+
await commit(archive, config.workRoot, baselineEval);
|
|
80
|
+
await archive.save();
|
|
81
|
+
const scoreById = new Map([[baseline.id, baselineEval.score]]);
|
|
82
|
+
let parents = [baseline];
|
|
83
|
+
// --- generations ---
|
|
84
|
+
for (let generation = 1; generation <= config.generations; generation++) {
|
|
85
|
+
// Build this generation's children from the current parents.
|
|
86
|
+
const children = [];
|
|
87
|
+
for (const parent of parents) {
|
|
88
|
+
for (let index = 0; index < config.childrenPerGeneration; index++) {
|
|
89
|
+
const child = await createChildVariant(parent, config.workRoot, generation, index, mutator, seed);
|
|
90
|
+
archive.addVariant(child);
|
|
91
|
+
children.push({ child, parent });
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
// Evaluate with bounded concurrency.
|
|
95
|
+
const evals = await mapLimit(children, concurrency, ({ child, parent }) => evaluateVariant(child, profile, config, scoreById.get(parent.id) ?? null));
|
|
96
|
+
// Commit sequentially (single-writer to the archive + one save), honouring
|
|
97
|
+
// the per-generation cost breaker.
|
|
98
|
+
let spent = 0;
|
|
99
|
+
const promoted = [];
|
|
100
|
+
for (const ev of evals) {
|
|
101
|
+
await commit(archive, config.workRoot, ev);
|
|
102
|
+
scoreById.set(ev.variant.id, ev.score);
|
|
103
|
+
if (ev.score.promoted)
|
|
104
|
+
promoted.push(ev.variant);
|
|
105
|
+
spent += traceSeconds(ev.traces);
|
|
106
|
+
if (config.costBudgetSeconds && spent >= config.costBudgetSeconds)
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
await archive.save();
|
|
110
|
+
// Selection (ADR-073): prefer promoted children; on a stalled generation
|
|
111
|
+
// sample the whole archive so we explore sideways instead of dead-ending.
|
|
112
|
+
parents = promoted.length > 0 ? promoted : archive.selectParents(2);
|
|
113
|
+
if (parents.length === 0)
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
const winner = archive.best();
|
|
117
|
+
const winnerLineage = winner ? archive.lineageOf(winner.variant.id) : [];
|
|
118
|
+
await writeFile(join(config.workRoot, 'reports', 'winner.json'), JSON.stringify(winner, null, 2), 'utf8');
|
|
119
|
+
await writeFile(join(config.workRoot, 'lineage.json'), JSON.stringify(archive.toLineageGraph(), null, 2), 'utf8');
|
|
120
|
+
const baselineRecord = archive.get(baseline.id);
|
|
121
|
+
return {
|
|
122
|
+
baseline: baselineRecord ?? { variant: baseline, score: baselineEval.score, children: [] },
|
|
123
|
+
winner,
|
|
124
|
+
records: archive.all(),
|
|
125
|
+
generations: config.generations,
|
|
126
|
+
winnerLineage,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=evolve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evolve.js","sourceRoot":"","sources":["../src/evolve.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,EAAE;AACF,0DAA0D;AAC1D,EAAE;AACF,gFAAgF;AAChF,EAAE;AACF,qFAAqF;AACrF,6EAA6E;AAC7E,6EAA6E;AAC7E,+EAA+E;AAE/E,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,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Q,EAAE,EAAE,EAAE;QAC1F,MAAM;QACN,OAAO,EAAE,OAAO,CAAC,GAAG,EAAE;QACtB,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,aAAa;KACd,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { HarnessVariant, RepoProfile } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Generate the baseline harness variant from a repo profile. Writes the seven
|
|
4
|
+
* mutation-surface files (filenames per FILE_BY_SURFACE) into
|
|
5
|
+
* `<workRoot>/variants/baseline/`, creating directories as needed, and returns
|
|
6
|
+
* the variant descriptor. Generation 0, no parent.
|
|
7
|
+
*/
|
|
8
|
+
export declare function generateBaselineHarness(profile: RepoProfile, workRoot: string): Promise<HarnessVariant>;
|
|
9
|
+
//# sourceMappingURL=generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../src/generator.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAY9D;;;;;GAKG;AACH,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,WAAW,EACpB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,cAAc,CAAC,CA6BzB"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
//
|
|
3
|
+
// Baseline generator (ADR-070 §generate) — turns a RepoProfile into the root
|
|
4
|
+
// "baseline" harness variant: a directory holding exactly the seven approved
|
|
5
|
+
// mutation-surface files (ADR-071). Every emitted file is pure policy logic and
|
|
6
|
+
// passes the safety inspection by construction.
|
|
7
|
+
//
|
|
8
|
+
// Dependency-free (Node built-ins only).
|
|
9
|
+
import { mkdir, writeFile } from 'node:fs/promises';
|
|
10
|
+
import { join } from 'node:path';
|
|
11
|
+
import { FILE_BY_SURFACE } from './safety.js';
|
|
12
|
+
import { contextBuilderTemplate, memoryPolicyTemplate, plannerTemplate, retryPolicyTemplate, reviewerTemplate, scorePolicyTemplate, toolPolicyTemplate, } from './templates.js';
|
|
13
|
+
/**
|
|
14
|
+
* Generate the baseline harness variant from a repo profile. Writes the seven
|
|
15
|
+
* mutation-surface files (filenames per FILE_BY_SURFACE) into
|
|
16
|
+
* `<workRoot>/variants/baseline/`, creating directories as needed, and returns
|
|
17
|
+
* the variant descriptor. Generation 0, no parent.
|
|
18
|
+
*/
|
|
19
|
+
export async function generateBaselineHarness(profile, workRoot) {
|
|
20
|
+
const dir = join(workRoot, 'variants', 'baseline');
|
|
21
|
+
await mkdir(dir, { recursive: true });
|
|
22
|
+
// Surface filename -> source text. Filenames come from the safety allowlist so
|
|
23
|
+
// the generator and inspector can never drift apart.
|
|
24
|
+
const files = {
|
|
25
|
+
[FILE_BY_SURFACE.planner]: plannerTemplate(profile),
|
|
26
|
+
[FILE_BY_SURFACE.contextBuilder]: contextBuilderTemplate(),
|
|
27
|
+
[FILE_BY_SURFACE.reviewer]: reviewerTemplate(),
|
|
28
|
+
[FILE_BY_SURFACE.retryPolicy]: retryPolicyTemplate(),
|
|
29
|
+
[FILE_BY_SURFACE.toolPolicy]: toolPolicyTemplate(),
|
|
30
|
+
[FILE_BY_SURFACE.memoryPolicy]: memoryPolicyTemplate(),
|
|
31
|
+
[FILE_BY_SURFACE.scorePolicy]: scorePolicyTemplate(),
|
|
32
|
+
};
|
|
33
|
+
for (const [name, source] of Object.entries(files)) {
|
|
34
|
+
await writeFile(join(dir, name), source, 'utf8');
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
id: 'baseline',
|
|
38
|
+
parentId: null,
|
|
39
|
+
generation: 0,
|
|
40
|
+
dir,
|
|
41
|
+
mutationSurface: 'planner',
|
|
42
|
+
mutationSummary: 'baseline generated from repo profile',
|
|
43
|
+
createdAt: new Date().toISOString(),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=generator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F,KAAK,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACnD,MAAM,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IACnD,CAAC;IAED,OAAO;QACL,EAAE,EAAE,UAAU;QACd,QAAQ,EAAE,IAAI;QACd,UAAU,EAAE,CAAC;QACb,GAAG;QACH,eAAe,EAAE,SAAS;QAC1B,eAAe,EAAE,sCAAsC;QACvD,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;KACpC,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from './types.js';
|
|
2
|
+
export * from './safety.js';
|
|
3
|
+
export * from './repo_profiler.js';
|
|
4
|
+
export * from './templates.js';
|
|
5
|
+
export * from './generator.js';
|
|
6
|
+
export * from './mutator.js';
|
|
7
|
+
export * from './sandbox.js';
|
|
8
|
+
export * from './scorer.js';
|
|
9
|
+
export * from './archive.js';
|
|
10
|
+
export * from './evolve.js';
|
|
11
|
+
export * as bench from './bench/index.js';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAwBA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAI5B,OAAO,KAAK,KAAK,MAAM,kBAAkB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
//
|
|
3
|
+
// @metaharness/darwin — Darwin Mode (ADR-070…075).
|
|
4
|
+
//
|
|
5
|
+
// Bounded, empirical, population-based self-improvement of an agent harness.
|
|
6
|
+
// The foundation model is frozen; the HARNESS evolves: generate child variants
|
|
7
|
+
// over seven approved mutation surfaces, sandbox-score them, archive the lineage
|
|
8
|
+
// as a tree (not a single best branch), and promote only measured, safe wins.
|
|
9
|
+
//
|
|
10
|
+
// The model proposes nothing here — the harness mutates, the benchmark judges,
|
|
11
|
+
// the archive remembers.
|
|
12
|
+
//
|
|
13
|
+
// Modules:
|
|
14
|
+
// types — the shared contract
|
|
15
|
+
// safety — the load-bearing allowlist + content gate (ADR-071)
|
|
16
|
+
// repo_profiler — repo → RepoProfile
|
|
17
|
+
// templates — the seven baseline mutation-surface sources
|
|
18
|
+
// generator — RepoProfile → baseline variant
|
|
19
|
+
// mutator — bounded, validated child mutations + the CodeGenerator hook
|
|
20
|
+
// sandbox — gate-first, shell-free, env-scrubbed task runner
|
|
21
|
+
// scorer — the frozen weighted scorer + strict promotion gate (ADR-072)
|
|
22
|
+
// archive — the population tree + archive-wide selection (ADR-073)
|
|
23
|
+
// evolve — the loop that composes them all (ADR-070)
|
|
24
|
+
export * from './types.js';
|
|
25
|
+
export * from './safety.js';
|
|
26
|
+
export * from './repo_profiler.js';
|
|
27
|
+
export * from './templates.js';
|
|
28
|
+
export * from './generator.js';
|
|
29
|
+
export * from './mutator.js';
|
|
30
|
+
export * from './sandbox.js';
|
|
31
|
+
export * from './scorer.js';
|
|
32
|
+
export * from './archive.js';
|
|
33
|
+
export * from './evolve.js';
|
|
34
|
+
// The benchmark + SOTA "Darwin Plus" layer (ADR-076…081) is namespaced to avoid
|
|
35
|
+
// name collisions (e.g. scoreWeights) with the lightweight ADR-072 scorer.
|
|
36
|
+
export * as bench from './bench/index.js';
|
|
37
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,EAAE;AACF,mDAAmD;AACnD,EAAE;AACF,6EAA6E;AAC7E,+EAA+E;AAC/E,iFAAiF;AACjF,8EAA8E;AAC9E,EAAE;AACF,iFAAiF;AACjF,2BAA2B;AAC3B,EAAE;AACF,WAAW;AACX,yCAAyC;AACzC,yEAAyE;AACzE,wCAAwC;AACxC,iEAAiE;AACjE,oDAAoD;AACpD,iFAAiF;AACjF,sEAAsE;AACtE,kFAAkF;AAClF,4EAA4E;AAC5E,+DAA+D;AAE/D,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAE5B,gFAAgF;AAChF,2EAA2E;AAC3E,OAAO,KAAK,KAAK,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { HarnessVariant, MutationSurface } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* A pluggable code generator. Given the parent's surface file and context, it
|
|
4
|
+
* returns replacement code for that one file plus a one-line summary. The
|
|
5
|
+
* default implementation is deterministic; an LLM-backed one slots in behind the
|
|
6
|
+
* same `validateGeneratedCode` gate (ADR-071 §contract).
|
|
7
|
+
*/
|
|
8
|
+
export interface CodeGenerator {
|
|
9
|
+
generateMutation(input: {
|
|
10
|
+
parentCode: string;
|
|
11
|
+
surface: MutationSurface;
|
|
12
|
+
repoSummary: string;
|
|
13
|
+
parentScore: number;
|
|
14
|
+
failedTraces: string[];
|
|
15
|
+
}): Promise<{
|
|
16
|
+
code: string;
|
|
17
|
+
summary: string;
|
|
18
|
+
}>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The default mutator: deterministic, seeded, dependency-free. It applies the
|
|
22
|
+
* first matching bounded edit (in a seeded rotation) to the parent file. If no
|
|
23
|
+
* edit rule matches, it appends a tracking comment — a safe, signature-neutral
|
|
24
|
+
* no-op so the surface still differs and the file still passes the scanner.
|
|
25
|
+
*/
|
|
26
|
+
export declare class DeterministicMutator implements CodeGenerator {
|
|
27
|
+
private readonly seed;
|
|
28
|
+
constructor(seed?: number);
|
|
29
|
+
generateMutation(input: {
|
|
30
|
+
parentCode: string;
|
|
31
|
+
surface: MutationSurface;
|
|
32
|
+
repoSummary: string;
|
|
33
|
+
parentScore: number;
|
|
34
|
+
failedTraces: string[];
|
|
35
|
+
}): Promise<{
|
|
36
|
+
code: string;
|
|
37
|
+
summary: string;
|
|
38
|
+
}>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Deterministically pick one of the seven surfaces from `(generation+index+seed)`.
|
|
42
|
+
* Same inputs ⇒ same surface (reproducibility, ADR-070 §seed).
|
|
43
|
+
*/
|
|
44
|
+
export declare function pickSurface(generation: number, index: number, seed: number): MutationSurface;
|
|
45
|
+
/**
|
|
46
|
+
* Recursively copy a variant directory using `node:fs/promises` only (never a
|
|
47
|
+
* shell). The destination is created fresh; only the parent's files are copied,
|
|
48
|
+
* so no extraneous entry can leak in.
|
|
49
|
+
*/
|
|
50
|
+
export declare function copyVariantDir(src: string, dest: string): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Create a child variant from `parent`: copy its directory, pick one surface
|
|
53
|
+
* deterministically, regenerate that surface's file via `gen`, validate the
|
|
54
|
+
* generated code BEFORE writing, and return the resulting `HarnessVariant`.
|
|
55
|
+
*
|
|
56
|
+
* If `validateGeneratedCode` reports any violation, the mutation is DISCARDED
|
|
57
|
+
* and the parent's surface file is left untouched (a safe no-op). The child
|
|
58
|
+
* directory therefore always still passes `inspectVariant`.
|
|
59
|
+
*/
|
|
60
|
+
export declare function createChildVariant(parent: HarnessVariant, workRoot: string, generation: number, index: number, gen?: CodeGenerator, seed?: number): Promise<HarnessVariant>;
|
|
61
|
+
//# sourceMappingURL=mutator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mutator.d.ts","sourceRoot":"","sources":["../src/mutator.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElE;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC5B,gBAAgB,CAAC,KAAK,EAAE;QACtB,UAAU,EAAE,MAAM,CAAC;QACnB,OAAO,EAAE,eAAe,CAAC;QACzB,WAAW,EAAE,MAAM,CAAC;QACpB,WAAW,EAAE,MAAM,CAAC;QACpB,YAAY,EAAE,MAAM,EAAE,CAAC;KACxB,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAChD;AA6FD;;;;;GAKG;AACH,qBAAa,oBAAqB,YAAW,aAAa;IACxD,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;gBAElB,IAAI,SAAI;IAId,gBAAgB,CAAC,KAAK,EAAE;QAC5B,UAAU,EAAE,MAAM,CAAC;QACnB,OAAO,EAAE,eAAe,CAAC;QACzB,WAAW,EAAE,MAAM,CAAC;QACpB,WAAW,EAAE,MAAM,CAAC;QACpB,YAAY,EAAE,MAAM,EAAE,CAAC;KACxB,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CAqB/C;AAED;;;GAGG;AACH,wBAAgB,WAAW,CACzB,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,GACX,eAAe,CAGjB;AAED;;;;GAIG;AACH,wBAAsB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAG7E;AAED;;;;;;;;GAQG;AACH,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,cAAc,EACtB,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,EACb,GAAG,GAAE,aAA0C,EAC/C,IAAI,SAAI,GACP,OAAO,CAAC,cAAc,CAAC,CA4CzB"}
|
package/dist/mutator.js
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
//
|
|
3
|
+
// The mutation engine (ADR-071) — produces a child variant from a parent by
|
|
4
|
+
// perturbing exactly one approved surface file, behind the safety gate.
|
|
5
|
+
//
|
|
6
|
+
// A mutation is BOUNDED by construction: it copies the parent variant directory
|
|
7
|
+
// verbatim, picks ONE surface deterministically, regenerates ONLY that surface's
|
|
8
|
+
// file, and writes nothing else. Generated code is run through
|
|
9
|
+
// `validateGeneratedCode` BEFORE it touches disk; a violation is discarded and
|
|
10
|
+
// the parent's file is preserved (a safe no-op mutation), so a child variant
|
|
11
|
+
// always still passes `inspectVariant` (ADR-071 §hard gate).
|
|
12
|
+
//
|
|
13
|
+
// The mutator is pluggable via `CodeGenerator`: the default `DeterministicMutator`
|
|
14
|
+
// performs seeded string-replacement edits (the prototype path), and can be
|
|
15
|
+
// swapped for an LLM-backed generator behind the SAME gate.
|
|
16
|
+
import { cp, mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
17
|
+
import { join } from 'node:path';
|
|
18
|
+
import { FILE_BY_SURFACE, SURFACES, validateGeneratedCode } from './safety.js';
|
|
19
|
+
/** A pure, deterministic 32-bit hash — seeds choice without `Math.random`. */
|
|
20
|
+
function hash(...parts) {
|
|
21
|
+
let h = 0x811c9dc5;
|
|
22
|
+
const s = parts.join('|');
|
|
23
|
+
for (let i = 0; i < s.length; i++) {
|
|
24
|
+
h ^= s.charCodeAt(i);
|
|
25
|
+
h = Math.imul(h, 0x01000193);
|
|
26
|
+
}
|
|
27
|
+
return h >>> 0;
|
|
28
|
+
}
|
|
29
|
+
/** Clamp a `.slice(start, end)` window to a small, sane range. */
|
|
30
|
+
function clampWindow(n) {
|
|
31
|
+
if (!Number.isFinite(n))
|
|
32
|
+
return 30;
|
|
33
|
+
return Math.max(5, Math.min(200, Math.round(n)));
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The ordered catalogue of bounded edits the deterministic mutator can apply.
|
|
37
|
+
* They are tried in a seeded rotation; the first that matches the parent file is
|
|
38
|
+
* used. Every rule is signature-preserving and capability-neutral.
|
|
39
|
+
*/
|
|
40
|
+
const EDIT_RULES = [
|
|
41
|
+
// Tweak a `.slice(0, N)` context window up or down by a bounded step.
|
|
42
|
+
{
|
|
43
|
+
find: /\.slice\(\s*0\s*,\s*(\d+)\s*\)/,
|
|
44
|
+
replace: (match, variant) => {
|
|
45
|
+
const current = Number(/(\d+)\s*\)/.exec(match)?.[1] ?? '30');
|
|
46
|
+
const step = (variant % 2 === 0 ? 1 : -1) * (10 + (variant % 3) * 5);
|
|
47
|
+
const next = clampWindow(current + step);
|
|
48
|
+
return match.replace(/0\s*,\s*\d+/, `0, ${next}`);
|
|
49
|
+
},
|
|
50
|
+
summary: (variant) => `adjusted context slice window (variant ${variant})`,
|
|
51
|
+
},
|
|
52
|
+
// Adjust a retry / attempt budget literal (e.g. `maxRetries = 3`).
|
|
53
|
+
{
|
|
54
|
+
find: /\b(maxRetries|retries|maxAttempts|attempts|retryBudget|budget)\b(\s*[:=]\s*)(\d+)/,
|
|
55
|
+
replace: (match, variant) => {
|
|
56
|
+
const m = /(\d+)\s*$/.exec(match);
|
|
57
|
+
const current = Number(m?.[1] ?? '3');
|
|
58
|
+
const delta = variant % 2 === 0 ? 1 : -1;
|
|
59
|
+
const next = Math.max(0, Math.min(16, current + delta));
|
|
60
|
+
return match.replace(/\d+\s*$/, String(next));
|
|
61
|
+
},
|
|
62
|
+
summary: (variant) => `adjusted retry/attempt budget (variant ${variant})`,
|
|
63
|
+
},
|
|
64
|
+
// Nudge a numeric threshold literal (memory/score policy), bounded to [0,1].
|
|
65
|
+
{
|
|
66
|
+
find: /\b(threshold|cutoff|minScore|weight|decay|temperature)\b(\s*[:=]\s*)(0?\.\d+|1(?:\.0+)?|0)\b/,
|
|
67
|
+
replace: (match, variant) => {
|
|
68
|
+
const m = /(0?\.\d+|1(?:\.0+)?|0)\s*$/.exec(match);
|
|
69
|
+
const current = Number(m?.[1] ?? '0.5');
|
|
70
|
+
const step = (variant % 2 === 0 ? 0.05 : -0.05) * (1 + (variant % 2));
|
|
71
|
+
const next = Math.max(0, Math.min(1, Math.round((current + step) * 100) / 100));
|
|
72
|
+
return match.replace(/(0?\.\d+|1(?:\.0+)?|0)\s*$/, String(next));
|
|
73
|
+
},
|
|
74
|
+
summary: (variant) => `nudged numeric threshold (variant ${variant})`,
|
|
75
|
+
},
|
|
76
|
+
// Perturb a quoted planner/reviewer phrase by appending a directive variant.
|
|
77
|
+
{
|
|
78
|
+
find: /(['"`])((?:step|plan|decompose|review|consider|first|then|focus)[^'"`]{0,80}?)\1/i,
|
|
79
|
+
replace: (match, variant) => {
|
|
80
|
+
const phrases = [
|
|
81
|
+
' Prefer the smallest viable change.',
|
|
82
|
+
' Verify assumptions before acting.',
|
|
83
|
+
' Surface the riskiest unknown first.',
|
|
84
|
+
];
|
|
85
|
+
const add = phrases[variant % phrases.length];
|
|
86
|
+
const quote = match[0];
|
|
87
|
+
const inner = match.slice(1, -1).replace(/\s+$/, '');
|
|
88
|
+
return `${quote}${inner}${add}${quote}`;
|
|
89
|
+
},
|
|
90
|
+
summary: (variant) => `refined planner/reviewer phrasing (variant ${variant})`,
|
|
91
|
+
},
|
|
92
|
+
];
|
|
93
|
+
/**
|
|
94
|
+
* The default mutator: deterministic, seeded, dependency-free. It applies the
|
|
95
|
+
* first matching bounded edit (in a seeded rotation) to the parent file. If no
|
|
96
|
+
* edit rule matches, it appends a tracking comment — a safe, signature-neutral
|
|
97
|
+
* no-op so the surface still differs and the file still passes the scanner.
|
|
98
|
+
*/
|
|
99
|
+
export class DeterministicMutator {
|
|
100
|
+
seed;
|
|
101
|
+
constructor(seed = 0) {
|
|
102
|
+
this.seed = seed;
|
|
103
|
+
}
|
|
104
|
+
async generateMutation(input) {
|
|
105
|
+
const { parentCode, surface } = input;
|
|
106
|
+
const variant = hash(this.seed, surface, parentCode.length) % 6;
|
|
107
|
+
const start = hash(this.seed, surface) % EDIT_RULES.length;
|
|
108
|
+
for (let i = 0; i < EDIT_RULES.length; i++) {
|
|
109
|
+
const rule = EDIT_RULES[(start + i) % EDIT_RULES.length];
|
|
110
|
+
if (!rule.find.test(parentCode))
|
|
111
|
+
continue;
|
|
112
|
+
const code = parentCode.replace(rule.find, (m) => rule.replace(m, variant));
|
|
113
|
+
if (code !== parentCode) {
|
|
114
|
+
return { code, summary: rule.summary(variant) };
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
// No structural edit matched — emit a signature-neutral tracking comment.
|
|
118
|
+
const note = `\n// darwin: ${surface} perturbation v${variant} (seed ${this.seed})\n`;
|
|
119
|
+
return {
|
|
120
|
+
code: parentCode.replace(/\s*$/, '') + note,
|
|
121
|
+
summary: `appended ${surface} tracking note (no structural edit available)`,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Deterministically pick one of the seven surfaces from `(generation+index+seed)`.
|
|
127
|
+
* Same inputs ⇒ same surface (reproducibility, ADR-070 §seed).
|
|
128
|
+
*/
|
|
129
|
+
export function pickSurface(generation, index, seed) {
|
|
130
|
+
const i = hash(generation, index, seed) % SURFACES.length;
|
|
131
|
+
return SURFACES[i];
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Recursively copy a variant directory using `node:fs/promises` only (never a
|
|
135
|
+
* shell). The destination is created fresh; only the parent's files are copied,
|
|
136
|
+
* so no extraneous entry can leak in.
|
|
137
|
+
*/
|
|
138
|
+
export async function copyVariantDir(src, dest) {
|
|
139
|
+
await mkdir(dest, { recursive: true });
|
|
140
|
+
await cp(src, dest, { recursive: true, dereference: true, force: true });
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Create a child variant from `parent`: copy its directory, pick one surface
|
|
144
|
+
* deterministically, regenerate that surface's file via `gen`, validate the
|
|
145
|
+
* generated code BEFORE writing, and return the resulting `HarnessVariant`.
|
|
146
|
+
*
|
|
147
|
+
* If `validateGeneratedCode` reports any violation, the mutation is DISCARDED
|
|
148
|
+
* and the parent's surface file is left untouched (a safe no-op). The child
|
|
149
|
+
* directory therefore always still passes `inspectVariant`.
|
|
150
|
+
*/
|
|
151
|
+
export async function createChildVariant(parent, workRoot, generation, index, gen = new DeterministicMutator(), seed = 0) {
|
|
152
|
+
const id = `g${generation}_v${index}`;
|
|
153
|
+
const dir = join(workRoot, 'variants', id);
|
|
154
|
+
// 1) Copy the parent directory verbatim (no shell, no extra files).
|
|
155
|
+
await copyVariantDir(parent.dir, dir);
|
|
156
|
+
// 2) Pick the single surface to mutate, deterministically.
|
|
157
|
+
const surface = pickSurface(generation, index, seed);
|
|
158
|
+
const fileName = FILE_BY_SURFACE[surface];
|
|
159
|
+
const filePath = join(dir, fileName);
|
|
160
|
+
const parentCode = await readFile(filePath, 'utf8');
|
|
161
|
+
// 3) Generate a candidate mutation for that one file.
|
|
162
|
+
const { code, summary } = await gen.generateMutation({
|
|
163
|
+
parentCode,
|
|
164
|
+
surface,
|
|
165
|
+
repoSummary: '',
|
|
166
|
+
parentScore: 0,
|
|
167
|
+
failedTraces: [],
|
|
168
|
+
});
|
|
169
|
+
// 4) Gate: validate BEFORE writing. Violations are discarded, never written.
|
|
170
|
+
const violations = validateGeneratedCode(code);
|
|
171
|
+
let mutationSummary;
|
|
172
|
+
if (violations.length > 0) {
|
|
173
|
+
// Discard: leave the parent's file unchanged (safe no-op mutation).
|
|
174
|
+
mutationSummary = `mutation rejected by validator; surface unchanged (${violations.join('; ')})`;
|
|
175
|
+
}
|
|
176
|
+
else if (code === parentCode) {
|
|
177
|
+
mutationSummary = `${summary} (no-op: identical to parent)`;
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
await writeFile(filePath, code, 'utf8');
|
|
181
|
+
mutationSummary = summary;
|
|
182
|
+
}
|
|
183
|
+
return {
|
|
184
|
+
id,
|
|
185
|
+
parentId: parent.id,
|
|
186
|
+
generation,
|
|
187
|
+
dir,
|
|
188
|
+
mutationSurface: surface,
|
|
189
|
+
mutationSummary,
|
|
190
|
+
createdAt: new Date().toISOString(),
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
//# sourceMappingURL=mutator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mutator.js","sourceRoot":"","sources":["../src/mutator.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,EAAE;AACF,4EAA4E;AAC5E,wEAAwE;AACxE,EAAE;AACF,gFAAgF;AAChF,iFAAiF;AACjF,+DAA+D;AAC/D,+EAA+E;AAC/E,6EAA6E;AAC7E,6DAA6D;AAC7D,EAAE;AACF,mFAAmF;AACnF,4EAA4E;AAC5E,4DAA4D;AAE5D,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAiC/E,8EAA8E;AAC9E,SAAS,IAAI,CAAC,GAAG,KAA6B;IAC5C,IAAI,CAAC,GAAG,UAAU,CAAC;IACnB,MAAM,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC1B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QA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AC;QAC1B,oEAAoE;QACpE,eAAe,GAAG,sDAAsD,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;IACnG,CAAC;SAAM,IAAI,IAAI,KAAK,UAAU,EAAE,CAAC;QAC/B,eAAe,GAAG,GAAG,OAAO,+BAA+B,CAAC;IAC9D,CAAC;SAAM,CAAC;QACN,MAAM,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QACxC,eAAe,GAAG,OAAO,CAAC;IAC5B,CAAC;IAED,OAAO;QACL,EAAE;QACF,QAAQ,EAAE,MAAM,CAAC,EAAE;QACnB,UAAU;QACV,GAAG;QACH,eAAe,EAAE,OAAO;QACxB,eAAe;QACf,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;KACpC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { CodeGenerator } from './mutator.js';
|
|
2
|
+
import type { MutationSurface } from './types.js';
|
|
3
|
+
export interface OpenRouterMutatorOptions {
|
|
4
|
+
model?: string;
|
|
5
|
+
/** Per-call cost/latency cap. */
|
|
6
|
+
maxTokens?: number;
|
|
7
|
+
temperature?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface MutatorTelemetry {
|
|
10
|
+
calls: number;
|
|
11
|
+
promptTokens: number;
|
|
12
|
+
completionTokens: number;
|
|
13
|
+
costUSD: number;
|
|
14
|
+
}
|
|
15
|
+
export declare class OpenRouterMutator implements CodeGenerator {
|
|
16
|
+
readonly model: string;
|
|
17
|
+
private readonly maxTokens;
|
|
18
|
+
private readonly temperature;
|
|
19
|
+
readonly telemetry: MutatorTelemetry;
|
|
20
|
+
constructor(opts?: OpenRouterMutatorOptions);
|
|
21
|
+
generateMutation(input: {
|
|
22
|
+
parentCode: string;
|
|
23
|
+
surface: MutationSurface;
|
|
24
|
+
repoSummary: string;
|
|
25
|
+
parentScore: number;
|
|
26
|
+
failedTraces: string[];
|
|
27
|
+
}): Promise<{
|
|
28
|
+
code: string;
|
|
29
|
+
summary: string;
|
|
30
|
+
}>;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=openrouter-mutator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openrouter-mutator.d.ts","sourceRoot":"","sources":["../src/openrouter-mutator.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAkBlD,MAAM,WAAW,wBAAwB;IACvC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,iCAAiC;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,MAAM,CAAC;IACzB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,qBAAa,iBAAkB,YAAW,aAAa;IACrD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,QAAQ,CAAC,SAAS,EAAE,gBAAgB,CAAkE;gBAE1F,IAAI,GAAE,wBAA6B;IAMzC,gBAAgB,CAAC,KAAK,EAAE;QAC5B,UAAU,EAAE,MAAM,CAAC;QACnB,OAAO,EAAE,eAAe,CAAC;QACzB,WAAW,EAAE,MAAM,CAAC;QACpB,WAAW,EAAE,MAAM,CAAC;QACpB,YAAY,EAAE,MAAM,EAAE,CAAC;KACxB,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CA4C/C"}
|