@hmharness/cli 0.21.1 → 0.21.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.
@@ -0,0 +1 @@
1
+ export declare function runTaskAblation(write: (s: string) => void, home: () => string, runs: number): Promise<void>;
@@ -0,0 +1,78 @@
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
+ function runOnce(task, bare, timeoutMs) {
29
+ return new Promise((resolve) => {
30
+ const child = spawn('npx', ['tsx', 'packages/cli/src/main.ts', '--yes', task], {
31
+ cwd: 'G:/hmharness',
32
+ shell: true,
33
+ env: { ...process.env, ...(bare ? { HMH_NO_COGNITIVE: '1' } : {}) },
34
+ });
35
+ let out = '';
36
+ const timer = setTimeout(() => child.kill(), timeoutMs);
37
+ child.stdout?.on('data', (d) => (out += d.toString()));
38
+ child.stderr?.on('data', (d) => (out += d.toString()));
39
+ child.on('close', (code) => {
40
+ clearTimeout(timer);
41
+ resolve({ ok: code === 0, output: out });
42
+ });
43
+ });
44
+ }
45
+ export async function runTaskAblation(write, home, runs) {
46
+ const homeDir = home();
47
+ write(`Terminal 域消融 · ${TASKS.length} 个可验证任务 × ${runs} 轮 × 双臂(§26 工作域测量)\n`);
48
+ let withOk = 0;
49
+ let bareOk = 0;
50
+ let total = 0;
51
+ const details = [];
52
+ for (let r = 1; r <= runs; r++) {
53
+ for (const t of TASKS) {
54
+ total += 1;
55
+ const a = await runOnce(t.text, false, 240_000);
56
+ const b = await runOnce(t.text, true, 240_000);
57
+ const aHit = a.output.includes(t.expect);
58
+ const bHit = b.output.includes(t.expect);
59
+ withOk += aHit ? 1 : 0;
60
+ bareOk += bHit ? 1 : 0;
61
+ details.push({ label: t.label, with: aHit, bare: bHit });
62
+ write(` ${t.label.padEnd(14)} 认知 ${aHit ? GREEN('✓') : RED('✗')} · 裸 ${bHit ? GREEN('✓') : RED('✗')}\n`);
63
+ }
64
+ }
65
+ const record = {
66
+ at: new Date().toISOString(),
67
+ type: 'terminal-task',
68
+ runs,
69
+ withCognitive: { pass: withOk, total },
70
+ bare: { pass: bareOk, total },
71
+ harnessDelta: Number(((withOk - bareOk) / total).toFixed(3)),
72
+ details,
73
+ };
74
+ await mkdir(join(homeDir, 'cognitive'), { recursive: true }).catch(() => undefined);
75
+ await appendFile(join(homeDir, 'cognitive', 'ablation.jsonl'), JSON.stringify(record) + '\n', 'utf8').catch(() => undefined);
76
+ write(`结论 · 认知层 ${withOk}/${total} vs 裸 ${bareOk}/${total} → harness 结果层净贡献 ${(record.harnessDelta * 100).toFixed(1)}%\n`);
77
+ write(DIM('(ARC 域测上限=诚实零;本域测工作范围=模型胜任区的结果增益)\n'));
78
+ }
package/dist/main.js CHANGED
@@ -1218,9 +1218,18 @@ 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
+ const rounds = Number(rest.find((a) => a.startsWith('--runs='))?.slice(7) ?? 1);
1225
+ const { runTaskAblation } = await import("./ablate-task.js");
1226
+ const { homeDir: hd } = await import('@hmharness/kernel');
1227
+ await runTaskAblation((s) => stdout.write(s), hd, Number.isFinite(rounds) ? Math.min(Math.max(rounds, 1), 5) : 1);
1228
+ return;
1229
+ }
1221
1230
  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'));
1231
+ stdout.write('用法: hmh cognitive ablate --env=arc3 [--steps=N] | --task [--runs=N] | --stats\n');
1232
+ stdout.write(DIM(' --env=arc3: ARC 域(上限测量); --task: terminal 域(工作范围测量); 结果落 cognitive/ablation.jsonl\n'));
1224
1233
  return;
1225
1234
  }
1226
1235
  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.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.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.2",
47
+ "@hmharness/cognitive": "0.21.2",
48
+ "@hmharness/domain-harmony": "0.21.2",
49
+ "@hmharness/domain-ops": "0.21.2",
50
+ "@hmharness/environments": "0.21.2",
51
+ "@hmharness/evaluation": "0.21.2",
52
+ "@hmharness/evolution": "0.21.2",
53
+ "@hmharness/kernel": "0.21.2",
54
+ "@hmharness/observability": "0.21.2",
55
+ "@hmharness/sandbox": "0.21.2",
56
+ "@hmharness/web": "0.21.2",
57
57
  "qrcode": "^1.5.4"
58
58
  }
59
59
  }