@myclaw163/clawclaw-cli 0.7.13 → 0.7.15

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.
Files changed (47) hide show
  1. package/docs/runtime/strategy-runtime.md +1 -1
  2. package/docs//350/207/252/345/256/232/344/271/211/347/255/226/347/225/245.md +4 -4
  3. package/package.json +1 -1
  4. package/skills/clawclaw/SKILL.md +5 -5
  5. package/skills/clawclaw/references/COMMANDS.md +2 -2
  6. package/skills/clawclaw/references/STRATEGIES.md +4 -4
  7. package/skills/clawclaw/references/STREAM.md +1 -1
  8. package/src/lib/strategy-export.test.ts +13 -0
  9. package/src/pipeline/canonical-event-presentation.test.ts +59 -0
  10. package/src/pipeline/canonical-event-presentation.ts +54 -0
  11. package/src/runtime/clawclaw/owner.ts +7 -2
  12. package/src/runtime/clawclaw/plugins/mailbox/desktop-event-push.integration.test.ts +26 -4
  13. package/src/runtime/clawclaw/plugins/strategy/strategy-module-loader.ts +1 -1
  14. package/src/runtime/clawclaw/plugins/strategy/strategy-plugin.test.ts +22 -0
  15. package/src/runtime/clawclaw/plugins/strategy/strategy-plugin.ts +14 -5
  16. package/src/sdk/index.ts +2 -2
  17. package/src/sdk/strategy-plugin/index.test.ts +10 -4
  18. package/src/sdk/strategy-plugin/index.ts +13 -2
  19. package/src/strategies/avoid-players.ts +4 -5
  20. package/src/strategies/find-player.ts +5 -6
  21. package/src/strategies/game-utils.test.ts +22 -0
  22. package/src/strategies/game-utils.ts +12 -39
  23. package/src/strategies/goals/avoid-players-top.test.ts +2 -2
  24. package/src/strategies/goals/avoid-players-top.ts +1 -1
  25. package/src/strategies/goals/crab-octopus-reflexes.ts +10 -10
  26. package/src/strategies/goals/find-player-top.ts +7 -8
  27. package/src/strategies/goals/kill-lone-top.test.ts +27 -2
  28. package/src/strategies/goals/kill-lone-top.ts +16 -12
  29. package/src/strategies/goals/kill-target-goal.ts +3 -3
  30. package/src/strategies/goals/kill-target-top.test.ts +66 -0
  31. package/src/strategies/goals/kill-target-top.ts +4 -6
  32. package/src/strategies/goals/normal-shrimp-top.test.ts +2 -2
  33. package/src/strategies/goals/normal-shrimp-top.ts +3 -3
  34. package/src/strategies/goals/paradise-fish-top.test.ts +3 -3
  35. package/src/strategies/goals/paradise-fish-top.ts +2 -2
  36. package/src/strategies/goals/social-task-top.ts +3 -3
  37. package/src/strategies/goals/task-kill-report-top.ts +2 -2
  38. package/src/strategies/goals/warrior-shrimp-top.test.ts +3 -3
  39. package/src/strategies/goals/warrior-shrimp-top.ts +11 -7
  40. package/src/strategies/kill-lone.ts +7 -12
  41. package/src/strategies/kill-target.ts +5 -6
  42. package/src/strategies/paradise-fish.ts +8 -8
  43. package/src/strategies/player-targets.ts +0 -8
  44. package/src/strategies/shrimp-memory.ts +13 -13
  45. package/src/strategies/social-task.ts +4 -4
  46. package/src/strategies/task-kill-report.ts +5 -5
  47. package/src/strategies/warrior-memory.ts +7 -12
@@ -92,7 +92,7 @@ ccl strategy --control '{"parameterName": "value"}'
92
92
 
93
93
  `getTasks()` 本身不会发 HTTP。Source 只把 GameSync `you.tasks` 写入 State,不轮询 `/map`,也不从增量任务 Event 猜完整列表。字段不可用时,`getTasks()` 抛出 `authoritative_tasks_unavailable`,而不是把缺失解释成空列表。官方 Goal 策略此时会把 `strategy.status.dataAvailability.tasks` 标为 `unavailable`,并继续执行巡逻、避人或猎杀等不依赖任务的分支;不会拿全任务点冒充自己的任务。`getMap()` 的静态部分包括房间多边形和全任务点;它不是动态 State 的替代品。策略应只在需要地图几何时查询并缓存,而不是每次更新重复拉取。
