@myclaw163/clawclaw-cli 0.6.112 → 0.7.5

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 (422) hide show
  1. package/QUICKSTART.md +46 -0
  2. package/QUICKSTART_HERMES.md +134 -0
  3. package/QUICKSTART_OPENCLAW.md +134 -0
  4. package/QUICKSTART_OTHER.md +134 -0
  5. package/README.md +23 -398
  6. package/bin/clawclaw-cli.mjs +9 -1
  7. package/docs/configuration.md +197 -0
  8. package/docs/runtime/README.md +52 -0
  9. package/docs/runtime/agent-notifications.md +55 -0
  10. package/docs/runtime/components-and-boundaries.md +213 -0
  11. package/docs/runtime/events-and-state.md +105 -0
  12. package/docs/runtime/owner-lifecycle-and-observability.md +69 -0
  13. package/docs/runtime/perception-replay.md +51 -0
  14. package/docs/runtime/short-commands-and-capabilities.md +55 -0
  15. package/docs/runtime/strategy-runtime.md +111 -0
  16. package/docs//350/207/252/345/256/232/344/271/211/346/204/237/347/237/245.md +488 -0
  17. package/docs//350/207/252/345/256/232/344/271/211/347/255/226/347/225/245.md +395 -0
  18. package/package.json +26 -8
  19. package/scripts/check-skill-command-surface.mjs +16 -7
  20. package/scripts/compare-perception-replays.test.ts +188 -0
  21. package/scripts/compare-perception-replays.ts +589 -0
  22. package/scripts/generate-spatial-facts.py +246 -0
  23. package/scripts/package-readme.mjs +48 -0
  24. package/scripts/replay-perception.ts +347 -0
  25. package/scripts/sync-frontend-map.mjs +195 -0
  26. package/scripts/watch-perception-events.test.ts +43 -0
  27. package/scripts/watch-perception-events.ts +162 -0
  28. package/skills/clawclaw/SKILL.md +121 -65
  29. package/skills/clawclaw/references/CHATTERBOX.md +2 -4
  30. package/skills/clawclaw/references/CLAUDE-CODE-MONITOR.md +1 -1
  31. package/skills/clawclaw/references/COMMANDS.md +95 -61
  32. package/skills/clawclaw/references/GAME-MECHANICS.md +19 -9
  33. package/skills/clawclaw/references/HUB.md +5 -5
  34. package/skills/clawclaw/references/STRATEGIES.md +34 -17
  35. package/skills/clawclaw/references/STREAM.md +82 -46
  36. package/src/assets/clawclaw-map.json +1692 -0
  37. package/src/assets/clawclaw-spatial-facts.json +1291 -0
  38. package/src/assets/clawclaw-spatial-model.txt +142 -0
  39. package/src/cli.ts +21 -47
  40. package/src/commands/account.test.ts +229 -50
  41. package/src/commands/account.ts +456 -223
  42. package/src/commands/communication.test.ts +259 -0
  43. package/src/commands/communication.ts +391 -0
  44. package/src/commands/competition.test.ts +116 -0
  45. package/src/commands/competition.ts +50 -28
  46. package/src/commands/data.test.ts +57 -1
  47. package/src/commands/data.ts +79 -4
  48. package/src/commands/events-canonical-state.test.ts +187 -0
  49. package/src/commands/events.test.ts +50 -136
  50. package/src/commands/events.ts +175 -241
  51. package/src/commands/game/index.test.ts +510 -0
  52. package/src/commands/game/index.ts +556 -0
  53. package/src/commands/game-map.test.ts +48 -7
  54. package/src/commands/hub.test.ts +2 -23
  55. package/src/commands/hub.ts +4 -16
  56. package/src/commands/load.test.ts +10 -22
  57. package/src/commands/load.ts +15 -2
  58. package/src/commands/peek.ts +2 -3
  59. package/src/commands/perception.test.ts +46 -0
  60. package/src/commands/perception.ts +92 -0
  61. package/src/commands/setup/codex.ts +0 -1
  62. package/src/commands/strategy.test.ts +139 -102
  63. package/src/commands/strategy.ts +175 -103
  64. package/src/commands/upgrade.ts +0 -21
  65. package/src/lib/auth.test.ts +35 -0
  66. package/src/lib/auth.ts +45 -6
  67. package/src/lib/diagnostics-config.test.ts +59 -0
  68. package/src/lib/diagnostics-config.ts +76 -0
  69. package/src/lib/game-client.test.ts +166 -0
  70. package/src/lib/game-client.ts +316 -87
  71. package/src/lib/game-context.ts +33 -4
  72. package/src/lib/gameplay-config.test.ts +66 -0
  73. package/src/lib/gameplay-config.ts +151 -0
  74. package/src/lib/http-transport.test.ts +63 -0
  75. package/src/lib/http-transport.ts +76 -10
  76. package/src/lib/init-command.test.ts +25 -1
  77. package/src/lib/init-command.ts +66 -1
  78. package/src/lib/participation-leave.ts +78 -0
  79. package/src/lib/perception-config.test.ts +138 -0
  80. package/src/lib/perception-config.ts +101 -0
  81. package/src/lib/room.test.ts +14 -0
  82. package/src/lib/room.ts +28 -2
  83. package/src/lib/server-registry.test.ts +15 -5
  84. package/src/lib/server-registry.ts +9 -10
  85. package/src/lib/strategy-export.test.ts +123 -44
  86. package/src/lib/strategy-export.ts +110 -81
  87. package/src/lib/user-data.test.ts +2 -0
  88. package/src/lib/user-data.ts +17 -16
  89. package/src/pipeline/canonical-event-presentation.test.ts +196 -0
  90. package/src/pipeline/canonical-event-presentation.ts +71 -0
  91. package/src/pipeline/event-format.test.ts +357 -59
  92. package/src/pipeline/event-format.ts +365 -80
  93. package/src/pipeline/event-hints.test.ts +241 -0
  94. package/src/pipeline/event-hints.ts +202 -51
  95. package/src/pipeline/game-sync-event-normalization.test.ts +239 -0
  96. package/src/pipeline/game-sync-event-normalization.ts +215 -0
  97. package/src/pipeline/player-projection.test.ts +164 -102
  98. package/src/pipeline/player-projection.ts +194 -235
  99. package/src/runtime/canonical-event-emitter.test.ts +70 -0
  100. package/src/runtime/canonical-event-emitter.ts +78 -0
  101. package/src/runtime/canonical-monitor.test.ts +575 -0
  102. package/src/runtime/canonical-monitor.ts +388 -0
  103. package/src/runtime/clawclaw/agent-event-policy.test.ts +27 -0
  104. package/src/runtime/clawclaw/agent-event-policy.ts +35 -0
  105. package/src/runtime/clawclaw/index.ts +4 -0
  106. package/src/runtime/clawclaw/notifications.test.ts +47 -0
  107. package/src/runtime/clawclaw/notifications.ts +65 -0
  108. package/src/runtime/clawclaw/owner-lock.test.ts +221 -0
  109. package/src/runtime/clawclaw/owner.ts +945 -0
  110. package/src/runtime/clawclaw/plugins/action/action-plugin.ts +299 -0
  111. package/src/runtime/clawclaw/plugins/action/index.ts +1 -0
  112. package/src/runtime/clawclaw/plugins/assembly.test.ts +81 -0
  113. package/src/runtime/clawclaw/plugins/assembly.ts +116 -0
  114. package/src/runtime/clawclaw/plugins/derived-event/derived-event-plugin.test.ts +150 -0
  115. package/src/runtime/clawclaw/plugins/derived-event/derived-event-plugin.ts +100 -0
  116. package/src/runtime/clawclaw/plugins/derived-event/derived-event-rules.ts +162 -0
  117. package/src/runtime/clawclaw/plugins/derived-event/index.ts +2 -0
  118. package/src/runtime/clawclaw/plugins/game-query/game-query-plugin.test.ts +223 -0
  119. package/src/runtime/clawclaw/plugins/game-query/game-query-plugin.ts +236 -0
  120. package/src/runtime/clawclaw/plugins/game-query/index.ts +1 -0
  121. package/src/runtime/clawclaw/plugins/index.ts +7 -0
  122. package/src/runtime/clawclaw/plugins/mailbox/index.ts +3 -0
  123. package/src/runtime/clawclaw/plugins/mailbox/mailbox-plugin.ts +77 -0
  124. package/src/runtime/clawclaw/plugins/mailbox/mailbox-presentation.ts +91 -0
  125. package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.test.ts +1008 -0
  126. package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.ts +475 -0
  127. package/src/runtime/clawclaw/plugins/perception/contracts.ts +32 -0
  128. package/src/runtime/clawclaw/plugins/perception/index.ts +8 -0
  129. package/src/runtime/clawclaw/plugins/perception/module-runner.test.ts +204 -0
  130. package/src/runtime/clawclaw/plugins/perception/module-runner.ts +290 -0
  131. package/src/runtime/clawclaw/plugins/perception/modules/co-movement-module.ts +324 -0
  132. package/src/runtime/clawclaw/plugins/perception/modules/follow-module.ts +365 -0
  133. package/src/runtime/clawclaw/plugins/perception/modules/index.ts +7 -0
  134. package/src/runtime/clawclaw/plugins/perception/modules/motion-module.test.ts +341 -0
  135. package/src/runtime/clawclaw/plugins/perception/modules/motion-module.ts +447 -0
  136. package/src/runtime/clawclaw/plugins/perception/modules/parallel-module-test-helpers.ts +30 -0
  137. package/src/runtime/clawclaw/plugins/perception/modules/relation-stability.test.ts +289 -0
  138. package/src/runtime/clawclaw/plugins/perception/modules/route-module.test.ts +180 -0
  139. package/src/runtime/clawclaw/plugins/perception/modules/route-module.ts +329 -0
  140. package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.test.ts +82 -0
  141. package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.ts +172 -0
  142. package/src/runtime/clawclaw/plugins/perception/modules/stop-module.test.ts +212 -0
  143. package/src/runtime/clawclaw/plugins/perception/modules/stop-module.ts +256 -0
  144. package/src/runtime/clawclaw/plugins/perception/modules/temporal-evidence.test.ts +121 -0
  145. package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.test.ts +106 -0
  146. package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.ts +225 -0
  147. package/src/runtime/clawclaw/plugins/perception/official-module-ids.ts +11 -0
  148. package/src/runtime/clawclaw/plugins/perception/official-modules.ts +31 -0
  149. package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-pool.test.ts +759 -0
  150. package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-pool.ts +707 -0
  151. package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-worker.ts +215 -0
  152. package/src/runtime/clawclaw/plugins/perception/perception-module-loader.ts +61 -0
  153. package/src/runtime/clawclaw/plugins/perception/perception-plugin.test.ts +1516 -0
  154. package/src/runtime/clawclaw/plugins/perception/perception-plugin.ts +1529 -0
  155. package/src/runtime/clawclaw/plugins/perception/perception-source.test.ts +119 -0
  156. package/src/runtime/clawclaw/plugins/perception/perception-source.ts +244 -0
  157. package/src/runtime/clawclaw/plugins/perception/replay.test.ts +65 -0
  158. package/src/runtime/clawclaw/plugins/perception/replay.ts +86 -0
  159. package/src/runtime/clawclaw/plugins/perception/shared/math.ts +107 -0
  160. package/src/runtime/clawclaw/plugins/perception/spatial-facts.ts +114 -0
  161. package/src/runtime/clawclaw/plugins/perception/visual-state-projector.ts +98 -0
  162. package/src/runtime/clawclaw/plugins/runtime-plugins.test.ts +1019 -0
  163. package/src/runtime/clawclaw/plugins/source/game-transport.test.ts +287 -0
  164. package/src/runtime/clawclaw/plugins/source/game-transport.ts +281 -0
  165. package/src/runtime/clawclaw/plugins/source/index.ts +5 -0
  166. package/src/runtime/clawclaw/plugins/source/player-change-tracker.test.ts +270 -0
  167. package/src/runtime/clawclaw/plugins/source/player-change-tracker.ts +151 -0
  168. package/src/runtime/clawclaw/plugins/source/room-transport.test.ts +307 -0
  169. package/src/runtime/clawclaw/plugins/source/room-transport.ts +480 -0
  170. package/src/runtime/clawclaw/plugins/source/source-plugin.test.ts +1909 -0
  171. package/src/runtime/clawclaw/plugins/source/source-plugin.ts +2055 -0
  172. package/src/runtime/clawclaw/plugins/source/source-transports.ts +30 -0
  173. package/src/runtime/clawclaw/plugins/source/types.ts +79 -0
  174. package/src/runtime/clawclaw/plugins/strategy/context-capabilities.ts +5 -0
  175. package/src/runtime/clawclaw/plugins/strategy/examples/task-only-strategy.test.ts +177 -0
  176. package/src/runtime/clawclaw/plugins/strategy/examples/task-only-strategy.ts +185 -0
  177. package/src/runtime/clawclaw/plugins/strategy/index.ts +8 -0
  178. package/src/runtime/clawclaw/plugins/strategy/local-strategy-executor.ts +412 -0
  179. package/src/runtime/clawclaw/plugins/strategy/strategy-action.ts +73 -0
  180. package/src/runtime/clawclaw/plugins/strategy/strategy-analysis-thread-host.ts +183 -0
  181. package/src/runtime/clawclaw/plugins/strategy/strategy-executor-types.ts +25 -0
  182. package/src/runtime/clawclaw/plugins/strategy/strategy-executor.test.ts +693 -0
  183. package/src/runtime/clawclaw/plugins/strategy/strategy-game-api.ts +57 -0
  184. package/src/runtime/clawclaw/plugins/strategy/strategy-module-loader.ts +164 -0
  185. package/src/runtime/clawclaw/plugins/strategy/strategy-plugin.test.ts +1936 -0
  186. package/src/runtime/clawclaw/plugins/strategy/strategy-plugin.ts +1557 -0
  187. package/src/runtime/clawclaw/plugins/strategy/strategy-source.test.ts +131 -0
  188. package/src/runtime/clawclaw/plugins/strategy/strategy-source.ts +413 -0
  189. package/src/runtime/clawclaw/plugins/strategy/thread-strategy-executor.ts +792 -0
  190. package/src/runtime/clawclaw/runtime-data-export.test.ts +249 -0
  191. package/src/runtime/clawclaw/runtime-data-export.ts +402 -0
  192. package/src/runtime/clawclaw/runtime-state.ts +98 -0
  193. package/src/runtime/clawclaw/runtime.ts +133 -0
  194. package/src/runtime/clawclaw-event-catalog.test.ts +74 -0
  195. package/src/runtime/clawclaw-event-catalog.ts +266 -0
  196. package/src/runtime/clawclaw-position.ts +4 -0
  197. package/src/runtime/clawclaw-room-state.ts +51 -0
  198. package/src/runtime/framework/action-diagnostics.test.ts +81 -0
  199. package/src/runtime/framework/action-diagnostics.ts +146 -0
  200. package/src/runtime/framework/capability-registry.test.ts +282 -0
  201. package/src/runtime/framework/capability-registry.ts +283 -0
  202. package/src/runtime/framework/contracts.ts +118 -0
  203. package/src/runtime/framework/control/control-scheduler.ts +1260 -0
  204. package/src/runtime/framework/control/domain-set.ts +81 -0
  205. package/src/runtime/framework/control/index.ts +3 -0
  206. package/src/runtime/framework/control/types.ts +184 -0
  207. package/src/runtime/framework/control-coordinator.test.ts +660 -0
  208. package/src/runtime/framework/control-coordinator.ts +11 -0
  209. package/src/runtime/framework/events/event-catalog.ts +74 -0
  210. package/src/runtime/framework/events/event-delivery-service.test.ts +84 -0
  211. package/src/runtime/framework/events/event-delivery-service.ts +198 -0
  212. package/src/runtime/framework/events/event-ingress.test.ts +178 -0
  213. package/src/runtime/framework/events/event-ingress.ts +97 -0
  214. package/src/runtime/framework/events/event-repository.ts +59 -0
  215. package/src/runtime/framework/events/index.ts +7 -0
  216. package/src/runtime/framework/events/mailbox-event-repositories.test.ts +594 -0
  217. package/src/runtime/framework/events/memory-event-repository.ts +928 -0
  218. package/src/runtime/framework/events/sqlite-event-repository.test.ts +200 -0
  219. package/src/runtime/framework/events/sqlite-event-repository.ts +1681 -0
  220. package/src/runtime/framework/events/test-helpers.ts +78 -0
  221. package/src/runtime/framework/events/types.ts +286 -0
  222. package/src/runtime/framework/index.ts +7 -0
  223. package/src/runtime/framework/load-node-sqlite.ts +17 -0
  224. package/src/runtime/framework/mailbox/coalescer.test.ts +55 -0
  225. package/src/runtime/framework/mailbox/coalescer.ts +83 -0
  226. package/src/runtime/framework/mailbox/host-notification-sink.ts +44 -0
  227. package/src/runtime/framework/mailbox/identity.test.ts +38 -0
  228. package/src/runtime/framework/mailbox/identity.ts +38 -0
  229. package/src/runtime/framework/mailbox/index.ts +7 -0
  230. package/src/runtime/framework/mailbox/mailbox-dispatcher.test.ts +513 -0
  231. package/src/runtime/framework/mailbox/mailbox-dispatcher.ts +282 -0
  232. package/src/runtime/framework/mailbox/mailbox-repository.ts +44 -0
  233. package/src/runtime/framework/mailbox/notification-projector.test.ts +77 -0
  234. package/src/runtime/framework/mailbox/notification-projector.ts +65 -0
  235. package/src/runtime/framework/mailbox/types.ts +139 -0
  236. package/src/runtime/framework/modules/runtime-module-loader-hooks.d.mts +19 -0
  237. package/src/runtime/framework/modules/runtime-module-loader-hooks.mjs +117 -0
  238. package/src/runtime/framework/modules/runtime-module-loader.test.ts +209 -0
  239. package/src/runtime/framework/modules/runtime-module-loader.ts +71 -0
  240. package/src/runtime/framework/modules/runtime-module-worker-bootstrap.mjs +23 -0
  241. package/src/runtime/framework/participation-manager.test.ts +108 -0
  242. package/src/runtime/framework/participation-manager.ts +244 -0
  243. package/src/runtime/framework/plugins/contracts.ts +382 -0
  244. package/src/runtime/framework/plugins/index.ts +4 -0
  245. package/src/runtime/framework/plugins/runtime-event-identity.ts +17 -0
  246. package/src/runtime/framework/plugins/runtime-input-journal.test.ts +179 -0
  247. package/src/runtime/framework/plugins/runtime-input-journal.ts +693 -0
  248. package/src/runtime/framework/plugins/runtime-plugin-scheduler.test.ts +1994 -0
  249. package/src/runtime/framework/plugins/runtime-plugin-scheduler.ts +1860 -0
  250. package/src/runtime/framework/runtime.ts +1756 -0
  251. package/src/runtime/framework/serial-task-queue.ts +14 -0
  252. package/src/runtime/framework/state/contracts.ts +49 -0
  253. package/src/runtime/framework/state/current-state-store.ts +184 -0
  254. package/src/runtime/framework/state/durable-agent-state-snapshot.test.ts +144 -0
  255. package/src/runtime/framework/state/durable-agent-state-snapshot.ts +209 -0
  256. package/src/runtime/framework/state/freshness.ts +72 -0
  257. package/src/runtime/framework/state/history/contracts.ts +150 -0
  258. package/src/runtime/framework/state/history/history-writer.ts +194 -0
  259. package/src/runtime/framework/state/history/memory-state-history-repository.ts +178 -0
  260. package/src/runtime/framework/state/history/sqlite-state-history-repository.test.ts +157 -0
  261. package/src/runtime/framework/state/history/sqlite-state-history-repository.ts +629 -0
  262. package/src/runtime/framework/state/history/state-history.test.ts +251 -0
  263. package/src/runtime/framework/state/history/trajectory-projector.ts +209 -0
  264. package/src/runtime/framework/state/index.ts +13 -0
  265. package/src/runtime/framework/state/state-core.test.ts +197 -0
  266. package/src/runtime/framework/state/state-ingress.ts +95 -0
  267. package/src/runtime/framework/state/state-provider.ts +62 -0
  268. package/src/runtime/framework/state/types.ts +155 -0
  269. package/src/runtime/game-sync-protocol.test.ts +123 -0
  270. package/src/runtime/game-sync-protocol.ts +261 -0
  271. package/src/runtime/mailbox-host-relay.test.ts +248 -0
  272. package/src/runtime/mailbox-host-relay.ts +300 -0
  273. package/src/runtime/observability/factory.ts +188 -0
  274. package/src/runtime/observability/index.ts +6 -0
  275. package/src/runtime/observability/observability.test.ts +561 -0
  276. package/src/runtime/observability/recorder.ts +209 -0
  277. package/src/runtime/observability/redaction.ts +154 -0
  278. package/src/runtime/observability/reporter.ts +154 -0
  279. package/src/runtime/observability/sinks.ts +135 -0
  280. package/src/runtime/observability/types.ts +92 -0
  281. package/src/runtime/owner-control.test.ts +153 -0
  282. package/src/runtime/owner-control.ts +206 -42
  283. package/src/runtime/parent-process-watch.test.ts +27 -0
  284. package/src/runtime/parent-process-watch.ts +51 -0
  285. package/src/runtime/pending-event-handoff.test.ts +29 -0
  286. package/src/runtime/pending-event-handoff.ts +61 -0
  287. package/src/runtime/raw-ws-log.test.ts +86 -17
  288. package/src/runtime/raw-ws-log.ts +230 -21
  289. package/src/runtime/runtime-logger.test.ts +58 -0
  290. package/src/runtime/runtime-logger.ts +10 -13
  291. package/src/runtime/runtime-persistence.test.ts +26 -0
  292. package/src/runtime/runtime.test.ts +1704 -0
  293. package/src/runtime/ws-client.test.ts +496 -103
  294. package/src/runtime/ws-client.ts +546 -166
  295. package/src/sdk/action.ts +3 -1
  296. package/src/sdk/index.ts +4 -19
  297. package/src/sdk/perception-plugin/index.test.ts +22 -0
  298. package/src/sdk/perception-plugin/index.ts +285 -0
  299. package/src/sdk/strategy-plugin/index.test.ts +952 -0
  300. package/src/sdk/strategy-plugin/index.ts +1324 -0
  301. package/src/sdk/types.ts +3 -1
  302. package/src/short-command/classifier.test.ts +107 -0
  303. package/src/short-command/classifier.ts +169 -0
  304. package/src/short-command/index.ts +7 -0
  305. package/src/short-command/presenter.test.ts +119 -0
  306. package/src/short-command/presenter.ts +308 -0
  307. package/src/short-command/process-io.ts +13 -0
  308. package/src/short-command/response-contract.ts +58 -0
  309. package/src/short-command/runner.test.ts +78 -0
  310. package/src/short-command/runner.ts +164 -0
  311. package/src/short-command/sensitive-data-filter.test.ts +56 -0
  312. package/src/short-command/sensitive-data-filter.ts +123 -0
  313. package/src/short-command/transport-response.test.ts +39 -0
  314. package/src/short-command/transport-response.ts +89 -0
  315. package/src/short-command/types.ts +92 -0
  316. package/src/strategies/avoid-lone.ts +18 -11
  317. package/src/strategies/avoid-players.ts +29 -13
  318. package/src/strategies/corpse-patrol.ts +29 -11
  319. package/src/strategies/crab-sabotage.ts +31 -18
  320. package/src/strategies/custom-module.test.ts +3 -5
  321. package/src/strategies/find-player.ts +34 -15
  322. package/src/strategies/game-utils.test.ts +42 -0
  323. package/src/strategies/game-utils.ts +143 -53
  324. package/src/strategies/goals/avoid-lone-top.ts +22 -1
  325. package/src/strategies/goals/avoid-players-top.test.ts +13 -0
  326. package/src/strategies/goals/avoid-players-top.ts +6 -5
  327. package/src/strategies/goals/corpse-patrol-top.ts +9 -2
  328. package/src/strategies/goals/crab-octopus-reflexes.ts +6 -2
  329. package/src/strategies/goals/crab-sabotage-top.ts +7 -1
  330. package/src/strategies/goals/emergency-hunt-goal.ts +15 -3
  331. package/src/strategies/goals/find-player-top.ts +47 -3
  332. package/src/strategies/goals/flee-players-goal.ts +2 -0
  333. package/src/strategies/goals/follow-companion-goal.ts +27 -3
  334. package/src/strategies/goals/hide-top.ts +47 -5
  335. package/src/strategies/goals/keep-away-goal.ts +24 -2
  336. package/src/strategies/goals/kill-frenzy-top.ts +12 -2
  337. package/src/strategies/goals/kill-lone-top.test.ts +72 -0
  338. package/src/strategies/goals/kill-lone-top.ts +8 -6
  339. package/src/strategies/goals/kill-target-goal.ts +16 -7
  340. package/src/strategies/goals/kill-target-top.ts +16 -2
  341. package/src/strategies/goals/linger-corpse-goal.ts +11 -3
  342. package/src/strategies/goals/lone-kill-core.ts +4 -2
  343. package/src/strategies/goals/move-room-goal.ts +46 -4
  344. package/src/strategies/goals/normal-shrimp-top.test.ts +16 -0
  345. package/src/strategies/goals/normal-shrimp-top.ts +18 -18
  346. package/src/strategies/goals/paradise-fish-top.test.ts +78 -0
  347. package/src/strategies/goals/paradise-fish-top.ts +16 -6
  348. package/src/strategies/goals/patrol-top.ts +14 -3
  349. package/src/strategies/goals/report-patrol-top.ts +14 -3
  350. package/src/strategies/goals/safe-task-goal.ts +32 -4
  351. package/src/strategies/goals/social-task-top.ts +39 -8
  352. package/src/strategies/goals/task-kill-report-top.ts +33 -10
  353. package/src/strategies/goals/task-only-top.test.ts +89 -0
  354. package/src/strategies/goals/task-only-top.ts +9 -2
  355. package/src/strategies/goals/task-or-patrol-goal.ts +21 -3
  356. package/src/strategies/goals/warrior-shrimp-top.test.ts +75 -23
  357. package/src/strategies/goals/warrior-shrimp-top.ts +34 -13
  358. package/src/strategies/greeting.ts +10 -3
  359. package/src/strategies/hide-spots.ts +4 -0
  360. package/src/strategies/hide.ts +35 -20
  361. package/src/strategies/kill-frenzy.ts +18 -12
  362. package/src/strategies/kill-lone.ts +43 -12
  363. package/src/strategies/kill-target.ts +34 -17
  364. package/src/strategies/lone-kill-task.ts +31 -18
  365. package/src/strategies/move-room.ts +32 -15
  366. package/src/strategies/off-route-points.ts +12 -4
  367. package/src/strategies/paradise-fish.ts +49 -14
  368. package/src/strategies/pathfind/astar-path.test.ts +73 -0
  369. package/src/strategies/pathfind/astar-path.ts +196 -0
  370. package/src/strategies/pathfind/escape-planner.test.ts +27 -1
  371. package/src/strategies/pathfind/escape-planner.ts +108 -0
  372. package/src/strategies/patrol.ts +18 -11
  373. package/src/strategies/report-patrol.ts +18 -11
  374. package/src/strategies/shrimp-memory.ts +66 -14
  375. package/src/strategies/social-task.ts +49 -45
  376. package/src/strategies/task-kill-report.ts +34 -16
  377. package/src/strategies/task-only.test.ts +124 -0
  378. package/src/strategies/task-only.ts +20 -11
  379. package/src/strategies/task-report.ts +29 -11
  380. package/src/strategies/types.ts +29 -62
  381. package/src/strategies/warrior-memory.ts +44 -14
  382. package/scripts/check_monitor.test.mjs +0 -212
  383. package/skills/clawclaw/references/KNOWLEDGE.md +0 -42
  384. package/src/assets/clawclaw-ascii-map.txt +0 -40
  385. package/src/commands/do.test.ts +0 -117
  386. package/src/commands/do.ts +0 -195
  387. package/src/commands/game-monitor-status.test.ts +0 -58
  388. package/src/commands/game-start-plan.test.ts +0 -356
  389. package/src/commands/game.ts +0 -2046
  390. package/src/commands/history-player.test.ts +0 -105
  391. package/src/commands/history.ts +0 -573
  392. package/src/commands/knowledge.test.ts +0 -13
  393. package/src/commands/knowledge.ts +0 -176
  394. package/src/commands/meeting-history.test.ts +0 -106
  395. package/src/commands/state.ts +0 -46
  396. package/src/commands/watch.test.ts +0 -1313
  397. package/src/commands/watch.ts +0 -824
  398. package/src/lib/knowledge-store.test.ts +0 -170
  399. package/src/lib/knowledge-store.ts +0 -369
  400. package/src/perception/player-history-store.test.ts +0 -177
  401. package/src/perception/player-history-store.ts +0 -262
  402. package/src/pipeline/event-store.test.ts +0 -28
  403. package/src/pipeline/event-store.ts +0 -193
  404. package/src/pipeline/pipeline.ts +0 -35
  405. package/src/runtime/event-daemon.test.ts +0 -268
  406. package/src/runtime/event-daemon.ts +0 -531
  407. package/src/runtime/room-lobby-runtime.test.ts +0 -95
  408. package/src/runtime/room-lobby-runtime.ts +0 -367
  409. package/src/strategies/avoid-players.knowledge.md +0 -19
  410. package/src/strategies/kill-lone.knowledge.md +0 -17
  411. package/src/strategies/knowledge-contract.ts +0 -85
  412. package/src/strategies/loader.test.ts +0 -710
  413. package/src/strategies/loader.ts +0 -183
  414. package/src/strategies/new-events-backfill.ts +0 -98
  415. package/src/strategies/paradise-fish.knowledge.md +0 -19
  416. package/src/strategies/scanner.ts +0 -238
  417. package/src/strategies/shrimp-memory.knowledge.md +0 -19
  418. package/src/strategies/social-task.test.ts +0 -28
  419. package/src/strategies/spawn.ts +0 -82
  420. package/src/strategies/strategy-loop.test.ts +0 -15
  421. package/src/strategies/strategy-loop.ts +0 -748
  422. package/src/strategies/warrior-memory.knowledge.md +0 -21
