@myclaw163/clawclaw-cli 0.6.112 → 0.7.5
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 +26 -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 +121 -65
- 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 +19 -9
- 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/assets/clawclaw-spatial-model.txt +142 -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 +48 -7
- 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 +33 -4
- 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 +196 -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/assets/clawclaw-ascii-map.txt +0 -40
- 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,1008 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { createClawclawEventCatalog } from '../../../clawclaw-event-catalog.js';
|
|
3
|
+
import {
|
|
4
|
+
EventIngress,
|
|
5
|
+
MemoryEventRepository,
|
|
6
|
+
type CanonicalEvent,
|
|
7
|
+
} from '../../../framework/events/index.js';
|
|
8
|
+
import type { RuntimeReadyView } from '../../../framework/runtime.js';
|
|
9
|
+
import { MailboxRelayBroker } from '../../../mailbox-host-relay.js';
|
|
10
|
+
import { ClawclawMailboxService } from './mailbox-service.js';
|
|
11
|
+
|
|
12
|
+
const INTERNAL_EVENTS_FIELDS = ['mode', 'scope', 'state_status', 'backlog', 'delivery', 'counts'] as const;
|
|
13
|
+
|
|
14
|
+
function expectCompactEventsOutput(output: Record<string, unknown>): void {
|
|
15
|
+
for (const field of INTERNAL_EVENTS_FIELDS) expect(output).not.toHaveProperty(field);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function fixture() {
|
|
19
|
+
const repository = new MemoryEventRepository();
|
|
20
|
+
repository.saveSession({
|
|
21
|
+
sessionId: 'session-1',
|
|
22
|
+
adapterId: 'clawclaw',
|
|
23
|
+
accountId: 'account-1',
|
|
24
|
+
status: 'open',
|
|
25
|
+
isCurrent: true,
|
|
26
|
+
openedAt: '2026-07-22T00:00:00.000Z',
|
|
27
|
+
});
|
|
28
|
+
repository.saveSegment({
|
|
29
|
+
segmentId: 'room-1',
|
|
30
|
+
sessionId: 'session-1',
|
|
31
|
+
sequence: 1,
|
|
32
|
+
kind: 'room',
|
|
33
|
+
status: 'open',
|
|
34
|
+
isCurrent: true,
|
|
35
|
+
openedAt: '2026-07-22T00:00:00.000Z',
|
|
36
|
+
});
|
|
37
|
+
const ingress = new EventIngress(repository, createClawclawEventCatalog());
|
|
38
|
+
let nowMs = Date.parse('2026-07-22T00:00:00.000Z');
|
|
39
|
+
let ready = readyView('room-1', 1, 0, { phase: 'room_waiting' });
|
|
40
|
+
const service = new ClawclawMailboxService({
|
|
41
|
+
repository,
|
|
42
|
+
readyView: () => structuredClone(ready),
|
|
43
|
+
now: () => nowMs,
|
|
44
|
+
});
|
|
45
|
+
return {
|
|
46
|
+
repository,
|
|
47
|
+
ingress,
|
|
48
|
+
service,
|
|
49
|
+
setReady: (next: RuntimeReadyView) => { ready = next; },
|
|
50
|
+
setNow: (next: number) => { nowMs = next; },
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function readyView(
|
|
55
|
+
segmentId: string,
|
|
56
|
+
epochSeq: number,
|
|
57
|
+
eventWatermark: number,
|
|
58
|
+
state: Record<string, any>,
|
|
59
|
+
pluginStates: RuntimeReadyView['pluginStates'] = {},
|
|
60
|
+
pluginOutcomes: RuntimeReadyView['pluginOutcomes'] = {},
|
|
61
|
+
): RuntimeReadyView {
|
|
62
|
+
const runtimeScope = {
|
|
63
|
+
adapterId: 'clawclaw',
|
|
64
|
+
accountId: 'account-1',
|
|
65
|
+
sessionId: 'session-1',
|
|
66
|
+
segmentId,
|
|
67
|
+
segmentSeq: segmentId === 'room-1' ? 1 : 2,
|
|
68
|
+
};
|
|
69
|
+
return {
|
|
70
|
+
scope: {
|
|
71
|
+
adapterId: runtimeScope.adapterId,
|
|
72
|
+
sessionId: runtimeScope.sessionId,
|
|
73
|
+
segmentId: runtimeScope.segmentId,
|
|
74
|
+
segmentSeq: runtimeScope.segmentSeq,
|
|
75
|
+
},
|
|
76
|
+
state: {
|
|
77
|
+
state,
|
|
78
|
+
stateStatus: {
|
|
79
|
+
status: 'fresh',
|
|
80
|
+
semantics: 'latest_received',
|
|
81
|
+
source: 'owner_memory',
|
|
82
|
+
scope: runtimeScope,
|
|
83
|
+
connectionId: 'connection-1',
|
|
84
|
+
connectionState: 'connected',
|
|
85
|
+
receivedAtMs: Date.parse('2026-07-22T00:00:00.000Z'),
|
|
86
|
+
ageMs: 0,
|
|
87
|
+
backendTick: Number(state.tick ?? 0),
|
|
88
|
+
reason: null,
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
pluginStates,
|
|
92
|
+
pluginOutcomes,
|
|
93
|
+
events: [],
|
|
94
|
+
throughCommitSeq: eventWatermark,
|
|
95
|
+
frameSeq: epochSeq,
|
|
96
|
+
eventWatermark,
|
|
97
|
+
epochSeq,
|
|
98
|
+
hasMore: false,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async function publish(
|
|
103
|
+
ingress: EventIngress,
|
|
104
|
+
input: {
|
|
105
|
+
eventId: string;
|
|
106
|
+
type: string;
|
|
107
|
+
segmentId: string;
|
|
108
|
+
epochSeq: number;
|
|
109
|
+
payload?: Record<string, unknown>;
|
|
110
|
+
producer?: 'backend_push' | 'local_synth';
|
|
111
|
+
producerPluginId?: string;
|
|
112
|
+
},
|
|
113
|
+
): Promise<CanonicalEvent> {
|
|
114
|
+
return (await ingress.publish({
|
|
115
|
+
epochSeq: input.epochSeq,
|
|
116
|
+
eventId: input.eventId,
|
|
117
|
+
type: input.type,
|
|
118
|
+
producer: input.producer ?? 'backend_push',
|
|
119
|
+
producerPluginId: input.producerPluginId,
|
|
120
|
+
sessionId: 'session-1',
|
|
121
|
+
segmentId: input.segmentId,
|
|
122
|
+
payload: input.payload,
|
|
123
|
+
source: { sourceId: 'game-ws', eventId: `remote:${input.eventId}` },
|
|
124
|
+
})).event;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
describe('ClawClaw Mailbox Event query', () => {
|
|
128
|
+
it('returns only the CCL-owned optional Event hint while delivery stays internal', async () => {
|
|
129
|
+
const { ingress, service, setReady } = fixture();
|
|
130
|
+
const event = await publish(ingress, {
|
|
131
|
+
eventId: 'role-hint',
|
|
132
|
+
type: 'role_assigned',
|
|
133
|
+
segmentId: 'room-1',
|
|
134
|
+
epochSeq: 1,
|
|
135
|
+
payload: {
|
|
136
|
+
role: 'shrimp_generic',
|
|
137
|
+
faction: 'lobster',
|
|
138
|
+
hint: 'backend hint',
|
|
139
|
+
next_step: 'backend next step',
|
|
140
|
+
notice: 'backend notice',
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
setReady(readyView('room-1', 1, event.commitSeq, { phase: 'loading', tick: 0 }));
|
|
144
|
+
|
|
145
|
+
const result = service.prepareEvents({ eventType: 'role_assigned' }).output;
|
|
146
|
+
const presented = result.event as Record<string, unknown>;
|
|
147
|
+
|
|
148
|
+
expect(result).toMatchObject({
|
|
149
|
+
schema: 'ccl.events.v5',
|
|
150
|
+
found: true,
|
|
151
|
+
});
|
|
152
|
+
expectCompactEventsOutput(result);
|
|
153
|
+
expect(presented.hint).toContain('You are shrimp_generic');
|
|
154
|
+
expect(JSON.stringify(result)).not.toContain('backend hint');
|
|
155
|
+
expect(result).not.toHaveProperty('guidance');
|
|
156
|
+
expect(result).not.toHaveProperty('next_step');
|
|
157
|
+
expect(presented).not.toHaveProperty('notice');
|
|
158
|
+
expect(presented).not.toHaveProperty('next_step');
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it('omits hint for room.full and adds it only to the authorized Derived readiness Event', async () => {
|
|
162
|
+
const { ingress, service, setReady } = fixture();
|
|
163
|
+
await publish(ingress, {
|
|
164
|
+
eventId: 'room-full',
|
|
165
|
+
type: 'room.full',
|
|
166
|
+
segmentId: 'room-1',
|
|
167
|
+
epochSeq: 1,
|
|
168
|
+
payload: { room_code: '123456', member_count: 10 },
|
|
169
|
+
});
|
|
170
|
+
const ready = await publish(ingress, {
|
|
171
|
+
eventId: 'room-ready',
|
|
172
|
+
type: 'room_ready_to_start',
|
|
173
|
+
producer: 'local_synth',
|
|
174
|
+
producerPluginId: 'clawclaw.derived-event',
|
|
175
|
+
segmentId: 'room-1',
|
|
176
|
+
epochSeq: 1,
|
|
177
|
+
payload: { room_code: '123456', ready_to_start: true },
|
|
178
|
+
});
|
|
179
|
+
setReady(readyView('room-1', 1, ready.commitSeq, { phase: 'room_waiting' }));
|
|
180
|
+
|
|
181
|
+
const events = service.prepareEvents().output.events as Array<Record<string, unknown>>;
|
|
182
|
+
const full = events.find((event) => event.type === 'room.full');
|
|
183
|
+
const derived = events.find((event) => event.type === 'room_ready_to_start');
|
|
184
|
+
|
|
185
|
+
expect(full).not.toHaveProperty('hint');
|
|
186
|
+
expect(derived?.hint).toContain('you are the owner');
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it('aggregates unread Events across segments and consumes only after ack', async () => {
|
|
190
|
+
const { repository, ingress, service, setReady } = fixture();
|
|
191
|
+
const roomEvent = await publish(ingress, {
|
|
192
|
+
eventId: 'room-chat',
|
|
193
|
+
type: 'room.chat',
|
|
194
|
+
segmentId: 'room-1',
|
|
195
|
+
epochSeq: 1,
|
|
196
|
+
payload: { name: '2号', content: '开局吗' },
|
|
197
|
+
});
|
|
198
|
+
repository.saveSegment({
|
|
199
|
+
segmentId: 'game-1',
|
|
200
|
+
sessionId: 'session-1',
|
|
201
|
+
sequence: 2,
|
|
202
|
+
kind: 'game',
|
|
203
|
+
status: 'open',
|
|
204
|
+
isCurrent: true,
|
|
205
|
+
openedAt: '2026-07-22T00:00:01.000Z',
|
|
206
|
+
});
|
|
207
|
+
const gameEvent = await publish(ingress, {
|
|
208
|
+
eventId: 'role',
|
|
209
|
+
type: 'role_assigned',
|
|
210
|
+
segmentId: 'game-1',
|
|
211
|
+
epochSeq: 2,
|
|
212
|
+
payload: { role: 'shrimp_generic', faction: 'lobster' },
|
|
213
|
+
});
|
|
214
|
+
setReady(readyView('game-1', 2, gameEvent.commitSeq, {
|
|
215
|
+
phase: 'wandering',
|
|
216
|
+
tick: 7,
|
|
217
|
+
you: { name: 'self', seat: 1, alive: true },
|
|
218
|
+
}));
|
|
219
|
+
|
|
220
|
+
const prepared = service.prepareEvents();
|
|
221
|
+
expect(prepared.deliveryToken).toBeTypeOf('string');
|
|
222
|
+
expect((prepared.output.events as Array<Record<string, unknown>>).map((event) => event.type))
|
|
223
|
+
.toEqual(['role_assigned', 'room.chat']);
|
|
224
|
+
expect(prepared.output).toMatchObject({
|
|
225
|
+
state: { phase: 'wandering', tick: 7 },
|
|
226
|
+
});
|
|
227
|
+
expectCompactEventsOutput(prepared.output);
|
|
228
|
+
expect(repository.delivery(roomEvent.eventId, 'local-agent')?.detailState).toBe('deferred');
|
|
229
|
+
expect(repository.delivery(gameEvent.eventId, 'local-agent')?.detailState).toBe('pending');
|
|
230
|
+
|
|
231
|
+
expect(service.ackEvents(prepared.deliveryToken!)).toBe(true);
|
|
232
|
+
expect(repository.delivery(roomEvent.eventId, 'local-agent')?.detailState).toBe('delivered');
|
|
233
|
+
expect(repository.delivery(gameEvent.eventId, 'local-agent')?.detailState).toBe('delivered');
|
|
234
|
+
const empty = service.prepareEvents().output;
|
|
235
|
+
expect(empty).toMatchObject({ events: [] });
|
|
236
|
+
expectCompactEventsOutput(empty);
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it('returns every unread Event in one response without paging', async () => {
|
|
240
|
+
const { ingress, service, setReady } = fixture();
|
|
241
|
+
let watermark = 0;
|
|
242
|
+
for (let index = 0; index < 20; index += 1) {
|
|
243
|
+
const event = await publish(ingress, {
|
|
244
|
+
eventId: `bulk-${index}`,
|
|
245
|
+
type: 'speech',
|
|
246
|
+
segmentId: 'room-1',
|
|
247
|
+
epochSeq: 1,
|
|
248
|
+
payload: { actor_name: `player-${index}`, text: 'x'.repeat(2_000) },
|
|
249
|
+
});
|
|
250
|
+
watermark = event.commitSeq;
|
|
251
|
+
}
|
|
252
|
+
setReady(readyView('room-1', 1, watermark, { phase: 'meeting', tick: 1 }));
|
|
253
|
+
|
|
254
|
+
const prepared = service.prepareEvents();
|
|
255
|
+
|
|
256
|
+
expectCompactEventsOutput(prepared.output);
|
|
257
|
+
expect((prepared.output.events as unknown[])).toHaveLength(20);
|
|
258
|
+
expect(Buffer.byteLength(JSON.stringify(prepared.output), 'utf8')).toBeGreaterThan(24 * 1024);
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it('never exposes or consumes Events beyond the captured Ready View', async () => {
|
|
262
|
+
const { repository, ingress, service, setReady } = fixture();
|
|
263
|
+
const first = await publish(ingress, {
|
|
264
|
+
eventId: 'speech-1',
|
|
265
|
+
type: 'speech',
|
|
266
|
+
segmentId: 'room-1',
|
|
267
|
+
epochSeq: 1,
|
|
268
|
+
payload: { actor_name: '2号', text: '一' },
|
|
269
|
+
});
|
|
270
|
+
const second = await publish(ingress, {
|
|
271
|
+
eventId: 'speech-2',
|
|
272
|
+
type: 'speech',
|
|
273
|
+
segmentId: 'room-1',
|
|
274
|
+
epochSeq: 2,
|
|
275
|
+
payload: { actor_name: '3号', text: '二' },
|
|
276
|
+
});
|
|
277
|
+
setReady(readyView('room-1', 1, first.commitSeq, { phase: 'meeting', tick: 1 }));
|
|
278
|
+
|
|
279
|
+
const prepared = service.prepareEvents();
|
|
280
|
+
const firstEvents = prepared.output.events as Array<Record<string, unknown>>;
|
|
281
|
+
expect(firstEvents.map((event) => event.text)).toEqual([first.payload.text]);
|
|
282
|
+
expect(firstEvents[0]).not.toHaveProperty('event_id');
|
|
283
|
+
expect(firstEvents[0]).not.toHaveProperty('occurred_at');
|
|
284
|
+
expect(firstEvents[0]).not.toHaveProperty('received_at');
|
|
285
|
+
expect(service.releaseEvents(prepared.deliveryToken!)).toBe(true);
|
|
286
|
+
expect(repository.delivery(first.eventId, 'local-agent')?.detailState).toBe('pending');
|
|
287
|
+
expect(repository.delivery(second.eventId, 'local-agent')?.detailState).toBe('pending');
|
|
288
|
+
|
|
289
|
+
setReady(readyView('room-1', 2, second.commitSeq, { phase: 'meeting', tick: 2 }));
|
|
290
|
+
expect((service.prepareEvents().output.events as Array<Record<string, unknown>>)
|
|
291
|
+
.map((event) => event.text)).toEqual([second.payload.text, first.payload.text]);
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
it('uses an explicitly captured boundary after the live view advances', async () => {
|
|
295
|
+
const { ingress, service, setReady } = fixture();
|
|
296
|
+
// A faster upstream plugin may commit a newer epoch before the boundary finishes.
|
|
297
|
+
await publish(ingress, {
|
|
298
|
+
eventId: 'speech-later',
|
|
299
|
+
type: 'speech',
|
|
300
|
+
segmentId: 'room-1',
|
|
301
|
+
epochSeq: 2,
|
|
302
|
+
payload: { actor_name: '3', text: 'after' },
|
|
303
|
+
});
|
|
304
|
+
const first = await publish(ingress, {
|
|
305
|
+
eventId: 'speech-boundary',
|
|
306
|
+
type: 'speech',
|
|
307
|
+
segmentId: 'room-1',
|
|
308
|
+
epochSeq: 1,
|
|
309
|
+
payload: { actor_name: '2', text: 'before' },
|
|
310
|
+
});
|
|
311
|
+
const boundary = readyView('room-1', 1, first.commitSeq, { phase: 'meeting', tick: 1 });
|
|
312
|
+
setReady(readyView('room-1', 2, first.commitSeq, { phase: 'meeting', tick: 2 }));
|
|
313
|
+
|
|
314
|
+
const prepared = service.prepareEvents({}, boundary);
|
|
315
|
+
expect(prepared.output).toMatchObject({ state: { tick: 1 } });
|
|
316
|
+
expect((prepared.output.events as Array<Record<string, unknown>>).map((event) => event.text))
|
|
317
|
+
.toEqual([first.payload.text]);
|
|
318
|
+
expect(service.releaseEvents(prepared.deliveryToken!)).toBe(true);
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
it('waits for the previous prepared delivery before preparing another response', async () => {
|
|
322
|
+
const { ingress, service, setReady } = fixture();
|
|
323
|
+
const event = await publish(ingress, {
|
|
324
|
+
eventId: 'speech-serial',
|
|
325
|
+
type: 'speech',
|
|
326
|
+
segmentId: 'room-1',
|
|
327
|
+
epochSeq: 1,
|
|
328
|
+
payload: { actor_name: '2', text: 'serial' },
|
|
329
|
+
});
|
|
330
|
+
setReady(readyView('room-1', 1, event.commitSeq, { phase: 'meeting', tick: 1 }));
|
|
331
|
+
|
|
332
|
+
const first = service.prepareEvents();
|
|
333
|
+
let secondSettled = false;
|
|
334
|
+
const secondPromise = service.prepareEventsWhenAvailable().finally(() => {
|
|
335
|
+
secondSettled = true;
|
|
336
|
+
});
|
|
337
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
338
|
+
expect(secondSettled).toBe(false);
|
|
339
|
+
expect(service.releaseEvents(first.deliveryToken!)).toBe(true);
|
|
340
|
+
|
|
341
|
+
const second = await secondPromise;
|
|
342
|
+
expect((second.output.events as Array<Record<string, unknown>>).map((item) => item.text))
|
|
343
|
+
.toEqual([event.payload.text]);
|
|
344
|
+
expect(service.releaseEvents(second.deliveryToken!)).toBe(true);
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
it('queries the latest type without changing unread state', async () => {
|
|
348
|
+
const { repository, ingress, service, setReady } = fixture();
|
|
349
|
+
const event = await publish(ingress, {
|
|
350
|
+
eventId: 'role',
|
|
351
|
+
type: 'role_assigned',
|
|
352
|
+
segmentId: 'room-1',
|
|
353
|
+
epochSeq: 1,
|
|
354
|
+
payload: { role: 'shrimp_generic' },
|
|
355
|
+
});
|
|
356
|
+
setReady(readyView('room-1', 1, event.commitSeq, { phase: 'loading', tick: 0 }));
|
|
357
|
+
|
|
358
|
+
const result = service.prepareEvents({ eventType: 'role_assigned' });
|
|
359
|
+
expect(result.deliveryToken).toBeUndefined();
|
|
360
|
+
expect(result.output).toMatchObject({
|
|
361
|
+
found: true,
|
|
362
|
+
event: { type: 'role_assigned', role: 'shrimp_generic' },
|
|
363
|
+
});
|
|
364
|
+
expect(result.output.event).not.toHaveProperty('event_id');
|
|
365
|
+
expect(result.output.event).not.toHaveProperty('occurred_at');
|
|
366
|
+
expect(result.output.event).not.toHaveProperty('received_at');
|
|
367
|
+
expectCompactEventsOutput(result.output);
|
|
368
|
+
expect(repository.delivery(event.eventId, 'local-agent')?.detailState).toBe('pending');
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
it('uses delivery class configuration for Monitor and ccl events independently', async () => {
|
|
372
|
+
const { repository, ingress, service, setReady } = fixture();
|
|
373
|
+
const internal = await publish(ingress, {
|
|
374
|
+
eventId: 'move-1',
|
|
375
|
+
type: 'move',
|
|
376
|
+
segmentId: 'room-1',
|
|
377
|
+
epochSeq: 1,
|
|
378
|
+
payload: { x: 1, y: 2 },
|
|
379
|
+
});
|
|
380
|
+
const eventsOnly = await publish(ingress, {
|
|
381
|
+
eventId: 'visual-1',
|
|
382
|
+
type: 'visual.player_moved',
|
|
383
|
+
producer: 'local_synth',
|
|
384
|
+
segmentId: 'room-1',
|
|
385
|
+
epochSeq: 1,
|
|
386
|
+
payload: {
|
|
387
|
+
player_seat: 2,
|
|
388
|
+
direction: 'right',
|
|
389
|
+
text: '9:41,你从导航仓左上侧移动到2号走廊右下侧。',
|
|
390
|
+
},
|
|
391
|
+
});
|
|
392
|
+
setReady(readyView('room-1', 1, eventsOnly.commitSeq, { phase: 'wandering', tick: 3 }));
|
|
393
|
+
|
|
394
|
+
expect(service.prepareMonitor(true)).toBe(0);
|
|
395
|
+
const prepared = service.prepareEvents();
|
|
396
|
+
expect(prepared.output.events).toEqual([
|
|
397
|
+
'visual.player_moved | 9:41,你从导航仓左上侧移动到2号走廊右下侧。',
|
|
398
|
+
]);
|
|
399
|
+
expect(repository.delivery(internal.eventId, 'local-agent')?.detailState)
|
|
400
|
+
.toBe('not_applicable');
|
|
401
|
+
expect(repository.delivery(eventsOnly.eventId, 'local-agent')?.monitorState)
|
|
402
|
+
.toBe('not_applicable');
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
it('hides task assignment and emits player changes as detailed Events instead of State', async () => {
|
|
406
|
+
const { repository, ingress, service, setReady } = fixture();
|
|
407
|
+
const task = await publish(ingress, {
|
|
408
|
+
eventId: 'task-assigned-1',
|
|
409
|
+
type: 'task_assigned',
|
|
410
|
+
segmentId: 'room-1',
|
|
411
|
+
epochSeq: 1,
|
|
412
|
+
payload: { task_name: '丢垃圾', room: '自助餐厅', x: 321, y: 654 },
|
|
413
|
+
});
|
|
414
|
+
const changed = await publish(ingress, {
|
|
415
|
+
eventId: 'players-changed-1',
|
|
416
|
+
type: 'players_changed',
|
|
417
|
+
producer: 'local_synth',
|
|
418
|
+
segmentId: 'room-1',
|
|
419
|
+
epochSeq: 1,
|
|
420
|
+
payload: {
|
|
421
|
+
tick: 644,
|
|
422
|
+
meeting: true,
|
|
423
|
+
meeting_count: 1,
|
|
424
|
+
changes: [{
|
|
425
|
+
change: 'died',
|
|
426
|
+
name: '陈皮一带四#c7',
|
|
427
|
+
seat: 9,
|
|
428
|
+
cause: 'killed',
|
|
429
|
+
killer: null,
|
|
430
|
+
}],
|
|
431
|
+
players: [{
|
|
432
|
+
name: 'Alpha',
|
|
433
|
+
seat: 2,
|
|
434
|
+
status: 'alive',
|
|
435
|
+
death: null,
|
|
436
|
+
}, {
|
|
437
|
+
name: '陈皮一带四#c7',
|
|
438
|
+
seat: 9,
|
|
439
|
+
status: 'dead',
|
|
440
|
+
death: { cause: 'killed', killer: null },
|
|
441
|
+
}],
|
|
442
|
+
},
|
|
443
|
+
});
|
|
444
|
+
setReady(readyView('room-1', 1, changed.commitSeq, {
|
|
445
|
+
phase: 'meeting',
|
|
446
|
+
tick: 644,
|
|
447
|
+
players: [{ name: '陈皮一带四#c7', seat: 9, status: 'dead' }],
|
|
448
|
+
meeting: { meeting_count: 1 },
|
|
449
|
+
}));
|
|
450
|
+
|
|
451
|
+
const output = service.prepareEvents().output;
|
|
452
|
+
expect(output.state).not.toHaveProperty('players');
|
|
453
|
+
expect(output.events).toEqual([{
|
|
454
|
+
type: 'players_changed',
|
|
455
|
+
tick: 644,
|
|
456
|
+
meeting: true,
|
|
457
|
+
meeting_count: 1,
|
|
458
|
+
changes: [{
|
|
459
|
+
change: 'died',
|
|
460
|
+
name: '陈皮一带四#c7',
|
|
461
|
+
seat: 9,
|
|
462
|
+
cause: 'killed',
|
|
463
|
+
killer: null,
|
|
464
|
+
}],
|
|
465
|
+
players: [{
|
|
466
|
+
name: 'Alpha',
|
|
467
|
+
seat: 2,
|
|
468
|
+
status: 'alive',
|
|
469
|
+
death: null,
|
|
470
|
+
}, {
|
|
471
|
+
name: '陈皮一带四#c7',
|
|
472
|
+
seat: 9,
|
|
473
|
+
status: 'dead',
|
|
474
|
+
death: { cause: 'killed', killer: null },
|
|
475
|
+
}],
|
|
476
|
+
}]);
|
|
477
|
+
expect(repository.delivery(task.eventId, 'local-agent')?.detailState).toBe('not_applicable');
|
|
478
|
+
});
|
|
479
|
+
|
|
480
|
+
it('adds the latest structured Strategy status only to ccl events State', async () => {
|
|
481
|
+
const { ingress, service, setReady } = fixture();
|
|
482
|
+
const event = await publish(ingress, {
|
|
483
|
+
eventId: 'strategy-state-event',
|
|
484
|
+
type: 'speech',
|
|
485
|
+
segmentId: 'room-1',
|
|
486
|
+
epochSeq: 2,
|
|
487
|
+
payload: { actor_name: '2', text: 'status' },
|
|
488
|
+
});
|
|
489
|
+
setReady(readyView('room-1', 2, event.commitSeq, {
|
|
490
|
+
phase: 'wandering',
|
|
491
|
+
tick: 105,
|
|
492
|
+
}, {
|
|
493
|
+
'strategy.status': {
|
|
494
|
+
pluginId: 'clawclaw.strategy',
|
|
495
|
+
topic: 'strategy.status',
|
|
496
|
+
value: {
|
|
497
|
+
strategy: 'runtime-task-demo',
|
|
498
|
+
activity: 'moving',
|
|
499
|
+
summary: 'Going to engine task.',
|
|
500
|
+
room: 'engine',
|
|
501
|
+
task: 'repair',
|
|
502
|
+
parameters: { greeting: 'hello' },
|
|
503
|
+
dataAvailability: { tasks: 'available' },
|
|
504
|
+
},
|
|
505
|
+
updatedEpochSeq: 1,
|
|
506
|
+
updatedDomainTick: 100,
|
|
507
|
+
},
|
|
508
|
+
}, {
|
|
509
|
+
'clawclaw.strategy': {
|
|
510
|
+
pluginId: 'clawclaw.strategy',
|
|
511
|
+
epochSeq: 2,
|
|
512
|
+
domainTick: 105,
|
|
513
|
+
outcome: 'noop',
|
|
514
|
+
reason: 'strategy_update_interval',
|
|
515
|
+
},
|
|
516
|
+
}));
|
|
517
|
+
|
|
518
|
+
expect(service.prepareEvents().output.state).toEqual({
|
|
519
|
+
phase: 'wandering',
|
|
520
|
+
tick: 105,
|
|
521
|
+
you: {},
|
|
522
|
+
game: {},
|
|
523
|
+
strategy: {
|
|
524
|
+
id: 'runtime-task-demo',
|
|
525
|
+
doing: 'Going to engine task.',
|
|
526
|
+
params: { greeting: 'hello' },
|
|
527
|
+
},
|
|
528
|
+
});
|
|
529
|
+
});
|
|
530
|
+
|
|
531
|
+
it('keeps the latest semantic Strategy summary while a fresh State is temporarily unavailable', () => {
|
|
532
|
+
const { service, setReady } = fixture();
|
|
533
|
+
const waitingOutcome: RuntimeReadyView['pluginOutcomes'] = {
|
|
534
|
+
'clawclaw.strategy': {
|
|
535
|
+
pluginId: 'clawclaw.strategy',
|
|
536
|
+
epochSeq: 2,
|
|
537
|
+
domainTick: 105,
|
|
538
|
+
outcome: 'noop',
|
|
539
|
+
reason: 'strategy_waiting_for_current_state',
|
|
540
|
+
},
|
|
541
|
+
};
|
|
542
|
+
|
|
543
|
+
setReady(readyView('room-1', 2, 0, {
|
|
544
|
+
phase: 'wandering',
|
|
545
|
+
tick: 105,
|
|
546
|
+
}, {
|
|
547
|
+
'strategy.status': {
|
|
548
|
+
pluginId: 'clawclaw.strategy',
|
|
549
|
+
topic: 'strategy.status',
|
|
550
|
+
value: {
|
|
551
|
+
strategy: 'task-only',
|
|
552
|
+
summary: '正在前往引擎室执行任务“维修引擎”。',
|
|
553
|
+
},
|
|
554
|
+
updatedEpochSeq: 1,
|
|
555
|
+
updatedDomainTick: 100,
|
|
556
|
+
},
|
|
557
|
+
}, waitingOutcome));
|
|
558
|
+
|
|
559
|
+
expect((service.prepareEvents().output.state as any).strategy).toEqual({
|
|
560
|
+
id: 'task-only',
|
|
561
|
+
doing: '正在前往引擎室执行任务“维修引擎”。',
|
|
562
|
+
issue: 'waiting_for_state',
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
setReady(readyView('room-1', 3, 0, {
|
|
566
|
+
phase: 'wandering',
|
|
567
|
+
tick: 106,
|
|
568
|
+
}, {}, waitingOutcome));
|
|
569
|
+
expect((service.prepareEvents().output.state as any).strategy).toEqual({
|
|
570
|
+
doing: '等待最新游戏状态后继续。',
|
|
571
|
+
issue: 'waiting_for_state',
|
|
572
|
+
});
|
|
573
|
+
});
|
|
574
|
+
|
|
575
|
+
it('keeps authoritative stage and runtime error text ahead of a stale Strategy summary', () => {
|
|
576
|
+
const { service, setReady } = fixture();
|
|
577
|
+
const status: RuntimeReadyView['pluginStates'] = {
|
|
578
|
+
'strategy.status': {
|
|
579
|
+
pluginId: 'clawclaw.strategy',
|
|
580
|
+
topic: 'strategy.status',
|
|
581
|
+
value: {
|
|
582
|
+
strategy: 'task-only',
|
|
583
|
+
summary: '正在前往引擎室执行任务“维修引擎”。',
|
|
584
|
+
},
|
|
585
|
+
updatedEpochSeq: 1,
|
|
586
|
+
updatedDomainTick: 100,
|
|
587
|
+
},
|
|
588
|
+
};
|
|
589
|
+
|
|
590
|
+
setReady(readyView('room-1', 2, 0, {
|
|
591
|
+
phase: 'meeting',
|
|
592
|
+
tick: 105,
|
|
593
|
+
}, status, {
|
|
594
|
+
'clawclaw.strategy': {
|
|
595
|
+
pluginId: 'clawclaw.strategy',
|
|
596
|
+
epochSeq: 2,
|
|
597
|
+
domainTick: 105,
|
|
598
|
+
outcome: 'noop',
|
|
599
|
+
reason: 'strategy_waiting_for_current_state',
|
|
600
|
+
},
|
|
601
|
+
}));
|
|
602
|
+
expect((service.prepareEvents().output.state as any).strategy).toEqual({
|
|
603
|
+
id: 'task-only',
|
|
604
|
+
doing: '会议阶段,自动策略已暂停。',
|
|
605
|
+
issue: 'waiting_for_state',
|
|
606
|
+
});
|
|
607
|
+
|
|
608
|
+
setReady(readyView('room-1', 3, 0, {
|
|
609
|
+
phase: 'wandering',
|
|
610
|
+
tick: 106,
|
|
611
|
+
}, status, {
|
|
612
|
+
'clawclaw.strategy': {
|
|
613
|
+
pluginId: 'clawclaw.strategy',
|
|
614
|
+
epochSeq: 3,
|
|
615
|
+
domainTick: 106,
|
|
616
|
+
outcome: 'failed',
|
|
617
|
+
reason: 'strategy worker exited',
|
|
618
|
+
},
|
|
619
|
+
}));
|
|
620
|
+
expect((service.prepareEvents().output.state as any).strategy).toEqual({
|
|
621
|
+
id: 'task-only',
|
|
622
|
+
doing: '策略执行出错,等待恢复。',
|
|
623
|
+
issue: 'strategy worker exited',
|
|
624
|
+
});
|
|
625
|
+
});
|
|
626
|
+
|
|
627
|
+
it('replaces stale Strategy doing text with the current non-wandering phase', () => {
|
|
628
|
+
const { service, setReady } = fixture();
|
|
629
|
+
const pluginStates: RuntimeReadyView['pluginStates'] = {
|
|
630
|
+
'strategy.status': {
|
|
631
|
+
pluginId: 'clawclaw.strategy',
|
|
632
|
+
topic: 'strategy.status',
|
|
633
|
+
value: {
|
|
634
|
+
strategy: 'task-only',
|
|
635
|
+
activity: 'moving',
|
|
636
|
+
summary: '正在前往引擎室执行任务“维修引擎”。',
|
|
637
|
+
room: '引擎室',
|
|
638
|
+
},
|
|
639
|
+
updatedEpochSeq: 1,
|
|
640
|
+
updatedDomainTick: 100,
|
|
641
|
+
},
|
|
642
|
+
};
|
|
643
|
+
const pluginOutcomes: RuntimeReadyView['pluginOutcomes'] = {
|
|
644
|
+
'clawclaw.strategy': {
|
|
645
|
+
pluginId: 'clawclaw.strategy',
|
|
646
|
+
epochSeq: 2,
|
|
647
|
+
domainTick: 101,
|
|
648
|
+
outcome: 'noop',
|
|
649
|
+
reason: 'strategy_inactive_stage',
|
|
650
|
+
},
|
|
651
|
+
};
|
|
652
|
+
const expected = {
|
|
653
|
+
meeting: '会议阶段,自动策略已暂停。',
|
|
654
|
+
game_over: '本局结束,自动策略已停止。',
|
|
655
|
+
preparing: '等待进入游走阶段。',
|
|
656
|
+
} as const;
|
|
657
|
+
|
|
658
|
+
for (const [phase, doing] of Object.entries(expected)) {
|
|
659
|
+
setReady(readyView('room-1', 2, 0, { phase, tick: 101 }, pluginStates, pluginOutcomes));
|
|
660
|
+
const strategy = (service.prepareEvents().output.state as any).strategy;
|
|
661
|
+
expect(strategy).toEqual({
|
|
662
|
+
id: 'task-only',
|
|
663
|
+
doing,
|
|
664
|
+
issue: 'inactive_stage',
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
});
|
|
668
|
+
|
|
669
|
+
it('uses authoritative death and no-selection state instead of stale Strategy doing text', () => {
|
|
670
|
+
const { service, setReady } = fixture();
|
|
671
|
+
const staleStatus: RuntimeReadyView['pluginStates'] = {
|
|
672
|
+
'strategy.status': {
|
|
673
|
+
pluginId: 'clawclaw.strategy',
|
|
674
|
+
topic: 'strategy.status',
|
|
675
|
+
value: {
|
|
676
|
+
strategy: 'task-only',
|
|
677
|
+
activity: 'moving',
|
|
678
|
+
summary: '正在前往引擎室执行任务“维修引擎”。',
|
|
679
|
+
parameters: { mode: 'fast' },
|
|
680
|
+
},
|
|
681
|
+
updatedEpochSeq: 1,
|
|
682
|
+
updatedDomainTick: 100,
|
|
683
|
+
},
|
|
684
|
+
};
|
|
685
|
+
|
|
686
|
+
setReady(readyView('room-1', 2, 0, {
|
|
687
|
+
phase: 'wandering',
|
|
688
|
+
tick: 101,
|
|
689
|
+
you: {
|
|
690
|
+
player: { seat: 1, name: 'self' },
|
|
691
|
+
is_alive: false,
|
|
692
|
+
},
|
|
693
|
+
}, staleStatus, {
|
|
694
|
+
'clawclaw.strategy': {
|
|
695
|
+
pluginId: 'clawclaw.strategy',
|
|
696
|
+
epochSeq: 2,
|
|
697
|
+
domainTick: 101,
|
|
698
|
+
outcome: 'noop',
|
|
699
|
+
reason: 'strategy_update_interval',
|
|
700
|
+
},
|
|
701
|
+
}));
|
|
702
|
+
expect((service.prepareEvents().output.state as any).strategy).toEqual({
|
|
703
|
+
id: 'task-only',
|
|
704
|
+
doing: '角色已死亡,自动策略已停止。',
|
|
705
|
+
params: { mode: 'fast' },
|
|
706
|
+
});
|
|
707
|
+
|
|
708
|
+
setReady(readyView('room-1', 3, 0, {
|
|
709
|
+
phase: 'wandering',
|
|
710
|
+
tick: 102,
|
|
711
|
+
you: {
|
|
712
|
+
player: { seat: 1, name: 'self' },
|
|
713
|
+
is_alive: true,
|
|
714
|
+
},
|
|
715
|
+
}, staleStatus, {
|
|
716
|
+
'clawclaw.strategy': {
|
|
717
|
+
pluginId: 'clawclaw.strategy',
|
|
718
|
+
epochSeq: 3,
|
|
719
|
+
domainTick: 102,
|
|
720
|
+
outcome: 'noop',
|
|
721
|
+
reason: 'strategy_not_selected',
|
|
722
|
+
},
|
|
723
|
+
}));
|
|
724
|
+
const notSelected = (service.prepareEvents().output.state as any).strategy;
|
|
725
|
+
expect(notSelected).toEqual({
|
|
726
|
+
doing: '尚未选择自动策略。',
|
|
727
|
+
issue: 'not_selected',
|
|
728
|
+
});
|
|
729
|
+
expect(notSelected).not.toHaveProperty('id');
|
|
730
|
+
expect(notSelected).not.toHaveProperty('params');
|
|
731
|
+
});
|
|
732
|
+
|
|
733
|
+
it('keeps only exceptional Strategy availability in ccl events State', () => {
|
|
734
|
+
const { service, setReady } = fixture();
|
|
735
|
+
setReady(readyView('room-1', 3, 0, {
|
|
736
|
+
phase: 'wandering',
|
|
737
|
+
tick: 110,
|
|
738
|
+
}, {
|
|
739
|
+
'strategy.status': {
|
|
740
|
+
pluginId: 'clawclaw.strategy',
|
|
741
|
+
topic: 'strategy.status',
|
|
742
|
+
value: {
|
|
743
|
+
strategy: 'task-only',
|
|
744
|
+
activity: 'waiting',
|
|
745
|
+
summary: 'Waiting for authoritative tasks.',
|
|
746
|
+
parameters: {},
|
|
747
|
+
dataAvailability: { tasks: 'unavailable' },
|
|
748
|
+
},
|
|
749
|
+
updatedEpochSeq: 3,
|
|
750
|
+
updatedDomainTick: 109,
|
|
751
|
+
},
|
|
752
|
+
}));
|
|
753
|
+
|
|
754
|
+
expect(service.prepareEvents().output.state).toMatchObject({
|
|
755
|
+
strategy: {
|
|
756
|
+
id: 'task-only',
|
|
757
|
+
doing: 'Waiting for authoritative tasks.',
|
|
758
|
+
issue: 'tasks_unavailable',
|
|
759
|
+
},
|
|
760
|
+
});
|
|
761
|
+
expect((service.prepareEvents().output.state as any).strategy).not.toHaveProperty('params');
|
|
762
|
+
});
|
|
763
|
+
|
|
764
|
+
it('exposes a Strategy plugin failure without requiring a status value', () => {
|
|
765
|
+
const { service, setReady } = fixture();
|
|
766
|
+
setReady(readyView('room-1', 3, 0, {
|
|
767
|
+
phase: 'wandering',
|
|
768
|
+
tick: 110,
|
|
769
|
+
}, {}, {
|
|
770
|
+
'clawclaw.strategy': {
|
|
771
|
+
pluginId: 'clawclaw.strategy',
|
|
772
|
+
epochSeq: 3,
|
|
773
|
+
domainTick: 110,
|
|
774
|
+
outcome: 'failed',
|
|
775
|
+
reason: 'strategy worker exited',
|
|
776
|
+
},
|
|
777
|
+
}));
|
|
778
|
+
|
|
779
|
+
expect(service.prepareEvents().output.state).toMatchObject({
|
|
780
|
+
strategy: {
|
|
781
|
+
issue: 'strategy worker exited',
|
|
782
|
+
},
|
|
783
|
+
});
|
|
784
|
+
});
|
|
785
|
+
});
|
|
786
|
+
|
|
787
|
+
describe('ClawClaw Mailbox Monitor', () => {
|
|
788
|
+
it('uses the registered short player-change message', async () => {
|
|
789
|
+
const { repository, ingress, service, setReady } = fixture();
|
|
790
|
+
const event = await publish(ingress, {
|
|
791
|
+
eventId: 'players-changed-monitor',
|
|
792
|
+
type: 'players_changed',
|
|
793
|
+
producer: 'local_synth',
|
|
794
|
+
segmentId: 'room-1',
|
|
795
|
+
epochSeq: 1,
|
|
796
|
+
payload: {
|
|
797
|
+
tick: 644,
|
|
798
|
+
meeting: true,
|
|
799
|
+
meeting_count: 1,
|
|
800
|
+
changes: [{
|
|
801
|
+
change: 'died',
|
|
802
|
+
name: '陈皮一带四#c7',
|
|
803
|
+
seat: 9,
|
|
804
|
+
cause: 'killed',
|
|
805
|
+
killer: null,
|
|
806
|
+
}],
|
|
807
|
+
players: [{
|
|
808
|
+
name: '陈皮一带四#c7',
|
|
809
|
+
seat: 9,
|
|
810
|
+
status: 'dead',
|
|
811
|
+
death: { cause: 'killed', killer: null },
|
|
812
|
+
}],
|
|
813
|
+
},
|
|
814
|
+
});
|
|
815
|
+
setReady(readyView('room-1', 1, event.commitSeq, { phase: 'meeting', tick: 644 }));
|
|
816
|
+
|
|
817
|
+
expect(service.prepareMonitor(true)).toBe(1);
|
|
818
|
+
const broker = new MailboxRelayBroker(repository, 'short');
|
|
819
|
+
const claim = broker.handle({
|
|
820
|
+
type: 'mailbox_claim',
|
|
821
|
+
relay_id: 'relay-players-changed',
|
|
822
|
+
mode: 'short',
|
|
823
|
+
});
|
|
824
|
+
const payloads = claim?.claim?.items.map((item: any) => item.payload) ?? [];
|
|
825
|
+
expect(service.composeMonitor(payloads)).toMatchObject({
|
|
826
|
+
events: ['players_changed'],
|
|
827
|
+
messages: [
|
|
828
|
+
't644 players_changed 第1次会议中发现9号陈皮一带四#c7已被击杀,凶手未知。',
|
|
829
|
+
],
|
|
830
|
+
});
|
|
831
|
+
});
|
|
832
|
+
|
|
833
|
+
it('keeps exact training mode while applying room-family terminal guidance', async () => {
|
|
834
|
+
const { repository, ingress, service, setReady } = fixture();
|
|
835
|
+
const event = await publish(ingress, {
|
|
836
|
+
eventId: 'room-game-over',
|
|
837
|
+
type: 'game_over',
|
|
838
|
+
segmentId: 'room-1',
|
|
839
|
+
epochSeq: 1,
|
|
840
|
+
payload: { game_mode: 'training_dummy', winner: 'lobster', reason: 'tasks' },
|
|
841
|
+
});
|
|
842
|
+
setReady(readyView('room-1', 1, event.commitSeq, {
|
|
843
|
+
phase: 'game_over',
|
|
844
|
+
game_mode: 'training_dummy',
|
|
845
|
+
}));
|
|
846
|
+
expect(service.prepareMonitor(true)).toBe(1);
|
|
847
|
+
|
|
848
|
+
const broker = new MailboxRelayBroker(repository, 'short');
|
|
849
|
+
const claim = broker.handle({
|
|
850
|
+
type: 'mailbox_claim',
|
|
851
|
+
relay_id: 'relay-room-game-over',
|
|
852
|
+
mode: 'short',
|
|
853
|
+
});
|
|
854
|
+
const payloads = claim?.claim?.items.map((item: any) => item.payload) ?? [];
|
|
855
|
+
const output = service.composeMonitor(payloads);
|
|
856
|
+
|
|
857
|
+
expect(output).toMatchObject({
|
|
858
|
+
events: ['game_over'],
|
|
859
|
+
game_mode: 'training_dummy',
|
|
860
|
+
messages: [expect.stringContaining('Review the result with the user')],
|
|
861
|
+
});
|
|
862
|
+
expect((output.messages as string[])[0]).toContain('wait for the room lifecycle to resume');
|
|
863
|
+
expect((output.messages as string[])[0]).toContain('do not start normal matchmaking');
|
|
864
|
+
expect(output).not.toHaveProperty('next_step');
|
|
865
|
+
expect(output).not.toHaveProperty('guidance');
|
|
866
|
+
expect(output).not.toHaveProperty('notice');
|
|
867
|
+
});
|
|
868
|
+
|
|
869
|
+
it('projects an unsent old-segment Event after switching within one session', async () => {
|
|
870
|
+
const { repository, ingress, service, setReady } = fixture();
|
|
871
|
+
const event = await publish(ingress, {
|
|
872
|
+
eventId: 'room-before-game',
|
|
873
|
+
type: 'speech',
|
|
874
|
+
segmentId: 'room-1',
|
|
875
|
+
epochSeq: 1,
|
|
876
|
+
payload: { actor_name: '2', text: 'start' },
|
|
877
|
+
});
|
|
878
|
+
setReady(readyView('room-1', 1, event.commitSeq, { phase: 'room_waiting' }));
|
|
879
|
+
|
|
880
|
+
repository.saveSegment({
|
|
881
|
+
segmentId: 'game-1',
|
|
882
|
+
sessionId: 'session-1',
|
|
883
|
+
sequence: 2,
|
|
884
|
+
kind: 'game',
|
|
885
|
+
status: 'open',
|
|
886
|
+
isCurrent: true,
|
|
887
|
+
openedAt: '2026-07-22T00:00:01.000Z',
|
|
888
|
+
});
|
|
889
|
+
setReady(readyView('game-1', 2, event.commitSeq, { phase: 'loading', tick: 0 }));
|
|
890
|
+
expect(service.prepareMonitor(true)).toBe(1);
|
|
891
|
+
|
|
892
|
+
const broker = new MailboxRelayBroker(repository, 'short');
|
|
893
|
+
const claim = broker.handle({
|
|
894
|
+
type: 'mailbox_claim',
|
|
895
|
+
relay_id: 'relay-after-switch',
|
|
896
|
+
mode: 'short',
|
|
897
|
+
});
|
|
898
|
+
expect(claim).toMatchObject({
|
|
899
|
+
scope: { session_id: 'session-1', segment_id: 'room-1' },
|
|
900
|
+
claim: { items: [{ event_id: event.eventId }] },
|
|
901
|
+
});
|
|
902
|
+
broker.handle({
|
|
903
|
+
type: 'mailbox_ack',
|
|
904
|
+
relay_id: 'relay-after-switch',
|
|
905
|
+
mode: 'short',
|
|
906
|
+
claim_token: claim?.claim?.claim_token,
|
|
907
|
+
});
|
|
908
|
+
expect(repository.delivery(event.eventId, 'local-agent')).toMatchObject({
|
|
909
|
+
monitorState: 'notified',
|
|
910
|
+
detailState: 'deferred',
|
|
911
|
+
});
|
|
912
|
+
|
|
913
|
+
const prepared = service.prepareEvents();
|
|
914
|
+
expect((prepared.output.events as Array<Record<string, unknown>>)
|
|
915
|
+
.map((item) => item.text)).toEqual([event.payload.text]);
|
|
916
|
+
});
|
|
917
|
+
|
|
918
|
+
it('delays configured Events, then emits one same-watermark batch', async () => {
|
|
919
|
+
const { repository, ingress, service, setReady, setNow } = fixture();
|
|
920
|
+
const start = Date.parse('2026-07-22T00:00:00.000Z');
|
|
921
|
+
const kill = await publish(ingress, {
|
|
922
|
+
eventId: 'kill-1',
|
|
923
|
+
type: 'kill',
|
|
924
|
+
segmentId: 'room-1',
|
|
925
|
+
epochSeq: 1,
|
|
926
|
+
payload: { killer_name: '2号', target_name: '3号' },
|
|
927
|
+
});
|
|
928
|
+
const speech = await publish(ingress, {
|
|
929
|
+
eventId: 'speech-1',
|
|
930
|
+
type: 'speech',
|
|
931
|
+
segmentId: 'room-1',
|
|
932
|
+
epochSeq: 1,
|
|
933
|
+
payload: { actor_name: '4号', text: '看到了' },
|
|
934
|
+
});
|
|
935
|
+
setReady(readyView('room-1', 1, speech.commitSeq, {
|
|
936
|
+
phase: 'wandering',
|
|
937
|
+
tick: 10,
|
|
938
|
+
you: { name: 'self', alive: true },
|
|
939
|
+
}));
|
|
940
|
+
|
|
941
|
+
setNow(start);
|
|
942
|
+
expect(service.prepareMonitor()).toBe(0);
|
|
943
|
+
setNow(start + 1_999);
|
|
944
|
+
expect(service.prepareMonitor()).toBe(0);
|
|
945
|
+
setNow(start + 2_000);
|
|
946
|
+
expect(service.prepareMonitor()).toBe(2);
|
|
947
|
+
|
|
948
|
+
const broker = new MailboxRelayBroker(repository, 'short');
|
|
949
|
+
const claim = broker.handle({
|
|
950
|
+
type: 'mailbox_claim',
|
|
951
|
+
relay_id: 'relay-1',
|
|
952
|
+
mode: 'short',
|
|
953
|
+
lease_ttl_ms: 10_000,
|
|
954
|
+
});
|
|
955
|
+
const payloads = claim?.claim?.items.map((item: any) => item.payload) ?? [];
|
|
956
|
+
expect(service.composeMonitor(payloads)).toMatchObject({
|
|
957
|
+
events: ['kill', 'speech'],
|
|
958
|
+
state: expect.stringContaining('wandering'),
|
|
959
|
+
messages: expect.arrayContaining([expect.stringContaining('4号')]),
|
|
960
|
+
});
|
|
961
|
+
const ack = broker.handle({
|
|
962
|
+
type: 'mailbox_ack',
|
|
963
|
+
relay_id: 'relay-1',
|
|
964
|
+
mode: 'short',
|
|
965
|
+
claim_token: claim?.claim?.claim_token,
|
|
966
|
+
});
|
|
967
|
+
expect(ack).toMatchObject({ ok: true, result: { status: 'accepted' } });
|
|
968
|
+
expect(repository.delivery(kill.eventId, 'local-agent')).toMatchObject({
|
|
969
|
+
monitorState: 'notified',
|
|
970
|
+
detailState: 'pending',
|
|
971
|
+
});
|
|
972
|
+
});
|
|
973
|
+
|
|
974
|
+
it('does not expand Strategy status in the short Monitor notification', async () => {
|
|
975
|
+
const { repository, ingress, service, setReady } = fixture();
|
|
976
|
+
const event = await publish(ingress, {
|
|
977
|
+
eventId: 'strategy-monitor-hidden',
|
|
978
|
+
type: 'speech',
|
|
979
|
+
segmentId: 'room-1',
|
|
980
|
+
epochSeq: 1,
|
|
981
|
+
payload: { actor_name: '2', text: 'hello' },
|
|
982
|
+
});
|
|
983
|
+
setReady(readyView('room-1', 1, event.commitSeq, {
|
|
984
|
+
phase: 'wandering',
|
|
985
|
+
tick: 10,
|
|
986
|
+
}, {
|
|
987
|
+
'strategy.status': {
|
|
988
|
+
pluginId: 'clawclaw.strategy',
|
|
989
|
+
topic: 'strategy.status',
|
|
990
|
+
value: { activity: 'moving', summary: 'SECRET LONG STRATEGY STATUS' },
|
|
991
|
+
updatedEpochSeq: 1,
|
|
992
|
+
updatedDomainTick: 10,
|
|
993
|
+
},
|
|
994
|
+
}));
|
|
995
|
+
|
|
996
|
+
expect(service.prepareMonitor(true)).toBe(1);
|
|
997
|
+
const broker = new MailboxRelayBroker(repository, 'short');
|
|
998
|
+
const claim = broker.handle({
|
|
999
|
+
type: 'mailbox_claim',
|
|
1000
|
+
relay_id: 'relay-strategy-hidden',
|
|
1001
|
+
mode: 'short',
|
|
1002
|
+
});
|
|
1003
|
+
const payloads = claim?.claim?.items.map((item: any) => item.payload) ?? [];
|
|
1004
|
+
const output = service.composeMonitor(payloads);
|
|
1005
|
+
expect(JSON.stringify(output)).not.toContain('SECRET LONG STRATEGY STATUS');
|
|
1006
|
+
expect(output).not.toHaveProperty('strategy');
|
|
1007
|
+
});
|
|
1008
|
+
});
|