@desplega.ai/agent-swarm 2.7.10 → 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-b8aqhrsg.js → actions-7e9czc7s.js} +18 -19
- package/dist/{amp-adapter-4c165vgn.js → amp-adapter-gv6cbb7d.js} +2 -3
- package/dist/{app-m9khefrh.js → app-b9fbkp9v.js} +3 -3
- package/dist/{assistant-rh4v3ntz.js → assistant-wjb7v4c7.js} +20 -21
- package/dist/{boot-args-schema-hwkc8bzv.js → boot-args-schema-2t37e0fe.js} +1 -1
- package/dist/{boot-reembed-5y6yw9sj.js → boot-reembed-a35nkyr1.js} +1 -1
- package/dist/{boot-reembed-fdyk55h4.js → boot-reembed-gka3zas7.js} +1 -1
- package/dist/{boot-scrub-sweep-r5r8kqsn.js → boot-scrub-sweep-65sdnp6c.js} +3 -3
- package/dist/{boot-seeds-8f9zt5cm.js → boot-seeds-x42tzytw.js} +4 -5
- package/dist/{claude-adapter-s5df247c.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-9gsmwzyx.js → claude-managed-setup-9m6450zk.js} +2 -2
- package/dist/{claude-sdk-session-dq1j4nz9.js → claude-sdk-session-0q0ptaba.js} +9066 -8818
- package/dist/{cli-n5yexkdg.js → cli-0b4zam62.js} +1 -0
- package/dist/{cli-5wfz00be.js → cli-0jzra9ad.js} +2 -2
- package/dist/{cli-eqtfgfr6.js → cli-2gxeg5gr.js} +1 -1
- package/dist/{cli-eqk5p56g.js → cli-2wnq8jkz.js} +9 -9
- package/dist/{cli-hfkwwy1h.js → cli-2zp0et3v.js} +21 -2
- package/dist/{cli-rt0ag4x1.js → cli-334z18y3.js} +4 -4
- package/dist/{cli-6m6b4bep.js → cli-3rkdne1h.js} +2 -2
- package/dist/{cli-3xddv0rk.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-n07eecjs.js → cli-6t09sdhy.js} +3 -3
- package/dist/{cli-38yww4e9.js → cli-6wxjceza.js} +8 -8
- package/dist/{cli-5xcb8gxq.js → cli-7b8sbmag.js} +8 -8
- package/dist/{cli-3xj33nrx.js → cli-7cp6aa1q.js} +10 -3
- package/dist/{cli-mp9aa8g5.js → cli-7p1kvkck.js} +6 -6
- package/dist/{cli-w3bk0dgv.js → cli-8aes17e4.js} +2 -2
- package/dist/{cli-n9abj89w.js → cli-8fknbnhw.js} +8 -8
- package/dist/{cli-xd5ebp64.js → cli-8kzasymh.js} +3 -3
- package/dist/{cli-2tsfpc70.js → cli-a7wvp2km.js} +1 -1
- package/dist/{cli-kx4c8j05.js → cli-abejgen1.js} +63 -19
- package/dist/{cli-36wdfzgn.js → cli-bsywb58a.js} +8 -8
- package/dist/{cli-yz7v0sh4.js → cli-c55z5chy.js} +4 -6
- package/dist/{cli-18qt3few.js → cli-deefvewm.js} +1 -1
- package/dist/{cli-jg24scat.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-rjyghzg4.js → cli-g70vxtjh.js} +2 -2
- package/dist/{cli-g1px1g2e.js → cli-gxkx0zzp.js} +1 -1
- package/dist/{cli-j7d73g1y.js → cli-h38x262p.js} +3035 -354
- package/dist/{cli-zjphdj1a.js → cli-j790gp2w.js} +40 -18
- package/dist/{cli-f2zenhja.js → cli-kc7v1nfv.js} +1 -1
- package/dist/{cli-td33w98c.js → cli-m23zjcy2.js} +10 -10
- package/dist/{cli-8ewkreqd.js → cli-m28atx8q.js} +7 -9
- package/dist/{cli-x9exydey.js → cli-m4dqmnbp.js} +1 -1
- package/dist/{cli-ybjdc978.js → cli-mrt48bx7.js} +7 -4
- package/dist/{cli-mr97t7cc.js → cli-p1bq50aa.js} +263 -14
- package/dist/{cli-ttbqe3q4.js → cli-p1w18yhx.js} +1 -1
- package/dist/{cli-nj3x45rw.js → cli-p2gfst4m.js} +52 -43
- package/dist/{cli-z9cs5m0w.js → cli-pasjcnmj.js} +12 -12
- package/dist/{cli-an1knn2k.js → cli-qa4wdgsy.js} +5 -5
- package/dist/{cli-xncjscpm.js → cli-qfedvmcr.js} +50 -24
- package/dist/{cli-tmft5dz2.js → cli-qmqk2yc2.js} +1 -1
- package/dist/{cli-bxz823sz.js → cli-qsnnd04k.js} +1 -1
- package/dist/{cli-cr14kftt.js → cli-qwca7s44.js} +3 -3
- package/dist/{cli-7wz05bx3.js → cli-rfywm85n.js} +460 -737
- package/dist/{cli-v2fwbnsk.js → cli-rmmpt0wm.js} +6 -6
- package/dist/{cli-xbtq4d6s.js → cli-rzsy6nc6.js} +12 -8
- package/dist/{cli-0m7rtm11.js → cli-s7t6p9my.js} +1 -1
- package/dist/{cli-16phend6.js → cli-sdtt3men.js} +1 -1
- package/dist/{cli-pyrxt9gw.js → cli-tk7cjj8h.js} +1 -1
- package/dist/{cli-xvymtmv4.js → cli-tqegb8eq.js} +3 -3
- package/dist/{cli-kf3pxxdg.js → cli-v1dv1r37.js} +1 -1
- package/dist/{cli-h49ejvmc.js → cli-wcg8x116.js} +1 -1
- package/dist/{cli-q581b386.js → cli-wk18cm92.js} +5 -5
- package/dist/{cli-4vwxp550.js → cli-x1wa213s.js} +1 -1
- package/dist/{cli-jrp1dt73.js → cli-xzm9vcfg.js} +1 -1
- package/dist/{cli-eb2azq8n.js → cli-y97qxcfx.js} +9 -9
- package/dist/{cli-55bkx8hh.js → cli-yq3zak69.js} +1 -1
- package/dist/cli.js +17 -17
- package/dist/{codex-adapter-yr60sme6.js → codex-adapter-30j9bpzd.js} +5 -6
- package/dist/{codex-hook-fac6175r.js → codex-hook-h3vk6xzr.js} +1 -1
- package/dist/{codex-session-runner-pch8x584.js → codex-session-runner-8vp57v8w.js} +5 -6
- package/dist/{commands-phjfbkv0.js → commands-bngnz9g7.js} +3 -3
- package/dist/{controller-jkx994pz.js → controller-hxx8wwy1.js} +2 -2
- package/dist/{controllers-connect-c4448kwa.js → controllers-connect-e2b4gyxc.js} +19 -20
- package/dist/{cursor-adapter-ndebqnm8.js → cursor-adapter-n5nc3mfe.js} +1 -2
- package/dist/{db-ez6egt6v.js → db-bgm7vkc0.js} +3 -3
- package/dist/{db-ef32tbfc.js → db-c6np41ca.js} +10 -2
- package/dist/{devin-adapter-z46ep5ph.js → devin-adapter-xedz98zv.js} +1 -1
- package/dist/{dispatcher-g3tt9hs9.js → dispatcher-jnybck15.js} +17 -18
- package/dist/{dsh-adapter-tcyn3099.js → dsh-adapter-nrhbrjz8.js} +1 -2
- package/dist/{easter-egg-3d-e36hk5td.js → easter-egg-3d-533knw22.js} +1 -1
- package/dist/{embedding-space-4kyh5qqj.js → embedding-space-crsm2zp0.js} +6 -6
- package/dist/{embeddings-6a8v4a6t.js → embeddings-e7z3f27f.js} +1 -1
- package/dist/{execute-3cbg0twf.js → execute-b3mrb1mv.js} +1 -1
- package/dist/{external-channel-se646snz.js → external-channel-m77wf5z3.js} +2 -2
- package/dist/{fx-adapter-yw795hqq.js → fx-adapter-b6w0kf56.js} +7 -8
- package/dist/{grok-adapter-ttmcss2j.js → grok-adapter-4sqtebdk.js} +7 -8
- package/dist/handlers-kdjcyzdj.js +32 -0
- package/dist/heartbeat-xgb036sx.js +43 -0
- package/dist/{hook-g3nhexsy.js → hook-5h02c9ga.js} +6 -6
- package/dist/{hook-hq93y5ej.js → hook-xsk1jbha.js} +5 -5
- package/dist/{http-5a9p4h6y.js → http-txe7qhvn.js} +282 -140
- package/dist/{index-6haqt3v5.js → index-4a0670yh.js} +8917 -8476
- package/dist/index-835xdgnm.js +33 -0
- package/dist/index-d469300x.js +37 -0
- package/dist/index-rzqwp11g.js +32 -0
- package/dist/{index-s72rqgsx.js → index-tvfafeyy.js} +1 -1
- package/dist/{index-hgn3c961.js → index-vk63emp7.js} +978 -35
- package/dist/{index-3c5pxbge.js → index-ysvbhg5m.js} +1 -1
- package/dist/{keepalive-1j4n4dmk.js → keepalive-4zsrce78.js} +3 -3
- package/dist/lead-yqt47dkr.js +70 -0
- package/dist/{maintenance-dmghacy5.js → maintenance-86jvartk.js} +1 -1
- package/dist/{oauth-refresh-sweep-yy06c03c.js → oauth-refresh-sweep-j52kg9pr.js} +2 -2
- package/dist/{onboard-52f9t5dm.js → onboard-c2aj5p8q.js} +3 -3
- package/dist/{opencode-adapter-krnh9jkn.js → opencode-adapter-dsagkhtw.js} +5 -6
- package/dist/{otel-impl-xjqz6wjj.js → otel-impl-yyy203z8.js} +1 -1
- package/dist/{pi-mono-adapter-dbxyp0qv.js → pi-mono-adapter-546cd1cc.js} +9 -9
- package/dist/{pricing-refresh-ctdr74pd.js → pricing-refresh-1rgzqyzz.js} +2 -3
- package/dist/{rbac-roles-q0gr8eyj.js → rbac-roles-e70xfeyj.js} +4 -6
- package/dist/{rbac-roles-ehv8s10n.js → rbac-roles-q89qe8er.js} +3 -3
- package/dist/{registry-hpjfmcfz.js → registry-32b1mft6.js} +1 -1
- package/dist/{render-v2-5b6chvcq.js → render-v2-k6tt107q.js} +3 -3
- package/dist/{resume-5a5d2845.js → resume-cnnrjfxa.js} +6 -6
- package/dist/{runtime-khxszyfp.js → runtime-1hv06jsn.js} +1 -1
- package/dist/{session-access-gj0bjhqg.js → session-access-xkxkjw3n.js} +4 -4
- package/dist/{session-source-backfill-2sy0krfk.js → session-source-backfill-1d5pdwww.js} +2 -2
- package/dist/{setup-7ssfakk1.js → setup-se8q7gkc.js} +1 -1
- package/dist/{virtual-modules-pjj0knwf.js → virtual-modules-gazyapte.js} +3 -3
- package/dist/{work-objects-bf3syvhq.js → work-objects-1kxnbzy5.js} +20 -21
- package/dist/{worker-follow-up-38xevga6.js → worker-follow-up-zqm8apt4.js} +17 -18
- package/dist/worker-j6xxtq7p.js +70 -0
- package/openapi.json +334 -7
- package/package.json +4 -4
- package/src/apps/definition.ts +11 -0
- package/src/apps/store.ts +28 -8
- package/src/be/db/model-profiles.ts +147 -38
- package/src/be/db/tasks/read.ts +5 -1
- package/src/be/db/workflow-run-definitions.ts +117 -0
- package/src/be/db.ts +24 -3
- 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 +160 -10
- package/src/be/memory/task-learning.ts +79 -14
- package/src/be/memory/types.ts +24 -1
- 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/commands/onboard/agent-fs-version.ts +1 -1
- package/src/commands/runner.ts +32 -1
- package/src/fs/provider.ts +17 -3
- package/src/heartbeat/heartbeat.ts +12 -1
- 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/index.ts +2 -3
- 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/tasks.ts +37 -12
- package/src/http/workflows.ts +15 -2
- 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/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 +93 -0
- package/src/slack/inbound-dispatch.ts +18 -1
- 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/chained-task-follow-up.test.ts +248 -0
- 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-task-read-contract.test.ts +5 -0
- package/src/tests/db-task-write-contract.test.ts +5 -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/explicit-model-validation.test.ts +2 -0
- package/src/tests/fs-provider.test.ts +42 -0
- package/src/tests/heartbeat.test.ts +28 -1
- package/src/tests/human-free-reclassify.test.ts +5 -1
- package/src/tests/list-endpoint-slimming.test.ts +17 -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/schedule-profile.test.ts +359 -0
- package/src/tests/script-connections.test.ts +6 -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/slack-inbound-receipts.test.ts +22 -2
- package/src/tests/slack-socket-ack.test.ts +16 -1
- 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/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 +61 -4
- 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/skills/apps/SKILL.md +2 -0
- package/templates/skills/apps/content.md +2 -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-srfhs1s9.js +0 -16
- package/dist/cli-bzvs88tv.js +0 -339
- package/dist/cli-cyn9v8zr.js +0 -748
- package/dist/cli-ed6yqpf1.js +0 -779
- package/dist/handlers-17wha3ze.js +0 -33
- package/dist/heartbeat-gwewgdms.js +0 -42
- package/dist/index-8arwq8mw.js +0 -34
- package/dist/index-tpw054az.js +0 -38
- package/dist/index-waq75j2j.js +0 -31
- package/dist/lead-re73kdgc.js +0 -72
- package/dist/worker-r8mz7a65.js +0 -72
|
@@ -15,6 +15,9 @@ import type { AgentMemorySource } from "@/types";
|
|
|
15
15
|
|
|
16
16
|
export const LONGTERM_ROOT = "/longterm";
|
|
17
17
|
|
|
18
|
+
/** Where store-progress learnings live. They expire after LEARNING_TTL_DAYS (see `computeExpiresAt`). */
|
|
19
|
+
export const LEARNINGS_ROOT = "/learnings";
|
|
20
|
+
|
|
18
21
|
/** Shape of a key written through `memory-store` or `memory-edit` `newKey`. */
|
|
19
22
|
export const MEMORY_KEY_PATTERN = /^\/[a-z0-9-]+(\/[a-z0-9._-]+)*$/;
|
|
20
23
|
|
|
@@ -53,6 +56,11 @@ export function isLongtermKey(key: string | null | undefined): boolean {
|
|
|
53
56
|
return !!key && isKeyUnderRoot(key, LONGTERM_ROOT);
|
|
54
57
|
}
|
|
55
58
|
|
|
59
|
+
/** True when `key` sits beneath `/learnings`: a store-progress learning. */
|
|
60
|
+
export function isLearningKey(key: string | null | undefined): boolean {
|
|
61
|
+
return !!key && key.startsWith(`${LEARNINGS_ROOT}/`);
|
|
62
|
+
}
|
|
63
|
+
|
|
56
64
|
/**
|
|
57
65
|
* Why a `/longterm` key is refused, or null when it is allowed (or sits outside
|
|
58
66
|
* `/longterm`, where keys stay free-form). Only the first segments are checked;
|
|
@@ -6,12 +6,14 @@ import { scrubSecrets } from "@/utils/secret-scrubber";
|
|
|
6
6
|
import { currentLoopPath, withLoopPath } from "../../event-loop-lag";
|
|
7
7
|
import {
|
|
8
8
|
EMBEDDING_DIMENSIONS,
|
|
9
|
+
EXHAUSTIVE_SEARCH_MAX_ROWS,
|
|
9
10
|
isHybridSearchEnabled,
|
|
11
|
+
LEARNING_TTL_DAYS,
|
|
10
12
|
minSimilarity,
|
|
11
13
|
PROTECTED_SOURCES,
|
|
12
14
|
TTL_DEFAULTS,
|
|
13
15
|
} from "../constants";
|
|
14
|
-
import { isLongtermKey, LONGTERM_ROOT, tierSource } from "../key-paths";
|
|
16
|
+
import { isLearningKey, isLongtermKey, LONGTERM_ROOT, tierSource } from "../key-paths";
|
|
15
17
|
import { recencyDecay } from "../reranker";
|
|
16
18
|
import { MAX_CANDIDATE_FETCH } from "../search-candidates";
|
|
17
19
|
import type {
|
|
@@ -194,7 +196,7 @@ export function applyEditMode(
|
|
|
194
196
|
}
|
|
195
197
|
|
|
196
198
|
function computeExpiresAt(source: AgentMemorySource, key: string | null): string | null {
|
|
197
|
-
const ttlDays = TTL_DEFAULTS[tierSource(source, key)];
|
|
199
|
+
const ttlDays = isLearningKey(key) ? LEARNING_TTL_DAYS : TTL_DEFAULTS[tierSource(source, key)];
|
|
198
200
|
if (ttlDays == null) return null;
|
|
199
201
|
return new Date(Date.now() + ttlDays * 86400000).toISOString();
|
|
200
202
|
}
|
|
@@ -635,6 +637,18 @@ export class SqliteMemoryStore implements MemoryStore {
|
|
|
635
637
|
keyPrefix,
|
|
636
638
|
} = options;
|
|
637
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
|
+
|
|
638
652
|
const health = this.getHealth();
|
|
639
653
|
if (
|
|
640
654
|
isHybridSearchEnabled() &&
|
|
@@ -668,6 +682,7 @@ export class SqliteMemoryStore implements MemoryStore {
|
|
|
668
682
|
isLead,
|
|
669
683
|
includeExpired,
|
|
670
684
|
keyPrefix,
|
|
685
|
+
minSimilarity: options.minSimilarity,
|
|
671
686
|
});
|
|
672
687
|
}
|
|
673
688
|
|
|
@@ -695,6 +710,7 @@ export class SqliteMemoryStore implements MemoryStore {
|
|
|
695
710
|
isLead,
|
|
696
711
|
includeExpired,
|
|
697
712
|
keyPrefix,
|
|
713
|
+
minSimilarity: options.minSimilarity,
|
|
698
714
|
});
|
|
699
715
|
}
|
|
700
716
|
|
|
@@ -867,9 +883,11 @@ export class SqliteMemoryStore implements MemoryStore {
|
|
|
867
883
|
isLead: boolean;
|
|
868
884
|
includeExpired: boolean;
|
|
869
885
|
keyPrefix?: string;
|
|
886
|
+
minSimilarity?: number;
|
|
870
887
|
},
|
|
871
888
|
): Promise<MemoryCandidate[]> {
|
|
872
889
|
const { scope, limit, source, isLead, includeExpired, keyPrefix } = options;
|
|
890
|
+
const floor = options.minSimilarity ?? minSimilarity();
|
|
873
891
|
|
|
874
892
|
const embeddingBuffer = serializeEmbedding(queryEmbedding);
|
|
875
893
|
// sqlite-vec hard ceiling is 4096 for knn queries
|
|
@@ -906,13 +924,135 @@ export class SqliteMemoryStore implements MemoryStore {
|
|
|
906
924
|
const candidates: MemoryCandidate[] = [];
|
|
907
925
|
for (const row of rows) {
|
|
908
926
|
const similarity = 1 - row.distance;
|
|
909
|
-
if (similarity <
|
|
927
|
+
if (similarity < floor) continue;
|
|
910
928
|
candidates.push({ ...rowToCandidate(row, similarity), retrievalSource: "vec" });
|
|
911
929
|
}
|
|
912
930
|
|
|
913
931
|
return candidates;
|
|
914
932
|
}
|
|
915
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
|
+
|
|
916
1056
|
private async searchBruteForce(
|
|
917
1057
|
queryEmbedding: Float32Array,
|
|
918
1058
|
agentId: string,
|
|
@@ -923,9 +1063,11 @@ export class SqliteMemoryStore implements MemoryStore {
|
|
|
923
1063
|
isLead: boolean;
|
|
924
1064
|
includeExpired: boolean;
|
|
925
1065
|
keyPrefix?: string;
|
|
1066
|
+
minSimilarity?: number;
|
|
926
1067
|
},
|
|
927
1068
|
): Promise<MemoryCandidate[]> {
|
|
928
1069
|
const { scope, limit, source, isLead, includeExpired, keyPrefix } = options;
|
|
1070
|
+
const floor = options.minSimilarity ?? minSimilarity();
|
|
929
1071
|
|
|
930
1072
|
const conditions: string[] = ["embedding IS NOT NULL"];
|
|
931
1073
|
const params: (string | null)[] = [];
|
|
@@ -955,7 +1097,7 @@ export class SqliteMemoryStore implements MemoryStore {
|
|
|
955
1097
|
const emb = deserializeEmbedding(row.embedding);
|
|
956
1098
|
if (emb.length !== queryEmbedding.length) continue;
|
|
957
1099
|
const similarity = cosineSimilarity(queryEmbedding, emb);
|
|
958
|
-
if (similarity <
|
|
1100
|
+
if (similarity < floor) continue;
|
|
959
1101
|
candidates.push({ ...rowToCandidate(row, similarity), retrievalSource: "fallback" });
|
|
960
1102
|
}
|
|
961
1103
|
|
|
@@ -1161,9 +1303,16 @@ export class SqliteMemoryStore implements MemoryStore {
|
|
|
1161
1303
|
if (taken) throw new Error(`key "${input.newKey}" is already used in this scope`);
|
|
1162
1304
|
}
|
|
1163
1305
|
|
|
1164
|
-
//
|
|
1165
|
-
//
|
|
1166
|
-
|
|
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;
|
|
1167
1316
|
const now = new Date().toISOString();
|
|
1168
1317
|
const versionIntent = moving
|
|
1169
1318
|
? `${input.intent} [key ${row.key ?? "(none)"} -> ${input.newKey}]`
|
|
@@ -1197,7 +1346,7 @@ export class SqliteMemoryStore implements MemoryStore {
|
|
|
1197
1346
|
await tx.run(
|
|
1198
1347
|
`UPDATE agent_memory
|
|
1199
1348
|
SET content = ?, contentHash = ?, version = ?, updatedAt = ?, key = ?,
|
|
1200
|
-
expiresAt = CASE WHEN ? = 1 THEN
|
|
1349
|
+
expiresAt = CASE WHEN ? = 1 THEN ? ELSE expiresAt END
|
|
1201
1350
|
WHERE id = ?`,
|
|
1202
1351
|
[
|
|
1203
1352
|
targetContent,
|
|
@@ -1205,7 +1354,8 @@ export class SqliteMemoryStore implements MemoryStore {
|
|
|
1205
1354
|
targetVersion,
|
|
1206
1355
|
now,
|
|
1207
1356
|
moving ? input.newKey! : target.key,
|
|
1208
|
-
|
|
1357
|
+
resetExpiry ? 1 : 0,
|
|
1358
|
+
expiresAt,
|
|
1209
1359
|
target.id,
|
|
1210
1360
|
],
|
|
1211
1361
|
);
|
|
@@ -1220,7 +1370,7 @@ export class SqliteMemoryStore implements MemoryStore {
|
|
|
1220
1370
|
version: nextVersion,
|
|
1221
1371
|
updatedAt: now,
|
|
1222
1372
|
key: moving ? input.newKey! : row.key,
|
|
1223
|
-
expiresAt
|
|
1373
|
+
expiresAt,
|
|
1224
1374
|
}),
|
|
1225
1375
|
changed: true,
|
|
1226
1376
|
previousVersion,
|
|
@@ -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,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;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
-- Model profiles, PR 2 (runbooks/model-tiers.md § Model profiles).
|
|
2
|
+
PRAGMA defer_foreign_keys = ON;
|
|
3
|
+
|
|
4
|
+
-- JSON {VAR: [suffix, ...]}: the last 5 characters of each pooled key the
|
|
5
|
+
-- profile may use, per credential var. NULL means the whole pool.
|
|
6
|
+
ALTER TABLE model_profiles ADD COLUMN credentialAllowlist TEXT;
|
|
7
|
+
|
|
8
|
+
-- A schedule's profile is copied onto every task it fires.
|
|
9
|
+
ALTER TABLE scheduled_tasks ADD COLUMN profile TEXT;
|
|
10
|
+
|
|
11
|
+
-- Same reference rule as migration 220's agent_tasks triggers: a schedule may
|
|
12
|
+
-- only name a profile that exists. The delete side is the matching guard in
|
|
13
|
+
-- deleteModelProfile (src/be/db/model-profiles.ts).
|
|
14
|
+
CREATE TRIGGER IF NOT EXISTS model_profiles_schedule_ref_insert
|
|
15
|
+
BEFORE INSERT ON scheduled_tasks
|
|
16
|
+
WHEN NEW.profile IS NOT NULL
|
|
17
|
+
AND NOT EXISTS (SELECT 1 FROM model_profiles WHERE name = NEW.profile)
|
|
18
|
+
BEGIN
|
|
19
|
+
SELECT RAISE(ABORT, 'model-profile-missing: the schedule''s model profile does not exist');
|
|
20
|
+
END;
|
|
21
|
+
|
|
22
|
+
CREATE TRIGGER IF NOT EXISTS model_profiles_schedule_ref_update
|
|
23
|
+
BEFORE UPDATE OF profile ON scheduled_tasks
|
|
24
|
+
WHEN NEW.profile IS NOT NULL
|
|
25
|
+
AND NOT EXISTS (SELECT 1 FROM model_profiles WHERE name = NEW.profile)
|
|
26
|
+
BEGIN
|
|
27
|
+
SELECT RAISE(ABORT, 'model-profile-missing: the schedule''s model profile does not exist');
|
|
28
|
+
END;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
-- Pin each workflow run to the definition it started with (#2720).
|
|
2
|
+
-- One immutable row per distinct definition content, keyed by its sha256.
|
|
3
|
+
-- Runs created before this migration keep a NULL definitionHash and read the
|
|
4
|
+
-- live workflows row, as before.
|
|
5
|
+
CREATE TABLE IF NOT EXISTS workflow_run_definitions (
|
|
6
|
+
hash TEXT PRIMARY KEY,
|
|
7
|
+
snapshot TEXT NOT NULL,
|
|
8
|
+
createdAt TEXT NOT NULL
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
ALTER TABLE workflow_runs ADD COLUMN definitionHash TEXT REFERENCES workflow_run_definitions(hash);
|
|
12
|
+
|
|
13
|
+
CREATE INDEX IF NOT EXISTS idx_workflow_runs_definitionHash
|
|
14
|
+
ON workflow_runs(definitionHash) WHERE definitionHash IS NOT NULL;
|