@myclaw163/clawclaw-cli 0.8.4 → 0.8.6

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 (330) hide show
  1. package/README.md +4 -3
  2. package/docs/configuration.md +44 -26
  3. package/docs/custom-modules/README.md +7 -10
  4. package/docs/custom-modules/behavior.md +10 -19
  5. package/docs/custom-modules/perception.md +1 -1
  6. package/docs/custom-modules/trigger.md +1 -1
  7. package/docs/runtime/README.md +4 -4
  8. package/docs/runtime/official-perception-modules.md +2 -2
  9. package/docs/runtime/owner-lifecycle-and-observability.md +1 -1
  10. package/package.json +15 -2
  11. package/scripts/enable_ccl_permissions.cjs +4 -2
  12. package/scripts/find-hide-spots.py +2 -2
  13. package/scripts/postinstall.mjs +1 -4
  14. package/scripts/sync-bundled-skill.mjs +12 -159
  15. package/skills/clawclaw/SKILL.md +25 -18
  16. package/skills/clawclaw/references/BEHAVIORS.md +15 -11
  17. package/skills/clawclaw/references/COMMANDS.md +45 -41
  18. package/skills/clawclaw/references/HUB.md +25 -38
  19. package/skills/clawclaw/references/TACTICS.md +1 -1
  20. package/src/commands/account.ts +58 -14
  21. package/src/commands/behavior.ts +116 -38
  22. package/src/commands/hub.ts +110 -153
  23. package/src/commands/load.ts +138 -33
  24. package/src/commands/perception.ts +55 -24
  25. package/src/commands/persona.ts +66 -20
  26. package/src/commands/skill.ts +12 -48
  27. package/src/commands/trigger.ts +68 -40
  28. package/src/lib/account-guidance.ts +54 -9
  29. package/src/lib/agent-workspace-client.ts +135 -0
  30. package/src/lib/agent-workspace-runtime.ts +154 -0
  31. package/src/lib/agent-workspace-skills.ts +177 -0
  32. package/src/lib/agent-workspace-sync.ts +852 -0
  33. package/src/lib/gameplay-config.ts +29 -15
  34. package/src/lib/hub-client.ts +252 -34
  35. package/src/lib/hub-reminder.ts +24 -11
  36. package/src/lib/init-command.ts +0 -6
  37. package/src/lib/load-context.ts +12 -6
  38. package/src/lib/persona.ts +141 -69
  39. package/src/lib/server-status.ts +78 -0
  40. package/src/lib/skill-host.ts +160 -0
  41. package/src/lib/user-data.ts +197 -4
  42. package/src/runtime/clawclaw/behavior-read-api.ts +1 -1
  43. package/src/{strategies/pathfind → runtime/clawclaw/navigation}/astar-path.ts +1 -1
  44. package/src/{strategies/pathfind → runtime/clawclaw/navigation}/escape-planner.ts +1 -1
  45. package/src/{strategies → runtime/clawclaw/navigation}/hide-spots.ts +2 -2
  46. package/src/{strategies → runtime/clawclaw/navigation}/off-route-points.ts +6 -3
  47. package/src/{strategies/pathfind → runtime/clawclaw/navigation}/walkable-grid.ts +1 -1
  48. package/src/runtime/clawclaw/owner.ts +63 -19
  49. package/src/runtime/clawclaw/plugins/behavior/activation-manager.ts +8 -2
  50. package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.ts +2 -2
  51. package/src/runtime/clawclaw/plugins/game-query/game-query-plugin.ts +1 -1
  52. package/src/runtime/clawclaw/plugins/perception/perception-plugin.ts +4 -1
  53. package/src/runtime/clawclaw/plugins/perception/perception-source.ts +11 -5
  54. package/src/runtime/clawclaw/plugins/perception/replay.ts +0 -2
  55. package/src/runtime/framework/modules/runtime-module-loader.ts +0 -54
  56. package/src/sdk/behavior-toolkit/escape.ts +2 -2
  57. package/personas//345/217/243/346/230/257/345/277/203/351/235/236.md +0 -50
  58. package/personas//345/277/240/345/277/203/350/200/201/344/273/206.md +0 -51
  59. package/personas//346/227/240/344/272/272/350/256/276.md +0 -1
  60. package/personas//350/264/253/345/230/264/346/215/237/345/217/213.md +0 -48
  61. package/personas//350/275/257/350/220/214/350/205/271/351/273/221.md +0 -51
  62. package/scripts/compare-perception-replays.test.ts +0 -188
  63. package/scripts/enable_ccl_permissions.test.mjs +0 -163
  64. package/scripts/enable_monitor.test.mjs +0 -201
  65. package/scripts/sync-bundled-skill.test.mjs +0 -152
  66. package/scripts/watch-perception-events.test.ts +0 -43
  67. package/src/behaviors/official-finite/do-task.ts +0 -211
  68. package/src/behaviors/official-finite/evade.ts +0 -78
  69. package/src/behaviors/official-finite/find-player.ts +0 -50
  70. package/src/behaviors/official-finite/follow-player.ts +0 -70
  71. package/src/behaviors/official-finite/go-to.ts +0 -69
  72. package/src/behaviors/official-finite/hide-temporarily.ts +0 -77
  73. package/src/behaviors/official-finite/hold-position.ts +0 -48
  74. package/src/behaviors/official-finite/hunt-player.ts +0 -47
  75. package/src/behaviors/official-finite/index.test.ts +0 -249
  76. package/src/behaviors/official-finite/index.ts +0 -44
  77. package/src/behaviors/official-finite/inspect-corpse.ts +0 -64
  78. package/src/behaviors/official-finite/patrol-area.ts +0 -80
  79. package/src/behaviors/official-finite/report-corpse.ts +0 -73
  80. package/src/behaviors/official-finite/seek-kill-opportunity.ts +0 -152
  81. package/src/behaviors/official-finite/shared.ts +0 -27
  82. package/src/channel/claude-channel-server.test.ts +0 -202
  83. package/src/commands/account.test.ts +0 -570
  84. package/src/commands/behavior.test.ts +0 -158
  85. package/src/commands/communication.test.ts +0 -282
  86. package/src/commands/competition.test.ts +0 -116
  87. package/src/commands/data.test.ts +0 -89
  88. package/src/commands/events-canonical-state.test.ts +0 -406
  89. package/src/commands/events.test.ts +0 -58
  90. package/src/commands/game/index.test.ts +0 -1251
  91. package/src/commands/game-map.test.ts +0 -69
  92. package/src/commands/hub.test.ts +0 -124
  93. package/src/commands/load.test.ts +0 -440
  94. package/src/commands/perception.test.ts +0 -75
  95. package/src/commands/setup/hermes.test.ts +0 -96
  96. package/src/commands/setup/openclaw.test.ts +0 -124
  97. package/src/commands/trigger.test.ts +0 -140
  98. package/src/commands/upgrade.test.ts +0 -82
  99. package/src/lib/account-guidance.test.ts +0 -36
  100. package/src/lib/auth.test.ts +0 -151
  101. package/src/lib/behavior-export.test.ts +0 -326
  102. package/src/lib/behavior-export.ts +0 -537
  103. package/src/lib/clawclaw-skill-spectate-guidance.test.ts +0 -21
  104. package/src/lib/custom-tts.test.ts +0 -387
  105. package/src/lib/diagnostics-config.test.ts +0 -59
  106. package/src/lib/game-client-tts.test.ts +0 -151
  107. package/src/lib/game-client.test.ts +0 -250
  108. package/src/lib/gameplay-config.test.ts +0 -301
  109. package/src/lib/host-config-patcher.test.ts +0 -130
  110. package/src/lib/http-transport.test.ts +0 -124
  111. package/src/lib/hub-client.test.ts +0 -57
  112. package/src/lib/hub-install.test.ts +0 -135
  113. package/src/lib/hub-install.ts +0 -185
  114. package/src/lib/hub-unzip.test.ts +0 -69
  115. package/src/lib/init-command.test.ts +0 -103
  116. package/src/lib/load-context.test.ts +0 -62
  117. package/src/lib/match-state.test.ts +0 -134
  118. package/src/lib/official-resource-sync.test.ts +0 -199
  119. package/src/lib/official-resource-sync.ts +0 -221
  120. package/src/lib/perception-config.test.ts +0 -143
  121. package/src/lib/perception-export.test.ts +0 -145
  122. package/src/lib/perception-export.ts +0 -178
  123. package/src/lib/persona.test.ts +0 -84
  124. package/src/lib/room.test.ts +0 -88
  125. package/src/lib/server-registry.test.ts +0 -64
  126. package/src/lib/service-status.test.ts +0 -81
  127. package/src/lib/skill-version.test.ts +0 -48
  128. package/src/lib/trigger-config.test.ts +0 -102
  129. package/src/lib/trigger-export.test.ts +0 -80
  130. package/src/lib/trigger-export.ts +0 -210
  131. package/src/lib/user-data.test.ts +0 -121
  132. package/src/lib/workspace-argv.test.ts +0 -49
  133. package/src/pipeline/canonical-event-presentation.test.ts +0 -257
  134. package/src/pipeline/event-format.test.ts +0 -879
  135. package/src/pipeline/event-hints.test.ts +0 -337
  136. package/src/pipeline/game-sync-event-normalization.test.ts +0 -419
  137. package/src/pipeline/player-projection.test.ts +0 -247
  138. package/src/runtime/auto-upgrade.test.ts +0 -66
  139. package/src/runtime/canonical-event-emitter.test.ts +0 -70
  140. package/src/runtime/canonical-monitor.test.ts +0 -577
  141. package/src/runtime/clawclaw/agent-event-policy.test.ts +0 -60
  142. package/src/runtime/clawclaw/behavior-decision.test.ts +0 -43
  143. package/src/runtime/clawclaw/behavior-input-fields.test.ts +0 -175
  144. package/src/runtime/clawclaw/behavior-input.test.ts +0 -173
  145. package/src/runtime/clawclaw/behavior-observation-memory.test.ts +0 -59
  146. package/src/runtime/clawclaw/behavior-read-api.test.ts +0 -123
  147. package/src/runtime/clawclaw/notifications.test.ts +0 -47
  148. package/src/runtime/clawclaw/owner-lock.test.ts +0 -221
  149. package/src/runtime/clawclaw/owner.test.ts +0 -203
  150. package/src/runtime/clawclaw/plugins/action/action-plugin.test.ts +0 -328
  151. package/src/runtime/clawclaw/plugins/assembly.test.ts +0 -200
  152. package/src/runtime/clawclaw/plugins/behavior/activation-manager.test.ts +0 -180
  153. package/src/runtime/clawclaw/plugins/behavior/behavior-action.test.ts +0 -43
  154. package/src/runtime/clawclaw/plugins/behavior/behavior-catalog.test.ts +0 -156
  155. package/src/runtime/clawclaw/plugins/behavior/behavior-module-loader.test.ts +0 -182
  156. package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.test.ts +0 -1094
  157. package/src/runtime/clawclaw/plugins/behavior/behavior-source.test.ts +0 -174
  158. package/src/runtime/clawclaw/plugins/behavior/control-driver.test.ts +0 -195
  159. package/src/runtime/clawclaw/plugins/behavior/official-goal-behavior.ts +0 -757
  160. package/src/runtime/clawclaw/plugins/behavior/thread-behavior-executor.test.ts +0 -283
  161. package/src/runtime/clawclaw/plugins/behavior-input-source.test.ts +0 -80
  162. package/src/runtime/clawclaw/plugins/derived-event/derived-event-plugin.test.ts +0 -267
  163. package/src/runtime/clawclaw/plugins/game-query/game-query-plugin.test.ts +0 -226
  164. package/src/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-adapter.test.ts +0 -239
  165. package/src/runtime/clawclaw/plugins/mailbox/agent-mailbox-coordinator.test.ts +0 -407
  166. package/src/runtime/clawclaw/plugins/mailbox/desktop-event-push.integration.test.ts +0 -397
  167. package/src/runtime/clawclaw/plugins/mailbox/desktop-event-socket.test.ts +0 -270
  168. package/src/runtime/clawclaw/plugins/mailbox/mailbox-agent-event-batch.test.ts +0 -166
  169. package/src/runtime/clawclaw/plugins/mailbox/mailbox-event-batch-delivery.test.ts +0 -194
  170. package/src/runtime/clawclaw/plugins/mailbox/mailbox-plugin.test.ts +0 -87
  171. package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.test.ts +0 -2012
  172. package/src/runtime/clawclaw/plugins/perception/module-runner.test.ts +0 -214
  173. package/src/runtime/clawclaw/plugins/perception/modules/co-movement-module.ts +0 -347
  174. package/src/runtime/clawclaw/plugins/perception/modules/corpse-visibility-module.test.ts +0 -92
  175. package/src/runtime/clawclaw/plugins/perception/modules/corpse-visibility-module.ts +0 -248
  176. package/src/runtime/clawclaw/plugins/perception/modules/follow-module.ts +0 -389
  177. package/src/runtime/clawclaw/plugins/perception/modules/index.ts +0 -8
  178. package/src/runtime/clawclaw/plugins/perception/modules/motion-module.test.ts +0 -342
  179. package/src/runtime/clawclaw/plugins/perception/modules/motion-module.ts +0 -475
  180. package/src/runtime/clawclaw/plugins/perception/modules/parallel-module-test-helpers.ts +0 -30
  181. package/src/runtime/clawclaw/plugins/perception/modules/relation-stability.test.ts +0 -304
  182. package/src/runtime/clawclaw/plugins/perception/modules/route-module.test.ts +0 -179
  183. package/src/runtime/clawclaw/plugins/perception/modules/route-module.ts +0 -364
  184. package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.test.ts +0 -81
  185. package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.ts +0 -200
  186. package/src/runtime/clawclaw/plugins/perception/modules/stop-module.test.ts +0 -216
  187. package/src/runtime/clawclaw/plugins/perception/modules/stop-module.ts +0 -284
  188. package/src/runtime/clawclaw/plugins/perception/modules/temporal-evidence.test.ts +0 -120
  189. package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.test.ts +0 -105
  190. package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.ts +0 -269
  191. package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-pool.test.ts +0 -865
  192. package/src/runtime/clawclaw/plugins/perception/perception-plugin.test.ts +0 -1878
  193. package/src/runtime/clawclaw/plugins/perception/perception-source.test.ts +0 -278
  194. package/src/runtime/clawclaw/plugins/perception/replay.test.ts +0 -77
  195. package/src/runtime/clawclaw/plugins/runtime-plugins.test.ts +0 -853
  196. package/src/runtime/clawclaw/plugins/source/game-transport.test.ts +0 -287
  197. package/src/runtime/clawclaw/plugins/source/player-change-tracker.test.ts +0 -321
  198. package/src/runtime/clawclaw/plugins/source/room-transport.test.ts +0 -307
  199. package/src/runtime/clawclaw/plugins/source/source-plugin.test.ts +0 -2646
  200. package/src/runtime/clawclaw/plugins/source/task-change-tracker.test.ts +0 -212
  201. package/src/runtime/clawclaw/plugins/trigger/trigger-plugin.test.ts +0 -548
  202. package/src/runtime/clawclaw/plugins/trigger/trigger-source.test.ts +0 -169
  203. package/src/runtime/clawclaw/runtime-data-export.test.ts +0 -249
  204. package/src/runtime/clawclaw-event-catalog.test.ts +0 -128
  205. package/src/runtime/framework/action-diagnostics.test.ts +0 -81
  206. package/src/runtime/framework/capability-registry.test.ts +0 -423
  207. package/src/runtime/framework/control-coordinator.test.ts +0 -675
  208. package/src/runtime/framework/events/event-delivery-service.test.ts +0 -84
  209. package/src/runtime/framework/events/event-ingress.test.ts +0 -203
  210. package/src/runtime/framework/events/mailbox-event-repositories.test.ts +0 -710
  211. package/src/runtime/framework/events/sqlite-event-repository.test.ts +0 -802
  212. package/src/runtime/framework/mailbox/coalescer.test.ts +0 -55
  213. package/src/runtime/framework/mailbox/identity.test.ts +0 -38
  214. package/src/runtime/framework/mailbox/mailbox-dispatcher.test.ts +0 -513
  215. package/src/runtime/framework/mailbox/notification-projector.test.ts +0 -77
  216. package/src/runtime/framework/modules/runtime-module-loader.test.ts +0 -435
  217. package/src/runtime/framework/participation-manager.test.ts +0 -108
  218. package/src/runtime/framework/plugins/runtime-input-journal.test.ts +0 -179
  219. package/src/runtime/framework/plugins/runtime-plugin-scheduler.test.ts +0 -2040
  220. package/src/runtime/framework/state/durable-agent-state-snapshot.test.ts +0 -144
  221. package/src/runtime/framework/state/history/sqlite-state-history-repository.test.ts +0 -157
  222. package/src/runtime/framework/state/history/state-history.test.ts +0 -251
  223. package/src/runtime/framework/state/state-core.test.ts +0 -197
  224. package/src/runtime/game-sync-protocol.test.ts +0 -123
  225. package/src/runtime/host-monitor-rate-gate.test.ts +0 -73
  226. package/src/runtime/mailbox-host-relay.test.ts +0 -293
  227. package/src/runtime/observability/observability.test.ts +0 -583
  228. package/src/runtime/owner-control.test.ts +0 -153
  229. package/src/runtime/parent-process-watch.test.ts +0 -27
  230. package/src/runtime/pending-event-handoff.test.ts +0 -29
  231. package/src/runtime/raw-ws-log.test.ts +0 -102
  232. package/src/runtime/runtime-logger.test.ts +0 -58
  233. package/src/runtime/runtime-persistence.test.ts +0 -26
  234. package/src/runtime/runtime.test.ts +0 -1770
  235. package/src/runtime/ws-client.test.ts +0 -562
  236. package/src/sdk/action.test.ts +0 -8
  237. package/src/sdk/behavior-plugin/index.test.ts +0 -74
  238. package/src/sdk/index.test.ts +0 -45
  239. package/src/sdk/module-input/index.test.ts +0 -49
  240. package/src/sdk/perception-plugin/index.test.ts +0 -22
  241. package/src/sdk/resource-metadata.test.ts +0 -40
  242. package/src/sdk/trigger-plugin/index.test.ts +0 -41
  243. package/src/short-command/classifier.test.ts +0 -107
  244. package/src/short-command/presenter.test.ts +0 -119
  245. package/src/short-command/runner.test.ts +0 -78
  246. package/src/short-command/sensitive-data-filter.test.ts +0 -56
  247. package/src/short-command/transport-response.test.ts +0 -39
  248. package/src/strategies/avoid-lone.ts +0 -32
  249. package/src/strategies/avoid-players.ts +0 -43
  250. package/src/strategies/corpse-patrol.ts +0 -50
  251. package/src/strategies/crab-sabotage.ts +0 -48
  252. package/src/strategies/custom-module.test.ts +0 -267
  253. package/src/strategies/find-player.ts +0 -49
  254. package/src/strategies/game-utils.test.ts +0 -305
  255. package/src/strategies/game-utils.ts +0 -927
  256. package/src/strategies/goals/anchor-linger.ts +0 -77
  257. package/src/strategies/goals/avoid-lone-top.ts +0 -189
  258. package/src/strategies/goals/avoid-players-top.test.ts +0 -95
  259. package/src/strategies/goals/avoid-players-top.ts +0 -122
  260. package/src/strategies/goals/conversation-goal.ts +0 -51
  261. package/src/strategies/goals/corpse-patrol-top.ts +0 -120
  262. package/src/strategies/goals/crab-octopus-reflexes.ts +0 -109
  263. package/src/strategies/goals/crab-sabotage-top.test.ts +0 -131
  264. package/src/strategies/goals/crab-sabotage-top.ts +0 -139
  265. package/src/strategies/goals/emergency-hunt-goal.ts +0 -40
  266. package/src/strategies/goals/find-player-top.ts +0 -136
  267. package/src/strategies/goals/flee-players-goal.ts +0 -55
  268. package/src/strategies/goals/follow-companion-goal.ts +0 -130
  269. package/src/strategies/goals/goal-manager.ts +0 -41
  270. package/src/strategies/goals/goal-root-strategy.ts +0 -49
  271. package/src/strategies/goals/goal.ts +0 -28
  272. package/src/strategies/goals/hide-top.ts +0 -240
  273. package/src/strategies/goals/keep-away-goal.ts +0 -243
  274. package/src/strategies/goals/kill-frenzy-top.ts +0 -90
  275. package/src/strategies/goals/kill-lone-top.test.ts +0 -96
  276. package/src/strategies/goals/kill-lone-top.ts +0 -166
  277. package/src/strategies/goals/kill-target-goal.ts +0 -69
  278. package/src/strategies/goals/kill-target-top.test.ts +0 -65
  279. package/src/strategies/goals/kill-target-top.ts +0 -121
  280. package/src/strategies/goals/leaf-goal.ts +0 -27
  281. package/src/strategies/goals/linger-corpse-goal.ts +0 -43
  282. package/src/strategies/goals/lone-kill-core.ts +0 -86
  283. package/src/strategies/goals/lone-kill-goal.ts +0 -24
  284. package/src/strategies/goals/lone-kill-task-top.test.ts +0 -84
  285. package/src/strategies/goals/lone-kill-task-top.ts +0 -133
  286. package/src/strategies/goals/move-room-goal.ts +0 -102
  287. package/src/strategies/goals/normal-shrimp-top.test.ts +0 -112
  288. package/src/strategies/goals/normal-shrimp-top.ts +0 -248
  289. package/src/strategies/goals/paradise-fish-top.test.ts +0 -203
  290. package/src/strategies/goals/paradise-fish-top.ts +0 -234
  291. package/src/strategies/goals/patrol-top.ts +0 -68
  292. package/src/strategies/goals/report-patrol-top.ts +0 -97
  293. package/src/strategies/goals/safe-task-goal.ts +0 -130
  294. package/src/strategies/goals/social-task-top.ts +0 -192
  295. package/src/strategies/goals/task-kill-report-top.ts +0 -187
  296. package/src/strategies/goals/task-only-top.test.ts +0 -88
  297. package/src/strategies/goals/task-only-top.ts +0 -64
  298. package/src/strategies/goals/task-or-patrol-goal.ts +0 -59
  299. package/src/strategies/goals/task-report-top.ts +0 -57
  300. package/src/strategies/goals/wander-task-goal.ts +0 -33
  301. package/src/strategies/goals/warrior-shrimp-top.test.ts +0 -138
  302. package/src/strategies/goals/warrior-shrimp-top.ts +0 -293
  303. package/src/strategies/greeting.ts +0 -60
  304. package/src/strategies/hide.ts +0 -51
  305. package/src/strategies/kill-frenzy.ts +0 -32
  306. package/src/strategies/kill-lone.ts +0 -52
  307. package/src/strategies/kill-target.ts +0 -48
  308. package/src/strategies/lone-kill-task.ts +0 -48
  309. package/src/strategies/meeting-gate.test.ts +0 -59
  310. package/src/strategies/meeting-gate.ts +0 -28
  311. package/src/strategies/move-room.ts +0 -46
  312. package/src/strategies/official-long-behavior.test.ts +0 -89
  313. package/src/strategies/paradise-fish.ts +0 -70
  314. package/src/strategies/pathfind/astar-path.test.ts +0 -198
  315. package/src/strategies/pathfind/escape-planner.test.ts +0 -223
  316. package/src/strategies/patrol.ts +0 -32
  317. package/src/strategies/player-targets.test.ts +0 -10
  318. package/src/strategies/player-targets.ts +0 -18
  319. package/src/strategies/report-patrol.ts +0 -32
  320. package/src/strategies/shrimp-memory.ts +0 -87
  321. package/src/strategies/social-task.ts +0 -67
  322. package/src/strategies/speech-module.ts +0 -123
  323. package/src/strategies/task-kill-report.ts +0 -49
  324. package/src/strategies/task-only.test.ts +0 -138
  325. package/src/strategies/task-only.ts +0 -34
  326. package/src/strategies/task-report.ts +0 -50
  327. package/src/strategies/types.ts +0 -116
  328. package/src/strategies/warrior-memory.ts +0 -54
  329. /package/src/{strategies/pathfind → runtime/clawclaw/navigation}/clawclaw-walkable.bin +0 -0
  330. /package/src/{strategies/pathfind → runtime/clawclaw/navigation}/distance-field.ts +0 -0
