@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
|
@@ -4,13 +4,23 @@ import { join } from 'node:path';
|
|
|
4
4
|
import { afterEach, describe, expect, it } from 'vitest';
|
|
5
5
|
import {
|
|
6
6
|
CLAWCLAW_ROLE_IDS,
|
|
7
|
-
|
|
7
|
+
DEFAULT_BEHAVIOR_IDLE_MS,
|
|
8
|
+
NPM_ROLE_FALLBACK_BEHAVIORS,
|
|
9
|
+
defaultGameplayConfig,
|
|
10
|
+
parseGameplayConfig,
|
|
8
11
|
readGameplayConfig,
|
|
9
12
|
updateGameplayConfig,
|
|
10
13
|
} from './gameplay-config.js';
|
|
11
14
|
import { getUserDataGameplayConfigFile } from './user-data.js';
|
|
12
15
|
|
|
13
16
|
const dirs: string[] = [];
|
|
17
|
+
const UNIFIED_FIELDS = [
|
|
18
|
+
'disabled_perception_modules',
|
|
19
|
+
'fallback_behaviors',
|
|
20
|
+
'disabled_behaviors',
|
|
21
|
+
'idle_ms',
|
|
22
|
+
'triggers',
|
|
23
|
+
];
|
|
14
24
|
|
|
15
25
|
afterEach(() => {
|
|
16
26
|
for (const dir of dirs.splice(0)) rmSync(dir, { recursive: true, force: true });
|
|
@@ -22,59 +32,270 @@ function workspace(): string {
|
|
|
22
32
|
return dir;
|
|
23
33
|
}
|
|
24
34
|
|
|
35
|
+
function writeExistingConfig(dir: string, value: unknown): string {
|
|
36
|
+
readGameplayConfig(dir);
|
|
37
|
+
const path = getUserDataGameplayConfigFile(dir);
|
|
38
|
+
writeFileSync(path, JSON.stringify(value, null, 2), 'utf8');
|
|
39
|
+
return path;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function legacyDefaults(): Record<string, string | null> {
|
|
43
|
+
return { ...NPM_ROLE_FALLBACK_BEHAVIORS };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function legacyConfig(fallbackIdleMs: unknown = 8_000): Record<string, unknown> {
|
|
47
|
+
return {
|
|
48
|
+
default_strategies: legacyDefaults(),
|
|
49
|
+
disabled_strategies: ['runtime-task-demo'],
|
|
50
|
+
disabled_perception_modules: [],
|
|
51
|
+
disabled_intents: [],
|
|
52
|
+
fallback_idle_ms: fallbackIdleMs,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
25
56
|
describe('gameplay config', () => {
|
|
26
|
-
it('
|
|
57
|
+
it('creates only the unified public fields with a 500ms default idle timeout', () => {
|
|
27
58
|
const dir = workspace();
|
|
28
59
|
const config = readGameplayConfig(dir);
|
|
29
60
|
|
|
30
|
-
expect(Object.keys(config)).toEqual(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
61
|
+
expect(Object.keys(config)).toEqual(UNIFIED_FIELDS);
|
|
62
|
+
expect(config).toEqual({
|
|
63
|
+
disabled_perception_modules: [],
|
|
64
|
+
fallback_behaviors: NPM_ROLE_FALLBACK_BEHAVIORS,
|
|
65
|
+
disabled_behaviors: [],
|
|
66
|
+
idle_ms: DEFAULT_BEHAVIOR_IDLE_MS,
|
|
67
|
+
triggers: {},
|
|
68
|
+
});
|
|
69
|
+
expect(Object.keys(config.fallback_behaviors)).toEqual(CLAWCLAW_ROLE_IDS);
|
|
38
70
|
expect(existsSync(getUserDataGameplayConfigFile(dir))).toBe(true);
|
|
71
|
+
expect(Object.keys(JSON.parse(
|
|
72
|
+
readFileSync(getUserDataGameplayConfigFile(dir), 'utf8'),
|
|
73
|
+
))).toEqual(UNIFIED_FIELDS);
|
|
39
74
|
});
|
|
40
75
|
|
|
41
|
-
it('
|
|
76
|
+
it('accepts only complete unified public config objects', () => {
|
|
77
|
+
const base = defaultGameplayConfig();
|
|
78
|
+
const missing = { ...base } as Record<string, unknown>;
|
|
79
|
+
delete missing.triggers;
|
|
80
|
+
|
|
81
|
+
expect(() => parseGameplayConfig({ ...base, default_strategies: legacyDefaults() }))
|
|
82
|
+
.toThrow('contains unknown fields: default_strategies');
|
|
83
|
+
expect(() => parseGameplayConfig({ ...base, surprise: true }))
|
|
84
|
+
.toThrow('contains unknown fields: surprise');
|
|
85
|
+
expect(() => parseGameplayConfig(missing))
|
|
86
|
+
.toThrow('triggers must be an object');
|
|
87
|
+
expect(() => parseGameplayConfig({ ...base, disabled_perception_modules: null }))
|
|
88
|
+
.toThrow('disabled_perception_modules must be an array');
|
|
89
|
+
expect(() => parseGameplayConfig({ ...base, fallback_behaviors: null }))
|
|
90
|
+
.toThrow('fallback_behaviors must be an object');
|
|
91
|
+
expect(() => parseGameplayConfig({ ...base, disabled_behaviors: null }))
|
|
92
|
+
.toThrow('disabled_behaviors must be an array');
|
|
93
|
+
expect(() => parseGameplayConfig({ ...base, idle_ms: null }))
|
|
94
|
+
.toThrow('idle_ms must be an integer from 0 to 60000');
|
|
95
|
+
expect(() => parseGameplayConfig({ ...base, triggers: null }))
|
|
96
|
+
.toThrow('triggers must be an object');
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('requires exactly every role and a Behavior id or null for each fallback', () => {
|
|
100
|
+
const base = defaultGameplayConfig();
|
|
101
|
+
const missingRole = { ...base.fallback_behaviors } as Record<string, unknown>;
|
|
102
|
+
delete missingRole.shrimp_generic;
|
|
103
|
+
const inheritedRole = Object.assign(
|
|
104
|
+
Object.create({ shrimp_generic: 'task-report' }) as Record<string, unknown>,
|
|
105
|
+
missingRole,
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
expect(() => parseGameplayConfig({ ...base, fallback_behaviors: missingRole }))
|
|
109
|
+
.toThrow('fallback_behaviors.shrimp_generic');
|
|
110
|
+
expect(() => parseGameplayConfig({ ...base, fallback_behaviors: inheritedRole }))
|
|
111
|
+
.toThrow('fallback_behaviors must be an object');
|
|
112
|
+
expect(() => parseGameplayConfig({
|
|
113
|
+
...base,
|
|
114
|
+
fallback_behaviors: { ...base.fallback_behaviors, extra_role: 'task-report' },
|
|
115
|
+
})).toThrow('Unknown role in user-data/gameplay.json fallback_behaviors: extra_role');
|
|
116
|
+
expect(() => parseGameplayConfig({
|
|
117
|
+
...base,
|
|
118
|
+
fallback_behaviors: { ...base.fallback_behaviors, shrimp_generic: false },
|
|
119
|
+
})).toThrow('fallback_behaviors.shrimp_generic');
|
|
120
|
+
expect(parseGameplayConfig({
|
|
121
|
+
...base,
|
|
122
|
+
fallback_behaviors: { ...base.fallback_behaviors, shrimp_generic: null },
|
|
123
|
+
}).fallback_behaviors.shrimp_generic).toBeNull();
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it.each([-1, 60_001, 500.5, '500'])('rejects invalid unified idle value %j', (value) => {
|
|
127
|
+
const base = defaultGameplayConfig();
|
|
128
|
+
expect(() => parseGameplayConfig({ ...base, idle_ms: value })).toThrow(
|
|
129
|
+
'idle_ms must be an integer from 0 to 60000',
|
|
130
|
+
);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it('migrates a legacy file once and immediately removes all legacy fields', () => {
|
|
42
134
|
const dir = workspace();
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
135
|
+
const defaults = legacyDefaults();
|
|
136
|
+
defaults.shrimp_generic = 'custom-shrimp';
|
|
137
|
+
const path = writeExistingConfig(dir, {
|
|
138
|
+
default_strategies: defaults,
|
|
139
|
+
disabled_strategies: ['runtime-task-demo', 'custom.long', 'custom.long'],
|
|
140
|
+
disabled_perception_modules: ['visual.removed'],
|
|
141
|
+
disabled_intents: ['go_to', 'go_to'],
|
|
142
|
+
fallback_idle_ms: 8_000,
|
|
143
|
+
});
|
|
47
144
|
|
|
48
|
-
|
|
145
|
+
const config = readGameplayConfig(dir);
|
|
146
|
+
const persisted = JSON.parse(readFileSync(path, 'utf8'));
|
|
147
|
+
|
|
148
|
+
expect(config.fallback_behaviors.shrimp_generic).toBe('custom-shrimp');
|
|
49
149
|
expect(config.disabled_perception_modules).toEqual(['visual.removed']);
|
|
150
|
+
expect(config.disabled_behaviors).toEqual(['custom.long', 'go_to']);
|
|
151
|
+
expect(config.idle_ms).toBe(500);
|
|
152
|
+
expect(config.triggers).toEqual({});
|
|
153
|
+
expect(Object.keys(config)).toEqual(UNIFIED_FIELDS);
|
|
154
|
+
expect(Object.keys(persisted)).toEqual(UNIFIED_FIELDS);
|
|
155
|
+
expect(persisted).toEqual(config);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it('gives unified values precedence while merging legacy disabled ids', () => {
|
|
159
|
+
const dir = workspace();
|
|
160
|
+
const fallbackBehaviors = {
|
|
161
|
+
...NPM_ROLE_FALLBACK_BEHAVIORS,
|
|
162
|
+
shrimp_generic: null,
|
|
163
|
+
};
|
|
164
|
+
const oldDefaults = legacyDefaults();
|
|
165
|
+
oldDefaults.shrimp_generic = 'old-shrimp';
|
|
166
|
+
writeExistingConfig(dir, {
|
|
167
|
+
disabled_perception_modules: ['visual.current'],
|
|
168
|
+
fallback_behaviors: fallbackBehaviors,
|
|
169
|
+
disabled_behaviors: ['unified.behavior', 'shared.behavior'],
|
|
170
|
+
idle_ms: 750,
|
|
171
|
+
triggers: {
|
|
172
|
+
'danger.followed': {
|
|
173
|
+
enabled: true,
|
|
174
|
+
behavior: 'evade',
|
|
175
|
+
reflex_priority: 20,
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
default_strategies: oldDefaults,
|
|
179
|
+
disabled_strategies: ['runtime-task-demo', 'legacy.strategy', 'shared.behavior'],
|
|
180
|
+
disabled_intents: ['legacy.intent', 'shared.behavior'],
|
|
181
|
+
fallback_idle_ms: 10_000,
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
const config = readGameplayConfig(dir);
|
|
185
|
+
|
|
186
|
+
expect(config.fallback_behaviors.shrimp_generic).toBeNull();
|
|
187
|
+
expect(config.disabled_behaviors).toEqual([
|
|
188
|
+
'unified.behavior',
|
|
189
|
+
'shared.behavior',
|
|
190
|
+
'legacy.strategy',
|
|
191
|
+
'legacy.intent',
|
|
192
|
+
]);
|
|
193
|
+
expect(config.idle_ms).toBe(750);
|
|
194
|
+
expect(config.triggers['danger.followed']).toEqual({
|
|
195
|
+
enabled: true,
|
|
196
|
+
behavior: 'evade',
|
|
197
|
+
reflex_priority: 20,
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it('maps the legacy runtime fallback sentinel to official Behavior fallbacks', () => {
|
|
202
|
+
const dir = workspace();
|
|
203
|
+
writeExistingConfig(dir, {
|
|
204
|
+
...legacyConfig(),
|
|
205
|
+
default_strategies: Object.fromEntries(
|
|
206
|
+
CLAWCLAW_ROLE_IDS.map((role) => [role, 'runtime-task-demo']),
|
|
207
|
+
),
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
expect(readGameplayConfig(dir).fallback_behaviors)
|
|
211
|
+
.toEqual(NPM_ROLE_FALLBACK_BEHAVIORS);
|
|
50
212
|
});
|
|
51
213
|
|
|
52
|
-
it(
|
|
214
|
+
it.each([
|
|
215
|
+
[0, 0],
|
|
216
|
+
[750, 750],
|
|
217
|
+
[8_000, 500],
|
|
218
|
+
[10_000, 10_000],
|
|
219
|
+
[60_000, 60_000],
|
|
220
|
+
])('migrates legacy fallback idle %i to unified idle %i', (legacyValue, expected) => {
|
|
53
221
|
const dir = workspace();
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
delete parsed.default_strategies.shrimp_generic;
|
|
58
|
-
writeFileSync(path, JSON.stringify(parsed));
|
|
59
|
-
expect(() => readGameplayConfig(dir)).toThrow('default_strategies.shrimp_generic');
|
|
222
|
+
writeExistingConfig(dir, legacyConfig(legacyValue));
|
|
223
|
+
|
|
224
|
+
expect(readGameplayConfig(dir).idle_ms).toBe(expected);
|
|
60
225
|
});
|
|
61
226
|
|
|
62
|
-
it('
|
|
227
|
+
it('uses the unified 500ms default when a legacy file omitted its idle field', () => {
|
|
63
228
|
const dir = workspace();
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
229
|
+
const legacy = legacyConfig();
|
|
230
|
+
delete legacy.fallback_idle_ms;
|
|
231
|
+
writeExistingConfig(dir, legacy);
|
|
232
|
+
|
|
233
|
+
expect(readGameplayConfig(dir).idle_ms).toBe(500);
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it.each([-1, 60_001, 500.5, '8000', null])(
|
|
237
|
+
'rejects invalid legacy fallback idle value %j',
|
|
238
|
+
(value) => {
|
|
239
|
+
const dir = workspace();
|
|
240
|
+
writeExistingConfig(dir, legacyConfig(value));
|
|
241
|
+
|
|
242
|
+
expect(() => readGameplayConfig(dir)).toThrow(
|
|
243
|
+
'fallback_idle_ms must be an integer from 0 to 60000',
|
|
244
|
+
);
|
|
245
|
+
},
|
|
246
|
+
);
|
|
247
|
+
|
|
248
|
+
it('rejects unknown fields even while migrating a legacy file', () => {
|
|
249
|
+
const dir = workspace();
|
|
250
|
+
writeExistingConfig(dir, { ...legacyConfig(), surprise: true });
|
|
251
|
+
|
|
252
|
+
expect(() => readGameplayConfig(dir)).toThrow('contains unknown fields: surprise');
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it('updates and normalizes only unified fields', () => {
|
|
256
|
+
const dir = workspace();
|
|
257
|
+
const config = updateGameplayConfig((current) => {
|
|
258
|
+
current.disabled_perception_modules = ['visual.removed', 'visual.removed'];
|
|
259
|
+
current.fallback_behaviors.shrimp_generic = null;
|
|
260
|
+
current.disabled_behaviors = ['custom.behavior', 'custom.behavior'];
|
|
261
|
+
current.idle_ms = 1_000;
|
|
262
|
+
current.triggers = {
|
|
263
|
+
'danger.followed': {
|
|
264
|
+
enabled: true,
|
|
265
|
+
behavior: 'evade',
|
|
266
|
+
cooldown_ms: 250,
|
|
267
|
+
},
|
|
268
|
+
};
|
|
269
|
+
}, dir);
|
|
270
|
+
|
|
271
|
+
expect(Object.keys(config)).toEqual(UNIFIED_FIELDS);
|
|
272
|
+
expect(config.disabled_perception_modules).toEqual(['visual.removed']);
|
|
273
|
+
expect(config.fallback_behaviors.shrimp_generic).toBeNull();
|
|
274
|
+
expect(config.disabled_behaviors).toEqual(['custom.behavior']);
|
|
275
|
+
expect(config.idle_ms).toBe(1_000);
|
|
276
|
+
expect(config.triggers['danger.followed']).toEqual({
|
|
277
|
+
enabled: true,
|
|
278
|
+
behavior: 'evade',
|
|
279
|
+
cooldown_ms: 250,
|
|
77
280
|
});
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
it('reads a complete unified file without rewriting it', () => {
|
|
284
|
+
const dir = workspace();
|
|
285
|
+
const path = writeExistingConfig(dir, defaultGameplayConfig());
|
|
286
|
+
const original = `${JSON.stringify(defaultGameplayConfig(), null, 4)}\n`;
|
|
287
|
+
writeFileSync(path, original, 'utf8');
|
|
288
|
+
|
|
289
|
+
expect(readGameplayConfig(dir)).toEqual(defaultGameplayConfig());
|
|
78
290
|
expect(readFileSync(path, 'utf8')).toBe(original);
|
|
79
291
|
});
|
|
292
|
+
|
|
293
|
+
it('reports malformed JSON without replacing the file', () => {
|
|
294
|
+
const dir = workspace();
|
|
295
|
+
const path = writeExistingConfig(dir, defaultGameplayConfig());
|
|
296
|
+
writeFileSync(path, '{ bad json', 'utf8');
|
|
297
|
+
|
|
298
|
+
expect(() => readGameplayConfig(dir)).toThrow(`Invalid JSON in ${path}`);
|
|
299
|
+
expect(readFileSync(path, 'utf8')).toBe('{ bad json');
|
|
300
|
+
});
|
|
80
301
|
});
|
|
@@ -4,6 +4,10 @@ import {
|
|
|
4
4
|
ensureUserDataLayout,
|
|
5
5
|
getUserDataGameplayConfigFile,
|
|
6
6
|
} from './user-data.js';
|
|
7
|
+
import {
|
|
8
|
+
parseGameplayTriggerConfigs,
|
|
9
|
+
type GameplayTriggerConfigs,
|
|
10
|
+
} from './trigger-config.js';
|
|
7
11
|
|
|
8
12
|
export const CLAWCLAW_ROLE_IDS = [
|
|
9
13
|
'shrimp_generic',
|
|
@@ -15,8 +19,9 @@ export const CLAWCLAW_ROLE_IDS = [
|
|
|
15
19
|
] as const;
|
|
16
20
|
|
|
17
21
|
export type ClawclawRoleId = typeof CLAWCLAW_ROLE_IDS[number];
|
|
22
|
+
export type GameplayFallbackBehaviors = Record<ClawclawRoleId, string | null>;
|
|
18
23
|
|
|
19
|
-
export const
|
|
24
|
+
export const NPM_ROLE_FALLBACK_BEHAVIORS: GameplayFallbackBehaviors = {
|
|
20
25
|
shrimp_generic: 'task-report',
|
|
21
26
|
shrimp_warrior: 'task-report',
|
|
22
27
|
shrimp_pistol: 'task-report',
|
|
@@ -25,32 +30,66 @@ export const NPM_ROLE_DEFAULT_STRATEGIES: Record<ClawclawRoleId, string> = {
|
|
|
25
30
|
neutral_octopus: 'lone-kill-task',
|
|
26
31
|
};
|
|
27
32
|
|
|
33
|
+
export const DEFAULT_BEHAVIOR_IDLE_MS = 500;
|
|
34
|
+
|
|
35
|
+
const LEGACY_DEFAULT_FALLBACK_IDLE_MS = 8_000;
|
|
28
36
|
const LEGACY_RUNTIME_FALLBACK = 'runtime-task-demo';
|
|
37
|
+
const GAMEPLAY_CONFIG_FIELDS = new Set([
|
|
38
|
+
'disabled_perception_modules',
|
|
39
|
+
'fallback_behaviors',
|
|
40
|
+
'disabled_behaviors',
|
|
41
|
+
'idle_ms',
|
|
42
|
+
'triggers',
|
|
43
|
+
]);
|
|
44
|
+
const LEGACY_GAMEPLAY_CONFIG_FIELDS = new Set([
|
|
45
|
+
...GAMEPLAY_CONFIG_FIELDS,
|
|
46
|
+
'default_strategies',
|
|
47
|
+
'disabled_strategies',
|
|
48
|
+
'disabled_intents',
|
|
49
|
+
'fallback_idle_ms',
|
|
50
|
+
]);
|
|
51
|
+
const LEGACY_FIELDS = [
|
|
52
|
+
'default_strategies',
|
|
53
|
+
'disabled_strategies',
|
|
54
|
+
'disabled_intents',
|
|
55
|
+
'fallback_idle_ms',
|
|
56
|
+
] as const;
|
|
29
57
|
|
|
30
58
|
export interface GameplayConfig {
|
|
31
|
-
default_strategies: Record<ClawclawRoleId, string>;
|
|
32
|
-
disabled_strategies: string[];
|
|
33
59
|
disabled_perception_modules: string[];
|
|
60
|
+
fallback_behaviors: GameplayFallbackBehaviors;
|
|
61
|
+
disabled_behaviors: string[];
|
|
62
|
+
idle_ms: number;
|
|
63
|
+
triggers: GameplayTriggerConfigs;
|
|
34
64
|
}
|
|
35
65
|
|
|
36
66
|
const RESOURCE_ID = /^[a-z0-9][a-z0-9._-]*$/;
|
|
67
|
+
|
|
37
68
|
export function defaultGameplayConfig(): GameplayConfig {
|
|
38
69
|
return {
|
|
39
|
-
default_strategies: { ...NPM_ROLE_DEFAULT_STRATEGIES },
|
|
40
|
-
disabled_strategies: [LEGACY_RUNTIME_FALLBACK],
|
|
41
70
|
disabled_perception_modules: [],
|
|
71
|
+
fallback_behaviors: { ...NPM_ROLE_FALLBACK_BEHAVIORS },
|
|
72
|
+
disabled_behaviors: [],
|
|
73
|
+
idle_ms: DEFAULT_BEHAVIOR_IDLE_MS,
|
|
74
|
+
triggers: {},
|
|
42
75
|
};
|
|
43
76
|
}
|
|
44
77
|
|
|
45
78
|
function record(value: unknown): Record<string, unknown> | null {
|
|
46
|
-
|
|
79
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return null;
|
|
80
|
+
const prototype = Object.getPrototypeOf(value);
|
|
81
|
+
return prototype === Object.prototype || prototype === null
|
|
47
82
|
? value as Record<string, unknown>
|
|
48
83
|
: null;
|
|
49
84
|
}
|
|
50
85
|
|
|
86
|
+
function hasOwn(recordValue: Record<string, unknown>, field: string): boolean {
|
|
87
|
+
return Object.prototype.hasOwnProperty.call(recordValue, field);
|
|
88
|
+
}
|
|
89
|
+
|
|
51
90
|
function resourceId(value: unknown, field: string): string {
|
|
52
91
|
if (typeof value !== 'string' || !RESOURCE_ID.test(value)) {
|
|
53
|
-
throw new Error(`${field} must
|
|
92
|
+
throw new Error(`${field} must be a resource id.`);
|
|
54
93
|
}
|
|
55
94
|
return value;
|
|
56
95
|
}
|
|
@@ -60,38 +99,144 @@ function resourceIds(value: unknown, field: string): string[] {
|
|
|
60
99
|
return [...new Set(value.map((entry) => resourceId(entry, field)))];
|
|
61
100
|
}
|
|
62
101
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const configuredDefaults = record(root.default_strategies);
|
|
67
|
-
if (!configuredDefaults) {
|
|
68
|
-
throw new Error('user-data/gameplay.json default_strategies must be an object.');
|
|
102
|
+
function behaviorIdleMs(value: unknown): number {
|
|
103
|
+
if (typeof value !== 'number' || !Number.isSafeInteger(value) || value < 0 || value > 60_000) {
|
|
104
|
+
throw new Error('user-data/gameplay.json idle_ms must be an integer from 0 to 60000.');
|
|
69
105
|
}
|
|
70
|
-
|
|
106
|
+
return value;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function fallbackBehaviorBindings(
|
|
110
|
+
value: unknown,
|
|
111
|
+
field: string,
|
|
112
|
+
options: { legacy?: boolean } = {},
|
|
113
|
+
): GameplayFallbackBehaviors {
|
|
114
|
+
const configured = record(value);
|
|
115
|
+
if (!configured) throw new Error(`${field} must be an object.`);
|
|
116
|
+
const unknownRoles = Object.keys(configured)
|
|
71
117
|
.filter((role) => !(CLAWCLAW_ROLE_IDS as readonly string[]).includes(role));
|
|
72
118
|
if (unknownRoles.length > 0) {
|
|
73
|
-
throw new Error(`Unknown role in
|
|
119
|
+
throw new Error(`Unknown role in ${field}: ${unknownRoles.join(', ')}`);
|
|
74
120
|
}
|
|
75
|
-
const
|
|
121
|
+
const result = {} as GameplayFallbackBehaviors;
|
|
76
122
|
for (const role of CLAWCLAW_ROLE_IDS) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
123
|
+
const configuredBehavior = hasOwn(configured, role) ? configured[role] : undefined;
|
|
124
|
+
if (configuredBehavior === null && !options.legacy) {
|
|
125
|
+
result[role] = null;
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
const behavior = resourceId(configuredBehavior, `${field}.${role}`);
|
|
129
|
+
result[role] = options.legacy && behavior === LEGACY_RUNTIME_FALLBACK
|
|
130
|
+
? NPM_ROLE_FALLBACK_BEHAVIORS[role]
|
|
131
|
+
: behavior;
|
|
132
|
+
}
|
|
133
|
+
return result;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function assertOnlyFields(
|
|
137
|
+
root: Record<string, unknown>,
|
|
138
|
+
allowed: ReadonlySet<string>,
|
|
139
|
+
): void {
|
|
140
|
+
const unknownFields = Object.keys(root).filter((field) => !allowed.has(field));
|
|
141
|
+
if (unknownFields.length > 0) {
|
|
142
|
+
throw new Error(
|
|
143
|
+
`user-data/gameplay.json contains unknown fields: ${unknownFields.sort().join(', ')}.`,
|
|
80
144
|
);
|
|
81
145
|
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export function parseGameplayConfig(value: unknown): GameplayConfig {
|
|
149
|
+
const root = record(value);
|
|
150
|
+
if (!root) throw new Error('user-data/gameplay.json must contain a JSON object.');
|
|
151
|
+
assertOnlyFields(root, GAMEPLAY_CONFIG_FIELDS);
|
|
82
152
|
return {
|
|
83
|
-
default_strategies: defaultStrategies,
|
|
84
|
-
disabled_strategies: resourceIds(
|
|
85
|
-
root.disabled_strategies,
|
|
86
|
-
'user-data/gameplay.json disabled_strategies',
|
|
87
|
-
),
|
|
88
153
|
disabled_perception_modules: resourceIds(
|
|
89
154
|
root.disabled_perception_modules,
|
|
90
155
|
'user-data/gameplay.json disabled_perception_modules',
|
|
91
156
|
),
|
|
157
|
+
fallback_behaviors: fallbackBehaviorBindings(
|
|
158
|
+
root.fallback_behaviors,
|
|
159
|
+
'user-data/gameplay.json fallback_behaviors',
|
|
160
|
+
),
|
|
161
|
+
disabled_behaviors: resourceIds(
|
|
162
|
+
root.disabled_behaviors,
|
|
163
|
+
'user-data/gameplay.json disabled_behaviors',
|
|
164
|
+
),
|
|
165
|
+
idle_ms: behaviorIdleMs(root.idle_ms),
|
|
166
|
+
triggers: parseGameplayTriggerConfigs(root.triggers),
|
|
92
167
|
};
|
|
93
168
|
}
|
|
94
169
|
|
|
170
|
+
function legacyDisabledIds(
|
|
171
|
+
root: Record<string, unknown>,
|
|
172
|
+
field: 'disabled_strategies' | 'disabled_intents',
|
|
173
|
+
): string[] {
|
|
174
|
+
if (!hasOwn(root, field)) return [];
|
|
175
|
+
return resourceIds(root[field], `user-data/gameplay.json ${field}`);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function migratedIdleMs(root: Record<string, unknown>): number {
|
|
179
|
+
if (hasOwn(root, 'idle_ms')) return behaviorIdleMs(root.idle_ms);
|
|
180
|
+
if (!hasOwn(root, 'fallback_idle_ms')) return DEFAULT_BEHAVIOR_IDLE_MS;
|
|
181
|
+
const legacyValue = root.fallback_idle_ms;
|
|
182
|
+
if (
|
|
183
|
+
typeof legacyValue !== 'number'
|
|
184
|
+
|| !Number.isSafeInteger(legacyValue)
|
|
185
|
+
|| legacyValue < 0
|
|
186
|
+
|| legacyValue > 60_000
|
|
187
|
+
) {
|
|
188
|
+
throw new Error(
|
|
189
|
+
'user-data/gameplay.json fallback_idle_ms must be an integer from 0 to 60000.',
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
return legacyValue === LEGACY_DEFAULT_FALLBACK_IDLE_MS
|
|
193
|
+
? DEFAULT_BEHAVIOR_IDLE_MS
|
|
194
|
+
: legacyValue;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function migrateLegacyGameplayConfig(root: Record<string, unknown>): GameplayConfig {
|
|
198
|
+
assertOnlyFields(root, LEGACY_GAMEPLAY_CONFIG_FIELDS);
|
|
199
|
+
const fallbackSource = hasOwn(root, 'fallback_behaviors')
|
|
200
|
+
? root.fallback_behaviors
|
|
201
|
+
: root.default_strategies;
|
|
202
|
+
const legacyDisabledStrategies = legacyDisabledIds(root, 'disabled_strategies')
|
|
203
|
+
.filter((id) => id !== LEGACY_RUNTIME_FALLBACK);
|
|
204
|
+
const legacyDisabledIntents = legacyDisabledIds(root, 'disabled_intents');
|
|
205
|
+
const unifiedDisabledBehaviors = hasOwn(root, 'disabled_behaviors')
|
|
206
|
+
? resourceIds(
|
|
207
|
+
root.disabled_behaviors,
|
|
208
|
+
'user-data/gameplay.json disabled_behaviors',
|
|
209
|
+
)
|
|
210
|
+
: [];
|
|
211
|
+
|
|
212
|
+
return parseGameplayConfig({
|
|
213
|
+
disabled_perception_modules: hasOwn(root, 'disabled_perception_modules')
|
|
214
|
+
? root.disabled_perception_modules
|
|
215
|
+
: [],
|
|
216
|
+
fallback_behaviors: hasOwn(root, 'fallback_behaviors')
|
|
217
|
+
? fallbackBehaviorBindings(
|
|
218
|
+
fallbackSource,
|
|
219
|
+
'user-data/gameplay.json fallback_behaviors',
|
|
220
|
+
)
|
|
221
|
+
: fallbackBehaviorBindings(
|
|
222
|
+
fallbackSource,
|
|
223
|
+
'user-data/gameplay.json default_strategies',
|
|
224
|
+
{ legacy: true },
|
|
225
|
+
),
|
|
226
|
+
disabled_behaviors: [
|
|
227
|
+
...unifiedDisabledBehaviors,
|
|
228
|
+
...legacyDisabledStrategies,
|
|
229
|
+
...legacyDisabledIntents,
|
|
230
|
+
],
|
|
231
|
+
idle_ms: migratedIdleMs(root),
|
|
232
|
+
triggers: hasOwn(root, 'triggers') ? root.triggers : {},
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function hasLegacyFields(root: Record<string, unknown>): boolean {
|
|
237
|
+
return LEGACY_FIELDS.some((field) => hasOwn(root, field));
|
|
238
|
+
}
|
|
239
|
+
|
|
95
240
|
export function writeGameplayConfig(
|
|
96
241
|
config: GameplayConfig,
|
|
97
242
|
workspaceDir = getWorkspaceDir(),
|
|
@@ -111,18 +256,13 @@ export function readGameplayConfig(workspaceDir = getWorkspaceDir()): GameplayCo
|
|
|
111
256
|
const path = getUserDataGameplayConfigFile(workspaceDir);
|
|
112
257
|
if (!existsSync(path)) return writeGameplayConfig(defaultGameplayConfig(), workspaceDir);
|
|
113
258
|
try {
|
|
114
|
-
const
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
)
|
|
118
|
-
|
|
119
|
-
config.default_strategies = { ...NPM_ROLE_DEFAULT_STRATEGIES };
|
|
120
|
-
if (!config.disabled_strategies.includes(LEGACY_RUNTIME_FALLBACK)) {
|
|
121
|
-
config.disabled_strategies.push(LEGACY_RUNTIME_FALLBACK);
|
|
122
|
-
}
|
|
123
|
-
return writeGameplayConfig(config, workspaceDir);
|
|
259
|
+
const raw = JSON.parse(readFileSync(path, 'utf8'));
|
|
260
|
+
const root = record(raw);
|
|
261
|
+
if (!root) throw new Error('user-data/gameplay.json must contain a JSON object.');
|
|
262
|
+
if (hasLegacyFields(root)) {
|
|
263
|
+
return writeGameplayConfig(migrateLegacyGameplayConfig(root), workspaceDir);
|
|
124
264
|
}
|
|
125
|
-
return
|
|
265
|
+
return parseGameplayConfig(root);
|
|
126
266
|
} catch (error) {
|
|
127
267
|
if (error instanceof SyntaxError) {
|
|
128
268
|
throw new Error(`Invalid JSON in ${path}: ${error.message}`);
|