@hmharness/cli 0.21.3 → 0.22.1

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.
@@ -1 +1,8 @@
1
- export declare function runTaskAblation(write: (s: string) => void, home: () => string, runs: number, difficulty?: 'easy' | 'mid'): 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
+ /**
3
+ * Bare-arm calibration (the v0.21.3 lesson, implemented): BEFORE an ablation
4
+ * claims a band is measurable, run each candidate task bare and measure its
5
+ * actual failure rate. Admission to the measurable band is 20-80% bare
6
+ * failure — the author's intuition about difficulty is not the instrument.
7
+ */
8
+ export declare function runBareCalibration(write: (s: string) => void, difficulty: 'easy' | 'mid' | 'hard' | 'bench', probes: number, home: () => string, filter?: string): Promise<void>;
@@ -3,59 +3,119 @@
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 mini-tasks where the model is competent, does the
7
- * cognitive context (tool-reliability digest) change task success?
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
- * Same model, same task text, deterministic exact-match verification.
13
- * Results append to cognitive/ablation.jsonl (type: 'terminal-task').
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" 字段的精确值,不要其他文字。', expect: 'hmharness', label: 'field-extract' },
24
- { text: '用 read_file 读取 G:/hmharness/README.md 的第一行,只回复该行内容。', expect: '#', label: 'first-line' },
25
- { text: '用 run_command 执行 node -e "console.log(21*2)",只回复输出数字。', expect: '42', label: 'compute' },
26
- { text: '用 list_dir 列出 G:/hmharness/packages 下名为 kernel 的目录是否存在,只回复 是 或 否。', expect: '是', label: 'exists-check' },
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
- * MID-difficulty band (§26's measurable zone): multi-step extraction where
30
- * bare-prompt runs sometimes slip — counting, sorted enumeration, version
31
- * arithmetic. Expected values verified against the repo at authoring time.
33
+ * MID band: multi-step extraction (author-designed; measured FLOOR — kept
34
+ * for the difficulty-spectrum record, not for measurable gain).
32
35
  */
33
36
  const MID_TASKS = [
34
- { text: '用 read_file 读取 G:/hmharness/packages/kernel/src/index.ts,统计包含 export 的行数,只回复该数字。', expect: '16', label: 'count-export' },
35
- { text: '读取 G:/hmharness/packages/cli/package.json,按字母序只列出全部 @hmharness 开头的依赖名,逗号分隔不要空格。', expect: '@hmharness/agent,@hmharness/cognitive,@hmharness/domain-harmony,@hmharness/domain-ops,@hmharness/environments,@hmharness/evaluation,@hmharness/evolution,@hmharness/kernel,@hmharness/observability,@hmharness/sandbox,@hmharness/web', label: 'sorted-deps' },
36
- { text: '读取 G:/hmharness/package.json 的 version 字段,计算 主版本+次版本+修订版 三个数字之和,只回复数字。', expect: '23', label: 'version-sum' },
37
- { text: '用 list_dir 查看 G:/hmharness/packages/cognitive/src/__tests__ 目录,统计其中 .test.ts 结尾的文件个数,只回复数字。', expect: '5', label: 'count-tests' },
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') },
38
41
  ];
39
- function runOnce(task, bare, timeoutMs) {
40
- return new Promise((resolve) => {
41
- const child = spawn('npx', ['tsx', 'packages/cli/src/main.ts', '--yes', task], {
42
- cwd: 'G:/hmharness',
43
- shell: true,
44
- env: { ...process.env, ...(bare ? { HMH_NO_COGNITIVE: '1' } : {}) },
45
- });
46
- let out = '';
47
- const timer = setTimeout(() => child.kill(), timeoutMs);
48
- child.stdout?.on('data', (d) => (out += d.toString()));
49
- child.stderr?.on('data', (d) => (out += d.toString()));
50
- child.on('close', (code) => {
51
- clearTimeout(timer);
52
- resolve({ ok: code === 0, output: out });
42
+ /**
43
+ * HARD band: cross-file aggregation (author-designed; measured FLOOR).
44
+ */
45
+ const HARD_TASKS = [
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') },
50
+ ];
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
+ }));
64
+ }
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
+ const result = 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;
53
105
  });
