@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
@@ -1,64 +1,43 @@
1
1
  import { Command, Option } from 'commander';
2
+ import { readFileSync } from 'fs';
3
+ import { basename } from 'path';
2
4
  import { AuthStore } from '../lib/auth.js';
3
5
  import type { AuthProfile } from '../lib/auth.js';
4
- import { GameClient, ApiError } from '../lib/game-client.js';
6
+ import { GameClient } from '../lib/game-client.js';
5
7
  import { createProfileDirs, cmdInit } from '../lib/init-command.js';
6
8
  import { setMeta } from '../lib/command-meta.js';
7
- import { hubReminder, writeGamesPlayedCache } from '../lib/hub-reminder.js';
9
+ import { hubReminder, readCachedGamesPlayed, writeGamesPlayedCache } from '../lib/hub-reminder.js';
8
10
  import {
9
11
  missingInviteCodeMessage,
10
12
  noAccountMessage,
11
- registrationSuccessOutput,
13
+ OFFICIAL_URL,
14
+ POST_REGISTRATION_NEXT_STEP,
12
15
  } from '../lib/account-guidance.js';
13
16
  import { ensureDefaultPersonaPreset } from '../lib/persona.js';
14
- import { syncOfficialStrategies } from '../lib/strategy-export.js';
15
- import {
16
- normalizeCompetitionRankResponse,
17
- normalizeCompetitionStatusResponse,
18
- serializeError,
19
- } from '../lib/competition.js';
17
+ import { ResponseClassifier } from '../short-command/classifier.js';
18
+ import { createProcessCommandIo } from '../short-command/process-io.js';
19
+ import { booleanSuccessContract } from '../short-command/response-contract.js';
20
+ import type { ResponseContract } from '../short-command/response-contract.js';
21
+ import { ShortCommandRunner } from '../short-command/runner.js';
22
+ import type {
23
+ CommandIo,
24
+ ShortCommandOperationResult,
25
+ } from '../short-command/runner.js';
26
+ import type { TransportResponse } from '../short-command/transport-response.js';
27
+ import type { PresentationOverrides } from '../short-command/types.js';
20
28
 
21
29
  const DEFAULT_SERVER_URL = 'https://myclaw.163.com/claw';
22
30
  const SERVER_URL_ENV = 'CLAWCLAW_SERVER_URL';
23
31
 
24
- async function refreshGamesPlayedForReminder(client: GameClient): Promise<number | undefined> {
25
- try {
26
- const result = await client.getMe();
27
- const gamesPlayed = result?.data?.games_played;
28
- if (typeof gamesPlayed === 'number') {
29
- writeGamesPlayedCache(gamesPlayed);
30
- return gamesPlayed;
31
- }
32
- } catch {}
33
- return undefined;
34
- }
35
-
36
- function createClientForProfile(profile: AuthProfile): GameClient {
37
- return new GameClient({
38
- lobbyUrl: profile.serverUrl,
39
- gameServerUrl: profile.gameServerUrl,
40
- apiKey: profile.apiKey,
41
- agentName: profile.agentName,
42
- });
43
- }
44
-
45
32
  function extractServerAccountName(payload: any): string | undefined {
46
33
  const data = payload?.data ?? payload;
47
34
  return data?.agent_name ?? data?.agentName ?? data?.name;
48
35
  }
49
36
 
