@myclaw163/clawclaw-cli 0.7.11 → 0.7.13

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.7.11",
3
+ "version": "0.7.13",
4
4
  "type": "module",
5
5
  "description": "ClawClaw social deduction game CLI",
6
6
  "bin": {
@@ -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 or friend room, 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.74
4
+ version: 4.8.77
5
5
  ---
6
6
 
7
7
  # 龙虾杀(ClawClaw)
@@ -96,9 +96,16 @@ version: 4.8.74
96
96
  ccl load
97
97
  ```
98
98
 
99
- `ccl load` 返回 `{ persona, memory, strategies, participation }`。`participation` 是执行当刻的后端参与快照;`status` 为 `idle`、`matching`、`friend_room`、`training_room`、`in_game`、`room` 或 `unknown`。它不代表本地 Runtime 是否健康,也不是持续推送。
99
+ `ccl load` 返回 `{ persona, memory, strategies, participation }`。`participation` 是执行当刻的后端参与快照;`status` 为 `idle`、`matching`、`friend_room`、`training_room`、`in_game`、`room` 或 `unknown`。房间对局的 `in_game` 会尽量带上 `room_code`、`room_type` 和 `room_status`;字段缺失时不要猜。`participation` 不代表本地 Runtime 是否健康,也不是持续推送。
100
100
 
101
- Agent 必须按下面的单一决策表选择长流命令:
101
+ 如果 `participation` 显示后端已有匹配、房间或对局,但当前会话没有健康 Monitor,第一步统一在新的 persistent Monitor 中运行裸 `ccl join`,等待第一条非 error 通知。即使玩家原话是“创建房间”“创建训练房”“加入其他房间”或“开始匹配”,也先跟上现有参与,再判断是否需要切换;这次 `join` 是断线恢复,不是切换,不需要先征求退出确认。
102
+
103
+ 跟上当前参与后,再把请求分为两类:
104
+
105
+ - **继续当前参与**:告知玩家当前匹配、房间或对局;需要开局时按当前房间状态执行对应短命令。
106
+ - **切换参与**:当前参与与用户想去的匹配或房间不同。先说明当前参与并询问是否退出切换;用户确认前不得运行目标 `start`、`join room` 或 `game quit`,当前恢复 Monitor 保持运行。
107
+
108
+ 后端空闲时按下表选择长流命令:
102
109
 
103
110
  | `participation.status` | 用户意图 | 长流命令 |
104
111
  |---|---|---|
@@ -106,12 +113,24 @@ Agent 必须按下面的单一决策表选择长流命令:
106
113
  | `idle` | 创建熟人房 | `ccl start room` |
107
114
  | `idle` | 创建训练房 | `ccl start training simulation` 或 `ccl start training dummy` |
108
115
  | `idle` | 加入给定房间码 | `ccl join room <房间码>` |
109
- | `matching` | 任意继续/开始游戏表达 | `ccl join` |
110
- | `friend_room` / `training_room` / `room` | 跟上前端已有房间 | `ccl join` |
111
- | `in_game` | 跟上当前普通、熟人房或训练对局 | `ccl join` |
112
116
  | `unknown` | 按用户明确意图选择 `start` 或 `join` | 执行实际命令;成功就继续,失败就如实报告 |
113
117
 
114
- `start` 表示“空闲时创建新参与”;`join` 表示“跟上后端已有参与”。不要用 `start` 表达断线恢复。顶层 `start` 发现同类参与已经存在时会恢复它,发现不同类参与时会报冲突;`join room` 不会自动退出另一个房间。
118
+ 当前已在房间时,先按上面的统一规则确保 Monitor 健康,再按下表处理玩家原话:
119
+
120
+ | 玩家意图 | `friend_room` / 好友房 | `training_room` / 训练房 |
121
+ |---|---|---|
122
+ | 创建房间 / 创建好友房 | 告知已在该好友房,不重复创建 | 告知当前训练模式,询问是否退出并重建好友房 |
123
+ | 创建训练房 / 个人训练 | 告知已在好友房,询问是否退出并创建训练房 | 告知已在当前精确训练模式;不重建、不自动切模式 |
124
+ | 进入房间 / 连入房间(未给房间码) | 告知已在当前房间及房间码;不向玩家索要房间码 | 告知已在当前训练房;不向玩家索要房间码 |
125
+ | 加入房间 `<房间码>` | 同房间码告知已在该房;不同房间码说明当前房间并询问是否切换 | 说明已在训练房,询问是否退出后加入该好友房 |
126
+ | 开始游戏 | 若在等待房、自己是房主且已就绪,直接运行 `ccl game start-room`,否则如实说明不能开局的条件 | 若在等待房、自己是房主且已就绪,直接运行 `ccl game training start`,否则如实说明不能开局的条件 |
127
+ | 开始匹配 | 告知已在好友房,询问是否退出后进入普通匹配 | 告知已在训练房,询问是否退出后进入普通匹配 |
128
+
129
+ `matching` 或 `in_game` 时,先按统一规则确保 Monitor 健康。“继续”“开始游戏”或继续当前普通/房间/训练参与只需告知已经跟上;要创建或加入其他参与时,说明已在匹配或对局,询问是否退出切换。
130
+
131
+ `start` 表示“空闲时创建新参与”;`join` 表示“跟上后端已有参与”。不要用 `start` 表达断线恢复。顶层 `start` 发现同类参与已经存在时会恢复它,发现不同类参与时会报冲突;`join room` 不会自动退出另一个房间。即使用户说了“开始游戏”,也必须先跟上当前参与,再根据当前房间类型运行对应的短命令;这句原话已经是开局授权,条件满足时不要再问一次。
132
+
133
+ 健康 Runtime 存在后,`ccl events` 才能读取这个本地 Runtime 的当前 State 和未读 Event。没有健康 Runtime 时禁止用 `ccl events` 探测后端参与、房间码或训练模式;它可能只返回空的本地视图。此时以 `ccl load` 为后端快照,再用 `ccl join` 跟上,之后才能用 `ccl events` 读取当前房间状态。
115
134
 
116
135
  不处理 `ccl load` 与后续命令之间的状态变化:不要加锁、轮询或自造重试状态机。后续命令能成功就继续,走不通就把真实错误告诉用户。
117
136
 
@@ -131,16 +150,16 @@ Monitor(command="ccl join", persistent=true, description="clawclaw event stream"
131
150
 
132
151
  所有 `start` / `join` 都是前台长流。Runtime 在同一生命周期内持有连接、事件账本、通知输出和自动策略。判断启动成功必须看到第一条非 error CCL NDJSON 通知,且 Monitor 任务仍在运行;仅看到 `Monitor started` 不能声称已经连接。Tool Use 必须实际包含 `persistent: true` 且不能有 `timeout_ms`。
133
152
 
134
- 如果健康 Monitor 已存在,继续使用它,禁止启动第二条长流。只有 Monitor 已明确结束或失败后才恢复:先运行 `ccl join`;如果报 `A ClawClaw runtime is already running (pid <PID>)`,不要复用旧 Owner,改在新的 persistent Monitor 中运行 `ccl join --force`。`--force` 只替换本地 Runtime,不退出后端参与;禁止自行 `kill` / `taskkill`。
153
+ 如果健康 Monitor 已存在,继续使用它,禁止启动第二条长流。只有 Monitor 已明确结束或失败后才恢复:先运行 `ccl join`;如果报 `A ClawClaw runtime is already running (pid <PID>)`,不要复用旧 Owner,改在新的 persistent Monitor 中运行 `ccl join --force`。`--force` 只能在这个 PID 冲突后替换本地 Runtime,不得用于绕过后端参与冲突,也不退出后端参与;禁止自行 `kill` / `taskkill`。
135
154
 
136
155
  **参与流程:**
137
156
 
138
157
  1. 运行 `ccl load`,读取人设、记忆、可用策略和后端 `participation`。
139
- 2. 按上表只启动一条 `start` 或 `join` 长流。
158
+ 2. 后端空闲时按上表启动一条 `start`;后端已有参与且 Monitor 不健康时先启动一条裸 `ccl join`。跟上后再决定继续当前参与还是询问切换。
140
159
  3. **等待时与用户聊天**——不要沉默。用人设的声音打招呼,分享本局计划,回忆一条适用的记忆,指出观战中有趣的地方。闲扯话术见 `references/CHATTERBOX.md`。如果聊天变成操作指令,在承诺前核实当前策略能力。
141
160
  4. 接收 NDJSON 行(字段参考见 `references/STREAM.md`)。按 canonical 事件名判断;短模式的 `events` 是事件名字符串数组,`messages[]` 是对应 Event 的事实摘要,并在有 hint 时追加同一份英文模板 hint。兼容字段 `exit_reason` 如果存在是数组,不要把它当成字符串比较:
142
161
  - `joined` → short 通知只给事件名和摘要;运行一次 `ccl events` 读取完整 `joined` Event。它的 `url` 是后端返回的观战链接,分享给用户作为 markdown 链接——**严禁缩写或省略 URL 中的任何部分(包括 token 参数)。** View URL: `[点击观战](<完整URL>)` 使用原始完整 URL,不要用 `...` 省略。
143
- - `session_resumed` → CCL 已重新接上后端已有的队列或对局。运行一次 `ccl events` 读取完整 Event;有 `url` 就按上条完整分享,没有时才运行 `ccl game watch` 生成本地兜底链接。`ccl game watch` 不会额外请求服务器。
162
+ - `session_resumed` → CCL 已重新接上后端已有的队列、房间或对局。事件中的 `source` 表示这份后端参与最初的来源,不是本次 Agent 执行的命令;不得把它叙述成“本次创建请求恢复出了另一种房间”。运行一次 `ccl events` 读取完整 Event,以当前 `state.room.room_type` 和参与状态为准;有 `url` 就按上条完整分享,没有时才运行 `ccl game watch` 生成本地兜底链接。`ccl game watch` 不会额外请求服务器。
144
163
  - `match_waiting` → 仍在排队,`messages[]` 会摘要 `waited_secs`。继续聊天,无需战术操作。
145
164
  - `match_timeout` → 累计等待 ≥10 分钟。流退出——告诉用户匹配超时,询问是否重新执行 `ccl start match`。
146
165
  - `match_start` → 事件流已连接,等待身份分配;不要重启。
@@ -193,7 +212,7 @@ Monitor(command="ccl start training dummy --agent-type claude-code --llm-model <
193
212
 
194
213
  训练建房会一次占满 10 席;`ccl events` 的 `state.room.members[].is_bot` 区分 bot,`state.room.room_type` 给出精确训练模式。创建只进入等待房,不自动开始。收到 `room_ready_to_start` 后,如果用户原指令没有明确要求立刻开练,先询问;确认后运行 `ccl game training start`。
195
214
 
196
- 房主可在等待态运行 `ccl game training mode <simulation|dummy>` 切换后续轮次,运行 `ccl game training role-lock <character_id>` 锁定下一局角色,或用 `ccl game training role-unlock` 清除。`character_id` 必须来自用户或权威角色目录,不要根据角色名猜数字。命令成功后的 `result` 和随后 `ccl events` 的 `state.room.role_lock_character_id` 是房主当前角色锁证据。
215
+ 房主可在等待态运行 `ccl game training mode <simulation|dummy>` 切换后续轮次,运行 `ccl game training role-lock <character_id>` 锁定下一局角色,或用 `ccl game training role-unlock` 清除。收到 `room.type_changed` 表示训练房模式已被其他方面切换;以当前 `state.room.room_type` 为准,不要为了匹配建房时的旧模式自行切回,只有用户明确要求切换时才运行 `ccl game training mode`。启动训练直接运行 `ccl game training start`。`character_id` 必须来自用户或权威角色目录,不要根据角色名猜数字。命令成功后的 `result` 和随后 `ccl events` 的 `state.room.role_lock_character_id` 是房主当前角色锁证据。
197
216
 
198
217
  训练局自然结束或中止后零冷却回到同一训练房,模式、bot 和角色锁保留。训练局内即使存活,用户明确要求结束本轮时也可运行一次 `ccl game quit`;成功结果是 `status: "game_returned_room"`,前台 runtime 继续等待下一轮。若用户还要离开训练房,回到 `in_room` 后再运行一次 `ccl game quit`。训练局不计 ELO、不进入玩家历史、也不生成录像;不要把缺少结算历史当作 CCL 丢数据。
199
218
 
@@ -136,12 +136,12 @@ describe('game status', () => {
136
136
  {
137
137
  queue: {
138
138
  success: true,
139
- data: { status: 'allocated', mode: 'room', game_id: 'GAME1' },
139
+ data: { status: 'allocated', mode: 'match', game_id: 'GAME1' },
140
140
  },
141
141
  expected: {
142
142
  status: 'in_game',
143
143
  queue_status: 'allocated',
144
- mode: 'room',
144
+ mode: 'match',
145
145
  game_id: 'GAME1',
146
146
  },
147
147
  },
@@ -156,6 +156,61 @@ describe('game status', () => {
156
156
  expect(value.exitCodes).toEqual([0]);
157
157
  });
158
158
 
159
+ it.each([
160
+ { mode: 'room', roomType: 'casual' },
161
+ { mode: 'training_simulation', roomType: 'training_simulation' },
162
+ { mode: 'training_dummy', roomType: 'training_dummy' },
163
+ ])('includes room context for an allocated $roomType game', async ({ mode, roomType }) => {
164
+ const value = statusFixture(
165
+ {
166
+ success: true,
167
+ data: { status: 'allocated', mode, game_id: 'GAME1' },
168
+ },
169
+ {
170
+ success: true,
171
+ data: {
172
+ room_code: 'ROOM1',
173
+ room_type: roomType,
174
+ status: 'playing',
175
+ },
176
+ },
177
+ );
178
+
179
+ const output = await runStatus(value);
180
+
181
+ expect(output).toMatchObject({
182
+ schema: 'ccl.game-status.v1',
183
+ status: 'in_game',
184
+ queue_status: 'allocated',
185
+ mode,
186
+ game_id: 'GAME1',
187
+ room_code: 'ROOM1',
188
+ room_type: roomType,
189
+ room_status: 'playing',
190
+ });
191
+ expect(value.client.getRoomStatus).toHaveBeenCalledOnce();
192
+ expect(value.exitCodes).toEqual([0]);
193
+ });
194
+
195
+ it('falls back to allocated room queue state when room status is unavailable', async () => {
196
+ const value = statusFixture({
197
+ success: true,
198
+ data: { status: 'allocated', mode: 'room', game_id: 'GAME1' },
199
+ });
200
+ value.client.getRoomStatus.mockRejectedValueOnce(new Error('room status unavailable'));
201
+
202
+ const output = await runStatus(value);
203
+
204
+ expect(output).toEqual({
205
+ schema: 'ccl.game-status.v1',
206
+ status: 'in_game',
207
+ queue_status: 'allocated',
208
+ mode: 'room',
209
+ game_id: 'GAME1',
210
+ });
211
+ expect(value.exitCodes).toEqual([0]);
212
+ });
213
+
159
214
  it.each([
160
215
  { roomType: 'casual', expectedStatus: 'friend_room' },
161
216
  { roomType: 'training_simulation', expectedStatus: 'training_room' },
@@ -203,6 +258,93 @@ describe('game status', () => {
203
258
  });
204
259
 
205
260
  describe('top-level participation commands', () => {
261
+ const activeParticipationCases = [
262
+ {
263
+ active: 'ordinary match queue',
264
+ kind: 'match',
265
+ queue: { success: true, data: { status: 'queued', mode: 'match' } },
266
+ room: undefined,
267
+ },
268
+ {
269
+ active: 'ordinary match game',
270
+ kind: 'match',
271
+ queue: { success: true, data: { status: 'allocated', mode: 'match', game_id: 'MATCH1' } },
272
+ room: undefined,
273
+ },
274
+ {
275
+ active: 'friend room lobby',
276
+ kind: 'room',
277
+ queue: { success: true, data: { status: 'in_room', mode: 'room', room_code: 'ROOM1' } },
278
+ room: {
279
+ success: true,
280
+ data: { room_code: 'ROOM1', room_type: 'casual', status: 'waiting' },
281
+ },
282
+ },
283
+ {
284
+ active: 'friend room game',
285
+ kind: 'room',
286
+ queue: { success: true, data: { status: 'allocated', mode: 'room', game_id: 'ROOMGAME1' } },
287
+ room: undefined,
288
+ },
289
+ {
290
+ active: 'simulation training lobby',
291
+ kind: 'training_simulation',
292
+ queue: {
293
+ success: true,
294
+ data: { status: 'in_room', mode: 'training_simulation', room_code: 'SIM1' },
295
+ },
296
+ room: {
297
+ success: true,
298
+ data: { room_code: 'SIM1', room_type: 'training_simulation', status: 'waiting' },
299
+ },
300
+ },
301
+ {
302
+ active: 'simulation training game',
303
+ kind: 'training_simulation',
304
+ queue: {
305
+ success: true,
306
+ data: { status: 'allocated', mode: 'training_simulation', game_id: 'SIMGAME1' },
307
+ },
308
+ room: undefined,
309
+ },
310
+ {
311
+ active: 'dummy training lobby',
312
+ kind: 'training_dummy',
313
+ queue: {
314
+ success: true,
315
+ data: { status: 'in_room', mode: 'training_dummy', room_code: 'DUMMY1' },
316
+ },
317
+ room: {
318
+ success: true,
319
+ data: { room_code: 'DUMMY1', room_type: 'training_dummy', status: 'waiting' },
320
+ },
321
+ },
322
+ {
323
+ active: 'dummy training game',
324
+ kind: 'training_dummy',
325
+ queue: {
326
+ success: true,
327
+ data: { status: 'allocated', mode: 'training_dummy', game_id: 'DUMMYGAME1' },
328
+ },
329
+ room: undefined,
330
+ },
331
+ ] as const;
332
+
333
+ const startTargetCases = [
334
+ { target: 'match', argv: ['match'], kind: 'match' },
335
+ { target: 'room', argv: ['room'], kind: 'room' },
336
+ {
337
+ target: 'training simulation',
338
+ argv: ['training', 'simulation'],
339
+ kind: 'training_simulation',
340
+ },
341
+ {
342
+ target: 'training dummy',
343
+ argv: ['training', 'dummy'],
344
+ kind: 'training_dummy',
345
+ },
346
+ ] as const;
347
+
206
348
  it('starts a new ordinary match while idle and forwards force', async () => {
207
349
  const value = statusFixture({ success: true, data: { status: 'not_in_queue' } });
208
350
  const ownerRunner = vi.fn(async () => {});
@@ -268,6 +410,34 @@ describe('top-level participation commands', () => {
268
410
  expect(ownerRunner).not.toHaveBeenCalled();
269
411
  });
270
412
 
413
+ it.each(activeParticipationCases.flatMap((active) => (
414
+ startTargetCases.map((target) => ({ active, target }))
415
+ )))('$active.active + start $target.target resumes only the same participation kind', async ({
416
+ active,
417
+ target,
418
+ }) => {
419
+ const value = statusFixture(active.queue, active.room);
420
+ const ownerRunner = vi.fn(async () => {});
421
+ const run = createStartCommand({ ...value.dependencies, ownerRunner }).parseAsync([
422
+ 'node',
423
+ 'start',
424
+ ...target.argv,
425
+ '--agent-type',
426
+ 'test-host',
427
+ ], { from: 'node' });
428
+
429
+ if (active.kind === target.kind) {
430
+ await run;
431
+ expect(ownerRunner).toHaveBeenCalledWith({ kind: 'resume' }, {
432
+ forceExistingRuntime: false,
433
+ });
434
+ return;
435
+ }
436
+
437
+ await expect(run).rejects.toThrow('another backend participation is active');
438
+ expect(ownerRunner).not.toHaveBeenCalled();
439
+ });
440
+
271
441
  it.each([
272
442
  { argv: [], roomType: 'training_simulation' },
273
443
  { argv: ['dummy'], roomType: 'training_dummy' },
@@ -312,6 +482,20 @@ describe('top-level participation commands', () => {
312
482
  });
313
483
  });
314
484
 
485
+ it.each(activeParticipationCases)('bare join resumes $active', async ({ queue, room }) => {
486
+ const value = statusFixture(queue, room);
487
+ const ownerRunner = vi.fn(async () => {});
488
+
489
+ await createJoinCommand({ ...value.dependencies, ownerRunner }).parseAsync([
490
+ 'node',
491
+ 'join',
492
+ ], { from: 'node' });
493
+
494
+ expect(ownerRunner).toHaveBeenCalledWith({ kind: 'resume' }, {
495
+ forceExistingRuntime: false,
496
+ });
497
+ });
498
+
315
499
  it('rejects bare join while the backend is idle', async () => {
316
500
  const value = statusFixture({ success: true, data: { status: 'not_in_queue' } });
317
501
  const ownerRunner = vi.fn(async () => {});
@@ -392,6 +576,31 @@ describe('top-level participation commands', () => {
392
576
  expect(differentOwner).not.toHaveBeenCalled();
393
577
  expect(different.client.leaveRoom).not.toHaveBeenCalled();
394
578
  });
579
+
580
+ it.each([
581
+ { roomType: 'training_simulation', mode: 'training_simulation' },
582
+ { roomType: 'training_dummy', mode: 'training_dummy' },
583
+ ])('refuses to join a friend room while $roomType is active', async ({ roomType, mode }) => {
584
+ const value = statusFixture(
585
+ { success: true, data: { status: 'in_room', mode, room_code: 'TRAIN1' } },
586
+ {
587
+ success: true,
588
+ data: { room_code: 'TRAIN1', room_type: roomType, status: 'waiting' },
589
+ },
590
+ );
591
+ const ownerRunner = vi.fn(async () => {});
592
+
593
+ await expect(createJoinCommand({ ...value.dependencies, ownerRunner }).parseAsync([
594
+ 'node',
595
+ 'join',
596
+ 'room',
597
+ '654321',
598
+ '--agent-type',
599
+ 'claude-code',
600
+ ], { from: 'node' })).rejects.toThrow('another backend participation is active');
601
+ expect(ownerRunner).not.toHaveBeenCalled();
602
+ expect(value.client.leaveRoom).not.toHaveBeenCalled();
603
+ });
395
604
  });
396
605
 
397
606
  describe('game quit', () => {
@@ -107,6 +107,62 @@ describe('load command', () => {
107
107
  });
108
108
  });
109
109
 
110
+ it('includes room context for an allocated room game', async () => {
111
+ const client = participationClient(
112
+ {
113
+ success: true,
114
+ data: { status: 'allocated', mode: 'room', game_id: 'GAME1' },
115
+ },
116
+ {
117
+ success: true,
118
+ data: {
119
+ room_code: 'ROOM1',
120
+ room_type: 'training_dummy',
121
+ status: 'playing',
122
+ },
123
+ },
124
+ );
125
+
126
+ await createLoadCommand({ clientFactory: () => client })
127
+ .parseAsync(['node', 'load'], { from: 'node' });
128
+
129
+ const output = JSON.parse(String(logSpy.mock.calls[0][0]));
130
+ expect(output.participation).toMatchObject({
131
+ schema: 'ccl.game-status.v1',
132
+ status: 'in_game',
133
+ queue_status: 'allocated',
134
+ mode: 'room',
135
+ game_id: 'GAME1',
136
+ room_code: 'ROOM1',
137
+ room_type: 'training_dummy',
138
+ room_status: 'playing',
139
+ });
140
+ expect(client.getRoomStatus).toHaveBeenCalledOnce();
141
+ });
142
+
143
+ it('keeps allocated room participation when room context lookup fails', async () => {
144
+ const client = {
145
+ getQueueStatus: vi.fn(async () => ({
146
+ success: true,
147
+ data: { status: 'allocated', mode: 'room', game_id: 'GAME1' },
148
+ })),
149
+ getRoomStatus: vi.fn(async () => { throw new Error('room status unavailable'); }),
150
+ };
151
+
152
+ await createLoadCommand({ clientFactory: () => client })
153
+ .parseAsync(['node', 'load'], { from: 'node' });
154
+
155
+ const output = JSON.parse(String(logSpy.mock.calls[0][0]));
156
+ expect(output.participation).toEqual({
157
+ schema: 'ccl.game-status.v1',
158
+ status: 'in_game',
159
+ queue_status: 'allocated',
160
+ mode: 'room',
161
+ game_id: 'GAME1',
162
+ });
163
+ expect(errorSpy).not.toHaveBeenCalled();
164
+ });
165
+
110
166
  it('keeps local context available when backend participation lookup fails', async () => {
111
167
  await createLoadCommand({
112
168
  clientFactory: () => ({
@@ -49,7 +49,7 @@ describe('gameplay config', () => {
49
49
  expect(config.disabled_perception_modules).toEqual(['visual.removed']);
50
50
  });
51
51
 
52
- it('requires every known role default and rejects unrelated fields', () => {
52
+ it('requires every known role default', () => {
53
53
  const dir = workspace();
54
54
  readGameplayConfig(dir);
55
55
  const path = getUserDataGameplayConfigFile(dir);
@@ -57,10 +57,24 @@ describe('gameplay config', () => {
57
57
  delete parsed.default_strategies.shrimp_generic;
58
58
  writeFileSync(path, JSON.stringify(parsed));
59
59
  expect(() => readGameplayConfig(dir)).toThrow('default_strategies.shrimp_generic');
60
+ });
60
61
 
61
- parsed.default_strategies.shrimp_generic = 'runtime-task-demo';
62
- parsed.modules = [];
63
- writeFileSync(path, JSON.stringify(parsed));
64
- expect(() => readGameplayConfig(dir)).toThrow('Unknown user-data/gameplay.json field');
62
+ it('ignores unknown top-level fields without rewriting the file', () => {
63
+ const dir = workspace();
64
+ readGameplayConfig(dir);
65
+ const path = getUserDataGameplayConfigFile(dir);
66
+ const parsed = JSON.parse(readFileSync(path, 'utf8'));
67
+
68
+ parsed.disabled_intents = ['go_to'];
69
+ parsed.fallback_idle_ms = 8_000;
70
+ const original = `${JSON.stringify(parsed, null, 2)}\n`;
71
+ writeFileSync(path, original);
72
+
73
+ expect(readGameplayConfig(dir)).toMatchObject({
74
+ default_strategies: parsed.default_strategies,
75
+ disabled_strategies: parsed.disabled_strategies,
76
+ disabled_perception_modules: parsed.disabled_perception_modules,
77
+ });
78
+ expect(readFileSync(path, 'utf8')).toBe(original);
65
79
  });
66
80
  });
@@ -34,12 +34,6 @@ export interface GameplayConfig {
34
34
  }
35
35
 
36
36
  const RESOURCE_ID = /^[a-z0-9][a-z0-9._-]*$/;
37
- const TOP_LEVEL_KEYS = new Set([
38
- 'default_strategies',
39
- 'disabled_strategies',
40
- 'disabled_perception_modules',
41
- ]);
42
-
43
37
  export function defaultGameplayConfig(): GameplayConfig {
44
38
  return {
45
39
  default_strategies: { ...NPM_ROLE_DEFAULT_STRATEGIES },
@@ -69,10 +63,6 @@ function resourceIds(value: unknown, field: string): string[] {
69
63
  export function parseGameplayConfig(value: unknown): GameplayConfig {
70
64
  const root = record(value);
71
65
  if (!root) throw new Error('user-data/gameplay.json must contain a JSON object.');
72
- const unknownKeys = Object.keys(root).filter((key) => !TOP_LEVEL_KEYS.has(key));
73
- if (unknownKeys.length > 0) {
74
- throw new Error(`Unknown user-data/gameplay.json field: ${unknownKeys.join(', ')}`);
75
- }
76
66
  const configuredDefaults = record(root.default_strategies);
77
67
  if (!configuredDefaults) {
78
68
  throw new Error('user-data/gameplay.json default_strategies must be an object.');
@@ -1,4 +1,5 @@
1
1
  import {
2
+ isRoomMode,
2
3
  isTrainingRoomMode,
3
4
  normalizeRoomSnapshot,
4
5
  queueMode,
@@ -56,9 +57,9 @@ function withOptionalFields(
56
57
  /**
57
58
  * Query the backend-owned participation state.
58
59
  *
59
- * Queue status is authoritative for idle/matching/game participation. A room
60
- * lookup is needed only while in a room because queue status intentionally
61
- * does not preserve the room type.
60
+ * Queue status is authoritative for idle/matching/game participation. Room
61
+ * participation also needs a room lookup because queue status may not preserve
62
+ * the room type or code after allocation.
62
63
  */
63
64
  export async function queryGameParticipationStatus(
64
65
  client: ParticipationStatusClient,
@@ -89,9 +90,23 @@ export async function queryGameParticipationStatus(
89
90
  }
90
91
 
91
92
  if (currentQueueStatus === 'allocated') {
92
- return withOptionalFields(base('in_game'), {
93
+ const allocated = withOptionalFields(base('in_game'), {
93
94
  game_id: stringField(queue?.game_id),
94
95
  });
96
+
97
+ if (!isRoomMode(mode)) return allocated;
98
+
99
+ try {
100
+ const room = normalizeRoomSnapshot(await client.getRoomStatus());
101
+ return withOptionalFields(allocated, {
102
+ room_code: stringField(room.room_code) ?? roomCode,
103
+ room_type: stringField(room.room_type),
104
+ room_status: stringField(room.status),
105
+ });
106
+ } catch {
107
+ // The queue allocation is still authoritative if room lookup is briefly unavailable.
108
+ return allocated;
109
+ }
95
110
  }
96
111
 
97
112
  if (currentQueueStatus === 'in_room') {
package/src/lib/room.ts CHANGED
@@ -36,6 +36,7 @@ export interface RoomSnapshot {
36
36
  game_id?: string;
37
37
  game_server_name?: string;
38
38
  ws_url?: string;
39
+ sync_reason?: string;
39
40
  [key: string]: any;
40
41
  }
41
42
 
@@ -6,6 +6,7 @@ import {
6
6
  parseServerServiceStatus,
7
7
  serverServiceStatusFromApiError,
8
8
  serverServiceStatusFromEnvelope,
9
+ serviceStatusSignature,
9
10
  } from './service-status.js';
10
11
 
11
12
  const maintenance = {
@@ -22,6 +23,30 @@ describe('service status contract', () => {
22
23
  })).toEqual({ service_status: 'maintenance_upcoming', maintenance });
23
24
  });
24
25
 
26
+ it('passes through an optional maintenance description', () => {
27
+ const describedMaintenance = {
28
+ ...maintenance,
29
+ description: '本次维护将升级匹配服务。',
30
+ };
31
+ expect(serverServiceStatusFromEnvelope({
32
+ server: { service_status: 'maintenance_upcoming', maintenance: describedMaintenance },
33
+ })).toEqual({
34
+ service_status: 'maintenance_upcoming',
35
+ maintenance: describedMaintenance,
36
+ });
37
+ });
38
+
39
+ it('treats a changed maintenance description as a new status', () => {
40
+ const status = { service_status: 'maintenance_upcoming' as const, maintenance };
41
+ expect(serviceStatusSignature({
42
+ ...status,
43
+ maintenance: { ...maintenance, description: '说明一' },
44
+ })).not.toBe(serviceStatusSignature({
45
+ ...status,
46
+ maintenance: { ...maintenance, description: '说明二' },
47
+ }));
48
+ });
49
+
25
50
  it('extracts active maintenance and Retry-After from an ApiError', () => {
26
51
  const payload = {
27
52
  success: false,
@@ -5,6 +5,7 @@ export type ServiceStatus = 'available' | 'maintenance_upcoming' | 'maintenance_
5
5
  export interface MaintenanceWindow {
6
6
  starts_at: string;
7
7
  ends_at: string;
8
+ description?: string;
8
9
  }
9
10
 
10
11
  export interface ServerServiceStatus {
@@ -32,7 +33,16 @@ function maintenanceWindow(value: unknown): MaintenanceWindow | undefined {
32
33
  if (!root) return undefined;
33
34
  const startsAt = typeof root.starts_at === 'string' ? root.starts_at : undefined;
34
35
  const endsAt = typeof root.ends_at === 'string' ? root.ends_at : undefined;
35
- return startsAt && endsAt ? { starts_at: startsAt, ends_at: endsAt } : undefined;
36
+ const description = typeof root.description === 'string' && root.description.length > 0
37
+ ? root.description
38
+ : undefined;
39
+ return startsAt && endsAt
40
+ ? {
41
+ starts_at: startsAt,
42
+ ends_at: endsAt,
43
+ ...(description ? { description } : {}),
44
+ }
45
+ : undefined;
36
46
  }
37
47
 
38
48
  function retryAfterSeconds(value: unknown): number | undefined {
@@ -107,5 +117,6 @@ export function serviceStatusSignature(status: ServerServiceStatus): string {
107
117
  status.service_status,
108
118
  status.maintenance?.starts_at ?? null,
109
119
  status.maintenance?.ends_at ?? null,
120
+ status.maintenance?.description ?? null,
110
121
  ]);
111
122
  }
@@ -7,10 +7,14 @@ describe('event-format', () => {
7
7
  const maintenance = {
8
8
  starts_at: '2026-08-05T01:00:00+00:00',
9
9
  ends_at: '2026-08-05T03:00:00+00:00',
10
+ description: '本次维护将升级匹配服务。',
10
11
  };
11
12
  expect(formatEventMessage({
12
13
  type: 'service_status', service_status: 'maintenance_upcoming', maintenance,
13
14
  })).toContain('当前请求仍可继续');
15
+ expect(formatEventMessage({
16
+ type: 'service_status', service_status: 'maintenance_upcoming', maintenance,
17
+ })).toContain(maintenance.description);
14
18
  expect(formatEventMessage({
15
19
  type: 'service_status', service_status: 'maintenance_active', maintenance,
16
20
  })).toContain('新的匹配和房间操作已停止');
@@ -251,6 +255,18 @@ describe('event-format', () => {
251
255
  expect(message).toContain('所有人已回到房间');
252
256
  });
253
257
 
258
+ it('formats an externally changed training room mode without attributing an origin', () => {
259
+ const event = {
260
+ type: 'room.type_changed',
261
+ previous_room_type: 'training_simulation',
262
+ room_type: 'training_dummy',
263
+ sync_reason: 'room_type_changed',
264
+ };
265
+
266
+ expect(formatEventMessage(event)).toContain('训练房模式已被其他方面从模拟训练切换为木桩训练');
267
+ expect(compactEventFields(event)).not.toHaveProperty('origin');
268
+ });
269
+
254
270
  it('formats current CCL lifecycle Event names as factual messages', () => {
255
271
  expect(formatEventMessage({ type: 'match_start' })).toContain('匹配长流已连接');
256
272
  expect(formatEventMessage({ type: 'quit_requested' })).toContain('正在结束');
@@ -48,6 +48,12 @@ function stringValue(value: unknown): string | undefined {
48
48
  return typeof value === 'string' && value.length > 0 ? value : undefined;
49
49
  }
50
50
 
51
+ function trainingRoomTypeLabel(value: unknown): string {
52
+ if (value === 'training_simulation') return '模拟训练';
53
+ if (value === 'training_dummy') return '木桩训练';
54
+ return text(value);
55
+ }
56
+
51
57
  function sceneDistance(
52
58
  item: Record<string, any>,
53
59
  observer: Record<string, any>,
@@ -337,11 +343,13 @@ function shortBody(event: Record<string, any>, ctx: EventFormatContext): string
337
343
  case 'service_status': {
338
344
  const startsAt = firstString(event.maintenance ?? {}, ['starts_at'], '计划时间未知');
339
345
  const endsAt = firstString(event.maintenance ?? {}, ['ends_at'], '恢复时间未知');
346
+ const description = stringValue(event.maintenance?.description);
347
+ const descriptionText = description ? `;维护说明:${description}` : '';
340
348
  if (event.service_status === 'maintenance_upcoming') {
341
- return `服务器计划于${startsAt}开始维护,预计${endsAt}恢复;当前请求仍可继续。`;
349
+ return `服务器计划于${startsAt}开始维护,预计${endsAt}恢复${descriptionText};当前请求仍可继续。`;
342
350
  }
343
351
  if (event.service_status === 'maintenance_active') {
344
- return `服务器正在维护,预计${endsAt}恢复;新的匹配和房间操作已停止。`;
352
+ return `服务器正在维护,预计${endsAt}恢复${descriptionText};新的匹配和房间操作已停止。`;
345
353
  }
346
354
  return '服务器维护已结束,服务恢复可用。';
347
355
  }
@@ -525,6 +533,8 @@ function shortBody(event: Record<string, any>, ctx: EventFormatContext): string
525
533
  return `房主变更为${playerLabel(event.name ?? event.agent_id, firstNumber(event, ['seat']), ctx)}。`;
526
534
  case 'room.full':
527
535
  return '房间人数已满。';
536
+ case 'room.type_changed':
537
+ return `训练房模式已被其他方面从${trainingRoomTypeLabel(event.previous_room_type)}切换为${trainingRoomTypeLabel(event.room_type)}。`;
528
538
  case 'room_ready_to_start':
529
539
  return '房间已满足开局条件,你是房主。';
530
540
  case 'room.chat':
@@ -11,7 +11,7 @@ import {
11
11
  } from './event-hints.js';
12
12
 
13
13
  describe('Mailbox-owned Event hint registries', () => {
14
- it('keeps 31 backend hint formatters and classifies 14 Agent Events as unregistered', () => {
14
+ it('keeps 30 backend hint formatters and classifies 15 Agent Events as unregistered', () => {
15
15
  const unregistered = CLAWCLAW_BACKEND_AGENT_EVENT_TYPES.filter((type) => (
16
16
  BACKEND_EVENT_HINT_FORMATTERS[type] === undefined
17
17
  ));
@@ -28,6 +28,7 @@ describe('Mailbox-owned Event hint registries', () => {
28
28
  'room.member_left',
29
29
  'room.owner_changed',
30
30
  'room.full',
31
+ 'room.type_changed',
31
32
  'room.chat',
32
33
  'room.game_starting',
33
34
  'room.game_start_failed',
@@ -39,11 +40,16 @@ describe('Mailbox-owned Event hint registries', () => {
39
40
  const maintenance = {
40
41
  starts_at: '2026-08-05T01:00:00+00:00',
41
42
  ends_at: '2026-08-05T03:00:00+00:00',
43
+ description: '本次维护将升级匹配服务。',
42
44
  };
43
45
  expect(formatCanonicalEventHint(
44
46
  { producer: 'backend_push' },
45
47
  { type: 'service_status', service_status: 'maintenance_upcoming', maintenance },
46
48
  )).toContain('current request succeeded');
49
+ expect(formatCanonicalEventHint(
50
+ { producer: 'backend_push' },
51
+ { type: 'service_status', service_status: 'maintenance_upcoming', maintenance },
52
+ )).toContain(maintenance.description);
47
53
  expect(formatCanonicalEventHint(
48
54
  { producer: 'backend_push' },
49
55
  { type: 'service_status', service_status: 'maintenance_active', maintenance },
@@ -113,11 +113,15 @@ export const BACKEND_EVENT_HINT_FORMATTERS: Readonly<Record<string, EventHintFor
113
113
  service_status: (event) => {
114
114
  const startsAt = text(event.maintenance?.starts_at, 'the scheduled start time');
115
115
  const endsAt = text(event.maintenance?.ends_at, 'the scheduled end time');
116
+ const description = typeof event.maintenance?.description === 'string'
117
+ && event.maintenance.description.length > 0
118
+ ? ` Maintenance description: ${event.maintenance.description}`
119
+ : '';
116
120
  if (event.service_status === 'maintenance_upcoming') {
117
- return `Tell the user that maintenance is scheduled from ${startsAt} to ${endsAt}. The current request succeeded and may continue; do not start an extra runtime.`;
121
+ return `Tell the user that maintenance is scheduled from ${startsAt} to ${endsAt}.${description} The current request succeeded and may continue; do not start an extra runtime.`;
118
122
  }
119
123
  if (event.service_status === 'maintenance_active') {
120
- return `Tell the user that the service is under maintenance until ${endsAt}. Do not retry matchmaking, room creation, room joining, or room start before then; query server status before trying again.`;
124
+ return `Tell the user that the service is under maintenance until ${endsAt}.${description} Do not retry matchmaking, room creation, room joining, or room start before then; query server status before trying again.`;
121
125
  }
122
126
  return 'The service is available again. Tell the user if they were waiting, but do not replay a previously blocked request unless they still want it.';
123
127
  },
@@ -20,6 +20,8 @@ describe('ClawClaw Monitor Event policy', () => {
20
20
 
21
21
  it('wakes for room presence and prioritizes idle termination', () => {
22
22
  expect(clawclawMonitorPriority('room.member_status_changed')).toBe(60);
23
+ expect(clawclawMonitorPriority('room.type_changed'))
24
+ .toBeGreaterThan(clawclawMonitorPriority('room_ready_to_start'));
23
25
  expect(clawclawMonitorPriority('room.idle_warning')).toBe(80);
24
26
  expect(clawclawMonitorPriority('room_destroyed')).toBe(90);
25
27
  });
@@ -4,6 +4,7 @@ export const CLAWCLAW_MONITOR_EVENT_PRIORITY: Readonly<Record<string, number>> =
4
4
  service_status: 95,
5
5
  killed: 99,
6
6
  speech_your_turn: 99,
7
+ 'room.type_changed': 95,
7
8
  vote_phase_start: 99,
8
9
  'room.game_started': 90,
9
10
  room_ready_to_start: 90,
@@ -307,6 +307,7 @@ function gameStateFrame(
307
307
  const maintenanceWindow = {
308
308
  starts_at: '2026-08-05T01:00:00+00:00',
309
309
  ends_at: '2026-08-05T03:00:00+00:00',
310
+ description: '本次维护将升级匹配服务。',
310
311
  };
311
312
 
312
313
  function maintenanceApiError(method = 'GET', path = '/api/v1/queue/status'): ApiError {
@@ -704,6 +705,70 @@ describe('ClawclawSourcePlugin lifecycle', () => {
704
705
  await runtime.close();
705
706
  });
706
707
 
708
+ it('turns a marked external training mode snapshot into one Agent Event', async () => {
709
+ const members = Array.from({ length: 10 }, (_, index) => ({
710
+ seat: index + 1,
711
+ agent_id: index === 0 ? 'self' : `bot-${index}`,
712
+ name: index === 0 ? 'me' : `Bot ${index}`,
713
+ is_owner: index === 0,
714
+ is_bot: index > 0,
715
+ status: 'online' as const,
716
+ }));
717
+ const { runtime, source, rooms } = await fixture(
718
+ [{ status: 'not_in_queue' }],
719
+ { kind: 'create_room', roomType: 'training_simulation' },
720
+ );
721
+ await waitUntil(() => rooms.length === 1, 'Training Room transport was not started.');
722
+
723
+ await rooms[0].emit('room.snapshot', {
724
+ room_code: 'R1',
725
+ room_type: 'training_simulation',
726
+ status: 'waiting',
727
+ my_seat: 1,
728
+ members,
729
+ }, {
730
+ room_code: 'R1',
731
+ room_type: 'training_simulation',
732
+ status: 'waiting',
733
+ my_seat: 1,
734
+ members,
735
+ }, 1);
736
+ await rooms[0].emit('room.snapshot', {
737
+ room_code: 'R1',
738
+ room_type: 'training_dummy',
739
+ status: 'waiting',
740
+ my_seat: 1,
741
+ members,
742
+ sync_reason: 'room_type_changed',
743
+ }, {
744
+ room_code: 'R1',
745
+ room_type: 'training_dummy',
746
+ status: 'waiting',
747
+ my_seat: 1,
748
+ members,
749
+ sync_reason: 'room_type_changed',
750
+ }, 2);
751
+ await runtime.flush();
752
+
753
+ const changes = runtime.repository.listCommittedEvents({
754
+ sessionId: runtime.scope().sessionId,
755
+ types: ['room.type_changed'],
756
+ order: 'asc',
757
+ });
758
+ expect(changes).toHaveLength(1);
759
+ expect(changes[0]?.payload).toEqual({
760
+ room_code: 'R1',
761
+ previous_room_type: 'training_simulation',
762
+ room_type: 'training_dummy',
763
+ sync_reason: 'room_type_changed',
764
+ });
765
+ expect(runtime.readReadyView().state.state?.room?.room_type).toBe('training_dummy');
766
+
767
+ await source.submitIntent({ kind: 'stop' });
768
+ await expect(source.waitForCompletion()).resolves.toEqual({ reason: 'stopped' });
769
+ await runtime.close();
770
+ });
771
+
707
772
  it('owns allocation through terminal Game State and keeps one physical frame in one epoch', async () => {
708
773
  const fixtureValue = await fixture([{
709
774
  status: 'allocated',
@@ -32,6 +32,7 @@ import {
32
32
  queueStatus,
33
33
  unwrapData,
34
34
  type RoomSnapshot,
35
+ type TrainingRoomType,
35
36
  } from '../../../../lib/room.js';
36
37
  import type {
37
38
  WsCloseInfo,
@@ -323,6 +324,7 @@ implements RuntimeSourcePlugin<Record<string, any>, Record<string, unknown>> {
323
324
  private currentQueue?: Record<string, any>;
324
325
  private currentRoom?: Record<string, any>;
325
326
  private trainingRoomControlOverlay: Record<string, any> = {};
327
+ private pendingTrainingRoomType?: TrainingRoomType;
326
328
  private hasFreshGameSnapshot = false;
327
329
  private latestFreshGameState?: Record<string, any>;
328
330
  private latestFreshGameTick?: number;
@@ -1484,6 +1486,7 @@ implements RuntimeSourcePlugin<Record<string, any>, Record<string, unknown>> {
1484
1486
  meta: RoomFrameMeta,
1485
1487
  terminalPhase?: 'room_left',
1486
1488
  ): Promise<void> {
1489
+ const previousRoomType = this.currentRoom?.room?.room_type;
1487
1490
  if (snapshot) {
1488
1491
  const roleConfig = Object.prototype.hasOwnProperty.call(snapshot, 'role_config')
1489
1492
  ? snapshot.role_config
@@ -1496,6 +1499,20 @@ implements RuntimeSourcePlugin<Record<string, any>, Record<string, unknown>> {
1496
1499
  }
1497
1500
  : { ...snapshot, ...this.trainingRoomControlOverlay };
1498
1501
  }
1502
+ const currentRoomType = snapshot?.room_type;
1503
+ const roomTypeChangedElsewhere = type === 'room.snapshot'
1504
+ && data.sync_reason === 'room_type_changed'
1505
+ && isTrainingRoomMode(previousRoomType)
1506
+ && isTrainingRoomMode(currentRoomType)
1507
+ && previousRoomType !== currentRoomType
1508
+ && this.pendingTrainingRoomType !== currentRoomType;
1509
+ if (
1510
+ type === 'room.snapshot'
1511
+ && data.sync_reason === 'room_type_changed'
1512
+ && isTrainingRoomMode(currentRoomType)
1513
+ ) {
1514
+ this.trainingRoomControlOverlay.room_type = currentRoomType;
1515
+ }
1499
1516
  const roomCode = snapshot?.room_code;
1500
1517
  if (roomCode) {
1501
1518
  this.requireRuntime().adoptResumeKey(roomCode);
@@ -1531,7 +1548,17 @@ implements RuntimeSourcePlugin<Record<string, any>, Record<string, unknown>> {
1531
1548
  else if (type === 'room.game_started' || snapshot?.status === 'playing') this.currentStage = 'loading';
1532
1549
  else this.currentStage = 'room';
1533
1550
 
1534
- let rawEvents: Record<string, unknown>[] = type === 'room.snapshot' ? [] : [{ type, ...data }];
1551
+ let rawEvents: Record<string, unknown>[] = type === 'room.snapshot'
1552
+ ? roomTypeChangedElsewhere
1553
+ ? [{
1554
+ type: 'room.type_changed',
1555
+ room_code: snapshot?.room_code,
1556
+ previous_room_type: previousRoomType,
1557
+ room_type: currentRoomType,
1558
+ sync_reason: 'room_type_changed',
1559
+ }]
1560
+ : []
1561
+ : [{ type, ...data }];
1535
1562
  if (type === 'service_status') {
1536
1563
  const serverStatus = parseServerServiceStatus(data);
1537
1564
  rawEvents = serverStatus && this.shouldEmitServiceStatus(serverStatus)
@@ -1693,11 +1720,18 @@ implements RuntimeSourcePlugin<Record<string, any>, Record<string, unknown>> {
1693
1720
  }
1694
1721
  if (intent.kind === 'training_mode') {
1695
1722
  this.requireTrainingRoomStage(intent.kind);
1696
- const result = await this.client.setTrainingRoomMode(intent.roomType);
1697
- const failure = businessFailureFromResult(result, 'Failed to change training mode.');
1698
- if (failure) throw leaveFailureError(failure);
1699
- await this.acceptTrainingRoomControlResult(result);
1700
- return result;
1723
+ this.pendingTrainingRoomType = intent.roomType;
1724
+ try {
1725
+ const result = await this.client.setTrainingRoomMode(intent.roomType);
1726
+ const failure = businessFailureFromResult(result, 'Failed to change training mode.');
1727
+ if (failure) throw leaveFailureError(failure);
1728
+ await this.acceptTrainingRoomControlResult(result);
1729
+ return result;
1730
+ } finally {
1731
+ if (this.pendingTrainingRoomType === intent.roomType) {
1732
+ this.pendingTrainingRoomType = undefined;
1733
+ }
1734
+ }
1701
1735
  }
1702
1736
  if (intent.kind === 'training_role_lock') {
1703
1737
  this.requireTrainingRoomStage(intent.kind);
@@ -16,6 +16,7 @@ describe('ClawClaw Event Catalog', () => {
16
16
  expect(CLAWCLAW_MONITOR_AND_EVENTS_EVENT_TYPES).toContain('quit_requested');
17
17
  expect(CLAWCLAW_MONITOR_AND_EVENTS_EVENT_TYPES).toContain('room_created');
18
18
  expect(CLAWCLAW_MONITOR_AND_EVENTS_EVENT_TYPES).toContain('room.member_status_changed');
19
+ expect(CLAWCLAW_MONITOR_AND_EVENTS_EVENT_TYPES).toContain('room.type_changed');
19
20
  expect(CLAWCLAW_MONITOR_AND_EVENTS_EVENT_TYPES).toContain('room.idle_warning');
20
21
  expect(CLAWCLAW_MONITOR_AND_EVENTS_EVENT_TYPES).toContain('room_destroyed');
21
22
  expect(CLAWCLAW_MONITOR_AND_EVENTS_EVENT_TYPES).toContain('players_changed');
@@ -125,6 +125,7 @@ export const CLAWCLAW_BACKEND_AGENT_EVENT_TYPES = [
125
125
  'room.member_left',
126
126
  'room.owner_changed',
127
127
  'room.full',
128
+ 'room.type_changed',
128
129
  'room.chat',
129
130
  'room.game_starting',
130
131
  'room.game_started',