@myclaw163/clawclaw-cli 0.7.16 → 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 +1 -0
  85. package/src/lib/gameplay-config.test.ts +258 -37
  86. package/src/lib/gameplay-config.ts +175 -35
  87. package/src/lib/hub-install.test.ts +19 -41
  88. package/src/lib/hub-install.ts +10 -38
  89. package/src/lib/hub-reminder.ts +7 -9
  90. package/src/lib/init-command.ts +1 -1
  91. package/src/lib/official-resource-sync.test.ts +199 -0
  92. package/src/lib/official-resource-sync.ts +221 -0
  93. package/src/lib/perception-config.test.ts +9 -4
  94. package/src/lib/perception-config.ts +10 -13
  95. package/src/lib/perception-export.test.ts +145 -0
  96. package/src/lib/perception-export.ts +178 -0
  97. package/src/lib/trigger-config.test.ts +102 -0
  98. package/src/lib/trigger-config.ts +217 -0
  99. package/src/lib/user-data.test.ts +23 -6
  100. package/src/lib/user-data.ts +15 -123
  101. package/src/pipeline/canonical-event-presentation.test.ts +5 -5
  102. package/src/pipeline/canonical-event-presentation.ts +13 -5
  103. package/src/pipeline/event-format.test.ts +106 -3
  104. package/src/pipeline/event-format.ts +172 -4
  105. package/src/pipeline/event-hints.test.ts +57 -4
  106. package/src/pipeline/event-hints.ts +34 -8
  107. package/src/runtime/canonical-monitor.test.ts +2 -0
  108. package/src/runtime/canonical-monitor.ts +6 -2
  109. package/src/runtime/clawclaw/agent-event-policy.test.ts +23 -2
  110. package/src/runtime/clawclaw/agent-event-policy.ts +12 -5
  111. package/src/runtime/clawclaw/behavior-decision.test.ts +29 -0
  112. package/src/runtime/clawclaw/behavior-decision.ts +82 -0
  113. package/src/runtime/clawclaw/behavior-input-fields.test.ts +175 -0
  114. package/src/runtime/clawclaw/behavior-input-fields.ts +270 -0
  115. package/src/runtime/clawclaw/behavior-input.test.ts +151 -0
  116. package/src/runtime/clawclaw/behavior-input.ts +70 -0
  117. package/src/runtime/clawclaw/behavior-observation-memory.test.ts +59 -0
  118. package/src/runtime/clawclaw/behavior-observation-memory.ts +142 -0
  119. package/src/runtime/clawclaw/behavior-read-api.test.ts +123 -0
  120. package/src/runtime/clawclaw/behavior-read-api.ts +158 -0
  121. package/src/runtime/clawclaw/{plugins/perception/visual-state-projector.ts → observation-frame-projector.ts} +44 -25
  122. package/src/runtime/clawclaw/owner.test.ts +187 -0
  123. package/src/runtime/clawclaw/owner.ts +431 -69
  124. package/src/runtime/clawclaw/plugins/action/action-plugin.test.ts +304 -0
  125. package/src/runtime/clawclaw/plugins/action/action-plugin.ts +285 -41
  126. package/src/runtime/clawclaw/plugins/action/automated-action-normalization.ts +82 -0
  127. package/src/runtime/clawclaw/plugins/assembly.test.ts +135 -29
  128. package/src/runtime/clawclaw/plugins/assembly.ts +54 -28
  129. package/src/runtime/clawclaw/plugins/behavior/activation-manager.test.ts +180 -0
  130. package/src/runtime/clawclaw/plugins/behavior/activation-manager.ts +468 -0
  131. package/src/runtime/clawclaw/plugins/behavior/behavior-action.test.ts +40 -0
  132. package/src/runtime/clawclaw/plugins/behavior/behavior-action.ts +30 -0
  133. package/src/runtime/clawclaw/plugins/behavior/behavior-analysis-thread-host.ts +152 -0
  134. package/src/runtime/clawclaw/plugins/behavior/behavior-catalog.test.ts +156 -0
  135. package/src/runtime/clawclaw/plugins/behavior/behavior-catalog.ts +104 -0
  136. package/src/runtime/clawclaw/plugins/behavior/behavior-manifest.ts +173 -0
  137. package/src/runtime/clawclaw/plugins/behavior/behavior-module-loader.test.ts +182 -0
  138. package/src/runtime/clawclaw/plugins/behavior/behavior-module-loader.ts +223 -0
  139. package/src/runtime/clawclaw/plugins/behavior/behavior-normalization.ts +157 -0
  140. package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.test.ts +848 -0
  141. package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.ts +1347 -0
  142. package/src/runtime/clawclaw/plugins/behavior/behavior-runner.ts +212 -0
  143. package/src/runtime/clawclaw/plugins/behavior/behavior-source.test.ts +174 -0
  144. package/src/runtime/clawclaw/plugins/behavior/behavior-source.ts +621 -0
  145. package/src/runtime/clawclaw/plugins/behavior/control-driver.test.ts +195 -0
  146. package/src/runtime/clawclaw/plugins/behavior/control-driver.ts +180 -0
  147. package/src/runtime/clawclaw/plugins/behavior/index.ts +11 -0
  148. package/src/runtime/clawclaw/plugins/behavior/official-goal-behavior.ts +766 -0
  149. package/src/runtime/clawclaw/plugins/behavior/thread-behavior-executor.test.ts +283 -0
  150. package/src/runtime/clawclaw/plugins/{strategy/thread-strategy-executor.ts → behavior/thread-behavior-executor.ts} +109 -121
  151. package/src/runtime/clawclaw/plugins/behavior-input-source.test.ts +80 -0
  152. package/src/runtime/clawclaw/plugins/behavior-input-source.ts +247 -0
  153. package/src/runtime/clawclaw/plugins/{strategy → game-query}/context-capabilities.ts +1 -1
  154. package/src/runtime/clawclaw/plugins/game-query/game-query-plugin.test.ts +13 -10
  155. package/src/runtime/clawclaw/plugins/game-query/game-query-plugin.ts +26 -14
  156. package/src/runtime/clawclaw/plugins/game-query/index.ts +1 -0
  157. package/src/runtime/clawclaw/plugins/index.ts +3 -1
  158. package/src/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-adapter.test.ts +239 -0
  159. package/src/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-adapter.ts +100 -0
  160. package/src/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-socket.ts +346 -0
  161. package/src/runtime/clawclaw/plugins/mailbox/agent-mailbox-coordinator.test.ts +230 -12
  162. package/src/runtime/clawclaw/plugins/mailbox/agent-mailbox-coordinator.ts +118 -90
  163. package/src/runtime/clawclaw/plugins/mailbox/consumer-ids.ts +5 -0
  164. package/src/runtime/clawclaw/plugins/mailbox/index.ts +3 -0
  165. package/src/runtime/clawclaw/plugins/mailbox/mailbox-agent-event-batch.test.ts +1 -1
  166. package/src/runtime/clawclaw/plugins/mailbox/mailbox-event-batch-delivery.ts +4 -0
  167. package/src/runtime/clawclaw/plugins/mailbox/mailbox-plugin.test.ts +87 -0
  168. package/src/runtime/clawclaw/plugins/mailbox/mailbox-plugin.ts +70 -12
  169. package/src/runtime/clawclaw/plugins/mailbox/mailbox-presentation.ts +94 -11
  170. package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.test.ts +1229 -345
  171. package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.ts +479 -35
  172. package/src/runtime/clawclaw/plugins/perception/contracts.ts +4 -3
  173. package/src/runtime/clawclaw/plugins/perception/index.ts +1 -1
  174. package/src/runtime/clawclaw/plugins/perception/module-runner.test.ts +23 -13
  175. package/src/runtime/clawclaw/plugins/perception/module-runner.ts +11 -9
  176. package/src/runtime/clawclaw/plugins/perception/modules/co-movement-module.ts +39 -38
  177. package/src/runtime/clawclaw/plugins/perception/modules/corpse-visibility-module.test.ts +92 -0
  178. package/src/runtime/clawclaw/plugins/perception/modules/corpse-visibility-module.ts +248 -0
  179. package/src/runtime/clawclaw/plugins/perception/modules/follow-module.ts +39 -37
  180. package/src/runtime/clawclaw/plugins/perception/modules/index.ts +1 -0
  181. package/src/runtime/clawclaw/plugins/perception/modules/motion-module.test.ts +22 -21
  182. package/src/runtime/clawclaw/plugins/perception/modules/motion-module.ts +15 -9
  183. package/src/runtime/clawclaw/plugins/perception/modules/parallel-module-test-helpers.ts +3 -3
  184. package/src/runtime/clawclaw/plugins/perception/modules/relation-stability.test.ts +33 -18
  185. package/src/runtime/clawclaw/plugins/perception/modules/route-module.test.ts +6 -7
  186. package/src/runtime/clawclaw/plugins/perception/modules/route-module.ts +22 -16
  187. package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.test.ts +6 -7
  188. package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.ts +18 -12
  189. package/src/runtime/clawclaw/plugins/perception/modules/stop-module.test.ts +14 -10
  190. package/src/runtime/clawclaw/plugins/perception/modules/stop-module.ts +20 -14
  191. package/src/runtime/clawclaw/plugins/perception/modules/temporal-evidence.test.ts +5 -6
  192. package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.test.ts +5 -6
  193. package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.ts +49 -34
  194. package/src/runtime/clawclaw/plugins/perception/official-module-ids.ts +1 -0
  195. package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-pool.test.ts +126 -20
  196. package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-pool.ts +24 -3
  197. package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-worker.ts +59 -46
  198. package/src/runtime/clawclaw/plugins/perception/perception-module-loader.ts +27 -5
  199. package/src/runtime/clawclaw/plugins/perception/perception-plugin.test.ts +381 -49
  200. package/src/runtime/clawclaw/plugins/perception/perception-plugin.ts +267 -245
  201. package/src/runtime/clawclaw/plugins/perception/perception-source.test.ts +98 -0
  202. package/src/runtime/clawclaw/plugins/perception/perception-source.ts +89 -16
  203. package/src/runtime/clawclaw/plugins/perception/perception-test-fixtures.ts +34 -0
  204. package/src/runtime/clawclaw/plugins/perception/replay.test.ts +27 -15
  205. package/src/runtime/clawclaw/plugins/perception/replay.ts +10 -5
  206. package/src/runtime/clawclaw/plugins/perception/shared/math.ts +1 -107
  207. package/src/runtime/clawclaw/plugins/perception/spatial-facts.ts +7 -10
  208. package/src/runtime/clawclaw/plugins/plugin-api-version.ts +112 -0
  209. package/src/runtime/clawclaw/plugins/runtime-plugins.test.ts +388 -559
  210. package/src/runtime/clawclaw/plugins/source/player-change-tracker.test.ts +56 -5
  211. package/src/runtime/clawclaw/plugins/source/player-change-tracker.ts +135 -26
  212. package/src/runtime/clawclaw/plugins/source/source-plugin.test.ts +249 -16
  213. package/src/runtime/clawclaw/plugins/source/source-plugin.ts +99 -2
  214. package/src/runtime/clawclaw/plugins/source/task-change-tracker.test.ts +212 -0
  215. package/src/runtime/clawclaw/plugins/source/task-change-tracker.ts +259 -0
  216. package/src/runtime/clawclaw/plugins/trigger/contracts.ts +97 -0
  217. package/src/runtime/clawclaw/plugins/trigger/index.ts +4 -0
  218. package/src/runtime/clawclaw/plugins/trigger/trigger-module-loader.ts +118 -0
  219. package/src/runtime/clawclaw/plugins/trigger/trigger-plugin.test.ts +548 -0
  220. package/src/runtime/clawclaw/plugins/trigger/trigger-plugin.ts +655 -0
  221. package/src/runtime/clawclaw/plugins/trigger/trigger-source.test.ts +169 -0
  222. package/src/runtime/clawclaw/plugins/trigger/trigger-source.ts +457 -0
  223. package/src/runtime/clawclaw/runtime.ts +8 -0
  224. package/src/runtime/clawclaw/spatial-api.ts +76 -0
  225. package/src/runtime/clawclaw-event-catalog.test.ts +46 -1
  226. package/src/runtime/clawclaw-event-catalog.ts +40 -3
  227. package/src/runtime/framework/capability-registry.test.ts +196 -55
  228. package/src/runtime/framework/capability-registry.ts +99 -17
  229. package/src/runtime/framework/contracts.ts +30 -4
  230. package/src/runtime/framework/control/control-scheduler.ts +13 -5
  231. package/src/runtime/framework/control/types.ts +11 -4
  232. package/src/runtime/framework/control-coordinator.test.ts +95 -80
  233. package/src/runtime/framework/events/event-delivery-service.ts +4 -2
  234. package/src/runtime/framework/events/event-ingress.test.ts +25 -0
  235. package/src/runtime/framework/events/event-ingress.ts +2 -1
  236. package/src/runtime/framework/events/event-repository.ts +24 -2
  237. package/src/runtime/framework/events/mailbox-event-repositories.test.ts +124 -8
  238. package/src/runtime/framework/events/memory-event-repository.ts +92 -28
  239. package/src/runtime/framework/events/sqlite-event-repository.test.ts +604 -2
  240. package/src/runtime/framework/events/sqlite-event-repository.ts +531 -21
  241. package/src/runtime/framework/events/types.ts +24 -8
  242. package/src/runtime/framework/modules/runtime-module-loader-hooks.mjs +38 -1
  243. package/src/runtime/framework/modules/runtime-module-loader.test.ts +233 -7
  244. package/src/runtime/framework/modules/runtime-module-loader.ts +69 -4
  245. package/src/runtime/framework/plugins/contracts.ts +12 -18
  246. package/src/runtime/framework/plugins/runtime-plugin-scheduler.test.ts +81 -71
  247. package/src/runtime/framework/plugins/runtime-plugin-scheduler.ts +38 -20
  248. package/src/runtime/framework/runtime.ts +20 -23
  249. package/src/runtime/host-monitor-rate-gate.test.ts +73 -0
  250. package/src/runtime/host-monitor-rate-gate.ts +123 -0
  251. package/src/runtime/mailbox-host-relay.test.ts +45 -0
  252. package/src/runtime/mailbox-host-relay.ts +25 -0
  253. package/src/runtime/observability/factory.ts +4 -4
  254. package/src/runtime/observability/observability.test.ts +25 -3
  255. package/src/runtime/observability/reporter.ts +1 -1
  256. package/src/runtime/observability/types.ts +2 -2
  257. package/src/runtime/owner-control.ts +10 -2
  258. package/src/runtime/runtime-logger.test.ts +1 -1
  259. package/src/runtime/runtime-logger.ts +4 -6
  260. package/src/runtime/runtime.test.ts +88 -22
  261. package/src/sdk/action.ts +2 -2
  262. package/src/sdk/behavior-plugin/index.test.ts +74 -0
  263. package/src/sdk/behavior-plugin/index.ts +335 -0
  264. package/src/sdk/behavior-toolkit/corpse-search.ts +87 -0
  265. package/src/sdk/behavior-toolkit/escape.ts +40 -0
  266. package/src/sdk/behavior-toolkit/index.ts +7 -0
  267. package/src/sdk/behavior-toolkit/kill-flow.ts +299 -0
  268. package/src/sdk/behavior-toolkit/model.ts +263 -0
  269. package/src/sdk/behavior-toolkit/move-gate.ts +52 -0
  270. package/src/sdk/behavior-toolkit/patrol.ts +53 -0
  271. package/src/sdk/behavior-toolkit/search.ts +102 -0
  272. package/src/sdk/index.test.ts +45 -0
  273. package/src/sdk/index.ts +67 -73
  274. package/src/sdk/module-input/index.test.ts +49 -0
  275. package/src/sdk/module-input/index.ts +229 -0
  276. package/src/sdk/perception-plugin/index.test.ts +2 -2
  277. package/src/sdk/perception-plugin/index.ts +51 -142
  278. package/src/sdk/perception-plugin/math.ts +107 -0
  279. package/src/sdk/trigger-plugin/index.test.ts +41 -0
  280. package/src/sdk/trigger-plugin/index.ts +128 -0
  281. package/src/strategies/avoid-lone.ts +21 -10
  282. package/src/strategies/avoid-players.ts +26 -16
  283. package/src/strategies/corpse-patrol.ts +25 -14
  284. package/src/strategies/crab-sabotage.ts +20 -9
  285. package/src/strategies/find-player.ts +33 -21
  286. package/src/strategies/game-utils.ts +1 -1
  287. package/src/strategies/goals/crab-sabotage-top.test.ts +145 -0
  288. package/src/strategies/goals/crab-sabotage-top.ts +32 -69
  289. package/src/strategies/hide.ts +25 -15
  290. package/src/strategies/kill-frenzy.ts +21 -10
  291. package/src/strategies/kill-lone.ts +27 -17
  292. package/src/strategies/kill-target.ts +33 -22
  293. package/src/strategies/lone-kill-task.ts +20 -9
  294. package/src/strategies/move-room.ts +29 -18
  295. package/src/strategies/official-long-behavior.test.ts +89 -0
  296. package/src/strategies/paradise-fish.ts +29 -18
  297. package/src/strategies/pathfind/astar-path.test.ts +127 -2
  298. package/src/strategies/pathfind/astar-path.ts +136 -26
  299. package/src/strategies/patrol.ts +21 -10
  300. package/src/strategies/player-targets.test.ts +10 -0
  301. package/src/strategies/player-targets.ts +13 -0
  302. package/src/strategies/report-patrol.ts +21 -10
  303. package/src/strategies/shrimp-memory.ts +30 -19
  304. package/src/strategies/social-task.ts +34 -23
  305. package/src/strategies/task-kill-report.ts +33 -22
  306. package/src/strategies/task-only.test.ts +99 -85
  307. package/src/strategies/task-only.ts +23 -12
  308. package/src/strategies/task-report.ts +25 -14
  309. package/src/strategies/types.ts +8 -8
  310. package/src/strategies/warrior-memory.ts +29 -19
  311. package/docs/runtime/strategy-runtime.md +0 -111
  312. package/docs//350/207/252/345/256/232/344/271/211/346/204/237/347/237/245.md +0 -502
  313. package/docs//350/207/252/345/256/232/344/271/211/347/255/226/347/225/245.md +0 -395
  314. package/skills/clawclaw/references/STRATEGIES.md +0 -76
  315. package/src/commands/strategy.test.ts +0 -209
  316. package/src/commands/strategy.ts +0 -242
  317. package/src/lib/strategy-export.test.ts +0 -406
  318. package/src/lib/strategy-export.ts +0 -381
  319. package/src/runtime/clawclaw/plugins/perception/official-modules.ts +0 -31
  320. package/src/runtime/clawclaw/plugins/strategy/examples/task-only-strategy.test.ts +0 -177
  321. package/src/runtime/clawclaw/plugins/strategy/examples/task-only-strategy.ts +0 -191
  322. package/src/runtime/clawclaw/plugins/strategy/index.ts +0 -8
  323. package/src/runtime/clawclaw/plugins/strategy/local-strategy-executor.ts +0 -412
  324. package/src/runtime/clawclaw/plugins/strategy/strategy-action.ts +0 -80
  325. package/src/runtime/clawclaw/plugins/strategy/strategy-analysis-thread-host.ts +0 -183
  326. package/src/runtime/clawclaw/plugins/strategy/strategy-executor-types.ts +0 -29
  327. package/src/runtime/clawclaw/plugins/strategy/strategy-executor.test.ts +0 -693
  328. package/src/runtime/clawclaw/plugins/strategy/strategy-game-api.ts +0 -57
  329. package/src/runtime/clawclaw/plugins/strategy/strategy-module-loader.ts +0 -168
  330. package/src/runtime/clawclaw/plugins/strategy/strategy-plugin.test.ts +0 -2175
  331. package/src/runtime/clawclaw/plugins/strategy/strategy-plugin.ts +0 -1774
  332. package/src/runtime/clawclaw/plugins/strategy/strategy-source.test.ts +0 -153
  333. package/src/runtime/clawclaw/plugins/strategy/strategy-source.ts +0 -443
  334. package/src/sdk/strategy-plugin/index.test.ts +0 -958
  335. package/src/sdk/strategy-plugin/index.ts +0 -1350
