@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
|
@@ -5,6 +5,8 @@ import {
|
|
|
5
5
|
decryptSecret,
|
|
6
6
|
getEncryptionKey,
|
|
7
7
|
init_crypto,
|
|
8
|
+
bindLoopPath,
|
|
9
|
+
init_event_loop_lag,
|
|
8
10
|
getDbClient2,
|
|
9
11
|
SLACK_REACTION_DEFAULTS,
|
|
10
12
|
SLACK_REACTION_CONFIG_KEYS,
|
|
@@ -20,6 +22,10 @@ import {
|
|
|
20
22
|
markFinalizedSlackRelaysDelivered2,
|
|
21
23
|
getInProgressSlackTasks2,
|
|
22
24
|
getSlackTasksMissingTree2,
|
|
25
|
+
closeSlackTreeIfSettled,
|
|
26
|
+
getSlackThreadsOfTasks,
|
|
27
|
+
slackThreadHasOutcomeWork,
|
|
28
|
+
init_slack_trees,
|
|
23
29
|
ensureSlackRenderV2Activation2,
|
|
24
30
|
ensureSlackDelegationActivation2,
|
|
25
31
|
isPendingSlackMessage2,
|
|
@@ -50,11 +56,15 @@ import {
|
|
|
50
56
|
checkDependencies2,
|
|
51
57
|
emitBuiltInIntegrationConnectedOnce2,
|
|
52
58
|
init_db4
|
|
53
|
-
} from "./cli-
|
|
59
|
+
} from "./cli-h38x262p.js";
|
|
54
60
|
import {
|
|
55
61
|
getChannelBlockReason2,
|
|
56
62
|
init_external_channel
|
|
57
|
-
} from "./cli-
|
|
63
|
+
} from "./cli-qsnnd04k.js";
|
|
64
|
+
import {
|
|
65
|
+
workflowEventBus2,
|
|
66
|
+
init_event_bus
|
|
67
|
+
} from "./cli-eddnyg3t.js";
|
|
58
68
|
import {
|
|
59
69
|
require_jsonwebtoken,
|
|
60
70
|
require_dist6,
|
|
@@ -80,11 +90,11 @@ import {
|
|
|
80
90
|
import {
|
|
81
91
|
isTerminalTaskStatus,
|
|
82
92
|
init_types4
|
|
83
|
-
} from "./cli-
|
|
93
|
+
} from "./cli-2zp0et3v.js";
|
|
84
94
|
import {
|
|
85
95
|
taskAttachmentDisplayUrl,
|
|
86
96
|
init_task_attachment_links
|
|
87
|
-
} from "./cli-
|
|
97
|
+
} from "./cli-tk7cjj8h.js";
|
|
88
98
|
import {
|
|
89
99
|
getSlackConfiguration,
|
|
90
100
|
init_config4
|
|
@@ -11411,6 +11421,179 @@ var init_slack_inbound = __esm(() => {
|
|
|
11411
11421
|
};
|
|
11412
11422
|
});
|
|
11413
11423
|
|
|
11424
|
+
// src/slack/workspace-guard.ts
|
|
11425
|
+
function asRecord(value) {
|
|
11426
|
+
return value && typeof value === "object" ? value : undefined;
|
|
11427
|
+
}
|
|
11428
|
+
function asId(value) {
|
|
11429
|
+
return typeof value === "string" && value.length > 0 ? value : null;
|
|
11430
|
+
}
|
|
11431
|
+
function asFlag(value) {
|
|
11432
|
+
if (value === true || value === "true")
|
|
11433
|
+
return true;
|
|
11434
|
+
if (value === false || value === "false")
|
|
11435
|
+
return false;
|
|
11436
|
+
return null;
|
|
11437
|
+
}
|
|
11438
|
+
function toInstallation(teamId, enterpriseId, flag) {
|
|
11439
|
+
const installation = {
|
|
11440
|
+
teamId: asId(teamId),
|
|
11441
|
+
enterpriseId: asId(enterpriseId),
|
|
11442
|
+
isEnterpriseInstall: asFlag(flag)
|
|
11443
|
+
};
|
|
11444
|
+
return installation.teamId || installation.enterpriseId ? installation : null;
|
|
11445
|
+
}
|
|
11446
|
+
function readInboundInstallations(body) {
|
|
11447
|
+
const record = asRecord(body);
|
|
11448
|
+
if (!record)
|
|
11449
|
+
return [];
|
|
11450
|
+
const authorizations = Array.isArray(record.authorizations) ? record.authorizations : [];
|
|
11451
|
+
const fromAuthorizations = [];
|
|
11452
|
+
for (const entry of authorizations) {
|
|
11453
|
+
const authorization = asRecord(entry);
|
|
11454
|
+
const installation = toInstallation(authorization?.team_id, authorization?.enterprise_id, authorization?.is_enterprise_install);
|
|
11455
|
+
if (installation)
|
|
11456
|
+
fromAuthorizations.push(installation);
|
|
11457
|
+
}
|
|
11458
|
+
if (fromAuthorizations.length > 0 || record.type === "event_callback")
|
|
11459
|
+
return fromAuthorizations;
|
|
11460
|
+
const team = asRecord(record.team);
|
|
11461
|
+
const view = asRecord(record.view);
|
|
11462
|
+
const installation = toInstallation(asId(view?.app_installed_team_id) ?? record.team_id ?? team?.id, record.enterprise_id ?? asRecord(record.enterprise)?.id ?? team?.enterprise_id, record.is_enterprise_install);
|
|
11463
|
+
if (!installation)
|
|
11464
|
+
return [];
|
|
11465
|
+
const botId = asId(view?.bot_id) ?? (record.type === "block_actions" ? asId(asRecord(record.message)?.bot_id) : null);
|
|
11466
|
+
return [botId ? { ...installation, botId } : installation];
|
|
11467
|
+
}
|
|
11468
|
+
function classifyInboundOwnership(identity, installations) {
|
|
11469
|
+
if (!identity || installations.length === 0) {
|
|
11470
|
+
return { own: false, reason: "unverified_workspace" };
|
|
11471
|
+
}
|
|
11472
|
+
const owns = (installation) => {
|
|
11473
|
+
if (identity.isEnterpriseInstall) {
|
|
11474
|
+
if (identity.enterpriseId === null || installation.enterpriseId !== identity.enterpriseId) {
|
|
11475
|
+
return false;
|
|
11476
|
+
}
|
|
11477
|
+
if (installation.isEnterpriseInstall !== null)
|
|
11478
|
+
return installation.isEnterpriseInstall;
|
|
11479
|
+
if (installation.botId)
|
|
11480
|
+
return installation.botId === identity.botId;
|
|
11481
|
+
return installation.teamId === null;
|
|
11482
|
+
}
|
|
11483
|
+
if (identity.teamId === null || installation.teamId !== identity.teamId)
|
|
11484
|
+
return false;
|
|
11485
|
+
if (installation.isEnterpriseInstall !== null)
|
|
11486
|
+
return !installation.isEnterpriseInstall;
|
|
11487
|
+
if (installation.botId)
|
|
11488
|
+
return installation.botId === identity.botId;
|
|
11489
|
+
return true;
|
|
11490
|
+
};
|
|
11491
|
+
return installations.some(owns) ? { own: true } : { own: false, reason: "foreign_workspace" };
|
|
11492
|
+
}
|
|
11493
|
+
function inboundPayloadType(body) {
|
|
11494
|
+
const record = asRecord(body);
|
|
11495
|
+
if (!record)
|
|
11496
|
+
return "unknown";
|
|
11497
|
+
const eventType = asRecord(record.event)?.type;
|
|
11498
|
+
if (typeof eventType === "string")
|
|
11499
|
+
return `event:${eventType}`;
|
|
11500
|
+
if (typeof record.command === "string")
|
|
11501
|
+
return "command";
|
|
11502
|
+
return typeof record.type === "string" ? record.type : "unknown";
|
|
11503
|
+
}
|
|
11504
|
+
async function resolveSlackIdentity(client, isEnterpriseInstall) {
|
|
11505
|
+
return identityFromAuthTest(await client.auth.test(), isEnterpriseInstall);
|
|
11506
|
+
}
|
|
11507
|
+
function isSlackEnterpriseInstall(env = process.env) {
|
|
11508
|
+
return isEnvFlagEnabled("SLACK_ENTERPRISE_INSTALL", false, env);
|
|
11509
|
+
}
|
|
11510
|
+
function identityFromAuthTest(result, isEnterpriseInstall) {
|
|
11511
|
+
const teamId = asId(result.team_id);
|
|
11512
|
+
const enterpriseId = asId(result.enterprise_id);
|
|
11513
|
+
const botId = asId(result.bot_id);
|
|
11514
|
+
if (isEnterpriseInstall && !enterpriseId) {
|
|
11515
|
+
throw new Error("SLACK_ENTERPRISE_INSTALL is set but auth.test returned no enterprise_id");
|
|
11516
|
+
}
|
|
11517
|
+
if (!isEnterpriseInstall && !teamId) {
|
|
11518
|
+
throw new Error("auth.test returned no team_id");
|
|
11519
|
+
}
|
|
11520
|
+
return {
|
|
11521
|
+
teamId: isEnterpriseInstall ? null : teamId,
|
|
11522
|
+
enterpriseId,
|
|
11523
|
+
isEnterpriseInstall,
|
|
11524
|
+
...botId ? { botId } : {}
|
|
11525
|
+
};
|
|
11526
|
+
}
|
|
11527
|
+
function setSlackWorkspaceIdentitySource(source) {
|
|
11528
|
+
resolveIdentity = source;
|
|
11529
|
+
identity = null;
|
|
11530
|
+
pending = null;
|
|
11531
|
+
}
|
|
11532
|
+
function getCachedSlackWorkspaceIdentity() {
|
|
11533
|
+
return identity;
|
|
11534
|
+
}
|
|
11535
|
+
async function getSlackWorkspaceIdentity() {
|
|
11536
|
+
if (identity)
|
|
11537
|
+
return identity;
|
|
11538
|
+
if (!resolveIdentity)
|
|
11539
|
+
return null;
|
|
11540
|
+
if (pending)
|
|
11541
|
+
return pending;
|
|
11542
|
+
const source = resolveIdentity;
|
|
11543
|
+
pending = (async () => {
|
|
11544
|
+
try {
|
|
11545
|
+
const resolved = await source();
|
|
11546
|
+
if (resolveIdentity !== source)
|
|
11547
|
+
return null;
|
|
11548
|
+
identity = resolved;
|
|
11549
|
+
console.log(`[Slack] Workspace guard: team=${resolved.teamId ?? "none"} enterprise=${resolved.enterpriseId ?? "none"} enterpriseInstall=${resolved.isEnterpriseInstall}`);
|
|
11550
|
+
return resolved;
|
|
11551
|
+
} catch (error) {
|
|
11552
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
11553
|
+
console.error(`[Slack] Workspace guard: identity lookup failed: ${message}`);
|
|
11554
|
+
return null;
|
|
11555
|
+
} finally {
|
|
11556
|
+
if (resolveIdentity === source)
|
|
11557
|
+
pending = null;
|
|
11558
|
+
}
|
|
11559
|
+
})();
|
|
11560
|
+
return pending;
|
|
11561
|
+
}
|
|
11562
|
+
function checkInboundWorkspace(body, own = identity) {
|
|
11563
|
+
const installations = readInboundInstallations(body);
|
|
11564
|
+
const ownership = classifyInboundOwnership(own, installations);
|
|
11565
|
+
if (ownership.own)
|
|
11566
|
+
return ownership;
|
|
11567
|
+
const team = installations.map((i) => i.teamId ?? "-").join(",") || "none";
|
|
11568
|
+
const enterprise = installations.map((i) => i.enterpriseId ?? "-").join(",") || "none";
|
|
11569
|
+
const type = inboundPayloadType(body);
|
|
11570
|
+
const key = `${ownership.reason}|${team}|${enterprise}|${type}`;
|
|
11571
|
+
const now = Date.now();
|
|
11572
|
+
if (now - (lastWithheldLogAt.get(key) ?? 0) >= WITHHELD_LOG_INTERVAL_MS) {
|
|
11573
|
+
if (lastWithheldLogAt.size >= 1000)
|
|
11574
|
+
lastWithheldLogAt.clear();
|
|
11575
|
+
lastWithheldLogAt.set(key, now);
|
|
11576
|
+
console.warn(`[Slack] Withheld inbound delivery (${ownership.reason}): team=${team} enterprise=${enterprise} type=${type}`);
|
|
11577
|
+
}
|
|
11578
|
+
return ownership;
|
|
11579
|
+
}
|
|
11580
|
+
function installSocketWorkspaceGate(client, getIdentity = getCachedSlackWorkspaceIdentity) {
|
|
11581
|
+
const emit = client.emit.bind(client);
|
|
11582
|
+
client.emit = (event, ...args) => {
|
|
11583
|
+
if (event !== "slack_event")
|
|
11584
|
+
return emit(event, ...args);
|
|
11585
|
+
const body = args[0]?.body;
|
|
11586
|
+
if (checkInboundWorkspace(body, getIdentity()).own)
|
|
11587
|
+
return emit(event, ...args);
|
|
11588
|
+
return true;
|
|
11589
|
+
};
|
|
11590
|
+
}
|
|
11591
|
+
var resolveIdentity = null, identity = null, pending = null, WITHHELD_LOG_INTERVAL_MS = 60000, lastWithheldLogAt;
|
|
11592
|
+
var init_workspace_guard = __esm(() => {
|
|
11593
|
+
init_env_flag();
|
|
11594
|
+
lastWithheldLogAt = new Map;
|
|
11595
|
+
});
|
|
11596
|
+
|
|
11414
11597
|
// src/slack/inbound-dispatch.ts
|
|
11415
11598
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
11416
11599
|
import { createHash } from "node:crypto";
|
|
@@ -11478,10 +11661,19 @@ function recordSlackSocketAckNotReady() {
|
|
|
11478
11661
|
counters.socket.ackNotReady += 1;
|
|
11479
11662
|
}
|
|
11480
11663
|
function slackInboundOutcomeMiddleware() {
|
|
11481
|
-
return async ({ next }) => {
|
|
11664
|
+
return async ({ next, body }) => {
|
|
11665
|
+
const identity = getCachedSlackWorkspaceIdentity();
|
|
11666
|
+
const ownership = checkInboundWorkspace(body, identity);
|
|
11482
11667
|
const existing = deliveryStorage.getStore();
|
|
11483
11668
|
if (existing) {
|
|
11484
11669
|
existing.dispatched = true;
|
|
11670
|
+
if (!ownership.own) {
|
|
11671
|
+
if (!identity)
|
|
11672
|
+
existing.failures.push("workspace_identity_unavailable");
|
|
11673
|
+
else
|
|
11674
|
+
existing.ignoredReasons.push(ownership.reason);
|
|
11675
|
+
return;
|
|
11676
|
+
}
|
|
11485
11677
|
try {
|
|
11486
11678
|
await next();
|
|
11487
11679
|
} catch (error) {
|
|
@@ -11492,6 +11684,11 @@ function slackInboundOutcomeMiddleware() {
|
|
|
11492
11684
|
}
|
|
11493
11685
|
const state = newDeliveryState("socket", false);
|
|
11494
11686
|
state.dispatched = true;
|
|
11687
|
+
if (!ownership.own) {
|
|
11688
|
+
state.ignoredReasons.push(ownership.reason);
|
|
11689
|
+
recordOutcome("socket", resolveSlackInboundOutcome(state));
|
|
11690
|
+
return;
|
|
11691
|
+
}
|
|
11495
11692
|
await deliveryStorage.run(state, async () => {
|
|
11496
11693
|
try {
|
|
11497
11694
|
await next();
|
|
@@ -11727,6 +11924,7 @@ var init_inbound_dispatch = __esm(() => {
|
|
|
11727
11924
|
init_slack_inbound();
|
|
11728
11925
|
init_secret_scrubber();
|
|
11729
11926
|
init_config4();
|
|
11927
|
+
init_workspace_guard();
|
|
11730
11928
|
deliveryStorage = new AsyncLocalStorage;
|
|
11731
11929
|
counters = {
|
|
11732
11930
|
socket: emptyCounters(),
|
|
@@ -11734,6 +11932,30 @@ var init_inbound_dispatch = __esm(() => {
|
|
|
11734
11932
|
};
|
|
11735
11933
|
});
|
|
11736
11934
|
|
|
11935
|
+
// src/slack/lifecycle-lock.ts
|
|
11936
|
+
async function runSlackLifecycleExclusive(fn) {
|
|
11937
|
+
holders += 1;
|
|
11938
|
+
const previous = tail;
|
|
11939
|
+
let release;
|
|
11940
|
+
tail = new Promise((resolve) => {
|
|
11941
|
+
release = resolve;
|
|
11942
|
+
});
|
|
11943
|
+
try {
|
|
11944
|
+
await previous;
|
|
11945
|
+
return await fn();
|
|
11946
|
+
} finally {
|
|
11947
|
+
holders -= 1;
|
|
11948
|
+
release();
|
|
11949
|
+
}
|
|
11950
|
+
}
|
|
11951
|
+
function isSlackLifecycleBusy() {
|
|
11952
|
+
return holders > 0;
|
|
11953
|
+
}
|
|
11954
|
+
var tail, holders = 0;
|
|
11955
|
+
var init_lifecycle_lock = __esm(() => {
|
|
11956
|
+
tail = Promise.resolve();
|
|
11957
|
+
});
|
|
11958
|
+
|
|
11737
11959
|
// src/slack/socket-ack.ts
|
|
11738
11960
|
function isSocketNotReadyError(error) {
|
|
11739
11961
|
return error instanceof Error && error.message === NOT_READY_MESSAGE;
|
|
@@ -11848,6 +12070,53 @@ var init_socket_ack = __esm(() => {
|
|
|
11848
12070
|
ORDER_DEPENDENT_EVENTS = new Set(["assistant_thread_context_changed"]);
|
|
11849
12071
|
});
|
|
11850
12072
|
|
|
12073
|
+
// src/slack/socket-fence.ts
|
|
12074
|
+
function fenceSocketModeClient(client) {
|
|
12075
|
+
let retired = false;
|
|
12076
|
+
const retrieveWSSURL = Reflect.get(client, "retrieveWSSURL");
|
|
12077
|
+
if (typeof retrieveWSSURL !== "function") {
|
|
12078
|
+
throw new Error("@slack/socket-mode changed: SocketModeClient.retrieveWSSURL is missing");
|
|
12079
|
+
}
|
|
12080
|
+
const start = client.start;
|
|
12081
|
+
Reflect.set(client, "retrieveWSSURL", async function() {
|
|
12082
|
+
if (retired)
|
|
12083
|
+
throw new SlackSocketClientRetiredError;
|
|
12084
|
+
let url;
|
|
12085
|
+
try {
|
|
12086
|
+
url = await retrieveWSSURL.call(this);
|
|
12087
|
+
} catch (error) {
|
|
12088
|
+
if (retired)
|
|
12089
|
+
throw new SlackSocketClientRetiredError;
|
|
12090
|
+
throw error;
|
|
12091
|
+
}
|
|
12092
|
+
if (retired)
|
|
12093
|
+
throw new SlackSocketClientRetiredError;
|
|
12094
|
+
return url;
|
|
12095
|
+
});
|
|
12096
|
+
Reflect.set(client, "start", function() {
|
|
12097
|
+
return start.call(this).catch((error) => {
|
|
12098
|
+
if (error instanceof SlackSocketClientRetiredError)
|
|
12099
|
+
return;
|
|
12100
|
+
throw error;
|
|
12101
|
+
});
|
|
12102
|
+
});
|
|
12103
|
+
return {
|
|
12104
|
+
retire: () => {
|
|
12105
|
+
retired = true;
|
|
12106
|
+
},
|
|
12107
|
+
isRetired: () => retired
|
|
12108
|
+
};
|
|
12109
|
+
}
|
|
12110
|
+
var SlackSocketClientRetiredError;
|
|
12111
|
+
var init_socket_fence = __esm(() => {
|
|
12112
|
+
SlackSocketClientRetiredError = class SlackSocketClientRetiredError extends Error {
|
|
12113
|
+
constructor() {
|
|
12114
|
+
super("Slack socket-mode client was retired; it opens no new socket");
|
|
12115
|
+
this.name = "SlackSocketClientRetiredError";
|
|
12116
|
+
}
|
|
12117
|
+
};
|
|
12118
|
+
});
|
|
12119
|
+
|
|
11851
12120
|
// src/slack/socket-mode-guard.ts
|
|
11852
12121
|
function getSlackSocketModeBlockReason(env) {
|
|
11853
12122
|
if (env.NODE_ENV !== "development")
|
|
@@ -11886,7 +12155,7 @@ async function initOtel(serviceRole = process.env.AGENT_ROLE || "api") {
|
|
|
11886
12155
|
return;
|
|
11887
12156
|
initialized = true;
|
|
11888
12157
|
try {
|
|
11889
|
-
const impl = await import("./otel-impl-
|
|
12158
|
+
const impl = await import("./otel-impl-yyy203z8.js");
|
|
11890
12159
|
await impl.boot(serviceRole, {
|
|
11891
12160
|
exportConsoleLogs: serviceRole === "api" && isApiLogExportEnabled()
|
|
11892
12161
|
});
|
|
@@ -14866,6 +15135,7 @@ async function refreshResolvedDeferralCards() {
|
|
|
14866
15135
|
} else {
|
|
14867
15136
|
await markSlackDeferralResolved2(card.id);
|
|
14868
15137
|
}
|
|
15138
|
+
markSlackThreadDirty(card.channelId, card.threadTs);
|
|
14869
15139
|
deferralRefreshAttempts.delete(card.id);
|
|
14870
15140
|
if (!isDeferredTask(wake))
|
|
14871
15141
|
await finalizeTerminalSlackReactions([wake]);
|
|
@@ -14883,240 +15153,373 @@ async function refreshResolvedDeferralCards() {
|
|
|
14883
15153
|
}
|
|
14884
15154
|
}
|
|
14885
15155
|
}
|
|
14886
|
-
async function
|
|
15156
|
+
async function renderStoredTree(storedTree, { activatedAt, delegationEnabled, delegationActivatedAt, statusTick }) {
|
|
14887
15157
|
if (!isSlackRenderV2Enabled2())
|
|
14888
|
-
return;
|
|
14889
|
-
|
|
14890
|
-
const
|
|
14891
|
-
|
|
14892
|
-
const statusTick = beginSlackStatusTick();
|
|
14893
|
-
for (const task of await getSlackTasksMissingTree2()) {
|
|
14894
|
-
if (!isSlackRenderV2Enabled2())
|
|
14895
|
-
return;
|
|
14896
|
-
if (!task.slackChannelId || !task.slackThreadTs)
|
|
14897
|
-
continue;
|
|
15158
|
+
return "stop";
|
|
15159
|
+
let tree = storedTree;
|
|
15160
|
+
const initialTasks = await getSlackTasksInThread2(tree.channelId, tree.threadTs);
|
|
15161
|
+
if (isPendingSlackMessage2(tree)) {
|
|
14898
15162
|
try {
|
|
14899
|
-
await ensureSlackThreadTree2(
|
|
15163
|
+
const recovered = await ensureSlackThreadTree2(initialTasks.map((task) => task.id), statusTick.budget);
|
|
15164
|
+
if (!recovered)
|
|
15165
|
+
return "skipped";
|
|
15166
|
+
tree = recovered;
|
|
14900
15167
|
} catch (error) {
|
|
14901
|
-
console.error(`[Slack] Failed to
|
|
15168
|
+
console.error(`[Slack] Failed to recover pending v2 tree ${tree.id}:`, error);
|
|
15169
|
+
return "skipped";
|
|
14902
15170
|
}
|
|
14903
15171
|
}
|
|
14904
|
-
|
|
14905
|
-
|
|
14906
|
-
|
|
14907
|
-
|
|
14908
|
-
|
|
14909
|
-
|
|
14910
|
-
try {
|
|
14911
|
-
const recovered = await ensureSlackThreadTree2(initialTasks.map((task) => task.id), statusTick.budget);
|
|
14912
|
-
if (!recovered)
|
|
14913
|
-
continue;
|
|
14914
|
-
tree = recovered;
|
|
14915
|
-
} catch (error) {
|
|
14916
|
-
console.error(`[Slack] Failed to recover pending v2 tree ${tree.id}:`, error);
|
|
14917
|
-
continue;
|
|
14918
|
-
}
|
|
14919
|
-
}
|
|
14920
|
-
const app = getSlackApp2();
|
|
14921
|
-
if (app && !tree.permalink) {
|
|
14922
|
-
try {
|
|
14923
|
-
tree = await ensureTreePermalink(app.client, tree);
|
|
14924
|
-
} catch (error) {
|
|
14925
|
-
if (isSlackMessageNotFound(error)) {
|
|
14926
|
-
try {
|
|
14927
|
-
await replaceMissingTree(tree, statusTick.budget);
|
|
14928
|
-
} catch (replacementError) {
|
|
14929
|
-
console.error(`[Slack] Failed to replace missing v2 tree ${tree.id}:`, replacementError);
|
|
14930
|
-
}
|
|
14931
|
-
continue;
|
|
14932
|
-
}
|
|
14933
|
-
console.error(`[Slack] Failed to resolve v2 tree permalink ${tree.id}:`, error);
|
|
14934
|
-
continue;
|
|
14935
|
-
}
|
|
14936
|
-
}
|
|
14937
|
-
let tasks = await getSlackTasksInThread2(tree.channelId, tree.threadTs);
|
|
14938
|
-
let needsOutcome = false;
|
|
14939
|
-
for (const task of tasks) {
|
|
14940
|
-
const card = await getSlackOutcomeMessage2(task.id);
|
|
14941
|
-
if (card && isSettledSlackMessage2(card))
|
|
14942
|
-
continue;
|
|
14943
|
-
const isDirectCandidate = await taskNeedsDirectOutcome(task, activatedAt) && isOutcomeStatus(task.status) && !await isAnsweredByDeferralCard(task, tasks);
|
|
14944
|
-
const isChildCandidate = delegationEnabled && delegationActivatedAt !== null && isChildCardCandidate(task, delegationActivatedAt) && !task.slackReplySent;
|
|
14945
|
-
if (isDirectCandidate || isChildCandidate) {
|
|
14946
|
-
needsOutcome = true;
|
|
14947
|
-
break;
|
|
14948
|
-
}
|
|
14949
|
-
}
|
|
14950
|
-
if (needsOutcome && app) {
|
|
14951
|
-
try {
|
|
14952
|
-
await resolvePermalink(app.client, tree.channelId, tree.ts);
|
|
14953
|
-
} catch (error) {
|
|
14954
|
-
if (!isSlackMessageNotFound(error)) {
|
|
14955
|
-
console.error(`[Slack] Failed to verify v2 tree ${tree.id}:`, error);
|
|
14956
|
-
continue;
|
|
14957
|
-
}
|
|
15172
|
+
const app = getSlackApp2();
|
|
15173
|
+
if (app && !tree.permalink) {
|
|
15174
|
+
try {
|
|
15175
|
+
tree = await ensureTreePermalink(app.client, tree);
|
|
15176
|
+
} catch (error) {
|
|
15177
|
+
if (isSlackMessageNotFound(error)) {
|
|
14958
15178
|
try {
|
|
14959
|
-
|
|
14960
|
-
if (!replacement)
|
|
14961
|
-
continue;
|
|
14962
|
-
tree = replacement;
|
|
14963
|
-
tasks = await getSlackTasksInThread2(tree.channelId, tree.threadTs);
|
|
15179
|
+
await replaceMissingTree(tree, statusTick.budget);
|
|
14964
15180
|
} catch (replacementError) {
|
|
14965
15181
|
console.error(`[Slack] Failed to replace missing v2 tree ${tree.id}:`, replacementError);
|
|
14966
|
-
continue;
|
|
14967
15182
|
}
|
|
15183
|
+
return "skipped";
|
|
14968
15184
|
}
|
|
15185
|
+
console.error(`[Slack] Failed to resolve v2 tree permalink ${tree.id}:`, error);
|
|
15186
|
+
return "skipped";
|
|
14969
15187
|
}
|
|
14970
|
-
|
|
14971
|
-
|
|
14972
|
-
|
|
14973
|
-
|
|
14974
|
-
|
|
14975
|
-
|
|
14976
|
-
|
|
14977
|
-
|
|
14978
|
-
|
|
14979
|
-
|
|
14980
|
-
|
|
14981
|
-
|
|
15188
|
+
}
|
|
15189
|
+
let tasks = await getSlackTasksInThread2(tree.channelId, tree.threadTs);
|
|
15190
|
+
let needsOutcome = false;
|
|
15191
|
+
for (const task of tasks) {
|
|
15192
|
+
const card = await getSlackOutcomeMessage2(task.id);
|
|
15193
|
+
if (card && isSettledSlackMessage2(card))
|
|
15194
|
+
continue;
|
|
15195
|
+
const isDirectCandidate = await taskNeedsDirectOutcome(task, activatedAt) && isOutcomeStatus(task.status) && !await isAnsweredByDeferralCard(task, tasks);
|
|
15196
|
+
const isChildCandidate = delegationEnabled && delegationActivatedAt !== null && isChildCardCandidate(task, delegationActivatedAt) && !task.slackReplySent;
|
|
15197
|
+
if (isDirectCandidate || isChildCandidate) {
|
|
15198
|
+
needsOutcome = true;
|
|
15199
|
+
break;
|
|
15200
|
+
}
|
|
15201
|
+
}
|
|
15202
|
+
if (needsOutcome && app) {
|
|
15203
|
+
try {
|
|
15204
|
+
await resolvePermalink(app.client, tree.channelId, tree.ts);
|
|
15205
|
+
} catch (error) {
|
|
15206
|
+
if (!isSlackMessageNotFound(error)) {
|
|
15207
|
+
console.error(`[Slack] Failed to verify v2 tree ${tree.id}:`, error);
|
|
15208
|
+
return "skipped";
|
|
15209
|
+
}
|
|
15210
|
+
try {
|
|
15211
|
+
const replacement = await replaceMissingTree(tree, statusTick.budget);
|
|
15212
|
+
if (!replacement)
|
|
15213
|
+
return "skipped";
|
|
15214
|
+
tree = replacement;
|
|
15215
|
+
tasks = await getSlackTasksInThread2(tree.channelId, tree.threadTs);
|
|
15216
|
+
} catch (replacementError) {
|
|
15217
|
+
console.error(`[Slack] Failed to replace missing v2 tree ${tree.id}:`, replacementError);
|
|
15218
|
+
return "skipped";
|
|
14982
15219
|
}
|
|
14983
15220
|
}
|
|
14984
|
-
|
|
14985
|
-
|
|
14986
|
-
|
|
14987
|
-
|
|
14988
|
-
|
|
14989
|
-
|
|
14990
|
-
|
|
15221
|
+
}
|
|
15222
|
+
const settleSec = Number(process.env.SLACK_CONCLUSION_SETTLE_SEC) || 10;
|
|
15223
|
+
const timeoutMin = Number(process.env.SLACK_CONCLUSION_TIMEOUT_MIN) || 240;
|
|
15224
|
+
const closuresByAskId = new Map;
|
|
15225
|
+
const ownerAskId = new Map;
|
|
15226
|
+
if (delegationEnabled) {
|
|
15227
|
+
for (const ask of tasks.filter((candidate) => candidate.source === "slack")) {
|
|
15228
|
+
const closure = buildAskClosure(ask, tasks);
|
|
15229
|
+
closuresByAskId.set(ask.id, closure);
|
|
14991
15230
|
for (const member of closure) {
|
|
14992
|
-
if (
|
|
14993
|
-
|
|
15231
|
+
if (!ownerAskId.has(member.id))
|
|
15232
|
+
ownerAskId.set(member.id, ask.id);
|
|
14994
15233
|
}
|
|
14995
|
-
childCardCounts.set(askId, count);
|
|
14996
|
-
return count;
|
|
14997
15234
|
}
|
|
14998
|
-
|
|
14999
|
-
|
|
15000
|
-
|
|
15001
|
-
|
|
15002
|
-
|
|
15003
|
-
|
|
15004
|
-
|
|
15005
|
-
|
|
15006
|
-
|
|
15007
|
-
|
|
15008
|
-
|
|
15009
|
-
|
|
15010
|
-
|
|
15011
|
-
|
|
15012
|
-
|
|
15013
|
-
|
|
15014
|
-
|
|
15015
|
-
|
|
15016
|
-
|
|
15017
|
-
|
|
15018
|
-
|
|
15019
|
-
|
|
15235
|
+
}
|
|
15236
|
+
const childCardCounts = new Map;
|
|
15237
|
+
async function childCardCountFor(askId) {
|
|
15238
|
+
const cached = childCardCounts.get(askId);
|
|
15239
|
+
if (cached !== undefined)
|
|
15240
|
+
return cached;
|
|
15241
|
+
const closure = closuresByAskId.get(askId) ?? [];
|
|
15242
|
+
let count = 0;
|
|
15243
|
+
for (const member of closure) {
|
|
15244
|
+
if (await getSlackOutcomeMessage2(member.id))
|
|
15245
|
+
count++;
|
|
15246
|
+
}
|
|
15247
|
+
childCardCounts.set(askId, count);
|
|
15248
|
+
return count;
|
|
15249
|
+
}
|
|
15250
|
+
let outcomeCreated = false;
|
|
15251
|
+
let childCardsThisTick = 0;
|
|
15252
|
+
for (const task of tasks) {
|
|
15253
|
+
if (!isSlackRenderV2Enabled2())
|
|
15254
|
+
return "stop";
|
|
15255
|
+
if (task.source === "slack")
|
|
15256
|
+
continue;
|
|
15257
|
+
const card = await getSlackOutcomeMessage2(task.id);
|
|
15258
|
+
if (card && isSettledSlackMessage2(card))
|
|
15259
|
+
continue;
|
|
15260
|
+
if (!delegationEnabled || delegationActivatedAt === null)
|
|
15261
|
+
continue;
|
|
15262
|
+
if (!isChildCardCandidate(task, delegationActivatedAt) || task.slackReplySent)
|
|
15263
|
+
continue;
|
|
15264
|
+
const askId = ownerAskId.get(task.id);
|
|
15265
|
+
const ownerAsk = askId ? tasks.find((candidate) => candidate.id === askId) : undefined;
|
|
15266
|
+
if (!ownerAsk || ownerAsk.createdAt < delegationActivatedAt)
|
|
15267
|
+
continue;
|
|
15268
|
+
if (childCardsThisTick >= CHILD_CARDS_PER_TICK)
|
|
15269
|
+
continue;
|
|
15270
|
+
if (askId && await childCardCountFor(askId) >= CHILD_CARDS_PER_ASK)
|
|
15271
|
+
continue;
|
|
15272
|
+
if (!await checkOutcomeDeliveryGate(task, card, statusTick.budget))
|
|
15273
|
+
continue;
|
|
15274
|
+
try {
|
|
15275
|
+
const outcome = await streamOutcomeCard(task, tree, {
|
|
15276
|
+
buildContent: childOutcomeContent,
|
|
15277
|
+
statusBudget: statusTick.budget
|
|
15278
|
+
});
|
|
15279
|
+
if (outcome) {
|
|
15280
|
+
noteOutcomeDeliverySuccess(task.id);
|
|
15281
|
+
childCardsThisTick++;
|
|
15282
|
+
if (askId)
|
|
15283
|
+
childCardCounts.set(askId, (childCardCounts.get(askId) ?? 0) + 1);
|
|
15284
|
+
await recordSlackDelivery(task, outcome, "child_outcome");
|
|
15285
|
+
}
|
|
15286
|
+
outcomeCreated ||= !!outcome;
|
|
15287
|
+
} catch (error) {
|
|
15288
|
+
await noteOutcomeDeliveryFailure(task, tree, error, statusTick.budget);
|
|
15289
|
+
}
|
|
15290
|
+
}
|
|
15291
|
+
for (const task of tasks) {
|
|
15292
|
+
if (!isSlackRenderV2Enabled2())
|
|
15293
|
+
return "stop";
|
|
15294
|
+
if (!await taskNeedsDirectOutcome(task, activatedAt))
|
|
15295
|
+
continue;
|
|
15296
|
+
const card = await getSlackOutcomeMessage2(task.id);
|
|
15297
|
+
if (card && isSettledSlackMessage2(card))
|
|
15298
|
+
continue;
|
|
15299
|
+
if (await isAnsweredByDeferralCard(task, tasks))
|
|
15300
|
+
continue;
|
|
15301
|
+
const deferByClosure = task.source === "slack" && delegationEnabled && delegationActivatedAt !== null && task.createdAt >= delegationActivatedAt;
|
|
15302
|
+
if (!deferByClosure) {
|
|
15020
15303
|
if (!await checkOutcomeDeliveryGate(task, card, statusTick.budget))
|
|
15021
15304
|
continue;
|
|
15022
15305
|
try {
|
|
15023
|
-
const outcome = await streamOutcomeCard(task, tree, {
|
|
15024
|
-
buildContent: childOutcomeContent,
|
|
15025
|
-
statusBudget: statusTick.budget
|
|
15026
|
-
});
|
|
15306
|
+
const outcome = await streamOutcomeCard(task, tree, { statusBudget: statusTick.budget });
|
|
15027
15307
|
if (outcome) {
|
|
15028
15308
|
noteOutcomeDeliverySuccess(task.id);
|
|
15029
|
-
|
|
15030
|
-
if (askId)
|
|
15031
|
-
childCardCounts.set(askId, (childCardCounts.get(askId) ?? 0) + 1);
|
|
15032
|
-
await recordSlackDelivery(task, outcome, "child_outcome");
|
|
15309
|
+
await finalizeTerminalSlackReactions([task]);
|
|
15033
15310
|
}
|
|
15034
15311
|
outcomeCreated ||= !!outcome;
|
|
15035
15312
|
} catch (error) {
|
|
15036
15313
|
await noteOutcomeDeliveryFailure(task, tree, error, statusTick.budget);
|
|
15037
15314
|
}
|
|
15315
|
+
continue;
|
|
15038
15316
|
}
|
|
15039
|
-
|
|
15040
|
-
|
|
15041
|
-
|
|
15042
|
-
|
|
15043
|
-
|
|
15044
|
-
const card = await getSlackOutcomeMessage2(task.id);
|
|
15045
|
-
if (card && isSettledSlackMessage2(card))
|
|
15046
|
-
continue;
|
|
15047
|
-
if (await isAnsweredByDeferralCard(task, tasks))
|
|
15317
|
+
const closure = closuresByAskId.get(task.id) ?? buildAskClosure(task, tasks);
|
|
15318
|
+
let childCardPending = false;
|
|
15319
|
+
const existingChildCards = await childCardCountFor(task.id);
|
|
15320
|
+
for (const member of closure) {
|
|
15321
|
+
if (!isChildCardCandidate(member, delegationActivatedAt) || member.slackReplySent)
|
|
15048
15322
|
continue;
|
|
15049
|
-
|
|
15050
|
-
|
|
15051
|
-
|
|
15052
|
-
|
|
15053
|
-
|
|
15054
|
-
|
|
15055
|
-
if (outcome) {
|
|
15056
|
-
noteOutcomeDeliverySuccess(task.id);
|
|
15057
|
-
await finalizeTerminalSlackReactions([task]);
|
|
15058
|
-
}
|
|
15059
|
-
outcomeCreated ||= !!outcome;
|
|
15060
|
-
} catch (error) {
|
|
15061
|
-
await noteOutcomeDeliveryFailure(task, tree, error, statusTick.budget);
|
|
15062
|
-
}
|
|
15063
|
-
continue;
|
|
15064
|
-
}
|
|
15065
|
-
const closure = closuresByAskId.get(task.id) ?? buildAskClosure(task, tasks);
|
|
15066
|
-
let childCardPending = false;
|
|
15067
|
-
const existingChildCards = await childCardCountFor(task.id);
|
|
15068
|
-
for (const member of closure) {
|
|
15069
|
-
if (!isChildCardCandidate(member, delegationActivatedAt) || member.slackReplySent)
|
|
15070
|
-
continue;
|
|
15071
|
-
if (existingChildCards >= CHILD_CARDS_PER_ASK)
|
|
15072
|
-
break;
|
|
15073
|
-
const memberCard = await getSlackOutcomeMessage2(member.id);
|
|
15074
|
-
if (!memberCard || !isSettledSlackMessage2(memberCard)) {
|
|
15075
|
-
childCardPending = true;
|
|
15076
|
-
break;
|
|
15077
|
-
}
|
|
15323
|
+
if (existingChildCards >= CHILD_CARDS_PER_ASK)
|
|
15324
|
+
break;
|
|
15325
|
+
const memberCard = await getSlackOutcomeMessage2(member.id);
|
|
15326
|
+
if (!memberCard || !isSettledSlackMessage2(memberCard)) {
|
|
15327
|
+
childCardPending = true;
|
|
15328
|
+
break;
|
|
15078
15329
|
}
|
|
15079
|
-
|
|
15080
|
-
|
|
15081
|
-
|
|
15082
|
-
|
|
15083
|
-
|
|
15084
|
-
|
|
15085
|
-
|
|
15086
|
-
|
|
15087
|
-
|
|
15088
|
-
|
|
15089
|
-
|
|
15090
|
-
|
|
15091
|
-
|
|
15092
|
-
|
|
15093
|
-
|
|
15094
|
-
|
|
15095
|
-
|
|
15096
|
-
|
|
15097
|
-
|
|
15098
|
-
|
|
15099
|
-
|
|
15100
|
-
await recordSlackDelivery(task, outcome, state === "timedOut" ? "conclusion_timeout" : "conclusion");
|
|
15330
|
+
}
|
|
15331
|
+
if (childCardPending)
|
|
15332
|
+
continue;
|
|
15333
|
+
const state = closureState(task, closure, new Date, settleSec, timeoutMin);
|
|
15334
|
+
if (state === "open")
|
|
15335
|
+
continue;
|
|
15336
|
+
if (!await checkOutcomeDeliveryGate(task, card, statusTick.budget))
|
|
15337
|
+
continue;
|
|
15338
|
+
try {
|
|
15339
|
+
const outcome = await streamOutcomeCard(task, tree, {
|
|
15340
|
+
buildContent: (_t, slackReplySent) => askConclusionContent(task, closure, state, slackReplySent),
|
|
15341
|
+
conclusionKind: state === "timedOut" ? "timeout" : "complete",
|
|
15342
|
+
statusBudget: statusTick.budget
|
|
15343
|
+
});
|
|
15344
|
+
if (outcome) {
|
|
15345
|
+
noteOutcomeDeliverySuccess(task.id);
|
|
15346
|
+
const app = getSlackApp2();
|
|
15347
|
+
if (app && task.slackChannelId && task.slackTriggerMessageTs) {
|
|
15348
|
+
const reaction = conclusionReactionChoice(state, task, closure);
|
|
15349
|
+
await finalizeSlackMessageReaction(app.client, task.slackChannelId, task.slackTriggerMessageTs, reaction.name, reaction.event);
|
|
15350
|
+
await finalizeSlackSteerReactions([task], () => reaction);
|
|
15101
15351
|
}
|
|
15102
|
-
|
|
15103
|
-
} catch (error) {
|
|
15104
|
-
await noteOutcomeDeliveryFailure(task, tree, error, statusTick.budget);
|
|
15352
|
+
await recordSlackDelivery(task, outcome, state === "timedOut" ? "conclusion_timeout" : "conclusion");
|
|
15105
15353
|
}
|
|
15354
|
+
outcomeCreated ||= !!outcome;
|
|
15355
|
+
} catch (error) {
|
|
15356
|
+
await noteOutcomeDeliveryFailure(task, tree, error, statusTick.budget);
|
|
15106
15357
|
}
|
|
15358
|
+
}
|
|
15359
|
+
try {
|
|
15360
|
+
await updateThreadTree(tree, outcomeCreated, statusTick.budget);
|
|
15361
|
+
} catch (error) {
|
|
15362
|
+
console.error(`[Slack] Failed to update v2 tree ${tree.id}:`, error);
|
|
15363
|
+
}
|
|
15364
|
+
await statusTick.reconcile(tree.channelId, tree.threadTs);
|
|
15365
|
+
try {
|
|
15366
|
+
if (await closeSlackTreeIfSettled(tree.id))
|
|
15367
|
+
return "closed";
|
|
15368
|
+
} catch (error) {
|
|
15369
|
+
console.error(`[Slack] Failed to close settled v2 tree ${tree.id}:`, error);
|
|
15370
|
+
}
|
|
15371
|
+
return "open";
|
|
15372
|
+
}
|
|
15373
|
+
function yieldToEventLoop() {
|
|
15374
|
+
return new Promise((resolve) => setImmediate(resolve));
|
|
15375
|
+
}
|
|
15376
|
+
function scheduleDirtyFlush(delayMs) {
|
|
15377
|
+
if (!renderEventsSubscribed)
|
|
15378
|
+
return;
|
|
15379
|
+
const at = Date.now() + delayMs;
|
|
15380
|
+
if (dirtyFlushTimer && dirtyFlushAt <= at)
|
|
15381
|
+
return;
|
|
15382
|
+
if (dirtyFlushTimer)
|
|
15383
|
+
clearTimeout(dirtyFlushTimer);
|
|
15384
|
+
dirtyFlushAt = at;
|
|
15385
|
+
dirtyFlushTimer = setTimeout(() => {
|
|
15386
|
+
dirtyFlushTimer = null;
|
|
15387
|
+
flushSlackRenderV2DirtyThreads().catch((error) => {
|
|
15388
|
+
console.error("[Slack] Event-driven v2 render failed:", error);
|
|
15389
|
+
});
|
|
15390
|
+
}, delayMs);
|
|
15391
|
+
}
|
|
15392
|
+
function markSlackThreadDirty(channelId, threadTs, delayMs = DIRTY_FLUSH_DEBOUNCE_MS) {
|
|
15393
|
+
dirtyThreads.set(`${channelId}\x00${threadTs}`, { channelId, threadTs });
|
|
15394
|
+
scheduleDirtyFlush(delayMs);
|
|
15395
|
+
}
|
|
15396
|
+
function onSlackRenderTaskEvent(data) {
|
|
15397
|
+
const taskId = data?.taskId;
|
|
15398
|
+
if (typeof taskId !== "string")
|
|
15399
|
+
return;
|
|
15400
|
+
dirtyTaskIds.add(taskId);
|
|
15401
|
+
scheduleDirtyFlush(DIRTY_FLUSH_DEBOUNCE_MS);
|
|
15402
|
+
}
|
|
15403
|
+
function startSlackRenderV2Events2() {
|
|
15404
|
+
if (renderEventsSubscribed)
|
|
15405
|
+
return;
|
|
15406
|
+
for (const event of SLACK_RENDER_TASK_EVENTS)
|
|
15407
|
+
workflowEventBus2.on(event, onSlackRenderTaskEvent);
|
|
15408
|
+
renderEventsSubscribed = true;
|
|
15409
|
+
}
|
|
15410
|
+
function stopSlackRenderV2Events2() {
|
|
15411
|
+
if (!renderEventsSubscribed)
|
|
15412
|
+
return;
|
|
15413
|
+
for (const event of SLACK_RENDER_TASK_EVENTS)
|
|
15414
|
+
workflowEventBus2.off(event, onSlackRenderTaskEvent);
|
|
15415
|
+
renderEventsSubscribed = false;
|
|
15416
|
+
if (dirtyFlushTimer)
|
|
15417
|
+
clearTimeout(dirtyFlushTimer);
|
|
15418
|
+
dirtyFlushTimer = null;
|
|
15419
|
+
}
|
|
15420
|
+
function runExclusive(work) {
|
|
15421
|
+
if (renderInFlight)
|
|
15422
|
+
return renderInFlight;
|
|
15423
|
+
const run = (async () => {
|
|
15107
15424
|
try {
|
|
15108
|
-
await
|
|
15425
|
+
await work();
|
|
15426
|
+
} finally {
|
|
15427
|
+
renderInFlight = null;
|
|
15428
|
+
}
|
|
15429
|
+
})();
|
|
15430
|
+
renderInFlight = run;
|
|
15431
|
+
return run;
|
|
15432
|
+
}
|
|
15433
|
+
async function beginRenderPass() {
|
|
15434
|
+
const activatedAt = await ensureSlackRenderV2Activation2();
|
|
15435
|
+
const delegationEnabled = isSlackDelegationEnabled();
|
|
15436
|
+
const delegationActivatedAt = delegationEnabled ? await ensureSlackDelegationActivation2() : null;
|
|
15437
|
+
return {
|
|
15438
|
+
activatedAt,
|
|
15439
|
+
delegationEnabled,
|
|
15440
|
+
delegationActivatedAt,
|
|
15441
|
+
statusTick: beginSlackStatusTick()
|
|
15442
|
+
};
|
|
15443
|
+
}
|
|
15444
|
+
async function flushSlackRenderV2DirtyThreads() {
|
|
15445
|
+
if (!isSlackRenderV2Enabled2() || !getSlackApp2())
|
|
15446
|
+
return;
|
|
15447
|
+
if (renderInFlight) {
|
|
15448
|
+
await renderInFlight;
|
|
15449
|
+
if (dirtyTaskIds.size === 0 && dirtyThreads.size === 0)
|
|
15450
|
+
return;
|
|
15451
|
+
}
|
|
15452
|
+
await runExclusive(renderDirtyThreads);
|
|
15453
|
+
}
|
|
15454
|
+
function processSlackRenderV22() {
|
|
15455
|
+
if (!isSlackRenderV2Enabled2())
|
|
15456
|
+
return Promise.resolve();
|
|
15457
|
+
return runExclusive(reconcileAllThreads);
|
|
15458
|
+
}
|
|
15459
|
+
async function reconcileAllThreads() {
|
|
15460
|
+
dirtyTaskIds.clear();
|
|
15461
|
+
dirtyThreads.clear();
|
|
15462
|
+
const context = await beginRenderPass();
|
|
15463
|
+
for (const task of await getSlackTasksMissingTree2()) {
|
|
15464
|
+
if (!isSlackRenderV2Enabled2())
|
|
15465
|
+
return;
|
|
15466
|
+
if (!task.slackChannelId || !task.slackThreadTs)
|
|
15467
|
+
continue;
|
|
15468
|
+
try {
|
|
15469
|
+
await ensureSlackThreadTree2([task.id], context.statusTick.budget);
|
|
15109
15470
|
} catch (error) {
|
|
15110
|
-
console.error(`[Slack] Failed to
|
|
15471
|
+
console.error(`[Slack] Failed to create v2 tree for task ${task.id}:`, error);
|
|
15111
15472
|
}
|
|
15112
|
-
|
|
15473
|
+
}
|
|
15474
|
+
await yieldToEventLoop();
|
|
15475
|
+
for (const storedTree of await getSlackTreeMessages2()) {
|
|
15476
|
+
if (await renderStoredTree(storedTree, context) === "stop")
|
|
15477
|
+
return;
|
|
15478
|
+
await yieldToEventLoop();
|
|
15113
15479
|
}
|
|
15114
15480
|
await refreshResolvedDeferralCards();
|
|
15115
|
-
await
|
|
15481
|
+
await yieldToEventLoop();
|
|
15482
|
+
await context.statusTick.finish();
|
|
15483
|
+
}
|
|
15484
|
+
async function renderDirtyThreads() {
|
|
15485
|
+
const taskIds = [...dirtyTaskIds];
|
|
15486
|
+
dirtyTaskIds.clear();
|
|
15487
|
+
const threads = new Map(dirtyThreads);
|
|
15488
|
+
dirtyThreads.clear();
|
|
15489
|
+
const touched = await getSlackThreadsOfTasks(taskIds);
|
|
15490
|
+
for (const thread of touched.threads) {
|
|
15491
|
+
threads.set(`${thread.channelId}\x00${thread.threadTs}`, thread);
|
|
15492
|
+
}
|
|
15493
|
+
if (threads.size === 0 && !touched.wakeTouched)
|
|
15494
|
+
return;
|
|
15495
|
+
const context = await beginRenderPass();
|
|
15496
|
+
for (const thread of threads.values()) {
|
|
15497
|
+
if (!isSlackRenderV2Enabled2())
|
|
15498
|
+
return;
|
|
15499
|
+
for (const task of await getSlackTasksMissingTree2({ thread })) {
|
|
15500
|
+
try {
|
|
15501
|
+
await ensureSlackThreadTree2([task.id], context.statusTick.budget);
|
|
15502
|
+
} catch (error) {
|
|
15503
|
+
console.error(`[Slack] Failed to create v2 tree for task ${task.id}:`, error);
|
|
15504
|
+
}
|
|
15505
|
+
}
|
|
15506
|
+
for (const storedTree of await getSlackTreeMessages2({ thread })) {
|
|
15507
|
+
const result = await renderStoredTree(storedTree, context);
|
|
15508
|
+
if (result === "stop")
|
|
15509
|
+
return;
|
|
15510
|
+
if (result !== "closed" && await slackThreadHasOutcomeWork(thread)) {
|
|
15511
|
+
markSlackThreadDirty(thread.channelId, thread.threadTs, DIRTY_REVISIT_MS);
|
|
15512
|
+
}
|
|
15513
|
+
}
|
|
15514
|
+
await yieldToEventLoop();
|
|
15515
|
+
}
|
|
15516
|
+
if (touched.wakeTouched)
|
|
15517
|
+
await refreshResolvedDeferralCards();
|
|
15116
15518
|
}
|
|
15117
|
-
var TREE_UPDATE_DEBOUNCE_MS = 500, TREE_UPDATE_MIN_INTERVAL_MS = 3000, MAX_SLACK_RETRIES = 3, MAX_RETRY_DELAY_MS = 30000, MAX_TITLE_LENGTH = 72, MAX_OUTCOME_MARKDOWN_LENGTH = 12000, MAX_TREE_NODE_LINE_LENGTH = 1000, MAX_TREE_PREFIX_LENGTH = 120, MAX_TREE_PROGRESS_LENGTH = 60, CHILD_CARDS_PER_TICK = 3, CHILD_CARDS_PER_ASK = 10, CONCLUSION_DIGEST_LENGTH = 300, TREE_INDENT, FIGURE_SPACE = " ", SLACK_RENDER_METADATA_EVENT = "agent_swarm_render_v2", treeCreationPromises, pendingTreeUpdates, treeUpdateTails, lastTreeText, lastTreeUpdateAt, cachedTeamId, OUTCOME_DELIVERY_MAX_ATTEMPTS = 5, OUTCOME_DELIVERY_BASE_DELAY_MS = 30000, OUTCOME_DELIVERY_MAX_DELAY_MS, outcomeDeliveryNextAttemptAt, outcomeReservedWithoutAttempt, LINE_START_BLOCK, TRANSIENT_SLACK_ERROR_CODES, DEFERRAL_REFRESH_MAX_ATTEMPTS = 5, deferralRefreshAttempts;
|
|
15519
|
+
var TREE_UPDATE_DEBOUNCE_MS = 500, TREE_UPDATE_MIN_INTERVAL_MS = 3000, MAX_SLACK_RETRIES = 3, MAX_RETRY_DELAY_MS = 30000, MAX_TITLE_LENGTH = 72, MAX_OUTCOME_MARKDOWN_LENGTH = 12000, MAX_TREE_NODE_LINE_LENGTH = 1000, MAX_TREE_PREFIX_LENGTH = 120, MAX_TREE_PROGRESS_LENGTH = 60, CHILD_CARDS_PER_TICK = 3, CHILD_CARDS_PER_ASK = 10, CONCLUSION_DIGEST_LENGTH = 300, TREE_INDENT, FIGURE_SPACE = " ", SLACK_RENDER_METADATA_EVENT = "agent_swarm_render_v2", treeCreationPromises, pendingTreeUpdates, treeUpdateTails, lastTreeText, lastTreeUpdateAt, cachedTeamId, OUTCOME_DELIVERY_MAX_ATTEMPTS = 5, OUTCOME_DELIVERY_BASE_DELAY_MS = 30000, OUTCOME_DELIVERY_MAX_DELAY_MS, outcomeDeliveryNextAttemptAt, outcomeReservedWithoutAttempt, LINE_START_BLOCK, TRANSIENT_SLACK_ERROR_CODES, DEFERRAL_REFRESH_MAX_ATTEMPTS = 5, deferralRefreshAttempts, SLACK_RENDER_TASK_EVENTS, DIRTY_FLUSH_DEBOUNCE_MS = 500, DIRTY_REVISIT_MS = 3000, dirtyTaskIds, dirtyThreads, renderInFlight = null, renderEventsSubscribed = false, dirtyFlushTimer = null, dirtyFlushAt = 0;
|
|
15118
15520
|
var init_render_v2 = __esm(() => {
|
|
15119
15521
|
init_db4();
|
|
15522
|
+
init_slack_trees();
|
|
15120
15523
|
init_task_citations2();
|
|
15121
15524
|
init_context_key();
|
|
15122
15525
|
init_business_use();
|
|
@@ -15124,6 +15527,7 @@ var init_render_v2 = __esm(() => {
|
|
|
15124
15527
|
init_secret_scrubber();
|
|
15125
15528
|
init_task_attachment_links();
|
|
15126
15529
|
init_task_citations();
|
|
15530
|
+
init_event_bus();
|
|
15127
15531
|
init_ack();
|
|
15128
15532
|
init_app3();
|
|
15129
15533
|
init_blocks();
|
|
@@ -15153,6 +15557,17 @@ var init_render_v2 = __esm(() => {
|
|
|
15153
15557
|
"external_channel_unverified"
|
|
15154
15558
|
]);
|
|
15155
15559
|
deferralRefreshAttempts = new Map;
|
|
15560
|
+
SLACK_RENDER_TASK_EVENTS = [
|
|
15561
|
+
"task.created",
|
|
15562
|
+
"task.completed",
|
|
15563
|
+
"task.failed",
|
|
15564
|
+
"task.cancelled",
|
|
15565
|
+
"task.skipped",
|
|
15566
|
+
"task.superseded",
|
|
15567
|
+
"task.progress"
|
|
15568
|
+
];
|
|
15569
|
+
dirtyTaskIds = new Set;
|
|
15570
|
+
dirtyThreads = new Map;
|
|
15156
15571
|
});
|
|
15157
15572
|
|
|
15158
15573
|
// src/slack/watcher.ts
|
|
@@ -15504,18 +15919,25 @@ async function processPendingSlackRelays(now = Date.now()) {
|
|
|
15504
15919
|
}
|
|
15505
15920
|
}
|
|
15506
15921
|
}
|
|
15507
|
-
|
|
15922
|
+
function slackTaskWatcherIntervalMs() {
|
|
15923
|
+
const raw = process.env.SLACK_TASK_WATCHER_INTERVAL_MS?.trim();
|
|
15924
|
+
const parsed = raw ? Number(raw) : Number.NaN;
|
|
15925
|
+
return Number.isInteger(parsed) && parsed > 0 ? parsed : DEFAULT_SLACK_TASK_WATCHER_INTERVAL_MS;
|
|
15926
|
+
}
|
|
15927
|
+
async function startTaskWatcher(intervalMs = slackTaskWatcherIntervalMs()) {
|
|
15508
15928
|
if (watcherInterval) {
|
|
15509
15929
|
console.log("[Slack] Task watcher already running");
|
|
15510
15930
|
return;
|
|
15511
15931
|
}
|
|
15932
|
+
const epoch = watcherEpoch;
|
|
15512
15933
|
let hydratedTrees = 0;
|
|
15513
15934
|
let hydratedFlat = 0;
|
|
15514
15935
|
const hydrationTasks = new Map;
|
|
15515
|
-
|
|
15516
|
-
|
|
15517
|
-
|
|
15518
|
-
|
|
15936
|
+
const inProgress = await getInProgressSlackTasks2();
|
|
15937
|
+
const pendingRelays = await getPendingSlackRelayTasks2();
|
|
15938
|
+
if (epoch !== watcherEpoch || watcherInterval)
|
|
15939
|
+
return;
|
|
15940
|
+
for (const task of [...inProgress, ...pendingRelays]) {
|
|
15519
15941
|
hydrationTasks.set(task.id, task);
|
|
15520
15942
|
}
|
|
15521
15943
|
for (const task of hydrationTasks.values()) {
|
|
@@ -15558,7 +15980,8 @@ async function startTaskWatcher(intervalMs = 3000) {
|
|
|
15558
15980
|
if (hydratedTrees > 0 || hydratedFlat > 0) {
|
|
15559
15981
|
console.log(`[Slack] Hydrated ${hydratedTrees} tree task(s) and ${hydratedFlat} flat task(s) from DB`);
|
|
15560
15982
|
}
|
|
15561
|
-
|
|
15983
|
+
startSlackRenderV2Events2();
|
|
15984
|
+
const watcherTick = async () => {
|
|
15562
15985
|
if (isProcessing || !getSlackApp2())
|
|
15563
15986
|
return;
|
|
15564
15987
|
isProcessing = true;
|
|
@@ -15696,20 +16119,24 @@ async function startTaskWatcher(intervalMs = 3000) {
|
|
|
15696
16119
|
} finally {
|
|
15697
16120
|
isProcessing = false;
|
|
15698
16121
|
}
|
|
15699
|
-
}
|
|
16122
|
+
};
|
|
16123
|
+
watcherInterval = setInterval(bindLoopPath("slack.watcher.tick", watcherTick), intervalMs);
|
|
15700
16124
|
console.log(`[Slack] Task watcher started (interval: ${intervalMs}ms)`);
|
|
15701
16125
|
}
|
|
15702
16126
|
function stopTaskWatcher() {
|
|
16127
|
+
watcherEpoch += 1;
|
|
15703
16128
|
if (watcherInterval) {
|
|
15704
16129
|
clearInterval(watcherInterval);
|
|
15705
16130
|
watcherInterval = null;
|
|
15706
16131
|
isProcessing = false;
|
|
16132
|
+
stopSlackRenderV2Events2();
|
|
15707
16133
|
console.log("[Slack] Task watcher stopped");
|
|
15708
16134
|
}
|
|
15709
16135
|
}
|
|
15710
|
-
var watcherInterval = null, isProcessing = false, notifiedCompletions, sentProgress, pendingSends, lastSendTime, MIN_SEND_INTERVAL = 1000, treeMessages, taskToTree, taskMessages, lastRenderedTree, treeLastUpdateTime;
|
|
16136
|
+
var watcherInterval = null, isProcessing = false, watcherEpoch = 0, notifiedCompletions, sentProgress, pendingSends, lastSendTime, MIN_SEND_INTERVAL = 1000, treeMessages, taskToTree, taskMessages, lastRenderedTree, treeLastUpdateTime, DEFAULT_SLACK_TASK_WATCHER_INTERVAL_MS = 1e4;
|
|
15711
16137
|
var init_watcher = __esm(() => {
|
|
15712
16138
|
init_db4();
|
|
16139
|
+
init_event_loop_lag();
|
|
15713
16140
|
init_ack();
|
|
15714
16141
|
init_app3();
|
|
15715
16142
|
init_blocks();
|
|
@@ -15732,10 +16159,128 @@ var init_watcher = __esm(() => {
|
|
|
15732
16159
|
function trackConnectionState(owner) {
|
|
15733
16160
|
for (const [event, state] of Object.entries(SOCKET_EVENT_STATES)) {
|
|
15734
16161
|
owner.client.on(event, () => {
|
|
15735
|
-
if (receiver
|
|
15736
|
-
|
|
16162
|
+
if (receiver !== owner)
|
|
16163
|
+
return;
|
|
16164
|
+
setSlackConnectionState(state);
|
|
16165
|
+
if (state === "connected")
|
|
16166
|
+
lastSocketActivityAt = Date.now();
|
|
15737
16167
|
});
|
|
15738
16168
|
}
|
|
16169
|
+
owner.client.on("slack_event", () => {
|
|
16170
|
+
if (receiver === owner)
|
|
16171
|
+
lastSocketActivityAt = Date.now();
|
|
16172
|
+
});
|
|
16173
|
+
}
|
|
16174
|
+
function slackWatchdogBackoffMs(attempt, options) {
|
|
16175
|
+
return Math.min(options.backoffBaseMs * 2 ** Math.max(0, attempt - 1), options.backoffMaxMs);
|
|
16176
|
+
}
|
|
16177
|
+
function createSlackSocketWatchdog(deps, options = SLACK_SOCKET_WATCHDOG_DEFAULTS) {
|
|
16178
|
+
let downSince = null;
|
|
16179
|
+
let attempts = 0;
|
|
16180
|
+
let nextAttemptAt = 0;
|
|
16181
|
+
let restarting = false;
|
|
16182
|
+
function isHealthy(now) {
|
|
16183
|
+
if (deps.getState() !== "connected")
|
|
16184
|
+
return false;
|
|
16185
|
+
const lastActivityAt = deps.getLastActivityAt();
|
|
16186
|
+
if (lastActivityAt === null || now - lastActivityAt < options.staleActivityMs)
|
|
16187
|
+
return true;
|
|
16188
|
+
return deps.isSocketActive();
|
|
16189
|
+
}
|
|
16190
|
+
async function tick() {
|
|
16191
|
+
if (restarting || deps.isLifecycleBusy())
|
|
16192
|
+
return;
|
|
16193
|
+
const now = deps.now();
|
|
16194
|
+
if (isHealthy(now)) {
|
|
16195
|
+
if (attempts > 0 && downSince !== null) {
|
|
16196
|
+
deps.log(`[Slack] watchdog: recovered after ${seconds(now - downSince)}s`);
|
|
16197
|
+
}
|
|
16198
|
+
downSince = null;
|
|
16199
|
+
attempts = 0;
|
|
16200
|
+
nextAttemptAt = 0;
|
|
16201
|
+
return;
|
|
16202
|
+
}
|
|
16203
|
+
downSince ??= now;
|
|
16204
|
+
if (now - downSince < options.downAfterMs || now < nextAttemptAt)
|
|
16205
|
+
return;
|
|
16206
|
+
attempts += 1;
|
|
16207
|
+
nextAttemptAt = now + slackWatchdogBackoffMs(attempts, options);
|
|
16208
|
+
deps.log(`[Slack] watchdog: socket down for ${seconds(now - downSince)}s, restarting (attempt ${attempts})`);
|
|
16209
|
+
restarting = true;
|
|
16210
|
+
try {
|
|
16211
|
+
await deps.restart();
|
|
16212
|
+
} catch (error) {
|
|
16213
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
16214
|
+
console.error(`[Slack] watchdog: restart failed: ${scrubSecrets(message)}`);
|
|
16215
|
+
} finally {
|
|
16216
|
+
restarting = false;
|
|
16217
|
+
}
|
|
16218
|
+
}
|
|
16219
|
+
return { tick, attempts: () => attempts };
|
|
16220
|
+
}
|
|
16221
|
+
function seconds(ms) {
|
|
16222
|
+
return Math.round(ms / 1000);
|
|
16223
|
+
}
|
|
16224
|
+
function isLiveSocketActive() {
|
|
16225
|
+
return receiver?.client.websocket?.isActive() ?? false;
|
|
16226
|
+
}
|
|
16227
|
+
async function restartSlackAppForWatchdog(owner) {
|
|
16228
|
+
await runSlackLifecycleExclusive(async () => {
|
|
16229
|
+
if (watchdogTimer !== owner)
|
|
16230
|
+
return;
|
|
16231
|
+
if (getSlackConnectionState() === "connected" && isLiveSocketActive())
|
|
16232
|
+
return;
|
|
16233
|
+
let abandoned = false;
|
|
16234
|
+
const restart = (async () => {
|
|
16235
|
+
await teardownSlackApp();
|
|
16236
|
+
if (!abandoned && watchdogTimer === owner)
|
|
16237
|
+
await startSlackApp2();
|
|
16238
|
+
})();
|
|
16239
|
+
const timeoutMs = watchdogOptions.restartTimeoutMs;
|
|
16240
|
+
let timer;
|
|
16241
|
+
const timedOut = new Promise((resolve) => {
|
|
16242
|
+
timer = setTimeout(() => resolve(true), timeoutMs);
|
|
16243
|
+
});
|
|
16244
|
+
try {
|
|
16245
|
+
const outcome = await Promise.race([restart.then(() => false), timedOut]);
|
|
16246
|
+
if (!outcome)
|
|
16247
|
+
return;
|
|
16248
|
+
} finally {
|
|
16249
|
+
clearTimeout(timer);
|
|
16250
|
+
}
|
|
16251
|
+
abandoned = true;
|
|
16252
|
+
restart.catch(() => {});
|
|
16253
|
+
abandonSlackApp();
|
|
16254
|
+
throw new Error(`restart did not finish within ${seconds(timeoutMs)}s; abandoned it`);
|
|
16255
|
+
});
|
|
16256
|
+
}
|
|
16257
|
+
function startSocketWatchdog() {
|
|
16258
|
+
if (watchdogTimer)
|
|
16259
|
+
return;
|
|
16260
|
+
let timer = null;
|
|
16261
|
+
const watchdog = createSlackSocketWatchdog({
|
|
16262
|
+
now: Date.now,
|
|
16263
|
+
getState: getSlackConnectionState,
|
|
16264
|
+
getLastActivityAt: () => lastSocketActivityAt,
|
|
16265
|
+
isSocketActive: isLiveSocketActive,
|
|
16266
|
+
isLifecycleBusy: isSlackLifecycleBusy,
|
|
16267
|
+
restart: () => timer ? restartSlackAppForWatchdog(timer) : Promise.resolve(),
|
|
16268
|
+
log: (line) => console.log(line)
|
|
16269
|
+
}, watchdogOptions);
|
|
16270
|
+
timer = setInterval(() => {
|
|
16271
|
+
if (getSlackConfiguration().mode !== "socket") {
|
|
16272
|
+
stopSocketWatchdog();
|
|
16273
|
+
return;
|
|
16274
|
+
}
|
|
16275
|
+
watchdog.tick();
|
|
16276
|
+
}, watchdogOptions.tickMs);
|
|
16277
|
+
timer.unref?.();
|
|
16278
|
+
watchdogTimer = timer;
|
|
16279
|
+
}
|
|
16280
|
+
function stopSocketWatchdog() {
|
|
16281
|
+
if (watchdogTimer)
|
|
16282
|
+
clearInterval(watchdogTimer);
|
|
16283
|
+
watchdogTimer = null;
|
|
15739
16284
|
}
|
|
15740
16285
|
function getSlackApp2() {
|
|
15741
16286
|
return app;
|
|
@@ -15780,27 +16325,33 @@ async function initSlackApp2() {
|
|
|
15780
16325
|
installerOptions: clientOptions ? { clientOptions } : {}
|
|
15781
16326
|
});
|
|
15782
16327
|
trackConnectionState(receiver);
|
|
16328
|
+
socketFence = fenceSocketModeClient(receiver.client);
|
|
15783
16329
|
app = new import_bolt4.App({
|
|
15784
16330
|
token: botToken,
|
|
15785
16331
|
receiver,
|
|
15786
16332
|
socketMode: true,
|
|
15787
16333
|
logLevel,
|
|
16334
|
+
deferInitialization: true,
|
|
15788
16335
|
...clientOptions ? { clientOptions } : {}
|
|
15789
16336
|
});
|
|
15790
16337
|
inboundDrain = installSocketAckRecovery(receiver.client, app);
|
|
16338
|
+
const authClient = app.client;
|
|
16339
|
+
const enterpriseInstall = isSlackEnterpriseInstall();
|
|
16340
|
+
setSlackWorkspaceIdentitySource(() => resolveSlackIdentity(authClient, enterpriseInstall));
|
|
16341
|
+
installSocketWorkspaceGate(receiver.client);
|
|
15791
16342
|
initialized2 = true;
|
|
15792
16343
|
app.use(slackInboundOutcomeMiddleware());
|
|
15793
|
-
const { registerMessageHandler } = await import("./handlers-
|
|
15794
|
-
const { registerCommandHandler } = await import("./commands-
|
|
15795
|
-
const { registerActionHandlers } = await import("./actions-
|
|
15796
|
-
const { registerWorkObjectHandlers } = await import("./work-objects-
|
|
16344
|
+
const { registerMessageHandler } = await import("./handlers-kdjcyzdj.js");
|
|
16345
|
+
const { registerCommandHandler } = await import("./commands-bngnz9g7.js");
|
|
16346
|
+
const { registerActionHandlers } = await import("./actions-7e9czc7s.js");
|
|
16347
|
+
const { registerWorkObjectHandlers } = await import("./work-objects-1kxnbzy5.js");
|
|
15797
16348
|
registerMessageHandler(app);
|
|
15798
16349
|
registerCommandHandler(app);
|
|
15799
16350
|
registerActionHandlers(app);
|
|
15800
16351
|
registerWorkObjectHandlers(app);
|
|
15801
|
-
const { createAssistant } = await import("./assistant-
|
|
16352
|
+
const { createAssistant } = await import("./assistant-wjb7v4c7.js");
|
|
15802
16353
|
app.assistant(createAssistant());
|
|
15803
|
-
const { isBlockExternalEnabled, scanExternalChannelsOnBoot } = await import("./external-channel-
|
|
16354
|
+
const { isBlockExternalEnabled, scanExternalChannelsOnBoot } = await import("./external-channel-m77wf5z3.js");
|
|
15804
16355
|
if (isBlockExternalEnabled()) {
|
|
15805
16356
|
scanExternalChannelsOnBoot(app.client).catch((error) => {
|
|
15806
16357
|
console.error("[Slack] External channel boot scan failed:", error);
|
|
@@ -15809,49 +16360,156 @@ async function initSlackApp2() {
|
|
|
15809
16360
|
return app;
|
|
15810
16361
|
}
|
|
15811
16362
|
async function startSlackApp2() {
|
|
16363
|
+
const generation = lifecycleGeneration;
|
|
15812
16364
|
if (!app) {
|
|
15813
16365
|
await initSlackApp2();
|
|
15814
16366
|
}
|
|
15815
|
-
|
|
15816
|
-
|
|
16367
|
+
const current = app;
|
|
16368
|
+
if (current && generation === lifecycleGeneration) {
|
|
16369
|
+
clearStartRetry();
|
|
16370
|
+
const verified = await verifySlackIdentity(current);
|
|
16371
|
+
if (generation !== lifecycleGeneration)
|
|
16372
|
+
return false;
|
|
16373
|
+
if (!verified) {
|
|
16374
|
+
const delay = scheduleStartRetry();
|
|
16375
|
+
setSlackConnectionState("disconnected");
|
|
16376
|
+
console.error(`[Slack] Socket Mode not started: this swarm's workspace is unknown. Retrying in ${seconds(delay)}s`);
|
|
16377
|
+
return false;
|
|
16378
|
+
}
|
|
16379
|
+
startRetryAttempt = 0;
|
|
16380
|
+
startSocketWatchdog();
|
|
16381
|
+
const { isSlackRenderV2Enabled } = await import("./render-v2-k6tt107q.js");
|
|
15817
16382
|
if (isSlackRenderV2Enabled())
|
|
15818
16383
|
await ensureSlackRenderV2Activation2();
|
|
15819
16384
|
await recoverSlackInboundAfterRestart();
|
|
15820
|
-
|
|
16385
|
+
if (generation !== lifecycleGeneration)
|
|
16386
|
+
return false;
|
|
16387
|
+
await current.start();
|
|
16388
|
+
if (generation !== lifecycleGeneration)
|
|
16389
|
+
return false;
|
|
15821
16390
|
console.log("[Slack] Bot connected via Socket Mode");
|
|
15822
16391
|
inboundDrain?.wake();
|
|
15823
16392
|
await emitBuiltInIntegrationConnectedOnce2("slack");
|
|
16393
|
+
if (generation !== lifecycleGeneration)
|
|
16394
|
+
return false;
|
|
15824
16395
|
await startTaskWatcher();
|
|
15825
16396
|
return true;
|
|
15826
16397
|
}
|
|
15827
16398
|
return false;
|
|
15828
16399
|
}
|
|
16400
|
+
async function verifySlackIdentity(current) {
|
|
16401
|
+
if (!await getSlackWorkspaceIdentity())
|
|
16402
|
+
return false;
|
|
16403
|
+
if (boltInitialized)
|
|
16404
|
+
return true;
|
|
16405
|
+
try {
|
|
16406
|
+
await current.init();
|
|
16407
|
+
} catch (error) {
|
|
16408
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
16409
|
+
console.error(`[Slack] Bolt initialization failed: ${message}`);
|
|
16410
|
+
return false;
|
|
16411
|
+
}
|
|
16412
|
+
boltInitialized = true;
|
|
16413
|
+
return true;
|
|
16414
|
+
}
|
|
16415
|
+
function clearStartRetry() {
|
|
16416
|
+
if (startRetryTimer)
|
|
16417
|
+
clearTimeout(startRetryTimer);
|
|
16418
|
+
startRetryTimer = null;
|
|
16419
|
+
}
|
|
16420
|
+
function scheduleStartRetry() {
|
|
16421
|
+
const delay = startRetryDelaysMs[Math.min(startRetryAttempt, startRetryDelaysMs.length - 1)];
|
|
16422
|
+
startRetryAttempt += 1;
|
|
16423
|
+
const generation = lifecycleGeneration;
|
|
16424
|
+
startRetryTimer = setTimeout(() => {
|
|
16425
|
+
startRetryTimer = null;
|
|
16426
|
+
runSlackLifecycleExclusive(async () => {
|
|
16427
|
+
if (generation !== lifecycleGeneration)
|
|
16428
|
+
return;
|
|
16429
|
+
await startSlackApp2();
|
|
16430
|
+
}).catch((error) => {
|
|
16431
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
16432
|
+
console.error(`[Slack] Start retry failed: ${scrubSecrets(message)}`);
|
|
16433
|
+
});
|
|
16434
|
+
}, delay);
|
|
16435
|
+
startRetryTimer.unref?.();
|
|
16436
|
+
return delay;
|
|
16437
|
+
}
|
|
15829
16438
|
async function stopSlackApp2() {
|
|
16439
|
+
const locked = runSlackLifecycleExclusive(stopSlackAppUnderLifecycleLock2);
|
|
16440
|
+
const waitMs = watchdogOptions.stopLockWaitMs;
|
|
16441
|
+
let timer;
|
|
16442
|
+
const timedOut = new Promise((resolve) => {
|
|
16443
|
+
timer = setTimeout(() => resolve(true), waitMs);
|
|
16444
|
+
});
|
|
16445
|
+
try {
|
|
16446
|
+
const outcome = await Promise.race([locked.then(() => false), timedOut]);
|
|
16447
|
+
if (!outcome)
|
|
16448
|
+
return;
|
|
16449
|
+
} finally {
|
|
16450
|
+
clearTimeout(timer);
|
|
16451
|
+
}
|
|
16452
|
+
locked.catch(() => {});
|
|
16453
|
+
console.error(`[Slack] stop: lifecycle lock still held after ${seconds(waitMs)}s; stopping without it`);
|
|
16454
|
+
stopSocketWatchdog();
|
|
16455
|
+
abandonSlackApp();
|
|
16456
|
+
}
|
|
16457
|
+
async function stopSlackAppUnderLifecycleLock2() {
|
|
16458
|
+
stopSocketWatchdog();
|
|
16459
|
+
await teardownSlackApp();
|
|
16460
|
+
}
|
|
16461
|
+
async function teardownSlackApp() {
|
|
16462
|
+
const stopping = detachSlackApp();
|
|
16463
|
+
if (stopping) {
|
|
16464
|
+
await stopping.stop();
|
|
16465
|
+
console.log("[Slack] Bot disconnected");
|
|
16466
|
+
}
|
|
16467
|
+
}
|
|
16468
|
+
function abandonSlackApp() {
|
|
16469
|
+
const stalled = detachSlackApp();
|
|
16470
|
+
stalled?.stop().catch((error) => {
|
|
16471
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
16472
|
+
console.error(`[Slack] watchdog: stopping the abandoned app failed: ${scrubSecrets(message)}`);
|
|
16473
|
+
});
|
|
16474
|
+
}
|
|
16475
|
+
function detachSlackApp() {
|
|
16476
|
+
socketFence?.retire();
|
|
16477
|
+
socketFence = null;
|
|
16478
|
+
lifecycleGeneration += 1;
|
|
16479
|
+
clearStartRetry();
|
|
16480
|
+
startRetryAttempt = 0;
|
|
16481
|
+
boltInitialized = false;
|
|
15830
16482
|
stopTaskWatcher();
|
|
15831
16483
|
inboundDrain?.stop();
|
|
15832
16484
|
inboundDrain = null;
|
|
15833
|
-
|
|
15834
|
-
|
|
15835
|
-
app = null;
|
|
15836
|
-
console.log("[Slack] Bot disconnected");
|
|
15837
|
-
}
|
|
16485
|
+
const detached = app;
|
|
16486
|
+
app = null;
|
|
15838
16487
|
receiver = null;
|
|
16488
|
+
setSlackWorkspaceIdentitySource(null);
|
|
16489
|
+
lastSocketActivityAt = null;
|
|
15839
16490
|
setSlackConnectionState("disconnected");
|
|
15840
16491
|
initialized2 = false;
|
|
16492
|
+
return detached;
|
|
15841
16493
|
}
|
|
15842
|
-
var import_bolt4, app = null, receiver = null, initialized2 = false, inboundDrain = null, SOCKET_EVENT_STATES;
|
|
16494
|
+
var import_bolt4, app = null, receiver = null, initialized2 = false, inboundDrain = null, socketFence = null, lifecycleGeneration = 0, lastSocketActivityAt = null, DEFAULT_START_RETRY_DELAYS_MS, startRetryDelaysMs, startRetryTimer = null, startRetryAttempt = 0, boltInitialized = false, SOCKET_EVENT_STATES, SLACK_SOCKET_WATCHDOG_DEFAULTS, watchdogTimer = null, watchdogOptions;
|
|
15843
16495
|
var init_app3 = __esm(() => {
|
|
15844
16496
|
init_db4();
|
|
15845
16497
|
init_node_env();
|
|
16498
|
+
init_secret_scrubber();
|
|
15846
16499
|
init_config4();
|
|
15847
16500
|
init_connection_state();
|
|
15848
16501
|
init_egress_scrub();
|
|
15849
16502
|
init_external_channel_egress();
|
|
15850
16503
|
init_inbound_dispatch();
|
|
16504
|
+
init_lifecycle_lock();
|
|
15851
16505
|
init_socket_ack();
|
|
16506
|
+
init_socket_fence();
|
|
15852
16507
|
init_socket_mode_guard();
|
|
15853
16508
|
init_watcher();
|
|
16509
|
+
init_workspace_guard();
|
|
15854
16510
|
import_bolt4 = __toESM(require_dist5(), 1);
|
|
16511
|
+
DEFAULT_START_RETRY_DELAYS_MS = [5000, 15000, 30000, 60000, 120000, 300000];
|
|
16512
|
+
startRetryDelaysMs = DEFAULT_START_RETRY_DELAYS_MS;
|
|
15855
16513
|
SOCKET_EVENT_STATES = {
|
|
15856
16514
|
connecting: "connecting",
|
|
15857
16515
|
reconnecting: "connecting",
|
|
@@ -15859,6 +16517,16 @@ var init_app3 = __esm(() => {
|
|
|
15859
16517
|
disconnecting: "disconnected",
|
|
15860
16518
|
disconnected: "disconnected"
|
|
15861
16519
|
};
|
|
16520
|
+
SLACK_SOCKET_WATCHDOG_DEFAULTS = {
|
|
16521
|
+
tickMs: 5000,
|
|
16522
|
+
downAfterMs: 60000,
|
|
16523
|
+
staleActivityMs: 10 * 60000,
|
|
16524
|
+
backoffBaseMs: 30000,
|
|
16525
|
+
backoffMaxMs: 5 * 60000,
|
|
16526
|
+
restartTimeoutMs: 2 * 60000,
|
|
16527
|
+
stopLockWaitMs: 1e4
|
|
16528
|
+
};
|
|
16529
|
+
watchdogOptions = SLACK_SOCKET_WATCHDOG_DEFAULTS;
|
|
15862
16530
|
});
|
|
15863
16531
|
|
|
15864
|
-
export { require_dist4, require_dist5, getSlackConnectionState, init_connection_state, noteSlackInboundSideEffect, ignoreSlackInbound, reportSlackInboundFailure, isAdmittedSlackDelivery, getSlackInboundDiagnostics, init_inbound_dispatch, terminalReactionEvent, init_reaction_events, isPollTracingEnabled, initOtel, withSpan2, startSpan2, withSpanContext2, withRemoteContext2, injectTraceContext2, recordSessionCost2, recordDbRetentionSweep2, recordDbRetentionStatement2, init_otel, slackTaskOutput, init_task_output, ackSlackMessage, skipSlackMessageReaction, finalizeTerminalSlackReactions, init_ack, getTaskLink, getTaskUrl, markdownToSlack, buildMrkdwnSectionBlocks, buildCaptionBlock, buildCancelledBlocks, buildBufferFlushBlocks, buildTreeBlocks, init_blocks, taskCitationIssues, stripInvalidTaskCitations, taskCitationSourceGroups, renderTaskCitations, taskCitationWarnings, init_task_citations, MAX_TASK_CITATIONS, CitationInputSchema, TaskCitationSchema, upsertTaskCitations, getTaskCitations, getTaskCitationsForTasks, hasTaskCitationCheckRefusal, init_task_citations2, initialize, ensure, init_business_use, getAgentDisplayName, getAgentSlackIcon, init_responses, markSlackSessionProcessing, init_session_status, isSlackRenderV2Enabled2, callSlackWithRetry2, ensureSlackThreadTree2, slackErrorCode2, processSlackRenderV22, init_render_v2, registerTreeMessage, init_watcher, getSlackApp2, initSlackApp2, startSlackApp2, stopSlackApp2, init_app3 };
|
|
16532
|
+
export { require_dist4, require_dist5, getSlackConnectionState, init_connection_state, noteSlackInboundSideEffect, ignoreSlackInbound, reportSlackInboundFailure, isAdmittedSlackDelivery, getSlackInboundDiagnostics, init_inbound_dispatch, runSlackLifecycleExclusive, init_lifecycle_lock, terminalReactionEvent, init_reaction_events, isPollTracingEnabled, initOtel, withSpan2, startSpan2, withSpanContext2, withRemoteContext2, injectTraceContext2, recordSessionCost2, recordDbRetentionSweep2, recordDbRetentionStatement2, init_otel, slackTaskOutput, init_task_output, ackSlackMessage, skipSlackMessageReaction, finalizeTerminalSlackReactions, init_ack, getTaskLink, getTaskUrl, markdownToSlack, buildMrkdwnSectionBlocks, buildCaptionBlock, buildCancelledBlocks, buildBufferFlushBlocks, buildTreeBlocks, init_blocks, taskCitationIssues, stripInvalidTaskCitations, taskCitationSourceGroups, renderTaskCitations, taskCitationWarnings, init_task_citations, MAX_TASK_CITATIONS, CitationInputSchema, TaskCitationSchema, upsertTaskCitations, getTaskCitations, getTaskCitationsForTasks, hasTaskCitationCheckRefusal, init_task_citations2, initialize, ensure, init_business_use, getAgentDisplayName, getAgentSlackIcon, init_responses, markSlackSessionProcessing, init_session_status, isSlackRenderV2Enabled2, callSlackWithRetry2, ensureSlackThreadTree2, slackErrorCode2, startSlackRenderV2Events2, stopSlackRenderV2Events2, processSlackRenderV22, init_render_v2, registerTreeMessage, init_watcher, getSlackApp2, initSlackApp2, startSlackApp2, stopSlackApp2, stopSlackAppUnderLifecycleLock2, init_app3 };
|