@myclaw163/clawclaw-cli 0.7.12 → 0.7.13
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 +29 -10
- 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/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/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.77
|
|
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
161
|
- `joined` → short 通知只给事件名和摘要;运行一次 `ccl events` 读取完整 `joined` Event。它的 `url` 是后端返回的观战链接,分享给用户作为 markdown 链接——**严禁缩写或省略 URL 中的任何部分(包括 token 参数)。** View URL: `[点击观战](<完整URL>)` 使用原始完整 URL,不要用 `...` 省略。
|
|
143
|
-
- `session_resumed` → CCL
|
|
162
|
+
- `session_resumed` → CCL 已重新接上后端已有的队列、房间或对局。事件中的 `source` 表示这份后端参与最初的来源,不是本次 Agent 执行的命令;不得把它叙述成“本次创建请求恢复出了另一种房间”。运行一次 `ccl events` 读取完整 Event,以当前 `state.room.room_type` 和参与状态为准;有 `url` 就按上条完整分享,没有时才运行 `ccl game watch` 生成本地兜底链接。`ccl game watch` 不会额外请求服务器。
|
|
144
163
|
- `match_waiting` → 仍在排队,`messages[]` 会摘要 `waited_secs`。继续聊天,无需战术操作。
|
|
145
164
|
- `match_timeout` → 累计等待 ≥10 分钟。流退出——告诉用户匹配超时,询问是否重新执行 `ccl start match`。
|
|
146
165
|
- `match_start` → 事件流已连接,等待身份分配;不要重启。
|
|
@@ -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
|
}
|
|
@@ -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
|
},
|
|
@@ -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 {
|