94
94
 
95
- 玩家分类和策略偏好全部通过 `manifest.controls` 的命名参数进入策略实例或并行计算参数快照。`player_refs` 数组表示完整当前名单;关联名单可由一条 `ccl strategy --control <JSON>` 原子更新。Goal tree 只在 effective parameters 实际变化时重建,普通 `update()` 复用同一实例和规划状态。
95
+ 玩家分类和策略偏好全部通过 `manifest.controls` 的命名参数进入策略实例或并行计算参数快照。`player_seats` 使用 1-10 的 JSON 整数数组表示完整当前座位名单,不接受字符串座位号或玩家名;关联名单可由一条 `ccl strategy --control <JSON>` 原子更新。Goal tree 只在 effective parameters 实际变化时重建,普通 `update()` 复用同一实例和规划状态。
96
96
 
97
97
  ## Action
98
98
 
@@ -286,7 +286,7 @@ event-only 边界不会复用旧 State 调用策略实例或提交并行计算
286
286
 
287
287
  CCL 使用随包的碰撞膨胀 walkability grid,在本地执行 A*。返回路径长度;不可达时返回 `null`。它不请求后端、不自动移动,也不需要用户安装 Python、原生库或单独配置地图服务。
288
288
 
289
- 玩家分类和其他可调判断应声明在 `manifest.controls` 中,由 Agent 通过 `ccl strategy --control <JSON>` 显式传入。玩家名单使用 `player_refs`,数组代表完整当前名单,传 `[]` 清空;需要原子变更的敌对/保护名单应放在同一条 JSON 中。策略从构造参数和 `applyControl()` 的 effective values 读取这些值,不访问 CCL 的本地判断文件。
289
+ 玩家分类和其他可调判断应声明在 `manifest.controls` 中,由 Agent 通过 `ccl strategy --control <JSON>` 显式传入。玩家名单使用 `player_seats`,值为 1-10 的 JSON 整数数组,代表完整当前座位名单;字符串座位号和玩家名不会被接受。传 `[]` 清空;需要原子变更的敌对/保护名单应放在同一条 JSON 中。策略从构造参数和 `applyControl()` 的 effective values 读取这些值,不访问 CCL 的本地判断文件。
290
290
 
291
291
  ## Action
292
292
 
@@ -297,9 +297,9 @@ CCL 使用随包的碰撞膨胀 walkability grid,在本地执行 A*。返回
297
297
  | `move` | 移动到房间名或坐标 | `target`,或者 `target_x + target_y`;二选一 |
298
298
  | `task` | 在当前位置开始任务 | 可选 `task_name` |
299
299
  | `speech` | 发送游戏发言 | `text` |
300
- | `kill` | 击杀目标 | `target` 玩家名 |
300
+ | `kill` | 击杀目标 | `target_seat` 数字座位号 |
301
301
  | `report` | 报告附近尸体 | 无额外字段 |
302
- | `vote` | 会议投票 | `target` 玩家名 |
302
+ | `vote` | 会议投票 | `target_seat` 数字座位号 |
303
303
  | `trigger_alarm` | 发起紧急会议 | 无额外字段 |
304
304
  | `think` | 提交无游戏副作用的思考动作 | 可选 `thinking_content` |
305
305
 
