@myclaw163/clawclaw-cli 0.7.5 → 0.7.7
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/docs/desktop-event-push.md +154 -0
- package/docs/runtime/README.md +1 -0
- package/docs/runtime/official-perception-modules.md +346 -0
- package/package.json +2 -1
- package/src/commands/game/index.test.ts +167 -1
- package/src/commands/game/index.ts +125 -36
- package/src/lib/game-client.test.ts +15 -0
- package/src/lib/game-client.ts +4 -0
- package/src/lib/participation-status.ts +113 -0
- package/src/lib/service-status.test.ts +56 -0
- package/src/lib/service-status.ts +111 -0
- package/src/pipeline/event-format.test.ts +30 -0
- package/src/pipeline/event-format.ts +26 -1
- package/src/pipeline/event-hints.test.ts +18 -3
- package/src/pipeline/event-hints.ts +11 -0
- package/src/pipeline/game-sync-event-normalization.test.ts +58 -1
- package/src/pipeline/game-sync-event-normalization.ts +51 -0
- package/src/runtime/clawclaw/agent-event-policy.test.ts +4 -0
- package/src/runtime/clawclaw/agent-event-policy.ts +1 -0
- package/src/runtime/clawclaw/owner.ts +62 -3
- package/src/runtime/clawclaw/plugins/mailbox/agent-mailbox-coordinator.test.ts +189 -0
- package/src/runtime/clawclaw/plugins/mailbox/agent-mailbox-coordinator.ts +532 -0
- package/src/runtime/clawclaw/plugins/mailbox/desktop-event-push.integration.test.ts +363 -0
- package/src/runtime/clawclaw/plugins/mailbox/desktop-event-socket.test.ts +236 -0
- package/src/runtime/clawclaw/plugins/mailbox/desktop-event-socket.ts +411 -0
- package/src/runtime/clawclaw/plugins/mailbox/index.ts +3 -0
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-agent-event-batch.test.ts +166 -0
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-event-batch-delivery.test.ts +194 -0
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-event-batch-delivery.ts +262 -0
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-plugin.ts +28 -0
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.test.ts +49 -0
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.ts +77 -259
- package/src/runtime/clawclaw/plugins/perception/contracts.ts +4 -0
- package/src/runtime/clawclaw/plugins/perception/modules/co-movement-module.ts +6 -0
- package/src/runtime/clawclaw/plugins/perception/modules/follow-module.ts +6 -0
- package/src/runtime/clawclaw/plugins/perception/modules/motion-module.ts +6 -0
- package/src/runtime/clawclaw/plugins/perception/modules/route-module.ts +6 -0
- package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.ts +6 -0
- package/src/runtime/clawclaw/plugins/perception/modules/stop-module.ts +6 -0
- package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.ts +6 -0
- package/src/runtime/clawclaw/plugins/perception/perception-plugin.test.ts +11 -0
- package/src/runtime/clawclaw/plugins/perception/perception-plugin.ts +8 -0
- package/src/runtime/clawclaw/plugins/perception/perception-source.test.ts +12 -0
- package/src/runtime/clawclaw/plugins/perception/perception-source.ts +37 -1
- package/src/runtime/clawclaw/plugins/runtime-plugins.test.ts +5 -0
- package/src/runtime/clawclaw/plugins/source/room-transport.ts +2 -1
- package/src/runtime/clawclaw/plugins/source/source-plugin.test.ts +201 -1
- package/src/runtime/clawclaw/plugins/source/source-plugin.ts +113 -24
- package/src/runtime/clawclaw/plugins/source/types.ts +1 -0
- package/src/runtime/clawclaw/plugins/strategy/examples/task-only-strategy.ts +6 -0
- package/src/runtime/clawclaw/plugins/strategy/strategy-executor-types.ts +4 -0
- package/src/runtime/clawclaw/plugins/strategy/strategy-module-loader.ts +4 -0
- package/src/runtime/clawclaw/plugins/strategy/strategy-plugin.test.ts +36 -0
- package/src/runtime/clawclaw/plugins/strategy/strategy-plugin.ts +13 -0
- package/src/runtime/clawclaw/plugins/strategy/strategy-source.test.ts +22 -0
- package/src/runtime/clawclaw/plugins/strategy/strategy-source.ts +46 -16
- package/src/runtime/clawclaw-event-catalog.test.ts +2 -0
- package/src/runtime/clawclaw-event-catalog.ts +1 -0
- package/src/sdk/perception-plugin/index.ts +14 -0
- package/src/sdk/resource-metadata.test.ts +40 -0
- package/src/sdk/resource-metadata.ts +63 -0
- package/src/sdk/strategy-plugin/index.ts +14 -0
|
@@ -19,6 +19,7 @@ function fixture(
|
|
|
19
19
|
const exitCodes: number[] = [];
|
|
20
20
|
const client = {
|
|
21
21
|
getQueueStatus: vi.fn(async () => queue),
|
|
22
|
+
getRoomStatus: vi.fn(async () => ({ success: true, data: {} })),
|
|
22
23
|
leaveGame: vi.fn(async () => overrides.leaveGame ?? { success: true }),
|
|
23
24
|
leaveRoom: vi.fn(async () => overrides.leaveRoom ?? { success: true }),
|
|
24
25
|
leaveQueue: vi.fn(async () => overrides.leaveQueue ?? {
|
|
@@ -45,6 +46,7 @@ function startRoomFixture(result: unknown | Error) {
|
|
|
45
46
|
const exitCodes: number[] = [];
|
|
46
47
|
const client = {
|
|
47
48
|
getQueueStatus: vi.fn(),
|
|
49
|
+
getRoomStatus: vi.fn(),
|
|
48
50
|
leaveGame: vi.fn(),
|
|
49
51
|
leaveRoom: vi.fn(),
|
|
50
52
|
leaveQueue: vi.fn(),
|
|
@@ -64,6 +66,31 @@ function startRoomFixture(result: unknown | Error) {
|
|
|
64
66
|
return { client, dependencies, exitCodes, stdout };
|
|
65
67
|
}
|
|
66
68
|
|
|
69
|
+
function statusFixture(
|
|
70
|
+
queue: Record<string, any>,
|
|
71
|
+
room: Record<string, any> = { success: true, data: {} },
|
|
72
|
+
) {
|
|
73
|
+
const stdout: string[] = [];
|
|
74
|
+
const exitCodes: number[] = [];
|
|
75
|
+
const client = {
|
|
76
|
+
getQueueStatus: vi.fn(async () => queue),
|
|
77
|
+
getRoomStatus: vi.fn(async () => room),
|
|
78
|
+
leaveGame: vi.fn(),
|
|
79
|
+
leaveRoom: vi.fn(),
|
|
80
|
+
leaveQueue: vi.fn(),
|
|
81
|
+
startRoom: vi.fn(),
|
|
82
|
+
};
|
|
83
|
+
const dependencies: GameCommandDependencies = {
|
|
84
|
+
activeProfile: () => profile,
|
|
85
|
+
clientFactory: () => client,
|
|
86
|
+
io: {
|
|
87
|
+
writeStdout: (text) => stdout.push(text),
|
|
88
|
+
setExitCode: (code) => exitCodes.push(code),
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
return { client, dependencies, exitCodes, stdout };
|
|
92
|
+
}
|
|
93
|
+
|
|
67
94
|
async function runStartRoom(value: ReturnType<typeof startRoomFixture>) {
|
|
68
95
|
await createGameCommand(value.dependencies).parseAsync(
|
|
69
96
|
['node', 'game', 'start-room'],
|
|
@@ -82,6 +109,94 @@ async function runQuit(value: ReturnType<typeof fixture>) {
|
|
|
82
109
|
return JSON.parse(value.stdout[0]);
|
|
83
110
|
}
|
|
84
111
|
|
|
112
|
+
async function runStatus(value: ReturnType<typeof statusFixture>) {
|
|
113
|
+
await createGameCommand(value.dependencies).parseAsync(
|
|
114
|
+
['node', 'game', 'status'],
|
|
115
|
+
{ from: 'node' },
|
|
116
|
+
);
|
|
117
|
+
expect(value.stdout).toHaveLength(1);
|
|
118
|
+
return JSON.parse(value.stdout[0]);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
describe('game status', () => {
|
|
122
|
+
it.each([
|
|
123
|
+
{
|
|
124
|
+
queue: { success: true, data: { status: 'not_in_queue' } },
|
|
125
|
+
expected: { status: 'idle', queue_status: 'not_in_queue' },
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
queue: { success: true, data: { status: 'queued', mode: 'match' } },
|
|
129
|
+
expected: { status: 'matching', queue_status: 'queued', mode: 'match' },
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
queue: {
|
|
133
|
+
success: true,
|
|
134
|
+
data: { status: 'allocated', mode: 'room', game_id: 'GAME1' },
|
|
135
|
+
},
|
|
136
|
+
expected: {
|
|
137
|
+
status: 'in_game',
|
|
138
|
+
queue_status: 'allocated',
|
|
139
|
+
mode: 'room',
|
|
140
|
+
game_id: 'GAME1',
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
])('projects backend queue state as $expected.status', async ({ queue, expected }) => {
|
|
144
|
+
const value = statusFixture(queue);
|
|
145
|
+
|
|
146
|
+
const output = await runStatus(value);
|
|
147
|
+
|
|
148
|
+
expect(output).toMatchObject({ schema: 'ccl.game-status.v1', ...expected });
|
|
149
|
+
expect(value.client.getQueueStatus).toHaveBeenCalledWith('clawclaw');
|
|
150
|
+
expect(value.client.getRoomStatus).not.toHaveBeenCalled();
|
|
151
|
+
expect(value.exitCodes).toEqual([0]);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it.each([
|
|
155
|
+
{ roomType: 'casual', expectedStatus: 'friend_room' },
|
|
156
|
+
{ roomType: 'training_simulation', expectedStatus: 'training_room' },
|
|
157
|
+
{ roomType: 'training_dummy', expectedStatus: 'training_room' },
|
|
158
|
+
])('uses room status to classify $roomType', async ({ roomType, expectedStatus }) => {
|
|
159
|
+
const value = statusFixture(
|
|
160
|
+
{ success: true, data: { status: 'in_room', mode: 'room', room_code: 'QUEUE1' } },
|
|
161
|
+
{
|
|
162
|
+
success: true,
|
|
163
|
+
data: {
|
|
164
|
+
room_code: 'ROOM1',
|
|
165
|
+
room_type: roomType,
|
|
166
|
+
status: 'waiting',
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
const output = await runStatus(value);
|
|
172
|
+
|
|
173
|
+
expect(output).toMatchObject({
|
|
174
|
+
schema: 'ccl.game-status.v1',
|
|
175
|
+
status: expectedStatus,
|
|
176
|
+
queue_status: 'in_room',
|
|
177
|
+
room_code: 'ROOM1',
|
|
178
|
+
room_type: roomType,
|
|
179
|
+
room_status: 'waiting',
|
|
180
|
+
});
|
|
181
|
+
expect(value.client.getRoomStatus).toHaveBeenCalledOnce();
|
|
182
|
+
expect(value.exitCodes).toEqual([0]);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('keeps an unrecognized queue status visible and exits nonzero', async () => {
|
|
186
|
+
const value = statusFixture({ success: true, data: { status: 'new_backend_state' } });
|
|
187
|
+
|
|
188
|
+
const output = await runStatus(value);
|
|
189
|
+
|
|
190
|
+
expect(output).toMatchObject({
|
|
191
|
+
schema: 'ccl.game-status.v1',
|
|
192
|
+
status: 'unknown',
|
|
193
|
+
queue_status: 'new_backend_state',
|
|
194
|
+
});
|
|
195
|
+
expect(value.client.getRoomStatus).not.toHaveBeenCalled();
|
|
196
|
+
expect(value.exitCodes).toEqual([1]);
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
|
|
85
200
|
describe('game quit', () => {
|
|
86
201
|
it('reports HTTP 200 STILL_ALIVE as a remote failure and stops only the local runtime', async () => {
|
|
87
202
|
const value = fixture(
|
|
@@ -273,12 +388,63 @@ describe('game start runtime replacement', () => {
|
|
|
273
388
|
forceExistingRuntime: expectedForce,
|
|
274
389
|
});
|
|
275
390
|
});
|
|
391
|
+
|
|
392
|
+
it('passes the paired Desktop event IPC configuration outside the game intent', async () => {
|
|
393
|
+
const ownerRunner = vi.fn(async () => {});
|
|
394
|
+
const socket = process.platform === 'win32' ? 'desktop-wake-test' : '/tmp/desktop-wake-test.sock';
|
|
395
|
+
|
|
396
|
+
await createGameCommand({ ownerRunner }).parseAsync([
|
|
397
|
+
'node',
|
|
398
|
+
'game',
|
|
399
|
+
'start',
|
|
400
|
+
'--agent-type',
|
|
401
|
+
'codex-desktop',
|
|
402
|
+
'--desktop-event-socket',
|
|
403
|
+
socket,
|
|
404
|
+
'--desktop-event-token',
|
|
405
|
+
'0123456789abcdef0123456789abcdef',
|
|
406
|
+
], { from: 'node' });
|
|
407
|
+
|
|
408
|
+
expect(ownerRunner).toHaveBeenCalledWith({
|
|
409
|
+
kind: 'match',
|
|
410
|
+
mode: 'match',
|
|
411
|
+
agentType: 'codex-desktop',
|
|
412
|
+
llmModel: undefined,
|
|
413
|
+
}, {
|
|
414
|
+
forceExistingRuntime: false,
|
|
415
|
+
desktopEvents: {
|
|
416
|
+
socketPath: process.platform === 'win32'
|
|
417
|
+
? '\\\\.\\pipe\\desktop-wake-test'
|
|
418
|
+
: '/tmp/desktop-wake-test.sock',
|
|
419
|
+
token: '0123456789abcdef0123456789abcdef',
|
|
420
|
+
},
|
|
421
|
+
});
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
it('rejects an unpaired Desktop event IPC option before starting the Owner', async () => {
|
|
425
|
+
const ownerRunner = vi.fn(async () => {});
|
|
426
|
+
const socket = process.platform === 'win32' ? 'desktop-wake-test' : '/tmp/desktop-wake-test.sock';
|
|
427
|
+
|
|
428
|
+
await expect(createGameCommand({ ownerRunner }).parseAsync([
|
|
429
|
+
'node',
|
|
430
|
+
'game',
|
|
431
|
+
'start',
|
|
432
|
+
'--agent-type',
|
|
433
|
+
'codex-desktop',
|
|
434
|
+
'--desktop-event-socket',
|
|
435
|
+
socket,
|
|
436
|
+
], { from: 'node' })).rejects.toThrow(
|
|
437
|
+
'--desktop-event-socket and --desktop-event-token must be provided together.',
|
|
438
|
+
);
|
|
439
|
+
expect(ownerRunner).not.toHaveBeenCalled();
|
|
440
|
+
});
|
|
276
441
|
});
|
|
277
442
|
|
|
278
443
|
describe('game room entry', () => {
|
|
279
|
-
it('exposes create-room, join-room, and start-room in game help', () => {
|
|
444
|
+
it('exposes status, create-room, join-room, and start-room in game help', () => {
|
|
280
445
|
const help = createGameCommand().helpInformation();
|
|
281
446
|
|
|
447
|
+
expect(help).toContain('status');
|
|
282
448
|
expect(help).toContain('create-room');
|
|
283
449
|
expect(help).toContain('join-room');
|
|
284
450
|
expect(help).toContain('start-room');
|
|
@@ -15,19 +15,33 @@ import {
|
|
|
15
15
|
unwrapData,
|
|
16
16
|
type TrainingRoomType,
|
|
17
17
|
} from '../../lib/room.js';
|
|
18
|
+
import { queryGameParticipationStatus } from '../../lib/participation-status.js';
|
|
18
19
|
import { setMeta } from '../../lib/command-meta.js';
|
|
19
20
|
import { ShortCommandRunner } from '../../short-command/runner.js';
|
|
20
21
|
import { createProcessCanonicalEventEmitter } from '../../runtime/canonical-event-emitter.js';
|
|
21
22
|
import { runClawclawOwner } from '../../runtime/clawclaw/owner.js';
|
|
22
23
|
import { ClawclawHostNotificationRoute } from '../../runtime/clawclaw/notifications.js';
|
|
24
|
+
import {
|
|
25
|
+
normalizeDesktopEventSocketPath,
|
|
26
|
+
validateDesktopEventToken,
|
|
27
|
+
type DesktopEventSocketConfig,
|
|
28
|
+
} from '../../runtime/clawclaw/plugins/mailbox/index.js';
|
|
23
29
|
import { sendProfileOwnerControlRequest } from '../../runtime/owner-control.js';
|
|
24
30
|
|
|
25
31
|
type GameCommandClient = Pick<
|
|
26
32
|
GameClient,
|
|
27
|
-
'getQueueStatus' | 'leaveGame' | 'leaveRoom' | 'leaveQueue' | 'startRoom'
|
|
33
|
+
'getQueueStatus' | 'getRoomStatus' | 'leaveGame' | 'leaveRoom' | 'leaveQueue' | 'startRoom'
|
|
28
34
|
>;
|
|
29
35
|
type GameOwnerIntent = Parameters<typeof runClawclawOwner>[0]['intent'];
|
|
30
|
-
type GameOwnerRunOptions = {
|
|
36
|
+
type GameOwnerRunOptions = {
|
|
37
|
+
forceExistingRuntime?: boolean;
|
|
38
|
+
desktopEvents?: DesktopEventSocketConfig;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
interface DesktopEventCliOptions {
|
|
42
|
+
desktopEventSocket?: string;
|
|
43
|
+
desktopEventToken?: string;
|
|
44
|
+
}
|
|
31
45
|
|
|
32
46
|
interface GameCommandIo {
|
|
33
47
|
writeStdout(text: string): void;
|
|
@@ -60,6 +74,33 @@ function positiveCharacterId(value: string): number {
|
|
|
60
74
|
return parsed;
|
|
61
75
|
}
|
|
62
76
|
|
|
77
|
+
function addDesktopEventOptions(command: Command): Command {
|
|
78
|
+
return command
|
|
79
|
+
.addOption(new Option('--desktop-event-socket <path>').hideHelp())
|
|
80
|
+
.addOption(new Option('--desktop-event-token <nonce>').hideHelp());
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function desktopEventConfig(
|
|
84
|
+
options: DesktopEventCliOptions,
|
|
85
|
+
): DesktopEventSocketConfig | undefined {
|
|
86
|
+
const hasSocket = typeof options.desktopEventSocket === 'string';
|
|
87
|
+
const hasToken = typeof options.desktopEventToken === 'string';
|
|
88
|
+
if (hasSocket !== hasToken) {
|
|
89
|
+
throw new InvalidArgumentError(
|
|
90
|
+
'--desktop-event-socket and --desktop-event-token must be provided together.',
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
if (!hasSocket || !hasToken) return undefined;
|
|
94
|
+
try {
|
|
95
|
+
return {
|
|
96
|
+
socketPath: normalizeDesktopEventSocketPath(options.desktopEventSocket!),
|
|
97
|
+
token: validateDesktopEventToken(options.desktopEventToken!),
|
|
98
|
+
};
|
|
99
|
+
} catch (error) {
|
|
100
|
+
throw new InvalidArgumentError(error instanceof Error ? error.message : String(error));
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
63
104
|
async function runTrainingControl(
|
|
64
105
|
type: 'training_mode' | 'training_role_lock' | 'training_role_clear',
|
|
65
106
|
payload: Record<string, any>,
|
|
@@ -121,9 +162,11 @@ async function runOwner(
|
|
|
121
162
|
profile,
|
|
122
163
|
intent,
|
|
123
164
|
forceExistingRuntime: options.forceExistingRuntime,
|
|
124
|
-
|
|
165
|
+
...(options.desktopEvents
|
|
166
|
+
? { desktopEvents: options.desktopEvents }
|
|
167
|
+
: { notificationHost: notifications }),
|
|
125
168
|
});
|
|
126
|
-
if (completion.reason === 'error') process.exitCode = 1;
|
|
169
|
+
if (completion.reason === 'error' || completion.reason === 'maintenance') process.exitCode = 1;
|
|
127
170
|
} catch (error) {
|
|
128
171
|
try {
|
|
129
172
|
await notifications.reportBootstrapFailure(
|
|
@@ -402,24 +445,38 @@ async function quitParticipation(dependencies: GameCommandDependencies = {}): Pr
|
|
|
402
445
|
), 1);
|
|
403
446
|
}
|
|
404
447
|
|
|
448
|
+
async function showParticipationStatus(
|
|
449
|
+
dependencies: GameCommandDependencies = {},
|
|
450
|
+
): Promise<void> {
|
|
451
|
+
(dependencies.activeProfile ?? activeProfile)();
|
|
452
|
+
const client = (dependencies.clientFactory ?? (() => GameClient.fromAuth()))();
|
|
453
|
+
const io = dependencies.io ?? processGameCommandIo;
|
|
454
|
+
const status = await queryGameParticipationStatus(client);
|
|
455
|
+
io.writeStdout(`${JSON.stringify(status, null, 2)}\n`);
|
|
456
|
+
io.setExitCode(status.status === 'unknown' ? 1 : 0);
|
|
457
|
+
}
|
|
458
|
+
|
|
405
459
|
export function createGameCommand(dependencies: GameCommandDependencies = {}): Command {
|
|
406
460
|
const game = new Command('game').description('Game participation and inspection');
|
|
407
461
|
const ownerRunner = dependencies.ownerRunner ?? runOwner;
|
|
408
462
|
|
|
409
|
-
const start = game
|
|
463
|
+
const start = addDesktopEventOptions(game
|
|
410
464
|
.command('start')
|
|
411
465
|
.alias('s')
|
|
412
466
|
.description('Run the ClawClaw Source until the current participation ends.')
|
|
413
467
|
.requiredOption('--agent-type <platform>')
|
|
414
468
|
.option('--llm-model <model>')
|
|
415
469
|
.option('--force', 'replace an existing local runtime process before starting')
|
|
416
|
-
.addOption(new Option('--competition').hideHelp())
|
|
470
|
+
.addOption(new Option('--competition').hideHelp()))
|
|
417
471
|
.action(async (opts: {
|
|
418
472
|
agentType: string;
|
|
419
473
|
llmModel?: string;
|
|
420
474
|
competition?: boolean;
|
|
421
475
|
force?: boolean;
|
|
476
|
+
desktopEventSocket?: string;
|
|
477
|
+
desktopEventToken?: string;
|
|
422
478
|
}) => {
|
|
479
|
+
const desktopEvents = desktopEventConfig(opts);
|
|
423
480
|
await ownerRunner({
|
|
424
481
|
kind: 'match',
|
|
425
482
|
mode: opts.competition ? 'competition' : 'match',
|
|
@@ -427,63 +484,90 @@ export function createGameCommand(dependencies: GameCommandDependencies = {}): C
|
|
|
427
484
|
llmModel: opts.llmModel,
|
|
428
485
|
}, {
|
|
429
486
|
forceExistingRuntime: opts.force === true,
|
|
487
|
+
...(desktopEvents ? { desktopEvents } : {}),
|
|
430
488
|
});
|
|
431
489
|
});
|
|
432
490
|
|
|
433
|
-
const createRoom = game
|
|
491
|
+
const createRoom = addDesktopEventOptions(game
|
|
434
492
|
.command('create-room')
|
|
435
493
|
.description('Create a room and run its Source lifecycle.')
|
|
436
494
|
.requiredOption('--agent-type <platform>')
|
|
437
495
|
.option('--llm-model <model>')
|
|
438
|
-
.option('--force', 'replace an existing local runtime process before starting')
|
|
439
|
-
.action(async (opts: {
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
})
|
|
446
|
-
|
|
447
|
-
|
|
496
|
+
.option('--force', 'replace an existing local runtime process before starting'))
|
|
497
|
+
.action(async (opts: {
|
|
498
|
+
agentType: string;
|
|
499
|
+
llmModel?: string;
|
|
500
|
+
force?: boolean;
|
|
501
|
+
desktopEventSocket?: string;
|
|
502
|
+
desktopEventToken?: string;
|
|
503
|
+
}) => {
|
|
504
|
+
const desktopEvents = desktopEventConfig(opts);
|
|
505
|
+
return ownerRunner({
|
|
506
|
+
kind: 'create_room',
|
|
507
|
+
agentType: opts.agentType,
|
|
508
|
+
llmModel: opts.llmModel,
|
|
509
|
+
}, {
|
|
510
|
+
forceExistingRuntime: opts.force === true,
|
|
511
|
+
...(desktopEvents ? { desktopEvents } : {}),
|
|
512
|
+
});
|
|
513
|
+
});
|
|
514
|
+
|
|
515
|
+
const joinRoom = addDesktopEventOptions(game
|
|
448
516
|
.command('join-room')
|
|
449
517
|
.description('Join a room and run its Source lifecycle.')
|
|
450
518
|
.argument('<room_code>')
|
|
451
519
|
.requiredOption('--agent-type <platform>')
|
|
452
520
|
.option('--llm-model <model>')
|
|
453
|
-
.option('--force', 'replace an existing local runtime process before starting')
|
|
454
|
-
.action(async (roomCode: string, opts: {
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
521
|
+
.option('--force', 'replace an existing local runtime process before starting'))
|
|
522
|
+
.action(async (roomCode: string, opts: {
|
|
523
|
+
agentType: string;
|
|
524
|
+
llmModel?: string;
|
|
525
|
+
force?: boolean;
|
|
526
|
+
desktopEventSocket?: string;
|
|
527
|
+
desktopEventToken?: string;
|
|
528
|
+
}) => {
|
|
529
|
+
const desktopEvents = desktopEventConfig(opts);
|
|
530
|
+
return ownerRunner({
|
|
531
|
+
kind: 'join_room',
|
|
532
|
+
roomCode,
|
|
533
|
+
agentType: opts.agentType,
|
|
534
|
+
llmModel: opts.llmModel,
|
|
535
|
+
}, {
|
|
536
|
+
forceExistingRuntime: opts.force === true,
|
|
537
|
+
...(desktopEvents ? { desktopEvents } : {}),
|
|
538
|
+
});
|
|
539
|
+
});
|
|
462
540
|
|
|
463
541
|
const training = game
|
|
464
542
|
.command('training')
|
|
465
543
|
.description('Create and configure a bot-filled training room.');
|
|
466
544
|
|
|
467
|
-
const trainingCreate = training
|
|
545
|
+
const trainingCreate = addDesktopEventOptions(training
|
|
468
546
|
.command('create')
|
|
469
547
|
.description('Create a training room and run its Source lifecycle.')
|
|
470
548
|
.requiredOption('--mode <simulation|dummy>', 'training ruleset', trainingRoomType)
|
|
471
549
|
.requiredOption('--agent-type <platform>')
|
|
472
550
|
.option('--llm-model <model>')
|
|
473
|
-
.option('--force', 'replace an existing local runtime process before starting')
|
|
551
|
+
.option('--force', 'replace an existing local runtime process before starting'))
|
|
474
552
|
.action(async (opts: {
|
|
475
553
|
mode: TrainingRoomType;
|
|
476
554
|
agentType: string;
|
|
477
555
|
llmModel?: string;
|
|
478
556
|
force?: boolean;
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
557
|
+
desktopEventSocket?: string;
|
|
558
|
+
desktopEventToken?: string;
|
|
559
|
+
}) => {
|
|
560
|
+
const desktopEvents = desktopEventConfig(opts);
|
|
561
|
+
return ownerRunner({
|
|
562
|
+
kind: 'create_room',
|
|
563
|
+
roomType: opts.mode,
|
|
564
|
+
agentType: opts.agentType,
|
|
565
|
+
llmModel: opts.llmModel,
|
|
566
|
+
}, {
|
|
567
|
+
forceExistingRuntime: opts.force === true,
|
|
568
|
+
...(desktopEvents ? { desktopEvents } : {}),
|
|
569
|
+
});
|
|
570
|
+
});
|
|
487
571
|
|
|
488
572
|
training
|
|
489
573
|
.command('mode')
|
|
@@ -515,6 +599,11 @@ export function createGameCommand(dependencies: GameCommandDependencies = {}): C
|
|
|
515
599
|
.description('Start a round in the current training room.')
|
|
516
600
|
.action(() => startCurrentRoom(dependencies, 'ccl game training start'));
|
|
517
601
|
|
|
602
|
+
game
|
|
603
|
+
.command('status')
|
|
604
|
+
.description('Show the current backend participation status.')
|
|
605
|
+
.action(() => showParticipationStatus(dependencies));
|
|
606
|
+
|
|
518
607
|
game
|
|
519
608
|
.command('quit')
|
|
520
609
|
.description('Leave the active queue, room, or game.')
|
|
@@ -82,6 +82,21 @@ describe('GameClient.joinQueue X-Monitor-Status / X-LLM-Model', () => {
|
|
|
82
82
|
});
|
|
83
83
|
|
|
84
84
|
describe('GameClient room entry metadata', () => {
|
|
85
|
+
it('gets the current room status from the lobby', async () => {
|
|
86
|
+
let captured: any;
|
|
87
|
+
vi.stubGlobal('fetch', vi.fn(async (url: string, init: any) => {
|
|
88
|
+
captured = { url, method: init.method };
|
|
89
|
+
return new Response('{"success":true,"data":{"room_type":"casual"}}', { status: 200 });
|
|
90
|
+
}));
|
|
91
|
+
|
|
92
|
+
await makeClient().getRoomStatus();
|
|
93
|
+
|
|
94
|
+
expect(captured).toEqual({
|
|
95
|
+
url: 'https://lobby.example/api/v1/room/status',
|
|
96
|
+
method: 'GET',
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
85
100
|
it('sends agent/model headers while preserving create-room request bodies', async () => {
|
|
86
101
|
const calls: Array<{ url: string; headers: Record<string, string>; body?: string }> = [];
|
|
87
102
|
vi.stubGlobal('fetch', vi.fn(async (url: string, init: any) => {
|
package/src/lib/game-client.ts
CHANGED
|
@@ -350,6 +350,10 @@ export class GameClient {
|
|
|
350
350
|
return this.http.post('/api/v1/room/join', { room_code: roomCode }, agentMetadataHeaders(metadata));
|
|
351
351
|
}
|
|
352
352
|
|
|
353
|
+
async getRoomStatus(): Promise<any> {
|
|
354
|
+
return this.http.get('/api/v1/room/status');
|
|
355
|
+
}
|
|
356
|
+
|
|
353
357
|
async leaveRoom(): Promise<any> {
|
|
354
358
|
return this.http.post('/api/v1/room/leave');
|
|
355
359
|
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isTrainingRoomMode,
|
|
3
|
+
normalizeRoomSnapshot,
|
|
4
|
+
queueMode,
|
|
5
|
+
queueRoomCode,
|
|
6
|
+
queueStatus,
|
|
7
|
+
unwrapData,
|
|
8
|
+
} from './room.js';
|
|
9
|
+
|
|
10
|
+
export const GAME_STATUS_SCHEMA = 'ccl.game-status.v1' as const;
|
|
11
|
+
|
|
12
|
+
export type GameParticipationState =
|
|
13
|
+
| 'idle'
|
|
14
|
+
| 'matching'
|
|
15
|
+
| 'friend_room'
|
|
16
|
+
| 'training_room'
|
|
17
|
+
| 'in_game'
|
|
18
|
+
| 'room'
|
|
19
|
+
| 'unknown';
|
|
20
|
+
|
|
21
|
+
export interface GameParticipationStatus {
|
|
22
|
+
schema: typeof GAME_STATUS_SCHEMA;
|
|
23
|
+
status: GameParticipationState;
|
|
24
|
+
queue_status: string | null;
|
|
25
|
+
mode?: string;
|
|
26
|
+
room_code?: string;
|
|
27
|
+
room_type?: string;
|
|
28
|
+
room_status?: string;
|
|
29
|
+
game_id?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface ParticipationStatusClient {
|
|
33
|
+
getQueueStatus(gameType?: string): Promise<any>;
|
|
34
|
+
getRoomStatus(): Promise<any>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function stringField(value: unknown): string | undefined {
|
|
38
|
+
return typeof value === 'string' && value.length > 0 ? value : undefined;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function withOptionalFields(
|
|
42
|
+
value: GameParticipationStatus,
|
|
43
|
+
fields: Partial<Pick<
|
|
44
|
+
GameParticipationStatus,
|
|
45
|
+
'mode' | 'room_code' | 'room_type' | 'room_status' | 'game_id'
|
|
46
|
+
>>,
|
|
47
|
+
): GameParticipationStatus {
|
|
48
|
+
if (fields.mode !== undefined) value.mode = fields.mode;
|
|
49
|
+
if (fields.room_code !== undefined) value.room_code = fields.room_code;
|
|
50
|
+
if (fields.room_type !== undefined) value.room_type = fields.room_type;
|
|
51
|
+
if (fields.room_status !== undefined) value.room_status = fields.room_status;
|
|
52
|
+
if (fields.game_id !== undefined) value.game_id = fields.game_id;
|
|
53
|
+
return value;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Query the backend-owned participation state.
|
|
58
|
+
*
|
|
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.
|
|
62
|
+
*/
|
|
63
|
+
export async function queryGameParticipationStatus(
|
|
64
|
+
client: ParticipationStatusClient,
|
|
65
|
+
): Promise<GameParticipationStatus> {
|
|
66
|
+
const queueResult = await client.getQueueStatus('clawclaw');
|
|
67
|
+
const queue = unwrapData(queueResult);
|
|
68
|
+
const currentQueueStatus = queueStatus(queueResult) ?? null;
|
|
69
|
+
const mode = queueMode(queueResult);
|
|
70
|
+
const roomCode = queueRoomCode(queueResult);
|
|
71
|
+
const base = (status: GameParticipationState): GameParticipationStatus =>
|
|
72
|
+
withOptionalFields({
|
|
73
|
+
schema: GAME_STATUS_SCHEMA,
|
|
74
|
+
status,
|
|
75
|
+
queue_status: currentQueueStatus,
|
|
76
|
+
}, {
|
|
77
|
+
mode,
|
|
78
|
+
room_code: roomCode,
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
if (currentQueueStatus === 'not_in_queue') return base('idle');
|
|
82
|
+
|
|
83
|
+
if (
|
|
84
|
+
currentQueueStatus === 'queued'
|
|
85
|
+
|| currentQueueStatus === 'already_in_queue'
|
|
86
|
+
|| currentQueueStatus === 'allocating'
|
|
87
|
+
) {
|
|
88
|
+
return base('matching');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (currentQueueStatus === 'allocated') {
|
|
92
|
+
return withOptionalFields(base('in_game'), {
|
|
93
|
+
game_id: stringField(queue?.game_id),
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (currentQueueStatus === 'in_room') {
|
|
98
|
+
const room = normalizeRoomSnapshot(await client.getRoomStatus());
|
|
99
|
+
const roomType = stringField(room.room_type);
|
|
100
|
+
const status: GameParticipationState = isTrainingRoomMode(roomType)
|
|
101
|
+
? 'training_room'
|
|
102
|
+
: roomType === 'casual'
|
|
103
|
+
? 'friend_room'
|
|
104
|
+
: 'room';
|
|
105
|
+
return withOptionalFields(base(status), {
|
|
106
|
+
room_code: stringField(room.room_code) ?? roomCode,
|
|
107
|
+
room_type: roomType,
|
|
108
|
+
room_status: stringField(room.status),
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return base('unknown');
|
|
113
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { ApiError } from './http-transport.js';
|
|
3
|
+
import { jsonTransportResponse } from '../short-command/transport-response.js';
|
|
4
|
+
import {
|
|
5
|
+
isServiceMaintenanceApiError,
|
|
6
|
+
parseServerServiceStatus,
|
|
7
|
+
serverServiceStatusFromApiError,
|
|
8
|
+
serverServiceStatusFromEnvelope,
|
|
9
|
+
} from './service-status.js';
|
|
10
|
+
|
|
11
|
+
const maintenance = {
|
|
12
|
+
starts_at: '2026-08-05T01:00:00+00:00',
|
|
13
|
+
ends_at: '2026-08-05T03:00:00+00:00',
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
describe('service status contract', () => {
|
|
17
|
+
it('extracts upcoming maintenance from a successful Lobby envelope', () => {
|
|
18
|
+
expect(serverServiceStatusFromEnvelope({
|
|
19
|
+
success: true,
|
|
20
|
+
data: { status: 'queued' },
|
|
21
|
+
server: { service_status: 'maintenance_upcoming', maintenance },
|
|
22
|
+
})).toEqual({ service_status: 'maintenance_upcoming', maintenance });
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('extracts active maintenance and Retry-After from an ApiError', () => {
|
|
26
|
+
const payload = {
|
|
27
|
+
success: false,
|
|
28
|
+
error: { code: 'SERVICE_MAINTENANCE', message: 'Service is under maintenance' },
|
|
29
|
+
server: { service_status: 'maintenance_active', maintenance },
|
|
30
|
+
};
|
|
31
|
+
const response = jsonTransportResponse(payload, {
|
|
32
|
+
method: 'GET',
|
|
33
|
+
path: '/api/v1/queue/status',
|
|
34
|
+
status: 503,
|
|
35
|
+
headers: { 'content-type': 'application/json', 'retry-after': '7200' },
|
|
36
|
+
});
|
|
37
|
+
const error = new ApiError(503, response.body.rawText, 'GET', response.path, response);
|
|
38
|
+
|
|
39
|
+
expect(serverServiceStatusFromApiError(error)).toEqual({
|
|
40
|
+
service_status: 'maintenance_active',
|
|
41
|
+
maintenance,
|
|
42
|
+
retry_after_seconds: 7200,
|
|
43
|
+
});
|
|
44
|
+
expect(isServiceMaintenanceApiError(error)).toBe(true);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('rejects unrelated 503 responses and malformed status values', () => {
|
|
48
|
+
const response = jsonTransportResponse({ error: { code: 'UPSTREAM_UNAVAILABLE' } }, {
|
|
49
|
+
status: 503,
|
|
50
|
+
});
|
|
51
|
+
const error = new ApiError(503, response.body.rawText, 'GET', '/api/v1/queue/status', response);
|
|
52
|
+
|
|
53
|
+
expect(serverServiceStatusFromApiError(error)).toBeUndefined();
|
|
54
|
+
expect(parseServerServiceStatus({ service_status: 'paused' })).toBeUndefined();
|
|
55
|
+
});
|
|
56
|
+
});
|