@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,48 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ClawclawBehavior,
|
|
3
|
+
type BehaviorInput,
|
|
4
|
+
type BehaviorNormalizationApi,
|
|
5
|
+
type ClawclawBehaviorManifest,
|
|
6
|
+
} from '../../sdk/behavior-plugin/index.js';
|
|
7
|
+
import { finished, running } from './shared.js';
|
|
8
|
+
|
|
9
|
+
type HoldInput = Readonly<Record<string, unknown>> & {
|
|
10
|
+
readonly duration_ms?: number;
|
|
11
|
+
readonly timeout_ms?: number;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export default class HoldPositionBehavior extends ClawclawBehavior<HoldInput> {
|
|
15
|
+
static override readonly manifest = {
|
|
16
|
+
apiVersion: 3,
|
|
17
|
+
id: 'hold_position',
|
|
18
|
+
name: 'Hold Position',
|
|
19
|
+
description: 'Stop planning movement and wait in place for a finite duration.',
|
|
20
|
+
localizations: { 'zh-CN': { name: '原地等待', description: '停止规划移动,并在原地等待有限时长。' } },
|
|
21
|
+
inputs: [],
|
|
22
|
+
execution: 'serial',
|
|
23
|
+
runtime: { defaultMs: 5_000, deadlineOutcome: 'failed', controlGraceMs: 11_000 },
|
|
24
|
+
} as const satisfies ClawclawBehaviorManifest;
|
|
25
|
+
|
|
26
|
+
private startedAtMs?: number;
|
|
27
|
+
private holdUntilMs?: number;
|
|
28
|
+
|
|
29
|
+
override normalize(input: Readonly<Record<string, unknown>>, api: BehaviorNormalizationApi): HoldInput {
|
|
30
|
+
return { ...api.timing(input) };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
override decide(input: Readonly<BehaviorInput<HoldInput>>) {
|
|
34
|
+
this.startedAtMs ??= input.nowMs;
|
|
35
|
+
if (input.gameState.you?.activity?.kind === 'moving') {
|
|
36
|
+
if (input.nowMs - this.startedAtMs >= 10_000) {
|
|
37
|
+
return finished('failed', 'motion_did_not_stop', '底层已有移动未在等待预算内结束,无法开始原地等待。');
|
|
38
|
+
}
|
|
39
|
+
return running('已停止规划新移动,等待底层现有移动结束后原地等待。', 'waiting');
|
|
40
|
+
}
|
|
41
|
+
const duration = input.input.duration_ms ?? input.input.timeout_ms ?? 5_000;
|
|
42
|
+
this.holdUntilMs ??= input.nowMs + duration;
|
|
43
|
+
if (input.nowMs >= this.holdUntilMs) {
|
|
44
|
+
return finished('completed', 'duration_elapsed', '已完成明确的原地有限等待。');
|
|
45
|
+
}
|
|
46
|
+
return running(`正在原地有限等待,剩余约${Math.max(0, Math.ceil((this.holdUntilMs - input.nowMs) / 1_000))}秒。`, 'waiting');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ClawclawBehavior,
|
|
3
|
+
type BehaviorInput,
|
|
4
|
+
type BehaviorNormalizationApi,
|
|
5
|
+
type BehaviorReadApi,
|
|
6
|
+
type ClawclawBehaviorManifest,
|
|
7
|
+
} from '../../sdk/behavior-plugin/index.js';
|
|
8
|
+
import {
|
|
9
|
+
AuthoritativeKillFlow,
|
|
10
|
+
type AfterKillBehavior,
|
|
11
|
+
} from '../../sdk/behavior-toolkit/index.js';
|
|
12
|
+
|
|
13
|
+
type HuntInput = Readonly<Record<string, unknown>> & {
|
|
14
|
+
readonly player_seat: number;
|
|
15
|
+
readonly after_kill: AfterKillBehavior;
|
|
16
|
+
readonly timeout_ms?: number;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default class HuntPlayerBehavior extends ClawclawBehavior<HuntInput> {
|
|
20
|
+
static override readonly manifest = {
|
|
21
|
+
apiVersion: 3,
|
|
22
|
+
id: 'hunt_player',
|
|
23
|
+
name: 'Hunt Player',
|
|
24
|
+
description: 'Find and attempt one authoritative kill against a player seat.',
|
|
25
|
+
localizations: { 'zh-CN': { name: '追猎玩家', description: '寻找指定玩家并尝试一次由权威状态确认的击杀。' } },
|
|
26
|
+
inputs: [
|
|
27
|
+
{ id: 'player_seat', type: 'player_seat', description: 'Authoritative seat of the player to hunt (1-10).', required: true },
|
|
28
|
+
{ id: 'after_kill', type: 'enum', description: 'Follow-up after a confirmed kill.', values: ['escape', 'hold', 'report', 'replan'], default: 'escape' },
|
|
29
|
+
],
|
|
30
|
+
execution: 'serial',
|
|
31
|
+
runtime: { defaultMs: 60_000, deadlineOutcome: 'failed' },
|
|
32
|
+
} as const satisfies ClawclawBehaviorManifest;
|
|
33
|
+
|
|
34
|
+
private readonly kill = new AuthoritativeKillFlow();
|
|
35
|
+
|
|
36
|
+
override normalize(input: Readonly<Record<string, unknown>>, api: BehaviorNormalizationApi): HuntInput {
|
|
37
|
+
return {
|
|
38
|
+
player_seat: api.number(input.player_seat, 'player_seat', { integer: true, min: 1, max: 10 }),
|
|
39
|
+
after_kill: api.choice(input.after_kill, 'after_kill', ['escape', 'hold', 'report', 'replan'] as const),
|
|
40
|
+
...api.timing(input),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
override decide(input: Readonly<BehaviorInput<HuntInput>>, api: BehaviorReadApi) {
|
|
45
|
+
return this.kill.step(input, api, input.input.player_seat, input.input.after_kill);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import type {
|
|
3
|
+
BehaviorInput,
|
|
4
|
+
BehaviorReadApi,
|
|
5
|
+
GameState,
|
|
6
|
+
ObservedCorpse,
|
|
7
|
+
ObservedPlayer,
|
|
8
|
+
} from '../../sdk/behavior-plugin/index.js';
|
|
9
|
+
import {
|
|
10
|
+
DoTaskBehavior,
|
|
11
|
+
GoToBehavior,
|
|
12
|
+
HuntPlayerBehavior,
|
|
13
|
+
OFFICIAL_FINITE_BEHAVIOR_CLASSES,
|
|
14
|
+
ReportCorpseBehavior,
|
|
15
|
+
TriggerAlarmBehavior,
|
|
16
|
+
} from './index.js';
|
|
17
|
+
|
|
18
|
+
const rooms = [{
|
|
19
|
+
name: '厨房',
|
|
20
|
+
polygon: [[100, 0], [200, 0], [200, 100], [100, 100]] as const,
|
|
21
|
+
bbox: { left: 100, top: 0, right: 200, bottom: 100 },
|
|
22
|
+
}, {
|
|
23
|
+
name: '酒吧',
|
|
24
|
+
polygon: [[300, 0], [400, 0], [400, 100], [300, 100]] as const,
|
|
25
|
+
bbox: { left: 300, top: 0, right: 400, bottom: 100 },
|
|
26
|
+
}] as const;
|
|
27
|
+
|
|
28
|
+
function api(options: Readonly<{
|
|
29
|
+
players?: readonly Readonly<ObservedPlayer>[];
|
|
30
|
+
corpses?: readonly Readonly<ObservedCorpse>[];
|
|
31
|
+
}> = {}): BehaviorReadApi {
|
|
32
|
+
const distance = (from: Readonly<{ x: number; y: number }>, to: Readonly<{ x: number; y: number }>) => (
|
|
33
|
+
Math.hypot(from.x - to.x, from.y - to.y)
|
|
34
|
+
);
|
|
35
|
+
return {
|
|
36
|
+
spatial: {
|
|
37
|
+
xPositive: 'right',
|
|
38
|
+
yPositive: 'down',
|
|
39
|
+
playerBodyLengthPx: 64,
|
|
40
|
+
rooms,
|
|
41
|
+
roomAt: () => null,
|
|
42
|
+
sideInRoom: () => null,
|
|
43
|
+
placeLabel: () => '',
|
|
44
|
+
transitionIsMapped: () => true,
|
|
45
|
+
},
|
|
46
|
+
navigation: {
|
|
47
|
+
pathDistance: async (from, to) => distance(from, to),
|
|
48
|
+
pathDistances: async (queries) => queries.map(({ from, to }) => distance(from, to)),
|
|
49
|
+
},
|
|
50
|
+
observation: {
|
|
51
|
+
lastSeenPlayer: (seat, maxAgeMs) => options.players?.find((player) => (
|
|
52
|
+
player.seat === seat && (maxAgeMs === undefined || player.ageMs <= maxAgeMs)
|
|
53
|
+
)),
|
|
54
|
+
lastSeenCorpse: (seat) => options.corpses?.find((corpse) => (
|
|
55
|
+
seat === undefined || corpse.seat === seat
|
|
56
|
+
)),
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function state(overrides: Partial<GameState> = {}): GameState {
|
|
62
|
+
return {
|
|
63
|
+
game_id: 'game',
|
|
64
|
+
tick: 1,
|
|
65
|
+
phase: 'wandering',
|
|
66
|
+
you: {
|
|
67
|
+
player: { seat: 1, name: 'Self' },
|
|
68
|
+
x: 0,
|
|
69
|
+
y: 0,
|
|
70
|
+
room: '走廊',
|
|
71
|
+
role: 'shrimp_generic',
|
|
72
|
+
faction: 'lobster',
|
|
73
|
+
is_alive: true,
|
|
74
|
+
activity: { kind: 'idle' },
|
|
75
|
+
tasks: [],
|
|
76
|
+
},
|
|
77
|
+
players: [],
|
|
78
|
+
visible_players: [],
|
|
79
|
+
visible_corpses: [],
|
|
80
|
+
...overrides,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function frame<T extends Readonly<Record<string, unknown>>>(
|
|
85
|
+
gameState: GameState,
|
|
86
|
+
values: T,
|
|
87
|
+
epochId = 1,
|
|
88
|
+
nowMs = 1_000,
|
|
89
|
+
): BehaviorInput<T> {
|
|
90
|
+
return {
|
|
91
|
+
epochId,
|
|
92
|
+
scope: { sessionId: 'session', segmentId: 'segment' },
|
|
93
|
+
nowMs,
|
|
94
|
+
gameState,
|
|
95
|
+
events: [],
|
|
96
|
+
input: values,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
describe('official finite Behavior modules', () => {
|
|
101
|
+
it('exposes thirteen unique serial API v3 modules with real decide handlers', () => {
|
|
102
|
+
expect(OFFICIAL_FINITE_BEHAVIOR_CLASSES).toHaveLength(13);
|
|
103
|
+
const ids = OFFICIAL_FINITE_BEHAVIOR_CLASSES.map((BehaviorClass) => BehaviorClass.manifest?.id);
|
|
104
|
+
expect(new Set(ids).size).toBe(13);
|
|
105
|
+
expect(ids).toContain('hide_temporarily');
|
|
106
|
+
expect(ids).not.toContain('hide');
|
|
107
|
+
for (const BehaviorClass of OFFICIAL_FINITE_BEHAVIOR_CLASSES) {
|
|
108
|
+
expect(BehaviorClass.manifest).toMatchObject({ apiVersion: 3, execution: 'serial' });
|
|
109
|
+
expect(String(BehaviorClass.prototype.decide).replace(/\s/g, '')).not.toMatch(/\{return\{\};?\}$/);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('go_to moves and completes only from later authoritative position', async () => {
|
|
114
|
+
const behavior = new GoToBehavior();
|
|
115
|
+
const first = await behavior.decide(frame(state(), { destination: '厨房', timeout_ms: 45_000 }), api());
|
|
116
|
+
expect(first?.actions).toEqual([expect.objectContaining({ action: 'move' })]);
|
|
117
|
+
expect(first?.finish).toBeUndefined();
|
|
118
|
+
|
|
119
|
+
const arrived = state({ you: { ...state().you!, x: 150, y: 50, room: '厨房' } });
|
|
120
|
+
const second = await behavior.decide(frame(arrived, { destination: '厨房', timeout_ms: 45_000 }, 2), api());
|
|
121
|
+
expect(second?.finish).toMatchObject({ outcome: 'completed', reason: 'arrived' });
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('hunt_player waits for later authoritative kill evidence without a receipt', async () => {
|
|
125
|
+
const behavior = new HuntPlayerBehavior();
|
|
126
|
+
const hunting = state({
|
|
127
|
+
you: { ...state().you!, role: 'crab_generic', faction: 'crab', kills_remaining: 1, crab_teammates: [] },
|
|
128
|
+
players: [{ seat: 2, name: 'Target', known_status: { is_alive: true } }],
|
|
129
|
+
visible_players: [{ player: { seat: 2, name: 'Target' }, x: 10, y: 0, room: '走廊', distance: 10, is_alive: true }],
|
|
130
|
+
});
|
|
131
|
+
const first = await behavior.decide(frame(hunting, {
|
|
132
|
+
player_seat: 2,
|
|
133
|
+
after_kill: 'replan',
|
|
134
|
+
timeout_ms: 60_000,
|
|
135
|
+
}), api());
|
|
136
|
+
expect(first?.actions).toEqual([expect.objectContaining({ action: 'kill', target_seat: 2 })]);
|
|
137
|
+
expect(first?.finish).toBeUndefined();
|
|
138
|
+
|
|
139
|
+
const confirmed = state({
|
|
140
|
+
you: { ...hunting.you!, kills_remaining: 0 },
|
|
141
|
+
players: [{ seat: 2, name: 'Target', known_status: { is_alive: false } }],
|
|
142
|
+
});
|
|
143
|
+
const second = await behavior.decide(frame(confirmed, {
|
|
144
|
+
player_seat: 2,
|
|
145
|
+
after_kill: 'replan',
|
|
146
|
+
timeout_ms: 60_000,
|
|
147
|
+
}, 2, 1_100), api());
|
|
148
|
+
expect(second?.finish).toMatchObject({ outcome: 'completed', reason: 'kill_confirmed' });
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('do_task waits for a later authoritative completed task', async () => {
|
|
152
|
+
const behavior = new DoTaskBehavior();
|
|
153
|
+
const taskState = state({
|
|
154
|
+
you: {
|
|
155
|
+
...state().you!,
|
|
156
|
+
tasks: [{ task_id: 'wires', name: '接线', room: '走廊', x: 5, y: 0, is_fake_shrimp: false, status: 'normal' }],
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
const first = await behavior.decide(frame(taskState, { task: 'wires', timeout_ms: 60_000 }), api());
|
|
160
|
+
expect(first?.actions).toEqual([expect.objectContaining({ action: 'task', task_name: '接线' })]);
|
|
161
|
+
const completed = state({
|
|
162
|
+
you: {
|
|
163
|
+
...taskState.you!,
|
|
164
|
+
tasks: [{ task_id: 'wires', name: '接线', room: '走廊', x: 5, y: 0, is_fake_shrimp: false, status: 'completed' }],
|
|
165
|
+
},
|
|
166
|
+
});
|
|
167
|
+
const second = await behavior.decide(frame(completed, { task: 'wires', timeout_ms: 60_000 }, 2), api());
|
|
168
|
+
expect(second?.finish).toMatchObject({ outcome: 'completed', reason: 'task_completed' });
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it('report_corpse completes only after a later meeting transition', async () => {
|
|
172
|
+
const behavior = new ReportCorpseBehavior();
|
|
173
|
+
const corpseState = state({
|
|
174
|
+
visible_corpses: [{ corpse_id: 'corpse-2', player: { seat: 2, name: 'Dead' }, x: 10, y: 0, room: '走廊', distance: 10 }],
|
|
175
|
+
});
|
|
176
|
+
const first = await behavior.decide(frame(corpseState, { corpse_seat: 2, timeout_ms: 45_000 }), api());
|
|
177
|
+
expect(first?.actions).toEqual([expect.objectContaining({ action: 'report' })]);
|
|
178
|
+
expect(first?.finish).toBeUndefined();
|
|
179
|
+
|
|
180
|
+
const meeting = state({ phase: 'meeting', meeting: { active: true } });
|
|
181
|
+
const second = await behavior.decide(frame(meeting, { corpse_seat: 2, timeout_ms: 45_000 }, 2), api());
|
|
182
|
+
expect(second?.finish).toMatchObject({ outcome: 'completed', reason: 'corpse_reported' });
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('trigger_alarm waits for later shared emergency authority', () => {
|
|
186
|
+
const behavior = new TriggerAlarmBehavior();
|
|
187
|
+
const ready = state({
|
|
188
|
+
you: { ...state().you!, faction: 'crab' },
|
|
189
|
+
crab_sabotage: { status: 'ready' },
|
|
190
|
+
emergency: { active: false },
|
|
191
|
+
});
|
|
192
|
+
const first = behavior.decide(frame(ready, { timeout_ms: 10_000 }));
|
|
193
|
+
expect(first?.actions).toEqual([expect.objectContaining({ action: 'trigger_alarm' })]);
|
|
194
|
+
const active = state({
|
|
195
|
+
you: { ...ready.you! },
|
|
196
|
+
crab_sabotage: { status: 'emergency_active' },
|
|
197
|
+
emergency: { active: true },
|
|
198
|
+
});
|
|
199
|
+
const second = behavior.decide(frame(active, { timeout_ms: 10_000 }, 2));
|
|
200
|
+
expect(second?.finish).toMatchObject({ outcome: 'completed', reason: 'alarm_triggered' });
|
|
201
|
+
});
|
|
202
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { ClawclawBehaviorClass } from '../../sdk/behavior-plugin/index.js';
|
|
2
|
+
import DoTaskBehavior from './do-task.js';
|
|
3
|
+
import EvadeBehavior from './evade.js';
|
|
4
|
+
import FindPlayerBehavior from './find-player.js';
|
|
5
|
+
import FollowPlayerBehavior from './follow-player.js';
|
|
6
|
+
import GoToBehavior from './go-to.js';
|
|
7
|
+
import HideTemporarilyBehavior from './hide-temporarily.js';
|
|
8
|
+
import HoldPositionBehavior from './hold-position.js';
|
|
9
|
+
import HuntPlayerBehavior from './hunt-player.js';
|
|
10
|
+
import InspectCorpseBehavior from './inspect-corpse.js';
|
|
11
|
+
import PatrolAreaBehavior from './patrol-area.js';
|
|
12
|
+
import ReportCorpseBehavior from './report-corpse.js';
|
|
13
|
+
import SeekKillOpportunityBehavior from './seek-kill-opportunity.js';
|
|
14
|
+
import TriggerAlarmBehavior from './trigger-alarm.js';
|
|
15
|
+
|
|
16
|
+
/** Standard public-API implementations; Runtime must load them like user modules. */
|
|
17
|
+
export const OFFICIAL_FINITE_BEHAVIOR_CLASSES = Object.freeze([
|
|
18
|
+
GoToBehavior,
|
|
19
|
+
PatrolAreaBehavior,
|
|
20
|
+
FindPlayerBehavior,
|
|
21
|
+
FollowPlayerBehavior,
|
|
22
|
+
HuntPlayerBehavior,
|
|
23
|
+
SeekKillOpportunityBehavior,
|
|
24
|
+
EvadeBehavior,
|
|
25
|
+
HideTemporarilyBehavior,
|
|
26
|
+
HoldPositionBehavior,
|
|
27
|
+
DoTaskBehavior,
|
|
28
|
+
InspectCorpseBehavior,
|
|
29
|
+
ReportCorpseBehavior,
|
|
30
|
+
TriggerAlarmBehavior,
|
|
31
|
+
] as const satisfies readonly ClawclawBehaviorClass[]);
|
|
32
|
+
|
|
33
|
+
export {
|
|
34
|
+
DoTaskBehavior,
|
|
35
|
+
EvadeBehavior,
|
|
36
|
+
FindPlayerBehavior,
|
|
37
|
+
FollowPlayerBehavior,
|
|
38
|
+
GoToBehavior,
|
|
39
|
+
HideTemporarilyBehavior,
|
|
40
|
+
HoldPositionBehavior,
|
|
41
|
+
HuntPlayerBehavior,
|
|
42
|
+
InspectCorpseBehavior,
|
|
43
|
+
PatrolAreaBehavior,
|
|
44
|
+
ReportCorpseBehavior,
|
|
45
|
+
SeekKillOpportunityBehavior,
|
|
46
|
+
TriggerAlarmBehavior,
|
|
47
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ClawclawBehavior,
|
|
3
|
+
type BehaviorInput,
|
|
4
|
+
type BehaviorNormalizationApi,
|
|
5
|
+
type BehaviorReadApi,
|
|
6
|
+
type ClawclawBehaviorManifest,
|
|
7
|
+
} from '../../sdk/behavior-plugin/index.js';
|
|
8
|
+
import {
|
|
9
|
+
behaviorDistance,
|
|
10
|
+
behaviorSelf,
|
|
11
|
+
behaviorVisibleCorpses,
|
|
12
|
+
FiniteCorpseSearch,
|
|
13
|
+
SemanticMoveGate,
|
|
14
|
+
} from '../../sdk/behavior-toolkit/index.js';
|
|
15
|
+
import { finished, running } from './shared.js';
|
|
16
|
+
|
|
17
|
+
type InspectInput = Readonly<Record<string, unknown>> & {
|
|
18
|
+
readonly corpse_seat?: number;
|
|
19
|
+
readonly timeout_ms?: number;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default class InspectCorpseBehavior extends ClawclawBehavior<InspectInput> {
|
|
23
|
+
static override readonly manifest = {
|
|
24
|
+
apiVersion: 3,
|
|
25
|
+
id: 'inspect_corpse',
|
|
26
|
+
name: 'Inspect Corpse',
|
|
27
|
+
description: 'Find and approach one corpse without reporting it.',
|
|
28
|
+
localizations: { 'zh-CN': { name: '检查尸体', description: '寻找并靠近一具尸体,但不报告。' } },
|
|
29
|
+
inputs: [{ id: 'corpse_seat', type: 'player_seat', description: 'Optional authoritative seat of the corpse owner (1-10).' }],
|
|
30
|
+
execution: 'serial',
|
|
31
|
+
runtime: { defaultMs: 30_000, deadlineOutcome: 'failed' },
|
|
32
|
+
} as const satisfies ClawclawBehaviorManifest;
|
|
33
|
+
|
|
34
|
+
private readonly search = new FiniteCorpseSearch();
|
|
35
|
+
private readonly move = new SemanticMoveGate();
|
|
36
|
+
|
|
37
|
+
override normalize(input: Readonly<Record<string, unknown>>, api: BehaviorNormalizationApi): InspectInput {
|
|
38
|
+
const seat = input.corpse_seat === undefined
|
|
39
|
+
? undefined
|
|
40
|
+
: api.number(input.corpse_seat, 'corpse_seat', { integer: true, min: 1, max: 10 });
|
|
41
|
+
return { ...api.timing(input), ...(seat === undefined ? {} : { corpse_seat: seat }) };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
override async decide(input: Readonly<BehaviorInput<InspectInput>>, api: BehaviorReadApi) {
|
|
45
|
+
const result = await this.search.step(input, api, input.input.corpse_seat);
|
|
46
|
+
if (result.kind === 'failed') return finished('failed', result.reason, result.summary);
|
|
47
|
+
if (result.kind === 'move') {
|
|
48
|
+
const action = this.move.propose(input, result.target, false, result.summary);
|
|
49
|
+
return running(result.summary, 'moving', action ? [action] : []);
|
|
50
|
+
}
|
|
51
|
+
const self = behaviorSelf(input);
|
|
52
|
+
if (!self) return finished('failed', 'self_position_unavailable', '当前无法取得自身位置。');
|
|
53
|
+
const label = result.corpse.name ?? '未辨认';
|
|
54
|
+
if (behaviorDistance(self, result.corpse) > 120) {
|
|
55
|
+
const summary = `正在前往${result.corpse.room ?? '最后目击区域'}查看${label}的尸体。`;
|
|
56
|
+
const action = this.move.propose(input, result.corpse, false, summary);
|
|
57
|
+
return running(summary, 'moving', action ? [action] : []);
|
|
58
|
+
}
|
|
59
|
+
const visible = behaviorVisibleCorpses(input).some((corpse) => corpse.id === result.corpse.id);
|
|
60
|
+
return visible
|
|
61
|
+
? finished('completed', 'corpse_inspected', `已靠近并观察${label}的尸体现场。`)
|
|
62
|
+
: finished('completed', 'corpse_unavailable', '已到达最后尸体位置,但尸体已不在视野内。');
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ClawclawBehavior,
|
|
3
|
+
type BehaviorInput,
|
|
4
|
+
type BehaviorNormalizationApi,
|
|
5
|
+
type BehaviorReadApi,
|
|
6
|
+
type ClawclawBehaviorManifest,
|
|
7
|
+
} from '../../sdk/behavior-plugin/index.js';
|
|
8
|
+
import {
|
|
9
|
+
behaviorPatrolTargets,
|
|
10
|
+
distancesFromSelf,
|
|
11
|
+
SemanticMoveGate,
|
|
12
|
+
} from '../../sdk/behavior-toolkit/index.js';
|
|
13
|
+
import { finished, running } from './shared.js';
|
|
14
|
+
|
|
15
|
+
type PatrolInput = Readonly<Record<string, unknown>> & {
|
|
16
|
+
readonly area?: string;
|
|
17
|
+
readonly duration_ms?: number;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export default class PatrolAreaBehavior extends ClawclawBehavior<PatrolInput> {
|
|
21
|
+
static override readonly manifest = {
|
|
22
|
+
apiVersion: 3,
|
|
23
|
+
id: 'patrol_area',
|
|
24
|
+
name: 'Patrol Area',
|
|
25
|
+
description: 'Patrol a bounded route, optionally inside one area.',
|
|
26
|
+
localizations: { 'zh-CN': { name: '区域巡逻', description: '沿有限路线巡逻,可限定在一个区域内。' } },
|
|
27
|
+
inputs: [{ id: 'area', type: 'string', description: 'Optional known room name to patrol.' }],
|
|
28
|
+
execution: 'serial',
|
|
29
|
+
runtime: { defaultMs: 30_000, deadlineOutcome: 'completed' },
|
|
30
|
+
} as const satisfies ClawclawBehaviorManifest;
|
|
31
|
+
|
|
32
|
+
private readonly move = new SemanticMoveGate();
|
|
33
|
+
private routeIndex = 0;
|
|
34
|
+
private dwellUntilMs?: number;
|
|
35
|
+
|
|
36
|
+
override normalize(input: Readonly<Record<string, unknown>>, api: BehaviorNormalizationApi): PatrolInput {
|
|
37
|
+
const area = api.optionalString(input.area, 'area');
|
|
38
|
+
return { ...api.timing(input), ...(area ? { area } : {}) };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
override async decide(input: Readonly<BehaviorInput<PatrolInput>>, api: BehaviorReadApi) {
|
|
42
|
+
const targets = behaviorPatrolTargets(input, api, input.input.area);
|
|
43
|
+
if (targets.length === 0) return finished('failed', 'area_unknown', `找不到巡逻区域“${input.input.area ?? ''}”。`);
|
|
44
|
+
if (input.input.area && targets.length < 2) {
|
|
45
|
+
return finished('failed', 'patrol_route_insufficient', `${input.input.area}无法建立至少两个不同巡逻观察点。`);
|
|
46
|
+
}
|
|
47
|
+
const distances = await distancesFromSelf(input, api, targets);
|
|
48
|
+
if (!distances) return finished('failed', 'self_position_unavailable', '当前无法取得自身位置。');
|
|
49
|
+
if (input.input.area && distances.filter((distance) => distance !== null).length < 2) {
|
|
50
|
+
return finished('failed', 'patrol_route_insufficient', `${input.input.area}当前不足两个可达巡逻观察点。`);
|
|
51
|
+
}
|
|
52
|
+
let selected = this.routeIndex % targets.length;
|
|
53
|
+
if (distances[selected] === null) {
|
|
54
|
+
const next = Array.from({ length: distances.length - 1 }, (_, offset) => (
|
|
55
|
+
(selected + offset + 1) % distances.length
|
|
56
|
+
)).find((index) => distances[index] !== null);
|
|
57
|
+
if (next === undefined) return finished('failed', 'search_route_unavailable', '当前没有可继续巡逻的可达观察点。');
|
|
58
|
+
this.routeIndex = next;
|
|
59
|
+
this.dwellUntilMs = undefined;
|
|
60
|
+
return running('当前观察点不可达,已转向巡逻路线的下一点。', 'waiting');
|
|
61
|
+
}
|
|
62
|
+
if ((distances[selected] ?? Infinity) <= 55) {
|
|
63
|
+
this.dwellUntilMs ??= input.nowMs + 700;
|
|
64
|
+
if (input.nowMs < this.dwellUntilMs) {
|
|
65
|
+
return running(`正在${targets[selected].name}短暂观察。`, 'waiting', [], input.input.area ? { room: input.input.area } : {});
|
|
66
|
+
}
|
|
67
|
+
this.routeIndex = (selected + 1) % targets.length;
|
|
68
|
+
this.dwellUntilMs = undefined;
|
|
69
|
+
return running(input.input.area
|
|
70
|
+
? `已完成${input.input.area}一个观察点,继续有限巡逻。`
|
|
71
|
+
: '已完成一个观察点,继续有限巡逻。', 'waiting');
|
|
72
|
+
}
|
|
73
|
+
this.dwellUntilMs = undefined;
|
|
74
|
+
this.routeIndex = selected;
|
|
75
|
+
const target = targets[selected];
|
|
76
|
+
const summary = input.input.area ? `正在${input.input.area}有限巡逻。` : '正在按有限路线巡逻。';
|
|
77
|
+
const action = this.move.propose(input, target, false, summary);
|
|
78
|
+
return running(summary, 'moving', action ? [action] : [], input.input.area ? { room: input.input.area } : {});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ClawclawBehavior,
|
|
3
|
+
type BehaviorInput,
|
|
4
|
+
type BehaviorNormalizationApi,
|
|
5
|
+
type BehaviorReadApi,
|
|
6
|
+
type ClawclawBehaviorManifest,
|
|
7
|
+
} from '../../sdk/behavior-plugin/index.js';
|
|
8
|
+
import {
|
|
9
|
+
behaviorDistance,
|
|
10
|
+
behaviorHasEvent,
|
|
11
|
+
behaviorSelf,
|
|
12
|
+
behaviorVisibleCorpses,
|
|
13
|
+
FiniteCorpseSearch,
|
|
14
|
+
SemanticMoveGate,
|
|
15
|
+
} from '../../sdk/behavior-toolkit/index.js';
|
|
16
|
+
import { finished, running } from './shared.js';
|
|
17
|
+
|
|
18
|
+
type ReportInput = Readonly<Record<string, unknown>> & {
|
|
19
|
+
readonly corpse_seat?: number;
|
|
20
|
+
readonly timeout_ms?: number;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default class ReportCorpseBehavior extends ClawclawBehavior<ReportInput> {
|
|
24
|
+
static override readonly manifest = {
|
|
25
|
+
apiVersion: 3,
|
|
26
|
+
id: 'report_corpse',
|
|
27
|
+
name: 'Report Corpse',
|
|
28
|
+
description: 'Find, approach, and submit one authoritative corpse report.',
|
|
29
|
+
localizations: { 'zh-CN': { name: '报告尸体', description: '寻找、靠近并提交一次由权威状态确认的尸体报告。' } },
|
|
30
|
+
inputs: [{ id: 'corpse_seat', type: 'player_seat', description: 'Optional authoritative seat of the corpse owner (1-10).' }],
|
|
31
|
+
execution: 'serial',
|
|
32
|
+
runtime: { defaultMs: 45_000, deadlineOutcome: 'failed' },
|
|
33
|
+
} as const satisfies ClawclawBehaviorManifest;
|
|
34
|
+
|
|
35
|
+
private readonly search = new FiniteCorpseSearch();
|
|
36
|
+
private readonly move = new SemanticMoveGate();
|
|
37
|
+
private submitted = false;
|
|
38
|
+
|
|
39
|
+
override normalize(input: Readonly<Record<string, unknown>>, api: BehaviorNormalizationApi): ReportInput {
|
|
40
|
+
const seat = input.corpse_seat === undefined
|
|
41
|
+
? undefined
|
|
42
|
+
: api.number(input.corpse_seat, 'corpse_seat', { integer: true, min: 1, max: 10 });
|
|
43
|
+
return { ...api.timing(input), ...(seat === undefined ? {} : { corpse_seat: seat }) };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
override async decide(input: Readonly<BehaviorInput<ReportInput>>, api: BehaviorReadApi) {
|
|
47
|
+
if (this.submitted) {
|
|
48
|
+
if (input.gameState.phase === 'meeting' || behaviorHasEvent(input.events, ['meeting_start', 'meeting_briefing'])) {
|
|
49
|
+
return finished('completed', 'corpse_reported', '报告已触发会议;实际报告对象以权威结果为准。');
|
|
50
|
+
}
|
|
51
|
+
return running('等待报告是否触发会议的权威状态;不会重复提交。', 'acting');
|
|
52
|
+
}
|
|
53
|
+
const result = await this.search.step(input, api, input.input.corpse_seat);
|
|
54
|
+
if (result.kind === 'failed') return finished('failed', result.reason, result.summary);
|
|
55
|
+
if (result.kind === 'move') {
|
|
56
|
+
const action = this.move.propose(input, result.target, false, result.summary);
|
|
57
|
+
return running(result.summary, 'moving', action ? [action] : []);
|
|
58
|
+
}
|
|
59
|
+
const self = behaviorSelf(input);
|
|
60
|
+
if (!self) return finished('failed', 'self_position_unavailable', '当前无法取得自身位置。');
|
|
61
|
+
const label = result.corpse.name ?? '未辨认';
|
|
62
|
+
if (behaviorDistance(self, result.corpse) > 140) {
|
|
63
|
+
const summary = `正在前往${result.corpse.room ?? '最后目击区域'}查看${label}的尸体。`;
|
|
64
|
+
const action = this.move.propose(input, result.corpse, false, summary);
|
|
65
|
+
return running(summary, 'moving', action ? [action] : []);
|
|
66
|
+
}
|
|
67
|
+
const visible = behaviorVisibleCorpses(input).some((corpse) => corpse.id === result.corpse.id);
|
|
68
|
+
if (!visible) return finished('failed', 'corpse_unavailable', '到达最后位置时尸体已经不可报告。');
|
|
69
|
+
this.submitted = true;
|
|
70
|
+
const summary = '正在报告当前范围内实际可报告的尸体。';
|
|
71
|
+
return running(summary, 'acting', [{ action: 'report', thinking_content: summary }]);
|
|
72
|
+
}
|
|
73
|
+
}
|