@myclaw163/clawclaw-cli 0.7.10 → 0.7.12

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.
@@ -2,7 +2,12 @@ import { describe, expect, it, vi } from 'vitest';
2
2
  import type { AuthProfile } from '../../lib/auth.js';
3
3
  import { ApiError } from '../../lib/game-client.js';
4
4
  import { jsonTransportResponse } from '../../short-command/transport-response.js';
5
- import { createGameCommand, type GameCommandDependencies } from './index.js';
5
+ import {
6
+ createGameCommand,
7
+ createJoinCommand,
8
+ createStartCommand,
9
+ type GameCommandDependencies,
10
+ } from './index.js';
6
11
 
7
12
  const profile: AuthProfile = {
8
13
  agentName: 'quit-test',
@@ -197,6 +202,198 @@ describe('game status', () => {
197
202
  });
198
203
  });
199
204
 
205
+ describe('top-level participation commands', () => {
206
+ it('starts a new ordinary match while idle and forwards force', async () => {
207
+ const value = statusFixture({ success: true, data: { status: 'not_in_queue' } });
208
+ const ownerRunner = vi.fn(async () => {});
209
+
210
+ await createStartCommand({ ...value.dependencies, ownerRunner }).parseAsync([
211
+ 'node',
212
+ 'start',
213
+ 'match',
214
+ '--agent-type',
215
+ 'claude-code',
216
+ '--llm-model',
217
+ 'claude-opus-4-8',
218
+ '--force',
219
+ ], { from: 'node' });
220
+
221
+ expect(ownerRunner).toHaveBeenCalledWith({
222
+ kind: 'match',
223
+ mode: 'match',
224
+ agentType: 'claude-code',
225
+ llmModel: 'claude-opus-4-8',
226
+ }, {
227
+ forceExistingRuntime: true,
228
+ });
229
+ });
230
+
231
+ it('resumes an existing ordinary match instead of creating a duplicate', async () => {
232
+ const value = statusFixture({
233
+ success: true,
234
+ data: { status: 'queued', mode: 'match' },
235
+ });
236
+ const ownerRunner = vi.fn(async () => {});
237
+
238
+ await createStartCommand({ ...value.dependencies, ownerRunner }).parseAsync([
239
+ 'node',
240
+ 'start',
241
+ 'match',
242
+ '--agent-type',
243
+ 'claude-code',
244
+ ], { from: 'node' });
245
+
246
+ expect(ownerRunner).toHaveBeenCalledWith({ kind: 'resume' }, {
247
+ forceExistingRuntime: false,
248
+ });
249
+ });
250
+
251
+ it('rejects starting a match while a training room is active', async () => {
252
+ const value = statusFixture(
253
+ { success: true, data: { status: 'in_room', mode: 'training_dummy', room_code: 'ROOM1' } },
254
+ {
255
+ success: true,
256
+ data: { room_code: 'ROOM1', room_type: 'training_dummy', status: 'waiting' },
257
+ },
258
+ );
259
+ const ownerRunner = vi.fn(async () => {});
260
+
261
+ await expect(createStartCommand({ ...value.dependencies, ownerRunner }).parseAsync([
262
+ 'node',
263
+ 'start',
264
+ 'match',
265
+ '--agent-type',
266
+ 'claude-code',
267
+ ], { from: 'node' })).rejects.toThrow('another backend participation is active');
268
+ expect(ownerRunner).not.toHaveBeenCalled();
269
+ });
270
+
271
+ it.each([
272
+ { argv: [], roomType: 'training_simulation' },
273
+ { argv: ['dummy'], roomType: 'training_dummy' },
274
+ ])('creates training mode $roomType from the simplified command', async ({ argv, roomType }) => {
275
+ const value = statusFixture({ success: true, data: { status: 'not_in_queue' } });
276
+ const ownerRunner = vi.fn(async () => {});
277
+
278
+ await createStartCommand({ ...value.dependencies, ownerRunner }).parseAsync([
279
+ 'node',
280
+ 'start',
281
+ 'training',
282
+ ...argv,
283
+ '--agent-type',
284
+ 'test-host',
285
+ ], { from: 'node' });
286
+
287
+ expect(ownerRunner).toHaveBeenCalledWith({
288
+ kind: 'create_room',
289
+ roomType,
290
+ agentType: 'test-host',
291
+ llmModel: undefined,
292
+ }, {
293
+ forceExistingRuntime: false,
294
+ });
295
+ });
296
+
297
+ it('joins the current backend participation and replaces a stale runtime with force', async () => {
298
+ const value = statusFixture({
299
+ success: true,
300
+ data: { status: 'allocated', mode: 'match', game_id: 'GAME1' },
301
+ });
302
+ const ownerRunner = vi.fn(async () => {});
303
+
304
+ await createJoinCommand({ ...value.dependencies, ownerRunner }).parseAsync([
305
+ 'node',
306
+ 'join',
307
+ '--force',
308
+ ], { from: 'node' });
309
+
310
+ expect(ownerRunner).toHaveBeenCalledWith({ kind: 'resume' }, {
311
+ forceExistingRuntime: true,
312
+ });
313
+ });
314
+
315
+ it('rejects bare join while the backend is idle', async () => {
316
+ const value = statusFixture({ success: true, data: { status: 'not_in_queue' } });
317
+ const ownerRunner = vi.fn(async () => {});
318
+
319
+ await expect(createJoinCommand({ ...value.dependencies, ownerRunner }).parseAsync([
320
+ 'node',
321
+ 'join',
322
+ ], { from: 'node' })).rejects.toThrow('No active backend participation to join.');
323
+ expect(ownerRunner).not.toHaveBeenCalled();
324
+ });
325
+
326
+ it('joins a specified room while idle and passes Agent metadata', async () => {
327
+ const value = statusFixture({ success: true, data: { status: 'not_in_queue' } });
328
+ const ownerRunner = vi.fn(async () => {});
329
+
330
+ await createJoinCommand({ ...value.dependencies, ownerRunner }).parseAsync([
331
+ 'node',
332
+ 'join',
333
+ 'room',
334
+ '123456',
335
+ '--agent-type',
336
+ 'openclaw',
337
+ '--llm-model',
338
+ 'deepseek-v4-pro',
339
+ ], { from: 'node' });
340
+
341
+ expect(ownerRunner).toHaveBeenCalledWith({
342
+ kind: 'join_room',
343
+ roomCode: '123456',
344
+ agentType: 'openclaw',
345
+ llmModel: 'deepseek-v4-pro',
346
+ }, {
347
+ forceExistingRuntime: false,
348
+ });
349
+ });
350
+
351
+ it('resumes the same room but refuses to switch rooms implicitly', async () => {
352
+ const currentRoom = {
353
+ success: true,
354
+ data: { room_code: '123456', room_type: 'casual', status: 'waiting' },
355
+ };
356
+ const same = statusFixture(
357
+ { success: true, data: { status: 'in_room', mode: 'room', room_code: '123456' } },
358
+ currentRoom,
359
+ );
360
+ const sameOwner = vi.fn(async () => {});
361
+
362
+ await createJoinCommand({ ...same.dependencies, ownerRunner: sameOwner }).parseAsync([
363
+ 'node',
364
+ 'join',
365
+ 'room',
366
+ '123456',
367
+ '--agent-type',
368
+ 'claude-code',
369
+ ], { from: 'node' });
370
+
371
+ expect(sameOwner).toHaveBeenCalledWith({ kind: 'resume' }, {
372
+ forceExistingRuntime: false,
373
+ });
374
+
375
+ const different = statusFixture(
376
+ { success: true, data: { status: 'in_room', mode: 'room', room_code: '123456' } },
377
+ currentRoom,
378
+ );
379
+ const differentOwner = vi.fn(async () => {});
380
+
381
+ await expect(createJoinCommand({
382
+ ...different.dependencies,
383
+ ownerRunner: differentOwner,
384
+ }).parseAsync([
385
+ 'node',
386
+ 'join',
387
+ 'room',
388
+ '654321',
389
+ '--agent-type',
390
+ 'claude-code',
391
+ ], { from: 'node' })).rejects.toThrow('another backend participation is active');
392
+ expect(differentOwner).not.toHaveBeenCalled();
393
+ expect(different.client.leaveRoom).not.toHaveBeenCalled();
394
+ });
395
+ });
396
+
200
397
  describe('game quit', () => {
201
398
  it('reports HTTP 200 STILL_ALIVE as a remote failure and stops only the local runtime', async () => {
202
399
  const value = fixture(
@@ -10,12 +10,16 @@ import {
10
10
  } from '../../lib/participation-leave.js';
11
11
  import {
12
12
  isRoomMode,
13
+ isTrainingRoomMode,
13
14
  queueMode,
14
15
  queueStatus,
15
16
  unwrapData,
16
17
  type TrainingRoomType,
17
18
  } from '../../lib/room.js';
18
- import { queryGameParticipationStatus } from '../../lib/participation-status.js';
19
+ import {
20
+ queryGameParticipationStatus,
21
+ type GameParticipationStatus,
22
+ } from '../../lib/participation-status.js';
19
23
  import { setMeta } from '../../lib/command-meta.js';
20
24
  import { ShortCommandRunner } from '../../short-command/runner.js';
21
25
  import { createProcessCanonicalEventEmitter } from '../../runtime/canonical-event-emitter.js';
@@ -43,6 +47,23 @@ interface DesktopEventCliOptions {
43
47
  desktopEventToken?: string;
44
48
  }
45
49
 
50
+ interface OwnerCliOptions extends DesktopEventCliOptions {
51
+ agentType: string;
52
+ llmModel?: string;
53
+ force?: boolean;
54
+ }
55
+
56
+ interface ResumeCliOptions extends DesktopEventCliOptions {
57
+ force?: boolean;
58
+ }
59
+
60
+ interface JoinCliOptions extends ResumeCliOptions {
61
+ agentType?: string;
62
+ llmModel?: string;
63
+ }
64
+
65
+ type ParticipationKind = 'match' | 'room' | TrainingRoomType;
66
+
46
67
  interface GameCommandIo {
47
68
  writeStdout(text: string): void;
48
69
  setExitCode(code: number): void;
@@ -448,14 +469,218 @@ async function quitParticipation(dependencies: GameCommandDependencies = {}): Pr
448
469
  async function showParticipationStatus(
449
470
  dependencies: GameCommandDependencies = {},
450
471
  ): Promise<void> {
451
- (dependencies.activeProfile ?? activeProfile)();
452
- const client = (dependencies.clientFactory ?? (() => GameClient.fromAuth()))();
453
472
  const io = dependencies.io ?? processGameCommandIo;
454
- const status = await queryGameParticipationStatus(client);
473
+ const status = await readParticipationStatus(dependencies);
455
474
  io.writeStdout(`${JSON.stringify(status, null, 2)}\n`);
456
475
  io.setExitCode(status.status === 'unknown' ? 1 : 0);
457
476
  }
458
477
 
478
+ async function readParticipationStatus(
479
+ dependencies: GameCommandDependencies,
480
+ ): Promise<GameParticipationStatus> {
481
+ (dependencies.activeProfile ?? activeProfile)();
482
+ const client = (dependencies.clientFactory ?? (() => GameClient.fromAuth()))();
483
+ return queryGameParticipationStatus(client);
484
+ }
485
+
486
+ function participationKind(status: GameParticipationStatus): ParticipationKind | undefined {
487
+ if (status.status === 'matching') return 'match';
488
+ if (status.status === 'friend_room') return 'room';
489
+ if (status.status === 'training_room') {
490
+ const roomType = status.room_type ?? status.mode;
491
+ return isTrainingRoomMode(roomType) ? roomType : undefined;
492
+ }
493
+ if (status.status === 'room') {
494
+ const roomType = status.room_type ?? status.mode;
495
+ return isTrainingRoomMode(roomType) ? roomType : 'room';
496
+ }
497
+ if (status.status === 'in_game') {
498
+ if (isTrainingRoomMode(status.mode)) return status.mode;
499
+ return isRoomMode(status.mode) ? 'room' : 'match';
500
+ }
501
+ return undefined;
502
+ }
503
+
504
+ function participationLabel(status: GameParticipationStatus): string {
505
+ const fields = [
506
+ `status=${status.status}`,
507
+ status.mode ? `mode=${status.mode}` : undefined,
508
+ status.room_type ? `room_type=${status.room_type}` : undefined,
509
+ status.room_code ? `room_code=${status.room_code}` : undefined,
510
+ ].filter((value): value is string => value !== undefined);
511
+ return fields.join(', ');
512
+ }
513
+
514
+ function participationConflict(operation: string, status: GameParticipationStatus): Error {
515
+ return new Error(
516
+ `Cannot ${operation} while another backend participation is active (${participationLabel(status)}). Run ccl join to continue it, or quit it before switching.`,
517
+ );
518
+ }
519
+
520
+ async function resolveStartIntent(
521
+ target: ParticipationKind,
522
+ createIntent: GameOwnerIntent,
523
+ dependencies: GameCommandDependencies,
524
+ ): Promise<GameOwnerIntent> {
525
+ const status = await readParticipationStatus(dependencies);
526
+ if (status.status === 'idle') return createIntent;
527
+ if (status.status === 'unknown') {
528
+ throw new Error('Cannot start because the backend participation status is unknown.');
529
+ }
530
+ if (participationKind(status) === target) return { kind: 'resume' };
531
+ throw participationConflict(`start ${target}`, status);
532
+ }
533
+
534
+ async function resolveResumeIntent(
535
+ dependencies: GameCommandDependencies,
536
+ ): Promise<GameOwnerIntent> {
537
+ const status = await readParticipationStatus(dependencies);
538
+ if (status.status === 'idle') {
539
+ throw new Error('No active backend participation to join.');
540
+ }
541
+ if (status.status === 'unknown') {
542
+ throw new Error('Cannot join because the backend participation status is unknown.');
543
+ }
544
+ return { kind: 'resume' };
545
+ }
546
+
547
+ async function resolveJoinRoomIntent(
548
+ roomCode: string,
549
+ metadata: { agentType: string; llmModel?: string },
550
+ dependencies: GameCommandDependencies,
551
+ ): Promise<GameOwnerIntent> {
552
+ const status = await readParticipationStatus(dependencies);
553
+ if (status.status === 'idle') {
554
+ return {
555
+ kind: 'join_room',
556
+ roomCode,
557
+ agentType: metadata.agentType,
558
+ llmModel: metadata.llmModel,
559
+ };
560
+ }
561
+ if (status.status === 'unknown') {
562
+ throw new Error('Cannot join a room because the backend participation status is unknown.');
563
+ }
564
+ const currentKind = participationKind(status);
565
+ if (
566
+ (currentKind === 'room' || isTrainingRoomMode(currentKind))
567
+ && status.room_code === roomCode
568
+ ) {
569
+ return { kind: 'resume' };
570
+ }
571
+ throw participationConflict(`join room ${roomCode}`, status);
572
+ }
573
+
574
+ function ownerRunOptions(options: ResumeCliOptions): GameOwnerRunOptions {
575
+ const desktopEvents = desktopEventConfig(options);
576
+ return {
577
+ forceExistingRuntime: options.force === true,
578
+ ...(desktopEvents ? { desktopEvents } : {}),
579
+ };
580
+ }
581
+
582
+ async function runTopLevelOwner(
583
+ intent: GameOwnerIntent,
584
+ options: ResumeCliOptions,
585
+ dependencies: GameCommandDependencies,
586
+ ): Promise<void> {
587
+ const ownerRunner = dependencies.ownerRunner ?? runOwner;
588
+ await ownerRunner(intent, ownerRunOptions(options));
589
+ }
590
+
591
+ export function createStartCommand(
592
+ dependencies: GameCommandDependencies = {},
593
+ ): Command {
594
+ const start = new Command('start').description('Create or resume a ClawClaw participation');
595
+
596
+ addDesktopEventOptions(start
597
+ .command('match')
598
+ .description('Start ordinary matchmaking, or resume an existing ordinary match')
599
+ .requiredOption('--agent-type <platform>')
600
+ .option('--llm-model <model>')
601
+ .option('--force', 'replace an existing local runtime process before starting'))
602
+ .action(async (options: OwnerCliOptions) => {
603
+ const intent = await resolveStartIntent('match', {
604
+ kind: 'match',
605
+ mode: 'match',
606
+ agentType: options.agentType,
607
+ llmModel: options.llmModel,
608
+ }, dependencies);
609
+ await runTopLevelOwner(intent, options, dependencies);
610
+ });
611
+
612
+ addDesktopEventOptions(start
613
+ .command('room')
614
+ .description('Create a friend room, or resume an existing friend-room participation')
615
+ .requiredOption('--agent-type <platform>')
616
+ .option('--llm-model <model>')
617
+ .option('--force', 'replace an existing local runtime process before starting'))
618
+ .action(async (options: OwnerCliOptions) => {
619
+ const intent = await resolveStartIntent('room', {
620
+ kind: 'create_room',
621
+ agentType: options.agentType,
622
+ llmModel: options.llmModel,
623
+ }, dependencies);
624
+ await runTopLevelOwner(intent, options, dependencies);
625
+ });
626
+
627
+ addDesktopEventOptions(start
628
+ .command('training')
629
+ .description('Create a training room, or resume the same training mode')
630
+ .argument('[simulation|dummy]', 'training ruleset', trainingRoomType, 'training_simulation')
631
+ .requiredOption('--agent-type <platform>')
632
+ .option('--llm-model <model>')
633
+ .option('--force', 'replace an existing local runtime process before starting'))
634
+ .action(async (roomType: TrainingRoomType, options: OwnerCliOptions) => {
635
+ const intent = await resolveStartIntent(roomType, {
636
+ kind: 'create_room',
637
+ roomType,
638
+ agentType: options.agentType,
639
+ llmModel: options.llmModel,
640
+ }, dependencies);
641
+ await runTopLevelOwner(intent, options, dependencies);
642
+ });
643
+
644
+ return start;
645
+ }
646
+
647
+ export function createJoinCommand(
648
+ dependencies: GameCommandDependencies = {},
649
+ ): Command {
650
+ return addDesktopEventOptions(new Command('join')
651
+ .description('Resume the current participation, or join a specific friend room')
652
+ .argument('[target]', 'omit to resume, or use "room" to join a friend room')
653
+ .argument('[room_code]', 'friend room code when target is "room"')
654
+ .option('--agent-type <platform>')
655
+ .option('--llm-model <model>')
656
+ .option('--force', 'replace an existing local runtime process before joining'))
657
+ .action(async (
658
+ target: string | undefined,
659
+ roomCode: string | undefined,
660
+ options: JoinCliOptions,
661
+ ) => {
662
+ if (target === undefined) {
663
+ const intent = await resolveResumeIntent(dependencies);
664
+ await runTopLevelOwner(intent, options, dependencies);
665
+ return;
666
+ }
667
+ if (target !== 'room') {
668
+ throw new InvalidArgumentError('Join target must be "room", or omitted to resume.');
669
+ }
670
+ if (!roomCode) {
671
+ throw new InvalidArgumentError('A room code is required for `ccl join room`.');
672
+ }
673
+ if (!options.agentType) {
674
+ throw new InvalidArgumentError('--agent-type is required when joining a room.');
675
+ }
676
+ const intent = await resolveJoinRoomIntent(roomCode, {
677
+ agentType: options.agentType,
678
+ llmModel: options.llmModel,
679
+ }, dependencies);
680
+ await runTopLevelOwner(intent, options, dependencies);
681
+ });
682
+ }
683
+
459
684
  export function createGameCommand(dependencies: GameCommandDependencies = {}): Command {
460
685
  const game = new Command('game').description('Game participation and inspection');
461
686
  const ownerRunner = dependencies.ownerRunner ?? runOwner;
@@ -17,6 +17,16 @@ import { loadContext } from '../lib/load-context.js';
17
17
  import { createLoadCommand } from './load.js';
18
18
  import { updateGameplayConfig } from '../lib/gameplay-config.js';
19
19
 
20
+ function participationClient(
21
+ queue: Record<string, unknown>,
22
+ room: Record<string, unknown> = { success: true, data: {} },
23
+ ) {
24
+ return {
25
+ getQueueStatus: vi.fn(async () => queue),
26
+ getRoomStatus: vi.fn(async () => room),
27
+ };
28
+ }
29
+
20
30
  describe('load command', () => {
21
31
  let logSpy: ReturnType<typeof vi.spyOn>;
22
32
  let errorSpy: ReturnType<typeof vi.spyOn>;
@@ -43,7 +53,8 @@ describe('load command', () => {
43
53
  });
44
54
 
45
55
  it('runs auto-upgrade check before printing JSON load context', async () => {
46
- const cmd = createLoadCommand();
56
+ const client = participationClient({ success: true, data: { status: 'not_in_queue' } });
57
+ const cmd = createLoadCommand({ clientFactory: () => client });
47
58
  await cmd.parseAsync(['node', 'load'], { from: 'node' });
48
59
 
49
60
  expect(runAutoUpgradeOnLoad).toHaveBeenCalledOnce();
@@ -52,6 +63,11 @@ describe('load command', () => {
52
63
  expect(output).toMatchObject({
53
64
  persona: { exists: true },
54
65
  memory: { exists: false },
66
+ participation: {
67
+ schema: 'ccl.game-status.v1',
68
+ status: 'idle',
69
+ queue_status: 'not_in_queue',
70
+ },
55
71
  });
56
72
  expect(output.strategies).toEqual(expect.arrayContaining([
57
73
  expect.objectContaining({
@@ -61,6 +77,57 @@ describe('load command', () => {
61
77
  }),
62
78
  ]));
63
79
  expect(existsSync(join(workspaceDir, 'user-data', 'strategies', 'task-only.ts'))).toBe(true);
80
+ expect(client.getQueueStatus).toHaveBeenCalledWith('clawclaw');
81
+ });
82
+
83
+ it('includes the current backend room participation', async () => {
84
+ const client = participationClient(
85
+ { success: true, data: { status: 'in_room', mode: 'room', room_code: 'QUEUE1' } },
86
+ {
87
+ success: true,
88
+ data: {
89
+ room_code: 'ROOM1',
90
+ room_type: 'training_dummy',
91
+ status: 'playing',
92
+ },
93
+ },
94
+ );
95
+
96
+ await createLoadCommand({ clientFactory: () => client })
97
+ .parseAsync(['node', 'load'], { from: 'node' });
98
+
99
+ const output = JSON.parse(String(logSpy.mock.calls[0][0]));
100
+ expect(output.participation).toMatchObject({
101
+ schema: 'ccl.game-status.v1',
102
+ status: 'training_room',
103
+ queue_status: 'in_room',
104
+ room_code: 'ROOM1',
105
+ room_type: 'training_dummy',
106
+ room_status: 'playing',
107
+ });
108
+ });
109
+
110
+ it('keeps local context available when backend participation lookup fails', async () => {
111
+ await createLoadCommand({
112
+ clientFactory: () => ({
113
+ getQueueStatus: vi.fn(async () => { throw new Error('backend offline'); }),
114
+ getRoomStatus: vi.fn(),
115
+ }),
116
+ }).parseAsync(['node', 'load'], { from: 'node' });
117
+
118
+ const output = JSON.parse(String(logSpy.mock.calls[0][0]));
119
+ expect(output).toMatchObject({
120
+ persona: { exists: true },
121
+ memory: { exists: false },
122
+ participation: {
123
+ schema: 'ccl.game-status.v1',
124
+ status: 'unknown',
125
+ queue_status: null,
126
+ },
127
+ });
128
+ expect(errorSpy).toHaveBeenCalledWith(
129
+ '[clawclaw-cli] participation status unavailable: backend offline',
130
+ );
64
131
  });
65
132
 
66
133
  it('routes auto-upgrade notifications to stderr', async () => {
@@ -8,10 +8,20 @@ import {
8
8
  } from '../runtime/clawclaw/plugins/strategy/index.js';
9
9
  import { readGameplayConfig } from '../lib/gameplay-config.js';
10
10
  import { syncOfficialStrategies } from '../lib/strategy-export.js';
11
+ import { GameClient } from '../lib/game-client.js';
12
+ import {
13
+ GAME_STATUS_SCHEMA,
14
+ queryGameParticipationStatus,
15
+ type ParticipationStatusClient,
16
+ } from '../lib/participation-status.js';
17
+
18
+ export interface LoadCommandDependencies {
19
+ clientFactory?: () => ParticipationStatusClient;
20
+ }
11
21
 
12
- export function createLoadCommand(): Command {
22
+ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): Command {
13
23
  return new Command('load')
14
- .description('Read active account persona, memory, and available strategies')
24
+ .description('Read active account context, strategies, and backend participation')
15
25
  .action(async () => {
16
26
  runAutoUpgradeOnLoad({ notify: (message) => console.error(message) });
17
27
  let snapshot;
@@ -34,6 +44,19 @@ export function createLoadCommand(): Command {
34
44
  name,
35
45
  description,
36
46
  }));
37
- console.log(JSON.stringify({ ...snapshot, strategies }, null, 2));
47
+ let participation;
48
+ try {
49
+ const client = (dependencies.clientFactory ?? (() => GameClient.fromAuth()))();
50
+ participation = await queryGameParticipationStatus(client);
51
+ } catch (error) {
52
+ participation = {
53
+ schema: GAME_STATUS_SCHEMA,
54
+ status: 'unknown' as const,
55
+ queue_status: null,
56
+ };
57
+ const message = error instanceof Error ? error.message : String(error);
58
+ console.error(`[clawclaw-cli] participation status unavailable: ${message}`);
59
+ }
60
+ console.log(JSON.stringify({ ...snapshot, strategies, participation }, null, 2));
38
61
  });
39
62
  }
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
 
@@ -251,6 +251,18 @@ describe('event-format', () => {
251
251
  expect(message).toContain('所有人已回到房间');
252
252
  });
253
253
 
254
+ it('formats an externally changed training room mode without attributing an origin', () => {
255
+ const event = {
256
+ type: 'room.type_changed',
257
+ previous_room_type: 'training_simulation',
258
+ room_type: 'training_dummy',
259
+ sync_reason: 'room_type_changed',
260
+ };
261
+
262
+ expect(formatEventMessage(event)).toContain('训练房模式已被其他方面从模拟训练切换为木桩训练');
263
+ expect(compactEventFields(event)).not.toHaveProperty('origin');
264
+ });
265
+
254
266
  it('formats current CCL lifecycle Event names as factual messages', () => {
255
267
  expect(formatEventMessage({ type: 'match_start' })).toContain('匹配长流已连接');
256
268
  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>,
@@ -525,6 +531,8 @@ function shortBody(event: Record<string, any>, ctx: EventFormatContext): string
525
531
  return `房主变更为${playerLabel(event.name ?? event.agent_id, firstNumber(event, ['seat']), ctx)}。`;
526
532
  case 'room.full':
527
533
  return '房间人数已满。';
534
+ case 'room.type_changed':
535
+ return `训练房模式已被其他方面从${trainingRoomTypeLabel(event.previous_room_type)}切换为${trainingRoomTypeLabel(event.room_type)}。`;
528
536
  case 'room_ready_to_start':
529
537
  return '房间已满足开局条件,你是房主。';
530
538
  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',