@myclaw163/clawclaw-cli 0.6.112 → 0.7.4
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.md +46 -0
- package/QUICKSTART_HERMES.md +134 -0
- package/QUICKSTART_OPENCLAW.md +134 -0
- package/QUICKSTART_OTHER.md +134 -0
- package/README.md +23 -398
- package/bin/clawclaw-cli.mjs +9 -1
- package/docs/configuration.md +197 -0
- package/docs/runtime/README.md +52 -0
- package/docs/runtime/agent-notifications.md +55 -0
- package/docs/runtime/components-and-boundaries.md +213 -0
- package/docs/runtime/events-and-state.md +105 -0
- package/docs/runtime/owner-lifecycle-and-observability.md +69 -0
- package/docs/runtime/perception-replay.md +51 -0
- package/docs/runtime/short-commands-and-capabilities.md +55 -0
- package/docs/runtime/strategy-runtime.md +111 -0
- package/docs//350/207/252/345/256/232/344/271/211/346/204/237/347/237/245.md +488 -0
- package/docs//350/207/252/345/256/232/344/271/211/347/255/226/347/225/245.md +395 -0
- package/package.json +25 -8
- package/scripts/check-skill-command-surface.mjs +16 -7
- package/scripts/compare-perception-replays.test.ts +188 -0
- package/scripts/compare-perception-replays.ts +589 -0
- package/scripts/generate-spatial-facts.py +246 -0
- package/scripts/package-readme.mjs +48 -0
- package/scripts/replay-perception.ts +347 -0
- package/scripts/sync-frontend-map.mjs +195 -0
- package/scripts/watch-perception-events.test.ts +43 -0
- package/scripts/watch-perception-events.ts +162 -0
- package/skills/clawclaw/SKILL.md +120 -64
- package/skills/clawclaw/references/CHATTERBOX.md +2 -4
- package/skills/clawclaw/references/CLAUDE-CODE-MONITOR.md +1 -1
- package/skills/clawclaw/references/COMMANDS.md +95 -61
- package/skills/clawclaw/references/GAME-MECHANICS.md +18 -8
- package/skills/clawclaw/references/HUB.md +5 -5
- package/skills/clawclaw/references/STRATEGIES.md +34 -17
- package/skills/clawclaw/references/STREAM.md +82 -46
- package/src/assets/clawclaw-map.json +1692 -0
- package/src/assets/clawclaw-spatial-facts.json +1291 -0
- package/src/cli.ts +21 -47
- package/src/commands/account.test.ts +229 -50
- package/src/commands/account.ts +456 -223
- package/src/commands/communication.test.ts +259 -0
- package/src/commands/communication.ts +391 -0
- package/src/commands/competition.test.ts +116 -0
- package/src/commands/competition.ts +50 -28
- package/src/commands/data.test.ts +57 -1
- package/src/commands/data.ts +79 -4
- package/src/commands/events-canonical-state.test.ts +187 -0
- package/src/commands/events.test.ts +50 -136
- package/src/commands/events.ts +175 -241
- package/src/commands/game/index.test.ts +510 -0
- package/src/commands/game/index.ts +556 -0
- package/src/commands/game-map.test.ts +40 -3
- package/src/commands/hub.test.ts +2 -23
- package/src/commands/hub.ts +4 -16
- package/src/commands/load.test.ts +10 -22
- package/src/commands/load.ts +15 -2
- package/src/commands/peek.ts +2 -3
- package/src/commands/perception.test.ts +46 -0
- package/src/commands/perception.ts +92 -0
- package/src/commands/setup/codex.ts +0 -1
- package/src/commands/strategy.test.ts +139 -102
- package/src/commands/strategy.ts +175 -103
- package/src/commands/upgrade.ts +0 -21
- package/src/lib/auth.test.ts +35 -0
- package/src/lib/auth.ts +45 -6
- package/src/lib/diagnostics-config.test.ts +59 -0
- package/src/lib/diagnostics-config.ts +76 -0
- package/src/lib/game-client.test.ts +166 -0
- package/src/lib/game-client.ts +316 -87
- package/src/lib/game-context.ts +29 -0
- package/src/lib/gameplay-config.test.ts +66 -0
- package/src/lib/gameplay-config.ts +151 -0
- package/src/lib/http-transport.test.ts +63 -0
- package/src/lib/http-transport.ts +76 -10
- package/src/lib/init-command.test.ts +25 -1
- package/src/lib/init-command.ts +66 -1
- package/src/lib/participation-leave.ts +78 -0
- package/src/lib/perception-config.test.ts +138 -0
- package/src/lib/perception-config.ts +101 -0
- package/src/lib/room.test.ts +14 -0
- package/src/lib/room.ts +28 -2
- package/src/lib/server-registry.test.ts +15 -5
- package/src/lib/server-registry.ts +9 -10
- package/src/lib/strategy-export.test.ts +123 -44
- package/src/lib/strategy-export.ts +110 -81
- package/src/lib/user-data.test.ts +2 -0
- package/src/lib/user-data.ts +17 -16
- package/src/pipeline/canonical-event-presentation.test.ts +195 -0
- package/src/pipeline/canonical-event-presentation.ts +71 -0
- package/src/pipeline/event-format.test.ts +357 -59
- package/src/pipeline/event-format.ts +365 -80
- package/src/pipeline/event-hints.test.ts +241 -0
- package/src/pipeline/event-hints.ts +202 -51
- package/src/pipeline/game-sync-event-normalization.test.ts +239 -0
- package/src/pipeline/game-sync-event-normalization.ts +215 -0
- package/src/pipeline/player-projection.test.ts +164 -102
- package/src/pipeline/player-projection.ts +194 -235
- package/src/runtime/canonical-event-emitter.test.ts +70 -0
- package/src/runtime/canonical-event-emitter.ts +78 -0
- package/src/runtime/canonical-monitor.test.ts +575 -0
- package/src/runtime/canonical-monitor.ts +388 -0
- package/src/runtime/clawclaw/agent-event-policy.test.ts +27 -0
- package/src/runtime/clawclaw/agent-event-policy.ts +35 -0
- package/src/runtime/clawclaw/index.ts +4 -0
- package/src/runtime/clawclaw/notifications.test.ts +47 -0
- package/src/runtime/clawclaw/notifications.ts +65 -0
- package/src/runtime/clawclaw/owner-lock.test.ts +221 -0
- package/src/runtime/clawclaw/owner.ts +945 -0
- package/src/runtime/clawclaw/plugins/action/action-plugin.ts +299 -0
- package/src/runtime/clawclaw/plugins/action/index.ts +1 -0
- package/src/runtime/clawclaw/plugins/assembly.test.ts +81 -0
- package/src/runtime/clawclaw/plugins/assembly.ts +116 -0
- package/src/runtime/clawclaw/plugins/derived-event/derived-event-plugin.test.ts +150 -0
- package/src/runtime/clawclaw/plugins/derived-event/derived-event-plugin.ts +100 -0
- package/src/runtime/clawclaw/plugins/derived-event/derived-event-rules.ts +162 -0
- package/src/runtime/clawclaw/plugins/derived-event/index.ts +2 -0
- package/src/runtime/clawclaw/plugins/game-query/game-query-plugin.test.ts +223 -0
- package/src/runtime/clawclaw/plugins/game-query/game-query-plugin.ts +236 -0
- package/src/runtime/clawclaw/plugins/game-query/index.ts +1 -0
- package/src/runtime/clawclaw/plugins/index.ts +7 -0
- package/src/runtime/clawclaw/plugins/mailbox/index.ts +3 -0
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-plugin.ts +77 -0
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-presentation.ts +91 -0
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.test.ts +1008 -0
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.ts +475 -0
- package/src/runtime/clawclaw/plugins/perception/contracts.ts +32 -0
- package/src/runtime/clawclaw/plugins/perception/index.ts +8 -0
- package/src/runtime/clawclaw/plugins/perception/module-runner.test.ts +204 -0
- package/src/runtime/clawclaw/plugins/perception/module-runner.ts +290 -0
- package/src/runtime/clawclaw/plugins/perception/modules/co-movement-module.ts +324 -0
- package/src/runtime/clawclaw/plugins/perception/modules/follow-module.ts +365 -0
- package/src/runtime/clawclaw/plugins/perception/modules/index.ts +7 -0
- package/src/runtime/clawclaw/plugins/perception/modules/motion-module.test.ts +341 -0
- package/src/runtime/clawclaw/plugins/perception/modules/motion-module.ts +447 -0
- package/src/runtime/clawclaw/plugins/perception/modules/parallel-module-test-helpers.ts +30 -0
- package/src/runtime/clawclaw/plugins/perception/modules/relation-stability.test.ts +289 -0
- package/src/runtime/clawclaw/plugins/perception/modules/route-module.test.ts +180 -0
- package/src/runtime/clawclaw/plugins/perception/modules/route-module.ts +329 -0
- package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.test.ts +82 -0
- package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.ts +172 -0
- package/src/runtime/clawclaw/plugins/perception/modules/stop-module.test.ts +212 -0
- package/src/runtime/clawclaw/plugins/perception/modules/stop-module.ts +256 -0
- package/src/runtime/clawclaw/plugins/perception/modules/temporal-evidence.test.ts +121 -0
- package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.test.ts +106 -0
- package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.ts +225 -0
- package/src/runtime/clawclaw/plugins/perception/official-module-ids.ts +11 -0
- package/src/runtime/clawclaw/plugins/perception/official-modules.ts +31 -0
- package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-pool.test.ts +759 -0
- package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-pool.ts +707 -0
- package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-worker.ts +215 -0
- package/src/runtime/clawclaw/plugins/perception/perception-module-loader.ts +61 -0
- package/src/runtime/clawclaw/plugins/perception/perception-plugin.test.ts +1516 -0
- package/src/runtime/clawclaw/plugins/perception/perception-plugin.ts +1529 -0
- package/src/runtime/clawclaw/plugins/perception/perception-source.test.ts +119 -0
- package/src/runtime/clawclaw/plugins/perception/perception-source.ts +244 -0
- package/src/runtime/clawclaw/plugins/perception/replay.test.ts +65 -0
- package/src/runtime/clawclaw/plugins/perception/replay.ts +86 -0
- package/src/runtime/clawclaw/plugins/perception/shared/math.ts +107 -0
- package/src/runtime/clawclaw/plugins/perception/spatial-facts.ts +114 -0
- package/src/runtime/clawclaw/plugins/perception/visual-state-projector.ts +98 -0
- package/src/runtime/clawclaw/plugins/runtime-plugins.test.ts +1019 -0
- package/src/runtime/clawclaw/plugins/source/game-transport.test.ts +287 -0
- package/src/runtime/clawclaw/plugins/source/game-transport.ts +281 -0
- package/src/runtime/clawclaw/plugins/source/index.ts +5 -0
- package/src/runtime/clawclaw/plugins/source/player-change-tracker.test.ts +270 -0
- package/src/runtime/clawclaw/plugins/source/player-change-tracker.ts +151 -0
- package/src/runtime/clawclaw/plugins/source/room-transport.test.ts +307 -0
- package/src/runtime/clawclaw/plugins/source/room-transport.ts +480 -0
- package/src/runtime/clawclaw/plugins/source/source-plugin.test.ts +1909 -0
- package/src/runtime/clawclaw/plugins/source/source-plugin.ts +2055 -0
- package/src/runtime/clawclaw/plugins/source/source-transports.ts +30 -0
- package/src/runtime/clawclaw/plugins/source/types.ts +79 -0
- package/src/runtime/clawclaw/plugins/strategy/context-capabilities.ts +5 -0
- package/src/runtime/clawclaw/plugins/strategy/examples/task-only-strategy.test.ts +177 -0
- package/src/runtime/clawclaw/plugins/strategy/examples/task-only-strategy.ts +185 -0
- package/src/runtime/clawclaw/plugins/strategy/index.ts +8 -0
- package/src/runtime/clawclaw/plugins/strategy/local-strategy-executor.ts +412 -0
- package/src/runtime/clawclaw/plugins/strategy/strategy-action.ts +73 -0
- package/src/runtime/clawclaw/plugins/strategy/strategy-analysis-thread-host.ts +183 -0
- package/src/runtime/clawclaw/plugins/strategy/strategy-executor-types.ts +25 -0
- package/src/runtime/clawclaw/plugins/strategy/strategy-executor.test.ts +693 -0
- package/src/runtime/clawclaw/plugins/strategy/strategy-game-api.ts +57 -0
- package/src/runtime/clawclaw/plugins/strategy/strategy-module-loader.ts +164 -0
- package/src/runtime/clawclaw/plugins/strategy/strategy-plugin.test.ts +1936 -0
- package/src/runtime/clawclaw/plugins/strategy/strategy-plugin.ts +1557 -0
- package/src/runtime/clawclaw/plugins/strategy/strategy-source.test.ts +131 -0
- package/src/runtime/clawclaw/plugins/strategy/strategy-source.ts +413 -0
- package/src/runtime/clawclaw/plugins/strategy/thread-strategy-executor.ts +792 -0
- package/src/runtime/clawclaw/runtime-data-export.test.ts +249 -0
- package/src/runtime/clawclaw/runtime-data-export.ts +402 -0
- package/src/runtime/clawclaw/runtime-state.ts +98 -0
- package/src/runtime/clawclaw/runtime.ts +133 -0
- package/src/runtime/clawclaw-event-catalog.test.ts +74 -0
- package/src/runtime/clawclaw-event-catalog.ts +266 -0
- package/src/runtime/clawclaw-position.ts +4 -0
- package/src/runtime/clawclaw-room-state.ts +51 -0
- package/src/runtime/framework/action-diagnostics.test.ts +81 -0
- package/src/runtime/framework/action-diagnostics.ts +146 -0
- package/src/runtime/framework/capability-registry.test.ts +282 -0
- package/src/runtime/framework/capability-registry.ts +283 -0
- package/src/runtime/framework/contracts.ts +118 -0
- package/src/runtime/framework/control/control-scheduler.ts +1260 -0
- package/src/runtime/framework/control/domain-set.ts +81 -0
- package/src/runtime/framework/control/index.ts +3 -0
- package/src/runtime/framework/control/types.ts +184 -0
- package/src/runtime/framework/control-coordinator.test.ts +660 -0
- package/src/runtime/framework/control-coordinator.ts +11 -0
- package/src/runtime/framework/events/event-catalog.ts +74 -0
- package/src/runtime/framework/events/event-delivery-service.test.ts +84 -0
- package/src/runtime/framework/events/event-delivery-service.ts +198 -0
- package/src/runtime/framework/events/event-ingress.test.ts +178 -0
- package/src/runtime/framework/events/event-ingress.ts +97 -0
- package/src/runtime/framework/events/event-repository.ts +59 -0
- package/src/runtime/framework/events/index.ts +7 -0
- package/src/runtime/framework/events/mailbox-event-repositories.test.ts +594 -0
- package/src/runtime/framework/events/memory-event-repository.ts +928 -0
- package/src/runtime/framework/events/sqlite-event-repository.test.ts +200 -0
- package/src/runtime/framework/events/sqlite-event-repository.ts +1681 -0
- package/src/runtime/framework/events/test-helpers.ts +78 -0
- package/src/runtime/framework/events/types.ts +286 -0
- package/src/runtime/framework/index.ts +7 -0
- package/src/runtime/framework/load-node-sqlite.ts +17 -0
- package/src/runtime/framework/mailbox/coalescer.test.ts +55 -0
- package/src/runtime/framework/mailbox/coalescer.ts +83 -0
- package/src/runtime/framework/mailbox/host-notification-sink.ts +44 -0
- package/src/runtime/framework/mailbox/identity.test.ts +38 -0
- package/src/runtime/framework/mailbox/identity.ts +38 -0
- package/src/runtime/framework/mailbox/index.ts +7 -0
- package/src/runtime/framework/mailbox/mailbox-dispatcher.test.ts +513 -0
- package/src/runtime/framework/mailbox/mailbox-dispatcher.ts +282 -0
- package/src/runtime/framework/mailbox/mailbox-repository.ts +44 -0
- package/src/runtime/framework/mailbox/notification-projector.test.ts +77 -0
- package/src/runtime/framework/mailbox/notification-projector.ts +65 -0
- package/src/runtime/framework/mailbox/types.ts +139 -0
- package/src/runtime/framework/modules/runtime-module-loader-hooks.d.mts +19 -0
- package/src/runtime/framework/modules/runtime-module-loader-hooks.mjs +117 -0
- package/src/runtime/framework/modules/runtime-module-loader.test.ts +209 -0
- package/src/runtime/framework/modules/runtime-module-loader.ts +71 -0
- package/src/runtime/framework/modules/runtime-module-worker-bootstrap.mjs +23 -0
- package/src/runtime/framework/participation-manager.test.ts +108 -0
- package/src/runtime/framework/participation-manager.ts +244 -0
- package/src/runtime/framework/plugins/contracts.ts +382 -0
- package/src/runtime/framework/plugins/index.ts +4 -0
- package/src/runtime/framework/plugins/runtime-event-identity.ts +17 -0
- package/src/runtime/framework/plugins/runtime-input-journal.test.ts +179 -0
- package/src/runtime/framework/plugins/runtime-input-journal.ts +693 -0
- package/src/runtime/framework/plugins/runtime-plugin-scheduler.test.ts +1994 -0
- package/src/runtime/framework/plugins/runtime-plugin-scheduler.ts +1860 -0
- package/src/runtime/framework/runtime.ts +1756 -0
- package/src/runtime/framework/serial-task-queue.ts +14 -0
- package/src/runtime/framework/state/contracts.ts +49 -0
- package/src/runtime/framework/state/current-state-store.ts +184 -0
- package/src/runtime/framework/state/durable-agent-state-snapshot.test.ts +144 -0
- package/src/runtime/framework/state/durable-agent-state-snapshot.ts +209 -0
- package/src/runtime/framework/state/freshness.ts +72 -0
- package/src/runtime/framework/state/history/contracts.ts +150 -0
- package/src/runtime/framework/state/history/history-writer.ts +194 -0
- package/src/runtime/framework/state/history/memory-state-history-repository.ts +178 -0
- package/src/runtime/framework/state/history/sqlite-state-history-repository.test.ts +157 -0
- package/src/runtime/framework/state/history/sqlite-state-history-repository.ts +629 -0
- package/src/runtime/framework/state/history/state-history.test.ts +251 -0
- package/src/runtime/framework/state/history/trajectory-projector.ts +209 -0
- package/src/runtime/framework/state/index.ts +13 -0
- package/src/runtime/framework/state/state-core.test.ts +197 -0
- package/src/runtime/framework/state/state-ingress.ts +95 -0
- package/src/runtime/framework/state/state-provider.ts +62 -0
- package/src/runtime/framework/state/types.ts +155 -0
- package/src/runtime/game-sync-protocol.test.ts +123 -0
- package/src/runtime/game-sync-protocol.ts +261 -0
- package/src/runtime/mailbox-host-relay.test.ts +248 -0
- package/src/runtime/mailbox-host-relay.ts +300 -0
- package/src/runtime/observability/factory.ts +188 -0
- package/src/runtime/observability/index.ts +6 -0
- package/src/runtime/observability/observability.test.ts +561 -0
- package/src/runtime/observability/recorder.ts +209 -0
- package/src/runtime/observability/redaction.ts +154 -0
- package/src/runtime/observability/reporter.ts +154 -0
- package/src/runtime/observability/sinks.ts +135 -0
- package/src/runtime/observability/types.ts +92 -0
- package/src/runtime/owner-control.test.ts +153 -0
- package/src/runtime/owner-control.ts +206 -42
- package/src/runtime/parent-process-watch.test.ts +27 -0
- package/src/runtime/parent-process-watch.ts +51 -0
- package/src/runtime/pending-event-handoff.test.ts +29 -0
- package/src/runtime/pending-event-handoff.ts +61 -0
- package/src/runtime/raw-ws-log.test.ts +86 -17
- package/src/runtime/raw-ws-log.ts +230 -21
- package/src/runtime/runtime-logger.test.ts +58 -0
- package/src/runtime/runtime-logger.ts +10 -13
- package/src/runtime/runtime-persistence.test.ts +26 -0
- package/src/runtime/runtime.test.ts +1704 -0
- package/src/runtime/ws-client.test.ts +496 -103
- package/src/runtime/ws-client.ts +546 -166
- package/src/sdk/action.ts +3 -1
- package/src/sdk/index.ts +4 -19
- package/src/sdk/perception-plugin/index.test.ts +22 -0
- package/src/sdk/perception-plugin/index.ts +285 -0
- package/src/sdk/strategy-plugin/index.test.ts +952 -0
- package/src/sdk/strategy-plugin/index.ts +1324 -0
- package/src/sdk/types.ts +3 -1
- package/src/short-command/classifier.test.ts +107 -0
- package/src/short-command/classifier.ts +169 -0
- package/src/short-command/index.ts +7 -0
- package/src/short-command/presenter.test.ts +119 -0
- package/src/short-command/presenter.ts +308 -0
- package/src/short-command/process-io.ts +13 -0
- package/src/short-command/response-contract.ts +58 -0
- package/src/short-command/runner.test.ts +78 -0
- package/src/short-command/runner.ts +164 -0
- package/src/short-command/sensitive-data-filter.test.ts +56 -0
- package/src/short-command/sensitive-data-filter.ts +123 -0
- package/src/short-command/transport-response.test.ts +39 -0
- package/src/short-command/transport-response.ts +89 -0
- package/src/short-command/types.ts +92 -0
- package/src/strategies/avoid-lone.ts +18 -11
- package/src/strategies/avoid-players.ts +29 -13
- package/src/strategies/corpse-patrol.ts +29 -11
- package/src/strategies/crab-sabotage.ts +31 -18
- package/src/strategies/custom-module.test.ts +3 -5
- package/src/strategies/find-player.ts +34 -15
- package/src/strategies/game-utils.test.ts +42 -0
- package/src/strategies/game-utils.ts +143 -53
- package/src/strategies/goals/avoid-lone-top.ts +22 -1
- package/src/strategies/goals/avoid-players-top.test.ts +13 -0
- package/src/strategies/goals/avoid-players-top.ts +6 -5
- package/src/strategies/goals/corpse-patrol-top.ts +9 -2
- package/src/strategies/goals/crab-octopus-reflexes.ts +6 -2
- package/src/strategies/goals/crab-sabotage-top.ts +7 -1
- package/src/strategies/goals/emergency-hunt-goal.ts +15 -3
- package/src/strategies/goals/find-player-top.ts +47 -3
- package/src/strategies/goals/flee-players-goal.ts +2 -0
- package/src/strategies/goals/follow-companion-goal.ts +27 -3
- package/src/strategies/goals/hide-top.ts +47 -5
- package/src/strategies/goals/keep-away-goal.ts +24 -2
- package/src/strategies/goals/kill-frenzy-top.ts +12 -2
- package/src/strategies/goals/kill-lone-top.test.ts +72 -0
- package/src/strategies/goals/kill-lone-top.ts +8 -6
- package/src/strategies/goals/kill-target-goal.ts +16 -7
- package/src/strategies/goals/kill-target-top.ts +16 -2
- package/src/strategies/goals/linger-corpse-goal.ts +11 -3
- package/src/strategies/goals/lone-kill-core.ts +4 -2
- package/src/strategies/goals/move-room-goal.ts +46 -4
- package/src/strategies/goals/normal-shrimp-top.test.ts +16 -0
- package/src/strategies/goals/normal-shrimp-top.ts +18 -18
- package/src/strategies/goals/paradise-fish-top.test.ts +78 -0
- package/src/strategies/goals/paradise-fish-top.ts +16 -6
- package/src/strategies/goals/patrol-top.ts +14 -3
- package/src/strategies/goals/report-patrol-top.ts +14 -3
- package/src/strategies/goals/safe-task-goal.ts +32 -4
- package/src/strategies/goals/social-task-top.ts +39 -8
- package/src/strategies/goals/task-kill-report-top.ts +33 -10
- package/src/strategies/goals/task-only-top.test.ts +89 -0
- package/src/strategies/goals/task-only-top.ts +9 -2
- package/src/strategies/goals/task-or-patrol-goal.ts +21 -3
- package/src/strategies/goals/warrior-shrimp-top.test.ts +75 -23
- package/src/strategies/goals/warrior-shrimp-top.ts +34 -13
- package/src/strategies/greeting.ts +10 -3
- package/src/strategies/hide-spots.ts +4 -0
- package/src/strategies/hide.ts +35 -20
- package/src/strategies/kill-frenzy.ts +18 -12
- package/src/strategies/kill-lone.ts +43 -12
- package/src/strategies/kill-target.ts +34 -17
- package/src/strategies/lone-kill-task.ts +31 -18
- package/src/strategies/move-room.ts +32 -15
- package/src/strategies/off-route-points.ts +12 -4
- package/src/strategies/paradise-fish.ts +49 -14
- package/src/strategies/pathfind/astar-path.test.ts +73 -0
- package/src/strategies/pathfind/astar-path.ts +196 -0
- package/src/strategies/pathfind/escape-planner.test.ts +27 -1
- package/src/strategies/pathfind/escape-planner.ts +108 -0
- package/src/strategies/patrol.ts +18 -11
- package/src/strategies/report-patrol.ts +18 -11
- package/src/strategies/shrimp-memory.ts +66 -14
- package/src/strategies/social-task.ts +49 -45
- package/src/strategies/task-kill-report.ts +34 -16
- package/src/strategies/task-only.test.ts +124 -0
- package/src/strategies/task-only.ts +20 -11
- package/src/strategies/task-report.ts +29 -11
- package/src/strategies/types.ts +29 -62
- package/src/strategies/warrior-memory.ts +44 -14
- package/scripts/check_monitor.test.mjs +0 -212
- package/skills/clawclaw/references/KNOWLEDGE.md +0 -42
- package/src/commands/do.test.ts +0 -117
- package/src/commands/do.ts +0 -195
- package/src/commands/game-monitor-status.test.ts +0 -58
- package/src/commands/game-start-plan.test.ts +0 -356
- package/src/commands/game.ts +0 -2046
- package/src/commands/history-player.test.ts +0 -105
- package/src/commands/history.ts +0 -573
- package/src/commands/knowledge.test.ts +0 -13
- package/src/commands/knowledge.ts +0 -176
- package/src/commands/meeting-history.test.ts +0 -106
- package/src/commands/state.ts +0 -46
- package/src/commands/watch.test.ts +0 -1313
- package/src/commands/watch.ts +0 -824
- package/src/lib/knowledge-store.test.ts +0 -170
- package/src/lib/knowledge-store.ts +0 -369
- package/src/perception/player-history-store.test.ts +0 -177
- package/src/perception/player-history-store.ts +0 -262
- package/src/pipeline/event-store.test.ts +0 -28
- package/src/pipeline/event-store.ts +0 -193
- package/src/pipeline/pipeline.ts +0 -35
- package/src/runtime/event-daemon.test.ts +0 -268
- package/src/runtime/event-daemon.ts +0 -531
- package/src/runtime/room-lobby-runtime.test.ts +0 -95
- package/src/runtime/room-lobby-runtime.ts +0 -367
- package/src/strategies/avoid-players.knowledge.md +0 -19
- package/src/strategies/kill-lone.knowledge.md +0 -17
- package/src/strategies/knowledge-contract.ts +0 -85
- package/src/strategies/loader.test.ts +0 -710
- package/src/strategies/loader.ts +0 -183
- package/src/strategies/new-events-backfill.ts +0 -98
- package/src/strategies/paradise-fish.knowledge.md +0 -19
- package/src/strategies/scanner.ts +0 -238
- package/src/strategies/shrimp-memory.knowledge.md +0 -19
- package/src/strategies/social-task.test.ts +0 -28
- package/src/strategies/spawn.ts +0 -82
- package/src/strategies/strategy-loop.test.ts +0 -15
- package/src/strategies/strategy-loop.ts +0 -748
- package/src/strategies/warrior-memory.knowledge.md +0 -21
|
@@ -0,0 +1,660 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import type { ScopeRef } from './contracts.js';
|
|
3
|
+
import {
|
|
4
|
+
ControlScheduler,
|
|
5
|
+
type ControlClock,
|
|
6
|
+
type ControllerSpec,
|
|
7
|
+
} from './control-coordinator.js';
|
|
8
|
+
|
|
9
|
+
const scope: ScopeRef = {
|
|
10
|
+
adapterId: 'test',
|
|
11
|
+
accountId: 'account',
|
|
12
|
+
sessionId: 'session',
|
|
13
|
+
segmentId: 'round-1',
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
class ManualClock implements ControlClock {
|
|
17
|
+
private current = 1_000;
|
|
18
|
+
private sleepers: Array<{ at: number; resolve: () => void }> = [];
|
|
19
|
+
|
|
20
|
+
now(): number {
|
|
21
|
+
return this.current;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
sleep(milliseconds: number): Promise<void> {
|
|
25
|
+
return new Promise((resolve) => {
|
|
26
|
+
this.sleepers.push({ at: this.current + milliseconds, resolve });
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
advance(milliseconds: number): void {
|
|
31
|
+
this.current += milliseconds;
|
|
32
|
+
const ready = this.sleepers.filter((entry) => entry.at <= this.current);
|
|
33
|
+
this.sleepers = this.sleepers.filter((entry) => entry.at > this.current);
|
|
34
|
+
for (const entry of ready) entry.resolve();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function deferred<T>() {
|
|
39
|
+
let resolve!: (value: T | PromiseLike<T>) => void;
|
|
40
|
+
let reject!: (reason?: unknown) => void;
|
|
41
|
+
const promise = new Promise<T>((resolvePromise, rejectPromise) => {
|
|
42
|
+
resolve = resolvePromise;
|
|
43
|
+
reject = rejectPromise;
|
|
44
|
+
});
|
|
45
|
+
return { promise, resolve, reject };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function controller(
|
|
49
|
+
controllerId: string,
|
|
50
|
+
kind: ControllerSpec['kind'],
|
|
51
|
+
domains: string[],
|
|
52
|
+
overrides: Partial<ControllerSpec> = {},
|
|
53
|
+
): ControllerSpec {
|
|
54
|
+
return {
|
|
55
|
+
controllerId,
|
|
56
|
+
kind,
|
|
57
|
+
domains,
|
|
58
|
+
scope,
|
|
59
|
+
ready: true,
|
|
60
|
+
...(kind === 'task' ? { maxRuntimeMs: 1_000 } : {}),
|
|
61
|
+
...overrides,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async function expectExecuted<T>(promise: Promise<unknown>, value: T): Promise<void> {
|
|
66
|
+
await expect(promise).resolves.toMatchObject({ status: 'executed', value });
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
describe('ControlScheduler controller lifecycle', () => {
|
|
70
|
+
it('holds a strategy only while an Agent is active, then restores it after lease expiry', async () => {
|
|
71
|
+
const clock = new ManualClock();
|
|
72
|
+
const scheduler = new ControlScheduler({ clock, defaultActivityLeaseMs: 100 });
|
|
73
|
+
scheduler.registerController(controller('strategy', 'strategy', ['body']));
|
|
74
|
+
scheduler.registerController(controller('agent', 'agent', ['*'], { activityLeaseMs: 100 }));
|
|
75
|
+
|
|
76
|
+
await expectExecuted(scheduler.runAction({
|
|
77
|
+
controllerId: 'strategy', scope, domains: ['body'], execute: () => 'before',
|
|
78
|
+
}), 'before');
|
|
79
|
+
await expectExecuted(scheduler.runAction({
|
|
80
|
+
controllerId: 'agent', scope, domains: ['body'], execute: () => 'direct',
|
|
81
|
+
}), 'direct');
|
|
82
|
+
|
|
83
|
+
const heldProvider = vi.fn(() => 'stale');
|
|
84
|
+
await expect(scheduler.runAction({
|
|
85
|
+
controllerId: 'strategy', scope, domains: ['body'], execute: heldProvider,
|
|
86
|
+
})).resolves.toMatchObject({ status: 'deferred', code: 'CONTROL_HELD' });
|
|
87
|
+
expect(heldProvider).not.toHaveBeenCalled();
|
|
88
|
+
|
|
89
|
+
clock.advance(101);
|
|
90
|
+
await expectExecuted(scheduler.runAction({
|
|
91
|
+
controllerId: 'strategy', scope, domains: ['body'], execute: () => 'fallback',
|
|
92
|
+
}), 'fallback');
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('does not leave an Agent lease behind when a higher controller rejects admission', async () => {
|
|
96
|
+
const scheduler = new ControlScheduler();
|
|
97
|
+
scheduler.registerController(controller('safety', 'system', ['body']));
|
|
98
|
+
scheduler.registerController(controller('agent', 'agent', ['*']));
|
|
99
|
+
const provider = vi.fn(() => 'never');
|
|
100
|
+
|
|
101
|
+
await expect(scheduler.runAction({
|
|
102
|
+
controllerId: 'agent', scope, domains: ['body'], execute: provider,
|
|
103
|
+
})).resolves.toMatchObject({ status: 'deferred', code: 'CONTROL_HELD' });
|
|
104
|
+
expect(provider).not.toHaveBeenCalled();
|
|
105
|
+
expect(scheduler.snapshot().controllers.find((entry) => entry.controllerId === 'agent'))
|
|
106
|
+
.toMatchObject({ state: 'idle', claimedDomains: [] });
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('hands Agent control to a finite task and restores strategy fallback on task exit', async () => {
|
|
110
|
+
const clock = new ManualClock();
|
|
111
|
+
const scheduler = new ControlScheduler({ clock });
|
|
112
|
+
scheduler.registerController(controller('strategy', 'strategy', ['body']));
|
|
113
|
+
scheduler.registerController(controller('agent', 'agent', ['*']));
|
|
114
|
+
scheduler.registerController(controller('task', 'task', ['body'], {
|
|
115
|
+
ready: false,
|
|
116
|
+
maxRuntimeMs: 500,
|
|
117
|
+
}));
|
|
118
|
+
await expectExecuted(scheduler.runAction({
|
|
119
|
+
controllerId: 'agent', scope, domains: ['body'], execute: () => 'direct',
|
|
120
|
+
}), 'direct');
|
|
121
|
+
|
|
122
|
+
const handoff = scheduler.handoff({
|
|
123
|
+
fromControllerId: 'agent',
|
|
124
|
+
toControllerId: 'task',
|
|
125
|
+
domains: ['body'],
|
|
126
|
+
});
|
|
127
|
+
expect(handoff.from.state).toBe('idle');
|
|
128
|
+
expect(handoff.to.state).toBe('active');
|
|
129
|
+
await expectExecuted(scheduler.runAction({
|
|
130
|
+
controllerId: 'task', scope, domains: ['body'], execute: () => 'task-work',
|
|
131
|
+
}), 'task-work');
|
|
132
|
+
|
|
133
|
+
scheduler.release('task', { reason: 'process_exited' });
|
|
134
|
+
await expectExecuted(scheduler.runAction({
|
|
135
|
+
controllerId: 'strategy', scope, domains: ['body'], execute: () => 'resumed',
|
|
136
|
+
}), 'resumed');
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('keeps Agent control when a higher controller blocks task handoff', async () => {
|
|
140
|
+
const scheduler = new ControlScheduler();
|
|
141
|
+
scheduler.registerController(controller('agent', 'agent', ['*']));
|
|
142
|
+
scheduler.registerController(controller('task', 'task', ['body'], { ready: false }));
|
|
143
|
+
await expectExecuted(scheduler.runAction({
|
|
144
|
+
controllerId: 'agent', scope, domains: ['body'], execute: () => 'direct',
|
|
145
|
+
}), 'direct');
|
|
146
|
+
scheduler.registerController(controller('safety', 'system', ['body']));
|
|
147
|
+
|
|
148
|
+
expect(() => scheduler.handoff({
|
|
149
|
+
fromControllerId: 'agent',
|
|
150
|
+
toControllerId: 'task',
|
|
151
|
+
domains: ['body'],
|
|
152
|
+
})).toThrow('control_handoff_target_held');
|
|
153
|
+
expect(scheduler.snapshot().controllers.find((entry) => entry.controllerId === 'agent'))
|
|
154
|
+
.toMatchObject({ claimedDomains: ['body'] });
|
|
155
|
+
expect(scheduler.snapshot().controllers.find((entry) => entry.controllerId === 'task'))
|
|
156
|
+
.toMatchObject({ ready: false });
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('expires a crashed finite task at its hard deadline', async () => {
|
|
160
|
+
const clock = new ManualClock();
|
|
161
|
+
const scheduler = new ControlScheduler({ clock });
|
|
162
|
+
scheduler.registerController(controller('strategy', 'strategy', ['body']));
|
|
163
|
+
scheduler.registerController(controller('task', 'task', ['body'], { maxRuntimeMs: 50 }));
|
|
164
|
+
|
|
165
|
+
await expect(scheduler.runAction({
|
|
166
|
+
controllerId: 'strategy', scope, domains: ['body'], execute: () => 'held',
|
|
167
|
+
})).resolves.toMatchObject({ status: 'deferred', code: 'CONTROL_HELD' });
|
|
168
|
+
clock.advance(51);
|
|
169
|
+
await expectExecuted(scheduler.runAction({
|
|
170
|
+
controllerId: 'strategy', scope, domains: ['body'], execute: () => 'recovered',
|
|
171
|
+
}), 'recovered');
|
|
172
|
+
expect(scheduler.snapshot().controllers.find((entry) => entry.controllerId === 'task'))
|
|
173
|
+
.toMatchObject({ state: 'expired', releaseReason: 'deadline_expired' });
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it('awaitControl waits for lease expiry without queuing an Action', async () => {
|
|
177
|
+
const clock = new ManualClock();
|
|
178
|
+
const scheduler = new ControlScheduler({ clock, defaultActivityLeaseMs: 50 });
|
|
179
|
+
scheduler.registerController(controller('strategy', 'strategy', ['body']));
|
|
180
|
+
scheduler.registerController(controller('agent', 'agent', ['*'], { activityLeaseMs: 50 }));
|
|
181
|
+
await expectExecuted(scheduler.runAction({
|
|
182
|
+
controllerId: 'agent', scope, domains: ['body'], execute: () => 'direct',
|
|
183
|
+
}), 'direct');
|
|
184
|
+
|
|
185
|
+
const awaiting = scheduler.awaitControl('strategy', scope, ['body'], { timeoutMs: 100 });
|
|
186
|
+
clock.advance(51);
|
|
187
|
+
await expect(awaiting).resolves.toMatchObject({ status: 'granted' });
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it('does not let an awaiter follow a re-registered controller with the same id', async () => {
|
|
191
|
+
const scheduler = new ControlScheduler();
|
|
192
|
+
scheduler.registerController(controller('blocker', 'system', ['body']));
|
|
193
|
+
scheduler.registerController(controller('strategy', 'strategy', ['body']));
|
|
194
|
+
const waiting = scheduler.awaitControl('strategy', scope, ['body']);
|
|
195
|
+
|
|
196
|
+
scheduler.release('strategy', { reason: 'process_exited' });
|
|
197
|
+
scheduler.registerController(controller('strategy', 'strategy', ['body']));
|
|
198
|
+
|
|
199
|
+
await expect(waiting).resolves.toMatchObject({
|
|
200
|
+
status: 'deferred', code: 'CONTROL_RELEASED', reason: 'controller_changed',
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it('reports an aborted await distinctly even when control is otherwise available', async () => {
|
|
205
|
+
const scheduler = new ControlScheduler();
|
|
206
|
+
scheduler.registerController(controller('strategy', 'strategy', ['body']));
|
|
207
|
+
const abort = new AbortController();
|
|
208
|
+
abort.abort();
|
|
209
|
+
|
|
210
|
+
await expect(scheduler.awaitControl('strategy', scope, ['body'], {
|
|
211
|
+
signal: abort.signal,
|
|
212
|
+
})).resolves.toMatchObject({
|
|
213
|
+
status: 'deferred', code: 'CONTROL_CANCELLED', retryable: false,
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
describe('ControlScheduler multi-controller allocation', () => {
|
|
219
|
+
it('runs multiple strategies with disjoint domains at the same time', async () => {
|
|
220
|
+
const scheduler = new ControlScheduler();
|
|
221
|
+
scheduler.registerController(controller('navigator', 'strategy', ['body']));
|
|
222
|
+
scheduler.registerController(controller('speaker', 'strategy', ['communication']));
|
|
223
|
+
const moving = deferred<string>();
|
|
224
|
+
|
|
225
|
+
const move = scheduler.runAction({
|
|
226
|
+
controllerId: 'navigator', scope, domains: ['body'], execute: () => moving.promise,
|
|
227
|
+
});
|
|
228
|
+
await expectExecuted(scheduler.runAction({
|
|
229
|
+
controllerId: 'speaker', scope, domains: ['communication'], execute: () => 'speaking',
|
|
230
|
+
}), 'speaking');
|
|
231
|
+
moving.resolve('moved');
|
|
232
|
+
await expectExecuted(move, 'moved');
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it('uses priority then stable registration order for overlapping strategies', async () => {
|
|
236
|
+
const scheduler = new ControlScheduler();
|
|
237
|
+
scheduler.registerController(controller('first', 'strategy', ['body']));
|
|
238
|
+
scheduler.registerController(controller('second', 'strategy', ['body']));
|
|
239
|
+
|
|
240
|
+
await expect(scheduler.runAction({
|
|
241
|
+
controllerId: 'second', scope, domains: ['body'], execute: () => 'blocked',
|
|
242
|
+
})).resolves.toMatchObject({ status: 'deferred', code: 'CONTROL_HELD', blockedBy: ['first'] });
|
|
243
|
+
scheduler.release('first');
|
|
244
|
+
await expectExecuted(scheduler.runAction({
|
|
245
|
+
controllerId: 'second', scope, domains: ['body'], execute: () => 'fallback',
|
|
246
|
+
}), 'fallback');
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it('uses mutex groups when scripts are incompatible despite disjoint domains', async () => {
|
|
250
|
+
const scheduler = new ControlScheduler();
|
|
251
|
+
scheduler.registerController(controller('primary', 'strategy', ['body'], {
|
|
252
|
+
mutexGroups: ['primary-gameplay'],
|
|
253
|
+
}));
|
|
254
|
+
scheduler.registerController(controller('other', 'strategy', ['communication'], {
|
|
255
|
+
mutexGroups: ['primary-gameplay'],
|
|
256
|
+
}));
|
|
257
|
+
|
|
258
|
+
await expect(scheduler.runAction({
|
|
259
|
+
controllerId: 'other', scope, domains: ['communication'], execute: () => 'blocked',
|
|
260
|
+
})).resolves.toMatchObject({ status: 'deferred', code: 'CONTROL_HELD', blockedBy: ['primary'] });
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
it('does not confuse a same-id replacement with the old mutex lifecycle', async () => {
|
|
264
|
+
const scheduler = new ControlScheduler();
|
|
265
|
+
scheduler.registerController(controller('same', 'strategy', ['body'], {
|
|
266
|
+
mutexGroups: ['exclusive'],
|
|
267
|
+
}));
|
|
268
|
+
const oldProvider = deferred<string>();
|
|
269
|
+
const oldRun = scheduler.runAction({
|
|
270
|
+
controllerId: 'same', scope, domains: ['body'], execute: () => oldProvider.promise,
|
|
271
|
+
});
|
|
272
|
+
scheduler.release('same', { reason: 'replaced' });
|
|
273
|
+
scheduler.registerController(controller('same', 'strategy', ['communication'], {
|
|
274
|
+
mutexGroups: ['exclusive'],
|
|
275
|
+
}));
|
|
276
|
+
const replacement = vi.fn(() => 'new');
|
|
277
|
+
|
|
278
|
+
await expect(scheduler.runAction({
|
|
279
|
+
controllerId: 'same', scope, domains: ['communication'], execute: replacement,
|
|
280
|
+
})).resolves.toMatchObject({ status: 'deferred', code: 'CONTROL_BUSY' });
|
|
281
|
+
expect(replacement).not.toHaveBeenCalled();
|
|
282
|
+
oldProvider.resolve('old');
|
|
283
|
+
await expectExecuted(oldRun, 'old');
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
it('does not treat a mutex group as a global lock inside one controller', async () => {
|
|
287
|
+
const scheduler = new ControlScheduler();
|
|
288
|
+
scheduler.registerController(controller('combined', 'strategy', ['body', 'communication'], {
|
|
289
|
+
mutexGroups: ['primary-gameplay'],
|
|
290
|
+
}));
|
|
291
|
+
const moving = deferred<string>();
|
|
292
|
+
const move = scheduler.runAction({
|
|
293
|
+
controllerId: 'combined', scope, domains: ['body'], execute: () => moving.promise,
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
await expectExecuted(scheduler.runAction({
|
|
297
|
+
controllerId: 'combined', scope, domains: ['communication'], execute: () => 'speaking',
|
|
298
|
+
}), 'speaking');
|
|
299
|
+
moving.resolve('moved');
|
|
300
|
+
await expectExecuted(move, 'moved');
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
it('reacquires a full wildcard after a partial release', async () => {
|
|
304
|
+
const scheduler = new ControlScheduler();
|
|
305
|
+
scheduler.registerController(controller('agent', 'agent', ['*']));
|
|
306
|
+
scheduler.touch('agent', { domains: ['*'] });
|
|
307
|
+
await expectExecuted(scheduler.runAction({
|
|
308
|
+
controllerId: 'agent', scope, domains: ['body'], execute: () => 'move',
|
|
309
|
+
}), 'move');
|
|
310
|
+
scheduler.release('agent', { domains: ['body'] });
|
|
311
|
+
expect(scheduler.snapshot().controllers.find((entry) => entry.controllerId === 'agent'))
|
|
312
|
+
.toMatchObject({ excludedDomains: ['body'] });
|
|
313
|
+
|
|
314
|
+
scheduler.touch('agent', { domains: ['*'] });
|
|
315
|
+
await expectExecuted(scheduler.runAction({
|
|
316
|
+
controllerId: 'agent', scope, domains: ['body'], execute: () => 'move-again',
|
|
317
|
+
}), 'move-again');
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
it('treats wildcard as ownership of unknown domains, not a literal domain name', async () => {
|
|
321
|
+
const scheduler = new ControlScheduler();
|
|
322
|
+
scheduler.registerController(controller('system', 'system', ['*']));
|
|
323
|
+
scheduler.registerController(controller('mod', 'strategy', ['future-game-domain']));
|
|
324
|
+
|
|
325
|
+
await expect(scheduler.runAction({
|
|
326
|
+
controllerId: 'mod', scope, domains: ['future-game-domain'], execute: () => 'blocked',
|
|
327
|
+
})).resolves.toMatchObject({ status: 'deferred', code: 'CONTROL_HELD' });
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
it('requires every domain of a multi-domain Action atomically', async () => {
|
|
331
|
+
const scheduler = new ControlScheduler();
|
|
332
|
+
scheduler.registerController(controller('strategy', 'strategy', ['body', 'communication'], {
|
|
333
|
+
holdMode: 'per_resource',
|
|
334
|
+
}));
|
|
335
|
+
scheduler.registerController(controller('agent', 'agent', ['*']));
|
|
336
|
+
await expectExecuted(scheduler.runAction({
|
|
337
|
+
controllerId: 'agent', scope, domains: ['body'], execute: () => 'direct',
|
|
338
|
+
}), 'direct');
|
|
339
|
+
|
|
340
|
+
await expectExecuted(scheduler.runAction({
|
|
341
|
+
controllerId: 'strategy', scope, domains: ['communication'], execute: () => 'talk',
|
|
342
|
+
}), 'talk');
|
|
343
|
+
const provider = vi.fn(() => 'invalid-partial');
|
|
344
|
+
await expect(scheduler.runAction({
|
|
345
|
+
controllerId: 'strategy',
|
|
346
|
+
scope,
|
|
347
|
+
domains: ['body', 'communication'],
|
|
348
|
+
execute: provider,
|
|
349
|
+
})).resolves.toMatchObject({ status: 'deferred', code: 'CONTROL_HELD' });
|
|
350
|
+
expect(provider).not.toHaveBeenCalled();
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
it('allows a no-control Action without creating a claim or provider barrier', async () => {
|
|
354
|
+
const scheduler = new ControlScheduler();
|
|
355
|
+
scheduler.registerController(controller('strategy', 'strategy', ['body']));
|
|
356
|
+
const running = deferred<string>();
|
|
357
|
+
const move = scheduler.runAction({
|
|
358
|
+
controllerId: 'strategy', scope, domains: ['body'], execute: () => running.promise,
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
await expectExecuted(scheduler.runAction({
|
|
362
|
+
controllerId: 'strategy', scope, domains: [], execute: () => 'local-note',
|
|
363
|
+
}), 'local-note');
|
|
364
|
+
expect(scheduler.snapshot().inFlight).toHaveLength(1);
|
|
365
|
+
running.resolve('done');
|
|
366
|
+
await expectExecuted(move, 'done');
|
|
367
|
+
});
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
describe('ControlScheduler provider handoff and shutdown', () => {
|
|
371
|
+
it('waits only at a bounded handoff barrier for an already-submitted lower provider', async () => {
|
|
372
|
+
const clock = new ManualClock();
|
|
373
|
+
const scheduler = new ControlScheduler({ clock, defaultHandoffWaitMs: 100 });
|
|
374
|
+
scheduler.registerController(controller('strategy', 'strategy', ['body']));
|
|
375
|
+
scheduler.registerController(controller('agent', 'agent', ['*']));
|
|
376
|
+
const lower = deferred<string>();
|
|
377
|
+
const lowerRun = scheduler.runAction({
|
|
378
|
+
controllerId: 'strategy', scope, domains: ['body'], execute: () => lower.promise,
|
|
379
|
+
});
|
|
380
|
+
const directProvider = vi.fn(() => 'direct');
|
|
381
|
+
const takeover = scheduler.runAction({
|
|
382
|
+
controllerId: 'agent', scope, domains: ['body'], execute: directProvider,
|
|
383
|
+
});
|
|
384
|
+
expect(directProvider).not.toHaveBeenCalled();
|
|
385
|
+
|
|
386
|
+
lower.resolve('old-finished');
|
|
387
|
+
await expectExecuted(lowerRun, 'old-finished');
|
|
388
|
+
await expectExecuted(takeover, 'direct');
|
|
389
|
+
expect(directProvider).toHaveBeenCalledOnce();
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
it('returns CONTROL_BUSY when the bounded handoff barrier times out', async () => {
|
|
393
|
+
const clock = new ManualClock();
|
|
394
|
+
const scheduler = new ControlScheduler({ clock });
|
|
395
|
+
scheduler.registerController(controller('strategy', 'strategy', ['body']));
|
|
396
|
+
scheduler.registerController(controller('agent', 'agent', ['*']));
|
|
397
|
+
const lower = deferred<string>();
|
|
398
|
+
const lowerRun = scheduler.runAction({
|
|
399
|
+
controllerId: 'strategy', scope, domains: ['body'], execute: () => lower.promise,
|
|
400
|
+
});
|
|
401
|
+
const takeover = scheduler.runAction({
|
|
402
|
+
controllerId: 'agent', scope, domains: ['body'], handoffWaitMs: 10, execute: () => 'direct',
|
|
403
|
+
});
|
|
404
|
+
clock.advance(10);
|
|
405
|
+
|
|
406
|
+
await expect(takeover).resolves.toMatchObject({
|
|
407
|
+
status: 'deferred', code: 'CONTROL_BUSY', reason: 'handoff_timeout',
|
|
408
|
+
});
|
|
409
|
+
lower.resolve('done');
|
|
410
|
+
await expectExecuted(lowerRun, 'done');
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
it('interrupts a long handoff wait immediately when shutdown starts', async () => {
|
|
414
|
+
const clock = new ManualClock();
|
|
415
|
+
const scheduler = new ControlScheduler({ clock });
|
|
416
|
+
scheduler.registerController(controller('strategy', 'strategy', ['body']));
|
|
417
|
+
scheduler.registerController(controller('agent', 'agent', ['*']));
|
|
418
|
+
const lower = deferred<string>();
|
|
419
|
+
const lowerRun = scheduler.runAction({
|
|
420
|
+
controllerId: 'strategy', scope, domains: ['body'], execute: () => lower.promise,
|
|
421
|
+
});
|
|
422
|
+
const takeover = scheduler.runAction({
|
|
423
|
+
controllerId: 'agent', scope, domains: ['body'], handoffWaitMs: 60_000,
|
|
424
|
+
execute: () => 'never',
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
// An unrelated scheduler change must not silently unregister the
|
|
428
|
+
// conditional shutdown/scope waiter.
|
|
429
|
+
scheduler.registerController(controller('speaker', 'strategy', ['communication']));
|
|
430
|
+
scheduler.beginStopping();
|
|
431
|
+
await expect(takeover).resolves.toMatchObject({
|
|
432
|
+
status: 'deferred', code: 'CONTROL_STOPPING', retryable: false,
|
|
433
|
+
});
|
|
434
|
+
lower.resolve('done');
|
|
435
|
+
await expectExecuted(lowerRun, 'done');
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
it('installs the in-flight fence before invoking synchronous provider code', async () => {
|
|
439
|
+
const scheduler = new ControlScheduler();
|
|
440
|
+
scheduler.registerController(controller('strategy', 'strategy', ['body']));
|
|
441
|
+
let nested!: Promise<unknown>;
|
|
442
|
+
const outer = scheduler.runAction({
|
|
443
|
+
controllerId: 'strategy',
|
|
444
|
+
scope,
|
|
445
|
+
domains: ['body'],
|
|
446
|
+
execute: () => {
|
|
447
|
+
nested = scheduler.runAction({
|
|
448
|
+
controllerId: 'strategy', scope, domains: ['body'], execute: () => 'nested',
|
|
449
|
+
});
|
|
450
|
+
return 'outer';
|
|
451
|
+
},
|
|
452
|
+
});
|
|
453
|
+
await expectExecuted(outer, 'outer');
|
|
454
|
+
await expect(nested).resolves.toMatchObject({ status: 'deferred', code: 'CONTROL_BUSY' });
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
it('does not revive an old prepared Action after its domain was released and reacquired', async () => {
|
|
458
|
+
const scheduler = new ControlScheduler();
|
|
459
|
+
scheduler.registerController(controller('agent', 'agent', ['*']));
|
|
460
|
+
const prepared = deferred<void>();
|
|
461
|
+
const run = scheduler.runAction({
|
|
462
|
+
controllerId: 'agent',
|
|
463
|
+
scope,
|
|
464
|
+
domains: ['body'],
|
|
465
|
+
execute: async (context) => {
|
|
466
|
+
await prepared.promise;
|
|
467
|
+
return context.revalidate();
|
|
468
|
+
},
|
|
469
|
+
});
|
|
470
|
+
await Promise.resolve();
|
|
471
|
+
|
|
472
|
+
scheduler.release('agent', { domains: ['body'] });
|
|
473
|
+
scheduler.touch('agent', { domains: ['body'] });
|
|
474
|
+
prepared.resolve();
|
|
475
|
+
|
|
476
|
+
await expect(run).resolves.toMatchObject({
|
|
477
|
+
status: 'executed',
|
|
478
|
+
value: { status: 'deferred', code: 'CONTROL_RELEASED', reason: 'authority_changed' },
|
|
479
|
+
});
|
|
480
|
+
});
|
|
481
|
+
|
|
482
|
+
it('uses old-scope in-flight work as a global segment handoff barrier', async () => {
|
|
483
|
+
const clock = new ManualClock();
|
|
484
|
+
const scheduler = new ControlScheduler({ clock });
|
|
485
|
+
scheduler.registerController(controller('old', 'strategy', ['body']));
|
|
486
|
+
const running = deferred<string>();
|
|
487
|
+
const oldRun = scheduler.runAction({
|
|
488
|
+
controllerId: 'old', scope, domains: ['body'], execute: () => running.promise,
|
|
489
|
+
});
|
|
490
|
+
const nextScope = { ...scope, segmentId: 'round-2' };
|
|
491
|
+
scheduler.activateScope(nextScope);
|
|
492
|
+
scheduler.registerController(controller('new', 'strategy', ['communication'], { scope: nextScope }));
|
|
493
|
+
const nextProvider = vi.fn(() => 'next');
|
|
494
|
+
const nextRun = scheduler.runAction({
|
|
495
|
+
controllerId: 'new', scope: nextScope, domains: ['communication'], execute: nextProvider,
|
|
496
|
+
});
|
|
497
|
+
expect(nextProvider).not.toHaveBeenCalled();
|
|
498
|
+
|
|
499
|
+
running.resolve('old-done');
|
|
500
|
+
await expectExecuted(oldRun, 'old-done');
|
|
501
|
+
await expectExecuted(nextRun, 'next');
|
|
502
|
+
});
|
|
503
|
+
|
|
504
|
+
it('tracks a no-control provider for shutdown drain and scope handoff', async () => {
|
|
505
|
+
const scheduler = new ControlScheduler();
|
|
506
|
+
scheduler.registerController(controller('old', 'strategy', ['body']));
|
|
507
|
+
const running = deferred<string>();
|
|
508
|
+
const oldRun = scheduler.runAction({
|
|
509
|
+
controllerId: 'old', scope, domains: [], execute: () => running.promise,
|
|
510
|
+
});
|
|
511
|
+
expect(scheduler.snapshot().inFlight).toHaveLength(1);
|
|
512
|
+
|
|
513
|
+
const nextScope = { ...scope, segmentId: 'round-2' };
|
|
514
|
+
scheduler.activateScope(nextScope);
|
|
515
|
+
scheduler.registerController(controller('new', 'strategy', ['body'], { scope: nextScope }));
|
|
516
|
+
const nextProvider = vi.fn(() => 'next');
|
|
517
|
+
const nextRun = scheduler.runAction({
|
|
518
|
+
controllerId: 'new', scope: nextScope, domains: [], execute: nextProvider,
|
|
519
|
+
});
|
|
520
|
+
expect(nextProvider).not.toHaveBeenCalled();
|
|
521
|
+
|
|
522
|
+
running.resolve('old-done');
|
|
523
|
+
await expectExecuted(oldRun, 'old-done');
|
|
524
|
+
await expectExecuted(nextRun, 'next');
|
|
525
|
+
});
|
|
526
|
+
|
|
527
|
+
it('revalidates a finite no-control controller after an old-scope wait', async () => {
|
|
528
|
+
const clock = new ManualClock();
|
|
529
|
+
const scheduler = new ControlScheduler({ clock });
|
|
530
|
+
scheduler.registerController(controller('old', 'strategy', ['body']));
|
|
531
|
+
const running = deferred<string>();
|
|
532
|
+
const oldRun = scheduler.runAction({
|
|
533
|
+
controllerId: 'old', scope, domains: ['body'], execute: () => running.promise,
|
|
534
|
+
});
|
|
535
|
+
const nextScope = { ...scope, segmentId: 'round-2' };
|
|
536
|
+
scheduler.activateScope(nextScope);
|
|
537
|
+
scheduler.registerController(controller('task', 'task', ['body'], {
|
|
538
|
+
scope: nextScope,
|
|
539
|
+
maxRuntimeMs: 10,
|
|
540
|
+
}));
|
|
541
|
+
const provider = vi.fn(() => 'stale');
|
|
542
|
+
const taskRun = scheduler.runAction({
|
|
543
|
+
controllerId: 'task', scope: nextScope, domains: [], handoffWaitMs: 100,
|
|
544
|
+
execute: provider,
|
|
545
|
+
});
|
|
546
|
+
|
|
547
|
+
clock.advance(11);
|
|
548
|
+
running.resolve('done');
|
|
549
|
+
await expectExecuted(oldRun, 'done');
|
|
550
|
+
await expect(taskRun).resolves.toMatchObject({
|
|
551
|
+
status: 'deferred', code: 'CONTROL_RELEASED', reason: 'deadline_expired',
|
|
552
|
+
});
|
|
553
|
+
expect(provider).not.toHaveBeenCalled();
|
|
554
|
+
});
|
|
555
|
+
|
|
556
|
+
it('does not let a waiting Action follow a same-id replacement lifecycle', async () => {
|
|
557
|
+
const scheduler = new ControlScheduler();
|
|
558
|
+
scheduler.registerController(controller('strategy', 'strategy', ['body']));
|
|
559
|
+
scheduler.registerController(controller('agent', 'agent', ['*']));
|
|
560
|
+
const lower = deferred<string>();
|
|
561
|
+
const lowerRun = scheduler.runAction({
|
|
562
|
+
controllerId: 'strategy', scope, domains: ['body'], execute: () => lower.promise,
|
|
563
|
+
});
|
|
564
|
+
const takeover = scheduler.runAction({
|
|
565
|
+
controllerId: 'agent', scope, domains: ['body'], execute: () => 'stale',
|
|
566
|
+
});
|
|
567
|
+
scheduler.release('agent', { reason: 'process_exited' });
|
|
568
|
+
scheduler.registerController(controller('agent', 'agent', ['*']));
|
|
569
|
+
lower.resolve('done');
|
|
570
|
+
|
|
571
|
+
await expectExecuted(lowerRun, 'done');
|
|
572
|
+
await expect(takeover).resolves.toMatchObject({
|
|
573
|
+
status: 'deferred', code: 'CONTROL_RELEASED', reason: 'controller_changed', retryable: false,
|
|
574
|
+
});
|
|
575
|
+
});
|
|
576
|
+
|
|
577
|
+
it('awaitControl waits until an already-submitted conflicting provider settles', async () => {
|
|
578
|
+
const scheduler = new ControlScheduler();
|
|
579
|
+
scheduler.registerController(controller('strategy', 'strategy', ['body']));
|
|
580
|
+
scheduler.registerController(controller('agent', 'agent', ['*']));
|
|
581
|
+
const lower = deferred<string>();
|
|
582
|
+
const lowerRun = scheduler.runAction({
|
|
583
|
+
controllerId: 'strategy', scope, domains: ['body'], execute: () => lower.promise,
|
|
584
|
+
});
|
|
585
|
+
scheduler.touch('agent', { domains: ['body'] });
|
|
586
|
+
const waiting = scheduler.awaitControl('agent', scope, ['body']);
|
|
587
|
+
let settled = false;
|
|
588
|
+
void waiting.then(() => { settled = true; });
|
|
589
|
+
await Promise.resolve();
|
|
590
|
+
expect(settled).toBe(false);
|
|
591
|
+
|
|
592
|
+
lower.resolve('done');
|
|
593
|
+
await expectExecuted(lowerRun, 'done');
|
|
594
|
+
await expect(waiting).resolves.toMatchObject({ status: 'granted' });
|
|
595
|
+
});
|
|
596
|
+
|
|
597
|
+
it('revalidates scope after waiting at the provider handoff barrier', async () => {
|
|
598
|
+
const scheduler = new ControlScheduler();
|
|
599
|
+
scheduler.registerController(controller('strategy', 'strategy', ['body']));
|
|
600
|
+
scheduler.registerController(controller('agent', 'agent', ['*']));
|
|
601
|
+
const lower = deferred<string>();
|
|
602
|
+
const lowerRun = scheduler.runAction({
|
|
603
|
+
controllerId: 'strategy', scope, domains: ['body'], execute: () => lower.promise,
|
|
604
|
+
});
|
|
605
|
+
const takeover = scheduler.runAction({
|
|
606
|
+
controllerId: 'agent', scope, domains: ['body'], execute: () => 'stale',
|
|
607
|
+
});
|
|
608
|
+
scheduler.activateScope({ ...scope, segmentId: 'round-2' });
|
|
609
|
+
lower.resolve('done');
|
|
610
|
+
await expectExecuted(lowerRun, 'done');
|
|
611
|
+
await expect(takeover).resolves.toMatchObject({
|
|
612
|
+
status: 'deferred', code: 'CONTROL_SCOPE_CHANGED',
|
|
613
|
+
});
|
|
614
|
+
});
|
|
615
|
+
|
|
616
|
+
it('allows a released logical controller id to start a fresh lifecycle in a new scope', async () => {
|
|
617
|
+
const scheduler = new ControlScheduler();
|
|
618
|
+
scheduler.registerController(controller('stable-id', 'strategy', ['body']));
|
|
619
|
+
const nextScope = { ...scope, segmentId: 'round-2' };
|
|
620
|
+
scheduler.activateScope(nextScope);
|
|
621
|
+
scheduler.registerController(controller('stable-id', 'strategy', ['body'], { scope: nextScope }));
|
|
622
|
+
|
|
623
|
+
await expectExecuted(scheduler.runAction({
|
|
624
|
+
controllerId: 'stable-id', scope: nextScope, domains: ['body'], execute: () => 'new-life',
|
|
625
|
+
}), 'new-life');
|
|
626
|
+
});
|
|
627
|
+
|
|
628
|
+
it('does not retain controller registrations from every completed segment', () => {
|
|
629
|
+
const scheduler = new ControlScheduler();
|
|
630
|
+
scheduler.registerController(controller('round-1', 'strategy', ['body']));
|
|
631
|
+
for (let round = 2; round <= 50; round += 1) {
|
|
632
|
+
const nextScope = { ...scope, segmentId: `round-${round}` };
|
|
633
|
+
scheduler.activateScope(nextScope);
|
|
634
|
+
scheduler.registerController(controller(`round-${round}`, 'strategy', ['body'], {
|
|
635
|
+
scope: nextScope,
|
|
636
|
+
}));
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
expect(scheduler.snapshot().controllers.map((entry) => entry.controllerId))
|
|
640
|
+
.toEqual(['round-50']);
|
|
641
|
+
});
|
|
642
|
+
|
|
643
|
+
it('stops admission while allowing already submitted providers to settle', async () => {
|
|
644
|
+
const scheduler = new ControlScheduler();
|
|
645
|
+
scheduler.registerController(controller('strategy', 'strategy', ['body']));
|
|
646
|
+
const running = deferred<string>();
|
|
647
|
+
const submitted = scheduler.runAction({
|
|
648
|
+
controllerId: 'strategy', scope, domains: ['body'], execute: () => running.promise,
|
|
649
|
+
});
|
|
650
|
+
scheduler.beginStopping();
|
|
651
|
+
|
|
652
|
+
await expect(scheduler.runAction({
|
|
653
|
+
controllerId: 'strategy', scope, domains: [], execute: () => 'new',
|
|
654
|
+
})).resolves.toMatchObject({ status: 'deferred', code: 'CONTROL_STOPPING' });
|
|
655
|
+
const idle = scheduler.waitForIdle();
|
|
656
|
+
running.resolve('settled');
|
|
657
|
+
await expectExecuted(submitted, 'settled');
|
|
658
|
+
await expect(idle).resolves.toBeUndefined();
|
|
659
|
+
});
|
|
660
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compatibility entry point. The implementation is a controller scheduler,
|
|
3
|
+
* not an Action queue; new code may import `ControlScheduler` directly.
|
|
4
|
+
*/
|
|
5
|
+
export {
|
|
6
|
+
ControlScheduler,
|
|
7
|
+
ControlScheduler as ControlCoordinator,
|
|
8
|
+
type ControlSchedulerOptions,
|
|
9
|
+
} from './control/control-scheduler.js';
|
|
10
|
+
export * from './control/types.js';
|
|
11
|
+
export { WILDCARD_DOMAIN } from './control/domain-set.js';
|