@myclaw163/clawclaw-cli 0.6.105 → 0.6.109

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myclaw163/clawclaw-cli",
3
- "version": "0.6.105",
3
+ "version": "0.6.109",
4
4
  "type": "module",
5
5
  "description": "ClawClaw social deduction game CLI",
6
6
  "bin": {
@@ -0,0 +1,164 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Add ClawClaw gameplay permissions to Claude Code's permissions.allow list.
4
+ *
5
+ * This script intentionally only edits ~/.claude/settings.json permissions.allow.
6
+ * It does not back up, revert, remove, or rewrite any other settings.
7
+ *
8
+ * Usage:
9
+ * node enable_ccl_permissions.cjs
10
+ * node enable_ccl_permissions.cjs --dry-run
11
+ */
12
+
13
+ const fs = require("fs");
14
+ const os = require("os");
15
+ const path = require("path");
16
+ const { parseArgs } = require("node:util");
17
+
18
+ const HOME = os.homedir();
19
+ const DEFAULT_SETTINGS_PATH = path.join(HOME, ".claude", "settings.json");
20
+ // Claude Code permission paths use POSIX-style separators on every platform.
21
+ // `~/` is home-relative on macOS/Linux and Windows; Edit rules also cover Write.
22
+ // The `skills` installer keeps its canonical copy under ~/.agents/skills and
23
+ // links ~/.claude/skills to it (a symlink on macOS/Linux, a junction on Windows).
24
+ // Claude Code requires both the link path and its resolved target to be allowed.
25
+ const REQUIRED_ALLOW = [
26
+ "Bash(ccl)",
27
+ "Bash(ccl *)",
28
+ "PowerShell(ccl)",
29
+ "PowerShell(ccl *)",
30
+ "Bash(clawclaw-cli)",
31
+ "Bash(clawclaw-cli *)",
32
+ "PowerShell(clawclaw-cli)",
33
+ "PowerShell(clawclaw-cli *)",
34
+ "Skill(clawclaw)",
35
+ "Skill(clawclaw *)",
36
+ "Read(~/.claude/skills/clawclaw/**)",
37
+ "Read(~/.agents/skills/clawclaw/**)",
38
+ "Edit(~/.clawclaw/user-data/accounts/**/persona.md)",
39
+ "Edit(~/.clawclaw/user-data/accounts/**/memory.md)",
40
+ "Edit(~/AppData/Roaming/clawclaw/user-data/accounts/**/persona.md)",
41
+ "Edit(~/AppData/Roaming/clawclaw/user-data/accounts/**/memory.md)",
42
+ ];
43
+
44
+ const { values: args } = parseArgs({
45
+ options: {
46
+ "dry-run": { type: "boolean", default: false },
47
+ settings: { type: "string", default: DEFAULT_SETTINGS_PATH },
48
+ },
49
+ });
50
+
51
+ function expandHome(input) {
52
+ return path.resolve(String(input).replace(/^~(?=$|[\\/])/, HOME));
53
+ }
54
+
55
+ const settingsPath = expandHome(args.settings);
56
+
57
+ function detectJsonIndent(raw) {
58
+ const match = raw.match(/\n([ \t]+)"/);
59
+ return match ? match[1] : 2;
60
+ }
61
+
62
+ function detectEol(raw) {
63
+ return raw.includes("\r\n") ? "\r\n" : "\n";
64
+ }
65
+
66
+ function formatJsonLikeOriginal(config, originalRaw) {
67
+ const hasBom = originalRaw !== null && originalRaw.charCodeAt(0) === 0xfeff;
68
+ const styleRaw = hasBom ? originalRaw.slice(1) : originalRaw;
69
+ const indent = styleRaw === null ? 2 : detectJsonIndent(styleRaw);
70
+ const eol = styleRaw === null ? "\n" : detectEol(styleRaw);
71
+ let data = JSON.stringify(config, null, indent);
72
+ if (eol !== "\n") data = data.replace(/\n/g, eol);
73
+ if (styleRaw === null || styleRaw.endsWith("\n") || styleRaw.endsWith("\r")) data += eol;
74
+ if (hasBom) data = "\ufeff" + data;
75
+ return data;
76
+ }
77
+
78
+ function loadSettings(filePath) {
79
+ if (!fs.existsSync(filePath)) {
80
+ return { settings: {}, raw: null };
81
+ }
82
+
83
+ let raw;
84
+ try {
85
+ raw = fs.readFileSync(filePath, "utf-8");
86
+ } catch (error) {
87
+ throw new Error(`Failed to read ${filePath}: ${error.message}`);
88
+ }
89
+
90
+ const jsonRaw = raw.charCodeAt(0) === 0xfeff ? raw.slice(1) : raw;
91
+ try {
92
+ return { settings: JSON.parse(jsonRaw), raw };
93
+ } catch (error) {
94
+ throw new Error(`Invalid JSON in ${filePath}: ${error.message}`);
95
+ }
96
+ }
97
+
98
+ function assertPlainObject(value, label) {
99
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
100
+ throw new Error(`${label} must be a JSON object`);
101
+ }
102
+ }
103
+
104
+ function addClawClawAllowEntries(settings) {
105
+ assertPlainObject(settings, settingsPath);
106
+
107
+ if (!("permissions" in settings)) {
108
+ settings.permissions = {};
109
+ }
110
+ assertPlainObject(settings.permissions, `${settingsPath}.permissions`);
111
+
112
+ if (!("allow" in settings.permissions)) {
113
+ settings.permissions.allow = [];
114
+ }
115
+ if (!Array.isArray(settings.permissions.allow)) {
116
+ throw new Error(`${settingsPath}.permissions.allow must be an array`);
117
+ }
118
+
119
+ const allow = settings.permissions.allow;
120
+ const missing = REQUIRED_ALLOW.filter((entry) => !allow.includes(entry));
121
+ allow.push(...missing);
122
+ return missing;
123
+ }
124
+
125
+ function saveSettings(filePath, settings, originalRaw) {
126
+ fs.mkdirSync(path.dirname(filePath), { recursive: true });
127
+ fs.writeFileSync(filePath, formatJsonLikeOriginal(settings, originalRaw), "utf-8");
128
+ }
129
+
130
+ let loaded;
131
+ try {
132
+ loaded = loadSettings(settingsPath);
133
+ } catch (error) {
134
+ console.log(`ERROR: ${error.message}`);
135
+ process.exit(1);
136
+ }
137
+
138
+ let missing;
139
+ try {
140
+ missing = addClawClawAllowEntries(loaded.settings);
141
+ } catch (error) {
142
+ console.log(`ERROR: ${error.message}`);
143
+ process.exit(1);
144
+ }
145
+
146
+ if (missing.length === 0) {
147
+ console.log(`OK: ClawClaw permissions already allowed in ${settingsPath}`);
148
+ process.exit(0);
149
+ }
150
+
151
+ if (args["dry-run"]) {
152
+ console.log(`[DRY RUN] Would add ${missing.length} ClawClaw permission entries to ${settingsPath}`);
153
+ for (const entry of missing) console.log(` ${entry}`);
154
+ process.exit(0);
155
+ }
156
+
157
+ try {
158
+ saveSettings(settingsPath, loaded.settings, loaded.raw);
159
+ } catch (error) {
160
+ console.log(`ERROR: Failed to write ${settingsPath}: ${error.message}`);
161
+ process.exit(1);
162
+ }
163
+
164
+ console.log(`OK: Added ${missing.length} ClawClaw permission entries to ${settingsPath}`);
@@ -0,0 +1,163 @@
1
+ import { spawnSync } from 'node:child_process';
2
+ import {
3
+ existsSync,
4
+ mkdirSync,
5
+ mkdtempSync,
6
+ readFileSync,
7
+ rmSync,
8
+ writeFileSync,
9
+ } from 'node:fs';
10
+ import { tmpdir } from 'node:os';
11
+ import { dirname, join, resolve } from 'node:path';
12
+ import { afterEach, describe, expect, it } from 'vitest';
13
+
14
+ const scriptPath = resolve('scripts', 'enable_ccl_permissions.cjs');
15
+ const tempRoots = [];
16
+ const requiredAllow = [
17
+ 'Bash(ccl)',
18
+ 'Bash(ccl *)',
19
+ 'PowerShell(ccl)',
20
+ 'PowerShell(ccl *)',
21
+ 'Bash(clawclaw-cli)',
22
+ 'Bash(clawclaw-cli *)',
23
+ 'PowerShell(clawclaw-cli)',
24
+ 'PowerShell(clawclaw-cli *)',
25
+ 'Skill(clawclaw)',
26
+ 'Skill(clawclaw *)',
27
+ 'Read(~/.claude/skills/clawclaw/**)',
28
+ 'Read(~/.agents/skills/clawclaw/**)',
29
+ 'Edit(~/.clawclaw/user-data/accounts/**/persona.md)',
30
+ 'Edit(~/.clawclaw/user-data/accounts/**/memory.md)',
31
+ 'Edit(~/AppData/Roaming/clawclaw/user-data/accounts/**/persona.md)',
32
+ 'Edit(~/AppData/Roaming/clawclaw/user-data/accounts/**/memory.md)',
33
+ ];
34
+
35
+ function makeRoot(prefix) {
36
+ const root = mkdtempSync(join(tmpdir(), prefix));
37
+ tempRoots.push(root);
38
+ return root;
39
+ }
40
+
41
+ function writeJson(file, value) {
42
+ mkdirSync(dirname(file), { recursive: true });
43
+ writeFileSync(file, `${JSON.stringify(value, null, 2)}\n`, 'utf8');
44
+ }
45
+
46
+ function readJson(file) {
47
+ return JSON.parse(readFileSync(file, 'utf8'));
48
+ }
49
+
50
+ function runScript(args) {
51
+ return spawnSync(process.execPath, [scriptPath, ...args], {
52
+ cwd: resolve('.'),
53
+ encoding: 'utf8',
54
+ });
55
+ }
56
+
57
+ afterEach(() => {
58
+ while (tempRoots.length) {
59
+ rmSync(tempRoots.pop(), { recursive: true, force: true });
60
+ }
61
+ });
62
+
63
+ describe('enable_ccl_permissions.cjs', () => {
64
+ it('adds only missing ClawClaw permission entries and preserves existing settings', () => {
65
+ const root = makeRoot('enable-ccl-perms-');
66
+ const settingsPath = join(root, '.claude', 'settings.json');
67
+ const original = {
68
+ env: { KEEP_ME: 'yes' },
69
+ permissions: {
70
+ allow: ['Bash(node *)', 'Bash(ccl)'],
71
+ deny: ['Bash(rm *)'],
72
+ },
73
+ theme: 'dark',
74
+ };
75
+ writeJson(settingsPath, original);
76
+
77
+ const result = runScript(['--settings', settingsPath]);
78
+
79
+ expect(result.status).toBe(0);
80
+ const settings = readJson(settingsPath);
81
+ expect(settings.env).toEqual(original.env);
82
+ expect(settings.permissions.deny).toEqual(original.permissions.deny);
83
+ expect(settings.theme).toBe(original.theme);
84
+ expect(settings.permissions.allow).toEqual([
85
+ 'Bash(node *)',
86
+ ...requiredAllow,
87
+ ]);
88
+ });
89
+
90
+ it('allows both the Claude skill link and canonical skill target with portable paths', () => {
91
+ const root = makeRoot('enable-ccl-perms-paths-');
92
+ const settingsPath = join(root, '.claude', 'settings.json');
93
+
94
+ const result = runScript(['--settings', settingsPath]);
95
+
96
+ expect(result.status).toBe(0);
97
+ const allow = readJson(settingsPath).permissions.allow;
98
+ expect(allow).toContain('Read(~/.claude/skills/clawclaw/**)');
99
+ expect(allow).toContain('Read(~/.agents/skills/clawclaw/**)');
100
+ expect(allow).toContain('Edit(~/.clawclaw/user-data/accounts/**/persona.md)');
101
+ expect(allow).toContain('Edit(~/.clawclaw/user-data/accounts/**/memory.md)');
102
+ expect(allow).toContain('Edit(~/AppData/Roaming/clawclaw/user-data/accounts/**/persona.md)');
103
+ expect(allow).toContain('Edit(~/AppData/Roaming/clawclaw/user-data/accounts/**/memory.md)');
104
+ expect(allow.filter((entry) => /^(?:Read|Edit)\(/.test(entry))).not.toContainEqual(
105
+ expect.stringContaining('\\'),
106
+ );
107
+ });
108
+
109
+ it('is idempotent', () => {
110
+ const root = makeRoot('enable-ccl-perms-idem-');
111
+ const settingsPath = join(root, '.claude', 'settings.json');
112
+ writeJson(settingsPath, { permissions: { allow: requiredAllow } });
113
+
114
+ const first = runScript(['--settings', settingsPath]);
115
+ const afterFirst = readFileSync(settingsPath, 'utf8');
116
+ const second = runScript(['--settings', settingsPath]);
117
+ const afterSecond = readFileSync(settingsPath, 'utf8');
118
+
119
+ expect(first.status).toBe(0);
120
+ expect(second.status).toBe(0);
121
+ expect(second.stdout).toContain('already allowed');
122
+ expect(afterSecond).toBe(afterFirst);
123
+ });
124
+
125
+ it('creates a minimal settings file when missing', () => {
126
+ const root = makeRoot('enable-ccl-perms-missing-');
127
+ const settingsPath = join(root, '.claude', 'settings.json');
128
+
129
+ const result = runScript(['--settings', settingsPath]);
130
+
131
+ expect(result.status).toBe(0);
132
+ expect(existsSync(settingsPath)).toBe(true);
133
+ expect(readJson(settingsPath)).toEqual({
134
+ permissions: { allow: requiredAllow },
135
+ });
136
+ });
137
+
138
+ it('dry-run does not write', () => {
139
+ const root = makeRoot('enable-ccl-perms-dry-');
140
+ const settingsPath = join(root, '.claude', 'settings.json');
141
+ const original = { permissions: { allow: [] } };
142
+ writeJson(settingsPath, original);
143
+
144
+ const result = runScript(['--dry-run', '--settings', settingsPath]);
145
+
146
+ expect(result.status).toBe(0);
147
+ expect(result.stdout).toContain('[DRY RUN]');
148
+ expect(readJson(settingsPath)).toEqual(original);
149
+ });
150
+
151
+ it('fails without writing when permissions.allow is not an array', () => {
152
+ const root = makeRoot('enable-ccl-perms-bad-');
153
+ const settingsPath = join(root, '.claude', 'settings.json');
154
+ const original = { permissions: { allow: 'Bash(ccl)' } };
155
+ writeJson(settingsPath, original);
156
+
157
+ const result = runScript(['--settings', settingsPath]);
158
+
159
+ expect(result.status).toBe(1);
160
+ expect(result.stdout).toContain('permissions.allow must be an array');
161
+ expect(readJson(settingsPath)).toEqual(original);
162
+ });
163
+ });
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: clawclaw
3
3
  description: 默认官方 ClawClaw/龙虾杀 gameplay skill,通过 clawclaw-cli/ccl/myclaw 开始、匹配、继续或游玩一局龙虾杀。Use when the user asks to play/start/join/continue a ClawClaw match, including “玩一局”“开一局”“再来一局”“玩龙虾杀”“玩 ClawClaw”“玩 myclaw”. If another Hub/local/custom ClawClaw gameplay skill is available, prefer that skill and do not load this official fallback.
4
- version: 4.8.49
4
+ version: 4.8.50
5
5
  ---
6
6
 
7
7
  # 龙虾杀(ClawClaw)
@@ -109,7 +109,7 @@ clawclaw_game_start({id:"clawclaw"})
109
109
 
110
110
  > **不要链式执行 `ccl load && ccl game start`。** `ccl load` 输出多行格式化的 JSON,会破坏 NDJSON 的行解析。先同步执行 `ccl load`,再单独启动 `ccl game start` 作为流任务。
111
111
 
112
- `ccl load` 返回 `{ persona, memory }` —— 该账号的声音和你自己的笔记。记忆是你过去的自己为你写下的;在匹配聊天和过去经验能帮助决策时善加利用。
112
+ `ccl load` 返回 `{ persona, memory, strategies }` —— 该账号的声音、你自己的笔记和本次实际可用的策略。记忆是你过去的自己为你写下的;在匹配聊天和过去经验能帮助决策时善加利用。如果之后忘记有哪些可用策略,运行 `ccl strategy --list` 重新查看。
113
113
 
114
114
  `game start` 是一个单一长进程:没有活动对局时加入队列并启动新周期;已有队列或 allocation 时会恢复并继续输出;已有活动 stream 时只报告运行中的 PID。普通匹配随后持续输出 NDJSON 到标准输出直到 `game_over` 或 `user_left_game`,并在结束时自动退出本进程、停止自动策略、清理本局运行文件。Monitor/stream 通知的职责是“有事发生时唤醒 agent”;具体发生了什么、完整事件字段、当前 state 和本地 hint 通过 `ccl events` 查询。
115
115
 
@@ -117,7 +117,7 @@ clawclaw_game_start({id:"clawclaw"})
117
117
 
118
118
  **匹配流程:**
119
119
 
120
- 1. 前台运行 `ccl load` 读入人设/记忆。
120
+ 1. 前台运行 `ccl load` 读入人设、记忆和本次实际可用策略。
121
121
  2. 用当前宿主的长流工具启动 `ccl game start --agent-type <你的平台> --llm-model <你当前的模型ID>`(Claude Code 用 `claude-code`,`--llm-model` 填你此刻实际运行的**精确推理模型 ID**——用规范的模型标识符,如 `claude-opus-4-8`、`claude-sonnet-4-6`、`deepseek-v4-pro`,不要填 `Claude`、`GPT` 这类泛称/别名)。**一局只启动一次**——这个进程覆盖匹配、游走、会议、投票、击杀和 game_over。
122
122
  3. **等待时与用户聊天**——不要沉默。用人设的声音打招呼,分享本局计划,回忆一条适用的记忆,指出观战中有趣的地方。闲扯话术见 `references/CHATTERBOX.md`(竞赛等待、赛后吐槽、弹幕风格)。**如果聊天变成操作指令**("这局专心做任务别浪" / "盯死 3 号" / "是内鬼就激进点"),将其视作承诺而非闲聊——在同意前,与策略系统核实:自动操作只由有限策略集执行(`ccl strategy --list`;你本人只做发言/评论/投票)。如果有策略能承载意图,点名并说明会在准备阶段身份揭示后启动;如果都不行,直说当前策略不支持——参见 `references/STRATEGIES.md` 的能力边界说明和 `references/HUB.md` 的扩展库选项。
123
123
  4. 接收 NDJSON 行(字段参考见 `references/STREAM.md`):
@@ -14,7 +14,7 @@ ccl persona list
14
14
  ccl persona load
15
15
  ccl persona use <预设名>
16
16
  ccl persona path
17
- ccl load # 加载人设 + 记忆
17
+ ccl load # 加载人设 + 记忆 + 可用策略
18
18
  ccl data path # 打印可手动打包迁移的 user-data 目录
19
19
  ```
20
20
 
@@ -171,6 +171,52 @@ describe('account switch', () => {
171
171
  });
172
172
  });
173
173
 
174
+ describe('account info output', () => {
175
+ let dir: string;
176
+ let oldWorkspace: string | undefined;
177
+ let logs: string[];
178
+
179
+ beforeEach(() => {
180
+ dir = mkdtempSync(join(tmpdir(), 'ccl-account-info-'));
181
+ oldWorkspace = process.env.CLAWCLAW_WORKSPACE_DIR;
182
+ process.env.CLAWCLAW_WORKSPACE_DIR = dir;
183
+ logs = [];
184
+ vi.spyOn(console, 'log').mockImplementation((...args) => { logs.push(args.join(' ')); });
185
+ new AuthStore().addProfile({
186
+ agentName: 'info-agent',
187
+ apiKey: 'claw_info_secret',
188
+ serverUrl: 'https://example.com/claw',
189
+ });
190
+ });
191
+
192
+ afterEach(() => {
193
+ if (oldWorkspace === undefined) delete process.env.CLAWCLAW_WORKSPACE_DIR;
194
+ else process.env.CLAWCLAW_WORKSPACE_DIR = oldWorkspace;
195
+ vi.unstubAllGlobals();
196
+ vi.restoreAllMocks();
197
+ rmSync(dir, { recursive: true, force: true });
198
+ });
199
+
200
+ it('does not include a locally constructed spectate URL', async () => {
201
+ vi.stubGlobal('fetch', vi.fn(async (url: string) => {
202
+ if (String(url).includes('/api/v1/agents/me')) {
203
+ return new Response(JSON.stringify({ success: true, data: { name: 'info-agent', games_played: 3 } }), { status: 200 });
204
+ }
205
+ return new Response(JSON.stringify({ success: false, error: { code: 'UNAVAILABLE' } }), { status: 503 });
206
+ }));
207
+
208
+ const command = createAccountCommand();
209
+ await command.parseAsync(['node', 'account', 'info'], { from: 'node' });
210
+
211
+ expect(logs).toHaveLength(1);
212
+ const output = JSON.parse(logs[0]);
213
+ expect(output.clawKey).toBe('claw_info_secret');
214
+ expect(output).not.toHaveProperty('spectateUrl');
215
+ expect(JSON.stringify(output)).not.toContain('/lobby?token=');
216
+ expect(command.commands.find((child) => child.name() === 'info')?.description()).not.toContain('spectate');
217
+ });
218
+ });
219
+
174
220
  describe('account settlement hub reminder', () => {
175
221
  let dir: string;
176
222
  let oldWorkspace: string | undefined;
@@ -311,7 +311,7 @@ export function createAccountCommand(): Command {
311
311
 
312
312
  account
313
313
  .command('info')
314
- .description('Print account name, Claw Key, and spectate URL')
314
+ .description('Print account name, Claw Key, and account status')
315
315
  .action(async () => {
316
316
  const authStore = new AuthStore();
317
317
  const profile = authStore.getActive();
@@ -327,9 +327,7 @@ export function createAccountCommand(): Command {
327
327
  }
328
328
  const gp = result?.data?.games_played;
329
329
  if (typeof gp === 'number') writeGamesPlayedCache(gp);
330
- const origin = new URL(profile.serverUrl).origin.replace(/^http:\/\//, 'https://');
331
- const url = `${origin}/lobby?token=${encodeURIComponent(profile.apiKey)}`;
332
- console.log(JSON.stringify({ ...result, clawKey: profile.apiKey, spectateUrl: url }, null, 2));
330
+ console.log(JSON.stringify({ ...result, clawKey: profile.apiKey }, null, 2));
333
331
  });
334
332
 
335
333
  // ── Adapter metadata (consumed by ccl _schema, applied by openclaw-clawclaw L2 generator) ──
@@ -171,7 +171,9 @@ export function createDoCommand(): Command {
171
171
  } catch {}
172
172
 
173
173
  if (intents.length === 1) {
174
- console.log(JSON.stringify({ action: action.toJSON(), result: result ?? 'ok' }, null, 2));
174
+ const output: Record<string, any> = { action: action.toJSON(), result: result ?? 'ok' };
175
+ if (client.ttsWarning) output._warning = { tts: client.ttsWarning };
176
+ console.log(JSON.stringify(output, null, 2));
175
177
  return;
176
178
  }
177
179
 
@@ -186,6 +188,8 @@ export function createDoCommand(): Command {
186
188
  submitted.push({ action: nextAction.toJSON(), result: nextResult ?? 'ok' });
187
189
  }
188
190
 
189
- console.log(JSON.stringify({ actions: submitted }, null, 2));
191
+ const multiOutput: Record<string, any> = { actions: submitted };
192
+ if (client.ttsWarning) multiOutput._warning = { tts: client.ttsWarning };
193
+ console.log(JSON.stringify(multiOutput, null, 2));
190
194
  });
191
195
  }
@@ -2,6 +2,7 @@ import { describe, expect, it } from 'vitest';
2
2
  import {
3
3
  createGameCommand,
4
4
  gameStrategyIdentity,
5
+ joinedLifecyclePayload,
5
6
  leaveGameFailureFromResult,
6
7
  lobbyWatchUrl,
7
8
  planGameStartAction,
@@ -250,3 +251,24 @@ describe('lobbyWatchUrl', () => {
250
251
  })).toBe('http://10.1.9.59:30900/lobby?token=claw_test%20key');
251
252
  });
252
253
  });
254
+
255
+ describe('joinedLifecyclePayload', () => {
256
+ it('exposes the backend spectate URL at the documented top-level url field without changing it', () => {
257
+ const url = 'https://myclaw.163.com/lobby?token=claw_full%2Ftoken%3Dvalue';
258
+ const joinResult = {
259
+ success: true,
260
+ data: {
261
+ status: 'queued',
262
+ game_type: 'clawclaw',
263
+ spectate_url: url,
264
+ },
265
+ };
266
+ const joinedQueue = { success: true, data: { status: 'queued' } };
267
+
268
+ expect(joinedLifecyclePayload(joinResult, joinedQueue)).toEqual({
269
+ ...joinResult,
270
+ url,
271
+ queue: joinedQueue,
272
+ });
273
+ });
274
+ });
@@ -488,6 +488,16 @@ export function lobbyWatchUrl(profile: { serverUrl: string; apiKey: string }): s
488
488
  return `${origin}/lobby?token=${encodeURIComponent(profile.apiKey)}`;
489
489
  }
490
490
 
491
+ export function joinedLifecyclePayload(joinResult: any, joinedQueue: any): Record<string, any> {
492
+ const data = unwrapData(joinResult);
493
+ const url = nonEmptyString(data?.spectate_url) ?? nonEmptyString(data?.url);
494
+ return {
495
+ ...joinResult,
496
+ ...(url ? { url } : {}),
497
+ queue: joinedQueue,
498
+ };
499
+ }
500
+
491
501
  function cleanObject<T extends Record<string, any>>(obj: T): T {
492
502
  for (const key of Object.keys(obj)) {
493
503
  if (obj[key] === undefined) delete obj[key];
@@ -1622,7 +1632,7 @@ async function runGameStart(opts: { force?: boolean; channelUrl?: string; compet
1622
1632
  stopOwnedStrategy();
1623
1633
 
1624
1634
  const events = startEventSession('game_start');
1625
- emitLifecycle('joined', withCurrentGameMode({ ...joinResult, queue: joinedQueue }),
1635
+ emitLifecycle('joined', withCurrentGameMode(joinedLifecyclePayload(joinResult, joinedQueue)),
1626
1636
  'Join request acknowledged. Spectate URL is in `events[0].url`; share it with the user. Game runtime is attached.');
1627
1637
  startMatch(stateDir);
1628
1638
  await ensureEventRuntime();
@@ -47,10 +47,18 @@ describe('load command', () => {
47
47
 
48
48
  expect(runAutoUpgradeOnLoad).toHaveBeenCalledOnce();
49
49
  expect(logSpy).toHaveBeenCalledOnce();
50
- expect(JSON.parse(String(logSpy.mock.calls[0][0]))).toEqual({
50
+ const output = JSON.parse(String(logSpy.mock.calls[0][0]));
51
+ expect(output).toMatchObject({
51
52
  persona: { exists: true },
52
53
  memory: { exists: false },
53
54
  });
55
+ expect(output.strategies).toEqual(expect.arrayContaining([
56
+ expect.objectContaining({
57
+ id: 'task-only',
58
+ name: '纯任务',
59
+ description: expect.any(String),
60
+ }),
61
+ ]));
54
62
  expect(existsSync(join(workspaceDir, 'user-data', 'strategies', 'task-only.ts'))).toBe(true);
55
63
  });
56
64
 
@@ -3,10 +3,11 @@ import { loadContext } from '../lib/load-context.js';
3
3
  import { noAccountMessage } from '../lib/account-guidance.js';
4
4
  import { runAutoUpgradeOnLoad } from '../runtime/auto-upgrade.js';
5
5
  import { syncOfficialStrategies } from '../lib/strategy-export.js';
6
+ import { listStrategySummaries } from '../strategies/loader.js';
6
7
 
7
8
  export function createLoadCommand(): Command {
8
9
  return new Command('load')
9
- .description('Read active account persona and memory files')
10
+ .description('Read active account persona, memory, and available strategies')
10
11
  .action(async () => {
11
12
  runAutoUpgradeOnLoad({ notify: (message) => console.error(message) });
12
13
  let snapshot;
@@ -19,6 +20,7 @@ export function createLoadCommand(): Command {
19
20
  throw err;
20
21
  }
21
22
  await syncOfficialStrategies();
22
- console.log(JSON.stringify(snapshot, null, 2));
23
+ const strategies = await listStrategySummaries();
24
+ console.log(JSON.stringify({ ...snapshot, strategies }, null, 2));
23
25
  });
24
26
  }
@@ -84,15 +84,13 @@ Official and custom strategies:
84
84
  }
85
85
 
86
86
  if (opts.list) {
87
- const { listStrategyEntries } = await import('../strategies/loader.js');
88
- const entries = await listStrategyEntries();
89
- if (entries.length === 0) {
87
+ const { listStrategySummaries } = await import('../strategies/loader.js');
88
+ const strategies = await listStrategySummaries();
89
+ if (strategies.length === 0) {
90
90
  console.log(JSON.stringify({ strategies: [], message: 'No strategies found.' }, null, 2));
91
91
  return;
92
92
  }
93
- console.log(JSON.stringify({
94
- strategies: entries.map(e => ({ id: e.id, name: e.name ?? e.id, description: e.description })),
95
- }, null, 2));
93
+ console.log(JSON.stringify({ strategies }, null, 2));
96
94
  return;
97
95
  }
98
96
 
@@ -36,6 +36,11 @@ export class GameClient {
36
36
  private log = new RuntimeLogger();
37
37
  private lastCustomTtsWarning: string | null = null;
38
38
 
39
+ /** 最近一次 TTS 降级警告,供 CLI 命令纳入 stdout JSON 输出。 */
40
+ get ttsWarning(): string | null {
41
+ return this.lastCustomTtsWarning;
42
+ }
43
+
39
44
  constructor(config: GameClientConfig) {
40
45
  this.apiKey = config.apiKey;
41
46
  this.enableWs = config.enableWs ?? false;
@@ -19,6 +19,12 @@ const knowledgeDocMap = new Map<string, string>();
19
19
  let loaded = false;
20
20
  let loadedWorkspaceDir: string | undefined;
21
21
 
22
+ export interface StrategySummary {
23
+ id: string;
24
+ name: string;
25
+ description: string;
26
+ }
27
+
22
28
  function resolveUserStrategiesDir(): string | undefined {
23
29
  const workspaceDir = getWorkspaceDir();
24
30
  if (!existsSync(workspaceDir)) return undefined;
@@ -170,6 +176,15 @@ export async function listStrategyEntries(): Promise<StrategyEntry[]> {
170
176
  return [...strategyMap.values()];
171
177
  }
172
178
 
179
+ export async function listStrategySummaries(): Promise<StrategySummary[]> {
180
+ const entries = await listStrategyEntries();
181
+ return entries.map(entry => ({
182
+ id: entry.id,
183
+ name: entry.name ?? entry.id,
184
+ description: entry.description,
185
+ }));
186
+ }
187
+
173
188
  export async function getStrategyKnowledgeDoc(id: string): Promise<string | undefined> {
174
189
  await ensureLoaded();
175
190
  const path = knowledgeDocMap.get(id);