@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
@@ -0,0 +1,556 @@
1
+ import { Command, InvalidArgumentError, Option } from 'commander';
2
+ import { AuthStore, type AuthProfile } from '../../lib/auth.js';
3
+ import { ApiError, GameClient } from '../../lib/game-client.js';
4
+ import { noAccountMessage } from '../../lib/account-guidance.js';
5
+ import { summarizeLocalClawclawMap } from '../../lib/game-context.js';
6
+ import {
7
+ businessFailureFromResult,
8
+ classifyLeaveQueueResult,
9
+ type ParticipationLeaveFailure,
10
+ } from '../../lib/participation-leave.js';
11
+ import {
12
+ isRoomMode,
13
+ queueMode,
14
+ queueStatus,
15
+ unwrapData,
16
+ type TrainingRoomType,
17
+ } from '../../lib/room.js';
18
+ import { setMeta } from '../../lib/command-meta.js';
19
+ import { ShortCommandRunner } from '../../short-command/runner.js';
20
+ import { createProcessCanonicalEventEmitter } from '../../runtime/canonical-event-emitter.js';
21
+ import { runClawclawOwner } from '../../runtime/clawclaw/owner.js';
22
+ import { ClawclawHostNotificationRoute } from '../../runtime/clawclaw/notifications.js';
23
+ import { sendProfileOwnerControlRequest } from '../../runtime/owner-control.js';
24
+
25
+ type GameCommandClient = Pick<
26
+ GameClient,
27
+ 'getQueueStatus' | 'leaveGame' | 'leaveRoom' | 'leaveQueue' | 'startRoom'
28
+ >;
29
+ type GameOwnerIntent = Parameters<typeof runClawclawOwner>[0]['intent'];
30
+ type GameOwnerRunOptions = { forceExistingRuntime?: boolean };
31
+
32
+ interface GameCommandIo {
33
+ writeStdout(text: string): void;
34
+ setExitCode(code: number): void;
35
+ }
36
+
37
+ export interface GameCommandDependencies {
38
+ activeProfile?: () => AuthProfile;
39
+ clientFactory?: () => GameCommandClient;
40
+ stopRuntime?: (profile: AuthProfile) => Promise<boolean>;
41
+ ownerControl?: typeof sendProfileOwnerControlRequest;
42
+ ownerRunner?: (
43
+ intent: GameOwnerIntent,
44
+ options?: GameOwnerRunOptions,
45
+ ) => Promise<void>;
46
+ io?: GameCommandIo;
47
+ }
48
+
49
+ function trainingRoomType(value: string): TrainingRoomType {
50
+ if (value === 'simulation' || value === 'training_simulation') return 'training_simulation';
51
+ if (value === 'dummy' || value === 'training_dummy') return 'training_dummy';
52
+ throw new InvalidArgumentError('Training mode must be simulation or dummy.');
53
+ }
54
+
55
+ function positiveCharacterId(value: string): number {
56
+ const parsed = Number(value);
57
+ if (!Number.isInteger(parsed) || parsed <= 0) {
58
+ throw new InvalidArgumentError('character_id must be a positive integer.');
59
+ }
60
+ return parsed;
61
+ }
62
+
63
+ async function runTrainingControl(
64
+ type: 'training_mode' | 'training_role_lock' | 'training_role_clear',
65
+ payload: Record<string, any>,
66
+ dependencies: GameCommandDependencies,
67
+ ): Promise<void> {
68
+ const profile = (dependencies.activeProfile ?? activeProfile)();
69
+ const io = dependencies.io ?? processGameCommandIo;
70
+ const response = await (dependencies.ownerControl ?? sendProfileOwnerControlRequest)(
71
+ profile,
72
+ type,
73
+ payload,
74
+ );
75
+ if (!response) {
76
+ const command = type === 'training_mode'
77
+ ? 'ccl game training mode'
78
+ : type === 'training_role_lock'
79
+ ? 'ccl game training role-lock'
80
+ : 'ccl game training role-unlock';
81
+ writeQuitResult(io, {
82
+ ok: false,
83
+ command,
84
+ error: 'runtime_not_running',
85
+ message: 'Training configuration requires the foreground training-room runtime.',
86
+ next_step: 'Start one with `ccl game training create --mode simulation|dummy`.',
87
+ }, 1);
88
+ return;
89
+ }
90
+ writeQuitResult(io, response, response.ok ? 0 : 1);
91
+ }
92
+
93
+ function activeProfile(): AuthProfile {
94
+ const profile = new AuthStore().getActive();
95
+ if (!profile) throw new Error(noAccountMessage('gameStart'));
96
+ return profile;
97
+ }
98
+
99
+ function backendSpectateUrl(result: any): string | undefined {
100
+ const data = unwrapData(result);
101
+ const value = data?.spectate_url ?? data?.url;
102
+ return typeof value === 'string' && value.length > 0 ? value : undefined;
103
+ }
104
+
105
+ function lobbyWatchUrl(profile: Pick<AuthProfile, 'serverUrl' | 'apiKey'>): string {
106
+ return `${new URL(profile.serverUrl).origin}/lobby?token=${encodeURIComponent(profile.apiKey)}`;
107
+ }
108
+
109
+ async function runOwner(
110
+ intent: GameOwnerIntent,
111
+ options: GameOwnerRunOptions = {},
112
+ ): Promise<void> {
113
+ const emitter = createProcessCanonicalEventEmitter();
114
+ const notifications = new ClawclawHostNotificationRoute(
115
+ (payload) => emitter.emit(payload),
116
+ );
117
+ let profile: AuthProfile | undefined;
118
+ try {
119
+ profile = activeProfile();
120
+ const completion = await runClawclawOwner({
121
+ profile,
122
+ intent,
123
+ forceExistingRuntime: options.forceExistingRuntime,
124
+ notificationHost: notifications,
125
+ });
126
+ if (completion.reason === 'error') process.exitCode = 1;
127
+ } catch (error) {
128
+ try {
129
+ await notifications.reportBootstrapFailure(
130
+ error,
131
+ profile ? [profile.apiKey] : [],
132
+ );
133
+ } catch {}
134
+ throw error;
135
+ }
136
+ }
137
+
138
+ const processGameCommandIo: GameCommandIo = {
139
+ writeStdout: (text) => process.stdout.write(text),
140
+ setExitCode: (code) => { process.exitCode = code; },
141
+ };
142
+
143
+ async function requestRuntimeStop(profile: AuthProfile): Promise<boolean> {
144
+ try {
145
+ return (await sendProfileOwnerControlRequest(profile, 'stop'))?.ok === true;
146
+ } catch {
147
+ return false;
148
+ }
149
+ }
150
+
151
+ function writeQuitResult(
152
+ io: GameCommandIo,
153
+ value: Record<string, unknown>,
154
+ exitCode: number,
155
+ ): void {
156
+ io.writeStdout(`${JSON.stringify(value, null, 2)}\n`);
157
+ io.setExitCode(exitCode);
158
+ }
159
+
160
+ function objectRoot(value: unknown): Record<string, unknown> | undefined {
161
+ return value !== null && typeof value === 'object' && !Array.isArray(value)
162
+ ? value as Record<string, unknown>
163
+ : undefined;
164
+ }
165
+
166
+ function apiErrorRoot(error: ApiError): Record<string, unknown> | undefined {
167
+ if (error.response?.body.kind === 'json') {
168
+ const root = objectRoot(error.response.body.value);
169
+ if (root) return root;
170
+ }
171
+ try {
172
+ return objectRoot(JSON.parse(error.body));
173
+ } catch {
174
+ return undefined;
175
+ }
176
+ }
177
+
178
+ async function writeStartRoomFailure(
179
+ io: GameCommandIo,
180
+ root: Record<string, unknown>,
181
+ httpStatus: number,
182
+ requestId?: string,
183
+ command = 'ccl game start-room',
184
+ ): Promise<void> {
185
+ await new ShortCommandRunner().run({
186
+ descriptor: {
187
+ command,
188
+ service: 'clawclaw-lobby',
189
+ operation: 'start_room',
190
+ },
191
+ io,
192
+ operation: () => ({
193
+ kind: 'backend_outcome',
194
+ status: 'failure',
195
+ value: root,
196
+ response: {
197
+ status: httpStatus,
198
+ ...(requestId ? { requestId } : {}),
199
+ },
200
+ }),
201
+ });
202
+ }
203
+
204
+ async function startCurrentRoom(
205
+ dependencies: GameCommandDependencies = {},
206
+ command = 'ccl game start-room',
207
+ ): Promise<void> {
208
+ (dependencies.activeProfile ?? activeProfile)();
209
+ const client = (dependencies.clientFactory ?? (() => GameClient.fromAuth()))();
210
+ const io = dependencies.io ?? processGameCommandIo;
211
+ try {
212
+ const result = await client.startRoom();
213
+ const root = objectRoot(result);
214
+ if (root?.success === false) {
215
+ await writeStartRoomFailure(io, root, 200, undefined, command);
216
+ return;
217
+ }
218
+ io.writeStdout(`${JSON.stringify(result, null, 2)}\n`);
219
+ io.setExitCode(0);
220
+ } catch (error) {
221
+ if (!(error instanceof ApiError)) throw error;
222
+ const root = apiErrorRoot(error) ?? {
223
+ success: false,
224
+ error: {
225
+ code: `HTTP_${error.status}`,
226
+ message: error.body || error.message,
227
+ },
228
+ };
229
+ await writeStartRoomFailure(
230
+ io,
231
+ root,
232
+ error.status,
233
+ error.response?.requestId,
234
+ command,
235
+ );
236
+ }
237
+ }
238
+
239
+ function quitFailure(
240
+ status: string,
241
+ presence: string | undefined,
242
+ failure: ParticipationLeaveFailure,
243
+ runtimeStopRequested: boolean,
244
+ extra: Record<string, unknown> = {},
245
+ ): Record<string, unknown> {
246
+ return {
247
+ ok: false,
248
+ command: 'game quit',
249
+ status,
250
+ left: runtimeStopRequested ? 'local_runtime' : 'none',
251
+ remote_left: false,
252
+ presence,
253
+ leave_error: failure,
254
+ runtime_stop_requested: runtimeStopRequested,
255
+ ...extra,
256
+ };
257
+ }
258
+
259
+ async function quitParticipation(dependencies: GameCommandDependencies = {}): Promise<void> {
260
+ const profile = (dependencies.activeProfile ?? activeProfile)();
261
+ const client = (dependencies.clientFactory ?? (() => GameClient.fromAuth()))();
262
+ const stopRuntime = dependencies.stopRuntime ?? requestRuntimeStop;
263
+ const io = dependencies.io ?? processGameCommandIo;
264
+ const queue = await client.getQueueStatus('clawclaw');
265
+ const status = queueStatus(queue);
266
+ if (status === 'allocated') {
267
+ const game = await client.leaveGame();
268
+ const failure = businessFailureFromResult(game, 'Failed to leave the active game.');
269
+ if (failure) {
270
+ const runtimeStopRequested = await stopRuntime(profile);
271
+ const stillAliveDetails = failure.still_alive
272
+ ? {
273
+ partial: runtimeStopRequested,
274
+ backend_participation: 'active_game',
275
+ local_runtime: runtimeStopRequested ? 'stopping' : 'stop_not_confirmed',
276
+ message: runtimeStopRequested
277
+ ? 'The local runtime accepted a stop request, but the backend rejected leaving the game. The player still exists in the active game on the server.'
278
+ : 'The backend rejected leaving the game, so the player still exists in the active game on the server. No local runtime acknowledged a stop request.',
279
+ next_step: 'Tell the user that the local runtime and the server-side player now have different states; do not claim that the player left the game.',
280
+ }
281
+ : {};
282
+ writeQuitResult(io, quitFailure(
283
+ 'leave_game_failed',
284
+ 'in_game',
285
+ failure,
286
+ runtimeStopRequested,
287
+ {
288
+ game_result: game,
289
+ queue_status: unwrapData(queue),
290
+ ...stillAliveDetails,
291
+ },
292
+ ), 1);
293
+ return;
294
+ }
295
+ if (isRoomMode(queueMode(queue))) {
296
+ writeQuitResult(io, {
297
+ ok: true,
298
+ command: 'game quit',
299
+ status: 'game_returned_room',
300
+ left: 'game_returned_room',
301
+ remote_left: true,
302
+ presence: 'in_game',
303
+ game_result: game,
304
+ queue_status: unwrapData(queue),
305
+ runtime_stop_requested: false,
306
+ next_step: 'Left the current room game. The running runtime will return to the room lobby.',
307
+ }, 0);
308
+ return;
309
+ }
310
+ const runtimeStopRequested = await stopRuntime(profile);
311
+ writeQuitResult(io, {
312
+ ok: true,
313
+ command: 'game quit',
314
+ status: 'left_game',
315
+ left: 'game',
316
+ remote_left: true,
317
+ presence: 'in_game',
318
+ game_result: game,
319
+ queue_status: unwrapData(queue),
320
+ runtime_stop_requested: runtimeStopRequested,
321
+ }, 0);
322
+ return;
323
+ }
324
+ if (status === 'in_room') {
325
+ const room = await client.leaveRoom();
326
+ const failure = businessFailureFromResult(room, 'Failed to leave the room.');
327
+ const runtimeStopRequested = await stopRuntime(profile);
328
+ if (failure) {
329
+ writeQuitResult(io, quitFailure(
330
+ 'leave_room_failed',
331
+ 'in_room',
332
+ failure,
333
+ runtimeStopRequested,
334
+ { room_result: room, queue_status: unwrapData(queue) },
335
+ ), 1);
336
+ return;
337
+ }
338
+ writeQuitResult(io, {
339
+ ok: true,
340
+ command: 'game quit',
341
+ status: 'left_room',
342
+ left: 'room',
343
+ remote_left: true,
344
+ presence: 'in_room',
345
+ room_result: room,
346
+ queue_status: unwrapData(queue),
347
+ runtime_stop_requested: runtimeStopRequested,
348
+ }, 0);
349
+ return;
350
+ }
351
+ if (status === 'queued' || status === 'already_in_queue' || status === 'allocating') {
352
+ const matching = await client.leaveQueue('clawclaw');
353
+ const outcome = classifyLeaveQueueResult(matching);
354
+ if (!outcome.remoteLeft) {
355
+ writeQuitResult(io, quitFailure(
356
+ outcome.status === 'allocating' ? 'leave_queue_allocating' : 'leave_queue_failed',
357
+ 'matching',
358
+ outcome.failure!,
359
+ false,
360
+ { queue_result: matching, queue_status: unwrapData(queue) },
361
+ ), 1);
362
+ return;
363
+ }
364
+ const runtimeStopRequested = await stopRuntime(profile);
365
+ writeQuitResult(io, {
366
+ ok: true,
367
+ command: 'game quit',
368
+ status: outcome.status,
369
+ left: 'queue',
370
+ remote_left: true,
371
+ presence: 'matching',
372
+ queue_result: matching,
373
+ queue_status: unwrapData(queue),
374
+ runtime_stop_requested: runtimeStopRequested,
375
+ }, 0);
376
+ return;
377
+ }
378
+ if (status === 'not_in_queue') {
379
+ const runtimeStopRequested = await stopRuntime(profile);
380
+ writeQuitResult(io, {
381
+ ok: true,
382
+ command: 'game quit',
383
+ status: 'not_participating',
384
+ left: runtimeStopRequested ? 'local_runtime' : 'none',
385
+ remote_left: true,
386
+ presence: status,
387
+ queue_status: unwrapData(queue),
388
+ runtime_stop_requested: runtimeStopRequested,
389
+ }, 0);
390
+ return;
391
+ }
392
+ writeQuitResult(io, quitFailure(
393
+ 'unknown_participation_status',
394
+ status,
395
+ {
396
+ code: 'UNEXPECTED_QUEUE_STATUS',
397
+ message: 'The server returned an unknown participation status, so no leave action was attempted.',
398
+ retryable: true,
399
+ },
400
+ false,
401
+ { queue_status: unwrapData(queue) },
402
+ ), 1);
403
+ }
404
+
405
+ export function createGameCommand(dependencies: GameCommandDependencies = {}): Command {
406
+ const game = new Command('game').description('Game participation and inspection');
407
+ const ownerRunner = dependencies.ownerRunner ?? runOwner;
408
+
409
+ const start = game
410
+ .command('start')
411
+ .alias('s')
412
+ .description('Run the ClawClaw Source until the current participation ends.')
413
+ .requiredOption('--agent-type <platform>')
414
+ .option('--llm-model <model>')
415
+ .option('--force', 'replace an existing local runtime process before starting')
416
+ .addOption(new Option('--competition').hideHelp())
417
+ .action(async (opts: {
418
+ agentType: string;
419
+ llmModel?: string;
420
+ competition?: boolean;
421
+ force?: boolean;
422
+ }) => {
423
+ await ownerRunner({
424
+ kind: 'match',
425
+ mode: opts.competition ? 'competition' : 'match',
426
+ agentType: opts.agentType,
427
+ llmModel: opts.llmModel,
428
+ }, {
429
+ forceExistingRuntime: opts.force === true,
430
+ });
431
+ });
432
+
433
+ const createRoom = game
434
+ .command('create-room')
435
+ .description('Create a room and run its Source lifecycle.')
436
+ .requiredOption('--agent-type <platform>')
437
+ .option('--llm-model <model>')
438
+ .option('--force', 'replace an existing local runtime process before starting')
439
+ .action(async (opts: { agentType: string; llmModel?: string; force?: boolean }) => ownerRunner({
440
+ kind: 'create_room',
441
+ agentType: opts.agentType,
442
+ llmModel: opts.llmModel,
443
+ }, {
444
+ forceExistingRuntime: opts.force === true,
445
+ }));
446
+
447
+ const joinRoom = game
448
+ .command('join-room')
449
+ .description('Join a room and run its Source lifecycle.')
450
+ .argument('<room_code>')
451
+ .requiredOption('--agent-type <platform>')
452
+ .option('--llm-model <model>')
453
+ .option('--force', 'replace an existing local runtime process before starting')
454
+ .action(async (roomCode: string, opts: { agentType: string; llmModel?: string; force?: boolean }) => ownerRunner({
455
+ kind: 'join_room',
456
+ roomCode,
457
+ agentType: opts.agentType,
458
+ llmModel: opts.llmModel,
459
+ }, {
460
+ forceExistingRuntime: opts.force === true,
461
+ }));
462
+
463
+ const training = game
464
+ .command('training')
465
+ .description('Create and configure a bot-filled training room.');
466
+
467
+ const trainingCreate = training
468
+ .command('create')
469
+ .description('Create a training room and run its Source lifecycle.')
470
+ .requiredOption('--mode <simulation|dummy>', 'training ruleset', trainingRoomType)
471
+ .requiredOption('--agent-type <platform>')
472
+ .option('--llm-model <model>')
473
+ .option('--force', 'replace an existing local runtime process before starting')
474
+ .action(async (opts: {
475
+ mode: TrainingRoomType;
476
+ agentType: string;
477
+ llmModel?: string;
478
+ force?: boolean;
479
+ }) => ownerRunner({
480
+ kind: 'create_room',
481
+ roomType: opts.mode,
482
+ agentType: opts.agentType,
483
+ llmModel: opts.llmModel,
484
+ }, {
485
+ forceExistingRuntime: opts.force === true,
486
+ }));
487
+
488
+ training
489
+ .command('mode')
490
+ .description('Switch the current training room ruleset.')
491
+ .argument('<simulation|dummy>', 'training ruleset', trainingRoomType)
492
+ .action((roomType: TrainingRoomType) => runTrainingControl(
493
+ 'training_mode',
494
+ { room_type: roomType },
495
+ dependencies,
496
+ ));
497
+
498
+ training
499
+ .command('role-lock')
500
+ .description('Lock the player character for future training rounds.')
501
+ .argument('<character_id>', 'backend character id', positiveCharacterId)
502
+ .action((characterId: number) => runTrainingControl(
503
+ 'training_role_lock',
504
+ { character_id: characterId },
505
+ dependencies,
506
+ ));
507
+
508
+ training
509
+ .command('role-unlock')
510
+ .description('Clear the player character lock for future training rounds.')
511
+ .action(() => runTrainingControl('training_role_clear', {}, dependencies));
512
+
513
+ training
514
+ .command('start')
515
+ .description('Start a round in the current training room.')
516
+ .action(() => startCurrentRoom(dependencies, 'ccl game training start'));
517
+
518
+ game
519
+ .command('quit')
520
+ .description('Leave the active queue, room, or game.')
521
+ .action(() => quitParticipation(dependencies));
522
+
523
+ game
524
+ .command('start-room')
525
+ .description('Start the current room.')
526
+ .action(() => startCurrentRoom(dependencies));
527
+
528
+ game
529
+ .command('map', { hidden: true })
530
+ .description('Show the current game map.')
531
+ .option('--ascii')
532
+ .action(async (opts: { ascii?: boolean }) => {
533
+ process.stdout.write(`${JSON.stringify(summarizeLocalClawclawMap({
534
+ ascii: opts.ascii === true,
535
+ }), null, 2)}\n`);
536
+ });
537
+
538
+ game
539
+ .command('watch')
540
+ .alias('w')
541
+ .description('Get the current spectating URL.')
542
+ .action(async () => {
543
+ const profile = activeProfile();
544
+ const queue = await GameClient.fromAuth().getQueueStatus('clawclaw');
545
+ process.stdout.write(`${JSON.stringify({
546
+ ...unwrapData(queue),
547
+ url: backendSpectateUrl(queue) ?? lobbyWatchUrl(profile),
548
+ }, null, 2)}\n`);
549
+ });
550
+
551
+ setMeta(start, { longRunning: true, timeoutMs: 1_800_000 });
552
+ setMeta(createRoom, { longRunning: true, timeoutMs: 1_800_000 });
553
+ setMeta(joinRoom, { longRunning: true, timeoutMs: 1_800_000 });
554
+ setMeta(trainingCreate, { longRunning: true, timeoutMs: 1_800_000 });
555
+ return game;
556
+ }
@@ -1,5 +1,9 @@
1
1
  import { describe, expect, it } from 'vitest';
