@hmharness/cli 0.21.1 → 0.21.3

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.
@@ -0,0 +1 @@
1
+ export declare function runTaskAblation(write: (s: string) => void, home: () => string, runs: number, difficulty?: 'easy' | 'mid'): Promise<void>;
@@ -0,0 +1,91 @@
1
+ /**
2
+ * @hmharness/cli - `hmh cognitive ablate-task` (blueprint §26, working domain)
3
+ *
4
+ * ARC ablation measures the CEILING (models fail there, harness gain is not
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?
8
+ *
9
+ * arm A (cognitive): normal runner (digest injected when evidence exists)
10
+ * arm B (bare): HMH_NO_COGNITIVE=1 strips the digest
11
+ *
12
+ * Same model, same task text, deterministic exact-match verification.
13
+ * Results append to cognitive/ablation.jsonl (type: 'terminal-task').
14
+ */
15
+ import { spawn } from 'node:child_process';
16
+ import { appendFile, mkdir } from 'node:fs/promises';
17
+ import { join } from 'node:path';
18
+ const GREEN = (s) => `\x1b[32m${s}\x1b[0m`;
19
+ const RED = (s) => `\x1b[31m${s}\x1b[0m`;
20
+ const DIM = (s) => `\x1b[2m${s}\x1b[0m`;
21
+ /** deterministic, verifiable mini-tasks (exact substring must appear) */
22
+ 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
+ ];
28
+ /**
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.
32
+ */
33
+ 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' },
38
+ ];
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 });
53
+ });
54
+ });
55
+ }
56
+ export async function runTaskAblation(write, home, runs, difficulty = 'easy') {
57
+ const homeDir = home();
58
+ const pool = difficulty === 'mid' ? MID_TASKS : TASKS;
59
+ write(`Terminal 域消融 · ${difficulty} 难度 · ${pool.length} 个可验证任务 × ${runs} 轮 × 双臂(§26 工作域测量)\n`);
60
+ let withOk = 0;
61
+ let bareOk = 0;
62
+ let total = 0;
63
+ const details = [];
64
+ for (let r = 1; r <= runs; r++) {
65
+ for (const t of pool) {
66
+ total += 1;
67
+ const a = await runOnce(t.text, false, 240_000);
68
+ 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);
71
+ withOk += aHit ? 1 : 0;
72
+ bareOk += bHit ? 1 : 0;
73
+ details.push({ label: t.label, with: aHit, bare: bHit });
74
+ write(` ${t.label.padEnd(14)} 认知 ${aHit ? GREEN('✓') : RED('✗')} · 裸 ${bHit ? GREEN('✓') : RED('✗')}\n`);
75
+ }
76
+ }
77
+ const record = {
78
+ at: new Date().toISOString(),
79
+ type: 'terminal-task',
80
+ difficulty,
81
+ runs,
82
+ withCognitive: { pass: withOk, total },
83
+ bare: { pass: bareOk, total },
84
+ harnessDelta: Number(((withOk - bareOk) / total).toFixed(3)),
85
+ details,
86
+ };
87
+ await mkdir(join(homeDir, 'cognitive'), { recursive: true }).catch(() => undefined);
88
+ await appendFile(join(homeDir, 'cognitive', 'ablation.jsonl'), JSON.stringify(record) + '\n', 'utf8').catch(() => undefined);
89
+ write(`结论 · 认知层 ${withOk}/${total} vs 裸 ${bareOk}/${total} → harness 结果层净贡献 ${(record.harnessDelta * 100).toFixed(1)}%\n`);
90
+ write(DIM('(ARC 域测上限=诚实零;本域测工作范围=模型胜任区的结果增益)\n'));
91
+ }
package/dist/main.js CHANGED
@@ -1218,9 +1218,20 @@ flags:
1218
1218
  }
1219
1219
  return;
1220
1220
  }
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).
1225
+ 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");
1228
+ 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);
1230
+ return;
1231
+ }
1221
1232
  if (!rest.includes('--env=arc3')) {
1222
- stdout.write('用法: hmh cognitive ablate --env=arc3 [--game=<id前缀>] [--steps=N] | --stats\n');
1223
- stdout.write(DIM(' 双臂对照: 认知层(世界模型信念+经验教训) vs 裸提示词; 结果落 cognitive/ablation.jsonl\n'));
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'));
1224
1235
  return;
1225
1236
  }
1226
1237
  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.1",
3
+ "version": "0.21.3",
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.1",
47
- "@hmharness/cognitive": "0.21.1",
48
- "@hmharness/domain-harmony": "0.21.1",
49
- "@hmharness/domain-ops": "0.21.1",
50
- "@hmharness/environments": "0.21.1",
51
- "@hmharness/evaluation": "0.21.1",
52
- "@hmharness/evolution": "0.21.1",
53
- "@hmharness/kernel": "0.21.1",
54
- "@hmharness/observability": "0.21.1",
55
- "@hmharness/sandbox": "0.21.1",
56
- "@hmharness/web": "0.21.1",
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",
57
57
  "qrcode": "^1.5.4"
58
58
  }
59
59
  }