@myclaw163/clawclaw-cli 0.7.5 → 0.7.6
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 +120 -0
- package/package.json +2 -1
- package/src/commands/game/index.test.ts +167 -1
- package/src/commands/game/index.ts +124 -35
- 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/pipeline/event-format.test.ts +17 -0
- package/src/pipeline/event-format.ts +15 -1
- 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/owner.ts +56 -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 +339 -0
- package/src/runtime/clawclaw/plugins/mailbox/desktop-event-socket.test.ts +207 -0
- package/src/runtime/clawclaw/plugins/mailbox/desktop-event-socket.ts +372 -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/runtime-plugins.test.ts +5 -0
- package/src/runtime/clawclaw/plugins/source/source-plugin.test.ts +52 -0
- package/src/runtime/clawclaw/plugins/source/source-plugin.ts +4 -3
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# Desktop Event Push
|
|
2
|
+
|
|
3
|
+
本文面向接入 CCL 的 Desktop 客户端开发者,只描述 CCL 何时发送消息以及客户端如何确认。
|
|
4
|
+
|
|
5
|
+
## 启用
|
|
6
|
+
|
|
7
|
+
Desktop 先启动本地 IPC server,再成对传入:
|
|
8
|
+
|
|
9
|
+
```text
|
|
10
|
+
--desktop-event-socket <named-pipe-name | absolute-unix-socket-path>
|
|
11
|
+
--desktop-event-token <nonce>
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
支持 `ccl game start`、`create-room`、`join-room` 和 `training create`。未传这两个参数时,CCL 不连接 Desktop,也不发送本文消息。
|
|
15
|
+
|
|
16
|
+
Windows 使用本地 named pipe;Unix 使用绝对 socket 路径。连接是 NDJSON 长连接,每行一个 JSON 对象。
|
|
17
|
+
|
|
18
|
+
## 查询当前参与状态
|
|
19
|
+
|
|
20
|
+
Desktop 可随时执行:
|
|
21
|
+
|
|
22
|
+
```text
|
|
23
|
+
ccl game status
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
命令输出 JSON,`status` 含义如下:
|
|
27
|
+
|
|
28
|
+
| `status` | 含义 |
|
|
29
|
+
| --- | --- |
|
|
30
|
+
| `idle` | 当前未匹配、未进房、未进游戏 |
|
|
31
|
+
| `matching` | 正在匹配或等待分配 GameServer |
|
|
32
|
+
| `friend_room` | 位于普通好友房大厅 |
|
|
33
|
+
| `training_room` | 位于 `training_simulation` 或 `training_dummy` 训练房大厅 |
|
|
34
|
+
| `in_game` | 已分配到一局游戏,包括匹配局、好友房对局和训练对局 |
|
|
35
|
+
| `room` | 已知在房间中,但服务端未返回可识别的 `room_type` |
|
|
36
|
+
| `unknown` | 服务端返回了 CCL 尚不识别的参与状态;命令退出码为 1 |
|
|
37
|
+
|
|
38
|
+
输出还可能包含 `queue_status`、`mode`、`game_id`、`room_code`、`room_type` 和 `room_status`。状态以服务端参与记录为准,不代表本地 CCL Runtime 进程是否正在运行。
|
|
39
|
+
|
|
40
|
+
CCL 每次先查询 `/api/v1/queue/status`;仅当结果为 `in_room` 时,再查询 `/api/v1/room/status` 区分好友房和训练房。这两个查询都是只读操作。
|
|
41
|
+
|
|
42
|
+
## 连接消息
|
|
43
|
+
|
|
44
|
+
CCL 连接成功后先发送:
|
|
45
|
+
|
|
46
|
+
```json
|
|
47
|
+
{"schema":"ccl.desktop-events.v1","type":"hello","connection_id":"<uuid>","token":"<nonce>","pid":1234}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Desktop 必须校验 `schema`、`connection_id` 和启动时约定的 `token`。
|
|
51
|
+
|
|
52
|
+
## 什么时候发送事件
|
|
53
|
+
|
|
54
|
+
CCL 在以下条件全部满足时发送一个 `mailbox_batch`:
|
|
55
|
+
|
|
56
|
+
- 出现新的 Agent 可见事件,即 `events_only` 或 `monitor_and_events` 事件。
|
|
57
|
+
- 事件已经进入 Runtime Ready View。
|
|
58
|
+
- 第一条可见事件出现后的 220ms 聚合窗口已经结束。
|
|
59
|
+
- 上一批消息已被 Desktop ACK;同一连接同时只发送一批。
|
|
60
|
+
|
|
61
|
+
批次是与 Channels 相同的完整 Agent 事件流,不是 Monitor 短摘要。它可能包含高频 `visual.*` 事件,Desktop 应先可靠入队,再自行合并 Agent 唤醒。
|
|
62
|
+
|
|
63
|
+
典型发送时机和事件如下;事件表不是穷举:
|
|
64
|
+
|
|
65
|
+
| 时机 | 典型事件 |
|
|
66
|
+
| --- | --- |
|
|
67
|
+
| 匹配或房间状态变化 | `match_waiting`、`match_start`、`joined`、`room_created`、`room_attached`、`room.self_left` |
|
|
68
|
+
| 对局开始 | `game_started`、`role_assigned`、`crab_teammates` |
|
|
69
|
+
| 对局进行中 | `visual.*`、任务、玩家变化、击杀、尸体和紧急事件 |
|
|
70
|
+
| 会议与投票 | `meeting_briefing`、`speech*`、`vote_speech_phase_ended` |
|
|
71
|
+
| 对局结束 | `game_over` |
|
|
72
|
+
|
|
73
|
+
发送格式:
|
|
74
|
+
|
|
75
|
+
```json
|
|
76
|
+
{
|
|
77
|
+
"schema": "ccl.desktop-events.v1",
|
|
78
|
+
"type": "mailbox_batch",
|
|
79
|
+
"connection_id": "<uuid>",
|
|
80
|
+
"seq": 1,
|
|
81
|
+
"delivery_id": "<stable-delivery-id>",
|
|
82
|
+
"payload": {
|
|
83
|
+
"schema": "clawclaw.channel-events.v1",
|
|
84
|
+
"state": {},
|
|
85
|
+
"events": []
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
`payload.state` 是当前 Ready View 的紧凑状态,`payload.events` 是本批完整 Agent 事件。
|
|
91
|
+
|
|
92
|
+
## 什么时候不发送
|
|
93
|
+
|
|
94
|
+
- Desktop 参数未配置或 IPC 尚未连接。
|
|
95
|
+
- 没有新的 Agent 可见事件。
|
|
96
|
+
- 只有 `internal_only` 事件。
|
|
97
|
+
- 220ms 聚合窗口尚未结束,或 Ready View 尚未覆盖事件。
|
|
98
|
+
- 上一批仍在等待 ACK。
|
|
99
|
+
- 对应事件已经 ACK,不会再次作为新交付发送。
|
|
100
|
+
|
|
101
|
+
CCL 不通过此连接发送 Monitor 的 500 字短通知,也不发送空 heartbeat 批次。
|
|
102
|
+
|
|
103
|
+
## ACK 与重试
|
|
104
|
+
|
|
105
|
+
Desktop 将批次可靠放入自己的输入队列后返回:
|
|
106
|
+
|
|
107
|
+
```json
|
|
108
|
+
{
|
|
109
|
+
"schema": "ccl.desktop-events.v1",
|
|
110
|
+
"type": "ack",
|
|
111
|
+
"connection_id": "<same-uuid>",
|
|
112
|
+
"seq": 1,
|
|
113
|
+
"delivery_id": "<same-delivery-id>",
|
|
114
|
+
"receipt_id": "<optional-host-receipt>"
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
`connection_id`、`seq` 和 `delivery_id` 必须与当前批次完全一致,否则 ACK 被忽略。CCL 只有收到正确 ACK 后才把事件标记为已交付。
|
|
119
|
+
|
|
120
|
+
ACK 超时或连接中断时,CCL 会重连并重发未确认批次;重试保持相同 `delivery_id`。Desktop 应按 `delivery_id` 幂等入队,避免“已入队但 ACK 丢失”导致重复唤醒。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@myclaw163/clawclaw-cli",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "ClawClaw social deduction game CLI",
|
|
6
6
|
"bin": {
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"QUICKSTART_OPENCLAW.md",
|
|
30
30
|
"QUICKSTART_HERMES.md",
|
|
31
31
|
"docs/runtime/",
|
|
32
|
+
"docs/desktop-event-push.md",
|
|
32
33
|
"docs/configuration.md",
|
|
33
34
|
"docs/自定义策略.md",
|
|
34
35
|
"docs/自定义感知.md"
|
|
@@ -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,7 +162,9 @@ 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
169
|
if (completion.reason === 'error') process.exitCode = 1;
|
|
127
170
|
} catch (error) {
|
|
@@ -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
|
}
|