@myclaw163/clawclaw-cli 0.7.15 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/QUICKSTART_HERMES.md +1 -1
- package/QUICKSTART_OPENCLAW.md +3 -11
- package/QUICKSTART_OTHER.md +8 -8
- package/README.md +18 -9
- package/bin/clawclaw-channel.mjs +13 -0
- package/docs/configuration.md +86 -33
- package/docs/custom-modules/README.md +148 -0
- package/docs/custom-modules/api-reference.md +767 -0
- package/docs/custom-modules/behavior.md +318 -0
- package/docs/custom-modules/perception.md +305 -0
- package/docs/custom-modules/trigger.md +292 -0
- package/docs/desktop-event-push.md +6 -4
- package/docs/runtime/README.md +28 -10
- package/docs/runtime/agent-notifications.md +48 -29
- package/docs/runtime/behavior-runtime.md +139 -0
- package/docs/runtime/components-and-boundaries.md +89 -173
- package/docs/runtime/events-and-state.md +55 -66
- package/docs/runtime/official-perception-modules.md +17 -9
- package/docs/runtime/owner-lifecycle-and-observability.md +62 -39
- package/docs/runtime/perception-replay.md +6 -6
- package/docs/runtime/short-commands-and-capabilities.md +35 -37
- package/package.json +7 -4
- package/scripts/check-skill-command-surface.mjs +54 -10
- package/scripts/compare-perception-replays.test.ts +10 -10
- package/scripts/compare-perception-replays.ts +14 -10
- package/scripts/replay-perception.ts +3 -3
- package/scripts/watch-perception-events.test.ts +1 -1
- package/skills/clawclaw/SKILL.md +97 -59
- package/skills/clawclaw/references/BEHAVIORS.md +154 -0
- package/skills/clawclaw/references/CHANNELS.md +115 -0
- package/skills/clawclaw/references/CHATTERBOX.md +3 -2
- package/skills/clawclaw/references/COMMANDS.md +108 -58
- package/skills/clawclaw/references/GAME-MECHANICS.md +4 -3
- package/skills/clawclaw/references/HUB.md +27 -23
- package/skills/clawclaw/references/STREAM.md +18 -14
- package/skills/clawclaw/references/TACTICS.md +2 -2
- package/src/behaviors/official-finite/do-task.ts +141 -0
- package/src/behaviors/official-finite/evade.ts +78 -0
- package/src/behaviors/official-finite/find-player.ts +50 -0
- package/src/behaviors/official-finite/follow-player.ts +70 -0
- package/src/behaviors/official-finite/go-to.ts +69 -0
- package/src/behaviors/official-finite/hide-temporarily.ts +77 -0
- package/src/behaviors/official-finite/hold-position.ts +48 -0
- package/src/behaviors/official-finite/hunt-player.ts +47 -0
- package/src/behaviors/official-finite/index.test.ts +202 -0
- package/src/behaviors/official-finite/index.ts +47 -0
- package/src/behaviors/official-finite/inspect-corpse.ts +64 -0
- package/src/behaviors/official-finite/patrol-area.ts +80 -0
- package/src/behaviors/official-finite/report-corpse.ts +73 -0
- package/src/behaviors/official-finite/seek-kill-opportunity.ts +152 -0
- package/src/behaviors/official-finite/shared.ts +27 -0
- package/src/behaviors/official-finite/trigger-alarm.ts +53 -0
- package/src/channel/claude-channel-ipc-server.ts +295 -0
- package/src/channel/claude-channel-ipc.ts +152 -0
- package/src/channel/claude-channel-server.test.ts +202 -0
- package/src/channel/claude-channel-server.ts +221 -0
- package/src/cli.ts +4 -2
- package/src/commands/account.test.ts +17 -17
- package/src/commands/behavior.test.ts +158 -0
- package/src/commands/behavior.ts +443 -0
- package/src/commands/communication.test.ts +12 -0
- package/src/commands/communication.ts +6 -3
- package/src/commands/data.test.ts +1 -1
- package/src/commands/data.ts +1 -1
- package/src/commands/events-canonical-state.test.ts +221 -2
- package/src/commands/events.ts +205 -12
- package/src/commands/game/index.test.ts +172 -3
- package/src/commands/game/index.ts +69 -32
- package/src/commands/hub.test.ts +25 -14
- package/src/commands/hub.ts +15 -19
- package/src/commands/load.test.ts +228 -6
- package/src/commands/load.ts +102 -18
- package/src/commands/memory.ts +1 -1
- package/src/commands/peek.ts +1 -1
- package/src/commands/perception.test.ts +30 -1
- package/src/commands/perception.ts +15 -17
- package/src/commands/trigger.test.ts +140 -0
- package/src/commands/trigger.ts +314 -0
- package/src/lib/account-guidance.test.ts +4 -0
- package/src/lib/account-guidance.ts +1 -1
- package/src/lib/behavior-export.test.ts +282 -0
- package/src/lib/behavior-export.ts +514 -0
- package/src/lib/game-client.test.ts +4 -17
- package/src/lib/game-client.ts +3 -0
- package/src/lib/gameplay-config.test.ts +258 -37
- package/src/lib/gameplay-config.ts +175 -35
- package/src/lib/hub-install.test.ts +19 -41
- package/src/lib/hub-install.ts +10 -38
- package/src/lib/hub-reminder.ts +7 -9
- package/src/lib/init-command.ts +1 -1
- package/src/lib/official-resource-sync.test.ts +199 -0
- package/src/lib/official-resource-sync.ts +221 -0
- package/src/lib/perception-config.test.ts +9 -4
- package/src/lib/perception-config.ts +10 -13
- package/src/lib/perception-export.test.ts +145 -0
- package/src/lib/perception-export.ts +178 -0
- package/src/lib/trigger-config.test.ts +102 -0
- package/src/lib/trigger-config.ts +217 -0
- package/src/lib/user-data.test.ts +23 -6
- package/src/lib/user-data.ts +15 -123
- package/src/pipeline/canonical-event-presentation.test.ts +5 -5
- package/src/pipeline/canonical-event-presentation.ts +13 -5
- package/src/pipeline/event-format.test.ts +106 -3
- package/src/pipeline/event-format.ts +172 -4
- package/src/pipeline/event-hints.test.ts +57 -4
- package/src/pipeline/event-hints.ts +34 -8
- package/src/runtime/canonical-monitor.test.ts +2 -0
- package/src/runtime/canonical-monitor.ts +6 -2
- package/src/runtime/clawclaw/agent-event-policy.test.ts +23 -2
- package/src/runtime/clawclaw/agent-event-policy.ts +12 -5
- package/src/runtime/clawclaw/behavior-decision.test.ts +29 -0
- package/src/runtime/clawclaw/behavior-decision.ts +82 -0
- package/src/runtime/clawclaw/behavior-input-fields.test.ts +175 -0
- package/src/runtime/clawclaw/behavior-input-fields.ts +270 -0
- package/src/runtime/clawclaw/behavior-input.test.ts +151 -0
- package/src/runtime/clawclaw/behavior-input.ts +70 -0
- package/src/runtime/clawclaw/behavior-observation-memory.test.ts +59 -0
- package/src/runtime/clawclaw/behavior-observation-memory.ts +142 -0
- package/src/runtime/clawclaw/behavior-read-api.test.ts +123 -0
- package/src/runtime/clawclaw/behavior-read-api.ts +158 -0
- package/src/runtime/clawclaw/{plugins/perception/visual-state-projector.ts → observation-frame-projector.ts} +44 -25
- package/src/runtime/clawclaw/owner.test.ts +187 -0
- package/src/runtime/clawclaw/owner.ts +431 -69
- package/src/runtime/clawclaw/plugins/action/action-plugin.test.ts +304 -0
- package/src/runtime/clawclaw/plugins/action/action-plugin.ts +286 -41
- package/src/runtime/clawclaw/plugins/action/automated-action-normalization.ts +82 -0
- package/src/runtime/clawclaw/plugins/assembly.test.ts +135 -29
- package/src/runtime/clawclaw/plugins/assembly.ts +54 -28
- package/src/runtime/clawclaw/plugins/behavior/activation-manager.test.ts +180 -0
- package/src/runtime/clawclaw/plugins/behavior/activation-manager.ts +468 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-action.test.ts +40 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-action.ts +30 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-analysis-thread-host.ts +152 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-catalog.test.ts +156 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-catalog.ts +104 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-manifest.ts +173 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-module-loader.test.ts +182 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-module-loader.ts +223 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-normalization.ts +157 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.test.ts +848 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.ts +1347 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-runner.ts +212 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-source.test.ts +174 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-source.ts +621 -0
- package/src/runtime/clawclaw/plugins/behavior/control-driver.test.ts +195 -0
- package/src/runtime/clawclaw/plugins/behavior/control-driver.ts +180 -0
- package/src/runtime/clawclaw/plugins/behavior/index.ts +11 -0
- package/src/runtime/clawclaw/plugins/behavior/official-goal-behavior.ts +766 -0
- package/src/runtime/clawclaw/plugins/behavior/thread-behavior-executor.test.ts +283 -0
- package/src/runtime/clawclaw/plugins/{strategy/thread-strategy-executor.ts → behavior/thread-behavior-executor.ts} +109 -121
- package/src/runtime/clawclaw/plugins/behavior-input-source.test.ts +80 -0
- package/src/runtime/clawclaw/plugins/behavior-input-source.ts +247 -0
- package/src/runtime/clawclaw/plugins/{strategy → game-query}/context-capabilities.ts +1 -1
- package/src/runtime/clawclaw/plugins/game-query/game-query-plugin.test.ts +13 -10
- package/src/runtime/clawclaw/plugins/game-query/game-query-plugin.ts +26 -14
- package/src/runtime/clawclaw/plugins/game-query/index.ts +1 -0
- package/src/runtime/clawclaw/plugins/index.ts +3 -1
- package/src/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-adapter.test.ts +239 -0
- package/src/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-adapter.ts +100 -0
- package/src/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-socket.ts +346 -0
- package/src/runtime/clawclaw/plugins/mailbox/agent-mailbox-coordinator.test.ts +230 -12
- package/src/runtime/clawclaw/plugins/mailbox/agent-mailbox-coordinator.ts +118 -90
- package/src/runtime/clawclaw/plugins/mailbox/consumer-ids.ts +5 -0
- package/src/runtime/clawclaw/plugins/mailbox/index.ts +3 -0
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-agent-event-batch.test.ts +1 -1
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-event-batch-delivery.ts +4 -0
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-plugin.test.ts +87 -0
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-plugin.ts +70 -12
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-presentation.ts +94 -11
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.test.ts +1229 -345
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.ts +479 -35
- package/src/runtime/clawclaw/plugins/perception/contracts.ts +4 -3
- package/src/runtime/clawclaw/plugins/perception/index.ts +1 -1
- package/src/runtime/clawclaw/plugins/perception/module-runner.test.ts +23 -13
- package/src/runtime/clawclaw/plugins/perception/module-runner.ts +11 -9
- package/src/runtime/clawclaw/plugins/perception/modules/co-movement-module.ts +39 -38
- package/src/runtime/clawclaw/plugins/perception/modules/corpse-visibility-module.test.ts +92 -0
- package/src/runtime/clawclaw/plugins/perception/modules/corpse-visibility-module.ts +248 -0
- package/src/runtime/clawclaw/plugins/perception/modules/follow-module.ts +39 -37
- package/src/runtime/clawclaw/plugins/perception/modules/index.ts +1 -0
- package/src/runtime/clawclaw/plugins/perception/modules/motion-module.test.ts +22 -21
- package/src/runtime/clawclaw/plugins/perception/modules/motion-module.ts +15 -9
- package/src/runtime/clawclaw/plugins/perception/modules/parallel-module-test-helpers.ts +3 -3
- package/src/runtime/clawclaw/plugins/perception/modules/relation-stability.test.ts +33 -18
- package/src/runtime/clawclaw/plugins/perception/modules/route-module.test.ts +6 -7
- package/src/runtime/clawclaw/plugins/perception/modules/route-module.ts +22 -16
- package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.test.ts +6 -7
- package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.ts +18 -12
- package/src/runtime/clawclaw/plugins/perception/modules/stop-module.test.ts +14 -10
- package/src/runtime/clawclaw/plugins/perception/modules/stop-module.ts +20 -14
- package/src/runtime/clawclaw/plugins/perception/modules/temporal-evidence.test.ts +5 -6
- package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.test.ts +5 -6
- package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.ts +49 -34
- package/src/runtime/clawclaw/plugins/perception/official-module-ids.ts +1 -0
- package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-pool.test.ts +126 -20
- package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-pool.ts +24 -3
- package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-worker.ts +59 -46
- package/src/runtime/clawclaw/plugins/perception/perception-module-loader.ts +27 -5
- package/src/runtime/clawclaw/plugins/perception/perception-plugin.test.ts +381 -49
- package/src/runtime/clawclaw/plugins/perception/perception-plugin.ts +267 -245
- package/src/runtime/clawclaw/plugins/perception/perception-source.test.ts +98 -0
- package/src/runtime/clawclaw/plugins/perception/perception-source.ts +89 -16
- package/src/runtime/clawclaw/plugins/perception/perception-test-fixtures.ts +34 -0
- package/src/runtime/clawclaw/plugins/perception/replay.test.ts +27 -15
- package/src/runtime/clawclaw/plugins/perception/replay.ts +10 -5
- package/src/runtime/clawclaw/plugins/perception/shared/math.ts +1 -107
- package/src/runtime/clawclaw/plugins/perception/spatial-facts.ts +7 -10
- package/src/runtime/clawclaw/plugins/plugin-api-version.ts +112 -0
- package/src/runtime/clawclaw/plugins/runtime-plugins.test.ts +389 -559
- package/src/runtime/clawclaw/plugins/source/player-change-tracker.test.ts +56 -5
- package/src/runtime/clawclaw/plugins/source/player-change-tracker.ts +135 -26
- package/src/runtime/clawclaw/plugins/source/source-plugin.test.ts +249 -16
- package/src/runtime/clawclaw/plugins/source/source-plugin.ts +99 -2
- package/src/runtime/clawclaw/plugins/source/task-change-tracker.test.ts +212 -0
- package/src/runtime/clawclaw/plugins/source/task-change-tracker.ts +259 -0
- package/src/runtime/clawclaw/plugins/trigger/contracts.ts +97 -0
- package/src/runtime/clawclaw/plugins/trigger/index.ts +4 -0
- package/src/runtime/clawclaw/plugins/trigger/trigger-module-loader.ts +118 -0
- package/src/runtime/clawclaw/plugins/trigger/trigger-plugin.test.ts +548 -0
- package/src/runtime/clawclaw/plugins/trigger/trigger-plugin.ts +655 -0
- package/src/runtime/clawclaw/plugins/trigger/trigger-source.test.ts +169 -0
- package/src/runtime/clawclaw/plugins/trigger/trigger-source.ts +457 -0
- package/src/runtime/clawclaw/runtime.ts +8 -0
- package/src/runtime/clawclaw/spatial-api.ts +76 -0
- package/src/runtime/clawclaw-event-catalog.test.ts +46 -1
- package/src/runtime/clawclaw-event-catalog.ts +40 -3
- package/src/runtime/framework/capability-registry.test.ts +196 -55
- package/src/runtime/framework/capability-registry.ts +99 -17
- package/src/runtime/framework/contracts.ts +30 -4
- package/src/runtime/framework/control/control-scheduler.ts +13 -5
- package/src/runtime/framework/control/types.ts +11 -4
- package/src/runtime/framework/control-coordinator.test.ts +95 -80
- package/src/runtime/framework/events/event-delivery-service.ts +4 -2
- package/src/runtime/framework/events/event-ingress.test.ts +25 -0
- package/src/runtime/framework/events/event-ingress.ts +2 -1
- package/src/runtime/framework/events/event-repository.ts +24 -2
- package/src/runtime/framework/events/mailbox-event-repositories.test.ts +124 -8
- package/src/runtime/framework/events/memory-event-repository.ts +92 -28
- package/src/runtime/framework/events/sqlite-event-repository.test.ts +604 -2
- package/src/runtime/framework/events/sqlite-event-repository.ts +531 -21
- package/src/runtime/framework/events/types.ts +24 -8
- package/src/runtime/framework/modules/runtime-module-loader-hooks.mjs +38 -1
- package/src/runtime/framework/modules/runtime-module-loader.test.ts +233 -7
- package/src/runtime/framework/modules/runtime-module-loader.ts +69 -4
- package/src/runtime/framework/plugins/contracts.ts +12 -18
- package/src/runtime/framework/plugins/runtime-plugin-scheduler.test.ts +81 -71
- package/src/runtime/framework/plugins/runtime-plugin-scheduler.ts +38 -20
- package/src/runtime/framework/runtime.ts +20 -23
- package/src/runtime/host-monitor-rate-gate.test.ts +73 -0
- package/src/runtime/host-monitor-rate-gate.ts +123 -0
- package/src/runtime/mailbox-host-relay.test.ts +45 -0
- package/src/runtime/mailbox-host-relay.ts +25 -0
- package/src/runtime/observability/factory.ts +4 -4
- package/src/runtime/observability/observability.test.ts +25 -3
- package/src/runtime/observability/reporter.ts +1 -1
- package/src/runtime/observability/types.ts +2 -2
- package/src/runtime/owner-control.ts +10 -2
- package/src/runtime/runtime-logger.test.ts +1 -1
- package/src/runtime/runtime-logger.ts +4 -6
- package/src/runtime/runtime.test.ts +88 -22
- package/src/sdk/action.ts +2 -2
- package/src/sdk/behavior-plugin/index.test.ts +74 -0
- package/src/sdk/behavior-plugin/index.ts +335 -0
- package/src/sdk/behavior-toolkit/corpse-search.ts +87 -0
- package/src/sdk/behavior-toolkit/escape.ts +40 -0
- package/src/sdk/behavior-toolkit/index.ts +7 -0
- package/src/sdk/behavior-toolkit/kill-flow.ts +299 -0
- package/src/sdk/behavior-toolkit/model.ts +263 -0
- package/src/sdk/behavior-toolkit/move-gate.ts +52 -0
- package/src/sdk/behavior-toolkit/patrol.ts +53 -0
- package/src/sdk/behavior-toolkit/search.ts +102 -0
- package/src/sdk/index.test.ts +45 -0
- package/src/sdk/index.ts +67 -73
- package/src/sdk/module-input/index.test.ts +49 -0
- package/src/sdk/module-input/index.ts +229 -0
- package/src/sdk/perception-plugin/index.test.ts +2 -2
- package/src/sdk/perception-plugin/index.ts +51 -142
- package/src/sdk/perception-plugin/math.ts +107 -0
- package/src/sdk/trigger-plugin/index.test.ts +41 -0
- package/src/sdk/trigger-plugin/index.ts +128 -0
- package/src/strategies/avoid-lone.ts +21 -10
- package/src/strategies/avoid-players.ts +26 -16
- package/src/strategies/corpse-patrol.ts +25 -14
- package/src/strategies/crab-sabotage.ts +20 -9
- package/src/strategies/find-player.ts +33 -21
- package/src/strategies/game-utils.ts +1 -1
- package/src/strategies/goals/crab-sabotage-top.test.ts +145 -0
- package/src/strategies/goals/crab-sabotage-top.ts +32 -69
- package/src/strategies/hide.ts +25 -15
- package/src/strategies/kill-frenzy.ts +21 -10
- package/src/strategies/kill-lone.ts +27 -17
- package/src/strategies/kill-target.ts +33 -22
- package/src/strategies/lone-kill-task.ts +20 -9
- package/src/strategies/move-room.ts +29 -18
- package/src/strategies/official-long-behavior.test.ts +89 -0
- package/src/strategies/paradise-fish.ts +29 -18
- package/src/strategies/pathfind/astar-path.test.ts +127 -2
- package/src/strategies/pathfind/astar-path.ts +136 -26
- package/src/strategies/patrol.ts +21 -10
- package/src/strategies/player-targets.test.ts +10 -0
- package/src/strategies/player-targets.ts +13 -0
- package/src/strategies/report-patrol.ts +21 -10
- package/src/strategies/shrimp-memory.ts +30 -19
- package/src/strategies/social-task.ts +34 -23
- package/src/strategies/task-kill-report.ts +33 -22
- package/src/strategies/task-only.test.ts +99 -85
- package/src/strategies/task-only.ts +23 -12
- package/src/strategies/task-report.ts +25 -14
- package/src/strategies/types.ts +8 -8
- package/src/strategies/warrior-memory.ts +29 -19
- package/docs/runtime/strategy-runtime.md +0 -111
- package/docs//350/207/252/345/256/232/344/271/211/346/204/237/347/237/245.md +0 -502
- package/docs//350/207/252/345/256/232/344/271/211/347/255/226/347/225/245.md +0 -395
- package/skills/clawclaw/references/STRATEGIES.md +0 -76
- package/src/commands/strategy.test.ts +0 -209
- package/src/commands/strategy.ts +0 -242
- package/src/lib/strategy-export.test.ts +0 -406
- package/src/lib/strategy-export.ts +0 -381
- package/src/runtime/clawclaw/plugins/perception/official-modules.ts +0 -31
- package/src/runtime/clawclaw/plugins/strategy/examples/task-only-strategy.test.ts +0 -177
- package/src/runtime/clawclaw/plugins/strategy/examples/task-only-strategy.ts +0 -191
- package/src/runtime/clawclaw/plugins/strategy/index.ts +0 -8
- package/src/runtime/clawclaw/plugins/strategy/local-strategy-executor.ts +0 -412
- package/src/runtime/clawclaw/plugins/strategy/strategy-action.ts +0 -80
- package/src/runtime/clawclaw/plugins/strategy/strategy-analysis-thread-host.ts +0 -183
- package/src/runtime/clawclaw/plugins/strategy/strategy-executor-types.ts +0 -29
- package/src/runtime/clawclaw/plugins/strategy/strategy-executor.test.ts +0 -693
- package/src/runtime/clawclaw/plugins/strategy/strategy-game-api.ts +0 -57
- package/src/runtime/clawclaw/plugins/strategy/strategy-module-loader.ts +0 -168
- package/src/runtime/clawclaw/plugins/strategy/strategy-plugin.test.ts +0 -1994
- package/src/runtime/clawclaw/plugins/strategy/strategy-plugin.ts +0 -1579
- package/src/runtime/clawclaw/plugins/strategy/strategy-source.test.ts +0 -153
- package/src/runtime/clawclaw/plugins/strategy/strategy-source.ts +0 -443
- package/src/sdk/strategy-plugin/index.test.ts +0 -958
- package/src/sdk/strategy-plugin/index.ts +0 -1350
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { describe, expect, it, vi } from 'vitest';
|
|
2
2
|
import { Runtime } from '../../framework/runtime.js';
|
|
3
3
|
import { createClawclawEventCatalog } from '../../clawclaw-event-catalog.js';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
behaviorControllerSpec,
|
|
6
|
+
type BehaviorActionCaller,
|
|
7
|
+
} from '../../framework/capability-registry.js';
|
|
5
8
|
import {
|
|
6
9
|
CLAWCLAW_ACTION_CAPABILITY,
|
|
7
10
|
CLAWCLAW_AGENT_CONTROL_LEASE_MS,
|
|
@@ -11,11 +14,6 @@ import {
|
|
|
11
14
|
import { ApiError } from '../../../lib/http-transport.js';
|
|
12
15
|
import { jsonTransportResponse } from '../../../short-command/transport-response.js';
|
|
13
16
|
import { ClawclawMailboxPlugin } from './mailbox/index.js';
|
|
14
|
-
import { ClawclawGameQueryPlugin } from './game-query/index.js';
|
|
15
|
-
import {
|
|
16
|
-
ClawclawStrategyPlugin,
|
|
17
|
-
type ClawclawStrategyExecutor,
|
|
18
|
-
} from './strategy/index.js';
|
|
19
17
|
|
|
20
18
|
function deferred<T>() {
|
|
21
19
|
let resolve!: (value: T | PromiseLike<T>) => void;
|
|
@@ -79,10 +77,66 @@ async function fixture() {
|
|
|
79
77
|
runtimeEpochPlugins: [action],
|
|
80
78
|
});
|
|
81
79
|
await runtime.start();
|
|
82
|
-
action.update({ epoch: { state: wanderingRuntimeState() } } as any);
|
|
80
|
+
action.update({ epoch: { scope: runtime.scope(), state: wanderingRuntimeState() } } as any);
|
|
83
81
|
return { runtime, client, action };
|
|
84
82
|
}
|
|
85
83
|
|
|
84
|
+
async function acceptRuntimeState(
|
|
85
|
+
runtime: Runtime,
|
|
86
|
+
sourceKey: string,
|
|
87
|
+
state: Record<string, any>,
|
|
88
|
+
): Promise<void> {
|
|
89
|
+
await runtime.acceptInputBatch({
|
|
90
|
+
scope: runtime.scope(),
|
|
91
|
+
sourceId: 'test.source',
|
|
92
|
+
connectionId: 'connection-1',
|
|
93
|
+
sourceKey,
|
|
94
|
+
state,
|
|
95
|
+
events: [],
|
|
96
|
+
completeness: 'complete',
|
|
97
|
+
receivedAt: new Date().toISOString(),
|
|
98
|
+
});
|
|
99
|
+
await runtime.flush();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function wanderingStateWithPlayers(players: readonly Record<string, any>[]) {
|
|
103
|
+
return {
|
|
104
|
+
...wanderingRuntimeState(),
|
|
105
|
+
game_snapshot: {
|
|
106
|
+
status: 'fresh' as const,
|
|
107
|
+
state: { phase: 'wandering', players: structuredClone(players) },
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function behaviorCaller(
|
|
113
|
+
activationId: string,
|
|
114
|
+
layer: BehaviorActionCaller['layer'] = 'long',
|
|
115
|
+
): BehaviorActionCaller {
|
|
116
|
+
return { kind: 'behavior', activationId, layer, activationGeneration: 1 };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function registerBehaviorController(
|
|
120
|
+
runtime: Runtime,
|
|
121
|
+
caller: BehaviorActionCaller,
|
|
122
|
+
domains: string[] = ['physical'],
|
|
123
|
+
): void {
|
|
124
|
+
runtime.actions.controls.registerController(behaviorControllerSpec(caller, {
|
|
125
|
+
scope: runtime.scope(),
|
|
126
|
+
domains,
|
|
127
|
+
lifecycle: 'persistent',
|
|
128
|
+
ready: true,
|
|
129
|
+
}));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function behaviorPrecondition(epochSeq = 1) {
|
|
133
|
+
return {
|
|
134
|
+
behaviorOriginEpochSeq: epochSeq,
|
|
135
|
+
behaviorActionSafetyGeneration: 0,
|
|
136
|
+
behaviorActivationGeneration: 1,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
86
140
|
describe('ClawClaw runtime capabilities', () => {
|
|
87
141
|
it.each([
|
|
88
142
|
['move', ['physical']],
|
|
@@ -93,6 +147,7 @@ describe('ClawClaw runtime capabilities', () => {
|
|
|
93
147
|
['speech', ['communication']],
|
|
94
148
|
['vote', ['meeting_vote']],
|
|
95
149
|
['think', []],
|
|
150
|
+
['strategy', []],
|
|
96
151
|
['future_action', ['*']],
|
|
97
152
|
])('maps %s onto generic control domains', (action, domains) => {
|
|
98
153
|
expect(describeClawclawActionControl({ action: { action } })).toEqual({
|
|
@@ -112,6 +167,10 @@ describe('ClawClaw runtime capabilities', () => {
|
|
|
112
167
|
}).domains).toEqual(['communication']);
|
|
113
168
|
});
|
|
114
169
|
|
|
170
|
+
it('does not let the physical Agent lease outlast the minimum fallback idle timeout', () => {
|
|
171
|
+
expect(CLAWCLAW_AGENT_CONTROL_LEASE_MS).toBeLessThanOrEqual(1_000);
|
|
172
|
+
});
|
|
173
|
+
|
|
115
174
|
it('conservatively claims all control for a missing action name', () => {
|
|
116
175
|
expect(describeClawclawActionControl({ action: {} }).domains).toEqual(['*']);
|
|
117
176
|
});
|
|
@@ -120,7 +179,7 @@ describe('ClawClaw runtime capabilities', () => {
|
|
|
120
179
|
const { runtime, client } = await fixture();
|
|
121
180
|
await expect(runtime.performAction(CLAWCLAW_ACTION_CAPABILITY, {
|
|
122
181
|
action: { action: 'move', target_x: 1, target_y: 2 },
|
|
123
|
-
}, { sessionId: 'old', segmentId: 'old' }, { kind: '
|
|
182
|
+
}, { sessionId: 'old', segmentId: 'old' }, { kind: 'agent', id: 'a1' }))
|
|
124
183
|
.rejects.toThrow('runtime_scope_changed');
|
|
125
184
|
expect(client.submitPreparedActionConfirmed).not.toHaveBeenCalled();
|
|
126
185
|
});
|
|
@@ -142,6 +201,7 @@ describe('ClawClaw runtime capabilities', () => {
|
|
|
142
201
|
const { runtime, client, action } = await fixture();
|
|
143
202
|
action.update({
|
|
144
203
|
epoch: {
|
|
204
|
+
scope: runtime.scope(),
|
|
145
205
|
state: { ...wanderingRuntimeState(), connection: 'reconnecting' },
|
|
146
206
|
},
|
|
147
207
|
} as any);
|
|
@@ -170,7 +230,318 @@ describe('ClawClaw runtime capabilities', () => {
|
|
|
170
230
|
await runtime.close();
|
|
171
231
|
});
|
|
172
232
|
|
|
173
|
-
it(
|
|
233
|
+
it.each([
|
|
234
|
+
['Agent', { kind: 'agent' as const, id: 'direct-agent' }],
|
|
235
|
+
['User', { kind: 'user' as const, id: 'direct-user' }],
|
|
236
|
+
])('keeps a direct %s caller pending until the HTTP acknowledgement settles', async (
|
|
237
|
+
_label,
|
|
238
|
+
caller,
|
|
239
|
+
) => {
|
|
240
|
+
const { runtime, client } = await fixture();
|
|
241
|
+
const acknowledgement = deferred<ReturnType<typeof jsonTransportResponse>>();
|
|
242
|
+
client.submitPreparedActionConfirmed.mockReturnValueOnce(acknowledgement.promise);
|
|
243
|
+
let resolved = false;
|
|
244
|
+
|
|
245
|
+
const pending = runtime.performAction(CLAWCLAW_ACTION_CAPABILITY, {
|
|
246
|
+
action: { action: 'move', target_x: 1, target_y: 2 },
|
|
247
|
+
}, runtime.publicScope(), caller).then((result) => {
|
|
248
|
+
resolved = true;
|
|
249
|
+
return result;
|
|
250
|
+
});
|
|
251
|
+
await vi.waitFor(() => expect(client.submitPreparedActionConfirmed).toHaveBeenCalledOnce());
|
|
252
|
+
expect(resolved).toBe(false);
|
|
253
|
+
|
|
254
|
+
acknowledgement.resolve(jsonTransportResponse({
|
|
255
|
+
success: true,
|
|
256
|
+
data: { status: 'queued', duration_secs: 1 },
|
|
257
|
+
}, { method: 'POST', path: '/api/v1/game/action' }));
|
|
258
|
+
await expect(pending).resolves.toMatchObject({
|
|
259
|
+
status: 'success',
|
|
260
|
+
source: 'backend',
|
|
261
|
+
actionOutcome: 'confirmed',
|
|
262
|
+
});
|
|
263
|
+
await runtime.close();
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
it('records ActionPlugin queue and final settlement diagnostics for detached automation', async () => {
|
|
267
|
+
const acknowledgement = deferred<ReturnType<typeof jsonTransportResponse>>();
|
|
268
|
+
const client = {
|
|
269
|
+
submitPreparedActionConfirmed: vi.fn().mockReturnValue(acknowledgement.promise),
|
|
270
|
+
prepareActionForConfirmedSubmission: vi.fn(async (action) => action),
|
|
271
|
+
chatRoomConfirmed: vi.fn(),
|
|
272
|
+
uploadAudio: vi.fn(),
|
|
273
|
+
} as any;
|
|
274
|
+
const diagnostics = vi.fn();
|
|
275
|
+
let service: any;
|
|
276
|
+
const action = new ClawclawActionPlugin(client);
|
|
277
|
+
action.start({
|
|
278
|
+
currentSegment: () => ({ kind: 'game' }),
|
|
279
|
+
diagnostic: diagnostics,
|
|
280
|
+
capabilities: {
|
|
281
|
+
provideAction: (registered: any) => {
|
|
282
|
+
service = registered;
|
|
283
|
+
return () => {};
|
|
284
|
+
},
|
|
285
|
+
},
|
|
286
|
+
} as any);
|
|
287
|
+
const state = wanderingRuntimeState();
|
|
288
|
+
const runtimeScope = {
|
|
289
|
+
adapterId: 'clawclaw',
|
|
290
|
+
accountId: 'acct-detached',
|
|
291
|
+
sessionId: 'session-detached',
|
|
292
|
+
segmentId: 'segment-detached',
|
|
293
|
+
};
|
|
294
|
+
action.update({ epoch: { scope: runtimeScope, state } } as any);
|
|
295
|
+
|
|
296
|
+
const dispatched = service.perform({
|
|
297
|
+
action: { action: 'move', target_x: 1, target_y: 2 },
|
|
298
|
+
behaviorOriginEpochSeq: 1,
|
|
299
|
+
behaviorActionSafetyGeneration: 0,
|
|
300
|
+
behaviorActivationGeneration: 1,
|
|
301
|
+
}, runtimeScope, {
|
|
302
|
+
kind: 'behavior', activationId: 'diagnostic-behavior', layer: 'long', activationGeneration: 1,
|
|
303
|
+
}, {
|
|
304
|
+
signal: new AbortController().signal,
|
|
305
|
+
revalidate: () => ({ status: 'authorized' }),
|
|
306
|
+
latestAcceptedState: () => ({ epochSeq: 1, state }),
|
|
307
|
+
});
|
|
308
|
+
expect(dispatched.receipt).toMatchObject({
|
|
309
|
+
status: 'success', source: 'local', actionOutcome: 'unknown',
|
|
310
|
+
});
|
|
311
|
+
expect(diagnostics).toHaveBeenCalledWith(
|
|
312
|
+
'runtime.action.provider_queued',
|
|
313
|
+
expect.objectContaining({ caller_kind: 'behavior', action_kind: 'move' }),
|
|
314
|
+
'debug',
|
|
315
|
+
);
|
|
316
|
+
|
|
317
|
+
acknowledgement.resolve(jsonTransportResponse({ success: true }, {
|
|
318
|
+
method: 'POST', path: '/api/v1/game/action',
|
|
319
|
+
}));
|
|
320
|
+
await expect(dispatched.settled).resolves.toMatchObject({
|
|
321
|
+
status: 'success', source: 'backend', actionOutcome: 'confirmed',
|
|
322
|
+
});
|
|
323
|
+
expect(diagnostics).toHaveBeenCalledWith(
|
|
324
|
+
'runtime.action.provider_settled',
|
|
325
|
+
expect.objectContaining({
|
|
326
|
+
caller_kind: 'behavior',
|
|
327
|
+
action_kind: 'move',
|
|
328
|
+
status: 'success',
|
|
329
|
+
action_outcome: 'confirmed',
|
|
330
|
+
}),
|
|
331
|
+
'debug',
|
|
332
|
+
);
|
|
333
|
+
action.stop();
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
it.each([
|
|
337
|
+
['manual Agent', { kind: 'agent' as const, id: 'manual-1' }],
|
|
338
|
+
['Behavior', behaviorCaller('seat-target-behavior')],
|
|
339
|
+
])('submits authoritative target seats without names for %s Actions', async (_label, caller) => {
|
|
340
|
+
const { runtime, client } = await fixture();
|
|
341
|
+
await acceptRuntimeState(runtime, 'authoritative-roster', wanderingStateWithPlayers([
|
|
342
|
+
{ name: 'same-name', seat: 1 },
|
|
343
|
+
{ name: 'same-name', seat: 2 },
|
|
344
|
+
]));
|
|
345
|
+
// Names and later event-only frames are irrelevant to seat-based targeting.
|
|
346
|
+
await acceptRuntimeState(runtime, 'event-only-after-roster', eventOnlyRuntimeState());
|
|
347
|
+
|
|
348
|
+
if (caller.kind === 'behavior') registerBehaviorController(runtime, caller);
|
|
349
|
+
const request = {
|
|
350
|
+
action: { action: 'kill', target_seat: 2 },
|
|
351
|
+
...(caller.kind === 'behavior' ? behaviorPrecondition() : {}),
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
const result = await runtime.performAction(
|
|
355
|
+
CLAWCLAW_ACTION_CAPABILITY,
|
|
356
|
+
request,
|
|
357
|
+
runtime.publicScope(),
|
|
358
|
+
caller,
|
|
359
|
+
);
|
|
360
|
+
expect(result).toMatchObject(caller.kind === 'agent' ? {
|
|
361
|
+
status: 'success',
|
|
362
|
+
source: 'backend',
|
|
363
|
+
actionOutcome: 'confirmed',
|
|
364
|
+
} : {
|
|
365
|
+
status: 'success',
|
|
366
|
+
source: 'local',
|
|
367
|
+
actionOutcome: 'unknown',
|
|
368
|
+
});
|
|
369
|
+
await runtime.actions.waitForIdle();
|
|
370
|
+
expect(client.prepareActionForConfirmedSubmission).toHaveBeenCalledWith({
|
|
371
|
+
action: 'kill',
|
|
372
|
+
target_seat: 2,
|
|
373
|
+
});
|
|
374
|
+
expect(client.submitPreparedActionConfirmed).toHaveBeenCalledWith({
|
|
375
|
+
action: 'kill',
|
|
376
|
+
target_seat: 2,
|
|
377
|
+
});
|
|
378
|
+
await runtime.close();
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
it('returns an ActionPlugin receipt before the HTTP acknowledgement for Behavior callers', async () => {
|
|
382
|
+
const { runtime, client } = await fixture();
|
|
383
|
+
await acceptRuntimeState(runtime, 'detached-origin', wanderingRuntimeState());
|
|
384
|
+
const acknowledgement = deferred<ReturnType<typeof jsonTransportResponse>>();
|
|
385
|
+
client.submitPreparedActionConfirmed.mockReturnValueOnce(acknowledgement.promise);
|
|
386
|
+
const caller = behaviorCaller('detached-behavior');
|
|
387
|
+
registerBehaviorController(runtime, caller);
|
|
388
|
+
const request = {
|
|
389
|
+
action: { action: 'move', target_x: 1, target_y: 2 },
|
|
390
|
+
...behaviorPrecondition(),
|
|
391
|
+
};
|
|
392
|
+
|
|
393
|
+
await expect(runtime.performAction(
|
|
394
|
+
CLAWCLAW_ACTION_CAPABILITY,
|
|
395
|
+
request,
|
|
396
|
+
runtime.publicScope(),
|
|
397
|
+
caller,
|
|
398
|
+
)).resolves.toMatchObject({
|
|
399
|
+
status: 'success',
|
|
400
|
+
source: 'local',
|
|
401
|
+
actionOutcome: 'unknown',
|
|
402
|
+
value: { accepted: true, status: 'queued' },
|
|
403
|
+
});
|
|
404
|
+
await vi.waitFor(() => expect(client.submitPreparedActionConfirmed).toHaveBeenCalledOnce());
|
|
405
|
+
expect(runtime.actions.controls.snapshot().inFlight).toHaveLength(0);
|
|
406
|
+
|
|
407
|
+
acknowledgement.resolve(jsonTransportResponse({
|
|
408
|
+
success: true,
|
|
409
|
+
data: { status: 'queued', duration_secs: 1 },
|
|
410
|
+
}, { method: 'POST', path: '/api/v1/game/action' }));
|
|
411
|
+
await runtime.actions.waitForIdle();
|
|
412
|
+
expect(runtime.actions.controls.snapshot().inFlight).toHaveLength(0);
|
|
413
|
+
await runtime.close();
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
it('lets one Behavior submit an after-kill move while the kill HTTP settlement is pending', async () => {
|
|
417
|
+
const { runtime, client } = await fixture();
|
|
418
|
+
await acceptRuntimeState(runtime, 'after-kill-origin', wanderingStateWithPlayers([
|
|
419
|
+
{ name: 'self-player', seat: 1 },
|
|
420
|
+
{ name: 'target-player', seat: 2 },
|
|
421
|
+
]));
|
|
422
|
+
const caller = behaviorCaller('after-kill-behavior', 'short');
|
|
423
|
+
registerBehaviorController(runtime, caller);
|
|
424
|
+
const killAcknowledgement = deferred<ReturnType<typeof jsonTransportResponse>>();
|
|
425
|
+
client.submitPreparedActionConfirmed
|
|
426
|
+
.mockReturnValueOnce(killAcknowledgement.promise)
|
|
427
|
+
.mockResolvedValueOnce(jsonTransportResponse({ success: true }, {
|
|
428
|
+
method: 'POST', path: '/api/v1/game/action',
|
|
429
|
+
}));
|
|
430
|
+
const automationPrecondition = behaviorPrecondition();
|
|
431
|
+
|
|
432
|
+
await expect(runtime.performAction(CLAWCLAW_ACTION_CAPABILITY, {
|
|
433
|
+
action: { action: 'kill', target_seat: 2 },
|
|
434
|
+
...automationPrecondition,
|
|
435
|
+
}, runtime.publicScope(), caller)).resolves.toMatchObject({
|
|
436
|
+
status: 'success', source: 'local', actionOutcome: 'unknown',
|
|
437
|
+
});
|
|
438
|
+
await vi.waitFor(() => expect(client.submitPreparedActionConfirmed).toHaveBeenCalledTimes(1));
|
|
439
|
+
expect(runtime.actions.controls.snapshot().inFlight).toHaveLength(0);
|
|
440
|
+
|
|
441
|
+
await expect(runtime.performAction(CLAWCLAW_ACTION_CAPABILITY, {
|
|
442
|
+
action: { action: 'move', target_x: 500, target_y: 0 },
|
|
443
|
+
...automationPrecondition,
|
|
444
|
+
}, runtime.publicScope(), caller)).resolves.toMatchObject({
|
|
445
|
+
status: 'success', source: 'local', actionOutcome: 'unknown',
|
|
446
|
+
});
|
|
447
|
+
await vi.waitFor(() => expect(client.submitPreparedActionConfirmed).toHaveBeenCalledTimes(2));
|
|
448
|
+
expect(client.submitPreparedActionConfirmed.mock.calls[0]?.[0]).toMatchObject({
|
|
449
|
+
action: 'kill', target_seat: 2,
|
|
450
|
+
});
|
|
451
|
+
expect(client.submitPreparedActionConfirmed.mock.calls[1]?.[0]).toMatchObject({
|
|
452
|
+
action: 'move', target_x: 500, target_y: 0,
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
let drained = false;
|
|
456
|
+
const drain = runtime.actions.waitForIdle().then(() => { drained = true; });
|
|
457
|
+
await Promise.resolve();
|
|
458
|
+
expect(drained).toBe(false);
|
|
459
|
+
killAcknowledgement.resolve(jsonTransportResponse({ success: true }, {
|
|
460
|
+
method: 'POST', path: '/api/v1/game/action',
|
|
461
|
+
}));
|
|
462
|
+
await drain;
|
|
463
|
+
await runtime.close();
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
it.each([8, 0])('submits vote target_seat %s without a name target', async (seat) => {
|
|
467
|
+
const { runtime, client } = await fixture();
|
|
468
|
+
await acceptRuntimeState(runtime, 'vote-without-roster', wanderingRuntimeState());
|
|
469
|
+
|
|
470
|
+
await expect(runtime.performAction(CLAWCLAW_ACTION_CAPABILITY, {
|
|
471
|
+
action: { action: 'vote', target_seat: seat },
|
|
472
|
+
}, runtime.publicScope(), { kind: 'agent' })).resolves.toMatchObject({
|
|
473
|
+
status: 'success', source: 'backend', actionOutcome: 'confirmed',
|
|
474
|
+
});
|
|
475
|
+
expect(client.submitPreparedActionConfirmed).toHaveBeenCalledWith({
|
|
476
|
+
action: 'vote', target_seat: seat,
|
|
477
|
+
});
|
|
478
|
+
await runtime.close();
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
it.each([
|
|
482
|
+
['missing roster', wanderingRuntimeState()],
|
|
483
|
+
[
|
|
484
|
+
'missing seat',
|
|
485
|
+
wanderingStateWithPlayers([{ name: 'self-player', seat: 1 }]),
|
|
486
|
+
],
|
|
487
|
+
[
|
|
488
|
+
'duplicate seat',
|
|
489
|
+
wanderingStateWithPlayers([
|
|
490
|
+
{ name: 'target-a', seat: 2 },
|
|
491
|
+
{ name: 'target-b', seat: 2 },
|
|
492
|
+
]),
|
|
493
|
+
],
|
|
494
|
+
[
|
|
495
|
+
'duplicate player name',
|
|
496
|
+
wanderingStateWithPlayers([
|
|
497
|
+
{ name: 'same-name', seat: 2 },
|
|
498
|
+
{ name: 'same-name', seat: 3 },
|
|
499
|
+
]),
|
|
500
|
+
],
|
|
501
|
+
])('does not consult the %s when submitting a seat-based kill', async (_label, state) => {
|
|
502
|
+
const { runtime, client } = await fixture();
|
|
503
|
+
await acceptRuntimeState(runtime, `seat-only-${_label}`, state);
|
|
504
|
+
|
|
505
|
+
await expect(runtime.performAction(CLAWCLAW_ACTION_CAPABILITY, {
|
|
506
|
+
action: { action: 'kill', target_seat: 2 },
|
|
507
|
+
}, runtime.publicScope(), { kind: 'agent' })).resolves.toMatchObject({
|
|
508
|
+
status: 'success',
|
|
509
|
+
source: 'backend',
|
|
510
|
+
actionOutcome: 'confirmed',
|
|
511
|
+
});
|
|
512
|
+
expect(client.prepareActionForConfirmedSubmission).toHaveBeenCalledWith({
|
|
513
|
+
action: 'kill', target_seat: 2,
|
|
514
|
+
});
|
|
515
|
+
expect(client.submitPreparedActionConfirmed).toHaveBeenCalledWith({
|
|
516
|
+
action: 'kill', target_seat: 2,
|
|
517
|
+
});
|
|
518
|
+
await runtime.close();
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
it.each([
|
|
522
|
+
['kill name only', { action: 'kill', target: 'untrusted-name' }],
|
|
523
|
+
['kill string seat', { action: 'kill', target_seat: '2' }],
|
|
524
|
+
['kill seat zero', { action: 'kill', target_seat: 0 }],
|
|
525
|
+
['kill seat eleven', { action: 'kill', target_seat: 11 }],
|
|
526
|
+
['vote negative seat', { action: 'vote', target_seat: -1 }],
|
|
527
|
+
['vote seat eleven', { action: 'vote', target_seat: 11 }],
|
|
528
|
+
])('fails closed for an invalid %s target', async (_label, action) => {
|
|
529
|
+
const { runtime, client } = await fixture();
|
|
530
|
+
|
|
531
|
+
await expect(runtime.performAction(CLAWCLAW_ACTION_CAPABILITY, {
|
|
532
|
+
action,
|
|
533
|
+
}, runtime.publicScope(), { kind: 'agent' })).resolves.toMatchObject({
|
|
534
|
+
status: 'failure',
|
|
535
|
+
source: 'local',
|
|
536
|
+
actionOutcome: 'not_submitted',
|
|
537
|
+
error: { error: { code: 'INVALID_ACTION_TARGET_SEAT' } },
|
|
538
|
+
});
|
|
539
|
+
expect(client.prepareActionForConfirmedSubmission).not.toHaveBeenCalled();
|
|
540
|
+
expect(client.submitPreparedActionConfirmed).not.toHaveBeenCalled();
|
|
541
|
+
await runtime.close();
|
|
542
|
+
});
|
|
543
|
+
|
|
544
|
+
it('does not invalidate a Behavior Action for a newer event-only State', async () => {
|
|
174
545
|
const { runtime, client } = await fixture();
|
|
175
546
|
const accept = (sourceKey: string, state: Record<string, any>) => runtime.acceptInputBatch({
|
|
176
547
|
scope: runtime.scope(),
|
|
@@ -182,19 +553,21 @@ describe('ClawClaw runtime capabilities', () => {
|
|
|
182
553
|
completeness: 'complete',
|
|
183
554
|
receivedAt: new Date().toISOString(),
|
|
184
555
|
});
|
|
185
|
-
await accept('fresh-
|
|
556
|
+
await accept('fresh-behavior-origin', wanderingRuntimeState());
|
|
186
557
|
await accept('event-only-after-origin', eventOnlyRuntimeState());
|
|
187
558
|
await runtime.flush();
|
|
188
559
|
|
|
560
|
+
const caller = behaviorCaller('event-only-behavior');
|
|
561
|
+
registerBehaviorController(runtime, caller);
|
|
189
562
|
await expect(runtime.performAction(CLAWCLAW_ACTION_CAPABILITY, {
|
|
190
563
|
action: { action: 'move', target_x: 1, target_y: 2 },
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
}, runtime.publicScope(), { kind: 'strategy', id: 's1' })).resolves.toMatchObject({
|
|
564
|
+
...behaviorPrecondition(),
|
|
565
|
+
}, runtime.publicScope(), caller)).resolves.toMatchObject({
|
|
194
566
|
status: 'success',
|
|
195
|
-
source: '
|
|
196
|
-
actionOutcome: '
|
|
567
|
+
source: 'local',
|
|
568
|
+
actionOutcome: 'unknown',
|
|
197
569
|
});
|
|
570
|
+
await runtime.actions.waitForIdle();
|
|
198
571
|
expect(client.submitPreparedActionConfirmed).toHaveBeenCalledOnce();
|
|
199
572
|
await runtime.close();
|
|
200
573
|
});
|
|
@@ -289,7 +662,7 @@ describe('ClawClaw runtime capabilities', () => {
|
|
|
289
662
|
});
|
|
290
663
|
|
|
291
664
|
const result = await runtime.performAction(CLAWCLAW_ACTION_CAPABILITY, {
|
|
292
|
-
action: { action: '
|
|
665
|
+
action: { action: 'move', target_x: 1, target_y: 2 },
|
|
293
666
|
}, runtime.publicScope(), { kind: 'agent' });
|
|
294
667
|
|
|
295
668
|
expect(result).toMatchObject({
|
|
@@ -478,547 +851,4 @@ describe('ClawClaw runtime capabilities', () => {
|
|
|
478
851
|
await runtime.close();
|
|
479
852
|
});
|
|
480
853
|
|
|
481
|
-
it('keeps concrete strategy code behind an injected executor', async () => {
|
|
482
|
-
const calls: string[] = [];
|
|
483
|
-
const seenUpstream: unknown[] = [];
|
|
484
|
-
let alive = false;
|
|
485
|
-
const executor: ClawclawStrategyExecutor = {
|
|
486
|
-
runtimeInstanceId: 'test-worker',
|
|
487
|
-
get isAlive() { return alive; },
|
|
488
|
-
start: async () => {
|
|
489
|
-
alive = true;
|
|
490
|
-
calls.push('start');
|
|
491
|
-
},
|
|
492
|
-
reset: async () => { calls.push('reset'); },
|
|
493
|
-
update: async (frame) => {
|
|
494
|
-
calls.push(`update:${frame.epochId}`);
|
|
495
|
-
seenUpstream.push(frame.upstreamStates['perception.summary']);
|
|
496
|
-
return {
|
|
497
|
-
states: [{ topic: 'strategy.status', value: { epoch: frame.epochId } }],
|
|
498
|
-
};
|
|
499
|
-
},
|
|
500
|
-
stop: async (reason) => {
|
|
501
|
-
alive = false;
|
|
502
|
-
calls.push(`stop:${reason}`);
|
|
503
|
-
},
|
|
504
|
-
};
|
|
505
|
-
const strategy = new ClawclawStrategyPlugin({
|
|
506
|
-
after: ['test.perception'],
|
|
507
|
-
executorFactory: () => executor,
|
|
508
|
-
});
|
|
509
|
-
strategy.select({
|
|
510
|
-
id: 'test-strategy',
|
|
511
|
-
sourcePath: 'unused.ts',
|
|
512
|
-
sourceRoot: '.',
|
|
513
|
-
});
|
|
514
|
-
expect(strategy.catchUp).toBe('every_epoch');
|
|
515
|
-
const runtime = new Runtime({
|
|
516
|
-
adapterId: 'clawclaw',
|
|
517
|
-
accountId: 'acct-strategy-driver',
|
|
518
|
-
eventCatalog: createClawclawEventCatalog(),
|
|
519
|
-
runtimeEpochPlugins: [{
|
|
520
|
-
kind: 'epoch',
|
|
521
|
-
id: 'test.perception',
|
|
522
|
-
version: '1',
|
|
523
|
-
produces: { states: ['perception.summary'] },
|
|
524
|
-
update: () => ({
|
|
525
|
-
outcome: 'processed',
|
|
526
|
-
states: [{ topic: 'perception.summary', value: { visible: 2 } }],
|
|
527
|
-
}),
|
|
528
|
-
}, strategy],
|
|
529
|
-
initialSegment: { kind: 'game', identity: 'g-strategy' },
|
|
530
|
-
});
|
|
531
|
-
await runtime.start();
|
|
532
|
-
const scope = runtime.scope();
|
|
533
|
-
await runtime.acceptInputBatch({
|
|
534
|
-
scope,
|
|
535
|
-
sourceId: 'test.source',
|
|
536
|
-
connectionId: 'connection-1',
|
|
537
|
-
sourceKey: 'strategy-input-1',
|
|
538
|
-
state: wanderingRuntimeState(),
|
|
539
|
-
events: [],
|
|
540
|
-
completeness: 'complete',
|
|
541
|
-
receivedAt: new Date().toISOString(),
|
|
542
|
-
});
|
|
543
|
-
await runtime.flush();
|
|
544
|
-
|
|
545
|
-
expect(calls).toEqual(['start', 'update:1']);
|
|
546
|
-
expect(seenUpstream).toEqual([{ visible: 2 }]);
|
|
547
|
-
expect(runtime.inputJournal.states(1)).toContainEqual(expect.objectContaining({
|
|
548
|
-
pluginId: 'clawclaw.strategy',
|
|
549
|
-
topic: 'strategy.status',
|
|
550
|
-
value: expect.objectContaining({ epoch: 1 }),
|
|
551
|
-
}));
|
|
552
|
-
await runtime.close();
|
|
553
|
-
expect(calls).toEqual([
|
|
554
|
-
'start',
|
|
555
|
-
'update:1',
|
|
556
|
-
'stop:shutdown',
|
|
557
|
-
]);
|
|
558
|
-
});
|
|
559
|
-
|
|
560
|
-
it('skips the Worker in every non-wandering stage and resets it before wandering resumes', async () => {
|
|
561
|
-
const calls: string[] = [];
|
|
562
|
-
let alive = false;
|
|
563
|
-
const strategy = new ClawclawStrategyPlugin({
|
|
564
|
-
executorFactory: () => ({
|
|
565
|
-
runtimeInstanceId: 'phase-worker',
|
|
566
|
-
get isAlive() { return alive; },
|
|
567
|
-
start: async () => { alive = true; calls.push('start'); },
|
|
568
|
-
reset: async () => { calls.push('reset'); },
|
|
569
|
-
update: async (frame) => { calls.push(`update:${frame.epochId}`); return {}; },
|
|
570
|
-
stop: async () => { alive = false; calls.push('stop'); },
|
|
571
|
-
}),
|
|
572
|
-
});
|
|
573
|
-
strategy.select({ id: 'phase-strategy', sourcePath: 'unused.ts', sourceRoot: '.' });
|
|
574
|
-
const runtime = new Runtime({
|
|
575
|
-
adapterId: 'clawclaw',
|
|
576
|
-
accountId: 'acct-strategy-phase',
|
|
577
|
-
eventCatalog: createClawclawEventCatalog(),
|
|
578
|
-
initialSegment: { kind: 'game', identity: 'g-phase' },
|
|
579
|
-
runtimeEpochPlugins: [strategy],
|
|
580
|
-
});
|
|
581
|
-
await runtime.start();
|
|
582
|
-
const accept = (sourceKey: string, state: Record<string, any>) => (
|
|
583
|
-
runtime.acceptInputBatch({
|
|
584
|
-
scope: runtime.scope(),
|
|
585
|
-
sourceId: 'test.source',
|
|
586
|
-
connectionId: 'connection-1',
|
|
587
|
-
sourceKey,
|
|
588
|
-
state,
|
|
589
|
-
events: [],
|
|
590
|
-
completeness: 'complete',
|
|
591
|
-
receivedAt: new Date().toISOString(),
|
|
592
|
-
})
|
|
593
|
-
);
|
|
594
|
-
|
|
595
|
-
await accept('wandering-1', wanderingRuntimeState());
|
|
596
|
-
await runtime.flush();
|
|
597
|
-
expect(calls).toEqual(['start', 'update:1']);
|
|
598
|
-
const inactiveFrames = [
|
|
599
|
-
['matching', 'matching'],
|
|
600
|
-
['room', 'room_waiting'],
|
|
601
|
-
['loading', 'preparing'],
|
|
602
|
-
['game', 'not_wandering'],
|
|
603
|
-
['meeting', 'meeting'],
|
|
604
|
-
['settlement', 'settling'],
|
|
605
|
-
['ended', 'game_over'],
|
|
606
|
-
] as const;
|
|
607
|
-
for (const [stage, phase] of inactiveFrames) {
|
|
608
|
-
await accept(`${stage}-${phase}`, nonWanderingRuntimeState(stage, phase));
|
|
609
|
-
await runtime.flush();
|
|
610
|
-
expect(calls).toEqual(['start', 'update:1']);
|
|
611
|
-
}
|
|
612
|
-
await accept('wandering-resumed', wanderingRuntimeState());
|
|
613
|
-
await runtime.flush();
|
|
614
|
-
expect(calls).toEqual(['start', 'update:1', 'reset', 'update:9']);
|
|
615
|
-
await runtime.close();
|
|
616
|
-
});
|
|
617
|
-
|
|
618
|
-
it('holds event-only input until a fresh wandering State is available', async () => {
|
|
619
|
-
const updates: Array<{ epochId: number; eventTypes: string[] }> = [];
|
|
620
|
-
let alive = false;
|
|
621
|
-
const strategy = new ClawclawStrategyPlugin({
|
|
622
|
-
executorFactory: () => ({
|
|
623
|
-
runtimeInstanceId: 'fresh-state-worker',
|
|
624
|
-
get isAlive() { return alive; },
|
|
625
|
-
start: async () => { alive = true; },
|
|
626
|
-
reset: async () => {},
|
|
627
|
-
update: async (frame) => {
|
|
628
|
-
updates.push({ epochId: frame.epochId, eventTypes: frame.events.map((event) => event.type) });
|
|
629
|
-
return {};
|
|
630
|
-
},
|
|
631
|
-
stop: async () => { alive = false; },
|
|
632
|
-
}),
|
|
633
|
-
});
|
|
634
|
-
strategy.select({ id: 'fresh-state-strategy', sourcePath: 'unused.ts', sourceRoot: '.' });
|
|
635
|
-
const runtime = new Runtime({
|
|
636
|
-
adapterId: 'clawclaw',
|
|
637
|
-
accountId: 'acct-strategy-fresh-state',
|
|
638
|
-
eventCatalog: createClawclawEventCatalog(),
|
|
639
|
-
initialSegment: { kind: 'game', identity: 'g-fresh-state' },
|
|
640
|
-
runtimeEpochPlugins: [strategy],
|
|
641
|
-
});
|
|
642
|
-
await runtime.start();
|
|
643
|
-
const accept = (sourceKey: string, state: Record<string, any>, events: any[] = []) => (
|
|
644
|
-
runtime.acceptInputBatch({
|
|
645
|
-
scope: runtime.scope(),
|
|
646
|
-
sourceId: 'test.source',
|
|
647
|
-
connectionId: 'connection-1',
|
|
648
|
-
sourceKey,
|
|
649
|
-
state,
|
|
650
|
-
events,
|
|
651
|
-
completeness: 'complete',
|
|
652
|
-
receivedAt: new Date().toISOString(),
|
|
653
|
-
})
|
|
654
|
-
);
|
|
655
|
-
|
|
656
|
-
await accept('fresh-1', wanderingRuntimeState());
|
|
657
|
-
await runtime.flush();
|
|
658
|
-
await accept('event-only-2', eventOnlyRuntimeState(), [{
|
|
659
|
-
type: 'task_completed',
|
|
660
|
-
payload: { task_name: 'repair' },
|
|
661
|
-
}]);
|
|
662
|
-
await runtime.flush();
|
|
663
|
-
expect(updates).toEqual([{ epochId: 1, eventTypes: [] }]);
|
|
664
|
-
await accept('fresh-3', wanderingRuntimeState());
|
|
665
|
-
await runtime.flush();
|
|
666
|
-
expect(updates).toEqual([
|
|
667
|
-
{ epochId: 1, eventTypes: [] },
|
|
668
|
-
{ epochId: 3, eventTypes: ['task_completed'] },
|
|
669
|
-
]);
|
|
670
|
-
await runtime.close();
|
|
671
|
-
});
|
|
672
|
-
|
|
673
|
-
it('routes executor Actions through the Runtime Action capability', async () => {
|
|
674
|
-
const client = {
|
|
675
|
-
submitPreparedActionConfirmed: vi.fn().mockResolvedValue(jsonTransportResponse({
|
|
676
|
-
success: true,
|
|
677
|
-
data: { status: 'queued' },
|
|
678
|
-
}, { method: 'POST', path: '/api/v1/game/action' })),
|
|
679
|
-
prepareActionForConfirmedSubmission: vi.fn(async (action) => action),
|
|
680
|
-
chatRoomConfirmed: vi.fn(),
|
|
681
|
-
uploadAudio: vi.fn(),
|
|
682
|
-
} as any;
|
|
683
|
-
let alive = false;
|
|
684
|
-
const strategy = new ClawclawStrategyPlugin({
|
|
685
|
-
after: ['clawclaw.action'],
|
|
686
|
-
executorFactory: (_selection, host) => ({
|
|
687
|
-
runtimeInstanceId: 'action-worker',
|
|
688
|
-
get isAlive() { return alive; },
|
|
689
|
-
start: async () => { alive = true; },
|
|
690
|
-
reset: async () => {},
|
|
691
|
-
update: async () => {
|
|
692
|
-
const action = await host.action({ action: 'task', task_name: 'demo' });
|
|
693
|
-
return {
|
|
694
|
-
states: [{ topic: 'strategy.status', value: { action: action.status } }],
|
|
695
|
-
};
|
|
696
|
-
},
|
|
697
|
-
stop: async () => { alive = false; },
|
|
698
|
-
}),
|
|
699
|
-
});
|
|
700
|
-
strategy.select({ id: 'action-strategy', sourcePath: 'unused.ts', sourceRoot: '.' });
|
|
701
|
-
const runtime = new Runtime({
|
|
702
|
-
adapterId: 'clawclaw',
|
|
703
|
-
accountId: 'acct-strategy-action',
|
|
704
|
-
eventCatalog: createClawclawEventCatalog(),
|
|
705
|
-
initialSegment: { kind: 'game', identity: 'g-action' },
|
|
706
|
-
runtimeEpochPlugins: [new ClawclawActionPlugin(client), strategy],
|
|
707
|
-
});
|
|
708
|
-
await runtime.start();
|
|
709
|
-
await runtime.acceptInputBatch({
|
|
710
|
-
scope: runtime.scope(),
|
|
711
|
-
sourceId: 'test.source',
|
|
712
|
-
connectionId: 'connection-1',
|
|
713
|
-
sourceKey: 'strategy-action-input',
|
|
714
|
-
state: wanderingRuntimeState(),
|
|
715
|
-
events: [],
|
|
716
|
-
completeness: 'complete',
|
|
717
|
-
receivedAt: new Date().toISOString(),
|
|
718
|
-
});
|
|
719
|
-
await runtime.flush();
|
|
720
|
-
|
|
721
|
-
expect(client.submitPreparedActionConfirmed).toHaveBeenCalledWith({
|
|
722
|
-
action: 'task',
|
|
723
|
-
task_name: 'demo',
|
|
724
|
-
});
|
|
725
|
-
expect(runtime.inputJournal.states(1)).toContainEqual(expect.objectContaining({
|
|
726
|
-
pluginId: 'clawclaw.strategy',
|
|
727
|
-
topic: 'strategy.status',
|
|
728
|
-
value: expect.objectContaining({ action: 'success' }),
|
|
729
|
-
}));
|
|
730
|
-
await runtime.close();
|
|
731
|
-
});
|
|
732
|
-
|
|
733
|
-
it('rejects an older Strategy Action after a newer safety boundary is accepted', async () => {
|
|
734
|
-
const events = new MemoryEventRepository();
|
|
735
|
-
const client = {
|
|
736
|
-
submitPreparedActionConfirmed: vi.fn().mockResolvedValue(jsonTransportResponse({
|
|
737
|
-
success: true,
|
|
738
|
-
}, { method: 'POST', path: '/api/v1/game/action' })),
|
|
739
|
-
prepareActionForConfirmedSubmission: vi.fn(async (action) => action),
|
|
740
|
-
chatRoomConfirmed: vi.fn(),
|
|
741
|
-
uploadAudio: vi.fn(),
|
|
742
|
-
} as any;
|
|
743
|
-
const computeStarted = deferred<void>();
|
|
744
|
-
const releaseCompute = deferred<void>();
|
|
745
|
-
const releaseBoundaryDependency = deferred<void>();
|
|
746
|
-
let alive = false;
|
|
747
|
-
const strategy = new ClawclawStrategyPlugin({
|
|
748
|
-
after: ['clawclaw.action', 'test.boundary-dependency'],
|
|
749
|
-
executorFactory: () => ({
|
|
750
|
-
runtimeInstanceId: 'parallel-boundary-worker',
|
|
751
|
-
get isAlive() { return alive; },
|
|
752
|
-
start: async () => { alive = true; },
|
|
753
|
-
reset: async () => {},
|
|
754
|
-
update: async (frame) => {
|
|
755
|
-
if (frame.epochId !== 1) return {};
|
|
756
|
-
computeStarted.resolve();
|
|
757
|
-
await releaseCompute.promise;
|
|
758
|
-
return {
|
|
759
|
-
actions: [{
|
|
760
|
-
action: { action: 'move', target_x: 10, target_y: 20 },
|
|
761
|
-
dedupeKey: 'move-before-meeting',
|
|
762
|
-
}],
|
|
763
|
-
states: [{
|
|
764
|
-
topic: 'strategy.status',
|
|
765
|
-
value: { activity: 'moving', summary: 'moving before meeting' },
|
|
766
|
-
}],
|
|
767
|
-
events: [{
|
|
768
|
-
type: 'strategy_alert',
|
|
769
|
-
dedupeKey: 'alert-before-meeting',
|
|
770
|
-
payload: { message: 'moving before meeting' },
|
|
771
|
-
}],
|
|
772
|
-
};
|
|
773
|
-
},
|
|
774
|
-
stop: async () => { alive = false; },
|
|
775
|
-
}),
|
|
776
|
-
});
|
|
777
|
-
strategy.select({
|
|
778
|
-
id: 'parallel-boundary-strategy',
|
|
779
|
-
sourcePath: 'unused.ts',
|
|
780
|
-
sourceRoot: '.',
|
|
781
|
-
execution: 'parallel_compute',
|
|
782
|
-
});
|
|
783
|
-
const runtime = new Runtime({
|
|
784
|
-
adapterId: 'clawclaw',
|
|
785
|
-
accountId: 'acct-strategy-boundary',
|
|
786
|
-
eventCatalog: createClawclawEventCatalog(),
|
|
787
|
-
eventRepository: events,
|
|
788
|
-
initialSegment: { kind: 'game', identity: 'g-boundary' },
|
|
789
|
-
runtimeEpochPlugins: [
|
|
790
|
-
new ClawclawActionPlugin(client),
|
|
791
|
-
{
|
|
792
|
-
kind: 'epoch',
|
|
793
|
-
id: 'test.boundary-dependency',
|
|
794
|
-
version: '1',
|
|
795
|
-
update: async (input) => {
|
|
796
|
-
if (input.epoch.epochSeq === 2) await releaseBoundaryDependency.promise;
|
|
797
|
-
return { outcome: 'noop' as const };
|
|
798
|
-
},
|
|
799
|
-
},
|
|
800
|
-
strategy,
|
|
801
|
-
],
|
|
802
|
-
});
|
|
803
|
-
await runtime.start();
|
|
804
|
-
const accept = (sourceKey: string, state: Record<string, any>) => runtime.acceptInputBatch({
|
|
805
|
-
scope: runtime.scope(),
|
|
806
|
-
sourceId: 'test.source',
|
|
807
|
-
connectionId: 'connection-1',
|
|
808
|
-
sourceKey,
|
|
809
|
-
state,
|
|
810
|
-
events: [],
|
|
811
|
-
completeness: 'complete',
|
|
812
|
-
receivedAt: new Date().toISOString(),
|
|
813
|
-
});
|
|
814
|
-
|
|
815
|
-
await accept('wandering-before-meeting', wanderingRuntimeState());
|
|
816
|
-
await computeStarted.promise;
|
|
817
|
-
await accept('meeting-boundary', {
|
|
818
|
-
...nonWanderingRuntimeState('meeting', 'meeting'),
|
|
819
|
-
action_safety_generation: 1,
|
|
820
|
-
});
|
|
821
|
-
releaseCompute.resolve();
|
|
822
|
-
|
|
823
|
-
await vi.waitFor(() => expect(
|
|
824
|
-
runtime.inputJournal.pluginProgress('clawclaw.strategy', runtime.scope())
|
|
825
|
-
.completedThroughEpochSeq,
|
|
826
|
-
).toBeGreaterThanOrEqual(1));
|
|
827
|
-
expect(client.prepareActionForConfirmedSubmission).not.toHaveBeenCalled();
|
|
828
|
-
expect(client.submitPreparedActionConfirmed).not.toHaveBeenCalled();
|
|
829
|
-
expect(runtime.inputJournal.states(1).filter((state) => (
|
|
830
|
-
state.pluginId === 'clawclaw.strategy'
|
|
831
|
-
))).toEqual([]);
|
|
832
|
-
expect(events.listCommittedEvents({
|
|
833
|
-
sessionId: runtime.scope().sessionId,
|
|
834
|
-
segmentId: runtime.scope().segmentId,
|
|
835
|
-
types: ['strategy_alert'],
|
|
836
|
-
})).toEqual([]);
|
|
837
|
-
|
|
838
|
-
const strategyController = runtime.actions.controls.snapshot().controllers.find(
|
|
839
|
-
controller => controller.kind === 'strategy',
|
|
840
|
-
);
|
|
841
|
-
expect(strategyController).toBeDefined();
|
|
842
|
-
const strategyCallerId = decodeURIComponent(
|
|
843
|
-
strategyController!.controllerId.slice('strategy:'.length),
|
|
844
|
-
);
|
|
845
|
-
|
|
846
|
-
await expect(runtime.performAction(CLAWCLAW_ACTION_CAPABILITY, {
|
|
847
|
-
action: { action: 'move', target_x: 10, target_y: 20 },
|
|
848
|
-
strategyOriginEpochSeq: 1,
|
|
849
|
-
strategyActionSafetyGeneration: 0,
|
|
850
|
-
}, runtime.publicScope(), {
|
|
851
|
-
kind: 'strategy', id: strategyCallerId,
|
|
852
|
-
})).resolves.toMatchObject({
|
|
853
|
-
status: 'failure',
|
|
854
|
-
source: 'local',
|
|
855
|
-
actionOutcome: 'not_submitted',
|
|
856
|
-
error: { error: { code: 'STALE_STRATEGY_ACTION' } },
|
|
857
|
-
});
|
|
858
|
-
|
|
859
|
-
releaseBoundaryDependency.resolve();
|
|
860
|
-
await runtime.flush();
|
|
861
|
-
await runtime.close();
|
|
862
|
-
});
|
|
863
|
-
|
|
864
|
-
it('routes executor game queries through declared Runtime capabilities', async () => {
|
|
865
|
-
const pathDistance = vi.fn().mockReturnValue(12.5);
|
|
866
|
-
let alive = false;
|
|
867
|
-
const strategy = new ClawclawStrategyPlugin({
|
|
868
|
-
after: ['clawclaw.game-query'],
|
|
869
|
-
executorFactory: (_selection, host) => ({
|
|
870
|
-
runtimeInstanceId: 'query-worker',
|
|
871
|
-
get isAlive() { return alive; },
|
|
872
|
-
start: async () => { alive = true; },
|
|
873
|
-
reset: async () => {},
|
|
874
|
-
update: async () => {
|
|
875
|
-
const map = await host.gameQuery({ kind: 'map' });
|
|
876
|
-
const distance = await host.gameQuery({
|
|
877
|
-
kind: 'path_distance',
|
|
878
|
-
from: { x: 1, y: 2 },
|
|
879
|
-
to: { x: 3, y: 4 },
|
|
880
|
-
});
|
|
881
|
-
return {
|
|
882
|
-
states: [{ topic: 'strategy.status', value: {
|
|
883
|
-
map: map.status === 'success' ? map.value : null,
|
|
884
|
-
distance: distance.status === 'success' ? distance.value : null,
|
|
885
|
-
} }],
|
|
886
|
-
};
|
|
887
|
-
},
|
|
888
|
-
stop: async () => { alive = false; },
|
|
889
|
-
}),
|
|
890
|
-
});
|
|
891
|
-
strategy.select({ id: 'query-strategy', sourcePath: 'unused.ts', sourceRoot: '.' });
|
|
892
|
-
const runtime = new Runtime({
|
|
893
|
-
adapterId: 'clawclaw',
|
|
894
|
-
accountId: 'acct-strategy-query',
|
|
895
|
-
eventCatalog: createClawclawEventCatalog(),
|
|
896
|
-
initialSegment: { kind: 'game', identity: 'g-query' },
|
|
897
|
-
runtimeEpochPlugins: [new ClawclawGameQueryPlugin(pathDistance), strategy],
|
|
898
|
-
});
|
|
899
|
-
await runtime.start();
|
|
900
|
-
await runtime.acceptInputBatch({
|
|
901
|
-
scope: runtime.scope(),
|
|
902
|
-
sourceId: 'test.source',
|
|
903
|
-
connectionId: 'connection-1',
|
|
904
|
-
sourceKey: 'strategy-query-input',
|
|
905
|
-
state: {
|
|
906
|
-
...wanderingRuntimeState(),
|
|
907
|
-
game_snapshot: {
|
|
908
|
-
status: 'fresh' as const,
|
|
909
|
-
state: {
|
|
910
|
-
phase: 'wandering',
|
|
911
|
-
you: { tasks: [{ name: 'repair', room: 'engine', status: 'normal' }] },
|
|
912
|
-
players: [{ name: 'player-2', seat: 2 }],
|
|
913
|
-
},
|
|
914
|
-
},
|
|
915
|
-
},
|
|
916
|
-
events: [],
|
|
917
|
-
completeness: 'complete',
|
|
918
|
-
receivedAt: new Date().toISOString(),
|
|
919
|
-
});
|
|
920
|
-
await runtime.flush();
|
|
921
|
-
|
|
922
|
-
expect(runtime.inputJournal.states(1)).toContainEqual(expect.objectContaining({
|
|
923
|
-
pluginId: 'clawclaw.strategy',
|
|
924
|
-
topic: 'strategy.status',
|
|
925
|
-
value: expect.objectContaining({
|
|
926
|
-
map: expect.objectContaining({
|
|
927
|
-
all_players: [{ name: 'player-2', seat: 2 }],
|
|
928
|
-
your_tasks: [{ name: 'repair', room: 'engine', status: 'normal' }],
|
|
929
|
-
rooms: expect.any(Array),
|
|
930
|
-
all_task_locations: expect.any(Array),
|
|
931
|
-
}),
|
|
932
|
-
distance: 12.5,
|
|
933
|
-
}),
|
|
934
|
-
}));
|
|
935
|
-
await runtime.close();
|
|
936
|
-
});
|
|
937
|
-
|
|
938
|
-
it('applies hot controls before the next update without restarting the strategy', async () => {
|
|
939
|
-
const starts: Array<Readonly<Record<string, unknown>>> = [];
|
|
940
|
-
const stops: string[] = [];
|
|
941
|
-
const controls: Array<{ epochId: number; values: Readonly<Record<string, unknown>> }> = [];
|
|
942
|
-
const updates: number[] = [];
|
|
943
|
-
let executorCount = 0;
|
|
944
|
-
const strategy = new ClawclawStrategyPlugin({
|
|
945
|
-
executorFactory: () => {
|
|
946
|
-
executorCount += 1;
|
|
947
|
-
let alive = false;
|
|
948
|
-
return {
|
|
949
|
-
runtimeInstanceId: `parameter-worker-${executorCount}`,
|
|
950
|
-
get isAlive() { return alive; },
|
|
951
|
-
start: async (parameters) => {
|
|
952
|
-
alive = true;
|
|
953
|
-
starts.push(parameters);
|
|
954
|
-
},
|
|
955
|
-
reset: async () => {},
|
|
956
|
-
applyControl: async (update) => {
|
|
957
|
-
controls.push({ epochId: update.epochId, values: update.values });
|
|
958
|
-
return {
|
|
959
|
-
accepted: true,
|
|
960
|
-
appliedRevision: update.revision,
|
|
961
|
-
effectiveValues: update.values,
|
|
962
|
-
};
|
|
963
|
-
},
|
|
964
|
-
update: async (frame) => {
|
|
965
|
-
updates.push(frame.epochId);
|
|
966
|
-
return {};
|
|
967
|
-
},
|
|
968
|
-
stop: async (reason) => {
|
|
969
|
-
alive = false;
|
|
970
|
-
stops.push(reason);
|
|
971
|
-
},
|
|
972
|
-
};
|
|
973
|
-
},
|
|
974
|
-
});
|
|
975
|
-
strategy.select({
|
|
976
|
-
id: 'parameter-strategy',
|
|
977
|
-
sourcePath: 'unused.ts',
|
|
978
|
-
sourceRoot: '.',
|
|
979
|
-
parameters: { greeting: 'old greeting' },
|
|
980
|
-
});
|
|
981
|
-
const runtime = new Runtime({
|
|
982
|
-
adapterId: 'clawclaw',
|
|
983
|
-
accountId: 'acct-strategy-parameters',
|
|
984
|
-
eventCatalog: createClawclawEventCatalog(),
|
|
985
|
-
initialSegment: { kind: 'game', identity: 'g-parameters' },
|
|
986
|
-
runtimeEpochPlugins: [strategy],
|
|
987
|
-
});
|
|
988
|
-
await runtime.start();
|
|
989
|
-
const scope = runtime.scope();
|
|
990
|
-
const accept = (sourceKey: string) => runtime.acceptInputBatch({
|
|
991
|
-
scope,
|
|
992
|
-
sourceId: 'test.source',
|
|
993
|
-
connectionId: 'connection-1',
|
|
994
|
-
sourceKey,
|
|
995
|
-
state: wanderingRuntimeState(),
|
|
996
|
-
events: [],
|
|
997
|
-
completeness: 'complete' as const,
|
|
998
|
-
receivedAt: new Date().toISOString(),
|
|
999
|
-
});
|
|
1000
|
-
await accept('strategy-parameters-1');
|
|
1001
|
-
await runtime.flush();
|
|
1002
|
-
|
|
1003
|
-
const control = strategy.control({ greeting: 'new greeting' });
|
|
1004
|
-
expect(starts).toEqual([{ greeting: 'old greeting' }]);
|
|
1005
|
-
expect(controls).toEqual([]);
|
|
1006
|
-
await accept('strategy-parameters-2');
|
|
1007
|
-
await runtime.flush();
|
|
1008
|
-
|
|
1009
|
-
await expect(control).resolves.toMatchObject({
|
|
1010
|
-
accepted: true,
|
|
1011
|
-
strategy: 'parameter-strategy',
|
|
1012
|
-
revision: 1,
|
|
1013
|
-
appliedEpochId: 2,
|
|
1014
|
-
effectiveValues: { greeting: 'new greeting' },
|
|
1015
|
-
});
|
|
1016
|
-
expect(starts).toEqual([{ greeting: 'old greeting' }]);
|
|
1017
|
-
expect(executorCount).toBe(1);
|
|
1018
|
-
expect(controls).toEqual([{ epochId: 2, values: { greeting: 'new greeting' } }]);
|
|
1019
|
-
expect(updates).toEqual([1, 2]);
|
|
1020
|
-
expect(stops).toEqual([]);
|
|
1021
|
-
await runtime.close();
|
|
1022
|
-
expect(stops).toEqual(['shutdown']);
|
|
1023
|
-
});
|
|
1024
854
|
});
|