@myclaw163/clawclaw-cli 0.7.15 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (335) hide show
  1. package/QUICKSTART_HERMES.md +1 -1
  2. package/QUICKSTART_OPENCLAW.md +3 -11
  3. package/QUICKSTART_OTHER.md +8 -8
  4. package/README.md +18 -9
  5. package/bin/clawclaw-channel.mjs +13 -0
  6. package/docs/configuration.md +86 -33
  7. package/docs/custom-modules/README.md +148 -0
  8. package/docs/custom-modules/api-reference.md +767 -0
  9. package/docs/custom-modules/behavior.md +318 -0
  10. package/docs/custom-modules/perception.md +305 -0
  11. package/docs/custom-modules/trigger.md +292 -0
  12. package/docs/desktop-event-push.md +6 -4
  13. package/docs/runtime/README.md +28 -10
  14. package/docs/runtime/agent-notifications.md +48 -29
  15. package/docs/runtime/behavior-runtime.md +139 -0
  16. package/docs/runtime/components-and-boundaries.md +89 -173
  17. package/docs/runtime/events-and-state.md +55 -66
  18. package/docs/runtime/official-perception-modules.md +17 -9
  19. package/docs/runtime/owner-lifecycle-and-observability.md +62 -39
  20. package/docs/runtime/perception-replay.md +6 -6
  21. package/docs/runtime/short-commands-and-capabilities.md +35 -37
  22. package/package.json +7 -4
  23. package/scripts/check-skill-command-surface.mjs +54 -10
  24. package/scripts/compare-perception-replays.test.ts +10 -10
  25. package/scripts/compare-perception-replays.ts +14 -10
  26. package/scripts/replay-perception.ts +3 -3
  27. package/scripts/watch-perception-events.test.ts +1 -1
  28. package/skills/clawclaw/SKILL.md +97 -59
  29. package/skills/clawclaw/references/BEHAVIORS.md +154 -0
  30. package/skills/clawclaw/references/CHANNELS.md +115 -0
  31. package/skills/clawclaw/references/CHATTERBOX.md +3 -2
  32. package/skills/clawclaw/references/COMMANDS.md +108 -58
  33. package/skills/clawclaw/references/GAME-MECHANICS.md +4 -3
  34. package/skills/clawclaw/references/HUB.md +27 -23
  35. package/skills/clawclaw/references/STREAM.md +18 -14
  36. package/skills/clawclaw/references/TACTICS.md +2 -2
  37. package/src/behaviors/official-finite/do-task.ts +141 -0
  38. package/src/behaviors/official-finite/evade.ts +78 -0
  39. package/src/behaviors/official-finite/find-player.ts +50 -0
  40. package/src/behaviors/official-finite/follow-player.ts +70 -0
  41. package/src/behaviors/official-finite/go-to.ts +69 -0
  42. package/src/behaviors/official-finite/hide-temporarily.ts +77 -0
  43. package/src/behaviors/official-finite/hold-position.ts +48 -0
  44. package/src/behaviors/official-finite/hunt-player.ts +47 -0
  45. package/src/behaviors/official-finite/index.test.ts +202 -0
  46. package/src/behaviors/official-finite/index.ts +47 -0
  47. package/src/behaviors/official-finite/inspect-corpse.ts +64 -0
  48. package/src/behaviors/official-finite/patrol-area.ts +80 -0
  49. package/src/behaviors/official-finite/report-corpse.ts +73 -0
  50. package/src/behaviors/official-finite/seek-kill-opportunity.ts +152 -0
  51. package/src/behaviors/official-finite/shared.ts +27 -0
  52. package/src/behaviors/official-finite/trigger-alarm.ts +53 -0
  53. package/src/channel/claude-channel-ipc-server.ts +295 -0
  54. package/src/channel/claude-channel-ipc.ts +152 -0
  55. package/src/channel/claude-channel-server.test.ts +202 -0
  56. package/src/channel/claude-channel-server.ts +221 -0
  57. package/src/cli.ts +4 -2
  58. package/src/commands/account.test.ts +17 -17
  59. package/src/commands/behavior.test.ts +158 -0
  60. package/src/commands/behavior.ts +443 -0
  61. package/src/commands/communication.test.ts +12 -0
  62. package/src/commands/communication.ts +6 -3
  63. package/src/commands/data.test.ts +1 -1
  64. package/src/commands/data.ts +1 -1
  65. package/src/commands/events-canonical-state.test.ts +221 -2
  66. package/src/commands/events.ts +205 -12
  67. package/src/commands/game/index.test.ts +172 -3
  68. package/src/commands/game/index.ts +69 -32
  69. package/src/commands/hub.test.ts +25 -14
  70. package/src/commands/hub.ts +15 -19
  71. package/src/commands/load.test.ts +228 -6
  72. package/src/commands/load.ts +102 -18
  73. package/src/commands/memory.ts +1 -1
  74. package/src/commands/peek.ts +1 -1
  75. package/src/commands/perception.test.ts +30 -1
  76. package/src/commands/perception.ts +15 -17
  77. package/src/commands/trigger.test.ts +140 -0
  78. package/src/commands/trigger.ts +314 -0
  79. package/src/lib/account-guidance.test.ts +4 -0
  80. package/src/lib/account-guidance.ts +1 -1
  81. package/src/lib/behavior-export.test.ts +282 -0
  82. package/src/lib/behavior-export.ts +514 -0
  83. package/src/lib/game-client.test.ts +4 -17
  84. package/src/lib/game-client.ts +3 -0
  85. package/src/lib/gameplay-config.test.ts +258 -37
  86. package/src/lib/gameplay-config.ts +175 -35
  87. package/src/lib/hub-install.test.ts +19 -41
  88. package/src/lib/hub-install.ts +10 -38
  89. package/src/lib/hub-reminder.ts +7 -9
  90. package/src/lib/init-command.ts +1 -1
  91. package/src/lib/official-resource-sync.test.ts +199 -0
  92. package/src/lib/official-resource-sync.ts +221 -0
  93. package/src/lib/perception-config.test.ts +9 -4
  94. package/src/lib/perception-config.ts +10 -13
  95. package/src/lib/perception-export.test.ts +145 -0
  96. package/src/lib/perception-export.ts +178 -0
  97. package/src/lib/trigger-config.test.ts +102 -0
  98. package/src/lib/trigger-config.ts +217 -0
  99. package/src/lib/user-data.test.ts +23 -6
  100. package/src/lib/user-data.ts +15 -123
  101. package/src/pipeline/canonical-event-presentation.test.ts +5 -5
  102. package/src/pipeline/canonical-event-presentation.ts +13 -5
  103. package/src/pipeline/event-format.test.ts +106 -3
  104. package/src/pipeline/event-format.ts +172 -4
  105. package/src/pipeline/event-hints.test.ts +57 -4
  106. package/src/pipeline/event-hints.ts +34 -8
  107. package/src/runtime/canonical-monitor.test.ts +2 -0
  108. package/src/runtime/canonical-monitor.ts +6 -2
  109. package/src/runtime/clawclaw/agent-event-policy.test.ts +23 -2
  110. package/src/runtime/clawclaw/agent-event-policy.ts +12 -5
  111. package/src/runtime/clawclaw/behavior-decision.test.ts +29 -0
  112. package/src/runtime/clawclaw/behavior-decision.ts +82 -0
  113. package/src/runtime/clawclaw/behavior-input-fields.test.ts +175 -0
  114. package/src/runtime/clawclaw/behavior-input-fields.ts +270 -0
  115. package/src/runtime/clawclaw/behavior-input.test.ts +151 -0
  116. package/src/runtime/clawclaw/behavior-input.ts +70 -0
  117. package/src/runtime/clawclaw/behavior-observation-memory.test.ts +59 -0
  118. package/src/runtime/clawclaw/behavior-observation-memory.ts +142 -0
  119. package/src/runtime/clawclaw/behavior-read-api.test.ts +123 -0
  120. package/src/runtime/clawclaw/behavior-read-api.ts +158 -0
  121. package/src/runtime/clawclaw/{plugins/perception/visual-state-projector.ts → observation-frame-projector.ts} +44 -25
  122. package/src/runtime/clawclaw/owner.test.ts +187 -0
  123. package/src/runtime/clawclaw/owner.ts +431 -69
  124. package/src/runtime/clawclaw/plugins/action/action-plugin.test.ts +304 -0
  125. package/src/runtime/clawclaw/plugins/action/action-plugin.ts +286 -41
  126. package/src/runtime/clawclaw/plugins/action/automated-action-normalization.ts +82 -0
  127. package/src/runtime/clawclaw/plugins/assembly.test.ts +135 -29
  128. package/src/runtime/clawclaw/plugins/assembly.ts +54 -28
  129. package/src/runtime/clawclaw/plugins/behavior/activation-manager.test.ts +180 -0
  130. package/src/runtime/clawclaw/plugins/behavior/activation-manager.ts +468 -0
  131. package/src/runtime/clawclaw/plugins/behavior/behavior-action.test.ts +40 -0
  132. package/src/runtime/clawclaw/plugins/behavior/behavior-action.ts +30 -0
  133. package/src/runtime/clawclaw/plugins/behavior/behavior-analysis-thread-host.ts +152 -0
  134. package/src/runtime/clawclaw/plugins/behavior/behavior-catalog.test.ts +156 -0
  135. package/src/runtime/clawclaw/plugins/behavior/behavior-catalog.ts +104 -0
  136. package/src/runtime/clawclaw/plugins/behavior/behavior-manifest.ts +173 -0
  137. package/src/runtime/clawclaw/plugins/behavior/behavior-module-loader.test.ts +182 -0
  138. package/src/runtime/clawclaw/plugins/behavior/behavior-module-loader.ts +223 -0
  139. package/src/runtime/clawclaw/plugins/behavior/behavior-normalization.ts +157 -0
  140. package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.test.ts +848 -0
  141. package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.ts +1347 -0
  142. package/src/runtime/clawclaw/plugins/behavior/behavior-runner.ts +212 -0
  143. package/src/runtime/clawclaw/plugins/behavior/behavior-source.test.ts +174 -0
  144. package/src/runtime/clawclaw/plugins/behavior/behavior-source.ts +621 -0
  145. package/src/runtime/clawclaw/plugins/behavior/control-driver.test.ts +195 -0
  146. package/src/runtime/clawclaw/plugins/behavior/control-driver.ts +180 -0
  147. package/src/runtime/clawclaw/plugins/behavior/index.ts +11 -0
  148. package/src/runtime/clawclaw/plugins/behavior/official-goal-behavior.ts +766 -0
  149. package/src/runtime/clawclaw/plugins/behavior/thread-behavior-executor.test.ts +283 -0
  150. package/src/runtime/clawclaw/plugins/{strategy/thread-strategy-executor.ts → behavior/thread-behavior-executor.ts} +109 -121
  151. package/src/runtime/clawclaw/plugins/behavior-input-source.test.ts +80 -0
  152. package/src/runtime/clawclaw/plugins/behavior-input-source.ts +247 -0
  153. package/src/runtime/clawclaw/plugins/{strategy → game-query}/context-capabilities.ts +1 -1
  154. package/src/runtime/clawclaw/plugins/game-query/game-query-plugin.test.ts +13 -10
  155. package/src/runtime/clawclaw/plugins/game-query/game-query-plugin.ts +26 -14
  156. package/src/runtime/clawclaw/plugins/game-query/index.ts +1 -0
  157. package/src/runtime/clawclaw/plugins/index.ts +3 -1
  158. package/src/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-adapter.test.ts +239 -0
  159. package/src/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-adapter.ts +100 -0
  160. package/src/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-socket.ts +346 -0
  161. package/src/runtime/clawclaw/plugins/mailbox/agent-mailbox-coordinator.test.ts +230 -12
  162. package/src/runtime/clawclaw/plugins/mailbox/agent-mailbox-coordinator.ts +118 -90
  163. package/src/runtime/clawclaw/plugins/mailbox/consumer-ids.ts +5 -0
  164. package/src/runtime/clawclaw/plugins/mailbox/index.ts +3 -0
  165. package/src/runtime/clawclaw/plugins/mailbox/mailbox-agent-event-batch.test.ts +1 -1
  166. package/src/runtime/clawclaw/plugins/mailbox/mailbox-event-batch-delivery.ts +4 -0
  167. package/src/runtime/clawclaw/plugins/mailbox/mailbox-plugin.test.ts +87 -0
  168. package/src/runtime/clawclaw/plugins/mailbox/mailbox-plugin.ts +70 -12
  169. package/src/runtime/clawclaw/plugins/mailbox/mailbox-presentation.ts +94 -11
  170. package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.test.ts +1229 -345
  171. package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.ts +479 -35
  172. package/src/runtime/clawclaw/plugins/perception/contracts.ts +4 -3
  173. package/src/runtime/clawclaw/plugins/perception/index.ts +1 -1
  174. package/src/runtime/clawclaw/plugins/perception/module-runner.test.ts +23 -13
  175. package/src/runtime/clawclaw/plugins/perception/module-runner.ts +11 -9
  176. package/src/runtime/clawclaw/plugins/perception/modules/co-movement-module.ts +39 -38
  177. package/src/runtime/clawclaw/plugins/perception/modules/corpse-visibility-module.test.ts +92 -0
  178. package/src/runtime/clawclaw/plugins/perception/modules/corpse-visibility-module.ts +248 -0
  179. package/src/runtime/clawclaw/plugins/perception/modules/follow-module.ts +39 -37
  180. package/src/runtime/clawclaw/plugins/perception/modules/index.ts +1 -0
  181. package/src/runtime/clawclaw/plugins/perception/modules/motion-module.test.ts +22 -21
  182. package/src/runtime/clawclaw/plugins/perception/modules/motion-module.ts +15 -9
  183. package/src/runtime/clawclaw/plugins/perception/modules/parallel-module-test-helpers.ts +3 -3
  184. package/src/runtime/clawclaw/plugins/perception/modules/relation-stability.test.ts +33 -18
  185. package/src/runtime/clawclaw/plugins/perception/modules/route-module.test.ts +6 -7
  186. package/src/runtime/clawclaw/plugins/perception/modules/route-module.ts +22 -16
  187. package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.test.ts +6 -7
  188. package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.ts +18 -12
  189. package/src/runtime/clawclaw/plugins/perception/modules/stop-module.test.ts +14 -10
  190. package/src/runtime/clawclaw/plugins/perception/modules/stop-module.ts +20 -14
  191. package/src/runtime/clawclaw/plugins/perception/modules/temporal-evidence.test.ts +5 -6
  192. package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.test.ts +5 -6
  193. package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.ts +49 -34
  194. package/src/runtime/clawclaw/plugins/perception/official-module-ids.ts +1 -0
  195. package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-pool.test.ts +126 -20
  196. package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-pool.ts +24 -3
  197. package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-worker.ts +59 -46
  198. package/src/runtime/clawclaw/plugins/perception/perception-module-loader.ts +27 -5
  199. package/src/runtime/clawclaw/plugins/perception/perception-plugin.test.ts +381 -49
  200. package/src/runtime/clawclaw/plugins/perception/perception-plugin.ts +267 -245
  201. package/src/runtime/clawclaw/plugins/perception/perception-source.test.ts +98 -0
  202. package/src/runtime/clawclaw/plugins/perception/perception-source.ts +89 -16
  203. package/src/runtime/clawclaw/plugins/perception/perception-test-fixtures.ts +34 -0
  204. package/src/runtime/clawclaw/plugins/perception/replay.test.ts +27 -15
  205. package/src/runtime/clawclaw/plugins/perception/replay.ts +10 -5
  206. package/src/runtime/clawclaw/plugins/perception/shared/math.ts +1 -107
  207. package/src/runtime/clawclaw/plugins/perception/spatial-facts.ts +7 -10
  208. package/src/runtime/clawclaw/plugins/plugin-api-version.ts +112 -0
  209. package/src/runtime/clawclaw/plugins/runtime-plugins.test.ts +389 -559
  210. package/src/runtime/clawclaw/plugins/source/player-change-tracker.test.ts +56 -5
  211. package/src/runtime/clawclaw/plugins/source/player-change-tracker.ts +135 -26
  212. package/src/runtime/clawclaw/plugins/source/source-plugin.test.ts +249 -16
  213. package/src/runtime/clawclaw/plugins/source/source-plugin.ts +99 -2
  214. package/src/runtime/clawclaw/plugins/source/task-change-tracker.test.ts +212 -0
  215. package/src/runtime/clawclaw/plugins/source/task-change-tracker.ts +259 -0
  216. package/src/runtime/clawclaw/plugins/trigger/contracts.ts +97 -0
  217. package/src/runtime/clawclaw/plugins/trigger/index.ts +4 -0
  218. package/src/runtime/clawclaw/plugins/trigger/trigger-module-loader.ts +118 -0
  219. package/src/runtime/clawclaw/plugins/trigger/trigger-plugin.test.ts +548 -0
  220. package/src/runtime/clawclaw/plugins/trigger/trigger-plugin.ts +655 -0
  221. package/src/runtime/clawclaw/plugins/trigger/trigger-source.test.ts +169 -0
  222. package/src/runtime/clawclaw/plugins/trigger/trigger-source.ts +457 -0
  223. package/src/runtime/clawclaw/runtime.ts +8 -0
  224. package/src/runtime/clawclaw/spatial-api.ts +76 -0
  225. package/src/runtime/clawclaw-event-catalog.test.ts +46 -1
  226. package/src/runtime/clawclaw-event-catalog.ts +40 -3
  227. package/src/runtime/framework/capability-registry.test.ts +196 -55
  228. package/src/runtime/framework/capability-registry.ts +99 -17
  229. package/src/runtime/framework/contracts.ts +30 -4
  230. package/src/runtime/framework/control/control-scheduler.ts +13 -5
  231. package/src/runtime/framework/control/types.ts +11 -4
  232. package/src/runtime/framework/control-coordinator.test.ts +95 -80
  233. package/src/runtime/framework/events/event-delivery-service.ts +4 -2
  234. package/src/runtime/framework/events/event-ingress.test.ts +25 -0
  235. package/src/runtime/framework/events/event-ingress.ts +2 -1
  236. package/src/runtime/framework/events/event-repository.ts +24 -2
  237. package/src/runtime/framework/events/mailbox-event-repositories.test.ts +124 -8
  238. package/src/runtime/framework/events/memory-event-repository.ts +92 -28
  239. package/src/runtime/framework/events/sqlite-event-repository.test.ts +604 -2
  240. package/src/runtime/framework/events/sqlite-event-repository.ts +531 -21
  241. package/src/runtime/framework/events/types.ts +24 -8
  242. package/src/runtime/framework/modules/runtime-module-loader-hooks.mjs +38 -1
  243. package/src/runtime/framework/modules/runtime-module-loader.test.ts +233 -7
  244. package/src/runtime/framework/modules/runtime-module-loader.ts +69 -4
  245. package/src/runtime/framework/plugins/contracts.ts +12 -18
  246. package/src/runtime/framework/plugins/runtime-plugin-scheduler.test.ts +81 -71
  247. package/src/runtime/framework/plugins/runtime-plugin-scheduler.ts +38 -20
  248. package/src/runtime/framework/runtime.ts +20 -23
  249. package/src/runtime/host-monitor-rate-gate.test.ts +73 -0
  250. package/src/runtime/host-monitor-rate-gate.ts +123 -0
  251. package/src/runtime/mailbox-host-relay.test.ts +45 -0
  252. package/src/runtime/mailbox-host-relay.ts +25 -0
  253. package/src/runtime/observability/factory.ts +4 -4
  254. package/src/runtime/observability/observability.test.ts +25 -3
  255. package/src/runtime/observability/reporter.ts +1 -1
  256. package/src/runtime/observability/types.ts +2 -2
  257. package/src/runtime/owner-control.ts +10 -2
  258. package/src/runtime/runtime-logger.test.ts +1 -1
  259. package/src/runtime/runtime-logger.ts +4 -6
  260. package/src/runtime/runtime.test.ts +88 -22
  261. package/src/sdk/action.ts +2 -2
  262. package/src/sdk/behavior-plugin/index.test.ts +74 -0
  263. package/src/sdk/behavior-plugin/index.ts +335 -0
  264. package/src/sdk/behavior-toolkit/corpse-search.ts +87 -0
  265. package/src/sdk/behavior-toolkit/escape.ts +40 -0
  266. package/src/sdk/behavior-toolkit/index.ts +7 -0
  267. package/src/sdk/behavior-toolkit/kill-flow.ts +299 -0
  268. package/src/sdk/behavior-toolkit/model.ts +263 -0
  269. package/src/sdk/behavior-toolkit/move-gate.ts +52 -0
  270. package/src/sdk/behavior-toolkit/patrol.ts +53 -0
  271. package/src/sdk/behavior-toolkit/search.ts +102 -0
  272. package/src/sdk/index.test.ts +45 -0
  273. package/src/sdk/index.ts +67 -73
  274. package/src/sdk/module-input/index.test.ts +49 -0
  275. package/src/sdk/module-input/index.ts +229 -0
  276. package/src/sdk/perception-plugin/index.test.ts +2 -2
  277. package/src/sdk/perception-plugin/index.ts +51 -142
  278. package/src/sdk/perception-plugin/math.ts +107 -0
  279. package/src/sdk/trigger-plugin/index.test.ts +41 -0
  280. package/src/sdk/trigger-plugin/index.ts +128 -0
  281. package/src/strategies/avoid-lone.ts +21 -10
  282. package/src/strategies/avoid-players.ts +26 -16
  283. package/src/strategies/corpse-patrol.ts +25 -14
  284. package/src/strategies/crab-sabotage.ts +20 -9
  285. package/src/strategies/find-player.ts +33 -21
  286. package/src/strategies/game-utils.ts +1 -1
  287. package/src/strategies/goals/crab-sabotage-top.test.ts +145 -0
  288. package/src/strategies/goals/crab-sabotage-top.ts +32 -69
  289. package/src/strategies/hide.ts +25 -15
  290. package/src/strategies/kill-frenzy.ts +21 -10
  291. package/src/strategies/kill-lone.ts +27 -17
  292. package/src/strategies/kill-target.ts +33 -22
  293. package/src/strategies/lone-kill-task.ts +20 -9
  294. package/src/strategies/move-room.ts +29 -18
  295. package/src/strategies/official-long-behavior.test.ts +89 -0
  296. package/src/strategies/paradise-fish.ts +29 -18
  297. package/src/strategies/pathfind/astar-path.test.ts +127 -2
  298. package/src/strategies/pathfind/astar-path.ts +136 -26
  299. package/src/strategies/patrol.ts +21 -10
  300. package/src/strategies/player-targets.test.ts +10 -0
  301. package/src/strategies/player-targets.ts +13 -0
  302. package/src/strategies/report-patrol.ts +21 -10
  303. package/src/strategies/shrimp-memory.ts +30 -19
  304. package/src/strategies/social-task.ts +34 -23
  305. package/src/strategies/task-kill-report.ts +33 -22
  306. package/src/strategies/task-only.test.ts +99 -85
  307. package/src/strategies/task-only.ts +23 -12
  308. package/src/strategies/task-report.ts +25 -14
  309. package/src/strategies/types.ts +8 -8
  310. package/src/strategies/warrior-memory.ts +29 -19
  311. package/docs/runtime/strategy-runtime.md +0 -111
  312. package/docs//350/207/252/345/256/232/344/271/211/346/204/237/347/237/245.md +0 -502
  313. package/docs//350/207/252/345/256/232/344/271/211/347/255/226/347/225/245.md +0 -395
  314. package/skills/clawclaw/references/STRATEGIES.md +0 -76
  315. package/src/commands/strategy.test.ts +0 -209
  316. package/src/commands/strategy.ts +0 -242
  317. package/src/lib/strategy-export.test.ts +0 -406
  318. package/src/lib/strategy-export.ts +0 -381
  319. package/src/runtime/clawclaw/plugins/perception/official-modules.ts +0 -31
  320. package/src/runtime/clawclaw/plugins/strategy/examples/task-only-strategy.test.ts +0 -177
  321. package/src/runtime/clawclaw/plugins/strategy/examples/task-only-strategy.ts +0 -191
  322. package/src/runtime/clawclaw/plugins/strategy/index.ts +0 -8
  323. package/src/runtime/clawclaw/plugins/strategy/local-strategy-executor.ts +0 -412
  324. package/src/runtime/clawclaw/plugins/strategy/strategy-action.ts +0 -80
  325. package/src/runtime/clawclaw/plugins/strategy/strategy-analysis-thread-host.ts +0 -183
  326. package/src/runtime/clawclaw/plugins/strategy/strategy-executor-types.ts +0 -29
  327. package/src/runtime/clawclaw/plugins/strategy/strategy-executor.test.ts +0 -693
  328. package/src/runtime/clawclaw/plugins/strategy/strategy-game-api.ts +0 -57
  329. package/src/runtime/clawclaw/plugins/strategy/strategy-module-loader.ts +0 -168
  330. package/src/runtime/clawclaw/plugins/strategy/strategy-plugin.test.ts +0 -1994
  331. package/src/runtime/clawclaw/plugins/strategy/strategy-plugin.ts +0 -1579
  332. package/src/runtime/clawclaw/plugins/strategy/strategy-source.test.ts +0 -153
  333. package/src/runtime/clawclaw/plugins/strategy/strategy-source.ts +0 -443
  334. package/src/sdk/strategy-plugin/index.test.ts +0 -958
  335. package/src/sdk/strategy-plugin/index.ts +0 -1350
