@myclaw163/clawclaw-cli 0.6.112 → 0.7.4
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.
- package/QUICKSTART.md +46 -0
- package/QUICKSTART_HERMES.md +134 -0
- package/QUICKSTART_OPENCLAW.md +134 -0
- package/QUICKSTART_OTHER.md +134 -0
- package/README.md +23 -398
- package/bin/clawclaw-cli.mjs +9 -1
- package/docs/configuration.md +197 -0
- package/docs/runtime/README.md +52 -0
- package/docs/runtime/agent-notifications.md +55 -0
- package/docs/runtime/components-and-boundaries.md +213 -0
- package/docs/runtime/events-and-state.md +105 -0
- package/docs/runtime/owner-lifecycle-and-observability.md +69 -0
- package/docs/runtime/perception-replay.md +51 -0
- package/docs/runtime/short-commands-and-capabilities.md +55 -0
- package/docs/runtime/strategy-runtime.md +111 -0
- package/docs//350/207/252/345/256/232/344/271/211/346/204/237/347/237/245.md +488 -0
- package/docs//350/207/252/345/256/232/344/271/211/347/255/226/347/225/245.md +395 -0
- package/package.json +25 -8
- package/scripts/check-skill-command-surface.mjs +16 -7
- package/scripts/compare-perception-replays.test.ts +188 -0
- package/scripts/compare-perception-replays.ts +589 -0
- package/scripts/generate-spatial-facts.py +246 -0
- package/scripts/package-readme.mjs +48 -0
- package/scripts/replay-perception.ts +347 -0
- package/scripts/sync-frontend-map.mjs +195 -0
- package/scripts/watch-perception-events.test.ts +43 -0
- package/scripts/watch-perception-events.ts +162 -0
- package/skills/clawclaw/SKILL.md +120 -64
- package/skills/clawclaw/references/CHATTERBOX.md +2 -4
- package/skills/clawclaw/references/CLAUDE-CODE-MONITOR.md +1 -1
- package/skills/clawclaw/references/COMMANDS.md +95 -61
- package/skills/clawclaw/references/GAME-MECHANICS.md +18 -8
- package/skills/clawclaw/references/HUB.md +5 -5
- package/skills/clawclaw/references/STRATEGIES.md +34 -17
- package/skills/clawclaw/references/STREAM.md +82 -46
- package/src/assets/clawclaw-map.json +1692 -0
- package/src/assets/clawclaw-spatial-facts.json +1291 -0
- package/src/cli.ts +21 -47
- package/src/commands/account.test.ts +229 -50
- package/src/commands/account.ts +456 -223
- package/src/commands/communication.test.ts +259 -0
- package/src/commands/communication.ts +391 -0
- package/src/commands/competition.test.ts +116 -0
- package/src/commands/competition.ts +50 -28
- package/src/commands/data.test.ts +57 -1
- package/src/commands/data.ts +79 -4
- package/src/commands/events-canonical-state.test.ts +187 -0
- package/src/commands/events.test.ts +50 -136
- package/src/commands/events.ts +175 -241
- package/src/commands/game/index.test.ts +510 -0
- package/src/commands/game/index.ts +556 -0
- package/src/commands/game-map.test.ts +40 -3
- package/src/commands/hub.test.ts +2 -23
- package/src/commands/hub.ts +4 -16
- package/src/commands/load.test.ts +10 -22
- package/src/commands/load.ts +15 -2
- package/src/commands/peek.ts +2 -3
- package/src/commands/perception.test.ts +46 -0
- package/src/commands/perception.ts +92 -0
- package/src/commands/setup/codex.ts +0 -1
- package/src/commands/strategy.test.ts +139 -102
- package/src/commands/strategy.ts +175 -103
- package/src/commands/upgrade.ts +0 -21
- package/src/lib/auth.test.ts +35 -0
- package/src/lib/auth.ts +45 -6
- package/src/lib/diagnostics-config.test.ts +59 -0
- package/src/lib/diagnostics-config.ts +76 -0
- package/src/lib/game-client.test.ts +166 -0
- package/src/lib/game-client.ts +316 -87
- package/src/lib/game-context.ts +29 -0
- package/src/lib/gameplay-config.test.ts +66 -0
- package/src/lib/gameplay-config.ts +151 -0
- package/src/lib/http-transport.test.ts +63 -0
- package/src/lib/http-transport.ts +76 -10
- package/src/lib/init-command.test.ts +25 -1
- package/src/lib/init-command.ts +66 -1
- package/src/lib/participation-leave.ts +78 -0
- package/src/lib/perception-config.test.ts +138 -0
- package/src/lib/perception-config.ts +101 -0
- package/src/lib/room.test.ts +14 -0
- package/src/lib/room.ts +28 -2
- package/src/lib/server-registry.test.ts +15 -5
- package/src/lib/server-registry.ts +9 -10
- package/src/lib/strategy-export.test.ts +123 -44
- package/src/lib/strategy-export.ts +110 -81
- package/src/lib/user-data.test.ts +2 -0
- package/src/lib/user-data.ts +17 -16
- package/src/pipeline/canonical-event-presentation.test.ts +195 -0
- package/src/pipeline/canonical-event-presentation.ts +71 -0
- package/src/pipeline/event-format.test.ts +357 -59
- package/src/pipeline/event-format.ts +365 -80
- package/src/pipeline/event-hints.test.ts +241 -0
- package/src/pipeline/event-hints.ts +202 -51
- package/src/pipeline/game-sync-event-normalization.test.ts +239 -0
- package/src/pipeline/game-sync-event-normalization.ts +215 -0
- package/src/pipeline/player-projection.test.ts +164 -102
- package/src/pipeline/player-projection.ts +194 -235
- package/src/runtime/canonical-event-emitter.test.ts +70 -0
- package/src/runtime/canonical-event-emitter.ts +78 -0
- package/src/runtime/canonical-monitor.test.ts +575 -0
- package/src/runtime/canonical-monitor.ts +388 -0
- package/src/runtime/clawclaw/agent-event-policy.test.ts +27 -0
- package/src/runtime/clawclaw/agent-event-policy.ts +35 -0
- package/src/runtime/clawclaw/index.ts +4 -0
- package/src/runtime/clawclaw/notifications.test.ts +47 -0
- package/src/runtime/clawclaw/notifications.ts +65 -0
- package/src/runtime/clawclaw/owner-lock.test.ts +221 -0
- package/src/runtime/clawclaw/owner.ts +945 -0
- package/src/runtime/clawclaw/plugins/action/action-plugin.ts +299 -0
- package/src/runtime/clawclaw/plugins/action/index.ts +1 -0
- package/src/runtime/clawclaw/plugins/assembly.test.ts +81 -0
- package/src/runtime/clawclaw/plugins/assembly.ts +116 -0
- package/src/runtime/clawclaw/plugins/derived-event/derived-event-plugin.test.ts +150 -0
- package/src/runtime/clawclaw/plugins/derived-event/derived-event-plugin.ts +100 -0
- package/src/runtime/clawclaw/plugins/derived-event/derived-event-rules.ts +162 -0
- package/src/runtime/clawclaw/plugins/derived-event/index.ts +2 -0
- package/src/runtime/clawclaw/plugins/game-query/game-query-plugin.test.ts +223 -0
- package/src/runtime/clawclaw/plugins/game-query/game-query-plugin.ts +236 -0
- package/src/runtime/clawclaw/plugins/game-query/index.ts +1 -0
- package/src/runtime/clawclaw/plugins/index.ts +7 -0
- package/src/runtime/clawclaw/plugins/mailbox/index.ts +3 -0
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-plugin.ts +77 -0
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-presentation.ts +91 -0
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.test.ts +1008 -0
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.ts +475 -0
- package/src/runtime/clawclaw/plugins/perception/contracts.ts +32 -0
- package/src/runtime/clawclaw/plugins/perception/index.ts +8 -0
- package/src/runtime/clawclaw/plugins/perception/module-runner.test.ts +204 -0
- package/src/runtime/clawclaw/plugins/perception/module-runner.ts +290 -0
- package/src/runtime/clawclaw/plugins/perception/modules/co-movement-module.ts +324 -0
- package/src/runtime/clawclaw/plugins/perception/modules/follow-module.ts +365 -0
- package/src/runtime/clawclaw/plugins/perception/modules/index.ts +7 -0
- package/src/runtime/clawclaw/plugins/perception/modules/motion-module.test.ts +341 -0
- package/src/runtime/clawclaw/plugins/perception/modules/motion-module.ts +447 -0
- package/src/runtime/clawclaw/plugins/perception/modules/parallel-module-test-helpers.ts +30 -0
- package/src/runtime/clawclaw/plugins/perception/modules/relation-stability.test.ts +289 -0
- package/src/runtime/clawclaw/plugins/perception/modules/route-module.test.ts +180 -0
- package/src/runtime/clawclaw/plugins/perception/modules/route-module.ts +329 -0
- package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.test.ts +82 -0
- package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.ts +172 -0
- package/src/runtime/clawclaw/plugins/perception/modules/stop-module.test.ts +212 -0
- package/src/runtime/clawclaw/plugins/perception/modules/stop-module.ts +256 -0
- package/src/runtime/clawclaw/plugins/perception/modules/temporal-evidence.test.ts +121 -0
- package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.test.ts +106 -0
- package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.ts +225 -0
- package/src/runtime/clawclaw/plugins/perception/official-module-ids.ts +11 -0
- package/src/runtime/clawclaw/plugins/perception/official-modules.ts +31 -0
- package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-pool.test.ts +759 -0
- package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-pool.ts +707 -0
- package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-worker.ts +215 -0
- package/src/runtime/clawclaw/plugins/perception/perception-module-loader.ts +61 -0
- package/src/runtime/clawclaw/plugins/perception/perception-plugin.test.ts +1516 -0
- package/src/runtime/clawclaw/plugins/perception/perception-plugin.ts +1529 -0
- package/src/runtime/clawclaw/plugins/perception/perception-source.test.ts +119 -0
- package/src/runtime/clawclaw/plugins/perception/perception-source.ts +244 -0
- package/src/runtime/clawclaw/plugins/perception/replay.test.ts +65 -0
- package/src/runtime/clawclaw/plugins/perception/replay.ts +86 -0
- package/src/runtime/clawclaw/plugins/perception/shared/math.ts +107 -0
- package/src/runtime/clawclaw/plugins/perception/spatial-facts.ts +114 -0
- package/src/runtime/clawclaw/plugins/perception/visual-state-projector.ts +98 -0
- package/src/runtime/clawclaw/plugins/runtime-plugins.test.ts +1019 -0
- package/src/runtime/clawclaw/plugins/source/game-transport.test.ts +287 -0
- package/src/runtime/clawclaw/plugins/source/game-transport.ts +281 -0
- package/src/runtime/clawclaw/plugins/source/index.ts +5 -0
- package/src/runtime/clawclaw/plugins/source/player-change-tracker.test.ts +270 -0
- package/src/runtime/clawclaw/plugins/source/player-change-tracker.ts +151 -0
- package/src/runtime/clawclaw/plugins/source/room-transport.test.ts +307 -0
- package/src/runtime/clawclaw/plugins/source/room-transport.ts +480 -0
- package/src/runtime/clawclaw/plugins/source/source-plugin.test.ts +1909 -0
- package/src/runtime/clawclaw/plugins/source/source-plugin.ts +2055 -0
- package/src/runtime/clawclaw/plugins/source/source-transports.ts +30 -0
- package/src/runtime/clawclaw/plugins/source/types.ts +79 -0
- package/src/runtime/clawclaw/plugins/strategy/context-capabilities.ts +5 -0
- package/src/runtime/clawclaw/plugins/strategy/examples/task-only-strategy.test.ts +177 -0
- package/src/runtime/clawclaw/plugins/strategy/examples/task-only-strategy.ts +185 -0
- package/src/runtime/clawclaw/plugins/strategy/index.ts +8 -0
- package/src/runtime/clawclaw/plugins/strategy/local-strategy-executor.ts +412 -0
- package/src/runtime/clawclaw/plugins/strategy/strategy-action.ts +73 -0
- package/src/runtime/clawclaw/plugins/strategy/strategy-analysis-thread-host.ts +183 -0
- package/src/runtime/clawclaw/plugins/strategy/strategy-executor-types.ts +25 -0
- package/src/runtime/clawclaw/plugins/strategy/strategy-executor.test.ts +693 -0
- package/src/runtime/clawclaw/plugins/strategy/strategy-game-api.ts +57 -0
- package/src/runtime/clawclaw/plugins/strategy/strategy-module-loader.ts +164 -0
- package/src/runtime/clawclaw/plugins/strategy/strategy-plugin.test.ts +1936 -0
- package/src/runtime/clawclaw/plugins/strategy/strategy-plugin.ts +1557 -0
- package/src/runtime/clawclaw/plugins/strategy/strategy-source.test.ts +131 -0
- package/src/runtime/clawclaw/plugins/strategy/strategy-source.ts +413 -0
- package/src/runtime/clawclaw/plugins/strategy/thread-strategy-executor.ts +792 -0
- package/src/runtime/clawclaw/runtime-data-export.test.ts +249 -0
- package/src/runtime/clawclaw/runtime-data-export.ts +402 -0
- package/src/runtime/clawclaw/runtime-state.ts +98 -0
- package/src/runtime/clawclaw/runtime.ts +133 -0
- package/src/runtime/clawclaw-event-catalog.test.ts +74 -0
- package/src/runtime/clawclaw-event-catalog.ts +266 -0
- package/src/runtime/clawclaw-position.ts +4 -0
- package/src/runtime/clawclaw-room-state.ts +51 -0
- package/src/runtime/framework/action-diagnostics.test.ts +81 -0
- package/src/runtime/framework/action-diagnostics.ts +146 -0
- package/src/runtime/framework/capability-registry.test.ts +282 -0
- package/src/runtime/framework/capability-registry.ts +283 -0
- package/src/runtime/framework/contracts.ts +118 -0
- package/src/runtime/framework/control/control-scheduler.ts +1260 -0
- package/src/runtime/framework/control/domain-set.ts +81 -0
- package/src/runtime/framework/control/index.ts +3 -0
- package/src/runtime/framework/control/types.ts +184 -0
- package/src/runtime/framework/control-coordinator.test.ts +660 -0
- package/src/runtime/framework/control-coordinator.ts +11 -0
- package/src/runtime/framework/events/event-catalog.ts +74 -0
- package/src/runtime/framework/events/event-delivery-service.test.ts +84 -0
- package/src/runtime/framework/events/event-delivery-service.ts +198 -0
- package/src/runtime/framework/events/event-ingress.test.ts +178 -0
- package/src/runtime/framework/events/event-ingress.ts +97 -0
- package/src/runtime/framework/events/event-repository.ts +59 -0
- package/src/runtime/framework/events/index.ts +7 -0
- package/src/runtime/framework/events/mailbox-event-repositories.test.ts +594 -0
- package/src/runtime/framework/events/memory-event-repository.ts +928 -0
- package/src/runtime/framework/events/sqlite-event-repository.test.ts +200 -0
- package/src/runtime/framework/events/sqlite-event-repository.ts +1681 -0
- package/src/runtime/framework/events/test-helpers.ts +78 -0
- package/src/runtime/framework/events/types.ts +286 -0
- package/src/runtime/framework/index.ts +7 -0
- package/src/runtime/framework/load-node-sqlite.ts +17 -0
- package/src/runtime/framework/mailbox/coalescer.test.ts +55 -0
- package/src/runtime/framework/mailbox/coalescer.ts +83 -0
- package/src/runtime/framework/mailbox/host-notification-sink.ts +44 -0
- package/src/runtime/framework/mailbox/identity.test.ts +38 -0
- package/src/runtime/framework/mailbox/identity.ts +38 -0
- package/src/runtime/framework/mailbox/index.ts +7 -0
- package/src/runtime/framework/mailbox/mailbox-dispatcher.test.ts +513 -0
- package/src/runtime/framework/mailbox/mailbox-dispatcher.ts +282 -0
- package/src/runtime/framework/mailbox/mailbox-repository.ts +44 -0
- package/src/runtime/framework/mailbox/notification-projector.test.ts +77 -0
- package/src/runtime/framework/mailbox/notification-projector.ts +65 -0
- package/src/runtime/framework/mailbox/types.ts +139 -0
- package/src/runtime/framework/modules/runtime-module-loader-hooks.d.mts +19 -0
- package/src/runtime/framework/modules/runtime-module-loader-hooks.mjs +117 -0
- package/src/runtime/framework/modules/runtime-module-loader.test.ts +209 -0
- package/src/runtime/framework/modules/runtime-module-loader.ts +71 -0
- package/src/runtime/framework/modules/runtime-module-worker-bootstrap.mjs +23 -0
- package/src/runtime/framework/participation-manager.test.ts +108 -0
- package/src/runtime/framework/participation-manager.ts +244 -0
- package/src/runtime/framework/plugins/contracts.ts +382 -0
- package/src/runtime/framework/plugins/index.ts +4 -0
- package/src/runtime/framework/plugins/runtime-event-identity.ts +17 -0
- package/src/runtime/framework/plugins/runtime-input-journal.test.ts +179 -0
- package/src/runtime/framework/plugins/runtime-input-journal.ts +693 -0
- package/src/runtime/framework/plugins/runtime-plugin-scheduler.test.ts +1994 -0
- package/src/runtime/framework/plugins/runtime-plugin-scheduler.ts +1860 -0
- package/src/runtime/framework/runtime.ts +1756 -0
- package/src/runtime/framework/serial-task-queue.ts +14 -0
- package/src/runtime/framework/state/contracts.ts +49 -0
- package/src/runtime/framework/state/current-state-store.ts +184 -0
- package/src/runtime/framework/state/durable-agent-state-snapshot.test.ts +144 -0
- package/src/runtime/framework/state/durable-agent-state-snapshot.ts +209 -0
- package/src/runtime/framework/state/freshness.ts +72 -0
- package/src/runtime/framework/state/history/contracts.ts +150 -0
- package/src/runtime/framework/state/history/history-writer.ts +194 -0
- package/src/runtime/framework/state/history/memory-state-history-repository.ts +178 -0
- package/src/runtime/framework/state/history/sqlite-state-history-repository.test.ts +157 -0
- package/src/runtime/framework/state/history/sqlite-state-history-repository.ts +629 -0
- package/src/runtime/framework/state/history/state-history.test.ts +251 -0
- package/src/runtime/framework/state/history/trajectory-projector.ts +209 -0
- package/src/runtime/framework/state/index.ts +13 -0
- package/src/runtime/framework/state/state-core.test.ts +197 -0
- package/src/runtime/framework/state/state-ingress.ts +95 -0
- package/src/runtime/framework/state/state-provider.ts +62 -0
- package/src/runtime/framework/state/types.ts +155 -0
- package/src/runtime/game-sync-protocol.test.ts +123 -0
- package/src/runtime/game-sync-protocol.ts +261 -0
- package/src/runtime/mailbox-host-relay.test.ts +248 -0
- package/src/runtime/mailbox-host-relay.ts +300 -0
- package/src/runtime/observability/factory.ts +188 -0
- package/src/runtime/observability/index.ts +6 -0
- package/src/runtime/observability/observability.test.ts +561 -0
- package/src/runtime/observability/recorder.ts +209 -0
- package/src/runtime/observability/redaction.ts +154 -0
- package/src/runtime/observability/reporter.ts +154 -0
- package/src/runtime/observability/sinks.ts +135 -0
- package/src/runtime/observability/types.ts +92 -0
- package/src/runtime/owner-control.test.ts +153 -0
- package/src/runtime/owner-control.ts +206 -42
- package/src/runtime/parent-process-watch.test.ts +27 -0
- package/src/runtime/parent-process-watch.ts +51 -0
- package/src/runtime/pending-event-handoff.test.ts +29 -0
- package/src/runtime/pending-event-handoff.ts +61 -0
- package/src/runtime/raw-ws-log.test.ts +86 -17
- package/src/runtime/raw-ws-log.ts +230 -21
- package/src/runtime/runtime-logger.test.ts +58 -0
- package/src/runtime/runtime-logger.ts +10 -13
- package/src/runtime/runtime-persistence.test.ts +26 -0
- package/src/runtime/runtime.test.ts +1704 -0
- package/src/runtime/ws-client.test.ts +496 -103
- package/src/runtime/ws-client.ts +546 -166
- package/src/sdk/action.ts +3 -1
- package/src/sdk/index.ts +4 -19
- package/src/sdk/perception-plugin/index.test.ts +22 -0
- package/src/sdk/perception-plugin/index.ts +285 -0
- package/src/sdk/strategy-plugin/index.test.ts +952 -0
- package/src/sdk/strategy-plugin/index.ts +1324 -0
- package/src/sdk/types.ts +3 -1
- package/src/short-command/classifier.test.ts +107 -0
- package/src/short-command/classifier.ts +169 -0
- package/src/short-command/index.ts +7 -0
- package/src/short-command/presenter.test.ts +119 -0
- package/src/short-command/presenter.ts +308 -0
- package/src/short-command/process-io.ts +13 -0
- package/src/short-command/response-contract.ts +58 -0
- package/src/short-command/runner.test.ts +78 -0
- package/src/short-command/runner.ts +164 -0
- package/src/short-command/sensitive-data-filter.test.ts +56 -0
- package/src/short-command/sensitive-data-filter.ts +123 -0
- package/src/short-command/transport-response.test.ts +39 -0
- package/src/short-command/transport-response.ts +89 -0
- package/src/short-command/types.ts +92 -0
- package/src/strategies/avoid-lone.ts +18 -11
- package/src/strategies/avoid-players.ts +29 -13
- package/src/strategies/corpse-patrol.ts +29 -11
- package/src/strategies/crab-sabotage.ts +31 -18
- package/src/strategies/custom-module.test.ts +3 -5
- package/src/strategies/find-player.ts +34 -15
- package/src/strategies/game-utils.test.ts +42 -0
- package/src/strategies/game-utils.ts +143 -53
- package/src/strategies/goals/avoid-lone-top.ts +22 -1
- package/src/strategies/goals/avoid-players-top.test.ts +13 -0
- package/src/strategies/goals/avoid-players-top.ts +6 -5
- package/src/strategies/goals/corpse-patrol-top.ts +9 -2
- package/src/strategies/goals/crab-octopus-reflexes.ts +6 -2
- package/src/strategies/goals/crab-sabotage-top.ts +7 -1
- package/src/strategies/goals/emergency-hunt-goal.ts +15 -3
- package/src/strategies/goals/find-player-top.ts +47 -3
- package/src/strategies/goals/flee-players-goal.ts +2 -0
- package/src/strategies/goals/follow-companion-goal.ts +27 -3
- package/src/strategies/goals/hide-top.ts +47 -5
- package/src/strategies/goals/keep-away-goal.ts +24 -2
- package/src/strategies/goals/kill-frenzy-top.ts +12 -2
- package/src/strategies/goals/kill-lone-top.test.ts +72 -0
- package/src/strategies/goals/kill-lone-top.ts +8 -6
- package/src/strategies/goals/kill-target-goal.ts +16 -7
- package/src/strategies/goals/kill-target-top.ts +16 -2
- package/src/strategies/goals/linger-corpse-goal.ts +11 -3
- package/src/strategies/goals/lone-kill-core.ts +4 -2
- package/src/strategies/goals/move-room-goal.ts +46 -4
- package/src/strategies/goals/normal-shrimp-top.test.ts +16 -0
- package/src/strategies/goals/normal-shrimp-top.ts +18 -18
- package/src/strategies/goals/paradise-fish-top.test.ts +78 -0
- package/src/strategies/goals/paradise-fish-top.ts +16 -6
- package/src/strategies/goals/patrol-top.ts +14 -3
- package/src/strategies/goals/report-patrol-top.ts +14 -3
- package/src/strategies/goals/safe-task-goal.ts +32 -4
- package/src/strategies/goals/social-task-top.ts +39 -8
- package/src/strategies/goals/task-kill-report-top.ts +33 -10
- package/src/strategies/goals/task-only-top.test.ts +89 -0
- package/src/strategies/goals/task-only-top.ts +9 -2
- package/src/strategies/goals/task-or-patrol-goal.ts +21 -3
- package/src/strategies/goals/warrior-shrimp-top.test.ts +75 -23
- package/src/strategies/goals/warrior-shrimp-top.ts +34 -13
- package/src/strategies/greeting.ts +10 -3
- package/src/strategies/hide-spots.ts +4 -0
- package/src/strategies/hide.ts +35 -20
- package/src/strategies/kill-frenzy.ts +18 -12
- package/src/strategies/kill-lone.ts +43 -12
- package/src/strategies/kill-target.ts +34 -17
- package/src/strategies/lone-kill-task.ts +31 -18
- package/src/strategies/move-room.ts +32 -15
- package/src/strategies/off-route-points.ts +12 -4
- package/src/strategies/paradise-fish.ts +49 -14
- package/src/strategies/pathfind/astar-path.test.ts +73 -0
- package/src/strategies/pathfind/astar-path.ts +196 -0
- package/src/strategies/pathfind/escape-planner.test.ts +27 -1
- package/src/strategies/pathfind/escape-planner.ts +108 -0
- package/src/strategies/patrol.ts +18 -11
- package/src/strategies/report-patrol.ts +18 -11
- package/src/strategies/shrimp-memory.ts +66 -14
- package/src/strategies/social-task.ts +49 -45
- package/src/strategies/task-kill-report.ts +34 -16
- package/src/strategies/task-only.test.ts +124 -0
- package/src/strategies/task-only.ts +20 -11
- package/src/strategies/task-report.ts +29 -11
- package/src/strategies/types.ts +29 -62
- package/src/strategies/warrior-memory.ts +44 -14
- package/scripts/check_monitor.test.mjs +0 -212
- package/skills/clawclaw/references/KNOWLEDGE.md +0 -42
- package/src/commands/do.test.ts +0 -117
- package/src/commands/do.ts +0 -195
- package/src/commands/game-monitor-status.test.ts +0 -58
- package/src/commands/game-start-plan.test.ts +0 -356
- package/src/commands/game.ts +0 -2046
- package/src/commands/history-player.test.ts +0 -105
- package/src/commands/history.ts +0 -573
- package/src/commands/knowledge.test.ts +0 -13
- package/src/commands/knowledge.ts +0 -176
- package/src/commands/meeting-history.test.ts +0 -106
- package/src/commands/state.ts +0 -46
- package/src/commands/watch.test.ts +0 -1313
- package/src/commands/watch.ts +0 -824
- package/src/lib/knowledge-store.test.ts +0 -170
- package/src/lib/knowledge-store.ts +0 -369
- package/src/perception/player-history-store.test.ts +0 -177
- package/src/perception/player-history-store.ts +0 -262
- package/src/pipeline/event-store.test.ts +0 -28
- package/src/pipeline/event-store.ts +0 -193
- package/src/pipeline/pipeline.ts +0 -35
- package/src/runtime/event-daemon.test.ts +0 -268
- package/src/runtime/event-daemon.ts +0 -531
- package/src/runtime/room-lobby-runtime.test.ts +0 -95
- package/src/runtime/room-lobby-runtime.ts +0 -367
- package/src/strategies/avoid-players.knowledge.md +0 -19
- package/src/strategies/kill-lone.knowledge.md +0 -17
- package/src/strategies/knowledge-contract.ts +0 -85
- package/src/strategies/loader.test.ts +0 -710
- package/src/strategies/loader.ts +0 -183
- package/src/strategies/new-events-backfill.ts +0 -98
- package/src/strategies/paradise-fish.knowledge.md +0 -19
- package/src/strategies/scanner.ts +0 -238
- package/src/strategies/shrimp-memory.knowledge.md +0 -19
- package/src/strategies/social-task.test.ts +0 -28
- package/src/strategies/spawn.ts +0 -82
- package/src/strategies/strategy-loop.test.ts +0 -15
- package/src/strategies/strategy-loop.ts +0 -748
- package/src/strategies/warrior-memory.knowledge.md +0 -21
package/src/commands/account.ts
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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 {
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
-
|
|
104
|
-
|
|
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
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
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>'
|
|
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
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
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
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
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'
|
|
233
|
-
.description('List
|
|
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
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
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
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
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
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
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
|
|
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
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
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) ──
|