@myclaw163/clawclaw-cli 0.7.16 → 0.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (335) hide show
  1. package/QUICKSTART_HERMES.md +1 -1
  2. package/QUICKSTART_OPENCLAW.md +3 -11
  3. package/QUICKSTART_OTHER.md +8 -8
  4. package/README.md +18 -9
  5. package/bin/clawclaw-channel.mjs +13 -0
  6. package/docs/configuration.md +86 -33
  7. package/docs/custom-modules/README.md +148 -0
  8. package/docs/custom-modules/api-reference.md +767 -0
  9. package/docs/custom-modules/behavior.md +318 -0
  10. package/docs/custom-modules/perception.md +305 -0
  11. package/docs/custom-modules/trigger.md +292 -0
  12. package/docs/desktop-event-push.md +6 -4
  13. package/docs/runtime/README.md +28 -10
  14. package/docs/runtime/agent-notifications.md +48 -29
  15. package/docs/runtime/behavior-runtime.md +139 -0
  16. package/docs/runtime/components-and-boundaries.md +89 -173
  17. package/docs/runtime/events-and-state.md +55 -66
  18. package/docs/runtime/official-perception-modules.md +17 -9
  19. package/docs/runtime/owner-lifecycle-and-observability.md +62 -39
  20. package/docs/runtime/perception-replay.md +6 -6
  21. package/docs/runtime/short-commands-and-capabilities.md +35 -37
  22. package/package.json +10 -7
  23. package/scripts/check-skill-command-surface.mjs +54 -10
  24. package/scripts/compare-perception-replays.test.ts +10 -10
  25. package/scripts/compare-perception-replays.ts +14 -10
  26. package/scripts/replay-perception.ts +3 -3
  27. package/scripts/watch-perception-events.test.ts +1 -1
  28. package/skills/clawclaw/SKILL.md +97 -59
  29. package/skills/clawclaw/references/BEHAVIORS.md +154 -0
  30. package/skills/clawclaw/references/CHANNELS.md +115 -0
  31. package/skills/clawclaw/references/CHATTERBOX.md +3 -2
  32. package/skills/clawclaw/references/COMMANDS.md +108 -58
  33. package/skills/clawclaw/references/GAME-MECHANICS.md +4 -3
  34. package/skills/clawclaw/references/HUB.md +27 -23
  35. package/skills/clawclaw/references/STREAM.md +18 -14
  36. package/skills/clawclaw/references/TACTICS.md +2 -2
  37. package/src/behaviors/official-finite/do-task.ts +141 -0
  38. package/src/behaviors/official-finite/evade.ts +78 -0
  39. package/src/behaviors/official-finite/find-player.ts +50 -0
  40. package/src/behaviors/official-finite/follow-player.ts +70 -0
  41. package/src/behaviors/official-finite/go-to.ts +69 -0
  42. package/src/behaviors/official-finite/hide-temporarily.ts +77 -0
  43. package/src/behaviors/official-finite/hold-position.ts +48 -0
  44. package/src/behaviors/official-finite/hunt-player.ts +47 -0
  45. package/src/behaviors/official-finite/index.test.ts +202 -0
  46. package/src/behaviors/official-finite/index.ts +47 -0
  47. package/src/behaviors/official-finite/inspect-corpse.ts +64 -0
  48. package/src/behaviors/official-finite/patrol-area.ts +80 -0
  49. package/src/behaviors/official-finite/report-corpse.ts +73 -0
  50. package/src/behaviors/official-finite/seek-kill-opportunity.ts +152 -0
  51. package/src/behaviors/official-finite/shared.ts +27 -0
  52. package/src/behaviors/official-finite/trigger-alarm.ts +53 -0
  53. package/src/channel/claude-channel-ipc-server.ts +295 -0
  54. package/src/channel/claude-channel-ipc.ts +152 -0
  55. package/src/channel/claude-channel-server.test.ts +202 -0
  56. package/src/channel/claude-channel-server.ts +221 -0
  57. package/src/cli.ts +4 -2
  58. package/src/commands/account.test.ts +17 -17
  59. package/src/commands/behavior.test.ts +158 -0
  60. package/src/commands/behavior.ts +443 -0
  61. package/src/commands/communication.test.ts +12 -0
  62. package/src/commands/communication.ts +6 -3
  63. package/src/commands/data.test.ts +1 -1
  64. package/src/commands/data.ts +1 -1
  65. package/src/commands/events-canonical-state.test.ts +221 -2
  66. package/src/commands/events.ts +205 -12
  67. package/src/commands/game/index.test.ts +172 -3
  68. package/src/commands/game/index.ts +69 -32
  69. package/src/commands/hub.test.ts +25 -14
  70. package/src/commands/hub.ts +15 -19
  71. package/src/commands/load.test.ts +228 -6
  72. package/src/commands/load.ts +102 -18
  73. package/src/commands/memory.ts +1 -1
  74. package/src/commands/peek.ts +1 -1
  75. package/src/commands/perception.test.ts +30 -1
  76. package/src/commands/perception.ts +15 -17
  77. package/src/commands/trigger.test.ts +140 -0
  78. package/src/commands/trigger.ts +314 -0
  79. package/src/lib/account-guidance.test.ts +4 -0
  80. package/src/lib/account-guidance.ts +1 -1
  81. package/src/lib/behavior-export.test.ts +282 -0
  82. package/src/lib/behavior-export.ts +514 -0
  83. package/src/lib/game-client.test.ts +4 -17
  84. package/src/lib/game-client.ts +1 -0
  85. package/src/lib/gameplay-config.test.ts +258 -37
  86. package/src/lib/gameplay-config.ts +175 -35
  87. package/src/lib/hub-install.test.ts +19 -41
  88. package/src/lib/hub-install.ts +10 -38
  89. package/src/lib/hub-reminder.ts +7 -9
  90. package/src/lib/init-command.ts +1 -1
  91. package/src/lib/official-resource-sync.test.ts +199 -0
  92. package/src/lib/official-resource-sync.ts +221 -0
  93. package/src/lib/perception-config.test.ts +9 -4
  94. package/src/lib/perception-config.ts +10 -13
  95. package/src/lib/perception-export.test.ts +145 -0
  96. package/src/lib/perception-export.ts +178 -0
  97. package/src/lib/trigger-config.test.ts +102 -0
  98. package/src/lib/trigger-config.ts +217 -0
  99. package/src/lib/user-data.test.ts +23 -6
  100. package/src/lib/user-data.ts +15 -123
  101. package/src/pipeline/canonical-event-presentation.test.ts +5 -5
  102. package/src/pipeline/canonical-event-presentation.ts +13 -5
  103. package/src/pipeline/event-format.test.ts +106 -3
  104. package/src/pipeline/event-format.ts +172 -4
  105. package/src/pipeline/event-hints.test.ts +57 -4
  106. package/src/pipeline/event-hints.ts +34 -8
  107. package/src/runtime/canonical-monitor.test.ts +2 -0
  108. package/src/runtime/canonical-monitor.ts +6 -2
  109. package/src/runtime/clawclaw/agent-event-policy.test.ts +23 -2
  110. package/src/runtime/clawclaw/agent-event-policy.ts +12 -5
  111. package/src/runtime/clawclaw/behavior-decision.test.ts +29 -0
  112. package/src/runtime/clawclaw/behavior-decision.ts +82 -0
  113. package/src/runtime/clawclaw/behavior-input-fields.test.ts +175 -0
  114. package/src/runtime/clawclaw/behavior-input-fields.ts +270 -0
  115. package/src/runtime/clawclaw/behavior-input.test.ts +151 -0
  116. package/src/runtime/clawclaw/behavior-input.ts +70 -0
  117. package/src/runtime/clawclaw/behavior-observation-memory.test.ts +59 -0
  118. package/src/runtime/clawclaw/behavior-observation-memory.ts +142 -0
  119. package/src/runtime/clawclaw/behavior-read-api.test.ts +123 -0
  120. package/src/runtime/clawclaw/behavior-read-api.ts +158 -0
  121. package/src/runtime/clawclaw/{plugins/perception/visual-state-projector.ts → observation-frame-projector.ts} +44 -25
  122. package/src/runtime/clawclaw/owner.test.ts +187 -0
  123. package/src/runtime/clawclaw/owner.ts +431 -69
  124. package/src/runtime/clawclaw/plugins/action/action-plugin.test.ts +304 -0
  125. package/src/runtime/clawclaw/plugins/action/action-plugin.ts +285 -41
  126. package/src/runtime/clawclaw/plugins/action/automated-action-normalization.ts +82 -0
  127. package/src/runtime/clawclaw/plugins/assembly.test.ts +135 -29
  128. package/src/runtime/clawclaw/plugins/assembly.ts +54 -28
  129. package/src/runtime/clawclaw/plugins/behavior/activation-manager.test.ts +180 -0
  130. package/src/runtime/clawclaw/plugins/behavior/activation-manager.ts +468 -0
  131. package/src/runtime/clawclaw/plugins/behavior/behavior-action.test.ts +40 -0
  132. package/src/runtime/clawclaw/plugins/behavior/behavior-action.ts +30 -0
  133. package/src/runtime/clawclaw/plugins/behavior/behavior-analysis-thread-host.ts +152 -0
  134. package/src/runtime/clawclaw/plugins/behavior/behavior-catalog.test.ts +156 -0
  135. package/src/runtime/clawclaw/plugins/behavior/behavior-catalog.ts +104 -0
  136. package/src/runtime/clawclaw/plugins/behavior/behavior-manifest.ts +173 -0
  137. package/src/runtime/clawclaw/plugins/behavior/behavior-module-loader.test.ts +182 -0
  138. package/src/runtime/clawclaw/plugins/behavior/behavior-module-loader.ts +223 -0
  139. package/src/runtime/clawclaw/plugins/behavior/behavior-normalization.ts +157 -0
  140. package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.test.ts +848 -0
  141. package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.ts +1347 -0
  142. package/src/runtime/clawclaw/plugins/behavior/behavior-runner.ts +212 -0
  143. package/src/runtime/clawclaw/plugins/behavior/behavior-source.test.ts +174 -0
  144. package/src/runtime/clawclaw/plugins/behavior/behavior-source.ts +621 -0
  145. package/src/runtime/clawclaw/plugins/behavior/control-driver.test.ts +195 -0
  146. package/src/runtime/clawclaw/plugins/behavior/control-driver.ts +180 -0
  147. package/src/runtime/clawclaw/plugins/behavior/index.ts +11 -0
  148. package/src/runtime/clawclaw/plugins/behavior/official-goal-behavior.ts +766 -0
  149. package/src/runtime/clawclaw/plugins/behavior/thread-behavior-executor.test.ts +283 -0
  150. package/src/runtime/clawclaw/plugins/{strategy/thread-strategy-executor.ts → behavior/thread-behavior-executor.ts} +109 -121
  151. package/src/runtime/clawclaw/plugins/behavior-input-source.test.ts +80 -0
  152. package/src/runtime/clawclaw/plugins/behavior-input-source.ts +247 -0
  153. package/src/runtime/clawclaw/plugins/{strategy → game-query}/context-capabilities.ts +1 -1
  154. package/src/runtime/clawclaw/plugins/game-query/game-query-plugin.test.ts +13 -10
  155. package/src/runtime/clawclaw/plugins/game-query/game-query-plugin.ts +26 -14
  156. package/src/runtime/clawclaw/plugins/game-query/index.ts +1 -0
  157. package/src/runtime/clawclaw/plugins/index.ts +3 -1
  158. package/src/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-adapter.test.ts +239 -0
  159. package/src/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-adapter.ts +100 -0
  160. package/src/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-socket.ts +346 -0
  161. package/src/runtime/clawclaw/plugins/mailbox/agent-mailbox-coordinator.test.ts +230 -12
  162. package/src/runtime/clawclaw/plugins/mailbox/agent-mailbox-coordinator.ts +118 -90
  163. package/src/runtime/clawclaw/plugins/mailbox/consumer-ids.ts +5 -0
  164. package/src/runtime/clawclaw/plugins/mailbox/index.ts +3 -0
  165. package/src/runtime/clawclaw/plugins/mailbox/mailbox-agent-event-batch.test.ts +1 -1
  166. package/src/runtime/clawclaw/plugins/mailbox/mailbox-event-batch-delivery.ts +4 -0
  167. package/src/runtime/clawclaw/plugins/mailbox/mailbox-plugin.test.ts +87 -0
  168. package/src/runtime/clawclaw/plugins/mailbox/mailbox-plugin.ts +70 -12
  169. package/src/runtime/clawclaw/plugins/mailbox/mailbox-presentation.ts +94 -11
  170. package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.test.ts +1229 -345
  171. package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.ts +479 -35
  172. package/src/runtime/clawclaw/plugins/perception/contracts.ts +4 -3
  173. package/src/runtime/clawclaw/plugins/perception/index.ts +1 -1
  174. package/src/runtime/clawclaw/plugins/perception/module-runner.test.ts +23 -13
  175. package/src/runtime/clawclaw/plugins/perception/module-runner.ts +11 -9
  176. package/src/runtime/clawclaw/plugins/perception/modules/co-movement-module.ts +39 -38
  177. package/src/runtime/clawclaw/plugins/perception/modules/corpse-visibility-module.test.ts +92 -0
  178. package/src/runtime/clawclaw/plugins/perception/modules/corpse-visibility-module.ts +248 -0
  179. package/src/runtime/clawclaw/plugins/perception/modules/follow-module.ts +39 -37
  180. package/src/runtime/clawclaw/plugins/perception/modules/index.ts +1 -0
  181. package/src/runtime/clawclaw/plugins/perception/modules/motion-module.test.ts +22 -21
  182. package/src/runtime/clawclaw/plugins/perception/modules/motion-module.ts +15 -9
  183. package/src/runtime/clawclaw/plugins/perception/modules/parallel-module-test-helpers.ts +3 -3
  184. package/src/runtime/clawclaw/plugins/perception/modules/relation-stability.test.ts +33 -18
  185. package/src/runtime/clawclaw/plugins/perception/modules/route-module.test.ts +6 -7
  186. package/src/runtime/clawclaw/plugins/perception/modules/route-module.ts +22 -16
  187. package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.test.ts +6 -7
  188. package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.ts +18 -12
  189. package/src/runtime/clawclaw/plugins/perception/modules/stop-module.test.ts +14 -10
  190. package/src/runtime/clawclaw/plugins/perception/modules/stop-module.ts +20 -14
  191. package/src/runtime/clawclaw/plugins/perception/modules/temporal-evidence.test.ts +5 -6
  192. package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.test.ts +5 -6
  193. package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.ts +49 -34
  194. package/src/runtime/clawclaw/plugins/perception/official-module-ids.ts +1 -0
  195. package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-pool.test.ts +126 -20
  196. package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-pool.ts +24 -3
  197. package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-worker.ts +59 -46
  198. package/src/runtime/clawclaw/plugins/perception/perception-module-loader.ts +27 -5
  199. package/src/runtime/clawclaw/plugins/perception/perception-plugin.test.ts +381 -49
  200. package/src/runtime/clawclaw/plugins/perception/perception-plugin.ts +267 -245
  201. package/src/runtime/clawclaw/plugins/perception/perception-source.test.ts +98 -0
  202. package/src/runtime/clawclaw/plugins/perception/perception-source.ts +89 -16
  203. package/src/runtime/clawclaw/plugins/perception/perception-test-fixtures.ts +34 -0
  204. package/src/runtime/clawclaw/plugins/perception/replay.test.ts +27 -15
  205. package/src/runtime/clawclaw/plugins/perception/replay.ts +10 -5
  206. package/src/runtime/clawclaw/plugins/perception/shared/math.ts +1 -107
  207. package/src/runtime/clawclaw/plugins/perception/spatial-facts.ts +7 -10
  208. package/src/runtime/clawclaw/plugins/plugin-api-version.ts +112 -0
  209. package/src/runtime/clawclaw/plugins/runtime-plugins.test.ts +388 -559
  210. package/src/runtime/clawclaw/plugins/source/player-change-tracker.test.ts +56 -5
  211. package/src/runtime/clawclaw/plugins/source/player-change-tracker.ts +135 -26
  212. package/src/runtime/clawclaw/plugins/source/source-plugin.test.ts +249 -16
  213. package/src/runtime/clawclaw/plugins/source/source-plugin.ts +99 -2
  214. package/src/runtime/clawclaw/plugins/source/task-change-tracker.test.ts +212 -0
  215. package/src/runtime/clawclaw/plugins/source/task-change-tracker.ts +259 -0
  216. package/src/runtime/clawclaw/plugins/trigger/contracts.ts +97 -0
  217. package/src/runtime/clawclaw/plugins/trigger/index.ts +4 -0
  218. package/src/runtime/clawclaw/plugins/trigger/trigger-module-loader.ts +118 -0
  219. package/src/runtime/clawclaw/plugins/trigger/trigger-plugin.test.ts +548 -0
  220. package/src/runtime/clawclaw/plugins/trigger/trigger-plugin.ts +655 -0
  221. package/src/runtime/clawclaw/plugins/trigger/trigger-source.test.ts +169 -0
  222. package/src/runtime/clawclaw/plugins/trigger/trigger-source.ts +457 -0
  223. package/src/runtime/clawclaw/runtime.ts +8 -0
  224. package/src/runtime/clawclaw/spatial-api.ts +76 -0
  225. package/src/runtime/clawclaw-event-catalog.test.ts +46 -1
  226. package/src/runtime/clawclaw-event-catalog.ts +40 -3
  227. package/src/runtime/framework/capability-registry.test.ts +196 -55
  228. package/src/runtime/framework/capability-registry.ts +99 -17
  229. package/src/runtime/framework/contracts.ts +30 -4
  230. package/src/runtime/framework/control/control-scheduler.ts +13 -5
  231. package/src/runtime/framework/control/types.ts +11 -4
  232. package/src/runtime/framework/control-coordinator.test.ts +95 -80
  233. package/src/runtime/framework/events/event-delivery-service.ts +4 -2
  234. package/src/runtime/framework/events/event-ingress.test.ts +25 -0
  235. package/src/runtime/framework/events/event-ingress.ts +2 -1
  236. package/src/runtime/framework/events/event-repository.ts +24 -2
  237. package/src/runtime/framework/events/mailbox-event-repositories.test.ts +124 -8
  238. package/src/runtime/framework/events/memory-event-repository.ts +92 -28
  239. package/src/runtime/framework/events/sqlite-event-repository.test.ts +604 -2
  240. package/src/runtime/framework/events/sqlite-event-repository.ts +531 -21
  241. package/src/runtime/framework/events/types.ts +24 -8
  242. package/src/runtime/framework/modules/runtime-module-loader-hooks.mjs +38 -1
  243. package/src/runtime/framework/modules/runtime-module-loader.test.ts +233 -7
  244. package/src/runtime/framework/modules/runtime-module-loader.ts +69 -4
  245. package/src/runtime/framework/plugins/contracts.ts +12 -18
  246. package/src/runtime/framework/plugins/runtime-plugin-scheduler.test.ts +81 -71
  247. package/src/runtime/framework/plugins/runtime-plugin-scheduler.ts +38 -20
  248. package/src/runtime/framework/runtime.ts +20 -23
  249. package/src/runtime/host-monitor-rate-gate.test.ts +73 -0
  250. package/src/runtime/host-monitor-rate-gate.ts +123 -0
  251. package/src/runtime/mailbox-host-relay.test.ts +45 -0
  252. package/src/runtime/mailbox-host-relay.ts +25 -0
  253. package/src/runtime/observability/factory.ts +4 -4
  254. package/src/runtime/observability/observability.test.ts +25 -3
  255. package/src/runtime/observability/reporter.ts +1 -1
  256. package/src/runtime/observability/types.ts +2 -2
  257. package/src/runtime/owner-control.ts +10 -2
  258. package/src/runtime/runtime-logger.test.ts +1 -1
  259. package/src/runtime/runtime-logger.ts +4 -6
  260. package/src/runtime/runtime.test.ts +88 -22
  261. package/src/sdk/action.ts +2 -2
  262. package/src/sdk/behavior-plugin/index.test.ts +74 -0
  263. package/src/sdk/behavior-plugin/index.ts +335 -0
  264. package/src/sdk/behavior-toolkit/corpse-search.ts +87 -0
  265. package/src/sdk/behavior-toolkit/escape.ts +40 -0
  266. package/src/sdk/behavior-toolkit/index.ts +7 -0
  267. package/src/sdk/behavior-toolkit/kill-flow.ts +299 -0
  268. package/src/sdk/behavior-toolkit/model.ts +263 -0
  269. package/src/sdk/behavior-toolkit/move-gate.ts +52 -0
  270. package/src/sdk/behavior-toolkit/patrol.ts +53 -0
  271. package/src/sdk/behavior-toolkit/search.ts +102 -0
  272. package/src/sdk/index.test.ts +45 -0
  273. package/src/sdk/index.ts +67 -73
  274. package/src/sdk/module-input/index.test.ts +49 -0
  275. package/src/sdk/module-input/index.ts +229 -0
  276. package/src/sdk/perception-plugin/index.test.ts +2 -2
  277. package/src/sdk/perception-plugin/index.ts +51 -142
  278. package/src/sdk/perception-plugin/math.ts +107 -0
  279. package/src/sdk/trigger-plugin/index.test.ts +41 -0
  280. package/src/sdk/trigger-plugin/index.ts +128 -0
  281. package/src/strategies/avoid-lone.ts +21 -10
  282. package/src/strategies/avoid-players.ts +26 -16
  283. package/src/strategies/corpse-patrol.ts +25 -14
  284. package/src/strategies/crab-sabotage.ts +20 -9
  285. package/src/strategies/find-player.ts +33 -21
  286. package/src/strategies/game-utils.ts +1 -1
  287. package/src/strategies/goals/crab-sabotage-top.test.ts +145 -0
  288. package/src/strategies/goals/crab-sabotage-top.ts +32 -69
  289. package/src/strategies/hide.ts +25 -15
  290. package/src/strategies/kill-frenzy.ts +21 -10
  291. package/src/strategies/kill-lone.ts +27 -17
  292. package/src/strategies/kill-target.ts +33 -22
  293. package/src/strategies/lone-kill-task.ts +20 -9
  294. package/src/strategies/move-room.ts +29 -18
  295. package/src/strategies/official-long-behavior.test.ts +89 -0
  296. package/src/strategies/paradise-fish.ts +29 -18
  297. package/src/strategies/pathfind/astar-path.test.ts +127 -2
  298. package/src/strategies/pathfind/astar-path.ts +136 -26
  299. package/src/strategies/patrol.ts +21 -10
  300. package/src/strategies/player-targets.test.ts +10 -0
  301. package/src/strategies/player-targets.ts +13 -0
  302. package/src/strategies/report-patrol.ts +21 -10
  303. package/src/strategies/shrimp-memory.ts +30 -19
  304. package/src/strategies/social-task.ts +34 -23
  305. package/src/strategies/task-kill-report.ts +33 -22
  306. package/src/strategies/task-only.test.ts +99 -85
  307. package/src/strategies/task-only.ts +23 -12
  308. package/src/strategies/task-report.ts +25 -14
  309. package/src/strategies/types.ts +8 -8
  310. package/src/strategies/warrior-memory.ts +29 -19
  311. package/docs/runtime/strategy-runtime.md +0 -111
  312. package/docs//350/207/252/345/256/232/344/271/211/346/204/237/347/237/245.md +0 -502
  313. package/docs//350/207/252/345/256/232/344/271/211/347/255/226/347/225/245.md +0 -395
  314. package/skills/clawclaw/references/STRATEGIES.md +0 -76
  315. package/src/commands/strategy.test.ts +0 -209
  316. package/src/commands/strategy.ts +0 -242
  317. package/src/lib/strategy-export.test.ts +0 -406
  318. package/src/lib/strategy-export.ts +0 -381
  319. package/src/runtime/clawclaw/plugins/perception/official-modules.ts +0 -31
  320. package/src/runtime/clawclaw/plugins/strategy/examples/task-only-strategy.test.ts +0 -177
  321. package/src/runtime/clawclaw/plugins/strategy/examples/task-only-strategy.ts +0 -191
  322. package/src/runtime/clawclaw/plugins/strategy/index.ts +0 -8
  323. package/src/runtime/clawclaw/plugins/strategy/local-strategy-executor.ts +0 -412
  324. package/src/runtime/clawclaw/plugins/strategy/strategy-action.ts +0 -80
  325. package/src/runtime/clawclaw/plugins/strategy/strategy-analysis-thread-host.ts +0 -183
  326. package/src/runtime/clawclaw/plugins/strategy/strategy-executor-types.ts +0 -29
  327. package/src/runtime/clawclaw/plugins/strategy/strategy-executor.test.ts +0 -693
  328. package/src/runtime/clawclaw/plugins/strategy/strategy-game-api.ts +0 -57
  329. package/src/runtime/clawclaw/plugins/strategy/strategy-module-loader.ts +0 -168
  330. package/src/runtime/clawclaw/plugins/strategy/strategy-plugin.test.ts +0 -2175
  331. package/src/runtime/clawclaw/plugins/strategy/strategy-plugin.ts +0 -1774
  332. package/src/runtime/clawclaw/plugins/strategy/strategy-source.test.ts +0 -153
  333. package/src/runtime/clawclaw/plugins/strategy/strategy-source.ts +0 -443
  334. package/src/sdk/strategy-plugin/index.test.ts +0 -958
  335. package/src/sdk/strategy-plugin/index.ts +0 -1350
