@myclaw163/clawclaw-cli 0.6.111 → 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 +24 -7
- 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.ts +2 -9
- package/src/commands/load.test.ts +12 -2
- 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 -83
- package/src/commands/strategy.ts +175 -125
- 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 +111 -101
- 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 -678
- package/src/strategies/loader.ts +0 -212
- package/src/strategies/new-events-backfill.ts +0 -98
- package/src/strategies/paradise-fish.knowledge.md +0 -19
- 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,299 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import type { GameClient } from '../../../../lib/game-client.js';
|
|
3
|
+
import { ApiError } from '../../../../lib/http-transport.js';
|
|
4
|
+
import type { TransportResponse } from '../../../../short-command/transport-response.js';
|
|
5
|
+
import type {
|
|
6
|
+
ActionCaller,
|
|
7
|
+
ActionControlDescriptor,
|
|
8
|
+
ActionExecutionContext,
|
|
9
|
+
ActionResult,
|
|
10
|
+
ScopeRef,
|
|
11
|
+
} from '../../../framework/contracts.js';
|
|
12
|
+
import type {
|
|
13
|
+
RuntimeEpochPlugin,
|
|
14
|
+
RuntimeEpochPluginContext,
|
|
15
|
+
RuntimeEpochPluginInput,
|
|
16
|
+
RuntimeEpochPluginResult,
|
|
17
|
+
} from '../../../framework/plugins/index.js';
|
|
18
|
+
import { isClawclawRuntimeState, type ClawclawRuntimeStage } from '../../runtime-state.js';
|
|
19
|
+
|
|
20
|
+
export const CLAWCLAW_ACTION_PLUGIN_ID = 'clawclaw.action';
|
|
21
|
+
export const CLAWCLAW_ACTION_CAPABILITY = 'clawclaw.action';
|
|
22
|
+
export const CLAWCLAW_AGENT_CONTROL_LEASE_MS = 8_000;
|
|
23
|
+
|
|
24
|
+
export interface ClawclawActionRequest {
|
|
25
|
+
route?: 'auto' | 'game' | 'room_chat';
|
|
26
|
+
action: Record<string, any>;
|
|
27
|
+
audioFile?: { path: string; contentType: string };
|
|
28
|
+
/** Host-only preconditions for an Action proposed by a Strategy epoch. */
|
|
29
|
+
strategyOriginEpochSeq?: number;
|
|
30
|
+
strategyActionSafetyGeneration?: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function describeClawclawActionControl(
|
|
34
|
+
request: ClawclawActionRequest,
|
|
35
|
+
): ActionControlDescriptor {
|
|
36
|
+
const action = typeof request.action?.action === 'string'
|
|
37
|
+
? request.action.action
|
|
38
|
+
: undefined;
|
|
39
|
+
let domains: string[];
|
|
40
|
+
switch (action) {
|
|
41
|
+
case 'move':
|
|
42
|
+
case 'task':
|
|
43
|
+
case 'kill':
|
|
44
|
+
case 'report':
|
|
45
|
+
case 'trigger_alarm':
|
|
46
|
+
domains = ['physical'];
|
|
47
|
+
break;
|
|
48
|
+
case 'speech':
|
|
49
|
+
domains = ['communication'];
|
|
50
|
+
break;
|
|
51
|
+
case 'vote':
|
|
52
|
+
domains = ['meeting_vote'];
|
|
53
|
+
break;
|
|
54
|
+
case 'think':
|
|
55
|
+
domains = [];
|
|
56
|
+
break;
|
|
57
|
+
default:
|
|
58
|
+
domains = ['*'];
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
return { domains, agentLeaseMs: CLAWCLAW_AGENT_CONTROL_LEASE_MS };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function cleanActionResponseValue(value: any): any {
|
|
65
|
+
return value === undefined ? undefined : structuredClone(value);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function backendError(error: unknown): unknown {
|
|
69
|
+
if (error instanceof ApiError) {
|
|
70
|
+
const parsed = error.response?.body.kind === 'json'
|
|
71
|
+
? error.response.body.value
|
|
72
|
+
: (() => { try { return JSON.parse(error.body); } catch { return null; } })();
|
|
73
|
+
return parsed ?? {
|
|
74
|
+
error: { code: `HTTP_${error.status}`, message: error.body },
|
|
75
|
+
http_status: error.status,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
error: {
|
|
80
|
+
code: 'ACTION_REQUEST_FAILED',
|
|
81
|
+
message: error instanceof Error ? error.message : String(error),
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function actionResult(
|
|
87
|
+
scope: ScopeRef,
|
|
88
|
+
actionId: string,
|
|
89
|
+
status: ActionResult['status'],
|
|
90
|
+
value?: unknown,
|
|
91
|
+
error?: unknown,
|
|
92
|
+
metadata: Pick<ActionResult, 'source' | 'actionOutcome'> = {},
|
|
93
|
+
): ActionResult {
|
|
94
|
+
return {
|
|
95
|
+
scope,
|
|
96
|
+
actionId,
|
|
97
|
+
status,
|
|
98
|
+
...metadata,
|
|
99
|
+
...(value === undefined ? {} : { value: cleanActionResponseValue(value) }),
|
|
100
|
+
...(error === undefined ? {} : { error: cleanActionResponseValue(error) }),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function deferredAtCommitBoundary(
|
|
105
|
+
context: ActionExecutionContext,
|
|
106
|
+
): ActionResult | undefined {
|
|
107
|
+
const authority = context.revalidate();
|
|
108
|
+
return authority.status === 'deferred' ? authority.result : undefined;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function acknowledgedActionResult(
|
|
112
|
+
scope: ScopeRef,
|
|
113
|
+
actionId: string,
|
|
114
|
+
response: TransportResponse,
|
|
115
|
+
): ActionResult {
|
|
116
|
+
const root = response.body.kind === 'json'
|
|
117
|
+
&& response.body.value
|
|
118
|
+
&& typeof response.body.value === 'object'
|
|
119
|
+
&& !Array.isArray(response.body.value)
|
|
120
|
+
? response.body.value as Record<string, unknown>
|
|
121
|
+
: null;
|
|
122
|
+
if (!root) {
|
|
123
|
+
return actionResult(scope, actionId, 'failure', undefined, {
|
|
124
|
+
error: {
|
|
125
|
+
code: 'ACTION_PROTOCOL_ERROR',
|
|
126
|
+
message: response.body.kind === 'empty'
|
|
127
|
+
? 'The action endpoint returned an empty response.'
|
|
128
|
+
: 'The action endpoint returned a non-object response.',
|
|
129
|
+
},
|
|
130
|
+
http_status: response.status,
|
|
131
|
+
}, { source: 'protocol', actionOutcome: 'unknown' });
|
|
132
|
+
}
|
|
133
|
+
const rejected = response.status < 200
|
|
134
|
+
|| response.status >= 300
|
|
135
|
+
|| root.success === false
|
|
136
|
+
|| root.ok === false;
|
|
137
|
+
return rejected
|
|
138
|
+
? actionResult(scope, actionId, 'failure', undefined, root, {
|
|
139
|
+
source: 'backend', actionOutcome: 'confirmed',
|
|
140
|
+
})
|
|
141
|
+
: actionResult(scope, actionId, 'success', root, undefined, {
|
|
142
|
+
source: 'backend', actionOutcome: 'confirmed',
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** ClawClaw command provider. Runtime only routes the declared capability. */
|
|
147
|
+
export class ClawclawActionPlugin implements RuntimeEpochPlugin<Record<string, any>> {
|
|
148
|
+
readonly kind = 'epoch' as const;
|
|
149
|
+
readonly id = CLAWCLAW_ACTION_PLUGIN_ID;
|
|
150
|
+
readonly version = '1';
|
|
151
|
+
readonly capabilities = { provides: [CLAWCLAW_ACTION_CAPABILITY] } as const;
|
|
152
|
+
|
|
153
|
+
private unregister?: () => void;
|
|
154
|
+
private stage: ClawclawRuntimeStage = 'matching';
|
|
155
|
+
private connection: 'connected' | 'reconnecting' | 'disconnected' = 'disconnected';
|
|
156
|
+
|
|
157
|
+
constructor(private readonly client: GameClient) {}
|
|
158
|
+
|
|
159
|
+
start(context: RuntimeEpochPluginContext<Record<string, any>>): void {
|
|
160
|
+
if (this.unregister) throw new Error('Clawclaw Action Plugin is already started.');
|
|
161
|
+
this.stage = context.currentSegment().kind === 'room_lobby' ? 'room' : 'matching';
|
|
162
|
+
this.unregister = context.capabilities.provideAction({
|
|
163
|
+
capability: CLAWCLAW_ACTION_CAPABILITY,
|
|
164
|
+
describeControl: describeClawclawActionControl,
|
|
165
|
+
perform: (request, scope, caller, actionContext) => (
|
|
166
|
+
this.perform(request, scope, caller, actionContext)
|
|
167
|
+
),
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
update(input: RuntimeEpochPluginInput<Record<string, any>>): RuntimeEpochPluginResult {
|
|
172
|
+
if (isClawclawRuntimeState(input.epoch.state)) {
|
|
173
|
+
this.stage = input.epoch.state.stage;
|
|
174
|
+
this.connection = input.epoch.state.connection;
|
|
175
|
+
}
|
|
176
|
+
return { outcome: 'noop', reason: 'no_action_request' };
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
stop(): void {
|
|
180
|
+
this.unregister?.();
|
|
181
|
+
this.unregister = undefined;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
private strategySafetyRejection(
|
|
185
|
+
request: ClawclawActionRequest,
|
|
186
|
+
scope: ScopeRef,
|
|
187
|
+
actionId: string,
|
|
188
|
+
caller: ActionCaller,
|
|
189
|
+
context: ActionExecutionContext,
|
|
190
|
+
): ActionResult | undefined {
|
|
191
|
+
if (caller.kind !== 'strategy') return undefined;
|
|
192
|
+
if (
|
|
193
|
+
!Number.isInteger(request.strategyOriginEpochSeq)
|
|
194
|
+
|| request.strategyOriginEpochSeq! <= 0
|
|
195
|
+
|| !Number.isInteger(request.strategyActionSafetyGeneration)
|
|
196
|
+
|| request.strategyActionSafetyGeneration! < 0
|
|
197
|
+
) {
|
|
198
|
+
return actionResult(scope, actionId, 'failure', undefined, {
|
|
199
|
+
error: {
|
|
200
|
+
code: 'STRATEGY_ACTION_PRECONDITION_MISSING',
|
|
201
|
+
message: 'The Strategy Action is missing its Runtime safety precondition.',
|
|
202
|
+
},
|
|
203
|
+
}, { source: 'local', actionOutcome: 'not_submitted' });
|
|
204
|
+
}
|
|
205
|
+
const latest = context.latestAcceptedState();
|
|
206
|
+
const state = latest?.state;
|
|
207
|
+
if (
|
|
208
|
+
latest
|
|
209
|
+
&& latest.epochSeq >= request.strategyOriginEpochSeq!
|
|
210
|
+
&& isClawclawRuntimeState(state)
|
|
211
|
+
&& state.action_safety_generation === request.strategyActionSafetyGeneration
|
|
212
|
+
&& state.connection === 'connected'
|
|
213
|
+
&& state.stage === 'game'
|
|
214
|
+
&& (
|
|
215
|
+
state.game_snapshot.status !== 'fresh'
|
|
216
|
+
|| (
|
|
217
|
+
state.game_snapshot.state.phase === 'wandering'
|
|
218
|
+
&& state.game_snapshot.state.you?.is_alive !== false
|
|
219
|
+
)
|
|
220
|
+
)
|
|
221
|
+
) return undefined;
|
|
222
|
+
return actionResult(scope, actionId, 'failure', undefined, {
|
|
223
|
+
error: {
|
|
224
|
+
code: 'STALE_STRATEGY_ACTION',
|
|
225
|
+
message: 'The Strategy Action was computed before the latest game safety boundary.',
|
|
226
|
+
},
|
|
227
|
+
}, { source: 'local', actionOutcome: 'not_submitted' });
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
private async perform(
|
|
231
|
+
request: ClawclawActionRequest,
|
|
232
|
+
scope: ScopeRef,
|
|
233
|
+
caller: ActionCaller,
|
|
234
|
+
context: ActionExecutionContext,
|
|
235
|
+
): Promise<ActionResult> {
|
|
236
|
+
const actionId = randomUUID();
|
|
237
|
+
let actionEndpointStarted = false;
|
|
238
|
+
try {
|
|
239
|
+
const staleAtStart = this.strategySafetyRejection(request, scope, actionId, caller, context);
|
|
240
|
+
if (staleAtStart) return staleAtStart;
|
|
241
|
+
const action = { ...request.action };
|
|
242
|
+
const route = request.route === 'auto'
|
|
243
|
+
? (this.stage === 'room' && action.action === 'speech' ? 'room_chat' : 'game')
|
|
244
|
+
: request.route ?? 'game';
|
|
245
|
+
if (route === 'game' && this.connection !== 'connected') {
|
|
246
|
+
return actionResult(scope, actionId, 'failure', undefined, {
|
|
247
|
+
error: {
|
|
248
|
+
code: 'GAME_SYNC_NOT_READY',
|
|
249
|
+
message: 'GameSync snapshot/resume has not completed; retry after the next authoritative State.',
|
|
250
|
+
},
|
|
251
|
+
}, { source: 'local', actionOutcome: 'not_submitted' });
|
|
252
|
+
}
|
|
253
|
+
if (request.audioFile) {
|
|
254
|
+
const uploaded = await this.client.uploadAudio(
|
|
255
|
+
request.audioFile.path,
|
|
256
|
+
undefined,
|
|
257
|
+
request.audioFile.contentType,
|
|
258
|
+
);
|
|
259
|
+
action.audio_url = uploaded.audio_url;
|
|
260
|
+
const stale = this.strategySafetyRejection(request, scope, actionId, caller, context);
|
|
261
|
+
if (stale) return stale;
|
|
262
|
+
const deferred = deferredAtCommitBoundary(context);
|
|
263
|
+
if (deferred) return deferred;
|
|
264
|
+
}
|
|
265
|
+
if (route === 'room_chat') {
|
|
266
|
+
if (action.action !== 'speech' || typeof action.text !== 'string') {
|
|
267
|
+
return actionResult(scope, actionId, 'failure', undefined, {
|
|
268
|
+
error: { code: 'INVALID_ROOM_ACTION', message: 'Room chat requires a speech action.' },
|
|
269
|
+
}, { source: 'local', actionOutcome: 'not_submitted' });
|
|
270
|
+
}
|
|
271
|
+
const stale = this.strategySafetyRejection(request, scope, actionId, caller, context);
|
|
272
|
+
if (stale) return stale;
|
|
273
|
+
const deferred = deferredAtCommitBoundary(context);
|
|
274
|
+
if (deferred) return deferred;
|
|
275
|
+
actionEndpointStarted = true;
|
|
276
|
+
return acknowledgedActionResult(
|
|
277
|
+
scope,
|
|
278
|
+
actionId,
|
|
279
|
+
await this.client.chatRoomConfirmed(action.text),
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
const preparedAction = await this.client.prepareActionForConfirmedSubmission(action as any);
|
|
283
|
+
const stale = this.strategySafetyRejection(request, scope, actionId, caller, context);
|
|
284
|
+
if (stale) return stale;
|
|
285
|
+
const deferred = deferredAtCommitBoundary(context);
|
|
286
|
+
if (deferred) return deferred;
|
|
287
|
+
actionEndpointStarted = true;
|
|
288
|
+
const response = await this.client.submitPreparedActionConfirmed(preparedAction);
|
|
289
|
+
return acknowledgedActionResult(scope, actionId, response);
|
|
290
|
+
} catch (error) {
|
|
291
|
+
return actionResult(scope, actionId, 'failure', undefined, backendError(error), {
|
|
292
|
+
source: error instanceof ApiError ? 'backend' : 'transport',
|
|
293
|
+
actionOutcome: actionEndpointStarted
|
|
294
|
+
? (error instanceof ApiError ? 'confirmed' : 'unknown')
|
|
295
|
+
: 'not_submitted',
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './action-plugin.js';
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import type { GameClient } from '../../../lib/game-client.js';
|
|
3
|
+
import type { RuntimeEpochPlugin } from '../../framework/plugins/index.js';
|
|
4
|
+
import { assembleClawclawPlugins } from './assembly.js';
|
|
5
|
+
import { CLAWCLAW_DERIVED_EVENT_PLUGIN_ID } from './derived-event/index.js';
|
|
6
|
+
import { CLAWCLAW_ACTION_PLUGIN_ID } from './action/index.js';
|
|
7
|
+
import { CLAWCLAW_GAME_QUERY_PLUGIN_ID } from './game-query/index.js';
|
|
8
|
+
import { ClawclawMailboxPlugin, CLAWCLAW_MAILBOX_PLUGIN_ID } from './mailbox/index.js';
|
|
9
|
+
import {
|
|
10
|
+
CLAWCLAW_PERCEPTION_PLUGIN_ID,
|
|
11
|
+
ClawclawPerceptionPlugin,
|
|
12
|
+
} from './perception/index.js';
|
|
13
|
+
import {
|
|
14
|
+
CLAWCLAW_STRATEGY_PLUGIN_ID,
|
|
15
|
+
} from './strategy/index.js';
|
|
16
|
+
|
|
17
|
+
const client = {} as GameClient;
|
|
18
|
+
|
|
19
|
+
describe('ClawClaw plugin assembly', () => {
|
|
20
|
+
it('loads one Perception plugin and makes Strategy and Mailbox wait for it', () => {
|
|
21
|
+
const producer: RuntimeEpochPlugin<Record<string, any>> = {
|
|
22
|
+
kind: 'epoch',
|
|
23
|
+
id: 'test.producer',
|
|
24
|
+
version: '1',
|
|
25
|
+
produces: { events: ['strategy_alert'] },
|
|
26
|
+
update: () => ({ outcome: 'noop' }),
|
|
27
|
+
};
|
|
28
|
+
const assembled = assembleClawclawPlugins(client, {
|
|
29
|
+
epochPlugins: [producer],
|
|
30
|
+
perception: { modules: ['visual.visibility', 'visual.motion'] },
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
expect(assembled.plugins.map((plugin) => plugin.id)).toEqual(expect.arrayContaining([
|
|
34
|
+
'test.producer',
|
|
35
|
+
CLAWCLAW_ACTION_PLUGIN_ID,
|
|
36
|
+
CLAWCLAW_DERIVED_EVENT_PLUGIN_ID,
|
|
37
|
+
CLAWCLAW_GAME_QUERY_PLUGIN_ID,
|
|
38
|
+
CLAWCLAW_PERCEPTION_PLUGIN_ID,
|
|
39
|
+
CLAWCLAW_STRATEGY_PLUGIN_ID,
|
|
40
|
+
CLAWCLAW_MAILBOX_PLUGIN_ID,
|
|
41
|
+
]));
|
|
42
|
+
expect(assembled.mailbox.after).toEqual(expect.arrayContaining([
|
|
43
|
+
'test.producer',
|
|
44
|
+
CLAWCLAW_DERIVED_EVENT_PLUGIN_ID,
|
|
45
|
+
CLAWCLAW_PERCEPTION_PLUGIN_ID,
|
|
46
|
+
CLAWCLAW_STRATEGY_PLUGIN_ID,
|
|
47
|
+
]));
|
|
48
|
+
expect(assembled.strategy.after).toEqual(expect.arrayContaining([
|
|
49
|
+
CLAWCLAW_ACTION_PLUGIN_ID,
|
|
50
|
+
CLAWCLAW_DERIVED_EVENT_PLUGIN_ID,
|
|
51
|
+
CLAWCLAW_GAME_QUERY_PLUGIN_ID,
|
|
52
|
+
CLAWCLAW_PERCEPTION_PLUGIN_ID,
|
|
53
|
+
]));
|
|
54
|
+
expect(assembled.strategy.status()).toEqual({
|
|
55
|
+
running: false,
|
|
56
|
+
});
|
|
57
|
+
expect(assembled.perception.moduleDescriptors().map((module) => module.id)).toEqual([
|
|
58
|
+
'visual.motion',
|
|
59
|
+
'visual.visibility',
|
|
60
|
+
]);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('keeps an explicitly configured Mailbox graph', () => {
|
|
64
|
+
const mailbox = new ClawclawMailboxPlugin({ after: [] });
|
|
65
|
+
const assembled = assembleClawclawPlugins(client, { epochPlugins: [mailbox] });
|
|
66
|
+
expect(assembled.mailbox).toBe(mailbox);
|
|
67
|
+
expect(assembled.mailbox.after).toEqual([]);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('keeps an explicitly configured aggregate Perception plugin', () => {
|
|
71
|
+
const perception = new ClawclawPerceptionPlugin({ modules: ['visual.stop'] });
|
|
72
|
+
const assembled = assembleClawclawPlugins(client, {
|
|
73
|
+
epochPlugins: [perception],
|
|
74
|
+
perception: { modules: ['visual.stop'] },
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
expect(assembled.perception).toBe(perception);
|
|
78
|
+
expect(assembled.plugins.filter((plugin) => plugin.id === CLAWCLAW_PERCEPTION_PLUGIN_ID))
|
|
79
|
+
.toEqual([perception]);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import type { RuntimeEpochPlugin } from '../../framework/plugins/index.js';
|
|
2
|
+
import type { GameClient } from '../../../lib/game-client.js';
|
|
3
|
+
import {
|
|
4
|
+
ClawclawActionPlugin,
|
|
5
|
+
CLAWCLAW_ACTION_PLUGIN_ID,
|
|
6
|
+
} from './action/index.js';
|
|
7
|
+
import {
|
|
8
|
+
ClawclawDerivedEventPlugin,
|
|
9
|
+
CLAWCLAW_DERIVED_EVENT_PLUGIN_ID,
|
|
10
|
+
} from './derived-event/index.js';
|
|
11
|
+
import {
|
|
12
|
+
ClawclawGameQueryPlugin,
|
|
13
|
+
CLAWCLAW_GAME_QUERY_PLUGIN_ID,
|
|
14
|
+
} from './game-query/index.js';
|
|
15
|
+
import {
|
|
16
|
+
ClawclawMailboxPlugin,
|
|
17
|
+
CLAWCLAW_MAILBOX_PLUGIN_ID,
|
|
18
|
+
} from './mailbox/index.js';
|
|
19
|
+
import {
|
|
20
|
+
CLAWCLAW_PERCEPTION_PLUGIN_ID,
|
|
21
|
+
ClawclawPerceptionPlugin,
|
|
22
|
+
type ClawclawPerceptionConfig,
|
|
23
|
+
} from './perception/index.js';
|
|
24
|
+
import {
|
|
25
|
+
ClawclawStrategyPlugin,
|
|
26
|
+
CLAWCLAW_STRATEGY_PLUGIN_ID,
|
|
27
|
+
type ClawclawStrategySelection,
|
|
28
|
+
} from './strategy/index.js';
|
|
29
|
+
|
|
30
|
+
export interface ClawclawPluginAssemblyOptions {
|
|
31
|
+
epochPlugins?: readonly RuntimeEpochPlugin<Record<string, any>, Record<string, unknown>>[];
|
|
32
|
+
perception?: ClawclawPerceptionConfig;
|
|
33
|
+
defaultStrategies?: Readonly<Record<string, ClawclawStrategySelection>>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface ClawclawPluginAssembly {
|
|
37
|
+
plugins: RuntimeEpochPlugin<Record<string, any>, Record<string, unknown>>[];
|
|
38
|
+
action: ClawclawActionPlugin;
|
|
39
|
+
gameQuery: ClawclawGameQueryPlugin;
|
|
40
|
+
perception: ClawclawPerceptionPlugin;
|
|
41
|
+
strategy: ClawclawStrategyPlugin;
|
|
42
|
+
mailbox: ClawclawMailboxPlugin;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Builds the official ClawClaw plugin graph without teaching Runtime plugin names. */
|
|
46
|
+
export function assembleClawclawPlugins(
|
|
47
|
+
client: GameClient,
|
|
48
|
+
options: ClawclawPluginAssemblyOptions = {},
|
|
49
|
+
): ClawclawPluginAssembly {
|
|
50
|
+
const plugins = [...(options.epochPlugins ?? [])];
|
|
51
|
+
|
|
52
|
+
const configuredAction = plugins.find((plugin) => plugin.id === CLAWCLAW_ACTION_PLUGIN_ID);
|
|
53
|
+
if (configuredAction && !(configuredAction instanceof ClawclawActionPlugin)) {
|
|
54
|
+
throw new Error(`Runtime Plugin ${CLAWCLAW_ACTION_PLUGIN_ID} is not a ClawclawActionPlugin.`);
|
|
55
|
+
}
|
|
56
|
+
const action = configuredAction as ClawclawActionPlugin | undefined
|
|
57
|
+
?? new ClawclawActionPlugin(client);
|
|
58
|
+
if (!configuredAction) plugins.push(action);
|
|
59
|
+
|
|
60
|
+
if (!plugins.some((plugin) => plugin.id === CLAWCLAW_DERIVED_EVENT_PLUGIN_ID)) {
|
|
61
|
+
plugins.push(new ClawclawDerivedEventPlugin());
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const configuredGameQuery = plugins.find((plugin) => plugin.id === CLAWCLAW_GAME_QUERY_PLUGIN_ID);
|
|
65
|
+
if (configuredGameQuery && !(configuredGameQuery instanceof ClawclawGameQueryPlugin)) {
|
|
66
|
+
throw new Error(`Runtime Plugin ${CLAWCLAW_GAME_QUERY_PLUGIN_ID} is not a ClawclawGameQueryPlugin.`);
|
|
67
|
+
}
|
|
68
|
+
const gameQuery = configuredGameQuery as ClawclawGameQueryPlugin | undefined
|
|
69
|
+
?? new ClawclawGameQueryPlugin();
|
|
70
|
+
if (!configuredGameQuery) plugins.push(gameQuery);
|
|
71
|
+
|
|
72
|
+
const configuredPerception = plugins.find((plugin) => plugin.id === CLAWCLAW_PERCEPTION_PLUGIN_ID);
|
|
73
|
+
if (configuredPerception && !(configuredPerception instanceof ClawclawPerceptionPlugin)) {
|
|
74
|
+
throw new Error(`Runtime Plugin ${CLAWCLAW_PERCEPTION_PLUGIN_ID} is not a ClawclawPerceptionPlugin.`);
|
|
75
|
+
}
|
|
76
|
+
const perception = configuredPerception as ClawclawPerceptionPlugin | undefined
|
|
77
|
+
?? new ClawclawPerceptionPlugin(options.perception);
|
|
78
|
+
if (!configuredPerception) plugins.push(perception);
|
|
79
|
+
|
|
80
|
+
const configuredStrategy = plugins.find((plugin) => plugin.id === CLAWCLAW_STRATEGY_PLUGIN_ID);
|
|
81
|
+
if (configuredStrategy && !(configuredStrategy instanceof ClawclawStrategyPlugin)) {
|
|
82
|
+
throw new Error(`Runtime Plugin ${CLAWCLAW_STRATEGY_PLUGIN_ID} is not a ClawclawStrategyPlugin.`);
|
|
83
|
+
}
|
|
84
|
+
const strategy = configuredStrategy as ClawclawStrategyPlugin | undefined
|
|
85
|
+
?? new ClawclawStrategyPlugin({
|
|
86
|
+
after: [
|
|
87
|
+
CLAWCLAW_ACTION_PLUGIN_ID,
|
|
88
|
+
CLAWCLAW_DERIVED_EVENT_PLUGIN_ID,
|
|
89
|
+
CLAWCLAW_GAME_QUERY_PLUGIN_ID,
|
|
90
|
+
CLAWCLAW_PERCEPTION_PLUGIN_ID,
|
|
91
|
+
],
|
|
92
|
+
defaultSelectionForRole: options.defaultStrategies
|
|
93
|
+
? (role) => {
|
|
94
|
+
const selection = options.defaultStrategies?.[role];
|
|
95
|
+
if (!selection) throw new Error(`No default strategy configured for role '${role}'.`);
|
|
96
|
+
return selection;
|
|
97
|
+
}
|
|
98
|
+
: undefined,
|
|
99
|
+
});
|
|
100
|
+
if (!configuredStrategy) {
|
|
101
|
+
plugins.push(strategy);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const configuredMailbox = plugins.find((plugin) => plugin.id === CLAWCLAW_MAILBOX_PLUGIN_ID);
|
|
105
|
+
if (configuredMailbox && !(configuredMailbox instanceof ClawclawMailboxPlugin)) {
|
|
106
|
+
throw new Error(`Runtime Plugin ${CLAWCLAW_MAILBOX_PLUGIN_ID} is not a ClawclawMailboxPlugin.`);
|
|
107
|
+
}
|
|
108
|
+
const eventProducers = plugins
|
|
109
|
+
.filter((plugin) => plugin.id !== CLAWCLAW_MAILBOX_PLUGIN_ID)
|
|
110
|
+
.filter((plugin) => (plugin.produces?.events?.length ?? 0) > 0)
|
|
111
|
+
.map((plugin) => plugin.id);
|
|
112
|
+
const mailbox = configuredMailbox as ClawclawMailboxPlugin | undefined
|
|
113
|
+
?? new ClawclawMailboxPlugin({ after: eventProducers });
|
|
114
|
+
if (!configuredMailbox) plugins.push(mailbox);
|
|
115
|
+
return { plugins, action, gameQuery, perception, strategy, mailbox };
|
|
116
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { createClawclawEventCatalog } from '../../../clawclaw-event-catalog.js';
|
|
3
|
+
import { MemoryEventRepository } from '../../../framework/events/index.js';
|
|
4
|
+
import { Runtime } from '../../../framework/runtime.js';
|
|
5
|
+
import { MemoryStateHistoryRepository } from '../../../framework/state/index.js';
|
|
6
|
+
import { projectClawclawCurrentState } from '../../runtime-state.js';
|
|
7
|
+
import {
|
|
8
|
+
ClawclawDerivedEventPlugin,
|
|
9
|
+
CLAWCLAW_DERIVED_EVENT_PLUGIN_ID,
|
|
10
|
+
} from './derived-event-plugin.js';
|
|
11
|
+
|
|
12
|
+
function roomState(ready: boolean, roomType = 'casual'): Record<string, any> {
|
|
13
|
+
return {
|
|
14
|
+
schema: 'clawclaw.runtime-state.v1',
|
|
15
|
+
stage: 'room',
|
|
16
|
+
transport: 'room_ws',
|
|
17
|
+
connection: 'connected',
|
|
18
|
+
cause: 'room_update',
|
|
19
|
+
room: {
|
|
20
|
+
phase: 'room_waiting',
|
|
21
|
+
room: {
|
|
22
|
+
room_code: 'R1',
|
|
23
|
+
room_type: roomType,
|
|
24
|
+
status: 'waiting',
|
|
25
|
+
is_owner: true,
|
|
26
|
+
member_count: ready ? 10 : 9,
|
|
27
|
+
ready_to_start: ready,
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
game_snapshot: { status: 'unavailable' },
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function gameState(tick: number, meeting?: Record<string, any>): Record<string, any> {
|
|
35
|
+
return {
|
|
36
|
+
schema: 'clawclaw.runtime-state.v1',
|
|
37
|
+
stage: meeting ? 'meeting' : 'game',
|
|
38
|
+
transport: 'game_ws',
|
|
39
|
+
connection: 'connected',
|
|
40
|
+
cause: 'game_snapshot',
|
|
41
|
+
game_snapshot: {
|
|
42
|
+
status: 'fresh',
|
|
43
|
+
state: {
|
|
44
|
+
tick,
|
|
45
|
+
phase: meeting ? 'meeting' : 'wandering',
|
|
46
|
+
...(meeting ? { meeting } : {}),
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function fixture(kind: 'room' | 'game') {
|
|
53
|
+
const events = new MemoryEventRepository();
|
|
54
|
+
const runtime = new Runtime({
|
|
55
|
+
adapterId: 'clawclaw',
|
|
56
|
+
accountId: `derived-${kind}`,
|
|
57
|
+
eventCatalog: createClawclawEventCatalog(),
|
|
58
|
+
eventRepository: events,
|
|
59
|
+
stateHistoryRepository: new MemoryStateHistoryRepository(),
|
|
60
|
+
currentStateFromRuntimeState: projectClawclawCurrentState,
|
|
61
|
+
runtimeEpochPlugins: [new ClawclawDerivedEventPlugin()],
|
|
62
|
+
initialSegment: { kind, identity: `${kind}-1` },
|
|
63
|
+
});
|
|
64
|
+
await runtime.start();
|
|
65
|
+
let sourceSeq = 0;
|
|
66
|
+
const submit = async (state: Record<string, any>) => {
|
|
67
|
+
sourceSeq += 1;
|
|
68
|
+
await runtime.acceptInputBatch({
|
|
69
|
+
scope: runtime.scope(),
|
|
70
|
+
sourceId: `test.${kind}`,
|
|
71
|
+
connectionId: `${kind}-connection`,
|
|
72
|
+
sourceKey: `${kind}:${sourceSeq}`,
|
|
73
|
+
sourceSeq,
|
|
74
|
+
state,
|
|
75
|
+
events: [],
|
|
76
|
+
completeness: 'complete',
|
|
77
|
+
receivedAt: new Date(sourceSeq * 100).toISOString(),
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
return { runtime, events, submit };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
describe('ClawclawDerivedEventPlugin', () => {
|
|
84
|
+
it('emits room readiness only on a false-to-true transition', async () => {
|
|
85
|
+
const { runtime, events, submit } = await fixture('room');
|
|
86
|
+
await submit(roomState(false, 'training_simulation'));
|
|
87
|
+
await submit(roomState(true, 'training_simulation'));
|
|
88
|
+
await submit(roomState(true, 'training_simulation'));
|
|
89
|
+
await submit(roomState(false));
|
|
90
|
+
await submit(roomState(true));
|
|
91
|
+
await runtime.flush();
|
|
92
|
+
|
|
93
|
+
const ready = events.listCommittedEvents({
|
|
94
|
+
sessionId: runtime.scope().sessionId,
|
|
95
|
+
types: ['room_ready_to_start'],
|
|
96
|
+
order: 'asc',
|
|
97
|
+
});
|
|
98
|
+
expect(ready).toHaveLength(2);
|
|
99
|
+
expect(ready[0]).toMatchObject({
|
|
100
|
+
producer: 'local_synth',
|
|
101
|
+
producerPluginId: CLAWCLAW_DERIVED_EVENT_PLUGIN_ID,
|
|
102
|
+
payload: {
|
|
103
|
+
room_code: 'R1',
|
|
104
|
+
room_type: 'training_simulation',
|
|
105
|
+
member_count: 10,
|
|
106
|
+
ready_to_start: true,
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
await runtime.close();
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('emits each changed meeting projection and infers consecutive rounds', async () => {
|
|
113
|
+
const { runtime, events, submit } = await fixture('game');
|
|
114
|
+
const first = {
|
|
115
|
+
caller: 'P1',
|
|
116
|
+
sub_phase: 'speech',
|
|
117
|
+
current_speaker: 'P2',
|
|
118
|
+
speech_order: ['P2', 'P3'],
|
|
119
|
+
alive_players: ['P1', 'P2', 'P3'],
|
|
120
|
+
};
|
|
121
|
+
await submit(gameState(10, first));
|
|
122
|
+
await submit(gameState(11, first));
|
|
123
|
+
await submit(gameState(12, { ...first, current_speaker: 'P3' }));
|
|
124
|
+
await submit(gameState(20));
|
|
125
|
+
await submit(gameState(30, { ...first, caller: 'P3' }));
|
|
126
|
+
await runtime.flush();
|
|
127
|
+
|
|
128
|
+
const meetingStates = events.listCommittedEvents({
|
|
129
|
+
sessionId: runtime.scope().sessionId,
|
|
130
|
+
types: ['meeting_state'],
|
|
131
|
+
order: 'asc',
|
|
132
|
+
});
|
|
133
|
+
expect(meetingStates.map((event) => event.payload)).toMatchObject([
|
|
134
|
+
{ tick: 10, round: 1, caller: 'P1', current_speaker: 'P2' },
|
|
135
|
+
{ tick: 12, round: 1, caller: 'P1', current_speaker: 'P3' },
|
|
136
|
+
{ tick: 30, round: 2, caller: 'P3', current_speaker: 'P2' },
|
|
137
|
+
]);
|
|
138
|
+
expect(meetingStates.every((event) => (
|
|
139
|
+
event.producerPluginId === CLAWCLAW_DERIVED_EVENT_PLUGIN_ID
|
|
140
|
+
))).toBe(true);
|
|
141
|
+
await runtime.close();
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('does not claim backend-owned terminal or turn Events', () => {
|
|
145
|
+
expect(new ClawclawDerivedEventPlugin().produces.events).toEqual([
|
|
146
|
+
'room_ready_to_start',
|
|
147
|
+
'meeting_state',
|
|
148
|
+
]);
|
|
149
|
+
});
|
|
150
|
+
});
|