@myclaw163/clawclaw-cli 0.7.16 → 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 +1 -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 +285 -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 +388 -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 -2175
- package/src/runtime/clawclaw/plugins/strategy/strategy-plugin.ts +0 -1774
- 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
|
@@ -0,0 +1,766 @@
|
|
|
1
|
+
import { loadClawclawMapAsset } from '../../../../lib/game-context.js';
|
|
2
|
+
import { normalizeGameState } from '../../../../lib/normalize.js';
|
|
3
|
+
import { CorpseMemory } from '../../../../strategies/game-utils.js';
|
|
4
|
+
import { HIDE_SPOTS } from '../../../../strategies/hide-spots.js';
|
|
5
|
+
import {
|
|
6
|
+
buildRouteEvidence,
|
|
7
|
+
type RouteEvidence,
|
|
8
|
+
} from '../../../../strategies/pathfind/escape-planner.js';
|
|
9
|
+
import type {
|
|
10
|
+
BehaviorDecision as GoalBehaviorDecision,
|
|
11
|
+
CustomModule,
|
|
12
|
+
RoomTarget,
|
|
13
|
+
Strategy,
|
|
14
|
+
StrategyContext,
|
|
15
|
+
StrategyIntent,
|
|
16
|
+
StrategyIntentActivity,
|
|
17
|
+
} from '../../../../strategies/types.js';
|
|
18
|
+
import type {
|
|
19
|
+
BehaviorDecision,
|
|
20
|
+
BehaviorReadApi,
|
|
21
|
+
GameAction,
|
|
22
|
+
} from '../../../../sdk/behavior-plugin/index.js';
|
|
23
|
+
import type {
|
|
24
|
+
BehaviorInput,
|
|
25
|
+
GameState,
|
|
26
|
+
Position,
|
|
27
|
+
} from '../../../../sdk/module-input/index.js';
|
|
28
|
+
import type {
|
|
29
|
+
EmergencyInfo,
|
|
30
|
+
GameState as GoalGameState,
|
|
31
|
+
TaskInfo,
|
|
32
|
+
} from '../../../../sdk/types.js';
|
|
33
|
+
|
|
34
|
+
const RECENT_KILL_IGNORE_MS = 3_000;
|
|
35
|
+
|
|
36
|
+
/** Package-internal input helper for bundled Behavior implementations. */
|
|
37
|
+
export function clawclawStrategyStringList(
|
|
38
|
+
parameters: Readonly<Record<string, unknown>>,
|
|
39
|
+
controlId: string,
|
|
40
|
+
): string[] {
|
|
41
|
+
const value = parameters[controlId];
|
|
42
|
+
return Array.isArray(value)
|
|
43
|
+
? value.filter((entry): entry is string => typeof entry === 'string')
|
|
44
|
+
: [];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Package-internal input helper for bundled Behavior implementations. */
|
|
48
|
+
export function clawclawStrategyString(
|
|
49
|
+
parameters: Readonly<Record<string, unknown>>,
|
|
50
|
+
controlId: string,
|
|
51
|
+
): string {
|
|
52
|
+
const value = parameters[controlId];
|
|
53
|
+
return typeof value === 'string' ? value : '';
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface OfficialGoalTask extends Position {
|
|
57
|
+
readonly name: string;
|
|
58
|
+
readonly room: string;
|
|
59
|
+
readonly status: string;
|
|
60
|
+
readonly is_fake_shrimp?: boolean;
|
|
61
|
+
readonly task_note?: string;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
interface OfficialGoalTaskLocation extends Position {
|
|
65
|
+
readonly name: string;
|
|
66
|
+
readonly room?: string;
|
|
67
|
+
readonly faction?: 'lobster' | 'crab';
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
interface OfficialGoalMapInfo {
|
|
71
|
+
readonly rooms: readonly {
|
|
72
|
+
readonly name: string;
|
|
73
|
+
readonly polygon: readonly (readonly [number, number])[];
|
|
74
|
+
}[];
|
|
75
|
+
readonly all_players: readonly {
|
|
76
|
+
readonly name: string;
|
|
77
|
+
readonly seat: number;
|
|
78
|
+
}[];
|
|
79
|
+
readonly your_tasks?: readonly OfficialGoalTask[];
|
|
80
|
+
readonly all_task_locations: readonly OfficialGoalTaskLocation[];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
interface OfficialBehaviorStatusState {
|
|
84
|
+
readonly activity: StrategyIntentActivity;
|
|
85
|
+
readonly summary: string;
|
|
86
|
+
readonly room?: string;
|
|
87
|
+
readonly task?: string;
|
|
88
|
+
readonly targetPlayer?: string;
|
|
89
|
+
readonly dataAvailability?: Readonly<{
|
|
90
|
+
readonly tasks?: 'available' | 'unavailable';
|
|
91
|
+
}>;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
interface OfficialGoalBehaviorOptions {
|
|
95
|
+
readonly id: string;
|
|
96
|
+
readonly requiresTasks?: boolean;
|
|
97
|
+
/** Defaults to true. Task-only behaviors can avoid copying the static map every epoch. */
|
|
98
|
+
readonly requiresMap?: boolean;
|
|
99
|
+
readonly sidecarSpeech?: boolean;
|
|
100
|
+
/** Static target groups whose current-frame A* routes should be analyzed off-thread. */
|
|
101
|
+
readonly routeEvidenceTargets?: readonly ('tasks' | 'rooms' | 'hide')[];
|
|
102
|
+
/** Return a user-facing reason when declared input fields are not ready yet. */
|
|
103
|
+
readonly validateParameters?: (parameters: Readonly<Record<string, unknown>>) => string | undefined;
|
|
104
|
+
readonly create: (parameters: Readonly<Record<string, unknown>>) => Strategy;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
interface OfficialGoalBehaviorResources {
|
|
108
|
+
readonly tasks: readonly OfficialGoalTask[] | null;
|
|
109
|
+
readonly tasksAvailable: boolean;
|
|
110
|
+
readonly map?: Readonly<OfficialGoalMapInfo>;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function sameControlValue(left: unknown, right: unknown): boolean {
|
|
114
|
+
if (Object.is(left, right)) return true;
|
|
115
|
+
if (!Array.isArray(left) || !Array.isArray(right) || left.length !== right.length) return false;
|
|
116
|
+
return left.every((value, index) => Object.is(value, right[index]));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function sameBehaviorInput(
|
|
120
|
+
left: Readonly<Record<string, unknown>>,
|
|
121
|
+
right: Readonly<Record<string, unknown>>,
|
|
122
|
+
): boolean {
|
|
123
|
+
const leftKeys = Object.keys(left);
|
|
124
|
+
const rightKeys = Object.keys(right);
|
|
125
|
+
return leftKeys.length === rightKeys.length
|
|
126
|
+
&& leftKeys.every(key => Object.hasOwn(right, key) && sameControlValue(left[key], right[key]));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function projectedPlayerRef(value: unknown): Record<string, any> {
|
|
130
|
+
return value && typeof value === 'object' && !Array.isArray(value)
|
|
131
|
+
? value as Record<string, any>
|
|
132
|
+
: {};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function frameEvents(frame: BehaviorInput): Record<string, any>[] {
|
|
136
|
+
return frame.events.map((event) => {
|
|
137
|
+
const payload = event.payload as Record<string, any>;
|
|
138
|
+
const actor = projectedPlayerRef(payload.actor);
|
|
139
|
+
const target = projectedPlayerRef(payload.target);
|
|
140
|
+
const killer = projectedPlayerRef(payload.killer);
|
|
141
|
+
return {
|
|
142
|
+
...payload,
|
|
143
|
+
type: event.type,
|
|
144
|
+
...(typeof actor.name === 'string' ? { actor_name: actor.name } : {}),
|
|
145
|
+
...(typeof target.name === 'string' ? { target_name: target.name } : {}),
|
|
146
|
+
...(typeof killer.name === 'string' ? { killer_name: killer.name } : {}),
|
|
147
|
+
...(event.type === 'corpse_spotted' ? {
|
|
148
|
+
...(typeof target.name === 'string' ? { corpse_name: target.name } : {}),
|
|
149
|
+
...(typeof payload.room === 'string' ? { corpse_room: payload.room } : {}),
|
|
150
|
+
...(Number.isFinite(Number(payload.x)) ? { corpse_x: Number(payload.x) } : {}),
|
|
151
|
+
...(Number.isFinite(Number(payload.y)) ? { corpse_y: Number(payload.y) } : {}),
|
|
152
|
+
} : {}),
|
|
153
|
+
};
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** Project the documented GameSync v2 player view into the bundled Goal contract. */
|
|
158
|
+
function projectGoalGameState(
|
|
159
|
+
source: Readonly<GameState>,
|
|
160
|
+
events: readonly Record<string, any>[],
|
|
161
|
+
): GoalGameState {
|
|
162
|
+
const raw = source as Readonly<Record<string, any>>;
|
|
163
|
+
const rawYou = projectedPlayerRef(raw.you);
|
|
164
|
+
const self = projectedPlayerRef(rawYou.player);
|
|
165
|
+
const activity = projectedPlayerRef(rawYou.activity);
|
|
166
|
+
const visiblePlayers = (Array.isArray(raw.visible_players) ? raw.visible_players : [])
|
|
167
|
+
.map((entry: unknown) => {
|
|
168
|
+
const visible = projectedPlayerRef(entry);
|
|
169
|
+
return { ...projectedPlayerRef(visible.player), ...visible };
|
|
170
|
+
})
|
|
171
|
+
.map(({ player: _player, ...visible }) => visible);
|
|
172
|
+
const visibleCorpses = (Array.isArray(raw.visible_corpses) ? raw.visible_corpses : [])
|
|
173
|
+
.map((entry: unknown) => {
|
|
174
|
+
const corpse = projectedPlayerRef(entry);
|
|
175
|
+
return { ...projectedPlayerRef(corpse.player), ...corpse };
|
|
176
|
+
})
|
|
177
|
+
.map(({ player: _player, ...corpse }) => corpse);
|
|
178
|
+
const knownPlayers = (Array.isArray(raw.players) ? raw.players : []).map((entry: unknown) => {
|
|
179
|
+
const player = projectedPlayerRef(entry);
|
|
180
|
+
const knownStatus = projectedPlayerRef(player.known_status);
|
|
181
|
+
return {
|
|
182
|
+
seat: player.seat,
|
|
183
|
+
name: player.name,
|
|
184
|
+
role: 'unknown',
|
|
185
|
+
...(typeof knownStatus.is_alive === 'boolean'
|
|
186
|
+
? { is_alive: knownStatus.is_alive }
|
|
187
|
+
: {}),
|
|
188
|
+
};
|
|
189
|
+
});
|
|
190
|
+
return normalizeGameState({
|
|
191
|
+
...raw,
|
|
192
|
+
you: {
|
|
193
|
+
...rawYou,
|
|
194
|
+
...self,
|
|
195
|
+
currently_moving: activity.kind === 'moving',
|
|
196
|
+
doing_task: activity.kind === 'task',
|
|
197
|
+
...(activity.kind === 'task' && typeof activity.task_name === 'string'
|
|
198
|
+
? { task_name: activity.task_name }
|
|
199
|
+
: {}),
|
|
200
|
+
...(typeof activity.remaining_secs === 'number'
|
|
201
|
+
? { remaining_secs: activity.remaining_secs }
|
|
202
|
+
: {}),
|
|
203
|
+
},
|
|
204
|
+
players: visiblePlayers,
|
|
205
|
+
visible_players: visiblePlayers,
|
|
206
|
+
corpses: visibleCorpses,
|
|
207
|
+
nearby_corpses: visibleCorpses,
|
|
208
|
+
all_players: knownPlayers,
|
|
209
|
+
...(raw.alive_count === undefined
|
|
210
|
+
? { alive_count: knownPlayers.filter((player) => player.is_alive === true).length }
|
|
211
|
+
: {}),
|
|
212
|
+
...(raw.emergency?.active === true
|
|
213
|
+
? { emergency: raw.emergency }
|
|
214
|
+
: { emergency: undefined }),
|
|
215
|
+
new_events: events,
|
|
216
|
+
stale: false,
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function point(value: unknown): { x: number; y: number } | null {
|
|
221
|
+
if (!value || typeof value !== 'object') return null;
|
|
222
|
+
const entry = value as Record<string, unknown>;
|
|
223
|
+
const x = Number(entry.x ?? (Array.isArray(value) ? value[0] : undefined));
|
|
224
|
+
const y = Number(entry.y ?? (Array.isArray(value) ? value[1] : undefined));
|
|
225
|
+
return Number.isFinite(x) && Number.isFinite(y) ? { x, y } : null;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function roomTarget(
|
|
229
|
+
room: OfficialGoalMapInfo['rooms'][number],
|
|
230
|
+
taskLocations: readonly OfficialGoalTaskLocation[],
|
|
231
|
+
): RoomTarget {
|
|
232
|
+
const task = taskLocations.find((candidate) => candidate.room === room.name);
|
|
233
|
+
if (task) return { name: room.name, x: task.x, y: task.y };
|
|
234
|
+
const polygon = room.polygon.map(point).filter((value): value is { x: number; y: number } => !!value);
|
|
235
|
+
if (polygon.length === 0) return { name: room.name, x: 0, y: 0 };
|
|
236
|
+
return {
|
|
237
|
+
name: room.name,
|
|
238
|
+
x: polygon.reduce((sum, value) => sum + value.x, 0) / polygon.length,
|
|
239
|
+
y: polygon.reduce((sum, value) => sum + value.y, 0) / polygon.length,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function packagedGoalMap(
|
|
244
|
+
gameState: Readonly<GameState>,
|
|
245
|
+
spatialRooms: BehaviorReadApi['spatial']['rooms'],
|
|
246
|
+
): Readonly<OfficialGoalMapInfo> {
|
|
247
|
+
const asset = loadClawclawMapAsset();
|
|
248
|
+
const rooms = spatialRooms.map(room => ({
|
|
249
|
+
name: room.name,
|
|
250
|
+
polygon: structuredClone(room.polygon),
|
|
251
|
+
}));
|
|
252
|
+
const allTaskLocations = (Array.isArray(asset?.tasks) ? asset.tasks : [])
|
|
253
|
+
.map((task: Record<string, any>) => ({
|
|
254
|
+
name: String(task.name ?? ''),
|
|
255
|
+
room: typeof task.room === 'string' ? task.room : undefined,
|
|
256
|
+
x: Number(task.x),
|
|
257
|
+
y: Number(task.y),
|
|
258
|
+
faction: Number(task.task_type) === 1 ? 'crab' as const : 'lobster' as const,
|
|
259
|
+
}))
|
|
260
|
+
.filter((task: OfficialGoalTaskLocation) => (
|
|
261
|
+
task.name && Number.isFinite(task.x) && Number.isFinite(task.y)
|
|
262
|
+
));
|
|
263
|
+
const allPlayers = (gameState.players ?? []).flatMap(player => (
|
|
264
|
+
typeof player.name === 'string' && Number.isInteger(player.seat)
|
|
265
|
+
? [{ name: player.name, seat: player.seat }]
|
|
266
|
+
: []
|
|
267
|
+
));
|
|
268
|
+
return {
|
|
269
|
+
rooms,
|
|
270
|
+
all_players: allPlayers,
|
|
271
|
+
all_task_locations: allTaskLocations,
|
|
272
|
+
...(Array.isArray(gameState.you?.tasks) ? { your_tasks: gameState.you.tasks } : {}),
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function fallbackActionIntent(state: GoalGameState, action: Record<string, any>): StrategyIntent {
|
|
277
|
+
const room = state.you.room || undefined;
|
|
278
|
+
if (action.action === 'move') {
|
|
279
|
+
const destination = typeof action.target === 'string' && action.target.trim()
|
|
280
|
+
? action.target.trim()
|
|
281
|
+
: undefined;
|
|
282
|
+
return {
|
|
283
|
+
activity: 'moving',
|
|
284
|
+
summary: destination ? `正在前往${destination}。` : '正在移动。',
|
|
285
|
+
...(destination ? { room: destination } : room ? { room } : {}),
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
if (action.action === 'task') {
|
|
289
|
+
const task = typeof action.task_name === 'string' && action.task_name.trim()
|
|
290
|
+
? action.task_name.trim()
|
|
291
|
+
: undefined;
|
|
292
|
+
return {
|
|
293
|
+
activity: 'doing_task',
|
|
294
|
+
summary: task
|
|
295
|
+
? `正在${room || '当前位置'}开始任务“${task}”。`
|
|
296
|
+
: `正在${room || '当前位置'}开始任务。`,
|
|
297
|
+
...(room ? { room } : {}),
|
|
298
|
+
...(task ? { task } : {}),
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
if (action.action === 'kill' && Number.isInteger(action.target_seat)) {
|
|
302
|
+
const knownTarget = [...state.players, ...(state.all_players ?? [])]
|
|
303
|
+
.find(player => player.seat === action.target_seat);
|
|
304
|
+
const target = knownTarget?.name != null
|
|
305
|
+
? `${action.target_seat}号${knownTarget.name}`
|
|
306
|
+
: `${action.target_seat}号`;
|
|
307
|
+
return {
|
|
308
|
+
activity: 'acting',
|
|
309
|
+
summary: `正在击杀${target}。`,
|
|
310
|
+
...(room ? { room } : {}),
|
|
311
|
+
...(knownTarget?.name ? { targetPlayer: knownTarget.name } : {}),
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
if (action.action === 'report') {
|
|
315
|
+
return {
|
|
316
|
+
activity: 'acting',
|
|
317
|
+
summary: '正在报告尸体并召集会议。',
|
|
318
|
+
...(room ? { room } : {}),
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
if (action.action === 'trigger_alarm') {
|
|
322
|
+
return {
|
|
323
|
+
activity: 'acting',
|
|
324
|
+
summary: '正在触发紧急警报。',
|
|
325
|
+
...(room ? { room } : {}),
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
if (action.action === 'speech') {
|
|
329
|
+
return {
|
|
330
|
+
activity: 'acting',
|
|
331
|
+
summary: '正在与附近玩家交流。',
|
|
332
|
+
...(room ? { room } : {}),
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
return {
|
|
336
|
+
activity: 'acting',
|
|
337
|
+
summary: '正在执行策略动作。',
|
|
338
|
+
...(room ? { room } : {}),
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
function sameMove(left: Record<string, any>, right: Record<string, any>): boolean {
|
|
343
|
+
if (left.action !== 'move' || right.action !== 'move') return false;
|
|
344
|
+
if ((left.stop_on_player === true) !== (right.stop_on_player === true)) return false;
|
|
345
|
+
if (typeof left.target === 'string' || typeof right.target === 'string') {
|
|
346
|
+
return String(left.target ?? '').trim().toLowerCase() === String(right.target ?? '').trim().toLowerCase();
|
|
347
|
+
}
|
|
348
|
+
const dx = Number(left.target_x) - Number(right.target_x);
|
|
349
|
+
const dy = Number(left.target_y) - Number(right.target_y);
|
|
350
|
+
return Number.isFinite(dx) && Number.isFinite(dy) && Math.hypot(dx, dy) <= 10;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Package-internal adapter for the bundled long Behaviors' existing Goal trees.
|
|
355
|
+
*
|
|
356
|
+
* It consumes only the public Behavior input/read contracts and proposes
|
|
357
|
+
* Decisions. It never submits effects or opens another data channel.
|
|
358
|
+
*/
|
|
359
|
+
export class OfficialGoalBehavior {
|
|
360
|
+
private readonly behaviorId: string;
|
|
361
|
+
private readonly options: OfficialGoalBehaviorOptions;
|
|
362
|
+
private strategy?: Strategy;
|
|
363
|
+
private readonly context: StrategyContext;
|
|
364
|
+
private readonly corpseMemory = new CorpseMemory();
|
|
365
|
+
private modules: CustomModule[];
|
|
366
|
+
private effectiveParameters: Readonly<Record<string, unknown>>;
|
|
367
|
+
private currentRole = '';
|
|
368
|
+
private configurationError?: string;
|
|
369
|
+
private mapCache?: Readonly<OfficialGoalMapInfo>;
|
|
370
|
+
private tasksAvailable = true;
|
|
371
|
+
private activeMove?: {
|
|
372
|
+
payload: Record<string, any>;
|
|
373
|
+
intent?: StrategyIntent;
|
|
374
|
+
epochId: number;
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
constructor(options: OfficialGoalBehaviorOptions) {
|
|
378
|
+
this.options = options;
|
|
379
|
+
this.behaviorId = options.id;
|
|
380
|
+
this.effectiveParameters = Object.freeze({});
|
|
381
|
+
this.strategy = undefined;
|
|
382
|
+
this.context = {
|
|
383
|
+
taskData: [],
|
|
384
|
+
taskLocations: [],
|
|
385
|
+
emergency: null,
|
|
386
|
+
taskLocalBlockedUntil: 0,
|
|
387
|
+
reportCorpseTarget: null,
|
|
388
|
+
reportBlockedUntil: 0,
|
|
389
|
+
octopusTimeActive: false,
|
|
390
|
+
notifications: [],
|
|
391
|
+
lastProgressNotifyAt: 0,
|
|
392
|
+
teammates: new Set(),
|
|
393
|
+
alarmDone: false,
|
|
394
|
+
alarmOnCooldown: false,
|
|
395
|
+
rooms: [],
|
|
396
|
+
playerNamesBySeat: {},
|
|
397
|
+
forcePatrolAdvance: false,
|
|
398
|
+
blockedMoveTarget: null,
|
|
399
|
+
mySeat: 0,
|
|
400
|
+
speechNotifications: [],
|
|
401
|
+
agentAlerts: [],
|
|
402
|
+
knownCorpses: [],
|
|
403
|
+
recentlyKilledTargets: new Map(),
|
|
404
|
+
};
|
|
405
|
+
this.modules = [];
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
private synchronizeInput(values: Readonly<Record<string, unknown>>): void {
|
|
409
|
+
if (sameBehaviorInput(this.effectiveParameters, values) && !this.configurationError) return;
|
|
410
|
+
const effectiveParameters = Object.freeze(structuredClone(values));
|
|
411
|
+
const configurationError = this.options.validateParameters?.(effectiveParameters);
|
|
412
|
+
this.effectiveParameters = effectiveParameters;
|
|
413
|
+
this.configurationError = configurationError;
|
|
414
|
+
this.currentRole = '';
|
|
415
|
+
this.activeMove = undefined;
|
|
416
|
+
this.context.intent = undefined;
|
|
417
|
+
if (configurationError) {
|
|
418
|
+
this.strategy = undefined;
|
|
419
|
+
this.modules = [];
|
|
420
|
+
delete this.context.customModules;
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
const strategy = this.options.create(effectiveParameters);
|
|
424
|
+
const modules = strategy.customModules?.() ?? [];
|
|
425
|
+
this.strategy = strategy;
|
|
426
|
+
this.modules = modules;
|
|
427
|
+
if (modules.length > 0) this.context.customModules = modules;
|
|
428
|
+
else delete this.context.customModules;
|
|
429
|
+
if (this.mapCache) {
|
|
430
|
+
for (const module of modules) module.onMapLoaded?.([...this.mapCache.rooms]);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
async decide(
|
|
435
|
+
frame: BehaviorInput,
|
|
436
|
+
api: BehaviorReadApi,
|
|
437
|
+
): Promise<BehaviorDecision> {
|
|
438
|
+
this.synchronizeInput(frame.input);
|
|
439
|
+
const events = frameEvents(frame);
|
|
440
|
+
const state = projectGoalGameState(frame.gameState, events);
|
|
441
|
+
if (!state.you?.is_alive) {
|
|
442
|
+
return this.status({ activity: 'idle', summary: '当前角色已死亡,策略停止行动。' });
|
|
443
|
+
}
|
|
444
|
+
const strategy = this.ensureStrategy();
|
|
445
|
+
if (!strategy) {
|
|
446
|
+
return this.status({
|
|
447
|
+
activity: 'waiting',
|
|
448
|
+
summary: this.configurationError ?? `${this.behaviorId} 正在等待参数配置。`,
|
|
449
|
+
...(state.you.room ? { room: state.you.room } : {}),
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
const resources = this.loadMapAndTasks(frame, api);
|
|
453
|
+
|
|
454
|
+
this.learnRoleAndPlayers(state, events);
|
|
455
|
+
this.applyMapAndTasks(state, resources);
|
|
456
|
+
this.context.routeEvidence = await this.buildRouteEvidence(frame, resources, api) ?? null;
|
|
457
|
+
this.context.emergency = this.emergency(state);
|
|
458
|
+
this.corpseMemory.observe(state, this.context.recentlyKilledTargets);
|
|
459
|
+
this.context.knownCorpses = this.corpseMemory.list();
|
|
460
|
+
for (const module of this.modules) module.processEvents(events, state.tick, state);
|
|
461
|
+
|
|
462
|
+
if (this.activeMove && (
|
|
463
|
+
events.some((event) => event.type === 'move_end' || event.type === 'move_interrupted')
|
|
464
|
+
|| (
|
|
465
|
+
frame.epochId > this.activeMove.epochId
|
|
466
|
+
&& state.you.currently_moving !== true
|
|
467
|
+
)
|
|
468
|
+
)) {
|
|
469
|
+
this.activeMove = undefined;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
this.context.intent = undefined;
|
|
473
|
+
let decisions = strategy.decide(state, this.context);
|
|
474
|
+
for (const module of this.modules) {
|
|
475
|
+
if (module.afterDecide) decisions = module.afterDecide(decisions, state, this.context);
|
|
476
|
+
}
|
|
477
|
+
const speech = this.options.sidecarSpeech
|
|
478
|
+
? decisions.filter((decision) => decision.action.toJSON().action === 'speech')
|
|
479
|
+
: [];
|
|
480
|
+
const main = speech.length > 0
|
|
481
|
+
? decisions.filter((decision) => decision.action.toJSON().action !== 'speech')
|
|
482
|
+
: decisions;
|
|
483
|
+
const decision = main.find(candidate => !this.repeatsActiveMove(candidate));
|
|
484
|
+
const proposed = decision
|
|
485
|
+
? this.propose(decision, frame.epochId, state)
|
|
486
|
+
: undefined;
|
|
487
|
+
const sidecarProposals: Array<{
|
|
488
|
+
payload: Record<string, any>;
|
|
489
|
+
intent?: StrategyIntent;
|
|
490
|
+
}> = [];
|
|
491
|
+
for (const sidecar of speech) {
|
|
492
|
+
sidecarProposals.push(this.propose(sidecar, frame.epochId, state));
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
const proposedEvents: NonNullable<BehaviorDecision['events']> = [
|
|
496
|
+
...this.context.agentAlerts.map((message) => ({
|
|
497
|
+
type: 'strategy_alert',
|
|
498
|
+
payload: { message, strategy: this.behaviorId, tick: state.tick },
|
|
499
|
+
})),
|
|
500
|
+
...this.context.speechNotifications.map((message) => ({
|
|
501
|
+
type: 'robot_speak_rule',
|
|
502
|
+
payload: { message },
|
|
503
|
+
})),
|
|
504
|
+
];
|
|
505
|
+
this.context.agentAlerts.length = 0;
|
|
506
|
+
this.context.speechNotifications.length = 0;
|
|
507
|
+
this.context.notifications.length = 0;
|
|
508
|
+
|
|
509
|
+
const actions = [proposed, ...sidecarProposals]
|
|
510
|
+
.filter((candidate): candidate is NonNullable<typeof candidate> => candidate !== undefined)
|
|
511
|
+
.map(candidate => candidate.payload as GameAction);
|
|
512
|
+
const status = this.statusFor(state, proposed ?? sidecarProposals[0]);
|
|
513
|
+
return {
|
|
514
|
+
...status,
|
|
515
|
+
...(actions.length > 0 ? { actions } : {}),
|
|
516
|
+
...(proposedEvents.length > 0 ? { events: proposedEvents } : {}),
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
private learnRoleAndPlayers(state: GoalGameState, events: readonly Record<string, any>[]): void {
|
|
521
|
+
const role = state.you.role ?? '';
|
|
522
|
+
if (role && role !== this.currentRole) {
|
|
523
|
+
this.currentRole = role;
|
|
524
|
+
this.strategy?.updateRole?.(role);
|
|
525
|
+
}
|
|
526
|
+
if (state.you.seat != null) this.context.mySeat = state.you.seat;
|
|
527
|
+
for (const player of state.all_players ?? state.players ?? []) {
|
|
528
|
+
if (player.seat != null && player.name) this.context.playerNamesBySeat[String(player.seat)] = player.name;
|
|
529
|
+
}
|
|
530
|
+
const teammateSeat = (teammate: unknown): string | null => {
|
|
531
|
+
const ref = projectedPlayerRef(teammate);
|
|
532
|
+
const seat = Number(ref.seat);
|
|
533
|
+
return Number.isInteger(seat) && seat >= 1 ? String(seat) : null;
|
|
534
|
+
};
|
|
535
|
+
for (const event of events) {
|
|
536
|
+
if (event.type === 'octopus_time_start') this.context.octopusTimeActive = true;
|
|
537
|
+
const eventTeammates = Array.isArray(event.crab_teammates)
|
|
538
|
+
? event.crab_teammates
|
|
539
|
+
: [];
|
|
540
|
+
for (const teammate of eventTeammates) {
|
|
541
|
+
const seat = teammateSeat(teammate);
|
|
542
|
+
if (seat) this.context.teammates.add(seat);
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
const stateTeammates = state.you.crab_teammates;
|
|
546
|
+
for (const teammate of Array.isArray(stateTeammates) ? stateTeammates : []) {
|
|
547
|
+
const seat = teammateSeat(teammate);
|
|
548
|
+
if (seat) this.context.teammates.add(seat);
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
private ensureStrategy(): Strategy | undefined {
|
|
553
|
+
if (this.strategy || this.configurationError) return this.strategy;
|
|
554
|
+
const strategy = this.options.create(this.effectiveParameters);
|
|
555
|
+
const modules = strategy.customModules?.() ?? [];
|
|
556
|
+
this.strategy = strategy;
|
|
557
|
+
this.modules = modules;
|
|
558
|
+
if (modules.length > 0) this.context.customModules = modules;
|
|
559
|
+
if (this.mapCache) {
|
|
560
|
+
for (const module of modules) module.onMapLoaded?.([...this.mapCache.rooms]);
|
|
561
|
+
}
|
|
562
|
+
return strategy;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
private loadMapAndTasks(
|
|
566
|
+
frame: BehaviorInput,
|
|
567
|
+
api: BehaviorReadApi,
|
|
568
|
+
): OfficialGoalBehaviorResources {
|
|
569
|
+
const projectedTasks = frame.gameState.you?.tasks;
|
|
570
|
+
const tasks = this.options.requiresTasks
|
|
571
|
+
? (Array.isArray(projectedTasks) ? projectedTasks : null)
|
|
572
|
+
: [];
|
|
573
|
+
const tasksAvailable = tasks !== null;
|
|
574
|
+
let map = this.mapCache;
|
|
575
|
+
if (this.options.requiresMap !== false && !map) {
|
|
576
|
+
map = packagedGoalMap(frame.gameState, api.spatial.rooms);
|
|
577
|
+
}
|
|
578
|
+
return { tasks, tasksAvailable, ...(map ? { map } : {}) };
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
private async buildRouteEvidence(
|
|
582
|
+
frame: BehaviorInput,
|
|
583
|
+
resources: OfficialGoalBehaviorResources,
|
|
584
|
+
api: BehaviorReadApi,
|
|
585
|
+
): Promise<RouteEvidence | null | undefined> {
|
|
586
|
+
const targets = this.options.routeEvidenceTargets;
|
|
587
|
+
const you = frame.gameState.you;
|
|
588
|
+
if (
|
|
589
|
+
!you
|
|
590
|
+
|| typeof you.x !== 'number'
|
|
591
|
+
|| typeof you.y !== 'number'
|
|
592
|
+
|| !targets
|
|
593
|
+
|| targets.length === 0
|
|
594
|
+
) return undefined;
|
|
595
|
+
const points: Array<{ x: number; y: number }> = [];
|
|
596
|
+
if (targets.includes('tasks')) {
|
|
597
|
+
for (const task of resources.tasks ?? []) points.push({ x: task.x, y: task.y });
|
|
598
|
+
}
|
|
599
|
+
if (targets.includes('rooms') && resources.map) {
|
|
600
|
+
for (const room of resources.map.rooms) {
|
|
601
|
+
const target = roomTarget(room, resources.map.all_task_locations);
|
|
602
|
+
points.push({ x: target.x, y: target.y });
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
if (targets.includes('hide')) {
|
|
606
|
+
for (const spot of HIDE_SPOTS) points.push({ x: spot.x, y: spot.y });
|
|
607
|
+
}
|
|
608
|
+
if (points.length === 0) return undefined;
|
|
609
|
+
const from = { x: you.x, y: you.y };
|
|
610
|
+
const evidence = buildRouteEvidence(from, points);
|
|
611
|
+
if (!evidence) return evidence;
|
|
612
|
+
const distances = await api.navigation.pathDistances(points.map(to => ({ from, to })));
|
|
613
|
+
const distanceByPoint = new Map(points.map((point, index) => [
|
|
614
|
+
`${point.x}\u0000${point.y}`,
|
|
615
|
+
distances[index] ?? null,
|
|
616
|
+
]));
|
|
617
|
+
return {
|
|
618
|
+
...evidence,
|
|
619
|
+
routes: evidence.routes.map(route => ({
|
|
620
|
+
...route,
|
|
621
|
+
distancePx: distanceByPoint.get(`${route.point.x}\u0000${route.point.y}`) ?? Infinity,
|
|
622
|
+
})),
|
|
623
|
+
};
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
private applyMapAndTasks(
|
|
627
|
+
state: GoalGameState,
|
|
628
|
+
resources: OfficialGoalBehaviorResources,
|
|
629
|
+
): void {
|
|
630
|
+
const { tasks, map } = resources;
|
|
631
|
+
const firstMapLoad = map !== undefined && this.mapCache === undefined;
|
|
632
|
+
if (map) this.mapCache = map;
|
|
633
|
+
this.tasksAvailable = resources.tasksAvailable;
|
|
634
|
+
const factionByName = new Map(
|
|
635
|
+
(map?.all_task_locations ?? []).map((task) => [task.name, task.faction]),
|
|
636
|
+
);
|
|
637
|
+
this.context.taskData = (tasks ?? []).map((task): TaskInfo => ({
|
|
638
|
+
task_id: task.name,
|
|
639
|
+
task_name: task.name,
|
|
640
|
+
room: task.room,
|
|
641
|
+
status: task.status,
|
|
642
|
+
x: task.x,
|
|
643
|
+
y: task.y,
|
|
644
|
+
is_fake_shrimp: task.is_fake_shrimp ?? false,
|
|
645
|
+
faction: factionByName.get(task.name),
|
|
646
|
+
}));
|
|
647
|
+
if (tasks === null) delete state.your_tasks;
|
|
648
|
+
else state.your_tasks = this.context.taskData;
|
|
649
|
+
if (map) {
|
|
650
|
+
this.context.taskLocations = map.all_task_locations.map((task) => ({
|
|
651
|
+
name: task.name,
|
|
652
|
+
room: task.room,
|
|
653
|
+
x: task.x,
|
|
654
|
+
y: task.y,
|
|
655
|
+
faction: task.faction,
|
|
656
|
+
}));
|
|
657
|
+
this.context.rooms = map.rooms.map((room) => roomTarget(room, map.all_task_locations));
|
|
658
|
+
if (firstMapLoad) {
|
|
659
|
+
for (const module of this.modules) module.onMapLoaded?.([...map.rooms]);
|
|
660
|
+
}
|
|
661
|
+
for (const player of map.all_players) {
|
|
662
|
+
this.context.playerNamesBySeat[String(player.seat)] = player.name;
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
private emergency(state: GoalGameState): EmergencyInfo | null {
|
|
668
|
+
const value = state.emergency;
|
|
669
|
+
if (!value) return null;
|
|
670
|
+
return {
|
|
671
|
+
task_id: value.task_name ?? '',
|
|
672
|
+
task_name: value.task_name ?? '',
|
|
673
|
+
room: value.room ?? '',
|
|
674
|
+
status: value.status ?? 'emergency',
|
|
675
|
+
x: value.x,
|
|
676
|
+
y: value.y,
|
|
677
|
+
remaining_secs: Number(value.remaining_secs ?? 0),
|
|
678
|
+
};
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
private repeatsActiveMove(decision: GoalBehaviorDecision): boolean {
|
|
682
|
+
if (!this.activeMove) return false;
|
|
683
|
+
if (!sameMove(decision.action.toJSON(), this.activeMove.payload)) return false;
|
|
684
|
+
return true;
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
private propose(
|
|
688
|
+
decision: GoalBehaviorDecision,
|
|
689
|
+
epochId: number,
|
|
690
|
+
state: GoalGameState,
|
|
691
|
+
): { payload: Record<string, any>; intent?: StrategyIntent } {
|
|
692
|
+
const payload = decision.action.toJSON();
|
|
693
|
+
const intent = decision.intent ?? this.context.intent;
|
|
694
|
+
delete payload.audio_url;
|
|
695
|
+
if (payload.action === 'move') {
|
|
696
|
+
this.activeMove = {
|
|
697
|
+
payload,
|
|
698
|
+
intent,
|
|
699
|
+
epochId,
|
|
700
|
+
};
|
|
701
|
+
}
|
|
702
|
+
if (payload.action === 'kill' && Number.isInteger(payload.target_seat)) {
|
|
703
|
+
this.context.recentlyKilledTargets?.set(
|
|
704
|
+
String(payload.target_seat),
|
|
705
|
+
Date.now() + RECENT_KILL_IGNORE_MS,
|
|
706
|
+
);
|
|
707
|
+
}
|
|
708
|
+
return { payload, intent };
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
private status(value: OfficialBehaviorStatusState): BehaviorDecision {
|
|
712
|
+
const { dataAvailability, ...status } = value;
|
|
713
|
+
return {
|
|
714
|
+
status: {
|
|
715
|
+
...status,
|
|
716
|
+
...(dataAvailability ? { data: { dataAvailability } } : {}),
|
|
717
|
+
},
|
|
718
|
+
};
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
private statusFor(
|
|
722
|
+
state: GoalGameState,
|
|
723
|
+
proposed?: { payload: Record<string, any>; intent?: StrategyIntent },
|
|
724
|
+
): BehaviorDecision {
|
|
725
|
+
const publish = (
|
|
726
|
+
value: OfficialBehaviorStatusState,
|
|
727
|
+
): BehaviorDecision => this.status({
|
|
728
|
+
...value,
|
|
729
|
+
...(this.options.requiresTasks ? {
|
|
730
|
+
dataAvailability: {
|
|
731
|
+
tasks: this.tasksAvailable ? 'available' : 'unavailable',
|
|
732
|
+
},
|
|
733
|
+
} : {}),
|
|
734
|
+
});
|
|
735
|
+
const taskStatus = (): OfficialBehaviorStatusState => ({
|
|
736
|
+
activity: 'doing_task',
|
|
737
|
+
summary: state.you.task_name
|
|
738
|
+
? `正在${state.you.room || '当前位置'}执行任务“${state.you.task_name}”。`
|
|
739
|
+
: `正在${state.you.room || '当前位置'}执行任务。`,
|
|
740
|
+
...(state.you.room ? { room: state.you.room } : {}),
|
|
741
|
+
...(state.you.task_name ? { task: state.you.task_name } : {}),
|
|
742
|
+
});
|
|
743
|
+
if (proposed) {
|
|
744
|
+
return publish(proposed.intent ?? fallbackActionIntent(state, proposed.payload));
|
|
745
|
+
}
|
|
746
|
+
if (state.you.doing_task) {
|
|
747
|
+
return publish(taskStatus());
|
|
748
|
+
}
|
|
749
|
+
if (this.activeMove) {
|
|
750
|
+
return publish(this.activeMove.intent ?? fallbackActionIntent(state, this.activeMove.payload));
|
|
751
|
+
}
|
|
752
|
+
if (this.context.intent) return publish(this.context.intent);
|
|
753
|
+
if (state.you.currently_moving) {
|
|
754
|
+
return publish({
|
|
755
|
+
activity: 'moving',
|
|
756
|
+
summary: '正在继续移动。',
|
|
757
|
+
...(state.you.room ? { room: state.you.room } : {}),
|
|
758
|
+
});
|
|
759
|
+
}
|
|
760
|
+
return publish({
|
|
761
|
+
activity: 'idle',
|
|
762
|
+
summary: `当前没有可执行动作,正在${state.you.room || '当前位置'}等待。`,
|
|
763
|
+
...(state.you.room ? { room: state.you.room } : {}),
|
|
764
|
+
});
|
|
765
|
+
}
|
|
766
|
+
}
|