@@ -1,153 +0,0 @@
1
- import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
2
- import { tmpdir } from 'node:os';
3
- import { join } from 'node:path';
4
- import { afterEach, describe, expect, it } from 'vitest';
5
- import {
6
- readGameplayConfig,
7
- updateGameplayConfig,
8
- } from '../../../../lib/gameplay-config.js';
9
- import { syncOfficialStrategies } from '../../../../lib/strategy-export.js';
10
- import { getUserDataStrategiesDir } from '../../../../lib/user-data.js';
11
- import {
12
- listClawclawStrategySources,
13
- resolveDefaultClawclawStrategies,
14
- } from './strategy-source.js';
15
-
16
- const workspaces: string[] = [];
17
- const originalWorkspace = process.env.CLAWCLAW_WORKSPACE_DIR;
18
-
19
- afterEach(() => {
20
- for (const workspace of workspaces.splice(0)) {
21
- rmSync(workspace, { recursive: true, force: true });
22
- }
23
- if (originalWorkspace === undefined) delete process.env.CLAWCLAW_WORKSPACE_DIR;
24
- else process.env.CLAWCLAW_WORKSPACE_DIR = originalWorkspace;
25
- });
26
-
27
- async function workspace(): Promise<string> {
28
- const path = mkdtempSync(join(tmpdir(), 'ccl-default-strategy-'));
29
- workspaces.push(path);
30
- process.env.CLAWCLAW_WORKSPACE_DIR = path;
31
- await syncOfficialStrategies();
32
- return path;
33
- }
34
-
35
- describe('default strategy resolution', () => {
36
- it('resolves every configured role from the installed source catalog', async () => {
37
- const path = await workspace();
38
- expect(Object.keys(resolveDefaultClawclawStrategies(path)))
39
- .toEqual(Object.keys(readGameplayConfig(path).default_strategies));
40
- expect(listClawclawStrategySources(path).find(source => source.id === 'task-only'))
41
- .toMatchObject({ execution: 'parallel_analyze' });
42
- expect(listClawclawStrategySources(path).find(source => source.id === 'runtime-task-demo'))
43
- .toMatchObject({
44
- name: 'Runtime task demo',
45
- localizations: {
46
- 'zh-CN': {
47
- name: 'Runtime 任务演示',
48
- description: '向新进入视野的玩家打招呼,并按本地 A* 路径距离完成最近任务。',
49
- },
50
- },
51
- });
52
- });
53
-
54
- it('rejects a disabled default while ignoring unrelated stale disabled ids', async () => {
55
- const path = await workspace();
56
- updateGameplayConfig((config) => {
57
- config.disabled_strategies = ['removed-strategy'];
58
- }, path);
59
- expect(() => resolveDefaultClawclawStrategies(path)).not.toThrow();
60
-
61
- updateGameplayConfig((config) => {
62
- config.disabled_strategies.push('task-report');
63
- }, path);
64
- expect(() => resolveDefaultClawclawStrategies(path)).toThrow(
65
- "Default strategy 'task-report' for role 'shrimp_generic' is disabled",
66
- );
67
- });
68
-
69
- it('rejects a default whose source is not installed', async () => {
70
- const path = await workspace();
71
- updateGameplayConfig((config) => {
72
- config.default_strategies.neutral_octopus = 'removed-strategy';
73
- }, path);
74
- expect(() => resolveDefaultClawclawStrategies(path)).toThrow(
75
- "Default strategy 'removed-strategy' for role 'neutral_octopus' is not installed",
76
- );
77
- });
78
-
79
- it('rejects a compute Strategy that omits its parallel execution declaration during discovery', async () => {
80
- const path = await workspace();
81
- writeFileSync(join(getUserDataStrategiesDir(path), 'invalid-compute.ts'), `
82
- import { ClawclawComputeStrategy } from '@myclaw163/clawclaw-cli/strategy-plugin';
83
- export default class InvalidCompute extends ClawclawComputeStrategy {
84
- static manifest = {
85
- id: 'invalid-compute',
86
- name: 'Invalid compute',
87
- description: 'Missing execution declaration.',
88
- };
89
- compute() { return {}; }
90
- }
91
- `, 'utf8');
92
-
93
- expect(() => listClawclawStrategySources(path)).toThrow(
94
- "Strategy 'invalid-compute' extends ClawclawComputeStrategy and must declare manifest.execution: 'parallel_compute'.",
95
- );
96
- });
97
-
98
- it('rejects a serial Strategy that falsely declares parallel execution during discovery', async () => {
99
- const path = await workspace();
100
- writeFileSync(join(getUserDataStrategiesDir(path), 'invalid-serial.ts'), `
101
- import { ClawclawStrategy } from '@myclaw163/clawclaw-cli/strategy-plugin';
102
- export default class InvalidSerial extends ClawclawStrategy {
103
- static manifest = {
104
- id: 'invalid-serial',
105
- name: 'Invalid serial',
106
- description: 'Claims parallel execution with mutable state.',
107
- execution: 'parallel_compute',
108
- };
109
- update() { return {}; }
110
- }
111
- `, 'utf8');
112
-
113
- expect(() => listClawclawStrategySources(path)).toThrow(
114
- "Strategy 'invalid-serial' declares manifest.execution: 'parallel_compute' but must extend ClawclawComputeStrategy.",
115
- );
116
- });
117
-
118
- it('discovers controls on a hybrid strategy for the ordered parameter barrier', async () => {
119
- const path = await workspace();
120
- writeFileSync(join(getUserDataStrategiesDir(path), 'invalid-hybrid-controls.ts'), `
121
- import { ClawclawHybridStrategy } from '@myclaw163/clawclaw-cli/strategy-plugin';
122
- export default class InvalidHybridControls extends ClawclawHybridStrategy {
123
- static manifest = {
124
- id: 'invalid-hybrid-controls',
125
- name: 'Invalid hybrid controls',
126
- description: 'Controls would split analyzer and reducer generations.',
127
- localizations: {
128
- 'zh-CN': {
129
- name: '混合策略控制测试',
130
- description: '验证分析器和归约器的参数屏障。',
131
- },
132
- },
133
- execution: 'parallel_analyze',
134
- controls: [{ id: 'target', type: 'string', description: 'Target.' }],
135
- };
136
- analyze() { return {}; }
137
- reduce() { return {}; }
138
- }
139
- `, 'utf8');
140
-
141
- expect(listClawclawStrategySources(path)).toContainEqual(expect.objectContaining({
142
- id: 'invalid-hybrid-controls',
143
- execution: 'parallel_analyze',
144
- controls: [{ id: 'target', type: 'string', description: 'Target.' }],
145
- localizations: {
146
- 'zh-CN': {
147
- name: '混合策略控制测试',
148
- description: '验证分析器和归约器的参数屏障。',
149
- },
150
- },
151
- }));
152
- });
153
- });
@@ -1,443 +0,0 @@
1
- import {
2
- existsSync,
3
- readFileSync,
4
- readdirSync,
5
- realpathSync,
6
- } from 'node:fs';
7
- import {
8
- dirname,
9
- isAbsolute,
10
- join,
11
- relative,
12
- resolve,
13
- } from 'node:path';
14
- import { fileURLToPath } from 'node:url';
15
- import { getWorkspaceDir } from '../../../../lib/init-command.js';
16
- import {
17
- CLAWCLAW_ROLE_IDS,
18
- readGameplayConfig,
19
- type ClawclawRoleId,
20
- } from '../../../../lib/gameplay-config.js';
21
- import {
22
- ensureUserDataLayout,
23
- getUserDataStrategiesDir,
24
- } from '../../../../lib/user-data.js';
25
- import type { StrategySource } from './strategy-executor-types.js';
26
- import type {
27
- ClawclawResourceLocalizations,
28
- StrategyControlSpec,
29
- } from '../../../../sdk/strategy-plugin/index.js';
30
-
31
- export const CLAWCLAW_TASK_ONLY_DEMO_STRATEGY_ID = 'runtime-task-demo';
32
-
33
- const HERE = dirname(fileURLToPath(import.meta.url));
34
- const DEMO_SOURCE = realpathSync(resolve(HERE, 'examples/task-only-strategy.ts'));
35
- const MAX_STRATEGY_FILES = 512;
36
- const MAX_STRATEGY_SOURCE_BYTES = 2 * 1024 * 1024;
37
- const SAFE_IMPORT = /(?:@myclaw163\/clawclaw-cli|clawclaw-cli)\/strategy-plugin/;
38
- const DEFAULT_STRATEGY_CLASS = /export\s+default\s+class(?:\s+[A-Za-z_$][\w$]*)?\s+extends\s+(ClawclawStrategy|ClawclawGoalStrategy|ClawclawComputeStrategy|ClawclawHybridStrategy)(?:<[\s\S]{0,4000}?>)?\s*\{/;
39
- const STATIC_MANIFEST = /\bstatic\s+(?:readonly\s+)?manifest\s*=\s*\{/;
40
-
41
- class StrategySourceValidationError extends Error {
42
- constructor(message: string) {
43
- super(message);
44
- this.name = 'StrategySourceValidationError';
45
- }
46
- }
47
-
48
- export interface ResolvedClawclawStrategySource extends StrategySource {
49
- readonly name: string;
50
- readonly description: string;
51
- readonly controls?: readonly StrategyControlSpec[];
52
- }
53
-
54
- function demoSource(): ResolvedClawclawStrategySource {
55
- const source = parseClassStrategy(DEMO_SOURCE, dirname(DEMO_SOURCE));
56
- if (!source) throw new Error('Bundled Runtime task demo strategy manifest is invalid.');
57
- return source;
58
- }
59
-
60
- function isPathInside(root: string, candidate: string): boolean {
61
- const child = relative(root, candidate);
62
- return child === '' || (!child.startsWith('..') && !isAbsolute(child));
63
- }
64
-
65
- function decodeEscapedString(raw: string): string | null {
66
- let result = '';
67
- for (let index = 0; index < raw.length; index += 1) {
68
- const char = raw[index];
69
- if (char !== '\\') {
70
- result += char;
71
- continue;
72
- }
73
- index += 1;
74
- if (index >= raw.length) return null;
75
- const escaped = raw[index];
76
- if (escaped === 'n') result += '\n';
77
- else if (escaped === 'r') result += '\r';
78
- else if (escaped === 't') result += '\t';
79
- else if (escaped === 'b') result += '\b';
80
- else if (escaped === 'f') result += '\f';
81
- else if (escaped === 'v') result += '\v';
82
- else if (escaped === '0') result += '\0';
83
- else if (escaped === '\n') continue;
84
- else if (escaped === '\r') {
85
- if (raw[index + 1] === '\n') index += 1;
86
- } else if (escaped === 'x') {
87
- const hex = raw.slice(index + 1, index + 3);
88
- if (!/^[0-9a-f]{2}$/i.test(hex)) return null;
89
- result += String.fromCharCode(Number.parseInt(hex, 16));
90
- index += 2;
91
- } else if (escaped === 'u') {
92
- const hex = raw.slice(index + 1, index + 5);
93
- if (!/^[0-9a-f]{4}$/i.test(hex)) return null;
94
- result += String.fromCharCode(Number.parseInt(hex, 16));
95
- index += 4;
96
- } else {
97
- result += escaped;
98
- }
99
- }
100
- return result;
101
- }
102
-
103
- function literalProperty(source: string, property: string): string | null {
104
- const match = new RegExp(`\\b${property}\\s*:\\s*([\"'\x60])`, 'm').exec(source);
105
- if (!match) return null;
106
- const quote = match[1];
107
- const start = match.index + match[0].length;
108
- let escaped = false;
109
- for (let index = start; index < source.length; index += 1) {
110
- const char = source[index];
111
- if (escaped) {
112
- escaped = false;
113
- continue;
114
- }
115
- if (char === '\\') {
116
- escaped = true;
117
- continue;
118
- }
119
- if (char !== quote) continue;
120
- const raw = source.slice(start, index);
121
- if (quote === '`' && raw.includes('${')) return null;
122
- let next = index + 1;
123
- while (/\s/.test(source[next] ?? '')) next += 1;
124
- if (source[next] !== ',' && source[next] !== '}') return null;
125
- return decodeEscapedString(raw);
126
- }
127
- return null;
128
- }
129
-
130
- function balancedSection(
131
- source: string,
132
- openIndex: number,
133
- open: '{' | '[',
134
- close: '}' | ']',
135
- ): string | null {
136
- let depth = 0;
137
- let quote: "'" | '"' | '`' | undefined;
138
- let escaped = false;
139
- let lineComment = false;
140
- let blockComment = false;
141
- for (let index = openIndex; index < source.length; index += 1) {
142
- const char = source[index];
143
- const next = source[index + 1];
144
- if (lineComment) {
145
- if (char === '\n' || char === '\r') lineComment = false;
146
- continue;
147
- }
148
- if (blockComment) {
149
- if (char === '*' && next === '/') {
150
- blockComment = false;
151
- index += 1;
152
- }
153
- continue;
154
- }
155
- if (quote) {
156
- if (escaped) {
157
- escaped = false;
158
- } else if (char === '\\') {
159
- escaped = true;
160
- } else if (char === quote) {
161
- quote = undefined;
162
- }
163
- continue;
164
- }
165
- if (char === '/' && next === '/') {
166
- lineComment = true;
167
- index += 1;
168
- continue;
169
- }
170
- if (char === '/' && next === '*') {
171
- blockComment = true;
172
- index += 1;
173
- continue;
174
- }
175
- if (char === "'" || char === '"' || char === '`') {
176
- quote = char;
177
- continue;
178
- }
179
- if (char === open) depth += 1;
180
- if (char !== close) continue;
181
- depth -= 1;
182
- if (depth === 0) return source.slice(openIndex, index + 1);
183
- if (depth < 0) return null;
184
- }
185
- return null;
186
- }
187
-
188
- function balancedBlock(source: string, openBrace: number): string | null {
189
- return balancedSection(source, openBrace, '{', '}');
190
- }
191
-
192
- function balancedArray(source: string, openBracket: number): string | null {
193
- return balancedSection(source, openBracket, '[', ']');
194
- }
195
-
196
- function stringArrayProperty(source: string, property: string): string[] | undefined {
197
- const marker = new RegExp(`\\b${property}\\s*:\\s*\\[`, 'm').exec(source);
198
- if (!marker) return undefined;
199
- const open = marker.index + marker[0].lastIndexOf('[');
200
- const array = balancedArray(source, open);
201
- if (!array) return undefined;
202
- const result: string[] = [];
203
- const pattern = /(["'])(?:\\.|(?!\1)[^\\])*\1/g;
204
- for (const match of array.matchAll(pattern)) {
205
- const decoded = decodeEscapedString(match[0].slice(1, -1));
206
- if (decoded !== null) result.push(decoded);
207
- }
208
- return result;
209
- }
210
-
211
- function defaultProperty(source: string): unknown {
212
- const marker = /\bdefault\s*:\s*/m.exec(source);
213
- if (!marker) return undefined;
214
- const tail = source.slice(marker.index + marker[0].length).trimStart();
215
- if (tail.startsWith('[]')) return [];
216
- if (tail.startsWith('true')) return true;
217
- if (tail.startsWith('false')) return false;
218
- const string = literalProperty(`value: ${tail}`, 'value');
219
- if (string !== null) return string;
220
- const number = /^-?\d+(?:\.\d+)?/.exec(tail);
221
- return number ? Number(number[0]) : undefined;
222
- }
223
-
224
- function parseControlSpecs(classBody: string): StrategyControlSpec[] | undefined {
225
- const marker = /\bcontrols\s*:\s*\[/m.exec(classBody);
226
- if (!marker) return undefined;
227
- const open = marker.index + marker[0].lastIndexOf('[');
228
- const array = balancedArray(classBody, open);
229
- if (!array) return undefined;
230
- const controls: StrategyControlSpec[] = [];
231
- for (let index = 1; index < array.length - 1; index += 1) {
232
- if (array[index] !== '{') continue;
233
- const block = balancedBlock(array, index);
234
- if (!block) return undefined;
235
- index += block.length - 1;
236
- const id = literalProperty(block, 'id');
237
- const type = literalProperty(block, 'type') as StrategyControlSpec['type'] | null;
238
- const description = literalProperty(block, 'description');
239
- if (!id || !type || !description) continue;
240
- const values = stringArrayProperty(block, 'values');
241
- const defaultValue = defaultProperty(block);
242
- controls.push({
243
- id,
244
- type,
245
- description,
246
- ...(values === undefined ? {} : { values }),
247
- ...(defaultValue === undefined ? {} : { default: defaultValue }),
248
- });
249
- }
250
- return controls;
251
- }
252
-
253
- function literalLocalizations(
254
- source: string,
255
- ): ClawclawResourceLocalizations | null | undefined {
256
- const property = /\blocalizations\s*:\s*\{/m.exec(source);
257
- if (!property) return undefined;
258
- const open = property.index + property[0].lastIndexOf('{');
259
- const block = balancedBlock(source, open);
260
- if (!block) return null;
261
- const values: Record<string, { name: string; description: string }> = {};
262
- const entry = /(["'\x60])((?:\\.|(?!\1)[\s\S])*)\1\s*:\s*\{/g;
263
- let cursor = 1;
264
- let match: RegExpExecArray | null;
265
- while ((match = entry.exec(block)) !== null) {
266
- if (block.slice(cursor, match.index).replace(/[\s,]/g, '')) return null;
267
- if (match[1] === '`' && match[2].includes('${')) return null;
268
- const locale = decodeEscapedString(match[2])?.trim();
269
- const entryOpen = match.index + match[0].lastIndexOf('{');
270
- const entryBlock = balancedBlock(block, entryOpen);
271
- if (!locale || !entryBlock || values[locale]) return null;
272
- const name = literalProperty(entryBlock, 'name')?.trim();
273
- const description = literalProperty(entryBlock, 'description')?.trim();
274
- if (!name || !description) return null;
275
- values[locale] = { name, description };
276
- cursor = entryOpen + entryBlock.length;
277
- entry.lastIndex = cursor;
278
- }
279
- if (block.slice(cursor, -1).replace(/[\s,]/g, '')) return null;
280
- return values;
281
- }
282
-
283
- function parseClassStrategy(
284
- sourcePath: string,
285
- strategiesRoot: string,
286
- ): ResolvedClawclawStrategySource | null {
287
- let source: string;
288
- try {
289
- source = readFileSync(sourcePath, 'utf8');
290
- } catch {
291
- return null;
292
- }
293
- if (Buffer.byteLength(source, 'utf8') > MAX_STRATEGY_SOURCE_BYTES) return null;
294
- if (!SAFE_IMPORT.test(source)) return null;
295
-
296
- const classMatch = DEFAULT_STRATEGY_CLASS.exec(source);
297
- if (!classMatch) return null;
298
- const classOpenBrace = classMatch.index + classMatch[0].lastIndexOf('{');
299
- const classBody = balancedBlock(source, classOpenBrace);
300
- if (!classBody) return null;
301
- const manifestMatch = STATIC_MANIFEST.exec(classBody);
302
- if (!manifestMatch) return null;
303
- const manifestOpenBrace = manifestMatch.index + manifestMatch[0].lastIndexOf('{');
304
- const manifest = balancedBlock(classBody, manifestOpenBrace);
305
- if (!manifest) return null;
306
-
307
- const id = literalProperty(manifest, 'id')?.trim();
308
- const name = literalProperty(manifest, 'name')?.trim();
309
- const description = literalProperty(manifest, 'description')?.trim();
310
- const localizations = literalLocalizations(manifest);
311
- if (
312
- !id
313
- || !name
314
- || !description
315
- || localizations === null
316
- || !/^[a-z0-9][a-z0-9._-]*$/.test(id)
317
- ) return null;
318
- const execution = literalProperty(manifest, 'execution')?.trim() ?? null;
319
- const computeClass = classMatch[1] === 'ClawclawComputeStrategy';
320
- const directHybridClass = classMatch[1] === 'ClawclawHybridStrategy';
321
- const hybridCapableClass = directHybridClass || classMatch[1] === 'ClawclawGoalStrategy';
322
- if (execution !== null && execution !== 'parallel_compute' && execution !== 'parallel_analyze') {
323
- throw new StrategySourceValidationError(
324
- `Strategy '${id}' has unsupported manifest.execution '${execution}'.`,
325
- );
326
- }
327
- if (computeClass && execution !== 'parallel_compute') {
328
- throw new StrategySourceValidationError(
329
- `Strategy '${id}' extends ClawclawComputeStrategy and must declare manifest.execution: 'parallel_compute'.`,
330
- );
331
- }
332
- if (!computeClass && execution === 'parallel_compute') {
333
- throw new StrategySourceValidationError(
334
- `Strategy '${id}' declares manifest.execution: 'parallel_compute' but must extend ClawclawComputeStrategy.`,
335
- );
336
- }
337
- if (execution === 'parallel_analyze' && !hybridCapableClass) {
338
- throw new StrategySourceValidationError(
339
- `Strategy '${id}' declares manifest.execution: 'parallel_analyze' but must extend ClawclawGoalStrategy or ClawclawHybridStrategy.`,
340
- );
341
- }
342
- if (directHybridClass && execution !== 'parallel_analyze') {
343
- throw new StrategySourceValidationError(
344
- `Strategy '${id}' extends ClawclawHybridStrategy and must declare manifest.execution: 'parallel_analyze'.`,
345
- );
346
- }
347
- const controls = parseControlSpecs(classBody);
348
- return {
349
- id,
350
- name,
351
- description,
352
- ...(localizations === undefined ? {} : { localizations }),
353
- ...(execution === null ? {} : { execution: execution as 'parallel_compute' | 'parallel_analyze' }),
354
- ...(controls === undefined ? {} : { controls }),
355
- sourcePath,
356
- sourceRoot: strategiesRoot,
357
- };
358
- }
359
-
360
- function userStrategySources(workspaceDir = getWorkspaceDir()): ResolvedClawclawStrategySource[] {
361
- ensureUserDataLayout(workspaceDir);
362
- const strategiesDir = getUserDataStrategiesDir(workspaceDir);
363
- if (!existsSync(strategiesDir)) return [];
364
-
365
- let root: string;
366
- let files: string[];
367
- try {
368
- root = realpathSync(strategiesDir);
369
- files = readdirSync(root)
370
- .filter((file) => {
371
- if (file.startsWith('_') || file.endsWith('.d.ts') || file.endsWith('.test.ts')) return false;
372
- return /\.(?:ts|js)$/.test(file);
373
- })
374
- .sort()
375
- .slice(0, MAX_STRATEGY_FILES);
376
- } catch {
377
- return [];
378
- }
379
-
380
- const sources = new Map<string, ResolvedClawclawStrategySource>();
381
- for (const file of files) {
382
- try {
383
- const sourcePath = realpathSync(join(root, file));
384
- if (!isPathInside(root, sourcePath) || dirname(sourcePath) !== root) continue;
385
- const source = parseClassStrategy(sourcePath, root);
386
- if (source) sources.set(source.id, source);
387
- } catch (error) {
388
- if (error instanceof StrategySourceValidationError) throw error;
389
- }
390
- }
391
- return [...sources.values()];
392
- }
393
-
394
- /** Lists default-exported ClawclawStrategy classes without evaluating source code. */
395
- export function listClawclawStrategySources(
396
- workspaceDir = getWorkspaceDir(),
397
- ): ResolvedClawclawStrategySource[] {
398
- const sources = [demoSource()];
399
- for (const source of userStrategySources(workspaceDir)) {
400
- if (source.id !== CLAWCLAW_TASK_ONLY_DEMO_STRATEGY_ID) sources.push(source);
401
- }
402
- return sources;
403
- }
404
-
405
- /** Resolves metadata and source without evaluating third-party code. */
406
- export function resolveClawclawStrategySource(
407
- idOrName: string,
408
- workspaceDir = getWorkspaceDir(),
409
- ): ResolvedClawclawStrategySource {
410
- const sources = listClawclawStrategySources(workspaceDir);
411
- const source = sources.find((candidate) => candidate.id === idOrName)
412
- ?? sources.find((candidate) => candidate.name === idOrName);
413
- if (!source) throw new Error(`Unknown strategy '${idOrName}'.`);
414
- if (readGameplayConfig(workspaceDir).disabled_strategies.includes(source.id)) {
415
- throw new Error(`Strategy '${source.id}' is disabled in user-data/gameplay.json.`);
416
- }
417
- return source;
418
- }
419
-
420
- export function resolveDefaultClawclawStrategies(
421
- workspaceDir = getWorkspaceDir(),
422
- ): Record<ClawclawRoleId, ResolvedClawclawStrategySource> {
423
- const config = readGameplayConfig(workspaceDir);
424
- const disabled = new Set(config.disabled_strategies);
425
- const sources = new Map(listClawclawStrategySources(workspaceDir).map((source) => [source.id, source]));
426
- const resolved = {} as Record<ClawclawRoleId, ResolvedClawclawStrategySource>;
427
- for (const role of CLAWCLAW_ROLE_IDS) {
428
- const id = config.default_strategies[role];
429
- if (disabled.has(id)) {
430
- throw new Error(
431
- `Default strategy '${id}' for role '${role}' is disabled in user-data/gameplay.json.`,
432
- );
433
- }
434
- const source = sources.get(id);
435
- if (!source) {
436
- throw new Error(
437
- `Default strategy '${id}' for role '${role}' is not installed.`,
438
- );
439
- }
440
- resolved[role] = source;
441
- }
442
- return resolved;
443
- }