@myclaw163/clawclaw-cli 0.6.110 → 0.6.111

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myclaw163/clawclaw-cli",
3
- "version": "0.6.110",
3
+ "version": "0.6.111",
4
4
  "type": "module",
5
5
  "description": "ClawClaw social deduction game CLI",
6
6
  "bin": {
@@ -1,16 +1,19 @@
1
- import { describe, expect, it } from 'vitest';
1
+ import { describe, expect, it, vi } from 'vitest';
2
2
  import {
3
+ backendSpectateUrl,
3
4
  createGameCommand,
4
5
  gameStrategyIdentity,
5
6
  joinedLifecyclePayload,
6
7
  leaveGameFailureFromResult,
7
- lobbyWatchUrl,
8
8
  planGameStartAction,
9
9
  planRoomEntryStreamGuard,
10
10
  planRoomJoinAction,
11
+ resumedSpectateLifecycle,
11
12
  roomStartFailureFromError,
12
13
  } from './game.js';
13
14
  import { ApiError } from '../lib/http-transport.js';
15
+ import { AuthStore } from '../lib/auth.js';
16
+ import { GameClient } from '../lib/game-client.js';
14
17
 
15
18
  describe('planGameStartAction', () => {
16
19
  it('returns the running game start pid when a stream is already alive', () => {
@@ -243,12 +246,44 @@ describe('game command help', () => {
243
246
  });
244
247
  });
245
248
 
246
- describe('lobbyWatchUrl', () => {
247
- it('preserves http for test server lobby links', () => {
248
- expect(lobbyWatchUrl({
249
- serverUrl: 'http://10.1.9.59:30900/claw',
250
- apiKey: 'claw_test key',
251
- })).toBe('http://10.1.9.59:30900/lobby?token=claw_test%20key');
249
+ describe('backendSpectateUrl', () => {
250
+ it('returns the backend URL unchanged from a wrapped queue status response', () => {
251
+ const url = 'https://myclaw.163.com/lobby#code=AbCdEf12';
252
+ expect(backendSpectateUrl({
253
+ success: true,
254
+ data: { status: 'queued', spectate_url: url },
255
+ })).toBe(url);
256
+ });
257
+
258
+ it('does not synthesize a URL when the backend omits it', () => {
259
+ expect(backendSpectateUrl({ success: true, data: { status: 'queued' } })).toBeUndefined();
260
+ });
261
+
262
+ it('makes game watch request queue status and print the backend URL', async () => {
263
+ const url = 'https://myclaw.163.com/lobby#code=AbCdEf12';
264
+ const getQueueStatus = vi.fn().mockResolvedValue({
265
+ success: true,
266
+ data: { status: 'queued', spectate_url: url },
267
+ });
268
+ vi.spyOn(AuthStore.prototype, 'getActive').mockReturnValue({
269
+ agentName: 'tester',
270
+ apiKey: 'claw_test',
271
+ serverUrl: 'https://api.example.test',
272
+ } as any);
273
+ vi.spyOn(GameClient, 'fromAuth').mockReturnValue({ getQueueStatus } as any);
274
+ const log = vi.spyOn(console, 'log').mockImplementation(() => {});
275
+
276
+ try {
277
+ await createGameCommand().parseAsync(['node', 'ccl-game', 'watch']);
278
+ expect(getQueueStatus).toHaveBeenCalledOnce();
279
+ expect(getQueueStatus).toHaveBeenCalledWith('clawclaw');
280
+ expect(log).toHaveBeenCalledWith(JSON.stringify({
281
+ url,
282
+ message: 'Open in browser to spectate.',
283
+ }, null, 2));
284
+ } finally {
285
+ vi.restoreAllMocks();
286
+ }
252
287
  });
253
288
  });
254
289
 
@@ -272,3 +307,50 @@ describe('joinedLifecyclePayload', () => {
272
307
  });
273
308
  });
274
309
  });
310
+
311
+ describe('resumedSpectateLifecycle', () => {
312
+ const url = 'https://myclaw.163.com/lobby#code=AbCdEf12';
313
+
314
+ it('reuses the normal joined URL contract for a confirmed match resume', () => {
315
+ const queue = { success: true, data: { status: 'queued', mode: 'match', spectate_url: url } };
316
+
317
+ expect(resumedSpectateLifecycle(queue, 'match')).toEqual({
318
+ reason: 'joined',
319
+ payload: {
320
+ ...queue,
321
+ url,
322
+ queue,
323
+ resumed: true,
324
+ },
325
+ nextStep: 'Game runtime reattached. Spectate URL is in events[0].url; share it with the user. Keep the game stream attached.',
326
+ });
327
+ });
328
+
329
+ it('reuses the normal room_joined contract for a confirmed room resume', () => {
330
+ const queue = { success: true, data: { status: 'in_room', mode: 'room', room_code: '123456', spectate_url: url } };
331
+
332
+ expect(resumedSpectateLifecycle(queue, 'room')).toEqual({
333
+ reason: 'room_joined',
334
+ payload: {
335
+ status: 'in_room',
336
+ mode: 'room',
337
+ room_code: '123456',
338
+ spectate_url: url,
339
+ resumed: true,
340
+ },
341
+ nextStep: 'Room runtime reattached. Share events[0].spectate_url with the user as the room page link. Keep the room stream attached.',
342
+ });
343
+ });
344
+
345
+ it('does not announce a queued room allocation before the runtime attaches', () => {
346
+ const queue = { data: { status: 'queued', mode: 'room', spectate_url: url } };
347
+ expect(resumedSpectateLifecycle(queue, 'room')).toBeUndefined();
348
+ expect(resumedSpectateLifecycle(queue, 'match')).toBeUndefined();
349
+ });
350
+
351
+ it('does not announce inactive, mismatched, or URL-less status results', () => {
352
+ expect(resumedSpectateLifecycle({ data: { status: 'not_in_queue', spectate_url: url } }, 'match')).toBeUndefined();
353
+ expect(resumedSpectateLifecycle({ data: { status: 'allocated', mode: 'room', spectate_url: url } }, 'match')).toBeUndefined();
354
+ expect(resumedSpectateLifecycle({ data: { status: 'allocated', mode: 'match' } }, 'match')).toBeUndefined();
355
+ });
356
+ });
@@ -483,14 +483,13 @@ function unwrapData(value: any): any {
483
483
  return value?.data ?? value;
484
484
  }
485
485
 
486
- export function lobbyWatchUrl(profile: { serverUrl: string; apiKey: string }): string {
487
- const origin = new URL(profile.serverUrl).origin;
488
- return `${origin}/lobby?token=${encodeURIComponent(profile.apiKey)}`;
486
+ export function backendSpectateUrl(result: any): string | undefined {
487
+ const data = unwrapData(result);
488
+ return nonEmptyString(data?.spectate_url) ?? nonEmptyString(data?.url);
489
489
  }
490
490
 
491
491
  export function joinedLifecyclePayload(joinResult: any, joinedQueue: any): Record<string, any> {
492
- const data = unwrapData(joinResult);
493
- const url = nonEmptyString(data?.spectate_url) ?? nonEmptyString(data?.url);
492
+ const url = backendSpectateUrl(joinResult);
494
493
  return {
495
494
  ...joinResult,
496
495
  ...(url ? { url } : {}),
@@ -498,6 +497,37 @@ export function joinedLifecyclePayload(joinResult: any, joinedQueue: any): Recor
498
497
  };
499
498
  }
500
499
 
500
+ export type ResumedSpectateKind = 'match' | 'room';
501
+
502
+ export function resumedSpectateLifecycle(
503
+ queue: any,
504
+ kind: ResumedSpectateKind,
505
+ ): { reason: 'joined' | 'room_joined'; payload: Record<string, any>; nextStep: string } | undefined {
506
+ const data = unwrapData(queue);
507
+ const status = queueStatus(queue);
508
+ const mode = roomQueueMode(queue);
509
+ const url = backendSpectateUrl(queue);
510
+ if (!url) return undefined;
511
+
512
+ const isRoomState = status === 'in_room' || (status === 'allocated' && mode === 'room');
513
+ const isMatchState = (status === 'queued' || status === 'already_in_queue' || status === 'allocated') && mode !== 'room';
514
+ if ((kind === 'room' && !isRoomState) || (kind === 'match' && !isMatchState)) return undefined;
515
+
516
+ if (kind === 'room') {
517
+ return {
518
+ reason: 'room_joined',
519
+ payload: { ...data, spectate_url: url, resumed: true },
520
+ nextStep: 'Room runtime reattached. Share events[0].spectate_url with the user as the room page link. Keep the room stream attached.',
521
+ };
522
+ }
523
+
524
+ return {
525
+ reason: 'joined',
526
+ payload: { ...joinedLifecyclePayload(queue, queue), resumed: true },
527
+ nextStep: 'Game runtime reattached. Spectate URL is in events[0].url; share it with the user. Keep the game stream attached.',
528
+ };
529
+ }
530
+
501
531
  function cleanObject<T extends Record<string, any>>(obj: T): T {
502
532
  for (const key of Object.keys(obj)) {
503
533
  if (obj[key] === undefined) delete obj[key];
@@ -809,6 +839,7 @@ async function runEnterRoom(
809
839
  }
810
840
  }
811
841
  stopStrategyIfRunning();
842
+ let entrySpectateEmitted = false;
812
843
  try {
813
844
  if (shouldEnter) {
814
845
  const result = await enter(client);
@@ -834,6 +865,7 @@ async function runEnterRoom(
834
865
  if (opts.channelUrl) {
835
866
  fetch(opts.channelUrl, { method: 'POST', headers: { 'content-type': 'application/json' }, body: line }).catch(() => {});
836
867
  }
868
+ entrySpectateEmitted = true;
837
869
  }
838
870
  } else {
839
871
  events.append({ type: `${source}_accepted`, room_code: targetRoomCode, already_in_room: true });
@@ -861,6 +893,7 @@ async function runEnterRoom(
861
893
  channelUrl: opts.channelUrl,
862
894
  agentType: opts.agentType,
863
895
  llmModel: opts.llmModel ?? '',
896
+ entrySpectateAlreadyEmitted: entrySpectateEmitted,
864
897
  });
865
898
  }
866
899
 
@@ -952,7 +985,14 @@ function requireStreamTool(command: string): void {
952
985
  process.exit(2);
953
986
  }
954
987
 
955
- async function runGameStart(opts: { force?: boolean; channelUrl?: string; competition?: boolean; agentType?: string; llmModel: string }): Promise<void> {
988
+ async function runGameStart(opts: {
989
+ force?: boolean;
990
+ channelUrl?: string;
991
+ competition?: boolean;
992
+ agentType?: string;
993
+ llmModel: string;
994
+ entrySpectateAlreadyEmitted?: boolean;
995
+ }): Promise<void> {
956
996
  requireStreamTool('ccl game start');
957
997
 
958
998
  // Channel 模式硬兜底:带 --channel-url 时,把真正的长流逻辑 fork 到 detached 后台进程,
@@ -978,7 +1018,11 @@ async function runGameStart(opts: { force?: boolean; channelUrl?: string; compet
978
1018
  const child = spawn(process.execPath, process.argv.slice(1), {
979
1019
  detached: true,
980
1020
  stdio: 'ignore',
981
- env: { ...process.env, CLAWCLAW_CHANNEL_DETACHED: '1' },
1021
+ env: {
1022
+ ...process.env,
1023
+ CLAWCLAW_CHANNEL_DETACHED: '1',
1024
+ CLAWCLAW_ENTRY_SPECTATE_EMITTED: opts.entrySpectateAlreadyEmitted ? '1' : '0',
1025
+ },
982
1026
  });
983
1027
  child.unref();
984
1028
  process.stdout.write(JSON.stringify({
@@ -1084,6 +1128,20 @@ async function runGameStart(opts: { force?: boolean; channelUrl?: string; compet
1084
1128
  summary: currentSummary(),
1085
1129
  });
1086
1130
  };
1131
+ let spectateLifecycleEmitted = opts.entrySpectateAlreadyEmitted === true
1132
+ || process.env.CLAWCLAW_ENTRY_SPECTATE_EMITTED === '1';
1133
+ const emitResumedSpectate = (queue: any, kind: ResumedSpectateKind): boolean => {
1134
+ if (spectateLifecycleEmitted || ownerExitRequested) return false;
1135
+ const lifecycle = resumedSpectateLifecycle(queue, kind);
1136
+ if (!lifecycle) return false;
1137
+ spectateLifecycleEmitted = true;
1138
+ emitLifecycle(
1139
+ lifecycle.reason,
1140
+ withCurrentGameMode(lifecycle.payload),
1141
+ lifecycle.nextStep,
1142
+ );
1143
+ return true;
1144
+ };
1087
1145
  const emitOwnerExit = (kind: 'stop' | 'quit' | 'leave', command: string): void => {
1088
1146
  if (manualExitEmitted) return;
1089
1147
  manualExitEmitted = true;
@@ -1166,6 +1224,7 @@ async function runGameStart(opts: { force?: boolean; channelUrl?: string; compet
1166
1224
  queue: any,
1167
1225
  preserveStrategy: boolean,
1168
1226
  sessionSource?: string,
1227
+ onAttached?: (queue: any) => void,
1169
1228
  ): Promise<void> => {
1170
1229
  let currentQueue = queue;
1171
1230
  updateGameMode(isRoomAllocatedQueueStatus(currentQueue) ? 'room' : queueMode(currentQueue));
@@ -1253,6 +1312,9 @@ async function runGameStart(opts: { force?: boolean; channelUrl?: string; compet
1253
1312
  };
1254
1313
  ownerFeed = { ...ownerFeed, allocation: allocationPayload };
1255
1314
  await ensureEventRuntime();
1315
+ // Recovery callers announce the URL only after every immediate attach gate
1316
+ // has succeeded and this process is about to remain in the game stream.
1317
+ onAttached?.(currentQueue);
1256
1318
  await streamGame();
1257
1319
  };
1258
1320
  const roomReturnSourceFor = (endedReason: string | null | undefined): string => {
@@ -1295,8 +1357,13 @@ async function runGameStart(opts: { force?: boolean; channelUrl?: string; compet
1295
1357
  return roomReturnSourceFor(endedReason);
1296
1358
  };
1297
1359
 
1298
- const streamRoomLobby = async (source: string): Promise<void> => {
1360
+ const streamRoomLobby = async (
1361
+ source: string,
1362
+ roomOpts: { announceResume?: boolean; queue?: any } = {},
1363
+ ): Promise<void> => {
1299
1364
  let roomSource = source;
1365
+ let pendingResumeSpectate = roomOpts.announceResume === true;
1366
+ let resumeQueue = roomOpts.queue;
1300
1367
  while (!ownerExitRequested) {
1301
1368
  startEventSession(roomSource);
1302
1369
  const roomStartedRef: { value: RoomGameStarted | null } = { value: null };
@@ -1318,6 +1385,22 @@ async function runGameStart(opts: { force?: boolean; channelUrl?: string; compet
1318
1385
  },
1319
1386
  });
1320
1387
  await roomRuntime.start();
1388
+ // RoomLobbyRuntime.start() resolves only after the Lobby websocket opens.
1389
+ // If the room started during that handshake, defer the URL until the
1390
+ // allocated game runtime has also attached successfully.
1391
+ if (pendingResumeSpectate && !roomStartedRef.value) {
1392
+ let refreshedQueue: any;
1393
+ try {
1394
+ refreshedQueue = await client.getQueueStatus('clawclaw');
1395
+ updateGameMode(queueMode(refreshedQueue));
1396
+ } catch {}
1397
+ const emitted = emitResumedSpectate(refreshedQueue, 'room')
1398
+ || emitResumedSpectate(resumeQueue, 'room');
1399
+ if (emitted) {
1400
+ pendingResumeSpectate = false;
1401
+ resumeQueue = refreshedQueue ?? resumeQueue;
1402
+ }
1403
+ }
1321
1404
  if (!roomStartedRef.value) {
1322
1405
  await streamGame({
1323
1406
  emitGameStart: false,
@@ -1343,7 +1426,13 @@ async function runGameStart(opts: { force?: boolean; channelUrl?: string; compet
1343
1426
  game_id: started.game_id,
1344
1427
  game_server_name: started.game_server_name,
1345
1428
  ws_url: started.ws_url,
1346
- }, true);
1429
+ }, true, undefined, pendingResumeSpectate
1430
+ ? (queue) => {
1431
+ const emitted = emitResumedSpectate(queue, 'room')
1432
+ || emitResumedSpectate(resumeQueue, 'room');
1433
+ if (emitted) pendingResumeSpectate = false;
1434
+ }
1435
+ : undefined);
1347
1436
 
1348
1437
  const endedReason = lastEventStopReason ?? eventRuntime?.snapshot()?.phase;
1349
1438
  const nextRoomSource = await prepareRoomLobbyReturn(endedReason);
@@ -1351,14 +1440,18 @@ async function runGameStart(opts: { force?: boolean; channelUrl?: string; compet
1351
1440
  roomSource = nextRoomSource;
1352
1441
  }
1353
1442
  };
1354
- const streamRoomAllocated = async (queue: any, source: string): Promise<void> => {
1355
- await handleAllocated(queue, true, source);
1443
+ const streamRoomAllocated = async (
1444
+ queue: any,
1445
+ source: string,
1446
+ onAttached?: (queue: any) => void,
1447
+ ): Promise<void> => {
1448
+ await handleAllocated(queue, true, source, onAttached);
1356
1449
  const endedReason = lastEventStopReason ?? eventRuntime?.snapshot()?.phase;
1357
1450
  const nextRoomSource = await prepareRoomLobbyReturn(endedReason);
1358
1451
  if (!nextRoomSource) return;
1359
1452
  await streamRoomLobby(nextRoomSource);
1360
1453
  };
1361
- const pollQueue = async (preserveStrategy: boolean): Promise<void> => {
1454
+ const pollQueue = async (preserveStrategy: boolean, announceResume = false): Promise<void> => {
1362
1455
  const intervalMs = 2000;
1363
1456
  const QUEUE_POLL_HEARTBEAT_MS = 60_000;
1364
1457
  const MAX_CONSECUTIVE_FAILURES = 3;
@@ -1391,20 +1484,42 @@ async function runGameStart(opts: { force?: boolean; channelUrl?: string; compet
1391
1484
  continue;
1392
1485
  }
1393
1486
 
1394
- if (queueStatus(queue) === 'allocated') {
1487
+ const status = queueStatus(queue);
1488
+ if (status === 'allocated') {
1395
1489
  if (isRoomAllocatedQueueStatus(queue)) {
1396
- await streamRoomAllocated(queue, 'game_start_room_allocated_from_queue');
1490
+ await streamRoomAllocated(
1491
+ queue,
1492
+ 'game_start_room_allocated_from_queue',
1493
+ announceResume ? (attachedQueue) => { emitResumedSpectate(attachedQueue, 'room'); } : undefined,
1494
+ );
1397
1495
  return;
1398
1496
  }
1399
- await handleAllocated(queue, preserveStrategy);
1497
+ await handleAllocated(
1498
+ queue,
1499
+ preserveStrategy,
1500
+ undefined,
1501
+ announceResume ? (attachedQueue) => { emitResumedSpectate(attachedQueue, 'match'); } : undefined,
1502
+ );
1400
1503
  return;
1401
1504
  }
1402
- if (queueStatus(queue) === 'not_in_queue') {
1505
+ if (status === 'not_in_queue') {
1403
1506
  endMatch(stateDir);
1404
1507
  emitLifecycle('not_in_queue', { queue, message: 'Left or dropped from queue.' },
1405
1508
  'No longer in matchmaking queue. The stream will exit; launch a fresh `ccl game start` to retry if the user wants to continue.');
1406
1509
  return;
1407
1510
  }
1511
+ if (status === 'in_room') {
1512
+ await streamRoomLobby('game_start_room_from_queue', {
1513
+ announceResume,
1514
+ queue,
1515
+ });
1516
+ return;
1517
+ }
1518
+ if (announceResume && (status === 'queued' || status === 'already_in_queue')) {
1519
+ if (roomQueueMode(queue) !== 'room' && emitResumedSpectate(queue, 'match')) {
1520
+ announceResume = false;
1521
+ }
1522
+ }
1408
1523
 
1409
1524
  const cur = readMatchState(stateDir);
1410
1525
  if (cur && shouldEmitWaiting(cur)) {
@@ -1439,7 +1554,7 @@ async function runGameStart(opts: { force?: boolean; channelUrl?: string; compet
1439
1554
  ensureEventSession(source);
1440
1555
  if (!readMatchState(stateDir)) startMatch(stateDir);
1441
1556
  await ensureEventRuntime();
1442
- await pollQueue(true);
1557
+ await pollQueue(true, !spectateLifecycleEmitted);
1443
1558
  };
1444
1559
  const recoverAlreadyInGame = async (): Promise<boolean> => {
1445
1560
  let queue: any;
@@ -1452,9 +1567,18 @@ async function runGameStart(opts: { force?: boolean; channelUrl?: string; compet
1452
1567
  const status = queueStatus(queue);
1453
1568
  if (status === 'allocated') {
1454
1569
  if (isRoomAllocatedQueueStatus(queue)) {
1455
- await streamRoomAllocated(queue, 'game_start_already_in_room_game');
1570
+ await streamRoomAllocated(
1571
+ queue,
1572
+ 'game_start_already_in_room_game',
1573
+ (attachedQueue) => { emitResumedSpectate(attachedQueue, 'room'); },
1574
+ );
1456
1575
  } else {
1457
- await handleAllocated(queue, true);
1576
+ await handleAllocated(
1577
+ queue,
1578
+ true,
1579
+ undefined,
1580
+ (attachedQueue) => { emitResumedSpectate(attachedQueue, 'match'); },
1581
+ );
1458
1582
  }
1459
1583
  return true;
1460
1584
  }
@@ -1542,17 +1666,29 @@ async function runGameStart(opts: { force?: boolean; channelUrl?: string; compet
1542
1666
  }
1543
1667
 
1544
1668
  if (plan.kind === 'resume_allocated') {
1545
- await handleAllocated(initialQueue, true);
1669
+ await handleAllocated(
1670
+ initialQueue,
1671
+ true,
1672
+ undefined,
1673
+ (attachedQueue) => { emitResumedSpectate(attachedQueue, 'match'); },
1674
+ );
1546
1675
  return;
1547
1676
  }
1548
1677
 
1549
1678
  if (plan.kind === 'resume_room_allocated') {
1550
- await streamRoomAllocated(initialQueue, 'game_start_resume_room_allocated');
1679
+ await streamRoomAllocated(
1680
+ initialQueue,
1681
+ 'game_start_resume_room_allocated',
1682
+ (attachedQueue) => { emitResumedSpectate(attachedQueue, 'room'); },
1683
+ );
1551
1684
  return;
1552
1685
  }
1553
1686
 
1554
1687
  if (plan.kind === 'resume_room') {
1555
- await streamRoomLobby('game_start_resume_room');
1688
+ await streamRoomLobby('game_start_resume_room', {
1689
+ announceResume: !spectateLifecycleEmitted,
1690
+ queue: initialQueue,
1691
+ });
1556
1692
  return;
1557
1693
  }
1558
1694
 
@@ -1571,7 +1707,9 @@ async function runGameStart(opts: { force?: boolean; channelUrl?: string; compet
1571
1707
  updateGameMode(queueMode(joinResult));
1572
1708
  } catch (err) {
1573
1709
  if (isAlreadyInRoomError(err)) {
1574
- await streamRoomLobby('game_start_already_in_room');
1710
+ await streamRoomLobby('game_start_already_in_room', {
1711
+ announceResume: !spectateLifecycleEmitted,
1712
+ });
1575
1713
  return;
1576
1714
  }
1577
1715
  if (isAlreadyInGameError(err) && await recoverAlreadyInGame()) return;
@@ -1610,7 +1748,10 @@ async function runGameStart(opts: { force?: boolean; channelUrl?: string; compet
1610
1748
  }
1611
1749
  const joinedStatus = queueStatus(joinResult);
1612
1750
  if (joinedStatus === 'in_room') {
1613
- await streamRoomLobby('game_start_joined_room');
1751
+ await streamRoomLobby('game_start_joined_room', {
1752
+ announceResume: !spectateLifecycleEmitted,
1753
+ queue: joinResult,
1754
+ });
1614
1755
  return;
1615
1756
  }
1616
1757
  if (joinedStatus === 'already_in_queue') {
@@ -1884,11 +2025,14 @@ export function createGameCommand(): Command {
1884
2025
  .command('watch')
1885
2026
  .alias('w')
1886
2027
  .description('Get spectating URL')
1887
- .action(() => {
2028
+ .action(async () => {
1888
2029
  const authStore = new AuthStore();
1889
2030
  const profile = authStore.getActive();
1890
2031
  if (!profile) throw new Error('Not logged in.');
1891
- const url = lobbyWatchUrl(profile);
2032
+ const client = GameClient.fromAuth({ authStore });
2033
+ const queue = await client.getQueueStatus('clawclaw');
2034
+ const url = backendSpectateUrl(queue);
2035
+ if (!url) throw new Error('Backend queue status did not return spectate_url.');
1892
2036
  console.log(JSON.stringify({ url, message: 'Open in browser to spectate.' }, null, 2));
1893
2037
  });
1894
2038