@myclaw163/clawclaw-cli 0.7.16 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/QUICKSTART_HERMES.md +1 -1
- package/QUICKSTART_OPENCLAW.md +3 -11
- package/QUICKSTART_OTHER.md +8 -8
- package/README.md +18 -9
- package/bin/clawclaw-channel.mjs +13 -0
- package/docs/configuration.md +86 -33
- package/docs/custom-modules/README.md +148 -0
- package/docs/custom-modules/api-reference.md +767 -0
- package/docs/custom-modules/behavior.md +318 -0
- package/docs/custom-modules/perception.md +305 -0
- package/docs/custom-modules/trigger.md +292 -0
- package/docs/desktop-event-push.md +6 -4
- package/docs/runtime/README.md +28 -10
- package/docs/runtime/agent-notifications.md +48 -29
- package/docs/runtime/behavior-runtime.md +139 -0
- package/docs/runtime/components-and-boundaries.md +89 -173
- package/docs/runtime/events-and-state.md +55 -66
- package/docs/runtime/official-perception-modules.md +17 -9
- package/docs/runtime/owner-lifecycle-and-observability.md +62 -39
- package/docs/runtime/perception-replay.md +6 -6
- package/docs/runtime/short-commands-and-capabilities.md +35 -37
- package/package.json +7 -4
- package/scripts/check-skill-command-surface.mjs +54 -10
- package/scripts/compare-perception-replays.test.ts +10 -10
- package/scripts/compare-perception-replays.ts +14 -10
- package/scripts/replay-perception.ts +3 -3
- package/scripts/watch-perception-events.test.ts +1 -1
- package/skills/clawclaw/SKILL.md +97 -59
- package/skills/clawclaw/references/BEHAVIORS.md +154 -0
- package/skills/clawclaw/references/CHANNELS.md +115 -0
- package/skills/clawclaw/references/CHATTERBOX.md +3 -2
- package/skills/clawclaw/references/COMMANDS.md +108 -58
- package/skills/clawclaw/references/GAME-MECHANICS.md +4 -3
- package/skills/clawclaw/references/HUB.md +27 -23
- package/skills/clawclaw/references/STREAM.md +18 -14
- package/skills/clawclaw/references/TACTICS.md +2 -2
- package/src/behaviors/official-finite/do-task.ts +141 -0
- package/src/behaviors/official-finite/evade.ts +78 -0
- package/src/behaviors/official-finite/find-player.ts +50 -0
- package/src/behaviors/official-finite/follow-player.ts +70 -0
- package/src/behaviors/official-finite/go-to.ts +69 -0
- package/src/behaviors/official-finite/hide-temporarily.ts +77 -0
- package/src/behaviors/official-finite/hold-position.ts +48 -0
- package/src/behaviors/official-finite/hunt-player.ts +47 -0
- package/src/behaviors/official-finite/index.test.ts +202 -0
- package/src/behaviors/official-finite/index.ts +47 -0
- package/src/behaviors/official-finite/inspect-corpse.ts +64 -0
- package/src/behaviors/official-finite/patrol-area.ts +80 -0
- package/src/behaviors/official-finite/report-corpse.ts +73 -0
- package/src/behaviors/official-finite/seek-kill-opportunity.ts +152 -0
- package/src/behaviors/official-finite/shared.ts +27 -0
- package/src/behaviors/official-finite/trigger-alarm.ts +53 -0
- package/src/channel/claude-channel-ipc-server.ts +295 -0
- package/src/channel/claude-channel-ipc.ts +152 -0
- package/src/channel/claude-channel-server.test.ts +202 -0
- package/src/channel/claude-channel-server.ts +221 -0
- package/src/cli.ts +4 -2
- package/src/commands/account.test.ts +17 -17
- package/src/commands/behavior.test.ts +158 -0
- package/src/commands/behavior.ts +443 -0
- package/src/commands/communication.test.ts +12 -0
- package/src/commands/communication.ts +6 -3
- package/src/commands/data.test.ts +1 -1
- package/src/commands/data.ts +1 -1
- package/src/commands/events-canonical-state.test.ts +221 -2
- package/src/commands/events.ts +205 -12
- package/src/commands/game/index.test.ts +172 -3
- package/src/commands/game/index.ts +69 -32
- package/src/commands/hub.test.ts +25 -14
- package/src/commands/hub.ts +15 -19
- package/src/commands/load.test.ts +228 -6
- package/src/commands/load.ts +102 -18
- package/src/commands/memory.ts +1 -1
- package/src/commands/peek.ts +1 -1
- package/src/commands/perception.test.ts +30 -1
- package/src/commands/perception.ts +15 -17
- package/src/commands/trigger.test.ts +140 -0
- package/src/commands/trigger.ts +314 -0
- package/src/lib/account-guidance.test.ts +4 -0
- package/src/lib/account-guidance.ts +1 -1
- package/src/lib/behavior-export.test.ts +282 -0
- package/src/lib/behavior-export.ts +514 -0
- package/src/lib/game-client.test.ts +4 -17
- package/src/lib/game-client.ts +1 -0
- package/src/lib/gameplay-config.test.ts +258 -37
- package/src/lib/gameplay-config.ts +175 -35
- package/src/lib/hub-install.test.ts +19 -41
- package/src/lib/hub-install.ts +10 -38
- package/src/lib/hub-reminder.ts +7 -9
- package/src/lib/init-command.ts +1 -1
- package/src/lib/official-resource-sync.test.ts +199 -0
- package/src/lib/official-resource-sync.ts +221 -0
- package/src/lib/perception-config.test.ts +9 -4
- package/src/lib/perception-config.ts +10 -13
- package/src/lib/perception-export.test.ts +145 -0
- package/src/lib/perception-export.ts +178 -0
- package/src/lib/trigger-config.test.ts +102 -0
- package/src/lib/trigger-config.ts +217 -0
- package/src/lib/user-data.test.ts +23 -6
- package/src/lib/user-data.ts +15 -123
- package/src/pipeline/canonical-event-presentation.test.ts +5 -5
- package/src/pipeline/canonical-event-presentation.ts +13 -5
- package/src/pipeline/event-format.test.ts +106 -3
- package/src/pipeline/event-format.ts +172 -4
- package/src/pipeline/event-hints.test.ts +57 -4
- package/src/pipeline/event-hints.ts +34 -8
- package/src/runtime/canonical-monitor.test.ts +2 -0
- package/src/runtime/canonical-monitor.ts +6 -2
- package/src/runtime/clawclaw/agent-event-policy.test.ts +23 -2
- package/src/runtime/clawclaw/agent-event-policy.ts +12 -5
- package/src/runtime/clawclaw/behavior-decision.test.ts +29 -0
- package/src/runtime/clawclaw/behavior-decision.ts +82 -0
- package/src/runtime/clawclaw/behavior-input-fields.test.ts +175 -0
- package/src/runtime/clawclaw/behavior-input-fields.ts +270 -0
- package/src/runtime/clawclaw/behavior-input.test.ts +151 -0
- package/src/runtime/clawclaw/behavior-input.ts +70 -0
- package/src/runtime/clawclaw/behavior-observation-memory.test.ts +59 -0
- package/src/runtime/clawclaw/behavior-observation-memory.ts +142 -0
- package/src/runtime/clawclaw/behavior-read-api.test.ts +123 -0
- package/src/runtime/clawclaw/behavior-read-api.ts +158 -0
- package/src/runtime/clawclaw/{plugins/perception/visual-state-projector.ts → observation-frame-projector.ts} +44 -25
- package/src/runtime/clawclaw/owner.test.ts +187 -0
- package/src/runtime/clawclaw/owner.ts +431 -69
- package/src/runtime/clawclaw/plugins/action/action-plugin.test.ts +304 -0
- package/src/runtime/clawclaw/plugins/action/action-plugin.ts +285 -41
- package/src/runtime/clawclaw/plugins/action/automated-action-normalization.ts +82 -0
- package/src/runtime/clawclaw/plugins/assembly.test.ts +135 -29
- package/src/runtime/clawclaw/plugins/assembly.ts +54 -28
- package/src/runtime/clawclaw/plugins/behavior/activation-manager.test.ts +180 -0
- package/src/runtime/clawclaw/plugins/behavior/activation-manager.ts +468 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-action.test.ts +40 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-action.ts +30 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-analysis-thread-host.ts +152 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-catalog.test.ts +156 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-catalog.ts +104 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-manifest.ts +173 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-module-loader.test.ts +182 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-module-loader.ts +223 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-normalization.ts +157 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.test.ts +848 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.ts +1347 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-runner.ts +212 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-source.test.ts +174 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-source.ts +621 -0
- package/src/runtime/clawclaw/plugins/behavior/control-driver.test.ts +195 -0
- package/src/runtime/clawclaw/plugins/behavior/control-driver.ts +180 -0
- package/src/runtime/clawclaw/plugins/behavior/index.ts +11 -0
- package/src/runtime/clawclaw/plugins/behavior/official-goal-behavior.ts +766 -0
- package/src/runtime/clawclaw/plugins/behavior/thread-behavior-executor.test.ts +283 -0
- package/src/runtime/clawclaw/plugins/{strategy/thread-strategy-executor.ts → behavior/thread-behavior-executor.ts} +109 -121
- package/src/runtime/clawclaw/plugins/behavior-input-source.test.ts +80 -0
- package/src/runtime/clawclaw/plugins/behavior-input-source.ts +247 -0
- package/src/runtime/clawclaw/plugins/{strategy → game-query}/context-capabilities.ts +1 -1
- package/src/runtime/clawclaw/plugins/game-query/game-query-plugin.test.ts +13 -10
- package/src/runtime/clawclaw/plugins/game-query/game-query-plugin.ts +26 -14
- package/src/runtime/clawclaw/plugins/game-query/index.ts +1 -0
- package/src/runtime/clawclaw/plugins/index.ts +3 -1
- package/src/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-adapter.test.ts +239 -0
- package/src/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-adapter.ts +100 -0
- package/src/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-socket.ts +346 -0
- package/src/runtime/clawclaw/plugins/mailbox/agent-mailbox-coordinator.test.ts +230 -12
- package/src/runtime/clawclaw/plugins/mailbox/agent-mailbox-coordinator.ts +118 -90
- package/src/runtime/clawclaw/plugins/mailbox/consumer-ids.ts +5 -0
- package/src/runtime/clawclaw/plugins/mailbox/index.ts +3 -0
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-agent-event-batch.test.ts +1 -1
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-event-batch-delivery.ts +4 -0
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-plugin.test.ts +87 -0
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-plugin.ts +70 -12
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-presentation.ts +94 -11
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.test.ts +1229 -345
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.ts +479 -35
- package/src/runtime/clawclaw/plugins/perception/contracts.ts +4 -3
- package/src/runtime/clawclaw/plugins/perception/index.ts +1 -1
- package/src/runtime/clawclaw/plugins/perception/module-runner.test.ts +23 -13
- package/src/runtime/clawclaw/plugins/perception/module-runner.ts +11 -9
- package/src/runtime/clawclaw/plugins/perception/modules/co-movement-module.ts +39 -38
- package/src/runtime/clawclaw/plugins/perception/modules/corpse-visibility-module.test.ts +92 -0
- package/src/runtime/clawclaw/plugins/perception/modules/corpse-visibility-module.ts +248 -0
- package/src/runtime/clawclaw/plugins/perception/modules/follow-module.ts +39 -37
- package/src/runtime/clawclaw/plugins/perception/modules/index.ts +1 -0
- package/src/runtime/clawclaw/plugins/perception/modules/motion-module.test.ts +22 -21
- package/src/runtime/clawclaw/plugins/perception/modules/motion-module.ts +15 -9
- package/src/runtime/clawclaw/plugins/perception/modules/parallel-module-test-helpers.ts +3 -3
- package/src/runtime/clawclaw/plugins/perception/modules/relation-stability.test.ts +33 -18
- package/src/runtime/clawclaw/plugins/perception/modules/route-module.test.ts +6 -7
- package/src/runtime/clawclaw/plugins/perception/modules/route-module.ts +22 -16
- package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.test.ts +6 -7
- package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.ts +18 -12
- package/src/runtime/clawclaw/plugins/perception/modules/stop-module.test.ts +14 -10
- package/src/runtime/clawclaw/plugins/perception/modules/stop-module.ts +20 -14
- package/src/runtime/clawclaw/plugins/perception/modules/temporal-evidence.test.ts +5 -6
- package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.test.ts +5 -6
- package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.ts +49 -34
- package/src/runtime/clawclaw/plugins/perception/official-module-ids.ts +1 -0
- package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-pool.test.ts +126 -20
- package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-pool.ts +24 -3
- package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-worker.ts +59 -46
- package/src/runtime/clawclaw/plugins/perception/perception-module-loader.ts +27 -5
- package/src/runtime/clawclaw/plugins/perception/perception-plugin.test.ts +381 -49
- package/src/runtime/clawclaw/plugins/perception/perception-plugin.ts +267 -245
- package/src/runtime/clawclaw/plugins/perception/perception-source.test.ts +98 -0
- package/src/runtime/clawclaw/plugins/perception/perception-source.ts +89 -16
- package/src/runtime/clawclaw/plugins/perception/perception-test-fixtures.ts +34 -0
- package/src/runtime/clawclaw/plugins/perception/replay.test.ts +27 -15
- package/src/runtime/clawclaw/plugins/perception/replay.ts +10 -5
- package/src/runtime/clawclaw/plugins/perception/shared/math.ts +1 -107
- package/src/runtime/clawclaw/plugins/perception/spatial-facts.ts +7 -10
- package/src/runtime/clawclaw/plugins/plugin-api-version.ts +112 -0
- package/src/runtime/clawclaw/plugins/runtime-plugins.test.ts +388 -559
- package/src/runtime/clawclaw/plugins/source/player-change-tracker.test.ts +56 -5
- package/src/runtime/clawclaw/plugins/source/player-change-tracker.ts +135 -26
- package/src/runtime/clawclaw/plugins/source/source-plugin.test.ts +249 -16
- package/src/runtime/clawclaw/plugins/source/source-plugin.ts +99 -2
- package/src/runtime/clawclaw/plugins/source/task-change-tracker.test.ts +212 -0
- package/src/runtime/clawclaw/plugins/source/task-change-tracker.ts +259 -0
- package/src/runtime/clawclaw/plugins/trigger/contracts.ts +97 -0
- package/src/runtime/clawclaw/plugins/trigger/index.ts +4 -0
- package/src/runtime/clawclaw/plugins/trigger/trigger-module-loader.ts +118 -0
- package/src/runtime/clawclaw/plugins/trigger/trigger-plugin.test.ts +548 -0
- package/src/runtime/clawclaw/plugins/trigger/trigger-plugin.ts +655 -0
- package/src/runtime/clawclaw/plugins/trigger/trigger-source.test.ts +169 -0
- package/src/runtime/clawclaw/plugins/trigger/trigger-source.ts +457 -0
- package/src/runtime/clawclaw/runtime.ts +8 -0
- package/src/runtime/clawclaw/spatial-api.ts +76 -0
- package/src/runtime/clawclaw-event-catalog.test.ts +46 -1
- package/src/runtime/clawclaw-event-catalog.ts +40 -3
- package/src/runtime/framework/capability-registry.test.ts +196 -55
- package/src/runtime/framework/capability-registry.ts +99 -17
- package/src/runtime/framework/contracts.ts +30 -4
- package/src/runtime/framework/control/control-scheduler.ts +13 -5
- package/src/runtime/framework/control/types.ts +11 -4
- package/src/runtime/framework/control-coordinator.test.ts +95 -80
- package/src/runtime/framework/events/event-delivery-service.ts +4 -2
- package/src/runtime/framework/events/event-ingress.test.ts +25 -0
- package/src/runtime/framework/events/event-ingress.ts +2 -1
- package/src/runtime/framework/events/event-repository.ts +24 -2
- package/src/runtime/framework/events/mailbox-event-repositories.test.ts +124 -8
- package/src/runtime/framework/events/memory-event-repository.ts +92 -28
- package/src/runtime/framework/events/sqlite-event-repository.test.ts +604 -2
- package/src/runtime/framework/events/sqlite-event-repository.ts +531 -21
- package/src/runtime/framework/events/types.ts +24 -8
- package/src/runtime/framework/modules/runtime-module-loader-hooks.mjs +38 -1
- package/src/runtime/framework/modules/runtime-module-loader.test.ts +233 -7
- package/src/runtime/framework/modules/runtime-module-loader.ts +69 -4
- package/src/runtime/framework/plugins/contracts.ts +12 -18
- package/src/runtime/framework/plugins/runtime-plugin-scheduler.test.ts +81 -71
- package/src/runtime/framework/plugins/runtime-plugin-scheduler.ts +38 -20
- package/src/runtime/framework/runtime.ts +20 -23
- package/src/runtime/host-monitor-rate-gate.test.ts +73 -0
- package/src/runtime/host-monitor-rate-gate.ts +123 -0
- package/src/runtime/mailbox-host-relay.test.ts +45 -0
- package/src/runtime/mailbox-host-relay.ts +25 -0
- package/src/runtime/observability/factory.ts +4 -4
- package/src/runtime/observability/observability.test.ts +25 -3
- package/src/runtime/observability/reporter.ts +1 -1
- package/src/runtime/observability/types.ts +2 -2
- package/src/runtime/owner-control.ts +10 -2
- package/src/runtime/runtime-logger.test.ts +1 -1
- package/src/runtime/runtime-logger.ts +4 -6
- package/src/runtime/runtime.test.ts +88 -22
- package/src/sdk/action.ts +2 -2
- package/src/sdk/behavior-plugin/index.test.ts +74 -0
- package/src/sdk/behavior-plugin/index.ts +335 -0
- package/src/sdk/behavior-toolkit/corpse-search.ts +87 -0
- package/src/sdk/behavior-toolkit/escape.ts +40 -0
- package/src/sdk/behavior-toolkit/index.ts +7 -0
- package/src/sdk/behavior-toolkit/kill-flow.ts +299 -0
- package/src/sdk/behavior-toolkit/model.ts +263 -0
- package/src/sdk/behavior-toolkit/move-gate.ts +52 -0
- package/src/sdk/behavior-toolkit/patrol.ts +53 -0
- package/src/sdk/behavior-toolkit/search.ts +102 -0
- package/src/sdk/index.test.ts +45 -0
- package/src/sdk/index.ts +67 -73
- package/src/sdk/module-input/index.test.ts +49 -0
- package/src/sdk/module-input/index.ts +229 -0
- package/src/sdk/perception-plugin/index.test.ts +2 -2
- package/src/sdk/perception-plugin/index.ts +51 -142
- package/src/sdk/perception-plugin/math.ts +107 -0
- package/src/sdk/trigger-plugin/index.test.ts +41 -0
- package/src/sdk/trigger-plugin/index.ts +128 -0
- package/src/strategies/avoid-lone.ts +21 -10
- package/src/strategies/avoid-players.ts +26 -16
- package/src/strategies/corpse-patrol.ts +25 -14
- package/src/strategies/crab-sabotage.ts +20 -9
- package/src/strategies/find-player.ts +33 -21
- package/src/strategies/game-utils.ts +1 -1
- package/src/strategies/goals/crab-sabotage-top.test.ts +145 -0
- package/src/strategies/goals/crab-sabotage-top.ts +32 -69
- package/src/strategies/hide.ts +25 -15
- package/src/strategies/kill-frenzy.ts +21 -10
- package/src/strategies/kill-lone.ts +27 -17
- package/src/strategies/kill-target.ts +33 -22
- package/src/strategies/lone-kill-task.ts +20 -9
- package/src/strategies/move-room.ts +29 -18
- package/src/strategies/official-long-behavior.test.ts +89 -0
- package/src/strategies/paradise-fish.ts +29 -18
- package/src/strategies/pathfind/astar-path.test.ts +127 -2
- package/src/strategies/pathfind/astar-path.ts +136 -26
- package/src/strategies/patrol.ts +21 -10
- package/src/strategies/player-targets.test.ts +10 -0
- package/src/strategies/player-targets.ts +13 -0
- package/src/strategies/report-patrol.ts +21 -10
- package/src/strategies/shrimp-memory.ts +30 -19
- package/src/strategies/social-task.ts +34 -23
- package/src/strategies/task-kill-report.ts +33 -22
- package/src/strategies/task-only.test.ts +99 -85
- package/src/strategies/task-only.ts +23 -12
- package/src/strategies/task-report.ts +25 -14
- package/src/strategies/types.ts +8 -8
- package/src/strategies/warrior-memory.ts +29 -19
- package/docs/runtime/strategy-runtime.md +0 -111
- package/docs//350/207/252/345/256/232/344/271/211/346/204/237/347/237/245.md +0 -502
- package/docs//350/207/252/345/256/232/344/271/211/347/255/226/347/225/245.md +0 -395
- package/skills/clawclaw/references/STRATEGIES.md +0 -76
- package/src/commands/strategy.test.ts +0 -209
- package/src/commands/strategy.ts +0 -242
- package/src/lib/strategy-export.test.ts +0 -406
- package/src/lib/strategy-export.ts +0 -381
- package/src/runtime/clawclaw/plugins/perception/official-modules.ts +0 -31
- package/src/runtime/clawclaw/plugins/strategy/examples/task-only-strategy.test.ts +0 -177
- package/src/runtime/clawclaw/plugins/strategy/examples/task-only-strategy.ts +0 -191
- package/src/runtime/clawclaw/plugins/strategy/index.ts +0 -8
- package/src/runtime/clawclaw/plugins/strategy/local-strategy-executor.ts +0 -412
- package/src/runtime/clawclaw/plugins/strategy/strategy-action.ts +0 -80
- package/src/runtime/clawclaw/plugins/strategy/strategy-analysis-thread-host.ts +0 -183
- package/src/runtime/clawclaw/plugins/strategy/strategy-executor-types.ts +0 -29
- package/src/runtime/clawclaw/plugins/strategy/strategy-executor.test.ts +0 -693
- package/src/runtime/clawclaw/plugins/strategy/strategy-game-api.ts +0 -57
- package/src/runtime/clawclaw/plugins/strategy/strategy-module-loader.ts +0 -168
- package/src/runtime/clawclaw/plugins/strategy/strategy-plugin.test.ts +0 -2175
- package/src/runtime/clawclaw/plugins/strategy/strategy-plugin.ts +0 -1774
- package/src/runtime/clawclaw/plugins/strategy/strategy-source.test.ts +0 -153
- package/src/runtime/clawclaw/plugins/strategy/strategy-source.ts +0 -443
- package/src/sdk/strategy-plugin/index.test.ts +0 -958
- package/src/sdk/strategy-plugin/index.ts +0 -1350
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
import { tmpdir } from 'node:os';
|
|
8
8
|
import { join } from 'node:path';
|
|
9
9
|
import { afterEach, describe, expect, it } from 'vitest';
|
|
10
|
+
import { PerceptionModuleLoader } from './perception-module-loader.js';
|
|
10
11
|
import {
|
|
11
12
|
listClawclawPerceptionSources,
|
|
12
13
|
resolveClawclawPerceptionSource,
|
|
@@ -34,6 +35,7 @@ describe('ClawClaw perception source discovery', () => {
|
|
|
34
35
|
throw new Error('source discovery must not execute this file');
|
|
35
36
|
export default class Linger extends ClawclawPerception {
|
|
36
37
|
static readonly manifest = {
|
|
38
|
+
apiVersion: 2,
|
|
37
39
|
id: 'visual.custom_linger',
|
|
38
40
|
name: 'Custom linger',
|
|
39
41
|
description: 'Reports a long stay.',
|
|
@@ -66,6 +68,7 @@ describe('ClawClaw perception source discovery', () => {
|
|
|
66
68
|
expect.objectContaining({
|
|
67
69
|
id: 'visual.custom_linger',
|
|
68
70
|
manifest: {
|
|
71
|
+
apiVersion: 2,
|
|
69
72
|
id: 'visual.custom_linger',
|
|
70
73
|
name: 'Custom linger',
|
|
71
74
|
description: 'Reports a long stay.',
|
|
@@ -104,12 +107,75 @@ describe('ClawClaw perception source discovery', () => {
|
|
|
104
107
|
expect(listClawclawPerceptionSources(fixture.root)).toEqual([]);
|
|
105
108
|
});
|
|
106
109
|
|
|
110
|
+
it.each([
|
|
111
|
+
{ declaration: '', apiVersion: undefined, received: 'missing' },
|
|
112
|
+
{ declaration: 'apiVersion: 2.5,', apiVersion: undefined, received: 'missing' },
|
|
113
|
+
{ declaration: 'metadata: { apiVersion: 2 },', apiVersion: undefined, received: 'missing' },
|
|
114
|
+
{ declaration: 'apiVersion: 1,', apiVersion: 1, received: '1' },
|
|
115
|
+
])(
|
|
116
|
+
'keeps a structurally valid source visible so the loader diagnoses apiVersion=$received',
|
|
117
|
+
async ({ declaration, apiVersion, received }) => {
|
|
118
|
+
const fixture = workspace();
|
|
119
|
+
writeFileSync(join(fixture.perceptions, `unsupported-${received}.ts`), `
|
|
120
|
+
import { ClawclawPerception } from '@myclaw163/clawclaw-cli/perception-plugin';
|
|
121
|
+
export default class Unsupported extends ClawclawPerception {
|
|
122
|
+
static readonly manifest = {
|
|
123
|
+
${declaration}
|
|
124
|
+
id: 'visual.unsupported_${received}',
|
|
125
|
+
name: 'Unsupported',
|
|
126
|
+
description: 'Exercises explicit Perception API diagnostics.',
|
|
127
|
+
subjectScope: 'others',
|
|
128
|
+
produces: ['visual.unsupported_${received}'],
|
|
129
|
+
} as const;
|
|
130
|
+
update() {}
|
|
131
|
+
}
|
|
132
|
+
`);
|
|
133
|
+
|
|
134
|
+
const [source] = listClawclawPerceptionSources(fixture.root);
|
|
135
|
+
expect(source.id).toBe(`visual.unsupported_${received}`);
|
|
136
|
+
expect(source.apiVersion).toBe(apiVersion);
|
|
137
|
+
const loader = new PerceptionModuleLoader();
|
|
138
|
+
expect(() => loader.threadSpec(source)).toThrow(
|
|
139
|
+
`perception_api_version_unsupported:expected=2:received=${received}`,
|
|
140
|
+
);
|
|
141
|
+
await expect(loader.load(source)).rejects.toThrow(
|
|
142
|
+
`perception_api_version_unsupported:expected=2:received=${received}`,
|
|
143
|
+
);
|
|
144
|
+
},
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
it('decodes valid TypeScript escapes in static manifest strings', () => {
|
|
148
|
+
const fixture = workspace();
|
|
149
|
+
writeFileSync(join(fixture.perceptions, 'escaped.ts'), `
|
|
150
|
+
import { ClawclawPerception } from '@myclaw163/clawclaw-cli/perception-plugin';
|
|
151
|
+
export default class Escaped extends ClawclawPerception {
|
|
152
|
+
static readonly manifest = {
|
|
153
|
+
apiVersion: 2,
|
|
154
|
+
id: 'visual.escaped',
|
|
155
|
+
name: 'Escaped',
|
|
156
|
+
description: 'Reports the observer\\'s current view.\\nNo evaluation required.',
|
|
157
|
+
subjectScope: 'others',
|
|
158
|
+
produces: ['visual.escaped'],
|
|
159
|
+
} as const;
|
|
160
|
+
update() {}
|
|
161
|
+
}
|
|
162
|
+
`);
|
|
163
|
+
|
|
164
|
+
expect(listClawclawPerceptionSources(fixture.root)).toEqual([
|
|
165
|
+
expect.objectContaining({
|
|
166
|
+
id: 'visual.escaped',
|
|
167
|
+
description: "Reports the observer's current view.\nNo evaluation required.",
|
|
168
|
+
}),
|
|
169
|
+
]);
|
|
170
|
+
});
|
|
171
|
+
|
|
107
172
|
it('rejects event metadata that does not cover every produced event type', () => {
|
|
108
173
|
const fixture = workspace();
|
|
109
174
|
writeFileSync(join(fixture.perceptions, 'incomplete-events.ts'), `
|
|
110
175
|
import { ClawclawPerception } from '@myclaw163/clawclaw-cli/perception-plugin';
|
|
111
176
|
export default class IncompleteEvents extends ClawclawPerception {
|
|
112
177
|
static readonly manifest = {
|
|
178
|
+
apiVersion: 2,
|
|
113
179
|
id: 'visual.incomplete_events',
|
|
114
180
|
name: 'Incomplete events',
|
|
115
181
|
description: 'Declares incomplete event metadata.',
|
|
@@ -136,6 +202,7 @@ describe('ClawClaw perception source discovery', () => {
|
|
|
136
202
|
type Analysis = { frameSeq: number };
|
|
137
203
|
export default class Parallel extends ClawclawParallelPerception<Analysis> {
|
|
138
204
|
static readonly manifest = {
|
|
205
|
+
apiVersion: 2,
|
|
139
206
|
id: 'visual.parallel',
|
|
140
207
|
name: 'Parallel',
|
|
141
208
|
description: 'Analyzes frames concurrently and commits in order.',
|
|
@@ -167,6 +234,7 @@ describe('ClawClaw perception source discovery', () => {
|
|
|
167
234
|
import { ClawclawParallelPerception } from '@myclaw163/clawclaw-cli/perception-plugin';
|
|
168
235
|
export default class Mismatch extends ClawclawParallelPerception {
|
|
169
236
|
static manifest = {
|
|
237
|
+
apiVersion: 2,
|
|
170
238
|
id: 'visual.mismatch', name: 'Mismatch', description: 'Missing execution contract.',
|
|
171
239
|
subjectScope: 'others', produces: ['visual.mismatch'],
|
|
172
240
|
};
|
|
@@ -177,4 +245,34 @@ describe('ClawClaw perception source discovery', () => {
|
|
|
177
245
|
|
|
178
246
|
expect(listClawclawPerceptionSources(fixture.root)).toEqual([]);
|
|
179
247
|
});
|
|
248
|
+
|
|
249
|
+
it('keeps the last deterministic filename when multiple files declare the same id', () => {
|
|
250
|
+
const fixture = workspace();
|
|
251
|
+
const source = (name: string) => `
|
|
252
|
+
import { ClawclawPerception } from '@myclaw163/clawclaw-cli/perception-plugin';
|
|
253
|
+
export default class ${name} extends ClawclawPerception {
|
|
254
|
+
static manifest = {
|
|
255
|
+
apiVersion: 2,
|
|
256
|
+
id: 'visual.duplicate',
|
|
257
|
+
name: '${name}',
|
|
258
|
+
description: 'Duplicate source fixture.',
|
|
259
|
+
subjectScope: 'others',
|
|
260
|
+
produces: ['visual.duplicate'],
|
|
261
|
+
};
|
|
262
|
+
update() {}
|
|
263
|
+
}
|
|
264
|
+
`;
|
|
265
|
+
const last = join(fixture.perceptions, 'z-second.ts');
|
|
266
|
+
writeFileSync(last, source('SecondPerception'), 'utf8');
|
|
267
|
+
writeFileSync(join(fixture.perceptions, 'a-first.js'), source('FirstPerception'), 'utf8');
|
|
268
|
+
|
|
269
|
+
expect(() => listClawclawPerceptionSources(fixture.root)).not.toThrow();
|
|
270
|
+
expect(listClawclawPerceptionSources(fixture.root)).toEqual([
|
|
271
|
+
expect.objectContaining({
|
|
272
|
+
id: 'visual.duplicate',
|
|
273
|
+
name: 'SecondPerception',
|
|
274
|
+
sourcePath: last,
|
|
275
|
+
}),
|
|
276
|
+
]);
|
|
277
|
+
});
|
|
180
278
|
});
|
|
@@ -20,6 +20,8 @@ import type {
|
|
|
20
20
|
ClawclawPerceptionManifest,
|
|
21
21
|
ClawclawResourceLocalizations,
|
|
22
22
|
} from './contracts.js';
|
|
23
|
+
import { PERCEPTION_PLUGIN_API_VERSION } from './contracts.js';
|
|
24
|
+
import { literalPluginApiVersion } from '../plugin-api-version.js';
|
|
23
25
|
|
|
24
26
|
export const MAX_PERCEPTION_FILES = 512;
|
|
25
27
|
const MAX_PERCEPTION_SOURCE_BYTES = 2 * 1024 * 1024;
|
|
@@ -28,6 +30,8 @@ const DEFAULT_CLASS = /export\s+default\s+class(?:\s+[A-Za-z_$][\w$]*)?\s+extend
|
|
|
28
30
|
const STATIC_MANIFEST = /\bstatic\s+(?:readonly\s+)?manifest\s*=\s*\{/;
|
|
29
31
|
|
|
30
32
|
export interface ResolvedClawclawPerceptionSource {
|
|
33
|
+
/** Literal source declaration; retained so the loader can diagnose unsupported modules. */
|
|
34
|
+
readonly apiVersion?: number;
|
|
31
35
|
readonly id: string;
|
|
32
36
|
readonly name: string;
|
|
33
37
|
readonly description: string;
|
|
@@ -150,12 +154,69 @@ function topLevelObjectPropertyBlock(source: string, property: string): string |
|
|
|
150
154
|
return undefined;
|
|
151
155
|
}
|
|
152
156
|
|
|
153
|
-
function decodeString(raw: string): string | null {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
157
|
+
function decodeString(raw: string, quote: "'" | '"' | '`'): string | null {
|
|
158
|
+
let decoded = '';
|
|
159
|
+
for (let index = 0; index < raw.length; index += 1) {
|
|
160
|
+
const char = raw[index]!;
|
|
161
|
+
if (char !== '\\') {
|
|
162
|
+
if (quote !== '`' && (char === '\n' || char === '\r')) return null;
|
|
163
|
+
decoded += char;
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
const escaped = raw[index + 1];
|
|
167
|
+
if (escaped === undefined) return null;
|
|
168
|
+
index += 1;
|
|
169
|
+
if (escaped === '\n') continue;
|
|
170
|
+
if (escaped === '\r') {
|
|
171
|
+
if (raw[index + 1] === '\n') index += 1;
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
const simple = {
|
|
175
|
+
"'": "'",
|
|
176
|
+
'"': '"',
|
|
177
|
+
'`': '`',
|
|
178
|
+
'\\': '\\',
|
|
179
|
+
n: '\n',
|
|
180
|
+
r: '\r',
|
|
181
|
+
t: '\t',
|
|
182
|
+
b: '\b',
|
|
183
|
+
f: '\f',
|
|
184
|
+
v: '\v',
|
|
185
|
+
0: '\0',
|
|
186
|
+
} as const;
|
|
187
|
+
if (escaped in simple) {
|
|
188
|
+
if (escaped === '0' && /[0-9]/.test(raw[index + 1] ?? '')) return null;
|
|
189
|
+
decoded += simple[escaped as keyof typeof simple];
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
if (escaped === 'x') {
|
|
193
|
+
const digits = raw.slice(index + 1, index + 3);
|
|
194
|
+
if (!/^[0-9a-fA-F]{2}$/.test(digits)) return null;
|
|
195
|
+
decoded += String.fromCharCode(Number.parseInt(digits, 16));
|
|
196
|
+
index += 2;
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
if (escaped === 'u') {
|
|
200
|
+
if (raw[index + 1] === '{') {
|
|
201
|
+
const close = raw.indexOf('}', index + 2);
|
|
202
|
+
if (close < 0) return null;
|
|
203
|
+
const digits = raw.slice(index + 2, close);
|
|
204
|
+
if (!/^[0-9a-fA-F]{1,6}$/.test(digits)) return null;
|
|
205
|
+
const codePoint = Number.parseInt(digits, 16);
|
|
206
|
+
if (codePoint > 0x10ffff) return null;
|
|
207
|
+
decoded += String.fromCodePoint(codePoint);
|
|
208
|
+
index = close;
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
const digits = raw.slice(index + 1, index + 5);
|
|
212
|
+
if (!/^[0-9a-fA-F]{4}$/.test(digits)) return null;
|
|
213
|
+
decoded += String.fromCharCode(Number.parseInt(digits, 16));
|
|
214
|
+
index += 4;
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
return null;
|
|
158
218
|
}
|
|
219
|
+
return decoded;
|
|
159
220
|
}
|
|
160
221
|
|
|
161
222
|
function literalProperty(source: string, property: string): string | null {
|
|
@@ -177,7 +238,7 @@ function literalProperty(source: string, property: string): string | null {
|
|
|
177
238
|
if (char !== quote) continue;
|
|
178
239
|
const raw = source.slice(start, index);
|
|
179
240
|
if (quote === '`' && raw.includes('${')) return null;
|
|
180
|
-
return decodeString(raw);
|
|
241
|
+
return decodeString(raw, quote as "'" | '"' | '`');
|
|
181
242
|
}
|
|
182
243
|
return null;
|
|
183
244
|
}
|
|
@@ -193,7 +254,7 @@ function literalStringArray(source: string, property: string): string[] | null {
|
|
|
193
254
|
let item: RegExpExecArray | null;
|
|
194
255
|
while ((item = matcher.exec(block)) !== null) {
|
|
195
256
|
if (item[1] === '`' && item[2].includes('${')) return null;
|
|
196
|
-
const decoded = decodeString(item[2]);
|
|
257
|
+
const decoded = decodeString(item[2], item[1] as "'" | '"' | '`');
|
|
197
258
|
if (decoded === null) return null;
|
|
198
259
|
values.push(decoded);
|
|
199
260
|
}
|
|
@@ -213,7 +274,7 @@ function literalLocalizations(
|
|
|
213
274
|
while ((match = entry.exec(block)) !== null) {
|
|
214
275
|
if (block.slice(cursor, match.index).replace(/[\s,]/g, '')) return null;
|
|
215
276
|
if (match[1] === '`' && match[2].includes('${')) return null;
|
|
216
|
-
const locale = decodeString(match[2])?.trim();
|
|
277
|
+
const locale = decodeString(match[2], match[1] as "'" | '"' | '`')?.trim();
|
|
217
278
|
const entryOpen = match.index + match[0].lastIndexOf('{');
|
|
218
279
|
const entryBlock = balancedBlock(block, entryOpen, '{', '}');
|
|
219
280
|
if (!locale || !entryBlock || values[locale]) return null;
|
|
@@ -240,7 +301,7 @@ function literalEventMetadata(
|
|
|
240
301
|
while ((match = entry.exec(block)) !== null) {
|
|
241
302
|
if (block.slice(cursor, match.index).replace(/[\s,]/g, '')) return null;
|
|
242
303
|
if (match[1] === '`' && match[2].includes('${')) return null;
|
|
243
|
-
const type = decodeString(match[2])?.trim();
|
|
304
|
+
const type = decodeString(match[2], match[1] as "'" | '"' | '`')?.trim();
|
|
244
305
|
const entryOpen = match.index + match[0].lastIndexOf('{');
|
|
245
306
|
const entryBlock = balancedBlock(block, entryOpen, '{', '}');
|
|
246
307
|
if (!type || !entryBlock || values[type]) return null;
|
|
@@ -279,6 +340,7 @@ function parseSource(sourcePath: string, sourceRoot: string): ResolvedClawclawPe
|
|
|
279
340
|
const manifestBlock = balancedBlock(classBody, manifestOpen, '{', '}');
|
|
280
341
|
if (!manifestBlock) return null;
|
|
281
342
|
|
|
343
|
+
const apiVersion = literalPluginApiVersion(manifestBlock) ?? null;
|
|
282
344
|
const id = literalProperty(manifestBlock, 'id')?.trim();
|
|
283
345
|
const name = literalProperty(manifestBlock, 'name')?.trim();
|
|
284
346
|
const description = literalProperty(manifestBlock, 'description')?.trim();
|
|
@@ -316,7 +378,10 @@ function parseSource(sourcePath: string, sourceRoot: string): ResolvedClawclawPe
|
|
|
316
378
|
)
|
|
317
379
|
) return null;
|
|
318
380
|
|
|
319
|
-
const manifest
|
|
381
|
+
const manifest = {
|
|
382
|
+
...(apiVersion === null ? {} : {
|
|
383
|
+
apiVersion: apiVersion as typeof PERCEPTION_PLUGIN_API_VERSION,
|
|
384
|
+
}),
|
|
320
385
|
id,
|
|
321
386
|
name,
|
|
322
387
|
description,
|
|
@@ -326,11 +391,19 @@ function parseSource(sourcePath: string, sourceRoot: string): ResolvedClawclawPe
|
|
|
326
391
|
...(eventMetadata === undefined ? {} : { eventMetadata }),
|
|
327
392
|
...(execution ? { execution: 'parallel_analysis' as const } : {}),
|
|
328
393
|
...(boundaryBaseline ? { boundaryBaseline: 'current_only' as const } : {}),
|
|
394
|
+
} as ClawclawPerceptionManifest;
|
|
395
|
+
return {
|
|
396
|
+
...(apiVersion === null ? {} : { apiVersion }),
|
|
397
|
+
id,
|
|
398
|
+
name,
|
|
399
|
+
description,
|
|
400
|
+
manifest,
|
|
401
|
+
sourcePath,
|
|
402
|
+
sourceRoot,
|
|
329
403
|
};
|
|
330
|
-
return { id, name, description, manifest, sourcePath, sourceRoot };
|
|
331
404
|
}
|
|
332
405
|
|
|
333
|
-
/** Lists
|
|
406
|
+
/** Lists installed perception classes by reading static manifests without evaluating their code. */
|
|
334
407
|
export function listClawclawPerceptionSources(
|
|
335
408
|
workspaceDir = getWorkspaceDir(),
|
|
336
409
|
): ResolvedClawclawPerceptionSource[] {
|
|
@@ -361,11 +434,11 @@ export function listClawclawPerceptionSources(
|
|
|
361
434
|
if (!pathInside(root, sourcePath) || dirname(sourcePath) !== root) continue;
|
|
362
435
|
const source = parseSource(sourcePath, root);
|
|
363
436
|
if (!source) continue;
|
|
364
|
-
|
|
437
|
+
// Match Strategy discovery: sorted filenames are deterministic and the
|
|
438
|
+
// last declaration wins. Duplicate entries stay recoverable and never
|
|
439
|
+
// make Owner terminal.
|
|
365
440
|
sources.set(source.id, source);
|
|
366
|
-
} catch
|
|
367
|
-
if (error instanceof Error && error.message.startsWith('Duplicate perception')) throw error;
|
|
368
|
-
}
|
|
441
|
+
} catch {}
|
|
369
442
|
}
|
|
370
443
|
return [...sources.values()];
|
|
371
444
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { GameState } from '../../../../sdk/module-input/index.js';
|
|
2
|
+
|
|
3
|
+
/** Complete canonical GameSync snapshot for Perception unit tests. */
|
|
4
|
+
export function perceptionTestGameState(
|
|
5
|
+
tick: number,
|
|
6
|
+
overrides: Partial<GameState> = {},
|
|
7
|
+
): Readonly<GameState> {
|
|
8
|
+
const observer = Object.freeze({ seat: 1, name: 'Observer' });
|
|
9
|
+
return Object.freeze({
|
|
10
|
+
game_id: 'perception-test-game',
|
|
11
|
+
phase: 'wandering',
|
|
12
|
+
tick,
|
|
13
|
+
you: Object.freeze({
|
|
14
|
+
player: observer,
|
|
15
|
+
x: 0,
|
|
16
|
+
y: 0,
|
|
17
|
+
room: '测试区',
|
|
18
|
+
role: 'lobster',
|
|
19
|
+
faction: 'lobster',
|
|
20
|
+
is_alive: true,
|
|
21
|
+
completed_task_count: 0,
|
|
22
|
+
activity: Object.freeze({ kind: 'idle' as const }),
|
|
23
|
+
}),
|
|
24
|
+
players: Object.freeze([Object.freeze({
|
|
25
|
+
...observer,
|
|
26
|
+
known_status: Object.freeze({ is_alive: true }),
|
|
27
|
+
})]),
|
|
28
|
+
task_progress: Object.freeze({ completed: 0, goal: 1 }),
|
|
29
|
+
emergency: Object.freeze({ active: false }),
|
|
30
|
+
meeting: Object.freeze({ active: false }),
|
|
31
|
+
octopus_time: Object.freeze({ active: false }),
|
|
32
|
+
...overrides,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { mkdtempSync, rmSync } from 'node:fs';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
1
4
|
import { describe, expect, it } from 'vitest';
|
|
2
5
|
import type { StoredStateFrame } from '../../../framework/state/history/contracts.js';
|
|
3
6
|
import { replayPerceptionFrames } from './replay.js';
|
|
@@ -44,22 +47,31 @@ function frame(frameSeq: number, tick: number, x: number): StoredStateFrame<Reco
|
|
|
44
47
|
|
|
45
48
|
describe('perception replay', () => {
|
|
46
49
|
it('rebuilds long-lived state before capturing the requested tick', async () => {
|
|
50
|
+
const workspaceDir = mkdtempSync(join(tmpdir(), 'ccl-perception-replay-'));
|
|
47
51
|
const frames = Array.from({ length: 20 }, (_, index) => frame(index + 1, index, index * 6));
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
try {
|
|
53
|
+
const first = await replayPerceptionFrames(frames, {
|
|
54
|
+
modules: ['visual.motion'],
|
|
55
|
+
fromTick: 19,
|
|
56
|
+
toTick: 19,
|
|
57
|
+
workspaceDir,
|
|
58
|
+
});
|
|
59
|
+
const second = await replayPerceptionFrames(frames, {
|
|
60
|
+
modules: ['visual.motion'],
|
|
61
|
+
fromTick: 19,
|
|
62
|
+
toTick: 19,
|
|
63
|
+
workspaceDir,
|
|
64
|
+
});
|
|
58
65
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
66
|
+
expect(first).toEqual(second);
|
|
67
|
+
expect(first.frames).toHaveLength(1);
|
|
68
|
+
expect(first.frames[0].perceptionFrame?.tick).toBe(19);
|
|
69
|
+
expect(first.frames[0].perceptionFrame?.gameState).toMatchObject({ tick: 19 });
|
|
70
|
+
expect(first.frames[0]).not.toHaveProperty('visual');
|
|
71
|
+
expect(first.frames[0].moduleStates['visual.motion']).toMatchObject({ latest_tick: 19 });
|
|
72
|
+
expect(first.proposals.some((proposal) => proposal.type === 'visual.player_moved')).toBe(true);
|
|
73
|
+
} finally {
|
|
74
|
+
rmSync(workspaceDir, { recursive: true, force: true });
|
|
75
|
+
}
|
|
64
76
|
});
|
|
65
77
|
});
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { RuntimeEventProposal } from '../../../framework/plugins/index.js';
|
|
2
2
|
import type { StoredStateFrame } from '../../../framework/state/history/contracts.js';
|
|
3
|
-
import
|
|
3
|
+
import { getWorkspaceDir } from '../../../../lib/init-command.js';
|
|
4
|
+
import { syncOfficialPerceptions } from '../../../../lib/perception-export.js';
|
|
5
|
+
import type { ClawclawPerceptionManifest, PerceptionFrame } from './contracts.js';
|
|
4
6
|
import {
|
|
5
7
|
ClawclawPerceptionPlugin,
|
|
6
8
|
type ClawclawPerceptionConfig,
|
|
@@ -10,7 +12,7 @@ export interface PerceptionReplayFrame {
|
|
|
10
12
|
frameSeq: number;
|
|
11
13
|
backendTick: number | null;
|
|
12
14
|
receivedAtMs: number;
|
|
13
|
-
|
|
15
|
+
perceptionFrame: PerceptionFrame | null;
|
|
14
16
|
proposals: readonly RuntimeEventProposal[];
|
|
15
17
|
moduleStates: Record<string, unknown>;
|
|
16
18
|
}
|
|
@@ -44,8 +46,11 @@ export async function replayPerceptionFrames(
|
|
|
44
46
|
inputFrames: readonly StoredStateFrame<Record<string, any>>[],
|
|
45
47
|
options: PerceptionReplayOptions = {},
|
|
46
48
|
): Promise<PerceptionReplayResult> {
|
|
49
|
+
const workspaceDir = options.workspaceDir ?? getWorkspaceDir();
|
|
50
|
+
await syncOfficialPerceptions({ workspaceDir });
|
|
47
51
|
const plugin = new ClawclawPerceptionPlugin({
|
|
48
52
|
modules: options.modules,
|
|
53
|
+
workspaceDir,
|
|
49
54
|
});
|
|
50
55
|
const frames: PerceptionReplayFrame[] = [];
|
|
51
56
|
const emitted: PerceptionReplayResult['proposals'] = [];
|
|
@@ -55,9 +60,9 @@ export async function replayPerceptionFrames(
|
|
|
55
60
|
await plugin.startForReplay(signal);
|
|
56
61
|
for (const frame of ordered) {
|
|
57
62
|
const inspection = await plugin.inspectFrame(frame, signal);
|
|
58
|
-
const
|
|
63
|
+
const perceptionFrame = inspection.visual;
|
|
59
64
|
const frameProposals = inspection.proposals;
|
|
60
|
-
const emittedAtTick =
|
|
65
|
+
const emittedAtTick = perceptionFrame?.tick ?? frame.backendTick ?? null;
|
|
61
66
|
for (const proposal of frameProposals) {
|
|
62
67
|
emitted.push({
|
|
63
68
|
...proposal,
|
|
@@ -70,7 +75,7 @@ export async function replayPerceptionFrames(
|
|
|
70
75
|
frameSeq: frame.frameSeq,
|
|
71
76
|
backendTick: frame.backendTick ?? null,
|
|
72
77
|
receivedAtMs: frame.receivedAtMs,
|
|
73
|
-
|
|
78
|
+
perceptionFrame,
|
|
74
79
|
proposals: frameProposals,
|
|
75
80
|
moduleStates: inspection.moduleStates,
|
|
76
81
|
});
|
|
@@ -1,107 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export const TICK_MS = 100;
|
|
4
|
-
export const MOVE_MIN_PX = 18;
|
|
5
|
-
export const STEP_MOVE_MIN_PX = 4;
|
|
6
|
-
export const STILL_STEP_MAX_PX = 3;
|
|
7
|
-
|
|
8
|
-
export interface Vec {
|
|
9
|
-
x: number;
|
|
10
|
-
y: number;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function vector(from: Vec, to: Vec): Vec {
|
|
14
|
-
return { x: to.x - from.x, y: to.y - from.y };
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function length(value: Vec): number {
|
|
18
|
-
return Math.hypot(value.x, value.y);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function distance(a: Vec, b: Vec): number {
|
|
22
|
-
return Math.hypot(a.x - b.x, a.y - b.y);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function dot(a: Vec, b: Vec): number {
|
|
26
|
-
return a.x * b.x + a.y * b.y;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function cross(a: Vec, b: Vec): number {
|
|
30
|
-
return a.x * b.y - a.y * b.x;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function unit(value: Vec): Vec {
|
|
34
|
-
const magnitude = length(value);
|
|
35
|
-
return magnitude <= 0 ? { x: 0, y: 0 } : { x: value.x / magnitude, y: value.y / magnitude };
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function cosine(a: Vec, b: Vec): number {
|
|
39
|
-
const denominator = length(a) * length(b);
|
|
40
|
-
return denominator <= 0 ? 0 : dot(a, b) / denominator;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function angleDegrees(a: Vec, b: Vec): number {
|
|
44
|
-
return Math.acos(Math.max(-1, Math.min(1, cosine(a, b)))) * (180 / Math.PI);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export type Direction = '左' | '右' | '上' | '下' | '左上' | '左下' | '右上' | '右下' | '原地';
|
|
48
|
-
|
|
49
|
-
export function direction(from: Vec, to: Vec, minimum = MOVE_MIN_PX): Direction {
|
|
50
|
-
const dx = to.x - from.x;
|
|
51
|
-
const dy = to.y - from.y;
|
|
52
|
-
if (Math.hypot(dx, dy) < minimum) return '原地';
|
|
53
|
-
const horizontal = Math.abs(dx) >= minimum / 2 ? (dx > 0 ? '右' : '左') : '';
|
|
54
|
-
const vertical = Math.abs(dy) >= minimum / 2 ? (dy > 0 ? '下' : '上') : '';
|
|
55
|
-
return `${horizontal}${vertical}` as Direction || '原地';
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Quantizes a displacement by its heading rather than by absolute component
|
|
60
|
-
* sizes. Unlike direction(), this label does not change merely because the
|
|
61
|
-
* same straight trajectory is measured over a shorter or longer window.
|
|
62
|
-
*/
|
|
63
|
-
export function headingDirection(from: Vec, to: Vec, minimum = MOVE_MIN_PX): Direction {
|
|
64
|
-
const dx = to.x - from.x;
|
|
65
|
-
const dy = to.y - from.y;
|
|
66
|
-
if (Math.hypot(dx, dy) < minimum) return '原地';
|
|
67
|
-
const octant = Math.round(Math.atan2(dy, dx) / (Math.PI / 4));
|
|
68
|
-
const directions: readonly Direction[] = [
|
|
69
|
-
'右',
|
|
70
|
-
'右下',
|
|
71
|
-
'下',
|
|
72
|
-
'左下',
|
|
73
|
-
'左',
|
|
74
|
-
'左上',
|
|
75
|
-
'上',
|
|
76
|
-
'右上',
|
|
77
|
-
];
|
|
78
|
-
return directions[(octant + directions.length) % directions.length];
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export function actorLabel(actor: { observer: boolean; seat?: number; name?: string; id: string }): string {
|
|
82
|
-
if (actor.observer) return '你';
|
|
83
|
-
if (actor.seat !== undefined) return `${actor.seat}号`;
|
|
84
|
-
return actor.name ?? actor.id;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export function actorValue(actor: { observer: boolean; seat?: number; id: string }): number | string {
|
|
88
|
-
return actor.seat ?? actor.id;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export function timeRange(fromTick: number, toTick: number): string {
|
|
92
|
-
const format = (tick: number): string => {
|
|
93
|
-
const total = Math.max(0, Math.floor((tick * TICK_MS) / 1000));
|
|
94
|
-
return `${Math.floor(total / 60)}:${String(total % 60).padStart(2, '0')}`;
|
|
95
|
-
};
|
|
96
|
-
const from = format(fromTick);
|
|
97
|
-
const to = format(toTick);
|
|
98
|
-
return from === to ? from : `${from}-${to}`;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export function round1(value: number): number {
|
|
102
|
-
return Math.round(value * 10) / 10;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export function positionCopy(position: VisualPosition): VisualPosition {
|
|
106
|
-
return { x: position.x, y: position.y, room: position.room };
|
|
107
|
-
}
|
|
1
|
+
export * from '../../../../../sdk/perception-plugin/math.js';
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { readFileSync } from 'fs';
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
VisualPosition,
|
|
5
|
-
} from './contracts.js';
|
|
6
|
-
import { createPerceptionSpatialApi } from '../../../../sdk/perception-plugin/index.js';
|
|
2
|
+
import type { VisualPosition } from './contracts.js';
|
|
3
|
+
import { createSpatialApi, type SpatialFacts } from '../../spatial-api.js';
|
|
7
4
|
|
|
8
5
|
export interface MapRoomArea {
|
|
9
6
|
name: string;
|
|
@@ -16,7 +13,7 @@ export interface SpatialTransition {
|
|
|
16
13
|
b: string;
|
|
17
14
|
}
|
|
18
15
|
|
|
19
|
-
interface
|
|
16
|
+
interface RawSpatialFacts {
|
|
20
17
|
schema_version: 2;
|
|
21
18
|
coordinates: {
|
|
22
19
|
x_positive: 'right';
|
|
@@ -29,10 +26,10 @@ interface SpatialFacts {
|
|
|
29
26
|
room_transitions: SpatialTransition[];
|
|
30
27
|
}
|
|
31
28
|
|
|
32
|
-
function loadSpatialFacts():
|
|
29
|
+
function loadSpatialFacts(): RawSpatialFacts {
|
|
33
30
|
const parsed = JSON.parse(
|
|
34
31
|
readFileSync(new URL('../../../../assets/clawclaw-spatial-facts.json', import.meta.url), 'utf8'),
|
|
35
|
-
) as
|
|
32
|
+
) as RawSpatialFacts;
|
|
36
33
|
if (
|
|
37
34
|
parsed.schema_version !== 2
|
|
38
35
|
|| parsed.coordinates?.x_positive !== 'right'
|
|
@@ -101,7 +98,7 @@ export function transitionIsMapped(from: string | null, to: string | null): bool
|
|
|
101
98
|
));
|
|
102
99
|
}
|
|
103
100
|
|
|
104
|
-
export const CLAWCLAW_PERCEPTION_SPATIAL_FACTS:
|
|
101
|
+
export const CLAWCLAW_PERCEPTION_SPATIAL_FACTS: SpatialFacts = Object.freeze({
|
|
105
102
|
coordinates: Object.freeze({ xPositive: 'right', yPositive: 'down' }),
|
|
106
103
|
playerBodyLengthPx: PLAYER_BODY_LENGTH_PX,
|
|
107
104
|
rooms: CLAWCLAW_SPATIAL_FACTS.rooms,
|
|
@@ -109,6 +106,6 @@ export const CLAWCLAW_PERCEPTION_SPATIAL_FACTS: PerceptionSpatialFacts = Object.
|
|
|
109
106
|
});
|
|
110
107
|
|
|
111
108
|
/** Read-only map capability exposed to perception module code. */
|
|
112
|
-
export const CLAWCLAW_PERCEPTION_SPATIAL_API =
|
|
109
|
+
export const CLAWCLAW_PERCEPTION_SPATIAL_API = createSpatialApi(
|
|
113
110
|
CLAWCLAW_PERCEPTION_SPATIAL_FACTS,
|
|
114
111
|
);
|