@hmharness/cli 0.20.2 → 0.21.0
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/arc3-play.d.ts +23 -1
- package/dist/arc3-play.js +91 -7
- package/dist/main.js +37 -3
- package/package.json +12 -12
package/dist/arc3-play.d.ts
CHANGED
|
@@ -1,7 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* §26 final research question, measured: with the SAME model and the SAME
|
|
3
|
+
* game, how much does the cognitive layer (world-model beliefs + distilled
|
|
4
|
+
* lessons injected into the prompt) contribute vs a bare prompt?
|
|
5
|
+
*
|
|
6
|
+
* arm A (cognitive): play with cognitive context
|
|
7
|
+
* arm B (bare): play with the context stripped — same model, same game
|
|
8
|
+
*
|
|
9
|
+
* Both runs land as trajectories; the delta is the HARNESS's contribution
|
|
10
|
+
* (the model was never touched). Recorded to cognitive/ablation.jsonl.
|
|
11
|
+
*/
|
|
12
|
+
export declare function runArc3Ablation(write: (s: string) => void, opts: {
|
|
13
|
+
game?: string;
|
|
14
|
+
steps: number;
|
|
15
|
+
}, deps: Parameters<typeof runArc3Play>[2]): Promise<void>;
|
|
1
16
|
export declare function runArc3Play(write: (s: string) => void, opts: {
|
|
2
17
|
game?: string;
|
|
3
18
|
steps: number;
|
|
4
19
|
vision?: boolean;
|
|
20
|
+
bare?: boolean;
|
|
21
|
+
quiet?: boolean;
|
|
5
22
|
}, deps: {
|
|
6
23
|
home: () => string;
|
|
7
24
|
loadConfig: () => Promise<unknown>;
|
|
@@ -10,4 +27,9 @@ export declare function runArc3Play(write: (s: string) => void, opts: {
|
|
|
10
27
|
apiKey: string;
|
|
11
28
|
model: string;
|
|
12
29
|
} | undefined;
|
|
13
|
-
}): Promise<
|
|
30
|
+
}): Promise<{
|
|
31
|
+
trajectoryId: string;
|
|
32
|
+
levelsCompleted: number;
|
|
33
|
+
levelCount: number;
|
|
34
|
+
actions: number;
|
|
35
|
+
} | null>;
|
package/dist/arc3-play.js
CHANGED
|
@@ -1,7 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hmharness/cli - `hmh cognitive play --env=arc3` (blueprint §14 finale)
|
|
3
|
+
*
|
|
4
|
+
* The LLM PLAYS the game for real: each step renders the frame pair to a
|
|
5
|
+
* PNG, the vision model looks at it, reasons about which action to take,
|
|
6
|
+
* and the choice (with the model's own words as `reasoning`) goes to the
|
|
7
|
+
* official API. Every step lands in the cognitive trajectory — ARC-AGI-3's
|
|
8
|
+
* replay and our world model share the same evidence.
|
|
9
|
+
*/
|
|
1
10
|
const GREEN = (s) => `\x1b[32m${s}\x1b[0m`;
|
|
2
11
|
const RED = (s) => `\x1b[31m${s}\x1b[0m`;
|
|
3
12
|
const DIM = (s) => `\x1b[2m${s}\x1b[0m`;
|
|
4
13
|
const YELLOW = (s) => `\x1b[33m${s}\x1b[0m`;
|
|
14
|
+
/**
|
|
15
|
+
* §26 final research question, measured: with the SAME model and the SAME
|
|
16
|
+
* game, how much does the cognitive layer (world-model beliefs + distilled
|
|
17
|
+
* lessons injected into the prompt) contribute vs a bare prompt?
|
|
18
|
+
*
|
|
19
|
+
* arm A (cognitive): play with cognitive context
|
|
20
|
+
* arm B (bare): play with the context stripped — same model, same game
|
|
21
|
+
*
|
|
22
|
+
* Both runs land as trajectories; the delta is the HARNESS's contribution
|
|
23
|
+
* (the model was never touched). Recorded to cognitive/ablation.jsonl.
|
|
24
|
+
*/
|
|
25
|
+
export async function runArc3Ablation(write, opts, deps) {
|
|
26
|
+
const { appendFile, mkdir } = await import('node:fs/promises');
|
|
27
|
+
const { join } = await import('node:path');
|
|
28
|
+
const home = deps.home();
|
|
29
|
+
// lock ONE game for both arms (games[0] ordering is not stable across calls)
|
|
30
|
+
let gameId = opts.game;
|
|
31
|
+
if (!gameId) {
|
|
32
|
+
const { Arc3RestBridge } = await import('@hmharness/environments');
|
|
33
|
+
const games = await new Arc3RestBridge().listGames();
|
|
34
|
+
gameId = games[0]?.game_id ?? '';
|
|
35
|
+
}
|
|
36
|
+
write(`消融实验 · 相同模型 · 相同游戏 ${gameId} · ${opts.steps} 步/臂(§26: harness 增益几何?)\n`);
|
|
37
|
+
const withCognitive = await runArc3Play((s) => write(s.replace(/^/, ' ')), { ...opts, game: gameId, quiet: false, bare: false }, deps);
|
|
38
|
+
write('\n ——— 裸提示词臂 ———\n');
|
|
39
|
+
const bare = await runArc3Play((s) => write(s.replace(/^/, ' ')), { ...opts, game: gameId, quiet: false, bare: true }, deps);
|
|
40
|
+
if (!withCognitive || !bare) {
|
|
41
|
+
write('(实验失败)\n');
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const record = {
|
|
45
|
+
at: new Date().toISOString(),
|
|
46
|
+
game: gameId,
|
|
47
|
+
steps: opts.steps,
|
|
48
|
+
withCognitive: { levels: withCognitive.levelsCompleted, actions: withCognitive.actions, trajectoryId: withCognitive.trajectoryId },
|
|
49
|
+
bare: { levels: bare.levelsCompleted, actions: bare.actions, trajectoryId: bare.trajectoryId },
|
|
50
|
+
harnessDeltaLevels: withCognitive.levelsCompleted - bare.levelsCompleted,
|
|
51
|
+
};
|
|
52
|
+
await mkdir(join(home, 'cognitive'), { recursive: true }).catch(() => undefined);
|
|
53
|
+
await appendFile(join(home, 'cognitive', 'ablation.jsonl'), JSON.stringify(record) + '\n', 'utf8').catch(() => undefined);
|
|
54
|
+
write(`\n结论 · 认知层 ${withCognitive.levelsCompleted} 关 vs 裸提示词 ${bare.levelsCompleted} 关 → harness 净贡献 ${record.harnessDeltaLevels >= 0 ? '+' : ''}${record.harnessDeltaLevels} 关\n`);
|
|
55
|
+
write(`(样本=${opts.steps} 步/臂,单次实验;多次运行后 cognitive/ablation.jsonl 聚合更可靠)\n`);
|
|
56
|
+
}
|
|
5
57
|
export async function runArc3Play(write, opts, deps) {
|
|
6
58
|
const home = deps.home();
|
|
7
59
|
const { Arc3RestBridge, Arc3Environment, renderFramePng } = await import('@hmharness/environments');
|
|
@@ -11,13 +63,35 @@ export async function runArc3Play(write, opts, deps) {
|
|
|
11
63
|
const games = await bridge.listGames();
|
|
12
64
|
if (games.length === 0) {
|
|
13
65
|
write('(API 未返回游戏)\n');
|
|
14
|
-
return;
|
|
66
|
+
return null;
|
|
15
67
|
}
|
|
16
68
|
const game = opts.game ? games.find((g) => g.game_id.startsWith(opts.game)) : undefined;
|
|
17
69
|
const gameId = game?.game_id ?? games[0].game_id;
|
|
18
|
-
|
|
70
|
+
if (!opts.quiet)
|
|
71
|
+
write(`ARC-AGI-3 对局 · ${gameId}(共 ${games.length} 个游戏可选)· ${opts.steps} 步${opts.vision === false ? ' · 无视觉' : ' · 视觉推理'}${opts.bare ? ' · 裸提示词(消融臂)' : ''}\n`);
|
|
19
72
|
const env = new Arc3Environment({ bridge, gameId });
|
|
20
73
|
const rec = new TrajectoryRecorder(`trj-arc3-play-${Date.now().toString(36)}`, `arc3-${gameId}`, { id: 'arc3', version: '1.0.0' }, { id: 'goal-arc3', description: `complete levels in game ${gameId}` });
|
|
74
|
+
// cognitive context (blueprint M3 for ARC): arc3 world-model beliefs +
|
|
75
|
+
// lessons distilled from earlier plays — the ablation's "with" arm injects
|
|
76
|
+
// this into the prompt; the bare arm sees none of it
|
|
77
|
+
let cognitiveNote = '';
|
|
78
|
+
if (!opts.bare) {
|
|
79
|
+
try {
|
|
80
|
+
const { analyzeWorldModel } = await import('@hmharness/cognitive');
|
|
81
|
+
const wm = await analyzeWorldModel(home, 'arc3');
|
|
82
|
+
const beliefs = wm.beliefs.filter((b) => b.actionType.startsWith('ACTION')).slice(0, 5);
|
|
83
|
+
const mem = new CognitiveMemory(home);
|
|
84
|
+
await mem.load();
|
|
85
|
+
const lessons = mem.retrieve({ layer: 'episodic', text: 'ARC3', limit: 3 }).map((e) => e.content.slice(0, 90));
|
|
86
|
+
const parts = [];
|
|
87
|
+
if (beliefs.length)
|
|
88
|
+
parts.push(`Historical action outcomes on ARC games: ${beliefs.map((b) => `${b.actionType} ${Math.round(b.confidence * 100)}% reliable (n=${b.evidenceCount})`).join(', ')}.`);
|
|
89
|
+
if (lessons.length)
|
|
90
|
+
parts.push(`Lessons from earlier ARC plays: ${lessons.join(' | ')}`);
|
|
91
|
+
cognitiveNote = parts.length ? `\nCognitive context from past runs:\n${parts.join('\n')}\n` : '';
|
|
92
|
+
}
|
|
93
|
+
catch { /* context is best-effort; bare prompt still works */ }
|
|
94
|
+
}
|
|
21
95
|
const cfg = await deps.loadConfig();
|
|
22
96
|
const visionProvider = deps.resolveProvider(cfg, 'vision') ?? deps.resolveProvider(cfg, 'chat');
|
|
23
97
|
const obs = await env.reset();
|
|
@@ -37,7 +111,8 @@ export async function runArc3Play(write, opts, deps) {
|
|
|
37
111
|
const dataUrl = `data:image/png;base64,${png.toString('base64')}`;
|
|
38
112
|
const prompt = `You are playing an ARC-AGI-3 game (${gameId}). The image shows the game grid(s) side by side. ` +
|
|
39
113
|
`Available actions: ${actions.join(', ')}${actions.includes('ACTION6') ? ' (ACTION6 needs x,y on the grid; estimate from the image)' : ''}. ` +
|
|
40
|
-
`Recent moves: ${history.slice(-5).join('; ') || '(none)'}
|
|
114
|
+
`Recent moves: ${history.slice(-5).join('; ') || '(none)'}.` +
|
|
115
|
+
cognitiveNote +
|
|
41
116
|
`Reason briefly about what the game wants, then answer with EXACTLY one line first: ACTION<n> or ACTION6 x,y`;
|
|
42
117
|
try {
|
|
43
118
|
const answer = await kernel.chatVision(visionProvider, prompt, dataUrl, { maxTokens: 1500 });
|
|
@@ -70,8 +145,9 @@ export async function runArc3Play(write, opts, deps) {
|
|
|
70
145
|
const out = (r.output ?? {});
|
|
71
146
|
history.push(`${actionType}${actionType === 'ACTION6' ? `(${args.x},${args.y})` : ''}→${r.outcome}${out.levelProgressed ? '+LEVEL' : ''}`);
|
|
72
147
|
rec.record({ action: { id: `s${step}`, type: actionType, args, reason }, outcome: r.outcome, evidence: [`arc3:${gameId}`], durationMs: Date.now() - started });
|
|
73
|
-
|
|
74
|
-
|
|
148
|
+
if (!opts.quiet)
|
|
149
|
+
write(` ${String(step).padStart(3)} ${actionType.padEnd(8)} ${r.outcome === 'success' ? GREEN('✓') : RED('✗')} 关卡 ${out.levelsCompleted ?? '?'}${out.levelProgressed ? GREEN(' ↑') : ''}\n`);
|
|
150
|
+
if (!opts.quiet && r.outcome === 'failure' && r.error)
|
|
75
151
|
write(DIM(` ${r.error.code}: ${r.error.message.slice(0, 80)}\n`));
|
|
76
152
|
}
|
|
77
153
|
const score = await env.evaluate();
|
|
@@ -91,6 +167,14 @@ export async function runArc3Play(write, opts, deps) {
|
|
|
91
167
|
tags: ['arc3', 'play'],
|
|
92
168
|
}).catch(() => undefined);
|
|
93
169
|
await env.close();
|
|
94
|
-
|
|
95
|
-
|
|
170
|
+
if (!opts.quiet) {
|
|
171
|
+
write(`对局结束 · 官方记分卡: ${score.metrics.levelsCompleted}/${score.metrics.levelCount} 关 · ${score.metrics.actions} 动作\n`);
|
|
172
|
+
write(`轨迹 ${traj.id} 已落盘(面板可回放每步+模型推理)\n`);
|
|
173
|
+
}
|
|
174
|
+
return {
|
|
175
|
+
trajectoryId: traj.id,
|
|
176
|
+
levelsCompleted: Number(score.metrics.levelsCompleted ?? 0),
|
|
177
|
+
levelCount: Number(score.metrics.levelCount ?? 0),
|
|
178
|
+
actions: Number(score.metrics.actions ?? opts.steps),
|
|
179
|
+
};
|
|
96
180
|
}
|
package/dist/main.js
CHANGED
|
@@ -931,9 +931,25 @@ flags:
|
|
|
931
931
|
return;
|
|
932
932
|
}
|
|
933
933
|
if (sub === 'bench') {
|
|
934
|
-
// BENCH seed: uniform metrics over recorded runs
|
|
934
|
+
// BENCH seed + ARC-005: uniform metrics over recorded runs; ARC variant
|
|
935
|
+
// adds action/exploration efficiency + recovery per play
|
|
936
|
+
const benchEnv = rest.find((a) => a.startsWith('--env='))?.slice(6) ?? 'terminal';
|
|
937
|
+
if (benchEnv === 'arc3') {
|
|
938
|
+
const { arc3Metrics } = await import('@hmharness/cognitive');
|
|
939
|
+
const r = await arc3Metrics(homeDir());
|
|
940
|
+
if (!r) {
|
|
941
|
+
stdout.write('(尚无 ARC 对局——hmh cognitive play --env=arc3 后再来)\n');
|
|
942
|
+
return;
|
|
943
|
+
}
|
|
944
|
+
stdout.write(`ARC-AGI-3 指标 · ${r.plays} 次对局 · 共 ${r.totalActions} 动作 · 过关 ${r.totalLevelsCompleted}\n`);
|
|
945
|
+
stdout.write(` 动作效率 ${r.meanActionEfficiency}(关/动作)· 探索效率 ${r.meanExplorationEfficiency}(动作空间覆盖/7)· 恢复率 ${r.meanRecoveryRate}\n`);
|
|
946
|
+
for (const p of r.perPlay.slice(-5)) {
|
|
947
|
+
stdout.write(` ${p.trajectoryId.slice(0, 30).padEnd(32)} ${String(p.actions).padStart(3)} 动作 ${p.levelsCompleted}/${p.levelCount} 关 · 效率 ${p.actionEfficiency}\n`);
|
|
948
|
+
}
|
|
949
|
+
return;
|
|
950
|
+
}
|
|
935
951
|
const { benchFromTrajectories } = await import('@hmharness/cognitive');
|
|
936
|
-
const report = await benchFromTrajectories(homeDir());
|
|
952
|
+
const report = await benchFromTrajectories(homeDir(), benchEnv);
|
|
937
953
|
if (!report) {
|
|
938
954
|
stdout.write('(尚无轨迹——跑几次任务后再来)\n');
|
|
939
955
|
return;
|
|
@@ -1173,8 +1189,26 @@ flags:
|
|
|
1173
1189
|
}, { home: hd, loadConfig: lc, resolveProvider: rp });
|
|
1174
1190
|
return;
|
|
1175
1191
|
}
|
|
1192
|
+
if (sub === 'ablate') {
|
|
1193
|
+
// blueprint §26 final question, measured: same model, same game —
|
|
1194
|
+
// how much does the cognitive layer contribute vs a bare prompt?
|
|
1195
|
+
if (!rest.includes('--env=arc3')) {
|
|
1196
|
+
stdout.write('用法: hmh cognitive ablate --env=arc3 [--game=<id前缀>] [--steps=N]\n');
|
|
1197
|
+
stdout.write(DIM(' 双臂对照: 认知层(世界模型信念+经验教训) vs 裸提示词; 结果落 cognitive/ablation.jsonl\n'));
|
|
1198
|
+
return;
|
|
1199
|
+
}
|
|
1200
|
+
const steps = Number(rest.find((a) => a.startsWith('--steps='))?.slice(8) ?? 5);
|
|
1201
|
+
const game = rest.find((a) => a.startsWith('--game='))?.slice(7);
|
|
1202
|
+
const { runArc3Ablation } = await import("./arc3-play.js");
|
|
1203
|
+
const { loadConfig: lc, resolveProvider: rp, homeDir: hd } = await import('@hmharness/kernel');
|
|
1204
|
+
await runArc3Ablation((s) => stdout.write(s), {
|
|
1205
|
+
game,
|
|
1206
|
+
steps: Number.isFinite(steps) ? Math.min(Math.max(steps, 2), 15) : 5,
|
|
1207
|
+
}, { home: hd, loadConfig: lc, resolveProvider: rp });
|
|
1208
|
+
return;
|
|
1209
|
+
}
|
|
1176
1210
|
if (sub !== 'status') {
|
|
1177
|
-
stdout.write('用法: hmh cognitive status|world-model|diagnose|bench|drift|skills|explore|transfer|team|learn|replay|export|purge|play — 认知子系统与世界模型\n');
|
|
1211
|
+
stdout.write('用法: hmh cognitive status|world-model|diagnose|bench|drift|skills|explore|transfer|team|learn|replay|export|purge|play|ablate — 认知子系统与世界模型\n');
|
|
1178
1212
|
return;
|
|
1179
1213
|
}
|
|
1180
1214
|
const { cognitiveStatus, formatCognitiveStatus } = await import('@hmharness/cognitive');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hmharness/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0",
|
|
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.
|
|
47
|
-
"@hmharness/cognitive": "0.
|
|
48
|
-
"@hmharness/domain-harmony": "0.
|
|
49
|
-
"@hmharness/domain-ops": "0.
|
|
50
|
-
"@hmharness/environments": "0.
|
|
51
|
-
"@hmharness/evaluation": "0.
|
|
52
|
-
"@hmharness/evolution": "0.
|
|
53
|
-
"@hmharness/kernel": "0.
|
|
54
|
-
"@hmharness/observability": "0.
|
|
55
|
-
"@hmharness/sandbox": "0.
|
|
56
|
-
"@hmharness/web": "0.
|
|
46
|
+
"@hmharness/agent": "0.21.0",
|
|
47
|
+
"@hmharness/cognitive": "0.21.0",
|
|
48
|
+
"@hmharness/domain-harmony": "0.21.0",
|
|
49
|
+
"@hmharness/domain-ops": "0.21.0",
|
|
50
|
+
"@hmharness/environments": "0.21.0",
|
|
51
|
+
"@hmharness/evaluation": "0.21.0",
|
|
52
|
+
"@hmharness/evolution": "0.21.0",
|
|
53
|
+
"@hmharness/kernel": "0.21.0",
|
|
54
|
+
"@hmharness/observability": "0.21.0",
|
|
55
|
+
"@hmharness/sandbox": "0.21.0",
|
|
56
|
+
"@hmharness/web": "0.21.0",
|
|
57
57
|
"qrcode": "^1.5.4"
|
|
58
58
|
}
|
|
59
59
|
}
|