@desplega.ai/agent-swarm 2.7.9 → 2.8.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-t949vbbp.js +15 -0
- package/dist/{actions-g563mbn2.js → actions-7e9czc7s.js} +19 -19
- package/dist/{amp-adapter-q61w05eb.js → amp-adapter-gv6cbb7d.js} +2 -3
- package/dist/app-b9fbkp9v.js +20 -0
- package/dist/{assistant-p477rjwj.js → assistant-wjb7v4c7.js} +22 -22
- package/dist/{boot-args-schema-h4qj462e.js → boot-args-schema-2t37e0fe.js} +1 -1
- package/dist/{boot-reembed-n1ehfbsw.js → boot-reembed-a35nkyr1.js} +1 -1
- package/dist/{boot-reembed-qw4mc0pt.js → boot-reembed-gka3zas7.js} +1 -1
- package/dist/{boot-scrub-sweep-9w9jp4sm.js → boot-scrub-sweep-65sdnp6c.js} +3 -3
- package/dist/{boot-seeds-qdaf3sdy.js → boot-seeds-x42tzytw.js} +4 -5
- package/dist/{claude-adapter-348p5hx9.js → claude-adapter-v221b2fd.js} +7 -8
- package/dist/{claude-managed-adapter-h74d06yz.js → claude-managed-adapter-29eq09wd.js} +2 -2
- package/dist/{claude-managed-setup-7787fxtp.js → claude-managed-setup-9m6450zk.js} +2 -2
- package/dist/{claude-sdk-session-hbszbt8a.js → claude-sdk-session-0q0ptaba.js} +9066 -8818
- package/dist/{cli-n5yexkdg.js → cli-0b4zam62.js} +1 -0
- package/dist/{cli-21159vea.js → cli-0jzra9ad.js} +2 -2
- package/dist/{cli-eqtfgfr6.js → cli-2gxeg5gr.js} +1 -1
- package/dist/{cli-k70e3x9e.js → cli-2wnq8jkz.js} +9 -9
- package/dist/{cli-cvs2r2vq.js → cli-2zp0et3v.js} +59 -6
- package/dist/{cli-650zv9q9.js → cli-334z18y3.js} +4 -4
- package/dist/{cli-12xyjhws.js → cli-3rkdne1h.js} +2 -2
- package/dist/{cli-2a8py3sx.js → cli-4txa0ter.js} +5 -7
- package/dist/{cli-jc1g9ndz.js → cli-5j88qqa8.js} +10 -5
- package/dist/{cli-xfjrc279.js → cli-5mrq3ake.js} +48 -14
- package/dist/{cli-v3cf1ts9.js → cli-6t09sdhy.js} +3 -3
- package/dist/{cli-qzt90yze.js → cli-6wxjceza.js} +8 -8
- package/dist/{cli-9aezs55w.js → cli-7b8sbmag.js} +8 -8
- package/dist/{cli-3xj33nrx.js → cli-7cp6aa1q.js} +10 -3
- package/dist/{cli-jfx48xrj.js → cli-7p1kvkck.js} +6 -6
- package/dist/{cli-b932gexn.js → cli-8aes17e4.js} +2 -2
- package/dist/{cli-3tqcamp6.js → cli-8fknbnhw.js} +14 -13
- package/dist/{cli-587857ys.js → cli-8kzasymh.js} +3 -3
- package/dist/{cli-sgs5k6yd.js → cli-a7wvp2km.js} +1 -1
- package/dist/{cli-varqt4d1.js → cli-abejgen1.js} +69 -22
- package/dist/{cli-rwymrnaz.js → cli-bsywb58a.js} +8 -8
- package/dist/{cli-btc9cb4c.js → cli-c55z5chy.js} +4 -6
- package/dist/{cli-ms5m5r1y.js → cli-deefvewm.js} +1 -1
- package/dist/{cli-p17970qv.js → cli-ee0b971j.js} +3 -3
- package/dist/cli-f3vq58d2.js +242 -0
- package/dist/{cli-3xcwp3z8.js → cli-ffhtssbp.js} +2 -2
- package/dist/{cli-hwprv9e4.js → cli-g70vxtjh.js} +2 -2
- package/dist/{cli-4t0fmf3z.js → cli-gxkx0zzp.js} +1 -1
- package/dist/{cli-neyag5p6.js → cli-h38x262p.js} +3365 -429
- package/dist/{cli-2ccpqyyf.js → cli-j790gp2w.js} +105 -22
- package/dist/{cli-f2zenhja.js → cli-kc7v1nfv.js} +1 -1
- package/dist/{cli-vxh6acp7.js → cli-m23zjcy2.js} +10 -10
- package/dist/{cli-y8nbefpb.js → cli-m28atx8q.js} +12 -10
- package/dist/{cli-serm8zrx.js → cli-m4dqmnbp.js} +1 -1
- package/dist/{cli-ybjdc978.js → cli-mrt48bx7.js} +7 -4
- package/dist/{cli-y5rbvxhc.js → cli-n515ex5z.js} +14 -14
- package/dist/{cli-ypff1qwp.js → cli-n9ftpys4.js} +7 -7
- package/dist/{cli-605nn699.js → cli-p1bq50aa.js} +894 -226
- package/dist/{cli-qkdmz8c8.js → cli-p1w18yhx.js} +1 -1
- package/dist/{cli-xk879m3k.js → cli-p2gfst4m.js} +52 -43
- package/dist/{cli-sya22y84.js → cli-pasjcnmj.js} +12 -12
- package/dist/{cli-0whpms1z.js → cli-qa4wdgsy.js} +5 -5
- package/dist/{cli-ejkvvqbe.js → cli-qfedvmcr.js} +50 -24
- package/dist/{cli-tqq0hspb.js → cli-qmqk2yc2.js} +1 -1
- package/dist/{cli-qmd3mse0.js → cli-qsnnd04k.js} +1 -1
- package/dist/{cli-agyaeef4.js → cli-qwca7s44.js} +3 -3
- package/dist/{cli-fayav105.js → cli-rfywm85n.js} +724 -792
- package/dist/{cli-zgv8gxgs.js → cli-rmmpt0wm.js} +6 -6
- package/dist/{cli-hae9j8sv.js → cli-rzsy6nc6.js} +12 -8
- package/dist/{cli-btf6fw39.js → cli-s7t6p9my.js} +1 -1
- package/dist/{cli-cseh6f8w.js → cli-sdtt3men.js} +1 -1
- package/dist/{cli-9r5gtwjr.js → cli-tk7cjj8h.js} +197 -2
- package/dist/{cli-q26b9wre.js → cli-tph5wt3y.js} +4 -4
- package/dist/{cli-gce09r66.js → cli-tqegb8eq.js} +3 -3
- package/dist/{cli-kf3pxxdg.js → cli-v1dv1r37.js} +1 -1
- package/dist/{cli-09kmfkmq.js → cli-wcg8x116.js} +1 -1
- package/dist/{cli-mnrkgg60.js → cli-wk18cm92.js} +5 -5
- package/dist/{cli-p0m0p34z.js → cli-x1wa213s.js} +3 -3
- package/dist/{cli-jrp1dt73.js → cli-xzm9vcfg.js} +1 -1
- package/dist/{cli-715t1gx6.js → cli-y97qxcfx.js} +9 -9
- package/dist/{cli-bc779n4v.js → cli-yq3zak69.js} +1 -1
- package/dist/cli.js +17 -17
- package/dist/{codex-adapter-ysq6bzha.js → codex-adapter-30j9bpzd.js} +5 -6
- package/dist/{codex-hook-fac6175r.js → codex-hook-h3vk6xzr.js} +1 -1
- package/dist/{codex-session-runner-qakzfx93.js → codex-session-runner-8vp57v8w.js} +5 -6
- package/dist/{commands-rs7hkv9r.js → commands-bngnz9g7.js} +3 -3
- package/dist/{controller-r5x9bg6e.js → controller-hxx8wwy1.js} +2 -2
- package/dist/{controllers-connect-498hrxvk.js → controllers-connect-e2b4gyxc.js} +20 -20
- package/dist/{cursor-adapter-d46qszer.js → cursor-adapter-n5nc3mfe.js} +1 -2
- package/dist/{db-s13dqhr6.js → db-bgm7vkc0.js} +3 -3
- package/dist/{db-pm96nhdb.js → db-c6np41ca.js} +12 -2
- package/dist/{devin-adapter-z46ep5ph.js → devin-adapter-xedz98zv.js} +1 -1
- package/dist/{dispatcher-j3h81t7m.js → dispatcher-jnybck15.js} +18 -18
- package/dist/{dsh-adapter-rw0d5rc4.js → dsh-adapter-nrhbrjz8.js} +1 -2
- package/dist/{easter-egg-3d-qtgfxgze.js → easter-egg-3d-533knw22.js} +1 -1
- package/dist/{embedding-space-xh8p4q4x.js → embedding-space-crsm2zp0.js} +6 -6
- package/dist/{embeddings-wp745m91.js → embeddings-e7z3f27f.js} +1 -1
- package/dist/{execute-2fzb9z74.js → execute-b3mrb1mv.js} +1 -1
- package/dist/{external-channel-ys21h3sy.js → external-channel-m77wf5z3.js} +2 -2
- package/dist/{fx-adapter-vz0b9z3g.js → fx-adapter-b6w0kf56.js} +7 -8
- package/dist/{google-generative-ai-ytpgncx9.js → google-generative-ai-h7s3e9kk.js} +1 -1
- package/dist/{google-vertex-tqhze5j7.js → google-vertex-fhxaafzw.js} +1 -1
- package/dist/{grok-adapter-spea7zkj.js → grok-adapter-4sqtebdk.js} +7 -8
- package/dist/handlers-kdjcyzdj.js +32 -0
- package/dist/heartbeat-xgb036sx.js +43 -0
- package/dist/{hook-amcj4s10.js → hook-5h02c9ga.js} +6 -6
- package/dist/{hook-bc6n49qn.js → hook-xsk1jbha.js} +5 -5
- package/dist/{http-7374brv5.js → http-txe7qhvn.js} +448 -165
- package/dist/{index-pxn30mse.js → index-0eny15vj.js} +8 -8
- package/dist/{index-5a9jtqde.js → index-0rvk3vd4.js} +46 -46
- package/dist/{index-fvzke5kx.js → index-1qw6f2dc.js} +10 -10
- package/dist/{index-q5cmtbz5.js → index-4a0670yh.js} +15939 -14244
- package/dist/index-835xdgnm.js +33 -0
- package/dist/index-d469300x.js +37 -0
- package/dist/{index-h7f61sy9.js → index-e5pfbsys.js} +3 -3
- package/dist/{index-hsad2t3r.js → index-m5gx1xd6.js} +38 -38
- package/dist/{index-5fx3b3kw.js → index-rvccek1w.js} +9 -9
- package/dist/index-rzqwp11g.js +32 -0
- package/dist/{index-w4m9z29z.js → index-tvfafeyy.js} +1 -1
- package/dist/{index-c9y31ytf.js → index-vk63emp7.js} +979 -35
- package/dist/{index-514d9pf6.js → index-w7em4ktq.js} +8 -8
- package/dist/{index-p4hjwbvw.js → index-ysvbhg5m.js} +1 -1
- package/dist/{keepalive-wy29kbrg.js → keepalive-4zsrce78.js} +3 -3
- package/dist/lead-yqt47dkr.js +70 -0
- package/dist/{maintenance-h2ds9w6c.js → maintenance-86jvartk.js} +1 -1
- package/dist/{oauth-refresh-sweep-q7mtbyp3.js → oauth-refresh-sweep-j52kg9pr.js} +2 -2
- package/dist/{onboard-vw8r2fdw.js → onboard-c2aj5p8q.js} +3 -3
- package/dist/{opencode-adapter-mtb0953j.js → opencode-adapter-dsagkhtw.js} +5 -6
- package/dist/{otel-impl-j42czw3r.js → otel-impl-yyy203z8.js} +1 -1
- package/dist/{pi-mono-adapter-zk8pg9jr.js → pi-mono-adapter-546cd1cc.js} +9 -9
- package/dist/{pricing-refresh-x7nhv23d.js → pricing-refresh-1rgzqyzz.js} +2 -3
- package/dist/{rbac-roles-9044425x.js → rbac-roles-e70xfeyj.js} +4 -6
- package/dist/{rbac-roles-bzvee6cf.js → rbac-roles-q89qe8er.js} +3 -3
- package/dist/{registry-hpjfmcfz.js → registry-32b1mft6.js} +1 -1
- package/dist/{render-v2-t7bn4skz.js → render-v2-k6tt107q.js} +9 -4
- package/dist/{resume-x94gemep.js → resume-cnnrjfxa.js} +6 -6
- package/dist/{runtime-breq6fmv.js → runtime-1hv06jsn.js} +1 -1
- package/dist/{session-access-q7dmqjvt.js → session-access-xkxkjw3n.js} +4 -4
- package/dist/{session-source-backfill-440ysamr.js → session-source-backfill-1d5pdwww.js} +2 -2
- package/dist/{setup-07n4727s.js → setup-se8q7gkc.js} +1 -1
- package/dist/{virtual-modules-z5h6mcyf.js → virtual-modules-gazyapte.js} +3 -3
- package/dist/{work-objects-pnq5y534.js → work-objects-1kxnbzy5.js} +22 -22
- package/dist/{worker-follow-up-7z1gfkr8.js → worker-follow-up-zqm8apt4.js} +18 -18
- package/dist/worker-j6xxtq7p.js +70 -0
- package/openapi.json +334 -7
- package/package.json +4 -4
- package/src/apps/catalog.generated.json +55 -0
- package/src/apps/definition.ts +11 -0
- package/src/apps/page-validator.ts +19 -0
- package/src/apps/store.ts +28 -8
- package/src/assets/key.ts +77 -4
- package/src/be/db/model-profiles.ts +147 -38
- package/src/be/db/session-labels.ts +57 -0
- package/src/be/db/session-tree.ts +51 -7
- package/src/be/db/slack-trees.ts +146 -0
- package/src/be/db/tasks/read.ts +107 -8
- package/src/be/db/workflow-run-definitions.ts +117 -0
- package/src/be/db-client.ts +8 -2
- package/src/be/db.ts +119 -87
- package/src/be/event-loop-lag.ts +146 -0
- package/src/be/mcp-overflow-sweep.ts +2 -1
- package/src/be/memory/constants.ts +14 -1
- package/src/be/memory/key-paths.ts +8 -0
- package/src/be/memory/providers/sqlite-store.ts +199 -18
- package/src/be/memory/task-learning.ts +79 -14
- package/src/be/memory/types.ts +24 -1
- package/src/be/migrations/278_slack_render_v2_reconcile.sql +108 -0
- package/src/be/migrations/279_backfill_learning_expiry.sql +15 -0
- package/src/be/migrations/281_model_profiles_pr2.sql +28 -0
- package/src/be/migrations/283_workflow_run_definitions.sql +14 -0
- package/src/be/model-profile-check.ts +284 -0
- package/src/be/model-tier-resolution.ts +112 -12
- package/src/be/multi-runtime.ts +27 -0
- package/src/be/runtime-pools/routing.ts +52 -4
- package/src/be/scripts/typecheck.ts +1 -0
- package/src/be/seed-scripts/catalog/dreaming-learnings.ts +552 -0
- package/src/be/seed-scripts/catalog/dreaming-memtax-create.ts +389 -14
- package/src/be/seed-scripts/catalog/dreaming-memtax.ts +6 -3
- package/src/be/seed-scripts/index.ts +9 -0
- package/src/be/steering.ts +8 -2
- package/src/be/swarm-config-guard.ts +2 -0
- package/src/commands/context-preamble.ts +258 -0
- package/src/commands/onboard/agent-fs-version.ts +1 -1
- package/src/commands/runner.ts +32 -1
- package/src/extensions/catalog.generated.json +3 -3
- package/src/fs/provider.ts +17 -3
- package/src/heartbeat/heartbeat.ts +17 -5
- package/src/heartbeat/index.ts +1 -0
- package/src/http/agents.ts +56 -4
- package/src/http/apps.ts +3 -1
- package/src/http/config.ts +2 -6
- package/src/http/core.ts +9 -3
- package/src/http/index.ts +12 -9
- package/src/http/memory.ts +9 -4
- package/src/http/model-profiles.ts +58 -10
- package/src/http/poll.ts +36 -3
- package/src/http/schedules.ts +42 -3
- package/src/http/sessions.ts +16 -3
- package/src/http/tasks.ts +37 -12
- package/src/http/utils.ts +18 -0
- package/src/http/webhooks.ts +48 -0
- package/src/http/workflows.ts +15 -2
- package/src/integrations/chat-sdk/commands.ts +167 -31
- package/src/integrations/chat-sdk/inbound.ts +10 -8
- package/src/integrations/chat-sdk/message-text.ts +117 -0
- package/src/prompts/session-templates.ts +1 -1
- package/src/providers/acp-targets.ts +11 -6
- package/src/providers/amp-adapter.ts +1 -1
- package/src/providers/claude-sdk-session.ts +132 -23
- package/src/providers/codex-skill-resolver.ts +10 -4
- package/src/providers/cursor-adapter.ts +1 -1
- package/src/providers/devin-skill-resolver.ts +5 -5
- package/src/providers/dsh-adapter.ts +1 -1
- package/src/scheduler/schedule-task.ts +1 -0
- package/src/scheduler/scheduler.ts +4 -1
- package/src/scripts-runtime/executors/quickjs-runner.ts +2 -0
- package/src/scripts-runtime/executors/quickjs-structured-clone.ts +180 -0
- package/src/scripts-runtime/quickjs-compat.ts +0 -1
- package/src/scripts-runtime/sdk-allowlist.ts +1 -0
- package/src/scripts-runtime/swarm-sdk.ts +18 -1
- package/src/scripts-runtime/types/stdlib.d.ts +1 -0
- package/src/scripts-runtime/types/swarm-sdk.d.ts +1 -0
- package/src/server.ts +2 -0
- package/src/slack/app.ts +425 -10
- package/src/slack/handlers.ts +9 -2
- package/src/slack/inbound-dispatch.ts +18 -1
- package/src/slack/index.ts +7 -1
- package/src/slack/lifecycle-lock.ts +29 -0
- package/src/slack/render-v2.ts +424 -212
- package/src/slack/socket-fence.ts +64 -0
- package/src/slack/watcher.ts +42 -8
- package/src/slack/workspace-guard.ts +345 -0
- package/src/tasks/task-terminal-effects.ts +4 -0
- package/src/tasks/worker-follow-up.ts +102 -2
- package/src/tests/acp-adapter.test.ts +82 -0
- package/src/tests/apps-icon.test.ts +120 -0
- package/src/tests/apps-schema-form.test.ts +151 -0
- package/src/tests/chained-task-follow-up.test.ts +248 -0
- package/src/tests/chat-sdk-commands.test.ts +359 -2
- package/src/tests/chat-sdk-inbound.test.ts +20 -0
- package/src/tests/chat-sdk-slack.test.ts +189 -1
- package/src/tests/check-pr-body.test.ts +40 -0
- package/src/tests/claude-sdk-lifecycle.test.ts +216 -1
- package/src/tests/claude-sdk-process.fixture.ts +57 -0
- package/src/tests/codex-skill-resolver.test.ts +31 -0
- package/src/tests/credentials-allowlist.test.ts +470 -0
- package/src/tests/db-client-busy-retry.test.ts +69 -18
- package/src/tests/db-client.test.ts +26 -1
- package/src/tests/db-task-read-contract.test.ts +7 -0
- package/src/tests/db-task-write-contract.test.ts +6 -0
- package/src/tests/deferred-wake-follow-up.test.ts +47 -0
- package/src/tests/docs-index-footprint.test.js +3 -3
- package/src/tests/dreaming-learnings.test.ts +1395 -0
- package/src/tests/dsh-adapter.test.ts +1 -1
- package/src/tests/event-loop-lag.test.ts +184 -0
- package/src/tests/explicit-model-validation.test.ts +2 -0
- package/src/tests/extensions-example-comms-adherence-gate.test.ts +115 -0
- package/src/tests/fs-provider.test.ts +42 -0
- package/src/tests/github-webhook-early-ack.test.ts +144 -0
- package/src/tests/heartbeat.test.ts +28 -1
- package/src/tests/http-api-integration.test.ts +2 -0
- package/src/tests/http-log-scrubbing.test.ts +68 -2
- package/src/tests/human-free-reclassify.test.ts +5 -1
- package/src/tests/kv-storage.test.ts +92 -1
- package/src/tests/list-endpoint-slimming.test.ts +17 -0
- package/src/tests/memory-key-paths.test.ts +57 -0
- package/src/tests/memory-retrieval-purge.test.ts +19 -0
- package/src/tests/migration-283-workflow-run-definitions.test.ts +69 -0
- package/src/tests/model-profile-check.test.ts +387 -0
- package/src/tests/model-profiles-api.test.ts +528 -1
- package/src/tests/profile-claim.test.ts +415 -3
- package/src/tests/profile-tier-alias.test.ts +382 -0
- package/src/tests/quickjs-compat.test.ts +1 -1
- package/src/tests/runner-context-preamble.test.ts +552 -0
- package/src/tests/schedule-profile.test.ts +359 -0
- package/src/tests/script-connections.test.ts +9 -0
- package/src/tests/script-executor-conformance.test.ts +188 -0
- package/src/tests/script-per-script-executor.test.ts +1 -0
- package/src/tests/scripts-sdk-bridge-tool-failure.test.ts +141 -0
- package/src/tests/seed-scripts.test.ts +2 -2
- package/src/tests/sessions-tree.test.ts +133 -2
- package/src/tests/slack-app-icon.test.ts +4 -0
- package/src/tests/slack-dm-implicit-mention.test.ts +236 -0
- package/src/tests/slack-file-tools-attachments.test.ts +1 -0
- package/src/tests/slack-inbound-receipts.test.ts +22 -2
- package/src/tests/slack-read-boundaries.test.ts +4 -3
- package/src/tests/slack-render-v2-query-plans.test.ts +262 -3
- package/src/tests/slack-render-v2-reconcile.test.ts +201 -0
- package/src/tests/slack-socket-ack.test.ts +16 -1
- package/src/tests/slack-socket-watchdog.test.ts +748 -0
- package/src/tests/slack-workspace-guard.test.ts +905 -0
- package/src/tests/steering-core.test.ts +40 -0
- package/src/tests/store-progress-learning.test.ts +605 -20
- package/src/tests/tool-annotations.test.ts +1 -1
- package/src/tests/vcs-identity-inheritance.test.ts +85 -0
- package/src/tests/workflow-convergence.test.ts +46 -40
- package/src/tests/workflow-definition-pinning-recovery.test.ts +552 -0
- package/src/tests/workflow-definition-pinning.test.ts +645 -0
- package/src/tests/workflow-executors.test.ts +16 -7
- package/src/tests/workflow-foreach.test.ts +43 -20
- package/src/tests/workflow-notify-slack-ready.test.ts +161 -0
- package/src/tests/workflow-profile.test.ts +328 -0
- package/src/tools/app-upsert.ts +1 -1
- package/src/tools/memory-edit.ts +2 -1
- package/src/tools/model-profiles/check-model-profile.ts +63 -0
- package/src/tools/schedules/create-schedule.ts +45 -4
- package/src/tools/schedules/patch-schedule.ts +50 -4
- package/src/tools/schedules/update-schedule.ts +50 -4
- package/src/tools/send-task.ts +17 -2
- package/src/tools/store-progress.ts +15 -3
- package/src/tools/task-action.ts +9 -1
- package/src/tools/templates.ts +13 -0
- package/src/tools/tool-config.ts +2 -1
- package/src/tools/utils.ts +77 -11
- package/src/tools/workflows/create-workflow.ts +1 -1
- package/src/tools/workflows/retry-workflow-run.ts +1 -1
- package/src/tools/workflows/update-workflow.ts +10 -1
- package/src/types.ts +56 -1
- package/src/utils/credentials.ts +89 -12
- package/src/workflows/engine.ts +10 -1
- package/src/workflows/executors/agent-task.ts +21 -2
- package/src/workflows/executors/foreach.ts +4 -1
- package/src/workflows/executors/notify.ts +62 -6
- package/src/workflows/executors/sub-workflow.ts +1 -1
- package/src/workflows/executors/swarm-script.ts +4 -1
- package/src/workflows/foreach-driver.ts +8 -5
- package/src/workflows/limits.ts +2 -1
- package/src/workflows/model-validation.ts +27 -2
- package/src/workflows/patch-definition.ts +3 -1
- package/src/workflows/recovery.ts +6 -6
- package/src/workflows/resume.ts +9 -9
- package/src/workflows/retry-poller.ts +2 -2
- package/templates/extensions/comms-adherence-gate/README.md +25 -0
- package/templates/extensions/comms-adherence-gate/hooks.ts +100 -11
- package/templates/extensions/comms-adherence-gate/manifest.json +1 -1
- package/templates/skills/apps/SKILL.md +9 -0
- package/templates/skills/apps/content.md +9 -0
- package/templates/skills/code-quality/content.md +12 -0
- package/templates/skills/memory/content.md +8 -0
- package/templates/skills/scheduling/config.json +1 -1
- package/templates/skills/scheduling/content.md +2 -2
- package/templates/skills/swarm-docs/content.md +4 -0
- package/templates/skills/swarm-extensions/content.md +1 -1
- package/templates/skills/swarm-scripts/SKILL.md +1 -1
- package/templates/skills/swarm-scripts/content.md +1 -1
- package/templates/skills/work-on-task/SKILL.md +2 -0
- package/templates/skills/work-on-task/content.md +2 -0
- package/templates/workflows/dreaming/content.md +174 -7
- package/dist/acp-adapter-dn4gdsgr.js +0 -16
- package/dist/app-a66ssc4k.js +0 -17
- package/dist/cli-530hkwdy.js +0 -779
- package/dist/cli-a0657jmf.js +0 -339
- package/dist/cli-cyn9v8zr.js +0 -748
- package/dist/handlers-crckt5dq.js +0 -32
- package/dist/heartbeat-8phn1kdq.js +0 -41
- package/dist/index-4x08sjtk.js +0 -30
- package/dist/index-8ybffts4.js +0 -37
- package/dist/index-nfy4kkg5.js +0 -33
- package/dist/lead-zdqxsvjn.js +0 -71
- package/dist/worker-y62rvvq3.js +0 -71
- package/dist/{cli-gxy8y1dt.js → cli-8bpgbr8k.js} +3 -3
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { SocketModeClient } from "@slack/socket-mode";
|
|
2
|
+
|
|
3
|
+
/** Thrown inside a retired client when it tries to open a socket. Never escapes the client. */
|
|
4
|
+
export class SlackSocketClientRetiredError extends Error {
|
|
5
|
+
constructor() {
|
|
6
|
+
super("Slack socket-mode client was retired; it opens no new socket");
|
|
7
|
+
this.name = "SlackSocketClientRetiredError";
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface SlackSocketFence {
|
|
12
|
+
/** After this call, the client opens no new socket. Call it before the client is torn down. */
|
|
13
|
+
retire: () => void;
|
|
14
|
+
isRetired: () => boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Fence a socket-mode client so a reconnect still in flight at teardown can
|
|
19
|
+
* never open a socket next to the replacement.
|
|
20
|
+
*
|
|
21
|
+
* `start()` awaits `apps.connections.open` (with up to 100 web-client retries)
|
|
22
|
+
* before it builds the websocket, and it resets `shuttingDown` when it begins.
|
|
23
|
+
* So `disconnect()` cannot stop a start that is already waiting for its URL.
|
|
24
|
+
* The fence checks the retired flag before and after each URL request (also
|
|
25
|
+
* when the request fails), and `start()` then fails before it builds a
|
|
26
|
+
* websocket. A start that fails that
|
|
27
|
+
* way resolves quietly: the library calls it from a reconnect with no catch.
|
|
28
|
+
*/
|
|
29
|
+
export function fenceSocketModeClient(client: SocketModeClient): SlackSocketFence {
|
|
30
|
+
let retired = false;
|
|
31
|
+
// retrieveWSSURL is private in the library's types, so reach it by name.
|
|
32
|
+
const retrieveWSSURL: unknown = Reflect.get(client, "retrieveWSSURL");
|
|
33
|
+
if (typeof retrieveWSSURL !== "function") {
|
|
34
|
+
throw new Error("@slack/socket-mode changed: SocketModeClient.retrieveWSSURL is missing");
|
|
35
|
+
}
|
|
36
|
+
const start = client.start;
|
|
37
|
+
|
|
38
|
+
Reflect.set(client, "retrieveWSSURL", async function (this: SocketModeClient) {
|
|
39
|
+
if (retired) throw new SlackSocketClientRetiredError();
|
|
40
|
+
let url: unknown;
|
|
41
|
+
try {
|
|
42
|
+
url = await retrieveWSSURL.call(this);
|
|
43
|
+
} catch (error) {
|
|
44
|
+
// A retired client's failure is no longer news, and its reconnect caller has no catch.
|
|
45
|
+
if (retired) throw new SlackSocketClientRetiredError();
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
if (retired) throw new SlackSocketClientRetiredError();
|
|
49
|
+
return url;
|
|
50
|
+
});
|
|
51
|
+
Reflect.set(client, "start", function (this: SocketModeClient) {
|
|
52
|
+
return start.call(this).catch((error: unknown) => {
|
|
53
|
+
if (error instanceof SlackSocketClientRetiredError) return undefined;
|
|
54
|
+
throw error;
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
retire: () => {
|
|
60
|
+
retired = true;
|
|
61
|
+
},
|
|
62
|
+
isRetired: () => retired,
|
|
63
|
+
};
|
|
64
|
+
}
|
package/src/slack/watcher.ts
CHANGED
|
@@ -10,12 +10,18 @@ import {
|
|
|
10
10
|
markSlackRelayDelivered,
|
|
11
11
|
setSlackMessageTracking,
|
|
12
12
|
} from "../be/db";
|
|
13
|
+
import { bindLoopPath } from "../be/event-loop-lag";
|
|
13
14
|
import type { AgentTask } from "../types";
|
|
14
15
|
import { finalizeTerminalSlackReactions } from "./ack";
|
|
15
16
|
import { getSlackApp } from "./app";
|
|
16
17
|
import type { TreeNode } from "./blocks";
|
|
17
18
|
import { buildTreeBlocks, formatDuration } from "./blocks";
|
|
18
|
-
import {
|
|
19
|
+
import {
|
|
20
|
+
isSlackRenderV2Enabled,
|
|
21
|
+
processSlackRenderV2,
|
|
22
|
+
startSlackRenderV2Events,
|
|
23
|
+
stopSlackRenderV2Events,
|
|
24
|
+
} from "./render-v2";
|
|
19
25
|
import {
|
|
20
26
|
getAgentDisplayName,
|
|
21
27
|
getAgentSlackIcon,
|
|
@@ -32,6 +38,10 @@ import { slackTaskOutput } from "./task-output";
|
|
|
32
38
|
|
|
33
39
|
let watcherInterval: ReturnType<typeof setInterval> | null = null;
|
|
34
40
|
let isProcessing = false;
|
|
41
|
+
// Bumped by stopTaskWatcher(). A start that sees a new epoch after its
|
|
42
|
+
// hydration awaits was abandoned (watchdog restart timeout or shutdown) and
|
|
43
|
+
// must not install a timer.
|
|
44
|
+
let watcherEpoch = 0;
|
|
35
45
|
|
|
36
46
|
// Track notified completion tasks (taskId -> timestamp)
|
|
37
47
|
const notifiedCompletions = new Map<string, number>();
|
|
@@ -231,6 +241,9 @@ export function _getLastRenderedTree(): Map<string, string> {
|
|
|
231
241
|
export function _getTreeLastUpdateTime(): Map<string, number> {
|
|
232
242
|
return treeLastUpdateTime;
|
|
233
243
|
}
|
|
244
|
+
export function _isTaskWatcherRunning(): boolean {
|
|
245
|
+
return watcherInterval !== null;
|
|
246
|
+
}
|
|
234
247
|
|
|
235
248
|
// Expose DM helpers for testing
|
|
236
249
|
export const _isDMChannel = isDMChannel;
|
|
@@ -616,22 +629,37 @@ export async function processPendingSlackRelays(now = Date.now()): Promise<void>
|
|
|
616
629
|
}
|
|
617
630
|
}
|
|
618
631
|
|
|
632
|
+
export const DEFAULT_SLACK_TASK_WATCHER_INTERVAL_MS = 10_000;
|
|
633
|
+
|
|
634
|
+
/**
|
|
635
|
+
* Watcher tick from SLACK_TASK_WATCHER_INTERVAL_MS (milliseconds), else 10 s.
|
|
636
|
+
* Under render v2 each tick is the full reconcile; task events render their
|
|
637
|
+
* own thread in between, so the tick is the safety net, not the cadence.
|
|
638
|
+
*/
|
|
639
|
+
export function slackTaskWatcherIntervalMs(): number {
|
|
640
|
+
const raw = process.env.SLACK_TASK_WATCHER_INTERVAL_MS?.trim();
|
|
641
|
+
const parsed = raw ? Number(raw) : Number.NaN;
|
|
642
|
+
return Number.isInteger(parsed) && parsed > 0 ? parsed : DEFAULT_SLACK_TASK_WATCHER_INTERVAL_MS;
|
|
643
|
+
}
|
|
644
|
+
|
|
619
645
|
/**
|
|
620
646
|
* Start watching for Slack task updates and sending responses.
|
|
621
647
|
*/
|
|
622
|
-
export async function startTaskWatcher(intervalMs =
|
|
648
|
+
export async function startTaskWatcher(intervalMs = slackTaskWatcherIntervalMs()): Promise<void> {
|
|
623
649
|
if (watcherInterval) {
|
|
624
650
|
console.log("[Slack] Task watcher already running");
|
|
625
651
|
return;
|
|
626
652
|
}
|
|
627
653
|
|
|
654
|
+
const epoch = watcherEpoch;
|
|
628
655
|
let hydratedTrees = 0;
|
|
629
656
|
let hydratedFlat = 0;
|
|
630
657
|
const hydrationTasks = new Map<string, AgentTask>();
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
658
|
+
const inProgress = await getInProgressSlackTasks();
|
|
659
|
+
const pendingRelays = await getPendingSlackRelayTasks();
|
|
660
|
+
// Abandoned while it hydrated (stopped, or overtaken by another start).
|
|
661
|
+
if (epoch !== watcherEpoch || watcherInterval) return;
|
|
662
|
+
for (const task of [...inProgress, ...pendingRelays]) {
|
|
635
663
|
hydrationTasks.set(task.id, task);
|
|
636
664
|
}
|
|
637
665
|
for (const task of hydrationTasks.values()) {
|
|
@@ -676,7 +704,8 @@ export async function startTaskWatcher(intervalMs = 3000): Promise<void> {
|
|
|
676
704
|
);
|
|
677
705
|
}
|
|
678
706
|
|
|
679
|
-
|
|
707
|
+
startSlackRenderV2Events();
|
|
708
|
+
const watcherTick = async () => {
|
|
680
709
|
// Prevent overlapping processing cycles
|
|
681
710
|
if (isProcessing || !getSlackApp()) return;
|
|
682
711
|
isProcessing = true;
|
|
@@ -848,16 +877,21 @@ export async function startTaskWatcher(intervalMs = 3000): Promise<void> {
|
|
|
848
877
|
} finally {
|
|
849
878
|
isProcessing = false;
|
|
850
879
|
}
|
|
851
|
-
}
|
|
880
|
+
};
|
|
881
|
+
// Name the entry point for the event-loop stall line.
|
|
882
|
+
watcherInterval = setInterval(bindLoopPath("slack.watcher.tick", watcherTick), intervalMs);
|
|
852
883
|
|
|
853
884
|
console.log(`[Slack] Task watcher started (interval: ${intervalMs}ms)`);
|
|
854
885
|
}
|
|
855
886
|
|
|
856
887
|
export function stopTaskWatcher(): void {
|
|
888
|
+
// Fence any start still hydrating, even when no timer is installed yet.
|
|
889
|
+
watcherEpoch += 1;
|
|
857
890
|
if (watcherInterval) {
|
|
858
891
|
clearInterval(watcherInterval);
|
|
859
892
|
watcherInterval = null;
|
|
860
893
|
isProcessing = false;
|
|
894
|
+
stopSlackRenderV2Events();
|
|
861
895
|
console.log("[Slack] Task watcher stopped");
|
|
862
896
|
}
|
|
863
897
|
}
|
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
import { isEnvFlagEnabled } from "../utils/env-flag";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Process only inbound Slack deliveries proven to belong to this swarm's
|
|
5
|
+
* installation.
|
|
6
|
+
*
|
|
7
|
+
* Socket Mode sends each payload to any one of the app's open connections,
|
|
8
|
+
* whatever workspace it came from. When several swarms share one Slack app
|
|
9
|
+
* (each with its own bot token but the same app-level token), a swarm receives
|
|
10
|
+
* other workspaces' deliveries, and Bolt does not filter them: with a single
|
|
11
|
+
* bot token its `authorize` returns that token for every source.
|
|
12
|
+
*
|
|
13
|
+
* Decisions:
|
|
14
|
+
* - The check runs on the raw socket envelope, before Bolt acks it
|
|
15
|
+
* (`installSocketWorkspaceGate`). A delivery that is not proven ours is
|
|
16
|
+
* neither acked nor dispatched. Slack retries an unacked Events API envelope,
|
|
17
|
+
* and each retry can land on another connection of the app, so the owner can
|
|
18
|
+
* still receive it. Acking and dropping would lose it for good. Interactive
|
|
19
|
+
* payloads and slash commands are not retried; the user sees an error instead
|
|
20
|
+
* of a silent drop.
|
|
21
|
+
* - Fail closed. The socket opens only after this swarm's identity resolved
|
|
22
|
+
* (`auth.test`). Without an identity, or for a payload with no installation
|
|
23
|
+
* field, nothing passes.
|
|
24
|
+
* - A workspace install owns a delivery only when the payload names its
|
|
25
|
+
* workspace (`team_id`) and does not mark the delivery as an org-wide
|
|
26
|
+
* install. An enterprise id alone never matches a workspace install.
|
|
27
|
+
* - Whether this swarm's token is an org-wide Enterprise install comes from the
|
|
28
|
+
* installation's OAuth metadata (`is_enterprise_install` in the
|
|
29
|
+
* `oauth.v2.access` response), set as `SLACK_ENTERPRISE_INSTALL`. `auth.test`
|
|
30
|
+
* supplies only the ids. An org install owns a delivery that names its
|
|
31
|
+
* enterprise and is marked as an org-wide install.
|
|
32
|
+
* - `is_enterprise_install` is optional on interactive payloads and on slash
|
|
33
|
+
* commands (Bolt's `SlashCommand` declares it as a string, and Bolt parses
|
|
34
|
+
* "true" for commands), though the docs' slash command example omits it.
|
|
35
|
+
* Without it, exactly one installation claims the delivery, the one Slack's
|
|
36
|
+
* own SDK would route it to:
|
|
37
|
+
* - A payload that names the bot it belongs to (`message.bot_id` on a button,
|
|
38
|
+
* `view.bot_id` on a view) belongs to the installation with that bot
|
|
39
|
+
* (`auth.test` `bot_id`). Each installation has its own bot.
|
|
40
|
+
* - Otherwise it belongs to the workspace it names, as Slack's own SDK reads
|
|
41
|
+
* it: Bolt (`isBodyWithTypeEnterpriseInstall`) treats a missing flag as a
|
|
42
|
+
* workspace install, and `@slack/oauth` resolves it to that workspace's
|
|
43
|
+
* installation. An org install claims a flag-less delivery only when it
|
|
44
|
+
* names no workspace. A swarm cannot see the other installations of a
|
|
45
|
+
* shared app, so any rule that also let an org install claim a named
|
|
46
|
+
* workspace would give some deliveries two owners.
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
export interface SlackWorkspaceIdentity {
|
|
50
|
+
teamId: string | null;
|
|
51
|
+
enterpriseId: string | null;
|
|
52
|
+
/** Org-wide Enterprise install, from trusted OAuth metadata. */
|
|
53
|
+
isEnterpriseInstall: boolean;
|
|
54
|
+
/** This installation's bot (`auth.test` `bot_id`). */
|
|
55
|
+
botId?: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** One installation a payload says it was delivered for. */
|
|
59
|
+
export interface InboundInstallation {
|
|
60
|
+
teamId: string | null;
|
|
61
|
+
enterpriseId: string | null;
|
|
62
|
+
/** null when the payload does not say. */
|
|
63
|
+
isEnterpriseInstall: boolean | null;
|
|
64
|
+
/** The bot whose message or view the payload came from, when it names one. */
|
|
65
|
+
botId?: string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export type InboundOwnership =
|
|
69
|
+
| { own: true }
|
|
70
|
+
| { own: false; reason: "foreign_workspace" | "unverified_workspace" };
|
|
71
|
+
|
|
72
|
+
type Body = Record<string, unknown>;
|
|
73
|
+
|
|
74
|
+
function asRecord(value: unknown): Body | undefined {
|
|
75
|
+
return value && typeof value === "object" ? (value as Body) : undefined;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function asId(value: unknown): string | null {
|
|
79
|
+
return typeof value === "string" && value.length > 0 ? value : null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Interactive payloads carry a boolean; slash commands carry "true"/"false". */
|
|
83
|
+
function asFlag(value: unknown): boolean | null {
|
|
84
|
+
if (value === true || value === "true") return true;
|
|
85
|
+
if (value === false || value === "false") return false;
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function toInstallation(
|
|
90
|
+
teamId: unknown,
|
|
91
|
+
enterpriseId: unknown,
|
|
92
|
+
flag: unknown,
|
|
93
|
+
): InboundInstallation | null {
|
|
94
|
+
const installation = {
|
|
95
|
+
teamId: asId(teamId),
|
|
96
|
+
enterpriseId: asId(enterpriseId),
|
|
97
|
+
isEnterpriseInstall: asFlag(flag),
|
|
98
|
+
};
|
|
99
|
+
return installation.teamId || installation.enterpriseId ? installation : null;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Installations an inbound payload was delivered for.
|
|
104
|
+
*
|
|
105
|
+
* Events API envelopes carry `authorizations`, the installation the event was
|
|
106
|
+
* delivered to. They are the only source for events: in a Slack Connect channel
|
|
107
|
+
* the top-level `team_id` can name the partner workspace. Interactive, view and
|
|
108
|
+
* shortcut payloads carry `team.id` / `enterprise.id` (or `team.enterprise_id`)
|
|
109
|
+
* and an optional `is_enterprise_install`; `team` is null for an org-wide
|
|
110
|
+
* install. A view opened from a Slack Connect channel names the installing
|
|
111
|
+
* workspace in `view.app_installed_team_id`, as Bolt reads it. Slash commands
|
|
112
|
+
* carry `team_id` / `enterprise_id`, and the documented payload has no flag.
|
|
113
|
+
*/
|
|
114
|
+
export function readInboundInstallations(body: unknown): InboundInstallation[] {
|
|
115
|
+
const record = asRecord(body);
|
|
116
|
+
if (!record) return [];
|
|
117
|
+
|
|
118
|
+
const authorizations = Array.isArray(record.authorizations) ? record.authorizations : [];
|
|
119
|
+
const fromAuthorizations: InboundInstallation[] = [];
|
|
120
|
+
for (const entry of authorizations) {
|
|
121
|
+
const authorization = asRecord(entry);
|
|
122
|
+
const installation = toInstallation(
|
|
123
|
+
authorization?.team_id,
|
|
124
|
+
authorization?.enterprise_id,
|
|
125
|
+
authorization?.is_enterprise_install,
|
|
126
|
+
);
|
|
127
|
+
if (installation) fromAuthorizations.push(installation);
|
|
128
|
+
}
|
|
129
|
+
// An Events API envelope without authorizations cannot be attributed.
|
|
130
|
+
if (fromAuthorizations.length > 0 || record.type === "event_callback") return fromAuthorizations;
|
|
131
|
+
|
|
132
|
+
const team = asRecord(record.team);
|
|
133
|
+
const view = asRecord(record.view);
|
|
134
|
+
const installation = toInstallation(
|
|
135
|
+
asId(view?.app_installed_team_id) ?? record.team_id ?? team?.id,
|
|
136
|
+
record.enterprise_id ?? asRecord(record.enterprise)?.id ?? team?.enterprise_id,
|
|
137
|
+
record.is_enterprise_install,
|
|
138
|
+
);
|
|
139
|
+
if (!installation) return [];
|
|
140
|
+
// A button's message, or a view, was posted or opened by one installation's
|
|
141
|
+
// bot. A message shortcut's message can be anyone's, so it proves nothing.
|
|
142
|
+
const botId =
|
|
143
|
+
asId(view?.bot_id) ??
|
|
144
|
+
(record.type === "block_actions" ? asId(asRecord(record.message)?.bot_id) : null);
|
|
145
|
+
return [botId ? { ...installation, botId } : installation];
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** Does this swarm's installation own the delivery? Anything unproven is not ours. */
|
|
149
|
+
export function classifyInboundOwnership(
|
|
150
|
+
identity: SlackWorkspaceIdentity | null,
|
|
151
|
+
installations: InboundInstallation[],
|
|
152
|
+
): InboundOwnership {
|
|
153
|
+
if (!identity || installations.length === 0) {
|
|
154
|
+
return { own: false, reason: "unverified_workspace" };
|
|
155
|
+
}
|
|
156
|
+
// The two branches are complementary: a workspace install and an org install
|
|
157
|
+
// granted that workspace never both claim one delivery.
|
|
158
|
+
const owns = (installation: InboundInstallation): boolean => {
|
|
159
|
+
if (identity.isEnterpriseInstall) {
|
|
160
|
+
if (identity.enterpriseId === null || installation.enterpriseId !== identity.enterpriseId) {
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
if (installation.isEnterpriseInstall !== null) return installation.isEnterpriseInstall;
|
|
164
|
+
if (installation.botId) return installation.botId === identity.botId;
|
|
165
|
+
// A flag-less delivery naming a workspace is that workspace's install's.
|
|
166
|
+
return installation.teamId === null;
|
|
167
|
+
}
|
|
168
|
+
if (identity.teamId === null || installation.teamId !== identity.teamId) return false;
|
|
169
|
+
if (installation.isEnterpriseInstall !== null) return !installation.isEnterpriseInstall;
|
|
170
|
+
if (installation.botId) return installation.botId === identity.botId;
|
|
171
|
+
return true;
|
|
172
|
+
};
|
|
173
|
+
return installations.some(owns) ? { own: true } : { own: false, reason: "foreign_workspace" };
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** The type label logged for a withheld delivery. Never message text. */
|
|
177
|
+
export function inboundPayloadType(body: unknown): string {
|
|
178
|
+
const record = asRecord(body);
|
|
179
|
+
if (!record) return "unknown";
|
|
180
|
+
const eventType = asRecord(record.event)?.type;
|
|
181
|
+
if (typeof eventType === "string") return `event:${eventType}`;
|
|
182
|
+
if (typeof record.command === "string") return "command";
|
|
183
|
+
return typeof record.type === "string" ? record.type : "unknown";
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// ─── Identity of this swarm's installation ───────────────────────────────────
|
|
187
|
+
|
|
188
|
+
/** Documented `auth.test` fields the guard reads. */
|
|
189
|
+
export interface SlackAuthTestResult {
|
|
190
|
+
team_id?: string;
|
|
191
|
+
enterprise_id?: string;
|
|
192
|
+
bot_id?: string;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** The Web API call that resolves this swarm's identity. */
|
|
196
|
+
export interface SlackIdentityClient {
|
|
197
|
+
auth: { test(): Promise<SlackAuthTestResult> };
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** Resolve this swarm's identity from `auth.test`. Throws on any failure, so the socket stays closed. */
|
|
201
|
+
export async function resolveSlackIdentity(
|
|
202
|
+
client: SlackIdentityClient,
|
|
203
|
+
isEnterpriseInstall: boolean,
|
|
204
|
+
): Promise<SlackWorkspaceIdentity> {
|
|
205
|
+
return identityFromAuthTest(await client.auth.test(), isEnterpriseInstall);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** `SLACK_ENTERPRISE_INSTALL`: the bot token is an org-wide install (`oauth.v2.access`). */
|
|
209
|
+
export function isSlackEnterpriseInstall(env: NodeJS.ProcessEnv = process.env): boolean {
|
|
210
|
+
return isEnvFlagEnabled("SLACK_ENTERPRISE_INSTALL", false, env);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** Build the identity, or throw when `auth.test` lacks the id the install mode needs. */
|
|
214
|
+
export function identityFromAuthTest(
|
|
215
|
+
result: SlackAuthTestResult,
|
|
216
|
+
isEnterpriseInstall: boolean,
|
|
217
|
+
): SlackWorkspaceIdentity {
|
|
218
|
+
const teamId = asId(result.team_id);
|
|
219
|
+
const enterpriseId = asId(result.enterprise_id);
|
|
220
|
+
const botId = asId(result.bot_id);
|
|
221
|
+
if (isEnterpriseInstall && !enterpriseId) {
|
|
222
|
+
throw new Error("SLACK_ENTERPRISE_INSTALL is set but auth.test returned no enterprise_id");
|
|
223
|
+
}
|
|
224
|
+
if (!isEnterpriseInstall && !teamId) {
|
|
225
|
+
throw new Error("auth.test returned no team_id");
|
|
226
|
+
}
|
|
227
|
+
return {
|
|
228
|
+
teamId: isEnterpriseInstall ? null : teamId,
|
|
229
|
+
enterpriseId,
|
|
230
|
+
isEnterpriseInstall,
|
|
231
|
+
...(botId ? { botId } : {}),
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
let resolveIdentity: (() => Promise<SlackWorkspaceIdentity>) | null = null;
|
|
236
|
+
let identity: SlackWorkspaceIdentity | null = null;
|
|
237
|
+
let pending: Promise<SlackWorkspaceIdentity | null> | null = null;
|
|
238
|
+
|
|
239
|
+
/** Register how to resolve this swarm's identity. Clears any cached identity. */
|
|
240
|
+
export function setSlackWorkspaceIdentitySource(
|
|
241
|
+
source: (() => Promise<SlackWorkspaceIdentity>) | null,
|
|
242
|
+
): void {
|
|
243
|
+
resolveIdentity = source;
|
|
244
|
+
identity = null;
|
|
245
|
+
pending = null;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** The resolved identity, or null. Never calls Slack. */
|
|
249
|
+
export function getCachedSlackWorkspaceIdentity(): SlackWorkspaceIdentity | null {
|
|
250
|
+
return identity;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Resolve this swarm's identity, or null when no source is registered or the
|
|
255
|
+
* lookup failed. A success is cached; a failure is retried on the next call.
|
|
256
|
+
*/
|
|
257
|
+
export async function getSlackWorkspaceIdentity(): Promise<SlackWorkspaceIdentity | null> {
|
|
258
|
+
if (identity) return identity;
|
|
259
|
+
if (!resolveIdentity) return null;
|
|
260
|
+
if (pending) return pending;
|
|
261
|
+
|
|
262
|
+
const source = resolveIdentity;
|
|
263
|
+
pending = (async () => {
|
|
264
|
+
try {
|
|
265
|
+
const resolved = await source();
|
|
266
|
+
// A source swapped mid-call (stop/start) must not cache the old identity.
|
|
267
|
+
if (resolveIdentity !== source) return null;
|
|
268
|
+
identity = resolved;
|
|
269
|
+
console.log(
|
|
270
|
+
`[Slack] Workspace guard: team=${resolved.teamId ?? "none"} enterprise=${resolved.enterpriseId ?? "none"} enterpriseInstall=${resolved.isEnterpriseInstall}`,
|
|
271
|
+
);
|
|
272
|
+
return resolved;
|
|
273
|
+
} catch (error) {
|
|
274
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
275
|
+
console.error(`[Slack] Workspace guard: identity lookup failed: ${message}`);
|
|
276
|
+
return null;
|
|
277
|
+
} finally {
|
|
278
|
+
// A source swapped mid-call already cleared or replaced `pending`.
|
|
279
|
+
if (resolveIdentity === source) pending = null;
|
|
280
|
+
}
|
|
281
|
+
})();
|
|
282
|
+
return pending;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
const WITHHELD_LOG_INTERVAL_MS = 60_000;
|
|
286
|
+
const lastWithheldLogAt = new Map<string, number>();
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Classify a delivery against `identity` and log the ones that are not ours:
|
|
290
|
+
* team, enterprise and payload type only, at most once a minute per key.
|
|
291
|
+
*/
|
|
292
|
+
export function checkInboundWorkspace(
|
|
293
|
+
body: unknown,
|
|
294
|
+
own: SlackWorkspaceIdentity | null = identity,
|
|
295
|
+
): InboundOwnership {
|
|
296
|
+
const installations = readInboundInstallations(body);
|
|
297
|
+
const ownership = classifyInboundOwnership(own, installations);
|
|
298
|
+
if (ownership.own) return ownership;
|
|
299
|
+
|
|
300
|
+
const team = installations.map((i) => i.teamId ?? "-").join(",") || "none";
|
|
301
|
+
const enterprise = installations.map((i) => i.enterpriseId ?? "-").join(",") || "none";
|
|
302
|
+
const type = inboundPayloadType(body);
|
|
303
|
+
const key = `${ownership.reason}|${team}|${enterprise}|${type}`;
|
|
304
|
+
const now = Date.now();
|
|
305
|
+
if (now - (lastWithheldLogAt.get(key) ?? 0) >= WITHHELD_LOG_INTERVAL_MS) {
|
|
306
|
+
if (lastWithheldLogAt.size >= 1_000) lastWithheldLogAt.clear();
|
|
307
|
+
lastWithheldLogAt.set(key, now);
|
|
308
|
+
console.warn(
|
|
309
|
+
`[Slack] Withheld inbound delivery (${ownership.reason}): team=${team} enterprise=${enterprise} type=${type}`,
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
return ownership;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/** Minimal surface of the Socket Mode client the gate wraps. */
|
|
316
|
+
interface SocketEventEmitter {
|
|
317
|
+
emit(event: string | symbol, ...args: unknown[]): boolean;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Wrap the Socket Mode client so a `slack_event` envelope reaches Bolt (which
|
|
322
|
+
* acks it) only when it belongs to `getIdentity()`'s installation. Any other
|
|
323
|
+
* envelope is left unacked and undispatched, so Slack redelivers it.
|
|
324
|
+
*
|
|
325
|
+
* Install it after every other `emit` wrapper: the last one installed runs
|
|
326
|
+
* first, so nothing downstream sees, stores or acks a withheld envelope.
|
|
327
|
+
*/
|
|
328
|
+
export function installSocketWorkspaceGate(
|
|
329
|
+
client: SocketEventEmitter,
|
|
330
|
+
getIdentity: () => SlackWorkspaceIdentity | null = getCachedSlackWorkspaceIdentity,
|
|
331
|
+
): void {
|
|
332
|
+
const emit = client.emit.bind(client);
|
|
333
|
+
client.emit = (event: string | symbol, ...args: unknown[]): boolean => {
|
|
334
|
+
if (event !== "slack_event") return emit(event, ...args);
|
|
335
|
+
const body = (args[0] as { body?: unknown } | undefined)?.body;
|
|
336
|
+
if (checkInboundWorkspace(body, getIdentity()).own) return emit(event, ...args);
|
|
337
|
+
return true;
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/** Test-only. */
|
|
342
|
+
export function resetSlackWorkspaceGuardForTests(): void {
|
|
343
|
+
setSlackWorkspaceIdentitySource(null);
|
|
344
|
+
lastWithheldLogAt.clear();
|
|
345
|
+
}
|
|
@@ -31,6 +31,8 @@ export async function runTaskTerminalEffects(args: {
|
|
|
31
31
|
failureReason?: string;
|
|
32
32
|
agentId?: string;
|
|
33
33
|
persistMemory?: boolean;
|
|
34
|
+
/** Passed through to `createWorkerTaskFollowUp`; see `store-progress`. */
|
|
35
|
+
chainedTaskId?: string;
|
|
34
36
|
}): Promise<void> {
|
|
35
37
|
const { task, status, agentId, persistMemory } = args;
|
|
36
38
|
const taskId = task.id;
|
|
@@ -160,6 +162,8 @@ export async function runTaskTerminalEffects(args: {
|
|
|
160
162
|
status,
|
|
161
163
|
output: safeOutput,
|
|
162
164
|
failureReason: safeFailureReason,
|
|
165
|
+
chainedTaskId: args.chainedTaskId,
|
|
166
|
+
completingAgentId: agentId,
|
|
163
167
|
});
|
|
164
168
|
if (followUp) {
|
|
165
169
|
console.log(
|
|
@@ -261,7 +261,8 @@ async function findDeferredWakeFor(taskId: string, agentId: string): Promise<Def
|
|
|
261
261
|
* task already reviews the result, so a follow-up would duplicate it. An
|
|
262
262
|
* `all` wait with siblings still pending wakes nobody, so the follow-up stays.
|
|
263
263
|
* A `followUpConfig.onCompleted` / `onFailed` instruction for this status also
|
|
264
|
-
* keeps the follow-up, because the wake-up task does not carry that text.
|
|
264
|
+
* keeps the follow-up, because the wake-up task does not carry that text. A
|
|
265
|
+
* rejected `chainedTaskId` keeps it for the same reason.
|
|
265
266
|
*
|
|
266
267
|
* With `FOLLOW_UP_GATE_MODE=shadow`, a gated scheduled run also records a
|
|
267
268
|
* verifier's would-skip decision after commit; the follow-up is never skipped.
|
|
@@ -271,6 +272,13 @@ export async function createWorkerTaskFollowUp(args: {
|
|
|
271
272
|
status: "completed" | "failed";
|
|
272
273
|
output?: string;
|
|
273
274
|
failureReason?: string;
|
|
275
|
+
/**
|
|
276
|
+
* `store-progress` `chainedTaskId`: a live child task the completing agent
|
|
277
|
+
* created to carry this result forward. Honoured only on `completed`.
|
|
278
|
+
*/
|
|
279
|
+
chainedTaskId?: string;
|
|
280
|
+
/** Agent that made the completing call; defaults to the task's assignee. */
|
|
281
|
+
completingAgentId?: string;
|
|
274
282
|
}): Promise<AgentTask | null> {
|
|
275
283
|
const { task, status, output, failureReason } = args;
|
|
276
284
|
|
|
@@ -295,6 +303,37 @@ export async function createWorkerTaskFollowUp(args: {
|
|
|
295
303
|
return null;
|
|
296
304
|
}
|
|
297
305
|
|
|
306
|
+
// Failures always wake the Lead, so only a completion can hand off to a child.
|
|
307
|
+
let chainRejection: (ChainedTaskCheck & { ok: false }) | null = null;
|
|
308
|
+
if (status === "completed" && args.chainedTaskId) {
|
|
309
|
+
const chain = await checkChainedTask(
|
|
310
|
+
task,
|
|
311
|
+
args.chainedTaskId,
|
|
312
|
+
args.completingAgentId ?? task.agentId ?? "",
|
|
313
|
+
);
|
|
314
|
+
if (chain.ok) {
|
|
315
|
+
try {
|
|
316
|
+
await createLogEntry({
|
|
317
|
+
eventType: "task_follow_up_suppressed",
|
|
318
|
+
taskId: task.id,
|
|
319
|
+
agentId: leadAgent.id,
|
|
320
|
+
metadata: {
|
|
321
|
+
reason: "chained_task_live",
|
|
322
|
+
status,
|
|
323
|
+
chainedTaskId: chain.child.id,
|
|
324
|
+
chainedTaskStatus: chain.child.status,
|
|
325
|
+
...(task.followUpConfig?.onCompleted ? { droppedOnCompleted: true } : {}),
|
|
326
|
+
},
|
|
327
|
+
});
|
|
328
|
+
} catch {}
|
|
329
|
+
console.log(
|
|
330
|
+
`[worker-follow-up] Skipped follow-up for completed task ${task.id.slice(0, 8)}: work continues in chained task ${chain.child.id.slice(0, 8)} (${chain.child.status})`,
|
|
331
|
+
);
|
|
332
|
+
return null;
|
|
333
|
+
}
|
|
334
|
+
chainRejection = chain;
|
|
335
|
+
}
|
|
336
|
+
|
|
298
337
|
const agentName = taskAgent.name || task.agentId?.slice(0, 8) || "Unknown";
|
|
299
338
|
const taskDesc = task.task.slice(0, 200);
|
|
300
339
|
const creatorAgent = task.creatorAgentId
|
|
@@ -323,6 +362,12 @@ export async function createWorkerTaskFollowUp(args: {
|
|
|
323
362
|
task_id: task.id,
|
|
324
363
|
});
|
|
325
364
|
followUpDescription = completedResult.text;
|
|
365
|
+
if (chainRejection) {
|
|
366
|
+
followUpDescription += resolveTemplate("task.worker.chain_rejected", {
|
|
367
|
+
chained_task_id: chainRejection.chainedTaskId,
|
|
368
|
+
reason: chainRejection.reason,
|
|
369
|
+
}).text;
|
|
370
|
+
}
|
|
326
371
|
} else {
|
|
327
372
|
const reason = failureReason || "(no reason given)";
|
|
328
373
|
const failedResult = resolveTemplate("task.worker.failed", {
|
|
@@ -374,8 +419,12 @@ export async function createWorkerTaskFollowUp(args: {
|
|
|
374
419
|
const changes = preFollowUp.action === "modify" ? preFollowUp.data : {};
|
|
375
420
|
const followUpAgentId = changes.agentId === undefined ? leadAgent.id : changes.agentId;
|
|
376
421
|
|
|
422
|
+
// Like `instructions`, a rejected chainedTaskId keeps the follow-up: the
|
|
423
|
+
// wake-up task does not carry the rejected id or the reason.
|
|
377
424
|
const wake =
|
|
378
|
-
followUpAgentId && !instructions
|
|
425
|
+
followUpAgentId && !instructions && !chainRejection
|
|
426
|
+
? await findDeferredWakeFor(task.id, followUpAgentId)
|
|
427
|
+
: null;
|
|
379
428
|
if (wake) {
|
|
380
429
|
try {
|
|
381
430
|
await createLogEntry({
|
|
@@ -435,6 +484,57 @@ export async function createWorkerTaskFollowUp(args: {
|
|
|
435
484
|
return followUp;
|
|
436
485
|
}
|
|
437
486
|
|
|
487
|
+
/**
|
|
488
|
+
* Child statuses that mean the chained work is still going to run. `reviewing`
|
|
489
|
+
* is the accept/reject step of an offer, and a `paused` task keeps its agent
|
|
490
|
+
* and resumes when that worker restarts.
|
|
491
|
+
*/
|
|
492
|
+
const LIVE_CHAINED_TASK_STATUSES: ReadonlySet<AgentTask["status"]> = new Set([
|
|
493
|
+
"offered",
|
|
494
|
+
"reviewing",
|
|
495
|
+
"pending",
|
|
496
|
+
"in_progress",
|
|
497
|
+
"paused",
|
|
498
|
+
]);
|
|
499
|
+
|
|
500
|
+
type ChainedTaskCheck =
|
|
501
|
+
| { ok: true; child: AgentTask }
|
|
502
|
+
| { ok: false; chainedTaskId: string; reason: string };
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* Whether `chainedTaskId` may stand in for the Lead follow-up of `task`: it
|
|
506
|
+
* must be a live direct child of `task`, created by the completing agent.
|
|
507
|
+
*/
|
|
508
|
+
async function checkChainedTask(
|
|
509
|
+
task: AgentTask,
|
|
510
|
+
chainedTaskId: string,
|
|
511
|
+
completingAgentId: string,
|
|
512
|
+
): Promise<ChainedTaskCheck> {
|
|
513
|
+
const reject = (reason: string): ChainedTaskCheck => ({ ok: false, chainedTaskId, reason });
|
|
514
|
+
let child: AgentTask | null;
|
|
515
|
+
try {
|
|
516
|
+
child = await getTaskById(chainedTaskId);
|
|
517
|
+
} catch (err) {
|
|
518
|
+
// Fail open: a broken lookup must never drop the follow-up.
|
|
519
|
+
return reject(`lookup failed (${err instanceof Error ? err.message : String(err)})`);
|
|
520
|
+
}
|
|
521
|
+
if (!child) return reject("no task has this id");
|
|
522
|
+
if (child.parentTaskId !== task.id) {
|
|
523
|
+
return reject(
|
|
524
|
+
child.parentTaskId
|
|
525
|
+
? `its parentTaskId is ${child.parentTaskId}, not this task`
|
|
526
|
+
: "it has no parentTaskId",
|
|
527
|
+
);
|
|
528
|
+
}
|
|
529
|
+
if (!completingAgentId || child.creatorAgentId !== completingAgentId) {
|
|
530
|
+
return reject("it was not created by the agent that completed this task");
|
|
531
|
+
}
|
|
532
|
+
if (!LIVE_CHAINED_TASK_STATUSES.has(child.status)) {
|
|
533
|
+
return reject(`it is ${child.status}, not live`);
|
|
534
|
+
}
|
|
535
|
+
return { ok: true, child };
|
|
536
|
+
}
|
|
537
|
+
|
|
438
538
|
/** Hop cap for `deferredWorkChatContextKey`; a defer/resume chain is short. */
|
|
439
539
|
const MAX_CONTINUATION_HOPS = 32;
|
|
440
540
|
|