@myclaw163/clawclaw-cli 0.7.9 → 0.7.11

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.
Files changed (39) hide show
  1. package/QUICKSTART_OTHER.md +2 -2
  2. package/docs/configuration.md +1 -1
  3. package/package.json +1 -1
  4. package/scripts/check-skill-command-surface.mjs +2 -0
  5. package/skills/clawclaw/SKILL.md +64 -43
  6. package/skills/clawclaw/references/CHATTERBOX.md +1 -1
  7. package/skills/clawclaw/references/CLAUDE-CODE-MONITOR.md +2 -2
  8. package/skills/clawclaw/references/COMMANDS.md +31 -19
  9. package/skills/clawclaw/references/GAME-MECHANICS.md +3 -3
  10. package/skills/clawclaw/references/STRATEGIES.md +1 -1
  11. package/skills/clawclaw/references/STREAM.md +3 -3
  12. package/src/cli.ts +7 -1
  13. package/src/commands/communication.test.ts +14 -3
  14. package/src/commands/communication.ts +12 -4
  15. package/src/commands/game/index.test.ts +198 -1
  16. package/src/commands/game/index.ts +229 -4
  17. package/src/commands/load.test.ts +68 -1
  18. package/src/commands/load.ts +26 -3
  19. package/src/pipeline/event-format.test.ts +0 -21
  20. package/src/pipeline/event-format.ts +0 -33
  21. package/src/pipeline/event-hints.test.ts +2 -5
  22. package/src/pipeline/event-hints.ts +0 -17
  23. package/src/pipeline/game-sync-event-normalization.test.ts +1 -12
  24. package/src/pipeline/game-sync-event-normalization.ts +0 -13
  25. package/src/runtime/clawclaw/plugins/strategy/strategy-action.ts +11 -4
  26. package/src/runtime/clawclaw-event-catalog.ts +0 -2
  27. package/src/sdk/action.ts +9 -8
  28. package/src/sdk/strategy-plugin/index.test.ts +3 -3
  29. package/src/sdk/strategy-plugin/index.ts +25 -24
  30. package/src/strategies/custom-module.test.ts +1 -1
  31. package/src/strategies/game-utils.test.ts +8 -8
  32. package/src/strategies/game-utils.ts +39 -28
  33. package/src/strategies/goals/crab-octopus-reflexes.ts +11 -7
  34. package/src/strategies/goals/hide-top.ts +2 -1
  35. package/src/strategies/goals/kill-target-goal.ts +2 -1
  36. package/src/strategies/goals/kill-target-top.ts +3 -3
  37. package/src/strategies/goals/lone-kill-core.ts +3 -1
  38. package/src/strategies/goals/task-kill-report-top.ts +2 -1
  39. package/src/strategies/goals/warrior-shrimp-top.ts +2 -1
@@ -49,8 +49,16 @@ export function communicationAction(kind: CommunicationActionKind, value: string
49
49
  switch (kind) {
50
50
  case 'speak':
51
51
  return Action.speech(value);
52
- case 'vote':
53
- return Action.vote(value);
52
+ case 'vote': {
53
+ // `skip` → target_seat 0 (弃票);数字 → 座位号。
54
+ const trimmed = value.trim();
55
+ if (trimmed === 'skip') return Action.vote(0);
56
+ const seat = Number(trimmed);
57
+ if (!/^\d+$/.test(trimmed) || !Number.isInteger(seat)) {
58
+ throw new Error(`invalid_vote_target: "${value}" — use a seat number or skip`);
59
+ }
60
+ return Action.vote(seat);
61
+ }
54
62
  case 'aside':
55
63
  return Action.think().withThinking(value);
56
64
  }
@@ -368,8 +376,8 @@ export function createSpeakCommand(dependencies: CommunicationCommandDependencie
368
376
 
369
377
  export function createVoteCommand(dependencies: CommunicationCommandDependencies = {}): Command {
370
378
  return new Command('vote')
371
- .description('Vote for a player during a meeting')
372
- .argument('<target>', 'Player name or skip')
379
+ .description('Vote for a player (by seat number) during a meeting, or skip')
380
+ .argument('<target>', 'Seat number (1-10) of the player to vote out, or skip')
373
381
  .action(async (target: string) => {
374
382
  await submitCommunicationAction({
375
383
  command: 'ccl vote',
@@ -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
  }
@@ -147,26 +147,6 @@ describe('event-format', () => {
147
147
  });
148
148
  });
149
149
 
150
- it('fills crab teammate seats from the opening seat map', () => {
151
- const ctx = {
152
- summary: {
153
- players: [{ name: '菜逼油条', seat: 8, known_status: { is_alive: true } }],
154
- },
155
- };
156
- const event = {
157
- type: 'crab_teammates',
158
- tick: 20,
159
- teammates: ['菜逼油条'],
160
- };
161
-
162
- expect(formatEventMessage(event, ctx)).toBe('t20 crab_teammates 蟹队友:8号菜逼油条。');
163
- expect(compactEventFields(event, ctx)).toMatchObject({
164
- type: 'crab_teammates',
165
- tick: 20,
166
- crab_teammates: [{ name: '菜逼油条', seat: 8 }],
167
- });
168
- });
169
-
170
150
  it('formats death_speech with explicit speaker fields', () => {
171
151
  const event = {
172
152
  type: 'death_speech',
@@ -643,7 +623,6 @@ describe('event-format', () => {
643
623
  it('keeps local hint formatters for backend-hinted monitor events', () => {
644
624
  const backendHintedMonitorEvents = [
645
625
  'corpse_spotted',
646
- 'crab_teammates',
647
626
  'emergency_resolved',
648
627
  'emergency_started',
649
628
  'exile',