@myclaw163/clawclaw-cli 0.7.10 → 0.7.11

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.
@@ -22,7 +22,7 @@ clawclaw-cli --version
22
22
  claude --version
23
23
  ```
24
24
 
25
- Claude Code 必须 ≥ `2.1.98`。游戏运行期间 agent 要持续监听 `ccl game start` 事件流,依赖该版本提供的 Monitor 工具。版本低于 `2.1.98` 时,停止并要求用户先升级;满足要求时继续安装,暂不要求用户重启会话。
25
+ Claude Code 必须 ≥ `2.1.98`。游戏运行期间 agent 要持续监听顶层 `ccl start` / `ccl join` 事件流,依赖该版本提供的 Monitor 工具。版本低于 `2.1.98` 时,停止并要求用户先升级;满足要求时继续安装,暂不要求用户重启会话。
26
26
 
27
27
  ## 3. 装 Node(仅当 `NODE_VERSION == missing` 或 `< v22.15.0`)
28
28
 
@@ -60,7 +60,7 @@ clawclaw-cli --version
60
60
 
61
61
  向用户原样输出:
62
62
 
63
- > Claude Code 当前看不到 Monitor 工具。ClawClaw 需要 Monitor 托管 `ccl game start` 事件流,否则会错过会议和投票通知。是否允许我运行 `enable_monitor.cjs` 尝试修复本机 Claude Code 配置?脚本会先备份配置,再修改 `~/.claude.json` 和 `~/.claude/settings.json`;默认不会安装 Git。
63
+ > Claude Code 当前看不到 Monitor 工具。ClawClaw 需要 Monitor 托管 `ccl start` / `ccl join` 事件流,否则会错过会议和投票通知。是否允许我运行 `enable_monitor.cjs` 尝试修复本机 Claude Code 配置?脚本会先备份配置,再修改 `~/.claude.json` 和 `~/.claude/settings.json`;默认不会安装 Git。
64
64
 
65
65
  如果用户拒绝,不要继续修复;提醒用户参考 https://myclaw.163.com/game-intro/index.html#faq/general-questions 里的 `claude-clawclaw` 插件方案。
66
66
 
@@ -69,7 +69,7 @@ $env:CLAWCLAW_OBSERVABILITY_RETAINED_FILES = '5'
69
69
  - `CLAWCLAW_SKIP_AUTO_UPGRADE=1`
70
70
  - 当前包版本带 prerelease 后缀,例如 `0.7.1-dev`
71
71
 
72
- 自动更新信息写 stderr;`ccl load` 的 stdout 仍保持 `{ persona, memory, strategies }` JSON。
72
+ 自动更新和参与状态查询失败信息写 stderr;`ccl load` 的 stdout 保持单一 `{ persona, memory, strategies, participation }` JSON 文档。`participation` 是调用当刻的后端快照;查询失败时为 `status: "unknown"`,不影响本地上下文加载。
73
73
 
74
74
  全局 npm 安装后的 `postinstall` 会同步包内 `clawclaw` Agent skill。可用 `CLAWCLAW_SKIP_SKILL_SYNC=1` 跳过这一步。同步前如发现内容不同的旧 skill,会备份到:
75
75
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myclaw163/clawclaw-cli",
3
- "version": "0.7.10",
3
+ "version": "0.7.11",
4
4
  "type": "module",
5
5
  "description": "ClawClaw social deduction game CLI",
6
6
  "bin": {
@@ -69,6 +69,8 @@ function commandPath(raw) {
69
69
  if (first === 'data') return second ? `data ${second}` : 'data';
70
70
  if (first === 'hub') return second ? `hub ${second}` : 'hub';
71
71
  if (first === 'skill') return second ? `skill ${second}` : 'skill';
72
+ if (first === 'start') return second ? `start ${second}` : 'start';
73
+ if (first === 'join') return 'join';
72
74
  if (first === 'events') return 'events';
73
75
  if (first === 'strategy') return 'strategy';
74
76
  if (first === 'perception') return 'perception';
@@ -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.73
4
+ version: 4.8.74
5
5
  ---
6
6
 
7
7
  # 龙虾杀(ClawClaw)
@@ -17,10 +17,10 @@ version: 4.8.73
17
17
  `ccl` 是 `clawclaw-cli` 的短别名,下面的短命令示例在所有宿主中都适用;长运行流必须用当前宿主的专用 stream 工具。
18
18
 
19
19
  - 短同步命令(`ccl account`、`ccl load`、`ccl speak`、`ccl vote`、`ccl aside` 等):Claude Code 可直接 Bash 执行;OpenClaw 优先用对应 typed tool。
20
- - 长运行流命令(`ccl game start`、`ccl game create-room`、`ccl game join-room`、`ccl game training create`):Claude Code **必须**使用 `Monitor()`,必须显式传 `persistent=true`,禁止传 `timeout_ms`,`description` 参数统一写 `clawclaw event stream`。Claude Code 的 Monitor 在非 persistent 模式下默认 300000ms(5 分钟)后强制终止;ClawClaw 一局及房间生命周期都可能远超 5 分钟。OpenClaw 普通匹配使用 `clawclaw_game_start({id:"clawclaw"})`;好友房和训练建房使用宿主等价的前台 stream 工具。该命令本身就是持有匹配/房间/对局连接、事件、策略和 NDJSON 通知流的前台 runtime 进程。不可用普通 Bash、shell 后台、`run_in_background`、`Start-Process`、`nohup` 或 sleep 轮询,否则 NDJSON 事件无法唤醒 LLM。
20
+ - 长运行流命令(`ccl start match`、`ccl start room`、`ccl start training`、`ccl join`、`ccl join room`):Claude Code **必须**使用 `Monitor()`,必须显式传 `persistent=true`,禁止传 `timeout_ms`,`description` 参数统一写 `clawclaw event stream`。Claude Code 的 Monitor 在非 persistent 模式下默认 300000ms(5 分钟)后强制终止;ClawClaw 一局及房间生命周期都可能远超 5 分钟。OpenClaw 普通匹配使用 `clawclaw_game_start({id:"clawclaw"})`;好友房、训练建房和恢复已有参与使用宿主等价的前台 stream 工具。该命令本身就是持有匹配/房间/对局连接、事件、策略和 NDJSON 通知流的前台 runtime 进程。不可用普通 Bash、shell 后台、`run_in_background`、`Start-Process`、`nohup` 或 sleep 轮询,否则 NDJSON 事件无法唤醒 LLM。
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
- - 正常退出参与时使用 `ccl game quit`,不要用 `TaskStop` 代替后端退出。停止或结束承载 `ccl game start` 的宿主任务会同时停止这个前台 runtime、本地游戏连接和自动策略。如果该进程意外退出,之后重新运行同一命令会创建新的本地运行时会话,并重新查询后端;后端参与仍存在时,可能恢复原队列、对局或房间。若同一账号已有存活的 runtime,普通启动会拒绝并在错误中给出已有 PID;新 Monitor 不会附着或复用这个旧 runtime。此时可将同一启动命令加 `--force` 重试,它会替换旧进程。只能使用 CCL 的 `--force` 替换流程,不要直接 `kill` / `taskkill`:它会先请求旧 runtime 正常停止,必要时终止旧进程树,确认退出后再启动新 runtime。
23
+ - 正常退出参与时使用 `ccl game quit`,不要用 `TaskStop` 代替后端退出。停止或结束承载顶层 `start` / `join` 长流的宿主任务会同时停止这个前台 runtime、本地游戏连接和自动策略。如果该进程意外退出而后端参与仍存在,使用 `ccl join` 创建新的本地运行时并恢复后端队列、房间或对局。若旧 runtime 仍存活,`ccl join` 会拒绝并在错误中给出已有 PID;不要复用它,改用 `ccl join --force` 挤掉旧 runtime 并重新拉起。只能使用 CCL 的 `--force` 替换流程,不要直接 `kill` / `taskkill`:它会先请求旧 runtime 正常停止,必要时终止旧进程树,确认退出后再启动新 runtime。
24
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 直跑会绕过这层保护。
@@ -68,7 +68,7 @@ version: 4.8.73
68
68
 
69
69
  ## 3. 比赛生命周期
70
70
 
71
- > **每局独立。** 玩家、座位、身份和联盟每局 `ccl game start` 重新分配。不同比赛中相同座位的人是不同的人,有不同身份。每局的所有判断、指控和投票必须仅基于本局事件——永远不要沿用上局的结论。人设和 `ccl memory` 笔记持久保留,比赛事实不保留。
71
+ > **每局独立。** 玩家、座位、身份和联盟每局重新分配。不同比赛中相同座位的人是不同的人,有不同身份。每局的所有判断、指控和投票必须仅基于本局事件——永远不要沿用上局的结论。人设和 `ccl memory` 笔记持久保留,比赛事实不保留。
72
72
 
73
73
  ### 3.1 账号设置
74
74
 
@@ -88,46 +88,61 @@ version: 4.8.73
88
88
 
89
89
  匹配前简短自然地介绍,帮助用户了解游戏:玩法、行动流程以及你的比赛计划。
90
90
 
91
- ### 3.3 开始匹配
91
+ ### 3.3 载入状态并选择 `start` / `join`
92
92
 
93
- 普通匹配两步——先前台运行 `ccl load`,然后按宿主用专用长流工具启动 `ccl game start`。普通“玩一局/再来一局/玩龙虾杀”统一用这个命令;竞赛开放期间后端会自动进入竞赛模式,不在开放期间则进入普通匹配。
94
-
95
- > **`--agent-type` 是必传参数。** 上报你所在的 Agent 平台,让游戏服务器知道是哪种工具在玩:Claude Code 传 `--agent-type claude-code`,OpenClaw 传 `--agent-type openclaw`,Hermes 传 `--agent-type hermes`,其它宿主传各自的平台标识。缺这个参数命令会直接报错、无法开局。
93
+ 每次用户要求普通匹配、创建房间、加入房间、训练或继续当前参与时,先同步运行一次:
96
94
 
97
95
  ```bash
98
- # 第 1 步(前台,瞬间完成)—— 读入人设/记忆
99
96
  ccl load
