@metaharness/darwin 0.1.0 → 0.2.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/README.md +69 -7
- package/dist/archive.d.ts +15 -0
- package/dist/archive.d.ts.map +1 -1
- package/dist/archive.js +41 -0
- package/dist/archive.js.map +1 -1
- package/dist/bench/promotion.d.ts.map +1 -1
- package/dist/bench/promotion.js +1 -0
- package/dist/bench/promotion.js.map +1 -1
- package/dist/bench/stats.d.ts +14 -0
- package/dist/bench/stats.d.ts.map +1 -1
- package/dist/bench/stats.js +38 -2
- package/dist/bench/stats.js.map +1 -1
- package/dist/bench/types.d.ts +4 -0
- package/dist/bench/types.d.ts.map +1 -1
- package/dist/clade.d.ts +26 -0
- package/dist/clade.d.ts.map +1 -0
- package/dist/clade.js +115 -0
- package/dist/clade.js.map +1 -0
- package/dist/cli.js +34 -1
- package/dist/cli.js.map +1 -1
- package/dist/curriculum.d.ts +19 -0
- package/dist/curriculum.d.ts.map +1 -0
- package/dist/curriculum.js +48 -0
- package/dist/curriculum.js.map +1 -0
- package/dist/epistasis.d.ts +40 -0
- package/dist/epistasis.d.ts.map +1 -0
- package/dist/epistasis.js +88 -0
- package/dist/epistasis.js.map +1 -0
- package/dist/evolve.d.ts +9 -1
- package/dist/evolve.d.ts.map +1 -1
- package/dist/evolve.js +314 -9
- package/dist/evolve.js.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -1
- package/dist/mock-sandbox.d.ts +58 -0
- package/dist/mock-sandbox.d.ts.map +1 -0
- package/dist/mock-sandbox.js +119 -0
- package/dist/mock-sandbox.js.map +1 -0
- package/dist/mutator.d.ts +44 -2
- package/dist/mutator.d.ts.map +1 -1
- package/dist/mutator.js +100 -7
- package/dist/mutator.js.map +1 -1
- package/dist/openrouter-mutator.d.ts.map +1 -1
- package/dist/openrouter-mutator.js +5 -2
- package/dist/openrouter-mutator.js.map +1 -1
- package/dist/pareto.d.ts +7 -0
- package/dist/pareto.d.ts.map +1 -0
- package/dist/pareto.js +46 -0
- package/dist/pareto.js.map +1 -0
- package/dist/phenotype.d.ts +83 -0
- package/dist/phenotype.d.ts.map +1 -0
- package/dist/phenotype.js +189 -0
- package/dist/phenotype.js.map +1 -0
- package/dist/templates.d.ts.map +1 -1
- package/dist/templates.js +6 -1
- package/dist/templates.js.map +1 -1
- package/dist/tier2-driver.d.ts +10 -0
- package/dist/tier2-driver.d.ts.map +1 -0
- package/dist/tier2-driver.js +62 -0
- package/dist/tier2-driver.js.map +1 -0
- package/dist/tier2-sandbox.d.ts +18 -0
- package/dist/tier2-sandbox.d.ts.map +1 -0
- package/dist/tier2-sandbox.js +91 -0
- package/dist/tier2-sandbox.js.map +1 -0
- package/dist/types.d.ts +99 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
//
|
|
3
|
+
// Deterministic surface-driven task runner (ADR-102) — Tier 1 of the
|
|
4
|
+
// Agent-Executing Sandbox (ADR-101). The real sandbox scores a variant by the
|
|
5
|
+
// REPO's test command, which is independent of the harness surfaces, so every
|
|
6
|
+
// trace is identical and the behavioural manifold collapses (measured:
|
|
7
|
+
// nicheEntropy=0, ADR-099). This runner makes the trace a PURE FUNCTION of the
|
|
8
|
+
// variant's surface parameters, so a mutation to retryPolicy / contextBuilder /
|
|
9
|
+
// toolPolicy actually changes the outcome — activating ADR-091/092/094/097/100.
|
|
10
|
+
//
|
|
11
|
+
// It does NOT call an LLM, compile, or shell out: it extracts the surface
|
|
12
|
+
// parameters with the SAME regexes the DeterministicMutator writes, then
|
|
13
|
+
// simulates a scripted agent loop. Fully deterministic ⇒ reproducible (ADR-075):
|
|
14
|
+
// `durationMs` is derived from surface params, not wall-clock.
|
|
15
|
+
import { readFile } from 'node:fs/promises';
|
|
16
|
+
import { join } from 'node:path';
|
|
17
|
+
import { FILE_BY_SURFACE } from './safety.js';
|
|
18
|
+
/**
|
|
19
|
+
* A graduated scripted ladder (drives the curriculum, ADR-097). Each rung needs
|
|
20
|
+
* slightly more retry budget and/or context than the last, so an incremental
|
|
21
|
+
* surface improvement solves incrementally MORE rungs — a climbable gradient
|
|
22
|
+
* (not a deceptive all-or-nothing plateau). The lower rungs reward retry-budget
|
|
23
|
+
* growth alone; the upper rungs additionally require a wider context window, so
|
|
24
|
+
* the full ladder rewards combining both surfaces (crossover/epistasis).
|
|
25
|
+
*/
|
|
26
|
+
export const DEFAULT_MOCK_TASKS = [
|
|
27
|
+
{ id: 'mock-1', failAttempts: 0, requiredContext: 10, backoffMs: 20, difficulty: 1 },
|
|
28
|
+
{ id: 'mock-2', failAttempts: 1, requiredContext: 20, backoffMs: 20, difficulty: 2 },
|
|
29
|
+
{ id: 'mock-3', failAttempts: 1, requiredContext: 30, backoffMs: 30, difficulty: 3 },
|
|
30
|
+
{ id: 'mock-4', failAttempts: 2, requiredContext: 50, backoffMs: 40, difficulty: 4 },
|
|
31
|
+
{ id: 'mock-5', failAttempts: 2, requiredContext: 70, backoffMs: 50, difficulty: 5 },
|
|
32
|
+
];
|
|
33
|
+
function intAfter(re, text, fallback) {
|
|
34
|
+
const m = re.exec(text);
|
|
35
|
+
return m ? Number(m[1]) : fallback;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Extract surface parameters from a variant directory (text-parsing, not import).
|
|
39
|
+
* Uses the same patterns the DeterministicMutator perturbs, so a mutation that
|
|
40
|
+
* bumps a budget or a slice width is reflected here. Missing files → defaults.
|
|
41
|
+
*/
|
|
42
|
+
export async function extractSurfaceParams(variantDir) {
|
|
43
|
+
const read = async (surface) => {
|
|
44
|
+
try {
|
|
45
|
+
return await readFile(join(variantDir, FILE_BY_SURFACE[surface]), 'utf8');
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return '';
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const retry = await read('retryPolicy');
|
|
52
|
+
const context = await read('contextBuilder');
|
|
53
|
+
const memory = await read('memoryPolicy');
|
|
54
|
+
const planner = await read('planner');
|
|
55
|
+
const maxAttempts = intAfter(/\b(?:maxAttempts|maxRetries|retries|retryBudget|budget)\b\s*[:=]\s*(\d+)/, retry, 3);
|
|
56
|
+
const contextWindow = intAfter(/\.slice\(\s*0\s*,\s*(\d+)\s*\)/, context, 30);
|
|
57
|
+
const memMatch = /\b(?:threshold|minScore|cutoff)\b\s*[:=]\s*(0?\.\d+|1(?:\.0+)?|0)\b/.exec(memory);
|
|
58
|
+
const memoryThreshold = memMatch ? Number(memMatch[1]) : 0.5;
|
|
59
|
+
// Plan steps ≈ count of directive sentences in the planner guidance.
|
|
60
|
+
const planSteps = Math.max(1, (planner.match(/\b(?:step|plan|decompose|verify|consider|first|then|focus)\b/gi) ?? []).length);
|
|
61
|
+
return { maxAttempts, contextWindow, memoryThreshold, planSteps };
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Simulate a scripted agent loop. Outcome is a deterministic function of the
|
|
65
|
+
* surface params and the task: the agent must (a) see enough context and
|
|
66
|
+
* (b) retry past the task's failing attempts. The log records plan steps,
|
|
67
|
+
* context builds, and retry decisions — so verbosity/repetition/duration all
|
|
68
|
+
* vary by surface, populating the behavioural phenotype (ADR-091).
|
|
69
|
+
*/
|
|
70
|
+
export function simulateAgentLoop(params, task) {
|
|
71
|
+
const sees = params.contextWindow >= task.requiredContext;
|
|
72
|
+
const lines = [];
|
|
73
|
+
for (let s = 0; s < params.planSteps; s++)
|
|
74
|
+
lines.push(`plan: step ${s}`);
|
|
75
|
+
let attemptsUsed = 0;
|
|
76
|
+
let solved = false;
|
|
77
|
+
for (let attempt = 0; attempt < params.maxAttempts; attempt++) {
|
|
78
|
+
attemptsUsed = attempt + 1;
|
|
79
|
+
lines.push(`ctx: built window ${params.contextWindow}`);
|
|
80
|
+
// Solvable once we are past the failing attempts AND we can see the bug.
|
|
81
|
+
if (sees && attempt >= task.failAttempts) {
|
|
82
|
+
lines.push('verify: PASS');
|
|
83
|
+
solved = true;
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
lines.push(`retry: attempt ${attempt} failed (${sees ? 'unfixed' : 'blind'})`);
|
|
87
|
+
}
|
|
88
|
+
const durationMs = attemptsUsed * task.backoffMs + params.contextWindow;
|
|
89
|
+
return { solved, attemptsUsed, durationMs, log: lines.join('\n') };
|
|
90
|
+
}
|
|
91
|
+
/** Run ONE mock task against a variant, producing a surface-dependent RunTrace. */
|
|
92
|
+
export async function runVariantTaskMock(variant, task, params) {
|
|
93
|
+
const p = params ?? (await extractSurfaceParams(variant.dir));
|
|
94
|
+
const sim = simulateAgentLoop(p, task);
|
|
95
|
+
// Deterministic timestamps derived from duration (no wall-clock → reproducible).
|
|
96
|
+
const startedAt = '1970-01-01T00:00:00.000Z';
|
|
97
|
+
const finishedAt = new Date(sim.durationMs).toISOString();
|
|
98
|
+
return {
|
|
99
|
+
variantId: variant.id,
|
|
100
|
+
taskId: task.id,
|
|
101
|
+
startedAt,
|
|
102
|
+
finishedAt,
|
|
103
|
+
exitCode: sim.solved ? 0 : 1,
|
|
104
|
+
stdout: sim.log,
|
|
105
|
+
stderr: sim.solved ? '' : `task ${task.id} unsolved after ${sim.attemptsUsed} attempts`,
|
|
106
|
+
durationMs: sim.durationMs,
|
|
107
|
+
timedOut: false,
|
|
108
|
+
blockedActions: [],
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
/** Run a variant against a graded mock suite (defaults to DEFAULT_MOCK_TASKS). */
|
|
112
|
+
export async function runVariantTasksMock(variant, tasks = DEFAULT_MOCK_TASKS) {
|
|
113
|
+
const params = await extractSurfaceParams(variant.dir);
|
|
114
|
+
const traces = [];
|
|
115
|
+
for (const task of tasks)
|
|
116
|
+
traces.push(await runVariantTaskMock(variant, task, params));
|
|
117
|
+
return traces;
|
|
118
|
+
}
|
|
119
|
+
//# source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I,CAAC,MAAM,kBAAkB,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;IACvF,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/mutator.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { HarnessVariant, MutationSurface } from './types.js';
|
|
1
|
+
import type { HarnessVariant, MutationSurface, RunTrace } from './types.js';
|
|
2
2
|
/**
|
|
3
3
|
* A pluggable code generator. Given the parent's surface file and context, it
|
|
4
4
|
* returns replacement code for that one file plus a one-line summary. The
|
|
@@ -12,6 +12,13 @@ export interface CodeGenerator {
|
|
|
12
12
|
repoSummary: string;
|
|
13
13
|
parentScore: number;
|
|
14
14
|
failedTraces: string[];
|
|
15
|
+
/**
|
|
16
|
+
* Sibling-diversity nonce (ADR-104): the child's index within its
|
|
17
|
+
* generation. Siblings mutating the same surface use it to explore
|
|
18
|
+
* DIFFERENT edit directions (e.g. retry budget up vs. down) instead of an
|
|
19
|
+
* identical edit. Deterministic, defaults to 0 — so reproducibility holds.
|
|
20
|
+
*/
|
|
21
|
+
nonce?: number;
|
|
15
22
|
}): Promise<{
|
|
16
23
|
code: string;
|
|
17
24
|
summary: string;
|
|
@@ -32,16 +39,51 @@ export declare class DeterministicMutator implements CodeGenerator {
|
|
|
32
39
|
repoSummary: string;
|
|
33
40
|
parentScore: number;
|
|
34
41
|
failedTraces: string[];
|
|
42
|
+
nonce?: number;
|
|
35
43
|
}): Promise<{
|
|
36
44
|
code: string;
|
|
37
45
|
summary: string;
|
|
38
46
|
}>;
|
|
39
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Reflection context (ADR-071 §contract) carried from a parent's evaluation into
|
|
50
|
+
* its child's mutation. The DeterministicMutator ignores it (stays reproducible);
|
|
51
|
+
* an LLM-backed CodeGenerator uses it to target the parent's actual failures —
|
|
52
|
+
* closing the self-improvement loop instead of mutating blind.
|
|
53
|
+
*/
|
|
54
|
+
export interface MutationContext {
|
|
55
|
+
/** Short human-readable repo summary (RepoProfile.summary). */
|
|
56
|
+
repoSummary?: string;
|
|
57
|
+
/** The parent variant's finalScore (0 if unknown). */
|
|
58
|
+
parentScore?: number;
|
|
59
|
+
/** Compact, one-line-per-failure summaries of the parent's failing traces. */
|
|
60
|
+
failedTraces?: string[];
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Distil a parent's run traces into compact failure summaries for the mutator.
|
|
64
|
+
* A trace "failed" if it exited non-zero, timed out, or tripped a safety block.
|
|
65
|
+
* Pure and deterministic — order-preserving, no wall-clock, no I/O.
|
|
66
|
+
*/
|
|
67
|
+
export declare function summarizeFailedTraces(traces: RunTrace[]): string[];
|
|
40
68
|
/**
|
|
41
69
|
* Deterministically pick one of the seven surfaces from `(generation+index+seed)`.
|
|
42
70
|
* Same inputs ⇒ same surface (reproducibility, ADR-070 §seed).
|
|
43
71
|
*/
|
|
44
72
|
export declare function pickSurface(generation: number, index: number, seed: number): MutationSurface;
|
|
73
|
+
/**
|
|
74
|
+
* Recombine two parents into a child (genetic crossover, ADR-089). The child is
|
|
75
|
+
* parentA's directory with a deterministic, non-empty PROPER subset of surface
|
|
76
|
+
* files replaced by parentB's versions — so it inherits some surfaces from each.
|
|
77
|
+
*
|
|
78
|
+
* Recombination only — no code is generated — so every adopted file already
|
|
79
|
+
* passed the gate when its parent was built; we re-run `validateGeneratedCode`
|
|
80
|
+
* defensively and skip any file that would fail (the child keeps parentA's), so
|
|
81
|
+
* the child always still passes `inspectVariant`.
|
|
82
|
+
*
|
|
83
|
+
* The archive is a strict tree (one `parentId`): we record `parentA` as the tree
|
|
84
|
+
* parent and name `parentB` in the summary, so every tree invariant holds.
|
|
85
|
+
*/
|
|
86
|
+
export declare function createCrossoverVariant(parentA: HarnessVariant, parentB: HarnessVariant, workRoot: string, generation: number, index: number, seed?: number, surfacesFromB?: readonly MutationSurface[]): Promise<HarnessVariant>;
|
|
45
87
|
/**
|
|
46
88
|
* Recursively copy a variant directory using `node:fs/promises` only (never a
|
|
47
89
|
* shell). The destination is created fresh; only the parent's files are copied,
|
|
@@ -57,5 +99,5 @@ export declare function copyVariantDir(src: string, dest: string): Promise<void>
|
|
|
57
99
|
* and the parent's surface file is left untouched (a safe no-op). The child
|
|
58
100
|
* directory therefore always still passes `inspectVariant`.
|
|
59
101
|
*/
|
|
60
|
-
export declare function createChildVariant(parent: HarnessVariant, workRoot: string, generation: number, index: number, gen?: CodeGenerator, seed?: number): Promise<HarnessVariant>;
|
|
102
|
+
export declare function createChildVariant(parent: HarnessVariant, workRoot: string, generation: number, index: number, gen?: CodeGenerator, seed?: number, context?: MutationContext): Promise<HarnessVariant>;
|
|
61
103
|
//# sourceMappingURL=mutator.d.ts.map
|
package/dist/mutator.d.ts.map
CHANGED
|
@@ -1 +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;
|
|
1
|
+
{"version":3,"file":"mutator.d.ts","sourceRoot":"","sources":["../src/mutator.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE5E;;;;;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;QACvB;;;;;WAKG;QACH,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAChD;AA6FD;;;;;GAKG;AACH,qBAAa,oBAAqB,YAA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sB,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,EACR,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,cAAc,CAAC,CA+CzB"}
|
package/dist/mutator.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
// performs seeded string-replacement edits (the prototype path), and can be
|
|
15
15
|
// swapped for an LLM-backed generator behind the SAME gate.
|
|
16
16
|
import { cp, mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
17
|
-
import { join } from 'node:path';
|
|
17
|
+
import { join, resolve } from 'node:path';
|
|
18
18
|
import { FILE_BY_SURFACE, SURFACES, validateGeneratedCode } from './safety.js';
|
|
19
19
|
/** A pure, deterministic 32-bit hash — seeds choice without `Math.random`. */
|
|
20
20
|
function hash(...parts) {
|
|
@@ -103,7 +103,11 @@ export class DeterministicMutator {
|
|
|
103
103
|
}
|
|
104
104
|
async generateMutation(input) {
|
|
105
105
|
const { parentCode, surface } = input;
|
|
106
|
-
|
|
106
|
+
// The sibling nonce (child index) makes same-surface siblings explore
|
|
107
|
+
// DIFFERENT edits (e.g. retry budget +1 vs −1), so a generation covers both
|
|
108
|
+
// directions instead of one — fixing the "budget never grows upward" bug
|
|
109
|
+
// found in ADR-103. Deterministic ⇒ reproducible.
|
|
110
|
+
const variant = hash(this.seed, surface, parentCode.length, input.nonce ?? 0) % 6;
|
|
107
111
|
const start = hash(this.seed, surface) % EDIT_RULES.length;
|
|
108
112
|
for (let i = 0; i < EDIT_RULES.length; i++) {
|
|
109
113
|
const rule = EDIT_RULES[(start + i) % EDIT_RULES.length];
|
|
@@ -122,6 +126,27 @@ export class DeterministicMutator {
|
|
|
122
126
|
};
|
|
123
127
|
}
|
|
124
128
|
}
|
|
129
|
+
/**
|
|
130
|
+
* Distil a parent's run traces into compact failure summaries for the mutator.
|
|
131
|
+
* A trace "failed" if it exited non-zero, timed out, or tripped a safety block.
|
|
132
|
+
* Pure and deterministic — order-preserving, no wall-clock, no I/O.
|
|
133
|
+
*/
|
|
134
|
+
export function summarizeFailedTraces(traces) {
|
|
135
|
+
const out = [];
|
|
136
|
+
for (const t of traces) {
|
|
137
|
+
const failed = t.exitCode !== 0 || t.timedOut || t.blockedActions.length > 0;
|
|
138
|
+
if (!failed)
|
|
139
|
+
continue;
|
|
140
|
+
const why = t.blockedActions.length > 0
|
|
141
|
+
? `blocked: ${t.blockedActions.join(', ')}`
|
|
142
|
+
: t.timedOut
|
|
143
|
+
? 'timed out'
|
|
144
|
+
: `exit ${t.exitCode}`;
|
|
145
|
+
const tail = (t.stderr || t.stdout || '').trim().split('\n').pop()?.slice(0, 160) ?? '';
|
|
146
|
+
out.push(`task ${t.taskId}: ${why}${tail ? ` — ${tail}` : ''}`);
|
|
147
|
+
}
|
|
148
|
+
return out;
|
|
149
|
+
}
|
|
125
150
|
/**
|
|
126
151
|
* Deterministically pick one of the seven surfaces from `(generation+index+seed)`.
|
|
127
152
|
* Same inputs ⇒ same surface (reproducibility, ADR-070 §seed).
|
|
@@ -130,12 +155,77 @@ export function pickSurface(generation, index, seed) {
|
|
|
130
155
|
const i = hash(generation, index, seed) % SURFACES.length;
|
|
131
156
|
return SURFACES[i];
|
|
132
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* Recombine two parents into a child (genetic crossover, ADR-089). The child is
|
|
160
|
+
* parentA's directory with a deterministic, non-empty PROPER subset of surface
|
|
161
|
+
* files replaced by parentB's versions — so it inherits some surfaces from each.
|
|
162
|
+
*
|
|
163
|
+
* Recombination only — no code is generated — so every adopted file already
|
|
164
|
+
* passed the gate when its parent was built; we re-run `validateGeneratedCode`
|
|
165
|
+
* defensively and skip any file that would fail (the child keeps parentA's), so
|
|
166
|
+
* the child always still passes `inspectVariant`.
|
|
167
|
+
*
|
|
168
|
+
* The archive is a strict tree (one `parentId`): we record `parentA` as the tree
|
|
169
|
+
* parent and name `parentB` in the summary, so every tree invariant holds.
|
|
170
|
+
*/
|
|
171
|
+
export async function createCrossoverVariant(parentA, parentB, workRoot, generation, index, seed = 0, surfacesFromB) {
|
|
172
|
+
const id = `g${generation}_x${index}`;
|
|
173
|
+
const dir = join(workRoot, 'variants', id);
|
|
174
|
+
await copyVariantDir(parentA.dir, dir);
|
|
175
|
+
// Which surfaces come from B: an explicit epistatic block (ADR-093 topology-
|
|
176
|
+
// aware crossover) when supplied, else a deterministic random bit-subset.
|
|
177
|
+
let fromB;
|
|
178
|
+
if (surfacesFromB && surfacesFromB.length > 0) {
|
|
179
|
+
fromB = [...new Set(surfacesFromB)].filter((s) => SURFACES.includes(s));
|
|
180
|
+
if (fromB.length >= SURFACES.length)
|
|
181
|
+
fromB = fromB.slice(0, SURFACES.length - 1);
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
const bits = hash(seed, generation, index, parentA.id, parentB.id, 'crossover');
|
|
185
|
+
fromB = SURFACES.filter((_, i) => ((bits >> i) & 1) === 1);
|
|
186
|
+
// Force a PROPER, non-empty recombination: never all-A and never all-B.
|
|
187
|
+
if (fromB.length === 0)
|
|
188
|
+
fromB = [SURFACES[bits % SURFACES.length]];
|
|
189
|
+
if (fromB.length === SURFACES.length)
|
|
190
|
+
fromB = fromB.slice(0, SURFACES.length - 1);
|
|
191
|
+
}
|
|
192
|
+
const adopted = [];
|
|
193
|
+
for (const surface of fromB) {
|
|
194
|
+
const fileName = FILE_BY_SURFACE[surface];
|
|
195
|
+
let codeB;
|
|
196
|
+
try {
|
|
197
|
+
codeB = await readFile(join(parentB.dir, fileName), 'utf8');
|
|
198
|
+
}
|
|
199
|
+
catch {
|
|
200
|
+
continue; // parentB lacks the file — keep parentA's
|
|
201
|
+
}
|
|
202
|
+
if (validateGeneratedCode(codeB).length > 0)
|
|
203
|
+
continue; // defensive: skip unsafe
|
|
204
|
+
await writeFile(join(dir, fileName), codeB, 'utf8');
|
|
205
|
+
adopted.push(surface);
|
|
206
|
+
}
|
|
207
|
+
return {
|
|
208
|
+
id,
|
|
209
|
+
parentId: parentA.id,
|
|
210
|
+
generation,
|
|
211
|
+
dir,
|
|
212
|
+
mutationSurface: adopted[0] ?? parentA.mutationSurface,
|
|
213
|
+
mutationSummary: adopted.length > 0
|
|
214
|
+
? `crossover: surfaces [${adopted.join(', ')}] from ${parentB.id} onto ${parentA.id}`
|
|
215
|
+
: `crossover: no safe surface adopted from ${parentB.id} (identical to ${parentA.id})`,
|
|
216
|
+
createdAt: new Date().toISOString(),
|
|
217
|
+
};
|
|
218
|
+
}
|
|
133
219
|
/**
|
|
134
220
|
* Recursively copy a variant directory using `node:fs/promises` only (never a
|
|
135
221
|
* shell). The destination is created fresh; only the parent's files are copied,
|
|
136
222
|
* so no extraneous entry can leak in.
|
|
137
223
|
*/
|
|
138
224
|
export async function copyVariantDir(src, dest) {
|
|
225
|
+
// Defensive: a child whose id collides with its parent's would make src===dest
|
|
226
|
+
// (cp throws EINVAL). Never copy a directory onto itself.
|
|
227
|
+
if (resolve(src) === resolve(dest))
|
|
228
|
+
return;
|
|
139
229
|
await mkdir(dest, { recursive: true });
|
|
140
230
|
await cp(src, dest, { recursive: true, dereference: true, force: true });
|
|
141
231
|
}
|
|
@@ -148,7 +238,7 @@ export async function copyVariantDir(src, dest) {
|
|
|
148
238
|
* and the parent's surface file is left untouched (a safe no-op). The child
|
|
149
239
|
* directory therefore always still passes `inspectVariant`.
|
|
150
240
|
*/
|
|
151
|
-
export async function createChildVariant(parent, workRoot, generation, index, gen = new DeterministicMutator(), seed = 0) {
|
|
241
|
+
export async function createChildVariant(parent, workRoot, generation, index, gen = new DeterministicMutator(), seed = 0, context = {}) {
|
|
152
242
|
const id = `g${generation}_v${index}`;
|
|
153
243
|
const dir = join(workRoot, 'variants', id);
|
|
154
244
|
// 1) Copy the parent directory verbatim (no shell, no extra files).
|
|
@@ -158,13 +248,16 @@ export async function createChildVariant(parent, workRoot, generation, index, ge
|
|
|
158
248
|
const fileName = FILE_BY_SURFACE[surface];
|
|
159
249
|
const filePath = join(dir, fileName);
|
|
160
250
|
const parentCode = await readFile(filePath, 'utf8');
|
|
161
|
-
// 3) Generate a candidate mutation for that one file.
|
|
251
|
+
// 3) Generate a candidate mutation for that one file. The reflection context
|
|
252
|
+
// (parent score + failures) lets an LLM generator target real weaknesses;
|
|
253
|
+
// the DeterministicMutator ignores it and stays byte-reproducible.
|
|
162
254
|
const { code, summary } = await gen.generateMutation({
|
|
163
255
|
parentCode,
|
|
164
256
|
surface,
|
|
165
|
-
repoSummary: '',
|
|
166
|
-
parentScore: 0,
|
|
167
|
-
failedTraces: [],
|
|
257
|
+
repoSummary: context.repoSummary ?? '',
|
|
258
|
+
parentScore: context.parentScore ?? 0,
|
|
259
|
+
failedTraces: context.failedTraces ?? [],
|
|
260
|
+
nonce: index, // sibling-diversity nonce (ADR-104)
|
|
168
261
|
});
|
|
169
262
|
// 4) Gate: validate BEFORE writing. Violations are discarded, never written.
|
|
170
263
|
const violations = validateGeneratedCode(code);
|
package/dist/mutator.js.map
CHANGED
|
@@ -1 +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;
|
|
1
|
+
{"version":3,"file":"mutator.js","sourceRoot":"","sources":["../src/mutator.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,EAAE;AACF,4EAA4E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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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openrouter-mutator.d.ts","sourceRoot":"","sources":["../src/openrouter-mutator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"openrouter-mutator.d.ts","sourceRoot":"","sources":["../src/openrouter-mutator.ts"],"names":[],"mappings":"AAeA,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"}
|
|
@@ -7,7 +7,10 @@
|
|
|
7
7
|
// safety gate in createChildVariant). Real OpenRouter calls; no fabrication.
|
|
8
8
|
//
|
|
9
9
|
// Key: OPENROUTER_API_KEY env, or falls back to /tmp/.orkey. Model: env
|
|
10
|
-
// DARWIN_MUTATOR_MODEL (default
|
|
10
|
+
// DARWIN_MUTATOR_MODEL (default google/gemini-2.5-flash — the measured best
|
|
11
|
+
// quality-per-dollar code model on TypeScript, the mutator's output language;
|
|
12
|
+
// see ADR-085 polyglot benchmark. NOTE: do NOT default to haiku-4.5 if the
|
|
13
|
+
// harness ever emits a compiled language — it fails to compile Rust/C++/C there).
|
|
11
14
|
import { readFileSync } from 'node:fs';
|
|
12
15
|
function apiKey() {
|
|
13
16
|
const env = (process.env.OPENROUTER_API_KEY || '').trim();
|
|
@@ -31,7 +34,7 @@ export class OpenRouterMutator {
|
|
|
31
34
|
temperature;
|
|
32
35
|
telemetry = { calls: 0, promptTokens: 0, completionTokens: 0, costUSD: 0 };
|
|
33
36
|
constructor(opts = {}) {
|
|
34
|
-
this.model = opts.model ?? process.env.DARWIN_MUTATOR_MODEL ?? '
|
|
37
|
+
this.model = opts.model ?? process.env.DARWIN_MUTATOR_MODEL ?? 'google/gemini-2.5-flash';
|
|
35
38
|
this.maxTokens = opts.maxTokens ?? 2000;
|
|
36
39
|
this.temperature = opts.temperature ?? 0.4;
|
|
37
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openrouter-mutator.js","sourceRoot":"","sources":["../src/openrouter-mutator.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,EAAE;AACF,6EAA6E;AAC7E,qFAAqF;AACrF,gFAAgF;AAChF,8EAA8E;AAC9E,6EAA6E;AAC7E,EAAE;AACF,wEAAwE;AACxE,
|
|
1
|
+
{"version":3,"file":"openrouter-mutator.js","sourceRoot":"","sources":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` returns a
|
|
3
|
+
* vector per item with HIGHER = better on each axis. Order-preserving (front
|
|
4
|
+
* items keep their input order → deterministic when the input is deterministic).
|
|
5
|
+
*/
|
|
6
|
+
export declare function paretoFront<T>(items: readonly T[], objectives: (t: T) => number[]): T[];
|
|
7
|
+
//# sourceMappingURL=pareto.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pareto.d.ts","sourceRoot":"","sources":["../src/pareto.ts"],"names":[],"mappings":"AAsBA;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,MAAM,EAAE,GAAG,CAAC,EAAE,CAevF"}
|
package/dist/pareto.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
//
|
|
3
|
+
// Multi-objective Pareto selection (ADR-100). The scorer is a scalar GATE that
|
|
4
|
+
// ceilings at 0.985 (ADR-072) — it cannot rank the safe, passing variants. A
|
|
5
|
+
// single scalar also forces a false choice between competing goods (capability
|
|
6
|
+
// vs. parsimony). Pareto dominance keeps the whole NON-DOMINATED front, so
|
|
7
|
+
// "mini" (small, cheap) and "grand" (capable) variants coexist instead of
|
|
8
|
+
// collapsing to one winner.
|
|
9
|
+
//
|
|
10
|
+
// Generic and pure. The caller maps each item to an objective vector where
|
|
11
|
+
// HIGHER is better on every axis (negate any cost objective). Deterministic.
|
|
12
|
+
/** Does `a` Pareto-dominate `b`? (≥ on every objective, > on at least one.) */
|
|
13
|
+
function dominates(a, b) {
|
|
14
|
+
let strictlyBetter = false;
|
|
15
|
+
for (let k = 0; k < a.length; k++) {
|
|
16
|
+
if (a[k] < b[k])
|
|
17
|
+
return false;
|
|
18
|
+
if (a[k] > b[k])
|
|
19
|
+
strictlyBetter = true;
|
|
20
|
+
}
|
|
21
|
+
return strictlyBetter;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The Pareto front: the items not dominated by any other. `objectives` returns a
|
|
25
|
+
* vector per item with HIGHER = better on each axis. Order-preserving (front
|
|
26
|
+
* items keep their input order → deterministic when the input is deterministic).
|
|
27
|
+
*/
|
|
28
|
+
export function paretoFront(items, objectives) {
|
|
29
|
+
const objs = items.map(objectives);
|
|
30
|
+
const front = [];
|
|
31
|
+
for (let i = 0; i < items.length; i++) {
|
|
32
|
+
let dominated = false;
|
|
33
|
+
for (let j = 0; j < items.length; j++) {
|
|
34
|
+
if (i === j)
|
|
35
|
+
continue;
|
|
36
|
+
if (dominates(objs[j], objs[i])) {
|
|
37
|
+
dominated = true;
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (!dominated)
|
|
42
|
+
front.push(items[i]);
|
|
43
|
+
}
|
|
44
|
+
return front;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=pareto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pareto.js","sourceRoot":"","sources":["../src/pareto.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,EAAE;AACF,+EAA+E;AAC/E,6EAA6E;AAC7E,+EAA+E;AAC/E,2EAA2E;AAC3E,0EAA0E;AAC1E,4BAA4B;AAC5B,EAAE;AACF,2EAA2E;AAC3E,6EAA6E;AAE7E,+EAA+E;AAC/E,SAAS,SAAS,CAAC,CAAoB,EAAE,CAAoB;IAC3D,IAAI,cAAc,GAAG,KAAK,CAAC;IAC3B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAClC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YAAE,OAAO,KAAK,CAAC;QAC9B,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YAAE,cAAc,GAAG,IAAI,CAAC;IACzC,CAAC;IACD,OAAO,cAAc,CAAC;AACxB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAI,KAAmB,EAAE,UAA8B;IAChF,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACnC,MAAM,KAAK,GAAQ,EAAE,CAAC;IACtB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,IAAI,SAAS,GAAG,KAAK,CAAC;QACtB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACtC,IAAI,CAAC,KAAK,CAAC;gBAAE,SAAS;YACtB,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;gBAChC,SAAS,GAAG,IAAI,CAAC;gBACjB,MAAM;YACR,CAAC;QACH,CAAC;QACD,IAAI,CAAC,SAAS;YAAE,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACvC,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { RunTrace } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* A small, bounded behaviour feature vector for one variant's traces. Each field
|
|
4
|
+
* is in [0, 1]. Pure and deterministic (no wall-clock beyond the recorded
|
|
5
|
+
* durations, which only affect `durationSpread`, a relative quantity).
|
|
6
|
+
*/
|
|
7
|
+
export interface BehaviorFeatures {
|
|
8
|
+
/** Fraction of traces that failed (non-zero exit, timeout, or safety block). */
|
|
9
|
+
failRate: number;
|
|
10
|
+
/** Fraction that hit the wall-clock timeout (a deep-loop signature). */
|
|
11
|
+
timeoutRate: number;
|
|
12
|
+
/** Fraction that tripped a safety block. */
|
|
13
|
+
blockRate: number;
|
|
14
|
+
/** Output verbosity, saturated (mean stdout+stderr chars). */
|
|
15
|
+
verbosity: number;
|
|
16
|
+
/** Repeated-line fraction across traces — loop / backtracking proxy. */
|
|
17
|
+
repetition: number;
|
|
18
|
+
/** Relative duration spread (stddev/mean) — irregular vs. uniform effort. */
|
|
19
|
+
durationSpread: number;
|
|
20
|
+
}
|
|
21
|
+
export declare function behaviorFeatures(traces: RunTrace[]): BehaviorFeatures;
|
|
22
|
+
/**
|
|
23
|
+
* Embed behaviour features into the 2-D Poincaré ball (the open unit disk).
|
|
24
|
+
* RADIUS encodes hierarchical "depth/struggle" (failure, looping, timeouts) —
|
|
25
|
+
* deep recursive strugglers sit near the boundary where hyperbolic distance
|
|
26
|
+
* explodes; clean shallow agents sit near the origin. ANGLE encodes behavioural
|
|
27
|
+
* MODE (verbosity vs. safety-pressure vs. effort irregularity). The point always
|
|
28
|
+
* satisfies ‖p‖ < 1.
|
|
29
|
+
*/
|
|
30
|
+
export declare function poincareEmbed(f: BehaviorFeatures): [number, number];
|
|
31
|
+
/**
|
|
32
|
+
* Poincaré-ball distance between two points in the open unit ball:
|
|
33
|
+
*
|
|
34
|
+
* d(u,v) = acosh( 1 + 2 · ‖u−v‖² / ((1−‖u‖²)(1−‖v‖²)) )
|
|
35
|
+
*
|
|
36
|
+
* Returns 0 for identical points, is symmetric, and grows without bound as
|
|
37
|
+
* either point approaches the boundary. Guards the denominator for points placed
|
|
38
|
+
* exactly on the boundary (treated as just inside).
|
|
39
|
+
*/
|
|
40
|
+
export declare function poincareDistance(u: readonly number[], v: readonly number[]): number;
|
|
41
|
+
/**
|
|
42
|
+
* Assign a discrete behavioural niche by hyperbolic region: a radial shell
|
|
43
|
+
* (hierarchy depth) crossed with an angular sector (behavioural mode). Same
|
|
44
|
+
* behaviour ⇒ same niche; deterministic. Plugs into `selectElites` as the
|
|
45
|
+
* descriptor: `selectElites(k, v => behavioralNiche(tracesById.get(v.id) ?? []))`.
|
|
46
|
+
*/
|
|
47
|
+
/** Poincaré polar niche of a disk point: radial shell (depth) × angular sector. */
|
|
48
|
+
export declare function poincareNicheOf(x: number, y: number, shells?: number, sectors?: number): string;
|
|
49
|
+
/** Flat Cartesian niche of a disk point: a uniform `bins × bins` square grid. */
|
|
50
|
+
export declare function euclideanNicheOf(x: number, y: number, bins?: number): string;
|
|
51
|
+
export declare function behavioralNiche(traces: RunTrace[], shells?: number, sectors?: number): string;
|
|
52
|
+
/**
|
|
53
|
+
* FLAT Euclidean niche over the SAME embedded behaviour point — a square
|
|
54
|
+
* `bins × bins` grid on the disk. This is the ablation comparator for ADR-095:
|
|
55
|
+
* it bins the identical `poincareEmbed` coordinate with a uniform Cartesian grid
|
|
56
|
+
* instead of the polar/hyperbolic radial-shell grid, so a controlled run can
|
|
57
|
+
* measure what the hyperbolic geometry actually buys. Deterministic.
|
|
58
|
+
*/
|
|
59
|
+
export declare function euclideanNiche(traces: RunTrace[], bins?: number): string;
|
|
60
|
+
/** Geometric centroid of niche cell `(shell, sector)` in the Poincaré disk. */
|
|
61
|
+
export declare function nicheCentroid(shell: number, sector: number, shells?: number, sectors?: number): [number, number];
|
|
62
|
+
/**
|
|
63
|
+
* Find an under-explored target niche: scan shells from the OUTSIDE in (prefer
|
|
64
|
+
* the high-radius complexity frontier, per open-endedness) and return the first
|
|
65
|
+
* unoccupied cell's id + centroid. Returns `null` when every niche is occupied.
|
|
66
|
+
*/
|
|
67
|
+
export declare function underExploredTarget(occupied: ReadonlySet<string>, shells?: number, sectors?: number): {
|
|
68
|
+
niche: string;
|
|
69
|
+
centroid: [number, number];
|
|
70
|
+
} | null;
|
|
71
|
+
/**
|
|
72
|
+
* Rank candidates by Poincaré distance to `target` (ascending) and return the
|
|
73
|
+
* nearest `limit` ids — the survivors whose offspring are most likely to reach
|
|
74
|
+
* the under-explored region. Ties break by the candidate array order (the caller
|
|
75
|
+
* supplies a deterministic order, e.g. archive insertion).
|
|
76
|
+
*/
|
|
77
|
+
export declare function nearestToTarget(candidates: ReadonlyArray<{
|
|
78
|
+
id: string;
|
|
79
|
+
embed: readonly [number, number];
|
|
80
|
+
}>, target: readonly [number, number], limit: number): string[];
|
|
81
|
+
/** Convenience: the Poincaré embedding of a variant straight from its traces. */
|
|
82
|
+
export declare function embedTraces(traces: RunTrace[]): [number, number];
|
|
83
|
+
//# sourceMappingURL=phenotype.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"phenotype.d.ts","sourceRoot":"","sources":["../src/phenotype.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAoB3C;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B,gFAAgF;IAChF,QAAQ,EAAE,MAAM,CAAC;IACjB,wEAAwE;IACxE,WAAW,EAAE,MAAM,CAAC;IACpB,4CAA4C;IAC5C,SAAS,EAAE,MAAM,CAAC;IAClB,8DAA8D;IAC9D,SAAS,EAAE,MAAM,CAAC;IAClB,wEAAwE;IACxE,UAAU,EAAE,MAAM,CAAC;IACnB,6EAA6E;IAC7E,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,QAAQ,EAAE,GAAG,gBAAgB,CA4BrE;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,gBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAOnE;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,SAAS,MAAM,EAAE,EAAE,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CASnF;AAED;;;;;GAKG;AACH,mFAAmF;AACnF,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,SAAI,EAAE,OAAO,SAAI,GAAG,MAAM,CAOrF;AAED,iFAAiF;AACjF,wBAAgB,gBAAgB,CA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