@north-light/crouter 0.3.349 → 0.3.350
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/crtr-launcher +4 -0
- package/bin/runtime-generation-manifest.mjs +12 -2
- package/dist/api/client.d.ts +50 -7
- package/dist/api/client.js +2 -2
- package/dist/api/dto/analytics.d.ts +184 -0
- package/dist/api/dto/analytics.js +0 -0
- package/dist/api/dto/broker-ops.d.ts +43 -1
- package/dist/api/dto/config.d.ts +11 -0
- package/dist/api/dto/grants.d.ts +14 -0
- package/dist/api/dto/grants.js +0 -0
- package/dist/api/dto/human-requests.d.ts +14 -0
- package/dist/api/dto/memory.d.ts +6 -0
- package/dist/api/dto/modelauth.d.ts +35 -0
- package/dist/api/dto/node-records.d.ts +35 -0
- package/dist/api/dto/node-records.js +0 -0
- package/dist/api/dto/nodes.d.ts +5 -0
- package/dist/api/dto/profiles.d.ts +38 -3
- package/dist/api/dto/worktree.d.ts +11 -0
- package/dist/api/errors.d.ts +23 -1
- package/dist/api/errors.js +1 -1
- package/dist/api/index.d.ts +2 -0
- package/dist/api/index.js +1 -1
- package/dist/api/node-transport.js +1 -1
- package/dist/api/routes.d.ts +22 -0
- package/dist/api/routes.js +1 -1
- package/dist/build-root.d.ts +6 -1
- package/dist/build-root.js +1 -1
- package/dist/builtin-memory/crouter-sdk/client.md +34 -0
- package/dist/builtin-memory/crouter-sdk/errors.md +2 -0
- package/dist/builtin-memory/crouter-sdk/memory.md +2 -2
- package/dist/builtin-memory/crouter-sdk/streaming.md +21 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/extensions/claude-plugin-commands.ts +8 -4
- package/dist/builtin-pi-packages/pi-crtr-extensions/extensions/memory-slash-commands.ts +39 -118
- package/dist/builtin-pi-packages/pi-crtr-extensions/extensions/provider-rotation.d.ts +6 -1
- package/dist/builtin-pi-packages/pi-crtr-extensions/extensions/provider-rotation.js +41 -27
- package/dist/builtin-pi-packages/pi-crtr-extensions/extensions/provider-rotation.ts +52 -29
- package/dist/cli.js +9 -8
- package/dist/clients/attach/chrome/inbox-strip.js +1 -1
- package/dist/clients/attach/chrome/roster.js +1 -1
- package/dist/clients/attach/config.js +1 -1
- package/dist/clients/attach/overlays/auth.js +2 -2
- package/dist/clients/attach/overlays/graph.js +1 -1
- package/dist/clients/attach/render/tool-calls.js +3 -3
- package/dist/clients/attach/session/connection.js +1 -1
- package/dist/clients/attach/session/profile-files.js +1 -1
- package/dist/clients/attach/viewer.js +1569 -816
- package/dist/commands/api-client.js +3 -3
- package/dist/commands/broker-permissions.d.ts +2 -0
- package/dist/commands/broker-permissions.js +1 -0
- package/dist/commands/canvas-analytics/chart.d.ts +52 -0
- package/dist/commands/canvas-analytics/chart.js +1 -0
- package/dist/commands/canvas-analytics/drilldown.d.ts +34 -0
- package/dist/commands/canvas-analytics/drilldown.js +1 -0
- package/dist/commands/canvas-analytics/format.d.ts +29 -0
- package/dist/commands/canvas-analytics/format.js +1 -0
- package/dist/commands/canvas-analytics/graph-detail.d.ts +2 -0
- package/dist/commands/canvas-analytics/graph-detail.js +2 -0
- package/dist/commands/canvas-analytics/graphs.d.ts +9 -0
- package/dist/commands/canvas-analytics/graphs.js +1 -0
- package/dist/commands/canvas-analytics/memory.d.ts +2 -0
- package/dist/commands/canvas-analytics/memory.js +1 -0
- package/dist/commands/canvas-analytics/overview.d.ts +2 -0
- package/dist/commands/canvas-analytics/overview.js +1 -0
- package/dist/commands/canvas-analytics/shell.d.ts +60 -0
- package/dist/commands/canvas-analytics/shell.js +2 -0
- package/dist/commands/canvas-analytics/time.d.ts +2 -0
- package/dist/commands/canvas-analytics/time.js +1 -0
- package/dist/commands/canvas-analytics/usage.d.ts +2 -0
- package/dist/commands/canvas-analytics/usage.js +1 -0
- package/dist/commands/canvas-analytics/view.d.ts +85 -0
- package/dist/commands/canvas-analytics/view.js +1 -0
- package/dist/commands/canvas-analytics.d.ts +2 -0
- package/dist/commands/canvas-analytics.js +1 -0
- package/dist/commands/canvas-prune.js +1 -1
- package/dist/commands/canvas.js +1 -1
- package/dist/commands/cron.js +5 -5
- package/dist/commands/human/components.d.ts +2 -0
- package/dist/commands/human/components.js +2 -2
- package/dist/commands/human/prompts.js +1 -1
- package/dist/commands/human/queue.js +1 -1
- package/dist/commands/memory/client.d.ts +11 -0
- package/dist/commands/memory/client.js +1 -0
- package/dist/commands/memory/delete.js +1 -1
- package/dist/commands/memory/edit.js +3 -3
- package/dist/commands/memory/find.js +1 -1
- package/dist/commands/memory/history.js +4 -4
- package/dist/commands/memory/lint.js +1 -1
- package/dist/commands/memory/list.d.ts +0 -2
- package/dist/commands/memory/list.js +1 -1
- package/dist/commands/memory/move.js +1 -1
- package/dist/commands/memory/origin.js +1 -1
- package/dist/commands/memory/read.d.ts +0 -5
- package/dist/commands/memory/read.js +3 -3
- package/dist/commands/memory/shared.d.ts +0 -178
- package/dist/commands/memory/shared.js +1 -12
- package/dist/commands/memory/write.js +5 -5
- package/dist/commands/node/bash.js +5 -5
- package/dist/commands/node/create.d.ts +0 -17
- package/dist/commands/node/create.js +2 -3
- package/dist/commands/node/inspect.js +6 -6
- package/dist/commands/node/lifecycle.js +2 -2
- package/dist/commands/node-context.js +2 -2
- package/dist/commands/node-inspect-artifacts.js +6 -6
- package/dist/commands/pkg/browse/catalog.js +1 -1
- package/dist/commands/pkg/browse/model.d.ts +1 -1
- package/dist/commands/pkg/market-manage.js +1 -1
- package/dist/commands/pkg/plugin-manage.js +10 -10
- package/dist/commands/profile/daemon-profiles.d.ts +13 -0
- package/dist/commands/profile/daemon-profiles.js +4 -0
- package/dist/commands/profile/delete.js +1 -1
- package/dist/commands/profile/env.d.ts +6 -0
- package/dist/commands/profile/env.js +2 -2
- package/dist/commands/profile/kind.js +1 -2
- package/dist/commands/profile/list.js +1 -1
- package/dist/commands/profile/meta.js +1 -1
- package/dist/commands/profile/new.js +1 -1
- package/dist/commands/profile/pause.js +1 -1
- package/dist/commands/profile/project.js +1 -1
- package/dist/commands/profile/rename.js +1 -1
- package/dist/commands/profile/show.js +1 -1
- package/dist/commands/profile.js +1 -1
- package/dist/commands/push.js +3 -3
- package/dist/commands/surface-inspect.js +1 -1
- package/dist/commands/sys/branch.js +1 -1
- package/dist/commands/sys/config.js +1 -1
- package/dist/commands/sys/connect.js +3 -3
- package/dist/commands/sys/context/admin/actions.js +1 -1
- package/dist/commands/sys/context/admin/model.d.ts +1 -0
- package/dist/commands/sys/context/admin/model.js +1 -1
- package/dist/commands/sys/context/admin.js +1 -1
- package/dist/commands/sys/context/expose.js +2 -1
- package/dist/commands/sys/context/prompt-review.js +2 -2
- package/dist/commands/sys/context/resolve.js +7 -7
- package/dist/commands/sys/context/sysprompt.js +1 -1
- package/dist/commands/sys/join.d.ts +1 -0
- package/dist/commands/sys/join.js +1 -0
- package/dist/commands/sys/migrate.js +1 -1
- package/dist/commands/sys/panels/models-panel.js +1 -1
- package/dist/commands/sys/panels/profiles-panel.d.ts +0 -1
- package/dist/commands/sys/panels/profiles-panel.js +1 -1
- package/dist/commands/sys/provider-login.js +6 -6
- package/dist/commands/sys/setup-core.d.ts +1 -1
- package/dist/commands/sys/setup-core.js +6 -6
- package/dist/commands/sys/setup-settings-runner.js +1 -1
- package/dist/commands/sys/setup.js +1 -1
- package/dist/commands/sys/spaces.d.ts +1 -0
- package/dist/commands/sys/spaces.js +2 -0
- package/dist/commands/sys/sync-deps.js +2 -2
- package/dist/commands/sys/sync-project-guidance.js +4 -4
- package/dist/commands/sys/sync-skills.js +2 -2
- package/dist/commands/sys/worktrees.d.ts +1 -0
- package/dist/commands/sys/worktrees.js +1 -1
- package/dist/commands/sys.js +1 -1
- package/dist/core/auth-file.js +2 -2
- package/dist/core/bash-job-supervisor.d.ts +6 -0
- package/dist/core/bash-job-supervisor.js +4 -0
- package/dist/core/bash-jobs.d.ts +13 -6
- package/dist/core/bash-jobs.js +8 -7
- package/dist/core/broker-client/transport-relay.d.ts +6 -3
- package/dist/core/broker-client/transport-relay.js +1 -1
- package/dist/core/broker-client/transport-socket.d.ts +6 -1
- package/dist/core/broker-client/transport-socket.js +1 -1
- package/dist/core/canvas/canvas.d.ts +39 -18
- package/dist/core/canvas/canvas.js +21 -20
- package/dist/core/canvas/context-strip.d.ts +20 -0
- package/dist/core/canvas/context-strip.js +5 -0
- package/dist/core/canvas/crons.d.ts +12 -20
- package/dist/core/canvas/crons.js +15 -13
- package/dist/core/canvas/db.js +2 -2
- package/dist/core/canvas/deliveries.d.ts +4 -1
- package/dist/core/canvas/deliveries.js +1 -1
- package/dist/core/canvas/executions.js +1 -1
- package/dist/core/canvas/history.d.ts +2 -1
- package/dist/core/canvas/history.js +17 -18
- package/dist/core/canvas/memory-reads.d.ts +19 -0
- package/dist/core/canvas/memory-reads.js +1 -0
- package/dist/core/canvas/migrations.d.ts +0 -4
- package/dist/core/canvas/migrations.js +99 -32
- package/dist/core/canvas/nav-render.js +1 -1
- package/dist/core/canvas/node-agent-paths.d.ts +8 -0
- package/dist/core/canvas/node-agent-paths.js +1 -0
- package/dist/core/canvas/node-recap.d.ts +2 -2
- package/dist/core/canvas/node-recap.js +2 -2
- package/dist/core/canvas/node-tokens.d.ts +24 -0
- package/dist/core/canvas/node-tokens.js +5 -0
- package/dist/core/canvas/paths.d.ts +16 -19
- package/dist/core/canvas/paths.js +1 -1
- package/dist/core/canvas/render-source.d.ts +2 -2
- package/dist/core/canvas/render-source.js +6 -9
- package/dist/core/canvas/sessions.d.ts +18 -0
- package/dist/core/canvas/sessions.js +4 -1
- package/dist/core/canvas/types.d.ts +22 -6
- package/dist/core/command-hooks/compose.js +1 -1
- package/dist/core/command-hooks/discovery.d.ts +15 -1
- package/dist/core/command-hooks/discovery.js +1 -1
- package/dist/core/command-hooks/help.d.ts +2 -2
- package/dist/core/command-hooks/lifecycle-create.d.ts +1 -1
- package/dist/core/command-hooks/lifecycle-create.js +1 -1
- package/dist/core/command-hooks/transport/exec-invoke.d.ts +2 -0
- package/dist/core/command-hooks/transport/exec-invoke.js +1 -1
- package/dist/core/command-hooks/transport/exec-lifecycle.d.ts +1 -0
- package/dist/core/command-hooks/transport/exec-lifecycle.js +1 -1
- package/dist/core/command-hooks/transport/plan.d.ts +3 -0
- package/dist/core/command-hooks/transport/plan.js +1 -0
- package/dist/core/command-plugins/discovery.js +1 -1
- package/dist/core/command.d.ts +6 -2
- package/dist/core/command.js +6 -6
- package/dist/core/config.d.ts +8 -5
- package/dist/core/config.js +1 -1
- package/dist/core/conversation-store/client-worker.d.ts +1 -0
- package/dist/core/conversation-store/client-worker.js +1 -0
- package/dist/core/conversation-store/client.d.ts +2 -0
- package/dist/core/conversation-store/client.js +2 -0
- package/dist/core/conversation-store/file-store.d.ts +37 -0
- package/dist/core/conversation-store/file-store.js +9 -0
- package/dist/core/conversation-store/index.d.ts +50 -0
- package/dist/core/conversation-store/index.js +1 -0
- package/dist/core/conversation-store/listener.d.ts +4 -0
- package/dist/core/conversation-store/listener.js +3 -0
- package/dist/core/conversation-store/patch.d.ts +1 -0
- package/dist/core/conversation-store/patch.js +1 -0
- package/dist/core/directory/join.d.ts +27 -0
- package/dist/core/directory/join.js +1 -0
- package/dist/core/disk-usage.d.ts +4 -0
- package/dist/core/disk-usage.js +1 -0
- package/dist/core/events/emit.d.ts +2 -0
- package/dist/core/events/emit.js +3 -1
- package/dist/core/feed/feed.js +4 -4
- package/dist/core/feed/messages.d.ts +3 -0
- package/dist/core/feed/messages.js +6 -6
- package/dist/core/fs-utils.d.ts +2 -0
- package/dist/core/fs-utils.js +3 -3
- package/dist/core/grants/local.d.ts +4 -0
- package/dist/core/grants/local.js +1 -0
- package/dist/core/grants/mirror.d.ts +44 -0
- package/dist/core/grants/mirror.js +4 -0
- package/dist/core/grants/on-sync.d.ts +22 -0
- package/dist/core/grants/on-sync.js +1 -0
- package/dist/core/grants/remove.d.ts +7 -0
- package/dist/core/grants/remove.js +1 -0
- package/dist/core/grants/sandboxes.d.ts +7 -0
- package/dist/core/grants/sandboxes.js +1 -0
- package/dist/core/grants/sync.d.ts +12 -0
- package/dist/core/grants/sync.js +1 -0
- package/dist/core/help/memory-extensions.d.ts +3 -0
- package/dist/core/help/memory-extensions.js +2 -0
- package/dist/core/help.d.ts +14 -0
- package/dist/core/help.js +7 -7
- package/dist/core/host-exports/builtins.js +3 -3
- package/dist/core/host-exports/export.js +3 -3
- package/dist/core/human/action-binding.d.ts +2 -0
- package/dist/core/human/action-binding.js +1 -1
- package/dist/core/human/feedback-companion.d.ts +0 -1
- package/dist/core/human/feedback-companion.js +1 -1
- package/dist/core/human/page-schema.d.ts +1 -1
- package/dist/core/inspector/core.d.ts +2 -0
- package/dist/core/inspector/core.js +1 -1
- package/dist/core/inspector/tui.js +2 -2
- package/dist/core/installed-plugins.js +1 -1
- package/dist/core/io.js +6 -6
- package/dist/core/keybindings/catalog.d.ts +1 -1
- package/dist/core/keybindings/catalog.js +1 -1
- package/dist/core/layout-migrate/index.d.ts +15 -0
- package/dist/core/layout-migrate/index.js +4 -0
- package/dist/core/layout-migrate/paths.d.ts +26 -0
- package/dist/core/layout-migrate/paths.js +1 -0
- package/dist/core/layout-migrate/stored-paths.d.ts +2 -0
- package/dist/core/layout-migrate/stored-paths.js +11 -0
- package/dist/core/layout-migrate/stores.d.ts +17 -0
- package/dist/core/layout-migrate/stores.js +4 -0
- package/dist/core/layout.d.ts +26 -0
- package/dist/core/layout.js +2 -0
- package/dist/core/llm/run.d.ts +60 -0
- package/dist/core/llm/run.js +4 -0
- package/dist/core/memory/cli-selector.d.ts +13 -0
- package/dist/core/memory/cli-selector.js +1 -0
- package/dist/core/memory/history.d.ts +5 -4
- package/dist/core/memory/history.js +6 -6
- package/dist/core/memory/inline-ref-inventory.d.ts +2 -1
- package/dist/core/memory/inline-ref-inventory.js +1 -1
- package/dist/core/memory/lint.js +2 -2
- package/dist/core/memory/mutation-domain.d.ts +2 -2
- package/dist/core/memory/mutation-domain.js +8 -7
- package/dist/core/memory/mutations.js +1 -1
- package/dist/core/memory/service.d.ts +5 -0
- package/dist/core/memory/service.js +2 -2
- package/dist/core/memory-resolver.d.ts +11 -7
- package/dist/core/memory-resolver.js +2 -2
- package/dist/core/model-auth/daemon-login.d.ts +13 -0
- package/dist/core/model-auth/daemon-login.js +1 -0
- package/dist/core/model-auth/flows.d.ts +45 -0
- package/dist/core/model-auth/flows.js +1 -0
- package/dist/core/model-auth/handoff-jti.d.ts +4 -0
- package/dist/core/model-auth/handoff-jti.js +1 -0
- package/dist/core/model-routes.js +1 -1
- package/dist/core/nested-stores.d.ts +2 -1
- package/dist/core/nested-stores.js +1 -2
- package/dist/core/preview-registry.js +2 -2
- package/dist/core/profiles/env-store.js +2 -2
- package/dist/core/profiles/manifest.d.ts +16 -5
- package/dist/core/profiles/manifest.js +1 -1
- package/dist/core/provider-management.js +1 -1
- package/dist/core/review/birth.js +1 -1
- package/dist/core/review/companion.d.ts +0 -2
- package/dist/core/review/companion.js +1 -1
- package/dist/core/review/fork.js +2 -2
- package/dist/core/review/realize.js +1 -1
- package/dist/core/review/stage.d.ts +1 -1
- package/dist/core/review/stage.js +1 -1
- package/dist/core/review/types.d.ts +1 -1
- package/dist/core/runs/events.d.ts +34 -0
- package/dist/core/runs/events.js +1 -0
- package/dist/core/runs/operations.d.ts +43 -0
- package/dist/core/runs/operations.js +12 -0
- package/dist/core/runtime/bearings-render.d.ts +2 -2
- package/dist/core/runtime/bearings-render.js +11 -11
- package/dist/core/runtime/bearings.js +2 -2
- package/dist/core/runtime/broker/cli-relay.d.ts +5 -0
- package/dist/core/runtime/broker/cli-relay.js +1 -0
- package/dist/core/runtime/broker/client-registry.d.ts +0 -5
- package/dist/core/runtime/broker/client-registry.js +1 -1
- package/dist/core/runtime/broker/daemon-ops.d.ts +28 -1
- package/dist/core/runtime/broker/daemon-ops.js +1 -1
- package/dist/core/runtime/broker/engine-drive.d.ts +0 -2
- package/dist/core/runtime/broker/engine-drive.js +1 -1
- package/dist/core/runtime/broker/fault-retry.d.ts +9 -0
- package/dist/core/runtime/broker/fault-retry.js +1 -1
- package/dist/core/runtime/broker/frame-dispatch.d.ts +5 -9
- package/dist/core/runtime/broker/frame-dispatch.js +1 -1
- package/dist/core/runtime/broker/frame-engine-control.d.ts +3 -2
- package/dist/core/runtime/broker/frame-engine-control.js +1 -1
- package/dist/core/runtime/broker/frame-memory-refs.d.ts +4 -3
- package/dist/core/runtime/broker/frame-memory-refs.js +1 -1
- package/dist/core/runtime/broker/frame-read.js +1 -1
- package/dist/core/runtime/broker/frame-session.js +1 -1
- package/dist/core/runtime/broker/held-deferred-inbox.d.ts +3 -1
- package/dist/core/runtime/broker/held-deferred-inbox.js +1 -1
- package/dist/core/runtime/broker/inbox.d.ts +1 -2
- package/dist/core/runtime/broker/inbox.js +7 -10
- package/dist/core/runtime/broker/model-adapter.d.ts +9 -0
- package/dist/core/runtime/broker/model-adapter.js +2 -0
- package/dist/core/runtime/broker/node-token.d.ts +3 -0
- package/dist/core/runtime/broker/node-token.js +1 -0
- package/dist/core/runtime/broker/read-ops.js +1 -1
- package/dist/core/runtime/broker/rebind.d.ts +2 -0
- package/dist/core/runtime/broker/rebind.js +1 -1
- package/dist/core/runtime/broker/tool-groups.js +1 -1
- package/dist/core/runtime/broker/turn-ignition.d.ts +3 -3
- package/dist/core/runtime/broker/turn-ignition.js +1 -1
- package/dist/core/runtime/broker-cli.js +3 -3
- package/dist/core/runtime/broker-extension-render.d.ts +2 -5
- package/dist/core/runtime/broker-extension-render.js +4 -4
- package/dist/core/runtime/broker-persona-guidance.js +3 -3
- package/dist/core/runtime/broker-protocol.d.ts +7 -8
- package/dist/core/runtime/broker.js +1 -1
- package/dist/core/runtime/canvas-extensions.d.ts +1 -0
- package/dist/core/runtime/canvas-extensions.js +1 -1
- package/dist/core/runtime/close.d.ts +9 -0
- package/dist/core/runtime/close.js +1 -1
- package/dist/core/runtime/deliver-live.js +1 -1
- package/dist/core/runtime/fleet.d.ts +1 -1
- package/dist/core/runtime/front-door-login.js +1 -1
- package/dist/core/runtime/front-door.js +2 -2
- package/dist/core/runtime/headless-pi.d.ts +1 -1
- package/dist/core/runtime/headless-pi.js +1 -1
- package/dist/core/runtime/host.d.ts +1 -1
- package/dist/core/runtime/host.js +3 -1
- package/dist/core/runtime/invocation.d.ts +3 -0
- package/dist/core/runtime/kickoff.d.ts +1 -0
- package/dist/core/runtime/kickoff.js +16 -16
- package/dist/core/runtime/launch-target.d.ts +1 -1
- package/dist/core/runtime/launch-target.js +1 -1
- package/dist/core/runtime/launch.d.ts +10 -35
- package/dist/core/runtime/launch.js +1 -1
- package/dist/core/runtime/lifecycle.js +2 -2
- package/dist/core/runtime/memory.d.ts +1 -1
- package/dist/core/runtime/memory.js +1 -1
- package/dist/core/runtime/model-registry.js +1 -1
- package/dist/core/runtime/model-swap.d.ts +17 -19
- package/dist/core/runtime/model-swap.js +1 -1
- package/dist/core/runtime/node-read.js +3 -2
- package/dist/core/runtime/nodes.d.ts +7 -0
- package/dist/core/runtime/nodes.js +1 -1
- package/dist/core/runtime/outcome-document.js +1 -1
- package/dist/core/runtime/package-health.js +2 -2
- package/dist/core/runtime/persona.js +2 -2
- package/dist/core/runtime/pi-vendored.js +1 -1
- package/dist/core/runtime/placement-tmux.d.ts +1 -1
- package/dist/core/runtime/placement-tmux.js +1 -1
- package/dist/core/runtime/placement.js +1 -1
- package/dist/core/runtime/promote.js +1 -1
- package/dist/core/runtime/provider-credential-gate.js +2 -2
- package/dist/core/runtime/recovery-hold.d.ts +2 -0
- package/dist/core/runtime/recovery-hold.js +1 -0
- package/dist/core/runtime/recycle.js +1 -1
- package/dist/core/runtime/reopen.js +1 -1
- package/dist/core/runtime/reset.js +1 -1
- package/dist/core/runtime/revive.d.ts +1 -1
- package/dist/core/runtime/revive.js +2 -3
- package/dist/core/runtime/roadmap.js +4 -4
- package/dist/core/runtime/run-command.d.ts +6 -0
- package/dist/core/runtime/run-command.js +1 -1
- package/dist/core/runtime/session-branch.d.ts +2 -8
- package/dist/core/runtime/session-branch.js +1 -1
- package/dist/core/runtime/session-list-cache.d.ts +6 -22
- package/dist/core/runtime/session-list-cache.js +1 -1
- package/dist/core/runtime/situational-context.js +2 -2
- package/dist/core/runtime/spawn-env.d.ts +6 -6
- package/dist/core/runtime/spawn-env.js +1 -1
- package/dist/core/runtime/spawn.d.ts +5 -0
- package/dist/core/runtime/spawn.js +2 -2
- package/dist/core/runtime/stop-guard.js +2 -2
- package/dist/core/runtime/stop-signals.d.ts +2 -2
- package/dist/core/runtime/stop-signals.js +1 -1
- package/dist/core/runtime/structured-output.d.ts +10 -4
- package/dist/core/runtime/structured-output.js +4 -4
- package/dist/core/runtime/tmux-bindings.js +3 -3
- package/dist/core/runtime/tmux-driver.d.ts +4 -0
- package/dist/core/runtime/tmux-driver.js +7 -7
- package/dist/core/runtime/view-socket.d.ts +9 -2
- package/dist/core/runtime/view-socket.js +1 -1
- package/dist/core/runtime/warm-pool.js +1 -1
- package/dist/core/scope.d.ts +3 -2
- package/dist/core/scope.js +1 -1
- package/dist/core/scoped-state/db.js +1 -1
- package/dist/core/scoped-state/migrate.js +3 -3
- package/dist/core/scoped-state/profiles.d.ts +2 -1
- package/dist/core/scoped-state/profiles.js +1 -1
- package/dist/core/scoped-state/schema.d.ts +2 -1
- package/dist/core/scoped-state/schema.js +4 -4
- package/dist/core/scopes.d.ts +2 -2
- package/dist/core/scopes.js +1 -1
- package/dist/core/secrets.d.ts +1 -0
- package/dist/core/secrets.js +2 -2
- package/dist/core/spaces/mounts.d.ts +32 -0
- package/dist/core/spaces/mounts.js +1 -0
- package/dist/core/spaces/open-beneath.d.ts +71 -0
- package/dist/core/spaces/open-beneath.js +1 -0
- package/dist/core/spaces/permissions.d.ts +46 -0
- package/dist/core/spaces/permissions.js +1 -0
- package/dist/core/spaces/process.d.ts +27 -0
- package/dist/core/spaces/process.js +1 -0
- package/dist/core/spaces/space.d.ts +8 -0
- package/dist/core/spaces/space.js +2 -0
- package/dist/core/spaces/stop.d.ts +8 -0
- package/dist/core/spaces/stop.js +2 -0
- package/dist/core/spaces/users.d.ts +19 -0
- package/dist/core/spaces/users.js +1 -0
- package/dist/core/subscription-state.d.ts +2 -0
- package/dist/core/subscription-state.js +3 -3
- package/dist/core/substrate/frontmatter-validation.js +1 -1
- package/dist/core/substrate/injected-store.d.ts +28 -3
- package/dist/core/substrate/injected-store.js +2 -1
- package/dist/core/substrate/listings.js +1 -1
- package/dist/core/substrate/memory-events.d.ts +6 -0
- package/dist/core/substrate/memory-events.js +1 -0
- package/dist/core/substrate/on-read-node.js +1 -1
- package/dist/core/substrate/on-read.d.ts +6 -6
- package/dist/core/substrate/on-read.js +5 -5
- package/dist/core/substrate/plan.js +1 -1
- package/dist/core/substrate/render-node.js +1 -1
- package/dist/core/substrate/render.d.ts +4 -3
- package/dist/core/substrate/render.js +38 -38
- package/dist/core/substrate/schema.d.ts +6 -0
- package/dist/core/substrate/schema.js +1 -1
- package/dist/core/tui/panel.js +1 -1
- package/dist/core/user-settings.d.ts +12 -0
- package/dist/core/user-settings.js +1 -1
- package/dist/core/worktree-mutation-async.js +5 -5
- package/dist/core/worktree-quarantine.js +1 -1
- package/dist/core/worktree-remove.d.ts +15 -0
- package/dist/core/worktree-remove.js +1 -0
- package/dist/core/worktree-sweep.js +6 -6
- package/dist/daemon/analytics/compute.d.ts +37 -0
- package/dist/daemon/analytics/compute.js +1 -0
- package/dist/daemon/analytics/scan-worker.d.ts +1 -0
- package/dist/daemon/analytics/scan-worker.js +2 -0
- package/dist/daemon/analytics/scan.d.ts +37 -0
- package/dist/daemon/analytics/scan.js +1 -0
- package/dist/daemon/api/app-listener.d.ts +11 -0
- package/dist/daemon/api/app-listener.js +21 -0
- package/dist/daemon/api/bridge.js +5 -5
- package/dist/daemon/api/handlers/analytics.d.ts +2 -0
- package/dist/daemon/api/handlers/analytics.js +1 -0
- package/dist/daemon/api/handlers/attach.js +1 -1
- package/dist/daemon/api/handlers/bash-jobs.js +2 -2
- package/dist/daemon/api/handlers/bash.js +1 -1
- package/dist/daemon/api/handlers/broker-ops.js +1 -1
- package/dist/daemon/api/handlers/canvas.d.ts +1 -1
- package/dist/daemon/api/handlers/canvas.js +6 -6
- package/dist/daemon/api/handlers/crons.js +1 -1
- package/dist/daemon/api/handlers/files.d.ts +1 -1
- package/dist/daemon/api/handlers/files.js +1 -1
- package/dist/daemon/api/handlers/health.js +2 -2
- package/dist/daemon/api/handlers/hook-exec.d.ts +2 -0
- package/dist/daemon/api/handlers/hook-exec.js +1 -0
- package/dist/daemon/api/handlers/human-requests.js +1 -1
- package/dist/daemon/api/handlers/inbox.js +1 -1
- package/dist/daemon/api/handlers/llm.d.ts +2 -0
- package/dist/daemon/api/handlers/llm.js +3 -0
- package/dist/daemon/api/handlers/memory-reads.d.ts +4 -0
- package/dist/daemon/api/handlers/memory-reads.js +1 -0
- package/dist/daemon/api/handlers/memory.js +5 -1
- package/dist/daemon/api/handlers/messages.js +2 -2
- package/dist/daemon/api/handlers/modelauth.js +1 -1
- package/dist/daemon/api/handlers/node-outcomes.js +1 -1
- package/dist/daemon/api/handlers/node-records.d.ts +2 -0
- package/dist/daemon/api/handlers/node-records.js +3 -0
- package/dist/daemon/api/handlers/nodes.d.ts +1 -1
- package/dist/daemon/api/handlers/nodes.js +1 -1
- package/dist/daemon/api/handlers/profiles.d.ts +4 -1
- package/dist/daemon/api/handlers/profiles.js +1 -1
- package/dist/daemon/api/handlers/reports.js +5 -3
- package/dist/daemon/api/handlers/reviews.d.ts +1 -1
- package/dist/daemon/api/handlers/reviews.js +1 -1
- package/dist/daemon/api/handlers/run-routes.d.ts +2 -0
- package/dist/daemon/api/handlers/run-routes.js +1 -0
- package/dist/daemon/api/handlers/runs.d.ts +9 -0
- package/dist/daemon/api/handlers/runs.js +1 -0
- package/dist/daemon/api/handlers/subscriptions.js +1 -1
- package/dist/daemon/api/handlers/worktree.js +1 -1
- package/dist/daemon/api/map.d.ts +10 -4
- package/dist/daemon/api/map.js +2 -2
- package/dist/daemon/api/operations.d.ts +18 -0
- package/dist/daemon/api/operations.js +1 -0
- package/dist/daemon/api/principal.d.ts +42 -0
- package/dist/daemon/api/principal.js +1 -0
- package/dist/daemon/api/router.d.ts +27 -3
- package/dist/daemon/api/router.js +1 -1
- package/dist/daemon/api/server.d.ts +4 -0
- package/dist/daemon/api/server.js +1 -1
- package/dist/daemon/api/vendor-signin.d.ts +7 -0
- package/dist/daemon/api/vendor-signin.js +77 -0
- package/dist/daemon/api/viewer-presence.d.ts +3 -0
- package/dist/daemon/api/viewer-presence.js +1 -0
- package/dist/daemon/cron/armed-context.d.ts +4 -0
- package/dist/daemon/cron/armed-context.js +1 -1
- package/dist/daemon/cron/escalation.js +3 -3
- package/dist/daemon/cron/lease-recovery.js +1 -1
- package/dist/daemon/cron/sinks.js +2 -2
- package/dist/daemon/cron-run.d.ts +5 -5
- package/dist/daemon/cron-run.js +1 -1
- package/dist/daemon/crtrd.js +8 -7
- package/dist/daemon/delivery/run-delivery.d.ts +4 -0
- package/dist/daemon/delivery/run-delivery.js +1 -1
- package/dist/daemon/fleet.d.ts +1 -1
- package/dist/daemon/fleet.js +6 -6
- package/dist/daemon/human/finish.js +7 -7
- package/dist/daemon/joined-owner.d.ts +5 -0
- package/dist/daemon/joined-owner.js +1 -0
- package/dist/daemon/manage.js +2 -2
- package/dist/daemon/messaging/node-message.js +1 -1
- package/dist/daemon/park-activity.js +1 -1
- package/dist/daemon/reconcilers/bash-deadline.js +1 -1
- package/dist/daemon/reconcilers/broker-supervision.d.ts +1 -1
- package/dist/daemon/reconcilers/broker-supervision.js +4 -4
- package/dist/daemon/reconcilers/delivery-lane.js +1 -1
- package/dist/daemon/reconcilers/live-obligation.d.ts +7 -0
- package/dist/daemon/reconcilers/live-obligation.js +1 -1
- package/dist/daemon/reconcilers/node-lifecycle/tick.js +1 -1
- package/dist/daemon/reconcilers/storage-maintenance.d.ts +20 -1
- package/dist/daemon/reconcilers/storage-maintenance.js +1 -1
- package/dist/daemon/runs/append-section.d.ts +6 -0
- package/dist/daemon/runs/append-section.js +2 -0
- package/dist/daemon/runs/observer.d.ts +5 -0
- package/dist/daemon/runs/observer.js +4 -0
- package/dist/launcher/bwrap.d.ts +4 -0
- package/dist/launcher/bwrap.js +2 -0
- package/dist/launcher/client.d.ts +2 -0
- package/dist/launcher/client.js +3 -0
- package/dist/launcher/main.d.ts +1 -0
- package/dist/launcher/main.js +3 -0
- package/dist/launcher/netrule.d.ts +1 -0
- package/dist/launcher/netrule.js +1 -0
- package/dist/launcher/seccomp.d.ts +1 -0
- package/dist/launcher/seccomp.js +1 -0
- package/dist/launcher/spec.d.ts +88 -0
- package/dist/launcher/spec.js +1 -0
- package/dist/launcher/users.d.ts +18 -0
- package/dist/launcher/users.js +7 -0
- package/dist/launcher/validate.d.ts +22 -0
- package/dist/launcher/validate.js +1 -0
- package/dist/migrations/corpus.js +3 -3
- package/dist/migrations/runner.js +1 -1
- package/dist/native/linux/addon.node +0 -0
- package/dist/native/linux.d.ts +29 -0
- package/dist/native/linux.js +1 -0
- package/dist/pi-extensions/broker-local.js +2 -2
- package/dist/pi-extensions/canvas-bash-valve.d.ts +1 -3
- package/dist/pi-extensions/canvas-bash-valve.js +4 -7
- package/dist/pi-extensions/canvas-context-intro.d.ts +1 -2
- package/dist/pi-extensions/canvas-context-intro.js +2 -2
- package/dist/pi-extensions/canvas-doc-substrate.js +6 -6
- package/dist/pi-extensions/canvas-inbox-watcher.d.ts +2 -1
- package/dist/pi-extensions/canvas-inbox-watcher.js +2 -1
- package/dist/pi-extensions/canvas-passive-context.d.ts +1 -1
- package/dist/pi-extensions/canvas-passive-context.js +11 -11
- package/dist/pi-extensions/canvas-recap.js +6 -6
- package/dist/pi-extensions/canvas-stophook.js +1 -1
- package/dist/pi-extensions/canvas-structured-output.js +4 -4
- package/dist/pi-extensions/canvas-tool-guide.js +1 -1
- package/dist/pi-extensions/system-prompt-entry.d.ts +15 -0
- package/dist/pi-extensions/system-prompt-entry.js +1 -0
- package/dist/shared/env.d.ts +5 -1
- package/dist/shared/env.js +1 -1
- package/dist/shared/strip-cd-prefix.d.ts +1 -0
- package/dist/shared/strip-cd-prefix.js +1 -0
- package/dist/types.d.ts +31 -15
- package/docs/cli/memory-and-preferences.md +3 -1
- package/docs/sdk/client.md +34 -0
- package/docs/sdk/errors.md +2 -0
- package/docs/sdk/memory.md +2 -2
- package/docs/sdk/streaming.md +21 -0
- package/package.json +18 -4
- package/packages/crouter-identity/dist/index.d.ts +54 -0
- package/packages/crouter-identity/dist/index.js +166 -0
- package/packages/crouter-identity/package.json +33 -0
- package/runtime.lock.json +34 -8
- package/scripts/build-native-linux.mjs +16 -0
- package/scripts/install-runtime.mjs +9 -7
- package/scripts/lib/isolation-env.mjs +42 -0
- package/scripts/runtime-smoke.mjs +49 -0
- package/src/native/linux/addon.c +249 -0
- package/dist/core/profiles/state-block.d.ts +0 -4
- package/dist/core/profiles/state-block.js +0 -3
- package/dist/core/runtime/broker/auth-reload.d.ts +0 -41
- package/dist/core/runtime/broker/auth-reload.js +0 -1
- package/dist/core/substrate/cli-context-delivery.d.ts +0 -22
- package/dist/core/substrate/cli-context-delivery.js +0 -1
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
var
|
|
1
|
+
var Y=Object.defineProperty;var r=(e,n)=>Y(e,"name",{value:n,configurable:!0});import{envNodeId as L}from"../../shared/env.js";import{rmdirSync as q,rmSync as V,statSync as K}from"node:fs";import{dirname as G,join as v,resolve as Q}from"node:path";import{removeTreeBeneath as A}from"../spaces/open-beneath.js";import{emitEvent as X}from"../events/emit.js";import{openDb as a,withCanvasWrite as _}from"./db.js";import{conversationStore as Z,ConversationNotFoundError as ee}from"../conversation-store/index.js";import{activateArmedExternalActionDelivery as ne,armExternalActionDelivery as te,hasUnseenWakeMail as oe}from"./deliveries.js";import{findNodeBySessionFileSql as re}from"./sessions.js";import{hydrateFault as ie}from"./recovery.js";import{hasUnreconciledWorktree as se,openWorktree as ae,readWorktree as de,worktreeFromRow as le}from"./worktrees.js";import{isPidAlive as ue,isPidPresent as b,recordedPidLiveness as ce}from"./pid.js";import{ensureHome as _e,jobDir as pe,nodeDir as fe,nodeRunDir as k}from"./paths.js";import{appForNode as Ee,ensureNodeDirs as me,nodeAgentDir as Ne}from"./node-agent-paths.js";import{memoryDir as ge}from"../runtime/memory.js";import{appSpace as x}from"../layout.js";function f(e,n){if(e==null)return null;const t=JSON.stringify(e);if(t===void 0)throw new TypeError(`${n} must be JSON-serializable`);return t}r(f,"jsonValue");function W(e,n,t){te(e,{destinationId:t.actionName,adapter:{adapter:"subprocess",argv:t.argv,cwd:t.cwd,config_origin:t.configOrigin,payload:t.payload??null},idempotencyKey:`node-outcome:${n}`})}r(W,"insertArmedOutcomeDelivery");function Ue(e,n){if(e.prepare("SELECT deleting_at FROM nodes WHERE node_id = ?").get(n)?.deleting_at)throw new Error("run is deleting")}r(Ue,"assertRunNotDeleting");function Re(e,n){n.prepare(`INSERT INTO nodes (node_id, name, description, title, icon, cycles, kind, mode, lifecycle, cwd, host_kind, profile_id, parent, spawned_by, creator, fork_from, fork_source_file, created, passive_default, cycle_pending, model_override, persona_ack_json, review_binding_json, launch_config_json, scopes_json, status, intent, waiting_for, final_report, finalized_at, deadline_at, "window", tmux_session, pane, grantee, sub, grant_id, client_id, metadata_json, run_id, event_cursor, usage_json, deleting_at) VALUES (${Array(43).fill("?").join(", ")})`).run(e.node_id,e.name,e.description??null,e.title??null,e.icon??null,e.cycles??null,e.kind,e.mode,e.lifecycle,e.cwd,e.host_kind??null,e.profile_id??null,e.parent??null,e.spawned_by??null,e.creator??null,e.fork_from??null,e.fork_source_file??null,e.created,e.passive_default===!0?1:0,e.cycle_pending===!0?1:0,e.model_override??null,f(e.persona_ack,"persona_ack"),f(e.review_binding,"review_binding"),f(e.launch,"launch"),f(e.scopes,"scopes"),e.status??"active",e.intent??null,e.waiting_for??null,e.final_report??null,e.finalized_at??null,e.deadline_at??null,e.window??null,e.tmux_session??null,e.pane??null,e.grantee??"app:terminal",e.sub??null,e.grant_id??null,e.client_id??null,e.metadata_json??null,e.run_id??null,e.event_cursor??null,e.usage_json??null,e.deleting_at??null)}r(Re,"seedRow");function j(e){if(e.fault_id==null)return null;const n=Object.entries(e).filter(([t])=>t.startsWith("fault_")).map(([t,o])=>[t==="fault_id"?t:t.slice(6),o]);return ie(Object.fromEntries(n))}r(j,"faultFrom");function p(e){const n={node_id:e.node_id,name:e.name,description:e.description??void 0,cycles:e.cycles??void 0,kind:e.kind,mode:e.mode,lifecycle:e.lifecycle,status:e.status,cwd:e.cwd,host_kind:e.host_kind??null,profile_id:e.profile_id??null,scopes:e.scopes_json==null?null:JSON.parse(e.scopes_json),grantee:e.grantee,sub:e.sub??null,grant_id:e.grant_id??null,client_id:e.client_id??null,metadata_json:e.metadata_json??null,run_id:e.run_id??null,event_cursor:e.event_cursor??null,last_activity_at:e.last_activity_at??null,usage_json:e.usage_json??null,deleting_at:e.deleting_at??null,parent:e.parent??null,created:e.created,intent:e.intent??null,waiting_for:e.waiting_for??null,frozen_at:e.frozen_at??null,respawn_failures:e.respawn_failures??0,respawn_not_before:e.respawn_not_before??null,launched_at:e.launched_at??null,last_settled_at:e.last_settled_at??null,terminal_reason:e.terminal_reason??null,final_report:e.final_report??null,finalized_at:e.finalized_at??null,outcome_kind:e.outcome_kind??null,outcome_reason:e.outcome_reason??null,outcome_at:e.outcome_at??null,outcome_revision:e.outcome_revision??0,outcome_detail_json:e.outcome_detail_json??null,deadline_at:e.deadline_at??null,telemetry_tokens_in:e.telemetry_tokens_in??null,telemetry_context_tokens:e.telemetry_context_tokens??null,telemetry_last_activity:e.telemetry_last_activity??null,telemetry_updated_at:e.telemetry_updated_at??null,pi_pid:e.pi_pid??null,pi_pid_identity:e.pi_pid_identity??null,window:e.window??null,tmux_session:e.tmux_session??null,pane:e.pane??null,fault:null,streaming:!1},t=b(n.pi_pid),o=j(e);return n.fault=o?.link==="pi\u2192provider"&&o.retry.by==="daemon"&&o.retry.disposition==="auto"&&!t?null:o,n.streaming=e.turn_open_at!==null&&e.turn_closed_at===null&&t,n}r(p,"rowFrom");function F(e,n=de(e.node_id)){return{...p(e),title:e.title??void 0,icon:e.icon??void 0,spawned_by:e.spawned_by??null,creator:e.creator??null,fork_from:e.fork_from??null,fork_source_file:e.fork_source_file??null,passive_default:e.passive_default===1,cycle_pending:e.cycle_pending===1,model_override:e.model_override??null,scopes:e.scopes_json==null?null:JSON.parse(e.scopes_json),persona_ack:e.persona_ack_json==null?void 0:JSON.parse(e.persona_ack_json),review_binding:e.review_binding_json==null?void 0:JSON.parse(e.review_binding_json),launch:e.launch_config_json==null?void 0:JSON.parse(e.launch_config_json),pi_session_id:e.pi_session_id??null,pi_session_file:e.pi_session_file??null,...n===null?{}:{managed_worktree:n}}}r(F,"metaFrom");function Pe(e,n={}){return _e(),_(t=>{Re(e,t),e.managed_worktree!==void 0&&e.managed_worktree!==null&&ae(e.node_id,e.managed_worktree,t),n.outcomeDelivery!==void 0&&W(t,e.node_id,n.outcomeDelivery),n.withinCreate?.(t,e)}),me(e.node_id),E(e.node_id)}r(Pe,"createNode");function E(e){const n=a().prepare("SELECT * FROM node_rows WHERE node_id = ?").get(e);return n===void 0?null:F(n)}r(E,"getNode");function $e(e){return Q(e)}r($e,"canonicalSessionFile");function Be(e){const n=re(e);return n===null?null:E(n)}r(Be,"findNodeBySessionFile");function ze(e){const n=a().prepare("SELECT * FROM node_rows WHERE node_id = ?").get(e);return n?p(n):null}r(ze,"getRow");function Je(e){const n=a().prepare("SELECT * FROM node_rows WHERE pane = ?").get(e);return n?p(n):null}r(Je,"getRowByPane");function Ye(e){return a().prepare(`SELECT * FROM node_rows
|
|
2
2
|
WHERE deadline_at IS NOT NULL AND outcome_at IS NULL
|
|
3
3
|
AND deadline_at <= ? AND status IN ('active','idle') AND kind != 'human'
|
|
4
|
-
ORDER BY deadline_at, created, node_id`).all(e).map(
|
|
5
|
-
WHERE profile_id = ? AND deadline_at IS NOT NULL AND status IN ('active', 'idle')`).all(e),i=t.prepare("UPDATE nodes SET deadline_at = ? WHERE node_id = ? AND deadline_at = ?");let s=0;for(const d of
|
|
4
|
+
ORDER BY deadline_at, created, node_id`).all(e).map(p)}r(Ye,"dueNodeDeadlines");function qe(e,n){return Number(a().prepare("UPDATE nodes SET deadline_at = ? WHERE node_id = ?").run(n,e).changes)===1}r(qe,"setNodeDeadline");function Ve(e,n){return!Number.isFinite(n)||n<=0?0:_(t=>{const o=t.prepare(`SELECT node_id, deadline_at FROM nodes
|
|
5
|
+
WHERE profile_id = ? AND deadline_at IS NOT NULL AND status IN ('active', 'idle')`).all(e),i=t.prepare("UPDATE nodes SET deadline_at = ? WHERE node_id = ? AND deadline_at = ?");let s=0;for(const d of o){const l=Date.parse(d.deadline_at);Number.isNaN(l)||(s+=Number(i.run(new Date(l+n).toISOString(),d.node_id,d.deadline_at).changes))}return s})}r(Ve,"shiftProfileNodeDeadlines");function Ke(e,n,t){return Number(e.prepare("UPDATE nodes SET sub = ? WHERE sub = 'user:local'").run(n).changes)+Number(e.prepare("UPDATE nodes SET grantee = 'app:terminal' WHERE grantee = 'user:local'").run().changes)+Number(e.prepare("UPDATE nodes SET sub = ? WHERE sub IS NULL AND grantee = 'app:terminal'").run(n).changes)+Number(e.prepare("UPDATE nodes SET grant_id = NULL WHERE grant_id = ?").run(t).changes)}r(Ke,"rewriteLocalNodeIdentity");function ye(e,n){if(e==null)return null;if(typeof e=="string"||typeof e=="number"||typeof e=="bigint"||e instanceof Uint8Array)return e;throw new TypeError(`${n} must be a SQLite scalar`)}r(ye,"sqlInput");function Ge(e,n){const t=[],o=r((s,d=s)=>{Object.prototype.hasOwnProperty.call(n,s)&&t.push([d,ye(n[s],s)])},"add");if(o("name"),o("description"),o("title"),o("icon"),o("cycles"),o("kind"),o("mode"),o("lifecycle"),o("cwd"),o("host_kind"),o("profile_id"),o("parent"),o("spawned_by"),o("creator"),o("fork_from"),o("fork_source_file"),o("model_override"),Object.prototype.hasOwnProperty.call(n,"passive_default")&&t.push(["passive_default",n.passive_default===!0?1:0]),Object.prototype.hasOwnProperty.call(n,"cycle_pending")&&t.push(["cycle_pending",n.cycle_pending===!0?1:0]),Object.prototype.hasOwnProperty.call(n,"persona_ack")&&t.push(["persona_ack_json",f(n.persona_ack,"persona_ack")]),Object.prototype.hasOwnProperty.call(n,"review_binding")&&t.push(["review_binding_json",f(n.review_binding,"review_binding")]),Object.prototype.hasOwnProperty.call(n,"scopes")&&t.push(["scopes_json",f(n.scopes,"scopes")]),Object.prototype.hasOwnProperty.call(n,"launch")&&t.push(["launch_config_json",f(n.launch,"launch")]),t.length===0){const s=E(e);if(s===null)throw new Error(`unknown node: ${e}`);return s}if(a().prepare(`UPDATE nodes SET ${t.map(([s])=>`${s} = ?`).join(", ")} WHERE node_id = ?`).run(...t.map(([,s])=>s),e).changes!==1)throw new Error(`unknown node: ${e}`);return E(e)}r(Ge,"updateNode");function Qe(e,n){a().prepare("UPDATE nodes SET status = ? WHERE node_id = ?").run(n,e)}r(Qe,"setStatus");function Xe(e,n){a().prepare("UPDATE nodes SET intent = ? WHERE node_id = ?").run(n??null,e)}r(Xe,"setIntent");function Ze(e,n,t={}){if(t.outcome===void 0){const i=[],s=[];Object.prototype.hasOwnProperty.call(n,"status")&&(i.push("status = ?"),s.push(n.status??null)),Object.prototype.hasOwnProperty.call(n,"intent")&&(i.push("intent = ?"),s.push(n.intent??null)),Object.prototype.hasOwnProperty.call(n,"terminal_reason")&&(i.push("terminal_reason = ?"),s.push(n.terminal_reason??null));const d=["node_id = ?"];s.push(e),t.fromStatuses!==void 0&&(d.push(`status IN (${t.fromStatuses.map(()=>"?").join(", ")})`),s.push(...t.fromStatuses)),t.requireNoFinalReport===!0&&d.push("final_report IS NULL");const l=a().prepare(`UPDATE nodes SET ${i.join(", ")} WHERE ${d.join(" AND ")}`).run(...s);return Number(l.changes)}const o=t.outcome;return _(i=>{const s=[],d=[];Object.prototype.hasOwnProperty.call(n,"status")&&(s.push("status = ?"),d.push(n.status??null)),Object.prototype.hasOwnProperty.call(n,"intent")&&(s.push("intent = ?"),d.push(n.intent??null)),Object.prototype.hasOwnProperty.call(n,"terminal_reason")&&(s.push("terminal_reason = ?"),d.push(n.terminal_reason??null));const l=r((g,u)=>o.supersede===!0?"?":`CASE WHEN outcome_at IS NULL THEN ? ELSE ${u} END`,"outcomeValue");s.push(`outcome_kind = ${l(o.kind,"outcome_kind")}`,`outcome_reason = ${l(o.reason,"outcome_reason")}`,`outcome_detail_json = ${l(o.detailJson,"outcome_detail_json")}`,`outcome_revision = ${o.supersede===!0?"outcome_revision + 1":"CASE WHEN outcome_at IS NULL THEN outcome_revision + 1 ELSE outcome_revision END"}`,`outcome_at = ${l(o.at,"outcome_at")}`),d.push(o.kind,o.reason,o.detailJson,o.at);const c=["node_id = ?"];d.push(e),t.fromStatuses!==void 0&&(c.push(`status IN (${t.fromStatuses.map(()=>"?").join(", ")})`),d.push(...t.fromStatuses)),t.requireNoFinalReport===!0&&c.push("final_report IS NULL");const m=i.prepare(`UPDATE nodes SET ${s.join(", ")} WHERE ${c.join(" AND ")}`).run(...d);if(Number(m.changes)===0)return 0;const y=i.prepare("SELECT outcome_at FROM nodes WHERE node_id = ?").get(e);return(o.supersede===!0||y.outcome_at===o.at)&&o.documentJson!==null&&o.documentJson!==void 0&&ne(i,{idempotencyKey:`node-outcome:${e}`,label:e,bodyJson:o.documentJson,supersede:o.supersede===!0}),Number(m.changes)})}r(Ze,"transitionStatusIntent");function en(e){return a().prepare("SELECT final_report FROM nodes WHERE node_id = ?").get(e)?.final_report??null}r(en,"getFinalReport");function nn(e,n){return a().prepare("UPDATE nodes SET final_report = NULL, finalized_at = NULL WHERE node_id = ? AND final_report = ?").run(e,n).changes>0}r(nn,"clearFinalReportIfMatches");function tn(e,n){a().prepare('UPDATE nodes SET tmux_session = ?, "window" = ?, pane = ? WHERE node_id = ?').run(n.tmux_session??null,n.window??null,n.pane??null,e)}r(tn,"setPresence");function on(e,n){a().prepare("UPDATE nodes SET launched_at = ?, frozen_at = NULL, respawn_not_before = NULL WHERE node_id = ?").run(n,e)}r(on,"recordLaunch");function rn(e,n){a().prepare("UPDATE nodes SET last_settled_at = ? WHERE node_id = ?").run(n,e)}r(rn,"recordSettledTurn");function sn(e,n){a().prepare("UPDATE nodes SET frozen_at = ? WHERE node_id = ?").run(n,e)}r(sn,"setFrozen");function an(e){a().prepare("UPDATE nodes SET frozen_at = NULL WHERE node_id = ?").run(e)}r(an,"clearFrozen");function dn(e,n){a().prepare("UPDATE nodes SET respawn_failures = ?, respawn_not_before = ? WHERE node_id = ?").run(n.failures,n.notBefore,e)}r(dn,"recordRespawnAttempt");const N="node_id NOT IN (SELECT node_id FROM warm_pool)",H=["state","cleanup_state","path","branch","repo_root","base_ref","base_sha","created_at","closed_at","next_attempt_at","attempts","quarantined","sweep_reason","sweep_detail","sweep_last_at","sweep_observed_json","abandoned_json","land_intent_json","disposal_json"];function Se(e){return e.worktree_state===null?null:le(Object.fromEntries(H.map(n=>[n,e[`worktree_${n}`]])))}r(Se,"worktreeFromProjection");function ln(e){const n=H.map(o=>`w.${o} AS worktree_${o}`).join(", ");return a().prepare(`SELECT n.*, ${n} FROM node_rows n LEFT JOIN worktrees w ON w.node_id = n.node_id WHERE n.profile_id = ? ORDER BY n.created`).all(e).map(o=>F(o,Se(o)))}r(ln,"listNodesByProfile");function un(){return a().prepare("SELECT node_id, cwd, profile_id, grantee FROM nodes ORDER BY created").all().map(e=>{const n=e;return{nodeId:n.node_id,cwd:n.cwd,profileId:n.profile_id,grantee:n.grantee}})}r(un,"listNodeMemoryTargets");function cn(e,n){a().prepare(`UPDATE nodes
|
|
6
6
|
SET telemetry_tokens_in = ?,
|
|
7
7
|
telemetry_context_tokens = COALESCE(?, telemetry_context_tokens),
|
|
8
8
|
telemetry_last_activity = COALESCE(?, telemetry_last_activity),
|
|
9
9
|
telemetry_updated_at = ?
|
|
10
10
|
WHERE node_id = ?
|
|
11
|
-
AND (telemetry_updated_at IS NULL OR telemetry_updated_at < ?)`).run(n.tokensIn,n.contextTokens,n.lastActivity,n.updatedAt,e,n.updatedAt)}
|
|
11
|
+
AND (telemetry_updated_at IS NULL OR telemetry_updated_at < ?)`).run(n.tokensIn,n.contextTokens,n.lastActivity,n.updatedAt,e,n.updatedAt)}r(cn,"updateNodeTelemetry");function _n(){return a().prepare(`SELECT
|
|
12
12
|
node_id, name, description, cycles, kind, status, frozen_at,
|
|
13
13
|
telemetry_context_tokens, telemetry_last_activity,
|
|
14
14
|
pi_pid, turn_open_at, turn_closed_at,
|
|
@@ -16,28 +16,29 @@ var j=Object.defineProperty;var o=(e,n)=>j(e,"name",{value:n,configurable:!0});i
|
|
|
16
16
|
fault_operation_id, fault_anchor_entry_id, fault_retry_disposition,
|
|
17
17
|
fault_retry_by, fault_retry_attempt, fault_retry_max, fault_retry_next_at,
|
|
18
18
|
fault_provider_error_json
|
|
19
|
-
FROM node_rows WHERE ${
|
|
20
|
-
WHERE ${
|
|
19
|
+
FROM node_rows WHERE ${N} ORDER BY created`).all().map(n=>{const t=n.pi_pid??null,o=b(t),i=j(n);return{node_id:n.node_id,name:n.name,description:n.description??null,cycles:n.cycles??null,kind:n.kind,status:n.status,frozen_at:n.frozen_at??null,pi_pid:t,telemetry_context_tokens:n.telemetry_context_tokens??null,telemetry_last_activity:n.telemetry_last_activity??null,fault:i?.link==="pi\u2192provider"&&i.retry.by==="daemon"&&i.retry.disposition==="auto"&&!o?null:i,streaming:n.turn_open_at!==null&&n.turn_closed_at===null&&o}})}r(_n,"graphNodes");function we(e){const n=[N],t=[];if(e?.status!==void 0){const i=Array.isArray(e.status)?e.status:[e.status];n.push(`status IN (${i.map(()=>"?").join(",")})`),t.push(...i)}return e?.withRecordedPid===!0&&n.push("pi_pid IS NOT NULL"),e?.withRecordedPidOrFrozen===!0&&n.push("(pi_pid IS NOT NULL OR frozen_at IS NOT NULL)"),a().prepare(`SELECT * FROM node_rows WHERE ${n.join(" AND ")} ORDER BY created`).all(...t).map(p)}r(we,"listNodes");function pn(){return a().prepare(`SELECT * FROM node_rows
|
|
20
|
+
WHERE ${N} AND kind != 'human'
|
|
21
21
|
AND (status IN ('active', 'idle') OR (status IN ('done', 'canceled', 'dead') AND (pi_pid IS NOT NULL OR frozen_at IS NOT NULL)))
|
|
22
|
-
ORDER BY created`).all().map(
|
|
22
|
+
ORDER BY created`).all().map(p)}r(pn,"listNodesForSupervision");function fn(){return a().prepare(`SELECT node_id, name, created FROM nodes WHERE ${N} ORDER BY created`).all()}r(fn,"listNodeIdentities");function En(e,n){_(t=>{t.prepare("INSERT OR REPLACE INTO warm_pool (node_id, recipe_key, created) VALUES (?, ?, ?)").run(e,n,new Date().toISOString())})}r(En,"registerWarmSpare");function mn(e){return _(n=>n.prepare("DELETE FROM warm_pool WHERE node_id = ?").run(e).changes>0)}r(mn,"unregisterWarmSpare");function S(e,n){const t=`SELECT w.node_id AS node_id, w.recipe_key AS recipe_key, w.created AS created,
|
|
23
23
|
n.status AS status, n.pi_pid AS pi_pid, n.pi_pid_identity AS pi_pid_identity
|
|
24
|
-
FROM warm_pool w JOIN node_rows n ON n.node_id = w.node_id`+(n===void 0?"":" WHERE w.recipe_key = ?")+" ORDER BY w.created";return(n===void 0?e.prepare(t).all():e.prepare(t).all(n)).map(i=>({node_id:i.node_id,recipe_key:i.recipe_key,created:i.created,status:i.status,pi_pid:i.pi_pid??null,pi_pid_identity:i.pi_pid_identity??null}))}
|
|
25
|
-
FROM nodes WHERE ${
|
|
24
|
+
FROM warm_pool w JOIN node_rows n ON n.node_id = w.node_id`+(n===void 0?"":" WHERE w.recipe_key = ?")+" ORDER BY w.created";return(n===void 0?e.prepare(t).all():e.prepare(t).all(n)).map(i=>({node_id:i.node_id,recipe_key:i.recipe_key,created:i.created,status:i.status,pi_pid:i.pi_pid??null,pi_pid_identity:i.pi_pid_identity??null}))}r(S,"warmSpareRowsFor");function Nn(){return S(a())}r(Nn,"listWarmSpares");function gn(e){return a().prepare("SELECT 1 FROM warm_pool WHERE node_id = ?").get(e)!==void 0}r(gn,"isWarmSpare");function M(e){return e.status!=="active"&&e.status!=="idle"?!1:ce(e.pi_pid,e.pi_pid_identity)==="alive"}r(M,"spareIsClaimable");function Rn(e,n,t={}){return _(o=>{const i=S(o,e).find(M);return i===void 0||o.prepare("DELETE FROM warm_pool WHERE node_id = ?").run(i.node_id).changes===0?null:(o.prepare("UPDATE nodes SET created = ?, deadline_at = ? WHERE node_id = ?").run(n,t.deadlineAt??null,i.node_id),t.outcomeDelivery!==void 0&&W(o,i.node_id,t.outcomeDelivery),i.node_id)})}r(Rn,"claimWarmSpare");function yn(e){return S(a(),e).filter(M).length}r(yn,"warmSpareCount");function Sn(e){return a().prepare("SELECT node_id FROM nodes WHERE parent = ? ORDER BY created").all(e).map(n=>n.node_id)}r(Sn,"childrenOf");function wn(){return a().prepare(`SELECT node_id, name, kind, mode, lifecycle, status, cwd, host_kind, parent, created
|
|
25
|
+
FROM nodes WHERE ${N} ORDER BY created`).all().map(e=>({node_id:e.node_id,name:e.name,kind:e.kind,mode:e.mode,lifecycle:e.lifecycle,status:e.status,cwd:e.cwd,host_kind:e.host_kind??null,parent:e.parent??null,created:e.created}))}r(wn,"rosterNodes");function On(){return a().prepare("SELECT from_id, to_id, active, created FROM edges WHERE type = 'subscribes_to' ORDER BY created").all().map(e=>({from_id:e.from_id,to_id:e.to_id,active:e.active===1,created:e.created}))}r(On,"rosterEdges");function hn(e){return a().prepare(`SELECT * FROM node_rows
|
|
26
26
|
WHERE parent IS NULL AND kind != 'human'
|
|
27
27
|
AND status IN ('active','idle') AND cwd = ?
|
|
28
|
-
AND ${
|
|
29
|
-
ORDER BY created DESC`).all(e).map(
|
|
28
|
+
AND ${N}
|
|
29
|
+
ORDER BY created DESC`).all(e).map(p)}r(hn,"listResumableRoots");function C(e,n,t,o){a().prepare(`INSERT INTO edges (type, from_id, to_id, active, created)
|
|
30
30
|
VALUES (?, ?, ?, ?, ?)
|
|
31
|
-
ON CONFLICT(type, from_id, to_id) DO UPDATE SET active=excluded.active`).run(e,n,t,
|
|
32
|
-
WHERE type = 'subscribes_to' AND to_id = ? ORDER BY created`).all(e).map(n=>({node_id:n.node_id,active:n.active===1,created:n.created}))}
|
|
33
|
-
WHERE type = 'subscribes_to' AND from_id = ? ORDER BY created`).all(e).map(n=>({node_id:n.node_id,active:n.active===1,created:n.created}))}
|
|
31
|
+
ON CONFLICT(type, from_id, to_id) DO UPDATE SET active=excluded.active`).run(e,n,t,o?1:0,new Date().toISOString())}r(C,"addEdge");function Tn(e,n,t=!0){C("subscribes_to",e,n,t)}r(Tn,"subscribe");function Dn(e,n){a().prepare("DELETE FROM edges WHERE type = ? AND from_id = ? AND to_id = ?").run("subscribes_to",e,n)}r(Dn,"unsubscribe");function Ln(e,n,t){a().prepare("UPDATE edges SET active = ? WHERE type = ? AND from_id = ? AND to_id = ?").run(t?1:0,"subscribes_to",e,n)}r(Ln,"setSubscriptionActive");function vn(e,n){C("spawned_by",e,n,!0)}r(vn,"recordSpawn");function An(e){return a().prepare(`SELECT from_id AS node_id, active, created FROM edges
|
|
32
|
+
WHERE type = 'subscribes_to' AND to_id = ? ORDER BY created`).all(e).map(n=>({node_id:n.node_id,active:n.active===1,created:n.created}))}r(An,"subscribersOf");function I(e){return a().prepare(`SELECT to_id AS node_id, active, created FROM edges
|
|
33
|
+
WHERE type = 'subscribes_to' AND from_id = ? ORDER BY created`).all(e).map(n=>({node_id:n.node_id,active:n.active===1,created:n.created}))}r(I,"subscriptionsOf");function bn(e){const n=new Set([e]),t=[],o=I(e).map(i=>i.node_id);for(;o.length>0;){const i=o.shift();if(!n.has(i)){n.add(i),t.push(i);for(const s of I(i))n.has(s.node_id)||o.push(s.node_id)}}return t}r(bn,"view");function kn(e){return a().prepare(`SELECT 1 FROM edges e JOIN nodes n ON n.node_id = e.to_id
|
|
34
34
|
WHERE e.type = 'subscribes_to' AND e.from_id = ? AND e.active = 1
|
|
35
|
-
AND n.status IN ('active', 'idle') LIMIT 1`).get(e)!==void 0}
|
|
35
|
+
AND n.status IN ('active', 'idle') LIMIT 1`).get(e)!==void 0}r(kn,"hasActiveLiveSubscription");function xn(e){return a().prepare(`SELECT 1 FROM edges e JOIN nodes n ON n.node_id = e.from_id
|
|
36
36
|
WHERE e.type = 'subscribes_to' AND e.to_id = ? AND e.active = 1
|
|
37
|
-
AND n.status IN ('active', 'idle') LIMIT 1`).get(e)!==void 0}
|
|
37
|
+
AND n.status IN ('active', 'idle') LIMIT 1`).get(e)!==void 0}r(xn,"hasLiveSubscriber");function Wn(e){const n=E(e)?.waiting_for;if(n==null)return!1;const t=E(n);return t!==null&&(t.status==="active"||t.status==="idle")}r(Wn,"hasLiveMessageWait");function jn(e,n){a().prepare("UPDATE nodes SET waiting_for = ?, waiting_for_generation = waiting_for_generation + 1 WHERE node_id = ?").run(n,e)}r(jn,"setMessageWait");function Fn(e,n,t){return _(o=>{const i=o.prepare("SELECT waiting_for_generation FROM nodes WHERE node_id = ? AND waiting_for = ?").get(e,n),s=t();return n!==null&&i!==void 0&&o.prepare("UPDATE nodes SET waiting_for = NULL WHERE node_id = ? AND waiting_for = ? AND waiting_for_generation = ?").run(e,n,i.waiting_for_generation),s})}r(Fn,"deliverAndSettleMessageWait");function Hn(e,n,t){return _(o=>{const i=o.prepare(`SELECT waiter.waiting_for, waiter.waiting_for_generation, target.status AS controller_status
|
|
38
38
|
FROM nodes AS waiter LEFT JOIN nodes AS target ON target.node_id = waiter.waiting_for
|
|
39
|
-
WHERE waiter.node_id = ?`).get(e),s=i?.controller_status==="active"||i?.controller_status==="idle";if(i?.waiting_for!==n||s)return null;const d=t();return
|
|
39
|
+
WHERE waiter.node_id = ?`).get(e),s=i?.controller_status==="active"||i?.controller_status==="idle";if(i?.waiting_for!==n||s)return null;const d=t();return o.prepare("UPDATE nodes SET waiting_for = NULL WHERE node_id = ? AND waiting_for = ? AND waiting_for_generation = ?").run(e,n,i.waiting_for_generation),d})}r(Hn,"settleDeadMessageWait");function Mn(e,n,t){return _(o=>{const i=o.prepare("SELECT status, final_report, frozen_at FROM nodes WHERE node_id = ?").get(e);return i===void 0?{kind:"missing"}:n(i)?{kind:"terminal",status:i.status,final_report:i.final_report}:{kind:"ran",result:t()}})}r(Mn,"withFreshTerminalGuard");function R(e){return se(e)}r(R,"hasUnreconciledManagedWorktree");function U(e,n={}){return!["done","dead","canceled"].includes(e.status)||e.pi_pid!==null||e.frozen_at!==null||R(e.node_id)||e.node_id===L()||(e.run_id??null)!==null?!1:n.pastTtl===!0||!["crashed","stranded",null].includes(e.terminal_reason??null)}r(U,"isCollectible");function w(e){if(e.length===0)return[];const n=e.map(()=>"?").join(",");return a().prepare(`SELECT DISTINCT session_id FROM sessions WHERE node_id IN (${n}) AND session_id IS NOT NULL`).all(...e).map(({session_id:o})=>o)}r(w,"nodeConversationIds");function O(e){const n=a(),t=n.prepare("SELECT 1 FROM sessions WHERE session_id = ? LIMIT 1"),o=n.prepare(`SELECT 1 FROM nodes n WHERE n.fork_source_file LIKE '%\\_' || ? || '.jsonl' ESCAPE '\\'
|
|
40
|
+
AND NOT EXISTS (SELECT 1 FROM sessions s WHERE s.node_id = n.node_id) LIMIT 1`);for(const i of e)if(!(t.get(i)!==void 0||o.get(i)!==void 0))try{Z().delete(i)}catch(s){if(!(s instanceof ee))throw s}}r(O,"deleteNodeConversations");function h(e){return{nodeId:e,app:E(e)===null?null:Ee(e)}}r(h,"nodeFiles");function P({nodeId:e,app:n}){n!==null&&A(x(n).nodes,Ne(e,n)),A(G(k(e)),k(e))}r(P,"removeNodeAppTrees");function $({nodeId:e,app:n}){return[...n===null?[]:[ge(e,n)],fe(e)]}r($,"nodeOwnedDirs");function B({nodeId:e,app:n}){if(n!==null)try{q(v(x(n).conversations,e))}catch(t){if(!["ENOENT","ENOTEMPTY"].includes(t.code??""))throw t}}r(B,"removeNodeConversationDir");function T(e){P(e);for(const n of $(e))V(n,{recursive:!0,force:!0});B(e)}r(T,"removeNodeFiles");function Cn(e){if(R(e))return{deleted:!1};const n=h(e),t=w([e]),o=_(i=>(i.prepare("DELETE FROM nodes WHERE node_id = ?").run(e),{deleted:!0}));return O(t),T(n),o}r(Cn,"deleteNode");function In(e){const n=[...new Set(e)];if(n.length===0)return[];const t=n.filter(R);if(t.length>0)throw new Error(`refusing to delete nodes with unreconciled managed worktrees: ${t.join(", ")}`);const o=n.map(h),i=w(n),s=n.map(()=>"?").join(","),d=_(l=>{const c=l.prepare(`SELECT node_id FROM nodes WHERE node_id IN (${s}) ORDER BY created`).all(...n).map(({node_id:m})=>m);return l.prepare(`DELETE FROM nodes WHERE node_id IN (${s})`).run(...n),c});O(i);for(const l of d){const c=o[n.indexOf(l)];D(c,()=>T(c))}return d}r(In,"deleteNodes");function Un(e){const n=e.dryRun??!1,t=e.includeStale??!1,o=Date.now()-e.ttlDays*864e5,i=new Date(o).toISOString(),s=L()??"",d=a(),l=r(u=>J(u)<o,"quiet"),c=r(u=>({node_id:u.node_id,status:u.status,created:u.created}),"toPruned"),m=d.prepare(`SELECT * FROM node_rows
|
|
40
41
|
WHERE status IN ('dead', 'done', 'canceled') AND created < ?
|
|
41
|
-
ORDER BY created`).all(
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
ORDER BY created`).all(i).map(p).filter(u=>U(u,{pastTtl:!0})&&l(u)&&!e.held(u.node_id)).map(c),y=t?d.prepare(`SELECT * FROM node_rows
|
|
43
|
+
WHERE status IN ('active', 'idle') AND created < ?
|
|
44
|
+
ORDER BY created`).all(i).map(p).filter(u=>u.node_id!==s&&!ue(u.pi_pid??null)&&(u.frozen_at??null)===null&&(u.respawn_not_before??null)===null&&u.intent!=="idle-release"&&(u.run_id??null)===null&&!oe(u.node_id)&&!R(u.node_id)&&l(u)&&!e.held(u.node_id)).map(c):[],g=[...m,...y];return n||g.length===0?{pruned:g,dryRun:n}:(z(g,e.removeDirs),{pruned:g,dryRun:n})}r(Un,"pruneNodes");function z(e,n){if(e.length===0)return;const t=e.map(i=>h(i.node_id)),o=w(e.map(i=>i.node_id));if(_(i=>{const s=i.prepare("DELETE FROM nodes WHERE node_id = ?");for(const d of e)s.run(d.node_id)}),O(o),n!==void 0){for(const i of t)D(i,()=>{P(i),B(i)});n(t.flatMap($));return}for(const i of t)D(i,()=>T(i))}r(z,"deletePrunedNodes");function D(e,n){try{n()}catch(t){X({level:"error",event:"canvas.node_files.remove_failed",error:t,fields:{node_id:e.nodeId}})}}r(D,"eachNodeBestEffort");function J(e){let n=0;for(const t of[e.created,e.launched_at,e.last_settled_at,e.finalized_at,e.outcome_at,e.last_activity_at]){if(t==null)continue;const o=Date.parse(t);Number.isFinite(o)&&o>n&&(n=o)}try{const t=K(v(pe(e.node_id),"telemetry.json"),{throwIfNoEntry:!1});t!==void 0&&t.mtimeMs>n&&(n=t.mtimeMs)}catch{}return n}r(J,"lastActivityMs");function Pn(e){const n=e.dryRun??!1,t=we(),o=t.filter(l=>U(l)&&!e.held(l.node_id)),i=t.length-o.length,s=Math.max(0,e.maxNodes-i),d=o.map(l=>({row:l,recency:J(l)})).sort((l,c)=>c.recency-l.recency).slice(s).map(({row:l})=>({node_id:l.node_id,status:l.status,created:l.created}));return n||d.length===0?{pruned:d,dryRun:n}:(z(d),{pruned:d,dryRun:n})}r(Pn,"pruneToLimit");export{Ue as assertRunNotDeleting,$e as canonicalSessionFile,Sn as childrenOf,Rn as claimWarmSpare,nn as clearFinalReportIfMatches,an as clearFrozen,Pe as createNode,Cn as deleteNode,In as deleteNodes,Fn as deliverAndSettleMessageWait,Ye as dueNodeDeadlines,Be as findNodeBySessionFile,en as getFinalReport,E as getNode,ze as getRow,Je as getRowByPane,_n as graphNodes,kn as hasActiveLiveSubscription,Wn as hasLiveMessageWait,xn as hasLiveSubscriber,U as isCollectible,gn as isWarmSpare,J as lastActivityMs,fn as listNodeIdentities,un as listNodeMemoryTargets,we as listNodes,ln as listNodesByProfile,pn as listNodesForSupervision,hn as listResumableRoots,Nn as listWarmSpares,h as nodeFiles,Un as pruneNodes,Pn as pruneToLimit,on as recordLaunch,dn as recordRespawnAttempt,rn as recordSettledTurn,vn as recordSpawn,En as registerWarmSpare,T as removeNodeFiles,Ke as rewriteLocalNodeIdentity,On as rosterEdges,wn as rosterNodes,sn as setFrozen,Xe as setIntent,jn as setMessageWait,qe as setNodeDeadline,tn as setPresence,Qe as setStatus,Ln as setSubscriptionActive,Hn as settleDeadMessageWait,Ve as shiftProfileNodeDeadlines,Tn as subscribe,An as subscribersOf,I as subscriptionsOf,Ze as transitionStatusIntent,mn as unregisterWarmSpare,Dn as unsubscribe,Ge as updateNode,cn as updateNodeTelemetry,bn as view,yn as warmSpareCount,Mn as withFreshTerminalGuard};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Files larger than this are replaced with a tombstone. */
|
|
2
|
+
export declare const CONTEXT_STRIP_FILE_LIMIT_BYTES: number;
|
|
3
|
+
/** The directory tombstone's file name; a directory whose only entry is this file is already stripped. */
|
|
4
|
+
export declare const CONTEXT_TOMBSTONE_NAME = "REMOVED.md";
|
|
5
|
+
export interface StrippedEntry {
|
|
6
|
+
/** Path relative to the context folder. */
|
|
7
|
+
path: string;
|
|
8
|
+
bytes: number;
|
|
9
|
+
reason: string;
|
|
10
|
+
}
|
|
11
|
+
export interface ContextStripResult {
|
|
12
|
+
removed: StrippedEntry[];
|
|
13
|
+
bytes: number;
|
|
14
|
+
}
|
|
15
|
+
/** When this node's context folder was last stripped (epoch ms), or null. */
|
|
16
|
+
export declare function lastContextStripMs(nodeId: string): Promise<number | null>;
|
|
17
|
+
/** Remove bulky content from one node's context folder and record the pass.
|
|
18
|
+
* The caller decides eligibility (finished, quiet, not held) and re-checks it
|
|
19
|
+
* immediately before calling. Per-entry failures are skipped, not thrown. */
|
|
20
|
+
export declare function stripContextDir(nodeId: string, now?: Date): Promise<ContextStripResult>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
var F=Object.defineProperty;var s=(t,e)=>F(t,"name",{value:e,configurable:!0});import{readFile as M,writeFile as R}from"node:fs/promises";import{setImmediate as B}from"node:timers/promises";import{join as p,relative as T}from"node:path";import{appSpace as v}from"../layout.js";import{readdirBeneath as d,removeTreeBeneath as $,statBeneath as E,writeFileBeneath as N}from"../spaces/open-beneath.js";import{appForNode as I,contextDir as C}from"./node-agent-paths.js";import{jobDir as w}from"./paths.js";const x=10*1024*1024,A=new Set(["node_modules",".pnpm-store",".git",".venv","venv","__pycache__","dist","build","target",".next",".turbo"]),L=[".heapsnapshot",".heapprofile",".cpuprofile"],g="REMOVED.md",D="context-stripped.json";async function Y(t){try{const e=JSON.parse(await M(p(w(t),D),"utf8")),n=typeof e.stripped_at=="string"?Date.parse(e.stripped_at):Number.NaN;return Number.isFinite(n)?n:null}catch{return null}}s(Y,"lastContextStripMs");function P(t,e){const n=t.toLowerCase();return n.endsWith(".md")?null:L.some(r=>n.endsWith(r))?"heap or CPU profile":n.endsWith(".har")||n==="har.json"?"browser network capture (HAR)":e>x?`file larger than ${x/(1024*1024)} MB`:null}s(P,"fileReason");function O(t,e,n){const r=(e.bytes/1048576).toFixed(1);return`# Removed by crouter retention
|
|
2
|
+
|
|
3
|
+
\`${e.path}\` (${r} MB, ${e.reason}) was deleted from node ${t}'s context folder on ${n.toISOString()}, after the node had been finished for at least a day. The original content is gone; recreate it if you need it.
|
|
4
|
+
`}s(O,"tombstoneText");function j(t,e){let n=0;const r=[e];for(;r.length>0;){const a=r.pop();for(const o of d(t,a)){const c=p(a,o.name);o.isDirectory()?r.push(c):o.isFile()&&(n+=E(t,c).size)}}return n}s(j,"treeBytes");function k(t,e){const n=d(t,e);return n.length===1&&n[0].name===g}s(k,"isTombstonedDir");async function q(t,e=new Date){const n=I(t),r=v(n).nodes,a=C(t,n),o=[],c=s(async u=>{let f;try{f=d(r,u)}catch{return}for(const m of f){const l=m.name,i=p(u,l);try{if(m.isDirectory()){if(!A.has(l)){await B(),await c(i);continue}if(k(r,i))continue;const S={path:T(a,i),bytes:j(r,i),reason:`${l} directory`};$(r,i),N(r,p(i,g),O(t,S,e)),o.push(S);continue}if(!m.isFile())continue;const h=E(r,i).size,_=P(l,h);if(_===null||h<1024)continue;const b={path:T(a,i),bytes:h,reason:_};N(r,i,O(t,b,e)),o.push(b)}catch{}}},"walk");await c(a);const y=o.reduce((u,f)=>u+f.bytes,0);try{await R(p(w(t),D),`${JSON.stringify({stripped_at:e.toISOString(),bytes:y,removed:o},null,2)}
|
|
5
|
+
`)}catch{}return{removed:o,bytes:y}}s(q,"stripContextDir");export{x as CONTEXT_STRIP_FILE_LIMIT_BYTES,g as CONTEXT_TOMBSTONE_NAME,Y as lastContextStripMs,q as stripContextDir};
|
|
@@ -19,6 +19,7 @@ export interface Cron {
|
|
|
19
19
|
cron_id: string;
|
|
20
20
|
name: string;
|
|
21
21
|
created_by: string | null;
|
|
22
|
+
grantee: string;
|
|
22
23
|
command: string;
|
|
23
24
|
fire_at: string;
|
|
24
25
|
recur: string | null;
|
|
@@ -73,6 +74,7 @@ export interface ArmCronSpec {
|
|
|
73
74
|
cron_id: string;
|
|
74
75
|
name: string;
|
|
75
76
|
created_by: string | null;
|
|
77
|
+
grantee?: string;
|
|
76
78
|
command: string;
|
|
77
79
|
fire_at: string;
|
|
78
80
|
recur: string | null;
|
|
@@ -111,24 +113,12 @@ export declare const CRON_RUN_RING = 20;
|
|
|
111
113
|
export declare function parseCronSink(sinkJson: string): ParsedCronSink;
|
|
112
114
|
/** Render a stored cron sink as the arm-time CLI spec, or null when it has no destination. */
|
|
113
115
|
export declare function cronSinkDisplay(sinkJson: string): string | null;
|
|
114
|
-
/**
|
|
115
|
-
*
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
*
|
|
119
|
-
|
|
120
|
-
* baseline was captured by the same daemon life that is now signaling, so an
|
|
121
|
-
* absent baseline or a failed `ps` probe means "no evidence of reuse" and
|
|
122
|
-
* failing open to the signal is right. A cron lease outlives its daemon: after
|
|
123
|
-
* a SIGKILL or a host reboot, `run_pid` is a number from a dead kernel's pid
|
|
124
|
-
* space that the OS has very likely handed to an unrelated process, and
|
|
125
|
-
* `isPidAlive` cheerfully confirms that stranger. So here the ONLY thing that
|
|
126
|
-
* authorizes a kill is positive proof of sameness — no identity (pre-v23 row,
|
|
127
|
-
* capture failed), no `ps` table (probe failed), no row for the pid (process
|
|
128
|
-
* gone), or a mismatch (reused) all mean: do not signal. The caller settles the
|
|
129
|
-
* lease instead; the worst case is a leaked runaway process, versus SIGTERMing
|
|
130
|
-
* a stranger's process group. */
|
|
131
|
-
export declare function killLeasedCronRun(c: Cron, signal?: NodeJS.Signals): boolean;
|
|
116
|
+
/** Signal only a run whose current pid identity matches its lease. A daemon
|
|
117
|
+
* replacement can leave a pid number that the kernel later reuses. */
|
|
118
|
+
export declare function stopLeasedCronRun(c: Cron, signal?: 'SIGTERM' | 'SIGKILL'): Promise<boolean>;
|
|
119
|
+
/** Start the signal inside the canvas write boundary; log a launcher refusal.
|
|
120
|
+
* Recovery uses the awaitable form so it cannot settle while the run lives. */
|
|
121
|
+
export declare function killLeasedCronRun(c: Cron, signal?: 'SIGTERM' | 'SIGKILL'): boolean;
|
|
132
122
|
/** Positive proof that `run_pid` is STILL the process this lease launched:
|
|
133
123
|
* a stored identity exists, the `ps` probe succeeded, the pid has a row, and
|
|
134
124
|
* its current identity matches. Anything else — including "we could not tell"
|
|
@@ -229,7 +219,9 @@ export declare function dueClockCrons(nowIso: string): Cron[];
|
|
|
229
219
|
*
|
|
230
220
|
* `outOfBand` stamps the lease as a `cron run` (manual verification) so the
|
|
231
221
|
* overlap pass leaves it alone — see `dueOverlapCrons`. */
|
|
232
|
-
export declare function acquireCronRunLease(cron_id: string, leaseOwner: string,
|
|
222
|
+
export declare function acquireCronRunLease(cron_id: string, leaseOwner: string, startedAtIso: string, outOfBand: boolean): boolean;
|
|
223
|
+
/** Attach the launcher's pid only to the run that claimed this lease. */
|
|
224
|
+
export declare function attachCronRunPid(cron_id: string, leaseOwner: string, startedAtIso: string, pid: number): boolean;
|
|
233
225
|
/** What a settling run does with the row's `held` state, applied in the SAME
|
|
234
226
|
* UPDATE that releases the lease — one write boundary, so no tick can observe
|
|
235
227
|
* `run_state='idle'` with the held transition not yet applied.
|
|
@@ -271,7 +263,7 @@ export declare function releaseCronRunLease(cron_id: string, held?: HeldSettle):
|
|
|
271
263
|
* a paused held row keeps its state and unparks via a later poke/backstop
|
|
272
264
|
* after resume (it still receives the stamp, harmlessly). Returns the
|
|
273
265
|
* unparked count. Idempotent and free when nothing is held. */
|
|
274
|
-
export declare function pokeHeldCrons(nowIso: string): number;
|
|
266
|
+
export declare function pokeHeldCrons(nowIso: string, grantee?: string | null): number;
|
|
275
267
|
/** Recurring crons whose NEXT fire has arrived while their previous run is
|
|
276
268
|
* still leased — the overlap-policy pass. One-shots never appear here (a
|
|
277
269
|
* one-shot has exactly one fire, already consumed by its running lease).
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
var f=Object.defineProperty;var
|
|
2
|
-
cron_id, name, created_by, command, fire_at, recur, tz, expires_at,
|
|
1
|
+
var f=Object.defineProperty;var o=(n,r)=>f(n,"name",{value:r,configurable:!0});import{openDb as i,withCanvasWrite as _}from"./db.js";import{capturePidIdentities as p,identitiesMatch as R,killProcessGroup as m}from"./pid.js";import{isProfilePaused as D}from"../profiles/manifest.js";import{stopAppProcess as S}from"../spaces/process.js";import{emitEvent as h}from"../events/emit.js";const O=20;function u(n){return{cron_id:n.cron_id,name:n.name,created_by:n.created_by??null,grantee:n.grantee,command:n.command,fire_at:n.fire_at,recur:n.recur??null,tz:n.tz??null,expires_at:n.expires_at??null,anchor_node:n.anchor_node??null,cancel_on_wake:Number(n.cancel_on_wake)!==0,cwd:n.cwd,env_json:n.env_json??null,profile:n.profile??null,scope:n.scope,run_timeout_s:Number(n.run_timeout_s),overlap:n.overlap,on_output:n.on_output,sink:n.sink,tier:n.tier,last_output_hash:n.last_output_hash??null,held:Number(n.held)!==0,last_poke_at:n.last_poke_at??null,state:n.state,run_state:n.run_state,run_pid:n.run_pid??null,run_pid_identity:n.run_pid_identity??null,run_started_at:n.run_started_at??null,run_lease_owner:n.run_lease_owner??null,run_out_of_band:Number(n.run_out_of_band)!==0,created:n.created,updated:n.updated}}o(u,"cronFrom");function l(n){try{const r=JSON.parse(n);if(typeof r.node=="string")return{kind:"node",node:r.node};if(typeof r.spawn=="string")return{kind:"spawn",spawn:r.spawn};if(r.human===!0)return{kind:"human"}}catch{}return null}o(l,"parseCronSink");function W(n){const r=l(n);if(r===null)return null;switch(r.kind){case"node":return`node:${r.node}`;case"spawn":return`spawn:${r.spawn}`;case"human":return"human"}}o(W,"cronSinkDisplay");async function N(n,r="SIGTERM"){if(!c(n))return!1;if(process.platform!=="linux")return m(n.run_pid,r),!0;try{return await S(n.run_pid,r,n.anchor_node??void 0),!0}catch(e){if(!c(n))return!1;throw e}}o(N,"stopLeasedCronRun");function d(n,r="SIGTERM"){return c(n)?(N(n,r).catch(e=>{h({level:"error",event:"cron.run.stop_failed",error:e,fields:{cron_id:n.cron_id,pid:n.run_pid}})}),!0):!1}o(d,"killLeasedCronRun");function c(n){const r=n.run_pid;if(r==null||n.run_pid_identity==null)return!1;const e=p([r]);if(e===null)return!1;const t=e.get(r);return t===void 0?!1:R(t,n.run_pid_identity)}o(c,"verifyLeasedCronRun");function H(n){return _(r=>{const e=[];if(n.cancel_on_wake&&n.anchor_node!==null){const t=r.prepare("SELECT * FROM crons WHERE anchor_node = ? AND cancel_on_wake = 1").all(n.anchor_node).map(u);for(const a of t)a.run_state==="running"&&d(a),r.prepare("DELETE FROM crons WHERE cron_id = ?").run(a.cron_id),e.push(a.cron_id)}return L(r,n),{cron_id:n.cron_id,replaced:e}})}o(H,"armCron");function L(n,r){const e=new Date().toISOString();n.prepare(`INSERT INTO crons (
|
|
2
|
+
cron_id, name, created_by, grantee, command, fire_at, recur, tz, expires_at,
|
|
3
3
|
anchor_node, cancel_on_wake, cwd, env_json, profile, scope,
|
|
4
4
|
run_timeout_s, overlap, on_output, sink, tier, created, updated
|
|
5
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(
|
|
5
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(r.cron_id,r.name,r.created_by,r.grantee??"app:terminal",r.command,r.fire_at,r.recur,r.tz,r.expires_at,r.anchor_node,r.cancel_on_wake?1:0,r.cwd,r.env_json,r.profile,r.scope,r.run_timeout_s,r.overlap,r.on_output,r.sink,r.tier,e,e)}o(L,"insertCron");function F(n){const r=i().prepare("SELECT * FROM crons WHERE cron_id = ?").get(n);return r===void 0?null:u(r)}o(F,"getCron");function M(n){const r=i();let e;return"profile"in n?e=r.prepare("SELECT * FROM crons WHERE scope = 'profile' AND profile = ? ORDER BY fire_at").all(n.profile):"global"in n?e=r.prepare("SELECT * FROM crons WHERE scope = 'global' ORDER BY fire_at").all():e=r.prepare("SELECT * FROM crons ORDER BY fire_at").all(),e.map(u)}o(M,"listCrons");function v(n,r){return _(e=>{const t=e.prepare("SELECT * FROM crons WHERE cron_id = ?").get(n);if(t===void 0)return!1;const a=u(t);return a.run_state==="running"&&r?.preserveRunningProcess!==!0&&d(a),e.prepare("DELETE FROM crons WHERE cron_id = ?").run(n),!0})}o(v,"cancelCron");function E(n,r){const e=[...new Set(r)];return e.length===0?{sql:"profile = ?",params:[n]}:{sql:`profile = ? OR anchor_node IN (${e.map(()=>"?").join(",")})`,params:[n,...e]}}o(E,"profileCronWhere");function I(n,r){const e=E(n,r);return i().prepare(`SELECT cron_id FROM crons WHERE ${e.sql} ORDER BY created, cron_id`).all(...e.params).map(({cron_id:t})=>t)}o(I,"cronIdsForProfileDeletion");function U(n,r){return _(e=>{const t=E(n,r),a=e.prepare(`SELECT * FROM crons WHERE ${t.sql} ORDER BY created, cron_id`).all(...t.params).map(u);for(const s of a)s.run_state==="running"&&d(s);return e.prepare(`DELETE FROM crons WHERE ${t.sql}`).run(...t.params),a.map(({cron_id:s})=>s)})}o(U,"deleteCronsForProfile");function P(n){return i().prepare("SELECT cron_id FROM crons WHERE profile = ? ORDER BY created, cron_id").all(n).map(({cron_id:r})=>r)}o(P,"cronIdsForProfileDetach");function y(n){return _(r=>{const e=r.prepare("SELECT cron_id FROM crons WHERE profile = ? ORDER BY created, cron_id").all(n).map(({cron_id:t})=>t);return e.length>0&&r.prepare("UPDATE crons SET profile = NULL, scope = 'global', updated = ? WHERE profile = ?").run(new Date().toISOString(),n),e})}o(y,"globalizeCronsForProfile");function b(n){return i().prepare("DELETE FROM crons WHERE cron_id = ?").run(n).changes>0}o(b,"consumeCron");function B(n,r){return i().prepare("UPDATE crons SET state = ?, updated = ? WHERE cron_id = ?").run(r,new Date().toISOString(),n).changes>0}o(B,"setCronState");function Y(n,r){i().prepare("UPDATE crons SET last_output_hash = ?, updated = ? WHERE cron_id = ?").run(r,new Date().toISOString(),n)}o(Y,"setCronLastOutputHash");function $(n){const r=i().prepare(`SELECT anchor_node, cancel_on_wake, sink
|
|
6
6
|
FROM crons
|
|
7
7
|
WHERE (anchor_node = ? AND cancel_on_wake = 1 AND state = 'active')
|
|
8
8
|
OR (
|
|
@@ -11,24 +11,26 @@ var f=Object.defineProperty;var t=(e,n)=>f(e,"name",{value:n,configurable:!0});i
|
|
|
11
11
|
run_state = 'running'
|
|
12
12
|
OR (run_state = 'idle' AND state = 'active' AND (expires_at IS NULL OR expires_at > ?))
|
|
13
13
|
)
|
|
14
|
-
)`).all(
|
|
14
|
+
)`).all(n,new Date().toISOString());for(const e of r){if(e.anchor_node===n&&Number(e.cancel_on_wake)!==0)return!0;const t=l(e.sink);if(t?.kind==="node"&&t.node===n)return!0}return!1}o($,"hasPendingCronWake");function q(n){return _(r=>{const e=r.prepare("SELECT * FROM crons WHERE anchor_node = ? AND cancel_on_wake = 1").all(n).map(u);for(const t of e)t.run_state==="running"&&d(t),r.prepare("DELETE FROM crons WHERE cron_id = ?").run(t.cron_id);return e.map(t=>t.cron_id)})}o(q,"cancelCronsOnWake");function j(n,r){i().prepare("UPDATE crons SET fire_at = ?, updated = ? WHERE cron_id = ?").run(r,new Date().toISOString(),n)}o(j,"advanceCron");function z(n){return i().prepare(`SELECT * FROM crons
|
|
15
15
|
WHERE state = 'active' AND run_state = 'idle' AND fire_at <= ?
|
|
16
|
-
ORDER BY fire_at, created, cron_id`).all(
|
|
17
|
-
SET run_state = 'running', run_started_at = ?, run_pid =
|
|
16
|
+
ORDER BY fire_at, created, cron_id`).all(n).map(u).filter(r=>!D(r.profile))}o(z,"dueClockCrons");function G(n,r,e,t){const a=i().prepare(`UPDATE crons
|
|
17
|
+
SET run_state = 'running', run_started_at = ?, run_pid = NULL, run_pid_identity = NULL,
|
|
18
18
|
run_lease_owner = ?, run_out_of_band = ?, updated = ?
|
|
19
|
-
WHERE cron_id = ? AND run_state = 'idle'`).run(
|
|
19
|
+
WHERE cron_id = ? AND run_state = 'idle'`).run(e,r,t?1:0,new Date().toISOString(),n);return Number(a.changes)>0}o(G,"acquireCronRunLease");function V(n,r,e,t){const a=p([t])?.get(t)??null,s=i().prepare(`UPDATE crons SET run_pid = ?, run_pid_identity = ?, updated = ?
|
|
20
|
+
WHERE cron_id = ? AND run_state = 'running' AND run_lease_owner = ?
|
|
21
|
+
AND run_started_at = ? AND run_pid IS NULL`).run(t,a,new Date().toISOString(),n,r,e);return Number(s.changes)>0}o(V,"attachCronRunPid");function J(n,r){let e="";const t=[];r!==void 0&&(r.kind==="clear"?e=", held = 0":r.kind==="park"?(e=r.fireAt!==void 0?", held = 1, fire_at = ?":", held = 1",r.fireAt!==void 0&&t.push(r.fireAt)):(e=", held = 0, fire_at = ?",t.push(r.nowIso))),i().prepare(`UPDATE crons
|
|
20
22
|
SET run_state = 'idle', run_started_at = NULL, run_pid = NULL, run_pid_identity = NULL,
|
|
21
|
-
run_lease_owner = NULL, run_out_of_band = 0, updated = ?${
|
|
22
|
-
WHERE cron_id = ?`).run(new Date().toISOString(),...
|
|
23
|
+
run_lease_owner = NULL, run_out_of_band = 0, updated = ?${e}
|
|
24
|
+
WHERE cron_id = ?`).run(new Date().toISOString(),...t,n)}o(J,"releaseCronRunLease");function K(n,r=null){return _(e=>{const t=r===null?"":" AND grantee = ?",a=r===null?[]:[r];e.prepare(`UPDATE crons SET last_poke_at = ? WHERE 1 = 1${t}`).run(n,...a);const s=e.prepare(`UPDATE crons SET fire_at = ?, held = 0, updated = ? WHERE held = 1 AND state = 'active' AND run_state = 'idle'${t}`).run(n,n,...a);return Number(s.changes)})}o(K,"pokeHeldCrons");function Q(n){return i().prepare(`SELECT * FROM crons
|
|
23
25
|
WHERE state = 'active' AND run_state = 'running' AND run_out_of_band = 0
|
|
24
26
|
AND recur IS NOT NULL AND fire_at <= ?
|
|
25
|
-
ORDER BY fire_at, created, cron_id`).all(
|
|
27
|
+
ORDER BY fire_at, created, cron_id`).all(n).map(u)}o(Q,"dueOverlapCrons");function X(n){return i().prepare(`SELECT * FROM crons
|
|
26
28
|
WHERE expires_at IS NOT NULL AND expires_at <= ? AND run_state = 'idle'
|
|
27
|
-
ORDER BY expires_at`).all(
|
|
29
|
+
ORDER BY expires_at`).all(n).map(u)}o(X,"expiredIdleCrons");function Z(n){return i().prepare("SELECT * FROM cron_runs WHERE cron_id = ? ORDER BY started DESC, run_id DESC").all(n).map(r=>({run_id:r.run_id,cron_id:r.cron_id,started:r.started,finished:r.finished,duration_ms:Number(r.duration_ms),exit_code:r.exit_code??null,stdout_head:r.stdout_head??null,stderr_head:r.stderr_head??null,delivered:r.delivered??null}))}o(Z,"listCronRuns");function nn(){return i().prepare("SELECT * FROM crons WHERE run_state = 'running'").all().map(u)}o(nn,"runningCrons");function C(n,r){return n.prepare("SELECT 1 FROM crons WHERE cron_id = ?").get(r.cron_id)===void 0?!1:(n.prepare(`INSERT INTO cron_runs (
|
|
28
30
|
run_id, cron_id, started, finished, duration_ms, exit_code,
|
|
29
31
|
stdout_head, stderr_head, delivered
|
|
30
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(
|
|
32
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(r.run_id,r.cron_id,r.started,r.finished,r.duration_ms,r.exit_code,r.stdout_head,r.stderr_head,r.delivered),n.prepare(`DELETE FROM cron_runs
|
|
31
33
|
WHERE cron_id = ? AND run_id NOT IN (
|
|
32
34
|
SELECT run_id FROM cron_runs WHERE cron_id = ?
|
|
33
35
|
ORDER BY started DESC, run_id DESC LIMIT ?
|
|
34
|
-
)`).run(
|
|
36
|
+
)`).run(r.cron_id,r.cron_id,O),!0)}o(C,"recordCronRunLocked");function rn(n){return _(r=>C(r,n))}o(rn,"recordCronRun");export{O as CRON_RUN_RING,G as acquireCronRunLease,j as advanceCron,H as armCron,V as attachCronRunPid,v as cancelCron,q as cancelCronsOnWake,b as consumeCron,I as cronIdsForProfileDeletion,P as cronIdsForProfileDetach,W as cronSinkDisplay,U as deleteCronsForProfile,z as dueClockCrons,Q as dueOverlapCrons,X as expiredIdleCrons,F as getCron,y as globalizeCronsForProfile,$ as hasPendingCronWake,d as killLeasedCronRun,Z as listCronRuns,M as listCrons,l as parseCronSink,K as pokeHeldCrons,rn as recordCronRun,C as recordCronRunLocked,J as releaseCronRunLease,nn as runningCrons,Y as setCronLastOutputHash,B as setCronState,N as stopLeasedCronRun,c as verifyLeasedCronRun};
|
package/dist/core/canvas/db.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var s=Object.defineProperty;var r=(t,e)=>s(t,"name",{value:e,configurable:!0});import{DatabaseSync as i}from"node:sqlite";import{appendFileSync as a}from"node:fs";import{canvasDbPath as c,ensureHome as p}from"./paths.js";import{migrate as
|
|
2
|
-
`;a(t,e)}catch{}}r(
|
|
1
|
+
var s=Object.defineProperty;var r=(t,e)=>s(t,"name",{value:e,configurable:!0});import{DatabaseSync as i}from"node:sqlite";import{appendFileSync as a}from"node:fs";import{canvasDbPath as c,ensureHome as p}from"./paths.js";import{initializeEmptyLayout as u}from"../layout.js";import{migrate as R,MIGRATIONS as b}from"./migrations.js";const o=new Map;function f(){const t=process.env.CRTR_DB_OPEN_LEDGER;if(t)try{const e=`${new Date().toISOString()} ${process.pid} ${process.argv[1]??"<unknown>"}
|
|
2
|
+
`;a(t,e)}catch{}}r(f,"recordOpenLedger");function m(){const t=c(),e=o.get(t);if(e)return e;u(),p(),f();const n=new i(t);return n.exec("PRAGMA busy_timeout = 5000;"),n.exec("PRAGMA journal_mode = WAL;"),n.exec("PRAGMA foreign_keys = ON;"),o.set(t,n),n}r(m,"openDb");function h(t){const e=m();if(e.isTransaction)return t(e);e.exec("BEGIN IMMEDIATE");try{const n=t(e);return e.exec("COMMIT"),n}catch(n){try{e.exec("ROLLBACK")}catch{}throw n}}r(h,"withCanvasWrite");function M(){const t=c(),e=o.get(t);e&&(e.close(),o.delete(t))}r(M,"closeDb");export{b as MIGRATIONS,M as closeDb,R as migrate,m as openDb,h as withCanvasWrite};
|
|
@@ -67,7 +67,10 @@ export type DeliverySettlement = {
|
|
|
67
67
|
};
|
|
68
68
|
/** The one execution/attempt/owner fence for node mail and external actions. */
|
|
69
69
|
export declare function settleDelivery(deliveryId: string, attempts: number, claimOwner: string, settlement: DeliverySettlement | ProcessDeliverySettlement, now?: number): boolean;
|
|
70
|
-
/** Broker acknowledgement additionally checks the
|
|
70
|
+
/** Broker acknowledgement additionally checks that the execution is live before the per-row fence.
|
|
71
|
+
* Refresh intent does not refuse it: a yielding turn still acknowledges the mail
|
|
72
|
+
* its conversation consumed, and the watcher withholds the queued mail the
|
|
73
|
+
* refresh abort discarded so the replacement execution replays only that. */
|
|
71
74
|
export declare function acknowledgeNodeMail(nodeId: string, executionId: string, deliveries: Array<{
|
|
72
75
|
deliveryId: string;
|
|
73
76
|
attempts: number;
|
|
@@ -13,7 +13,7 @@ var w=Object.defineProperty;var o=(e,n)=>w(e,"name",{value:n,configurable:!0});i
|
|
|
13
13
|
WHERE destination_kind = 'node_inbox' AND destination_id = ? AND wake = 1 AND state = 'pending' AND canceled_at IS NULL`).run(n,d,d,e),O(r,e,n,1,i)})}o(q,"claimKickoffMail");function C(e){return e.state==="accepted"?{state:"acknowledged"}:e}o(C,"normalizedSettlement");function h(e,n,d,r,i=Date.now()){const _=C(r),s=_.state==="pending"||_.state==="permanent_failed"?JSON.stringify(_.failure):null,c=_.state==="released"?"pending":_.state,t=_.state==="pending"?_.nextAttemptAt:c==="pending"?i:null;return N(a=>Number(a.prepare(`UPDATE deliveries
|
|
14
14
|
SET state = ?, next_attempt_at = ?, claimed_at = NULL, claim_owner = NULL,
|
|
15
15
|
acknowledged_at = ?, failed_at = ?, last_failure_json = ?, updated_at = ?
|
|
16
|
-
WHERE delivery_id = ? AND state = 'handed_off' AND attempts = ? AND claim_owner = ?`).run(c,t,c==="acknowledged"?i:null,c==="permanent_failed"?i:null,s,i,e,n,d).changes)===1)}o(h,"settleDelivery");function $(e,n,d,r=Date.now()){return N(i=>y(i,e,n,!
|
|
16
|
+
WHERE delivery_id = ? AND state = 'handed_off' AND attempts = ? AND claim_owner = ?`).run(c,t,c==="acknowledged"?i:null,c==="permanent_failed"?i:null,s,i,e,n,d).changes)===1)}o(h,"settleDelivery");function $(e,n,d,r=Date.now()){return N(i=>y(i,e,n,!1)?{action:"acknowledged",results:d.map(s=>{const c=i.prepare("SELECT 1 FROM deliveries WHERE delivery_id = ? AND destination_kind = 'node_inbox' AND destination_id = ?").get(s.deliveryId,e)!==void 0;return{deliveryId:s.deliveryId,outcome:c&&h(s.deliveryId,s.attempts,n,{state:s.disposition},r)?s.disposition:"stale"}})}:{action:"hold",results:[]})}o($,"acknowledgeNodeMail");function J(e){const n=u().prepare(`SELECT m.body_json FROM deliveries d JOIN messages m ON m.message_id = d.message_id
|
|
17
17
|
WHERE d.delivery_id = ? AND d.destination_kind = 'external_action'`).get(e);return n===void 0||n.body_json===null?null:JSON.parse(n.body_json)}o(J,"messageBodyForDelivery");function K(e){const n=u().prepare("SELECT * FROM deliveries WHERE destination_kind = 'external_action' AND idempotency_key = ?").get(e);return n===void 0?null:g(n)}o(K,"readExternalActionDelivery");function P(e){return u().prepare(`SELECT * FROM deliveries
|
|
18
18
|
WHERE destination_kind = 'external_action' AND state = 'pending' AND canceled_at IS NULL AND next_attempt_at <= ?
|
|
19
19
|
ORDER BY next_attempt_at, created_at, delivery_id`).all(e).map(g)}o(P,"dueExternalActionDeliveries");function G(e,n,d){return N(r=>{const i=r.prepare(`UPDATE deliveries SET state = 'handed_off', attempts = attempts + 1, claimed_at = ?, claim_owner = ?, updated_at = ?
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var m=Object.defineProperty;var o=(e,t)=>m(e,"name",{value:t,configurable:!0});import{randomUUID as g}from"node:crypto";import{openDb as _,withCanvasWrite as a}from"./db.js";import{capturePidIdentities as f,captureLivenessSnapshot as h,identitiesMatch as A,isBootScopedIdentity as T,isLegacyTicksIdentity as D}from"./pid.js";import{existsSync as L,readFileSync as y}from"node:fs";import{LAUNCHER_SOCKET as S}from"../../launcher/spec.js";import{forgetNodeToken as U,mintNodeToken as R,revokeNodeTokens as p}from"./node-tokens.js";function x(){return new Date().toISOString()}o(x,"now");function H(e){return{executionId:e.execution_id,nodeId:e.node_id,daemonEpoch:e.daemon_epoch??null,pid:e.pid??null,processIdentity:e.process_identity??null,state:e.state,startedAt:e.started_at,endedAt:e.ended_at??null,exitReason:e.exit_reason??null}}o(H,"hydrate");function M(e){const t=_().prepare("SELECT * FROM executions WHERE node_id = ? AND state != 'exited'").get(e);return t===void 0?null:H(t)}o(M,"liveExecutionForNode");function b(e,t){return a(n=>{const i=x();n.prepare("UPDATE executions SET state = 'exited', ended_at = ?, exit_reason = 'superseded' WHERE node_id = ? AND state != 'exited'").run(i,e),p(n,"node_id",e,i);const r=g();return n.prepare("INSERT INTO executions (execution_id, node_id, daemon_epoch, pid, process_identity, state, started_at, ended_at, exit_reason) VALUES (?, ?, ?, NULL, NULL, 'launching', ?, NULL, NULL)").run(r,e,t.daemonEpoch,i),R(n,r,e,i),r})}o(b,"beginExecution");function $(e,t,n){const i=f([n])?.get(n)??null;return a(r=>{if(r.prepare("UPDATE executions SET pid = ?, process_identity = ?, state = 'running' WHERE execution_id = ? AND node_id = ? AND state = 'launching'").run(n,i,e,t).changes>0)return"recorded";const d=r.prepare("SELECT pid FROM executions WHERE execution_id = ? AND node_id = ? AND state = 'running'").get(e,t);if(d?.pid===n)return"recorded";if(process.platform==="linux"&&L(S)&&d?.pid!=null){const l=h(),c=[d.pid];for(let u=0;u<c.length;u++)c.push(...l?.childrenOf.get(c[u])??[]);if(c.includes(n))return"recorded";for(const u of c)try{const N=y(`/proc/${u}/status`,"utf8"),E=/^NSpid:\s*(.+)$/m.exec(N)?.[1]?.trim().split(/\s+/).map(Number)??[];if(E.length>1&&E.at(-1)===n)return"recorded"}catch{}}return"shutdown"})}o($,"recordExecutionPid");function O(e,t){return U(e),a(n=>{const i=x(),r=n.prepare("UPDATE executions SET state = 'exited', ended_at = ?, exit_reason = ? WHERE execution_id = ? AND state != 'exited'").run(i,t.reason,e);return p(n,"broker_process_id",e,i),Number(r.changes)===1})}o(O,"endExecution");function B(e,t){return O(e,t)}o(B,"abortExecution");function K(e,t){return a(n=>{const i=x(),r=n.prepare("UPDATE executions SET state = 'exited', ended_at = ?, exit_reason = ? WHERE node_id = ? AND state != 'exited'").run(i,t.reason,e);return p(n,"node_id",e,i),Number(r.changes)===1})}o(K,"endLiveExecution");function V(e=t=>f([t])?.get(t)){const t=_(),n=t.prepare("SELECT execution_id, pid, process_identity FROM executions WHERE state = 'running' AND pid IS NOT NULL AND process_identity IS NOT NULL").all(),i=t.prepare("UPDATE executions SET process_identity = ? WHERE execution_id = ? AND pid = ? AND process_identity = ? AND state = 'running'"),r=[];for(const s of n){if(!D(s.process_identity))continue;const d=e(s.pid);d===void 0||!T(d)||!A(d,s.process_identity)||i.run(d,s.execution_id,s.pid,s.process_identity).changes>0&&r.push(s.execution_id)}return{migrated:r}}o(V,"migrateLegacyExecutionIdentities");export{B as abortExecution,b as beginExecution,O as endExecution,K as endLiveExecution,M as liveExecutionForNode,V as migrateLegacyExecutionIdentities,$ as recordExecutionPid};
|
|
@@ -111,7 +111,8 @@ export interface ResolvedRef {
|
|
|
111
111
|
path: string | null;
|
|
112
112
|
}
|
|
113
113
|
/** Resolve a `<node-id>:<relpath>` handle to its content. Returns null when the
|
|
114
|
-
* node is unknown or the artifact
|
|
114
|
+
* node is unknown or the artifact is not a file in the node's own folder
|
|
115
|
+
* (absent, or on Linux reached through a symlink). Throws on path traversal. */
|
|
115
116
|
export declare function resolveRef(ref: string): ResolvedRef | null;
|
|
116
117
|
/** Enumerate one node's artifacts (for `history show`). */
|
|
117
118
|
export declare function nodeArtifacts(nodeId: string, types?: HistorySource[]): HistoryArtifact[];
|