@dealdesk/server 2026.527.0-canary.0
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/LICENSE +21 -0
- package/dist/__tests__/helpers/embedded-postgres.d.ts +2 -0
- package/dist/__tests__/helpers/embedded-postgres.d.ts.map +1 -0
- package/dist/__tests__/helpers/embedded-postgres.js +2 -0
- package/dist/__tests__/helpers/embedded-postgres.js.map +1 -0
- package/dist/adapters/builtin-adapter-types.d.ts +5 -0
- package/dist/adapters/builtin-adapter-types.d.ts.map +1 -0
- package/dist/adapters/builtin-adapter-types.js +18 -0
- package/dist/adapters/builtin-adapter-types.js.map +1 -0
- package/dist/adapters/codex-models.d.ts +5 -0
- package/dist/adapters/codex-models.d.ts.map +1 -0
- package/dist/adapters/codex-models.js +105 -0
- package/dist/adapters/codex-models.js.map +1 -0
- package/dist/adapters/cursor-models.d.ts +13 -0
- package/dist/adapters/cursor-models.d.ts.map +1 -0
- package/dist/adapters/cursor-models.js +148 -0
- package/dist/adapters/cursor-models.js.map +1 -0
- package/dist/adapters/http/execute.d.ts +3 -0
- package/dist/adapters/http/execute.d.ts.map +1 -0
- package/dist/adapters/http/execute.js +51 -0
- package/dist/adapters/http/execute.js.map +1 -0
- package/dist/adapters/http/execute.test.d.ts +2 -0
- package/dist/adapters/http/execute.test.d.ts.map +1 -0
- package/dist/adapters/http/execute.test.js +40 -0
- package/dist/adapters/http/execute.test.js.map +1 -0
- package/dist/adapters/http/index.d.ts +3 -0
- package/dist/adapters/http/index.d.ts.map +1 -0
- package/dist/adapters/http/index.js +20 -0
- package/dist/adapters/http/index.js.map +1 -0
- package/dist/adapters/http/test.d.ts +3 -0
- package/dist/adapters/http/test.d.ts.map +1 -0
- package/dist/adapters/http/test.js +106 -0
- package/dist/adapters/http/test.js.map +1 -0
- package/dist/adapters/index.d.ts +4 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +3 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/plugin-loader.d.ts +28 -0
- package/dist/adapters/plugin-loader.d.ts.map +1 -0
- package/dist/adapters/plugin-loader.js +196 -0
- package/dist/adapters/plugin-loader.js.map +1 -0
- package/dist/adapters/process/execute.d.ts +3 -0
- package/dist/adapters/process/execute.d.ts.map +1 -0
- package/dist/adapters/process/execute.js +70 -0
- package/dist/adapters/process/execute.js.map +1 -0
- package/dist/adapters/process/index.d.ts +3 -0
- package/dist/adapters/process/index.d.ts.map +1 -0
- package/dist/adapters/process/index.js +23 -0
- package/dist/adapters/process/index.js.map +1 -0
- package/dist/adapters/process/test.d.ts +3 -0
- package/dist/adapters/process/test.d.ts.map +1 -0
- package/dist/adapters/process/test.js +77 -0
- package/dist/adapters/process/test.js.map +1 -0
- package/dist/adapters/registry.d.ts +69 -0
- package/dist/adapters/registry.d.ts.map +1 -0
- package/dist/adapters/registry.js +589 -0
- package/dist/adapters/registry.js.map +1 -0
- package/dist/adapters/types.d.ts +2 -0
- package/dist/adapters/types.d.ts.map +1 -0
- package/dist/adapters/types.js +2 -0
- package/dist/adapters/types.js.map +1 -0
- package/dist/adapters/utils.d.ts +43 -0
- package/dist/adapters/utils.d.ts.map +1 -0
- package/dist/adapters/utils.js +52 -0
- package/dist/adapters/utils.js.map +1 -0
- package/dist/agent-auth-jwt.d.ts +14 -0
- package/dist/agent-auth-jwt.d.ts.map +1 -0
- package/dist/agent-auth-jwt.js +117 -0
- package/dist/agent-auth-jwt.js.map +1 -0
- package/dist/app.d.ts +43 -0
- package/dist/app.d.ts.map +1 -0
- package/dist/app.js +426 -0
- package/dist/app.js.map +1 -0
- package/dist/attachment-types.d.ts +23 -0
- package/dist/attachment-types.d.ts.map +1 -0
- package/dist/attachment-types.js +91 -0
- package/dist/attachment-types.js.map +1 -0
- package/dist/auth/better-auth.d.ts +33 -0
- package/dist/auth/better-auth.d.ts.map +1 -0
- package/dist/auth/better-auth.js +133 -0
- package/dist/auth/better-auth.js.map +1 -0
- package/dist/board-claim.d.ts +23 -0
- package/dist/board-claim.d.ts.map +1 -0
- package/dist/board-claim.js +115 -0
- package/dist/board-claim.js.map +1 -0
- package/dist/config-file.d.ts +3 -0
- package/dist/config-file.d.ts.map +1 -0
- package/dist/config-file.js +16 -0
- package/dist/config-file.js.map +1 -0
- package/dist/config.d.ts +50 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +233 -0
- package/dist/config.js.map +1 -0
- package/dist/deal-desk/enrichment/__tests__/apollo-client.test.d.ts +2 -0
- package/dist/deal-desk/enrichment/__tests__/apollo-client.test.d.ts.map +1 -0
- package/dist/deal-desk/enrichment/__tests__/apollo-client.test.js +168 -0
- package/dist/deal-desk/enrichment/__tests__/apollo-client.test.js.map +1 -0
- package/dist/deal-desk/enrichment/__tests__/apollo-config.test.d.ts +2 -0
- package/dist/deal-desk/enrichment/__tests__/apollo-config.test.d.ts.map +1 -0
- package/dist/deal-desk/enrichment/__tests__/apollo-config.test.js +63 -0
- package/dist/deal-desk/enrichment/__tests__/apollo-config.test.js.map +1 -0
- package/dist/deal-desk/enrichment/__tests__/resolve-contact-email.test.d.ts +2 -0
- package/dist/deal-desk/enrichment/__tests__/resolve-contact-email.test.d.ts.map +1 -0
- package/dist/deal-desk/enrichment/__tests__/resolve-contact-email.test.js +127 -0
- package/dist/deal-desk/enrichment/__tests__/resolve-contact-email.test.js.map +1 -0
- package/dist/deal-desk/enrichment/apollo-client.d.ts +57 -0
- package/dist/deal-desk/enrichment/apollo-client.d.ts.map +1 -0
- package/dist/deal-desk/enrichment/apollo-client.js +263 -0
- package/dist/deal-desk/enrichment/apollo-client.js.map +1 -0
- package/dist/deal-desk/enrichment/apollo-config.d.ts +56 -0
- package/dist/deal-desk/enrichment/apollo-config.d.ts.map +1 -0
- package/dist/deal-desk/enrichment/apollo-config.js +58 -0
- package/dist/deal-desk/enrichment/apollo-config.js.map +1 -0
- package/dist/deal-desk/enrichment/resolve-contact-email.d.ts +62 -0
- package/dist/deal-desk/enrichment/resolve-contact-email.d.ts.map +1 -0
- package/dist/deal-desk/enrichment/resolve-contact-email.js +199 -0
- package/dist/deal-desk/enrichment/resolve-contact-email.js.map +1 -0
- package/dist/deal-desk/gmail/__tests__/client-config.test.d.ts +2 -0
- package/dist/deal-desk/gmail/__tests__/client-config.test.d.ts.map +1 -0
- package/dist/deal-desk/gmail/__tests__/client-config.test.js +73 -0
- package/dist/deal-desk/gmail/__tests__/client-config.test.js.map +1 -0
- package/dist/deal-desk/gmail/__tests__/oauth.test.d.ts +2 -0
- package/dist/deal-desk/gmail/__tests__/oauth.test.d.ts.map +1 -0
- package/dist/deal-desk/gmail/__tests__/oauth.test.js +38 -0
- package/dist/deal-desk/gmail/__tests__/oauth.test.js.map +1 -0
- package/dist/deal-desk/gmail/__tests__/redirect-uri.test.d.ts +2 -0
- package/dist/deal-desk/gmail/__tests__/redirect-uri.test.d.ts.map +1 -0
- package/dist/deal-desk/gmail/__tests__/redirect-uri.test.js +74 -0
- package/dist/deal-desk/gmail/__tests__/redirect-uri.test.js.map +1 -0
- package/dist/deal-desk/gmail/__tests__/send.test.d.ts +2 -0
- package/dist/deal-desk/gmail/__tests__/send.test.d.ts.map +1 -0
- package/dist/deal-desk/gmail/__tests__/send.test.js +44 -0
- package/dist/deal-desk/gmail/__tests__/send.test.js.map +1 -0
- package/dist/deal-desk/gmail/__tests__/tokens.test.d.ts +2 -0
- package/dist/deal-desk/gmail/__tests__/tokens.test.d.ts.map +1 -0
- package/dist/deal-desk/gmail/__tests__/tokens.test.js +69 -0
- package/dist/deal-desk/gmail/__tests__/tokens.test.js.map +1 -0
- package/dist/deal-desk/gmail/client-config.d.ts +51 -0
- package/dist/deal-desk/gmail/client-config.d.ts.map +1 -0
- package/dist/deal-desk/gmail/client-config.js +38 -0
- package/dist/deal-desk/gmail/client-config.js.map +1 -0
- package/dist/deal-desk/gmail/oauth.d.ts +26 -0
- package/dist/deal-desk/gmail/oauth.d.ts.map +1 -0
- package/dist/deal-desk/gmail/oauth.js +50 -0
- package/dist/deal-desk/gmail/oauth.js.map +1 -0
- package/dist/deal-desk/gmail/redirect-uri.d.ts +8 -0
- package/dist/deal-desk/gmail/redirect-uri.d.ts.map +1 -0
- package/dist/deal-desk/gmail/redirect-uri.js +83 -0
- package/dist/deal-desk/gmail/redirect-uri.js.map +1 -0
- package/dist/deal-desk/gmail/send.d.ts +19 -0
- package/dist/deal-desk/gmail/send.d.ts.map +1 -0
- package/dist/deal-desk/gmail/send.js +39 -0
- package/dist/deal-desk/gmail/send.js.map +1 -0
- package/dist/deal-desk/gmail/tokens.d.ts +50 -0
- package/dist/deal-desk/gmail/tokens.d.ts.map +1 -0
- package/dist/deal-desk/gmail/tokens.js +50 -0
- package/dist/deal-desk/gmail/tokens.js.map +1 -0
- package/dist/deal-desk/intermediary-campaign.d.ts +4 -0
- package/dist/deal-desk/intermediary-campaign.d.ts.map +1 -0
- package/dist/deal-desk/intermediary-campaign.js +26 -0
- package/dist/deal-desk/intermediary-campaign.js.map +1 -0
- package/dist/deal-desk/seeds/role-templates.d.ts +10 -0
- package/dist/deal-desk/seeds/role-templates.d.ts.map +1 -0
- package/dist/deal-desk/seeds/role-templates.js +110 -0
- package/dist/deal-desk/seeds/role-templates.js.map +1 -0
- package/dist/deal-desk/seeds/seed-role-templates.d.ts +3 -0
- package/dist/deal-desk/seeds/seed-role-templates.d.ts.map +1 -0
- package/dist/deal-desk/seeds/seed-role-templates.js +39 -0
- package/dist/deal-desk/seeds/seed-role-templates.js.map +1 -0
- package/dist/deal-desk/target-service.d.ts +131 -0
- package/dist/deal-desk/target-service.d.ts.map +1 -0
- package/dist/deal-desk/target-service.js +169 -0
- package/dist/deal-desk/target-service.js.map +1 -0
- package/dist/deal-desk/tools/__tests__/apollo-api-key.test.d.ts +2 -0
- package/dist/deal-desk/tools/__tests__/apollo-api-key.test.d.ts.map +1 -0
- package/dist/deal-desk/tools/__tests__/apollo-api-key.test.js +122 -0
- package/dist/deal-desk/tools/__tests__/apollo-api-key.test.js.map +1 -0
- package/dist/deal-desk/tools/__tests__/create-contact.test.d.ts +2 -0
- package/dist/deal-desk/tools/__tests__/create-contact.test.d.ts.map +1 -0
- package/dist/deal-desk/tools/__tests__/create-contact.test.js +73 -0
- package/dist/deal-desk/tools/__tests__/create-contact.test.js.map +1 -0
- package/dist/deal-desk/tools/__tests__/deal-desk-tools.test.d.ts +2 -0
- package/dist/deal-desk/tools/__tests__/deal-desk-tools.test.d.ts.map +1 -0
- package/dist/deal-desk/tools/__tests__/deal-desk-tools.test.js +193 -0
- package/dist/deal-desk/tools/__tests__/deal-desk-tools.test.js.map +1 -0
- package/dist/deal-desk/tools/__tests__/email-accounts.test.d.ts +2 -0
- package/dist/deal-desk/tools/__tests__/email-accounts.test.d.ts.map +1 -0
- package/dist/deal-desk/tools/__tests__/email-accounts.test.js +71 -0
- package/dist/deal-desk/tools/__tests__/email-accounts.test.js.map +1 -0
- package/dist/deal-desk/tools/__tests__/enrich-contact.test.d.ts +2 -0
- package/dist/deal-desk/tools/__tests__/enrich-contact.test.d.ts.map +1 -0
- package/dist/deal-desk/tools/__tests__/enrich-contact.test.js +183 -0
- package/dist/deal-desk/tools/__tests__/enrich-contact.test.js.map +1 -0
- package/dist/deal-desk/tools/__tests__/gmail-client-config.test.d.ts +2 -0
- package/dist/deal-desk/tools/__tests__/gmail-client-config.test.d.ts.map +1 -0
- package/dist/deal-desk/tools/__tests__/gmail-client-config.test.js +67 -0
- package/dist/deal-desk/tools/__tests__/gmail-client-config.test.js.map +1 -0
- package/dist/deal-desk/tools/__tests__/helpers/where-introspection.d.ts +2 -0
- package/dist/deal-desk/tools/__tests__/helpers/where-introspection.d.ts.map +1 -0
- package/dist/deal-desk/tools/__tests__/helpers/where-introspection.js +29 -0
- package/dist/deal-desk/tools/__tests__/helpers/where-introspection.js.map +1 -0
- package/dist/deal-desk/tools/__tests__/outreach-approve.test.d.ts +2 -0
- package/dist/deal-desk/tools/__tests__/outreach-approve.test.d.ts.map +1 -0
- package/dist/deal-desk/tools/__tests__/outreach-approve.test.js +258 -0
- package/dist/deal-desk/tools/__tests__/outreach-approve.test.js.map +1 -0
- package/dist/deal-desk/tools/__tests__/outreach-draft.test.d.ts +2 -0
- package/dist/deal-desk/tools/__tests__/outreach-draft.test.d.ts.map +1 -0
- package/dist/deal-desk/tools/__tests__/outreach-draft.test.js +115 -0
- package/dist/deal-desk/tools/__tests__/outreach-draft.test.js.map +1 -0
- package/dist/deal-desk/tools/__tests__/outreach-edit.test.d.ts +2 -0
- package/dist/deal-desk/tools/__tests__/outreach-edit.test.d.ts.map +1 -0
- package/dist/deal-desk/tools/__tests__/outreach-edit.test.js +169 -0
- package/dist/deal-desk/tools/__tests__/outreach-edit.test.js.map +1 -0
- package/dist/deal-desk/tools/__tests__/outreach-list-pending.test.d.ts +2 -0
- package/dist/deal-desk/tools/__tests__/outreach-list-pending.test.d.ts.map +1 -0
- package/dist/deal-desk/tools/__tests__/outreach-list-pending.test.js +59 -0
- package/dist/deal-desk/tools/__tests__/outreach-list-pending.test.js.map +1 -0
- package/dist/deal-desk/tools/__tests__/test-gmail-send.test.d.ts +2 -0
- package/dist/deal-desk/tools/__tests__/test-gmail-send.test.d.ts.map +1 -0
- package/dist/deal-desk/tools/__tests__/test-gmail-send.test.js +98 -0
- package/dist/deal-desk/tools/__tests__/test-gmail-send.test.js.map +1 -0
- package/dist/deal-desk/tools/apollo-api-key.d.ts +11 -0
- package/dist/deal-desk/tools/apollo-api-key.d.ts.map +1 -0
- package/dist/deal-desk/tools/apollo-api-key.js +70 -0
- package/dist/deal-desk/tools/apollo-api-key.js.map +1 -0
- package/dist/deal-desk/tools/create-contact.d.ts +28 -0
- package/dist/deal-desk/tools/create-contact.d.ts.map +1 -0
- package/dist/deal-desk/tools/create-contact.js +52 -0
- package/dist/deal-desk/tools/create-contact.js.map +1 -0
- package/dist/deal-desk/tools/create-intermediary.d.ts +62 -0
- package/dist/deal-desk/tools/create-intermediary.d.ts.map +1 -0
- package/dist/deal-desk/tools/create-intermediary.js +105 -0
- package/dist/deal-desk/tools/create-intermediary.js.map +1 -0
- package/dist/deal-desk/tools/create-target.d.ts +8 -0
- package/dist/deal-desk/tools/create-target.d.ts.map +1 -0
- package/dist/deal-desk/tools/create-target.js +56 -0
- package/dist/deal-desk/tools/create-target.js.map +1 -0
- package/dist/deal-desk/tools/enrich-contact.d.ts +22 -0
- package/dist/deal-desk/tools/enrich-contact.d.ts.map +1 -0
- package/dist/deal-desk/tools/enrich-contact.js +85 -0
- package/dist/deal-desk/tools/enrich-contact.js.map +1 -0
- package/dist/deal-desk/tools/get-target.d.ts +5 -0
- package/dist/deal-desk/tools/get-target.d.ts.map +1 -0
- package/dist/deal-desk/tools/get-target.js +33 -0
- package/dist/deal-desk/tools/get-target.js.map +1 -0
- package/dist/deal-desk/tools/gmail-client-config.d.ts +20 -0
- package/dist/deal-desk/tools/gmail-client-config.d.ts.map +1 -0
- package/dist/deal-desk/tools/gmail-client-config.js +43 -0
- package/dist/deal-desk/tools/gmail-client-config.js.map +1 -0
- package/dist/deal-desk/tools/index.d.ts +39 -0
- package/dist/deal-desk/tools/index.d.ts.map +1 -0
- package/dist/deal-desk/tools/index.js +208 -0
- package/dist/deal-desk/tools/index.js.map +1 -0
- package/dist/deal-desk/tools/intermediary-outreach-draft.d.ts +21 -0
- package/dist/deal-desk/tools/intermediary-outreach-draft.d.ts.map +1 -0
- package/dist/deal-desk/tools/intermediary-outreach-draft.js +59 -0
- package/dist/deal-desk/tools/intermediary-outreach-draft.js.map +1 -0
- package/dist/deal-desk/tools/list-intermediaries.d.ts +20 -0
- package/dist/deal-desk/tools/list-intermediaries.d.ts.map +1 -0
- package/dist/deal-desk/tools/list-intermediaries.js +74 -0
- package/dist/deal-desk/tools/list-intermediaries.js.map +1 -0
- package/dist/deal-desk/tools/list-targets.d.ts +20 -0
- package/dist/deal-desk/tools/list-targets.d.ts.map +1 -0
- package/dist/deal-desk/tools/list-targets.js +73 -0
- package/dist/deal-desk/tools/list-targets.js.map +1 -0
- package/dist/deal-desk/tools/outreach-approve.d.ts +18 -0
- package/dist/deal-desk/tools/outreach-approve.d.ts.map +1 -0
- package/dist/deal-desk/tools/outreach-approve.js +229 -0
- package/dist/deal-desk/tools/outreach-approve.js.map +1 -0
- package/dist/deal-desk/tools/outreach-draft.d.ts +32 -0
- package/dist/deal-desk/tools/outreach-draft.d.ts.map +1 -0
- package/dist/deal-desk/tools/outreach-draft.js +101 -0
- package/dist/deal-desk/tools/outreach-draft.js.map +1 -0
- package/dist/deal-desk/tools/outreach-edit.d.ts +6 -0
- package/dist/deal-desk/tools/outreach-edit.d.ts.map +1 -0
- package/dist/deal-desk/tools/outreach-edit.js +94 -0
- package/dist/deal-desk/tools/outreach-edit.js.map +1 -0
- package/dist/deal-desk/tools/outreach-list-pending.d.ts +4 -0
- package/dist/deal-desk/tools/outreach-list-pending.d.ts.map +1 -0
- package/dist/deal-desk/tools/outreach-list-pending.js +55 -0
- package/dist/deal-desk/tools/outreach-list-pending.js.map +1 -0
- package/dist/deal-desk/tools/record-intermediary-touch.d.ts +20 -0
- package/dist/deal-desk/tools/record-intermediary-touch.d.ts.map +1 -0
- package/dist/deal-desk/tools/record-intermediary-touch.js +80 -0
- package/dist/deal-desk/tools/record-intermediary-touch.js.map +1 -0
- package/dist/deal-desk/tools/test-gmail-send.d.ts +21 -0
- package/dist/deal-desk/tools/test-gmail-send.d.ts.map +1 -0
- package/dist/deal-desk/tools/test-gmail-send.js +65 -0
- package/dist/deal-desk/tools/test-gmail-send.js.map +1 -0
- package/dist/deal-desk/tools/update-target.d.ts +6 -0
- package/dist/deal-desk/tools/update-target.d.ts.map +1 -0
- package/dist/deal-desk/tools/update-target.js +43 -0
- package/dist/deal-desk/tools/update-target.js.map +1 -0
- package/dist/dev-runner-worktree.d.ts +15 -0
- package/dist/dev-runner-worktree.d.ts.map +1 -0
- package/dist/dev-runner-worktree.js +68 -0
- package/dist/dev-runner-worktree.js.map +1 -0
- package/dist/dev-server-status.d.ts +27 -0
- package/dist/dev-server-status.d.ts.map +1 -0
- package/dist/dev-server-status.js +74 -0
- package/dist/dev-server-status.js.map +1 -0
- package/dist/dev-watch-ignore.d.ts +2 -0
- package/dist/dev-watch-ignore.d.ts.map +1 -0
- package/dist/dev-watch-ignore.js +36 -0
- package/dist/dev-watch-ignore.js.map +1 -0
- package/dist/embedded-postgres-watchdog.d.ts +12 -0
- package/dist/embedded-postgres-watchdog.d.ts.map +1 -0
- package/dist/embedded-postgres-watchdog.js +21 -0
- package/dist/embedded-postgres-watchdog.js.map +1 -0
- package/dist/errors.d.ts +12 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +28 -0
- package/dist/errors.js.map +1 -0
- package/dist/home-paths.d.ts +15 -0
- package/dist/home-paths.d.ts.map +1 -0
- package/dist/home-paths.js +48 -0
- package/dist/home-paths.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +787 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/join-request-dedupe.d.ts +11 -0
- package/dist/lib/join-request-dedupe.d.ts.map +1 -0
- package/dist/lib/join-request-dedupe.js +49 -0
- package/dist/lib/join-request-dedupe.js.map +1 -0
- package/dist/log-redaction.d.ts +11 -0
- package/dist/log-redaction.d.ts.map +1 -0
- package/dist/log-redaction.js +122 -0
- package/dist/log-redaction.js.map +1 -0
- package/dist/middleware/auth.d.ts +12 -0
- package/dist/middleware/auth.d.ts.map +1 -0
- package/dist/middleware/auth.js +302 -0
- package/dist/middleware/auth.js.map +1 -0
- package/dist/middleware/board-mutation-guard.d.ts +3 -0
- package/dist/middleware/board-mutation-guard.d.ts.map +1 -0
- package/dist/middleware/board-mutation-guard.js +67 -0
- package/dist/middleware/board-mutation-guard.js.map +1 -0
- package/dist/middleware/error-handler.d.ts +17 -0
- package/dist/middleware/error-handler.d.ts.map +1 -0
- package/dist/middleware/error-handler.js +45 -0
- package/dist/middleware/error-handler.js.map +1 -0
- package/dist/middleware/http-log-policy.d.ts +2 -0
- package/dist/middleware/http-log-policy.d.ts.map +1 -0
- package/dist/middleware/http-log-policy.js +52 -0
- package/dist/middleware/http-log-policy.js.map +1 -0
- package/dist/middleware/index.d.ts +4 -0
- package/dist/middleware/index.d.ts.map +1 -0
- package/dist/middleware/index.js +4 -0
- package/dist/middleware/index.js.map +1 -0
- package/dist/middleware/logger.d.ts +4 -0
- package/dist/middleware/logger.d.ts.map +1 -0
- package/dist/middleware/logger.js +92 -0
- package/dist/middleware/logger.js.map +1 -0
- package/dist/middleware/private-hostname-guard.d.ts +11 -0
- package/dist/middleware/private-hostname-guard.d.ts.map +1 -0
- package/dist/middleware/private-hostname-guard.js +78 -0
- package/dist/middleware/private-hostname-guard.js.map +1 -0
- package/dist/middleware/validate.d.ts +4 -0
- package/dist/middleware/validate.d.ts.map +1 -0
- package/dist/middleware/validate.js +7 -0
- package/dist/middleware/validate.js.map +1 -0
- package/dist/onboarding-assets/ceo/AGENTS.md +59 -0
- package/dist/onboarding-assets/ceo/HEARTBEAT.md +85 -0
- package/dist/onboarding-assets/ceo/SOUL.md +33 -0
- package/dist/onboarding-assets/ceo/TOOLS.md +3 -0
- package/dist/onboarding-assets/default/AGENTS.md +17 -0
- package/dist/paths.d.ts +3 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +31 -0
- package/dist/paths.js.map +1 -0
- package/dist/realtime/live-events-ws.d.ts +28 -0
- package/dist/realtime/live-events-ws.d.ts.map +1 -0
- package/dist/realtime/live-events-ws.js +187 -0
- package/dist/realtime/live-events-ws.js.map +1 -0
- package/dist/redaction.d.ts +5 -0
- package/dist/redaction.d.ts.map +1 -0
- package/dist/redaction.js +98 -0
- package/dist/redaction.js.map +1 -0
- package/dist/routes/__tests__/deal-desk-thesis.test.d.ts +2 -0
- package/dist/routes/__tests__/deal-desk-thesis.test.d.ts.map +1 -0
- package/dist/routes/__tests__/deal-desk-thesis.test.js +53 -0
- package/dist/routes/__tests__/deal-desk-thesis.test.js.map +1 -0
- package/dist/routes/__tests__/gmail-oauth.test.d.ts +2 -0
- package/dist/routes/__tests__/gmail-oauth.test.d.ts.map +1 -0
- package/dist/routes/__tests__/gmail-oauth.test.js +99 -0
- package/dist/routes/__tests__/gmail-oauth.test.js.map +1 -0
- package/dist/routes/access.d.ts +82 -0
- package/dist/routes/access.d.ts.map +1 -0
- package/dist/routes/access.js +3411 -0
- package/dist/routes/access.js.map +1 -0
- package/dist/routes/activity.d.ts +3 -0
- package/dist/routes/activity.d.ts.map +1 -0
- package/dist/routes/activity.js +90 -0
- package/dist/routes/activity.js.map +1 -0
- package/dist/routes/adapters.d.ts +16 -0
- package/dist/routes/adapters.d.ts.map +1 -0
- package/dist/routes/adapters.js +527 -0
- package/dist/routes/adapters.js.map +1 -0
- package/dist/routes/agents.d.ts +6 -0
- package/dist/routes/agents.d.ts.map +1 -0
- package/dist/routes/agents.js +2765 -0
- package/dist/routes/agents.js.map +1 -0
- package/dist/routes/approvals.d.ts +6 -0
- package/dist/routes/approvals.d.ts.map +1 -0
- package/dist/routes/approvals.js +300 -0
- package/dist/routes/approvals.js.map +1 -0
- package/dist/routes/assets.d.ts +4 -0
- package/dist/routes/assets.d.ts.map +1 -0
- package/dist/routes/assets.js +309 -0
- package/dist/routes/assets.js.map +1 -0
- package/dist/routes/auth.d.ts +3 -0
- package/dist/routes/auth.d.ts.map +1 -0
- package/dist/routes/auth.js +82 -0
- package/dist/routes/auth.js.map +1 -0
- package/dist/routes/authz.d.ts +19 -0
- package/dist/routes/authz.d.ts.map +1 -0
- package/dist/routes/authz.js +75 -0
- package/dist/routes/authz.js.map +1 -0
- package/dist/routes/companies.d.ts +4 -0
- package/dist/routes/companies.d.ts.map +1 -0
- package/dist/routes/companies.js +359 -0
- package/dist/routes/companies.js.map +1 -0
- package/dist/routes/company-skills.d.ts +3 -0
- package/dist/routes/company-skills.d.ts.map +1 -0
- package/dist/routes/company-skills.js +258 -0
- package/dist/routes/company-skills.js.map +1 -0
- package/dist/routes/costs.d.ts +11 -0
- package/dist/routes/costs.d.ts.map +1 -0
- package/dist/routes/costs.js +307 -0
- package/dist/routes/costs.js.map +1 -0
- package/dist/routes/dashboard.d.ts +3 -0
- package/dist/routes/dashboard.d.ts.map +1 -0
- package/dist/routes/dashboard.js +15 -0
- package/dist/routes/dashboard.js.map +1 -0
- package/dist/routes/deal-desk.d.ts +83 -0
- package/dist/routes/deal-desk.d.ts.map +1 -0
- package/dist/routes/deal-desk.js +288 -0
- package/dist/routes/deal-desk.js.map +1 -0
- package/dist/routes/deal-desk.test.d.ts +2 -0
- package/dist/routes/deal-desk.test.d.ts.map +1 -0
- package/dist/routes/deal-desk.test.js +291 -0
- package/dist/routes/deal-desk.test.js.map +1 -0
- package/dist/routes/environment-selection.d.ts +13 -0
- package/dist/routes/environment-selection.d.ts.map +1 -0
- package/dist/routes/environment-selection.js +30 -0
- package/dist/routes/environment-selection.js.map +1 -0
- package/dist/routes/environments.d.ts +6 -0
- package/dist/routes/environments.d.ts.map +1 -0
- package/dist/routes/environments.js +408 -0
- package/dist/routes/environments.js.map +1 -0
- package/dist/routes/execution-workspaces.d.ts +3 -0
- package/dist/routes/execution-workspaces.d.ts.map +1 -0
- package/dist/routes/execution-workspaces.js +536 -0
- package/dist/routes/execution-workspaces.js.map +1 -0
- package/dist/routes/gmail-oauth.d.ts +14 -0
- package/dist/routes/gmail-oauth.d.ts.map +1 -0
- package/dist/routes/gmail-oauth.js +124 -0
- package/dist/routes/gmail-oauth.js.map +1 -0
- package/dist/routes/goals.d.ts +3 -0
- package/dist/routes/goals.d.ts.map +1 -0
- package/dist/routes/goals.js +101 -0
- package/dist/routes/goals.js.map +1 -0
- package/dist/routes/health.d.ts +9 -0
- package/dist/routes/health.d.ts.map +1 -0
- package/dist/routes/health.js +114 -0
- package/dist/routes/health.js.map +1 -0
- package/dist/routes/inbox-dismissals.d.ts +3 -0
- package/dist/routes/inbox-dismissals.d.ts.map +1 -0
- package/dist/routes/inbox-dismissals.js +58 -0
- package/dist/routes/inbox-dismissals.js.map +1 -0
- package/dist/routes/index.d.ts +21 -0
- package/dist/routes/index.d.ts.map +1 -0
- package/dist/routes/index.js +21 -0
- package/dist/routes/index.js.map +1 -0
- package/dist/routes/instance-database-backups.d.ts +15 -0
- package/dist/routes/instance-database-backups.d.ts.map +1 -0
- package/dist/routes/instance-database-backups.js +12 -0
- package/dist/routes/instance-database-backups.js.map +1 -0
- package/dist/routes/instance-settings.d.ts +3 -0
- package/dist/routes/instance-settings.d.ts.map +1 -0
- package/dist/routes/instance-settings.js +110 -0
- package/dist/routes/instance-settings.js.map +1 -0
- package/dist/routes/issue-tree-control.d.ts +3 -0
- package/dist/routes/issue-tree-control.d.ts.map +1 -0
- package/dist/routes/issue-tree-control.js +363 -0
- package/dist/routes/issue-tree-control.js.map +1 -0
- package/dist/routes/issues-checkout-wakeup.d.ts +9 -0
- package/dist/routes/issues-checkout-wakeup.d.ts.map +1 -0
- package/dist/routes/issues-checkout-wakeup.js +12 -0
- package/dist/routes/issues-checkout-wakeup.js.map +1 -0
- package/dist/routes/issues.d.ts +23 -0
- package/dist/routes/issues.d.ts.map +1 -0
- package/dist/routes/issues.js +4094 -0
- package/dist/routes/issues.js.map +1 -0
- package/dist/routes/llms.d.ts +3 -0
- package/dist/routes/llms.d.ts.map +1 -0
- package/dist/routes/llms.js +80 -0
- package/dist/routes/llms.js.map +1 -0
- package/dist/routes/org-chart-svg.d.ts +25 -0
- package/dist/routes/org-chart-svg.d.ts.map +1 -0
- package/dist/routes/org-chart-svg.js +656 -0
- package/dist/routes/org-chart-svg.js.map +1 -0
- package/dist/routes/plugin-ui-static.d.ts +69 -0
- package/dist/routes/plugin-ui-static.d.ts.map +1 -0
- package/dist/routes/plugin-ui-static.js +411 -0
- package/dist/routes/plugin-ui-static.js.map +1 -0
- package/dist/routes/plugins.d.ts +121 -0
- package/dist/routes/plugins.d.ts.map +1 -0
- package/dist/routes/plugins.js +2184 -0
- package/dist/routes/plugins.js.map +1 -0
- package/dist/routes/projects.d.ts +3 -0
- package/dist/routes/projects.d.ts.map +1 -0
- package/dist/routes/projects.js +572 -0
- package/dist/routes/projects.js.map +1 -0
- package/dist/routes/routines.d.ts +6 -0
- package/dist/routes/routines.d.ts.map +1 -0
- package/dist/routes/routines.js +417 -0
- package/dist/routes/routines.js.map +1 -0
- package/dist/routes/secrets.d.ts +3 -0
- package/dist/routes/secrets.d.ts.map +1 -0
- package/dist/routes/secrets.js +392 -0
- package/dist/routes/secrets.js.map +1 -0
- package/dist/routes/sidebar-badges.d.ts +3 -0
- package/dist/routes/sidebar-badges.d.ts.map +1 -0
- package/dist/routes/sidebar-badges.js +68 -0
- package/dist/routes/sidebar-badges.js.map +1 -0
- package/dist/routes/sidebar-preferences.d.ts +3 -0
- package/dist/routes/sidebar-preferences.d.ts.map +1 -0
- package/dist/routes/sidebar-preferences.js +63 -0
- package/dist/routes/sidebar-preferences.js.map +1 -0
- package/dist/routes/user-profiles.d.ts +3 -0
- package/dist/routes/user-profiles.d.ts.map +1 -0
- package/dist/routes/user-profiles.js +337 -0
- package/dist/routes/user-profiles.js.map +1 -0
- package/dist/routes/workspace-command-authz.d.ts +14 -0
- package/dist/routes/workspace-command-authz.d.ts.map +1 -0
- package/dist/routes/workspace-command-authz.js +83 -0
- package/dist/routes/workspace-command-authz.js.map +1 -0
- package/dist/routes/workspace-runtime-service-authz.d.ts +12 -0
- package/dist/routes/workspace-runtime-service-authz.d.ts.map +1 -0
- package/dist/routes/workspace-runtime-service-authz.js +96 -0
- package/dist/routes/workspace-runtime-service-authz.js.map +1 -0
- package/dist/runtime-api.d.ts +19 -0
- package/dist/runtime-api.d.ts.map +1 -0
- package/dist/runtime-api.js +137 -0
- package/dist/runtime-api.js.map +1 -0
- package/dist/secrets/aws-secrets-manager-provider.d.ts +87 -0
- package/dist/secrets/aws-secrets-manager-provider.d.ts.map +1 -0
- package/dist/secrets/aws-secrets-manager-provider.js +748 -0
- package/dist/secrets/aws-secrets-manager-provider.js.map +1 -0
- package/dist/secrets/configured-provider.d.ts +3 -0
- package/dist/secrets/configured-provider.d.ts.map +1 -0
- package/dist/secrets/configured-provider.js +8 -0
- package/dist/secrets/configured-provider.js.map +1 -0
- package/dist/secrets/external-stub-providers.d.ts +5 -0
- package/dist/secrets/external-stub-providers.d.ts.map +1 -0
- package/dist/secrets/external-stub-providers.js +71 -0
- package/dist/secrets/external-stub-providers.js.map +1 -0
- package/dist/secrets/local-encrypted-provider.d.ts +3 -0
- package/dist/secrets/local-encrypted-provider.d.ts.map +1 -0
- package/dist/secrets/local-encrypted-provider.js +244 -0
- package/dist/secrets/local-encrypted-provider.js.map +1 -0
- package/dist/secrets/provider-registry.d.ts +6 -0
- package/dist/secrets/provider-registry.d.ts.map +1 -0
- package/dist/secrets/provider-registry.js +24 -0
- package/dist/secrets/provider-registry.js.map +1 -0
- package/dist/secrets/types.d.ts +131 -0
- package/dist/secrets/types.d.ts.map +1 -0
- package/dist/secrets/types.js +36 -0
- package/dist/secrets/types.js.map +1 -0
- package/dist/services/access.d.ts +171 -0
- package/dist/services/access.d.ts.map +1 -0
- package/dist/services/access.js +522 -0
- package/dist/services/access.js.map +1 -0
- package/dist/services/activity-log.d.ts +19 -0
- package/dist/services/activity-log.d.ts.map +1 -0
- package/dist/services/activity-log.js +99 -0
- package/dist/services/activity-log.js.map +1 -0
- package/dist/services/activity.d.ts +462 -0
- package/dist/services/activity.d.ts.map +1 -0
- package/dist/services/activity.js +443 -0
- package/dist/services/activity.js.map +1 -0
- package/dist/services/adapter-plugin-store.d.ts +36 -0
- package/dist/services/adapter-plugin-store.d.ts.map +1 -0
- package/dist/services/adapter-plugin-store.js +154 -0
- package/dist/services/adapter-plugin-store.js.map +1 -0
- package/dist/services/agent-instructions.d.ts +91 -0
- package/dist/services/agent-instructions.d.ts.map +1 -0
- package/dist/services/agent-instructions.js +580 -0
- package/dist/services/agent-instructions.js.map +1 -0
- package/dist/services/agent-permissions.d.ts +6 -0
- package/dist/services/agent-permissions.d.ts.map +1 -0
- package/dist/services/agent-permissions.js +18 -0
- package/dist/services/agent-permissions.js.map +1 -0
- package/dist/services/agent-start-lock.d.ts +2 -0
- package/dist/services/agent-start-lock.d.ts.map +1 -0
- package/dist/services/agent-start-lock.js +43 -0
- package/dist/services/agent-start-lock.js.map +1 -0
- package/dist/services/agents.d.ts +2253 -0
- package/dist/services/agents.d.ts.map +1 -0
- package/dist/services/agents.js +609 -0
- package/dist/services/agents.js.map +1 -0
- package/dist/services/approvals.d.ts +546 -0
- package/dist/services/approvals.d.ts.map +1 -0
- package/dist/services/approvals.js +212 -0
- package/dist/services/approvals.js.map +1 -0
- package/dist/services/assets.d.ts +33 -0
- package/dist/services/assets.d.ts.map +1 -0
- package/dist/services/assets.js +17 -0
- package/dist/services/assets.js.map +1 -0
- package/dist/services/board-auth.d.ts +239 -0
- package/dist/services/board-auth.d.ts.map +1 -0
- package/dist/services/board-auth.js +300 -0
- package/dist/services/board-auth.js.map +1 -0
- package/dist/services/budgets.d.ts +38 -0
- package/dist/services/budgets.d.ts.map +1 -0
- package/dist/services/budgets.js +784 -0
- package/dist/services/budgets.js.map +1 -0
- package/dist/services/companies.d.ts +154 -0
- package/dist/services/companies.d.ts.map +1 -0
- package/dist/services/companies.js +286 -0
- package/dist/services/companies.js.map +1 -0
- package/dist/services/company-export-readme.d.ts +17 -0
- package/dist/services/company-export-readme.d.ts.map +1 -0
- package/dist/services/company-export-readme.js +148 -0
- package/dist/services/company-export-readme.js.map +1 -0
- package/dist/services/company-member-roles.d.ts +9 -0
- package/dist/services/company-member-roles.d.ts.map +1 -0
- package/dist/services/company-member-roles.js +46 -0
- package/dist/services/company-member-roles.js.map +1 -0
- package/dist/services/company-portability.d.ts +24 -0
- package/dist/services/company-portability.d.ts.map +1 -0
- package/dist/services/company-portability.js +4077 -0
- package/dist/services/company-portability.js.map +1 -0
- package/dist/services/company-search-rate-limit.d.ts +22 -0
- package/dist/services/company-search-rate-limit.d.ts.map +1 -0
- package/dist/services/company-search-rate-limit.js +38 -0
- package/dist/services/company-search-rate-limit.js.map +1 -0
- package/dist/services/company-search.d.ts +8 -0
- package/dist/services/company-search.d.ts.map +1 -0
- package/dist/services/company-search.js +626 -0
- package/dist/services/company-search.js.map +1 -0
- package/dist/services/company-skills.d.ts +77 -0
- package/dist/services/company-skills.d.ts.map +1 -0
- package/dist/services/company-skills.js +2131 -0
- package/dist/services/company-skills.js.map +1 -0
- package/dist/services/cost-backfill.d.ts +16 -0
- package/dist/services/cost-backfill.d.ts.map +1 -0
- package/dist/services/cost-backfill.js +115 -0
- package/dist/services/cost-backfill.js.map +1 -0
- package/dist/services/cost-ledger.d.ts +28 -0
- package/dist/services/cost-ledger.d.ts.map +1 -0
- package/dist/services/cost-ledger.js +140 -0
- package/dist/services/cost-ledger.js.map +1 -0
- package/dist/services/cost-ledger.test.d.ts +2 -0
- package/dist/services/cost-ledger.test.d.ts.map +1 -0
- package/dist/services/cost-ledger.test.js +50 -0
- package/dist/services/cost-ledger.test.js.map +1 -0
- package/dist/services/cost-pipeline-health.d.ts +4 -0
- package/dist/services/cost-pipeline-health.d.ts.map +1 -0
- package/dist/services/cost-pipeline-health.js +42 -0
- package/dist/services/cost-pipeline-health.js.map +1 -0
- package/dist/services/costs.d.ts +128 -0
- package/dist/services/costs.d.ts.map +1 -0
- package/dist/services/costs.js +412 -0
- package/dist/services/costs.js.map +1 -0
- package/dist/services/cron.d.ts +80 -0
- package/dist/services/cron.d.ts.map +1 -0
- package/dist/services/cron.js +300 -0
- package/dist/services/cron.js.map +1 -0
- package/dist/services/dashboard.d.ts +34 -0
- package/dist/services/dashboard.d.ts.map +1 -0
- package/dist/services/dashboard.js +142 -0
- package/dist/services/dashboard.js.map +1 -0
- package/dist/services/default-agent-instructions.d.ts +9 -0
- package/dist/services/default-agent-instructions.d.ts.map +1 -0
- package/dist/services/default-agent-instructions.js +20 -0
- package/dist/services/default-agent-instructions.js.map +1 -0
- package/dist/services/documents.d.ts +199 -0
- package/dist/services/documents.d.ts.map +1 -0
- package/dist/services/documents.js +411 -0
- package/dist/services/documents.js.map +1 -0
- package/dist/services/environment-config.d.ts +55 -0
- package/dist/services/environment-config.d.ts.map +1 -0
- package/dist/services/environment-config.js +441 -0
- package/dist/services/environment-config.js.map +1 -0
- package/dist/services/environment-execution-target.d.ts +21 -0
- package/dist/services/environment-execution-target.d.ts.map +1 -0
- package/dist/services/environment-execution-target.js +121 -0
- package/dist/services/environment-execution-target.js.map +1 -0
- package/dist/services/environment-probe.d.ts +9 -0
- package/dist/services/environment-probe.d.ts.map +1 -0
- package/dist/services/environment-probe.js +106 -0
- package/dist/services/environment-probe.js.map +1 -0
- package/dist/services/environment-run-orchestrator.d.ts +124 -0
- package/dist/services/environment-run-orchestrator.d.ts.map +1 -0
- package/dist/services/environment-run-orchestrator.js +392 -0
- package/dist/services/environment-run-orchestrator.js.map +1 -0
- package/dist/services/environment-runtime.d.ts +90 -0
- package/dist/services/environment-runtime.d.ts.map +1 -0
- package/dist/services/environment-runtime.js +968 -0
- package/dist/services/environment-runtime.js.map +1 -0
- package/dist/services/environments.d.ts +36 -0
- package/dist/services/environments.d.ts.map +1 -0
- package/dist/services/environments.js +260 -0
- package/dist/services/environments.js.map +1 -0
- package/dist/services/execution-workspace-policy.d.ts +30 -0
- package/dist/services/execution-workspace-policy.d.ts.map +1 -0
- package/dist/services/execution-workspace-policy.js +195 -0
- package/dist/services/execution-workspace-policy.js.map +1 -0
- package/dist/services/execution-workspaces.d.ts +30 -0
- package/dist/services/execution-workspaces.d.ts.map +1 -0
- package/dist/services/execution-workspaces.js +635 -0
- package/dist/services/execution-workspaces.js.map +1 -0
- package/dist/services/feedback-redaction.d.ts +23 -0
- package/dist/services/feedback-redaction.d.ts.map +1 -0
- package/dist/services/feedback-redaction.js +150 -0
- package/dist/services/feedback-redaction.js.map +1 -0
- package/dist/services/feedback-share-client.d.ts +9 -0
- package/dist/services/feedback-share-client.d.ts.map +1 -0
- package/dist/services/feedback-share-client.js +46 -0
- package/dist/services/feedback-share-client.js.map +1 -0
- package/dist/services/feedback.d.ts +93 -0
- package/dist/services/feedback.d.ts.map +1 -0
- package/dist/services/feedback.js +1717 -0
- package/dist/services/feedback.js.map +1 -0
- package/dist/services/finance.d.ts +93 -0
- package/dist/services/finance.d.ts.map +1 -0
- package/dist/services/finance.js +120 -0
- package/dist/services/finance.js.map +1 -0
- package/dist/services/github-fetch.d.ts +4 -0
- package/dist/services/github-fetch.d.ts.map +1 -0
- package/dist/services/github-fetch.js +23 -0
- package/dist/services/github-fetch.js.map +1 -0
- package/dist/services/goals.d.ts +433 -0
- package/dist/services/goals.d.ts.map +1 -0
- package/dist/services/goals.js +54 -0
- package/dist/services/goals.js.map +1 -0
- package/dist/services/heartbeat-run-summary.d.ts +7 -0
- package/dist/services/heartbeat-run-summary.d.ts.map +1 -0
- package/dist/services/heartbeat-run-summary.js +84 -0
- package/dist/services/heartbeat-run-summary.js.map +1 -0
- package/dist/services/heartbeat-stop-metadata.d.ts +28 -0
- package/dist/services/heartbeat-stop-metadata.d.ts.map +1 -0
- package/dist/services/heartbeat-stop-metadata.js +86 -0
- package/dist/services/heartbeat-stop-metadata.js.map +1 -0
- package/dist/services/heartbeat-stop-metadata.test.d.ts +2 -0
- package/dist/services/heartbeat-stop-metadata.test.d.ts.map +1 -0
- package/dist/services/heartbeat-stop-metadata.test.js +93 -0
- package/dist/services/heartbeat-stop-metadata.test.js.map +1 -0
- package/dist/services/heartbeat.d.ts +1546 -0
- package/dist/services/heartbeat.d.ts.map +1 -0
- package/dist/services/heartbeat.js +7854 -0
- package/dist/services/heartbeat.js.map +1 -0
- package/dist/services/hire-hook.d.ts +14 -0
- package/dist/services/hire-hook.d.ts.map +1 -0
- package/dist/services/hire-hook.js +85 -0
- package/dist/services/hire-hook.js.map +1 -0
- package/dist/services/inbox-dismissals.d.ts +22 -0
- package/dist/services/inbox-dismissals.d.ts.map +1 -0
- package/dist/services/inbox-dismissals.js +33 -0
- package/dist/services/inbox-dismissals.js.map +1 -0
- package/dist/services/index.d.ts +45 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +45 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/instance-settings.d.ts +11 -0
- package/dist/services/instance-settings.d.ts.map +1 -0
- package/dist/services/instance-settings.js +138 -0
- package/dist/services/instance-settings.js.map +1 -0
- package/dist/services/invite-grants.d.ts +15 -0
- package/dist/services/invite-grants.d.ts.map +1 -0
- package/dist/services/invite-grants.js +50 -0
- package/dist/services/invite-grants.js.map +1 -0
- package/dist/services/issue-approvals.d.ts +56 -0
- package/dist/services/issue-approvals.d.ts.map +1 -0
- package/dist/services/issue-approvals.js +153 -0
- package/dist/services/issue-approvals.js.map +1 -0
- package/dist/services/issue-assignment-wakeup.d.ts +29 -0
- package/dist/services/issue-assignment-wakeup.d.ts.map +1 -0
- package/dist/services/issue-assignment-wakeup.js +22 -0
- package/dist/services/issue-assignment-wakeup.js.map +1 -0
- package/dist/services/issue-continuation-summary.d.ts +68 -0
- package/dist/services/issue-continuation-summary.d.ts.map +1 -0
- package/dist/services/issue-continuation-summary.js +222 -0
- package/dist/services/issue-continuation-summary.js.map +1 -0
- package/dist/services/issue-execution-policy.d.ts +93 -0
- package/dist/services/issue-execution-policy.d.ts.map +1 -0
- package/dist/services/issue-execution-policy.js +838 -0
- package/dist/services/issue-execution-policy.js.map +1 -0
- package/dist/services/issue-goal-fallback.d.ts +18 -0
- package/dist/services/issue-goal-fallback.d.ts.map +1 -0
- package/dist/services/issue-goal-fallback.js +33 -0
- package/dist/services/issue-goal-fallback.js.map +1 -0
- package/dist/services/issue-liveness.d.ts +3 -0
- package/dist/services/issue-liveness.d.ts.map +1 -0
- package/dist/services/issue-liveness.js +2 -0
- package/dist/services/issue-liveness.js.map +1 -0
- package/dist/services/issue-recovery-actions.d.ts +40 -0
- package/dist/services/issue-recovery-actions.d.ts.map +1 -0
- package/dist/services/issue-recovery-actions.js +204 -0
- package/dist/services/issue-recovery-actions.js.map +1 -0
- package/dist/services/issue-references.d.ts +21 -0
- package/dist/services/issue-references.d.ts.map +1 -0
- package/dist/services/issue-references.js +318 -0
- package/dist/services/issue-references.js.map +1 -0
- package/dist/services/issue-thread-interactions.d.ts +76 -0
- package/dist/services/issue-thread-interactions.d.ts.map +1 -0
- package/dist/services/issue-thread-interactions.js +923 -0
- package/dist/services/issue-thread-interactions.js.map +1 -0
- package/dist/services/issue-thread-interactions.test.d.ts +2 -0
- package/dist/services/issue-thread-interactions.test.d.ts.map +1 -0
- package/dist/services/issue-thread-interactions.test.js +195 -0
- package/dist/services/issue-thread-interactions.test.js.map +1 -0
- package/dist/services/issue-tree-control.d.ts +89 -0
- package/dist/services/issue-tree-control.d.ts.map +1 -0
- package/dist/services/issue-tree-control.js +933 -0
- package/dist/services/issue-tree-control.js.map +1 -0
- package/dist/services/issues.d.ts +744 -0
- package/dist/services/issues.d.ts.map +1 -0
- package/dist/services/issues.js +3374 -0
- package/dist/services/issues.js.map +1 -0
- package/dist/services/json-schema-secret-refs.d.ts +5 -0
- package/dist/services/json-schema-secret-refs.d.ts.map +1 -0
- package/dist/services/json-schema-secret-refs.js +67 -0
- package/dist/services/json-schema-secret-refs.js.map +1 -0
- package/dist/services/live-events.d.ts +17 -0
- package/dist/services/live-events.d.ts.map +1 -0
- package/dist/services/live-events.js +33 -0
- package/dist/services/live-events.js.map +1 -0
- package/dist/services/local-service-supervisor.d.ts +56 -0
- package/dist/services/local-service-supervisor.d.ts.map +1 -0
- package/dist/services/local-service-supervisor.js +284 -0
- package/dist/services/local-service-supervisor.js.map +1 -0
- package/dist/services/plugin-capability-validator.d.ts +108 -0
- package/dist/services/plugin-capability-validator.d.ts.map +1 -0
- package/dist/services/plugin-capability-validator.js +313 -0
- package/dist/services/plugin-capability-validator.js.map +1 -0
- package/dist/services/plugin-config-validator.d.ts +26 -0
- package/dist/services/plugin-config-validator.d.ts.map +1 -0
- package/dist/services/plugin-config-validator.js +41 -0
- package/dist/services/plugin-config-validator.js.map +1 -0
- package/dist/services/plugin-database.d.ts +49 -0
- package/dist/services/plugin-database.d.ts.map +1 -0
- package/dist/services/plugin-database.js +440 -0
- package/dist/services/plugin-database.js.map +1 -0
- package/dist/services/plugin-dev-watcher.d.ts +30 -0
- package/dist/services/plugin-dev-watcher.d.ts.map +1 -0
- package/dist/services/plugin-dev-watcher.js +246 -0
- package/dist/services/plugin-dev-watcher.js.map +1 -0
- package/dist/services/plugin-environment-driver.d.ts +126 -0
- package/dist/services/plugin-environment-driver.d.ts.map +1 -0
- package/dist/services/plugin-environment-driver.js +226 -0
- package/dist/services/plugin-environment-driver.js.map +1 -0
- package/dist/services/plugin-event-bus.d.ts +149 -0
- package/dist/services/plugin-event-bus.d.ts.map +1 -0
- package/dist/services/plugin-event-bus.js +258 -0
- package/dist/services/plugin-event-bus.js.map +1 -0
- package/dist/services/plugin-host-service-cleanup.d.ts +14 -0
- package/dist/services/plugin-host-service-cleanup.d.ts.map +1 -0
- package/dist/services/plugin-host-service-cleanup.js +37 -0
- package/dist/services/plugin-host-service-cleanup.js.map +1 -0
- package/dist/services/plugin-host-services.d.ts +17 -0
- package/dist/services/plugin-host-services.d.ts.map +1 -0
- package/dist/services/plugin-host-services.js +1867 -0
- package/dist/services/plugin-host-services.js.map +1 -0
- package/dist/services/plugin-job-coordinator.d.ts +81 -0
- package/dist/services/plugin-job-coordinator.d.ts.map +1 -0
- package/dist/services/plugin-job-coordinator.js +172 -0
- package/dist/services/plugin-job-coordinator.js.map +1 -0
- package/dist/services/plugin-job-scheduler.d.ts +163 -0
- package/dist/services/plugin-job-scheduler.d.ts.map +1 -0
- package/dist/services/plugin-job-scheduler.js +459 -0
- package/dist/services/plugin-job-scheduler.js.map +1 -0
- package/dist/services/plugin-job-store.d.ts +208 -0
- package/dist/services/plugin-job-store.d.ts.map +1 -0
- package/dist/services/plugin-job-store.js +350 -0
- package/dist/services/plugin-job-store.js.map +1 -0
- package/dist/services/plugin-lifecycle.d.ts +203 -0
- package/dist/services/plugin-lifecycle.d.ts.map +1 -0
- package/dist/services/plugin-lifecycle.js +476 -0
- package/dist/services/plugin-lifecycle.js.map +1 -0
- package/dist/services/plugin-loader.d.ts +445 -0
- package/dist/services/plugin-loader.d.ts.map +1 -0
- package/dist/services/plugin-loader.js +1273 -0
- package/dist/services/plugin-loader.js.map +1 -0
- package/dist/services/plugin-local-folders.d.ts +49 -0
- package/dist/services/plugin-local-folders.d.ts.map +1 -0
- package/dist/services/plugin-local-folders.js +506 -0
- package/dist/services/plugin-local-folders.js.map +1 -0
- package/dist/services/plugin-log-retention.d.ts +20 -0
- package/dist/services/plugin-log-retention.d.ts.map +1 -0
- package/dist/services/plugin-log-retention.js +63 -0
- package/dist/services/plugin-log-retention.js.map +1 -0
- package/dist/services/plugin-managed-agents.d.ts +15 -0
- package/dist/services/plugin-managed-agents.d.ts.map +1 -0
- package/dist/services/plugin-managed-agents.js +458 -0
- package/dist/services/plugin-managed-agents.js.map +1 -0
- package/dist/services/plugin-managed-routines.d.ts +41 -0
- package/dist/services/plugin-managed-routines.d.ts.map +1 -0
- package/dist/services/plugin-managed-routines.js +416 -0
- package/dist/services/plugin-managed-routines.js.map +1 -0
- package/dist/services/plugin-managed-skills.d.ts +14 -0
- package/dist/services/plugin-managed-skills.d.ts.map +1 -0
- package/dist/services/plugin-managed-skills.js +264 -0
- package/dist/services/plugin-managed-skills.js.map +1 -0
- package/dist/services/plugin-manifest-validator.d.ts +79 -0
- package/dist/services/plugin-manifest-validator.d.ts.map +1 -0
- package/dist/services/plugin-manifest-validator.js +84 -0
- package/dist/services/plugin-manifest-validator.js.map +1 -0
- package/dist/services/plugin-registry.d.ts +2550 -0
- package/dist/services/plugin-registry.d.ts.map +1 -0
- package/dist/services/plugin-registry.js +581 -0
- package/dist/services/plugin-registry.js.map +1 -0
- package/dist/services/plugin-runtime-sandbox.d.ts +40 -0
- package/dist/services/plugin-runtime-sandbox.d.ts.map +1 -0
- package/dist/services/plugin-runtime-sandbox.js +154 -0
- package/dist/services/plugin-runtime-sandbox.js.map +1 -0
- package/dist/services/plugin-secrets-handler.d.ts +83 -0
- package/dist/services/plugin-secrets-handler.d.ts.map +1 -0
- package/dist/services/plugin-secrets-handler.js +168 -0
- package/dist/services/plugin-secrets-handler.js.map +1 -0
- package/dist/services/plugin-state-store.d.ts +92 -0
- package/dist/services/plugin-state-store.d.ts.map +1 -0
- package/dist/services/plugin-state-store.js +190 -0
- package/dist/services/plugin-state-store.js.map +1 -0
- package/dist/services/plugin-stream-bus.d.ts +29 -0
- package/dist/services/plugin-stream-bus.d.ts.map +1 -0
- package/dist/services/plugin-stream-bus.js +48 -0
- package/dist/services/plugin-stream-bus.js.map +1 -0
- package/dist/services/plugin-tool-dispatcher.d.ts +180 -0
- package/dist/services/plugin-tool-dispatcher.d.ts.map +1 -0
- package/dist/services/plugin-tool-dispatcher.js +224 -0
- package/dist/services/plugin-tool-dispatcher.js.map +1 -0
- package/dist/services/plugin-tool-registry.d.ts +192 -0
- package/dist/services/plugin-tool-registry.d.ts.map +1 -0
- package/dist/services/plugin-tool-registry.js +224 -0
- package/dist/services/plugin-tool-registry.js.map +1 -0
- package/dist/services/plugin-worker-manager.d.ts +262 -0
- package/dist/services/plugin-worker-manager.d.ts.map +1 -0
- package/dist/services/plugin-worker-manager.js +842 -0
- package/dist/services/plugin-worker-manager.js.map +1 -0
- package/dist/services/productivity-review.d.ts +83 -0
- package/dist/services/productivity-review.d.ts.map +1 -0
- package/dist/services/productivity-review.js +652 -0
- package/dist/services/productivity-review.js.map +1 -0
- package/dist/services/project-workspace-runtime-config.d.ts +4 -0
- package/dist/services/project-workspace-runtime-config.d.ts.map +1 -0
- package/dist/services/project-workspace-runtime-config.js +54 -0
- package/dist/services/project-workspace-runtime-config.js.map +1 -0
- package/dist/services/projects.d.ts +99 -0
- package/dist/services/projects.d.ts.map +1 -0
- package/dist/services/projects.js +822 -0
- package/dist/services/projects.js.map +1 -0
- package/dist/services/quota-windows.d.ts +9 -0
- package/dist/services/quota-windows.d.ts.map +1 -0
- package/dist/services/quota-windows.js +56 -0
- package/dist/services/quota-windows.js.map +1 -0
- package/dist/services/recovery/index.d.ts +10 -0
- package/dist/services/recovery/index.d.ts.map +1 -0
- package/dist/services/recovery/index.js +6 -0
- package/dist/services/recovery/index.js.map +1 -0
- package/dist/services/recovery/issue-graph-liveness.d.ts +85 -0
- package/dist/services/recovery/issue-graph-liveness.d.ts.map +1 -0
- package/dist/services/recovery/issue-graph-liveness.js +356 -0
- package/dist/services/recovery/issue-graph-liveness.js.map +1 -0
- package/dist/services/recovery/model-profile-hint.d.ts +8 -0
- package/dist/services/recovery/model-profile-hint.d.ts.map +1 -0
- package/dist/services/recovery/model-profile-hint.js +11 -0
- package/dist/services/recovery/model-profile-hint.js.map +1 -0
- package/dist/services/recovery/origins.d.ts +36 -0
- package/dist/services/recovery/origins.d.ts.map +1 -0
- package/dist/services/recovery/origins.js +45 -0
- package/dist/services/recovery/origins.js.map +1 -0
- package/dist/services/recovery/pause-hold-guard.d.ts +6 -0
- package/dist/services/recovery/pause-hold-guard.d.ts.map +1 -0
- package/dist/services/recovery/pause-hold-guard.js +6 -0
- package/dist/services/recovery/pause-hold-guard.js.map +1 -0
- package/dist/services/recovery/run-liveness-continuations.d.ts +50 -0
- package/dist/services/recovery/run-liveness-continuations.d.ts.map +1 -0
- package/dist/services/recovery/run-liveness-continuations.js +117 -0
- package/dist/services/recovery/run-liveness-continuations.js.map +1 -0
- package/dist/services/recovery/service.d.ts +256 -0
- package/dist/services/recovery/service.d.ts.map +1 -0
- package/dist/services/recovery/service.js +2441 -0
- package/dist/services/recovery/service.js.map +1 -0
- package/dist/services/recovery/successful-run-handoff.d.ts +89 -0
- package/dist/services/recovery/successful-run-handoff.d.ts.map +1 -0
- package/dist/services/recovery/successful-run-handoff.js +304 -0
- package/dist/services/recovery/successful-run-handoff.js.map +1 -0
- package/dist/services/recovery/successful-run-handoff.test.d.ts +2 -0
- package/dist/services/recovery/successful-run-handoff.test.d.ts.map +1 -0
- package/dist/services/recovery/successful-run-handoff.test.js +270 -0
- package/dist/services/recovery/successful-run-handoff.test.js.map +1 -0
- package/dist/services/routines.d.ts +166 -0
- package/dist/services/routines.d.ts.map +1 -0
- package/dist/services/routines.js +1969 -0
- package/dist/services/routines.js.map +1 -0
- package/dist/services/run-continuations.d.ts +3 -0
- package/dist/services/run-continuations.d.ts.map +1 -0
- package/dist/services/run-continuations.js +2 -0
- package/dist/services/run-continuations.js.map +1 -0
- package/dist/services/run-liveness.d.ts +46 -0
- package/dist/services/run-liveness.d.ts.map +1 -0
- package/dist/services/run-liveness.js +275 -0
- package/dist/services/run-liveness.js.map +1 -0
- package/dist/services/run-log-store.d.ts +34 -0
- package/dist/services/run-log-store.d.ts.map +1 -0
- package/dist/services/run-log-store.js +111 -0
- package/dist/services/run-log-store.js.map +1 -0
- package/dist/services/sandbox-provider-runtime.d.ts +132 -0
- package/dist/services/sandbox-provider-runtime.d.ts.map +1 -0
- package/dist/services/sandbox-provider-runtime.js +216 -0
- package/dist/services/sandbox-provider-runtime.js.map +1 -0
- package/dist/services/secrets.d.ts +1962 -0
- package/dist/services/secrets.d.ts.map +1 -0
- package/dist/services/secrets.js +1686 -0
- package/dist/services/secrets.js.map +1 -0
- package/dist/services/sidebar-badges.d.ts +14 -0
- package/dist/services/sidebar-badges.d.ts.map +1 -0
- package/dist/services/sidebar-badges.js +48 -0
- package/dist/services/sidebar-badges.js.map +1 -0
- package/dist/services/sidebar-preferences.d.ts +9 -0
- package/dist/services/sidebar-preferences.d.ts.map +1 -0
- package/dist/services/sidebar-preferences.js +82 -0
- package/dist/services/sidebar-preferences.js.map +1 -0
- package/dist/services/work-products.d.ts +14 -0
- package/dist/services/work-products.d.ts.map +1 -0
- package/dist/services/work-products.js +100 -0
- package/dist/services/work-products.js.map +1 -0
- package/dist/services/workspace-operation-log-store.d.ts +33 -0
- package/dist/services/workspace-operation-log-store.d.ts.map +1 -0
- package/dist/services/workspace-operation-log-store.js +110 -0
- package/dist/services/workspace-operation-log-store.js.map +1 -0
- package/dist/services/workspace-operations.d.ts +44 -0
- package/dist/services/workspace-operations.d.ts.map +1 -0
- package/dist/services/workspace-operations.js +211 -0
- package/dist/services/workspace-operations.js.map +1 -0
- package/dist/services/workspace-realization.d.ts +33 -0
- package/dist/services/workspace-realization.d.ts.map +1 -0
- package/dist/services/workspace-realization.js +221 -0
- package/dist/services/workspace-realization.js.map +1 -0
- package/dist/services/workspace-runtime-read-model.d.ts +92 -0
- package/dist/services/workspace-runtime-read-model.d.ts.map +1 -0
- package/dist/services/workspace-runtime-read-model.js +67 -0
- package/dist/services/workspace-runtime-read-model.js.map +1 -0
- package/dist/services/workspace-runtime.d.ts +238 -0
- package/dist/services/workspace-runtime.d.ts.map +1 -0
- package/dist/services/workspace-runtime.js +2388 -0
- package/dist/services/workspace-runtime.js.map +1 -0
- package/dist/startup-banner.d.ts +32 -0
- package/dist/startup-banner.d.ts.map +1 -0
- package/dist/startup-banner.js +89 -0
- package/dist/startup-banner.js.map +1 -0
- package/dist/storage/index.d.ts +6 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +29 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/local-disk-provider.d.ts +3 -0
- package/dist/storage/local-disk-provider.d.ts.map +1 -0
- package/dist/storage/local-disk-provider.js +79 -0
- package/dist/storage/local-disk-provider.js.map +1 -0
- package/dist/storage/provider-registry.d.ts +4 -0
- package/dist/storage/provider-registry.d.ts.map +1 -0
- package/dist/storage/provider-registry.js +15 -0
- package/dist/storage/provider-registry.js.map +1 -0
- package/dist/storage/s3-provider.d.ts +11 -0
- package/dist/storage/s3-provider.d.ts.map +1 -0
- package/dist/storage/s3-provider.js +123 -0
- package/dist/storage/s3-provider.js.map +1 -0
- package/dist/storage/service.d.ts +3 -0
- package/dist/storage/service.d.ts.map +1 -0
- package/dist/storage/service.js +120 -0
- package/dist/storage/service.js.map +1 -0
- package/dist/storage/types.d.ts +55 -0
- package/dist/storage/types.d.ts.map +1 -0
- package/dist/storage/types.js +2 -0
- package/dist/storage/types.js.map +1 -0
- package/dist/telemetry.d.ts +6 -0
- package/dist/telemetry.d.ts.map +1 -0
- package/dist/telemetry.js +20 -0
- package/dist/telemetry.js.map +1 -0
- package/dist/ui-branding.d.ts +13 -0
- package/dist/ui-branding.d.ts.map +1 -0
- package/dist/ui-branding.js +188 -0
- package/dist/ui-branding.js.map +1 -0
- package/dist/utils/coalesced-error-logger.d.ts +11 -0
- package/dist/utils/coalesced-error-logger.d.ts.map +1 -0
- package/dist/utils/coalesced-error-logger.js +21 -0
- package/dist/utils/coalesced-error-logger.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +5 -0
- package/dist/version.js.map +1 -0
- package/dist/vite-html-renderer.d.ts +18 -0
- package/dist/vite-html-renderer.d.ts.map +1 -0
- package/dist/vite-html-renderer.js +61 -0
- package/dist/vite-html-renderer.js.map +1 -0
- package/dist/worktree-config.d.ts +19 -0
- package/dist/worktree-config.d.ts.map +1 -0
- package/dist/worktree-config.js +368 -0
- package/dist/worktree-config.js.map +1 -0
- package/package.json +95 -0
- package/skills/deal-desk-outreach/SKILL.md +77 -0
- package/skills/dealdesk/SKILL.md +109 -0
- package/skills/dealdesk/references/api-reference.md +899 -0
- package/skills/dealdesk/references/company-skills.md +193 -0
- package/skills/dealdesk/references/issue-workspaces.md +80 -0
- package/skills/dealdesk/references/routines.md +187 -0
- package/skills/dealdesk/references/workflows.md +141 -0
- package/skills/dealdesk-converting-plans-to-tasks/SKILL.md +110 -0
- package/skills/dealdesk-create-agent/SKILL.md +124 -0
- package/skills/dealdesk-create-agent/references/agent-instruction-templates.md +123 -0
- package/skills/dealdesk-create-agent/references/agents/coder.md +64 -0
- package/skills/dealdesk-create-agent/references/agents/qa.md +88 -0
- package/skills/dealdesk-create-agent/references/agents/securityengineer.md +135 -0
- package/skills/dealdesk-create-agent/references/agents/uxdesigner.md +115 -0
- package/skills/dealdesk-create-agent/references/api-reference.md +110 -0
- package/skills/dealdesk-create-agent/references/baseline-role-guide.md +168 -0
- package/skills/dealdesk-create-agent/references/draft-review-checklist.md +95 -0
- package/skills/dealdesk-create-plugin/SKILL.md +92 -0
- package/skills/dealdesk-dev/SKILL.md +103 -0
- package/skills/diagnose-why-work-stopped/SKILL.md +161 -0
- package/skills/para-memory-files/SKILL.md +104 -0
- package/skills/para-memory-files/references/schemas.md +35 -0
- package/skills/terminal-bench-loop/SKILL.md +236 -0
- package/ui-dist/android-chrome-192x192.png +0 -0
- package/ui-dist/android-chrome-512x512.png +0 -0
- package/ui-dist/apple-touch-icon.png +0 -0
- package/ui-dist/assets/_basePickBy-CaQZTZgE.js +1 -0
- package/ui-dist/assets/_baseUniq-DvA-iyvx.js +1 -0
- package/ui-dist/assets/apl-B4CMkyY2.js +1 -0
- package/ui-dist/assets/arc-_uwl-PL9.js +1 -0
- package/ui-dist/assets/architectureDiagram-VXUJARFQ-hoEr3qym.js +36 -0
- package/ui-dist/assets/asciiarmor-Df11BRmG.js +1 -0
- package/ui-dist/assets/asn1-EdZsLKOL.js +1 -0
- package/ui-dist/assets/asterisk-B-8jnY81.js +1 -0
- package/ui-dist/assets/blockDiagram-VD42YOAC-BpNmbQ9P.js +122 -0
- package/ui-dist/assets/brainfuck-C4LP7Hcl.js +1 -0
- package/ui-dist/assets/c4Diagram-YG6GDRKO-BG14x8dM.js +10 -0
- package/ui-dist/assets/channel-NmuAvKfd.js +1 -0
- package/ui-dist/assets/chunk-4BX2VUAB-Cb1YcG81.js +1 -0
- package/ui-dist/assets/chunk-55IACEB6-DkMTjrQj.js +1 -0
- package/ui-dist/assets/chunk-B4BG7PRW-BD6QmYfE.js +165 -0
- package/ui-dist/assets/chunk-DI55MBZ5-B_xkiL3H.js +220 -0
- package/ui-dist/assets/chunk-FMBD7UC4-DC95tjc1.js +15 -0
- package/ui-dist/assets/chunk-QN33PNHL-BkIJ2KXA.js +1 -0
- package/ui-dist/assets/chunk-QZHKN3VN-BWUNV7If.js +1 -0
- package/ui-dist/assets/chunk-TZMSLE5B-NQYnSIs1.js +1 -0
- package/ui-dist/assets/classDiagram-2ON5EDUG-eS4kRH8R.js +1 -0
- package/ui-dist/assets/classDiagram-v2-WZHVMYZB-eS4kRH8R.js +1 -0
- package/ui-dist/assets/clike-B9uivgTg.js +1 -0
- package/ui-dist/assets/clojure-BMjYHr_A.js +1 -0
- package/ui-dist/assets/clone-CbA0swX6.js +1 -0
- package/ui-dist/assets/cmake-BQqOBYOt.js +1 -0
- package/ui-dist/assets/cobol-CWcv1MsR.js +1 -0
- package/ui-dist/assets/coffeescript-S37ZYGWr.js +1 -0
- package/ui-dist/assets/commonlisp-DBKNyK5s.js +1 -0
- package/ui-dist/assets/cose-bilkent-S5V4N54A-BHo6DkZj.js +1 -0
- package/ui-dist/assets/crystal-SjHAIU92.js +1 -0
- package/ui-dist/assets/css-BnMrqG3P.js +1 -0
- package/ui-dist/assets/cypher-C_CwsFkJ.js +1 -0
- package/ui-dist/assets/cytoscape.esm-jbPEKk2Y.js +321 -0
- package/ui-dist/assets/d-pRatUO7H.js +1 -0
- package/ui-dist/assets/dagre-6UL2VRFP-CfzNlqfr.js +4 -0
- package/ui-dist/assets/defaultLocale-DX6XiGOO.js +1 -0
- package/ui-dist/assets/diagram-PSM6KHXK-DjPk4Vl5.js +24 -0
- package/ui-dist/assets/diagram-QEK2KX5R-ClmlUcpT.js +43 -0
- package/ui-dist/assets/diagram-S2PKOQOG-B68LEXtz.js +24 -0
- package/ui-dist/assets/diff-DbItnlRl.js +1 -0
- package/ui-dist/assets/dockerfile-BKs6k2Af.js +1 -0
- package/ui-dist/assets/dtd-DF_7sFjM.js +1 -0
- package/ui-dist/assets/dylan-DwRh75JA.js +1 -0
- package/ui-dist/assets/ebnf-CDyGwa7X.js +1 -0
- package/ui-dist/assets/ecl-Cabwm37j.js +1 -0
- package/ui-dist/assets/eiffel-CnydiIhH.js +1 -0
- package/ui-dist/assets/elm-vLlmbW-K.js +1 -0
- package/ui-dist/assets/erDiagram-Q2GNP2WA-CJSnga5T.js +60 -0
- package/ui-dist/assets/erlang-BNw1qcRV.js +1 -0
- package/ui-dist/assets/factor-kuTfRLto.js +1 -0
- package/ui-dist/assets/fcl-Kvtd6kyn.js +1 -0
- package/ui-dist/assets/flowDiagram-NV44I4VS-Drmp4DHd.js +162 -0
- package/ui-dist/assets/forth-Ffai-XNe.js +1 -0
- package/ui-dist/assets/fortran-DYz_wnZ1.js +1 -0
- package/ui-dist/assets/ganttDiagram-JELNMOA3-C8ffQ-2u.js +267 -0
- package/ui-dist/assets/gas-Bneqetm1.js +1 -0
- package/ui-dist/assets/gherkin-heZmZLOM.js +1 -0
- package/ui-dist/assets/gitGraphDiagram-V2S2FVAM-CPjF6oPQ.js +65 -0
- package/ui-dist/assets/graph-B2qUgzgo.js +1 -0
- package/ui-dist/assets/groovy-D9Dt4D0W.js +1 -0
- package/ui-dist/assets/haskell-Cw1EW3IL.js +1 -0
- package/ui-dist/assets/haxe-H-WmDvRZ.js +1 -0
- package/ui-dist/assets/http-DBlCnlav.js +1 -0
- package/ui-dist/assets/idl-BEugSyMb.js +1 -0
- package/ui-dist/assets/index-6t3ZNnLR.js +1 -0
- package/ui-dist/assets/index-ARl1W2jj.js +1 -0
- package/ui-dist/assets/index-B9T1xuwJ.js +13 -0
- package/ui-dist/assets/index-BAhZurej.js +2 -0
- package/ui-dist/assets/index-BJ9IksfS.js +1 -0
- package/ui-dist/assets/index-BKv2WUK1.js +1 -0
- package/ui-dist/assets/index-BT7YS1Ir.js +3 -0
- package/ui-dist/assets/index-Bkj-OIiI.js +1 -0
- package/ui-dist/assets/index-CNEquZvK.js +1 -0
- package/ui-dist/assets/index-CPGHpqpR.js +1 -0
- package/ui-dist/assets/index-CW2NmfmI.js +1 -0
- package/ui-dist/assets/index-Cf8smU9e.js +1 -0
- package/ui-dist/assets/index-CrrVEpWP.js +537 -0
- package/ui-dist/assets/index-CtebvrC7.js +1 -0
- package/ui-dist/assets/index-CuwS3-lF.js +1 -0
- package/ui-dist/assets/index-D1D5GrGc.js +1 -0
- package/ui-dist/assets/index-DLN9KwFF.css +1 -0
- package/ui-dist/assets/index-DWfkKcGS.js +1 -0
- package/ui-dist/assets/index-DXzbokce.js +6 -0
- package/ui-dist/assets/index-DY03uqeZ.js +1 -0
- package/ui-dist/assets/index-DnDdXZYl.js +1 -0
- package/ui-dist/assets/index-DvRp33UU.js +1 -0
- package/ui-dist/assets/index-FnWH4Q9P.js +7 -0
- package/ui-dist/assets/index-O_WP0QsK.js +1 -0
- package/ui-dist/assets/infoDiagram-HS3SLOUP-DLOW6p4c.js +2 -0
- package/ui-dist/assets/init-Gi6I4Gst.js +1 -0
- package/ui-dist/assets/javascript-iXu5QeM3.js +1 -0
- package/ui-dist/assets/journeyDiagram-XKPGCS4Q-oYaaSMQP.js +139 -0
- package/ui-dist/assets/julia-DuME0IfC.js +1 -0
- package/ui-dist/assets/kanban-definition-3W4ZIXB7-BE7mgk6q.js +89 -0
- package/ui-dist/assets/katex-B95LWT_Q.js +261 -0
- package/ui-dist/assets/layout-Cq5BDWzM.js +1 -0
- package/ui-dist/assets/linear-HnEHTC6F.js +1 -0
- package/ui-dist/assets/livescript-BwQOo05w.js +1 -0
- package/ui-dist/assets/lua-BgMRiT3U.js +1 -0
- package/ui-dist/assets/mathematica-DTrFuWx2.js +1 -0
- package/ui-dist/assets/mbox-CNhZ1qSd.js +1 -0
- package/ui-dist/assets/mermaid.core-JMROPF3S.js +250 -0
- package/ui-dist/assets/mindmap-definition-VGOIOE7T-DoeZEBQU.js +68 -0
- package/ui-dist/assets/mirc-CjQqDB4T.js +1 -0
- package/ui-dist/assets/mllike-CXdrOF99.js +1 -0
- package/ui-dist/assets/modelica-Dc1JOy9r.js +1 -0
- package/ui-dist/assets/mscgen-BA5vi2Kp.js +1 -0
- package/ui-dist/assets/mumps-BT43cFF4.js +1 -0
- package/ui-dist/assets/nginx-DdIZxoE0.js +1 -0
- package/ui-dist/assets/nsis-LdVXkNf5.js +1 -0
- package/ui-dist/assets/ntriples-BfvgReVJ.js +1 -0
- package/ui-dist/assets/octave-Ck1zUtKM.js +1 -0
- package/ui-dist/assets/ordinal-Cboi1Yqb.js +1 -0
- package/ui-dist/assets/oz-BzwKVEFT.js +1 -0
- package/ui-dist/assets/pascal--L3eBynH.js +1 -0
- package/ui-dist/assets/perl-CdXCOZ3F.js +1 -0
- package/ui-dist/assets/pieDiagram-ADFJNKIX-BtfKQ-xw.js +30 -0
- package/ui-dist/assets/pig-CevX1Tat.js +1 -0
- package/ui-dist/assets/powershell-CFHJl5sT.js +1 -0
- package/ui-dist/assets/properties-C78fOPTZ.js +1 -0
- package/ui-dist/assets/protobuf-ChK-085T.js +1 -0
- package/ui-dist/assets/pug-DeIclll2.js +1 -0
- package/ui-dist/assets/puppet-DMA9R1ak.js +1 -0
- package/ui-dist/assets/python-BuPzkPfP.js +1 -0
- package/ui-dist/assets/q-pXgVlZs6.js +1 -0
- package/ui-dist/assets/quadrantDiagram-AYHSOK5B-CIrjVDBB.js +7 -0
- package/ui-dist/assets/r-B6wPVr8A.js +1 -0
- package/ui-dist/assets/requirementDiagram-UZGBJVZJ-CNQ5h-EW.js +64 -0
- package/ui-dist/assets/rpm-CTu-6PCP.js +1 -0
- package/ui-dist/assets/ruby-B2Rjki9n.js +1 -0
- package/ui-dist/assets/sankeyDiagram-TZEHDZUN-CrOSPDz5.js +10 -0
- package/ui-dist/assets/sas-B4kiWyti.js +1 -0
- package/ui-dist/assets/scheme-C41bIUwD.js +1 -0
- package/ui-dist/assets/sequenceDiagram-WL72ISMW-D96XuK7n.js +145 -0
- package/ui-dist/assets/shell-CjFT_Tl9.js +1 -0
- package/ui-dist/assets/sieve-C3Gn_uJK.js +1 -0
- package/ui-dist/assets/simple-mode-GW_nhZxv.js +1 -0
- package/ui-dist/assets/smalltalk-CnHTOXQT.js +1 -0
- package/ui-dist/assets/solr-DehyRSwq.js +1 -0
- package/ui-dist/assets/sparql-DkYu6x3z.js +1 -0
- package/ui-dist/assets/spreadsheet-BCZA_wO0.js +1 -0
- package/ui-dist/assets/sql-D0XecflT.js +1 -0
- package/ui-dist/assets/stateDiagram-FKZM4ZOC-BOf9izkD.js +1 -0
- package/ui-dist/assets/stateDiagram-v2-4FDKWEC3-DEhq019K.js +1 -0
- package/ui-dist/assets/stex-C3f8Ysf7.js +1 -0
- package/ui-dist/assets/stylus-B533Al4x.js +1 -0
- package/ui-dist/assets/swift-BzpIVaGY.js +1 -0
- package/ui-dist/assets/tcl-DVfN8rqt.js +1 -0
- package/ui-dist/assets/textile-CnDTJFAw.js +1 -0
- package/ui-dist/assets/tiddlywiki-DO-Gjzrf.js +1 -0
- package/ui-dist/assets/tiki-DGYXhP31.js +1 -0
- package/ui-dist/assets/timeline-definition-IT6M3QCI-_lAaYcUI.js +61 -0
- package/ui-dist/assets/toml-Bm5Em-hy.js +1 -0
- package/ui-dist/assets/treemap-GDKQZRPO-BS18z8ox.js +154 -0
- package/ui-dist/assets/troff-wAsdV37c.js +1 -0
- package/ui-dist/assets/ttcn-CfJYG6tj.js +1 -0
- package/ui-dist/assets/ttcn-cfg-B9xdYoR4.js +1 -0
- package/ui-dist/assets/turtle-B1tBg_DP.js +1 -0
- package/ui-dist/assets/vb-CmGdzxic.js +1 -0
- package/ui-dist/assets/vbscript-BuJXcnF6.js +1 -0
- package/ui-dist/assets/velocity-D8B20fx6.js +1 -0
- package/ui-dist/assets/verilog-C6RDOZhf.js +1 -0
- package/ui-dist/assets/vhdl-lSbBsy5d.js +1 -0
- package/ui-dist/assets/webidl-ZXfAyPTL.js +1 -0
- package/ui-dist/assets/xquery-DzFWVndE.js +1 -0
- package/ui-dist/assets/xychartDiagram-PRI3JC2R-X82nn6D0.js +7 -0
- package/ui-dist/assets/yacas-BJ4BC0dw.js +1 -0
- package/ui-dist/assets/z80-Hz9HOZM7.js +1 -0
- package/ui-dist/brands/opencode-logo-dark-square.svg +18 -0
- package/ui-dist/brands/opencode-logo-light-square.svg +18 -0
- package/ui-dist/favicon-16x16.png +0 -0
- package/ui-dist/favicon-32x32.png +0 -0
- package/ui-dist/favicon.ico +0 -0
- package/ui-dist/favicon.svg +10 -0
- package/ui-dist/index.html +49 -0
- package/ui-dist/site.webmanifest +30 -0
- package/ui-dist/sw.js +42 -0
- package/ui-dist/worktree-favicon-16x16.png +0 -0
- package/ui-dist/worktree-favicon-32x32.png +0 -0
- package/ui-dist/worktree-favicon.ico +0 -0
- package/ui-dist/worktree-favicon.svg +10 -0
|
@@ -0,0 +1,4094 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { Router } from "express";
|
|
3
|
+
import multer from "multer";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { and, desc, eq, inArray, notInArray } from "drizzle-orm";
|
|
6
|
+
import { activityLog, executionWorkspaces, issueExecutionDecisions, issueRelations, issues as issueRows, projectWorkspaces, } from "@dealdesk/db";
|
|
7
|
+
import { addIssueCommentSchema, acceptIssueThreadInteractionSchema, cancelIssueThreadInteractionSchema, companySearchQuerySchema, createIssueAttachmentMetadataSchema, createIssueThreadInteractionSchema, createIssueWorkProductSchema, createIssueLabelSchema, checkoutIssueSchema, createChildIssueSchema, createIssueSchema, resolveCreateIssueStatusDefault, resolveIssueRecoveryActionSchema, feedbackTargetTypeSchema, feedbackTraceStatusSchema, feedbackVoteValueSchema, upsertIssueFeedbackVoteSchema, linkIssueApprovalSchema, issueDocumentKeySchema, ISSUE_CONTINUATION_SUMMARY_DOCUMENT_KEY, rejectIssueThreadInteractionSchema, restoreIssueDocumentRevisionSchema, respondIssueThreadInteractionSchema, updateIssueWorkProductSchema, upsertIssueDocumentSchema, updateIssueSchema, getClosedIsolatedExecutionWorkspaceMessage, isClosedIsolatedExecutionWorkspace, normalizeIssueIdentifier as normalizeIssueReferenceIdentifier, } from "@dealdesk/shared";
|
|
8
|
+
import { trackAgentTaskCompleted } from "@dealdesk/shared/telemetry";
|
|
9
|
+
import { getTelemetryClient } from "../telemetry.js";
|
|
10
|
+
import { validate } from "../middleware/validate.js";
|
|
11
|
+
import * as serviceIndex from "../services/index.js";
|
|
12
|
+
import { accessService, agentService, companyService, companySearchService, heartbeatService, issueApprovalService, issueRecoveryActionService, issueThreadInteractionService, ISSUE_LIST_DEFAULT_LIMIT, ISSUE_LIST_MAX_LIMIT, issueReferenceService, issueService, clampIssueListLimit, documentService, logActivity, projectService, routineService, workProductService, } from "../services/index.js";
|
|
13
|
+
import { logger } from "../middleware/logger.js";
|
|
14
|
+
import { conflict, forbidden, HttpError, notFound, unauthorized, unprocessable } from "../errors.js";
|
|
15
|
+
import { assertBoard, assertCompanyAccess, getActorInfo } from "./authz.js";
|
|
16
|
+
import { assertNoAgentHostWorkspaceCommandMutation, collectIssueWorkspaceCommandPaths, } from "./workspace-command-authz.js";
|
|
17
|
+
import { shouldWakeAssigneeOnCheckout } from "./issues-checkout-wakeup.js";
|
|
18
|
+
import { isInlineAttachmentContentType, normalizeIssueAttachmentMaxBytes, normalizeContentType, SVG_CONTENT_TYPE, } from "../attachment-types.js";
|
|
19
|
+
import { queueIssueAssignmentWakeup } from "../services/issue-assignment-wakeup.js";
|
|
20
|
+
import { assertEnvironmentSelectionForCompany } from "./environment-selection.js";
|
|
21
|
+
import { executionWorkspaceService as executionWorkspaceServiceDirect } from "../services/execution-workspaces.js";
|
|
22
|
+
import { feedbackService } from "../services/feedback.js";
|
|
23
|
+
import { instanceSettingsService } from "../services/instance-settings.js";
|
|
24
|
+
import { environmentService } from "../services/environments.js";
|
|
25
|
+
import { redactSensitiveText } from "../redaction.js";
|
|
26
|
+
import { createCompanySearchRateLimiter, } from "../services/company-search-rate-limit.js";
|
|
27
|
+
import { applyIssueExecutionPolicyTransition, normalizeIssueExecutionPolicy, parseIssueExecutionState, redactIssueMonitorExternalRef, setIssueExecutionPolicyMonitorScheduledBy, } from "../services/issue-execution-policy.js";
|
|
28
|
+
import { parseIssueExecutionWorkspaceSettings } from "../services/execution-workspace-policy.js";
|
|
29
|
+
const MAX_ISSUE_COMMENT_LIMIT = 500;
|
|
30
|
+
const updateIssueRouteSchema = updateIssueSchema.extend({
|
|
31
|
+
interrupt: z.boolean().optional(),
|
|
32
|
+
});
|
|
33
|
+
function applyCreateIssueStatusDefault(req, res, next) {
|
|
34
|
+
if (!req.body || typeof req.body !== "object" || Array.isArray(req.body)) {
|
|
35
|
+
next();
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const resolution = resolveCreateIssueStatusDefault(req.body);
|
|
39
|
+
res.locals.createIssueStatusDefault = resolution;
|
|
40
|
+
if (resolution.defaulted) {
|
|
41
|
+
req.body = {
|
|
42
|
+
...req.body,
|
|
43
|
+
status: resolution.status,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
next();
|
|
47
|
+
}
|
|
48
|
+
function buildCreateIssueActivityStatusDetails(issue, res) {
|
|
49
|
+
const statusDefault = res.locals.createIssueStatusDefault;
|
|
50
|
+
const assignmentWakeSkipped = !issue.assigneeAgentId || issue.status === "backlog";
|
|
51
|
+
return {
|
|
52
|
+
status: issue.status,
|
|
53
|
+
statusDefaulted: statusDefault?.defaulted ?? false,
|
|
54
|
+
statusDefaultReason: statusDefault?.reason ?? "explicit",
|
|
55
|
+
assignmentWakeSkipped,
|
|
56
|
+
assignmentWakeSkipReason: assignmentWakeSkipped
|
|
57
|
+
? issue.assigneeAgentId
|
|
58
|
+
? "assigned_backlog"
|
|
59
|
+
: "no_agent_assignee"
|
|
60
|
+
: null,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
const SUCCESSFUL_RUN_HANDOFF_ACTIONS = [
|
|
64
|
+
"issue.successful_run_handoff_required",
|
|
65
|
+
"issue.successful_run_handoff_resolved",
|
|
66
|
+
"issue.successful_run_handoff_escalated",
|
|
67
|
+
];
|
|
68
|
+
const ISSUE_WORKSPACE_AUDIT_FIELDS = new Set([
|
|
69
|
+
"projectWorkspaceId",
|
|
70
|
+
"executionWorkspaceId",
|
|
71
|
+
"executionWorkspacePreference",
|
|
72
|
+
"executionWorkspaceSettings",
|
|
73
|
+
]);
|
|
74
|
+
function readNonEmptyString(value) {
|
|
75
|
+
return typeof value === "string" && value.trim().length > 0 ? value.trim() : null;
|
|
76
|
+
}
|
|
77
|
+
function hasIssueWorkspaceAuditChange(previous) {
|
|
78
|
+
return Object.keys(previous).some((key) => ISSUE_WORKSPACE_AUDIT_FIELDS.has(key));
|
|
79
|
+
}
|
|
80
|
+
function labelIssueWorkspaceMode(mode) {
|
|
81
|
+
switch (mode) {
|
|
82
|
+
case "shared_workspace":
|
|
83
|
+
return "Project default";
|
|
84
|
+
case "isolated_workspace":
|
|
85
|
+
return "New isolated workspace";
|
|
86
|
+
case "operator_branch":
|
|
87
|
+
return "Operator branch";
|
|
88
|
+
case "reuse_existing":
|
|
89
|
+
return "Reuse existing workspace";
|
|
90
|
+
case "agent_default":
|
|
91
|
+
return "Agent default";
|
|
92
|
+
case "inherit":
|
|
93
|
+
return "Inherited workspace";
|
|
94
|
+
default:
|
|
95
|
+
return "No workspace";
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function emptyWorkspaceNameMaps() {
|
|
99
|
+
return {
|
|
100
|
+
projectWorkspaceNames: new Map(),
|
|
101
|
+
executionWorkspaceNames: new Map(),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
function summarizeIssueWorkspaceForActivity(issue, names) {
|
|
105
|
+
const settings = parseIssueExecutionWorkspaceSettings(issue.executionWorkspaceSettings);
|
|
106
|
+
const mode = settings?.mode ?? issue.executionWorkspacePreference ?? null;
|
|
107
|
+
const executionWorkspaceId = issue.executionWorkspaceId ?? null;
|
|
108
|
+
const projectWorkspaceId = issue.projectWorkspaceId ?? null;
|
|
109
|
+
const label = (() => {
|
|
110
|
+
if (executionWorkspaceId) {
|
|
111
|
+
return names.executionWorkspaceNames.get(executionWorkspaceId) ?? `Workspace ${executionWorkspaceId.slice(0, 8)}`;
|
|
112
|
+
}
|
|
113
|
+
if (projectWorkspaceId) {
|
|
114
|
+
return names.projectWorkspaceNames.get(projectWorkspaceId) ?? `Workspace ${projectWorkspaceId.slice(0, 8)}`;
|
|
115
|
+
}
|
|
116
|
+
return labelIssueWorkspaceMode(mode);
|
|
117
|
+
})();
|
|
118
|
+
return {
|
|
119
|
+
label,
|
|
120
|
+
projectWorkspaceId,
|
|
121
|
+
executionWorkspaceId,
|
|
122
|
+
mode,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
async function buildIssueWorkspaceChangeActivityDetails(db, companyId, previousIssue, nextIssue) {
|
|
126
|
+
const projectWorkspaceIds = [
|
|
127
|
+
previousIssue.projectWorkspaceId,
|
|
128
|
+
nextIssue.projectWorkspaceId,
|
|
129
|
+
].filter((value) => typeof value === "string" && value.length > 0);
|
|
130
|
+
const executionWorkspaceIds = [
|
|
131
|
+
previousIssue.executionWorkspaceId,
|
|
132
|
+
nextIssue.executionWorkspaceId,
|
|
133
|
+
].filter((value) => typeof value === "string" && value.length > 0);
|
|
134
|
+
const [projectRows, executionRows] = await Promise.all([
|
|
135
|
+
projectWorkspaceIds.length > 0
|
|
136
|
+
? db
|
|
137
|
+
.select({ id: projectWorkspaces.id, name: projectWorkspaces.name })
|
|
138
|
+
.from(projectWorkspaces)
|
|
139
|
+
.where(and(eq(projectWorkspaces.companyId, companyId), inArray(projectWorkspaces.id, projectWorkspaceIds)))
|
|
140
|
+
: Promise.resolve([]),
|
|
141
|
+
executionWorkspaceIds.length > 0
|
|
142
|
+
? db
|
|
143
|
+
.select({ id: executionWorkspaces.id, name: executionWorkspaces.name })
|
|
144
|
+
.from(executionWorkspaces)
|
|
145
|
+
.where(and(eq(executionWorkspaces.companyId, companyId), inArray(executionWorkspaces.id, executionWorkspaceIds)))
|
|
146
|
+
: Promise.resolve([]),
|
|
147
|
+
]);
|
|
148
|
+
const names = {
|
|
149
|
+
projectWorkspaceNames: new Map(projectRows.map((row) => [row.id, row.name])),
|
|
150
|
+
executionWorkspaceNames: new Map(executionRows.map((row) => [row.id, row.name])),
|
|
151
|
+
};
|
|
152
|
+
return {
|
|
153
|
+
from: summarizeIssueWorkspaceForActivity(previousIssue, names),
|
|
154
|
+
to: summarizeIssueWorkspaceForActivity(nextIssue, names),
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
function hasExecutionParticipant(value) {
|
|
158
|
+
const state = parseIssueExecutionState(value);
|
|
159
|
+
if (!state || state.status !== "pending")
|
|
160
|
+
return false;
|
|
161
|
+
const participant = state.currentParticipant;
|
|
162
|
+
if (!participant)
|
|
163
|
+
return false;
|
|
164
|
+
if (participant.type === "agent")
|
|
165
|
+
return Boolean(participant.agentId);
|
|
166
|
+
if (participant.type === "user")
|
|
167
|
+
return Boolean(participant.userId);
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
function hasScheduledMonitor(input) {
|
|
171
|
+
if (input.patchMonitorNextCheckAt instanceof Date && !Number.isNaN(input.patchMonitorNextCheckAt.getTime()))
|
|
172
|
+
return true;
|
|
173
|
+
if (input.patchMonitorNextCheckAt === undefined && input.existingMonitorNextCheckAt)
|
|
174
|
+
return true;
|
|
175
|
+
const policy = normalizeIssueExecutionPolicy(input.executionPolicy ?? null);
|
|
176
|
+
return Boolean(policy?.monitor?.nextCheckAt);
|
|
177
|
+
}
|
|
178
|
+
function successfulRunHandoffStateFromActivity(row) {
|
|
179
|
+
const details = row.details ?? {};
|
|
180
|
+
const state = row.action === "issue.successful_run_handoff_required"
|
|
181
|
+
? "required"
|
|
182
|
+
: row.action === "issue.successful_run_handoff_resolved"
|
|
183
|
+
? "resolved"
|
|
184
|
+
: row.action === "issue.successful_run_handoff_escalated"
|
|
185
|
+
? "escalated"
|
|
186
|
+
: null;
|
|
187
|
+
if (!state)
|
|
188
|
+
return null;
|
|
189
|
+
const detectedProgressSummary = readNonEmptyString(details.detectedProgressSummary)
|
|
190
|
+
?? readNonEmptyString(details.detected_progress_summary)
|
|
191
|
+
?? null;
|
|
192
|
+
return {
|
|
193
|
+
state,
|
|
194
|
+
required: state === "required",
|
|
195
|
+
sourceRunId: readNonEmptyString(details.sourceRunId)
|
|
196
|
+
?? readNonEmptyString(details.source_run_id)
|
|
197
|
+
?? readNonEmptyString(details.resumeFromRunId)
|
|
198
|
+
?? row.runId
|
|
199
|
+
?? null,
|
|
200
|
+
correctiveRunId: readNonEmptyString(details.correctiveRunId)
|
|
201
|
+
?? readNonEmptyString(details.corrective_run_id)
|
|
202
|
+
?? (state !== "required" ? row.runId : null),
|
|
203
|
+
assigneeAgentId: readNonEmptyString(details.assigneeAgentId)
|
|
204
|
+
?? readNonEmptyString(details.agentId)
|
|
205
|
+
?? row.agentId
|
|
206
|
+
?? null,
|
|
207
|
+
detectedProgressSummary: detectedProgressSummary
|
|
208
|
+
? redactSensitiveText(detectedProgressSummary)
|
|
209
|
+
: null,
|
|
210
|
+
createdAt: row.createdAt,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
async function listSuccessfulRunHandoffStates(db, companyId, issueIds) {
|
|
214
|
+
if (issueIds.length === 0)
|
|
215
|
+
return new Map();
|
|
216
|
+
const rows = await db
|
|
217
|
+
.select({
|
|
218
|
+
entityId: activityLog.entityId,
|
|
219
|
+
action: activityLog.action,
|
|
220
|
+
agentId: activityLog.agentId,
|
|
221
|
+
runId: activityLog.runId,
|
|
222
|
+
details: activityLog.details,
|
|
223
|
+
createdAt: activityLog.createdAt,
|
|
224
|
+
})
|
|
225
|
+
.from(activityLog)
|
|
226
|
+
.where(and(eq(activityLog.companyId, companyId), eq(activityLog.entityType, "issue"), inArray(activityLog.entityId, issueIds), inArray(activityLog.action, [...SUCCESSFUL_RUN_HANDOFF_ACTIONS])))
|
|
227
|
+
.orderBy(activityLog.entityId, desc(activityLog.createdAt), desc(activityLog.id));
|
|
228
|
+
const states = new Map();
|
|
229
|
+
for (const row of rows) {
|
|
230
|
+
if (states.has(row.entityId))
|
|
231
|
+
continue;
|
|
232
|
+
const state = successfulRunHandoffStateFromActivity(row);
|
|
233
|
+
if (state)
|
|
234
|
+
states.set(row.entityId, state);
|
|
235
|
+
}
|
|
236
|
+
return states;
|
|
237
|
+
}
|
|
238
|
+
async function relationRecoveryActionMap(recoveryActionsSvc, companyId, relations) {
|
|
239
|
+
const candidates = [];
|
|
240
|
+
const visit = (summary) => {
|
|
241
|
+
candidates.push(summary);
|
|
242
|
+
for (const terminal of summary.terminalBlockers ?? []) {
|
|
243
|
+
visit(terminal);
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
for (const blocker of relations.blockedBy)
|
|
247
|
+
visit(blocker);
|
|
248
|
+
for (const blocking of relations.blocks)
|
|
249
|
+
visit(blocking);
|
|
250
|
+
if (candidates.length === 0)
|
|
251
|
+
return new Map();
|
|
252
|
+
const ids = [...new Set(candidates.map((summary) => summary.id))];
|
|
253
|
+
return recoveryActionsSvc.listActiveForIssues(companyId, ids);
|
|
254
|
+
}
|
|
255
|
+
function withRecoveryActionsOnRelationSummaries(relations, recoveryActionByIssueId) {
|
|
256
|
+
const augment = (summary) => ({
|
|
257
|
+
...summary,
|
|
258
|
+
activeRecoveryAction: recoveryActionByIssueId.get(summary.id) ?? summary.activeRecoveryAction ?? null,
|
|
259
|
+
terminalBlockers: summary.terminalBlockers?.map(augment),
|
|
260
|
+
});
|
|
261
|
+
return {
|
|
262
|
+
blockedBy: relations.blockedBy.map(augment),
|
|
263
|
+
blocks: relations.blocks.map(augment),
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
const ACTIVE_REVIEW_APPROVAL_STATUSES = new Set(["pending", "revision_requested"]);
|
|
267
|
+
const INVALID_AGENT_IN_REVIEW_DISPOSITION_MESSAGE = "invalid_issue_disposition: Agent-authored updates that move an issue to in_review must include a real review path. " +
|
|
268
|
+
"This request would leave the issue in_review without anyone or anything owning the next action. " +
|
|
269
|
+
"Keep working instead of moving to review, create a request_confirmation or ask_user_questions interaction, " +
|
|
270
|
+
"link or request a pending approval, assign a human reviewer with assigneeUserId, set a typed executionState.currentParticipant through an execution policy, " +
|
|
271
|
+
"or schedule an issue monitor for an external review/check. After creating one of those review paths, retry the status update.";
|
|
272
|
+
function executionPrincipalsEqual(left, right) {
|
|
273
|
+
if (!left || !right || left.type !== right.type)
|
|
274
|
+
return false;
|
|
275
|
+
return left.type === "agent" ? left.agentId === right.agentId : left.userId === right.userId;
|
|
276
|
+
}
|
|
277
|
+
function buildExecutionStageWakeContext(input) {
|
|
278
|
+
return {
|
|
279
|
+
wakeRole: input.wakeRole,
|
|
280
|
+
stageId: input.state.currentStageId,
|
|
281
|
+
stageType: input.state.currentStageType,
|
|
282
|
+
currentParticipant: input.state.currentParticipant,
|
|
283
|
+
returnAssignee: input.state.returnAssignee,
|
|
284
|
+
reviewRequest: input.state.reviewRequest ?? null,
|
|
285
|
+
lastDecisionOutcome: input.state.lastDecisionOutcome,
|
|
286
|
+
allowedActions: input.allowedActions,
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
function summarizeIssueRelationForActivity(relation) {
|
|
290
|
+
return {
|
|
291
|
+
id: relation.id,
|
|
292
|
+
identifier: relation.identifier,
|
|
293
|
+
title: relation.title,
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
const defaultCompanySearchRateLimiter = createCompanySearchRateLimiter();
|
|
297
|
+
function companySearchRateLimitActor(req, companyId) {
|
|
298
|
+
if (req.actor.type === "agent") {
|
|
299
|
+
return {
|
|
300
|
+
companyId,
|
|
301
|
+
actorType: "agent",
|
|
302
|
+
actorId: req.actor.agentId ?? req.actor.keyId ?? "unknown-agent",
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
return {
|
|
306
|
+
companyId,
|
|
307
|
+
actorType: "board",
|
|
308
|
+
actorId: req.actor.userId ?? req.actor.source ?? "board",
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
function summarizeIssueReferenceActivityDetails(input) {
|
|
312
|
+
if (!input)
|
|
313
|
+
return {};
|
|
314
|
+
return {
|
|
315
|
+
...(input.addedReferencedIssues.length > 0 ? { addedReferencedIssues: input.addedReferencedIssues } : {}),
|
|
316
|
+
...(input.removedReferencedIssues.length > 0 ? { removedReferencedIssues: input.removedReferencedIssues } : {}),
|
|
317
|
+
...(input.currentReferencedIssues.length > 0 ? { currentReferencedIssues: input.currentReferencedIssues } : {}),
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
function monitorPoliciesEqual(left, right) {
|
|
321
|
+
return JSON.stringify(left?.monitor ?? null) === JSON.stringify(right?.monitor ?? null);
|
|
322
|
+
}
|
|
323
|
+
function applyActorMonitorScheduledBy(policy, actorType) {
|
|
324
|
+
return setIssueExecutionPolicyMonitorScheduledBy(policy, actorType === "user" ? "board" : "assignee");
|
|
325
|
+
}
|
|
326
|
+
function assertCanManageIssueMonitor(req, assigneeAgentId, monitorChanged) {
|
|
327
|
+
if (!monitorChanged)
|
|
328
|
+
return;
|
|
329
|
+
if (req.actor.type === "board")
|
|
330
|
+
return;
|
|
331
|
+
if (req.actor.type === "agent" && req.actor.agentId && req.actor.agentId === assigneeAgentId)
|
|
332
|
+
return;
|
|
333
|
+
throw forbidden("Only the assignee agent or a board user can manage issue monitors");
|
|
334
|
+
}
|
|
335
|
+
function summarizeIssueMonitor(issue, policy) {
|
|
336
|
+
const state = parseIssueExecutionState(issue.executionState);
|
|
337
|
+
return {
|
|
338
|
+
nextCheckAt: issue.monitorNextCheckAt?.toISOString() ?? policy?.monitor?.nextCheckAt ?? null,
|
|
339
|
+
lastTriggeredAt: issue.monitorLastTriggeredAt?.toISOString() ?? state?.monitor?.lastTriggeredAt ?? null,
|
|
340
|
+
attemptCount: issue.monitorAttemptCount ?? state?.monitor?.attemptCount ?? 0,
|
|
341
|
+
notes: policy?.monitor?.notes ?? issue.monitorNotes ?? state?.monitor?.notes ?? null,
|
|
342
|
+
scheduledBy: issue.monitorScheduledBy ?? policy?.monitor?.scheduledBy ?? state?.monitor?.scheduledBy ?? null,
|
|
343
|
+
kind: policy?.monitor?.kind ?? state?.monitor?.kind ?? null,
|
|
344
|
+
serviceName: policy?.monitor?.serviceName ?? state?.monitor?.serviceName ?? null,
|
|
345
|
+
externalRef: redactIssueMonitorExternalRef(policy?.monitor?.externalRef ?? state?.monitor?.externalRef ?? null),
|
|
346
|
+
timeoutAt: policy?.monitor?.timeoutAt ?? state?.monitor?.timeoutAt ?? null,
|
|
347
|
+
maxAttempts: policy?.monitor?.maxAttempts ?? state?.monitor?.maxAttempts ?? null,
|
|
348
|
+
recoveryPolicy: policy?.monitor?.recoveryPolicy ?? state?.monitor?.recoveryPolicy ?? null,
|
|
349
|
+
status: state?.monitor?.status ?? (policy?.monitor ? "scheduled" : null),
|
|
350
|
+
clearReason: state?.monitor?.clearReason ?? null,
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
function activityExecutionParticipantKey(participant) {
|
|
354
|
+
return participant.type === "agent" ? `agent:${participant.agentId}` : `user:${participant.userId}`;
|
|
355
|
+
}
|
|
356
|
+
function summarizeExecutionParticipants(policy, stageType) {
|
|
357
|
+
const stage = policy?.stages.find((candidate) => candidate.type === stageType);
|
|
358
|
+
return (stage?.participants.map((participant) => ({
|
|
359
|
+
type: participant.type,
|
|
360
|
+
agentId: participant.agentId ?? null,
|
|
361
|
+
userId: participant.userId ?? null,
|
|
362
|
+
})) ?? []);
|
|
363
|
+
}
|
|
364
|
+
function isClosedIssueStatus(status) {
|
|
365
|
+
return status === "done" || status === "cancelled";
|
|
366
|
+
}
|
|
367
|
+
function shouldImplicitlyMoveCommentedIssueToTodo(input) {
|
|
368
|
+
// Only human comments should implicitly reopen finished work.
|
|
369
|
+
// Agent-authored comments remain communicative unless reopen was explicit.
|
|
370
|
+
if (input.actorType !== "user")
|
|
371
|
+
return false;
|
|
372
|
+
if (!isClosedIssueStatus(input.issueStatus) && input.issueStatus !== "blocked")
|
|
373
|
+
return false;
|
|
374
|
+
if (typeof input.assigneeAgentId !== "string" || input.assigneeAgentId.length === 0)
|
|
375
|
+
return false;
|
|
376
|
+
return true;
|
|
377
|
+
}
|
|
378
|
+
function isExplicitResumeCapableStatus(status) {
|
|
379
|
+
return status === "done" || status === "blocked" || status === "todo" || status === "in_progress";
|
|
380
|
+
}
|
|
381
|
+
function queueResolvedInteractionContinuationWakeup(input) {
|
|
382
|
+
if (input.interaction.continuationPolicy !== "wake_assignee"
|
|
383
|
+
&& input.interaction.continuationPolicy !== "wake_assignee_on_accept")
|
|
384
|
+
return;
|
|
385
|
+
if (input.interaction.continuationPolicy === "wake_assignee_on_accept"
|
|
386
|
+
&& input.interaction.status !== "accepted")
|
|
387
|
+
return;
|
|
388
|
+
if (input.interaction.status === "expired")
|
|
389
|
+
return;
|
|
390
|
+
if (!input.issue.assigneeAgentId || isClosedIssueStatus(input.issue.status))
|
|
391
|
+
return;
|
|
392
|
+
void input.heartbeat.wakeup(input.issue.assigneeAgentId, {
|
|
393
|
+
source: "automation",
|
|
394
|
+
triggerDetail: "system",
|
|
395
|
+
reason: "issue_commented",
|
|
396
|
+
payload: {
|
|
397
|
+
issueId: input.issue.id,
|
|
398
|
+
interactionId: input.interaction.id,
|
|
399
|
+
interactionKind: input.interaction.kind,
|
|
400
|
+
interactionStatus: input.interaction.status,
|
|
401
|
+
sourceCommentId: input.interaction.sourceCommentId ?? null,
|
|
402
|
+
sourceRunId: input.interaction.sourceRunId ?? null,
|
|
403
|
+
mutation: "interaction",
|
|
404
|
+
},
|
|
405
|
+
requestedByActorType: input.actor.actorType,
|
|
406
|
+
requestedByActorId: input.actor.actorId,
|
|
407
|
+
contextSnapshot: {
|
|
408
|
+
issueId: input.issue.id,
|
|
409
|
+
taskId: input.issue.id,
|
|
410
|
+
interactionId: input.interaction.id,
|
|
411
|
+
interactionKind: input.interaction.kind,
|
|
412
|
+
interactionStatus: input.interaction.status,
|
|
413
|
+
sourceCommentId: input.interaction.sourceCommentId ?? null,
|
|
414
|
+
sourceRunId: input.interaction.sourceRunId ?? null,
|
|
415
|
+
wakeReason: "issue_commented",
|
|
416
|
+
source: input.source,
|
|
417
|
+
},
|
|
418
|
+
}).catch((err) => logger.warn({
|
|
419
|
+
err,
|
|
420
|
+
issueId: input.issue.id,
|
|
421
|
+
interactionId: input.interaction.id,
|
|
422
|
+
agentId: input.issue.assigneeAgentId,
|
|
423
|
+
}, "failed to wake assignee on issue interaction resolution"));
|
|
424
|
+
}
|
|
425
|
+
function diffExecutionParticipants(previousPolicy, nextPolicy, stageType) {
|
|
426
|
+
const previousParticipants = summarizeExecutionParticipants(previousPolicy, stageType);
|
|
427
|
+
const nextParticipants = summarizeExecutionParticipants(nextPolicy, stageType);
|
|
428
|
+
const previousByKey = new Map(previousParticipants.map((participant) => [
|
|
429
|
+
activityExecutionParticipantKey(participant),
|
|
430
|
+
participant,
|
|
431
|
+
]));
|
|
432
|
+
const nextByKey = new Map(nextParticipants.map((participant) => [
|
|
433
|
+
activityExecutionParticipantKey(participant),
|
|
434
|
+
participant,
|
|
435
|
+
]));
|
|
436
|
+
return {
|
|
437
|
+
participants: nextParticipants,
|
|
438
|
+
addedParticipants: nextParticipants.filter((participant) => !previousByKey.has(activityExecutionParticipantKey(participant))),
|
|
439
|
+
removedParticipants: previousParticipants.filter((participant) => !nextByKey.has(activityExecutionParticipantKey(participant))),
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
function buildExecutionStageWakeup(input) {
|
|
443
|
+
const { issueId, previousState, nextState, interruptedRunId } = input;
|
|
444
|
+
if (!nextState)
|
|
445
|
+
return null;
|
|
446
|
+
if (nextState.status === "pending") {
|
|
447
|
+
const agentId = nextState.currentParticipant?.type === "agent" ? (nextState.currentParticipant.agentId ?? null) : null;
|
|
448
|
+
const stageChanged = previousState?.status !== "pending" ||
|
|
449
|
+
previousState?.currentStageId !== nextState.currentStageId ||
|
|
450
|
+
!executionPrincipalsEqual(previousState?.currentParticipant ?? null, nextState.currentParticipant ?? null);
|
|
451
|
+
if (!agentId || !stageChanged)
|
|
452
|
+
return null;
|
|
453
|
+
const reason = nextState.currentStageType === "approval" ? "execution_approval_requested" : "execution_review_requested";
|
|
454
|
+
const executionStage = buildExecutionStageWakeContext({
|
|
455
|
+
state: nextState,
|
|
456
|
+
wakeRole: nextState.currentStageType === "approval" ? "approver" : "reviewer",
|
|
457
|
+
allowedActions: ["approve", "request_changes"],
|
|
458
|
+
});
|
|
459
|
+
return {
|
|
460
|
+
agentId,
|
|
461
|
+
wakeup: {
|
|
462
|
+
source: "assignment",
|
|
463
|
+
triggerDetail: "system",
|
|
464
|
+
reason,
|
|
465
|
+
payload: {
|
|
466
|
+
issueId,
|
|
467
|
+
mutation: "update",
|
|
468
|
+
executionStage,
|
|
469
|
+
...(interruptedRunId ? { interruptedRunId } : {}),
|
|
470
|
+
},
|
|
471
|
+
requestedByActorType: input.requestedByActorType,
|
|
472
|
+
requestedByActorId: input.requestedByActorId,
|
|
473
|
+
contextSnapshot: {
|
|
474
|
+
issueId,
|
|
475
|
+
taskId: issueId,
|
|
476
|
+
wakeReason: reason,
|
|
477
|
+
source: "issue.execution_stage",
|
|
478
|
+
executionStage,
|
|
479
|
+
...(interruptedRunId ? { interruptedRunId } : {}),
|
|
480
|
+
},
|
|
481
|
+
},
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
if (nextState.status === "changes_requested") {
|
|
485
|
+
const agentId = nextState.returnAssignee?.type === "agent" ? (nextState.returnAssignee.agentId ?? null) : null;
|
|
486
|
+
const becameChangesRequested = previousState?.status !== "changes_requested" ||
|
|
487
|
+
previousState?.lastDecisionId !== nextState.lastDecisionId ||
|
|
488
|
+
!executionPrincipalsEqual(previousState?.returnAssignee ?? null, nextState.returnAssignee ?? null);
|
|
489
|
+
if (!agentId || !becameChangesRequested)
|
|
490
|
+
return null;
|
|
491
|
+
const executionStage = buildExecutionStageWakeContext({
|
|
492
|
+
state: nextState,
|
|
493
|
+
wakeRole: "executor",
|
|
494
|
+
allowedActions: ["address_changes", "resubmit"],
|
|
495
|
+
});
|
|
496
|
+
return {
|
|
497
|
+
agentId,
|
|
498
|
+
wakeup: {
|
|
499
|
+
source: "assignment",
|
|
500
|
+
triggerDetail: "system",
|
|
501
|
+
reason: "execution_changes_requested",
|
|
502
|
+
payload: {
|
|
503
|
+
issueId,
|
|
504
|
+
mutation: "update",
|
|
505
|
+
executionStage,
|
|
506
|
+
...(interruptedRunId ? { interruptedRunId } : {}),
|
|
507
|
+
},
|
|
508
|
+
requestedByActorType: input.requestedByActorType,
|
|
509
|
+
requestedByActorId: input.requestedByActorId,
|
|
510
|
+
contextSnapshot: {
|
|
511
|
+
issueId,
|
|
512
|
+
taskId: issueId,
|
|
513
|
+
wakeReason: "execution_changes_requested",
|
|
514
|
+
source: "issue.execution_stage",
|
|
515
|
+
executionStage,
|
|
516
|
+
...(interruptedRunId ? { interruptedRunId } : {}),
|
|
517
|
+
},
|
|
518
|
+
},
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
return null;
|
|
522
|
+
}
|
|
523
|
+
export function issueRoutes(db, storage, opts = {}) {
|
|
524
|
+
const router = Router();
|
|
525
|
+
const svc = issueService(db);
|
|
526
|
+
const access = accessService(db);
|
|
527
|
+
const heartbeat = heartbeatService(db, {
|
|
528
|
+
pluginWorkerManager: opts.pluginWorkerManager,
|
|
529
|
+
});
|
|
530
|
+
const feedback = feedbackService(db);
|
|
531
|
+
const companiesSvc = companyService(db);
|
|
532
|
+
let searchSvc = opts.searchService ?? null;
|
|
533
|
+
const getSearchService = () => {
|
|
534
|
+
searchSvc ??= companySearchService(db);
|
|
535
|
+
return searchSvc;
|
|
536
|
+
};
|
|
537
|
+
const searchRateLimiter = opts.searchRateLimiter ?? defaultCompanySearchRateLimiter;
|
|
538
|
+
const instanceSettings = instanceSettingsService(db);
|
|
539
|
+
const agentsSvc = agentService(db);
|
|
540
|
+
const projectsSvc = projectService(db);
|
|
541
|
+
const issueApprovalsSvc = issueApprovalService(db);
|
|
542
|
+
const recoveryActionsSvc = issueRecoveryActionService(db);
|
|
543
|
+
const executionWorkspacesSvc = executionWorkspaceServiceDirect(db);
|
|
544
|
+
const workProductsSvc = workProductService(db);
|
|
545
|
+
const documentsSvc = documentService(db);
|
|
546
|
+
const issueReferencesSvc = issueReferenceService(db);
|
|
547
|
+
const routinesSvc = routineService(db, {
|
|
548
|
+
pluginWorkerManager: opts.pluginWorkerManager,
|
|
549
|
+
});
|
|
550
|
+
const issueTreeControlFactory = Object.prototype.hasOwnProperty.call(serviceIndex, "issueTreeControlService")
|
|
551
|
+
? serviceIndex.issueTreeControlService
|
|
552
|
+
: undefined;
|
|
553
|
+
const treeControlSvc = issueTreeControlFactory?.(db) ?? {
|
|
554
|
+
getActivePauseHoldGate: async () => null,
|
|
555
|
+
};
|
|
556
|
+
const feedbackExportService = opts?.feedbackExportService;
|
|
557
|
+
const environmentsSvc = environmentService(db);
|
|
558
|
+
function withContentPath(attachment) {
|
|
559
|
+
return {
|
|
560
|
+
...attachment,
|
|
561
|
+
contentPath: `/api/attachments/${attachment.id}/content`,
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
function parseBooleanQuery(value) {
|
|
565
|
+
return value === true || value === "true" || value === "1";
|
|
566
|
+
}
|
|
567
|
+
async function assertIssueEnvironmentSelection(companyId, environmentId) {
|
|
568
|
+
if (environmentId === undefined || environmentId === null)
|
|
569
|
+
return;
|
|
570
|
+
await assertEnvironmentSelectionForCompany(environmentsSvc, companyId, environmentId, { allowedDrivers: ["local", "ssh", "sandbox"] });
|
|
571
|
+
}
|
|
572
|
+
async function assertAgentInReviewReviewPath(input) {
|
|
573
|
+
const nextStatus = typeof input.updateFields.status === "string"
|
|
574
|
+
? input.updateFields.status
|
|
575
|
+
: input.existing.status;
|
|
576
|
+
if (input.actorType !== "agent" || input.existing.status === "in_review" || nextStatus !== "in_review")
|
|
577
|
+
return;
|
|
578
|
+
const nextAssigneeUserId = input.updateFields.assigneeUserId === undefined
|
|
579
|
+
? input.existing.assigneeUserId
|
|
580
|
+
: input.updateFields.assigneeUserId;
|
|
581
|
+
if (typeof nextAssigneeUserId === "string" && nextAssigneeUserId.trim().length > 0)
|
|
582
|
+
return;
|
|
583
|
+
const nextExecutionState = input.updateFields.executionState === undefined
|
|
584
|
+
? input.existing.executionState
|
|
585
|
+
: input.updateFields.executionState;
|
|
586
|
+
if (hasExecutionParticipant(nextExecutionState))
|
|
587
|
+
return;
|
|
588
|
+
const nextExecutionPolicy = input.updateFields.executionPolicy;
|
|
589
|
+
if (hasScheduledMonitor({
|
|
590
|
+
existingMonitorNextCheckAt: input.existing.monitorNextCheckAt ?? null,
|
|
591
|
+
patchMonitorNextCheckAt: input.updateFields.monitorNextCheckAt,
|
|
592
|
+
executionPolicy: nextExecutionPolicy,
|
|
593
|
+
}))
|
|
594
|
+
return;
|
|
595
|
+
const interactions = await issueThreadInteractionService(db).listForIssue(input.existing.id);
|
|
596
|
+
if (interactions.some((interaction) => interaction.status === "pending"))
|
|
597
|
+
return;
|
|
598
|
+
const approvals = await issueApprovalsSvc.listApprovalsForIssue(input.existing.id);
|
|
599
|
+
if (approvals.some((approval) => ACTIVE_REVIEW_APPROVAL_STATUSES.has(String(approval.status))))
|
|
600
|
+
return;
|
|
601
|
+
throw unprocessable(INVALID_AGENT_IN_REVIEW_DISPOSITION_MESSAGE, {
|
|
602
|
+
code: "invalid_issue_disposition",
|
|
603
|
+
missing: "review_path",
|
|
604
|
+
validReviewPaths: [
|
|
605
|
+
"pending_issue_thread_interaction",
|
|
606
|
+
"linked_pending_approval",
|
|
607
|
+
"human_assignee_user_id",
|
|
608
|
+
"typed_execution_state_current_participant",
|
|
609
|
+
"scheduled_issue_monitor",
|
|
610
|
+
],
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
async function logExpiredRequestConfirmations(input) {
|
|
614
|
+
for (const interaction of input.interactions) {
|
|
615
|
+
await logActivity(db, {
|
|
616
|
+
companyId: input.issue.companyId,
|
|
617
|
+
actorType: input.actor.actorType,
|
|
618
|
+
actorId: input.actor.actorId,
|
|
619
|
+
agentId: input.actor.agentId,
|
|
620
|
+
runId: input.actor.runId,
|
|
621
|
+
action: "issue.thread_interaction_expired",
|
|
622
|
+
entityType: "issue",
|
|
623
|
+
entityId: input.issue.id,
|
|
624
|
+
details: {
|
|
625
|
+
identifier: input.issue.identifier ?? null,
|
|
626
|
+
interactionId: interaction.id,
|
|
627
|
+
interactionKind: interaction.kind,
|
|
628
|
+
interactionStatus: interaction.status,
|
|
629
|
+
source: input.source,
|
|
630
|
+
result: interaction.result ?? null,
|
|
631
|
+
},
|
|
632
|
+
});
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
function parseDateQuery(value, field) {
|
|
636
|
+
if (typeof value !== "string" || value.trim().length === 0)
|
|
637
|
+
return undefined;
|
|
638
|
+
const parsed = new Date(value);
|
|
639
|
+
if (Number.isNaN(parsed.getTime())) {
|
|
640
|
+
throw new HttpError(400, `Invalid ${field} query value`);
|
|
641
|
+
}
|
|
642
|
+
return parsed;
|
|
643
|
+
}
|
|
644
|
+
async function runSingleFileUpload(req, res, fileSizeLimit) {
|
|
645
|
+
const upload = multer({
|
|
646
|
+
storage: multer.memoryStorage(),
|
|
647
|
+
limits: { fileSize: fileSizeLimit, files: 1 },
|
|
648
|
+
});
|
|
649
|
+
await new Promise((resolve, reject) => {
|
|
650
|
+
upload.single("file")(req, res, (err) => {
|
|
651
|
+
if (err)
|
|
652
|
+
reject(err);
|
|
653
|
+
else
|
|
654
|
+
resolve();
|
|
655
|
+
});
|
|
656
|
+
});
|
|
657
|
+
}
|
|
658
|
+
async function assertCanManageIssueApprovalLinks(req, res, companyId) {
|
|
659
|
+
assertCompanyAccess(req, companyId);
|
|
660
|
+
if (req.actor.type === "board")
|
|
661
|
+
return true;
|
|
662
|
+
if (!req.actor.agentId) {
|
|
663
|
+
res.status(403).json({ error: "Agent authentication required" });
|
|
664
|
+
return false;
|
|
665
|
+
}
|
|
666
|
+
const actorAgent = await agentsSvc.getById(req.actor.agentId);
|
|
667
|
+
if (!actorAgent || actorAgent.companyId !== companyId) {
|
|
668
|
+
res.status(403).json({ error: "Forbidden" });
|
|
669
|
+
return false;
|
|
670
|
+
}
|
|
671
|
+
if (actorAgent.role === "ceo" || Boolean(actorAgent.permissions?.canCreateAgents))
|
|
672
|
+
return true;
|
|
673
|
+
res.status(403).json({ error: "Missing permission to link approvals" });
|
|
674
|
+
return false;
|
|
675
|
+
}
|
|
676
|
+
function actorCanAccessCompany(req, companyId) {
|
|
677
|
+
if (req.actor.type === "none")
|
|
678
|
+
return false;
|
|
679
|
+
if (req.actor.type === "agent")
|
|
680
|
+
return req.actor.companyId === companyId;
|
|
681
|
+
if (req.actor.source === "local_implicit" || req.actor.isInstanceAdmin)
|
|
682
|
+
return true;
|
|
683
|
+
return (req.actor.companyIds ?? []).includes(companyId);
|
|
684
|
+
}
|
|
685
|
+
function canCreateAgentsLegacy(agent) {
|
|
686
|
+
if (agent.role === "ceo")
|
|
687
|
+
return true;
|
|
688
|
+
if (!agent.permissions || typeof agent.permissions !== "object")
|
|
689
|
+
return false;
|
|
690
|
+
return Boolean(agent.permissions.canCreateAgents);
|
|
691
|
+
}
|
|
692
|
+
async function assertCanAssignTasks(req, companyId) {
|
|
693
|
+
assertCompanyAccess(req, companyId);
|
|
694
|
+
if (req.actor.type === "board") {
|
|
695
|
+
if (req.actor.source === "local_implicit" || req.actor.isInstanceAdmin)
|
|
696
|
+
return;
|
|
697
|
+
const allowed = await access.canUser(companyId, req.actor.userId, "tasks:assign");
|
|
698
|
+
if (!allowed)
|
|
699
|
+
throw forbidden("Missing permission: tasks:assign");
|
|
700
|
+
return;
|
|
701
|
+
}
|
|
702
|
+
if (req.actor.type === "agent") {
|
|
703
|
+
if (!req.actor.agentId)
|
|
704
|
+
throw forbidden("Agent authentication required");
|
|
705
|
+
const allowedByGrant = await access.hasPermission(companyId, "agent", req.actor.agentId, "tasks:assign");
|
|
706
|
+
if (allowedByGrant)
|
|
707
|
+
return;
|
|
708
|
+
const actorAgent = await agentsSvc.getById(req.actor.agentId);
|
|
709
|
+
if (actorAgent && actorAgent.companyId === companyId && canCreateAgentsLegacy(actorAgent))
|
|
710
|
+
return;
|
|
711
|
+
throw forbidden("Missing permission: tasks:assign");
|
|
712
|
+
}
|
|
713
|
+
throw unauthorized();
|
|
714
|
+
}
|
|
715
|
+
function requireAgentRunId(req, res) {
|
|
716
|
+
if (req.actor.type !== "agent")
|
|
717
|
+
return null;
|
|
718
|
+
const runId = req.actor.runId?.trim();
|
|
719
|
+
if (runId)
|
|
720
|
+
return runId;
|
|
721
|
+
res.status(401).json({ error: "Agent run id required" });
|
|
722
|
+
return null;
|
|
723
|
+
}
|
|
724
|
+
async function hasActiveCheckoutManagementOverride(actorAgentId, companyId, assigneeAgentId) {
|
|
725
|
+
const allowedByGrant = await access.hasPermission(companyId, "agent", actorAgentId, "tasks:manage_active_checkouts");
|
|
726
|
+
if (allowedByGrant)
|
|
727
|
+
return true;
|
|
728
|
+
const companyAgents = await agentsSvc.list(companyId);
|
|
729
|
+
const agentsById = new Map(companyAgents.map((agent) => [agent.id, agent]));
|
|
730
|
+
const actorAgent = agentsById.get(actorAgentId);
|
|
731
|
+
if (!actorAgent)
|
|
732
|
+
return false;
|
|
733
|
+
if (canCreateAgentsLegacy(actorAgent))
|
|
734
|
+
return true;
|
|
735
|
+
// Reporting-chain managers may intervene in an agent's active checkout
|
|
736
|
+
// without taking the task over. Peers must own the checkout/run first.
|
|
737
|
+
let cursor = assigneeAgentId;
|
|
738
|
+
for (let depth = 0; cursor && depth < 50; depth += 1) {
|
|
739
|
+
const assignee = agentsById.get(cursor);
|
|
740
|
+
if (!assignee)
|
|
741
|
+
return false;
|
|
742
|
+
if (assignee.reportsTo === actorAgentId)
|
|
743
|
+
return true;
|
|
744
|
+
cursor = assignee.reportsTo;
|
|
745
|
+
}
|
|
746
|
+
return false;
|
|
747
|
+
}
|
|
748
|
+
async function assertAgentIssueMutationAllowed(req, res, issue) {
|
|
749
|
+
if (req.actor.type !== "agent")
|
|
750
|
+
return true;
|
|
751
|
+
const actorAgentId = req.actor.agentId;
|
|
752
|
+
if (!actorAgentId) {
|
|
753
|
+
res.status(403).json({ error: "Agent authentication required" });
|
|
754
|
+
return false;
|
|
755
|
+
}
|
|
756
|
+
if (issue.assigneeAgentId === null) {
|
|
757
|
+
return true;
|
|
758
|
+
}
|
|
759
|
+
if (issue.assigneeAgentId !== actorAgentId) {
|
|
760
|
+
if (await hasActiveCheckoutManagementOverride(actorAgentId, issue.companyId, issue.assigneeAgentId)) {
|
|
761
|
+
return true;
|
|
762
|
+
}
|
|
763
|
+
if (issue.status === "in_progress") {
|
|
764
|
+
res.status(409).json({
|
|
765
|
+
error: "Issue is checked out by another agent",
|
|
766
|
+
details: {
|
|
767
|
+
issueId: issue.id,
|
|
768
|
+
assigneeAgentId: issue.assigneeAgentId,
|
|
769
|
+
actorAgentId,
|
|
770
|
+
},
|
|
771
|
+
});
|
|
772
|
+
}
|
|
773
|
+
else {
|
|
774
|
+
res.status(403).json({
|
|
775
|
+
error: "Agent cannot mutate another agent's issue",
|
|
776
|
+
details: {
|
|
777
|
+
issueId: issue.id,
|
|
778
|
+
assigneeAgentId: issue.assigneeAgentId,
|
|
779
|
+
actorAgentId,
|
|
780
|
+
status: issue.status,
|
|
781
|
+
securityPrinciples: ["Least Privilege", "Complete Mediation", "Fail Securely"],
|
|
782
|
+
},
|
|
783
|
+
});
|
|
784
|
+
}
|
|
785
|
+
return false;
|
|
786
|
+
}
|
|
787
|
+
if (issue.status !== "in_progress") {
|
|
788
|
+
return true;
|
|
789
|
+
}
|
|
790
|
+
const runId = requireAgentRunId(req, res);
|
|
791
|
+
if (!runId)
|
|
792
|
+
return false;
|
|
793
|
+
const ownership = await svc.assertCheckoutOwner(issue.id, actorAgentId, runId);
|
|
794
|
+
if (ownership.adoptedFromRunId) {
|
|
795
|
+
const actor = getActorInfo(req);
|
|
796
|
+
await logActivity(db, {
|
|
797
|
+
companyId: issue.companyId,
|
|
798
|
+
actorType: actor.actorType,
|
|
799
|
+
actorId: actor.actorId,
|
|
800
|
+
agentId: actor.agentId,
|
|
801
|
+
runId: actor.runId,
|
|
802
|
+
action: "issue.checkout_lock_adopted",
|
|
803
|
+
entityType: "issue",
|
|
804
|
+
entityId: issue.id,
|
|
805
|
+
details: {
|
|
806
|
+
previousCheckoutRunId: ownership.adoptedFromRunId,
|
|
807
|
+
checkoutRunId: runId,
|
|
808
|
+
reason: "stale_checkout_run",
|
|
809
|
+
},
|
|
810
|
+
});
|
|
811
|
+
}
|
|
812
|
+
return true;
|
|
813
|
+
}
|
|
814
|
+
function assertStructuredCommentFieldsAllowed(req, res, input) {
|
|
815
|
+
const hasStructuredFields = input.presentation !== undefined || input.metadata !== undefined;
|
|
816
|
+
if (!hasStructuredFields)
|
|
817
|
+
return true;
|
|
818
|
+
if (req.actor.type === "board")
|
|
819
|
+
return true;
|
|
820
|
+
res.status(403).json({
|
|
821
|
+
error: "Only board users may set structured comment presentation or metadata",
|
|
822
|
+
details: {
|
|
823
|
+
securityPrinciples: ["Least Privilege", "Secure Defaults", "Complete Mediation"],
|
|
824
|
+
},
|
|
825
|
+
});
|
|
826
|
+
return false;
|
|
827
|
+
}
|
|
828
|
+
async function assertExplicitResumeIntentAllowed(req, res, issue) {
|
|
829
|
+
if (issue.status === "cancelled") {
|
|
830
|
+
res.status(409).json({
|
|
831
|
+
error: "Cancelled issues must be restored through the dedicated restore flow",
|
|
832
|
+
details: {
|
|
833
|
+
issueId: issue.id,
|
|
834
|
+
status: issue.status,
|
|
835
|
+
},
|
|
836
|
+
});
|
|
837
|
+
return false;
|
|
838
|
+
}
|
|
839
|
+
if (!isExplicitResumeCapableStatus(issue.status)) {
|
|
840
|
+
res.status(409).json({
|
|
841
|
+
error: "Issue is not resumable through comment follow-up intent",
|
|
842
|
+
details: { issueId: issue.id, status: issue.status },
|
|
843
|
+
});
|
|
844
|
+
return false;
|
|
845
|
+
}
|
|
846
|
+
const activePauseHold = await treeControlSvc.getActivePauseHoldGate(issue.companyId, issue.id);
|
|
847
|
+
if (activePauseHold) {
|
|
848
|
+
res.status(409).json({
|
|
849
|
+
error: "Issue follow-up blocked by active subtree pause hold",
|
|
850
|
+
details: {
|
|
851
|
+
issueId: issue.id,
|
|
852
|
+
holdId: activePauseHold.holdId,
|
|
853
|
+
rootIssueId: activePauseHold.rootIssueId,
|
|
854
|
+
mode: activePauseHold.mode,
|
|
855
|
+
},
|
|
856
|
+
});
|
|
857
|
+
return false;
|
|
858
|
+
}
|
|
859
|
+
if (issue.status === "blocked") {
|
|
860
|
+
const readiness = await svc.getDependencyReadiness(issue.id);
|
|
861
|
+
if (readiness.unresolvedBlockerCount > 0) {
|
|
862
|
+
res.status(409).json({
|
|
863
|
+
error: "Issue follow-up blocked by unresolved blockers",
|
|
864
|
+
details: {
|
|
865
|
+
issueId: issue.id,
|
|
866
|
+
unresolvedBlockerIssueIds: readiness.unresolvedBlockerIssueIds,
|
|
867
|
+
},
|
|
868
|
+
});
|
|
869
|
+
return false;
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
if (req.actor.type !== "agent")
|
|
873
|
+
return true;
|
|
874
|
+
const actorAgentId = req.actor.agentId;
|
|
875
|
+
if (!actorAgentId) {
|
|
876
|
+
res.status(403).json({ error: "Agent authentication required" });
|
|
877
|
+
return false;
|
|
878
|
+
}
|
|
879
|
+
if (!issue.assigneeAgentId) {
|
|
880
|
+
res.status(409).json({
|
|
881
|
+
error: "Issue follow-up requires an assigned agent",
|
|
882
|
+
details: { issueId: issue.id, actorAgentId },
|
|
883
|
+
});
|
|
884
|
+
return false;
|
|
885
|
+
}
|
|
886
|
+
if (issue.assigneeAgentId === actorAgentId)
|
|
887
|
+
return true;
|
|
888
|
+
if (await hasActiveCheckoutManagementOverride(actorAgentId, issue.companyId, issue.assigneeAgentId)) {
|
|
889
|
+
return true;
|
|
890
|
+
}
|
|
891
|
+
res.status(403).json({
|
|
892
|
+
error: "Agent cannot request follow-up for another agent's issue",
|
|
893
|
+
details: {
|
|
894
|
+
issueId: issue.id,
|
|
895
|
+
assigneeAgentId: issue.assigneeAgentId,
|
|
896
|
+
actorAgentId,
|
|
897
|
+
},
|
|
898
|
+
});
|
|
899
|
+
return false;
|
|
900
|
+
}
|
|
901
|
+
async function resolveActiveIssueRun(issue) {
|
|
902
|
+
let runToInterrupt = issue.executionRunId ? await heartbeat.getRun(issue.executionRunId) : null;
|
|
903
|
+
if ((!runToInterrupt || runToInterrupt.status !== "running") && issue.assigneeAgentId) {
|
|
904
|
+
const activeRun = await heartbeat.getActiveRunForAgent(issue.assigneeAgentId);
|
|
905
|
+
const activeIssueId = activeRun &&
|
|
906
|
+
activeRun.contextSnapshot &&
|
|
907
|
+
typeof activeRun.contextSnapshot === "object" &&
|
|
908
|
+
typeof activeRun.contextSnapshot.issueId === "string"
|
|
909
|
+
? activeRun.contextSnapshot.issueId
|
|
910
|
+
: null;
|
|
911
|
+
if (activeRun && activeRun.status === "running" && activeIssueId === issue.id) {
|
|
912
|
+
runToInterrupt = activeRun;
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
return runToInterrupt?.status === "running" ? runToInterrupt : null;
|
|
916
|
+
}
|
|
917
|
+
async function normalizeIssueAssigneeAgentReference(companyId, rawAssigneeAgentId) {
|
|
918
|
+
if (rawAssigneeAgentId === undefined || rawAssigneeAgentId === null) {
|
|
919
|
+
return rawAssigneeAgentId;
|
|
920
|
+
}
|
|
921
|
+
const raw = rawAssigneeAgentId.trim();
|
|
922
|
+
if (raw.length === 0) {
|
|
923
|
+
return rawAssigneeAgentId;
|
|
924
|
+
}
|
|
925
|
+
const resolved = await agentsSvc.resolveByReference(companyId, raw);
|
|
926
|
+
if (resolved.ambiguous) {
|
|
927
|
+
throw conflict("Agent shortname is ambiguous in this company. Use the agent ID.");
|
|
928
|
+
}
|
|
929
|
+
if (!resolved.agent) {
|
|
930
|
+
throw notFound("Agent not found");
|
|
931
|
+
}
|
|
932
|
+
return resolved.agent.id;
|
|
933
|
+
}
|
|
934
|
+
function toValidTimestamp(value) {
|
|
935
|
+
if (!value)
|
|
936
|
+
return null;
|
|
937
|
+
const timestamp = value instanceof Date ? value.getTime() : new Date(value).getTime();
|
|
938
|
+
return Number.isFinite(timestamp) ? timestamp : null;
|
|
939
|
+
}
|
|
940
|
+
function isQueuedIssueCommentForActiveRun(params) {
|
|
941
|
+
const activeRunStartedAtMs = toValidTimestamp(params.activeRun.startedAt) ?? toValidTimestamp(params.activeRun.createdAt);
|
|
942
|
+
const commentCreatedAtMs = toValidTimestamp(params.comment.createdAt);
|
|
943
|
+
if (activeRunStartedAtMs === null || commentCreatedAtMs === null)
|
|
944
|
+
return false;
|
|
945
|
+
if (params.comment.authorAgentId && params.comment.authorAgentId === params.activeRun.agentId)
|
|
946
|
+
return false;
|
|
947
|
+
return commentCreatedAtMs >= activeRunStartedAtMs;
|
|
948
|
+
}
|
|
949
|
+
async function getClosedIssueExecutionWorkspace(issue) {
|
|
950
|
+
if (!issue.executionWorkspaceId)
|
|
951
|
+
return null;
|
|
952
|
+
const workspace = await executionWorkspacesSvc.getById(issue.executionWorkspaceId);
|
|
953
|
+
if (!workspace || !isClosedIsolatedExecutionWorkspace(workspace))
|
|
954
|
+
return null;
|
|
955
|
+
return workspace;
|
|
956
|
+
}
|
|
957
|
+
function respondClosedIssueExecutionWorkspace(res, workspace) {
|
|
958
|
+
res.status(409).json({
|
|
959
|
+
error: getClosedIsolatedExecutionWorkspaceMessage(workspace),
|
|
960
|
+
executionWorkspace: workspace,
|
|
961
|
+
});
|
|
962
|
+
}
|
|
963
|
+
async function resolveIssueRouteId(rawId) {
|
|
964
|
+
const identifier = normalizeIssueReferenceIdentifier(rawId);
|
|
965
|
+
if (identifier) {
|
|
966
|
+
const issue = await svc.getByIdentifier(identifier);
|
|
967
|
+
if (issue) {
|
|
968
|
+
return issue.id;
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
return rawId;
|
|
972
|
+
}
|
|
973
|
+
async function resolveIssueProjectAndGoal(issue) {
|
|
974
|
+
const project = issue.projectId ? await projectsSvc.getById(issue.projectId) : null;
|
|
975
|
+
return { project, goal: null };
|
|
976
|
+
}
|
|
977
|
+
// Resolve issue identifiers (e.g. "PAP-39") to UUIDs for all /issues/:id routes
|
|
978
|
+
router.param("id", async (req, res, next, rawId) => {
|
|
979
|
+
try {
|
|
980
|
+
req.params.id = await resolveIssueRouteId(rawId);
|
|
981
|
+
next();
|
|
982
|
+
}
|
|
983
|
+
catch (err) {
|
|
984
|
+
next(err);
|
|
985
|
+
}
|
|
986
|
+
});
|
|
987
|
+
// Resolve issue identifiers (e.g. "PAP-39") to UUIDs for company-scoped attachment routes.
|
|
988
|
+
router.param("issueId", async (req, res, next, rawId) => {
|
|
989
|
+
try {
|
|
990
|
+
req.params.issueId = await resolveIssueRouteId(rawId);
|
|
991
|
+
next();
|
|
992
|
+
}
|
|
993
|
+
catch (err) {
|
|
994
|
+
next(err);
|
|
995
|
+
}
|
|
996
|
+
});
|
|
997
|
+
// Common malformed path when companyId is empty in "/api/companies/{companyId}/issues".
|
|
998
|
+
router.get("/issues", (_req, res) => {
|
|
999
|
+
res.status(400).json({
|
|
1000
|
+
error: "Missing companyId in path. Use /api/companies/{companyId}/issues.",
|
|
1001
|
+
});
|
|
1002
|
+
});
|
|
1003
|
+
router.get("/companies/:companyId/search", async (req, res) => {
|
|
1004
|
+
const companyId = req.params.companyId;
|
|
1005
|
+
assertCompanyAccess(req, companyId);
|
|
1006
|
+
const query = companySearchQuerySchema.parse(req.query);
|
|
1007
|
+
const rateLimit = searchRateLimiter.consume(companySearchRateLimitActor(req, companyId));
|
|
1008
|
+
res.setHeader("X-RateLimit-Limit", String(rateLimit.limit));
|
|
1009
|
+
res.setHeader("X-RateLimit-Remaining", String(rateLimit.remaining));
|
|
1010
|
+
if (!rateLimit.allowed) {
|
|
1011
|
+
res.setHeader("Retry-After", String(rateLimit.retryAfterSeconds));
|
|
1012
|
+
res.status(429).json({
|
|
1013
|
+
error: "Search rate limit exceeded",
|
|
1014
|
+
retryAfterSeconds: rateLimit.retryAfterSeconds,
|
|
1015
|
+
});
|
|
1016
|
+
return;
|
|
1017
|
+
}
|
|
1018
|
+
const result = await getSearchService().search(companyId, query);
|
|
1019
|
+
res.json(result);
|
|
1020
|
+
});
|
|
1021
|
+
router.get("/companies/:companyId/issues", async (req, res) => {
|
|
1022
|
+
const companyId = req.params.companyId;
|
|
1023
|
+
assertCompanyAccess(req, companyId);
|
|
1024
|
+
const assigneeUserFilterRaw = req.query.assigneeUserId;
|
|
1025
|
+
const touchedByUserFilterRaw = req.query.touchedByUserId;
|
|
1026
|
+
const inboxArchivedByUserFilterRaw = req.query.inboxArchivedByUserId;
|
|
1027
|
+
const unreadForUserFilterRaw = req.query.unreadForUserId;
|
|
1028
|
+
const assigneeUserId = assigneeUserFilterRaw === "me" && req.actor.type === "board"
|
|
1029
|
+
? req.actor.userId
|
|
1030
|
+
: assigneeUserFilterRaw;
|
|
1031
|
+
const touchedByUserId = touchedByUserFilterRaw === "me" && req.actor.type === "board"
|
|
1032
|
+
? req.actor.userId
|
|
1033
|
+
: touchedByUserFilterRaw;
|
|
1034
|
+
const inboxArchivedByUserId = inboxArchivedByUserFilterRaw === "me" && req.actor.type === "board"
|
|
1035
|
+
? req.actor.userId
|
|
1036
|
+
: inboxArchivedByUserFilterRaw;
|
|
1037
|
+
const unreadForUserId = unreadForUserFilterRaw === "me" && req.actor.type === "board"
|
|
1038
|
+
? req.actor.userId
|
|
1039
|
+
: unreadForUserFilterRaw;
|
|
1040
|
+
const rawLimit = req.query.limit;
|
|
1041
|
+
const parsedLimit = rawLimit !== undefined && /^\d+$/.test(rawLimit)
|
|
1042
|
+
? Number.parseInt(rawLimit, 10)
|
|
1043
|
+
: null;
|
|
1044
|
+
const limit = parsedLimit === null ? ISSUE_LIST_DEFAULT_LIMIT : clampIssueListLimit(parsedLimit);
|
|
1045
|
+
const rawOffset = req.query.offset;
|
|
1046
|
+
const parsedOffset = rawOffset !== undefined && /^\d+$/.test(rawOffset)
|
|
1047
|
+
? Number.parseInt(rawOffset, 10)
|
|
1048
|
+
: null;
|
|
1049
|
+
if (assigneeUserFilterRaw === "me" && (!assigneeUserId || req.actor.type !== "board")) {
|
|
1050
|
+
res.status(403).json({ error: "assigneeUserId=me requires board authentication" });
|
|
1051
|
+
return;
|
|
1052
|
+
}
|
|
1053
|
+
if (touchedByUserFilterRaw === "me" && (!touchedByUserId || req.actor.type !== "board")) {
|
|
1054
|
+
res.status(403).json({ error: "touchedByUserId=me requires board authentication" });
|
|
1055
|
+
return;
|
|
1056
|
+
}
|
|
1057
|
+
if (inboxArchivedByUserFilterRaw === "me" && (!inboxArchivedByUserId || req.actor.type !== "board")) {
|
|
1058
|
+
res.status(403).json({ error: "inboxArchivedByUserId=me requires board authentication" });
|
|
1059
|
+
return;
|
|
1060
|
+
}
|
|
1061
|
+
if (unreadForUserFilterRaw === "me" && (!unreadForUserId || req.actor.type !== "board")) {
|
|
1062
|
+
res.status(403).json({ error: "unreadForUserId=me requires board authentication" });
|
|
1063
|
+
return;
|
|
1064
|
+
}
|
|
1065
|
+
if (rawLimit !== undefined && (parsedLimit === null || !Number.isInteger(parsedLimit) || parsedLimit <= 0)) {
|
|
1066
|
+
res.status(400).json({ error: `limit must be a positive integer up to ${ISSUE_LIST_MAX_LIMIT}` });
|
|
1067
|
+
return;
|
|
1068
|
+
}
|
|
1069
|
+
if (rawOffset !== undefined && (parsedOffset === null || !Number.isInteger(parsedOffset) || parsedOffset < 0)) {
|
|
1070
|
+
res.status(400).json({ error: "offset must be a non-negative integer" });
|
|
1071
|
+
return;
|
|
1072
|
+
}
|
|
1073
|
+
const offset = parsedOffset ?? 0;
|
|
1074
|
+
const result = await svc.list(companyId, {
|
|
1075
|
+
status: req.query.status,
|
|
1076
|
+
assigneeAgentId: req.query.assigneeAgentId,
|
|
1077
|
+
participantAgentId: req.query.participantAgentId,
|
|
1078
|
+
assigneeUserId,
|
|
1079
|
+
touchedByUserId,
|
|
1080
|
+
inboxArchivedByUserId,
|
|
1081
|
+
unreadForUserId,
|
|
1082
|
+
projectId: req.query.projectId,
|
|
1083
|
+
workspaceId: req.query.workspaceId,
|
|
1084
|
+
executionWorkspaceId: req.query.executionWorkspaceId,
|
|
1085
|
+
parentId: req.query.parentId,
|
|
1086
|
+
descendantOf: req.query.descendantOf,
|
|
1087
|
+
labelId: req.query.labelId,
|
|
1088
|
+
originKind: req.query.originKind,
|
|
1089
|
+
originKindPrefix: req.query.originKindPrefix,
|
|
1090
|
+
originId: req.query.originId,
|
|
1091
|
+
includeRoutineExecutions: req.query.includeRoutineExecutions === "true" || req.query.includeRoutineExecutions === "1",
|
|
1092
|
+
excludeRoutineExecutions: req.query.excludeRoutineExecutions === "true" || req.query.excludeRoutineExecutions === "1",
|
|
1093
|
+
includePluginOperations: req.query.includePluginOperations === "true" || req.query.includePluginOperations === "1",
|
|
1094
|
+
includeBlockedBy: req.query.includeBlockedBy === "true" || req.query.includeBlockedBy === "1",
|
|
1095
|
+
q: req.query.q,
|
|
1096
|
+
limit,
|
|
1097
|
+
offset,
|
|
1098
|
+
});
|
|
1099
|
+
const issueIds = result.map((issue) => issue.id);
|
|
1100
|
+
const [handoffStates, recoveryActionByIssue] = await Promise.all([
|
|
1101
|
+
listSuccessfulRunHandoffStates(db, companyId, issueIds),
|
|
1102
|
+
recoveryActionsSvc.listActiveForIssues(companyId, issueIds),
|
|
1103
|
+
]);
|
|
1104
|
+
res.json(result.map((issue) => ({
|
|
1105
|
+
...issue,
|
|
1106
|
+
successfulRunHandoff: handoffStates.get(issue.id) ?? null,
|
|
1107
|
+
activeRecoveryAction: recoveryActionByIssue.get(issue.id) ?? null,
|
|
1108
|
+
})));
|
|
1109
|
+
});
|
|
1110
|
+
router.get("/companies/:companyId/labels", async (req, res) => {
|
|
1111
|
+
const companyId = req.params.companyId;
|
|
1112
|
+
assertCompanyAccess(req, companyId);
|
|
1113
|
+
const result = await svc.listLabels(companyId);
|
|
1114
|
+
res.json(result);
|
|
1115
|
+
});
|
|
1116
|
+
router.post("/companies/:companyId/labels", validate(createIssueLabelSchema), async (req, res) => {
|
|
1117
|
+
const companyId = req.params.companyId;
|
|
1118
|
+
assertCompanyAccess(req, companyId);
|
|
1119
|
+
const label = await svc.createLabel(companyId, req.body);
|
|
1120
|
+
const actor = getActorInfo(req);
|
|
1121
|
+
await logActivity(db, {
|
|
1122
|
+
companyId,
|
|
1123
|
+
actorType: actor.actorType,
|
|
1124
|
+
actorId: actor.actorId,
|
|
1125
|
+
agentId: actor.agentId,
|
|
1126
|
+
runId: actor.runId,
|
|
1127
|
+
action: "label.created",
|
|
1128
|
+
entityType: "label",
|
|
1129
|
+
entityId: label.id,
|
|
1130
|
+
details: { name: label.name, color: label.color },
|
|
1131
|
+
});
|
|
1132
|
+
res.status(201).json(label);
|
|
1133
|
+
});
|
|
1134
|
+
router.delete("/labels/:labelId", async (req, res) => {
|
|
1135
|
+
const labelId = req.params.labelId;
|
|
1136
|
+
const existing = await svc.getLabelById(labelId);
|
|
1137
|
+
if (!existing) {
|
|
1138
|
+
res.status(404).json({ error: "Label not found" });
|
|
1139
|
+
return;
|
|
1140
|
+
}
|
|
1141
|
+
assertCompanyAccess(req, existing.companyId);
|
|
1142
|
+
const removed = await svc.deleteLabel(labelId);
|
|
1143
|
+
if (!removed) {
|
|
1144
|
+
res.status(404).json({ error: "Label not found" });
|
|
1145
|
+
return;
|
|
1146
|
+
}
|
|
1147
|
+
const actor = getActorInfo(req);
|
|
1148
|
+
await logActivity(db, {
|
|
1149
|
+
companyId: removed.companyId,
|
|
1150
|
+
actorType: actor.actorType,
|
|
1151
|
+
actorId: actor.actorId,
|
|
1152
|
+
agentId: actor.agentId,
|
|
1153
|
+
runId: actor.runId,
|
|
1154
|
+
action: "label.deleted",
|
|
1155
|
+
entityType: "label",
|
|
1156
|
+
entityId: removed.id,
|
|
1157
|
+
details: { name: removed.name, color: removed.color },
|
|
1158
|
+
});
|
|
1159
|
+
res.json(removed);
|
|
1160
|
+
});
|
|
1161
|
+
router.get("/issues/:id/heartbeat-context", async (req, res) => {
|
|
1162
|
+
const id = req.params.id;
|
|
1163
|
+
const issue = await svc.getById(id);
|
|
1164
|
+
if (!issue) {
|
|
1165
|
+
res.status(404).json({ error: "Issue not found" });
|
|
1166
|
+
return;
|
|
1167
|
+
}
|
|
1168
|
+
assertCompanyAccess(req, issue.companyId);
|
|
1169
|
+
const wakeCommentId = typeof req.query.wakeCommentId === "string" && req.query.wakeCommentId.trim().length > 0
|
|
1170
|
+
? req.query.wakeCommentId.trim()
|
|
1171
|
+
: null;
|
|
1172
|
+
const currentExecutionWorkspacePromise = issue.executionWorkspaceId
|
|
1173
|
+
? executionWorkspacesSvc.getById(issue.executionWorkspaceId)
|
|
1174
|
+
: Promise.resolve(null);
|
|
1175
|
+
const [{ project, goal }, ancestors, commentCursor, wakeComment, relations, blockerAttention, productivityReview, scheduledRetry, attachments, continuationSummary, currentExecutionWorkspace, activeRecoveryAction,] = await Promise.all([
|
|
1176
|
+
resolveIssueProjectAndGoal(issue),
|
|
1177
|
+
svc.getAncestors(issue.id),
|
|
1178
|
+
svc.getCommentCursor(issue.id),
|
|
1179
|
+
wakeCommentId ? svc.getComment(wakeCommentId) : null,
|
|
1180
|
+
svc.getRelationSummaries(issue.id),
|
|
1181
|
+
svc.listBlockerAttention(issue.companyId, [issue]).then((map) => map.get(issue.id) ?? null),
|
|
1182
|
+
svc.listProductivityReviews(issue.companyId, [issue.id]).then((map) => map.get(issue.id) ?? null),
|
|
1183
|
+
svc.getCurrentScheduledRetry(issue.id),
|
|
1184
|
+
svc.listAttachments(issue.id),
|
|
1185
|
+
documentsSvc.getIssueDocumentByKey(issue.id, ISSUE_CONTINUATION_SUMMARY_DOCUMENT_KEY),
|
|
1186
|
+
currentExecutionWorkspacePromise,
|
|
1187
|
+
recoveryActionsSvc.getActiveForIssue(issue.companyId, issue.id),
|
|
1188
|
+
]);
|
|
1189
|
+
const recoveryActionsByRelationIssue = await relationRecoveryActionMap(recoveryActionsSvc, issue.companyId, relations);
|
|
1190
|
+
const relationsWithRecoveryActions = withRecoveryActionsOnRelationSummaries(relations, recoveryActionsByRelationIssue);
|
|
1191
|
+
res.json({
|
|
1192
|
+
issue: {
|
|
1193
|
+
id: issue.id,
|
|
1194
|
+
identifier: issue.identifier,
|
|
1195
|
+
title: issue.title,
|
|
1196
|
+
description: issue.description,
|
|
1197
|
+
status: issue.status,
|
|
1198
|
+
workMode: issue.workMode,
|
|
1199
|
+
...(blockerAttention ? { blockerAttention } : {}),
|
|
1200
|
+
productivityReview,
|
|
1201
|
+
scheduledRetry,
|
|
1202
|
+
activeRecoveryAction,
|
|
1203
|
+
priority: issue.priority,
|
|
1204
|
+
projectId: issue.projectId,
|
|
1205
|
+
goalId: issue.goalId,
|
|
1206
|
+
parentId: issue.parentId,
|
|
1207
|
+
blockedBy: relationsWithRecoveryActions.blockedBy,
|
|
1208
|
+
blocks: relationsWithRecoveryActions.blocks,
|
|
1209
|
+
assigneeAgentId: issue.assigneeAgentId,
|
|
1210
|
+
assigneeUserId: issue.assigneeUserId,
|
|
1211
|
+
originKind: issue.originKind,
|
|
1212
|
+
originId: issue.originId,
|
|
1213
|
+
updatedAt: issue.updatedAt,
|
|
1214
|
+
},
|
|
1215
|
+
ancestors: ancestors.map((ancestor) => ({
|
|
1216
|
+
id: ancestor.id,
|
|
1217
|
+
identifier: ancestor.identifier,
|
|
1218
|
+
title: ancestor.title,
|
|
1219
|
+
status: ancestor.status,
|
|
1220
|
+
priority: ancestor.priority,
|
|
1221
|
+
})),
|
|
1222
|
+
project: project
|
|
1223
|
+
? {
|
|
1224
|
+
id: project.id,
|
|
1225
|
+
name: project.name,
|
|
1226
|
+
status: project.status,
|
|
1227
|
+
targetDate: project.targetDate,
|
|
1228
|
+
}
|
|
1229
|
+
: null,
|
|
1230
|
+
goal: null,
|
|
1231
|
+
commentCursor,
|
|
1232
|
+
wakeComment: wakeComment && wakeComment.issueId === issue.id
|
|
1233
|
+
? wakeComment
|
|
1234
|
+
: null,
|
|
1235
|
+
attachments: attachments.map((a) => ({
|
|
1236
|
+
id: a.id,
|
|
1237
|
+
filename: a.originalFilename,
|
|
1238
|
+
contentType: a.contentType,
|
|
1239
|
+
byteSize: a.byteSize,
|
|
1240
|
+
contentPath: withContentPath(a).contentPath,
|
|
1241
|
+
createdAt: a.createdAt,
|
|
1242
|
+
})),
|
|
1243
|
+
continuationSummary: continuationSummary
|
|
1244
|
+
? {
|
|
1245
|
+
key: continuationSummary.key,
|
|
1246
|
+
title: continuationSummary.title,
|
|
1247
|
+
body: continuationSummary.body,
|
|
1248
|
+
latestRevisionId: continuationSummary.latestRevisionId,
|
|
1249
|
+
latestRevisionNumber: continuationSummary.latestRevisionNumber,
|
|
1250
|
+
updatedAt: continuationSummary.updatedAt,
|
|
1251
|
+
}
|
|
1252
|
+
: null,
|
|
1253
|
+
currentExecutionWorkspace,
|
|
1254
|
+
});
|
|
1255
|
+
});
|
|
1256
|
+
router.get("/issues/:id", async (req, res) => {
|
|
1257
|
+
const id = req.params.id;
|
|
1258
|
+
const issue = await svc.getById(id);
|
|
1259
|
+
if (!issue) {
|
|
1260
|
+
res.status(404).json({ error: "Issue not found" });
|
|
1261
|
+
return;
|
|
1262
|
+
}
|
|
1263
|
+
assertCompanyAccess(req, issue.companyId);
|
|
1264
|
+
const [{ project, goal }, ancestors, mentionedProjectIds, documentPayload, relations, blockerAttention, productivityReview, referenceSummary, successfulRunHandoffStates, scheduledRetry, activeRecoveryAction,] = await Promise.all([
|
|
1265
|
+
resolveIssueProjectAndGoal(issue),
|
|
1266
|
+
svc.getAncestors(issue.id),
|
|
1267
|
+
svc.findMentionedProjectIds(issue.id, { includeCommentBodies: false }),
|
|
1268
|
+
documentsSvc.getIssueDocumentPayload(issue),
|
|
1269
|
+
svc.getRelationSummaries(issue.id),
|
|
1270
|
+
svc.listBlockerAttention(issue.companyId, [issue]).then((map) => map.get(issue.id) ?? null),
|
|
1271
|
+
svc.listProductivityReviews(issue.companyId, [issue.id]).then((map) => map.get(issue.id) ?? null),
|
|
1272
|
+
issueReferencesSvc.listIssueReferenceSummary(issue.id),
|
|
1273
|
+
listSuccessfulRunHandoffStates(db, issue.companyId, [issue.id]),
|
|
1274
|
+
svc.getCurrentScheduledRetry(issue.id),
|
|
1275
|
+
recoveryActionsSvc.getActiveForIssue(issue.companyId, issue.id),
|
|
1276
|
+
]);
|
|
1277
|
+
const recoveryActionsByRelationIssue = await relationRecoveryActionMap(recoveryActionsSvc, issue.companyId, relations);
|
|
1278
|
+
const relationsWithRecoveryActions = withRecoveryActionsOnRelationSummaries(relations, recoveryActionsByRelationIssue);
|
|
1279
|
+
const mentionedProjects = mentionedProjectIds.length > 0
|
|
1280
|
+
? await projectsSvc.listByIds(issue.companyId, mentionedProjectIds)
|
|
1281
|
+
: [];
|
|
1282
|
+
const currentExecutionWorkspace = issue.executionWorkspaceId
|
|
1283
|
+
? await executionWorkspacesSvc.getById(issue.executionWorkspaceId)
|
|
1284
|
+
: null;
|
|
1285
|
+
const workProducts = await workProductsSvc.listForIssue(issue.id);
|
|
1286
|
+
res.json({
|
|
1287
|
+
...issue,
|
|
1288
|
+
goalId: issue.goalId,
|
|
1289
|
+
ancestors,
|
|
1290
|
+
...(blockerAttention ? { blockerAttention } : {}),
|
|
1291
|
+
productivityReview,
|
|
1292
|
+
successfulRunHandoff: successfulRunHandoffStates.get(issue.id) ?? null,
|
|
1293
|
+
scheduledRetry,
|
|
1294
|
+
activeRecoveryAction,
|
|
1295
|
+
blockedBy: relationsWithRecoveryActions.blockedBy,
|
|
1296
|
+
blocks: relationsWithRecoveryActions.blocks,
|
|
1297
|
+
relatedWork: referenceSummary,
|
|
1298
|
+
referencedIssueIdentifiers: referenceSummary.outbound.map((item) => item.issue.identifier ?? item.issue.id),
|
|
1299
|
+
...documentPayload,
|
|
1300
|
+
project: project ?? null,
|
|
1301
|
+
goal: goal ?? null,
|
|
1302
|
+
mentionedProjects,
|
|
1303
|
+
currentExecutionWorkspace,
|
|
1304
|
+
workProducts,
|
|
1305
|
+
});
|
|
1306
|
+
});
|
|
1307
|
+
router.get("/issues/:id/recovery-actions", async (req, res) => {
|
|
1308
|
+
const id = req.params.id;
|
|
1309
|
+
const issue = await svc.getById(id);
|
|
1310
|
+
if (!issue) {
|
|
1311
|
+
res.status(404).json({ error: "Issue not found" });
|
|
1312
|
+
return;
|
|
1313
|
+
}
|
|
1314
|
+
assertCompanyAccess(req, issue.companyId);
|
|
1315
|
+
const active = await recoveryActionsSvc.getActiveForIssue(issue.companyId, issue.id);
|
|
1316
|
+
res.json({
|
|
1317
|
+
active,
|
|
1318
|
+
actions: active ? [active] : [],
|
|
1319
|
+
});
|
|
1320
|
+
});
|
|
1321
|
+
router.post("/issues/:id/recovery-actions/resolve", validate(resolveIssueRecoveryActionSchema), async (req, res) => {
|
|
1322
|
+
const id = req.params.id;
|
|
1323
|
+
const existing = await svc.getById(id);
|
|
1324
|
+
if (!existing) {
|
|
1325
|
+
res.status(404).json({ error: "Issue not found" });
|
|
1326
|
+
return;
|
|
1327
|
+
}
|
|
1328
|
+
assertCompanyAccess(req, existing.companyId);
|
|
1329
|
+
if (!(await assertAgentIssueMutationAllowed(req, res, existing)))
|
|
1330
|
+
return;
|
|
1331
|
+
const { actionId, outcome, sourceIssueStatus, resolutionNote } = req.body;
|
|
1332
|
+
if (outcome === "false_positive" || outcome === "cancelled") {
|
|
1333
|
+
assertBoard(req);
|
|
1334
|
+
}
|
|
1335
|
+
const actor = getActorInfo(req);
|
|
1336
|
+
const updateFields = sourceIssueStatus ? { status: sourceIssueStatus } : {};
|
|
1337
|
+
await assertAgentInReviewReviewPath({
|
|
1338
|
+
existing,
|
|
1339
|
+
updateFields,
|
|
1340
|
+
actorType: req.actor.type,
|
|
1341
|
+
});
|
|
1342
|
+
const actionStatus = outcome === "cancelled" ? "cancelled" : "resolved";
|
|
1343
|
+
const result = await db.transaction(async (tx) => {
|
|
1344
|
+
let issue = existing;
|
|
1345
|
+
if (outcome === "blocked") {
|
|
1346
|
+
const unresolvedBlockers = await tx
|
|
1347
|
+
.select({ id: issueRows.id })
|
|
1348
|
+
.from(issueRelations)
|
|
1349
|
+
.innerJoin(issueRows, eq(issueRelations.issueId, issueRows.id))
|
|
1350
|
+
.where(and(eq(issueRelations.companyId, existing.companyId), eq(issueRelations.relatedIssueId, existing.id), eq(issueRelations.type, "blocks"), notInArray(issueRows.status, ["done", "cancelled"])))
|
|
1351
|
+
.limit(1);
|
|
1352
|
+
if (unresolvedBlockers.length === 0) {
|
|
1353
|
+
throw unprocessable("Blocked recovery resolution requires an unresolved first-class blocker on the source issue");
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
if (sourceIssueStatus) {
|
|
1357
|
+
const updatedIssue = await svc.update(id, {
|
|
1358
|
+
status: sourceIssueStatus,
|
|
1359
|
+
actorAgentId: actor.agentId ?? null,
|
|
1360
|
+
actorUserId: actor.actorType === "user" ? actor.actorId : null,
|
|
1361
|
+
}, tx);
|
|
1362
|
+
if (!updatedIssue)
|
|
1363
|
+
throw notFound("Issue not found");
|
|
1364
|
+
issue = updatedIssue;
|
|
1365
|
+
}
|
|
1366
|
+
const recoveryAction = await recoveryActionsSvc.resolveActiveForIssue({
|
|
1367
|
+
companyId: existing.companyId,
|
|
1368
|
+
sourceIssueId: existing.id,
|
|
1369
|
+
actionId: actionId ?? null,
|
|
1370
|
+
status: actionStatus,
|
|
1371
|
+
outcome,
|
|
1372
|
+
resolutionNote: resolutionNote ?? null,
|
|
1373
|
+
}, tx);
|
|
1374
|
+
if (!recoveryAction)
|
|
1375
|
+
throw notFound("Active recovery action not found");
|
|
1376
|
+
return { issue, recoveryAction };
|
|
1377
|
+
});
|
|
1378
|
+
await routinesSvc.syncRunStatusForIssue(result.issue.id);
|
|
1379
|
+
if (sourceIssueStatus && existing.status !== result.issue.status) {
|
|
1380
|
+
await logActivity(db, {
|
|
1381
|
+
companyId: result.issue.companyId,
|
|
1382
|
+
actorType: actor.actorType,
|
|
1383
|
+
actorId: actor.actorId,
|
|
1384
|
+
agentId: actor.agentId,
|
|
1385
|
+
runId: actor.runId,
|
|
1386
|
+
action: "issue.updated",
|
|
1387
|
+
entityType: "issue",
|
|
1388
|
+
entityId: result.issue.id,
|
|
1389
|
+
details: {
|
|
1390
|
+
identifier: result.issue.identifier,
|
|
1391
|
+
status: result.issue.status,
|
|
1392
|
+
source: "recovery_action_resolution",
|
|
1393
|
+
recoveryActionId: result.recoveryAction.id,
|
|
1394
|
+
_previous: {
|
|
1395
|
+
status: existing.status,
|
|
1396
|
+
},
|
|
1397
|
+
},
|
|
1398
|
+
});
|
|
1399
|
+
}
|
|
1400
|
+
await logActivity(db, {
|
|
1401
|
+
companyId: result.issue.companyId,
|
|
1402
|
+
actorType: actor.actorType,
|
|
1403
|
+
actorId: actor.actorId,
|
|
1404
|
+
agentId: actor.agentId,
|
|
1405
|
+
runId: actor.runId,
|
|
1406
|
+
action: "issue.recovery_action_resolved",
|
|
1407
|
+
entityType: "issue",
|
|
1408
|
+
entityId: result.issue.id,
|
|
1409
|
+
details: {
|
|
1410
|
+
identifier: result.issue.identifier,
|
|
1411
|
+
recoveryActionId: result.recoveryAction.id,
|
|
1412
|
+
recoveryActionStatus: result.recoveryAction.status,
|
|
1413
|
+
outcome: result.recoveryAction.outcome,
|
|
1414
|
+
sourceIssueStatus: sourceIssueStatus ?? null,
|
|
1415
|
+
resolutionNote: result.recoveryAction.resolutionNote,
|
|
1416
|
+
},
|
|
1417
|
+
});
|
|
1418
|
+
res.json({
|
|
1419
|
+
issue: {
|
|
1420
|
+
...result.issue,
|
|
1421
|
+
activeRecoveryAction: null,
|
|
1422
|
+
},
|
|
1423
|
+
recoveryAction: result.recoveryAction,
|
|
1424
|
+
});
|
|
1425
|
+
});
|
|
1426
|
+
router.get("/issues/:id/work-products", async (req, res) => {
|
|
1427
|
+
const id = req.params.id;
|
|
1428
|
+
const issue = await svc.getById(id);
|
|
1429
|
+
if (!issue) {
|
|
1430
|
+
res.status(404).json({ error: "Issue not found" });
|
|
1431
|
+
return;
|
|
1432
|
+
}
|
|
1433
|
+
assertCompanyAccess(req, issue.companyId);
|
|
1434
|
+
const workProducts = await workProductsSvc.listForIssue(issue.id);
|
|
1435
|
+
res.json(workProducts);
|
|
1436
|
+
});
|
|
1437
|
+
router.get("/issues/:id/documents", async (req, res) => {
|
|
1438
|
+
const id = req.params.id;
|
|
1439
|
+
const issue = await svc.getById(id);
|
|
1440
|
+
if (!issue) {
|
|
1441
|
+
res.status(404).json({ error: "Issue not found" });
|
|
1442
|
+
return;
|
|
1443
|
+
}
|
|
1444
|
+
assertCompanyAccess(req, issue.companyId);
|
|
1445
|
+
const docs = await documentsSvc.listIssueDocuments(issue.id, {
|
|
1446
|
+
includeSystem: req.query.includeSystem === "true",
|
|
1447
|
+
});
|
|
1448
|
+
res.json(docs);
|
|
1449
|
+
});
|
|
1450
|
+
router.get("/issues/:id/documents/:key", async (req, res) => {
|
|
1451
|
+
const id = req.params.id;
|
|
1452
|
+
const issue = await svc.getById(id);
|
|
1453
|
+
if (!issue) {
|
|
1454
|
+
res.status(404).json({ error: "Issue not found" });
|
|
1455
|
+
return;
|
|
1456
|
+
}
|
|
1457
|
+
assertCompanyAccess(req, issue.companyId);
|
|
1458
|
+
const keyParsed = issueDocumentKeySchema.safeParse(String(req.params.key ?? "").trim().toLowerCase());
|
|
1459
|
+
if (!keyParsed.success) {
|
|
1460
|
+
res.status(400).json({ error: "Invalid document key", details: keyParsed.error.issues });
|
|
1461
|
+
return;
|
|
1462
|
+
}
|
|
1463
|
+
const doc = await documentsSvc.getIssueDocumentByKey(issue.id, keyParsed.data);
|
|
1464
|
+
if (!doc) {
|
|
1465
|
+
res.status(404).json({ error: "Document not found" });
|
|
1466
|
+
return;
|
|
1467
|
+
}
|
|
1468
|
+
res.json(doc);
|
|
1469
|
+
});
|
|
1470
|
+
router.put("/issues/:id/documents/:key", validate(upsertIssueDocumentSchema), async (req, res) => {
|
|
1471
|
+
const id = req.params.id;
|
|
1472
|
+
const issue = await svc.getById(id);
|
|
1473
|
+
if (!issue) {
|
|
1474
|
+
res.status(404).json({ error: "Issue not found" });
|
|
1475
|
+
return;
|
|
1476
|
+
}
|
|
1477
|
+
assertCompanyAccess(req, issue.companyId);
|
|
1478
|
+
if (!(await assertAgentIssueMutationAllowed(req, res, issue)))
|
|
1479
|
+
return;
|
|
1480
|
+
const keyParsed = issueDocumentKeySchema.safeParse(String(req.params.key ?? "").trim().toLowerCase());
|
|
1481
|
+
if (!keyParsed.success) {
|
|
1482
|
+
res.status(400).json({ error: "Invalid document key", details: keyParsed.error.issues });
|
|
1483
|
+
return;
|
|
1484
|
+
}
|
|
1485
|
+
const actor = getActorInfo(req);
|
|
1486
|
+
const referenceSummaryBefore = await issueReferencesSvc.listIssueReferenceSummary(issue.id);
|
|
1487
|
+
const result = await documentsSvc.upsertIssueDocument({
|
|
1488
|
+
issueId: issue.id,
|
|
1489
|
+
key: keyParsed.data,
|
|
1490
|
+
title: req.body.title ?? null,
|
|
1491
|
+
format: req.body.format,
|
|
1492
|
+
body: req.body.body,
|
|
1493
|
+
changeSummary: req.body.changeSummary ?? null,
|
|
1494
|
+
baseRevisionId: req.body.baseRevisionId ?? null,
|
|
1495
|
+
createdByAgentId: actor.agentId ?? null,
|
|
1496
|
+
createdByUserId: actor.actorType === "user" ? actor.actorId : null,
|
|
1497
|
+
createdByRunId: actor.runId ?? null,
|
|
1498
|
+
});
|
|
1499
|
+
const doc = result.document;
|
|
1500
|
+
await issueReferencesSvc.syncDocument(doc.id);
|
|
1501
|
+
const referenceSummaryAfter = await issueReferencesSvc.listIssueReferenceSummary(issue.id);
|
|
1502
|
+
const referenceDiff = issueReferencesSvc.diffIssueReferenceSummary(referenceSummaryBefore, referenceSummaryAfter);
|
|
1503
|
+
await logActivity(db, {
|
|
1504
|
+
companyId: issue.companyId,
|
|
1505
|
+
actorType: actor.actorType,
|
|
1506
|
+
actorId: actor.actorId,
|
|
1507
|
+
agentId: actor.agentId,
|
|
1508
|
+
runId: actor.runId,
|
|
1509
|
+
action: result.created ? "issue.document_created" : "issue.document_updated",
|
|
1510
|
+
entityType: "issue",
|
|
1511
|
+
entityId: issue.id,
|
|
1512
|
+
details: {
|
|
1513
|
+
key: doc.key,
|
|
1514
|
+
documentId: doc.id,
|
|
1515
|
+
title: doc.title,
|
|
1516
|
+
format: doc.format,
|
|
1517
|
+
revisionNumber: doc.latestRevisionNumber,
|
|
1518
|
+
...summarizeIssueReferenceActivityDetails({
|
|
1519
|
+
addedReferencedIssues: referenceDiff.addedReferencedIssues.map(summarizeIssueRelationForActivity),
|
|
1520
|
+
removedReferencedIssues: referenceDiff.removedReferencedIssues.map(summarizeIssueRelationForActivity),
|
|
1521
|
+
currentReferencedIssues: referenceDiff.currentReferencedIssues.map(summarizeIssueRelationForActivity),
|
|
1522
|
+
}),
|
|
1523
|
+
},
|
|
1524
|
+
});
|
|
1525
|
+
if (!result.created) {
|
|
1526
|
+
const expiredInteractions = await issueThreadInteractionService(db).expireStaleRequestConfirmationsForIssueDocument(issue, {
|
|
1527
|
+
id: doc.id,
|
|
1528
|
+
key: doc.key,
|
|
1529
|
+
latestRevisionId: doc.latestRevisionId,
|
|
1530
|
+
latestRevisionNumber: doc.latestRevisionNumber,
|
|
1531
|
+
}, {
|
|
1532
|
+
agentId: actor.agentId,
|
|
1533
|
+
userId: actor.actorType === "user" ? actor.actorId : null,
|
|
1534
|
+
});
|
|
1535
|
+
await logExpiredRequestConfirmations({
|
|
1536
|
+
issue,
|
|
1537
|
+
interactions: expiredInteractions,
|
|
1538
|
+
actor,
|
|
1539
|
+
source: "issue.document_updated",
|
|
1540
|
+
});
|
|
1541
|
+
}
|
|
1542
|
+
res.status(result.created ? 201 : 200).json(doc);
|
|
1543
|
+
});
|
|
1544
|
+
router.get("/issues/:id/documents/:key/revisions", async (req, res) => {
|
|
1545
|
+
const id = req.params.id;
|
|
1546
|
+
const issue = await svc.getById(id);
|
|
1547
|
+
if (!issue) {
|
|
1548
|
+
res.status(404).json({ error: "Issue not found" });
|
|
1549
|
+
return;
|
|
1550
|
+
}
|
|
1551
|
+
assertCompanyAccess(req, issue.companyId);
|
|
1552
|
+
const keyParsed = issueDocumentKeySchema.safeParse(String(req.params.key ?? "").trim().toLowerCase());
|
|
1553
|
+
if (!keyParsed.success) {
|
|
1554
|
+
res.status(400).json({ error: "Invalid document key", details: keyParsed.error.issues });
|
|
1555
|
+
return;
|
|
1556
|
+
}
|
|
1557
|
+
const revisions = await documentsSvc.listIssueDocumentRevisions(issue.id, keyParsed.data);
|
|
1558
|
+
res.json(revisions);
|
|
1559
|
+
});
|
|
1560
|
+
router.post("/issues/:id/documents/:key/revisions/:revisionId/restore", validate(restoreIssueDocumentRevisionSchema), async (req, res) => {
|
|
1561
|
+
const id = req.params.id;
|
|
1562
|
+
const revisionId = req.params.revisionId;
|
|
1563
|
+
const issue = await svc.getById(id);
|
|
1564
|
+
if (!issue) {
|
|
1565
|
+
res.status(404).json({ error: "Issue not found" });
|
|
1566
|
+
return;
|
|
1567
|
+
}
|
|
1568
|
+
assertCompanyAccess(req, issue.companyId);
|
|
1569
|
+
if (!(await assertAgentIssueMutationAllowed(req, res, issue)))
|
|
1570
|
+
return;
|
|
1571
|
+
const keyParsed = issueDocumentKeySchema.safeParse(String(req.params.key ?? "").trim().toLowerCase());
|
|
1572
|
+
if (!keyParsed.success) {
|
|
1573
|
+
res.status(400).json({ error: "Invalid document key", details: keyParsed.error.issues });
|
|
1574
|
+
return;
|
|
1575
|
+
}
|
|
1576
|
+
const actor = getActorInfo(req);
|
|
1577
|
+
const referenceSummaryBefore = await issueReferencesSvc.listIssueReferenceSummary(issue.id);
|
|
1578
|
+
const result = await documentsSvc.restoreIssueDocumentRevision({
|
|
1579
|
+
issueId: issue.id,
|
|
1580
|
+
key: keyParsed.data,
|
|
1581
|
+
revisionId,
|
|
1582
|
+
createdByAgentId: actor.agentId ?? null,
|
|
1583
|
+
createdByUserId: actor.actorType === "user" ? actor.actorId : null,
|
|
1584
|
+
});
|
|
1585
|
+
await issueReferencesSvc.syncDocument(result.document.id);
|
|
1586
|
+
const referenceSummaryAfter = await issueReferencesSvc.listIssueReferenceSummary(issue.id);
|
|
1587
|
+
const referenceDiff = issueReferencesSvc.diffIssueReferenceSummary(referenceSummaryBefore, referenceSummaryAfter);
|
|
1588
|
+
await logActivity(db, {
|
|
1589
|
+
companyId: issue.companyId,
|
|
1590
|
+
actorType: actor.actorType,
|
|
1591
|
+
actorId: actor.actorId,
|
|
1592
|
+
agentId: actor.agentId,
|
|
1593
|
+
runId: actor.runId,
|
|
1594
|
+
action: "issue.document_restored",
|
|
1595
|
+
entityType: "issue",
|
|
1596
|
+
entityId: issue.id,
|
|
1597
|
+
details: {
|
|
1598
|
+
key: result.document.key,
|
|
1599
|
+
documentId: result.document.id,
|
|
1600
|
+
title: result.document.title,
|
|
1601
|
+
format: result.document.format,
|
|
1602
|
+
revisionNumber: result.document.latestRevisionNumber,
|
|
1603
|
+
restoredFromRevisionId: result.restoredFromRevisionId,
|
|
1604
|
+
restoredFromRevisionNumber: result.restoredFromRevisionNumber,
|
|
1605
|
+
...summarizeIssueReferenceActivityDetails({
|
|
1606
|
+
addedReferencedIssues: referenceDiff.addedReferencedIssues.map(summarizeIssueRelationForActivity),
|
|
1607
|
+
removedReferencedIssues: referenceDiff.removedReferencedIssues.map(summarizeIssueRelationForActivity),
|
|
1608
|
+
currentReferencedIssues: referenceDiff.currentReferencedIssues.map(summarizeIssueRelationForActivity),
|
|
1609
|
+
}),
|
|
1610
|
+
},
|
|
1611
|
+
});
|
|
1612
|
+
const expiredInteractions = await issueThreadInteractionService(db).expireStaleRequestConfirmationsForIssueDocument(issue, {
|
|
1613
|
+
id: result.document.id,
|
|
1614
|
+
key: result.document.key,
|
|
1615
|
+
latestRevisionId: result.document.latestRevisionId,
|
|
1616
|
+
latestRevisionNumber: result.document.latestRevisionNumber,
|
|
1617
|
+
}, {
|
|
1618
|
+
agentId: actor.agentId,
|
|
1619
|
+
userId: actor.actorType === "user" ? actor.actorId : null,
|
|
1620
|
+
});
|
|
1621
|
+
await logExpiredRequestConfirmations({
|
|
1622
|
+
issue,
|
|
1623
|
+
interactions: expiredInteractions,
|
|
1624
|
+
actor,
|
|
1625
|
+
source: "issue.document_restored",
|
|
1626
|
+
});
|
|
1627
|
+
res.json(result.document);
|
|
1628
|
+
});
|
|
1629
|
+
router.delete("/issues/:id/documents/:key", async (req, res) => {
|
|
1630
|
+
const id = req.params.id;
|
|
1631
|
+
const issue = await svc.getById(id);
|
|
1632
|
+
if (!issue) {
|
|
1633
|
+
res.status(404).json({ error: "Issue not found" });
|
|
1634
|
+
return;
|
|
1635
|
+
}
|
|
1636
|
+
assertCompanyAccess(req, issue.companyId);
|
|
1637
|
+
if (req.actor.type !== "board") {
|
|
1638
|
+
res.status(403).json({ error: "Board authentication required" });
|
|
1639
|
+
return;
|
|
1640
|
+
}
|
|
1641
|
+
const keyParsed = issueDocumentKeySchema.safeParse(String(req.params.key ?? "").trim().toLowerCase());
|
|
1642
|
+
if (!keyParsed.success) {
|
|
1643
|
+
res.status(400).json({ error: "Invalid document key", details: keyParsed.error.issues });
|
|
1644
|
+
return;
|
|
1645
|
+
}
|
|
1646
|
+
const referenceSummaryBefore = await issueReferencesSvc.listIssueReferenceSummary(issue.id);
|
|
1647
|
+
const removed = await documentsSvc.deleteIssueDocument(issue.id, keyParsed.data);
|
|
1648
|
+
if (!removed) {
|
|
1649
|
+
res.status(404).json({ error: "Document not found" });
|
|
1650
|
+
return;
|
|
1651
|
+
}
|
|
1652
|
+
await issueReferencesSvc.deleteDocumentSource(removed.id);
|
|
1653
|
+
const referenceSummaryAfter = await issueReferencesSvc.listIssueReferenceSummary(issue.id);
|
|
1654
|
+
const referenceDiff = issueReferencesSvc.diffIssueReferenceSummary(referenceSummaryBefore, referenceSummaryAfter);
|
|
1655
|
+
const actor = getActorInfo(req);
|
|
1656
|
+
await logActivity(db, {
|
|
1657
|
+
companyId: issue.companyId,
|
|
1658
|
+
actorType: actor.actorType,
|
|
1659
|
+
actorId: actor.actorId,
|
|
1660
|
+
agentId: actor.agentId,
|
|
1661
|
+
runId: actor.runId,
|
|
1662
|
+
action: "issue.document_deleted",
|
|
1663
|
+
entityType: "issue",
|
|
1664
|
+
entityId: issue.id,
|
|
1665
|
+
details: {
|
|
1666
|
+
key: removed.key,
|
|
1667
|
+
documentId: removed.id,
|
|
1668
|
+
title: removed.title,
|
|
1669
|
+
...summarizeIssueReferenceActivityDetails({
|
|
1670
|
+
addedReferencedIssues: referenceDiff.addedReferencedIssues.map(summarizeIssueRelationForActivity),
|
|
1671
|
+
removedReferencedIssues: referenceDiff.removedReferencedIssues.map(summarizeIssueRelationForActivity),
|
|
1672
|
+
currentReferencedIssues: referenceDiff.currentReferencedIssues.map(summarizeIssueRelationForActivity),
|
|
1673
|
+
}),
|
|
1674
|
+
},
|
|
1675
|
+
});
|
|
1676
|
+
const expiredInteractions = await issueThreadInteractionService(db).expireStaleRequestConfirmationsForIssueDocument(issue, {
|
|
1677
|
+
id: removed.id,
|
|
1678
|
+
key: removed.key,
|
|
1679
|
+
latestRevisionId: null,
|
|
1680
|
+
latestRevisionNumber: null,
|
|
1681
|
+
}, {
|
|
1682
|
+
agentId: actor.agentId,
|
|
1683
|
+
userId: actor.actorType === "user" ? actor.actorId : null,
|
|
1684
|
+
});
|
|
1685
|
+
await logExpiredRequestConfirmations({
|
|
1686
|
+
issue,
|
|
1687
|
+
interactions: expiredInteractions,
|
|
1688
|
+
actor,
|
|
1689
|
+
source: "issue.document_deleted",
|
|
1690
|
+
});
|
|
1691
|
+
res.json({ ok: true });
|
|
1692
|
+
});
|
|
1693
|
+
router.post("/issues/:id/work-products", validate(createIssueWorkProductSchema), async (req, res) => {
|
|
1694
|
+
const id = req.params.id;
|
|
1695
|
+
const issue = await svc.getById(id);
|
|
1696
|
+
if (!issue) {
|
|
1697
|
+
res.status(404).json({ error: "Issue not found" });
|
|
1698
|
+
return;
|
|
1699
|
+
}
|
|
1700
|
+
assertCompanyAccess(req, issue.companyId);
|
|
1701
|
+
if (!(await assertAgentIssueMutationAllowed(req, res, issue)))
|
|
1702
|
+
return;
|
|
1703
|
+
const product = await workProductsSvc.createForIssue(issue.id, issue.companyId, {
|
|
1704
|
+
...req.body,
|
|
1705
|
+
projectId: req.body.projectId ?? issue.projectId ?? null,
|
|
1706
|
+
});
|
|
1707
|
+
if (!product) {
|
|
1708
|
+
res.status(422).json({ error: "Invalid work product payload" });
|
|
1709
|
+
return;
|
|
1710
|
+
}
|
|
1711
|
+
const actor = getActorInfo(req);
|
|
1712
|
+
await logActivity(db, {
|
|
1713
|
+
companyId: issue.companyId,
|
|
1714
|
+
actorType: actor.actorType,
|
|
1715
|
+
actorId: actor.actorId,
|
|
1716
|
+
agentId: actor.agentId,
|
|
1717
|
+
runId: actor.runId,
|
|
1718
|
+
action: "issue.work_product_created",
|
|
1719
|
+
entityType: "issue",
|
|
1720
|
+
entityId: issue.id,
|
|
1721
|
+
details: { workProductId: product.id, type: product.type, provider: product.provider },
|
|
1722
|
+
});
|
|
1723
|
+
res.status(201).json(product);
|
|
1724
|
+
});
|
|
1725
|
+
router.patch("/work-products/:id", validate(updateIssueWorkProductSchema), async (req, res) => {
|
|
1726
|
+
const id = req.params.id;
|
|
1727
|
+
const existing = await workProductsSvc.getById(id);
|
|
1728
|
+
if (!existing) {
|
|
1729
|
+
res.status(404).json({ error: "Work product not found" });
|
|
1730
|
+
return;
|
|
1731
|
+
}
|
|
1732
|
+
assertCompanyAccess(req, existing.companyId);
|
|
1733
|
+
const issue = await svc.getById(existing.issueId);
|
|
1734
|
+
if (!issue) {
|
|
1735
|
+
res.status(404).json({ error: "Issue not found" });
|
|
1736
|
+
return;
|
|
1737
|
+
}
|
|
1738
|
+
if (!(await assertAgentIssueMutationAllowed(req, res, issue)))
|
|
1739
|
+
return;
|
|
1740
|
+
const product = await workProductsSvc.update(id, req.body);
|
|
1741
|
+
if (!product) {
|
|
1742
|
+
res.status(404).json({ error: "Work product not found" });
|
|
1743
|
+
return;
|
|
1744
|
+
}
|
|
1745
|
+
const actor = getActorInfo(req);
|
|
1746
|
+
await logActivity(db, {
|
|
1747
|
+
companyId: existing.companyId,
|
|
1748
|
+
actorType: actor.actorType,
|
|
1749
|
+
actorId: actor.actorId,
|
|
1750
|
+
agentId: actor.agentId,
|
|
1751
|
+
runId: actor.runId,
|
|
1752
|
+
action: "issue.work_product_updated",
|
|
1753
|
+
entityType: "issue",
|
|
1754
|
+
entityId: existing.issueId,
|
|
1755
|
+
details: { workProductId: product.id, changedKeys: Object.keys(req.body).sort() },
|
|
1756
|
+
});
|
|
1757
|
+
res.json(product);
|
|
1758
|
+
});
|
|
1759
|
+
router.delete("/work-products/:id", async (req, res) => {
|
|
1760
|
+
const id = req.params.id;
|
|
1761
|
+
const existing = await workProductsSvc.getById(id);
|
|
1762
|
+
if (!existing) {
|
|
1763
|
+
res.status(404).json({ error: "Work product not found" });
|
|
1764
|
+
return;
|
|
1765
|
+
}
|
|
1766
|
+
assertCompanyAccess(req, existing.companyId);
|
|
1767
|
+
const issue = await svc.getById(existing.issueId);
|
|
1768
|
+
if (!issue) {
|
|
1769
|
+
res.status(404).json({ error: "Issue not found" });
|
|
1770
|
+
return;
|
|
1771
|
+
}
|
|
1772
|
+
if (!(await assertAgentIssueMutationAllowed(req, res, issue)))
|
|
1773
|
+
return;
|
|
1774
|
+
const removed = await workProductsSvc.remove(id);
|
|
1775
|
+
if (!removed) {
|
|
1776
|
+
res.status(404).json({ error: "Work product not found" });
|
|
1777
|
+
return;
|
|
1778
|
+
}
|
|
1779
|
+
const actor = getActorInfo(req);
|
|
1780
|
+
await logActivity(db, {
|
|
1781
|
+
companyId: existing.companyId,
|
|
1782
|
+
actorType: actor.actorType,
|
|
1783
|
+
actorId: actor.actorId,
|
|
1784
|
+
agentId: actor.agentId,
|
|
1785
|
+
runId: actor.runId,
|
|
1786
|
+
action: "issue.work_product_deleted",
|
|
1787
|
+
entityType: "issue",
|
|
1788
|
+
entityId: existing.issueId,
|
|
1789
|
+
details: { workProductId: removed.id, type: removed.type },
|
|
1790
|
+
});
|
|
1791
|
+
res.json(removed);
|
|
1792
|
+
});
|
|
1793
|
+
router.post("/issues/:id/read", async (req, res) => {
|
|
1794
|
+
const id = req.params.id;
|
|
1795
|
+
const issue = await svc.getById(id);
|
|
1796
|
+
if (!issue) {
|
|
1797
|
+
res.status(404).json({ error: "Issue not found" });
|
|
1798
|
+
return;
|
|
1799
|
+
}
|
|
1800
|
+
assertCompanyAccess(req, issue.companyId);
|
|
1801
|
+
if (req.actor.type !== "board") {
|
|
1802
|
+
res.status(403).json({ error: "Board authentication required" });
|
|
1803
|
+
return;
|
|
1804
|
+
}
|
|
1805
|
+
if (!req.actor.userId) {
|
|
1806
|
+
res.status(403).json({ error: "Board user context required" });
|
|
1807
|
+
return;
|
|
1808
|
+
}
|
|
1809
|
+
const readState = await svc.markRead(issue.companyId, issue.id, req.actor.userId, new Date());
|
|
1810
|
+
const actor = getActorInfo(req);
|
|
1811
|
+
await logActivity(db, {
|
|
1812
|
+
companyId: issue.companyId,
|
|
1813
|
+
actorType: actor.actorType,
|
|
1814
|
+
actorId: actor.actorId,
|
|
1815
|
+
agentId: actor.agentId,
|
|
1816
|
+
runId: actor.runId,
|
|
1817
|
+
action: "issue.read_marked",
|
|
1818
|
+
entityType: "issue",
|
|
1819
|
+
entityId: issue.id,
|
|
1820
|
+
details: { userId: req.actor.userId, lastReadAt: readState.lastReadAt },
|
|
1821
|
+
});
|
|
1822
|
+
res.json(readState);
|
|
1823
|
+
});
|
|
1824
|
+
router.delete("/issues/:id/read", async (req, res) => {
|
|
1825
|
+
const id = req.params.id;
|
|
1826
|
+
const issue = await svc.getById(id);
|
|
1827
|
+
if (!issue) {
|
|
1828
|
+
res.status(404).json({ error: "Issue not found" });
|
|
1829
|
+
return;
|
|
1830
|
+
}
|
|
1831
|
+
assertCompanyAccess(req, issue.companyId);
|
|
1832
|
+
if (req.actor.type !== "board") {
|
|
1833
|
+
res.status(403).json({ error: "Board authentication required" });
|
|
1834
|
+
return;
|
|
1835
|
+
}
|
|
1836
|
+
if (!req.actor.userId) {
|
|
1837
|
+
res.status(403).json({ error: "Board user context required" });
|
|
1838
|
+
return;
|
|
1839
|
+
}
|
|
1840
|
+
const removed = await svc.markUnread(issue.companyId, issue.id, req.actor.userId);
|
|
1841
|
+
const actor = getActorInfo(req);
|
|
1842
|
+
await logActivity(db, {
|
|
1843
|
+
companyId: issue.companyId,
|
|
1844
|
+
actorType: actor.actorType,
|
|
1845
|
+
actorId: actor.actorId,
|
|
1846
|
+
agentId: actor.agentId,
|
|
1847
|
+
runId: actor.runId,
|
|
1848
|
+
action: "issue.read_unmarked",
|
|
1849
|
+
entityType: "issue",
|
|
1850
|
+
entityId: issue.id,
|
|
1851
|
+
details: { userId: req.actor.userId },
|
|
1852
|
+
});
|
|
1853
|
+
res.json({ id: issue.id, removed });
|
|
1854
|
+
});
|
|
1855
|
+
router.post("/issues/:id/inbox-archive", async (req, res) => {
|
|
1856
|
+
const id = req.params.id;
|
|
1857
|
+
const issue = await svc.getById(id);
|
|
1858
|
+
if (!issue) {
|
|
1859
|
+
res.status(404).json({ error: "Issue not found" });
|
|
1860
|
+
return;
|
|
1861
|
+
}
|
|
1862
|
+
assertCompanyAccess(req, issue.companyId);
|
|
1863
|
+
if (req.actor.type !== "board") {
|
|
1864
|
+
res.status(403).json({ error: "Board authentication required" });
|
|
1865
|
+
return;
|
|
1866
|
+
}
|
|
1867
|
+
if (!req.actor.userId) {
|
|
1868
|
+
res.status(403).json({ error: "Board user context required" });
|
|
1869
|
+
return;
|
|
1870
|
+
}
|
|
1871
|
+
const archiveState = await svc.archiveInbox(issue.companyId, issue.id, req.actor.userId, new Date());
|
|
1872
|
+
const actor = getActorInfo(req);
|
|
1873
|
+
await logActivity(db, {
|
|
1874
|
+
companyId: issue.companyId,
|
|
1875
|
+
actorType: actor.actorType,
|
|
1876
|
+
actorId: actor.actorId,
|
|
1877
|
+
agentId: actor.agentId,
|
|
1878
|
+
runId: actor.runId,
|
|
1879
|
+
action: "issue.inbox_archived",
|
|
1880
|
+
entityType: "issue",
|
|
1881
|
+
entityId: issue.id,
|
|
1882
|
+
details: { userId: req.actor.userId, archivedAt: archiveState.archivedAt },
|
|
1883
|
+
});
|
|
1884
|
+
res.json(archiveState);
|
|
1885
|
+
});
|
|
1886
|
+
router.delete("/issues/:id/inbox-archive", async (req, res) => {
|
|
1887
|
+
const id = req.params.id;
|
|
1888
|
+
const issue = await svc.getById(id);
|
|
1889
|
+
if (!issue) {
|
|
1890
|
+
res.status(404).json({ error: "Issue not found" });
|
|
1891
|
+
return;
|
|
1892
|
+
}
|
|
1893
|
+
assertCompanyAccess(req, issue.companyId);
|
|
1894
|
+
if (req.actor.type !== "board") {
|
|
1895
|
+
res.status(403).json({ error: "Board authentication required" });
|
|
1896
|
+
return;
|
|
1897
|
+
}
|
|
1898
|
+
if (!req.actor.userId) {
|
|
1899
|
+
res.status(403).json({ error: "Board user context required" });
|
|
1900
|
+
return;
|
|
1901
|
+
}
|
|
1902
|
+
const removed = await svc.unarchiveInbox(issue.companyId, issue.id, req.actor.userId);
|
|
1903
|
+
const actor = getActorInfo(req);
|
|
1904
|
+
await logActivity(db, {
|
|
1905
|
+
companyId: issue.companyId,
|
|
1906
|
+
actorType: actor.actorType,
|
|
1907
|
+
actorId: actor.actorId,
|
|
1908
|
+
agentId: actor.agentId,
|
|
1909
|
+
runId: actor.runId,
|
|
1910
|
+
action: "issue.inbox_unarchived",
|
|
1911
|
+
entityType: "issue",
|
|
1912
|
+
entityId: issue.id,
|
|
1913
|
+
details: { userId: req.actor.userId },
|
|
1914
|
+
});
|
|
1915
|
+
res.json(removed ?? { ok: true });
|
|
1916
|
+
});
|
|
1917
|
+
router.get("/issues/:id/approvals", async (req, res) => {
|
|
1918
|
+
const id = req.params.id;
|
|
1919
|
+
const issue = await svc.getById(id);
|
|
1920
|
+
if (!issue) {
|
|
1921
|
+
res.status(404).json({ error: "Issue not found" });
|
|
1922
|
+
return;
|
|
1923
|
+
}
|
|
1924
|
+
assertCompanyAccess(req, issue.companyId);
|
|
1925
|
+
const approvals = await issueApprovalsSvc.listApprovalsForIssue(id);
|
|
1926
|
+
res.json(approvals);
|
|
1927
|
+
});
|
|
1928
|
+
router.post("/issues/:id/approvals", validate(linkIssueApprovalSchema), async (req, res) => {
|
|
1929
|
+
const id = req.params.id;
|
|
1930
|
+
const issue = await svc.getById(id);
|
|
1931
|
+
if (!issue) {
|
|
1932
|
+
res.status(404).json({ error: "Issue not found" });
|
|
1933
|
+
return;
|
|
1934
|
+
}
|
|
1935
|
+
assertCompanyAccess(req, issue.companyId);
|
|
1936
|
+
if (!(await assertAgentIssueMutationAllowed(req, res, issue)))
|
|
1937
|
+
return;
|
|
1938
|
+
if (!(await assertCanManageIssueApprovalLinks(req, res, issue.companyId)))
|
|
1939
|
+
return;
|
|
1940
|
+
const actor = getActorInfo(req);
|
|
1941
|
+
await issueApprovalsSvc.link(id, req.body.approvalId, {
|
|
1942
|
+
agentId: actor.agentId,
|
|
1943
|
+
userId: actor.actorType === "user" ? actor.actorId : null,
|
|
1944
|
+
});
|
|
1945
|
+
await logActivity(db, {
|
|
1946
|
+
companyId: issue.companyId,
|
|
1947
|
+
actorType: actor.actorType,
|
|
1948
|
+
actorId: actor.actorId,
|
|
1949
|
+
agentId: actor.agentId,
|
|
1950
|
+
runId: actor.runId,
|
|
1951
|
+
action: "issue.approval_linked",
|
|
1952
|
+
entityType: "issue",
|
|
1953
|
+
entityId: issue.id,
|
|
1954
|
+
details: { approvalId: req.body.approvalId },
|
|
1955
|
+
});
|
|
1956
|
+
const approvals = await issueApprovalsSvc.listApprovalsForIssue(id);
|
|
1957
|
+
res.status(201).json(approvals);
|
|
1958
|
+
});
|
|
1959
|
+
router.delete("/issues/:id/approvals/:approvalId", async (req, res) => {
|
|
1960
|
+
const id = req.params.id;
|
|
1961
|
+
const approvalId = req.params.approvalId;
|
|
1962
|
+
const issue = await svc.getById(id);
|
|
1963
|
+
if (!issue) {
|
|
1964
|
+
res.status(404).json({ error: "Issue not found" });
|
|
1965
|
+
return;
|
|
1966
|
+
}
|
|
1967
|
+
assertCompanyAccess(req, issue.companyId);
|
|
1968
|
+
if (!(await assertAgentIssueMutationAllowed(req, res, issue)))
|
|
1969
|
+
return;
|
|
1970
|
+
if (!(await assertCanManageIssueApprovalLinks(req, res, issue.companyId)))
|
|
1971
|
+
return;
|
|
1972
|
+
await issueApprovalsSvc.unlink(id, approvalId);
|
|
1973
|
+
const actor = getActorInfo(req);
|
|
1974
|
+
await logActivity(db, {
|
|
1975
|
+
companyId: issue.companyId,
|
|
1976
|
+
actorType: actor.actorType,
|
|
1977
|
+
actorId: actor.actorId,
|
|
1978
|
+
agentId: actor.agentId,
|
|
1979
|
+
runId: actor.runId,
|
|
1980
|
+
action: "issue.approval_unlinked",
|
|
1981
|
+
entityType: "issue",
|
|
1982
|
+
entityId: issue.id,
|
|
1983
|
+
details: { approvalId },
|
|
1984
|
+
});
|
|
1985
|
+
res.json({ ok: true });
|
|
1986
|
+
});
|
|
1987
|
+
router.post("/companies/:companyId/issues", applyCreateIssueStatusDefault, validate(createIssueSchema), async (req, res) => {
|
|
1988
|
+
const companyId = req.params.companyId;
|
|
1989
|
+
assertCompanyAccess(req, companyId);
|
|
1990
|
+
assertNoAgentHostWorkspaceCommandMutation(req, collectIssueWorkspaceCommandPaths(req.body));
|
|
1991
|
+
if (req.body.assigneeAgentId || req.body.assigneeUserId) {
|
|
1992
|
+
await assertCanAssignTasks(req, companyId);
|
|
1993
|
+
}
|
|
1994
|
+
await assertIssueEnvironmentSelection(companyId, req.body.executionWorkspaceSettings?.environmentId);
|
|
1995
|
+
const actor = getActorInfo(req);
|
|
1996
|
+
const executionPolicy = applyActorMonitorScheduledBy(normalizeIssueExecutionPolicy(req.body.executionPolicy), actor.actorType);
|
|
1997
|
+
assertCanManageIssueMonitor(req, req.body.assigneeAgentId ?? null, Boolean(executionPolicy?.monitor));
|
|
1998
|
+
const issue = await svc.create(companyId, {
|
|
1999
|
+
...req.body,
|
|
2000
|
+
executionPolicy,
|
|
2001
|
+
createdByAgentId: actor.agentId,
|
|
2002
|
+
createdByUserId: actor.actorType === "user" ? actor.actorId : null,
|
|
2003
|
+
});
|
|
2004
|
+
await issueReferencesSvc.syncIssue(issue.id);
|
|
2005
|
+
const referenceSummary = await issueReferencesSvc.listIssueReferenceSummary(issue.id);
|
|
2006
|
+
const referenceDiff = issueReferencesSvc.diffIssueReferenceSummary(issueReferencesSvc.emptySummary(), referenceSummary);
|
|
2007
|
+
await logActivity(db, {
|
|
2008
|
+
companyId,
|
|
2009
|
+
actorType: actor.actorType,
|
|
2010
|
+
actorId: actor.actorId,
|
|
2011
|
+
agentId: actor.agentId,
|
|
2012
|
+
runId: actor.runId,
|
|
2013
|
+
action: "issue.created",
|
|
2014
|
+
entityType: "issue",
|
|
2015
|
+
entityId: issue.id,
|
|
2016
|
+
details: {
|
|
2017
|
+
title: issue.title,
|
|
2018
|
+
identifier: issue.identifier,
|
|
2019
|
+
...buildCreateIssueActivityStatusDetails(issue, res),
|
|
2020
|
+
...(Array.isArray(req.body.blockedByIssueIds) ? { blockedByIssueIds: req.body.blockedByIssueIds } : {}),
|
|
2021
|
+
...summarizeIssueReferenceActivityDetails({
|
|
2022
|
+
addedReferencedIssues: referenceDiff.addedReferencedIssues.map(summarizeIssueRelationForActivity),
|
|
2023
|
+
removedReferencedIssues: referenceDiff.removedReferencedIssues.map(summarizeIssueRelationForActivity),
|
|
2024
|
+
currentReferencedIssues: referenceDiff.currentReferencedIssues.map(summarizeIssueRelationForActivity),
|
|
2025
|
+
}),
|
|
2026
|
+
},
|
|
2027
|
+
});
|
|
2028
|
+
if (executionPolicy?.monitor) {
|
|
2029
|
+
await logActivity(db, {
|
|
2030
|
+
companyId,
|
|
2031
|
+
actorType: actor.actorType,
|
|
2032
|
+
actorId: actor.actorId,
|
|
2033
|
+
agentId: actor.agentId,
|
|
2034
|
+
runId: actor.runId,
|
|
2035
|
+
action: "issue.monitor_scheduled",
|
|
2036
|
+
entityType: "issue",
|
|
2037
|
+
entityId: issue.id,
|
|
2038
|
+
details: {
|
|
2039
|
+
identifier: issue.identifier,
|
|
2040
|
+
nextCheckAt: executionPolicy.monitor.nextCheckAt,
|
|
2041
|
+
notes: executionPolicy.monitor.notes,
|
|
2042
|
+
scheduledBy: executionPolicy.monitor.scheduledBy,
|
|
2043
|
+
serviceName: executionPolicy.monitor.serviceName ?? null,
|
|
2044
|
+
timeoutAt: executionPolicy.monitor.timeoutAt ?? null,
|
|
2045
|
+
maxAttempts: executionPolicy.monitor.maxAttempts ?? null,
|
|
2046
|
+
recoveryPolicy: executionPolicy.monitor.recoveryPolicy ?? null,
|
|
2047
|
+
},
|
|
2048
|
+
});
|
|
2049
|
+
}
|
|
2050
|
+
void queueIssueAssignmentWakeup({
|
|
2051
|
+
heartbeat,
|
|
2052
|
+
issue,
|
|
2053
|
+
reason: "issue_assigned",
|
|
2054
|
+
mutation: "create",
|
|
2055
|
+
contextSource: "issue.create",
|
|
2056
|
+
requestedByActorType: actor.actorType,
|
|
2057
|
+
requestedByActorId: actor.actorId,
|
|
2058
|
+
});
|
|
2059
|
+
res.status(201).json({
|
|
2060
|
+
...issue,
|
|
2061
|
+
relatedWork: referenceSummary,
|
|
2062
|
+
referencedIssueIdentifiers: referenceSummary.outbound.map((item) => item.issue.identifier ?? item.issue.id),
|
|
2063
|
+
});
|
|
2064
|
+
});
|
|
2065
|
+
router.post("/issues/:id/children", applyCreateIssueStatusDefault, validate(createChildIssueSchema), async (req, res) => {
|
|
2066
|
+
const parentId = req.params.id;
|
|
2067
|
+
const parent = await svc.getById(parentId);
|
|
2068
|
+
if (!parent) {
|
|
2069
|
+
res.status(404).json({ error: "Parent issue not found" });
|
|
2070
|
+
return;
|
|
2071
|
+
}
|
|
2072
|
+
assertCompanyAccess(req, parent.companyId);
|
|
2073
|
+
assertNoAgentHostWorkspaceCommandMutation(req, collectIssueWorkspaceCommandPaths(req.body));
|
|
2074
|
+
if (req.body.assigneeAgentId || req.body.assigneeUserId) {
|
|
2075
|
+
await assertCanAssignTasks(req, parent.companyId);
|
|
2076
|
+
}
|
|
2077
|
+
await assertIssueEnvironmentSelection(parent.companyId, req.body.executionWorkspaceSettings?.environmentId);
|
|
2078
|
+
const actor = getActorInfo(req);
|
|
2079
|
+
const executionPolicy = applyActorMonitorScheduledBy(normalizeIssueExecutionPolicy(req.body.executionPolicy), actor.actorType);
|
|
2080
|
+
assertCanManageIssueMonitor(req, req.body.assigneeAgentId ?? null, Boolean(executionPolicy?.monitor));
|
|
2081
|
+
const { issue, parentBlockerAdded } = await svc.createChild(parent.id, {
|
|
2082
|
+
...req.body,
|
|
2083
|
+
executionPolicy,
|
|
2084
|
+
createdByAgentId: actor.agentId,
|
|
2085
|
+
createdByUserId: actor.actorType === "user" ? actor.actorId : null,
|
|
2086
|
+
actorAgentId: actor.agentId,
|
|
2087
|
+
actorUserId: actor.actorType === "user" ? actor.actorId : null,
|
|
2088
|
+
});
|
|
2089
|
+
await logActivity(db, {
|
|
2090
|
+
companyId: parent.companyId,
|
|
2091
|
+
actorType: actor.actorType,
|
|
2092
|
+
actorId: actor.actorId,
|
|
2093
|
+
agentId: actor.agentId,
|
|
2094
|
+
runId: actor.runId,
|
|
2095
|
+
action: "issue.child_created",
|
|
2096
|
+
entityType: "issue",
|
|
2097
|
+
entityId: issue.id,
|
|
2098
|
+
details: {
|
|
2099
|
+
parentId: parent.id,
|
|
2100
|
+
identifier: issue.identifier,
|
|
2101
|
+
title: issue.title,
|
|
2102
|
+
...buildCreateIssueActivityStatusDetails(issue, res),
|
|
2103
|
+
inheritedExecutionWorkspaceFromIssueId: parent.id,
|
|
2104
|
+
...(Array.isArray(req.body.blockedByIssueIds) ? { blockedByIssueIds: req.body.blockedByIssueIds } : {}),
|
|
2105
|
+
...(parentBlockerAdded ? { parentBlockerAdded: true } : {}),
|
|
2106
|
+
},
|
|
2107
|
+
});
|
|
2108
|
+
if (executionPolicy?.monitor) {
|
|
2109
|
+
await logActivity(db, {
|
|
2110
|
+
companyId: parent.companyId,
|
|
2111
|
+
actorType: actor.actorType,
|
|
2112
|
+
actorId: actor.actorId,
|
|
2113
|
+
agentId: actor.agentId,
|
|
2114
|
+
runId: actor.runId,
|
|
2115
|
+
action: "issue.monitor_scheduled",
|
|
2116
|
+
entityType: "issue",
|
|
2117
|
+
entityId: issue.id,
|
|
2118
|
+
details: {
|
|
2119
|
+
identifier: issue.identifier,
|
|
2120
|
+
parentId: parent.id,
|
|
2121
|
+
nextCheckAt: executionPolicy.monitor.nextCheckAt,
|
|
2122
|
+
notes: executionPolicy.monitor.notes,
|
|
2123
|
+
scheduledBy: executionPolicy.monitor.scheduledBy,
|
|
2124
|
+
serviceName: executionPolicy.monitor.serviceName ?? null,
|
|
2125
|
+
timeoutAt: executionPolicy.monitor.timeoutAt ?? null,
|
|
2126
|
+
maxAttempts: executionPolicy.monitor.maxAttempts ?? null,
|
|
2127
|
+
recoveryPolicy: executionPolicy.monitor.recoveryPolicy ?? null,
|
|
2128
|
+
},
|
|
2129
|
+
});
|
|
2130
|
+
}
|
|
2131
|
+
void queueIssueAssignmentWakeup({
|
|
2132
|
+
heartbeat,
|
|
2133
|
+
issue,
|
|
2134
|
+
reason: "issue_assigned",
|
|
2135
|
+
mutation: "create",
|
|
2136
|
+
contextSource: "issue.child_create",
|
|
2137
|
+
requestedByActorType: actor.actorType,
|
|
2138
|
+
requestedByActorId: actor.actorId,
|
|
2139
|
+
});
|
|
2140
|
+
res.status(201).json(issue);
|
|
2141
|
+
});
|
|
2142
|
+
router.post("/issues/:id/monitor/check-now", async (req, res) => {
|
|
2143
|
+
const id = req.params.id;
|
|
2144
|
+
const issue = await svc.getById(id);
|
|
2145
|
+
if (!issue) {
|
|
2146
|
+
res.status(404).json({ error: "Issue not found" });
|
|
2147
|
+
return;
|
|
2148
|
+
}
|
|
2149
|
+
assertCompanyAccess(req, issue.companyId);
|
|
2150
|
+
assertCanManageIssueMonitor(req, issue.assigneeAgentId, true);
|
|
2151
|
+
const actor = getActorInfo(req);
|
|
2152
|
+
await heartbeat.triggerIssueMonitor(issue.id, {
|
|
2153
|
+
actorType: actor.actorType,
|
|
2154
|
+
actorId: actor.actorId,
|
|
2155
|
+
agentId: actor.agentId ?? null,
|
|
2156
|
+
runId: actor.runId ?? null,
|
|
2157
|
+
});
|
|
2158
|
+
res.json({ ok: true });
|
|
2159
|
+
});
|
|
2160
|
+
router.post("/issues/:id/scheduled-retry/retry-now", async (req, res) => {
|
|
2161
|
+
assertBoard(req);
|
|
2162
|
+
const id = req.params.id;
|
|
2163
|
+
const issue = await svc.getById(id);
|
|
2164
|
+
if (!issue) {
|
|
2165
|
+
res.status(404).json({ error: "Issue not found" });
|
|
2166
|
+
return;
|
|
2167
|
+
}
|
|
2168
|
+
assertCompanyAccess(req, issue.companyId);
|
|
2169
|
+
const actor = getActorInfo(req);
|
|
2170
|
+
const result = await heartbeat.retryScheduledRetryNow({
|
|
2171
|
+
issueId: issue.id,
|
|
2172
|
+
actor: {
|
|
2173
|
+
actorType: actor.actorType,
|
|
2174
|
+
actorId: actor.actorId,
|
|
2175
|
+
},
|
|
2176
|
+
});
|
|
2177
|
+
await logActivity(db, {
|
|
2178
|
+
companyId: issue.companyId,
|
|
2179
|
+
actorType: actor.actorType,
|
|
2180
|
+
actorId: actor.actorId,
|
|
2181
|
+
action: "issue.scheduled_retry_retry_now",
|
|
2182
|
+
entityType: "issue",
|
|
2183
|
+
entityId: issue.id,
|
|
2184
|
+
agentId: result.scheduledRetry?.agentId ?? issue.assigneeAgentId ?? null,
|
|
2185
|
+
runId: result.scheduledRetry?.runId ?? null,
|
|
2186
|
+
details: {
|
|
2187
|
+
outcome: result.outcome,
|
|
2188
|
+
message: result.message,
|
|
2189
|
+
scheduledRetry: result.scheduledRetry,
|
|
2190
|
+
},
|
|
2191
|
+
});
|
|
2192
|
+
res.json(result);
|
|
2193
|
+
});
|
|
2194
|
+
router.patch("/issues/:id", validate(updateIssueRouteSchema), async (req, res) => {
|
|
2195
|
+
const id = req.params.id;
|
|
2196
|
+
const existing = await svc.getById(id);
|
|
2197
|
+
if (!existing) {
|
|
2198
|
+
res.status(404).json({ error: "Issue not found" });
|
|
2199
|
+
return;
|
|
2200
|
+
}
|
|
2201
|
+
assertCompanyAccess(req, existing.companyId);
|
|
2202
|
+
assertNoAgentHostWorkspaceCommandMutation(req, collectIssueWorkspaceCommandPaths(req.body));
|
|
2203
|
+
if (!(await assertAgentIssueMutationAllowed(req, res, existing)))
|
|
2204
|
+
return;
|
|
2205
|
+
const actor = getActorInfo(req);
|
|
2206
|
+
const isClosed = isClosedIssueStatus(existing.status);
|
|
2207
|
+
const isBlocked = existing.status === "blocked";
|
|
2208
|
+
const normalizedAssigneeAgentId = await normalizeIssueAssigneeAgentReference(existing.companyId, req.body.assigneeAgentId);
|
|
2209
|
+
const titleOrDescriptionChanged = req.body.title !== undefined || req.body.description !== undefined;
|
|
2210
|
+
const existingRelations = Array.isArray(req.body.blockedByIssueIds)
|
|
2211
|
+
? await svc.getRelationSummaries(existing.id)
|
|
2212
|
+
: null;
|
|
2213
|
+
const { comment: commentBody, reviewRequest, reopen: reopenRequested, resume: resumeRequested, interrupt: interruptRequested, hiddenAt: hiddenAtRaw, ...updateFields } = req.body;
|
|
2214
|
+
const shouldCancelActiveRunForCancelledStatus = existing.status !== "cancelled" && updateFields.status === "cancelled";
|
|
2215
|
+
if (resumeRequested === true && !commentBody) {
|
|
2216
|
+
res.status(400).json({ error: "Follow-up intent requires a comment" });
|
|
2217
|
+
return;
|
|
2218
|
+
}
|
|
2219
|
+
if (resumeRequested === true && !(await assertExplicitResumeIntentAllowed(req, res, existing)))
|
|
2220
|
+
return;
|
|
2221
|
+
if (resumeRequested !== true && reopenRequested === true && req.actor.type === "agent") {
|
|
2222
|
+
if (!(await assertExplicitResumeIntentAllowed(req, res, existing)))
|
|
2223
|
+
return;
|
|
2224
|
+
}
|
|
2225
|
+
await assertIssueEnvironmentSelection(existing.companyId, updateFields.executionWorkspaceSettings?.environmentId);
|
|
2226
|
+
const requestedAssigneeAgentId = normalizedAssigneeAgentId === undefined ? existing.assigneeAgentId : normalizedAssigneeAgentId;
|
|
2227
|
+
const explicitMoveToTodoRequested = reopenRequested || resumeRequested === true;
|
|
2228
|
+
const effectiveMoveToTodoRequested = explicitMoveToTodoRequested ||
|
|
2229
|
+
(!!commentBody &&
|
|
2230
|
+
shouldImplicitlyMoveCommentedIssueToTodo({
|
|
2231
|
+
issueStatus: existing.status,
|
|
2232
|
+
assigneeAgentId: requestedAssigneeAgentId,
|
|
2233
|
+
actorType: actor.actorType,
|
|
2234
|
+
actorId: actor.actorId,
|
|
2235
|
+
}));
|
|
2236
|
+
const updateReferenceSummaryBefore = titleOrDescriptionChanged
|
|
2237
|
+
? await issueReferencesSvc.listIssueReferenceSummary(existing.id)
|
|
2238
|
+
: null;
|
|
2239
|
+
const hasUnresolvedFirstClassBlockers = isBlocked && effectiveMoveToTodoRequested
|
|
2240
|
+
? (await svc.getDependencyReadiness(existing.id)).unresolvedBlockerCount > 0
|
|
2241
|
+
: false;
|
|
2242
|
+
if (resumeRequested === true && isBlocked && hasUnresolvedFirstClassBlockers) {
|
|
2243
|
+
res.status(409).json({ error: "Issue follow-up blocked by unresolved blockers" });
|
|
2244
|
+
return;
|
|
2245
|
+
}
|
|
2246
|
+
let interruptedRunId = null;
|
|
2247
|
+
const closedExecutionWorkspace = await getClosedIssueExecutionWorkspace(existing);
|
|
2248
|
+
const isAgentWorkUpdate = req.actor.type === "agent" && (Object.keys(updateFields).length > 0 || reviewRequest !== undefined);
|
|
2249
|
+
if (closedExecutionWorkspace && (commentBody || isAgentWorkUpdate)) {
|
|
2250
|
+
respondClosedIssueExecutionWorkspace(res, closedExecutionWorkspace);
|
|
2251
|
+
return;
|
|
2252
|
+
}
|
|
2253
|
+
if (interruptRequested) {
|
|
2254
|
+
if (!commentBody) {
|
|
2255
|
+
res.status(400).json({ error: "Interrupt is only supported when posting a comment" });
|
|
2256
|
+
return;
|
|
2257
|
+
}
|
|
2258
|
+
if (req.actor.type !== "board") {
|
|
2259
|
+
res.status(403).json({ error: "Only board users can interrupt active runs from issue comments" });
|
|
2260
|
+
return;
|
|
2261
|
+
}
|
|
2262
|
+
const runToInterrupt = await resolveActiveIssueRun(existing);
|
|
2263
|
+
if (runToInterrupt) {
|
|
2264
|
+
const cancelled = await heartbeat.cancelRun(runToInterrupt.id);
|
|
2265
|
+
if (cancelled) {
|
|
2266
|
+
interruptedRunId = cancelled.id;
|
|
2267
|
+
await logActivity(db, {
|
|
2268
|
+
companyId: cancelled.companyId,
|
|
2269
|
+
actorType: actor.actorType,
|
|
2270
|
+
actorId: actor.actorId,
|
|
2271
|
+
agentId: actor.agentId,
|
|
2272
|
+
runId: actor.runId,
|
|
2273
|
+
action: "heartbeat.cancelled",
|
|
2274
|
+
entityType: "heartbeat_run",
|
|
2275
|
+
entityId: cancelled.id,
|
|
2276
|
+
details: { agentId: cancelled.agentId, source: "issue_comment_interrupt", issueId: existing.id },
|
|
2277
|
+
});
|
|
2278
|
+
}
|
|
2279
|
+
}
|
|
2280
|
+
}
|
|
2281
|
+
const runToCancelForCancelledStatus = shouldCancelActiveRunForCancelledStatus
|
|
2282
|
+
? await resolveActiveIssueRun(existing)
|
|
2283
|
+
: null;
|
|
2284
|
+
if (hiddenAtRaw !== undefined) {
|
|
2285
|
+
updateFields.hiddenAt = hiddenAtRaw ? new Date(hiddenAtRaw) : null;
|
|
2286
|
+
}
|
|
2287
|
+
if (commentBody &&
|
|
2288
|
+
effectiveMoveToTodoRequested &&
|
|
2289
|
+
(isClosed || (isBlocked && !hasUnresolvedFirstClassBlockers)) &&
|
|
2290
|
+
updateFields.status === undefined) {
|
|
2291
|
+
updateFields.status = "todo";
|
|
2292
|
+
}
|
|
2293
|
+
if (req.body.executionPolicy !== undefined) {
|
|
2294
|
+
updateFields.executionPolicy = applyActorMonitorScheduledBy(normalizeIssueExecutionPolicy(req.body.executionPolicy), actor.actorType);
|
|
2295
|
+
}
|
|
2296
|
+
const previousExecutionPolicy = normalizeIssueExecutionPolicy(existing.executionPolicy ?? null);
|
|
2297
|
+
const nextExecutionPolicy = updateFields.executionPolicy !== undefined
|
|
2298
|
+
? updateFields.executionPolicy
|
|
2299
|
+
: previousExecutionPolicy;
|
|
2300
|
+
if (normalizedAssigneeAgentId !== undefined) {
|
|
2301
|
+
updateFields.assigneeAgentId = normalizedAssigneeAgentId;
|
|
2302
|
+
}
|
|
2303
|
+
const monitorChanged = monitorPoliciesEqual(previousExecutionPolicy, nextExecutionPolicy) === false;
|
|
2304
|
+
assertCanManageIssueMonitor(req, existing.assigneeAgentId, req.body.executionPolicy !== undefined && monitorChanged);
|
|
2305
|
+
const transition = applyIssueExecutionPolicyTransition({
|
|
2306
|
+
issue: existing,
|
|
2307
|
+
policy: nextExecutionPolicy,
|
|
2308
|
+
previousPolicy: previousExecutionPolicy,
|
|
2309
|
+
requestedStatus: typeof updateFields.status === "string" ? updateFields.status : undefined,
|
|
2310
|
+
requestedAssigneePatch: {
|
|
2311
|
+
assigneeAgentId: normalizedAssigneeAgentId,
|
|
2312
|
+
assigneeUserId: req.body.assigneeUserId === undefined ? undefined : req.body.assigneeUserId,
|
|
2313
|
+
},
|
|
2314
|
+
actor: {
|
|
2315
|
+
agentId: actor.agentId ?? null,
|
|
2316
|
+
userId: actor.actorType === "user" ? actor.actorId : null,
|
|
2317
|
+
},
|
|
2318
|
+
commentBody,
|
|
2319
|
+
reviewRequest: reviewRequest === undefined ? undefined : reviewRequest,
|
|
2320
|
+
monitorExplicitlyUpdated: req.body.executionPolicy !== undefined && monitorChanged,
|
|
2321
|
+
});
|
|
2322
|
+
const decisionId = transition.decision ? randomUUID() : null;
|
|
2323
|
+
if (decisionId) {
|
|
2324
|
+
const nextExecutionState = transition.patch.executionState;
|
|
2325
|
+
if (!nextExecutionState || typeof nextExecutionState !== "object") {
|
|
2326
|
+
throw new Error("Execution policy decision patch is missing executionState");
|
|
2327
|
+
}
|
|
2328
|
+
transition.patch.executionState = {
|
|
2329
|
+
...nextExecutionState,
|
|
2330
|
+
lastDecisionId: decisionId,
|
|
2331
|
+
};
|
|
2332
|
+
}
|
|
2333
|
+
Object.assign(updateFields, transition.patch);
|
|
2334
|
+
if (reviewRequest !== undefined && transition.patch.executionState === undefined) {
|
|
2335
|
+
const existingExecutionState = parseIssueExecutionState(existing.executionState);
|
|
2336
|
+
if (!existingExecutionState || existingExecutionState.status !== "pending") {
|
|
2337
|
+
if (reviewRequest !== null) {
|
|
2338
|
+
res.status(422).json({ error: "reviewRequest requires an active review or approval stage" });
|
|
2339
|
+
return;
|
|
2340
|
+
}
|
|
2341
|
+
}
|
|
2342
|
+
else {
|
|
2343
|
+
updateFields.executionState = {
|
|
2344
|
+
...existingExecutionState,
|
|
2345
|
+
reviewRequest,
|
|
2346
|
+
};
|
|
2347
|
+
}
|
|
2348
|
+
}
|
|
2349
|
+
await assertAgentInReviewReviewPath({
|
|
2350
|
+
existing,
|
|
2351
|
+
updateFields,
|
|
2352
|
+
actorType: req.actor.type,
|
|
2353
|
+
});
|
|
2354
|
+
const nextAssigneeAgentId = updateFields.assigneeAgentId === undefined ? existing.assigneeAgentId : updateFields.assigneeAgentId;
|
|
2355
|
+
const nextAssigneeUserId = updateFields.assigneeUserId === undefined ? existing.assigneeUserId : updateFields.assigneeUserId;
|
|
2356
|
+
const assigneeWillChange = nextAssigneeAgentId !== existing.assigneeAgentId || nextAssigneeUserId !== existing.assigneeUserId;
|
|
2357
|
+
const isAgentReturningIssueToCreator = req.actor.type === "agent" &&
|
|
2358
|
+
!!req.actor.agentId &&
|
|
2359
|
+
existing.assigneeAgentId === req.actor.agentId &&
|
|
2360
|
+
nextAssigneeAgentId === null &&
|
|
2361
|
+
typeof nextAssigneeUserId === "string" &&
|
|
2362
|
+
!!existing.createdByUserId &&
|
|
2363
|
+
nextAssigneeUserId === existing.createdByUserId;
|
|
2364
|
+
if (assigneeWillChange && !transition.workflowControlledAssignment) {
|
|
2365
|
+
if (!isAgentReturningIssueToCreator) {
|
|
2366
|
+
await assertCanAssignTasks(req, existing.companyId);
|
|
2367
|
+
}
|
|
2368
|
+
}
|
|
2369
|
+
let issue;
|
|
2370
|
+
try {
|
|
2371
|
+
if (transition.decision && decisionId) {
|
|
2372
|
+
const decision = transition.decision;
|
|
2373
|
+
issue = await db.transaction(async (tx) => {
|
|
2374
|
+
const updated = await svc.update(id, {
|
|
2375
|
+
...updateFields,
|
|
2376
|
+
actorAgentId: actor.agentId ?? null,
|
|
2377
|
+
actorUserId: actor.actorType === "user" ? actor.actorId : null,
|
|
2378
|
+
}, tx);
|
|
2379
|
+
if (!updated)
|
|
2380
|
+
return null;
|
|
2381
|
+
await tx.insert(issueExecutionDecisions).values({
|
|
2382
|
+
id: decisionId,
|
|
2383
|
+
companyId: updated.companyId,
|
|
2384
|
+
issueId: updated.id,
|
|
2385
|
+
stageId: decision.stageId,
|
|
2386
|
+
stageType: decision.stageType,
|
|
2387
|
+
actorAgentId: actor.agentId ?? null,
|
|
2388
|
+
actorUserId: actor.actorType === "user" ? actor.actorId : null,
|
|
2389
|
+
outcome: decision.outcome,
|
|
2390
|
+
body: decision.body,
|
|
2391
|
+
createdByRunId: actor.runId ?? null,
|
|
2392
|
+
});
|
|
2393
|
+
return updated;
|
|
2394
|
+
});
|
|
2395
|
+
}
|
|
2396
|
+
else {
|
|
2397
|
+
issue = await svc.update(id, {
|
|
2398
|
+
...updateFields,
|
|
2399
|
+
actorAgentId: actor.agentId ?? null,
|
|
2400
|
+
actorUserId: actor.actorType === "user" ? actor.actorId : null,
|
|
2401
|
+
});
|
|
2402
|
+
}
|
|
2403
|
+
}
|
|
2404
|
+
catch (err) {
|
|
2405
|
+
if (err instanceof HttpError && err.status === 422) {
|
|
2406
|
+
logger.warn({
|
|
2407
|
+
issueId: id,
|
|
2408
|
+
companyId: existing.companyId,
|
|
2409
|
+
assigneePatch: {
|
|
2410
|
+
assigneeAgentId: normalizedAssigneeAgentId === undefined ? "__omitted__" : normalizedAssigneeAgentId,
|
|
2411
|
+
assigneeUserId: req.body.assigneeUserId === undefined ? "__omitted__" : req.body.assigneeUserId,
|
|
2412
|
+
},
|
|
2413
|
+
currentAssignee: {
|
|
2414
|
+
assigneeAgentId: existing.assigneeAgentId,
|
|
2415
|
+
assigneeUserId: existing.assigneeUserId,
|
|
2416
|
+
},
|
|
2417
|
+
error: err.message,
|
|
2418
|
+
details: err.details,
|
|
2419
|
+
}, "issue update rejected with 422");
|
|
2420
|
+
}
|
|
2421
|
+
throw err;
|
|
2422
|
+
}
|
|
2423
|
+
if (!issue) {
|
|
2424
|
+
res.status(404).json({ error: "Issue not found" });
|
|
2425
|
+
return;
|
|
2426
|
+
}
|
|
2427
|
+
let cancelledStatusRunId = null;
|
|
2428
|
+
if (runToCancelForCancelledStatus) {
|
|
2429
|
+
try {
|
|
2430
|
+
const cancelled = await heartbeat.cancelRun(runToCancelForCancelledStatus.id);
|
|
2431
|
+
if (cancelled) {
|
|
2432
|
+
cancelledStatusRunId = cancelled.id;
|
|
2433
|
+
await logActivity(db, {
|
|
2434
|
+
companyId: cancelled.companyId,
|
|
2435
|
+
actorType: actor.actorType,
|
|
2436
|
+
actorId: actor.actorId,
|
|
2437
|
+
agentId: actor.agentId,
|
|
2438
|
+
runId: actor.runId,
|
|
2439
|
+
action: "heartbeat.cancelled",
|
|
2440
|
+
entityType: "heartbeat_run",
|
|
2441
|
+
entityId: cancelled.id,
|
|
2442
|
+
details: { agentId: cancelled.agentId, source: "issue_status_cancelled", issueId: existing.id },
|
|
2443
|
+
});
|
|
2444
|
+
}
|
|
2445
|
+
}
|
|
2446
|
+
catch (err) {
|
|
2447
|
+
logger.warn({ err, issueId: existing.id, runId: runToCancelForCancelledStatus.id }, "failed to cancel run for cancelled issue");
|
|
2448
|
+
await logActivity(db, {
|
|
2449
|
+
companyId: existing.companyId,
|
|
2450
|
+
actorType: actor.actorType,
|
|
2451
|
+
actorId: actor.actorId,
|
|
2452
|
+
agentId: actor.agentId,
|
|
2453
|
+
runId: actor.runId,
|
|
2454
|
+
action: "heartbeat.cancel_failed",
|
|
2455
|
+
entityType: "heartbeat_run",
|
|
2456
|
+
entityId: runToCancelForCancelledStatus.id,
|
|
2457
|
+
details: { source: "issue_status_cancelled", issueId: existing.id },
|
|
2458
|
+
});
|
|
2459
|
+
}
|
|
2460
|
+
}
|
|
2461
|
+
if (titleOrDescriptionChanged) {
|
|
2462
|
+
await issueReferencesSvc.syncIssue(issue.id);
|
|
2463
|
+
}
|
|
2464
|
+
const updateReferenceSummaryAfter = titleOrDescriptionChanged
|
|
2465
|
+
? await issueReferencesSvc.listIssueReferenceSummary(issue.id)
|
|
2466
|
+
: null;
|
|
2467
|
+
const updateReferenceDiff = updateReferenceSummaryBefore && updateReferenceSummaryAfter
|
|
2468
|
+
? issueReferencesSvc.diffIssueReferenceSummary(updateReferenceSummaryBefore, updateReferenceSummaryAfter)
|
|
2469
|
+
: null;
|
|
2470
|
+
let issueResponse = issue;
|
|
2471
|
+
let updatedRelations = null;
|
|
2472
|
+
if (issue && Array.isArray(req.body.blockedByIssueIds)) {
|
|
2473
|
+
updatedRelations = await svc.getRelationSummaries(issue.id);
|
|
2474
|
+
issueResponse = {
|
|
2475
|
+
...issue,
|
|
2476
|
+
blockedBy: updatedRelations.blockedBy,
|
|
2477
|
+
blocks: updatedRelations.blocks,
|
|
2478
|
+
};
|
|
2479
|
+
}
|
|
2480
|
+
await routinesSvc.syncRunStatusForIssue(issue.id);
|
|
2481
|
+
if (actor.runId) {
|
|
2482
|
+
await heartbeat.reportRunActivity(actor.runId).catch((err) => logger.warn({ err, runId: actor.runId }, "failed to clear detached run warning after issue activity"));
|
|
2483
|
+
}
|
|
2484
|
+
// Build activity details with previous values for changed fields
|
|
2485
|
+
const previous = {};
|
|
2486
|
+
for (const key of Object.keys(updateFields)) {
|
|
2487
|
+
if (key in existing && existing[key] !== updateFields[key]) {
|
|
2488
|
+
previous[key] = existing[key];
|
|
2489
|
+
}
|
|
2490
|
+
}
|
|
2491
|
+
if (Array.isArray(req.body.blockedByIssueIds)) {
|
|
2492
|
+
previous.blockedByIssueIds = existingRelations?.blockedBy.map((relation) => relation.id) ?? [];
|
|
2493
|
+
}
|
|
2494
|
+
const hasFieldChanges = Object.keys(previous).length > 0;
|
|
2495
|
+
let workspaceChange = null;
|
|
2496
|
+
if (hasIssueWorkspaceAuditChange(previous)) {
|
|
2497
|
+
try {
|
|
2498
|
+
workspaceChange = await buildIssueWorkspaceChangeActivityDetails(db, issue.companyId, existing, issue);
|
|
2499
|
+
}
|
|
2500
|
+
catch (err) {
|
|
2501
|
+
logger.warn({ err, issueId: issue.id }, "failed to enrich issue workspace change activity details");
|
|
2502
|
+
const fallbackNames = emptyWorkspaceNameMaps();
|
|
2503
|
+
workspaceChange = {
|
|
2504
|
+
from: summarizeIssueWorkspaceForActivity(existing, fallbackNames),
|
|
2505
|
+
to: summarizeIssueWorkspaceForActivity(issue, fallbackNames),
|
|
2506
|
+
};
|
|
2507
|
+
}
|
|
2508
|
+
}
|
|
2509
|
+
const reopened = commentBody &&
|
|
2510
|
+
effectiveMoveToTodoRequested &&
|
|
2511
|
+
(isClosed || (isBlocked && !hasUnresolvedFirstClassBlockers)) &&
|
|
2512
|
+
previous.status !== undefined &&
|
|
2513
|
+
issue.status === "todo";
|
|
2514
|
+
const reopenFromStatus = reopened ? existing.status : null;
|
|
2515
|
+
await logActivity(db, {
|
|
2516
|
+
companyId: issue.companyId,
|
|
2517
|
+
actorType: actor.actorType,
|
|
2518
|
+
actorId: actor.actorId,
|
|
2519
|
+
agentId: actor.agentId,
|
|
2520
|
+
runId: actor.runId,
|
|
2521
|
+
action: "issue.updated",
|
|
2522
|
+
entityType: "issue",
|
|
2523
|
+
entityId: issue.id,
|
|
2524
|
+
details: {
|
|
2525
|
+
...updateFields,
|
|
2526
|
+
identifier: issue.identifier,
|
|
2527
|
+
...(commentBody ? { source: "comment" } : {}),
|
|
2528
|
+
...(resumeRequested === true ? { resumeIntent: true, followUpRequested: true } : {}),
|
|
2529
|
+
...(reopened ? { reopened: true, reopenedFrom: reopenFromStatus } : {}),
|
|
2530
|
+
...(interruptedRunId ? { interruptedRunId } : {}),
|
|
2531
|
+
...(cancelledStatusRunId ? { cancelledStatusRunId } : {}),
|
|
2532
|
+
...(workspaceChange ? { workspaceChange } : {}),
|
|
2533
|
+
_previous: hasFieldChanges ? previous : undefined,
|
|
2534
|
+
...summarizeIssueReferenceActivityDetails(updateReferenceDiff
|
|
2535
|
+
? {
|
|
2536
|
+
addedReferencedIssues: updateReferenceDiff.addedReferencedIssues.map(summarizeIssueRelationForActivity),
|
|
2537
|
+
removedReferencedIssues: updateReferenceDiff.removedReferencedIssues.map(summarizeIssueRelationForActivity),
|
|
2538
|
+
currentReferencedIssues: updateReferenceDiff.currentReferencedIssues.map(summarizeIssueRelationForActivity),
|
|
2539
|
+
}
|
|
2540
|
+
: null),
|
|
2541
|
+
},
|
|
2542
|
+
});
|
|
2543
|
+
if (existing.status === "in_progress" && issue.status !== existing.status && issue.status !== "in_progress") {
|
|
2544
|
+
await listSuccessfulRunHandoffStates(db, issue.companyId, [issue.id])
|
|
2545
|
+
.then(async (handoffStates) => {
|
|
2546
|
+
const handoff = handoffStates.get(issue.id);
|
|
2547
|
+
if (handoff?.state !== "required")
|
|
2548
|
+
return;
|
|
2549
|
+
await logActivity(db, {
|
|
2550
|
+
companyId: issue.companyId,
|
|
2551
|
+
actorType: actor.actorType,
|
|
2552
|
+
actorId: actor.actorId,
|
|
2553
|
+
agentId: actor.agentId,
|
|
2554
|
+
runId: actor.runId,
|
|
2555
|
+
action: "issue.successful_run_handoff_resolved",
|
|
2556
|
+
entityType: "issue",
|
|
2557
|
+
entityId: issue.id,
|
|
2558
|
+
details: {
|
|
2559
|
+
identifier: issue.identifier,
|
|
2560
|
+
sourceRunId: handoff.sourceRunId,
|
|
2561
|
+
correctiveRunId: handoff.correctiveRunId,
|
|
2562
|
+
resolvedByStatus: issue.status,
|
|
2563
|
+
},
|
|
2564
|
+
});
|
|
2565
|
+
})
|
|
2566
|
+
.catch((err) => {
|
|
2567
|
+
logger.warn({ err, issueId: issue.id }, "failed to log successful run handoff resolution");
|
|
2568
|
+
});
|
|
2569
|
+
}
|
|
2570
|
+
if (Array.isArray(req.body.blockedByIssueIds)) {
|
|
2571
|
+
const previousBlockedByIds = new Set((existingRelations?.blockedBy ?? []).map((relation) => relation.id));
|
|
2572
|
+
const nextBlockedByIds = new Set(req.body.blockedByIssueIds);
|
|
2573
|
+
const addedBlockedByIssueIds = [...nextBlockedByIds].filter((candidate) => !previousBlockedByIds.has(candidate));
|
|
2574
|
+
const removedBlockedByIssueIds = [...previousBlockedByIds].filter((candidate) => !nextBlockedByIds.has(candidate));
|
|
2575
|
+
const nextBlockedByRelations = updatedRelations?.blockedBy ?? [];
|
|
2576
|
+
const previousBlockedByRelations = existingRelations?.blockedBy ?? [];
|
|
2577
|
+
if (addedBlockedByIssueIds.length > 0 || removedBlockedByIssueIds.length > 0) {
|
|
2578
|
+
await logActivity(db, {
|
|
2579
|
+
companyId: issue.companyId,
|
|
2580
|
+
actorType: actor.actorType,
|
|
2581
|
+
actorId: actor.actorId,
|
|
2582
|
+
agentId: actor.agentId,
|
|
2583
|
+
runId: actor.runId,
|
|
2584
|
+
action: "issue.blockers_updated",
|
|
2585
|
+
entityType: "issue",
|
|
2586
|
+
entityId: issue.id,
|
|
2587
|
+
details: {
|
|
2588
|
+
identifier: issue.identifier,
|
|
2589
|
+
blockedByIssueIds: req.body.blockedByIssueIds,
|
|
2590
|
+
addedBlockedByIssueIds,
|
|
2591
|
+
removedBlockedByIssueIds,
|
|
2592
|
+
blockedByIssues: nextBlockedByRelations.map(summarizeIssueRelationForActivity),
|
|
2593
|
+
addedBlockedByIssues: nextBlockedByRelations
|
|
2594
|
+
.filter((relation) => addedBlockedByIssueIds.includes(relation.id))
|
|
2595
|
+
.map(summarizeIssueRelationForActivity),
|
|
2596
|
+
removedBlockedByIssues: previousBlockedByRelations
|
|
2597
|
+
.filter((relation) => removedBlockedByIssueIds.includes(relation.id))
|
|
2598
|
+
.map(summarizeIssueRelationForActivity),
|
|
2599
|
+
},
|
|
2600
|
+
});
|
|
2601
|
+
}
|
|
2602
|
+
}
|
|
2603
|
+
const reviewerChanges = diffExecutionParticipants(previousExecutionPolicy, nextExecutionPolicy, "review");
|
|
2604
|
+
if (reviewerChanges.addedParticipants.length > 0 || reviewerChanges.removedParticipants.length > 0) {
|
|
2605
|
+
await logActivity(db, {
|
|
2606
|
+
companyId: issue.companyId,
|
|
2607
|
+
actorType: actor.actorType,
|
|
2608
|
+
actorId: actor.actorId,
|
|
2609
|
+
agentId: actor.agentId,
|
|
2610
|
+
runId: actor.runId,
|
|
2611
|
+
action: "issue.reviewers_updated",
|
|
2612
|
+
entityType: "issue",
|
|
2613
|
+
entityId: issue.id,
|
|
2614
|
+
details: {
|
|
2615
|
+
identifier: issue.identifier,
|
|
2616
|
+
participants: reviewerChanges.participants,
|
|
2617
|
+
addedParticipants: reviewerChanges.addedParticipants,
|
|
2618
|
+
removedParticipants: reviewerChanges.removedParticipants,
|
|
2619
|
+
},
|
|
2620
|
+
});
|
|
2621
|
+
}
|
|
2622
|
+
const approverChanges = diffExecutionParticipants(previousExecutionPolicy, nextExecutionPolicy, "approval");
|
|
2623
|
+
if (approverChanges.addedParticipants.length > 0 || approverChanges.removedParticipants.length > 0) {
|
|
2624
|
+
await logActivity(db, {
|
|
2625
|
+
companyId: issue.companyId,
|
|
2626
|
+
actorType: actor.actorType,
|
|
2627
|
+
actorId: actor.actorId,
|
|
2628
|
+
agentId: actor.agentId,
|
|
2629
|
+
runId: actor.runId,
|
|
2630
|
+
action: "issue.approvers_updated",
|
|
2631
|
+
entityType: "issue",
|
|
2632
|
+
entityId: issue.id,
|
|
2633
|
+
details: {
|
|
2634
|
+
identifier: issue.identifier,
|
|
2635
|
+
participants: approverChanges.participants,
|
|
2636
|
+
addedParticipants: approverChanges.addedParticipants,
|
|
2637
|
+
removedParticipants: approverChanges.removedParticipants,
|
|
2638
|
+
},
|
|
2639
|
+
});
|
|
2640
|
+
}
|
|
2641
|
+
const nextStoredExecutionPolicy = normalizeIssueExecutionPolicy(issue.executionPolicy ?? null);
|
|
2642
|
+
const previousMonitor = summarizeIssueMonitor(existing, previousExecutionPolicy);
|
|
2643
|
+
const nextMonitor = summarizeIssueMonitor(issue, nextStoredExecutionPolicy);
|
|
2644
|
+
const monitorScheduledChanged = previousMonitor.nextCheckAt !== nextMonitor.nextCheckAt;
|
|
2645
|
+
if (nextMonitor.nextCheckAt && (monitorScheduledChanged || previousMonitor.notes !== nextMonitor.notes)) {
|
|
2646
|
+
await logActivity(db, {
|
|
2647
|
+
companyId: issue.companyId,
|
|
2648
|
+
actorType: actor.actorType,
|
|
2649
|
+
actorId: actor.actorId,
|
|
2650
|
+
agentId: actor.agentId,
|
|
2651
|
+
runId: actor.runId,
|
|
2652
|
+
action: "issue.monitor_scheduled",
|
|
2653
|
+
entityType: "issue",
|
|
2654
|
+
entityId: issue.id,
|
|
2655
|
+
details: {
|
|
2656
|
+
identifier: issue.identifier,
|
|
2657
|
+
nextCheckAt: nextMonitor.nextCheckAt,
|
|
2658
|
+
previousNextCheckAt: previousMonitor.nextCheckAt,
|
|
2659
|
+
notes: nextMonitor.notes,
|
|
2660
|
+
scheduledBy: nextMonitor.scheduledBy,
|
|
2661
|
+
serviceName: nextMonitor.serviceName,
|
|
2662
|
+
timeoutAt: nextMonitor.timeoutAt,
|
|
2663
|
+
maxAttempts: nextMonitor.maxAttempts,
|
|
2664
|
+
recoveryPolicy: nextMonitor.recoveryPolicy,
|
|
2665
|
+
},
|
|
2666
|
+
});
|
|
2667
|
+
}
|
|
2668
|
+
else if (!nextMonitor.nextCheckAt && previousMonitor.nextCheckAt) {
|
|
2669
|
+
await logActivity(db, {
|
|
2670
|
+
companyId: issue.companyId,
|
|
2671
|
+
actorType: actor.actorType,
|
|
2672
|
+
actorId: actor.actorId,
|
|
2673
|
+
agentId: actor.agentId,
|
|
2674
|
+
runId: actor.runId,
|
|
2675
|
+
action: "issue.monitor_cleared",
|
|
2676
|
+
entityType: "issue",
|
|
2677
|
+
entityId: issue.id,
|
|
2678
|
+
details: {
|
|
2679
|
+
identifier: issue.identifier,
|
|
2680
|
+
previousNextCheckAt: previousMonitor.nextCheckAt,
|
|
2681
|
+
reason: nextMonitor.clearReason ?? "manual",
|
|
2682
|
+
notes: previousMonitor.notes,
|
|
2683
|
+
},
|
|
2684
|
+
});
|
|
2685
|
+
}
|
|
2686
|
+
if (issue.status === "done" && existing.status !== "done") {
|
|
2687
|
+
const tc = getTelemetryClient();
|
|
2688
|
+
if (tc && actor.agentId) {
|
|
2689
|
+
const actorAgent = await agentsSvc.getById(actor.agentId);
|
|
2690
|
+
if (actorAgent) {
|
|
2691
|
+
const model = typeof actorAgent.adapterConfig?.model === "string" ? actorAgent.adapterConfig.model : undefined;
|
|
2692
|
+
trackAgentTaskCompleted(tc, {
|
|
2693
|
+
agentRole: actorAgent.role,
|
|
2694
|
+
agentId: actorAgent.id,
|
|
2695
|
+
adapterType: actorAgent.adapterType,
|
|
2696
|
+
model,
|
|
2697
|
+
});
|
|
2698
|
+
}
|
|
2699
|
+
}
|
|
2700
|
+
}
|
|
2701
|
+
let comment = null;
|
|
2702
|
+
if (commentBody) {
|
|
2703
|
+
const commentReferenceSummaryBefore = updateReferenceSummaryAfter
|
|
2704
|
+
?? await issueReferencesSvc.listIssueReferenceSummary(issue.id);
|
|
2705
|
+
comment = await svc.addComment(id, commentBody, {
|
|
2706
|
+
agentId: actor.agentId ?? undefined,
|
|
2707
|
+
userId: actor.actorType === "user" ? actor.actorId : undefined,
|
|
2708
|
+
runId: actor.runId,
|
|
2709
|
+
});
|
|
2710
|
+
await issueReferencesSvc.syncComment(comment.id);
|
|
2711
|
+
const commentReferenceSummaryAfter = await issueReferencesSvc.listIssueReferenceSummary(issue.id);
|
|
2712
|
+
const commentReferenceDiff = issueReferencesSvc.diffIssueReferenceSummary(commentReferenceSummaryBefore, commentReferenceSummaryAfter);
|
|
2713
|
+
issueResponse = {
|
|
2714
|
+
...issueResponse,
|
|
2715
|
+
relatedWork: commentReferenceSummaryAfter,
|
|
2716
|
+
referencedIssueIdentifiers: commentReferenceSummaryAfter.outbound.map((item) => item.issue.identifier ?? item.issue.id),
|
|
2717
|
+
};
|
|
2718
|
+
await logActivity(db, {
|
|
2719
|
+
companyId: issue.companyId,
|
|
2720
|
+
actorType: actor.actorType,
|
|
2721
|
+
actorId: actor.actorId,
|
|
2722
|
+
agentId: actor.agentId,
|
|
2723
|
+
runId: actor.runId,
|
|
2724
|
+
action: "issue.comment_added",
|
|
2725
|
+
entityType: "issue",
|
|
2726
|
+
entityId: issue.id,
|
|
2727
|
+
details: {
|
|
2728
|
+
commentId: comment.id,
|
|
2729
|
+
bodySnippet: comment.body.slice(0, 120),
|
|
2730
|
+
identifier: issue.identifier,
|
|
2731
|
+
issueTitle: issue.title,
|
|
2732
|
+
...(resumeRequested === true ? { resumeIntent: true, followUpRequested: true } : {}),
|
|
2733
|
+
...(reopened ? { reopened: true, reopenedFrom: reopenFromStatus, source: "comment" } : {}),
|
|
2734
|
+
...(interruptedRunId ? { interruptedRunId } : {}),
|
|
2735
|
+
...(hasFieldChanges ? { updated: true } : {}),
|
|
2736
|
+
...summarizeIssueReferenceActivityDetails({
|
|
2737
|
+
addedReferencedIssues: commentReferenceDiff.addedReferencedIssues.map(summarizeIssueRelationForActivity),
|
|
2738
|
+
removedReferencedIssues: commentReferenceDiff.removedReferencedIssues.map(summarizeIssueRelationForActivity),
|
|
2739
|
+
currentReferencedIssues: commentReferenceDiff.currentReferencedIssues.map(summarizeIssueRelationForActivity),
|
|
2740
|
+
}),
|
|
2741
|
+
},
|
|
2742
|
+
});
|
|
2743
|
+
const expiredInteractions = await issueThreadInteractionService(db).expireRequestConfirmationsSupersededByComment(issue, comment, {
|
|
2744
|
+
agentId: actor.agentId,
|
|
2745
|
+
userId: actor.actorType === "user" ? actor.actorId : null,
|
|
2746
|
+
});
|
|
2747
|
+
await logExpiredRequestConfirmations({
|
|
2748
|
+
issue,
|
|
2749
|
+
interactions: expiredInteractions,
|
|
2750
|
+
actor,
|
|
2751
|
+
source: "issue.comment",
|
|
2752
|
+
});
|
|
2753
|
+
}
|
|
2754
|
+
else if (updateReferenceSummaryAfter) {
|
|
2755
|
+
issueResponse = {
|
|
2756
|
+
...issueResponse,
|
|
2757
|
+
relatedWork: updateReferenceSummaryAfter,
|
|
2758
|
+
referencedIssueIdentifiers: updateReferenceSummaryAfter.outbound.map((item) => item.issue.identifier ?? item.issue.id),
|
|
2759
|
+
};
|
|
2760
|
+
}
|
|
2761
|
+
const assigneeChanged = issue.assigneeAgentId !== existing.assigneeAgentId || issue.assigneeUserId !== existing.assigneeUserId;
|
|
2762
|
+
const statusChangedFromBacklog = existing.status === "backlog" &&
|
|
2763
|
+
issue.status !== "backlog" &&
|
|
2764
|
+
req.body.status !== undefined;
|
|
2765
|
+
const statusChangedFromBlockedToTodo = existing.status === "blocked" &&
|
|
2766
|
+
issue.status === "todo" &&
|
|
2767
|
+
(req.body.status !== undefined || reopened);
|
|
2768
|
+
const statusChangedFromClosedToTodo = isClosedIssueStatus(existing.status) &&
|
|
2769
|
+
issue.status === "todo" &&
|
|
2770
|
+
req.body.status !== undefined;
|
|
2771
|
+
const previousExecutionState = parseIssueExecutionState(existing.executionState);
|
|
2772
|
+
const nextExecutionState = parseIssueExecutionState(issue.executionState);
|
|
2773
|
+
const executionStageWakeup = buildExecutionStageWakeup({
|
|
2774
|
+
issueId: issue.id,
|
|
2775
|
+
previousState: previousExecutionState,
|
|
2776
|
+
nextState: nextExecutionState,
|
|
2777
|
+
interruptedRunId,
|
|
2778
|
+
requestedByActorType: actor.actorType,
|
|
2779
|
+
requestedByActorId: actor.actorId,
|
|
2780
|
+
});
|
|
2781
|
+
// Merge all wakeups from this update into one enqueue per agent to avoid duplicate runs.
|
|
2782
|
+
void (async () => {
|
|
2783
|
+
const wakeups = new Map();
|
|
2784
|
+
const addWakeup = (agentId, wakeup) => {
|
|
2785
|
+
const wakeIssueId = wakeup.payload && typeof wakeup.payload === "object" && typeof wakeup.payload.issueId === "string"
|
|
2786
|
+
? wakeup.payload.issueId
|
|
2787
|
+
: issue.id;
|
|
2788
|
+
wakeups.set(`${agentId}:${wakeIssueId}`, { agentId, wakeup });
|
|
2789
|
+
};
|
|
2790
|
+
if (executionStageWakeup) {
|
|
2791
|
+
addWakeup(executionStageWakeup.agentId, executionStageWakeup.wakeup);
|
|
2792
|
+
}
|
|
2793
|
+
else if (assigneeChanged && issue.assigneeAgentId && issue.status !== "backlog") {
|
|
2794
|
+
addWakeup(issue.assigneeAgentId, {
|
|
2795
|
+
source: "assignment",
|
|
2796
|
+
triggerDetail: "system",
|
|
2797
|
+
reason: "issue_assigned",
|
|
2798
|
+
payload: {
|
|
2799
|
+
issueId: issue.id,
|
|
2800
|
+
...(comment ? { commentId: comment.id } : {}),
|
|
2801
|
+
mutation: "update",
|
|
2802
|
+
...(resumeRequested === true ? { resumeIntent: true, followUpRequested: true } : {}),
|
|
2803
|
+
...(interruptedRunId ? { interruptedRunId } : {}),
|
|
2804
|
+
},
|
|
2805
|
+
requestedByActorType: actor.actorType,
|
|
2806
|
+
requestedByActorId: actor.actorId,
|
|
2807
|
+
contextSnapshot: {
|
|
2808
|
+
issueId: issue.id,
|
|
2809
|
+
...(comment
|
|
2810
|
+
? {
|
|
2811
|
+
taskId: issue.id,
|
|
2812
|
+
commentId: comment.id,
|
|
2813
|
+
wakeCommentId: comment.id,
|
|
2814
|
+
}
|
|
2815
|
+
: {}),
|
|
2816
|
+
source: "issue.update",
|
|
2817
|
+
...(resumeRequested === true ? { resumeIntent: true, followUpRequested: true } : {}),
|
|
2818
|
+
...(interruptedRunId ? { interruptedRunId } : {}),
|
|
2819
|
+
},
|
|
2820
|
+
});
|
|
2821
|
+
}
|
|
2822
|
+
if (!assigneeChanged &&
|
|
2823
|
+
(statusChangedFromBacklog || statusChangedFromBlockedToTodo || statusChangedFromClosedToTodo) &&
|
|
2824
|
+
issue.assigneeAgentId) {
|
|
2825
|
+
addWakeup(issue.assigneeAgentId, {
|
|
2826
|
+
source: "automation",
|
|
2827
|
+
triggerDetail: "system",
|
|
2828
|
+
reason: "issue_status_changed",
|
|
2829
|
+
payload: {
|
|
2830
|
+
issueId: issue.id,
|
|
2831
|
+
mutation: "update",
|
|
2832
|
+
...(resumeRequested === true ? { resumeIntent: true, followUpRequested: true } : {}),
|
|
2833
|
+
...(interruptedRunId ? { interruptedRunId } : {}),
|
|
2834
|
+
},
|
|
2835
|
+
requestedByActorType: actor.actorType,
|
|
2836
|
+
requestedByActorId: actor.actorId,
|
|
2837
|
+
contextSnapshot: {
|
|
2838
|
+
issueId: issue.id,
|
|
2839
|
+
source: "issue.status_change",
|
|
2840
|
+
...(resumeRequested === true ? { resumeIntent: true, followUpRequested: true } : {}),
|
|
2841
|
+
...(interruptedRunId ? { interruptedRunId } : {}),
|
|
2842
|
+
},
|
|
2843
|
+
});
|
|
2844
|
+
}
|
|
2845
|
+
if (commentBody && comment) {
|
|
2846
|
+
const assigneeId = issue.assigneeAgentId;
|
|
2847
|
+
const actorIsAgent = actor.actorType === "agent";
|
|
2848
|
+
const selfComment = actorIsAgent && actor.actorId === assigneeId;
|
|
2849
|
+
const skipAssigneeCommentWake = selfComment || isClosed;
|
|
2850
|
+
if (assigneeId && !assigneeChanged && (reopened || !skipAssigneeCommentWake)) {
|
|
2851
|
+
addWakeup(assigneeId, {
|
|
2852
|
+
source: "automation",
|
|
2853
|
+
triggerDetail: "system",
|
|
2854
|
+
reason: reopened ? "issue_reopened_via_comment" : "issue_commented",
|
|
2855
|
+
payload: {
|
|
2856
|
+
issueId: id,
|
|
2857
|
+
commentId: comment.id,
|
|
2858
|
+
mutation: "comment",
|
|
2859
|
+
...(reopened ? { reopenedFrom: reopenFromStatus } : {}),
|
|
2860
|
+
...(resumeRequested === true ? { resumeIntent: true, followUpRequested: true } : {}),
|
|
2861
|
+
...(interruptedRunId ? { interruptedRunId } : {}),
|
|
2862
|
+
},
|
|
2863
|
+
requestedByActorType: actor.actorType,
|
|
2864
|
+
requestedByActorId: actor.actorId,
|
|
2865
|
+
contextSnapshot: {
|
|
2866
|
+
issueId: id,
|
|
2867
|
+
taskId: id,
|
|
2868
|
+
commentId: comment.id,
|
|
2869
|
+
wakeCommentId: comment.id,
|
|
2870
|
+
source: reopened ? "issue.comment.reopen" : "issue.comment",
|
|
2871
|
+
wakeReason: reopened ? "issue_reopened_via_comment" : "issue_commented",
|
|
2872
|
+
...(reopened ? { reopenedFrom: reopenFromStatus } : {}),
|
|
2873
|
+
...(resumeRequested === true ? { resumeIntent: true, followUpRequested: true } : {}),
|
|
2874
|
+
...(interruptedRunId ? { interruptedRunId } : {}),
|
|
2875
|
+
},
|
|
2876
|
+
});
|
|
2877
|
+
}
|
|
2878
|
+
let mentionedIds = [];
|
|
2879
|
+
try {
|
|
2880
|
+
mentionedIds = await svc.findMentionedAgents(issue.companyId, commentBody);
|
|
2881
|
+
}
|
|
2882
|
+
catch (err) {
|
|
2883
|
+
logger.warn({ err, issueId: id }, "failed to resolve @-mentions");
|
|
2884
|
+
}
|
|
2885
|
+
for (const mentionedId of mentionedIds) {
|
|
2886
|
+
if (actor.actorType === "agent" && actor.actorId === mentionedId)
|
|
2887
|
+
continue;
|
|
2888
|
+
addWakeup(mentionedId, {
|
|
2889
|
+
source: "automation",
|
|
2890
|
+
triggerDetail: "system",
|
|
2891
|
+
reason: "issue_comment_mentioned",
|
|
2892
|
+
payload: { issueId: id, commentId: comment.id },
|
|
2893
|
+
requestedByActorType: actor.actorType,
|
|
2894
|
+
requestedByActorId: actor.actorId,
|
|
2895
|
+
contextSnapshot: {
|
|
2896
|
+
issueId: id,
|
|
2897
|
+
taskId: id,
|
|
2898
|
+
commentId: comment.id,
|
|
2899
|
+
wakeCommentId: comment.id,
|
|
2900
|
+
wakeReason: "issue_comment_mentioned",
|
|
2901
|
+
source: "comment.mention",
|
|
2902
|
+
},
|
|
2903
|
+
});
|
|
2904
|
+
}
|
|
2905
|
+
}
|
|
2906
|
+
const becameDone = existing.status !== "done" && issue.status === "done";
|
|
2907
|
+
if (becameDone) {
|
|
2908
|
+
const dependents = await svc.listWakeableBlockedDependents(issue.id);
|
|
2909
|
+
for (const dependent of dependents) {
|
|
2910
|
+
addWakeup(dependent.assigneeAgentId, {
|
|
2911
|
+
source: "automation",
|
|
2912
|
+
triggerDetail: "system",
|
|
2913
|
+
reason: "issue_blockers_resolved",
|
|
2914
|
+
payload: {
|
|
2915
|
+
issueId: dependent.id,
|
|
2916
|
+
resolvedBlockerIssueId: issue.id,
|
|
2917
|
+
blockerIssueIds: dependent.blockerIssueIds,
|
|
2918
|
+
},
|
|
2919
|
+
requestedByActorType: actor.actorType,
|
|
2920
|
+
requestedByActorId: actor.actorId,
|
|
2921
|
+
contextSnapshot: {
|
|
2922
|
+
issueId: dependent.id,
|
|
2923
|
+
taskId: dependent.id,
|
|
2924
|
+
wakeReason: "issue_blockers_resolved",
|
|
2925
|
+
source: "issue.blockers_resolved",
|
|
2926
|
+
resolvedBlockerIssueId: issue.id,
|
|
2927
|
+
blockerIssueIds: dependent.blockerIssueIds,
|
|
2928
|
+
},
|
|
2929
|
+
});
|
|
2930
|
+
}
|
|
2931
|
+
}
|
|
2932
|
+
const becameTerminal = !["done", "cancelled"].includes(existing.status) && ["done", "cancelled"].includes(issue.status);
|
|
2933
|
+
if (becameTerminal && issue.parentId) {
|
|
2934
|
+
const parent = await svc.getWakeableParentAfterChildCompletion(issue.parentId);
|
|
2935
|
+
if (parent) {
|
|
2936
|
+
addWakeup(parent.assigneeAgentId, {
|
|
2937
|
+
source: "automation",
|
|
2938
|
+
triggerDetail: "system",
|
|
2939
|
+
reason: "issue_children_completed",
|
|
2940
|
+
payload: {
|
|
2941
|
+
issueId: parent.id,
|
|
2942
|
+
completedChildIssueId: issue.id,
|
|
2943
|
+
childIssueIds: parent.childIssueIds,
|
|
2944
|
+
childIssueSummaries: parent.childIssueSummaries,
|
|
2945
|
+
childIssueSummaryTruncated: parent.childIssueSummaryTruncated,
|
|
2946
|
+
},
|
|
2947
|
+
requestedByActorType: actor.actorType,
|
|
2948
|
+
requestedByActorId: actor.actorId,
|
|
2949
|
+
contextSnapshot: {
|
|
2950
|
+
issueId: parent.id,
|
|
2951
|
+
taskId: parent.id,
|
|
2952
|
+
wakeReason: "issue_children_completed",
|
|
2953
|
+
source: "issue.children_completed",
|
|
2954
|
+
completedChildIssueId: issue.id,
|
|
2955
|
+
childIssueIds: parent.childIssueIds,
|
|
2956
|
+
childIssueSummaries: parent.childIssueSummaries,
|
|
2957
|
+
childIssueSummaryTruncated: parent.childIssueSummaryTruncated,
|
|
2958
|
+
},
|
|
2959
|
+
});
|
|
2960
|
+
}
|
|
2961
|
+
}
|
|
2962
|
+
for (const { agentId, wakeup } of wakeups.values()) {
|
|
2963
|
+
heartbeat
|
|
2964
|
+
.wakeup(agentId, wakeup)
|
|
2965
|
+
.catch((err) => logger.warn({ err, issueId: issue.id, agentId }, "failed to wake agent on issue update"));
|
|
2966
|
+
}
|
|
2967
|
+
})();
|
|
2968
|
+
res.json({ ...issueResponse, comment });
|
|
2969
|
+
});
|
|
2970
|
+
router.delete("/issues/:id", async (req, res) => {
|
|
2971
|
+
const id = req.params.id;
|
|
2972
|
+
const existing = await svc.getById(id);
|
|
2973
|
+
if (!existing) {
|
|
2974
|
+
res.status(404).json({ error: "Issue not found" });
|
|
2975
|
+
return;
|
|
2976
|
+
}
|
|
2977
|
+
assertCompanyAccess(req, existing.companyId);
|
|
2978
|
+
if (!(await assertAgentIssueMutationAllowed(req, res, existing)))
|
|
2979
|
+
return;
|
|
2980
|
+
const attachments = await svc.listAttachments(id);
|
|
2981
|
+
const issue = await svc.remove(id);
|
|
2982
|
+
if (!issue) {
|
|
2983
|
+
res.status(404).json({ error: "Issue not found" });
|
|
2984
|
+
return;
|
|
2985
|
+
}
|
|
2986
|
+
for (const attachment of attachments) {
|
|
2987
|
+
try {
|
|
2988
|
+
await storage.deleteObject(attachment.companyId, attachment.objectKey);
|
|
2989
|
+
}
|
|
2990
|
+
catch (err) {
|
|
2991
|
+
logger.warn({ err, issueId: id, attachmentId: attachment.id }, "failed to delete attachment object during issue delete");
|
|
2992
|
+
}
|
|
2993
|
+
}
|
|
2994
|
+
const actor = getActorInfo(req);
|
|
2995
|
+
await logActivity(db, {
|
|
2996
|
+
companyId: issue.companyId,
|
|
2997
|
+
actorType: actor.actorType,
|
|
2998
|
+
actorId: actor.actorId,
|
|
2999
|
+
agentId: actor.agentId,
|
|
3000
|
+
runId: actor.runId,
|
|
3001
|
+
action: "issue.deleted",
|
|
3002
|
+
entityType: "issue",
|
|
3003
|
+
entityId: issue.id,
|
|
3004
|
+
});
|
|
3005
|
+
res.json(issue);
|
|
3006
|
+
});
|
|
3007
|
+
router.post("/issues/:id/checkout", validate(checkoutIssueSchema), async (req, res) => {
|
|
3008
|
+
const id = req.params.id;
|
|
3009
|
+
const issue = await svc.getById(id);
|
|
3010
|
+
if (!issue) {
|
|
3011
|
+
res.status(404).json({ error: "Issue not found" });
|
|
3012
|
+
return;
|
|
3013
|
+
}
|
|
3014
|
+
assertCompanyAccess(req, issue.companyId);
|
|
3015
|
+
if (issue.projectId) {
|
|
3016
|
+
const project = await projectsSvc.getById(issue.projectId);
|
|
3017
|
+
if (project?.pausedAt) {
|
|
3018
|
+
res.status(409).json({
|
|
3019
|
+
error: project.pauseReason === "budget"
|
|
3020
|
+
? "Project is paused because its budget hard-stop was reached"
|
|
3021
|
+
: "Project is paused",
|
|
3022
|
+
});
|
|
3023
|
+
return;
|
|
3024
|
+
}
|
|
3025
|
+
}
|
|
3026
|
+
if (req.actor.type === "agent" && req.actor.agentId !== req.body.agentId) {
|
|
3027
|
+
res.status(403).json({ error: "Agent can only checkout as itself" });
|
|
3028
|
+
return;
|
|
3029
|
+
}
|
|
3030
|
+
const closedExecutionWorkspace = await getClosedIssueExecutionWorkspace(issue);
|
|
3031
|
+
if (closedExecutionWorkspace) {
|
|
3032
|
+
respondClosedIssueExecutionWorkspace(res, closedExecutionWorkspace);
|
|
3033
|
+
return;
|
|
3034
|
+
}
|
|
3035
|
+
const checkoutRunId = requireAgentRunId(req, res);
|
|
3036
|
+
if (req.actor.type === "agent" && !checkoutRunId)
|
|
3037
|
+
return;
|
|
3038
|
+
const updated = await svc.checkout(id, req.body.agentId, req.body.expectedStatuses, checkoutRunId);
|
|
3039
|
+
const actor = getActorInfo(req);
|
|
3040
|
+
await logActivity(db, {
|
|
3041
|
+
companyId: issue.companyId,
|
|
3042
|
+
actorType: actor.actorType,
|
|
3043
|
+
actorId: actor.actorId,
|
|
3044
|
+
agentId: actor.agentId,
|
|
3045
|
+
runId: actor.runId,
|
|
3046
|
+
action: "issue.checked_out",
|
|
3047
|
+
entityType: "issue",
|
|
3048
|
+
entityId: issue.id,
|
|
3049
|
+
details: { agentId: req.body.agentId },
|
|
3050
|
+
});
|
|
3051
|
+
if (shouldWakeAssigneeOnCheckout({
|
|
3052
|
+
actorType: req.actor.type,
|
|
3053
|
+
actorAgentId: req.actor.type === "agent" ? req.actor.agentId ?? null : null,
|
|
3054
|
+
checkoutAgentId: req.body.agentId,
|
|
3055
|
+
checkoutRunId,
|
|
3056
|
+
})) {
|
|
3057
|
+
void heartbeat
|
|
3058
|
+
.wakeup(req.body.agentId, {
|
|
3059
|
+
source: "assignment",
|
|
3060
|
+
triggerDetail: "system",
|
|
3061
|
+
reason: "issue_checked_out",
|
|
3062
|
+
payload: { issueId: issue.id, mutation: "checkout" },
|
|
3063
|
+
requestedByActorType: actor.actorType,
|
|
3064
|
+
requestedByActorId: actor.actorId,
|
|
3065
|
+
contextSnapshot: { issueId: issue.id, source: "issue.checkout" },
|
|
3066
|
+
})
|
|
3067
|
+
.catch((err) => logger.warn({ err, issueId: issue.id }, "failed to wake assignee on issue checkout"));
|
|
3068
|
+
}
|
|
3069
|
+
res.json(updated);
|
|
3070
|
+
});
|
|
3071
|
+
router.post("/issues/:id/release", async (req, res) => {
|
|
3072
|
+
const id = req.params.id;
|
|
3073
|
+
const existing = await svc.getById(id);
|
|
3074
|
+
if (!existing) {
|
|
3075
|
+
res.status(404).json({ error: "Issue not found" });
|
|
3076
|
+
return;
|
|
3077
|
+
}
|
|
3078
|
+
assertCompanyAccess(req, existing.companyId);
|
|
3079
|
+
if (!(await assertAgentIssueMutationAllowed(req, res, existing)))
|
|
3080
|
+
return;
|
|
3081
|
+
const actorRunId = requireAgentRunId(req, res);
|
|
3082
|
+
if (req.actor.type === "agent" && !actorRunId)
|
|
3083
|
+
return;
|
|
3084
|
+
const released = await svc.release(id, req.actor.type === "agent" ? req.actor.agentId : undefined, actorRunId);
|
|
3085
|
+
if (!released) {
|
|
3086
|
+
res.status(404).json({ error: "Issue not found" });
|
|
3087
|
+
return;
|
|
3088
|
+
}
|
|
3089
|
+
const actor = getActorInfo(req);
|
|
3090
|
+
await logActivity(db, {
|
|
3091
|
+
companyId: released.companyId,
|
|
3092
|
+
actorType: actor.actorType,
|
|
3093
|
+
actorId: actor.actorId,
|
|
3094
|
+
agentId: actor.agentId,
|
|
3095
|
+
runId: actor.runId,
|
|
3096
|
+
action: "issue.released",
|
|
3097
|
+
entityType: "issue",
|
|
3098
|
+
entityId: released.id,
|
|
3099
|
+
});
|
|
3100
|
+
res.json(released);
|
|
3101
|
+
});
|
|
3102
|
+
router.post("/issues/:id/admin/force-release", async (req, res) => {
|
|
3103
|
+
if (req.actor.type !== "board") {
|
|
3104
|
+
res.status(403).json({ error: "Board access required" });
|
|
3105
|
+
return;
|
|
3106
|
+
}
|
|
3107
|
+
if (!req.actor.userId) {
|
|
3108
|
+
throw forbidden("Board user context required");
|
|
3109
|
+
}
|
|
3110
|
+
const id = req.params.id;
|
|
3111
|
+
const existing = await svc.getById(id);
|
|
3112
|
+
if (!existing) {
|
|
3113
|
+
res.status(404).json({ error: "Issue not found" });
|
|
3114
|
+
return;
|
|
3115
|
+
}
|
|
3116
|
+
assertCompanyAccess(req, existing.companyId);
|
|
3117
|
+
const clearAssignee = req.query.clearAssignee === "true";
|
|
3118
|
+
const result = await svc.adminForceRelease(id, { clearAssignee });
|
|
3119
|
+
if (!result) {
|
|
3120
|
+
res.status(404).json({ error: "Issue not found" });
|
|
3121
|
+
return;
|
|
3122
|
+
}
|
|
3123
|
+
const actor = getActorInfo(req);
|
|
3124
|
+
await logActivity(db, {
|
|
3125
|
+
companyId: result.issue.companyId,
|
|
3126
|
+
actorType: actor.actorType,
|
|
3127
|
+
actorId: actor.actorId,
|
|
3128
|
+
agentId: actor.agentId,
|
|
3129
|
+
runId: actor.runId,
|
|
3130
|
+
action: "issue.admin_force_release",
|
|
3131
|
+
entityType: "issue",
|
|
3132
|
+
entityId: result.issue.id,
|
|
3133
|
+
details: {
|
|
3134
|
+
issueId: result.issue.id,
|
|
3135
|
+
actorUserId: req.actor.userId,
|
|
3136
|
+
prevCheckoutRunId: result.previous.checkoutRunId,
|
|
3137
|
+
prevExecutionRunId: result.previous.executionRunId,
|
|
3138
|
+
clearAssignee,
|
|
3139
|
+
},
|
|
3140
|
+
});
|
|
3141
|
+
res.json(result);
|
|
3142
|
+
});
|
|
3143
|
+
router.get("/issues/:id/comments", async (req, res) => {
|
|
3144
|
+
const id = req.params.id;
|
|
3145
|
+
const issue = await svc.getById(id);
|
|
3146
|
+
if (!issue) {
|
|
3147
|
+
res.status(404).json({ error: "Issue not found" });
|
|
3148
|
+
return;
|
|
3149
|
+
}
|
|
3150
|
+
assertCompanyAccess(req, issue.companyId);
|
|
3151
|
+
const afterCommentId = typeof req.query.after === "string" && req.query.after.trim().length > 0
|
|
3152
|
+
? req.query.after.trim()
|
|
3153
|
+
: typeof req.query.afterCommentId === "string" && req.query.afterCommentId.trim().length > 0
|
|
3154
|
+
? req.query.afterCommentId.trim()
|
|
3155
|
+
: null;
|
|
3156
|
+
const order = typeof req.query.order === "string" && req.query.order.trim().toLowerCase() === "asc"
|
|
3157
|
+
? "asc"
|
|
3158
|
+
: "desc";
|
|
3159
|
+
const limitRaw = typeof req.query.limit === "string" && req.query.limit.trim().length > 0
|
|
3160
|
+
? Number(req.query.limit)
|
|
3161
|
+
: null;
|
|
3162
|
+
const limit = limitRaw && Number.isFinite(limitRaw) && limitRaw > 0
|
|
3163
|
+
? Math.min(Math.floor(limitRaw), MAX_ISSUE_COMMENT_LIMIT)
|
|
3164
|
+
: null;
|
|
3165
|
+
const comments = await svc.listComments(id, {
|
|
3166
|
+
afterCommentId,
|
|
3167
|
+
order,
|
|
3168
|
+
limit,
|
|
3169
|
+
});
|
|
3170
|
+
res.json(comments);
|
|
3171
|
+
});
|
|
3172
|
+
router.get("/issues/:id/interactions", async (req, res) => {
|
|
3173
|
+
const id = req.params.id;
|
|
3174
|
+
const issue = await svc.getById(id);
|
|
3175
|
+
if (!issue) {
|
|
3176
|
+
res.status(404).json({ error: "Issue not found" });
|
|
3177
|
+
return;
|
|
3178
|
+
}
|
|
3179
|
+
assertCompanyAccess(req, issue.companyId);
|
|
3180
|
+
const interactions = await issueThreadInteractionService(db).listForIssue(id);
|
|
3181
|
+
res.json(interactions);
|
|
3182
|
+
});
|
|
3183
|
+
router.post("/issues/:id/interactions", validate(createIssueThreadInteractionSchema), async (req, res) => {
|
|
3184
|
+
const id = req.params.id;
|
|
3185
|
+
const issue = await svc.getById(id);
|
|
3186
|
+
if (!issue) {
|
|
3187
|
+
res.status(404).json({ error: "Issue not found" });
|
|
3188
|
+
return;
|
|
3189
|
+
}
|
|
3190
|
+
assertCompanyAccess(req, issue.companyId);
|
|
3191
|
+
if (req.actor.type === "agent") {
|
|
3192
|
+
if (!(await assertAgentIssueMutationAllowed(req, res, issue)))
|
|
3193
|
+
return;
|
|
3194
|
+
}
|
|
3195
|
+
else {
|
|
3196
|
+
assertBoard(req);
|
|
3197
|
+
}
|
|
3198
|
+
const actor = getActorInfo(req);
|
|
3199
|
+
const agentSourceRunId = req.actor.type === "agent" ? requireAgentRunId(req, res) : null;
|
|
3200
|
+
if (req.actor.type === "agent" && !agentSourceRunId)
|
|
3201
|
+
return;
|
|
3202
|
+
const interaction = await issueThreadInteractionService(db).create(issue, {
|
|
3203
|
+
...req.body,
|
|
3204
|
+
sourceRunId: req.actor.type === "agent" ? agentSourceRunId : req.body.sourceRunId ?? null,
|
|
3205
|
+
}, {
|
|
3206
|
+
agentId: actor.agentId,
|
|
3207
|
+
userId: actor.actorType === "user" ? actor.actorId : null,
|
|
3208
|
+
});
|
|
3209
|
+
await logActivity(db, {
|
|
3210
|
+
companyId: issue.companyId,
|
|
3211
|
+
actorType: actor.actorType,
|
|
3212
|
+
actorId: actor.actorId,
|
|
3213
|
+
agentId: actor.agentId,
|
|
3214
|
+
runId: actor.runId,
|
|
3215
|
+
action: "issue.thread_interaction_created",
|
|
3216
|
+
entityType: "issue",
|
|
3217
|
+
entityId: issue.id,
|
|
3218
|
+
details: {
|
|
3219
|
+
interactionId: interaction.id,
|
|
3220
|
+
interactionKind: interaction.kind,
|
|
3221
|
+
interactionStatus: interaction.status,
|
|
3222
|
+
continuationPolicy: interaction.continuationPolicy,
|
|
3223
|
+
},
|
|
3224
|
+
});
|
|
3225
|
+
res.status(201).json(interaction);
|
|
3226
|
+
});
|
|
3227
|
+
router.post("/issues/:id/interactions/:interactionId/accept", validate(acceptIssueThreadInteractionSchema), async (req, res) => {
|
|
3228
|
+
const id = req.params.id;
|
|
3229
|
+
const interactionId = req.params.interactionId;
|
|
3230
|
+
const issue = await svc.getById(id);
|
|
3231
|
+
if (!issue) {
|
|
3232
|
+
res.status(404).json({ error: "Issue not found" });
|
|
3233
|
+
return;
|
|
3234
|
+
}
|
|
3235
|
+
assertCompanyAccess(req, issue.companyId);
|
|
3236
|
+
assertBoard(req);
|
|
3237
|
+
const actor = getActorInfo(req);
|
|
3238
|
+
const { interaction, createdIssues, continuationIssue } = await issueThreadInteractionService(db).acceptInteraction(issue, interactionId, req.body, {
|
|
3239
|
+
agentId: actor.agentId,
|
|
3240
|
+
userId: actor.actorType === "user" ? actor.actorId : null,
|
|
3241
|
+
});
|
|
3242
|
+
const continuationWakeIssue = continuationIssue ?? issue;
|
|
3243
|
+
await logActivity(db, {
|
|
3244
|
+
companyId: issue.companyId,
|
|
3245
|
+
actorType: actor.actorType,
|
|
3246
|
+
actorId: actor.actorId,
|
|
3247
|
+
agentId: actor.agentId,
|
|
3248
|
+
runId: actor.runId,
|
|
3249
|
+
action: interaction.status === "expired"
|
|
3250
|
+
? "issue.thread_interaction_expired"
|
|
3251
|
+
: "issue.thread_interaction_accepted",
|
|
3252
|
+
entityType: "issue",
|
|
3253
|
+
entityId: issue.id,
|
|
3254
|
+
details: {
|
|
3255
|
+
interactionId: interaction.id,
|
|
3256
|
+
interactionKind: interaction.kind,
|
|
3257
|
+
interactionStatus: interaction.status,
|
|
3258
|
+
createdTaskCount: interaction.kind === "suggest_tasks"
|
|
3259
|
+
? (interaction.result?.createdTasks?.length ?? 0)
|
|
3260
|
+
: 0,
|
|
3261
|
+
skippedTaskCount: interaction.kind === "suggest_tasks"
|
|
3262
|
+
? (interaction.result?.skippedClientKeys?.length ?? 0)
|
|
3263
|
+
: 0,
|
|
3264
|
+
},
|
|
3265
|
+
});
|
|
3266
|
+
if (continuationIssue) {
|
|
3267
|
+
await logActivity(db, {
|
|
3268
|
+
companyId: issue.companyId,
|
|
3269
|
+
actorType: actor.actorType,
|
|
3270
|
+
actorId: actor.actorId,
|
|
3271
|
+
agentId: actor.agentId,
|
|
3272
|
+
runId: actor.runId,
|
|
3273
|
+
action: "issue.updated",
|
|
3274
|
+
entityType: "issue",
|
|
3275
|
+
entityId: issue.id,
|
|
3276
|
+
details: {
|
|
3277
|
+
identifier: issue.identifier,
|
|
3278
|
+
status: continuationIssue.status,
|
|
3279
|
+
assigneeAgentId: continuationIssue.assigneeAgentId ?? null,
|
|
3280
|
+
assigneeUserId: continuationIssue.assigneeUserId ?? null,
|
|
3281
|
+
source: "request_confirmation_accept",
|
|
3282
|
+
interactionId: interaction.id,
|
|
3283
|
+
_previous: {
|
|
3284
|
+
status: issue.status,
|
|
3285
|
+
assigneeAgentId: issue.assigneeAgentId ?? null,
|
|
3286
|
+
assigneeUserId: issue.assigneeUserId ?? null,
|
|
3287
|
+
},
|
|
3288
|
+
},
|
|
3289
|
+
});
|
|
3290
|
+
}
|
|
3291
|
+
for (const createdIssue of createdIssues) {
|
|
3292
|
+
void queueIssueAssignmentWakeup({
|
|
3293
|
+
heartbeat,
|
|
3294
|
+
issue: createdIssue,
|
|
3295
|
+
reason: "issue_assigned",
|
|
3296
|
+
mutation: "interaction_accept",
|
|
3297
|
+
contextSource: "issue.interaction.accept",
|
|
3298
|
+
requestedByActorType: actor.actorType,
|
|
3299
|
+
requestedByActorId: actor.actorId,
|
|
3300
|
+
});
|
|
3301
|
+
}
|
|
3302
|
+
queueResolvedInteractionContinuationWakeup({
|
|
3303
|
+
heartbeat,
|
|
3304
|
+
issue: continuationWakeIssue,
|
|
3305
|
+
interaction,
|
|
3306
|
+
actor,
|
|
3307
|
+
source: "issue.interaction.accept",
|
|
3308
|
+
});
|
|
3309
|
+
res.json(interaction);
|
|
3310
|
+
});
|
|
3311
|
+
router.post("/issues/:id/interactions/:interactionId/reject", validate(rejectIssueThreadInteractionSchema), async (req, res) => {
|
|
3312
|
+
const id = req.params.id;
|
|
3313
|
+
const interactionId = req.params.interactionId;
|
|
3314
|
+
const issue = await svc.getById(id);
|
|
3315
|
+
if (!issue) {
|
|
3316
|
+
res.status(404).json({ error: "Issue not found" });
|
|
3317
|
+
return;
|
|
3318
|
+
}
|
|
3319
|
+
assertCompanyAccess(req, issue.companyId);
|
|
3320
|
+
assertBoard(req);
|
|
3321
|
+
const actor = getActorInfo(req);
|
|
3322
|
+
const interaction = await issueThreadInteractionService(db).rejectInteraction(issue, interactionId, req.body, {
|
|
3323
|
+
agentId: actor.agentId,
|
|
3324
|
+
userId: actor.actorType === "user" ? actor.actorId : null,
|
|
3325
|
+
});
|
|
3326
|
+
await logActivity(db, {
|
|
3327
|
+
companyId: issue.companyId,
|
|
3328
|
+
actorType: actor.actorType,
|
|
3329
|
+
actorId: actor.actorId,
|
|
3330
|
+
agentId: actor.agentId,
|
|
3331
|
+
runId: actor.runId,
|
|
3332
|
+
action: interaction.status === "expired"
|
|
3333
|
+
? "issue.thread_interaction_expired"
|
|
3334
|
+
: "issue.thread_interaction_rejected",
|
|
3335
|
+
entityType: "issue",
|
|
3336
|
+
entityId: issue.id,
|
|
3337
|
+
details: {
|
|
3338
|
+
interactionId: interaction.id,
|
|
3339
|
+
interactionKind: interaction.kind,
|
|
3340
|
+
interactionStatus: interaction.status,
|
|
3341
|
+
rejectionReason: interaction.kind === "suggest_tasks"
|
|
3342
|
+
? (interaction.result?.rejectionReason ?? null)
|
|
3343
|
+
: interaction.kind === "request_confirmation"
|
|
3344
|
+
? (interaction.result?.reason ?? null)
|
|
3345
|
+
: null,
|
|
3346
|
+
},
|
|
3347
|
+
});
|
|
3348
|
+
queueResolvedInteractionContinuationWakeup({
|
|
3349
|
+
heartbeat,
|
|
3350
|
+
issue,
|
|
3351
|
+
interaction,
|
|
3352
|
+
actor,
|
|
3353
|
+
source: "issue.interaction.reject",
|
|
3354
|
+
});
|
|
3355
|
+
res.json(interaction);
|
|
3356
|
+
});
|
|
3357
|
+
router.post("/issues/:id/interactions/:interactionId/respond", validate(respondIssueThreadInteractionSchema), async (req, res) => {
|
|
3358
|
+
const id = req.params.id;
|
|
3359
|
+
const interactionId = req.params.interactionId;
|
|
3360
|
+
const issue = await svc.getById(id);
|
|
3361
|
+
if (!issue) {
|
|
3362
|
+
res.status(404).json({ error: "Issue not found" });
|
|
3363
|
+
return;
|
|
3364
|
+
}
|
|
3365
|
+
assertCompanyAccess(req, issue.companyId);
|
|
3366
|
+
assertBoard(req);
|
|
3367
|
+
const actor = getActorInfo(req);
|
|
3368
|
+
const interaction = await issueThreadInteractionService(db).answerQuestions(issue, interactionId, req.body, {
|
|
3369
|
+
agentId: actor.agentId,
|
|
3370
|
+
userId: actor.actorType === "user" ? actor.actorId : null,
|
|
3371
|
+
});
|
|
3372
|
+
await logActivity(db, {
|
|
3373
|
+
companyId: issue.companyId,
|
|
3374
|
+
actorType: actor.actorType,
|
|
3375
|
+
actorId: actor.actorId,
|
|
3376
|
+
agentId: actor.agentId,
|
|
3377
|
+
runId: actor.runId,
|
|
3378
|
+
action: "issue.thread_interaction_answered",
|
|
3379
|
+
entityType: "issue",
|
|
3380
|
+
entityId: issue.id,
|
|
3381
|
+
details: {
|
|
3382
|
+
interactionId: interaction.id,
|
|
3383
|
+
interactionKind: interaction.kind,
|
|
3384
|
+
interactionStatus: interaction.status,
|
|
3385
|
+
answeredQuestionCount: interaction.kind === "ask_user_questions"
|
|
3386
|
+
? (interaction.result?.answers?.length ?? 0)
|
|
3387
|
+
: 0,
|
|
3388
|
+
},
|
|
3389
|
+
});
|
|
3390
|
+
queueResolvedInteractionContinuationWakeup({
|
|
3391
|
+
heartbeat,
|
|
3392
|
+
issue,
|
|
3393
|
+
interaction,
|
|
3394
|
+
actor,
|
|
3395
|
+
source: "issue.interaction.respond",
|
|
3396
|
+
});
|
|
3397
|
+
res.json(interaction);
|
|
3398
|
+
});
|
|
3399
|
+
router.post("/issues/:id/interactions/:interactionId/cancel", validate(cancelIssueThreadInteractionSchema), async (req, res) => {
|
|
3400
|
+
const id = req.params.id;
|
|
3401
|
+
const interactionId = req.params.interactionId;
|
|
3402
|
+
const issue = await svc.getById(id);
|
|
3403
|
+
if (!issue) {
|
|
3404
|
+
res.status(404).json({ error: "Issue not found" });
|
|
3405
|
+
return;
|
|
3406
|
+
}
|
|
3407
|
+
assertCompanyAccess(req, issue.companyId);
|
|
3408
|
+
assertBoard(req);
|
|
3409
|
+
const actor = getActorInfo(req);
|
|
3410
|
+
const interaction = await issueThreadInteractionService(db).cancelQuestions(issue, interactionId, req.body, {
|
|
3411
|
+
agentId: actor.agentId,
|
|
3412
|
+
userId: actor.actorType === "user" ? actor.actorId : null,
|
|
3413
|
+
});
|
|
3414
|
+
await logActivity(db, {
|
|
3415
|
+
companyId: issue.companyId,
|
|
3416
|
+
actorType: actor.actorType,
|
|
3417
|
+
actorId: actor.actorId,
|
|
3418
|
+
agentId: actor.agentId,
|
|
3419
|
+
runId: actor.runId,
|
|
3420
|
+
action: "issue.thread_interaction_cancelled",
|
|
3421
|
+
entityType: "issue",
|
|
3422
|
+
entityId: issue.id,
|
|
3423
|
+
details: {
|
|
3424
|
+
interactionId: interaction.id,
|
|
3425
|
+
interactionKind: interaction.kind,
|
|
3426
|
+
interactionStatus: interaction.status,
|
|
3427
|
+
cancellationReason: interaction.kind === "ask_user_questions"
|
|
3428
|
+
? (interaction.result?.cancellationReason ?? null)
|
|
3429
|
+
: null,
|
|
3430
|
+
},
|
|
3431
|
+
});
|
|
3432
|
+
queueResolvedInteractionContinuationWakeup({
|
|
3433
|
+
heartbeat,
|
|
3434
|
+
issue,
|
|
3435
|
+
interaction,
|
|
3436
|
+
actor,
|
|
3437
|
+
source: "issue.interaction.cancel",
|
|
3438
|
+
});
|
|
3439
|
+
res.json(interaction);
|
|
3440
|
+
});
|
|
3441
|
+
router.get("/issues/:id/comments/:commentId", async (req, res) => {
|
|
3442
|
+
const id = req.params.id;
|
|
3443
|
+
const commentId = req.params.commentId;
|
|
3444
|
+
const issue = await svc.getById(id);
|
|
3445
|
+
if (!issue) {
|
|
3446
|
+
res.status(404).json({ error: "Issue not found" });
|
|
3447
|
+
return;
|
|
3448
|
+
}
|
|
3449
|
+
assertCompanyAccess(req, issue.companyId);
|
|
3450
|
+
const comment = await svc.getComment(commentId);
|
|
3451
|
+
if (!comment || comment.issueId !== id) {
|
|
3452
|
+
res.status(404).json({ error: "Comment not found" });
|
|
3453
|
+
return;
|
|
3454
|
+
}
|
|
3455
|
+
res.json(comment);
|
|
3456
|
+
});
|
|
3457
|
+
router.delete("/issues/:id/comments/:commentId", async (req, res) => {
|
|
3458
|
+
const id = req.params.id;
|
|
3459
|
+
const commentId = req.params.commentId;
|
|
3460
|
+
const issue = await svc.getById(id);
|
|
3461
|
+
if (!issue) {
|
|
3462
|
+
res.status(404).json({ error: "Issue not found" });
|
|
3463
|
+
return;
|
|
3464
|
+
}
|
|
3465
|
+
assertCompanyAccess(req, issue.companyId);
|
|
3466
|
+
if (!(await assertAgentIssueMutationAllowed(req, res, issue)))
|
|
3467
|
+
return;
|
|
3468
|
+
const comment = await svc.getComment(commentId);
|
|
3469
|
+
if (!comment || comment.issueId !== id) {
|
|
3470
|
+
res.status(404).json({ error: "Comment not found" });
|
|
3471
|
+
return;
|
|
3472
|
+
}
|
|
3473
|
+
const actor = getActorInfo(req);
|
|
3474
|
+
const actorOwnsComment = actor.actorType === "agent"
|
|
3475
|
+
? comment.authorAgentId === actor.agentId
|
|
3476
|
+
: comment.authorUserId === actor.actorId;
|
|
3477
|
+
if (!actorOwnsComment) {
|
|
3478
|
+
res.status(403).json({ error: "Only the comment author can cancel queued comments" });
|
|
3479
|
+
return;
|
|
3480
|
+
}
|
|
3481
|
+
const activeRun = await resolveActiveIssueRun(issue);
|
|
3482
|
+
if (!activeRun) {
|
|
3483
|
+
res.status(409).json({ error: "Queued comment can no longer be canceled" });
|
|
3484
|
+
return;
|
|
3485
|
+
}
|
|
3486
|
+
if (!isQueuedIssueCommentForActiveRun({ comment, activeRun })) {
|
|
3487
|
+
res.status(409).json({ error: "Only queued comments can be canceled" });
|
|
3488
|
+
return;
|
|
3489
|
+
}
|
|
3490
|
+
const removed = await svc.removeComment(commentId);
|
|
3491
|
+
if (!removed) {
|
|
3492
|
+
res.status(404).json({ error: "Comment not found" });
|
|
3493
|
+
return;
|
|
3494
|
+
}
|
|
3495
|
+
await logActivity(db, {
|
|
3496
|
+
companyId: issue.companyId,
|
|
3497
|
+
actorType: actor.actorType,
|
|
3498
|
+
actorId: actor.actorId,
|
|
3499
|
+
agentId: actor.agentId,
|
|
3500
|
+
runId: actor.runId,
|
|
3501
|
+
action: "issue.comment_cancelled",
|
|
3502
|
+
entityType: "issue",
|
|
3503
|
+
entityId: issue.id,
|
|
3504
|
+
details: {
|
|
3505
|
+
commentId: removed.id,
|
|
3506
|
+
bodySnippet: removed.body.slice(0, 120),
|
|
3507
|
+
identifier: issue.identifier,
|
|
3508
|
+
issueTitle: issue.title,
|
|
3509
|
+
source: "queue_cancel",
|
|
3510
|
+
queueTargetRunId: activeRun.id,
|
|
3511
|
+
},
|
|
3512
|
+
});
|
|
3513
|
+
res.json(removed);
|
|
3514
|
+
});
|
|
3515
|
+
router.get("/issues/:id/feedback-votes", async (req, res) => {
|
|
3516
|
+
const id = req.params.id;
|
|
3517
|
+
const issue = await svc.getById(id);
|
|
3518
|
+
if (!issue) {
|
|
3519
|
+
res.status(404).json({ error: "Issue not found" });
|
|
3520
|
+
return;
|
|
3521
|
+
}
|
|
3522
|
+
assertCompanyAccess(req, issue.companyId);
|
|
3523
|
+
if (req.actor.type !== "board") {
|
|
3524
|
+
res.status(403).json({ error: "Only board users can view feedback votes" });
|
|
3525
|
+
return;
|
|
3526
|
+
}
|
|
3527
|
+
const votes = await feedback.listIssueVotesForUser(id, req.actor.userId ?? "local-board");
|
|
3528
|
+
res.json(votes);
|
|
3529
|
+
});
|
|
3530
|
+
router.get("/issues/:id/feedback-traces", async (req, res) => {
|
|
3531
|
+
const id = req.params.id;
|
|
3532
|
+
const issue = await svc.getById(id);
|
|
3533
|
+
if (!issue) {
|
|
3534
|
+
res.status(404).json({ error: "Issue not found" });
|
|
3535
|
+
return;
|
|
3536
|
+
}
|
|
3537
|
+
assertCompanyAccess(req, issue.companyId);
|
|
3538
|
+
if (req.actor.type !== "board") {
|
|
3539
|
+
res.status(403).json({ error: "Only board users can view feedback traces" });
|
|
3540
|
+
return;
|
|
3541
|
+
}
|
|
3542
|
+
const targetTypeRaw = typeof req.query.targetType === "string" ? req.query.targetType : undefined;
|
|
3543
|
+
const voteRaw = typeof req.query.vote === "string" ? req.query.vote : undefined;
|
|
3544
|
+
const statusRaw = typeof req.query.status === "string" ? req.query.status : undefined;
|
|
3545
|
+
const targetType = targetTypeRaw ? feedbackTargetTypeSchema.parse(targetTypeRaw) : undefined;
|
|
3546
|
+
const vote = voteRaw ? feedbackVoteValueSchema.parse(voteRaw) : undefined;
|
|
3547
|
+
const status = statusRaw ? feedbackTraceStatusSchema.parse(statusRaw) : undefined;
|
|
3548
|
+
const traces = await feedback.listFeedbackTraces({
|
|
3549
|
+
companyId: issue.companyId,
|
|
3550
|
+
issueId: issue.id,
|
|
3551
|
+
targetType,
|
|
3552
|
+
vote,
|
|
3553
|
+
status,
|
|
3554
|
+
from: parseDateQuery(req.query.from, "from"),
|
|
3555
|
+
to: parseDateQuery(req.query.to, "to"),
|
|
3556
|
+
sharedOnly: parseBooleanQuery(req.query.sharedOnly),
|
|
3557
|
+
includePayload: parseBooleanQuery(req.query.includePayload),
|
|
3558
|
+
});
|
|
3559
|
+
res.json(traces);
|
|
3560
|
+
});
|
|
3561
|
+
router.get("/feedback-traces/:traceId", async (req, res) => {
|
|
3562
|
+
const traceId = req.params.traceId;
|
|
3563
|
+
if (req.actor.type !== "board") {
|
|
3564
|
+
res.status(403).json({ error: "Only board users can view feedback traces" });
|
|
3565
|
+
return;
|
|
3566
|
+
}
|
|
3567
|
+
const includePayload = parseBooleanQuery(req.query.includePayload) || req.query.includePayload === undefined;
|
|
3568
|
+
const trace = await feedback.getFeedbackTraceById(traceId, includePayload);
|
|
3569
|
+
if (!trace || !actorCanAccessCompany(req, trace.companyId)) {
|
|
3570
|
+
res.status(404).json({ error: "Feedback trace not found" });
|
|
3571
|
+
return;
|
|
3572
|
+
}
|
|
3573
|
+
res.json(trace);
|
|
3574
|
+
});
|
|
3575
|
+
router.get("/feedback-traces/:traceId/bundle", async (req, res) => {
|
|
3576
|
+
const traceId = req.params.traceId;
|
|
3577
|
+
if (req.actor.type !== "board") {
|
|
3578
|
+
res.status(403).json({ error: "Only board users can view feedback trace bundles" });
|
|
3579
|
+
return;
|
|
3580
|
+
}
|
|
3581
|
+
const bundle = await feedback.getFeedbackTraceBundle(traceId);
|
|
3582
|
+
if (!bundle || !actorCanAccessCompany(req, bundle.companyId)) {
|
|
3583
|
+
res.status(404).json({ error: "Feedback trace not found" });
|
|
3584
|
+
return;
|
|
3585
|
+
}
|
|
3586
|
+
res.json(bundle);
|
|
3587
|
+
});
|
|
3588
|
+
router.post("/issues/:id/comments", validate(addIssueCommentSchema), async (req, res) => {
|
|
3589
|
+
const id = req.params.id;
|
|
3590
|
+
const issue = await svc.getById(id);
|
|
3591
|
+
if (!issue) {
|
|
3592
|
+
res.status(404).json({ error: "Issue not found" });
|
|
3593
|
+
return;
|
|
3594
|
+
}
|
|
3595
|
+
assertCompanyAccess(req, issue.companyId);
|
|
3596
|
+
if (!(await assertAgentIssueMutationAllowed(req, res, issue)))
|
|
3597
|
+
return;
|
|
3598
|
+
if (!assertStructuredCommentFieldsAllowed(req, res, {
|
|
3599
|
+
presentation: req.body.presentation,
|
|
3600
|
+
metadata: req.body.metadata,
|
|
3601
|
+
}))
|
|
3602
|
+
return;
|
|
3603
|
+
const closedExecutionWorkspace = await getClosedIssueExecutionWorkspace(issue);
|
|
3604
|
+
if (closedExecutionWorkspace) {
|
|
3605
|
+
respondClosedIssueExecutionWorkspace(res, closedExecutionWorkspace);
|
|
3606
|
+
return;
|
|
3607
|
+
}
|
|
3608
|
+
const actor = getActorInfo(req);
|
|
3609
|
+
const reopenRequested = req.body.reopen === true;
|
|
3610
|
+
const resumeRequested = req.body.resume === true;
|
|
3611
|
+
const interruptRequested = req.body.interrupt === true;
|
|
3612
|
+
if (resumeRequested === true && !(await assertExplicitResumeIntentAllowed(req, res, issue)))
|
|
3613
|
+
return;
|
|
3614
|
+
if (resumeRequested !== true && reopenRequested === true && req.actor.type === "agent") {
|
|
3615
|
+
if (!(await assertExplicitResumeIntentAllowed(req, res, issue)))
|
|
3616
|
+
return;
|
|
3617
|
+
}
|
|
3618
|
+
const isClosed = isClosedIssueStatus(issue.status);
|
|
3619
|
+
const isBlocked = issue.status === "blocked";
|
|
3620
|
+
const explicitMoveToTodoRequested = reopenRequested || resumeRequested === true;
|
|
3621
|
+
const effectiveMoveToTodoRequested = explicitMoveToTodoRequested ||
|
|
3622
|
+
shouldImplicitlyMoveCommentedIssueToTodo({
|
|
3623
|
+
issueStatus: issue.status,
|
|
3624
|
+
assigneeAgentId: issue.assigneeAgentId,
|
|
3625
|
+
actorType: actor.actorType,
|
|
3626
|
+
actorId: actor.actorId,
|
|
3627
|
+
});
|
|
3628
|
+
const hasUnresolvedFirstClassBlockers = isBlocked && effectiveMoveToTodoRequested
|
|
3629
|
+
? (await svc.getDependencyReadiness(issue.id)).unresolvedBlockerCount > 0
|
|
3630
|
+
: false;
|
|
3631
|
+
if (resumeRequested === true && isBlocked && hasUnresolvedFirstClassBlockers) {
|
|
3632
|
+
res.status(409).json({ error: "Issue follow-up blocked by unresolved blockers" });
|
|
3633
|
+
return;
|
|
3634
|
+
}
|
|
3635
|
+
let reopened = false;
|
|
3636
|
+
let reopenFromStatus = null;
|
|
3637
|
+
let interruptedRunId = null;
|
|
3638
|
+
let currentIssue = issue;
|
|
3639
|
+
const commentReferenceSummaryBefore = await issueReferencesSvc.listIssueReferenceSummary(issue.id);
|
|
3640
|
+
if (effectiveMoveToTodoRequested && (isClosed || (isBlocked && !hasUnresolvedFirstClassBlockers))) {
|
|
3641
|
+
const reopenedIssue = await svc.update(id, { status: "todo" });
|
|
3642
|
+
if (!reopenedIssue) {
|
|
3643
|
+
res.status(404).json({ error: "Issue not found" });
|
|
3644
|
+
return;
|
|
3645
|
+
}
|
|
3646
|
+
reopened = true;
|
|
3647
|
+
reopenFromStatus = issue.status;
|
|
3648
|
+
currentIssue = reopenedIssue;
|
|
3649
|
+
await logActivity(db, {
|
|
3650
|
+
companyId: currentIssue.companyId,
|
|
3651
|
+
actorType: actor.actorType,
|
|
3652
|
+
actorId: actor.actorId,
|
|
3653
|
+
agentId: actor.agentId,
|
|
3654
|
+
runId: actor.runId,
|
|
3655
|
+
action: "issue.updated",
|
|
3656
|
+
entityType: "issue",
|
|
3657
|
+
entityId: currentIssue.id,
|
|
3658
|
+
details: {
|
|
3659
|
+
status: "todo",
|
|
3660
|
+
reopened: true,
|
|
3661
|
+
reopenedFrom: reopenFromStatus,
|
|
3662
|
+
source: "comment",
|
|
3663
|
+
...(resumeRequested === true ? { resumeIntent: true, followUpRequested: true } : {}),
|
|
3664
|
+
identifier: currentIssue.identifier,
|
|
3665
|
+
},
|
|
3666
|
+
});
|
|
3667
|
+
}
|
|
3668
|
+
if (interruptRequested) {
|
|
3669
|
+
if (req.actor.type !== "board") {
|
|
3670
|
+
res.status(403).json({ error: "Only board users can interrupt active runs from issue comments" });
|
|
3671
|
+
return;
|
|
3672
|
+
}
|
|
3673
|
+
const runToInterrupt = await resolveActiveIssueRun(currentIssue);
|
|
3674
|
+
if (runToInterrupt) {
|
|
3675
|
+
const cancelled = await heartbeat.cancelRun(runToInterrupt.id);
|
|
3676
|
+
if (cancelled) {
|
|
3677
|
+
interruptedRunId = cancelled.id;
|
|
3678
|
+
await logActivity(db, {
|
|
3679
|
+
companyId: cancelled.companyId,
|
|
3680
|
+
actorType: actor.actorType,
|
|
3681
|
+
actorId: actor.actorId,
|
|
3682
|
+
agentId: actor.agentId,
|
|
3683
|
+
runId: actor.runId,
|
|
3684
|
+
action: "heartbeat.cancelled",
|
|
3685
|
+
entityType: "heartbeat_run",
|
|
3686
|
+
entityId: cancelled.id,
|
|
3687
|
+
details: { agentId: cancelled.agentId, source: "issue_comment_interrupt", issueId: currentIssue.id },
|
|
3688
|
+
});
|
|
3689
|
+
}
|
|
3690
|
+
}
|
|
3691
|
+
}
|
|
3692
|
+
const comment = await svc.addComment(id, req.body.body, {
|
|
3693
|
+
agentId: actor.agentId ?? undefined,
|
|
3694
|
+
userId: actor.actorType === "user" ? actor.actorId : undefined,
|
|
3695
|
+
runId: actor.runId,
|
|
3696
|
+
}, {
|
|
3697
|
+
authorType: req.body.authorType ?? (actor.actorType === "agent" ? "agent" : "user"),
|
|
3698
|
+
presentation: req.body.presentation ?? null,
|
|
3699
|
+
metadata: req.body.metadata ?? null,
|
|
3700
|
+
});
|
|
3701
|
+
await issueReferencesSvc.syncComment(comment.id);
|
|
3702
|
+
const commentReferenceSummaryAfter = await issueReferencesSvc.listIssueReferenceSummary(currentIssue.id);
|
|
3703
|
+
const commentReferenceDiff = issueReferencesSvc.diffIssueReferenceSummary(commentReferenceSummaryBefore, commentReferenceSummaryAfter);
|
|
3704
|
+
if (actor.runId) {
|
|
3705
|
+
await heartbeat.reportRunActivity(actor.runId).catch((err) => logger.warn({ err, runId: actor.runId }, "failed to clear detached run warning after issue comment"));
|
|
3706
|
+
}
|
|
3707
|
+
await logActivity(db, {
|
|
3708
|
+
companyId: currentIssue.companyId,
|
|
3709
|
+
actorType: actor.actorType,
|
|
3710
|
+
actorId: actor.actorId,
|
|
3711
|
+
agentId: actor.agentId,
|
|
3712
|
+
runId: actor.runId,
|
|
3713
|
+
action: "issue.comment_added",
|
|
3714
|
+
entityType: "issue",
|
|
3715
|
+
entityId: currentIssue.id,
|
|
3716
|
+
details: {
|
|
3717
|
+
commentId: comment.id,
|
|
3718
|
+
bodySnippet: comment.body.slice(0, 120),
|
|
3719
|
+
identifier: currentIssue.identifier,
|
|
3720
|
+
issueTitle: currentIssue.title,
|
|
3721
|
+
...(resumeRequested === true ? { resumeIntent: true, followUpRequested: true } : {}),
|
|
3722
|
+
...(reopened ? { reopened: true, reopenedFrom: reopenFromStatus, source: "comment" } : {}),
|
|
3723
|
+
...(interruptedRunId ? { interruptedRunId } : {}),
|
|
3724
|
+
...summarizeIssueReferenceActivityDetails({
|
|
3725
|
+
addedReferencedIssues: commentReferenceDiff.addedReferencedIssues.map(summarizeIssueRelationForActivity),
|
|
3726
|
+
removedReferencedIssues: commentReferenceDiff.removedReferencedIssues.map(summarizeIssueRelationForActivity),
|
|
3727
|
+
currentReferencedIssues: commentReferenceDiff.currentReferencedIssues.map(summarizeIssueRelationForActivity),
|
|
3728
|
+
}),
|
|
3729
|
+
},
|
|
3730
|
+
});
|
|
3731
|
+
const expiredInteractions = await issueThreadInteractionService(db).expireRequestConfirmationsSupersededByComment(currentIssue, comment, {
|
|
3732
|
+
agentId: actor.agentId,
|
|
3733
|
+
userId: actor.actorType === "user" ? actor.actorId : null,
|
|
3734
|
+
});
|
|
3735
|
+
await logExpiredRequestConfirmations({
|
|
3736
|
+
issue: currentIssue,
|
|
3737
|
+
interactions: expiredInteractions,
|
|
3738
|
+
actor,
|
|
3739
|
+
source: "issue.comment",
|
|
3740
|
+
});
|
|
3741
|
+
// Merge all wakeups from this comment into one enqueue per agent to avoid duplicate runs.
|
|
3742
|
+
void (async () => {
|
|
3743
|
+
const wakeups = new Map();
|
|
3744
|
+
const assigneeId = currentIssue.assigneeAgentId;
|
|
3745
|
+
const actorIsAgent = actor.actorType === "agent";
|
|
3746
|
+
const selfComment = actorIsAgent && actor.actorId === assigneeId;
|
|
3747
|
+
const skipWake = selfComment || isClosed;
|
|
3748
|
+
if (assigneeId && (reopened || !skipWake)) {
|
|
3749
|
+
if (reopened) {
|
|
3750
|
+
wakeups.set(assigneeId, {
|
|
3751
|
+
source: "automation",
|
|
3752
|
+
triggerDetail: "system",
|
|
3753
|
+
reason: "issue_reopened_via_comment",
|
|
3754
|
+
payload: {
|
|
3755
|
+
issueId: currentIssue.id,
|
|
3756
|
+
commentId: comment.id,
|
|
3757
|
+
reopenedFrom: reopenFromStatus,
|
|
3758
|
+
mutation: "comment",
|
|
3759
|
+
...(resumeRequested === true ? { resumeIntent: true, followUpRequested: true } : {}),
|
|
3760
|
+
...(interruptedRunId ? { interruptedRunId } : {}),
|
|
3761
|
+
},
|
|
3762
|
+
requestedByActorType: actor.actorType,
|
|
3763
|
+
requestedByActorId: actor.actorId,
|
|
3764
|
+
contextSnapshot: {
|
|
3765
|
+
issueId: currentIssue.id,
|
|
3766
|
+
taskId: currentIssue.id,
|
|
3767
|
+
commentId: comment.id,
|
|
3768
|
+
wakeCommentId: comment.id,
|
|
3769
|
+
source: "issue.comment.reopen",
|
|
3770
|
+
wakeReason: "issue_reopened_via_comment",
|
|
3771
|
+
reopenedFrom: reopenFromStatus,
|
|
3772
|
+
...(resumeRequested === true ? { resumeIntent: true, followUpRequested: true } : {}),
|
|
3773
|
+
...(interruptedRunId ? { interruptedRunId } : {}),
|
|
3774
|
+
},
|
|
3775
|
+
});
|
|
3776
|
+
}
|
|
3777
|
+
else {
|
|
3778
|
+
wakeups.set(assigneeId, {
|
|
3779
|
+
source: "automation",
|
|
3780
|
+
triggerDetail: "system",
|
|
3781
|
+
reason: "issue_commented",
|
|
3782
|
+
payload: {
|
|
3783
|
+
issueId: currentIssue.id,
|
|
3784
|
+
commentId: comment.id,
|
|
3785
|
+
mutation: "comment",
|
|
3786
|
+
...(resumeRequested === true ? { resumeIntent: true, followUpRequested: true } : {}),
|
|
3787
|
+
...(interruptedRunId ? { interruptedRunId } : {}),
|
|
3788
|
+
},
|
|
3789
|
+
requestedByActorType: actor.actorType,
|
|
3790
|
+
requestedByActorId: actor.actorId,
|
|
3791
|
+
contextSnapshot: {
|
|
3792
|
+
issueId: currentIssue.id,
|
|
3793
|
+
taskId: currentIssue.id,
|
|
3794
|
+
commentId: comment.id,
|
|
3795
|
+
wakeCommentId: comment.id,
|
|
3796
|
+
source: "issue.comment",
|
|
3797
|
+
wakeReason: "issue_commented",
|
|
3798
|
+
...(resumeRequested === true ? { resumeIntent: true, followUpRequested: true } : {}),
|
|
3799
|
+
...(interruptedRunId ? { interruptedRunId } : {}),
|
|
3800
|
+
},
|
|
3801
|
+
});
|
|
3802
|
+
}
|
|
3803
|
+
}
|
|
3804
|
+
let mentionedIds = [];
|
|
3805
|
+
try {
|
|
3806
|
+
mentionedIds = await svc.findMentionedAgents(issue.companyId, req.body.body);
|
|
3807
|
+
}
|
|
3808
|
+
catch (err) {
|
|
3809
|
+
logger.warn({ err, issueId: id }, "failed to resolve @-mentions");
|
|
3810
|
+
}
|
|
3811
|
+
for (const mentionedId of mentionedIds) {
|
|
3812
|
+
if (wakeups.has(mentionedId))
|
|
3813
|
+
continue;
|
|
3814
|
+
if (actorIsAgent && actor.actorId === mentionedId)
|
|
3815
|
+
continue;
|
|
3816
|
+
wakeups.set(mentionedId, {
|
|
3817
|
+
source: "automation",
|
|
3818
|
+
triggerDetail: "system",
|
|
3819
|
+
reason: "issue_comment_mentioned",
|
|
3820
|
+
payload: { issueId: id, commentId: comment.id },
|
|
3821
|
+
requestedByActorType: actor.actorType,
|
|
3822
|
+
requestedByActorId: actor.actorId,
|
|
3823
|
+
contextSnapshot: {
|
|
3824
|
+
issueId: id,
|
|
3825
|
+
taskId: id,
|
|
3826
|
+
commentId: comment.id,
|
|
3827
|
+
wakeCommentId: comment.id,
|
|
3828
|
+
wakeReason: "issue_comment_mentioned",
|
|
3829
|
+
source: "comment.mention",
|
|
3830
|
+
},
|
|
3831
|
+
});
|
|
3832
|
+
}
|
|
3833
|
+
for (const [agentId, wakeup] of wakeups.entries()) {
|
|
3834
|
+
heartbeat
|
|
3835
|
+
.wakeup(agentId, wakeup)
|
|
3836
|
+
.catch((err) => logger.warn({ err, issueId: currentIssue.id, agentId }, "failed to wake agent on issue comment"));
|
|
3837
|
+
}
|
|
3838
|
+
})();
|
|
3839
|
+
res.status(201).json(comment);
|
|
3840
|
+
});
|
|
3841
|
+
router.post("/issues/:id/feedback-votes", validate(upsertIssueFeedbackVoteSchema), async (req, res) => {
|
|
3842
|
+
const id = req.params.id;
|
|
3843
|
+
const issue = await svc.getById(id);
|
|
3844
|
+
if (!issue) {
|
|
3845
|
+
res.status(404).json({ error: "Issue not found" });
|
|
3846
|
+
return;
|
|
3847
|
+
}
|
|
3848
|
+
assertCompanyAccess(req, issue.companyId);
|
|
3849
|
+
if (req.actor.type !== "board") {
|
|
3850
|
+
res.status(403).json({ error: "Only board users can vote on AI feedback" });
|
|
3851
|
+
return;
|
|
3852
|
+
}
|
|
3853
|
+
const actor = getActorInfo(req);
|
|
3854
|
+
const result = await feedback.saveIssueVote({
|
|
3855
|
+
issueId: id,
|
|
3856
|
+
targetType: req.body.targetType,
|
|
3857
|
+
targetId: req.body.targetId,
|
|
3858
|
+
vote: req.body.vote,
|
|
3859
|
+
reason: req.body.reason,
|
|
3860
|
+
authorUserId: req.actor.userId ?? "local-board",
|
|
3861
|
+
allowSharing: req.body.allowSharing === true,
|
|
3862
|
+
});
|
|
3863
|
+
await logActivity(db, {
|
|
3864
|
+
companyId: issue.companyId,
|
|
3865
|
+
actorType: actor.actorType,
|
|
3866
|
+
actorId: actor.actorId,
|
|
3867
|
+
agentId: actor.agentId,
|
|
3868
|
+
runId: actor.runId,
|
|
3869
|
+
action: "issue.feedback_vote_saved",
|
|
3870
|
+
entityType: "issue",
|
|
3871
|
+
entityId: issue.id,
|
|
3872
|
+
details: {
|
|
3873
|
+
identifier: issue.identifier,
|
|
3874
|
+
targetType: result.vote.targetType,
|
|
3875
|
+
targetId: result.vote.targetId,
|
|
3876
|
+
vote: result.vote.vote,
|
|
3877
|
+
hasReason: Boolean(result.vote.reason),
|
|
3878
|
+
sharingEnabled: result.sharingEnabled,
|
|
3879
|
+
},
|
|
3880
|
+
});
|
|
3881
|
+
if (result.consentEnabledNow) {
|
|
3882
|
+
await logActivity(db, {
|
|
3883
|
+
companyId: issue.companyId,
|
|
3884
|
+
actorType: actor.actorType,
|
|
3885
|
+
actorId: actor.actorId,
|
|
3886
|
+
agentId: actor.agentId,
|
|
3887
|
+
runId: actor.runId,
|
|
3888
|
+
action: "company.feedback_data_sharing_updated",
|
|
3889
|
+
entityType: "company",
|
|
3890
|
+
entityId: issue.companyId,
|
|
3891
|
+
details: {
|
|
3892
|
+
feedbackDataSharingEnabled: true,
|
|
3893
|
+
source: "issue_feedback_vote",
|
|
3894
|
+
},
|
|
3895
|
+
});
|
|
3896
|
+
}
|
|
3897
|
+
if (result.persistedSharingPreference) {
|
|
3898
|
+
const settings = await instanceSettings.get();
|
|
3899
|
+
const companyIds = await instanceSettings.listCompanyIds();
|
|
3900
|
+
await Promise.all(companyIds.map((companyId) => logActivity(db, {
|
|
3901
|
+
companyId,
|
|
3902
|
+
actorType: actor.actorType,
|
|
3903
|
+
actorId: actor.actorId,
|
|
3904
|
+
agentId: actor.agentId,
|
|
3905
|
+
runId: actor.runId,
|
|
3906
|
+
action: "instance.settings.general_updated",
|
|
3907
|
+
entityType: "instance_settings",
|
|
3908
|
+
entityId: settings.id,
|
|
3909
|
+
details: {
|
|
3910
|
+
general: settings.general,
|
|
3911
|
+
changedKeys: ["feedbackDataSharingPreference"],
|
|
3912
|
+
source: "issue_feedback_vote",
|
|
3913
|
+
},
|
|
3914
|
+
})));
|
|
3915
|
+
}
|
|
3916
|
+
if (result.sharingEnabled && result.traceId && feedbackExportService) {
|
|
3917
|
+
try {
|
|
3918
|
+
await feedbackExportService.flushPendingFeedbackTraces({
|
|
3919
|
+
companyId: issue.companyId,
|
|
3920
|
+
traceId: result.traceId,
|
|
3921
|
+
limit: 1,
|
|
3922
|
+
});
|
|
3923
|
+
}
|
|
3924
|
+
catch (err) {
|
|
3925
|
+
logger.warn({ err, issueId: issue.id, traceId: result.traceId }, "failed to flush shared feedback trace immediately");
|
|
3926
|
+
}
|
|
3927
|
+
}
|
|
3928
|
+
res.status(201).json(result.vote);
|
|
3929
|
+
});
|
|
3930
|
+
router.get("/issues/:id/attachments", async (req, res) => {
|
|
3931
|
+
const issueId = req.params.id;
|
|
3932
|
+
const issue = await svc.getById(issueId);
|
|
3933
|
+
if (!issue) {
|
|
3934
|
+
res.status(404).json({ error: "Issue not found" });
|
|
3935
|
+
return;
|
|
3936
|
+
}
|
|
3937
|
+
assertCompanyAccess(req, issue.companyId);
|
|
3938
|
+
const attachments = await svc.listAttachments(issueId);
|
|
3939
|
+
res.json(attachments.map(withContentPath));
|
|
3940
|
+
});
|
|
3941
|
+
router.post("/companies/:companyId/issues/:issueId/attachments", async (req, res) => {
|
|
3942
|
+
const companyId = req.params.companyId;
|
|
3943
|
+
const issueId = req.params.issueId;
|
|
3944
|
+
assertCompanyAccess(req, companyId);
|
|
3945
|
+
const issue = await svc.getById(issueId);
|
|
3946
|
+
if (!issue) {
|
|
3947
|
+
res.status(404).json({ error: "Issue not found" });
|
|
3948
|
+
return;
|
|
3949
|
+
}
|
|
3950
|
+
if (issue.companyId !== companyId) {
|
|
3951
|
+
res.status(422).json({ error: "Issue does not belong to company" });
|
|
3952
|
+
return;
|
|
3953
|
+
}
|
|
3954
|
+
if (!(await assertAgentIssueMutationAllowed(req, res, issue)))
|
|
3955
|
+
return;
|
|
3956
|
+
const company = await companiesSvc.getById(companyId);
|
|
3957
|
+
const attachmentMaxBytes = normalizeIssueAttachmentMaxBytes(company?.attachmentMaxBytes);
|
|
3958
|
+
try {
|
|
3959
|
+
await runSingleFileUpload(req, res, attachmentMaxBytes);
|
|
3960
|
+
}
|
|
3961
|
+
catch (err) {
|
|
3962
|
+
if (err instanceof multer.MulterError) {
|
|
3963
|
+
if (err.code === "LIMIT_FILE_SIZE") {
|
|
3964
|
+
res.status(422).json({ error: `Attachment exceeds ${attachmentMaxBytes} bytes` });
|
|
3965
|
+
return;
|
|
3966
|
+
}
|
|
3967
|
+
res.status(400).json({ error: err.message });
|
|
3968
|
+
return;
|
|
3969
|
+
}
|
|
3970
|
+
throw err;
|
|
3971
|
+
}
|
|
3972
|
+
const file = req.file;
|
|
3973
|
+
if (!file) {
|
|
3974
|
+
res.status(400).json({ error: "Missing file field 'file'" });
|
|
3975
|
+
return;
|
|
3976
|
+
}
|
|
3977
|
+
const contentType = normalizeContentType(file.mimetype);
|
|
3978
|
+
if (file.buffer.length <= 0) {
|
|
3979
|
+
res.status(422).json({ error: "Attachment is empty" });
|
|
3980
|
+
return;
|
|
3981
|
+
}
|
|
3982
|
+
const parsedMeta = createIssueAttachmentMetadataSchema.safeParse(req.body ?? {});
|
|
3983
|
+
if (!parsedMeta.success) {
|
|
3984
|
+
res.status(400).json({ error: "Invalid attachment metadata", details: parsedMeta.error.issues });
|
|
3985
|
+
return;
|
|
3986
|
+
}
|
|
3987
|
+
const actor = getActorInfo(req);
|
|
3988
|
+
const stored = await storage.putFile({
|
|
3989
|
+
companyId,
|
|
3990
|
+
namespace: `issues/${issueId}`,
|
|
3991
|
+
originalFilename: file.originalname || null,
|
|
3992
|
+
contentType,
|
|
3993
|
+
body: file.buffer,
|
|
3994
|
+
});
|
|
3995
|
+
const attachment = await svc.createAttachment({
|
|
3996
|
+
issueId,
|
|
3997
|
+
issueCommentId: parsedMeta.data.issueCommentId ?? null,
|
|
3998
|
+
provider: stored.provider,
|
|
3999
|
+
objectKey: stored.objectKey,
|
|
4000
|
+
contentType: stored.contentType,
|
|
4001
|
+
byteSize: stored.byteSize,
|
|
4002
|
+
sha256: stored.sha256,
|
|
4003
|
+
originalFilename: stored.originalFilename,
|
|
4004
|
+
createdByAgentId: actor.agentId,
|
|
4005
|
+
createdByUserId: actor.actorType === "user" ? actor.actorId : null,
|
|
4006
|
+
});
|
|
4007
|
+
await logActivity(db, {
|
|
4008
|
+
companyId,
|
|
4009
|
+
actorType: actor.actorType,
|
|
4010
|
+
actorId: actor.actorId,
|
|
4011
|
+
agentId: actor.agentId,
|
|
4012
|
+
runId: actor.runId,
|
|
4013
|
+
action: "issue.attachment_added",
|
|
4014
|
+
entityType: "issue",
|
|
4015
|
+
entityId: issueId,
|
|
4016
|
+
details: {
|
|
4017
|
+
attachmentId: attachment.id,
|
|
4018
|
+
originalFilename: attachment.originalFilename,
|
|
4019
|
+
contentType: attachment.contentType,
|
|
4020
|
+
byteSize: attachment.byteSize,
|
|
4021
|
+
},
|
|
4022
|
+
});
|
|
4023
|
+
res.status(201).json(withContentPath(attachment));
|
|
4024
|
+
});
|
|
4025
|
+
router.get("/attachments/:attachmentId/content", async (req, res, next) => {
|
|
4026
|
+
const attachmentId = req.params.attachmentId;
|
|
4027
|
+
const attachment = await svc.getAttachmentById(attachmentId);
|
|
4028
|
+
if (!attachment) {
|
|
4029
|
+
res.status(404).json({ error: "Attachment not found" });
|
|
4030
|
+
return;
|
|
4031
|
+
}
|
|
4032
|
+
assertCompanyAccess(req, attachment.companyId);
|
|
4033
|
+
const object = await storage.getObject(attachment.companyId, attachment.objectKey);
|
|
4034
|
+
const responseContentType = normalizeContentType(attachment.contentType || object.contentType);
|
|
4035
|
+
res.setHeader("Content-Type", responseContentType);
|
|
4036
|
+
res.setHeader("Content-Length", String(attachment.byteSize || object.contentLength || 0));
|
|
4037
|
+
res.setHeader("Cache-Control", "private, max-age=60");
|
|
4038
|
+
res.setHeader("X-Content-Type-Options", "nosniff");
|
|
4039
|
+
if (responseContentType === SVG_CONTENT_TYPE) {
|
|
4040
|
+
res.setHeader("Content-Security-Policy", "sandbox; default-src 'none'; img-src 'self' data:; style-src 'unsafe-inline'");
|
|
4041
|
+
}
|
|
4042
|
+
const filename = attachment.originalFilename ?? "attachment";
|
|
4043
|
+
const disposition = isInlineAttachmentContentType(responseContentType) ? "inline" : "attachment";
|
|
4044
|
+
res.setHeader("Content-Disposition", `${disposition}; filename=\"${filename.replaceAll("\"", "")}\"`);
|
|
4045
|
+
object.stream.on("error", (err) => {
|
|
4046
|
+
next(err);
|
|
4047
|
+
});
|
|
4048
|
+
object.stream.pipe(res);
|
|
4049
|
+
});
|
|
4050
|
+
router.delete("/attachments/:attachmentId", async (req, res) => {
|
|
4051
|
+
const attachmentId = req.params.attachmentId;
|
|
4052
|
+
const attachment = await svc.getAttachmentById(attachmentId);
|
|
4053
|
+
if (!attachment) {
|
|
4054
|
+
res.status(404).json({ error: "Attachment not found" });
|
|
4055
|
+
return;
|
|
4056
|
+
}
|
|
4057
|
+
assertCompanyAccess(req, attachment.companyId);
|
|
4058
|
+
const issue = await svc.getById(attachment.issueId);
|
|
4059
|
+
if (!issue) {
|
|
4060
|
+
res.status(404).json({ error: "Issue not found" });
|
|
4061
|
+
return;
|
|
4062
|
+
}
|
|
4063
|
+
if (!(await assertAgentIssueMutationAllowed(req, res, issue)))
|
|
4064
|
+
return;
|
|
4065
|
+
try {
|
|
4066
|
+
await storage.deleteObject(attachment.companyId, attachment.objectKey);
|
|
4067
|
+
}
|
|
4068
|
+
catch (err) {
|
|
4069
|
+
logger.warn({ err, attachmentId }, "storage delete failed while removing attachment");
|
|
4070
|
+
}
|
|
4071
|
+
const removed = await svc.removeAttachment(attachmentId);
|
|
4072
|
+
if (!removed) {
|
|
4073
|
+
res.status(404).json({ error: "Attachment not found" });
|
|
4074
|
+
return;
|
|
4075
|
+
}
|
|
4076
|
+
const actor = getActorInfo(req);
|
|
4077
|
+
await logActivity(db, {
|
|
4078
|
+
companyId: removed.companyId,
|
|
4079
|
+
actorType: actor.actorType,
|
|
4080
|
+
actorId: actor.actorId,
|
|
4081
|
+
agentId: actor.agentId,
|
|
4082
|
+
runId: actor.runId,
|
|
4083
|
+
action: "issue.attachment_removed",
|
|
4084
|
+
entityType: "issue",
|
|
4085
|
+
entityId: removed.issueId,
|
|
4086
|
+
details: {
|
|
4087
|
+
attachmentId: removed.id,
|
|
4088
|
+
},
|
|
4089
|
+
});
|
|
4090
|
+
res.json({ ok: true });
|
|
4091
|
+
});
|
|
4092
|
+
return router;
|
|
4093
|
+
}
|
|
4094
|
+
//# sourceMappingURL=issues.js.map
|