@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
|
@@ -3,14 +3,17 @@ import { cosineSimilarity, deserializeEmbedding, serializeEmbedding } from "@/be
|
|
|
3
3
|
import { contentSha256 } from "@/commands/profile-sync";
|
|
4
4
|
import type { AgentMemory, AgentMemoryScope, AgentMemorySource } from "@/types";
|
|
5
5
|
import { scrubSecrets } from "@/utils/secret-scrubber";
|
|
6
|
+
import { currentLoopPath, withLoopPath } from "../../event-loop-lag";
|
|
6
7
|
import {
|
|
7
8
|
EMBEDDING_DIMENSIONS,
|
|
9
|
+
EXHAUSTIVE_SEARCH_MAX_ROWS,
|
|
8
10
|
isHybridSearchEnabled,
|
|
11
|
+
LEARNING_TTL_DAYS,
|
|
9
12
|
minSimilarity,
|
|
10
13
|
PROTECTED_SOURCES,
|
|
11
14
|
TTL_DEFAULTS,
|
|
12
15
|
} from "../constants";
|
|
13
|
-
import { isLongtermKey, LONGTERM_ROOT, tierSource } from "../key-paths";
|
|
16
|
+
import { isLearningKey, isLongtermKey, LONGTERM_ROOT, tierSource } from "../key-paths";
|
|
14
17
|
import { recencyDecay } from "../reranker";
|
|
15
18
|
import { MAX_CANDIDATE_FETCH } from "../search-candidates";
|
|
16
19
|
import type {
|
|
@@ -193,7 +196,7 @@ export function applyEditMode(
|
|
|
193
196
|
}
|
|
194
197
|
|
|
195
198
|
function computeExpiresAt(source: AgentMemorySource, key: string | null): string | null {
|
|
196
|
-
const ttlDays = TTL_DEFAULTS[tierSource(source, key)];
|
|
199
|
+
const ttlDays = isLearningKey(key) ? LEARNING_TTL_DAYS : TTL_DEFAULTS[tierSource(source, key)];
|
|
197
200
|
if (ttlDays == null) return null;
|
|
198
201
|
return new Date(Date.now() + ttlDays * 86400000).toISOString();
|
|
199
202
|
}
|
|
@@ -613,6 +616,17 @@ export class SqliteMemoryStore implements MemoryStore {
|
|
|
613
616
|
embedding: Float32Array,
|
|
614
617
|
agentId: string,
|
|
615
618
|
options: MemorySearchOptions = {},
|
|
619
|
+
): Promise<MemoryCandidate[]> {
|
|
620
|
+
// Nested breadcrumb: the stall line keeps the caller and names the search.
|
|
621
|
+
return withLoopPath(`${currentLoopPath()} > memory.search`, () =>
|
|
622
|
+
this.searchInLoopPath(embedding, agentId, options),
|
|
623
|
+
);
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
private async searchInLoopPath(
|
|
627
|
+
embedding: Float32Array,
|
|
628
|
+
agentId: string,
|
|
629
|
+
options: MemorySearchOptions,
|
|
616
630
|
): Promise<MemoryCandidate[]> {
|
|
617
631
|
const {
|
|
618
632
|
scope = "all",
|
|
@@ -623,6 +637,18 @@ export class SqliteMemoryStore implements MemoryStore {
|
|
|
623
637
|
keyPrefix,
|
|
624
638
|
} = options;
|
|
625
639
|
|
|
640
|
+
if (options.exhaustive) {
|
|
641
|
+
return this.searchExhaustive(embedding, agentId, {
|
|
642
|
+
scope,
|
|
643
|
+
limit,
|
|
644
|
+
source,
|
|
645
|
+
isLead,
|
|
646
|
+
includeExpired,
|
|
647
|
+
keyPrefix,
|
|
648
|
+
minSimilarity: options.minSimilarity,
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
|
|
626
652
|
const health = this.getHealth();
|
|
627
653
|
if (
|
|
628
654
|
isHybridSearchEnabled() &&
|
|
@@ -656,6 +682,7 @@ export class SqliteMemoryStore implements MemoryStore {
|
|
|
656
682
|
isLead,
|
|
657
683
|
includeExpired,
|
|
658
684
|
keyPrefix,
|
|
685
|
+
minSimilarity: options.minSimilarity,
|
|
659
686
|
});
|
|
660
687
|
}
|
|
661
688
|
|
|
@@ -683,6 +710,7 @@ export class SqliteMemoryStore implements MemoryStore {
|
|
|
683
710
|
isLead,
|
|
684
711
|
includeExpired,
|
|
685
712
|
keyPrefix,
|
|
713
|
+
minSimilarity: options.minSimilarity,
|
|
686
714
|
});
|
|
687
715
|
}
|
|
688
716
|
|
|
@@ -855,9 +883,11 @@ export class SqliteMemoryStore implements MemoryStore {
|
|
|
855
883
|
isLead: boolean;
|
|
856
884
|
includeExpired: boolean;
|
|
857
885
|
keyPrefix?: string;
|
|
886
|
+
minSimilarity?: number;
|
|
858
887
|
},
|
|
859
888
|
): Promise<MemoryCandidate[]> {
|
|
860
889
|
const { scope, limit, source, isLead, includeExpired, keyPrefix } = options;
|
|
890
|
+
const floor = options.minSimilarity ?? minSimilarity();
|
|
861
891
|
|
|
862
892
|
const embeddingBuffer = serializeEmbedding(queryEmbedding);
|
|
863
893
|
// sqlite-vec hard ceiling is 4096 for knn queries
|
|
@@ -894,13 +924,135 @@ export class SqliteMemoryStore implements MemoryStore {
|
|
|
894
924
|
const candidates: MemoryCandidate[] = [];
|
|
895
925
|
for (const row of rows) {
|
|
896
926
|
const similarity = 1 - row.distance;
|
|
897
|
-
if (similarity <
|
|
927
|
+
if (similarity < floor) continue;
|
|
898
928
|
candidates.push({ ...rowToCandidate(row, similarity), retrievalSource: "vec" });
|
|
899
929
|
}
|
|
900
930
|
|
|
901
931
|
return candidates;
|
|
902
932
|
}
|
|
903
933
|
|
|
934
|
+
/**
|
|
935
|
+
* Exact cosine over the newest EXHAUSTIVE_SEARCH_MAX_ROWS eligible rows,
|
|
936
|
+
* `updatedAt DESC` with an `id` tie-break. While the eligible set fits the
|
|
937
|
+
* cap, every eligible row is scored; past it, older rows are not scored and
|
|
938
|
+
* the call logs `capped=true`. With sqlite-vec loaded, SQLite scores the
|
|
939
|
+
* capped set with `vec_distance_cosine` and only the top `limit` rows leave
|
|
940
|
+
* the query. Without it, JS scores the same capped set reading only id and
|
|
941
|
+
* embedding, then loads full rows for the top `limit`. One call's memory and
|
|
942
|
+
* CPU stay bounded whatever the corpus size, and a missing extension never
|
|
943
|
+
* makes it throw.
|
|
944
|
+
*/
|
|
945
|
+
private async searchExhaustive(
|
|
946
|
+
queryEmbedding: Float32Array,
|
|
947
|
+
agentId: string,
|
|
948
|
+
options: {
|
|
949
|
+
scope: string;
|
|
950
|
+
limit: number;
|
|
951
|
+
source?: AgentMemorySource;
|
|
952
|
+
isLead: boolean;
|
|
953
|
+
includeExpired: boolean;
|
|
954
|
+
keyPrefix?: string;
|
|
955
|
+
minSimilarity?: number;
|
|
956
|
+
},
|
|
957
|
+
): Promise<MemoryCandidate[]> {
|
|
958
|
+
const { scope, limit, source, isLead, includeExpired, keyPrefix } = options;
|
|
959
|
+
const floor = options.minSimilarity ?? minSimilarity();
|
|
960
|
+
|
|
961
|
+
const conditions: string[] = ["embedding IS NOT NULL"];
|
|
962
|
+
const params: (string | number | null)[] = [];
|
|
963
|
+
this.addScopeConditions(conditions, params, agentId, scope, isLead);
|
|
964
|
+
this.addKeyPrefixCondition(conditions, params, keyPrefix);
|
|
965
|
+
if (source) {
|
|
966
|
+
conditions.push("source = ?");
|
|
967
|
+
params.push(source);
|
|
968
|
+
}
|
|
969
|
+
if (!includeExpired) {
|
|
970
|
+
conditions.push("(expiresAt IS NULL OR expiresAt > datetime('now'))");
|
|
971
|
+
}
|
|
972
|
+
// FROM..LIMIT of the capped eligible set, newest first, so a capped scan
|
|
973
|
+
// drops the oldest rows. Each path adds its own projection.
|
|
974
|
+
const capped = `FROM agent_memory
|
|
975
|
+
WHERE ${conditions.join(" AND ")}
|
|
976
|
+
ORDER BY updatedAt DESC, id
|
|
977
|
+
LIMIT ?`;
|
|
978
|
+
const cappedParams = [...params, EXHAUSTIVE_SEARCH_MAX_ROWS];
|
|
979
|
+
|
|
980
|
+
const { scanned, top } = isSqliteVecAvailable()
|
|
981
|
+
? await this.scoreCappedInSql(queryEmbedding, capped, cappedParams, floor, limit)
|
|
982
|
+
: await this.scoreCappedInJs(queryEmbedding, capped, cappedParams, floor, limit);
|
|
983
|
+
console.log(
|
|
984
|
+
`[memory-search] retrieval_path=exhaustive scope=${scope} limit=${limit} scanned=${scanned} hits=${top.length}${scanned >= EXHAUSTIVE_SEARCH_MAX_ROWS ? " capped=true" : ""}`,
|
|
985
|
+
);
|
|
986
|
+
if (top.length === 0) return [];
|
|
987
|
+
|
|
988
|
+
const rows = await getDbClient().query<AgentMemoryRow>(
|
|
989
|
+
`SELECT * FROM agent_memory WHERE id IN (${top.map(() => "?").join(", ")})`,
|
|
990
|
+
top.map((hit) => hit.id),
|
|
991
|
+
);
|
|
992
|
+
const byId = new Map(rows.map((row) => [row.id, row]));
|
|
993
|
+
const candidates: MemoryCandidate[] = [];
|
|
994
|
+
for (const hit of top) {
|
|
995
|
+
const row = byId.get(hit.id);
|
|
996
|
+
if (row)
|
|
997
|
+
candidates.push({ ...rowToCandidate(row, hit.similarity), retrievalSource: "fallback" });
|
|
998
|
+
}
|
|
999
|
+
return candidates;
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
/** Rank the capped set inside SQLite; only the top `limit` ids leave the query. */
|
|
1003
|
+
private async scoreCappedInSql(
|
|
1004
|
+
queryEmbedding: Float32Array,
|
|
1005
|
+
capped: string,
|
|
1006
|
+
cappedParams: (string | number | null)[],
|
|
1007
|
+
floor: number,
|
|
1008
|
+
limit: number,
|
|
1009
|
+
): Promise<{ scanned: number; top: { id: string; similarity: number }[] }> {
|
|
1010
|
+
const db = getDbClient();
|
|
1011
|
+
const counted = await db.get<{ n: number }>(
|
|
1012
|
+
`SELECT COUNT(*) AS n FROM (SELECT 1 ${capped})`,
|
|
1013
|
+
cappedParams,
|
|
1014
|
+
);
|
|
1015
|
+
const queryBuffer = serializeEmbedding(queryEmbedding);
|
|
1016
|
+
// The length guard keeps a row of another dimension from raising inside
|
|
1017
|
+
// vec_distance_cosine; a zero vector scores NULL and fails the floor.
|
|
1018
|
+
const top = await db.query<{ id: string; similarity: number }>(
|
|
1019
|
+
`SELECT id, similarity FROM (
|
|
1020
|
+
SELECT id,
|
|
1021
|
+
CASE WHEN length(embedding) = ? THEN 1 - vec_distance_cosine(embedding, ?) END
|
|
1022
|
+
AS similarity
|
|
1023
|
+
FROM (SELECT id, embedding ${capped})
|
|
1024
|
+
)
|
|
1025
|
+
WHERE similarity >= ?
|
|
1026
|
+
ORDER BY similarity DESC, id
|
|
1027
|
+
LIMIT ?`,
|
|
1028
|
+
[queryBuffer.byteLength, queryBuffer, ...cappedParams, floor, limit],
|
|
1029
|
+
);
|
|
1030
|
+
return { scanned: counted?.n ?? 0, top };
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
/** Score the capped set in JS when sqlite-vec is not loaded, reading only id + embedding. */
|
|
1034
|
+
private async scoreCappedInJs(
|
|
1035
|
+
queryEmbedding: Float32Array,
|
|
1036
|
+
capped: string,
|
|
1037
|
+
cappedParams: (string | number | null)[],
|
|
1038
|
+
floor: number,
|
|
1039
|
+
limit: number,
|
|
1040
|
+
): Promise<{ scanned: number; top: { id: string; similarity: number }[] }> {
|
|
1041
|
+
const rows = await getDbClient().query<{ id: string; embedding: Buffer }>(
|
|
1042
|
+
`SELECT id, embedding ${capped}`,
|
|
1043
|
+
cappedParams,
|
|
1044
|
+
);
|
|
1045
|
+
const scored: { id: string; similarity: number }[] = [];
|
|
1046
|
+
for (const row of rows) {
|
|
1047
|
+
const emb = deserializeEmbedding(row.embedding);
|
|
1048
|
+
if (emb.length !== queryEmbedding.length) continue;
|
|
1049
|
+
const similarity = cosineSimilarity(queryEmbedding, emb);
|
|
1050
|
+
if (similarity >= floor) scored.push({ id: row.id, similarity });
|
|
1051
|
+
}
|
|
1052
|
+
scored.sort((a, b) => b.similarity - a.similarity || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
|
|
1053
|
+
return { scanned: rows.length, top: scored.slice(0, limit) };
|
|
1054
|
+
}
|
|
1055
|
+
|
|
904
1056
|
private async searchBruteForce(
|
|
905
1057
|
queryEmbedding: Float32Array,
|
|
906
1058
|
agentId: string,
|
|
@@ -911,9 +1063,11 @@ export class SqliteMemoryStore implements MemoryStore {
|
|
|
911
1063
|
isLead: boolean;
|
|
912
1064
|
includeExpired: boolean;
|
|
913
1065
|
keyPrefix?: string;
|
|
1066
|
+
minSimilarity?: number;
|
|
914
1067
|
},
|
|
915
1068
|
): Promise<MemoryCandidate[]> {
|
|
916
1069
|
const { scope, limit, source, isLead, includeExpired, keyPrefix } = options;
|
|
1070
|
+
const floor = options.minSimilarity ?? minSimilarity();
|
|
917
1071
|
|
|
918
1072
|
const conditions: string[] = ["embedding IS NOT NULL"];
|
|
919
1073
|
const params: (string | null)[] = [];
|
|
@@ -943,7 +1097,7 @@ export class SqliteMemoryStore implements MemoryStore {
|
|
|
943
1097
|
const emb = deserializeEmbedding(row.embedding);
|
|
944
1098
|
if (emb.length !== queryEmbedding.length) continue;
|
|
945
1099
|
const similarity = cosineSimilarity(queryEmbedding, emb);
|
|
946
|
-
if (similarity <
|
|
1100
|
+
if (similarity < floor) continue;
|
|
947
1101
|
candidates.push({ ...rowToCandidate(row, similarity), retrievalSource: "fallback" });
|
|
948
1102
|
}
|
|
949
1103
|
|
|
@@ -1149,9 +1303,16 @@ export class SqliteMemoryStore implements MemoryStore {
|
|
|
1149
1303
|
if (taken) throw new Error(`key "${input.newKey}" is already used in this scope`);
|
|
1150
1304
|
}
|
|
1151
1305
|
|
|
1152
|
-
//
|
|
1153
|
-
//
|
|
1154
|
-
|
|
1306
|
+
// A move takes the expiry of its destination when the key decides it:
|
|
1307
|
+
// into /longterm (curated, never expires), into /learnings (ages out) or
|
|
1308
|
+
// out of /learnings (the source's own TTL; none for manual). Any other
|
|
1309
|
+
// move, and every in-place edit, keeps the expiry the row already has.
|
|
1310
|
+
const resetExpiry =
|
|
1311
|
+
moving &&
|
|
1312
|
+
(isLongtermKey(input.newKey) || isLearningKey(row.key) !== isLearningKey(input.newKey));
|
|
1313
|
+
const expiresAt = resetExpiry
|
|
1314
|
+
? computeExpiresAt(row.source as AgentMemorySource, input.newKey!)
|
|
1315
|
+
: row.expiresAt;
|
|
1155
1316
|
const now = new Date().toISOString();
|
|
1156
1317
|
const versionIntent = moving
|
|
1157
1318
|
? `${input.intent} [key ${row.key ?? "(none)"} -> ${input.newKey}]`
|
|
@@ -1185,7 +1346,7 @@ export class SqliteMemoryStore implements MemoryStore {
|
|
|
1185
1346
|
await tx.run(
|
|
1186
1347
|
`UPDATE agent_memory
|
|
1187
1348
|
SET content = ?, contentHash = ?, version = ?, updatedAt = ?, key = ?,
|
|
1188
|
-
expiresAt = CASE WHEN ? = 1 THEN
|
|
1349
|
+
expiresAt = CASE WHEN ? = 1 THEN ? ELSE expiresAt END
|
|
1189
1350
|
WHERE id = ?`,
|
|
1190
1351
|
[
|
|
1191
1352
|
targetContent,
|
|
@@ -1193,7 +1354,8 @@ export class SqliteMemoryStore implements MemoryStore {
|
|
|
1193
1354
|
targetVersion,
|
|
1194
1355
|
now,
|
|
1195
1356
|
moving ? input.newKey! : target.key,
|
|
1196
|
-
|
|
1357
|
+
resetExpiry ? 1 : 0,
|
|
1358
|
+
expiresAt,
|
|
1197
1359
|
target.id,
|
|
1198
1360
|
],
|
|
1199
1361
|
);
|
|
@@ -1208,7 +1370,7 @@ export class SqliteMemoryStore implements MemoryStore {
|
|
|
1208
1370
|
version: nextVersion,
|
|
1209
1371
|
updatedAt: now,
|
|
1210
1372
|
key: moving ? input.newKey! : row.key,
|
|
1211
|
-
expiresAt
|
|
1373
|
+
expiresAt,
|
|
1212
1374
|
}),
|
|
1213
1375
|
changed: true,
|
|
1214
1376
|
previousVersion,
|
|
@@ -1308,24 +1470,43 @@ export class SqliteMemoryStore implements MemoryStore {
|
|
|
1308
1470
|
const db = getDbClient();
|
|
1309
1471
|
|
|
1310
1472
|
const expiredIds = await db.query<{ id: string }>(
|
|
1311
|
-
"SELECT id FROM agent_memory WHERE expiresAt IS NOT NULL AND expiresAt <= datetime('now')",
|
|
1473
|
+
"SELECT id FROM agent_memory WHERE expiresAt IS NOT NULL AND expiresAt <= datetime('now') ORDER BY id",
|
|
1312
1474
|
);
|
|
1313
1475
|
|
|
1314
1476
|
if (expiredIds.length === 0) return 0;
|
|
1315
1477
|
|
|
1316
1478
|
const batchSize = 500;
|
|
1479
|
+
let purged = 0;
|
|
1317
1480
|
for (let i = 0; i < expiredIds.length; i += batchSize) {
|
|
1318
|
-
|
|
1481
|
+
// Yield a macrotask between batches: chained awaits on the DB client are
|
|
1482
|
+
// microtasks, so without it the whole purge is one event-loop stall.
|
|
1483
|
+
if (i > 0) await new Promise<void>((resolve) => setImmediate(resolve));
|
|
1484
|
+
const batch = expiredIds.slice(i, i + batchSize).map((r) => r.id);
|
|
1485
|
+
// A memory can be curated (moved to /longterm, expiry cleared) during
|
|
1486
|
+
// the yield. Recheck expiry and delete the index rows and memory rows of
|
|
1487
|
+
// the batch in one transaction, so a live row never loses its index.
|
|
1488
|
+
purged += await db.transaction(async (tx) => {
|
|
1489
|
+
const placeholders = batch.map(() => "?").join(",");
|
|
1490
|
+
const still = await tx.query<{ id: string }>(
|
|
1491
|
+
`SELECT id FROM agent_memory WHERE id IN (${placeholders})
|
|
1492
|
+
AND expiresAt IS NOT NULL AND expiresAt <= datetime('now')`,
|
|
1493
|
+
batch,
|
|
1494
|
+
);
|
|
1495
|
+
const ids = still.map((r) => r.id);
|
|
1496
|
+
if (ids.length === 0) return 0;
|
|
1497
|
+
await this.purgeByIds(ids);
|
|
1498
|
+
const result = await tx.run(
|
|
1499
|
+
`DELETE FROM agent_memory WHERE id IN (${ids.map(() => "?").join(",")})`,
|
|
1500
|
+
ids,
|
|
1501
|
+
);
|
|
1502
|
+
return result.changes;
|
|
1503
|
+
});
|
|
1319
1504
|
}
|
|
1320
1505
|
|
|
1321
|
-
const result = await db.run(
|
|
1322
|
-
"DELETE FROM agent_memory WHERE expiresAt IS NOT NULL AND expiresAt <= datetime('now')",
|
|
1323
|
-
);
|
|
1324
|
-
|
|
1325
1506
|
console.log(
|
|
1326
|
-
`[memory] Purged ${
|
|
1507
|
+
`[memory] Purged ${purged} expired memory row(s) (candidates: ${expiredIds.length} id(s))`,
|
|
1327
1508
|
);
|
|
1328
|
-
return
|
|
1509
|
+
return purged;
|
|
1329
1510
|
}
|
|
1330
1511
|
|
|
1331
1512
|
async updateEmbedding(id: string, embedding: Float32Array, model: string): Promise<void> {
|
|
@@ -4,18 +4,27 @@
|
|
|
4
4
|
* `sourceTaskId`, so "what did we learn doing X" is one `keyPrefix` search.
|
|
5
5
|
*
|
|
6
6
|
* Source stays `manual` so nightly curation (memtax B1 reads only manual and
|
|
7
|
-
* file_index rows) picks learnings up without a new source value.
|
|
7
|
+
* file_index rows) picks learnings up without a new source value. The key
|
|
8
|
+
* gives it a LEARNING_TTL_DAYS expiry: what is worth keeping gets distilled
|
|
9
|
+
* into `/longterm`, the rest ages out.
|
|
8
10
|
*
|
|
9
|
-
* A learning close to an existing swarm memory
|
|
10
|
-
*
|
|
11
|
-
* positive rating instead. Known gap:
|
|
12
|
-
* so two near-identical learnings
|
|
13
|
-
* Nightly curation catches those.
|
|
11
|
+
* A learning close to an existing swarm memory under `/learnings` or
|
|
12
|
+
* `/longterm` (raw cosine at or above LEARNING_DUPLICATE_MIN_SIMILARITY) is
|
|
13
|
+
* not stored: the existing row gets a positive rating instead. Known gap:
|
|
14
|
+
* embeddings are written in the background, so two near-identical learnings
|
|
15
|
+
* seconds apart can both pass the check. Nightly curation catches those.
|
|
16
|
+
*
|
|
17
|
+
* Before any of that, a noise floor rejects text that cannot hold a lesson:
|
|
18
|
+
* under LEARNING_MIN_CHARS, or a restatement of the same call's progress or
|
|
19
|
+
* output. Calibrated on the stored learnings (see LEARNING_MIN_CHARS). A
|
|
20
|
+
* "needs a second line" rule was measured and dropped: it would have rejected
|
|
21
|
+
* 15% of the rated or retrieved learnings, most of them good one-line gotchas.
|
|
14
22
|
*/
|
|
15
23
|
import { getDbClient } from "@/be/db";
|
|
16
24
|
import { getEmbeddingProvider, getMemoryStore } from "@/be/memory";
|
|
17
25
|
import { LEARNING_DUPLICATE_MIN_SIMILARITY } from "@/be/memory/constants";
|
|
18
26
|
import { indexMemoryContent } from "@/be/memory/index-content";
|
|
27
|
+
import { LEARNINGS_ROOT, LONGTERM_ROOT } from "@/be/memory/key-paths";
|
|
19
28
|
import { applyRating } from "@/be/memory/raters/store";
|
|
20
29
|
import { contentSha256 } from "@/commands/profile-sync";
|
|
21
30
|
import type { AgentTask } from "@/types";
|
|
@@ -24,11 +33,16 @@ import { scrubSecrets } from "@/utils/secret-scrubber";
|
|
|
24
33
|
/** ~500 tokens at ceil(chars / 4); also keeps a learning to one memory chunk. */
|
|
25
34
|
export const LEARNING_MAX_CHARS = 2000;
|
|
26
35
|
export const LEARNING_MAX_TAGS = 5;
|
|
27
|
-
|
|
36
|
+
/**
|
|
37
|
+
* ~20 tokens: room for a title and a "When X, do Y" rule, not for a status
|
|
38
|
+
* line. No stored learning was under 130 characters when this was set, so the
|
|
39
|
+
* floor rejects none of them.
|
|
40
|
+
*/
|
|
41
|
+
export const LEARNING_MIN_CHARS = 80;
|
|
28
42
|
const SEGMENT_MAX_CHARS = 60;
|
|
29
43
|
const KEY_ATTEMPTS = 4;
|
|
30
|
-
/** Where a near duplicate can already live: any workstream's learnings and the
|
|
31
|
-
const DUPLICATE_SEARCH_PREFIXES = [`${LEARNINGS_ROOT}/`,
|
|
44
|
+
/** Where a near duplicate can already live: any workstream's learnings and the whole curated tree. */
|
|
45
|
+
const DUPLICATE_SEARCH_PREFIXES = [`${LEARNINGS_ROOT}/`, `${LONGTERM_ROOT}/`];
|
|
32
46
|
/** memory_rating.source for the positive rating a duplicate gives the existing row. */
|
|
33
47
|
export const LEARNING_DUPLICATE_RATING_SOURCE = "learning-duplicate";
|
|
34
48
|
|
|
@@ -38,7 +52,10 @@ export type TaskLearningResult =
|
|
|
38
52
|
| { status: "stored"; memoryId: string; key: string; workstream: string }
|
|
39
53
|
| { status: "replayed"; memoryId: string; key: string }
|
|
40
54
|
| { status: "duplicate"; memoryId: string; key: string; similarity: number }
|
|
41
|
-
| { status: "failed"; error: string };
|
|
55
|
+
| { status: "failed"; error: string; noiseFloor?: LearningNoiseFloor };
|
|
56
|
+
|
|
57
|
+
/** Which noise-floor rule rejected a learning; drives the store-progress nudge. */
|
|
58
|
+
export type LearningNoiseFloor = "too-short" | "repeats-progress";
|
|
42
59
|
|
|
43
60
|
/** Lowercase kebab slug: `Agent Swarm!` -> `agent-swarm`. Empty when nothing usable is left. */
|
|
44
61
|
export function toKebab(value: string, maxChars = SEGMENT_MAX_CHARS): string {
|
|
@@ -73,6 +90,8 @@ export async function storeTaskLearning(params: {
|
|
|
73
90
|
isLead: boolean;
|
|
74
91
|
task: Pick<AgentTask, "id" | "vcsRepo">;
|
|
75
92
|
learning: TaskLearningInput;
|
|
93
|
+
/** The same call's progress and output: a learning that only restates them is rejected. */
|
|
94
|
+
sameCall?: { progress?: string; output?: string };
|
|
76
95
|
}): Promise<TaskLearningResult> {
|
|
77
96
|
const { agentId, isLead, task } = params;
|
|
78
97
|
const input = typeof params.learning === "string" ? { text: params.learning } : params.learning;
|
|
@@ -93,6 +112,8 @@ export async function storeTaskLearning(params: {
|
|
|
93
112
|
if (tags.length > LEARNING_MAX_TAGS) {
|
|
94
113
|
return { status: "failed", error: `learning takes at most ${LEARNING_MAX_TAGS} tags` };
|
|
95
114
|
}
|
|
115
|
+
const noise = checkNoiseFloor(text, params.sameCall);
|
|
116
|
+
if (noise) return noise;
|
|
96
117
|
|
|
97
118
|
const workstream = resolveLearningWorkstream(
|
|
98
119
|
input.workstream === undefined ? undefined : scrubSecrets(input.workstream),
|
|
@@ -122,6 +143,40 @@ export async function storeTaskLearning(params: {
|
|
|
122
143
|
}
|
|
123
144
|
}
|
|
124
145
|
|
|
146
|
+
/** Lowercase, whitespace collapsed: the comparison form for the restatement check. */
|
|
147
|
+
function normalizeForEcho(value: string): string {
|
|
148
|
+
return value.toLowerCase().replace(/\s+/g, " ").trim();
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* The write-time noise floor. Exact rules only: a fuzzy word-overlap check
|
|
153
|
+
* against the task output was measured too, and every learning it caught was
|
|
154
|
+
* a real lesson that shared the output's vocabulary.
|
|
155
|
+
*/
|
|
156
|
+
export function checkNoiseFloor(
|
|
157
|
+
text: string,
|
|
158
|
+
sameCall: { progress?: string; output?: string } | undefined,
|
|
159
|
+
): Extract<TaskLearningResult, { status: "failed" }> | null {
|
|
160
|
+
if (text.length < LEARNING_MIN_CHARS) {
|
|
161
|
+
return {
|
|
162
|
+
status: "failed",
|
|
163
|
+
noiseFloor: "too-short",
|
|
164
|
+
error: `learning is under ${LEARNING_MIN_CHARS} characters; write a title line, then the rule as "When X, do Y"`,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
const learning = normalizeForEcho(text);
|
|
168
|
+
for (const [field, value] of Object.entries(sameCall ?? {})) {
|
|
169
|
+
if (value && normalizeForEcho(scrubSecrets(value)).includes(learning)) {
|
|
170
|
+
return {
|
|
171
|
+
status: "failed",
|
|
172
|
+
noiseFloor: "repeats-progress",
|
|
173
|
+
error: `learning repeats this call's ${field}; store the rule the next agent should follow, not the result`,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
|
|
125
180
|
async function findReplay(
|
|
126
181
|
taskId: string,
|
|
127
182
|
contentHash: string,
|
|
@@ -137,10 +192,14 @@ async function findReplay(
|
|
|
137
192
|
|
|
138
193
|
/**
|
|
139
194
|
* The closest swarm memory under the duplicate prefixes when its raw cosine to
|
|
140
|
-
* the learning reaches the threshold.
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
195
|
+
* the learning reaches the threshold. The search scores each prefix's stored
|
|
196
|
+
* embeddings directly, so `similarity` is raw cosine (not an FTS rank or a
|
|
197
|
+
* fused score) and no amount of closer rows outside the prefixes can hide a
|
|
198
|
+
* match. Each prefix scan is bounded at EXHAUSTIVE_SEARCH_MAX_ROWS eligible
|
|
199
|
+
* rows, newest first: exact while a prefix holds at most that many, and past
|
|
200
|
+
* it an older twin is missed and the search logs `capped=true`. Without
|
|
201
|
+
* sqlite-vec the same capped scan runs in JS. Any failure (no embedding
|
|
202
|
+
* provider, a search error) returns null so the learning is stored as usual.
|
|
144
203
|
*/
|
|
145
204
|
async function findNearDuplicate(params: {
|
|
146
205
|
agentId: string;
|
|
@@ -158,6 +217,12 @@ async function findNearDuplicate(params: {
|
|
|
158
217
|
isLead: params.isLead,
|
|
159
218
|
keyPrefix,
|
|
160
219
|
limit: 1,
|
|
220
|
+
// The vector index ranks the whole table before the prefix filter;
|
|
221
|
+
// past 4096 closer rows elsewhere it would hide a real duplicate.
|
|
222
|
+
exhaustive: true,
|
|
223
|
+
// The dedup bar, not the retrieval floor: MEMORY_MIN_SIMILARITY above
|
|
224
|
+
// it would drop a real duplicate before the threshold check below.
|
|
225
|
+
minSimilarity: LEARNING_DUPLICATE_MIN_SIMILARITY,
|
|
161
226
|
}),
|
|
162
227
|
),
|
|
163
228
|
);
|
package/src/be/memory/types.ts
CHANGED
|
@@ -150,8 +150,31 @@ export interface MemorySearchOptions {
|
|
|
150
150
|
isLead?: boolean;
|
|
151
151
|
includeExpired?: boolean;
|
|
152
152
|
queryText?: string;
|
|
153
|
-
/**
|
|
153
|
+
/**
|
|
154
|
+
* Keep only memories whose `key` starts with this string. The vector arm
|
|
155
|
+
* applies it after the sqlite-vec KNN (capped at 4096 rows), so a prefix
|
|
156
|
+
* whose rows all rank below that cap returns nothing; pass `exhaustive`
|
|
157
|
+
* when a miss is not acceptable.
|
|
158
|
+
*/
|
|
154
159
|
keyPrefix?: string;
|
|
160
|
+
/**
|
|
161
|
+
* Score eligible rows' stored embeddings instead of the vector index's
|
|
162
|
+
* top-K, so rows outside `keyPrefix` can never hide a match. Bounded: it
|
|
163
|
+
* scores at most EXHAUSTIVE_SEARCH_MAX_ROWS eligible rows, newest
|
|
164
|
+
* `updatedAt` first, so it is exact only while the eligible set fits the
|
|
165
|
+
* cap; past it, older rows are not scored and the search logs
|
|
166
|
+
* `capped=true`. With sqlite-vec, SQLite ranks the capped set
|
|
167
|
+
* (`vec_distance_cosine`); without it, JS scores the same set reading only
|
|
168
|
+
* id and embedding. Either way only the top `limit` full rows are loaded.
|
|
169
|
+
* Ignores `queryText`.
|
|
170
|
+
*/
|
|
171
|
+
exhaustive?: boolean;
|
|
172
|
+
/**
|
|
173
|
+
* Raw-cosine floor for this call, replacing MEMORY_MIN_SIMILARITY. Honored by
|
|
174
|
+
* the exhaustive, vector and brute-force paths (raw cosine); the FTS and
|
|
175
|
+
* hybrid paths score differently and ignore it.
|
|
176
|
+
*/
|
|
177
|
+
minSimilarity?: number;
|
|
155
178
|
}
|
|
156
179
|
|
|
157
180
|
/**
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
-- Cut the Slack render-v2 reconcile cost. bun:sqlite is synchronous, so each
|
|
2
|
+
-- discovery query in the 3 s render tick blocks the event loop for its full
|
|
3
|
+
-- run. All three scanned the whole render-v2 history on every tick.
|
|
4
|
+
|
|
5
|
+
-- Deferral resolution anchors on the few tasks that ever deferred instead of
|
|
6
|
+
-- on every outcome card.
|
|
7
|
+
CREATE INDEX IF NOT EXISTS idx_agent_tasks_deferred
|
|
8
|
+
ON agent_tasks(id)
|
|
9
|
+
WHERE deferredAt IS NOT NULL;
|
|
10
|
+
|
|
11
|
+
-- A tree is closed once the tree sweep has nothing left to do for it. The
|
|
12
|
+
-- sweep reads only open trees. Any write that could give the thread work
|
|
13
|
+
-- again (a task in the thread, an outcome card in the thread) reopens it
|
|
14
|
+
-- through the triggers below, so "closed" stays a pure cache of "the sweep
|
|
15
|
+
-- would skip it".
|
|
16
|
+
ALTER TABLE slack_messages ADD COLUMN closed_at TEXT;
|
|
17
|
+
|
|
18
|
+
CREATE INDEX IF NOT EXISTS idx_slack_messages_open_trees
|
|
19
|
+
ON slack_messages(created_at)
|
|
20
|
+
WHERE kind = 'tree' AND closed_at IS NULL;
|
|
21
|
+
|
|
22
|
+
-- Backfill: close every tree the sweep (getSlackTreeMessages) skips today.
|
|
23
|
+
-- Keep this predicate in step with SLACK_TREE_NEEDS_RENDER_SQL in src/be/db.ts.
|
|
24
|
+
UPDATE slack_messages AS tree
|
|
25
|
+
SET closed_at = strftime('%Y-%m-%dT%H:%M:%fZ', 'now')
|
|
26
|
+
WHERE tree.kind = 'tree'
|
|
27
|
+
AND tree.closed_at IS NULL
|
|
28
|
+
AND tree.ts NOT LIKE 'pending:%'
|
|
29
|
+
AND EXISTS (SELECT 1 FROM slack_render_v2_state WHERE id = 1)
|
|
30
|
+
AND NOT EXISTS (
|
|
31
|
+
SELECT 1 FROM agent_tasks task, slack_render_v2_state state
|
|
32
|
+
WHERE state.id = 1
|
|
33
|
+
AND task.slackChannelId = tree.channel_id
|
|
34
|
+
AND task.slackThreadTs = tree.thread_ts
|
|
35
|
+
AND task.createdAt >= state.activated_at
|
|
36
|
+
AND (
|
|
37
|
+
(task.source = 'slack'
|
|
38
|
+
AND task.status IN ('completed', 'failed', 'cancelled')
|
|
39
|
+
AND NOT EXISTS (
|
|
40
|
+
SELECT 1 FROM slack_messages outcome
|
|
41
|
+
WHERE outcome.kind = 'outcome'
|
|
42
|
+
AND outcome.task_id = task.id
|
|
43
|
+
AND (outcome.finalized_at IS NOT NULL OR outcome.delivery_abandoned_at IS NOT NULL)
|
|
44
|
+
))
|
|
45
|
+
OR task.status NOT IN ('completed', 'failed', 'cancelled', 'superseded', 'skipped')
|
|
46
|
+
OR task.lastUpdatedAt > tree.updated_at
|
|
47
|
+
)
|
|
48
|
+
)
|
|
49
|
+
AND NOT EXISTS (
|
|
50
|
+
SELECT 1 FROM slack_messages outcome
|
|
51
|
+
JOIN agent_tasks task ON task.id = outcome.task_id,
|
|
52
|
+
slack_render_v2_state state
|
|
53
|
+
WHERE state.id = 1
|
|
54
|
+
AND outcome.kind = 'outcome'
|
|
55
|
+
AND outcome.channel_id = tree.channel_id
|
|
56
|
+
AND outcome.thread_ts = tree.thread_ts
|
|
57
|
+
AND task.createdAt >= state.activated_at
|
|
58
|
+
AND (
|
|
59
|
+
(outcome.finalized_at IS NULL AND outcome.delivery_abandoned_at IS NULL)
|
|
60
|
+
OR outcome.updated_at > tree.updated_at
|
|
61
|
+
)
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
-- Reopen: a task in the thread was created or changed.
|
|
65
|
+
CREATE TRIGGER reopen_slack_tree_after_task_insert
|
|
66
|
+
AFTER INSERT ON agent_tasks
|
|
67
|
+
WHEN NEW.slackChannelId IS NOT NULL AND NEW.slackThreadTs IS NOT NULL
|
|
68
|
+
BEGIN
|
|
69
|
+
UPDATE slack_messages SET closed_at = NULL
|
|
70
|
+
WHERE kind = 'tree'
|
|
71
|
+
AND channel_id = NEW.slackChannelId
|
|
72
|
+
AND thread_ts = NEW.slackThreadTs
|
|
73
|
+
AND closed_at IS NOT NULL;
|
|
74
|
+
END;
|
|
75
|
+
|
|
76
|
+
CREATE TRIGGER reopen_slack_tree_after_task_update
|
|
77
|
+
AFTER UPDATE OF status, lastUpdatedAt, slackChannelId, slackThreadTs ON agent_tasks
|
|
78
|
+
WHEN NEW.slackChannelId IS NOT NULL AND NEW.slackThreadTs IS NOT NULL
|
|
79
|
+
BEGIN
|
|
80
|
+
UPDATE slack_messages SET closed_at = NULL
|
|
81
|
+
WHERE kind = 'tree'
|
|
82
|
+
AND channel_id = NEW.slackChannelId
|
|
83
|
+
AND thread_ts = NEW.slackThreadTs
|
|
84
|
+
AND closed_at IS NOT NULL;
|
|
85
|
+
END;
|
|
86
|
+
|
|
87
|
+
-- Reopen: an outcome card in the thread was created or changed.
|
|
88
|
+
CREATE TRIGGER reopen_slack_tree_after_outcome_insert
|
|
89
|
+
AFTER INSERT ON slack_messages
|
|
90
|
+
WHEN NEW.kind = 'outcome'
|
|
91
|
+
BEGIN
|
|
92
|
+
UPDATE slack_messages SET closed_at = NULL
|
|
93
|
+
WHERE kind = 'tree'
|
|
94
|
+
AND channel_id = NEW.channel_id
|
|
95
|
+
AND thread_ts = NEW.thread_ts
|
|
96
|
+
AND closed_at IS NOT NULL;
|
|
97
|
+
END;
|
|
98
|
+
|
|
99
|
+
CREATE TRIGGER reopen_slack_tree_after_outcome_update
|
|
100
|
+
AFTER UPDATE ON slack_messages
|
|
101
|
+
WHEN NEW.kind = 'outcome'
|
|
102
|
+
BEGIN
|
|
103
|
+
UPDATE slack_messages SET closed_at = NULL
|
|
104
|
+
WHERE kind = 'tree'
|
|
105
|
+
AND channel_id = NEW.channel_id
|
|
106
|
+
AND thread_ts = NEW.thread_ts
|
|
107
|
+
AND closed_at IS NOT NULL;
|
|
108
|
+
END;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
-- Backfill the 30-day TTL on store-progress learnings.
|
|
2
|
+
--
|
|
3
|
+
-- Rows under /learnings/ were written before computeExpiresAt() gave the key a
|
|
4
|
+
-- LEARNING_TTL_DAYS expiry, so they carry expiresAt = NULL and never age out.
|
|
5
|
+
-- Give each one createdAt + 30 days, the expiry a new learning gets at write
|
|
6
|
+
-- time; purgeExpired() then removes it once that date passes. A learning worth
|
|
7
|
+
-- keeping is moved under /longterm first, which clears the expiry.
|
|
8
|
+
--
|
|
9
|
+
-- Data-only. Touches no row outside /learnings/ and no row that already has an
|
|
10
|
+
-- expiry. ISO-8601 with milliseconds, matching Date#toISOString() used by
|
|
11
|
+
-- computeExpiresAt() for new rows.
|
|
12
|
+
UPDATE agent_memory
|
|
13
|
+
SET expiresAt = strftime('%Y-%m-%dT%H:%M:%fZ', createdAt, '+30 days')
|
|
14
|
+
WHERE key GLOB '/learnings/*'
|
|
15
|
+
AND expiresAt IS NULL;
|