@north-light/cli 0.3.530 → 0.3.532
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/clients/attach/session/connection.js +1 -1
- package/dist/clients/attach/session/reconnect.js +1 -1
- package/dist/clients/attach/viewer.js +508 -508
- package/dist/core/async-array.d.ts +7 -0
- package/dist/core/async-array.js +1 -0
- package/dist/core/audit.d.ts +1 -1
- package/dist/core/audit.js +2 -2
- package/dist/core/canvas/attention.d.ts +4 -4
- package/dist/core/canvas/attention.js +1 -1
- package/dist/core/canvas/boot.d.ts +4 -4
- package/dist/core/canvas/boot.js +1 -1
- package/dist/core/canvas/canvas.d.ts +59 -59
- package/dist/core/canvas/canvas.js +19 -19
- package/dist/core/canvas/context-strip.js +2 -2
- package/dist/core/canvas/crons.d.ts +27 -27
- package/dist/core/canvas/crons.js +11 -11
- package/dist/core/canvas/daemon-actions.d.ts +10 -10
- package/dist/core/canvas/daemon-actions.js +8 -8
- package/dist/core/canvas/daemon-owner.d.ts +3 -3
- package/dist/core/canvas/daemon-owner.js +2 -2
- package/dist/core/canvas/db.d.ts +19 -30
- package/dist/core/canvas/db.js +3 -2
- package/dist/core/canvas/deliveries.d.ts +16 -16
- package/dist/core/canvas/deliveries.js +24 -24
- package/dist/core/canvas/executions.d.ts +8 -8
- package/dist/core/canvas/executions.js +1 -1
- package/dist/core/canvas/focuses.d.ts +8 -8
- package/dist/core/canvas/focuses.js +1 -1
- package/dist/core/canvas/history.d.ts +3 -3
- package/dist/core/canvas/history.js +9 -9
- package/dist/core/canvas/install-id.d.ts +1 -1
- package/dist/core/canvas/install-id.js +1 -1
- package/dist/core/canvas/managed-worktree-sweep-candidates.d.ts +1 -1
- package/dist/core/canvas/managed-worktree-sweep-candidates.js +2 -2
- package/dist/core/canvas/memory-reads.d.ts +6 -6
- package/dist/core/canvas/memory-reads.js +1 -1
- package/dist/core/canvas/nav-model.d.ts +13 -13
- package/dist/core/canvas/nav-model.js +1 -1
- package/dist/core/canvas/node-agent-paths.d.ts +6 -6
- package/dist/core/canvas/node-agent-paths.js +1 -1
- package/dist/core/canvas/node-tokens.d.ts +7 -7
- package/dist/core/canvas/node-tokens.js +3 -3
- package/dist/core/canvas/outcome-actions.d.ts +5 -5
- package/dist/core/canvas/outcome-actions.js +3 -3
- package/dist/core/canvas/recovery.d.ts +26 -26
- package/dist/core/canvas/recovery.js +2 -2
- package/dist/core/canvas/render-source.d.ts +1 -1
- package/dist/core/canvas/render-source.js +1 -1
- package/dist/core/canvas/sessions.d.ts +10 -10
- package/dist/core/canvas/sessions.js +4 -4
- package/dist/core/canvas/source.js +1 -1
- package/dist/core/canvas/structured-requests.d.ts +15 -15
- package/dist/core/canvas/structured-requests.js +5 -5
- package/dist/core/canvas/tree.d.ts +9 -9
- package/dist/core/canvas/tree.js +5 -5
- package/dist/core/canvas/waits.d.ts +13 -13
- package/dist/core/canvas/waits.js +6 -6
- package/dist/core/canvas/worktrees.d.ts +15 -15
- package/dist/core/canvas/worktrees.js +1 -1
- package/dist/core/command-hooks/transport/exec-lifecycle.js +1 -1
- package/dist/core/conversation-store/file-store.d.ts +7 -7
- package/dist/core/conversation-store/file-store.js +9 -9
- package/dist/core/conversation-store/index.d.ts +16 -14
- package/dist/core/conversation-store/index.js +1 -1
- package/dist/core/conversation-store/listener.js +5 -5
- package/dist/core/conversation-store/patch.d.ts +3 -1
- package/dist/core/conversation-store/patch.js +1 -1
- package/dist/core/feed/feed.js +3 -3
- package/dist/core/feed/inbox.d.ts +2 -2
- package/dist/core/feed/inbox.js +1 -1
- package/dist/core/feed/messages.d.ts +11 -12
- package/dist/core/feed/messages.js +5 -5
- package/dist/core/feed/reports.d.ts +4 -4
- package/dist/core/feed/reports.js +2 -2
- package/dist/core/grants/cover.d.ts +1 -1
- package/dist/core/grants/cover.js +1 -1
- package/dist/core/grants/local.d.ts +1 -1
- package/dist/core/grants/local.js +1 -1
- package/dist/core/grants/mirror.d.ts +19 -19
- package/dist/core/grants/mirror.js +2 -2
- package/dist/core/grants/on-sync.d.ts +1 -1
- package/dist/core/grants/on-sync.js +1 -1
- package/dist/core/grants/remove.js +1 -1
- package/dist/core/grants/sync.js +1 -1
- package/dist/core/graph/access.d.ts +17 -17
- package/dist/core/graph/access.js +3 -3
- package/dist/core/graph/custom.d.ts +16 -16
- package/dist/core/graph/custom.js +9 -9
- package/dist/core/graph/deletion.d.ts +3 -7
- package/dist/core/graph/deletion.js +4 -4
- package/dist/core/graph/documents.d.ts +24 -27
- package/dist/core/graph/documents.js +7 -7
- package/dist/core/graph/edges.d.ts +13 -13
- package/dist/core/graph/edges.js +1 -1
- package/dist/core/graph/events.d.ts +7 -9
- package/dist/core/graph/events.js +8 -8
- package/dist/core/graph/exposures.d.ts +6 -6
- package/dist/core/graph/exposures.js +4 -4
- package/dist/core/graph/jobs.d.ts +6 -8
- package/dist/core/graph/jobs.js +2 -2
- package/dist/core/graph/kinds/action.js +1 -1
- package/dist/core/graph/kinds/custom.js +2 -2
- package/dist/core/graph/kinds/document.d.ts +1 -0
- package/dist/core/graph/kinds/document.js +4 -4
- package/dist/core/graph/kinds/dto.d.ts +2 -2
- package/dist/core/graph/kinds/dto.js +1 -1
- package/dist/core/graph/kinds/job.js +2 -2
- package/dist/core/graph/kinds/kind.d.ts +6 -8
- package/dist/core/graph/kinds/kind.js +1 -1
- package/dist/core/graph/kinds/node.js +5 -5
- package/dist/core/graph/kinds/owner.js +2 -2
- package/dist/core/graph/kinds/registry.d.ts +6 -9
- package/dist/core/graph/kinds/registry.js +1 -1
- package/dist/core/graph/names.d.ts +6 -6
- package/dist/core/graph/names.js +3 -3
- package/dist/core/graph/object-waits.d.ts +4 -7
- package/dist/core/graph/object-waits.js +1 -1
- package/dist/core/graph/objects.d.ts +14 -14
- package/dist/core/graph/objects.js +9 -9
- package/dist/core/graph/package-docs.d.ts +2 -7
- package/dist/core/graph/package-docs.js +5 -5
- package/dist/core/graph/package-kinds.d.ts +2 -5
- package/dist/core/graph/package-kinds.js +1 -1
- package/dist/core/graph/package-reconcile.d.ts +2 -5
- package/dist/core/graph/package-reconcile.js +1 -1
- package/dist/core/graph/reader.d.ts +18 -18
- package/dist/core/graph/reader.js +3 -3
- package/dist/core/graph/receivers.d.ts +4 -4
- package/dist/core/graph/receivers.js +5 -5
- package/dist/core/graph/repo-sync/exchange.d.ts +3 -7
- package/dist/core/graph/repo-sync/exchange.js +2 -2
- package/dist/core/graph/repo-sync/repos.d.ts +7 -5
- package/dist/core/graph/repo-sync/repos.js +3 -3
- package/dist/core/graph/repo-sync/sync.d.ts +3 -6
- package/dist/core/graph/repo-sync/sync.js +2 -2
- package/dist/core/graph/rules.d.ts +5 -5
- package/dist/core/graph/rules.js +3 -3
- package/dist/core/graph/spaces/app.js +1 -1
- package/dist/core/graph/spaces/index.d.ts +4 -5
- package/dist/core/graph/spaces/index.js +1 -1
- package/dist/core/graph/spaces/own-memory.d.ts +4 -4
- package/dist/core/graph/spaces/own-memory.js +1 -1
- package/dist/core/graph/spaces/person.js +3 -3
- package/dist/core/graph/spaces/repo.d.ts +1 -1
- package/dist/core/graph/spaces/repo.js +1 -1
- package/dist/core/graph/watches.d.ts +15 -15
- package/dist/core/graph/watches.js +10 -10
- package/dist/core/human/feedback-companion.d.ts +2 -2
- package/dist/core/human/feedback-companion.js +1 -1
- package/dist/core/human/feedback.d.ts +3 -3
- package/dist/core/human/feedback.js +1 -1
- package/dist/core/human/requests.d.ts +34 -33
- package/dist/core/human/requests.js +20 -20
- package/dist/core/human/scan.d.ts +2 -2
- package/dist/core/human/scan.js +1 -1
- package/dist/core/human/tickets.d.ts +9 -9
- package/dist/core/human/tickets.js +1 -1
- package/dist/core/llm/app-rungs.d.ts +1 -1
- package/dist/core/llm/app-rungs.js +1 -1
- package/dist/core/llm/run.js +2 -2
- package/dist/core/peer/directory.d.ts +1 -1
- package/dist/core/peer/directory.js +1 -1
- package/dist/core/peer/envelope.d.ts +3 -3
- package/dist/core/peer/envelope.js +1 -1
- package/dist/core/peer/home.d.ts +13 -7
- package/dist/core/peer/home.js +2 -2
- package/dist/core/peer/ingest.d.ts +6 -6
- package/dist/core/peer/ingest.js +1 -1
- package/dist/core/peer/outbox-store.d.ts +14 -14
- package/dist/core/peer/outbox-store.js +5 -5
- package/dist/core/peer/receiver.d.ts +2 -2
- package/dist/core/peer/receiver.js +1 -1
- package/dist/core/peer/stubs.d.ts +10 -10
- package/dist/core/peer/stubs.js +1 -1
- package/dist/core/providers/approval.d.ts +2 -2
- package/dist/core/providers/approval.js +2 -2
- package/dist/core/providers/audit.d.ts +3 -3
- package/dist/core/providers/audit.js +2 -2
- package/dist/core/providers/bundles.js +2 -2
- package/dist/core/providers/call.d.ts +2 -2
- package/dist/core/providers/call.js +1 -1
- package/dist/core/providers/files.d.ts +1 -1
- package/dist/core/providers/files.js +1 -1
- package/dist/core/providers/mint.js +1 -1
- package/dist/core/providers/receipts.d.ts +1 -1
- package/dist/core/providers/receipts.js +2 -2
- package/dist/core/review/birth.js +1 -1
- package/dist/core/review/comments.d.ts +19 -19
- package/dist/core/review/comments.js +5 -5
- package/dist/core/review/companion.d.ts +1 -1
- package/dist/core/review/companion.js +1 -1
- package/dist/core/review/document.d.ts +3 -3
- package/dist/core/review/document.js +2 -2
- package/dist/core/review/fork.js +2 -2
- package/dist/core/review/realize.js +1 -1
- package/dist/core/review/remap.d.ts +2 -2
- package/dist/core/review/remap.js +4 -4
- package/dist/core/review/stage.d.ts +1 -1
- package/dist/core/review/stage.js +1 -1
- package/dist/core/review/store.d.ts +21 -21
- package/dist/core/review/store.js +1 -1
- package/dist/core/runs/activity.d.ts +1 -1
- package/dist/core/runs/activity.js +5 -5
- package/dist/core/runs/confinement.d.ts +7 -7
- package/dist/core/runs/confinement.js +2 -2
- package/dist/core/runs/events.d.ts +12 -12
- package/dist/core/runs/events.js +4 -4
- package/dist/core/runs/operations.d.ts +11 -11
- package/dist/core/runs/operations.js +5 -5
- package/dist/core/runs/questions.d.ts +10 -10
- package/dist/core/runs/questions.js +3 -3
- package/dist/core/runtime/auth-reload.js +1 -1
- package/dist/core/runtime/bearings.d.ts +5 -5
- package/dist/core/runtime/bearings.js +6 -6
- package/dist/core/runtime/broker-inventory.js +1 -1
- package/dist/core/runtime/broker-request.js +1 -1
- package/dist/core/runtime/broker.js +1 -1
- package/dist/core/runtime/close.d.ts +3 -3
- package/dist/core/runtime/close.js +1 -1
- package/dist/core/runtime/deliver-live.js +1 -1
- package/dist/core/runtime/fleet.d.ts +2 -2
- package/dist/core/runtime/host.d.ts +3 -3
- package/dist/core/runtime/host.js +3 -3
- package/dist/core/runtime/kickoff.d.ts +12 -12
- package/dist/core/runtime/kickoff.js +17 -17
- package/dist/core/runtime/launch-target.d.ts +1 -1
- package/dist/core/runtime/launch-target.js +1 -1
- package/dist/core/runtime/ledger.d.ts +3 -3
- package/dist/core/runtime/ledger.js +3 -3
- package/dist/core/runtime/lifecycle.d.ts +1 -1
- package/dist/core/runtime/lifecycle.js +2 -2
- package/dist/core/runtime/memory-admission.js +1 -1
- package/dist/core/runtime/model-swap.d.ts +2 -2
- package/dist/core/runtime/model-swap.js +1 -1
- package/dist/core/runtime/node-read.d.ts +1 -1
- package/dist/core/runtime/node-read.js +2 -2
- package/dist/core/runtime/nodes.d.ts +6 -6
- package/dist/core/runtime/nodes.js +1 -1
- package/dist/core/runtime/outcome-document.d.ts +1 -1
- package/dist/core/runtime/outcome-document.js +1 -1
- package/dist/core/runtime/persona.d.ts +3 -3
- package/dist/core/runtime/persona.js +2 -2
- package/dist/core/runtime/placement.d.ts +11 -11
- package/dist/core/runtime/placement.js +1 -1
- package/dist/core/runtime/promote.d.ts +3 -3
- package/dist/core/runtime/promote.js +1 -1
- package/dist/core/runtime/recycle.js +1 -1
- package/dist/core/runtime/reopen.d.ts +5 -5
- package/dist/core/runtime/reopen.js +1 -1
- package/dist/core/runtime/reset.d.ts +4 -4
- package/dist/core/runtime/reset.js +1 -1
- package/dist/core/runtime/revive-all.d.ts +2 -2
- package/dist/core/runtime/revive-all.js +1 -1
- package/dist/core/runtime/revive.d.ts +4 -4
- package/dist/core/runtime/revive.js +2 -2
- package/dist/core/runtime/roadmap.d.ts +6 -6
- package/dist/core/runtime/roadmap.js +5 -5
- package/dist/core/runtime/session-branch.d.ts +1 -1
- package/dist/core/runtime/session-branch.js +1 -1
- package/dist/core/runtime/session-list-cache.js +1 -1
- package/dist/core/runtime/situational-live.js +1 -1
- package/dist/core/runtime/spawn.d.ts +2 -2
- package/dist/core/runtime/spawn.js +2 -2
- package/dist/core/runtime/stop-guard.d.ts +2 -2
- package/dist/core/runtime/stop-guard.js +3 -3
- package/dist/core/runtime/warm-pool.d.ts +2 -2
- package/dist/core/runtime/warm-pool.js +1 -1
- package/dist/core/spaces/mounts.d.ts +2 -2
- package/dist/core/spaces/mounts.js +1 -1
- package/dist/core/spaces/permissions.d.ts +1 -1
- package/dist/core/spaces/permissions.js +1 -1
- package/dist/core/spaces/process.d.ts +1 -1
- package/dist/core/spaces/process.js +1 -1
- package/dist/core/spaces/space.js +1 -1
- package/dist/core/spaces/stop.d.ts +3 -3
- package/dist/core/spaces/stop.js +2 -2
- package/dist/core/spaces/users.d.ts +6 -6
- package/dist/core/spaces/users.js +1 -1
- package/dist/core/storage/attachments.d.ts +2 -2
- package/dist/core/storage/attachments.js +1 -1
- package/dist/core/storage/shares.d.ts +2 -2
- package/dist/core/storage/shares.js +1 -1
- package/dist/core/storage/tables.d.ts +21 -21
- package/dist/core/storage/tables.js +3 -3
- package/dist/core/substrate/delivery/corpus.d.ts +5 -8
- package/dist/core/substrate/delivery/corpus.js +3 -3
- package/dist/core/substrate/delivery/deliver.d.ts +10 -15
- package/dist/core/substrate/delivery/deliver.js +3 -3
- package/dist/core/substrate/delivery/plan.d.ts +2 -12
- package/dist/core/substrate/delivery/plan.js +3 -3
- package/dist/core/substrate/delivery/render-boot.d.ts +4 -4
- package/dist/core/substrate/delivery/render-boot.js +18 -18
- package/dist/core/substrate/delivery/render-event.d.ts +7 -14
- package/dist/core/substrate/delivery/render-event.js +4 -4
- package/dist/core/substrate/subject.d.ts +2 -2
- package/dist/core/substrate/subject.js +1 -1
- package/dist/core/usage/ledger.d.ts +6 -6
- package/dist/core/usage/ledger.js +4 -4
- package/dist/core/worktree-close.js +4 -4
- package/dist/core/worktree-mutation-async.js +7 -7
- package/dist/core/worktree-quarantine.js +1 -1
- package/dist/core/worktree-sweep.d.ts +1 -1
- package/dist/core/worktree-sweep.js +6 -6
- package/dist/core/worktree.d.ts +5 -5
- package/dist/core/worktree.js +13 -13
- package/dist/daemon/analytics/compute.d.ts +2 -2
- package/dist/daemon/analytics/compute.js +1 -1
- package/dist/daemon/api/app-listener.d.ts +4 -4
- package/dist/daemon/api/app-listener.js +13 -13
- package/dist/daemon/api/bridge.js +5 -5
- package/dist/daemon/api/document-listener.js +6 -6
- package/dist/daemon/api/handlers/analytics.js +1 -1
- package/dist/daemon/api/handlers/attach.js +1 -1
- package/dist/daemon/api/handlers/bash-jobs.js +1 -1
- package/dist/daemon/api/handlers/bash.js +1 -1
- package/dist/daemon/api/handlers/broker-ops.d.ts +1 -1
- package/dist/daemon/api/handlers/broker-ops.js +1 -1
- package/dist/daemon/api/handlers/broker-recovery.d.ts +1 -1
- package/dist/daemon/api/handlers/broker-recovery.js +1 -1
- package/dist/daemon/api/handlers/broker-signals.d.ts +2 -2
- package/dist/daemon/api/handlers/broker-signals.js +2 -2
- package/dist/daemon/api/handlers/canvas.d.ts +1 -1
- package/dist/daemon/api/handlers/canvas.js +4 -4
- package/dist/daemon/api/handlers/chat-inventory.js +1 -1
- package/dist/daemon/api/handlers/crons.js +1 -1
- package/dist/daemon/api/handlers/custom-objects.d.ts +4 -4
- package/dist/daemon/api/handlers/custom-objects.js +3 -3
- package/dist/daemon/api/handlers/delivery-retry.js +1 -1
- package/dist/daemon/api/handlers/delivery.js +1 -1
- package/dist/daemon/api/handlers/docs.d.ts +4 -4
- package/dist/daemon/api/handlers/docs.js +1 -1
- package/dist/daemon/api/handlers/feedback-comments.js +3 -3
- package/dist/daemon/api/handlers/files.js +1 -1
- package/dist/daemon/api/handlers/focus.js +1 -1
- package/dist/daemon/api/handlers/health.js +3 -3
- package/dist/daemon/api/handlers/hook-exec.js +1 -1
- package/dist/daemon/api/handlers/human-requests.js +1 -1
- package/dist/daemon/api/handlers/inbox-page.d.ts +1 -1
- package/dist/daemon/api/handlers/inbox-page.js +1 -1
- package/dist/daemon/api/handlers/inbox.d.ts +1 -1
- package/dist/daemon/api/handlers/inbox.js +1 -1
- package/dist/daemon/api/handlers/llm.d.ts +1 -1
- package/dist/daemon/api/handlers/llm.js +3 -3
- package/dist/daemon/api/handlers/memory-reads.js +1 -1
- package/dist/daemon/api/handlers/memory.d.ts +5 -5
- package/dist/daemon/api/handlers/memory.js +5 -5
- package/dist/daemon/api/handlers/messages.js +2 -2
- package/dist/daemon/api/handlers/node-events.d.ts +2 -2
- package/dist/daemon/api/handlers/node-events.js +3 -3
- package/dist/daemon/api/handlers/node-outcomes.js +1 -1
- package/dist/daemon/api/handlers/node-records.js +2 -2
- package/dist/daemon/api/handlers/nodes.d.ts +1 -1
- package/dist/daemon/api/handlers/nodes.js +1 -1
- package/dist/daemon/api/handlers/objects.js +3 -3
- package/dist/daemon/api/handlers/package-docs.js +1 -1
- package/dist/daemon/api/handlers/plugin-app-token.d.ts +1 -1
- package/dist/daemon/api/handlers/plugin-app-token.js +1 -1
- package/dist/daemon/api/handlers/profiles.d.ts +3 -3
- package/dist/daemon/api/handlers/profiles.js +1 -1
- package/dist/daemon/api/handlers/providers.d.ts +1 -1
- package/dist/daemon/api/handlers/providers.js +1 -1
- package/dist/daemon/api/handlers/questions.js +1 -1
- package/dist/daemon/api/handlers/reports.d.ts +1 -1
- package/dist/daemon/api/handlers/reports.js +5 -5
- package/dist/daemon/api/handlers/review-comments.js +1 -1
- package/dist/daemon/api/handlers/reviews.js +1 -1
- package/dist/daemon/api/handlers/runs.js +1 -1
- package/dist/daemon/api/handlers/structured-requests.js +1 -1
- package/dist/daemon/api/handlers/subscriptions.js +1 -1
- package/dist/daemon/api/handlers/transfer.js +1 -1
- package/dist/daemon/api/map.d.ts +3 -3
- package/dist/daemon/api/map.js +1 -1
- package/dist/daemon/api/principal.d.ts +1 -1
- package/dist/daemon/api/principal.js +1 -1
- package/dist/daemon/api/reader.d.ts +5 -5
- package/dist/daemon/api/reader.js +1 -1
- package/dist/daemon/api/router.d.ts +5 -5
- package/dist/daemon/api/router.js +1 -1
- package/dist/daemon/api/server.js +1 -1
- package/dist/daemon/broker-signals/bus.d.ts +1 -1
- package/dist/daemon/broker-signals/bus.js +1 -1
- package/dist/daemon/companion-retire.js +1 -1
- package/dist/daemon/cron/armed-context.d.ts +2 -2
- package/dist/daemon/cron/armed-context.js +1 -1
- package/dist/daemon/cron/authority.d.ts +2 -2
- package/dist/daemon/cron/authority.js +1 -1
- package/dist/daemon/cron/disposition.js +1 -1
- package/dist/daemon/cron/ended.d.ts +1 -1
- package/dist/daemon/cron/ended.js +2 -2
- package/dist/daemon/cron/escalation.js +3 -3
- package/dist/daemon/cron/folders.d.ts +1 -1
- package/dist/daemon/cron/folders.js +1 -1
- package/dist/daemon/cron/held.d.ts +1 -1
- package/dist/daemon/cron/held.js +1 -1
- package/dist/daemon/cron/lease-recovery.d.ts +1 -1
- package/dist/daemon/cron/lease-recovery.js +1 -1
- package/dist/daemon/cron/passes.d.ts +2 -2
- package/dist/daemon/cron/passes.js +1 -1
- package/dist/daemon/cron/run-socket.d.ts +1 -1
- package/dist/daemon/cron/run-socket.js +1 -1
- package/dist/daemon/cron/settle.js +1 -1
- package/dist/daemon/cron/sinks.d.ts +1 -1
- package/dist/daemon/cron/sinks.js +2 -2
- package/dist/daemon/cron-run.d.ts +12 -3
- package/dist/daemon/cron-run.js +2 -2
- package/dist/daemon/crtrd.js +6 -6
- package/dist/daemon/delivery/run-delivery.js +1 -1
- package/dist/daemon/due-sources.d.ts +3 -3
- package/dist/daemon/due-sources.js +1 -1
- package/dist/daemon/due.d.ts +3 -3
- package/dist/daemon/due.js +7 -7
- package/dist/daemon/fleet.d.ts +2 -2
- package/dist/daemon/fleet.js +11 -11
- package/dist/daemon/human/finish.js +3 -3
- package/dist/daemon/human/settle.d.ts +1 -1
- package/dist/daemon/human/settle.js +1 -1
- package/dist/daemon/human/sweep.js +1 -1
- package/dist/daemon/joined-owner.d.ts +2 -2
- package/dist/daemon/joined-owner.js +1 -1
- package/dist/daemon/messaging/node-message.js +1 -1
- package/dist/daemon/park-activity.d.ts +2 -2
- package/dist/daemon/park-activity.js +1 -1
- package/dist/daemon/peer/authority.js +1 -1
- package/dist/daemon/peer/forward.d.ts +13 -6
- package/dist/daemon/peer/forward.js +1 -1
- package/dist/daemon/peer/handlers.js +1 -1
- package/dist/daemon/peer/ingress.d.ts +4 -4
- package/dist/daemon/peer/ingress.js +1 -1
- package/dist/daemon/peer/outbox.d.ts +2 -2
- package/dist/daemon/peer/outbox.js +1 -1
- package/dist/daemon/peer/relay-service.js +1 -1
- package/dist/daemon/plugin-objects/read-leaf.d.ts +2 -2
- package/dist/daemon/plugin-objects/read-leaf.js +2 -2
- package/dist/daemon/profile-delete.js +1 -1
- package/dist/daemon/readiness.d.ts +2 -2
- package/dist/daemon/readiness.js +1 -1
- package/dist/daemon/reconcilers/action-lane.d.ts +1 -1
- package/dist/daemon/reconcilers/action-lane.js +1 -1
- package/dist/daemon/reconcilers/bash-deadline.js +2 -2
- package/dist/daemon/reconcilers/broker-supervision.d.ts +1 -1
- package/dist/daemon/reconcilers/broker-supervision.js +4 -4
- package/dist/daemon/reconcilers/controller-death.d.ts +1 -1
- package/dist/daemon/reconcilers/controller-death.js +1 -1
- package/dist/daemon/reconcilers/cron-lane.d.ts +1 -1
- package/dist/daemon/reconcilers/cron-lane.js +1 -1
- package/dist/daemon/reconcilers/delivery-lane.d.ts +1 -1
- package/dist/daemon/reconcilers/delivery-lane.js +2 -2
- package/dist/daemon/reconcilers/fault-retry-backstop.d.ts +3 -3
- package/dist/daemon/reconcilers/fault-retry-backstop.js +1 -1
- package/dist/daemon/reconcilers/grove-instance-sweep.d.ts +2 -2
- package/dist/daemon/reconcilers/grove-instance-sweep.js +1 -1
- package/dist/daemon/reconcilers/live-obligation.d.ts +6 -6
- package/dist/daemon/reconcilers/live-obligation.js +1 -1
- package/dist/daemon/reconcilers/managed-worktree-sweep.js +1 -1
- package/dist/daemon/reconcilers/node-deadline.d.ts +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/node-lifecycle/respawn-policy.d.ts +3 -3
- package/dist/daemon/reconcilers/node-lifecycle/respawn-policy.js +1 -1
- package/dist/daemon/reconcilers/node-lifecycle/terminating.js +1 -1
- package/dist/daemon/reconcilers/node-lifecycle/tick.js +1 -1
- package/dist/daemon/reconcilers/node-lifecycle/wants-execution.d.ts +1 -1
- package/dist/daemon/reconcilers/node-lifecycle/wants-execution.js +1 -1
- package/dist/daemon/reconcilers/pending-review-submit.d.ts +1 -1
- package/dist/daemon/reconcilers/pending-review-submit.js +1 -1
- package/dist/daemon/reconcilers/storage-due-work.js +1 -1
- package/dist/daemon/reconcilers/storage-maintenance.d.ts +1 -1
- package/dist/daemon/reconcilers/storage-maintenance.js +2 -2
- package/dist/daemon/reconcilers/structured-request-lane.d.ts +1 -1
- package/dist/daemon/reconcilers/structured-request-lane.js +1 -1
- package/dist/daemon/review/comment-notify.js +2 -2
- package/dist/daemon/review/companion.d.ts +3 -3
- package/dist/daemon/review/companion.js +1 -1
- package/dist/daemon/review/finish.js +1 -1
- package/dist/daemon/review/sweep.js +1 -1
- package/dist/daemon/run-notices.d.ts +4 -4
- package/dist/daemon/run-notices.js +1 -1
- package/dist/daemon/runs/append-section.d.ts +2 -2
- package/dist/daemon/runs/append-section.js +2 -2
- package/dist/daemon/runs/observer.d.ts +2 -2
- package/dist/daemon/runs/observer.js +2 -2
- package/dist/daemon/structured-requests/boot.d.ts +1 -1
- package/dist/daemon/structured-requests/boot.js +1 -1
- package/dist/daemon/structured-requests/effects.js +1 -1
- package/dist/daemon/structured-requests/sidecar.d.ts +1 -1
- package/dist/daemon/structured-requests/sidecar.js +1 -1
- package/dist/migrations/004-canvas-documents/apply.d.ts +3 -3
- package/dist/migrations/004-canvas-documents/apply.js +1 -1
- package/dist/migrations/004-canvas-documents/index.d.ts +2 -2
- package/dist/migrations/004-canvas-documents/index.js +2 -2
- package/dist/migrations/activation.js +2 -2
- package/docs/public-api.md +11 -0
- package/package.json +3 -2
- package/packages/crouter-identity/package.json +1 -1
- package/runtime.lock.json +12 -12
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
var B=Object.defineProperty;var
|
|
2
|
-
\u2026 (truncated \u2014 the full result is at the result path above)`:
|
|
1
|
+
var B=Object.defineProperty;var s=(t,e)=>B(t,"name",{value:e,configurable:!0});import{existsSync as M,rmSync as j}from"node:fs";import{getNode as d}from"../../../core/canvas/canvas.js";import{liveExecutionForNode as J}from"../../../core/canvas/executions.js";import{markStopSignal as z}from"../../../core/runtime/stop-signals.js";import{emitEvent as L}from"../../../core/events/emit.js";import{push as W,FinalizationError as S,StructuredRequestFinalizationError as H}from"../../../core/feed/feed.js";import{branchIsPushedAtCurrentTip as X,hasOpenManagedWorktree as G,missingWorktreeRecoveryHint as K}from"../../../core/worktree.js";import{autoDropCleanManagedWorktreeAsync as U}from"../../../core/worktree-mutation-async.js";import{withCanvasWrite as V,openDb as Y}from"../../../core/canvas/db.js";import{get as Q}from"../../../core/graph/bodies.js";import{heads as Z}from"../../../core/graph/documents.js";import{listObjects as ee,nodeObject as te}from"../../../core/graph/objects.js";import{readerFor as re}from"../../../core/graph/reader.js";import{notFound as ne,usage as f}from"../../../core/errors.js";import{InputError as u}from"../../../core/io.js";import{toReportResultDTO as ie}from"../map.js";import{clearSchemaReprompts as oe,outputDeclinedPath as ae,stageStructuredResult as se,structuredRequestResultPath as de,validateStructuredResult as ue}from"../../../core/runtime/structured-output.js";import{getPendingStructuredRequestForNode as _,getStructuredRequest as R,settleStructuredRequestIn as le}from"../../../core/canvas/structured-requests.js";import{ApiError as h}from"../../../api/errors.js";import{applySettlementEffects as $}from"../../structured-requests/effects.js";import{nodeEventStreams as x}from"./node-events.js";import{emitRunEvent as E}from"../../../core/runs/events.js";import{mapAsync as ce}from"../../../core/async-array.js";async function g(t){const e=await d(t);if(e===null)throw ne(`unknown node: ${t}`,{received:t});return e}s(g,"requireNode");function fe(t){if(typeof t!="object"||t===null)throw f("a push report requires a JSON body { tier, body }");const e=t.tier,n=t.delivery_tier,r=t.body;if(e!=="update"&&e!=="urgent"&&e!=="final")throw f(`invalid report tier: ${String(e)} (expected update|urgent|final)`);if(n!==void 0&&n!=="deferred"&&n!=="normal"&&n!=="urgent")throw f(`invalid delivery_tier: ${String(n)} (expected deferred|normal|urgent)`);if(e!=="update"&&n!==void 0)throw f("delivery_tier is only valid for update reports");if(typeof r!="string"||r.trim()==="")throw f("a push report requires a non-empty body");return{tier:e,...n===void 0?{}:{delivery_tier:n},body:r}}s(fe,"parsePushBody");async function me(t){const e=t.params.id;await g(e);const n=fe(t.body);if(n.tier==="final"&&await _(e)!==null)throw new u({error:"structured_result_pending",message:"This node owes a structured result \u2014 a plain `push final` would finish it without recording one.",next:'Submit the result with the `submit_result` tool instead (or `crtr push result`); it validates against the pending schema, records it, and pushes the final report for you. If the schema cannot be honestly satisfied, call `submit_result` with `decline` (or `crtr push result --decline "<reason>" --code <token>`) to record the decline and finish the node.'});const r=n.tier==="final"?(await d(e))?.status:void 0,i=n.tier==="final"?await O(e):void 0,o=await b(e,n);n.tier==="final"&&await A(e);const a=n.tier==="final"&&r!==void 0?{from:r,to:(await d(e))?.status??"done"}:void 0,m=ie(o,a,i),l=(await q(e)).find(c=>c.id===o.reportId);if(l!==void 0){x.report(e,l);const c=(await d(e))?.run_id;c&&await E(c,e,"node.report.pushed",{body:l.body,kind:l.tier==="final"?"final":"update"})}return{status:200,body:m}}s(me,"handlePush");async function O(t){if(!G(await d(t)))return;const e=await U(t);if(e!==null)return e.worktree_path;if(!await X((await d(t)).managed_worktree))throw new u({error:"open_managed_worktree",message:"This node still owns an open managed worktree that is neither clean and locally landed nor clean with its exact tip on origin \u2014 `push final` cannot finish.",next:await(async()=>{const n=(await d(t))?.managed_worktree;return n!=null&&n.state==="open"&&!M(n.path)?K(n):"Make the recorded worktree clean, including untracked files: commit work to retain and remove or ignore only disposable generated files. With its recorded branch checked out and no rebase in progress, push its current tip to a branch on origin, then rerun `crtr push final`; or run `crtr node worktree close` to land the clean worktree into its recorded local base."})()})}s(O,"guardFinalWorktree");const I=2e3;function pe(t,e){const n=JSON.stringify(e,null,2),r=n.length>I?`${n.slice(0,I)}
|
|
2
|
+
\u2026 (truncated \u2014 the full result is at the result path above)`:n;return`Structured output submitted.
|
|
3
3
|
|
|
4
4
|
Result path: ${t}
|
|
5
5
|
|
|
6
6
|
\`\`\`json
|
|
7
7
|
${r}
|
|
8
8
|
\`\`\`
|
|
9
|
-
`}
|
|
9
|
+
`}s(pe,"submitReportBody");function he(t,e){return`Structured result declined.
|
|
10
10
|
|
|
11
11
|
Reason: ${e.reason}
|
|
12
12
|
Code: ${e.code}
|
|
13
13
|
Retryable: ${e.retryable?"yes":"no"}
|
|
14
14
|
|
|
15
15
|
Declined marker: ${t}
|
|
16
|
-
`}
|
|
16
|
+
`}s(he,"declineReportBody");const N=1024,T=64;async function we(t,e){if(typeof t!="object"||t===null)throw f("a result submission requires a JSON body { value } or { decline, code, retryable }");const n=t.request_id;if(typeof n!="string"||n.trim()===""){const o=await _(e);throw new u({error:"request_id_required",message:`a structured result requires request_id${o===null?"":` (pending request: ${o.request_id})`}`,next:"Pass `--request <request-id>` exactly as named in the structured-output instruction."})}const r=Object.hasOwn(t,"value"),i=Object.hasOwn(t,"decline");if(r&&i)throw f("a result submission carries either { value } or { decline, code, retryable }, not both");if(i){const{decline:o,code:a,retryable:m}=t;if(typeof o!="string"||o.trim()==="")throw new u({error:"missing_decline_reason",message:"A decline needs a reason.",next:'Rerun with `--decline "<one sentence on why the schema cannot be honestly satisfied>" --code <token>`.'});if(o.length>N)throw new u({error:"decline_reason_too_long",message:`A decline reason is at most ${N} characters (got ${o.length}).`,next:"Keep the reason to one plain sentence; put any detail in an artifact and name its path."});if(typeof a!="string"||a.trim()===""||/\s/.test(a.trim())||a.trim().length>T)throw new u({error:"invalid_decline_code",message:`A decline needs a code: one whitespace-free token of at most ${T} characters naming the decline class.`,next:"Rerun with `--code <token>` \u2014 the token your requester documented for this case."});if(typeof m!="boolean")throw f("a decline carries `retryable` as a boolean");return{requestId:n.trim(),declined:{reason:o.trim(),code:a.trim(),retryable:m}}}if(!r)throw f("a result submission requires a JSON body { value } or { decline, code, retryable }");return{requestId:n.trim(),value:t.value}}s(we,"parseSubmitBody");const ye=1024*1024;async function _e(t){const e=t.params.id,n=await g(e);await _(e)!==null&&oe(e);const r=await we(t.body,e),i=await R(r.requestId);if(i===null||i.node_id!==e)throw new h(404,"structured_request_not_found","the named structured request does not belong to this node");if(i.state!=="pending")throw new h(409,i.state==="expired"?"structured_request_expired":"structured_request_settled",`structured request ${i.request_id} is already ${i.state}`);let o;if("value"in r){if(Buffer.byteLength(JSON.stringify(r.value)??"")>ye)throw new u({error:"result_too_large",message:"the submitted result is over 1 MiB serialized; nothing was recorded.",next:"Submit a smaller result \u2014 write bulky content to a file and put its path in the result."});try{o=await ue(i.schema,r.value)}catch(c){throw new u({error:"result_schema_mismatch",message:`the submitted result does not match the requested schema: ${c.message}`,next:'Fix the listed fields and submit again; if the schema cannot be honestly satisfied, decline it (`submit_result` with `decline`, or `crtr push result --decline "<reason>" --code <token>`).'})}}const a="declined"in r?ae(e,n.grantee):de(e,i.request_id,i.submission,n.grantee),m="declined"in r?he(a,r.declined):pe(a,o),l="value"in r?se(e,i.request_id,i.submission,o,n.grantee):void 0;try{if(i.submission==="oneoff"){const p=await V(async D=>await le(D,i.request_id,"declined"in r?{intended:"declined",declined:r.declined}:{intended:"completed",result:o}));if(!p.changed||p.row===null||p.row.state!=="completed"&&p.row.state!=="declined")throw new h(409,p.row?.state==="expired"?"structured_request_expired":"structured_request_settled",`structured request ${i.request_id} is already ${p.row?.state??"settled"}`);await $(p.row,l);const y=await b(e,{tier:"update",body:m},void 0,{requestMessageId:i.request_message_id});return await P(e,y.reportId),{status:200,body:{mode:i.submission,result_path:a,report:y.report,notified:[...y.deliveredTo],..."declined"in r?{declined:r.declined}:{}}}}const c=(await d(e))?.status,v=await O(e),F="declined"in r?{kind:"failure",reason:"declined",detailJson:JSON.stringify({schema:"crtr.node-outcome-detail/v1",message:r.declined.reason,declined:r.declined}),structured:{requestId:i.request_id,declined:r.declined,skipEffects:!0}}:{structured:{requestId:i.request_id,value:o,skipEffects:!0}},w=await b(e,{tier:"final",body:m},F);await A(e);const C=await R(i.request_id);await $(C,l),await P(e,w.reportId);const k=c===void 0?void 0:{from:c,to:(await d(e))?.status??"done"};return{status:200,body:{mode:i.submission,result_path:a,report:w.report,notified:[...w.deliveredTo],..."declined"in r?{declined:r.declined}:{},...k===void 0?{}:{transitioned:k},...v===void 0?{}:{worktree_auto_dropped:!0,worktree_auto_dropped_path:v}}}}finally{l!==void 0&&j(l.tmpPath,{force:!0})}}s(_e,"handleSubmitResult");async function P(t,e){const n=(await q(t)).find(i=>i.id===e);if(n===void 0)return;x.report(t,n);const r=(await d(t))?.run_id;r&&await E(r,t,"node.report.pushed",{body:n.body,kind:n.tier==="final"?"final":"update"})}s(P,"emitReportEvents");async function A(t){try{const e=await J(t);e!==null&&z(t,"pushedFinal",e.executionId)}catch(e){try{L({event:"daemon.node.final-marker.failed",level:"error",node_id:t,error:e})||process.stderr.write(`final marker failed for ${t}: ${String(e)}
|
|
17
17
|
`)}catch{process.stderr.write(`final marker failed for ${t}: ${String(e)}
|
|
18
|
-
`)}}}
|
|
18
|
+
`)}}}s(A,"markCommittedFinal");async function b(t,e,n,r){try{return await W(t,{kind:e.tier,body:e.body,...e.delivery_tier===void 0?{}:{deliveryTier:e.delivery_tier},...n===void 0?{}:{outcome:n},...r===void 0?{}:{result:r}})}catch(i){throw i instanceof H?new h(409,i.message,i.message==="structured_request_expired"?"the named structured request expired before this submission committed":"the named structured request is already settled"):i instanceof S&&i.code==="already_finalized"?new u({error:"already_finalized",message:"This node already submitted its canonical final result.",next:"Push an update with the new information, then stop."}):i instanceof S&&i.code==="finalization_forbidden"?new u({error:"finalization_forbidden",message:"A canceled or dead node cannot submit a canonical final result.",next:"Do not push final from this node."}):i}}s(b,"pushOrRethrow");async function q(t){const e=await Y(),n=await ee(e,await re(e,{class:"person"},async()=>[]),{type:"document",kind:"report",owner:await te(e,t)});return(await ce(n,async r=>{const i=r.name.match(/-(update|urgent|final)$/)?.[1]??"update",o=(await Z(e,r))[0];return{name:r.name,id:r.id,tier:i,body:o===void 0?"":Q(o.body_hash).trim(),created:r.created_at}})).sort((r,i)=>r.created<i.created?1:r.created>i.created?-1:i.name.localeCompare(r.name))}s(q,"reportsForNode");async function ge(t){const e=t.params.id;await g(e);const n=t.query.get("tier"),r=t.query.get("limit"),i=r!==null?Number(r):void 0;let o=await q(e);return n!==null&&(o=o.filter(a=>a.tier===n)),i!==void 0&&Number.isFinite(i)&&i>=0&&(o=o.slice(0,i)),{status:200,body:o}}s(ge,"handleList");const We=[{method:"POST",pattern:"/v1/nodes/:id/reports",ownerOnly:!0,handler:me},{method:"GET",pattern:"/v1/nodes/:id/reports",handler:ge},{method:"POST",pattern:"/v1/nodes/:id/result",handler:_e}];export{We as reportRoutes,q as reportsForNode};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var z=Object.defineProperty;var d=(n,t)=>z(n,"name",{value:t,configurable:!0});import{randomUUID as q}from"node:crypto";import{getNode as T}from"../../../core/canvas/canvas.js";import{isSafeNodeId as S}from"../../../core/canvas/paths.js";import{createComment as J,deleteComment as X,editComment as Y,getComment as A,listCommentEvents as Z,listComments as $,listReviewEvents as ee,reopenComment as ne,resolveComment as te}from"../../../core/review/comments.js";import{withCanvasWrite as k}from"../../../core/canvas/db.js";import{captureAnchorText as ie,requireCurrentDocumentLocked as oe}from"../../../core/review/document.js";import{forkReviewComment as re}from"../../../core/review/fork.js";import{applyRangeBatch as de}from"../../../core/review/remap.js";import{getReviewByCompanion as se,requireVisibleReview as f}from"../../../core/review/store.js";import{ReviewOperationError as v}from"../../../core/review/types.js";import{notifyComment as ce}from"../../review/comment-notify.js";import{toReviewCommentDTO as p,toReviewCommentEventDTO as x}from"../map.js";import{invalidRequest as ue,isRecord as I,objectBody as R,requireParam as D,requiredString as P}from"./validate.js";const j=/^[a-f0-9]{32}$/,L=/^[a-f0-9]{64}$/,ae=new Set(["open","resolved","deleted","all"]),me=new Set(["wake","quiet"]);function m(n){ue("review comment request",n)}d(m,"invalidRequest");function le(n,t,e){const i=n[t];if(i!==void 0){if(typeof i!="string"||!L.test(i)){e.push({field:t,problem:"must be a lowercase SHA-256 hex digest",received:i});return}return i}}d(le,"optionalSha256");function M(n,t,e){const i=n[t];if(typeof i!="string"||!L.test(i)){e.push({field:t,problem:"must be a lowercase SHA-256 hex digest",...i===void 0?{}:{received:i}});return}return i}d(M,"requiredSha256");function B(n,t){const e=n.deliver;if(e!==void 0){if(typeof e!="string"||!me.has(e)){t.push({field:"deliver",problem:"must be wake or quiet",received:e});return}return e}}d(B,"optionalDeliver");function fe(n,t){const e=n.if_revision;if(e!==void 0){if(!Number.isSafeInteger(e)||e<0){t.push({field:"if_revision",problem:"must be a non-negative safe integer",received:e});return}return e}}d(fe,"optionalRevision");function F(n,t){const e=n.actor_node_id;return e==null?{kind:"human",node_id:null}:typeof e!="string"||!S(e)?(t.push({field:"actor_node_id",problem:"must be a safe node id or null",received:e}),null):{kind:"node",node_id:e}}d(F,"actorFrom");function G(n,t,e){T(n)===null&&e.push({field:t,problem:"must name an existing node",received:n})}d(G,"requireKnownNode");function N(n,t){n.node_id!==null&&G(n.node_id,"actor_node_id",t)}d(N,"requireKnownActor");function H(n,t,e){if(!I(n)){e.push({field:t,problem:"must be an anchor object",received:n});return}const i=["line","end_line","col_start","col_end","quote"];for(const r of Object.keys(n))i.includes(r)||e.push({field:`${t}.${r}`,problem:"is not allowed",received:n[r]});const o=n.line,s=n.end_line;typeof o!="number"&&e.push({field:`${t}.line`,problem:"must be a number",...o===void 0?{}:{received:o}}),typeof s!="number"&&e.push({field:`${t}.end_line`,problem:"must be a number",...s===void 0?{}:{received:s}});for(const r of["col_start","col_end"]){const c=n[r];c!==void 0&&typeof c!="number"&&e.push({field:`${t}.${r}`,problem:"must be a number",received:c})}if(n.quote!==void 0&&typeof n.quote!="string"&&e.push({field:`${t}.quote`,problem:"must be a string",received:n.quote}),!(typeof o!="number"||typeof s!="number"))return{line:o,end_line:s,...typeof n.col_start=="number"?{col_start:n.col_start}:{},...typeof n.col_end=="number"?{col_end:n.col_end}:{},...typeof n.quote=="string"?{quote:n.quote}:{}}}d(H,"anchorFrom");function w(n,t){return D(n,"review_id","must be a safe review id",S,t)}d(w,"requireReviewId");function C(n,t){return D(n,"comment_id","must be a 32-character lowercase hexadecimal id",e=>j.test(e),t)}d(C,"requireCommentId");function b(n){const t=f(n);if(t.state!=="open")throw new v("review_terminal","review already has a terminal outcome",{state:t.state,requested:"comment",review:t});return t}d(b,"requireOpenReview");function U(n){const t=n===null?void 0:T(n)?.review_binding?.review_id,e=n===null?null:se(n)??(t===void 0?null:f(t));if(e===null||e.state!=="open")throw new v("review_required","an open review is required when no review id is supplied",{actor_node_id:n});return e}d(U,"requireCompanionReview");function he(n){return{comment:p(n),events:Z(n.comment_id).map(x)}}d(he,"toDetail");function _e(n,t){return{attempted:!0,target_node_id:n.companion_node_id,status:"failed",woke:!1,error:t instanceof Error?t.message:String(t)}}d(_e,"deliveryFailure");async function V(n){if(!n.changed)return{comment:p(n.comment),changed:!1};let t;try{t=await ce({review:n.review,comment:n.comment,verb:n.verb,actor_node_id:n.actor.node_id,deliver:n.deliver,operation_id:n.operationId})}catch(e){t=_e(n.review,e)}return{comment:p(n.comment),changed:!0,delivery:t}}d(V,"mutationResult");function ve(n,t){const e=[],i=R(n.body,["text","anchor","doc_hash","actor_node_id","deliver"],e),o=t==="review"?(()=>{const a=w(n,e);return a===void 0?void 0:{kind:"review",review_id:a}})():{kind:"self"},s=P(i,"text",e),r=H(i.anchor,"anchor",e),c=le(i,"doc_hash",e),u=F(i,e),h=B(i,e);return u!==null&&N(u,e),(e.length>0||o===void 0||s===void 0||r===void 0||u===null)&&m(e),{selector:o,text:s,anchor:r,...c===void 0?{}:{doc_hash:c},actor:u,...h===void 0?{}:{deliver:h}}}d(ve,"parseCreate");function pe(n,t){const e=[],i=R(n.body,t?["text","actor_node_id","deliver","if_revision"]:["actor_node_id","deliver","if_revision"],e),o=C(n,e),s=t?P(i,"text",e):void 0,r=F(i,e),c=B(i,e),u=fe(i,e);return r!==null&&N(r,e),(e.length>0||o===void 0||r===null||t&&s===void 0)&&m(e),{comment_id:o,...s===void 0?{}:{text:s},actor:r,...c===void 0?{}:{deliver:c},...u===void 0?{}:{if_revision:u}}}d(pe,"parseAction");function we(n){const t=[],e=R(n.body,["from_doc_hash","to_doc_hash","entries"],t),i=w(n,t),o=M(e,"from_doc_hash",t),s=M(e,"to_doc_hash",t),r=e.entries,c=[];return Array.isArray(r)?r.forEach((u,h)=>{const a=`entries[${h}]`;if(!I(u)){t.push({field:a,problem:"must be an object",received:u});return}for(const g of Object.keys(u))["comment_id","anchor","detached"].includes(g)||t.push({field:`${a}.${g}`,problem:"is not allowed",received:u[g]});const l=u.comment_id;if(typeof l!="string"||!j.test(l)){t.push({field:`${a}.comment_id`,problem:"must be a 32-character lowercase hexadecimal id",received:l});return}const W=u.anchor!==void 0,_=u.detached;_!==void 0&&_!==!0&&t.push({field:`${a}.detached`,problem:"must be true when present",received:_});const E=_===!0;if(W===E){t.push({field:a,problem:"must provide exactly one of anchor or detached: true"});return}if(E){c.push({comment_id:l,detached:!0});return}const O=H(u.anchor,`${a}.anchor`,t);O!==void 0&&c.push({comment_id:l,anchor:O})}):t.push({field:"entries",problem:"must be an array",received:r}),(t.length>0||i===void 0||o===void 0||s===void 0||!Array.isArray(r))&&m(t),{review_id:i,request:{from_doc_hash:o,to_doc_hash:s,entries:c}}}d(we,"parseRangeBatch");function be(n,t,e){for(const[r,c]of n.query)r!=="status"&&(r!=="actor_node_id"||t!=="self")&&e.push({field:r,problem:"is not allowed",received:c});const i=n.query.getAll("status");(i.length>1||i.length===1&&!ae.has(i[0]))&&e.push({field:"status",problem:"must be open, resolved, deleted, or all",received:i.length>1?i:i[0]});const o=n.query.getAll("actor_node_id");let s=null;if(o.length>1)e.push({field:"actor_node_id",problem:"must appear at most once",received:o});else if(o.length===1){const r=o[0];S(r)?(s=r,G(r,"actor_node_id",e)):e.push({field:"actor_node_id",problem:"must be a safe node id",received:r})}return{...i.length===0?{}:{status:i[0]},actor_node_id:s}}d(be,"parseListQuery");function ye(n,t){const e={};for(const[i,o]of n.query)i!=="since_seq"&&i!=="limit"&&t.push({field:i,problem:"is not allowed",received:o});for(const i of["since_seq","limit"]){const o=n.query.getAll(i);if(o.length>1){t.push({field:i,problem:"must appear at most once",received:o});continue}if(o.length===0)continue;const s=o[0],r=Number(s);if(!Number.isSafeInteger(r)||r<0||String(r)!==s){t.push({field:i,problem:"must be a non-negative safe integer",received:s});continue}e[i]=r}return e.limit!==void 0&&e.limit<1&&t.push({field:"limit",problem:"must be at least 1",received:e.limit}),e}d(ye,"parseEventQuery");async function Q(n,t){const e=ve(n,t),i=q(),o=k(s=>{const r=e.selector.kind==="review"?b(e.selector.review_id):b(U(e.actor.node_id).review_id),c=oe(s,r.review_id,e.doc_hash??r.anchor_base_sha256),u=J({review_id:r.review_id,text:e.text,anchor:e.anchor,line_text:ie(c.lines,e.anchor),doc_hash:c.sha256,actor:e.actor,operation_id:i});return{review:r,mutation:u}});return{status:200,body:await V({review:o.review,...o.mutation,verb:"create",actor:e.actor,deliver:e.deliver,operationId:i})}}d(Q,"handleCreate");function K(n,t){const e=[],i=t==="review"?(()=>{const c=w(n,e);return c===void 0?void 0:{kind:"review",review_id:c}})():{kind:"self"},o=be(n,t,e);(e.length>0||i===void 0)&&m(e);const s=i.kind==="review"?f(i.review_id):U(o.actor_node_id);return{status:200,body:{review_id:s.review_id,comments:$(s.review_id,o).map(p)}}}d(K,"handleList");function ge(n){const t=[],e=w(n,t),i=ye(n,t);(t.length>0||e===void 0)&&m(t);const o=f(e),s=ee(o.review_id,i);return{status:200,body:{review_id:o.review_id,events:s.events.map(x),next_since_seq:s.events.length===0?null:s.next_since_seq}}}d(ge,"handleEvents");function qe(n){const{review_id:t,request:e}=we(n),i=q(),o=k(()=>{const r=b(t),c=$(r.review_id).length,u=de({review_id:r.review_id,...e,actor:{kind:"human",node_id:null},operation_id:i});return{review:r,nondeleted:c,applied:u}});return{status:200,body:{review_id:o.review.review_id,anchor_base_sha256:o.applied.anchor_base_sha256,updated:o.applied.updated,detached:o.applied.detached,unchanged:o.nondeleted-o.applied.updated}}}d(qe,"handleRanges");function Se(n){const t=[],e=C(n,t);(t.length>0||e===void 0)&&m(t);const i=A(e);if(i===null)throw new v("unknown_comment","comment was not found",{received:e});return f(i.review_id),{status:200,body:he(i)}}d(Se,"handleDetail");async function y(n,t){const e=pe(n,t==="edit"),i=q(),o=k(()=>{const s=A(e.comment_id);if(s===null)throw new v("unknown_comment","comment was not found",{received:e.comment_id});const r=b(s.review_id),c=t==="edit"?Y(e.comment_id,{text:e.text,actor:e.actor,operation_id:i,if_revision:e.if_revision}):t==="resolve"?te(e.comment_id,{actor:e.actor,operation_id:i,if_revision:e.if_revision}):t==="reopen"?ne(e.comment_id,{actor:e.actor,operation_id:i,if_revision:e.if_revision}):X(e.comment_id,{actor:e.actor,operation_id:i,if_revision:e.if_revision});return{review:r,mutation:c}});return{status:200,body:await V({review:o.review,...o.mutation,verb:t,actor:e.actor,deliver:e.deliver,operationId:i})}}d(y,"handleAction");async function ke(n){const t=[],e=C(n,t);(t.length>0||e===void 0)&&m(t);const i=await re(e);return{status:200,body:{comment_id:e,node_id:i.node_id,cwd:i.cwd}}}d(ke,"handleFork");const Be=[{method:"POST",pattern:"/v1/human/reviews/self/comments",handler:d(n=>Q(n,"self"),"handler")},{method:"GET",pattern:"/v1/human/reviews/self/comments",handler:d(n=>K(n,"self"),"handler")},{method:"POST",pattern:"/v1/human/reviews/:review_id/comments",handler:d(n=>Q(n,"review"),"handler")},{method:"GET",pattern:"/v1/human/reviews/:review_id/comments",handler:d(n=>K(n,"review"),"handler")},{method:"GET",pattern:"/v1/human/reviews/:review_id/comment-events",handler:ge},{method:"POST",pattern:"/v1/human/reviews/:review_id/comment-ranges",handler:qe},{method:"GET",pattern:"/v1/human/comments/:comment_id",handler:Se},{method:"POST",pattern:"/v1/human/comments/:comment_id/edit",handler:d(n=>y(n,"edit"),"handler")},{method:"POST",pattern:"/v1/human/comments/:comment_id/resolve",handler:d(n=>y(n,"resolve"),"handler")},{method:"POST",pattern:"/v1/human/comments/:comment_id/reopen",handler:d(n=>y(n,"reopen"),"handler")},{method:"POST",pattern:"/v1/human/comments/:comment_id/delete",handler:d(n=>y(n,"delete"),"handler")},{method:"POST",pattern:"/v1/human/comments/:comment_id/fork",handler:ke}];export{Be as reviewCommentRoutes};
|
|
1
|
+
var z=Object.defineProperty;var d=(n,t)=>z(n,"name",{value:t,configurable:!0});import{randomUUID as q}from"node:crypto";import{getNode as T}from"../../../core/canvas/canvas.js";import{isSafeNodeId as S}from"../../../core/canvas/paths.js";import{createComment as J,deleteComment as X,editComment as Y,getComment as A,listCommentEvents as Z,listComments as $,listReviewEvents as ee,reopenComment as ne,resolveComment as te}from"../../../core/review/comments.js";import{withCanvasWrite as k}from"../../../core/canvas/db.js";import{captureAnchorText as ie,requireCurrentDocumentLocked as oe}from"../../../core/review/document.js";import{forkReviewComment as re}from"../../../core/review/fork.js";import{applyRangeBatch as de}from"../../../core/review/remap.js";import{getReviewByCompanion as ae,requireVisibleReview as f}from"../../../core/review/store.js";import{ReviewOperationError as v}from"../../../core/review/types.js";import{notifyComment as se}from"../../review/comment-notify.js";import{toReviewCommentDTO as p,toReviewCommentEventDTO as x}from"../map.js";import{invalidRequest as ce,isRecord as I,objectBody as R,requireParam as D,requiredString as P}from"./validate.js";const j=/^[a-f0-9]{32}$/,L=/^[a-f0-9]{64}$/,ue=new Set(["open","resolved","deleted","all"]),me=new Set(["wake","quiet"]);function m(n){ce("review comment request",n)}d(m,"invalidRequest");function le(n,t,e){const i=n[t];if(i!==void 0){if(typeof i!="string"||!L.test(i)){e.push({field:t,problem:"must be a lowercase SHA-256 hex digest",received:i});return}return i}}d(le,"optionalSha256");function M(n,t,e){const i=n[t];if(typeof i!="string"||!L.test(i)){e.push({field:t,problem:"must be a lowercase SHA-256 hex digest",...i===void 0?{}:{received:i}});return}return i}d(M,"requiredSha256");function B(n,t){const e=n.deliver;if(e!==void 0){if(typeof e!="string"||!me.has(e)){t.push({field:"deliver",problem:"must be wake or quiet",received:e});return}return e}}d(B,"optionalDeliver");function fe(n,t){const e=n.if_revision;if(e!==void 0){if(!Number.isSafeInteger(e)||e<0){t.push({field:"if_revision",problem:"must be a non-negative safe integer",received:e});return}return e}}d(fe,"optionalRevision");function F(n,t){const e=n.actor_node_id;return e==null?{kind:"human",node_id:null}:typeof e!="string"||!S(e)?(t.push({field:"actor_node_id",problem:"must be a safe node id or null",received:e}),null):{kind:"node",node_id:e}}d(F,"actorFrom");async function G(n,t,e){await T(n)===null&&e.push({field:t,problem:"must name an existing node",received:n})}d(G,"requireKnownNode");async function N(n,t){n.node_id!==null&&await G(n.node_id,"actor_node_id",t)}d(N,"requireKnownActor");function H(n,t,e){if(!I(n)){e.push({field:t,problem:"must be an anchor object",received:n});return}const i=["line","end_line","col_start","col_end","quote"];for(const r of Object.keys(n))i.includes(r)||e.push({field:`${t}.${r}`,problem:"is not allowed",received:n[r]});const o=n.line,a=n.end_line;typeof o!="number"&&e.push({field:`${t}.line`,problem:"must be a number",...o===void 0?{}:{received:o}}),typeof a!="number"&&e.push({field:`${t}.end_line`,problem:"must be a number",...a===void 0?{}:{received:a}});for(const r of["col_start","col_end"]){const s=n[r];s!==void 0&&typeof s!="number"&&e.push({field:`${t}.${r}`,problem:"must be a number",received:s})}if(n.quote!==void 0&&typeof n.quote!="string"&&e.push({field:`${t}.quote`,problem:"must be a string",received:n.quote}),!(typeof o!="number"||typeof a!="number"))return{line:o,end_line:a,...typeof n.col_start=="number"?{col_start:n.col_start}:{},...typeof n.col_end=="number"?{col_end:n.col_end}:{},...typeof n.quote=="string"?{quote:n.quote}:{}}}d(H,"anchorFrom");function w(n,t){return D(n,"review_id","must be a safe review id",S,t)}d(w,"requireReviewId");function C(n,t){return D(n,"comment_id","must be a 32-character lowercase hexadecimal id",e=>j.test(e),t)}d(C,"requireCommentId");async function b(n){const t=await f(n);if(t.state!=="open")throw new v("review_terminal","review already has a terminal outcome",{state:t.state,requested:"comment",review:t});return t}d(b,"requireOpenReview");async function U(n){const t=n===null?void 0:(await T(n))?.review_binding?.review_id,e=n===null?null:await ae(n)??(t===void 0?null:await f(t));if(e===null||e.state!=="open")throw new v("review_required","an open review is required when no review id is supplied",{actor_node_id:n});return e}d(U,"requireCompanionReview");async function he(n){return{comment:p(n),events:(await Z(n.comment_id)).map(x)}}d(he,"toDetail");function _e(n,t){return{attempted:!0,target_node_id:n.companion_node_id,status:"failed",woke:!1,error:t instanceof Error?t.message:String(t)}}d(_e,"deliveryFailure");async function V(n){if(!n.changed)return{comment:p(n.comment),changed:!1};let t;try{t=await se({review:n.review,comment:n.comment,verb:n.verb,actor_node_id:n.actor.node_id,deliver:n.deliver,operation_id:n.operationId})}catch(e){t=_e(n.review,e)}return{comment:p(n.comment),changed:!0,delivery:t}}d(V,"mutationResult");async function ve(n,t){const e=[],i=R(n.body,["text","anchor","doc_hash","actor_node_id","deliver"],e),o=t==="review"?(()=>{const u=w(n,e);return u===void 0?void 0:{kind:"review",review_id:u}})():{kind:"self"},a=P(i,"text",e),r=H(i.anchor,"anchor",e),s=le(i,"doc_hash",e),c=F(i,e),h=B(i,e);return c!==null&&await N(c,e),(e.length>0||o===void 0||a===void 0||r===void 0||c===null)&&m(e),{selector:o,text:a,anchor:r,...s===void 0?{}:{doc_hash:s},actor:c,...h===void 0?{}:{deliver:h}}}d(ve,"parseCreate");async function pe(n,t){const e=[],i=R(n.body,t?["text","actor_node_id","deliver","if_revision"]:["actor_node_id","deliver","if_revision"],e),o=C(n,e),a=t?P(i,"text",e):void 0,r=F(i,e),s=B(i,e),c=fe(i,e);return r!==null&&await N(r,e),(e.length>0||o===void 0||r===null||t&&a===void 0)&&m(e),{comment_id:o,...a===void 0?{}:{text:a},actor:r,...s===void 0?{}:{deliver:s},...c===void 0?{}:{if_revision:c}}}d(pe,"parseAction");function we(n){const t=[],e=R(n.body,["from_doc_hash","to_doc_hash","entries"],t),i=w(n,t),o=M(e,"from_doc_hash",t),a=M(e,"to_doc_hash",t),r=e.entries,s=[];return Array.isArray(r)?r.forEach((c,h)=>{const u=`entries[${h}]`;if(!I(c)){t.push({field:u,problem:"must be an object",received:c});return}for(const g of Object.keys(c))["comment_id","anchor","detached"].includes(g)||t.push({field:`${u}.${g}`,problem:"is not allowed",received:c[g]});const l=c.comment_id;if(typeof l!="string"||!j.test(l)){t.push({field:`${u}.comment_id`,problem:"must be a 32-character lowercase hexadecimal id",received:l});return}const W=c.anchor!==void 0,_=c.detached;_!==void 0&&_!==!0&&t.push({field:`${u}.detached`,problem:"must be true when present",received:_});const E=_===!0;if(W===E){t.push({field:u,problem:"must provide exactly one of anchor or detached: true"});return}if(E){s.push({comment_id:l,detached:!0});return}const O=H(c.anchor,`${u}.anchor`,t);O!==void 0&&s.push({comment_id:l,anchor:O})}):t.push({field:"entries",problem:"must be an array",received:r}),(t.length>0||i===void 0||o===void 0||a===void 0||!Array.isArray(r))&&m(t),{review_id:i,request:{from_doc_hash:o,to_doc_hash:a,entries:s}}}d(we,"parseRangeBatch");async function be(n,t,e){for(const[r,s]of n.query)r!=="status"&&(r!=="actor_node_id"||t!=="self")&&e.push({field:r,problem:"is not allowed",received:s});const i=n.query.getAll("status");(i.length>1||i.length===1&&!ue.has(i[0]))&&e.push({field:"status",problem:"must be open, resolved, deleted, or all",received:i.length>1?i:i[0]});const o=n.query.getAll("actor_node_id");let a=null;if(o.length>1)e.push({field:"actor_node_id",problem:"must appear at most once",received:o});else if(o.length===1){const r=o[0];S(r)?(a=r,await G(r,"actor_node_id",e)):e.push({field:"actor_node_id",problem:"must be a safe node id",received:r})}return{...i.length===0?{}:{status:i[0]},actor_node_id:a}}d(be,"parseListQuery");function ye(n,t){const e={};for(const[i,o]of n.query)i!=="since_seq"&&i!=="limit"&&t.push({field:i,problem:"is not allowed",received:o});for(const i of["since_seq","limit"]){const o=n.query.getAll(i);if(o.length>1){t.push({field:i,problem:"must appear at most once",received:o});continue}if(o.length===0)continue;const a=o[0],r=Number(a);if(!Number.isSafeInteger(r)||r<0||String(r)!==a){t.push({field:i,problem:"must be a non-negative safe integer",received:a});continue}e[i]=r}return e.limit!==void 0&&e.limit<1&&t.push({field:"limit",problem:"must be at least 1",received:e.limit}),e}d(ye,"parseEventQuery");async function Q(n,t){const e=await ve(n,t),i=q(),o=await k(async a=>{const r=e.selector.kind==="review"?await b(e.selector.review_id):await b((await U(e.actor.node_id)).review_id),s=await oe(a,r.review_id,e.doc_hash??r.anchor_base_sha256),c=await J({review_id:r.review_id,text:e.text,anchor:e.anchor,line_text:ie(s.lines,e.anchor),doc_hash:s.sha256,actor:e.actor,operation_id:i});return{review:r,mutation:c}});return{status:200,body:await V({review:o.review,...o.mutation,verb:"create",actor:e.actor,deliver:e.deliver,operationId:i})}}d(Q,"handleCreate");async function K(n,t){const e=[],i=t==="review"?(()=>{const s=w(n,e);return s===void 0?void 0:{kind:"review",review_id:s}})():{kind:"self"},o=await be(n,t,e);(e.length>0||i===void 0)&&m(e);const a=i.kind==="review"?await f(i.review_id):await U(o.actor_node_id);return{status:200,body:{review_id:a.review_id,comments:(await $(a.review_id,o)).map(p)}}}d(K,"handleList");async function ge(n){const t=[],e=w(n,t),i=ye(n,t);(t.length>0||e===void 0)&&m(t);const o=await f(e),a=await ee(o.review_id,i);return{status:200,body:{review_id:o.review_id,events:a.events.map(x),next_since_seq:a.events.length===0?null:a.next_since_seq}}}d(ge,"handleEvents");async function qe(n){const{review_id:t,request:e}=we(n),i=q(),o=await k(async()=>{const r=await b(t),s=(await $(r.review_id)).length,c=await de({review_id:r.review_id,...e,actor:{kind:"human",node_id:null},operation_id:i});return{review:r,nondeleted:s,applied:c}});return{status:200,body:{review_id:o.review.review_id,anchor_base_sha256:o.applied.anchor_base_sha256,updated:o.applied.updated,detached:o.applied.detached,unchanged:o.nondeleted-o.applied.updated}}}d(qe,"handleRanges");async function Se(n){const t=[],e=C(n,t);(t.length>0||e===void 0)&&m(t);const i=await A(e);if(i===null)throw new v("unknown_comment","comment was not found",{received:e});return await f(i.review_id),{status:200,body:await he(i)}}d(Se,"handleDetail");async function y(n,t){const e=await pe(n,t==="edit"),i=q(),o=await k(async()=>{const a=await A(e.comment_id);if(a===null)throw new v("unknown_comment","comment was not found",{received:e.comment_id});const r=await b(a.review_id),s=t==="edit"?await Y(e.comment_id,{text:e.text,actor:e.actor,operation_id:i,if_revision:e.if_revision}):t==="resolve"?await te(e.comment_id,{actor:e.actor,operation_id:i,if_revision:e.if_revision}):t==="reopen"?await ne(e.comment_id,{actor:e.actor,operation_id:i,if_revision:e.if_revision}):await X(e.comment_id,{actor:e.actor,operation_id:i,if_revision:e.if_revision});return{review:r,mutation:s}});return{status:200,body:await V({review:o.review,...o.mutation,verb:t,actor:e.actor,deliver:e.deliver,operationId:i})}}d(y,"handleAction");async function ke(n){const t=[],e=C(n,t);(t.length>0||e===void 0)&&m(t);const i=await re(e);return{status:200,body:{comment_id:e,node_id:i.node_id,cwd:i.cwd}}}d(ke,"handleFork");const Be=[{method:"POST",pattern:"/v1/human/reviews/self/comments",handler:d(n=>Q(n,"self"),"handler")},{method:"GET",pattern:"/v1/human/reviews/self/comments",handler:d(async n=>await K(n,"self"),"handler")},{method:"POST",pattern:"/v1/human/reviews/:review_id/comments",handler:d(n=>Q(n,"review"),"handler")},{method:"GET",pattern:"/v1/human/reviews/:review_id/comments",handler:d(async n=>await K(n,"review"),"handler")},{method:"GET",pattern:"/v1/human/reviews/:review_id/comment-events",handler:ge},{method:"POST",pattern:"/v1/human/reviews/:review_id/comment-ranges",handler:qe},{method:"GET",pattern:"/v1/human/comments/:comment_id",handler:Se},{method:"POST",pattern:"/v1/human/comments/:comment_id/edit",handler:d(n=>y(n,"edit"),"handler")},{method:"POST",pattern:"/v1/human/comments/:comment_id/resolve",handler:d(n=>y(n,"resolve"),"handler")},{method:"POST",pattern:"/v1/human/comments/:comment_id/reopen",handler:d(n=>y(n,"reopen"),"handler")},{method:"POST",pattern:"/v1/human/comments/:comment_id/delete",handler:d(n=>y(n,"delete"),"handler")},{method:"POST",pattern:"/v1/human/comments/:comment_id/fork",handler:ke}];export{Be as reviewCommentRoutes};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var k=Object.defineProperty;var s=(t,e)=>k(t,"name",{value:e,configurable:!0});import{ApiError as m}from"../../../api/index.js";import{withCanvasWrite as R}from"../../../core/canvas/db.js";import{isSafeNodeId as p}from"../../../core/canvas/paths.js";import{readDocument as q}from"../../../core/graph/documents.js";import{getByRowid as E}from"../../../core/graph/objects.js";import{checkoutsForCwd as S}from"../../../core/graph/repo-sync/repos.js";import{getNode as b}from"../../../core/canvas/canvas.js";import{assertScope as T}from"../../../core/scopes.js";import{createReview as $}from"../../../core/review/birth.js";import{readAnchorBase as C,listReviews as D,requireVisibleReview as y}from"../../../core/review/store.js";import{cancelReview as I,submitReviewApproval as A}from"../../review/finish.js";import{toFeedbackResultDTO as O,toReviewDTO as F}from"../map.js";import{readerFor as L,resolveRef as B}from"../reader.js";import{canReadNode as N}from"../router.js";import{invalidRequest as P,objectBody as
|
|
1
|
+
var k=Object.defineProperty;var s=(t,e)=>k(t,"name",{value:e,configurable:!0});import{ApiError as m}from"../../../api/index.js";import{withCanvasWrite as R}from"../../../core/canvas/db.js";import{isSafeNodeId as p}from"../../../core/canvas/paths.js";import{readDocument as q}from"../../../core/graph/documents.js";import{getByRowid as E}from"../../../core/graph/objects.js";import{checkoutsForCwd as S}from"../../../core/graph/repo-sync/repos.js";import{getNode as b}from"../../../core/canvas/canvas.js";import{assertScope as T}from"../../../core/scopes.js";import{createReview as $}from"../../../core/review/birth.js";import{readAnchorBase as C,listReviews as D,requireVisibleReview as y}from"../../../core/review/store.js";import{cancelReview as I,submitReviewApproval as A}from"../../review/finish.js";import{toFeedbackResultDTO as O,toReviewDTO as F}from"../map.js";import{readerFor as L,resolveRef as B}from"../reader.js";import{canReadNode as N}from"../router.js";import{invalidRequest as P,objectBody as v,optionalString as c,requireParam as j,requiredString as g}from"./validate.js";import{filterAsync as G}from"../../../core/async-array.js";const V=new Set(["open","approved","canceled"]),W=["origin_kind","origin_node_id","document","file","idempotency_key","subtitle","output_path"],K=["reason","actor","disposition"];function l(t){P("review request",t)}s(l,"invalidRequest");function w(t,e){return j(t,"review_id","must be a safe review id",p,e)}s(w,"requireReviewId");function f(t){return{...F(t,t.state==="approved"?{result_path:`${t.review_dir}/result.json`}:{}),review_dir:t.review_dir}}s(f,"toReviewResponseDTO");function M(t){const e=[],n=v(t.body,W,e),o=n.origin_kind,i=o==="ticket"||o==="inline"?o:void 0;i===void 0&&e.push({field:"origin_kind",problem:"must be ticket or inline",...o===void 0?{}:{received:o}});const r=g(n,"origin_node_id",e);r!==void 0&&!p(r)&&e.push({field:"origin_node_id",problem:"must be a safe node id",received:r});const d=c(n,"document",e),u=c(n,"file",e);i==="ticket"&&(d===void 0||u!==void 0)&&e.push({field:"document",problem:"is required for ticket reviews, and file is not allowed"}),i==="inline"&&u===void 0==(d===void 0)&&e.push({field:"file",problem:"inline reviews take exactly one of file or document"});const a=g(n,"idempotency_key",e);a!==void 0&&a.length>128&&e.push({field:"idempotency_key",problem:"must be at most 128 characters",received:a});const h=c(n,"subtitle",e),_=c(n,"output_path",e);return i==="ticket"&&h===void 0&&n.subtitle===void 0&&e.push({field:"subtitle",problem:"is required for ticket reviews"}),i==="inline"&&n.subtitle!==void 0&&e.push({field:"subtitle",problem:"is only allowed for ticket reviews",received:n.subtitle}),i==="inline"&&n.output_path!==void 0&&e.push({field:"output_path",problem:"is only allowed for ticket reviews",received:n.output_path}),(e.length>0||i===void 0||r===void 0||!p(r)||a===void 0||a.length>128)&&l(e),{origin_kind:i,origin_node_id:r,...d===void 0?{}:{document:d},...u===void 0?{}:{file:u},idempotency_key:a,...h===void 0?{}:{subtitle:h},..._===void 0?{}:{output_path:_}}}s(M,"parseCreate");function x(t){const e=[],n={},o=new Set(["state","origin_node_id","file"]);for(const[i,r]of t.query.entries())o.has(i)||e.push({field:i,problem:"is not allowed",received:r});for(const i of o){const r=t.query.getAll(i);if(r.length>1){e.push({field:i,problem:"must appear at most once",received:r});continue}const d=r[0];d!==void 0&&(i==="state"?V.has(d)?n.state=d:e.push({field:i,problem:"must be open, approved, or canceled",received:d}):i==="origin_node_id"?p(d)?n.origin_node_id=d:e.push({field:i,problem:"must be a safe node id",received:d}):d===""?e.push({field:i,problem:"must be a non-empty string",received:d}):n.file=d)}return e.length>0&&l(e),n}s(x,"parseList");function z(t,e){const n=t.body===void 0?{}:v(t.body,K,e),o=c(n,"reason",e),i=c(n,"actor",e),r=c(n,"disposition",e);return r!==void 0&&r!=="canceled"&&r!=="dismissed"&&e.push({field:"disposition",problem:'must be "canceled" or "dismissed"',received:r}),{...o===void 0?{}:{reason:o},...i===void 0?{}:{actor:i},...r==="canceled"||r==="dismissed"?{disposition:r}:{}}}s(z,"parseCancel");function H(t,e){v(t.body,[],e)}s(H,"requireEmptyBody");async function J(t){const e=M(t),n=await b(e.origin_node_id);n!==null&&T(n,"crtr:act");const{document:o,file:i,...r}=e,d=await $({...r,...o===void 0?{file:i??""}:{document:await Q(t,o)}});return{status:200,body:f(d)}}s(J,"handleCreate");async function Q(t,e){return await R(async n=>{const o=await L(n,t),i=await B(n,o,e);if("remote"in i)throw new m(404,"not_found",`no document named ${i.remote} on this runtime`,{next:"Check the name with `crtr canvas search`."});if("deleted"in i)throw new m(404,"not_found",`${i.deleted.name} is deleted`,{id:i.deleted.id,deleted:!0});if(i.type!=="document")throw new m(400,"invalid_request",`${e} is a ${i.type}, not a document`);const r=await q(n,o,i,async a=>await S(n,a));if(r.needsMerge)throw new m(409,"needs_merge",`${i.name} has ${r.heads.length} heads; merge them before a review`,{id:i.id,next:`Read it with \`crtr canvas read ${i.id}\` and write the merged body with \`crtr doc edit\`.`});const d=i.owner===null?null:await E(n,i.owner),u=d===null?"":d.type==="node"?d.id:d.name;return{id:i.id,name:u===""?i.name:`${u}/${i.name}`,base:r.record.heads_key,body:r.heads[0].body}})}s(Q,"reviewedDocument");async function U(t){const e=x(t);return{status:200,body:{reviews:(await G(await D(e),async o=>{if(t.principal.class==="person")return!0;const i=await b(o.origin_node_id);return i!==null&&await N(t.principal,i.grantee??"app:terminal",i.node_id)})).map(f)}}}s(U,"handleList");async function X(t){const e=[],n=w(t,e);return(e.length>0||n===void 0)&&l(e),{status:200,body:f(await y(n))}}s(X,"handleRead");async function Y(t){const e=[],n=w(t,e);H(t,e),(e.length>0||n===void 0)&&l(e);const o=await A(n);return{status:200,body:o.outcome==="awaiting_companion"?{review:f(o.record),outcome:o.outcome}:{review:f(o.record),result:O(o.result),outcome:o.outcome}}}s(Y,"handleSubmit");async function Z(t){const e=[],n=w(t,e),o=z(t,e);(e.length>0||n===void 0)&&l(e);const i=await I(n,o);return{status:200,body:{review:f(i.record),outcome:i.outcome}}}s(Z,"handleCancel");async function ee(t){const e=[],n=w(t,e);(e.length>0||n===void 0)&&l(e);const o=await y(n),i=await C(o.review_id);if(i===null)throw new Error(`review anchor base is missing: ${o.review_id}`);return{status:200,body:{review_id:o.review_id,anchor_base_sha256:i.sha256,anchor_base_text:new TextDecoder("utf-8",{fatal:!0}).decode(i.bytes),file:o.file}}}s(ee,"handleDocument");const _e=[{method:"POST",pattern:"/v1/human/reviews",scope:"crtr:act",handler:J},{method:"GET",pattern:"/v1/human/reviews",handler:U},{method:"GET",pattern:"/v1/human/reviews/:review_id",handler:X},{method:"POST",pattern:"/v1/human/reviews/:review_id/submit",handler:Y},{method:"POST",pattern:"/v1/human/reviews/:review_id/cancel",handler:Z},{method:"GET",pattern:"/v1/human/reviews/:review_id/document",handler:ee}];export{M as parseCreate,_e as reviewRoutes};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var R=Object.defineProperty;var
|
|
1
|
+
var R=Object.defineProperty;var w=(o,t)=>R(o,"name",{value:t,configurable:!0});import{callerGrant as h}from"../principal.js";import{grantVersion as g,payerOfGrant as S}from"../../../core/grants/mirror.js";import{waitGrantChange as O}from"../../../core/grants/watch.js";import{RunError as n,idempotencyKeyOf as b,cancelRun as $,deleteRun as N,interruptRun as A,listRuns as j,messageRun as x,renameRun as B,requestedScopes as J,startRun as z,traceRun as C,waitRun as E}from"../../../core/runs/operations.js";import{canReadRun as v,requireRun as l,runCallerApp as G}from"../router.js";import{waitSeconds as y}from"../long-poll-wait.js";import{outputSchemaProblem as K}from"../../../core/runtime/structured-output.js";function f(o){if(!o||typeof o!="object"||Array.isArray(o))throw new n(400,"invalid_request","a JSON object is required");return o}w(f,"object");function q(o,t,i,d,u){if(o===null)return u;if(!/^(0|[1-9]\d*)$/.test(o)||!Number.isSafeInteger(Number(o))||Number(o)<i||Number(o)>d)throw new n(400,"invalid_request",`invalid ${t}`,t);return Number(o)}w(q,"integer");const T=256*1024;async function X(o,t,i,d,u,_){switch(o.name){case"grant.get":{if("class"in t)throw new n(403,"permission_error","an app token is required");const e=y("grant.get",d),s=d.get("since");if(s!==null&&!/^[A-Za-z0-9_-]{1,64}$/.test(s))throw new n(400,"invalid_request","invalid since","since");let a=await h(t);return e&&s!==null&&g(a)===s&&(await O(t.grant,e),a=await h(t)),{status:200,body:{sub:t.sub,grantee:t.grantee,client_id:t.client_id,grant:t.grant,rev:a.rev,resolved_scopes:a.resolved_scopes,spend_cap:a.spend_cap,exp:t.exp,payer:await S(t.grant),dependencies:a.dependencies??{},version:g(a)}}}case"run.start":{if("class"in t)throw new n(403,"permission_error","an app token is required");const e=f(u),s=["mode","parent","fork_from","node_id","env","tools","system_prompt"];for(const r of s)if(e[r]!==void 0)throw new n(403,"owner_only",`${r} is owner-only`,r);const a=["payer","model_policy","kind"];for(const r of a)if(e[r]!==void 0)throw new n(400,"invalid_request",`${r} is not available`,r);for(const r of Object.keys(e))if(!["prompt","scopes","metadata","profile","isolated","cwd","worktree","output_schema","message","model","deadline"].includes(r))throw new n(400,"invalid_request",`unknown field ${r}`,r);if(e.model!==void 0&&(typeof e.model!="string"||!e.model.trim()))throw new n(400,"invalid_request","model must be a non-empty string","model");if(e.deadline!==void 0&&(typeof e.deadline!="string"||!e.deadline.trim()))throw new n(400,"invalid_request","deadline must be a duration string such as 10m","deadline");if(e.profile!==void 0&&(typeof e.profile!="string"||!e.profile))throw new n(400,"invalid_request","profile must be a profile id","profile");if(e.isolated!==void 0&&typeof e.isolated!="boolean")throw new n(400,"invalid_request","isolated must be a boolean","isolated");if(e.cwd!==void 0&&(e.isolated!==!0||typeof e.cwd!="string"||!e.cwd))throw new n(400,"invalid_request","cwd is available only for an isolated run and must be an absolute path inside its root folder","cwd");if(e.worktree!==void 0&&e.isolated!==!0)throw new n(400,"invalid_request","worktree is not available","worktree");if(e.isolated===!0&&e.worktree!==void 0)throw new n(400,"invalid_request","worktree is unavailable for an isolated run","worktree");if(typeof e.prompt!="string"||!e.prompt.trim())throw new n(400,"invalid_request","prompt is required","prompt");if(e.message!==void 0&&(typeof e.message!="string"||!e.message.trim()))throw new n(400,"invalid_request","message must be a non-empty string","message");const m=e.metadata===void 0?{}:f(e.metadata);if(Buffer.byteLength(JSON.stringify(m))>4096)throw new n(400,"invalid_request","metadata exceeds 4 KB","metadata");let c;if(e.output_schema!==void 0){const r=e.output_schema;if(!r||typeof r!="object"||Array.isArray(r))throw new n(400,"invalid_request","output_schema must be a JSON Schema object","output_schema");if(Buffer.byteLength(JSON.stringify(r))>T)throw new n(400,"invalid_request","output_schema exceeds 256 KB","output_schema");const p=await K(r);if(p!==null)throw new n(400,"invalid_request",`output_schema is not usable: ${p}`,"output_schema");c=r}const k=J(t.resolved,e.scopes,t.grantee);return{status:201,body:await z(t,{prompt:e.prompt,scopes:k,metadata:m,profile:e.profile,isolated:e.isolated,cwd:e.cwd,...e.model===void 0?{}:{model:e.model},...e.deadline===void 0?{}:{deadline:e.deadline},...c===void 0?{}:{output_schema:c},...e.message===void 0?{}:{message:e.message}},b(_))}}case"run.list":{const e=d.get("status")??void 0;if(e&&!["running","waiting_on_user","idle","settled"].includes(e))throw new n(400,"invalid_request","invalid status","status");const s=d.get("app");if(s!==null&&!/^(?:app:)?[a-z0-9][a-z0-9-]*$/.test(s))throw new n(400,"invalid_request","invalid app","app");const a=s===null?G(t):s.startsWith("app:")?s:`app:${s}`;if(a!==null&&!await v(t,a))throw new n(404,"not_found","run not found");return{status:200,body:await j(a,{status:e,after:d.get("after")??void 0,limit:q(d.get("limit"),"limit",1,100,50),..."class"in t&&(t.class==="broker"||t.class==="cron")&&a!==null?{visible:w(async m=>await v(t,a,m),"visible")}:{}})}}case"run.get":{const e=y("run.get",d),s=await l(t,i),a=await E(i,s.grantee,e);return await l(t,i),{status:200,body:a}}case"run.message":{const e=f(u);if(typeof e.message!="string"||!e.message.trim())throw new n(400,"invalid_request","message is required","message");if(e.start_turn!==void 0&&typeof e.start_turn!="boolean")throw new n(400,"invalid_request","start_turn must be a boolean","start_turn");return{status:202,body:await x(await l(t,i,!0),e.message,void 0,e.start_turn,b(_))}}case"run.interrupt":{const e=f(u===void 0?{}:u);if(e.children!==void 0&&e.children!=="stop"&&e.children!=="continue")throw new n(400,"invalid_request","invalid children","children");return{status:200,body:await A(await l(t,i,!0),e.children)}}case"run.cancel":{const e=f(u===void 0?{}:u);if(e.keep_schedules!==void 0&&typeof e.keep_schedules!="boolean")throw new n(400,"invalid_request","invalid keep_schedules","keep_schedules");return{status:200,body:await $(await l(t,i,!0),{keepSchedules:e.keep_schedules})}}case"run.rename":{const e=f(u);for(const s of Object.keys(e))if(s!=="name")throw new n(400,"invalid_request",`unknown field ${s}`,s);return{status:200,body:await B(await l(t,i,!0),e.name)}}case"run.delete":{const{uploads_pending:e}=await N(await l(t,i,!0,!0));return{status:200,body:{run_id:i,uploads_pending:e}}}case"trace.get":{const e=d.get("format")??void 0;if(e&&e!=="entries")throw new n(400,"invalid_request","unknown trace format","format");const s=await l(t,i);return{status:200,body:await C(i,s.grantee,e)}}default:throw new n(404,"not_found","unknown operation")}}w(X,"handleRunOperation");export{X as handleRunOperation,q as integer};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var P=Object.defineProperty;var
|
|
1
|
+
var P=Object.defineProperty;var s=(t,e)=>P(t,"name",{value:e,configurable:!0});import{isSafeNodeId as S}from"../../../core/canvas/paths.js";import{admitStructuredRequest as T,bindStructuredRequest as N,getPendingStructuredRequestForNode as D,getStructuredRequest as l,settleStructuredRequest as _,toStructuredRequestDTO as f}from"../../../core/canvas/structured-requests.js";import{getNode as k}from"../../../core/canvas/canvas.js";import{ApiError as j}from"../../../api/errors.js";import{handleCreate as E}from"./nodes.js";import{handleMessage as $}from"./messages.js";import{outputSchemaProblem as x,writeStructuredRequestSidecar as R}from"../../../core/runtime/structured-output.js";import{requestBrokerTeardown as C}from"../../../core/runtime/host.js";import{transition as I}from"../../../core/runtime/lifecycle.js";import{subscribeStructuredRequest as M}from"../../structured-requests/notifier.js";import{SYNC_WORK_BUDGET_MS as v}from"../../../api/index.js";import{waitSeconds as F}from"../long-poll-wait.js";function n(t,e,r){throw new j(t,e,r)}s(n,"fail");function B(t){(typeof t!="object"||t===null||Array.isArray(t))&&n(400,"invalid_request","a structured request requires a JSON object");const e=t;(typeof e.request_id!="string"||!S(e.request_id))&&n(400,"request_id_invalid","request_id must use the node-id character rule"),e.mode!=="sync"&&e.mode!=="async"&&n(400,"invalid_request","mode must be sync or async"),typeof e.prompt!="string"&&n(400,"invalid_request","prompt must be a string"),(typeof e.output_schema!="object"||e.output_schema===null||Array.isArray(e.output_schema))&&n(400,"invalid_request","output_schema must be a JSON Schema object");const r=e.target;(typeof r!="object"||r===null)&&n(400,"invalid_request","target is required");const a=r;if(a.kind==="node")(typeof a.node_id!="string"||!S(a.node_id))&&n(400,"invalid_request","target.node_id must use the node-id character rule");else if(a.kind==="new"){(typeof a.create!="object"||a.create===null||Array.isArray(a.create))&&n(400,"invalid_request","target.create must be an object");for(const i of["prompt","output_schema","deadline","root_lifecycle","no_kickoff"])Object.hasOwn(a.create,i)&&n(400,"create_field_forbidden",`target.create may not carry ${i}`)}else n(400,"invalid_request","target.kind must be new or node");return e.work_budget_ms!==void 0&&(!Number.isInteger(e.work_budget_ms)||e.work_budget_ms<=0)&&n(400,"work_budget_invalid","work_budget_ms must be a positive integer"),e.deadline_at!==void 0&&(typeof e.deadline_at!="string"||Number.isNaN(Date.parse(e.deadline_at)))&&n(400,"invalid_request","deadline_at must be an ISO timestamp"),e}s(B,"parseCreate");function L(t,e){const r=t.deadline_at===void 0?null:Date.parse(t.deadline_at),a=t.work_budget_ms===void 0?null:e+t.work_budget_ms,i=r===null?a:a===null?r:Math.min(r,a);return t.mode==="sync"?Math.min(i??e+v,e+v):i}s(L,"deadlineFor");function A(t,e,r=""){return{...t,method:"POST",path:"",params:r===""?{}:{id:r},query:new URLSearchParams,body:e}}s(A,"context");async function w(t){return{status:200,body:{admitted:!0,request:f(t)}}}s(w,"terminalAdmission");function m(t){return t!==null&&Date.now()>=t}s(m,"deadlinePassed");async function p(t){return await w((await _(t,{intended:"expired"})).row)}s(p,"expireAdmission");async function O(t,e){let r;const a=new Promise(u=>{r=u}),i=M(t,r);try{return(await l(t)).state==="pending"&&e>0&&await Promise.race([a,new Promise(q=>setTimeout(q,e))]),f(await l(t))}finally{i()}}s(O,"waitForRequest");async function Y(t,e){const r=await O(t,Math.max(0,e-Date.now()));return r.state==="pending"?f((await _(t,{intended:"expired"})).row):r}s(Y,"waitForTerminal");async function G(t){const e=B(t.body),r=await x(e.output_schema);r!==null&&n(400,"invalid_request",`output_schema is not usable: ${r}`),e.mode==="sync"&&e.target.kind!=="new"&&n(400,"sync_requires_dedicated_node","sync requests require target.kind=new");const a=Date.now(),i=L(e,a);if(m(i))return{status:200,body:{admitted:!1,reason:"work_budget_exhausted"}};let u=null,q="terminal",y=!0;if(e.target.kind==="node"){u=e.target.node_id;const d=await k(u);d===null&&n(404,"node_not_found",`unknown node: ${u}`),(d.final_report!==null||d.status==="done"||d.status==="canceled"||d.status==="dead")&&n(409,"node_terminal",`node ${u} is terminal`),await D(u)!==null&&n(409,"structured_request_conflict",`node ${u} already has a pending structured request`),q="oneoff",y=!1}if(m(i))return{status:200,body:{admitted:!1,reason:"work_budget_exhausted"}};let b;try{b=await T({requestId:e.request_id,mode:e.mode,submission:q,dedicated:y,schema:e.output_schema,deadlineAt:i,nodeId:u,now:Date.now()})}catch(d){const o=String(d);throw(d.code==="ERR_SQLITE_CONSTRAINT_PRIMARYKEY"||o.includes("structured_requests.request_id"))&&n(409,"request_id_in_use",`request_id ${e.request_id} is already in use`),(o.includes("idx_structured_requests_one_pending_node")||o.includes("structured_requests.node_id"))&&n(409,"structured_request_conflict","the target node already has a pending structured request"),d}if(m(i))return await p(e.request_id);if(e.target.kind==="new")try{u=(await E(A(t,{...e.target.create,root:!0,root_lifecycle:"terminal",prompt:""}),{},{...i===null?{}:{deadlineAt:new Date(i).toISOString()},beforeBrokerLaunch:s(async o=>{if(u=o,m(i))throw new Error("structured request deadline expired before binding");const c=await N(e.request_id,o);if(!c.changed||c.row===null||c.row.state!=="pending")throw new Error("structured request bind did not remain pending");u=o,R(c.row)},"beforeBrokerLaunch")})).body.node_id}catch{const o=await l(e.request_id),c=o.state==="pending"?(await _(e.request_id,{intended:"failed",failureReason:o.node_id===null?"node_create_failed":"bind_failed"})).row:o;if(u!==null&&c.node_id===null){const g=await k(u);(g?.status==="active"||g?.status==="idle")&&await I(u,"cancel",{reason:"stranded"}),await C(u)}return await w(c)}else{if(m(i))return await p(e.request_id);try{R(b)}catch{return await w((await _(e.request_id,{intended:"failed",failureReason:"bind_failed"})).row)}}const h=await l(e.request_id);if(h.state!=="pending")return await w(h);if(m(i))return await p(e.request_id);try{await $(A(t,{body:e.prompt,tier:"normal"},u))}catch{return await w((await _(e.request_id,{intended:"failed",failureReason:"prompt_delivery_failed"})).row)}return e.mode==="async"?{status:202,body:{admitted:!0,request:f(await l(e.request_id))}}:{status:200,body:{admitted:!0,request:await Y(e.request_id,i)}}}s(G,"handleCreateStructuredRequest");async function J(t){const e=t.params.request_id,r=F("structured-request.get",t.query),a=await l(e);return a===null&&n(404,"structured_request_not_found",`unknown structured request: ${e}`),{status:200,body:r===0?f(a):await O(e,r*1e3)}}s(J,"handleReadStructuredRequest");async function K(t){const e=await _(t.params.request_id,{intended:"canceled"});return e.row===null&&n(404,"structured_request_not_found",`unknown structured request: ${t.params.request_id}`),{status:200,body:f(e.row)}}s(K,"handleCancelStructuredRequest");const ie=[{method:"POST",pattern:"/v1/structured-requests",handler:G},{method:"GET",pattern:"/v1/structured-requests/:request_id",handler:J},{method:"POST",pattern:"/v1/structured-requests/:request_id/cancel",handler:K}];export{ie as structuredRequestRoutes};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var l=Object.defineProperty;var p=(n,
|
|
1
|
+
var l=Object.defineProperty;var p=(n,r)=>l(n,"name",{value:r,configurable:!0});import{ApiError as t}from"../../../api/index.js";import{getNode as o,subscribe as w,subscriptionsOf as b,unsubscribe as f}from"../../../core/canvas/canvas.js";import{toSubscriptionDTO as h}from"../map.js";async function u(n){if(await o(n)===null)throw new t(404,"node_not_found",`unknown node: ${n}`)}p(u,"requireNode");async function g(n){const r=n.params.id,a=n.body??{},i=a.target;if(typeof i!="string"||i==="")throw new t(400,"invalid_request","subscribe body requires a `target` node id");if(i===r)throw new t(422,"unprocessable","a node cannot subscribe to itself");if(await u(r),await u(i),n.principal.class==="broker"){const s=await o(r),c=await o(i);if(s.grantee!==n.principal.app||c.grantee!==n.principal.app||s.run_id!==c.run_id||n.principal.run!==null&&s.run_id!==n.principal.run)throw new t(403,"other_app_run","subscriptions must stay within the calling app run")}const e=a.active??!0;await w(r,i,e);const d=(await b(r)).find(s=>s.node_id===i);if(d===void 0)throw new t(500,"internal","subscription edge vanished after write");return{status:200,body:h(d)}}p(g,"handleSubscribe");async function _(n){const r=n.params.id,a=n.params.target;if(await u(r),n.principal.class==="broker"){const i=await o(r),e=await o(a);if(i.grantee!==n.principal.app||n.principal.run!==null&&i.run_id!==n.principal.run||e&&(e.grantee!==i.grantee||e.run_id!==i.run_id))throw new t(403,"other_app_run","subscriptions must stay within the calling app run")}return await f(r,a),{status:204}}p(_,"handleUnsubscribe");const E=[{method:"POST",pattern:"/v1/nodes/:id/subscriptions",handler:g},{method:"DELETE",pattern:"/v1/nodes/:id/subscriptions/:target",handler:_}];export{E as subscriptionRoutes};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var w=Object.defineProperty;var s=(e,a)=>w(e,"name",{value:a,configurable:!0});import{isAbsolute as h,resolve as _}from"node:path";import{RunError as n}from"../../../core/runs/operations.js";import{invalidStorageName as m,storageClient as l,StorageRefused as y,UPLOAD_MAX_BYTES as g}from"../../../core/storage/client.js";import{serveDownload as b}from"../../../core/storage/download.js";import{createShare as q,deleteOwnShare as v,listOwnShares as A}from"../../../core/storage/shares.js";import{getUpload as S,insertUpload as k,uploadUseAt as x}from"../../../core/storage/tables.js";import{requireRun as z}from"../router.js";const C=new Set(["upload.create","attachment.link","file.download","share.create","share.list","share.delete"]);function c(e){if(!e||typeof e!="object"||Array.isArray(e))throw new n(400,"invalid_request","a JSON object is required");return e}s(c,"object");function f(e){return{app:e.grantee,resolved:e.resolved,launched:null}}s(f,"fileCaller");const O=/^[A-Za-z0-9][A-Za-z0-9!#$&^_.+-]{0,126}\/[A-Za-z0-9][A-Za-z0-9!#$&^_.+-]{0,126}(?:\s*;.{0,200})?$/;async function T(e,a){const i=c(a);for(const p of Object.keys(i))if(!["name","media_type","size"].includes(p))throw new n(400,"invalid_request",`unknown field ${p}`,p);const{name:r,media_type:o,size:t}=i;if(typeof t!="number"||!Number.isSafeInteger(t)||t<0)throw new n(400,"invalid_request","size must be a non-negative integer","size");if(t>g)throw new n(400,"invalid_request","size exceeds 100 MiB","size");if(typeof r!="string")throw new n(400,"invalid_request","name is required","name");const d=m(r);if(d)throw new n(400,"invalid_request",d,"name");if(typeof o!="string"||!O.test(o))throw new n(400,"invalid_request","media_type must be a media type","media_type");const u=await l().createUpload({name:r,media_type:o,size:t});return await k({upload_id:u.upload_id,grantee:e.grantee,name:r,media_type:o,size:t,created_at:new Date().toISOString()}),{upload_id:u.upload_id,url:u.url,upload_link:u.upload_link,expires_at:u.expires_at}}s(T,"uploadCreate");async function D(e,a){if(!a)throw new n(400,"invalid_request","path is required","path");if(!h(a))throw new n(400,"invalid_request","path must be absolute","path");const i=await x(_(a)),r=s(()=>new n(404,"not_found","no upload is recorded at that path"),"missing");if(!i)throw r();try{await z(e,i.run_id)}catch(t){throw t instanceof n&&t.code==="not_found"?r():t}const o=await S(i.upload_id);if(!o||o.delete_pending_since)throw r();try{return await l().signDownload(i.upload_id)}catch(t){throw t instanceof y?r():t}}s(D,"attachmentLink");async function M(e,a,i,r,o){switch(e.name){case"upload.create":return{status:201,body:await T(a,o)};case"attachment.link":return{status:200,body:await D(a,r.get("path"))};case"share.create":{const t=c(o);for(const d of Object.keys(t))if(!["path","expires_at"].includes(d))throw new n(400,"invalid_request",`unknown field ${d}`,d);return{status:201,body:await q(f(a),{path:t.path,expires_at:t.expires_at})}}case"share.list":return{status:200,body:await A(a.grantee)};case"share.delete":return{status:200,body:await v(a.grantee,i.share_id)};default:throw new n(404,"not_found","unknown operation")}}s(M,"handleTransferOperation");function P(e,a,i,r){return b(e,a,f(i),r.get("path"))}s(P,"handleTransferDownload");export{C as TRANSFER_OPERATIONS,f as fileCaller,P as handleTransferDownload,M as handleTransferOperation};
|
package/dist/daemon/api/map.d.ts
CHANGED
|
@@ -52,7 +52,7 @@ export declare function toGraphNodeDTO(row: {
|
|
|
52
52
|
fault: NodeRow['fault'];
|
|
53
53
|
streaming: boolean;
|
|
54
54
|
}): GraphNodeDTO;
|
|
55
|
-
export declare function toNodeSummaryDTO(row: NodeRow, paused?: boolean): NodeSummaryDTO
|
|
55
|
+
export declare function toNodeSummaryDTO(row: NodeRow, paused?: boolean): Promise<NodeSummaryDTO>;
|
|
56
56
|
/** The subscription/child edges a detail projection needs. The handler gathers
|
|
57
57
|
* these from `subscriptionsOf`/`subscribersOf` + a children query and passes
|
|
58
58
|
* them in, so this module stays a pure projection with no db reach. */
|
|
@@ -68,14 +68,14 @@ export interface NodeEdgesInput {
|
|
|
68
68
|
export declare function toNodeEdgesDTO(meta: NodeMeta, edges: NodeEdgesInput): NodeEdgesDTO;
|
|
69
69
|
/** Absolute filesystem paths for a node (absorbs the `paths` read).
|
|
70
70
|
* App assignment comes from the authoritative node row. */
|
|
71
|
-
export declare function toNodePathsDTO(nodeId: string, grantee: string): NodePathsDTO
|
|
71
|
+
export declare function toNodePathsDTO(nodeId: string, grantee: string): Promise<NodePathsDTO>;
|
|
72
72
|
/** Project a node's managed git worktree, if any. */
|
|
73
73
|
export declare function toNodeWorktreeDTO(w: ManagedWorktree): NodeWorktreeDTO;
|
|
74
74
|
/** Project the hydrated node view (`getNode` → `NodeMeta`) into a detail DTO.
|
|
75
75
|
* The summary fields come from the meta's runtime half (hydrated from the
|
|
76
76
|
* authoritative row); the identity extras (description/cycles/session) come
|
|
77
77
|
* from the meta's identity half. Edges are gathered by the handler. */
|
|
78
|
-
export declare function toNodeDetailDTO(meta: NodeMeta, edges: NodeEdgesInput): NodeDetailDTO
|
|
78
|
+
export declare function toNodeDetailDTO(meta: NodeMeta, edges: NodeEdgesInput): Promise<NodeDetailDTO>;
|
|
79
79
|
/** Project a `reviveNode` result. `revived` is true only when a fresh launch
|
|
80
80
|
* actually happened — the double-revive no-op (already-alive) returns without a
|
|
81
81
|
* `launch` handle, so its absence is the "nothing relaunched" signal. `status`
|
package/dist/daemon/api/map.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var g=Object.defineProperty;var r=(e,t)=>g(e,"name",{value:t,configurable:!0});import{join as b}from"node:path";import{readOutputResult as y}from"../../core/runtime/structured-output.js";import{ReviewOperationError as _}from"../../core/review/types.js";import{cronSinkDisplay as x}from"../../core/canvas/crons.js";import{isProfilePaused as c,profileDir as O,sanitizeProfileMetadata as D}from"../../core/profiles/manifest.js";import{nodeMetaPath as T,transcriptPath as E,viewSocketPath as S}from"../../core/canvas/paths.js";import{appForNode as f,contextDir as A,nodeAgentDir as R}from"../../core/canvas/node-agent-paths.js";import{readControllerWait as p}from"../../core/canvas/waits.js";import{FinalizationError as z}from"../../core/feed/feed.js";import{NodeIdConflictError as N}from"../../core/runtime/nodes.js";import{ScopeDeniedError as C}from"../../core/scopes.js";import{isBeneathRefusal as j}from"../../core/spaces/open-beneath.js";import{CrtrError as a}from"../../core/errors.js";import{WorktreeError as q}from"../../core/worktree.js";import{ApiError as I}from"../../api/errors.js";import{RunError as s}from"../../core/runs/operations.js";import{ExitCode as o}from"../../types.js";function pe(e,t){const{report:n}=e;return{stores:n.stores.map(i=>({root:i.root,owner:{...i.owner},docs:i.docs,...i.skipped===void 0?{}:{skipped:i.skipped}})),counts:n.counts,rewrites:n.rewrites,dropped_fields:n.droppedFields,skipped:n.skipped,resolutions:n.resolutions.map(i=>({kind:i.kind,message:i.message,paths:i.paths})),blockers:e.blockers.map(i=>({kind:i.kind,message:i.message,paths:i.paths})),dryRun:e.dryRun,pending:e.pending,resumed:t.resumed,...t.resumeError===void 0?{}:{resume_error:t.resumeError}}}r(pe,"toMigrateStateDTO");function F(e,t){try{return y(e,t)??null}catch{return null}}r(F,"readStructuredResult");function P(e){return e.outcome_at===null||e.outcome_at===void 0||e.outcome_kind===null||e.outcome_kind===void 0||e.outcome_reason===null||e.outcome_reason===void 0?null:{kind:e.outcome_kind,reason:e.outcome_reason,settled_at:e.outcome_at}}r(P,"toNodeOutcomeSummaryDTO");function m(e){if(e.outcome_at===null||e.outcome_at===void 0||e.outcome_kind===null||e.outcome_kind===void 0||e.outcome_reason===null||e.outcome_reason===void 0)return null;let t=null;if(e.outcome_detail_json!==null&&e.outcome_detail_json!==void 0)try{t=JSON.parse(e.outcome_detail_json)}catch{t=null}const n=e.final_report??null,i={node_id:e.node_id,revision:e.outcome_revision??1,settled_at:e.outcome_at,final_report:n===null?null:`${e.node_id}/${n}`,structured_result:e.outcome_kind==="result"?F(e.node_id,e.grantee):null,detail:t};return e.outcome_kind==="result"?{...i,kind:"result",reason:e.outcome_reason,declined:null}:e.outcome_reason==="declined"?{...i,kind:"failure",reason:"declined",declined:t?.declined??null}:{...i,kind:"failure",reason:e.outcome_reason,declined:null}}r(m,"toNodeOutcomeDTO");function me(e){const t=m(e);return t===null||t.reason==="parked"?null:t.kind==="result"||t.reason==="finished"?{...t,kind:"result",reason:"finalized",declined:null}:t.reason==="declined"?{...t,reason:"declined",details:t.declined}:t.reason==="deadline_exceeded"?{...t,reason:"deadline_exceeded",declined:null}:t.reason==="cap_exhausted"?{...t,reason:"cap_exhausted",declined:null}:t.reason==="closed"||t.reason==="stranded"||t.reason==="retired"?{...t,reason:"canceled",declined:null}:{...t,reason:"runtime_error",declined:null,details:{crouter_reason:t.reason}}}r(me,"toRunOutcomeDTO");function ve(e){const t=e.lastFailure;return{node_id:e.nodeId,state:e.state,action:e.actionName,attempt:e.attempt,next_attempt_at:e.nextAttemptAt===0?null:new Date(e.nextAttemptAt).toISOString(),accepted_at:e.acceptedAt===null?null:new Date(e.acceptedAt).toISOString(),permanent_failed_at:e.permanentFailedAt===null?null:new Date(e.permanentFailedAt).toISOString(),last_failure:t===null?null:{kind:t.kind,...t.exitCode===void 0?{}:{exit_code:t.exitCode},...t.signal===void 0?{}:{signal:t.signal},...t.message===void 0?{}:{message:t.message}},created_at:new Date(e.createdAt).toISOString(),updated_at:new Date(e.updatedAt).toISOString()}}r(ve,"toOutcomeDeliveryDTO");function ke(e){return{node_id:e.node_id,name:e.name,description:e.description,cycles:e.cycles,kind:e.kind,status:e.status,frozen_at:e.frozen_at,pi_pid:e.pi_pid,telemetry_context_tokens:e.telemetry_context_tokens,telemetry_last_activity:e.telemetry_last_activity,fault:e.fault&&e.fault.link!=="broker\u2194crtrd"?{...e.fault,link:e.fault.link}:null,streaming:e.streaming}}r(ke,"toGraphNodeDTO");function he(e,t=c(e.profile_id)){return{node_id:e.node_id,name:e.name,description:e.description,cycles:e.cycles,kind:e.kind,mode:e.mode,lifecycle:e.lifecycle,status:e.status,cwd:e.cwd,host_kind:e.host_kind,profile_id:e.profile_id,scopes:e.scopes,isolated:e.isolated,grantee:e.grantee??f(e.node_id),profile_paused:t,parent:e.parent,created:e.created,intent:e.intent,waiting_for:p(e.node_id)?.controllerId??null,frozen_at:e.frozen_at??null,terminal_reason:e.terminal_reason??null,pi_pid:e.pi_pid,pi_pid_identity:e.pi_pid_identity,window:e.window,tmux_session:e.tmux_session,pane:e.pane,final_report:e.final_report??null,finalized_at:e.finalized_at??null,deadline_at:e.deadline_at??null,telemetry_tokens_in:e.telemetry_tokens_in??null,telemetry_context_tokens:e.telemetry_context_tokens??null,telemetry_last_activity:e.telemetry_last_activity??null,telemetry_updated_at:e.telemetry_updated_at??null,outcome:P(e),fault:e.fault&&e.fault.link!=="broker\u2194crtrd"?{...e.fault,link:e.fault.link}:null,streaming:e.streaming??!1}}r(he,"toNodeSummaryDTO");function U(e,t){return{parent:e.parent??null,spawned_by:e.spawned_by??null,subscribes_to:t.subscribesTo.map(n=>n.node_id),subscribers:t.subscribers.map(n=>n.node_id),children:[...t.children]}}r(U,"toNodeEdgesDTO");function G(e,t){return{node_dir:R(e,t),context_dir:A(e,t),meta_path:T(e),transcript_path:E(e),view_socket:S(e)}}r(G,"toNodePathsDTO");function M(e){const t={state:e.state,path:e.path,branch:e.branch,repo_root:e.repo_root,base_ref:e.base_ref,base_sha:e.base_sha,created:e.created};return e.cleanup!==void 0&&(t.cleanup=e.cleanup),e.closed!==void 0&&(t.closed=e.closed),e.abandoned!==void 0&&(t.abandoned={...e.abandoned}),t}r(M,"toNodeWorktreeDTO");function ge(e,t){const n=f(e.node_id),i={node_id:e.node_id,name:e.name,kind:e.kind,mode:e.mode,lifecycle:e.lifecycle,status:e.status,cwd:e.cwd,host_kind:e.host_kind??null,profile_id:e.profile_id??null,scopes:e.scopes??null,isolated:e.isolated===!0,grantee:n,profile_paused:c(e.profile_id),parent:e.parent??null,created:e.created,intent:e.intent??null,waiting_for:p(e.node_id)?.controllerId??null,frozen_at:e.frozen_at??null,terminal_reason:e.terminal_reason??null,pi_pid:e.pi_pid??null,pi_pid_identity:e.pi_pid_identity??null,window:e.window??null,tmux_session:e.tmux_session??null,pane:e.pane??null,final_report:e.final_report??null,finalized_at:e.finalized_at??null,deadline_at:e.deadline_at??null,telemetry_tokens_in:e.telemetry_tokens_in??null,telemetry_context_tokens:e.telemetry_context_tokens??null,telemetry_last_activity:e.telemetry_last_activity??null,telemetry_updated_at:e.telemetry_updated_at??null,outcome:m(e),fault:e.fault&&e.fault.link!=="broker\u2194crtrd"?{...e.fault,link:e.fault.link}:null,streaming:e.streaming??!1,creator:e.creator??null,edges:U(e,t),paths:G(e.node_id,n)};return e.description!==void 0&&(i.description=e.description),e.title!==void 0&&(i.title=e.title),e.icon!==void 0&&(i.icon=e.icon),e.cycles!==void 0&&(i.cycles=e.cycles),i.context_tokens=e.telemetry_context_tokens??e.telemetry_tokens_in??null,e.pi_session_id!==void 0&&(i.pi_session_id=e.pi_session_id??null),i.model_override=e.model_override??null,e.pi_session_file!==void 0&&(i.pi_session_file=e.pi_session_file??null),e.review_binding!==void 0&&(i.review_binding=e.review_binding===null?null:{...e.review_binding.kind===void 0?{}:{kind:e.review_binding.kind},review_id:e.review_binding.review_id,origin_node_id:e.review_binding.origin_node_id,branch_file:e.review_binding.branch_file,target_file:e.review_binding.target_file}),e.managed_worktree!=null&&(i.worktree=M(e.managed_worktree)),i}r(ge,"toNodeDetailDTO");function be(e,t,n,i){return{node_id:e,revived:t.launch!==void 0,resumed:t.resumed,status:n,outcome:t.outcome,ready:i}}r(be,"toReviveResultDTO");function ye(e){return{root:e.root,closed:[...e.closed],spared:[...e.spared]}}r(ye,"toCloseResultDTO");function xe(e,t,n){const i={report:e.report,notified:[...e.deliveredTo]};return t!==void 0&&(i.transitioned=t),n!==void 0&&(i.worktree_auto_dropped=!0,i.worktree_auto_dropped_path=n),i}r(xe,"toReportResultDTO");function Oe(e){return{node_id:e.node_id,active:e.active,created:e.created}}r(Oe,"toSubscriptionDTO");function W(e){if(e===null||e==="")return[];try{const t=JSON.parse(e);return typeof t=="object"&&t!==null&&!Array.isArray(t)?Object.keys(t):[]}catch{return[]}}r(W,"envKeys");function De(e,t){return{cron_id:e.cron_id,name:e.name,created_by:e.created_by,command:e.command,grant_id:e.grant_id,scopes:e.scopes,origin_run_id:e.origin_run_id,isolated:e.isolated,fire_at:e.fire_at,recur:e.recur,tz:e.tz,expires_at:e.expires_at,anchor_node:e.anchor_node,cancel_on_wake:e.cancel_on_wake,cwd:e.cwd,profile:e.profile,scope:e.scope,env_keys:W(e.env_json),run_timeout_s:e.run_timeout_s,overlap:e.overlap,on_output:e.on_output,sink:x(e.sink),tier:e.tier,state:e.state,held:e.held,run_state:e.run_state,last_run:t==null?null:{finished:t.finished,exit_code:t.exit_code,delivered:t.delivered},created:e.created,updated:e.updated}}r(De,"toCronDTO");function Te(e){return{run_id:e.run_id,started:e.started,finished:e.finished,duration_ms:e.duration_ms,exit_code:e.exit_code,stdout_head:e.stdout_head,stderr_head:e.stderr_head,delivered:e.delivered}}r(Te,"toCronRunDTO");function Ee(e){return{id:e.profileId,app:e.manifest.grantee??"app:terminal",name:e.manifest.name,projects:e.manifest.projects.map(t=>({...t})),delivery_limits:{...e.manifest.delivery_limits},paused_at:e.manifest.paused_at,default_kind:e.manifest.default_kind??"general",metadata:D(e.manifest.metadata),default_dir:null,created_at:e.manifest.created_at,last_used_at:e.manifest.last_used_at,profile_path:O(e.profileId)}}r(Ee,"toProfileDTO");function v(e,t={}){const n={review_id:e.review_id,origin_kind:e.origin_kind,origin_node_id:e.origin_node_id,review_dir:e.review_dir,companion_node_id:e.companion_node_id,file:e.file,state:e.state,created:e.created,source_missing:e.source_missing,anchor_base_sha256:e.anchor_base_sha256};return e.document_name!==null&&(n.document=e.document_name),e.opened_at!==null&&(n.opened_at=e.opened_at),e.submit_requested_at!==null&&(n.submit_requested_at=e.submit_requested_at),e.approved_at!==null&&(n.approved_at=e.approved_at),e.changed!==null&&(n.changed=e.changed),e.comments_total!==null&&(n.comments_total=e.comments_total),e.comments_unresolved!==null&&(n.comments_unresolved=e.comments_unresolved),e.canceled_at!==null&&(n.canceled_at=e.canceled_at),e.cancel_reason!==null&&(n.cancel_reason=e.cancel_reason),e.cancel_actor!==null&&(n.cancel_actor=e.cancel_actor),t.result_path!==void 0&&(n.result_path=t.result_path),e.delivery_error!==null&&(n.delivery_error=e.delivery_error),e.projection_error!==null&&(n.projection_error=e.projection_error),n}r(v,"toReviewDTO");function Se(e){return{comment_id:e.comment_id,review_id:e.review_id,status:e.status,revision:e.revision,text:e.text,anchor:{...e.anchor},anchor_state:e.anchor_state,anchor_line_text:e.anchor_line_text,anchor_doc_hash:e.anchor_doc_hash,author:{kind:e.author.kind,...e.author.node_id===null?{}:{node_id:e.author.node_id}},updated_by:{kind:e.updated_by.kind,...e.updated_by.node_id===null?{}:{node_id:e.updated_by.node_id}},created_at:e.created_at,updated_at:e.updated_at,...e.resolved_at===null?{}:{resolved_at:e.resolved_at},...e.deleted_at===null?{}:{deleted_at:e.deleted_at},created_seq:e.created_seq}}r(Se,"toReviewCommentDTO");function B(e){return{id:e.id,quote:e.quote,...e.context===void 0?{}:{context:e.context},note:e.note,status:e.status,created_at:e.createdAt,...e.resolvedAt===void 0?{}:{resolved_at:e.resolvedAt}}}r(B,"toPageFeedbackCommentDTO");function Ae(e){return{companion_node_id:e.companionNodeId??null,open_count:e.comments.filter(t=>t.status==="open").length,comments:e.comments.map(B)}}r(Ae,"toPageFeedbackDTO");function Re(e){return{seq:e.seq,review_id:e.review_id,comment_id:e.comment_id,kind:e.kind,state_change:e.state_change===1,revision_after:e.revision_after,actor:{kind:e.actor.kind,...e.actor.node_id===null?{}:{node_id:e.actor.node_id}},at:e.at,operation_id:e.operation_id,...e.payload===void 0?{}:{payload:e.payload}}}r(Re,"toReviewCommentEventDTO");function ze(e){return{file:e.file,submitted:e.submitted,approved:e.approved,comments:e.comments.map(n=>({...n})),submittedAt:e.submittedAt,savedAt:e.savedAt,reviewId:e.review_id,changed:e.changed,baselineSha256:e.baseline_sha256,approvedSha256:e.approved_sha256,companionNodeId:e.companion_node_id,commentsTotal:e.comments_total,commentsUnresolved:e.comments_unresolved}}r(ze,"toFeedbackResultDTO");const L=!0,$=Object.freeze({review_origin_missing:{status:400,code:"review_origin_unavailable"},review_origin_unforkable:{status:400,code:"review_origin_unavailable"},review_branch_unavailable:{status:409,code:"review_branch_unavailable"},branch_lost:{status:409,code:"review_branch_unavailable"},review_companion_unbound:{status:409,code:"review_companion_unbound"},review_bridge_unsubscribed:{status:409,code:"review_bridge_unavailable"},review_target_unreviewable:{status:400,code:"review_file_unreadable"},source_unreadable:{status:409,code:"review_source_unreadable"},delivery_unroutable:{status:409,code:"review_delivery_unroutable"},unknown_review:{status:404,code:"unknown_review"},review_terminal:{status:409,code:"review_terminal_conflict"},review_required:{status:400,code:"review_required"},stale_document:{status:409,code:"stale_document"},stale_revision:{status:409,code:"stale_revision"},unknown_comment:{status:404,code:"unknown_comment"},comment_deleted:{status:409,code:"comment_deleted"},invalid_anchor:{status:400,code:"invalid_anchor"},anchor_out_of_range:{status:400,code:"anchor_out_of_range"},text_too_long:{status:400,code:"text_too_long"},comment_limit_reached:{status:409,code:"comment_limit_reached"},stale_comment:{status:409,code:"stale_comment"},range_batch_incomplete:{status:409,code:"range_batch_incomplete"},range_batch_stale:{status:409,code:"range_batch_stale"}});function K(e){const t=k(e);if(typeof t=="object"&&t!==null&&typeof t.status=="number"&&typeof t.code=="string")return{status:t.status,code:t.code};if(t instanceof z)return t.code==="unknown_node"?{status:404,code:"node_not_found"}:t.code==="already_finalized"?{status:409,code:"already_finalized"}:{status:409,code:"finalization_forbidden"};if(t instanceof N)return{status:409,code:"node_id_exists"};if(t instanceof C)return{status:403,code:"scope_denied"};if(j(t))return{status:400,code:"invalid_request"};if(t instanceof _)return $[t.code];if(t instanceof a)return["kind_owned","name_taken","hop_limit","not_a_queue"].includes(t.code)?{status:409,code:t.code}:t.code==="invalid_publish_token"?{status:401,code:t.code}:t.code==="forbidden"||t.code==="argv_forbidden"||t.code==="scope_missing"?{status:403,code:t.code}:{status:J(t.exitCode),code:t.code};if(t instanceof Error){const n=t.message;if(/unknown node/i.test(n))return{status:404,code:"node_not_found"};if(/finalization latch/i.test(n))return{status:409,code:"already_finalized"};if(/illegal lifecycle transition/i.test(n))return{status:409,code:"illegal_transition"}}return{status:500,code:"internal"}}r(K,"errorToStatus");function k(e){if(!(e instanceof q))return e;const t=e.code==="unknown_node"?o.NOT_FOUND:o.GENERAL,n={error:e.code,message:e.message,next:e.next};return e.detail!==void 0&&(n.received=e.detail),new a(e.code,e.message,t,n)}r(k,"normalizeThrow");function V(e){if(e.code!=="review_terminal")return e.detail;const{review:t,...n}=e.detail;return{...n,review:H(t)}}r(V,"reviewErrorDetails");function H(e){return e.state!=="approved"?v(e):v(e,{result_path:b(e.review_dir,"result.json")})}r(H,"terminalConflictReviewDTO");function J(e){switch(e){case o.NOT_FOUND:return 404;case o.USAGE:return 400;case o.AMBIGUOUS:return 400;case o.NETWORK:return 503;case o.GENERAL:return 400;default:return 500}}r(J,"statusForExitCode");function Q(e){const n=(e instanceof Error?e.message:String(e)).split(`
|
|
1
|
+
var g=Object.defineProperty;var r=(e,t)=>g(e,"name",{value:t,configurable:!0});import{join as b}from"node:path";import{readOutputResult as y}from"../../core/runtime/structured-output.js";import{ReviewOperationError as _}from"../../core/review/types.js";import{cronSinkDisplay as x}from"../../core/canvas/crons.js";import{isProfilePaused as c,profileDir as O,sanitizeProfileMetadata as D}from"../../core/profiles/manifest.js";import{nodeMetaPath as T,transcriptPath as E,viewSocketPath as S}from"../../core/canvas/paths.js";import{appForNode as f,contextDir as A,nodeAgentDir as R}from"../../core/canvas/node-agent-paths.js";import{readControllerWait as p}from"../../core/canvas/waits.js";import{FinalizationError as z}from"../../core/feed/feed.js";import{NodeIdConflictError as N}from"../../core/runtime/nodes.js";import{ScopeDeniedError as C}from"../../core/scopes.js";import{isBeneathRefusal as j}from"../../core/spaces/open-beneath.js";import{CrtrError as a}from"../../core/errors.js";import{WorktreeError as q}from"../../core/worktree.js";import{ApiError as I}from"../../api/errors.js";import{RunError as s}from"../../core/runs/operations.js";import{ExitCode as o}from"../../types.js";function pe(e,t){const{report:n}=e;return{stores:n.stores.map(i=>({root:i.root,owner:{...i.owner},docs:i.docs,...i.skipped===void 0?{}:{skipped:i.skipped}})),counts:n.counts,rewrites:n.rewrites,dropped_fields:n.droppedFields,skipped:n.skipped,resolutions:n.resolutions.map(i=>({kind:i.kind,message:i.message,paths:i.paths})),blockers:e.blockers.map(i=>({kind:i.kind,message:i.message,paths:i.paths})),dryRun:e.dryRun,pending:e.pending,resumed:t.resumed,...t.resumeError===void 0?{}:{resume_error:t.resumeError}}}r(pe,"toMigrateStateDTO");function F(e,t){try{return y(e,t)??null}catch{return null}}r(F,"readStructuredResult");function P(e){return e.outcome_at===null||e.outcome_at===void 0||e.outcome_kind===null||e.outcome_kind===void 0||e.outcome_reason===null||e.outcome_reason===void 0?null:{kind:e.outcome_kind,reason:e.outcome_reason,settled_at:e.outcome_at}}r(P,"toNodeOutcomeSummaryDTO");function m(e){if(e.outcome_at===null||e.outcome_at===void 0||e.outcome_kind===null||e.outcome_kind===void 0||e.outcome_reason===null||e.outcome_reason===void 0)return null;let t=null;if(e.outcome_detail_json!==null&&e.outcome_detail_json!==void 0)try{t=JSON.parse(e.outcome_detail_json)}catch{t=null}const n=e.final_report??null,i={node_id:e.node_id,revision:e.outcome_revision??1,settled_at:e.outcome_at,final_report:n===null?null:`${e.node_id}/${n}`,structured_result:e.outcome_kind==="result"?F(e.node_id,e.grantee):null,detail:t};return e.outcome_kind==="result"?{...i,kind:"result",reason:e.outcome_reason,declined:null}:e.outcome_reason==="declined"?{...i,kind:"failure",reason:"declined",declined:t?.declined??null}:{...i,kind:"failure",reason:e.outcome_reason,declined:null}}r(m,"toNodeOutcomeDTO");function me(e){const t=m(e);return t===null||t.reason==="parked"?null:t.kind==="result"||t.reason==="finished"?{...t,kind:"result",reason:"finalized",declined:null}:t.reason==="declined"?{...t,reason:"declined",details:t.declined}:t.reason==="deadline_exceeded"?{...t,reason:"deadline_exceeded",declined:null}:t.reason==="cap_exhausted"?{...t,reason:"cap_exhausted",declined:null}:t.reason==="closed"||t.reason==="stranded"||t.reason==="retired"?{...t,reason:"canceled",declined:null}:{...t,reason:"runtime_error",declined:null,details:{crouter_reason:t.reason}}}r(me,"toRunOutcomeDTO");function ve(e){const t=e.lastFailure;return{node_id:e.nodeId,state:e.state,action:e.actionName,attempt:e.attempt,next_attempt_at:e.nextAttemptAt===0?null:new Date(e.nextAttemptAt).toISOString(),accepted_at:e.acceptedAt===null?null:new Date(e.acceptedAt).toISOString(),permanent_failed_at:e.permanentFailedAt===null?null:new Date(e.permanentFailedAt).toISOString(),last_failure:t===null?null:{kind:t.kind,...t.exitCode===void 0?{}:{exit_code:t.exitCode},...t.signal===void 0?{}:{signal:t.signal},...t.message===void 0?{}:{message:t.message}},created_at:new Date(e.createdAt).toISOString(),updated_at:new Date(e.updatedAt).toISOString()}}r(ve,"toOutcomeDeliveryDTO");function ke(e){return{node_id:e.node_id,name:e.name,description:e.description,cycles:e.cycles,kind:e.kind,status:e.status,frozen_at:e.frozen_at,pi_pid:e.pi_pid,telemetry_context_tokens:e.telemetry_context_tokens,telemetry_last_activity:e.telemetry_last_activity,fault:e.fault&&e.fault.link!=="broker\u2194crtrd"?{...e.fault,link:e.fault.link}:null,streaming:e.streaming}}r(ke,"toGraphNodeDTO");async function he(e,t=c(e.profile_id)){return{node_id:e.node_id,name:e.name,description:e.description,cycles:e.cycles,kind:e.kind,mode:e.mode,lifecycle:e.lifecycle,status:e.status,cwd:e.cwd,host_kind:e.host_kind,profile_id:e.profile_id,scopes:e.scopes,isolated:e.isolated,grantee:e.grantee??await f(e.node_id),profile_paused:t,parent:e.parent,created:e.created,intent:e.intent,waiting_for:(await p(e.node_id))?.controllerId??null,frozen_at:e.frozen_at??null,terminal_reason:e.terminal_reason??null,pi_pid:e.pi_pid,pi_pid_identity:e.pi_pid_identity,window:e.window,tmux_session:e.tmux_session,pane:e.pane,final_report:e.final_report??null,finalized_at:e.finalized_at??null,deadline_at:e.deadline_at??null,telemetry_tokens_in:e.telemetry_tokens_in??null,telemetry_context_tokens:e.telemetry_context_tokens??null,telemetry_last_activity:e.telemetry_last_activity??null,telemetry_updated_at:e.telemetry_updated_at??null,outcome:P(e),fault:e.fault&&e.fault.link!=="broker\u2194crtrd"?{...e.fault,link:e.fault.link}:null,streaming:e.streaming??!1}}r(he,"toNodeSummaryDTO");function U(e,t){return{parent:e.parent??null,spawned_by:e.spawned_by??null,subscribes_to:t.subscribesTo.map(n=>n.node_id),subscribers:t.subscribers.map(n=>n.node_id),children:[...t.children]}}r(U,"toNodeEdgesDTO");async function G(e,t){return{node_dir:await R(e,t),context_dir:await A(e,t),meta_path:T(e),transcript_path:E(e),view_socket:S(e)}}r(G,"toNodePathsDTO");function M(e){const t={state:e.state,path:e.path,branch:e.branch,repo_root:e.repo_root,base_ref:e.base_ref,base_sha:e.base_sha,created:e.created};return e.cleanup!==void 0&&(t.cleanup=e.cleanup),e.closed!==void 0&&(t.closed=e.closed),e.abandoned!==void 0&&(t.abandoned={...e.abandoned}),t}r(M,"toNodeWorktreeDTO");async function ge(e,t){const n=await f(e.node_id),i={node_id:e.node_id,name:e.name,kind:e.kind,mode:e.mode,lifecycle:e.lifecycle,status:e.status,cwd:e.cwd,host_kind:e.host_kind??null,profile_id:e.profile_id??null,scopes:e.scopes??null,isolated:e.isolated===!0,grantee:n,profile_paused:c(e.profile_id),parent:e.parent??null,created:e.created,intent:e.intent??null,waiting_for:(await p(e.node_id))?.controllerId??null,frozen_at:e.frozen_at??null,terminal_reason:e.terminal_reason??null,pi_pid:e.pi_pid??null,pi_pid_identity:e.pi_pid_identity??null,window:e.window??null,tmux_session:e.tmux_session??null,pane:e.pane??null,final_report:e.final_report??null,finalized_at:e.finalized_at??null,deadline_at:e.deadline_at??null,telemetry_tokens_in:e.telemetry_tokens_in??null,telemetry_context_tokens:e.telemetry_context_tokens??null,telemetry_last_activity:e.telemetry_last_activity??null,telemetry_updated_at:e.telemetry_updated_at??null,outcome:m(e),fault:e.fault&&e.fault.link!=="broker\u2194crtrd"?{...e.fault,link:e.fault.link}:null,streaming:e.streaming??!1,creator:e.creator??null,edges:U(e,t),paths:await G(e.node_id,n)};return e.description!==void 0&&(i.description=e.description),e.title!==void 0&&(i.title=e.title),e.icon!==void 0&&(i.icon=e.icon),e.cycles!==void 0&&(i.cycles=e.cycles),i.context_tokens=e.telemetry_context_tokens??e.telemetry_tokens_in??null,e.pi_session_id!==void 0&&(i.pi_session_id=e.pi_session_id??null),i.model_override=e.model_override??null,e.pi_session_file!==void 0&&(i.pi_session_file=e.pi_session_file??null),e.review_binding!==void 0&&(i.review_binding=e.review_binding===null?null:{...e.review_binding.kind===void 0?{}:{kind:e.review_binding.kind},review_id:e.review_binding.review_id,origin_node_id:e.review_binding.origin_node_id,branch_file:e.review_binding.branch_file,target_file:e.review_binding.target_file}),e.managed_worktree!=null&&(i.worktree=M(e.managed_worktree)),i}r(ge,"toNodeDetailDTO");function be(e,t,n,i){return{node_id:e,revived:t.launch!==void 0,resumed:t.resumed,status:n,outcome:t.outcome,ready:i}}r(be,"toReviveResultDTO");function ye(e){return{root:e.root,closed:[...e.closed],spared:[...e.spared]}}r(ye,"toCloseResultDTO");function xe(e,t,n){const i={report:e.report,notified:[...e.deliveredTo]};return t!==void 0&&(i.transitioned=t),n!==void 0&&(i.worktree_auto_dropped=!0,i.worktree_auto_dropped_path=n),i}r(xe,"toReportResultDTO");function Oe(e){return{node_id:e.node_id,active:e.active,created:e.created}}r(Oe,"toSubscriptionDTO");function W(e){if(e===null||e==="")return[];try{const t=JSON.parse(e);return typeof t=="object"&&t!==null&&!Array.isArray(t)?Object.keys(t):[]}catch{return[]}}r(W,"envKeys");function De(e,t){return{cron_id:e.cron_id,name:e.name,created_by:e.created_by,command:e.command,grant_id:e.grant_id,scopes:e.scopes,origin_run_id:e.origin_run_id,isolated:e.isolated,fire_at:e.fire_at,recur:e.recur,tz:e.tz,expires_at:e.expires_at,anchor_node:e.anchor_node,cancel_on_wake:e.cancel_on_wake,cwd:e.cwd,profile:e.profile,scope:e.scope,env_keys:W(e.env_json),run_timeout_s:e.run_timeout_s,overlap:e.overlap,on_output:e.on_output,sink:x(e.sink),tier:e.tier,state:e.state,held:e.held,run_state:e.run_state,last_run:t==null?null:{finished:t.finished,exit_code:t.exit_code,delivered:t.delivered},created:e.created,updated:e.updated}}r(De,"toCronDTO");function Te(e){return{run_id:e.run_id,started:e.started,finished:e.finished,duration_ms:e.duration_ms,exit_code:e.exit_code,stdout_head:e.stdout_head,stderr_head:e.stderr_head,delivered:e.delivered}}r(Te,"toCronRunDTO");function Ee(e){return{id:e.profileId,app:e.manifest.grantee??"app:terminal",name:e.manifest.name,projects:e.manifest.projects.map(t=>({...t})),delivery_limits:{...e.manifest.delivery_limits},paused_at:e.manifest.paused_at,default_kind:e.manifest.default_kind??"general",metadata:D(e.manifest.metadata),default_dir:null,created_at:e.manifest.created_at,last_used_at:e.manifest.last_used_at,profile_path:O(e.profileId)}}r(Ee,"toProfileDTO");function v(e,t={}){const n={review_id:e.review_id,origin_kind:e.origin_kind,origin_node_id:e.origin_node_id,review_dir:e.review_dir,companion_node_id:e.companion_node_id,file:e.file,state:e.state,created:e.created,source_missing:e.source_missing,anchor_base_sha256:e.anchor_base_sha256};return e.document_name!==null&&(n.document=e.document_name),e.opened_at!==null&&(n.opened_at=e.opened_at),e.submit_requested_at!==null&&(n.submit_requested_at=e.submit_requested_at),e.approved_at!==null&&(n.approved_at=e.approved_at),e.changed!==null&&(n.changed=e.changed),e.comments_total!==null&&(n.comments_total=e.comments_total),e.comments_unresolved!==null&&(n.comments_unresolved=e.comments_unresolved),e.canceled_at!==null&&(n.canceled_at=e.canceled_at),e.cancel_reason!==null&&(n.cancel_reason=e.cancel_reason),e.cancel_actor!==null&&(n.cancel_actor=e.cancel_actor),t.result_path!==void 0&&(n.result_path=t.result_path),e.delivery_error!==null&&(n.delivery_error=e.delivery_error),e.projection_error!==null&&(n.projection_error=e.projection_error),n}r(v,"toReviewDTO");function Se(e){return{comment_id:e.comment_id,review_id:e.review_id,status:e.status,revision:e.revision,text:e.text,anchor:{...e.anchor},anchor_state:e.anchor_state,anchor_line_text:e.anchor_line_text,anchor_doc_hash:e.anchor_doc_hash,author:{kind:e.author.kind,...e.author.node_id===null?{}:{node_id:e.author.node_id}},updated_by:{kind:e.updated_by.kind,...e.updated_by.node_id===null?{}:{node_id:e.updated_by.node_id}},created_at:e.created_at,updated_at:e.updated_at,...e.resolved_at===null?{}:{resolved_at:e.resolved_at},...e.deleted_at===null?{}:{deleted_at:e.deleted_at},created_seq:e.created_seq}}r(Se,"toReviewCommentDTO");function B(e){return{id:e.id,quote:e.quote,...e.context===void 0?{}:{context:e.context},note:e.note,status:e.status,created_at:e.createdAt,...e.resolvedAt===void 0?{}:{resolved_at:e.resolvedAt}}}r(B,"toPageFeedbackCommentDTO");function Ae(e){return{companion_node_id:e.companionNodeId??null,open_count:e.comments.filter(t=>t.status==="open").length,comments:e.comments.map(B)}}r(Ae,"toPageFeedbackDTO");function Re(e){return{seq:e.seq,review_id:e.review_id,comment_id:e.comment_id,kind:e.kind,state_change:e.state_change===1,revision_after:e.revision_after,actor:{kind:e.actor.kind,...e.actor.node_id===null?{}:{node_id:e.actor.node_id}},at:e.at,operation_id:e.operation_id,...e.payload===void 0?{}:{payload:e.payload}}}r(Re,"toReviewCommentEventDTO");function ze(e){return{file:e.file,submitted:e.submitted,approved:e.approved,comments:e.comments.map(n=>({...n})),submittedAt:e.submittedAt,savedAt:e.savedAt,reviewId:e.review_id,changed:e.changed,baselineSha256:e.baseline_sha256,approvedSha256:e.approved_sha256,companionNodeId:e.companion_node_id,commentsTotal:e.comments_total,commentsUnresolved:e.comments_unresolved}}r(ze,"toFeedbackResultDTO");const L=!0,$=Object.freeze({review_origin_missing:{status:400,code:"review_origin_unavailable"},review_origin_unforkable:{status:400,code:"review_origin_unavailable"},review_branch_unavailable:{status:409,code:"review_branch_unavailable"},branch_lost:{status:409,code:"review_branch_unavailable"},review_companion_unbound:{status:409,code:"review_companion_unbound"},review_bridge_unsubscribed:{status:409,code:"review_bridge_unavailable"},review_target_unreviewable:{status:400,code:"review_file_unreadable"},source_unreadable:{status:409,code:"review_source_unreadable"},delivery_unroutable:{status:409,code:"review_delivery_unroutable"},unknown_review:{status:404,code:"unknown_review"},review_terminal:{status:409,code:"review_terminal_conflict"},review_required:{status:400,code:"review_required"},stale_document:{status:409,code:"stale_document"},stale_revision:{status:409,code:"stale_revision"},unknown_comment:{status:404,code:"unknown_comment"},comment_deleted:{status:409,code:"comment_deleted"},invalid_anchor:{status:400,code:"invalid_anchor"},anchor_out_of_range:{status:400,code:"anchor_out_of_range"},text_too_long:{status:400,code:"text_too_long"},comment_limit_reached:{status:409,code:"comment_limit_reached"},stale_comment:{status:409,code:"stale_comment"},range_batch_incomplete:{status:409,code:"range_batch_incomplete"},range_batch_stale:{status:409,code:"range_batch_stale"}});function K(e){const t=k(e);if(typeof t=="object"&&t!==null&&typeof t.status=="number"&&typeof t.code=="string")return{status:t.status,code:t.code};if(t instanceof z)return t.code==="unknown_node"?{status:404,code:"node_not_found"}:t.code==="already_finalized"?{status:409,code:"already_finalized"}:{status:409,code:"finalization_forbidden"};if(t instanceof N)return{status:409,code:"node_id_exists"};if(t instanceof C)return{status:403,code:"scope_denied"};if(j(t))return{status:400,code:"invalid_request"};if(t instanceof _)return $[t.code];if(t instanceof a)return["kind_owned","name_taken","hop_limit","not_a_queue"].includes(t.code)?{status:409,code:t.code}:t.code==="invalid_publish_token"?{status:401,code:t.code}:t.code==="forbidden"||t.code==="argv_forbidden"||t.code==="scope_missing"?{status:403,code:t.code}:{status:J(t.exitCode),code:t.code};if(t instanceof Error){const n=t.message;if(/unknown node/i.test(n))return{status:404,code:"node_not_found"};if(/finalization latch/i.test(n))return{status:409,code:"already_finalized"};if(/illegal lifecycle transition/i.test(n))return{status:409,code:"illegal_transition"}}return{status:500,code:"internal"}}r(K,"errorToStatus");function k(e){if(!(e instanceof q))return e;const t=e.code==="unknown_node"?o.NOT_FOUND:o.GENERAL,n={error:e.code,message:e.message,next:e.next};return e.detail!==void 0&&(n.received=e.detail),new a(e.code,e.message,t,n)}r(k,"normalizeThrow");function V(e){if(e.code!=="review_terminal")return e.detail;const{review:t,...n}=e.detail;return{...n,review:H(t)}}r(V,"reviewErrorDetails");function H(e){return e.state!=="approved"?v(e):v(e,{result_path:b(e.review_dir,"result.json")})}r(H,"terminalConflictReviewDTO");function J(e){switch(e){case o.NOT_FOUND:return 404;case o.USAGE:return 400;case o.AMBIGUOUS:return 400;case o.NETWORK:return 503;case o.GENERAL:return 400;default:return 500}}r(J,"statusForExitCode");function Q(e){const n=(e instanceof Error?e.message:String(e)).split(`
|
|
2
2
|
`,1)[0].trim();return n===""?"internal error":n.length>500?`${n.slice(0,497)}\u2026`:n}r(Q,"boundedCause");function Ne(e){const t=k(e),{status:n,code:i}=K(t);if(n>=500){const u={error:{code:i,message:Q(t),origin:"runtime"}};return t instanceof s&&(u.error.retryable=t.retryable),{status:n,body:u}}const h=t instanceof Error?t.message:String(t),l=t instanceof _?V(t):(t instanceof a||t instanceof I||t instanceof s)&&t.details!==void 0?t.details:void 0,d={error:{code:i,message:h,origin:"runtime"}};return l!==void 0&&(d.error.details=l),t instanceof s&&(t.param&&(d.error.param=t.param),t.scope&&(d.error.scope=t.scope),d.error.retryable=t.retryable),{status:n,body:d}}r(Ne,"toErrorBody");export{$ as REVIEW_ERROR_MAP,K as errorToStatus,ye as toCloseResultDTO,De as toCronDTO,Te as toCronRunDTO,Ne as toErrorBody,ze as toFeedbackResultDTO,ke as toGraphNodeDTO,pe as toMigrateStateDTO,ge as toNodeDetailDTO,U as toNodeEdgesDTO,m as toNodeOutcomeDTO,P as toNodeOutcomeSummaryDTO,G as toNodePathsDTO,he as toNodeSummaryDTO,M as toNodeWorktreeDTO,ve as toOutcomeDeliveryDTO,B as toPageFeedbackCommentDTO,Ae as toPageFeedbackDTO,Ee as toProfileDTO,xe as toReportResultDTO,Se as toReviewCommentDTO,Re as toReviewCommentEventDTO,v as toReviewDTO,be as toReviveResultDTO,me as toRunOutcomeDTO,Oe as toSubscriptionDTO};
|
|
@@ -62,4 +62,4 @@ export declare class AppPrincipalResolver {
|
|
|
62
62
|
* caller's: active, the same `sub` and `grantee`, and not past `expires_at`.
|
|
63
63
|
* Otherwise 401 `grant_revoked`. `resolve()` and every later re-read during a
|
|
64
64
|
* request (a `grant.get` long-poll waking) apply this one check. */
|
|
65
|
-
export declare function callerGrant(caller: Pick<AppPrincipal, 'grant' | 'sub' | 'grantee'>): ActiveGrant
|
|
65
|
+
export declare function callerGrant(caller: Pick<AppPrincipal, 'grant' | 'sub' | 'grantee'>): Promise<ActiveGrant>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var g=Object.defineProperty;var d=(c,e)=>g(c,"name",{value:e,configurable:!0});import{covers as v,JwksCache as m,MissingRevClaimError as p,verifyCallToken as _}from"@north-light/identity";import{createLocalJWKSet as l,decodeProtectedHeader as h,jwtVerify as f}from"jose";import{callerGrantOf as b,coverGrant as k}from"../../core/grants/cover.js";import{RunError as n}from"../../core/runs/operations.js";import{NoticeLedger as E}from"./sync-notice.js";class W{static{d(this,"AppPrincipalResolver")}issuer;audience;syncGrants;cache;ready=!1;timer;constructor(e,t,r,i){this.issuer=e,this.audience=t,this.syncGrants=r,this.cache=new m(e,fetch,i),this.load(),this.timer=setInterval(()=>{this.ready||this.load()},5e3),this.timer.unref()}async load(){try{await this.cache.load(),this.ready=!0}catch{}}isReady(){return this.ready}get jwks(){return this.cache}close(){this.timer&&clearInterval(this.timer)}ledger=new E;async verifySyncNotice(e){if(!this.ready)throw new n(503,"runtime_starting","runtime_starting");return this.ledger.accept(e,this.cache,this.issuer,this.audience)}async verifyHandoff(e){if(!this.ready)throw new n(503,"runtime_starting","runtime_starting");const t=d(()=>new n(401,"unauthorized","invalid vendor sign-in handoff"),"refuse");if(!e)throw t();let r;try{const u=h(e);if(u.alg!=="ES256")throw t();const y=await this.cache.forKid(u.kid);({payload:r}=await f(e,l(y),{issuer:this.issuer,audience:this.audience,algorithms:["ES256"],requiredClaims:["exp","jti","sub"]}))}catch{throw t()}const{sub:i,jti:s,exp:a,purpose:o,aud:w}=r;if(o!=="vendor_sign_in"||w!==this.audience||typeof i!="string"||typeof s!="string"||s===""||typeof a!="number")throw t();return{sub:i,jti:s,exp:a}}async verifyDirectoryRead(e,t){if(!this.ready)throw new n(503,"runtime_starting","runtime_starting");const r=d(()=>new n(401,"unauthorized","invalid directory token"),"refuse");if(!e?.startsWith("Bearer ")||e.length<=7)throw r();const i=e.slice(7);let s;try{const a=h(i);if(a.alg!=="ES256")throw r();const o=await this.cache.forKid(a.kid);({payload:s}=await f(i,l(o),{issuer:this.issuer,audience:this.audience,algorithms:["ES256"],requiredClaims:["exp"]}))}catch{throw r()}if(s.purpose!==t||s.aud!==this.audience)throw r()}async verifyCall(e){if(!this.ready)throw new n(503,"runtime_starting","runtime_starting");if(!e?.startsWith("Bearer ")||e.length<=7)throw new n(401,"unauthorized","a directory access token is required");const t=e.slice(7);try{if(h(t).alg!=="ES256")throw new Error("Invalid call token header");return await _({token:t,jwks:this.cache,issuer:this.issuer,audience:this.audience})}catch(r){throw r instanceof p?new n(401,"unauthorized",r.message):new n(401,"unauthorized","invalid directory access token")}}async resolve(e,t){return this.resolveVerified(await this.verifyCall(e),t)}async resolveVerified(e,t){const r=e.chain[0],i=e.claims;if(e.chain.length!==1||!r||!r.sub.startsWith("app:")||r.grant===void 0||r.rev===void 0||!/^[A-Za-z0-9_-]{1,64}$/.test(i.client_id)||i.grantee!==void 0&&i.grantee!==r.sub||i.rev!==void 0&&i.rev!==r.rev)throw new n(401,"unauthorized","invalid directory access token");const s=await k(r.grant,r.rev,e.sub,r.sub,this.syncGrants);if(t&&!s.resolved.some(a=>v(a,t)))throw new n(403,"scope_missing",`missing scope ${t}`,void 0,void 0,t);return{sub:e.sub,grantee:r.sub,client_id:i.client_id,grant:r.grant,rev:s.rev,resolved:s.resolved,resolved_scopes:s.resolved_scopes,spend_cap:s.spend_cap,dependencies:s.dependencies??{},exp:i.exp}}}function q(c){return b(c.grant,c.sub,c.grantee)}d(q,"callerGrant");export{W as AppPrincipalResolver,q as callerGrant};
|
|
1
|
+
var g=Object.defineProperty;var d=(c,e)=>g(c,"name",{value:e,configurable:!0});import{covers as v,JwksCache as m,MissingRevClaimError as p,verifyCallToken as _}from"@north-light/identity";import{createLocalJWKSet as l,decodeProtectedHeader as h,jwtVerify as f}from"jose";import{callerGrantOf as b,coverGrant as k}from"../../core/grants/cover.js";import{RunError as n}from"../../core/runs/operations.js";import{NoticeLedger as E}from"./sync-notice.js";class W{static{d(this,"AppPrincipalResolver")}issuer;audience;syncGrants;cache;ready=!1;timer;constructor(e,t,r,i){this.issuer=e,this.audience=t,this.syncGrants=r,this.cache=new m(e,fetch,i),this.load(),this.timer=setInterval(()=>{this.ready||this.load()},5e3),this.timer.unref()}async load(){try{await this.cache.load(),this.ready=!0}catch{}}isReady(){return this.ready}get jwks(){return this.cache}close(){this.timer&&clearInterval(this.timer)}ledger=new E;async verifySyncNotice(e){if(!this.ready)throw new n(503,"runtime_starting","runtime_starting");return this.ledger.accept(e,this.cache,this.issuer,this.audience)}async verifyHandoff(e){if(!this.ready)throw new n(503,"runtime_starting","runtime_starting");const t=d(()=>new n(401,"unauthorized","invalid vendor sign-in handoff"),"refuse");if(!e)throw t();let r;try{const u=h(e);if(u.alg!=="ES256")throw t();const y=await this.cache.forKid(u.kid);({payload:r}=await f(e,l(y),{issuer:this.issuer,audience:this.audience,algorithms:["ES256"],requiredClaims:["exp","jti","sub"]}))}catch{throw t()}const{sub:i,jti:s,exp:a,purpose:o,aud:w}=r;if(o!=="vendor_sign_in"||w!==this.audience||typeof i!="string"||typeof s!="string"||s===""||typeof a!="number")throw t();return{sub:i,jti:s,exp:a}}async verifyDirectoryRead(e,t){if(!this.ready)throw new n(503,"runtime_starting","runtime_starting");const r=d(()=>new n(401,"unauthorized","invalid directory token"),"refuse");if(!e?.startsWith("Bearer ")||e.length<=7)throw r();const i=e.slice(7);let s;try{const a=h(i);if(a.alg!=="ES256")throw r();const o=await this.cache.forKid(a.kid);({payload:s}=await f(i,l(o),{issuer:this.issuer,audience:this.audience,algorithms:["ES256"],requiredClaims:["exp"]}))}catch{throw r()}if(s.purpose!==t||s.aud!==this.audience)throw r()}async verifyCall(e){if(!this.ready)throw new n(503,"runtime_starting","runtime_starting");if(!e?.startsWith("Bearer ")||e.length<=7)throw new n(401,"unauthorized","a directory access token is required");const t=e.slice(7);try{if(h(t).alg!=="ES256")throw new Error("Invalid call token header");return await _({token:t,jwks:this.cache,issuer:this.issuer,audience:this.audience})}catch(r){throw r instanceof p?new n(401,"unauthorized",r.message):new n(401,"unauthorized","invalid directory access token")}}async resolve(e,t){return this.resolveVerified(await this.verifyCall(e),t)}async resolveVerified(e,t){const r=e.chain[0],i=e.claims;if(e.chain.length!==1||!r||!r.sub.startsWith("app:")||r.grant===void 0||r.rev===void 0||!/^[A-Za-z0-9_-]{1,64}$/.test(i.client_id)||i.grantee!==void 0&&i.grantee!==r.sub||i.rev!==void 0&&i.rev!==r.rev)throw new n(401,"unauthorized","invalid directory access token");const s=await k(r.grant,r.rev,e.sub,r.sub,this.syncGrants);if(t&&!s.resolved.some(a=>v(a,t)))throw new n(403,"scope_missing",`missing scope ${t}`,void 0,void 0,t);return{sub:e.sub,grantee:r.sub,client_id:i.client_id,grant:r.grant,rev:s.rev,resolved:s.resolved,resolved_scopes:s.resolved_scopes,spend_cap:s.spend_cap,dependencies:s.dependencies??{},exp:i.exp}}}async function q(c){return await b(c.grant,c.sub,c.grantee)}d(q,"callerGrant");export{W as AppPrincipalResolver,q as callerGrant};
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import type { DatabaseSync } from 'node:sqlite';
|
|
2
1
|
import type { DocOwnerFlag } from '../../api/dto/docs.js';
|
|
3
2
|
import type { ObjectRow, Reader } from '../../core/graph/types.js';
|
|
4
3
|
import type { RequestContext } from './router.js';
|
|
4
|
+
import type { CanvasDb } from '../../core/canvas/db.js';
|
|
5
5
|
/** The graph reader for a request's principal; repos come from the node's cwd. */
|
|
6
|
-
export declare function readerFor(db:
|
|
6
|
+
export declare function readerFor(db: CanvasDb, ctx: Pick<RequestContext, 'principal'>): Promise<Reader>;
|
|
7
7
|
/** A ref (`[[ ]]`-wrapped or not, raw id, name, `<owner>/<name>`, or an old
|
|
8
8
|
* `<node-id>:reports/<basename>[.md]`) → the object, or a deleted/remote answer.
|
|
9
9
|
* Anything unreadable is `not_found`. */
|
|
10
|
-
export declare function resolveRef(db:
|
|
10
|
+
export declare function resolveRef(db: CanvasDb, reader: Reader, raw: string): Promise<ObjectRow | {
|
|
11
11
|
deleted: ObjectRow;
|
|
12
12
|
} | {
|
|
13
13
|
remote: string;
|
|
14
|
-
}
|
|
14
|
+
}>;
|
|
15
15
|
/** The owner object a `--owner` value names. `cwd` is the caller's directory,
|
|
16
16
|
* used for `repo` when the reader is a person (who has no cwd of its own). */
|
|
17
|
-
export declare function ownerFromFlag(db:
|
|
17
|
+
export declare function ownerFromFlag(db: CanvasDb, reader: Reader, value: DocOwnerFlag | undefined, cwd?: string): Promise<ObjectRow>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var g=Object.defineProperty;var c=(n,e)=>g(n,"name",{value:e,configurable:!0});import{ApiError as d}from"../../api/index.js";import{readerFor as E}from"../../core/graph/reader.js";import{canRead as R}from"../../core/graph/access.js";import{ownersByHandle as y,resolveName as v,viewOf as x}from"../../core/graph/names.js";import{ensureOwner as h}from"../../core/graph/objects.js";import{checkoutsForCwd as F,reposForCwd as N}from"../../core/graph/repo-sync/repos.js";import{lookupProfile as j}from"../../core/profiles/manifest.js";import{filterAsync as L,mapAsync as _}from"../../core/async-array.js";async function T(n,e){return await E(n,e.principal,async o=>await F(n,o))}c(T,"readerFor");async function U(n,e,o){const r=await v(n,e,o);if("object"in r)return r.object;if("deleted"in r||"remote"in r)return r;if("ambiguous"in r){const s=await _(r.ambiguous,async w=>`${await A(n,w)}/${w.name}`);throw new d(409,"ambiguous_name",`'${o}' names more than one object: ${s.join(", ")}`,{candidates:s,next:"Read one of them by its full `<type>:<owner>/<name>`."})}const t=o.replace(/^\s*\[\[(.*)\]\]\s*$/,"$1").trim(),i=/^(person|app|repo|profile):([^/]+)$/.exec(t),a=await L(i?await y(n,i[2],i[1]):(await y(n,t)).filter(s=>s.type!=="node"),async s=>await R(n,e,s));if(a.length>0){const s=await x(n,e),w=c(m=>{const f=s.findIndex($=>$.rowid===m.rowid);return f<0?1/0:f},"rank"),l=[...a].sort((m,f)=>w(m)-w(f))[0];if(w(l)===1/0&&a.length>1){const m=a.map(f=>`${f.type}:${f.name}`);throw new d(409,"ambiguous_name",`'${o}' names more than one owner: ${m.join(", ")}`,{candidates:m,next:"Name one as `<type>:<handle>`."})}return l.deleted_at?{deleted:l}:l}const p=`'${o}' not found: no object by that name in your view`,u=`Search for it with \`crtr canvas search ${t}\`.`;throw new d(404,"not_found",p,{error:"not_found",message:p,next:u})}c(U,"resolveRef");async function A(n,e){if(e.owner===null)return"";const o=await n.prepare("SELECT type, id, name FROM objects WHERE rowid = ?").get(e.owner);return o.type==="node"?o.id:`${o.type}:${o.name}`}c(A,"typedOwnerHandle");async function B(n,e,o,r){const t=o??(e.class==="node"?"node":e.class==="person"?"user":"app"),i=c(a=>new d(400,"invalid_owner",a,{next:"Run `crtr doc write --owner -h`."}),"refuse");if(t==="node"){if(e.class!=="node")throw i("`--owner node` needs a node; you are not running as one");return e.node}if(t==="user")return await h(n,"person","local-user","user:local","user");if(t==="app"){if(e.class==="person")throw i("`--owner app` needs an app; a person has none \u2014 use `--owner user`");return e.app}if(t==="profile"){if(e.class!=="node"||!e.profile)throw i("`--owner profile` needs a profile; you have none");return e.profile}if(t==="repo"){const a=r?await N(n,r):[],p=a[0]?a:e.class==="node"?e.repos:[];if(!p[0])throw i(`\`--owner repo\` needs a repo; ${r??(e.class==="node"?e.cwd:"your directory")} is not inside one`);return p[0]}if(t.startsWith("repo:"))return await I(n,"repo",t.slice(5),i);if(t.startsWith("profile:")){const a=t.slice(8),p=await n.prepare("SELECT * FROM objects WHERE type = 'profile' AND name = ? AND home_machine IS NULL").get(a);if(p)return p;const u=j(a);if(u.kind!=="resolved")throw i(`no profile named '${a}'`);const s=e.class==="person"?e.person:e.app;return await h(n,"profile","profile",u.entry.profileId,u.entry.manifest.name,s)}throw i(`unknown --owner value '${t}'`)}c(B,"ownerFromFlag");async function I(n,e,o,r){const t=await n.prepare("SELECT * FROM objects WHERE type = ? AND name = ? AND deleted_at IS NULL AND home_machine IS NULL").get(e,o);if(!t)throw r(`no ${e} named '${o}'`);return t}c(I,"namedOwner");export{B as ownerFromFlag,T as readerFor,U as resolveRef};
|
|
@@ -75,15 +75,15 @@ export type CronPrincipalClass = {
|
|
|
75
75
|
export declare function appOf(principal: RequestPrincipal): string | null;
|
|
76
76
|
/** Whether the caller is the person (a local person, or a forwarded call the envelope makes for the person). */
|
|
77
77
|
export declare function actsAsPerson(principal: RequestPrincipal): boolean;
|
|
78
|
-
export declare function resolvedScopes(principal: RequestPrincipal): readonly string[]
|
|
78
|
+
export declare function resolvedScopes(principal: RequestPrincipal): Promise<readonly string[]>;
|
|
79
79
|
export declare function runCallerApp(principal: RequestPrincipal | AppPrincipal): string | null;
|
|
80
80
|
/** Run confinement (Silas, 2026-09-30): a broker caller reaches a same-app node or
|
|
81
81
|
* run only when it is in the caller's run, or neither run is isolated. `target`
|
|
82
82
|
* omitted means no particular node (an app-wide question), which passes. */
|
|
83
|
-
export declare function brokerMayReach(principal: RequestPrincipal | AppPrincipal, target: string | undefined, grantee: string): boolean
|
|
84
|
-
export declare function canReadRun(principal: RequestPrincipal | AppPrincipal, grantee: string, target?: string): boolean
|
|
85
|
-
export declare function requireRun(principal: RequestPrincipal | AppPrincipal, id: string, acting?: boolean, allowDeleting?: boolean): import("../../index.js").NodeMeta
|
|
86
|
-
export declare function canReadNode(principal: RequestPrincipal, grantee: string, target?: string): boolean
|
|
83
|
+
export declare function brokerMayReach(principal: RequestPrincipal | AppPrincipal, target: string | undefined, grantee: string): Promise<boolean>;
|
|
84
|
+
export declare function canReadRun(principal: RequestPrincipal | AppPrincipal, grantee: string, target?: string): Promise<boolean>;
|
|
85
|
+
export declare function requireRun(principal: RequestPrincipal | AppPrincipal, id: string, acting?: boolean, allowDeleting?: boolean): Promise<import("../../index.js").NodeMeta>;
|
|
86
|
+
export declare function canReadNode(principal: RequestPrincipal, grantee: string, target?: string): Promise<boolean>;
|
|
87
87
|
/** Throw the 403 `scope_denied` a scoped bearer earns when its ceiling lacks
|
|
88
88
|
* `scope`. The owner (`null`) always passes. */
|
|
89
89
|
export declare function assertCeiling(ceiling: Ceiling, scope: string): void;
|