@myclaw163/clawclaw-cli 0.6.111 → 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 +24 -7
- 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.ts +2 -9
- package/src/commands/load.test.ts +12 -2
- 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 -83
- package/src/commands/strategy.ts +175 -125
- 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 +111 -101
- 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 -678
- package/src/strategies/loader.ts +0 -212
- package/src/strategies/new-events-backfill.ts +0 -98
- package/src/strategies/paradise-fish.knowledge.md +0 -19
- 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
|
@@ -0,0 +1,952 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
ClawclawGoalStrategy,
|
|
4
|
+
ClawclawStrategy,
|
|
5
|
+
type ClawclawStrategyAction,
|
|
6
|
+
type ClawclawStrategyGameState,
|
|
7
|
+
STRATEGY_PLUGIN_API_VERSION,
|
|
8
|
+
type StrategyApi,
|
|
9
|
+
type WanderingStrategyFrame,
|
|
10
|
+
} from './index.js';
|
|
11
|
+
import type {
|
|
12
|
+
CustomModule,
|
|
13
|
+
Strategy,
|
|
14
|
+
StrategyContext,
|
|
15
|
+
} from '../../strategies/types.js';
|
|
16
|
+
import type { GameState } from '../types.js';
|
|
17
|
+
import { Action } from '../action.js';
|
|
18
|
+
|
|
19
|
+
afterEach(() => vi.useRealTimers());
|
|
20
|
+
|
|
21
|
+
class TestStrategy extends ClawclawStrategy {
|
|
22
|
+
static readonly manifest = {
|
|
23
|
+
id: 'test-strategy',
|
|
24
|
+
name: 'Test strategy',
|
|
25
|
+
description: 'A class-based strategy.',
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
parametersSnapshot(): Readonly<Record<string, unknown>> {
|
|
29
|
+
return this.parameters;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
update(
|
|
33
|
+
frame: WanderingStrategyFrame,
|
|
34
|
+
_api: StrategyApi<ClawclawStrategyAction>,
|
|
35
|
+
) {
|
|
36
|
+
return this.status({
|
|
37
|
+
activity: 'idle',
|
|
38
|
+
summary: `epoch ${frame.epochId}`,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
describe('Strategy Plugin SDK', () => {
|
|
44
|
+
it('defines one class with manifest and update as the authoring contract', () => {
|
|
45
|
+
expect(TestStrategy.apiVersion).toBe(STRATEGY_PLUGIN_API_VERSION);
|
|
46
|
+
expect(TestStrategy.manifest.id).toBe('test-strategy');
|
|
47
|
+
|
|
48
|
+
const strategy = new TestStrategy({ greeting: 'hello' });
|
|
49
|
+
expect(strategy.parametersSnapshot()).toEqual({ greeting: 'hello' });
|
|
50
|
+
expect(Object.isFrozen(strategy.parametersSnapshot())).toBe(true);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('provides the semantic strategy.status helper', async () => {
|
|
54
|
+
const strategy = new TestStrategy();
|
|
55
|
+
const result = await strategy.update({
|
|
56
|
+
epochId: 3,
|
|
57
|
+
scope: { sessionId: 'session', segmentId: 'game' },
|
|
58
|
+
stage: 'game',
|
|
59
|
+
state: { phase: 'wandering' },
|
|
60
|
+
upstreamStates: {},
|
|
61
|
+
events: [],
|
|
62
|
+
parameters: {},
|
|
63
|
+
}, {} as StrategyApi<ClawclawStrategyAction>);
|
|
64
|
+
|
|
65
|
+
expect(result).toEqual({
|
|
66
|
+
states: [{
|
|
67
|
+
topic: 'strategy.status',
|
|
68
|
+
value: { activity: 'idle', summary: 'epoch 3' },
|
|
69
|
+
}],
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('keeps one Goal tree, strictly projects GameSync v2, and refreshes only dynamic tasks', async () => {
|
|
74
|
+
let createCount = 0;
|
|
75
|
+
let mapLoadCount = 0;
|
|
76
|
+
const projected: Array<{
|
|
77
|
+
state: GameState;
|
|
78
|
+
tasks: StrategyContext['taskData'];
|
|
79
|
+
events: Array<Record<string, any>>;
|
|
80
|
+
}> = [];
|
|
81
|
+
const create = (_parameters: Readonly<Record<string, unknown>>): Strategy => {
|
|
82
|
+
createCount += 1;
|
|
83
|
+
const module: CustomModule = {
|
|
84
|
+
processEvents(events, _tick, state) {
|
|
85
|
+
projected.push({
|
|
86
|
+
state: structuredClone(state),
|
|
87
|
+
tasks: structuredClone(state.your_tasks ?? []),
|
|
88
|
+
events: structuredClone(events),
|
|
89
|
+
});
|
|
90
|
+
},
|
|
91
|
+
onMapLoaded() { mapLoadCount += 1; },
|
|
92
|
+
};
|
|
93
|
+
return {
|
|
94
|
+
name: 'fixture-goal',
|
|
95
|
+
decide: () => [],
|
|
96
|
+
customModules: () => [module],
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
class FixtureGoalStrategy extends ClawclawGoalStrategy {
|
|
100
|
+
static readonly manifest = {
|
|
101
|
+
id: 'fixture-goal',
|
|
102
|
+
name: 'Fixture Goal',
|
|
103
|
+
description: 'Exercises the npm Goal migration boundary.',
|
|
104
|
+
controls: [{
|
|
105
|
+
id: 'targets',
|
|
106
|
+
type: 'player_refs',
|
|
107
|
+
description: 'Fixture arguments.',
|
|
108
|
+
default: [],
|
|
109
|
+
}],
|
|
110
|
+
} as const;
|
|
111
|
+
|
|
112
|
+
constructor(parameters: Readonly<Record<string, unknown>> = {}) {
|
|
113
|
+
super(parameters, {
|
|
114
|
+
id: 'fixture-goal',
|
|
115
|
+
requiresTasks: true,
|
|
116
|
+
create,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const getMap = vi.fn().mockResolvedValue({
|
|
122
|
+
rooms: [{ name: 'navigation', polygon: [[0, 0], [10, 0], [10, 10], [0, 10]] }],
|
|
123
|
+
all_players: [
|
|
124
|
+
{ name: 'self', seat: 1 },
|
|
125
|
+
{ name: 'target', seat: 2 },
|
|
126
|
+
{ name: 'unknown', seat: 3 },
|
|
127
|
+
],
|
|
128
|
+
your_tasks: [],
|
|
129
|
+
all_task_locations: [{ name: 'repair', room: 'engine', x: 5, y: 6, faction: 'lobster' }],
|
|
130
|
+
});
|
|
131
|
+
const getTasks = vi.fn().mockResolvedValue([
|
|
132
|
+
{ name: 'repair', room: 'engine', x: 5, y: 6, status: 'normal' },
|
|
133
|
+
]);
|
|
134
|
+
const api: StrategyApi<ClawclawStrategyAction> = {
|
|
135
|
+
action: { submit: vi.fn().mockResolvedValue({ status: 'success' }) },
|
|
136
|
+
game: {
|
|
137
|
+
getMap,
|
|
138
|
+
getTasks,
|
|
139
|
+
pathDistance: vi.fn().mockResolvedValue(12),
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
const v2State = {
|
|
143
|
+
phase: 'wandering' as const,
|
|
144
|
+
tick: 321,
|
|
145
|
+
you: {
|
|
146
|
+
player: { seat: 1, name: 'self' },
|
|
147
|
+
role: 'shrimp_generic',
|
|
148
|
+
faction: 'lobster',
|
|
149
|
+
is_alive: true,
|
|
150
|
+
x: 10,
|
|
151
|
+
y: 20,
|
|
152
|
+
room: 'navigation',
|
|
153
|
+
completed_task_count: 1,
|
|
154
|
+
kill_cooldown_secs: 0,
|
|
155
|
+
activity: { kind: 'task', task_name: 'repair', remaining_secs: 3 },
|
|
156
|
+
},
|
|
157
|
+
players: [
|
|
158
|
+
{ seat: 1, name: 'self', known_status: { is_alive: true } },
|
|
159
|
+
{
|
|
160
|
+
seat: 2,
|
|
161
|
+
name: 'target',
|
|
162
|
+
known_status: {
|
|
163
|
+
is_alive: false,
|
|
164
|
+
death_cause: 'killed',
|
|
165
|
+
reported_in_current_meeting: true,
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
{ seat: 3, name: 'unknown', known_status: {} },
|
|
169
|
+
],
|
|
170
|
+
visible_players: [{
|
|
171
|
+
player: { seat: 3, name: 'unknown' }, x: 30, y: 40, room: 'corridor', distance: 25,
|
|
172
|
+
}],
|
|
173
|
+
visible_corpses: [{
|
|
174
|
+
player: { seat: 2, name: 'target' }, x: 31, y: 41, room: 'corridor', distance: 27,
|
|
175
|
+
}],
|
|
176
|
+
emergency: {
|
|
177
|
+
active: true, task_name: 'fix', room: 'engine', x: 5, y: 6, remaining_secs: 20,
|
|
178
|
+
},
|
|
179
|
+
crab_sabotage: {
|
|
180
|
+
status: 'cooldown_charged' as const,
|
|
181
|
+
cooldown_remaining_secs: 4,
|
|
182
|
+
},
|
|
183
|
+
} satisfies ClawclawStrategyGameState;
|
|
184
|
+
const makeFrame = (epochId: number): WanderingStrategyFrame<ClawclawStrategyGameState> => ({
|
|
185
|
+
epochId,
|
|
186
|
+
scope: { sessionId: 'session', segmentId: 'game' },
|
|
187
|
+
stage: 'game',
|
|
188
|
+
tick: 321 + epochId,
|
|
189
|
+
state: v2State,
|
|
190
|
+
upstreamStates: {},
|
|
191
|
+
events: epochId === 1 ? [{
|
|
192
|
+
eventId: 'corpse-1',
|
|
193
|
+
type: 'corpse_spotted',
|
|
194
|
+
occurredAt: '2026-07-28T09:41:00.000Z',
|
|
195
|
+
payload: {
|
|
196
|
+
actor: { seat: 1, name: 'self' },
|
|
197
|
+
target: { seat: 2, name: 'target' },
|
|
198
|
+
room: 'corridor',
|
|
199
|
+
x: 31,
|
|
200
|
+
y: 41,
|
|
201
|
+
},
|
|
202
|
+
}] : [],
|
|
203
|
+
parameters: {},
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
const instance = new FixtureGoalStrategy({ targets: ['first'] });
|
|
207
|
+
await instance.update(makeFrame(1), api);
|
|
208
|
+
await instance.update(makeFrame(2), api);
|
|
209
|
+
|
|
210
|
+
expect(createCount).toBe(1);
|
|
211
|
+
expect(getMap).toHaveBeenCalledTimes(1);
|
|
212
|
+
expect(getTasks).toHaveBeenCalledTimes(2);
|
|
213
|
+
expect(mapLoadCount).toBe(1);
|
|
214
|
+
expect(projected[0].state).toMatchObject({
|
|
215
|
+
tick: 321,
|
|
216
|
+
you: {
|
|
217
|
+
seat: 1,
|
|
218
|
+
name: 'self',
|
|
219
|
+
role: 'shrimp_generic',
|
|
220
|
+
currently_moving: false,
|
|
221
|
+
doing_task: true,
|
|
222
|
+
task_name: 'repair',
|
|
223
|
+
remaining_secs: 3,
|
|
224
|
+
},
|
|
225
|
+
players: [{ seat: 3, name: 'unknown', room: 'corridor', x: 30, y: 40 }],
|
|
226
|
+
corpses: [{ seat: 2, name: 'target', room: 'corridor', x: 31, y: 41 }],
|
|
227
|
+
alive_count: 1,
|
|
228
|
+
emergency: { task_name: 'fix', room: 'engine', x: 5, y: 6 },
|
|
229
|
+
crab_sabotage: { status: 'cooldown_charged', cooldown_remaining_secs: 4 },
|
|
230
|
+
});
|
|
231
|
+
expect(projected[0].state.all_players).toEqual([
|
|
232
|
+
{ seat: 1, name: 'self', role: 'unknown', is_alive: true },
|
|
233
|
+
{ seat: 2, name: 'target', role: 'unknown', is_alive: false },
|
|
234
|
+
{ seat: 3, name: 'unknown', role: 'unknown' },
|
|
235
|
+
]);
|
|
236
|
+
expect(projected[0].tasks).toEqual([expect.objectContaining({
|
|
237
|
+
task_id: 'repair', task_name: 'repair', room: 'engine', x: 5, y: 6,
|
|
238
|
+
})]);
|
|
239
|
+
expect(projected[0].events).toEqual([expect.objectContaining({
|
|
240
|
+
type: 'corpse_spotted',
|
|
241
|
+
actor_name: 'self',
|
|
242
|
+
target_name: 'target',
|
|
243
|
+
corpse_name: 'target',
|
|
244
|
+
corpse_room: 'corridor',
|
|
245
|
+
corpse_x: 31,
|
|
246
|
+
corpse_y: 41,
|
|
247
|
+
})]);
|
|
248
|
+
|
|
249
|
+
expect(instance.applyControl({
|
|
250
|
+
epochId: 3,
|
|
251
|
+
scope: { sessionId: 'session', segmentId: 'game' },
|
|
252
|
+
revision: 7,
|
|
253
|
+
values: { targets: ['changed'] },
|
|
254
|
+
})).toMatchObject({
|
|
255
|
+
accepted: true,
|
|
256
|
+
appliedRevision: 7,
|
|
257
|
+
effectiveValues: { targets: ['changed'] },
|
|
258
|
+
});
|
|
259
|
+
expect(createCount).toBe(2);
|
|
260
|
+
expect(mapLoadCount).toBe(2);
|
|
261
|
+
|
|
262
|
+
await instance.update(makeFrame(3), api);
|
|
263
|
+
expect(createCount).toBe(2);
|
|
264
|
+
expect(getMap).toHaveBeenCalledTimes(1);
|
|
265
|
+
expect(getTasks).toHaveBeenCalledTimes(3);
|
|
266
|
+
expect(mapLoadCount).toBe(2);
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
it('moves requested A* route work into analyzer evidence consumed by the ordered Goal context', async () => {
|
|
270
|
+
let routeEvidenceSeen: StrategyContext['routeEvidence'];
|
|
271
|
+
const strategy = new ClawclawGoalStrategy({}, {
|
|
272
|
+
id: 'route-evidence-fixture',
|
|
273
|
+
requiresTasks: true,
|
|
274
|
+
requiresMap: false,
|
|
275
|
+
routeEvidenceTargets: ['tasks'],
|
|
276
|
+
create: () => ({
|
|
277
|
+
name: 'route-evidence-fixture',
|
|
278
|
+
decide: (_state, ctx) => {
|
|
279
|
+
routeEvidenceSeen = ctx.routeEvidence;
|
|
280
|
+
return [];
|
|
281
|
+
},
|
|
282
|
+
}),
|
|
283
|
+
});
|
|
284
|
+
const frame: WanderingStrategyFrame<ClawclawStrategyGameState> = {
|
|
285
|
+
epochId: 1,
|
|
286
|
+
scope: { sessionId: 'session', segmentId: 'game' },
|
|
287
|
+
stage: 'game',
|
|
288
|
+
state: {
|
|
289
|
+
phase: 'wandering',
|
|
290
|
+
you: {
|
|
291
|
+
player: { seat: 1, name: 'self' },
|
|
292
|
+
role: 'shrimp_generic',
|
|
293
|
+
faction: 'lobster',
|
|
294
|
+
is_alive: true,
|
|
295
|
+
x: 2882,
|
|
296
|
+
y: 1362,
|
|
297
|
+
room: 'navigation',
|
|
298
|
+
activity: { kind: 'idle' },
|
|
299
|
+
},
|
|
300
|
+
},
|
|
301
|
+
upstreamStates: {},
|
|
302
|
+
events: [],
|
|
303
|
+
parameters: {},
|
|
304
|
+
};
|
|
305
|
+
const api: StrategyApi<ClawclawStrategyAction> = {
|
|
306
|
+
action: { submit: vi.fn() },
|
|
307
|
+
game: {
|
|
308
|
+
getTasks: vi.fn().mockResolvedValue([
|
|
309
|
+
{ name: 'fixture', room: 'gym', x: 2386, y: 1138, status: 'pending' },
|
|
310
|
+
]),
|
|
311
|
+
getMap: vi.fn(),
|
|
312
|
+
pathDistance: vi.fn(),
|
|
313
|
+
},
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
await strategy.update(frame, api);
|
|
317
|
+
|
|
318
|
+
expect(routeEvidenceSeen).toMatchObject({
|
|
319
|
+
from: { x: 2882, y: 1362 },
|
|
320
|
+
routes: [{ point: { x: 2386, y: 1138 }, distancePx: expect.any(Number) }],
|
|
321
|
+
});
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
it('learns Crab teammates from the authoritative nested self state', async () => {
|
|
325
|
+
let teammatesSeen: string[] = [];
|
|
326
|
+
const strategy = new ClawclawGoalStrategy({}, {
|
|
327
|
+
id: 'crab-teammate-state-fixture',
|
|
328
|
+
requiresTasks: false,
|
|
329
|
+
requiresMap: false,
|
|
330
|
+
create: () => ({
|
|
331
|
+
name: 'crab-teammate-state-fixture',
|
|
332
|
+
decide: (_state, ctx) => {
|
|
333
|
+
teammatesSeen = [...ctx.teammates];
|
|
334
|
+
return [];
|
|
335
|
+
},
|
|
336
|
+
}),
|
|
337
|
+
});
|
|
338
|
+
const frame: WanderingStrategyFrame<ClawclawStrategyGameState> = {
|
|
339
|
+
epochId: 1,
|
|
340
|
+
scope: { sessionId: 'session', segmentId: 'game' },
|
|
341
|
+
stage: 'game',
|
|
342
|
+
state: {
|
|
343
|
+
phase: 'wandering',
|
|
344
|
+
tick: 1,
|
|
345
|
+
you: {
|
|
346
|
+
player: { seat: 1, name: 'self' },
|
|
347
|
+
role: 'crab_generic',
|
|
348
|
+
faction: 'crab',
|
|
349
|
+
is_alive: true,
|
|
350
|
+
x: 10,
|
|
351
|
+
y: 20,
|
|
352
|
+
room: 'navigation',
|
|
353
|
+
activity: { kind: 'idle' },
|
|
354
|
+
crab_teammates: [{ seat: 2, name: 'ally' }],
|
|
355
|
+
},
|
|
356
|
+
},
|
|
357
|
+
upstreamStates: {},
|
|
358
|
+
events: [],
|
|
359
|
+
parameters: {},
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
await strategy.update(frame, {
|
|
363
|
+
action: { submit: vi.fn().mockResolvedValue({ status: 'success' }) },
|
|
364
|
+
game: {
|
|
365
|
+
getMap: vi.fn(),
|
|
366
|
+
getTasks: vi.fn(),
|
|
367
|
+
pathDistance: vi.fn(),
|
|
368
|
+
},
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
expect(teammatesSeen).toEqual(['ally']);
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
it('fails explicitly when a required task or map capability is unavailable', async () => {
|
|
375
|
+
const strategy = (): Strategy => ({ name: 'fixture', decide: () => [] });
|
|
376
|
+
const state = {
|
|
377
|
+
phase: 'wandering' as const,
|
|
378
|
+
you: {
|
|
379
|
+
player: { seat: 1, name: 'self' },
|
|
380
|
+
role: 'shrimp_generic',
|
|
381
|
+
faction: 'lobster',
|
|
382
|
+
is_alive: true,
|
|
383
|
+
x: 0,
|
|
384
|
+
y: 0,
|
|
385
|
+
room: 'navigation',
|
|
386
|
+
activity: { kind: 'idle' },
|
|
387
|
+
},
|
|
388
|
+
} satisfies ClawclawStrategyGameState;
|
|
389
|
+
const frame: WanderingStrategyFrame<ClawclawStrategyGameState> = {
|
|
390
|
+
epochId: 1,
|
|
391
|
+
scope: { sessionId: 'session', segmentId: 'game' },
|
|
392
|
+
stage: 'game',
|
|
393
|
+
state,
|
|
394
|
+
upstreamStates: {},
|
|
395
|
+
events: [],
|
|
396
|
+
parameters: {},
|
|
397
|
+
};
|
|
398
|
+
const unavailableTasks = new ClawclawGoalStrategy({}, {
|
|
399
|
+
id: 'needs-tasks', requiresTasks: true, create: strategy,
|
|
400
|
+
});
|
|
401
|
+
await expect(unavailableTasks.update(frame, {
|
|
402
|
+
action: { submit: vi.fn() },
|
|
403
|
+
game: {
|
|
404
|
+
getTasks: vi.fn().mockRejectedValue(new Error('not projected')),
|
|
405
|
+
getMap: vi.fn(),
|
|
406
|
+
pathDistance: vi.fn(),
|
|
407
|
+
},
|
|
408
|
+
})).rejects.toThrow('STRATEGY_CAPABILITY_UNAVAILABLE:tasks:not projected');
|
|
409
|
+
|
|
410
|
+
const fallbackDecide = vi.fn(() => []);
|
|
411
|
+
const authoritativeTasksMissing = new ClawclawGoalStrategy({}, {
|
|
412
|
+
id: 'tasks-fallback',
|
|
413
|
+
requiresTasks: true,
|
|
414
|
+
create: () => ({ name: 'tasks-fallback', decide: fallbackDecide }),
|
|
415
|
+
});
|
|
416
|
+
const fallbackResult = await authoritativeTasksMissing.update(frame, {
|
|
417
|
+
action: { submit: vi.fn() },
|
|
418
|
+
game: {
|
|
419
|
+
getTasks: vi.fn().mockRejectedValue(new Error('authoritative_tasks_unavailable')),
|
|
420
|
+
getMap: vi.fn().mockResolvedValue({
|
|
421
|
+
rooms: [{ name: 'navigation', polygon: [[0, 0], [10, 0], [10, 10], [0, 10]] }],
|
|
422
|
+
all_players: [{ name: 'self', seat: 1 }],
|
|
423
|
+
all_task_locations: [],
|
|
424
|
+
}),
|
|
425
|
+
pathDistance: vi.fn(),
|
|
426
|
+
},
|
|
427
|
+
});
|
|
428
|
+
expect(fallbackDecide).toHaveBeenCalledOnce();
|
|
429
|
+
expect(fallbackResult).toEqual({
|
|
430
|
+
states: [{
|
|
431
|
+
topic: 'strategy.status',
|
|
432
|
+
value: {
|
|
433
|
+
activity: 'idle',
|
|
434
|
+
summary: '当前没有可执行动作,正在navigation等待。',
|
|
435
|
+
room: 'navigation',
|
|
436
|
+
dataAvailability: { tasks: 'unavailable' },
|
|
437
|
+
},
|
|
438
|
+
}],
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
const unavailableMap = new ClawclawGoalStrategy({}, {
|
|
442
|
+
id: 'needs-map', create: strategy,
|
|
443
|
+
});
|
|
444
|
+
await expect(unavailableMap.update(frame, {
|
|
445
|
+
action: { submit: vi.fn() },
|
|
446
|
+
game: {
|
|
447
|
+
getTasks: vi.fn(),
|
|
448
|
+
getMap: vi.fn().mockResolvedValue(null),
|
|
449
|
+
pathDistance: vi.fn(),
|
|
450
|
+
},
|
|
451
|
+
})).rejects.toThrow('STRATEGY_CAPABILITY_UNAVAILABLE:map:no current map');
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
it('publishes semantic intent across action acknowledgement and active movement without coordinates', async () => {
|
|
455
|
+
const state = {
|
|
456
|
+
phase: 'wandering' as const,
|
|
457
|
+
tick: 12,
|
|
458
|
+
you: {
|
|
459
|
+
player: { seat: 1, name: 'self' },
|
|
460
|
+
role: 'shrimp_generic',
|
|
461
|
+
faction: 'lobster',
|
|
462
|
+
is_alive: true,
|
|
463
|
+
x: 10,
|
|
464
|
+
y: 20,
|
|
465
|
+
room: '导航仓',
|
|
466
|
+
activity: { kind: 'idle' as const },
|
|
467
|
+
},
|
|
468
|
+
players: [
|
|
469
|
+
{ seat: 1, name: 'self', known_status: { is_alive: true } },
|
|
470
|
+
{ seat: 7, name: '目标', known_status: { is_alive: true } },
|
|
471
|
+
],
|
|
472
|
+
visible_players: [{
|
|
473
|
+
player: { seat: 7, name: '目标' },
|
|
474
|
+
x: 30,
|
|
475
|
+
y: 40,
|
|
476
|
+
room: '引擎室',
|
|
477
|
+
}],
|
|
478
|
+
} satisfies ClawclawStrategyGameState;
|
|
479
|
+
const frame = (
|
|
480
|
+
epochId: number,
|
|
481
|
+
moving = false,
|
|
482
|
+
events: WanderingStrategyFrame<ClawclawStrategyGameState>['events'] = [],
|
|
483
|
+
): WanderingStrategyFrame<ClawclawStrategyGameState> => ({
|
|
484
|
+
epochId,
|
|
485
|
+
scope: { sessionId: 'session', segmentId: 'game' },
|
|
486
|
+
stage: 'game',
|
|
487
|
+
state: {
|
|
488
|
+
...state,
|
|
489
|
+
you: {
|
|
490
|
+
...state.you,
|
|
491
|
+
activity: { kind: moving ? 'moving' : 'idle' },
|
|
492
|
+
},
|
|
493
|
+
},
|
|
494
|
+
upstreamStates: {},
|
|
495
|
+
events,
|
|
496
|
+
parameters: {},
|
|
497
|
+
});
|
|
498
|
+
const map = {
|
|
499
|
+
rooms: [{ name: '导航仓', polygon: [[0, 0], [10, 0], [10, 10], [0, 10]] }],
|
|
500
|
+
all_players: [{ name: 'self', seat: 1 }, { name: '目标', seat: 7 }],
|
|
501
|
+
all_task_locations: [],
|
|
502
|
+
};
|
|
503
|
+
const apiFor = (
|
|
504
|
+
status: 'success' | 'partial' | 'deferred' | 'failure',
|
|
505
|
+
metadata: {
|
|
506
|
+
source?: 'backend' | 'transport' | 'protocol' | 'local';
|
|
507
|
+
actionOutcome?: 'confirmed' | 'not_submitted' | 'unknown';
|
|
508
|
+
} = {},
|
|
509
|
+
) => ({
|
|
510
|
+
action: { submit: vi.fn().mockResolvedValue({ status, ...metadata }) },
|
|
511
|
+
game: {
|
|
512
|
+
getTasks: vi.fn().mockResolvedValue([]),
|
|
513
|
+
getMap: vi.fn().mockResolvedValue(map),
|
|
514
|
+
pathDistance: vi.fn(),
|
|
515
|
+
},
|
|
516
|
+
}) satisfies StrategyApi<ClawclawStrategyAction>;
|
|
517
|
+
const semanticStrategy = () => ({
|
|
518
|
+
name: 'semantic',
|
|
519
|
+
decide: () => [{
|
|
520
|
+
action: Action.move({ x: 1234, y: 5678 }),
|
|
521
|
+
intent: {
|
|
522
|
+
activity: 'moving' as const,
|
|
523
|
+
summary: '正在前往引擎室执行任务“维修引擎”。',
|
|
524
|
+
room: '引擎室',
|
|
525
|
+
task: '维修引擎',
|
|
526
|
+
},
|
|
527
|
+
}],
|
|
528
|
+
});
|
|
529
|
+
|
|
530
|
+
const successApi = apiFor('success');
|
|
531
|
+
const success = new ClawclawGoalStrategy({}, {
|
|
532
|
+
id: 'semantic-success',
|
|
533
|
+
create: semanticStrategy,
|
|
534
|
+
});
|
|
535
|
+
const submitted = await success.update(frame(1), successApi);
|
|
536
|
+
expect(submitted.states?.[0].value).toEqual({
|
|
537
|
+
activity: 'moving',
|
|
538
|
+
summary: '正在前往引擎室执行任务“维修引擎”。',
|
|
539
|
+
room: '引擎室',
|
|
540
|
+
task: '维修引擎',
|
|
541
|
+
});
|
|
542
|
+
const retained = await success.update(frame(2, true), successApi);
|
|
543
|
+
await success.update(frame(3), successApi);
|
|
544
|
+
expect(successApi.action.submit).toHaveBeenCalledTimes(1);
|
|
545
|
+
expect(retained.states?.[0].value).toEqual(submitted.states?.[0].value);
|
|
546
|
+
expect(JSON.stringify(retained)).not.toContain('1234');
|
|
547
|
+
expect(JSON.stringify(retained)).not.toContain('5678');
|
|
548
|
+
|
|
549
|
+
await success.update(frame(4, false, [{
|
|
550
|
+
eventId: 'move-end-4',
|
|
551
|
+
epochId: 4,
|
|
552
|
+
type: 'move_end',
|
|
553
|
+
occurredAt: '2026-07-30T05:18:10.000Z',
|
|
554
|
+
payload: {},
|
|
555
|
+
}]), successApi);
|
|
556
|
+
expect(successApi.action.submit).toHaveBeenCalledTimes(2);
|
|
557
|
+
|
|
558
|
+
const partial = new ClawclawGoalStrategy({}, {
|
|
559
|
+
id: 'semantic-partial',
|
|
560
|
+
create: semanticStrategy,
|
|
561
|
+
});
|
|
562
|
+
expect((await partial.update(frame(1), apiFor('partial'))).states?.[0].value)
|
|
563
|
+
.toEqual(submitted.states?.[0].value);
|
|
564
|
+
|
|
565
|
+
const deferred = new ClawclawGoalStrategy({}, {
|
|
566
|
+
id: 'semantic-deferred',
|
|
567
|
+
create: semanticStrategy,
|
|
568
|
+
});
|
|
569
|
+
expect((await deferred.update(frame(1), apiFor('deferred'))).states?.[0].value).toMatchObject({
|
|
570
|
+
activity: 'waiting',
|
|
571
|
+
summary: '尚未提交前往引擎室执行任务“维修引擎”,稍后重试。',
|
|
572
|
+
room: '引擎室',
|
|
573
|
+
task: '维修引擎',
|
|
574
|
+
});
|
|
575
|
+
|
|
576
|
+
const failed = new ClawclawGoalStrategy({}, {
|
|
577
|
+
id: 'semantic-failed',
|
|
578
|
+
create: semanticStrategy,
|
|
579
|
+
});
|
|
580
|
+
expect((await failed.update(frame(1), apiFor('failure'))).states?.[0].value).toMatchObject({
|
|
581
|
+
activity: 'waiting',
|
|
582
|
+
summary: '尝试前往引擎室执行任务“维修引擎”失败,等待重试。',
|
|
583
|
+
});
|
|
584
|
+
|
|
585
|
+
const alarmDeferred = new ClawclawGoalStrategy({}, {
|
|
586
|
+
id: 'semantic-alarm-deferred',
|
|
587
|
+
create: () => ({
|
|
588
|
+
name: 'semantic-alarm-deferred',
|
|
589
|
+
decide: () => [{
|
|
590
|
+
action: Action.triggerAlarm(),
|
|
591
|
+
intent: {
|
|
592
|
+
activity: 'acting' as const,
|
|
593
|
+
summary: '破坏任务“切断电力”已完成,正在触发紧急警报。',
|
|
594
|
+
},
|
|
595
|
+
}],
|
|
596
|
+
}),
|
|
597
|
+
});
|
|
598
|
+
expect((await alarmDeferred.update(frame(1), apiFor('deferred'))).states?.[0].value)
|
|
599
|
+
.toMatchObject({
|
|
600
|
+
activity: 'waiting',
|
|
601
|
+
summary: '尚未提交触发紧急警报,稍后重试。',
|
|
602
|
+
});
|
|
603
|
+
|
|
604
|
+
const coordinateFallback = new ClawclawGoalStrategy({}, {
|
|
605
|
+
id: 'coordinate-fallback',
|
|
606
|
+
create: () => ({
|
|
607
|
+
name: 'coordinate-fallback',
|
|
608
|
+
decide: () => [{ action: Action.move({ x: 999, y: 888 }) }],
|
|
609
|
+
}),
|
|
610
|
+
});
|
|
611
|
+
const fallback = await coordinateFallback.update(frame(1), apiFor('success'));
|
|
612
|
+
expect(fallback.states?.[0].value).toMatchObject({ activity: 'moving', summary: '正在移动。' });
|
|
613
|
+
expect(JSON.stringify(fallback)).not.toContain('999');
|
|
614
|
+
expect(JSON.stringify(fallback)).not.toContain('888');
|
|
615
|
+
});
|
|
616
|
+
|
|
617
|
+
it('uses acknowledgement truth before stale doing-task state', async () => {
|
|
618
|
+
const state = {
|
|
619
|
+
phase: 'wandering' as const,
|
|
620
|
+
tick: 20,
|
|
621
|
+
you: {
|
|
622
|
+
player: { seat: 1, name: 'self' },
|
|
623
|
+
role: 'shrimp_generic',
|
|
624
|
+
faction: 'lobster',
|
|
625
|
+
is_alive: true,
|
|
626
|
+
x: 10,
|
|
627
|
+
y: 20,
|
|
628
|
+
room: '医务室',
|
|
629
|
+
activity: { kind: 'task' as const, task_name: '扫描', remaining_secs: 3 },
|
|
630
|
+
},
|
|
631
|
+
players: [{ seat: 1, name: 'self', known_status: { is_alive: true } }],
|
|
632
|
+
} satisfies ClawclawStrategyGameState;
|
|
633
|
+
const frame: WanderingStrategyFrame<ClawclawStrategyGameState> = {
|
|
634
|
+
epochId: 1,
|
|
635
|
+
scope: { sessionId: 'session', segmentId: 'game' },
|
|
636
|
+
stage: 'game',
|
|
637
|
+
state,
|
|
638
|
+
upstreamStates: {},
|
|
639
|
+
events: [],
|
|
640
|
+
parameters: {},
|
|
641
|
+
};
|
|
642
|
+
const map = {
|
|
643
|
+
rooms: [{ name: '医务室', polygon: [[0, 0], [10, 0], [10, 10], [0, 10]] }],
|
|
644
|
+
all_players: [{ name: 'self', seat: 1 }],
|
|
645
|
+
all_task_locations: [],
|
|
646
|
+
};
|
|
647
|
+
const strategy = () => ({
|
|
648
|
+
name: 'report-after-task',
|
|
649
|
+
decide: () => [{
|
|
650
|
+
action: Action.move({ x: 30, y: 40 }),
|
|
651
|
+
intent: {
|
|
652
|
+
activity: 'moving' as const,
|
|
653
|
+
summary: '正在靠近医务室的尸体,准备报告。',
|
|
654
|
+
room: '医务室',
|
|
655
|
+
},
|
|
656
|
+
}],
|
|
657
|
+
});
|
|
658
|
+
const run = async (ack: Record<string, unknown>) => {
|
|
659
|
+
const instance = new ClawclawGoalStrategy({}, { id: 'report-after-task', create: strategy });
|
|
660
|
+
return instance.update(frame, {
|
|
661
|
+
action: { submit: vi.fn().mockResolvedValue(ack) },
|
|
662
|
+
game: {
|
|
663
|
+
getTasks: vi.fn().mockResolvedValue([]),
|
|
664
|
+
getMap: vi.fn().mockResolvedValue(map),
|
|
665
|
+
pathDistance: vi.fn(),
|
|
666
|
+
},
|
|
667
|
+
} as StrategyApi<ClawclawStrategyAction>);
|
|
668
|
+
};
|
|
669
|
+
|
|
670
|
+
for (const status of ['success', 'partial'] as const) {
|
|
671
|
+
expect((await run({ status, source: 'backend', actionOutcome: 'confirmed' })).states?.[0].value)
|
|
672
|
+
.toMatchObject({
|
|
673
|
+
activity: 'moving',
|
|
674
|
+
summary: '正在靠近医务室的尸体,准备报告。',
|
|
675
|
+
});
|
|
676
|
+
}
|
|
677
|
+
expect((await run({
|
|
678
|
+
status: 'deferred', source: 'local', actionOutcome: 'not_submitted',
|
|
679
|
+
})).states?.[0].value).toMatchObject({
|
|
680
|
+
activity: 'doing_task',
|
|
681
|
+
summary: '正在医务室执行任务“扫描”。',
|
|
682
|
+
});
|
|
683
|
+
expect((await run({
|
|
684
|
+
status: 'failure', source: 'backend', actionOutcome: 'confirmed',
|
|
685
|
+
})).states?.[0].value).toMatchObject({
|
|
686
|
+
activity: 'doing_task',
|
|
687
|
+
summary: '正在医务室执行任务“扫描”。',
|
|
688
|
+
});
|
|
689
|
+
expect((await run({
|
|
690
|
+
status: 'failure', source: 'transport', actionOutcome: 'unknown',
|
|
691
|
+
})).states?.[0].value).toMatchObject({
|
|
692
|
+
activity: 'waiting',
|
|
693
|
+
summary: '靠近医务室的尸体,准备报告的结果未知,正在等待权威状态。',
|
|
694
|
+
});
|
|
695
|
+
});
|
|
696
|
+
|
|
697
|
+
it('holds an unknown non-idempotent action until authoritative State changes', async () => {
|
|
698
|
+
vi.useFakeTimers();
|
|
699
|
+
vi.setSystemTime(new Date('2026-07-29T00:00:00.000Z'));
|
|
700
|
+
const state = {
|
|
701
|
+
phase: 'wandering' as const,
|
|
702
|
+
tick: 30,
|
|
703
|
+
you: {
|
|
704
|
+
player: { seat: 1, name: 'self' },
|
|
705
|
+
role: 'crab_generic',
|
|
706
|
+
faction: 'crab',
|
|
707
|
+
is_alive: true,
|
|
708
|
+
x: 10,
|
|
709
|
+
y: 20,
|
|
710
|
+
room: '引擎室',
|
|
711
|
+
kill_cooldown_secs: 0,
|
|
712
|
+
kills_remaining: 1,
|
|
713
|
+
activity: { kind: 'idle' as const },
|
|
714
|
+
},
|
|
715
|
+
players: [
|
|
716
|
+
{ seat: 1, name: 'self', known_status: { is_alive: true } },
|
|
717
|
+
{ seat: 7, name: '目标', known_status: { is_alive: true } },
|
|
718
|
+
],
|
|
719
|
+
visible_players: [{
|
|
720
|
+
player: { seat: 7, name: '目标' }, x: 20, y: 20, room: '引擎室', distance: 10,
|
|
721
|
+
}],
|
|
722
|
+
} satisfies ClawclawStrategyGameState;
|
|
723
|
+
const frame = (
|
|
724
|
+
epochId: number,
|
|
725
|
+
targetAlive: boolean,
|
|
726
|
+
events: WanderingStrategyFrame['events'] = [],
|
|
727
|
+
): WanderingStrategyFrame<ClawclawStrategyGameState> => ({
|
|
728
|
+
epochId,
|
|
729
|
+
scope: { sessionId: 'session', segmentId: 'game' },
|
|
730
|
+
stage: 'game',
|
|
731
|
+
state: {
|
|
732
|
+
...state,
|
|
733
|
+
tick: 30 + epochId,
|
|
734
|
+
players: state.players.map(player => player.seat === 7
|
|
735
|
+
? { ...player, known_status: { is_alive: targetAlive } }
|
|
736
|
+
: player),
|
|
737
|
+
},
|
|
738
|
+
upstreamStates: {},
|
|
739
|
+
events,
|
|
740
|
+
parameters: {},
|
|
741
|
+
});
|
|
742
|
+
const submit = vi.fn()
|
|
743
|
+
.mockResolvedValueOnce({ status: 'failure', source: 'transport', actionOutcome: 'unknown' })
|
|
744
|
+
.mockResolvedValue({ status: 'success', source: 'backend', actionOutcome: 'confirmed' });
|
|
745
|
+
const instance = new ClawclawGoalStrategy({}, {
|
|
746
|
+
id: 'unknown-kill',
|
|
747
|
+
create: () => ({
|
|
748
|
+
name: 'unknown-kill',
|
|
749
|
+
decide: () => [{
|
|
750
|
+
action: Action.kill('目标'),
|
|
751
|
+
intent: { activity: 'acting', summary: '正在击杀7号目标。', targetPlayer: '目标' },
|
|
752
|
+
}],
|
|
753
|
+
}),
|
|
754
|
+
});
|
|
755
|
+
const api: StrategyApi<ClawclawStrategyAction> = {
|
|
756
|
+
action: { submit },
|
|
757
|
+
game: {
|
|
758
|
+
getTasks: vi.fn().mockResolvedValue([]),
|
|
759
|
+
getMap: vi.fn().mockResolvedValue({
|
|
760
|
+
rooms: [{ name: '引擎室', polygon: [[0, 0], [10, 0], [10, 10], [0, 10]] }],
|
|
761
|
+
all_players: [{ name: 'self', seat: 1 }, { name: '目标', seat: 7 }],
|
|
762
|
+
all_task_locations: [],
|
|
763
|
+
}),
|
|
764
|
+
pathDistance: vi.fn(),
|
|
765
|
+
},
|
|
766
|
+
};
|
|
767
|
+
|
|
768
|
+
const first = await instance.update(frame(1, true), api);
|
|
769
|
+
expect(first.states?.[0].value).toMatchObject({
|
|
770
|
+
activity: 'waiting',
|
|
771
|
+
summary: '击杀7号目标的结果未知,正在等待权威状态。',
|
|
772
|
+
});
|
|
773
|
+
const unrelatedEvent = [{
|
|
774
|
+
eventId: 'speech-1',
|
|
775
|
+
type: 'speech',
|
|
776
|
+
occurredAt: '2026-07-29T00:00:00.000Z',
|
|
777
|
+
payload: { actor: { seat: 2, name: '路人' }, text: '你好' },
|
|
778
|
+
}];
|
|
779
|
+
vi.advanceTimersByTime(10_000);
|
|
780
|
+
const held = await instance.update(frame(2, true, unrelatedEvent), api);
|
|
781
|
+
expect(submit).toHaveBeenCalledTimes(1);
|
|
782
|
+
expect(held.states?.[0].value).toEqual(first.states?.[0].value);
|
|
783
|
+
|
|
784
|
+
await instance.update(frame(3, false), api);
|
|
785
|
+
expect(submit).toHaveBeenCalledTimes(2);
|
|
786
|
+
vi.useRealTimers();
|
|
787
|
+
});
|
|
788
|
+
|
|
789
|
+
it('uses a sidecar speech submission as status only when there is no main action', async () => {
|
|
790
|
+
const state = {
|
|
791
|
+
phase: 'wandering' as const,
|
|
792
|
+
tick: 40,
|
|
793
|
+
you: {
|
|
794
|
+
player: { seat: 1, name: 'self' },
|
|
795
|
+
role: 'shrimp_generic',
|
|
796
|
+
faction: 'lobster',
|
|
797
|
+
is_alive: true,
|
|
798
|
+
x: 10,
|
|
799
|
+
y: 20,
|
|
800
|
+
room: '导航仓',
|
|
801
|
+
activity: { kind: 'idle' as const },
|
|
802
|
+
},
|
|
803
|
+
players: [{ seat: 1, name: 'self', known_status: { is_alive: true } }],
|
|
804
|
+
} satisfies ClawclawStrategyGameState;
|
|
805
|
+
const frame = (epochId: number): WanderingStrategyFrame<ClawclawStrategyGameState> => ({
|
|
806
|
+
epochId,
|
|
807
|
+
scope: { sessionId: 'session', segmentId: 'game' },
|
|
808
|
+
stage: 'game',
|
|
809
|
+
state: { ...state, tick: 40 + epochId },
|
|
810
|
+
upstreamStates: {},
|
|
811
|
+
events: [],
|
|
812
|
+
parameters: {},
|
|
813
|
+
});
|
|
814
|
+
const map = {
|
|
815
|
+
rooms: [{ name: '导航仓', polygon: [[0, 0], [10, 0], [10, 10], [0, 10]] }],
|
|
816
|
+
all_players: [{ name: 'self', seat: 1 }],
|
|
817
|
+
all_task_locations: [],
|
|
818
|
+
};
|
|
819
|
+
const api = (submit: ReturnType<typeof vi.fn>): StrategyApi<ClawclawStrategyAction> => ({
|
|
820
|
+
action: { submit },
|
|
821
|
+
game: {
|
|
822
|
+
getTasks: vi.fn().mockResolvedValue([]),
|
|
823
|
+
getMap: vi.fn().mockResolvedValue(map),
|
|
824
|
+
pathDistance: vi.fn(),
|
|
825
|
+
},
|
|
826
|
+
});
|
|
827
|
+
const speechOnly = () => ({
|
|
828
|
+
name: 'speech-only',
|
|
829
|
+
decide: () => [{
|
|
830
|
+
action: Action.speech('你好'),
|
|
831
|
+
intent: { activity: 'acting' as const, summary: '正在导航仓向附近玩家打招呼。', room: '导航仓' },
|
|
832
|
+
}],
|
|
833
|
+
});
|
|
834
|
+
|
|
835
|
+
const successSubmit = vi.fn().mockResolvedValue({
|
|
836
|
+
status: 'success', source: 'backend', actionOutcome: 'confirmed',
|
|
837
|
+
});
|
|
838
|
+
const success = new ClawclawGoalStrategy({}, {
|
|
839
|
+
id: 'speech-only', sidecarSpeech: true, create: speechOnly,
|
|
840
|
+
});
|
|
841
|
+
expect((await success.update(frame(1), api(successSubmit))).states?.[0].value).toMatchObject({
|
|
842
|
+
activity: 'acting',
|
|
843
|
+
summary: '正在导航仓向附近玩家打招呼。',
|
|
844
|
+
});
|
|
845
|
+
|
|
846
|
+
const unknownSubmit = vi.fn().mockResolvedValue({
|
|
847
|
+
status: 'failure', source: 'transport', actionOutcome: 'unknown',
|
|
848
|
+
});
|
|
849
|
+
const unknown = new ClawclawGoalStrategy({}, {
|
|
850
|
+
id: 'speech-unknown', sidecarSpeech: true, create: speechOnly,
|
|
851
|
+
});
|
|
852
|
+
const first = await unknown.update(frame(1), api(unknownSubmit));
|
|
853
|
+
expect(first.states?.[0].value).toMatchObject({
|
|
854
|
+
activity: 'waiting',
|
|
855
|
+
summary: '导航仓向附近玩家打招呼的结果未知,正在等待权威状态。',
|
|
856
|
+
});
|
|
857
|
+
const held = await unknown.update(frame(2), api(unknownSubmit));
|
|
858
|
+
expect(unknownSubmit).toHaveBeenCalledTimes(1);
|
|
859
|
+
expect(held.states?.[0].value).toEqual(first.states?.[0].value);
|
|
860
|
+
});
|
|
861
|
+
|
|
862
|
+
it('retains independent unknown holds for a main action and sidecar speech', async () => {
|
|
863
|
+
const baseState = {
|
|
864
|
+
phase: 'wandering' as const,
|
|
865
|
+
tick: 50,
|
|
866
|
+
you: {
|
|
867
|
+
player: { seat: 1, name: 'self' },
|
|
868
|
+
role: 'crab_generic',
|
|
869
|
+
faction: 'crab',
|
|
870
|
+
is_alive: true,
|
|
871
|
+
x: 10,
|
|
872
|
+
y: 20,
|
|
873
|
+
room: '引擎室',
|
|
874
|
+
kill_cooldown_secs: 0,
|
|
875
|
+
kills_remaining: 1,
|
|
876
|
+
activity: { kind: 'idle' as const },
|
|
877
|
+
},
|
|
878
|
+
players: [
|
|
879
|
+
{ seat: 1, name: 'self', known_status: { is_alive: true } },
|
|
880
|
+
{ seat: 7, name: '目标', known_status: { is_alive: true } },
|
|
881
|
+
],
|
|
882
|
+
visible_players: [{
|
|
883
|
+
player: { seat: 7, name: '目标' }, x: 20, y: 20, room: '引擎室', distance: 10,
|
|
884
|
+
}],
|
|
885
|
+
} satisfies ClawclawStrategyGameState;
|
|
886
|
+
const frame = (epochId: number, targetAlive: boolean): WanderingStrategyFrame<ClawclawStrategyGameState> => ({
|
|
887
|
+
epochId,
|
|
888
|
+
scope: { sessionId: 'session', segmentId: 'game' },
|
|
889
|
+
stage: 'game',
|
|
890
|
+
state: {
|
|
891
|
+
...baseState,
|
|
892
|
+
tick: 50 + epochId,
|
|
893
|
+
players: baseState.players.map(player => player.seat === 7
|
|
894
|
+
? { ...player, known_status: { is_alive: targetAlive } }
|
|
895
|
+
: player),
|
|
896
|
+
},
|
|
897
|
+
upstreamStates: {},
|
|
898
|
+
events: [],
|
|
899
|
+
parameters: {},
|
|
900
|
+
});
|
|
901
|
+
const submit = vi.fn().mockResolvedValue({
|
|
902
|
+
status: 'failure', source: 'transport', actionOutcome: 'unknown',
|
|
903
|
+
});
|
|
904
|
+
const instance = new ClawclawGoalStrategy({}, {
|
|
905
|
+
id: 'main-and-speech-unknown',
|
|
906
|
+
sidecarSpeech: true,
|
|
907
|
+
create: () => ({
|
|
908
|
+
name: 'main-and-speech-unknown',
|
|
909
|
+
decide: (state) => [
|
|
910
|
+
...(state.all_players?.some(player => player.name === '目标' && player.is_alive !== false)
|
|
911
|
+
? [{
|
|
912
|
+
action: Action.kill('目标'),
|
|
913
|
+
intent: { activity: 'acting' as const, summary: '正在击杀7号目标。', targetPlayer: '目标' },
|
|
914
|
+
}]
|
|
915
|
+
: []),
|
|
916
|
+
{
|
|
917
|
+
action: Action.speech('我在引擎室'),
|
|
918
|
+
intent: { activity: 'acting' as const, summary: '正在引擎室与附近玩家交流。', room: '引擎室' },
|
|
919
|
+
},
|
|
920
|
+
],
|
|
921
|
+
}),
|
|
922
|
+
});
|
|
923
|
+
const api: StrategyApi<ClawclawStrategyAction> = {
|
|
924
|
+
action: { submit },
|
|
925
|
+
game: {
|
|
926
|
+
getTasks: vi.fn().mockResolvedValue([]),
|
|
927
|
+
getMap: vi.fn().mockResolvedValue({
|
|
928
|
+
rooms: [{ name: '引擎室', polygon: [[0, 0], [10, 0], [10, 10], [0, 10]] }],
|
|
929
|
+
all_players: [{ name: 'self', seat: 1 }, { name: '目标', seat: 7 }],
|
|
930
|
+
all_task_locations: [],
|
|
931
|
+
}),
|
|
932
|
+
pathDistance: vi.fn(),
|
|
933
|
+
},
|
|
934
|
+
};
|
|
935
|
+
|
|
936
|
+
const first = await instance.update(frame(1, true), api);
|
|
937
|
+
expect(submit).toHaveBeenCalledTimes(2);
|
|
938
|
+
expect(first.states?.[0].value).toMatchObject({
|
|
939
|
+
summary: '击杀7号目标的结果未知,正在等待权威状态。',
|
|
940
|
+
});
|
|
941
|
+
|
|
942
|
+
const bothHeld = await instance.update(frame(2, true), api);
|
|
943
|
+
expect(submit).toHaveBeenCalledTimes(2);
|
|
944
|
+
expect(bothHeld.states?.[0].value).toEqual(first.states?.[0].value);
|
|
945
|
+
|
|
946
|
+
const onlySpeechHeld = await instance.update(frame(3, false), api);
|
|
947
|
+
expect(submit).toHaveBeenCalledTimes(2);
|
|
948
|
+
expect(onlySpeechHeld.states?.[0].value).toMatchObject({
|
|
949
|
+
summary: '引擎室与附近玩家交流的结果未知,正在等待权威状态。',
|
|
950
|
+
});
|
|
951
|
+
});
|
|
952
|
+
});
|