@north-light/crouter 0.3.353 → 0.3.354
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/dist/api/client.d.ts +35 -25
- package/dist/api/client.js +2 -2
- package/dist/api/dto/broker-ops.d.ts +2 -36
- package/dist/api/dto/canvas.d.ts +8 -13
- package/dist/api/dto/config.d.ts +4 -0
- package/dist/api/dto/delivery.d.ts +61 -0
- package/dist/api/dto/docs.d.ts +133 -0
- package/dist/api/dto/docs.js +1 -0
- package/dist/api/dto/health.d.ts +26 -79
- package/dist/api/dto/node-outcomes.d.ts +1 -3
- package/dist/api/dto/nodes.d.ts +5 -26
- package/dist/api/dto/objects.d.ts +167 -0
- package/dist/api/dto/objects.js +1 -0
- package/dist/api/dto/profiles.d.ts +14 -8
- package/dist/api/dto/reports.d.ts +9 -7
- package/dist/api/dto/reviews.d.ts +9 -3
- package/dist/api/dto/worktree.d.ts +1 -1
- package/dist/api/index.d.ts +0 -1
- package/dist/api/index.js +1 -1
- package/dist/api/routes.d.ts +14 -12
- package/dist/api/routes.js +1 -1
- package/dist/build-root.js +1 -1
- package/dist/builtin-memory/00-runtime-base/00-authoring.md +10 -5
- package/dist/builtin-memory/04-orchestration-kernel.md +7 -7
- package/dist/builtin-memory/05-kinds/advisor/01-orchestrator.md +1 -1
- package/dist/builtin-memory/05-kinds/explore/00-base.md +2 -2
- package/dist/builtin-memory/05-kinds/explore/01-orchestrator.md +2 -2
- package/dist/builtin-memory/crouter-concepts/INDEX.md +2 -2
- package/dist/builtin-memory/crouter-concepts/lifecycle-and-wakes.md +1 -1
- package/dist/builtin-memory/crouter-concepts/memory.md +15 -15
- package/dist/builtin-memory/crouter-concepts/nodes-and-the-canvas.md +1 -1
- package/dist/builtin-memory/crouter-concepts/profiles-kinds-and-modes.md +5 -5
- package/dist/builtin-memory/crouter-concepts/scopes-and-trust.md +1 -1
- package/dist/builtin-memory/crouter-concepts/why-a-daemon.md +1 -1
- package/dist/builtin-memory/crouter-sdk/INDEX.md +2 -2
- package/dist/builtin-memory/crouter-sdk/README.md +5 -6
- package/dist/builtin-memory/crouter-sdk/errors.md +0 -13
- package/dist/builtin-memory/crouter-sdk/guides/README.md +0 -1
- package/dist/builtin-memory/crouter-sdk/guides/event-driven-assistant.md +2 -2
- package/dist/builtin-memory/crouter-sdk/nodes.md +0 -2
- package/dist/builtin-memory/crouter-sdk/resources.md +0 -1
- package/dist/builtin-memory/explore/exploration-doc.md +4 -4
- package/dist/builtin-memory/insights/capture.md +6 -6
- package/dist/builtin-memory/insights/init.md +14 -14
- package/dist/builtin-memory/internal/INDEX.md +4 -4
- package/dist/builtin-memory/internal/agent-shaping.md +20 -20
- package/dist/builtin-memory/internal/examples/imessage-assistant.md +2 -2
- package/dist/builtin-memory/internal/marketplaces.md +2 -2
- package/dist/builtin-memory/internal/memory-loading.md +31 -30
- package/dist/builtin-memory/internal/nodes-and-canvas.md +1 -1
- package/dist/builtin-memory/internal/plugins.md +16 -14
- package/dist/builtin-memory/internal/storage-tiers.md +4 -4
- package/dist/builtin-memory/memory-read-orientation.md +1 -1
- package/dist/builtin-pi-packages/pi-crtr-extensions/extensions/memory-slash-commands.ts +32 -40
- package/dist/clients/attach/input/controller.js +1 -1
- package/dist/clients/attach/input/ref-autocomplete.js +1 -1
- package/dist/clients/attach/input/titled-editor.js +1 -1
- package/dist/clients/attach/render/chat-view.js +1 -1
- package/dist/clients/attach/render/crtr-output.d.ts +1 -2
- package/dist/clients/attach/render/crtr-output.js +17 -17
- package/dist/clients/attach/render/group-activity.d.ts +8 -8
- package/dist/clients/attach/render/group-activity.js +2 -2
- package/dist/clients/attach/render/group-recap.js +1 -1
- package/dist/clients/attach/render/tool-calls.d.ts +1 -1
- package/dist/clients/attach/session/profile-files.js +1 -1
- package/dist/clients/attach/slash/dispatch.js +1 -1
- package/dist/clients/attach/viewer.js +806 -1553
- package/dist/commands/api-client.d.ts +2 -0
- package/dist/commands/api-client.js +3 -3
- package/dist/commands/canvas/edges.d.ts +2 -0
- package/dist/commands/canvas/edges.js +2 -0
- package/dist/commands/canvas/list.d.ts +4 -0
- package/dist/commands/canvas/list.js +3 -0
- package/dist/commands/canvas/read.d.ts +8 -0
- package/dist/commands/canvas/read.js +5 -0
- package/dist/commands/canvas/search.d.ts +2 -0
- package/dist/commands/canvas/search.js +3 -0
- package/dist/commands/canvas/unwatch.d.ts +2 -0
- package/dist/commands/canvas/unwatch.js +1 -0
- package/dist/commands/canvas/watch.d.ts +3 -0
- package/dist/commands/canvas/watch.js +1 -0
- package/dist/commands/canvas-analytics.js +1 -1
- package/dist/commands/canvas-history/grep.js +4 -4
- package/dist/commands/canvas-history/read.js +2 -2
- package/dist/commands/canvas-history/search.js +7 -7
- package/dist/commands/canvas-history/shared.d.ts +0 -1
- package/dist/commands/canvas-history/shared.js +1 -1
- package/dist/commands/canvas-history/stats.js +2 -2
- package/dist/commands/canvas-history.js +1 -1
- package/dist/commands/canvas.js +1 -1
- package/dist/commands/doc/delete.d.ts +2 -0
- package/dist/commands/doc/delete.js +1 -0
- package/dist/commands/doc/edit.d.ts +2 -0
- package/dist/commands/doc/edit.js +1 -0
- package/dist/commands/doc/history.d.ts +2 -0
- package/dist/commands/doc/history.js +2 -0
- package/dist/commands/doc/lint.d.ts +2 -0
- package/dist/commands/doc/lint.js +2 -0
- package/dist/commands/doc/list.d.ts +2 -0
- package/dist/commands/doc/list.js +1 -0
- package/dist/commands/doc/move.d.ts +2 -0
- package/dist/commands/doc/move.js +1 -0
- package/dist/commands/doc/read.d.ts +2 -0
- package/dist/commands/doc/read.js +1 -0
- package/dist/commands/doc/shared.d.ts +25 -0
- package/dist/commands/doc/shared.js +2 -0
- package/dist/commands/doc/write.d.ts +2 -0
- package/dist/commands/doc/write.js +1 -0
- package/dist/commands/{memory.d.ts → doc.d.ts} +1 -1
- package/dist/commands/doc.js +1 -0
- package/dist/commands/human/review.js +1 -1
- package/dist/commands/node/bash.js +2 -2
- package/dist/commands/node/create.js +1 -1
- package/dist/commands/node/inspect.js +10 -10
- package/dist/commands/node/lifecycle.js +2 -2
- package/dist/commands/node/outcome.js +1 -1
- package/dist/commands/node/subscription.js +1 -1
- package/dist/commands/node-context.js +2 -2
- package/dist/commands/pkg/browse/catalog.js +1 -1
- package/dist/commands/pkg/browse/doc-view.js +1 -1
- package/dist/commands/pkg/browse/model.d.ts +9 -17
- package/dist/commands/pkg/plugin-inspect.js +1 -1
- package/dist/commands/pkg/plugin-manage.d.ts +4 -8
- package/dist/commands/pkg/plugin-manage.js +15 -17
- package/dist/commands/profile/list.js +1 -1
- package/dist/commands/profile/new.js +1 -1
- package/dist/commands/profile/project.js +1 -1
- package/dist/commands/profile/show.js +1 -1
- package/dist/commands/push.js +3 -3
- package/dist/commands/sys/config.js +1 -1
- package/dist/commands/sys/context/admin/actions.d.ts +18 -43
- package/dist/commands/sys/context/admin/actions.js +1 -2
- package/dist/commands/sys/context/admin/detail-panel.d.ts +17 -25
- package/dist/commands/sys/context/admin/detail-panel.js +2 -1
- package/dist/commands/sys/context/admin/docs-panel.d.ts +7 -6
- package/dist/commands/sys/context/admin/docs-panel.js +1 -1
- package/dist/commands/sys/context/admin/list-view.d.ts +12 -12
- package/dist/commands/sys/context/admin/list-view.js +1 -1
- package/dist/commands/sys/context/admin/model.d.ts +96 -69
- package/dist/commands/sys/context/admin/model.js +1 -1
- package/dist/commands/sys/context/admin/rail-panel.d.ts +7 -5
- package/dist/commands/sys/context/admin/rail-panel.js +1 -1
- package/dist/commands/sys/context/admin/read-view.d.ts +10 -14
- package/dist/commands/sys/context/admin/read-view.js +1 -2
- package/dist/commands/sys/context/admin/shell.d.ts +26 -31
- package/dist/commands/sys/context/admin/shell.js +1 -1
- package/dist/commands/sys/context/admin.js +2 -2
- package/dist/commands/sys/context/doc.js +2 -3
- package/dist/commands/sys/context/expose.js +2 -2
- package/dist/commands/sys/context/prompt-review.js +4 -4
- package/dist/commands/sys/context/resolve.d.ts +92 -65
- package/dist/commands/sys/context/resolve.js +7 -9
- package/dist/commands/sys/context.js +1 -1
- package/dist/commands/sys/doctor.js +1 -1
- package/dist/commands/sys/migrate.js +1 -1
- package/dist/commands/sys/panels/profiles-panel.d.ts +3 -1
- package/dist/commands/sys/panels/profiles-panel.js +1 -1
- package/dist/commands/sys/sync-deps.d.ts +6 -11
- package/dist/commands/sys/sync-deps.js +7 -8
- package/dist/commands/sys/sync-project-guidance.js +5 -4
- package/dist/commands/sys/sync-shared.d.ts +41 -4
- package/dist/commands/sys/sync-shared.js +1 -1
- package/dist/commands/sys/sync-skills.js +2 -2
- package/dist/commands/sys/sync.js +1 -1
- package/dist/core/bash-job-supervisor.d.ts +2 -3
- package/dist/core/bash-job-supervisor.js +3 -3
- package/dist/core/bash-jobs.d.ts +0 -5
- package/dist/core/bash-jobs.js +7 -7
- package/dist/core/bootstrap.js +2 -2
- package/dist/core/canvas/canvas.d.ts +6 -50
- package/dist/core/canvas/canvas.js +16 -21
- package/dist/core/canvas/db.d.ts +4 -1
- package/dist/core/canvas/db.js +2 -2
- package/dist/core/canvas/history.d.ts +11 -39
- package/dist/core/canvas/history.js +9 -20
- package/dist/core/canvas/install-id.d.ts +2 -2
- package/dist/core/canvas/install-id.js +1 -1
- package/dist/core/canvas/memory-reads.d.ts +5 -0
- package/dist/core/canvas/memory-reads.js +1 -1
- package/dist/core/canvas/migrations.js +215 -41
- package/dist/core/canvas/node-agent-paths.js +1 -1
- package/dist/core/canvas/node-tokens.js +1 -1
- package/dist/core/canvas/paths.d.ts +0 -4
- package/dist/core/canvas/paths.js +1 -1
- package/dist/core/canvas/remote-canvas-source.d.ts +0 -1
- package/dist/core/canvas/remote-canvas-source.js +1 -1
- package/dist/core/canvas/render-source.d.ts +9 -6
- package/dist/core/canvas/render-source.js +6 -6
- package/dist/core/canvas/sessions.js +2 -2
- package/dist/core/canvas/source.d.ts +6 -0
- package/dist/core/canvas/tree.d.ts +29 -0
- package/dist/core/canvas/tree.js +12 -0
- package/dist/core/canvas/types.d.ts +0 -20
- package/dist/core/command-plugins/bundle.js +1 -1
- package/dist/core/config.d.ts +1 -1
- package/dist/core/conversation-store/listener.js +4 -2
- package/dist/core/feed/feed.d.ts +9 -7
- package/dist/core/feed/feed.js +3 -7
- package/dist/core/feed/inbox.d.ts +3 -5
- package/dist/core/feed/inbox.js +1 -10
- package/dist/core/feed/messages.d.ts +33 -6
- package/dist/core/feed/messages.js +10 -7
- package/dist/core/feed/reports.d.ts +10 -0
- package/dist/core/feed/reports.js +2 -0
- package/dist/core/grants/remove.js +1 -1
- package/dist/core/graph/access.d.ts +24 -0
- package/dist/core/graph/access.js +8 -0
- package/dist/core/graph/bodies.d.ts +6 -0
- package/dist/core/graph/bodies.js +1 -0
- package/dist/core/graph/deletion.d.ts +9 -0
- package/dist/core/graph/deletion.js +5 -0
- package/dist/core/graph/diff.d.ts +4 -0
- package/dist/core/graph/diff.js +4 -0
- package/dist/core/graph/documents.d.ts +160 -0
- package/dist/core/graph/documents.js +7 -0
- package/dist/core/graph/edges.d.ts +24 -0
- package/dist/core/graph/edges.js +1 -0
- package/dist/core/graph/events.d.ts +26 -0
- package/dist/core/graph/events.js +6 -0
- package/dist/core/graph/exposures.d.ts +53 -0
- package/dist/core/graph/exposures.js +4 -0
- package/dist/core/graph/jobs.d.ts +31 -0
- package/dist/core/graph/jobs.js +2 -0
- package/dist/core/graph/names.d.ts +28 -0
- package/dist/core/graph/names.js +3 -0
- package/dist/core/graph/objects.d.ts +55 -0
- package/dist/core/graph/objects.js +9 -0
- package/dist/core/graph/package-docs.d.ts +31 -0
- package/dist/core/graph/package-docs.js +5 -0
- package/dist/core/graph/package-files.d.ts +20 -0
- package/dist/core/graph/package-files.js +2 -0
- package/dist/core/graph/reader.d.ts +21 -0
- package/dist/core/graph/reader.js +3 -0
- package/dist/core/graph/repo-sync/exchange.d.ts +34 -0
- package/dist/core/graph/repo-sync/exchange.js +2 -0
- package/dist/core/graph/repo-sync/identity.d.ts +30 -0
- package/dist/core/graph/repo-sync/identity.js +1 -0
- package/dist/core/graph/repo-sync/index.d.ts +4 -0
- package/dist/core/graph/repo-sync/index.js +1 -0
- package/dist/core/graph/repo-sync/mirror.d.ts +30 -0
- package/dist/core/graph/repo-sync/mirror.js +6 -0
- package/dist/core/graph/repo-sync/ref-format.d.ts +76 -0
- package/dist/core/graph/repo-sync/ref-format.js +2 -0
- package/dist/core/graph/repo-sync/repos.d.ts +17 -0
- package/dist/core/graph/repo-sync/repos.js +3 -0
- package/dist/core/graph/repo-sync/sync.d.ts +42 -0
- package/dist/core/graph/repo-sync/sync.js +2 -0
- package/dist/core/graph/rules.d.ts +26 -0
- package/dist/core/graph/rules.js +3 -0
- package/dist/core/graph/spaces/app.d.ts +3 -0
- package/dist/core/graph/spaces/app.js +1 -0
- package/dist/core/graph/spaces/index.d.ts +19 -0
- package/dist/core/graph/spaces/index.js +1 -0
- package/dist/core/graph/spaces/person.d.ts +5 -0
- package/dist/core/graph/spaces/person.js +2 -0
- package/dist/core/graph/spaces/repo.d.ts +4 -0
- package/dist/core/graph/spaces/repo.js +1 -0
- package/dist/core/graph/types.d.ts +75 -0
- package/dist/core/graph/types.js +1 -0
- package/dist/core/graph/watches.d.ts +62 -0
- package/dist/core/graph/watches.js +18 -0
- package/dist/core/human/feedback-companion.js +1 -1
- package/dist/core/human/requests.d.ts +3 -1
- package/dist/core/human/requests.js +6 -6
- package/dist/core/inspector/model.js +2 -2
- package/dist/core/io.js +5 -5
- package/dist/core/layout-migrate/index.d.ts +24 -1
- package/dist/core/layout-migrate/index.js +4 -4
- package/dist/core/layout-migrate/paths.d.ts +4 -0
- package/dist/core/layout-migrate/paths.js +1 -1
- package/dist/core/layout-migrate/stored-paths.d.ts +7 -0
- package/dist/core/layout-migrate/stored-paths.js +11 -11
- package/dist/core/layout-migrate/stores.d.ts +19 -6
- package/dist/core/layout-migrate/stores.js +3 -4
- package/dist/core/manifest.d.ts +0 -2
- package/dist/core/manifest.js +1 -1
- package/dist/core/{memory/extensions.d.ts → plugin-extensions.d.ts} +9 -10
- package/dist/core/plugin-extensions.js +1 -0
- package/dist/core/preview-registry.d.ts +1 -1
- package/dist/core/preview-registry.js +3 -2
- package/dist/core/profiles/manifest.d.ts +7 -7
- package/dist/core/profiles/manifest.js +1 -1
- package/dist/core/profiles/select.js +3 -3
- package/dist/core/review/birth.js +1 -1
- package/dist/core/review/companion.js +1 -1
- package/dist/core/review/stage.d.ts +12 -1
- package/dist/core/review/stage.js +1 -1
- package/dist/core/review/store.d.ts +2 -0
- package/dist/core/review/store.js +1 -1
- package/dist/core/review/types.d.ts +7 -1
- package/dist/core/runs/events.js +1 -1
- package/dist/core/runs/operations.js +5 -5
- package/dist/core/runs/questions.js +2 -2
- package/dist/core/runtime/bearings-render.d.ts +13 -7
- package/dist/core/runtime/bearings-render.js +12 -12
- package/dist/core/runtime/bearings.d.ts +8 -18
- package/dist/core/runtime/bearings.js +7 -7
- package/dist/core/runtime/broker/daemon-ops.d.ts +7 -12
- package/dist/core/runtime/broker/daemon-ops.js +1 -1
- package/dist/core/runtime/broker/fault-retry.d.ts +2 -0
- package/dist/core/runtime/broker/fault-retry.js +1 -1
- package/dist/core/runtime/broker/frame-dispatch.d.ts +1 -1
- package/dist/core/runtime/broker/frame-memory-refs.d.ts +7 -2
- package/dist/core/runtime/broker/frame-memory-refs.js +1 -1
- package/dist/core/runtime/broker/inbox.d.ts +1 -4
- package/dist/core/runtime/broker/inbox.js +1 -10
- package/dist/core/runtime/broker/rebind.js +1 -1
- package/dist/core/runtime/broker/retry-card-elision.d.ts +7 -0
- package/dist/core/runtime/broker/retry-card-elision.js +1 -0
- package/dist/core/runtime/broker-extension-render.d.ts +0 -13
- package/dist/core/runtime/broker-extension-render.js +2 -4
- package/dist/core/runtime/broker-persona-guidance.js +3 -3
- package/dist/core/runtime/broker-protocol.d.ts +1 -1
- package/dist/core/runtime/broker.js +1 -1
- package/dist/core/runtime/close.d.ts +9 -4
- package/dist/core/runtime/close.js +1 -1
- package/dist/core/runtime/deliver-live.js +1 -1
- package/dist/core/runtime/kickoff.js +17 -19
- package/dist/core/runtime/launch-target.d.ts +7 -0
- package/dist/core/runtime/launch-target.js +1 -1
- package/dist/core/runtime/ledger.d.ts +10 -0
- package/dist/core/runtime/ledger.js +3 -0
- package/dist/core/runtime/lifecycle.js +2 -2
- package/dist/core/runtime/nodes.d.ts +10 -2
- package/dist/core/runtime/nodes.js +1 -1
- package/dist/core/runtime/outcome-document.d.ts +2 -2
- package/dist/core/runtime/outcome-document.js +1 -1
- package/dist/core/runtime/persona.js +2 -2
- package/dist/core/runtime/placement.js +1 -1
- package/dist/core/runtime/promote.d.ts +2 -2
- package/dist/core/runtime/promote.js +1 -1
- package/dist/core/runtime/prospective-inventory-cli.js +2 -2
- package/dist/core/runtime/recycle.js +1 -1
- package/dist/core/runtime/reopen.js +1 -1
- package/dist/core/runtime/revive.js +2 -2
- package/dist/core/runtime/roadmap.d.ts +17 -9
- package/dist/core/runtime/roadmap.js +4 -4
- package/dist/core/runtime/spawn-env.js +1 -1
- package/dist/core/runtime/spawn.d.ts +5 -3
- package/dist/core/runtime/spawn.js +2 -2
- package/dist/core/runtime/structured-output.d.ts +3 -1
- package/dist/core/runtime/structured-output.js +4 -4
- package/dist/core/scope.d.ts +1 -32
- package/dist/core/scope.js +1 -1
- package/dist/core/scoped-state/db.js +2 -1
- package/dist/core/scoped-state/migrate.js +2 -2
- package/dist/core/scoped-state/profiles.d.ts +11 -0
- package/dist/core/scoped-state/profiles.js +1 -1
- package/dist/core/scoped-state/schema.d.ts +1 -1
- package/dist/core/scoped-state/schema.js +7 -5
- package/dist/core/spaces/permissions.d.ts +0 -14
- package/dist/core/spaces/permissions.js +1 -1
- package/dist/core/spaces/stop.d.ts +13 -0
- package/dist/core/spaces/stop.js +2 -2
- package/dist/core/storage/tables.d.ts +1 -1
- package/dist/core/substrate/delivery/corpus.d.ts +21 -0
- package/dist/core/substrate/delivery/corpus.js +3 -0
- package/dist/core/substrate/delivery/deliver.d.ts +76 -0
- package/dist/core/substrate/delivery/deliver.js +6 -0
- package/dist/core/substrate/delivery/listings.d.ts +27 -0
- package/dist/core/substrate/delivery/listings.js +4 -0
- package/dist/core/substrate/delivery/match.d.ts +28 -0
- package/dist/core/substrate/delivery/match.js +1 -0
- package/dist/core/substrate/delivery/plan.d.ts +67 -0
- package/dist/core/substrate/delivery/plan.js +3 -0
- package/dist/core/substrate/delivery/render-boot.d.ts +20 -0
- package/dist/core/substrate/delivery/render-boot.js +54 -0
- package/dist/core/substrate/delivery/render-event.d.ts +47 -0
- package/dist/core/substrate/delivery/render-event.js +6 -0
- package/dist/core/substrate/delivery/sub-persona-menu.d.ts +2 -0
- package/dist/core/substrate/delivery/sub-persona-menu.js +6 -0
- package/dist/core/substrate/delivery/types.d.ts +30 -0
- package/dist/core/substrate/delivery/types.js +0 -0
- package/dist/core/substrate/gate-explain.d.ts +0 -13
- package/dist/core/substrate/gate-explain.js +1 -1
- package/dist/core/substrate/schema.d.ts +11 -139
- package/dist/core/substrate/schema.js +1 -1
- package/dist/core/substrate/subject-fields.d.ts +3 -0
- package/dist/core/substrate/subject.d.ts +2 -1
- package/dist/core/substrate/subject.js +1 -1
- package/dist/daemon/api/handlers/app-profiles.js +1 -1
- package/dist/daemon/api/handlers/bash-jobs.js +1 -2
- package/dist/daemon/api/handlers/broker-ops.js +1 -1
- package/dist/daemon/api/handlers/canvas.js +5 -5
- package/dist/daemon/api/handlers/daemon.js +1 -1
- package/dist/daemon/api/handlers/delivery.d.ts +2 -0
- package/dist/daemon/api/handlers/delivery.js +1 -0
- package/dist/daemon/api/handlers/{memory.d.ts → docs.d.ts} +1 -1
- package/dist/daemon/api/handlers/docs.js +1 -0
- package/dist/daemon/api/handlers/hook-exec.js +1 -1
- package/dist/daemon/api/handlers/messages.js +2 -2
- package/dist/daemon/api/handlers/node-records.js +2 -2
- package/dist/daemon/api/handlers/nodes.js +1 -1
- package/dist/daemon/api/handlers/objects.d.ts +2 -0
- package/dist/daemon/api/handlers/objects.js +5 -0
- package/dist/daemon/api/handlers/package-docs.d.ts +2 -0
- package/dist/daemon/api/handlers/package-docs.js +1 -0
- package/dist/daemon/api/handlers/profiles.js +1 -1
- package/dist/daemon/api/handlers/reports.d.ts +2 -2
- package/dist/daemon/api/handlers/reports.js +4 -4
- package/dist/daemon/api/handlers/reviews.js +1 -1
- package/dist/daemon/api/map.d.ts +2 -2
- package/dist/daemon/api/map.js +2 -2
- package/dist/daemon/api/operations.d.ts +1 -1
- package/dist/daemon/api/operations.js +1 -1
- package/dist/daemon/api/reader.d.ts +17 -0
- package/dist/daemon/api/reader.js +1 -0
- package/dist/daemon/api/server.js +1 -1
- package/dist/daemon/control.d.ts +2 -3
- package/dist/daemon/crtrd.js +8 -6
- package/dist/daemon/fleet.js +4 -4
- package/dist/daemon/reconcilers/bash-deadline.d.ts +11 -1
- package/dist/daemon/reconcilers/bash-deadline.js +2 -1
- package/dist/daemon/reconcilers/broker-supervision.js +4 -4
- package/dist/daemon/reconcilers/live-obligation.js +1 -1
- package/dist/daemon/reconcilers/node-deadline.js +1 -1
- package/dist/daemon/reconcilers/node-lifecycle/freeze-lane.js +1 -1
- package/dist/daemon/reconcilers/storage-maintenance.d.ts +1 -0
- package/dist/daemon/reconcilers/storage-maintenance.js +1 -1
- package/dist/daemon/review/deliver.js +2 -2
- package/dist/daemon/review/finish.js +1 -1
- package/dist/hook-authoring.d.ts +0 -1
- package/dist/hook-authoring.js +3 -3
- package/dist/migrations/004-canvas-documents/apply.d.ts +10 -0
- package/dist/migrations/004-canvas-documents/apply.js +1 -0
- package/dist/migrations/004-canvas-documents/fields.d.ts +24 -0
- package/dist/migrations/004-canvas-documents/fields.js +2 -0
- package/dist/migrations/004-canvas-documents/index.d.ts +16 -0
- package/dist/migrations/004-canvas-documents/index.js +2 -0
- package/dist/migrations/004-canvas-documents/legacy/discover.d.ts +16 -0
- package/dist/migrations/004-canvas-documents/legacy/discover.js +1 -0
- package/dist/migrations/004-canvas-documents/legacy/history.d.ts +5 -0
- package/dist/migrations/004-canvas-documents/legacy/history.js +2 -0
- package/dist/migrations/004-canvas-documents/legacy/nested.d.ts +7 -0
- package/dist/migrations/004-canvas-documents/legacy/nested.js +1 -0
- package/dist/migrations/004-canvas-documents/legacy/parse.d.ts +14 -0
- package/dist/migrations/004-canvas-documents/legacy/parse.js +1 -0
- package/dist/migrations/004-canvas-documents/legacy/types.d.ts +91 -0
- package/dist/migrations/004-canvas-documents/legacy/types.js +0 -0
- package/dist/migrations/004-canvas-documents/legacy-edges.d.ts +6 -0
- package/dist/migrations/004-canvas-documents/legacy-edges.js +18 -0
- package/dist/migrations/004-canvas-documents/plan.d.ts +102 -0
- package/dist/migrations/004-canvas-documents/plan.js +3 -0
- package/dist/migrations/004-canvas-documents/pointers.d.ts +23 -0
- package/dist/migrations/004-canvas-documents/pointers.js +4 -0
- package/dist/migrations/activation.d.ts +9 -18
- package/dist/migrations/activation.js +2 -2
- package/dist/pi-extensions/broker-local.d.ts +2 -2
- package/dist/pi-extensions/broker-local.js +2 -2
- package/dist/pi-extensions/canvas-bash-valve.js +5 -4
- package/dist/pi-extensions/canvas-context-intro.js +2 -2
- package/dist/pi-extensions/canvas-doc-substrate.d.ts +0 -1
- package/dist/pi-extensions/canvas-doc-substrate.js +6 -6
- package/dist/pi-extensions/canvas-inbox-watcher.js +2 -2
- package/dist/pi-extensions/canvas-passive-context.js +1 -1
- package/dist/pi-extensions/canvas-recap.js +2 -2
- package/dist/pi-extensions/canvas-stophook.d.ts +1 -1
- package/dist/pi-extensions/canvas-stophook.js +1 -1
- package/dist/prompts/review.js +3 -3
- package/dist/shared/env.d.ts +5 -0
- package/dist/shared/env.js +1 -1
- package/dist/shared/generated-context.js +2 -10
- package/dist/shared/inbox-entry-body.d.ts +22 -0
- package/dist/shared/inbox-entry-body.js +10 -0
- package/dist/{core/memory → shared}/inline-ref-guidance.d.ts +2 -2
- package/dist/shared/inline-ref-guidance.js +2 -0
- package/dist/types.d.ts +3 -1
- package/docs/cli/memory-and-preferences.md +12 -14
- package/docs/concepts/README.md +1 -1
- package/docs/concepts/lifecycle-and-wakes.md +1 -1
- package/docs/concepts/memory.md +15 -15
- package/docs/concepts/nodes-and-the-canvas.md +1 -1
- package/docs/concepts/profiles-kinds-and-modes.md +5 -5
- package/docs/concepts/scopes-and-trust.md +1 -1
- package/docs/concepts/why-a-daemon.md +1 -1
- package/docs/sdk/README.md +5 -6
- package/docs/sdk/errors.md +0 -13
- package/docs/sdk/guides/README.md +0 -1
- package/docs/sdk/nodes.md +0 -2
- package/docs/sdk/resources.md +0 -1
- package/package.json +2 -2
- package/packages/crouter-identity/package.json +1 -1
- package/runtime.lock.json +11 -11
- package/dist/api/dto/memory.d.ts +0 -171
- package/dist/api/dto/memory.js +0 -1
- package/dist/builtin-memory/crouter-sdk/guides/app-memory.md +0 -73
- package/dist/builtin-memory/crouter-sdk/memory.md +0 -87
- package/dist/commands/broker-permissions.d.ts +0 -2
- package/dist/commands/broker-permissions.js +0 -1
- package/dist/commands/memory/client.d.ts +0 -11
- package/dist/commands/memory/client.js +0 -1
- package/dist/commands/memory/delete.d.ts +0 -1
- package/dist/commands/memory/delete.js +0 -1
- package/dist/commands/memory/edit.d.ts +0 -1
- package/dist/commands/memory/edit.js +0 -21
- package/dist/commands/memory/find.d.ts +0 -1
- package/dist/commands/memory/find.js +0 -1
- package/dist/commands/memory/history.d.ts +0 -1
- package/dist/commands/memory/history.js +0 -5
- package/dist/commands/memory/lint.d.ts +0 -1
- package/dist/commands/memory/lint.js +0 -1
- package/dist/commands/memory/list.d.ts +0 -1
- package/dist/commands/memory/list.js +0 -1
- package/dist/commands/memory/move.d.ts +0 -1
- package/dist/commands/memory/move.js +0 -1
- package/dist/commands/memory/origin.d.ts +0 -1
- package/dist/commands/memory/origin.js +0 -1
- package/dist/commands/memory/read.d.ts +0 -1
- package/dist/commands/memory/read.js +0 -6
- package/dist/commands/memory/shared.d.ts +0 -22
- package/dist/commands/memory/shared.js +0 -1
- package/dist/commands/memory/write.d.ts +0 -1
- package/dist/commands/memory/write.js +0 -13
- package/dist/commands/memory.js +0 -1
- package/dist/commands/node-inspect-artifacts.d.ts +0 -1
- package/dist/commands/node-inspect-artifacts.js +0 -8
- package/dist/core/help/memory-extensions.d.ts +0 -3
- package/dist/core/help/memory-extensions.js +0 -2
- package/dist/core/memory/cli-selector.d.ts +0 -13
- package/dist/core/memory/cli-selector.js +0 -1
- package/dist/core/memory/doc-link-grammar.d.ts +0 -20
- package/dist/core/memory/doc-link-grammar.js +0 -2
- package/dist/core/memory/extensions.js +0 -1
- package/dist/core/memory/history.d.ts +0 -87
- package/dist/core/memory/history.js +0 -6
- package/dist/core/memory/identity.d.ts +0 -65
- package/dist/core/memory/identity.js +0 -1
- package/dist/core/memory/inline-ref-guidance.js +0 -2
- package/dist/core/memory/inline-ref-inventory.d.ts +0 -9
- package/dist/core/memory/inline-ref-inventory.js +0 -1
- package/dist/core/memory/lint.d.ts +0 -163
- package/dist/core/memory/lint.js +0 -2
- package/dist/core/memory/mutation-domain.d.ts +0 -113
- package/dist/core/memory/mutation-domain.js +0 -12
- package/dist/core/memory/mutations.d.ts +0 -74
- package/dist/core/memory/mutations.js +0 -1
- package/dist/core/memory/project-namespace.d.ts +0 -31
- package/dist/core/memory/project-namespace.js +0 -2
- package/dist/core/memory/repository-association.d.ts +0 -31
- package/dist/core/memory/repository-association.js +0 -1
- package/dist/core/memory/service.d.ts +0 -145
- package/dist/core/memory/service.js +0 -2
- package/dist/core/memory/tree.d.ts +0 -39
- package/dist/core/memory/tree.js +0 -1
- package/dist/core/memory-resolver.d.ts +0 -280
- package/dist/core/memory-resolver.js +0 -2
- package/dist/core/nested-stores.d.ts +0 -18
- package/dist/core/nested-stores.js +0 -1
- package/dist/core/runtime/memory.d.ts +0 -3
- package/dist/core/runtime/memory.js +0 -1
- package/dist/core/substrate/frontmatter-validation.d.ts +0 -11
- package/dist/core/substrate/frontmatter-validation.js +0 -1
- package/dist/core/substrate/gate.d.ts +0 -16
- package/dist/core/substrate/gate.js +0 -1
- package/dist/core/substrate/index.d.ts +0 -18
- package/dist/core/substrate/index.js +0 -1
- package/dist/core/substrate/injected-store.d.ts +0 -75
- package/dist/core/substrate/injected-store.js +0 -2
- package/dist/core/substrate/listings.d.ts +0 -28
- package/dist/core/substrate/listings.js +0 -1
- package/dist/core/substrate/memory-events.d.ts +0 -6
- package/dist/core/substrate/memory-events.js +0 -1
- package/dist/core/substrate/on-read-node.d.ts +0 -6
- package/dist/core/substrate/on-read-node.js +0 -1
- package/dist/core/substrate/on-read.d.ts +0 -101
- package/dist/core/substrate/on-read.js +0 -9
- package/dist/core/substrate/plan.d.ts +0 -94
- package/dist/core/substrate/plan.js +0 -1
- package/dist/core/substrate/render-node.d.ts +0 -12
- package/dist/core/substrate/render-node.js +0 -1
- package/dist/core/substrate/render.d.ts +0 -41
- package/dist/core/substrate/render.js +0 -65
- package/dist/core/substrate/session-cache.d.ts +0 -27
- package/dist/core/substrate/session-cache.js +0 -1
- package/dist/core/substrate/surface-match.d.ts +0 -73
- package/dist/core/substrate/surface-match.js +0 -1
- package/dist/daemon/api/handlers/memory.js +0 -5
- package/dist/migrations/001-surfaces-frontmatter.d.ts +0 -2
- package/dist/migrations/001-surfaces-frontmatter.js +0 -1
- package/dist/migrations/002-profile-project-memory.d.ts +0 -2
- package/dist/migrations/002-profile-project-memory.js +0 -1
- package/dist/migrations/003-repository-root-memory-identity/front-door.d.ts +0 -26
- package/dist/migrations/003-repository-root-memory-identity/front-door.js +0 -11
- package/dist/migrations/003-repository-root-memory-identity/index.d.ts +0 -2
- package/dist/migrations/003-repository-root-memory-identity/index.js +0 -5
- package/dist/migrations/003-repository-root-memory-identity/references.d.ts +0 -95
- package/dist/migrations/003-repository-root-memory-identity/references.js +0 -5
- package/dist/migrations/003-repository-root-memory-identity/repository-facts.d.ts +0 -39
- package/dist/migrations/003-repository-root-memory-identity/repository-facts.js +0 -3
- package/dist/migrations/convergent.d.ts +0 -43
- package/dist/migrations/convergent.js +0 -2
- package/dist/migrations/corpus.d.ts +0 -75
- package/dist/migrations/corpus.js +0 -3
- package/dist/migrations/frontmatter-splice.d.ts +0 -15
- package/dist/migrations/frontmatter-splice.js +0 -8
- package/dist/migrations/profile-manifests.d.ts +0 -30
- package/dist/migrations/profile-manifests.js +0 -2
- package/dist/migrations/registry.d.ts +0 -7
- package/dist/migrations/registry.js +0 -1
- package/dist/migrations/runner.d.ts +0 -43
- package/dist/migrations/runner.js +0 -1
- package/dist/migrations/types.d.ts +0 -211
- package/dist/shared/birth-announcement.d.ts +0 -12
- package/dist/shared/birth-announcement.js +0 -1
- package/docs/sdk/guides/app-memory.md +0 -22
- package/docs/sdk/memory.md +0 -85
- /package/dist/{migrations/types.js → api/dto/delivery.js} +0 -0
- /package/dist/{core/memory → shared}/inline-ref-grammar.d.ts +0 -0
- /package/dist/{core/memory → shared}/inline-ref-grammar.js +0 -0
package/dist/daemon/fleet.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
var b=Object.defineProperty;var l=(t,e)=>b(t,"name",{value:e,configurable:!0});import{getNode as p,getRow as g
|
|
1
|
+
var b=Object.defineProperty;var l=(t,e)=>b(t,"name",{value:e,configurable:!0});import{getNode as p,getRow as g}from"../core/canvas/index.js";import{revokeExitedNodeToken as k}from"../core/canvas/node-tokens.js";import{isProfilePaused as $}from"../core/profiles/manifest.js";import{fullName as v}from"../core/canvas/labels.js";import{isSafeNodeId as o}from"../core/canvas/paths.js";import{transition as _}from"../core/runtime/lifecycle.js";import{publishNotice as T}from"../core/runtime/close.js";import{readInterruptedTurn as P,readTransportPoisonVerdict as E}from"../core/canvas/recovery.js";import{hasPendingWake as N}from"./reconcilers/live-obligation.js";import{clearRespawnPolicy as h,deferRespawnWhileOffline as x,MAX_RESPAWN_ATTEMPTS as R,OFFLINE_RESPAWN_RETRY_MS as C,recordRespawnPolicy as F,respawnBackoffMs as S}from"./reconcilers/node-lifecycle/respawn-policy.js";import{probeOnline as M}from"../core/runtime/connectivity.js";import{reviveNode as A}from"../core/runtime/revive.js";import{pushUrgent as m}from"../core/feed/feed.js";import{emitEvent as c}from"../core/events/emit.js";import{brokerThresholdsForDaemon as O}from"../core/runtime/fleet.js";import{isRecoveryHeld as z}from"../core/runtime/recovery-hold.js";function w(t,e){const r=e===void 0?"The daemon did not observe an exit status.":`The observed exit status was code ${e.code??"null"}, signal ${e.signal??"null"}.`;return`\u26A0 Spawn failed \u2014 \`${t.name}\` (${t.kind}) never started.
|
|
2
2
|
|
|
3
3
|
Its pi vehicle exited before the session came up (no pi_session_id was ever recorded), so the node produced no output. ${r}
|
|
4
4
|
|
|
5
5
|
Inspect canonical event diagnostics with \`crtr sys logs --node ${t.node_id}\`.
|
|
6
6
|
|
|
7
|
-
If the work still needs doing, re-spawn it.`}l(w,"bootFailureBody");async function y(t,e){await m(t.node_id,w(t,e),{from:t.node_id})}l(y,"surfaceBootFailure");async function
|
|
7
|
+
If the work still needs doing, re-spawn it.`}l(w,"bootFailureBody");async function y(t,e){await m(t.node_id,w(t,e),{from:t.node_id})}l(y,"surfaceBootFailure");async function D(t){const e=E(t.node_id),r=e===null?"":`
|
|
8
8
|
|
|
9
9
|
Provider rotation observed ${e.consecutivePasses} consecutive route-queue passes with no HTTP response (tried ${e.routes.join(", ")}). Check network and provider transport before reviving.`,i=`\u26A0 Crash loop \u2014 \`${t.name}\` (${t.kind}) kept dying without settling a turn.
|
|
10
10
|
|
|
11
11
|
Its session started successfully, but six consecutive relaunches made no progress, so the daemon stopped retrying.`+r+`
|
|
12
12
|
|
|
13
|
-
Fix the crash cause, then revive the node if the work still needs doing.`;await m(t.node_id,i,{from:t.node_id})}l(
|
|
13
|
+
Fix the crash cause, then revive the node if the work still needs doing.`;await m(t.node_id,i,{from:t.node_id})}l(D,"surfaceCrashLoop");async function B(t,e){const r=e instanceof Error?e.message:String(e),i=`\u26A0 Recovery failed \u2014 \`${t.name}\` (${t.kind}) could not be relaunched.
|
|
14
14
|
|
|
15
15
|
The daemon refused this recovery before starting a broker: ${r}
|
|
16
16
|
|
|
17
|
-
The node is now dead. Fix the recorded launch configuration, then revive it if the work still needs doing.`;await m(t.node_id,i,{from:t.node_id})}l(
|
|
17
|
+
The node is now dead. Fix the recorded launch configuration, then revive it if the work still needs doing.`;await m(t.node_id,i,{from:t.node_id})}l(B,"surfaceRecoveryFailure");function L(t){return t?.cycle_pending!==!0}l(L,"retryResumeMode");function W(t,e,r=!0){return t===null||t.status==="done"||t.status==="canceled"||t.status==="dead"?"forget":t.intent==="refresh"?"respawn-fresh":t.intent==="idle-release"?"dormant":t.lifecycle==="resident"&&!e&&!r&&t.pi_session_id!=null?"release-idle":t.pi_session_id!=null?L(t)?"respawn-resume":"respawn-cycle":e||t.fork_from!=null?"respawn-fresh":"boot-failure"}l(W,"classifyDeadNode");const q=3e4;class ne{static{l(this,"DaemonFleet")}#a;#o;#i;#l;#e=new Map;#r=new Set;#s=new Set;#t=new Map;#c=Number.NEGATIVE_INFINITY;constructor(e){this.#a=e.epoch,this.#o=e.enqueue,this.#i=e.now??Date.now,this.#l=e.probeOnline??(()=>M())}epoch(){return this.#a}register(e,r){if(this.#e.has(e))throw new Error(`fleet: ${e} already has a live broker entry \u2014 refusing a second launch (programming error)`);if(r.pid===null)throw new Error(`fleet: refusing to register ${e} with no pid`);this.#r.delete(e),this.#t.delete(e),this.#e.set(e,{pid:r.pid,handle:r})}has(e){return this.#e.has(e)}isClaimed(e){return this.#e.has(e)||this.#r.has(e)}get(e){return this.#e.get(e)}size(){return this.#e.size}occupancy(){return this.#e.size+this.#r.size}reserveSlot(e){if(this.#r.has(e)||this.#e.has(e))return!0;const{automaticReviveCap:r}=O();if(this.occupancy()<r)return this.#r.add(e),!0;const i=this.#i();return i-this.#c>=q&&(this.#c=i,c({level:"warn",event:"broker.capacity.revive_deferred",fields:{live_count:this.occupancy(),hard_cap:r}})),!1}releaseReservation(e){this.#r.delete(e)}entries(){return this.#e.entries()}interruptForProfilePause(e,r=this.#e.get(e)?.pid){if(r!==void 0){this.#s.add(e);try{process.kill(r,"SIGTERM")}catch{}}}hasProfilePauseInterruption(e){return this.#s.has(e)}forget(e){this.#e.delete(e),this.#r.delete(e),this.#t.delete(e)}onChildExit(e,r,i){i&&k(i),this.#e.delete(e),this.#o(()=>{const s=p(e),n=s?.launched_at==null?Number.NaN:Date.parse(s.launched_at),a=Number.isFinite(n)?Math.max(0,this.#i()-n):null,d=s?.respawn_failures??0;s?.status==="done"||s?.status==="canceled"||s?.status==="dead"?this.#t.delete(e):this.#t.set(e,r),this.#u(e,r,a,d)})}deliverExit(e,r){this.onChildExit(e,r)}async applyDeadRowPolicy(e){const r=this.#t.get(e);try{await this.#f(e,r)}finally{this.#t.get(e)===r&&this.#t.delete(e)}}async terminalizeIfStillNonTerminal(e,r,i,s,n){const a=p(e);return a===null||a.status==="done"||a.status==="canceled"||a.status==="dead"?!1:(await this.#n(e,a,{event:r,reason:s,detail:n,wake:`Child crashed \u2014 ${v(a)} (${e}) could not be relaunched and is now dead. It stays dead until you revive it \u2014 \`crtr node lifecycle revive ${e}\`.`,surface:l(()=>B(a,i),"surface")}),!0)}dispose(){}#u(e,r,i,s){c({level:"info",event:"broker.exit.observed",...o(e)?{node_id:e}:{},fields:{...o(e)?{}:{affected_node_id:e},code:r.code,signal:r.signal,uptime_ms:i,consecutive_failures:s}})}async#f(e,r){return this.#h(e,r)}async#h(e,r){const i=p(e);if(i!==null&&$(i.profile_id))return h(e),"forget";if(this.#s.delete(e))return h(e),"forget";if(z(e))return"dormant";const s=P(e)?.interrupted===!0,n=W(i,s,N(e));switch(n){case"forget":h(e);break;case"dormant":h(e);break;case"release-idle":h(e),_(e,"release"),c({level:"info",event:"broker.recovery.released",...o(e)?{node_id:e}:{},fields:{...o(e)?{}:{affected_node_id:e}}});break;case"boot-failure":await this.#n(e,i,{event:"broker.boot.failed",reason:"boot_failed",detail:{schema:"crtr.node-outcome-detail/v1",message:w(i,r)},wake:`Child crashed \u2014 ${v(i)} (${e}) exited before its session ever came up and is now dead. It stays dead until you revive it \u2014 \`crtr node lifecycle revive ${e}\`.`,surface:l(()=>y(i,r),"surface")});break;case"respawn-fresh":case"respawn-cycle":case"respawn-resume":await this.#d(e,i,n,s);break}return n}async#d(e,r,i,s){const n=g(e);if(n===null)return;const a=n.respawn_failures??0;if(!await this.#l()){x(e,a,this.#i()),c({level:"info",event:"broker.respawn.offline_deferred",...o(e)?{node_id:e}:{},fields:{...o(e)?{}:{affected_node_id:e},action:i,retry_in_ms:C,consecutive_failures:a}});return}const d=n.respawn_not_before==null,f=d?F(n,this.#i()):{failures:a,notBefore:n.respawn_not_before,exhausted:a>=R};if(f.exhausted){const u=`Child crashed \u2014 ${v(r)} (${e}) kept dying without settling a turn (${f.failures} consecutive launches) and is now dead. It stays dead until you revive it \u2014 \`crtr node lifecycle revive ${e}\`.`;await this.#n(e,r,{event:"broker.respawn.exhausted",reason:"crash_looped",detail:{schema:"crtr.node-outcome-detail/v1",message:u,respawn_failures:f.failures},wake:u,...r.pi_session_id!=null?{surface:l(()=>D(r),"surface")}:{}});return}if(d&&f.notBefore!==null){c({level:"info",event:"broker.respawn.deferred",...o(e)?{node_id:e}:{},fields:{...o(e)?{}:{affected_node_id:e},action:i,backoff_ms:S(f.failures),consecutive_failures:f.failures}});return}c({level:"info",event:"broker.respawn.started",...o(e)?{node_id:e}:{},fields:{...o(e)?{}:{affected_node_id:e},action:i,consecutive_failures:f.failures}});try{await A(e,{capacity:"freeze",resume:i==="respawn-resume",wakeReason:i==="respawn-resume"&&s?"runtime-restart-abort":void 0,recovery:!0})}catch(u){c({level:"error",event:"broker.respawn.failed",...o(e)?{node_id:e}:{},error:u,fields:{...o(e)?{}:{affected_node_id:e},action:i}}),await this.terminalizeIfStillNonTerminal(e,"broker.respawn.refused",u,"launch_failed",{schema:"crtr.node-outcome-detail/v1",message:u instanceof Error?u.message:String(u)})}}async#n(e,r,i){c({level:"error",event:i.event,...o(e)?{node_id:e}:{fields:{affected_node_id:e}}}),_(e,"crash",{reason:i.reason,outcome:{detail:i.detail}});try{await(i.surface??(()=>y(r)))()}catch(s){c({level:"error",event:"broker.boot_failure_surface.failed",...o(e)?{node_id:e}:{fields:{affected_node_id:e}},error:s})}T(e,"notice.crash",i.wake,{reason:"child-crashed",child:e})}}export{ne as DaemonFleet,W as classifyDeadNode,L as retryResumeMode,y as surfaceBootFailure};
|
|
@@ -9,9 +9,19 @@ export interface BashDeadlineContext {
|
|
|
9
9
|
* alive. This lane is the enforcer: it survives a broker restart and fires while
|
|
10
10
|
* the node is idle, so a runaway command cannot outlive its window just because
|
|
11
11
|
* the agent moved on. A deliberately backgrounded job carries no deadline and is
|
|
12
|
-
* never
|
|
12
|
+
* never canceled here. It also publishes every backgrounded job's exit, and adopts
|
|
13
|
+
* a job the broker backgrounded while exiting (SIGTERM/SIGHUP), which could not
|
|
14
|
+
* record its own job object. */
|
|
13
15
|
export declare class BashDeadlineReconciler {
|
|
14
16
|
private lastScanAt;
|
|
17
|
+
/** An exit written before this daemon started is history, not a job to adopt. */
|
|
18
|
+
private readonly startedAt;
|
|
15
19
|
run(now: number, ctx: BashDeadlineContext): Promise<void>;
|
|
20
|
+
/** A running job whose supervisor wrote job.exit has exited: `finishJob` publishes `exited`
|
|
21
|
+
* once (the row leaves `running`). A job being stopped (job.stop) is ended by its killer. */
|
|
22
|
+
private publishExits;
|
|
23
|
+
/** Give every backgrounded job dir (job.bg) that has no job object one; the next tick's
|
|
24
|
+
* `publishExits` then ends it like any other job. */
|
|
25
|
+
private adoptUnrecorded;
|
|
16
26
|
private cancel;
|
|
17
27
|
}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
var p=Object.defineProperty;var
|
|
1
|
+
var p=Object.defineProperty;var f=(l,e)=>p(l,"name",{value:e,configurable:!0});import{existsSync as s,readFileSync as m,readdirSync as u,statSync as j}from"node:fs";import{join as b}from"node:path";import{bashJobPaths as _,bashJobsDir as S,expiredAutoBackgroundBashJobs as x,stopBackgroundBashJob as y}from"../../core/bash-jobs.js";import{killBashJobObject as N,recordBashJobObject as E}from"../../core/spaces/stop.js";import{withCanvasWrite as h}from"../../core/canvas/db.js";import{finishJob as v}from"../../core/graph/jobs.js";import{getById as g,getByRowid as A}from"../../core/graph/objects.js";import{isSafeNodeId as c}from"../../core/canvas/paths.js";import{contextDir as B}from"../../core/canvas/node-agent-paths.js";import{emitEvent as a}from"../../core/events/emit.js";import{operationIdContext as d}from"../../core/events/operation-id.js";import{isProfilePaused as J}from"../../core/profiles/manifest.js";const w=5*1e3;class W{static{f(this,"BashDeadlineReconciler")}lastScanAt=Number.NEGATIVE_INFINITY;startedAt=Date.now();async run(e,n){if(this.publishExits(),!(e-this.lastScanAt<w)){this.lastScanAt=e;for(const t of n.rows){if(t.status==="dead"||J(t.profile_id))continue;const i=B(t.node_id);let r;try{this.adoptUnrecorded(t.node_id,i),r=x(i,e)}catch(o){d.fresh(()=>{a({level:"error",event:"bash_deadline.scan_failed",...c(t.node_id)?{node_id:t.node_id}:{},error:o})});continue}for(const o of r)await this.cancel(t.node_id,i,o.jobId)}}}publishExits(){try{h(e=>{const n=e.prepare(`SELECT j.object, j.job_dir FROM jobs j JOIN objects o ON o.rowid = j.object
|
|
2
|
+
WHERE j.status = 'running' AND o.deleted_at IS NULL`).all();for(const{object:t,job_dir:i}of n){const r=b(i,"job.exit");if(!s(r)||s(b(i,"job.stop")))continue;const o=Number(m(r,"utf8").trim());Number.isSafeInteger(o)&&v(e,A(e,t),{exitCode:o})}})}catch(e){d.fresh(()=>a({level:"error",event:"bash_completion.delivery_failed",error:e}))}}adoptUnrecorded(e,n){let t;try{t=u(S(n))}catch{return}const i=h(r=>t.filter(o=>g(r,o)===null));for(const r of i){const o=_(n,r);!s(o.jobBg)||!s(o.cmdSh)||s(o.jobExit)&&j(o.jobExit).mtimeMs<this.startedAt||E(e,r,{command:m(o.cmdSh,"utf8"),jobDir:o.dir,logPath:o.jobLog})}}async cancel(e,n,t){(await y(n,t,!1,e)).kind==="stopped"&&d.fresh(()=>{try{a({level:"info",event:"bash_deadline.canceled",...c(e)?{node_id:e}:{},fields:{job_id:t}}),N(t,()=>null,"deadline")}catch(r){a({level:"error",event:"bash_deadline.notice_failed",...c(e)?{node_id:e}:{},error:r,fields:{job_id:t}})}})}}export{W as BashDeadlineReconciler};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
2
|
-
`)){const a=i.trim();if(a==="")continue;const n=a.split(/\s+/);if(n.length<3)continue;const s=Number(n[0]),r=Number(n[1]),d=Number(n[2]);if(!Number.isFinite(s)||!Number.isFinite(r)||!Number.isFinite(d))continue;e.set(s,d);const c=t.get(r);c===void 0?t.set(r,[s]):c.push(s)}return{byPid:e,childrenOf:t}}m(
|
|
3
|
-
`).map(async p=>{if(p!=="")try{await N("tmux",["display-message","-C","-d","10000","-c",p,c],{encoding:"utf8",timeout:2e3})}catch{try{await N("tmux",["display-message","-c",p,c],{encoding:"utf8",timeout:2e3})}catch(h){f({level:"error",event:"broker.capacity.tmux_display_failed",error:h,fields:{client:p}})}}}))}catch(l){f({level:"error",event:"broker.capacity.tmux_list_clients_failed",error:l})}}async handleYieldStall(e,t,i,a){const n=e.node_id,s=
|
|
4
|
-
`)[0]??"").slice(0,200),r=t.providerError,d=r===void 0?"":` Provider: ${r.provider}/${r.model}.`+(r.status===void 0?"":` HTTP status: ${r.status}.`)+(r.errno===void 0?"":` Errno: ${r.errno}.`)+(r.code===void 0?"":` Code: ${r.code}.`)+(r.body===void 0?"":` Body: ${r.body.slice(0,200)}.`),c=t.kind==="context-overflow",l=i?.parent==null&&i?.lifecycle==="terminal",p=c||l,h=c?`Child failed \u2014 ${a} (${e}) exceeded its model context window and is now dead. Shrink the task or loaded context, or choose a larger-context model before spawning it again. Error: ${s}`:`Child hit a fatal provider fault \u2014 ${a} (${e}) got a non-retryable ${t.kind} error and will NOT recover on its own; `+(l?"its terminal run has failed. ":"it stays alive, and waking it clears the fault as soon as one turn completes \u2014 a wake that hits the same cause fails again. "+(n?"Its provider credential is dead \u2014 re-authenticate (`/login`, or re-auth crtr); the child recovers on its next wake once the auth reloads. ":""))+`Error: ${s}.${d}`;p&&(
|
|
1
|
+
var Y=Object.defineProperty;var m=(o,e)=>Y(o,"name",{value:e,configurable:!0});import{existsSync as H,statSync as j}from"node:fs";import{join as $}from"node:path";import{LAUNCHER_SOCKET as K}from"../../launcher/spec.js";import{launcherRequest as V}from"../../launcher/client.js";import{secretsDir as z}from"../../core/layout.js";import{execFile as J}from"node:child_process";import{promisify as Q}from"node:util";import{getNode as A,isWarmSpare as X}from"../../core/canvas/index.js";import{isSafeNodeId as u}from"../../core/canvas/paths.js";import{contextDir as Z}from"../../core/canvas/node-agent-paths.js";import{fullName as I}from"../../core/canvas/labels.js";import{recordedPidLiveness as D}from"../../core/canvas/pid.js";import{transition as ee}from"../../core/runtime/lifecycle.js";import{readFault as O,readLiveTurn as C,recordFault as te}from"../../core/canvas/recovery.js";import{errorClassFromFault as ne}from"../../core/fault-classifier.js";import{nextFaultRetry as re}from"../../core/runtime/fault-recovery.js";import{publishNotice as L}from"../../core/runtime/close.js";import{headlessBrokerHost as v}from"../../core/runtime/host.js";import{reloadAuthLive as ie}from"../../core/runtime/auth-reload.js";import{emitEvent as f}from"../../core/events/emit.js";import{operationIdContext as R}from"../../core/events/operation-id.js";import{hasUnseenWakeMail as ae,resetStaleExecutionMail as se}from"../../core/canvas/deliveries.js";import{activeBackgroundBashJobs as oe}from"../../core/bash-jobs.js";import{focusOf as le}from"../../core/runtime/placement.js";import{hasAttachedBrokerViewers as de}from"../api/viewer-presence.js";import{deliverLive as ce}from"../../core/runtime/interactive-deliver.js";import{BrokerUnreachableError as ue}from"../../core/runtime/broker-request.js";import{formatCard as fe,PARK_SUMMARY_PROMPT as pe}from"../../shared/generated-context.js";import{brokerThresholdsForDaemon as me}from"../../core/runtime/fleet.js";import{readConfig as he}from"../../core/config.js";import{scopedStoreExists as _e}from"../../core/scoped-state/db.js";import{providerStore as ge}from"../../core/scoped-state/paths.js";import{providerRevision as ve}from"../../core/scoped-state/providers.js";import{beginPendingPark as ke,consumePendingPark as y,pendingParkIds as ye,pendingParkStartedAt as we}from"../park-pending.js";import{shouldParkAfterSummary as be}from"../park-activity.js";import{applyParkEvent as w,parkEvent as Se}from"./live-obligation.js";import{envNoDaemonAutostart as Ae,envTestUnattendedParkMs as Ne,parkSummaryGraceMs as Pe,envUnattendedParkMs as Me}from"../../shared/env.js";const N=Q(J);function Te(o){return C(o)?.busy===!0}m(Te,"liveBusy");function wt(o){const e=C(o)?.progressAt;if(e==null)return null;const t=Date.parse(e);return Number.isNaN(t)?null:t}m(wt,"liveTurnProgressMs");function G(o,e){return e===null?null:`${o}:${e}`}m(G,"incarnationOf");function F(o){const e=C(o.node_id),t=e?.busy===!0&&e.progressAt!==null?Date.parse(e.progressAt):Number.NaN,i=o.launched_at===null||o.launched_at===void 0?Number.NaN:Date.parse(o.launched_at);return!Number.isFinite(t)||!Number.isFinite(i)||t<i?null:t}m(F,"busySinceForIncarnation");const W=3*6e4,U=2e4,x=20*6e4,Ee=2,$e=5*6e4;function Ce(){const o=Me();if(o!==void 0)return o;const e=he("user").lifecycle.unattendedParkMs;return Ae()?Ne()??e:e}m(Ce,"unattendedParkMsForDaemon");function B(){return Pe()}m(B,"parkSummaryGraceMsForDaemon");function Re(o,e,t,i){return o!==!0||e!=="refresh"||t?"leave":i===null||i<W?"pending":"kill"}m(Re,"yieldStallVerdict");function Fe(o){return!o.busy||o.quietForMs===null||o.quietForMs<x?"leave":o.cpuPercent===null||o.hasDescendants!==!1&&o.cpuPercent>Ee?"pending":"wedged"}m(Fe,"wedgeVerdict");function q(o){const e=new Map,t=new Map;for(const i of o.split(`
|
|
2
|
+
`)){const a=i.trim();if(a==="")continue;const n=a.split(/\s+/);if(n.length<3)continue;const s=Number(n[0]),r=Number(n[1]),d=Number(n[2]);if(!Number.isFinite(s)||!Number.isFinite(r)||!Number.isFinite(d))continue;e.set(s,d);const c=t.get(r);c===void 0?t.set(r,[s]):c.push(s)}return{byPid:e,childrenOf:t}}m(q,"parsePsTree");function xe(o,e){const{byPid:t,childrenOf:i}=q(o);if(!t.has(e))return null;let a=0;const n=[e],s=new Set;for(;n.length>0;){const r=n.pop();if(s.has(r))continue;s.add(r),a+=t.get(r)??0;const d=i.get(r);d!==void 0&&n.push(...d)}return a}m(xe,"sumTreeCpu");function Ie(o,e){const{byPid:t,childrenOf:i}=q(o);return t.has(e)?(i.get(e)??[]).length>0:null}m(Ie,"treeHasDescendants");function De(o){return[$(o,"auth.json"),$(o,"anthropic-credentials.json"),$(o,"openai-codex-credentials.json")]}m(De,"piCredentialPaths");class bt{static{m(this,"BrokerSupervisionReconciler")}yieldStalls=new Map;wedgeNotifiedAt=new Map;fatalFaultNotifiedAt=new Map;unattendedSince=new Map;sampleTree;signal;knownCredentialRevision=null;lastOverCapWarnAt=Number.NEGATIVE_INFINITY;constructor(e={}){this.sampleTree=e.readTreeSample??(t=>this.readTreeSample(t)),this.signal=e.signal??((t,i)=>{if(process.platform==="linux"&&H(K)){if(i!=="SIGTERM"&&i!=="SIGKILL")throw new Error(`unsupported launcher signal ${i}`);return V({operation:"stop",pid:t,signal:i}).then(()=>{})}process.kill(t,i)})}async runFleetPreamble(e){return await this.handleAuthReload(e),me()}warnIfSaturated(e){if(e.fleet.size()<e.thresholds.warning||!e.lifecycle.acceptsDetachedWork())return;const t=R.fresh(()=>this.warnOverCapInTmux(e.fleet.size(),e.thresholds,e.frozen));e.lifecycle.registerDetached(t)}async run(e,t){const i=Ce();for(const a of t.rows){const n=a.node_id,s=t.fleet.get(n);if(s===void 0||a.status!=="active"&&a.status!=="idle"){this.unattendedSince.delete(n);continue}await R.fresh(async()=>{try{await this.handleYieldStall(a,s,t.fleet,e),await this.handleWedgeDetection(a,s,t.fleet,e),this.handleFatalFault(n),this.handleUnattendedParking(n,A(n),s.pid,e,t,i)}catch(r){this.unattendedSince.delete(n),f({level:"error",event:"broker.supervision.failed",...u(n)?{node_id:n}:{fields:{affected_node_id:n}},error:r})}})}for(const a of this.unattendedSince.keys())t.fleet.has(a)||this.unattendedSince.delete(a);for(const a of ye())t.fleet.has(a)||y(a);se(e)}parkResetCondition(e,t,i,a){if(t.pi_session_id==null||t.pi_pid!==i||t.status==="done"||t.status==="canceled"||t.status==="dead"||t.intent!==null||oe(Z(e)).length>0||le(e)!==null||de(e))return!0;const n=O(e);return n!==null&&n.retry.disposition==="auto"&&n.retry.by==="daemon"&&(n.kind==="connection"||n.kind==="rate-limit"||n.kind==="overloaded")&&(n.retry.nextAt!==void 0||re(n,a)!==null)?!0:ae(e)}handleUnattendedParking(e,t,i,a,n,s){if(X(e)){this.unattendedSince.delete(e),y(e);return}if(t===null){this.unattendedSince.delete(e),y(e);return}const r=this.parkResetCondition(e,t,i,a),d=we(e);if(d!==void 0){if(a-d<B())return;const p=y(e);if(p===void 0||(this.unattendedSince.delete(e),!be(e,t,p)))return;f({level:"warn",event:"broker.park.summary_expired",...u(e)?{node_id:e}:{},fields:{...u(e)?{}:{affected_node_id:e},grace_ms:B()}}),w(e,"park"),v.teardown(e);return}if(r||Te(e)){this.unattendedSince.delete(e);return}const c=this.unattendedSince.get(e);if(c===void 0){this.unattendedSince.set(e,a);return}if(a-c<s)return;this.unattendedSince.delete(e);const l=Se(e,t.lifecycle);if(l==="release"){w(e,l),v.teardown(e);return}if(l==="cancel"){w(e,l),v.teardown(e);return}if(t.grantee!==void 0&&t.grantee!=="app:terminal"){w(e,"park"),v.teardown(e);return}n.lifecycle.acceptsDetachedWork()&&(ke(e,a),n.lifecycle.registerDetached(this.requestParkSummary(e)))}async requestParkSummary(e){try{const t=await ce(e,fe("park",{},pe),{origin:{type:"runtime",kind:"park"}});f({level:"info",event:"broker.park.summary_requested",...u(e)?{node_id:e}:{},fields:{...u(e)?{}:{affected_node_id:e},route:t}})}catch(t){if(y(e)===void 0)return;if(t instanceof ue){w(e,"park"),v.teardown(e);return}f({level:"error",event:"broker.park.summary_failed",...u(e)?{node_id:e}:{fields:{affected_node_id:e}},error:t})}}async warnOverCapInTmux(e,t,i){const a=Date.now();if(a-this.lastOverCapWarnAt<$e)return;this.lastOverCapWarnAt=a;const{warning:n,automaticReviveCap:s}=t,r=i.stalled+i.waitingOnMail;f({level:"warn",event:"broker.capacity.warning",fields:{live_count:e,warning_threshold:n,hard_cap:s,frozen_stalled:i.stalled,frozen_waiting_on_mail:i.waitingOnMail}});const d=r===0?"":` \u2014 ${r} frozen (${i.stalled} stalled, ${i.waitingOnMail} waiting on mail)`,c=`\u26A0 crtrd: ${e} live brokers (warning ${n}; hard cap ${s})${d} \u2014 possible broker leak. ps -ax | grep broker-cli.js`;try{const l=await N("tmux",["list-clients","-F","#{client_name}"],{encoding:"utf8",timeout:2e3});if(typeof l.stdout!="string")return;await Promise.allSettled(l.stdout.split(`
|
|
3
|
+
`).map(async p=>{if(p!=="")try{await N("tmux",["display-message","-C","-d","10000","-c",p,c],{encoding:"utf8",timeout:2e3})}catch{try{await N("tmux",["display-message","-c",p,c],{encoding:"utf8",timeout:2e3})}catch(h){f({level:"error",event:"broker.capacity.tmux_display_failed",error:h,fields:{client:p}})}}}))}catch(l){f({level:"error",event:"broker.capacity.tmux_list_clients_failed",error:l})}}async handleYieldStall(e,t,i,a){const n=e.node_id,s=G(t.pid,e.pi_pid_identity);if(e.intent!=="refresh"||F(e)!==null||s===null){s!==null&&this.yieldStalls.delete(s);return}let r=this.yieldStalls.get(s);if(r===void 0){r={since:a},this.yieldStalls.set(s,r);return}if(Re(!0,e.intent,!1,a-r.since)!=="kill")return;const d=A(n);if(!(i.get(n)!==t||d?.pi_pid!==t.pid||d.pi_pid_identity!==e.pi_pid_identity||D(t.pid,e.pi_pid_identity)!=="alive"))if(r.termedAt===void 0){if(!await this.signalYieldStall(n,t.pid,"SIGTERM"))return;r.termedAt=a,f({level:"warn",event:"broker.yield_stall.sigterm",...u(n)?{node_id:n}:{},fields:{...u(n)?{}:{affected_node_id:n},pid:t.pid,elapsed_ms:a-r.since,grace_ms:W}})}else a-r.termedAt>=U&&await this.signalYieldStall(n,t.pid,"SIGKILL")&&f({level:"warn",event:"broker.yield_stall.sigkill",...u(n)?{node_id:n}:{},fields:{...u(n)?{}:{affected_node_id:n},pid:t.pid,elapsed_ms:a-r.termedAt,grace_ms:U,stall_elapsed_ms:a-r.since}})}async signalYieldStall(e,t,i){try{return await this.signal(t,i),!0}catch(a){return f({level:"error",event:"broker.yield_stall.signal_failed",...u(e)?{node_id:e}:{},error:a,fields:{...u(e)?{}:{affected_node_id:e},pid:t,signal:i}}),!1}}async readTreeSample(e){try{const{stdout:t}=await N("ps",["-ax","-o","pid=,ppid=,pcpu="],{encoding:"utf8",timeout:2e3});if(typeof t!="string")return null;const i=xe(t,e),a=Ie(t,e);return i===null||a===null?null:{cpuPercent:i,hasDescendants:a}}catch{return null}}async handleWedgeDetection(e,t,i,a){const n=e.node_id,s=G(t.pid,e.pi_pid_identity),r=F(e);if(r===null||s===null){s!==null&&this.wedgeNotifiedAt.delete(s);return}const d=a-r,c=d>=x?await this.sampleTree(t.pid):null,l=A(n),p=l===null?null:F(l);if(i.get(n)!==t||l===null||l.pi_pid!==t.pid||l.pi_pid_identity!==e.pi_pid_identity||p!==r)return;const h=c?.cpuPercent??null,_=c?.hasDescendants??null;if(Fe({busy:!0,quietForMs:d,cpuPercent:h,hasDescendants:_})!=="wedged"||this.wedgeNotifiedAt.get(s)===r)return;this.wedgeNotifiedAt.set(s,r);const b=I(l),S=Math.round((d??x)/6e4),P=_??!0,k=!P&&D(t.pid,e.pi_pid_identity)!=="alive"?"pid_identity_unproven":null;let M=!1,T=!1,g;if(P)g=`Child wedged \u2014 ${b} (${n}) is alive and mid-turn but has shown NO engine progress for ${S}+ minutes and its process is near-idle. It will NOT recover on its own \u2014 read \`crtr canvas read wedged-child-on-runaway-bash\` and kill the runaway SUBPROCESS (not this node) so its turn can resume with no lost context.`;else if(k!==null)g=`Child wedged \u2014 ${b} (${n}) is alive and mid-turn but has shown NO engine progress for ${S}+ minutes and it has no subprocess to kill (the engine itself stalled). The daemon did not SIGTERM the broker because its PID identity cannot be confirmed alive.`;else{M=!0;try{await this.signal(t.pid,"SIGTERM"),T=!0,g=`Child wedged \u2014 ${b} (${n}) is alive and mid-turn but has shown NO engine progress for ${S}+ minutes and it has no subprocess to kill (the engine itself stalled). The daemon sent SIGTERM to the broker and will resume a cleanly aborted session with a continuation, or start a recovery cycle if the abort cannot settle.`}catch(E){f({level:"error",event:"broker.wedge.signal_failed",...u(n)?{node_id:n}:{},error:E,fields:{...u(n)?{}:{affected_node_id:n},pid:t.pid,signal:"SIGTERM"}}),g=`Child wedged \u2014 ${b} (${n}) is alive and mid-turn but has shown NO engine progress for ${S}+ minutes and it has no subprocess to kill (the engine itself stalled). The daemon attempted SIGTERM to the broker, but the signal call failed.`}}f({level:"error",event:"broker.wedge.detected",...u(n)?{node_id:n}:{},fields:{...u(n)?{}:{affected_node_id:n},pid:t.pid,quiet_ms:d,cpu_percent:h,has_descendants:P,kick_attempted:M,kicked:T,...k===null?{}:{kick_suppression_reason:k}}});try{te(n,{link:"daemon\u2192node",op:"engine wedge",kind:"wedged",retry:{disposition:"manual"},message:g})}catch(E){f({level:"error",event:"broker.wedge.fault_record_failed",...u(n)?{node_id:n}:{fields:{affected_node_id:n}},error:E})}L(n,"notice.crash",g,{reason:"child-wedged",child:n,quiet_ms:d,cpu_percent:h,kick_attempted:M,kicked:T,...k===null?{}:{kick_suppression_reason:k}})}handleFatalFault(e){const t=O(e);if(t===null){this.fatalFaultNotifiedAt.delete(e);return}if(t.retry.disposition!=="fatal"||t.link!=="pi\u2192provider"||this.fatalFaultNotifiedAt.get(e)===t.since)return;const i=A(e),a=i!==null?I(i):e,n=t.kind==="auth",s=(t.message.split(`
|
|
4
|
+
`)[0]??"").slice(0,200),r=t.providerError,d=r===void 0?"":` Provider: ${r.provider}/${r.model}.`+(r.status===void 0?"":` HTTP status: ${r.status}.`)+(r.errno===void 0?"":` Errno: ${r.errno}.`)+(r.code===void 0?"":` Code: ${r.code}.`)+(r.body===void 0?"":` Body: ${r.body.slice(0,200)}.`),c=t.kind==="context-overflow",l=i?.parent==null&&i?.lifecycle==="terminal",p=c||l,h=c?`Child failed \u2014 ${a} (${e}) exceeded its model context window and is now dead. Shrink the task or loaded context, or choose a larger-context model before spawning it again. Error: ${s}`:`Child hit a fatal provider fault \u2014 ${a} (${e}) got a non-retryable ${t.kind} error and will NOT recover on its own; `+(l?"its terminal run has failed. ":"it stays alive, and waking it clears the fault as soon as one turn completes \u2014 a wake that hits the same cause fails again. "+(n?"Its provider credential is dead \u2014 re-authenticate (`/login`, or re-auth crtr); the child recovers on its next wake once the auth reloads. ":""))+`Error: ${s}.${d}`;p&&(ee(e,"crash",{reason:c?"context_overflow":"provider_fatal",outcome:{detail:{schema:"crtr.node-outcome-detail/v1",message:t.message,fault_kind:t.kind,error_class:ne(t).class}}}),v.teardown(e).then(_=>{_.confirmed||f({level:"error",event:"fault.fatal.teardown_failed",node_id:e,error:_.error??new Error("Broker teardown not confirmed")})},_=>f({level:"error",event:"fault.fatal.teardown_failed",node_id:e,error:_}))),this.fatalFaultNotifiedAt.set(e,t.since),f({level:"error",event:"fault.fatal.fanout",...u(e)?{node_id:e}:{},fields:{...u(e)?{}:{affected_node_id:e},kind:t.kind,link:t.link,terminal_overflow:c,terminal_provider_fault:l}}),L(e,"notice.crash",h,{reason:c?"child-context-overflow":"child-fault-fatal",child:e,kind:t.kind,message:s,...r===void 0?{}:{provider_error:r}})}async handleAuthReload(e){const t=z();let i=0;for(const r of De(t))try{i=Math.max(i,j(r).mtimeMs)}catch{}let a=0;const n=ge(t);_e(n)&&(a=ve(t));const s=`${i}:${a}`;if(this.knownCredentialRevision===null){this.knownCredentialRevision=s;return}s!==this.knownCredentialRevision&&(this.knownCredentialRevision=s,await R.fresh(async()=>{try{const r=Array.from(e.entries(),([l])=>l);if(r.length===0)return;const c=(await Promise.allSettled(r.map(async l=>{try{await ie(l)}catch(p){throw f({level:"error",event:"auth.reload.broker_failed",...u(l)?{node_id:l}:{fields:{broker_id:l}},error:p}),p}}))).filter(l=>l.status==="fulfilled").length;f({level:"info",event:"auth.reload.completed",outcome:c===r.length?"succeeded":"failed",fields:{broker_count:r.length,succeeded_count:c,failed_count:r.length-c}})}catch(r){f({level:"error",event:"auth.reload.failed",error:r})}}))}}export{bt as BrokerSupervisionReconciler,Ee as WEDGE_CPU_MAX_PERCENT,x as WEDGE_QUIET_MS,W as YIELD_STALL_GRACE_MS,B as parkSummaryGraceMsForDaemon,xe as sumTreeCpu,Ie as treeHasDescendants,Ce as unattendedParkMsForDaemon,Fe as wedgeVerdict,Re as yieldStallVerdict};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var f=Object.defineProperty;var e=(r,t)=>f(r,"name",{value:t,configurable:!0});import{hasActiveLiveSubscription as l,hasLiveMessageWait as p,hasLiveSubscriber as m,hasPendingCronWake as h}from"../../core/canvas/index.js";import{fullName as k}from"../../core/canvas/labels.js";import{newestReportName as g}from"../../core/feed/reports.js";import{countTickets as w}from"../../core/canvas/attention.js";import{hasUnseenWakeMail as s}from"../../core/canvas/deliveries.js";import{readOutputRequest as b}from"../../core/runtime/structured-output.js";import{focusOf as v}from"../../core/runtime/placement.js";import{hasAttachedBrokerViewers as x}from"../api/viewer-presence.js";import{publishNotice as $}from"../../core/runtime/close.js";import{readFault as L}from"../../core/canvas/recovery.js";import{transition as u}from"../../core/runtime/lifecycle.js";function a(r){return l(r)||p(r)||h(r)||w(r)>0||b(r).state!=="absent"}e(a,"hasLiveObligation");function V(r){return a(r)||s(r)?!0:n(r)}e(V,"hasPendingWake");function q(r){return t=>r.isClaimed(t)||a(t)||n(t)}e(q,"retentionHold");function n(r){return v(r)!==null||x(r)}e(n,"hasHumanViewer");function B(r,t){if(n(r)||a(r))return"release";const i=L(r);return i?.link==="pi\u2192provider"&&i.retry.disposition==="fatal"?"release":t==="resident"?s(r)?"release":"park":s(r)||m(r)?"release":"cancel"}e(B,"parkEvent");function F(r,t){const i=t==="cancel"?u(r,t,{reason:"stranded"}):u(r,t);if(t!=="park")return;const o=g(r),c=o===null?`It left no report behind; \`crtr node inspect show ${r}\` shows where it stands.`:`Its latest report is where it left things: \`crtr canvas read ${o}\`.`;$(r,"notice.close",`Resident concluded \u2014 ${k(i)} (${r}) had nothing left to wake it through its unattended grace, so its conversation was concluded. It submitted no final report. ${c} A message to it reopens it on a fresh cycle.`,{reason:"child-auto-done",child:r},"deferred")}e(F,"applyParkEvent");export{F as applyParkEvent,n as hasHumanViewer,a as hasLiveObligation,V as hasPendingWake,B as parkEvent,q as retentionHold};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var c=Object.defineProperty;var s=(o,e)=>c(o,"name",{value:e,configurable:!0});import{dueNodeDeadlines as _
|
|
1
|
+
var c=Object.defineProperty;var s=(o,e)=>c(o,"name",{value:e,configurable:!0});import{dueNodeDeadlines as _}from"../../core/canvas/index.js";import{emitEvent as n}from"../../core/events/emit.js";import{isProfilePaused as f}from"../../core/profiles/manifest.js";import{operationIdContext as m}from"../../core/events/operation-id.js";import{errorClassFromFault as u}from"../../core/fault-classifier.js";import{publishNotice as p}from"../../core/runtime/close.js";import{readFault as h}from"../../core/canvas/recovery.js";import{requestBrokerTeardown as v}from"../../core/runtime/host.js";import{transition as x}from"../../core/runtime/lifecycle.js";class b{static{s(this,"NodeDeadlineReconciler")}run(e){let r;try{r=_(new Date(e).toISOString())}catch(d){n({level:"error",event:"node_deadline.scan_failed",error:d});return}for(const d of r)f(d.profile_id)||m.fresh(()=>this.expire(d,e))}expire(e,r){const d=e.deadline_at;if(d==null)return;const l=h(e.node_id),t=l?.retry.disposition==="fatal"?l:null;let a;try{a=x(e.node_id,"cancel",{reason:"deadline_exceeded",outcome:{detail:{schema:"crtr.node-outcome-detail/v1",deadline:{deadline_at:d,elapsed_ms:r-Date.parse(d)},...t===null?{}:{message:t.message,fault_kind:t.kind,error_class:u(t).class}}}})}catch(i){n({level:"error",event:"node_deadline.terminalize_failed",node_id:e.node_id,error:i,fields:{deadline_at:d}});return}if(!(a.status!=="canceled"||a.outcome_reason!=="deadline_exceeded")){try{v(e.node_id)}catch(i){n({level:"error",event:"node_deadline.teardown_failed",node_id:e.node_id,error:i,fields:{deadline_at:d}})}try{p(e.node_id,"notice.deadline","child-deadline-exceeded",{reason:"child-deadline-exceeded",child:e.node_id})}catch(i){n({level:"error",event:"node_deadline.notify_failed",node_id:e.node_id,error:i,fields:{deadline_at:d}})}try{n({level:"error",event:"node_deadline.expired",node_id:e.node_id,fields:{deadline_at:d,elapsed_ms:r-Date.parse(d)}})}catch{}}}}export{b as NodeDeadlineReconciler};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var w=Object.defineProperty;var d=(i,t)=>w(i,"name",{value:t,configurable:!0});import{clearFrozen as v,getNode as E,getRow as y
|
|
1
|
+
var w=Object.defineProperty;var d=(i,t)=>w(i,"name",{value:t,configurable:!0});import{clearFrozen as v,getNode as E,getRow as y}from"../../../core/canvas/index.js";import{fullName as g}from"../../../core/canvas/labels.js";import{isSafeNodeId as s}from"../../../core/canvas/paths.js";import{emitEvent as c}from"../../../core/events/emit.js";import{operationIdContext as A}from"../../../core/events/operation-id.js";import{acknowledgedNodeMailCount as z}from"../../../core/canvas/deliveries.js";import{publishNotice as S}from"../../../core/runtime/close.js";import{transition as p}from"../../../core/runtime/lifecycle.js";import{reviveNode as m}from"../../../core/runtime/revive.js";import{hasPendingWake as _}from"../live-obligation.js";const f=6,k=10*6e4,R=2e4;function L(i,t){if(t)return 2;const r=i.launched_at;if(r==null)return 1;const e=i.last_settled_at;return e==null?2:Date.parse(e)>Date.parse(r)?1:2}d(L,"thawTier");function M(i,t){if(i.tier!==t.tier)return i.tier-t.tier;const r=i.row.frozen_at,e=t.row.frozen_at;return r==null?e==null?0:1:e==null?-1:Date.parse(r)-Date.parse(e)}d(M,"compareThaw");class O{static{d(this,"FreezeLaneReconciler")}relaunchState=new Map;endEpisode(t){this.relaunchState.delete(t)}async run(t,r){const e=r.candidates.map(a=>({...a,tier:L(a.row,_(a.row.node_id))}));e.sort(M);const n={stalled:0,waitingOnMail:0};for(const a of e)await A.fresh(()=>this.enact(t,a,r.fleet))==="frozen"&&(a.tier===1?n.stalled+=1:n.waitingOnMail+=1);return n}async enact(t,r,e){const n=r.row.node_id;try{return r.enact==="thaw"?await this.enactThaw(r.row):r.enact==="idle-release"?await this.enactIdleRelease(t,r.row):(await e.applyDeadRowPolicy(n),e.has(n)?"launched":y(n)?.frozen_at!=null?"frozen":"skipped")}catch(a){return c({level:"error",event:"node.lifecycle.enact_failed",...s(n)?{node_id:n}:{},error:a,fields:{...s(n)?{}:{affected_node_id:n},enact:r.enact}}),"skipped"}}async enactThaw(t){return t.lifecycle==="resident"&&E(t.node_id)?.pi_session_id!=null&&!_(t.node_id)?(p(t.node_id,"release"),v(t.node_id),"skipped"):(await m(t.node_id,{resume:!0,capacity:"freeze",recovery:!0})).outcome==="frozen"?"frozen":"launched"}async enactIdleRelease(t,r){const e=r.node_id,n=z(e),a=this.relaunchState.get(e),l=a===void 0||a.acknowledgedCount!==n,o=l?0:a.attempts;if(o>=f)return this.relaunchState.delete(e),c({level:"warn",event:"broker.idle_release.exhausted",...s(e)?{node_id:e}:{},fields:{...s(e)?{}:{affected_node_id:e},attempts:o,max_attempts:f}}),p(e,"crash",{reason:"launch_failed",outcome:{detail:{schema:"crtr.node-outcome-detail/v1",respawn_failures:o}}}),S(e,"notice.crash",`Child crashed \u2014 ${g(r)} (${e}) failed to relaunch after ${o} attempts while trying to deliver a pending inbox message (no delivery progress across any attempt), and is now dead. It stays dead until you revive it \u2014 \`crtr node lifecycle revive ${e}\`.`,{reason:"child-crashed",child:e}),"skipped";const u=l?void 0:a?.lastAttempt,h=Math.min(R*2**o,k);return u!==void 0&&t-u<h?"skipped":(await m(e,{resume:!0,capacity:"freeze"})).outcome==="frozen"?"frozen":(this.relaunchState.set(e,{acknowledgedCount:n,attempts:o+1,lastAttempt:t}),c({level:"info",event:"broker.revive.idle_release",...s(e)?{node_id:e}:{},attempt:o+1,fields:{...s(e)?{}:{affected_node_id:e},attempts:o+1,max_attempts:f}}),"launched")}}export{O as FreezeLaneReconciler,M as compareThaw,L as thawTier};
|
|
@@ -16,6 +16,7 @@ export interface StorageMaintenanceContext {
|
|
|
16
16
|
export declare class StorageMaintenanceReconciler {
|
|
17
17
|
private lastSpareSweepAt;
|
|
18
18
|
private lastRunExpiryAt;
|
|
19
|
+
private lastAnalyzeAt;
|
|
19
20
|
private lastRetentionSweepAt;
|
|
20
21
|
private lastContextStripAt;
|
|
21
22
|
private contextStripInFlight;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var S=Object.defineProperty;var c=(f,t)=>S(f,"name",{value:t,configurable:!0});import{rm as A}from"node:fs/promises";import{closeFocusRow as y,getFocusById as N,listFocuses as E,listNodes as h}from"../../core/canvas/index.js";import{getNode as g,lastActivityMs as u,pruneNodes as x}from"../../core/canvas/canvas.js";import{lastContextStripMs as T,stripContextDir as R}from"../../core/canvas/context-strip.js";import{isSafeNodeId as d}from"../../core/canvas/paths.js";import{emitEvent as i}from"../../core/events/emit.js";import{operationIdContext as o}from"../../core/events/operation-id.js";import{listLivePanesAsync as F,tearDownNode as w}from"../../core/runtime/placement.js";import{reapStaleSpares as D}from"../../core/runtime/warm-pool.js";import{ManagedWorktreeSweepReconciler as C}from"./managed-worktree-sweep.js";import{expireRunEvents as G}from"../../core/runs/events.js";import{openDb as b}from"../../core/canvas/db.js";import{retentionHold as m}from"./live-obligation.js";import{pruneMemoryReads as P}from"../../core/canvas/memory-reads.js";const M=10*6e4,V=60*1e3,v=5*6e4,W=14,Y=1440*6e4;class ee{static{c(this,"StorageMaintenanceReconciler")}lastSpareSweepAt=Number.NEGATIVE_INFINITY;lastRunExpiryAt=Number.NEGATIVE_INFINITY;lastAnalyzeAt=Number.NEGATIVE_INFINITY;lastRetentionSweepAt=Number.NEGATIVE_INFINITY;lastContextStripAt=Number.NEGATIVE_INFINITY;contextStripInFlight=!1;focusGcInFlight=!1;worktreeSweep=new C;run(t,r){if(this.reapDeadResidue(t),this.scheduleFocusGc(r),this.gcWarmPool(t),t-this.lastRunExpiryAt>=60*6e4){G(t);try{P(t)}catch(e){console.warn(`memory-read log prune failed: ${String(e)}`)}this.lastRunExpiryAt=t}t-this.lastAnalyzeAt>=1440*6e4&&(b().exec("ANALYZE"),this.lastAnalyzeAt=t),this.sweepRetention(t,r),this.scheduleContextStrip(t,r),this.worktreeSweep.run(t,r)}msSinceTerminalActivity(t,r){const e=u(t);return e===0?Number.POSITIVE_INFINITY:r-e}sweepRetention(t,r){t-this.lastRetentionSweepAt<v||r.lifecycle.acceptsDetachedWork()&&(this.lastRetentionSweepAt=t,o.fresh(()=>{try{const e=x({ttlDays:W,held:m(r.fleet),removeDirs:c(s=>{r.lifecycle.registerDetached(Promise.all(s.map(l=>A(l,{recursive:!0,force:!0}))).then(()=>{}).catch(l=>{o.fresh(()=>{i({level:"error",event:"canvas.retention.failed",error:l})})}))},"removeDirs")});e.pruned.length>0&&i({level:"info",event:"canvas.retention.pruned",outcome:"succeeded",fields:{pruned_count:e.pruned.length}})}catch(e){i({level:"error",event:"canvas.retention.failed",error:e})}}))}scheduleContextStrip(t,r){if(this.contextStripInFlight||t-this.lastContextStripAt<v||!r.lifecycle.acceptsDetachedWork())return;this.lastContextStripAt=t,this.contextStripInFlight=!0;const e=this.stripFinishedContexts(t,r).finally(()=>{this.contextStripInFlight=!1});r.lifecycle.registerDetached(e)}async stripFinishedContexts(t,r){const e=m(r.fleet),s=c(n=>n!==null&&["done","canceled","dead"].includes(n.status)&&(n.pi_pid??null)===null&&(n.frozen_at??null)===null&&(n.run_id??null)===null&&u(n)<t-Y&&!e(n.node_id),"eligible");let l=0,p=0;try{for(const n of h({status:["done","canceled","dead"]})){if(!d(n.node_id)||!s(n))continue;const _=await T(n.node_id);if(_!==null&&_>=u(n)||!s(g(n.node_id)))continue;let a;try{a=await R(n.node_id)}catch(I){o.fresh(()=>{i({level:"warn",event:"canvas.context_strip.node_failed",error:I,fields:{node_id:n.node_id}})});continue}a.removed.length>0&&(l+=1,p+=a.bytes)}}catch(n){o.fresh(()=>{i({level:"error",event:"canvas.context_strip.failed",error:n})})}l>0&&o.fresh(()=>{i({level:"info",event:"canvas.context_strip.completed",outcome:"succeeded",fields:{node_count:l,bytes:p}})})}reapDeadResidue(t){let r;try{r=h({status:["done","canceled","dead"]})}catch(e){o.fresh(()=>{i({level:"error",event:"residue.reap_scan.failed",error:e})});return}for(const e of r)if(!(e.pane==null&&e.window==null&&e.tmux_session==null)){try{if(this.msSinceTerminalActivity(e,t)<M)continue}catch(s){o.fresh(()=>{i({level:"error",event:"residue.reap.failed",...d(e.node_id)?{node_id:e.node_id}:{},error:s,fields:{...d(e.node_id)?{}:{affected_node_id:e.node_id},pane:e.pane,window:e.window,tmux_session:e.tmux_session}})});continue}o.fresh(()=>{try{i({level:"info",event:"residue.reaped",...d(e.node_id)?{node_id:e.node_id}:{},fields:{...d(e.node_id)?{}:{affected_node_id:e.node_id},pane:e.pane,window:e.window,tmux_session:e.tmux_session}}),w(e.node_id)}catch(s){i({level:"error",event:"residue.reap.failed",...d(e.node_id)?{node_id:e.node_id}:{},error:s,fields:{...d(e.node_id)?{}:{affected_node_id:e.node_id},pane:e.pane,window:e.window,tmux_session:e.tmux_session}})}})}}scheduleFocusGc(t){if(this.focusGcInFlight||!t.lifecycle.acceptsDetachedWork())return;this.focusGcInFlight=!0;const r=this.gcStaleFocuses().finally(()=>{this.focusGcInFlight=!1});t.lifecycle.registerDetached(r)}async gcStaleFocuses(){let t;try{t=E()}catch(e){o.fresh(()=>{i({level:"error",event:"focus.gc.failed",error:e})});return}if(t.length===0)return;let r;try{r=await F()}catch(e){o.fresh(()=>{i({level:"error",event:"focus.gc.failed",error:e})});return}if(r!==null)for(const e of t){if(e.pane===null||r.has(e.pane))continue;if(!o.fresh(()=>{try{return N(e.focus_id)?.pane!==e.pane||(i({level:"info",event:"focus.gc.removed",...d(e.node_id)?{node_id:e.node_id}:{},fields:{focus_id:e.focus_id,focus_node_id:e.node_id,pane:e.pane}}),y(e.focus_id)),!0}catch(l){return i({level:"error",event:"focus.gc.failed",error:l}),!1}}))return}}gcWarmPool(t){t-this.lastSpareSweepAt<V||(this.lastSpareSweepAt=t,o.fresh(()=>{const r=D();r.length>0&&i({level:"info",event:"warm_pool.spares_reaped",outcome:"succeeded",fields:{reaped_count:r.length}})}))}}export{Y as CONTEXT_STRIP_GRACE_MS,M as DEAD_REAP_GRACE_MS,v as RETENTION_SWEEP_INTERVAL_MS,W as RETENTION_TTL_DAYS,ee as StorageMaintenanceReconciler};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var
|
|
1
|
+
var a=Object.defineProperty;var d=(e,n)=>a(e,"name",{value:n,configurable:!0});import{formatCard as r}from"../../shared/generated-context.js";function c(e,n){const o=e.document_name!==null?e.changed?`The user reviewed and approved \`${e.document_name}\`. Their edits are saved as a new revision; re-read it with \`crtr canvas read ${e.document_name}\` before continuing. Review conversation: node \`${e.companion_node_id}\`.`:`The user reviewed and approved \`${e.document_name}\`. The document was not modified.`:e.changed?`The user reviewed and approved \`${e.file}\`. The document changed during review; re-read it before continuing. Review conversation: node \`${e.companion_node_id}\`.`:`The user reviewed and approved \`${e.file}\`. The document was not modified.`;return r("review-approval",{},`${o}
|
|
2
2
|
|
|
3
|
-
Durable review result: ${
|
|
3
|
+
Durable review result: ${n}`)}d(c,"renderApprovalMessage");export{c as renderApprovalMessage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var g=Object.defineProperty;var n=(e,t)=>g(e,"name",{value:t,configurable:!0});import{withCanvasWrite as j}from"../../core/canvas/db.js";import{get as S}from"../../core/graph/bodies.js";import{documentById as q,editDocument as C,heads as $}from"../../core/graph/documents.js";import{readerFor as J}from"../../core/graph/reader.js";import{reposForCwd as k}from"../../core/graph/repo-sync/repos.js";import{snapshotCommentsLocked as x}from"../../core/review/comments.js";import{readReviewSource as N}from"../../core/review/document.js";import{projectReviewCancellation as O,projectReviewResult as T,buildReviewResult as A}from"../../core/review/project.js";import{signalReviewActivity as p}from"../../core/review/signal.js";import{clearReviewSubmit as D,getReview as E,getReviewByCompanion as B,requestReviewSubmit as F,requireVisibleReview as u}from"../../core/review/store.js";import{ReviewOperationError as f}from"../../core/review/types.js";import{settleHumanRequest as w}from"../human/settle.js";import{retireCompanion as h}from"../companion-retire.js";import{companionHasQueuedWork as W,companionMidTurn as H,companionStillWorking as M}from"./companion.js";import{renderApprovalMessage as L}from"./deliver.js";function _(){return new Date().toISOString()}n(_,"now");function l(e,t){throw new f("review_terminal","review already has a terminal outcome",{state:e.state,requested:t,review:e})}n(l,"terminalConflict");function v(e){if(e.result_json===null)throw new Error(`approved review lacks its immutable result: ${e.review_id}`);return JSON.parse(e.result_json)}n(v,"approvedResult");function y(e){return`${e.review_dir}/result.json`}n(y,"resultPath");function P(e){return{project:n(t=>{T(u(t.request_id),e)},"project"),retire:n(async(t,o)=>{await h(t,o)},"retire")}}n(P,"effects");function Q(e){return{label:"review approved by the user",disposition:"human-answer",body_json:{review_id:e.review_id,result_path:y(e),body:L(e,y(e))}}}n(Q,"approvalNotification");function V(e,t,o){const s=o==="dismissed";return{label:s?"review dismissed":"review canceled",disposition:"human-canceled",body_json:{review_id:e.review_id,disposition:o,body:s?`The review of \`${e.document_name??e.file}\` was dismissed without approval.`:`The review of \`${e.document_name??e.file}\` was canceled${t===""?"":` \u2014 ${t}`}.`}}}n(V,"cancellationNotification");function z(e,t,o){if(t.document_id===null||t.document_base===null)return;const s=n(d=>k(e,d),"reposFn"),i=q(e,t.document_id),a=J(e,{class:"person"},s),c=C(e,a,i,{body:o},`edited in review ${t.review_id}`,t.document_base,{},s);if(!("stale"in c))return;const r=$(e,i);if(!(r.length===1&&S(r[0].body_hash)===o))throw new f("stale_revision",`${t.document_name??i.name} changed since the review began; the reviewed text was not saved`,{review_id:t.review_id,document:t.document_name??i.name,base:t.document_base,heads_key:c.stale.heads_key,revision:c.stale.revision,next:`Read the current revision with \`crtr canvas read ${i.id}\`, then start a new review of it.`})}n(z,"saveReviewedDocument");async function b(e){if(e.state==="canceled")return l(e,"submit");if(e.state==="approved")return{outcome:"already_settled",record:e,result:v(e)};const t=N(e.file,"submit"),{result:o,resultJson:s}=j(c=>{const r=u(e.review_id);if(r.state==="canceled")return l(r,"submit");if(r.state==="approved")return{result:v(r),resultJson:r.result_json};const d=x(c,r.review_id),m=A(r,d,t.sha256,_());return m.changed&&z(c,r,new TextDecoder("utf-8").decode(t.bytes)),{result:m,resultJson:JSON.stringify(m)}}),i=await w({request_id:e.review_id,outcome:"approved",result_json:s,notification:Q({...e,changed:o.changed}),post_commit:P(o)});i.outcome==="settled"&&p();const a=u(e.review_id);return i.outcome==="already_settled"&&a.state!=="approved"?l(a,"submit"):{outcome:i.outcome,record:a,result:i.outcome==="settled"?o:v(a)}}n(b,"approveReview");async function de(e){const t=u(e);return t.state==="canceled"?l(t,"submit"):t.state==="open"&&M(t.companion_node_id)?(F(e,_())&&p(),{outcome:"awaiting_companion",record:u(e)}):b(t)}n(de,"submitReviewApproval");async function G(e,t){const o=E(e);if(o===null||o.state!=="open"||o.submit_requested_at===null||W(o.companion_node_id)||!t.atCompanionTurnEnd&&H(o.companion_node_id))return null;try{return await b(o)}catch(s){throw s instanceof f&&s.code==="stale_revision"&&(D(e),p()),s}}n(G,"completeRequestedSubmit");async function me(e){const t=B(e);return t===null?null:G(t.review_id,{atCompanionTurnEnd:!0})}n(me,"completeCompanionRequestedSubmit");async function le(e,t={}){const o=u(e);if(o.state==="approved")return l(o,"cancel");const s=_(),i=t.reason??"",a=t.disposition??"canceled",c=JSON.stringify({schema:"humanloop.cancel/v1",kind:"canceled",canceledAt:s,...i===""?{}:{reason:i},...t.actor===void 0?{}:{actor:t.actor},...a==="dismissed"?{disposition:a}:{}}),r=await w({request_id:e,outcome:a==="dismissed"?"dismissed":"canceled",result_json:c,notification:V(o,i,a),post_commit:{project:n(m=>{O(u(m.request_id),JSON.parse(c))},"project"),retire:n(async(m,R)=>{await h(m,R)},"retire")}});r.outcome==="settled"&&p();const d=u(e);return r.outcome==="already_settled"&&d.state==="approved"?l(d,"cancel"):{outcome:r.outcome,record:d}}n(le,"cancelReview");export{le as cancelReview,me as completeCompanionRequestedSubmit,G as completeRequestedSubmit,de as submitReviewApproval};
|
package/dist/hook-authoring.d.ts
CHANGED
package/dist/hook-authoring.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
var B=Object.defineProperty;var o=(e,r)=>B(e,"name",{value:r,configurable:!0});import{spawn as R}from"node:child_process";import{Console as T}from"node:console";import{posixProcessGroupSpawnOptions as M,terminateProcessGroup as j}from"./hook-process.js";function d(e,r,t={}){return{protocolVersion:1,ok:!1,error:{code:e,message:r,...t}}}o(d,"hookError");async function X(e,r={}){const t=r.stdin??process.stdin,s=r.stdout??process.stdout,i=r.stderr??process.stderr;let c;try{const m=await
|
|
1
|
+
var B=Object.defineProperty;var o=(e,r)=>B(e,"name",{value:r,configurable:!0});import{spawn as R}from"node:child_process";import{Console as T}from"node:console";import{posixProcessGroupSpawnOptions as M,terminateProcessGroup as j}from"./hook-process.js";function d(e,r,t={}){return{protocolVersion:1,ok:!1,error:{code:e,message:r,...t}}}o(d,"hookError");async function X(e,r={}){const t=r.stdin??process.stdin,s=r.stdout??process.stdout,i=r.stderr??process.stderr;let c;try{const m=await C(t);let p;try{p=JSON.parse(m)}catch{c=d("invalid_hook_request","stdin must contain one JSON hook request"),_(s,c);return}const f=A(p);if(!f.valid){c=d("invalid_hook_request",f.message),_(s,c);return}const g=e[f.value.op];if(g===void 0){c=d("unsupported_hook_op",`no handler is registered for ${f.value.op}`),_(s,c);return}try{c=await H(i,()=>g(f.value))}catch(h){i.write(`hook handler ${f.value.op} failed: ${b(h)}
|
|
2
2
|
`),c=d("hook_handler_failed",`handler failed for ${f.value.op}`)}const a=I(c,f.value);a.valid||(i.write(`hook handler ${f.value.op} returned an invalid response: ${a.message}
|
|
3
3
|
`),c=d("invalid_hook_response",a.message))}catch(m){i.write(`hook executable failed: ${b(m)}
|
|
4
|
-
`),c=d("hook_executable_failed","hook executable could not read its request")}_(s,c)}o(X,"runHookExecutable");async function Y(e,r){const t=e[0];return t===void 0||t===""?d("local_process_invalid","local process argv[0] must not be empty"):!Number.isFinite(r.timeoutMs)||r.timeoutMs<=0?d("local_process_invalid_options","timeoutMs must be greater than zero"):new Promise(s=>{let i=!1,c=!1,m=!1,p=!1,f;const g=[],a=o(u=>{i||(i=!0,f!==void 0&&clearTimeout(f),s(u))},"settle");let h;try{h=R(t,e.slice(1),{cwd:r.cwd,env:r.env,shell:!1,stdio:[r.input===void 0?"ignore":"pipe","pipe","inherit"],...M()})}catch(u){a(d("local_process_spawn_failed",`could not start ${t}: ${b(u)}`));return}const x=o(()=>{c&&m&&p&&a(d("local_process_timeout",`${t} did not finish within ${r.timeoutMs}ms`))},"settleTimeout");f=setTimeout(()=>{c=!0,j(h).then(()=>{p=!0,x()},u=>{p=!0,a(d("local_process_cleanup_failed",`could not stop ${t}: ${b(u)}`))})},r.timeoutMs),h.stdout.on("data",u=>g.push(u)),h.once("error",u=>{h.pid===void 0&&a(d("local_process_spawn_failed",`could not start ${t}: ${b(u)}`))}),h.once("close",(u,$)=>{if(m=!0,c){x();return}if(u===0){a({ok:!0,stdout:Buffer.concat(g).toString("utf8")});return}const V=$===null?`exit code ${u??"unknown"}`:`signal ${$}`;a(d("local_process_failed",`${t} exited with ${V}`))}),r.input!==void 0&&h.stdin!==null&&h.stdin.end(r.input)})}o(Y,"runLocalHookProcess");async function Z(e,r,t){if(!Number.isFinite(t.timeoutMs)||t.timeoutMs<=0)return d("hook_forward_invalid_options","timeoutMs must be greater than zero");if(!Number.isSafeInteger(t.maxResponseBytes)||t.maxResponseBytes<=0)return d("hook_forward_invalid_options","maxResponseBytes must be a positive integer");const s=new Headers(t.headers);s.has("content-type")||s.set("content-type","application/json"),t.bearer!==void 0&&s.set("authorization",`Bearer ${t.bearer}`);const i=new AbortController;let c=!1;const m=setTimeout(()=>{c=!0,i.abort()},t.timeoutMs);try{const p=await fetch(e,{method:"POST",headers:s,body:JSON.stringify(r),signal:i.signal}),f=await
|
|
5
|
-
`)}o(_,"writeResponse");async function
|
|
4
|
+
`),c=d("hook_executable_failed","hook executable could not read its request")}_(s,c)}o(X,"runHookExecutable");async function Y(e,r){const t=e[0];return t===void 0||t===""?d("local_process_invalid","local process argv[0] must not be empty"):!Number.isFinite(r.timeoutMs)||r.timeoutMs<=0?d("local_process_invalid_options","timeoutMs must be greater than zero"):new Promise(s=>{let i=!1,c=!1,m=!1,p=!1,f;const g=[],a=o(u=>{i||(i=!0,f!==void 0&&clearTimeout(f),s(u))},"settle");let h;try{h=R(t,e.slice(1),{cwd:r.cwd,env:r.env,shell:!1,stdio:[r.input===void 0?"ignore":"pipe","pipe","inherit"],...M()})}catch(u){a(d("local_process_spawn_failed",`could not start ${t}: ${b(u)}`));return}const x=o(()=>{c&&m&&p&&a(d("local_process_timeout",`${t} did not finish within ${r.timeoutMs}ms`))},"settleTimeout");f=setTimeout(()=>{c=!0,j(h).then(()=>{p=!0,x()},u=>{p=!0,a(d("local_process_cleanup_failed",`could not stop ${t}: ${b(u)}`))})},r.timeoutMs),h.stdout.on("data",u=>g.push(u)),h.once("error",u=>{h.pid===void 0&&a(d("local_process_spawn_failed",`could not start ${t}: ${b(u)}`))}),h.once("close",(u,$)=>{if(m=!0,c){x();return}if(u===0){a({ok:!0,stdout:Buffer.concat(g).toString("utf8")});return}const V=$===null?`exit code ${u??"unknown"}`:`signal ${$}`;a(d("local_process_failed",`${t} exited with ${V}`))}),r.input!==void 0&&h.stdin!==null&&h.stdin.end(r.input)})}o(Y,"runLocalHookProcess");async function Z(e,r,t){if(!Number.isFinite(t.timeoutMs)||t.timeoutMs<=0)return d("hook_forward_invalid_options","timeoutMs must be greater than zero");if(!Number.isSafeInteger(t.maxResponseBytes)||t.maxResponseBytes<=0)return d("hook_forward_invalid_options","maxResponseBytes must be a positive integer");const s=new Headers(t.headers);s.has("content-type")||s.set("content-type","application/json"),t.bearer!==void 0&&s.set("authorization",`Bearer ${t.bearer}`);const i=new AbortController;let c=!1;const m=setTimeout(()=>{c=!0,i.abort()},t.timeoutMs);try{const p=await fetch(e,{method:"POST",headers:s,body:JSON.stringify(r),signal:i.signal}),f=await J(p,t.maxResponseBytes);let g;try{g=JSON.parse(f)}catch{return d("hook_forward_invalid_response",`hook endpoint returned invalid JSON (HTTP ${p.status})`)}const a=I(g,r);return a.valid?a.value:d("hook_forward_invalid_response",`${a.message} (HTTP ${p.status})`)}catch(p){return c?d("hook_forward_timeout",`hook endpoint did not respond within ${t.timeoutMs}ms`):p instanceof N?d("hook_forward_response_too_large",`hook endpoint exceeded ${t.maxResponseBytes} response bytes`):d("hook_forward_failed",`hook endpoint request failed: ${b(p)}`)}finally{clearTimeout(m)}}o(Z,"forwardHook");const O=["log","info","debug","dir","table","group","groupCollapsed"];async function H(e,r){const t=new T({stdout:e,stderr:e,colorMode:!1}),s=new Map;for(const i of O)s.set(i,console[i]),console[i]=t[i].bind(t);try{return await r()}finally{for(const i of O)console[i]=s.get(i)}}o(H,"withConsoleStdoutOnStderr");function _(e,r){e.write(`${JSON.stringify(r)}
|
|
5
|
+
`)}o(_,"writeResponse");async function C(e){const r=[];for await(const t of e)r.push(Buffer.isBuffer(t)?t:Buffer.from(t));return Buffer.concat(r).toString("utf8")}o(C,"readStream");async function J(e,r){if(e.body===null)return"";const t=e.body.getReader(),s=[];let i=0;try{for(;;){const{done:c,value:m}=await t.read();if(c)break;if(i+=m.byteLength,i>r)throw await t.cancel(),new N;s.push(m)}}finally{t.releaseLock()}return new TextDecoder().decode(P(s,i))}o(J,"readResponseBody");function P(e,r){const t=new Uint8Array(r);let s=0;for(const i of e)t.set(i,s),s+=i.byteLength;return t}o(P,"concatBytes");function A(e){return y(e)?e.protocolVersion!==1?n("unsupported hook protocol version"):typeof e.op!="string"||e.op===""?n("op must be a non-empty string"):typeof e.operationId!="string"||!/^[0-9a-f]{32}$/.test(e.operationId)?n("operationId must be a 32-character lowercase hexadecimal string"):e.event==="node:create"?l(e,["protocolVersion","op","event","phase","operationId","create","runtime","context"])?e.phase!=="before"?n("node:create phase must be before"):E(e.create)?L(e.runtime)?q(e.context)?w({protocolVersion:1,op:e.op,event:"node:create",phase:"before",operationId:e.operationId,create:e.create,runtime:e.runtime,context:e.context}):n("node:create request context must contain cwd"):n("node:create request runtime contains invalid fields"):n("node:create request create contains invalid fields"):n("node:create request contains unknown fields"):e.phase==="on"?l(e,["protocolVersion","op","event","phase","operationId","node","runtime","context"])?e.event!=="node:start"&&e.event!=="node:close"?n("unsupported lifecycle event"):z(e.node)?F(e.runtime)?q(e.context)?w({protocolVersion:1,op:e.op,event:e.event,phase:"on",operationId:e.operationId,node:e.node,runtime:e.runtime,context:e.context}):n("lifecycle request context must contain cwd"):n("lifecycle request runtime contains invalid fields"):n("lifecycle request node contains invalid fields"):n("lifecycle request contains unknown fields"):l(e,["protocolVersion","op","phase","command","operationId","input","context","result"])?!S(e.command)||e.command.length===0?n("command must be a non-empty string array"):!y(e.input)||!k(e.input)?n("input must be a JSON object"):D(e.context)?e.phase==="after"?!Object.hasOwn(e,"result")||!k(e.result)?n("after requests require a JSON result"):w({protocolVersion:1,op:e.op,phase:"after",command:e.command,operationId:e.operationId,input:e.input,context:e.context,result:e.result}):e.phase!=="before"&&e.phase!=="replace"?n("phase must be before, after, or replace"):Object.hasOwn(e,"result")?n("only after requests may contain result"):e.phase==="before"?w({protocolVersion:1,op:e.op,phase:"before",command:e.command,operationId:e.operationId,input:e.input,context:e.context}):w({protocolVersion:1,op:e.op,phase:"replace",command:e.command,operationId:e.operationId,input:e.input,context:e.context}):n("context must contain cwd and providedParams"):n("request contains unknown fields"):n("request must be an object")}o(A,"validateRequest");function I(e,r){if(!y(e))return n("response must be an object");if(e.protocolVersion!==1)return n("response has an unsupported hook protocol version");if(e.ok===!0){if(!l(e,["protocolVersion","ok","result"]))return n("successful response contains unknown fields");const t=Object.hasOwn(e,"result");if(r.phase==="replace"&&!t)return n("replace response requires result");if(r.phase!=="replace"&&t)return n("only replace responses may contain result");if(t){const s=e.result;return k(s)?w({protocolVersion:1,ok:!0,result:s}):n("response result must be JSON")}return w({protocolVersion:1,ok:!0})}return e.ok!==!1||!l(e,["protocolVersion","ok","error"])?n("response must contain protocolVersion, ok, and error or result"):G(e.error)?w({protocolVersion:1,ok:!1,error:e.error}):n("response error must contain code and message strings")}o(I,"validateResponse");function D(e){return y(e)&&l(e,["cwd","providedParams"])&&typeof e.cwd=="string"&&S(e.providedParams)}o(D,"isContext");function q(e){return y(e)&&l(e,["cwd"])&&typeof e.cwd=="string"}o(q,"isLifecycleContext");function E(e){return y(e)&&l(e,["kind","mode","cwd","profile","root","parentId","requestingNodeId","lifecycle","replaces"])&&typeof e.kind=="string"&&typeof e.mode=="string"&&typeof e.cwd=="string"&&(typeof e.profile=="string"||e.profile===null)&&typeof e.root=="boolean"&&(typeof e.parentId=="string"||e.parentId===null)&&(typeof e.requestingNodeId=="string"||e.requestingNodeId===null)&&(e.lifecycle==="resident"||e.lifecycle==="terminal")&&(typeof e.replaces=="string"||e.replaces===null)}o(E,"isNodeCreate");function L(e){return y(e)&&l(e,["canvasHome","profile"])&&typeof e.canvasHome=="string"&&(typeof e.profile=="string"||e.profile===null)}o(L,"isCreateRuntime");function z(e){return y(e)&&l(e,["id","name","kind","mode","lifecycle","cwd","nodeDir","contextDir","jobDir"])&&["id","name","kind","mode","lifecycle","cwd","nodeDir","contextDir","jobDir"].every(r=>typeof e[r]=="string")}o(z,"isLifecycleNode");function F(e){return y(e)&&l(e,["isBirth","canvasHome","profile"])&&typeof e.isBirth=="boolean"&&typeof e.canvasHome=="string"&&(typeof e.profile=="string"||e.profile===null)}o(F,"isLifecycleRuntime");function G(e){return y(e)&&l(e,["code","message","field","next"])&&typeof e.code=="string"&&e.code!==""&&typeof e.message=="string"&&e.message!==""&&(e.field===void 0||typeof e.field=="string")&&(e.next===void 0||typeof e.next=="string")}o(G,"isHookError");function y(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}o(y,"isRecord");function S(e){return Array.isArray(e)&&e.every(r=>typeof r=="string")}o(S,"isStringArray");function k(e){return e===null||typeof e=="boolean"||typeof e=="string"?!0:typeof e=="number"?Number.isFinite(e):Array.isArray(e)?e.every(k):y(e)&&Object.values(e).every(k)}o(k,"isJson");function l(e,r){return Object.keys(e).every(t=>r.includes(t))}o(l,"hasOnlyKeys");function w(e){return{valid:!0,value:e}}o(w,"valid");function n(e){return{valid:!1,message:e}}o(n,"invalid");function b(e){return e instanceof Error?e.message:String(e)}o(b,"describeError");class N extends Error{static{o(this,"ResponseTooLargeError")}}export{Z as forwardHook,d as hookError,X as runHookExecutable,Y as runLocalHookProcess};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { DatabaseSync } from 'node:sqlite';
|
|
2
|
+
import type { ImportPlan, ImportReport } from './plan.js';
|
|
3
|
+
/** The canvas_meta key whose presence means this home's legacy stores were imported. */
|
|
4
|
+
export declare const IMPORT_DONE_KEY = "canvas-import";
|
|
5
|
+
export declare const IMPORT_ID = "004-canvas-documents";
|
|
6
|
+
export declare function readImportRecord(db: DatabaseSync): ImportReport | null;
|
|
7
|
+
/** Store every revision body. Call before `applyPlan`, outside its transaction. */
|
|
8
|
+
export declare function storePlanBodies(plan: ImportPlan): Map<string, string>;
|
|
9
|
+
/** Run inside the caller's write transaction. Throws on any divergence from the plan. */
|
|
10
|
+
export declare function applyPlan(db: DatabaseSync, plan: ImportPlan, hashes: ReadonlyMap<string, string>): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var x=Object.defineProperty;var d=(n,t)=>x(n,"name",{value:t,configurable:!0});import{put as N}from"../../core/graph/bodies.js";import{importDocument as O}from"../../core/graph/documents.js";import{linksIn as _}from"../../core/graph/documents.js";import{recordActedOn as M,setLinks as R}from"../../core/graph/edges.js";import{resolveName as $}from"../../core/graph/names.js";import{ensureOwner as y,nodeObject as k,ownerForGrantee as b}from"../../core/graph/objects.js";import{ensureRepo as S}from"../../core/graph/repo-sync/repos.js";import{recordWatch as T}from"../../core/graph/watches.js";const v="canvas-import",K="004-canvas-documents";function C(n){const t=n.prepare("SELECT value FROM canvas_meta WHERE key = ?").get(v);if(t===void 0)return null;const p=JSON.parse(t.value).report;return{...p,resolutions:p.resolutions??[]}}d(C,"readImportRecord");function G(n){const t=new Map;for(const p of n.documents)for(const i of p.revisions)t.has(i.body)||t.set(i.body,N(i.body));return t}d(G,"storePlanBodies");function U(n,t,p){const i=new Map(t.owners.map(e=>[e.key,e])),f=new Map,u=d(e=>{const o=f.get(e.key);if(o)return o;let r;switch(e.type){case"person":r=b(n,"user:local");break;case"app":r=y(n,"app","app",`app:${e.handle}`,e.handle);break;case"profile":{const c=i.get(e.ownerKey);if(!c)throw new Error(`import: profile ${e.key} names unplanned app ${e.ownerKey}`);r=y(n,"profile","profile",e.key.slice(8),e.handle,u(c));break}case"repo":r=S(n,{scheme:e.scheme,externalId:e.externalId,handleHint:e.handle},e.handle);break;case"node":r=k(n,e.handle);break}if(e.type!=="node"&&r.name!==e.handle)throw new Error(`import: owner ${e.key} holds handle ${r.name}, planned ${e.handle}`);return f.set(e.key,r),r},"ownerRow"),I={class:"person",person:u(i.get("person")??{key:"person",type:"person",handle:"user"})},h=new Map,m=d(e=>{let o=h.get(e);return o||h.set(e,o=k(n,e)),o},"node"),w=[];for(const e of t.documents){const o=u(i.get(e.ownerKey)),r=O(n,{owner:o,name:e.name,kind:e.kind,preview:e.preview,privacy:e.privacy,summary:e.summary,whyItExists:e.whyItExists,unlisted:e.unlisted,rules:e.rules,lintIgnore:e.lintIgnore,extensions:e.extensions,revisions:e.revisions.map(s=>({body_hash:p.get(s.body),author:s.authorNodeId===null?null:m(s.authorNodeId),rationale:s.rationale,created_at:s.createdAt}))}),c=new Set(e.revisions.flatMap(s=>s.authorNodeId===null?[]:[s.authorNodeId]));w.push({doc:r,owner:o,body:e.revisions[e.revisions.length-1].body,authors:c})}for(const{doc:e,owner:o,body:r,authors:c}of w){const s=[];for(const a of _(r)){const g=a.includes("/")?[a]:[`${o.type==="node"?o.id:o.name}/${a}`,a];for(const E of g){const l=$(n,I,E);if("object"in l){s.push({written_as:a,dst:l.object});break}if("deleted"in l){s.push({written_as:a,dst:l.deleted});break}}}R(n,e,s);for(const a of c)M(n,m(a),e),T(n,m(a),e,"write")}n.prepare("INSERT INTO canvas_meta (key, value) VALUES (?, ?)").run(v,JSON.stringify({id:K,report:t.report}))}d(U,"applyPlan");export{v as IMPORT_DONE_KEY,K as IMPORT_ID,U as applyPlan,C as readImportRecord,G as storePlanBodies};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Privacy, RuleSpec } from '../../core/graph/types.js';
|
|
2
|
+
export type DocumentKind = 'knowledge' | 'preference' | 'report';
|
|
3
|
+
export interface DocumentFields {
|
|
4
|
+
kind: DocumentKind;
|
|
5
|
+
privacy: Privacy;
|
|
6
|
+
preview: string;
|
|
7
|
+
summary: string | null;
|
|
8
|
+
whyItExists: string | null;
|
|
9
|
+
unlisted: boolean;
|
|
10
|
+
lintIgnore: unknown;
|
|
11
|
+
extensions: unknown;
|
|
12
|
+
rules: RuleSpec[];
|
|
13
|
+
/** Frontmatter keys with no document field; listed in the report. */
|
|
14
|
+
dropped: string[];
|
|
15
|
+
}
|
|
16
|
+
/** First non-empty body line, with a leading markdown heading or list marker removed. */
|
|
17
|
+
export declare function firstLine(body: string): string;
|
|
18
|
+
/** `missingPrivacy` is what a document without a valid `privacy` key gets. */
|
|
19
|
+
export declare function documentFields(fm: Record<string, unknown> | null, body: string, opts: {
|
|
20
|
+
kind?: DocumentKind;
|
|
21
|
+
missingPrivacy: Privacy;
|
|
22
|
+
}): DocumentFields;
|
|
23
|
+
/** AND `extra` into every rule's `if` (private repo documents re-owned to the person). */
|
|
24
|
+
export declare function andIntoRules(rules: RuleSpec[], extra: Record<string, unknown>): RuleSpec[];
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var c=Object.defineProperty;var r=(e,t)=>c(e,"name",{value:t,configurable:!0});import{rulesFromFrontmatter as u}from"../../core/graph/rules.js";const f=new Set(["kind","privacy","unlisted","lint-ignore","extensions","when-and-why-to-read","short-form","rationale","surfaces","gate","slash","origin","last-updated","name","namespace"]),p=["public","friends","private"],s=r(e=>typeof e=="string"&&e.trim()!==""?e.trim():null,"str");function m(e){for(const t of e.split(`
|
|
2
|
+
`)){const i=t.trim().replace(/^#+\s*/,"").replace(/^[-*]\s+/,"").trim();if(i!==""&&i!=="---")return i}return""}r(m,"firstLine");function g(e,t,i){const n=e??{},o=Object.keys(n).filter(a=>!f.has(a));let l=i.kind??"knowledge";i.kind===void 0&&n.kind!==void 0&&(n.kind==="knowledge"||n.kind==="preference"?l=n.kind:o.push("kind"));const d=typeof n.privacy=="string"&&p.includes(n.privacy)?n.privacy:i.missingPrivacy;return{kind:l,privacy:d,preview:s(n["when-and-why-to-read"])?.replace(/\s+/g," ")??m(t),summary:s(n["short-form"]),whyItExists:s(n.rationale),unlisted:n.unlisted===!0,lintIgnore:n["lint-ignore"]??null,extensions:n.extensions??null,rules:u(n),dropped:o}}r(g,"documentFields");function h(e,t){return e.map(i=>({...i,if:i.if===void 0?t:{all:[i.if,t]}}))}r(h,"andIntoRules");export{h as andIntoRules,g as documentFields,m as firstLine};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type ImportBlocker, type ImportReport } from './plan.js';
|
|
2
|
+
export type { ImportBlocker, ImportReport } from './plan.js';
|
|
3
|
+
export interface CanvasImportResult {
|
|
4
|
+
report: ImportReport;
|
|
5
|
+
blockers: ImportBlocker[];
|
|
6
|
+
dryRun: boolean;
|
|
7
|
+
/** True while this home still has to be imported (always false after a write run succeeds). */
|
|
8
|
+
pending: boolean;
|
|
9
|
+
}
|
|
10
|
+
/** Whether this home's import has already been recorded. */
|
|
11
|
+
export declare function canvasImportDone(): boolean;
|
|
12
|
+
/** Plan and (unless `dryRun` or blocked) apply the import. On an imported home a dry run
|
|
13
|
+
* returns the recorded report; a write run does nothing and returns empty counts. */
|
|
14
|
+
export declare function runCanvasImport(opts: {
|
|
15
|
+
dryRun: boolean;
|
|
16
|
+
}): CanvasImportResult;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var g=Object.defineProperty;var a=(e,n)=>g(e,"name",{value:n,configurable:!0});import{existsSync as f}from"node:fs";import{join as l}from"node:path";import{openDb as c,withCanvasWrite as w}from"../../core/canvas/db.js";import{nodeAgentDir as k,nodeRecordDir as S,onDiskMigrationMarkerPath as C}from"../../core/canvas/paths.js";import{identifyCheckout as j}from"../../core/graph/repo-sync/identity.js";import{profileSpace as I,userRoot as b}from"../../core/layout.js";import{commitConvertedProjectCaps as E,listLegacyProjectCaps as P,listStoredProfiles as x}from"../../core/scoped-state/profiles.js";import{userStore as L}from"../../core/scoped-state/paths.js";import{userScopeRoot as y}from"../../core/scope.js";import{applyPlan as M,readImportRecord as h,storePlanBodies as _}from"./apply.js";import{readLegacyCorpus as v,readMarkerIds as D}from"./legacy/discover.js";import{planImport as O}from"./plan.js";const F=a(()=>({stores:[],counts:{},rewrites:[],droppedFields:[],skipped:[],resolutions:[]}),"emptyReport");function A(){const e=y(),n=x(e),o=P(e),m=L(e).path,i=n.map(({profileId:r,manifest:s})=>{const p=s.grantee??"app:terminal",d=new Map(o.filter(t=>t.profileId===r).map(t=>[t.path,t.memory]));return{id:r,name:s.name,app:p,memory:I(p,r).memory,projects:s.projects.map(t=>t.path),raw:{projects:s.projects.map(t=>d.has(t.path)?{path:t.path,memory:d.get(t.path)}:{path:t.path})},manifestPath:`${m}#${r}`}}),u=c().prepare("SELECT node_id, cwd, grantee FROM node_rows ORDER BY created").all(),R=u.map(r=>{const s=r.grantee==="user:local"?"app:terminal":r.grantee,p=s?.startsWith("app:")?k(r.node_id,s):null,d=p!==null&&(f(l(p,"context"))||f(l(p,"reports")))?p:S(r.node_id);return{id:r.node_id,dir:d}});return{roots:{userMemory:l(b(),"memory"),profiles:i,nodeCwds:[...new Set(u.map(r=>r.cwd))],nodes:R},stored:n}}a(A,"legacyRoots");function N(){const{roots:e,stored:n}=A(),o=v(e),m=c().prepare(`SELECT o.type, o.name AS handle, i.external_id AS externalId FROM objects o
|
|
2
|
+
LEFT JOIN identities i ON i.object = o.rowid WHERE o.type IN ('person','app','repo','profile')`).all();return O(o,{roots:e,markerIds:D(C()),repoIdentity:j,existingOwners:m,storedProfiles:n.map(i=>({id:i.profileId,deliveryLimits:{...i.manifest.delivery_limits??{}}}))})}a(N,"plan");function V(){return h(c())!==null}a(V,"canvasImportDone");function X(e){const n=h(c());if(n!==null)return{report:e.dryRun?n:F(),blockers:[],dryRun:e.dryRun,pending:!1};const o=N();if(e.dryRun||o.blockers.length>0)return{report:o.report,blockers:o.blockers,dryRun:e.dryRun,pending:!0};const m=_(o);return E(y(),o.profileLimits),w(i=>M(i,o,m)),{report:o.report,blockers:[],dryRun:!1,pending:!1}}a(X,"runCanvasImport");export{V as canvasImportDone,X as runCanvasImport};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { LegacyCorpus, LegacyProfile, LegacyRoots } from './types.js';
|
|
2
|
+
export type { LegacyCorpus, LegacyDoc, LegacyOwnerRef, LegacyProfile, LegacyRoots, LegacyStoreRoot, LegacyHistoryRecord } from './types.js';
|
|
3
|
+
/** Every stored profile manifest, read as raw JSON (the current manifest reader
|
|
4
|
+
* is not used). `memoryFor(app, id)` resolves the profile's store path. */
|
|
5
|
+
export declare function readLegacyProfiles(profilesRoot: string, memoryFor: (app: string, id: string) => string): {
|
|
6
|
+
profiles: LegacyProfile[];
|
|
7
|
+
skipped: Array<{
|
|
8
|
+
path: string;
|
|
9
|
+
reason: string;
|
|
10
|
+
}>;
|
|
11
|
+
};
|
|
12
|
+
/** Ids listed in `<canvas home>/on-disk-migrations.json`, or null when the marker is absent. */
|
|
13
|
+
export declare function readMarkerIds(markerPath: string): string[] | null;
|
|
14
|
+
export declare function readLegacyCorpus(roots: LegacyRoots): LegacyCorpus;
|
|
15
|
+
/** Cheap probe: is there any legacy document to import? */
|
|
16
|
+
export declare function hasLegacyContent(roots: LegacyRoots): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var J=Object.defineProperty;var l=(t,o)=>J(t,"name",{value:o,configurable:!0});import{existsSync as D,readdirSync as b,readFileSync as x,realpathSync as P,statSync as R}from"node:fs";import{basename as T,dirname as C,isAbsolute as L,join as i,relative as A,resolve as F}from"node:path";import{walkFiles as I}from"../../../core/fs-utils.js";import{historyLogPath as O,HISTORY_DIR as z,readHistory as X}from"./history.js";import{walkNestedStores as W}from"./nested.js";import{contextDocName as _,parseFile as $,rawFile as E,storeDocName as q}from"./parse.js";const G=/^[a-z0-9]+(?:-[a-z0-9]+)*-[0-9a-f]{8}$/;function k(t){try{return P(t)}catch{return F(t)}}l(k,"real");const w=l(t=>{try{return R(t).isDirectory()}catch{return!1}},"isDir"),Y=l(t=>["canvas","canvas.db","runtime","profiles"].some(o=>D(i(t,o))),"isCrouterHome"),H=l(t=>I(t,o=>o.toLowerCase().endsWith(".md"),o=>o.startsWith(".")).sort(),"markdownIn");function re(t,o){const s=[],y=[];if(!w(t))return{profiles:s,skipped:y};for(const j of b(t).sort()){const d=i(t,j,"profile.json");if(!G.test(j)||!D(d))continue;let h;try{const p=JSON.parse(x(d,"utf8"));if(p===null||typeof p!="object"||Array.isArray(p))throw new Error("not a JSON object");h=p}catch(p){y.push({path:d,reason:`invalid-manifest: ${p.message}`});continue}const v=typeof h.grantee=="string"?h.grantee:"app:terminal",M=Array.isArray(h.projects)?h.projects.flatMap(p=>typeof p=="string"?[p]:p!==null&&typeof p=="object"&&typeof p.path=="string"?[p.path]:[]):[];s.push({id:j,name:typeof h.name=="string"?h.name:j,app:v,memory:o(v,j),projects:M,raw:h,manifestPath:d})}return{profiles:s,skipped:y}}l(re,"readLegacyProfiles");function ne(t){if(!D(t))return null;const o=JSON.parse(x(t,"utf8"));if(!Array.isArray(o))throw new Error(`${t}: not a JSON array`);return o.map(s=>typeof s=="string"?s:String(s.id))}l(ne,"readMarkerIds");function B(t){const o=i(t,".git");if(w(o))return k(o);if(!D(o))return null;const s=/^gitdir:\s*(.+)$/m.exec(x(o,"utf8"));if(!s)return null;const y=L(s[1].trim())?s[1].trim():F(t,s[1].trim()),j=i(y,"commondir");if(!D(j))return k(y);const d=x(j,"utf8").trim();return k(L(d)?d:F(y,d))}l(B,"gitCommonDir");function K(t){const o={docs:[],storeRoots:[],skipped:[],orphanHistory:0,orphanNodeDirs:0,nonMarkdown:0,injectedDocs:0},s=new Set([t.userMemory,...t.profiles.map(e=>e.memory)].map(k)),y=l((e,r,c)=>{const u=H(e),S=new Set(u.map(n=>O(e,n)));o.orphanHistory+=I(i(e,z),n=>n.endsWith(".jsonl")).filter(n=>!S.has(n)).length;let g=0;for(const n of u){const f=c+q(A(e,n));let m;try{m=$(n)}catch(N){o.docs.push({path:n,owner:r,name:f,source:"store",...E(n),history:[],invalid:{kind:"invalid-source",reason:`invalid frontmatter: ${N.message}`}}),g+=1;continue}let a;try{a=X(O(e,n))}catch(N){o.docs.push({path:n,owner:r,name:f,source:"store",...m,history:[],invalid:{kind:"invalid-history",reason:`unreadable history log: ${N.message}`}}),g+=1;continue}o.docs.push({path:n,owner:r,name:f,source:"store",...m,history:a}),g+=1}o.storeRoots.push({root:e,owner:r,docs:g})},"readStore");w(t.userMemory)&&y(t.userMemory,{type:"person"},"");for(const e of t.profiles)w(e.memory)&&y(e.memory,{type:"profile",id:e.id},"");const j=l(e=>{let r=null;for(let c=k(e);;c=C(c)){if(D(i(c,".git")))return c;const u=i(c,".crouter","memory");if(r===null&&w(u)&&!s.has(k(u))&&!Y(i(c,".crouter"))&&(r=c),C(c)===c)return r}},"projectRoot"),d=[];for(const e of[...t.profiles.flatMap(r=>r.projects),...t.nodeCwds]){if(!w(e))continue;const r=j(e);r!==null&&d.push(r)}const h=new Map,v=new Set,M=[];for(;d.length>0;){const e=d.shift();if(v.has(e))continue;v.add(e);const r=B(e);if(M.push({root:e,commonDir:r}),r!==null){h.set(r,[...h.get(r)??[],e]);const c=C(r);T(r)===".git"&&w(i(c,".git"))&&d.push(c)}d.push(...W(e).embeddedRepos)}for(const{root:e,commonDir:r}of M.sort((c,u)=>c.root.localeCompare(u.root))){const c=r===null?[e]:h.get(r),u=c.find(a=>w(i(a,".git")))??[...c].sort()[0],S=i(e,".crouter","memory"),g=w(S)&&!s.has(k(S)),n=W(e).nested.filter(a=>!s.has(k(i(e,a,".crouter","memory"))));let f=null;if(g&&D(i(S,"INDEX.md")))try{const a=$(i(S,"INDEX.md")).frontmatter?.namespace;typeof a=="string"&&a!==""&&(f=a)}catch{}const m={type:"repo",root:e,commonDir:r,namespace:f};if(e!==u){g&&o.storeRoots.push({root:S,owner:m,docs:0,skipped:"duplicate-worktree"});for(const a of n)o.storeRoots.push({root:i(e,a,".crouter","memory"),owner:m,docs:0,skipped:"duplicate-worktree"});continue}g&&y(S,m,"");for(const a of n)y(i(e,a,".crouter","memory"),m,a.split(/[\\/]/).join("/")+"/")}const p=new Set(t.nodes.map(e=>e.id));for(const e of new Set(t.nodes.map(r=>C(r.dir))))for(const r of b(e,{withFileTypes:!0}))r.isDirectory()&&!p.has(r.name)&&(o.orphanNodeDirs+=1);for(const{id:e,dir:r}of t.nodes){const c={type:"node",id:e};D(i(r,"injected-docs.json"))&&(o.injectedDocs+=1);const u=i(r,"context");w(i(u,"memory"))&&y(i(u,"memory"),c,"");const S=l((n,f,m)=>{try{o.docs.push({path:n,owner:c,name:f,source:m,...$(n),history:[]})}catch(a){o.docs.push({path:n,owner:c,name:f,source:m,...E(n),history:[],invalid:{kind:"invalid-source",reason:`invalid frontmatter: ${a.message}`}})}},"readPlain");for(const n of I(u,()=>!0,f=>f.startsWith(".")).sort()){const f=A(u,n),m=f.split(/[\\/]/)[0];m==="memory"||m==="jobs"||(n.toLowerCase().endsWith(".md")?S(n,_(f),"context"):o.nonMarkdown+=1)}const g=i(r,"reports");if(w(g))for(const n of b(g,{withFileTypes:!0}).sort((f,m)=>f.name.localeCompare(m.name)))n.isFile()&&(n.name.toLowerCase().endsWith(".md")?S(i(g,n.name),`reports/${n.name.replace(/\.md$/i,"")}`,"report"):o.nonMarkdown+=1)}return o}l(K,"readLegacyCorpus");function se(t){const o=l(s=>w(s)&&H(s).length>0,"anyMd");return o(t.userMemory)||t.profiles.some(s=>o(s.memory))||t.nodes.some(s=>o(i(s.dir,"context"))||o(i(s.dir,"reports")))?!0:K({...t,nodes:[]}).docs.length>0}l(se,"hasLegacyContent");export{se as hasLegacyContent,K as readLegacyCorpus,re as readLegacyProfiles,ne as readMarkerIds};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { LegacyHistoryRecord } from './types.js';
|
|
2
|
+
export declare const HISTORY_DIR = ".history";
|
|
3
|
+
export declare function historyLogPath(storeRoot: string, docPath: string): string;
|
|
4
|
+
/** Records of the current life, or throws naming the bad line. */
|
|
5
|
+
export declare function readHistory(logPath: string): LegacyHistoryRecord[];
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var c=Object.defineProperty;var o=(r,t)=>c(r,"name",{value:t,configurable:!0});import{existsSync as f,readFileSync as l}from"node:fs";import{join as a,relative as y}from"node:path";const h=".history";function w(r,t){return a(r,h,y(r,t).replace(/\.md$/i,"")+".jsonl")}o(w,"historyLogPath");function x(r){if(!f(r))return[];const t=[];return l(r,"utf8").split(`
|
|
2
|
+
`).forEach((n,i)=>{if(n.trim()==="")return;let s;try{s=JSON.parse(n)}catch(p){throw new Error(`line ${i+1}: ${p.message}`)}const e=s;if(e===null||typeof e!="object"||typeof e.op!="string"||typeof e.at!="string"||typeof e.after!="string")throw new Error(`line ${i+1}: not a history record`);e.op==="delete"?t.length=0:t.push(e)}),t}o(x,"readHistory");export{h as HISTORY_DIR,w as historyLogPath,x as readHistory};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export interface NestedWalk {
|
|
2
|
+
/** `<rel>` of each `<root>/<rel>/.crouter/memory`, rel non-empty. */
|
|
3
|
+
nested: string[];
|
|
4
|
+
/** Folders below the root holding their own `.git`. */
|
|
5
|
+
embeddedRepos: string[];
|
|
6
|
+
}
|
|
7
|
+
export declare function walkNestedStores(root: string): NestedWalk;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var m=Object.defineProperty;var d=(s,e)=>m(s,"name",{value:e,configurable:!0});import{existsSync as c,readdirSync as p}from"node:fs";import{join as i,relative as u}from"node:path";function l(s){const e={nested:[],embeddedRepos:[]},o=[s];for(;o.length>0;){const t=o.pop();if(t!==s){if(c(i(t,".git"))){e.embeddedRepos.push(t);continue}c(i(t,".crouter","memory"))&&e.nested.push(u(s,t))}let r;try{r=p(t,{withFileTypes:!0})}catch{continue}for(const n of r)!n.isDirectory()||n.name.startsWith(".")||n.name==="node_modules"||o.push(i(t,n.name))}return e.nested.sort(),e.embeddedRepos.sort(),e}d(l,"walkNestedStores");export{l as walkNestedStores};
|