@@ -2,11 +2,11 @@
2
2
 
3
3
  ## 1. 一条长流、一种 Monitor 输出
4
4
 
5
- `ccl start match`、`ccl start room`、`ccl start training`、`ccl join` 和 `ccl join room` 都会启动当前参与的唯一前台 Runtime 长进程。它在同一个进程生命周期中持有后端连接、事件、策略和通知输出。不要为同一账号重复启动,也不要用轮询代替它。
5
+ `ccl start match`、`ccl start room`、`ccl start training`、`ccl join` 和 `ccl join room` 都会启动当前参与的唯一前台 Runtime 长进程。它在同一个进程生命周期中持有后端连接、事件、Behavior 控制栈和通知输出。不要为同一账号重复启动,也不要用轮询代替它。
6
6
 
7
- 收到第一条非 error 的 CCL NDJSON 通知且持久 Monitor 任务仍在运行后,当前 Monitor 即为健康通知流。后续新事件会自动从同一个 Monitor 推送并唤醒 Agent;等待下一事件时不要再次调用 Monitor,也不要再次运行任何匹配/房间长流启动命令或加 `--force`。只有当前 Monitor 已明确结束或失败时才启动恢复流程。
7
+ 收到第一条非 error 的 CCL NDJSON 通知且持久 Monitor 任务仍在运行后,当前 Monitor 即为健康通知流。后续主动通知和有界 backlog 唤醒都来自同一个 Monitor;普通事件受 60 秒滚动窗口约束,余量仍持久留给裸 `ccl events`,不是长流失效。等待下一次唤醒时不要再次调用 Monitor,也不要再次运行任何匹配/房间长流启动命令或加 `--force`。只有当前 Monitor 已明确结束或失败时才启动恢复流程。
8
8
 
