@myclaw163/clawclaw-cli 0.7.16 → 0.8.2
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 +10 -7
- 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
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { MAX_TRIGGER_RUNTIME_MS } from '../sdk/trigger-plugin/index.js';
|
|
2
|
+
|
|
3
|
+
export type GameplayTriggerRearm = 'after_clear' | 'after_cooldown';
|
|
4
|
+
|
|
5
|
+
/** New community Trigger modules are inert until explicitly enabled. */
|
|
6
|
+
export const DEFAULT_GAMEPLAY_TRIGGER_ENABLED = false;
|
|
7
|
+
|
|
8
|
+
export interface GameplayTriggerConfig {
|
|
9
|
+
enabled?: boolean;
|
|
10
|
+
input?: Record<string, unknown>;
|
|
11
|
+
behavior?: string;
|
|
12
|
+
behavior_input?: Record<string, unknown>;
|
|
13
|
+
reflex_priority?: number;
|
|
14
|
+
cooldown_ms?: number;
|
|
15
|
+
rearm?: GameplayTriggerRearm;
|
|
16
|
+
max_runtime_ms?: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type GameplayTriggerConfigs = Record<string, GameplayTriggerConfig>;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Configuration-only representation consumed by Runtime assembly before it
|
|
23
|
+
* binds an installed Trigger source. It deliberately has no dependency on a
|
|
24
|
+
* loader, source path, module class, or Runtime plugin contract.
|
|
25
|
+
*/
|
|
26
|
+
export interface TriggerRegistrationOverride {
|
|
27
|
+
readonly id: string;
|
|
28
|
+
readonly enabled?: boolean;
|
|
29
|
+
readonly input?: Readonly<Record<string, unknown>>;
|
|
30
|
+
readonly behavior?: string;
|
|
31
|
+
readonly behaviorInput?: Readonly<Record<string, unknown>>;
|
|
32
|
+
readonly reflexPriority?: number;
|
|
33
|
+
readonly cooldownMs?: number;
|
|
34
|
+
readonly rearm?: GameplayTriggerRearm;
|
|
35
|
+
readonly maxRuntimeMs?: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const RESOURCE_ID = /^[a-z0-9][a-z0-9._-]*$/;
|
|
39
|
+
const TRIGGER_FIELDS = new Set([
|
|
40
|
+
'enabled',
|
|
41
|
+
'input',
|
|
42
|
+
'behavior',
|
|
43
|
+
'behavior_input',
|
|
44
|
+
'reflex_priority',
|
|
45
|
+
'cooldown_ms',
|
|
46
|
+
'rearm',
|
|
47
|
+
'max_runtime_ms',
|
|
48
|
+
]);
|
|
49
|
+
const MAX_JSON_DEPTH = 32;
|
|
50
|
+
const MAX_JSON_NODES = 10_000;
|
|
51
|
+
const MAX_TRIGGER_CONFIGS = 512;
|
|
52
|
+
const UNSAFE_OBJECT_KEYS = new Set(['__proto__', 'prototype', 'constructor']);
|
|
53
|
+
|
|
54
|
+
interface JsonCloneState {
|
|
55
|
+
nodes: number;
|
|
56
|
+
readonly ancestors: WeakSet<object>;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function plainRecord(value: unknown): Record<string, unknown> | undefined {
|
|
60
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return undefined;
|
|
61
|
+
const prototype = Object.getPrototypeOf(value);
|
|
62
|
+
return prototype === Object.prototype || prototype === null
|
|
63
|
+
? value as Record<string, unknown>
|
|
64
|
+
: undefined;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function cloneJsonValue(
|
|
68
|
+
value: unknown,
|
|
69
|
+
field: string,
|
|
70
|
+
state: JsonCloneState,
|
|
71
|
+
depth = 0,
|
|
72
|
+
): unknown {
|
|
73
|
+
state.nodes += 1;
|
|
74
|
+
if (state.nodes > MAX_JSON_NODES) {
|
|
75
|
+
throw new Error(`${field} exceeds the JSON value limit.`);
|
|
76
|
+
}
|
|
77
|
+
if (depth > MAX_JSON_DEPTH) {
|
|
78
|
+
throw new Error(`${field} exceeds the JSON nesting limit.`);
|
|
79
|
+
}
|
|
80
|
+
if (
|
|
81
|
+
value === null
|
|
82
|
+
|| typeof value === 'string'
|
|
83
|
+
|| typeof value === 'boolean'
|
|
84
|
+
) return value;
|
|
85
|
+
if (typeof value === 'number') {
|
|
86
|
+
if (!Number.isFinite(value)) throw new Error(`${field} must contain JSON-safe values.`);
|
|
87
|
+
return value;
|
|
88
|
+
}
|
|
89
|
+
if (typeof value !== 'object') {
|
|
90
|
+
throw new Error(`${field} must contain JSON-safe values.`);
|
|
91
|
+
}
|
|
92
|
+
if (state.ancestors.has(value)) throw new Error(`${field} must not contain cycles.`);
|
|
93
|
+
state.ancestors.add(value);
|
|
94
|
+
try {
|
|
95
|
+
if (Array.isArray(value)) {
|
|
96
|
+
return value.map((entry, index) => (
|
|
97
|
+
cloneJsonValue(entry, `${field}[${index}]`, state, depth + 1)
|
|
98
|
+
));
|
|
99
|
+
}
|
|
100
|
+
const source = plainRecord(value);
|
|
101
|
+
if (!source) throw new Error(`${field} must contain only plain JSON objects.`);
|
|
102
|
+
const result: Record<string, unknown> = {};
|
|
103
|
+
for (const [key, entry] of Object.entries(source)) {
|
|
104
|
+
if (UNSAFE_OBJECT_KEYS.has(key)) {
|
|
105
|
+
throw new Error(`${field} contains an unsafe object key.`);
|
|
106
|
+
}
|
|
107
|
+
result[key] = cloneJsonValue(entry, `${field}.${key}`, state, depth + 1);
|
|
108
|
+
}
|
|
109
|
+
return result;
|
|
110
|
+
} finally {
|
|
111
|
+
state.ancestors.delete(value);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function jsonObject(value: unknown, field: string): Record<string, unknown> {
|
|
116
|
+
if (!plainRecord(value)) throw new Error(`${field} must be a JSON object.`);
|
|
117
|
+
return cloneJsonValue(value, field, {
|
|
118
|
+
nodes: 0,
|
|
119
|
+
ancestors: new WeakSet<object>(),
|
|
120
|
+
}) as Record<string, unknown>;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function optionalSafeInteger(
|
|
124
|
+
value: unknown,
|
|
125
|
+
field: string,
|
|
126
|
+
minimum: number,
|
|
127
|
+
): number | undefined {
|
|
128
|
+
if (value === undefined) return undefined;
|
|
129
|
+
if (!Number.isSafeInteger(value) || (value as number) < minimum) {
|
|
130
|
+
throw new Error(`${field} must be a safe integer greater than or equal to ${minimum}.`);
|
|
131
|
+
}
|
|
132
|
+
return value as number;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function parseTriggerConfig(value: unknown, field: string): GameplayTriggerConfig {
|
|
136
|
+
const source = plainRecord(value);
|
|
137
|
+
if (!source) throw new Error(`${field} must be an object.`);
|
|
138
|
+
const unknown = Object.keys(source).filter((key) => !TRIGGER_FIELDS.has(key));
|
|
139
|
+
if (unknown.length > 0) {
|
|
140
|
+
throw new Error(`${field} contains unknown fields: ${unknown.sort().join(', ')}.`);
|
|
141
|
+
}
|
|
142
|
+
if (source.enabled !== undefined && typeof source.enabled !== 'boolean') {
|
|
143
|
+
throw new Error(`${field}.enabled must be a boolean.`);
|
|
144
|
+
}
|
|
145
|
+
if (
|
|
146
|
+
source.behavior !== undefined
|
|
147
|
+
&& (typeof source.behavior !== 'string' || !RESOURCE_ID.test(source.behavior))
|
|
148
|
+
) throw new Error(`${field}.behavior must be a Behavior id.`);
|
|
149
|
+
if (
|
|
150
|
+
source.rearm !== undefined
|
|
151
|
+
&& source.rearm !== 'after_clear'
|
|
152
|
+
&& source.rearm !== 'after_cooldown'
|
|
153
|
+
) throw new Error(`${field}.rearm must be after_clear or after_cooldown.`);
|
|
154
|
+
|
|
155
|
+
const reflexPriority = optionalSafeInteger(
|
|
156
|
+
source.reflex_priority,
|
|
157
|
+
`${field}.reflex_priority`,
|
|
158
|
+
Number.MIN_SAFE_INTEGER,
|
|
159
|
+
);
|
|
160
|
+
const cooldownMs = optionalSafeInteger(source.cooldown_ms, `${field}.cooldown_ms`, 0);
|
|
161
|
+
const maxRuntimeMs = optionalSafeInteger(source.max_runtime_ms, `${field}.max_runtime_ms`, 1);
|
|
162
|
+
if (maxRuntimeMs !== undefined && maxRuntimeMs > MAX_TRIGGER_RUNTIME_MS) {
|
|
163
|
+
throw new Error(`${field}.max_runtime_ms cannot exceed ${MAX_TRIGGER_RUNTIME_MS}.`);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return {
|
|
167
|
+
...(source.enabled === undefined ? {} : { enabled: source.enabled }),
|
|
168
|
+
...(source.input === undefined ? {} : { input: jsonObject(source.input, `${field}.input`) }),
|
|
169
|
+
...(source.behavior === undefined ? {} : { behavior: source.behavior }),
|
|
170
|
+
...(source.behavior_input === undefined ? {} : {
|
|
171
|
+
behavior_input: jsonObject(source.behavior_input, `${field}.behavior_input`),
|
|
172
|
+
}),
|
|
173
|
+
...(reflexPriority === undefined ? {} : { reflex_priority: reflexPriority }),
|
|
174
|
+
...(cooldownMs === undefined ? {} : { cooldown_ms: cooldownMs }),
|
|
175
|
+
...(source.rearm === undefined ? {} : { rearm: source.rearm as GameplayTriggerRearm }),
|
|
176
|
+
...(maxRuntimeMs === undefined ? {} : { max_runtime_ms: maxRuntimeMs }),
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export function parseGameplayTriggerConfigs(
|
|
181
|
+
value: unknown,
|
|
182
|
+
field = 'user-data/gameplay.json triggers',
|
|
183
|
+
): GameplayTriggerConfigs {
|
|
184
|
+
const source = plainRecord(value);
|
|
185
|
+
if (!source) throw new Error(`${field} must be an object keyed by Trigger id.`);
|
|
186
|
+
if (Object.keys(source).length > MAX_TRIGGER_CONFIGS) {
|
|
187
|
+
throw new Error(`${field} cannot contain more than ${MAX_TRIGGER_CONFIGS} entries.`);
|
|
188
|
+
}
|
|
189
|
+
const result: GameplayTriggerConfigs = {};
|
|
190
|
+
for (const id of Object.keys(source).sort()) {
|
|
191
|
+
if (!RESOURCE_ID.test(id)) throw new Error(`${field} contains an invalid Trigger id: ${id}.`);
|
|
192
|
+
result[id] = parseTriggerConfig(source[id], `${field}.${id}`);
|
|
193
|
+
}
|
|
194
|
+
return result;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** Converts persisted snake_case values into deterministic Runtime-neutral overrides. */
|
|
198
|
+
export function toTriggerRegistrationOverrides(
|
|
199
|
+
configs: GameplayTriggerConfigs,
|
|
200
|
+
): readonly TriggerRegistrationOverride[] {
|
|
201
|
+
const normalized = parseGameplayTriggerConfigs(configs);
|
|
202
|
+
return Object.entries(normalized).map(([id, config]) => Object.freeze({
|
|
203
|
+
id,
|
|
204
|
+
...(config.enabled === undefined ? {} : { enabled: config.enabled }),
|
|
205
|
+
...(config.input === undefined ? {} : { input: Object.freeze(config.input) }),
|
|
206
|
+
...(config.behavior === undefined ? {} : { behavior: config.behavior }),
|
|
207
|
+
...(config.behavior_input === undefined ? {} : {
|
|
208
|
+
behaviorInput: Object.freeze(config.behavior_input),
|
|
209
|
+
}),
|
|
210
|
+
...(config.reflex_priority === undefined ? {} : {
|
|
211
|
+
reflexPriority: config.reflex_priority,
|
|
212
|
+
}),
|
|
213
|
+
...(config.cooldown_ms === undefined ? {} : { cooldownMs: config.cooldown_ms }),
|
|
214
|
+
...(config.rearm === undefined ? {} : { rearm: config.rearm }),
|
|
215
|
+
...(config.max_runtime_ms === undefined ? {} : { maxRuntimeMs: config.max_runtime_ms }),
|
|
216
|
+
}));
|
|
217
|
+
}
|
|
@@ -7,11 +7,12 @@ import {
|
|
|
7
7
|
getRuntimeAuthStateFile,
|
|
8
8
|
getUserDataAccountHash,
|
|
9
9
|
getUserDataAuthFile,
|
|
10
|
+
getUserDataBehaviorsDir,
|
|
10
11
|
getUserDataHubStrategyLockfile,
|
|
11
12
|
getUserDataMemoryFile,
|
|
12
13
|
getUserDataPerceptionsDir,
|
|
13
14
|
getUserDataPersonaFile,
|
|
14
|
-
|
|
15
|
+
getUserDataTriggersDir,
|
|
15
16
|
} from './user-data.js';
|
|
16
17
|
|
|
17
18
|
describe('user-data layout migration', () => {
|
|
@@ -70,13 +71,14 @@ describe('user-data layout migration', () => {
|
|
|
70
71
|
expect(readFileSync(getUserDataPersonaFile(ws, { apiKey }), 'utf8')).toBe('persona old');
|
|
71
72
|
expect(readFileSync(getUserDataMemoryFile(ws, { apiKey }), 'utf8')).toBe('memory old');
|
|
72
73
|
|
|
73
|
-
expect(
|
|
74
|
-
expect(existsSync(join(getUserDataStrategiesDir(ws), '.official'))).toBe(false);
|
|
74
|
+
expect(existsSync(getUserDataBehaviorsDir(ws))).toBe(true);
|
|
75
75
|
expect(existsSync(getUserDataPerceptionsDir(ws))).toBe(true);
|
|
76
|
+
expect(existsSync(getUserDataTriggersDir(ws))).toBe(true);
|
|
77
|
+
expect(existsSync(join(ws, 'user-data', 'strategies'))).toBe(false);
|
|
78
|
+
expect(existsSync(join(ws, 'user-data', 'intents'))).toBe(false);
|
|
79
|
+
expect(existsSync(join(ws, 'strategies', 'custom.ts'))).toBe(true);
|
|
76
80
|
|
|
77
|
-
|
|
78
|
-
expect(Object.keys(strategyLock)).toEqual(['strategy/abc']);
|
|
79
|
-
expect(strategyLock['skill/def']).toBeUndefined();
|
|
81
|
+
expect(existsSync(getUserDataHubStrategyLockfile(ws))).toBe(false);
|
|
80
82
|
});
|
|
81
83
|
|
|
82
84
|
it('does not overwrite existing user-data account files', () => {
|
|
@@ -97,4 +99,19 @@ describe('user-data layout migration', () => {
|
|
|
97
99
|
expect(readFileSync(getUserDataPersonaFile(ws, { apiKey }), 'utf8')).toBe('new persona');
|
|
98
100
|
});
|
|
99
101
|
|
|
102
|
+
it('creates unified module directories without recreating or deleting legacy module directories', () => {
|
|
103
|
+
mkdirSync(join(ws, 'user-data', 'strategies'), { recursive: true });
|
|
104
|
+
mkdirSync(join(ws, 'user-data', 'intents'), { recursive: true });
|
|
105
|
+
writeFileSync(join(ws, 'user-data', 'strategies', 'old.ts'), 'old strategy', 'utf8');
|
|
106
|
+
writeFileSync(join(ws, 'user-data', 'intents', 'old.ts'), 'old intent', 'utf8');
|
|
107
|
+
|
|
108
|
+
ensureUserDataLayout(ws);
|
|
109
|
+
|
|
110
|
+
expect(existsSync(getUserDataBehaviorsDir(ws))).toBe(true);
|
|
111
|
+
expect(existsSync(getUserDataPerceptionsDir(ws))).toBe(true);
|
|
112
|
+
expect(existsSync(getUserDataTriggersDir(ws))).toBe(true);
|
|
113
|
+
expect(readFileSync(join(ws, 'user-data', 'strategies', 'old.ts'), 'utf8')).toBe('old strategy');
|
|
114
|
+
expect(readFileSync(join(ws, 'user-data', 'intents', 'old.ts'), 'utf8')).toBe('old intent');
|
|
115
|
+
});
|
|
116
|
+
|
|
100
117
|
});
|
package/src/lib/user-data.ts
CHANGED
|
@@ -2,14 +2,11 @@ import {
|
|
|
2
2
|
copyFileSync,
|
|
3
3
|
existsSync,
|
|
4
4
|
mkdirSync,
|
|
5
|
-
readdirSync,
|
|
6
5
|
readFileSync,
|
|
7
|
-
statSync,
|
|
8
6
|
writeFileSync,
|
|
9
7
|
} from 'fs';
|
|
10
8
|
import { createHash } from 'crypto';
|
|
11
|
-
import { dirname,
|
|
12
|
-
import { fileURLToPath } from 'url';
|
|
9
|
+
import { dirname, join } from 'path';
|
|
13
10
|
import type { AuthData, AuthProfile } from './auth.js';
|
|
14
11
|
|
|
15
12
|
export const USER_DATA_DIR = 'user-data';
|
|
@@ -72,14 +69,18 @@ export function getUserDataMemoryFile(workspaceDir: string, profile: Pick<AuthPr
|
|
|
72
69
|
return join(getUserDataAccountDir(workspaceDir, profile), 'memory.md');
|
|
73
70
|
}
|
|
74
71
|
|
|
75
|
-
export function
|
|
76
|
-
return join(getUserDataDir(workspaceDir), '
|
|
72
|
+
export function getUserDataBehaviorsDir(workspaceDir: string): string {
|
|
73
|
+
return join(getUserDataDir(workspaceDir), 'behaviors');
|
|
77
74
|
}
|
|
78
75
|
|
|
79
76
|
export function getUserDataPerceptionsDir(workspaceDir: string): string {
|
|
80
77
|
return join(getUserDataDir(workspaceDir), 'perceptions');
|
|
81
78
|
}
|
|
82
79
|
|
|
80
|
+
export function getUserDataTriggersDir(workspaceDir: string): string {
|
|
81
|
+
return join(getUserDataDir(workspaceDir), 'triggers');
|
|
82
|
+
}
|
|
83
|
+
|
|
83
84
|
export function getUserDataGameplayConfigFile(workspaceDir: string): string {
|
|
84
85
|
return join(getUserDataDir(workspaceDir), 'gameplay.json');
|
|
85
86
|
}
|
|
@@ -88,8 +89,12 @@ export function getUserDataDiagnosticsConfigFile(workspaceDir: string): string {
|
|
|
88
89
|
return join(getUserDataDir(workspaceDir), 'diagnostics.json');
|
|
89
90
|
}
|
|
90
91
|
|
|
91
|
-
export function
|
|
92
|
-
return join(
|
|
92
|
+
export function getUserDataOfficialBehaviorsManifestFile(workspaceDir: string): string {
|
|
93
|
+
return join(getUserDataBehaviorsDir(workspaceDir), '.official-manifest.json');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function getUserDataOfficialPerceptionsManifestFile(workspaceDir: string): string {
|
|
97
|
+
return join(getUserDataPerceptionsDir(workspaceDir), '.official-manifest.json');
|
|
93
98
|
}
|
|
94
99
|
|
|
95
100
|
export function getUserDataHubDir(workspaceDir: string): string {
|
|
@@ -228,118 +233,6 @@ function migrateAccountFiles(workspaceDir: string, auth: AuthData | null, result
|
|
|
228
233
|
}
|
|
229
234
|
}
|
|
230
235
|
|
|
231
|
-
interface OfficialManifestEntry {
|
|
232
|
-
sourceHash: string;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
type OfficialManifest = Record<string, OfficialManifestEntry>;
|
|
236
|
-
|
|
237
|
-
function hashContent(content: string): string {
|
|
238
|
-
return createHash('sha256').update(content).digest('hex').slice(0, 16);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
function locateBuiltinSource(id: string): string | null {
|
|
242
|
-
const currentDir = dirname(fileURLToPath(import.meta.url));
|
|
243
|
-
const strategiesDir = join(currentDir, '..', 'strategies');
|
|
244
|
-
const filePath = join(strategiesDir, `${id}.ts`);
|
|
245
|
-
return existsSync(filePath) ? filePath : null;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
function rewriteBuiltinImportBody(source: string): string {
|
|
249
|
-
return source.replace(/from\s+['"]\.\.?\/[^'"]+['"]/g, `from '@myclaw163/clawclaw-cli'`);
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
function stripExportHeader(source: string, id: string): string | null {
|
|
253
|
-
const firstLineMatch = source.match(/^\/\/ Exported from ([^@\r\n]+)@[^\r\n]*(?:\r?\n|$)/);
|
|
254
|
-
if (!firstLineMatch || firstLineMatch[1] !== id) return null;
|
|
255
|
-
return source.replace(/^\/\/ Exported from [^\r\n]*(?:\r?\n|$)/, '');
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
function officialExportIsUnmodified(oldDir: string, id: string, entry: OfficialManifestEntry): boolean {
|
|
259
|
-
const strategyFile = join(oldDir, `${id}.ts`);
|
|
260
|
-
if (!existsSync(strategyFile)) return false;
|
|
261
|
-
|
|
262
|
-
const sourcePath = locateBuiltinSource(id);
|
|
263
|
-
if (!sourcePath) return false;
|
|
264
|
-
const source = readFileSync(sourcePath, 'utf8');
|
|
265
|
-
if (hashContent(source) !== entry.sourceHash) return false;
|
|
266
|
-
|
|
267
|
-
const oldBody = stripExportHeader(readFileSync(strategyFile, 'utf8'), id);
|
|
268
|
-
if (oldBody === null || oldBody !== rewriteBuiltinImportBody(source)) return false;
|
|
269
|
-
|
|
270
|
-
return true;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
function migrateStrategies(workspaceDir: string, result: UserDataMigrationResult): void {
|
|
274
|
-
const oldDir = join(workspaceDir, 'strategies');
|
|
275
|
-
if (!existsSync(oldDir)) return;
|
|
276
|
-
const newDir = getUserDataStrategiesDir(workspaceDir);
|
|
277
|
-
ensureDir(newDir);
|
|
278
|
-
|
|
279
|
-
const manifest = readJson<OfficialManifest>(join(oldDir, '.official', 'manifest.json')) ?? {};
|
|
280
|
-
const skipFiles = new Set<string>();
|
|
281
|
-
for (const [id, entry] of Object.entries(manifest)) {
|
|
282
|
-
if (officialExportIsUnmodified(oldDir, id, entry)) {
|
|
283
|
-
skipFiles.add(`${id}.ts`);
|
|
284
|
-
result.skipped.push(`strategies/${id}.ts official export`);
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
for (const fileName of readdirSync(oldDir)) {
|
|
289
|
-
if (fileName === '.official') continue;
|
|
290
|
-
const from = join(oldDir, fileName);
|
|
291
|
-
let stat;
|
|
292
|
-
try {
|
|
293
|
-
stat = statSync(from);
|
|
294
|
-
} catch {
|
|
295
|
-
continue;
|
|
296
|
-
}
|
|
297
|
-
if (!stat.isFile()) continue;
|
|
298
|
-
const ext = extname(fileName).toLowerCase();
|
|
299
|
-
const isStrategyFile = ext === '.ts' || ext === '.tsx' || ext === '.js';
|
|
300
|
-
if (!isStrategyFile) continue;
|
|
301
|
-
if (skipFiles.has(fileName)) continue;
|
|
302
|
-
|
|
303
|
-
const to = join(newDir, fileName);
|
|
304
|
-
if (existsSync(to)) {
|
|
305
|
-
result.skippedExisting.push(`user-data/strategies/${fileName}`);
|
|
306
|
-
continue;
|
|
307
|
-
}
|
|
308
|
-
copyFileSync(from, to);
|
|
309
|
-
result.copied.push(`strategies/${fileName} -> user-data/strategies/${fileName}`);
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
function migrateHubStrategyLockfile(workspaceDir: string, result: UserDataMigrationResult): void {
|
|
314
|
-
const oldLockFile = join(workspaceDir, 'hub', 'installed.json');
|
|
315
|
-
const newLockFile = getUserDataHubStrategyLockfile(workspaceDir);
|
|
316
|
-
const oldLock = readJson<Record<string, any>>(oldLockFile);
|
|
317
|
-
if (!oldLock) return;
|
|
318
|
-
|
|
319
|
-
const strategyEntries = Object.fromEntries(
|
|
320
|
-
Object.entries(oldLock).filter(([, entry]) => entry?.type === 'strategy'),
|
|
321
|
-
);
|
|
322
|
-
if (Object.keys(strategyEntries).length === 0) {
|
|
323
|
-
result.skipped.push('hub/installed.json skill entries');
|
|
324
|
-
return;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
const current = readJson<Record<string, any>>(newLockFile) ?? {};
|
|
328
|
-
let changed = false;
|
|
329
|
-
for (const [ref, entry] of Object.entries(strategyEntries)) {
|
|
330
|
-
if (current[ref]) {
|
|
331
|
-
result.skippedExisting.push(`user-data/hub/installed-strategies.json ${ref}`);
|
|
332
|
-
continue;
|
|
333
|
-
}
|
|
334
|
-
current[ref] = entry;
|
|
335
|
-
changed = true;
|
|
336
|
-
}
|
|
337
|
-
if (changed) {
|
|
338
|
-
writeJson(newLockFile, current);
|
|
339
|
-
result.copied.push('hub/installed.json strategy entries -> user-data/hub/installed-strategies.json');
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
|
|
343
236
|
function writeMigrationMarker(workspaceDir: string, result: UserDataMigrationResult): void {
|
|
344
237
|
if (result.copied.length === 0 && result.skipped.length === 0 && result.skippedExisting.length === 0) return;
|
|
345
238
|
const marker = join(getUserDataDir(workspaceDir), '.migration.json');
|
|
@@ -357,15 +250,14 @@ export function ensureUserDataLayout(workspaceDir: string): UserDataMigrationRes
|
|
|
357
250
|
const result = EMPTY_RESULT();
|
|
358
251
|
ensureDir(getUserDataDir(workspaceDir));
|
|
359
252
|
ensureDir(getUserDataAccountsDir(workspaceDir));
|
|
360
|
-
ensureDir(
|
|
253
|
+
ensureDir(getUserDataBehaviorsDir(workspaceDir));
|
|
361
254
|
ensureDir(getUserDataPerceptionsDir(workspaceDir));
|
|
255
|
+
ensureDir(getUserDataTriggersDir(workspaceDir));
|
|
362
256
|
ensureDir(getUserDataHubDir(workspaceDir));
|
|
363
257
|
ensureDir(getRuntimeDir(workspaceDir));
|
|
364
258
|
|
|
365
259
|
const auth = migrateAuth(workspaceDir, result);
|
|
366
260
|
migrateAccountFiles(workspaceDir, auth, result);
|
|
367
|
-
migrateStrategies(workspaceDir, result);
|
|
368
|
-
migrateHubStrategyLockfile(workspaceDir, result);
|
|
369
261
|
writeMigrationMarker(workspaceDir, result);
|
|
370
262
|
return result;
|
|
371
263
|
}
|
|
@@ -149,13 +149,13 @@ describe('canonical Agent Event presentation', () => {
|
|
|
149
149
|
expect(derived.hint).toContain('ccl game start-room');
|
|
150
150
|
});
|
|
151
151
|
|
|
152
|
-
it('does not give
|
|
153
|
-
const
|
|
152
|
+
it('does not give Behavior or Perception Events a CCL hint', () => {
|
|
153
|
+
const behavior = presentCanonicalEvent(canonical('match_timeout', {
|
|
154
154
|
waited_secs: 300,
|
|
155
|
-
message: '
|
|
155
|
+
message: 'behavior text',
|
|
156
156
|
}, {
|
|
157
157
|
producer: 'local_synth',
|
|
158
|
-
producerPluginId: 'clawclaw.
|
|
158
|
+
producerPluginId: 'clawclaw.behavior',
|
|
159
159
|
}), null);
|
|
160
160
|
const perception = presentCanonicalEvent(canonical('visual.player_moved', {
|
|
161
161
|
text: 'visual fact',
|
|
@@ -164,7 +164,7 @@ describe('canonical Agent Event presentation', () => {
|
|
|
164
164
|
producerPluginId: 'clawclaw.perception',
|
|
165
165
|
}), null);
|
|
166
166
|
|
|
167
|
-
expect(
|
|
167
|
+
expect(behavior).not.toHaveProperty('hint');
|
|
168
168
|
expect(perception).not.toHaveProperty('hint');
|
|
169
169
|
});
|
|
170
170
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { CanonicalEvent } from '../runtime/framework/events/index.js';
|
|
2
2
|
import { buildLocalGameStartedEnrichment } from '../lib/game-context.js';
|
|
3
|
-
import {
|
|
3
|
+
import { compactEventForChannel } from './event-format.js';
|
|
4
4
|
import { formatCanonicalEventHint } from './event-hints.js';
|
|
5
5
|
|
|
6
6
|
const DESKTOP_SPECTATE_EVENT_TYPES = new Set([
|
|
@@ -67,13 +67,13 @@ export function enrichCanonicalEventForAgent(
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
export function canonicalEventForAgent(event: CanonicalEvent): Record<string, any> {
|
|
70
|
-
return
|
|
70
|
+
return compactEventForChannel(cleanObject({
|
|
71
71
|
...event.payload,
|
|
72
72
|
type: event.type,
|
|
73
73
|
}));
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
/** One authoritative detailed Event presenter for
|
|
76
|
+
/** One authoritative detailed Event presenter for Agent delivery. */
|
|
77
77
|
export function presentCanonicalEvent(
|
|
78
78
|
event: CanonicalEvent,
|
|
79
79
|
summary: any | null | undefined,
|
|
@@ -96,8 +96,8 @@ export function presentCanonicalEvent(
|
|
|
96
96
|
});
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
/**
|
|
100
|
-
export function
|
|
99
|
+
/** Compact Channel projection for visual Events; other Events keep their canonical shape. */
|
|
100
|
+
export function presentCanonicalEventForChannel(
|
|
101
101
|
event: CanonicalEvent,
|
|
102
102
|
summary: any | null | undefined,
|
|
103
103
|
): Record<string, any> | string {
|
|
@@ -108,6 +108,14 @@ export function presentCanonicalEventForCclEvents(
|
|
|
108
108
|
return presentCanonicalEvent(event, summary);
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
+
/** Backward-compatible name for the same compact Agent Event projection. */
|
|
112
|
+
export function presentCanonicalEventForCclEvents(
|
|
113
|
+
event: CanonicalEvent,
|
|
114
|
+
summary: any | null | undefined,
|
|
115
|
+
): Record<string, any> | string {
|
|
116
|
+
return presentCanonicalEventForChannel(event, summary);
|
|
117
|
+
}
|
|
118
|
+
|
|
111
119
|
/** Desktop projection keeps lifecycle guidance but withholds spectate links from its Agent. */
|
|
112
120
|
export function presentCanonicalEventForDesktop(
|
|
113
121
|
event: CanonicalEvent,
|