2
- import { summarizeGameMap } from './game.js';
2
+ import {
3
+ loadClawclawMapAsset,
4
+ summarizeGameMap,
5
+ summarizeLocalClawclawMap,
6
+ } from '../lib/game-context.js';
3
7
 
4
8
  const mapData = {
5
9
  rooms: [{ name: '酒吧', polygon: [[1, 2]] }],
@@ -13,16 +17,53 @@ describe('summarizeGameMap', () => {
13
17
  it('does not include ASCII by default', () => {
14
18
  const summary = summarizeGameMap(mapData);
15
19
  expect(summary.rooms).toEqual([{ name: '酒吧', polygon: [[1, 2]] }]);
16
- expect(summary.task_locations.lobster).toEqual([{ name: '修线', room: '酒吧', x: 1, y: 2 }]);
17
- expect(summary.task_locations.crab).toEqual([{ name: '破坏', room: '控制室', x: 3, y: 4 }]);
20
+ expect(summary.task_locations.lobster).toEqual([
21
+ { name: '修线', room: '酒吧', x: 1, y: 2 },
22
+ ]);
23
+ expect(summary.task_locations.crab).toEqual([
24
+ { name: '破坏', room: '控制室', x: 3, y: 4 },
25
+ ]);
18
26
  expect(summary).not.toHaveProperty('ascii_map');
27
+ expect(summary).not.toHaveProperty('spatial_model');
19
28
  });
20
29
 
21
- it('includes packaged ASCII map only with --ascii', () => {
30
+ it('includes the packaged spatial model with --ascii', () => {
22
31
  const summary = summarizeGameMap(mapData, { ascii: true });
23
- expect(typeof summary.ascii_map).toBe('string');
24
- expect(summary.ascii_map).toContain('酒吧');
25
- expect(summary.ascii_map).toContain('5号走廊');
32
+ expect(typeof summary.spatial_model).toBe('string');
33
+ expect(summary.spatial_model).toContain('# ClawClaw 地图空间模型');
34
+ expect(summary.spatial_model).toContain('房间图例(小写=房间)');
35
+ expect(summary.spatial_model).not.toContain('从 clawclaw.tmj 推导');
36
+ expect(summary).not.toHaveProperty('ascii_map');
26
37
  expect(summary).not.toHaveProperty('corridors');
27
38
  });
28
39
  });
40
+
41
+ describe('packaged frontend map', () => {
42
+ it('contains the map generated directly from the authoritative frontend ref', () => {
43
+ const map = loadClawclawMapAsset();
44
+
45
+ expect(map.source).toMatchObject({
46
+ authority: 'frontend',
47
+ ref: 'feature/v0.3.2',
48
+ commit: expect.stringMatching(/^[0-9a-f]{40}$/),
49
+ map_git_blob: expect.stringMatching(/^[0-9a-f]{40}$/),
50
+ map_sha256: expect.stringMatching(/^[0-9a-f]{64}$/),
51
+ });
52
+ expect(map.source).not.toHaveProperty('map_commit');
53
+ expect(map.coordinates).toMatchObject({ x_positive: 'right', y_positive: 'down' });
54
+ expect(map.rooms).toHaveLength(21);
55
+ expect(map.tasks).toHaveLength(50);
56
+ expect(map.spawn_points).toHaveLength(10);
57
+ expect(map.rooms.every((room: any) => room.polygon.length >= 3)).toBe(true);
58
+ expect(map.tasks.every((task: any) => typeof task.room === 'string')).toBe(true);
59
+ });
60
+
61
+ it('serves the packaged asset without requiring backend discovery', () => {
62
+ const summary = summarizeLocalClawclawMap();
63
+
64
+ expect(summary.source.authority).toBe('frontend');
65
+ expect(summary.rooms).toHaveLength(21);
66
+ expect(summary).not.toHaveProperty('ascii_map');
67
+ expect(summary).not.toHaveProperty('spatial_model');
68
+ });
69
+ });
@@ -1,18 +1,11 @@
1
1
  // src/commands/hub.test.ts
2
2
  import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
3
- import { existsSync, mkdtempSync, rmSync } from 'fs';
3
+ import { mkdtempSync, rmSync } from 'fs';
4
4
  import { tmpdir } from 'os';
5
5
  import { join } from 'path';
6
6
  import { createHubCommand } from './hub.js';
7
7
  import type { ResourceListResult, ResourceDetail } from '../lib/hub-client.js';
8
8
 
9
- const STRATEGY_ARTIFACT = `export const strategy = {
10
- id: 'hub-kill',
11
- name: '抢刀',
12
- description: '贴脸抢刀',
13
- create: () => ({ name: 'hub-kill', decide: () => [] }),
14
- };`;
15
-
16
9
  let ws: string;
17
10
  let logs: string[];
18
11
  let errs: string[];
@@ -47,7 +40,7 @@ function fakeClient(over: any = {}) {
47
40
  downloadUrl: '/dl', likedByMe: false, createdAt: '', updatedAt: '',
48
41
  artifact: { fileName: 'kill.ts', downloadUrl: '/dl' },
49
42
  })),
50
- downloadArtifact: vi.fn(async () => Buffer.from(STRATEGY_ARTIFACT)),
43
+ downloadArtifact: vi.fn(async () => Buffer.from('export const strategy = {};')),
51
44
  ...over,
52
45
  };
53
46
  }
@@ -87,20 +80,6 @@ describe('hub install', () => {
87
80
  expect(out.ref).toBe('strategy/ab12');
88
81
  expect(out.installedPath).toMatch(/strategies[\\/]aggressive-kill__ab12\.ts/);
89
82
  });
90
- it('does not execute downloaded top-level code while installing and reloading', async () => {
91
- const marker = join(ws, 'hub-install-marker.txt');
92
- const artifact = `
93
- import { writeFileSync } from 'fs';
94
- writeFileSync(${JSON.stringify(marker)}, 'executed', 'utf8');
95
- export const strategy = {
96
- id: 'hub-marker',
97
- name: 'Hub Marker',
98
- description: 'static metadata',
99
- create: () => ({ name: 'hub-marker', decide: () => [] }),
100
- };`;
101
- await run(fakeClient({ downloadArtifact: vi.fn(async () => Buffer.from(artifact)) }), ['install', 'strategy/ab12']);
102
- expect(existsSync(marker)).toBe(false);
103
- });
104
83
  });
105
84
 
106
85
  describe('hub installed / uninstall', () => {