9
- Monitor 每条 stdout 通知最多 500 个字符,使用 `events:string[]`、`messages:string[]`、紧凑 `state` 和可选 `game_mode`。每条 message 是事实摘要;对应 Event 有 CCL-owned `hint` 时,再原样追加同一份 hint。通知没有批次 `next_step` 或 `guidance`。收到真实通知后运行一次 `ccl events` 读取完整事件与当前 State。
9
+ Monitor 每条 stdout 通知最多 500 个字符,使用 `events:string[]`、`messages:string[]`、可选 `details_required:string[]` / `game_mode` / `backlog` / `guidance` / `truncated`,不重复投影批次级 `state` 或 `self`。每条 message 是可直接决策的事实;对应 Event 有 CCL-owned `hint` 时,再原样追加同一份 hint。多个短 Event 先拆成完整通知。普通主动输出有两个互不替代的边界:pending/claimed 容量限制瞬时积压,60 秒滚动窗口限制持续输出;任一窗口最多 12 个普通直推项目,余量转给裸 `ccl events` 的 durable consumer,并最多用 4 个额外 ordinary-only 提示唤醒 backlog。高频移动/路线/空间 visual 每 5 秒只主动保留最新一条,关键 visual 转折不受这条限频。击杀、死亡、有效目击、Behavior 终态(`behavior.completed` / `failed` / `cancelled` / `replaced`)和关键会议等 priority ≥80 的 Event,以及 `game_over` / `exile_game_over`,始终由 Monitor 直达且可顺带携带当前 backlog,不消耗普通预算。通知没有 `details_required`、`backlog` 或 `truncated:true` 时直接处理;每次出现任一标记时运行一次裸 `ccl events`。
10
10
 
