@hmharness/cli 0.22.0 → 0.22.2
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/ablate-task.d.ts +2 -2
- package/dist/ablate-task.js +105 -47
- package/dist/main.js +10 -9
- package/package.json +12 -12
package/dist/ablate-task.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export declare function runTaskAblation(write: (s: string) => void, home: () => string, runs: number, difficulty?: 'easy' | 'mid' | 'hard'): Promise<void>;
|
|
1
|
+
export declare function runTaskAblation(write: (s: string) => void, home: () => string, runs: number, difficulty?: 'easy' | 'mid' | 'hard' | 'bench', filter?: string): Promise<void>;
|
|
2
2
|
/**
|
|
3
3
|
* Bare-arm calibration (the v0.21.3 lesson, implemented): BEFORE an ablation
|
|
4
4
|
* claims a band is measurable, run each candidate task bare and measure its
|
|
5
5
|
* actual failure rate. Admission to the measurable band is 20-80% bare
|
|
6
6
|
* failure — the author's intuition about difficulty is not the instrument.
|
|
7
7
|
*/
|
|
8
|
-
export declare function runBareCalibration(write: (s: string) => void, difficulty: 'easy' | 'mid' | 'hard', probes: number): Promise<void>;
|
|
8
|
+
export declare function runBareCalibration(write: (s: string) => void, difficulty: 'easy' | 'mid' | 'hard' | 'bench', probes: number, home: () => string, filter?: string): Promise<void>;
|
package/dist/ablate-task.js
CHANGED
|
@@ -3,67 +3,124 @@
|
|
|
3
3
|
*
|
|
4
4
|
* ARC ablation measures the CEILING (models fail there, harness gain is not
|
|
5
5
|
* measurable yet — honest zero). This one measures the WORKING RANGE: on
|
|
6
|
-
* verifiable terminal
|
|
7
|
-
*
|
|
6
|
+
* verifiable terminal tasks where the model is competent, does the cognitive
|
|
7
|
+
* context (tool-reliability digest) change task success?
|
|
8
8
|
*
|
|
9
9
|
* arm A (cognitive): normal runner (digest injected when evidence exists)
|
|
10
10
|
* arm B (bare): HMH_NO_COGNITIVE=1 strips the digest
|
|
11
11
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
12
|
+
* Difficulty bands: easy/mid/hard (author-designed, all measured FLOOR) and
|
|
13
|
+
* `bench` — REAL corpus cases from evolution's bench with the structured
|
|
14
|
+
* assertion engine (matchCase), the natural 20-80% failure-rate sample
|
|
15
|
+
* source. Calibration (`--calibrate`) gates admission to the measurable
|
|
16
|
+
* band before any ablation spends runtime. Results append to
|
|
17
|
+
* cognitive/ablation.jsonl (type: 'terminal-task').
|
|
14
18
|
*/
|
|
15
|
-
import { spawn } from 'node:child_process';
|
|
16
19
|
import { appendFile, mkdir } from 'node:fs/promises';
|
|
17
20
|
import { join } from 'node:path';
|
|
18
21
|
const GREEN = (s) => `\x1b[32m${s}\x1b[0m`;
|
|
19
22
|
const RED = (s) => `\x1b[31m${s}\x1b[0m`;
|
|
20
23
|
const DIM = (s) => `\x1b[2m${s}\x1b[0m`;
|
|
24
|
+
const bySubstring = (expect) => (output) => output.includes(expect);
|
|
21
25
|
/** deterministic, verifiable mini-tasks (exact substring must appear) */
|
|
22
26
|
const TASKS = [
|
|
23
|
-
{ text: '用 read_file 读取 G:/hmharness/package.json,只回复 "name" 字段的精确值,不要其他文字。',
|
|
24
|
-
{ text: '用 read_file 读取 G:/hmharness/README.md 的第一行,只回复该行内容。',
|
|
25
|
-
{ text: '用 run_command 执行 node -e "console.log(21*2)",只回复输出数字。',
|
|
26
|
-
{ text: '用 list_dir 列出 G:/hmharness/packages 下名为 kernel 的目录是否存在,只回复 是 或 否。',
|
|
27
|
+
{ text: '用 read_file 读取 G:/hmharness/package.json,只回复 "name" 字段的精确值,不要其他文字。', label: 'field-extract', check: bySubstring('hmharness') },
|
|
28
|
+
{ text: '用 read_file 读取 G:/hmharness/README.md 的第一行,只回复该行内容。', label: 'first-line', check: bySubstring('#') },
|
|
29
|
+
{ text: '用 run_command 执行 node -e "console.log(21*2)",只回复输出数字。', label: 'compute', check: bySubstring('42') },
|
|
30
|
+
{ text: '用 list_dir 列出 G:/hmharness/packages 下名为 kernel 的目录是否存在,只回复 是 或 否。', label: 'exists-check', check: bySubstring('是') },
|
|
27
31
|
];
|
|
28
32
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
33
|
+
* MID band: multi-step extraction (author-designed; measured FLOOR — kept
|
|
34
|
+
* for the difficulty-spectrum record, not for measurable gain).
|
|
35
|
+
*/
|
|
36
|
+
const MID_TASKS = [
|
|
37
|
+
{ text: '用 read_file 读取 G:/hmharness/packages/kernel/src/index.ts,统计包含 export 的行数,只回复该数字。', label: 'count-export', check: bySubstring('16') },
|
|
38
|
+
{ text: '读取 G:/hmharness/packages/cli/package.json,按字母序只列出全部 @hmharness 开头的依赖名,逗号分隔不要空格。', label: 'sorted-deps', check: bySubstring('@hmharness/agent,@hmharness/cognitive,@hmharness/domain-harmony,@hmharness/domain-ops,@hmharness/environments,@hmharness/evaluation,@hmharness/evolution,@hmharness/kernel,@hmharness/observability,@hmharness/sandbox,@hmharness/web') },
|
|
39
|
+
{ text: '读取 G:/hmharness/package.json 的 version 字段,计算 主版本+次版本+修订版 三个数字之和,只回复数字。', label: 'version-sum', check: bySubstring('23') },
|
|
40
|
+
{ text: '用 list_dir 查看 G:/hmharness/packages/cognitive/src/__tests__ 目录,统计其中 .test.ts 结尾的文件个数,只回复数字。', label: 'count-tests', check: bySubstring('5') },
|
|
41
|
+
];
|
|
42
|
+
/**
|
|
43
|
+
* HARD band: cross-file aggregation (author-designed; measured FLOOR).
|
|
31
44
|
*/
|
|
32
45
|
const HARD_TASKS = [
|
|
33
|
-
{ text: '分别读取 G:/hmharness/packages/kernel/src/index.ts 和 G:/hmharness/packages/agent/src/index.ts 两个文件,统计两个文件中包含 export 的行数总和,只回复该数字。',
|
|
34
|
-
{ text: '读取 G:/hmharness/packages/web/package.json,只回复 dependencies 中 qrcode 这一项的精确版本约束字符串(含符号),不要其他文字。',
|
|
35
|
-
{ text: '统计 G:/hmharness/packages/cognitive/src/__tests__ 和 G:/hmharness/packages/environments/src/__tests__ 两个目录中 .test.ts 结尾文件的总个数,只回复数字。',
|
|
36
|
-
{ text: '读取 G:/hmharness/package.json 的 version 字段,把其中的点全部换成短横线后回复结果,不要其他文字。',
|
|
46
|
+
{ text: '分别读取 G:/hmharness/packages/kernel/src/index.ts 和 G:/hmharness/packages/agent/src/index.ts 两个文件,统计两个文件中包含 export 的行数总和,只回复该数字。', label: 'cross-file-count', check: bySubstring('29') },
|
|
47
|
+
{ text: '读取 G:/hmharness/packages/web/package.json,只回复 dependencies 中 qrcode 这一项的精确版本约束字符串(含符号),不要其他文字。', label: 'dep-constraint', check: bySubstring('^1.5.4') },
|
|
48
|
+
{ text: '统计 G:/hmharness/packages/cognitive/src/__tests__ 和 G:/hmharness/packages/environments/src/__tests__ 两个目录中 .test.ts 结尾文件的总个数,只回复数字。', label: 'cross-dir-count', check: bySubstring('9') },
|
|
49
|
+
{ text: '读取 G:/hmharness/package.json 的 version 字段,把其中的点全部换成短横线后回复结果,不要其他文字。', label: 'version-dashes', check: bySubstring('0-21-3') },
|
|
37
50
|
];
|
|
38
|
-
|
|
39
|
-
|
|
51
|
+
/** BENCH band: real corpus cases with the structured assertion engine. */
|
|
52
|
+
async function benchPool(home, filter, limit = 8) {
|
|
53
|
+
const { listCases, matchCase } = await import('@hmharness/evolution');
|
|
54
|
+
const cases = await listCases(home);
|
|
55
|
+
return cases
|
|
56
|
+
.filter((c) => !c.holdout)
|
|
57
|
+
.filter((c) => (filter ? c.name.startsWith(filter) : true))
|
|
58
|
+
.slice(0, limit)
|
|
59
|
+
.map((c) => ({
|
|
60
|
+
text: c.prompt,
|
|
61
|
+
label: `bench:${c.name}`,
|
|
62
|
+
check: (out) => matchCase(out, c).pass,
|
|
63
|
+
}));
|
|
40
64
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
65
|
+
async function poolOf(difficulty, home, filter) {
|
|
66
|
+
if (difficulty === 'bench')
|
|
67
|
+
return benchPool(home(), filter);
|
|
68
|
+
if (difficulty === 'hard')
|
|
69
|
+
return HARD_TASKS;
|
|
70
|
+
if (difficulty === 'mid')
|
|
71
|
+
return MID_TASKS;
|
|
72
|
+
return TASKS;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* One agent run IN-PROCESS, capturing the FINAL reply text — the exact same
|
|
76
|
+
* extraction the bench gate uses. (The earlier subprocess version captured
|
|
77
|
+
* raw stdout: thinking blocks + session lines + ANSI noise broke expect-exact
|
|
78
|
+
* assertions — a measurement artifact that misread "model fails" when the
|
|
79
|
+
* harness output was merely verbose. Same instrument, same reading.)
|
|
80
|
+
*/
|
|
81
|
+
async function runOnce(task, bare, timeoutMs) {
|
|
82
|
+
const prev = process.env.HMH_NO_COGNITIVE;
|
|
83
|
+
if (bare)
|
|
84
|
+
process.env.HMH_NO_COGNITIVE = '1';
|
|
85
|
+
else
|
|
86
|
+
delete process.env.HMH_NO_COGNITIVE;
|
|
87
|
+
let finalText = '';
|
|
88
|
+
try {
|
|
89
|
+
const { runAgentTask, buildRegistry } = await import('@hmharness/agent');
|
|
90
|
+
const { loadConfig } = await import('@hmharness/kernel');
|
|
91
|
+
const { reg } = await buildRegistry({ mcp: false });
|
|
92
|
+
await Promise.race([
|
|
93
|
+
runAgentTask({
|
|
94
|
+
task,
|
|
95
|
+
registry: reg,
|
|
96
|
+
cfg: await loadConfig(),
|
|
97
|
+
yes: true,
|
|
98
|
+
events: { onFinal: (r) => { finalText = r.text; } },
|
|
99
|
+
}),
|
|
100
|
+
new Promise((_, reject) => setTimeout(() => reject(new Error('ablate run timeout')), timeoutMs)),
|
|
101
|
+
]).catch((err) => {
|
|
102
|
+
if (!finalText)
|
|
103
|
+
throw err;
|
|
104
|
+
return undefined;
|
|
61
105
|
});
|
|
62
|
-
|
|
106
|
+
return { ok: true, output: finalText };
|
|
107
|
+
}
|
|
108
|
+
catch (err) {
|
|
109
|
+
// a crashed run is a FAILED run (honest reading): record it and keep the
|
|
110
|
+
// ablation alive — one transient provider 400 must not kill the whole
|
|
111
|
+
// experiment and lose every arm's data
|
|
112
|
+
return { ok: false, output: finalText, error: String(err).slice(0, 120) };
|
|
113
|
+
}
|
|
114
|
+
finally {
|
|
115
|
+
if (prev === undefined)
|
|
116
|
+
delete process.env.HMH_NO_COGNITIVE;
|
|
117
|
+
else
|
|
118
|
+
process.env.HMH_NO_COGNITIVE = prev;
|
|
119
|
+
}
|
|
63
120
|
}
|
|
64
|
-
export async function runTaskAblation(write, home, runs, difficulty = 'easy') {
|
|
121
|
+
export async function runTaskAblation(write, home, runs, difficulty = 'easy', filter) {
|
|
65
122
|
const homeDir = home();
|
|
66
|
-
const pool = poolOf(difficulty);
|
|
123
|
+
const pool = await poolOf(difficulty, home, filter);
|
|
67
124
|
write(`Terminal 域消融 · ${difficulty} 难度 · ${pool.length} 个可验证任务 × ${runs} 轮 × 双臂(§26 工作域测量)\n`);
|
|
68
125
|
let withOk = 0;
|
|
69
126
|
let bareOk = 0;
|
|
@@ -74,12 +131,13 @@ export async function runTaskAblation(write, home, runs, difficulty = 'easy') {
|
|
|
74
131
|
total += 1;
|
|
75
132
|
const a = await runOnce(t.text, false, 240_000);
|
|
76
133
|
const b = await runOnce(t.text, true, 240_000);
|
|
77
|
-
const aHit = a.output
|
|
78
|
-
const bHit = b.output
|
|
134
|
+
const aHit = t.check(a.output);
|
|
135
|
+
const bHit = t.check(b.output);
|
|
79
136
|
withOk += aHit ? 1 : 0;
|
|
80
137
|
bareOk += bHit ? 1 : 0;
|
|
81
138
|
details.push({ label: t.label, with: aHit, bare: bHit });
|
|
82
|
-
|
|
139
|
+
const crash = a.error || b.error ? DIM(` ⚠ ${String(a.error ?? b.error).slice(0, 70)}`) : '';
|
|
140
|
+
write(` ${t.label.padEnd(24)} 认知 ${aHit ? GREEN('✓') : RED('✗')} · 裸 ${bHit ? GREEN('✓') : RED('✗')}${crash}\n`);
|
|
83
141
|
}
|
|
84
142
|
}
|
|
85
143
|
const record = {
|
|
@@ -103,19 +161,19 @@ export async function runTaskAblation(write, home, runs, difficulty = 'easy') {
|
|
|
103
161
|
* actual failure rate. Admission to the measurable band is 20-80% bare
|
|
104
162
|
* failure — the author's intuition about difficulty is not the instrument.
|
|
105
163
|
*/
|
|
106
|
-
export async function runBareCalibration(write, difficulty, probes) {
|
|
107
|
-
const pool = poolOf(difficulty);
|
|
164
|
+
export async function runBareCalibration(write, difficulty, probes, home, filter) {
|
|
165
|
+
const pool = await poolOf(difficulty, home, filter);
|
|
108
166
|
write(`裸臂定标 · ${difficulty} 难度 · ${pool.length} 任务 × ${probes} 次裸跑(准入带=失败率 20%-80%)\n`);
|
|
109
167
|
for (const t of pool) {
|
|
110
168
|
let fails = 0;
|
|
111
169
|
for (let i = 0; i < probes; i++) {
|
|
112
170
|
const r = await runOnce(t.text, true, 240_000);
|
|
113
|
-
if (!r.output
|
|
171
|
+
if (!t.check(r.output))
|
|
114
172
|
fails += 1;
|
|
115
173
|
}
|
|
116
174
|
const rate = Number((fails / probes).toFixed(2));
|
|
117
175
|
const band = rate === 0 ? '地板(剔除)' : rate >= 1 ? '天花板(剔除)' : rate >= 0.2 && rate <= 0.8 ? '可测带 ✓' : '边缘';
|
|
118
|
-
write(` ${t.label.padEnd(
|
|
176
|
+
write(` ${t.label.padEnd(24)} 裸失败率 ${Math.round(rate * 100)}% → ${band}\n`);
|
|
119
177
|
}
|
|
120
178
|
write(DIM(' 定标纪律:只有可测带任务进消融池;地板/天花板任务测不出处理效应\n'));
|
|
121
179
|
}
|
package/dist/main.js
CHANGED
|
@@ -1219,25 +1219,26 @@ flags:
|
|
|
1219
1219
|
return;
|
|
1220
1220
|
}
|
|
1221
1221
|
if (rest.includes('--task')) {
|
|
1222
|
-
// §26 in the WORKING domain: verifiable
|
|
1223
|
-
//
|
|
1224
|
-
// --difficulty
|
|
1225
|
-
//
|
|
1222
|
+
// §26 in the WORKING domain: verifiable tasks, same model, digest on
|
|
1223
|
+
// vs HMH_NO_COGNITIVE=1 — result-level harness delta.
|
|
1224
|
+
// --difficulty=bench uses the REAL evolution corpus (116 cases with
|
|
1225
|
+
// the structured assertion engine) — the natural failure-rate source.
|
|
1226
1226
|
const rounds = Number(rest.find((a) => a.startsWith('--runs='))?.slice(7) ?? 1);
|
|
1227
|
-
const difficulty = rest.includes('--difficulty=hard') ? 'hard' : rest.includes('--difficulty=mid') ? 'mid' : 'easy';
|
|
1227
|
+
const difficulty = rest.includes('--difficulty=bench') ? 'bench' : rest.includes('--difficulty=hard') ? 'hard' : rest.includes('--difficulty=mid') ? 'mid' : 'easy';
|
|
1228
|
+
const filter = rest.find((a) => a.startsWith('--filter='))?.slice(9);
|
|
1228
1229
|
const { runTaskAblation, runBareCalibration } = await import("./ablate-task.js");
|
|
1229
1230
|
const { homeDir: hd } = await import('@hmharness/kernel');
|
|
1230
1231
|
if (rest.includes('--calibrate')) {
|
|
1231
1232
|
const probes = Number(rest.find((a) => a.startsWith('--probes='))?.slice(9) ?? 2);
|
|
1232
|
-
await runBareCalibration((s) => stdout.write(s), difficulty, Number.isFinite(probes) ? Math.min(Math.max(probes, 1), 4) : 2);
|
|
1233
|
+
await runBareCalibration((s) => stdout.write(s), difficulty, Number.isFinite(probes) ? Math.min(Math.max(probes, 1), 4) : 2, hd, filter);
|
|
1233
1234
|
return;
|
|
1234
1235
|
}
|
|
1235
|
-
await runTaskAblation((s) => stdout.write(s), hd, Number.isFinite(rounds) ? Math.min(Math.max(rounds, 1), 5) : 1, difficulty);
|
|
1236
|
+
await runTaskAblation((s) => stdout.write(s), hd, Number.isFinite(rounds) ? Math.min(Math.max(rounds, 1), 5) : 1, difficulty, filter);
|
|
1236
1237
|
return;
|
|
1237
1238
|
}
|
|
1238
1239
|
if (!rest.includes('--env=arc3')) {
|
|
1239
|
-
stdout.write('用法: hmh cognitive ablate --env=arc3 [--steps=N] | --task [--runs=N] [--difficulty=easy|mid|hard] [--calibrate [--probes=N]] | --stats\n');
|
|
1240
|
-
stdout.write(DIM(' --calibrate: 裸臂定标(准入带=裸失败率20-80%)
|
|
1240
|
+
stdout.write('用法: hmh cognitive ablate --env=arc3 [--steps=N] | --task [--runs=N] [--difficulty=easy|mid|hard|bench] [--filter=前缀] [--calibrate [--probes=N]] | --stats\n');
|
|
1241
|
+
stdout.write(DIM(' --difficulty=bench: evolution 真实语料(结构化断言); --calibrate: 裸臂定标(准入带=裸失败率20-80%)\n'));
|
|
1241
1242
|
return;
|
|
1242
1243
|
}
|
|
1243
1244
|
const steps = Number(rest.find((a) => a.startsWith('--steps='))?.slice(8) ?? 5);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hmharness/cli",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.2",
|
|
4
4
|
"description": "hmharness command line: one-shot tasks, an interactive REPL, a fullscreen TUI, the web frontend, and direct tool invocation.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -43,17 +43,17 @@
|
|
|
43
43
|
"build": "tsc -p tsconfig.build.json"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@hmharness/agent": "0.22.
|
|
47
|
-
"@hmharness/cognitive": "0.22.
|
|
48
|
-
"@hmharness/domain-harmony": "0.22.
|
|
49
|
-
"@hmharness/domain-ops": "0.22.
|
|
50
|
-
"@hmharness/environments": "0.22.
|
|
51
|
-
"@hmharness/evaluation": "0.22.
|
|
52
|
-
"@hmharness/evolution": "0.22.
|
|
53
|
-
"@hmharness/kernel": "0.22.
|
|
54
|
-
"@hmharness/observability": "0.22.
|
|
55
|
-
"@hmharness/sandbox": "0.22.
|
|
56
|
-
"@hmharness/web": "0.22.
|
|
46
|
+
"@hmharness/agent": "0.22.2",
|
|
47
|
+
"@hmharness/cognitive": "0.22.2",
|
|
48
|
+
"@hmharness/domain-harmony": "0.22.2",
|
|
49
|
+
"@hmharness/domain-ops": "0.22.2",
|
|
50
|
+
"@hmharness/environments": "0.22.2",
|
|
51
|
+
"@hmharness/evaluation": "0.22.2",
|
|
52
|
+
"@hmharness/evolution": "0.22.2",
|
|
53
|
+
"@hmharness/kernel": "0.22.2",
|
|
54
|
+
"@hmharness/observability": "0.22.2",
|
|
55
|
+
"@hmharness/sandbox": "0.22.2",
|
|
56
|
+
"@hmharness/web": "0.22.2",
|
|
57
57
|
"qrcode": "^1.5.4"
|
|
58
58
|
}
|
|
59
59
|
}
|