@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,210 @@
|
|
|
1
|
+
import { chmodSync, existsSync, readFileSync, writeFileSync, mkdirSync } from "fs";
|
|
2
|
+
import { randomUUID } from "crypto";
|
|
3
|
+
import { join, dirname } from "path";
|
|
4
|
+
import { getWorkspaceDir } from "./init-command.js";
|
|
5
|
+
import { tryAcquireWorkspaceRuntimeLock } from "./workspace-runtime-lock.js";
|
|
6
|
+
import {
|
|
7
|
+
ensureUserDataLayout,
|
|
8
|
+
getRuntimeAuthStateFile,
|
|
9
|
+
getUserDataAccountHash,
|
|
10
|
+
getUserDataAuthFile,
|
|
11
|
+
readRuntimeAuthState,
|
|
12
|
+
splitAuthData,
|
|
13
|
+
writeRuntimeAuthState
|
|
14
|
+
} from "./user-data.js";
|
|
15
|
+
const EMPTY_AUTH = { activeProfile: "", profiles: {} };
|
|
16
|
+
const RUNTIME_ACCOUNT_ID = /^acct_[a-f0-9]{32}$/;
|
|
17
|
+
function createRuntimeAccountId() {
|
|
18
|
+
return `acct_${randomUUID().replace(/-/g, "")}`;
|
|
19
|
+
}
|
|
20
|
+
function profileKeyFor(data, profile) {
|
|
21
|
+
if (profile.backendAccountId) {
|
|
22
|
+
for (const [key, savedProfile] of Object.entries(data.profiles ?? {})) {
|
|
23
|
+
if (savedProfile?.backendAccountId === profile.backendAccountId) return key;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
for (const [key, savedProfile] of Object.entries(data.profiles ?? {})) {
|
|
27
|
+
if (savedProfile?.apiKey === profile.apiKey) return key;
|
|
28
|
+
}
|
|
29
|
+
const baseKey = profile.agentName;
|
|
30
|
+
if (!data.profiles[baseKey]) return baseKey;
|
|
31
|
+
const suffix = getUserDataAccountHash(profile.apiKey);
|
|
32
|
+
let candidate = `${baseKey}#${suffix}`;
|
|
33
|
+
let index = 2;
|
|
34
|
+
while (data.profiles[candidate] && data.profiles[candidate]?.apiKey !== profile.apiKey) {
|
|
35
|
+
candidate = `${baseKey}#${suffix}-${index}`;
|
|
36
|
+
index += 1;
|
|
37
|
+
}
|
|
38
|
+
return candidate;
|
|
39
|
+
}
|
|
40
|
+
class AuthStore {
|
|
41
|
+
authFile;
|
|
42
|
+
runtimeAuthStateFile;
|
|
43
|
+
workspaceDir;
|
|
44
|
+
constructor(authFile, runtimeAuthStateFile) {
|
|
45
|
+
if (authFile) {
|
|
46
|
+
this.authFile = authFile;
|
|
47
|
+
this.runtimeAuthStateFile = runtimeAuthStateFile ?? join(dirname(authFile), "auth-state.json");
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const workspaceDir = getWorkspaceDir();
|
|
51
|
+
this.workspaceDir = workspaceDir;
|
|
52
|
+
ensureUserDataLayout(workspaceDir);
|
|
53
|
+
this.authFile = getUserDataAuthFile(workspaceDir);
|
|
54
|
+
this.runtimeAuthStateFile = getRuntimeAuthStateFile(workspaceDir);
|
|
55
|
+
}
|
|
56
|
+
load() {
|
|
57
|
+
if (!existsSync(this.authFile)) return { ...EMPTY_AUTH, profiles: {} };
|
|
58
|
+
try {
|
|
59
|
+
const data = JSON.parse(readFileSync(this.authFile, "utf8"));
|
|
60
|
+
const { auth, runtime, changed } = splitAuthData(data);
|
|
61
|
+
let identityChanged = false;
|
|
62
|
+
for (const profile of Object.values(auth.profiles)) {
|
|
63
|
+
if (!RUNTIME_ACCOUNT_ID.test(profile.runtimeAccountId ?? "")) {
|
|
64
|
+
profile.runtimeAccountId = createRuntimeAccountId();
|
|
65
|
+
identityChanged = true;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
this.mergeRuntimeState(runtime);
|
|
69
|
+
if (changed || identityChanged) this.writeAuth(auth);
|
|
70
|
+
return auth;
|
|
71
|
+
} catch {
|
|
72
|
+
return { ...EMPTY_AUTH, profiles: {} };
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
save(data) {
|
|
76
|
+
const { auth, runtime } = splitAuthData(data);
|
|
77
|
+
this.mergeRuntimeState(runtime);
|
|
78
|
+
this.writeAuth(auth);
|
|
79
|
+
}
|
|
80
|
+
writeAuth(data) {
|
|
81
|
+
let guard = null;
|
|
82
|
+
if (this.workspaceDir) {
|
|
83
|
+
let previous = EMPTY_AUTH;
|
|
84
|
+
try {
|
|
85
|
+
previous = JSON.parse(readFileSync(this.authFile, "utf8"));
|
|
86
|
+
} catch (error) {
|
|
87
|
+
if (error.code !== "ENOENT") throw error;
|
|
88
|
+
}
|
|
89
|
+
if (previous.profiles[previous.activeProfile]?.apiKey !== data.profiles[data.activeProfile]?.apiKey) {
|
|
90
|
+
guard = tryAcquireWorkspaceRuntimeLock(this.workspaceDir);
|
|
91
|
+
if (!guard) throw new Error("A ClawClaw runtime is running in this workspace. Stop it before switching accounts.");
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
try {
|
|
95
|
+
const dir = dirname(this.authFile);
|
|
96
|
+
if (!existsSync(dir)) mkdirSync(dir, { recursive: true, mode: 448 });
|
|
97
|
+
writeFileSync(this.authFile, JSON.stringify(data, null, 2), {
|
|
98
|
+
encoding: "utf8",
|
|
99
|
+
mode: 384
|
|
100
|
+
});
|
|
101
|
+
try {
|
|
102
|
+
chmodSync(this.authFile, 384);
|
|
103
|
+
} catch {
|
|
104
|
+
}
|
|
105
|
+
} finally {
|
|
106
|
+
guard?.release();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
mergeRuntimeState(incoming) {
|
|
110
|
+
const incomingEntries = Object.entries(incoming.profiles ?? {}).filter(([, profile]) => profile.gameServerUrl);
|
|
111
|
+
if (incomingEntries.length === 0) return;
|
|
112
|
+
const current = readRuntimeAuthState(this.runtimeAuthStateFile);
|
|
113
|
+
let changed = false;
|
|
114
|
+
for (const [name, profile] of incomingEntries) {
|
|
115
|
+
if (current.profiles[name]?.gameServerUrl) continue;
|
|
116
|
+
current.profiles[name] = profile;
|
|
117
|
+
changed = true;
|
|
118
|
+
}
|
|
119
|
+
if (changed) writeRuntimeAuthState(this.runtimeAuthStateFile, current);
|
|
120
|
+
}
|
|
121
|
+
addProfile(profile, options = {}) {
|
|
122
|
+
const data = this.load();
|
|
123
|
+
const key = profileKeyFor(data, profile);
|
|
124
|
+
const existing = data.profiles[key];
|
|
125
|
+
if (options.replaceExisting) data.profiles = {};
|
|
126
|
+
data.profiles[key] = {
|
|
127
|
+
...profile,
|
|
128
|
+
runtimeAccountId: RUNTIME_ACCOUNT_ID.test(profile.runtimeAccountId ?? "") ? profile.runtimeAccountId : existing?.runtimeAccountId ?? createRuntimeAccountId(),
|
|
129
|
+
backendAccountId: profile.backendAccountId ?? existing?.backendAccountId
|
|
130
|
+
};
|
|
131
|
+
data.activeProfile = key;
|
|
132
|
+
this.save(data);
|
|
133
|
+
return key;
|
|
134
|
+
}
|
|
135
|
+
/** Forget credentials and routing, without deleting account resources or memory. */
|
|
136
|
+
clear() {
|
|
137
|
+
this.save({ activeProfile: "", profiles: {} });
|
|
138
|
+
writeRuntimeAuthState(this.runtimeAuthStateFile, { profiles: {} });
|
|
139
|
+
}
|
|
140
|
+
removeProfile(name) {
|
|
141
|
+
this.removeProfileByKey(name);
|
|
142
|
+
}
|
|
143
|
+
removeProfileByKey(key) {
|
|
144
|
+
const data = this.load();
|
|
145
|
+
delete data.profiles[key];
|
|
146
|
+
if (data.activeProfile === key) {
|
|
147
|
+
const remaining = Object.keys(data.profiles);
|
|
148
|
+
data.activeProfile = remaining[0] ?? "";
|
|
149
|
+
}
|
|
150
|
+
this.save(data);
|
|
151
|
+
const state = readRuntimeAuthState(this.runtimeAuthStateFile);
|
|
152
|
+
if (state.profiles[key]) {
|
|
153
|
+
delete state.profiles[key];
|
|
154
|
+
writeRuntimeAuthState(this.runtimeAuthStateFile, state);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
switchProfile(name) {
|
|
158
|
+
const data = this.load();
|
|
159
|
+
if (!data.profiles[name]) {
|
|
160
|
+
throw new Error(`Profile "${name}" not found. Available: ${Object.keys(data.profiles).join(", ") || "none"}`);
|
|
161
|
+
}
|
|
162
|
+
data.activeProfile = name;
|
|
163
|
+
this.save(data);
|
|
164
|
+
}
|
|
165
|
+
listProfiles() {
|
|
166
|
+
return Object.keys(this.load().profiles);
|
|
167
|
+
}
|
|
168
|
+
findProfileKeyByApiKey(apiKey) {
|
|
169
|
+
const data = this.load();
|
|
170
|
+
return Object.keys(data.profiles).find((key) => data.profiles[key]?.apiKey === apiKey) ?? null;
|
|
171
|
+
}
|
|
172
|
+
getActiveProfileKey() {
|
|
173
|
+
const data = this.load();
|
|
174
|
+
if (!data.activeProfile || !data.profiles[data.activeProfile]) return null;
|
|
175
|
+
return data.activeProfile;
|
|
176
|
+
}
|
|
177
|
+
getActive() {
|
|
178
|
+
const data = this.load();
|
|
179
|
+
if (!data.activeProfile || !data.profiles[data.activeProfile]) return null;
|
|
180
|
+
const profile = data.profiles[data.activeProfile];
|
|
181
|
+
const gameServerUrl = this.getGameServerUrl(data.activeProfile);
|
|
182
|
+
return gameServerUrl ? { ...profile, gameServerUrl } : { ...profile };
|
|
183
|
+
}
|
|
184
|
+
updateGameServerUrl(url, name) {
|
|
185
|
+
const data = this.load();
|
|
186
|
+
const profileName = name ?? data.activeProfile;
|
|
187
|
+
const profile = data.profiles[profileName];
|
|
188
|
+
if (!profile) return;
|
|
189
|
+
const state = readRuntimeAuthState(this.runtimeAuthStateFile);
|
|
190
|
+
if (url) {
|
|
191
|
+
state.profiles[profileName] = { gameServerUrl: url, updatedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
192
|
+
} else {
|
|
193
|
+
delete state.profiles[profileName]?.gameServerUrl;
|
|
194
|
+
delete state.profiles[profileName]?.updatedAt;
|
|
195
|
+
if (state.profiles[profileName] && Object.keys(state.profiles[profileName]).length === 0) {
|
|
196
|
+
delete state.profiles[profileName];
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
writeRuntimeAuthState(this.runtimeAuthStateFile, state);
|
|
200
|
+
}
|
|
201
|
+
getGameServerUrl(profileName) {
|
|
202
|
+
const data = this.load();
|
|
203
|
+
const name = profileName ?? data.activeProfile;
|
|
204
|
+
if (!name) return void 0;
|
|
205
|
+
return readRuntimeAuthState(this.runtimeAuthStateFile).profiles[name]?.gameServerUrl;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
export {
|
|
209
|
+
AuthStore
|
|
210
|
+
};
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import {
|
|
2
|
+
readCapabilityWorkspaceRegistry,
|
|
3
|
+
writeCapabilityWorkspaceRegistry
|
|
4
|
+
} from "./capability-workspace.js";
|
|
5
|
+
function publisher(item) {
|
|
6
|
+
if (item.owner.isOfficial) return "official";
|
|
7
|
+
return item.isCreatedByMe ? "self" : "community";
|
|
8
|
+
}
|
|
9
|
+
function setCloudStatus(entry, status) {
|
|
10
|
+
if (!entry.hub || entry.hub.cloudStatus === status) return false;
|
|
11
|
+
if (status) entry.hub.cloudStatus = status;
|
|
12
|
+
else delete entry.hub.cloudStatus;
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
function reconcileCapabilityWorkspacePresence(workspaceDir, profile, inventory, snapshot) {
|
|
16
|
+
const registry = readCapabilityWorkspaceRegistry(workspaceDir, profile);
|
|
17
|
+
const selected = snapshot ? new Set(Object.values(snapshot.items).flat().map((item) => item.resourceId)) : void 0;
|
|
18
|
+
const inventoryByResource = new Map(inventory.map((item) => [item.resourceId, {
|
|
19
|
+
...item,
|
|
20
|
+
equipped: selected ? selected.has(item.resourceId) : item.equipped
|
|
21
|
+
}]));
|
|
22
|
+
const deactivated = [];
|
|
23
|
+
const restored = [];
|
|
24
|
+
const inactiveResourceIds = new Set(
|
|
25
|
+
[...inventoryByResource.values()].filter((item) => !item.equipped).map((item) => item.resourceId)
|
|
26
|
+
);
|
|
27
|
+
let changed = false;
|
|
28
|
+
for (const entry of Object.values(registry.entries)) {
|
|
29
|
+
if (!entry.hub || entry.runtimeId === "clawclaw") continue;
|
|
30
|
+
let entryChanged = false;
|
|
31
|
+
const item = inventoryByResource.get(entry.hub.resourceId);
|
|
32
|
+
const wasEquipped = entry.selection === "equipped";
|
|
33
|
+
const nextStatus = item ? void 0 : "workspace_missing";
|
|
34
|
+
if (nextStatus) inactiveResourceIds.add(entry.hub.resourceId);
|
|
35
|
+
if (setCloudStatus(entry, nextStatus)) {
|
|
36
|
+
entryChanged = true;
|
|
37
|
+
if (nextStatus && wasEquipped) {
|
|
38
|
+
deactivated.push({
|
|
39
|
+
type: entry.type,
|
|
40
|
+
id: entry.runtimeId,
|
|
41
|
+
resource_id: entry.hub.resourceId,
|
|
42
|
+
reason: nextStatus
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (item) {
|
|
47
|
+
const nextPublisher = publisher(item);
|
|
48
|
+
if (entry.hub.workspaceItemId !== item.workspaceItemId || entry.hub.publisher !== nextPublisher) {
|
|
49
|
+
entry.hub.workspaceItemId = item.workspaceItemId;
|
|
50
|
+
entry.hub.publisher = nextPublisher;
|
|
51
|
+
entryChanged = true;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (nextStatus) {
|
|
55
|
+
if (entry.selection !== "unequipped") {
|
|
56
|
+
entry.selection = "unequipped";
|
|
57
|
+
entryChanged = true;
|
|
58
|
+
}
|
|
59
|
+
if (entry.conflictChoice) {
|
|
60
|
+
delete entry.conflictChoice;
|
|
61
|
+
entryChanged = true;
|
|
62
|
+
}
|
|
63
|
+
} else if (item) {
|
|
64
|
+
const nextSelection = item.equipped ? "equipped" : entry.selection === "pending" ? "pending" : "unequipped";
|
|
65
|
+
if (entry.selection !== nextSelection) {
|
|
66
|
+
entry.selection = nextSelection;
|
|
67
|
+
entryChanged = true;
|
|
68
|
+
if (wasEquipped && !item.equipped) {
|
|
69
|
+
deactivated.push({
|
|
70
|
+
type: entry.type,
|
|
71
|
+
id: entry.runtimeId,
|
|
72
|
+
resource_id: entry.hub.resourceId,
|
|
73
|
+
reason: "unequipped"
|
|
74
|
+
});
|
|
75
|
+
} else if (!wasEquipped && item.equipped) {
|
|
76
|
+
restored.push({
|
|
77
|
+
type: entry.type,
|
|
78
|
+
id: entry.runtimeId,
|
|
79
|
+
resource_id: entry.hub.resourceId
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (entryChanged) {
|
|
85
|
+
entry.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
86
|
+
changed = true;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (changed) writeCapabilityWorkspaceRegistry(workspaceDir, profile, registry);
|
|
90
|
+
return {
|
|
91
|
+
deactivated,
|
|
92
|
+
restored,
|
|
93
|
+
inactiveResourceIds: [...inactiveResourceIds]
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function filterInactiveAgentWorkspaceSnapshot(workspaceDir, profile, snapshot, additionalResourceIds = []) {
|
|
97
|
+
if (!snapshot) return void 0;
|
|
98
|
+
const inactive = new Set(additionalResourceIds);
|
|
99
|
+
for (const entry of Object.values(readCapabilityWorkspaceRegistry(workspaceDir, profile).entries)) {
|
|
100
|
+
if (entry.hub && (entry.hub.cloudStatus || entry.selection !== "equipped")) inactive.add(entry.hub.resourceId);
|
|
101
|
+
}
|
|
102
|
+
if (inactive.size === 0) return snapshot;
|
|
103
|
+
const filtered = structuredClone(snapshot);
|
|
104
|
+
for (const type of Object.keys(filtered.items)) {
|
|
105
|
+
filtered.items[type] = filtered.items[type].filter((item) => !inactive.has(item.resourceId));
|
|
106
|
+
}
|
|
107
|
+
return filtered;
|
|
108
|
+
}
|
|
109
|
+
function reconcileCapabilityLoadout(workspaceDir, profile, snapshot) {
|
|
110
|
+
const registry = readCapabilityWorkspaceRegistry(workspaceDir, profile);
|
|
111
|
+
const selected = new Set(Object.values(snapshot.items).flat().map((item) => item.resourceId));
|
|
112
|
+
const result = { deactivated: [], restored: [], inactiveResourceIds: [] };
|
|
113
|
+
let changed = false;
|
|
114
|
+
for (const entry of Object.values(registry.entries)) {
|
|
115
|
+
if (!entry.hub || entry.runtimeId === "clawclaw") continue;
|
|
116
|
+
const equipped = selected.has(entry.hub.resourceId);
|
|
117
|
+
if (!equipped) result.inactiveResourceIds.push(entry.hub.resourceId);
|
|
118
|
+
const selection = equipped ? "equipped" : entry.selection === "pending" ? "pending" : "unequipped";
|
|
119
|
+
if (selection !== entry.selection) {
|
|
120
|
+
const change = { type: entry.type, id: entry.runtimeId, resource_id: entry.hub.resourceId };
|
|
121
|
+
if (equipped) result.restored.push(change);
|
|
122
|
+
else if (entry.selection === "equipped") result.deactivated.push({ ...change, reason: "unequipped" });
|
|
123
|
+
entry.selection = selection;
|
|
124
|
+
changed = true;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (changed) writeCapabilityWorkspaceRegistry(workspaceDir, profile, registry);
|
|
128
|
+
return result;
|
|
129
|
+
}
|
|
130
|
+
export {
|
|
131
|
+
filterInactiveAgentWorkspaceSnapshot,
|
|
132
|
+
reconcileCapabilityLoadout,
|
|
133
|
+
reconcileCapabilityWorkspacePresence
|
|
134
|
+
};
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import {
|
|
2
|
+
existsSync,
|
|
3
|
+
lstatSync,
|
|
4
|
+
mkdirSync,
|
|
5
|
+
mkdtempSync,
|
|
6
|
+
readFileSync,
|
|
7
|
+
readdirSync,
|
|
8
|
+
renameSync,
|
|
9
|
+
rmSync,
|
|
10
|
+
writeFileSync
|
|
11
|
+
} from "node:fs";
|
|
12
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
13
|
+
import { tmpdir } from "node:os";
|
|
14
|
+
import { dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
15
|
+
import {
|
|
16
|
+
capabilityWorkspacePath,
|
|
17
|
+
readCapabilityWorkspaceRegistry,
|
|
18
|
+
updateCapabilityHubIdentity,
|
|
19
|
+
updateCapabilityDisplayMetadata
|
|
20
|
+
} from "./capability-workspace.js";
|
|
21
|
+
import { HubClient } from "./hub-client.js";
|
|
22
|
+
import { findSkillRoot, overwriteAgentSkillTarget } from "./skill-host.js";
|
|
23
|
+
import { unzip } from "./hub-unzip.js";
|
|
24
|
+
import { zipContentDigest } from "./zip-store.js";
|
|
25
|
+
import { selectedSkillNameConflicts, skillNameCandidate, skillNameKey } from "./skill-name-conflicts.js";
|
|
26
|
+
async function syncInstalledCapabilityUpdates(profile, dependencies = {}) {
|
|
27
|
+
const client = dependencies.client ?? HubClient.fromProfile(profile);
|
|
28
|
+
const result = {
|
|
29
|
+
updated: [],
|
|
30
|
+
failed: [],
|
|
31
|
+
inventory: [],
|
|
32
|
+
inventoryComplete: false
|
|
33
|
+
};
|
|
34
|
+
let cursor;
|
|
35
|
+
do {
|
|
36
|
+
const page = await client.listWorkspace({ cursor, limit: 100 });
|
|
37
|
+
result.inventory.push(...page.items);
|
|
38
|
+
cursor = page.hasMore && page.nextCursor ? page.nextCursor : void 0;
|
|
39
|
+
} while (cursor);
|
|
40
|
+
for (const item of result.inventory.filter((candidate) => candidate.hasUpdate)) {
|
|
41
|
+
try {
|
|
42
|
+
const synced = await client.syncWorkspaceItem(item.workspaceItemId);
|
|
43
|
+
item.versionId = synced.versionId;
|
|
44
|
+
item.hasUpdate = false;
|
|
45
|
+
result.updated.push({
|
|
46
|
+
type: item.resourceType,
|
|
47
|
+
resource_id: item.resourceId,
|
|
48
|
+
workspace_item_id: item.workspaceItemId,
|
|
49
|
+
version_id: synced.versionId
|
|
50
|
+
});
|
|
51
|
+
} catch (error) {
|
|
52
|
+
result.failed.push({
|
|
53
|
+
type: item.resourceType,
|
|
54
|
+
resource_id: item.resourceId,
|
|
55
|
+
workspace_item_id: item.workspaceItemId,
|
|
56
|
+
error: error instanceof Error ? error.message : String(error)
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
result.inventoryComplete = true;
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
63
|
+
function resourceType(type) {
|
|
64
|
+
return type === "behavior" ? "strategy" : type;
|
|
65
|
+
}
|
|
66
|
+
function sha256(bytes) {
|
|
67
|
+
return createHash("sha256").update(bytes).digest("hex");
|
|
68
|
+
}
|
|
69
|
+
function collectSkill(root) {
|
|
70
|
+
const files = [];
|
|
71
|
+
const visit = (directory) => {
|
|
72
|
+
for (const entry of readdirSync(directory, { withFileTypes: true })) {
|
|
73
|
+
const path = join(directory, entry.name);
|
|
74
|
+
const stat = lstatSync(path);
|
|
75
|
+
if (stat.isSymbolicLink()) throw new Error("skill_source_symlink_unsupported");
|
|
76
|
+
if (stat.isDirectory()) visit(path);
|
|
77
|
+
else if (stat.isFile()) files.push({
|
|
78
|
+
path: relative(root, path).replaceAll("\\", "/"),
|
|
79
|
+
content: readFileSync(path)
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
visit(root);
|
|
84
|
+
if (files.length === 0) throw new Error("skill_source_empty");
|
|
85
|
+
return files;
|
|
86
|
+
}
|
|
87
|
+
function localDigest(entry, path) {
|
|
88
|
+
return entry.type === "skill" ? zipContentDigest(collectSkill(path)) : sha256(readFileSync(path));
|
|
89
|
+
}
|
|
90
|
+
function pathInside(root, candidate) {
|
|
91
|
+
const child = relative(resolve(root), resolve(candidate));
|
|
92
|
+
return child === "" || !child.startsWith("..") && !isAbsolute(child);
|
|
93
|
+
}
|
|
94
|
+
function prepareCloudArtifact(entry, bytes) {
|
|
95
|
+
if (entry.type !== "skill") {
|
|
96
|
+
return {
|
|
97
|
+
digest: sha256(bytes),
|
|
98
|
+
apply(target) {
|
|
99
|
+
const stage2 = `${target}.ccl-cloud-${randomUUID()}.tmp`;
|
|
100
|
+
const displaced = `${target}.ccl-old-${randomUUID()}.tmp`;
|
|
101
|
+
let moved = false;
|
|
102
|
+
writeFileSync(stage2, bytes);
|
|
103
|
+
try {
|
|
104
|
+
renameSync(target, displaced);
|
|
105
|
+
moved = true;
|
|
106
|
+
renameSync(stage2, target);
|
|
107
|
+
if (sha256(readFileSync(target)) !== sha256(bytes)) {
|
|
108
|
+
throw new Error("capability_cloud_write_verification_failed");
|
|
109
|
+
}
|
|
110
|
+
rmSync(displaced, { force: true });
|
|
111
|
+
} catch (error) {
|
|
112
|
+
rmSync(stage2, { force: true });
|
|
113
|
+
if (moved && existsSync(displaced)) {
|
|
114
|
+
rmSync(target, { force: true });
|
|
115
|
+
try {
|
|
116
|
+
renameSync(displaced, target);
|
|
117
|
+
} catch {
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
throw error;
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
cleanup() {
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
const stage = mkdtempSync(join(tmpdir(), "ccl-capability-refresh-"));
|
|
128
|
+
try {
|
|
129
|
+
for (const file of unzip(bytes)) {
|
|
130
|
+
const target = resolve(stage, ...file.path.split("/"));
|
|
131
|
+
if (!pathInside(stage, target) || target === resolve(stage)) {
|
|
132
|
+
throw new Error("capability_cloud_skill_path_invalid");
|
|
133
|
+
}
|
|
134
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
135
|
+
writeFileSync(target, file.content);
|
|
136
|
+
}
|
|
137
|
+
const root = findSkillRoot(stage);
|
|
138
|
+
if (!existsSync(join(root, "SKILL.md"))) throw new Error("capability_cloud_skill_invalid");
|
|
139
|
+
return {
|
|
140
|
+
digest: zipContentDigest(collectSkill(root)),
|
|
141
|
+
apply(target) {
|
|
142
|
+
const replaced = overwriteAgentSkillTarget(root, target);
|
|
143
|
+
if (!replaced.ok) throw new Error(replaced.error ?? "capability_cloud_restore_failed");
|
|
144
|
+
},
|
|
145
|
+
cleanup() {
|
|
146
|
+
rmSync(stage, { recursive: true, force: true });
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
} catch (error) {
|
|
150
|
+
rmSync(stage, { recursive: true, force: true });
|
|
151
|
+
throw error;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
function activeResourceIds(snapshot) {
|
|
155
|
+
if (!snapshot) return /* @__PURE__ */ new Set();
|
|
156
|
+
return new Set(Object.values(snapshot.items).flat().map((item) => item.resourceId));
|
|
157
|
+
}
|
|
158
|
+
async function refreshCapabilitiesFromCloud(workspaceDir, profile, activeWorkspace, dependencies = {}) {
|
|
159
|
+
const client = dependencies.client ?? HubClient.fromProfile(profile);
|
|
160
|
+
const result = { downloaded: [], conflicts: [], failed: [], unchanged: [] };
|
|
161
|
+
const active = activeResourceIds(activeWorkspace);
|
|
162
|
+
const blockedSkillNames = new Set(selectedSkillNameConflicts(workspaceDir, profile, activeWorkspace).map((item) => item.name));
|
|
163
|
+
const unresolvedParents = new Set(Object.values(activeWorkspace?.items ?? {}).flat().flatMap((item) => item.forkReconciliation?.status === "unresolved" ? [item.forkReconciliation.parentResourceId] : []));
|
|
164
|
+
const entries = Object.values(readCapabilityWorkspaceRegistry(workspaceDir, profile).entries).filter((entry) => entry.runtimeId !== "clawclaw" && entry.hub && !entry.hub.cloudStatus && !entry.hub.forkRelationshipUnresolved && !active.has(entry.hub.resourceId) && !unresolvedParents.has(entry.hub.resourceId));
|
|
165
|
+
for (const entry of entries) {
|
|
166
|
+
if (entry.type === "skill" && blockedSkillNames.has(skillNameKey(skillNameCandidate(workspaceDir, profile, entry).name))) continue;
|
|
167
|
+
const hub = entry.hub;
|
|
168
|
+
const type = resourceType(entry.type);
|
|
169
|
+
const path = capabilityWorkspacePath(workspaceDir, profile, entry);
|
|
170
|
+
try {
|
|
171
|
+
const before = localDigest(entry, path);
|
|
172
|
+
let workspaceItemId = hub.publisher === "self" ? void 0 : hub.workspaceItemId;
|
|
173
|
+
if (hub.publisher !== "self") {
|
|
174
|
+
const workspaceItem = await client.findWorkspaceItem(type, hub.resourceId);
|
|
175
|
+
if (!workspaceItem) throw new Error("capability_cloud_workspace_item_missing");
|
|
176
|
+
workspaceItemId = workspaceItem.workspaceItemId;
|
|
177
|
+
if (workspaceItem.hasUpdate) await client.syncWorkspaceItem(workspaceItem.workspaceItemId);
|
|
178
|
+
}
|
|
179
|
+
const detail = await client.getResource(type, hub.resourceId, workspaceItemId);
|
|
180
|
+
if (detail.versionId === hub.versionId) {
|
|
181
|
+
updateCapabilityDisplayMetadata(workspaceDir, profile, entry.key, detail);
|
|
182
|
+
if (hub.observedCloudVersionId || hub.pendingForkConflict && before === hub.baseSha256 || hub.localOriginUnrecognized && (before === hub.baseSha256 || before === hub.lastUploadedSha256)) updateCapabilityHubIdentity(workspaceDir, profile, entry.key, {
|
|
183
|
+
...hub,
|
|
184
|
+
observedCloudVersionId: void 0,
|
|
185
|
+
pendingForkConflict: before === hub.baseSha256 ? void 0 : hub.pendingForkConflict,
|
|
186
|
+
localOriginUnrecognized: before === hub.baseSha256 || before === hub.lastUploadedSha256 ? void 0 : hub.localOriginUnrecognized
|
|
187
|
+
});
|
|
188
|
+
result.unchanged.push({ type: entry.type, id: entry.runtimeId });
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
const artifact = prepareCloudArtifact(
|
|
192
|
+
entry,
|
|
193
|
+
await client.downloadArtifact(type, hub.resourceId, workspaceItemId)
|
|
194
|
+
);
|
|
195
|
+
try {
|
|
196
|
+
const afterDownload = localDigest(entry, path);
|
|
197
|
+
if (afterDownload !== before) {
|
|
198
|
+
updateCapabilityHubIdentity(workspaceDir, profile, entry.key, {
|
|
199
|
+
...hub,
|
|
200
|
+
...workspaceItemId ? { workspaceItemId } : {},
|
|
201
|
+
observedCloudVersionId: detail.versionId
|
|
202
|
+
});
|
|
203
|
+
if (entry.conflictChoice !== "local") result.conflicts.push({
|
|
204
|
+
type: entry.type,
|
|
205
|
+
id: entry.runtimeId,
|
|
206
|
+
resource_id: hub.resourceId,
|
|
207
|
+
reason: "local_and_cloud_changed"
|
|
208
|
+
});
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
const localUnmodified = before === hub.baseSha256 || before === hub.lastUploadedSha256;
|
|
212
|
+
if (before !== artifact.digest && !localUnmodified) {
|
|
213
|
+
updateCapabilityHubIdentity(workspaceDir, profile, entry.key, {
|
|
214
|
+
...hub,
|
|
215
|
+
...workspaceItemId ? { workspaceItemId } : {},
|
|
216
|
+
observedCloudVersionId: detail.versionId
|
|
217
|
+
});
|
|
218
|
+
if (entry.conflictChoice !== "local") result.conflicts.push({
|
|
219
|
+
type: entry.type,
|
|
220
|
+
id: entry.runtimeId,
|
|
221
|
+
resource_id: hub.resourceId,
|
|
222
|
+
reason: "local_and_cloud_changed"
|
|
223
|
+
});
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
const convergence = before === artifact.digest;
|
|
227
|
+
if (!convergence) artifact.apply(path);
|
|
228
|
+
updateCapabilityDisplayMetadata(workspaceDir, profile, entry.key, detail);
|
|
229
|
+
updateCapabilityHubIdentity(workspaceDir, profile, entry.key, {
|
|
230
|
+
...hub,
|
|
231
|
+
versionId: detail.versionId,
|
|
232
|
+
...workspaceItemId ? { workspaceItemId } : {},
|
|
233
|
+
baseSha256: artifact.digest,
|
|
234
|
+
lastUploadedSha256: artifact.digest,
|
|
235
|
+
observedCloudVersionId: void 0,
|
|
236
|
+
localOriginUnrecognized: void 0,
|
|
237
|
+
pendingForkConflict: void 0
|
|
238
|
+
});
|
|
239
|
+
result.downloaded.push({
|
|
240
|
+
type: entry.type,
|
|
241
|
+
id: entry.runtimeId,
|
|
242
|
+
resource_id: hub.resourceId,
|
|
243
|
+
version_id: detail.versionId,
|
|
244
|
+
result: convergence ? "converged" : "updated"
|
|
245
|
+
});
|
|
246
|
+
} finally {
|
|
247
|
+
artifact.cleanup();
|
|
248
|
+
}
|
|
249
|
+
} catch (error) {
|
|
250
|
+
result.failed.push({
|
|
251
|
+
type: entry.type,
|
|
252
|
+
id: entry.runtimeId,
|
|
253
|
+
action: "download",
|
|
254
|
+
error: error instanceof Error ? error.message : String(error)
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return result;
|
|
259
|
+
}
|
|
260
|
+
export {
|
|
261
|
+
refreshCapabilitiesFromCloud,
|
|
262
|
+
syncInstalledCapabilityUpdates
|
|
263
|
+
};
|