@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,757 +0,0 @@
1
- import { loadClawclawMapAsset } from '../../../../lib/game-context.js';
2
- import { normalizeGameState } from '../../../../lib/normalize.js';
3
- import { CorpseMemory } from '../../../../strategies/game-utils.js';
4
- import { HIDE_SPOTS } from '../../../../strategies/hide-spots.js';
5
- import {
6
- buildRouteEvidence,
7
- type RouteEvidence,
8
- } from '../../../../strategies/pathfind/escape-planner.js';
9
- import type {
10
- BehaviorDecision as GoalBehaviorDecision,
11
- CustomModule,
12
- RoomTarget,
13
- Strategy,
14
- StrategyContext,
15
- StrategyIntent,
16
- StrategyIntentActivity,
17
- } from '../../../../strategies/types.js';
18
- import type {
19
- BehaviorDecision,
20
- BehaviorReadApi,
21
- GameAction,
22
- } from '../../../../sdk/behavior-plugin/index.js';
23
- import type {
24
- BehaviorInput,
25
- GameState,
26
- Position,
27
- } from '../../../../sdk/module-input/index.js';
28
- import type {
29
- EmergencyInfo,
30
- GameState as GoalGameState,
31
- TaskInfo,
32
- } from '../../../../sdk/types.js';
33
-
34
- const RECENT_KILL_IGNORE_MS = 3_000;
35
-
36
- /** Package-internal input helper for bundled Behavior implementations. */
37
- export function clawclawStrategyStringList(
38
- parameters: Readonly<Record<string, unknown>>,
39
- controlId: string,
40
- ): string[] {
41
- const value = parameters[controlId];
42
- return Array.isArray(value)
43
- ? value.filter((entry): entry is string => typeof entry === 'string')
44
- : [];
45
- }
46
-
47
- /** Package-internal input helper for bundled Behavior implementations. */
48
- export function clawclawStrategyString(
49
- parameters: Readonly<Record<string, unknown>>,
50
- controlId: string,
51
- ): string {
52
- const value = parameters[controlId];
53
- return typeof value === 'string' ? value : '';
54
- }
55
-
56
- interface OfficialGoalTask extends Position {
57
- readonly name: string;
58
- readonly room: string;
59
- readonly status: string;
60
- readonly is_fake_shrimp?: boolean;
61
- readonly task_note?: string;
62
- }
63
-
64
- interface OfficialGoalTaskLocation extends Position {
65
- readonly name: string;
66
- readonly room?: string;
67
- readonly faction?: 'lobster' | 'crab';
68
- }
69
-
70
- interface OfficialGoalMapInfo {
71
- readonly rooms: readonly {
72
- readonly name: string;
73
- readonly polygon: readonly (readonly [number, number])[];
74
- }[];
75
- readonly all_players: readonly {
76
- readonly name: string;
77
- readonly seat: number;
78
- }[];
79
- readonly your_tasks?: readonly OfficialGoalTask[];
80
- readonly all_task_locations: readonly OfficialGoalTaskLocation[];
81
- }
82
-
83
- interface OfficialBehaviorStatusState {
84
- readonly activity: StrategyIntentActivity;
85
- readonly summary: string;
86
- readonly room?: string;
87
- readonly task?: string;
88
- readonly targetPlayer?: string;
89
- readonly dataAvailability?: Readonly<{
90
- readonly tasks?: 'available' | 'unavailable';
91
- }>;
92
- }
93
-
94
- interface OfficialGoalBehaviorOptions {
95
- readonly id: string;
96
- readonly requiresTasks?: boolean;
97
- /** Defaults to true. Task-only behaviors can avoid copying the static map every epoch. */
98
- readonly requiresMap?: boolean;
99
- readonly sidecarSpeech?: boolean;
100
- /** Static target groups whose current-frame A* routes should be analyzed off-thread. */
101
- readonly routeEvidenceTargets?: readonly ('tasks' | 'rooms' | 'hide')[];
102
- /** Return a user-facing reason when declared input fields are not ready yet. */
103
- readonly validateParameters?: (parameters: Readonly<Record<string, unknown>>) => string | undefined;
104
- readonly create: (parameters: Readonly<Record<string, unknown>>) => Strategy;
105
- }
106
-
107
- interface OfficialGoalBehaviorResources {
108
- readonly tasks: readonly OfficialGoalTask[] | null;
109
- readonly tasksAvailable: boolean;
110
- readonly map?: Readonly<OfficialGoalMapInfo>;
111
- }
112
-
113
- function sameControlValue(left: unknown, right: unknown): boolean {
114
- if (Object.is(left, right)) return true;
115
- if (!Array.isArray(left) || !Array.isArray(right) || left.length !== right.length) return false;
116
- return left.every((value, index) => Object.is(value, right[index]));
117
- }
118
-
119
- function sameBehaviorInput(
120
- left: Readonly<Record<string, unknown>>,
121
- right: Readonly<Record<string, unknown>>,
122
- ): boolean {
123
- const leftKeys = Object.keys(left);
124
- const rightKeys = Object.keys(right);
125
- return leftKeys.length === rightKeys.length
126
- && leftKeys.every(key => Object.hasOwn(right, key) && sameControlValue(left[key], right[key]));
127
- }
128
-
129
- function projectedPlayerRef(value: unknown): Record<string, any> {
130
- return value && typeof value === 'object' && !Array.isArray(value)
131
- ? value as Record<string, any>
132
- : {};
133
- }
134
-
135
- function frameEvents(frame: BehaviorInput): Record<string, any>[] {
136
- return frame.events.map((event) => {
137
- const payload = event.payload as Record<string, any>;
138
- const actor = projectedPlayerRef(payload.actor);
139
- const target = projectedPlayerRef(payload.target);
140
- const killer = projectedPlayerRef(payload.killer);
141
- return {
142
- ...payload,
143
- type: event.type,
144
- ...(typeof actor.name === 'string' ? { actor_name: actor.name } : {}),
145
- ...(typeof target.name === 'string' ? { target_name: target.name } : {}),
146
- ...(typeof killer.name === 'string' ? { killer_name: killer.name } : {}),
147
- ...(event.type === 'corpse_spotted' ? {
148
- ...(typeof target.name === 'string' ? { corpse_name: target.name } : {}),
149
- ...(typeof payload.room === 'string' ? { corpse_room: payload.room } : {}),
150
- ...(Number.isFinite(Number(payload.x)) ? { corpse_x: Number(payload.x) } : {}),
151
- ...(Number.isFinite(Number(payload.y)) ? { corpse_y: Number(payload.y) } : {}),
152
- } : {}),
153
- };
154
- });
155
- }
156
-
157
- /** Project the documented GameSync v2 player view into the bundled Goal contract. */
158
- function projectGoalGameState(
159
- source: Readonly<GameState>,
160
- events: readonly Record<string, any>[],
161
- ): GoalGameState {
162
- const raw = source as Readonly<Record<string, any>>;
163
- const rawYou = projectedPlayerRef(raw.you);
164
- const self = projectedPlayerRef(rawYou.player);
165
- const activity = projectedPlayerRef(rawYou.activity);
166
- const visiblePlayers = (Array.isArray(raw.visible_players) ? raw.visible_players : [])
167
- .map((entry: unknown) => {
168
- const visible = projectedPlayerRef(entry);
169
- return { ...projectedPlayerRef(visible.player), ...visible };
170
- })
171
- .map(({ player: _player, ...visible }) => visible);
172
- const visibleCorpses = (Array.isArray(raw.visible_corpses) ? raw.visible_corpses : [])
173
- .map((entry: unknown) => {
174
- const corpse = projectedPlayerRef(entry);
175
- return { ...projectedPlayerRef(corpse.player), ...corpse };
176
- })
177
- .map(({ player: _player, ...corpse }) => corpse);
178
- const knownPlayers = (Array.isArray(raw.players) ? raw.players : []).map((entry: unknown) => {
179
- const player = projectedPlayerRef(entry);
180
- const knownStatus = projectedPlayerRef(player.known_status);
181
- return {
182
- seat: player.seat,
183
- name: player.name,
184
- role: 'unknown',
185
- ...(typeof knownStatus.is_alive === 'boolean'
186
- ? { is_alive: knownStatus.is_alive }
187
- : {}),
188
- };
189
- });
190
- return normalizeGameState({
191
- ...raw,
192
- you: {
193
- ...rawYou,
194
- ...self,
195
- currently_moving: activity.kind === 'moving',
196
- doing_task: activity.kind === 'task',
197
- ...(activity.kind === 'task' && typeof activity.task_name === 'string'
198
- ? { task_name: activity.task_name }
199
- : {}),
200
- ...(typeof activity.remaining_secs === 'number'
201
- ? { remaining_secs: activity.remaining_secs }
202
- : {}),
203
- },
204
- players: visiblePlayers,
205
- visible_players: visiblePlayers,
206
- corpses: visibleCorpses,
207
- nearby_corpses: visibleCorpses,
208
- all_players: knownPlayers,
209
- ...(raw.alive_count === undefined
210
- ? { alive_count: knownPlayers.filter((player) => player.is_alive === true).length }
211
- : {}),
212
- ...(raw.emergency?.active === true
213
- ? { emergency: raw.emergency }
214
- : { emergency: undefined }),
215
- new_events: events,
216
- stale: false,
217
- });
218
- }
219
-
220
- function point(value: unknown): { x: number; y: number } | null {
221
- if (!value || typeof value !== 'object') return null;
222
- const entry = value as Record<string, unknown>;
223
- const x = Number(entry.x ?? (Array.isArray(value) ? value[0] : undefined));
224
- const y = Number(entry.y ?? (Array.isArray(value) ? value[1] : undefined));
225
- return Number.isFinite(x) && Number.isFinite(y) ? { x, y } : null;
226
- }
227
-
228
- function roomTarget(
229
- room: OfficialGoalMapInfo['rooms'][number],
230
- taskLocations: readonly OfficialGoalTaskLocation[],
231
- ): RoomTarget {
232
- const task = taskLocations.find((candidate) => candidate.room === room.name);
233
- if (task) return { name: room.name, x: task.x, y: task.y };
234
- const polygon = room.polygon.map(point).filter((value): value is { x: number; y: number } => !!value);
235
- if (polygon.length === 0) return { name: room.name, x: 0, y: 0 };
236
- return {
237
- name: room.name,
238
- x: polygon.reduce((sum, value) => sum + value.x, 0) / polygon.length,
239
- y: polygon.reduce((sum, value) => sum + value.y, 0) / polygon.length,
240
- };
241
- }
242
-
243
- function packagedGoalMap(
244
- gameState: Readonly<GameState>,
245
- spatialRooms: BehaviorReadApi['spatial']['rooms'],
246
- ): Readonly<OfficialGoalMapInfo> {
247
- const asset = loadClawclawMapAsset();
248
- const rooms = spatialRooms.map(room => ({
249
- name: room.name,
250
- polygon: structuredClone(room.polygon),
251
- }));
252
- const allTaskLocations = (Array.isArray(asset?.tasks) ? asset.tasks : [])
253
- .map((task: Record<string, any>) => ({
254
- name: String(task.name ?? ''),
255
- room: typeof task.room === 'string' ? task.room : undefined,
256
- x: Number(task.x),
257
- y: Number(task.y),
258
- faction: Number(task.task_type) === 1 ? 'crab' as const : 'lobster' as const,
259
- }))
260
- .filter((task: OfficialGoalTaskLocation) => (
261
- task.name && Number.isFinite(task.x) && Number.isFinite(task.y)
262
- ));
263
- const allPlayers = (gameState.players ?? []).flatMap(player => (
264
- typeof player.name === 'string' && Number.isInteger(player.seat)
265
- ? [{ name: player.name, seat: player.seat }]
266
- : []
267
- ));
268
- return {
269
- rooms,
270
- all_players: allPlayers,
271
- all_task_locations: allTaskLocations,
272
- ...(Array.isArray(gameState.you?.tasks) ? { your_tasks: gameState.you.tasks } : {}),
273
- };
274
- }
275
-
276
- function fallbackActionIntent(state: GoalGameState, action: Record<string, any>): StrategyIntent {
277
- const room = state.you.room || undefined;
278
- if (action.action === 'move') {
279
- const destination = typeof action.target === 'string' && action.target.trim()
280
- ? action.target.trim()
281
- : undefined;
282
- return {
283
- activity: 'moving',
284
- summary: destination ? `正在前往${destination}。` : '正在移动。',
285
- ...(destination ? { room: destination } : room ? { room } : {}),
286
- };
287
- }
288
- if (action.action === 'task') {
289
- const task = typeof action.task_name === 'string' && action.task_name.trim()
290
- ? action.task_name.trim()
291
- : undefined;
292
- return {
293
- activity: 'doing_task',
294
- summary: task
295
- ? `正在${room || '当前位置'}开始任务“${task}”。`
296
- : `正在${room || '当前位置'}开始任务。`,
297
- ...(room ? { room } : {}),
298
- ...(task ? { task } : {}),
299
- };
300
- }
301
- if (action.action === 'kill' && Number.isInteger(action.target_seat)) {
302
- const knownTarget = [...state.players, ...(state.all_players ?? [])]
303
- .find(player => player.seat === action.target_seat);
304
- const target = knownTarget?.name != null
305
- ? `${action.target_seat}号${knownTarget.name}`
306
- : `${action.target_seat}号`;
307
- return {
308
- activity: 'acting',
309
- summary: `正在击杀${target}。`,
310
- ...(room ? { room } : {}),
311
- ...(knownTarget?.name ? { targetPlayer: knownTarget.name } : {}),
312
- };
313
- }
314
- if (action.action === 'report') {
315
- return {
316
- activity: 'acting',
317
- summary: '正在报告尸体并召集会议。',
318
- ...(room ? { room } : {}),
319
- };
320
- }
321
- if (action.action === 'speech') {
322
- return {
323
- activity: 'acting',
324
- summary: '正在与附近玩家交流。',
325
- ...(room ? { room } : {}),
326
- };
327
- }
328
- return {
329
- activity: 'acting',
330
- summary: '正在执行策略动作。',
331
- ...(room ? { room } : {}),
332
- };
333
- }
334
-
335
- function sameMove(left: Record<string, any>, right: Record<string, any>): boolean {
336
- if (left.action !== 'move' || right.action !== 'move') return false;
337
- if ((left.stop_on_player === true) !== (right.stop_on_player === true)) return false;
338
- if (typeof left.target === 'string' || typeof right.target === 'string') {
339
- return String(left.target ?? '').trim().toLowerCase() === String(right.target ?? '').trim().toLowerCase();
340
- }
341
- const dx = Number(left.target_x) - Number(right.target_x);
342
- const dy = Number(left.target_y) - Number(right.target_y);
343
- return Number.isFinite(dx) && Number.isFinite(dy) && Math.hypot(dx, dy) <= 10;
344
- }
345
-
346
- /**
347
- * Package-internal adapter for the bundled long Behaviors' existing Goal trees.
348
- *
349
- * It consumes only the public Behavior input/read contracts and proposes
350
- * Decisions. It never submits effects or opens another data channel.
351
- */
352
- export class OfficialGoalBehavior {
353
- private readonly behaviorId: string;
354
- private readonly options: OfficialGoalBehaviorOptions;
355
- private strategy?: Strategy;
356
- private readonly context: StrategyContext;
357
- private readonly corpseMemory = new CorpseMemory();
358
- private modules: CustomModule[];
359
- private effectiveParameters: Readonly<Record<string, unknown>>;
360
- private currentRole = '';
361
- private configurationError?: string;
362
- private mapCache?: Readonly<OfficialGoalMapInfo>;
363
- private tasksAvailable = true;
364
- private activeMove?: {
365
- payload: Record<string, any>;
366
- intent?: StrategyIntent;
367
- epochId: number;
368
- };
369
-
370
- constructor(options: OfficialGoalBehaviorOptions) {
371
- this.options = options;
372
- this.behaviorId = options.id;
373
- this.effectiveParameters = Object.freeze({});
374
- this.strategy = undefined;
375
- this.context = {
376
- taskData: [],
377
- taskLocations: [],
378
- emergency: null,
379
- taskLocalBlockedUntil: 0,
380
- reportCorpseTarget: null,
381
- reportBlockedUntil: 0,
382
- octopusTimeActive: false,
383
- notifications: [],
384
- lastProgressNotifyAt: 0,
385
- teammates: new Set(),
386
- rooms: [],
387
- playerNamesBySeat: {},
388
- forcePatrolAdvance: false,
389
- blockedMoveTarget: null,
390
- mySeat: 0,
391
- speechNotifications: [],
392
- agentAlerts: [],
393
- knownCorpses: [],
394
- recentlyKilledTargets: new Map(),
395
- };
396
- this.modules = [];
397
- }
398
-
399
- private synchronizeInput(values: Readonly<Record<string, unknown>>): void {
400
- if (sameBehaviorInput(this.effectiveParameters, values) && !this.configurationError) return;
401
- const effectiveParameters = Object.freeze(structuredClone(values));
402
- const configurationError = this.options.validateParameters?.(effectiveParameters);
403
- this.effectiveParameters = effectiveParameters;
404
- this.configurationError = configurationError;
405
- this.currentRole = '';
406
- this.activeMove = undefined;
407
- this.context.intent = undefined;
408
- if (configurationError) {
409
- this.strategy = undefined;
410
- this.modules = [];
411
- delete this.context.customModules;
412
- return;
413
- }
414
- const strategy = this.options.create(effectiveParameters);
415
- const modules = strategy.customModules?.() ?? [];
416
- this.strategy = strategy;
417
- this.modules = modules;
418
- if (modules.length > 0) this.context.customModules = modules;
419
- else delete this.context.customModules;
420
- if (this.mapCache) {
421
- for (const module of modules) module.onMapLoaded?.([...this.mapCache.rooms]);
422
- }
423
- }
424
-
425
- async decide(
426
- frame: BehaviorInput,
427
- api: BehaviorReadApi,
428
- ): Promise<BehaviorDecision> {
429
- this.synchronizeInput(frame.input);
430
- const events = frameEvents(frame);
431
- const state = projectGoalGameState(frame.gameState, events);
432
- if (!state.you?.is_alive) {
433
- return this.status({ activity: 'idle', summary: '当前角色已死亡,策略停止行动。' });
434
- }
435
- const strategy = this.ensureStrategy();
436
- if (!strategy) {
437
- return this.status({
438
- activity: 'waiting',
439
- summary: this.configurationError ?? `${this.behaviorId} 正在等待参数配置。`,
440
- ...(state.you.room ? { room: state.you.room } : {}),
441
- });
442
- }
443
- const resources = this.loadMapAndTasks(frame, api);
444
-
445
- this.learnRoleAndPlayers(state, events);
446
- this.applyMapAndTasks(state, resources);
447
- this.context.routeEvidence = await this.buildRouteEvidence(frame, resources, api) ?? null;
448
- this.context.emergency = this.emergency(state);
449
- this.corpseMemory.observe(state, this.context.recentlyKilledTargets);
450
- this.context.knownCorpses = this.corpseMemory.list();
451
- for (const module of this.modules) module.processEvents(events, state.tick, state);
452
-
453
- if (this.activeMove && (
454
- events.some((event) => event.type === 'move_end' || event.type === 'move_interrupted')
455
- || (
456
- frame.epochId > this.activeMove.epochId
457
- && state.you.currently_moving !== true
458
- )
459
- )) {
460
- this.activeMove = undefined;
461
- }
462
-
463
- this.context.intent = undefined;
464
- let decisions = strategy.decide(state, this.context);
465
- for (const module of this.modules) {
466
- if (module.afterDecide) decisions = module.afterDecide(decisions, state, this.context);
467
- }
468
- const speech = this.options.sidecarSpeech
469
- ? decisions.filter((decision) => decision.action.toJSON().action === 'speech')
470
- : [];
471
- const main = speech.length > 0
472
- ? decisions.filter((decision) => decision.action.toJSON().action !== 'speech')
473
- : decisions;
474
- const decision = main.find(candidate => !this.repeatsActiveMove(candidate));
475
- const proposed = decision
476
- ? this.propose(decision, frame.epochId, state)
477
- : undefined;
478
- const sidecarProposals: Array<{
479
- payload: Record<string, any>;
480
- intent?: StrategyIntent;
481
- }> = [];
482
- for (const sidecar of speech) {
483
- sidecarProposals.push(this.propose(sidecar, frame.epochId, state));
484
- }
485
-
486
- const proposedEvents: NonNullable<BehaviorDecision['events']> = [
487
- ...this.context.agentAlerts.map((message) => ({
488
- type: 'strategy_alert',
489
- payload: { message, strategy: this.behaviorId, tick: state.tick },
490
- })),
491
- ...this.context.speechNotifications.map((message) => ({
492
- type: 'robot_speak_rule',
493
- payload: { message },
494
- })),
495
- ];
496
- this.context.agentAlerts.length = 0;
497
- this.context.speechNotifications.length = 0;
498
- this.context.notifications.length = 0;
499
-
500
- const actions = [proposed, ...sidecarProposals]
501
- .filter((candidate): candidate is NonNullable<typeof candidate> => candidate !== undefined)
502
- .map(candidate => candidate.payload as GameAction);
503
- const status = this.statusFor(state, proposed ?? sidecarProposals[0]);
504
- return {
505
- ...status,
506
- ...(actions.length > 0 ? { actions } : {}),
507
- ...(proposedEvents.length > 0 ? { events: proposedEvents } : {}),
508
- };
509
- }
510
-
511
- private learnRoleAndPlayers(state: GoalGameState, events: readonly Record<string, any>[]): void {
512
- const role = state.you.role ?? '';
513
- if (role && role !== this.currentRole) {
514
- this.currentRole = role;
515
- this.strategy?.updateRole?.(role);
516
- }
517
- if (state.you.seat != null) this.context.mySeat = state.you.seat;
518
- for (const player of state.all_players ?? state.players ?? []) {
519
- if (player.seat != null && player.name) this.context.playerNamesBySeat[String(player.seat)] = player.name;
520
- }
521
- const teammateSeat = (teammate: unknown): string | null => {
522
- const ref = projectedPlayerRef(teammate);
523
- const seat = Number(ref.seat);
524
- return Number.isInteger(seat) && seat >= 1 ? String(seat) : null;
525
- };
526
- for (const event of events) {
527
- if (event.type === 'octopus_time_start') this.context.octopusTimeActive = true;
528
- const eventTeammates = Array.isArray(event.crab_teammates)
529
- ? event.crab_teammates
530
- : [];
531
- for (const teammate of eventTeammates) {
532
- const seat = teammateSeat(teammate);
533
- if (seat) this.context.teammates.add(seat);
534
- }
535
- }
536
- const stateTeammates = state.you.crab_teammates;
537
- for (const teammate of Array.isArray(stateTeammates) ? stateTeammates : []) {
538
- const seat = teammateSeat(teammate);
539
- if (seat) this.context.teammates.add(seat);
540
- }
541
- }
542
-
543
- private ensureStrategy(): Strategy | undefined {
544
- if (this.strategy || this.configurationError) return this.strategy;
545
- const strategy = this.options.create(this.effectiveParameters);
546
- const modules = strategy.customModules?.() ?? [];
547
- this.strategy = strategy;
548
- this.modules = modules;
549
- if (modules.length > 0) this.context.customModules = modules;
550
- if (this.mapCache) {
551
- for (const module of modules) module.onMapLoaded?.([...this.mapCache.rooms]);
552
- }
553
- return strategy;
554
- }
555
-
556
- private loadMapAndTasks(
557
- frame: BehaviorInput,
558
- api: BehaviorReadApi,
559
- ): OfficialGoalBehaviorResources {
560
- const projectedTasks = frame.gameState.you?.tasks;
561
- const tasks = this.options.requiresTasks
562
- ? (Array.isArray(projectedTasks) ? projectedTasks : null)
563
- : [];
564
- const tasksAvailable = tasks !== null;
565
- let map = this.mapCache;
566
- if (this.options.requiresMap !== false && !map) {
567
- map = packagedGoalMap(frame.gameState, api.spatial.rooms);
568
- }
569
- return { tasks, tasksAvailable, ...(map ? { map } : {}) };
570
- }
571
-
572
- private async buildRouteEvidence(
573
- frame: BehaviorInput,
574
- resources: OfficialGoalBehaviorResources,
575
- api: BehaviorReadApi,
576
- ): Promise<RouteEvidence | null | undefined> {
577
- const targets = this.options.routeEvidenceTargets;
578
- const you = frame.gameState.you;
579
- if (
580
- !you
581
- || typeof you.x !== 'number'
582
- || typeof you.y !== 'number'
583
- || !targets
584
- || targets.length === 0
585
- ) return undefined;
586
- const points: Array<{ x: number; y: number }> = [];
587
- if (targets.includes('tasks')) {
588
- for (const task of resources.tasks ?? []) points.push({ x: task.x, y: task.y });
589
- }
590
- if (targets.includes('rooms') && resources.map) {
591
- for (const room of resources.map.rooms) {
592
- const target = roomTarget(room, resources.map.all_task_locations);
593
- points.push({ x: target.x, y: target.y });
594
- }
595
- }
596
- if (targets.includes('hide')) {
597
- for (const spot of HIDE_SPOTS) points.push({ x: spot.x, y: spot.y });
598
- }
599
- if (points.length === 0) return undefined;
600
- const from = { x: you.x, y: you.y };
601
- const evidence = buildRouteEvidence(from, points);
602
- if (!evidence) return evidence;
603
- const distances = await api.navigation.pathDistances(points.map(to => ({ from, to })));
604
- const distanceByPoint = new Map(points.map((point, index) => [
605
- `${point.x}\u0000${point.y}`,
606
- distances[index] ?? null,
607
- ]));
608
- return {
609
- ...evidence,
610
- routes: evidence.routes.map(route => ({
611
- ...route,
612
- distancePx: distanceByPoint.get(`${route.point.x}\u0000${route.point.y}`) ?? Infinity,
613
- })),
614
- };
615
- }
616
-
617
- private applyMapAndTasks(
618
- state: GoalGameState,
619
- resources: OfficialGoalBehaviorResources,
620
- ): void {
621
- const { tasks, map } = resources;
622
- const firstMapLoad = map !== undefined && this.mapCache === undefined;
623
- if (map) this.mapCache = map;
624
- this.tasksAvailable = resources.tasksAvailable;
625
- const factionByName = new Map(
626
- (map?.all_task_locations ?? []).map((task) => [task.name, task.faction]),
627
- );
628
- this.context.taskData = (tasks ?? []).map((task): TaskInfo => ({
629
- task_id: task.name,
630
- task_name: task.name,
631
- room: task.room,
632
- status: task.status,
633
- x: task.x,
634
- y: task.y,
635
- is_fake_shrimp: task.is_fake_shrimp ?? false,
636
- faction: factionByName.get(task.name),
637
- }));
638
- if (tasks === null) delete state.your_tasks;
639
- else state.your_tasks = this.context.taskData;
640
- if (map) {
641
- this.context.taskLocations = map.all_task_locations.map((task) => ({
642
- name: task.name,
643
- room: task.room,
644
- x: task.x,
645
- y: task.y,
646
- faction: task.faction,
647
- }));
648
- this.context.rooms = map.rooms.map((room) => roomTarget(room, map.all_task_locations));
649
- if (firstMapLoad) {
650
- for (const module of this.modules) module.onMapLoaded?.([...map.rooms]);
651
- }
652
- for (const player of map.all_players) {
653
- this.context.playerNamesBySeat[String(player.seat)] = player.name;
654
- }
655
- }
656
- }
657
-
658
- private emergency(state: GoalGameState): EmergencyInfo | null {
659
- const value = state.emergency;
660
- if (!value) return null;
661
- return {
662
- task_id: value.task_name ?? '',
663
- task_name: value.task_name ?? '',
664
- room: value.room ?? '',
665
- status: value.status ?? 'emergency',
666
- x: value.x,
667
- y: value.y,
668
- remaining_secs: Number(value.remaining_secs ?? 0),
669
- };
670
- }
671
-
672
- private repeatsActiveMove(decision: GoalBehaviorDecision): boolean {
673
- if (!this.activeMove) return false;
674
- if (!sameMove(decision.action.toJSON(), this.activeMove.payload)) return false;
675
- return true;
676
- }
677
-
678
- private propose(
679
- decision: GoalBehaviorDecision,
680
- epochId: number,
681
- state: GoalGameState,
682
- ): { payload: Record<string, any>; intent?: StrategyIntent } {
683
- const payload = decision.action.toJSON();
684
- const intent = decision.intent ?? this.context.intent;
685
- delete payload.audio_url;
686
- if (payload.action === 'move') {
687
- this.activeMove = {
688
- payload,
689
- intent,
690
- epochId,
691
- };
692
- }
693
- if (payload.action === 'kill' && Number.isInteger(payload.target_seat)) {
694
- this.context.recentlyKilledTargets?.set(
695
- String(payload.target_seat),
696
- Date.now() + RECENT_KILL_IGNORE_MS,
697
- );
698
- }
699
- return { payload, intent };
700
- }
701
-
702
- private status(value: OfficialBehaviorStatusState): BehaviorDecision {
703
- const { dataAvailability, ...status } = value;
704
- return {
705
- status: {
706
- ...status,
707
- ...(dataAvailability ? { data: { dataAvailability } } : {}),
708
- },
709
- };
710
- }
711
-
712
- private statusFor(
713
- state: GoalGameState,
714
- proposed?: { payload: Record<string, any>; intent?: StrategyIntent },
715
- ): BehaviorDecision {
716
- const publish = (
717
- value: OfficialBehaviorStatusState,
718
- ): BehaviorDecision => this.status({
719
- ...value,
720
- ...(this.options.requiresTasks ? {
721
- dataAvailability: {
722
- tasks: this.tasksAvailable ? 'available' : 'unavailable',
723
- },
724
- } : {}),
725
- });
726
- const taskStatus = (): OfficialBehaviorStatusState => ({
727
- activity: 'doing_task',
728
- summary: state.you.task_name
729
- ? `正在${state.you.room || '当前位置'}执行任务“${state.you.task_name}”。`
730
- : `正在${state.you.room || '当前位置'}执行任务。`,
731
- ...(state.you.room ? { room: state.you.room } : {}),
732
- ...(state.you.task_name ? { task: state.you.task_name } : {}),
733
- });
734
- if (proposed) {
735
- return publish(proposed.intent ?? fallbackActionIntent(state, proposed.payload));
736
- }
737
- if (state.you.doing_task) {
738
- return publish(taskStatus());
739
- }
740
- if (this.activeMove) {
741
- return publish(this.activeMove.intent ?? fallbackActionIntent(state, this.activeMove.payload));
742
- }
743
- if (this.context.intent) return publish(this.context.intent);
744
- if (state.you.currently_moving) {
745
- return publish({
746
- activity: 'moving',
747
- summary: '正在继续移动。',
748
- ...(state.you.room ? { room: state.you.room } : {}),
749
- });
750
- }
751
- return publish({
752
- activity: 'idle',
753
- summary: `当前没有可执行动作,正在${state.you.room || '当前位置'}等待。`,
754
- ...(state.you.room ? { room: state.you.room } : {}),
755
- });
756
- }
757
- }