@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
|
@@ -23,25 +23,21 @@ import {
|
|
|
23
23
|
type PerceptionBoundary,
|
|
24
24
|
type PerceptionBoundaryKind,
|
|
25
25
|
type PerceptionEventProposal,
|
|
26
|
-
type
|
|
26
|
+
type PerceptionFrame,
|
|
27
27
|
type PerceptionSpatialFacts,
|
|
28
|
-
type VisualState,
|
|
29
28
|
} from './contracts.js';
|
|
30
29
|
import { DEFAULT_PERCEPTION_MODULES } from './official-module-ids.js';
|
|
31
30
|
import {
|
|
32
31
|
ImportedLocalPerceptionModuleRunner,
|
|
33
|
-
LocalPerceptionModuleRunner,
|
|
34
32
|
type PerceptionModuleRunner,
|
|
35
33
|
} from './module-runner.js';
|
|
36
34
|
import {
|
|
37
35
|
listClawclawPerceptionSources,
|
|
38
36
|
type ResolvedClawclawPerceptionSource,
|
|
39
37
|
} from './perception-source.js';
|
|
40
|
-
import {
|
|
41
|
-
officialPerceptionModuleClass,
|
|
42
|
-
} from './official-modules.js';
|
|
43
38
|
import {
|
|
44
39
|
PerceptionAnalysisThreadPool,
|
|
40
|
+
perceptionAnalysisWorkerStartModuleId,
|
|
45
41
|
type PerceptionAnalysisJob,
|
|
46
42
|
} from './perception-analysis-thread-pool.js';
|
|
47
43
|
import {
|
|
@@ -52,17 +48,20 @@ import {
|
|
|
52
48
|
CLAWCLAW_PERCEPTION_SPATIAL_API,
|
|
53
49
|
CLAWCLAW_PERCEPTION_SPATIAL_FACTS,
|
|
54
50
|
} from './spatial-facts.js';
|
|
55
|
-
import {
|
|
51
|
+
import { ObservationFrameProjector } from '../../observation-frame-projector.js';
|
|
56
52
|
|
|
57
53
|
export { DEFAULT_PERCEPTION_MODULES } from './official-module-ids.js';
|
|
58
54
|
|
|
59
55
|
export const CLAWCLAW_PERCEPTION_PLUGIN_ID = 'clawclaw.perception';
|
|
60
56
|
export const DEFAULT_MAX_PERCEPTION_BACKFILL_VISUAL_FRAMES = 10;
|
|
57
|
+
export const DEFAULT_PERCEPTION_RECOVERY_TIMEOUT_MS = 30_000;
|
|
61
58
|
const PERCEPTION_MODULE_TIMING_WINDOW_MS = 10_000;
|
|
62
59
|
const PERCEPTION_ANALYSIS_WINDOW_FRAMES = 10;
|
|
63
60
|
|
|
64
61
|
export interface ClawclawPerceptionConfig {
|
|
65
62
|
modules?: readonly string[];
|
|
63
|
+
/** Explicit source workspace for tooling and isolated replay. */
|
|
64
|
+
workspaceDir?: string;
|
|
66
65
|
/** Maximum visual frames replayed into modules during one live Runtime invocation. */
|
|
67
66
|
maxBackfillVisualFrames?: number;
|
|
68
67
|
}
|
|
@@ -80,7 +79,7 @@ export interface LocalizedPerceptionEventDescriptor {
|
|
|
80
79
|
}
|
|
81
80
|
|
|
82
81
|
export interface PerceptionFrameInspection {
|
|
83
|
-
visual:
|
|
82
|
+
visual: PerceptionFrame | null;
|
|
84
83
|
proposals: readonly RuntimeEventProposal[];
|
|
85
84
|
moduleStates: Record<string, unknown>;
|
|
86
85
|
reason?: string;
|
|
@@ -89,7 +88,7 @@ export interface PerceptionFrameInspection {
|
|
|
89
88
|
interface PerceptionModuleSlot {
|
|
90
89
|
readonly manifest: ClawclawPerceptionManifest;
|
|
91
90
|
readonly runner: PerceptionModuleRunner;
|
|
92
|
-
readonly
|
|
91
|
+
readonly source: ResolvedClawclawPerceptionSource;
|
|
93
92
|
/** Invalidates analyses that were computed before an ordered reducer barrier. */
|
|
94
93
|
analysisGeneration: number;
|
|
95
94
|
/** Oldest raw visual frame that a new generation may use as trajectory history. */
|
|
@@ -100,6 +99,11 @@ interface PerceptionModuleSlot {
|
|
|
100
99
|
reducerReplayFromFrameSeq: number | null | undefined;
|
|
101
100
|
}
|
|
102
101
|
|
|
102
|
+
interface PerceptionParallelStartupCandidate {
|
|
103
|
+
readonly module: PerceptionModuleSlot;
|
|
104
|
+
readonly threadModule: PerceptionThreadModuleSpec;
|
|
105
|
+
}
|
|
106
|
+
|
|
103
107
|
function elapsedMs(startedAt: number): number {
|
|
104
108
|
return Math.round(Math.max(0, performance.now() - startedAt) * 1_000) / 1_000;
|
|
105
109
|
}
|
|
@@ -125,7 +129,7 @@ function roundedAverage(values: readonly number[]): number {
|
|
|
125
129
|
|
|
126
130
|
interface PreparedPerceptionFrame {
|
|
127
131
|
readonly stored: StoredStateFrame<Record<string, any>>;
|
|
128
|
-
readonly visual:
|
|
132
|
+
readonly visual: PerceptionFrame | null;
|
|
129
133
|
readonly analyses: readonly PerceptionModuleAnalysis[];
|
|
130
134
|
}
|
|
131
135
|
|
|
@@ -144,13 +148,13 @@ interface PerceptionModuleAnalysis {
|
|
|
144
148
|
|
|
145
149
|
interface PerceptionComputationProposal {
|
|
146
150
|
readonly schema: 'clawclaw.perception-computation.v1';
|
|
147
|
-
readonly visual:
|
|
151
|
+
readonly visual: PerceptionFrame | null;
|
|
148
152
|
readonly analyses: readonly PerceptionModuleAnalysis[];
|
|
149
153
|
}
|
|
150
154
|
|
|
151
155
|
interface PerceptionCheckpoint {
|
|
152
156
|
readonly schema: 'clawclaw.perception-checkpoint.v1';
|
|
153
|
-
/** First
|
|
157
|
+
/** First frame in the current in-process slice; process restart deliberately does not replay it. */
|
|
154
158
|
readonly replayFromFrameSeq: number | null;
|
|
155
159
|
/** Per parallel module, the first frame allowed after its latest private failure boundary. */
|
|
156
160
|
readonly parallelModuleHistoryFloors?: Readonly<Record<string, number>>;
|
|
@@ -174,6 +178,14 @@ function nonEmpty(value: unknown): value is string {
|
|
|
174
178
|
return typeof value === 'string' && value.trim().length > 0;
|
|
175
179
|
}
|
|
176
180
|
|
|
181
|
+
/** Runtime-only lifecycle key. Module authors inspect the canonical Game State directly. */
|
|
182
|
+
function perceptionLifecycle(frame: Readonly<PerceptionFrame>): string {
|
|
183
|
+
const phase = frame.gameState.phase ?? 'unknown';
|
|
184
|
+
return phase === 'wandering' && frame.gameState.you?.is_alive === false
|
|
185
|
+
? 'dead'
|
|
186
|
+
: phase;
|
|
187
|
+
}
|
|
188
|
+
|
|
177
189
|
function hasValidPerceptionEventMetadata(manifest: ClawclawPerceptionManifest): boolean {
|
|
178
190
|
const metadata = manifest.eventMetadata;
|
|
179
191
|
if (metadata === undefined) return true;
|
|
@@ -220,9 +232,6 @@ function perceptionFailureDetails(reason: unknown): Readonly<{
|
|
|
220
232
|
|
|
221
233
|
export function perceptionManifest(instance: ClawclawPerception): ClawclawPerceptionManifest {
|
|
222
234
|
const ModuleClass = moduleClass(instance);
|
|
223
|
-
if (ModuleClass.apiVersion !== PERCEPTION_PLUGIN_API_VERSION) {
|
|
224
|
-
throw new Error('Perception module API version is unsupported.');
|
|
225
|
-
}
|
|
226
235
|
return validatePerceptionManifest(ModuleClass.manifest);
|
|
227
236
|
}
|
|
228
237
|
|
|
@@ -231,6 +240,7 @@ export function validatePerceptionManifest(
|
|
|
231
240
|
): ClawclawPerceptionManifest {
|
|
232
241
|
if (
|
|
233
242
|
!manifest
|
|
243
|
+
|| manifest.apiVersion !== PERCEPTION_PLUGIN_API_VERSION
|
|
234
244
|
|| !/^[a-z0-9][a-z0-9._-]*$/.test(manifest.id)
|
|
235
245
|
|| !nonEmpty(manifest.name)
|
|
236
246
|
|| !nonEmpty(manifest.description)
|
|
@@ -255,47 +265,22 @@ export function validatePerceptionManifest(
|
|
|
255
265
|
return manifest;
|
|
256
266
|
}
|
|
257
267
|
|
|
258
|
-
export function createOfficialPerceptionModule(id: PerceptionModuleId): ClawclawPerception {
|
|
259
|
-
return new (officialPerceptionModuleClass(id))();
|
|
260
|
-
}
|
|
261
|
-
|
|
262
268
|
function createModuleSlots(
|
|
263
269
|
config: ClawclawPerceptionConfig,
|
|
264
270
|
loader: PerceptionModuleLoader,
|
|
265
271
|
): PerceptionModuleSlot[] {
|
|
266
272
|
const ids = [...new Set(config.modules ?? DEFAULT_PERCEPTION_MODULES)].sort();
|
|
267
|
-
const
|
|
268
|
-
|
|
269
|
-
const customSources = new Map(
|
|
270
|
-
customIds.length > 0
|
|
271
|
-
? listClawclawPerceptionSources().map((source) => [source.id, source])
|
|
272
|
-
: [],
|
|
273
|
+
const sources = new Map(
|
|
274
|
+
listClawclawPerceptionSources(config.workspaceDir).map((source) => [source.id, source]),
|
|
273
275
|
);
|
|
274
|
-
const collisions = [...customSources.keys()].filter((id) => officialIds.has(id));
|
|
275
|
-
if (collisions.length > 0) {
|
|
276
|
-
throw new Error(`User perception module id conflicts with an official module: ${collisions.join(', ')}`);
|
|
277
|
-
}
|
|
278
276
|
return ids.map((id) => {
|
|
279
|
-
|
|
280
|
-
const instance = createOfficialPerceptionModule(id as PerceptionModuleId);
|
|
281
|
-
const manifest = perceptionManifest(instance);
|
|
282
|
-
const runner = new LocalPerceptionModuleRunner(instance, manifest);
|
|
283
|
-
return {
|
|
284
|
-
manifest,
|
|
285
|
-
runner,
|
|
286
|
-
analysisGeneration: 0,
|
|
287
|
-
analysisHistoryFloorFrameSeq: 0,
|
|
288
|
-
analysisBaselinePending: false,
|
|
289
|
-
reducerReplayFromFrameSeq: undefined,
|
|
290
|
-
};
|
|
291
|
-
}
|
|
292
|
-
const source = customSources.get(id);
|
|
277
|
+
const source = sources.get(id);
|
|
293
278
|
if (!source) throw new Error(`Unknown perception module '${id}'.`);
|
|
294
279
|
const runner = new ImportedLocalPerceptionModuleRunner(source, loader);
|
|
295
280
|
return {
|
|
296
281
|
manifest: validatePerceptionManifest(runner.manifest),
|
|
297
282
|
runner,
|
|
298
|
-
|
|
283
|
+
source,
|
|
299
284
|
analysisGeneration: 0,
|
|
300
285
|
analysisHistoryFloorFrameSeq: 0,
|
|
301
286
|
analysisBaselinePending: false,
|
|
@@ -311,76 +296,6 @@ function proposals(value: readonly PerceptionEventProposal[] | void): RuntimeEve
|
|
|
311
296
|
})) : [];
|
|
312
297
|
}
|
|
313
298
|
|
|
314
|
-
function perceptionCheckpoint(value: unknown): PerceptionCheckpoint | null {
|
|
315
|
-
if (!value || typeof value !== 'object' || Array.isArray(value)) return null;
|
|
316
|
-
const checkpoint = value as Record<string, unknown>;
|
|
317
|
-
if (checkpoint.schema !== PERCEPTION_CHECKPOINT_SCHEMA) return null;
|
|
318
|
-
const replayFromFrameSeq = checkpoint.replayFromFrameSeq;
|
|
319
|
-
if (
|
|
320
|
-
replayFromFrameSeq !== null
|
|
321
|
-
&& (!Number.isInteger(replayFromFrameSeq) || Number(replayFromFrameSeq) <= 0)
|
|
322
|
-
) return null;
|
|
323
|
-
const rawFloors = checkpoint.parallelModuleHistoryFloors;
|
|
324
|
-
if (rawFloors !== undefined && (
|
|
325
|
-
!rawFloors
|
|
326
|
-
|| typeof rawFloors !== 'object'
|
|
327
|
-
|| Array.isArray(rawFloors)
|
|
328
|
-
)) return null;
|
|
329
|
-
const parallelModuleHistoryFloors: Record<string, number> = {};
|
|
330
|
-
for (const [moduleId, floor] of Object.entries(rawFloors ?? {})) {
|
|
331
|
-
if (
|
|
332
|
-
!/^[a-z0-9][a-z0-9._-]*$/.test(moduleId)
|
|
333
|
-
|| !Number.isInteger(floor)
|
|
334
|
-
|| Number(floor) <= 0
|
|
335
|
-
) return null;
|
|
336
|
-
parallelModuleHistoryFloors[moduleId] = Number(floor);
|
|
337
|
-
}
|
|
338
|
-
const rawReplayStarts = checkpoint.parallelModuleReducerReplayStarts;
|
|
339
|
-
if (rawReplayStarts !== undefined && (
|
|
340
|
-
!rawReplayStarts
|
|
341
|
-
|| typeof rawReplayStarts !== 'object'
|
|
342
|
-
|| Array.isArray(rawReplayStarts)
|
|
343
|
-
)) return null;
|
|
344
|
-
const parallelModuleReducerReplayStarts: Record<string, number | null> = {};
|
|
345
|
-
for (const [moduleId, start] of Object.entries(rawReplayStarts ?? {})) {
|
|
346
|
-
if (
|
|
347
|
-
!/^[a-z0-9][a-z0-9._-]*$/.test(moduleId)
|
|
348
|
-
|| (
|
|
349
|
-
start !== null
|
|
350
|
-
&& (!Number.isInteger(start) || Number(start) <= 0)
|
|
351
|
-
)
|
|
352
|
-
) return null;
|
|
353
|
-
parallelModuleReducerReplayStarts[moduleId] = start === null ? null : Number(start);
|
|
354
|
-
}
|
|
355
|
-
const rawBaselinePending = checkpoint.parallelModuleBaselinePending;
|
|
356
|
-
if (rawBaselinePending !== undefined && (
|
|
357
|
-
!rawBaselinePending
|
|
358
|
-
|| typeof rawBaselinePending !== 'object'
|
|
359
|
-
|| Array.isArray(rawBaselinePending)
|
|
360
|
-
)) return null;
|
|
361
|
-
const parallelModuleBaselinePending: Record<string, boolean> = {};
|
|
362
|
-
for (const [moduleId, pending] of Object.entries(rawBaselinePending ?? {})) {
|
|
363
|
-
if (
|
|
364
|
-
!/^[a-z0-9][a-z0-9._-]*$/.test(moduleId)
|
|
365
|
-
|| typeof pending !== 'boolean'
|
|
366
|
-
) return null;
|
|
367
|
-
parallelModuleBaselinePending[moduleId] = pending;
|
|
368
|
-
}
|
|
369
|
-
return {
|
|
370
|
-
schema: PERCEPTION_CHECKPOINT_SCHEMA,
|
|
371
|
-
replayFromFrameSeq: replayFromFrameSeq === null ? null : Number(replayFromFrameSeq),
|
|
372
|
-
...(Object.keys(parallelModuleHistoryFloors).length === 0
|
|
373
|
-
? {}
|
|
374
|
-
: { parallelModuleHistoryFloors }),
|
|
375
|
-
...(Object.keys(parallelModuleReducerReplayStarts).length === 0
|
|
376
|
-
? {}
|
|
377
|
-
: { parallelModuleReducerReplayStarts }),
|
|
378
|
-
...(Object.keys(parallelModuleBaselinePending).length === 0
|
|
379
|
-
? {}
|
|
380
|
-
: { parallelModuleBaselinePending }),
|
|
381
|
-
};
|
|
382
|
-
}
|
|
383
|
-
|
|
384
299
|
/** One Runtime plugin that projects each frame once and fans it out to perception modules. */
|
|
385
300
|
export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<string, any>> {
|
|
386
301
|
readonly kind = 'epoch' as const;
|
|
@@ -393,23 +308,26 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
|
|
|
393
308
|
: 'every_epoch';
|
|
394
309
|
}
|
|
395
310
|
readonly maxInFlight: number;
|
|
311
|
+
readonly recoveryTimeoutMs = DEFAULT_PERCEPTION_RECOVERY_TIMEOUT_MS;
|
|
396
312
|
readonly produces: { readonly events: readonly string[] };
|
|
397
313
|
|
|
398
|
-
private readonly
|
|
314
|
+
private readonly configuredModules: readonly PerceptionModuleSlot[];
|
|
315
|
+
/** Modules that completed every startup stage for the current lifecycle. */
|
|
316
|
+
private modules: readonly PerceptionModuleSlot[];
|
|
399
317
|
private readonly maxBackfillVisualFrames: number;
|
|
400
318
|
private readonly moduleLoader = new PerceptionModuleLoader();
|
|
401
319
|
private analysisPool?: PerceptionAnalysisThreadPool;
|
|
402
|
-
private readonly projector = new
|
|
320
|
+
private readonly projector = new ObservationFrameProjector();
|
|
403
321
|
private readonly api: PerceptionApi = Object.freeze({
|
|
404
322
|
spatial: CLAWCLAW_PERCEPTION_SPATIAL_API,
|
|
405
323
|
});
|
|
406
|
-
private
|
|
324
|
+
private lifecyclePhase: string | null = null;
|
|
407
325
|
private lastFrameSeq = 0;
|
|
408
326
|
private lastFrameTimeMs: number | null = null;
|
|
409
327
|
private lastVisualTick: number | null = null;
|
|
410
|
-
private lastVisualFrame:
|
|
328
|
+
private lastVisualFrame: PerceptionFrame | null = null;
|
|
411
329
|
private lastConnectionId: string | null = null;
|
|
412
|
-
private readonly analysisWindow:
|
|
330
|
+
private readonly analysisWindow: PerceptionFrame[] = [];
|
|
413
331
|
private replayFromFrameSeq: number | null = null;
|
|
414
332
|
private readonly moduleFailureReports = new Map<string, {
|
|
415
333
|
lastReportedAtMs: number;
|
|
@@ -423,7 +341,6 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
|
|
|
423
341
|
private runnersStartGeneration = 0;
|
|
424
342
|
private runnersStopTask?: Promise<void>;
|
|
425
343
|
private runnerLifecycleGeneration = 0;
|
|
426
|
-
private recovering = false;
|
|
427
344
|
|
|
428
345
|
constructor(config: ClawclawPerceptionConfig = {}) {
|
|
429
346
|
const maxBackfillVisualFrames = config.maxBackfillVisualFrames
|
|
@@ -436,7 +353,10 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
|
|
|
436
353
|
throw new TypeError('maxBackfillVisualFrames must be an integer between 1 and 10.');
|
|
437
354
|
}
|
|
438
355
|
this.maxBackfillVisualFrames = maxBackfillVisualFrames;
|
|
439
|
-
this.
|
|
356
|
+
this.configuredModules = createModuleSlots(config, this.moduleLoader);
|
|
357
|
+
// Keep configured descriptors available before the first Runtime start.
|
|
358
|
+
// Once startup settles, this is narrowed to only successfully active modules.
|
|
359
|
+
this.modules = this.configuredModules;
|
|
440
360
|
// Pure legacy assemblies do all module work in ordered commit. Keeping
|
|
441
361
|
// them at one in-flight epoch preserves the scheduler's normal catch-up
|
|
442
362
|
// path instead of buffering ten empty analysis proposals ahead of a slow
|
|
@@ -456,75 +376,26 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
|
|
|
456
376
|
async recover(context: RuntimeEpochPluginContext<Record<string, any>>): Promise<void> {
|
|
457
377
|
const completedThroughEpochSeq = context.progress().completedThroughEpochSeq;
|
|
458
378
|
if (completedThroughEpochSeq <= 0) return;
|
|
459
|
-
const
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
379
|
+
const latestCompletedFrame = context.stateHistory.queryStateFrames({
|
|
380
|
+
scope: context.scope,
|
|
381
|
+
toEpochSeq: completedThroughEpochSeq,
|
|
382
|
+
order: 'desc',
|
|
383
|
+
limit: 1,
|
|
384
|
+
}).frames[0];
|
|
385
|
+
if (!latestCompletedFrame) return;
|
|
386
|
+
const nextFrameSeq = latestCompletedFrame.frameSeq + 1;
|
|
387
|
+
this.resetProjection();
|
|
388
|
+
this.lastFrameSeq = latestCompletedFrame.frameSeq;
|
|
389
|
+
this.replayFromFrameSeq = nextFrameSeq;
|
|
463
390
|
for (const module of this.modules) {
|
|
464
391
|
if (module.runner.execution !== 'parallel_analysis') continue;
|
|
465
|
-
|
|
466
|
-
if (floor !== undefined) module.analysisHistoryFloorFrameSeq = floor;
|
|
467
|
-
const replayStarts = checkpoint?.parallelModuleReducerReplayStarts;
|
|
468
|
-
const baselinePending = checkpoint?.parallelModuleBaselinePending;
|
|
469
|
-
const hasExactBaseline = !!baselinePending
|
|
470
|
-
&& Object.hasOwn(baselinePending, module.manifest.id);
|
|
471
|
-
if (replayStarts && Object.hasOwn(replayStarts, module.manifest.id)) {
|
|
472
|
-
module.reducerReplayFromFrameSeq = replayStarts[module.manifest.id]!;
|
|
473
|
-
if (!hasExactBaseline) {
|
|
474
|
-
module.analysisBaselinePending = module.reducerReplayFromFrameSeq === null;
|
|
475
|
-
}
|
|
476
|
-
} else if (floor !== undefined && !hasExactBaseline) {
|
|
477
|
-
// Older additive checkpoints only had the history floor. Preserve
|
|
478
|
-
// their conservative behavior by rebuilding a baseline at that floor.
|
|
479
|
-
module.analysisBaselinePending = true;
|
|
480
|
-
}
|
|
481
|
-
if (hasExactBaseline) {
|
|
482
|
-
module.analysisBaselinePending = baselinePending[module.manifest.id]!;
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
this.recovering = true;
|
|
486
|
-
try {
|
|
487
|
-
let afterFrameSeq = 0;
|
|
488
|
-
while (true) {
|
|
489
|
-
const page = context.stateHistory.queryStateFrames({
|
|
490
|
-
scope: context.scope,
|
|
491
|
-
afterFrameSeq,
|
|
492
|
-
order: 'asc',
|
|
493
|
-
limit: 500,
|
|
494
|
-
});
|
|
495
|
-
if (page.frames.length === 0) break;
|
|
496
|
-
for (const frame of page.frames) {
|
|
497
|
-
if (frame.epochSeq !== undefined && frame.epochSeq > completedThroughEpochSeq) return;
|
|
498
|
-
const visual = this.projector.project(frame);
|
|
499
|
-
if (
|
|
500
|
-
hasCheckpoint
|
|
501
|
-
&& (
|
|
502
|
-
checkpoint.replayFromFrameSeq === null
|
|
503
|
-
|| frame.frameSeq < checkpoint.replayFromFrameSeq
|
|
504
|
-
)
|
|
505
|
-
) {
|
|
506
|
-
this.lastFrameSeq = frame.frameSeq;
|
|
507
|
-
} else {
|
|
508
|
-
await this.inspectPreparedFrame(
|
|
509
|
-
await this.prepareFrame(
|
|
510
|
-
frame,
|
|
511
|
-
visual,
|
|
512
|
-
context.signal,
|
|
513
|
-
visual && this.shouldAnalyze(frame)
|
|
514
|
-
? this.analysisInputFromHistory(frame, visual, context)
|
|
515
|
-
: null,
|
|
516
|
-
),
|
|
517
|
-
context.signal,
|
|
518
|
-
context.diagnostic,
|
|
519
|
-
);
|
|
520
|
-
}
|
|
521
|
-
afterFrameSeq = frame.frameSeq;
|
|
522
|
-
}
|
|
523
|
-
if (!page.page.hasMore) break;
|
|
524
|
-
}
|
|
525
|
-
} finally {
|
|
526
|
-
this.recovering = false;
|
|
392
|
+
this.advanceParallelGeneration(module, nextFrameSeq);
|
|
527
393
|
}
|
|
394
|
+
context.diagnostic('perception.recovery_history_skipped', {
|
|
395
|
+
completed_through_epoch_seq: completedThroughEpochSeq,
|
|
396
|
+
skipped_through_frame_seq: latestCompletedFrame.frameSeq,
|
|
397
|
+
resume_from_frame_seq: nextFrameSeq,
|
|
398
|
+
});
|
|
528
399
|
}
|
|
529
400
|
|
|
530
401
|
async update(
|
|
@@ -681,7 +552,9 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
|
|
|
681
552
|
}
|
|
682
553
|
|
|
683
554
|
const previousVisualTick = this.lastVisualTick;
|
|
684
|
-
const
|
|
555
|
+
const projectedLifecycle = perceptionLifecycle(projected);
|
|
556
|
+
const phaseChanged = this.lifecyclePhase !== null
|
|
557
|
+
&& this.lifecyclePhase !== projectedLifecycle;
|
|
685
558
|
const tickDelta = previousVisualTick === null ? null : projected.tick - previousVisualTick;
|
|
686
559
|
const sameConnection = this.lastConnectionId === input.stored.connectionId;
|
|
687
560
|
const emitted: RuntimeEventProposal[] = [];
|
|
@@ -703,7 +576,7 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
|
|
|
703
576
|
&& tickDelta >= 0
|
|
704
577
|
&& tickDelta <= 3
|
|
705
578
|
&& sameConnection;
|
|
706
|
-
const frame:
|
|
579
|
+
const frame: PerceptionFrame = { ...projected, tickDelta, continuousFromPrevious };
|
|
707
580
|
const gap = this.lastVisualTick !== null && !phaseChanged && !continuousFromPrevious;
|
|
708
581
|
|
|
709
582
|
// Close every module's old slice before it receives the new phase/gap frame.
|
|
@@ -778,8 +651,9 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
|
|
|
778
651
|
await analysisPool?.stop();
|
|
779
652
|
// This includes direct imports that are still starting; their own
|
|
780
653
|
// generation fence prevents a late loader result from resurrecting them.
|
|
781
|
-
await Promise.allSettled(this.
|
|
654
|
+
await Promise.allSettled(this.configuredModules.map(({ runner }) => runner.stop(reason)));
|
|
782
655
|
await this.moduleLoader.stop();
|
|
656
|
+
this.modules = [];
|
|
783
657
|
this.moduleFailureReports.clear();
|
|
784
658
|
this.moduleTimingWindows.clear();
|
|
785
659
|
this.moduleTimingWindowStartedAt = performance.now();
|
|
@@ -829,7 +703,7 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
|
|
|
829
703
|
}
|
|
830
704
|
|
|
831
705
|
private async deliverVisualFrame(
|
|
832
|
-
frame: Readonly<
|
|
706
|
+
frame: Readonly<PerceptionFrame>,
|
|
833
707
|
connectionId: string,
|
|
834
708
|
analyses: readonly PerceptionModuleAnalysis[],
|
|
835
709
|
discardParallelAnalysis: boolean,
|
|
@@ -837,7 +711,7 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
|
|
|
837
711
|
diagnostic?: PerceptionDiagnostic,
|
|
838
712
|
): Promise<RuntimeEventProposal[]> {
|
|
839
713
|
this.lastFrameTimeMs = frame.timeMs;
|
|
840
|
-
this.
|
|
714
|
+
this.lifecyclePhase = perceptionLifecycle(frame);
|
|
841
715
|
this.lastVisualTick = frame.tick;
|
|
842
716
|
this.lastVisualFrame = frame;
|
|
843
717
|
this.lastConnectionId = connectionId;
|
|
@@ -856,7 +730,7 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
|
|
|
856
730
|
}
|
|
857
731
|
|
|
858
732
|
private async updateModules(
|
|
859
|
-
frame: Readonly<
|
|
733
|
+
frame: Readonly<PerceptionFrame>,
|
|
860
734
|
analyses: readonly PerceptionModuleAnalysis[],
|
|
861
735
|
discardParallelAnalysis: boolean,
|
|
862
736
|
signal: AbortSignal,
|
|
@@ -968,7 +842,7 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
|
|
|
968
842
|
|
|
969
843
|
private async prepareFrame(
|
|
970
844
|
stored: StoredStateFrame<Record<string, any>>,
|
|
971
|
-
visual:
|
|
845
|
+
visual: PerceptionFrame | null,
|
|
972
846
|
signal: AbortSignal,
|
|
973
847
|
analysisInput: Readonly<PerceptionAnalysisInput> | null = null,
|
|
974
848
|
): Promise<PreparedPerceptionFrame> {
|
|
@@ -1042,7 +916,7 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
|
|
|
1042
916
|
const previous = history.at(-1);
|
|
1043
917
|
const keptImmediatePrevious = previous === input.history.at(-1);
|
|
1044
918
|
const tickDelta = previous ? input.frame.tick - previous.tick : null;
|
|
1045
|
-
const frame:
|
|
919
|
+
const frame: PerceptionFrame = {
|
|
1046
920
|
...input.frame,
|
|
1047
921
|
tickDelta,
|
|
1048
922
|
continuousFromPrevious: !!previous
|
|
@@ -1062,20 +936,17 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
|
|
|
1062
936
|
module: PerceptionModuleSlot,
|
|
1063
937
|
frameSeq: number,
|
|
1064
938
|
): boolean {
|
|
1065
|
-
|
|
1066
|
-
if (!this.recovering) return true;
|
|
1067
|
-
const replayFrom = module.reducerReplayFromFrameSeq;
|
|
1068
|
-
return replayFrom === undefined || (replayFrom !== null && frameSeq >= replayFrom);
|
|
939
|
+
return frameSeq >= module.analysisHistoryFloorFrameSeq;
|
|
1069
940
|
}
|
|
1070
941
|
|
|
1071
942
|
private analysisInputFromHistory(
|
|
1072
943
|
stored: StoredStateFrame<Record<string, any>>,
|
|
1073
|
-
currentVisual:
|
|
944
|
+
currentVisual: PerceptionFrame,
|
|
1074
945
|
context: RuntimeEpochPluginContext<Record<string, any>>,
|
|
1075
946
|
): PerceptionAnalysisInput {
|
|
1076
947
|
const projected = new Map<number, {
|
|
1077
948
|
stored: StoredStateFrame<Record<string, any>>;
|
|
1078
|
-
visual:
|
|
949
|
+
visual: PerceptionFrame;
|
|
1079
950
|
}>();
|
|
1080
951
|
let beforeFrameSeq = stored.frameSeq + 1;
|
|
1081
952
|
while (projected.size < PERCEPTION_ANALYSIS_WINDOW_FRAMES + 1 && beforeFrameSeq > 1) {
|
|
@@ -1103,13 +974,13 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
|
|
|
1103
974
|
}
|
|
1104
975
|
const values = [...projected.values()]
|
|
1105
976
|
.sort((left, right) => left.stored.frameSeq - right.stored.frameSeq);
|
|
1106
|
-
const enriched:
|
|
977
|
+
const enriched: PerceptionFrame[] = [];
|
|
1107
978
|
values.forEach((value, index) => {
|
|
1108
979
|
const previous = index > 0 ? values[index - 1] : undefined;
|
|
1109
980
|
const before = enriched.at(-1);
|
|
1110
981
|
const tickDelta = before ? value.visual.tick - before.tick : null;
|
|
1111
982
|
const continuousFromPrevious = !!before
|
|
1112
|
-
&& before
|
|
983
|
+
&& perceptionLifecycle(before) === perceptionLifecycle(value.visual)
|
|
1113
984
|
&& tickDelta !== null
|
|
1114
985
|
&& tickDelta >= 0
|
|
1115
986
|
&& tickDelta <= 3
|
|
@@ -1128,16 +999,16 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
|
|
|
1128
999
|
|
|
1129
1000
|
private localAnalysisInput(
|
|
1130
1001
|
stored: StoredStateFrame<Record<string, any>>,
|
|
1131
|
-
visual:
|
|
1002
|
+
visual: PerceptionFrame,
|
|
1132
1003
|
): PerceptionAnalysisInput {
|
|
1133
1004
|
const history = this.analysisWindow.slice(-(PERCEPTION_ANALYSIS_WINDOW_FRAMES - 1));
|
|
1134
1005
|
const previous = history.at(-1);
|
|
1135
1006
|
const tickDelta = previous ? visual.tick - previous.tick : null;
|
|
1136
|
-
const frame:
|
|
1007
|
+
const frame: PerceptionFrame = {
|
|
1137
1008
|
...visual,
|
|
1138
1009
|
tickDelta,
|
|
1139
1010
|
continuousFromPrevious: !!previous
|
|
1140
|
-
&& previous
|
|
1011
|
+
&& perceptionLifecycle(previous) === perceptionLifecycle(visual)
|
|
1141
1012
|
&& tickDelta !== null
|
|
1142
1013
|
&& tickDelta >= 0
|
|
1143
1014
|
&& tickDelta <= 3
|
|
@@ -1225,7 +1096,7 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
|
|
|
1225
1096
|
diagnostic,
|
|
1226
1097
|
replayFromFrameSeq ?? this.lastFrameSeq + 1,
|
|
1227
1098
|
);
|
|
1228
|
-
this.
|
|
1099
|
+
this.lifecyclePhase = null;
|
|
1229
1100
|
this.lastFrameTimeMs = null;
|
|
1230
1101
|
this.lastVisualTick = null;
|
|
1231
1102
|
this.lastVisualFrame = null;
|
|
@@ -1242,8 +1113,9 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
|
|
|
1242
1113
|
parallelHistoryFloorFrameSeq?: number,
|
|
1243
1114
|
parallelBaselinePending = true,
|
|
1244
1115
|
): Promise<void> {
|
|
1116
|
+
const modules = this.modules;
|
|
1245
1117
|
if (parallelHistoryFloorFrameSeq !== undefined) {
|
|
1246
|
-
for (const module of
|
|
1118
|
+
for (const module of modules) {
|
|
1247
1119
|
if (module.runner.execution !== 'parallel_analysis') continue;
|
|
1248
1120
|
this.advanceParallelGeneration(
|
|
1249
1121
|
module,
|
|
@@ -1253,9 +1125,9 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
|
|
|
1253
1125
|
}
|
|
1254
1126
|
}
|
|
1255
1127
|
const results = await Promise.allSettled(
|
|
1256
|
-
|
|
1128
|
+
modules.map(({ runner }) => runner.reset(reason, signal)),
|
|
1257
1129
|
);
|
|
1258
|
-
this.reportModuleFailures(`reset:${reason}`, results, diagnostic);
|
|
1130
|
+
this.reportModuleFailures(`reset:${reason}`, modules, results, diagnostic);
|
|
1259
1131
|
}
|
|
1260
1132
|
|
|
1261
1133
|
private async collectModuleEvents(
|
|
@@ -1266,13 +1138,14 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
|
|
|
1266
1138
|
diagnostic?: PerceptionDiagnostic,
|
|
1267
1139
|
onRejected?: (module: PerceptionModuleSlot, error: unknown) => void | Promise<void>,
|
|
1268
1140
|
): Promise<RuntimeEventProposal[]> {
|
|
1141
|
+
const modules = this.modules;
|
|
1269
1142
|
const timings: Array<{
|
|
1270
1143
|
module_id: string;
|
|
1271
1144
|
duration_ms: number;
|
|
1272
1145
|
outcome: 'fulfilled' | 'rejected';
|
|
1273
1146
|
event_count: number;
|
|
1274
|
-
}> = new Array(
|
|
1275
|
-
const results = await Promise.allSettled(
|
|
1147
|
+
}> = new Array(modules.length);
|
|
1148
|
+
const results = await Promise.allSettled(modules.map(async (module, index) => {
|
|
1276
1149
|
const startedAt = performance.now();
|
|
1277
1150
|
try {
|
|
1278
1151
|
const result = await invoke(module);
|
|
@@ -1293,11 +1166,11 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
|
|
|
1293
1166
|
throw error;
|
|
1294
1167
|
}
|
|
1295
1168
|
}));
|
|
1296
|
-
this.reportModuleFailures(operation, results, diagnostic);
|
|
1169
|
+
this.reportModuleFailures(operation, modules, results, diagnostic);
|
|
1297
1170
|
if (onRejected) {
|
|
1298
1171
|
await Promise.allSettled(results.map((result, index) => (
|
|
1299
1172
|
result.status === 'rejected'
|
|
1300
|
-
? onRejected(
|
|
1173
|
+
? onRejected(modules[index]!, result.reason)
|
|
1301
1174
|
: Promise.resolve()
|
|
1302
1175
|
)));
|
|
1303
1176
|
}
|
|
@@ -1365,12 +1238,13 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
|
|
|
1365
1238
|
|
|
1366
1239
|
private reportModuleFailures(
|
|
1367
1240
|
operation: string,
|
|
1241
|
+
modules: readonly PerceptionModuleSlot[],
|
|
1368
1242
|
results: readonly PromiseSettledResult<unknown>[],
|
|
1369
1243
|
diagnostic?: PerceptionDiagnostic,
|
|
1370
1244
|
): void {
|
|
1371
1245
|
results.forEach((result, index) => {
|
|
1372
1246
|
if (result.status === 'fulfilled' || !diagnostic) return;
|
|
1373
|
-
const moduleId =
|
|
1247
|
+
const moduleId = modules[index]!.manifest.id;
|
|
1374
1248
|
this.reportModuleFailure(
|
|
1375
1249
|
moduleId,
|
|
1376
1250
|
operation,
|
|
@@ -1459,55 +1333,203 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
|
|
|
1459
1333
|
): Promise<void> {
|
|
1460
1334
|
let analysisPool: PerceptionAnalysisThreadPool | undefined;
|
|
1461
1335
|
try {
|
|
1462
|
-
const
|
|
1336
|
+
const candidates = this.configuredModules;
|
|
1337
|
+
for (const module of candidates) {
|
|
1338
|
+
module.analysisGeneration = 0;
|
|
1339
|
+
module.analysisHistoryFloorFrameSeq = 0;
|
|
1340
|
+
module.analysisBaselinePending = false;
|
|
1341
|
+
module.reducerReplayFromFrameSeq = undefined;
|
|
1342
|
+
}
|
|
1343
|
+
const startResults = await Promise.allSettled(candidates.map(({ runner }) => runner.start(
|
|
1344
|
+
CLAWCLAW_PERCEPTION_SPATIAL_FACTS satisfies PerceptionSpatialFacts,
|
|
1345
|
+
this.api,
|
|
1346
|
+
signal,
|
|
1347
|
+
)));
|
|
1348
|
+
this.assertRunnerLifecycle(generation, signal);
|
|
1349
|
+
|
|
1350
|
+
const startedModules = candidates.filter((module, index) => {
|
|
1351
|
+
const result = startResults[index]!;
|
|
1352
|
+
if (result.status === 'fulfilled') return true;
|
|
1353
|
+
this.reportModuleFailure(
|
|
1354
|
+
module.manifest.id,
|
|
1355
|
+
'start',
|
|
1356
|
+
perceptionFailureDetails(result.reason),
|
|
1357
|
+
diagnostic,
|
|
1358
|
+
);
|
|
1359
|
+
return false;
|
|
1360
|
+
});
|
|
1361
|
+
await Promise.allSettled(candidates.flatMap((module, index) => (
|
|
1362
|
+
startResults[index]?.status === 'rejected'
|
|
1363
|
+
? [module.runner.stop('shutdown')]
|
|
1364
|
+
: []
|
|
1365
|
+
)));
|
|
1366
|
+
this.assertRunnerLifecycle(generation, signal);
|
|
1367
|
+
|
|
1368
|
+
const parallelModules = startedModules.filter(({ runner }) => (
|
|
1463
1369
|
runner.execution === 'parallel_analysis'
|
|
1464
1370
|
));
|
|
1465
|
-
const
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
: {
|
|
1469
|
-
moduleId: module.manifest.id,
|
|
1470
|
-
kind: 'official' as const,
|
|
1471
|
-
}),
|
|
1472
|
-
);
|
|
1371
|
+
const threadSpecResults = await Promise.allSettled(parallelModules.map((module) => (
|
|
1372
|
+
Promise.resolve().then(() => this.moduleLoader.threadSpec(module.source))
|
|
1373
|
+
)));
|
|
1473
1374
|
this.assertRunnerLifecycle(generation, signal);
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
]);
|
|
1375
|
+
let parallelCandidates: PerceptionParallelStartupCandidate[] = [];
|
|
1376
|
+
const threadSpecFailures: PerceptionModuleSlot[] = [];
|
|
1377
|
+
threadSpecResults.forEach((result, index) => {
|
|
1378
|
+
const module = parallelModules[index]!;
|
|
1379
|
+
if (result.status === 'fulfilled') {
|
|
1380
|
+
parallelCandidates.push({ module, threadModule: result.value });
|
|
1381
|
+
return;
|
|
1382
|
+
}
|
|
1383
|
+
this.reportModuleFailure(
|
|
1384
|
+
module.manifest.id,
|
|
1385
|
+
'worker_start',
|
|
1386
|
+
perceptionFailureDetails(result.reason),
|
|
1387
|
+
diagnostic,
|
|
1388
|
+
);
|
|
1389
|
+
threadSpecFailures.push(module);
|
|
1390
|
+
});
|
|
1391
|
+
await Promise.allSettled(threadSpecFailures.map(({ runner }) => runner.stop('shutdown')));
|
|
1492
1392
|
this.assertRunnerLifecycle(generation, signal);
|
|
1393
|
+
|
|
1394
|
+
let usedSingletonPreflight = false;
|
|
1395
|
+
while (parallelCandidates.length > 0) {
|
|
1396
|
+
const currentPool = new PerceptionAnalysisThreadPool({
|
|
1397
|
+
modules: parallelCandidates.map(({ threadModule }) => threadModule),
|
|
1398
|
+
loader: this.moduleLoader.threadConfig(),
|
|
1399
|
+
spatialFacts: CLAWCLAW_PERCEPTION_SPATIAL_FACTS satisfies PerceptionSpatialFacts,
|
|
1400
|
+
maxWorkers: this.maxInFlight,
|
|
1401
|
+
diagnostic,
|
|
1402
|
+
});
|
|
1403
|
+
analysisPool = currentPool;
|
|
1404
|
+
this.analysisPool = currentPool;
|
|
1405
|
+
try {
|
|
1406
|
+
await currentPool.start();
|
|
1407
|
+
this.assertRunnerLifecycle(generation, signal);
|
|
1408
|
+
break;
|
|
1409
|
+
} catch (error) {
|
|
1410
|
+
await currentPool.stop();
|
|
1411
|
+
if (this.analysisPool === currentPool) this.analysisPool = undefined;
|
|
1412
|
+
analysisPool = undefined;
|
|
1413
|
+
// A concurrent stop is a lifecycle cancellation, not a user-module
|
|
1414
|
+
// failure. Preserve that cancellation instead of reporting it as one.
|
|
1415
|
+
this.assertRunnerLifecycle(generation, signal);
|
|
1416
|
+
|
|
1417
|
+
const failedModuleId = perceptionAnalysisWorkerStartModuleId(error);
|
|
1418
|
+
const failedIndex = failedModuleId
|
|
1419
|
+
? parallelCandidates.findIndex(({ module }) => module.manifest.id === failedModuleId)
|
|
1420
|
+
: -1;
|
|
1421
|
+
if (failedIndex >= 0) {
|
|
1422
|
+
const [failed] = parallelCandidates.splice(failedIndex, 1);
|
|
1423
|
+
this.reportModuleFailure(
|
|
1424
|
+
failed!.module.manifest.id,
|
|
1425
|
+
'worker_start',
|
|
1426
|
+
perceptionFailureDetails(error),
|
|
1427
|
+
diagnostic,
|
|
1428
|
+
);
|
|
1429
|
+
await Promise.allSettled([failed!.module.runner.stop('shutdown')]);
|
|
1430
|
+
continue;
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1433
|
+
if (!usedSingletonPreflight) {
|
|
1434
|
+
usedSingletonPreflight = true;
|
|
1435
|
+
parallelCandidates = await this.preflightParallelStartupCandidates(
|
|
1436
|
+
parallelCandidates,
|
|
1437
|
+
signal,
|
|
1438
|
+
diagnostic,
|
|
1439
|
+
generation,
|
|
1440
|
+
);
|
|
1441
|
+
// Retry the shared pool once even when every singleton succeeded:
|
|
1442
|
+
// the first unattributed failure may have been transient.
|
|
1443
|
+
continue;
|
|
1444
|
+
}
|
|
1445
|
+
|
|
1446
|
+
for (const candidate of parallelCandidates) {
|
|
1447
|
+
this.reportModuleFailure(
|
|
1448
|
+
candidate.module.manifest.id,
|
|
1449
|
+
'worker_start',
|
|
1450
|
+
perceptionFailureDetails(error),
|
|
1451
|
+
diagnostic,
|
|
1452
|
+
);
|
|
1453
|
+
}
|
|
1454
|
+
await Promise.allSettled(parallelCandidates.map(({ module }) => (
|
|
1455
|
+
module.runner.stop('shutdown')
|
|
1456
|
+
)));
|
|
1457
|
+
parallelCandidates = [];
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
const activeParallelIds = new Set(
|
|
1462
|
+
parallelCandidates.map(({ module }) => module.manifest.id),
|
|
1463
|
+
);
|
|
1464
|
+
const activeModules = startedModules.filter(({ manifest, runner }) => (
|
|
1465
|
+
runner.execution === 'ordered_update' || activeParallelIds.has(manifest.id)
|
|
1466
|
+
));
|
|
1467
|
+
|
|
1468
|
+
this.assertRunnerLifecycle(generation, signal);
|
|
1469
|
+
this.modules = activeModules;
|
|
1493
1470
|
this.moduleTimingWindows.clear();
|
|
1494
1471
|
this.moduleTimingWindowStartedAt = performance.now();
|
|
1495
|
-
await this.resetModules('replay', signal);
|
|
1472
|
+
await this.resetModules('replay', signal, diagnostic);
|
|
1496
1473
|
this.assertRunnerLifecycle(generation, signal);
|
|
1497
1474
|
this.resetProjection();
|
|
1498
1475
|
this.runnersStarted = true;
|
|
1499
1476
|
} catch (error) {
|
|
1500
1477
|
await analysisPool?.stop();
|
|
1501
1478
|
if (this.analysisPool === analysisPool) this.analysisPool = undefined;
|
|
1502
|
-
await Promise.allSettled(this.
|
|
1479
|
+
await Promise.allSettled(this.configuredModules.map(({ runner }) => runner.stop('shutdown')));
|
|
1503
1480
|
if (generation === this.runnerLifecycleGeneration) {
|
|
1504
1481
|
await this.moduleLoader.stop();
|
|
1482
|
+
this.modules = [];
|
|
1505
1483
|
this.runnersStarted = false;
|
|
1506
1484
|
}
|
|
1507
1485
|
throw error;
|
|
1508
1486
|
}
|
|
1509
1487
|
}
|
|
1510
1488
|
|
|
1489
|
+
private async preflightParallelStartupCandidates(
|
|
1490
|
+
candidates: readonly PerceptionParallelStartupCandidate[],
|
|
1491
|
+
signal: AbortSignal,
|
|
1492
|
+
diagnostic: PerceptionDiagnostic | undefined,
|
|
1493
|
+
generation: number,
|
|
1494
|
+
): Promise<PerceptionParallelStartupCandidate[]> {
|
|
1495
|
+
const healthy: PerceptionParallelStartupCandidate[] = [];
|
|
1496
|
+
for (const candidate of candidates) {
|
|
1497
|
+
this.assertRunnerLifecycle(generation, signal);
|
|
1498
|
+
const pool = new PerceptionAnalysisThreadPool({
|
|
1499
|
+
modules: [candidate.threadModule],
|
|
1500
|
+
loader: this.moduleLoader.threadConfig(),
|
|
1501
|
+
spatialFacts: CLAWCLAW_PERCEPTION_SPATIAL_FACTS satisfies PerceptionSpatialFacts,
|
|
1502
|
+
maxWorkers: 1,
|
|
1503
|
+
});
|
|
1504
|
+
this.analysisPool = pool;
|
|
1505
|
+
let failure: unknown;
|
|
1506
|
+
let failed = false;
|
|
1507
|
+
try {
|
|
1508
|
+
await pool.start();
|
|
1509
|
+
this.assertRunnerLifecycle(generation, signal);
|
|
1510
|
+
} catch (error) {
|
|
1511
|
+
failed = true;
|
|
1512
|
+
failure = error;
|
|
1513
|
+
} finally {
|
|
1514
|
+
await pool.stop().catch(() => {});
|
|
1515
|
+
if (this.analysisPool === pool) this.analysisPool = undefined;
|
|
1516
|
+
}
|
|
1517
|
+
this.assertRunnerLifecycle(generation, signal);
|
|
1518
|
+
if (!failed) {
|
|
1519
|
+
healthy.push(candidate);
|
|
1520
|
+
continue;
|
|
1521
|
+
}
|
|
1522
|
+
this.reportModuleFailure(
|
|
1523
|
+
candidate.module.manifest.id,
|
|
1524
|
+
'worker_start',
|
|
1525
|
+
perceptionFailureDetails(failure),
|
|
1526
|
+
diagnostic,
|
|
1527
|
+
);
|
|
1528
|
+
await Promise.allSettled([candidate.module.runner.stop('shutdown')]);
|
|
1529
|
+
}
|
|
1530
|
+
return healthy;
|
|
1531
|
+
}
|
|
1532
|
+
|
|
1511
1533
|
private assertRunnerLifecycle(generation: number, signal: AbortSignal): void {
|
|
1512
1534
|
signal.throwIfAborted();
|
|
1513
1535
|
if (generation !== this.runnerLifecycleGeneration) {
|
|
@@ -1517,7 +1539,7 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
|
|
|
1517
1539
|
|
|
1518
1540
|
private resetProjection(): void {
|
|
1519
1541
|
this.projector.reset();
|
|
1520
|
-
this.
|
|
1542
|
+
this.lifecyclePhase = null;
|
|
1521
1543
|
this.lastFrameSeq = 0;
|
|
1522
1544
|
this.lastFrameTimeMs = null;
|
|
1523
1545
|
this.lastVisualTick = null;
|