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