@@ -1,879 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import {
3
- compactEventFields,
4
- compactEventForEvents,
5
- compactStateForEvents,
6
- formatEventMessage,
7
- shortStateText,
8
- } from './event-format.js';
9
- import { BACKEND_EVENT_HINT_FORMATTERS } from './event-hints.js';
10
-
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
-
26
- it('formats upcoming and active maintenance as explicit service messages', () => {
27
- const maintenance = {
28
- starts_at: '2026-08-05T01:00:00+00:00',
29
- ends_at: '2026-08-05T03:00:00+00:00',
30
- description: '本次维护将升级匹配服务。',
31
- };
32
- expect(formatEventMessage({
33
- type: 'service_status', service_status: 'maintenance_upcoming', maintenance,
34
- })).toContain('当前请求仍可继续');
35
- expect(formatEventMessage({
36
- type: 'service_status', service_status: 'maintenance_upcoming', maintenance,
37
- })).toContain(maintenance.description);
38
- expect(formatEventMessage({
39
- type: 'service_status', service_status: 'maintenance_active', maintenance,
40
- })).toContain('新的匹配和房间操作已停止');
41
- });
42
-
43
- it('formats killed as a short message and keeps direct compaction separate from presentation ownership', () => {
44
- const event = {
45
- type: 'killed',
46
- tick: 5330,
47
- room: '情报室',
48
- killer_name: '哈基米南北绿豆',
49
- killer_seat: 8,
50
- killer_role: 'neutral_octopus',
51
- hint: 'YOU ARE DEAD: 哈基米南北绿豆 removed you from play. Your hands are off the board now — alert your user, then spectate or leave while your teammates weaponize what you learned.',
52
- };
53
-
54
- const message = formatEventMessage(event);
55
- const { hint: _hint, ...facts } = event;
56
- const formatted = compactEventFields(facts, {}, 1158);
57
-
58
- expect(message).toContain('t5330 killed');
59
- expect(message).toContain('8号哈基米南北绿豆');
60
- expect(message).toContain('8号哈基米南北绿豆(章鱼)');
61
- expect(formatted).not.toHaveProperty('notice');
62
- expect(formatted).not.toHaveProperty('hint');
63
- expect(JSON.stringify(formatted)).not.toContain('Your hands are off the board');
64
- });
65
-
66
- it('formats a system killer without a fake player seat', () => {
67
- const message = formatEventMessage({
68
- type: 'killed',
69
- tick: 41,
70
- room: '制氧舱',
71
- killer_kind: 'system',
72
- killer_name: 'Shrimp God',
73
- killer_role: 'neutral_octopus',
74
- });
75
-
76
- expect(message).toContain('被Shrimp God击杀');
77
- expect(message).not.toContain('?号Shrimp God');
78
- expect(message).not.toContain('章鱼');
79
- });
80
-
81
- it('formats emergency interruption as a private second-person fact', () => {
82
- const message = formatEventMessage({
83
- type: 'emergency_interrupted',
84
- tick: 486,
85
- actor_name: 'Alpha',
86
- actor_seat: 2,
87
- task_name: '修复火灾-发动机',
88
- });
89
-
90
- expect(message).toContain('你在处理修复火灾-发动机时死亡');
91
- expect(message).not.toContain('Alpha');
92
- expect(message).not.toContain('未知玩家');
93
- });
94
-
95
- it('downgrades self-killer murder_witnessed presentation to neutral diagnostics', () => {
96
- const message = formatEventMessage({
97
- type: 'murder_witnessed',
98
- tick: 42,
99
- room: '制氧舱',
100
- killer_name: 'self',
101
- killer_seat: 1,
102
- target_name: 'target',
103
- target_seat: 2,
104
- }, {
105
- summary: { you: { player: { name: 'self', seat: 1 } } },
106
- });
107
-
108
- expect(message).toContain('已降级为诊断信息');
109
- expect(message).toContain('不能据此判断任何目击者');
110
- expect(message).not.toContain('你在制氧舱目击');
111
- });
112
-
113
- it('keeps meeting_briefing details aligned with the compact monitor payload', () => {
114
- const formatted = compactEventFields({
115
- type: 'meeting_briefing',
116
- tick: 979,
117
- room: '会议室',
118
- meeting_caller_name: '单钳渔夫',
119
- meeting_caller_seat: 1,
120
- reported_corpses: [{ name: '丹霞兄', seat: 3 }],
121
- your_seat: 6,
122
- all_seats: [{ name: '单钳渔夫', seat: 1 }],
123
- speech_order: ['单钳渔夫', '洋流王子'],
124
- crab_teammates: [{ name: '暗礁壳壳', seat: 5 }],
125
- }, {}, 941);
126
-
127
- expect(formatted).toMatchObject({
128
- line: 941,
129
- type: 'meeting_briefing',
130
- tick: 979,
131
- meeting_caller_name: '单钳渔夫',
132
- meeting_caller_seat: 1,
133
- reported_corpses: [{ name: '丹霞兄', seat: 3 }],
134
- your_seat: 6,
135
- all_seats: [{ name: '单钳渔夫', seat: 1 }],
136
- speech_order: ['单钳渔夫', '洋流王子'],
137
- crab_teammates: [{ name: '暗礁壳壳', seat: 5 }],
138
- });
139
- expect(formatted).not.toHaveProperty('room');
140
- });
141
-
142
- it('hides vote targets in event details', () => {
143
- const formatted = compactEventFields({
144
- type: 'vote_cast',
145
- tick: 3409,
146
- actor_name: '菜逼油条',
147
- actor_seat: 8,
148
- target: '单钳渔夫',
149
- target_name: '单钳渔夫',
150
- target_seat: 1,
151
- });
152
-
153
- expect(formatted).toMatchObject({
154
- type: 'vote_cast',
155
- tick: 3409,
156
- actor_name: '菜逼油条',
157
- actor_seat: 8,
158
- });
159
- expect(formatted).not.toHaveProperty('target');
160
- expect(formatted).not.toHaveProperty('target_name');
161
- expect(formatted).not.toHaveProperty('target_seat');
162
- expect(JSON.stringify(formatted)).not.toContain('单钳渔夫');
163
- });
164
-
165
- it('formats meeting result Events as meeting-ended facts with seat-aware votes', () => {
166
- const ctx = {
167
- summary: {
168
- players: [
169
- { name: '菜逼油条', seat: 8, known_status: { is_alive: true } },
170
- { name: '单钳渔夫', seat: 1, known_status: { is_alive: true } },
171
- { name: '暗礁壳壳', seat: 5, known_status: { is_alive: true } },
172
- ],
173
- },
174
- };
175
- const exile = {
176
- type: 'exile',
177
- tick: 3411,
178
- actor_name: '单钳渔夫',
179
- votes: {
180
- 菜逼油条: '单钳渔夫',
181
- 暗礁壳壳: 'skip',
182
- },
183
- hint: 'backend hint',
184
- };
185
-
186
- expect(formatEventMessage(exile, ctx))
187
- .toBe('t3411 exile 会议结束:1号单钳渔夫被放逐。 Hint: backend hint');
188
- const { hint: _hint, ...exileFacts } = exile;
189
- expect(compactEventFields(exileFacts, ctx)).toMatchObject({
190
- type: 'exile',
191
- tick: 3411,
192
- meeting_ended: true,
193
- result: 'exiled',
194
- exiled_player: { name: '单钳渔夫', seat: 1 },
195
- votes: {
196
- '8号菜逼油条': '1号单钳渔夫',
197
- '5号暗礁壳壳': 'skip',
198
- },
199
- });
200
-
201
- expect(formatEventMessage({ type: 'no_exile', tick: 3412 }, ctx)).toBe('t3412 no_exile 会议结束:无人被放逐。');
202
- expect(compactEventFields({ type: 'no_exile', tick: 3412 }, ctx)).toMatchObject({
203
- type: 'no_exile',
204
- tick: 3412,
205
- meeting_ended: true,
206
- result: 'no_exile',
207
- });
208
- });
209
-
210
- it('formats death_speech with explicit speaker fields', () => {
211
- const event = {
212
- type: 'death_speech',
213
- tick: 2201,
214
- actor_name: '旧字段',
215
- actor_seat: 2,
216
- speaker_name: '暗礁壳壳',
217
- speaker_seat: 5,
218
- text: '我看到2号在尸体旁。',
219
- };
220
-
221
- expect(formatEventMessage(event)).toBe('t2201 death_speech 5号暗礁壳壳死亡弹幕:我看到2号在尸体旁。');
222
- });
223
-
224
- it('keeps Monitor facts separate and appends the projected Event hint', () => {
225
- const factual = formatEventMessage({
226
- type: 'vote_phase_start',
227
- tick: 3408,
228
- message: 'Speech phase ended. All alive players, please cast your vote',
229
- });
230
- const hint = BACKEND_EVENT_HINT_FORMATTERS.vote_phase_start({}, {}) ?? '';
231
- const withHint = formatEventMessage({
232
- type: 'vote_phase_start',
233
- tick: 3408,
234
- hint,
235
- });
236
-
237
- expect(factual).toBe('t3408 vote_phase_start 投票阶段开始。');
238
- expect(factual).not.toContain('ccl speak');
239
- expect(factual).not.toContain('ccl vote');
240
- expect(withHint).toContain(`Hint: ${hint}`);
241
- expect(withHint).toContain('ccl speak');
242
- expect(withHint).toContain('ccl vote');
243
- expect(withHint).not.toContain('ccl do');
244
- });
245
-
246
- it('uses standalone speak and vote commands in Agent hints', () => {
247
- const speech = BACKEND_EVENT_HINT_FORMATTERS.speech_your_turn({}, {}) ?? '';
248
- const vote = BACKEND_EVENT_HINT_FORMATTERS.vote_phase_start({}, {}) ?? '';
249
- const voteNow = BACKEND_EVENT_HINT_FORMATTERS.vote_speech_phase_ended({}, {}) ?? '';
250
-
251
- expect(speech).toContain('ccl speak');
252
- expect(vote).toContain('ccl speak');
253
- expect(vote).toContain('ccl vote');
254
- expect(vote.indexOf('ccl speak')).toBeLessThan(vote.indexOf('ccl vote'));
255
- expect(voteNow).toContain('ccl vote');
256
- expect([speech, vote, voteNow].join('\n')).not.toContain('ccl do');
257
- });
258
-
259
- it('formats game_started as a factual Monitor message plus the projected hint', () => {
260
- const hint = BACKEND_EVENT_HINT_FORMATTERS.game_started({
261
- player_count: 10,
262
- }, {}) ?? '';
263
- const message = formatEventMessage({
264
- type: 'game_started',
265
- tick: 0,
266
- player_count: 10,
267
- game_mode: 'competition',
268
- hint,
269
- });
270
- const formatted = compactEventFields({
271
- type: 'game_started',
272
- tick: 0,
273
- player_count: 10,
274
- game_mode: 'competition',
275
- });
276
-
277
- expect(message).toContain('t0 game_started');
278
- expect(message).toContain('10');
279
- expect(message).toContain('竞赛模式');
280
- expect(message).toContain('full Event delivery');
281
- expect(message).not.toContain('ccl events game_started');
282
- expect(message).not.toContain('ccl events role_assigned');
283
- expect(message).toContain(`Hint: ${hint}`);
284
- expect(formatted).toMatchObject({
285
- type: 'game_started',
286
- tick: 0,
287
- player_count: 10,
288
- game_mode: 'competition',
289
- });
290
- expect(formatted).not.toHaveProperty('hint');
291
- });
292
-
293
- it('formats room readiness as a fact plus the projected confirmation hint', () => {
294
- const message = formatEventMessage({
295
- type: 'room_ready_to_start',
296
- hint: 'The room is ready to start and you are the owner. Ask the user whether to start now before running `ccl game start-room`.',
297
- });
298
-
299
- expect(message).toContain('房间已满足开局条件,你是房主。');
300
- expect(message).toContain('Hint: The room is ready');
301
- expect(message).toContain('ccl game start-room');
302
- });
303
-
304
- it('formats room game finished as a factual short message', () => {
305
- const message = formatEventMessage({
306
- type: 'room.game_finished',
307
- game_id: 'game-1',
308
- });
309
-
310
- expect(message).toContain('上一轮房间对局已结束');
311
- expect(message).toContain('所有人已回到房间');
312
- });
313
-
314
- it('formats an externally changed training room mode without attributing an origin', () => {
315
- const event = {
316
- type: 'room.type_changed',
317
- previous_room_type: 'training_simulation',
318
- room_type: 'training_dummy',
319
- sync_reason: 'room_type_changed',
320
- };
321
-
322
- expect(formatEventMessage(event)).toContain('训练房模式已被其他方面从模拟训练切换为木桩训练');
323
- expect(compactEventFields(event)).not.toHaveProperty('origin');
324
- });
325
-
326
- it('formats current CCL lifecycle Event names as factual messages', () => {
327
- expect(formatEventMessage({ type: 'match_start' })).toContain('匹配长流已连接');
328
- expect(formatEventMessage({ type: 'quit_requested' })).toContain('正在结束');
329
- expect(formatEventMessage({ type: 'room_created', room_code: '123456' })).toContain('123456');
330
- expect(formatEventMessage({ type: 'room_lobby_reconnect_failed' })).toContain('失败');
331
- expect(formatEventMessage({
332
- type: 'behavior.completed', behavior: 'evade', layer: 'short', reason: 'escaped',
333
- })).toContain('evade(short)已完成:escaped');
334
- });
335
-
336
- it('formats backend Event types that previously fell through to raw names', () => {
337
- const cases = [
338
- [{ type: 'move_interrupted', nearby_players: [{ name: 'Alpha', seat: 2 }] }, 'Alpha'],
339
- [{ type: 'body_dropped', room: 'Room A' }, 'Room A'],
340
- [{ type: 'speech_next_turn', current_speaker: 'Alpha' }, 'Alpha'],
341
- [{ type: 'emergency_interrupted', actor_name: 'Alpha', task_name: 'Task A' }, 'Task A'],
342
- [{ type: 'exile_game_over', winner: 'lobster' }, 'lobster'],
343
- [{ type: 'octopus_time_win', winner_name: 'Alpha' }, 'Alpha'],
344
- [{ type: 'win_blocked_by_octopus', blocked_winner: 'lobster', reason: 'tasks' }, 'tasks'],
345
- ] as const;
346
-
347
- for (const [event, expected] of cases) {
348
- expect(formatEventMessage(event)).toContain(expected);
349
- }
350
- });
351
-
352
- it('keeps every nearby player in a move interruption fact', () => {
353
- const message = formatEventMessage({
354
- type: 'move_interrupted',
355
- nearby_players: [
356
- { name: 'Alpha', seat: 2 },
357
- { name: 'Beta', seat: 3 },
358
- { name: 'Gamma', seat: 4 },
359
- { name: 'Delta', seat: 5 },
360
- ],
361
- });
362
- expect(message).toContain('2号Alpha、3号Beta、4号Gamma、5号Delta');
363
- });
364
-
365
- it('mentions a newly assigned task only when task_completed carries one', () => {
366
- expect(formatEventMessage({
367
- type: 'task_completed',
368
- task_name: '擦拭酒瓶',
369
- newly_assigned_task: {
370
- name: '消毒淋浴器',
371
- room: '制氧舱',
372
- x: 123,
373
- y: 456,
374
- },
375
- })).toContain('任务完成:擦拭酒瓶;新分配任务:消毒淋浴器(制氧舱)');
376
- expect(formatEventMessage({
377
- type: 'task_completed',
378
- task_name: '擦拭酒瓶',
379
- })).toBe('tick=null task_completed 任务完成:擦拭酒瓶。');
380
- });
381
-
382
- it('removes the duplicate single assignment once a task Event has full list context', () => {
383
- const compact = compactEventForEvents({
384
- type: 'task_completed',
385
- tick: 42,
386
- task_name: '擦拭酒瓶',
387
- newly_assigned_task: { name: '消毒淋浴器' },
388
- reason: 'task_completed',
389
- delta: [{ change: 'added', task: { name: '消毒淋浴器', status: 'normal' } }],
390
- tasks: [{ name: '消毒淋浴器', status: 'normal' }],
391
- });
392
-
393
- expect(compact).not.toHaveProperty('newly_assigned_task');
394
- expect(compact).toMatchObject({
395
- reason: 'task_completed',
396
- delta: [{ change: 'added', task: { name: '消毒淋浴器', status: 'normal' } }],
397
- tasks: [{ name: '消毒淋浴器', status: 'normal' }],
398
- });
399
- });
400
-
401
- it('preserves old and new values for a player status delta', () => {
402
- const compact = compactEventForEvents({
403
- type: 'players_changed',
404
- reason: 'player_status_changed',
405
- changes: [{
406
- change: 'status_changed',
407
- name: 'Hidden',
408
- seat: 2,
409
- from_status: 'unknown',
410
- to_status: 'alive',
411
- }],
412
- players: [{ name: 'Hidden', seat: 2, status: 'alive', death: null }],
413
- });
414
-
415
- expect(compact).toMatchObject({
416
- changes: [{
417
- change: 'status_changed',
418
- name: 'Hidden',
419
- seat: 2,
420
- from_status: 'unknown',
421
- to_status: 'alive',
422
- }],
423
- players: [{ name: 'Hidden', seat: 2, status: 'alive', death: null }],
424
- });
425
- });
426
-
427
- it('formats room presence and idle lifecycle Events', () => {
428
- expect(formatEventMessage({
429
- type: 'room.member_status_changed', agent_id: 'agent-2', status: 'online',
430
- })).toContain('在线');
431
- expect(formatEventMessage({
432
- type: 'room.idle_warning', seconds_remaining: 119,
433
- })).toContain('119秒后自动销毁');
434
- expect(formatEventMessage({
435
- type: 'room_destroyed', reason: 'idle_timeout', close_code: 4005,
436
- })).toContain('已自动销毁');
437
- });
438
-
439
- it('uses custom heartbeat messages when provided', () => {
440
- expect(formatEventMessage({
441
- type: 'heartbeat',
442
- message: '房间 123456 当前 6/10 人,正在等待更多玩家加入。',
443
- })).toContain('正在等待更多玩家加入');
444
- });
445
-
446
- it('compacts room waiting state without game player projection', () => {
447
- const state = compactStateForEvents({
448
- phase: 'room_waiting',
449
- you: { name: 'me', seat: 1, is_owner: true },
450
- room: {
451
- room_code: '123456',
452
- room_type: 'casual',
453
- status: 'waiting',
454
- member_count: 10,
455
- cooldown_seconds: 44,
456
- idle_destroy_at: 1719000900,
457
- is_owner: true,
458
- ready_to_start: true,
459
- members: [{ seat: 1, name: 'me', is_owner: true }],
460
- },
461
- }, [
462
- { type: 'room_ready_to_start', room_code: '123456' },
463
- ]);
464
-
465
- expect(state).toMatchObject({
466
- phase: 'room_waiting',
467
- you: { name: 'me', seat: 1, is_owner: true },
468
- room: {
469
- room_code: '123456',
470
- status: 'waiting',
471
- member_count: 10,
472
- idle_destroy_at: 1719000900,
473
- ready_to_start: true,
474
- },
475
- recent_events: [{ type: 'room_ready_to_start', room_code: '123456' }],
476
- });
477
- expect(state).not.toHaveProperty('players');
478
- expect(state?.room).not.toHaveProperty('cooldown_seconds');
479
- expect(shortStateText(state)).toContain('ready=confirm-start');
480
- });
481
-
482
- it('returns the authoritative known-player view alongside the bounded current scene', () => {
483
- const state = compactStateForEvents({
484
- phase: 'wandering',
485
- tick: 120,
486
- you: {
487
- player: { name: 'me', seat: 1 },
488
- x: 100,
489
- y: 100,
490
- room: '情报室',
491
- crab_teammates: [{ name: 'ally', seat: 5 }],
492
- tasks: [{
493
- name: '丢垃圾', room: '自助餐厅', x: 321, y: 654,
494
- status: 'normal', is_fake_shrimp: true,
495
- }],
496
- },
497
- players: [
498
- { name: 'me', seat: 1, known_status: { is_alive: true } },
499
- { name: 'nearby', seat: 2, known_status: { is_alive: true } },
500
- {
501
- name: 'fallen',
502
- seat: 3,
503
- known_status: {
504
- is_alive: false,
505
- death_cause: 'killed',
506
- reported_in_current_meeting: true,
507
- },
508
- },
509
- { name: 'unknown', seat: 4, known_status: {} },
510
- ],
511
- visible_players: [{
512
- player: { name: 'nearby', seat: 2 },
513
- room: '5号走廊',
514
- x: 130,
515
- y: 140,
516
- role: 'must-not-leak',
517
- }],
518
- visible_corpses: [{
519
- player: { name: 'fallen', seat: 3 },
520
- room: '情报室',
521
- x: 60,
522
- y: 100,
523
- distance: 8.44,
524
- agent_id: 'must-not-leak',
525
- }],
526
- crab_sabotage: {
527
- status: 'cooldown_charged',
528
- cooldown_remaining_secs: 4.25,
529
- internal_charge_id: 'must-not-leak',
530
- },
531
- }, [{
532
- type: 'corpse_spotted',
533
- corpse_name: 'fallen',
534
- corpse_seat: 3,
535
- }]);
536
-
537
- expect(state?.visible_players).toEqual([{
538
- name: 'nearby',
539
- seat: 2,
540
- room: '5号走廊',
541
- relative_direction: '右下',
542
- distance_px: 50,
543
- }]);
544
- expect(state?.you.tasks).toEqual([{
545
- name: '丢垃圾', room: '自助餐厅', x: 321, y: 654,
546
- status: 'normal', is_fake_shrimp: true,
547
- }]);
548
- expect(state?.you.crab_teammates).toEqual([{ name: 'ally', seat: 5 }]);
549
- expect(state?.nearby_corpses).toEqual([{
550
- name: 'fallen',
551
- seat: 3,
552
- room: '情报室',
553
- relative_direction: '左',
554
- distance_px: 8.4,
555
- }]);
556
- expect(state?.crab_sabotage).toEqual({
557
- status: 'cooldown_charged',
558
- cooldown_remaining_secs: 4.25,
559
- });
560
- expect(state?.abilities).toBeUndefined();
561
- expect(state?.players).toEqual([
562
- { name: 'me', seat: 1, known_status: { is_alive: true } },
563
- { name: 'nearby', seat: 2, known_status: { is_alive: true } },
564
- {
565
- name: 'fallen',
566
- seat: 3,
567
- known_status: {
568
- is_alive: false,
569
- death_cause: 'killed',
570
- reported_in_current_meeting: true,
571
- },
572
- },
573
- { name: 'unknown', seat: 4, known_status: {} },
574
- ]);
575
- expect(state?.visible_players[0]).not.toHaveProperty('x');
576
- expect(state?.visible_players[0]).not.toHaveProperty('y');
577
- expect(state?.visible_players[0]).not.toHaveProperty('role');
578
- expect(state?.nearby_corpses[0]).not.toHaveProperty('agent_id');
579
- expect(state?.nearby_corpses[0]).not.toHaveProperty('x');
580
- expect(state?.nearby_corpses[0]).not.toHaveProperty('y');
581
- });
582
-
583
- it('omits a malformed known-player roster instead of returning partial evidence', () => {
584
- const state = compactStateForEvents({
585
- phase: 'wandering',
586
- you: { player: { name: 'me', seat: 1 } },
587
- players: [
588
- { name: 'me', seat: 1, known_status: { is_alive: true } },
589
- { name: 'missing-seat', known_status: {} },
590
- ],
591
- });
592
-
593
- expect(state).not.toHaveProperty('players');
594
- });
595
-
596
- it('uses separate compact Monitor and detailed ccl events projections for player changes', () => {
597
- const event = {
598
- type: 'players_changed',
599
- tick: 644,
600
- meeting: true,
601
- meeting_count: 1,
602
- changes: [{
603
- change: 'died',
604
- name: '陈皮一带四#c7',
605
- seat: 9,
606
- cause: 'killed',
607
- killer: null,
608
- internal_field: 'must-not-leak',
609
- }],
610
- players: [{
611
- name: 'Alpha',
612
- seat: 2,
613
- status: 'alive',
614
- death: null,
615
- internal_field: 'must-not-leak',
616
- }, {
617
- name: '陈皮一带四#c7',
618
- seat: 9,
619
- status: 'dead',
620
- death: {
621
- cause: 'killed',
622
- killer: null,
623
- source: 'event_log',
624
- },
625
- }],
626
- };
627
-
628
- expect(formatEventMessage(event)).toBe(
629
- 't644 players_changed 第1次会议中发现9号陈皮一带四#c7已被击杀,凶手未知。',
630
- );
631
- expect(compactEventFields(event)).toEqual({
632
- type: 'players_changed',
633
- tick: 644,
634
- meeting: true,
635
- meeting_count: 1,
636
- changes: [{
637
- change: 'died',
638
- name: '陈皮一带四#c7',
639
- seat: 9,
640
- cause: 'killed',
641
- killer: null,
642
- }],
643
- players: [{
644
- name: 'Alpha',
645
- seat: 2,
646
- status: 'alive',
647
- death: null,
648
- }, {
649
- name: '陈皮一带四#c7',
650
- seat: 9,
651
- status: 'dead',
652
- death: {
653
- cause: 'killed',
654
- killer: null,
655
- },
656
- }],
657
- });
658
- });
659
-
660
- it('keeps explicit empty scene sets and omits scene fields outside raw visual state', () => {
661
- const emptyScene = compactStateForEvents({
662
- phase: 'wandering',
663
- you: { player: { name: 'me', seat: 1 } },
664
- visible_players: [],
665
- visible_corpses: [],
666
- });
667
- expect(emptyScene).toMatchObject({
668
- visible_players: [],
669
- nearby_corpses: [],
670
- });
671
-
672
- const meeting = compactStateForEvents({
673
- phase: 'meeting',
674
- you: { player: { name: 'me', seat: 1 } },
675
- meeting: { active: true, sub_phase: 'speech' },
676
- });
677
- expect(meeting).not.toHaveProperty('visible_players');
678
- expect(meeting).not.toHaveProperty('nearby_corpses');
679
- });
680
-
681
- it('uses heading sectors for current-scene direction and never calls unprojectable entries empty', () => {
682
- const nearHorizontal = compactStateForEvents({
683
- phase: 'wandering',
684
- you: { player: { name: 'me', seat: 1 }, x: 0, y: 0 },
685
- visible_players: [{ player: { name: 'other', seat: 2 }, x: 100, y: 1 }],
686
- visible_corpses: [],
687
- });
688
- expect(nearHorizontal?.visible_players).toEqual([{
689
- name: 'other',
690
- seat: 2,
691
- relative_direction: '右',
692
- distance_px: 100,
693
- }]);
694
-
695
- const unavailable = compactStateForEvents({
696
- phase: 'wandering',
697
- you: { player: { name: 'me', seat: 1 }, x: 0, y: 0 },
698
- visible_players: [{ x: 10, y: 10 }],
699
- visible_corpses: [],
700
- });
701
- expect(unavailable).not.toHaveProperty('visible_players');
702
- expect(unavailable?.nearby_corpses).toEqual([]);
703
- });
704
-
705
- it('formats corpse_spotted Monitor messages as my discovery with body owner', () => {
706
- const message = formatEventMessage({
707
- type: 'corpse_spotted',
708
- tick: 3410,
709
- corpse_name: '丹霞兄',
710
- corpse_seat: 3,
711
- corpse_room: '情报室',
712
- });
713
-
714
- expect(message).toBe('t3410 corpse_spotted 我发现了3号丹霞兄的尸体,在情报室。');
715
- });
716
-
717
- it('describes octopus time without narrowing the trigger to exactly three survivors', () => {
718
- const event = { type: 'octopus_time_start', tick: 3413 };
719
-
720
- expect(formatEventMessage(event)).toContain('存活人数已降至3人或更少');
721
- expect(BACKEND_EVENT_HINT_FORMATTERS.octopus_time_start(event, {})).toContain('At most three players remain');
722
- expect(BACKEND_EVENT_HINT_FORMATTERS.octopus_time_start(event, {})).toContain('emergency timeout');
723
- });
724
-
725
- it('formats emergency countdown and ability transition facts', () => {
726
- expect(formatEventMessage({
727
- type: 'emergency_countdown_warning',
728
- tick: 12,
729
- task_name: '修复供氧',
730
- threshold_secs: 30,
731
- remaining_secs: 29.8,
732
- })).toBe('t12 emergency_countdown_warning 紧急任务修复供氧只剩29.8秒(30秒提醒)。');
733
- expect(formatEventMessage({
734
- type: 'ability.ready',
735
- tick: 13,
736
- ability_id: 'kill',
737
- ability_name: '攻击',
738
- })).toBe('t13 ability.ready 能力“攻击”现在可以使用。');
739
- expect(formatEventMessage({
740
- type: 'ability.exhausted',
741
- tick: 14,
742
- ability_id: 'kill',
743
- ability_name: '攻击',
744
- })).toBe('t14 ability.exhausted 能力“攻击”已无剩余次数。');
745
- });
746
-
747
- it('includes current emergency and stateful abilities in Agent State', () => {
748
- const state = compactStateForEvents({
749
- phase: 'wandering',
750
- tick: 88,
751
- you: {
752
- player: { name: 'me', seat: 1 },
753
- role: 'shrimp_pistol',
754
- is_alive: true,
755
- kill_cooldown_secs: 0,
756
- kills_remaining: 1,
757
- },
758
- emergency: {
759
- active: true,
760
- task_name: '修复供氧',
761
- room: '制氧舱',
762
- x: 120,
763
- y: 240,
764
- remaining_secs: 27.5,
765
- internal_id: 'must-not-leak',
766
- },
767
- });
768
-
769
- expect(state?.emergency).toEqual({
770
- active: true,
771
- task_name: '修复供氧',
772
- room: '制氧舱',
773
- x: 120,
774
- y: 240,
775
- remaining_secs: 27.5,
776
- });
777
- expect(state?.abilities).toEqual([{
778
- id: 'kill',
779
- name: '攻击',
780
- ready: true,
781
- cooldown_remaining_secs: 0,
782
- remaining_uses: 1,
783
- effective_range_px: 160,
784
- }]);
785
- });
786
-
787
- it('tells every surviving role that emergency repair is real and available', () => {
788
- const hint = BACKEND_EVENT_HINT_FORMATTERS.emergency_started({
789
- type: 'emergency_started',
790
- task_name: '修复氧气',
791
- room: '控制室',
792
- timeout_secs: 80,
793
- }, {});
794
-
795
- expect(hint).toContain('Any surviving role can complete this real emergency repair');
796
- expect(hint).not.toContain('Lobsters —');
797
- });
798
-
799
- it('explains sabotage-caused emergencies without exposing a saboteur identity', () => {
800
- const event = {
801
- type: 'emergency_started',
802
- task_name: '稳定反应堆',
803
- room: '反应堆',
804
- timeout_secs: 80,
805
- cause: 'sabotage',
806
- };
807
-
808
- expect(formatEventMessage(event)).toContain('蟹刚完成对应破坏任务');
809
- const hint = BACKEND_EVENT_HINT_FORMATTERS.emergency_started(event, {});
810
- expect(hint).toContain('A Crab completed the paired sabotage task');
811
- expect(hint).toContain("identity is not exposed");
812
- });
813
-
814
- it('presents a private sabotage task interruption with its authoritative cooldown', () => {
815
- const event = {
816
- type: 'task_interrupted',
817
- task_id: '102',
818
- task_name: '投放毒药',
819
- reason: 'emergency_started',
820
- cooldown_remaining_secs: 100,
821
- };
822
-
823
- expect(formatEventMessage(event)).toContain('任务未消耗');
824
- expect(formatEventMessage(event)).toContain('100秒');
825
- const hint = BACKEND_EVENT_HINT_FORMATTERS.task_interrupted(event, {});
826
- expect(hint).toContain('was interrupted');
827
- expect(hint).toContain('not consumed');
828
- });
829
-
830
- it('states when a meeting, rather than a player, resolves an emergency', () => {
831
- const event = {
832
- type: 'emergency_resolved',
833
- task_name: '修复氧气',
834
- reason: 'meeting_started',
835
- };
836
-
837
- expect(formatEventMessage(event)).toContain('会议开始');
838
- expect(formatEventMessage(event)).toContain('自动解除');
839
- const hint = BACKEND_EVENT_HINT_FORMATTERS.emergency_resolved(event, {});
840
- expect(hint).toContain('Meeting started');
841
- expect(hint).toContain('No player completed the repair');
842
- });
843
-
844
- it('distinguishes a private self repair from an anonymous emergency resolution', () => {
845
- const self = { type: 'emergency_resolved', task_name: 'repair oxygen', resolved_by_self: true };
846
- const anonymous = { type: 'emergency_resolved', task_name: 'repair oxygen' };
847
-
848
- expect(formatEventMessage(self)).toContain('你已解决');
849
- expect(BACKEND_EVENT_HINT_FORMATTERS.emergency_resolved(self, {})).toContain('You resolved');
850
- expect(BACKEND_EVENT_HINT_FORMATTERS.emergency_resolved(anonymous, {}))
851
- .toContain("identity is not visible to you");
852
- });
853
-
854
- it('keeps local hint formatters for backend-hinted monitor events', () => {
855
- const backendHintedMonitorEvents = [
856
- 'corpse_spotted',
857
- 'emergency_resolved',
858
- 'emergency_started',
859
- 'exile',
860
- 'game_over',
861
- 'game_started',
862
- 'kill',
863
- 'killed',
864
- 'meeting_briefing',
865
- 'murder_witnessed',
866
- 'no_exile',
867
- 'octopus_time_start',
868
- 'role_assigned',
869
- 'speech_skipped',
870
- 'task_interrupted',
871
- 'vote_phase_start',
872
- 'vote_speech_phase_ended',
873
- ];
874
-
875
- for (const type of backendHintedMonitorEvents) {
876
- expect(BACKEND_EVENT_HINT_FORMATTERS[type], type).toBeTypeOf('function');
877
- }
878
- });
879
- });