@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
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
BehaviorDecision,
|
|
3
|
+
BehaviorInput,
|
|
4
|
+
BehaviorReadApi,
|
|
5
|
+
Position,
|
|
6
|
+
} from '../behavior-plugin/index.js';
|
|
7
|
+
import {
|
|
8
|
+
behaviorDistance,
|
|
9
|
+
behaviorEventMentionsSeat,
|
|
10
|
+
behaviorKnownPlayer,
|
|
11
|
+
behaviorPlayerLabel,
|
|
12
|
+
behaviorRooms,
|
|
13
|
+
behaviorSelf,
|
|
14
|
+
behaviorTeammateSeats,
|
|
15
|
+
behaviorVisibleCorpses,
|
|
16
|
+
behaviorVisiblePlayer,
|
|
17
|
+
} from './model.js';
|
|
18
|
+
import { SemanticMoveGate } from './move-gate.js';
|
|
19
|
+
import { FinitePlayerSearch } from './search.js';
|
|
20
|
+
|
|
21
|
+
const KILL_AUTHORITY_CONFIRMATION_MS = 1_500;
|
|
22
|
+
const KILL_OUTSTANDING_CONFIRMATION_MS = 5_000;
|
|
23
|
+
const KILL_MAX_SUBMISSIONS = 2;
|
|
24
|
+
const REPORT_RANGE = 140;
|
|
25
|
+
const KILL_ROLES = new Set([
|
|
26
|
+
'crab_generic',
|
|
27
|
+
'neutral_octopus',
|
|
28
|
+
'shrimp_warrior',
|
|
29
|
+
'shrimp_pistol',
|
|
30
|
+
]);
|
|
31
|
+
const SAFE_AUTOMATIC_KILL_SELECTION_ROLES = new Set([
|
|
32
|
+
'crab_generic',
|
|
33
|
+
'neutral_octopus',
|
|
34
|
+
]);
|
|
35
|
+
|
|
36
|
+
export type AfterKillBehavior = 'escape' | 'hold' | 'report' | 'replan';
|
|
37
|
+
|
|
38
|
+
interface PendingKill {
|
|
39
|
+
readonly submittedAtMs: number;
|
|
40
|
+
readonly targetSeat: number;
|
|
41
|
+
readonly targetLabel: string;
|
|
42
|
+
readonly killsRemaining: number | null | undefined;
|
|
43
|
+
readonly scene: Position;
|
|
44
|
+
}
|
|
45
|
+
function finish(
|
|
46
|
+
outcome: 'completed' | 'failed',
|
|
47
|
+
reason: string,
|
|
48
|
+
summary: string,
|
|
49
|
+
): BehaviorDecision {
|
|
50
|
+
return {
|
|
51
|
+
status: { summary, activity: 'idle' },
|
|
52
|
+
finish: { outcome, reason, summary },
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function status(summary: string, targetPlayer?: string): BehaviorDecision {
|
|
57
|
+
return {
|
|
58
|
+
status: {
|
|
59
|
+
summary,
|
|
60
|
+
activity: 'acting',
|
|
61
|
+
...(targetPlayer ? { targetPlayer } : {}),
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function behaviorRoleCanKill(role: string | undefined): boolean {
|
|
67
|
+
return !!role && KILL_ROLES.has(role);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function behaviorRoleCanSelectKillTarget(role: string | undefined): boolean {
|
|
71
|
+
return !!role && SAFE_AUTOMATIC_KILL_SELECTION_ROLES.has(role);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function behaviorHasKillUse(input: Readonly<BehaviorInput>): boolean {
|
|
75
|
+
const remaining = input.gameState.you?.kills_remaining;
|
|
76
|
+
return remaining == null || remaining > 0;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function behaviorKillCommitRange(role: string | undefined): number {
|
|
80
|
+
return role === 'shrimp_warrior' || role === 'shrimp_pistol' ? 144 : 72;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Public serial kill state machine. It observes only later authoritative
|
|
85
|
+
* State/Event and deliberately has no Action receipt channel.
|
|
86
|
+
*/
|
|
87
|
+
export class AuthoritativeKillFlow {
|
|
88
|
+
private readonly search = new FinitePlayerSearch();
|
|
89
|
+
private readonly move = new SemanticMoveGate();
|
|
90
|
+
private killSubmissions = 0;
|
|
91
|
+
private pending?: PendingKill;
|
|
92
|
+
private outstanding?: PendingKill;
|
|
93
|
+
private repositionRequired = false;
|
|
94
|
+
private afterKill?: AfterKillBehavior;
|
|
95
|
+
private afterKillScene?: Position;
|
|
96
|
+
private afterKillConfirmedAtMs?: number;
|
|
97
|
+
private holdUntilMs?: number;
|
|
98
|
+
private escapeTarget?: Position;
|
|
99
|
+
private afterReportSubmitted = false;
|
|
100
|
+
private afterReportWaitStartedAtMs?: number;
|
|
101
|
+
|
|
102
|
+
async step(
|
|
103
|
+
input: Readonly<BehaviorInput>,
|
|
104
|
+
api: BehaviorReadApi,
|
|
105
|
+
targetSeat: number,
|
|
106
|
+
afterKill: AfterKillBehavior,
|
|
107
|
+
): Promise<BehaviorDecision> {
|
|
108
|
+
const targetLabel = behaviorPlayerLabel(input, targetSeat);
|
|
109
|
+
if (this.outstanding) {
|
|
110
|
+
if (this.authorityConfirmed(input, this.outstanding)) {
|
|
111
|
+
this.beginAfterKill(input, this.outstanding, afterKill);
|
|
112
|
+
return this.stepAfterKill(input, api);
|
|
113
|
+
}
|
|
114
|
+
if (input.nowMs - this.outstanding.submittedAtMs >= KILL_OUTSTANDING_CONFIRMATION_MS) {
|
|
115
|
+
this.outstanding = undefined;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (this.pending) {
|
|
119
|
+
if (this.authorityConfirmed(input, this.pending)) {
|
|
120
|
+
this.beginAfterKill(input, this.pending, afterKill);
|
|
121
|
+
return this.stepAfterKill(input, api);
|
|
122
|
+
}
|
|
123
|
+
if (input.nowMs - this.pending.submittedAtMs >= KILL_AUTHORITY_CONFIRMATION_MS) {
|
|
124
|
+
if (this.killSubmissions < KILL_MAX_SUBMISSIONS) {
|
|
125
|
+
this.outstanding = this.pending;
|
|
126
|
+
this.pending = undefined;
|
|
127
|
+
this.repositionRequired = true;
|
|
128
|
+
return status(`${targetLabel}的击杀尚未得到权威确认,重新贴近后进行最后一次复核。`);
|
|
129
|
+
}
|
|
130
|
+
return finish(
|
|
131
|
+
'failed',
|
|
132
|
+
'kill_authority_unconfirmed',
|
|
133
|
+
`${targetLabel}的击杀在确认窗口内没有权威结果;停止重试,已提交动作仍可能完成。`,
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
return status(`等待${targetLabel}击杀结果的权威状态;不会盲目重试。`);
|
|
137
|
+
}
|
|
138
|
+
if (this.afterKill) return this.stepAfterKill(input, api);
|
|
139
|
+
|
|
140
|
+
const role = input.gameState.you?.role;
|
|
141
|
+
if (!behaviorRoleCanKill(role)) {
|
|
142
|
+
return finish('failed', 'role_cannot_kill', '当前角色没有可用的击杀能力。');
|
|
143
|
+
}
|
|
144
|
+
if (!behaviorHasKillUse(input)) {
|
|
145
|
+
return finish('failed', 'no_kills_remaining', '当前角色已经没有剩余击杀次数。');
|
|
146
|
+
}
|
|
147
|
+
const known = input.gameState.players?.find((player) => player.seat === targetSeat);
|
|
148
|
+
if (known?.known_status.is_alive === false) {
|
|
149
|
+
return finish('failed', 'target_not_alive', `${known.name}已知死亡,停止追杀。`);
|
|
150
|
+
}
|
|
151
|
+
const searched = await this.search.step(input, api, targetSeat);
|
|
152
|
+
if (searched.kind === 'failed') return finish('failed', searched.reason, searched.summary);
|
|
153
|
+
if (searched.kind === 'move') {
|
|
154
|
+
const action = this.move.propose(input, searched.target, false, searched.summary);
|
|
155
|
+
return {
|
|
156
|
+
status: { summary: searched.summary, activity: 'moving', targetPlayer: targetLabel },
|
|
157
|
+
...(action ? { actions: [action] } : {}),
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
const target = searched.player;
|
|
161
|
+
if (behaviorTeammateSeats(input).has(target.seat)) {
|
|
162
|
+
return finish('failed', 'target_is_teammate', `${target.name} 是当前已知队友,拒绝攻击。`);
|
|
163
|
+
}
|
|
164
|
+
if (this.repositionRequired) {
|
|
165
|
+
const summary = `上次击杀尚未确认,正在重新贴近${target.name}。`;
|
|
166
|
+
const action = this.move.propose(input, target, false, summary);
|
|
167
|
+
if (action) this.repositionRequired = false;
|
|
168
|
+
return {
|
|
169
|
+
status: { summary, activity: 'moving', targetPlayer: target.name },
|
|
170
|
+
...(action ? { actions: [action] } : {}),
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
const self = behaviorSelf(input);
|
|
174
|
+
if (!self) return finish('failed', 'self_position_unavailable', '当前无法取得自身位置。');
|
|
175
|
+
const cooldown = input.gameState.you?.kill_cooldown_secs ?? 0;
|
|
176
|
+
const distance = behaviorDistance(self, target);
|
|
177
|
+
if (cooldown <= 0 && distance <= behaviorKillCommitRange(role)) {
|
|
178
|
+
if (this.killSubmissions >= KILL_MAX_SUBMISSIONS) {
|
|
179
|
+
return finish('failed', 'kill_retry_exhausted', `对${target.name}的击杀已达有界重试上限。`);
|
|
180
|
+
}
|
|
181
|
+
this.killSubmissions += 1;
|
|
182
|
+
this.pending = {
|
|
183
|
+
submittedAtMs: input.nowMs,
|
|
184
|
+
targetSeat,
|
|
185
|
+
targetLabel,
|
|
186
|
+
killsRemaining: input.gameState.you?.kills_remaining,
|
|
187
|
+
scene: { x: target.x, y: target.y },
|
|
188
|
+
};
|
|
189
|
+
const summary = `正在复核并尝试击杀${target.name}。`;
|
|
190
|
+
return {
|
|
191
|
+
status: { summary, activity: 'acting', targetPlayer: target.name },
|
|
192
|
+
actions: [{ action: 'kill', target_seat: targetSeat, thinking_content: summary }],
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
const summary = cooldown > 0
|
|
196
|
+
? `击杀冷却尚有${Math.ceil(cooldown)}秒,正在保持追踪${target.name}。`
|
|
197
|
+
: `正在追近${target.name}。`;
|
|
198
|
+
const action = this.move.propose(input, target, false, summary);
|
|
199
|
+
return {
|
|
200
|
+
status: { summary, activity: 'moving', targetPlayer: target.name },
|
|
201
|
+
...(action ? { actions: [action] } : {}),
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
private authorityConfirmed(input: Readonly<BehaviorInput>, pending: PendingKill): boolean {
|
|
206
|
+
const remaining = input.gameState.you?.kills_remaining;
|
|
207
|
+
const useConsumed = pending.killsRemaining != null
|
|
208
|
+
&& remaining != null
|
|
209
|
+
&& remaining < pending.killsRemaining;
|
|
210
|
+
if (useConsumed || behaviorEventMentionsSeat(input.events, ['kill'], pending.targetSeat)) return true;
|
|
211
|
+
const selfSeat = input.gameState.you?.player?.seat;
|
|
212
|
+
const target = input.gameState.players?.find((player) => player.seat === pending.targetSeat);
|
|
213
|
+
const killer = target?.known_status.killer;
|
|
214
|
+
return target?.known_status.is_alive === false
|
|
215
|
+
&& killer?.kind === 'player'
|
|
216
|
+
&& selfSeat !== undefined
|
|
217
|
+
&& killer.player.seat === selfSeat;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
private beginAfterKill(
|
|
221
|
+
input: Readonly<BehaviorInput>,
|
|
222
|
+
pending: PendingKill,
|
|
223
|
+
afterKill: AfterKillBehavior,
|
|
224
|
+
): void {
|
|
225
|
+
this.pending = undefined;
|
|
226
|
+
this.outstanding = undefined;
|
|
227
|
+
this.afterKill = afterKill;
|
|
228
|
+
this.afterKillScene = pending.scene;
|
|
229
|
+
this.afterKillConfirmedAtMs = input.nowMs;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
private stepAfterKill(
|
|
233
|
+
input: Readonly<BehaviorInput>,
|
|
234
|
+
api: BehaviorReadApi,
|
|
235
|
+
): BehaviorDecision {
|
|
236
|
+
if (this.afterKill === 'replan') {
|
|
237
|
+
return finish('completed', 'kill_confirmed', '击杀已经确认,交回 Agent 重新决策。');
|
|
238
|
+
}
|
|
239
|
+
if (this.afterKill === 'hold') {
|
|
240
|
+
if (input.gameState.you?.activity?.kind === 'moving') {
|
|
241
|
+
if (input.nowMs - (this.afterKillConfirmedAtMs ?? input.nowMs) >= 10_000) {
|
|
242
|
+
return finish('failed', 'motion_did_not_stop', '击杀后的底层移动未结束,无法完成原地停留。');
|
|
243
|
+
}
|
|
244
|
+
return status('击杀已确认,等待底层现有移动结束后原地有限停留。');
|
|
245
|
+
}
|
|
246
|
+
this.holdUntilMs ??= input.nowMs + 3_000;
|
|
247
|
+
return input.nowMs >= this.holdUntilMs
|
|
248
|
+
? finish('completed', 'kill_confirmed_hold_finished', '击杀确认后已原地有限停留。')
|
|
249
|
+
: status('击杀已确认,正在原地有限停留。');
|
|
250
|
+
}
|
|
251
|
+
if (this.afterKill === 'report') {
|
|
252
|
+
if (this.afterReportSubmitted) {
|
|
253
|
+
if (
|
|
254
|
+
input.gameState.phase === 'meeting'
|
|
255
|
+
|| input.events.some((event) => event.type === 'meeting_start' || event.type === 'meeting_briefing')
|
|
256
|
+
) return finish('completed', 'corpse_reported', '自报已触发会议。');
|
|
257
|
+
return status('击杀已确认,等待自报是否触发会议。');
|
|
258
|
+
}
|
|
259
|
+
const self = behaviorSelf(input);
|
|
260
|
+
const corpse = self
|
|
261
|
+
? [...behaviorVisibleCorpses(input)]
|
|
262
|
+
.sort((left, right) => behaviorDistance(self, left) - behaviorDistance(self, right))[0]
|
|
263
|
+
: undefined;
|
|
264
|
+
if (!corpse || !self || behaviorDistance(self, corpse) > REPORT_RANGE) {
|
|
265
|
+
this.afterReportWaitStartedAtMs ??= input.nowMs;
|
|
266
|
+
if (input.nowMs - this.afterReportWaitStartedAtMs < 1_500) {
|
|
267
|
+
return status('击杀已确认,短暂等待尸体进入权威可见状态后尝试自报。');
|
|
268
|
+
}
|
|
269
|
+
return finish('completed', 'kill_confirmed_report_unavailable', '击杀已确认,但当前没有可报告尸体;交回 Agent。');
|
|
270
|
+
}
|
|
271
|
+
this.afterReportSubmitted = true;
|
|
272
|
+
const summary = '击杀已确认,正在尝试报告当前范围内尸体。';
|
|
273
|
+
return {
|
|
274
|
+
status: { summary, activity: 'acting' },
|
|
275
|
+
actions: [{ action: 'report', thinking_content: summary }],
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
const self = behaviorSelf(input);
|
|
280
|
+
const scene = this.afterKillScene;
|
|
281
|
+
if (!self || !scene) return finish('completed', 'kill_confirmed_escape_unavailable', '击杀已确认,但没有可用离场路线;交回 Agent。');
|
|
282
|
+
if (behaviorDistance(self, scene) >= 420) {
|
|
283
|
+
return finish('completed', 'kill_confirmed_escaped', '击杀已确认并已离开现场。');
|
|
284
|
+
}
|
|
285
|
+
if (!this.escapeTarget || behaviorDistance(self, this.escapeTarget) <= 70) {
|
|
286
|
+
this.escapeTarget = [...behaviorRooms(api)]
|
|
287
|
+
.sort((left, right) => behaviorDistance(right, scene) - behaviorDistance(left, scene))[0];
|
|
288
|
+
}
|
|
289
|
+
if (!this.escapeTarget) {
|
|
290
|
+
return finish('completed', 'kill_confirmed_escape_unavailable', '击杀已确认,但没有可用离场路线;交回 Agent。');
|
|
291
|
+
}
|
|
292
|
+
const summary = '击杀已确认,正在离开尸体和现场。';
|
|
293
|
+
const action = this.move.propose(input, this.escapeTarget, false, summary);
|
|
294
|
+
return {
|
|
295
|
+
status: { summary, activity: 'moving' },
|
|
296
|
+
...(action ? { actions: [action] } : {}),
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
}
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
BehaviorInput,
|
|
3
|
+
BehaviorReadApi,
|
|
4
|
+
GameEvent,
|
|
5
|
+
GameTask,
|
|
6
|
+
Position,
|
|
7
|
+
SpatialRoom,
|
|
8
|
+
VisibleCorpse,
|
|
9
|
+
VisiblePlayer,
|
|
10
|
+
} from '../behavior-plugin/index.js';
|
|
11
|
+
|
|
12
|
+
export interface BehaviorPlayer extends Position {
|
|
13
|
+
readonly name: string;
|
|
14
|
+
readonly seat: number;
|
|
15
|
+
readonly room?: string;
|
|
16
|
+
readonly distance?: number;
|
|
17
|
+
readonly isAlive?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface BehaviorCorpse extends Position {
|
|
20
|
+
readonly id: string;
|
|
21
|
+
readonly name?: string;
|
|
22
|
+
readonly seat?: number;
|
|
23
|
+
readonly room?: string;
|
|
24
|
+
readonly distance?: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface BehaviorTaskPoint extends Position {
|
|
28
|
+
readonly id?: string;
|
|
29
|
+
readonly name: string;
|
|
30
|
+
readonly room?: string;
|
|
31
|
+
readonly status?: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface NamedPoint extends Position {
|
|
35
|
+
readonly name: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function record(value: unknown): Readonly<Record<string, unknown>> {
|
|
39
|
+
return value && typeof value === 'object' && !Array.isArray(value)
|
|
40
|
+
? value as Readonly<Record<string, unknown>>
|
|
41
|
+
: {};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function finite(value: unknown): number | undefined {
|
|
45
|
+
const result = Number(value);
|
|
46
|
+
return Number.isFinite(result) ? result : undefined;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function behaviorDistance(left: Readonly<Position>, right: Readonly<Position>): number {
|
|
50
|
+
return Math.hypot(left.x - right.x, left.y - right.y);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function normalizedBehaviorLabel(value: string): string {
|
|
54
|
+
return value.trim().toLocaleLowerCase().replace(/\s+/gu, '').replace(/号$/u, '');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function behaviorSelf(input: Readonly<BehaviorInput>): Position | undefined {
|
|
58
|
+
const you = input.gameState.you;
|
|
59
|
+
return typeof you?.x === 'number' && typeof you.y === 'number'
|
|
60
|
+
? { x: you.x, y: you.y }
|
|
61
|
+
: undefined;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function behaviorVisiblePlayers(input: Readonly<BehaviorInput>): BehaviorPlayer[] {
|
|
65
|
+
return (input.gameState.visible_players ?? []).map((player: Readonly<VisiblePlayer>) => ({
|
|
66
|
+
name: player.player.name,
|
|
67
|
+
seat: player.player.seat,
|
|
68
|
+
x: player.x,
|
|
69
|
+
y: player.y,
|
|
70
|
+
room: player.room,
|
|
71
|
+
...(player.distance === undefined ? {} : { distance: player.distance }),
|
|
72
|
+
...(player.is_alive === undefined ? {} : { isAlive: player.is_alive }),
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function behaviorVisiblePlayer(
|
|
77
|
+
input: Readonly<BehaviorInput>,
|
|
78
|
+
seat: number,
|
|
79
|
+
): BehaviorPlayer | undefined {
|
|
80
|
+
return behaviorVisiblePlayers(input).find((player) => player.seat === seat);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function behaviorKnownPlayer(
|
|
84
|
+
input: Readonly<BehaviorInput>,
|
|
85
|
+
seat: number,
|
|
86
|
+
): Readonly<{ name: string; seat: number; isAlive?: boolean }> | undefined {
|
|
87
|
+
const player = input.gameState.players?.find((candidate) => candidate.seat === seat);
|
|
88
|
+
return player === undefined ? undefined : {
|
|
89
|
+
name: player.name,
|
|
90
|
+
seat: player.seat,
|
|
91
|
+
...(player.known_status.is_alive === undefined
|
|
92
|
+
? {}
|
|
93
|
+
: { isAlive: player.known_status.is_alive }),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function behaviorPlayerLabel(input: Readonly<BehaviorInput>, seat: number): string {
|
|
98
|
+
const player = behaviorVisiblePlayer(input, seat) ?? behaviorKnownPlayer(input, seat);
|
|
99
|
+
return player ? `${seat}号${player.name}` : `${seat}号玩家`;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function behaviorTeammateSeats(input: Readonly<BehaviorInput>): ReadonlySet<number> {
|
|
103
|
+
return new Set((input.gameState.you?.crab_teammates ?? []).map((player) => player.seat));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function behaviorCrabTeammatesKnown(input: Readonly<BehaviorInput>): boolean {
|
|
107
|
+
return Array.isArray(input.gameState.you?.crab_teammates);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function behaviorVisibleCorpses(input: Readonly<BehaviorInput>): BehaviorCorpse[] {
|
|
111
|
+
return (input.gameState.visible_corpses ?? []).map((corpse: Readonly<VisibleCorpse>) => ({
|
|
112
|
+
id: corpse.corpse_id,
|
|
113
|
+
x: corpse.x,
|
|
114
|
+
y: corpse.y,
|
|
115
|
+
room: corpse.room,
|
|
116
|
+
...(corpse.player === undefined ? {} : {
|
|
117
|
+
name: corpse.player.name,
|
|
118
|
+
seat: corpse.player.seat,
|
|
119
|
+
}),
|
|
120
|
+
...(corpse.distance === undefined ? {} : { distance: corpse.distance }),
|
|
121
|
+
}));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function roomCenter(room: Readonly<SpatialRoom>): NamedPoint {
|
|
125
|
+
const points = room.polygon;
|
|
126
|
+
if (points.length === 0) {
|
|
127
|
+
return {
|
|
128
|
+
name: room.name,
|
|
129
|
+
x: (room.bbox.left + room.bbox.right) / 2,
|
|
130
|
+
y: (room.bbox.top + room.bbox.bottom) / 2,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
name: room.name,
|
|
135
|
+
x: points.reduce((sum, point) => sum + point[0], 0) / points.length,
|
|
136
|
+
y: points.reduce((sum, point) => sum + point[1], 0) / points.length,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export function behaviorRooms(api: BehaviorReadApi): NamedPoint[] {
|
|
141
|
+
return api.spatial.rooms.map(roomCenter);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export function findBehaviorRoom(
|
|
145
|
+
api: BehaviorReadApi,
|
|
146
|
+
value: string,
|
|
147
|
+
): (NamedPoint & { readonly polygon: readonly (readonly [number, number])[] }) | undefined {
|
|
148
|
+
const expected = normalizedBehaviorLabel(value);
|
|
149
|
+
const room = api.spatial.rooms.find((candidate) => (
|
|
150
|
+
normalizedBehaviorLabel(candidate.name) === expected
|
|
151
|
+
)) ?? api.spatial.rooms.find((candidate) => (
|
|
152
|
+
normalizedBehaviorLabel(candidate.name).includes(expected)
|
|
153
|
+
));
|
|
154
|
+
return room === undefined ? undefined : {
|
|
155
|
+
...roomCenter(room),
|
|
156
|
+
polygon: room.polygon,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function taskPoint(task: Readonly<GameTask>): BehaviorTaskPoint {
|
|
161
|
+
return {
|
|
162
|
+
...(task.task_id ? { id: task.task_id } : {}),
|
|
163
|
+
name: task.name,
|
|
164
|
+
room: task.room,
|
|
165
|
+
x: task.x,
|
|
166
|
+
y: task.y,
|
|
167
|
+
...(task.status ? { status: task.status } : {}),
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export function behaviorTasks(input: Readonly<BehaviorInput>): BehaviorTaskPoint[] {
|
|
172
|
+
const personal = (input.gameState.you?.tasks ?? []).map(taskPoint);
|
|
173
|
+
const emergency = input.gameState.emergency;
|
|
174
|
+
if (
|
|
175
|
+
emergency?.active !== true
|
|
176
|
+
|| !emergency.task_name
|
|
177
|
+
|| typeof emergency.x !== 'number'
|
|
178
|
+
|| typeof emergency.y !== 'number'
|
|
179
|
+
) return personal;
|
|
180
|
+
const candidate: BehaviorTaskPoint = {
|
|
181
|
+
id: `emergency:${emergency.task_name}`,
|
|
182
|
+
name: emergency.task_name,
|
|
183
|
+
...(emergency.room ? { room: emergency.room } : {}),
|
|
184
|
+
x: emergency.x,
|
|
185
|
+
y: emergency.y,
|
|
186
|
+
status: 'normal',
|
|
187
|
+
};
|
|
188
|
+
return personal.some((task) => (
|
|
189
|
+
task.id === candidate.id
|
|
190
|
+
|| normalizedBehaviorLabel(task.name) === normalizedBehaviorLabel(candidate.name)
|
|
191
|
+
)) ? personal : [...personal, candidate];
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export function behaviorTaskAvailable(task: Readonly<BehaviorTaskPoint>): boolean {
|
|
195
|
+
return task.status !== 'completed' && task.status !== 'in_progress';
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function playerSeat(value: unknown): number | undefined {
|
|
199
|
+
if (typeof value === 'number' && Number.isInteger(value) && value >= 1 && value <= 10) {
|
|
200
|
+
return value;
|
|
201
|
+
}
|
|
202
|
+
const source = record(value);
|
|
203
|
+
const nested = record(source.player);
|
|
204
|
+
const seat = finite(source.target_seat ?? source.player_seat ?? source.corpse_seat ?? source.seat ?? nested.seat);
|
|
205
|
+
return seat !== undefined && Number.isInteger(seat) && seat >= 1 && seat <= 10
|
|
206
|
+
? seat
|
|
207
|
+
: undefined;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export function behaviorEventMentionsSeat(
|
|
211
|
+
events: readonly Readonly<GameEvent>[],
|
|
212
|
+
types: readonly string[],
|
|
213
|
+
seat: number,
|
|
214
|
+
): boolean {
|
|
215
|
+
return events.some((event) => {
|
|
216
|
+
if (!types.includes(event.type)) return false;
|
|
217
|
+
const payload = record(event.payload);
|
|
218
|
+
return [
|
|
219
|
+
payload.target_seat,
|
|
220
|
+
payload.player_seat,
|
|
221
|
+
payload.corpse_seat,
|
|
222
|
+
payload.target,
|
|
223
|
+
payload.actor,
|
|
224
|
+
payload.killer,
|
|
225
|
+
payload.player,
|
|
226
|
+
payload.corpse,
|
|
227
|
+
].some((value) => playerSeat(value) === seat);
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function playerName(value: unknown): string | undefined {
|
|
232
|
+
if (typeof value === 'string') return value.trim() || undefined;
|
|
233
|
+
const source = record(value);
|
|
234
|
+
const nested = record(source.player);
|
|
235
|
+
const name = String(source.name ?? nested.name ?? '').trim();
|
|
236
|
+
return name || undefined;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export function behaviorEventMentionsTarget(
|
|
240
|
+
events: readonly Readonly<GameEvent>[],
|
|
241
|
+
types: readonly string[],
|
|
242
|
+
target?: string,
|
|
243
|
+
): boolean {
|
|
244
|
+
return events.some((event) => {
|
|
245
|
+
if (!types.includes(event.type)) return false;
|
|
246
|
+
if (!target) return true;
|
|
247
|
+
const payload = record(event.payload);
|
|
248
|
+
const semantic = String(
|
|
249
|
+
payload.task_name ?? payload.task ?? payload.target_name ?? payload.corpse_name ?? '',
|
|
250
|
+
).trim();
|
|
251
|
+
if (semantic && normalizedBehaviorLabel(semantic) === normalizedBehaviorLabel(target)) return true;
|
|
252
|
+
return [payload.target, payload.actor, payload.killer, payload.player, payload.corpse]
|
|
253
|
+
.map(playerName)
|
|
254
|
+
.some((name) => !!name && normalizedBehaviorLabel(name) === normalizedBehaviorLabel(target));
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export function behaviorHasEvent(
|
|
259
|
+
events: readonly Readonly<GameEvent>[],
|
|
260
|
+
types: readonly string[],
|
|
261
|
+
): boolean {
|
|
262
|
+
return events.some((event) => types.includes(event.type));
|
|
263
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
BehaviorInput,
|
|
3
|
+
GameAction,
|
|
4
|
+
Position,
|
|
5
|
+
} from '../behavior-plugin/index.js';
|
|
6
|
+
import { behaviorDistance } from './model.js';
|
|
7
|
+
|
|
8
|
+
const MOVE_TARGET_EPSILON = 10;
|
|
9
|
+
|
|
10
|
+
/** Activation-local semantic move dedupe driven only by authoritative State/Event. */
|
|
11
|
+
export class SemanticMoveGate {
|
|
12
|
+
private target?: Position;
|
|
13
|
+
private stopOnPlayer = false;
|
|
14
|
+
private submittedEpoch?: number;
|
|
15
|
+
|
|
16
|
+
clear(): void {
|
|
17
|
+
this.target = undefined;
|
|
18
|
+
this.submittedEpoch = undefined;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
propose(
|
|
22
|
+
input: Readonly<BehaviorInput>,
|
|
23
|
+
target: Readonly<Position>,
|
|
24
|
+
stopOnPlayer = false,
|
|
25
|
+
thinkingContent?: string,
|
|
26
|
+
): Readonly<GameAction> | undefined {
|
|
27
|
+
const terminalMovement = input.events.some((event) => (
|
|
28
|
+
event.type === 'move_end' || event.type === 'move_interrupted'
|
|
29
|
+
));
|
|
30
|
+
if (terminalMovement || (
|
|
31
|
+
this.submittedEpoch !== undefined
|
|
32
|
+
&& input.epochId > this.submittedEpoch
|
|
33
|
+
&& input.gameState.you?.activity?.kind !== 'moving'
|
|
34
|
+
)) this.clear();
|
|
35
|
+
|
|
36
|
+
const repeats = this.target !== undefined
|
|
37
|
+
&& behaviorDistance(this.target, target) <= MOVE_TARGET_EPSILON
|
|
38
|
+
&& this.stopOnPlayer === stopOnPlayer;
|
|
39
|
+
if (repeats && input.gameState.you?.activity?.kind === 'moving') return undefined;
|
|
40
|
+
|
|
41
|
+
this.target = { x: target.x, y: target.y };
|
|
42
|
+
this.stopOnPlayer = stopOnPlayer;
|
|
43
|
+
this.submittedEpoch = input.epochId;
|
|
44
|
+
return {
|
|
45
|
+
action: 'move',
|
|
46
|
+
target_x: target.x,
|
|
47
|
+
target_y: target.y,
|
|
48
|
+
...(stopOnPlayer ? { stop_on_player: true } : {}),
|
|
49
|
+
...(thinkingContent ? { thinking_content: thinkingContent } : {}),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
BehaviorInput,
|
|
3
|
+
BehaviorReadApi,
|
|
4
|
+
Position,
|
|
5
|
+
} from '../behavior-plugin/index.js';
|
|
6
|
+
import {
|
|
7
|
+
behaviorDistance,
|
|
8
|
+
behaviorTasks,
|
|
9
|
+
findBehaviorRoom,
|
|
10
|
+
roomCenter,
|
|
11
|
+
type NamedPoint,
|
|
12
|
+
} from './model.js';
|
|
13
|
+
|
|
14
|
+
const POINT_SEPARATION = 90;
|
|
15
|
+
|
|
16
|
+
export function behaviorPatrolTargets(
|
|
17
|
+
input: Readonly<BehaviorInput>,
|
|
18
|
+
api: BehaviorReadApi,
|
|
19
|
+
area?: string,
|
|
20
|
+
): NamedPoint[] {
|
|
21
|
+
const room = area ? findBehaviorRoom(api, area) : undefined;
|
|
22
|
+
if (area && !room) return [];
|
|
23
|
+
if (!room) return api.spatial.rooms.map(roomCenter);
|
|
24
|
+
const rawRoom = api.spatial.rooms.find((candidate) => candidate.name === room.name)!;
|
|
25
|
+
const candidates: NamedPoint[] = [
|
|
26
|
+
...behaviorTasks(input)
|
|
27
|
+
.filter((task) => task.room === room.name)
|
|
28
|
+
.map((task) => ({ name: task.name, x: task.x, y: task.y })),
|
|
29
|
+
room,
|
|
30
|
+
...room.polygon.map((point, index) => ({
|
|
31
|
+
name: `${room.name}巡逻点${index + 1}`,
|
|
32
|
+
x: room.x + (point[0] - room.x) * 0.55,
|
|
33
|
+
y: room.y + (point[1] - room.y) * 0.55,
|
|
34
|
+
})),
|
|
35
|
+
];
|
|
36
|
+
const result: NamedPoint[] = [];
|
|
37
|
+
for (const candidate of candidates) {
|
|
38
|
+
if (!Number.isFinite(candidate.x) || !Number.isFinite(candidate.y)) continue;
|
|
39
|
+
if (result.some((point) => behaviorDistance(point, candidate) < POINT_SEPARATION)) continue;
|
|
40
|
+
result.push(candidate);
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
export async function distancesFromSelf(
|
|
45
|
+
input: Readonly<BehaviorInput>,
|
|
46
|
+
api: BehaviorReadApi,
|
|
47
|
+
targets: readonly Readonly<Position>[],
|
|
48
|
+
): Promise<readonly (number | null)[] | undefined> {
|
|
49
|
+
const you = input.gameState.you;
|
|
50
|
+
if (typeof you?.x !== 'number' || typeof you.y !== 'number') return undefined;
|
|
51
|
+
const from = { x: you.x, y: you.y };
|
|
52
|
+
return api.navigation.pathDistances(targets.map((to) => ({ from, to })));
|
|
53
|
+
}
|