@@ -9,7 +9,6 @@ import { HubClient, parseResourceRef } from '../lib/hub-client.js';
9
9
  import type { ListOptions } from '../lib/hub-client.js';
10
10
  import { installResource, uninstallResource, listInstalled, readLockfile } from '../lib/hub-install.js';
11
11
  import { getWorkspaceDir } from '../lib/init-command.js';
12
- import { inspectStrategySource } from '../strategies/scanner.js';
13
12
 
14
13
  const require = createRequire(import.meta.url);
15
14
 
@@ -145,19 +144,13 @@ export function createHubCommand(deps: HubCommandDeps = {}): Command {
145
144
  const client = getClient(deps);
146
145
  const detail = await client.getResource(type, id);
147
146
  const artifact = await client.downloadArtifact(type, id);
148
- const strategySummary = type === 'strategy'
149
- ? inspectStrategySource(artifact.toString('utf8'), detail.fileName || detail.artifact?.fileName || `${id}.ts`)
150
- : undefined;
151
- if (type === 'strategy' && !strategySummary) {
152
- throw new Error('Downloaded strategy must export static id, name/description, and create metadata.');
153
- }
154
147
  const res = installResource(detail, artifact, { force: opts.force });
155
- // Reload the static strategy catalog so the new file is picked up immediately.
148
+ // Strategy Plugin scans class files on demand. Extract the declared id
149
+ // only to tell the user what to select after installation.
156
150
  let strategyId: string | undefined;
157
151
  if (res.type === 'strategy') {
158
- const { reload } = await import('../strategies/loader.js');
159
- await reload();
160
- strategyId = strategySummary?.id;
152
+ const m = artifact.toString('utf8').match(/id\s*:\s*['"]([^'"]+)['"]/);
153
+ strategyId = m ? m[1] : undefined;
161
154
  }
162
155
 
163
156
  // For skills: auto-register with the agent via `ccl skill install`.
@@ -221,11 +214,6 @@ export function createHubCommand(deps: HubCommandDeps = {}): Command {
221
214
 
222
215
  const r = uninstallResource(ref);
223
216
  if (!r.removed) { console.log(ref + ' is not installed.'); return; }
224
- // Reload the strategy map so the removed strategy disappears immediately.
225
- if (type === 'strategy') {
226
- const { reload } = await import('../strategies/loader.js');
227
- await reload();
228
- }
229
217
  console.log('Removed ' + ref + '\n → ' + r.path);
230
218
  } catch (err) { handleError(err); }
231
219
  });