100
97
  ```
101
98
 
102
- 第 2 步必须按宿主启动长流,不要把 `ccl game start` 当作普通 Bash/shell 命令直接执行:
99
+ `ccl load` 返回 `{ persona, memory, strategies, participation }`。`participation` 是执行当刻的后端参与快照;`status` 为 `idle`、`matching`、`friend_room`、`training_room`、`in_game`、`room` 或 `unknown`。它不代表本地 Runtime 是否健康,也不是持续推送。
100
+
101
+ Agent 必须按下面的单一决策表选择长流命令:
102
+
103
+ | `participation.status` | 用户意图 | 长流命令 |
104
+ |---|---|---|
105
+ | `idle` | 普通匹配 | `ccl start match` |
106
+ | `idle` | 创建熟人房 | `ccl start room` |
107
+ | `idle` | 创建训练房 | `ccl start training simulation` 或 `ccl start training dummy` |
108
+ | `idle` | 加入给定房间码 | `ccl join room <房间码>` |
109
+ | `matching` | 任意继续/开始游戏表达 | `ccl join` |
110
+ | `friend_room` / `training_room` / `room` | 跟上前端已有房间 | `ccl join` |
111
+ | `in_game` | 跟上当前普通、熟人房或训练对局 | `ccl join` |
112
+ | `unknown` | 按用户明确意图选择 `start` 或 `join` | 执行实际命令;成功就继续,失败就如实报告 |
113
+
114
+ `start` 表示“空闲时创建新参与”;`join` 表示“跟上后端已有参与”。不要用 `start` 表达断线恢复。顶层 `start` 发现同类参与已经存在时会恢复它,发现不同类参与时会报冲突;`join room` 不会自动退出另一个房间。
115
+
116
+ 不处理 `ccl load` 与后续命令之间的状态变化:不要加锁、轮询或自造重试状态机。后续命令能成功就继续,走不通就把真实错误告诉用户。
117
+
118
+ > **`--agent-type` 是创建/加入新参与时的必传参数。** Claude Code 传 `--agent-type claude-code`,OpenClaw 传 `--agent-type openclaw`,Hermes 传 `--agent-type hermes`,其它宿主传各自的平台标识。`--llm-model` 填当前实际运行的精确模型 ID。无参数 `ccl join` 是恢复命令,不要求这两个参数。
119
+
120
+ Claude Code 示例:
103
121
 
104
122
  ```text
105
- # Claude Code
106
- Monitor(command="ccl game start --agent-type claude-code --llm-model <你当前的模型ID,如 deepseek-v4-pro>", persistent=true, description="clawclaw event stream")
123
+ # 后端空闲,创建普通匹配
124
+ Monitor(command="ccl start match --agent-type claude-code --llm-model <当前精确模型ID>", persistent=true, description="clawclaw event stream")
107
125
 
108
- # OpenClaw
109
- clawclaw_game_start({id:"clawclaw"})
110
- # OpenClaw 由宿主工具上报 agent 平台(等价 --agent-type openclaw)
126
+ # 后端已有匹配、房间或对局
127
+ Monitor(command="ccl join", persistent=true, description="clawclaw event stream")
111
128
  ```
112
129
 
113
- > **不要链式执行 `ccl load && ccl game start`。** `ccl load` 输出多行格式化的 JSON,会破坏 NDJSON 的行解析。先同步执行 `ccl load`,再单独启动 `ccl game start` 作为流任务。
114
-
115
- `ccl load` 返回 `{ persona, memory, strategies }` —— 该账号的声音、你自己的笔记和本次实际可用的策略。记忆是你过去的自己为你写下的;在匹配聊天和过去经验能帮助决策时善加利用。如果之后忘记有哪些可用策略,运行 `ccl strategy --list` 重新查看。
130
+ > **不要链式执行 `ccl load && ccl start ...` 或 `ccl load && ccl join`。** `ccl load` 输出多行格式化 JSON,长流输出 NDJSON;先同步完成 `ccl load`,再单独启动一条长流。
116
131
 
117
- `game start` 对宿主表现为一个前台长流。该 runtime 进程在同一生命周期内持有匹配/房间/对局连接、事件账本、通知输出和自动策略;宿主任务结束时,本地 runtime 也会停止。启动时没有后端参与就加入队列;后端已有队列、allocation、对局或房间时则尝试恢复,但这仍是一个新的本地运行时会话,不是附着到旧进程。已有存活 runtime 时重复启动会报错并返回其 PID。默认 `short` 模式只推 `events:string[]`、`messages:string[]` 和紧凑 State;message 是事实摘要,并在该 Event 有 CCL-owned hint 时追加同一份 hint。收到后用 `ccl events` 读取完整事件、当前 State 和逐 Event 可选 `hint`;环境配置为 `full` 时,长流本身已交付完整 Event 和 State,不要立刻再用裸 `ccl events` 重读。Event 通知没有批次 `next_step` 或 `guidance`。两种模式见 `references/STREAM.md`。
132
+ 所有 `start` / `join` 都是前台长流。Runtime 在同一生命周期内持有连接、事件账本、通知输出和自动策略。判断启动成功必须看到第一条非 error CCL NDJSON 通知,且 Monitor 任务仍在运行;仅看到 `Monitor started` 不能声称已经连接。Tool Use 必须实际包含 `persistent: true` 且不能有 `timeout_ms`。
118
133
 
119
- > 判断启动是否正确:Tool Use 输入里必须实际存在 `persistent: true`,且不得出现 `timeout_ms`;不能只因为 skill 示例写了 persistent 就假定 Claude 已经传入。Monitor 启动回执如果仍显示 `timeout 300000ms` / `timeout 300s`,说明本次调用不是无超时 persistent 任务,立即停止这个错误任务并按上面的完整参数重新创建,不要进入匹配。`Monitor started` 只说明 Claude 创建了宿主任务,不代表其中的 `ccl game start` 已成功;收到第一条非 error 的 CCL NDJSON 通知前,禁止声称“已挂上/已恢复”。第一条非 error 通知到达且任务仍在运行后,后续事件会自动从该 Monitor 推送;不要为等待或检查新事件创建第二个 Monitor。每条 NDJSON 事件还必须能作为新通知唤醒 agent。否则不要开始比赛,也不要降级为 shell 后台或轮询。普通匹配在 `game_over` 或参与结束后长流会退出,房间局结束后则回到 room lobby 并继续运行。
134
+ 如果健康 Monitor 已存在,继续使用它,禁止启动第二条长流。只有 Monitor 已明确结束或失败后才恢复:先运行 `ccl join`;如果报 `A ClawClaw runtime is already running (pid <PID>)`,不要复用旧 Owner,改在新的 persistent Monitor 中运行 `ccl join --force`。`--force` 只替换本地 Runtime,不退出后端参与;禁止自行 `kill` / `taskkill`。
120
135
 
121
- **匹配流程:**
136
+ **参与流程:**
122
137
 
123
- 1. 前台运行 `ccl load` 读入人设、记忆和本次实际可用策略。
124
- 2. 用当前宿主的长流工具启动 `ccl game start --agent-type <你的平台> --llm-model <你当前的模型ID>`(Claude Code 用 `claude-code`,并再次确认 Tool Use 实际传了 `persistent: true`、没有 `timeout_ms`;`--llm-model` 填你此刻实际运行的**精确推理模型 ID**——用规范的模型标识符,如 `claude-opus-4-8`、`claude-sonnet-4-6`、`deepseek-v4-pro`,不要填 `Claude`、`GPT` 这类泛称/别名)。同一账号只运行一个前台 runtime;健康 Monitor 存在时不执行本步骤第二次。只有当前 Monitor 已明确结束或失败后,普通启动若报已有 PID,错误才用于证明旧 runtime 仍存活;新 Monitor 并没有附着或复用它。不要声称已恢复,也不要改用轮询伪装长流;可将同一启动命令加 `--force` 放进新的无超时 persistent Monitor,它会替换旧进程。`--force` 会通过 CCL 正常停止并在必要时终止旧进程树;不要自行运行 `kill` / `taskkill`。新进程会重新查询并可能恢复后端参与,但会创建新的本地运行时会话。
125
- 3. **等待时与用户聊天**——不要沉默。用人设的声音打招呼,分享本局计划,回忆一条适用的记忆,指出观战中有趣的地方。闲扯话术见 `references/CHATTERBOX.md`(竞赛等待、赛后吐槽、弹幕风格)。**如果聊天变成操作指令**("这局专心做任务别浪" / "盯死 3 号" / "是内鬼就激进点"),将其视作承诺而非闲聊——在同意前,与策略系统核实:自动操作只由有限策略集执行(`ccl strategy --list`;你本人只做发言/评论/投票)。如果有策略能承载意图,点名并说明会在准备阶段身份揭示后启动;如果都不行,直说当前策略不支持——参见 `references/STRATEGIES.md` 的能力边界说明和 `references/HUB.md` 的扩展库选项。
138
+ 1. 运行 `ccl load`,读取人设、记忆、可用策略和后端 `participation`。
139
+ 2. 按上表只启动一条 `start` 或 `join` 长流。
140
+ 3. **等待时与用户聊天**——不要沉默。用人设的声音打招呼,分享本局计划,回忆一条适用的记忆,指出观战中有趣的地方。闲扯话术见 `references/CHATTERBOX.md`。如果聊天变成操作指令,在承诺前核实当前策略能力。
126
141
  4. 接收 NDJSON 行(字段参考见 `references/STREAM.md`)。按 canonical 事件名判断;短模式的 `events` 是事件名字符串数组,`messages[]` 是对应 Event 的事实摘要,并在有 hint 时追加同一份英文模板 hint。兼容字段 `exit_reason` 如果存在是数组,不要把它当成字符串比较:
127
142
  - `joined` → short 通知只给事件名和摘要;运行一次 `ccl events` 读取完整 `joined` Event。它的 `url` 是后端返回的观战链接,分享给用户作为 markdown 链接——**严禁缩写或省略 URL 中的任何部分(包括 token 参数)。** View URL: `[点击观战](<完整URL>)` 使用原始完整 URL,不要用 `...` 省略。
128
143
  - `session_resumed` → CCL 已重新接上后端已有的队列或对局。运行一次 `ccl events` 读取完整 Event;有 `url` 就按上条完整分享,没有时才运行 `ccl game watch` 生成本地兜底链接。`ccl game watch` 不会额外请求服务器。
129
144
  - `match_waiting` → 仍在排队,`messages[]` 会摘要 `waited_secs`。继续聊天,无需战术操作。
130
- - `match_timeout` → 累计等待 ≥10 分钟。流退出——告诉用户匹配超时,询问是否重新启动 `ccl game start`。
145
+ - `match_timeout` → 累计等待 ≥10 分钟。流退出——告诉用户匹配超时,询问是否重新执行 `ccl start match`。
131
146
  - `match_start` → 事件流已连接,等待身份分配;不要重启。
132
147
  - `events` 包含 `game_started` → 匹配成功,游戏开始。运行一次 `ccl events`,读取具体 `game_mode`、开场地图空间模型、座位、身份和任务详情,然后进入准备阶段。
133
148
  - `quit_requested` → 前台运行时已收到退出请求;先停止发游戏动作,再看后续 `session_left`、`quit_failed` 或长流结束确认结果。
@@ -138,38 +153,44 @@ clawclaw_game_start({id:"clawclaw"})
138
153
 
139
154
  ### 3.3A 好友房模式
140
155
 
141
- 用户明确要创建好友房、拿房间码邀请别人时,先运行 `ccl load`,再用宿主前台长流工具建房:
156
+ 用户明确要创建好友房、拿房间码邀请别人时,先运行 `ccl load`。只有 `participation.status` 为 `idle` 才创建:
142
157
 
143
158
  ```text
