@hmharness/cli 0.20.3 → 0.21.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.
- package/dist/arc3-play.d.ts +24 -1
- package/dist/arc3-play.js +95 -7
- package/dist/main.js +45 -1
- 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,10 @@ 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
|
+
distinctActions: number;
|
|
36
|
+
} | null>;
|
package/dist/arc3-play.js
CHANGED
|
@@ -1,7 +1,61 @@
|
|
|
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, distinctActions: withCognitive.distinctActions, trajectoryId: withCognitive.trajectoryId },
|
|
49
|
+
bare: { levels: bare.levelsCompleted, actions: bare.actions, distinctActions: bare.distinctActions, trajectoryId: bare.trajectoryId },
|
|
50
|
+
harnessDeltaLevels: withCognitive.levelsCompleted - bare.levelsCompleted,
|
|
51
|
+
harnessDeltaDiversity: withCognitive.distinctActions - bare.distinctActions,
|
|
52
|
+
};
|
|
53
|
+
await mkdir(join(home, 'cognitive'), { recursive: true }).catch(() => undefined);
|
|
54
|
+
await appendFile(join(home, 'cognitive', 'ablation.jsonl'), JSON.stringify(record) + '\n', 'utf8').catch(() => undefined);
|
|
55
|
+
write(`\n结论 · 认知层 ${withCognitive.levelsCompleted} 关 vs 裸提示词 ${bare.levelsCompleted} 关 → harness 净贡献 ${record.harnessDeltaLevels >= 0 ? '+' : ''}${record.harnessDeltaLevels} 关\n`);
|
|
56
|
+
write(` 动作多样性 认知层 ${withCognitive.distinctActions} 种 vs 裸 ${bare.distinctActions} 种(关卡持平时行为差异信号)\n`);
|
|
57
|
+
write(`(样本=${opts.steps} 步/臂,单次实验;多次运行后 cognitive/ablation.jsonl 聚合更可靠)\n`);
|
|
58
|
+
}
|
|
5
59
|
export async function runArc3Play(write, opts, deps) {
|
|
6
60
|
const home = deps.home();
|
|
7
61
|
const { Arc3RestBridge, Arc3Environment, renderFramePng } = await import('@hmharness/environments');
|
|
@@ -11,13 +65,35 @@ export async function runArc3Play(write, opts, deps) {
|
|
|
11
65
|
const games = await bridge.listGames();
|
|
12
66
|
if (games.length === 0) {
|
|
13
67
|
write('(API 未返回游戏)\n');
|
|
14
|
-
return;
|
|
68
|
+
return null;
|
|
15
69
|
}
|
|
16
70
|
const game = opts.game ? games.find((g) => g.game_id.startsWith(opts.game)) : undefined;
|
|
17
71
|
const gameId = game?.game_id ?? games[0].game_id;
|
|
18
|
-
|
|
72
|
+
if (!opts.quiet)
|
|
73
|
+
write(`ARC-AGI-3 对局 · ${gameId}(共 ${games.length} 个游戏可选)· ${opts.steps} 步${opts.vision === false ? ' · 无视觉' : ' · 视觉推理'}${opts.bare ? ' · 裸提示词(消融臂)' : ''}\n`);
|
|
19
74
|
const env = new Arc3Environment({ bridge, gameId });
|
|
20
75
|
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}` });
|
|
76
|
+
// cognitive context (blueprint M3 for ARC): arc3 world-model beliefs +
|
|
77
|
+
// lessons distilled from earlier plays — the ablation's "with" arm injects
|
|
78
|
+
// this into the prompt; the bare arm sees none of it
|
|
79
|
+
let cognitiveNote = '';
|
|
80
|
+
if (!opts.bare) {
|
|
81
|
+
try {
|
|
82
|
+
const { analyzeWorldModel } = await import('@hmharness/cognitive');
|
|
83
|
+
const wm = await analyzeWorldModel(home, 'arc3');
|
|
84
|
+
const beliefs = wm.beliefs.filter((b) => b.actionType.startsWith('ACTION')).slice(0, 5);
|
|
85
|
+
const mem = new CognitiveMemory(home);
|
|
86
|
+
await mem.load();
|
|
87
|
+
const lessons = mem.retrieve({ layer: 'episodic', text: 'ARC3', limit: 3 }).map((e) => e.content.slice(0, 90));
|
|
88
|
+
const parts = [];
|
|
89
|
+
if (beliefs.length)
|
|
90
|
+
parts.push(`Historical action outcomes on ARC games: ${beliefs.map((b) => `${b.actionType} ${Math.round(b.confidence * 100)}% reliable (n=${b.evidenceCount})`).join(', ')}.`);
|
|
91
|
+
if (lessons.length)
|
|
92
|
+
parts.push(`Lessons from earlier ARC plays: ${lessons.join(' | ')}`);
|
|
93
|
+
cognitiveNote = parts.length ? `\nCognitive context from past runs:\n${parts.join('\n')}\n` : '';
|
|
94
|
+
}
|
|
95
|
+
catch { /* context is best-effort; bare prompt still works */ }
|
|
96
|
+
}
|
|
21
97
|
const cfg = await deps.loadConfig();
|
|
22
98
|
const visionProvider = deps.resolveProvider(cfg, 'vision') ?? deps.resolveProvider(cfg, 'chat');
|
|
23
99
|
const obs = await env.reset();
|
|
@@ -37,7 +113,8 @@ export async function runArc3Play(write, opts, deps) {
|
|
|
37
113
|
const dataUrl = `data:image/png;base64,${png.toString('base64')}`;
|
|
38
114
|
const prompt = `You are playing an ARC-AGI-3 game (${gameId}). The image shows the game grid(s) side by side. ` +
|
|
39
115
|
`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)'}
|
|
116
|
+
`Recent moves: ${history.slice(-5).join('; ') || '(none)'}.` +
|
|
117
|
+
cognitiveNote +
|
|
41
118
|
`Reason briefly about what the game wants, then answer with EXACTLY one line first: ACTION<n> or ACTION6 x,y`;
|
|
42
119
|
try {
|
|
43
120
|
const answer = await kernel.chatVision(visionProvider, prompt, dataUrl, { maxTokens: 1500 });
|
|
@@ -70,13 +147,15 @@ export async function runArc3Play(write, opts, deps) {
|
|
|
70
147
|
const out = (r.output ?? {});
|
|
71
148
|
history.push(`${actionType}${actionType === 'ACTION6' ? `(${args.x},${args.y})` : ''}→${r.outcome}${out.levelProgressed ? '+LEVEL' : ''}`);
|
|
72
149
|
rec.record({ action: { id: `s${step}`, type: actionType, args, reason }, outcome: r.outcome, evidence: [`arc3:${gameId}`], durationMs: Date.now() - started });
|
|
73
|
-
|
|
74
|
-
|
|
150
|
+
if (!opts.quiet)
|
|
151
|
+
write(` ${String(step).padStart(3)} ${actionType.padEnd(8)} ${r.outcome === 'success' ? GREEN('✓') : RED('✗')} 关卡 ${out.levelsCompleted ?? '?'}${out.levelProgressed ? GREEN(' ↑') : ''}\n`);
|
|
152
|
+
if (!opts.quiet && r.outcome === 'failure' && r.error)
|
|
75
153
|
write(DIM(` ${r.error.code}: ${r.error.message.slice(0, 80)}\n`));
|
|
76
154
|
}
|
|
77
155
|
const score = await env.evaluate();
|
|
78
156
|
const traj = rec.finish(Number(score.metrics.levelsCompleted ?? 0) > state0.levelsCompleted);
|
|
79
157
|
await new TrajectoryStore(home).append(traj);
|
|
158
|
+
const distinctActions = new Set(traj.steps.map((s) => s.action.type)).size;
|
|
80
159
|
const mem = new CognitiveMemory(home);
|
|
81
160
|
await mem.load();
|
|
82
161
|
await mem.write({
|
|
@@ -91,6 +170,15 @@ export async function runArc3Play(write, opts, deps) {
|
|
|
91
170
|
tags: ['arc3', 'play'],
|
|
92
171
|
}).catch(() => undefined);
|
|
93
172
|
await env.close();
|
|
94
|
-
|
|
95
|
-
|
|
173
|
+
if (!opts.quiet) {
|
|
174
|
+
write(`对局结束 · 官方记分卡: ${score.metrics.levelsCompleted}/${score.metrics.levelCount} 关 · ${score.metrics.actions} 动作\n`);
|
|
175
|
+
write(`轨迹 ${traj.id} 已落盘(面板可回放每步+模型推理)\n`);
|
|
176
|
+
}
|
|
177
|
+
return {
|
|
178
|
+
trajectoryId: traj.id,
|
|
179
|
+
levelsCompleted: Number(score.metrics.levelsCompleted ?? 0),
|
|
180
|
+
levelCount: Number(score.metrics.levelCount ?? 0),
|
|
181
|
+
actions: Number(score.metrics.actions ?? opts.steps),
|
|
182
|
+
distinctActions,
|
|
183
|
+
};
|
|
96
184
|
}
|
package/dist/main.js
CHANGED
|
@@ -1189,8 +1189,52 @@ flags:
|
|
|
1189
1189
|
}, { home: hd, loadConfig: lc, resolveProvider: rp });
|
|
1190
1190
|
return;
|
|
1191
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
|
+
const { readFile } = await import('node:fs/promises');
|
|
1196
|
+
const { join: j } = await import('node:path');
|
|
1197
|
+
if (rest.includes('--stats')) {
|
|
1198
|
+
try {
|
|
1199
|
+
const text = await readFile(j(homeDir(), 'cognitive', 'ablation.jsonl'), 'utf8');
|
|
1200
|
+
const rows = text.split('\n').filter((l) => l.trim()).map((l) => JSON.parse(l));
|
|
1201
|
+
if (rows.length === 0) {
|
|
1202
|
+
stdout.write('(暂无消融记录——先跑 hmh cognitive ablate --env=arc3)\n');
|
|
1203
|
+
return;
|
|
1204
|
+
}
|
|
1205
|
+
const avg = (pick) => {
|
|
1206
|
+
const vals = rows.map(pick).filter((v) => Number.isFinite(v));
|
|
1207
|
+
return vals.length ? Number((vals.reduce((s, v) => s + v, 0) / vals.length).toFixed(2)) : Number.NaN;
|
|
1208
|
+
};
|
|
1209
|
+
stdout.write(`消融聚合 · ${rows.length} 次实验 · 平均 ${avg((r) => r.steps)} 步/臂\n`);
|
|
1210
|
+
stdout.write(` 关卡净贡献均值 ${avg((r) => r.harnessDeltaLevels)} · 动作多样性净贡献均值 ${avg((r) => r.harnessDeltaDiversity ?? Number.NaN)}\n`);
|
|
1211
|
+
const pos = rows.filter((r) => r.harnessDeltaLevels > 0).length;
|
|
1212
|
+
const neg = rows.filter((r) => r.harnessDeltaLevels < 0).length;
|
|
1213
|
+
stdout.write(` 关卡贡献分布: 正 ${pos} / 持平 ${rows.length - pos - neg} / 负 ${neg}\n`);
|
|
1214
|
+
stdout.write(DIM(' 关卡持平是常态(ARC 难度);多样性与后续关卡增益随样本累积显现\n'));
|
|
1215
|
+
}
|
|
1216
|
+
catch {
|
|
1217
|
+
stdout.write('(暂无消融记录——先跑 hmh cognitive ablate --env=arc3)\n');
|
|
1218
|
+
}
|
|
1219
|
+
return;
|
|
1220
|
+
}
|
|
1221
|
+
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'));
|
|
1224
|
+
return;
|
|
1225
|
+
}
|
|
1226
|
+
const steps = Number(rest.find((a) => a.startsWith('--steps='))?.slice(8) ?? 5);
|
|
1227
|
+
const game = rest.find((a) => a.startsWith('--game='))?.slice(7);
|
|
1228
|
+
const { runArc3Ablation } = await import("./arc3-play.js");
|
|
1229
|
+
const { loadConfig: lc, resolveProvider: rp, homeDir: hd } = await import('@hmharness/kernel');
|
|
1230
|
+
await runArc3Ablation((s) => stdout.write(s), {
|
|
1231
|
+
game,
|
|
1232
|
+
steps: Number.isFinite(steps) ? Math.min(Math.max(steps, 2), 15) : 5,
|
|
1233
|
+
}, { home: hd, loadConfig: lc, resolveProvider: rp });
|
|
1234
|
+
return;
|
|
1235
|
+
}
|
|
1192
1236
|
if (sub !== 'status') {
|
|
1193
|
-
stdout.write('用法: hmh cognitive status|world-model|diagnose|bench|drift|skills|explore|transfer|team|learn|replay|export|purge|play — 认知子系统与世界模型\n');
|
|
1237
|
+
stdout.write('用法: hmh cognitive status|world-model|diagnose|bench|drift|skills|explore|transfer|team|learn|replay|export|purge|play|ablate — 认知子系统与世界模型\n');
|
|
1194
1238
|
return;
|
|
1195
1239
|
}
|
|
1196
1240
|
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.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.
|
|
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.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",
|
|
57
57
|
"qrcode": "^1.5.4"
|
|
58
58
|
}
|
|
59
59
|
}
|