11
11
  Monitor 只负责“有事发生时唤醒 Agent”。内部 heartbeat、PID、HTTP 审计和诊断日志不会作为游戏通知推给 Agent。
12
12
 
@@ -18,27 +18,31 @@ Monitor 字段如下:
18
18
  | --- | --- |
19
19
  | `events` | 事件名字符串数组 |
20
20
  | `messages` | 与 `events[]` 对齐的事实摘要;对应 Event 有 hint 时,以 `Hint: <同一 hint>` 追加,不维护第二套动作建议 |
21
- | `state` | 紧凑状态文本 |
21
+ | `details_required` | 这些 Event 需要用一次裸 `ccl events` 取得完整对象;未出现表示本批短事实已经完整 |
22
22
  | `game_mode` | 可选的匹配、竞赛或房间模式 |
23
+ | `backlog` | 当前 unread backlog 的合并提示;含 durable 余量 `remaining_events`、本次 Ready View 水位 `through_event_commit_seq` 和固定 `command:"ccl events"`。排干后新 backlog 可在滚动 hint 窗口有额度时再次提示;高优直推也可顺带携带 |
24
+ | `guidance` | 有 backlog 时提示运行裸 `ccl events`;同条含 `speech_your_turn` 时仍先发言 |
25
+ | `truncated` | 单个异常 Event 连短投影也放不下,或存在 Monitor backlog 时为 `true`;按 `ccl events` 路径处理 |
23
26
 
24
27
  常见 canonical 生命周期事件包括:
25
28
 
26
29
  - `joined`:新加入匹配;完整 Event 中的 `url` 是后端观战链接。
27
30
  - `room_created` / `room_joined`:已创建或加入好友房;完整 Event 提供房间码及后端可用的观战链接。
28
- - `room.member_joined` / `room.member_left` / `room.member_status_changed` / `room.owner_changed` / `room.full`:房间成员、在线状态、房主或人数发生变化;这些事件都会唤醒 Agent,随后用 `ccl events` 读取当前 `state.room.members`。
31
+ - `room.member_joined` / `room.member_left` / `room.member_status_changed` / `room.owner_changed` / `room.full`:房间成员、在线状态、房主或人数发生变化;从 Monitor message 或其提示后的一次裸 `ccl events` 处理本次变化。
29
32
  - `room_ready_to_start`:当前房间已满足开局条件;只有房主按用户意图运行一次 `ccl game start-room`。
30
33
  - `room.game_started`:现有房间 Runtime 自动切换到本局 GameSync,不另起 `start` 或 `join`。
31
- - `session_resumed`:重新接上后端已有匹配或对局。
34
+ - `session_resumed`:重新接上后端已有匹配或对局;同批 `joined` / `room_joined` 详情带完整 `url` 时直接分享,没有时才用 `ccl game watch` 的本地兜底链接。
32
35
  - `match_start`:匹配长流已连接。
33
36
  - `match_waiting`:仍在队列。
34
- - `match_timeout`、`not_in_queue`、`game_start_failed`:本次流即将或已经结束;读取对应完整 Event 的事实和可选 `hint`。
37
+ - `match_timeout`、`not_in_queue`、`game_start_failed`:本次流即将或已经结束;直接处理 Monitor 事实和可选 `hint`,只有通知要求详情时才查询。
35
38
  - `game_stream_disconnected` / `game_stream_reconnected`:同一逻辑对局内的物理 WS 断线与重连;不会因此开启新事件段。
36
39
  - `quit_requested`:runtime 已收到退出请求;停止发游戏动作,并等待 `session_left`、`quit_failed` 或长流结束确认结果。
37
40
  - `session_left`:当前后端参与已结束,前台运行时即将结束。
38
41
  - `user_left_game`:用户从网页退出当前对局;普通匹配结束长流,房间模式尝试回到 lobby,不自动开下一局。
39
42
  - `game_over`:本局结束;普通匹配 runtime 自动退出,房间模式回到 lobby。
43
+ - `behavior.completed` / `behavior.failed` / `behavior.cancelled` / `behavior.replaced`:一个 Activation 的终态;用 `activation_id`、`behavior`、`layer`、`reason` 和可选 `replaced_by_activation_id` 判断结果。`behavior.suspended` / `behavior.restarted` 只是抢占与 fresh restart,不是终态。
40
44
 
41
- 生命周期和游戏事件走同一个 Event Repository、Monitor 和 `ccl events` 交付流程。Canonical Event Ledger 只存事实;Mailbox 按来源和 type 为登记过的 backend 或 CCL lifecycle/derived Event 增加可选英文模板 `hint`。未登记就没有 `hint`,Strategy/Robot 和 Perception/Visual Event 不由这张表补 hint。Event 输出没有 `notice`,也没有批次 `next_step` 或 gameplay `guidance`。
45
+ 生命周期和游戏事件走同一个 Event Repository,再由各 Mailbox Adapter 独立选择和确认。Monitor 与 Channels 接收 Agent 可见实时事实;裸 `ccl events` 的未读批次选择需要完整对象的 Event,也选择 Monitor 因瞬时队列压力、滚动窗口或高频 visual 限频而委托的 durable 普通/visual Event。Monitor 已完整发送的普通短 Event 不会在该批次中再次返回。Canonical Event Ledger 仍保留全部事实,`ccl events <事件名>` 也仍可按类型复查最新一条。Mailbox 按来源和 type 为登记过的 backend 或 CCL lifecycle/derived Event 增加可选英文模板 `hint`。未登记就没有 `hint`,普通 Behavior 自定义输出和 Perception/Visual Event 不由这张表补 hint。Event 输出没有 `notice`,也没有批次 `next_step` 或 gameplay `guidance`;Monitor backlog 通知自带的 `guidance` 是该 Adapter 的有界委托提示。
42
46
 
43
47
  ## 3. `ccl events` v5
44
48
 
@@ -48,7 +52,7 @@ ccl events --backlog
48
52
  ccl events <事件名>
