@hmharness/evolution 0.23.49 → 0.23.51
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/bench.d.ts +10 -0
- package/dist/bench.js +34 -2
- package/dist/case-runner.d.ts +47 -0
- package/dist/case-runner.js +43 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/insights.d.ts +9 -1
- package/dist/three-arm.js +5 -1
- package/package.json +3 -3
package/dist/bench.d.ts
CHANGED
|
@@ -24,6 +24,16 @@ export interface BenchResult {
|
|
|
24
24
|
detail: string;
|
|
25
25
|
}
|
|
26
26
|
export declare function matchExpect(output: string, expect: string[]): boolean;
|
|
27
|
+
/** Strip JS regex-literal delimiters: `/^\d+$/i` -> `^\d+$`.
|
|
28
|
+
* .task data files write expect-regex with slashes (bench/cases/*.task,
|
|
29
|
+
* HarmonyBench exports); callers hand the value to `new RegExp(...)`, which
|
|
30
|
+
* treats the slashes as literal characters — so `/^\d+$/` matched the
|
|
31
|
+
* literal text "^\d+$" and never a digit. 13 of 35 gate cases were
|
|
32
|
+
* unpassable for this reason (2026-11-25; three-arm v1/v2 root cause).
|
|
33
|
+
* Flags are dropped on purpose: the assertions are case-sensitive.
|
|
34
|
+
* A bare pattern (no leading slash) is returned untouched, and a pattern
|
|
35
|
+
* whose first slash is never closed is treated as literal. */
|
|
36
|
+
export declare function normalizeRegex(pattern: string): string;
|
|
27
37
|
/** Fence convention: when the reply is a fenced block, assertions test the
|
|
28
38
|
* fence INNER content (day-55 finding: models preserve literals verbatim
|
|
29
39
|
* inside code fences while normalizing them in prose - the fence is the
|
package/dist/bench.js
CHANGED
|
@@ -24,6 +24,34 @@ export function matchExpect(output, expect) {
|
|
|
24
24
|
const lower = output.toLowerCase();
|
|
25
25
|
return expect.every((e) => lower.includes(e.toLowerCase()));
|
|
26
26
|
}
|
|
27
|
+
/** Strip JS regex-literal delimiters: `/^\d+$/i` -> `^\d+$`.
|
|
28
|
+
* .task data files write expect-regex with slashes (bench/cases/*.task,
|
|
29
|
+
* HarmonyBench exports); callers hand the value to `new RegExp(...)`, which
|
|
30
|
+
* treats the slashes as literal characters — so `/^\d+$/` matched the
|
|
31
|
+
* literal text "^\d+$" and never a digit. 13 of 35 gate cases were
|
|
32
|
+
* unpassable for this reason (2026-11-25; three-arm v1/v2 root cause).
|
|
33
|
+
* Flags are dropped on purpose: the assertions are case-sensitive.
|
|
34
|
+
* A bare pattern (no leading slash) is returned untouched, and a pattern
|
|
35
|
+
* whose first slash is never closed is treated as literal. */
|
|
36
|
+
export function normalizeRegex(pattern) {
|
|
37
|
+
if (pattern.length < 2 || pattern[0] !== '/')
|
|
38
|
+
return pattern;
|
|
39
|
+
let escaped = false;
|
|
40
|
+
for (let i = 1; i < pattern.length; i++) {
|
|
41
|
+
const ch = pattern[i];
|
|
42
|
+
if (escaped) {
|
|
43
|
+
escaped = false;
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (ch === '\\') {
|
|
47
|
+
escaped = true;
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (ch === '/')
|
|
51
|
+
return pattern.slice(1, i);
|
|
52
|
+
}
|
|
53
|
+
return pattern;
|
|
54
|
+
}
|
|
27
55
|
/** Fence convention: when the reply is a fenced block, assertions test the
|
|
28
56
|
* fence INNER content (day-55 finding: models preserve literals verbatim
|
|
29
57
|
* inside code fences while normalizing them in prose - the fence is the
|
|
@@ -41,7 +69,9 @@ export function matchCase(output, c) {
|
|
|
41
69
|
}
|
|
42
70
|
if (c.expectRegex !== undefined) {
|
|
43
71
|
try {
|
|
44
|
-
|
|
72
|
+
// defense in depth: case objects built by hand (not via listCases)
|
|
73
|
+
// may still carry the delimiters
|
|
74
|
+
if (!new RegExp(normalizeRegex(c.expectRegex)).test(body))
|
|
45
75
|
return { pass: false, detail: `regex mismatch: /${c.expectRegex.slice(0, 60)}/` };
|
|
46
76
|
}
|
|
47
77
|
catch {
|
|
@@ -87,7 +117,9 @@ export async function listCases(home) {
|
|
|
87
117
|
prompt,
|
|
88
118
|
expect: list('expect') ?? [],
|
|
89
119
|
expectExact: pick('expect-exact')?.replace(/^"|"$/g, ''),
|
|
90
|
-
|
|
120
|
+
// normalized at the parse boundary so every consumer (matchCase,
|
|
121
|
+
// three-arm judgeOutput, experiment drivers) gets a bare pattern
|
|
122
|
+
expectRegex: pick('expect-regex') !== undefined ? normalizeRegex(pick('expect-regex')) : undefined,
|
|
91
123
|
expectNone: list('expect-none'),
|
|
92
124
|
expectAny: list('expect-any'),
|
|
93
125
|
tools: pick('tools') === 'loop',
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hmharness/evolution - case-runner
|
|
3
|
+
*
|
|
4
|
+
* The ONE place that turns a bench case + skills prompt into model messages.
|
|
5
|
+
*
|
|
6
|
+
* Root cause #2 (2026-11-25): `runEvolution` calls `runCase(case, skillsPrompt)`
|
|
7
|
+
* - the baseline receives the active-skills block, the candidate receives
|
|
8
|
+
* active + draft. Three call sites existed and two of them (the agent
|
|
9
|
+
* background loop and the TUI) silently dropped the second parameter, so in
|
|
10
|
+
* production both arms got IDENTICAL messages and the promotion gate compared
|
|
11
|
+
* A against A. The published evolution log shows the fingerprint: 125 of 127
|
|
12
|
+
* promotions had baseline pass rate == candidate pass rate.
|
|
13
|
+
*
|
|
14
|
+
* This module makes the injection impossible to forget: the skills prompt is
|
|
15
|
+
* a required parameter of `caseRunnerMessages` and always lands in the
|
|
16
|
+
* system message. Every `runEvolution` call site builds its runner from here
|
|
17
|
+
* (the CLI's own `makeCaseRunner` was the correct reference implementation -
|
|
18
|
+
* it had fixed the same defect on "day-50" - so this is that fix, shared).
|
|
19
|
+
*/
|
|
20
|
+
export type ChatMessage = {
|
|
21
|
+
role: 'system' | 'user';
|
|
22
|
+
content: string;
|
|
23
|
+
};
|
|
24
|
+
/** Messages for a non-tool bench case. An empty skills prompt yields the
|
|
25
|
+
* user message alone, which keeps the control arm byte-identical to the
|
|
26
|
+
* pre-skills behavior. */
|
|
27
|
+
export declare function caseRunnerMessages(prompt: string, skillsPrompt: string): ChatMessage[];
|
|
28
|
+
export interface CaseRunnerDeps {
|
|
29
|
+
/** One model turn. Receives exactly what `caseRunnerMessages` built.
|
|
30
|
+
* `content` may be null - that is the kernel's ChatResponse contract
|
|
31
|
+
* (`content: string | null`), so callers can pass `chat` straight through. */
|
|
32
|
+
chat: (messages: ChatMessage[]) => Promise<{
|
|
33
|
+
message: {
|
|
34
|
+
content?: string | null;
|
|
35
|
+
};
|
|
36
|
+
}>;
|
|
37
|
+
}
|
|
38
|
+
/** A `runEvolution`-compatible `runCase` for the plain (non-tool) bench cases.
|
|
39
|
+
* Returns the function itself - the exact shape `runEvolution` expects, so a
|
|
40
|
+
* call site reads `runCase: buildCaseRunner({ chat })`.
|
|
41
|
+
* Tool cases (`c.tools`) need a live agent loop, so they are the caller's
|
|
42
|
+
* concern: route them before calling this and pass the skills prompt into
|
|
43
|
+
* the loop's system prompt yourself (the agent runner shows the pattern). */
|
|
44
|
+
export declare function buildCaseRunner(deps: CaseRunnerDeps): (c: {
|
|
45
|
+
prompt: string;
|
|
46
|
+
tools: boolean;
|
|
47
|
+
}, skillsPrompt: string) => Promise<string>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hmharness/evolution - case-runner
|
|
3
|
+
*
|
|
4
|
+
* The ONE place that turns a bench case + skills prompt into model messages.
|
|
5
|
+
*
|
|
6
|
+
* Root cause #2 (2026-11-25): `runEvolution` calls `runCase(case, skillsPrompt)`
|
|
7
|
+
* - the baseline receives the active-skills block, the candidate receives
|
|
8
|
+
* active + draft. Three call sites existed and two of them (the agent
|
|
9
|
+
* background loop and the TUI) silently dropped the second parameter, so in
|
|
10
|
+
* production both arms got IDENTICAL messages and the promotion gate compared
|
|
11
|
+
* A against A. The published evolution log shows the fingerprint: 125 of 127
|
|
12
|
+
* promotions had baseline pass rate == candidate pass rate.
|
|
13
|
+
*
|
|
14
|
+
* This module makes the injection impossible to forget: the skills prompt is
|
|
15
|
+
* a required parameter of `caseRunnerMessages` and always lands in the
|
|
16
|
+
* system message. Every `runEvolution` call site builds its runner from here
|
|
17
|
+
* (the CLI's own `makeCaseRunner` was the correct reference implementation -
|
|
18
|
+
* it had fixed the same defect on "day-50" - so this is that fix, shared).
|
|
19
|
+
*/
|
|
20
|
+
/** Messages for a non-tool bench case. An empty skills prompt yields the
|
|
21
|
+
* user message alone, which keeps the control arm byte-identical to the
|
|
22
|
+
* pre-skills behavior. */
|
|
23
|
+
export function caseRunnerMessages(prompt, skillsPrompt) {
|
|
24
|
+
if (skillsPrompt) {
|
|
25
|
+
return [
|
|
26
|
+
{ role: 'system', content: skillsPrompt },
|
|
27
|
+
{ role: 'user', content: prompt },
|
|
28
|
+
];
|
|
29
|
+
}
|
|
30
|
+
return [{ role: 'user', content: prompt }];
|
|
31
|
+
}
|
|
32
|
+
/** A `runEvolution`-compatible `runCase` for the plain (non-tool) bench cases.
|
|
33
|
+
* Returns the function itself - the exact shape `runEvolution` expects, so a
|
|
34
|
+
* call site reads `runCase: buildCaseRunner({ chat })`.
|
|
35
|
+
* Tool cases (`c.tools`) need a live agent loop, so they are the caller's
|
|
36
|
+
* concern: route them before calling this and pass the skills prompt into
|
|
37
|
+
* the loop's system prompt yourself (the agent runner shows the pattern). */
|
|
38
|
+
export function buildCaseRunner(deps) {
|
|
39
|
+
return async (c, skillsPrompt) => {
|
|
40
|
+
const r = await deps.chat(caseRunnerMessages(c.prompt, skillsPrompt));
|
|
41
|
+
return r.message.content ?? '';
|
|
42
|
+
};
|
|
43
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export * from './sequential.js';
|
|
|
11
11
|
export * from './insights.js';
|
|
12
12
|
export * from './skills.js';
|
|
13
13
|
export * from './bench.js';
|
|
14
|
+
export * from './case-runner.js';
|
|
14
15
|
export * from './evolve.js';
|
|
15
16
|
export * from './patches.js';
|
|
16
17
|
export * from './impact.js';
|
package/dist/index.js
CHANGED
|
@@ -11,6 +11,7 @@ export * from "./sequential.js";
|
|
|
11
11
|
export * from "./insights.js";
|
|
12
12
|
export * from "./skills.js";
|
|
13
13
|
export * from "./bench.js";
|
|
14
|
+
export * from "./case-runner.js";
|
|
14
15
|
export * from "./evolve.js";
|
|
15
16
|
export * from "./patches.js";
|
|
16
17
|
export * from "./impact.js";
|
package/dist/insights.d.ts
CHANGED
|
@@ -2,7 +2,15 @@ export interface Insight {
|
|
|
2
2
|
time: string;
|
|
3
3
|
session: string;
|
|
4
4
|
task: string;
|
|
5
|
-
|
|
5
|
+
/** How the task's agent loop stopped. `ok` = the model produced a final
|
|
6
|
+
* answer. The rest mirror the kernel's `LoopResult.reason` (2026-11-25;
|
|
7
|
+
* before that the agent re-derived a two-valued 'ok' | 'turn-budget' from
|
|
8
|
+
* the turn count, so a loop stopped by the token valve or an interrupt
|
|
9
|
+
* was logged as a success). 'turn-budget' is kept because it is what
|
|
10
|
+
* historical records on disk contain.
|
|
11
|
+
* NOTE: `ok` is "finished with an answer", not "the answer is correct" -
|
|
12
|
+
* correctness is not observable from inside the loop. */
|
|
13
|
+
outcome: 'ok' | 'turn-budget' | 'error' | 'turn-valve' | 'token-valve' | 'idle' | 'interrupted';
|
|
6
14
|
turns: number;
|
|
7
15
|
toolUses: number;
|
|
8
16
|
toolsUsed: string[];
|
package/dist/three-arm.js
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
* analysis cannot tune them after seeing results (pre-registration rule).
|
|
17
17
|
*/
|
|
18
18
|
import { createHash } from 'node:crypto';
|
|
19
|
+
import { normalizeRegex } from "./bench.js";
|
|
19
20
|
/* ---------------- pre-registered constants (frozen before any run) ---------------- */
|
|
20
21
|
export const EXPERIMENT_ID = 'three-arm-main-experiment-2026-10-27';
|
|
21
22
|
/** Family quotas for the train subset. Families are the first '-' segment of
|
|
@@ -126,7 +127,10 @@ export function judgeOutput(output, t) {
|
|
|
126
127
|
}
|
|
127
128
|
if (a.expectRegex !== undefined) {
|
|
128
129
|
try {
|
|
129
|
-
|
|
130
|
+
// normalizeRegex: .task files carry JS-literal delimiters (/^\d+$/);
|
|
131
|
+
// without it the judge compared against the literal text "^\d+$" and
|
|
132
|
+
// 13 gate cases were unpassable (2026-11-25 root cause)
|
|
133
|
+
if (!new RegExp(normalizeRegex(a.expectRegex)).test(body))
|
|
130
134
|
return { pass: false, detail: `regex mismatch: /${a.expectRegex.slice(0, 60)}/`, falseCompletion: DONE_RE.test(body) };
|
|
131
135
|
}
|
|
132
136
|
catch {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hmharness/evolution",
|
|
3
|
-
"version": "0.23.
|
|
3
|
+
"version": "0.23.51",
|
|
4
4
|
"description": "hmharness evolution subsystem: persistent memory, insight capture, skill library, and the bench that gives evolution its fitness signal. First-class kernel citizen, not a plugin.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
"build": "tsc -p tsconfig.build.json"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@hmharness/cognitive": "0.23.
|
|
19
|
-
"@hmharness/kernel": "0.23.
|
|
18
|
+
"@hmharness/cognitive": "0.23.51",
|
|
19
|
+
"@hmharness/kernel": "0.23.51"
|
|
20
20
|
},
|
|
21
21
|
"files": [
|
|
22
22
|
"dist"
|