@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
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SESSION_RESOURCE_KINDS,
|
|
3
|
+
type SessionResourceGroup,
|
|
4
|
+
type SessionResourceKind,
|
|
5
|
+
sessionResourceGroupOf,
|
|
6
|
+
} from "../../assets/key";
|
|
1
7
|
import { getDbClient, upsertKv } from "../db";
|
|
2
8
|
|
|
3
9
|
const NAMESPACE = "session-labels";
|
|
@@ -26,3 +32,54 @@ export async function rememberSessionLabel(
|
|
|
26
32
|
expiresAt: ttlMs === undefined ? null : Date.now() + ttlMs,
|
|
27
33
|
});
|
|
28
34
|
}
|
|
35
|
+
|
|
36
|
+
/** The table and name column of each resource kind a session group can name. */
|
|
37
|
+
const RESOURCE_NAMES: Record<SessionResourceKind, { table: string; column: string }> = {
|
|
38
|
+
page: { table: "pages", column: "title" },
|
|
39
|
+
workflow: { table: "workflows", column: "name" },
|
|
40
|
+
schedule: { table: "scheduled_tasks", column: "name" },
|
|
41
|
+
app: { table: "apps", column: "name" },
|
|
42
|
+
script: { table: "scripts", column: "name" },
|
|
43
|
+
fs: { table: "asset_key_mappings", column: "provider_key" },
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Labels of resource session groups (`sessionResourceGroupOf`), one query per
|
|
48
|
+
* kind: the resource's name, and an app action's name. A deleted resource
|
|
49
|
+
* gets no label; the UI falls back to "<Kind> · <short id>".
|
|
50
|
+
*/
|
|
51
|
+
export async function getResourceSessionLabels(keys: string[]): Promise<Record<string, string>> {
|
|
52
|
+
const groups = keys.flatMap((key) => {
|
|
53
|
+
const resource = sessionResourceGroupOf(key);
|
|
54
|
+
return resource ? [{ key, resource }] : [];
|
|
55
|
+
});
|
|
56
|
+
const labels: Record<string, string> = {};
|
|
57
|
+
for (const { key, resource } of groups) {
|
|
58
|
+
if (resource.action) labels[key] = resource.action;
|
|
59
|
+
}
|
|
60
|
+
// An `fs` id keeps its provider (`agent-fs:<id>`): the mapping id is the last part.
|
|
61
|
+
const rowId = (resource: SessionResourceGroup) =>
|
|
62
|
+
resource.kind === "fs" ? resource.id.slice(resource.id.lastIndexOf(":") + 1) : resource.id;
|
|
63
|
+
await Promise.all(
|
|
64
|
+
SESSION_RESOURCE_KINDS.map(async (kind) => {
|
|
65
|
+
const wanted = groups.filter(({ resource }) => resource.kind === kind && !resource.action);
|
|
66
|
+
if (wanted.length === 0) return;
|
|
67
|
+
const ids = [...new Set(wanted.map(({ resource }) => rowId(resource)))];
|
|
68
|
+
const { table, column } = RESOURCE_NAMES[kind];
|
|
69
|
+
const rows = await getDbClient().query<{ id: string; name: string | null }>(
|
|
70
|
+
// Keys are lower case, and so are generated ids: `id IN` keeps the primary key index.
|
|
71
|
+
`SELECT lower(id) AS id, NULLIF(trim(${column}), '') AS name FROM ${table}
|
|
72
|
+
WHERE id IN (${ids.map(() => "?").join(", ")})`,
|
|
73
|
+
ids,
|
|
74
|
+
);
|
|
75
|
+
const names = new Map(rows.map((row) => [row.id, row.name]));
|
|
76
|
+
for (const { key, resource } of wanted) {
|
|
77
|
+
const name = names.get(rowId(resource));
|
|
78
|
+
if (!name) continue;
|
|
79
|
+
// A file reads as its last path segment.
|
|
80
|
+
labels[key] = kind === "fs" ? name.replace(/\/+$/, "").split("/").pop() || name : name;
|
|
81
|
+
}
|
|
82
|
+
}),
|
|
83
|
+
);
|
|
84
|
+
return labels;
|
|
85
|
+
}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
keyPrefixRange,
|
|
3
|
+
NO_GROUP_LEAF_KINDS,
|
|
3
4
|
normalizeAssetKey,
|
|
5
|
+
parseAssetKey,
|
|
4
6
|
SESSION_LEAF_KINDS,
|
|
7
|
+
SESSION_RESOURCE_KINDS,
|
|
5
8
|
sessionGroupKey,
|
|
9
|
+
sessionResourceGroupOf,
|
|
6
10
|
} from "../../assets/key";
|
|
7
11
|
import {
|
|
8
12
|
effectiveSource,
|
|
@@ -188,6 +192,9 @@ export async function getSessionGroupKey(task: { id: string; key: string }): Pro
|
|
|
188
192
|
*/
|
|
189
193
|
function groupCondition(group: string, scan = false): SqlFragment {
|
|
190
194
|
const { lo, hi } = keyPrefixRange(group);
|
|
195
|
+
// A namespace root keeps resource leaves out: they are resource groups (`sessionGroupKey`).
|
|
196
|
+
const kinds =
|
|
197
|
+
parseAssetKey(group).relativeSegments.length === 0 ? NO_GROUP_LEAF_KINDS : SESSION_LEAF_KINDS;
|
|
191
198
|
// The remaining key must be one resource leaf, with no nested path.
|
|
192
199
|
// SQLite substr/length count code points, so count them here too (not UTF-16 units).
|
|
193
200
|
const start = [...lo].length + 1;
|
|
@@ -195,7 +202,7 @@ function groupCondition(group: string, scan = false): SqlFragment {
|
|
|
195
202
|
return {
|
|
196
203
|
sql: `(${scan ? "+" : ""}r."key" >= ? AND ${scan ? "+" : ""}r."key" < ? AND (r."key" = ? OR (
|
|
197
204
|
instr(substr(r."key", ?, length(r."key") - ?), '/') = 0 AND
|
|
198
|
-
(${
|
|
205
|
+
(${kinds.map(() => 'substr(r."key", ?) GLOB ?').join(" OR ")}) AND
|
|
199
206
|
${threadRoots.sql} < ?
|
|
200
207
|
)))`,
|
|
201
208
|
params: [
|
|
@@ -204,7 +211,7 @@ function groupCondition(group: string, scan = false): SqlFragment {
|
|
|
204
211
|
lo,
|
|
205
212
|
start,
|
|
206
213
|
start,
|
|
207
|
-
...
|
|
214
|
+
...kinds.flatMap((kind) => [start, `${kind}:?*/`]),
|
|
208
215
|
...threadRoots.params,
|
|
209
216
|
NESTED_THREAD_MIN_ROOTS,
|
|
210
217
|
],
|
|
@@ -221,13 +228,39 @@ function noGroupCondition(userId: string | null | undefined): SqlFragment {
|
|
|
221
228
|
};
|
|
222
229
|
}
|
|
223
230
|
|
|
231
|
+
/** The namespace roots whose resource groups the Inbox holds: `shared/` and the viewer's own. */
|
|
232
|
+
function resourceBases(userId: string | null | undefined): string[] {
|
|
233
|
+
return userId ? ["shared/", `personal/${userId}/`] : ["shared/"];
|
|
234
|
+
}
|
|
235
|
+
|
|
224
236
|
/**
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
|
|
237
|
+
* Whether a root key sits in a resource section (Pages, Workflows, ...) of
|
|
238
|
+
* the viewer: `inboxScopeCondition`'s resource ranges, in JS.
|
|
239
|
+
*/
|
|
240
|
+
export function inResourceScope(key: string, userId: string | null | undefined): boolean {
|
|
241
|
+
return resourceBases(userId).some((base) =>
|
|
242
|
+
SESSION_RESOURCE_KINDS.some((kind) => key.startsWith(`${base}${kind}:`)),
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/** Key ranges of every `<base><kind>:` prefix ({@link inResourceScope}). */
|
|
247
|
+
function resourceKeyRanges(userId: string | null | undefined) {
|
|
248
|
+
return resourceBases(userId).flatMap((base) =>
|
|
249
|
+
SESSION_RESOURCE_KINDS.map((kind) => {
|
|
250
|
+
const lo = normalizeAssetKey(`${base}${kind}:`).slice(0, -1);
|
|
251
|
+
return { lo, hi: `${lo.slice(0, -1)};` };
|
|
252
|
+
}),
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Roots the Inbox holds: No group, the source sections (Slack, Telegram,
|
|
258
|
+
* Discord), and the resource sections (Pages, Workflows, ...), which file
|
|
259
|
+
* sessions on their own. A session that a person filed into a group (My
|
|
260
|
+
* groups, Shared with me) shows under that group only.
|
|
228
261
|
*/
|
|
229
262
|
function inboxScopeCondition(userId: string | null | undefined): SqlFragment {
|
|
230
|
-
const ranges = sourceKeyRanges();
|
|
263
|
+
const ranges = [...sourceKeyRanges(), ...resourceKeyRanges(userId)];
|
|
231
264
|
const noGroup = noGroupCondition(userId);
|
|
232
265
|
return {
|
|
233
266
|
sql: `(${ranges.map(() => '(+r."key" >= ? AND +r."key" < ?)').join(" OR ")} OR ${noGroup.sql})`,
|
|
@@ -627,6 +660,11 @@ export interface SessionTree {
|
|
|
627
660
|
sourceGroups: string[];
|
|
628
661
|
/** Slack channel ids backed by visible roots with matching Slack fields, including hidden sources. */
|
|
629
662
|
slackChannels: string[];
|
|
663
|
+
/**
|
|
664
|
+
* Every resource group key in this view and the key of its resource
|
|
665
|
+
* (`shared/app:<id>/` for an action group), hidden sources included, for labels.
|
|
666
|
+
*/
|
|
667
|
+
resourceGroups: string[];
|
|
630
668
|
/**
|
|
631
669
|
* The oldest visible root of each nested source thread, including hidden
|
|
632
670
|
* sources: its title, else a preview of its prompt without the thread context.
|
|
@@ -705,6 +743,7 @@ export async function getSessionTree(
|
|
|
705
743
|
sources: [],
|
|
706
744
|
sourceGroups: [],
|
|
707
745
|
slackChannels: [],
|
|
746
|
+
resourceGroups: [],
|
|
708
747
|
threadLabels: {},
|
|
709
748
|
};
|
|
710
749
|
const hidden = new Set(opts.hideSource);
|
|
@@ -712,6 +751,7 @@ export async function getSessionTree(
|
|
|
712
751
|
const sources = new Map<string, number>();
|
|
713
752
|
const sourceGroups = new Set<string>();
|
|
714
753
|
const slackChannels = new Set<string>();
|
|
754
|
+
const resourceGroups = new Set<string>();
|
|
715
755
|
const threadRootIds: string[] = [];
|
|
716
756
|
const groups = new Map<string, SessionTreeGroup>();
|
|
717
757
|
const add = (section: SessionSectionCounts, row: (typeof rows)[number]) => {
|
|
@@ -735,6 +775,8 @@ export async function getSessionTree(
|
|
|
735
775
|
sourceGroups.add(sourceGroupKey);
|
|
736
776
|
}
|
|
737
777
|
if (sourceOfKey(key)) sourceGroups.add(key);
|
|
778
|
+
const resource = sessionResourceGroupOf(key);
|
|
779
|
+
if (resource) resourceGroups.add(key).add(resource.resourceKey);
|
|
738
780
|
if (hidden.has(source) || (shown && !shown.has(source))) continue;
|
|
739
781
|
const noGroup =
|
|
740
782
|
key === "shared/" || (actor.kind === "user" && key === `personal/${actor.userId}/`);
|
|
@@ -750,7 +792,8 @@ export async function getSessionTree(
|
|
|
750
792
|
if (row.readState === "later" || row.readState === "done") add(result[row.readState], row);
|
|
751
793
|
else {
|
|
752
794
|
// A session filed into a group shows under it only (`inboxScopeCondition`).
|
|
753
|
-
|
|
795
|
+
const viewer = actor.kind === "user" ? actor.userId : null;
|
|
796
|
+
if (noGroup || sourceOfKey(key) || inResourceScope(row.key, viewer)) add(result.inbox, row);
|
|
754
797
|
if (noGroup) add(result.noGroup, row);
|
|
755
798
|
else if (group) add(group, row);
|
|
756
799
|
}
|
|
@@ -761,6 +804,7 @@ export async function getSessionTree(
|
|
|
761
804
|
.sort((a, b) => b.total - a.total || a.source.localeCompare(b.source));
|
|
762
805
|
result.sourceGroups = [...sourceGroups].sort();
|
|
763
806
|
result.slackChannels = [...slackChannels].sort();
|
|
807
|
+
result.resourceGroups = [...resourceGroups].sort();
|
|
764
808
|
if (threadRootIds.length) {
|
|
765
809
|
// A missing or empty title falls back to a preview of the prompt without its thread context.
|
|
766
810
|
const labels = await getDbClient().query<{ key: string; title: string | null; prompt: string }>(
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { getDbClient } from "../db";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* True when the tree sweep has render work for `tree` (aliases `tree` and
|
|
5
|
+
* `state` must be in scope). Shared by the sweep (getSlackTreeMessages) and by
|
|
6
|
+
* closeSlackTreeIfSettled, so a closed tree is exactly one the sweep would
|
|
7
|
+
* skip. Migration 278 backfills closed_at with the same predicate; keep the
|
|
8
|
+
* two in step.
|
|
9
|
+
*/
|
|
10
|
+
export const SLACK_TREE_NEEDS_RENDER_SQL = `(
|
|
11
|
+
(tree.ts LIKE 'pending:%' AND tree.created_at >= state.activated_at)
|
|
12
|
+
OR EXISTS (
|
|
13
|
+
SELECT 1 FROM agent_tasks task
|
|
14
|
+
WHERE task.slackChannelId = tree.channel_id
|
|
15
|
+
AND task.slackThreadTs = tree.thread_ts
|
|
16
|
+
AND task.source = 'slack'
|
|
17
|
+
AND task.createdAt >= state.activated_at
|
|
18
|
+
AND task.status IN ('completed', 'failed', 'cancelled')
|
|
19
|
+
AND NOT EXISTS (
|
|
20
|
+
SELECT 1 FROM slack_messages outcome
|
|
21
|
+
WHERE outcome.kind = 'outcome'
|
|
22
|
+
AND outcome.task_id = task.id
|
|
23
|
+
AND (outcome.finalized_at IS NOT NULL OR outcome.delivery_abandoned_at IS NOT NULL)
|
|
24
|
+
)
|
|
25
|
+
)
|
|
26
|
+
OR
|
|
27
|
+
EXISTS (
|
|
28
|
+
SELECT 1 FROM agent_tasks task
|
|
29
|
+
WHERE task.slackChannelId = tree.channel_id
|
|
30
|
+
AND task.slackThreadTs = tree.thread_ts
|
|
31
|
+
AND task.createdAt >= state.activated_at
|
|
32
|
+
AND task.status NOT IN ('completed', 'failed', 'cancelled', 'superseded', 'skipped')
|
|
33
|
+
)
|
|
34
|
+
OR EXISTS (
|
|
35
|
+
SELECT 1 FROM agent_tasks task
|
|
36
|
+
WHERE task.slackChannelId = tree.channel_id
|
|
37
|
+
AND task.slackThreadTs = tree.thread_ts
|
|
38
|
+
AND task.createdAt >= state.activated_at
|
|
39
|
+
AND task.lastUpdatedAt > tree.updated_at
|
|
40
|
+
)
|
|
41
|
+
OR EXISTS (
|
|
42
|
+
SELECT 1 FROM slack_messages outcome
|
|
43
|
+
JOIN agent_tasks task ON task.id = outcome.task_id
|
|
44
|
+
WHERE outcome.kind = 'outcome'
|
|
45
|
+
AND outcome.channel_id = tree.channel_id
|
|
46
|
+
AND outcome.thread_ts = tree.thread_ts
|
|
47
|
+
AND task.createdAt >= state.activated_at
|
|
48
|
+
AND (
|
|
49
|
+
(outcome.finalized_at IS NULL AND outcome.delivery_abandoned_at IS NULL)
|
|
50
|
+
OR outcome.updated_at > tree.updated_at
|
|
51
|
+
)
|
|
52
|
+
)
|
|
53
|
+
)`;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Close a tree once the sweep has nothing left to do for it: every task in
|
|
57
|
+
* the thread is terminal, every outcome card is finalized or abandoned, and no
|
|
58
|
+
* task or card changed after the tree. One statement, so a write that lands
|
|
59
|
+
* before it is seen by the predicate; a write after it reopens the tree
|
|
60
|
+
* through migration 278's triggers. Returns true when the tree was closed.
|
|
61
|
+
*/
|
|
62
|
+
export async function closeSlackTreeIfSettled(id: string): Promise<boolean> {
|
|
63
|
+
const result = await getDbClient().run(
|
|
64
|
+
`UPDATE slack_messages AS tree SET closed_at = ?
|
|
65
|
+
WHERE tree.id = ?
|
|
66
|
+
AND tree.kind = 'tree'
|
|
67
|
+
AND tree.closed_at IS NULL
|
|
68
|
+
AND tree.ts NOT LIKE 'pending:%'
|
|
69
|
+
AND EXISTS (
|
|
70
|
+
SELECT 1 FROM slack_render_v2_state state
|
|
71
|
+
WHERE state.id = 1 AND NOT ${SLACK_TREE_NEEDS_RENDER_SQL}
|
|
72
|
+
)`,
|
|
73
|
+
[new Date().toISOString(), id],
|
|
74
|
+
);
|
|
75
|
+
return result.changes > 0;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const THREAD_LOOKUP_CHUNK = 500;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* The Slack threads the given tasks belong to, for the event-driven render.
|
|
82
|
+
* `wakeTouched` is true when any of them is a deferral wake-up, whose
|
|
83
|
+
* settling can resolve a ⏳ card in another thread.
|
|
84
|
+
*/
|
|
85
|
+
export async function getSlackThreadsOfTasks(taskIds: string[]): Promise<{
|
|
86
|
+
threads: { channelId: string; threadTs: string }[];
|
|
87
|
+
wakeTouched: boolean;
|
|
88
|
+
}> {
|
|
89
|
+
const threads = new Map<string, { channelId: string; threadTs: string }>();
|
|
90
|
+
let wakeTouched = false;
|
|
91
|
+
for (let i = 0; i < taskIds.length; i += THREAD_LOOKUP_CHUNK) {
|
|
92
|
+
const chunk = taskIds.slice(i, i + THREAD_LOOKUP_CHUNK);
|
|
93
|
+
const rows = await getDbClient().query<{
|
|
94
|
+
slackChannelId: string | null;
|
|
95
|
+
slackThreadTs: string | null;
|
|
96
|
+
taskType: string | null;
|
|
97
|
+
}>(
|
|
98
|
+
`SELECT slackChannelId, slackThreadTs, taskType FROM agent_tasks
|
|
99
|
+
WHERE id IN (${chunk.map(() => "?").join(",")})`,
|
|
100
|
+
chunk,
|
|
101
|
+
);
|
|
102
|
+
for (const row of rows) {
|
|
103
|
+
if (row.taskType === "deferred") wakeTouched = true;
|
|
104
|
+
if (!row.slackChannelId || !row.slackThreadTs) continue;
|
|
105
|
+
threads.set(`${row.slackChannelId}\u0000${row.slackThreadTs}`, {
|
|
106
|
+
channelId: row.slackChannelId,
|
|
107
|
+
threadTs: row.slackThreadTs,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return { threads: [...threads.values()], wakeTouched };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* True while the thread still owes an outcome card: a terminal Slack task
|
|
116
|
+
* whose card is not finalized or abandoned, or a card still in flight. These
|
|
117
|
+
* wait on time (conclusion settle, delivery backoff), not on a task event.
|
|
118
|
+
*/
|
|
119
|
+
export async function slackThreadHasOutcomeWork(thread: {
|
|
120
|
+
channelId: string;
|
|
121
|
+
threadTs: string;
|
|
122
|
+
}): Promise<boolean> {
|
|
123
|
+
const row = await getDbClient().get<{ pending: number }>(
|
|
124
|
+
`SELECT EXISTS (
|
|
125
|
+
SELECT 1 FROM agent_tasks task, slack_render_v2_state state
|
|
126
|
+
WHERE state.id = 1
|
|
127
|
+
AND task.slackChannelId = ? AND task.slackThreadTs = ?
|
|
128
|
+
AND task.source = 'slack'
|
|
129
|
+
AND task.createdAt >= state.activated_at
|
|
130
|
+
AND task.status IN ('completed', 'failed', 'cancelled')
|
|
131
|
+
AND NOT EXISTS (
|
|
132
|
+
SELECT 1 FROM slack_messages outcome
|
|
133
|
+
WHERE outcome.kind = 'outcome'
|
|
134
|
+
AND outcome.task_id = task.id
|
|
135
|
+
AND (outcome.finalized_at IS NOT NULL OR outcome.delivery_abandoned_at IS NOT NULL)
|
|
136
|
+
)
|
|
137
|
+
) OR EXISTS (
|
|
138
|
+
SELECT 1 FROM slack_messages outcome
|
|
139
|
+
WHERE outcome.kind = 'outcome'
|
|
140
|
+
AND outcome.channel_id = ? AND outcome.thread_ts = ?
|
|
141
|
+
AND outcome.finalized_at IS NULL AND outcome.delivery_abandoned_at IS NULL
|
|
142
|
+
) AS pending`,
|
|
143
|
+
[thread.channelId, thread.threadTs, thread.channelId, thread.threadTs],
|
|
144
|
+
);
|
|
145
|
+
return !!row?.pending;
|
|
146
|
+
}
|
package/src/be/db/tasks/read.ts
CHANGED
|
@@ -163,6 +163,8 @@ type AgentTaskSummaryRow = Pick<
|
|
|
163
163
|
| "modelAlias"
|
|
164
164
|
| "effort"
|
|
165
165
|
| "resolvedEffort"
|
|
166
|
+
| "profile"
|
|
167
|
+
| "resolvedProfile"
|
|
166
168
|
| "provider"
|
|
167
169
|
| "requestedByUserId"
|
|
168
170
|
| "progress"
|
|
@@ -243,7 +245,7 @@ const LIST_COLUMNS = {
|
|
|
243
245
|
agent_tasks.offeredTo, agent_tasks.acceptedAt, agent_tasks.parentTaskId,
|
|
244
246
|
agent_tasks.scheduleId, agent_tasks.model, agent_tasks.modelTier,
|
|
245
247
|
agent_tasks.resolvedModel, agent_tasks.modelSource, agent_tasks.modelAlias, agent_tasks.effort,
|
|
246
|
-
agent_tasks.resolvedEffort,
|
|
248
|
+
agent_tasks.resolvedEffort, agent_tasks.profile, agent_tasks.resolvedProfile,
|
|
247
249
|
agent_tasks.provider, agent_tasks.requestedByUserId, agent_tasks.progress,
|
|
248
250
|
agent_tasks.createdAt, agent_tasks.lastUpdatedAt, agent_tasks.finishedAt,
|
|
249
251
|
agent_tasks.peakContextPercent`,
|
|
@@ -432,6 +434,8 @@ export function rowToAgentTaskSummary(row: AgentTaskSummaryRow): AgentTaskSummar
|
|
|
432
434
|
resolvedEffort: ReasoningEffortSchema.safeParse(row.resolvedEffort).success
|
|
433
435
|
? (row.resolvedEffort as ReasoningEffort)
|
|
434
436
|
: undefined,
|
|
437
|
+
profile: row.profile ?? undefined,
|
|
438
|
+
resolvedProfile: row.resolvedProfile ?? undefined,
|
|
435
439
|
provider: (row.provider as ProviderName | null) ?? undefined,
|
|
436
440
|
requestedByUserId: row.requestedByUserId ?? undefined,
|
|
437
441
|
progress: row.progress ?? undefined,
|
|
@@ -1607,13 +1611,50 @@ export async function getInProgressSlackTasks(): Promise<AgentTask[]> {
|
|
|
1607
1611
|
return rows.map(rowToAgentTask);
|
|
1608
1612
|
}
|
|
1609
1613
|
|
|
1610
|
-
|
|
1614
|
+
/** How far back the missing-tree sweep looks for Slack tasks without a tree. */
|
|
1615
|
+
const SLACK_MISSING_TREE_WINDOW_MS = 24 * 60 * 60 * 1000;
|
|
1616
|
+
|
|
1617
|
+
/**
|
|
1618
|
+
* Slack tasks (created since render-v2 activation) whose thread has no tree
|
|
1619
|
+
* row yet.
|
|
1620
|
+
*
|
|
1621
|
+
* The full sweep reads only tasks updated in the last 24 h. The bound is on
|
|
1622
|
+
* lastUpdatedAt, not createdAt: a task that waits in backlog/unassigned for
|
|
1623
|
+
* days gets a fresh lastUpdatedAt when it leaves that status, so it re-enters
|
|
1624
|
+
* the window exactly when it starts to need a tree. idx_agent_tasks_slack_last_updated
|
|
1625
|
+
* makes the bound a range seek and also serves the ORDER BY. INDEXED BY:
|
|
1626
|
+
* without ANALYZE statistics the planner otherwise picks a wider index.
|
|
1627
|
+
*
|
|
1628
|
+
* `thread` scopes the query to one thread (event-driven render). It seeks the
|
|
1629
|
+
* thread through idx_agent_tasks_slack_thread_cover and has no time window,
|
|
1630
|
+
* so an old task in that thread is never skipped.
|
|
1631
|
+
*/
|
|
1632
|
+
export async function getSlackTasksMissingTree(
|
|
1633
|
+
options: { now?: Date; thread?: { channelId: string; threadTs: string } } = {},
|
|
1634
|
+
): Promise<AgentTask[]> {
|
|
1635
|
+
const thread = options.thread;
|
|
1636
|
+
const since = new Date(
|
|
1637
|
+
(options.now ?? new Date()).getTime() - SLACK_MISSING_TREE_WINDOW_MS,
|
|
1638
|
+
).toISOString();
|
|
1639
|
+
const scope = thread
|
|
1640
|
+
? {
|
|
1641
|
+
index: "idx_agent_tasks_slack_thread_cover",
|
|
1642
|
+
sql: "AND task.slackChannelId = ? AND task.slackThreadTs = ?",
|
|
1643
|
+
params: [thread.channelId, thread.threadTs],
|
|
1644
|
+
}
|
|
1645
|
+
: {
|
|
1646
|
+
index: "idx_agent_tasks_slack_last_updated",
|
|
1647
|
+
sql: "AND task.lastUpdatedAt >= ?",
|
|
1648
|
+
params: [since],
|
|
1649
|
+
};
|
|
1611
1650
|
const rows = await getDbClient().query<AgentTaskRow>(
|
|
1612
|
-
`SELECT task.* FROM
|
|
1613
|
-
JOIN
|
|
1614
|
-
WHERE
|
|
1651
|
+
`SELECT task.* FROM slack_render_v2_state state
|
|
1652
|
+
CROSS JOIN agent_tasks task INDEXED BY ${scope.index}
|
|
1653
|
+
WHERE state.id = 1
|
|
1654
|
+
AND task.source = 'slack'
|
|
1615
1655
|
AND task.slackChannelId IS NOT NULL
|
|
1616
1656
|
AND task.slackThreadTs IS NOT NULL
|
|
1657
|
+
${scope.sql}
|
|
1617
1658
|
AND task.createdAt >= state.activated_at
|
|
1618
1659
|
AND task.status NOT IN ('backlog', 'unassigned', 'superseded')
|
|
1619
1660
|
AND NOT EXISTS (
|
|
@@ -1631,6 +1672,7 @@ export async function getSlackTasksMissingTree(): Promise<AgentTask[]> {
|
|
|
1631
1672
|
)
|
|
1632
1673
|
ORDER BY task.lastUpdatedAt DESC
|
|
1633
1674
|
LIMIT 200`,
|
|
1675
|
+
scope.params,
|
|
1634
1676
|
);
|
|
1635
1677
|
return rows.map(rowToAgentTask);
|
|
1636
1678
|
}
|
|
@@ -1740,14 +1782,28 @@ export async function findExistingLinearTrackerContextWork(
|
|
|
1740
1782
|
return null;
|
|
1741
1783
|
}
|
|
1742
1784
|
|
|
1743
|
-
|
|
1785
|
+
/**
|
|
1786
|
+
* Latest task on a contextKey. `requestedByUserId` keeps only that user's
|
|
1787
|
+
* tasks; `notRequestedByUserId` keeps only tasks of anyone else, including
|
|
1788
|
+
* tasks with no requester.
|
|
1789
|
+
*/
|
|
1790
|
+
export async function getLatestTaskByContextKey(
|
|
1791
|
+
contextKey: string,
|
|
1792
|
+
options: { requestedByUserId?: string; notRequestedByUserId?: string } = {},
|
|
1793
|
+
): Promise<AgentTask | null> {
|
|
1744
1794
|
if (!contextKey) return null;
|
|
1745
1795
|
const row = await getDbClient().get<AgentTaskRow>(
|
|
1746
1796
|
`SELECT * FROM agent_tasks
|
|
1747
1797
|
WHERE contextKey = ?
|
|
1798
|
+
${options.requestedByUserId !== undefined ? "AND requestedByUserId = ?" : ""}
|
|
1799
|
+
${options.notRequestedByUserId !== undefined ? "AND requestedByUserId IS NOT ?" : ""}
|
|
1748
1800
|
ORDER BY createdAt DESC
|
|
1749
1801
|
LIMIT 1`,
|
|
1750
|
-
[
|
|
1802
|
+
[
|
|
1803
|
+
contextKey,
|
|
1804
|
+
...(options.requestedByUserId !== undefined ? [options.requestedByUserId] : []),
|
|
1805
|
+
...(options.notRequestedByUserId !== undefined ? [options.notRequestedByUserId] : []),
|
|
1806
|
+
],
|
|
1751
1807
|
);
|
|
1752
1808
|
return row ? rowToAgentTask(row) : null;
|
|
1753
1809
|
}
|
|
@@ -1889,19 +1945,62 @@ export async function getAgentWorkingOnContextKey(
|
|
|
1889
1945
|
return null;
|
|
1890
1946
|
}
|
|
1891
1947
|
|
|
1948
|
+
/**
|
|
1949
|
+
* Latest task whose contextKey starts with `prefix` (a half-open key range, so
|
|
1950
|
+
* the contextKey index serves it). The Chat SDK keys a Slack or Discord task by
|
|
1951
|
+
* `<channel>:<thread>`, while a slash command only knows the channel: the
|
|
1952
|
+
* prefix finds the tasks of every thread in it. `activeOnly` narrows to
|
|
1953
|
+
* `in_progress` and `pending`; `source` narrows as in the exact-key twins;
|
|
1954
|
+
* `requestedByUserId` keeps only that user's tasks.
|
|
1955
|
+
*/
|
|
1956
|
+
export async function getLatestTaskByContextKeyPrefix(
|
|
1957
|
+
prefix: string,
|
|
1958
|
+
options: { activeOnly?: boolean; source?: string; requestedByUserId?: string } = {},
|
|
1959
|
+
): Promise<AgentTask | null> {
|
|
1960
|
+
if (!prefix) return null;
|
|
1961
|
+
const upper = prefix.slice(0, -1) + String.fromCharCode(prefix.charCodeAt(prefix.length - 1) + 1);
|
|
1962
|
+
const source = options.source ?? null;
|
|
1963
|
+
const row = await getDbClient().get<AgentTaskRow>(
|
|
1964
|
+
`SELECT * FROM agent_tasks
|
|
1965
|
+
WHERE contextKey >= ? AND contextKey < ?
|
|
1966
|
+
AND ${contextKeySourceSql()}
|
|
1967
|
+
${options.activeOnly ? "AND status IN ('in_progress', 'pending')" : ""}
|
|
1968
|
+
${options.requestedByUserId !== undefined ? "AND requestedByUserId = ?" : ""}
|
|
1969
|
+
ORDER BY createdAt DESC, rowid DESC
|
|
1970
|
+
LIMIT 1`,
|
|
1971
|
+
[
|
|
1972
|
+
prefix,
|
|
1973
|
+
upper,
|
|
1974
|
+
source,
|
|
1975
|
+
source,
|
|
1976
|
+
source,
|
|
1977
|
+
...(options.requestedByUserId !== undefined ? [options.requestedByUserId] : []),
|
|
1978
|
+
],
|
|
1979
|
+
);
|
|
1980
|
+
return row ? rowToAgentTask(row) : null;
|
|
1981
|
+
}
|
|
1982
|
+
|
|
1892
1983
|
/** Latest `in_progress` or `pending` task on a contextKey (dependency chaining). */
|
|
1893
1984
|
export async function getLatestActiveTaskByContextKey(
|
|
1894
1985
|
contextKey: string,
|
|
1895
1986
|
source?: string,
|
|
1987
|
+
requestedByUserId?: string,
|
|
1896
1988
|
): Promise<AgentTask | null> {
|
|
1897
1989
|
const row = await getDbClient().get<AgentTaskRow>(
|
|
1898
1990
|
`SELECT * FROM agent_tasks
|
|
1899
1991
|
WHERE contextKey = ?
|
|
1900
1992
|
AND ${contextKeySourceSql()}
|
|
1901
1993
|
AND status IN ('in_progress', 'pending')
|
|
1994
|
+
${requestedByUserId !== undefined ? "AND requestedByUserId = ?" : ""}
|
|
1902
1995
|
ORDER BY createdAt DESC, rowid DESC
|
|
1903
1996
|
LIMIT 1`,
|
|
1904
|
-
[
|
|
1997
|
+
[
|
|
1998
|
+
contextKey,
|
|
1999
|
+
source ?? null,
|
|
2000
|
+
source ?? null,
|
|
2001
|
+
source ?? null,
|
|
2002
|
+
...(requestedByUserId !== undefined ? [requestedByUserId] : []),
|
|
2003
|
+
],
|
|
1905
2004
|
);
|
|
1906
2005
|
|
|
1907
2006
|
return row ? rowToAgentTask(row) : null;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { Workflow, WorkflowSnapshot } from "../../types";
|
|
2
|
+
import { getWorkflow } from "../db";
|
|
3
|
+
import { computeContentHash } from "./context-versions";
|
|
4
|
+
import { getDbClient } from "./runtime";
|
|
5
|
+
|
|
6
|
+
// A run is pinned to the definition it started with (migration 283). The
|
|
7
|
+
// snapshot lives once per distinct content in `workflow_run_definitions`, keyed
|
|
8
|
+
// by its hash; `workflow_runs.definitionHash` points at it. Rows are immutable,
|
|
9
|
+
// so a lookup never races an edit.
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The definition fields a run keeps from its start. `enabled` stays live: it
|
|
13
|
+
* does not stop in-flight runs today, and toggling it must not mint a new row.
|
|
14
|
+
* Row identity and the security principal (`id`, `key`, `createdByAgentId`)
|
|
15
|
+
* are not part of the snapshot and always come from the live row.
|
|
16
|
+
*/
|
|
17
|
+
export type PinnedWorkflowDefinition = Omit<WorkflowSnapshot, "enabled">;
|
|
18
|
+
|
|
19
|
+
export const PINNED_WORKFLOW_KEYS = [
|
|
20
|
+
"name",
|
|
21
|
+
"description",
|
|
22
|
+
"definition",
|
|
23
|
+
"triggers",
|
|
24
|
+
"cooldown",
|
|
25
|
+
"input",
|
|
26
|
+
"triggerSchema",
|
|
27
|
+
"params",
|
|
28
|
+
"requiredParams",
|
|
29
|
+
"requires",
|
|
30
|
+
"dir",
|
|
31
|
+
"vcsRepo",
|
|
32
|
+
] as const satisfies readonly (keyof PinnedWorkflowDefinition)[];
|
|
33
|
+
|
|
34
|
+
export function toPinnedDefinition(workflow: PinnedWorkflowDefinition): PinnedWorkflowDefinition {
|
|
35
|
+
const pinned: Record<string, unknown> = {};
|
|
36
|
+
for (const key of PINNED_WORKFLOW_KEYS) pinned[key] = workflow[key];
|
|
37
|
+
return pinned as PinnedWorkflowDefinition;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The stored snapshot and its hash. Nested key order is kept exactly as the
|
|
42
|
+
* definition wrote it: executors iterate config objects (script `args`, System
|
|
43
|
+
* One `questions` and `choices`) in insertion order, so a resumed run must see
|
|
44
|
+
* the order it started with, and two definitions that differ only in order get
|
|
45
|
+
* two rows. Only the top level is normalized (`PINNED_WORKFLOW_KEYS` order);
|
|
46
|
+
* absent and `undefined` fields serialize the same.
|
|
47
|
+
*/
|
|
48
|
+
export function hashPinnedDefinition(pinned: PinnedWorkflowDefinition): {
|
|
49
|
+
hash: string;
|
|
50
|
+
snapshot: string;
|
|
51
|
+
} {
|
|
52
|
+
const snapshot = JSON.stringify(toPinnedDefinition(pinned));
|
|
53
|
+
return { hash: computeContentHash(snapshot), snapshot };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Store the workflow's pinned definition (once per content) and return its hash. */
|
|
57
|
+
export async function pinWorkflowDefinition(workflow: Workflow): Promise<string> {
|
|
58
|
+
const { hash, snapshot } = hashPinnedDefinition(toPinnedDefinition(workflow));
|
|
59
|
+
await getDbClient().run(
|
|
60
|
+
"INSERT OR IGNORE INTO workflow_run_definitions (hash, snapshot, createdAt) VALUES (?, ?, ?)",
|
|
61
|
+
[hash, snapshot, new Date().toISOString()],
|
|
62
|
+
);
|
|
63
|
+
return hash;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** The pinned definition of a run, or null when the run has none (pre-283 or preflight-failed). */
|
|
67
|
+
export async function getPinnedRunDefinition(
|
|
68
|
+
runId: string,
|
|
69
|
+
): Promise<PinnedWorkflowDefinition | null> {
|
|
70
|
+
const row = await getDbClient().get<{ snapshot: string }>(
|
|
71
|
+
`SELECT d.snapshot FROM workflow_runs r
|
|
72
|
+
JOIN workflow_run_definitions d ON d.hash = r.definitionHash
|
|
73
|
+
WHERE r.id = ?`,
|
|
74
|
+
[runId],
|
|
75
|
+
);
|
|
76
|
+
// Not schema-validated, like `rowToWorkflow`: a later tightening of the
|
|
77
|
+
// definition schema must not break runs pinned under the old one.
|
|
78
|
+
return row ? (JSON.parse(row.snapshot) as PinnedWorkflowDefinition) : null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The live row with every pinned field taken from the snapshot. Each key is
|
|
83
|
+
* assigned explicitly, `undefined` included, so a field the edit added (a `dir`
|
|
84
|
+
* the run started without) cannot leak into the run.
|
|
85
|
+
*/
|
|
86
|
+
export function mergePinnedDefinition(live: Workflow, pinned: PinnedWorkflowDefinition): Workflow {
|
|
87
|
+
const merged: Record<string, unknown> = { ...live };
|
|
88
|
+
for (const key of PINNED_WORKFLOW_KEYS) merged[key] = pinned[key];
|
|
89
|
+
return merged as Workflow;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* The workflow a run executes: the definition it started with (migration 283)
|
|
94
|
+
* on top of the live row. Live fields (`enabled`, `key`, `createdByAgentId`,
|
|
95
|
+
* row metadata) come from the row. A run with no pin (created before 283, or
|
|
96
|
+
* a preflight failure) gets the live row unchanged. Null when the workflow is
|
|
97
|
+
* gone. Use this, not `getWorkflow`, for every read made on behalf of a run.
|
|
98
|
+
*/
|
|
99
|
+
export async function getRunWorkflow(run: {
|
|
100
|
+
id: string;
|
|
101
|
+
workflowId: string;
|
|
102
|
+
}): Promise<Workflow | null> {
|
|
103
|
+
const live = await getWorkflow(run.workflowId);
|
|
104
|
+
if (!live) return null;
|
|
105
|
+
const pinned = await getPinnedRunDefinition(run.id);
|
|
106
|
+
return pinned ? mergePinnedDefinition(live, pinned) : live;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Remove snapshots no run references any more. Call after deleting runs. */
|
|
110
|
+
export async function deleteOrphanedRunDefinitions(): Promise<void> {
|
|
111
|
+
await getDbClient().run(
|
|
112
|
+
`DELETE FROM workflow_run_definitions
|
|
113
|
+
WHERE NOT EXISTS (
|
|
114
|
+
SELECT 1 FROM workflow_runs r WHERE r.definitionHash = workflow_run_definitions.hash
|
|
115
|
+
)`,
|
|
116
|
+
);
|
|
117
|
+
}
|
package/src/be/db-client.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Database } from "bun:sqlite";
|
|
2
2
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
3
3
|
import { scrubSecrets } from "../utils/secret-scrubber";
|
|
4
|
+
import { currentLoopPath, recordStatement } from "./event-loop-lag";
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Async database seam.
|
|
@@ -216,14 +217,19 @@ const SLOW_STATEMENT_SQL_MAX_CHARS = 200;
|
|
|
216
217
|
|
|
217
218
|
/** Params are never logged: they can carry secrets and user content. */
|
|
218
219
|
function warnIfSlowStatement(sql: string, durationMs: number): void {
|
|
220
|
+
recordStatement(sql, durationMs);
|
|
219
221
|
if (durationMs < SLOW_STATEMENT_WARN_MS) return;
|
|
220
|
-
|
|
222
|
+
// Scrub the complete SQL before truncation, so a secret that straddles the
|
|
223
|
+
// cut cannot leave a partial token, then scrub the complete line at egress.
|
|
224
|
+
const flat = scrubSecrets(sql.replace(/\s+/g, " ").trim());
|
|
221
225
|
const shown =
|
|
222
226
|
flat.length > SLOW_STATEMENT_SQL_MAX_CHARS
|
|
223
227
|
? `${flat.slice(0, SLOW_STATEMENT_SQL_MAX_CHARS)}…`
|
|
224
228
|
: flat;
|
|
225
229
|
console.warn(
|
|
226
|
-
|
|
230
|
+
scrubSecrets(
|
|
231
|
+
`[db-client] slow sync statement blocked the event loop for ${Math.round(durationMs)}ms path=${currentLoopPath()}: ${shown}`,
|
|
232
|
+
),
|
|
227
233
|
);
|
|
228
234
|
}
|
|
229
235
|
|