@hmharness/cli 0.20.0 → 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 +34 -11
- 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
|
@@ -997,13 +997,16 @@ flags:
|
|
|
997
997
|
await mkdir(scratch, { recursive: true });
|
|
998
998
|
try {
|
|
999
999
|
const { runExploration } = await import('@hmharness/cognitive');
|
|
1000
|
-
const { TerminalEnvironment, HarmonyOsEnvironment } = await import('@hmharness/environments');
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1000
|
+
const { TerminalEnvironment, HarmonyOsEnvironment, Arc3Environment, Arc3RestBridge } = await import('@hmharness/environments');
|
|
1001
|
+
let env;
|
|
1002
|
+
if (envId === 'harmonyos')
|
|
1003
|
+
env = new HarmonyOsEnvironment({ timeoutMs: 20_000 });
|
|
1004
|
+
else if (envId === 'arc3')
|
|
1005
|
+
env = new Arc3Environment({ bridge: new Arc3RestBridge() });
|
|
1006
|
+
else if (envId === 'terminal')
|
|
1007
|
+
env = new TerminalEnvironment({ workspaceDir: scratch, timeoutMs: 15_000 });
|
|
1005
1008
|
if (!env) {
|
|
1006
|
-
stdout.write(`环境 '${envId}' 暂不支持 headless 探索(terminal | harmonyos)\n`);
|
|
1009
|
+
stdout.write(`环境 '${envId}' 暂不支持 headless 探索(terminal | harmonyos | arc3)\n`);
|
|
1007
1010
|
return;
|
|
1008
1011
|
}
|
|
1009
1012
|
const summary = await runExploration(home, {
|
|
@@ -1044,13 +1047,15 @@ flags:
|
|
|
1044
1047
|
await mkdir(scratch, { recursive: true });
|
|
1045
1048
|
try {
|
|
1046
1049
|
const { runTransferExperiment } = await import('@hmharness/cognitive');
|
|
1047
|
-
const { TerminalEnvironment, HarmonyOsEnvironment } = await import('@hmharness/environments');
|
|
1050
|
+
const { TerminalEnvironment, HarmonyOsEnvironment, Arc3Environment, Arc3RestBridge } = await import('@hmharness/environments');
|
|
1048
1051
|
const makeEnv = target === 'harmonyos'
|
|
1049
1052
|
? () => new HarmonyOsEnvironment({ timeoutMs: 20_000 })
|
|
1050
|
-
: target === '
|
|
1051
|
-
:
|
|
1053
|
+
: target === 'arc3'
|
|
1054
|
+
? () => new Arc3Environment({ bridge: new Arc3RestBridge() })
|
|
1055
|
+
: target === 'terminal' ? () => new TerminalEnvironment({ workspaceDir: join(scratch, `t-${Date.now().toString(36)}`), timeoutMs: 15_000 })
|
|
1056
|
+
: null;
|
|
1052
1057
|
if (!makeEnv) {
|
|
1053
|
-
stdout.write(`目标环境 '${target}' 暂不支持(terminal | harmonyos)\n`);
|
|
1058
|
+
stdout.write(`目标环境 '${target}' 暂不支持(terminal | harmonyos | arc3)\n`);
|
|
1054
1059
|
return;
|
|
1055
1060
|
}
|
|
1056
1061
|
const report = await runTransferExperiment(home, {
|
|
@@ -1150,8 +1155,26 @@ flags:
|
|
|
1150
1155
|
stdout.write(`已删除: ${r.removed.join(', ')}\n`);
|
|
1151
1156
|
return;
|
|
1152
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
|
+
}
|
|
1153
1176
|
if (sub !== 'status') {
|
|
1154
|
-
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');
|
|
1155
1178
|
return;
|
|
1156
1179
|
}
|
|
1157
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
|
}
|