prismalens 0.5.3 → 0.5.4
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/README.md +7 -5
- package/THIRD_PARTY_NOTICES.txt +381 -3
- package/dist/{chunk-2BLEMVIB.js → chunk-7JTFOLGT.js} +9 -4
- package/dist/{chunk-32MOXOOZ.js → chunk-IEPD6EMA.js} +15 -7
- package/dist/{chunk-2SF6M3PV.js → chunk-IJ2EB73U.js} +10 -0
- package/dist/{chunk-B34NMVBM.js → chunk-JK7AMZSE.js} +34 -1
- package/dist/{chunk-7JF4AL64.js → chunk-NXTEM2HN.js} +3 -2
- package/dist/src/cli/doctor.js +53 -184
- package/dist/src/cli/pair.js +8 -3
- package/dist/src/cli/service-unit.js +1 -1
- package/dist/src/cli/service.js +4 -4
- package/dist/src/cli/tailscale.js +3 -1
- package/dist/src/cli/up-console.js +7 -3
- package/dist/src/cli/up.js +23 -4
- package/dist/src/cli/upgrade-trial.js +1 -1
- package/dist/src/cli/upgrade.js +4 -4
- package/node_modules/@prismalens/agent-adapters/THIRD_PARTY_LICENSES/@agentclientprotocol/sdk/2.1.0/LICENSE +191 -0
- package/node_modules/@prismalens/agent-adapters/THIRD_PARTY_LICENSES/@anthropic-ai/claude-agent-sdk/README.md +2 -2
- package/node_modules/@prismalens/agent-adapters/dist/adapters/bundled.json +6 -6
- package/node_modules/@prismalens/agent-adapters/dist/adapters/claude-agent-acp.mjs +3840 -1504
- package/node_modules/@prismalens/agent-adapters/dist/adapters/codex-acp.mjs +3247 -1158
- package/node_modules/@prismalens/agent-adapters/node_modules/@anthropic-ai/claude-agent-sdk/README.md +2 -2
- package/node_modules/@prismalens/agent-adapters/node_modules/@anthropic-ai/claude-agent-sdk/bridge.mjs +81 -86
- package/node_modules/@prismalens/agent-adapters/node_modules/@anthropic-ai/claude-agent-sdk/browser-sdk.js +76 -83
- package/node_modules/@prismalens/agent-adapters/node_modules/@anthropic-ai/claude-agent-sdk/core-07pvccxf.mjs +43 -0
- package/node_modules/@prismalens/agent-adapters/node_modules/@anthropic-ai/claude-agent-sdk/core-0rjxgk9e.mjs +18 -0
- package/node_modules/@prismalens/agent-adapters/node_modules/@anthropic-ai/claude-agent-sdk/core-fpeb751h.mjs +33 -0
- package/node_modules/@prismalens/agent-adapters/node_modules/@anthropic-ai/claude-agent-sdk/core-jf0rbr11.mjs +17 -0
- package/node_modules/@prismalens/agent-adapters/node_modules/@anthropic-ai/claude-agent-sdk/core.d.ts +1 -0
- package/node_modules/@prismalens/agent-adapters/node_modules/@anthropic-ai/claude-agent-sdk/core.mjs +12 -21
- package/node_modules/@prismalens/agent-adapters/node_modules/@anthropic-ai/claude-agent-sdk/manifest.json +19 -24
- package/node_modules/@prismalens/agent-adapters/node_modules/@anthropic-ai/claude-agent-sdk/manifest.zst.json +23 -28
- package/node_modules/@prismalens/agent-adapters/node_modules/@anthropic-ai/claude-agent-sdk/package.json +7 -7
- package/node_modules/@prismalens/agent-adapters/node_modules/@anthropic-ai/claude-agent-sdk/sdk-tools.d.ts +11 -0
- package/node_modules/@prismalens/agent-adapters/node_modules/@anthropic-ai/claude-agent-sdk/sdk.d.ts +139 -36
- package/node_modules/@prismalens/agent-adapters/node_modules/@anthropic-ai/claude-agent-sdk/sdk.mjs +68 -73
- package/node_modules/@prismalens/agent-adapters/package.json +1 -1
- package/node_modules/@prismalens/agent-host/dist/launch.js +81 -12
- package/node_modules/@prismalens/agent-host/dist/probe.js +76 -24
- package/node_modules/@prismalens/agent-host/dist/registry/agents.js +17 -1
- package/node_modules/@prismalens/agent-host/dist/workspace/git.js +20 -5
- package/node_modules/@prismalens/agent-host/dist/workspace/index.js +26 -4
- package/node_modules/@prismalens/api/dist/src/app.module.js +14 -0
- package/node_modules/@prismalens/api/dist/src/core/auth/auth.guard.js +7 -3
- package/node_modules/@prismalens/api/dist/src/core/auth/instance-identity.js +12 -0
- package/node_modules/@prismalens/api/dist/src/core/auth/operator.controller.js +1 -1
- package/node_modules/@prismalens/api/dist/src/core/auth/owner.js +18 -0
- package/node_modules/@prismalens/api/dist/src/core/auth/pairing.controller.js +11 -7
- package/node_modules/@prismalens/api/dist/src/core/harness/git-credential.js +18 -0
- package/node_modules/@prismalens/api/dist/src/core/harness/git-env.js +3 -20
- package/node_modules/@prismalens/api/dist/src/core/harness/git-spawn.js +22 -4
- package/node_modules/@prismalens/api/dist/src/core/harness/harness.service.js +81 -1
- package/node_modules/@prismalens/api/dist/src/core/harness/ready-harness.js +26 -0
- package/node_modules/@prismalens/api/dist/src/core/harness/repo-source.service.js +46 -9
- package/node_modules/@prismalens/api/dist/src/core/harness/run-worktree.js +22 -5
- package/node_modules/@prismalens/api/dist/src/core/lifecycle/admission.service.js +35 -0
- package/node_modules/@prismalens/api/dist/src/core/lifecycle/restart-exit.js +8 -0
- package/node_modules/@prismalens/api/dist/src/core/lifecycle/runtime-lifecycle.module.js +28 -0
- package/node_modules/@prismalens/api/dist/src/core/lifecycle/runtime-lifecycle.service.js +186 -0
- package/node_modules/@prismalens/api/dist/src/core/lifecycle/workspace-lock-shutdown.service.js +4 -0
- package/node_modules/@prismalens/api/dist/src/core/live/live-changes.js +25 -12
- package/node_modules/@prismalens/api/dist/src/core/prisma/prisma.service.js +54 -0
- package/node_modules/@prismalens/api/dist/src/core/settings/about.service.js +17 -3
- package/node_modules/@prismalens/api/dist/src/core/settings/diagnostics.service.js +61 -0
- package/node_modules/@prismalens/api/dist/src/core/settings/settings.controller.js +52 -15
- package/node_modules/@prismalens/api/dist/src/core/settings/settings.module.js +3 -1
- package/node_modules/@prismalens/api/dist/src/core/settings/settings.service.js +0 -4
- package/node_modules/@prismalens/api/dist/src/core/settings/update-handoff.js +201 -0
- package/node_modules/@prismalens/api/dist/src/core/settings/update.service.js +373 -0
- package/node_modules/@prismalens/api/dist/src/core/telemetry/telemetry.service.js +16 -7
- package/node_modules/@prismalens/api/dist/src/infrastructure/dispatch/checkout-lease.js +203 -0
- package/node_modules/@prismalens/api/dist/src/infrastructure/dispatch/checkout-status.js +125 -0
- package/node_modules/@prismalens/api/dist/src/infrastructure/dispatch/dispatch.service.js +962 -81
- package/node_modules/@prismalens/api/dist/src/infrastructure/dispatch/dispatcher.js +66 -22
- package/node_modules/@prismalens/api/dist/src/infrastructure/dispatch/event-bus.js +6 -0
- package/node_modules/@prismalens/api/dist/src/infrastructure/dispatch/folder-lock.js +140 -0
- package/node_modules/@prismalens/api/dist/src/infrastructure/dispatch/harness-receipt.js +312 -0
- package/node_modules/@prismalens/api/dist/src/infrastructure/dispatch/in-process-runner.js +27 -5
- package/node_modules/@prismalens/api/dist/src/infrastructure/dispatch/investigation-run.js +683 -60
- package/node_modules/@prismalens/api/dist/src/infrastructure/dispatch/job-store.js +72 -9
- package/node_modules/@prismalens/api/dist/src/infrastructure/dispatch/pre-run-context.js +7 -1
- package/node_modules/@prismalens/api/dist/src/infrastructure/dispatch/restart-recovery.js +112 -0
- package/node_modules/@prismalens/api/dist/src/infrastructure/dispatch/run-abort.js +2 -0
- package/node_modules/@prismalens/api/dist/src/main.js +16 -3
- package/node_modules/@prismalens/api/dist/src/middlewares/cross-site.middleware.js +79 -0
- package/node_modules/@prismalens/api/dist/src/middlewares/host-allowlist.middleware.js +18 -3
- package/node_modules/@prismalens/api/dist/src/modules/alerts/alert-pull.service.js +20 -8
- package/node_modules/@prismalens/api/dist/src/modules/alerts/alerts.service.js +12 -3
- package/node_modules/@prismalens/api/dist/src/modules/asks/asks.contract.js +6 -0
- package/node_modules/@prismalens/api/dist/src/modules/asks/asks.service.js +303 -0
- package/node_modules/@prismalens/api/dist/src/modules/composer/composer.controller.js +64 -0
- package/node_modules/@prismalens/api/dist/src/modules/composer/composer.module.js +54 -0
- package/node_modules/@prismalens/api/dist/src/modules/composer/drafts.service.js +169 -0
- package/node_modules/@prismalens/api/dist/src/modules/delivery/report-delivery.controller.js +5 -1
- package/node_modules/@prismalens/api/dist/src/modules/events/events.service.js +27 -1
- package/node_modules/@prismalens/api/dist/src/modules/fixes/fixes.service.js +12 -4
- package/node_modules/@prismalens/api/dist/src/modules/gateway/gateway.service.js +1034 -80
- package/node_modules/@prismalens/api/dist/src/modules/gateway/runbooks.js +2 -0
- package/node_modules/@prismalens/api/dist/src/modules/gateway/tools/artifacts.js +30 -0
- package/node_modules/@prismalens/api/dist/src/modules/gateway/tools/asks.js +94 -0
- package/node_modules/@prismalens/api/dist/src/modules/gateway/tools/attachments.js +128 -0
- package/node_modules/@prismalens/api/dist/src/modules/gateway/tools/history.js +42 -0
- package/node_modules/@prismalens/api/dist/src/modules/gateway/tools/incident.js +74 -0
- package/node_modules/@prismalens/api/dist/src/modules/gateway/tools/index.js +32 -4
- package/node_modules/@prismalens/api/dist/src/modules/gateway/tools/knowledge.js +18 -10
- package/node_modules/@prismalens/api/dist/src/modules/gateway/tools/propose.js +36 -0
- package/node_modules/@prismalens/api/dist/src/modules/gateway/tools/record.js +80 -0
- package/node_modules/@prismalens/api/dist/src/modules/gateway/tools/report.js +41 -0
- package/node_modules/@prismalens/api/dist/src/modules/gateway/tools/rules.js +3 -0
- package/node_modules/@prismalens/api/dist/src/modules/gateway/tools/run.js +24 -0
- package/node_modules/@prismalens/api/dist/src/modules/gateway/tools/runbooks.js +18 -12
- package/node_modules/@prismalens/api/dist/src/modules/gateway/tools/serves.js +11 -0
- package/node_modules/@prismalens/api/dist/src/modules/gateway/tools/services.js +24 -0
- package/node_modules/@prismalens/api/dist/src/modules/gateway/tools/thread-tree.js +99 -0
- package/node_modules/@prismalens/api/dist/src/modules/gateway/tools/threads.js +85 -0
- package/node_modules/@prismalens/api/dist/src/modules/gateway/tools/watches.js +75 -0
- package/node_modules/@prismalens/api/dist/src/modules/images/image-fetch.js +100 -0
- package/node_modules/@prismalens/api/dist/src/modules/images/images.controller.js +50 -0
- package/node_modules/@prismalens/api/dist/src/modules/images/images.module.js +22 -0
- package/node_modules/@prismalens/api/dist/src/modules/images/images.service.js +211 -0
- package/node_modules/@prismalens/api/dist/src/modules/incidents/incidents.controller.js +75 -34
- package/node_modules/@prismalens/api/dist/src/modules/incidents/incidents.module.js +2 -0
- package/node_modules/@prismalens/api/dist/src/modules/incidents/incidents.service.js +89 -46
- package/node_modules/@prismalens/api/dist/src/modules/integrations/host-repositories.service.js +76 -0
- package/node_modules/@prismalens/api/dist/src/modules/integrations/integrations.controller.js +67 -7
- package/node_modules/@prismalens/api/dist/src/modules/integrations/integrations.module.js +4 -1
- package/node_modules/@prismalens/api/dist/src/modules/integrations/telemetry-snapshot.service.js +11 -1
- package/node_modules/@prismalens/api/dist/src/modules/investigations/attachments.service.js +157 -49
- package/node_modules/@prismalens/api/dist/src/modules/investigations/context-pack.service.js +39 -7
- package/node_modules/@prismalens/api/dist/src/modules/investigations/dto/investigation-result.dto.js +3 -3
- package/node_modules/@prismalens/api/dist/src/modules/investigations/investigation-trigger.service.js +4 -1
- package/node_modules/@prismalens/api/dist/src/modules/investigations/investigations.controller.js +301 -21
- package/node_modules/@prismalens/api/dist/src/modules/investigations/investigations.module.js +17 -0
- package/node_modules/@prismalens/api/dist/src/modules/investigations/investigations.service.js +165 -30
- package/node_modules/@prismalens/api/dist/src/modules/investigations/promotion.js +5 -0
- package/node_modules/@prismalens/api/dist/src/modules/investigations/run-scope.js +31 -0
- package/node_modules/@prismalens/api/dist/src/modules/investigations/run-views.js +333 -0
- package/node_modules/@prismalens/api/dist/src/modules/investigations/subagent-sessions.js +28 -0
- package/node_modules/@prismalens/api/dist/src/modules/investigations/tool-asks.service.js +193 -0
- package/node_modules/@prismalens/api/dist/src/modules/investigations/worktree-changes.js +324 -0
- package/node_modules/@prismalens/api/dist/src/modules/openapi/build-spec.js +42 -0
- package/node_modules/@prismalens/api/dist/src/modules/openapi/openapi.controller.js +8 -87
- package/node_modules/@prismalens/api/dist/src/modules/overlay/overlay.service.js +36 -24
- package/node_modules/@prismalens/api/dist/src/modules/push/ask-state.js +6 -3
- package/node_modules/@prismalens/api/dist/src/modules/push/push-outbox.js +4 -1
- package/node_modules/@prismalens/api/dist/src/modules/push/push.service.js +13 -3
- package/node_modules/@prismalens/api/dist/src/modules/references/file-list.js +135 -0
- package/node_modules/@prismalens/api/dist/src/modules/references/monitoring.provider.js +200 -0
- package/node_modules/@prismalens/api/dist/src/modules/references/ranking.js +42 -0
- package/node_modules/@prismalens/api/dist/src/modules/references/records.provider.js +463 -0
- package/node_modules/@prismalens/api/dist/src/modules/references/reference-provider.js +9 -0
- package/node_modules/@prismalens/api/dist/src/modules/references/references.service.js +341 -0
- package/node_modules/@prismalens/api/dist/src/modules/references/work-items.provider.js +83 -0
- package/node_modules/@prismalens/api/dist/src/modules/repositories/folder-browser.js +150 -0
- package/node_modules/@prismalens/api/dist/src/modules/repositories/project-scripts.js +100 -0
- package/node_modules/@prismalens/api/dist/src/modules/repositories/repo-icon-scan.js +180 -0
- package/node_modules/@prismalens/api/dist/src/modules/repositories/repositories.controller.js +51 -4
- package/node_modules/@prismalens/api/dist/src/modules/repositories/repositories.module.js +5 -3
- package/node_modules/@prismalens/api/dist/src/modules/repositories/repositories.service.js +91 -15
- package/node_modules/@prismalens/api/dist/src/modules/repositories/repository-icon.service.js +271 -0
- package/node_modules/@prismalens/api/dist/src/modules/repositories/serialize-repository.js +5 -3
- package/node_modules/@prismalens/api/dist/src/modules/repositories/start-git.js +204 -0
- package/node_modules/@prismalens/api/dist/src/modules/run-workspaces/editors.js +122 -0
- package/node_modules/@prismalens/api/dist/src/modules/run-workspaces/run-workspaces.controller.js +15 -16
- package/node_modules/@prismalens/api/dist/src/modules/run-workspaces/run-workspaces.service.js +29 -1
- package/node_modules/@prismalens/api/dist/src/modules/schedules/allowed-asks.js +17 -0
- package/node_modules/@prismalens/api/dist/src/modules/schedules/decide.js +54 -0
- package/node_modules/@prismalens/api/dist/src/modules/schedules/recurrence.js +85 -0
- package/node_modules/@prismalens/api/dist/src/modules/schedules/schedule-text.js +111 -0
- package/node_modules/@prismalens/api/dist/src/modules/schedules/schedules.controller.js +83 -0
- package/node_modules/@prismalens/api/dist/src/modules/schedules/schedules.module.js +23 -0
- package/node_modules/@prismalens/api/dist/src/modules/schedules/schedules.service.js +898 -0
- package/node_modules/@prismalens/api/dist/src/modules/services/services.controller.js +24 -5
- package/node_modules/@prismalens/api/dist/src/modules/services/services.module.js +2 -1
- package/node_modules/@prismalens/api/dist/src/modules/services/services.service.js +11 -6
- package/node_modules/@prismalens/api/dist/src/modules/terminal/local-request.js +61 -0
- package/node_modules/@prismalens/api/dist/src/modules/terminal/pty.js +75 -0
- package/node_modules/@prismalens/api/dist/src/modules/terminal/terminal-gate.js +57 -0
- package/node_modules/@prismalens/api/dist/src/modules/terminal/terminal-key-issue.js +22 -0
- package/node_modules/@prismalens/api/dist/src/modules/terminal/terminal-socket.js +162 -0
- package/node_modules/@prismalens/api/dist/src/modules/terminal/terminal.controller.js +94 -0
- package/node_modules/@prismalens/api/dist/src/modules/terminal/terminal.module.js +20 -0
- package/node_modules/@prismalens/api/dist/src/modules/terminal/terminal.service.js +54 -0
- package/node_modules/@prismalens/api/dist/src/modules/thread-tree/pending-actions.service.js +465 -0
- package/node_modules/@prismalens/api/dist/src/modules/thread-tree/proposals.service.js +234 -0
- package/node_modules/@prismalens/api/dist/src/modules/thread-tree/put-off.js +19 -0
- package/node_modules/@prismalens/api/dist/src/modules/thread-tree/thread-tree.controller.js +68 -0
- package/node_modules/@prismalens/api/dist/src/modules/thread-tree/thread-tree.module.js +46 -0
- package/node_modules/@prismalens/api/dist/src/modules/thread-tree/thread-tree.service.js +972 -0
- package/node_modules/@prismalens/api/dist/src/modules/thread-tree/tree-gateway.service.js +85 -0
- package/node_modules/@prismalens/api/dist/src/modules/thread-tree/tree-io.service.js +98 -0
- package/node_modules/@prismalens/api/dist/src/modules/thread-tree/tree-settings.service.js +49 -0
- package/node_modules/@prismalens/api/dist/src/modules/threads/links.service.js +258 -0
- package/node_modules/@prismalens/api/dist/src/modules/threads/pr-hosts.js +359 -0
- package/node_modules/@prismalens/api/dist/src/modules/threads/pr-url.js +74 -0
- package/node_modules/@prismalens/api/dist/src/modules/threads/pull-requests.service.js +471 -0
- package/node_modules/@prismalens/api/dist/src/modules/threads/thread-context-settings.controller.js +58 -0
- package/node_modules/@prismalens/api/dist/src/modules/threads/thread-context-settings.js +28 -0
- package/node_modules/@prismalens/api/dist/src/modules/threads/thread-context.service.js +250 -0
- package/node_modules/@prismalens/api/dist/src/modules/threads/thread-sections.js +82 -0
- package/node_modules/@prismalens/api/dist/src/modules/threads/thread-titles.js +56 -0
- package/node_modules/@prismalens/api/dist/src/modules/threads/thread-watches.service.js +329 -0
- package/node_modules/@prismalens/api/dist/src/modules/threads/threads.controller.js +81 -0
- package/node_modules/@prismalens/api/dist/src/modules/threads/threads.module.js +53 -0
- package/node_modules/@prismalens/api/dist/src/modules/threads/threads.service.js +623 -0
- package/node_modules/@prismalens/api/dist/src/modules/threads/work-items.js +171 -0
- package/node_modules/@prismalens/api/dist/src/modules/timeline/timeline.service.js +2 -0
- package/node_modules/@prismalens/api/dist/src/modules/wakes/agent-wakes.js +17 -0
- package/node_modules/@prismalens/api/dist/src/modules/wakes/session-lifecycle.service.js +376 -0
- package/node_modules/@prismalens/api/dist/src/modules/wakes/session.js +124 -0
- package/node_modules/@prismalens/api/dist/src/modules/wakes/wakes.module.js +28 -0
- package/node_modules/@prismalens/api/dist/src/modules/wakes/wakes.service.js +129 -0
- package/node_modules/@prismalens/api/dist/src/modules/webhooks/dto/generic-webhook.dto.js +12 -0
- package/node_modules/@prismalens/api/dist/src/modules/webhooks/webhooks.controller.js +7 -1
- package/node_modules/@prismalens/api/dist/src/modules/webhooks/webhooks.module.js +2 -0
- package/node_modules/@prismalens/api/dist/src/modules/webhooks/webhooks.service.js +103 -41
- package/node_modules/@prismalens/api/dist/src/shared/utils/literal-like.js +5 -0
- package/node_modules/@prismalens/api/public/THIRD_PARTY_NOTICES.txt +381 -3
- package/node_modules/@prismalens/api/public/assets/AddProjectDialog-BEBKziDJ.js +1 -0
- package/node_modules/@prismalens/api/public/assets/AgentDetail-DNNZ2RSQ.js +6 -0
- package/node_modules/@prismalens/api/public/assets/AlertsBlank-M7HkWlgo.js +1 -0
- package/node_modules/@prismalens/api/public/assets/Composer-MAXlRLhF.js +1 -0
- package/node_modules/@prismalens/api/public/assets/CopyButton-DKP5JHET.js +1 -0
- package/node_modules/@prismalens/api/public/assets/HelperThread-BmGnmkL5.js +1 -0
- package/node_modules/@prismalens/api/public/assets/Hint-BCpVhAvV.js +1 -0
- package/node_modules/@prismalens/api/public/assets/HomeComposer-BI6Vhge8.js +1 -0
- package/node_modules/@prismalens/api/public/assets/HypothesesCard-HKxfxVbG.js +1 -0
- package/node_modules/@prismalens/api/public/assets/IncidentHeader-BIYafwD0.js +2 -0
- package/node_modules/@prismalens/api/public/assets/KeptWorkspaces-ozJb7lRG.js +1 -0
- package/node_modules/@prismalens/api/public/assets/MergeDialog-DRjChRQQ.js +1 -0
- package/node_modules/@prismalens/api/public/assets/NewThread-HisGwIRc.js +2 -0
- package/node_modules/@prismalens/api/public/assets/PageHeader-CL1AN9BA.js +1 -0
- package/node_modules/@prismalens/api/public/assets/PanelShell-BHpdPx3P.js +1 -0
- package/node_modules/@prismalens/api/public/assets/ProjectList-lAMigyat.js +1 -0
- package/node_modules/@prismalens/api/public/assets/ResolveDialog-DbMNHrwo.js +1 -0
- package/node_modules/@prismalens/api/public/assets/RingTick-DkMvLoUV.js +1 -0
- package/node_modules/@prismalens/api/public/assets/Row-B3HLhwlw.js +1 -0
- package/node_modules/@prismalens/api/public/assets/RunStrip-CLaYEj2D.js +1 -0
- package/node_modules/@prismalens/api/public/assets/RunsMenu-CD4Yy4jT.js +1 -0
- package/node_modules/@prismalens/api/public/assets/ScheduleDialog-DPYtmK0g.js +2 -0
- package/node_modules/@prismalens/api/public/assets/ServiceFormDialog-9-qDnObk.js +1 -0
- package/node_modules/@prismalens/api/public/assets/SettingsFrame-D4eE2n4w.js +1 -0
- package/node_modules/@prismalens/api/public/assets/State-CCKzehkH.js +1 -0
- package/node_modules/@prismalens/api/public/assets/SubagentPane-exGNOprU.js +1574 -0
- package/node_modules/@prismalens/api/public/assets/TickDot-m_aEzdkj.js +1 -0
- package/node_modules/@prismalens/api/public/assets/Transcript-2ke3pjya.js +159 -0
- package/node_modules/@prismalens/api/public/assets/TriggerCard-BIAznpA9.js +1 -0
- package/node_modules/@prismalens/api/public/assets/WebhookCopy-C8w9xwD6.js +1 -0
- package/node_modules/@prismalens/api/public/assets/{WorkspaceFields-CiyyjkGf.js → WorkspaceFields-DCSJCThm.js} +6 -6
- package/node_modules/@prismalens/api/public/assets/___design-8brlEBqd.js +1 -0
- package/node_modules/@prismalens/api/public/assets/_authenticated-BETuqAeS.js +22 -0
- package/node_modules/@prismalens/api/public/assets/_authenticated-BVT266zx.js +1 -0
- package/node_modules/@prismalens/api/public/assets/_authenticated-BrP-ENHg.css +1 -0
- package/node_modules/@prismalens/api/public/assets/_id-B8v8uWe_.js +1 -0
- package/node_modules/@prismalens/api/public/assets/_id-BeO8QWfB.js +1 -0
- package/node_modules/@prismalens/api/public/assets/_id-Cnh_sXTf.js +1 -0
- package/node_modules/@prismalens/api/public/assets/_id-Crvjv3cl.js +1 -0
- package/node_modules/@prismalens/api/public/assets/_id-DiQnst4D.js +1 -0
- package/node_modules/@prismalens/api/public/assets/_id-VgE-Xeq5.js +1 -0
- package/node_modules/@prismalens/api/public/assets/_id-y5y3CxjT.js +1 -0
- package/node_modules/@prismalens/api/public/assets/_id_.runs._runId-U4P5LH-M.js +1 -0
- package/node_modules/@prismalens/api/public/assets/alerts-BI1l8Cxn.js +1 -0
- package/node_modules/@prismalens/api/public/assets/app-DmCziBS9.css +2 -0
- package/node_modules/@prismalens/api/public/assets/automation-FhFtuS5_.js +1 -0
- package/node_modules/@prismalens/api/public/assets/boxes-Dh2QZfJa.js +1 -0
- package/node_modules/@prismalens/api/public/assets/button-DmIfWVZ8.js +1 -0
- package/node_modules/@prismalens/api/public/assets/check-DfKru7HJ.js +1 -0
- package/node_modules/@prismalens/api/public/assets/chevron-left-DWLaEwl8.js +1 -0
- package/node_modules/@prismalens/api/public/assets/chevron-right-tPbGnTHi.js +1 -0
- package/node_modules/@prismalens/api/public/assets/circle-BqIhGHXt.js +1 -0
- package/node_modules/@prismalens/api/public/assets/command-chip-5Lf0FARB.js +1 -0
- package/node_modules/@prismalens/api/public/assets/conversation-CXkaesO_.js +1 -0
- package/node_modules/@prismalens/api/public/assets/copy-BUnkkIK-.js +1 -0
- package/node_modules/@prismalens/api/public/assets/desktop-Bqso9PNq.js +9 -0
- package/node_modules/@prismalens/api/public/assets/{device-name-uZQ3wSgk.js → device-name-CZPntaj6.js} +1 -1
- package/node_modules/@prismalens/api/public/assets/dist-CQz4Osl1.js +1 -0
- package/node_modules/@prismalens/api/public/assets/dist-CYLssYEL.js +1 -0
- package/node_modules/@prismalens/api/public/assets/dropdown-menu-Db9u3UIb.js +1 -0
- package/node_modules/@prismalens/api/public/assets/ellipsis-d1vABf4v.js +1 -0
- package/node_modules/@prismalens/api/public/assets/evidence-files-C9UcJR1J.js +1 -0
- package/node_modules/@prismalens/api/public/assets/fixes-CgjsPkfr.js +1 -0
- package/node_modules/@prismalens/api/public/assets/folder-git-2-DRsiaeAx.js +1 -0
- package/node_modules/@prismalens/api/public/assets/globe-D2S-zGel.js +1 -0
- package/node_modules/@prismalens/api/public/assets/harness-CokJrRXZ.js +55 -0
- package/node_modules/@prismalens/api/public/assets/highlighted-body-JLMTFACH-B_v9yJZa.js +1 -0
- package/node_modules/@prismalens/api/public/assets/incidents-B0KnIveX.js +1 -0
- package/node_modules/@prismalens/api/public/assets/index-DZMj9YK4.js +23 -0
- package/node_modules/@prismalens/api/public/assets/input-CXxt1dAV.js +1 -0
- package/node_modules/@prismalens/api/public/assets/key-CjFGD02m.js +1 -0
- package/node_modules/@prismalens/api/public/assets/lazyRouteComponent-DkcTE9Kh.js +1 -0
- package/node_modules/@prismalens/api/public/assets/live-refresh-C5Jfxdxb.js +1 -0
- package/node_modules/@prismalens/api/public/assets/mermaid-WFAXDIZX-CqliGVff.js +1 -0
- package/node_modules/@prismalens/api/public/assets/needs-find-DPugLWCN.js +1 -0
- package/node_modules/@prismalens/api/public/assets/new-Ci475pgf.js +1 -0
- package/node_modules/@prismalens/api/public/assets/pair-CobM73_c.js +1 -0
- package/node_modules/@prismalens/api/public/assets/pencil-BwNhunJy.js +1 -0
- package/node_modules/@prismalens/api/public/assets/plus-DWSahnrj.js +1 -0
- package/node_modules/@prismalens/api/public/assets/preload-helper-BLdHbfdN.js +1 -0
- package/node_modules/@prismalens/api/public/assets/projects-CIckRlw8.js +1 -0
- package/node_modules/@prismalens/api/public/assets/record-context-CoIOStXx.js +1 -0
- package/node_modules/@prismalens/api/public/assets/restart-40l7XMmi.js +1 -0
- package/node_modules/@prismalens/api/public/assets/route-Bg17GbpR.js +1 -0
- package/node_modules/@prismalens/api/public/assets/route-DX3TI7JD.js +1 -0
- package/node_modules/@prismalens/api/public/assets/route-Dvao2bBW.js +1 -0
- package/node_modules/@prismalens/api/public/assets/{route-CCkTDfa6.js → route-ah1SnYbH.js} +1 -1
- package/node_modules/@prismalens/api/public/assets/run-details-DTzMO1X0.js +1 -0
- package/node_modules/@prismalens/api/public/assets/run-labels-ubQZmnqd.js +2 -0
- package/node_modules/@prismalens/api/public/assets/select-98_n4DVz.js +1 -0
- package/node_modules/@prismalens/api/public/assets/service-detail.utils-ulWHS1Ao.js +1 -0
- package/node_modules/@prismalens/api/public/assets/service-lanes-BfHIrySn.js +1 -0
- package/node_modules/@prismalens/api/public/assets/services-CZQMzqYj.js +1 -0
- package/node_modules/@prismalens/api/public/assets/settings-QPxeIS82.js +1 -0
- package/node_modules/@prismalens/api/public/assets/source-words-B5oOdiQU.js +4 -0
- package/node_modules/@prismalens/api/public/assets/state-tone-DEsvSFn6.js +1 -0
- package/node_modules/@prismalens/api/public/assets/strip-inline-markdown-d6Movgzo.js +1 -0
- package/node_modules/@prismalens/api/public/assets/switch-DpPkkZxw.js +1 -0
- package/node_modules/@prismalens/api/public/assets/theme-provider-C9jvt7JX.js +1 -0
- package/node_modules/@prismalens/api/public/assets/threads-BqAHgCGd.js +1 -0
- package/node_modules/@prismalens/api/public/assets/tick-copy-B7dbIrfQ.js +1 -0
- package/node_modules/@prismalens/api/public/assets/trigger-DVo1oKMX.js +1 -0
- package/node_modules/@prismalens/api/public/assets/{use-back-VWIQYM2j.js → use-back-R0oWqfab.js} +1 -1
- package/node_modules/@prismalens/api/public/assets/use-operator-BH6GxjAY.js +1 -0
- package/node_modules/@prismalens/api/public/assets/use-repositories-orpc-c6hPOKjE.js +41 -0
- package/node_modules/@prismalens/api/public/assets/use-threads-orpc-rBrvQXJf.js +1 -0
- package/node_modules/@prismalens/api/public/assets/useInvestigationRun-xdB0R08B.js +1 -0
- package/node_modules/@prismalens/api/public/assets/useLocation-CXMqJKgu.js +1 -0
- package/node_modules/@prismalens/api/public/assets/{useSearch-Bq5sxYI3.js → useMatch-B0f9tdXB.js} +1 -1
- package/node_modules/@prismalens/api/public/assets/useQueries-CGpidxif.js +1 -0
- package/node_modules/@prismalens/api/public/assets/useSearch-BBl0vmEJ.js +1 -0
- package/node_modules/@prismalens/api/public/index.html +5 -3
- package/node_modules/@prismalens/auth/dist/index.js +2 -1
- package/node_modules/@prismalens/auth/dist/pairing.js +31 -6
- package/node_modules/@prismalens/auth/dist/terminal-key.js +25 -0
- package/node_modules/@prismalens/config/dist/acp-registry.json +151 -103
- package/node_modules/@prismalens/config/dist/index.js +3 -0
- package/node_modules/@prismalens/config/dist/providers/harness.js +61 -6
- package/node_modules/@prismalens/config/dist/utils/app-data.js +14 -13
- package/node_modules/@prismalens/config/dist/utils/background-service.js +9 -4
- package/node_modules/@prismalens/config/dist/utils/diagnostics.js +247 -0
- package/node_modules/@prismalens/config/dist/utils/node-version.js +29 -0
- package/node_modules/@prismalens/config/dist/utils/update-install.js +160 -0
- package/node_modules/@prismalens/contracts/dist/contracts/composer.js +70 -0
- package/node_modules/@prismalens/contracts/dist/contracts/incidents.js +3 -2
- package/node_modules/@prismalens/contracts/dist/contracts/index.js +16 -0
- package/node_modules/@prismalens/contracts/dist/contracts/investigations.js +184 -2
- package/node_modules/@prismalens/contracts/dist/contracts/live.js +8 -1
- package/node_modules/@prismalens/contracts/dist/contracts/pairing.js +6 -0
- package/node_modules/@prismalens/contracts/dist/contracts/push.js +1 -1
- package/node_modules/@prismalens/contracts/dist/contracts/repositories.js +41 -1
- package/node_modules/@prismalens/contracts/dist/contracts/run-workspaces.js +11 -0
- package/node_modules/@prismalens/contracts/dist/contracts/schedules.js +84 -0
- package/node_modules/@prismalens/contracts/dist/contracts/settings.js +99 -1
- package/node_modules/@prismalens/contracts/dist/contracts/sources.js +19 -19
- package/node_modules/@prismalens/contracts/dist/contracts/terminal.js +43 -0
- package/node_modules/@prismalens/contracts/dist/contracts/thread-tree.js +87 -0
- package/node_modules/@prismalens/contracts/dist/contracts/threads.js +239 -0
- package/node_modules/@prismalens/contracts/dist/schemas/ask-projection.js +107 -0
- package/node_modules/@prismalens/contracts/dist/schemas/asks.js +211 -0
- package/node_modules/@prismalens/contracts/dist/schemas/composer.js +139 -0
- package/node_modules/@prismalens/contracts/dist/schemas/context-pack.js +6 -2
- package/node_modules/@prismalens/contracts/dist/schemas/impact.js +2 -0
- package/node_modules/@prismalens/contracts/dist/schemas/incident.js +29 -2
- package/node_modules/@prismalens/contracts/dist/schemas/index.js +12 -0
- package/node_modules/@prismalens/contracts/dist/schemas/investigation.js +642 -39
- package/node_modules/@prismalens/contracts/dist/schemas/pull-request.js +176 -0
- package/node_modules/@prismalens/contracts/dist/schemas/recommendation.js +2 -1
- package/node_modules/@prismalens/contracts/dist/schemas/references.js +104 -0
- package/node_modules/@prismalens/contracts/dist/schemas/repository.js +69 -2
- package/node_modules/@prismalens/contracts/dist/schemas/run-views.js +168 -0
- package/node_modules/@prismalens/contracts/dist/schemas/schedule.js +172 -0
- package/node_modules/@prismalens/contracts/dist/schemas/service.js +4 -1
- package/node_modules/@prismalens/contracts/dist/schemas/settings.js +101 -1
- package/node_modules/@prismalens/contracts/dist/schemas/source-type.js +25 -1
- package/node_modules/@prismalens/contracts/dist/schemas/subagents.js +31 -0
- package/node_modules/@prismalens/contracts/dist/schemas/terminal.js +78 -0
- package/node_modules/@prismalens/contracts/dist/schemas/thread-context.js +222 -0
- package/node_modules/@prismalens/contracts/dist/schemas/thread-tree.js +172 -0
- package/node_modules/@prismalens/contracts/dist/schemas/thread.js +159 -0
- package/node_modules/@prismalens/database/dist/prisma/generated/internal/class.js +4 -4
- package/node_modules/@prismalens/database/dist/prisma/generated/internal/prismaNamespace.js +231 -1
- package/node_modules/@prismalens/database/dist/prisma/generated/models/CheckoutLease.js +2 -0
- package/node_modules/@prismalens/database/dist/prisma/generated/models/ComposerDraft.js +2 -0
- package/node_modules/@prismalens/database/dist/prisma/generated/models/PendingAction.js +2 -0
- package/node_modules/@prismalens/database/dist/prisma/generated/models/PrWatch.js +2 -0
- package/node_modules/@prismalens/database/dist/prisma/generated/models/Proposal.js +2 -0
- package/node_modules/@prismalens/database/dist/prisma/generated/models/PullRequest.js +2 -0
- package/node_modules/@prismalens/database/dist/prisma/generated/models/ReferenceUse.js +2 -0
- package/node_modules/@prismalens/database/dist/prisma/generated/models/Schedule.js +2 -0
- package/node_modules/@prismalens/database/dist/prisma/generated/models/ScheduleEvent.js +2 -0
- package/node_modules/@prismalens/database/dist/prisma/generated/models/ScheduleTick.js +2 -0
- package/node_modules/@prismalens/database/dist/prisma/generated/models/SecretRequested.js +2 -0
- package/node_modules/@prismalens/database/dist/prisma/generated/models/SubagentSession.js +2 -0
- package/node_modules/@prismalens/database/dist/prisma/generated/models/ThreadMessage.js +2 -0
- package/node_modules/@prismalens/database/dist/prisma/generated/models/ThreadWait.js +2 -0
- package/node_modules/@prismalens/database/dist/prisma/generated/models/ThreadWake.js +2 -0
- package/node_modules/@prismalens/database/dist/prisma/generated/models/ToolAsk.js +2 -0
- package/node_modules/@prismalens/database/dist/prisma/generated/models/TreeAllowance.js +2 -0
- package/node_modules/@prismalens/database/dist/prisma/sqlite/schema/20261028083515_scheduled_tasks/migration.sql +148 -0
- package/node_modules/@prismalens/database/dist/prisma/sqlite/schema/20261102044114_investigation_service_set_null/migration.sql +57 -0
- package/node_modules/@prismalens/database/dist/prisma/sqlite/schema/20261102202000_thread_subjects/migration.sql +78 -0
- package/node_modules/@prismalens/database/dist/prisma/sqlite/schema/20261103010000_thread_list/migration.sql +3 -0
- package/node_modules/@prismalens/database/dist/prisma/sqlite/schema/20261103090000_thread_titles/migration.sql +2 -0
- package/node_modules/@prismalens/database/dist/prisma/sqlite/schema/20261103200000_helper_place/migration.sql +2 -0
- package/node_modules/@prismalens/database/dist/prisma/sqlite/schema/20261104010000_project_kinds/migration.sql +3 -0
- package/node_modules/@prismalens/database/dist/prisma/sqlite/schema/20261104200000_schedule_subjects/migration.sql +41 -0
- package/node_modules/@prismalens/database/dist/prisma/sqlite/schema/20261107100000_composer/migration.sql +40 -0
- package/node_modules/@prismalens/database/dist/prisma/sqlite/schema/20261107110000_session_wake/migration.sql +26 -0
- package/node_modules/@prismalens/database/dist/prisma/sqlite/schema/20261107120000_thread_context/migration.sql +32 -0
- package/node_modules/@prismalens/database/dist/prisma/sqlite/schema/20261107130000_app_sources/migration.sql +4 -0
- package/node_modules/@prismalens/database/dist/prisma/sqlite/schema/20261107140000_thread_tree/migration.sql +166 -0
- package/node_modules/@prismalens/database/dist/prisma/sqlite/schema/20261108100000_subagents/migration.sql +51 -0
- package/node_modules/@prismalens/database/dist/prisma/sqlite/schema/20261108110000_in_place/migration.sql +15 -0
- package/node_modules/@prismalens/database/dist/prisma/sqlite/schema/app.prisma +391 -7
- package/node_modules/@prismalens/engine/dist/adapter/acp-adapter.js +380 -31
- package/node_modules/@prismalens/engine/dist/index.js +2 -0
- package/node_modules/@prismalens/engine/dist/launch/policy.js +29 -9
- package/node_modules/@prismalens/engine/dist/run/conductor.js +5 -1
- package/node_modules/@prismalens/engine/dist/run/elicitation.js +244 -0
- package/node_modules/@prismalens/engine/dist/run/fence.js +23 -5
- package/node_modules/@prismalens/engine/dist/run/findings.js +203 -0
- package/node_modules/@prismalens/engine/dist/run/handoff.js +86 -2
- package/node_modules/@prismalens/engine/dist/run/harness-doctor.js +46 -6
- package/node_modules/@prismalens/engine/dist/run/investigate.js +403 -57
- package/node_modules/@prismalens/engine/dist/run/local-default.js +13 -4
- package/node_modules/@prismalens/engine/dist/run/permission.js +192 -14
- package/node_modules/@prismalens/engine/dist/run/prompt.js +126 -12
- package/node_modules/@prismalens/engine/dist/run/redact.js +52 -0
- package/node_modules/@prismalens/engine/dist/run/usage-limit.js +91 -9
- package/node_modules/@prismalens/engine/dist/runner/acp-client.js +238 -16
- package/node_modules/@prismalens/integrations/dist/engine/oauth2-flow.js +12 -0
- package/node_modules/@prismalens/integrations/dist/harness/index.js +8 -0
- package/node_modules/@prismalens/integrations/dist/harness/mcp-server.js +60 -0
- package/node_modules/@prismalens/integrations/dist/harness/registry.js +127 -0
- package/node_modules/@prismalens/integrations/dist/harness/replay.js +67 -0
- package/node_modules/@prismalens/integrations/dist/harness/search.js +113 -0
- package/node_modules/@prismalens/integrations/dist/harness/tool.js +64 -0
- package/node_modules/@prismalens/integrations/dist/index.js +2 -0
- package/node_modules/@prismalens/integrations/dist/providers/host-repositories.js +193 -0
- package/node_modules/@prismalens/integrations/package.json +4 -0
- package/package.json +12 -5
- package/node_modules/@prismalens/agent-adapters/node_modules/@anthropic-ai/claude-agent-sdk/core-4pv47a2z.mjs +0 -27
- package/node_modules/@prismalens/agent-adapters/node_modules/@anthropic-ai/claude-agent-sdk/core-bz5kkzv0.mjs +0 -40
- package/node_modules/@prismalens/agent-adapters/node_modules/@anthropic-ai/claude-agent-sdk/core-c86d180z.mjs +0 -52
- package/node_modules/@prismalens/agent-adapters/node_modules/@anthropic-ai/claude-agent-sdk/core-pzfwbvz7.mjs +0 -26
- package/node_modules/@prismalens/api/dist/src/modules/gateway/mcp-delivery.js +0 -39
- package/node_modules/@prismalens/api/public/assets/Field-BQic-QnX.js +0 -1
- package/node_modules/@prismalens/api/public/assets/Hint-B9ocVmjH.js +0 -41
- package/node_modules/@prismalens/api/public/assets/KeptWorkspaces-mrbq8M-h.js +0 -1
- package/node_modules/@prismalens/api/public/assets/MergeDialog-BO_TSjSe.js +0 -1
- package/node_modules/@prismalens/api/public/assets/NewIncident-DWw1jRp3.js +0 -1
- package/node_modules/@prismalens/api/public/assets/PageHeader-DmwtlO5o.js +0 -1
- package/node_modules/@prismalens/api/public/assets/ResolveDialog-nVfxRJOp.js +0 -1
- package/node_modules/@prismalens/api/public/assets/RunsMenu-DrVYxtD6.js +0 -3
- package/node_modules/@prismalens/api/public/assets/ServiceFormDialog-CM8ibEPP.js +0 -1
- package/node_modules/@prismalens/api/public/assets/_authenticated-BIX9FmcY.js +0 -1
- package/node_modules/@prismalens/api/public/assets/_authenticated-g2XLlfqP.js +0 -1
- package/node_modules/@prismalens/api/public/assets/_id-Bs75xuEI.js +0 -1
- package/node_modules/@prismalens/api/public/assets/_id-CbGZLynL.js +0 -1
- package/node_modules/@prismalens/api/public/assets/_id-D7TdCttn.js +0 -1
- package/node_modules/@prismalens/api/public/assets/_id-asM5UbQq.js +0 -1
- package/node_modules/@prismalens/api/public/assets/alerts-C2Ii6YGg.js +0 -1
- package/node_modules/@prismalens/api/public/assets/app-DpX-DlR8.css +0 -2
- package/node_modules/@prismalens/api/public/assets/button-BX6aOWvu.js +0 -1
- package/node_modules/@prismalens/api/public/assets/conversation-MWIw1Mcu.js +0 -461
- package/node_modules/@prismalens/api/public/assets/desktop-CcO1sAJv.js +0 -63
- package/node_modules/@prismalens/api/public/assets/dist-NPKXzqzH.js +0 -1
- package/node_modules/@prismalens/api/public/assets/dropdown-menu-C2eZATbR.js +0 -1
- package/node_modules/@prismalens/api/public/assets/fixes-qbD9HTI7.js +0 -1
- package/node_modules/@prismalens/api/public/assets/format-time-CGRUxfR2.js +0 -1
- package/node_modules/@prismalens/api/public/assets/get-error-message-XWlcOfOx.js +0 -1
- package/node_modules/@prismalens/api/public/assets/highlighted-body-JLMTFACH-DrFHe1nT.js +0 -1
- package/node_modules/@prismalens/api/public/assets/incident-attention-DvrvH6ZE.js +0 -1
- package/node_modules/@prismalens/api/public/assets/incidents-tNIOIUJ9.js +0 -1
- package/node_modules/@prismalens/api/public/assets/index-Bkua5FuI.js +0 -26
- package/node_modules/@prismalens/api/public/assets/loader-circle-BxgKP4dD.js +0 -1
- package/node_modules/@prismalens/api/public/assets/mermaid-WFAXDIZX-BJN6kGuM.js +0 -1
- package/node_modules/@prismalens/api/public/assets/pair-CyzQzNhd.js +0 -1
- package/node_modules/@prismalens/api/public/assets/plus-C-sWiVlr.js +0 -1
- package/node_modules/@prismalens/api/public/assets/route-9A2eeVtZ.js +0 -1
- package/node_modules/@prismalens/api/public/assets/route-BpObCIuc.js +0 -1
- package/node_modules/@prismalens/api/public/assets/route-CAqkvl37.js +0 -1
- package/node_modules/@prismalens/api/public/assets/services-B9GdE4hP.js +0 -1
- package/node_modules/@prismalens/api/public/assets/settings-DsCNpTCk.js +0 -1
- package/node_modules/@prismalens/api/public/assets/state-tone-B3RGc3XM.js +0 -1
- package/node_modules/@prismalens/api/public/assets/switch-UJRRev_z.js +0 -3
- package/node_modules/@prismalens/api/public/assets/use-first-open-rsFZV7FY.js +0 -1
- package/node_modules/@prismalens/api/public/assets/useInvestigationRun-7torOSoz.js +0 -1
- package/node_modules/@prismalens/api/public/assets/useLocation-D-akr70j.js +0 -1
|
@@ -14,31 +14,57 @@ var DispatchService_1;
|
|
|
14
14
|
import { Inject, Injectable, Logger, Optional, } from "@nestjs/common";
|
|
15
15
|
import { getConfig } from "@prismalens/config";
|
|
16
16
|
import { HARNESS_IDS, HARNESS_REGISTRY, resolveHarnessModel, } from "@prismalens/config/harness";
|
|
17
|
-
import { AccessLevelSchema,
|
|
17
|
+
import { AccessLevelSchema, asksLeftOpen, ENDED_INCIDENT_STATUSES, effectiveAccess, HelperPlaceSchema, InvestigationJobDataSchema, isWorkflowTerminal, LIVE_WORKFLOW_STATUSES, parseEventRows, questionTimeoutFrom, queuedLeftWaiting, RunWorkspaceSchema, ScheduledRunSchema, } from "@prismalens/contracts";
|
|
18
18
|
import { reapLiveHarnesses } from "@prismalens/engine";
|
|
19
19
|
import { HarnessService } from "../../core/harness/harness.service.js";
|
|
20
20
|
import { RepoSourceService } from "../../core/harness/repo-source.service.js";
|
|
21
|
+
import { AdmissionService } from "../../core/lifecycle/admission.service.js";
|
|
22
|
+
import { RuntimeLifecycleService } from "../../core/lifecycle/runtime-lifecycle.service.js";
|
|
21
23
|
import { PrismaService } from "../../core/prisma/prisma.service.js";
|
|
22
24
|
import { TelemetryService, triggerFor, } from "../../core/telemetry/telemetry.service.js";
|
|
23
25
|
import { ReportDeliveryService } from "../../modules/delivery/report-delivery.service.js";
|
|
24
26
|
import { GatewayService } from "../../modules/gateway/gateway.service.js";
|
|
25
27
|
import { IncidentsService } from "../../modules/incidents/incidents.service.js";
|
|
26
28
|
import { ConnectorResolverService } from "../../modules/integrations/connector-resolver.service.js";
|
|
29
|
+
import { CredentialsService } from "../../modules/integrations/crypto/credentials.service.js";
|
|
27
30
|
import { GitCredentialService, pickOf, } from "../../modules/integrations/git-credential.service.js";
|
|
28
31
|
import { TelemetrySnapshotService } from "../../modules/integrations/telemetry-snapshot.service.js";
|
|
29
32
|
import { ContextPackService } from "../../modules/investigations/context-pack.service.js";
|
|
30
33
|
import { followUpRoute, handoffPreflight, } from "../../modules/investigations/follow-up-route.js";
|
|
31
34
|
import { InvestigationsService } from "../../modules/investigations/investigations.service.js";
|
|
35
|
+
import { runScope, runScopeKey, sharesAdmission, } from "../../modules/investigations/run-scope.js";
|
|
32
36
|
import { StreamRelayService } from "../../modules/investigations/stream-relay.service.js";
|
|
37
|
+
import { agentCommandsKey } from "../../modules/references/references.service.js";
|
|
38
|
+
import { shownFullName } from "../../modules/repositories/serialize-repository.js";
|
|
33
39
|
import { interruptedRunIds, RunWorkspacesService, } from "../../modules/run-workspaces/run-workspaces.service.js";
|
|
34
40
|
import { TimelineService } from "../../modules/timeline/timeline.service.js";
|
|
41
|
+
import { safeParseJsonObject } from "../../shared/utils/json-utils.js";
|
|
42
|
+
import { busyReason, CheckoutUnreadable, checkoutBusy, checkoutRoot, leasedBy, releaseIfGone, releaseLease, sameCheckout, takeLease, } from "./checkout-lease.js";
|
|
35
43
|
import { Dispatcher } from "./dispatcher.js";
|
|
36
|
-
import { EVENT_BUS, runAskTopic, runCancelTopic, runMessageTopic, } from "./event-bus.js";
|
|
44
|
+
import { EVENT_BUS, runAskTopic, runCancelTopic, runMessageTopic, runQueueTopic, runSubagentTopic, } from "./event-bus.js";
|
|
45
|
+
import { FOLDER_BUSY, FOLDER_TX, folderBusy } from "./folder-lock.js";
|
|
46
|
+
export const QUESTION_TIMEOUT_SETTING = "agents.questionTimeoutMinutes";
|
|
47
|
+
import { containPrevious, readReceipt } from "./harness-receipt.js";
|
|
37
48
|
import { createInProcessRunner } from "./in-process-runner.js";
|
|
38
|
-
import { followUpNotDelivered, sweepRunWorkspaces, } from "./investigation-run.js";
|
|
49
|
+
import { checkoutGoneReason, followUpNotDelivered, runDirFor, sweepRunWorkspaces, } from "./investigation-run.js";
|
|
39
50
|
import { PrismaJobStore, } from "./job-store.js";
|
|
51
|
+
import { BOOT_LOOP_MS, NOT_RESUMED, notResumedReason, RECOVERY_DELAY_MS, } from "./restart-recovery.js";
|
|
52
|
+
const RESTART_SUMMARY_KEY = "runtime.lastRecovery";
|
|
53
|
+
const RECHECK_MS = 10_000;
|
|
54
|
+
const HELD_UNTIL = new Date("9999-01-01T00:00:00Z");
|
|
55
|
+
const AGENT_KINDS = [
|
|
56
|
+
"agent_step",
|
|
57
|
+
"tool_result",
|
|
58
|
+
"permission_ask",
|
|
59
|
+
"report",
|
|
60
|
+
"branch_done",
|
|
61
|
+
];
|
|
40
62
|
export class FollowUpRefused extends Error {
|
|
41
63
|
}
|
|
64
|
+
export class CheckoutGone extends FollowUpRefused {
|
|
65
|
+
}
|
|
66
|
+
class WakeTaken extends Error {
|
|
67
|
+
}
|
|
42
68
|
const PRIORITY_ORDER = {
|
|
43
69
|
critical: 1,
|
|
44
70
|
high: 2,
|
|
@@ -56,9 +82,57 @@ function jobResume(payload) {
|
|
|
56
82
|
return undefined;
|
|
57
83
|
}
|
|
58
84
|
}
|
|
85
|
+
function serviceCheckOf(snapshot) {
|
|
86
|
+
try {
|
|
87
|
+
const raw = JSON.parse(snapshot ?? "null");
|
|
88
|
+
const scheduled = ScheduledRunSchema.safeParse(raw);
|
|
89
|
+
if (!scheduled.success)
|
|
90
|
+
return {};
|
|
91
|
+
return {
|
|
92
|
+
scheduled: scheduled.data,
|
|
93
|
+
...(typeof raw?.brief === "string" ? { brief: raw.brief } : {}),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
return {};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
59
100
|
function startedByAlert(triggerType) {
|
|
60
101
|
return !!triggerType && triggerType !== "manual";
|
|
61
102
|
}
|
|
103
|
+
function agentLabel(harness) {
|
|
104
|
+
const id = HARNESS_IDS.find((h) => h === harness);
|
|
105
|
+
return id ? HARNESS_REGISTRY[id].label : "The agent";
|
|
106
|
+
}
|
|
107
|
+
function safeJson(text) {
|
|
108
|
+
try {
|
|
109
|
+
return JSON.parse(text);
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
export function recoveryPayload(original, plan, turn, restart, sawEvidence = false) {
|
|
116
|
+
const { resume: prev, ...rest } = original;
|
|
117
|
+
const question = turn === "answer" ? (prev ? prev.text : original.chat?.text) : undefined;
|
|
118
|
+
return {
|
|
119
|
+
...rest,
|
|
120
|
+
resume: {
|
|
121
|
+
text: question ?? "PrismaLens restarted.",
|
|
122
|
+
mode: "queue",
|
|
123
|
+
kind: turn === "report" ? "continue" : "chat",
|
|
124
|
+
...(turn === "report" ? { sawEvidence } : {}),
|
|
125
|
+
restore: prev?.restore ?? {
|
|
126
|
+
status: "failed",
|
|
127
|
+
completedAt: null,
|
|
128
|
+
error: RESTART_REASON,
|
|
129
|
+
},
|
|
130
|
+
to: { ...(prev?.to ?? {}), harness: plan.harness },
|
|
131
|
+
...(plan.route === "handoff" ? { handoff: true } : {}),
|
|
132
|
+
restart,
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
}
|
|
62
136
|
export function resolveHarnessRunModel(harnessId, operatorModel, agentEnv = {}) {
|
|
63
137
|
if (HARNESS_REGISTRY[harnessId].modelVia === "unsupported")
|
|
64
138
|
return {};
|
|
@@ -76,6 +150,7 @@ export function isCustomModel(model, custom) {
|
|
|
76
150
|
!!model.model &&
|
|
77
151
|
!!custom?.includes(model.model));
|
|
78
152
|
}
|
|
153
|
+
const LEASE_RETRY_MS = 60_000;
|
|
79
154
|
let DispatchService = DispatchService_1 = class DispatchService {
|
|
80
155
|
bus;
|
|
81
156
|
streamRelay;
|
|
@@ -92,10 +167,15 @@ let DispatchService = DispatchService_1 = class DispatchService {
|
|
|
92
167
|
reportDelivery;
|
|
93
168
|
gateway;
|
|
94
169
|
runWorkspaces;
|
|
170
|
+
lifecycle;
|
|
171
|
+
credentials;
|
|
95
172
|
logger = new Logger(DispatchService_1.name);
|
|
96
173
|
store;
|
|
97
174
|
dispatcher;
|
|
98
|
-
|
|
175
|
+
recoveryWake;
|
|
176
|
+
recheckTimer;
|
|
177
|
+
leaseRetry;
|
|
178
|
+
constructor(bus, streamRelay, investigationsService, incidentsService, timelineService, harnessService, repoSource, prisma, gitCredentials, connectorResolver, contextPackService, telemetry, reportDelivery, gateway, telemetrySnapshot, runWorkspaces, lifecycle, admission, credentials) {
|
|
99
179
|
this.bus = bus;
|
|
100
180
|
this.streamRelay = streamRelay;
|
|
101
181
|
this.investigationsService = investigationsService;
|
|
@@ -111,8 +191,11 @@ let DispatchService = DispatchService_1 = class DispatchService {
|
|
|
111
191
|
this.reportDelivery = reportDelivery;
|
|
112
192
|
this.gateway = gateway;
|
|
113
193
|
this.runWorkspaces = runWorkspaces;
|
|
194
|
+
this.lifecycle = lifecycle;
|
|
195
|
+
this.credentials = credentials;
|
|
114
196
|
this.store = new PrismaJobStore(this.prisma.job);
|
|
115
197
|
const ports = {
|
|
198
|
+
releaseLease: (id) => releaseLease(this.prisma, id),
|
|
116
199
|
findInvestigation: async (id) => {
|
|
117
200
|
const investigation = await this.investigationsService.findById(id);
|
|
118
201
|
return investigation
|
|
@@ -127,6 +210,7 @@ let DispatchService = DispatchService_1 = class DispatchService {
|
|
|
127
210
|
kind: investigation.kind,
|
|
128
211
|
stopRequestedAt: investigation.stopRequestedAt ?? null,
|
|
129
212
|
report: investigation.report ?? null,
|
|
213
|
+
usage: investigation.usage ?? null,
|
|
130
214
|
}
|
|
131
215
|
: null;
|
|
132
216
|
},
|
|
@@ -188,7 +272,7 @@ let DispatchService = DispatchService_1 = class DispatchService {
|
|
|
188
272
|
recordUsage: async (id, usage) => {
|
|
189
273
|
await this.prisma.investigation.updateMany({
|
|
190
274
|
where: { id },
|
|
191
|
-
data: { usage: JSON.stringify(usage) },
|
|
275
|
+
data: { usage: JSON.stringify(usage), lastActivityAt: new Date() },
|
|
192
276
|
});
|
|
193
277
|
},
|
|
194
278
|
markAwaitingApproval: async (id, since) => {
|
|
@@ -197,16 +281,55 @@ let DispatchService = DispatchService_1 = class DispatchService {
|
|
|
197
281
|
data: { awaitingApprovalAt: since },
|
|
198
282
|
});
|
|
199
283
|
},
|
|
284
|
+
recordAgentCommands: async (id, harness, commands) => {
|
|
285
|
+
const value = JSON.stringify(commands);
|
|
286
|
+
await this.prisma.investigation.updateMany({
|
|
287
|
+
where: { id },
|
|
288
|
+
data: { agentCommands: value },
|
|
289
|
+
});
|
|
290
|
+
await this.prisma.setting.upsert({
|
|
291
|
+
where: { key: agentCommandsKey(harness) },
|
|
292
|
+
create: {
|
|
293
|
+
key: agentCommandsKey(harness),
|
|
294
|
+
value,
|
|
295
|
+
type: "json",
|
|
296
|
+
category: "ai",
|
|
297
|
+
},
|
|
298
|
+
update: { value },
|
|
299
|
+
});
|
|
300
|
+
},
|
|
301
|
+
requestedSecrets: async (runId) => {
|
|
302
|
+
const rows = await this.prisma.secretRequested.findMany({
|
|
303
|
+
where: { investigationId: runId, valueEnc: { not: null } },
|
|
304
|
+
orderBy: { answeredAt: "asc" },
|
|
305
|
+
});
|
|
306
|
+
const out = {};
|
|
307
|
+
for (const row of rows)
|
|
308
|
+
if (row.valueEnc && this.credentials)
|
|
309
|
+
out[row.name] = this.credentials.decryptFromBase64(row.valueEnc);
|
|
310
|
+
return out;
|
|
311
|
+
},
|
|
312
|
+
questionTimeoutMs: async () => {
|
|
313
|
+
const row = await this.prisma.setting.findUnique({
|
|
314
|
+
where: { key: QUESTION_TIMEOUT_SETTING },
|
|
315
|
+
});
|
|
316
|
+
return questionTimeoutFrom(row?.value);
|
|
317
|
+
},
|
|
200
318
|
newerRun: async (id) => {
|
|
201
319
|
const self = await this.prisma.investigation.findUnique({
|
|
202
320
|
where: { id },
|
|
203
|
-
select: {
|
|
321
|
+
select: {
|
|
322
|
+
id: true,
|
|
323
|
+
incidentId: true,
|
|
324
|
+
scheduleId: true,
|
|
325
|
+
createdAt: true,
|
|
326
|
+
},
|
|
204
327
|
});
|
|
205
328
|
if (!self)
|
|
206
329
|
return null;
|
|
207
330
|
const newer = await this.prisma.investigation.findFirst({
|
|
208
331
|
where: {
|
|
209
|
-
|
|
332
|
+
...runScope(self),
|
|
210
333
|
createdAt: { gt: self.createdAt },
|
|
211
334
|
workspace: { not: null },
|
|
212
335
|
},
|
|
@@ -220,7 +343,7 @@ let DispatchService = DispatchService_1 = class DispatchService {
|
|
|
220
343
|
return null;
|
|
221
344
|
const number = await this.prisma.investigation.count({
|
|
222
345
|
where: {
|
|
223
|
-
|
|
346
|
+
...runScope(self),
|
|
224
347
|
createdAt: { lte: newer.createdAt },
|
|
225
348
|
},
|
|
226
349
|
});
|
|
@@ -326,13 +449,37 @@ let DispatchService = DispatchService_1 = class DispatchService {
|
|
|
326
449
|
const incident = await this.incidentsService.findById(id);
|
|
327
450
|
return incident;
|
|
328
451
|
},
|
|
452
|
+
restartAlerts: (incidentId, since, until, stoppedAt) => this.restartAlerts(incidentId, since, until, stoppedAt),
|
|
329
453
|
resolveConnectors: (serviceId) => this.connectorResolver.resolve({ serviceId }),
|
|
330
|
-
contextPack: (
|
|
454
|
+
contextPack: (subject) => typeof subject === "string"
|
|
455
|
+
? this.contextPackService.assemble(subject)
|
|
456
|
+
: this.contextPackService.assembleForService(subject.serviceId),
|
|
457
|
+
deployments: async (services) => {
|
|
458
|
+
const rows = await this.prisma.changeEvent.findMany({
|
|
459
|
+
where: {
|
|
460
|
+
type: { in: ["deploy", "deployment"] },
|
|
461
|
+
service: { name: { in: services } },
|
|
462
|
+
},
|
|
463
|
+
orderBy: { timestamp: "desc" },
|
|
464
|
+
take: 50,
|
|
465
|
+
select: { metadata: true },
|
|
466
|
+
});
|
|
467
|
+
return rows.flatMap((r) => {
|
|
468
|
+
const meta = safeParseJsonObject(r.metadata ?? null) ?? {};
|
|
469
|
+
const sha = meta.sha ?? meta.commit;
|
|
470
|
+
const name = meta.version ?? meta.tag;
|
|
471
|
+
return typeof sha === "string"
|
|
472
|
+
? [{ sha, name: typeof name === "string" ? name : null }]
|
|
473
|
+
: [];
|
|
474
|
+
});
|
|
475
|
+
},
|
|
331
476
|
...(this.gateway ? { gateway: this.gateway } : {}),
|
|
332
477
|
...(telemetrySnapshot
|
|
333
478
|
? {
|
|
334
479
|
preRun: {
|
|
335
|
-
telemetry: (
|
|
480
|
+
telemetry: (subject, window, signal) => typeof subject === "string"
|
|
481
|
+
? telemetrySnapshot.fetch(subject, window, signal)
|
|
482
|
+
: telemetrySnapshot.fetchForService(subject.serviceId, window, signal),
|
|
336
483
|
runbooks: (runId, signal) => this.gateway?.runbookIndex(runId, signal) ??
|
|
337
484
|
Promise.resolve({ entries: [] }),
|
|
338
485
|
save: async (runId, snapshot) => {
|
|
@@ -352,13 +499,23 @@ let DispatchService = DispatchService_1 = class DispatchService {
|
|
|
352
499
|
this.dispatcher = new Dispatcher(this.store, this.bus, createInProcessRunner(ports), {
|
|
353
500
|
concurrency: getConfig().PRISMALENS_DISPATCH_CONCURRENCY,
|
|
354
501
|
onClaim: (job) => this.streamRelay.attach(job.investigationId),
|
|
355
|
-
onSettled: (job) =>
|
|
502
|
+
onSettled: (job, outcome) => {
|
|
503
|
+
this.logger.log(`Job ${job.id} settled (${job.investigationId})`);
|
|
504
|
+
for (const listener of this.settledListeners)
|
|
505
|
+
void Promise.resolve()
|
|
506
|
+
.then(() => listener(job.investigationId, outcome))
|
|
507
|
+
.catch((e) => this.logger.warn(`A run-settled listener failed: ${e.message}`));
|
|
508
|
+
},
|
|
356
509
|
log: {
|
|
357
510
|
info: (m) => this.logger.log(m),
|
|
358
511
|
warn: (m) => this.logger.warn(m),
|
|
359
512
|
error: (m, e) => this.logger.error(m, e),
|
|
360
513
|
},
|
|
361
514
|
});
|
|
515
|
+
admission?.attach({
|
|
516
|
+
drain: (on) => this.dispatcher.drain(on),
|
|
517
|
+
running: () => this.dispatcher.running,
|
|
518
|
+
});
|
|
362
519
|
}
|
|
363
520
|
async resolveHarness(requested = {}) {
|
|
364
521
|
const [selection, settings] = await Promise.all([
|
|
@@ -404,14 +561,24 @@ let DispatchService = DispatchService_1 = class DispatchService {
|
|
|
404
561
|
}
|
|
405
562
|
await this.telemetry.captureFinished(id, status, { startedAt: investigation?.startedAt, error: investigation?.error });
|
|
406
563
|
}
|
|
564
|
+
settledListeners = [];
|
|
565
|
+
onRunSettled(listener) {
|
|
566
|
+
this.settledListeners.push(listener);
|
|
567
|
+
}
|
|
407
568
|
async onModuleInit() {
|
|
569
|
+
const boot = await this.bootContext().catch((e) => {
|
|
570
|
+
this.logger.warn(`Could not read the runs a stop cut off: ${e.message}`);
|
|
571
|
+
return null;
|
|
572
|
+
});
|
|
408
573
|
await this.denyAsksLeftWaiting().catch((e) => this.logger.warn(`Could not settle asks left waiting at boot: ${e.message}`));
|
|
409
574
|
await this.markQueuedLeftWaiting().catch((e) => this.logger.warn(`Could not settle messages left queued at boot: ${e.message}`));
|
|
410
575
|
const ids = await this.store.failRunning(RESTART_REASON);
|
|
411
576
|
if (ids.length > 0) {
|
|
412
577
|
this.logger.warn(`Failed ${ids.length} investigation(s) left running by a previous process: ${ids.join(", ")}`);
|
|
413
578
|
}
|
|
414
|
-
await this.reconcileLiveRows(new Set(ids)).catch((e) => this.logger.warn(`Could not reconcile live runs at boot: ${e.message}`));
|
|
579
|
+
await this.reconcileLiveRows(new Set(ids), boot).catch((e) => this.logger.warn(`Could not reconcile live runs at boot: ${e.message}`));
|
|
580
|
+
const checked = boot ? await this.checkRecoveries(boot) : true;
|
|
581
|
+
await this.releaseEndedLeases(boot);
|
|
415
582
|
await this.runWorkspaces?.ready();
|
|
416
583
|
try {
|
|
417
584
|
const interrupted = await interruptedRunIds(this.prisma);
|
|
@@ -421,7 +588,7 @@ let DispatchService = DispatchService_1 = class DispatchService {
|
|
|
421
588
|
});
|
|
422
589
|
const liveIds = new Set(live.map((r) => r.id));
|
|
423
590
|
const swept = await sweepRunWorkspaces({
|
|
424
|
-
isLive: (id) => liveIds.has(id),
|
|
591
|
+
isLive: (id) => liveIds.has(id) || !!boot?.keep.has(id),
|
|
425
592
|
isInterrupted: (id) => interrupted.has(id),
|
|
426
593
|
});
|
|
427
594
|
if (swept > 0)
|
|
@@ -430,13 +597,36 @@ let DispatchService = DispatchService_1 = class DispatchService {
|
|
|
430
597
|
catch (e) {
|
|
431
598
|
this.logger.warn("Could not sweep leftover run workspaces", e);
|
|
432
599
|
}
|
|
600
|
+
if (boot)
|
|
601
|
+
await this.writeRestartSummary(boot).catch((e) => this.logger.warn(`Could not record what this start resumed: ${e.message}`));
|
|
602
|
+
if (!checked && boot) {
|
|
603
|
+
this.dispatcher.hold();
|
|
604
|
+
this.recheckTimer = setInterval(() => {
|
|
605
|
+
void this.checkRecoveries(boot).then((ok) => {
|
|
606
|
+
if (!ok)
|
|
607
|
+
return;
|
|
608
|
+
clearInterval(this.recheckTimer);
|
|
609
|
+
this.dispatcher.unhold();
|
|
610
|
+
this.recoveryWake = setTimeout(() => void this.dispatcher.tick(), RECOVERY_DELAY_MS + 1_000).unref();
|
|
611
|
+
});
|
|
612
|
+
}, RECHECK_MS).unref();
|
|
613
|
+
}
|
|
433
614
|
this.dispatcher.start();
|
|
615
|
+
if (boot?.resumed.length)
|
|
616
|
+
this.recoveryWake = setTimeout(() => void this.dispatcher.tick(), RECOVERY_DELAY_MS + 1_000).unref();
|
|
434
617
|
this.logger.log(`Dispatch loop started, concurrency cap ${getConfig().PRISMALENS_DISPATCH_CONCURRENCY}, owner ${this.dispatcher.ownerToken}`);
|
|
435
618
|
}
|
|
436
619
|
async onApplicationShutdown() {
|
|
620
|
+
clearTimeout(this.recoveryWake);
|
|
621
|
+
clearInterval(this.recheckTimer);
|
|
622
|
+
clearTimeout(this.leaseRetry);
|
|
437
623
|
await this.dispatcher.stop();
|
|
438
624
|
reapLiveHarnesses();
|
|
439
625
|
}
|
|
626
|
+
startAdmitted(investigationId) {
|
|
627
|
+
this.streamRelay.attach(investigationId);
|
|
628
|
+
void this.dispatcher.tick();
|
|
629
|
+
}
|
|
440
630
|
async addInvestigationJob(data) {
|
|
441
631
|
try {
|
|
442
632
|
const jobId = await this.store.enqueue({
|
|
@@ -455,13 +645,14 @@ let DispatchService = DispatchService_1 = class DispatchService {
|
|
|
455
645
|
return null;
|
|
456
646
|
}
|
|
457
647
|
}
|
|
458
|
-
async reconcileLiveRows(wasRunning) {
|
|
648
|
+
async reconcileLiveRows(wasRunning, boot = null) {
|
|
459
649
|
await this.settleJobsOfEndedRows(wasRunning);
|
|
460
650
|
const rows = await this.prisma.investigation.findMany({
|
|
461
651
|
where: { status: { in: [...LIVE_WORKFLOW_STATUSES] } },
|
|
462
652
|
select: {
|
|
463
653
|
id: true,
|
|
464
654
|
incidentId: true,
|
|
655
|
+
scheduleId: true,
|
|
465
656
|
kind: true,
|
|
466
657
|
stopRequestedAt: true,
|
|
467
658
|
createdAt: true,
|
|
@@ -480,18 +671,30 @@ let DispatchService = DispatchService_1 = class DispatchService {
|
|
|
480
671
|
}
|
|
481
672
|
const stopped = !!row.stopRequestedAt ||
|
|
482
673
|
(!wasRunning.has(row.id) && job?.status === "cancelled");
|
|
674
|
+
if (!stopped && job && boot) {
|
|
675
|
+
const verdict = await this.tryRecover(row.id, boot).catch((e) => `it could not be prepared: ${e.message}`);
|
|
676
|
+
if (verdict === true) {
|
|
677
|
+
waiting.push(row);
|
|
678
|
+
continue;
|
|
679
|
+
}
|
|
680
|
+
if (verdict !== null) {
|
|
681
|
+
boot.skipped.push({ id: row.id, reason: verdict });
|
|
682
|
+
boot.keep.add(row.id);
|
|
683
|
+
await this.endAtBoot(row, job, false, undefined, verdict).catch((e) => this.logger.warn(`Could not settle run ${row.id} at boot: ${e.message}`));
|
|
684
|
+
continue;
|
|
685
|
+
}
|
|
686
|
+
}
|
|
483
687
|
await this.endAtBoot(row, job, stopped).catch((e) => this.logger.warn(`Could not settle run ${row.id} at boot: ${e.message}`));
|
|
484
688
|
}
|
|
485
|
-
const
|
|
486
|
-
for (const row of waiting)
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
for (const [incidentId, live] of byIncident) {
|
|
689
|
+
const byScope = new Map();
|
|
690
|
+
for (const row of waiting) {
|
|
691
|
+
const key = runScopeKey(row);
|
|
692
|
+
byScope.set(key, [...(byScope.get(key) ?? []), row]);
|
|
693
|
+
}
|
|
694
|
+
for (const [scope, live] of byScope) {
|
|
492
695
|
if (live.length < 2)
|
|
493
696
|
continue;
|
|
494
|
-
this.logger.warn(
|
|
697
|
+
this.logger.warn(`${scope} had ${live.length} live runs; keeping the newest`);
|
|
495
698
|
for (const row of live.slice(0, -1)) {
|
|
496
699
|
await this.cancelPendingJob(row.id);
|
|
497
700
|
const job = await this.prisma.job.findUnique({
|
|
@@ -517,37 +720,43 @@ let DispatchService = DispatchService_1 = class DispatchService {
|
|
|
517
720
|
const events = await this.prisma.investigationEvent.findMany({
|
|
518
721
|
where: {
|
|
519
722
|
investigationId: id,
|
|
520
|
-
|
|
723
|
+
OR: [
|
|
724
|
+
{ event: { contains: '"kind":"permission_' } },
|
|
725
|
+
{ event: { contains: '"kind":"ask_' } },
|
|
726
|
+
],
|
|
521
727
|
},
|
|
522
728
|
orderBy: { seq: "asc" },
|
|
523
729
|
select: { event: true },
|
|
524
730
|
});
|
|
525
|
-
const
|
|
526
|
-
|
|
527
|
-
const parsed = CanonicalEventSchema.safeParse(JSON.parse(row.event));
|
|
528
|
-
const e = parsed.success ? parsed.data : null;
|
|
529
|
-
if (e?.kind === "permission_ask")
|
|
530
|
-
open.set(e.askId, e.branchId);
|
|
531
|
-
else if (e?.kind === "permission_answer")
|
|
532
|
-
open.delete(e.askId);
|
|
533
|
-
}
|
|
534
|
-
if (open.size === 0 && !awaitingApprovalAt)
|
|
731
|
+
const { legacy, asks } = asksLeftOpen(parseEventRows(events));
|
|
732
|
+
if (legacy.length + asks.length === 0 && !awaitingApprovalAt)
|
|
535
733
|
continue;
|
|
536
|
-
if (
|
|
734
|
+
if (legacy.length + asks.length > 0)
|
|
537
735
|
denied++;
|
|
538
736
|
let seq = (await this.investigationsService.lastEventSeq(id)) + 1;
|
|
539
737
|
const ts = new Date().toISOString();
|
|
540
|
-
|
|
541
|
-
kind: "permission_answer",
|
|
738
|
+
const at = (branchId) => ({
|
|
542
739
|
runId: id,
|
|
543
740
|
branchId,
|
|
544
741
|
path: [],
|
|
545
742
|
seq: seq++,
|
|
546
743
|
label: null,
|
|
547
744
|
ts,
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
745
|
+
});
|
|
746
|
+
await this.investigationsService.appendEvents(id, [
|
|
747
|
+
...legacy.map(({ askId, branchId }) => ({
|
|
748
|
+
kind: "permission_answer",
|
|
749
|
+
...at(branchId),
|
|
750
|
+
askId,
|
|
751
|
+
outcome: "restarted",
|
|
752
|
+
})),
|
|
753
|
+
...asks.map(({ askId, branchId }) => ({
|
|
754
|
+
kind: "ask_closed",
|
|
755
|
+
...at(branchId),
|
|
756
|
+
askId,
|
|
757
|
+
outcome: "restarted",
|
|
758
|
+
})),
|
|
759
|
+
]);
|
|
551
760
|
await this.prisma.investigation.update({
|
|
552
761
|
where: { id },
|
|
553
762
|
data: { awaitingApprovalAt: null },
|
|
@@ -567,20 +776,12 @@ let DispatchService = DispatchService_1 = class DispatchService {
|
|
|
567
776
|
orderBy: { seq: "asc" },
|
|
568
777
|
select: { event: true },
|
|
569
778
|
});
|
|
570
|
-
const open =
|
|
571
|
-
|
|
572
|
-
const parsed = CanonicalEventSchema.safeParse(JSON.parse(row.event));
|
|
573
|
-
const e = parsed.success ? parsed.data : null;
|
|
574
|
-
if (e?.kind === "message_queued")
|
|
575
|
-
open.set(e.messageId, e);
|
|
576
|
-
else if (e?.kind === "operator_message" && e.messageId)
|
|
577
|
-
open.delete(e.messageId);
|
|
578
|
-
}
|
|
579
|
-
if (open.size === 0)
|
|
779
|
+
const open = queuedLeftWaiting(parseEventRows(events));
|
|
780
|
+
if (open.length === 0)
|
|
580
781
|
continue;
|
|
581
782
|
let seq = (await this.investigationsService.lastEventSeq(id)) + 1;
|
|
582
783
|
const ts = new Date().toISOString();
|
|
583
|
-
await this.investigationsService.appendEvents(id,
|
|
784
|
+
await this.investigationsService.appendEvents(id, open.map((q) => ({
|
|
584
785
|
kind: "operator_message",
|
|
585
786
|
runId: id,
|
|
586
787
|
branchId: q.branchId,
|
|
@@ -593,6 +794,8 @@ let DispatchService = DispatchService_1 = class DispatchService {
|
|
|
593
794
|
delivered: false,
|
|
594
795
|
messageId: q.messageId,
|
|
595
796
|
...(q.attachments?.length ? { attachments: q.attachments } : {}),
|
|
797
|
+
...(q.quotes?.length ? { quotes: q.quotes } : {}),
|
|
798
|
+
...(q.references?.length ? { references: q.references } : {}),
|
|
596
799
|
})));
|
|
597
800
|
}
|
|
598
801
|
}
|
|
@@ -636,13 +839,26 @@ let DispatchService = DispatchService_1 = class DispatchService {
|
|
|
636
839
|
});
|
|
637
840
|
}
|
|
638
841
|
}
|
|
639
|
-
async endAtBoot(row, job, stopped, reason = job ? RESTART_REASON : UNQUEUED_REASON) {
|
|
842
|
+
async endAtBoot(row, job, stopped, reason = job ? RESTART_REASON : UNQUEUED_REASON, notResumed) {
|
|
640
843
|
if (job && jobResume(job.payload)) {
|
|
641
|
-
await this.restoreFollowUp(row.id,
|
|
844
|
+
await this.restoreFollowUp(row.id, notResumed
|
|
845
|
+
? `${FOLLOW_UP_RESTART_REASON} ${NOT_RESUMED}${notResumed}`
|
|
846
|
+
: FOLLOW_UP_RESTART_REASON, stopped ? "stopped" : "error");
|
|
847
|
+
if (notResumed)
|
|
848
|
+
await this.prisma.investigation.updateMany({
|
|
849
|
+
where: { id: row.id, status: "failed", endReason: "interrupted" },
|
|
850
|
+
data: { error: `${NOT_RESUMED}${notResumed}` },
|
|
851
|
+
});
|
|
642
852
|
}
|
|
643
853
|
else {
|
|
644
854
|
const chat = row.kind === "chat";
|
|
645
|
-
await this.investigationsService.updateStatusInternal(row.id, stopped ? "cancelled" : "failed", undefined, stopped
|
|
855
|
+
await this.investigationsService.updateStatusInternal(row.id, stopped ? "cancelled" : "failed", undefined, stopped
|
|
856
|
+
? chat
|
|
857
|
+
? "Chat stopped"
|
|
858
|
+
: "Investigation cancelled"
|
|
859
|
+
: notResumed
|
|
860
|
+
? `${NOT_RESUMED}${notResumed}`
|
|
861
|
+
: reason, undefined, stopped || !job ? undefined : { endReason: "interrupted" });
|
|
646
862
|
}
|
|
647
863
|
if (stopped && job && job.status !== "cancelled")
|
|
648
864
|
await this.prisma.job.updateMany({
|
|
@@ -655,11 +871,15 @@ let DispatchService = DispatchService_1 = class DispatchService {
|
|
|
655
871
|
},
|
|
656
872
|
});
|
|
657
873
|
}
|
|
658
|
-
async resumeInvestigation(id, text, mode, kind = "chat", attachments = [], to = {}) {
|
|
874
|
+
async resumeInvestigation(id, text, mode, kind = "chat", attachments = [], to = {}, context, session = {}) {
|
|
659
875
|
const row = await this.prisma.investigation.findUnique({
|
|
660
876
|
where: { id },
|
|
661
877
|
select: {
|
|
662
878
|
incidentId: true,
|
|
879
|
+
scheduleId: true,
|
|
880
|
+
serviceId: true,
|
|
881
|
+
repositoryId: true,
|
|
882
|
+
configSnapshot: true,
|
|
663
883
|
status: true,
|
|
664
884
|
completedAt: true,
|
|
665
885
|
error: true,
|
|
@@ -688,14 +908,11 @@ let DispatchService = DispatchService_1 = class DispatchService {
|
|
|
688
908
|
if (row.status !== "cancelled" && row.status !== "failed")
|
|
689
909
|
throw new FollowUpRefused("Only a stopped or failed run can be continued.");
|
|
690
910
|
}
|
|
911
|
+
const checkout = await this.borrowedCheckout(id, row.repositoryId);
|
|
912
|
+
if (checkout)
|
|
913
|
+
await this.freeCheckout(checkout);
|
|
691
914
|
const accessLevel = await this.followUpLevel(row);
|
|
692
|
-
const sawEvidence = kind === "continue" &&
|
|
693
|
-
(await this.prisma.investigationEvent.count({
|
|
694
|
-
where: {
|
|
695
|
-
investigationId: id,
|
|
696
|
-
event: { contains: '"kind":"tool_result"' },
|
|
697
|
-
},
|
|
698
|
-
})) > 0;
|
|
915
|
+
const sawEvidence = kind === "continue" && (await this.hasToolResult(id));
|
|
699
916
|
const restore = {
|
|
700
917
|
status: row.status,
|
|
701
918
|
completedAt: row.completedAt?.toISOString() ?? null,
|
|
@@ -704,6 +921,15 @@ let DispatchService = DispatchService_1 = class DispatchService {
|
|
|
704
921
|
const data = {
|
|
705
922
|
incidentId: row.incidentId,
|
|
706
923
|
investigationId: id,
|
|
924
|
+
startedBy: row.triggerType === "scheduled"
|
|
925
|
+
? "schedule"
|
|
926
|
+
: startedByAlert(row.triggerType)
|
|
927
|
+
? "alert"
|
|
928
|
+
: "person",
|
|
929
|
+
...(row.incidentId ? {} : serviceCheckOf(row.configSnapshot)),
|
|
930
|
+
...(row.incidentId || row.scheduleId
|
|
931
|
+
? {}
|
|
932
|
+
: { thread: await this.threadRunOf(row) }),
|
|
707
933
|
...(accessLevel ? { accessLevel } : {}),
|
|
708
934
|
resume: {
|
|
709
935
|
text,
|
|
@@ -712,27 +938,43 @@ let DispatchService = DispatchService_1 = class DispatchService {
|
|
|
712
938
|
kind,
|
|
713
939
|
...(kind === "continue" ? { sawEvidence } : {}),
|
|
714
940
|
...(attachments.length ? { attachments } : {}),
|
|
941
|
+
...(context ? { context } : {}),
|
|
715
942
|
to: { ...to, harness: plan.harness },
|
|
716
|
-
...(plan.route === "handoff" ? { handoff: true } : {}),
|
|
943
|
+
...(plan.route === "handoff" || session.fresh ? { handoff: true } : {}),
|
|
944
|
+
...(session.fresh ? { fresh: true } : {}),
|
|
945
|
+
...(session.compact && !session.fresh
|
|
946
|
+
? { compact: session.compact }
|
|
947
|
+
: {}),
|
|
948
|
+
...(session.wakeId
|
|
949
|
+
? { wakeId: session.wakeId, messageId: session.wakeId }
|
|
950
|
+
: {}),
|
|
951
|
+
...(session.delivers?.length ? { delivers: session.delivers } : {}),
|
|
717
952
|
...((await this.afterRestart(id, row.endReason))
|
|
718
953
|
? { afterRestart: true }
|
|
719
954
|
: {}),
|
|
720
955
|
},
|
|
721
956
|
};
|
|
722
|
-
const admitted = await this.prisma
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
957
|
+
const admitted = await this.prisma
|
|
958
|
+
.$transaction(async (tx) => {
|
|
959
|
+
const other = sharesAdmission(row)
|
|
960
|
+
? await tx.investigation.findFirst({
|
|
961
|
+
where: {
|
|
962
|
+
...runScope(row),
|
|
963
|
+
id: { not: id },
|
|
964
|
+
status: { in: [...LIVE_WORKFLOW_STATUSES] },
|
|
965
|
+
},
|
|
966
|
+
orderBy: { createdAt: "desc" },
|
|
967
|
+
select: { createdAt: true },
|
|
968
|
+
})
|
|
969
|
+
: null;
|
|
970
|
+
if (row.repositoryId && (await folderBusy(tx, row.repositoryId, id)))
|
|
971
|
+
throw new FollowUpRefused(FOLDER_BUSY);
|
|
972
|
+
if (checkout)
|
|
973
|
+
await this.leaseIn(tx, checkout, id);
|
|
732
974
|
if (other) {
|
|
733
975
|
const n = await tx.investigation.count({
|
|
734
976
|
where: {
|
|
735
|
-
|
|
977
|
+
...runScope(row),
|
|
736
978
|
createdAt: { lte: other.createdAt },
|
|
737
979
|
},
|
|
738
980
|
});
|
|
@@ -750,6 +992,14 @@ let DispatchService = DispatchService_1 = class DispatchService {
|
|
|
750
992
|
});
|
|
751
993
|
if (count === 0)
|
|
752
994
|
return false;
|
|
995
|
+
if (session.wakeId) {
|
|
996
|
+
const taken = await tx.threadWake.updateMany({
|
|
997
|
+
where: { id: session.wakeId, state: "pending" },
|
|
998
|
+
data: { state: "done", doneAt: session.wakeDoneAt ?? new Date() },
|
|
999
|
+
});
|
|
1000
|
+
if (taken.count === 0)
|
|
1001
|
+
throw new WakeTaken();
|
|
1002
|
+
}
|
|
753
1003
|
await new PrismaJobStore(tx.job).enqueue({
|
|
754
1004
|
investigationId: id,
|
|
755
1005
|
incidentId: row.incidentId,
|
|
@@ -757,6 +1007,11 @@ let DispatchService = DispatchService_1 = class DispatchService {
|
|
|
757
1007
|
priority: PRIORITY_ORDER.normal ?? 3,
|
|
758
1008
|
});
|
|
759
1009
|
return true;
|
|
1010
|
+
}, FOLDER_TX)
|
|
1011
|
+
.catch((e) => {
|
|
1012
|
+
if (e instanceof WakeTaken)
|
|
1013
|
+
return false;
|
|
1014
|
+
throw e;
|
|
760
1015
|
});
|
|
761
1016
|
if (!admitted)
|
|
762
1017
|
return false;
|
|
@@ -764,6 +1019,148 @@ let DispatchService = DispatchService_1 = class DispatchService {
|
|
|
764
1019
|
void this.dispatcher.tick();
|
|
765
1020
|
return true;
|
|
766
1021
|
}
|
|
1022
|
+
async borrowedCheckout(id, repositoryId) {
|
|
1023
|
+
const recorded = await this.recordedCheckout(id);
|
|
1024
|
+
if (!recorded)
|
|
1025
|
+
return null;
|
|
1026
|
+
const repo = repositoryId
|
|
1027
|
+
? await this.prisma.repository.findUnique({
|
|
1028
|
+
where: { id: repositoryId },
|
|
1029
|
+
select: { url: true },
|
|
1030
|
+
})
|
|
1031
|
+
: null;
|
|
1032
|
+
const now = repo
|
|
1033
|
+
? await checkoutRoot(repo.url).catch((e) => {
|
|
1034
|
+
if (e instanceof CheckoutUnreadable)
|
|
1035
|
+
throw new FollowUpRefused(e.message);
|
|
1036
|
+
throw e;
|
|
1037
|
+
})
|
|
1038
|
+
: null;
|
|
1039
|
+
if (!now || !sameCheckout(now, recorded))
|
|
1040
|
+
throw new CheckoutGone(checkoutGoneReason(recorded));
|
|
1041
|
+
return recorded;
|
|
1042
|
+
}
|
|
1043
|
+
async recordedCheckout(id) {
|
|
1044
|
+
const inv = await this.prisma.investigation.findUnique({
|
|
1045
|
+
where: { id },
|
|
1046
|
+
select: { workspace: true },
|
|
1047
|
+
});
|
|
1048
|
+
let ws;
|
|
1049
|
+
try {
|
|
1050
|
+
ws = inv?.workspace
|
|
1051
|
+
? RunWorkspaceSchema.safeParse(JSON.parse(inv.workspace)).data
|
|
1052
|
+
: undefined;
|
|
1053
|
+
}
|
|
1054
|
+
catch {
|
|
1055
|
+
ws = undefined;
|
|
1056
|
+
}
|
|
1057
|
+
if (ws)
|
|
1058
|
+
return ws.layout === "in_place" ? (ws.borrowed?.path ?? null) : null;
|
|
1059
|
+
return leasedBy(this.prisma, id);
|
|
1060
|
+
}
|
|
1061
|
+
async abandonUnstarted(investigationId, error) {
|
|
1062
|
+
if (await this.store.findByInvestigation(investigationId))
|
|
1063
|
+
return;
|
|
1064
|
+
await this.prisma.investigation.updateMany({
|
|
1065
|
+
where: {
|
|
1066
|
+
id: investigationId,
|
|
1067
|
+
status: { in: [...LIVE_WORKFLOW_STATUSES] },
|
|
1068
|
+
},
|
|
1069
|
+
data: { status: "failed", error, completedAt: new Date() },
|
|
1070
|
+
});
|
|
1071
|
+
await releaseLease(this.prisma, investigationId);
|
|
1072
|
+
}
|
|
1073
|
+
async releaseEndedLeases(boot) {
|
|
1074
|
+
const { released, failed } = await releaseIfGone(this.prisma, async (id, session, signal) => boot?.contained.get(id) ?? this.previousGone(id, session, signal)).catch((e) => {
|
|
1075
|
+
this.logger.warn(`Could not release ended checkout leases: ${e.message}`);
|
|
1076
|
+
return { released: 0, failed: 1 };
|
|
1077
|
+
});
|
|
1078
|
+
if (released > 0)
|
|
1079
|
+
this.logger.log(`Released ${released} checkout lease(s) of ended runs`);
|
|
1080
|
+
if (failed > 0) {
|
|
1081
|
+
this.logger.warn(`Could not release ${failed} checkout lease(s); retrying in a minute`);
|
|
1082
|
+
clearTimeout(this.leaseRetry);
|
|
1083
|
+
this.leaseRetry = setTimeout(() => void this.releaseEndedLeases(null), LEASE_RETRY_MS);
|
|
1084
|
+
this.leaseRetry.unref?.();
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
async freeCheckout(path) {
|
|
1088
|
+
await releaseIfGone(this.prisma, (id, session, signal) => this.previousGone(id, session, signal), path);
|
|
1089
|
+
}
|
|
1090
|
+
async leaseIn(tx, checkout, id) {
|
|
1091
|
+
if (await checkoutBusy(tx, checkout, id))
|
|
1092
|
+
throw new FollowUpRefused(await busyReason(tx, checkout, id));
|
|
1093
|
+
await takeLease(tx, checkout, id);
|
|
1094
|
+
}
|
|
1095
|
+
async threadRunOf(row) {
|
|
1096
|
+
const repoFields = {
|
|
1097
|
+
sourceKind: true,
|
|
1098
|
+
url: true,
|
|
1099
|
+
defaultBranch: true,
|
|
1100
|
+
connectionId: true,
|
|
1101
|
+
fullName: true,
|
|
1102
|
+
subPath: true,
|
|
1103
|
+
plain: true,
|
|
1104
|
+
};
|
|
1105
|
+
const ref = (r, subPath, serviceName) => ({
|
|
1106
|
+
sourceKind: r.sourceKind === "folder" ? "folder" : "url",
|
|
1107
|
+
url: r.url,
|
|
1108
|
+
defaultBranch: r.defaultBranch,
|
|
1109
|
+
subPath,
|
|
1110
|
+
connectionId: r.connectionId,
|
|
1111
|
+
serviceName,
|
|
1112
|
+
});
|
|
1113
|
+
if (row.repositoryId) {
|
|
1114
|
+
const repo = await this.prisma.repository.findUnique({
|
|
1115
|
+
where: { id: row.repositoryId },
|
|
1116
|
+
select: repoFields,
|
|
1117
|
+
});
|
|
1118
|
+
if (repo) {
|
|
1119
|
+
const name = shownFullName(repo);
|
|
1120
|
+
return {
|
|
1121
|
+
subject: "project",
|
|
1122
|
+
repositoryId: row.repositoryId,
|
|
1123
|
+
serviceId: null,
|
|
1124
|
+
name,
|
|
1125
|
+
repos: [
|
|
1126
|
+
{
|
|
1127
|
+
...ref(repo, repo.subPath, name),
|
|
1128
|
+
...(repo.plain ? { plain: true } : {}),
|
|
1129
|
+
},
|
|
1130
|
+
],
|
|
1131
|
+
};
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
if (row.serviceId) {
|
|
1135
|
+
const service = await this.prisma.service.findUnique({
|
|
1136
|
+
where: { id: row.serviceId },
|
|
1137
|
+
select: {
|
|
1138
|
+
name: true,
|
|
1139
|
+
repositories: {
|
|
1140
|
+
orderBy: [{ isPrimary: "desc" }, { createdAt: "asc" }],
|
|
1141
|
+
select: { subPath: true, repository: { select: repoFields } },
|
|
1142
|
+
},
|
|
1143
|
+
},
|
|
1144
|
+
});
|
|
1145
|
+
if (service)
|
|
1146
|
+
return {
|
|
1147
|
+
subject: "service",
|
|
1148
|
+
repositoryId: null,
|
|
1149
|
+
serviceId: row.serviceId,
|
|
1150
|
+
name: service.name,
|
|
1151
|
+
repos: service.repositories.map((r) => ref(r.repository, r.subPath, service.name)),
|
|
1152
|
+
};
|
|
1153
|
+
}
|
|
1154
|
+
const place = HelperPlaceSchema.safeParse(row.helperPlace).data;
|
|
1155
|
+
return {
|
|
1156
|
+
subject: "none",
|
|
1157
|
+
repositoryId: null,
|
|
1158
|
+
serviceId: null,
|
|
1159
|
+
name: null,
|
|
1160
|
+
repos: [],
|
|
1161
|
+
...(place ? { place } : {}),
|
|
1162
|
+
};
|
|
1163
|
+
}
|
|
767
1164
|
async followUpLevel(row) {
|
|
768
1165
|
const alertHarness = startedByAlert(row.triggerType) &&
|
|
769
1166
|
HARNESS_IDS.find((h) => h === row.harness);
|
|
@@ -797,12 +1194,13 @@ let DispatchService = DispatchService_1 = class DispatchService {
|
|
|
797
1194
|
preflight: handoffPreflight(plan.harness, selection, this.harnessService.checkedOutcome(plan.harness)),
|
|
798
1195
|
};
|
|
799
1196
|
}
|
|
800
|
-
sendMessage(investigationId, text, mode, attachments = [], kind, id) {
|
|
1197
|
+
sendMessage(investigationId, text, mode, attachments = [], kind, id, context) {
|
|
801
1198
|
let state = null;
|
|
802
1199
|
this.bus.publish(runMessageTopic(investigationId), {
|
|
803
1200
|
text,
|
|
804
1201
|
mode,
|
|
805
1202
|
attachments,
|
|
1203
|
+
...(context ? { context } : {}),
|
|
806
1204
|
...(kind ? { kind } : {}),
|
|
807
1205
|
...(id ? { id } : {}),
|
|
808
1206
|
reply: (s) => {
|
|
@@ -811,16 +1209,37 @@ let DispatchService = DispatchService_1 = class DispatchService {
|
|
|
811
1209
|
});
|
|
812
1210
|
return state;
|
|
813
1211
|
}
|
|
814
|
-
answerAsk(investigationId, askId,
|
|
815
|
-
let
|
|
1212
|
+
answerAsk(investigationId, askId, answer) {
|
|
1213
|
+
let result = null;
|
|
816
1214
|
this.bus.publish(runAskTopic(investigationId), {
|
|
817
1215
|
askId,
|
|
818
|
-
|
|
819
|
-
reply: (
|
|
820
|
-
|
|
1216
|
+
answer,
|
|
1217
|
+
reply: (r) => {
|
|
1218
|
+
result = r;
|
|
1219
|
+
},
|
|
1220
|
+
});
|
|
1221
|
+
return result;
|
|
1222
|
+
}
|
|
1223
|
+
cancelSubagent(investigationId, sessionId) {
|
|
1224
|
+
let result = null;
|
|
1225
|
+
this.bus.publish(runSubagentTopic(investigationId), {
|
|
1226
|
+
sessionId,
|
|
1227
|
+
reply: (r) => {
|
|
1228
|
+
result = r;
|
|
1229
|
+
},
|
|
1230
|
+
});
|
|
1231
|
+
return result;
|
|
1232
|
+
}
|
|
1233
|
+
changeQueued(investigationId, messageId, text) {
|
|
1234
|
+
let state = null;
|
|
1235
|
+
this.bus.publish(runQueueTopic(investigationId), {
|
|
1236
|
+
messageId,
|
|
1237
|
+
text,
|
|
1238
|
+
reply: (s) => {
|
|
1239
|
+
state = s;
|
|
821
1240
|
},
|
|
822
1241
|
});
|
|
823
|
-
return
|
|
1242
|
+
return state;
|
|
824
1243
|
}
|
|
825
1244
|
async requestCancel(investigationId) {
|
|
826
1245
|
const receivers = this.bus.publish(runCancelTopic(investigationId), {
|
|
@@ -829,6 +1248,462 @@ let DispatchService = DispatchService_1 = class DispatchService {
|
|
|
829
1248
|
this.logger.log(`Published cancel for investigation ${investigationId} (${receivers} receiver(s))`);
|
|
830
1249
|
return receivers;
|
|
831
1250
|
}
|
|
1251
|
+
async bootContext() {
|
|
1252
|
+
const now = new Date();
|
|
1253
|
+
const live = await this.prisma.investigation.findMany({
|
|
1254
|
+
where: { status: { in: [...LIVE_WORKFLOW_STATUSES] } },
|
|
1255
|
+
select: { id: true, acpSessionId: true },
|
|
1256
|
+
});
|
|
1257
|
+
const activity = new Map();
|
|
1258
|
+
const agentSeen = new Map();
|
|
1259
|
+
const contained = new Map();
|
|
1260
|
+
const keep = new Set();
|
|
1261
|
+
for (const { id, acpSessionId } of live) {
|
|
1262
|
+
const seen = await this.lastActivity(id);
|
|
1263
|
+
activity.set(id, seen.at);
|
|
1264
|
+
agentSeen.set(id, seen.agent);
|
|
1265
|
+
const gone = await this.previousGone(id, acpSessionId);
|
|
1266
|
+
contained.set(id, gone);
|
|
1267
|
+
if (!gone)
|
|
1268
|
+
keep.add(id);
|
|
1269
|
+
}
|
|
1270
|
+
const interrupted = await this.prisma.investigation.findMany({
|
|
1271
|
+
where: {
|
|
1272
|
+
endReason: "interrupted",
|
|
1273
|
+
status: { notIn: [...LIVE_WORKFLOW_STATUSES] },
|
|
1274
|
+
incident: { status: { notIn: [...ENDED_INCIDENT_STATUSES] } },
|
|
1275
|
+
},
|
|
1276
|
+
select: { id: true },
|
|
1277
|
+
});
|
|
1278
|
+
for (const { id } of interrupted)
|
|
1279
|
+
keep.add(id);
|
|
1280
|
+
const prev = this.lifecycle?.lastRestart()?.previous ?? null;
|
|
1281
|
+
const last = await this.restartSummary().catch(() => null);
|
|
1282
|
+
const bootLoop = !!prev &&
|
|
1283
|
+
prev.lastAliveAt.getTime() - prev.startedAt.getTime() < BOOT_LOOP_MS &&
|
|
1284
|
+
!!last &&
|
|
1285
|
+
last.resumed.length > 0 &&
|
|
1286
|
+
Date.parse(last.at) >= prev.startedAt.getTime() - 5_000;
|
|
1287
|
+
const latest = Math.max(0, ...[...activity.values()].map((d) => d.getTime()));
|
|
1288
|
+
return {
|
|
1289
|
+
now,
|
|
1290
|
+
stoppedAt: prev?.lastAliveAt ?? (latest ? new Date(latest) : now),
|
|
1291
|
+
bootLoop,
|
|
1292
|
+
enabled: await this.harnessService.resumeAfterRestart().catch(() => true),
|
|
1293
|
+
activity,
|
|
1294
|
+
agentSeen,
|
|
1295
|
+
contained,
|
|
1296
|
+
keep,
|
|
1297
|
+
resumed: [],
|
|
1298
|
+
skipped: [],
|
|
1299
|
+
};
|
|
1300
|
+
}
|
|
1301
|
+
async previousGone(id, acpSessionId, signal) {
|
|
1302
|
+
const receipt = readReceipt(runDirFor(id));
|
|
1303
|
+
if (!receipt)
|
|
1304
|
+
return !acpSessionId;
|
|
1305
|
+
return containPrevious(receipt, undefined, signal).catch(() => false);
|
|
1306
|
+
}
|
|
1307
|
+
async hasToolResult(id) {
|
|
1308
|
+
return ((await this.prisma.investigationEvent.count({
|
|
1309
|
+
where: {
|
|
1310
|
+
investigationId: id,
|
|
1311
|
+
event: { contains: '"kind":"tool_result"' },
|
|
1312
|
+
},
|
|
1313
|
+
})) > 0);
|
|
1314
|
+
}
|
|
1315
|
+
async lastActivity(id) {
|
|
1316
|
+
const last = await this.prisma.investigationEvent.findFirst({
|
|
1317
|
+
where: {
|
|
1318
|
+
investigationId: id,
|
|
1319
|
+
OR: AGENT_KINDS.map((k) => ({ event: { contains: `"kind":"${k}"` } })),
|
|
1320
|
+
},
|
|
1321
|
+
orderBy: { createdAt: "desc" },
|
|
1322
|
+
select: { createdAt: true },
|
|
1323
|
+
});
|
|
1324
|
+
const [job, inv] = await Promise.all([
|
|
1325
|
+
this.prisma.job.findUnique({
|
|
1326
|
+
where: { investigationId: id },
|
|
1327
|
+
select: { claimedAt: true },
|
|
1328
|
+
}),
|
|
1329
|
+
this.prisma.investigation.findUnique({
|
|
1330
|
+
where: { id },
|
|
1331
|
+
select: { createdAt: true },
|
|
1332
|
+
}),
|
|
1333
|
+
]);
|
|
1334
|
+
const agent = last?.createdAt ?? null;
|
|
1335
|
+
return {
|
|
1336
|
+
agent,
|
|
1337
|
+
at: agent ?? job?.claimedAt ?? inv?.createdAt ?? new Date(0),
|
|
1338
|
+
};
|
|
1339
|
+
}
|
|
1340
|
+
async tryRecover(id, boot) {
|
|
1341
|
+
const found = await this.recoverable(id);
|
|
1342
|
+
if (!found)
|
|
1343
|
+
return null;
|
|
1344
|
+
const { inv, job, original, turn } = found;
|
|
1345
|
+
if (await this.finishedTurn(id, job.claimedAt))
|
|
1346
|
+
return null;
|
|
1347
|
+
const prior = original.resume?.restart;
|
|
1348
|
+
const lastActivityAt = prior
|
|
1349
|
+
? new Date(Math.max(Date.parse(prior.lastActivityAt), boot.agentSeen.get(id)?.getTime() ?? 0))
|
|
1350
|
+
: (boot.activity.get(id) ?? boot.now);
|
|
1351
|
+
const plan = await this.planFollowUp(inv, {});
|
|
1352
|
+
const reason = notResumedReason({
|
|
1353
|
+
enabled: boot.enabled,
|
|
1354
|
+
now: boot.now,
|
|
1355
|
+
lastActivityAt,
|
|
1356
|
+
attempt: (prior?.attempt ?? 0) + 1,
|
|
1357
|
+
bootLoop: boot.bootLoop,
|
|
1358
|
+
contained: boot.contained.get(id) ?? true,
|
|
1359
|
+
agent: agentLabel(plan?.harness ?? inv.harness),
|
|
1360
|
+
preflight: !plan
|
|
1361
|
+
? "it names no agent to resume in."
|
|
1362
|
+
: plan.preflight
|
|
1363
|
+
? `${plan.preflight.problem} ${plan.preflight.fix}`
|
|
1364
|
+
: null,
|
|
1365
|
+
});
|
|
1366
|
+
if (reason || !plan)
|
|
1367
|
+
return reason ?? "it names no agent to resume in.";
|
|
1368
|
+
const data = recoveryPayload(original, plan, turn, {
|
|
1369
|
+
attempt: (prior?.attempt ?? 0) + 1,
|
|
1370
|
+
stoppedAt: new Date(Math.max(boot.stoppedAt.getTime(), lastActivityAt.getTime())).toISOString(),
|
|
1371
|
+
lastActivityAt: lastActivityAt.toISOString(),
|
|
1372
|
+
by: "auto",
|
|
1373
|
+
}, await this.hasToolResult(id));
|
|
1374
|
+
const admitted = await this.rearm(id, inv.incidentId, turn, data, new Date(boot.now.getTime() + RECOVERY_DELAY_MS), "live");
|
|
1375
|
+
if (!admitted)
|
|
1376
|
+
return "it changed while PrismaLens was starting.";
|
|
1377
|
+
boot.keep.add(id);
|
|
1378
|
+
boot.resumed.push(id);
|
|
1379
|
+
this.streamRelay.attach(id);
|
|
1380
|
+
return true;
|
|
1381
|
+
}
|
|
1382
|
+
async recoverable(id) {
|
|
1383
|
+
const inv = await this.prisma.investigation.findUnique({
|
|
1384
|
+
where: { id },
|
|
1385
|
+
select: {
|
|
1386
|
+
incidentId: true,
|
|
1387
|
+
kind: true,
|
|
1388
|
+
harness: true,
|
|
1389
|
+
model: true,
|
|
1390
|
+
acpSessionId: true,
|
|
1391
|
+
status: true,
|
|
1392
|
+
endReason: true,
|
|
1393
|
+
},
|
|
1394
|
+
});
|
|
1395
|
+
const job = await this.prisma.job.findUnique({
|
|
1396
|
+
where: { investigationId: id },
|
|
1397
|
+
select: { payload: true, claimedAt: true, priority: true },
|
|
1398
|
+
});
|
|
1399
|
+
if (!inv || !job)
|
|
1400
|
+
return null;
|
|
1401
|
+
const parsed = InvestigationJobDataSchema.safeParse(safeJson(job.payload));
|
|
1402
|
+
if (!parsed.success)
|
|
1403
|
+
return null;
|
|
1404
|
+
const original = parsed.data;
|
|
1405
|
+
const turn = original.resume
|
|
1406
|
+
? original.resume.kind === "continue"
|
|
1407
|
+
? "report"
|
|
1408
|
+
: "answer"
|
|
1409
|
+
: inv.kind === "chat"
|
|
1410
|
+
? "answer"
|
|
1411
|
+
: "report";
|
|
1412
|
+
return { inv, job, original, turn };
|
|
1413
|
+
}
|
|
1414
|
+
async finishedTurn(id, since) {
|
|
1415
|
+
if (!since)
|
|
1416
|
+
return false;
|
|
1417
|
+
const ends = await this.prisma.investigationEvent.count({
|
|
1418
|
+
where: {
|
|
1419
|
+
investigationId: id,
|
|
1420
|
+
createdAt: { gte: since },
|
|
1421
|
+
OR: [
|
|
1422
|
+
{ event: { contains: '"kind":"report"' } },
|
|
1423
|
+
{ event: { contains: '"kind":"branch_done"' } },
|
|
1424
|
+
],
|
|
1425
|
+
},
|
|
1426
|
+
});
|
|
1427
|
+
return ends > 0;
|
|
1428
|
+
}
|
|
1429
|
+
async rearm(id, incidentId, turn, data, runAt, from) {
|
|
1430
|
+
const repositoryId = (await this.prisma.investigation.findUnique({
|
|
1431
|
+
where: { id },
|
|
1432
|
+
select: { repositoryId: true },
|
|
1433
|
+
}))?.repositoryId ?? null;
|
|
1434
|
+
const checkout = await this.borrowedCheckout(id, repositoryId);
|
|
1435
|
+
if (checkout)
|
|
1436
|
+
await this.freeCheckout(checkout);
|
|
1437
|
+
return this.prisma.$transaction(async (tx) => {
|
|
1438
|
+
const own = await tx.investigation.findUnique({
|
|
1439
|
+
where: { id },
|
|
1440
|
+
select: { repositoryId: true },
|
|
1441
|
+
});
|
|
1442
|
+
if (own?.repositoryId && (await folderBusy(tx, own.repositoryId, id)))
|
|
1443
|
+
throw new FollowUpRefused(FOLDER_BUSY);
|
|
1444
|
+
if (checkout)
|
|
1445
|
+
await this.leaseIn(tx, checkout, id);
|
|
1446
|
+
const { count } = await tx.investigation.updateMany({
|
|
1447
|
+
where: from === "live"
|
|
1448
|
+
? { id, status: { in: [...LIVE_WORKFLOW_STATUSES] } }
|
|
1449
|
+
: { id, status: "failed", endReason: "interrupted" },
|
|
1450
|
+
data: {
|
|
1451
|
+
status: "pending",
|
|
1452
|
+
completedAt: null,
|
|
1453
|
+
error: null,
|
|
1454
|
+
stopRequestedAt: null,
|
|
1455
|
+
endReason: "interrupted",
|
|
1456
|
+
liveTurn: turn,
|
|
1457
|
+
},
|
|
1458
|
+
});
|
|
1459
|
+
if (count === 0)
|
|
1460
|
+
return false;
|
|
1461
|
+
await new PrismaJobStore(tx.job).enqueue({
|
|
1462
|
+
investigationId: id,
|
|
1463
|
+
incidentId,
|
|
1464
|
+
payload: JSON.stringify(data),
|
|
1465
|
+
priority: PRIORITY_ORDER[data.priority ?? "normal"] ?? 3,
|
|
1466
|
+
runAt,
|
|
1467
|
+
});
|
|
1468
|
+
return true;
|
|
1469
|
+
}, FOLDER_TX);
|
|
1470
|
+
}
|
|
1471
|
+
async checkRecoveries(boot) {
|
|
1472
|
+
try {
|
|
1473
|
+
return await this.revalidateRecoveries(boot);
|
|
1474
|
+
}
|
|
1475
|
+
catch (e) {
|
|
1476
|
+
this.logger.warn(`Could not re-check recoveries left pending; holding them for the next start: ${e.message}`);
|
|
1477
|
+
return this.holdRecoveries({ except: boot.resumed }).then(() => true, () => false);
|
|
1478
|
+
}
|
|
1479
|
+
}
|
|
1480
|
+
async revalidateRecoveries(boot) {
|
|
1481
|
+
let settled = true;
|
|
1482
|
+
const pending = await this.prisma.job.findMany({
|
|
1483
|
+
where: { status: "pending" },
|
|
1484
|
+
select: { investigationId: true, payload: true },
|
|
1485
|
+
});
|
|
1486
|
+
for (const job of pending) {
|
|
1487
|
+
const id = job.investigationId;
|
|
1488
|
+
const resume = jobResume(job.payload);
|
|
1489
|
+
const restart = resume?.restart;
|
|
1490
|
+
if (!resume || !restart || boot.resumed.includes(id))
|
|
1491
|
+
continue;
|
|
1492
|
+
if (boot.skipped.some((s) => s.id === id))
|
|
1493
|
+
continue;
|
|
1494
|
+
const reason = await this.recheck(id, restart, boot).catch((e) => `the check before resuming could not run: ${e.message}`);
|
|
1495
|
+
if (reason === null) {
|
|
1496
|
+
await this.prisma.job.updateMany({
|
|
1497
|
+
where: { investigationId: id, status: "pending" },
|
|
1498
|
+
data: { runAt: new Date(boot.now.getTime() + RECOVERY_DELAY_MS) },
|
|
1499
|
+
});
|
|
1500
|
+
boot.keep.add(id);
|
|
1501
|
+
boot.resumed.push(id);
|
|
1502
|
+
this.streamRelay.attach(id);
|
|
1503
|
+
continue;
|
|
1504
|
+
}
|
|
1505
|
+
boot.keep.add(id);
|
|
1506
|
+
const landed = await this.refuseRecovery(id, resume, reason).then(() => true, (e) => {
|
|
1507
|
+
this.logger.warn(`Could not refuse recovery ${id}; holding it for the next start: ${e.message}`);
|
|
1508
|
+
return this.holdRecoveries({ id }).then(() => true, () => false);
|
|
1509
|
+
});
|
|
1510
|
+
if (landed)
|
|
1511
|
+
boot.skipped.push({ id, reason });
|
|
1512
|
+
else
|
|
1513
|
+
settled = false;
|
|
1514
|
+
}
|
|
1515
|
+
return settled;
|
|
1516
|
+
}
|
|
1517
|
+
async holdRecoveries(only) {
|
|
1518
|
+
await this.prisma.job.updateMany({
|
|
1519
|
+
where: {
|
|
1520
|
+
status: "pending",
|
|
1521
|
+
payload: { contains: '"restart":{' },
|
|
1522
|
+
investigationId: "id" in only ? only.id : { notIn: only.except },
|
|
1523
|
+
},
|
|
1524
|
+
data: { runAt: HELD_UNTIL },
|
|
1525
|
+
});
|
|
1526
|
+
}
|
|
1527
|
+
async recheck(id, restart, boot) {
|
|
1528
|
+
const inv = await this.prisma.investigation.findUnique({
|
|
1529
|
+
where: { id },
|
|
1530
|
+
select: { harness: true, model: true, acpSessionId: true, status: true },
|
|
1531
|
+
});
|
|
1532
|
+
if (!inv || !LIVE_WORKFLOW_STATUSES.includes(inv.status))
|
|
1533
|
+
return "the run had already ended.";
|
|
1534
|
+
const plan = await this.planFollowUp(inv, {});
|
|
1535
|
+
return notResumedReason({
|
|
1536
|
+
enabled: boot.enabled,
|
|
1537
|
+
now: boot.now,
|
|
1538
|
+
lastActivityAt: new Date(restart.lastActivityAt),
|
|
1539
|
+
attempt: restart.attempt,
|
|
1540
|
+
bootLoop: boot.bootLoop,
|
|
1541
|
+
contained: boot.contained.get(id) ?? true,
|
|
1542
|
+
agent: agentLabel(plan?.harness ?? inv.harness),
|
|
1543
|
+
preflight: !plan
|
|
1544
|
+
? "it names no agent to resume in."
|
|
1545
|
+
: plan.preflight
|
|
1546
|
+
? `${plan.preflight.problem} ${plan.preflight.fix}`
|
|
1547
|
+
: null,
|
|
1548
|
+
});
|
|
1549
|
+
}
|
|
1550
|
+
async refuseRecovery(id, resume, reason) {
|
|
1551
|
+
const failed = resume.restore.status === "failed";
|
|
1552
|
+
await this.prisma.$transaction(async (tx) => {
|
|
1553
|
+
await tx.investigation.updateMany({
|
|
1554
|
+
where: { id, status: { in: [...LIVE_WORKFLOW_STATUSES] } },
|
|
1555
|
+
data: {
|
|
1556
|
+
status: resume.restore.status,
|
|
1557
|
+
completedAt: resume.restore.completedAt
|
|
1558
|
+
? new Date(resume.restore.completedAt)
|
|
1559
|
+
: null,
|
|
1560
|
+
error: failed ? `${NOT_RESUMED}${reason}` : resume.restore.error,
|
|
1561
|
+
lastTurnOutcome: "error",
|
|
1562
|
+
liveTurn: null,
|
|
1563
|
+
stopRequestedAt: null,
|
|
1564
|
+
...(failed ? { endReason: "interrupted" } : {}),
|
|
1565
|
+
},
|
|
1566
|
+
});
|
|
1567
|
+
await new PrismaJobStore(tx.job).cancelIfPending(id);
|
|
1568
|
+
});
|
|
1569
|
+
try {
|
|
1570
|
+
const seq = (await this.investigationsService.lastEventSeq(id)) + 1;
|
|
1571
|
+
await this.investigationsService.appendEvents(id, followUpNotDelivered(id, seq, resume, `${FOLLOW_UP_RESTART_REASON} ${NOT_RESUMED}${reason}`));
|
|
1572
|
+
}
|
|
1573
|
+
catch (e) {
|
|
1574
|
+
this.logger.warn(`Could not record the refused recovery in the conversation: ${e.message}`);
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
async writeRestartSummary(boot) {
|
|
1578
|
+
const ids = [...boot.resumed, ...boot.skipped.map((s) => s.id)];
|
|
1579
|
+
const rows = await this.prisma.investigation.findMany({
|
|
1580
|
+
where: { id: { in: ids } },
|
|
1581
|
+
select: {
|
|
1582
|
+
id: true,
|
|
1583
|
+
incidentId: true,
|
|
1584
|
+
incident: { select: { number: true, title: true } },
|
|
1585
|
+
},
|
|
1586
|
+
});
|
|
1587
|
+
const ref = (id) => {
|
|
1588
|
+
const r = rows.find((x) => x.id === id);
|
|
1589
|
+
return {
|
|
1590
|
+
investigationId: id,
|
|
1591
|
+
incidentId: r?.incidentId ?? null,
|
|
1592
|
+
incidentNumber: r?.incident?.number ?? null,
|
|
1593
|
+
title: r?.incident?.title ?? "",
|
|
1594
|
+
};
|
|
1595
|
+
};
|
|
1596
|
+
const summary = {
|
|
1597
|
+
at: boot.now.toISOString(),
|
|
1598
|
+
stoppedAt: this.lifecycle?.lastRestart()?.previous
|
|
1599
|
+
? boot.stoppedAt.toISOString()
|
|
1600
|
+
: null,
|
|
1601
|
+
resumed: boot.resumed.map(ref),
|
|
1602
|
+
skipped: boot.skipped.map((s) => ({ ...ref(s.id), reason: s.reason })),
|
|
1603
|
+
};
|
|
1604
|
+
await this.prisma.setting.upsert({
|
|
1605
|
+
where: { key: RESTART_SUMMARY_KEY },
|
|
1606
|
+
update: { value: JSON.stringify(summary), type: "json" },
|
|
1607
|
+
create: {
|
|
1608
|
+
key: RESTART_SUMMARY_KEY,
|
|
1609
|
+
value: JSON.stringify(summary),
|
|
1610
|
+
type: "json",
|
|
1611
|
+
category: "general",
|
|
1612
|
+
},
|
|
1613
|
+
});
|
|
1614
|
+
}
|
|
1615
|
+
async restartAlerts(incidentId, since, until, stoppedAt) {
|
|
1616
|
+
if (!incidentId)
|
|
1617
|
+
return { catchUp: "unchecked", fired: [], resolved: [] };
|
|
1618
|
+
const inGap = { gte: since, lte: until };
|
|
1619
|
+
const rows = await this.prisma.alert.findMany({
|
|
1620
|
+
where: {
|
|
1621
|
+
incidentId,
|
|
1622
|
+
OR: [
|
|
1623
|
+
{ triggeredAt: inGap },
|
|
1624
|
+
{ createdAt: inGap },
|
|
1625
|
+
{ resolvedAt: inGap },
|
|
1626
|
+
],
|
|
1627
|
+
},
|
|
1628
|
+
select: {
|
|
1629
|
+
title: true,
|
|
1630
|
+
triggeredAt: true,
|
|
1631
|
+
createdAt: true,
|
|
1632
|
+
resolvedAt: true,
|
|
1633
|
+
},
|
|
1634
|
+
orderBy: { triggeredAt: "asc" },
|
|
1635
|
+
});
|
|
1636
|
+
const within = (d) => !!d && d.getTime() >= since.getTime() && d.getTime() <= until.getTime();
|
|
1637
|
+
const fired = rows
|
|
1638
|
+
.filter((a) => within(a.triggeredAt) || within(a.createdAt))
|
|
1639
|
+
.map((a) => ({
|
|
1640
|
+
title: a.title,
|
|
1641
|
+
at: within(a.triggeredAt) ? a.triggeredAt : a.createdAt,
|
|
1642
|
+
}));
|
|
1643
|
+
const resolved = rows
|
|
1644
|
+
.filter((a) => within(a.resolvedAt))
|
|
1645
|
+
.map((a) => ({ title: a.title, at: a.resolvedAt }));
|
|
1646
|
+
const sources = await this.prisma.connection.count({
|
|
1647
|
+
where: {
|
|
1648
|
+
status: "ACTIVE",
|
|
1649
|
+
integration: { templateId: { in: ["prometheus", "alertmanager"] } },
|
|
1650
|
+
},
|
|
1651
|
+
});
|
|
1652
|
+
const pulled = await this.prisma.setting
|
|
1653
|
+
.findUnique({ where: { key: "ALERT_PULL" } })
|
|
1654
|
+
.then((r) => {
|
|
1655
|
+
const at = r
|
|
1656
|
+
? JSON.parse(r.value).lastCompleteAt
|
|
1657
|
+
: undefined;
|
|
1658
|
+
return at ? Date.parse(at) : 0;
|
|
1659
|
+
})
|
|
1660
|
+
.catch(() => 0);
|
|
1661
|
+
const booted = this.lifecycle?.lastRestart()?.bootedAt ?? stoppedAt;
|
|
1662
|
+
const catchUp = sources === 0
|
|
1663
|
+
? "none"
|
|
1664
|
+
: pulled >= booted.getTime()
|
|
1665
|
+
? "done"
|
|
1666
|
+
: "unchecked";
|
|
1667
|
+
return { catchUp, fired, resolved };
|
|
1668
|
+
}
|
|
1669
|
+
async restartSummary() {
|
|
1670
|
+
const row = await this.prisma.setting.findUnique({
|
|
1671
|
+
where: { key: RESTART_SUMMARY_KEY },
|
|
1672
|
+
});
|
|
1673
|
+
if (!row)
|
|
1674
|
+
return null;
|
|
1675
|
+
try {
|
|
1676
|
+
return JSON.parse(row.value);
|
|
1677
|
+
}
|
|
1678
|
+
catch {
|
|
1679
|
+
return null;
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
async resumeInterrupted(id) {
|
|
1683
|
+
const found = await this.recoverable(id);
|
|
1684
|
+
if (found?.inv.status !== "failed" || found.inv.endReason !== "interrupted")
|
|
1685
|
+
throw new FollowUpRefused("Only a run a restart interrupted can be resumed this way.");
|
|
1686
|
+
const { inv, original, turn } = found;
|
|
1687
|
+
const plan = await this.planFollowUp(inv, {});
|
|
1688
|
+
if (!plan)
|
|
1689
|
+
throw new FollowUpRefused("Pick an agent to continue in.");
|
|
1690
|
+
if (!(await this.previousGone(id, inv.acpSessionId)))
|
|
1691
|
+
throw new FollowUpRefused(`${agentLabel(plan.harness)} from before the restart may still be running. Resume once it has stopped.`);
|
|
1692
|
+
if (plan.preflight)
|
|
1693
|
+
throw new FollowUpRefused(`${plan.preflight.problem} ${plan.preflight.fix}`);
|
|
1694
|
+
const now = new Date();
|
|
1695
|
+
const last = (await this.lastActivity(id)).at;
|
|
1696
|
+
const data = recoveryPayload(original, plan, turn, {
|
|
1697
|
+
attempt: 1,
|
|
1698
|
+
stoppedAt: last.toISOString(),
|
|
1699
|
+
lastActivityAt: last.toISOString(),
|
|
1700
|
+
by: "operator",
|
|
1701
|
+
}, await this.hasToolResult(id));
|
|
1702
|
+
if (!(await this.rearm(id, inv.incidentId, turn, data, now, "interrupted")))
|
|
1703
|
+
throw new FollowUpRefused("The run changed; reload it.");
|
|
1704
|
+
this.streamRelay.attach(id);
|
|
1705
|
+
void this.dispatcher.tick();
|
|
1706
|
+
}
|
|
832
1707
|
async restoreFollowUp(investigationId, reason, outcome) {
|
|
833
1708
|
const job = await this.prisma.job.findUnique({
|
|
834
1709
|
where: { investigationId },
|
|
@@ -900,6 +1775,9 @@ DispatchService = DispatchService_1 = __decorate([
|
|
|
900
1775
|
__param(13, Optional()),
|
|
901
1776
|
__param(14, Optional()),
|
|
902
1777
|
__param(15, Optional()),
|
|
1778
|
+
__param(16, Optional()),
|
|
1779
|
+
__param(17, Optional()),
|
|
1780
|
+
__param(18, Optional()),
|
|
903
1781
|
__metadata("design:paramtypes", [Object, StreamRelayService,
|
|
904
1782
|
InvestigationsService,
|
|
905
1783
|
IncidentsService,
|
|
@@ -914,7 +1792,10 @@ DispatchService = DispatchService_1 = __decorate([
|
|
|
914
1792
|
ReportDeliveryService,
|
|
915
1793
|
GatewayService,
|
|
916
1794
|
TelemetrySnapshotService,
|
|
917
|
-
RunWorkspacesService
|
|
1795
|
+
RunWorkspacesService,
|
|
1796
|
+
RuntimeLifecycleService,
|
|
1797
|
+
AdmissionService,
|
|
1798
|
+
CredentialsService])
|
|
918
1799
|
], DispatchService);
|
|
919
1800
|
export { DispatchService };
|
|
920
1801
|
//# sourceMappingURL=dispatch.service.js.map
|