@myclaw163/clawclaw-cli 0.10.11 → 0.10.13
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/bin/clawclaw-cli.mjs +15 -6
- package/bin/startup-trace.d.mts +9 -0
- package/bin/startup-trace.mjs +100 -0
- package/cli-runtime/assets/clawclaw-map.json +1782 -0
- package/cli-runtime/assets/clawclaw-spatial-facts.json +1383 -0
- package/cli-runtime/assets/clawclaw-spatial-model.txt +142 -0
- package/cli-runtime/channel/claude-channel-ipc-server.js +220 -0
- package/cli-runtime/channel/claude-channel-ipc.js +135 -0
- package/cli-runtime/channel/claude-channel-server.js +209 -0
- package/cli-runtime/cli.js +81 -0
- package/cli-runtime/commands/_schema.js +60 -0
- package/cli-runtime/commands/account.js +577 -0
- package/cli-runtime/commands/auth.js +140 -0
- package/cli-runtime/commands/behavior.js +422 -0
- package/cli-runtime/commands/capability.js +327 -0
- package/cli-runtime/commands/communication.js +339 -0
- package/cli-runtime/commands/competition.js +55 -0
- package/cli-runtime/commands/config.js +28 -0
- package/cli-runtime/commands/data.js +78 -0
- package/cli-runtime/commands/events.js +339 -0
- package/cli-runtime/commands/game/index.js +646 -0
- package/cli-runtime/commands/hub.js +152 -0
- package/cli-runtime/commands/load.js +22 -0
- package/cli-runtime/commands/memory.js +30 -0
- package/cli-runtime/commands/module-runtime-control.js +110 -0
- package/cli-runtime/commands/peek.js +38 -0
- package/cli-runtime/commands/perception.js +146 -0
- package/cli-runtime/commands/persona.js +165 -0
- package/cli-runtime/commands/prepare.js +878 -0
- package/cli-runtime/commands/setup/codex.js +244 -0
- package/cli-runtime/commands/setup/hermes.js +55 -0
- package/cli-runtime/commands/setup/index.js +15 -0
- package/cli-runtime/commands/setup/openclaw.js +103 -0
- package/cli-runtime/commands/skill.js +76 -0
- package/cli-runtime/commands/strategy.js +4 -0
- package/cli-runtime/commands/trigger.js +271 -0
- package/cli-runtime/commands/upgrade.js +112 -0
- package/cli-runtime/lib/account-guidance.js +97 -0
- package/cli-runtime/lib/agent-workspace-client.js +66 -0
- package/cli-runtime/lib/agent-workspace-runtime.js +174 -0
- package/cli-runtime/lib/agent-workspace-skills.js +453 -0
- package/cli-runtime/lib/agent-workspace-sync.js +812 -0
- package/cli-runtime/lib/auth.js +210 -0
- package/cli-runtime/lib/capability-cloud-presence.js +134 -0
- package/cli-runtime/lib/capability-cloud-refresh.js +263 -0
- package/cli-runtime/lib/capability-cloud-sync.js +385 -0
- package/cli-runtime/lib/capability-discovery.js +94 -0
- package/cli-runtime/lib/capability-load-diagnostics.js +121 -0
- package/cli-runtime/lib/capability-operation-name.js +24 -0
- package/cli-runtime/lib/capability-operation-rename.js +120 -0
- package/cli-runtime/lib/capability-selection.js +69 -0
- package/cli-runtime/lib/capability-workspace.js +214 -0
- package/cli-runtime/lib/command-error.js +25 -0
- package/cli-runtime/lib/command-meta.js +13 -0
- package/cli-runtime/lib/competition.js +77 -0
- package/cli-runtime/lib/custom-tts.js +363 -0
- package/cli-runtime/lib/desktop-auth.js +44 -0
- package/cli-runtime/lib/desktop-mode.js +12 -0
- package/cli-runtime/lib/diagnostics-config.js +82 -0
- package/cli-runtime/lib/game-client.js +602 -0
- package/cli-runtime/lib/game-context.js +117 -0
- package/cli-runtime/lib/gameplay-config.js +232 -0
- package/cli-runtime/lib/host-config-patcher.js +101 -0
- package/cli-runtime/lib/http-keepalive.js +15 -0
- package/cli-runtime/lib/http-transport.js +163 -0
- package/cli-runtime/lib/hub-client.js +292 -0
- package/cli-runtime/lib/hub-errors.js +51 -0
- package/cli-runtime/lib/hub-reminder.js +65 -0
- package/cli-runtime/lib/hub-unzip.js +52 -0
- package/cli-runtime/lib/init-command.js +160 -0
- package/cli-runtime/lib/load-context.js +97 -0
- package/cli-runtime/lib/load-startup-context.js +59 -0
- package/cli-runtime/lib/load-startup.js +23 -0
- package/cli-runtime/lib/lobby-host-context.js +70 -0
- package/cli-runtime/lib/match-state.js +61 -0
- package/cli-runtime/lib/normalize.js +28 -0
- package/cli-runtime/lib/package-skills.js +15 -0
- package/cli-runtime/lib/participation-leave.js +54 -0
- package/cli-runtime/lib/participation-status.js +73 -0
- package/cli-runtime/lib/perception-config.js +85 -0
- package/cli-runtime/lib/persona.js +157 -0
- package/cli-runtime/lib/room.js +108 -0
- package/cli-runtime/lib/runtime-cadence-config.js +18 -0
- package/cli-runtime/lib/server-registry.js +155 -0
- package/cli-runtime/lib/server-status.js +44 -0
- package/cli-runtime/lib/service-status.js +88 -0
- package/cli-runtime/lib/skill-host.js +246 -0
- package/cli-runtime/lib/skill-name-conflicts.js +89 -0
- package/cli-runtime/lib/skill-version.js +20 -0
- package/cli-runtime/lib/training-role.js +23 -0
- package/cli-runtime/lib/trigger-config.js +138 -0
- package/cli-runtime/lib/user-data.js +336 -0
- package/cli-runtime/lib/workspace-argv.js +35 -0
- package/cli-runtime/lib/workspace-runtime-lock.js +6 -0
- package/cli-runtime/lib/zip-store.js +78 -0
- package/cli-runtime/pipeline/canonical-event-presentation.js +32 -0
- package/cli-runtime/pipeline/event-format.js +921 -0
- package/cli-runtime/pipeline/event-hints.js +235 -0
- package/cli-runtime/pipeline/game-sync-event-normalization.js +228 -0
- package/cli-runtime/pipeline/player-projection.js +272 -0
- package/cli-runtime/pipeline/role-display.js +22 -0
- package/cli-runtime/runtime/auto-upgrade.js +30 -0
- package/cli-runtime/runtime/canonical-event-emitter.js +58 -0
- package/cli-runtime/runtime/canonical-monitor.js +332 -0
- package/cli-runtime/runtime/clawclaw/agent-ability-state.js +41 -0
- package/cli-runtime/runtime/clawclaw/agent-event-policy.js +58 -0
- package/cli-runtime/runtime/clawclaw/behavior-decision.js +84 -0
- package/cli-runtime/runtime/clawclaw/behavior-input-fields.js +212 -0
- package/cli-runtime/runtime/clawclaw/behavior-input.js +54 -0
- package/cli-runtime/runtime/clawclaw/behavior-observation-memory.js +106 -0
- package/cli-runtime/runtime/clawclaw/behavior-read-api.js +110 -0
- package/cli-runtime/runtime/clawclaw/behavior-reflex-control.js +97 -0
- package/cli-runtime/runtime/clawclaw/behavior-start-control.js +159 -0
- package/cli-runtime/runtime/clawclaw/index.js +3 -0
- package/cli-runtime/runtime/clawclaw/navigation/astar-path.js +244 -0
- package/cli-runtime/runtime/clawclaw/navigation/clawclaw-walkable.bin +0 -0
- package/cli-runtime/runtime/clawclaw/navigation/distance-field.js +136 -0
- package/cli-runtime/runtime/clawclaw/navigation/escape-planner.js +273 -0
- package/cli-runtime/runtime/clawclaw/navigation/hide-spots.js +31 -0
- package/cli-runtime/runtime/clawclaw/navigation/off-route-points.js +64 -0
- package/cli-runtime/runtime/clawclaw/navigation/walkable-grid.js +85 -0
- package/cli-runtime/runtime/clawclaw/notification-policy.js +59 -0
- package/cli-runtime/runtime/clawclaw/notification-turn.js +28 -0
- package/cli-runtime/runtime/clawclaw/notifications.js +65 -0
- package/cli-runtime/runtime/clawclaw/observation-frame-projector.js +94 -0
- package/cli-runtime/runtime/clawclaw/owner-lock-error.js +17 -0
- package/cli-runtime/runtime/clawclaw/owner-lock.js +219 -0
- package/cli-runtime/runtime/clawclaw/owner.js +1257 -0
- package/cli-runtime/runtime/clawclaw/perception-module-manifest.js +67 -0
- package/cli-runtime/runtime/clawclaw/perception-strategy-names.js +12 -0
- package/cli-runtime/runtime/clawclaw/persistence-compatibility.js +38 -0
- package/cli-runtime/runtime/clawclaw/plugins/action/action-plugin.js +604 -0
- package/cli-runtime/runtime/clawclaw/plugins/action/automated-action-normalization.js +67 -0
- package/cli-runtime/runtime/clawclaw/plugins/action/index.js +1 -0
- package/cli-runtime/runtime/clawclaw/plugins/assembly.js +134 -0
- package/cli-runtime/runtime/clawclaw/plugins/behavior/activation-manager.js +1 -0
- package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-action.js +26 -0
- package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-analysis-thread-host.js +21 -0
- package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-analysis-thread-host.ts +25 -0
- package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-catalog.js +90 -0
- package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-decision-history.js +60 -0
- package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-instance-snapshot.js +1 -0
- package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-manifest.js +136 -0
- package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-module-loader.js +230 -0
- package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-normalization.js +92 -0
- package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-plugin.js +162 -0
- package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-runner.js +20 -0
- package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-source.js +493 -0
- package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-worker-bridge.js +28 -0
- package/cli-runtime/runtime/clawclaw/plugins/behavior/control-driver.js +5 -0
- package/cli-runtime/runtime/clawclaw/plugins/behavior/index.js +11 -0
- package/cli-runtime/runtime/clawclaw/plugins/behavior/thread-behavior-executor.js +18 -0
- package/cli-runtime/runtime/clawclaw/plugins/behavior-input-source.js +233 -0
- package/cli-runtime/runtime/clawclaw/plugins/derived-event/derived-event-plugin.js +25 -0
- package/cli-runtime/runtime/clawclaw/plugins/derived-event/derived-event-rules.js +289 -0
- package/cli-runtime/runtime/clawclaw/plugins/derived-event/index.js +2 -0
- package/cli-runtime/runtime/clawclaw/plugins/derived-event/player-change-tracker.js +162 -0
- package/cli-runtime/runtime/clawclaw/plugins/derived-event/reminder-plugin.js +182 -0
- package/cli-runtime/runtime/clawclaw/plugins/derived-event/reminder-rules.js +1 -0
- package/cli-runtime/runtime/clawclaw/plugins/derived-event/reminder-runner.js +83 -0
- package/cli-runtime/runtime/clawclaw/plugins/derived-event/reminder-worker.js +35 -0
- package/cli-runtime/runtime/clawclaw/plugins/derived-event/reminder-worker.ts +33 -0
- package/cli-runtime/runtime/clawclaw/plugins/derived-event/state-change-rules.js +111 -0
- package/cli-runtime/runtime/clawclaw/plugins/derived-event/task-change-tracker.js +1 -0
- package/cli-runtime/runtime/clawclaw/plugins/game-query/context-capabilities.js +10 -0
- package/cli-runtime/runtime/clawclaw/plugins/game-query/game-query-plugin.js +196 -0
- package/cli-runtime/runtime/clawclaw/plugins/game-query/index.js +2 -0
- package/cli-runtime/runtime/clawclaw/plugins/index.js +9 -0
- package/cli-runtime/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-adapter.js +24 -0
- package/cli-runtime/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-socket.js +21 -0
- package/cli-runtime/runtime/clawclaw/plugins/mailbox/adapters/game-sync-perception-report-adapter.js +84 -0
- package/cli-runtime/runtime/clawclaw/plugins/mailbox/adapters/game-sync-runtime-report-adapter.js +54 -0
- package/cli-runtime/runtime/clawclaw/plugins/mailbox/agent-mailbox-coordinator.js +61 -0
- package/cli-runtime/runtime/clawclaw/plugins/mailbox/consumer-ids.js +10 -0
- package/cli-runtime/runtime/clawclaw/plugins/mailbox/desktop-event-socket.js +45 -0
- package/cli-runtime/runtime/clawclaw/plugins/mailbox/index.js +11 -0
- package/cli-runtime/runtime/clawclaw/plugins/mailbox/mailbox-event-batch-delivery.js +1 -0
- package/cli-runtime/runtime/clawclaw/plugins/mailbox/mailbox-plugin.js +13 -0
- package/cli-runtime/runtime/clawclaw/plugins/mailbox/mailbox-presentation.js +99 -0
- package/cli-runtime/runtime/clawclaw/plugins/mailbox/mailbox-service.js +84 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/contracts.js +14 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/index.js +11 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/map-concurrent.js +1 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/module-input-boundary.js +64 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/module-runner.js +182 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/notification-content.js +47 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/official-module-ids.js +13 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/perception-analysis-thread-pool.js +684 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/perception-analysis-thread-worker.js +145 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/perception-analysis-thread-worker.ts +252 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/perception-module-loader.js +78 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/perception-module-output.js +15 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/perception-module-plugin.js +144 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/perception-module-runner.js +22 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/perception-module-worker.js +18 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/perception-module-worker.ts +19 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/perception-plugin.js +1343 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/perception-reducer-thread-pool.js +522 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/perception-reducer-thread-worker.js +161 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/perception-reducer-thread-worker.ts +262 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/perception-source.js +489 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/perception-test-fixtures.js +31 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/replay.js +56 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/report-content.js +39 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/shared/math.js +1 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/spatial-facts.js +103 -0
- package/cli-runtime/runtime/clawclaw/plugins/perception/task-baseline.js +29 -0
- package/cli-runtime/runtime/clawclaw/plugins/plugin-api-version.js +89 -0
- package/cli-runtime/runtime/clawclaw/plugins/source/game-transport.js +204 -0
- package/cli-runtime/runtime/clawclaw/plugins/source/index.js +5 -0
- package/cli-runtime/runtime/clawclaw/plugins/source/room-transport.js +399 -0
- package/cli-runtime/runtime/clawclaw/plugins/source/source-plugin.js +2003 -0
- package/cli-runtime/runtime/clawclaw/plugins/source/source-transports.js +26 -0
- package/cli-runtime/runtime/clawclaw/plugins/source/types.js +0 -0
- package/cli-runtime/runtime/clawclaw/plugins/system-perception/rule-runner.js +90 -0
- package/cli-runtime/runtime/clawclaw/plugins/system-perception/sabotage-availability-rule.js +59 -0
- package/cli-runtime/runtime/clawclaw/plugins/system-perception/system-perceptions.js +241 -0
- package/cli-runtime/runtime/clawclaw/plugins/trigger/contracts.js +12 -0
- package/cli-runtime/runtime/clawclaw/plugins/trigger/index.js +4 -0
- package/cli-runtime/runtime/clawclaw/plugins/trigger/trigger-module-loader.js +105 -0
- package/cli-runtime/runtime/clawclaw/plugins/trigger/trigger-plugin.js +741 -0
- package/cli-runtime/runtime/clawclaw/plugins/trigger/trigger-source.js +372 -0
- package/cli-runtime/runtime/clawclaw/plugins/trigger/trigger-thread-pool.js +378 -0
- package/cli-runtime/runtime/clawclaw/plugins/trigger/trigger-thread-worker.js +118 -0
- package/cli-runtime/runtime/clawclaw/plugins/trigger/trigger-thread-worker.ts +168 -0
- package/cli-runtime/runtime/clawclaw/reaction-behavior-resolution.js +1 -0
- package/cli-runtime/runtime/clawclaw/reaction-manifest.js +62 -0
- package/cli-runtime/runtime/clawclaw/reminder-manifest.js +39 -0
- package/cli-runtime/runtime/clawclaw/runtime-cadence.js +28 -0
- package/cli-runtime/runtime/clawclaw/runtime-data-export.js +321 -0
- package/cli-runtime/runtime/clawclaw/runtime-state.js +51 -0
- package/cli-runtime/runtime/clawclaw/runtime.js +132 -0
- package/cli-runtime/runtime/clawclaw/spatial-api.js +48 -0
- package/cli-runtime/runtime/clawclaw/starting-owner-control.js +24 -0
- package/cli-runtime/runtime/clawclaw/strategy-memory-rpc.js +1 -0
- package/cli-runtime/runtime/clawclaw/strategy-memory.js +6 -0
- package/cli-runtime/runtime/clawclaw/task-choice-projection.js +72 -0
- package/cli-runtime/runtime/clawclaw-event-catalog.js +284 -0
- package/cli-runtime/runtime/clawclaw-position.js +0 -0
- package/cli-runtime/runtime/clawclaw-room-state.js +38 -0
- package/cli-runtime/runtime/framework/action-diagnostics.js +69 -0
- package/cli-runtime/runtime/framework/capability-registry.js +1 -0
- package/cli-runtime/runtime/framework/contracts.js +1 -0
- package/cli-runtime/runtime/framework/control/control-scheduler.js +1 -0
- package/cli-runtime/runtime/framework/control/domain-set.js +1 -0
- package/cli-runtime/runtime/framework/control/index.js +1 -0
- package/cli-runtime/runtime/framework/control/types.js +1 -0
- package/cli-runtime/runtime/framework/control-coordinator.js +1 -0
- package/cli-runtime/runtime/framework/events/event-catalog.js +1 -0
- package/cli-runtime/runtime/framework/events/event-delivery-service.js +1 -0
- package/cli-runtime/runtime/framework/events/event-ingress.js +1 -0
- package/cli-runtime/runtime/framework/events/event-repository.js +1 -0
- package/cli-runtime/runtime/framework/events/index.js +5 -0
- package/cli-runtime/runtime/framework/events/memory-event-repository.js +1 -0
- package/cli-runtime/runtime/framework/events/runtime-resume.js +1 -0
- package/cli-runtime/runtime/framework/events/sqlite-event-repository.js +6 -0
- package/cli-runtime/runtime/framework/events/test-helpers.js +56 -0
- package/cli-runtime/runtime/framework/events/types.js +1 -0
- package/cli-runtime/runtime/framework/index.js +7 -0
- package/cli-runtime/runtime/framework/load-node-sqlite.js +1 -0
- package/cli-runtime/runtime/framework/mailbox/coalescer.js +1 -0
- package/cli-runtime/runtime/framework/mailbox/host-notification-sink.js +1 -0
- package/cli-runtime/runtime/framework/mailbox/identity.js +1 -0
- package/cli-runtime/runtime/framework/mailbox/index.js +1 -0
- package/cli-runtime/runtime/framework/mailbox/mailbox-dispatcher.js +1 -0
- package/cli-runtime/runtime/framework/mailbox/mailbox-repository.js +1 -0
- package/cli-runtime/runtime/framework/mailbox/notification-projector.js +1 -0
- package/cli-runtime/runtime/framework/mailbox/types.js +1 -0
- package/cli-runtime/runtime/framework/modules/runtime-module-loader-hooks.mjs +2 -0
- package/cli-runtime/runtime/framework/modules/runtime-module-loader.js +31 -0
- package/cli-runtime/runtime/framework/modules/runtime-module-output.js +1 -0
- package/cli-runtime/runtime/framework/modules/runtime-module-worker-bootstrap.mjs +3 -0
- package/cli-runtime/runtime/framework/participation-manager.js +1 -0
- package/cli-runtime/runtime/framework/persistence/async-sqlite-persistence-worker.js +1 -0
- package/cli-runtime/runtime/framework/persistence/async-sqlite-persistence-worker.ts +2 -0
- package/cli-runtime/runtime/framework/persistence/memory-first-persistence.js +9 -0
- package/cli-runtime/runtime/framework/plugins/contracts.js +1 -0
- package/cli-runtime/runtime/framework/plugins/index.js +1 -0
- package/cli-runtime/runtime/framework/plugins/runtime-event-identity.js +1 -0
- package/cli-runtime/runtime/framework/plugins/runtime-input-journal.js +1 -0
- package/cli-runtime/runtime/framework/plugins/runtime-plugin-scheduler.js +1 -0
- package/cli-runtime/runtime/framework/runtime.js +12 -0
- package/cli-runtime/runtime/framework/serial-task-queue.js +1 -0
- package/cli-runtime/runtime/framework/state/contracts.js +1 -0
- package/cli-runtime/runtime/framework/state/current-state-store.js +1 -0
- package/cli-runtime/runtime/framework/state/durable-agent-state-snapshot.js +1 -0
- package/cli-runtime/runtime/framework/state/freshness.js +1 -0
- package/cli-runtime/runtime/framework/state/history/contracts.js +1 -0
- package/cli-runtime/runtime/framework/state/history/history-writer.js +1 -0
- package/cli-runtime/runtime/framework/state/history/memory-state-history-repository.js +1 -0
- package/cli-runtime/runtime/framework/state/history/sqlite-state-history-repository.js +1 -0
- package/cli-runtime/runtime/framework/state/history/trajectory-projector.js +1 -0
- package/cli-runtime/runtime/framework/state/index.js +1 -0
- package/cli-runtime/runtime/framework/state/state-ingress.js +1 -0
- package/cli-runtime/runtime/framework/state/state-provider.js +1 -0
- package/cli-runtime/runtime/framework/state/types.js +1 -0
- package/cli-runtime/runtime/game-sync-ingress-protocol.js +0 -0
- package/cli-runtime/runtime/game-sync-ingress-worker.js +310 -0
- package/cli-runtime/runtime/game-sync-ingress-worker.ts +274 -0
- package/cli-runtime/runtime/game-sync-protocol.js +278 -0
- package/cli-runtime/runtime/host-monitor-rate-gate.js +1 -0
- package/cli-runtime/runtime/mailbox-host-relay.js +1 -0
- package/cli-runtime/runtime/observability/detail-capture.js +35 -0
- package/cli-runtime/runtime/observability/factory.js +137 -0
- package/cli-runtime/runtime/observability/index.js +6 -0
- package/cli-runtime/runtime/observability/process-timing.js +1 -0
- package/cli-runtime/runtime/observability/recorder.js +1 -0
- package/cli-runtime/runtime/observability/redaction.js +1 -0
- package/cli-runtime/runtime/observability/reporter.js +1 -0
- package/cli-runtime/runtime/observability/sinks.js +1 -0
- package/cli-runtime/runtime/observability/types.js +1 -0
- package/cli-runtime/runtime/owner-control.js +59 -0
- package/cli-runtime/runtime/parent-process-watch.js +1 -0
- package/cli-runtime/runtime/pending-event-handoff.js +48 -0
- package/cli-runtime/runtime/process-identity.js +45 -0
- package/cli-runtime/runtime/raw-ws-log.js +181 -0
- package/cli-runtime/runtime/runtime-logger.js +79 -0
- package/cli-runtime/runtime/threaded-ws-client.js +263 -0
- package/cli-runtime/runtime/ws-client.js +563 -0
- package/cli-runtime/sdk/action.js +133 -0
- package/cli-runtime/sdk/action.ts +160 -0
- package/cli-runtime/sdk/behavior-plugin/index.js +23 -0
- package/cli-runtime/sdk/behavior-plugin/index.ts +341 -0
- package/cli-runtime/sdk/behavior-toolkit/corpse-search.js +56 -0
- package/cli-runtime/sdk/behavior-toolkit/corpse-search.ts +87 -0
- package/cli-runtime/sdk/behavior-toolkit/escape.js +25 -0
- package/cli-runtime/sdk/behavior-toolkit/escape.ts +40 -0
- package/cli-runtime/sdk/behavior-toolkit/index.js +7 -0
- package/cli-runtime/sdk/behavior-toolkit/index.ts +7 -0
- package/cli-runtime/sdk/behavior-toolkit/kill-flow.js +239 -0
- package/cli-runtime/sdk/behavior-toolkit/kill-flow.ts +299 -0
- package/cli-runtime/sdk/behavior-toolkit/model.js +183 -0
- package/cli-runtime/sdk/behavior-toolkit/model.ts +265 -0
- package/cli-runtime/sdk/behavior-toolkit/move-gate.js +30 -0
- package/cli-runtime/sdk/behavior-toolkit/move-gate.ts +52 -0
- package/cli-runtime/sdk/behavior-toolkit/patrol.js +39 -0
- package/cli-runtime/sdk/behavior-toolkit/patrol.ts +53 -0
- package/cli-runtime/sdk/behavior-toolkit/search.js +81 -0
- package/cli-runtime/sdk/behavior-toolkit/search.ts +102 -0
- package/cli-runtime/sdk/index.js +78 -0
- package/cli-runtime/sdk/index.ts +136 -0
- package/cli-runtime/sdk/module-input/index.js +0 -0
- package/cli-runtime/sdk/module-input/index.ts +310 -0
- package/cli-runtime/sdk/perception-plugin/index.js +79 -0
- package/cli-runtime/sdk/perception-plugin/index.ts +251 -0
- package/cli-runtime/sdk/perception-plugin/lifecycle.js +18 -0
- package/cli-runtime/sdk/perception-plugin/lifecycle.ts +15 -0
- package/cli-runtime/sdk/perception-plugin/math.js +99 -0
- package/cli-runtime/sdk/perception-plugin/math.ts +107 -0
- package/cli-runtime/sdk/perception-plugin/module.js +4 -0
- package/cli-runtime/sdk/perception-plugin/module.ts +80 -0
- package/cli-runtime/sdk/perception-plugin/reaction.js +6 -0
- package/cli-runtime/sdk/perception-plugin/reaction.ts +79 -0
- package/cli-runtime/sdk/perception-plugin/reminder-rules.js +131 -0
- package/cli-runtime/sdk/perception-plugin/reminder-rules.ts +89 -0
- package/cli-runtime/sdk/perception-plugin/reminder.js +8 -0
- package/cli-runtime/sdk/perception-plugin/reminder.ts +68 -0
- package/cli-runtime/sdk/perception-plugin/task-change-tracker.js +150 -0
- package/cli-runtime/sdk/perception-plugin/task-change-tracker.ts +258 -0
- package/cli-runtime/sdk/resource-metadata.js +27 -0
- package/cli-runtime/sdk/resource-metadata.ts +66 -0
- package/cli-runtime/sdk/strategy-memory.js +1 -0
- package/cli-runtime/sdk/strategy-memory.ts +1 -0
- package/cli-runtime/sdk/strategy-plugin/index.js +6 -0
- package/cli-runtime/sdk/strategy-plugin/index.ts +36 -0
- package/cli-runtime/sdk/task-availability.js +56 -0
- package/cli-runtime/sdk/task-availability.ts +70 -0
- package/cli-runtime/sdk/trigger-plugin/index.js +16 -0
- package/cli-runtime/sdk/trigger-plugin/index.ts +130 -0
- package/cli-runtime/sdk/types.js +25 -0
- package/cli-runtime/sdk/types.ts +165 -0
- package/cli-runtime/short-command/classifier.js +129 -0
- package/cli-runtime/short-command/index.js +7 -0
- package/cli-runtime/short-command/presenter.js +225 -0
- package/cli-runtime/short-command/process-io.js +13 -0
- package/cli-runtime/short-command/response-contract.js +24 -0
- package/cli-runtime/short-command/runner.js +94 -0
- package/cli-runtime/short-command/sensitive-data-filter.js +92 -0
- package/cli-runtime/short-command/transport-response.js +57 -0
- package/cli-runtime/short-command/types.js +0 -0
- package/dist/strategy-worker/runtime/clawclaw/plugins/behavior/host.js +21 -29
- package/dist/strategy-worker/runtime/clawclaw/plugins/behavior/sdk-sdk.js +76 -6
- package/docs/configuration.md +13 -0
- package/package.json +7 -4
- package/scripts/build-cli.mjs +34 -0
- package/skills/clawclaw/SKILL.md +1 -1
- package/skills/clawclaw/references/STREAM.md +1 -0
- package/skills/clawclaw-start/SKILL.md +1 -0
- package/skills/clawclaw-start/references/STARTUP.md +1 -0
- package/src/cli.ts +75 -77
- package/src/commands/auth.ts +3 -2
- package/src/commands/game/index.ts +33 -9
- package/src/commands/prepare.ts +34 -18
- package/src/lib/agent-workspace-client.ts +12 -9
- package/src/lib/game-client.ts +1 -1
- package/src/lib/http-transport.ts +17 -2
- package/src/lib/hub-client.ts +10 -7
- package/src/pipeline/event-format.ts +2 -0
- package/src/pipeline/event-hints.ts +6 -0
- package/src/runtime/clawclaw/notification-policy.ts +1 -1
- package/src/runtime/clawclaw/owner-lock.ts +3 -2
- package/src/runtime/clawclaw/owner.ts +36 -10
- package/src/runtime/clawclaw/plugins/behavior/behavior-worker-bridge.ts +1 -1
- package/src/runtime/clawclaw/plugins/mailbox/desktop-event-socket.ts +19 -0
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.ts +1 -0
- package/src/runtime/clawclaw/plugins/source/source-plugin.ts +33 -9
- package/src/runtime/clawclaw-event-catalog.ts +1 -0
- package/src/runtime/framework/modules/runtime-module-loader.ts +24 -29
- package/src/runtime/process-identity.ts +44 -0
|
@@ -0,0 +1,741 @@
|
|
|
1
|
+
import { isNotificationTurn } from "../../notification-turn.js";
|
|
2
|
+
import {
|
|
3
|
+
MAX_TRIGGER_RUNTIME_MS,
|
|
4
|
+
TRIGGER_PLUGIN_API_VERSION
|
|
5
|
+
} from "../../../../sdk/trigger-plugin/index.js";
|
|
6
|
+
import { createBehaviorInput } from "../../behavior-input.js";
|
|
7
|
+
import { normalizeBehaviorInput } from "../../behavior-input-fields.js";
|
|
8
|
+
import { ClawclawBehaviorObservationMemory } from "../../behavior-observation-memory.js";
|
|
9
|
+
import { createBehaviorReadApi } from "../../behavior-read-api.js";
|
|
10
|
+
import { ObservationFrameProjector } from "../../observation-frame-projector.js";
|
|
11
|
+
import {
|
|
12
|
+
CLAWCLAW_TRIGGER_PLUGIN_ID
|
|
13
|
+
} from "./contracts.js";
|
|
14
|
+
import { TriggerModuleLoader } from "./trigger-module-loader.js";
|
|
15
|
+
import { assertRuntimeModuleOutputSize } from "../../../framework/modules/runtime-module-output.js";
|
|
16
|
+
import { TriggerThreadPool } from "./trigger-thread-pool.js";
|
|
17
|
+
import { ClawclawStrategyMemory } from "../../strategy-memory.js";
|
|
18
|
+
const TRIGGER_COMPUTATION_SCHEMA = 1;
|
|
19
|
+
const TRIGGER_CHECKPOINT_SCHEMA = 1;
|
|
20
|
+
const DEFAULT_TRIGGER_PLUGIN_TIMEOUT_MS = 2e3;
|
|
21
|
+
function record(value) {
|
|
22
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
23
|
+
}
|
|
24
|
+
function normalizeMatch(value) {
|
|
25
|
+
if (value === void 0) return void 0;
|
|
26
|
+
const source = record(value);
|
|
27
|
+
if (!source) throw new Error("trigger_match_invalid");
|
|
28
|
+
const allowed = /* @__PURE__ */ new Set(["reason", "evidence", "behaviorInput"]);
|
|
29
|
+
for (const key of Object.keys(source)) {
|
|
30
|
+
if (!allowed.has(key)) throw new Error(`trigger_match_field_unknown:${key}`);
|
|
31
|
+
}
|
|
32
|
+
if (typeof source.reason !== "string" || !source.reason.trim()) {
|
|
33
|
+
throw new Error("trigger_match_reason_invalid");
|
|
34
|
+
}
|
|
35
|
+
if (source.evidence !== void 0 && !record(source.evidence)) {
|
|
36
|
+
throw new Error("trigger_match_evidence_invalid");
|
|
37
|
+
}
|
|
38
|
+
if (source.behaviorInput !== void 0 && !record(source.behaviorInput)) {
|
|
39
|
+
throw new Error("trigger_match_behavior_input_invalid");
|
|
40
|
+
}
|
|
41
|
+
const normalized = Object.freeze(structuredClone({
|
|
42
|
+
reason: source.reason.trim(),
|
|
43
|
+
...source.evidence === void 0 ? {} : { evidence: source.evidence },
|
|
44
|
+
...source.behaviorInput === void 0 ? {} : { behaviorInput: source.behaviorInput }
|
|
45
|
+
}));
|
|
46
|
+
assertRuntimeModuleOutputSize(normalized, "trigger_output");
|
|
47
|
+
return normalized;
|
|
48
|
+
}
|
|
49
|
+
function normalizeRegistration(value) {
|
|
50
|
+
const { source } = value;
|
|
51
|
+
const manifest = source.manifest;
|
|
52
|
+
if (!source || source.id !== manifest.id) throw new Error("trigger_source_identity_invalid");
|
|
53
|
+
const input = value.enabled ? normalizeBehaviorInput(value.input ?? {}, manifest.inputs) : Object.freeze(structuredClone(value.input ?? {}));
|
|
54
|
+
const behavior = value.behavior ?? manifest.defaultBehavior;
|
|
55
|
+
const behaviorInput = {
|
|
56
|
+
...structuredClone(manifest.defaultBehaviorInput),
|
|
57
|
+
...structuredClone(value.behaviorInput ?? {})
|
|
58
|
+
};
|
|
59
|
+
const reflexPriority = value.reflexPriority ?? manifest.defaultReflexPriority;
|
|
60
|
+
const cooldownMs = value.cooldownMs ?? manifest.defaultCooldownMs;
|
|
61
|
+
const rearm = value.rearm ?? manifest.defaultRearm;
|
|
62
|
+
const maxRuntimeMs = value.maxRuntimeMs ?? manifest.defaultMaxRuntimeMs;
|
|
63
|
+
if (typeof behavior !== "string" || !/^[a-z0-9][a-z0-9._-]*$/.test(behavior)) {
|
|
64
|
+
throw new Error("trigger_behavior_invalid");
|
|
65
|
+
}
|
|
66
|
+
if (!Number.isSafeInteger(reflexPriority)) throw new Error("trigger_reflex_priority_invalid");
|
|
67
|
+
if (!Number.isSafeInteger(cooldownMs) || cooldownMs < 0) throw new Error("trigger_cooldown_ms_invalid");
|
|
68
|
+
if (rearm !== "after_clear" && rearm !== "after_cooldown") throw new Error("trigger_rearm_invalid");
|
|
69
|
+
if (!Number.isSafeInteger(maxRuntimeMs) || maxRuntimeMs <= 0 || maxRuntimeMs > MAX_TRIGGER_RUNTIME_MS) {
|
|
70
|
+
throw new Error("trigger_max_runtime_ms_invalid");
|
|
71
|
+
}
|
|
72
|
+
return Object.freeze({
|
|
73
|
+
source,
|
|
74
|
+
enabled: value.enabled,
|
|
75
|
+
scope: value.scope,
|
|
76
|
+
input,
|
|
77
|
+
behavior,
|
|
78
|
+
behaviorInput: Object.freeze(behaviorInput),
|
|
79
|
+
reflexPriority,
|
|
80
|
+
cooldownMs,
|
|
81
|
+
rearm,
|
|
82
|
+
maxRuntimeMs
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
function normalizeRegistrations(values) {
|
|
86
|
+
const result = /* @__PURE__ */ new Map();
|
|
87
|
+
for (const value of values) {
|
|
88
|
+
const normalized = normalizeRegistration(value);
|
|
89
|
+
if (result.has(normalized.source.id)) {
|
|
90
|
+
throw new Error(`trigger_registration_duplicate:${normalized.source.id}`);
|
|
91
|
+
}
|
|
92
|
+
result.set(normalized.source.id, normalized);
|
|
93
|
+
}
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
function proposal(value) {
|
|
97
|
+
const parsed = record(value);
|
|
98
|
+
if (parsed?.schema !== TRIGGER_COMPUTATION_SCHEMA || !Number.isSafeInteger(parsed.configGeneration) || !Number.isSafeInteger(parsed.epochId) || typeof parsed.nowMs !== "number" || !Array.isArray(parsed.evaluations)) throw new Error("trigger_computation_invalid");
|
|
99
|
+
return parsed;
|
|
100
|
+
}
|
|
101
|
+
function diagnosticErrorCode(error) {
|
|
102
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
103
|
+
return /^[a-z0-9_.:-]+$/i.test(message) ? message.slice(0, 160) : "TRIGGER_MODULE_FAILED";
|
|
104
|
+
}
|
|
105
|
+
function triggerInputFor(frame, semanticInput, config) {
|
|
106
|
+
const consumes = new Set(config.source.manifest.consumes);
|
|
107
|
+
const events = consumes.has("*") ? semanticInput.events : semanticInput.events.filter((event) => consumes.has(event.type));
|
|
108
|
+
return Object.freeze({
|
|
109
|
+
frame,
|
|
110
|
+
...semanticInput.cycle ? { cycle: semanticInput.cycle } : {},
|
|
111
|
+
events: Object.freeze(events),
|
|
112
|
+
input: config.input
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
function behaviorInputForTrigger(frame, semanticInput, triggerInput) {
|
|
116
|
+
return Object.freeze({
|
|
117
|
+
epochId: semanticInput.epochId,
|
|
118
|
+
scope: semanticInput.scope,
|
|
119
|
+
nowMs: semanticInput.nowMs,
|
|
120
|
+
...semanticInput.cycle ? { cycle: semanticInput.cycle } : {},
|
|
121
|
+
gameState: frame.gameState,
|
|
122
|
+
events: triggerInput.events,
|
|
123
|
+
input: triggerInput.input
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
function triggerLifecycle(frame) {
|
|
127
|
+
const phase = frame.gameState.phase ?? "unknown";
|
|
128
|
+
return phase === "wandering" && frame.gameState.you?.is_alive === false ? "dead" : phase;
|
|
129
|
+
}
|
|
130
|
+
class ClawclawTriggerPlugin {
|
|
131
|
+
kind = "epoch";
|
|
132
|
+
id = CLAWCLAW_TRIGGER_PLUGIN_ID;
|
|
133
|
+
version = String(TRIGGER_PLUGIN_API_VERSION);
|
|
134
|
+
after;
|
|
135
|
+
consumes = { events: ["*"] };
|
|
136
|
+
catchUp = "every_epoch";
|
|
137
|
+
get maxInFlight() {
|
|
138
|
+
return this.threaded ? 10 : 1;
|
|
139
|
+
}
|
|
140
|
+
maxPendingEpochs = 10;
|
|
141
|
+
backlogPolicy = "finish_started";
|
|
142
|
+
timeoutMs = DEFAULT_TRIGGER_PLUGIN_TIMEOUT_MS;
|
|
143
|
+
failurePolicy = "failed_completion";
|
|
144
|
+
registrations;
|
|
145
|
+
loader;
|
|
146
|
+
slots = /* @__PURE__ */ new Map();
|
|
147
|
+
loadFailures = /* @__PURE__ */ new Set();
|
|
148
|
+
states = /* @__PURE__ */ new Map();
|
|
149
|
+
observationMemory = new ClawclawBehaviorObservationMemory();
|
|
150
|
+
memory;
|
|
151
|
+
projector = new ObservationFrameProjector();
|
|
152
|
+
threaded;
|
|
153
|
+
diagnosticsEnabled;
|
|
154
|
+
threadPool;
|
|
155
|
+
threadPoolStartTask;
|
|
156
|
+
threadPoolFailed = false;
|
|
157
|
+
pendingThreadResetReason;
|
|
158
|
+
driver;
|
|
159
|
+
configGeneration = 1;
|
|
160
|
+
currentScope;
|
|
161
|
+
isEnabled(config) {
|
|
162
|
+
return config.enabled && (!config.scope || config.scope.sessionId === this.currentScope?.sessionId && config.scope.segmentId === this.currentScope?.segmentId);
|
|
163
|
+
}
|
|
164
|
+
started = false;
|
|
165
|
+
lastFrameSeq = 0;
|
|
166
|
+
lastVisualTick = null;
|
|
167
|
+
lastConnectionId = null;
|
|
168
|
+
lifecyclePhase = null;
|
|
169
|
+
constructor(options = {}) {
|
|
170
|
+
this.memory = options.memory ?? new ClawclawStrategyMemory();
|
|
171
|
+
this.after = [...options.after ?? []];
|
|
172
|
+
this.registrations = normalizeRegistrations(options.triggers ?? []);
|
|
173
|
+
this.loader = options.loader ?? new TriggerModuleLoader();
|
|
174
|
+
this.driver = options.driver;
|
|
175
|
+
this.threaded = options.threaded ?? options.loader === void 0;
|
|
176
|
+
this.diagnosticsEnabled = options.diagnosticsEnabled === true;
|
|
177
|
+
}
|
|
178
|
+
attachMemory(memory) {
|
|
179
|
+
if (this.started) throw Error("strategy_memory_already_started");
|
|
180
|
+
this.memory = memory;
|
|
181
|
+
}
|
|
182
|
+
attachDriver(driver) {
|
|
183
|
+
if (this.driver && this.driver !== driver) throw new Error("trigger_activation_driver_already_attached");
|
|
184
|
+
this.driver = driver;
|
|
185
|
+
}
|
|
186
|
+
/** Atomically replace effective config; newly enabled modules import on the next ordered boundary. */
|
|
187
|
+
configure(triggers) {
|
|
188
|
+
const next = normalizeRegistrations(triggers);
|
|
189
|
+
for (const [id, config] of next) {
|
|
190
|
+
if (config.enabled && !this.registrations.get(id)?.enabled) {
|
|
191
|
+
const state = this.states.get(id);
|
|
192
|
+
if (state) state.armed = true;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
this.configGeneration += 1;
|
|
196
|
+
this.registrations = next;
|
|
197
|
+
this.slots.clear();
|
|
198
|
+
this.loadFailures.clear();
|
|
199
|
+
for (const id of this.states.keys()) if (!next.has(id)) this.states.delete(id);
|
|
200
|
+
this.observationMemory.clear();
|
|
201
|
+
this.clearFrameBoundary();
|
|
202
|
+
void this.threadPool?.stop();
|
|
203
|
+
this.threadPool = void 0;
|
|
204
|
+
this.threadPoolStartTask = void 0;
|
|
205
|
+
this.threadPoolFailed = false;
|
|
206
|
+
this.pendingThreadResetReason = void 0;
|
|
207
|
+
this.loader.stop();
|
|
208
|
+
}
|
|
209
|
+
descriptors() {
|
|
210
|
+
return [...this.registrations.values()].map((entry) => Object.freeze({
|
|
211
|
+
id: entry.source.id,
|
|
212
|
+
enabled: this.isEnabled(entry),
|
|
213
|
+
armed: this.states.get(entry.source.id)?.armed ?? true,
|
|
214
|
+
cooldownRemainingMs: Math.max(0, entry.cooldownMs - (Date.now() - (this.states.get(entry.source.id)?.lastAcceptedAtMs ?? 0))),
|
|
215
|
+
behavior: entry.behavior,
|
|
216
|
+
reflexPriority: entry.reflexPriority,
|
|
217
|
+
cooldownMs: entry.cooldownMs,
|
|
218
|
+
rearm: entry.rearm,
|
|
219
|
+
maxRuntimeMs: entry.maxRuntimeMs
|
|
220
|
+
}));
|
|
221
|
+
}
|
|
222
|
+
diagnosticSnapshot() {
|
|
223
|
+
const pool = this.threadPool?.snapshot();
|
|
224
|
+
return Object.freeze({
|
|
225
|
+
threaded: this.threaded,
|
|
226
|
+
configured_trigger_count: this.registrations.size,
|
|
227
|
+
enabled_trigger_count: [...this.registrations.values()].filter((config) => this.isEnabled(config)).length,
|
|
228
|
+
active_trigger_count: this.threaded ? pool?.workerCount ?? 0 : this.slots.size,
|
|
229
|
+
thread_pool_failed: this.threadPoolFailed,
|
|
230
|
+
worker_pool: pool ? {
|
|
231
|
+
state: pool.state,
|
|
232
|
+
worker_count: pool.workerCount,
|
|
233
|
+
busy_worker_count: pool.busyWorkerCount,
|
|
234
|
+
queued_request_count: pool.queuedRequestCount,
|
|
235
|
+
in_flight_request_count: pool.inFlightRequestCount,
|
|
236
|
+
worker_heap_used_bytes: pool.workerHeapUsedBytes,
|
|
237
|
+
peak_worker_heap_used_bytes: pool.peakWorkerHeapUsedBytes
|
|
238
|
+
} : null
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
async start(context) {
|
|
242
|
+
this.started = true;
|
|
243
|
+
this.memory.open(context.scope);
|
|
244
|
+
this.currentScope = context.scope;
|
|
245
|
+
if (this.threaded) await this.ensureThreadPool(context);
|
|
246
|
+
else await this.ensureModules(context);
|
|
247
|
+
}
|
|
248
|
+
recover(context) {
|
|
249
|
+
const checkpoint = record(context.checkpoint());
|
|
250
|
+
if (checkpoint?.schema !== TRIGGER_CHECKPOINT_SCHEMA) return;
|
|
251
|
+
const states = record(checkpoint.states);
|
|
252
|
+
if (!states) return;
|
|
253
|
+
for (const [triggerId, value] of Object.entries(states)) {
|
|
254
|
+
if (!this.registrations.has(triggerId)) continue;
|
|
255
|
+
const state = record(value);
|
|
256
|
+
if (!state || typeof state.armed !== "boolean") continue;
|
|
257
|
+
if (state.lastAcceptedAtMs !== void 0 && typeof state.lastAcceptedAtMs !== "number") continue;
|
|
258
|
+
this.states.set(triggerId, {
|
|
259
|
+
armed: state.armed,
|
|
260
|
+
...state.lastAcceptedAtMs === void 0 ? {} : {
|
|
261
|
+
lastAcceptedAtMs: state.lastAcceptedAtMs
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
async update(input, context) {
|
|
267
|
+
if (isNotificationTurn(input.epoch.state)) return { outcome: "noop", reason: "notification_only" };
|
|
268
|
+
this.currentScope = input.epoch.scope;
|
|
269
|
+
if (![...this.registrations.values()].some((config) => this.isEnabled(config))) {
|
|
270
|
+
return { outcome: "noop", reason: "no_enabled_triggers", proposal: {
|
|
271
|
+
schema: TRIGGER_COMPUTATION_SCHEMA,
|
|
272
|
+
configGeneration: this.configGeneration,
|
|
273
|
+
epochId: input.epoch.epochSeq,
|
|
274
|
+
nowMs: input.frame.observedAtMs ?? input.frame.receivedAtMs,
|
|
275
|
+
...input.pendingEvents.length ? { eventCursor: input.pendingEvents.at(-1).commitSeq } : {},
|
|
276
|
+
evaluations: []
|
|
277
|
+
} };
|
|
278
|
+
}
|
|
279
|
+
if (this.threaded) return this.updateThreaded(input, context);
|
|
280
|
+
await this.ensureModules(context);
|
|
281
|
+
const generation = this.configGeneration;
|
|
282
|
+
const eventCursor = input.pendingEvents.at(-1)?.commitSeq;
|
|
283
|
+
const triggerVisibleInput = {
|
|
284
|
+
...input,
|
|
285
|
+
pendingEvents: input.pendingEvents.filter((event) => event.producer === "backend_push" && !event.notificationOf && event.producerPluginId === void 0)
|
|
286
|
+
};
|
|
287
|
+
const emptyInput = createBehaviorInput(triggerVisibleInput, Object.freeze({}));
|
|
288
|
+
if (!emptyInput || emptyInput.gameState.phase !== "wandering" || emptyInput.gameState.you?.is_alive === false) {
|
|
289
|
+
if (this.lastVisualTick !== null) {
|
|
290
|
+
await this.requestModuleReset("phase_changed", context);
|
|
291
|
+
this.clearFrameBoundary();
|
|
292
|
+
}
|
|
293
|
+
return {
|
|
294
|
+
outcome: "processed",
|
|
295
|
+
reason: "trigger_ineligible_state",
|
|
296
|
+
proposal: {
|
|
297
|
+
schema: TRIGGER_COMPUTATION_SCHEMA,
|
|
298
|
+
configGeneration: generation,
|
|
299
|
+
epochId: input.epoch.epochSeq,
|
|
300
|
+
nowMs: input.frame.observedAtMs ?? input.frame.receivedAtMs,
|
|
301
|
+
...eventCursor === void 0 ? {} : { eventCursor },
|
|
302
|
+
evaluations: []
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
const projected = this.projector.project(input.frame);
|
|
307
|
+
if (!projected) {
|
|
308
|
+
if (this.lastVisualTick !== null) {
|
|
309
|
+
await this.requestModuleReset("trajectory_gap", context);
|
|
310
|
+
this.clearFrameBoundary();
|
|
311
|
+
}
|
|
312
|
+
return {
|
|
313
|
+
outcome: "processed",
|
|
314
|
+
reason: "trigger_observation_unavailable",
|
|
315
|
+
proposal: {
|
|
316
|
+
schema: TRIGGER_COMPUTATION_SCHEMA,
|
|
317
|
+
configGeneration: generation,
|
|
318
|
+
epochId: input.epoch.epochSeq,
|
|
319
|
+
nowMs: emptyInput.nowMs,
|
|
320
|
+
...eventCursor === void 0 ? {} : { eventCursor },
|
|
321
|
+
evaluations: []
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
const stateFrameGap = this.lastFrameSeq > 0 && input.frame.frameSeq > this.lastFrameSeq + 1;
|
|
326
|
+
const tickDelta = this.lastVisualTick === null ? null : projected.tick - this.lastVisualTick;
|
|
327
|
+
const lifecycle = triggerLifecycle(projected);
|
|
328
|
+
const phaseChanged = this.lifecyclePhase !== null && this.lifecyclePhase !== lifecycle;
|
|
329
|
+
const continuousFromPrevious = !stateFrameGap && !phaseChanged && tickDelta !== null && tickDelta >= 0 && tickDelta <= 3 && this.lastConnectionId === input.frame.connectionId;
|
|
330
|
+
const frame = Object.freeze({
|
|
331
|
+
...projected,
|
|
332
|
+
tickDelta,
|
|
333
|
+
continuousFromPrevious
|
|
334
|
+
});
|
|
335
|
+
const gap = this.lastVisualTick !== null && !phaseChanged && !continuousFromPrevious;
|
|
336
|
+
if (gap || phaseChanged) {
|
|
337
|
+
await this.requestModuleReset(gap ? "trajectory_gap" : "phase_changed", context);
|
|
338
|
+
}
|
|
339
|
+
this.lastFrameSeq = input.frame.frameSeq;
|
|
340
|
+
this.lastVisualTick = frame.tick;
|
|
341
|
+
this.lastConnectionId = input.frame.connectionId;
|
|
342
|
+
this.lifecyclePhase = lifecycle;
|
|
343
|
+
const observationSnapshot = this.observationMemory.capture(emptyInput);
|
|
344
|
+
const evaluators = [...this.slots.values()].filter((entry) => this.isEnabled(entry.config)).sort((left, right) => left.config.source.id.localeCompare(right.config.source.id));
|
|
345
|
+
const evaluationsPending = evaluators.map(async (evaluator) => {
|
|
346
|
+
const { config } = evaluator;
|
|
347
|
+
const triggerInput = triggerInputFor(frame, emptyInput, config);
|
|
348
|
+
const readInput = behaviorInputForTrigger(frame, emptyInput, triggerInput);
|
|
349
|
+
const isActive = () => generation === this.configGeneration && this.slots.get(config.source.id) === evaluator;
|
|
350
|
+
try {
|
|
351
|
+
const value = await evaluator.module.evaluate(
|
|
352
|
+
triggerInput,
|
|
353
|
+
createBehaviorReadApi(readInput, {
|
|
354
|
+
isActive,
|
|
355
|
+
observationSnapshot,
|
|
356
|
+
memory: this.memory.bind(
|
|
357
|
+
readInput.scope,
|
|
358
|
+
this.memoryNamespace(config.source),
|
|
359
|
+
() => isActive() && !context.signal.aborted && this.started
|
|
360
|
+
)
|
|
361
|
+
})
|
|
362
|
+
);
|
|
363
|
+
if (!isActive()) return { triggerId: config.source.id, outcome: "error" };
|
|
364
|
+
const match = normalizeMatch(value);
|
|
365
|
+
return match ? { triggerId: config.source.id, outcome: "match", match } : { triggerId: config.source.id, outcome: "clear" };
|
|
366
|
+
} catch (error) {
|
|
367
|
+
context.diagnostic("trigger.module.failed", {
|
|
368
|
+
trigger_id: config.source.id,
|
|
369
|
+
operation: "evaluate",
|
|
370
|
+
error_code: diagnosticErrorCode(error)
|
|
371
|
+
}, "error");
|
|
372
|
+
return { triggerId: config.source.id, outcome: "error" };
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
const settled = await Promise.allSettled(evaluationsPending);
|
|
376
|
+
const evaluations = settled.map((result, index) => {
|
|
377
|
+
if (result.status === "fulfilled") return result.value;
|
|
378
|
+
const triggerId = evaluators[index].config.source.id;
|
|
379
|
+
context.diagnostic("trigger.module.failed", {
|
|
380
|
+
trigger_id: triggerId,
|
|
381
|
+
operation: "evaluate",
|
|
382
|
+
error_code: diagnosticErrorCode(result.reason)
|
|
383
|
+
}, "error");
|
|
384
|
+
return { triggerId, outcome: "error" };
|
|
385
|
+
});
|
|
386
|
+
return {
|
|
387
|
+
outcome: "processed",
|
|
388
|
+
reason: evaluations.some((entry) => entry.outcome === "match") ? "trigger_match_computed" : "trigger_no_match",
|
|
389
|
+
proposal: {
|
|
390
|
+
schema: TRIGGER_COMPUTATION_SCHEMA,
|
|
391
|
+
configGeneration: generation,
|
|
392
|
+
epochId: input.epoch.epochSeq,
|
|
393
|
+
nowMs: frame.timeMs,
|
|
394
|
+
...eventCursor === void 0 ? {} : { eventCursor },
|
|
395
|
+
evaluations
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
async updateThreaded(input, context) {
|
|
400
|
+
await this.ensureThreadPool(context);
|
|
401
|
+
const generation = this.configGeneration;
|
|
402
|
+
const eventCursor = input.pendingEvents.at(-1)?.commitSeq;
|
|
403
|
+
const triggerVisibleInput = {
|
|
404
|
+
...input,
|
|
405
|
+
pendingEvents: input.pendingEvents.filter((event) => event.producer === "backend_push" && !event.notificationOf && event.producerPluginId === void 0)
|
|
406
|
+
};
|
|
407
|
+
const emptyInput = createBehaviorInput(triggerVisibleInput, Object.freeze({}));
|
|
408
|
+
const baseProposal = (nowMs, evaluations2) => ({
|
|
409
|
+
schema: TRIGGER_COMPUTATION_SCHEMA,
|
|
410
|
+
configGeneration: generation,
|
|
411
|
+
epochId: input.epoch.epochSeq,
|
|
412
|
+
nowMs,
|
|
413
|
+
...eventCursor === void 0 ? {} : { eventCursor },
|
|
414
|
+
evaluations: evaluations2
|
|
415
|
+
});
|
|
416
|
+
if (!emptyInput || emptyInput.gameState.phase !== "wandering" || emptyInput.gameState.you?.is_alive === false) {
|
|
417
|
+
return {
|
|
418
|
+
outcome: "processed",
|
|
419
|
+
reason: "trigger_ineligible_state",
|
|
420
|
+
proposal: baseProposal(
|
|
421
|
+
input.frame.observedAtMs ?? input.frame.receivedAtMs,
|
|
422
|
+
[]
|
|
423
|
+
)
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
const projected = this.projector.project(input.frame);
|
|
427
|
+
if (!projected) {
|
|
428
|
+
return {
|
|
429
|
+
outcome: "processed",
|
|
430
|
+
reason: "trigger_observation_unavailable",
|
|
431
|
+
proposal: baseProposal(emptyInput.nowMs, [])
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
const previousStored = context.stateHistory.queryStateFrames({
|
|
435
|
+
scope: context.scope,
|
|
436
|
+
toEpochSeq: input.epoch.epochSeq - 1,
|
|
437
|
+
order: "desc",
|
|
438
|
+
limit: 1
|
|
439
|
+
}).frames[0];
|
|
440
|
+
const previous = previousStored ? this.projector.project(previousStored) : null;
|
|
441
|
+
const tickDelta = previous ? projected.tick - previous.tick : null;
|
|
442
|
+
const phaseChanged = !!previous && triggerLifecycle(previous) !== triggerLifecycle(projected);
|
|
443
|
+
const continuousFromPrevious = !!previous && !!previousStored && previousStored.frameSeq + 1 === input.frame.frameSeq && previousStored.connectionId === input.frame.connectionId && !phaseChanged && tickDelta !== null && tickDelta >= 0 && tickDelta <= 3;
|
|
444
|
+
const frame = Object.freeze({
|
|
445
|
+
...projected,
|
|
446
|
+
tickDelta,
|
|
447
|
+
continuousFromPrevious
|
|
448
|
+
});
|
|
449
|
+
const resetReason = phaseChanged ? "phase_changed" : previousStored && !continuousFromPrevious ? "trajectory_gap" : void 0;
|
|
450
|
+
const configs = [...this.registrations.values()].filter((config) => this.isEnabled(config)).sort((left, right) => left.source.id.localeCompare(right.source.id));
|
|
451
|
+
const settled = await Promise.allSettled(configs.map(async (config) => {
|
|
452
|
+
const triggerInput = triggerInputFor(frame, emptyInput, config);
|
|
453
|
+
const readInput = behaviorInputForTrigger(frame, emptyInput, triggerInput);
|
|
454
|
+
try {
|
|
455
|
+
if (!this.threadPool) throw new Error("trigger_thread_pool_unavailable");
|
|
456
|
+
const value = await this.threadPool.evaluate({
|
|
457
|
+
epochId: input.epoch.epochSeq,
|
|
458
|
+
triggerId: config.source.id,
|
|
459
|
+
input: triggerInput,
|
|
460
|
+
readInput,
|
|
461
|
+
...resetReason === void 0 ? {} : { resetReason }
|
|
462
|
+
}, context.signal);
|
|
463
|
+
const match = normalizeMatch(value);
|
|
464
|
+
return match ? { triggerId: config.source.id, outcome: "match", match } : { triggerId: config.source.id, outcome: "clear" };
|
|
465
|
+
} catch (error) {
|
|
466
|
+
context.diagnostic("trigger.module.failed", {
|
|
467
|
+
trigger_id: config.source.id,
|
|
468
|
+
operation: "evaluate",
|
|
469
|
+
error_code: diagnosticErrorCode(error)
|
|
470
|
+
}, context.signal.aborted ? "debug" : "error");
|
|
471
|
+
return { triggerId: config.source.id, outcome: "error" };
|
|
472
|
+
}
|
|
473
|
+
}));
|
|
474
|
+
const evaluations = settled.map((result, index) => {
|
|
475
|
+
if (result.status === "fulfilled") return result.value;
|
|
476
|
+
const triggerId = configs[index].source.id;
|
|
477
|
+
context.diagnostic("trigger.module.failed", {
|
|
478
|
+
trigger_id: triggerId,
|
|
479
|
+
operation: "evaluate",
|
|
480
|
+
error_code: diagnosticErrorCode(result.reason)
|
|
481
|
+
}, context.signal.aborted ? "debug" : "error");
|
|
482
|
+
return { triggerId, outcome: "error" };
|
|
483
|
+
});
|
|
484
|
+
return {
|
|
485
|
+
outcome: "processed",
|
|
486
|
+
reason: evaluations.some((entry) => entry.outcome === "match") ? "trigger_match_computed" : "trigger_no_match",
|
|
487
|
+
proposal: baseProposal(frame.timeMs, evaluations)
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
async commit(input, computation, context) {
|
|
491
|
+
if (isNotificationTurn(input.epoch.state)) return computation;
|
|
492
|
+
const computed = proposal(computation.proposal);
|
|
493
|
+
if (computed.configGeneration !== this.configGeneration) {
|
|
494
|
+
return {
|
|
495
|
+
outcome: "noop",
|
|
496
|
+
reason: "trigger_config_superseded",
|
|
497
|
+
checkpoint: this.checkpoint()
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
for (const evaluation of computed.evaluations) {
|
|
501
|
+
if (evaluation.outcome !== "clear") continue;
|
|
502
|
+
const config = this.registrations.get(evaluation.triggerId);
|
|
503
|
+
if (config?.rearm !== "after_clear") continue;
|
|
504
|
+
const state = this.stateFor(evaluation.triggerId);
|
|
505
|
+
state.armed = true;
|
|
506
|
+
}
|
|
507
|
+
const candidates = computed.evaluations.flatMap((evaluation) => {
|
|
508
|
+
if (evaluation.outcome !== "match" || !evaluation.match) return [];
|
|
509
|
+
const config = this.registrations.get(evaluation.triggerId);
|
|
510
|
+
if (!config || !this.isEnabled(config)) return [];
|
|
511
|
+
const state = this.stateFor(evaluation.triggerId);
|
|
512
|
+
if (config.rearm === "after_clear" && !state.armed) return [];
|
|
513
|
+
if (state.lastAcceptedAtMs !== void 0 && computed.nowMs - state.lastAcceptedAtMs < config.cooldownMs) return [];
|
|
514
|
+
return [{ config, match: evaluation.match }];
|
|
515
|
+
}).sort((left, right) => {
|
|
516
|
+
if (left.config.reflexPriority !== right.config.reflexPriority) {
|
|
517
|
+
return left.config.reflexPriority > right.config.reflexPriority ? -1 : 1;
|
|
518
|
+
}
|
|
519
|
+
return left.config.source.id.localeCompare(right.config.source.id);
|
|
520
|
+
});
|
|
521
|
+
let activationResult;
|
|
522
|
+
const selected = candidates[0];
|
|
523
|
+
if (selected) {
|
|
524
|
+
const request = Object.freeze({
|
|
525
|
+
source: "trigger",
|
|
526
|
+
triggerId: selected.config.source.id,
|
|
527
|
+
scope: Object.freeze({
|
|
528
|
+
sessionId: input.epoch.scope.sessionId,
|
|
529
|
+
segmentId: input.epoch.scope.segmentId
|
|
530
|
+
}),
|
|
531
|
+
epochId: computed.epochId,
|
|
532
|
+
configGeneration: computed.configGeneration,
|
|
533
|
+
behavior: selected.config.behavior,
|
|
534
|
+
behaviorInput: Object.freeze({
|
|
535
|
+
...structuredClone(selected.config.behaviorInput),
|
|
536
|
+
...structuredClone(selected.match.behaviorInput ?? {})
|
|
537
|
+
}),
|
|
538
|
+
reflexPriority: selected.config.reflexPriority,
|
|
539
|
+
maxRuntimeMs: selected.config.maxRuntimeMs,
|
|
540
|
+
reason: selected.match.reason,
|
|
541
|
+
...selected.match.evidence === void 0 ? {} : {
|
|
542
|
+
evidence: structuredClone(selected.match.evidence)
|
|
543
|
+
}
|
|
544
|
+
});
|
|
545
|
+
if (!this.driver) {
|
|
546
|
+
activationResult = { accepted: false, reason: "activation_driver_unavailable" };
|
|
547
|
+
context.diagnostic("trigger.activation.rejected", {
|
|
548
|
+
trigger_id: request.triggerId,
|
|
549
|
+
reason: activationResult.reason
|
|
550
|
+
}, "error");
|
|
551
|
+
} else {
|
|
552
|
+
try {
|
|
553
|
+
activationResult = await this.driver.requestReflex(request, {
|
|
554
|
+
isCurrent: () => computed.configGeneration === this.configGeneration
|
|
555
|
+
});
|
|
556
|
+
} catch (error) {
|
|
557
|
+
activationResult = { accepted: false, reason: "activation_driver_failed" };
|
|
558
|
+
context.diagnostic("trigger.activation.rejected", {
|
|
559
|
+
trigger_id: request.triggerId,
|
|
560
|
+
reason: activationResult.reason,
|
|
561
|
+
error_code: diagnosticErrorCode(error)
|
|
562
|
+
}, "error");
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
if (activationResult.accepted) {
|
|
566
|
+
const state = this.stateFor(request.triggerId);
|
|
567
|
+
state.lastAcceptedAtMs = computed.nowMs;
|
|
568
|
+
if (selected.config.rearm === "after_clear") state.armed = false;
|
|
569
|
+
context.diagnostic("trigger.activation.accepted", {
|
|
570
|
+
trigger_id: request.triggerId,
|
|
571
|
+
behavior_id: request.behavior,
|
|
572
|
+
activation_id: activationResult.activationId,
|
|
573
|
+
reflex_priority: request.reflexPriority,
|
|
574
|
+
...activationResult.replacedActivationId === void 0 ? {} : {
|
|
575
|
+
replaced_activation_id: activationResult.replacedActivationId
|
|
576
|
+
}
|
|
577
|
+
});
|
|
578
|
+
} else {
|
|
579
|
+
context.diagnostic("trigger.activation.rejected", {
|
|
580
|
+
trigger_id: request.triggerId,
|
|
581
|
+
behavior_id: request.behavior,
|
|
582
|
+
reason: activationResult.reason,
|
|
583
|
+
reflex_priority: request.reflexPriority
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
return {
|
|
588
|
+
outcome: activationResult?.accepted ? "processed" : "noop",
|
|
589
|
+
reason: activationResult?.accepted ? "trigger_activation_accepted" : selected ? `trigger_activation_rejected:${activationResult?.reason ?? "unknown"}` : "trigger_no_eligible_match",
|
|
590
|
+
checkpoint: this.checkpoint(),
|
|
591
|
+
// Earlier ordered commits may have consumed a newer watermark while this
|
|
592
|
+
// computation was in flight. Never move the consumption cursor backwards.
|
|
593
|
+
...computed.eventCursor === void 0 || computed.eventCursor <= context.progress().eventCursor ? {} : {
|
|
594
|
+
consumeEventsThroughCommitSeq: computed.eventCursor
|
|
595
|
+
}
|
|
596
|
+
};
|
|
597
|
+
}
|
|
598
|
+
async stop(reason) {
|
|
599
|
+
this.started = false;
|
|
600
|
+
if (this.currentScope) this.memory.close(this.currentScope);
|
|
601
|
+
if (this.threaded) await this.threadPool?.stop();
|
|
602
|
+
else await this.resetModules(reason, void 0);
|
|
603
|
+
this.started = false;
|
|
604
|
+
this.configGeneration += 1;
|
|
605
|
+
this.slots.clear();
|
|
606
|
+
this.loadFailures.clear();
|
|
607
|
+
this.states.clear();
|
|
608
|
+
this.observationMemory.clear();
|
|
609
|
+
this.clearFrameBoundary();
|
|
610
|
+
this.threadPool = void 0;
|
|
611
|
+
this.threadPoolStartTask = void 0;
|
|
612
|
+
this.threadPoolFailed = false;
|
|
613
|
+
this.pendingThreadResetReason = void 0;
|
|
614
|
+
this.loader.stop();
|
|
615
|
+
}
|
|
616
|
+
memoryNamespace(source) {
|
|
617
|
+
return `trigger:${source.id}`;
|
|
618
|
+
}
|
|
619
|
+
async ensureThreadPool(context) {
|
|
620
|
+
if (!this.started || this.threadPool || this.threadPoolFailed) return;
|
|
621
|
+
if (this.threadPoolStartTask) return this.threadPoolStartTask;
|
|
622
|
+
const generation = this.configGeneration;
|
|
623
|
+
let task;
|
|
624
|
+
task = this.startThreadPool(context, generation).finally(() => {
|
|
625
|
+
if (this.threadPoolStartTask === task) this.threadPoolStartTask = void 0;
|
|
626
|
+
});
|
|
627
|
+
this.threadPoolStartTask = task;
|
|
628
|
+
return task;
|
|
629
|
+
}
|
|
630
|
+
async startThreadPool(context, generation) {
|
|
631
|
+
const enabled = [...this.registrations.values()].filter((config) => this.isEnabled(config));
|
|
632
|
+
if (enabled.length === 0) return;
|
|
633
|
+
let pool;
|
|
634
|
+
try {
|
|
635
|
+
pool = new TriggerThreadPool({
|
|
636
|
+
memory: (evaluation, active) => {
|
|
637
|
+
const source = this.registrations.get(evaluation.triggerId)?.source;
|
|
638
|
+
if (!source) throw Error("strategy_memory_inactive");
|
|
639
|
+
return this.memory.bind(
|
|
640
|
+
evaluation.readInput.scope,
|
|
641
|
+
this.memoryNamespace(source),
|
|
642
|
+
() => active() && this.started && generation === this.configGeneration
|
|
643
|
+
);
|
|
644
|
+
},
|
|
645
|
+
modules: enabled.map(({ source }) => this.loader.threadSpec(source)),
|
|
646
|
+
loader: this.loader.threadConfig(),
|
|
647
|
+
diagnosticsEnabled: this.diagnosticsEnabled,
|
|
648
|
+
diagnostic: context.diagnostic
|
|
649
|
+
});
|
|
650
|
+
await pool.start();
|
|
651
|
+
if (!this.started || generation !== this.configGeneration) {
|
|
652
|
+
await pool.stop();
|
|
653
|
+
return;
|
|
654
|
+
}
|
|
655
|
+
this.threadPool = pool;
|
|
656
|
+
} catch (error) {
|
|
657
|
+
if (!this.started || generation !== this.configGeneration) {
|
|
658
|
+
await pool?.stop().catch(() => {
|
|
659
|
+
});
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
662
|
+
this.threadPoolFailed = true;
|
|
663
|
+
await pool?.stop().catch(() => {
|
|
664
|
+
});
|
|
665
|
+
for (const config of enabled) {
|
|
666
|
+
context.diagnostic("trigger.module.failed", {
|
|
667
|
+
trigger_id: config.source.id,
|
|
668
|
+
operation: "worker_start",
|
|
669
|
+
error_code: diagnosticErrorCode(error)
|
|
670
|
+
}, "error");
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
async requestModuleReset(reason, context) {
|
|
675
|
+
if (this.threaded) {
|
|
676
|
+
this.pendingThreadResetReason = reason;
|
|
677
|
+
return;
|
|
678
|
+
}
|
|
679
|
+
await this.resetModules(reason, context);
|
|
680
|
+
}
|
|
681
|
+
async ensureModules(context) {
|
|
682
|
+
if (!this.started) return;
|
|
683
|
+
const enabled = [...this.registrations.values()].filter((config) => this.isEnabled(config));
|
|
684
|
+
await Promise.all(enabled.map(async (config) => {
|
|
685
|
+
const id = config.source.id;
|
|
686
|
+
if (this.slots.has(id) || this.loadFailures.has(id)) return;
|
|
687
|
+
try {
|
|
688
|
+
const ModuleClass = await this.loader.load(config.source);
|
|
689
|
+
if (!this.started || this.registrations.get(id) !== config) return;
|
|
690
|
+
this.slots.set(id, { config, module: new ModuleClass() });
|
|
691
|
+
} catch (error) {
|
|
692
|
+
if (!this.started || this.registrations.get(id) !== config) return;
|
|
693
|
+
this.loadFailures.add(id);
|
|
694
|
+
context.diagnostic("trigger.module.failed", {
|
|
695
|
+
trigger_id: id,
|
|
696
|
+
operation: "load",
|
|
697
|
+
error_code: diagnosticErrorCode(error)
|
|
698
|
+
}, "error");
|
|
699
|
+
}
|
|
700
|
+
}));
|
|
701
|
+
}
|
|
702
|
+
stateFor(triggerId) {
|
|
703
|
+
let state = this.states.get(triggerId);
|
|
704
|
+
if (!state) {
|
|
705
|
+
state = { armed: true };
|
|
706
|
+
this.states.set(triggerId, state);
|
|
707
|
+
}
|
|
708
|
+
return state;
|
|
709
|
+
}
|
|
710
|
+
async resetModules(reason, context) {
|
|
711
|
+
await Promise.all([...this.slots.values()].map(async (slot) => {
|
|
712
|
+
if (!slot.module.reset) return;
|
|
713
|
+
try {
|
|
714
|
+
await slot.module.reset(reason);
|
|
715
|
+
} catch (error) {
|
|
716
|
+
context?.diagnostic("trigger.module.failed", {
|
|
717
|
+
trigger_id: slot.config.source.id,
|
|
718
|
+
operation: "reset",
|
|
719
|
+
error_code: diagnosticErrorCode(error)
|
|
720
|
+
}, "error");
|
|
721
|
+
}
|
|
722
|
+
}));
|
|
723
|
+
}
|
|
724
|
+
clearFrameBoundary() {
|
|
725
|
+
this.projector.reset();
|
|
726
|
+
this.lastFrameSeq = 0;
|
|
727
|
+
this.lastVisualTick = null;
|
|
728
|
+
this.lastConnectionId = null;
|
|
729
|
+
this.lifecyclePhase = null;
|
|
730
|
+
}
|
|
731
|
+
checkpoint() {
|
|
732
|
+
return {
|
|
733
|
+
schema: TRIGGER_CHECKPOINT_SCHEMA,
|
|
734
|
+
states: Object.fromEntries([...this.states].map(([id, state]) => [id, { ...state }]))
|
|
735
|
+
};
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
export {
|
|
739
|
+
ClawclawTriggerPlugin,
|
|
740
|
+
DEFAULT_TRIGGER_PLUGIN_TIMEOUT_MS
|
|
741
|
+
};
|