@hmharness/cli 0.20.1 → 0.20.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.
- package/dist/arc3-play.d.ts +13 -0
- package/dist/arc3-play.js +96 -0
- package/dist/main.js +19 -1
- 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
|
@@ -1155,8 +1155,26 @@ flags:
|
|
|
1155
1155
|
stdout.write(`已删除: ${r.removed.join(', ')}\n`);
|
|
1156
1156
|
return;
|
|
1157
1157
|
}
|
|
1158
|
+
if (sub === 'play') {
|
|
1159
|
+
// blueprint §14 finale: the LLM plays an ARC-AGI-3 game for real
|
|
1160
|
+
// (vision renders the frame, the model reasons, actions carry reasoning)
|
|
1161
|
+
if (!rest.includes('--env=arc3')) {
|
|
1162
|
+
stdout.write('用法: hmh cognitive play --env=arc3 [--game=<id前缀>] [--steps=N] [--no-vision]\n');
|
|
1163
|
+
return;
|
|
1164
|
+
}
|
|
1165
|
+
const steps = Number(rest.find((a) => a.startsWith('--steps='))?.slice(8) ?? 3);
|
|
1166
|
+
const game = rest.find((a) => a.startsWith('--game='))?.slice(7);
|
|
1167
|
+
const { runArc3Play } = await import("./arc3-play.js");
|
|
1168
|
+
const { loadConfig: lc, resolveProvider: rp, homeDir: hd } = await import('@hmharness/kernel');
|
|
1169
|
+
await runArc3Play((s) => stdout.write(s), {
|
|
1170
|
+
game,
|
|
1171
|
+
steps: Number.isFinite(steps) ? Math.min(Math.max(steps, 1), 30) : 3,
|
|
1172
|
+
vision: !rest.includes('--no-vision'),
|
|
1173
|
+
}, { home: hd, loadConfig: lc, resolveProvider: rp });
|
|
1174
|
+
return;
|
|
1175
|
+
}
|
|
1158
1176
|
if (sub !== 'status') {
|
|
1159
|
-
stdout.write('用法: hmh cognitive status|world-model|diagnose|bench|drift|skills|explore|transfer|team|learn|replay|export|purge — 认知子系统与世界模型\n');
|
|
1177
|
+
stdout.write('用法: hmh cognitive status|world-model|diagnose|bench|drift|skills|explore|transfer|team|learn|replay|export|purge|play — 认知子系统与世界模型\n');
|
|
1160
1178
|
return;
|
|
1161
1179
|
}
|
|
1162
1180
|
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.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.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.2",
|
|
47
|
+
"@hmharness/cognitive": "0.20.2",
|
|
48
|
+
"@hmharness/domain-harmony": "0.20.2",
|
|
49
|
+
"@hmharness/domain-ops": "0.20.2",
|
|
50
|
+
"@hmharness/environments": "0.20.2",
|
|
51
|
+
"@hmharness/evaluation": "0.20.2",
|
|
52
|
+
"@hmharness/evolution": "0.20.2",
|
|
53
|
+
"@hmharness/kernel": "0.20.2",
|
|
54
|
+
"@hmharness/observability": "0.20.2",
|
|
55
|
+
"@hmharness/sandbox": "0.20.2",
|
|
56
|
+
"@hmharness/web": "0.20.2",
|
|
57
57
|
"qrcode": "^1.5.4"
|
|
58
58
|
}
|
|
59
59
|
}
|