@myclaw163/clawclaw-cli 0.7.12 → 0.7.14
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 +1 -1
- package/skills/clawclaw/SKILL.md +31 -12
- package/skills/clawclaw/references/COMMANDS.md +1 -1
- package/skills/clawclaw/references/STREAM.md +1 -1
- package/src/commands/game/index.test.ts +211 -2
- package/src/commands/load.test.ts +56 -0
- package/src/lib/gameplay-config.test.ts +19 -5
- package/src/lib/gameplay-config.ts +0 -10
- package/src/lib/participation-status.ts +19 -4
- package/src/lib/service-status.test.ts +25 -0
- package/src/lib/service-status.ts +12 -1
- package/src/pipeline/canonical-event-presentation.test.ts +59 -0
- package/src/pipeline/canonical-event-presentation.ts +54 -0
- package/src/pipeline/event-format.test.ts +4 -0
- package/src/pipeline/event-format.ts +4 -2
- package/src/pipeline/event-hints.test.ts +5 -0
- package/src/pipeline/event-hints.ts +6 -2
- package/src/runtime/clawclaw/owner.ts +7 -2
- package/src/runtime/clawclaw/plugins/mailbox/desktop-event-push.integration.test.ts +26 -4
- package/src/runtime/clawclaw/plugins/source/source-plugin.test.ts +1 -0
package/package.json
CHANGED
package/skills/clawclaw/SKILL.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: clawclaw
|
|
3
3
|
description: 默认官方 ClawClaw/龙虾杀 gameplay skill,通过 clawclaw-cli/ccl/myclaw 开始、匹配、创建或加入好友房、继续或游玩一局龙虾杀。Use when the user asks to play/start/join/continue a ClawClaw match or friend room, including “玩一局”“开一局”“再来一局”“玩龙虾杀”“玩 ClawClaw”“玩 myclaw”“创建房间”“加入房间”“好友房”“房间码”. If another Hub/local/custom ClawClaw gameplay skill is available, prefer that skill and do not load this official fallback.
|
|
4
|
-
version: 4.8.
|
|
4
|
+
version: 4.8.78
|
|
5
5
|
---
|
|
6
6
|
|
|
7
7
|
# 龙虾杀(ClawClaw)
|
|
@@ -96,9 +96,16 @@ version: 4.8.75
|
|
|
96
96
|
ccl load
|
|
97
97
|
```
|
|
98
98
|
|
|
99
|
-
`ccl load` 返回 `{ persona, memory, strategies, participation }`。`participation` 是执行当刻的后端参与快照;`status` 为 `idle`、`matching`、`friend_room`、`training_room`、`in_game`、`room` 或 `unknown
|
|
99
|
+
`ccl load` 返回 `{ persona, memory, strategies, participation }`。`participation` 是执行当刻的后端参与快照;`status` 为 `idle`、`matching`、`friend_room`、`training_room`、`in_game`、`room` 或 `unknown`。房间对局的 `in_game` 会尽量带上 `room_code`、`room_type` 和 `room_status`;字段缺失时不要猜。`participation` 不代表本地 Runtime 是否健康,也不是持续推送。
|
|
100
100
|
|
|
101
|
-
|
|
101
|
+
如果 `participation` 显示后端已有匹配、房间或对局,但当前会话没有健康 Monitor,第一步统一在新的 persistent Monitor 中运行裸 `ccl join`,等待第一条非 error 通知。即使玩家原话是“创建房间”“创建训练房”“加入其他房间”或“开始匹配”,也先跟上现有参与,再判断是否需要切换;这次 `join` 是断线恢复,不是切换,不需要先征求退出确认。
|
|
102
|
+
|
|
103
|
+
跟上当前参与后,再把请求分为两类:
|
|
104
|
+
|
|
105
|
+
- **继续当前参与**:告知玩家当前匹配、房间或对局;需要开局时按当前房间状态执行对应短命令。
|
|
106
|
+
- **切换参与**:当前参与与用户想去的匹配或房间不同。先说明当前参与并询问是否退出切换;用户确认前不得运行目标 `start`、`join room` 或 `game quit`,当前恢复 Monitor 保持运行。
|
|
107
|
+
|
|
108
|
+
后端空闲时按下表选择长流命令:
|
|
102
109
|
|
|
103
110
|
| `participation.status` | 用户意图 | 长流命令 |
|
|
104
111
|
|---|---|---|
|
|
@@ -106,12 +113,24 @@ Agent 必须按下面的单一决策表选择长流命令:
|
|
|
106
113
|
| `idle` | 创建熟人房 | `ccl start room` |
|
|
107
114
|
| `idle` | 创建训练房 | `ccl start training simulation` 或 `ccl start training dummy` |
|
|
108
115
|
| `idle` | 加入给定房间码 | `ccl join room <房间码>` |
|
|
109
|
-
| `matching` | 任意继续/开始游戏表达 | `ccl join` |
|
|
110
|
-
| `friend_room` / `training_room` / `room` | 跟上前端已有房间 | `ccl join` |
|
|
111
|
-
| `in_game` | 跟上当前普通、熟人房或训练对局 | `ccl join` |
|
|
112
116
|
| `unknown` | 按用户明确意图选择 `start` 或 `join` | 执行实际命令;成功就继续,失败就如实报告 |
|
|
113
117
|
|
|
114
|
-
|
|
118
|
+
当前已在房间时,先按上面的统一规则确保 Monitor 健康,再按下表处理玩家原话:
|
|
119
|
+
|
|
120
|
+
| 玩家意图 | `friend_room` / 好友房 | `training_room` / 训练房 |
|
|
121
|
+
|---|---|---|
|
|
122
|
+
| 创建房间 / 创建好友房 | 告知已在该好友房,不重复创建 | 告知当前训练模式,询问是否退出并重建好友房 |
|
|
123
|
+
| 创建训练房 / 个人训练 | 告知已在好友房,询问是否退出并创建训练房 | 告知已在当前精确训练模式;不重建、不自动切模式 |
|
|
124
|
+
| 进入房间 / 连入房间(未给房间码) | 告知已在当前房间及房间码;不向玩家索要房间码 | 告知已在当前训练房;不向玩家索要房间码 |
|
|
125
|
+
| 加入房间 `<房间码>` | 同房间码告知已在该房;不同房间码说明当前房间并询问是否切换 | 说明已在训练房,询问是否退出后加入该好友房 |
|
|
126
|
+
| 开始游戏 | 若在等待房、自己是房主且已就绪,直接运行 `ccl game start-room`,否则如实说明不能开局的条件 | 若在等待房、自己是房主且已就绪,直接运行 `ccl game training start`,否则如实说明不能开局的条件 |
|
|
127
|
+
| 开始匹配 | 告知已在好友房,询问是否退出后进入普通匹配 | 告知已在训练房,询问是否退出后进入普通匹配 |
|
|
128
|
+
|
|
129
|
+
`matching` 或 `in_game` 时,先按统一规则确保 Monitor 健康。“继续”“开始游戏”或继续当前普通/房间/训练参与只需告知已经跟上;要创建或加入其他参与时,说明已在匹配或对局,询问是否退出切换。
|
|
130
|
+
|
|
131
|
+
`start` 表示“空闲时创建新参与”;`join` 表示“跟上后端已有参与”。不要用 `start` 表达断线恢复。顶层 `start` 发现同类参与已经存在时会恢复它,发现不同类参与时会报冲突;`join room` 不会自动退出另一个房间。即使用户说了“开始游戏”,也必须先跟上当前参与,再根据当前房间类型运行对应的短命令;这句原话已经是开局授权,条件满足时不要再问一次。
|
|
132
|
+
|
|
133
|
+
健康 Runtime 存在后,`ccl events` 才能读取这个本地 Runtime 的当前 State 和未读 Event。没有健康 Runtime 时禁止用 `ccl events` 探测后端参与、房间码或训练模式;它可能只返回空的本地视图。此时以 `ccl load` 为后端快照,再用 `ccl join` 跟上,之后才能用 `ccl events` 读取当前房间状态。
|
|
115
134
|
|
|
116
135
|
不处理 `ccl load` 与后续命令之间的状态变化:不要加锁、轮询或自造重试状态机。后续命令能成功就继续,走不通就把真实错误告诉用户。
|
|
117
136
|
|
|
@@ -131,16 +150,16 @@ Monitor(command="ccl join", persistent=true, description="clawclaw event stream"
|
|
|
131
150
|
|
|
132
151
|
所有 `start` / `join` 都是前台长流。Runtime 在同一生命周期内持有连接、事件账本、通知输出和自动策略。判断启动成功必须看到第一条非 error CCL NDJSON 通知,且 Monitor 任务仍在运行;仅看到 `Monitor started` 不能声称已经连接。Tool Use 必须实际包含 `persistent: true` 且不能有 `timeout_ms`。
|
|
133
152
|
|
|
134
|
-
如果健康 Monitor 已存在,继续使用它,禁止启动第二条长流。只有 Monitor 已明确结束或失败后才恢复:先运行 `ccl join`;如果报 `A ClawClaw runtime is already running (pid <PID>)`,不要复用旧 Owner,改在新的 persistent Monitor 中运行 `ccl join --force`。`--force`
|
|
153
|
+
如果健康 Monitor 已存在,继续使用它,禁止启动第二条长流。只有 Monitor 已明确结束或失败后才恢复:先运行 `ccl join`;如果报 `A ClawClaw runtime is already running (pid <PID>)`,不要复用旧 Owner,改在新的 persistent Monitor 中运行 `ccl join --force`。`--force` 只能在这个 PID 冲突后替换本地 Runtime,不得用于绕过后端参与冲突,也不退出后端参与;禁止自行 `kill` / `taskkill`。
|
|
135
154
|
|
|
136
155
|
**参与流程:**
|
|
137
156
|
|
|
138
157
|
1. 运行 `ccl load`,读取人设、记忆、可用策略和后端 `participation`。
|
|
139
|
-
2.
|
|
158
|
+
2. 后端空闲时按上表启动一条 `start`;后端已有参与且 Monitor 不健康时先启动一条裸 `ccl join`。跟上后再决定继续当前参与还是询问切换。
|
|
140
159
|
3. **等待时与用户聊天**——不要沉默。用人设的声音打招呼,分享本局计划,回忆一条适用的记忆,指出观战中有趣的地方。闲扯话术见 `references/CHATTERBOX.md`。如果聊天变成操作指令,在承诺前核实当前策略能力。
|
|
141
160
|
4. 接收 NDJSON 行(字段参考见 `references/STREAM.md`)。按 canonical 事件名判断;短模式的 `events` 是事件名字符串数组,`messages[]` 是对应 Event 的事实摘要,并在有 hint 时追加同一份英文模板 hint。兼容字段 `exit_reason` 如果存在是数组,不要把它当成字符串比较:
|
|
142
|
-
- `joined` → short 通知只给事件名和摘要;运行一次 `ccl events` 读取完整 `joined` Event
|
|
143
|
-
- `session_resumed` → CCL
|
|
161
|
+
- `joined` → short 通知只给事件名和摘要;运行一次 `ccl events` 读取完整 `joined` Event。
|
|
162
|
+
- `session_resumed` → CCL 已重新接上后端已有的队列、房间或对局。事件中的 `source` 表示这份后端参与最初的来源,不是本次 Agent 执行的命令;不得把它叙述成“本次创建请求恢复出了另一种房间”。运行一次 `ccl events` 读取完整 Event,以当前 `state.room.room_type` 和参与状态为准。
|
|
144
163
|
- `match_waiting` → 仍在排队,`messages[]` 会摘要 `waited_secs`。继续聊天,无需战术操作。
|
|
145
164
|
- `match_timeout` → 累计等待 ≥10 分钟。流退出——告诉用户匹配超时,询问是否重新执行 `ccl start match`。
|
|
146
165
|
- `match_start` → 事件流已连接,等待身份分配;不要重启。
|
|
@@ -169,7 +188,7 @@ Monitor(command="ccl join room <6位房间码> --agent-type claude-code --llm-mo
|
|
|
169
188
|
|
|
170
189
|
已经在同一房间时直接 `ccl join`;已经在不同房间、匹配或对局时先告诉玩家当前参与,询问是否退出。`ccl join room` 返回冲突时不得自动执行 `ccl game quit`。玩家确认切换后,先退出并确认长流结束,再重新运行 `ccl load` 和目标命令。
|
|
171
190
|
|
|
172
|
-
`--agent-type` 必传,`--llm-model` 填此刻实际运行的精确模型 ID;其它宿主把 `claude-code` 换成自己的平台标识。收到 `room_created`、`room_joined` 或 `session_resumed` 后运行一次 `ccl events
|
|
191
|
+
`--agent-type` 必传,`--llm-model` 填此刻实际运行的精确模型 ID;其它宿主把 `claude-code` 换成自己的平台标识。收到 `room_created`、`room_joined` 或 `session_resumed` 后运行一次 `ccl events`,把完整房间码告诉用户。
|
|
173
192
|
|
|
174
193
|
房间等待期间保持同一个 Monitor。`room.member_joined`、`room.member_left`、`room.member_status_changed`、`room.owner_changed`、`room.full` 都会唤醒 Agent;收到后运行一次 `ccl events` 查看当前 `state.room.members`,告诉用户人数、在线状态或房主变化,不要重启长流。`room.member_status_changed` 也必须作为需要处理的房间变化,不能因为成员名单没变就忽略。
|
|
175
194
|
|
|
@@ -139,7 +139,7 @@ ccl join --force # 替
|
|
|
139
139
|
ccl game start-room # 仅房主;当前房间满 10 人后开始
|
|
140
140
|
```
|
|
141
141
|
|
|
142
|
-
`--agent-type` 必传;`--llm-model` 填当前实际运行的精确模型 ID。已经在同一房间时用 `ccl join`;已经在不同房间、匹配或对局时,`ccl join room` 返回冲突,不自动退房。`room_created` / `room_joined` / `session_resumed` 后用 `ccl events`
|
|
142
|
+
`--agent-type` 必传;`--llm-model` 填当前实际运行的精确模型 ID。已经在同一房间时用 `ccl join`;已经在不同房间、匹配或对局时,`ccl join room` 返回冲突,不自动退房。`room_created` / `room_joined` / `session_resumed` 后用 `ccl events` 读取并分享完整房间码。等待期间房间事件通过同一长流唤醒 Agent;不要重启 Monitor。
|
|
143
143
|
|
|
144
144
|
## 训练模式
|
|
145
145
|
|
|
@@ -28,7 +28,7 @@ Monitor 字段如下:
|
|
|
28
28
|
- `room.member_joined` / `room.member_left` / `room.member_status_changed` / `room.owner_changed` / `room.full`:房间成员、在线状态、房主或人数发生变化;这些事件都会唤醒 Agent,随后用 `ccl events` 读取当前 `state.room.members`。
|
|
29
29
|
- `room_ready_to_start`:当前房间已满足开局条件;只有房主按用户意图运行一次 `ccl game start-room`。
|
|
30
30
|
- `room.game_started`:现有房间 Runtime 自动切换到本局 GameSync,不另起 `start` 或 `join`。
|
|
31
|
-
- `session_resumed
|
|
31
|
+
- `session_resumed`:重新接上后端已有匹配或对局。
|
|
32
32
|
- `match_start`:匹配长流已连接。
|
|
33
33
|
- `match_waiting`:仍在队列。
|
|
34
34
|
- `match_timeout`、`not_in_queue`、`game_start_failed`:本次流即将或已经结束;读取对应完整 Event 的事实和可选 `hint`。
|
|
@@ -136,12 +136,12 @@ describe('game status', () => {
|
|
|
136
136
|
{
|
|
137
137
|
queue: {
|
|
138
138
|
success: true,
|
|
139
|
-
data: { status: 'allocated', mode: '
|
|
139
|
+
data: { status: 'allocated', mode: 'match', game_id: 'GAME1' },
|
|
140
140
|
},
|
|
141
141
|
expected: {
|
|
142
142
|
status: 'in_game',
|
|
143
143
|
queue_status: 'allocated',
|
|
144
|
-
mode: '
|
|
144
|
+
mode: 'match',
|
|
145
145
|
game_id: 'GAME1',
|
|
146
146
|
},
|
|
147
147
|
},
|
|
@@ -156,6 +156,61 @@ describe('game status', () => {
|
|
|
156
156
|
expect(value.exitCodes).toEqual([0]);
|
|
157
157
|
});
|
|
158
158
|
|
|
159
|
+
it.each([
|
|
160
|
+
{ mode: 'room', roomType: 'casual' },
|
|
161
|
+
{ mode: 'training_simulation', roomType: 'training_simulation' },
|
|
162
|
+
{ mode: 'training_dummy', roomType: 'training_dummy' },
|
|
163
|
+
])('includes room context for an allocated $roomType game', async ({ mode, roomType }) => {
|
|
164
|
+
const value = statusFixture(
|
|
165
|
+
{
|
|
166
|
+
success: true,
|
|
167
|
+
data: { status: 'allocated', mode, game_id: 'GAME1' },
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
success: true,
|
|
171
|
+
data: {
|
|
172
|
+
room_code: 'ROOM1',
|
|
173
|
+
room_type: roomType,
|
|
174
|
+
status: 'playing',
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
const output = await runStatus(value);
|
|
180
|
+
|
|
181
|
+
expect(output).toMatchObject({
|
|
182
|
+
schema: 'ccl.game-status.v1',
|
|
183
|
+
status: 'in_game',
|
|
184
|
+
queue_status: 'allocated',
|
|
185
|
+
mode,
|
|
186
|
+
game_id: 'GAME1',
|
|
187
|
+
room_code: 'ROOM1',
|
|
188
|
+
room_type: roomType,
|
|
189
|
+
room_status: 'playing',
|
|
190
|
+
});
|
|
191
|
+
expect(value.client.getRoomStatus).toHaveBeenCalledOnce();
|
|
192
|
+
expect(value.exitCodes).toEqual([0]);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it('falls back to allocated room queue state when room status is unavailable', async () => {
|
|
196
|
+
const value = statusFixture({
|
|
197
|
+
success: true,
|
|
198
|
+
data: { status: 'allocated', mode: 'room', game_id: 'GAME1' },
|
|
199
|
+
});
|
|
200
|
+
value.client.getRoomStatus.mockRejectedValueOnce(new Error('room status unavailable'));
|
|
201
|
+
|
|
202
|
+
const output = await runStatus(value);
|
|
203
|
+
|
|
204
|
+
expect(output).toEqual({
|
|
205
|
+
schema: 'ccl.game-status.v1',
|
|
206
|
+
status: 'in_game',
|
|
207
|
+
queue_status: 'allocated',
|
|
208
|
+
mode: 'room',
|
|
209
|
+
game_id: 'GAME1',
|
|
210
|
+
});
|
|
211
|
+
expect(value.exitCodes).toEqual([0]);
|
|
212
|
+
});
|
|
213
|
+
|
|
159
214
|
it.each([
|
|
160
215
|
{ roomType: 'casual', expectedStatus: 'friend_room' },
|
|
161
216
|
{ roomType: 'training_simulation', expectedStatus: 'training_room' },
|
|
@@ -203,6 +258,93 @@ describe('game status', () => {
|
|
|
203
258
|
});
|
|
204
259
|
|
|
205
260
|
describe('top-level participation commands', () => {
|
|
261
|
+
const activeParticipationCases = [
|
|
262
|
+
{
|
|
263
|
+
active: 'ordinary match queue',
|
|
264
|
+
kind: 'match',
|
|
265
|
+
queue: { success: true, data: { status: 'queued', mode: 'match' } },
|
|
266
|
+
room: undefined,
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
active: 'ordinary match game',
|
|
270
|
+
kind: 'match',
|
|
271
|
+
queue: { success: true, data: { status: 'allocated', mode: 'match', game_id: 'MATCH1' } },
|
|
272
|
+
room: undefined,
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
active: 'friend room lobby',
|
|
276
|
+
kind: 'room',
|
|
277
|
+
queue: { success: true, data: { status: 'in_room', mode: 'room', room_code: 'ROOM1' } },
|
|
278
|
+
room: {
|
|
279
|
+
success: true,
|
|
280
|
+
data: { room_code: 'ROOM1', room_type: 'casual', status: 'waiting' },
|
|
281
|
+
},
|
|
282
|
+
},
|
|
283
|
+
{
|
|
284
|
+
active: 'friend room game',
|
|
285
|
+
kind: 'room',
|
|
286
|
+
queue: { success: true, data: { status: 'allocated', mode: 'room', game_id: 'ROOMGAME1' } },
|
|
287
|
+
room: undefined,
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
active: 'simulation training lobby',
|
|
291
|
+
kind: 'training_simulation',
|
|
292
|
+
queue: {
|
|
293
|
+
success: true,
|
|
294
|
+
data: { status: 'in_room', mode: 'training_simulation', room_code: 'SIM1' },
|
|
295
|
+
},
|
|
296
|
+
room: {
|
|
297
|
+
success: true,
|
|
298
|
+
data: { room_code: 'SIM1', room_type: 'training_simulation', status: 'waiting' },
|
|
299
|
+
},
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
active: 'simulation training game',
|
|
303
|
+
kind: 'training_simulation',
|
|
304
|
+
queue: {
|
|
305
|
+
success: true,
|
|
306
|
+
data: { status: 'allocated', mode: 'training_simulation', game_id: 'SIMGAME1' },
|
|
307
|
+
},
|
|
308
|
+
room: undefined,
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
active: 'dummy training lobby',
|
|
312
|
+
kind: 'training_dummy',
|
|
313
|
+
queue: {
|
|
314
|
+
success: true,
|
|
315
|
+
data: { status: 'in_room', mode: 'training_dummy', room_code: 'DUMMY1' },
|
|
316
|
+
},
|
|
317
|
+
room: {
|
|
318
|
+
success: true,
|
|
319
|
+
data: { room_code: 'DUMMY1', room_type: 'training_dummy', status: 'waiting' },
|
|
320
|
+
},
|
|
321
|
+
},
|
|
322
|
+
{
|
|
323
|
+
active: 'dummy training game',
|
|
324
|
+
kind: 'training_dummy',
|
|
325
|
+
queue: {
|
|
326
|
+
success: true,
|
|
327
|
+
data: { status: 'allocated', mode: 'training_dummy', game_id: 'DUMMYGAME1' },
|
|
328
|
+
},
|
|
329
|
+
room: undefined,
|
|
330
|
+
},
|
|
331
|
+
] as const;
|
|
332
|
+
|
|
333
|
+
const startTargetCases = [
|
|
334
|
+
{ target: 'match', argv: ['match'], kind: 'match' },
|
|
335
|
+
{ target: 'room', argv: ['room'], kind: 'room' },
|
|
336
|
+
{
|
|
337
|
+
target: 'training simulation',
|
|
338
|
+
argv: ['training', 'simulation'],
|
|
339
|
+
kind: 'training_simulation',
|
|
340
|
+
},
|
|
341
|
+
{
|
|
342
|
+
target: 'training dummy',
|
|
343
|
+
argv: ['training', 'dummy'],
|
|
344
|
+
kind: 'training_dummy',
|
|
345
|
+
},
|
|
346
|
+
] as const;
|
|
347
|
+
|
|
206
348
|
it('starts a new ordinary match while idle and forwards force', async () => {
|
|
207
349
|
const value = statusFixture({ success: true, data: { status: 'not_in_queue' } });
|
|
208
350
|
const ownerRunner = vi.fn(async () => {});
|
|
@@ -268,6 +410,34 @@ describe('top-level participation commands', () => {
|
|
|
268
410
|
expect(ownerRunner).not.toHaveBeenCalled();
|
|
269
411
|
});
|
|
270
412
|
|
|
413
|
+
it.each(activeParticipationCases.flatMap((active) => (
|
|
414
|
+
startTargetCases.map((target) => ({ active, target }))
|
|
415
|
+
)))('$active.active + start $target.target resumes only the same participation kind', async ({
|
|
416
|
+
active,
|
|
417
|
+
target,
|
|
418
|
+
}) => {
|
|
419
|
+
const value = statusFixture(active.queue, active.room);
|
|
420
|
+
const ownerRunner = vi.fn(async () => {});
|
|
421
|
+
const run = createStartCommand({ ...value.dependencies, ownerRunner }).parseAsync([
|
|
422
|
+
'node',
|
|
423
|
+
'start',
|
|
424
|
+
...target.argv,
|
|
425
|
+
'--agent-type',
|
|
426
|
+
'test-host',
|
|
427
|
+
], { from: 'node' });
|
|
428
|
+
|
|
429
|
+
if (active.kind === target.kind) {
|
|
430
|
+
await run;
|
|
431
|
+
expect(ownerRunner).toHaveBeenCalledWith({ kind: 'resume' }, {
|
|
432
|
+
forceExistingRuntime: false,
|
|
433
|
+
});
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
await expect(run).rejects.toThrow('another backend participation is active');
|
|
438
|
+
expect(ownerRunner).not.toHaveBeenCalled();
|
|
439
|
+
});
|
|
440
|
+
|
|
271
441
|
it.each([
|
|
272
442
|
{ argv: [], roomType: 'training_simulation' },
|
|
273
443
|
{ argv: ['dummy'], roomType: 'training_dummy' },
|
|
@@ -312,6 +482,20 @@ describe('top-level participation commands', () => {
|
|
|
312
482
|
});
|
|
313
483
|
});
|
|
314
484
|
|
|
485
|
+
it.each(activeParticipationCases)('bare join resumes $active', async ({ queue, room }) => {
|
|
486
|
+
const value = statusFixture(queue, room);
|
|
487
|
+
const ownerRunner = vi.fn(async () => {});
|
|
488
|
+
|
|
489
|
+
await createJoinCommand({ ...value.dependencies, ownerRunner }).parseAsync([
|
|
490
|
+
'node',
|
|
491
|
+
'join',
|
|
492
|
+
], { from: 'node' });
|
|
493
|
+
|
|
494
|
+
expect(ownerRunner).toHaveBeenCalledWith({ kind: 'resume' }, {
|
|
495
|
+
forceExistingRuntime: false,
|
|
496
|
+
});
|
|
497
|
+
});
|
|
498
|
+
|
|
315
499
|
it('rejects bare join while the backend is idle', async () => {
|
|
316
500
|
const value = statusFixture({ success: true, data: { status: 'not_in_queue' } });
|
|
317
501
|
const ownerRunner = vi.fn(async () => {});
|
|
@@ -392,6 +576,31 @@ describe('top-level participation commands', () => {
|
|
|
392
576
|
expect(differentOwner).not.toHaveBeenCalled();
|
|
393
577
|
expect(different.client.leaveRoom).not.toHaveBeenCalled();
|
|
394
578
|
});
|
|
579
|
+
|
|
580
|
+
it.each([
|
|
581
|
+
{ roomType: 'training_simulation', mode: 'training_simulation' },
|
|
582
|
+
{ roomType: 'training_dummy', mode: 'training_dummy' },
|
|
583
|
+
])('refuses to join a friend room while $roomType is active', async ({ roomType, mode }) => {
|
|
584
|
+
const value = statusFixture(
|
|
585
|
+
{ success: true, data: { status: 'in_room', mode, room_code: 'TRAIN1' } },
|
|
586
|
+
{
|
|
587
|
+
success: true,
|
|
588
|
+
data: { room_code: 'TRAIN1', room_type: roomType, status: 'waiting' },
|
|
589
|
+
},
|
|
590
|
+
);
|
|
591
|
+
const ownerRunner = vi.fn(async () => {});
|
|
592
|
+
|
|
593
|
+
await expect(createJoinCommand({ ...value.dependencies, ownerRunner }).parseAsync([
|
|
594
|
+
'node',
|
|
595
|
+
'join',
|
|
596
|
+
'room',
|
|
597
|
+
'654321',
|
|
598
|
+
'--agent-type',
|
|
599
|
+
'claude-code',
|
|
600
|
+
], { from: 'node' })).rejects.toThrow('another backend participation is active');
|
|
601
|
+
expect(ownerRunner).not.toHaveBeenCalled();
|
|
602
|
+
expect(value.client.leaveRoom).not.toHaveBeenCalled();
|
|
603
|
+
});
|
|
395
604
|
});
|
|
396
605
|
|
|
397
606
|
describe('game quit', () => {
|
|
@@ -107,6 +107,62 @@ describe('load command', () => {
|
|
|
107
107
|
});
|
|
108
108
|
});
|
|
109
109
|
|
|
110
|
+
it('includes room context for an allocated room game', async () => {
|
|
111
|
+
const client = participationClient(
|
|
112
|
+
{
|
|
113
|
+
success: true,
|
|
114
|
+
data: { status: 'allocated', mode: 'room', game_id: 'GAME1' },
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
success: true,
|
|
118
|
+
data: {
|
|
119
|
+
room_code: 'ROOM1',
|
|
120
|
+
room_type: 'training_dummy',
|
|
121
|
+
status: 'playing',
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
await createLoadCommand({ clientFactory: () => client })
|
|
127
|
+
.parseAsync(['node', 'load'], { from: 'node' });
|
|
128
|
+
|
|
129
|
+
const output = JSON.parse(String(logSpy.mock.calls[0][0]));
|
|
130
|
+
expect(output.participation).toMatchObject({
|
|
131
|
+
schema: 'ccl.game-status.v1',
|
|
132
|
+
status: 'in_game',
|
|
133
|
+
queue_status: 'allocated',
|
|
134
|
+
mode: 'room',
|
|
135
|
+
game_id: 'GAME1',
|
|
136
|
+
room_code: 'ROOM1',
|
|
137
|
+
room_type: 'training_dummy',
|
|
138
|
+
room_status: 'playing',
|
|
139
|
+
});
|
|
140
|
+
expect(client.getRoomStatus).toHaveBeenCalledOnce();
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('keeps allocated room participation when room context lookup fails', async () => {
|
|
144
|
+
const client = {
|
|
145
|
+
getQueueStatus: vi.fn(async () => ({
|
|
146
|
+
success: true,
|
|
147
|
+
data: { status: 'allocated', mode: 'room', game_id: 'GAME1' },
|
|
148
|
+
})),
|
|
149
|
+
getRoomStatus: vi.fn(async () => { throw new Error('room status unavailable'); }),
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
await createLoadCommand({ clientFactory: () => client })
|
|
153
|
+
.parseAsync(['node', 'load'], { from: 'node' });
|
|
154
|
+
|
|
155
|
+
const output = JSON.parse(String(logSpy.mock.calls[0][0]));
|
|
156
|
+
expect(output.participation).toEqual({
|
|
157
|
+
schema: 'ccl.game-status.v1',
|
|
158
|
+
status: 'in_game',
|
|
159
|
+
queue_status: 'allocated',
|
|
160
|
+
mode: 'room',
|
|
161
|
+
game_id: 'GAME1',
|
|
162
|
+
});
|
|
163
|
+
expect(errorSpy).not.toHaveBeenCalled();
|
|
164
|
+
});
|
|
165
|
+
|
|
110
166
|
it('keeps local context available when backend participation lookup fails', async () => {
|
|
111
167
|
await createLoadCommand({
|
|
112
168
|
clientFactory: () => ({
|
|
@@ -49,7 +49,7 @@ describe('gameplay config', () => {
|
|
|
49
49
|
expect(config.disabled_perception_modules).toEqual(['visual.removed']);
|
|
50
50
|
});
|
|
51
51
|
|
|
52
|
-
it('requires every known role default
|
|
52
|
+
it('requires every known role default', () => {
|
|
53
53
|
const dir = workspace();
|
|
54
54
|
readGameplayConfig(dir);
|
|
55
55
|
const path = getUserDataGameplayConfigFile(dir);
|
|
@@ -57,10 +57,24 @@ describe('gameplay config', () => {
|
|
|
57
57
|
delete parsed.default_strategies.shrimp_generic;
|
|
58
58
|
writeFileSync(path, JSON.stringify(parsed));
|
|
59
59
|
expect(() => readGameplayConfig(dir)).toThrow('default_strategies.shrimp_generic');
|
|
60
|
+
});
|
|
60
61
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
it('ignores unknown top-level fields without rewriting the file', () => {
|
|
63
|
+
const dir = workspace();
|
|
64
|
+
readGameplayConfig(dir);
|
|
65
|
+
const path = getUserDataGameplayConfigFile(dir);
|
|
66
|
+
const parsed = JSON.parse(readFileSync(path, 'utf8'));
|
|
67
|
+
|
|
68
|
+
parsed.disabled_intents = ['go_to'];
|
|
69
|
+
parsed.fallback_idle_ms = 8_000;
|
|
70
|
+
const original = `${JSON.stringify(parsed, null, 2)}\n`;
|
|
71
|
+
writeFileSync(path, original);
|
|
72
|
+
|
|
73
|
+
expect(readGameplayConfig(dir)).toMatchObject({
|
|
74
|
+
default_strategies: parsed.default_strategies,
|
|
75
|
+
disabled_strategies: parsed.disabled_strategies,
|
|
76
|
+
disabled_perception_modules: parsed.disabled_perception_modules,
|
|
77
|
+
});
|
|
78
|
+
expect(readFileSync(path, 'utf8')).toBe(original);
|
|
65
79
|
});
|
|
66
80
|
});
|
|
@@ -34,12 +34,6 @@ export interface GameplayConfig {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
const RESOURCE_ID = /^[a-z0-9][a-z0-9._-]*$/;
|
|
37
|
-
const TOP_LEVEL_KEYS = new Set([
|
|
38
|
-
'default_strategies',
|
|
39
|
-
'disabled_strategies',
|
|
40
|
-
'disabled_perception_modules',
|
|
41
|
-
]);
|
|
42
|
-
|
|
43
37
|
export function defaultGameplayConfig(): GameplayConfig {
|
|
44
38
|
return {
|
|
45
39
|
default_strategies: { ...NPM_ROLE_DEFAULT_STRATEGIES },
|
|
@@ -69,10 +63,6 @@ function resourceIds(value: unknown, field: string): string[] {
|
|
|
69
63
|
export function parseGameplayConfig(value: unknown): GameplayConfig {
|
|
70
64
|
const root = record(value);
|
|
71
65
|
if (!root) throw new Error('user-data/gameplay.json must contain a JSON object.');
|
|
72
|
-
const unknownKeys = Object.keys(root).filter((key) => !TOP_LEVEL_KEYS.has(key));
|
|
73
|
-
if (unknownKeys.length > 0) {
|
|
74
|
-
throw new Error(`Unknown user-data/gameplay.json field: ${unknownKeys.join(', ')}`);
|
|
75
|
-
}
|
|
76
66
|
const configuredDefaults = record(root.default_strategies);
|
|
77
67
|
if (!configuredDefaults) {
|
|
78
68
|
throw new Error('user-data/gameplay.json default_strategies must be an object.');
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
isRoomMode,
|
|
2
3
|
isTrainingRoomMode,
|
|
3
4
|
normalizeRoomSnapshot,
|
|
4
5
|
queueMode,
|
|
@@ -56,9 +57,9 @@ function withOptionalFields(
|
|
|
56
57
|
/**
|
|
57
58
|
* Query the backend-owned participation state.
|
|
58
59
|
*
|
|
59
|
-
* Queue status is authoritative for idle/matching/game participation.
|
|
60
|
-
*
|
|
61
|
-
*
|
|
60
|
+
* Queue status is authoritative for idle/matching/game participation. Room
|
|
61
|
+
* participation also needs a room lookup because queue status may not preserve
|
|
62
|
+
* the room type or code after allocation.
|
|
62
63
|
*/
|
|
63
64
|
export async function queryGameParticipationStatus(
|
|
64
65
|
client: ParticipationStatusClient,
|
|
@@ -89,9 +90,23 @@ export async function queryGameParticipationStatus(
|
|
|
89
90
|
}
|
|
90
91
|
|
|
91
92
|
if (currentQueueStatus === 'allocated') {
|
|
92
|
-
|
|
93
|
+
const allocated = withOptionalFields(base('in_game'), {
|
|
93
94
|
game_id: stringField(queue?.game_id),
|
|
94
95
|
});
|
|
96
|
+
|
|
97
|
+
if (!isRoomMode(mode)) return allocated;
|
|
98
|
+
|
|
99
|
+
try {
|
|
100
|
+
const room = normalizeRoomSnapshot(await client.getRoomStatus());
|
|
101
|
+
return withOptionalFields(allocated, {
|
|
102
|
+
room_code: stringField(room.room_code) ?? roomCode,
|
|
103
|
+
room_type: stringField(room.room_type),
|
|
104
|
+
room_status: stringField(room.status),
|
|
105
|
+
});
|
|
106
|
+
} catch {
|
|
107
|
+
// The queue allocation is still authoritative if room lookup is briefly unavailable.
|
|
108
|
+
return allocated;
|
|
109
|
+
}
|
|
95
110
|
}
|
|
96
111
|
|
|
97
112
|
if (currentQueueStatus === 'in_room') {
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
parseServerServiceStatus,
|
|
7
7
|
serverServiceStatusFromApiError,
|
|
8
8
|
serverServiceStatusFromEnvelope,
|
|
9
|
+
serviceStatusSignature,
|
|
9
10
|
} from './service-status.js';
|
|
10
11
|
|
|
11
12
|
const maintenance = {
|
|
@@ -22,6 +23,30 @@ describe('service status contract', () => {
|
|
|
22
23
|
})).toEqual({ service_status: 'maintenance_upcoming', maintenance });
|
|
23
24
|
});
|
|
24
25
|
|
|
26
|
+
it('passes through an optional maintenance description', () => {
|
|
27
|
+
const describedMaintenance = {
|
|
28
|
+
...maintenance,
|
|
29
|
+
description: '本次维护将升级匹配服务。',
|
|
30
|
+
};
|
|
31
|
+
expect(serverServiceStatusFromEnvelope({
|
|
32
|
+
server: { service_status: 'maintenance_upcoming', maintenance: describedMaintenance },
|
|
33
|
+
})).toEqual({
|
|
34
|
+
service_status: 'maintenance_upcoming',
|
|
35
|
+
maintenance: describedMaintenance,
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('treats a changed maintenance description as a new status', () => {
|
|
40
|
+
const status = { service_status: 'maintenance_upcoming' as const, maintenance };
|
|
41
|
+
expect(serviceStatusSignature({
|
|
42
|
+
...status,
|
|
43
|
+
maintenance: { ...maintenance, description: '说明一' },
|
|
44
|
+
})).not.toBe(serviceStatusSignature({
|
|
45
|
+
...status,
|
|
46
|
+
maintenance: { ...maintenance, description: '说明二' },
|
|
47
|
+
}));
|
|
48
|
+
});
|
|
49
|
+
|
|
25
50
|
it('extracts active maintenance and Retry-After from an ApiError', () => {
|
|
26
51
|
const payload = {
|
|
27
52
|
success: false,
|
|
@@ -5,6 +5,7 @@ export type ServiceStatus = 'available' | 'maintenance_upcoming' | 'maintenance_
|
|
|
5
5
|
export interface MaintenanceWindow {
|
|
6
6
|
starts_at: string;
|
|
7
7
|
ends_at: string;
|
|
8
|
+
description?: string;
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
export interface ServerServiceStatus {
|
|
@@ -32,7 +33,16 @@ function maintenanceWindow(value: unknown): MaintenanceWindow | undefined {
|
|
|
32
33
|
if (!root) return undefined;
|
|
33
34
|
const startsAt = typeof root.starts_at === 'string' ? root.starts_at : undefined;
|
|
34
35
|
const endsAt = typeof root.ends_at === 'string' ? root.ends_at : undefined;
|
|
35
|
-
|
|
36
|
+
const description = typeof root.description === 'string' && root.description.length > 0
|
|
37
|
+
? root.description
|
|
38
|
+
: undefined;
|
|
39
|
+
return startsAt && endsAt
|
|
40
|
+
? {
|
|
41
|
+
starts_at: startsAt,
|
|
42
|
+
ends_at: endsAt,
|
|
43
|
+
...(description ? { description } : {}),
|
|
44
|
+
}
|
|
45
|
+
: undefined;
|
|
36
46
|
}
|
|
37
47
|
|
|
38
48
|
function retryAfterSeconds(value: unknown): number | undefined {
|
|
@@ -107,5 +117,6 @@ export function serviceStatusSignature(status: ServerServiceStatus): string {
|
|
|
107
117
|
status.service_status,
|
|
108
118
|
status.maintenance?.starts_at ?? null,
|
|
109
119
|
status.maintenance?.ends_at ?? null,
|
|
120
|
+
status.maintenance?.description ?? null,
|
|
110
121
|
]);
|
|
111
122
|
}
|
|
@@ -3,6 +3,7 @@ import type { CanonicalEvent } from '../runtime/framework/events/index.js';
|
|
|
3
3
|
import {
|
|
4
4
|
presentCanonicalEvent,
|
|
5
5
|
presentCanonicalEventForCclEvents,
|
|
6
|
+
presentCanonicalEventForDesktop,
|
|
6
7
|
} from './canonical-event-presentation.js';
|
|
7
8
|
|
|
8
9
|
function canonical(
|
|
@@ -193,4 +194,62 @@ describe('canonical Agent Event presentation', () => {
|
|
|
193
194
|
expect(nonVisual).not.toHaveProperty('occurred_at');
|
|
194
195
|
expect(nonVisual).not.toHaveProperty('received_at');
|
|
195
196
|
});
|
|
197
|
+
|
|
198
|
+
it('withholds spectate links only from the Desktop Agent projection', () => {
|
|
199
|
+
const source = canonical('joined', {
|
|
200
|
+
status: 'matched',
|
|
201
|
+
recovered: true,
|
|
202
|
+
url: 'https://example.test/lobby?token=top-secret',
|
|
203
|
+
spectate_url: 'https://example.test/lobby?token=spread-secret',
|
|
204
|
+
queue: {
|
|
205
|
+
status: 'matched',
|
|
206
|
+
spectate_url: 'https://example.test/lobby?token=nested-secret',
|
|
207
|
+
data: {
|
|
208
|
+
url: 'https://example.test/lobby?token=deep-secret',
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
}, { producer: 'local_synth' });
|
|
212
|
+
|
|
213
|
+
const external = presentCanonicalEventForCclEvents(source, null);
|
|
214
|
+
const desktop = presentCanonicalEventForDesktop(source, null);
|
|
215
|
+
|
|
216
|
+
expect(external).toMatchObject({
|
|
217
|
+
type: 'joined',
|
|
218
|
+
url: 'https://example.test/lobby?token=top-secret',
|
|
219
|
+
hint: expect.stringContaining("Share this Event's url"),
|
|
220
|
+
});
|
|
221
|
+
expect(JSON.stringify(desktop)).not.toContain('example.test');
|
|
222
|
+
expect(desktop).toMatchObject({
|
|
223
|
+
type: 'joined',
|
|
224
|
+
status: 'matched',
|
|
225
|
+
queue: { status: 'matched' },
|
|
226
|
+
hint: 'The game runtime reattached; do not start a duplicate runtime.',
|
|
227
|
+
});
|
|
228
|
+
expect(JSON.stringify((desktop as Record<string, unknown>).hint))
|
|
229
|
+
.not.toMatch(/url|link|user/iu);
|
|
230
|
+
expect(source.payload.url).toBe('https://example.test/lobby?token=top-secret');
|
|
231
|
+
|
|
232
|
+
const roomSource = canonical('room_joined', {
|
|
233
|
+
status: 'room_waiting',
|
|
234
|
+
room_code: '123456',
|
|
235
|
+
resumed: true,
|
|
236
|
+
spectate_url: 'https://example.test/room?token=room-secret',
|
|
237
|
+
}, { producer: 'local_synth' });
|
|
238
|
+
const externalRoom = presentCanonicalEventForCclEvents(roomSource, null);
|
|
239
|
+
const desktopRoom = presentCanonicalEventForDesktop(roomSource, null);
|
|
240
|
+
|
|
241
|
+
expect(externalRoom).toMatchObject({
|
|
242
|
+
spectate_url: 'https://example.test/room?token=room-secret',
|
|
243
|
+
hint: expect.stringContaining("Share this Event's spectate_url"),
|
|
244
|
+
});
|
|
245
|
+
expect(desktopRoom).toMatchObject({
|
|
246
|
+
status: 'room_waiting',
|
|
247
|
+
room_code: '123456',
|
|
248
|
+
resumed: true,
|
|
249
|
+
type: 'room_joined',
|
|
250
|
+
hint: 'The room runtime reattached; keep it attached.',
|
|
251
|
+
});
|
|
252
|
+
expect(JSON.stringify(desktopRoom)).not.toContain('example.test');
|
|
253
|
+
expect(JSON.stringify(desktopRoom)).not.toMatch(/url|link|user/iu);
|
|
254
|
+
});
|
|
196
255
|
});
|
|
@@ -3,6 +3,19 @@ import { buildLocalGameStartedEnrichment } from '../lib/game-context.js';
|
|
|
3
3
|
import { compactEventForEvents } from './event-format.js';
|
|
4
4
|
import { formatCanonicalEventHint } from './event-hints.js';
|
|
5
5
|
|
|
6
|
+
const DESKTOP_SPECTATE_EVENT_TYPES = new Set([
|
|
7
|
+
'joined',
|
|
8
|
+
'room_created',
|
|
9
|
+
'room_joined',
|
|
10
|
+
'session_resumed',
|
|
11
|
+
]);
|
|
12
|
+
|
|
13
|
+
const DESKTOP_SPECTATE_FIELD_NAMES = new Set([
|
|
14
|
+
'url',
|
|
15
|
+
'spectate_url',
|
|
16
|
+
'spectateUrl',
|
|
17
|
+
]);
|
|
18
|
+
|
|
6
19
|
function cleanObject<T extends Record<string, any>>(value: T): T {
|
|
7
20
|
for (const key of Object.keys(value)) {
|
|
8
21
|
if (value[key] === undefined) delete value[key];
|
|
@@ -10,6 +23,31 @@ function cleanObject<T extends Record<string, any>>(value: T): T {
|
|
|
10
23
|
return value;
|
|
11
24
|
}
|
|
12
25
|
|
|
26
|
+
function stripDesktopSpectateFields(value: unknown): unknown {
|
|
27
|
+
if (Array.isArray(value)) return value.map((item) => stripDesktopSpectateFields(item));
|
|
28
|
+
if (!value || typeof value !== 'object') return value;
|
|
29
|
+
return Object.fromEntries(Object.entries(value)
|
|
30
|
+
.filter(([key]) => !DESKTOP_SPECTATE_FIELD_NAMES.has(key))
|
|
31
|
+
.map(([key, item]) => [key, stripDesktopSpectateFields(item)]));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function desktopLifecycleHint(event: Record<string, any>): string | undefined {
|
|
35
|
+
switch (event.type) {
|
|
36
|
+
case 'joined':
|
|
37
|
+
return event.recovered === true || event.resumed === true
|
|
38
|
+
? 'The game runtime reattached; do not start a duplicate runtime.'
|
|
39
|
+
: 'The game runtime is attached; do not start a duplicate runtime.';
|
|
40
|
+
case 'room_created':
|
|
41
|
+
return 'Keep the room runtime attached.';
|
|
42
|
+
case 'room_joined':
|
|
43
|
+
return event.recovered === true || event.resumed === true
|
|
44
|
+
? 'The room runtime reattached; keep it attached.'
|
|
45
|
+
: 'Keep the room runtime attached.';
|
|
46
|
+
default:
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
13
51
|
/** CCL-owned enrichment for Agent-visible Event details. */
|
|
14
52
|
export function enrichCanonicalEventForAgent(
|
|
15
53
|
event: Record<string, any>,
|
|
@@ -69,3 +107,19 @@ export function presentCanonicalEventForCclEvents(
|
|
|
69
107
|
}
|
|
70
108
|
return presentCanonicalEvent(event, summary);
|
|
71
109
|
}
|
|
110
|
+
|
|
111
|
+
/** Desktop projection keeps lifecycle guidance but withholds spectate links from its Agent. */
|
|
112
|
+
export function presentCanonicalEventForDesktop(
|
|
113
|
+
event: CanonicalEvent,
|
|
114
|
+
summary: any | null | undefined,
|
|
115
|
+
): Record<string, any> | string {
|
|
116
|
+
const presented = presentCanonicalEventForCclEvents(event, summary);
|
|
117
|
+
if (
|
|
118
|
+
typeof presented === 'string'
|
|
119
|
+
|| !DESKTOP_SPECTATE_EVENT_TYPES.has(event.type)
|
|
120
|
+
) return presented;
|
|
121
|
+
return cleanObject({
|
|
122
|
+
...stripDesktopSpectateFields(presented) as Record<string, any>,
|
|
123
|
+
hint: desktopLifecycleHint(presented),
|
|
124
|
+
});
|
|
125
|
+
}
|
|
@@ -7,10 +7,14 @@ describe('event-format', () => {
|
|
|
7
7
|
const maintenance = {
|
|
8
8
|
starts_at: '2026-08-05T01:00:00+00:00',
|
|
9
9
|
ends_at: '2026-08-05T03:00:00+00:00',
|
|
10
|
+
description: '本次维护将升级匹配服务。',
|
|
10
11
|
};
|
|
11
12
|
expect(formatEventMessage({
|
|
12
13
|
type: 'service_status', service_status: 'maintenance_upcoming', maintenance,
|
|
13
14
|
})).toContain('当前请求仍可继续');
|
|
15
|
+
expect(formatEventMessage({
|
|
16
|
+
type: 'service_status', service_status: 'maintenance_upcoming', maintenance,
|
|
17
|
+
})).toContain(maintenance.description);
|
|
14
18
|
expect(formatEventMessage({
|
|
15
19
|
type: 'service_status', service_status: 'maintenance_active', maintenance,
|
|
16
20
|
})).toContain('新的匹配和房间操作已停止');
|
|
@@ -343,11 +343,13 @@ function shortBody(event: Record<string, any>, ctx: EventFormatContext): string
|
|
|
343
343
|
case 'service_status': {
|
|
344
344
|
const startsAt = firstString(event.maintenance ?? {}, ['starts_at'], '计划时间未知');
|
|
345
345
|
const endsAt = firstString(event.maintenance ?? {}, ['ends_at'], '恢复时间未知');
|
|
346
|
+
const description = stringValue(event.maintenance?.description);
|
|
347
|
+
const descriptionText = description ? `;维护说明:${description}` : '';
|
|
346
348
|
if (event.service_status === 'maintenance_upcoming') {
|
|
347
|
-
return `服务器计划于${startsAt}开始维护,预计${endsAt}
|
|
349
|
+
return `服务器计划于${startsAt}开始维护,预计${endsAt}恢复${descriptionText};当前请求仍可继续。`;
|
|
348
350
|
}
|
|
349
351
|
if (event.service_status === 'maintenance_active') {
|
|
350
|
-
return `服务器正在维护,预计${endsAt}
|
|
352
|
+
return `服务器正在维护,预计${endsAt}恢复${descriptionText};新的匹配和房间操作已停止。`;
|
|
351
353
|
}
|
|
352
354
|
return '服务器维护已结束,服务恢复可用。';
|
|
353
355
|
}
|
|
@@ -40,11 +40,16 @@ describe('Mailbox-owned Event hint registries', () => {
|
|
|
40
40
|
const maintenance = {
|
|
41
41
|
starts_at: '2026-08-05T01:00:00+00:00',
|
|
42
42
|
ends_at: '2026-08-05T03:00:00+00:00',
|
|
43
|
+
description: '本次维护将升级匹配服务。',
|
|
43
44
|
};
|
|
44
45
|
expect(formatCanonicalEventHint(
|
|
45
46
|
{ producer: 'backend_push' },
|
|
46
47
|
{ type: 'service_status', service_status: 'maintenance_upcoming', maintenance },
|
|
47
48
|
)).toContain('current request succeeded');
|
|
49
|
+
expect(formatCanonicalEventHint(
|
|
50
|
+
{ producer: 'backend_push' },
|
|
51
|
+
{ type: 'service_status', service_status: 'maintenance_upcoming', maintenance },
|
|
52
|
+
)).toContain(maintenance.description);
|
|
48
53
|
expect(formatCanonicalEventHint(
|
|
49
54
|
{ producer: 'backend_push' },
|
|
50
55
|
{ type: 'service_status', service_status: 'maintenance_active', maintenance },
|
|
@@ -113,11 +113,15 @@ export const BACKEND_EVENT_HINT_FORMATTERS: Readonly<Record<string, EventHintFor
|
|
|
113
113
|
service_status: (event) => {
|
|
114
114
|
const startsAt = text(event.maintenance?.starts_at, 'the scheduled start time');
|
|
115
115
|
const endsAt = text(event.maintenance?.ends_at, 'the scheduled end time');
|
|
116
|
+
const description = typeof event.maintenance?.description === 'string'
|
|
117
|
+
&& event.maintenance.description.length > 0
|
|
118
|
+
? ` Maintenance description: ${event.maintenance.description}`
|
|
119
|
+
: '';
|
|
116
120
|
if (event.service_status === 'maintenance_upcoming') {
|
|
117
|
-
return `Tell the user that maintenance is scheduled from ${startsAt} to ${endsAt}
|
|
121
|
+
return `Tell the user that maintenance is scheduled from ${startsAt} to ${endsAt}.${description} The current request succeeded and may continue; do not start an extra runtime.`;
|
|
118
122
|
}
|
|
119
123
|
if (event.service_status === 'maintenance_active') {
|
|
120
|
-
return `Tell the user that the service is under maintenance until ${endsAt}
|
|
124
|
+
return `Tell the user that the service is under maintenance until ${endsAt}.${description} Do not retry matchmaking, room creation, room joining, or room start before then; query server status before trying again.`;
|
|
121
125
|
}
|
|
122
126
|
return 'The service is available again. Tell the user if they were waiting, but do not replay a previously blocked request unless they still want it.';
|
|
123
127
|
},
|
|
@@ -44,7 +44,10 @@ import {
|
|
|
44
44
|
type ParentProcessWatchHandle,
|
|
45
45
|
} from '../parent-process-watch.js';
|
|
46
46
|
import { BufferedRawWsLog, ownerRawWsLogPath } from '../raw-ws-log.js';
|
|
47
|
-
import {
|
|
47
|
+
import {
|
|
48
|
+
presentCanonicalEventForCclEvents,
|
|
49
|
+
presentCanonicalEventForDesktop,
|
|
50
|
+
} from '../../pipeline/canonical-event-presentation.js';
|
|
48
51
|
import { compactStateForEvents } from '../../pipeline/event-format.js';
|
|
49
52
|
import { createClawclawRuntime } from './runtime.js';
|
|
50
53
|
import { assembleClawclawPlugins } from './plugins/assembly.js';
|
|
@@ -550,7 +553,9 @@ export async function runClawclawOwner(
|
|
|
550
553
|
agentMailbox = new AgentMailboxCoordinator({
|
|
551
554
|
repository: mailboxRepository,
|
|
552
555
|
readyView: () => runtime!.readReadyView(0, 1),
|
|
553
|
-
presentEvent:
|
|
556
|
+
presentEvent: options.desktopEvents
|
|
557
|
+
? presentCanonicalEventForDesktop
|
|
558
|
+
: presentCanonicalEventForCclEvents,
|
|
554
559
|
compactState: compactStateForEvents,
|
|
555
560
|
diagnostic: (name, attributes) => runtime?.diagnostic(name, attributes),
|
|
556
561
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
2
|
import { createServer, type Server, type Socket } from 'node:net';
|
|
3
3
|
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
4
|
-
import {
|
|
4
|
+
import { presentCanonicalEventForDesktop } from '../../../../pipeline/canonical-event-presentation.js';
|
|
5
5
|
import { compactStateForEvents } from '../../../../pipeline/event-format.js';
|
|
6
6
|
import { createClawclawEventCatalog } from '../../../clawclaw-event-catalog.js';
|
|
7
7
|
import {
|
|
@@ -128,7 +128,7 @@ function sendAck(
|
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
describe('Desktop Agent event push integration', () => {
|
|
131
|
-
it('pushes
|
|
131
|
+
it('pushes sanitized ready visible Events and retries one durable batch until exact ACK', async () => {
|
|
132
132
|
const pipeName = `ccl-desktop-integration-${randomUUID()}`;
|
|
133
133
|
const socketPath = process.platform === 'win32'
|
|
134
134
|
? `\\\\.\\pipe\\${pipeName}`
|
|
@@ -185,7 +185,7 @@ describe('Desktop Agent event push integration', () => {
|
|
|
185
185
|
const coordinator = new AgentMailboxCoordinator({
|
|
186
186
|
repository,
|
|
187
187
|
readyView: () => structuredClone(ready),
|
|
188
|
-
presentEvent:
|
|
188
|
+
presentEvent: presentCanonicalEventForDesktop,
|
|
189
189
|
compactState: compactStateForEvents,
|
|
190
190
|
});
|
|
191
191
|
let pump: MailboxEventBatchPump | undefined;
|
|
@@ -258,6 +258,20 @@ describe('Desktop Agent event push integration', () => {
|
|
|
258
258
|
await delay(AGENT_MAILBOX_COALESCE_MS + 60);
|
|
259
259
|
expect(received.filter(({ frame }) => frame.type === 'mailbox_batch')).toHaveLength(0);
|
|
260
260
|
|
|
261
|
+
const joined = await publish(ingress, {
|
|
262
|
+
eventId: 'joined-1',
|
|
263
|
+
type: 'joined',
|
|
264
|
+
epochSeq: 2,
|
|
265
|
+
producer: 'local_synth',
|
|
266
|
+
payload: {
|
|
267
|
+
status: 'matched',
|
|
268
|
+
url: 'https://example.test/lobby?token=desktop-secret',
|
|
269
|
+
queue: {
|
|
270
|
+
status: 'matched',
|
|
271
|
+
spectate_url: 'https://example.test/lobby?token=nested-desktop-secret',
|
|
272
|
+
},
|
|
273
|
+
},
|
|
274
|
+
});
|
|
261
275
|
const longText = `BEGIN-${'x'.repeat(70 * 1024)}-END`;
|
|
262
276
|
const speech = await publish(ingress, {
|
|
263
277
|
eventId: 'speech-1',
|
|
@@ -268,7 +282,7 @@ describe('Desktop Agent event push integration', () => {
|
|
|
268
282
|
expect(speech.deliveryClass).toBe('monitor_and_events');
|
|
269
283
|
ready = readyView(2, speech.commitSeq);
|
|
270
284
|
const firstObservedAt = Date.now();
|
|
271
|
-
await mailbox.update({ pendingEvents: [speech] } as any);
|
|
285
|
+
await mailbox.update({ pendingEvents: [joined, speech] } as any);
|
|
272
286
|
await delay(100);
|
|
273
287
|
|
|
274
288
|
const visual = await publish(ingress, {
|
|
@@ -307,7 +321,15 @@ describe('Desktop Agent event push integration', () => {
|
|
|
307
321
|
expect(firstBatch.frame.payload.events).toEqual([
|
|
308
322
|
'visual.player_moved | player-2 moved through engine',
|
|
309
323
|
expect.objectContaining({ type: 'speech', text: longText }),
|
|
324
|
+
expect.objectContaining({
|
|
325
|
+
type: 'joined',
|
|
326
|
+
status: 'matched',
|
|
327
|
+
hint: 'The game runtime is attached; do not start a duplicate runtime.',
|
|
328
|
+
}),
|
|
310
329
|
]);
|
|
330
|
+
expect(JSON.stringify(firstBatch.frame.payload)).not.toContain('desktop-secret');
|
|
331
|
+
expect(JSON.stringify(firstBatch.frame.payload)).not.toMatch(/spectate_url/iu);
|
|
332
|
+
expect(JSON.stringify(firstBatch.frame.payload)).not.toMatch(/Share this Event/iu);
|
|
311
333
|
expect(Buffer.byteLength(JSON.stringify(firstBatch.frame.payload), 'utf8'))
|
|
312
334
|
.toBeGreaterThan(64 * 1024);
|
|
313
335
|
expect(JSON.stringify(firstBatch.frame.payload)).not.toContain('task_assigned');
|
|
@@ -307,6 +307,7 @@ function gameStateFrame(
|
|
|
307
307
|
const maintenanceWindow = {
|
|
308
308
|
starts_at: '2026-08-05T01:00:00+00:00',
|
|
309
309
|
ends_at: '2026-08-05T03:00:00+00:00',
|
|
310
|
+
description: '本次维护将升级匹配服务。',
|
|
310
311
|
};
|
|
311
312
|
|
|
312
313
|
function maintenanceApiError(method = 'GET', path = '/api/v1/queue/status'): ApiError {
|