@hmharness/cli 0.20.1 → 0.20.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.
- package/dist/arc3-play.d.ts +13 -0
- package/dist/arc3-play.js +96 -0
- package/dist/main.js +37 -3
- package/package.json +12 -12
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare function runArc3Play(write: (s: string) => void, opts: {
|
|
2
|
+
game?: string;
|
|
3
|
+
steps: number;
|
|
4
|
+
vision?: boolean;
|
|
5
|
+
}, deps: {
|
|
6
|
+
home: () => string;
|
|
7
|
+
loadConfig: () => Promise<unknown>;
|
|
8
|
+
resolveProvider: (cfg: unknown, route: string) => {
|
|
9
|
+
baseUrl: string;
|
|
10
|
+
apiKey: string;
|
|
11
|
+
model: string;
|
|
12
|
+
} | undefined;
|
|
13
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
const GREEN = (s) => `\x1b[32m${s}\x1b[0m`;
|
|
2
|
+
const RED = (s) => `\x1b[31m${s}\x1b[0m`;
|
|
3
|
+
const DIM = (s) => `\x1b[2m${s}\x1b[0m`;
|
|
4
|
+
const YELLOW = (s) => `\x1b[33m${s}\x1b[0m`;
|
|
5
|
+
export async function runArc3Play(write, opts, deps) {
|
|
6
|
+
const home = deps.home();
|
|
7
|
+
const { Arc3RestBridge, Arc3Environment, renderFramePng } = await import('@hmharness/environments');
|
|
8
|
+
const { TrajectoryRecorder, TrajectoryStore, CognitiveMemory } = await import('@hmharness/cognitive');
|
|
9
|
+
const kernel = await import('@hmharness/kernel');
|
|
10
|
+
const bridge = new Arc3RestBridge();
|
|
11
|
+
const games = await bridge.listGames();
|
|
12
|
+
if (games.length === 0) {
|
|
13
|
+
write('(API 未返回游戏)\n');
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const game = opts.game ? games.find((g) => g.game_id.startsWith(opts.game)) : undefined;
|
|
17
|
+
const gameId = game?.game_id ?? games[0].game_id;
|
|
18
|
+
write(`ARC-AGI-3 对局 · ${gameId}(共 ${games.length} 个游戏可选)· ${opts.steps} 步${opts.vision === false ? ' · 无视觉' : ' · 视觉推理'}\n`);
|
|
19
|
+
const env = new Arc3Environment({ bridge, gameId });
|
|
20
|
+
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}` });
|
|
21
|
+
const cfg = await deps.loadConfig();
|
|
22
|
+
const visionProvider = deps.resolveProvider(cfg, 'vision') ?? deps.resolveProvider(cfg, 'chat');
|
|
23
|
+
const obs = await env.reset();
|
|
24
|
+
const state0 = obs.state;
|
|
25
|
+
write(` 开局 · 需过 ${state0.winLevels} 关,已过 ${state0.levelsCompleted}\n`);
|
|
26
|
+
const history = [];
|
|
27
|
+
for (let step = 1; step <= opts.steps; step++) {
|
|
28
|
+
const obs2 = await env.observe();
|
|
29
|
+
const raw = (obs2.raw ?? {});
|
|
30
|
+
const actions = obs2.availableActions.map((a) => a.type);
|
|
31
|
+
let actionType = actions[0];
|
|
32
|
+
let reason = 'no vision — first available action';
|
|
33
|
+
let visionNote = '';
|
|
34
|
+
if (opts.vision !== false && visionProvider?.apiKey && Array.isArray(raw.frame)) {
|
|
35
|
+
const png = renderFramePng(raw.frame, 8);
|
|
36
|
+
if (png) {
|
|
37
|
+
const dataUrl = `data:image/png;base64,${png.toString('base64')}`;
|
|
38
|
+
const prompt = `You are playing an ARC-AGI-3 game (${gameId}). The image shows the game grid(s) side by side. ` +
|
|
39
|
+
`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)'}. ` +
|
|
41
|
+
`Reason briefly about what the game wants, then answer with EXACTLY one line first: ACTION<n> or ACTION6 x,y`;
|
|
42
|
+
try {
|
|
43
|
+
const answer = await kernel.chatVision(visionProvider, prompt, dataUrl, { maxTokens: 1500 });
|
|
44
|
+
const lines = String(answer).trim().split('\n').map((l) => l.trim()).filter(Boolean);
|
|
45
|
+
const line = lines.find((l) => /ACTION\s*\d/i.test(l)) ?? '';
|
|
46
|
+
const m = line.match(/ACTION\s*6\s*[, ]*\s*(\d{1,2})\s*[, ]+\s*(\d{1,2})/i) ?? line.match(/ACTION\s*(\d)/i);
|
|
47
|
+
if (m) {
|
|
48
|
+
if (m[0].toUpperCase().includes('ACTION6') && m.length === 3) {
|
|
49
|
+
actionType = 'ACTION6';
|
|
50
|
+
opts.xy = [Number(m[1]), Number(m[2])];
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
actionType = `ACTION${m[1]}`;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
reason = (line || lines.join(' ')).slice(0, 200);
|
|
57
|
+
visionNote = DIM(` 模型: ${reason.slice(0, 90)}\n`);
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
visionNote = YELLOW(` 视觉调用失败(${String(err).slice(0, 70)}),退回首选动作\n`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
write(visionNote);
|
|
65
|
+
const xy = opts.xy;
|
|
66
|
+
delete opts.xy;
|
|
67
|
+
const args = actionType === 'ACTION6' ? { x: xy?.[0] ?? 32, y: xy?.[1] ?? 32 } : {};
|
|
68
|
+
const started = Date.now();
|
|
69
|
+
const r = await env.act({ id: `s${step}`, type: actionType, args, reason });
|
|
70
|
+
const out = (r.output ?? {});
|
|
71
|
+
history.push(`${actionType}${actionType === 'ACTION6' ? `(${args.x},${args.y})` : ''}→${r.outcome}${out.levelProgressed ? '+LEVEL' : ''}`);
|
|
72
|
+
rec.record({ action: { id: `s${step}`, type: actionType, args, reason }, outcome: r.outcome, evidence: [`arc3:${gameId}`], durationMs: Date.now() - started });
|
|
73
|
+
write(` ${String(step).padStart(3)} ${actionType.padEnd(8)} ${r.outcome === 'success' ? GREEN('✓') : RED('✗')} 关卡 ${out.levelsCompleted ?? '?'}${out.levelProgressed ? GREEN(' ↑') : ''}\n`);
|
|
74
|
+
if (r.outcome === 'failure' && r.error)
|
|
75
|
+
write(DIM(` ${r.error.code}: ${r.error.message.slice(0, 80)}\n`));
|
|
76
|
+
}
|
|
77
|
+
const score = await env.evaluate();
|
|
78
|
+
const traj = rec.finish(Number(score.metrics.levelsCompleted ?? 0) > state0.levelsCompleted);
|
|
79
|
+
await new TrajectoryStore(home).append(traj);
|
|
80
|
+
const mem = new CognitiveMemory(home);
|
|
81
|
+
await mem.load();
|
|
82
|
+
await mem.write({
|
|
83
|
+
layer: 'episodic',
|
|
84
|
+
content: `ARC3 PLAY ${gameId}: ${score.metrics.levelsCompleted}/${score.metrics.levelCount} levels in ${opts.steps} actions`,
|
|
85
|
+
payload: { trajectoryId: traj.id, gameId },
|
|
86
|
+
source: 'arc3-play',
|
|
87
|
+
provenance: `trajectory:${traj.id}`,
|
|
88
|
+
confidence: 0.8,
|
|
89
|
+
environment: 'arc3',
|
|
90
|
+
session: traj.sessionId,
|
|
91
|
+
tags: ['arc3', 'play'],
|
|
92
|
+
}).catch(() => undefined);
|
|
93
|
+
await env.close();
|
|
94
|
+
write(`对局结束 · 官方记分卡: ${score.metrics.levelsCompleted}/${score.metrics.levelCount} 关 · ${score.metrics.actions} 动作\n`);
|
|
95
|
+
write(`轨迹 ${traj.id} 已落盘(面板可回放每步+模型推理)\n`);
|
|
96
|
+
}
|
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;
|
|
@@ -1155,8 +1171,26 @@ flags:
|
|
|
1155
1171
|
stdout.write(`已删除: ${r.removed.join(', ')}\n`);
|
|
1156
1172
|
return;
|
|
1157
1173
|
}
|
|
1174
|
+
if (sub === 'play') {
|
|
1175
|
+
// blueprint §14 finale: the LLM plays an ARC-AGI-3 game for real
|
|
1176
|
+
// (vision renders the frame, the model reasons, actions carry reasoning)
|
|
1177
|
+
if (!rest.includes('--env=arc3')) {
|
|
1178
|
+
stdout.write('用法: hmh cognitive play --env=arc3 [--game=<id前缀>] [--steps=N] [--no-vision]\n');
|
|
1179
|
+
return;
|
|
1180
|
+
}
|
|
1181
|
+
const steps = Number(rest.find((a) => a.startsWith('--steps='))?.slice(8) ?? 3);
|
|
1182
|
+
const game = rest.find((a) => a.startsWith('--game='))?.slice(7);
|
|
1183
|
+
const { runArc3Play } = await import("./arc3-play.js");
|
|
1184
|
+
const { loadConfig: lc, resolveProvider: rp, homeDir: hd } = await import('@hmharness/kernel');
|
|
1185
|
+
await runArc3Play((s) => stdout.write(s), {
|
|
1186
|
+
game,
|
|
1187
|
+
steps: Number.isFinite(steps) ? Math.min(Math.max(steps, 1), 30) : 3,
|
|
1188
|
+
vision: !rest.includes('--no-vision'),
|
|
1189
|
+
}, { home: hd, loadConfig: lc, resolveProvider: rp });
|
|
1190
|
+
return;
|
|
1191
|
+
}
|
|
1158
1192
|
if (sub !== 'status') {
|
|
1159
|
-
stdout.write('用法: hmh cognitive status|world-model|diagnose|bench|drift|skills|explore|transfer|team|learn|replay|export|purge — 认知子系统与世界模型\n');
|
|
1193
|
+
stdout.write('用法: hmh cognitive status|world-model|diagnose|bench|drift|skills|explore|transfer|team|learn|replay|export|purge|play — 认知子系统与世界模型\n');
|
|
1160
1194
|
return;
|
|
1161
1195
|
}
|
|
1162
1196
|
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.20.
|
|
3
|
+
"version": "0.20.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.20.
|
|
47
|
-
"@hmharness/cognitive": "0.20.
|
|
48
|
-
"@hmharness/domain-harmony": "0.20.
|
|
49
|
-
"@hmharness/domain-ops": "0.20.
|
|
50
|
-
"@hmharness/environments": "0.20.
|
|
51
|
-
"@hmharness/evaluation": "0.20.
|
|
52
|
-
"@hmharness/evolution": "0.20.
|
|
53
|
-
"@hmharness/kernel": "0.20.
|
|
54
|
-
"@hmharness/observability": "0.20.
|
|
55
|
-
"@hmharness/sandbox": "0.20.
|
|
56
|
-
"@hmharness/web": "0.20.
|
|
46
|
+
"@hmharness/agent": "0.20.3",
|
|
47
|
+
"@hmharness/cognitive": "0.20.3",
|
|
48
|
+
"@hmharness/domain-harmony": "0.20.3",
|
|
49
|
+
"@hmharness/domain-ops": "0.20.3",
|
|
50
|
+
"@hmharness/environments": "0.20.3",
|
|
51
|
+
"@hmharness/evaluation": "0.20.3",
|
|
52
|
+
"@hmharness/evolution": "0.20.3",
|
|
53
|
+
"@hmharness/kernel": "0.20.3",
|
|
54
|
+
"@hmharness/observability": "0.20.3",
|
|
55
|
+
"@hmharness/sandbox": "0.20.3",
|
|
56
|
+
"@hmharness/web": "0.20.3",
|
|
57
57
|
"qrcode": "^1.5.4"
|
|
58
58
|
}
|
|
59
59
|
}
|