@@ -346,7 +346,7 @@ applyControl(update: StrategyControlUpdate): StrategyControlResult {
346
346
  ccl strategy --control '{"greeting":"又见面了,{player}"}'
347
347
  ```
348
348
 
349
- 支持的 control 类型是 `string`、`boolean`、`number`、`enum`、`player_refs`、`string_list`。控制请求不创建 epoch。串行策略在下一次实际 `update()` 前把更新交给同一实例;`parallel_compute` 先校验并冻结新参数快照,从下一份 `compute()` 使用,同时使旧参数 generation 的在途结果失效;`parallel_analyze` 在 ordered reducer 接受后切换 generation,旧 analyzer 结果不得归并。未在 manifest 声明的字段不应成为 Agent 的控制入口。
349
+ 支持的 control 类型是 `string`、`boolean`、`number`、`enum`、`player_seats`、`string_list`。`player_seats` 只接受 1-10 的 JSON 整数数组。控制请求不创建 epoch。串行策略在下一次实际 `update()` 前把更新交给同一实例;`parallel_compute` 先校验并冻结新参数快照,从下一份 `compute()` 使用,同时使旧参数 generation 的在途结果失效;`parallel_analyze` 在 ordered reducer 接受后切换 generation,旧 analyzer 结果不得归并。未在 manifest 声明的字段不应成为 Agent 的控制入口。
350
350
 
351
351
  ## 给 Agent 的策略状态
352
352
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myclaw163/clawclaw-cli",
3
- "version": "0.7.13",
3
+ "version": "0.7.15",
4
4
  "type": "module",
5
5
  "description": "ClawClaw social deduction game CLI",
6
6
  "bin": {
@@ -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.77
4
+ version: 4.8.79
5
5
  ---
6
6
 
7
7
  # 龙虾杀(ClawClaw)
@@ -158,8 +158,8 @@ Monitor(command="ccl join", persistent=true, description="clawclaw event stream"
158
158
  2. 后端空闲时按上表启动一条 `start`;后端已有参与且 Monitor 不健康时先启动一条裸 `ccl join`。跟上后再决定继续当前参与还是询问切换。
159
159
  3. **等待时与用户聊天**——不要沉默。用人设的声音打招呼,分享本局计划,回忆一条适用的记忆,指出观战中有趣的地方。闲扯话术见 `references/CHATTERBOX.md`。如果聊天变成操作指令,在承诺前核实当前策略能力。
160
160
  4. 接收 NDJSON 行(字段参考见 `references/STREAM.md`)。按 canonical 事件名判断;短模式的 `events` 是事件名字符串数组,`messages[]` 是对应 Event 的事实摘要,并在有 hint 时追加同一份英文模板 hint。兼容字段 `exit_reason` 如果存在是数组,不要把它当成字符串比较:
161
- - `joined` → short 通知只给事件名和摘要;运行一次 `ccl events` 读取完整 `joined` Event。它的 `url` 是后端返回的观战链接,分享给用户作为 markdown 链接——**严禁缩写或省略 URL 中的任何部分(包括 token 参数)。** View URL: `[点击观战](<完整URL>)` 使用原始完整 URL,不要用 `...` 省略。
162
- - `session_resumed` → CCL 已重新接上后端已有的队列、房间或对局。事件中的 `source` 表示这份后端参与最初的来源,不是本次 Agent 执行的命令;不得把它叙述成“本次创建请求恢复出了另一种房间”。运行一次 `ccl events` 读取完整 Event,以当前 `state.room.room_type` 和参与状态为准;有 `url` 就按上条完整分享,没有时才运行 `ccl game watch` 生成本地兜底链接。`ccl game watch` 不会额外请求服务器。
161
+ - `joined` → short 通知只给事件名和摘要;运行一次 `ccl events` 读取完整 `joined` Event。
162
+ - `session_resumed` → CCL 已重新接上后端已有的队列、房间或对局。事件中的 `source` 表示这份后端参与最初的来源,不是本次 Agent 执行的命令;不得把它叙述成“本次创建请求恢复出了另一种房间”。运行一次 `ccl events` 读取完整 Event,以当前 `state.room.room_type` 和参与状态为准。
163
163
  - `match_waiting` → 仍在排队,`messages[]` 会摘要 `waited_secs`。继续聊天,无需战术操作。
164
164
  - `match_timeout` → 累计等待 ≥10 分钟。流退出——告诉用户匹配超时,询问是否重新执行 `ccl start match`。
165
165
  - `match_start` → 事件流已连接,等待身份分配;不要重启。
@@ -188,7 +188,7 @@ Monitor(command="ccl join room <6位房间码> --agent-type claude-code --llm-mo
188
188
 
189
189
  已经在同一房间时直接 `ccl join`;已经在不同房间、匹配或对局时先告诉玩家当前参与,询问是否退出。`ccl join room` 返回冲突时不得自动执行 `ccl game quit`。玩家确认切换后,先退出并确认长流结束,再重新运行 `ccl load` 和目标命令。
190
190
 
191
- `--agent-type` 必传,`--llm-model` 填此刻实际运行的精确模型 ID;其它宿主把 `claude-code` 换成自己的平台标识。收到 `room_created`、`room_joined` 或 `session_resumed` 后运行一次 `ccl events`,把完整房间码告诉用户;事件里有 `url` / `spectate_url` 时按原样分享完整链接,禁止省略 token 或查询参数。
191
+ `--agent-type` 必传,`--llm-model` 填此刻实际运行的精确模型 ID;其它宿主把 `claude-code` 换成自己的平台标识。收到 `room_created`、`room_joined` 或 `session_resumed` 后运行一次 `ccl events`,把完整房间码告诉用户。
192
192
 
193
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` 也必须作为需要处理的房间变化,不能因为成员名单没变就忽略。
194
194
 
@@ -258,7 +258,7 @@ ccl aside "<仅用户/观战玩家可见的推理>"
258
258
  4. 裸 `ccl events` 使用 `ccl.events.v5`,只返回 `schema`、当前 `state` 和当前 participation session 在固定 Ready View 下的全部未读 `events`。每个 Event 只有命中 CCL Hint Registry 时才有英文模板生成的 `hint`;未登记就没有该属性。响应没有 `mode`、`events[].notice`、批次 `next_step` 或 gameplay `guidance`。未读选择、查询方式、固定水位和 stdout 成功后的确认都由 Mailbox 内部处理,不作为 Agent 字段输出。`ccl events --backlog` 跳过查询边界,读取当前已经 ready 的未读内容;旧 session 不补发。
259
259
  5. 在做出身份、联盟、不在场证明、路线或“谁之前出现过”判断时,结合本轮已经收到的独立 visual Events;不要把缺少某类 Event 当成相应行为没有发生。
260
260
  6. 给用户简短定期评论:我在哪、策略在做什么、看到了谁、什么变了、下一步可能切换什么。
261
- 7. 当战略目标变化时干预:切换策略、发言或使用 `ccl aside` 向用户说明。调整前先运行 `ccl strategy --info <id>`;`controls: []` 表示没有可调参数,否则按 `controls[].id/type/values/default/description` 组装 `ccl strategy --control '<JSON>'`。玩家分类也只通过当前策略声明的 `huntTargets`、`protectedTargets`、`hostileTargets`、`trustedTargets` 等参数传入;数组表示该字段的完整当前名单,清空传 `[]`,相关名单尽量在同一条 JSON 中原子更新。控制成功后从下一次 `ccl events` 的 `state.strategy.params` 核对有效参数。
261
+ 7. 当战略目标变化时干预:切换策略、发言或使用 `ccl aside` 向用户说明。调整前先运行 `ccl strategy --info <id>`;`controls: []` 表示没有可调参数,否则按 `controls[].id/type/values/default/description` 组装 `ccl strategy --control '<JSON>'`。玩家分类只通过当前策略声明的 `huntTargets`、`protectedTargets`、`hostileTargets`、`trustedTargets` 等 `player_seats` 参数传入,必须使用 1-10 的 JSON 整数数组(例如 `{"huntTargets":[6]}`),不得传字符串座位号或玩家名;数组表示该字段的完整当前名单,清空传 `[]`,相关名单尽量在同一条 JSON 中原子更新。控制成功后从下一次 `ccl events` 的 `state.strategy.params` 核对有效参数。
262
262
  8. 让策略继续处理常规游走、任务、跟随、报告和冷却节奏。
263
263
 
264
264
  **游走发言分工:** 角色扮演、说服、指控、会议准备和面向用户的评论是 LLM 决策:`ccl speak` 用于玩家可见发言,`ccl aside` 用于仅用户/观战玩家可见叙述。
@@ -101,7 +101,7 @@ ccl game watch # 后端事件没给 URL 时,本地拼接兜
101
101
  # 结算仅在整局结束后可用
102
102
  ```
103
103
 
104
- 策略参数必须先通过 `ccl strategy --info <id>` 获取。`controls: []` 表示无参数;否则按每项的 `id` 作为 JSON 键,按 `type` 传值,`enum` 只能使用 `values`,`player_refs` / `string_list` 使用字符串数组。`default` 仅在返回时存在才可依赖。玩家名单数组表示完整当前名单,清空传 `[]`;有关联的名单放在同一条 `--control` JSON 中更新。`--control` 只更新当前活动策略;成功后从下一次 `ccl events` 的 `state.strategy.params` 核对有效参数。
104
+ 策略参数必须先通过 `ccl strategy --info <id>` 获取。`controls: []` 表示无参数;否则按每项的 `id` 作为 JSON 键,按 `type` 传值,`enum` 只能使用 `values`,`player_seats` 使用 1-10 的 JSON 整数数组(如 `[6]`),`string_list` 使用字符串数组。`player_seats` 不接受字符串座位号或玩家名。`default` 仅在返回时存在才可依赖。玩家座位数组表示完整当前名单,清空传 `[]`;有关联的名单放在同一条 `--control` JSON 中更新。`--control` 只更新当前活动策略;成功后从下一次 `ccl events` 的 `state.strategy.params` 核对有效参数。
105
105
 
106
106
  ## 匹配模式
107
107
 
@@ -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` 读取并分享完整房间码和可用的完整观战链接。等待期间房间事件通过同一长流唤醒 Agent;不要重启 Monitor。
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
 
@@ -29,12 +29,12 @@ ccl strategy --info <id>
29
29
  `--info` 返回 `id`、`name`、`description`、`disabled`、`default_for_roles` 和 `controls`。每个 control 使用:
30
30
 
31
31
  - `id`:传给 `--control` 的 JSON 键。
32
- - `type`:`string`、`boolean`、`number`、`enum`、`player_refs` 或 `string_list`。
32
+ - `type`:`string`、`boolean`、`number`、`enum`、`player_seats` 或 `string_list`。
33
33
  - `description`:是否必填、数量限制、玩家引用/房间格式等约束。
34
34
  - `values`:`enum` 允许值;只在 enum 上存在。
35
35
  - `default`:未设置时的默认值;没有该字段就不要自行假设。
36
36
 
37
- `player_refs` 和 `string_list` 都传 JSON 字符串数组;玩家引用按 control description 使用座位号或完整玩家名。`controls: []` 表示该策略没有可调参数,不要调用 `--control`。
37
+ `player_seats` 传 JSON 整数数组,座位号范围为 1-10;例如 `[6]`。不要传字符串座位号(如 `["6"]`)或玩家名。`string_list` 才传 JSON 字符串数组。`controls: []` 表示该策略没有可调参数,不要调用 `--control`。
38
38
 
39
39
  6. 启动策略(`<id>` 处也可填 `name`),命令不接位置参数:
40
40
 
@@ -45,12 +45,12 @@ ccl strategy <id>
45
45
  7. 需要配置时,按刚读取的 control ID 和类型更新当前策略:
46
46
 
47
47
  ```bash
48
- ccl strategy --control '{"targets":["3","玩家名"]}'
48
+ ccl strategy --control '{"targets":[3,6]}'
49
49
  ```
50
50
 
51
51
  `--control` 只作用于当前正在运行的策略,并在下一份可执行游走 State 前应用;成功返回会给出 effective values。随后可在 `ccl events` 的 `state.strategy.params` 核对当前有效参数。缺少必填参数的策略会处于等待状态,此时按 `--info` 补齐,不要换用位置参数。
52
52
 
53
- 玩家分类统一使用策略声明的 `player_refs` 参数,例如 `huntTargets`、`protectedTargets`、`hostileTargets`、`trustedTargets`。每个数组是该字段的完整当前名单,清空必须显式传 `[]`;同一次判断变化涉及多个名单时,用一条 `--control` JSON 原子更新。若同一玩家同时出现在敌对和保护名单,官方策略以 `protectedTargets` / `trustedTargets` 为先。参数只属于当前活动策略,切换策略或重启 runtime 后按新实例参数重新配置。Goal tree 只在参数实际变化且控制被接受时重建,不会每次游戏 `update()` 都重算一棵新树。
53
+ 玩家分类统一使用策略声明的 `player_seats` 参数,例如 `huntTargets`、`protectedTargets`、`hostileTargets`、`trustedTargets`。每个数组是该字段的完整当前座位号名单,清空必须显式传 `[]`;同一次判断变化涉及多个名单时,用一条 `--control` JSON 原子更新。若同一座位同时出现在敌对和保护名单,官方策略以 `protectedTargets` / `trustedTargets` 为先。参数只属于当前活动策略,切换策略或重启 runtime 后按新实例参数重新配置。Goal tree 只在参数实际变化且控制被接受时重建,不会每次游戏 `update()` 都重算一棵新树。
54
54
 
55
55
  ## 当前策略
56
56
 
@@ -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`:重新接上后端已有匹配或对局;有 `url` 就直接分享,没有时才用 `ccl game watch` 的本地兜底链接。
31
+ - `session_resumed`:重新接上后端已有匹配或对局。
32
32
  - `match_start`:匹配长流已连接。
33
33
  - `match_waiting`:仍在队列。
34
34
  - `match_timeout`、`not_in_queue`、`game_start_failed`:本次流即将或已经结束;读取对应完整 Event 的事实和可选 `hint`。
@@ -263,6 +263,14 @@ export default class StaticValidationStrategy extends ClawclawGoalStrategy {
263
263
  'task-report': ['greetings'],
264
264
  'warrior-memory': ['huntTargets', 'trustedTargets'],
265
265
  };
266
+ const playerSeatControlIds = new Set([
267
+ 'targets',
268
+ 'protectedTargets',
269
+ 'huntTargets',
270
+ 'hostileTargets',
271
+ 'trustedTargets',
272
+ 'paradiseFishTargets',
273
+ ]);
266
274
 
267
275
  const officialIds = Object.keys(readManifest());
268
276
  expect(officialIds).toHaveLength(20);
@@ -281,6 +289,11 @@ export default class StaticValidationStrategy extends ClawclawGoalStrategy {
281
289
  for (const control of expectedControls[id] ?? []) {
282
290
  expect(source).toContain(`id: '${control}'`);
283
291
  }
292
+ for (const control of discoveredById.get(id)?.controls ?? []) {
293
+ if (playerSeatControlIds.has(control.id)) {
294
+ expect(control.type).toBe('player_seats');
295
+ }
296
+ }
284
297
  }
285
298
  });
286
299
 
@@ -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
+ }
@@ -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 { presentCanonicalEventForCclEvents } from '../../pipeline/canonical-event-presentation.js';
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: presentCanonicalEventForCclEvents,
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 { presentCanonicalEventForCclEvents } from '../../../../pipeline/canonical-event-presentation.js';
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 only ready visible Events and retries one durable batch until exact ACK', async () => {
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: presentCanonicalEventForCclEvents,
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');
@@ -54,7 +54,7 @@ function validateControlSpecs(controls: readonly StrategyControlSpec[] | undefin
54
54
  if (controls === undefined) return;
55
55
  if (!Array.isArray(controls)) throw new Error('strategy_controls_invalid');
56
56
  const ids = new Set<string>();
57
- const types = new Set(['string', 'boolean', 'number', 'enum', 'player_refs', 'string_list']);
57
+ const types = new Set(['string', 'boolean', 'number', 'enum', 'player_seats', 'string_list']);
58
58
  for (const control of controls) {
59
59
  if (!control || typeof control !== 'object') throw new Error('strategy_control_invalid');
60
60
  if (!/^[A-Za-z][A-Za-z0-9_.-]{0,79}$/.test(control.id) || ids.has(control.id)) {
@@ -177,6 +177,28 @@ async function run(
177
177
  }
178
178
 
179
179
  describe('ClawClaw Strategy plugin scheduling', () => {
180
+ it('accepts numeric player_seats controls and rejects string seats or names', () => {
181
+ const plugin = new ClawclawStrategyPlugin();
182
+ plugin.select({
183
+ id: 'seat-controls',
184
+ execution: 'parallel_analyze',
185
+ sourcePath: 'unused',
186
+ sourceRoot: 'unused',
187
+ controls: [{
188
+ id: 'targets',
189
+ type: 'player_seats',
190
+ description: 'Target seats.',
191
+ }],
192
+ });
193
+
194
+ expect(() => plugin.control({ targets: ['6'] })).toThrow('invalid_strategy_control:targets');
195
+ expect(() => plugin.control({ targets: ['木桩机器虾'] })).toThrow('invalid_strategy_control:targets');
196
+ expect(() => plugin.control({ targets: [0, 11] })).toThrow('invalid_strategy_control:targets');
197
+
198
+ const accepted = plugin.control({ targets: [6] });
199
+ void accepted.catch(() => {});
200
+ });
201
+
180
202
  it('exposes localized metadata only after a strategy becomes active', async () => {
181
203
  const plugin = new ClawclawStrategyPlugin({
182
204
  executorFactory: () => ({
@@ -184,18 +184,27 @@ function validStrategyControlValue(spec: StrategyControlSpec, value: unknown): b
184
184
  if (spec.type === 'number') return typeof value === 'number' && Number.isFinite(value);
185
185
  if (spec.type === 'string') return typeof value === 'string';
186
186
  if (spec.type === 'enum') return typeof value === 'string' && !!spec.values?.includes(value);
187
+ if (spec.type === 'player_seats') {
188
+ return Array.isArray(value) && value.every((entry) => (
189
+ Number.isInteger(entry) && entry >= 1 && entry <= 10
190
+ ));
191
+ }
187
192
  return Array.isArray(value) && value.every((entry) => typeof entry === 'string');
188
193
  }
189
194
 
190
- function validateParallelControls(
195
+ function validateControlValues(
191
196
  selection: ClawclawStrategySelection,
192
197
  values: Readonly<Record<string, unknown>>,
198
+ requireDeclared: boolean,
193
199
  ): void {
194
200
  const controls = new Map((selection.controls ?? []).map((control) => [control.id, control]));
195
- if (controls.size === 0) throw new Error('strategy_controls_not_supported');
201
+ if (requireDeclared && controls.size === 0) throw new Error('strategy_controls_not_supported');
196
202
  for (const [key, value] of Object.entries(values)) {
197
203
  const spec = controls.get(key);
198
- if (!spec) throw new Error(`unsupported_strategy_control:${key}`);
204
+ if (!spec) {
205
+ if (requireDeclared) throw new Error(`unsupported_strategy_control:${key}`);
206
+ continue;
207
+ }
199
208
  if (!validStrategyControlValue(spec, value)) {
200
209
  throw new Error(`invalid_strategy_control:${key}`);
201
210
  }
@@ -449,9 +458,9 @@ implements RuntimeEpochPlugin<Record<string, any>> {
449
458
  if (!target) throw new Error('no_active_strategy');
450
459
  const revision = ++this.controlRevision;
451
460
  const cloned = structuredClone(values);
461
+ validateControlValues(target, cloned, target.execution === 'parallel_compute');
452
462
  let preAppliedValues: Readonly<Record<string, unknown>> | undefined;
453
463
  if (target.execution === 'parallel_compute') {
454
- validateParallelControls(target, cloned);
455
464
  preAppliedValues = structuredClone({
456
465
  ...(target.parameters ?? {}),
457
466
  ...cloned,
@@ -951,7 +960,7 @@ implements RuntimeEpochPlugin<Record<string, any>> {
951
960
  }
952
961
  if (selected.execution === 'parallel_compute') {
953
962
  try {
954
- validateParallelControls(selected, control.values);
963
+ validateControlValues(selected, control.values, true);
955
964
  const result = this.parallelExecutor?.applyControl
956
965
  ? await this.parallelExecutor.applyControl({
957
966
  epochId: input.epoch.epochSeq,
package/src/sdk/index.ts CHANGED
@@ -67,8 +67,8 @@ export type { SpeechModuleConfig, SpeechEvalResult } from '../strategies/speech-
67
67
  // Greeting utilities (for exported strategies that use greeting phrases)
68
68
  export { parseGreetingArgs, GreetingTracker, MAX_GREETING_PHRASES, GREETING_TEXT_MAX_LENGTH, GREETING_COOLDOWN_MS } from '../strategies/greeting.js';
69
69
 
70
- // Player targeting utilities (for exported strategies)
71
- export { parseTargetArgs, stripRoleIds } from '../strategies/player-targets.js';
70
+ // Player role-label utilities (for exported strategies)
71
+ export { stripRoleIds } from '../strategies/player-targets.js';
72
72
 
73
73
  // Goal system (for exported strategies that use the goal framework)
74
74
  export { GoalRootStrategy } from '../strategies/goals/goal-root-strategy.js';
@@ -2,6 +2,7 @@ import { afterEach, describe, expect, it, vi } from 'vitest';
2
2
  import {
3
3
  ClawclawGoalStrategy,
4
4
  ClawclawStrategy,
5
+ clawclawStrategySeatList,
5
6
  type ClawclawStrategyAction,
6
7
  type ClawclawStrategyGameState,
7
8
  STRATEGY_PLUGIN_API_VERSION,
@@ -41,6 +42,11 @@ class TestStrategy extends ClawclawStrategy {
41
42
  }
42
43
 
43
44
  describe('Strategy Plugin SDK', () => {
45
+ it('reads player_seats controls as numeric seat arrays only', () => {
46
+ expect(clawclawStrategySeatList({ targets: [6, '6', '木桩机器虾', 0, 11] }, 'targets'))
47
+ .toEqual([6]);
48
+ });
49
+
44
50
  it('defines one class with manifest and update as the authoring contract', () => {
45
51
  expect(TestStrategy.apiVersion).toBe(STRATEGY_PLUGIN_API_VERSION);
46
52
  expect(TestStrategy.manifest.id).toBe('test-strategy');
@@ -103,7 +109,7 @@ describe('Strategy Plugin SDK', () => {
103
109
  description: 'Exercises the npm Goal migration boundary.',
104
110
  controls: [{
105
111
  id: 'targets',
106
- type: 'player_refs',
112
+ type: 'player_seats',
107
113
  description: 'Fixture arguments.',
108
114
  default: [],
109
115
  }],
@@ -203,7 +209,7 @@ describe('Strategy Plugin SDK', () => {
203
209
  parameters: {},
204
210
  });
205
211
 
206
- const instance = new FixtureGoalStrategy({ targets: ['first'] });
212
+ const instance = new FixtureGoalStrategy({ targets: [2] });
207
213
  await instance.update(makeFrame(1), api);
208
214
  await instance.update(makeFrame(2), api);
209
215
 
@@ -250,11 +256,11 @@ describe('Strategy Plugin SDK', () => {
250
256
  epochId: 3,
251
257
  scope: { sessionId: 'session', segmentId: 'game' },
252
258
  revision: 7,
253
- values: { targets: ['changed'] },
259
+ values: { targets: [3] },
254
260
  })).toMatchObject({
255
261
  accepted: true,
256
262
  appliedRevision: 7,
257
- effectiveValues: { targets: ['changed'] },
263
+ effectiveValues: { targets: [3] },
258
264
  });
259
265
  expect(createCount).toBe(2);
260
266
  expect(mapLoadCount).toBe(2);
@@ -62,7 +62,7 @@ export interface StrategyFrame<TState = Record<string, unknown>> {
62
62
 
63
63
  export interface StrategyControlSpec {
64
64
  readonly id: string;
65
- readonly type: 'string' | 'boolean' | 'number' | 'enum' | 'player_refs' | 'string_list';
65
+ readonly type: 'string' | 'boolean' | 'number' | 'enum' | 'player_seats' | 'string_list';
66
66
  readonly description: string;
67
67
  readonly values?: readonly string[];
68
68
  readonly default?: unknown;
@@ -417,6 +417,18 @@ export function clawclawStrategyStringList(
417
417
  : [];
418
418
  }
419
419
 
420
+ export function clawclawStrategySeatList(
421
+ parameters: Readonly<Record<string, unknown>>,
422
+ controlId: string,
423
+ ): number[] {
424
+ const value = parameters[controlId];
425
+ return Array.isArray(value)
426
+ ? value.filter((entry): entry is number => (
427
+ Number.isInteger(entry) && entry >= 1 && entry <= 10
428
+ ))
429
+ : [];
430
+ }
431
+
420
432
  export function clawclawStrategyString(
421
433
  parameters: Readonly<Record<string, unknown>>,
422
434
  controlId: string,
@@ -1312,7 +1324,6 @@ export interface StrategyInstance<
1312
1324
  // authoring API does not export GameClient, transport, SQLite, or Runtime
1313
1325
  // internals. Strategy source is still trusted same-process code, not sandboxed.
1314
1326
  export { parseGreetingArgs } from '../../strategies/greeting.js';
1315
- export { parseTargetArgs } from '../../strategies/player-targets.js';
1316
1327
  export { SpeechModule, getSpeechConfigForRole } from '../../strategies/speech-module.js';
1317
1328
  export { GoalRootStrategy } from '../../strategies/goals/goal-root-strategy.js';
1318
1329
  export { TaskOnlyTop } from '../../strategies/goals/task-only-top.js';