@@ -1,24 +1,24 @@
1
1
  import { describe, expect, it, vi } from 'vitest';
2
2
  import type {
3
- ClawclawStrategyAction,
4
- ClawclawStrategyGameState,
5
- ClawclawStrategyPlayerActivity,
6
- StrategyApi,
7
- StrategyGameApi,
8
- WanderingStrategyFrame,
9
- } from '../sdk/strategy-plugin/index.js';
3
+ BehaviorInput,
4
+ BehaviorReadApi,
5
+ } from '../sdk/behavior-plugin/index.js';
6
+ import type { GamePlayerActivity, GameTask } from '../sdk/module-input/index.js';
7
+ import HideStrategy from './hide.js';
10
8
  import TaskOnlyStrategy from './task-only.js';
11
9
 
12
10
  function frame(
13
11
  epochId: number,
14
- activity: ClawclawStrategyPlayerActivity = { kind: 'idle' },
15
- ): WanderingStrategyFrame<ClawclawStrategyGameState> {
12
+ tasks?: readonly Readonly<GameTask>[],
13
+ activity: GamePlayerActivity = { kind: 'idle' },
14
+ input: Readonly<Record<string, unknown>> = {},
15
+ ): BehaviorInput {
16
16
  return {
17
17
  epochId,
18
18
  scope: { sessionId: 'session', segmentId: 'game' },
19
- stage: 'game',
20
- tick: 100 + epochId,
21
- state: {
19
+ nowMs: epochId * 100,
20
+ gameState: {
21
+ game_id: 'game',
22
22
  phase: 'wandering',
23
23
  tick: 100 + epochId,
24
24
  you: {
@@ -29,96 +29,110 @@ function frame(
29
29
  x: 0,
30
30
  y: 0,
31
31
  room: '引擎室',
32
+ completed_task_count: 0,
32
33
  activity,
34
+ ...(tasks === undefined ? {} : { tasks }),
33
35
  },
34
36
  players: [{ seat: 1, name: 'self', known_status: { is_alive: true } }],
35
37
  visible_players: [],
36
38
  visible_corpses: [],
39
+ task_progress: { completed: 0, goal: 3 },
40
+ emergency: { active: false },
41
+ meeting: { active: false },
42
+ octopus_time: { active: false },
37
43
  },
38
- upstreamStates: {},
39
44
  events: [],
40
- parameters: {},
45
+ input,
41
46
  };
42
47
  }
43
48
 
44
- describe('task-only hybrid strategy', () => {
45
- it('keeps analysis stateless and constructs one persistent Goal tree only in reduce', async () => {
46
- const getMap = vi.fn().mockRejectedValue(new Error('task-only must not request the static map'));
47
- const getTasks = vi.fn().mockResolvedValue([]);
48
- const game: StrategyGameApi = {
49
- getMap,
50
- getTasks,
51
- pathDistance: vi.fn(),
52
- };
49
+ function readApi(): BehaviorReadApi & {
50
+ navigation: BehaviorReadApi['navigation'] & {
51
+ pathDistance: ReturnType<typeof vi.fn>;
52
+ pathDistances: ReturnType<typeof vi.fn>;
53
+ };
54
+ } {
55
+ const rooms = [{
56
+ name: '引擎室',
57
+ polygon: [[-100, -100], [100, -100], [100, 100], [-100, 100]] as const,
58
+ bbox: { left: -100, top: -100, right: 100, bottom: 100 },
59
+ }];
60
+ const pathDistance = vi.fn(async () => 0);
61
+ const pathDistances = vi.fn(async (queries: readonly unknown[]) => queries.map(() => 100));
62
+ return {
63
+ spatial: {
64
+ xPositive: 'right',
65
+ yPositive: 'down',
66
+ playerBodyLengthPx: 64,
67
+ rooms,
68
+ roomAt: () => rooms[0],
69
+ sideInRoom: () => 'center',
70
+ placeLabel: () => '引擎室',
71
+ transitionIsMapped: () => true,
72
+ },
73
+ navigation: { pathDistance, pathDistances },
74
+ observation: {
75
+ lastSeenPlayer: () => undefined,
76
+ lastSeenCorpse: () => undefined,
77
+ },
78
+ };
79
+ }
80
+
81
+ const taskA = {
82
+ name: '任务A',
83
+ room: '引擎室',
84
+ x: 0,
85
+ y: 0,
86
+ is_fake_shrimp: false,
87
+ status: 'normal',
88
+ } as const satisfies GameTask;
89
+
90
+ describe('official Strategy standard callback', () => {
91
+ it('reads tasks from BehaviorInput and returns an Action proposal without private submit/query APIs', async () => {
92
+ const api = readApi();
53
93
  const instance = new TaskOnlyStrategy();
54
- const privateState = instance as unknown as { strategy?: unknown };
55
94
 
56
- const first = await instance.analyze(frame(1), game);
57
- const second = await instance.analyze(frame(2), game);
58
- expect(privateState.strategy).toBeUndefined();
59
- expect(first).toEqual({ resources: { tasks: [], tasksAvailable: true } });
60
- expect(first).not.toHaveProperty('state');
61
- expect(first).not.toHaveProperty('events');
62
- expect(getTasks).toHaveBeenCalledTimes(2);
63
- expect(getMap).not.toHaveBeenCalled();
64
- expect(() => structuredClone(first)).not.toThrow();
65
- expect(() => structuredClone(second)).not.toThrow();
95
+ const first = await instance.decide(frame(1, [taskA]), api);
96
+ expect(first.actions?.[0]).toMatchObject({ action: 'task', task_name: '任务A' });
97
+ expect(first.status).toMatchObject({ activity: 'doing_task', task: '任务A' });
98
+ expect(api.navigation.pathDistance).not.toHaveBeenCalled();
99
+ expect(api.navigation.pathDistances).not.toHaveBeenCalled();
66
100
 
67
- const api: StrategyApi<ClawclawStrategyAction> = {
68
- game,
69
- action: { submit: vi.fn() },
70
- };
71
- await instance.reduce(frame(1), first, api);
72
- const goalTree = privateState.strategy;
73
- expect(goalTree).toBeDefined();
74
- await instance.reduce(frame(2), second, api);
75
- expect(privateState.strategy).toBe(goalTree);
76
- expect(getTasks).toHaveBeenCalledTimes(2);
77
- expect(getMap).not.toHaveBeenCalled();
101
+ const active = await instance.decide(frame(2, [{ ...taskA, status: 'in_progress' }], {
102
+ kind: 'task',
103
+ task_name: '任务A',
104
+ }), api);
105
+ expect(active.actions).toBeUndefined();
106
+ expect(active.status).toMatchObject({ activity: 'doing_task', task: '任务A' });
78
107
  });
79
108
 
80
- it('does not resubmit a successful task from a stale pre-analysis snapshot', async () => {
81
- let tasks = [
82
- { name: '任务A', room: '引擎室', x: 0, y: 0, status: 'normal' },
83
- { name: '任务B', room: '引擎室', x: 0, y: 0, status: 'normal' },
84
- ];
85
- const getTasks = vi.fn(async () => structuredClone(tasks));
86
- const game: StrategyGameApi = {
87
- getTasks,
88
- getMap: vi.fn().mockRejectedValue(new Error('task-only must not request the static map')),
89
- pathDistance: vi.fn(),
90
- };
91
- const submitted: string[] = [];
92
- const api: StrategyApi<ClawclawStrategyAction> = {
93
- game,
94
- action: {
95
- submit: vi.fn(async (action) => {
96
- if (action.action === 'task') submitted.push(String(action.task_name));
97
- return {
98
- status: 'success' as const,
99
- source: 'backend' as const,
100
- actionOutcome: 'confirmed' as const,
101
- };
102
- }),
109
+ it('publishes an explicit waiting status when required tasks are absent', async () => {
110
+ const result = await new TaskOnlyStrategy().decide(frame(1), readApi());
111
+
112
+ expect(result.actions).toBeUndefined();
113
+ expect(result.status).toMatchObject({
114
+ activity: 'waiting',
115
+ data: { dataAvailability: { tasks: 'unavailable' } },
116
+ });
117
+ });
118
+
119
+ it('uses the shared spatial and navigation capabilities for official route evidence', async () => {
120
+ const api = readApi();
121
+ const base = frame(1, [], { kind: 'idle' }, { killWhenCornered: 'auto' });
122
+ const routeFrame: BehaviorInput = {
123
+ ...base,
124
+ gameState: {
125
+ ...base.gameState,
126
+ you: { ...base.gameState.you, x: 2_882, y: 1_362 },
103
127
  },
104
128
  };
105
- const instance = new TaskOnlyStrategy();
106
-
107
- // Both expensive analyses finish against the same authoritative State.
108
- const first = await instance.analyze(frame(1), game);
109
- const staleSecond = await instance.analyze(frame(2), game);
110
- await instance.reduce(frame(1), first, api);
111
- await instance.reduce(frame(2), staleSecond, api);
112
- expect(submitted).toEqual(['任务A']);
129
+ const result = await new HideStrategy().decide(
130
+ routeFrame,
131
+ api,
132
+ );
113
133
 
114
- // A later authoritative task-list change releases the hold and lets the
115
- // reducer advance to the next task.
116
- tasks = [
117
- { name: '任务A', room: '引擎室', x: 0, y: 0, status: 'completed' },
118
- { name: '任务B', room: '引擎室', x: 0, y: 0, status: 'normal' },
119
- ];
120
- const authoritativeThird = await instance.analyze(frame(3), game);
121
- await instance.reduce(frame(3), authoritativeThird, api);
122
- expect(submitted).toEqual(['任务A', '任务B']);
134
+ expect(api.navigation.pathDistances).toHaveBeenCalledTimes(1);
135
+ expect(api.navigation.pathDistances.mock.calls[0]?.[0]).not.toHaveLength(0);
136
+ expect(result.status?.summary).toBeTruthy();
123
137
  });
124
138
  });
@@ -1,23 +1,34 @@
1
- import { ClawclawGoalStrategy } from '../sdk/strategy-plugin/index.js';
1
+ import {
2
+ type BehaviorDecision,
3
+ type BehaviorInput,
4
+ type BehaviorReadApi,
5
+ ClawclawBehavior,
6
+ } from '../sdk/behavior-plugin/index.js';
7
+ import { OfficialGoalBehavior } from '../runtime/clawclaw/plugins/behavior/official-goal-behavior.js';
2
8
  import { GoalRootStrategy } from './goals/goal-root-strategy.js';
3
9
  import { TaskOnlyTop } from './goals/task-only-top.js';
4
10
 
5
- export default class TaskOnlyStrategy extends ClawclawGoalStrategy {
11
+ export default class TaskOnlyStrategy extends ClawclawBehavior {
6
12
  static readonly manifest = {
13
+ apiVersion: 3,
7
14
  id: 'task-only',
8
15
  name: '纯任务',
9
16
  description: '专心做任务。紧急任务出现时优先处理,其次按顺序完成普通任务,如果是蟹,则蟹的伪装任务也会做。没有尸体报告和战斗行为。',
10
- execution: 'parallel_analyze',
17
+ execution: 'serial',
18
+ produces: ['strategy_alert', 'robot_speak_rule'],
19
+ inputs: [],
11
20
  } as const;
12
21
 
13
- constructor(parameters: Readonly<Record<string, unknown>> = {}) {
14
- super(parameters, {
15
- id: 'task-only',
16
- requiresTasks: true,
17
- requiresMap: false,
18
- create: () => new GoalRootStrategy('task-only', () => new TaskOnlyTop(), {
19
- resetOnMeetingResume: false,
20
- }),
21
- });
22
+ private readonly goal = new OfficialGoalBehavior({
23
+ id: 'task-only',
24
+ requiresTasks: true,
25
+ requiresMap: false,
26
+ create: () => new GoalRootStrategy('task-only', () => new TaskOnlyTop(), {
27
+ resetOnMeetingResume: false,
28
+ }),
29
+ });
30
+
31
+ override decide(input: BehaviorInput, api: BehaviorReadApi): Promise<BehaviorDecision> {
32
+ return this.goal.decide(input, api);
22
33
  }
23
34
  }
@@ -1,7 +1,13 @@
1
1
  import {
2
- ClawclawGoalStrategy,
2
+ type BehaviorDecision,
3
+ type BehaviorInput,
4
+ type BehaviorReadApi,
5
+ ClawclawBehavior,
6
+ } from '../sdk/behavior-plugin/index.js';
7
+ import {
8
+ OfficialGoalBehavior,
3
9
  clawclawStrategyStringList,
4
- } from '../sdk/strategy-plugin/index.js';
10
+ } from '../runtime/clawclaw/plugins/behavior/official-goal-behavior.js';
5
11
  import { GoalRootStrategy } from './goals/goal-root-strategy.js';
6
12
  import { TaskReportTop } from './goals/task-report-top.js';
7
13
  import { parseGreetingArgs } from './greeting.js';
@@ -12,28 +18,33 @@ class TaskReportStrategy extends GoalRootStrategy {
12
18
  }
13
19
  }
14
20
 
15
- export default class TaskReportGoalStrategy extends ClawclawGoalStrategy {
21
+ export default class TaskReportGoalStrategy extends ClawclawBehavior {
16
22
  static readonly manifest = {
23
+ apiVersion: 3,
17
24
  id: 'task-report',
18
25
  name: '尽责虾',
19
26
  description: '遇尸体最优先:达到报告距离立刻报告,没达到距离就靠近准备报告。紧急任务出现时优先处理,其次按顺序完成普通任务。greetings 控制可配置最多3条打招呼话术;视野内出现人时随机发送一条,之后120秒内不再发言。',
20
- execution: 'parallel_analyze',
21
- controls: [{
27
+ execution: 'serial',
28
+ produces: ['strategy_alert', 'robot_speak_rule'],
29
+ inputs: [{
22
30
  id: 'greetings',
23
31
  type: 'string_list',
24
32
  description: '可选的打招呼话术列表。',
25
33
  default: [],
34
+ maxItems: 3,
26
35
  }],
27
36
  } as const;
28
37
 
29
- constructor(parameters: Readonly<Record<string, unknown>> = {}) {
30
- super(parameters, {
31
- id: 'task-report',
32
- requiresTasks: true,
33
- sidecarSpeech: true,
34
- create: (values) => new TaskReportStrategy(
35
- parseGreetingArgs(clawclawStrategyStringList(values, 'greetings'), 'task-report'),
36
- ),
37
- });
38
+ private readonly goal = new OfficialGoalBehavior({
39
+ id: 'task-report',
40
+ requiresTasks: true,
41
+ sidecarSpeech: true,
42
+ create: (values) => new TaskReportStrategy(
43
+ parseGreetingArgs(clawclawStrategyStringList(values, 'greetings'), 'task-report'),
44
+ ),
45
+ });
46
+
47
+ override decide(input: BehaviorInput, api: BehaviorReadApi): Promise<BehaviorDecision> {
48
+ return this.goal.decide(input, api);
38
49
  }
39
50
  }
@@ -6,7 +6,7 @@ import type { RouteEvidence } from './pathfind/escape-planner.js';
6
6
  * Minimal interface for custom modules (built-in and strategy-registered).
7
7
  * Strategy authors implement this to inject custom analysis modules
8
8
  * (e.g. CoMovementTracker, VisibilityTracker, SpeechAnalyzer) via ctx.customModules.
9
- * ClawclawGoalStrategy manages lifecycle through these hooks:
9
+ * OfficialGoalBehavior manages lifecycle through these hooks:
10
10
  * - processEvents: called every tick with new events, tick number, and current game state
11
11
  * - afterDecide: called after strategy.decide(), can filter/modify decisions (chained by registration order)
12
12
  * - onMeetingResume: called after each meeting (decay or full reset)
@@ -48,7 +48,7 @@ export interface Strategy {
48
48
  decide(state: GameState, ctx: StrategyContext): BehaviorDecision[];
49
49
  /** Called when wandering resumes after a meeting pause. */
50
50
  onMeetingResume?(): void;
51
- /** Called by ClawclawGoalStrategy when authoritative role state changes. */
51
+ /** Called by OfficialGoalBehavior when authoritative role state changes. */
52
52
  updateRole?(role: string): void;
53
53
  /** Return custom analysis modules. Called once during setup, before the main loop. */
54
54
  customModules?(): CustomModule[];
@@ -67,7 +67,7 @@ export interface StrategyContext {
67
67
  /** Current-frame A* route projection computed by the parallel analyzer. */
68
68
  routeEvidence?: Readonly<RouteEvidence> | null;
69
69
  /**
70
- * 全局任务站点(map 的 all_task_locations),ClawclawGoalStrategy 首次加载地图后写入。与 taskData(仅自己被
70
+ * 全局任务站点(map 的 all_task_locations),OfficialGoalBehavior 首次加载地图后写入。与 taskData(仅自己被
71
71
  * 分配、带 status)不同:这是地图上所有任务点的位置,开局固定。用于「同伴停在任务点附近 → 在真实
72
72
  * 任务点假装做任务」这类定点行为。首次地图加载前可能为空/未设置。
73
73
  */
@@ -78,7 +78,7 @@ export interface StrategyContext {
78
78
  reportBlockedUntil: number;
79
79
  /**
80
80
  * 章鱼时间(剩 3 人,服务端禁用会议/报尸,report 会被 `cannot_report_during_octopus_time` 拒绝)进行中。
81
- * ClawclawGoalStrategy 见到 `octopus_time_start` 事件即置 true;每局
81
+ * OfficialGoalBehavior 见到 `octopus_time_start` 事件即置 true;每局
82
82
  * 进程独立初始化为 false,会议恢复时一并清 false(章鱼时间不会开会,纯防御)。为 true 时所有报尸决策
83
83
  * (reportCorpseDecision / ReportPatrolTop.tryReport / 经前者的 corpseReportWithNonTeammate)直接放弃,改生存优先。
84
84
  */
@@ -99,10 +99,10 @@ export interface StrategyContext {
99
99
  blockedMoveTarget: { x: number; y: number } | null;
100
100
  /** Own seat number, used by speech module for initiation arbitration. */
101
101
  mySeat: number;
102
- /** Speech-module notifications, flushed by ClawclawGoalStrategy as robot_speak_rule events. */
102
+ /** Speech-module notifications, flushed by OfficialGoalBehavior as robot_speak_rule events. */
103
103
  speechNotifications: string[];
104
104
  /**
105
- * Strategy → agent real-time briefings, flushed by ClawclawGoalStrategy as `strategy_alert`
105
+ * Strategy → agent real-time briefings, flushed by OfficialGoalBehavior as `strategy_alert`
106
106
  * events (notable → surfaced live by Monitor, unlike `notifications` which only
107
107
  * land in the log as `type:'auto'`). Push **sparingly**, only on a decisive autonomous
108
108
  * move the agent must account for when it next speaks/votes (e.g. the bot reported a
@@ -110,13 +110,13 @@ export interface StrategyContext {
110
110
  */
111
111
  agentAlerts: string[];
112
112
  /**
113
- * 跨 tick 的已知尸体记忆,由 ClawclawGoalStrategy 每次运行用中心 CorpseMemory 写入:尸体从出现一直存在到
113
+ * 跨 tick 的已知尸体记忆,由 OfficialGoalBehavior 每次运行用中心 CorpseMemory 写入:尸体从出现一直存在到
114
114
  * 开会才清空(会议恢复时清空)。是 `state.corpses`(仅当前视野)的严格超集,含已离开
115
115
  * 视野、之前看见过的尸体。策略应统一读它做尸体检测/接近/任务回避/死亡确认,而非只看 `state.corpses`。
116
116
  * 通过 hasKnownCorpse / nearestKnownCorpse / firstAvailableTask 的 avoidCorpses 参数消费。
117
117
  */
118
118
  knownCorpses?: CorpseInfo[];
119
119
  recentlyKilledTargets?: Map<string, number>;
120
- /** Strategy-registered modules. ClawclawGoalStrategy calls processEvents, afterDecide, onMeetingResume and onMapLoaded. */
120
+ /** Strategy-registered modules. OfficialGoalBehavior calls processEvents, afterDecide, onMeetingResume and onMapLoaded. */
121
121
  customModules?: CustomModule[];
122
122
  }
@@ -1,17 +1,25 @@
1
1
  import {
2
- ClawclawGoalStrategy,
3
- clawclawStrategySeatList,
4
- } from '../sdk/strategy-plugin/index.js';
2
+ type BehaviorDecision,
3
+ type BehaviorInput,
4
+ type BehaviorReadApi,
5
+ ClawclawBehavior,
6
+ } from '../sdk/behavior-plugin/index.js';
7
+ import {
8
+ OfficialGoalBehavior,
9
+ } from '../runtime/clawclaw/plugins/behavior/official-goal-behavior.js';
5
10
  import { GoalRootStrategy } from './goals/goal-root-strategy.js';
6
11
  import { WarriorShrimpTop } from './goals/warrior-shrimp-top.js';
12
+ import { strategySeatList } from './player-targets.js';
7
13
 
8
- export default class WarriorMemoryStrategy extends ClawclawGoalStrategy {
14
+ export default class WarriorMemoryStrategy extends ClawclawBehavior {
9
15
  static readonly manifest = {
16
+ apiVersion: 3,
10
17
  id: 'warrior-memory',
11
18
  name: '武士虾',
12
19
  description: '带刀虾·进阶版(武士虾/枪虾通用)。只对 huntTargets 指定的玩家出刀,其他非 trustedTargets 玩家只回避。发现尸体优先报警;无危险时优先紧急任务,否则做任务或巡逻。枪虾会尊重剩余出刀次数。',
13
- execution: 'parallel_analyze',
14
- controls: [
20
+ execution: 'serial',
21
+ produces: ['strategy_alert', 'robot_speak_rule'],
22
+ inputs: [
15
23
  {
16
24
  id: 'huntTargets',
17
25
  type: 'player_seats',
@@ -27,18 +35,20 @@ export default class WarriorMemoryStrategy extends ClawclawGoalStrategy {
27
35
  ],
28
36
  } as const;
29
37
 
30
- constructor(parameters: Readonly<Record<string, unknown>> = {}) {
31
- super(parameters, {
32
- id: 'warrior-memory',
33
- requiresTasks: true,
34
- routeEvidenceTargets: ['tasks'],
35
- create: (values) => {
36
- const huntTargets = clawclawStrategySeatList(values, 'huntTargets');
37
- const trustedTargets = clawclawStrategySeatList(values, 'trustedTargets');
38
- return new GoalRootStrategy('warrior-memory', () => new WarriorShrimpTop(huntTargets, trustedTargets), {
39
- resetOnMeetingResume: false,
40
- });
41
- },
42
- });
38
+ private readonly goal = new OfficialGoalBehavior({
39
+ id: 'warrior-memory',
40
+ requiresTasks: true,
41
+ routeEvidenceTargets: ['tasks'],
42
+ create: (values) => {
43
+ const huntTargets = strategySeatList(values, 'huntTargets');
44
+ const trustedTargets = strategySeatList(values, 'trustedTargets');
45
+ return new GoalRootStrategy('warrior-memory', () => new WarriorShrimpTop(huntTargets, trustedTargets), {
46
+ resetOnMeetingResume: false,
47
+ });
48
+ },
49
+ });
50
+
51
+ override decide(input: BehaviorInput, api: BehaviorReadApi): Promise<BehaviorDecision> {
52
+ return this.goal.decide(input, api);
43
53
  }
44
54
  }
@@ -1,111 +0,0 @@
1
- # Strategy Plugin、GameSync 与 Action 边界
2
-
3
- > 当前状态:Action、Game Query 和 Strategy 都由 `ccl game start` 的长进程统一装配。每个角色按用户配置选择默认策略;Agent 运行中只负责切换策略和更新该策略声明过的命名参数。
4
-
5
- 总的组件与 Event 归属见 [Runtime 组件职责与 Event 归属](./components-and-boundaries.md)。
6
-
7
- ## 唯一动态游戏事实链路
8
-
9
- ```text
10
- GameSync v2 WebSocket
11
- snapshot / update(state_delta + events[]) / resume
12
- |
13
- v
14
- WsClient 顺序校验、typed reducer、断线续传
15
- |
16
- v
17
- Source InputBatch(当前 State + Canonical Events)
18
- |
19
- v
20
- Runtime epoch -> StrategyFrame -> update() / compute() / analyze()
21
-
22
- Strategy ordered commit / compute proposal 或 update()/reduce() 中的 api.action.submit()
23
- |
24
- v
25
- Action Plugin -> HTTP Action(只返回提交确认)
26
- ```
27
-
28
- GameSync v2 是动态 State 和后端 Event 的唯一来源。HTTP 只用于提交 Action;HTTP 返回只表示请求是否被接受,不能作为第二条 State/Event 输入。公开 Strategy API 不提供后端 URL、凭据、HTTP 客户端或 WebSocket;但自定义策略与 CCL 同权限运行,不能把这个 API 边界理解成安全沙箱。
29
-
30
- `WsClient` 从 snapshot 建立基线,按 `seq` 合并 update,并在断线后用 `resume_seq` 恢复。恢复完成前 Source 不发布半恢复 State,Action 和 Strategy 也不会运行;恢复成功后再把同一水位的 State 与重放 Event 交给 Runtime。若后端只能返回新的 snapshot,CCL 会用它整体替换旧基线,而不会用历史 Event 猜一个“看起来完整”的 State。
31
-
32
- ## Strategy 在 Runtime 中的位置
33
-
34
- Strategy 是普通 `RuntimeEpochPlugin`,但不是每个 Runtime epoch 都执行决策:
35
-
36
- ```text
37
- Source InputBatch
38
- -> Action + DerivedEvent + GameQuery + Perception 完成本 epoch
39
- -> ClawclawStrategyPlugin
40
- -> 要求 stage=game、phase=wandering、game_snapshot=fresh
41
- -> 每个不同的后端 domain tick 可运行;同 tick revision 去重
42
- -> StrategyFrame@epoch
43
- -> 旧接口:同一实例有序 update() / applyControl()
44
- -> 无状态并行:fresh 实例 compute(),只返回 proposal
45
- -> Hybrid:fresh 实例 analyze(),持久实例有序 reduce()
46
- -> Strategy ordered commit 提交 Action/State/Event/cursor 和 Completion
47
- -> Mailbox 等下游插件
48
- ```
49
-
50
- 首个可执行游走 State 会立即调用;之后每个不同的 fresh wandering 后端 domain tick 都可运行。同一 tick 的多份 State revision 只运行一次。两次实际调用之间到达的 Canonical Event 由独立 cursor 累积,到下一次调用一并交付。会议、加载、结算、重连等待、只有 Event 而没有 fresh State 的边界都不调用策略实例或提交并行计算,也不会拿旧 State 伪造一帧。
51
-
52
- 若 Runtime 处理落后并跳过旧 epoch,策略不会补做可能产生过期 Action 的历史决策。插件记录 `strategy.catchup_gap`,在最新 fresh wandering State 上恢复;Event cursor 仍保留尚未消费的事件。一次 `update()` / `compute()` / `analyze()` / `reduce()` 超时、被追帧淘汰、主线程执行器失败或并行 Worker Thread 退出时,本 epoch 记为失败或 coalesced,不提交半批 State/Event/Action,也不推进该策略的 Event cursor。Runtime 默认最多保留 10 个在途或已完成待提交 epoch,分析即使乱序完成也只能逐 epoch 进入 commit/reduce。
53
-
54
- ## 策略实例与 Goal tree
55
-
56
- 第三方文件应从公开子路径导入 `ClawclawStrategy`、`ClawclawComputeStrategy`、`ClawclawHybridStrategy` 或 `ClawclawGoalStrategy`,并默认导出一个策略类。作者不自行创建循环或实例。
57
-
58
- `ClawclawStrategy` 是有状态串行兼容接口:类提供 `static manifest` 和 `update(frame, api)`,可选提供 `constructor(parameters)`、`reset(reason)`、`applyControl(update)` 与 `stop(reason)`。Owner 主线程直接 import 所选源码并创建一个持久实例;普通实例字段跨 `update()` 保留,同一个 segment 内的会议暂停和普通 WS 重连不会每 tick 重建实例。切换策略、segment 结束或 Runtime 关闭才结束该实例。
59
-
60
- `ClawclawComputeStrategy` 是显式无状态并行接口:manifest 还必须声明 `execution: 'parallel_compute'`,类实现 `compute(frame, game)`。生产运行时在策略启动阶段预热 2 个 Worker Threads;每个线程同时只计算一帧,每帧创建 fresh compute 实例并冻结参数,因此同步 CPU 密集计算可以跨线程并行。请求压力超过当前容量时逐步扩到最多 10 个线程,连续空闲 30 秒后回收到 2 个;完成顺序不作保证,但结果只能按 epoch 顺序提交,超过保留窗口的旧结果整批作废。策略只能返回可克隆的 State/Event/Action proposal,不能在计算阶段直接 Action。
61
-
62
- `ClawclawHybridStrategy` 是显式混合接口:manifest 声明 `execution: 'parallel_analyze'`,类分别实现 `analyze(frame, game)` 和 `reduce(frame, analysis, api)`。每帧 analyze 在自适应线程池中创建 fresh analyzer 实例,只能读取绑定本 epoch 的不可变输入和 Game Query,不能提交 Action 或保存跨帧状态;不同 epoch 最多由 10 个 Worker Threads 并发分析。reduce 使用 Owner 主线程上另一个唯一持久实例,并严格按 epoch 顺序运行;只有 reduce 可以修改 Goal/策略状态、调用 Action,以及返回最终 State/Event。reducer 侧 Game Query 被拒绝,因此所需 evidence 必须由 analyze 返回;当前 State/Event 则使用提交时重建的 frame。analysis 必须可 `structuredClone`。阶段屏障、策略切换、追帧或失败会让旧 analysis 在进入 reducer 前作废。
63
-
64
- hybrid manifest 可以声明 `controls`。控制在 ordered commit 只对持久 reducer 应用一次;接受后参数 generation 递增,旧 analyzer 池被关闭,旧 generation 的在途 analysis 全部作废。下一份 analyze 使用新参数。reducer 拒绝时保持原参数、Goal tree 和 analyzer generation。
65
-
66
- 20 个官方策略都直接继承 `ClawclawGoalStrategy` 并声明 hybrid。每帧 fresh analyzer 不创建 Goal tree,只有 Owner 主线程上的持久 reducer 在第一次实际归并时按需懒创建一次 Goal Strategy/Goal tree,之后跨 reduce 保留 Goal 实例状态,不是每帧重算整棵树。任务和地图资源读取放在并行 analyze,Goal 决策、Action ack、controls 与重复动作抑制留在 ordered reduce。自定义策略省略 execution 时仍走串行兼容接口。
67
-
68
- `StrategyFrame` 包含当前 epoch、session/segment、后端 tick、当前 fresh GameSync State、已完成依赖产生的 `upstreamStates`、尚未消费的 Event,以及本次调用的有效命名参数快照。并行线程中的 Game Query 也绑定到这个 epoch,不能读到后来到达的 State。由于多个 analyze 可以在前一个 epoch 提交前启动,计算阶段看到的待消费 Event 切片可能重叠;ordered reduce 会按提交时最新 cursor 为同一个 epoch 重建 frame,只把尚未消费的 Event 交给持久状态机,analysis 不能携带旧 State/Event 取代这份 frame。策略可返回已登记的 State/Event proposal;`parallel_compute` 还可返回 Action proposal。epoch 和生产插件 ID 由 Runtime 补齐。
69
-
70
- ## Agent 控制面
71
-
72
- Agent 对正在运行的策略只有两种控制:
73
-
74
- ```powershell
75
- ccl strategy <id>
76
- ccl strategy --control '{"parameterName": "value"}'
77
- ```
78
-
79
- `ccl strategy <id>` 只请求切换策略,没有位置参数 `args`。下一份可执行 fresh wandering State 到来时,插件先停止旧持久实例与并行线程池,再为所选策略创建对应执行器。若 Agent 未手动选择,角色分配后使用用户 `gameplay.json` 中该角色的默认策略。
80
-
81
- `--control` 只更新目标策略 `manifest.controls` 声明过的命名参数。插件为请求分配递增 revision;串行接口在下一次实际 `update()` 前把更新交给同一实例的 `applyControl()`,`parallel_compute` 冻结新的参数 generation,从下一份 `compute()` 生效并使旧 generation 的在途结果失效;`parallel_analyze` 在 reducer 接受后重启 analyzer generation 并丢弃旧分析。CLI 等待确认。切换策略、segment 结束或 Runtime 关闭会拒绝尚未应用的控制,避免把参数投给错误实例。
82
-
83
- ## 只读 CCL capability
84
-
85
- 动态 State/Event 已主动进入 `StrategyFrame`。只有按需数据通过受控 capability 查询,全部在本地 CCL 内完成:
86
-
87
- | Strategy API | CCL 数据来源 | 网络行为 |
88
- |---|---|---|
89
- | `api.game.getTasks()` | 最新 fresh CCL State 的 `you.tasks` | 策略不请求 HTTP;字段缺失时抛出 `authoritative_tasks_unavailable` |
90
- | `api.game.getMap()` | 随 npm 包发布的地图资源;玩家座位和任务取最新 CCL State | 策略不请求 HTTP;静态资源适合由策略实例缓存 |
91
- | `api.game.pathDistance(from, to)` | 随包的碰撞膨胀 walkability grid + 本地 A* | 不请求 HTTP;不可达返回 `null` |
92
-
93
- `getTasks()` 本身不会发 HTTP。Source 只把 GameSync `you.tasks` 写入 State,不轮询 `/map`,也不从增量任务 Event 猜完整列表。字段不可用时,`getTasks()` 抛出 `authoritative_tasks_unavailable`,而不是把缺失解释成空列表。官方 Goal 策略此时会把 `strategy.status.dataAvailability.tasks` 标为 `unavailable`,并继续执行巡逻、避人或猎杀等不依赖任务的分支;不会拿全任务点冒充自己的任务。`getMap()` 的静态部分包括房间多边形和全任务点;它不是动态 State 的替代品。策略应只在需要地图几何时查询并缓存,而不是每次更新重复拉取。
94
-
95
- 玩家分类和策略偏好全部通过 `manifest.controls` 的命名参数进入策略实例或并行计算参数快照。`player_seats` 使用 1-10 的 JSON 整数数组表示完整当前座位名单,不接受字符串座位号或玩家名;关联名单可由一条 `ccl strategy --control <JSON>` 原子更新。Goal tree 只在 effective parameters 实际变化时重建,普通 `update()` 复用同一实例和规划状态。
96
-
97
- ## Action
98
-
99
- Owner 主线程串行实例的 `api.action.submit()` 只接受龙虾杀适配层允许的结构化动作。`parallel_compute` 线程内 API 没有直接 Action 入口,只返回 `actions[]` proposal;即使第三方类覆盖 `update()` 尝试直接提交,线程内 API 也固定返回 `not_submitted`,不会产生后端 Action request。hybrid 的 analyze 只拿到只读 `game`,同样不能 Action;只有轮到 ordered commit 的 Owner 主线程 reduce 才拿到 `api.action`。宿主在进入 reduce 或提交 compute proposal 前重新校验策略/参数 generation,以及会议、死亡、断线、终局等 Action 屏障,再以 `{kind: 'strategy'}` 调用 `clawclaw.action` capability。Action Plugin 是唯一会提交后端 HTTP Action 的策略相关模块。
100
-
101
- 串行 update 和 hybrid reduce 的 Action response 作为本次有序提交的 ack 返回 Owner 主线程持久实例;`parallel_compute` 不在 compute 中等待 Action ack。真实结果同样只看后续 GameSync v2 State/Event。移动是否到达、任务是否完成、击杀是否生效,不能从 HTTP 接纳结果推断。内置 Goal 策略把动作坐标与 Agent 可读的 `BehaviorDecision.intent` 分开:状态只说房间、任务、追踪/巡逻/击杀等目的,不输出路径点或目标坐标。Agent 的 `ccl speak`、`ccl vote`、`ccl aside` 也经同一个 Action Plugin。
102
-
103
- ## 生命周期与信任边界
104
-
105
- `ccl game start` 是前台 Owner。Agent/launcher 消失、CCL 收到终止信号或 Runtime 正常关闭时,Owner 先禁止新 Action,再停止 Strategy Plugin、主线程持久实例和并行 Worker Thread 池。这个本地结束路径不等于后端退出;只有显式 `ccl game quit` 表达离开游戏。
106
-
107
- CCL 直接 import 所选策略源码,不经过独立执行进程或私有 IPC 层。串行 update 与 hybrid reduce 在 Owner 主线程运行,parallel compute/analyze 在生产自适应 Worker Thread 池中运行,每帧创建 fresh 计算实例。池从 2 个线程开始,按压力扩到最多 10 个,空闲后回收到 2 个;终止活动计算时只退役对应线程槽,并按当前需求决定是否补位,停止策略或 Owner 时关闭整个策略线程池。
108
-
109
- 自定义策略与 CCL 同权限运行,是受信任本地代码而不是安全沙箱。公开 Strategy API 不导出 `GameClient`、传输、SQLite 或 Runtime 私有对象,输入和结果也会经过克隆、冻结与校验;这些是正常 authoring/capability 契约。CCL 不承诺拦截 Node builtin、第三方包、动态 import、文件、网络、环境变量或自建线程/子进程,因此只能加载自己信任的源码。
110
-
111
- 无状态闭环示例 `runtime-task-demo` 位于 `src/runtime/clawclaw/plugins/strategy/examples/task-only-strategy.ts`。它使用 `parallel_compute`,从绑定到输入 epoch 的 GameSync `you.tasks` capability 读取任务,用本地 A* 选择最近任务,返回 Action proposal,并输出语义化 `strategy.status`。20 个官方 Goal hybrid 位于 `src/strategies/`,其 Goal tree 只存在于持久 reducer;公开接口见 [Strategy Plugin 开发指南](../自定义策略.md)。