@myclaw163/clawclaw-cli 0.6.112 → 0.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/QUICKSTART.md +46 -0
- package/QUICKSTART_HERMES.md +134 -0
- package/QUICKSTART_OPENCLAW.md +134 -0
- package/QUICKSTART_OTHER.md +134 -0
- package/README.md +23 -398
- package/bin/clawclaw-cli.mjs +9 -1
- package/docs/configuration.md +197 -0
- package/docs/runtime/README.md +52 -0
- package/docs/runtime/agent-notifications.md +55 -0
- package/docs/runtime/components-and-boundaries.md +213 -0
- package/docs/runtime/events-and-state.md +105 -0
- package/docs/runtime/owner-lifecycle-and-observability.md +69 -0
- package/docs/runtime/perception-replay.md +51 -0
- package/docs/runtime/short-commands-and-capabilities.md +55 -0
- package/docs/runtime/strategy-runtime.md +111 -0
- package/docs//350/207/252/345/256/232/344/271/211/346/204/237/347/237/245.md +488 -0
- package/docs//350/207/252/345/256/232/344/271/211/347/255/226/347/225/245.md +395 -0
- package/package.json +25 -8
- package/scripts/check-skill-command-surface.mjs +16 -7
- package/scripts/compare-perception-replays.test.ts +188 -0
- package/scripts/compare-perception-replays.ts +589 -0
- package/scripts/generate-spatial-facts.py +246 -0
- package/scripts/package-readme.mjs +48 -0
- package/scripts/replay-perception.ts +347 -0
- package/scripts/sync-frontend-map.mjs +195 -0
- package/scripts/watch-perception-events.test.ts +43 -0
- package/scripts/watch-perception-events.ts +162 -0
- package/skills/clawclaw/SKILL.md +120 -64
- package/skills/clawclaw/references/CHATTERBOX.md +2 -4
- package/skills/clawclaw/references/CLAUDE-CODE-MONITOR.md +1 -1
- package/skills/clawclaw/references/COMMANDS.md +95 -61
- package/skills/clawclaw/references/GAME-MECHANICS.md +18 -8
- package/skills/clawclaw/references/HUB.md +5 -5
- package/skills/clawclaw/references/STRATEGIES.md +34 -17
- package/skills/clawclaw/references/STREAM.md +82 -46
- package/src/assets/clawclaw-map.json +1692 -0
- package/src/assets/clawclaw-spatial-facts.json +1291 -0
- package/src/cli.ts +21 -47
- package/src/commands/account.test.ts +229 -50
- package/src/commands/account.ts +456 -223
- package/src/commands/communication.test.ts +259 -0
- package/src/commands/communication.ts +391 -0
- package/src/commands/competition.test.ts +116 -0
- package/src/commands/competition.ts +50 -28
- package/src/commands/data.test.ts +57 -1
- package/src/commands/data.ts +79 -4
- package/src/commands/events-canonical-state.test.ts +187 -0
- package/src/commands/events.test.ts +50 -136
- package/src/commands/events.ts +175 -241
- package/src/commands/game/index.test.ts +510 -0
- package/src/commands/game/index.ts +556 -0
- package/src/commands/game-map.test.ts +40 -3
- package/src/commands/hub.test.ts +2 -23
- package/src/commands/hub.ts +4 -16
- package/src/commands/load.test.ts +10 -22
- package/src/commands/load.ts +15 -2
- package/src/commands/peek.ts +2 -3
- package/src/commands/perception.test.ts +46 -0
- package/src/commands/perception.ts +92 -0
- package/src/commands/setup/codex.ts +0 -1
- package/src/commands/strategy.test.ts +139 -102
- package/src/commands/strategy.ts +175 -103
- package/src/commands/upgrade.ts +0 -21
- package/src/lib/auth.test.ts +35 -0
- package/src/lib/auth.ts +45 -6
- package/src/lib/diagnostics-config.test.ts +59 -0
- package/src/lib/diagnostics-config.ts +76 -0
- package/src/lib/game-client.test.ts +166 -0
- package/src/lib/game-client.ts +316 -87
- package/src/lib/game-context.ts +29 -0
- package/src/lib/gameplay-config.test.ts +66 -0
- package/src/lib/gameplay-config.ts +151 -0
- package/src/lib/http-transport.test.ts +63 -0
- package/src/lib/http-transport.ts +76 -10
- package/src/lib/init-command.test.ts +25 -1
- package/src/lib/init-command.ts +66 -1
- package/src/lib/participation-leave.ts +78 -0
- package/src/lib/perception-config.test.ts +138 -0
- package/src/lib/perception-config.ts +101 -0
- package/src/lib/room.test.ts +14 -0
- package/src/lib/room.ts +28 -2
- package/src/lib/server-registry.test.ts +15 -5
- package/src/lib/server-registry.ts +9 -10
- package/src/lib/strategy-export.test.ts +123 -44
- package/src/lib/strategy-export.ts +110 -81
- package/src/lib/user-data.test.ts +2 -0
- package/src/lib/user-data.ts +17 -16
- package/src/pipeline/canonical-event-presentation.test.ts +195 -0
- package/src/pipeline/canonical-event-presentation.ts +71 -0
- package/src/pipeline/event-format.test.ts +357 -59
- package/src/pipeline/event-format.ts +365 -80
- package/src/pipeline/event-hints.test.ts +241 -0
- package/src/pipeline/event-hints.ts +202 -51
- package/src/pipeline/game-sync-event-normalization.test.ts +239 -0
- package/src/pipeline/game-sync-event-normalization.ts +215 -0
- package/src/pipeline/player-projection.test.ts +164 -102
- package/src/pipeline/player-projection.ts +194 -235
- package/src/runtime/canonical-event-emitter.test.ts +70 -0
- package/src/runtime/canonical-event-emitter.ts +78 -0
- package/src/runtime/canonical-monitor.test.ts +575 -0
- package/src/runtime/canonical-monitor.ts +388 -0
- package/src/runtime/clawclaw/agent-event-policy.test.ts +27 -0
- package/src/runtime/clawclaw/agent-event-policy.ts +35 -0
- package/src/runtime/clawclaw/index.ts +4 -0
- package/src/runtime/clawclaw/notifications.test.ts +47 -0
- package/src/runtime/clawclaw/notifications.ts +65 -0
- package/src/runtime/clawclaw/owner-lock.test.ts +221 -0
- package/src/runtime/clawclaw/owner.ts +945 -0
- package/src/runtime/clawclaw/plugins/action/action-plugin.ts +299 -0
- package/src/runtime/clawclaw/plugins/action/index.ts +1 -0
- package/src/runtime/clawclaw/plugins/assembly.test.ts +81 -0
- package/src/runtime/clawclaw/plugins/assembly.ts +116 -0
- package/src/runtime/clawclaw/plugins/derived-event/derived-event-plugin.test.ts +150 -0
- package/src/runtime/clawclaw/plugins/derived-event/derived-event-plugin.ts +100 -0
- package/src/runtime/clawclaw/plugins/derived-event/derived-event-rules.ts +162 -0
- package/src/runtime/clawclaw/plugins/derived-event/index.ts +2 -0
- package/src/runtime/clawclaw/plugins/game-query/game-query-plugin.test.ts +223 -0
- package/src/runtime/clawclaw/plugins/game-query/game-query-plugin.ts +236 -0
- package/src/runtime/clawclaw/plugins/game-query/index.ts +1 -0
- package/src/runtime/clawclaw/plugins/index.ts +7 -0
- package/src/runtime/clawclaw/plugins/mailbox/index.ts +3 -0
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-plugin.ts +77 -0
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-presentation.ts +91 -0
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.test.ts +1008 -0
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.ts +475 -0
- package/src/runtime/clawclaw/plugins/perception/contracts.ts +32 -0
- package/src/runtime/clawclaw/plugins/perception/index.ts +8 -0
- package/src/runtime/clawclaw/plugins/perception/module-runner.test.ts +204 -0
- package/src/runtime/clawclaw/plugins/perception/module-runner.ts +290 -0
- package/src/runtime/clawclaw/plugins/perception/modules/co-movement-module.ts +324 -0
- package/src/runtime/clawclaw/plugins/perception/modules/follow-module.ts +365 -0
- package/src/runtime/clawclaw/plugins/perception/modules/index.ts +7 -0
- package/src/runtime/clawclaw/plugins/perception/modules/motion-module.test.ts +341 -0
- package/src/runtime/clawclaw/plugins/perception/modules/motion-module.ts +447 -0
- package/src/runtime/clawclaw/plugins/perception/modules/parallel-module-test-helpers.ts +30 -0
- package/src/runtime/clawclaw/plugins/perception/modules/relation-stability.test.ts +289 -0
- package/src/runtime/clawclaw/plugins/perception/modules/route-module.test.ts +180 -0
- package/src/runtime/clawclaw/plugins/perception/modules/route-module.ts +329 -0
- package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.test.ts +82 -0
- package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.ts +172 -0
- package/src/runtime/clawclaw/plugins/perception/modules/stop-module.test.ts +212 -0
- package/src/runtime/clawclaw/plugins/perception/modules/stop-module.ts +256 -0
- package/src/runtime/clawclaw/plugins/perception/modules/temporal-evidence.test.ts +121 -0
- package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.test.ts +106 -0
- package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.ts +225 -0
- package/src/runtime/clawclaw/plugins/perception/official-module-ids.ts +11 -0
- package/src/runtime/clawclaw/plugins/perception/official-modules.ts +31 -0
- package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-pool.test.ts +759 -0
- package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-pool.ts +707 -0
- package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-worker.ts +215 -0
- package/src/runtime/clawclaw/plugins/perception/perception-module-loader.ts +61 -0
- package/src/runtime/clawclaw/plugins/perception/perception-plugin.test.ts +1516 -0
- package/src/runtime/clawclaw/plugins/perception/perception-plugin.ts +1529 -0
- package/src/runtime/clawclaw/plugins/perception/perception-source.test.ts +119 -0
- package/src/runtime/clawclaw/plugins/perception/perception-source.ts +244 -0
- package/src/runtime/clawclaw/plugins/perception/replay.test.ts +65 -0
- package/src/runtime/clawclaw/plugins/perception/replay.ts +86 -0
- package/src/runtime/clawclaw/plugins/perception/shared/math.ts +107 -0
- package/src/runtime/clawclaw/plugins/perception/spatial-facts.ts +114 -0
- package/src/runtime/clawclaw/plugins/perception/visual-state-projector.ts +98 -0
- package/src/runtime/clawclaw/plugins/runtime-plugins.test.ts +1019 -0
- package/src/runtime/clawclaw/plugins/source/game-transport.test.ts +287 -0
- package/src/runtime/clawclaw/plugins/source/game-transport.ts +281 -0
- package/src/runtime/clawclaw/plugins/source/index.ts +5 -0
- package/src/runtime/clawclaw/plugins/source/player-change-tracker.test.ts +270 -0
- package/src/runtime/clawclaw/plugins/source/player-change-tracker.ts +151 -0
- package/src/runtime/clawclaw/plugins/source/room-transport.test.ts +307 -0
- package/src/runtime/clawclaw/plugins/source/room-transport.ts +480 -0
- package/src/runtime/clawclaw/plugins/source/source-plugin.test.ts +1909 -0
- package/src/runtime/clawclaw/plugins/source/source-plugin.ts +2055 -0
- package/src/runtime/clawclaw/plugins/source/source-transports.ts +30 -0
- package/src/runtime/clawclaw/plugins/source/types.ts +79 -0
- package/src/runtime/clawclaw/plugins/strategy/context-capabilities.ts +5 -0
- package/src/runtime/clawclaw/plugins/strategy/examples/task-only-strategy.test.ts +177 -0
- package/src/runtime/clawclaw/plugins/strategy/examples/task-only-strategy.ts +185 -0
- package/src/runtime/clawclaw/plugins/strategy/index.ts +8 -0
- package/src/runtime/clawclaw/plugins/strategy/local-strategy-executor.ts +412 -0
- package/src/runtime/clawclaw/plugins/strategy/strategy-action.ts +73 -0
- package/src/runtime/clawclaw/plugins/strategy/strategy-analysis-thread-host.ts +183 -0
- package/src/runtime/clawclaw/plugins/strategy/strategy-executor-types.ts +25 -0
- package/src/runtime/clawclaw/plugins/strategy/strategy-executor.test.ts +693 -0
- package/src/runtime/clawclaw/plugins/strategy/strategy-game-api.ts +57 -0
- package/src/runtime/clawclaw/plugins/strategy/strategy-module-loader.ts +164 -0
- package/src/runtime/clawclaw/plugins/strategy/strategy-plugin.test.ts +1936 -0
- package/src/runtime/clawclaw/plugins/strategy/strategy-plugin.ts +1557 -0
- package/src/runtime/clawclaw/plugins/strategy/strategy-source.test.ts +131 -0
- package/src/runtime/clawclaw/plugins/strategy/strategy-source.ts +413 -0
- package/src/runtime/clawclaw/plugins/strategy/thread-strategy-executor.ts +792 -0
- package/src/runtime/clawclaw/runtime-data-export.test.ts +249 -0
- package/src/runtime/clawclaw/runtime-data-export.ts +402 -0
- package/src/runtime/clawclaw/runtime-state.ts +98 -0
- package/src/runtime/clawclaw/runtime.ts +133 -0
- package/src/runtime/clawclaw-event-catalog.test.ts +74 -0
- package/src/runtime/clawclaw-event-catalog.ts +266 -0
- package/src/runtime/clawclaw-position.ts +4 -0
- package/src/runtime/clawclaw-room-state.ts +51 -0
- package/src/runtime/framework/action-diagnostics.test.ts +81 -0
- package/src/runtime/framework/action-diagnostics.ts +146 -0
- package/src/runtime/framework/capability-registry.test.ts +282 -0
- package/src/runtime/framework/capability-registry.ts +283 -0
- package/src/runtime/framework/contracts.ts +118 -0
- package/src/runtime/framework/control/control-scheduler.ts +1260 -0
- package/src/runtime/framework/control/domain-set.ts +81 -0
- package/src/runtime/framework/control/index.ts +3 -0
- package/src/runtime/framework/control/types.ts +184 -0
- package/src/runtime/framework/control-coordinator.test.ts +660 -0
- package/src/runtime/framework/control-coordinator.ts +11 -0
- package/src/runtime/framework/events/event-catalog.ts +74 -0
- package/src/runtime/framework/events/event-delivery-service.test.ts +84 -0
- package/src/runtime/framework/events/event-delivery-service.ts +198 -0
- package/src/runtime/framework/events/event-ingress.test.ts +178 -0
- package/src/runtime/framework/events/event-ingress.ts +97 -0
- package/src/runtime/framework/events/event-repository.ts +59 -0
- package/src/runtime/framework/events/index.ts +7 -0
- package/src/runtime/framework/events/mailbox-event-repositories.test.ts +594 -0
- package/src/runtime/framework/events/memory-event-repository.ts +928 -0
- package/src/runtime/framework/events/sqlite-event-repository.test.ts +200 -0
- package/src/runtime/framework/events/sqlite-event-repository.ts +1681 -0
- package/src/runtime/framework/events/test-helpers.ts +78 -0
- package/src/runtime/framework/events/types.ts +286 -0
- package/src/runtime/framework/index.ts +7 -0
- package/src/runtime/framework/load-node-sqlite.ts +17 -0
- package/src/runtime/framework/mailbox/coalescer.test.ts +55 -0
- package/src/runtime/framework/mailbox/coalescer.ts +83 -0
- package/src/runtime/framework/mailbox/host-notification-sink.ts +44 -0
- package/src/runtime/framework/mailbox/identity.test.ts +38 -0
- package/src/runtime/framework/mailbox/identity.ts +38 -0
- package/src/runtime/framework/mailbox/index.ts +7 -0
- package/src/runtime/framework/mailbox/mailbox-dispatcher.test.ts +513 -0
- package/src/runtime/framework/mailbox/mailbox-dispatcher.ts +282 -0
- package/src/runtime/framework/mailbox/mailbox-repository.ts +44 -0
- package/src/runtime/framework/mailbox/notification-projector.test.ts +77 -0
- package/src/runtime/framework/mailbox/notification-projector.ts +65 -0
- package/src/runtime/framework/mailbox/types.ts +139 -0
- package/src/runtime/framework/modules/runtime-module-loader-hooks.d.mts +19 -0
- package/src/runtime/framework/modules/runtime-module-loader-hooks.mjs +117 -0
- package/src/runtime/framework/modules/runtime-module-loader.test.ts +209 -0
- package/src/runtime/framework/modules/runtime-module-loader.ts +71 -0
- package/src/runtime/framework/modules/runtime-module-worker-bootstrap.mjs +23 -0
- package/src/runtime/framework/participation-manager.test.ts +108 -0
- package/src/runtime/framework/participation-manager.ts +244 -0
- package/src/runtime/framework/plugins/contracts.ts +382 -0
- package/src/runtime/framework/plugins/index.ts +4 -0
- package/src/runtime/framework/plugins/runtime-event-identity.ts +17 -0
- package/src/runtime/framework/plugins/runtime-input-journal.test.ts +179 -0
- package/src/runtime/framework/plugins/runtime-input-journal.ts +693 -0
- package/src/runtime/framework/plugins/runtime-plugin-scheduler.test.ts +1994 -0
- package/src/runtime/framework/plugins/runtime-plugin-scheduler.ts +1860 -0
- package/src/runtime/framework/runtime.ts +1756 -0
- package/src/runtime/framework/serial-task-queue.ts +14 -0
- package/src/runtime/framework/state/contracts.ts +49 -0
- package/src/runtime/framework/state/current-state-store.ts +184 -0
- package/src/runtime/framework/state/durable-agent-state-snapshot.test.ts +144 -0
- package/src/runtime/framework/state/durable-agent-state-snapshot.ts +209 -0
- package/src/runtime/framework/state/freshness.ts +72 -0
- package/src/runtime/framework/state/history/contracts.ts +150 -0
- package/src/runtime/framework/state/history/history-writer.ts +194 -0
- package/src/runtime/framework/state/history/memory-state-history-repository.ts +178 -0
- package/src/runtime/framework/state/history/sqlite-state-history-repository.test.ts +157 -0
- package/src/runtime/framework/state/history/sqlite-state-history-repository.ts +629 -0
- package/src/runtime/framework/state/history/state-history.test.ts +251 -0
- package/src/runtime/framework/state/history/trajectory-projector.ts +209 -0
- package/src/runtime/framework/state/index.ts +13 -0
- package/src/runtime/framework/state/state-core.test.ts +197 -0
- package/src/runtime/framework/state/state-ingress.ts +95 -0
- package/src/runtime/framework/state/state-provider.ts +62 -0
- package/src/runtime/framework/state/types.ts +155 -0
- package/src/runtime/game-sync-protocol.test.ts +123 -0
- package/src/runtime/game-sync-protocol.ts +261 -0
- package/src/runtime/mailbox-host-relay.test.ts +248 -0
- package/src/runtime/mailbox-host-relay.ts +300 -0
- package/src/runtime/observability/factory.ts +188 -0
- package/src/runtime/observability/index.ts +6 -0
- package/src/runtime/observability/observability.test.ts +561 -0
- package/src/runtime/observability/recorder.ts +209 -0
- package/src/runtime/observability/redaction.ts +154 -0
- package/src/runtime/observability/reporter.ts +154 -0
- package/src/runtime/observability/sinks.ts +135 -0
- package/src/runtime/observability/types.ts +92 -0
- package/src/runtime/owner-control.test.ts +153 -0
- package/src/runtime/owner-control.ts +206 -42
- package/src/runtime/parent-process-watch.test.ts +27 -0
- package/src/runtime/parent-process-watch.ts +51 -0
- package/src/runtime/pending-event-handoff.test.ts +29 -0
- package/src/runtime/pending-event-handoff.ts +61 -0
- package/src/runtime/raw-ws-log.test.ts +86 -17
- package/src/runtime/raw-ws-log.ts +230 -21
- package/src/runtime/runtime-logger.test.ts +58 -0
- package/src/runtime/runtime-logger.ts +10 -13
- package/src/runtime/runtime-persistence.test.ts +26 -0
- package/src/runtime/runtime.test.ts +1704 -0
- package/src/runtime/ws-client.test.ts +496 -103
- package/src/runtime/ws-client.ts +546 -166
- package/src/sdk/action.ts +3 -1
- package/src/sdk/index.ts +4 -19
- package/src/sdk/perception-plugin/index.test.ts +22 -0
- package/src/sdk/perception-plugin/index.ts +285 -0
- package/src/sdk/strategy-plugin/index.test.ts +952 -0
- package/src/sdk/strategy-plugin/index.ts +1324 -0
- package/src/sdk/types.ts +3 -1
- package/src/short-command/classifier.test.ts +107 -0
- package/src/short-command/classifier.ts +169 -0
- package/src/short-command/index.ts +7 -0
- package/src/short-command/presenter.test.ts +119 -0
- package/src/short-command/presenter.ts +308 -0
- package/src/short-command/process-io.ts +13 -0
- package/src/short-command/response-contract.ts +58 -0
- package/src/short-command/runner.test.ts +78 -0
- package/src/short-command/runner.ts +164 -0
- package/src/short-command/sensitive-data-filter.test.ts +56 -0
- package/src/short-command/sensitive-data-filter.ts +123 -0
- package/src/short-command/transport-response.test.ts +39 -0
- package/src/short-command/transport-response.ts +89 -0
- package/src/short-command/types.ts +92 -0
- package/src/strategies/avoid-lone.ts +18 -11
- package/src/strategies/avoid-players.ts +29 -13
- package/src/strategies/corpse-patrol.ts +29 -11
- package/src/strategies/crab-sabotage.ts +31 -18
- package/src/strategies/custom-module.test.ts +3 -5
- package/src/strategies/find-player.ts +34 -15
- package/src/strategies/game-utils.test.ts +42 -0
- package/src/strategies/game-utils.ts +143 -53
- package/src/strategies/goals/avoid-lone-top.ts +22 -1
- package/src/strategies/goals/avoid-players-top.test.ts +13 -0
- package/src/strategies/goals/avoid-players-top.ts +6 -5
- package/src/strategies/goals/corpse-patrol-top.ts +9 -2
- package/src/strategies/goals/crab-octopus-reflexes.ts +6 -2
- package/src/strategies/goals/crab-sabotage-top.ts +7 -1
- package/src/strategies/goals/emergency-hunt-goal.ts +15 -3
- package/src/strategies/goals/find-player-top.ts +47 -3
- package/src/strategies/goals/flee-players-goal.ts +2 -0
- package/src/strategies/goals/follow-companion-goal.ts +27 -3
- package/src/strategies/goals/hide-top.ts +47 -5
- package/src/strategies/goals/keep-away-goal.ts +24 -2
- package/src/strategies/goals/kill-frenzy-top.ts +12 -2
- package/src/strategies/goals/kill-lone-top.test.ts +72 -0
- package/src/strategies/goals/kill-lone-top.ts +8 -6
- package/src/strategies/goals/kill-target-goal.ts +16 -7
- package/src/strategies/goals/kill-target-top.ts +16 -2
- package/src/strategies/goals/linger-corpse-goal.ts +11 -3
- package/src/strategies/goals/lone-kill-core.ts +4 -2
- package/src/strategies/goals/move-room-goal.ts +46 -4
- package/src/strategies/goals/normal-shrimp-top.test.ts +16 -0
- package/src/strategies/goals/normal-shrimp-top.ts +18 -18
- package/src/strategies/goals/paradise-fish-top.test.ts +78 -0
- package/src/strategies/goals/paradise-fish-top.ts +16 -6
- package/src/strategies/goals/patrol-top.ts +14 -3
- package/src/strategies/goals/report-patrol-top.ts +14 -3
- package/src/strategies/goals/safe-task-goal.ts +32 -4
- package/src/strategies/goals/social-task-top.ts +39 -8
- package/src/strategies/goals/task-kill-report-top.ts +33 -10
- package/src/strategies/goals/task-only-top.test.ts +89 -0
- package/src/strategies/goals/task-only-top.ts +9 -2
- package/src/strategies/goals/task-or-patrol-goal.ts +21 -3
- package/src/strategies/goals/warrior-shrimp-top.test.ts +75 -23
- package/src/strategies/goals/warrior-shrimp-top.ts +34 -13
- package/src/strategies/greeting.ts +10 -3
- package/src/strategies/hide-spots.ts +4 -0
- package/src/strategies/hide.ts +35 -20
- package/src/strategies/kill-frenzy.ts +18 -12
- package/src/strategies/kill-lone.ts +43 -12
- package/src/strategies/kill-target.ts +34 -17
- package/src/strategies/lone-kill-task.ts +31 -18
- package/src/strategies/move-room.ts +32 -15
- package/src/strategies/off-route-points.ts +12 -4
- package/src/strategies/paradise-fish.ts +49 -14
- package/src/strategies/pathfind/astar-path.test.ts +73 -0
- package/src/strategies/pathfind/astar-path.ts +196 -0
- package/src/strategies/pathfind/escape-planner.test.ts +27 -1
- package/src/strategies/pathfind/escape-planner.ts +108 -0
- package/src/strategies/patrol.ts +18 -11
- package/src/strategies/report-patrol.ts +18 -11
- package/src/strategies/shrimp-memory.ts +66 -14
- package/src/strategies/social-task.ts +49 -45
- package/src/strategies/task-kill-report.ts +34 -16
- package/src/strategies/task-only.test.ts +124 -0
- package/src/strategies/task-only.ts +20 -11
- package/src/strategies/task-report.ts +29 -11
- package/src/strategies/types.ts +29 -62
- package/src/strategies/warrior-memory.ts +44 -14
- package/scripts/check_monitor.test.mjs +0 -212
- package/skills/clawclaw/references/KNOWLEDGE.md +0 -42
- package/src/commands/do.test.ts +0 -117
- package/src/commands/do.ts +0 -195
- package/src/commands/game-monitor-status.test.ts +0 -58
- package/src/commands/game-start-plan.test.ts +0 -356
- package/src/commands/game.ts +0 -2046
- package/src/commands/history-player.test.ts +0 -105
- package/src/commands/history.ts +0 -573
- package/src/commands/knowledge.test.ts +0 -13
- package/src/commands/knowledge.ts +0 -176
- package/src/commands/meeting-history.test.ts +0 -106
- package/src/commands/state.ts +0 -46
- package/src/commands/watch.test.ts +0 -1313
- package/src/commands/watch.ts +0 -824
- package/src/lib/knowledge-store.test.ts +0 -170
- package/src/lib/knowledge-store.ts +0 -369
- package/src/perception/player-history-store.test.ts +0 -177
- package/src/perception/player-history-store.ts +0 -262
- package/src/pipeline/event-store.test.ts +0 -28
- package/src/pipeline/event-store.ts +0 -193
- package/src/pipeline/pipeline.ts +0 -35
- package/src/runtime/event-daemon.test.ts +0 -268
- package/src/runtime/event-daemon.ts +0 -531
- package/src/runtime/room-lobby-runtime.test.ts +0 -95
- package/src/runtime/room-lobby-runtime.ts +0 -367
- package/src/strategies/avoid-players.knowledge.md +0 -19
- package/src/strategies/kill-lone.knowledge.md +0 -17
- package/src/strategies/knowledge-contract.ts +0 -85
- package/src/strategies/loader.test.ts +0 -710
- package/src/strategies/loader.ts +0 -183
- package/src/strategies/new-events-backfill.ts +0 -98
- package/src/strategies/paradise-fish.knowledge.md +0 -19
- package/src/strategies/scanner.ts +0 -238
- package/src/strategies/shrimp-memory.knowledge.md +0 -19
- package/src/strategies/social-task.test.ts +0 -28
- package/src/strategies/spawn.ts +0 -82
- package/src/strategies/strategy-loop.test.ts +0 -15
- package/src/strategies/strategy-loop.ts +0 -748
- package/src/strategies/warrior-memory.knowledge.md +0 -21
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { playerHistoryCommandInternals } from './history.js';
|
|
3
|
-
import type { PlayerHistoryData, VisibleFrame } from '../perception/player-history-store.js';
|
|
4
|
-
|
|
5
|
-
function iso(ms: number): string {
|
|
6
|
-
return new Date(ms).toISOString();
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
function frame(tick: number, players: VisibleFrame['players']): VisibleFrame {
|
|
10
|
-
return {
|
|
11
|
-
tick,
|
|
12
|
-
time: iso(tick * 100),
|
|
13
|
-
players,
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function baseData(frames: VisibleFrame[]): PlayerHistoryData {
|
|
18
|
-
return {
|
|
19
|
-
time: iso(0),
|
|
20
|
-
visible_frames: frames,
|
|
21
|
-
self_frames: [],
|
|
22
|
-
seats: { A: 1, B: 2, C: 3 },
|
|
23
|
-
lobster_tasks: [],
|
|
24
|
-
last_raw_frame: null,
|
|
25
|
-
last_history_tick: frames[frames.length - 1]?.tick ?? null,
|
|
26
|
-
last_self_tick: null,
|
|
27
|
-
tick_interval_ms: 100,
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
describe('history player query helpers', () => {
|
|
32
|
-
it('resolves all, seat, exact, prefix, and ambiguous selectors', () => {
|
|
33
|
-
const data = baseData([frame(1, { Alice: { x: 0, y: 0 } })]);
|
|
34
|
-
data.seats = { Alice: 1, Alicia: 2, Bob: 3 };
|
|
35
|
-
expect(playerHistoryCommandInternals.resolvePlayers(data, ['all']).players).toEqual(['Alice', 'Alicia', 'Bob']);
|
|
36
|
-
expect(playerHistoryCommandInternals.resolvePlayers(data, ['seat:3']).players).toEqual(['Bob']);
|
|
37
|
-
expect(playerHistoryCommandInternals.resolvePlayers(data, ['Alice']).players).toEqual(['Alice']);
|
|
38
|
-
expect(playerHistoryCommandInternals.resolvePlayers(data, ['Bob']).players).toEqual(['Bob']);
|
|
39
|
-
expect(playerHistoryCommandInternals.resolvePlayers(data, ['Ali']).error?.code).toBe('ambiguous');
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('computes last_appear direction from the last two continuous sightings', () => {
|
|
43
|
-
const data = baseData([
|
|
44
|
-
frame(1, { A: { x: 0, y: 0, room: 'r1' } }),
|
|
45
|
-
frame(2, { A: { x: 0, y: 0, room: 'r1' } }),
|
|
46
|
-
frame(3, { A: { x: 60, y: 60, room: 'r2' } }),
|
|
47
|
-
]);
|
|
48
|
-
const result = playerHistoryCommandInternals.buildLastAppearResult(data, 'A', 1000);
|
|
49
|
-
expect(result.dir).toBe('右下');
|
|
50
|
-
expect(result.visible).toBe(true);
|
|
51
|
-
expect(result.room).toBe('r2');
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('uses a 6px minimum move for direction and reports smaller movement as stay', () => {
|
|
55
|
-
const staying = baseData([
|
|
56
|
-
frame(1, { A: { x: 0, y: 0, room: 'r1' } }),
|
|
57
|
-
frame(2, { A: { x: 5.9, y: 0, room: 'r1' } }),
|
|
58
|
-
]);
|
|
59
|
-
expect(playerHistoryCommandInternals.buildLastAppearResult(staying, 'A', 1000).dir).toBe('stay');
|
|
60
|
-
|
|
61
|
-
const moving = baseData([
|
|
62
|
-
frame(1, { A: { x: 0, y: 0, room: 'r1' } }),
|
|
63
|
-
frame(2, { A: { x: 6, y: 0, room: 'r1' } }),
|
|
64
|
-
]);
|
|
65
|
-
expect(playerHistoryCommandInternals.buildLastAppearResult(moving, 'A', 1000).dir).toBe('右');
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('breaks rooms_seen on continuous room changes', () => {
|
|
69
|
-
const data = baseData([
|
|
70
|
-
frame(1, { A: { x: 0, y: 0, room: 'r1' } }),
|
|
71
|
-
frame(2, { A: { x: 0, y: 0, room: 'r1' } }),
|
|
72
|
-
frame(3, { A: { x: 0, y: 0, room: 'r2' } }),
|
|
73
|
-
]);
|
|
74
|
-
const result = playerHistoryCommandInternals.buildRoomsSeenResult(data, 'A', 1000);
|
|
75
|
-
expect(new Set(result.rooms.map((room: any) => room.room))).toEqual(new Set(['r1', 'r2']));
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('requires exact same coordinates for non-task stay', () => {
|
|
79
|
-
const exactFrames: VisibleFrame[] = [];
|
|
80
|
-
for (let tick = 0; tick <= 20; tick++) {
|
|
81
|
-
exactFrames.push(frame(tick, { A: { x: 100, y: 100, room: 'r1' } }));
|
|
82
|
-
}
|
|
83
|
-
const exact = playerHistoryCommandInternals.buildStayResult(baseData(exactFrames), 'A', 3000);
|
|
84
|
-
expect(exact.stays).toHaveLength(1);
|
|
85
|
-
|
|
86
|
-
const movingFrames: VisibleFrame[] = [];
|
|
87
|
-
for (let tick = 0; tick <= 20; tick++) {
|
|
88
|
-
movingFrames.push(frame(tick, { A: { x: 100 + tick % 2, y: 100, room: 'r1' } }));
|
|
89
|
-
}
|
|
90
|
-
const moving = playerHistoryCommandInternals.buildStayResult(baseData(movingFrames), 'A', 3000);
|
|
91
|
-
expect(moving.stays).toHaveLength(0);
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it('groups stay near the same lobster task within the 15px task radius', () => {
|
|
95
|
-
const frames: VisibleFrame[] = [];
|
|
96
|
-
for (let tick = 0; tick <= 20; tick++) {
|
|
97
|
-
frames.push(frame(tick, { A: { x: 90 + (tick % 3) * 10, y: 100, room: 'r1' } }));
|
|
98
|
-
}
|
|
99
|
-
const data = baseData(frames);
|
|
100
|
-
data.lobster_tasks = [{ name: '修线', room: 'r1', x: 100, y: 100 }];
|
|
101
|
-
const result = playerHistoryCommandInternals.buildStayResult(data, 'A', 3000);
|
|
102
|
-
expect(result.stays).toHaveLength(1);
|
|
103
|
-
expect(result.stays[0].near_task).toBe('修线');
|
|
104
|
-
});
|
|
105
|
-
});
|
package/src/commands/history.ts
DELETED
|
@@ -1,573 +0,0 @@
|
|
|
1
|
-
import { Command } from 'commander';
|
|
2
|
-
import { EventStore } from '../pipeline/event-store.js';
|
|
3
|
-
import {
|
|
4
|
-
PlayerHistoryStore,
|
|
5
|
-
type FramePlayer,
|
|
6
|
-
type LobsterTaskPoint,
|
|
7
|
-
type PlayerHistoryData,
|
|
8
|
-
type VisibleFrame,
|
|
9
|
-
} from '../perception/player-history-store.js';
|
|
10
|
-
|
|
11
|
-
type HistoryKind = 'stay' | 'last_appear' | 'rooms_seen';
|
|
12
|
-
|
|
13
|
-
const KINDS = new Set<HistoryKind>(['stay', 'last_appear', 'rooms_seen']);
|
|
14
|
-
const STOP_MIN_SECS = 2;
|
|
15
|
-
const TASK_DONE_RADIUS = 15;
|
|
16
|
-
const DIR_MIN_MOVE = 6;
|
|
17
|
-
|
|
18
|
-
interface PlayerPoint {
|
|
19
|
-
frame: VisibleFrame;
|
|
20
|
-
pos: FramePlayer;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function round1(value: number): number {
|
|
24
|
-
return Math.round(value * 10) / 10;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function dist(a: { x: number; y: number }, b: { x: number; y: number }): number {
|
|
28
|
-
return Math.sqrt((a.x - b.x) ** 2 + (a.y - b.y) ** 2);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function ageSecs(time: string, now: number): number {
|
|
32
|
-
const ms = Date.parse(time);
|
|
33
|
-
if (!Number.isFinite(ms)) return 0;
|
|
34
|
-
return Math.max(0, round1((now - ms) / 1000));
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function durationSecs(start: string, end: string): number {
|
|
38
|
-
const startMs = Date.parse(start);
|
|
39
|
-
const endMs = Date.parse(end);
|
|
40
|
-
if (!Number.isFinite(startMs) || !Number.isFinite(endMs)) return 0;
|
|
41
|
-
return Math.max(0, round1((endMs - startMs) / 1000));
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function splitSelectors(values: string[]): string[] {
|
|
45
|
-
return values
|
|
46
|
-
.flatMap((value) => String(value).split(','))
|
|
47
|
-
.map((value) => value.trim())
|
|
48
|
-
.filter(Boolean);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function knownPlayerNames(data: PlayerHistoryData): string[] {
|
|
52
|
-
const names = new Set<string>(Object.keys(data.seats ?? {}));
|
|
53
|
-
for (const frame of data.visible_frames ?? []) {
|
|
54
|
-
for (const name of Object.keys(frame.players ?? {})) names.add(name);
|
|
55
|
-
}
|
|
56
|
-
return Array.from(names).sort((a, b) => a.localeCompare(b));
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function resolvePlayers(data: PlayerHistoryData, selectors: string[]): { players?: string[]; error?: Record<string, any> } {
|
|
60
|
-
const names = knownPlayerNames(data);
|
|
61
|
-
if (selectors.length === 0) {
|
|
62
|
-
return { error: { code: 'missing_player_id', message: 'Provide a player id/name, list, or all.' } };
|
|
63
|
-
}
|
|
64
|
-
if (selectors.some((selector) => selector.toLowerCase() === 'all')) return { players: names };
|
|
65
|
-
|
|
66
|
-
const resolved: string[] = [];
|
|
67
|
-
for (const selector of selectors) {
|
|
68
|
-
const seatMatch = selector.match(/^seat:(\d+)$/i);
|
|
69
|
-
const seat = seatMatch ? Number(seatMatch[1]) : /^\d+$/.test(selector) ? Number(selector) : null;
|
|
70
|
-
let matches: string[] = [];
|
|
71
|
-
if (seat != null) {
|
|
72
|
-
matches = names.filter((name) => data.seats?.[name] === seat);
|
|
73
|
-
} else {
|
|
74
|
-
matches = names.filter((name) => name === selector);
|
|
75
|
-
if (matches.length === 0) matches = names.filter((name) => name.startsWith(selector));
|
|
76
|
-
if (matches.length === 0) matches = names.filter((name) => name.toLowerCase().includes(selector.toLowerCase()));
|
|
77
|
-
}
|
|
78
|
-
if (matches.length === 0) {
|
|
79
|
-
return { error: { code: 'not_found', selector, known_players: names } };
|
|
80
|
-
}
|
|
81
|
-
if (matches.length > 1) {
|
|
82
|
-
return { error: { code: 'ambiguous', selector, candidates: matches } };
|
|
83
|
-
}
|
|
84
|
-
if (!resolved.includes(matches[0])) resolved.push(matches[0]);
|
|
85
|
-
}
|
|
86
|
-
return { players: resolved };
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function pointsForPlayer(frames: VisibleFrame[], player: string): PlayerPoint[] {
|
|
90
|
-
const points: PlayerPoint[] = [];
|
|
91
|
-
for (const frame of frames) {
|
|
92
|
-
const pos = frame.players?.[player];
|
|
93
|
-
if (pos) points.push({ frame, pos });
|
|
94
|
-
}
|
|
95
|
-
return points;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function continuousRuns(points: PlayerPoint[]): PlayerPoint[][] {
|
|
99
|
-
const runs: PlayerPoint[][] = [];
|
|
100
|
-
let current: PlayerPoint[] = [];
|
|
101
|
-
for (const point of points) {
|
|
102
|
-
const prev = current[current.length - 1];
|
|
103
|
-
if (!prev || point.frame.tick === prev.frame.tick + 1) {
|
|
104
|
-
current.push(point);
|
|
105
|
-
} else {
|
|
106
|
-
if (current.length > 0) runs.push(current);
|
|
107
|
-
current = [point];
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
if (current.length > 0) runs.push(current);
|
|
111
|
-
return runs;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function centroid(points: PlayerPoint[]): { x: number; y: number } {
|
|
115
|
-
const sum = points.reduce((acc, point) => ({ x: acc.x + point.pos.x, y: acc.y + point.pos.y }), { x: 0, y: 0 });
|
|
116
|
-
return { x: sum.x / points.length, y: sum.y / points.length };
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
function mostCommonRoom(points: PlayerPoint[]): string | undefined {
|
|
120
|
-
const counts = new Map<string, number>();
|
|
121
|
-
for (const point of points) {
|
|
122
|
-
if (!point.pos.room) continue;
|
|
123
|
-
counts.set(point.pos.room, (counts.get(point.pos.room) ?? 0) + 1);
|
|
124
|
-
}
|
|
125
|
-
return Array.from(counts.entries()).sort((a, b) => b[1] - a[1])[0]?.[0];
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function nearTask(tasks: LobsterTaskPoint[], point: { x: number; y: number }): string | null {
|
|
129
|
-
let best: { task: LobsterTaskPoint; distance: number } | null = null;
|
|
130
|
-
for (const task of tasks) {
|
|
131
|
-
const distance = dist(point, task);
|
|
132
|
-
if (distance > TASK_DONE_RADIUS) continue;
|
|
133
|
-
if (!best || distance < best.distance) best = { task, distance };
|
|
134
|
-
}
|
|
135
|
-
return best?.task.name ?? null;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
function stayKey(data: PlayerHistoryData, point: PlayerPoint): string {
|
|
139
|
-
const task = nearTask(data.lobster_tasks, point.pos);
|
|
140
|
-
if (task) return `task:${task}`;
|
|
141
|
-
return `pos:${point.pos.x},${point.pos.y}`;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
function buildStayResult(data: PlayerHistoryData, player: string, now: number): Record<string, any> {
|
|
145
|
-
const stays: Record<string, any>[] = [];
|
|
146
|
-
for (const run of continuousRuns(pointsForPlayer(data.visible_frames, player))) {
|
|
147
|
-
let segment: PlayerPoint[] = [];
|
|
148
|
-
let segmentKey: string | null = null;
|
|
149
|
-
for (const point of run) {
|
|
150
|
-
const key = stayKey(data, point);
|
|
151
|
-
if (segment.length === 0 || key === segmentKey) {
|
|
152
|
-
segment.push(point);
|
|
153
|
-
segmentKey = key;
|
|
154
|
-
} else {
|
|
155
|
-
appendStay(stays, segment, data.lobster_tasks, now);
|
|
156
|
-
segment = [point];
|
|
157
|
-
segmentKey = key;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
appendStay(stays, segment, data.lobster_tasks, now);
|
|
161
|
-
}
|
|
162
|
-
stays.sort((a, b) => a.to_ago - b.to_ago);
|
|
163
|
-
return {
|
|
164
|
-
player,
|
|
165
|
-
...(data.seats?.[player] != null ? { seat: data.seats[player] } : {}),
|
|
166
|
-
stays,
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
function appendStay(out: Record<string, any>[], segment: PlayerPoint[], tasks: LobsterTaskPoint[], now: number): void {
|
|
171
|
-
if (segment.length < 2) return;
|
|
172
|
-
const first = segment[0];
|
|
173
|
-
const last = segment[segment.length - 1];
|
|
174
|
-
const secs = durationSecs(first.frame.time, last.frame.time);
|
|
175
|
-
if (secs < STOP_MIN_SECS) return;
|
|
176
|
-
const center = centroid(segment);
|
|
177
|
-
const room = mostCommonRoom(segment);
|
|
178
|
-
out.push({
|
|
179
|
-
from_ago: ageSecs(first.frame.time, now),
|
|
180
|
-
to_ago: ageSecs(last.frame.time, now),
|
|
181
|
-
secs,
|
|
182
|
-
room,
|
|
183
|
-
x: round1(center.x),
|
|
184
|
-
y: round1(center.y),
|
|
185
|
-
pos: `${round1(center.x)},${round1(center.y)}`,
|
|
186
|
-
near_task: nearTask(tasks, center),
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
function direction(from: { x: number; y: number }, to: { x: number; y: number }): string {
|
|
191
|
-
const dx = to.x - from.x;
|
|
192
|
-
const dy = to.y - from.y;
|
|
193
|
-
if (Math.sqrt(dx ** 2 + dy ** 2) < DIR_MIN_MOVE) return 'stay';
|
|
194
|
-
const horizontal = Math.abs(dx) >= DIR_MIN_MOVE / 2 ? (dx > 0 ? '右' : '左') : '';
|
|
195
|
-
const vertical = Math.abs(dy) >= DIR_MIN_MOVE / 2 ? (dy > 0 ? '下' : '上') : '';
|
|
196
|
-
return `${horizontal}${vertical}` || 'stay';
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
function buildLastAppearResult(data: PlayerHistoryData, player: string, now: number): Record<string, any> {
|
|
200
|
-
const runs = continuousRuns(pointsForPlayer(data.visible_frames, player));
|
|
201
|
-
const latestFrame = data.visible_frames[data.visible_frames.length - 1];
|
|
202
|
-
const lastRun = runs[runs.length - 1] ?? [];
|
|
203
|
-
const last = lastRun[lastRun.length - 1];
|
|
204
|
-
if (!last) {
|
|
205
|
-
return {
|
|
206
|
-
player,
|
|
207
|
-
...(data.seats?.[player] != null ? { seat: data.seats[player] } : {}),
|
|
208
|
-
visible: false,
|
|
209
|
-
ago: null,
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
const previous = lastRun.length >= 2 ? lastRun[lastRun.length - 2] : last;
|
|
214
|
-
return {
|
|
215
|
-
player,
|
|
216
|
-
...(data.seats?.[player] != null ? { seat: data.seats[player] } : {}),
|
|
217
|
-
visible: latestFrame?.players?.[player] != null,
|
|
218
|
-
ago: ageSecs(last.frame.time, now),
|
|
219
|
-
room: last.pos.room,
|
|
220
|
-
x: round1(last.pos.x),
|
|
221
|
-
y: round1(last.pos.y),
|
|
222
|
-
dir: direction(previous.pos, last.pos),
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
function buildRoomsSeenResult(data: PlayerHistoryData, player: string, now: number): Record<string, any> {
|
|
227
|
-
const rooms: Record<string, any>[] = [];
|
|
228
|
-
for (const run of continuousRuns(pointsForPlayer(data.visible_frames, player))) {
|
|
229
|
-
let currentRoom = run[0]?.pos.room ?? 'unknown';
|
|
230
|
-
let start = run[0];
|
|
231
|
-
let previous = run[0];
|
|
232
|
-
for (const point of run.slice(1)) {
|
|
233
|
-
const room = point.pos.room ?? 'unknown';
|
|
234
|
-
if (room !== currentRoom) {
|
|
235
|
-
rooms.push(roomSegment(currentRoom, start, previous, now));
|
|
236
|
-
currentRoom = room;
|
|
237
|
-
start = point;
|
|
238
|
-
}
|
|
239
|
-
previous = point;
|
|
240
|
-
}
|
|
241
|
-
if (start && previous) rooms.push(roomSegment(currentRoom, start, previous, now));
|
|
242
|
-
}
|
|
243
|
-
rooms.sort((a, b) => a.to_ago - b.to_ago);
|
|
244
|
-
return {
|
|
245
|
-
player,
|
|
246
|
-
...(data.seats?.[player] != null ? { seat: data.seats[player] } : {}),
|
|
247
|
-
rooms,
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
function roomSegment(room: string, start: PlayerPoint, end: PlayerPoint, now: number): Record<string, any> {
|
|
252
|
-
return {
|
|
253
|
-
room,
|
|
254
|
-
from_ago: ageSecs(start.frame.time, now),
|
|
255
|
-
to_ago: ageSecs(end.frame.time, now),
|
|
256
|
-
secs: durationSecs(start.frame.time, end.frame.time),
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
interface MeetingRecord {
|
|
261
|
-
round: number;
|
|
262
|
-
start?: Record<string, any>;
|
|
263
|
-
briefing?: Record<string, any>;
|
|
264
|
-
states: Record<string, any>[];
|
|
265
|
-
speechEvents: Record<string, any>[];
|
|
266
|
-
voteEvents: Record<string, any>[];
|
|
267
|
-
resultEvent?: Record<string, any>;
|
|
268
|
-
ended?: Record<string, any>;
|
|
269
|
-
interrupted?: boolean;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
interface DeathInfo {
|
|
273
|
-
type: 'found_in_meeting' | 'exiled';
|
|
274
|
-
round: number;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
function buildMeetingRecords(events: Record<string, any>[]): MeetingRecord[] {
|
|
278
|
-
const meetings: MeetingRecord[] = [];
|
|
279
|
-
let current: MeetingRecord | null = null;
|
|
280
|
-
|
|
281
|
-
const finishCurrent = (interrupted = false) => {
|
|
282
|
-
if (!current) return;
|
|
283
|
-
current.interrupted = current.interrupted || interrupted;
|
|
284
|
-
meetings.push(current);
|
|
285
|
-
current = null;
|
|
286
|
-
};
|
|
287
|
-
|
|
288
|
-
for (const event of events) {
|
|
289
|
-
if (event.type === 'meeting_start') {
|
|
290
|
-
finishCurrent(true);
|
|
291
|
-
current = {
|
|
292
|
-
round: meetings.length + 1,
|
|
293
|
-
start: event,
|
|
294
|
-
states: [],
|
|
295
|
-
speechEvents: [],
|
|
296
|
-
voteEvents: [],
|
|
297
|
-
};
|
|
298
|
-
continue;
|
|
299
|
-
}
|
|
300
|
-
if (!current) continue;
|
|
301
|
-
|
|
302
|
-
if (event.type === 'meeting_briefing') current.briefing = event;
|
|
303
|
-
if (event.type === 'meeting_state' && (event.round == null || event.round === current.round)) current.states.push(event);
|
|
304
|
-
if (event.type === 'speech' || event.type === 'speech_skipped' || event.type === 'speech_turn') current.speechEvents.push(event);
|
|
305
|
-
if (event.type === 'vote_cast') current.voteEvents.push(event);
|
|
306
|
-
if (event.type === 'exile' || event.type === 'no_exile') current.resultEvent = event;
|
|
307
|
-
if (event.type === 'meeting_ended') {
|
|
308
|
-
current.ended = event;
|
|
309
|
-
finishCurrent(false);
|
|
310
|
-
continue;
|
|
311
|
-
}
|
|
312
|
-
if (event.type === 'game_over') {
|
|
313
|
-
finishCurrent(true);
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
finishCurrent(false);
|
|
317
|
-
return meetings;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
function latestMeetingState(record: MeetingRecord): Record<string, any> | undefined {
|
|
321
|
-
return record.states[record.states.length - 1];
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
function meetingVotes(record: MeetingRecord): Record<string, string> {
|
|
325
|
-
const resultVotes = record.resultEvent?.votes;
|
|
326
|
-
if (resultVotes && typeof resultVotes === 'object' && !Array.isArray(resultVotes)) {
|
|
327
|
-
return resultVotes as Record<string, string>;
|
|
328
|
-
}
|
|
329
|
-
const votes: Record<string, string> = {};
|
|
330
|
-
for (const vote of record.voteEvents) {
|
|
331
|
-
if (typeof vote.actor_name === 'string' && typeof vote.target === 'string') votes[vote.actor_name] = vote.target;
|
|
332
|
-
}
|
|
333
|
-
return votes;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
function exiledPlayer(record: MeetingRecord): string | null {
|
|
337
|
-
if (record.ended?.result === 'exiled' && typeof record.ended.result_target === 'string') return record.ended.result_target;
|
|
338
|
-
if (record.resultEvent?.type === 'exile' && typeof record.resultEvent.actor_name === 'string') return record.resultEvent.actor_name;
|
|
339
|
-
return null;
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
function meetingState(record: MeetingRecord): string {
|
|
343
|
-
if (record.ended) return 'ended';
|
|
344
|
-
const subPhase = latestMeetingState(record)?.sub_phase;
|
|
345
|
-
if (typeof subPhase === 'string' && subPhase.length > 0) return subPhase;
|
|
346
|
-
if (record.interrupted) return 'interrupted_or_missing_end';
|
|
347
|
-
return 'interrupted_or_missing_end';
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
function meetingAllSeats(record: MeetingRecord): Array<{ name: string; seat: number }> {
|
|
351
|
-
const allSeats = record.briefing?.all_seats;
|
|
352
|
-
if (!Array.isArray(allSeats)) return [];
|
|
353
|
-
return allSeats
|
|
354
|
-
.filter((player: any) => typeof player?.name === 'string' && Number.isFinite(player.seat))
|
|
355
|
-
.map((player: any) => ({ name: player.name, seat: player.seat }))
|
|
356
|
-
.sort((a, b) => a.seat - b.seat);
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
function latestAlivePlayers(record: MeetingRecord): Set<string> | null {
|
|
360
|
-
for (let i = record.states.length - 1; i >= 0; i--) {
|
|
361
|
-
const alive = record.states[i].alive_players;
|
|
362
|
-
if (Array.isArray(alive)) return new Set(alive.filter((name: any) => typeof name === 'string'));
|
|
363
|
-
}
|
|
364
|
-
return null;
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
function collectSpeechOrder(record: MeetingRecord): string[] {
|
|
368
|
-
for (const state of record.states) {
|
|
369
|
-
if (Array.isArray(state.speech_order)) {
|
|
370
|
-
return state.speech_order.filter((name: any) => typeof name === 'string');
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
const order: string[] = [];
|
|
374
|
-
for (const event of record.speechEvents) {
|
|
375
|
-
const speaker = event.actor_name;
|
|
376
|
-
if (typeof speaker === 'string' && !order.includes(speaker)) order.push(speaker);
|
|
377
|
-
}
|
|
378
|
-
return order;
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
function meetingSpeeches(record: MeetingRecord): Array<{ speaker: string; text: string; skipped: boolean }> {
|
|
382
|
-
const order = collectSpeechOrder(record);
|
|
383
|
-
const texts = new Map<string, string>();
|
|
384
|
-
const skipped = new Set<string>();
|
|
385
|
-
const seen = new Set<string>();
|
|
386
|
-
|
|
387
|
-
for (const state of record.states) {
|
|
388
|
-
const stateSpeeches = state.speeches;
|
|
389
|
-
if (stateSpeeches && typeof stateSpeeches === 'object' && !Array.isArray(stateSpeeches)) {
|
|
390
|
-
for (const [speaker, text] of Object.entries(stateSpeeches)) {
|
|
391
|
-
if (typeof speaker !== 'string') continue;
|
|
392
|
-
texts.set(speaker, typeof text === 'string' ? text : '');
|
|
393
|
-
seen.add(speaker);
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
if (Array.isArray(state.speech_skipped)) {
|
|
397
|
-
for (const speaker of state.speech_skipped) {
|
|
398
|
-
if (typeof speaker !== 'string') continue;
|
|
399
|
-
skipped.add(speaker);
|
|
400
|
-
seen.add(speaker);
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
for (const event of record.speechEvents) {
|
|
406
|
-
const speaker = event.actor_name;
|
|
407
|
-
if (typeof speaker !== 'string') continue;
|
|
408
|
-
if (event.type === 'speech') {
|
|
409
|
-
texts.set(speaker, typeof event.text === 'string' ? event.text : '');
|
|
410
|
-
seen.add(speaker);
|
|
411
|
-
} else if (event.type === 'speech_skipped') {
|
|
412
|
-
skipped.add(speaker);
|
|
413
|
-
seen.add(speaker);
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
const outputOrder = [...order, ...Array.from(seen).filter((speaker) => !order.includes(speaker))];
|
|
418
|
-
return outputOrder
|
|
419
|
-
.filter((speaker) => seen.has(speaker))
|
|
420
|
-
.map((speaker) => ({
|
|
421
|
-
speaker,
|
|
422
|
-
text: texts.get(speaker) ?? '',
|
|
423
|
-
skipped: skipped.has(speaker),
|
|
424
|
-
}));
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
function applyMeetingDeaths(record: MeetingRecord, deaths: Map<string, DeathInfo>): void {
|
|
428
|
-
const alive = latestAlivePlayers(record);
|
|
429
|
-
if (alive) {
|
|
430
|
-
for (const player of meetingAllSeats(record)) {
|
|
431
|
-
if (!alive.has(player.name) && !deaths.has(player.name)) {
|
|
432
|
-
deaths.set(player.name, { type: 'found_in_meeting', round: record.round });
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
const exiled = exiledPlayer(record);
|
|
437
|
-
if (exiled) deaths.set(exiled, { type: 'exiled', round: record.round });
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
function meetingPlayers(record: MeetingRecord, deaths: Map<string, DeathInfo>): Record<string, any>[] {
|
|
441
|
-
return meetingAllSeats(record).map((player) => {
|
|
442
|
-
const death = deaths.get(player.name) ?? null;
|
|
443
|
-
return {
|
|
444
|
-
name: player.name,
|
|
445
|
-
seat: player.seat,
|
|
446
|
-
status: death ? 'dead' : 'alive',
|
|
447
|
-
death,
|
|
448
|
-
};
|
|
449
|
-
});
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
function meetingOutput(record: MeetingRecord, deaths: Map<string, DeathInfo>): Record<string, any> {
|
|
453
|
-
applyMeetingDeaths(record, deaths);
|
|
454
|
-
return {
|
|
455
|
-
round: record.round,
|
|
456
|
-
tick: record.start?.tick ?? record.briefing?.tick ?? null,
|
|
457
|
-
caller: record.start?.actor_name ?? record.briefing?.caller ?? latestMeetingState(record)?.caller ?? null,
|
|
458
|
-
corpses_found: null,
|
|
459
|
-
state: meetingState(record),
|
|
460
|
-
exiled_player: exiledPlayer(record),
|
|
461
|
-
players: meetingPlayers(record, deaths),
|
|
462
|
-
votes: meetingVotes(record),
|
|
463
|
-
speeches: meetingSpeeches(record),
|
|
464
|
-
};
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
function allMeetingOutputs(records: MeetingRecord[]): Record<string, any>[] {
|
|
468
|
-
const deaths = new Map<string, DeathInfo>();
|
|
469
|
-
return records.map((record) => meetingOutput(record, deaths));
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
function createMeetingsCommand(): Command {
|
|
473
|
-
return new Command('meetings')
|
|
474
|
-
.description('Show meeting history')
|
|
475
|
-
.argument('[round]', 'Meeting round number, starting from 1')
|
|
476
|
-
.action((roundText?: string) => {
|
|
477
|
-
const records = buildMeetingRecords(EventStore.forLatestGame().all());
|
|
478
|
-
const outputs = allMeetingOutputs(records);
|
|
479
|
-
if (roundText != null) {
|
|
480
|
-
const round = Number(roundText);
|
|
481
|
-
const record = Number.isInteger(round) && round > 0 ? outputs.find((meeting) => meeting.round === round) : null;
|
|
482
|
-
if (!record) {
|
|
483
|
-
console.log(JSON.stringify({
|
|
484
|
-
error: {
|
|
485
|
-
code: 'meeting_round_not_found',
|
|
486
|
-
round: roundText,
|
|
487
|
-
available_rounds: outputs.map((meeting) => meeting.round),
|
|
488
|
-
},
|
|
489
|
-
}, null, 2));
|
|
490
|
-
return;
|
|
491
|
-
}
|
|
492
|
-
console.log(JSON.stringify(record, null, 2));
|
|
493
|
-
return;
|
|
494
|
-
}
|
|
495
|
-
console.log(JSON.stringify({ meetings: outputs }, null, 2));
|
|
496
|
-
});
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
function createPlayerHistorySubcommand(): Command {
|
|
500
|
-
return new Command('player')
|
|
501
|
-
.description('Show derived visible-player history')
|
|
502
|
-
.argument('<kind>', 'stay | last_appear | rooms_seen')
|
|
503
|
-
.argument('[player_id...]', 'Player name/seat/list, or all')
|
|
504
|
-
.action(async (kind: string, playerArgs: string[]) => {
|
|
505
|
-
if (!KINDS.has(kind as HistoryKind)) {
|
|
506
|
-
console.log(JSON.stringify({ error: { code: 'invalid_kind', allowed: Array.from(KINDS) } }, null, 2));
|
|
507
|
-
return;
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
const sessionPath = EventStore.latestSessionPath();
|
|
511
|
-
if (!sessionPath) {
|
|
512
|
-
console.log(JSON.stringify({
|
|
513
|
-
kind,
|
|
514
|
-
error: { code: 'no_game_events', message: 'No game events found. Join a game first.' },
|
|
515
|
-
}, null, 2));
|
|
516
|
-
return;
|
|
517
|
-
}
|
|
518
|
-
const data = PlayerHistoryStore.forSession(sessionPath).read();
|
|
519
|
-
if (!data || !Array.isArray(data.visible_frames) || data.visible_frames.length === 0) {
|
|
520
|
-
console.log(JSON.stringify({
|
|
521
|
-
kind,
|
|
522
|
-
error: {
|
|
523
|
-
code: 'no_player_history',
|
|
524
|
-
message: 'No player_spotted history yet. Join a game and wait for the game runtime to receive player_spotted events.',
|
|
525
|
-
},
|
|
526
|
-
}, null, 2));
|
|
527
|
-
return;
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
const selectors = splitSelectors(playerArgs);
|
|
531
|
-
const resolved = resolvePlayers(data, selectors);
|
|
532
|
-
if (resolved.error) {
|
|
533
|
-
console.log(JSON.stringify({ kind, error: resolved.error }, null, 2));
|
|
534
|
-
return;
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
const now = Date.now();
|
|
538
|
-
const players = resolved.players ?? [];
|
|
539
|
-
const resultPlayers = players.map((player) => {
|
|
540
|
-
if (kind === 'stay') return buildStayResult(data, player, now);
|
|
541
|
-
if (kind === 'last_appear') return buildLastAppearResult(data, player, now);
|
|
542
|
-
return buildRoomsSeenResult(data, player, now);
|
|
543
|
-
});
|
|
544
|
-
|
|
545
|
-
console.log(JSON.stringify({
|
|
546
|
-
kind,
|
|
547
|
-
time: new Date(now).toISOString(),
|
|
548
|
-
players: resultPlayers,
|
|
549
|
-
}, null, 2));
|
|
550
|
-
});
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
export function createHistoryCommand(): Command {
|
|
554
|
-
const history = new Command('history')
|
|
555
|
-
.description('Show derived player and meeting history');
|
|
556
|
-
history.addCommand(createPlayerHistorySubcommand());
|
|
557
|
-
history.addCommand(createMeetingsCommand());
|
|
558
|
-
return history;
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
export const playerHistoryCommandInternals = {
|
|
562
|
-
direction,
|
|
563
|
-
resolvePlayers,
|
|
564
|
-
buildStayResult,
|
|
565
|
-
buildLastAppearResult,
|
|
566
|
-
buildRoomsSeenResult,
|
|
567
|
-
};
|
|
568
|
-
|
|
569
|
-
export const meetingHistoryCommandInternals = {
|
|
570
|
-
buildMeetingRecords,
|
|
571
|
-
allMeetingOutputs,
|
|
572
|
-
meetingSpeeches,
|
|
573
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { normalizePlayerMark } from './knowledge.js';
|
|
3
|
-
|
|
4
|
-
describe('knowledge player marks', () => {
|
|
5
|
-
it('accepts only the two canonical mark names', () => {
|
|
6
|
-
expect(normalizePlayerMark('hostile')).toBe('hostile');
|
|
7
|
-
expect(normalizePlayerMark('trusted')).toBe('trusted');
|
|
8
|
-
// suspect 不再是可设标记:未标记 = 默认被怀疑。
|
|
9
|
-
expect(normalizePlayerMark('suspect')).toBeNull();
|
|
10
|
-
expect(normalizePlayerMark('impostor')).toBeNull();
|
|
11
|
-
expect(normalizePlayerMark('avoid')).toBeNull();
|
|
12
|
-
});
|
|
13
|
-
});
|