@myclaw163/clawclaw-cli 0.7.8 → 0.7.10
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 +14 -2
- package/docs//350/207/252/345/256/232/344/271/211/346/204/237/347/237/245.md +15 -1
- package/package.json +1 -1
- package/skills/clawclaw/SKILL.md +5 -5
- package/skills/clawclaw/references/COMMANDS.md +4 -4
- package/skills/clawclaw/references/GAME-MECHANICS.md +1 -1
- package/src/commands/communication.test.ts +14 -3
- package/src/commands/communication.ts +12 -4
- package/src/pipeline/event-format.test.ts +0 -21
- package/src/pipeline/event-format.ts +0 -33
- package/src/pipeline/event-hints.test.ts +2 -5
- package/src/pipeline/event-hints.ts +0 -17
- package/src/pipeline/game-sync-event-normalization.test.ts +34 -12
- package/src/pipeline/game-sync-event-normalization.ts +52 -22
- package/src/runtime/clawclaw/owner.ts +8 -0
- package/src/runtime/clawclaw/plugins/assembly.test.ts +13 -0
- package/src/runtime/clawclaw/plugins/assembly.ts +10 -0
- package/src/runtime/clawclaw/plugins/mailbox/desktop-event-push.integration.test.ts +17 -5
- package/src/runtime/clawclaw/plugins/mailbox/desktop-event-socket.test.ts +37 -3
- package/src/runtime/clawclaw/plugins/mailbox/desktop-event-socket.ts +49 -14
- package/src/runtime/clawclaw/plugins/perception/contracts.ts +1 -0
- package/src/runtime/clawclaw/plugins/perception/modules/co-movement-module.ts +16 -0
- package/src/runtime/clawclaw/plugins/perception/modules/follow-module.ts +16 -0
- package/src/runtime/clawclaw/plugins/perception/modules/motion-module.ts +16 -0
- package/src/runtime/clawclaw/plugins/perception/modules/route-module.ts +23 -0
- package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.ts +16 -0
- package/src/runtime/clawclaw/plugins/perception/modules/stop-module.ts +16 -0
- package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.ts +23 -0
- package/src/runtime/clawclaw/plugins/perception/perception-plugin.test.ts +19 -0
- package/src/runtime/clawclaw/plugins/perception/perception-plugin.ts +41 -0
- package/src/runtime/clawclaw/plugins/perception/perception-source.test.ts +49 -0
- package/src/runtime/clawclaw/plugins/perception/perception-source.ts +105 -5
- package/src/runtime/clawclaw/plugins/source/source-plugin.test.ts +174 -0
- package/src/runtime/clawclaw/plugins/source/source-plugin.ts +146 -66
- package/src/runtime/clawclaw/plugins/strategy/strategy-action.ts +11 -4
- package/src/runtime/clawclaw-event-catalog.ts +0 -2
- package/src/runtime/framework/plugins/runtime-plugin-scheduler.test.ts +36 -0
- package/src/runtime/framework/plugins/runtime-plugin-scheduler.ts +0 -5
- package/src/sdk/action.ts +9 -8
- package/src/sdk/perception-plugin/index.ts +8 -0
- package/src/sdk/strategy-plugin/index.test.ts +3 -3
- package/src/sdk/strategy-plugin/index.ts +25 -24
- package/src/strategies/custom-module.test.ts +1 -1
- package/src/strategies/game-utils.test.ts +8 -8
- package/src/strategies/game-utils.ts +39 -28
- package/src/strategies/goals/crab-octopus-reflexes.ts +11 -7
- package/src/strategies/goals/hide-top.ts +2 -1
- package/src/strategies/goals/kill-target-goal.ts +2 -1
- package/src/strategies/goals/kill-target-top.ts +3 -3
- package/src/strategies/goals/lone-kill-core.ts +3 -1
- package/src/strategies/goals/task-kill-report-top.ts +2 -1
- package/src/strategies/goals/warrior-shrimp-top.ts +2 -1
|
@@ -113,16 +113,28 @@ CCL 在以下条件全部满足时发送一个 `mailbox_batch`:
|
|
|
113
113
|
}
|
|
114
114
|
]
|
|
115
115
|
},
|
|
116
|
+
"event_descriptors": [
|
|
117
|
+
{
|
|
118
|
+
"type": "visual.player_moved",
|
|
119
|
+
"perception_id": "visual.motion",
|
|
120
|
+
"name": "玩家移动",
|
|
121
|
+
"description": "玩家持续移动形成一段可观察的移动轨迹。"
|
|
122
|
+
}
|
|
123
|
+
],
|
|
116
124
|
"payload": {
|
|
117
125
|
"schema": "clawclaw.channel-events.v1",
|
|
118
126
|
"state": {},
|
|
119
|
-
"events": [
|
|
127
|
+
"events": [
|
|
128
|
+
"visual.player_moved | 9:41,你从导航仓左上侧移动到2号走廊右下侧。"
|
|
129
|
+
]
|
|
120
130
|
}
|
|
121
131
|
}
|
|
122
132
|
```
|
|
123
133
|
|
|
124
134
|
`payload.state` 是当前 Ready View 的紧凑状态,`payload.events` 是本批完整 Agent 事件。`active_resources` 是这一交付批次创建时的资源快照,Desktop 可据此更新策略和感知窗口;它不属于 `payload` 内的 Agent Mailbox 内容。
|
|
125
135
|
|
|
136
|
+
`event_descriptors` 只包含本批 `payload.events` 实际出现、并且由当前激活感知模块声明的 Event type。同一 type 在一批出现多次只附一份描述;非感知事件、禁用模块的 Event type、未激活自定义模块的 Event type,以及没有出现在本批的 Event type 都不列入。名称和描述来自对应感知模块 manifest,当前按 `zh-CN` 解析。没有匹配项时省略整个字段,原有 `payload.events` 结构始终保持不变。
|
|
137
|
+
|
|
126
138
|
## 什么时候不发送
|
|
127
139
|
|
|
128
140
|
- Desktop 参数未配置或 IPC 尚未连接。
|
|
@@ -151,4 +163,4 @@ Desktop 将批次可靠放入自己的输入队列后返回:
|
|
|
151
163
|
|
|
152
164
|
`connection_id`、`seq` 和 `delivery_id` 必须与当前批次完全一致,否则 ACK 被忽略。CCL 只有收到正确 ACK 后才把事件标记为已交付。
|
|
153
165
|
|
|
154
|
-
ACK 超时或连接中断时,CCL 会重连并重发未确认批次;重试保持相同 `delivery_id`,并保留该交付首次创建时的 `active_resources` 快照。Desktop 应按 `delivery_id` 幂等入队,避免“已入队但 ACK 丢失”导致重复唤醒。
|
|
166
|
+
ACK 超时或连接中断时,CCL 会重连并重发未确认批次;重试保持相同 `delivery_id`,并保留该交付首次创建时的 `active_resources` 和 `event_descriptors` 快照。Desktop 应按 `delivery_id` 幂等入队,避免“已入队但 ACK 丢失”导致重复唤醒。
|
|
@@ -66,6 +66,18 @@ export default class EnterCounter extends ClawclawPerception {
|
|
|
66
66
|
description: 'Counts other players entering the field of view.',
|
|
67
67
|
subjectScope: 'others',
|
|
68
68
|
produces: ['visual.enter_count_changed'],
|
|
69
|
+
eventMetadata: {
|
|
70
|
+
'visual.enter_count_changed': {
|
|
71
|
+
name: 'Player enter count changed',
|
|
72
|
+
description: 'Reports a newly observed player entering view.',
|
|
73
|
+
localizations: {
|
|
74
|
+
'zh-CN': {
|
|
75
|
+
name: '玩家进入视野',
|
|
76
|
+
description: '发现一名此前不可见的玩家进入当前视野。',
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
},
|
|
69
81
|
};
|
|
70
82
|
|
|
71
83
|
seen = new Set();
|
|
@@ -96,9 +108,11 @@ export default class EnterCounter extends ClawclawPerception {
|
|
|
96
108
|
|
|
97
109
|
`static manifest` 必须使用可静态读取的字面量;CCL 在不执行用户代码的前提下读取它。类可以包含普通私有字段,用来保存轨迹、计数器、候选关系和“已经报告到哪里”等短期状态。
|
|
98
110
|
|
|
111
|
+
`eventMetadata` 为兼容已有自定义模块仍是可选字段;一旦提供,就必须完整覆盖 `produces`,不能声明额外 Event type。Desktop IPC 只会为当前激活模块、本批实际出现的 Event type 传递这里的本地化名称和描述。新模块建议始终提供该字段;文案属于模块,不应由 Mailbox 或 Desktop 建立中央映射。
|
|
112
|
+
|
|
99
113
|
| 类成员 | 是否必需 | 作用 |
|
|
100
114
|
|---|---:|---|
|
|
101
|
-
| `static manifest` | 是 | 声明模块 ID
|
|
115
|
+
| `static manifest` | 是 | 声明模块 ID、说明、事件主体范围、所有可能输出的 Event type,以及可选的 Event 显示元数据 |
|
|
102
116
|
| `update(frame, api)` | 是 | 消费一份新的视觉帧,更新私有状态,并可返回零到多条 Event |
|
|
103
117
|
| 普通实例字段 | 否 | 保存这个模块自己的跨帧状态;不同模块互不共享 |
|
|
104
118
|
| `flush(boundary, api)` | 否 | 在查询或硬边界处报告尚未自然结束的长片段 |
|
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.73
|
|
5
5
|
---
|
|
6
6
|
|
|
7
7
|
# 龙虾杀(ClawClaw)
|
|
@@ -21,7 +21,7 @@ version: 4.8.70
|
|
|
21
21
|
- **持久 Monitor 只启动一次。** 收到第一条非 error 的 CCL NDJSON 通知且 Monitor 任务仍在运行后,当前 Monitor 即为健康通知流;后续新事件会由同一个 Monitor 自动推送并唤醒 Agent。等待下一事件时只需保持它运行,不要再次调用 Monitor,也不要再次运行任何房间/匹配长流启动命令(包括 `--force`)。只有当前 Monitor 已明确结束或失败时,才进入下文的恢复流程。
|
|
22
22
|
- Claude Code 如果当前工具面板里没有 `Monitor`,先用 `ToolSearch` 查询 `select:Monitor`;不要把上述长流命令退回到 `Bash`。一旦你用 Bash 启动长流,当前回合会被阻塞,后续 `ccl events`、房间成员通知、会议发言和投票都会错过。
|
|
23
23
|
- 正常退出参与时使用 `ccl game quit`,不要用 `TaskStop` 代替后端退出。停止或结束承载 `ccl game start` 的宿主任务会同时停止这个前台 runtime、本地游戏连接和自动策略。如果该进程意外退出,之后重新运行同一命令会创建新的本地运行时会话,并重新查询后端;后端参与仍存在时,可能恢复原队列、对局或房间。若同一账号已有存活的 runtime,普通启动会拒绝并在错误中给出已有 PID;新 Monitor 不会附着或复用这个旧 runtime。此时可将同一启动命令加 `--force` 重试,它会替换旧进程。只能使用 CCL 的 `--force` 替换流程,不要直接 `kill` / `taskkill`:它会先请求旧 runtime 正常停止,必要时终止旧进程树,确认退出后再启动新 runtime。
|
|
24
|
-
- **游戏内发言只用 `ccl speak "<文本>"`。** 首次轮到发言、会议正式发言、投票阶段前 20 秒弹幕、路过发言都用这个独立命令;投票用 `ccl vote
|
|
24
|
+
- **游戏内发言只用 `ccl speak "<文本>"`。** 首次轮到发言、会议正式发言、投票阶段前 20 秒弹幕、路过发言都用这个独立命令;投票用 `ccl vote <座位号|skip>`,给用户/观战方说话用 `ccl aside "<文本>"`。三个命令各做一件事,不要组合。死亡后 `ccl speak` 是死亡弹幕,仅死亡玩家和观战方可见,存活玩家(活虾/活蟹)看不到。
|
|
25
25
|
|
|
26
26
|
> 敏感命令如 `ccl account register`、`ccl account rename`涉及账号操作,操作前与用户确认。OpenClaw typed tools 会在工具层提供确认门禁,shell 直跑会绕过这层保护。
|
|
27
27
|
|
|
@@ -200,7 +200,7 @@ ccl aside "<仅用户/观战玩家可见的推理>"
|
|
|
200
200
|
|
|
201
201
|
实时探索。保持移动,让用户了解方向,叙述紧张感,让用户输入塑造你的下一步决策。
|
|
202
202
|
|
|
203
|
-
**`ccl strategy <名称>` 是游走阶段的角色控制器。** 要中途切换行为,调用另一个 `ccl strategy <新名称>`(它会替换当前运行的策略)——只在目标确实变化时才切换策略。`ccl speak "<文本>"` 用于玩家发言,`ccl vote
|
|
203
|
+
**`ccl strategy <名称>` 是游走阶段的角色控制器。** 要中途切换行为,调用另一个 `ccl strategy <新名称>`(它会替换当前运行的策略)——只在目标确实变化时才切换策略。`ccl speak "<文本>"` 用于玩家发言,`ccl vote <座位号|skip>` 用于投票,`ccl aside "<文本>"` 用于仅用户/观战玩家可见的评论。
|
|
204
204
|
|
|
205
205
|
你仍然负责策略选择、叙述、观察流读取和会议决策。策略负责即时移动和任务操作。
|
|
206
206
|
|
|
@@ -244,7 +244,7 @@ ccl aside "<仅用户/观战玩家可见的推理>"
|
|
|
244
244
|
| `speech_skipped` | 某玩家超时跳过 | 记下谁被跳过 |
|
|
245
245
|
| `speech_your_turn` | **你的发言轮次——45 秒时限** | **立即**提交 `ccl speak`,禁止先查 `ccl events`;发言成功返回后再补查详情。自动化策略脚本不会帮你发言,必须你手动发言 |
|
|
246
246
|
| `vote_phase_start` | 投票弹幕窗口开始 | 发言轮次结束,进入投票阶段。第一步仍可通过 `ccl speak` 发投票弹幕,也可以用 `ccl vote` 投票 |
|
|
247
|
-
| `vote_speech_phase_ended` | 投票弹幕窗口结束 | 第二步只能投票。立即用 `ccl vote
|
|
247
|
+
| `vote_speech_phase_ended` | 投票弹幕窗口结束 | 第二步只能投票。立即用 `ccl vote <座位号\|skip>` 完成投票 |
|
|
248
248
|
| `exile` | 投票结果确定,有人进入放逐流程 | 读取被投出玩家和投票明细;是否已经死亡以当前 State 为准 |
|
|
249
249
|
| `no_exile` | 会议结束且无人放逐 | 继续保留嫌疑和路线判断 |
|
|
250
250
|
|
|
@@ -259,7 +259,7 @@ ccl aside "<仅用户/观战玩家可见的推理>"
|
|
|
259
259
|
```bash
|
|
260
260
|
ccl speak "<回合发言>" # 发言阶段:仅在你轮次时使用,最多 100 字;死亡后是仅死亡玩家/观战方可见的弹幕,存活玩家看不到
|
|
261
261
|
ccl speak "<投票施压>" # 投票阶段前 20 秒:先发一条弹幕
|
|
262
|
-
ccl vote
|
|
262
|
+
ccl vote 3 # 独立投给 3 号玩家;跳过用 ccl vote skip
|
|
263
263
|
ccl aside "<你的房间判断>" # 在会议中与用户分享你的怀疑/策略(游戏内无效果)
|
|
264
264
|
```
|
|
265
265
|
|
|
@@ -80,7 +80,6 @@ ccl data export --all [--output <新目录>]
|
|
|
80
80
|
ccl events # short 通知后固定查询边界,读取当前 State + 全部未读 Event
|
|
81
81
|
ccl events --backlog # 不建查询边界,读取当前已经 ready 的全部未读 Event
|
|
82
82
|
ccl events role_assigned # 补查身份、阵营、角色说明和你的任务;精确胜利条件看 GAME-MECHANICS.md
|
|
83
|
-
ccl events crab_teammates # 补查蟹方队友的开场通知;当前名单看裸 ccl events 的 state.you.crab_teammates
|
|
84
83
|
|
|
85
84
|
# 策略:身份揭示后自动运行该角色默认策略;只手动切换到 --list 中存在且未禁用的类策略
|
|
86
85
|
ccl strategy --list
|
|
@@ -94,7 +93,7 @@ ccl strategy --control '{"hostileTargets":["5"],"trustedTargets":["3"]}' # 原
|
|
|
94
93
|
# 三个独立沟通命令:
|
|
95
94
|
ccl speak "<玩家可见的发言>" # 游戏内发言,最多 100 字。存活时:附近/广播;死亡时:仅死亡玩家和观战方可见的弹幕,存活玩家看不到
|
|
96
95
|
ccl speak "<玩家可见的发言>" --file <音频> # 可选:上传本地音频并附到本次发言
|
|
97
|
-
ccl vote
|
|
96
|
+
ccl vote <座位号|skip> # 会议投票:数字=目标座位号(1-10),skip=弃票
|
|
98
97
|
ccl aside "<对用户说的话>" # 与用户/观战玩家对话,游戏内无效果
|
|
99
98
|
|
|
100
99
|
ccl game quit # 退出当前队列/对局/房间;房间对局第一次只退出本轮并回房
|
|
@@ -181,8 +180,9 @@ ccl events <事件名> # 补查当前 participation 该类型最新事件
|
|
|
181
180
|
```bash
|
|
182
181
|
ccl speak "<回合发言>" # 发言阶段:仅在你轮次时,最多 100 字;死亡后是仅死亡玩家/观战方可见的弹幕,存活玩家看不到
|
|
183
182
|
ccl speak "<投票施压>" # vote_phase_start 后、vote_speech_phase_ended 前:发投票弹幕
|
|
184
|
-
ccl vote
|
|
185
|
-
ccl vote skip
|
|
183
|
+
ccl vote 3 # 独立投给 3 号玩家;前 20 秒内也可直接投
|
|
184
|
+
ccl vote skip # 弃票,不投任何人
|
|
185
|
+
ccl vote 0 # 弃票(等价 skip)
|
|
186
186
|
ccl aside "<你对房间的判断>" # 会议中与用户分享怀疑/策略
|
|
187
187
|
```
|
|
188
188
|
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
## 信息不对称
|
|
83
83
|
|
|
84
84
|
- 虾方、天堂鱼、章鱼只知道自己的角色,不知道其他玩家的真实身份。
|
|
85
|
-
-
|
|
85
|
+
- 蟹方互相知道队友是蟹;当前名单以每次状态的 `state.you.crab_teammates` 为准(仅蟹玩家可见),但不知道中立角色是谁。
|
|
86
86
|
- 玩家被击杀或被投票驱逐后,真实身份不会向其他玩家公开;所有玩家身份在游戏结束时统一揭示。不要把“某人死亡/被投”当成身份确认,除非流事件或结算明确揭示。
|
|
87
87
|
|
|
88
88
|
## 常用术语
|
|
@@ -143,13 +143,24 @@ describe('communicationAction', () => {
|
|
|
143
143
|
});
|
|
144
144
|
});
|
|
145
145
|
|
|
146
|
-
it('builds
|
|
147
|
-
expect(communicationAction('vote', '
|
|
146
|
+
it('builds a vote action by seat number', () => {
|
|
147
|
+
expect(communicationAction('vote', '3').toJSON()).toMatchObject({
|
|
148
148
|
action: 'vote',
|
|
149
|
-
|
|
149
|
+
target_seat: 3,
|
|
150
150
|
});
|
|
151
151
|
});
|
|
152
152
|
|
|
153
|
+
it('builds a vote-skip action for skip', () => {
|
|
154
|
+
expect(communicationAction('vote', 'skip').toJSON()).toMatchObject({
|
|
155
|
+
action: 'vote',
|
|
156
|
+
target_seat: 0,
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('rejects a non-seat vote target', () => {
|
|
161
|
+
expect(() => communicationAction('vote', 'player3')).toThrow(/invalid_vote_target/);
|
|
162
|
+
});
|
|
163
|
+
|
|
153
164
|
it('builds an observer-only aside as the existing think action', () => {
|
|
154
165
|
expect(communicationAction('aside', 'keep this private').toJSON()).toEqual({
|
|
155
166
|
action: 'think',
|
|
@@ -49,8 +49,16 @@ export function communicationAction(kind: CommunicationActionKind, value: string
|
|
|
49
49
|
switch (kind) {
|
|
50
50
|
case 'speak':
|
|
51
51
|
return Action.speech(value);
|
|
52
|
-
case 'vote':
|
|
53
|
-
|
|
52
|
+
case 'vote': {
|
|
53
|
+
// `skip` → target_seat 0 (弃票);数字 → 座位号。
|
|
54
|
+
const trimmed = value.trim();
|
|
55
|
+
if (trimmed === 'skip') return Action.vote(0);
|
|
56
|
+
const seat = Number(trimmed);
|
|
57
|
+
if (!/^\d+$/.test(trimmed) || !Number.isInteger(seat)) {
|
|
58
|
+
throw new Error(`invalid_vote_target: "${value}" — use a seat number or skip`);
|
|
59
|
+
}
|
|
60
|
+
return Action.vote(seat);
|
|
61
|
+
}
|
|
54
62
|
case 'aside':
|
|
55
63
|
return Action.think().withThinking(value);
|
|
56
64
|
}
|
|
@@ -368,8 +376,8 @@ export function createSpeakCommand(dependencies: CommunicationCommandDependencie
|
|
|
368
376
|
|
|
369
377
|
export function createVoteCommand(dependencies: CommunicationCommandDependencies = {}): Command {
|
|
370
378
|
return new Command('vote')
|
|
371
|
-
.description('Vote for a player during a meeting')
|
|
372
|
-
.argument('<target>', '
|
|
379
|
+
.description('Vote for a player (by seat number) during a meeting, or skip')
|
|
380
|
+
.argument('<target>', 'Seat number (1-10) of the player to vote out, or skip')
|
|
373
381
|
.action(async (target: string) => {
|
|
374
382
|
await submitCommunicationAction({
|
|
375
383
|
command: 'ccl vote',
|
|
@@ -147,26 +147,6 @@ describe('event-format', () => {
|
|
|
147
147
|
});
|
|
148
148
|
});
|
|
149
149
|
|
|
150
|
-
it('fills crab teammate seats from the opening seat map', () => {
|
|
151
|
-
const ctx = {
|
|
152
|
-
summary: {
|
|
153
|
-
players: [{ name: '菜逼油条', seat: 8, known_status: { is_alive: true } }],
|
|
154
|
-
},
|
|
155
|
-
};
|
|
156
|
-
const event = {
|
|
157
|
-
type: 'crab_teammates',
|
|
158
|
-
tick: 20,
|
|
159
|
-
teammates: ['菜逼油条'],
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
expect(formatEventMessage(event, ctx)).toBe('t20 crab_teammates 蟹队友:8号菜逼油条。');
|
|
163
|
-
expect(compactEventFields(event, ctx)).toMatchObject({
|
|
164
|
-
type: 'crab_teammates',
|
|
165
|
-
tick: 20,
|
|
166
|
-
crab_teammates: [{ name: '菜逼油条', seat: 8 }],
|
|
167
|
-
});
|
|
168
|
-
});
|
|
169
|
-
|
|
170
150
|
it('formats death_speech with explicit speaker fields', () => {
|
|
171
151
|
const event = {
|
|
172
152
|
type: 'death_speech',
|
|
@@ -643,7 +623,6 @@ describe('event-format', () => {
|
|
|
643
623
|
it('keeps local hint formatters for backend-hinted monitor events', () => {
|
|
644
624
|
const backendHintedMonitorEvents = [
|
|
645
625
|
'corpse_spotted',
|
|
646
|
-
'crab_teammates',
|
|
647
626
|
'emergency_resolved',
|
|
648
627
|
'emergency_started',
|
|
649
628
|
'exile',
|
|
@@ -269,20 +269,6 @@ function formatVotes(votes: unknown, ctx: EventFormatContext): Record<string, st
|
|
|
269
269
|
return out;
|
|
270
270
|
}
|
|
271
271
|
|
|
272
|
-
function teammateNames(event: Record<string, any>): string[] {
|
|
273
|
-
const raw = Array.isArray(event.crab_teammates)
|
|
274
|
-
? event.crab_teammates
|
|
275
|
-
: Array.isArray(event.teammates)
|
|
276
|
-
? event.teammates
|
|
277
|
-
: [];
|
|
278
|
-
const names: string[] = [];
|
|
279
|
-
for (const teammate of raw) {
|
|
280
|
-
const name = typeof teammate === 'string' ? teammate : teammate?.name;
|
|
281
|
-
if (typeof name === 'string' && name.length > 0) names.push(name);
|
|
282
|
-
}
|
|
283
|
-
return names;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
272
|
function teammateObjects(event: Record<string, any>, ctx: EventFormatContext): Record<string, any>[] {
|
|
287
273
|
const raw = Array.isArray(event.crab_teammates)
|
|
288
274
|
? event.crab_teammates
|
|
@@ -471,10 +457,6 @@ function shortBody(event: Record<string, any>, ctx: EventFormatContext): string
|
|
|
471
457
|
const speakerSeat = firstNumber(event, ['speaker_seat', 'actor_seat', 'seat']);
|
|
472
458
|
return `${playerLabel(speakerName, speakerSeat, ctx)}死亡弹幕:${truncate(event.text ?? event.message, maxTextLength)}`;
|
|
473
459
|
}
|
|
474
|
-
case 'crab_teammates': {
|
|
475
|
-
const labels = teammateNames(event).map((name) => playerLabel(name, undefined, ctx));
|
|
476
|
-
return labels.length > 0 ? `蟹队友:${labels.join('、')}。` : '蟹队友信息已更新。';
|
|
477
|
-
}
|
|
478
460
|
case 'wandering_speech':
|
|
479
461
|
return `${text(event.actor_name, '你')}在${firstString(event, ['room'])}说:${truncate(event.text ?? event.message, maxTextLength)}`;
|
|
480
462
|
case 'game_over':
|
|
@@ -663,20 +645,6 @@ function compactVoteCastForEvents(event: Record<string, any>, ctx: EventFormatCo
|
|
|
663
645
|
});
|
|
664
646
|
}
|
|
665
647
|
|
|
666
|
-
function compactCrabTeammatesForEvents(event: Record<string, any>, ctx: EventFormatContext): FormattedEvent {
|
|
667
|
-
const {
|
|
668
|
-
teammates: _teammates,
|
|
669
|
-
crab_teammates: _crabTeammates,
|
|
670
|
-
...rest
|
|
671
|
-
} = event;
|
|
672
|
-
return cleanObject({
|
|
673
|
-
...rest,
|
|
674
|
-
type: text(rest.type, 'event'),
|
|
675
|
-
tick: numberValue(rest.tick) ?? null,
|
|
676
|
-
crab_teammates: teammateObjects(event, ctx),
|
|
677
|
-
});
|
|
678
|
-
}
|
|
679
|
-
|
|
680
648
|
function compactMeetingResultForEvents(event: Record<string, any>, ctx: EventFormatContext): FormattedEvent {
|
|
681
649
|
const {
|
|
682
650
|
votes: _votes,
|
|
@@ -756,7 +724,6 @@ export function compactEventForEvents(
|
|
|
756
724
|
}
|
|
757
725
|
|
|
758
726
|
if (event.type === 'vote_cast') return compactVoteCastForEvents(event, ctx);
|
|
759
|
-
if (event.type === 'crab_teammates') return compactCrabTeammatesForEvents(event, ctx);
|
|
760
727
|
if (event.type === 'exile' || event.type === 'no_exile') return compactMeetingResultForEvents(event, ctx);
|
|
761
728
|
if (event.type === 'players_changed') return compactPlayersChangedForEvents(event);
|
|
762
729
|
|
|
@@ -16,7 +16,7 @@ describe('Mailbox-owned Event hint registries', () => {
|
|
|
16
16
|
BACKEND_EVENT_HINT_FORMATTERS[type] === undefined
|
|
17
17
|
));
|
|
18
18
|
|
|
19
|
-
expect(Object.keys(BACKEND_EVENT_HINT_FORMATTERS)).toHaveLength(
|
|
19
|
+
expect(Object.keys(BACKEND_EVENT_HINT_FORMATTERS)).toHaveLength(30);
|
|
20
20
|
expect(unregistered).toEqual([
|
|
21
21
|
'task_completed',
|
|
22
22
|
'task_sabotaged',
|
|
@@ -175,9 +175,6 @@ describe('Mailbox-owned Event hint registries', () => {
|
|
|
175
175
|
|
|
176
176
|
it('preserves the useful incremental semantics from npm batch next_step routes', () => {
|
|
177
177
|
expect(BACKEND_EVENT_HINT_FORMATTERS.game_started({}, {})).toContain('do not relaunch');
|
|
178
|
-
expect(BACKEND_EVENT_HINT_FORMATTERS.crab_teammates({
|
|
179
|
-
crab_teammates: [{ name: 'Bob', seat: 2 }],
|
|
180
|
-
}, {})).toContain('avoid voting for or killing them');
|
|
181
178
|
|
|
182
179
|
const normalGameOver = BACKEND_EVENT_HINT_FORMATTERS.game_over({
|
|
183
180
|
winner: 'lobster',
|
|
@@ -250,7 +247,7 @@ describe('Mailbox-owned Event hint registries', () => {
|
|
|
250
247
|
...Object.values(DERIVED_EVENT_HINT_FORMATTERS).map((formatter) => formatter(sample, {})),
|
|
251
248
|
].filter((hint): hint is string => typeof hint === 'string');
|
|
252
249
|
|
|
253
|
-
expect(hints).toHaveLength(
|
|
250
|
+
expect(hints).toHaveLength(50);
|
|
254
251
|
for (const hint of hints) expect(hint).not.toMatch(/[一-鿿]/);
|
|
255
252
|
});
|
|
256
253
|
});
|
|
@@ -182,23 +182,6 @@ export const BACKEND_EVENT_HINT_FORMATTERS: Readonly<Record<string, EventHintFor
|
|
|
182
182
|
+ 'If this is you, your influence is dead — tell your user and ask whether to spectate or leave.'
|
|
183
183
|
),
|
|
184
184
|
no_exile: () => 'Meeting ended — no one was exiled. The table failed to strike, and every hidden threat gets another turn.',
|
|
185
|
-
crab_teammates: (event) => {
|
|
186
|
-
const raw = Array.isArray(event.crab_teammates)
|
|
187
|
-
? event.crab_teammates
|
|
188
|
-
: Array.isArray(event.teammates)
|
|
189
|
-
? event.teammates
|
|
190
|
-
: [];
|
|
191
|
-
const labels = raw
|
|
192
|
-
.map((teammate: any) => (
|
|
193
|
-
typeof teammate === 'string'
|
|
194
|
-
? teammate
|
|
195
|
-
: optionalSeatPlayerLabel(teammate?.name, teammate?.seat)
|
|
196
|
-
))
|
|
197
|
-
.filter((label: string) => label.length > 0);
|
|
198
|
-
return labels.length > 0
|
|
199
|
-
? `Your Crab teammate(s): ${labels.join(', ')}. Keep this private, coordinate cover stories, and avoid voting for or killing them.`
|
|
200
|
-
: 'Your Crab teammate list is available. Keep it private and check the Event before voting or killing.';
|
|
201
|
-
},
|
|
202
185
|
meeting_briefing: (event) => meetingBriefingHint(event),
|
|
203
186
|
speech_skipped: (event) => `${actorName(event, 'Someone')} lost the floor — silence becomes evidence`,
|
|
204
187
|
speech_your_turn: () => 'Submit `ccl speak "<draft>"` immediately. Server skips you after 45s.',
|
|
@@ -4,6 +4,7 @@ import { presentCanonicalEvent } from './canonical-event-presentation.js';
|
|
|
4
4
|
import {
|
|
5
5
|
normalizeGameSyncEvent,
|
|
6
6
|
normalizeGameSyncEvents,
|
|
7
|
+
normalizeGameSyncEventsSafely,
|
|
7
8
|
} from './game-sync-event-normalization.js';
|
|
8
9
|
|
|
9
10
|
function canonical(event: Record<string, any>): CanonicalEvent {
|
|
@@ -80,6 +81,38 @@ describe('GameSync v2 Event normalization', () => {
|
|
|
80
81
|
expect(normalized[0]).not.toHaveProperty('newly_assigned_task');
|
|
81
82
|
});
|
|
82
83
|
|
|
84
|
+
it('isolates malformed Events while preserving original indexes and same-frame enrichment', () => {
|
|
85
|
+
const result = normalizeGameSyncEventsSafely([{
|
|
86
|
+
event_id: 'completed-1',
|
|
87
|
+
tick: 42,
|
|
88
|
+
type: 'task_completed',
|
|
89
|
+
actor: { seat: 1, name: 'self' },
|
|
90
|
+
task_name: '擦拭酒瓶',
|
|
91
|
+
}, {
|
|
92
|
+
event_id: 'malformed-killed',
|
|
93
|
+
tick: 42,
|
|
94
|
+
type: 'killed',
|
|
95
|
+
actor: { seat: 4, name: 'victim' },
|
|
96
|
+
killer: { kind: 'player', player: { seat: 2 } },
|
|
97
|
+
}, {
|
|
98
|
+
event_id: 'assigned-1',
|
|
99
|
+
tick: 42,
|
|
100
|
+
type: 'task_assigned',
|
|
101
|
+
actor: { seat: 1, name: 'self' },
|
|
102
|
+
task_name: '消毒淋浴器',
|
|
103
|
+
room: '制氧舱',
|
|
104
|
+
}]);
|
|
105
|
+
|
|
106
|
+
expect(result.rejected).toHaveLength(1);
|
|
107
|
+
expect(result.rejected[0]).toMatchObject({ index: 1 });
|
|
108
|
+
expect(result.rejected[0]?.error).toBeInstanceOf(TypeError);
|
|
109
|
+
expect(result.events.map(({ index }) => index)).toEqual([0, 2]);
|
|
110
|
+
expect(result.events[0]?.event).toMatchObject({
|
|
111
|
+
type: 'task_completed',
|
|
112
|
+
newly_assigned_task: { name: '消毒淋浴器', room: '制氧舱' },
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
83
116
|
it('projects actor and target PlayerRefs to the established canonical fields', () => {
|
|
84
117
|
const wire = {
|
|
85
118
|
event_id: '68a339d7-c5f6-4eef-8f40-b8779ca8bfcc',
|
|
@@ -212,7 +245,7 @@ describe('GameSync v2 Event normalization', () => {
|
|
|
212
245
|
reported_corpses: [{ seat: 9, name: 'dead' }],
|
|
213
246
|
speech_order: [{ seat: 1, name: 'caller' }, { seat: 2, name: 'next' }],
|
|
214
247
|
dead_players: [{ seat: 9, name: 'dead' }],
|
|
215
|
-
|
|
248
|
+
crab_teammates: [{ seat: 3, name: 'crab' }],
|
|
216
249
|
});
|
|
217
250
|
|
|
218
251
|
expect(normalized.reported_corpses).toEqual([{ name: 'dead', seat: 9 }]);
|
|
@@ -222,7 +255,6 @@ describe('GameSync v2 Event normalization', () => {
|
|
|
222
255
|
]);
|
|
223
256
|
expect(normalized.dead_players).toEqual([{ name: 'dead', seat: 9 }]);
|
|
224
257
|
expect(normalized.crab_teammates).toEqual([{ name: 'crab', seat: 3 }]);
|
|
225
|
-
expect(normalized).not.toHaveProperty('teammates');
|
|
226
258
|
|
|
227
259
|
const presented = presentCanonicalEvent(canonical(normalized), null);
|
|
228
260
|
expect(presented.speech_order).toEqual(normalized.speech_order);
|
|
@@ -259,16 +291,6 @@ describe('GameSync v2 Event normalization', () => {
|
|
|
259
291
|
actor_seat: 2,
|
|
260
292
|
current_speaker: 'caller',
|
|
261
293
|
});
|
|
262
|
-
|
|
263
|
-
expect(normalizeGameSyncEvent({
|
|
264
|
-
event_id: 'teammates-current-dev',
|
|
265
|
-
tick: 0,
|
|
266
|
-
type: 'crab_teammates',
|
|
267
|
-
actor: { seat: 1, name: 'self' },
|
|
268
|
-
teammates: ['crab-a', 'crab-b'],
|
|
269
|
-
})).toMatchObject({
|
|
270
|
-
crab_teammates: ['crab-a', 'crab-b'],
|
|
271
|
-
});
|
|
272
294
|
});
|
|
273
295
|
|
|
274
296
|
it('keeps the private self-repair marker and anonymizes every other emergency resolution', () => {
|
|
@@ -3,6 +3,21 @@ export interface CanonicalPlayerRef {
|
|
|
3
3
|
seat: number;
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
+
export interface NormalizedGameSyncEventEntry {
|
|
7
|
+
index: number;
|
|
8
|
+
event: Record<string, any>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface RejectedGameSyncEventEntry {
|
|
12
|
+
index: number;
|
|
13
|
+
error: unknown;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface GameSyncEventNormalizationResult {
|
|
17
|
+
events: NormalizedGameSyncEventEntry[];
|
|
18
|
+
rejected: RejectedGameSyncEventEntry[];
|
|
19
|
+
}
|
|
20
|
+
|
|
6
21
|
interface PlayerRefProjection {
|
|
7
22
|
wireField: string;
|
|
8
23
|
nameField: string;
|
|
@@ -231,19 +246,6 @@ export function normalizeGameSyncEvent(value: unknown): Record<string, any> {
|
|
|
231
246
|
throw new TypeError('GameSync Event.speech_order must be a string or PlayerRef array');
|
|
232
247
|
}
|
|
233
248
|
|
|
234
|
-
if (Object.hasOwn(normalized, 'teammates')) {
|
|
235
|
-
if (!Array.isArray(normalized.teammates)) {
|
|
236
|
-
throw new TypeError('GameSync Event.teammates must be an array');
|
|
237
|
-
}
|
|
238
|
-
// The current dev implementation emits the setup event as string[];
|
|
239
|
-
// meeting briefings already use PlayerRef[]. Keep one canonical field.
|
|
240
|
-
normalized.crab_teammates = normalized.teammates.map((item: unknown, index: number) => {
|
|
241
|
-
if (typeof item === 'string' && item.length > 0) return item;
|
|
242
|
-
return playerRef(item, `GameSync Event.teammates[${index}]`);
|
|
243
|
-
});
|
|
244
|
-
delete normalized.teammates;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
249
|
return normalized;
|
|
248
250
|
}
|
|
249
251
|
|
|
@@ -274,26 +276,54 @@ function newlyAssignedTask(event: Record<string, any>): Record<string, any> | nu
|
|
|
274
276
|
* Event Catalog.
|
|
275
277
|
*/
|
|
276
278
|
export function normalizeGameSyncEvents(values: readonly unknown[]): Record<string, any>[] {
|
|
277
|
-
|
|
279
|
+
return enrichTaskAssignments(values.map((value, index) => ({
|
|
280
|
+
index,
|
|
281
|
+
event: normalizeGameSyncEvent(value),
|
|
282
|
+
}))).map(({ event }) => event);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/** Normalize independent Events without rejecting their valid frame siblings. */
|
|
286
|
+
export function normalizeGameSyncEventsSafely(
|
|
287
|
+
values: readonly unknown[],
|
|
288
|
+
): GameSyncEventNormalizationResult {
|
|
289
|
+
const events: NormalizedGameSyncEventEntry[] = [];
|
|
290
|
+
const rejected: RejectedGameSyncEventEntry[] = [];
|
|
291
|
+
values.forEach((value, index) => {
|
|
292
|
+
try {
|
|
293
|
+
events.push({ index, event: normalizeGameSyncEvent(value) });
|
|
294
|
+
} catch (error) {
|
|
295
|
+
rejected.push({ index, error });
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
return { events: enrichTaskAssignments(events), rejected };
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function enrichTaskAssignments(
|
|
302
|
+
entries: readonly NormalizedGameSyncEventEntry[],
|
|
303
|
+
): NormalizedGameSyncEventEntry[] {
|
|
278
304
|
const claimedAssignments = new Set<number>();
|
|
279
305
|
|
|
280
|
-
return
|
|
281
|
-
|
|
306
|
+
return entries.map((entry, index) => {
|
|
307
|
+
const { event } = entry;
|
|
308
|
+
if (event.type !== 'task_completed' || !Number.isInteger(event.tick)) return entry;
|
|
282
309
|
const actorKey = taskEventActorKey(event);
|
|
283
|
-
if (!actorKey) return
|
|
310
|
+
if (!actorKey) return entry;
|
|
284
311
|
|
|
285
|
-
const assignmentIndex =
|
|
312
|
+
const assignmentIndex = entries.findIndex(({ event: candidate }, candidateIndex) => (
|
|
286
313
|
candidateIndex > index
|
|
287
314
|
&& !claimedAssignments.has(candidateIndex)
|
|
288
315
|
&& candidate.type === 'task_assigned'
|
|
289
316
|
&& candidate.tick === event.tick
|
|
290
317
|
&& taskEventActorKey(candidate) === actorKey
|
|
291
318
|
));
|
|
292
|
-
if (assignmentIndex < 0) return
|
|
319
|
+
if (assignmentIndex < 0) return entry;
|
|
293
320
|
|
|
294
|
-
const task = newlyAssignedTask(
|
|
295
|
-
if (!task) return
|
|
321
|
+
const task = newlyAssignedTask(entries[assignmentIndex]!.event);
|
|
322
|
+
if (!task) return entry;
|
|
296
323
|
claimedAssignments.add(assignmentIndex);
|
|
297
|
-
return {
|
|
324
|
+
return {
|
|
325
|
+
...entry,
|
|
326
|
+
event: { ...event, newly_assigned_task: task },
|
|
327
|
+
};
|
|
298
328
|
});
|
|
299
329
|
}
|
|
@@ -569,6 +569,14 @@ export async function runClawclawOwner(
|
|
|
569
569
|
strategy: assembly.strategy.activeResourceDescriptor(DESKTOP_RESOURCE_LOCALE),
|
|
570
570
|
perceptions: assembly.perception.localizedModuleDescriptors(DESKTOP_RESOURCE_LOCALE),
|
|
571
571
|
}),
|
|
572
|
+
eventDescriptors: () => assembly.perception
|
|
573
|
+
.localizedEventDescriptors(DESKTOP_RESOURCE_LOCALE)
|
|
574
|
+
.map((descriptor) => ({
|
|
575
|
+
type: descriptor.type,
|
|
576
|
+
perception_id: descriptor.perceptionId,
|
|
577
|
+
name: descriptor.name,
|
|
578
|
+
description: descriptor.description,
|
|
579
|
+
})),
|
|
572
580
|
onConnected: () => desktopEventPump?.retryNow(),
|
|
573
581
|
diagnostic: (name, attributes) => runtime?.diagnostic(name, attributes),
|
|
574
582
|
});
|
|
@@ -78,4 +78,17 @@ describe('ClawClaw plugin assembly', () => {
|
|
|
78
78
|
expect(assembled.plugins.filter((plugin) => plugin.id === CLAWCLAW_PERCEPTION_PLUGIN_ID))
|
|
79
79
|
.toEqual([perception]);
|
|
80
80
|
});
|
|
81
|
+
|
|
82
|
+
it('rejects terminate policy for plugins loaded into the ClawClaw graph', () => {
|
|
83
|
+
const plugin: RuntimeEpochPlugin<Record<string, any>> = {
|
|
84
|
+
kind: 'epoch',
|
|
85
|
+
id: 'user.plugin',
|
|
86
|
+
version: '1',
|
|
87
|
+
failurePolicy: 'terminate',
|
|
88
|
+
update: () => ({ outcome: 'noop' }),
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
expect(() => assembleClawclawPlugins(client, { epochPlugins: [plugin] }))
|
|
92
|
+
.toThrow('Runtime Plugin user.plugin cannot use the terminate failure policy');
|
|
93
|
+
});
|
|
81
94
|
});
|
|
@@ -48,6 +48,16 @@ export function assembleClawclawPlugins(
|
|
|
48
48
|
options: ClawclawPluginAssemblyOptions = {},
|
|
49
49
|
): ClawclawPluginAssembly {
|
|
50
50
|
const plugins = [...(options.epochPlugins ?? [])];
|
|
51
|
+
for (const plugin of plugins) {
|
|
52
|
+
const failureMode = typeof plugin.failurePolicy === 'string'
|
|
53
|
+
? plugin.failurePolicy
|
|
54
|
+
: plugin.failurePolicy?.mode;
|
|
55
|
+
if (failureMode === 'terminate') {
|
|
56
|
+
throw new Error(
|
|
57
|
+
`Runtime Plugin ${plugin.id} cannot use the terminate failure policy in the ClawClaw plugin graph.`,
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
51
61
|
|
|
52
62
|
const configuredAction = plugins.find((plugin) => plugin.id === CLAWCLAW_ACTION_PLUGIN_ID);
|
|
53
63
|
if (configuredAction && !(configuredAction instanceof ClawclawActionPlugin)) {
|