@@ -1,5 +1,5 @@
1
1
  import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
2
- import { existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'fs';
2
+ import { existsSync, mkdtempSync, rmSync } from 'fs';
3
3
  import { tmpdir } from 'os';
4
4
  import { join } from 'path';
5
5
 
@@ -15,6 +15,7 @@ import { runAutoUpgradeOnLoad } from '../runtime/auto-upgrade.js';
15
15
  import { noAccountMessage } from '../lib/account-guidance.js';
16
16
  import { loadContext } from '../lib/load-context.js';
17
17
  import { createLoadCommand } from './load.js';
18
+ import { updateGameplayConfig } from '../lib/gameplay-config.js';
18
19
 
19
20
  describe('load command', () => {
20
21
  let logSpy: ReturnType<typeof vi.spyOn>;
@@ -54,8 +55,8 @@ describe('load command', () => {
54
55
  });
55
56
  expect(output.strategies).toEqual(expect.arrayContaining([
56
57
  expect.objectContaining({
57
- id: 'task-only',
58
- name: '纯任务',
58
+ id: 'task-report',
59
+ name: '尽责虾',
59
60
  description: expect.any(String),
60
61
  }),
61
62
  ]));
@@ -73,26 +74,13 @@ describe('load command', () => {
73
74
  expect(errorSpy).toHaveBeenCalledWith('[clawclaw-cli] auto-upgrade installed 0.6.39');
74
75
  });
75
76
 
76
- it('does not execute workspace strategy top-level code while loading summaries', async () => {
77
- const strategiesDir = join(workspaceDir, 'user-data', 'strategies');
78
- const marker = join(workspaceDir, 'load-marker.txt');
79
- mkdirSync(strategiesDir, { recursive: true });
80
- writeFileSync(join(strategiesDir, 'load-marker.ts'), `
81
- import { writeFileSync } from 'fs';
82
- writeFileSync(${JSON.stringify(marker)}, 'executed', 'utf8');
83
- export const strategy = {
84
- id: 'load-marker',
85
- name: 'Load Marker',
86
- description: 'static metadata',
87
- create: () => ({ name: 'load-marker', decide: () => [] }),
88
- };`, 'utf8');
77
+ it('rejects a disabled role default instead of silently hiding it', async () => {
78
+ updateGameplayConfig((config) => {
79
+ config.disabled_strategies.push('task-report');
80
+ }, workspaceDir);
89
81
 
90
- const cmd = createLoadCommand();
91
- await cmd.parseAsync(['node', 'load'], { from: 'node' });
92
-
93
- const output = JSON.parse(String(logSpy.mock.calls[0][0]));
94
- expect(output.strategies).toEqual(expect.arrayContaining([expect.objectContaining({ id: 'load-marker' })]));
95
- expect(existsSync(marker)).toBe(false);
82
+ await expect(createLoadCommand().parseAsync(['node', 'load'], { from: 'node' }))
83
+ .rejects.toThrow("Default strategy 'task-report' for role 'shrimp_generic' is disabled");
96
84
  });
97
85
 
98
86
  it('turns missing-account load errors into registration guidance', async () => {
@@ -2,8 +2,12 @@ import { Command } from 'commander';
2
2
  import { loadContext } from '../lib/load-context.js';
3
3
  import { noAccountMessage } from '../lib/account-guidance.js';
4
4
  import { runAutoUpgradeOnLoad } from '../runtime/auto-upgrade.js';
5
+ import {
6
+ listClawclawStrategySources,
7
+ resolveDefaultClawclawStrategies,
8
+ } from '../runtime/clawclaw/plugins/strategy/index.js';
9
+ import { readGameplayConfig } from '../lib/gameplay-config.js';
5
10
  import { syncOfficialStrategies } from '../lib/strategy-export.js';
6
- import { listStrategySummaries } from '../strategies/loader.js';
7
11
 
8
12
  export function createLoadCommand(): Command {
9
13
  return new Command('load')
@@ -20,7 +24,16 @@ export function createLoadCommand(): Command {
20
24
  throw err;
21
25
  }
22
26
  await syncOfficialStrategies();
23
- const strategies = await listStrategySummaries();
27
+ const gameplay = readGameplayConfig();
28
+ resolveDefaultClawclawStrategies();
29
+ const disabled = new Set(gameplay.disabled_strategies);
30
+ const strategies = listClawclawStrategySources()
31
+ .filter(({ id }) => !disabled.has(id))
32
+ .map(({ id, name, description }) => ({
33
+ id,
34
+ name,
35
+ description,
36
+ }));
24
37
  console.log(JSON.stringify({ ...snapshot, strategies }, null, 2));
25
38
  });
26
39
  }
@@ -1,7 +1,6 @@
1
1
  import { Command } from 'commander';
2
2
  import { AuthStore } from '../lib/auth.js';
3
- import { getProfileStateDir } from '../lib/init-command.js';
4
- import { sendOwnerControlRequest } from '../runtime/owner-control.js';
3
+ import { sendProfileOwnerControlRequest } from '../runtime/owner-control.js';
5
4
 
6
5
  export interface RunPeekOptions {
7
6
  stdout: (line: string) => void;
@@ -18,7 +17,7 @@ export async function runPeek(opts: RunPeekOptions): Promise<number> {
18
17
  return 0;
19
18
  }
20
19
  try {
21
- const response = await sendOwnerControlRequest(getProfileStateDir(profile), 'snapshot');
20
+ const response = await sendProfileOwnerControlRequest(profile, 'snapshot');
22
21
  if (!response?.ok) {
23
22
  throw new Error('ccl game runtime is not running. Start it first with `ccl game start`.');
24
23
  }
@@ -0,0 +1,46 @@
1
+ import { mkdtempSync, readFileSync, rmSync } from 'node:fs';
2
+ import { tmpdir } from 'node:os';
3
+ import { join } from 'node:path';
4
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
5
+ import { createPerceptionCommand } from './perception.js';
6
+
7
+ let workspaceDir: string;
8
+ let logs: string[];
9
+
10
+ beforeEach(() => {
11
+ workspaceDir = mkdtempSync(join(tmpdir(), 'ccl-perception-command-'));
12
+ process.env.CLAWCLAW_WORKSPACE_DIR = workspaceDir;
13
+ logs = [];
14
+ vi.spyOn(console, 'log').mockImplementation((...args) => logs.push(args.join(' ')));
15
+ });
16
+
17
+ afterEach(() => {
18
+ delete process.env.CLAWCLAW_WORKSPACE_DIR;
19
+ vi.restoreAllMocks();
20
+ rmSync(workspaceDir, { recursive: true, force: true });
21
+ });
22
+
23
+ async function run(args: string[]): Promise<void> {
24
+ await createPerceptionCommand().parseAsync(['node', 'ccl', ...args]);
25
+ }
26
+
27
+ describe('perception command', () => {
28
+ it('lists installed modules and their enabled state', async () => {
29
+ await run(['--list']);
30
+ const output = JSON.parse(logs[0]);
31
+ expect(output.perception_modules.map((module: any) => module.id))
32
+ .toContain('visual.visibility');
33
+ expect(output.perception_modules.every((module: any) => module.disabled === false)).toBe(true);
34
+ });
35
+
36
+ it('keeps missing disabled module ids without reporting an error', async () => {
37
+ await run(['--disable', 'visual.removed']);
38
+ const config = JSON.parse(
39
+ readFileSync(join(workspaceDir, 'user-data', 'gameplay.json'), 'utf8'),
40
+ );
41
+ expect(config.disabled_perception_modules).toEqual(['visual.removed']);
42
+
43
+ await run(['--list']);
44
+ expect(JSON.parse(logs.at(-1)!).ignored_disabled_ids).toEqual(['visual.removed']);
45
+ });
46
+ });
@@ -0,0 +1,92 @@
1
+ import { Command } from 'commander';
2
+ import { getWorkspaceDir } from '../lib/init-command.js';
3
+ import {
4
+ readGameplayConfig,
5
+ updateGameplayConfig,
6
+ } from '../lib/gameplay-config.js';
7
+ import {
8
+ getUserDataGameplayConfigFile,
9
+ getUserDataPerceptionsDir,
10
+ } from '../lib/user-data.js';
11
+ import {
12
+ createOfficialPerceptionModule,
13
+ DEFAULT_PERCEPTION_MODULES,
14
+ listClawclawPerceptionSources,
15
+ perceptionManifest,
16
+ } from '../runtime/clawclaw/plugins/perception/index.js';
17
+
18
+ export function createPerceptionCommand(): Command {
19
+ const cmd = new Command('perception')
20
+ .alias('pcp')
21
+ .description('Inspect, enable, or disable perception modules')
22
+ .option('--list', 'List installed perception modules')
23
+ .option('--disable <id>', 'Disable a perception module on the next runtime')
24
+ .option('--enable <id>', 'Enable a perception module on the next runtime')
25
+ .addHelpText('after', () => `
26
+ Perception modules:
27
+ Place custom .ts or .js modules in ${getUserDataPerceptionsDir(getWorkspaceDir())}
28
+ Installed modules are enabled by default unless listed in user-data/gameplay.json.
29
+ `)
30
+ .action((opts: { list?: boolean; disable?: string; enable?: string }) => {
31
+ if (opts.disable && opts.enable) {
32
+ throw new Error('Use only one of --disable or --enable at a time.');
33
+ }
34
+ const workspaceDir = getWorkspaceDir();
35
+ if (opts.disable) {
36
+ const updated = updateGameplayConfig((current) => {
37
+ current.disabled_perception_modules.push(opts.disable!);
38
+ }, workspaceDir);
39
+ console.log(JSON.stringify({
40
+ perception_module: opts.disable,
41
+ disabled: true,
42
+ effective: 'next_runtime',
43
+ config_file: getUserDataGameplayConfigFile(workspaceDir),
44
+ disabled_perception_modules: updated.disabled_perception_modules,
45
+ }, null, 2));
46
+ return;
47
+ }
48
+ if (opts.enable) {
49
+ const updated = updateGameplayConfig((current) => {
50
+ current.disabled_perception_modules = current.disabled_perception_modules
51
+ .filter((id) => id !== opts.enable);
52
+ }, workspaceDir);
53
+ console.log(JSON.stringify({
54
+ perception_module: opts.enable,
55
+ disabled: false,
56
+ effective: 'next_runtime',
57
+ config_file: getUserDataGameplayConfigFile(workspaceDir),
58
+ disabled_perception_modules: updated.disabled_perception_modules,
59
+ }, null, 2));
60
+ return;
61
+ }
62
+ if (opts.list) {
63
+ const config = readGameplayConfig(workspaceDir);
64
+ const disabled = new Set(config.disabled_perception_modules);
65
+ const official = DEFAULT_PERCEPTION_MODULES.map((id) => {
66
+ const manifest = perceptionManifest(createOfficialPerceptionModule(id));
67
+ return {
68
+ id: manifest.id,
69
+ name: manifest.name,
70
+ description: manifest.description,
71
+ source: 'official',
72
+ disabled: disabled.has(id),
73
+ };
74
+ });
75
+ const custom = listClawclawPerceptionSources(workspaceDir).map((source) => ({
76
+ id: source.id,
77
+ name: source.name,
78
+ description: source.description,
79
+ source: 'user',
80
+ disabled: disabled.has(source.id),
81
+ }));
82
+ console.log(JSON.stringify({
83
+ perception_modules: [...official, ...custom],
84
+ ignored_disabled_ids: config.disabled_perception_modules
85
+ .filter((id) => ![...official, ...custom].some((module) => module.id === id)),
86
+ }, null, 2));
87
+ return;
88
+ }
89
+ cmd.help();
90
+ });
91
+ return cmd;
92
+ }
@@ -261,6 +261,5 @@ export function createSetupCodexSubcommand(): Command {
261
261
  console.log('');
262
262
  console.log('重启 Codex 后生效。可用工具:');
263
263
  console.log(' clawclaw_game_start / clawclaw_game_stop / clawclaw_game_status');
264
- console.log(' clawclaw_do / clawclaw_state / clawclaw_events / ...');
265
264
  });
266
265
  }
@@ -1,24 +1,34 @@
1
1
  // src/commands/strategy.test.ts
2
2
  import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
3
- import { mkdtempSync, rmSync, mkdirSync, writeFileSync, readFileSync, existsSync } from 'fs';
3
+ import { mkdtempSync, rmSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
4
4
  import { tmpdir } from 'os';
5
5
  import { join } from 'path';
6
6
  import { createStrategyCommand } from './strategy.js';
7
+ import { AuthStore } from '../lib/auth.js';
8
+ import { getProfileRuntimeStateDir } from '../lib/init-command.js';
9
+ import {
10
+ gameStartRuntimePath,
11
+ startOwnerControlServer,
12
+ type OwnerControlServer,
13
+ } from '../runtime/owner-control.js';
7
14
 
8
15
  let ws: string;
9
16
  let logs: string[];
10
17
  let errs: string[];
18
+ let owner: OwnerControlServer | undefined;
11
19
 
12
20
  beforeEach(() => {
13
21
  ws = mkdtempSync(join(tmpdir(), 'ccl-strategy-cmd-'));
14
22
  process.env.CLAWCLAW_WORKSPACE_DIR = ws;
15
23
  logs = []; errs = [];
24
+ owner = undefined;
16
25
  vi.spyOn(console, 'log').mockImplementation((...a) => { logs.push(a.join(' ')); });
17
26
  vi.spyOn(console, 'error').mockImplementation((...a) => { errs.push(a.join(' ')); });
18
27
  vi.spyOn(process, 'exit').mockImplementation((() => { throw new Error('process.exit'); }) as any);
19
28
  });
20
29
 
21
- afterEach(() => {
30
+ afterEach(async () => {
31
+ await owner?.close();
22
32
  delete process.env.CLAWCLAW_WORKSPACE_DIR;
23
33
  vi.restoreAllMocks();
24
34
  rmSync(ws, { recursive: true, force: true });
@@ -33,97 +43,78 @@ function userStrategiesDir(): string {
33
43
  return join(ws, 'user-data', 'strategies');
34
44
  }
35
45
 
36
- function officialManifestFile(): string {
37
- return join(userStrategiesDir(), '.official-manifest.json');
38
- }
39
-
40
46
  describe('strategy command', () => {
41
- describe('--export', () => {
42
- it('should export a valid strategy', async () => {
43
- await run(['--export', 'task-only']);
44
-
45
- const strategyFile = join(userStrategiesDir(), 'task-only.ts');
46
- expect(logs[0]).toContain('task-only');
47
- expect(logs[0]).toContain('exported');
48
-
49
- const content = readFileSync(strategyFile, 'utf8');
50
- expect(content).toContain('// Exported from task-only@');
51
- expect(content).toContain("from '@myclaw163/clawclaw-cli'");
52
- });
53
-
54
- it('should export with --force to overwrite', async () => {
55
- // First export
56
- await run(['--export', 'task-only']);
57
-
58
- // Modify the file
59
- const strategyFile = join(userStrategiesDir(), 'task-only.ts');
60
- writeFileSync(strategyFile, '// customized', 'utf8');
61
-
62
- // Re-export with --force
63
- await run(['--export', 'task-only', '--force']);
64
-
65
- const content = readFileSync(strategyFile, 'utf8');
66
- expect(content).toContain('// Exported from task-only@');
47
+ describe('--control', () => {
48
+ it('sends a JSON control object to the active runtime', async () => {
49
+ const auth = new AuthStore();
50
+ auth.addProfile({
51
+ agentName: 'strategy-control-agent',
52
+ apiKey: 'strategy-control-secret',
53
+ serverUrl: 'https://example.test/claw',
54
+ });
55
+ const profile = auth.getActive()!;
56
+ const stateDir = getProfileRuntimeStateDir(profile);
57
+ mkdirSync(stateDir, { recursive: true });
58
+ let received: Record<string, unknown> | undefined;
59
+ owner = await startOwnerControlServer(stateDir, (request) => {
60
+ received = request;
61
+ return {
62
+ ok: true,
63
+ type: 'update_strategy_control',
64
+ accepted: true,
65
+ revision: 3,
66
+ effectiveValues: request.control,
67
+ };
68
+ });
69
+ writeFileSync(gameStartRuntimePath(stateDir), JSON.stringify({
70
+ control: owner.control,
71
+ control_token: owner.token,
72
+ }), 'utf8');
73
+
74
+ await run(['--control', '{"greeting":"hello {player}"}']);
75
+
76
+ expect(received).toMatchObject({
77
+ type: 'update_strategy_control',
78
+ control: { greeting: 'hello {player}' },
79
+ });
80
+ expect(JSON.parse(logs[0])).toMatchObject({
81
+ ok: true,
82
+ accepted: true,
83
+ effectiveValues: { greeting: 'hello {player}' },
84
+ });
67
85
  });
68
86
 
69
- it('should export a formerly goal-based strategy with its knowledge sidecar', async () => {
70
- await run(['--export', 'kill-lone']);
71
-
72
- expect(existsSync(join(userStrategiesDir(), 'kill-lone.ts'))).toBe(true);
73
- expect(existsSync(join(userStrategiesDir(), 'kill-lone.knowledge.md'))).toBe(true);
74
- });
75
-
76
- it('should reject non-existent strategies', async () => {
77
- await expect(run(['--export', 'non-existent'])).rejects.toThrow('process.exit');
78
-
79
- expect(errs[0]).toContain('export_failed');
80
- expect(errs[0]).toContain('not found');
81
- });
82
-
83
- it('should warn about other stale strategies after export', async () => {
84
- // Export two strategies
85
- await run(['--export', 'task-only']);
86
- await run(['--export', 'kill-lone']);
87
- logs = []; errs = [];
88
-
89
- // Tamper kill-lone's hash to make it stale
90
- const manifestFile = officialManifestFile();
91
- const manifest = JSON.parse(readFileSync(manifestFile, 'utf8'));
92
- manifest['kill-lone'].sourceHash = 'stale';
93
- writeFileSync(manifestFile, JSON.stringify(manifest), 'utf8');
94
-
95
- // Re-export task-only — should warn about kill-lone being stale
96
- await run(['--export', 'task-only', '--force']);
97
-
98
- expect(errs.join(' ')).toContain('kill-lone');
99
- expect(errs.join(' ')).toContain('提示');
87
+ it('rejects non-object control JSON before contacting the runtime', async () => {
88
+ await expect(run(['--control', '[]'])).rejects.toThrow('process.exit');
89
+ expect(errs.join(' ')).toContain('invalid_strategy_control_json');
100
90
  });
101
91
  });
102
92
 
103
93
  describe('--info', () => {
104
- it('should show strategy info', async () => {
105
- await run(['--info', 'task-only']);
94
+ it('shows managed strategy class metadata', async () => {
95
+ await run(['--info', 'runtime-task-demo']);
106
96
 
107
- expect(logs[0]).toContain('"id": "task-only"');
97
+ expect(logs[0]).toContain('"id": "runtime-task-demo"');
108
98
  expect(logs[0]).toContain('"description"');
99
+ expect(logs[0]).toContain('"runtime": "strategy-plugin"');
100
+ expect(JSON.parse(logs[0]).controls).toEqual([expect.objectContaining({
101
+ id: 'greeting', type: 'string',
102
+ })]);
109
103
  });
110
104
 
111
- it('should show knowledge contract if available', async () => {
112
- await run(['--info', 'task-report']);
113
-
114
- const output = JSON.parse(logs[0]);
115
- expect(output.id).toBe('task-report');
116
- expect(output.description).toBeDefined();
117
- // knowledge might be null if no .knowledge.md file exists
105
+ it('shows a materialized official strategy through the managed class catalog', async () => {
106
+ await run(['--info', 'task-only']);
107
+ expect(logs[0]).toContain('"id": "task-only"');
108
+ expect(logs[0]).toContain('"runtime": "strategy-plugin"');
109
+ expect(JSON.parse(logs[0]).controls).toEqual([]);
118
110
  });
119
111
 
120
- it('should resolve a Chinese name and show its knowledge contract', async () => {
121
- await run(['--info', '武士虾']);
122
-
123
- const output = JSON.parse(logs[0]);
124
- expect(output.id).toBe('warrior-memory');
125
- expect(output.name).toBe('武士虾');
126
- expect(output.knowledge).toContain('warrior-memory');
112
+ it('shows semantic controls instead of opaque positional args', async () => {
113
+ await run(['--info', 'move-room']);
114
+ expect(JSON.parse(logs[0]).controls).toEqual([expect.objectContaining({
115
+ id: 'targetRoom',
116
+ type: 'string',
117
+ })]);
127
118
  });
128
119
 
129
120
  it('should reject non-existent strategies', async () => {
@@ -132,25 +123,6 @@ describe('strategy command', () => {
132
123
  expect(errs[0]).toContain('unknown_strategy');
133
124
  expect(errs[0]).toContain('non-existent');
134
125
  });
135
-
136
- it('does not execute top-level code while reading strategy info', async () => {
137
- const marker = join(ws, 'strategy-info-marker.txt');
138
- mkdirSync(userStrategiesDir(), { recursive: true });
139
- writeFileSync(join(userStrategiesDir(), 'info-marker.ts'), `
140
- import { writeFileSync } from 'fs';
141
- writeFileSync(${JSON.stringify(marker)}, 'executed', 'utf8');
142
- export const strategy = {
143
- id: 'info-marker',
144
- name: 'Info Marker',
145
- description: 'static metadata',
146
- create: () => ({ name: 'info-marker', decide: () => [] }),
147
- };`, 'utf8');
148
- const { reload } = await import('../strategies/loader.js');
149
- await reload();
150
- await run(['--info', 'info-marker']);
151
- expect(JSON.parse(logs[0]).id).toBe('info-marker');
152
- expect(existsSync(marker)).toBe(false);
153
- });
154
126
  });
155
127
 
156
128
  describe('--list', () => {
@@ -162,11 +134,76 @@ export const strategy = {
162
134
  expect(Array.isArray(output.strategies)).toBe(true);
163
135
  expect(output.strategies.length).toBeGreaterThan(0);
164
136
 
165
- // Check that task-only is in the list
166
- const taskOnly = output.strategies.find((s: any) => s.id === 'task-only');
137
+ const taskOnly = output.strategies.find((s: any) => s.id === 'runtime-task-demo');
167
138
  expect(taskOnly).toBeDefined();
168
- expect(taskOnly.name).toBe('纯任务');
139
+ expect(taskOnly.name).toBe('Runtime task demo');
169
140
  expect(taskOnly.description).toBeDefined();
141
+ expect(taskOnly.disabled).toBe(true);
142
+ expect(taskOnly.default_for_roles).toHaveLength(0);
143
+
144
+ const taskReport = output.strategies.find((s: any) => s.id === 'task-report');
145
+ expect(taskReport.disabled).toBe(false);
146
+ expect(taskReport.default_for_roles).toEqual([
147
+ 'shrimp_generic', 'shrimp_warrior', 'shrimp_pistol',
148
+ ]);
170
149
  });
150
+
151
+ it('discovers class exports and ignores object-style strategy definitions', async () => {
152
+ mkdirSync(userStrategiesDir(), { recursive: true });
153
+ writeFileSync(join(userStrategiesDir(), 'class-strategy.ts'), `
154
+ import { ClawclawStrategy } from '@myclaw163/clawclaw-cli/strategy-plugin';
155
+ export default class ClassStrategy extends ClawclawStrategy {
156
+ static manifest = {
157
+ id: 'class-strategy',
158
+ name: 'Class strategy',
159
+ description: 'A managed strategy class.',
160
+ };
161
+ update() {}
162
+ }
163
+ `, 'utf8');
164
+ writeFileSync(join(userStrategiesDir(), 'object-strategy.ts'), `
165
+ import { defineStrategy, STRATEGY_PLUGIN_API_VERSION } from '@myclaw163/clawclaw-cli/strategy-plugin';
166
+ export default defineStrategy({
167
+ apiVersion: STRATEGY_PLUGIN_API_VERSION,
168
+ id: 'object-strategy',
169
+ name: 'Object strategy',
170
+ description: 'An unsupported object definition.',
171
+ create() { return { update() {} }; },
172
+ });
173
+ `, 'utf8');
174
+
175
+ await run(['--list']);
176
+
177
+ const ids = JSON.parse(logs[0]).strategies.map((strategy: any) => strategy.id);
178
+ expect(ids).toContain('class-strategy');
179
+ expect(ids).not.toContain('object-strategy');
180
+ });
181
+ });
182
+
183
+ describe('gameplay configuration', () => {
184
+ it('does not allow disabling a role default', async () => {
185
+ await expect(run(['--disable', 'task-report']))
186
+ .rejects.toThrow('Cannot disable default strategy');
187
+ });
188
+
189
+ it('keeps stale disabled ids and can remove them again', async () => {
190
+ await run(['--disable', 'removed-strategy']);
191
+ let config = JSON.parse(readFileSync(join(ws, 'user-data', 'gameplay.json'), 'utf8'));
192
+ expect(config.disabled_strategies).toEqual(['runtime-task-demo', 'removed-strategy']);
193
+
194
+ await run(['--enable', 'removed-strategy']);
195
+ config = JSON.parse(readFileSync(join(ws, 'user-data', 'gameplay.json'), 'utf8'));
196
+ expect(config.disabled_strategies).toEqual(['runtime-task-demo']);
197
+ });
198
+
199
+ it('sets a valid installed default for one role', async () => {
200
+ await run(['--default', 'patrol', '--role', 'crab_generic']);
201
+ const config = JSON.parse(readFileSync(join(ws, 'user-data', 'gameplay.json'), 'utf8'));
202
+ expect(config.default_strategies.crab_generic).toBe('patrol');
203
+ });
204
+ });
205
+
206
+ it('rejects positional strategy parameters; controls use --control JSON', async () => {
207
+ await expect(run(['move-room', '酒吧'])).rejects.toThrow('process.exit');
171
208
  });
172
209
  });