49
53
  ```
50
54
 
51
- 裸 `ccl events` 固定一次 Ready View,返回当前 participation session 截至该水位的全部未读 Event。成功写完 stdout 后,这些 Event 才记为已交付,下一次裸调用不会重复返回。当前不分页;`--backlog` 只是跳过新的 Source 查询边界,直接读取已经 ready 的全部未读 Event。
55
+ 裸 `ccl events` 固定一次 Ready View,返回当前 participation session 截至该水位的全部未读详情 Event,以及 Monitor 因瞬时队列压力、滚动窗口或高频 visual 限频而委托的 durable 普通/visual Event。成功写完 stdout 后,本批 Event 才记为已交付,下一次裸调用不会重复返回;排干不会提前归还滚动窗口额度,时间滑出 60 秒后额度自然恢复。Monitor 已完整发送的普通短 Event 不进入这个批次;它们仍保留在 Canonical Event Ledger。当前不分页;`--backlog` 只是跳过新的 Source 查询边界,直接读取已经 ready 的未读详情和委托余量。
52
56
 
53
57
  逻辑事件段是 queue、game 或 room-lobby 等前台阶段。普通 WS 断线重连仍属于原段;房间内新一轮 game 才会切段。
54
58
 
@@ -58,7 +62,7 @@ ccl events <事件名>
58
62
  | --- | --- |
59
63
  | `schema` | `ccl.events.v5`;普通 Agent 查询不会静默退回旧 cursor 协议 |
60
64
  | `state` | 当前最新 Agent State;字段始终存在,但可能为 `null`。游戏中 `state.you.tasks` 是查询边界读取的当前权威任务列表,`state.players` 是本局完整姓名/座位与当前视角已知状态,蟹方另有阵营共享的 `state.crab_sabotage` |
61
- | `events[]` | Agent 事实投影;含 `type`、可选 `tick`、类型详情,以及命中 Registry 时才存在的可选 `hint`。稳定 Event ID 与发生/接收时间只供 Ledger/Mailbox 内部去重、排序和确认,不进入 Monitor 或 `ccl events` 输出 |
65
+ | `events[]` | 本批未读详情或 Monitor 委托短事实的 Agent 投影;含 `type`、可选 `tick`、类型详情,以及命中 Registry 时才存在的可选 `hint`。稳定 Event ID 与发生/接收时间只供 Ledger/Mailbox 内部去重、排序和确认,不进入 Monitor 或 `ccl events` 输出 |
62
66
 
63
67
  即使 `events=[]`,`state` 仍会返回。scope、水位、未读计数、租约、cursor 和 stdout ack 都由 Mailbox 内部处理,不重复塞进 Agent 输出。`--backlog` 随附的 State 也是“调用此刻的最新 State”,不是历史事件发生时的旧 State。
64
68
 
@@ -71,7 +75,7 @@ ccl events <事件名>
71
75
  | `known_status.death_cause` | 已公开死因:`killed` 为被击杀,`exiled` 为会议放逐 |
72
76
  | `known_status.reported_in_current_meeting` | 会议中为 `true` 表示此人是触发本次会议的被报告尸体;`false` 表示已知死亡但不是本次被报告尸体;缺失表示后端没有公开该判断 |
73
77
 
74
- Source 在这些已知事实变化时仍生成 `players_changed`:Monitor 使用一句短摘要,`ccl events` 详情保留本批 `changes[]`。State 是当前权威视图,Agent 不从历史 `players_changed` 拼当前名单。当前视野仍独立读取 `state.visible_players` / `state.nearby_corpses`。
78
+ Source 在这些已知事实变化时生成 `players_changed`:Monitor 使用一句短摘要并列入 `details_required`,`ccl events` 详情给出本批 `changes[]` 和变化后的完整 `players[]`,整体替换此前玩家表。当前画面以持续收到的 visual Event 为准。
75
79
 
76
80
  蟹方的 `state.crab_sabotage` 是阵营共享装填的当前权威状态:
77
81
 
@@ -85,9 +89,9 @@ Source 在这些已知事实变化时仍生成 `players_changed`:Monitor 使
85
89
 
86
90
  不要根据当前蟹自己是否完成过破坏任务推断装填;另一只蟹的完成或消耗也会改变该共享状态。
87
91
 
88
- 任务分配不作为 `task_assigned` Event 交付;当前任务统一从 GameSync 提供的权威 `state.you.tasks` 读取。Agent 和策略不自行发 HTTP,也不从历史事件拼当前任务列表。
92
+ 任务分配不作为独立 `task_assigned` Event 交付;`role_assigned`、自己的 `task_completed` / `task_sabotaged` 或 `tasks_changed` 详情会给出变化后的完整 `tasks[]` 与 `delta[]`,整体替换此前任务表。Agent 和 Behavior 不自行发 HTTP,也不从零散历史事件拼当前任务列表。
89
93
 
90
- `ccl events --backlog` 不新建查询边界,只读取调用时已经 ready 的未读内容。旧 participation session 不补发。
94
+ `ccl events --backlog` 不新建查询边界,只读取调用时已经 ready 的未读详情和 Monitor 委托余量。旧 participation session 不补发。
91
95
 
92
96
  `ccl events <事件名>` 返回当前 participation 中该类型最新一条 Agent 可见事件,不改变它的交付状态。开局复查常用:
93
97
 
@@ -99,7 +103,7 @@ ccl events
99
103
 
100
104
  ## 4. 退出与崩溃恢复
101
105
 
102
- 正常退出参与时使用 `ccl game quit`,不要用宿主任务强杀代替后端退出。读取命令的结构化结果,并结合长流后续的 `session_left`、`quit_failed` 或结束状态确认结果。停止或结束承载长流的宿主任务会同时停止本地 runtime、连接和策略,但不等于后端已经接受退出。房间对局返回 `game_returned_room` 时只退出当前一轮,runtime 会继续回到 room lobby;在 `in_room` 再次 quit 才离开房间。`STILL_ALIVE` 时 `ok: false` 指后端拒绝退出;`runtime_stop_requested` / `local_runtime` 另行说明本地 runtime 是否已接到停止请求,而 `backend_participation: "active_game"` 明确表示服务器里的玩家仍在本局。`ALLOCATION_IN_PROGRESS` 表示远端未退出且 runtime 保持运行。
106
+ 正常退出参与时使用 `ccl game quit`,不要用宿主任务强杀代替后端退出。读取命令的结构化结果,并结合长流后续的 `session_left`、`quit_failed` 或结束状态确认结果。停止或结束承载长流的宿主任务会同时停止本地 runtime、连接和 Behavior,但不等于后端已经接受退出。房间对局返回 `game_returned_room` 时只退出当前一轮,runtime 会继续回到 room lobby;在 `in_room` 再次 quit 才离开房间。`STILL_ALIVE` 时 `ok: false` 指后端拒绝退出;`runtime_stop_requested` / `local_runtime` 另行说明本地 runtime 是否已接到停止请求,而 `backend_participation: "active_game"` 明确表示服务器里的玩家仍在本局。`ALLOCATION_IN_PROGRESS` 表示远端未退出且 runtime 保持运行。
103
107
 
104
108
  只有当前 Monitor 已明确结束或失败时才使用本节:后端已有参与时,在新的 persistent Monitor 中运行 `ccl join`。新进程会创建新的本地运行时会话,再向后端确认并恢复 queue、game 或 room;它不会附着到旧进程,也不会恢复旧本地会话中遗漏的实时事件。若旧 Runtime 仍存活,`ccl join` 会被拒绝并返回其 PID。这个 PID 只证明 Owner 存活;不要附着或复用旧 Owner,改用 `ccl join --force` 挤掉旧 Runtime 后重新拉起。只使用 CCL 的 `--force`,不要自行运行 `kill` / `taskkill`;它会先请求旧 Runtime 正常停止,必要时终止旧进程树,确认退出后再启动新进程。`--force` 不退出后端参与,新进程仍可能恢复原 queue、game 或 room:
105
109
 
@@ -46,7 +46,7 @@
46
46
 
47
47
  ## 报尸先查附近
48
48
 
49
- 发现尸体后报尸前,先用 `ccl events` 查谁在尸体附近出现过,第一轮发言直接点名指认:
49
+ 发现尸体后报尸前,先从已收到的视觉 Events 判断谁在尸体附近出现过,第一轮发言直接点名指认:
50
50
 
51
51
  - **查到就一定要说**,不说=包庇=显得你是凶手
52
52
  - **离尸体最近的人没报尸=铁证**:正常虾看到尸体必报,不报的只能是杀手或天堂鱼
@@ -56,7 +56,7 @@
56
56
 
57
57
  目击凶案时,**先报尸再发言**,顺序错了就会变成"目击不报尸"的嫌疑人:
58
58
 
59
- 1. 走到尸体旁边让策略自动**报尸**触发会议(wander speech 不算正式报尸)
59
+ 1. 从本局玩家表查到尸体所属座位,立即启动 short Behavior,例如 3 号尸体用 `ccl behavior start report_corpse --layer short --input '{"corpse_seat":3,"timeout_ms":45000}'`,让它到场复核并尝试**报尸**;`corpse_seat` 只传 1-10 的 JSON 数字,不传玩家名或字符串。启动返回 `accepted` 不表示已报告;只有后续 `behavior.completed` 加权威会议 Event 才证明报告成功(wander speech 不算正式报尸)
60
60
  2. 会议中 **斩钉截铁+完整逻辑链** 指认凶手
61
61
  3. 例:"我亲眼看见X号在Y房间杀了Z。当时我正好在隔壁做任务,听到动静过去一看——X号正对Z动手。X号在之前的发言里说自己没去过Y房间?那他为什么会在现场?"
62
62
 
@@ -0,0 +1,141 @@
1
+ import {
2
+ ClawclawBehavior,
3
+ type BehaviorInput,
4
+ type BehaviorNormalizationApi,
5
+ type BehaviorReadApi,
6
+ type ClawclawBehaviorManifest,
7
+ } from '../../sdk/behavior-plugin/index.js';
8
+ import {
9
+ behaviorEventMentionsTarget,
10
+ behaviorSelf,
11
+ behaviorTaskAvailable,
12
+ behaviorTasks,
13
+ normalizedBehaviorLabel,
14
+ SemanticMoveGate,
15
+ type BehaviorTaskPoint,
16
+ } from '../../sdk/behavior-toolkit/index.js';
17
+ import { finished, running } from './shared.js';
18
+
19
+ type TaskSelector = 'nearest' | 'any';
20
+ type DoTaskInput = Readonly<Record<string, unknown>> & {
21
+ readonly task?: string;
22
+ readonly selector?: TaskSelector;
23
+ readonly timeout_ms?: number;
24
+ };
25
+
26
+ export default class DoTaskBehavior extends ClawclawBehavior<DoTaskInput> {
27
+ static override readonly manifest = {
28
+ apiVersion: 3,
29
+ id: 'do_task',
30
+ name: 'Do Task',
31
+ description: 'Navigate to and submit one currently available task.',
32
+ localizations: { 'zh-CN': { name: '执行任务', description: '前往并提交一个当前可用任务。' } },
33
+ inputs: [
34
+ { id: 'task', type: 'string', description: 'Exact task id or name. Mutually exclusive with selector.' },
35
+ { id: 'selector', type: 'enum', description: 'Task selector. Mutually exclusive with task.', values: ['nearest', 'any'] },
36
+ ],
37
+ execution: 'serial',
38
+ runtime: { defaultMs: 60_000, deadlineOutcome: 'failed' },
39
+ } as const satisfies ClawclawBehaviorManifest;
40
+
41
+ private readonly move = new SemanticMoveGate();
42
+ private selectedTaskId?: string;
43
+ private selectedTaskName?: string;
44
+ private submittedAtMs?: number;
45
+
46
+ override normalize(input: Readonly<Record<string, unknown>>, api: BehaviorNormalizationApi): DoTaskInput {
47
+ const task = api.optionalString(input.task, 'task');
48
+ const selector = input.selector === undefined
49
+ ? undefined
50
+ : api.choice(input.selector, 'task_selection', ['nearest', 'any'] as const);
51
+ if (!!task === !!selector) throw new Error('behavior_task_selection_invalid');
52
+ return { ...api.timing(input), ...(task ? { task } : { selector }) };
53
+ }
54
+
55
+ override async decide(input: Readonly<BehaviorInput<DoTaskInput>>, api: BehaviorReadApi) {
56
+ if (this.submittedAtMs !== undefined && this.selectedTaskName) {
57
+ const selected = behaviorTasks(input).find((task) => (
58
+ (this.selectedTaskId && task.id === this.selectedTaskId)
59
+ || task.name === this.selectedTaskName
60
+ ));
61
+ if (
62
+ selected?.status === 'completed'
63
+ || behaviorEventMentionsTarget(input.events, ['task_completed'], this.selectedTaskName)
64
+ ) return finished('completed', 'task_completed', `任务“${this.selectedTaskName}”已完成。`);
65
+ if (!selected && input.nowMs - this.submittedAtMs > 1_000) {
66
+ return finished('failed', 'task_unavailable', `任务“${this.selectedTaskName}”不再可用。`);
67
+ }
68
+ return running(`等待任务“${this.selectedTaskName}”的权威完成状态;不会重复提交。`, 'doing_task', [], { task: this.selectedTaskName });
69
+ }
70
+
71
+ const selected = await this.selectTask(input, api);
72
+ if (!selected) {
73
+ return finished('failed', 'task_unavailable', input.input.task
74
+ ? `任务“${input.input.task}”已经不可执行。`
75
+ : '当前没有符合选择条件的可执行任务。');
76
+ }
77
+ if (selected.distance > 12) {
78
+ const summary = `正在前往${selected.task.room ?? '任务点'}执行“${selected.task.name}”。`;
79
+ const action = this.move.propose(input, selected.task, false, summary);
80
+ return running(summary, 'moving', action ? [action] : [], {
81
+ task: selected.task.name,
82
+ ...(selected.task.room ? { room: selected.task.room } : {}),
83
+ });
84
+ }
85
+ this.selectedTaskId = selected.task.id;
86
+ this.selectedTaskName = selected.task.name;
87
+ this.submittedAtMs = input.nowMs;
88
+ const summary = `正在提交任务“${selected.task.name}”并等待权威结果。`;
89
+ return running(summary, 'doing_task', [{ action: 'task', task_name: selected.task.name, thinking_content: summary }], { task: selected.task.name });
90
+ }
91
+
92
+ private async selectTask(
93
+ input: Readonly<BehaviorInput<DoTaskInput>>,
94
+ api: BehaviorReadApi,
95
+ ): Promise<{ task: BehaviorTaskPoint; distance: number } | undefined> {
96
+ const tasks = behaviorTasks(input);
97
+ if (this.selectedTaskName) {
98
+ const existing = tasks.find((task) => (
99
+ (this.selectedTaskId && task.id === this.selectedTaskId)
100
+ || task.name === this.selectedTaskName
101
+ ));
102
+ if (existing && behaviorTaskAvailable(existing)) {
103
+ const distance = await this.distance(input, api, existing);
104
+ return distance === null ? undefined : { task: existing, distance };
105
+ }
106
+ if (input.input.task) return undefined;
107
+ this.selectedTaskId = undefined;
108
+ this.selectedTaskName = undefined;
109
+ }
110
+ const candidates = tasks.filter(behaviorTaskAvailable);
111
+ const exact = input.input.task
112
+ ? candidates.find((task) => (
113
+ normalizedBehaviorLabel(task.name) === normalizedBehaviorLabel(input.input.task!)
114
+ || (!!task.id && normalizedBehaviorLabel(task.id) === normalizedBehaviorLabel(input.input.task!))
115
+ ))
116
+ : undefined;
117
+ if (input.input.task && !exact) return undefined;
118
+ const considered = exact ? [exact] : candidates;
119
+ const self = behaviorSelf(input);
120
+ if (!self || considered.length === 0) return undefined;
121
+ const distances = await api.navigation.pathDistances(considered.map((to) => ({ from: self, to })));
122
+ const reachable = considered
123
+ .map((task, index) => ({ task, distance: distances[index] }))
124
+ .filter((entry): entry is { task: BehaviorTaskPoint; distance: number } => entry.distance !== null)
125
+ .sort((left, right) => left.distance - right.distance);
126
+ const selected = reachable[0];
127
+ if (!selected) return undefined;
128
+ this.selectedTaskId = selected.task.id;
129
+ this.selectedTaskName = selected.task.name;
130
+ return selected;
131
+ }
132
+
133
+ private async distance(
134
+ input: Readonly<BehaviorInput>,
135
+ api: BehaviorReadApi,
136
+ task: Readonly<BehaviorTaskPoint>,
137
+ ): Promise<number | null> {
138
+ const self = behaviorSelf(input);
139
+ return self ? api.navigation.pathDistance(self, task) : null;
140
+ }
141
+ }
@@ -0,0 +1,78 @@
1
+ import {
2
+ ClawclawBehavior,
3
+ type BehaviorInput,
4
+ type BehaviorNormalizationApi,
5
+ type BehaviorReadApi,
6
+ type ClawclawBehaviorManifest,
7
+ type Position,
8
+ } from '../../sdk/behavior-plugin/index.js';
9
+ import {
10
+ behaviorDistance,
11
+ behaviorSelf,
12
+ behaviorTeammateSeats,
13
+ behaviorVisiblePlayers,
14
+ planBehaviorEscape,
15
+ SemanticMoveGate,
16
+ } from '../../sdk/behavior-toolkit/index.js';
17
+ import { finished, running } from './shared.js';
18
+
19
+ type EvadeInput = Readonly<Record<string, unknown>> & {
20
+ readonly player_seats?: readonly number[];
21
+ readonly duration_ms?: number;
22
+ };
23
+
24
+ export default class EvadeBehavior extends ClawclawBehavior<EvadeInput> {
25
+ static override readonly manifest = {
26
+ apiVersion: 3,
27
+ id: 'evade',
28
+ name: 'Evade',
29
+ description: 'Keep distance from selected or nearby threats for a bounded duration.',
30
+ localizations: { 'zh-CN': { name: '躲避', description: '在有限时长内远离指定或附近威胁。' } },
31
+ inputs: [{ id: 'player_seats', type: 'player_seats', description: 'Optional authoritative player seats to evade (1-10).', maxItems: 8 }],
32
+ execution: 'serial',
33
+ runtime: { defaultMs: 15_000, deadlineOutcome: 'completed' },
34
+ } as const satisfies ClawclawBehaviorManifest;
35
+
36
+ private readonly move = new SemanticMoveGate();
37
+ private escapeTarget?: Position;
38
+ private plannedAtMs = 0;
39
+
40
+ override normalize(input: Readonly<Record<string, unknown>>, api: BehaviorNormalizationApi): EvadeInput {
41
+ const seats = input.player_seats === undefined ? [] : input.player_seats as readonly number[];
42
+ return { ...api.timing(input), ...(seats.length ? { player_seats: seats } : {}) };
43
+ }
44
+
45
+ override decide(input: Readonly<BehaviorInput<EvadeInput>>, api: BehaviorReadApi) {
46
+ const self = behaviorSelf(input);
47
+ if (!self) return finished('failed', 'self_position_unavailable', '当前无法取得自身位置。');
48
+ const selected = input.input.player_seats ?? [];
49
+ const teammates = behaviorTeammateSeats(input);
50
+ let threats = behaviorVisiblePlayers(input).filter((player) => (
51
+ player.isAlive !== false
52
+ && (selected.length ? selected.includes(player.seat) : !teammates.has(player.seat))
53
+ ));
54
+ if (threats.length === 0 && selected.length) {
55
+ threats = selected.flatMap((seat) => {
56
+ const seen = api.observation.lastSeenPlayer(seat, 5_000);
57
+ return seen ? [{ ...seen, isAlive: seen.isAlive }] : [];
58
+ });
59
+ }
60
+ if (threats.length === 0) {
61
+ return finished('completed', 'threat_out_of_sight', selected.length
62
+ ? '已在有限时间内持续躲避,当前看不到指定玩家;这不代表威胁已经解除。'
63
+ : '当前没有可见威胁,本次有限躲避结束。');
64
+ }
65
+ if (!this.escapeTarget || behaviorDistance(self, this.escapeTarget) <= 70 || this.plannedAtMs + 1_600 <= input.nowMs) {
66
+ const plan = planBehaviorEscape(self, threats);
67
+ if (plan.caught && plan.survivedSteps === 0) return finished('failed', 'no_escape_route', '当前没有可确认的逃生路线。');
68
+ this.escapeTarget = plan.target;
69
+ this.plannedAtMs = input.nowMs;
70
+ }
71
+ const visibleSeats = new Set(behaviorVisiblePlayers(input).map((player) => player.seat));
72
+ const summary = threats.some((threat) => visibleSeats.has(threat.seat))
73
+ ? `正在远离${threats.map((threat) => threat.name).join('、')}。`
74
+ : '指定玩家暂时离开视野,正在根据最后目击位置继续有限拉开距离。';
75
+ const action = this.move.propose(input, this.escapeTarget, false, summary);
76
+ return running(summary, 'moving', action ? [action] : []);
77
+ }
78
+ }
@@ -0,0 +1,50 @@
1
+ import {
2
+ ClawclawBehavior,
3
+ type BehaviorInput,
4
+ type BehaviorNormalizationApi,
5
+ type BehaviorReadApi,
6
+ type ClawclawBehaviorManifest,
7
+ } from '../../sdk/behavior-plugin/index.js';
8
+ import {
9
+ FinitePlayerSearch,
10
+ SemanticMoveGate,
11
+ } from '../../sdk/behavior-toolkit/index.js';
12
+ import { finished, running } from './shared.js';
13
+
14
+ type FindPlayerInput = Readonly<Record<string, unknown>> & {
15
+ readonly player_seat: number;
16
+ readonly timeout_ms?: number;
17
+ };
18
+
19
+ export default class FindPlayerBehavior extends ClawclawBehavior<FindPlayerInput> {
20
+ static override readonly manifest = {
21
+ apiVersion: 3,
22
+ id: 'find_player',
23
+ name: 'Find Player',
24
+ description: 'Search a finite route for one known player.',
25
+ localizations: { 'zh-CN': { name: '寻找玩家', description: '沿有限路线寻找一名已知玩家。' } },
26
+ inputs: [{ id: 'player_seat', type: 'player_seat', description: 'Authoritative seat of the player to find (1-10).', required: true }],
27
+ execution: 'serial',
28
+ runtime: { defaultMs: 45_000, deadlineOutcome: 'failed' },
29
+ } as const satisfies ClawclawBehaviorManifest;
30
+
31
+ private readonly search = new FinitePlayerSearch();
32
+ private readonly move = new SemanticMoveGate();
33
+
34
+ override normalize(input: Readonly<Record<string, unknown>>, api: BehaviorNormalizationApi): FindPlayerInput {
35
+ return {
36
+ player_seat: api.number(input.player_seat, 'player_seat', { integer: true, min: 1, max: 10 }),
37
+ ...api.timing(input),
38
+ };
39
+ }
40
+
41
+ override async decide(input: Readonly<BehaviorInput<FindPlayerInput>>, api: BehaviorReadApi) {
42
+ const result = await this.search.step(input, api, input.input.player_seat);
43
+ if (result.kind === 'visible') {
44
+ return finished('completed', 'player_found', `已在${result.player.room ?? '当前区域'}看到${result.player.name}。`);
45
+ }
46
+ if (result.kind === 'failed') return finished('failed', result.reason, result.summary);
47
+ const action = this.move.propose(input, result.target, false, result.summary);
48
+ return running(result.summary, 'moving', action ? [action] : []);
49
+ }
50
+ }
@@ -0,0 +1,70 @@
1
+ import {
2
+ ClawclawBehavior,
3
+ type BehaviorInput,
4
+ type BehaviorNormalizationApi,
5
+ type BehaviorReadApi,
6
+ type ClawclawBehaviorManifest,
7
+ } from '../../sdk/behavior-plugin/index.js';
8
+ import {
9
+ behaviorDistance,
10
+ behaviorSelf,
11
+ FinitePlayerSearch,
12
+ SemanticMoveGate,
13
+ } from '../../sdk/behavior-toolkit/index.js';
14
+ import { finished, running } from './shared.js';
15
+
16
+ type FollowPlayerInput = Readonly<Record<string, unknown>> & {
17
+ readonly player_seat: number;
18
+ readonly distance: number;
19
+ readonly duration_ms?: number;
20
+ };
21
+
22
+ export default class FollowPlayerBehavior extends ClawclawBehavior<FollowPlayerInput> {
23
+ static override readonly manifest = {
24
+ apiVersion: 3,
25
+ id: 'follow_player',
26
+ name: 'Follow Player',
27
+ description: 'Follow one known player at a bounded distance.',
28
+ localizations: { 'zh-CN': { name: '跟随玩家', description: '在有限距离内跟随一名已知玩家。' } },
29
+ inputs: [
30
+ { id: 'player_seat', type: 'player_seat', description: 'Authoritative seat of the player to follow (1-10).', required: true },
31
+ { id: 'distance', type: 'number', description: 'Preferred following distance in pixels.', min: 20, max: 500, default: 90 },
32
+ ],
33
+ execution: 'serial',
34
+ runtime: { defaultMs: 30_000, deadlineOutcome: 'completed' },
35
+ } as const satisfies ClawclawBehaviorManifest;
36
+
37
+ private readonly search = new FinitePlayerSearch();
38
+ private readonly move = new SemanticMoveGate();
39
+
40
+ override normalize(input: Readonly<Record<string, unknown>>, api: BehaviorNormalizationApi): FollowPlayerInput {
41
+ return {
42
+ player_seat: api.number(input.player_seat, 'player_seat', { integer: true, min: 1, max: 10 }),
43
+ distance: api.number(input.distance, 'follow_distance', { min: 20, max: 500 }),
44
+ ...api.timing(input),
45
+ };
46
+ }
47
+
48
+ override async decide(input: Readonly<BehaviorInput<FollowPlayerInput>>, api: BehaviorReadApi) {
49
+ const result = await this.search.step(input, api, input.input.player_seat);
50
+ if (result.kind === 'failed') return finished('failed', result.reason, result.summary);
51
+ if (result.kind === 'move') {
52
+ const action = this.move.propose(input, result.target, false, result.summary);
53
+ return running(result.summary, 'moving', action ? [action] : []);
54
+ }
55
+ const self = behaviorSelf(input);
56
+ if (!self) return finished('failed', 'self_position_unavailable', '当前无法取得自身位置。');
57
+ const distance = behaviorDistance(self, result.player);
58
+ if (distance <= input.input.distance * 1.15) {
59
+ return running(`正在与${result.player.name}保持约${Math.round(distance)}距离。`, 'waiting', [], { targetPlayer: result.player.name });
60
+ }
61
+ const travel = Math.max(0, distance - input.input.distance);
62
+ const target = {
63
+ x: self.x + ((result.player.x - self.x) * travel) / distance,
64
+ y: self.y + ((result.player.y - self.y) * travel) / distance,
65
+ };
66
+ const summary = `正在跟随${result.player.name}并保持距离。`;
67
+ const action = this.move.propose(input, target, false, summary);
68
+ return running(summary, 'moving', action ? [action] : [], { targetPlayer: result.player.name });
69
+ }
70
+ }
@@ -0,0 +1,69 @@
1
+ import {
2
+ ClawclawBehavior,
3
+ type BehaviorInput,
4
+ type BehaviorNormalizationApi,
5
+ type BehaviorReadApi,
6
+ type ClawclawBehaviorManifest,
7
+ } from '../../sdk/behavior-plugin/index.js';
8
+ import {
9
+ behaviorSelf,
10
+ behaviorTasks,
11
+ findBehaviorRoom,
12
+ normalizedBehaviorLabel,
13
+ SemanticMoveGate,
14
+ } from '../../sdk/behavior-toolkit/index.js';
15
+ import { finished, running } from './shared.js';
16
+
17
+ type GoToInput = Readonly<Record<string, unknown>> & {
18
+ readonly destination: string;
19
+ readonly timeout_ms?: number;
20
+ };
21
+
22
+ export default class GoToBehavior extends ClawclawBehavior<GoToInput> {
23
+ static override readonly manifest = {
24
+ apiVersion: 3,
25
+ id: 'go_to',
26
+ name: 'Go To',
27
+ description: 'Navigate to one semantic room or task destination.',
28
+ localizations: { 'zh-CN': { name: '前往', description: '前往一个语义房间或任务地点。' } },
29
+ inputs: [{
30
+ id: 'destination',
31
+ type: 'string',
32
+ description: 'Known room name or exact current task id or name.',
33
+ required: true,
34
+ }],
35
+ execution: 'serial',
36
+ runtime: { defaultMs: 45_000, deadlineOutcome: 'failed' },
37
+ } as const satisfies ClawclawBehaviorManifest;
38
+
39
+ private readonly move = new SemanticMoveGate();
40
+
41
+ override normalize(input: Readonly<Record<string, unknown>>, api: BehaviorNormalizationApi): GoToInput {
42
+ return {
43
+ destination: api.string(input.destination, 'destination'),
44
+ ...api.timing(input),
45
+ };
46
+ }
47
+
48
+ override async decide(input: Readonly<BehaviorInput<GoToInput>>, api: BehaviorReadApi) {
49
+ const room = findBehaviorRoom(api, input.input.destination);
50
+ const task = behaviorTasks(input).find((candidate) => (
51
+ normalizedBehaviorLabel(candidate.name) === normalizedBehaviorLabel(input.input.destination)
52
+ || (!!candidate.id && normalizedBehaviorLabel(candidate.id) === normalizedBehaviorLabel(input.input.destination))
53
+ ));
54
+ const target = task ?? room;
55
+ const label = room?.name ?? task?.name ?? input.input.destination;
56
+ if (!target) return finished('failed', 'destination_unknown', `找不到语义目标“${input.input.destination}”。`);
57
+ if (room && input.gameState.you?.room === room.name) {
58
+ return finished('completed', 'arrived', `已到达${label}。`);
59
+ }
60
+ const self = behaviorSelf(input);
61
+ if (!self) return finished('failed', 'self_position_unavailable', '当前无法取得自身位置。');
62
+ const distance = await api.navigation.pathDistance(self, target);
63
+ if (distance === null) return finished('failed', 'destination_unreachable', `当前没有到达${label}的可用路径。`);
64
+ if (distance <= 70) return finished('completed', 'arrived', `已到达${label}。`);
65
+ const summary = `正在前往${label}。`;
66
+ const action = this.move.propose(input, target, false, summary);
67
+ return running(summary, 'moving', action ? [action] : [], room ? { room: room.name } : task ? { task: task.name } : {});
68
+ }
69
+ }
@@ -0,0 +1,77 @@
1
+ import {
2
+ ClawclawBehavior,
3
+ type BehaviorInput,
4
+ type BehaviorNormalizationApi,
5
+ type BehaviorReadApi,
6
+ type ClawclawBehaviorManifest,
7
+ } from '../../sdk/behavior-plugin/index.js';
8
+ import {
9
+ behaviorDistance,
10
+ behaviorHideSpots,
11
+ behaviorSelf,
12
+ behaviorTeammateSeats,
13
+ behaviorVisiblePlayers,
14
+ nearestBehaviorHideSpot,
15
+ normalizedBehaviorLabel,
16
+ planBehaviorEscape,
17
+ SemanticMoveGate,
18
+ type HideSpot,
19
+ } from '../../sdk/behavior-toolkit/index.js';
20
+ import { finished, running } from './shared.js';
21
+
22
+ type HideInput = Readonly<Record<string, unknown>> & {
23
+ readonly area?: string;
24
+ readonly duration_ms?: number;
25
+ };
26
+
27
+ export default class HideTemporarilyBehavior extends ClawclawBehavior<HideInput> {
28
+ static override readonly manifest = {
29
+ apiVersion: 3,
30
+ id: 'hide_temporarily',
31
+ name: 'Hide Temporarily',
32
+ description: 'Move to and remain near a bounded hide point.',
33
+ localizations: { 'zh-CN': { name: '短暂隐藏', description: '移动到一个隐藏点并在附近有限停留。' } },
34
+ inputs: [{ id: 'area', type: 'string', description: 'Optional preferred room name.' }],
35
+ execution: 'serial',
36
+ runtime: { defaultMs: 20_000, deadlineOutcome: 'completed' },
37
+ } as const satisfies ClawclawBehaviorManifest;
38
+
39
+ private readonly move = new SemanticMoveGate();
40
+ private hideTarget?: HideSpot;
41
+ private escapeTarget?: Readonly<{ x: number; y: number }>;
42
+
43
+ override normalize(input: Readonly<Record<string, unknown>>, api: BehaviorNormalizationApi): HideInput {
44
+ const area = api.optionalString(input.area, 'area');
45
+ return { ...api.timing(input), ...(area ? { area } : {}) };
46
+ }
47
+
48
+ override decide(input: Readonly<BehaviorInput<HideInput>>, _api: BehaviorReadApi) {
49
+ const self = behaviorSelf(input);
50
+ if (!self) return finished('failed', 'self_position_unavailable', '当前无法取得自身位置。');
51
+ const teammates = behaviorTeammateSeats(input);
52
+ const threats = behaviorVisiblePlayers(input).filter((player) => (
53
+ player.isAlive !== false && !teammates.has(player.seat)
54
+ ));
55
+ if (threats.some((threat) => behaviorDistance(self, threat) <= 420)) {
56
+ const plan = planBehaviorEscape(self, threats);
57
+ if (plan.caught && plan.survivedSteps === 0) return finished('failed', 'no_escape_route', '当前没有可确认的逃生路线。');
58
+ this.escapeTarget = plan.target;
59
+ const summary = `威胁过近,正在先远离${threats.map((threat) => threat.name).join('、')}。`;
60
+ const action = this.move.propose(input, this.escapeTarget, false, summary);
61
+ return running(summary, 'moving', action ? [action] : []);
62
+ }
63
+ const preferred = input.input.area
64
+ ? behaviorHideSpots()
65
+ .filter((spot) => normalizedBehaviorLabel(spot.room) === normalizedBehaviorLabel(input.input.area!))
66
+ .sort((left, right) => behaviorDistance(self, left) - behaviorDistance(self, right))[0]
67
+ : undefined;
68
+ this.hideTarget = preferred ?? nearestBehaviorHideSpot(self, threats, this.hideTarget) ?? undefined;
69
+ if (!this.hideTarget) return finished('failed', 'hide_spot_unavailable', '没有可用的隐藏点。');
70
+ if (behaviorDistance(self, this.hideTarget) <= 35) {
71
+ return running(`正在${this.hideTarget.room}隐蔽等待。`, 'waiting', [], { room: this.hideTarget.room });
72
+ }
73
+ const summary = `正在前往${this.hideTarget.room}的隐藏点。`;
74
+ const action = this.move.propose(input, this.hideTarget, false, summary);
75
+ return running(summary, 'moving', action ? [action] : [], { room: this.hideTarget.room });
76
+ }
77
+ }