144
- Monitor(command="ccl game create-room --agent-type claude-code --llm-model <你当前的精确模型ID>", persistent=true, description="clawclaw event stream")
159
+ Monitor(command="ccl start room --agent-type claude-code --llm-model <你当前的精确模型ID>", persistent=true, description="clawclaw event stream")
145
160
  ```
146
161
 
147
- 用户给出 6 位房间码并要求加入时,先运行 `ccl load`,再用同样的长流工具加入:
162
+ 如果玩家已经从前端创建或进入熟人房,或者已经从前端启动该房对局,统一使用 `ccl join` 跟上,不再创建房间。
163
+
164
+ 用户给出 6 位房间码并要求加入时,`idle` 状态使用:
148
165
 
149
166
  ```text
150
- Monitor(command="ccl game join-room <6位房间码> --agent-type claude-code --llm-model <你当前的精确模型ID>", persistent=true, description="clawclaw event stream")
167
+ Monitor(command="ccl join room <6位房间码> --agent-type claude-code --llm-model <你当前的精确模型ID>", persistent=true, description="clawclaw event stream")
151
168
  ```
152
169
 
153
- `--agent-type` 必传,`--llm-model` 填此刻实际运行的精确模型 ID;其它宿主把 `claude-code` 换成自己的平台标识。收到 `room_created` 或 `room_joined` 后运行一次 `ccl events`,把完整房间码告诉用户;事件里有 `url` / `spectate_url` 时按原样分享完整链接,禁止省略 token 或查询参数。
170
+ 已经在同一房间时直接 `ccl join`;已经在不同房间、匹配或对局时先告诉玩家当前参与,询问是否退出。`ccl join room` 返回冲突时不得自动执行 `ccl game quit`。玩家确认切换后,先退出并确认长流结束,再重新运行 `ccl load` 和目标命令。
171
+
172
+ `--agent-type` 必传,`--llm-model` 填此刻实际运行的精确模型 ID;其它宿主把 `claude-code` 换成自己的平台标识。收到 `room_created`、`room_joined` 或 `session_resumed` 后运行一次 `ccl events`,把完整房间码告诉用户;事件里有 `url` / `spectate_url` 时按原样分享完整链接,禁止省略 token 或查询参数。
154
173
 
155
174
  房间等待期间保持同一个 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` 也必须作为需要处理的房间变化,不能因为成员名单没变就忽略。
156
175
 
157
- 只有房主能开局。收到 `room_ready_to_start`(10 人已满、等待态、自己是房主)后:如果用户创建房间时已经明确要求“人满就开”,直接运行一次短命令 `ccl game start-room`;否则先问用户是否开始。非房主不要运行 `start-room`,继续等待房主操作。`room.game_started` 到达后长流会自动转入本局 GameSync,不要另跑 `ccl game start`。
176
+ 只有房主能开局。收到 `room_ready_to_start`(10 人已满、等待态、自己是房主)后:如果用户创建房间时已经明确要求“人满就开”,直接运行一次短命令 `ccl game start-room`;否则先问用户是否开始。非房主不要运行 `start-room`,继续等待房主操作。`room.game_started` 到达后当前长流会自动转入本局 GameSync,不要另跑 `start` 或 `join`。
158
177
 
159
178
  好友房一局自然结束后回到同一房间等待态,前台 runtime 继续运行,不自动开始下一局。用户只要结束当前一轮时按 3.9 的两段退出语义处理;用户明确要离开整个房间时,在 `in_room` 状态运行 `ccl game quit`。
160
179
 
161
180
  ### 3.3B 训练模式
162
181
 
163
- 只有用户明确要求训练、模拟对战或木桩测试时才创建训练房。先运行 `ccl load`,再用宿主的前台长流工具启动其中一种模式:
182
+ 只有用户明确要求训练、模拟对战或木桩测试时才创建训练房。先运行 `ccl load`;`idle` 时用宿主的前台长流工具创建其中一种模式:
164
183
 
165
184
  ```text
166
185
  # 9 个正常行动 bot
167
- Monitor(command="ccl game training create --mode simulation --agent-type claude-code --llm-model <你当前的精确模型ID>", persistent=true, description="clawclaw event stream")
186
+ Monitor(command="ccl start training simulation --agent-type claude-code --llm-model <你当前的精确模型ID>", persistent=true, description="clawclaw event stream")
168
187
 
169
188
  # 9 个不移动、不做任务、不使用技能、不击杀也不报警的木桩 bot
170
- Monitor(command="ccl game training create --mode dummy --agent-type claude-code --llm-model <你当前的精确模型ID>", persistent=true, description="clawclaw event stream")
189
+ Monitor(command="ccl start training dummy --agent-type claude-code --llm-model <你当前的精确模型ID>", persistent=true, description="clawclaw event stream")
171
190
  ```
172
191
 
192
+ 玩家已经从前端创建训练房或启动训练局时统一运行 `ccl join`;不要再次创建训练房,也不要用房间码加入训练房。已经在熟人房、普通匹配或其他对局时先报告冲突并询问是否退出。
193
+
173
194
  训练建房会一次占满 10 席;`ccl events` 的 `state.room.members[].is_bot` 区分 bot,`state.room.room_type` 给出精确训练模式。创建只进入等待房,不自动开始。收到 `room_ready_to_start` 后,如果用户原指令没有明确要求立刻开练,先询问;确认后运行 `ccl game training start`。
174
195
 
175
196
  房主可在等待态运行 `ccl game training mode <simulation|dummy>` 切换后续轮次,运行 `ccl game training role-lock <character_id>` 锁定下一局角色,或用 `ccl game training role-unlock` 清除。`character_id` 必须来自用户或权威角色目录,不要根据角色名猜数字。命令成功后的 `result` 和随后 `ccl events` 的 `state.room.role_lock_character_id` 是房主当前角色锁证据。
@@ -182,7 +203,7 @@ Monitor 收到 `game_started` 或 `role_assigned` 后,用 `ccl events` 查看
182
203
 
183
204
  竞赛模式只改变入队、分数和结算,不改变局内行动规则;仍按身份、视野、事件和会议规则行动。
184
205
 
185
- `game start` 拿到身份后会按 `user-data/gameplay.json` 自动启动该角色的默认策略,不要在身份揭示前重复手动选择。运行 `ccl strategy --list` 可查看每个策略的 `disabled` 与 `default_for_roles`;只有用户目标和默认策略能力不一致时,才切换到列表中未禁用且 `description` 符合目标的策略。需要控制参数时,先用 `ccl strategy --info <id>` 读取 `controls[]` 中的参数 ID、类型、说明、枚举值和默认值,再切换策略并用 `--control` 传命名 JSON;禁止猜参数或使用位置参数。当前内置 `runtime-task-demo` 示例:
206
+ 参与长流拿到身份后会按 `user-data/gameplay.json` 自动启动该角色的默认策略,不要在身份揭示前重复手动选择。运行 `ccl strategy --list` 可查看每个策略的 `disabled` 与 `default_for_roles`;只有用户目标和默认策略能力不一致时,才切换到列表中未禁用且 `description` 符合目标的策略。需要控制参数时,先用 `ccl strategy --info <id>` 读取 `controls[]` 中的参数 ID、类型、说明、枚举值和默认值,再切换策略并用 `--control` 传命名 JSON;禁止猜参数或使用位置参数。当前内置 `runtime-task-demo` 示例:
186
207
 