54
- });
106
+ void result;
107
+ return { ok: true, output: finalText };
108
+ }
109
+ finally {
110
+ if (prev === undefined)
111
+ delete process.env.HMH_NO_COGNITIVE;
112
+ else
113
+ process.env.HMH_NO_COGNITIVE = prev;
114
+ }
55
115
  }
56
- export async function runTaskAblation(write, home, runs, difficulty = 'easy') {
116
+ export async function runTaskAblation(write, home, runs, difficulty = 'easy', filter) {
57
117
  const homeDir = home();
58
- const pool = difficulty === 'mid' ? MID_TASKS : TASKS;
118
+ const pool = await poolOf(difficulty, home, filter);
59
119
  write(`Terminal 域消融 · ${difficulty} 难度 · ${pool.length} 个可验证任务 × ${runs} 轮 × 双臂(§26 工作域测量)\n`);
60
120
  let withOk = 0;
61
121
  let bareOk = 0;
@@ -66,12 +126,12 @@ export async function runTaskAblation(write, home, runs, difficulty = 'easy') {
66
126
  total += 1;
67
127
  const a = await runOnce(t.text, false, 240_000);
68
128
  const b = await runOnce(t.text, true, 240_000);
69
- const aHit = a.output.includes(t.expect);
70
- const bHit = b.output.includes(t.expect);
129
+ const aHit = t.check(a.output);
130
+ const bHit = t.check(b.output);
71
131
  withOk += aHit ? 1 : 0;
72
132
  bareOk += bHit ? 1 : 0;
73
133
  details.push({ label: t.label, with: aHit, bare: bHit });
74
- write(` ${t.label.padEnd(14)} 认知 ${aHit ? GREEN('✓') : RED('✗')} · 裸 ${bHit ? GREEN('✓') : RED('✗')}\n`);
134
+ write(` ${t.label.padEnd(24)} 认知 ${aHit ? GREEN('✓') : RED('✗')} · 裸 ${bHit ? GREEN('✓') : RED('✗')}\n`);
75
135
  }
76
136
  }
77
137
  const record = {
@@ -89,3 +149,25 @@ export async function runTaskAblation(write, home, runs, difficulty = 'easy') {
89
149
  write(`结论 · 认知层 ${withOk}/${total} vs 裸 ${bareOk}/${total} → harness 结果层净贡献 ${(record.harnessDelta * 100).toFixed(1)}%\n`);
90
150
  write(DIM('(ARC 域测上限=诚实零;本域测工作范围=模型胜任区的结果增益)\n'));
91
151
  }
152
+ /**
153
+ * Bare-arm calibration (the v0.21.3 lesson, implemented): BEFORE an ablation
154
+ * claims a band is measurable, run each candidate task bare and measure its
155
+ * actual failure rate. Admission to the measurable band is 20-80% bare
156
+ * failure — the author's intuition about difficulty is not the instrument.
157
+ */
158
+ export async function runBareCalibration(write, difficulty, probes, home, filter) {
159
+ const pool = await poolOf(difficulty, home, filter);
160
+ write(`裸臂定标 · ${difficulty} 难度 · ${pool.length} 任务 × ${probes} 次裸跑(准入带=失败率 20%-80%)\n`);
161
+ for (const t of pool) {
162
+ let fails = 0;
163
+ for (let i = 0; i < probes; i++) {
164
+ const r = await runOnce(t.text, true, 240_000);
165
+ if (!t.check(r.output))
166
+ fails += 1;
167
+ }
168
+ const rate = Number((fails / probes).toFixed(2));
169
+ const band = rate === 0 ? '地板(剔除)' : rate >= 1 ? '天花板(剔除)' : rate >= 0.2 && rate <= 0.8 ? '可测带 ✓' : '边缘';
170
+ write(` ${t.label.padEnd(24)} 裸失败率 ${Math.round(rate * 100)}% → ${band}\n`);
171
+ }
172
+ write(DIM(' 定标纪律:只有可测带任务进消融池;地板/天花板任务测不出处理效应\n'));
173
+ }
package/dist/main.js CHANGED
@@ -1219,19 +1219,26 @@ flags:
1219
1219
  return;
1220
1220
  }
1221
1221
  if (rest.includes('--task')) {
1222
- // §26 in the WORKING domain: verifiable terminal mini-tasks, same
1223
- // model, digest on vs HMH_NO_COGNITIVE=1 — result-level harness delta.
1224
- // --difficulty=mid is the measurable band (bare runs sometimes slip).
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.
1225
1226
  const rounds = Number(rest.find((a) => a.startsWith('--runs='))?.slice(7) ?? 1);
1226
- const difficulty = rest.includes('--difficulty=mid') ? 'mid' : 'easy';
1227
- const { runTaskAblation } = await import("./ablate-task.js");
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);
1229
+ const { runTaskAblation, runBareCalibration } = await import("./ablate-task.js");
1228
1230
  const { homeDir: hd } = await import('@hmharness/kernel');
1229
- await runTaskAblation((s) => stdout.write(s), hd, Number.isFinite(rounds) ? Math.min(Math.max(rounds, 1), 5) : 1, difficulty);
1231
+ if (rest.includes('--calibrate')) {
1232
+ const probes = Number(rest.find((a) => a.startsWith('--probes='))?.slice(9) ?? 2);
1233
+ await runBareCalibration((s) => stdout.write(s), difficulty, Number.isFinite(probes) ? Math.min(Math.max(probes, 1), 4) : 2, hd, filter);
1234
+ return;
1235
+ }
1236
+ await runTaskAblation((s) => stdout.write(s), hd, Number.isFinite(rounds) ? Math.min(Math.max(rounds, 1), 5) : 1, difficulty, filter);
1230
1237
  return;
1231
1238
  }