50
- function formatRegistrationError(payload: any): string | undefined {
51
- if (payload?.success !== false) return undefined;
52
- const error = payload?.error;
53
- const code = typeof error?.code === 'string' ? error.code.trim() : '';
54
- const rawMessage = typeof error?.message === 'string' ? error.message.trim() : '';
55
- const rawHint = typeof error?.hint === 'string' ? error.hint.trim() : '';
56
- const fallback = (() => {
57
- try { return JSON.stringify(error ?? payload); } catch { return String(error ?? payload); }
58
- })();
59
- const message = rawMessage || fallback || 'Unknown registration error';
60
- const hint = rawHint ? ` Hint: ${rawHint}` : '';
61
- return `Registration failed${code ? ` (${code})` : ''}: ${message}${hint}`;
37
+ function extractBackendAccountId(payload: any): string | undefined {
38
+ const data = payload?.data ?? payload;
39
+ const value = data?.id ?? data?.agent_id ?? data?.agentId;
40
+ return typeof value === 'string' && value.trim() ? value.trim() : undefined;
62
41
  }
63
42
 
64
43
  function getRegisterServerUrl(env: NodeJS.ProcessEnv = process.env): string {
@@ -70,54 +49,156 @@ function getSwitchServerUrl(authStore: AuthStore, env: NodeJS.ProcessEnv = proce
70
49
  return authStore.getActive()?.serverUrl ?? getRegisterServerUrl(env);
71
50
  }
72
51
 
73
- async function initializeOfficialStrategies(): Promise<string | undefined> {
52
+ const classifyResponse = new ResponseClassifier();
53
+ const REGISTER_CONTRACT: ResponseContract = {
54
+ id: 'clawclaw.account.register',
55
+ rules: [
56
+ {
57
+ outcome: 'failure',
58
+ when: { path: ['success'], predicate: { operator: 'equals', value: false } },
59
+ },
60
+ {
61
+ outcome: 'success',
62
+ when: [
63
+ { path: ['success'], predicate: { operator: 'equals', value: true } },
64
+ { path: ['data', 'api_key'], predicate: { operator: 'truthy' } },
65
+ { path: ['data', 'agent_name'], predicate: { operator: 'truthy' } },
66
+ ],
67
+ },
68
+ ],
69
+ default2xxOutcome: 'protocol_failure',
70
+ };
71
+ const LOGIN_CONTRACT: ResponseContract = {
72
+ id: 'clawclaw.account.login',
73
+ rules: [
74
+ {
75
+ outcome: 'failure',
76
+ when: { path: ['success'], predicate: { operator: 'equals', value: false } },
77
+ },
78
+ {
79
+ outcome: 'success',
80
+ when: [
81
+ { path: ['success'], predicate: { operator: 'equals', value: true } },
82
+ { path: ['data', 'name'], predicate: { operator: 'truthy' } },
83
+ ],
84
+ },
85
+ {
86
+ outcome: 'success',
87
+ when: [
88
+ { path: ['success'], predicate: { operator: 'equals', value: true } },
89
+ { path: ['data', 'agent_name'], predicate: { operator: 'truthy' } },
90
+ ],
91
+ },
92
+ ],
93
+ default2xxOutcome: 'protocol_failure',
94
+ };
95
+ const RENAME_CONTRACT: ResponseContract = {
96
+ id: 'clawclaw.account.rename',
97
+ rules: [
98
+ {
99
+ outcome: 'failure',
100
+ when: { path: ['success'], predicate: { operator: 'equals', value: false } },
101
+ },
102
+ {
103
+ outcome: 'success',
104
+ when: [
105
+ { path: ['success'], predicate: { operator: 'equals', value: true } },
106
+ { path: ['data', 'name'], predicate: { operator: 'truthy' } },
107
+ ],
108
+ },
109
+ ],
110
+ default2xxOutcome: 'protocol_failure',
111
+ };
112
+ const INFO_CONTRACT = booleanSuccessContract({ id: 'clawclaw.account.info' });
113
+ const SETTLEMENT_CONTRACT = booleanSuccessContract({ id: 'clawclaw.account.settlement' });
114
+
115
+ function transportFailure(error: unknown): ShortCommandOperationResult {
116
+ return {
117
+ kind: 'transport_failure',
118
+ error: {
119
+ code: 'REQUEST_FAILED',
120
+ message: error instanceof Error ? error.message : String(error),
121
+ },
122
+ };
123
+ }
124
+
125
+ function backendResult(
126
+ response: TransportResponse,
127
+ contract: ResponseContract,
128
+ presentation?: PresentationOverrides,
129
+ ): ShortCommandOperationResult {
130
+ return { kind: 'backend', response, contract, presentation };
131
+ }
132
+
133
+ function successfulRoot(
134
+ response: TransportResponse,
135
+ contract: ResponseContract,
136
+ ): Record<string, unknown> | undefined {
137
+ const classified = classifyResponse.classify(response, contract);
138
+ return classified.kind === 'success' ? classified.upstreamRoot : undefined;
139
+ }
140
+
141
+ async function refreshGamesPlayedForReminder(client: GameClient): Promise<number | undefined> {
74
142
  try {
75
- await syncOfficialStrategies();
143
+ const response = await client.requestRaw('GET', '/api/v1/agents/me');
144
+ const root = successfulRoot(response, INFO_CONTRACT);
145
+ const data = root?.data;
146
+ if (data && typeof data === 'object' && !Array.isArray(data)) {
147
+ const gamesPlayed = (data as Record<string, unknown>).games_played;
148
+ if (typeof gamesPlayed === 'number') {
149
+ writeGamesPlayedCache(gamesPlayed);
150
+ return gamesPlayed;
151
+ }
152
+ }
153
+ } catch {}
154
+ return readCachedGamesPlayed();
155
+ }
156
+
157
+ function responseErrorCode(response: TransportResponse): string | undefined {
158
+ if (response.body.kind !== 'json' || !response.body.value || typeof response.body.value !== 'object') {
76
159
  return undefined;
77
- } catch (error: any) {
78
- return `Account is ready, but official strategies could not be initialized: ${error?.message ?? String(error)}`;
79
160
  }
161
+ const root = response.body.value as Record<string, any>;
162
+ return root.error?.code ?? root.code;
80
163
  }
81
164
 
82
- async function buildCompetitionAccountInfo(client: GameClient): Promise<Record<string, any>> {
83
- let competition: Record<string, any>;
84
- try {
85
- competition = normalizeCompetitionStatusResponse(await client.getCompetitionStatus());
86
- } catch (err) {
87
- return {
88
- status: 'unavailable',
89
- active: null,
90
- is_open: null,
91
- error: serializeError(err),
92
- rank: { status: 'not_checked' },
93
- };
165
+ function withoutTutorial(root: Readonly<Record<string, unknown>>): Record<string, unknown> {
166
+ const out = { ...root };
167
+ if (out.data && typeof out.data === 'object' && !Array.isArray(out.data)) {
168
+ const data = { ...(out.data as Record<string, unknown>) };
169
+ delete data.tutorial;
170
+ out.data = data;
94
171
  }
172
+ return out;
173
+ }
95
174
 
96
- if (competition.active === false) {
97
- return {
98
- ...competition,
99
- rank: { status: 'NO_ACTIVE_COMPETITION' },
100
- };
175
+ function buildRegistrationForm(opts: {
176
+ name?: string;
177
+ desc?: string;
178
+ inviteCode: string;
179
+ avatarUrl?: string;
180
+ avatarFile?: string;
181
+ }): FormData {
182
+ const form = new FormData();
183
+ if (opts.name) form.append('name', opts.name);
184
+ if (opts.desc) form.append('description', opts.desc);
185
+ form.append('invite_code', opts.inviteCode);
186
+ if (opts.avatarUrl) form.append('avatar_url', opts.avatarUrl);
187
+ if (opts.avatarFile) {
188
+ const bytes = readFileSync(opts.avatarFile);
189
+ form.append('avatar_file', new Blob([bytes]), basename(opts.avatarFile));
101
190
  }
191
+ return form;
192
+ }
102
193
 
103
- try {
104
- return {
105
- ...competition,
106
- rank: normalizeCompetitionRankResponse(await client.getMyCompetitionRank()),
107
- };
108
- } catch (err) {
109
- return {
110
- ...competition,
111
- rank: {
112
- status: 'unavailable',
113
- error: serializeError(err),
114
- },
115
- };
116
- }
194
+ export interface CreateAccountCommandOptions {
195
+ io?: CommandIo;
117
196
  }
118
197
 
119
- export function createAccountCommand(): Command {
198
+ export function createAccountCommand(options: CreateAccountCommandOptions = {}): Command {
120
199
  const account = new Command('account');
200
+ const io = options.io ?? createProcessCommandIo();
201
+ const runner = new ShortCommandRunner();
121
202
  account.description('Account management & game data');
122
203
 
123
204
  // ─── Auth ───
@@ -131,42 +212,86 @@ export function createAccountCommand(): Command {
131
212
  .addOption(new Option('--avatar-url <url>', 'Avatar image URL').hideHelp())
132
213
  .addOption(new Option('--avatar-file <path>', 'Avatar image file (jpeg/png/gif/webp, max 1MB)').hideHelp())
133
214
  .action(async (opts: { name?: string; desc?: string; inviteCode?: string; avatarUrl?: string; avatarFile?: string }) => {
134
- const inviteCode = opts.inviteCode?.trim();
135
- if (!inviteCode) throw new Error(missingInviteCodeMessage());
136
- const authStore = new AuthStore();
137
- const { created, path: wsPath } = cmdInit();
138
- if (created) console.log(`[ClawClaw] Workspace initialized at ${wsPath}`);
139
- const serverUrl = getRegisterServerUrl();
140
-
141
- const tmpClient = new GameClient({ lobbyUrl: serverUrl, apiKey: '' });
142
- const result = await tmpClient.registerAgent({
143
- name: opts.name,
144
- description: opts.desc,
145
- inviteCode,
146
- avatarUrl: opts.avatarUrl,
147
- avatarFile: opts.avatarFile,
215
+ const inviteCode = opts.inviteCode?.trim() ?? '';
216
+ await runner.run({
217
+ descriptor: {
218
+ command: 'ccl account register',
219
+ service: 'clawclaw-lobby',
220
+ operation: 'register_agent',
221
+ sensitivePolicy: {
222
+ sensitiveValues: inviteCode ? [inviteCode] : [],
223
+ sensitiveFieldNames: ['spectate_url', 'spectateUrl'],
224
+ },
225
+ },
226
+ io,
227
+ operation: async () => {
228
+ if (!inviteCode) {
229
+ return {
230
+ kind: 'local_failure',
231
+ source: 'local',
232
+ error: { code: 'INVITE_CODE_REQUIRED', message: missingInviteCodeMessage() },
233
+ };
234
+ }
235
+
236
+ let form: FormData;
237
+ try {
238
+ form = buildRegistrationForm({
239
+ name: opts.name,
240
+ desc: opts.desc,
241
+ inviteCode,
242
+ avatarUrl: opts.avatarUrl,
243
+ avatarFile: opts.avatarFile,
244
+ });
245
+ } catch (error) {
246
+ return {
247
+ kind: 'local_failure',
248
+ source: 'local',
249
+ error: {
250
+ code: 'REGISTRATION_INPUT_FAILED',
251
+ message: error instanceof Error ? error.message : String(error),
252
+ },
253
+ };
254
+ }
255
+
256
+ const serverUrl = getRegisterServerUrl();
257
+ const tmpClient = new GameClient({ lobbyUrl: serverUrl, apiKey: '' });
258
+ let response: TransportResponse;
259
+ try {
260
+ response = await tmpClient.requestRaw('POST', '/api/v1/agents/register', form);
261
+ } catch (error) {
262
+ return transportFailure(error);
263
+ }
264
+
265
+ const root = successfulRoot(response, REGISTER_CONTRACT);
266
+ if (!root) return backendResult(response, REGISTER_CONTRACT);
267
+
268
+ const data = root.data as Record<string, unknown>;
269
+ const apiKey = String(data.api_key);
270
+ const agentName = String(data.agent_name);
271
+ const profile: AuthProfile = {
272
+ agentName,
273
+ apiKey,
274
+ serverUrl,
275
+ backendAccountId: extractBackendAccountId(root),
276
+ };
277
+ const workspace = cmdInit();
278
+ const authStore = new AuthStore();
279
+ authStore.addProfile(profile);
280
+ try { createProfileDirs(profile); } catch {}
281
+ ensureDefaultPersonaPreset(authStore);
282
+ return backendResult(response, REGISTER_CONTRACT, {
283
+ enhanceSuccess: () => ({
284
+ message: `Registered and saved as profile "${agentName}"`,
285
+ officialUrl: OFFICIAL_URL,
286
+ }),
287
+ effects: [
288
+ { name: 'workspace_init', status: 'success', data: { created: workspace.created } },
289
+ { name: 'account_profile_saved', status: 'success', data: { name: agentName } },
290
+ ],
291
+ guidance: POST_REGISTRATION_NEXT_STEP,
292
+ });
293
+ },
148
294
  });
149
- const registrationError = formatRegistrationError(result);
150
- if (registrationError) throw new Error(registrationError);
151
- const d = result.data ?? result;
152
- const apiKey = d.api_key ?? d.apiKey ?? '';
153
- if (!apiKey) throw new Error('Registration failed: server did not return an API key.');
154
- const agentName = d.agent_name ?? '';
155
- if (!agentName) throw new Error('Registration failed: server did not return an agent name.');
156
-
157
- const profile: AuthProfile = {
158
- agentName,
159
- apiKey,
160
- serverUrl,
161
- };
162
- authStore.addProfile(profile);
163
- try { createProfileDirs(profile); } catch {}
164
- ensureDefaultPersonaPreset(authStore);
165
- const strategySetupWarning = await initializeOfficialStrategies();
166
- console.log(JSON.stringify({
167
- ...registrationSuccessOutput(result, agentName),
168
- ...(strategySetupWarning ? { strategy_setup_warning: strategySetupWarning } : {}),
169
- }, null, 2));
170
295
  });
171
296
 
172
297
  account
@@ -174,84 +299,151 @@ export function createAccountCommand(): Command {
174
299
  .description('Rename agent (not during a game)')
175
300
  .action(async (newName: string) => {
176
301
  const authStore = new AuthStore();
177
- const activeKey = authStore.getActiveProfileKey();
178
302
  const profile = authStore.getActive();
179
- if (!profile) throw new Error('Not logged in.');
180
- const client = GameClient.fromAuth();
181
- const result = await client.renameAgent(newName);
182
- const oldName = profile.agentName;
183
- profile.agentName = newName;
184
- if (activeKey) authStore.removeProfileByKey(activeKey);
185
- authStore.addProfile(profile);
186
- console.log(JSON.stringify({ ...result, message: `Renamed "${oldName}" → "${newName}"` }, null, 2));
303
+ await runner.run({
304
+ descriptor: {
305
+ command: 'ccl account rename',
306
+ service: 'clawclaw-lobby',
307
+ operation: 'rename_agent',
308
+ sensitivePolicy: {
309
+ sensitiveValues: profile ? [profile.apiKey] : [],
310
+ sensitiveFieldNames: ['spectate_url', 'spectateUrl'],
311
+ },
312
+ },
313
+ io,
314
+ operation: async () => {
315
+ if (!profile) {
316
+ return {
317
+ kind: 'local_failure',
318
+ source: 'local',
319
+ error: { code: 'NO_ACTIVE_ACCOUNT', message: 'Not logged in.' },
320
+ };
321
+ }
322
+ const client = GameClient.fromAuth({ authStore });
323
+ let response: TransportResponse;
324
+ try {
325
+ response = await client.requestRaw('PATCH', '/api/v1/agents/name', { name: newName });
326
+ } catch (error) {
327
+ return transportFailure(error);
328
+ }
329
+
330
+ const root = successfulRoot(response, RENAME_CONTRACT);
331
+ if (!root) return backendResult(response, RENAME_CONTRACT);
332
+
333
+ const serverName = extractServerAccountName(root) ?? newName;
334
+ const oldName = profile.agentName;
335
+ authStore.addProfile({ ...profile, agentName: serverName });
336
+ return backendResult(response, RENAME_CONTRACT, {
337
+ enhanceSuccess: () => ({ message: `Renamed "${oldName}" to "${serverName}"` }),
338
+ effects: [{ name: 'account_profile_updated', status: 'success', data: { name: serverName } }],
339
+ });
340
+ },
341
+ });
187
342
  });
188
343
 
189
344
  account
190
- .command('switch <apiKey>', { hidden: true })
345
+ .command('switch <apiKey>')
191
346
  .description('Switch active profile by API key')
192
347
  .action(async (apiKey: string) => {
193
348
  const targetApiKey = apiKey.trim();
194
- if (!targetApiKey) throw new Error('API key is required.');
195
349
  const authStore = new AuthStore();
196
- const profileKey = authStore.findProfileKeyByApiKey(targetApiKey);
197
- if (profileKey) {
198
- authStore.switchProfile(profileKey);
199
- const strategySetupWarning = await initializeOfficialStrategies();
200
- console.log(JSON.stringify({
201
- message: 'Switched active profile',
202
- apiKey: targetApiKey,
203
- ...(strategySetupWarning ? { strategy_setup_warning: strategySetupWarning } : {}),
204
- }, null, 2));
205
- return;
206
- }
350
+ await runner.run({
351
+ descriptor: {
352
+ command: 'ccl account switch',
353
+ service: 'clawclaw-lobby',
354
+ operation: 'switch_account',
355
+ sensitivePolicy: {
356
+ sensitiveValues: targetApiKey ? [targetApiKey] : [],
357
+ sensitiveFieldNames: ['spectate_url', 'spectateUrl'],
358
+ },
359
+ },
360
+ io,
361
+ operation: async () => {
362
+ if (!targetApiKey) {
363
+ return {
364
+ kind: 'local_failure',
365
+ source: 'local',
366
+ error: { code: 'API_KEY_REQUIRED', message: 'API key is required.' },
367
+ };
368
+ }
369
+
370
+ const profileKey = authStore.findProfileKeyByApiKey(targetApiKey);
371
+ if (profileKey) {
372
+ authStore.switchProfile(profileKey);
373
+ const active = authStore.getActive();
374
+ return {
375
+ kind: 'local_success',
376
+ source: 'local',
377
+ value: {
378
+ success: true,
379
+ data: { name: active?.agentName, active: true },
380
+ message: 'Switched active profile',
381
+ },
382
+ presentation: {
383
+ effects: [
384
+ { name: 'active_profile_switched', status: 'success', data: { name: active?.agentName } },
385
+ ],
386
+ },
387
+ };
388
+ }
207
389
 
208
- const serverUrl = getSwitchServerUrl(authStore);
209
- const client = new GameClient({ lobbyUrl: serverUrl, apiKey: '' });
210
- const result = await client.login(targetApiKey);
211
- const agentName = extractServerAccountName(result);
212
- if (!agentName) throw new Error('Account switch failed: server did not return an agent name.');
213
-
214
- const profile: AuthProfile = {
215
- agentName,
216
- apiKey: targetApiKey,
217
- serverUrl,
218
- };
219
- authStore.addProfile(profile);
220
- try { createProfileDirs(profile); } catch {}
221
- ensureDefaultPersonaPreset(authStore);
222
- const strategySetupWarning = await initializeOfficialStrategies();
223
- console.log(JSON.stringify({
224
- message: 'Imported and switched active profile',
225
- name: agentName,
226
- apiKey: targetApiKey,
227
- ...(strategySetupWarning ? { strategy_setup_warning: strategySetupWarning } : {}),
228
- }, null, 2));
390
+ const serverUrl = getSwitchServerUrl(authStore);
391
+ const client = new GameClient({ lobbyUrl: serverUrl, apiKey: '' });
392
+ let response: TransportResponse;
393
+ try {
394
+ response = await client.requestRaw('POST', '/api/v1/agents/login', { api_key: targetApiKey });
395
+ } catch (error) {
396
+ return transportFailure(error);
397
+ }
398
+
399
+ const root = successfulRoot(response, LOGIN_CONTRACT);
400
+ if (!root) return backendResult(response, LOGIN_CONTRACT);
401
+
402
+ const agentName = extractServerAccountName(root)!;
403
+ const profile: AuthProfile = {
404
+ agentName,
405
+ apiKey: targetApiKey,
406
+ serverUrl,
407
+ backendAccountId: extractBackendAccountId(root),
408
+ };
409
+ authStore.addProfile(profile);
410
+ try { createProfileDirs(profile); } catch {}
411
+ ensureDefaultPersonaPreset(authStore);
412
+ return backendResult(response, LOGIN_CONTRACT, {
413
+ enhanceSuccess: () => ({ message: 'Imported and switched active profile' }),
414
+ effects: [
415
+ { name: 'account_profile_saved', status: 'success', data: { name: agentName } },
416
+ { name: 'active_profile_switched', status: 'success', data: { name: agentName } },
417
+ ],
418
+ });
419
+ },
420
+ });
229
421
  });
230
422
 
231
423
  account
232
- .command('list', { hidden: true })
233
- .description('List all saved profiles with current server names')
424
+ .command('list')
425
+ .description('List locally saved profiles without credentials')
234
426
  .action(async () => {
235
427
  const authStore = new AuthStore();
236
428
  const active = authStore.getActive();
237
429
  const data = authStore.load();
238
- const result = await Promise.all(Object.values(data.profiles).map(async (profile) => {
239
- try {
240
- const me = await createClientForProfile(profile).getMe();
241
- return {
242
- name: extractServerAccountName(me) ?? profile.agentName,
243
- apiKey: profile.apiKey,
244
- active: profile.apiKey === active?.apiKey,
245
- };
246
- } catch {
247
- return {
248
- name: profile.agentName,
249
- apiKey: profile.apiKey,
250
- active: profile.apiKey === active?.apiKey,
251
- };
252
- }
253
- }));
254
- console.log(JSON.stringify(result, null, 2));
430
+ await runner.run({
431
+ descriptor: { command: 'ccl account list', operation: 'list_saved_accounts' },
432
+ io,
433
+ operation: () => ({
434
+ kind: 'local_success',
435
+ source: 'local',
436
+ value: {
437
+ success: true,
438
+ data: {
439
+ profiles: Object.values(data.profiles).map((profile) => ({
440
+ name: profile.agentName,
441
+ active: profile.apiKey === active?.apiKey,
442
+ })),
443
+ },
444
+ },
445
+ }),
446
+ });
255
447
  });
256
448
 
257
449
  // ─── Game Data ───
@@ -272,62 +464,103 @@ export function createAccountCommand(): Command {
272
464
  .command('settlement')
273
465
  .description('Show settlement data from last game')
274
466
  .action(async () => {
275
- const client = GameClient.fromAuth();
276
- try {
277
- const result = await client.getSettlement();
278
- // `ccl account settlement` is the last command the agent runs before
279
- // writing the debrief close, and its `data` block is long enough to bury
280
- // the reminder that rode in on the `game_over` push. Re-attach it here as
281
- // the final fields (after `data`) so the nudge is the freshest thing in
282
- // context the moment the agent writes the close.
283
- const reminder = hubReminder(await refreshGamesPlayedForReminder(client));
284
- const out: Record<string, any> = (result && typeof result === 'object' && !Array.isArray(result))
285
- ? { ...result }
286
- : { result };
287
- if (reminder) {
288
- out.hub_reminder = reminder;
289
- out.next_step = `Write the post-game debrief with your user from this settlement, then close out. ${reminder}`;
290
- }
291
- console.log(JSON.stringify(out, null, 2));
292
- } catch (err: any) {
293
- if (err instanceof ApiError && err.body?.includes('NO_SETTLEMENT')) {
294
- console.info('No settlement data yet. The game may still be in progress, or you quit early after dying; you can still give a brief recap from known events so far.');
295
- return;
296
- }
297
- throw err;
298
- }
299
- });
467
+ const authStore = new AuthStore();
468
+ const profile = authStore.getActive();
469
+ await runner.run({
470
+ descriptor: {
471
+ command: 'ccl account settlement',
472
+ service: 'clawclaw-lobby',
473
+ operation: 'get_settlement',
474
+ sensitivePolicy: {
475
+ sensitiveValues: profile ? [profile.apiKey] : [],
476
+ sensitiveFieldNames: ['spectate_url', 'spectateUrl'],
477
+ },
478
+ },
479
+ io,
480
+ operation: async () => {
481
+ if (!profile) {
482
+ return {
483
+ kind: 'local_failure',
484
+ source: 'local',
485
+ error: { code: 'NO_ACTIVE_ACCOUNT', message: noAccountMessage('accountInfo') },
486
+ };
487
+ }
488
+ const client = GameClient.fromAuth({ authStore });
489
+ let response: TransportResponse;
490
+ try {
491
+ response = await client.requestRaw('GET', '/api/v1/game/settlement');
492
+ } catch (error) {
493
+ return transportFailure(error);
494
+ }
300
495
 
301
- account
302
- .command('history', { hidden: true })
303
- .description('Show game history')
304
- .option('-p, --page <number>', 'Page number', '1')
305
- .option('-l, --limit <number>', 'Items per page (max 100)', '20')
306
- .action(async (opts: { page: string; limit: string }) => {
307
- const client = GameClient.fromAuth();
308
- const result = await client.getGameHistory(Number(opts.page), Number(opts.limit));
309
- console.log(JSON.stringify(result, null, 2));
496
+ const root = successfulRoot(response, SETTLEMENT_CONTRACT);
497
+ if (!root) {
498
+ return backendResult(response, SETTLEMENT_CONTRACT, {
499
+ guidance: responseErrorCode(response) === 'NO_SETTLEMENT'
500
+ ? 'No settlement is available yet; recap from the events already observed and retry later if needed.'
501
+ : null,
502
+ });
503
+ }
504
+
505
+ const reminder = hubReminder(await refreshGamesPlayedForReminder(client));
506
+ return backendResult(response, SETTLEMENT_CONTRACT, {
507
+ guidance: reminder
508
+ ? `Write the post-game debrief with the user, then close out. ${reminder}`
509
+ : null,
510
+ });
511
+ },
512
+ });
310
513
  });
311
514
 
312
515
  account
313
516
  .command('info')
314
- .description('Print account name, Claw Key, and account status')
517
+ .description('Print the current account status without credentials or spectator links')
315
518
  .action(async () => {
316
519
  const authStore = new AuthStore();
317
520
  const profile = authStore.getActive();
318
- if (!profile) throw new Error(noAccountMessage('accountInfo'));
319
- const client = GameClient.fromAuth();
320
- const result = await client.getMe();
321
- if (result?.data) delete result.data.tutorial;
322
- const competition = await buildCompetitionAccountInfo(client);
323
- if (result?.data && typeof result.data === 'object') {
324
- result.data.competition = competition;
325
- } else if (result && typeof result === 'object') {
326
- result.competition = competition;
327
- }
328
- const gp = result?.data?.games_played;
329
- if (typeof gp === 'number') writeGamesPlayedCache(gp);
330
- console.log(JSON.stringify({ ...result, clawKey: profile.apiKey }, null, 2));
521
+ await runner.run({
522
+ descriptor: {
523
+ command: 'ccl account info',
524
+ service: 'clawclaw-lobby',
525
+ operation: 'get_account_info',
526
+ sensitivePolicy: {
527
+ sensitiveValues: profile ? [profile.apiKey] : [],
528
+ sensitiveFieldNames: [
529
+ 'spectate_url',
530
+ 'spectateUrl',
531
+ 'watch_url',
532
+ 'watchUrl',
533
+ ],
534
+ },
535
+ },
536
+ io,
537
+ operation: async () => {
538
+ if (!profile) {
539
+ return {
540
+ kind: 'local_failure',
541
+ source: 'local',
542
+ error: { code: 'NO_ACTIVE_ACCOUNT', message: noAccountMessage('accountInfo') },
543
+ };
544
+ }
545
+ const client = GameClient.fromAuth({ authStore });
546
+ let response: TransportResponse;
547
+ try {
548
+ response = await client.requestRaw('GET', '/api/v1/agents/me');
549
+ } catch (error) {
550
+ return transportFailure(error);
551
+ }
552
+
553
+ const root = successfulRoot(response, INFO_CONTRACT);
554
+ if (!root) return backendResult(response, INFO_CONTRACT);
555
+
556
+ const data = root.data;
557
+ if (data && typeof data === 'object' && !Array.isArray(data)) {
558
+ const gamesPlayed = (data as Record<string, unknown>).games_played;
559
+ if (typeof gamesPlayed === 'number') writeGamesPlayedCache(gamesPlayed);
560
+ }
561
+ return backendResult(response, INFO_CONTRACT, { projectSuccess: withoutTutorial });
562
+ },
563
+ });
331
564
  });
332
565
 
333
566
  // ── Adapter metadata (consumed by ccl _schema, applied by openclaw-clawclaw L2 generator) ──