@myclaw163/clawclaw-cli 0.7.16 → 0.8.2

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 (335) hide show
  1. package/QUICKSTART_HERMES.md +1 -1
  2. package/QUICKSTART_OPENCLAW.md +3 -11
  3. package/QUICKSTART_OTHER.md +8 -8
  4. package/README.md +18 -9
  5. package/bin/clawclaw-channel.mjs +13 -0
  6. package/docs/configuration.md +86 -33
  7. package/docs/custom-modules/README.md +148 -0
  8. package/docs/custom-modules/api-reference.md +767 -0
  9. package/docs/custom-modules/behavior.md +318 -0
  10. package/docs/custom-modules/perception.md +305 -0
  11. package/docs/custom-modules/trigger.md +292 -0
  12. package/docs/desktop-event-push.md +6 -4
  13. package/docs/runtime/README.md +28 -10
  14. package/docs/runtime/agent-notifications.md +48 -29
  15. package/docs/runtime/behavior-runtime.md +139 -0
  16. package/docs/runtime/components-and-boundaries.md +89 -173
  17. package/docs/runtime/events-and-state.md +55 -66
  18. package/docs/runtime/official-perception-modules.md +17 -9
  19. package/docs/runtime/owner-lifecycle-and-observability.md +62 -39
  20. package/docs/runtime/perception-replay.md +6 -6
  21. package/docs/runtime/short-commands-and-capabilities.md +35 -37
  22. package/package.json +10 -7
  23. package/scripts/check-skill-command-surface.mjs +54 -10
  24. package/scripts/compare-perception-replays.test.ts +10 -10
  25. package/scripts/compare-perception-replays.ts +14 -10
  26. package/scripts/replay-perception.ts +3 -3
  27. package/scripts/watch-perception-events.test.ts +1 -1
  28. package/skills/clawclaw/SKILL.md +97 -59
  29. package/skills/clawclaw/references/BEHAVIORS.md +154 -0
  30. package/skills/clawclaw/references/CHANNELS.md +115 -0
  31. package/skills/clawclaw/references/CHATTERBOX.md +3 -2
  32. package/skills/clawclaw/references/COMMANDS.md +108 -58
  33. package/skills/clawclaw/references/GAME-MECHANICS.md +4 -3
  34. package/skills/clawclaw/references/HUB.md +27 -23
  35. package/skills/clawclaw/references/STREAM.md +18 -14
  36. package/skills/clawclaw/references/TACTICS.md +2 -2
  37. package/src/behaviors/official-finite/do-task.ts +141 -0
  38. package/src/behaviors/official-finite/evade.ts +78 -0
  39. package/src/behaviors/official-finite/find-player.ts +50 -0
  40. package/src/behaviors/official-finite/follow-player.ts +70 -0
  41. package/src/behaviors/official-finite/go-to.ts +69 -0
  42. package/src/behaviors/official-finite/hide-temporarily.ts +77 -0
  43. package/src/behaviors/official-finite/hold-position.ts +48 -0
  44. package/src/behaviors/official-finite/hunt-player.ts +47 -0
  45. package/src/behaviors/official-finite/index.test.ts +202 -0
  46. package/src/behaviors/official-finite/index.ts +47 -0
  47. package/src/behaviors/official-finite/inspect-corpse.ts +64 -0
  48. package/src/behaviors/official-finite/patrol-area.ts +80 -0
  49. package/src/behaviors/official-finite/report-corpse.ts +73 -0
  50. package/src/behaviors/official-finite/seek-kill-opportunity.ts +152 -0
  51. package/src/behaviors/official-finite/shared.ts +27 -0
  52. package/src/behaviors/official-finite/trigger-alarm.ts +53 -0
  53. package/src/channel/claude-channel-ipc-server.ts +295 -0
  54. package/src/channel/claude-channel-ipc.ts +152 -0
  55. package/src/channel/claude-channel-server.test.ts +202 -0
  56. package/src/channel/claude-channel-server.ts +221 -0
  57. package/src/cli.ts +4 -2
  58. package/src/commands/account.test.ts +17 -17
  59. package/src/commands/behavior.test.ts +158 -0
  60. package/src/commands/behavior.ts +443 -0
  61. package/src/commands/communication.test.ts +12 -0
  62. package/src/commands/communication.ts +6 -3
  63. package/src/commands/data.test.ts +1 -1
  64. package/src/commands/data.ts +1 -1
  65. package/src/commands/events-canonical-state.test.ts +221 -2
  66. package/src/commands/events.ts +205 -12
  67. package/src/commands/game/index.test.ts +172 -3
  68. package/src/commands/game/index.ts +69 -32
  69. package/src/commands/hub.test.ts +25 -14
  70. package/src/commands/hub.ts +15 -19
  71. package/src/commands/load.test.ts +228 -6
  72. package/src/commands/load.ts +102 -18
  73. package/src/commands/memory.ts +1 -1
  74. package/src/commands/peek.ts +1 -1
  75. package/src/commands/perception.test.ts +30 -1
  76. package/src/commands/perception.ts +15 -17
  77. package/src/commands/trigger.test.ts +140 -0
  78. package/src/commands/trigger.ts +314 -0
  79. package/src/lib/account-guidance.test.ts +4 -0
  80. package/src/lib/account-guidance.ts +1 -1
  81. package/src/lib/behavior-export.test.ts +282 -0
  82. package/src/lib/behavior-export.ts +514 -0
  83. package/src/lib/game-client.test.ts +4 -17
  84. package/src/lib/game-client.ts +1 -0
  85. package/src/lib/gameplay-config.test.ts +258 -37
  86. package/src/lib/gameplay-config.ts +175 -35
  87. package/src/lib/hub-install.test.ts +19 -41
  88. package/src/lib/hub-install.ts +10 -38
  89. package/src/lib/hub-reminder.ts +7 -9
  90. package/src/lib/init-command.ts +1 -1
  91. package/src/lib/official-resource-sync.test.ts +199 -0
  92. package/src/lib/official-resource-sync.ts +221 -0
  93. package/src/lib/perception-config.test.ts +9 -4
  94. package/src/lib/perception-config.ts +10 -13
  95. package/src/lib/perception-export.test.ts +145 -0
  96. package/src/lib/perception-export.ts +178 -0
  97. package/src/lib/trigger-config.test.ts +102 -0
  98. package/src/lib/trigger-config.ts +217 -0
  99. package/src/lib/user-data.test.ts +23 -6
  100. package/src/lib/user-data.ts +15 -123
  101. package/src/pipeline/canonical-event-presentation.test.ts +5 -5
  102. package/src/pipeline/canonical-event-presentation.ts +13 -5
  103. package/src/pipeline/event-format.test.ts +106 -3
  104. package/src/pipeline/event-format.ts +172 -4
  105. package/src/pipeline/event-hints.test.ts +57 -4
  106. package/src/pipeline/event-hints.ts +34 -8
  107. package/src/runtime/canonical-monitor.test.ts +2 -0
  108. package/src/runtime/canonical-monitor.ts +6 -2
  109. package/src/runtime/clawclaw/agent-event-policy.test.ts +23 -2
  110. package/src/runtime/clawclaw/agent-event-policy.ts +12 -5
  111. package/src/runtime/clawclaw/behavior-decision.test.ts +29 -0
  112. package/src/runtime/clawclaw/behavior-decision.ts +82 -0
  113. package/src/runtime/clawclaw/behavior-input-fields.test.ts +175 -0
  114. package/src/runtime/clawclaw/behavior-input-fields.ts +270 -0
  115. package/src/runtime/clawclaw/behavior-input.test.ts +151 -0
  116. package/src/runtime/clawclaw/behavior-input.ts +70 -0
  117. package/src/runtime/clawclaw/behavior-observation-memory.test.ts +59 -0
  118. package/src/runtime/clawclaw/behavior-observation-memory.ts +142 -0
  119. package/src/runtime/clawclaw/behavior-read-api.test.ts +123 -0
  120. package/src/runtime/clawclaw/behavior-read-api.ts +158 -0
  121. package/src/runtime/clawclaw/{plugins/perception/visual-state-projector.ts → observation-frame-projector.ts} +44 -25
  122. package/src/runtime/clawclaw/owner.test.ts +187 -0
  123. package/src/runtime/clawclaw/owner.ts +431 -69
  124. package/src/runtime/clawclaw/plugins/action/action-plugin.test.ts +304 -0
  125. package/src/runtime/clawclaw/plugins/action/action-plugin.ts +285 -41
  126. package/src/runtime/clawclaw/plugins/action/automated-action-normalization.ts +82 -0
  127. package/src/runtime/clawclaw/plugins/assembly.test.ts +135 -29
  128. package/src/runtime/clawclaw/plugins/assembly.ts +54 -28
  129. package/src/runtime/clawclaw/plugins/behavior/activation-manager.test.ts +180 -0
  130. package/src/runtime/clawclaw/plugins/behavior/activation-manager.ts +468 -0
  131. package/src/runtime/clawclaw/plugins/behavior/behavior-action.test.ts +40 -0
  132. package/src/runtime/clawclaw/plugins/behavior/behavior-action.ts +30 -0
  133. package/src/runtime/clawclaw/plugins/behavior/behavior-analysis-thread-host.ts +152 -0
  134. package/src/runtime/clawclaw/plugins/behavior/behavior-catalog.test.ts +156 -0
  135. package/src/runtime/clawclaw/plugins/behavior/behavior-catalog.ts +104 -0
  136. package/src/runtime/clawclaw/plugins/behavior/behavior-manifest.ts +173 -0
  137. package/src/runtime/clawclaw/plugins/behavior/behavior-module-loader.test.ts +182 -0
  138. package/src/runtime/clawclaw/plugins/behavior/behavior-module-loader.ts +223 -0
  139. package/src/runtime/clawclaw/plugins/behavior/behavior-normalization.ts +157 -0
  140. package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.test.ts +848 -0
  141. package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.ts +1347 -0
  142. package/src/runtime/clawclaw/plugins/behavior/behavior-runner.ts +212 -0
  143. package/src/runtime/clawclaw/plugins/behavior/behavior-source.test.ts +174 -0
  144. package/src/runtime/clawclaw/plugins/behavior/behavior-source.ts +621 -0
  145. package/src/runtime/clawclaw/plugins/behavior/control-driver.test.ts +195 -0
  146. package/src/runtime/clawclaw/plugins/behavior/control-driver.ts +180 -0
  147. package/src/runtime/clawclaw/plugins/behavior/index.ts +11 -0
  148. package/src/runtime/clawclaw/plugins/behavior/official-goal-behavior.ts +766 -0
  149. package/src/runtime/clawclaw/plugins/behavior/thread-behavior-executor.test.ts +283 -0
  150. package/src/runtime/clawclaw/plugins/{strategy/thread-strategy-executor.ts → behavior/thread-behavior-executor.ts} +109 -121
  151. package/src/runtime/clawclaw/plugins/behavior-input-source.test.ts +80 -0
  152. package/src/runtime/clawclaw/plugins/behavior-input-source.ts +247 -0
  153. package/src/runtime/clawclaw/plugins/{strategy → game-query}/context-capabilities.ts +1 -1
  154. package/src/runtime/clawclaw/plugins/game-query/game-query-plugin.test.ts +13 -10
  155. package/src/runtime/clawclaw/plugins/game-query/game-query-plugin.ts +26 -14
  156. package/src/runtime/clawclaw/plugins/game-query/index.ts +1 -0
  157. package/src/runtime/clawclaw/plugins/index.ts +3 -1
  158. package/src/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-adapter.test.ts +239 -0
  159. package/src/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-adapter.ts +100 -0
  160. package/src/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-socket.ts +346 -0
  161. package/src/runtime/clawclaw/plugins/mailbox/agent-mailbox-coordinator.test.ts +230 -12
  162. package/src/runtime/clawclaw/plugins/mailbox/agent-mailbox-coordinator.ts +118 -90
  163. package/src/runtime/clawclaw/plugins/mailbox/consumer-ids.ts +5 -0
  164. package/src/runtime/clawclaw/plugins/mailbox/index.ts +3 -0
  165. package/src/runtime/clawclaw/plugins/mailbox/mailbox-agent-event-batch.test.ts +1 -1
  166. package/src/runtime/clawclaw/plugins/mailbox/mailbox-event-batch-delivery.ts +4 -0
  167. package/src/runtime/clawclaw/plugins/mailbox/mailbox-plugin.test.ts +87 -0
  168. package/src/runtime/clawclaw/plugins/mailbox/mailbox-plugin.ts +70 -12
  169. package/src/runtime/clawclaw/plugins/mailbox/mailbox-presentation.ts +94 -11
  170. package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.test.ts +1229 -345
  171. package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.ts +479 -35
  172. package/src/runtime/clawclaw/plugins/perception/contracts.ts +4 -3
  173. package/src/runtime/clawclaw/plugins/perception/index.ts +1 -1
  174. package/src/runtime/clawclaw/plugins/perception/module-runner.test.ts +23 -13
  175. package/src/runtime/clawclaw/plugins/perception/module-runner.ts +11 -9
  176. package/src/runtime/clawclaw/plugins/perception/modules/co-movement-module.ts +39 -38
  177. package/src/runtime/clawclaw/plugins/perception/modules/corpse-visibility-module.test.ts +92 -0
  178. package/src/runtime/clawclaw/plugins/perception/modules/corpse-visibility-module.ts +248 -0
  179. package/src/runtime/clawclaw/plugins/perception/modules/follow-module.ts +39 -37
  180. package/src/runtime/clawclaw/plugins/perception/modules/index.ts +1 -0
  181. package/src/runtime/clawclaw/plugins/perception/modules/motion-module.test.ts +22 -21
  182. package/src/runtime/clawclaw/plugins/perception/modules/motion-module.ts +15 -9
  183. package/src/runtime/clawclaw/plugins/perception/modules/parallel-module-test-helpers.ts +3 -3
  184. package/src/runtime/clawclaw/plugins/perception/modules/relation-stability.test.ts +33 -18
  185. package/src/runtime/clawclaw/plugins/perception/modules/route-module.test.ts +6 -7
  186. package/src/runtime/clawclaw/plugins/perception/modules/route-module.ts +22 -16
  187. package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.test.ts +6 -7
  188. package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.ts +18 -12
  189. package/src/runtime/clawclaw/plugins/perception/modules/stop-module.test.ts +14 -10
  190. package/src/runtime/clawclaw/plugins/perception/modules/stop-module.ts +20 -14
  191. package/src/runtime/clawclaw/plugins/perception/modules/temporal-evidence.test.ts +5 -6
  192. package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.test.ts +5 -6
  193. package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.ts +49 -34
  194. package/src/runtime/clawclaw/plugins/perception/official-module-ids.ts +1 -0
  195. package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-pool.test.ts +126 -20
  196. package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-pool.ts +24 -3
  197. package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-worker.ts +59 -46
  198. package/src/runtime/clawclaw/plugins/perception/perception-module-loader.ts +27 -5
  199. package/src/runtime/clawclaw/plugins/perception/perception-plugin.test.ts +381 -49
  200. package/src/runtime/clawclaw/plugins/perception/perception-plugin.ts +267 -245
  201. package/src/runtime/clawclaw/plugins/perception/perception-source.test.ts +98 -0
  202. package/src/runtime/clawclaw/plugins/perception/perception-source.ts +89 -16
  203. package/src/runtime/clawclaw/plugins/perception/perception-test-fixtures.ts +34 -0
  204. package/src/runtime/clawclaw/plugins/perception/replay.test.ts +27 -15
  205. package/src/runtime/clawclaw/plugins/perception/replay.ts +10 -5
  206. package/src/runtime/clawclaw/plugins/perception/shared/math.ts +1 -107
  207. package/src/runtime/clawclaw/plugins/perception/spatial-facts.ts +7 -10
  208. package/src/runtime/clawclaw/plugins/plugin-api-version.ts +112 -0
  209. package/src/runtime/clawclaw/plugins/runtime-plugins.test.ts +388 -559
  210. package/src/runtime/clawclaw/plugins/source/player-change-tracker.test.ts +56 -5
  211. package/src/runtime/clawclaw/plugins/source/player-change-tracker.ts +135 -26
  212. package/src/runtime/clawclaw/plugins/source/source-plugin.test.ts +249 -16
  213. package/src/runtime/clawclaw/plugins/source/source-plugin.ts +99 -2
  214. package/src/runtime/clawclaw/plugins/source/task-change-tracker.test.ts +212 -0
  215. package/src/runtime/clawclaw/plugins/source/task-change-tracker.ts +259 -0
  216. package/src/runtime/clawclaw/plugins/trigger/contracts.ts +97 -0
  217. package/src/runtime/clawclaw/plugins/trigger/index.ts +4 -0
  218. package/src/runtime/clawclaw/plugins/trigger/trigger-module-loader.ts +118 -0
  219. package/src/runtime/clawclaw/plugins/trigger/trigger-plugin.test.ts +548 -0
  220. package/src/runtime/clawclaw/plugins/trigger/trigger-plugin.ts +655 -0
  221. package/src/runtime/clawclaw/plugins/trigger/trigger-source.test.ts +169 -0
  222. package/src/runtime/clawclaw/plugins/trigger/trigger-source.ts +457 -0
  223. package/src/runtime/clawclaw/runtime.ts +8 -0
  224. package/src/runtime/clawclaw/spatial-api.ts +76 -0
  225. package/src/runtime/clawclaw-event-catalog.test.ts +46 -1
  226. package/src/runtime/clawclaw-event-catalog.ts +40 -3
  227. package/src/runtime/framework/capability-registry.test.ts +196 -55
  228. package/src/runtime/framework/capability-registry.ts +99 -17
  229. package/src/runtime/framework/contracts.ts +30 -4
  230. package/src/runtime/framework/control/control-scheduler.ts +13 -5
  231. package/src/runtime/framework/control/types.ts +11 -4
  232. package/src/runtime/framework/control-coordinator.test.ts +95 -80
  233. package/src/runtime/framework/events/event-delivery-service.ts +4 -2
  234. package/src/runtime/framework/events/event-ingress.test.ts +25 -0
  235. package/src/runtime/framework/events/event-ingress.ts +2 -1
  236. package/src/runtime/framework/events/event-repository.ts +24 -2
  237. package/src/runtime/framework/events/mailbox-event-repositories.test.ts +124 -8
  238. package/src/runtime/framework/events/memory-event-repository.ts +92 -28
  239. package/src/runtime/framework/events/sqlite-event-repository.test.ts +604 -2
  240. package/src/runtime/framework/events/sqlite-event-repository.ts +531 -21
  241. package/src/runtime/framework/events/types.ts +24 -8
  242. package/src/runtime/framework/modules/runtime-module-loader-hooks.mjs +38 -1
  243. package/src/runtime/framework/modules/runtime-module-loader.test.ts +233 -7
  244. package/src/runtime/framework/modules/runtime-module-loader.ts +69 -4
  245. package/src/runtime/framework/plugins/contracts.ts +12 -18
  246. package/src/runtime/framework/plugins/runtime-plugin-scheduler.test.ts +81 -71
  247. package/src/runtime/framework/plugins/runtime-plugin-scheduler.ts +38 -20
  248. package/src/runtime/framework/runtime.ts +20 -23
  249. package/src/runtime/host-monitor-rate-gate.test.ts +73 -0
  250. package/src/runtime/host-monitor-rate-gate.ts +123 -0
  251. package/src/runtime/mailbox-host-relay.test.ts +45 -0
  252. package/src/runtime/mailbox-host-relay.ts +25 -0
  253. package/src/runtime/observability/factory.ts +4 -4
  254. package/src/runtime/observability/observability.test.ts +25 -3
  255. package/src/runtime/observability/reporter.ts +1 -1
  256. package/src/runtime/observability/types.ts +2 -2
  257. package/src/runtime/owner-control.ts +10 -2
  258. package/src/runtime/runtime-logger.test.ts +1 -1
  259. package/src/runtime/runtime-logger.ts +4 -6
  260. package/src/runtime/runtime.test.ts +88 -22
  261. package/src/sdk/action.ts +2 -2
  262. package/src/sdk/behavior-plugin/index.test.ts +74 -0
  263. package/src/sdk/behavior-plugin/index.ts +335 -0
  264. package/src/sdk/behavior-toolkit/corpse-search.ts +87 -0
  265. package/src/sdk/behavior-toolkit/escape.ts +40 -0
  266. package/src/sdk/behavior-toolkit/index.ts +7 -0
  267. package/src/sdk/behavior-toolkit/kill-flow.ts +299 -0
  268. package/src/sdk/behavior-toolkit/model.ts +263 -0
  269. package/src/sdk/behavior-toolkit/move-gate.ts +52 -0
  270. package/src/sdk/behavior-toolkit/patrol.ts +53 -0
  271. package/src/sdk/behavior-toolkit/search.ts +102 -0
  272. package/src/sdk/index.test.ts +45 -0
  273. package/src/sdk/index.ts +67 -73
  274. package/src/sdk/module-input/index.test.ts +49 -0
  275. package/src/sdk/module-input/index.ts +229 -0
  276. package/src/sdk/perception-plugin/index.test.ts +2 -2
  277. package/src/sdk/perception-plugin/index.ts +51 -142
  278. package/src/sdk/perception-plugin/math.ts +107 -0
  279. package/src/sdk/trigger-plugin/index.test.ts +41 -0
  280. package/src/sdk/trigger-plugin/index.ts +128 -0
  281. package/src/strategies/avoid-lone.ts +21 -10
  282. package/src/strategies/avoid-players.ts +26 -16
  283. package/src/strategies/corpse-patrol.ts +25 -14
  284. package/src/strategies/crab-sabotage.ts +20 -9
  285. package/src/strategies/find-player.ts +33 -21
  286. package/src/strategies/game-utils.ts +1 -1
  287. package/src/strategies/goals/crab-sabotage-top.test.ts +145 -0
  288. package/src/strategies/goals/crab-sabotage-top.ts +32 -69
  289. package/src/strategies/hide.ts +25 -15
  290. package/src/strategies/kill-frenzy.ts +21 -10
  291. package/src/strategies/kill-lone.ts +27 -17
  292. package/src/strategies/kill-target.ts +33 -22
  293. package/src/strategies/lone-kill-task.ts +20 -9
  294. package/src/strategies/move-room.ts +29 -18
  295. package/src/strategies/official-long-behavior.test.ts +89 -0
  296. package/src/strategies/paradise-fish.ts +29 -18
  297. package/src/strategies/pathfind/astar-path.test.ts +127 -2
  298. package/src/strategies/pathfind/astar-path.ts +136 -26
  299. package/src/strategies/patrol.ts +21 -10
  300. package/src/strategies/player-targets.test.ts +10 -0
  301. package/src/strategies/player-targets.ts +13 -0
  302. package/src/strategies/report-patrol.ts +21 -10
  303. package/src/strategies/shrimp-memory.ts +30 -19
  304. package/src/strategies/social-task.ts +34 -23
  305. package/src/strategies/task-kill-report.ts +33 -22
  306. package/src/strategies/task-only.test.ts +99 -85
  307. package/src/strategies/task-only.ts +23 -12
  308. package/src/strategies/task-report.ts +25 -14
  309. package/src/strategies/types.ts +8 -8
  310. package/src/strategies/warrior-memory.ts +29 -19
  311. package/docs/runtime/strategy-runtime.md +0 -111
  312. package/docs//350/207/252/345/256/232/344/271/211/346/204/237/347/237/245.md +0 -502
  313. package/docs//350/207/252/345/256/232/344/271/211/347/255/226/347/225/245.md +0 -395
  314. package/skills/clawclaw/references/STRATEGIES.md +0 -76
  315. package/src/commands/strategy.test.ts +0 -209
  316. package/src/commands/strategy.ts +0 -242
  317. package/src/lib/strategy-export.test.ts +0 -406
  318. package/src/lib/strategy-export.ts +0 -381
  319. package/src/runtime/clawclaw/plugins/perception/official-modules.ts +0 -31
  320. package/src/runtime/clawclaw/plugins/strategy/examples/task-only-strategy.test.ts +0 -177
  321. package/src/runtime/clawclaw/plugins/strategy/examples/task-only-strategy.ts +0 -191
  322. package/src/runtime/clawclaw/plugins/strategy/index.ts +0 -8
  323. package/src/runtime/clawclaw/plugins/strategy/local-strategy-executor.ts +0 -412
  324. package/src/runtime/clawclaw/plugins/strategy/strategy-action.ts +0 -80
  325. package/src/runtime/clawclaw/plugins/strategy/strategy-analysis-thread-host.ts +0 -183
  326. package/src/runtime/clawclaw/plugins/strategy/strategy-executor-types.ts +0 -29
  327. package/src/runtime/clawclaw/plugins/strategy/strategy-executor.test.ts +0 -693
  328. package/src/runtime/clawclaw/plugins/strategy/strategy-game-api.ts +0 -57
  329. package/src/runtime/clawclaw/plugins/strategy/strategy-module-loader.ts +0 -168
  330. package/src/runtime/clawclaw/plugins/strategy/strategy-plugin.test.ts +0 -2175
  331. package/src/runtime/clawclaw/plugins/strategy/strategy-plugin.ts +0 -1774
  332. package/src/runtime/clawclaw/plugins/strategy/strategy-source.test.ts +0 -153
  333. package/src/runtime/clawclaw/plugins/strategy/strategy-source.ts +0 -443
  334. package/src/sdk/strategy-plugin/index.test.ts +0 -958
  335. package/src/sdk/strategy-plugin/index.ts +0 -1350