1232
1239
  if (!rest.includes('--env=arc3')) {
1233
- stdout.write('用法: hmh cognitive ablate --env=arc3 [--steps=N] | --task [--runs=N] [--difficulty=easy|mid] | --stats\n');
1234
- stdout.write(DIM(' --env=arc3: ARC 域(上限); --task: terminal 域; --difficulty=mid: 中等难度区(结果层可测带); 结果落 cognitive/ablation.jsonl\n'));
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'));
1235
1242
  return;
1236
1243
  }
1237
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.21.3",
3
+ "version": "0.22.1",
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.21.3",
47
- "@hmharness/cognitive": "0.21.3",
48
- "@hmharness/domain-harmony": "0.21.3",
49
- "@hmharness/domain-ops": "0.21.3",
50
- "@hmharness/environments": "0.21.3",
51
- "@hmharness/evaluation": "0.21.3",
52
- "@hmharness/evolution": "0.21.3",
53
- "@hmharness/kernel": "0.21.3",
54
- "@hmharness/observability": "0.21.3",
55
- "@hmharness/sandbox": "0.21.3",
56
- "@hmharness/web": "0.21.3",
46
+ "@hmharness/agent": "0.22.1",
47
+ "@hmharness/cognitive": "0.22.1",
48
+ "@hmharness/domain-harmony": "0.22.1",
49
+ "@hmharness/domain-ops": "0.22.1",
50
+ "@hmharness/environments": "0.22.1",
51
+ "@hmharness/evaluation": "0.22.1",
52
+ "@hmharness/evolution": "0.22.1",
53
+ "@hmharness/kernel": "0.22.1",
54
+ "@hmharness/observability": "0.22.1",
55
+ "@hmharness/sandbox": "0.22.1",
56
+ "@hmharness/web": "0.22.1",
57
57
  "qrcode": "^1.5.4"
58
58
  }
59
59
  }