@desplega.ai/agent-swarm 2.9.1 → 2.10.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/dist/acp-adapter-bht22g3k.js +16 -0
- package/dist/{acp-targets-ny75x1qy.js → acp-targets-arrwv4f0.js} +6 -6
- package/dist/{actions-b9qgrmeq.js → actions-y0d2n1c2.js} +49 -28
- package/dist/{agent-fs-provision-b5dhdsbd.js → agent-fs-provision-tpj7sktd.js} +4 -4
- package/dist/{amp-adapter-vtax2c9s.js → amp-adapter-vmmnmw8d.js} +1 -1
- package/dist/{anthropic-messages-r5xf5hqw.js → anthropic-messages-zdca3gv1.js} +13 -13
- package/dist/{app-g2z15hax.js → app-wb7w45dq.js} +3 -3
- package/dist/{approval-notifications-yt13wp8r.js → approval-notifications-7mqr6vbd.js} +5 -5
- package/dist/{assistant-2cgfxsgk.js → assistant-gf60454p.js} +19 -19
- package/dist/{boot-args-schema-3gwy0f60.js → boot-args-schema-qxmd59sr.js} +1 -1
- package/dist/{boot-reembed-mywmyp4s.js → boot-reembed-5tmeskj2.js} +1 -1
- package/dist/{boot-reembed-92g7s5zp.js → boot-reembed-wb44vc3s.js} +1 -1
- package/dist/boot-scrub-sweep-25bxhnw4.js +9 -0
- package/dist/{boot-seeds-ce7rvgq1.js → boot-seeds-nj9za0vk.js} +4 -4
- package/dist/{claude-adapter-3m4q7735.js → claude-adapter-d3krpdyb.js} +5 -5
- package/dist/{claude-managed-setup-c217draw.js → claude-managed-setup-7y4pwd81.js} +1 -1
- package/dist/{claude-sdk-session-7fbqm51z.js → claude-sdk-session-d138zy0e.js} +5 -5
- package/dist/{cli-tvc4jag9.js → cli-01k6wpr9.js} +3 -3
- package/dist/{cli-2xs8tsf7.js → cli-124ntmf0.js} +42 -36
- package/dist/{cli-jm0hvmz2.js → cli-2rnd5j3t.js} +1 -1
- package/dist/{cli-32djehja.js → cli-2spnz7ye.js} +8 -8
- package/dist/{cli-2dq9yv8p.js → cli-2v2zdm0a.js} +1 -1
- package/dist/{cli-fkef327x.js → cli-3caf7pmg.js} +2 -2
- package/dist/{cli-mw620q3n.js → cli-3et6fmfe.js} +1 -1
- package/dist/{cli-h9yqfzx9.js → cli-3f8zbtqa.js} +3 -3
- package/dist/{cli-mhapr559.js → cli-43evxwj4.js} +1 -1
- package/dist/{cli-pyjn0qhk.js → cli-539h29es.js} +138 -21
- package/dist/{cli-bnqncekd.js → cli-5qhfv9rw.js} +2 -2
- package/dist/{cli-p4kckx1z.js → cli-6037prsx.js} +6 -6
- package/dist/{cli-zr6qy15y.js → cli-6cwr32fe.js} +17 -17
- package/dist/{cli-1jykg0py.js → cli-7r162fxe.js} +22 -15
- package/dist/{cli-sn650d7x.js → cli-8st34zhr.js} +20 -10
- package/dist/{cli-rq5rpv6k.js → cli-91pkxres.js} +1 -1
- package/dist/{cli-m7zvgt57.js → cli-9fjr27ez.js} +10 -10
- package/dist/{cli-f8x9drqr.js → cli-aw83sr40.js} +19 -5
- package/dist/{cli-jkw6ptfw.js → cli-cc93xzes.js} +5 -5
- package/dist/{cli-gfy38pvt.js → cli-fcfbct2j.js} +5 -5
- package/dist/{cli-nafvvsp8.js → cli-fq2rr3jb.js} +5 -5
- package/dist/{boot-scrub-sweep-7dkdzqxx.js → cli-had1p04a.js} +8 -9
- package/dist/{cli-bg63qmsx.js → cli-j6te8keb.js} +4 -4
- package/dist/{cli-br0924pw.js → cli-jrbq4djp.js} +1 -1
- package/dist/{cli-kxx4k2jw.js → cli-k3q2va86.js} +2 -2
- package/dist/{cli-jaw5v1sy.js → cli-k5yewqgd.js} +3 -3
- package/dist/cli-kbtzfrxj.js +404 -0
- package/dist/{cli-td9tb872.js → cli-m9cvf7vs.js} +7 -7
- package/dist/{cli-f3jyzq4g.js → cli-md50mj0r.js} +2 -2
- package/dist/{cli-xag7btpe.js → cli-mk7c5ac4.js} +1 -1
- package/dist/cli-mys27d03.js +321 -0
- package/dist/{cli-nbt14he0.js → cli-nstkanmx.js} +5 -5
- package/dist/{cli-wn13hhdt.js → cli-nv4xsvmk.js} +4 -4
- package/dist/{cli-vyff45ve.js → cli-p0c3vtch.js} +2 -2
- package/dist/{cli-2czxfnvj.js → cli-p0n7b5rz.js} +662 -93
- package/dist/{cli-j7svy295.js → cli-q5srsxq2.js} +12 -12
- package/dist/{cli-vt89089n.js → cli-qrta34nb.js} +4 -4
- package/dist/{cli-ysvspf5e.js → cli-qx4f057j.js} +2 -2
- package/dist/{cli-zh0e5x7p.js → cli-s1khw52h.js} +11 -11
- package/dist/{cli-mkwkwq81.js → cli-s1zqk1aj.js} +18 -11
- package/dist/{cli-f9gz2vyj.js → cli-sb4426be.js} +7 -7
- package/dist/{cli-dgs10ttj.js → cli-th1dkc2v.js} +1 -1
- package/dist/{cli-3j873zxq.js → cli-tr27kwyg.js} +2 -2
- package/dist/{cli-6945ywhr.js → cli-tvgqesec.js} +6 -4
- package/dist/{cli-fjggej24.js → cli-v46zsvqk.js} +1 -1
- package/dist/{cli-67mwzr35.js → cli-v8z0yga9.js} +4 -4
- package/dist/{cli-pb2ay3sh.js → cli-vfqvrd82.js} +5 -5
- package/dist/{cli-fh97xn30.js → cli-vq2eg24x.js} +2 -2
- package/dist/{cli-v57d7fmm.js → cli-vsw91x06.js} +23 -22
- package/dist/{cli-2yjj3e31.js → cli-w1q68d8x.js} +9 -7
- package/dist/{cli-y2ewxhth.js → cli-wafmk3fn.js} +10 -10
- package/dist/{cli-ctx0b85j.js → cli-wwp1bd3n.js} +257 -101
- package/dist/{cli-bkjdknnp.js → cli-y4ccxtz5.js} +37 -5
- package/dist/{cli-w4n323t3.js → cli-y8p78ekx.js} +7 -7
- package/dist/{cli-8zh9nrew.js → cli-z0m452jr.js} +1 -1
- package/dist/{cli-mjw0yf82.js → cli-zeh2mhkg.js} +1 -1
- package/dist/{cli-jwampxxq.js → cli-zk7v5s89.js} +2 -2
- package/dist/cli.js +16 -16
- package/dist/{cloudflare-workers-ai-system-one-9y1zx3pt.js → cloudflare-workers-ai-system-one-4aysy6rh.js} +2 -2
- package/dist/{codex-adapter-n656pvb8.js → codex-adapter-exfdbj73.js} +4 -4
- package/dist/{codex-session-runner-p0fbv5y9.js → codex-session-runner-xhznc4g3.js} +4 -4
- package/dist/{commands-gwea8z5p.js → commands-d8g349v4.js} +3 -3
- package/dist/{controller-t67c3grh.js → controller-mwgdmb8y.js} +3 -3
- package/dist/{controllers-connect-ks155r0h.js → controllers-connect-5v7qx04j.js} +19 -19
- package/dist/core-sxy4epp2.js +38 -0
- package/dist/{cursor-adapter-ygwrtmkv.js → cursor-adapter-p2q5h35d.js} +1 -1
- package/dist/{db-rb2xqdb1.js → db-qpganbeb.js} +3 -3
- package/dist/{db-kpmx06s9.js → db-wcw0b2j8.js} +2 -2
- package/dist/{dispatcher-31sm0ej2.js → dispatcher-8d8s49yz.js} +17 -17
- package/dist/{dsh-adapter-qyxh0w31.js → dsh-adapter-me0twn13.js} +1 -1
- package/dist/{easter-egg-3d-00wjscn6.js → easter-egg-3d-wv7w5ty6.js} +1 -1
- package/dist/{embedding-space-qhw4g68n.js → embedding-space-e48xchqa.js} +6 -6
- package/dist/{embeddings-zdv9ke6x.js → embeddings-tgq2afbq.js} +1 -1
- package/dist/{execute-zna8wwr7.js → execute-8rhwrk7f.js} +1 -1
- package/dist/{external-channel-1ac6t56s.js → external-channel-8bt3j2pm.js} +2 -2
- package/dist/{fx-adapter-sk7n0fzc.js → fx-adapter-adtdb3jb.js} +8 -8
- package/dist/{grok-adapter-sjbcm5ew.js → grok-adapter-accnn9km.js} +8 -8
- package/dist/handlers-1x77561e.js +35 -0
- package/dist/{heartbeat-2f6z4kdx.js → heartbeat-x0056ra5.js} +20 -20
- package/dist/{hook-w1skzaqc.js → hook-a7vmn2st.js} +4 -4
- package/dist/{hook-8y0gvtp1.js → hook-mrd2ayxv.js} +5 -5
- package/dist/{http-wghxvpef.js → http-ym9c5svp.js} +676 -273
- package/dist/{index-s71ez27v.js → index-01ns1pkw.js} +1 -1
- package/dist/index-48qzcqzj.js +35 -0
- package/dist/{index-9zkchs9t.js → index-ny60jcat.js} +186 -14
- package/dist/{index-rv89fvzf.js → index-p46tvwtx.js} +21 -21
- package/dist/index-rkvaambe.js +36 -0
- package/dist/{index-8zn8nxn5.js → index-x6azjwm8.js} +1 -1
- package/dist/{index-25pvya7q.js → index-xj1mq27m.js} +17 -17
- package/dist/k8s-m56sw868.js +217 -0
- package/dist/{keepalive-sh02349h.js → keepalive-7yxg8z4c.js} +3 -3
- package/dist/lead-enzn86bz.js +74 -0
- package/dist/{maintenance-yj0dcjja.js → maintenance-6tefxmk1.js} +1 -1
- package/dist/{oauth-refresh-sweep-d9xedk66.js → oauth-refresh-sweep-70cavc3a.js} +2 -2
- package/dist/{onboard-dpgjn03r.js → onboard-fja65z08.js} +5 -5
- package/dist/{openai-decisions-q3hh60wr.js → openai-decisions-ytp6w6xh.js} +1 -1
- package/dist/{opencode-adapter-2d31cpjc.js → opencode-adapter-hakkm7yh.js} +5 -5
- package/dist/{otel-impl-1skarpfq.js → otel-impl-7zhnt6gj.js} +1 -1
- package/dist/{pending-bfmxtx0g.js → pending-h01yzpx4.js} +18 -18
- package/dist/{pi-mono-adapter-gvppnasy.js → pi-mono-adapter-f52hz743.js} +6 -6
- package/dist/{pricing-refresh-c6b325mk.js → pricing-refresh-fzxvk2zf.js} +2 -2
- package/dist/{rbac-roles-h80qbdbs.js → rbac-roles-9v6vhgbs.js} +3 -3
- package/dist/{rbac-roles-zfcx68tx.js → rbac-roles-hfgh8sba.js} +2 -2
- package/dist/{render-v2-nx20t3rb.js → render-v2-1rgspxzf.js} +3 -3
- package/dist/{resume-5ep8agan.js → resume-tqy61x24.js} +7 -7
- package/dist/{runtime-r3pj4mce.js → runtime-exkxyx5f.js} +1 -1
- package/dist/{session-access-n7p3m15b.js → session-access-3act7vt4.js} +4 -4
- package/dist/{session-source-backfill-v8mt0zwn.js → session-source-backfill-82qe7fqq.js} +2 -2
- package/dist/{setup-z1psaqhe.js → setup-ry1vfdef.js} +1 -1
- package/dist/thread-buffer-3x93yexa.js +38 -0
- package/dist/{typesafe-system-one-f2en2knd.js → typesafe-system-one-vcfj2ak8.js} +2 -2
- package/dist/user-merge-jobs-bx6bf7db.js +22 -0
- package/dist/{virtual-modules-rrbjdpxn.js → virtual-modules-s0rjzcqq.js} +3 -3
- package/dist/{work-objects-4aghh73z.js → work-objects-z2e5tv03.js} +20 -20
- package/dist/{worker-follow-up-166zmex1.js → worker-follow-up-y3xeg89w.js} +17 -17
- package/dist/worker-zfcv2wbf.js +74 -0
- package/openapi.json +1630 -388
- package/package.json +3 -3
- package/src/be/boot-seeds.ts +7 -1
- package/src/be/db/model-groups.ts +238 -0
- package/src/be/db/model-profiles.ts +26 -8
- package/src/be/db/session-costs.ts +8 -2
- package/src/be/db/tasks/read.ts +3 -2
- package/src/be/db/tasks/write.ts +2 -1
- package/src/be/db/user-references.ts +75 -0
- package/src/be/db/users/references.ts +185 -0
- package/src/be/db-client.ts +70 -19
- package/src/be/db.ts +32 -57
- package/src/be/key-window-usage.ts +1 -0
- package/src/be/memory/demotion-evidence.ts +34 -0
- package/src/be/memory/reranker.ts +34 -12
- package/src/be/memory/review-recall-filter.ts +83 -0
- package/src/be/memory/search-candidates.ts +19 -6
- package/src/be/memory/types.ts +11 -0
- package/src/be/migrations/312_task_ui_action_runs_repeatable.sql +6 -0
- package/src/be/migrations/314_model_groups.sql +85 -0
- package/src/be/migrations/318_superseded_workflow_cut_backfill.sql +22 -0
- package/src/be/migrations/319_user_fk_indexes.sql +153 -0
- package/src/be/migrations/320_session_costs_kind.sql +4 -0
- package/src/be/migrations/321_user_merge_jobs.sql +52 -0
- package/src/be/pricing-normalize.ts +2 -0
- package/src/be/rbac-roles.ts +6 -4
- package/src/be/runtime-pools/db.ts +20 -5
- package/src/be/runtime-pools/supervisor.ts +15 -1
- package/src/be/scripts/db.ts +11 -0
- package/src/be/scripts/typecheck.ts +2 -0
- package/src/be/seed-model-groups.ts +86 -0
- package/src/be/seed-model-profiles.ts +20 -13
- package/src/be/seed-scripts/catalog/dreaming-gather.ts +165 -1
- package/src/be/swarm-config-guard.ts +34 -0
- package/src/be/task-ui-spec.ts +102 -1
- package/src/be/user-merge-jobs.ts +564 -0
- package/src/be/users.ts +41 -23
- package/src/commands/onboard/agent-fs-version.ts +1 -1
- package/src/commands/onboard/compose-generator.ts +1 -1
- package/src/commands/onboard/env-generator.ts +1 -1
- package/src/commands/provider-credentials.ts +1 -1
- package/src/extensions/contract-types.generated.ts +1 -1
- package/src/extensions/contract.ts +15 -0
- package/src/extensions/dispatcher.ts +14 -4
- package/src/github/handlers.ts +57 -0
- package/src/github/types.ts +4 -0
- package/src/http/all-routes.ts +2 -0
- package/src/http/approval-requests.ts +5 -1
- package/src/http/auth.ts +3 -1
- package/src/http/config.ts +34 -1
- package/src/http/index.ts +13 -0
- package/src/http/memory.ts +19 -6
- package/src/http/model-groups.ts +277 -0
- package/src/http/model-profiles.ts +30 -13
- package/src/http/tasks.ts +41 -6
- package/src/http/tool-hooks.ts +140 -0
- package/src/http/users.ts +142 -19
- package/src/http/workflows.ts +19 -1
- package/src/integrations/chat-sdk/inbound.ts +8 -2
- package/src/integrations/chat-sdk/limits.ts +8 -3
- package/src/providers/acp-targets.ts +2 -2
- package/src/providers/amp-adapter.ts +1 -1
- package/src/providers/pricing-sources.md +9 -0
- package/src/rbac/legacy-policy.ts +1 -0
- package/src/rbac/permissions.ts +5 -0
- package/src/runtime-providers/index.ts +7 -5
- package/src/runtime-providers/k8s.ts +250 -0
- package/src/scripts-runtime/types/stdlib.d.ts +2 -0
- package/src/scripts-runtime/types/swarm-extension.d.ts +16 -1
- package/src/scripts-runtime/types/swarm-sdk.d.ts +2 -0
- package/src/slack/actions.ts +33 -10
- package/src/slack/blocks.ts +23 -2
- package/src/slack/render-v2.ts +47 -0
- package/src/tests/acp-adapter.test.ts +26 -0
- package/src/tests/chat-sdk-relay.test.ts +21 -1
- package/src/tests/check-pr-body.test.ts +43 -0
- package/src/tests/credential-check.test.ts +14 -6
- package/src/tests/db-client.test.ts +146 -0
- package/src/tests/deploy-guard.test.ts +7 -7
- package/src/tests/deploy-select.test.ts +83 -0
- package/src/tests/dreaming-gather-corrections.test.ts +467 -0
- package/src/tests/event-loop-lag.test.ts +9 -7
- package/src/tests/fixtures/extensions/native-tool-recorder/hooks.ts +26 -0
- package/src/tests/fixtures/extensions/native-tool-recorder/manifest.json +10 -0
- package/src/tests/fixtures/onboard/content.compose.yml.txt +1 -1
- package/src/tests/fixtures/onboard/content.env.txt +1 -1
- package/src/tests/fixtures/onboard/dev.compose.yml.txt +1 -1
- package/src/tests/fixtures/onboard/dev.env.txt +1 -1
- package/src/tests/fixtures/onboard/full-all.compose.yml.txt +1 -1
- package/src/tests/fixtures/onboard/full-all.env.txt +1 -1
- package/src/tests/fixtures/onboard/full.compose.yml.txt +1 -1
- package/src/tests/fixtures/onboard/full.env.txt +1 -1
- package/src/tests/fixtures/onboard/research.compose.yml.txt +1 -1
- package/src/tests/fixtures/onboard/research.env.txt +1 -1
- package/src/tests/fixtures/onboard/solo.compose.yml.txt +1 -1
- package/src/tests/fixtures/onboard/solo.env.txt +1 -1
- package/src/tests/github-event-filter.test.ts +8 -0
- package/src/tests/github-handlers-inline-comments.test.ts +2 -0
- package/src/tests/github-handlers-reactions.test.ts +4 -0
- package/src/tests/github-handlers.test.ts +3 -0
- package/src/tests/github-sender-trust.test.ts +223 -0
- package/src/tests/http-users.test.ts +142 -41
- package/src/tests/k8s-pool-smoke.test.ts +190 -0
- package/src/tests/key-window-usage.test.ts +15 -0
- package/src/tests/memory-rater-store.test.ts +35 -1
- package/src/tests/memory-reranker.test.ts +39 -4
- package/src/tests/memory-review-recall-filter.test.ts +205 -0
- package/src/tests/migration-318-superseded-workflow-cut-backfill.test.ts +74 -0
- package/src/tests/model-groups-api.test.ts +415 -0
- package/src/tests/model-profiles-api.test.ts +1 -0
- package/src/tests/operator-granted-credentials.test.ts +7 -2
- package/src/tests/operator-granted-role-wire.test.ts +2 -1
- package/src/tests/rbac-engine.test.ts +1 -0
- package/src/tests/runtime-k8s-pools.test.ts +142 -0
- package/src/tests/runtime-pools-db.test.ts +42 -2
- package/src/tests/runtime-pools-http.test.ts +47 -2
- package/src/tests/runtime-provider-registration.test.ts +5 -14
- package/src/tests/runtime-providers-k8s.test.ts +303 -0
- package/src/tests/script-connections.test.ts +13 -1
- package/src/tests/short-id.test.ts +23 -0
- package/src/tests/slack-blocks.test.ts +69 -0
- package/src/tests/slack-render-v2.test.ts +54 -0
- package/src/tests/spec-base-url.test.ts +13 -1
- package/src/tests/system-one-decide-session-cost.test.ts +196 -0
- package/src/tests/task-ui-action-route.test.ts +59 -1
- package/src/tests/task-ui-script-actions.test.ts +517 -0
- package/src/tests/tool-hooks-http.test.ts +187 -0
- package/src/tests/ui-spec-script-actions-config.test.ts +196 -0
- package/src/tests/user-delete-perf.test.ts +321 -0
- package/src/tests/user-merge-jobs.test.ts +680 -0
- package/src/tests/vcs-provider.test.ts +25 -5
- package/src/tests/vendored-openapi.test.ts +13 -1
- package/src/tests/workflow-agent-task-retry.test.ts +62 -0
- package/src/tests/workflow-foreach-supersede-retry.test.ts +10 -0
- package/src/tests/workflow-http-v2.test.ts +27 -0
- package/src/tests/workflow-replay.test.ts +10 -1
- package/src/tests/workflow-triggers-v2.test.ts +128 -0
- package/src/tests/workflow-wait-event.test.ts +109 -1
- package/src/tools/memory-search.ts +14 -3
- package/src/tools/store-progress.ts +26 -26
- package/src/tools/swarm-config/delete-config.ts +12 -1
- package/src/tools/swarm-config/set-config.ts +8 -0
- package/src/tools/system-one-decide.ts +113 -3
- package/src/tools/utils.ts +4 -1
- package/src/tools/workflows/create-workflow.ts +2 -0
- package/src/tools/workflows/update-workflow.ts +3 -1
- package/src/types.ts +86 -2
- package/src/ui-spec/actions.ts +30 -4
- package/src/ui-spec/schema.ts +38 -0
- package/src/ui-spec/script-actions.ts +340 -0
- package/src/ui-spec/script-allowlist.ts +48 -0
- package/src/utils/short-id.ts +20 -14
- package/src/utils/task-ui-spec.ts +16 -4
- package/src/vcs/index.ts +12 -2
- package/src/workflows/executors/system-one-decision.ts +2 -2
- package/src/workflows/resume.ts +3 -2
- package/src/workflows/task-step-routing.ts +30 -10
- package/src/workflows/triggers.ts +35 -3
- package/templates/extensions/manifest.schema.json +13 -0
- package/templates/skills/swarm-docs/content.md +2 -0
- package/templates/skills/ui-spec/content.md +7 -1
- package/templates/workflows/dreaming/content.md +1 -1
- package/dist/acp-adapter-g909b5hw.js +0 -16
- package/dist/cli-b91nz213.js +0 -93
- package/dist/handlers-yzy0c87x.js +0 -35
- package/dist/index-2t4859r5.js +0 -35
- package/dist/index-cxca2t8y.js +0 -36
- package/dist/lead-gk4h5eg7.js +0 -74
- package/dist/thread-buffer-a1re2r9r.js +0 -38
- package/dist/worker-3dyyb8ev.js +0 -74
- package/dist/{azure-openai-responses-590s1eea.js → azure-openai-responses-b3y7fz36.js} +8 -8
- package/dist/{cli-m7c2380k.js → cli-3aaeb78m.js} +4 -4
- package/dist/{cli-g0vv9dg4.js → cli-8y43jx2r.js} +8 -8
- package/dist/{cli-m0cy2vyf.js → cli-k6nejceb.js} +4 -4
- package/dist/{google-generative-ai-maq6c9bf.js → google-generative-ai-bh0djqjp.js} +4 -4
- package/dist/{google-vertex-2jgsw2nb.js → google-vertex-prjbw8dj.js} +8 -8
- package/dist/{mistral-conversations-0c30em7t.js → mistral-conversations-tm2vd4gc.js} +8 -8
- package/dist/{node-dqm4xgxw.js → node-2wfcey7d.js} +0 -0
- package/dist/{openai-codex-responses-bkcd8pjj.js → openai-codex-responses-sxjv60xx.js} +4 -4
- package/dist/{openai-completions-f3n69rep.js → openai-completions-0c7qnhsx.js} +20 -20
- package/dist/{openai-responses-gbh0wfqe.js → openai-responses-a7h29chp.js} +15 -15
- package/dist/{pi-messages-zebyt7gb.js → pi-messages-2j0fpqwq.js} +5 -5
package/src/be/users.ts
CHANGED
|
@@ -19,11 +19,12 @@
|
|
|
19
19
|
* * Q16 — `fingerprintApiKey` returns `op:<sha256-16>` for operator audit
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
-
import { createHash,
|
|
22
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
23
23
|
import { scheduleOrgDomainRecompute } from "../telemetry-identity";
|
|
24
24
|
import type { User } from "../types";
|
|
25
25
|
import { registerVolatileSecret, unregisterVolatileSecret } from "../utils/secret-scrubber";
|
|
26
26
|
import { closeSessionTokenConnections } from "../utils/session-token-connections";
|
|
27
|
+
import { randomChars } from "../utils/short-id";
|
|
27
28
|
import { getDbClient } from "./db";
|
|
28
29
|
import type { DbExecutor } from "./db-client";
|
|
29
30
|
import { validateRuntimeTokenTtlHours } from "./swarm-config-guard";
|
|
@@ -65,6 +66,7 @@ type UserRow = {
|
|
|
65
66
|
metadata: string | null;
|
|
66
67
|
dailyBudgetUsd: number | null;
|
|
67
68
|
status: string;
|
|
69
|
+
mergedIntoUserId: string | null;
|
|
68
70
|
createdAt: string;
|
|
69
71
|
lastUpdatedAt: string;
|
|
70
72
|
};
|
|
@@ -82,6 +84,7 @@ function rowToUser(row: UserRow): User {
|
|
|
82
84
|
metadata: row.metadata ? (JSON.parse(row.metadata) as Record<string, unknown>) : undefined,
|
|
83
85
|
dailyBudgetUsd: row.dailyBudgetUsd ?? null,
|
|
84
86
|
status: (row.status as "invited" | "active" | "suspended") ?? "active",
|
|
87
|
+
...(row.mergedIntoUserId ? { mergedIntoUserId: row.mergedIntoUserId } : {}),
|
|
85
88
|
createdAt: row.createdAt,
|
|
86
89
|
lastUpdatedAt: row.lastUpdatedAt,
|
|
87
90
|
};
|
|
@@ -97,6 +100,21 @@ export async function findUserById(id: string): Promise<User | null> {
|
|
|
97
100
|
return row ? rowToUser(row) : null;
|
|
98
101
|
}
|
|
99
102
|
|
|
103
|
+
/**
|
|
104
|
+
* A user whose merge job still runs (`users.mergedIntoUserId` set) is the
|
|
105
|
+
* target for every identity lookup: the merge route already moved its
|
|
106
|
+
* identities and aliases, and the background job only rewrites attribution
|
|
107
|
+
* before it deletes the row. Lookups by id are left alone so the People page
|
|
108
|
+
* and the job itself still see the source row.
|
|
109
|
+
*/
|
|
110
|
+
async function followMergedUser(row: UserRow): Promise<User | null> {
|
|
111
|
+
if (!row.mergedIntoUserId) return rowToUser(row);
|
|
112
|
+
const target = await getDbClient().get<UserRow>("SELECT * FROM users WHERE id = ?", [
|
|
113
|
+
row.mergedIntoUserId,
|
|
114
|
+
]);
|
|
115
|
+
return target ? rowToUser(target) : null;
|
|
116
|
+
}
|
|
117
|
+
|
|
100
118
|
/**
|
|
101
119
|
* Look up a user by an `(kind, externalId)` pair via `user_external_ids`.
|
|
102
120
|
* Returns null if no mapping exists. Use this for webhook auto-link paths.
|
|
@@ -108,7 +126,7 @@ export async function findUserByExternalId(kind: string, externalId: string): Pr
|
|
|
108
126
|
WHERE x.kind = ? AND x.externalId = ?`,
|
|
109
127
|
[kind, externalId],
|
|
110
128
|
);
|
|
111
|
-
return row ?
|
|
129
|
+
return row ? followMergedUser(row) : null;
|
|
112
130
|
}
|
|
113
131
|
|
|
114
132
|
/**
|
|
@@ -123,15 +141,19 @@ export async function findUserByEmail(email: string): Promise<User | null> {
|
|
|
123
141
|
const lower = email.toLowerCase();
|
|
124
142
|
const db = getDbClient();
|
|
125
143
|
|
|
126
|
-
// Primary email (case-insensitive)
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
144
|
+
// Primary email (case-insensitive). A merge source keeps its primary email
|
|
145
|
+
// until the job deletes it, while the target already holds it as an alias,
|
|
146
|
+
// so the source row must not win here.
|
|
147
|
+
const primary = await db.get<UserRow>(
|
|
148
|
+
"SELECT * FROM users WHERE LOWER(email) = LOWER(?) AND mergedIntoUserId IS NULL",
|
|
149
|
+
[email],
|
|
150
|
+
);
|
|
130
151
|
if (primary) return rowToUser(primary);
|
|
131
152
|
|
|
132
153
|
// Alias array
|
|
133
154
|
const aliasRows = await db.query<UserRow>(
|
|
134
|
-
|
|
155
|
+
`SELECT * FROM users
|
|
156
|
+
WHERE emailAliases IS NOT NULL AND emailAliases != '[]' AND mergedIntoUserId IS NULL`,
|
|
135
157
|
);
|
|
136
158
|
for (const r of aliasRows) {
|
|
137
159
|
const aliases: string[] = r.emailAliases ? (JSON.parse(r.emailAliases) as string[]) : [];
|
|
@@ -154,14 +176,17 @@ export async function findUsersByName(name: string): Promise<User[]> {
|
|
|
154
176
|
if (!trimmed) return [];
|
|
155
177
|
const client = getDbClient();
|
|
156
178
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
179
|
+
// A merge source (mergedIntoUserId set) is on its way out; its target is
|
|
180
|
+
// found by its own name.
|
|
181
|
+
const exact = await client.query<UserRow>(
|
|
182
|
+
"SELECT * FROM users WHERE LOWER(name) = LOWER(?) AND mergedIntoUserId IS NULL",
|
|
183
|
+
[trimmed],
|
|
184
|
+
);
|
|
160
185
|
if (exact.length > 0) return exact.map(rowToUser);
|
|
161
186
|
|
|
162
187
|
const firstToken = trimmed.split(/\s+/)[0] ?? trimmed;
|
|
163
188
|
const prefixed = await client.query<UserRow>(
|
|
164
|
-
"SELECT * FROM users WHERE LOWER(name) LIKE LOWER(?) || '%'",
|
|
189
|
+
"SELECT * FROM users WHERE LOWER(name) LIKE LOWER(?) || '%' AND mergedIntoUserId IS NULL",
|
|
165
190
|
[firstToken],
|
|
166
191
|
);
|
|
167
192
|
return prefixed.map(rowToUser);
|
|
@@ -442,15 +467,8 @@ export async function unlinkIdentity(
|
|
|
442
467
|
|
|
443
468
|
const TOKEN_PREFIX = "aswt_"; // agent-swarm-token
|
|
444
469
|
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
const alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
448
|
-
let out = "";
|
|
449
|
-
for (const b of bytes) {
|
|
450
|
-
out += alphabet[b % 62];
|
|
451
|
-
}
|
|
452
|
-
return out;
|
|
453
|
-
}
|
|
470
|
+
// base62 alphabet for URL-safe, unambiguous tokens.
|
|
471
|
+
const TOKEN_ALPHABET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
454
472
|
|
|
455
473
|
function sha256Hex(input: string): string {
|
|
456
474
|
return createHash("sha256").update(input).digest("hex");
|
|
@@ -469,8 +487,8 @@ export async function mintToken(
|
|
|
469
487
|
actor: IdentityActor,
|
|
470
488
|
options: { source?: string } = {},
|
|
471
489
|
): Promise<{ tokenId: string; plaintext: string }> {
|
|
472
|
-
// 24 base62 chars
|
|
473
|
-
const plaintext = `${TOKEN_PREFIX}${
|
|
490
|
+
// 24 uniformly random base62 chars (~143 bits of entropy).
|
|
491
|
+
const plaintext = `${TOKEN_PREFIX}${randomChars(TOKEN_ALPHABET, 24)}`;
|
|
474
492
|
const tokenId = randomUUID().replace(/-/g, "");
|
|
475
493
|
const hash = sha256Hex(plaintext);
|
|
476
494
|
const preview = plaintext.slice(-4);
|
|
@@ -731,7 +749,7 @@ export async function insertSessionToken(
|
|
|
731
749
|
parentTokenId: string | null = null,
|
|
732
750
|
scriptRun = false,
|
|
733
751
|
): Promise<{ tokenId: string; plaintext: string }> {
|
|
734
|
-
const plaintext = `${SESSION_TOKEN_PREFIX}${
|
|
752
|
+
const plaintext = `${SESSION_TOKEN_PREFIX}${randomChars(TOKEN_ALPHABET, 24)}`;
|
|
735
753
|
const tokenId = randomUUID().replace(/-/g, "");
|
|
736
754
|
const hash = sha256Hex(plaintext);
|
|
737
755
|
const preview = plaintext.slice(-4);
|
|
@@ -249,7 +249,7 @@ export function generateCompose(state: OnboardState): string {
|
|
|
249
249
|
// biome-ignore lint/suspicious/noTemplateCurlyInString: Docker Compose env var syntax
|
|
250
250
|
lines.push(" - MEMORY_RATERS=${MEMORY_RATERS-implicit-citation,explicit-self}");
|
|
251
251
|
// biome-ignore lint/suspicious/noTemplateCurlyInString: Docker Compose env var syntax
|
|
252
|
-
lines.push(" - MEMORY_DEMOTION_FLOOR=${MEMORY_DEMOTION_FLOOR-
|
|
252
|
+
lines.push(" - MEMORY_DEMOTION_FLOOR=${MEMORY_DEMOTION_FLOOR-0.5}");
|
|
253
253
|
appendProviderEnvironment(lines, state, false);
|
|
254
254
|
lines.push(` - MCP_BASE_URL=http://localhost:${port}`);
|
|
255
255
|
lines.push(` - APP_URL=${APP_URL}`);
|
|
@@ -53,7 +53,7 @@ export function generateEnv(state: OnboardState, env: NodeJS.ProcessEnv = proces
|
|
|
53
53
|
lines.push("MEMORY_HYBRID_SEARCH=1");
|
|
54
54
|
lines.push("MEMORY_GRAPH_EXPANSION=1");
|
|
55
55
|
lines.push("MEMORY_RATERS=implicit-citation,explicit-self");
|
|
56
|
-
lines.push("MEMORY_DEMOTION_FLOOR=
|
|
56
|
+
lines.push("MEMORY_DEMOTION_FLOOR=0.5");
|
|
57
57
|
|
|
58
58
|
if (state.bundleAgentFs) {
|
|
59
59
|
lines.push("");
|
|
@@ -191,7 +191,7 @@ export const CREDENTIAL_PROVIDER_CHECKERS: Record<SupportedProvider, CredentialC
|
|
|
191
191
|
};
|
|
192
192
|
},
|
|
193
193
|
acp: (env) => {
|
|
194
|
-
const target = env.ACP_TARGET
|
|
194
|
+
const target = env.ACP_TARGET?.trim().toLowerCase() || "custom";
|
|
195
195
|
if (!isAcpTarget(target)) {
|
|
196
196
|
return {
|
|
197
197
|
ready: false,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// Generated by scripts/bundle-extension-types.ts. Do not edit.
|
|
2
2
|
// biome-ignore-all lint/suspicious/noTemplateCurlyInString: Type declarations contain literal template placeholders.
|
|
3
3
|
export const EXTENSION_TYPE_DEFINITIONS =
|
|
4
|
-
'// biome-ignore-all lint/suspicious/noConfusingVoidType: Extension handlers may explicitly return no result.\ndeclare module "swarm-extension" {\n export type CreateTaskOptions = {\n key?: string | undefined;\n agentId?: string | null | undefined;\n creatorAgentId?: string | undefined;\n source?:\n | "chat"\n | "workflow"\n | "schedule"\n | "slack"\n | "agentmail"\n | "mcp"\n | "api"\n | "ui"\n | "github"\n | "gitlab"\n | "azure-devops"\n | "bitbucket"\n | "system"\n | "linear"\n | "jira"\n | "comb"\n | undefined;\n routingReason?:\n | "skill"\n | "continuity"\n | "overflow"\n | "human_pinned"\n | "reroute_fault"\n | undefined;\n routingSource?: "declared" | "engine_default" | undefined;\n routingNote?: string | undefined;\n taskType?: string | undefined;\n tags?: string[] | undefined;\n priority?: number | undefined;\n dependsOn?: string[] | undefined;\n offeredTo?: string | undefined;\n status?: "draft" | "backlog" | "unassigned" | undefined;\n slackChannelId?: string | undefined;\n slackThreadTs?: string | undefined;\n slackTriggerMessageTs?: string | undefined;\n slackUserId?: string | undefined;\n slackParticipants?:\n | {\n people: {\n slackUserId: string;\n trust: "external" | "unknown" | "internal";\n userId?: string | undefined;\n starter?: boolean | undefined;\n newest?: boolean | undefined;\n asked?: boolean | undefined;\n }[];\n more: number;\n }\n | undefined;\n overrideSlackContext?: boolean | undefined;\n vcsProvider?: "github" | "gitlab" | "azure-devops" | "bitbucket" | undefined;\n vcsRepo?: string | undefined;\n vcsEventType?: string | undefined;\n vcsNumber?: number | undefined;\n vcsCommentId?: number | undefined;\n vcsAuthor?: string | undefined;\n vcsUrl?: string | undefined;\n vcsInstallationId?: number | undefined;\n vcsNodeId?: string | undefined;\n agentmailInboxId?: string | undefined;\n agentmailMessageId?: string | undefined;\n agentmailThreadId?: string | undefined;\n mentionMessageId?: string | undefined;\n mentionChannelId?: string | undefined;\n dir?: string | undefined;\n parentTaskId?: string | undefined;\n model?: string | undefined;\n modelTier?: "smol" | "regular" | "smart" | "ultra" | undefined;\n effort?: "low" | "medium" | "high" | "max" | "off" | "xhigh" | undefined;\n profile?: string | undefined;\n fallbackHops?:\n | {\n from: string;\n profile: string;\n errorClass:\n | "rate_limit"\n | "model_window"\n | "seat"\n | "credits"\n | "overloaded"\n | "server_error"\n | "auth"\n | "pool_empty";\n at: string;\n skipped?: { profile: string; reason: string }[] | undefined;\n }[]\n | undefined;\n scheduleId?: string | undefined;\n workflowRunId?: string | undefined;\n workflowRunStepId?: string | undefined;\n sourceTaskId?: string | undefined;\n dispatchedByTaskId?: string | undefined;\n outputSchema?: Record<string, unknown> | undefined;\n inheritParentOutputSchema?: boolean | undefined;\n inheritParentRequester?: boolean | undefined;\n inheritParentRoutingAffinity?: boolean | undefined;\n inheritParentFollowUpConfig?: boolean | undefined;\n followUpConfig?:\n | {\n disabled?: boolean | undefined;\n onCompleted?: string | undefined;\n onFailed?: string | undefined;\n }\n | undefined;\n requestedByUserId?: string | undefined;\n contextKey?: string | undefined;\n bypassTrackerContextDedup?: boolean | undefined;\n routingAffinity?:\n | {\n capabilities: string[];\n sourceAgentId?: string | undefined;\n role?: string | undefined;\n harnessProvider?:\n | "pi"\n | "claude"\n | "claude-managed"\n | "codex"\n | "grok"\n | "fx"\n | "opencode"\n | "dsh"\n | "cursor"\n | "amp"\n | "devin"\n | "acp"\n | undefined;\n leadOnly?: boolean | undefined;\n }\n | undefined;\n };\n\n export type AgentTask = {\n id: string;\n key: string;\n agentId: string | null;\n task: string;\n status:\n | "skipped"\n | "draft"\n | "backlog"\n | "unassigned"\n | "offered"\n | "reviewing"\n | "pending"\n | "in_progress"\n | "paused"\n | "completed"\n | "failed"\n | "cancelled"\n | "superseded";\n source:\n | "chat"\n | "workflow"\n | "schedule"\n | "slack"\n | "agentmail"\n | "mcp"\n | "api"\n | "ui"\n | "github"\n | "gitlab"\n | "azure-devops"\n | "bitbucket"\n | "system"\n | "linear"\n | "jira"\n | "comb";\n tags: string[];\n priority: number;\n dependsOn: string[];\n createdAt: string;\n lastUpdatedAt: string;\n slackReplySent: boolean;\n wasPaused: boolean;\n creatorAgentId?: string | undefined;\n title?: string | undefined;\n routingReason?:\n | "skill"\n | "continuity"\n | "overflow"\n | "human_pinned"\n | "reroute_fault"\n | undefined;\n routingSource?: "declared" | "engine_default" | undefined;\n routingNote?: string | undefined;\n poolWakeAt?: string | undefined;\n taskType?: string | undefined;\n offeredTo?: string | undefined;\n offeredAt?: string | undefined;\n acceptedAt?: string | undefined;\n rejectionReason?: string | undefined;\n finishedAt?: string | undefined;\n notifiedAt?: string | undefined;\n failureReason?: string | undefined;\n output?: string | undefined;\n progress?: string | undefined;\n slackChannelId?: string | undefined;\n slackThreadTs?: string | undefined;\n slackTriggerMessageTs?: string | undefined;\n slackUserId?: string | undefined;\n slackParticipants?:\n | {\n people: {\n slackUserId: string;\n trust: "external" | "unknown" | "internal";\n userId?: string | undefined;\n starter?: boolean | undefined;\n newest?: boolean | undefined;\n asked?: boolean | undefined;\n }[];\n more: number;\n }\n | undefined;\n slackProgressMessageTs?: string | undefined;\n slackTreeRootMessageTs?: string | undefined;\n vcsProvider?: "github" | "gitlab" | "azure-devops" | "bitbucket" | undefined;\n vcsRepo?: string | undefined;\n vcsEventType?: string | undefined;\n vcsNumber?: number | undefined;\n vcsCommentId?: number | undefined;\n vcsAuthor?: string | undefined;\n vcsUrl?: string | undefined;\n vcsInstallationId?: number | undefined;\n vcsNodeId?: string | undefined;\n agentmailInboxId?: string | undefined;\n agentmailMessageId?: string | undefined;\n agentmailThreadId?: string | undefined;\n mentionMessageId?: string | undefined;\n mentionChannelId?: string | undefined;\n dir?: string | undefined;\n parentTaskId?: string | undefined;\n dispatchedByTaskId?: string | undefined;\n claudeSessionId?: string | undefined;\n model?: string | undefined;\n modelTier?: "smol" | "regular" | "smart" | "ultra" | undefined;\n effort?: "low" | "medium" | "high" | "max" | "off" | "xhigh" | undefined;\n resolvedModel?: string | undefined;\n modelSource?: string | undefined;\n modelAlias?: string | undefined;\n resolvedEffort?: "low" | "medium" | "high" | "max" | "off" | "xhigh" | undefined;\n profile?: string | undefined;\n resolvedProfile?: string | undefined;\n fallbackHops?:\n | {\n from: string;\n profile: string;\n errorClass:\n | "rate_limit"\n | "model_window"\n | "seat"\n | "credits"\n | "overloaded"\n | "server_error"\n | "auth"\n | "pool_empty";\n at: string;\n skipped?: { profile: string; reason: string }[] | undefined;\n }[]\n | undefined;\n scheduleId?: string | undefined;\n workflowRunId?: string | null | undefined;\n workflowRunStepId?: string | null | undefined;\n contextKey?: string | undefined;\n outputSchema?: Record<string, unknown> | undefined;\n followUpConfig?:\n | {\n disabled?: boolean | undefined;\n onCompleted?: string | undefined;\n onFailed?: string | undefined;\n }\n | undefined;\n deferredAt?: string | undefined;\n compactionCount?: number | undefined;\n peakContextPercent?: number | undefined;\n peakContextTokens?: number | undefined;\n contextWindowSize?: number | undefined;\n credentialKeySuffix?: string | undefined;\n credentialKeyType?: string | undefined;\n requestedByUserId?: string | undefined;\n swarmVersion?: string | undefined;\n provider?:\n | "pi"\n | "claude"\n | "claude-managed"\n | "codex"\n | "grok"\n | "fx"\n | "opencode"\n | "dsh"\n | "cursor"\n | "amp"\n | "devin"\n | "acp"\n | undefined;\n providerMeta?: Record<string, unknown> | undefined;\n harnessVariant?: string | undefined;\n harnessVariantMeta?: Record<string, unknown> | undefined;\n totalCostUsd?: number | undefined;\n routingAffinity?:\n | {\n capabilities: string[];\n sourceAgentId?: string | undefined;\n role?: string | undefined;\n harnessProvider?:\n | "pi"\n | "claude"\n | "claude-managed"\n | "codex"\n | "grok"\n | "fx"\n | "opencode"\n | "dsh"\n | "cursor"\n | "amp"\n | "devin"\n | "acp"\n | undefined;\n leadOnly?: boolean | undefined;\n }\n | undefined;\n routingAffinityInvalid?: boolean | undefined;\n };\n\n export type ActiveSession = {\n id: string;\n agentId: string;\n taskId: string | null;\n triggerType: string;\n inboxMessageId: string | null;\n taskDescription: string | null;\n runnerSessionId: string | null;\n providerSessionId: string | null;\n startedAt: string;\n lastHeartbeatAt: string;\n runtimeInstanceId?: string | null | undefined;\n };\n\n export type SteerMode = "steer" | "queue";\n\n export type SteeringSource = "chat" | "script" | "slack" | "mcp" | "api" | "ui" | "app-page";\n\n export type RequestInfo = {\n sessionId: string | undefined;\n agentId: string | undefined;\n runtimeInstanceId: string | undefined;\n sourceTaskId: string | undefined;\n contextKey: string | undefined;\n callOrigin: "mcp" | "extension" | "script-sdk";\n };\n\n import type { SwarmSdk } from "swarm-sdk";\n import type { z } from "zod";\n export type Runtime = "api" | "worker";\n export interface ExtensionScriptAsset {\n name: string;\n file: string;\n description: string;\n intent?: string;\n }\n export interface ExtensionScheduleAsset {\n name: string;\n description?: string;\n script: string;\n cronExpression?: string;\n intervalMs?: number;\n timezone?: string;\n args?: Record<string, unknown>;\n }\n export interface ExtensionWorkflowAsset {\n file: string;\n }\n export interface ExtensionSkillAsset {\n dir: string;\n }\n export interface ExtensionManifest {\n $schema?: string;\n name: string;\n description: string;\n version: string;\n runtime: Runtime;\n assets: {\n hooks: string;\n scripts?: readonly ExtensionScriptAsset[];\n schedules?: readonly ExtensionScheduleAsset[];\n workflows?: readonly ExtensionWorkflowAsset[];\n skills?: readonly ExtensionSkillAsset[];\n };\n homepage?: string;\n author?: string;\n }\n export interface HooksModule {\n default: SwarmExtension;\n config?: z.ZodTypeAny;\n }\n export interface ExtensionState {\n get<T = unknown>(key: string): Promise<T | null>;\n set<T>(key: string, value: T): Promise<void>;\n incr(key: string, by?: number): Promise<number>;\n del(key: string): Promise<void>;\n }\n export interface ExtensionLogger {\n debug(message: string, data?: unknown): void;\n info(message: string, data?: unknown): void;\n warn(message: string, data?: unknown): void;\n error(message: string, data?: unknown): void;\n }\n type ConfigFor<M extends ExtensionManifest> = M extends {\n config: infer C extends z.ZodTypeAny;\n }\n ? z.infer<C>\n : Record<string, unknown>;\n export interface ApiCtx<Config = Record<string, unknown>> {\n swarm: SwarmSdk;\n state: ExtensionState;\n config: Config;\n log: ExtensionLogger;\n signal: AbortSignal;\n event: {\n name: keyof SwarmEventMap;\n at: string;\n extension: {\n id: string;\n version: number;\n };\n };\n }\n export interface WorkerCtx<Config = Record<string, unknown>>\n extends Omit<ApiCtx<Config>, "swarm"> {\n swarm: SwarmSdk;\n worker: {\n agentId: string;\n taskId: string;\n harness: string;\n };\n }\n export type CtxFor<M extends ExtensionManifest> = M["runtime"] extends "api"\n ? ApiCtx<ConfigFor<M>>\n : WorkerCtx<ConfigFor<M>>;\n export type PreResult<Modify> =\n | void\n | {\n action: "continue";\n }\n | {\n action: "modify";\n data: Modify;\n }\n | {\n action: "block";\n reason: string;\n };\n export type TaskCreateOrigin =\n | "rest"\n | "app"\n | "mcp"\n | "slack"\n | "schedule"\n | "workflow"\n | "webhook"\n | "followUp"\n | `extension:${string}`;\n export interface TaskCreateEvent {\n options: CreateTaskOptions;\n description: string;\n origin: TaskCreateOrigin;\n requestInfo?: RequestInfo;\n /** Slack ingress metadata; not persisted or writable through modify. */\n slack?: {\n trigger: "mention" | "thread-buffer";\n messages: {\n ts: string;\n userId: string;\n text: string;\n }[];\n };\n }\n /** A pre.task.create hook blocked a task before it was created. */\n export interface TaskBlockedEvent {\n /** The extension that blocked, or whose model/agent rewrite was rejected. */\n extension: {\n id: string;\n name: string;\n };\n /** The scrubbed block reason. */\n reason: string;\n origin: TaskCreateOrigin;\n source?: AgentTask["source"];\n requester: {\n userId?: string;\n agentId?: string;\n slackUserId?: string;\n };\n context?: {\n contextKey?: string;\n scheduleId?: string;\n workflowRunId?: string;\n workflowRunStepId?: string;\n parentTaskId?: string;\n vcsRepo?: string;\n vcsNumber?: number;\n slackChannelId?: string;\n slackThreadTs?: string;\n };\n /** The original task description, scrubbed and cut to 500 characters. */\n description: string;\n }\n export type TaskCreateModify = Partial<\n Pick<\n CreateTaskOptions,\n | "agentId"\n | "creatorAgentId"\n | "source"\n | "taskType"\n | "tags"\n | "priority"\n | "dependsOn"\n | "offeredTo"\n | "vcsProvider"\n | "vcsRepo"\n | "vcsEventType"\n | "vcsNumber"\n | "vcsCommentId"\n | "vcsAuthor"\n | "vcsUrl"\n | "vcsInstallationId"\n | "vcsNodeId"\n | "agentmailInboxId"\n | "agentmailMessageId"\n | "agentmailThreadId"\n | "mentionMessageId"\n | "mentionChannelId"\n | "dir"\n | "model"\n | "modelTier"\n | "effort"\n | "outputSchema"\n | "followUpConfig"\n | "bypassTrackerContextDedup"\n >\n > & {\n description?: string;\n };\n export interface TaskFollowUpEvent {\n completedTask: AgentTask;\n status: "completed" | "failed";\n output?: string;\n failureReason?: string;\n workerAgentId: string;\n leadAgentId: string;\n summary: string;\n }\n export interface TaskSteerEvent {\n task: AgentTask;\n message: string;\n mode: SteerMode;\n source: SteeringSource;\n sender: {\n kind: "user" | "agent" | "system";\n userId?: string;\n agentId?: string;\n };\n messageTimestamps?: string[];\n /** Slack ingress metadata; not persisted or writable through modify. */\n slack?: {\n channelId: string;\n threadTs: string;\n userId?: string;\n };\n }\n export interface TaskSteerModify {\n message: string;\n }\n export type TaskFollowUpModify = Partial<\n Pick<CreateTaskOptions, "agentId" | "priority" | "followUpConfig">\n > & {\n description?: string;\n };\n export interface SlackRouteEvent {\n channelId: string;\n userId: string;\n text: string;\n threadTs?: string;\n botMentioned: boolean;\n threadContext?: {\n channelId: string;\n threadTs: string;\n };\n }\n export interface SlackRouteModify {\n target:\n | {\n kind: "agent";\n agentId: string;\n }\n | {\n kind: "lead";\n }\n | {\n kind: "broadcast";\n };\n }\n /** A Chat SDK message after its thread buffer flushed, before routing. */\n export interface ChatRouteEvent {\n /** Adapter name, such as `telegram` or `slack`. */\n adapter: string;\n channelId: string;\n /** The Chat SDK thread id, prefixed with the adapter name. */\n threadId: string;\n /** The first buffered sender. */\n userId: string;\n userName?: string;\n /** The buffered messages, joined. */\n text: string;\n /** True for an @mention and for a reply to one of the bot\'s messages. */\n botMentioned: boolean;\n isDirectMessage: boolean;\n /** Platform chat type, such as Telegram `private`, `group`, `supergroup` or `channel`. */\n chatType?: string;\n /** Set for a Telegram supergroup with topics. */\n isForum?: boolean;\n /** A buffered message replies to one of the bot\'s own messages. */\n replyToBot: boolean;\n /** Set when earlier swarm tasks exist in this thread. */\n threadContext?: {\n adapter: string;\n threadId: string;\n };\n }\n export interface ChatRouteModify {\n target:\n | {\n kind: "agent";\n agentId: string;\n }\n | {\n kind: "lead";\n }\n | {\n kind: "broadcast";\n }\n | {\n kind: "workflow";\n workflowId: string;\n };\n }\n export type HeartbeatClassification = "no-session" | "stale-session" | "fresh-stalled";\n export type HeartbeatAction = "supersede-resume" | "fail" | "record";\n export interface HeartbeatRemediateEvent {\n task: AgentTask;\n session?: ActiveSession;\n classification: HeartbeatClassification;\n proposedAction: HeartbeatAction;\n reason: string;\n taskAgeMs: number;\n sessionHeartbeatAgeMs?: number;\n }\n export interface HeartbeatRemediateModify {\n proposedAction: HeartbeatAction;\n }\n export interface ToolCallEvent {\n tool: string;\n args: unknown;\n requestInfo: RequestInfo;\n }\n export interface ToolCallModify {\n args: unknown;\n }\n export interface TaskEvent {\n task: AgentTask;\n }\n export interface TaskCompletedEvent extends TaskEvent {\n output: string;\n }\n export interface TaskFailedEvent extends TaskEvent {\n failureReason: string;\n }\n export interface TaskSupersededEvent extends TaskEvent {\n supersededBy: string;\n }\n export interface TaskProgressEvent extends TaskEvent {\n progress: string;\n }\n export interface SlackMessageEvent {\n channelId: string;\n userId: string;\n text: string;\n threadTs?: string;\n taskId?: string;\n }\n /** A Chat SDK message the swarm received or sent. */\n export interface ChatMessageEvent {\n adapter: string;\n channelId: string;\n threadId: string;\n /** The sender, for an inbound message. */\n userId?: string;\n text: string;\n direction: "inbound" | "outbound";\n taskId?: string;\n messageId?: string;\n }\n /**\n * A person answered an approval request. Fires for workflow and standalone\n * requests. Timeouts and cancellations do not emit it today.\n */\n export interface ApprovalResolvedEvent {\n requestId: string;\n status: "approved" | "rejected" | "timeout" | "cancelled";\n responses: Record<string, unknown> | null;\n /** Set when a workflow human-in-the-loop step asked. Absent for a standalone request. */\n workflowRunId?: string;\n workflowRunStepId?: string;\n /** The task whose agent asked, for a standalone request. */\n sourceTaskId?: string;\n }\n /** A task was refused because a daily spend budget is used up. */\n export interface TaskBudgetRefusedEvent extends TaskEvent {\n /** The agent the task was refused for. */\n agentId: string;\n /** Which budget refused it. The matching spend and budget fields are set. */\n cause: "agent" | "global" | "user";\n agentSpendUsd?: number;\n agentBudgetUsd?: number;\n globalSpendUsd?: number;\n globalBudgetUsd?: number;\n userSpendUsd?: number;\n userBudgetUsd?: number;\n /** ISO 8601 time the daily budget resets. */\n resetAt: string;\n }\n /** An inbound AgentMail message. */\n export interface EmailReceivedEvent {\n inboxId: string;\n /** The From header as sent. */\n from: string;\n subject: string;\n /** The text body, or the HTML when there is no text, cut to 500 characters with `...` appended. */\n body: string;\n threadId: string;\n messageId: string;\n }\n /** An inbound Kapso (WhatsApp) message. */\n export interface KapsoMessageEvent {\n phoneNumberId: string;\n conversationId?: string;\n messageId: string;\n from?: string;\n /** Kapso message type, such as `text` or `image`. */\n type?: string;\n /** The text, or a placeholder naming the type for a non-text message. */\n text: string;\n }\n export type VcsProvider = "github" | "gitlab" | "azure-devops" | "bitbucket";\n /**\n * The provider object the event is about, as the provider names it. GitLab\n * calls a pull request a merge request, and a comment a `note`.\n */\n export type VcsEventKind =\n | "pull_request"\n | "merge_request"\n | "issue"\n | "issue_comment"\n | "note"\n | "pull_request_review"\n | "pipeline";\n /**\n * A webhook event from a connected code host. `action` is the provider\'s own\n * value: `opened`, `closed`, `synchronize`, `merge`, `created`, `commented`, or,\n * for a pipeline, its status such as `success` or `failed`. Fields a kind does\n * not carry are absent.\n */\n export interface VcsEvent {\n provider: VcsProvider;\n kind: VcsEventKind;\n action: string;\n /** `owner/name` on GitHub and GitLab, `workspace/repo_slug` on Bitbucket, the repository URL on Azure DevOps. */\n repo: string;\n /** The PR, merge request, or issue number. Absent for a pipeline outside a merge request. */\n number?: number;\n title?: string;\n body?: string | null;\n /** Login of the user behind the event. Set for pull requests, merge requests, and Azure DevOps comments. */\n author?: string;\n url?: string;\n merged?: boolean;\n changedFiles?: number;\n /** The review verdict, on a pull request review. */\n reviewState?: string;\n }\n export interface ToolCallCompletedEvent extends ToolCallEvent {\n result: unknown;\n durationMs: number;\n }\n export interface SwarmEventMap {\n "pre.task.create": {\n event: TaskCreateEvent;\n modify: TaskCreateModify;\n result: PreResult<TaskCreateModify>;\n };\n "pre.task.followUp": {\n event: TaskFollowUpEvent;\n modify: TaskFollowUpModify;\n result: PreResult<TaskFollowUpModify>;\n };\n "pre.task.steer": {\n event: TaskSteerEvent;\n modify: TaskSteerModify;\n result: PreResult<TaskSteerModify>;\n };\n "pre.slack.route": {\n event: SlackRouteEvent;\n modify: SlackRouteModify;\n result: PreResult<SlackRouteModify>;\n };\n "pre.chat.route": {\n event: ChatRouteEvent;\n modify: ChatRouteModify;\n result: PreResult<ChatRouteModify>;\n };\n "pre.heartbeat.remediate": {\n event: HeartbeatRemediateEvent;\n modify: HeartbeatRemediateModify;\n result: PreResult<HeartbeatRemediateModify>;\n };\n "pre.tool.call": {\n event: ToolCallEvent;\n modify: ToolCallModify;\n result: PreResult<ToolCallModify>;\n };\n "post.task.created": {\n event: TaskEvent;\n modify: never;\n result: void;\n };\n "post.task.blocked": {\n event: TaskBlockedEvent;\n modify: never;\n result: void;\n };\n "post.task.completed": {\n event: TaskCompletedEvent;\n modify: never;\n result: void;\n };\n "post.task.failed": {\n event: TaskFailedEvent;\n modify: never;\n result: void;\n };\n "post.task.cancelled": {\n event: TaskEvent;\n modify: never;\n result: void;\n };\n "post.task.superseded": {\n event: TaskSupersededEvent;\n modify: never;\n result: void;\n };\n "post.task.progress": {\n event: TaskProgressEvent;\n modify: never;\n result: void;\n };\n "post.slack.message": {\n event: SlackMessageEvent;\n modify: never;\n result: void;\n };\n "post.chat.message": {\n event: ChatMessageEvent;\n modify: never;\n result: void;\n };\n "post.approval.resolved": {\n event: ApprovalResolvedEvent;\n modify: never;\n result: void;\n };\n "post.task.budgetRefused": {\n event: TaskBudgetRefusedEvent;\n modify: never;\n result: void;\n };\n "post.email.received": {\n event: EmailReceivedEvent;\n modify: never;\n result: void;\n };\n "post.kapso.message": {\n event: KapsoMessageEvent;\n modify: never;\n result: void;\n };\n "post.vcs.event": {\n event: VcsEvent;\n modify: never;\n result: void;\n };\n "post.tool.call": {\n event: ToolCallCompletedEvent;\n modify: never;\n result: void;\n };\n }\n export interface ExtensionApi<\n M extends ExtensionManifest = ExtensionManifest & {\n runtime: "api";\n },\n > {\n on<E extends keyof SwarmEventMap>(\n event: E,\n handler: (\n event: SwarmEventMap[E]["event"],\n ctx: CtxFor<M>,\n ) => Promise<SwarmEventMap[E]["result"]> | SwarmEventMap[E]["result"],\n opts?: {\n priority?: number;\n },\n ): void;\n }\n export type SwarmExtension<\n M extends ExtensionManifest = ExtensionManifest & {\n runtime: "api";\n },\n > = (api: ExtensionApi<M>) => void;\n export { block, modify } from "./contract-runtime";\n}\n';
|
|
4
|
+
'// biome-ignore-all lint/suspicious/noConfusingVoidType: Extension handlers may explicitly return no result.\ndeclare module "swarm-extension" {\n export type CreateTaskOptions = {\n key?: string | undefined;\n agentId?: string | null | undefined;\n creatorAgentId?: string | undefined;\n source?:\n | "chat"\n | "workflow"\n | "schedule"\n | "slack"\n | "agentmail"\n | "mcp"\n | "api"\n | "ui"\n | "github"\n | "gitlab"\n | "azure-devops"\n | "bitbucket"\n | "system"\n | "linear"\n | "jira"\n | "comb"\n | undefined;\n routingReason?:\n | "skill"\n | "continuity"\n | "overflow"\n | "human_pinned"\n | "reroute_fault"\n | undefined;\n routingSource?: "declared" | "engine_default" | undefined;\n routingNote?: string | undefined;\n taskType?: string | undefined;\n tags?: string[] | undefined;\n priority?: number | undefined;\n dependsOn?: string[] | undefined;\n offeredTo?: string | undefined;\n status?: "draft" | "backlog" | "unassigned" | undefined;\n slackChannelId?: string | undefined;\n slackThreadTs?: string | undefined;\n slackTriggerMessageTs?: string | undefined;\n slackUserId?: string | undefined;\n slackParticipants?:\n | {\n people: {\n slackUserId: string;\n trust: "external" | "unknown" | "internal";\n userId?: string | undefined;\n starter?: boolean | undefined;\n newest?: boolean | undefined;\n asked?: boolean | undefined;\n }[];\n more: number;\n }\n | undefined;\n overrideSlackContext?: boolean | undefined;\n vcsProvider?: "github" | "gitlab" | "azure-devops" | "bitbucket" | undefined;\n vcsRepo?: string | undefined;\n vcsEventType?: string | undefined;\n vcsNumber?: number | undefined;\n vcsCommentId?: number | undefined;\n vcsAuthor?: string | undefined;\n vcsUrl?: string | undefined;\n vcsInstallationId?: number | undefined;\n vcsNodeId?: string | undefined;\n agentmailInboxId?: string | undefined;\n agentmailMessageId?: string | undefined;\n agentmailThreadId?: string | undefined;\n mentionMessageId?: string | undefined;\n mentionChannelId?: string | undefined;\n dir?: string | undefined;\n parentTaskId?: string | undefined;\n model?: string | undefined;\n modelTier?: "smol" | "regular" | "smart" | "ultra" | undefined;\n effort?: "low" | "medium" | "high" | "max" | "off" | "xhigh" | undefined;\n profile?: string | undefined;\n fallbackHops?:\n | {\n from: string;\n profile: string;\n errorClass:\n | "rate_limit"\n | "model_window"\n | "seat"\n | "credits"\n | "overloaded"\n | "server_error"\n | "auth"\n | "pool_empty";\n at: string;\n skipped?: { profile: string; reason: string }[] | undefined;\n }[]\n | undefined;\n scheduleId?: string | undefined;\n workflowRunId?: string | undefined;\n workflowRunStepId?: string | undefined;\n sourceTaskId?: string | undefined;\n dispatchedByTaskId?: string | undefined;\n outputSchema?: Record<string, unknown> | undefined;\n inheritParentOutputSchema?: boolean | undefined;\n inheritParentRequester?: boolean | undefined;\n inheritParentRoutingAffinity?: boolean | undefined;\n inheritParentFollowUpConfig?: boolean | undefined;\n followUpConfig?:\n | {\n disabled?: boolean | undefined;\n onCompleted?: string | undefined;\n onFailed?: string | undefined;\n }\n | undefined;\n requestedByUserId?: string | undefined;\n contextKey?: string | undefined;\n bypassTrackerContextDedup?: boolean | undefined;\n routingAffinity?:\n | {\n capabilities: string[];\n sourceAgentId?: string | undefined;\n role?: string | undefined;\n harnessProvider?:\n | "pi"\n | "claude"\n | "claude-managed"\n | "codex"\n | "grok"\n | "fx"\n | "opencode"\n | "dsh"\n | "cursor"\n | "amp"\n | "devin"\n | "acp"\n | undefined;\n leadOnly?: boolean | undefined;\n }\n | undefined;\n };\n\n export type AgentTask = {\n id: string;\n key: string;\n agentId: string | null;\n task: string;\n status:\n | "skipped"\n | "draft"\n | "backlog"\n | "unassigned"\n | "offered"\n | "reviewing"\n | "pending"\n | "in_progress"\n | "paused"\n | "completed"\n | "failed"\n | "cancelled"\n | "superseded";\n source:\n | "chat"\n | "workflow"\n | "schedule"\n | "slack"\n | "agentmail"\n | "mcp"\n | "api"\n | "ui"\n | "github"\n | "gitlab"\n | "azure-devops"\n | "bitbucket"\n | "system"\n | "linear"\n | "jira"\n | "comb";\n tags: string[];\n priority: number;\n dependsOn: string[];\n createdAt: string;\n lastUpdatedAt: string;\n slackReplySent: boolean;\n wasPaused: boolean;\n creatorAgentId?: string | undefined;\n title?: string | undefined;\n routingReason?:\n | "skill"\n | "continuity"\n | "overflow"\n | "human_pinned"\n | "reroute_fault"\n | undefined;\n routingSource?: "declared" | "engine_default" | undefined;\n routingNote?: string | undefined;\n poolWakeAt?: string | undefined;\n taskType?: string | undefined;\n offeredTo?: string | undefined;\n offeredAt?: string | undefined;\n acceptedAt?: string | undefined;\n rejectionReason?: string | undefined;\n finishedAt?: string | undefined;\n notifiedAt?: string | undefined;\n failureReason?: string | undefined;\n output?: string | undefined;\n progress?: string | undefined;\n slackChannelId?: string | undefined;\n slackThreadTs?: string | undefined;\n slackTriggerMessageTs?: string | undefined;\n slackUserId?: string | undefined;\n slackParticipants?:\n | {\n people: {\n slackUserId: string;\n trust: "external" | "unknown" | "internal";\n userId?: string | undefined;\n starter?: boolean | undefined;\n newest?: boolean | undefined;\n asked?: boolean | undefined;\n }[];\n more: number;\n }\n | undefined;\n slackProgressMessageTs?: string | undefined;\n slackTreeRootMessageTs?: string | undefined;\n vcsProvider?: "github" | "gitlab" | "azure-devops" | "bitbucket" | undefined;\n vcsRepo?: string | undefined;\n vcsEventType?: string | undefined;\n vcsNumber?: number | undefined;\n vcsCommentId?: number | undefined;\n vcsAuthor?: string | undefined;\n vcsUrl?: string | undefined;\n vcsInstallationId?: number | undefined;\n vcsNodeId?: string | undefined;\n agentmailInboxId?: string | undefined;\n agentmailMessageId?: string | undefined;\n agentmailThreadId?: string | undefined;\n mentionMessageId?: string | undefined;\n mentionChannelId?: string | undefined;\n dir?: string | undefined;\n parentTaskId?: string | undefined;\n dispatchedByTaskId?: string | undefined;\n claudeSessionId?: string | undefined;\n model?: string | undefined;\n modelTier?: "smol" | "regular" | "smart" | "ultra" | undefined;\n effort?: "low" | "medium" | "high" | "max" | "off" | "xhigh" | undefined;\n resolvedModel?: string | undefined;\n modelSource?: string | undefined;\n modelAlias?: string | undefined;\n resolvedEffort?: "low" | "medium" | "high" | "max" | "off" | "xhigh" | undefined;\n profile?: string | undefined;\n resolvedProfile?: string | undefined;\n fallbackHops?:\n | {\n from: string;\n profile: string;\n errorClass:\n | "rate_limit"\n | "model_window"\n | "seat"\n | "credits"\n | "overloaded"\n | "server_error"\n | "auth"\n | "pool_empty";\n at: string;\n skipped?: { profile: string; reason: string }[] | undefined;\n }[]\n | undefined;\n scheduleId?: string | undefined;\n workflowRunId?: string | null | undefined;\n workflowRunStepId?: string | null | undefined;\n contextKey?: string | undefined;\n outputSchema?: Record<string, unknown> | undefined;\n followUpConfig?:\n | {\n disabled?: boolean | undefined;\n onCompleted?: string | undefined;\n onFailed?: string | undefined;\n }\n | undefined;\n deferredAt?: string | undefined;\n compactionCount?: number | undefined;\n peakContextPercent?: number | undefined;\n peakContextTokens?: number | undefined;\n contextWindowSize?: number | undefined;\n credentialKeySuffix?: string | undefined;\n credentialKeyType?: string | undefined;\n requestedByUserId?: string | undefined;\n swarmVersion?: string | undefined;\n provider?:\n | "pi"\n | "claude"\n | "claude-managed"\n | "codex"\n | "grok"\n | "fx"\n | "opencode"\n | "dsh"\n | "cursor"\n | "amp"\n | "devin"\n | "acp"\n | undefined;\n providerMeta?: Record<string, unknown> | undefined;\n harnessVariant?: string | undefined;\n harnessVariantMeta?: Record<string, unknown> | undefined;\n totalCostUsd?: number | undefined;\n routingAffinity?:\n | {\n capabilities: string[];\n sourceAgentId?: string | undefined;\n role?: string | undefined;\n harnessProvider?:\n | "pi"\n | "claude"\n | "claude-managed"\n | "codex"\n | "grok"\n | "fx"\n | "opencode"\n | "dsh"\n | "cursor"\n | "amp"\n | "devin"\n | "acp"\n | undefined;\n leadOnly?: boolean | undefined;\n }\n | undefined;\n routingAffinityInvalid?: boolean | undefined;\n };\n\n export type ActiveSession = {\n id: string;\n agentId: string;\n taskId: string | null;\n triggerType: string;\n inboxMessageId: string | null;\n taskDescription: string | null;\n runnerSessionId: string | null;\n providerSessionId: string | null;\n startedAt: string;\n lastHeartbeatAt: string;\n runtimeInstanceId?: string | null | undefined;\n };\n\n export type SteerMode = "steer" | "queue";\n\n export type SteeringSource = "chat" | "script" | "slack" | "mcp" | "api" | "ui" | "app-page";\n\n export type RequestInfo = {\n sessionId: string | undefined;\n agentId: string | undefined;\n runtimeInstanceId: string | undefined;\n sourceTaskId: string | undefined;\n contextKey: string | undefined;\n callOrigin: "mcp" | "native" | "extension" | "script-sdk";\n harness?: string | undefined;\n };\n\n import type { SwarmSdk } from "swarm-sdk";\n import type { z } from "zod";\n export type Runtime = "api" | "worker";\n export interface ExtensionScriptAsset {\n name: string;\n file: string;\n description: string;\n intent?: string;\n }\n export interface ExtensionScheduleAsset {\n name: string;\n description?: string;\n script: string;\n cronExpression?: string;\n intervalMs?: number;\n timezone?: string;\n args?: Record<string, unknown>;\n }\n export interface ExtensionWorkflowAsset {\n file: string;\n }\n export interface ExtensionSkillAsset {\n dir: string;\n }\n export interface ExtensionManifest {\n $schema?: string;\n name: string;\n description: string;\n version: string;\n runtime: Runtime;\n assets: {\n hooks: string;\n scripts?: readonly ExtensionScriptAsset[];\n schedules?: readonly ExtensionScheduleAsset[];\n workflows?: readonly ExtensionWorkflowAsset[];\n skills?: readonly ExtensionSkillAsset[];\n };\n homepage?: string;\n author?: string;\n /** Tool-call sources this extension\'s tool handlers receive. Default `["mcp"]`. */\n toolSources?: readonly ToolSource[];\n }\n /** `mcp`: swarm MCP tools. `native`: harness built-ins reported by a worker shim. */\n export type ToolSource = "mcp" | "native";\n export interface HooksModule {\n default: SwarmExtension;\n config?: z.ZodTypeAny;\n }\n export interface ExtensionState {\n get<T = unknown>(key: string): Promise<T | null>;\n set<T>(key: string, value: T): Promise<void>;\n incr(key: string, by?: number): Promise<number>;\n del(key: string): Promise<void>;\n }\n export interface ExtensionLogger {\n debug(message: string, data?: unknown): void;\n info(message: string, data?: unknown): void;\n warn(message: string, data?: unknown): void;\n error(message: string, data?: unknown): void;\n }\n type ConfigFor<M extends ExtensionManifest> = M extends {\n config: infer C extends z.ZodTypeAny;\n }\n ? z.infer<C>\n : Record<string, unknown>;\n export interface ApiCtx<Config = Record<string, unknown>> {\n swarm: SwarmSdk;\n state: ExtensionState;\n config: Config;\n log: ExtensionLogger;\n signal: AbortSignal;\n event: {\n name: keyof SwarmEventMap;\n at: string;\n extension: {\n id: string;\n version: number;\n };\n };\n }\n export interface WorkerCtx<Config = Record<string, unknown>>\n extends Omit<ApiCtx<Config>, "swarm"> {\n swarm: SwarmSdk;\n worker: {\n agentId: string;\n taskId: string;\n harness: string;\n };\n }\n export type CtxFor<M extends ExtensionManifest> = M["runtime"] extends "api"\n ? ApiCtx<ConfigFor<M>>\n : WorkerCtx<ConfigFor<M>>;\n export type PreResult<Modify> =\n | void\n | {\n action: "continue";\n }\n | {\n action: "modify";\n data: Modify;\n }\n | {\n action: "block";\n reason: string;\n };\n export type TaskCreateOrigin =\n | "rest"\n | "app"\n | "mcp"\n | "slack"\n | "schedule"\n | "workflow"\n | "webhook"\n | "followUp"\n | `extension:${string}`;\n export interface TaskCreateEvent {\n options: CreateTaskOptions;\n description: string;\n origin: TaskCreateOrigin;\n requestInfo?: RequestInfo;\n /** Slack ingress metadata; not persisted or writable through modify. */\n slack?: {\n trigger: "mention" | "thread-buffer";\n messages: {\n ts: string;\n userId: string;\n text: string;\n }[];\n };\n }\n /** A pre.task.create hook blocked a task before it was created. */\n export interface TaskBlockedEvent {\n /** The extension that blocked, or whose model/agent rewrite was rejected. */\n extension: {\n id: string;\n name: string;\n };\n /** The scrubbed block reason. */\n reason: string;\n origin: TaskCreateOrigin;\n source?: AgentTask["source"];\n requester: {\n userId?: string;\n agentId?: string;\n slackUserId?: string;\n };\n context?: {\n contextKey?: string;\n scheduleId?: string;\n workflowRunId?: string;\n workflowRunStepId?: string;\n parentTaskId?: string;\n vcsRepo?: string;\n vcsNumber?: number;\n slackChannelId?: string;\n slackThreadTs?: string;\n };\n /** The original task description, scrubbed and cut to 500 characters. */\n description: string;\n }\n export type TaskCreateModify = Partial<\n Pick<\n CreateTaskOptions,\n | "agentId"\n | "creatorAgentId"\n | "source"\n | "taskType"\n | "tags"\n | "priority"\n | "dependsOn"\n | "offeredTo"\n | "vcsProvider"\n | "vcsRepo"\n | "vcsEventType"\n | "vcsNumber"\n | "vcsCommentId"\n | "vcsAuthor"\n | "vcsUrl"\n | "vcsInstallationId"\n | "vcsNodeId"\n | "agentmailInboxId"\n | "agentmailMessageId"\n | "agentmailThreadId"\n | "mentionMessageId"\n | "mentionChannelId"\n | "dir"\n | "model"\n | "modelTier"\n | "effort"\n | "outputSchema"\n | "followUpConfig"\n | "bypassTrackerContextDedup"\n >\n > & {\n description?: string;\n };\n export interface TaskFollowUpEvent {\n completedTask: AgentTask;\n status: "completed" | "failed";\n output?: string;\n failureReason?: string;\n workerAgentId: string;\n leadAgentId: string;\n summary: string;\n }\n export interface TaskSteerEvent {\n task: AgentTask;\n message: string;\n mode: SteerMode;\n source: SteeringSource;\n sender: {\n kind: "user" | "agent" | "system";\n userId?: string;\n agentId?: string;\n };\n messageTimestamps?: string[];\n /** Slack ingress metadata; not persisted or writable through modify. */\n slack?: {\n channelId: string;\n threadTs: string;\n userId?: string;\n };\n }\n export interface TaskSteerModify {\n message: string;\n }\n export type TaskFollowUpModify = Partial<\n Pick<CreateTaskOptions, "agentId" | "priority" | "followUpConfig">\n > & {\n description?: string;\n };\n export interface SlackRouteEvent {\n channelId: string;\n userId: string;\n text: string;\n threadTs?: string;\n botMentioned: boolean;\n threadContext?: {\n channelId: string;\n threadTs: string;\n };\n }\n export interface SlackRouteModify {\n target:\n | {\n kind: "agent";\n agentId: string;\n }\n | {\n kind: "lead";\n }\n | {\n kind: "broadcast";\n };\n }\n /** A Chat SDK message after its thread buffer flushed, before routing. */\n export interface ChatRouteEvent {\n /** Adapter name, such as `telegram` or `slack`. */\n adapter: string;\n channelId: string;\n /** The Chat SDK thread id, prefixed with the adapter name. */\n threadId: string;\n /** The first buffered sender. */\n userId: string;\n userName?: string;\n /** The buffered messages, joined. */\n text: string;\n /** True for an @mention and for a reply to one of the bot\'s messages. */\n botMentioned: boolean;\n isDirectMessage: boolean;\n /** Platform chat type, such as Telegram `private`, `group`, `supergroup` or `channel`. */\n chatType?: string;\n /** Set for a Telegram supergroup with topics. */\n isForum?: boolean;\n /** A buffered message replies to one of the bot\'s own messages. */\n replyToBot: boolean;\n /** Set when earlier swarm tasks exist in this thread. */\n threadContext?: {\n adapter: string;\n threadId: string;\n };\n }\n export interface ChatRouteModify {\n target:\n | {\n kind: "agent";\n agentId: string;\n }\n | {\n kind: "lead";\n }\n | {\n kind: "broadcast";\n }\n | {\n kind: "workflow";\n workflowId: string;\n };\n }\n export type HeartbeatClassification = "no-session" | "stale-session" | "fresh-stalled";\n export type HeartbeatAction = "supersede-resume" | "fail" | "record";\n export interface HeartbeatRemediateEvent {\n task: AgentTask;\n session?: ActiveSession;\n classification: HeartbeatClassification;\n proposedAction: HeartbeatAction;\n reason: string;\n taskAgeMs: number;\n sessionHeartbeatAgeMs?: number;\n }\n export interface HeartbeatRemediateModify {\n proposedAction: HeartbeatAction;\n }\n export interface ToolCallEvent {\n tool: string;\n /** Secret-scrubbed on native calls: a secret reads as `[REDACTED:<name>]`. */\n args: unknown;\n requestInfo: RequestInfo;\n /** Native calls only: the harness\'s own tool name, such as `Bash`. */\n nativeTool?: string;\n /** Native calls only: the harness\'s own argument shape, secret-scrubbed. */\n rawArgs?: unknown;\n /** Native calls only: the harness\'s call id, and its parent for a nested call. */\n toolCallId?: string;\n parentToolCallId?: string;\n }\n export interface ToolCallModify {\n args: unknown;\n }\n export interface TaskEvent {\n task: AgentTask;\n }\n export interface TaskCompletedEvent extends TaskEvent {\n output: string;\n }\n export interface TaskFailedEvent extends TaskEvent {\n failureReason: string;\n }\n export interface TaskSupersededEvent extends TaskEvent {\n supersededBy: string;\n }\n export interface TaskProgressEvent extends TaskEvent {\n progress: string;\n }\n export interface SlackMessageEvent {\n channelId: string;\n userId: string;\n text: string;\n threadTs?: string;\n taskId?: string;\n }\n /** A Chat SDK message the swarm received or sent. */\n export interface ChatMessageEvent {\n adapter: string;\n channelId: string;\n threadId: string;\n /** The sender, for an inbound message. */\n userId?: string;\n text: string;\n direction: "inbound" | "outbound";\n taskId?: string;\n messageId?: string;\n }\n /**\n * A person answered an approval request. Fires for workflow and standalone\n * requests. Timeouts and cancellations do not emit it today.\n */\n export interface ApprovalResolvedEvent {\n requestId: string;\n status: "approved" | "rejected" | "timeout" | "cancelled";\n responses: Record<string, unknown> | null;\n /** Set when a workflow human-in-the-loop step asked. Absent for a standalone request. */\n workflowRunId?: string;\n workflowRunStepId?: string;\n /** The task whose agent asked, for a standalone request. */\n sourceTaskId?: string;\n }\n /** A task was refused because a daily spend budget is used up. */\n export interface TaskBudgetRefusedEvent extends TaskEvent {\n /** The agent the task was refused for. */\n agentId: string;\n /** Which budget refused it. The matching spend and budget fields are set. */\n cause: "agent" | "global" | "user";\n agentSpendUsd?: number;\n agentBudgetUsd?: number;\n globalSpendUsd?: number;\n globalBudgetUsd?: number;\n userSpendUsd?: number;\n userBudgetUsd?: number;\n /** ISO 8601 time the daily budget resets. */\n resetAt: string;\n }\n /** An inbound AgentMail message. */\n export interface EmailReceivedEvent {\n inboxId: string;\n /** The From header as sent. */\n from: string;\n subject: string;\n /** The text body, or the HTML when there is no text, cut to 500 characters with `...` appended. */\n body: string;\n threadId: string;\n messageId: string;\n }\n /** An inbound Kapso (WhatsApp) message. */\n export interface KapsoMessageEvent {\n phoneNumberId: string;\n conversationId?: string;\n messageId: string;\n from?: string;\n /** Kapso message type, such as `text` or `image`. */\n type?: string;\n /** The text, or a placeholder naming the type for a non-text message. */\n text: string;\n }\n export type VcsProvider = "github" | "gitlab" | "azure-devops" | "bitbucket";\n /**\n * The provider object the event is about, as the provider names it. GitLab\n * calls a pull request a merge request, and a comment a `note`.\n */\n export type VcsEventKind =\n | "pull_request"\n | "merge_request"\n | "issue"\n | "issue_comment"\n | "note"\n | "pull_request_review"\n | "pipeline";\n /**\n * A webhook event from a connected code host. `action` is the provider\'s own\n * value: `opened`, `closed`, `synchronize`, `merge`, `created`, `commented`, or,\n * for a pipeline, its status such as `success` or `failed`. Fields a kind does\n * not carry are absent.\n */\n export interface VcsEvent {\n provider: VcsProvider;\n kind: VcsEventKind;\n action: string;\n /** `owner/name` on GitHub and GitLab, `workspace/repo_slug` on Bitbucket, the repository URL on Azure DevOps. */\n repo: string;\n /** The PR, merge request, or issue number. Absent for a pipeline outside a merge request. */\n number?: number;\n title?: string;\n body?: string | null;\n /** Login of the user behind the event. Set for pull requests, merge requests, and Azure DevOps comments. */\n author?: string;\n url?: string;\n merged?: boolean;\n changedFiles?: number;\n /** The review verdict, on a pull request review. */\n reviewState?: string;\n }\n export interface ToolCallCompletedEvent extends ToolCallEvent {\n result: unknown;\n durationMs: number;\n /** Native calls only: the harness reported the call as failed. */\n isError?: boolean;\n }\n export interface SwarmEventMap {\n "pre.task.create": {\n event: TaskCreateEvent;\n modify: TaskCreateModify;\n result: PreResult<TaskCreateModify>;\n };\n "pre.task.followUp": {\n event: TaskFollowUpEvent;\n modify: TaskFollowUpModify;\n result: PreResult<TaskFollowUpModify>;\n };\n "pre.task.steer": {\n event: TaskSteerEvent;\n modify: TaskSteerModify;\n result: PreResult<TaskSteerModify>;\n };\n "pre.slack.route": {\n event: SlackRouteEvent;\n modify: SlackRouteModify;\n result: PreResult<SlackRouteModify>;\n };\n "pre.chat.route": {\n event: ChatRouteEvent;\n modify: ChatRouteModify;\n result: PreResult<ChatRouteModify>;\n };\n "pre.heartbeat.remediate": {\n event: HeartbeatRemediateEvent;\n modify: HeartbeatRemediateModify;\n result: PreResult<HeartbeatRemediateModify>;\n };\n "pre.tool.call": {\n event: ToolCallEvent;\n modify: ToolCallModify;\n result: PreResult<ToolCallModify>;\n };\n "post.task.created": {\n event: TaskEvent;\n modify: never;\n result: void;\n };\n "post.task.blocked": {\n event: TaskBlockedEvent;\n modify: never;\n result: void;\n };\n "post.task.completed": {\n event: TaskCompletedEvent;\n modify: never;\n result: void;\n };\n "post.task.failed": {\n event: TaskFailedEvent;\n modify: never;\n result: void;\n };\n "post.task.cancelled": {\n event: TaskEvent;\n modify: never;\n result: void;\n };\n "post.task.superseded": {\n event: TaskSupersededEvent;\n modify: never;\n result: void;\n };\n "post.task.progress": {\n event: TaskProgressEvent;\n modify: never;\n result: void;\n };\n "post.slack.message": {\n event: SlackMessageEvent;\n modify: never;\n result: void;\n };\n "post.chat.message": {\n event: ChatMessageEvent;\n modify: never;\n result: void;\n };\n "post.approval.resolved": {\n event: ApprovalResolvedEvent;\n modify: never;\n result: void;\n };\n "post.task.budgetRefused": {\n event: TaskBudgetRefusedEvent;\n modify: never;\n result: void;\n };\n "post.email.received": {\n event: EmailReceivedEvent;\n modify: never;\n result: void;\n };\n "post.kapso.message": {\n event: KapsoMessageEvent;\n modify: never;\n result: void;\n };\n "post.vcs.event": {\n event: VcsEvent;\n modify: never;\n result: void;\n };\n "post.tool.call": {\n event: ToolCallCompletedEvent;\n modify: never;\n result: void;\n };\n }\n export interface ExtensionApi<\n M extends ExtensionManifest = ExtensionManifest & {\n runtime: "api";\n },\n > {\n on<E extends keyof SwarmEventMap>(\n event: E,\n handler: (\n event: SwarmEventMap[E]["event"],\n ctx: CtxFor<M>,\n ) => Promise<SwarmEventMap[E]["result"]> | SwarmEventMap[E]["result"],\n opts?: {\n priority?: number;\n },\n ): void;\n }\n export type SwarmExtension<\n M extends ExtensionManifest = ExtensionManifest & {\n runtime: "api";\n },\n > = (api: ExtensionApi<M>) => void;\n export { block, modify } from "./contract-runtime";\n}\n';
|
|
@@ -52,8 +52,13 @@ export interface ExtensionManifest {
|
|
|
52
52
|
};
|
|
53
53
|
homepage?: string;
|
|
54
54
|
author?: string;
|
|
55
|
+
/** Tool-call sources this extension's tool handlers receive. Default `["mcp"]`. */
|
|
56
|
+
toolSources?: readonly ToolSource[];
|
|
55
57
|
}
|
|
56
58
|
|
|
59
|
+
/** `mcp`: swarm MCP tools. `native`: harness built-ins reported by a worker shim. */
|
|
60
|
+
export type ToolSource = "mcp" | "native";
|
|
61
|
+
|
|
57
62
|
export interface HooksModule {
|
|
58
63
|
default: SwarmExtension;
|
|
59
64
|
config?: z.ZodTypeAny;
|
|
@@ -283,8 +288,16 @@ export interface HeartbeatRemediateModify {
|
|
|
283
288
|
|
|
284
289
|
export interface ToolCallEvent {
|
|
285
290
|
tool: string;
|
|
291
|
+
/** Secret-scrubbed on native calls: a secret reads as `[REDACTED:<name>]`. */
|
|
286
292
|
args: unknown;
|
|
287
293
|
requestInfo: RequestInfo;
|
|
294
|
+
/** Native calls only: the harness's own tool name, such as `Bash`. */
|
|
295
|
+
nativeTool?: string;
|
|
296
|
+
/** Native calls only: the harness's own argument shape, secret-scrubbed. */
|
|
297
|
+
rawArgs?: unknown;
|
|
298
|
+
/** Native calls only: the harness's call id, and its parent for a nested call. */
|
|
299
|
+
toolCallId?: string;
|
|
300
|
+
parentToolCallId?: string;
|
|
288
301
|
}
|
|
289
302
|
|
|
290
303
|
export interface ToolCallModify {
|
|
@@ -430,6 +443,8 @@ export interface VcsEvent {
|
|
|
430
443
|
export interface ToolCallCompletedEvent extends ToolCallEvent {
|
|
431
444
|
result: unknown;
|
|
432
445
|
durationMs: number;
|
|
446
|
+
/** Native calls only: the harness reported the call as failed. */
|
|
447
|
+
isError?: boolean;
|
|
433
448
|
}
|
|
434
449
|
|
|
435
450
|
export interface SwarmEventMap {
|
|
@@ -3,7 +3,7 @@ import { setAssetsEnabled } from "../be/extensions/assets";
|
|
|
3
3
|
import { insertExtensionRun, recordExtensionFailure, setExtensionState } from "../be/extensions/db";
|
|
4
4
|
import { grantLeadEquivalence, revokeLeadEquivalence } from "../rbac/elevated-agents";
|
|
5
5
|
import { scrubSecrets } from "../utils/secret-scrubber";
|
|
6
|
-
import type { SwarmEventMap } from "./contract";
|
|
6
|
+
import type { SwarmEventMap, ToolSource } from "./contract";
|
|
7
7
|
import { buildCtx } from "./ctx";
|
|
8
8
|
import type { ExtensionHandler, LoadedExtension } from "./loader";
|
|
9
9
|
|
|
@@ -91,9 +91,19 @@ function positiveEnv(name: string, fallback: number): number {
|
|
|
91
91
|
return Number.isFinite(value) && value > 0 ? Math.floor(value) : fallback;
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
|
|
94
|
+
/** The tool source of a tool event, or undefined for every other event. */
|
|
95
|
+
function toolSourceOf(event: keyof SwarmEventMap, payload: unknown): ToolSource | undefined {
|
|
96
|
+
if (event !== "pre.tool.call" && event !== "post.tool.call") return undefined;
|
|
97
|
+
return stringField(payload, "requestInfo", "callOrigin") === "native" ? "native" : "mcp";
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function handlersFor(event: keyof SwarmEventMap, payload: unknown, opts?: DispatchOptions) {
|
|
101
|
+
const toolSource = toolSourceOf(event, payload);
|
|
95
102
|
return [...registry.values()]
|
|
96
103
|
.filter((loaded) => loaded.record.id !== opts?.skipExtensionId)
|
|
104
|
+
.filter(
|
|
105
|
+
(loaded) => !toolSource || (loaded.manifest.toolSources ?? ["mcp"]).includes(toolSource),
|
|
106
|
+
)
|
|
97
107
|
.flatMap((loaded) =>
|
|
98
108
|
loaded.handlers
|
|
99
109
|
.filter((handler) => handler.event === event)
|
|
@@ -392,7 +402,7 @@ export async function dispatchPre<E extends PreEventName>(
|
|
|
392
402
|
let currentPayload: Record<string, unknown> = { ...payload };
|
|
393
403
|
const mergedData: Record<string, unknown> = {};
|
|
394
404
|
let modified = false;
|
|
395
|
-
for (const { loaded, handler } of handlersFor(event, opts)) {
|
|
405
|
+
for (const { loaded, handler } of handlersFor(event, payload, opts)) {
|
|
396
406
|
if (!isRegistered(loaded.record.id)) continue;
|
|
397
407
|
const run = await runHandler(loaded, handler, event, currentPayload);
|
|
398
408
|
if (!run.ok) continue;
|
|
@@ -498,7 +508,7 @@ export async function dispatchPost<E extends PostEventName>(
|
|
|
498
508
|
payload: SwarmEventMap[E]["event"],
|
|
499
509
|
opts?: DispatchOptions,
|
|
500
510
|
): Promise<void> {
|
|
501
|
-
for (const { loaded, handler } of handlersFor(event, opts)) {
|
|
511
|
+
for (const { loaded, handler } of handlersFor(event, payload, opts)) {
|
|
502
512
|
if (!isRegistered(loaded.record.id)) continue;
|
|
503
513
|
const run = await runHandler(loaded, handler, event, payload);
|
|
504
514
|
if (run.ok) {
|
package/src/github/handlers.ts
CHANGED
|
@@ -198,6 +198,44 @@ async function resolveGitHubSender(
|
|
|
198
198
|
return undefined;
|
|
199
199
|
}
|
|
200
200
|
|
|
201
|
+
const TRUSTED_AUTHOR_ASSOCIATIONS = new Set(["OWNER", "MEMBER", "COLLABORATOR"]);
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Whether a sender may open a lead task through content that any account able
|
|
205
|
+
* to read the repo can post (mentions, comments, reviews). Accepted: a linked
|
|
206
|
+
* swarm user, this bot, a login listed in GITHUB_ALLOWED_SENDERS
|
|
207
|
+
* (comma-separated), or the content's author when GitHub reports them as an
|
|
208
|
+
* owner, org member or collaborator. Assignment, label and review-request
|
|
209
|
+
* events already need write or triage access on GitHub, so they skip this.
|
|
210
|
+
*/
|
|
211
|
+
function isTrustedGitHubSender(
|
|
212
|
+
login: string,
|
|
213
|
+
requestedByUserId: string | undefined,
|
|
214
|
+
content: { user: { login: string }; author_association?: string },
|
|
215
|
+
): boolean {
|
|
216
|
+
if (requestedByUserId || isBotAssignee(login)) return true;
|
|
217
|
+
const normalized = login.toLowerCase();
|
|
218
|
+
const allowed = (process.env.GITHUB_ALLOWED_SENDERS ?? "")
|
|
219
|
+
.split(",")
|
|
220
|
+
.map((name) => name.trim().toLowerCase())
|
|
221
|
+
.filter(Boolean);
|
|
222
|
+
if (allowed.includes(normalized)) return true;
|
|
223
|
+
// author_association describes the content's author, so it vouches only when the sender wrote it.
|
|
224
|
+
return (
|
|
225
|
+
content.user.login.toLowerCase() === normalized &&
|
|
226
|
+
TRUSTED_AUTHOR_ASSOCIATIONS.has(content.author_association ?? "")
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const UNTRUSTED_SENDER_REASON =
|
|
231
|
+
"sender is not a linked user, an allowed sender, or a repo owner, member or collaborator";
|
|
232
|
+
|
|
233
|
+
function logUntrustedSender(eventType: string, login: string, repo: string, number: number) {
|
|
234
|
+
console.log(
|
|
235
|
+
`[GitHub] Skipped ${eventType} by ${login} on ${repo}#${number}: ${UNTRUSTED_SENDER_REASON}`,
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
|
|
201
239
|
/**
|
|
202
240
|
* Handle pull_request events (opened, edited)
|
|
203
241
|
*/
|
|
@@ -538,6 +576,11 @@ export async function handlePullRequest(
|
|
|
538
576
|
return { created: false };
|
|
539
577
|
}
|
|
540
578
|
|
|
579
|
+
if (!isTrustedGitHubSender(sender.login, requestedByUserId, pr)) {
|
|
580
|
+
logUntrustedSender(`pull_request.${action}`, sender.login, repository.full_name, pr.number);
|
|
581
|
+
return { created: false };
|
|
582
|
+
}
|
|
583
|
+
|
|
541
584
|
// Deduplicate
|
|
542
585
|
const eventKey = `pr:${repository.full_name}:${pr.number}:${action}`;
|
|
543
586
|
if (isDuplicate(eventKey)) {
|
|
@@ -799,6 +842,11 @@ export async function handleIssue(
|
|
|
799
842
|
return { created: false };
|
|
800
843
|
}
|
|
801
844
|
|
|
845
|
+
if (!isTrustedGitHubSender(sender.login, requestedByUserId, issue)) {
|
|
846
|
+
logUntrustedSender(`issues.${action}`, sender.login, repository.full_name, issue.number);
|
|
847
|
+
return { created: false };
|
|
848
|
+
}
|
|
849
|
+
|
|
802
850
|
// Deduplicate
|
|
803
851
|
const eventKey = `issue:${repository.full_name}:${issue.number}:${action}`;
|
|
804
852
|
if (isDuplicate(eventKey)) {
|
|
@@ -896,6 +944,10 @@ export async function handleComment(
|
|
|
896
944
|
return skip("no bot mention");
|
|
897
945
|
}
|
|
898
946
|
|
|
947
|
+
if (!isTrustedGitHubSender(sender.login, requestedByUserId, comment)) {
|
|
948
|
+
return skip(UNTRUSTED_SENDER_REASON);
|
|
949
|
+
}
|
|
950
|
+
|
|
899
951
|
// Deduplicate
|
|
900
952
|
const eventKey = `comment:${repository.full_name}:${comment.id}`;
|
|
901
953
|
if (isDuplicate(eventKey)) {
|
|
@@ -1317,6 +1369,11 @@ export async function handlePullRequestReview(
|
|
|
1317
1369
|
return { created: false };
|
|
1318
1370
|
}
|
|
1319
1371
|
|
|
1372
|
+
if (!isTrustedGitHubSender(sender.login, requestedByUserId, review)) {
|
|
1373
|
+
logUntrustedSender("pull_request_review", sender.login, repository.full_name, pr.number);
|
|
1374
|
+
return { created: false };
|
|
1375
|
+
}
|
|
1376
|
+
|
|
1320
1377
|
// Deduplicate before making any API calls
|
|
1321
1378
|
const eventKey = `pr-review:${repository.full_name}:${pr.number}:${review.id}`;
|
|
1322
1379
|
if (isDuplicate(eventKey)) {
|
package/src/github/types.ts
CHANGED
|
@@ -13,6 +13,7 @@ export interface PullRequestEvent extends GitHubWebhookEvent {
|
|
|
13
13
|
body: string | null;
|
|
14
14
|
html_url: string;
|
|
15
15
|
user: { login: string };
|
|
16
|
+
author_association?: string;
|
|
16
17
|
head: { ref: string; sha: string };
|
|
17
18
|
base: { ref: string };
|
|
18
19
|
merged: boolean;
|
|
@@ -30,6 +31,7 @@ export interface IssueEvent extends GitHubWebhookEvent {
|
|
|
30
31
|
body: string | null;
|
|
31
32
|
html_url: string;
|
|
32
33
|
user: { login: string };
|
|
34
|
+
author_association?: string;
|
|
33
35
|
};
|
|
34
36
|
label?: { id: number; name: string; color: string }; // Added for labeled/unlabeled events
|
|
35
37
|
}
|
|
@@ -41,6 +43,7 @@ export interface CommentEvent extends GitHubWebhookEvent {
|
|
|
41
43
|
body: string;
|
|
42
44
|
html_url: string;
|
|
43
45
|
user: { login: string };
|
|
46
|
+
author_association?: string;
|
|
44
47
|
};
|
|
45
48
|
issue?: { number: number; title: string; html_url: string };
|
|
46
49
|
pull_request?: { number: number; title: string; html_url: string };
|
|
@@ -55,6 +58,7 @@ export interface PullRequestReviewEvent extends GitHubWebhookEvent {
|
|
|
55
58
|
state: "approved" | "changes_requested" | "commented" | "dismissed";
|
|
56
59
|
html_url: string;
|
|
57
60
|
user: { login: string };
|
|
61
|
+
author_association?: string;
|
|
58
62
|
submitted_at: string;
|
|
59
63
|
commit_id?: string;
|
|
60
64
|
};
|
package/src/http/all-routes.ts
CHANGED
|
@@ -36,6 +36,7 @@ import "./integrations";
|
|
|
36
36
|
import "./kv";
|
|
37
37
|
import "./memory";
|
|
38
38
|
import "./metrics";
|
|
39
|
+
import "./model-groups";
|
|
39
40
|
import "./model-profiles";
|
|
40
41
|
import "./models-catalog";
|
|
41
42
|
import "./oauth-locks";
|
|
@@ -72,6 +73,7 @@ import "./status";
|
|
|
72
73
|
import "./tasks";
|
|
73
74
|
import "./task-templates";
|
|
74
75
|
import "./telemetry-ui";
|
|
76
|
+
import "./tool-hooks";
|
|
75
77
|
import "./trackers/jira";
|
|
76
78
|
import "./trackers/linear";
|
|
77
79
|
import "./ranking";
|
|
@@ -42,7 +42,7 @@ import {
|
|
|
42
42
|
dispatchApprovalNotifications,
|
|
43
43
|
} from "../workflows/approval-notifications";
|
|
44
44
|
import { workflowEventBus } from "../workflows/event-bus";
|
|
45
|
-
import { ensureConfigAdmin, runConfigWriteSideEffects } from "./config";
|
|
45
|
+
import { ensureConfigAdmin, ensureHumanOnlyConfigWrite, runConfigWriteSideEffects } from "./config";
|
|
46
46
|
import { type ApprovalResponder, approvalResponder, responderKey } from "./person-responder";
|
|
47
47
|
import { agentFirstPrincipal, authUserId } from "./request-principal";
|
|
48
48
|
import { bodyTask, route } from "./route-def";
|
|
@@ -623,6 +623,10 @@ export async function handleApprovalRequests(
|
|
|
623
623
|
}
|
|
624
624
|
if ([...configAnswers.values()].some(({ answer }) => answer.action === "set")) {
|
|
625
625
|
if (!(await ensureConfigAdmin(req, res, "config.write.any"))) return true;
|
|
626
|
+
for (const { question, answer } of configAnswers.values()) {
|
|
627
|
+
if (answer.action !== "set") continue;
|
|
628
|
+
if (!(await ensureHumanOnlyConfigWrite(req, res, question.config.key))) return true;
|
|
629
|
+
}
|
|
626
630
|
// Admission only checked `approval.respond`; `ensureConfigAdmin` passes
|
|
627
631
|
// every user, so check the config write grant here as PUT /api/config would.
|
|
628
632
|
const userId = authUserId(getRequestAuth(req));
|
package/src/http/auth.ts
CHANGED
|
@@ -69,5 +69,7 @@ export async function resolveHttpRequestAuth(
|
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
function isActiveUser(user: User | null): user is User {
|
|
72
|
-
|
|
72
|
+
// A merge source (mergedIntoUserId set) is on its way out: the merge route
|
|
73
|
+
// revoked its tokens, and any credential that still names it is refused.
|
|
74
|
+
return !!user && user.status === "active" && !user.mergedIntoUserId;
|
|
73
75
|
}
|