@@ -1,8 +1,28 @@
1
1
  import { describe, expect, it } from 'vitest';
2
- import { compactEventFields, compactStateForEvents, formatEventMessage, shortStateText } from './event-format.js';
2
+ import {
3
+ compactEventFields,
4
+ compactEventForEvents,
5
+ compactStateForEvents,
6
+ formatEventMessage,
7
+ shortStateText,
8
+ } from './event-format.js';
3
9
  import { BACKEND_EVENT_HINT_FORMATTERS } from './event-hints.js';
4
10
 
5
11
  describe('event-format', () => {
12
+ it('formats unified Behavior lifecycle Events', () => {
13
+ expect(formatEventMessage({
14
+ type: 'behavior.completed',
15
+ behavior: 'do-task',
16
+ layer: 'short',
17
+ reason: 'task_completed',
18
+ })).toContain('behavior.completed do-task(short)已完成:task_completed');
19
+ expect(formatEventMessage({
20
+ type: 'behavior.restarted',
21
+ behavior: 'hunt-player',
22
+ layer: 'short',
23
+ })).toContain('behavior.restarted hunt-player(short)已重新启动');
24
+ });
25
+
6
26
  it('formats upcoming and active maintenance as explicit service messages', () => {
7
27
  const maintenance = {
8
28
  starts_at: '2026-08-05T01:00:00+00:00',
@@ -54,6 +74,24 @@ describe('event-format', () => {
54
74
  expect(message).not.toContain('?号Shrimp God');
55
75
  });
56
76
 
77
+ it('downgrades self-killer murder_witnessed presentation to neutral diagnostics', () => {
78
+ const message = formatEventMessage({
79
+ type: 'murder_witnessed',
80
+ tick: 42,
81
+ room: '制氧舱',
82
+ killer_name: 'self',
83
+ killer_seat: 1,
84
+ target_name: 'target',
85
+ target_seat: 2,
86
+ }, {
87
+ summary: { you: { player: { name: 'self', seat: 1 } } },
88
+ });
89
+
90
+ expect(message).toContain('已降级为诊断信息');
91
+ expect(message).toContain('不能据此判断任何目击者');
92
+ expect(message).not.toContain('你在制氧舱目击');
93
+ });
94
+
57
95
  it('keeps meeting_briefing details aligned with the compact monitor payload', () => {
58
96
  const formatted = compactEventFields({
59
97
  type: 'meeting_briefing',
@@ -221,7 +259,7 @@ describe('event-format', () => {
221
259
  expect(message).toContain('t0 game_started');
222
260
  expect(message).toContain('10');
223
261
  expect(message).toContain('竞赛模式');
224
- expect(message).toContain('ccl events');
262
+ expect(message).toContain('full Event delivery');
225
263
  expect(message).not.toContain('ccl events game_started');
226
264
  expect(message).not.toContain('ccl events role_assigned');
227
265
  expect(message).toContain(`Hint: ${hint}`);
@@ -272,6 +310,9 @@ describe('event-format', () => {
272
310
  expect(formatEventMessage({ type: 'quit_requested' })).toContain('正在结束');
273
311
  expect(formatEventMessage({ type: 'room_created', room_code: '123456' })).toContain('123456');
274
312
  expect(formatEventMessage({ type: 'room_lobby_reconnect_failed' })).toContain('失败');
313
+ expect(formatEventMessage({
314
+ type: 'behavior.completed', behavior: 'evade', layer: 'short', reason: 'escaped',
315
+ })).toContain('evade(short)已完成:escaped');
275
316
  });
276
317
 
277
318
  it('formats backend Event types that previously fell through to raw names', () => {
@@ -290,6 +331,19 @@ describe('event-format', () => {
290
331
  }
291
332
  });
292
333
 
334
+ it('keeps every nearby player in a move interruption fact', () => {
335
+ const message = formatEventMessage({
336
+ type: 'move_interrupted',
337
+ nearby_players: [
338
+ { name: 'Alpha', seat: 2 },
339
+ { name: 'Beta', seat: 3 },
340
+ { name: 'Gamma', seat: 4 },
341
+ { name: 'Delta', seat: 5 },
342
+ ],
343
+ });
344
+ expect(message).toContain('2号Alpha、3号Beta、4号Gamma、5号Delta');
345
+ });
346
+
293
347
  it('mentions a newly assigned task only when task_completed carries one', () => {
294
348
  expect(formatEventMessage({
295
349
  type: 'task_completed',
@@ -307,6 +361,51 @@ describe('event-format', () => {
307
361
  })).toBe('tick=null task_completed 任务完成:擦拭酒瓶。');
308
362
  });
309
363
 
364
+ it('removes the duplicate single assignment once a task Event has full list context', () => {
365
+ const compact = compactEventForEvents({
366
+ type: 'task_completed',
367
+ tick: 42,
368
+ task_name: '擦拭酒瓶',
369
+ newly_assigned_task: { name: '消毒淋浴器' },
370
+ reason: 'task_completed',
371
+ delta: [{ change: 'added', task: { name: '消毒淋浴器', status: 'normal' } }],
372
+ tasks: [{ name: '消毒淋浴器', status: 'normal' }],
373
+ });
374
+
375
+ expect(compact).not.toHaveProperty('newly_assigned_task');
376
+ expect(compact).toMatchObject({
377
+ reason: 'task_completed',
378
+ delta: [{ change: 'added', task: { name: '消毒淋浴器', status: 'normal' } }],
379
+ tasks: [{ name: '消毒淋浴器', status: 'normal' }],
380
+ });
381
+ });
382
+
383
+ it('preserves old and new values for a player status delta', () => {
384
+ const compact = compactEventForEvents({
385
+ type: 'players_changed',
386
+ reason: 'player_status_changed',
387
+ changes: [{
388
+ change: 'status_changed',
389
+ name: 'Hidden',
390
+ seat: 2,
391
+ from_status: 'unknown',
392
+ to_status: 'alive',
393
+ }],
394
+ players: [{ name: 'Hidden', seat: 2, status: 'alive', death: null }],
395
+ });
396
+
397
+ expect(compact).toMatchObject({
398
+ changes: [{
399
+ change: 'status_changed',
400
+ name: 'Hidden',
401
+ seat: 2,
402
+ from_status: 'unknown',
403
+ to_status: 'alive',
404
+ }],
405
+ players: [{ name: 'Hidden', seat: 2, status: 'alive', death: null }],
406
+ });
407
+ });
408
+
310
409
  it('formats room presence and idle lifecycle Events', () => {
311
410
  expect(formatEventMessage({
312
411
  type: 'room.member_status_changed', agent_id: 'agent-2', status: 'online',
@@ -401,6 +500,8 @@ describe('event-format', () => {
401
500
  visible_corpses: [{
402
501
  player: { name: 'fallen', seat: 3 },
403
502
  room: '情报室',
503
+ x: 60,
504
+ y: 100,
404
505
  distance: 8.44,
405
506
  agent_id: 'must-not-leak',
406
507
  }],
@@ -431,6 +532,7 @@ describe('event-format', () => {
431
532
  name: 'fallen',
432
533
  seat: 3,
433
534
  room: '情报室',
535
+ relative_direction: '左',
434
536
  distance_px: 8.4,
435
537
  }]);
436
538
  expect(state?.crab_sabotage).toEqual({
@@ -455,7 +557,8 @@ describe('event-format', () => {
455
557
  expect(state?.visible_players[0]).not.toHaveProperty('y');
456
558
  expect(state?.visible_players[0]).not.toHaveProperty('role');
457
559
  expect(state?.nearby_corpses[0]).not.toHaveProperty('agent_id');
458
- expect(state?.nearby_corpses[0]).not.toHaveProperty('relative_direction');
560
+ expect(state?.nearby_corpses[0]).not.toHaveProperty('x');
561
+ expect(state?.nearby_corpses[0]).not.toHaveProperty('y');
459
562
  });
460
563
 
461
564
  it('omits a malformed known-player roster instead of returning partial evidence', () => {
@@ -1,6 +1,7 @@
1
1
  import { projectPlayers } from './player-projection.js';
2
2
  import { headingDirection } from '../runtime/clawclaw/plugins/perception/shared/math.js';
3
3
  import { isRoomMode } from '../lib/room.js';
4
+ import { isSelfKillerMurderWitnessed } from './event-hints.js';
4
5
 
5
6
  export interface EventFormatContext {
6
7
  summary?: any | null;
@@ -121,7 +122,7 @@ function projectCurrentScene(
121
122
  };
122
123
  return cleanObject({
123
124
  visible_players: projectList(summary.visible_players, true),
124
- nearby_corpses: projectList(summary.visible_corpses, false),
125
+ nearby_corpses: projectList(summary.visible_corpses, true),
125
126
  });
126
127
  }
127
128
 
@@ -328,6 +329,9 @@ function playersChangedBody(event: Record<string, any>, ctx: EventFormatContext)
328
329
  if (change.change === 'discovered') {
329
330
  return `发现${playerLabel(change.name, numberValue(change.seat), ctx)}`;
330
331
  }
332
+ if (change.change === 'status_changed') {
333
+ return `${playerLabel(change.name, numberValue(change.seat), ctx)}状态由${text(change.from_status)}变为${text(change.to_status)}`;
334
+ }
331
335
  const death = playerChangeDeathText(change, ctx);
332
336
  return change.change === 'death_updated' ? `${death}(死亡信息更新)` : death;
333
337
  }).join(';');
@@ -373,6 +377,9 @@ function shortBody(event: Record<string, any>, ctx: EventFormatContext): string
373
377
  case 'killed':
374
378
  return `你在${firstString(event, ['room'])}被${killerLabel(event.killer_name, firstNumber(event, ['killer_seat', 'killer_player_seat']), event.killer_kind, ctx)}击杀了,你已死亡。`;
375
379
  case 'murder_witnessed':
380
+ if (isSelfKillerMurderWitnessed(event, ctx.summary)) {
381
+ return '收到一条与自身击杀身份冲突的 murder_witnessed 事件;该事件已降级为诊断信息,不能据此判断任何目击者。';
382
+ }
376
383
  return `你在${firstString(event, ['room'])}目击${playerLabel(event.killer_name, firstNumber(event, ['killer_seat', 'killer_player_seat']), ctx)}击杀${playerLabel(event.target_name, firstNumber(event, ['target_seat', 'target_player_seat']), ctx)}。`;
377
384
  case 'warrior_shrimp_self_destruct':
378
385
  return `你误杀了${playerLabel(event.target_name, firstNumber(event, ['target_seat', 'target_player_seat']), ctx)},武士虾自爆出局。`;
@@ -396,12 +403,13 @@ function shortBody(event: Record<string, any>, ctx: EventFormatContext): string
396
403
  }
397
404
  case 'task_sabotaged':
398
405
  return `破坏任务完成:${firstString(event, ['task_name'])}(${firstString(event, ['room'])})。`;
406
+ case 'tasks_changed':
407
+ return `任务列表已更新(${firstString(event, ['reason'])})。`;
399
408
  case 'players_changed':
400
409
  return playersChangedBody(event, ctx);
401
410
  case 'move_interrupted': {
402
411
  const nearby = Array.isArray(event.nearby_players)
403
412
  ? event.nearby_players
404
- .slice(0, 3)
405
413
  .map((player: any) => playerLabel(player?.name, numberValue(player?.seat), ctx))
406
414
  .filter(Boolean)
407
415
  : [];
@@ -571,6 +579,35 @@ function shortBody(event: Record<string, any>, ctx: EventFormatContext): string
571
579
  return `发言提示:${truncate(event.message ?? event.text, maxTextLength)}`;
572
580
  case 'strategy_alert':
573
581
  return truncate(event.message ?? event.text, maxTextLength);
582
+ case 'behavior.started':
583
+ case 'behavior.restarted':
584
+ case 'behavior.suspended':
585
+ case 'behavior.completed':
586
+ case 'behavior.failed':
587
+ case 'behavior.cancelled':
588
+ case 'behavior.replaced': {
589
+ const behavior = text(event.behavior, 'behavior');
590
+ const layer = typeof event.layer === 'string' && event.layer.length > 0
591
+ ? `(${event.layer})`
592
+ : '';
593
+ const action = event.type === 'behavior.started'
594
+ ? '已启动'
595
+ : event.type === 'behavior.restarted'
596
+ ? '已重新启动'
597
+ : event.type === 'behavior.suspended'
598
+ ? '已暂停'
599
+ : event.type === 'behavior.completed'
600
+ ? '已完成'
601
+ : event.type === 'behavior.failed'
602
+ ? '执行失败'
603
+ : event.type === 'behavior.cancelled'
604
+ ? '已取消'
605
+ : '已被替换';
606
+ const reason = typeof event.reason === 'string' && event.reason.length > 0
607
+ ? `:${event.reason}`
608
+ : '';
609
+ return `${behavior}${layer}${action}${reason}`;
610
+ }
574
611
  case 'game_start':
575
612
  return '事件流已连接,等待身份分配。';
576
613
  case 'heartbeat':
@@ -605,12 +642,18 @@ function taskKindForEvents(task: any, event: Record<string, any>): string | unde
605
642
  }
606
643
 
607
644
  function compactRoleAssignedForEvents(event: Record<string, any>): FormattedEvent {
608
- const tasks = Array.isArray(event.assigned_tasks)
609
- ? event.assigned_tasks.map((task: any) => cleanObject({
645
+ const sourceTasks = Array.isArray(event.tasks)
646
+ ? event.tasks
647
+ : Array.isArray(event.assigned_tasks) ? event.assigned_tasks : undefined;
648
+ const tasks = Array.isArray(sourceTasks)
649
+ ? sourceTasks.map((task: any) => cleanObject({
650
+ task_id: task?.task_id,
610
651
  name: task?.name,
611
652
  room: task?.room,
612
653
  x: task?.x,
613
654
  y: task?.y,
655
+ status: task?.status,
656
+ task_note: task?.task_note,
614
657
  kind: taskKindForEvents(task, event),
615
658
  }))
616
659
  : undefined;
@@ -637,6 +680,8 @@ function compactRoleAssignedForEvents(event: Record<string, any>): FormattedEven
637
680
  task_kind: useTopLevelTaskKind ? taskKinds[0] : undefined,
638
681
  task_note: hasFakeTask ? 'Fake shrimp tasks: disguise only; no lobster progress.' : undefined,
639
682
  tasks: compactTasks,
683
+ reason: event.reason,
684
+ delta: event.delta,
640
685
  });
641
686
  }
642
687
 
@@ -689,6 +734,8 @@ function compactPlayersChangedForEvents(event: Record<string, any>): FormattedEv
689
734
  seat: numberValue(change.seat),
690
735
  cause: change.cause,
691
736
  killer: change.killer,
737
+ from_status: change.from_status,
738
+ to_status: change.to_status,
692
739
  }))
693
740
  : [];
694
741
  const players = Array.isArray(event.players)
@@ -713,6 +760,7 @@ function compactPlayersChangedForEvents(event: Record<string, any>): FormattedEv
713
760
  tick: numberValue(event.tick) ?? null,
714
761
  meeting: event.meeting === true ? true : undefined,
715
762
  meeting_count: numberValue(event.meeting_count),
763
+ reason: event.reason,
716
764
  changes,
717
765
  players,
718
766
  });
@@ -736,6 +784,14 @@ export function compactEventForEvents(
736
784
  if (event.type === 'vote_cast') return compactVoteCastForEvents(event, ctx);
737
785
  if (event.type === 'exile' || event.type === 'no_exile') return compactMeetingResultForEvents(event, ctx);
738
786
  if (event.type === 'players_changed') return compactPlayersChangedForEvents(event);
787
+ if (event.type === 'task_completed' && Array.isArray(event.tasks) && Array.isArray(event.delta)) {
788
+ const { newly_assigned_task: _duplicateAssignment, ...rest } = event;
789
+ return cleanObject({
790
+ ...rest,
791
+ type: text(rest.type, 'event'),
792
+ tick: numberValue(rest.tick) ?? null,
793
+ });
794
+ }
739
795
 
740
796
  return cleanObject({
741
797
  ...event,
@@ -744,6 +800,14 @@ export function compactEventForEvents(
744
800
  });
745
801
  }
746
802
 
803
+ /** Realtime adapters share the authoritative structured Agent projection. */
804
+ export function compactEventForChannel(
805
+ event: Record<string, any>,
806
+ ctx: EventFormatContext = {},
807
+ ): FormattedEvent {
808
+ return compactEventForEvents(event, ctx);
809
+ }
810
+
747
811
  export function compactEventFields(
748
812
  event: Record<string, any>,
749
813
  ctx: EventFormatContext = {},
@@ -755,6 +819,110 @@ export function compactEventFields(
755
819
  });
756
820
  }
757
821
 
822
+ /** Compact, decision-oriented projection used by realtime Agent adapters. */
823
+ export function compactStateForChannel(
824
+ summary: any | null | undefined,
825
+ events: Array<Record<string, any>> = [],
826
+ ): Record<string, any> | null {
827
+ if (!summary || typeof summary !== 'object') return null;
828
+ if (typeof summary.phase === 'string' && summary.phase.startsWith('room_')) {
829
+ const room = summary.room ?? {};
830
+ const you = summary.you ?? {};
831
+ return cleanObject({
832
+ phase: summary.phase,
833
+ you: cleanObject({
834
+ name: you.name,
835
+ seat: you.seat,
836
+ is_owner: you.is_owner,
837
+ }),
838
+ room: cleanObject({
839
+ room_code: room.room_code,
840
+ room_type: room.room_type,
841
+ status: room.status,
842
+ member_count: room.member_count,
843
+ deadline: room.deadline,
844
+ idle_destroy_at: room.idle_destroy_at,
845
+ is_owner: room.is_owner,
846
+ ready_to_start: room.ready_to_start,
847
+ role_config: room.role_config,
848
+ role_lock_character_id: room.role_lock_character_id,
849
+ members: room.members,
850
+ game_id: room.game_id,
851
+ game_server_name: room.game_server_name,
852
+ }),
853
+ recent_events: events.slice(-10).map((event) => cleanObject({
854
+ type: event.type,
855
+ room_code: event.room_code,
856
+ name: event.name,
857
+ agent_id: event.agent_id,
858
+ seat: event.seat,
859
+ status: event.status,
860
+ content: event.content,
861
+ reason: event.reason,
862
+ destroy_at: event.destroy_at,
863
+ close_code: event.close_code,
864
+ seconds_remaining: event.seconds_remaining,
865
+ })),
866
+ automation: summary.automation,
867
+ });
868
+ }
869
+ const you = summary.you ?? {};
870
+ const meeting = summary.meeting ?? null;
871
+ const crabSabotage = summary.crab_sabotage && typeof summary.crab_sabotage === 'object'
872
+ && !Array.isArray(summary.crab_sabotage)
873
+ ? summary.crab_sabotage
874
+ : null;
875
+ const votesSubmitted = Array.isArray(meeting?.votes_submitted) ? meeting.votes_submitted : undefined;
876
+ const knownPlayers = projectKnownPlayers(summary.players);
877
+ const currentScene = projectCurrentScene(summary, knownPlayers ?? projectPlayers({ summary }));
878
+ return cleanObject({
879
+ phase: summary.phase,
880
+ tick: summary.tick,
881
+ you: cleanObject({
882
+ name: you.player?.name,
883
+ seat: you.player?.seat,
884
+ role: you.role,
885
+ faction: you.faction,
886
+ alive: you.is_alive,
887
+ room: you.room,
888
+ kill_cooldown_secs: you.kill_cooldown_secs,
889
+ activity: you.activity,
890
+ tasks: Array.isArray(you.tasks) ? you.tasks : undefined,
891
+ crab_teammates: Array.isArray(you.crab_teammates)
892
+ ? teammateObjects({ crab_teammates: you.crab_teammates }, { summary })
893
+ : undefined,
894
+ }),
895
+ game: cleanObject({
896
+ alive_count: Array.isArray(summary.players)
897
+ ? summary.players.filter((player: any) => player?.known_status?.is_alive !== false).length
898
+ : undefined,
899
+ task_progress: summary.task_progress,
900
+ winner: summary.winner,
901
+ settlement: summary.settlement,
902
+ }),
903
+ players: knownPlayers,
904
+ ...currentScene,
905
+ meeting: meeting?.active === true
906
+ ? cleanObject({
907
+ caller: meeting.caller,
908
+ sub_phase: meeting.sub_phase,
909
+ current_speaker: meeting.current_speaker,
910
+ is_my_turn: meeting.current_speaker?.seat !== undefined
911
+ && meeting.current_speaker.seat === you.player?.seat,
912
+ votes_submitted_count: votesSubmitted?.length,
913
+ })
914
+ : undefined,
915
+ crab_sabotage: crabSabotage
916
+ ? cleanObject({
917
+ status: stringValue(crabSabotage.status),
918
+ cooldown_remaining_secs: numberValue(crabSabotage.cooldown_remaining_secs),
919
+ })
920
+ : undefined,
921
+ urgent: summary.urgent,
922
+ automation: summary.automation,
923
+ });
924
+ }
925
+
758
926
  export function compactStateForEvents(
759
927
  summary: any | null | undefined,
760
928
  events: Array<Record<string, any>> = [],
@@ -56,7 +56,7 @@ describe('Mailbox-owned Event hint registries', () => {
56
56
  )).toContain('Do not retry matchmaking');
57
57
  });
58
58
 
59
- it('classifies Source and Derived lifecycle Events with players_changed factual-only', () => {
59
+ it('classifies Source and Derived lifecycle Events with list changes factual-only', () => {
60
60
  const excluded = new Set(['robot_speak_rule', 'strategy_alert']);
61
61
  const sourceTypes = CLAWCLAW_LOCAL_AGENT_EVENT_TYPES.filter((type) => (
62
62
  type !== 'room_ready_to_start' && !excluded.has(type)
@@ -74,7 +74,15 @@ describe('Mailbox-owned Event hint registries', () => {
74
74
  'quit_failed',
75
75
  'room_attached',
76
76
  'room_ping_timeout',
77
+ 'behavior.started',
78
+ 'behavior.suspended',
79
+ 'behavior.restarted',
80
+ 'behavior.completed',
81
+ 'behavior.failed',
82
+ 'behavior.cancelled',
83
+ 'behavior.replaced',
77
84
  'players_changed',
85
+ 'tasks_changed',
78
86
  ]);
79
87
  });
80
88
 
@@ -115,7 +123,31 @@ describe('Mailbox-owned Event hint registries', () => {
115
123
  )).toBeUndefined();
116
124
  });
117
125
 
118
- it('uses producerPluginId to exclude Strategy, Perception, and unknown local plugins', () => {
126
+ it('does not present a self-killer murder_witnessed anomaly as witness evidence', () => {
127
+ const event = {
128
+ type: 'murder_witnessed',
129
+ killer_name: 'self',
130
+ killer_seat: 1,
131
+ target_name: 'target',
132
+ target_seat: 2,
133
+ };
134
+ const downgraded = formatCanonicalEventHint(
135
+ { producer: 'backend_push' },
136
+ event,
137
+ { summary: { you: { player: { name: 'self', seat: 1 } } } },
138
+ );
139
+ expect(downgraded).toContain('IGNORE AS WITNESS EVIDENCE');
140
+ expect(downgraded).toContain('Do not infer any witness or observer');
141
+ expect(downgraded).not.toContain('You saw');
142
+
143
+ expect(formatCanonicalEventHint(
144
+ { producer: 'backend_push' },
145
+ event,
146
+ { summary: { you: { player: { name: 'observer', seat: 3 } } } },
147
+ )).toContain('You saw self kill target');
148
+ });
149
+
150
+ it('uses producerPluginId to exclude Behavior, Perception, and unknown local plugins', () => {
119
151
  const event = { type: 'match_timeout', waited_secs: 300 };
120
152
 
121
153
  expect(formatCanonicalEventHint({ producer: 'local_synth' }, event)).toContain('300s');
@@ -125,7 +157,7 @@ describe('Mailbox-owned Event hint registries', () => {
125
157
  }, event)).toContain('300s');
126
158
  expect(formatCanonicalEventHint({
127
159
  producer: 'local_synth',
128
- producerPluginId: 'clawclaw.strategy',
160
+ producerPluginId: 'clawclaw.behavior',
129
161
  }, event)).toBeUndefined();
130
162
  expect(formatCanonicalEventHint({
131
163
  producer: 'local_synth',
@@ -171,7 +203,7 @@ describe('Mailbox-owned Event hint registries', () => {
171
203
  type: 'game_start_failed',
172
204
  game_mode: 'competition',
173
205
  error: { code: 'ALREADY_IN_GAME' },
174
- })).toContain('Reconnect or continue');
206
+ })).toContain('`ccl join`');
175
207
  expect(formatCanonicalEventHint(origin, {
176
208
  type: 'game_start_failed',
177
209
  game_mode: 'competition',
@@ -179,6 +211,27 @@ describe('Mailbox-owned Event hint registries', () => {
179
211
  })).toContain('Do not start normal matchmaking');
180
212
  });
181
213
 
214
+ it('uses top-level start and join commands for lifecycle recovery guidance', () => {
215
+ const notInQueue = LOCAL_LIFECYCLE_EVENT_HINT_FORMATTERS.not_in_queue({}, {});
216
+ const matchTimeout = LOCAL_LIFECYCLE_EVENT_HINT_FORMATTERS.match_timeout({
217
+ waited_secs: 300,
218
+ }, {});
219
+ const roomRecovery = LOCAL_LIFECYCLE_EVENT_HINT_FORMATTERS.room_lobby_reconnect_failed({}, {});
220
+ const existingGame = LOCAL_LIFECYCLE_EVENT_HINT_FORMATTERS.game_start_failed({
221
+ game_mode: 'competition',
222
+ error: { code: 'ALREADY_IN_GAME' },
223
+ }, {});
224
+
225
+ expect(notInQueue).toContain('`ccl start match`');
226
+ expect(matchTimeout).toContain('`ccl start match`');
227
+ expect(roomRecovery).toContain('`ccl load`');
228
+ expect(roomRecovery).toContain('`ccl join`');
229
+ expect(existingGame).toContain('`ccl load`');
230
+ expect(existingGame).toContain('`ccl join`');
231
+ expect([notInQueue, matchTimeout, roomRecovery, existingGame].join('\n'))
232
+ .not.toContain('`ccl game start`');
233
+ });
234
+
182
235
  it('preserves the useful incremental semantics from npm batch next_step routes', () => {
183
236
  expect(BACKEND_EVENT_HINT_FORMATTERS.game_started({}, {})).toContain('do not relaunch');
184
237
 
@@ -34,6 +34,30 @@ function numberValue(value: unknown): number | undefined {
34
34
  return undefined;
35
35
  }
36
36
 
37
+ function nonEmptyString(value: unknown): string | undefined {
38
+ return typeof value === 'string' && value.length > 0 ? value : undefined;
39
+ }
40
+
41
+ /** Defensive recipient check for a backend event that contradicts witness semantics. */
42
+ export function isSelfKillerMurderWitnessed(
43
+ event: Record<string, any>,
44
+ summary: any | null | undefined,
45
+ ): boolean {
46
+ if (event.type !== 'murder_witnessed') return false;
47
+ const killerSeat = firstNumber(event, ['killer_seat', 'killer_player_seat']);
48
+ const selfSeat = numberValue(
49
+ summary?.you?.player?.seat
50
+ ?? summary?.you?.seat
51
+ ?? summary?.my_seat,
52
+ );
53
+ if (killerSeat !== undefined && selfSeat !== undefined) return killerSeat === selfSeat;
54
+
55
+ const killerName = nonEmptyString(event.killer_name);
56
+ const selfName = nonEmptyString(summary?.you?.player?.name)
57
+ ?? nonEmptyString(summary?.you?.name);
58
+ return killerName !== undefined && selfName !== undefined && killerName === selfName;
59
+ }
60
+
37
61
  function firstString(event: Record<string, any>, keys: string[], fallback = '?'): string {
38
62
  for (const key of keys) {
39
63
  const value = event[key];
@@ -136,7 +160,7 @@ export const BACKEND_EVENT_HINT_FORMATTERS: Readonly<Record<string, EventHintFor
136
160
  game_started: (event) => {
137
161
  const playerCount = numberValue(event.player_count);
138
162
  const countText = playerCount === undefined ? 'Game started.' : `Game started with ${playerCount} players.`;
139
- return `${countText} Use \`ccl events\` for opening map, seat, role, and task details. The runtime is already attached; do not relaunch.`;
163
+ return `${countText} Opening map, seat, role, and task details are included in the full Event delivery. The runtime is already attached; do not relaunch.`;
140
164
  },
141
165
  role_assigned: (event) => roleAssignedHint(event),
142
166
  kill: (event) => (
@@ -146,9 +170,11 @@ export const BACKEND_EVENT_HINT_FORMATTERS: Readonly<Record<string, EventHintFor
146
170
  killed: (event) => (
147
171
  `YOU ARE DEAD: ${optionalSeatPlayerLabel(event.killer_name, firstNumber(event, ['killer_seat', 'killer_player_seat']))} removed you from play.`
148
172
  ),
149
- murder_witnessed: (event) => (
150
- `WITNESS: You saw ${text(event.killer_name, 'someone')} kill ${text(event.target_name, 'someone')}. `
151
- + 'This is hard evidence; survive, report, or weaponize it.'
173
+ murder_witnessed: (event, ctx) => (
174
+ isSelfKillerMurderWitnessed(event, ctx.summary)
175
+ ? 'IGNORE AS WITNESS EVIDENCE: this event conflicts with the recipient identity and was downgraded. Do not infer any witness or observer from it; rely on the separate kill Event and current State.'
176
+ : `WITNESS: You saw ${text(event.killer_name, 'someone')} kill ${text(event.target_name, 'someone')}. `
177
+ + 'This is hard evidence; survive, report, or weaponize it.'
152
178
  ),
153
179
  warrior_shrimp_self_destruct: (event) => (
154
180
  `You executed ${text(event.target_name, 'a teammate')}, but they were a fellow Lobster. `
@@ -249,7 +275,7 @@ export const LOCAL_LIFECYCLE_EVENT_HINT_FORMATTERS: Readonly<Record<string, Even
249
275
  : "Share this Event's spectate_url with the user as the room link and keep the room runtime attached.";
250
276
  },
251
277
  not_in_queue: () => (
252
- 'This account is no longer in the matchmaking queue. The runtime is exiting; start a fresh `ccl game start` only if the user wants to continue.'
278
+ 'This account is no longer in the matchmaking queue. The runtime is exiting; launch a fresh `ccl start match` only if the user wants to continue.'
253
279
  ),
254
280
  poll_error: (event) => (
255
281
  event.retrying === true
@@ -271,7 +297,7 @@ export const LOCAL_LIFECYCLE_EVENT_HINT_FORMATTERS: Readonly<Record<string, Even
271
297
  case 'COMPETITION_NOT_OPEN':
272
298
  return 'Tell the user competition is not open now and use `competition.daily_windows` for the opening windows. Do not start normal matchmaking unless the user asks.';
273
299
  case 'ALREADY_IN_GAME':
274
- return 'Tell the user this account is already in a game. Reconnect or continue the existing game instead of starting another match.';
300
+ return 'Tell the user this account is already in a game. Run `ccl load` to confirm the existing participation, then attach with `ccl join` instead of starting another match.';
275
301
  default:
276
302
  return 'Tell the user competition matchmaking failed. Do not start normal matchmaking unless the user asks.';
277
303
  }
@@ -297,7 +323,7 @@ export const LOCAL_LIFECYCLE_EVENT_HINT_FORMATTERS: Readonly<Record<string, Even
297
323
  'Still in queue (see `waited_secs`). Keep chatting with the user; no tactical action is required.'
298
324
  ),
299
325
  match_timeout: (event) => (
300
- `Matchmaking timed out after ${text(event.waited_secs, '?')}s and this runtime is exiting. Ask whether the user wants to launch a fresh \`ccl game start\` or end the session.`
326
+ `Matchmaking timed out after ${text(event.waited_secs, '?')}s and this runtime is exiting. Ask whether the user wants to launch a fresh \`ccl start match\` or end the session.`
301
327
  ),
302
328
  user_left_game: (event, ctx) => (
303
329
  isRoomGameEvent(event, ctx)
@@ -305,7 +331,7 @@ export const LOCAL_LIFECYCLE_EVENT_HINT_FORMATTERS: Readonly<Record<string, Even
305
331
  : 'The user left this game from the web page. Stop playing and do not start another match unless the user asks.'
306
332
  ),
307
333
  room_lobby_reconnect_failed: () => (
308
- 'The room round ended, but Lobby reattachment failed. Ask the user whether to launch `ccl game start` to reattach or leave the room.'
334
+ 'The room round ended, but Lobby reattachment failed and this runtime is exiting. Ask whether to recover or leave the room; to recover, run `ccl load` and, if participation still exists, attach with `ccl join`. Do not start normal matchmaking.'
309
335
  ),
310
336
  room_lobby_missing: () => (
311
337
  'The room round ended and the account is no longer in the familiar room. Do not start normal matchmaking; ask the user what to do next.'
@@ -558,6 +558,7 @@ describe('CanonicalMonitor', () => {
558
558
  schema: 'ccl.monitor.v1',
559
559
  mode: 'short',
560
560
  events: [{ type: 'speech', event_id: 'evt-1', text: 'x'.repeat(1_000) }],
561
+ details_required: ['speech'],
561
562
  messages: ['m'.repeat(1_000)],
562
563
  state: 's'.repeat(1_000),
563
564
  guidance: `Take the next legal action: ${'g'.repeat(1_000)}`,
@@ -568,6 +569,7 @@ describe('CanonicalMonitor', () => {
568
569
  schema: 'ccl.monitor.v1',
569
570
  mode: 'short',
570
571
  events: [{ type: 'speech' }],
572
+ details_required: ['speech'],
571
573
  truncated: true,
572
574
  });
573
575
  expect(oversized.messages[0]).toHaveLength(1_000);