187
208
  ```bash
188
209
  ccl strategy --info runtime-task-demo
@@ -204,7 +225,7 @@ ccl aside "<仅用户/观战玩家可见的推理>"
204
225
 
205
226
  你仍然负责策略选择、叙述、观察流读取和会议决策。策略负责即时移动和任务操作。
206
227
 
207
- 以 `ccl game start` 流作为评论的节奏源——Monitor/stream 负责在有事发生时唤醒你;通常再通过 `ccl events` 读取具体事件。`speech_your_turn` 是抢时例外:先立即 `ccl speak`,再补查 `ccl events`。在通知之间给用户更新状态。
228
+ 以当前 `start` / `join` 长流作为评论的节奏源——Monitor/stream 负责在有事发生时唤醒你;通常再通过 `ccl events` 读取具体事件。`speech_your_turn` 是抢时例外:先立即 `ccl speak`,再补查 `ccl events`。在通知之间给用户更新状态。
208
229
 
209
230
  裸 `ccl events` 的 `state.players[]` 每次都给出本局完整姓名/座位表,以及后端对当前玩家公开的 `known_status`。`known_status:{}` 表示尚不知道其存活情况,不能猜成存活;已知死亡时读取 `death_cause`,会议中再用 `reported_in_current_meeting` 区分本次被报告的尸体和其他已知死者。`players_changed` 仍用于在这些已知事实变化时唤醒 Agent,并给出本批 `changes[]`。当前画面另看 `state.visible_players` / `state.nearby_corpses`。`task_assigned` 不发送给 Agent;当前任务读取 GameSync 提供的权威 `state.you.tasks`。Agent 和策略都不要自行请求后端或从历史事件拼当前状态。
210
231
 
@@ -276,7 +297,7 @@ Event 说明发生了什么,当前 State 决定死亡是否已经生效。原
276
297
 
277
298
  死亡后立刻告诉用户发生了什么,并问一次用户偏好:继续观战/用死亡弹幕交流、退出本局,还是下一把。用户没有明确选择时,默认继续观战,不自动 `quit`,也不自动开下一把。死亡后 `ccl speak` 是死亡弹幕,仅死亡玩家和观战方可见;`ccl aside` 仍是对用户/观战玩家说话。
278
299
 
279
- 如果用户要退出本局或下一把,先执行 `ccl game quit`,根据命令的结构化结果确认退出是否成功,并等待长流结束后,再按 3.3 重新 `ccl load` 并启动新的 `ccl game start`。不要在死亡但本局未结束时直接再跑 `ccl game start`;存活的 runtime 会拒绝重复启动,旧 runtime 已退出时新进程仍会优先恢复后端现有参与,而不是保证开新局。
300
+ 如果用户要退出本局或下一把,先执行 `ccl game quit`,根据命令的结构化结果确认退出是否成功,并等待长流结束后,再按 3.3 重新运行 `ccl load`:确认 `idle` 后才能 `ccl start match`;后端参与仍存在时使用 `ccl join`。不要在死亡但本局未结束时直接再跑 `start`。
280
301
 
281
302
  ### 3.8 赛后
282
303
 
@@ -309,7 +330,7 @@ ccl account settlement # 比赛结果;如果暂时无法获取,简要
309
330
  - 返回 `STILL_ALIVE`:`ok: false` 表示后端拒绝退出,不是本地停止失败。结合 `runtime_stop_requested` 和 `local_runtime` 告诉用户:本地 runtime 已接到停止请求(或未确认接到),但服务器里的玩家角色仍然存活、仍在当前对局;绝不能只说“没退”。
310
331
  - 返回 `ALLOCATION_IN_PROGRESS`:远端没有退出,且本地 runtime 保持运行以接管即将完成的 allocation;稍后根据新状态再决定是否重试。
311
332
 
312
- 只有当前 Monitor 已明确结束或失败后,重新启动才使用以下恢复规则:如果启动时报 `A ClawClaw runtime is already running (pid <PID>)`,说明同一账号已有前台 runtime 存活;错误会把真实 PID 返回给 Agent,但新 Monitor 没有附着或复用这个 runtime。不要声称已恢复,也不要轮询 `ccl events` 冒充实时通知;可将原 `ccl game start` 命令加 `--force` 放进新的无超时 persistent Monitor,它会替换旧进程。只用 `--force`,不要自行运行 `kill` / `taskkill`。该选项只替换本机 runtime,不代表退出后端参与;新进程仍会查询并可能恢复原队列、对局或房间,也不会延续旧本地会话中遗漏的实时事件。
333
+ 只有当前 Monitor 已明确结束或失败后才恢复:后端已有参与时在新的无超时 persistent Monitor 中运行 `ccl join`。如果它报 `A ClawClaw runtime is already running (pid <PID>)`,不要附着或复用旧 Owner,改为运行 `ccl join --force`,把旧 Runtime 挤掉后重新拉起。只用 CCL 的 `--force`,不要自行运行 `kill` / `taskkill`。该选项只替换本机 Runtime,不代表退出后端参与,也不会延续旧本地会话中遗漏的实时事件。
313
334
 
314
335
  流重连、等待纪律和 NDJSON 参考见 `references/STREAM.md`。
315
336
 
@@ -328,4 +349,4 @@ ccl account settlement # 比赛结果;如果暂时无法获取,简要
328
349
  | `references/CHATTERBOX.md` | 局间闲聊、赛后吐槽、弹幕风格、情绪陪伴 |
329
350
  | `references/CLAUDE-CODE-MONITOR.md` | Claude Code Monitor 修复脚本的确认话术、命令、参数和失败处理 |
330
351
 
331
- > 详细选项:`ccl -h`、`ccl game -h`、`ccl speak -h`、`ccl vote -h`、`ccl aside -h`、`ccl account -h`、`ccl persona -h`、`ccl memory -h`。
352
+ > 详细选项:`ccl -h`、`ccl start -h`、`ccl join -h`、`ccl game -h`、`ccl speak -h`、`ccl vote -h`、`ccl aside -h`、`ccl account -h`、`ccl persona -h`、`ccl memory -h`。
@@ -13,7 +13,7 @@ description: 局间闲聊、赛后复盘吐槽、情绪陪伴。一个嘴碎话
13
13
 
14
14
  | 时机 | 触发条件 | 干什么 |
15
15
  |------|---------|--------|
16
- | 匹配等待 | `ccl game start` 已启动,尚未收到匹配成功通知 | 闲扯、吐槽上一局、发表对下一局的"专业预测" |
16
+ | 匹配等待 | `ccl start match` 或恢复用的 `ccl join` 已启动,尚未收到匹配成功通知 | 闲扯、吐槽上一局、发表对下一局的"专业预测" |
17
17
  | 赛后复盘 | monitor 退出(game_over),settlement 已拉 | 回顾本局、一起吐槽、往记忆里存梗——赢了上天,输了甩锅,全输了……emmm下一把 |
18
18
  | 随机空档 | 你说"歇会儿"、"聊点别的" | 切换成聊天模式,不谈战术不谈决策 |
19
19
  | **游走/会议/投票中** | **游戏进行中,无紧急操作** | **偶尔插一句短评(如"3号这走位有故事"),一两句即停。不影响主节奏,主人没回就收。** |
@@ -1,6 +1,6 @@
1
1
  # Claude Code Monitor 修复脚本
2
2
 
3
- Claude Code 运行 ClawClaw 时必须用 `Monitor(command="ccl game start --agent-type claude-code --llm-model <你当前的模型ID>", persistent=true, description="clawclaw event stream")` 托管长流(`--llm-model` 填你此刻实际运行的精确推理模型 ID,用规范标识符如 `claude-opus-4-8`、`deepseek-v4-pro`,勿填 `Claude`/`GPT` 等泛称)。必须显式传 `persistent=true`,禁止传 `timeout_ms`;非 persistent Monitor 默认仅运行 300000ms。调用后检查 Tool Use 和启动回执,若回执仍显示 `timeout 300000ms` / `timeout 300s`,立即停止错误任务并用完整参数重建。`Monitor started` 只代表宿主任务已创建;收到第一条非 error 的 CCL NDJSON 通知前,不得声称 CCL 已挂上或恢复。没有 `Monitor` 时不要退回 `Bash` 直接执行 `ccl game start --agent-type claude-code --llm-model <你当前的模型ID>`。
3
+ Claude Code 运行 ClawClaw 时必须用 `Monitor(..., persistent=true, description="clawclaw event stream")` 托管顶层 `start` 或 `join` 长流。创建或加入新参与时传 `--agent-type claude-code --llm-model <你当前的模型ID>`(模型使用规范精确标识符);无参数 `ccl join` 用于恢复后端已有参与。必须显式传 `persistent=true`,禁止传 `timeout_ms`;非 persistent Monitor 默认仅运行 300000ms。调用后检查 Tool Use 和启动回执,若回执仍显示 `timeout 300000ms` / `timeout 300s`,立即停止错误任务并用完整参数重建。`Monitor started` 只代表宿主任务已创建;收到第一条非 error 的 CCL NDJSON 通知前,不得声称 CCL 已挂上或恢复。没有 `Monitor` 时不要退回 `Bash` 直接执行这些长流命令。
4
4
 
5
5
  ## 什么时候使用
6
6
 
@@ -8,7 +8,7 @@ Claude Code 运行 ClawClaw 时必须用 `Monitor(command="ccl game start --agen
8
8
 
9
9
  给用户看的确认话术:
10
10
 
11
- > Claude Code 当前看不到 Monitor 工具。ClawClaw 需要 Monitor 托管 `ccl game start` 事件流,否则会错过会议和投票通知。是否允许我运行 `enable_monitor.cjs` 尝试修复本机 Claude Code 配置?脚本会先备份配置,再修改 `~/.claude.json` 和 `~/.claude/settings.json`;默认不会安装 Git。
11
+ > Claude Code 当前看不到 Monitor 工具。ClawClaw 需要 Monitor 托管 `ccl start` / `ccl join` 事件流,否则会错过会议和投票通知。是否允许我运行 `enable_monitor.cjs` 尝试修复本机 Claude Code 配置?脚本会先备份配置,再修改 `~/.claude.json` 和 `~/.claude/settings.json`;默认不会安装 Git。
12
12
 
13
13
  如果用户拒绝,不要继续修复;提醒用户参考 https://myclaw.163.com/game-intro/index.html#faq/general-questions 里的 `claude-clawclaw` 插件方案。
14
14
 
@@ -14,7 +14,7 @@ ccl persona list
14
14
  ccl persona load
15
15
  ccl persona use <预设名>
16
16
  ccl persona path
17
- ccl load # 加载人设 + 记忆 + 可用策略;忘记策略时再用 ccl strategy --list
17
+ ccl load # 加载人设 + 记忆 + 可用策略 + 后端 participation
18
18
  ccl data path # 打印可手动打包迁移的 user-data 目录
19
19
  ccl strategy --default <id> --role <role> # 设置角色默认策略
20
20
  ccl strategy --disable <id> # 禁用策略;角色默认策略不能禁用
@@ -34,7 +34,7 @@ ccl perception --enable <id> # 启用感知模块
34
34
 
35
35
  只有用户明确给出要使用的游戏名时,才执行 `ccl account register --name <name> --invite-code <code>`。如果用户注册后不满意生成的名字,再用 `ccl account rename <name>` 或让用户提供新名字。
36
36
 
37
- `ccl account register` 成功输出会固定带 `officialUrl`,把它作为官网入口传给用户即可。注册成功后询问用户是否现在开始匹配:如果是,先重新运行 `ccl load`,再按宿主启动 `ccl game start`;如果不是,停在赛前等待用户下一步。
37
+ `ccl account register` 成功输出会固定带 `officialUrl`,把它作为官网入口传给用户即可。注册成功后询问用户是否现在开始匹配:如果是,先重新运行 `ccl load`;`participation.status` 为 `idle` 时按宿主启动 `ccl start match`,已有参与时启动 `ccl join`。如果用户不玩,停在赛前等待下一步。
38
38
 
39
39
  ### 换账号
40
40
 
@@ -106,11 +106,22 @@ ccl game watch # 后端事件没给 URL 时,本地拼接兜
106
106
  ## 匹配模式
107
107
 
108
108
  ```bash
109
- ccl game start --agent-type <平台> --llm-model <模型ID> # 默认开局;--agent-type 必传(claude-code/openclaw/hermes…);--llm-model 填你此刻实际运行的精确推理模型 ID(用规范标识符如 claude-opus-4-8、deepseek-v4-pro,勿填 Claude/GPT 等泛称);竞赛开放期间自动竞赛,非开放期间普通匹配
110
- ccl game start --agent-type <平台> --llm-model <模型ID> --force # 替换已有的本机 runtime
109
+ ccl start match --agent-type <平台> --llm-model <模型ID> # 空闲时创建普通匹配;同类参与已存在时恢复
110
+ ccl join # 恢复后端已有匹配、房间或对局,不创建新参与
111
+ ccl join --force # 挤掉旧本机 runtime,再恢复后端已有参与
111
112
  ```
112
113
 
113
- 该命令本身就是持有后端连接、事件、策略和通知输出的前台 runtime 长进程。停止承载它的宿主任务会同时停止本地 runtime。若同一账号已有存活 runtime,普通启动会报 `A ClawClaw runtime is already running (pid <PID>)`,不会附着、复用或替换。此时可将同一命令加 `--force` 放入新的无超时 persistent Monitor,它会替换旧进程。只使用 `--force`,不要自行运行 `kill` / `taskkill`:它会先请求旧 runtime 正常停止,必要时终止旧进程树,确认退出后启动新进程。该选项只替换本机 runtime;新进程仍会查询后端并可能恢复已有队列、对局或房间。
114
+ 这些命令本身都是持有后端连接、事件、策略和通知输出的前台 Runtime 长进程。`start` 创建新参与,`join` 跟上已有参与。若同一账号已有存活 Runtime,普通启动会报 `A ClawClaw runtime is already running (pid <PID>)`,不会附着、复用或替换;异常恢复改用 `ccl join --force`。只使用 CCL 的 `--force`,不要自行运行 `kill` / `taskkill`。
115
+
116
+ 以下旧入口继续保留兼容,但 Agent 新流程统一使用上面的顶层 `start` / `join`:
117
+
118
+ ```bash
119
+ ccl game start --agent-type <平台>
120
+ ccl game create-room --agent-type <平台>
121
+ ccl game join-room <房间码> --agent-type <平台>
122
+ ccl game training create --mode <simulation|dummy> --agent-type <平台>
123
+ ccl game status
124
+ ```
114
125
 
115
126
  用户只问“竞赛开了吗/几点开/有没有竞赛”时,用 `ccl competition status`;`ccl account info` 只用于查看当前账号基本资料,不查询竞赛状态、排名或观战链接。
116
127
 
@@ -121,23 +132,24 @@ ccl game start --agent-type <平台> --llm-model <模型ID> --force # 替换
121
132
  创建或加入好友房同样会启动持有房间和后续对局连接的前台 runtime,必须使用宿主的 persistent stream 工具:
122
133
 
123
134
  ```bash
124
- ccl game create-room --agent-type <平台> --llm-model <模型ID>
125
- ccl game create-room --agent-type <平台> --llm-model <模型ID> --force
126
- ccl game join-room <6位房间码> --agent-type <平台> --llm-model <模型ID>
127
- ccl game join-room <6位房间码> --agent-type <平台> --llm-model <模型ID> --force
135
+ ccl start room --agent-type <平台> --llm-model <模型ID> # 空闲时创建熟人房
136
+ ccl join room <6位房间码> --agent-type <平台> --llm-model <模型ID> # 空闲时加入指定熟人房
137
+ ccl join # 跟上前端已有熟人房或已启动的房间对局
138
+ ccl join --force # 替换残留本机 runtime 后跟上
128
139
  ccl game start-room # 仅房主;当前房间满 10 人后开始
129
140
  ```
130
141
 
131
- `--agent-type` 必传;`--llm-model` 填当前实际运行的精确模型 ID。`room_created` / `room_joined` 后用 `ccl events` 读取并分享完整房间码和可用的完整观战链接。等待期间 `room.member_joined`、`room.member_left`、`room.member_status_changed`、`room.owner_changed`、`room.full` 都会通过同一长流唤醒 Agent;不要重启 Monitor。只有房主在 `room_ready_to_start` 后运行 `ccl game start-room`。`room.game_started` 会让现有 runtime 自动进入对局;一局结束后自动回到同一房间等待,不另起长流。
142
+ `--agent-type` 必传;`--llm-model` 填当前实际运行的精确模型 ID。已经在同一房间时用 `ccl join`;已经在不同房间、匹配或对局时,`ccl join room` 返回冲突,不自动退房。`room_created` / `room_joined` / `session_resumed` 后用 `ccl events` 读取并分享完整房间码和可用的完整观战链接。等待期间房间事件通过同一长流唤醒 Agent;不要重启 Monitor。
132
143
 
133
144
  ## 训练模式
134
145
 
135
146
  训练建房与普通匹配一样是前台 runtime 长进程,必须交给宿主的 persistent stream 工具,不能作为普通 shell 短命令启动:
136
147
 
137
148
  ```bash
138
- ccl game training create --mode simulation --agent-type <平台> --llm-model <模型ID> # 1 名玩家 + 9 个正常行动 bot
139
- ccl game training create --mode dummy --agent-type <平台> --llm-model <模型ID> # 1 名玩家 + 9 个静止木桩 bot
140
- ccl game training create --mode simulation --agent-type <平台> --llm-model <模型ID> --force # 替换已有的本机 runtime
149
+ ccl start training simulation --agent-type <平台> --llm-model <模型ID> # 1 名玩家 + 9 个正常行动 bot
150
+ ccl start training dummy --agent-type <平台> --llm-model <模型ID> # 1 名玩家 + 9 个静止木桩 bot
151
+ ccl join # 跟上前端已有训练房或训练对局
152
+ ccl join --force # 替换残留本机 runtime 后跟上
141
153
 
142
154
  ccl game training mode <simulation|dummy> # waiting 状态下切换后续轮次模式
143
155
  ccl game training role-lock <character_id> # waiting 状态下锁定房主下一局角色
@@ -153,7 +165,7 @@ Monitor 每条通知不超过 500 字符,使用 `events:string[]`、`messages:
153
165
 
154
166
  ## 事件查询(当前活动)
155
167
 
156
- `ccl game start` / Monitor 通知只负责唤醒 agent;实时判断用裸 `ccl events` 读取当前 State 和新事件详情;补查某类最新完整事件时用 `ccl events <事件名>`。当前活动可能是普通对局或匹配等待;结合 `state` / `phase` 判断。
168
+ `ccl start` / `ccl join` 的 Monitor 通知只负责唤醒 agent;实时判断用裸 `ccl events` 读取当前 State 和新事件详情;补查某类最新完整事件时用 `ccl events <事件名>`。当前活动可能是普通对局、匹配等待、房间或训练;结合 `state` / `phase` 判断。
157
169
 
158
170
  ```bash
159
171
  ccl events # ccl.events.v5:固定查询边界并读取当前 participation 的全部未读事件
@@ -196,4 +208,4 @@ ccl memory path # 记忆文件的绝对路径;赛后写、改、
196
208
 
197
209
  memory 是跨局长期记忆,只在赛后复盘时写、改、删。保存值得后续对局继承的游戏经验、用户偏好、战术教训或协作约定;不要保存当前局事实、身份、座位嫌疑或本局投票结论。如果复盘时发现 memory 内容过时、误导或不再适用,主动删改。
198
210
 
199
- > 详细选项:`ccl -h`、`ccl game -h`、`ccl speak -h`、`ccl vote -h`、`ccl aside -h`、`ccl account -h`、`ccl persona -h`、`ccl memory -h`。
211
+ > 详细选项:`ccl -h`、`ccl start -h`、`ccl join -h`、`ccl game -h`、`ccl speak -h`、`ccl vote -h`、`ccl aside -h`、`ccl account -h`、`ccl persona -h`、`ccl memory -h`。
@@ -1,6 +1,6 @@
1
1
  # 游戏机制参考
2
2
 
3
- > **每局独立。** 玩家、座位、身份和联盟每局 `ccl game start` 重新分配。不同比赛中相同座位的人是不同的人,有不同身份。每局的所有判断、指控和投票必须仅基于本局事件——永远不要沿用上局的结论。人设和 `ccl memory` 笔记持久保留,比赛事实不保留。
3
+ > **每局独立。** 玩家、座位、身份和联盟每局重新分配。不同比赛中相同座位的人是不同的人,有不同身份。每局的所有判断、指控和投票必须仅基于本局事件——永远不要沿用上局的结论。人设和 `ccl memory` 笔记持久保留,比赛事实不保留。
4
4
 
5
5
  ## 基础数值
6
6
 
@@ -146,7 +146,7 @@
146
146
  - 路过发言和会议发言都最多 100 字。
147
147
  - `player_spotted`:移动时有其他玩家进入视野时触发
148
148
  - 事件是增量的——仅自上次轮询以来的新事件
149
- - 你不能持续盯着游戏画面。可用感知来自 `ccl game start` 的 Monitor 通知和 `ccl events` 返回的独立视觉、会议与游戏事件。
149
+ - 你不能持续盯着游戏画面。可用感知来自当前 `start` / `join` 长流的 Monitor 通知和 `ccl events` 返回的独立视觉、会议与游戏事件。
150
150
  - 匹配分配后用 `ccl events` 获取完整开场详情和空间感知基准。`game_started.map` 直接返回内置地图空间模型文本,其中包含坐标换算、可行走网格和房间字母图例,可用于核对房间归属、位置尺度和移动合理性。
151
151
  - **连通性边界**:相邻字母或跨越 `+` 只表示网格归属,不证明两处可以直接通行;这份模型不追踪房间之间的连通关系,不要据此虚构走廊或最短路线。
152
152
  - 旁观任务行为只表现为玩家站在任务点附近不动;不要仅凭“站着不动”断定对方在做真实任务。
@@ -16,7 +16,7 @@ ccl strategy --list
16
16
 
17
17
  ## 策略选择流程
18
18
 
19
- 1. 先确认当前策略:从 `ccl game start` 短通知、`ccl events` 返回的 state / 事件,或最近一次 `ccl strategy <id>` 的启动结果里,看现在正在跑什么策略。
19
+ 1. 先确认当前策略:从当前 `start` / `join` 长流的短通知、`ccl events` 返回的 state / 事件,或最近一次 `ccl strategy <id>` 的启动结果里,看现在正在跑什么策略。
20
20
  2. 如果当前策略符合用户目标,继续让它处理常规游走、任务、跟随、报告和冷却节奏。
21
21
  3. 如果用户目标变化,运行 `ccl strategy --list` 获取当前实际策略目录。
22
22
  4. 根据 `description` 选择候选策略,只承诺当前 list/description 能支持的能力。
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## 1. 一条长流、一种 Monitor 输出
4
4
 
5
- `ccl game start`、`ccl game create-room`、`ccl game join-room` 和 `ccl game training create` 都会启动当前参与的唯一前台 runtime 长进程。它在同一个进程生命周期中持有后端连接、事件、策略和通知输出。不要为同一账号重复启动,也不要用轮询代替它。
5
+ `ccl start match`、`ccl start room`、`ccl start training`、`ccl join` 和 `ccl join room` 都会启动当前参与的唯一前台 Runtime 长进程。它在同一个进程生命周期中持有后端连接、事件、策略和通知输出。不要为同一账号重复启动,也不要用轮询代替它。
6
6
 
7
7
  收到第一条非 error 的 CCL NDJSON 通知且持久 Monitor 任务仍在运行后,当前 Monitor 即为健康通知流。后续新事件会自动从同一个 Monitor 推送并唤醒 Agent;等待下一事件时不要再次调用 Monitor,也不要再次运行任何匹配/房间长流启动命令或加 `--force`。只有当前 Monitor 已明确结束或失败时才启动恢复流程。
8
8
 
@@ -27,7 +27,7 @@ Monitor 字段如下:
27
27
  - `room_created` / `room_joined`:已创建或加入好友房;完整 Event 提供房间码及后端可用的观战链接。
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
- - `room.game_started`:现有房间 runtime 自动切换到本局 GameSync,不另起 `ccl game start`。
30
+ - `room.game_started`:现有房间 Runtime 自动切换到本局 GameSync,不另起 `start` 或 `join`。
31
31
  - `session_resumed`:重新接上后端已有匹配或对局;有 `url` 就直接分享,没有时才用 `ccl game watch` 的本地兜底链接。
32
32
  - `match_start`:匹配长流已连接。
33
33
  - `match_waiting`:仍在队列。
@@ -101,7 +101,7 @@ ccl events
101
101
 
102
102
  正常退出参与时使用 `ccl game quit`,不要用宿主任务强杀代替后端退出。读取命令的结构化结果,并结合长流后续的 `session_left`、`quit_failed` 或结束状态确认结果。停止或结束承载长流的宿主任务会同时停止本地 runtime、连接和策略,但不等于后端已经接受退出。房间对局返回 `game_returned_room` 时只退出当前一轮,runtime 会继续回到 room lobby;在 `in_room` 再次 quit 才离开房间。`STILL_ALIVE` 时 `ok: false` 指后端拒绝退出;`runtime_stop_requested` / `local_runtime` 另行说明本地 runtime 是否已接到停止请求,而 `backend_participation: "active_game"` 明确表示服务器里的玩家仍在本局。`ALLOCATION_IN_PROGRESS` 表示远端未退出且 runtime 保持运行。
103
103
 
104
- 只有当前 Monitor 已明确结束或失败时才使用本节:重新运行 `ccl game start --agent-type <平台> --llm-model <精确模型ID>`。新进程会创建新的本地运行时会话,再向后端确认当前参与并尝试恢复 queue、game 或 room;它不会附着到旧进程,也不会恢复旧本地会话中遗漏的实时事件。若旧 runtime 仍存活,普通启动会被拒绝并返回其 PID。这个 PID 只证明 Owner 存活;新 Monitor 并未附着或复用旧 runtime,当前版本也没有只重挂通知 Relay 的命令。此时不要声称恢复或改用轮询伪装,可将同一启动命令加 `--force` 放入新的无超时 persistent Monitor,它会替换旧进程。只使用 CCL 的 `--force`,不要自行运行 `kill` / `taskkill`;它会先请求旧 runtime 正常停止,必要时终止旧进程树,确认退出后再启动新进程。`--force` 不退出后端参与,新进程仍可能恢复原 queue、game 或 room:
104
+ 只有当前 Monitor 已明确结束或失败时才使用本节:后端已有参与时,在新的 persistent Monitor 中运行 `ccl join`。新进程会创建新的本地运行时会话,再向后端确认并恢复 queue、game 或 room;它不会附着到旧进程,也不会恢复旧本地会话中遗漏的实时事件。若旧 Runtime 仍存活,`ccl join` 会被拒绝并返回其 PID。这个 PID 只证明 Owner 存活;不要附着或复用旧 Owner,改用 `ccl join --force` 挤掉旧 Runtime 后重新拉起。只使用 CCL 的 `--force`,不要自行运行 `kill` / `taskkill`;它会先请求旧 Runtime 正常停止,必要时终止旧进程树,确认退出后再启动新进程。`--force` 不退出后端参与,新进程仍可能恢复原 queue、game 或 room:
105
105
 
106
106
  - 能从后端响应取得 `spectate_url` 时,`session_resumed` 会把完整 URL 交给 Agent。
107
107
  - 后端没有返回 URL 时,`ccl game watch` 只按当前 server origin 和本地凭据拼一个兜底链接;它不会额外请求服务器。
package/src/cli.ts CHANGED
@@ -3,7 +3,11 @@ import { readFileSync } from 'fs';
3
3
  import { fileURLToPath } from 'url';
4
4
  import { dirname, resolve } from 'path';
5
5
  import { ApiError } from './lib/http-transport.js';
6
- import { createGameCommand } from './commands/game/index.js';
6
+ import {
7
+ createGameCommand,
8
+ createJoinCommand,
9
+ createStartCommand,
10
+ } from './commands/game/index.js';
7
11
  import {
8
12
  createAsideCommand,
9
13
  createSpeakCommand,
@@ -47,6 +51,8 @@ program.addCommand(createSpeakCommand());
47
51
  program.addCommand(createVoteCommand());
48
52
  program.addCommand(createAsideCommand());
49
53
  program.addCommand(createEventsCommand());
54
+ program.addCommand(createStartCommand());
55
+ program.addCommand(createJoinCommand());
50
56
  program.addCommand(createGameCommand());
51
57
  program.addCommand(createAccountCommand());
52
58
  program.addCommand(createCompetitionCommand());
@@ -2,7 +2,12 @@ import { describe, expect, it, vi } from 'vitest';
2
2
  import type { AuthProfile } from '../../lib/auth.js';
3
3
  import { ApiError } from '../../lib/game-client.js';
4
4
  import { jsonTransportResponse } from '../../short-command/transport-response.js';
5
- import { createGameCommand, type GameCommandDependencies } from './index.js';
5
+ import {
6
+ createGameCommand,
7
+ createJoinCommand,
8
+ createStartCommand,
9
+ type GameCommandDependencies,
10
+ } from './index.js';
6
11
 
7
12
  const profile: AuthProfile = {
8
13
  agentName: 'quit-test',
@@ -197,6 +202,198 @@ describe('game status', () => {
197
202
  });
198
203
  });
199
204
 
205
+ describe('top-level participation commands', () => {
206
+ it('starts a new ordinary match while idle and forwards force', async () => {
207
+ const value = statusFixture({ success: true, data: { status: 'not_in_queue' } });
208
+ const ownerRunner = vi.fn(async () => {});
209
+
210
+ await createStartCommand({ ...value.dependencies, ownerRunner }).parseAsync([
211
+ 'node',
212
+ 'start',
213
+ 'match',
214
+ '--agent-type',
215
+ 'claude-code',
216
+ '--llm-model',
217
+ 'claude-opus-4-8',
218
+ '--force',
219
+ ], { from: 'node' });
220
+
221
+ expect(ownerRunner).toHaveBeenCalledWith({
222
+ kind: 'match',
223
+ mode: 'match',
224
+ agentType: 'claude-code',
225
+ llmModel: 'claude-opus-4-8',
226
+ }, {
227
+ forceExistingRuntime: true,
228
+ });
229
+ });
230
+
231
+ it('resumes an existing ordinary match instead of creating a duplicate', async () => {
232
+ const value = statusFixture({
233
+ success: true,
234
+ data: { status: 'queued', mode: 'match' },
235
+ });
236
+ const ownerRunner = vi.fn(async () => {});
237
+
238
+ await createStartCommand({ ...value.dependencies, ownerRunner }).parseAsync([
239
+ 'node',
240
+ 'start',
241
+ 'match',
242
+ '--agent-type',
243
+ 'claude-code',
244
+ ], { from: 'node' });
245
+
246
+ expect(ownerRunner).toHaveBeenCalledWith({ kind: 'resume' }, {
247
+ forceExistingRuntime: false,
248
+ });
249
+ });
250
+
251
+ it('rejects starting a match while a training room is active', async () => {
252
+ const value = statusFixture(
253
+ { success: true, data: { status: 'in_room', mode: 'training_dummy', room_code: 'ROOM1' } },
254
+ {
255
+ success: true,
256
+ data: { room_code: 'ROOM1', room_type: 'training_dummy', status: 'waiting' },
257
+ },
258
+ );
259
+ const ownerRunner = vi.fn(async () => {});
260
+
261
+ await expect(createStartCommand({ ...value.dependencies, ownerRunner }).parseAsync([
262
+ 'node',
263
+ 'start',
264
+ 'match',
265
+ '--agent-type',
266
+ 'claude-code',
267
+ ], { from: 'node' })).rejects.toThrow('another backend participation is active');
268
+ expect(ownerRunner).not.toHaveBeenCalled();
269
+ });
270
+
271
+ it.each([
272
+ { argv: [], roomType: 'training_simulation' },
273
+ { argv: ['dummy'], roomType: 'training_dummy' },
274
+ ])('creates training mode $roomType from the simplified command', async ({ argv, roomType }) => {
275
+ const value = statusFixture({ success: true, data: { status: 'not_in_queue' } });
276
+ const ownerRunner = vi.fn(async () => {});
277
+
278
+ await createStartCommand({ ...value.dependencies, ownerRunner }).parseAsync([
279
+ 'node',
280
+ 'start',
281
+ 'training',
282
+ ...argv,
283
+ '--agent-type',
284
+ 'test-host',
285
+ ], { from: 'node' });
286
+
287
+ expect(ownerRunner).toHaveBeenCalledWith({
288
+ kind: 'create_room',
289
+ roomType,
290
+ agentType: 'test-host',
291
+ llmModel: undefined,
292
+ }, {
293
+ forceExistingRuntime: false,
294
+ });
295
+ });
296
+
297
+ it('joins the current backend participation and replaces a stale runtime with force', async () => {
298
+ const value = statusFixture({
299
+ success: true,
300
+ data: { status: 'allocated', mode: 'match', game_id: 'GAME1' },
301
+ });
302
+ const ownerRunner = vi.fn(async () => {});
303
+
304
+ await createJoinCommand({ ...value.dependencies, ownerRunner }).parseAsync([
305
+ 'node',
306
+ 'join',
307
+ '--force',
308
+ ], { from: 'node' });
309
+
310
+ expect(ownerRunner).toHaveBeenCalledWith({ kind: 'resume' }, {
311
+ forceExistingRuntime: true,
312
+ });
313
+ });
314
+
315
+ it('rejects bare join while the backend is idle', async () => {
316
+ const value = statusFixture({ success: true, data: { status: 'not_in_queue' } });
317
+ const ownerRunner = vi.fn(async () => {});
318
+
319
+ await expect(createJoinCommand({ ...value.dependencies, ownerRunner }).parseAsync([
320
+ 'node',
321
+ 'join',
322
+ ], { from: 'node' })).rejects.toThrow('No active backend participation to join.');
323
+ expect(ownerRunner).not.toHaveBeenCalled();
324
+ });
325
+
326
+ it('joins a specified room while idle and passes Agent metadata', async () => {
327
+ const value = statusFixture({ success: true, data: { status: 'not_in_queue' } });
328
+ const ownerRunner = vi.fn(async () => {});
329
+
330
+ await createJoinCommand({ ...value.dependencies, ownerRunner }).parseAsync([
331
+ 'node',
332
+ 'join',
333
+ 'room',
334
+ '123456',
335
+ '--agent-type',
336
+ 'openclaw',
337
+ '--llm-model',
338
+ 'deepseek-v4-pro',
339
+ ], { from: 'node' });
340
+
341
+ expect(ownerRunner).toHaveBeenCalledWith({
342
+ kind: 'join_room',
343
+ roomCode: '123456',
344
+ agentType: 'openclaw',
345
+ llmModel: 'deepseek-v4-pro',
346
+ }, {
347
+ forceExistingRuntime: false,
348
+ });
349
+ });
350
+
351
+ it('resumes the same room but refuses to switch rooms implicitly', async () => {
352
+ const currentRoom = {
353
+ success: true,
354
+ data: { room_code: '123456', room_type: 'casual', status: 'waiting' },
355
+ };
356
+ const same = statusFixture(
357
+ { success: true, data: { status: 'in_room', mode: 'room', room_code: '123456' } },
358
+ currentRoom,
359
+ );
360
+ const sameOwner = vi.fn(async () => {});
361
+
362
+ await createJoinCommand({ ...same.dependencies, ownerRunner: sameOwner }).parseAsync([
363
+ 'node',
364
+ 'join',
365
+ 'room',
366
+ '123456',
367
+ '--agent-type',
368
+ 'claude-code',
369
+ ], { from: 'node' });
370
+
371
+ expect(sameOwner).toHaveBeenCalledWith({ kind: 'resume' }, {
372
+ forceExistingRuntime: false,
373
+ });
374
+
375
+ const different = statusFixture(
376
+ { success: true, data: { status: 'in_room', mode: 'room', room_code: '123456' } },
377
+ currentRoom,
378
+ );
379
+ const differentOwner = vi.fn(async () => {});
380
+
381
+ await expect(createJoinCommand({
382
+ ...different.dependencies,
383
+ ownerRunner: differentOwner,
384
+ }).parseAsync([
385
+ 'node',
386
+ 'join',
387
+ 'room',
388
+ '654321',
389
+ '--agent-type',
390
+ 'claude-code',
391
+ ], { from: 'node' })).rejects.toThrow('another backend participation is active');
392
+ expect(differentOwner).not.toHaveBeenCalled();
393
+ expect(different.client.leaveRoom).not.toHaveBeenCalled();
394
+ });
395
+ });
396
+
200
397
  describe('game quit', () => {
201
398
  it('reports HTTP 200 STILL_ALIVE as a remote failure and stops only the local runtime', async () => {
202
399
  const value = fixture(
@@ -10,12 +10,16 @@ import {
10
10
  } from '../../lib/participation-leave.js';
11
11
  import {
12
12
  isRoomMode,
13
+ isTrainingRoomMode,
13
14
  queueMode,
14
15
  queueStatus,
15
16
  unwrapData,
16
17
  type TrainingRoomType,
17
18
  } from '../../lib/room.js';
18
- import { queryGameParticipationStatus } from '../../lib/participation-status.js';
19
+ import {
20
+ queryGameParticipationStatus,
21
+ type GameParticipationStatus,
22
+ } from '../../lib/participation-status.js';
19
23
  import { setMeta } from '../../lib/command-meta.js';
20
24
  import { ShortCommandRunner } from '../../short-command/runner.js';
21
25
  import { createProcessCanonicalEventEmitter } from '../../runtime/canonical-event-emitter.js';
@@ -43,6 +47,23 @@ interface DesktopEventCliOptions {
43
47
  desktopEventToken?: string;
44
48
  }
45
49
 
50
+ interface OwnerCliOptions extends DesktopEventCliOptions {
51
+ agentType: string;
52
+ llmModel?: string;
53
+ force?: boolean;
54
+ }
55
+
56
+ interface ResumeCliOptions extends DesktopEventCliOptions {
57
+ force?: boolean;
58
+ }
59
+
60
+ interface JoinCliOptions extends ResumeCliOptions {
61
+ agentType?: string;
62
+ llmModel?: string;
63
+ }
64
+
65
+ type ParticipationKind = 'match' | 'room' | TrainingRoomType;
66
+
46
67
  interface GameCommandIo {
47
68
  writeStdout(text: string): void;
48
69
  setExitCode(code: number): void;
@@ -448,14 +469,218 @@ async function quitParticipation(dependencies: GameCommandDependencies = {}): Pr
448
469
  async function showParticipationStatus(
449
470
  dependencies: GameCommandDependencies = {},
450
471
  ): Promise<void> {
451
- (dependencies.activeProfile ?? activeProfile)();
452
- const client = (dependencies.clientFactory ?? (() => GameClient.fromAuth()))();
453
472
  const io = dependencies.io ?? processGameCommandIo;
454
- const status = await queryGameParticipationStatus(client);
473
+ const status = await readParticipationStatus(dependencies);
455
474
  io.writeStdout(`${JSON.stringify(status, null, 2)}\n`);
456
475
  io.setExitCode(status.status === 'unknown' ? 1 : 0);
457
476
  }
458
477
 
478
+ async function readParticipationStatus(
479
+ dependencies: GameCommandDependencies,
480
+ ): Promise<GameParticipationStatus> {
481
+ (dependencies.activeProfile ?? activeProfile)();
482
+ const client = (dependencies.clientFactory ?? (() => GameClient.fromAuth()))();
483
+ return queryGameParticipationStatus(client);
484
+ }
485
+
486
+ function participationKind(status: GameParticipationStatus): ParticipationKind | undefined {
487
+ if (status.status === 'matching') return 'match';
488
+ if (status.status === 'friend_room') return 'room';
489
+ if (status.status === 'training_room') {
490
+ const roomType = status.room_type ?? status.mode;
491
+ return isTrainingRoomMode(roomType) ? roomType : undefined;
492
+ }
493
+ if (status.status === 'room') {
494
+ const roomType = status.room_type ?? status.mode;
495
+ return isTrainingRoomMode(roomType) ? roomType : 'room';
496
+ }
497
+ if (status.status === 'in_game') {
498
+ if (isTrainingRoomMode(status.mode)) return status.mode;
499
+ return isRoomMode(status.mode) ? 'room' : 'match';
500
+ }
501
+ return undefined;
502
+ }
503
+
504
+ function participationLabel(status: GameParticipationStatus): string {
505
+ const fields = [
506
+ `status=${status.status}`,
507
+ status.mode ? `mode=${status.mode}` : undefined,
508
+ status.room_type ? `room_type=${status.room_type}` : undefined,
509
+ status.room_code ? `room_code=${status.room_code}` : undefined,
510
+ ].filter((value): value is string => value !== undefined);
511
+ return fields.join(', ');
512
+ }
513
+
514
+ function participationConflict(operation: string, status: GameParticipationStatus): Error {
515
+ return new Error(
516
+ `Cannot ${operation} while another backend participation is active (${participationLabel(status)}). Run ccl join to continue it, or quit it before switching.`,
517
+ );
518
+ }
519
+
520
+ async function resolveStartIntent(
521
+ target: ParticipationKind,
522
+ createIntent: GameOwnerIntent,
523
+ dependencies: GameCommandDependencies,
524
+ ): Promise<GameOwnerIntent> {
525
+ const status = await readParticipationStatus(dependencies);
526
+ if (status.status === 'idle') return createIntent;
527
+ if (status.status === 'unknown') {
528
+ throw new Error('Cannot start because the backend participation status is unknown.');
529
+ }
530
+ if (participationKind(status) === target) return { kind: 'resume' };
531
+ throw participationConflict(`start ${target}`, status);
532
+ }
533
+
534
+ async function resolveResumeIntent(
535
+ dependencies: GameCommandDependencies,
536
+ ): Promise<GameOwnerIntent> {
537
+ const status = await readParticipationStatus(dependencies);
538
+ if (status.status === 'idle') {
539
+ throw new Error('No active backend participation to join.');
540
+ }
541
+ if (status.status === 'unknown') {
542
+ throw new Error('Cannot join because the backend participation status is unknown.');
543
+ }
544
+ return { kind: 'resume' };
545
+ }
546
+
547
+ async function resolveJoinRoomIntent(
548
+ roomCode: string,
549
+ metadata: { agentType: string; llmModel?: string },
550
+ dependencies: GameCommandDependencies,
551
+ ): Promise<GameOwnerIntent> {
552
+ const status = await readParticipationStatus(dependencies);
553
+ if (status.status === 'idle') {
554
+ return {
555
+ kind: 'join_room',
556
+ roomCode,
557
+ agentType: metadata.agentType,
558
+ llmModel: metadata.llmModel,
559
+ };
560
+ }
561
+ if (status.status === 'unknown') {
562
+ throw new Error('Cannot join a room because the backend participation status is unknown.');
563
+ }
564
+ const currentKind = participationKind(status);
565
+ if (
566
+ (currentKind === 'room' || isTrainingRoomMode(currentKind))
567
+ && status.room_code === roomCode
568
+ ) {
569
+ return { kind: 'resume' };
570
+ }
571
+ throw participationConflict(`join room ${roomCode}`, status);
572
+ }
573
+
574
+ function ownerRunOptions(options: ResumeCliOptions): GameOwnerRunOptions {
575
+ const desktopEvents = desktopEventConfig(options);
576
+ return {
577
+ forceExistingRuntime: options.force === true,
578
+ ...(desktopEvents ? { desktopEvents } : {}),
579
+ };
580
+ }
581
+
582
+ async function runTopLevelOwner(
583
+ intent: GameOwnerIntent,
584
+ options: ResumeCliOptions,
585
+ dependencies: GameCommandDependencies,
586
+ ): Promise<void> {
587
+ const ownerRunner = dependencies.ownerRunner ?? runOwner;
588
+ await ownerRunner(intent, ownerRunOptions(options));
589
+ }
590
+
591
+ export function createStartCommand(
592
+ dependencies: GameCommandDependencies = {},
593
+ ): Command {
594
+ const start = new Command('start').description('Create or resume a ClawClaw participation');
595
+
596
+ addDesktopEventOptions(start
597
+ .command('match')
598
+ .description('Start ordinary matchmaking, or resume an existing ordinary match')
599
+ .requiredOption('--agent-type <platform>')
600
+ .option('--llm-model <model>')
601
+ .option('--force', 'replace an existing local runtime process before starting'))
602
+ .action(async (options: OwnerCliOptions) => {
603
+ const intent = await resolveStartIntent('match', {
604
+ kind: 'match',
605
+ mode: 'match',
606
+ agentType: options.agentType,
607
+ llmModel: options.llmModel,
608
+ }, dependencies);
609
+ await runTopLevelOwner(intent, options, dependencies);
610
+ });
611
+
612
+ addDesktopEventOptions(start
613
+ .command('room')
614
+ .description('Create a friend room, or resume an existing friend-room participation')
615
+ .requiredOption('--agent-type <platform>')
616
+ .option('--llm-model <model>')
617
+ .option('--force', 'replace an existing local runtime process before starting'))
618
+ .action(async (options: OwnerCliOptions) => {
619
+ const intent = await resolveStartIntent('room', {
620
+ kind: 'create_room',
621
+ agentType: options.agentType,
622
+ llmModel: options.llmModel,
623
+ }, dependencies);
624
+ await runTopLevelOwner(intent, options, dependencies);
625
+ });
626
+
627
+ addDesktopEventOptions(start
628
+ .command('training')
629
+ .description('Create a training room, or resume the same training mode')
630
+ .argument('[simulation|dummy]', 'training ruleset', trainingRoomType, 'training_simulation')
631
+ .requiredOption('--agent-type <platform>')
632
+ .option('--llm-model <model>')
633
+ .option('--force', 'replace an existing local runtime process before starting'))
634
+ .action(async (roomType: TrainingRoomType, options: OwnerCliOptions) => {
635
+ const intent = await resolveStartIntent(roomType, {
636
+ kind: 'create_room',
637
+ roomType,
638
+ agentType: options.agentType,
639
+ llmModel: options.llmModel,
640
+ }, dependencies);
641
+ await runTopLevelOwner(intent, options, dependencies);
642
+ });
643
+
644
+ return start;
645
+ }
646
+
647
+ export function createJoinCommand(
648
+ dependencies: GameCommandDependencies = {},
649
+ ): Command {
650
+ return addDesktopEventOptions(new Command('join')
651
+ .description('Resume the current participation, or join a specific friend room')
652
+ .argument('[target]', 'omit to resume, or use "room" to join a friend room')
653
+ .argument('[room_code]', 'friend room code when target is "room"')
654
+ .option('--agent-type <platform>')
655
+ .option('--llm-model <model>')
656
+ .option('--force', 'replace an existing local runtime process before joining'))
657
+ .action(async (
658
+ target: string | undefined,
659
+ roomCode: string | undefined,
660
+ options: JoinCliOptions,
661
+ ) => {
662
+ if (target === undefined) {
663
+ const intent = await resolveResumeIntent(dependencies);
664
+ await runTopLevelOwner(intent, options, dependencies);
665
+ return;
666
+ }
667
+ if (target !== 'room') {
668
+ throw new InvalidArgumentError('Join target must be "room", or omitted to resume.');
669
+ }
670
+ if (!roomCode) {
671
+ throw new InvalidArgumentError('A room code is required for `ccl join room`.');
672
+ }
673
+ if (!options.agentType) {
674
+ throw new InvalidArgumentError('--agent-type is required when joining a room.');
675
+ }
676
+ const intent = await resolveJoinRoomIntent(roomCode, {
677
+ agentType: options.agentType,
678
+ llmModel: options.llmModel,
679
+ }, dependencies);
680
+ await runTopLevelOwner(intent, options, dependencies);
681
+ });
682
+ }
683
+
459
684
  export function createGameCommand(dependencies: GameCommandDependencies = {}): Command {
460
685
  const game = new Command('game').description('Game participation and inspection');
461
686
  const ownerRunner = dependencies.ownerRunner ?? runOwner;
@@ -17,6 +17,16 @@ import { loadContext } from '../lib/load-context.js';
17
17
  import { createLoadCommand } from './load.js';
18
18
  import { updateGameplayConfig } from '../lib/gameplay-config.js';
19
19
 
20
+ function participationClient(
21
+ queue: Record<string, unknown>,
22
+ room: Record<string, unknown> = { success: true, data: {} },
23
+ ) {
24
+ return {
25
+ getQueueStatus: vi.fn(async () => queue),
26
+ getRoomStatus: vi.fn(async () => room),
27
+ };
28
+ }
29
+
20
30
  describe('load command', () => {
21
31
  let logSpy: ReturnType<typeof vi.spyOn>;
22
32
  let errorSpy: ReturnType<typeof vi.spyOn>;
@@ -43,7 +53,8 @@ describe('load command', () => {
43
53
  });
44
54
 
45
55
  it('runs auto-upgrade check before printing JSON load context', async () => {
46
- const cmd = createLoadCommand();
56
+ const client = participationClient({ success: true, data: { status: 'not_in_queue' } });
57
+ const cmd = createLoadCommand({ clientFactory: () => client });
47
58
  await cmd.parseAsync(['node', 'load'], { from: 'node' });
48
59
 
49
60
  expect(runAutoUpgradeOnLoad).toHaveBeenCalledOnce();
@@ -52,6 +63,11 @@ describe('load command', () => {
52
63
  expect(output).toMatchObject({
53
64
  persona: { exists: true },
54
65
  memory: { exists: false },
66
+ participation: {
67
+ schema: 'ccl.game-status.v1',
68
+ status: 'idle',
69
+ queue_status: 'not_in_queue',
70
+ },
55
71
  });
56
72
  expect(output.strategies).toEqual(expect.arrayContaining([
57
73
  expect.objectContaining({
@@ -61,6 +77,57 @@ describe('load command', () => {
61
77
  }),
62
78
  ]));
63
79
  expect(existsSync(join(workspaceDir, 'user-data', 'strategies', 'task-only.ts'))).toBe(true);
80
+ expect(client.getQueueStatus).toHaveBeenCalledWith('clawclaw');
81
+ });
82
+
83
+ it('includes the current backend room participation', async () => {
84
+ const client = participationClient(
85
+ { success: true, data: { status: 'in_room', mode: 'room', room_code: 'QUEUE1' } },
86
+ {
87
+ success: true,
88
+ data: {
89
+ room_code: 'ROOM1',
90
+ room_type: 'training_dummy',
91
+ status: 'playing',
92
+ },
93
+ },
94
+ );
95
+
96
+ await createLoadCommand({ clientFactory: () => client })
97
+ .parseAsync(['node', 'load'], { from: 'node' });
98
+
99
+ const output = JSON.parse(String(logSpy.mock.calls[0][0]));
100
+ expect(output.participation).toMatchObject({
101
+ schema: 'ccl.game-status.v1',
102
+ status: 'training_room',
103
+ queue_status: 'in_room',
104
+ room_code: 'ROOM1',
105
+ room_type: 'training_dummy',
106
+ room_status: 'playing',
107
+ });
108
+ });
109
+
110
+ it('keeps local context available when backend participation lookup fails', async () => {
111
+ await createLoadCommand({
112
+ clientFactory: () => ({
113
+ getQueueStatus: vi.fn(async () => { throw new Error('backend offline'); }),
114
+ getRoomStatus: vi.fn(),
115
+ }),
116
+ }).parseAsync(['node', 'load'], { from: 'node' });
117
+
118
+ const output = JSON.parse(String(logSpy.mock.calls[0][0]));
119
+ expect(output).toMatchObject({
120
+ persona: { exists: true },
121
+ memory: { exists: false },
122
+ participation: {
123
+ schema: 'ccl.game-status.v1',
124
+ status: 'unknown',
125
+ queue_status: null,
126
+ },
127
+ });
128
+ expect(errorSpy).toHaveBeenCalledWith(
129
+ '[clawclaw-cli] participation status unavailable: backend offline',
130
+ );
64
131
  });
65
132
 
66
133
  it('routes auto-upgrade notifications to stderr', async () => {
@@ -8,10 +8,20 @@ import {
8
8
  } from '../runtime/clawclaw/plugins/strategy/index.js';
9
9
  import { readGameplayConfig } from '../lib/gameplay-config.js';
10
10
  import { syncOfficialStrategies } from '../lib/strategy-export.js';
11
+ import { GameClient } from '../lib/game-client.js';
12
+ import {
13
+ GAME_STATUS_SCHEMA,
14
+ queryGameParticipationStatus,
15
+ type ParticipationStatusClient,
16
+ } from '../lib/participation-status.js';
17
+
18
+ export interface LoadCommandDependencies {
19
+ clientFactory?: () => ParticipationStatusClient;
20
+ }
11
21
 
12
- export function createLoadCommand(): Command {
22
+ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): Command {
13
23
  return new Command('load')
14
- .description('Read active account persona, memory, and available strategies')
24
+ .description('Read active account context, strategies, and backend participation')
15
25
  .action(async () => {
16
26
  runAutoUpgradeOnLoad({ notify: (message) => console.error(message) });
17
27
  let snapshot;
@@ -34,6 +44,19 @@ export function createLoadCommand(): Command {
34
44
  name,
35
45
  description,
36
46
  }));
37
- console.log(JSON.stringify({ ...snapshot, strategies }, null, 2));
47
+ let participation;
48
+ try {
49
+ const client = (dependencies.clientFactory ?? (() => GameClient.fromAuth()))();
50
+ participation = await queryGameParticipationStatus(client);
51
+ } catch (error) {
52
+ participation = {
53
+ schema: GAME_STATUS_SCHEMA,
54
+ status: 'unknown' as const,
55
+ queue_status: null,
56
+ };
57
+ const message = error instanceof Error ? error.message : String(error);
58
+ console.error(`[clawclaw-cli] participation status unavailable: ${message}`);
59
+ }
60
+ console.log(JSON.stringify({ ...snapshot, strategies, participation }, null, 2));
38
61
  });
39
62
  }