@myclaw163/clawclaw-cli 0.7.15 → 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 +3 -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 +286 -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 +389 -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 -1994
- package/src/runtime/clawclaw/plugins/strategy/strategy-plugin.ts +0 -1579
- 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
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import type { BehaviorInputFieldSpec } from '../../../sdk/behavior-plugin/index.js';
|
|
2
|
+
import { normalizeBehaviorInputFields } from '../behavior-input-fields.js';
|
|
3
|
+
|
|
4
|
+
export type LiteralBehaviorInputFieldsResult =
|
|
5
|
+
| Readonly<{ status: 'missing' }>
|
|
6
|
+
| Readonly<{ status: 'valid'; inputs: readonly Readonly<BehaviorInputFieldSpec>[] }>
|
|
7
|
+
| Readonly<{ status: 'invalid'; diagnostic: string }>;
|
|
8
|
+
|
|
9
|
+
interface ParsedValue {
|
|
10
|
+
readonly value: unknown;
|
|
11
|
+
readonly next: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
class LiteralParseError extends Error {}
|
|
15
|
+
|
|
16
|
+
function skipTrivia(source: string, start: number): number {
|
|
17
|
+
let cursor = start;
|
|
18
|
+
while (cursor < source.length) {
|
|
19
|
+
if (/\s/.test(source[cursor])) {
|
|
20
|
+
cursor += 1;
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
if (source.startsWith('//', cursor)) {
|
|
24
|
+
const end = source.indexOf('\n', cursor + 2);
|
|
25
|
+
cursor = end < 0 ? source.length : end + 1;
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (source.startsWith('/*', cursor)) {
|
|
29
|
+
const end = source.indexOf('*/', cursor + 2);
|
|
30
|
+
if (end < 0) throw new LiteralParseError('behavior_inputs_literal_invalid');
|
|
31
|
+
cursor = end + 2;
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
return cursor;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function parseString(source: string, start: number): ParsedValue {
|
|
40
|
+
const quote = source[start];
|
|
41
|
+
if (quote !== "'" && quote !== '"' && quote !== '`') {
|
|
42
|
+
throw new LiteralParseError('behavior_inputs_literal_invalid');
|
|
43
|
+
}
|
|
44
|
+
let value = '';
|
|
45
|
+
for (let cursor = start + 1; cursor < source.length; cursor += 1) {
|
|
46
|
+
const char = source[cursor];
|
|
47
|
+
if (char === quote) return { value, next: cursor + 1 };
|
|
48
|
+
if (quote === '`' && char === '$' && source[cursor + 1] === '{') {
|
|
49
|
+
throw new LiteralParseError('behavior_inputs_not_literal');
|
|
50
|
+
}
|
|
51
|
+
if (char !== '\\') {
|
|
52
|
+
value += char;
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
cursor += 1;
|
|
56
|
+
if (cursor >= source.length) throw new LiteralParseError('behavior_inputs_literal_invalid');
|
|
57
|
+
const escaped = source[cursor];
|
|
58
|
+
if (escaped === 'n') value += '\n';
|
|
59
|
+
else if (escaped === 'r') value += '\r';
|
|
60
|
+
else if (escaped === 't') value += '\t';
|
|
61
|
+
else if (escaped === 'b') value += '\b';
|
|
62
|
+
else if (escaped === 'f') value += '\f';
|
|
63
|
+
else if (escaped === 'v') value += '\v';
|
|
64
|
+
else if (escaped === '0') value += '\0';
|
|
65
|
+
else if (escaped === '\n') continue;
|
|
66
|
+
else if (escaped === '\r') {
|
|
67
|
+
if (source[cursor + 1] === '\n') cursor += 1;
|
|
68
|
+
} else if (escaped === 'x') {
|
|
69
|
+
const hex = source.slice(cursor + 1, cursor + 3);
|
|
70
|
+
if (!/^[0-9a-f]{2}$/i.test(hex)) throw new LiteralParseError('behavior_inputs_literal_invalid');
|
|
71
|
+
value += String.fromCharCode(Number.parseInt(hex, 16));
|
|
72
|
+
cursor += 2;
|
|
73
|
+
} else if (escaped === 'u') {
|
|
74
|
+
const hex = source.slice(cursor + 1, cursor + 5);
|
|
75
|
+
if (!/^[0-9a-f]{4}$/i.test(hex)) throw new LiteralParseError('behavior_inputs_literal_invalid');
|
|
76
|
+
value += String.fromCharCode(Number.parseInt(hex, 16));
|
|
77
|
+
cursor += 4;
|
|
78
|
+
} else value += escaped;
|
|
79
|
+
}
|
|
80
|
+
throw new LiteralParseError('behavior_inputs_literal_invalid');
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function consumeAsConst(source: string, start: number): number {
|
|
84
|
+
const cursor = skipTrivia(source, start);
|
|
85
|
+
const match = /^as\s+const\b/.exec(source.slice(cursor));
|
|
86
|
+
return match ? cursor + match[0].length : start;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function parseArray(source: string, start: number): ParsedValue {
|
|
90
|
+
const values: unknown[] = [];
|
|
91
|
+
let cursor = skipTrivia(source, start + 1);
|
|
92
|
+
if (source[cursor] === ']') {
|
|
93
|
+
const next = cursor + 1;
|
|
94
|
+
return { value: values, next: consumeAsConst(source, next) };
|
|
95
|
+
}
|
|
96
|
+
while (cursor < source.length) {
|
|
97
|
+
const parsed = parseValue(source, cursor);
|
|
98
|
+
values.push(parsed.value);
|
|
99
|
+
cursor = skipTrivia(source, parsed.next);
|
|
100
|
+
if (source[cursor] === ']') {
|
|
101
|
+
const next = cursor + 1;
|
|
102
|
+
return { value: values, next: consumeAsConst(source, next) };
|
|
103
|
+
}
|
|
104
|
+
if (source[cursor] !== ',') throw new LiteralParseError('behavior_inputs_literal_invalid');
|
|
105
|
+
cursor = skipTrivia(source, cursor + 1);
|
|
106
|
+
if (source[cursor] === ']') {
|
|
107
|
+
const next = cursor + 1;
|
|
108
|
+
return { value: values, next: consumeAsConst(source, next) };
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
throw new LiteralParseError('behavior_inputs_literal_invalid');
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function parseObject(source: string, start: number): ParsedValue {
|
|
115
|
+
const value: Record<string, unknown> = {};
|
|
116
|
+
let cursor = skipTrivia(source, start + 1);
|
|
117
|
+
if (source[cursor] === '}') return { value, next: cursor + 1 };
|
|
118
|
+
while (cursor < source.length) {
|
|
119
|
+
let key: string;
|
|
120
|
+
if (source[cursor] === "'" || source[cursor] === '"' || source[cursor] === '`') {
|
|
121
|
+
const parsedKey = parseString(source, cursor);
|
|
122
|
+
key = String(parsedKey.value);
|
|
123
|
+
cursor = skipTrivia(source, parsedKey.next);
|
|
124
|
+
} else {
|
|
125
|
+
const identifier = /^[A-Za-z_$][\w$]*/.exec(source.slice(cursor));
|
|
126
|
+
if (!identifier) throw new LiteralParseError('behavior_inputs_literal_invalid');
|
|
127
|
+
key = identifier[0];
|
|
128
|
+
cursor = skipTrivia(source, cursor + key.length);
|
|
129
|
+
}
|
|
130
|
+
if (Object.prototype.hasOwnProperty.call(value, key)) {
|
|
131
|
+
throw new LiteralParseError(`behavior_inputs_literal_duplicate_property:${key}`);
|
|
132
|
+
}
|
|
133
|
+
if (source[cursor] !== ':') throw new LiteralParseError('behavior_inputs_literal_invalid');
|
|
134
|
+
const parsed = parseValue(source, skipTrivia(source, cursor + 1));
|
|
135
|
+
Object.defineProperty(value, key, {
|
|
136
|
+
configurable: true,
|
|
137
|
+
enumerable: true,
|
|
138
|
+
writable: true,
|
|
139
|
+
value: parsed.value,
|
|
140
|
+
});
|
|
141
|
+
cursor = skipTrivia(source, parsed.next);
|
|
142
|
+
if (source[cursor] === '}') return { value, next: cursor + 1 };
|
|
143
|
+
if (source[cursor] !== ',') throw new LiteralParseError('behavior_inputs_literal_invalid');
|
|
144
|
+
cursor = skipTrivia(source, cursor + 1);
|
|
145
|
+
if (source[cursor] === '}') return { value, next: cursor + 1 };
|
|
146
|
+
}
|
|
147
|
+
throw new LiteralParseError('behavior_inputs_literal_invalid');
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function parseValue(source: string, start: number): ParsedValue {
|
|
151
|
+
const cursor = skipTrivia(source, start);
|
|
152
|
+
const char = source[cursor];
|
|
153
|
+
if (char === "'" || char === '"' || char === '`') return parseString(source, cursor);
|
|
154
|
+
if (char === '[') return parseArray(source, cursor);
|
|
155
|
+
if (char === '{') return parseObject(source, cursor);
|
|
156
|
+
const boolean = /^(true|false)\b/.exec(source.slice(cursor));
|
|
157
|
+
if (boolean) return { value: boolean[1] === 'true', next: cursor + boolean[0].length };
|
|
158
|
+
const nil = /^null\b/.exec(source.slice(cursor));
|
|
159
|
+
if (nil) return { value: null, next: cursor + nil[0].length };
|
|
160
|
+
const number = /^-?(?:(?:\d(?:_?\d)*)(?:\.(?:\d(?:_?\d)*)?)?|\.\d(?:_?\d)*)(?:e[+-]?\d(?:_?\d)*)?/i
|
|
161
|
+
.exec(source.slice(cursor));
|
|
162
|
+
if (number) {
|
|
163
|
+
const parsed = Number(number[0].replaceAll('_', ''));
|
|
164
|
+
if (!Number.isFinite(parsed)) throw new LiteralParseError('behavior_inputs_literal_invalid');
|
|
165
|
+
return { value: parsed, next: cursor + number[0].length };
|
|
166
|
+
}
|
|
167
|
+
throw new LiteralParseError('behavior_inputs_not_literal');
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function topLevelPropertyValue(source: string, property: string): number | undefined {
|
|
171
|
+
let depth = 0;
|
|
172
|
+
for (let cursor = 0; cursor < source.length;) {
|
|
173
|
+
const next = skipTrivia(source, cursor);
|
|
174
|
+
if (next !== cursor) {
|
|
175
|
+
cursor = next;
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
const char = source[cursor];
|
|
179
|
+
if (char === "'" || char === '"' || char === '`') {
|
|
180
|
+
const parsed = parseString(source, cursor);
|
|
181
|
+
if (depth === 1 && parsed.value === property) {
|
|
182
|
+
const colon = skipTrivia(source, parsed.next);
|
|
183
|
+
if (source[colon] === ':') return skipTrivia(source, colon + 1);
|
|
184
|
+
}
|
|
185
|
+
cursor = parsed.next;
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
if (char === '{') {
|
|
189
|
+
depth += 1;
|
|
190
|
+
cursor += 1;
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
if (char === '}') {
|
|
194
|
+
depth -= 1;
|
|
195
|
+
cursor += 1;
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
if (depth === 1 && /[A-Za-z_$]/.test(char ?? '')) {
|
|
199
|
+
const identifier = /^[A-Za-z_$][\w$]*/.exec(source.slice(cursor))![0];
|
|
200
|
+
if (identifier === property) {
|
|
201
|
+
const colon = skipTrivia(source, cursor + identifier.length);
|
|
202
|
+
if (source[colon] === ':') return skipTrivia(source, colon + 1);
|
|
203
|
+
}
|
|
204
|
+
cursor += identifier.length;
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
cursor += 1;
|
|
208
|
+
}
|
|
209
|
+
return undefined;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** Detects a real top-level manifest property without matching comments or string values. */
|
|
213
|
+
export function hasTopLevelManifestProperty(
|
|
214
|
+
manifestSource: string,
|
|
215
|
+
property: string,
|
|
216
|
+
): boolean {
|
|
217
|
+
try {
|
|
218
|
+
return topLevelPropertyValue(manifestSource, property) !== undefined;
|
|
219
|
+
} catch {
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/** Parses only a top-level manifest.inputs literal; it never evaluates module source. */
|
|
225
|
+
export function parseLiteralBehaviorInputFields(
|
|
226
|
+
manifestSource: string,
|
|
227
|
+
): LiteralBehaviorInputFieldsResult {
|
|
228
|
+
try {
|
|
229
|
+
const start = topLevelPropertyValue(manifestSource, 'inputs');
|
|
230
|
+
if (start === undefined) return Object.freeze({ status: 'missing' });
|
|
231
|
+
if (manifestSource[start] !== '[') {
|
|
232
|
+
return Object.freeze({ status: 'invalid', diagnostic: 'behavior_inputs_not_literal' });
|
|
233
|
+
}
|
|
234
|
+
const parsed = parseArray(manifestSource, start);
|
|
235
|
+
const tail = skipTrivia(manifestSource, parsed.next);
|
|
236
|
+
if (manifestSource[tail] !== ',' && manifestSource[tail] !== '}') {
|
|
237
|
+
return Object.freeze({ status: 'invalid', diagnostic: 'behavior_inputs_literal_invalid' });
|
|
238
|
+
}
|
|
239
|
+
const inputs = normalizeBehaviorInputFields(parsed.value);
|
|
240
|
+
return Object.freeze({ status: 'valid', inputs });
|
|
241
|
+
} catch (error) {
|
|
242
|
+
return Object.freeze({
|
|
243
|
+
status: 'invalid',
|
|
244
|
+
diagnostic: error instanceof Error ? error.message : 'behavior_inputs_literal_invalid',
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Read-only game capability names exposed by
|
|
1
|
+
/** Read-only game capability names exposed by the ClawClaw GameQuery plugin. */
|
|
2
2
|
export const CLAWCLAW_MAP_CAPABILITY = 'clawclaw.map';
|
|
3
3
|
export const CLAWCLAW_TASKS_CAPABILITY = 'clawclaw.tasks';
|
|
4
4
|
export const CLAWCLAW_PATH_DISTANCE_CAPABILITY = 'clawclaw.path_distance';
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
CLAWCLAW_MAP_CAPABILITY,
|
|
7
7
|
CLAWCLAW_PATH_DISTANCE_CAPABILITY,
|
|
8
8
|
CLAWCLAW_TASKS_CAPABILITY,
|
|
9
|
-
} from '
|
|
9
|
+
} from './context-capabilities.js';
|
|
10
10
|
import { ClawclawGameQueryPlugin } from './game-query-plugin.js';
|
|
11
11
|
|
|
12
12
|
describe('ClawclawGameQueryPlugin', () => {
|
|
@@ -83,8 +83,8 @@ describe('ClawclawGameQueryPlugin', () => {
|
|
|
83
83
|
await runtime.close();
|
|
84
84
|
});
|
|
85
85
|
|
|
86
|
-
it('provides authoritative State tasks, packaged map data and local path
|
|
87
|
-
const
|
|
86
|
+
it('provides authoritative State tasks, packaged map data and batched local path distances', async () => {
|
|
87
|
+
const pathDistances = vi.fn().mockReturnValue([7.5, 9]);
|
|
88
88
|
const observed: unknown[] = [];
|
|
89
89
|
const consumer: RuntimeEpochPlugin<Record<string, any>> = {
|
|
90
90
|
kind: 'epoch',
|
|
@@ -103,7 +103,10 @@ describe('ClawclawGameQueryPlugin', () => {
|
|
|
103
103
|
const map = await context.capabilities.queryObservation(CLAWCLAW_MAP_CAPABILITY, {});
|
|
104
104
|
const distance = await context.capabilities.queryObservation(
|
|
105
105
|
CLAWCLAW_PATH_DISTANCE_CAPABILITY,
|
|
106
|
-
{
|
|
106
|
+
{ queries: [
|
|
107
|
+
{ from: { x: 1, y: 2 }, to: { x: 3, y: 4 } },
|
|
108
|
+
{ from: { x: 8, y: 9 }, to: { x: 10, y: 11 } },
|
|
109
|
+
] },
|
|
107
110
|
);
|
|
108
111
|
observed.push(tasks.value, map.value, distance.value);
|
|
109
112
|
return { outcome: 'noop' };
|
|
@@ -114,7 +117,7 @@ describe('ClawclawGameQueryPlugin', () => {
|
|
|
114
117
|
accountId: 'acct-game-query',
|
|
115
118
|
eventCatalog: createClawclawEventCatalog(),
|
|
116
119
|
initialSegment: { kind: 'game', identity: 'g-query' },
|
|
117
|
-
runtimeEpochPlugins: [new ClawclawGameQueryPlugin(
|
|
120
|
+
runtimeEpochPlugins: [new ClawclawGameQueryPlugin(pathDistances), consumer],
|
|
118
121
|
});
|
|
119
122
|
await runtime.start();
|
|
120
123
|
await runtime.acceptInputBatch({
|
|
@@ -154,11 +157,11 @@ describe('ClawclawGameQueryPlugin', () => {
|
|
|
154
157
|
});
|
|
155
158
|
expect((observed[1] as any).rooms).toHaveLength(21);
|
|
156
159
|
expect((observed[1] as any).all_task_locations).toHaveLength(50);
|
|
157
|
-
expect(observed[2]).
|
|
158
|
-
expect(
|
|
159
|
-
{ x: 1, y: 2 },
|
|
160
|
-
{ x:
|
|
161
|
-
);
|
|
160
|
+
expect(observed[2]).toEqual([7.5, 9]);
|
|
161
|
+
expect(pathDistances).toHaveBeenCalledWith([
|
|
162
|
+
{ from: { x: 1, y: 2 }, to: { x: 3, y: 4 } },
|
|
163
|
+
{ from: { x: 8, y: 9 }, to: { x: 10, y: 11 } },
|
|
164
|
+
]);
|
|
162
165
|
await runtime.close();
|
|
163
166
|
});
|
|
164
167
|
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { loadClawclawMapAsset } from '../../../../lib/game-context.js';
|
|
2
|
-
import type {
|
|
3
|
-
|
|
2
|
+
import type {
|
|
3
|
+
BehaviorPathQuery,
|
|
4
|
+
Position,
|
|
5
|
+
} from '../../../../sdk/behavior-plugin/index.js';
|
|
6
|
+
import { getLocalPathDistances } from '../../../../strategies/pathfind/astar-path.js';
|
|
4
7
|
import type {
|
|
5
8
|
RuntimeEpochPlugin,
|
|
6
9
|
RuntimeEpochPluginContext,
|
|
@@ -12,21 +15,19 @@ import {
|
|
|
12
15
|
CLAWCLAW_MAP_CAPABILITY,
|
|
13
16
|
CLAWCLAW_PATH_DISTANCE_CAPABILITY,
|
|
14
17
|
CLAWCLAW_TASKS_CAPABILITY,
|
|
15
|
-
} from '
|
|
18
|
+
} from './context-capabilities.js';
|
|
16
19
|
|
|
17
20
|
export const CLAWCLAW_GAME_QUERY_PLUGIN_ID = 'clawclaw.game-query';
|
|
18
21
|
|
|
19
22
|
export interface ClawclawPathDistanceRequest {
|
|
20
|
-
readonly
|
|
21
|
-
readonly to: StrategyPoint;
|
|
23
|
+
readonly queries: readonly Readonly<BehaviorPathQuery>[];
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
export type ClawclawPathDistanceProvider = (
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
) => number | null | Promise<number | null>;
|
|
27
|
+
queries: readonly Readonly<BehaviorPathQuery>[],
|
|
28
|
+
) => readonly (number | null)[] | Promise<readonly (number | null)[]>;
|
|
28
29
|
|
|
29
|
-
function finitePoint(value:
|
|
30
|
+
function finitePoint(value: Position): boolean {
|
|
30
31
|
return Number.isFinite(value?.x) && Number.isFinite(value?.y);
|
|
31
32
|
}
|
|
32
33
|
|
|
@@ -107,7 +108,7 @@ export class ClawclawGameQueryPlugin implements RuntimeEpochPlugin<Record<string
|
|
|
107
108
|
private activeScopeKey: string | null = null;
|
|
108
109
|
|
|
109
110
|
constructor(
|
|
110
|
-
private readonly
|
|
111
|
+
private readonly pathDistances: ClawclawPathDistanceProvider = getLocalPathDistances,
|
|
111
112
|
) {}
|
|
112
113
|
|
|
113
114
|
private gameStateForQuery(
|
|
@@ -191,18 +192,29 @@ export class ClawclawGameQueryPlugin implements RuntimeEpochPlugin<Record<string
|
|
|
191
192
|
};
|
|
192
193
|
},
|
|
193
194
|
}),
|
|
194
|
-
context.capabilities.provideObservation<
|
|
195
|
+
context.capabilities.provideObservation<
|
|
196
|
+
ClawclawPathDistanceRequest,
|
|
197
|
+
readonly (number | null)[]
|
|
198
|
+
>({
|
|
195
199
|
capability: CLAWCLAW_PATH_DISTANCE_CAPABILITY,
|
|
196
200
|
query: async (request, scope) => {
|
|
197
|
-
if (!
|
|
201
|
+
if (!Array.isArray(request?.queries) || request.queries.some(({ from, to }) => (
|
|
202
|
+
!finitePoint(from) || !finitePoint(to)
|
|
203
|
+
))) {
|
|
198
204
|
throw new Error('invalid_path_distance_points');
|
|
199
205
|
}
|
|
200
|
-
const
|
|
206
|
+
const provided = await this.pathDistances(request.queries);
|
|
207
|
+
const value = Array.isArray(provided) ? [...provided] : [];
|
|
208
|
+
if (
|
|
209
|
+
!Array.isArray(provided)
|
|
210
|
+
|| value.length !== request.queries.length
|
|
211
|
+
|| value.some(distance => distance !== null && !Number.isFinite(distance))
|
|
212
|
+
) throw new Error('invalid_path_distance_result');
|
|
201
213
|
return {
|
|
202
214
|
scope,
|
|
203
215
|
capability: CLAWCLAW_PATH_DISTANCE_CAPABILITY,
|
|
204
216
|
receivedAt: new Date().toISOString(),
|
|
205
|
-
freshness: value === null ? 'unknown' : 'fresh',
|
|
217
|
+
freshness: value.some(distance => distance === null) ? 'unknown' : 'fresh',
|
|
206
218
|
value,
|
|
207
219
|
provenance: { source: 'packaged_walkable_grid', algorithm: 'local_astar' },
|
|
208
220
|
};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export * from './action/index.js';
|
|
2
2
|
export * from './assembly.js';
|
|
3
|
+
export * from './behavior/index.js';
|
|
3
4
|
export * from './derived-event/index.js';
|
|
5
|
+
export * from './game-query/index.js';
|
|
4
6
|
export * from './mailbox/index.js';
|
|
5
7
|
export * from './source/index.js';
|
|
6
8
|
export * from './perception/index.js';
|
|
7
|
-
export * from './
|
|
9
|
+
export * from './trigger/index.js';
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { createClawclawEventCatalog } from '../../../../clawclaw-event-catalog.js';
|
|
3
|
+
import {
|
|
4
|
+
EventIngress,
|
|
5
|
+
MemoryEventRepository,
|
|
6
|
+
type CanonicalEvent,
|
|
7
|
+
} from '../../../../framework/events/index.js';
|
|
8
|
+
import type { RuntimeReadyView } from '../../../../framework/runtime.js';
|
|
9
|
+
import {
|
|
10
|
+
CLAUDE_CHANNEL_CONSUMER_ID,
|
|
11
|
+
CLAUDE_CHANNEL_COALESCE_MS,
|
|
12
|
+
ClaudeChannelMailboxAdapter,
|
|
13
|
+
} from './claude-channel-adapter.js';
|
|
14
|
+
|
|
15
|
+
const START_MS = Date.parse('2026-08-03T00:00:00.000Z');
|
|
16
|
+
|
|
17
|
+
function readyView(epochSeq: number, eventWatermark: number): RuntimeReadyView {
|
|
18
|
+
const runtimeScope = {
|
|
19
|
+
adapterId: 'clawclaw',
|
|
20
|
+
accountId: 'account-1',
|
|
21
|
+
sessionId: 'session-1',
|
|
22
|
+
segmentId: 'segment-1',
|
|
23
|
+
segmentSeq: 1,
|
|
24
|
+
};
|
|
25
|
+
return {
|
|
26
|
+
scope: {
|
|
27
|
+
adapterId: runtimeScope.adapterId,
|
|
28
|
+
sessionId: runtimeScope.sessionId,
|
|
29
|
+
segmentId: runtimeScope.segmentId,
|
|
30
|
+
segmentSeq: runtimeScope.segmentSeq,
|
|
31
|
+
},
|
|
32
|
+
state: {
|
|
33
|
+
state: { phase: 'wandering', tick: epochSeq },
|
|
34
|
+
stateStatus: {
|
|
35
|
+
status: 'fresh',
|
|
36
|
+
semantics: 'latest_received',
|
|
37
|
+
source: 'owner_memory',
|
|
38
|
+
scope: runtimeScope,
|
|
39
|
+
connectionId: 'connection-1',
|
|
40
|
+
connectionState: 'connected',
|
|
41
|
+
receivedAtMs: START_MS,
|
|
42
|
+
ageMs: 0,
|
|
43
|
+
backendTick: epochSeq,
|
|
44
|
+
reason: null,
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
pluginStates: {},
|
|
48
|
+
pluginOutcomes: {},
|
|
49
|
+
events: [],
|
|
50
|
+
throughCommitSeq: eventWatermark,
|
|
51
|
+
frameSeq: epochSeq,
|
|
52
|
+
eventWatermark,
|
|
53
|
+
epochSeq,
|
|
54
|
+
hasMore: false,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function fixture() {
|
|
59
|
+
const repository = new MemoryEventRepository();
|
|
60
|
+
repository.saveSession({
|
|
61
|
+
sessionId: 'session-1',
|
|
62
|
+
adapterId: 'clawclaw',
|
|
63
|
+
accountId: 'account-1',
|
|
64
|
+
status: 'open',
|
|
65
|
+
isCurrent: true,
|
|
66
|
+
openedAt: new Date(START_MS).toISOString(),
|
|
67
|
+
});
|
|
68
|
+
repository.saveSegment({
|
|
69
|
+
segmentId: 'segment-1',
|
|
70
|
+
sessionId: 'session-1',
|
|
71
|
+
sequence: 1,
|
|
72
|
+
kind: 'game',
|
|
73
|
+
status: 'open',
|
|
74
|
+
isCurrent: true,
|
|
75
|
+
openedAt: new Date(START_MS).toISOString(),
|
|
76
|
+
});
|
|
77
|
+
const ingress = new EventIngress(repository, createClawclawEventCatalog());
|
|
78
|
+
let nowMs = START_MS;
|
|
79
|
+
let ready = readyView(1, 0);
|
|
80
|
+
const service = new ClaudeChannelMailboxAdapter({
|
|
81
|
+
repository,
|
|
82
|
+
readyView: () => structuredClone(ready),
|
|
83
|
+
now: () => nowMs,
|
|
84
|
+
});
|
|
85
|
+
return {
|
|
86
|
+
repository,
|
|
87
|
+
ingress,
|
|
88
|
+
service,
|
|
89
|
+
advance: (milliseconds: number) => { nowMs += milliseconds; },
|
|
90
|
+
setReady: (epochSeq: number, watermark: number) => { ready = readyView(epochSeq, watermark); },
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async function publish(
|
|
95
|
+
ingress: EventIngress,
|
|
96
|
+
eventId: string,
|
|
97
|
+
type: string,
|
|
98
|
+
epochSeq: number,
|
|
99
|
+
payload: Record<string, unknown> = {},
|
|
100
|
+
): Promise<CanonicalEvent> {
|
|
101
|
+
return (await ingress.publish({
|
|
102
|
+
eventId,
|
|
103
|
+
epochSeq,
|
|
104
|
+
type,
|
|
105
|
+
producer: 'backend_push',
|
|
106
|
+
sessionId: 'session-1',
|
|
107
|
+
segmentId: 'segment-1',
|
|
108
|
+
payload,
|
|
109
|
+
source: { sourceId: 'game-ws', eventId: `remote:${eventId}` },
|
|
110
|
+
})).event;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
describe('ClaudeChannelMailboxAdapter', () => {
|
|
114
|
+
it('never projects Ready State into the Channel batch', () => {
|
|
115
|
+
const { service } = fixture();
|
|
116
|
+
const ready = readyView(2, 0);
|
|
117
|
+
ready.pluginStates['behavior.status'] = {
|
|
118
|
+
pluginId: 'clawclaw.behavior',
|
|
119
|
+
topic: 'behavior.status',
|
|
120
|
+
value: {
|
|
121
|
+
running: true,
|
|
122
|
+
activation_id: 'short-1',
|
|
123
|
+
behavior: 'find_player',
|
|
124
|
+
layer: 'short',
|
|
125
|
+
status: { summary: '正在有限搜索 7 号。' },
|
|
126
|
+
},
|
|
127
|
+
updatedEpochSeq: 2,
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
expect(service.prepare(ready).batch).toEqual({ state: null, events: [] });
|
|
131
|
+
});
|
|
132
|
+
it('returns no delivery for an empty Ready boundary and never invents an Event', () => {
|
|
133
|
+
const { service } = fixture();
|
|
134
|
+
|
|
135
|
+
expect(service.prepare()).toEqual({
|
|
136
|
+
batch: {
|
|
137
|
+
state: null,
|
|
138
|
+
events: [],
|
|
139
|
+
},
|
|
140
|
+
readyEpochSeq: 1,
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('uses one fixed 220ms window and delivers every Event accumulated inside it', async () => {
|
|
145
|
+
const { ingress, service, advance, setReady } = fixture();
|
|
146
|
+
const first = await publish(ingress, 'speech-1', 'speech', 1, {
|
|
147
|
+
speaker_name: 'Alpha',
|
|
148
|
+
text: 'first',
|
|
149
|
+
});
|
|
150
|
+
service.observeEvents([first]);
|
|
151
|
+
setReady(1, first.commitSeq);
|
|
152
|
+
|
|
153
|
+
advance(100);
|
|
154
|
+
const second = await publish(ingress, 'speech-2', 'speech', 2, {
|
|
155
|
+
speaker_name: 'Bravo',
|
|
156
|
+
text: 'second',
|
|
157
|
+
});
|
|
158
|
+
service.observeEvents([second]);
|
|
159
|
+
setReady(2, second.commitSeq);
|
|
160
|
+
|
|
161
|
+
advance(CLAUDE_CHANNEL_COALESCE_MS - 101);
|
|
162
|
+
expect(service.prepare().deliveryToken).toBeUndefined();
|
|
163
|
+
advance(1);
|
|
164
|
+
const prepared = service.prepare();
|
|
165
|
+
|
|
166
|
+
expect(prepared.deliveryToken).toBeTypeOf('string');
|
|
167
|
+
expect((prepared.batch.events as Array<Record<string, unknown>>).map((event) => event.text))
|
|
168
|
+
.toEqual(['first', 'second']);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it('ignores internal-only facts while naturally queued Agent-visible facts are delivered', async () => {
|
|
172
|
+
const { repository, ingress, service, advance, setReady } = fixture();
|
|
173
|
+
const internal = await publish(ingress, 'task-1', 'task_assigned', 1, {
|
|
174
|
+
task_name: 'wires',
|
|
175
|
+
});
|
|
176
|
+
const visible = await publish(ingress, 'speech-1', 'speech', 1, {
|
|
177
|
+
speaker_name: 'Alpha',
|
|
178
|
+
text: 'visible',
|
|
179
|
+
});
|
|
180
|
+
service.observeEvents([internal, visible]);
|
|
181
|
+
setReady(1, visible.commitSeq);
|
|
182
|
+
advance(CLAUDE_CHANNEL_COALESCE_MS);
|
|
183
|
+
|
|
184
|
+
const prepared = service.prepare();
|
|
185
|
+
expect(prepared.batch.events).toMatchObject([{ type: 'speech', text: 'visible' }]);
|
|
186
|
+
expect(repository.delivery(internal.eventId, CLAUDE_CHANNEL_CONSUMER_ID)?.detailState)
|
|
187
|
+
.toBe('not_applicable');
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it('holds one details lease and supports renew, release, retry, and ack', async () => {
|
|
191
|
+
const { repository, ingress, service, advance, setReady } = fixture();
|
|
192
|
+
const event = await publish(ingress, 'speech-1', 'speech', 1, {
|
|
193
|
+
speaker_name: 'Alpha',
|
|
194
|
+
text: 'lease me',
|
|
195
|
+
});
|
|
196
|
+
service.observeEvents([event]);
|
|
197
|
+
setReady(1, event.commitSeq);
|
|
198
|
+
advance(CLAUDE_CHANNEL_COALESCE_MS);
|
|
199
|
+
|
|
200
|
+
const first = service.prepare();
|
|
201
|
+
expect(service.renew(first.deliveryToken!)).toBe(true);
|
|
202
|
+
expect(() => service.prepare()).toThrow('agent_mailbox_delivery_busy');
|
|
203
|
+
expect(repository.acquireLease({
|
|
204
|
+
consumerId: CLAUDE_CHANNEL_CONSUMER_ID,
|
|
205
|
+
channel: 'details',
|
|
206
|
+
ownerId: 'competing-channel',
|
|
207
|
+
ttlMs: 1_000,
|
|
208
|
+
nowMs: START_MS + CLAUDE_CHANNEL_COALESCE_MS,
|
|
209
|
+
})).toBeNull();
|
|
210
|
+
expect(service.release(first.deliveryToken!)).toBe(true);
|
|
211
|
+
expect(repository.delivery(event.eventId, CLAUDE_CHANNEL_CONSUMER_ID)?.detailState).toBe('pending');
|
|
212
|
+
|
|
213
|
+
const retried = service.prepare();
|
|
214
|
+
expect(retried.deliveryToken).toBeTypeOf('string');
|
|
215
|
+
expect(service.ack(retried.deliveryToken!)).toBe(true);
|
|
216
|
+
expect(repository.delivery(event.eventId, CLAUDE_CHANNEL_CONSUMER_ID)).toMatchObject({
|
|
217
|
+
detailState: 'delivered',
|
|
218
|
+
detailDeliveredAt: expect.any(String),
|
|
219
|
+
detailDeliveryVia: 'claude_channel',
|
|
220
|
+
});
|
|
221
|
+
expect(service.prepare().deliveryToken).toBeUndefined();
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it('preserves long Channel payloads without the former short-message budget', async () => {
|
|
225
|
+
const { ingress, service, advance, setReady } = fixture();
|
|
226
|
+
const text = `BEGIN-${'x'.repeat(64 * 1024)}-END`;
|
|
227
|
+
const event = await publish(ingress, 'speech-long', 'speech', 1, {
|
|
228
|
+
speaker_name: 'Alpha',
|
|
229
|
+
text,
|
|
230
|
+
});
|
|
231
|
+
service.observeEvents([event]);
|
|
232
|
+
setReady(1, event.commitSeq);
|
|
233
|
+
advance(CLAUDE_CHANNEL_COALESCE_MS);
|
|
234
|
+
|
|
235
|
+
const prepared = service.prepare();
|
|
236
|
+
expect((prepared.batch.events as Array<Record<string, unknown>>)[0]?.text).toBe(text);
|
|
237
|
+
expect(Buffer.byteLength(JSON.stringify(prepared.batch), 'utf8')).toBeGreaterThan(64 * 1024);
|
|
238
|
+
});
|
|
239
|
+
});
|