@cortexkit/opencode-magic-context 0.47.0 → 0.48.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/agents/magic-context-prompt.d.ts +1 -1
- package/dist/agents/magic-context-prompt.d.ts.map +1 -1
- package/dist/{announcement-y35wzg2r.js → announcement-fp14dw0n.js} +3 -2
- package/dist/auto-search-worker.js +27 -30
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/mural-model-deprecation.d.ts +15 -0
- package/dist/config/mural-model-deprecation.d.ts.map +1 -0
- package/dist/config/project-security.d.ts +0 -3
- package/dist/config/project-security.d.ts.map +1 -1
- package/dist/config/schema/magic-context.d.ts +10 -6
- package/dist/config/schema/magic-context.d.ts.map +1 -1
- package/dist/{conflict-warning-hook-z44ynfz7.js → conflict-warning-hook-w8cykrnf.js} +12 -10
- package/dist/{context-wq4ffwyb.js → context-m0cy262m.js} +2690 -1903
- package/dist/{derive-budgets-ke12jnnh.js → derive-budgets-sg0xsq7s.js} +4 -3
- package/dist/embedding-activity-g1dhes6g.js +10 -0
- package/dist/embedding-backfill-9rcm1mfy.js +21 -0
- package/dist/embedding-cache-mgyr73ef.js +16 -0
- package/dist/embedding-worker.js +11 -9
- package/dist/features/magic-context/compaction-marker.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/evaluate-smart-notes.d.ts +1 -0
- package/dist/features/magic-context/dreamer/evaluate-smart-notes.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-config.d.ts +3 -3
- package/dist/features/magic-context/dreamer/task-config.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-executor.d.ts +1 -1
- package/dist/features/magic-context/dreamer/task-executor.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-registry.d.ts +1 -0
- package/dist/features/magic-context/dreamer/task-registry.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/verify.d.ts.map +1 -1
- package/dist/features/magic-context/message-index-async.d.ts +16 -3
- package/dist/features/magic-context/message-index-async.d.ts.map +1 -1
- package/dist/features/magic-context/message-index-bounded.d.ts +17 -0
- package/dist/features/magic-context/message-index-bounded.d.ts.map +1 -0
- package/dist/features/magic-context/message-index.d.ts +7 -1
- package/dist/features/magic-context/message-index.d.ts.map +1 -1
- package/dist/features/magic-context/mural/render-trigger.d.ts +7 -4
- package/dist/features/magic-context/mural/render-trigger.d.ts.map +1 -1
- package/dist/features/magic-context/pi-content-decisions.d.ts +7 -1
- package/dist/features/magic-context/pi-content-decisions.d.ts.map +1 -1
- package/dist/features/magic-context/search.d.ts +29 -0
- package/dist/features/magic-context/search.d.ts.map +1 -1
- package/dist/features/magic-context/session-activity.d.ts.map +1 -1
- package/dist/features/magic-context/smart-notes/runner.d.ts +1 -0
- package/dist/features/magic-context/smart-notes/runner.d.ts.map +1 -1
- package/dist/features/magic-context/storage-db.d.ts.map +1 -1
- package/dist/features/magic-context/storage-meta-session.d.ts +6 -0
- package/dist/features/magic-context/storage-meta-session.d.ts.map +1 -1
- package/dist/features/magic-context/storage-tag-identity-revision.d.ts +30 -0
- package/dist/features/magic-context/storage-tag-identity-revision.d.ts.map +1 -0
- package/dist/features/magic-context/storage-tags.d.ts +144 -4
- package/dist/features/magic-context/storage-tags.d.ts.map +1 -1
- package/dist/features/magic-context/subagent-token-capture.d.ts.map +1 -1
- package/dist/features/magic-context/transform-decision-log.d.ts +1 -1
- package/dist/features/magic-context/transform-decision-log.d.ts.map +1 -1
- package/dist/harness-e4avh192.js +10 -0
- package/dist/hooks/magic-context/active-anthropic-turn.d.ts +2 -0
- package/dist/hooks/magic-context/active-anthropic-turn.d.ts.map +1 -1
- package/dist/hooks/magic-context/auto-search-worker-client.d.ts +32 -3
- package/dist/hooks/magic-context/auto-search-worker-client.d.ts.map +1 -1
- package/dist/hooks/magic-context/command-handler.d.ts +1 -0
- package/dist/hooks/magic-context/command-handler.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-incremental.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-recomp.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-trigger.d.ts.map +1 -1
- package/dist/hooks/magic-context/event-handler.d.ts.map +1 -1
- package/dist/hooks/magic-context/hook.d.ts +1 -1
- package/dist/hooks/magic-context/hook.d.ts.map +1 -1
- package/dist/hooks/magic-context/inject-compartments.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-persist.d.ts +4 -3
- package/dist/hooks/magic-context/lkg-persist.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-replay.d.ts +13 -8
- package/dist/hooks/magic-context/lkg-replay.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-slot.d.ts +139 -2
- package/dist/hooks/magic-context/lkg-slot.d.ts.map +1 -1
- package/dist/hooks/magic-context/message-search-accepting-silent-worker.fixture.d.ts +2 -0
- package/dist/hooks/magic-context/message-search-accepting-silent-worker.fixture.d.ts.map +1 -0
- package/dist/hooks/magic-context/oc-stall-r2-warmup-worker.fixture.d.ts +2 -0
- package/dist/hooks/magic-context/oc-stall-r2-warmup-worker.fixture.d.ts.map +1 -0
- package/dist/hooks/magic-context/oc-stall-search-review.fixture.d.ts +2 -0
- package/dist/hooks/magic-context/oc-stall-search-review.fixture.d.ts.map +1 -0
- package/dist/hooks/magic-context/opencode1-to-model-messages.fixture.d.ts +63 -0
- package/dist/hooks/magic-context/opencode1-to-model-messages.fixture.d.ts.map +1 -0
- package/dist/hooks/magic-context/provider-visible-parts.d.ts +45 -0
- package/dist/hooks/magic-context/provider-visible-parts.d.ts.map +1 -0
- package/dist/hooks/magic-context/raw-ordinal-warmup-silent-worker.fixture.d.ts +2 -0
- package/dist/hooks/magic-context/raw-ordinal-warmup-silent-worker.fixture.d.ts.map +1 -0
- package/dist/hooks/magic-context/raw-ordinal-warmup-worker.d.ts +2 -0
- package/dist/hooks/magic-context/raw-ordinal-warmup-worker.d.ts.map +1 -0
- package/dist/hooks/magic-context/raw-ordinal-warmup.d.ts +87 -0
- package/dist/hooks/magic-context/raw-ordinal-warmup.d.ts.map +1 -0
- package/dist/hooks/magic-context/read-session-chunk.d.ts +12 -0
- package/dist/hooks/magic-context/read-session-chunk.d.ts.map +1 -1
- package/dist/hooks/magic-context/read-session-db.d.ts.map +1 -1
- package/dist/hooks/magic-context/read-session-formatting.d.ts +5 -0
- package/dist/hooks/magic-context/read-session-formatting.d.ts.map +1 -1
- package/dist/hooks/magic-context/read-session-raw.d.ts +83 -1
- package/dist/hooks/magic-context/read-session-raw.d.ts.map +1 -1
- package/dist/hooks/magic-context/read-session-true-raw-tokens.d.ts.map +1 -1
- package/dist/hooks/magic-context/reasoning-budget.d.ts.map +1 -1
- package/dist/hooks/magic-context/sentinel.d.ts +41 -1
- package/dist/hooks/magic-context/sentinel.d.ts.map +1 -1
- package/dist/hooks/magic-context/strip-content.d.ts +14 -2
- package/dist/hooks/magic-context/strip-content.d.ts.map +1 -1
- package/dist/hooks/magic-context/system-prompt-hash.d.ts +1 -0
- package/dist/hooks/magic-context/system-prompt-hash.d.ts.map +1 -1
- package/dist/hooks/magic-context/tag-messages.d.ts +8 -0
- package/dist/hooks/magic-context/tag-messages.d.ts.map +1 -1
- package/dist/hooks/magic-context/tag-owner-warmup.d.ts +6 -0
- package/dist/hooks/magic-context/tag-owner-warmup.d.ts.map +1 -0
- package/dist/hooks/magic-context/tail-hygiene-walk.d.ts.map +1 -1
- package/dist/hooks/magic-context/token-count-exact.d.ts +35 -0
- package/dist/hooks/magic-context/token-count-exact.d.ts.map +1 -0
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform.d.ts +8 -2
- package/dist/hooks/magic-context/transform.d.ts.map +1 -1
- package/dist/hooks/magic-context/wrapup-orchestrator.d.ts.map +1 -1
- package/dist/{index-w2t4ah5j.js → index-0an7742d.js} +14072 -14286
- package/dist/index-0qhce371.js +120 -0
- package/dist/{index-q6hef7fh.js → index-0sahzkwr.js} +6 -19
- package/dist/{index-k5bdx1bx.js → index-0w56v4fm.js} +3 -5
- package/dist/index-14cjxt20.js +819 -0
- package/dist/{v2/server-51dv1pr5.js → index-1qb0z7wa.js} +301 -27
- package/dist/index-2bvekkfy.js +11 -0
- package/dist/{index-sj29b3z2.js → index-2y0s2hep.js} +3 -3
- package/dist/index-4dhv7mqz.js +131 -0
- package/dist/{index-b35pxds2.js → index-58e3y90n.js} +1 -18
- package/dist/index-5zygecde.js +152 -0
- package/dist/{index-6d9e1m08.js → index-692jzy0p.js} +17775 -17450
- package/dist/index-72nhv486.js +2307 -0
- package/dist/index-7jzrrxap.js +931 -0
- package/dist/{v2/server-njt3np1k.js → index-7mx8v0pw.js} +220 -961
- package/dist/index-8ajstryz.js +18 -0
- package/dist/{index-sfpzqvdz.js → index-8cd2j99z.js} +2 -3
- package/dist/{index-hybnrwq0.js → index-8j7gqj40.js} +131 -128
- package/dist/index-bdckkfw6.js +3261 -0
- package/dist/{index-m5fe6jch.js → index-bhvjj0ys.js} +152 -2453
- package/dist/index-c43kr12f.js +3030 -0
- package/dist/index-cb7emxgj.js +984 -0
- package/dist/index-d9vfe7xq.js +16 -0
- package/dist/{index-5gq3b2ya.js → index-db7zwa3v.js} +147 -209
- package/dist/index-dhwzyd54.js +1142 -0
- package/dist/{index-8da2zjhz.js → index-eeezr5zz.js} +9 -7
- package/dist/{index-cwf6s3ay.js → index-f0h6xwqm.js} +2828 -2618
- package/dist/index-fb3zxn06.js +13 -0
- package/dist/index-fbv1dn35.js +171 -0
- package/dist/index-fr0wbhdn.js +43 -0
- package/dist/{index-mc22ayvf.js → index-ghc9f0n7.js} +11 -9
- package/dist/{index-fzbvakh0.js → index-jcbd3znx.js} +3 -3
- package/dist/{index-5a2r0p9f.js → index-k1xb52kd.js} +20 -13
- package/dist/index-k9nnwad5.js +3532 -0
- package/dist/{index-wx8a6bw3.js → index-kb9nn0a0.js} +270 -53
- package/dist/index-knh4y330.js +566 -0
- package/dist/{v2/server-fq7kq32k.js → index-mfkzp7qj.js} +1 -16
- package/dist/{index-gg8j07zz.js → index-mmyh6d8f.js} +4 -4
- package/dist/index-pavzsdc6.js +17 -0
- package/dist/{index-0c82743p.js → index-pdecwzrd.js} +17 -15
- package/dist/index-pg50n748.js +1060 -0
- package/dist/{index-92bp57hg.js → index-q2tqeqde.js} +123 -80
- package/dist/{index-rrrsepyw.js → index-q7h7csab.js} +90 -85
- package/dist/{v2/server-yr3zj7e7.js → index-qt1qqasc.js} +6 -7
- package/dist/{index-6wkcswft.js → index-ty64eqcn.js} +28 -18
- package/dist/{index-adwfkpex.js → index-yq8n9qcb.js} +23 -23
- package/dist/{index-9pk9exrb.js → index-z8e0psj8.js} +18 -18
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +586 -344
- package/dist/logger-d3wex3dz.js +20 -0
- package/dist/message-index-bounded-7ezbgddp.js +124 -0
- package/dist/{v2/message-time-backfill-1f9tzvcs.js → message-time-backfill-brbd63hv.js} +8 -6
- package/dist/migration-worker.js +25 -18
- package/dist/{model-resolution-xhfmyyvy.js → model-resolution-nx97z3x7.js} +1 -1
- package/dist/plugin/dream-timer.d.ts +1 -1
- package/dist/plugin/dream-timer.d.ts.map +1 -1
- package/dist/plugin/hooks/create-session-hooks.d.ts +1 -0
- package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
- package/dist/plugin/host-stall-profiler-report.d.ts +1 -66
- package/dist/plugin/host-stall-profiler-report.d.ts.map +1 -1
- package/dist/plugin/host-stall-profiler.d.ts +2 -95
- package/dist/plugin/host-stall-profiler.d.ts.map +1 -1
- package/dist/plugin/messages-transform.d.ts +0 -13
- package/dist/plugin/messages-transform.d.ts.map +1 -1
- package/dist/plugin/rpc-handlers.d.ts.map +1 -1
- package/dist/plugin/tool-registry.d.ts.map +1 -1
- package/dist/project-embedding-registry-7qzptcw7.js +88 -0
- package/dist/raw-ordinal-warmup-worker.js +60 -0
- package/dist/{read-session-chunk-4jey7hpt.js → read-session-chunk-6k83m4fj.js} +15 -9
- package/dist/read-session-raw-3g9qy1xa.js +58 -0
- package/dist/recomp-orchestrator-d3fp1cy0.js +57 -0
- package/dist/{v2/safe-notification-target-eb1n1vfb.js → safe-notification-target-5ffqq32m.js} +4 -2
- package/dist/search-epax1ecv.js +45 -0
- package/dist/{v2/send-session-notification-c0wtscea.js → send-session-notification-erecz4y4.js} +10 -7
- package/dist/shared/conflict-detector.d.ts.map +1 -1
- package/dist/shared/host-stall-profiler-bun.d.ts +46 -0
- package/dist/shared/host-stall-profiler-bun.d.ts.map +1 -0
- package/dist/shared/host-stall-profiler-common.d.ts +58 -0
- package/dist/shared/host-stall-profiler-common.d.ts.map +1 -0
- package/dist/shared/host-stall-profiler-node.d.ts +36 -0
- package/dist/shared/host-stall-profiler-node.d.ts.map +1 -0
- package/dist/shared/host-stall-profiler-report.d.ts +68 -0
- package/dist/shared/host-stall-profiler-report.d.ts.map +1 -0
- package/dist/shared/host-stall-profiler.d.ts +5 -0
- package/dist/shared/host-stall-profiler.d.ts.map +1 -0
- package/dist/shared/model-resolution.d.ts +2 -3
- package/dist/shared/model-resolution.d.ts.map +1 -1
- package/dist/shared/sqlite.d.ts +30 -0
- package/dist/shared/sqlite.d.ts.map +1 -1
- package/dist/shared/stable-json.d.ts.map +1 -1
- package/dist/shared/user-facing-codes.d.ts +0 -5
- package/dist/shared/user-facing-codes.d.ts.map +1 -1
- package/dist/sqlite-context-pragmas-mv9jqwjh.js +6 -0
- package/dist/sqlite-mhjkerzq.js +46 -0
- package/dist/storage-memory-07fx57k6.js +71 -0
- package/dist/storage-tags-d3b0v2ss.js +131 -0
- package/dist/{task-config-v81k8jvk.js → task-config-cgpg0nvh.js} +2 -2
- package/dist/tools/ctx-expand/tools.d.ts.map +1 -1
- package/dist/tools/ctx-note/constants.d.ts +4 -0
- package/dist/tools/ctx-note/constants.d.ts.map +1 -1
- package/dist/tools/ctx-note/tools.d.ts +1 -0
- package/dist/tools/ctx-note/tools.d.ts.map +1 -1
- package/dist/tools/ctx-search/tools.d.ts.map +1 -1
- package/dist/tools/parameter-descriptions.d.ts +2 -2
- package/dist/tools/parameter-descriptions.d.ts.map +1 -1
- package/dist/{transform-postprocess-phase-z5hzpsxv.js → transform-postprocess-phase-spcy2qre.js} +35 -20
- package/dist/transformers-node-wasm.js +18415 -18415
- package/dist/v2/auto-search-worker.js +27 -30
- package/dist/v2/{context-14v1hr8b.js → context-sf98kstd.js} +3737 -3004
- package/dist/v2/{derive-budgets-nc9avxz8.js → derive-budgets-3vc0y84t.js} +4 -3
- package/dist/v2/embedding-activity-g1dhes6g.js +10 -0
- package/dist/v2/embedding-backfill-vn8g1nh1.js +21 -0
- package/dist/v2/embedding-cache-mgyr73ef.js +16 -0
- package/dist/v2/embedding-worker.js +12 -9
- package/dist/v2/fold/host-media.d.ts +4 -0
- package/dist/v2/fold/host-media.d.ts.map +1 -1
- package/dist/v2/fold/memory-cache.d.ts +70 -0
- package/dist/v2/fold/memory-cache.d.ts.map +1 -0
- package/dist/v2/fold/native-codec.d.ts +10 -0
- package/dist/v2/fold/native-codec.d.ts.map +1 -0
- package/dist/v2/fold/native-replay.d.ts +58 -0
- package/dist/v2/fold/native-replay.d.ts.map +1 -0
- package/dist/v2/fold/policy.d.ts +24 -0
- package/dist/v2/fold/policy.d.ts.map +1 -0
- package/dist/v2/harness-e4avh192.js +10 -0
- package/dist/v2/hooks/context.d.ts +2 -2
- package/dist/v2/hooks/context.d.ts.map +1 -1
- package/dist/v2/hooks/dream-manual.d.ts +1 -1
- package/dist/v2/hooks/dream-manual.d.ts.map +1 -1
- package/dist/v2/hooks/dream-timer.d.ts.map +1 -1
- package/dist/v2/hooks/dream-trigger.d.ts +1 -2
- package/dist/v2/hooks/dream-trigger.d.ts.map +1 -1
- package/dist/v2/hooks/payload.d.ts.map +1 -1
- package/dist/v2/hooks/tools.d.ts.map +1 -1
- package/dist/v2/hooks/types.d.ts +6 -0
- package/dist/v2/hooks/types.d.ts.map +1 -1
- package/dist/v2/logger-mxd0ym09.js +19 -0
- package/dist/v2/message-index-bounded-dy3s2k1e.js +123 -0
- package/dist/{message-time-backfill-r5epkzj3.js → v2/message-time-backfill-gtx1pwk1.js} +7 -7
- package/dist/v2/migration-worker.js +24 -17
- package/dist/v2/{model-resolution-xhfmyyvy.js → model-resolution-nx97z3x7.js} +1 -1
- package/dist/v2/project-embedding-registry-1tgba5dv.js +86 -0
- package/dist/v2/raw-ordinal-warmup-worker.js +60 -0
- package/dist/v2/{read-session-chunk-gyyv7w2r.js → read-session-chunk-rh4khdkv.js} +14 -8
- package/dist/v2/read-session-raw-bsbmf0vj.js +57 -0
- package/dist/v2/recomp-orchestrator-az61rfcg.js +57 -0
- package/dist/{safe-notification-target-43r8jsxw.js → v2/safe-notification-target-73ax1p5v.js} +3 -3
- package/dist/v2/search-nzkwrc6n.js +45 -0
- package/dist/{send-session-notification-0m68ms3n.js → v2/send-session-notification-6km439kn.js} +9 -8
- package/dist/{index-5eqk6z3s.js → v2/server-1r6pmz4f.js} +301 -27
- package/dist/v2/server-2bvekkfy.js +11 -0
- package/dist/v2/server-2fbhp79z.js +3205 -0
- package/dist/v2/{server-ajzeteqw.js → server-2ra6pwf3.js} +1 -18
- package/dist/v2/server-4dhv7mqz.js +131 -0
- package/dist/v2/{server-y10vbq6y.js → server-4k748ke6.js} +11 -1053
- package/dist/v2/{server-vs5gpnd4.js → server-52awr2mw.js} +81 -145
- package/dist/v2/{server-1qbnzc80.js → server-5m3dt5r1.js} +136 -148
- package/dist/v2/server-686jg6eb.js +3508 -0
- package/dist/v2/server-7jzrrxap.js +931 -0
- package/dist/v2/server-7wwc2nga.js +3023 -0
- package/dist/v2/server-8ajstryz.js +18 -0
- package/dist/v2/{server-sfpzqvdz.js → server-8cd2j99z.js} +2 -3
- package/dist/v2/{server-d0sraw7m.js → server-8pyt7hev.js} +291 -286
- package/dist/v2/server-8tqanswc.js +984 -0
- package/dist/v2/{server-14vq4kpm.js → server-aan4q8mx.js} +3 -3
- package/dist/v2/server-d9vfe7xq.js +16 -0
- package/dist/{index-x3kwrmqk.js → v2/server-e0vdaae2.js} +35 -792
- package/dist/v2/server-ezhze64f.js +1048 -0
- package/dist/v2/server-fb3zxn06.js +13 -0
- package/dist/v2/server-fr0wbhdn.js +43 -0
- package/dist/v2/server-g5r0n3b6.js +1137 -0
- package/dist/v2/server-gjcr4w98.js +154 -0
- package/dist/v2/server-k228xhjg.js +171 -0
- package/dist/v2/{server-nf82q6pt.js → server-k8x2rbxc.js} +5946 -5602
- package/dist/v2/{server-wx8a6bw3.js → server-kb9nn0a0.js} +270 -53
- package/dist/{index-rrbbspwh.js → v2/server-mfkzp7qj.js} +1 -16
- package/dist/v2/server-pavzsdc6.js +17 -0
- package/dist/v2/{server-e0c1b7a7.js → server-psqc7e9n.js} +122 -79
- package/dist/{index-yr3zj7e7.js → v2/server-qt1qqasc.js} +6 -7
- package/dist/v2/server-qye6ykf7.js +120 -0
- package/dist/v2/{server-qdjnb2z1.js → server-r5p3b1wy.js} +11 -9
- package/dist/v2/server-sggvvzhb.js +759 -0
- package/dist/v2/{server-cpepxy2q.js → server-v06jcv0w.js} +14 -12
- package/dist/v2/server-vqpf3167.js +1048 -0
- package/dist/v2/{server-rz514f14.js → server-x2g40a71.js} +2044 -2060
- package/dist/v2/{server-vd4e7174.js → server-xdfwt6kh.js} +20 -16
- package/dist/v2/{server-efhwzx05.js → server-xxm59eww.js} +23 -23
- package/dist/v2/server-yczc713m.js +564 -0
- package/dist/v2/{server-fcdehk1s.js → server-z2037m6z.js} +4 -4
- package/dist/v2/{server-50hvkg3v.js → server-zm570tr2.js} +160 -158
- package/dist/v2/{server-6r257mf5.js → server-zxhgvsf9.js} +3 -3
- package/dist/v2/server.js +16 -14
- package/dist/v2/sqlite-context-pragmas-mv9jqwjh.js +6 -0
- package/dist/v2/sqlite-mhjkerzq.js +46 -0
- package/dist/v2/storage-memory-07fx57k6.js +71 -0
- package/dist/v2/storage-tags-w4tv77sn.js +130 -0
- package/dist/v2/store-reader.d.ts +16 -0
- package/dist/v2/store-reader.d.ts.map +1 -1
- package/dist/v2/{task-config-tbndqyny.js → task-config-x0hq3qfd.js} +2 -2
- package/dist/v2/transformers-node-wasm.js +18415 -18415
- package/dist/v2/tui/index.d.ts.map +1 -1
- package/dist/v2/tui/types.d.ts +1 -10
- package/dist/v2/tui/types.d.ts.map +1 -1
- package/dist/v2/{wrapup-orchestrator-nbz854vc.js → wrapup-orchestrator-mz7efs7w.js} +51 -30
- package/dist/wrapup-orchestrator-amzta1t4.js +44 -0
- package/package.json +4 -3
- package/src/agents/magic-context-prompt.ts +27 -2
- package/src/agents/smart-notes-enabled.test.ts +294 -0
- package/src/agents/smart-notes-on.golden.json +70 -0
- package/src/config/index.test.ts +67 -1
- package/src/config/index.ts +2 -0
- package/src/config/latch-permanence-guard.test.ts +4 -0
- package/src/config/mural-model-deprecation.ts +24 -0
- package/src/config/project-security.hostile-matrix.test.ts +4 -44
- package/src/config/project-security.test.ts +9 -14
- package/src/config/project-security.ts +13 -55
- package/src/config/schema/magic-context.test.ts +2 -2
- package/src/config/schema/magic-context.ts +16 -10
- package/src/features/magic-context/dreamer/task-registry.ts +6 -0
- package/src/shared/conflict-detector.test.ts +56 -0
- package/src/shared/conflict-detector.ts +16 -5
- package/src/shared/host-stall-profiler-bun.ts +358 -0
- package/src/shared/host-stall-profiler-common.ts +159 -0
- package/src/shared/host-stall-profiler-node.test.ts +234 -0
- package/src/shared/host-stall-profiler-node.ts +274 -0
- package/src/shared/host-stall-profiler-report.ts +248 -0
- package/src/shared/host-stall-profiler.ts +57 -0
- package/src/shared/model-resolution.test.ts +54 -17
- package/src/shared/model-resolution.ts +6 -17
- package/src/shared/sqlite.test.ts +52 -0
- package/src/shared/sqlite.ts +339 -23
- package/src/shared/stable-json-linear.test.ts +109 -0
- package/src/shared/stable-json.ts +37 -7
- package/src/shared/user-facing-codes.ts +2 -6
- package/src/shared/write-transaction-attribution.test.ts +2 -2
- package/src/v2/tui/host-contract.test.ts +41 -67
- package/src/v2/tui/index.ts +6 -214
- package/src/v2/tui/types.ts +5 -17
- package/dist/features/magic-context/checkout-claim-fake-subc.test-support.d.ts +0 -45
- package/dist/features/magic-context/checkout-claim-fake-subc.test-support.d.ts.map +0 -1
- package/dist/features/magic-context/checkout-claim.d.ts +0 -155
- package/dist/features/magic-context/checkout-claim.d.ts.map +0 -1
- package/dist/index-bb36vgr3.js +0 -6608
- package/dist/index-fnn5pjtt.js +0 -6554
- package/dist/recomp-orchestrator-rervg6q4.js +0 -42
- package/dist/v2/recomp-orchestrator-42vjba7p.js +0 -42
- package/dist/v2/server-3trjk1hx.js +0 -6360
- package/dist/v2/server-nm9n3aqq.js +0 -6461
- package/dist/wrapup-orchestrator-b2dztrar.js +0 -29
- /package/dist/{index-5prbx026.js → index-2pp04pmg.js} +0 -0
- /package/dist/v2/{index-5prbx026.js → index-2pp04pmg.js} +0 -0
|
@@ -0,0 +1,931 @@
|
|
|
1
|
+
import {
|
|
2
|
+
withPrivilegedWriter2
|
|
3
|
+
} from "./server-kb9nn0a0.js";
|
|
4
|
+
import {
|
|
5
|
+
MEMORY_CATEGORY_ORDER_SQL
|
|
6
|
+
} from "./server-fr0wbhdn.js";
|
|
7
|
+
import {
|
|
8
|
+
invalidateProject2,
|
|
9
|
+
invalidateMemory2
|
|
10
|
+
} from "./server-4dhv7mqz.js";
|
|
11
|
+
import {
|
|
12
|
+
computeNormalizedHash
|
|
13
|
+
} from "./server-2bvekkfy.js";
|
|
14
|
+
|
|
15
|
+
// src/features/magic-context/mural/storage-mural-cues.ts
|
|
16
|
+
import { createHash } from "node:crypto";
|
|
17
|
+
function computeCueContentHash(content) {
|
|
18
|
+
return createHash("sha256").update(content).digest("hex");
|
|
19
|
+
}
|
|
20
|
+
var muralCueColumnCache = new WeakMap;
|
|
21
|
+
var muralCueRejectionColumnCache = new WeakMap;
|
|
22
|
+
function hasMuralCueColumns(db) {
|
|
23
|
+
const cached = muralCueColumnCache.get(db);
|
|
24
|
+
if (cached !== undefined)
|
|
25
|
+
return cached;
|
|
26
|
+
const columns = db.prepare("PRAGMA table_info(memories)").all();
|
|
27
|
+
const present = columns.some((column) => column.name === "mural_cue");
|
|
28
|
+
muralCueColumnCache.set(db, present);
|
|
29
|
+
return present;
|
|
30
|
+
}
|
|
31
|
+
function hasMuralCueRejectionCountColumn(db) {
|
|
32
|
+
const cached = muralCueRejectionColumnCache.get(db);
|
|
33
|
+
if (cached !== undefined)
|
|
34
|
+
return cached;
|
|
35
|
+
const columns = db.prepare("PRAGMA table_info(memories)").all();
|
|
36
|
+
const present = columns.some((column) => column.name === "mural_cue_rejection_count");
|
|
37
|
+
muralCueRejectionColumnCache.set(db, present);
|
|
38
|
+
return present;
|
|
39
|
+
}
|
|
40
|
+
function getMuralCueState(db, memoryIds) {
|
|
41
|
+
const out = new Map;
|
|
42
|
+
if (!hasMuralCueColumns(db))
|
|
43
|
+
return out;
|
|
44
|
+
const ids = Array.from(new Set(memoryIds.filter(Number.isInteger)));
|
|
45
|
+
if (ids.length === 0)
|
|
46
|
+
return out;
|
|
47
|
+
const rejectionCountColumn = hasMuralCueRejectionCountColumn(db) ? "COALESCE(mural_cue_rejection_count, 0) AS mural_cue_rejection_count" : "0 AS mural_cue_rejection_count";
|
|
48
|
+
const rows = db.prepare(`SELECT id, mural_cue, mural_cue_hash, ${rejectionCountColumn} FROM memories WHERE id IN (SELECT value FROM json_each(?))`).all(JSON.stringify(ids));
|
|
49
|
+
for (const row of rows) {
|
|
50
|
+
out.set(row.id, {
|
|
51
|
+
cue: row.mural_cue ?? null,
|
|
52
|
+
hash: row.mural_cue_hash ?? null,
|
|
53
|
+
...row.mural_cue_rejection_count > 0 ? { rejectionCount: row.mural_cue_rejection_count } : {}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return out;
|
|
57
|
+
}
|
|
58
|
+
function memoryNeedsCue(state, currentContent) {
|
|
59
|
+
if (!state || state.cue === null || state.hash === null)
|
|
60
|
+
return true;
|
|
61
|
+
return state.hash !== computeCueContentHash(currentContent);
|
|
62
|
+
}
|
|
63
|
+
function setMuralCue(db, projectPath, id, cue, contentHash) {
|
|
64
|
+
if (!hasMuralCueColumns(db))
|
|
65
|
+
return;
|
|
66
|
+
withPrivilegedWriter2(db, () => {
|
|
67
|
+
const owned = db.prepare("SELECT 1 FROM memories WHERE id = ? AND project_path = ?").get(id, projectPath);
|
|
68
|
+
if (!owned) {
|
|
69
|
+
throw new Error(`Memory ${id} does not belong to project ${projectPath}`);
|
|
70
|
+
}
|
|
71
|
+
const rejectionReset = hasMuralCueRejectionCountColumn(db) ? ", mural_cue_rejection_count = 0" : "";
|
|
72
|
+
db.prepare(`UPDATE memories SET mural_cue = ?, mural_cue_hash = ?, mural_cue_at = ?${rejectionReset} WHERE id = ? AND project_path = ?`).run(cue, contentHash, Date.now(), id, projectPath);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
function recordMuralCueRejection(db, projectPath, id, contentHash) {
|
|
76
|
+
if (!hasMuralCueColumns(db) || !hasMuralCueRejectionCountColumn(db))
|
|
77
|
+
return 0;
|
|
78
|
+
let count = 0;
|
|
79
|
+
withPrivilegedWriter2(db, () => {
|
|
80
|
+
const owned = db.prepare("SELECT 1 FROM memories WHERE id = ? AND project_path = ?").get(id, projectPath);
|
|
81
|
+
if (!owned) {
|
|
82
|
+
throw new Error(`Memory ${id} does not belong to project ${projectPath}`);
|
|
83
|
+
}
|
|
84
|
+
const row = db.prepare("SELECT mural_cue_hash, mural_cue_rejection_count FROM memories WHERE id = ?").get(id);
|
|
85
|
+
count = row?.mural_cue_hash === contentHash ? (row.mural_cue_rejection_count ?? 0) + 1 : 1;
|
|
86
|
+
db.prepare("UPDATE memories SET mural_cue = NULL, mural_cue_hash = ?, mural_cue_at = ?, mural_cue_rejection_count = ? WHERE id = ? AND project_path = ?").run(contentHash, Date.now(), count, id, projectPath);
|
|
87
|
+
});
|
|
88
|
+
return count;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// src/features/magic-context/memory/visibility.ts
|
|
92
|
+
var FOREIGN_VISIBLE_SQL = "status IN ('active','permanent') AND (expires_at IS NULL OR expires_at > :now_ms) AND shareable = 1 AND scope IN ('project','ecosystem','universe') AND category IN (SELECT value FROM json_each(:share_categories)) AND project_path IN (SELECT project_path FROM workspace_members WHERE workspace_id = :workspace_id) AND project_path <> :reader_project";
|
|
93
|
+
|
|
94
|
+
// src/features/magic-context/memory/storage-memory.ts
|
|
95
|
+
var COLUMN_MAP2 = {
|
|
96
|
+
id: "id",
|
|
97
|
+
projectPath: "project_path",
|
|
98
|
+
category: "category",
|
|
99
|
+
content: "content",
|
|
100
|
+
normalizedHash: "normalized_hash",
|
|
101
|
+
importance: "importance",
|
|
102
|
+
scope: "scope",
|
|
103
|
+
shareable: "shareable",
|
|
104
|
+
sourceSessionId: "source_session_id",
|
|
105
|
+
sourceType: "source_type",
|
|
106
|
+
seenCount: "seen_count",
|
|
107
|
+
retrievalCount: "retrieval_count",
|
|
108
|
+
firstSeenAt: "first_seen_at",
|
|
109
|
+
createdAt: "created_at",
|
|
110
|
+
updatedAt: "updated_at",
|
|
111
|
+
lastSeenAt: "last_seen_at",
|
|
112
|
+
lastRetrievedAt: "last_retrieved_at",
|
|
113
|
+
status: "status",
|
|
114
|
+
expiresAt: "expires_at",
|
|
115
|
+
verificationStatus: "verification_status",
|
|
116
|
+
verifiedAt: "verified_at",
|
|
117
|
+
supersededByMemoryId: "superseded_by_memory_id",
|
|
118
|
+
mergedFrom: "merged_from",
|
|
119
|
+
metadataJson: "metadata_json"
|
|
120
|
+
};
|
|
121
|
+
var MEMORY_CATEGORY_LOOKUP = {
|
|
122
|
+
PROJECT_RULES: true,
|
|
123
|
+
ARCHITECTURE: true,
|
|
124
|
+
CONFIG_VALUES: true,
|
|
125
|
+
ARCHITECTURE_DECISIONS: true,
|
|
126
|
+
CONSTRAINTS: true,
|
|
127
|
+
CONFIG_DEFAULTS: true,
|
|
128
|
+
NAMING: true,
|
|
129
|
+
USER_PREFERENCES: true,
|
|
130
|
+
USER_DIRECTIVES: true,
|
|
131
|
+
ENVIRONMENT: true,
|
|
132
|
+
WORKFLOW_RULES: true,
|
|
133
|
+
KNOWN_ISSUES: true
|
|
134
|
+
};
|
|
135
|
+
var MEMORY_STATUS_LOOKUP = {
|
|
136
|
+
active: true,
|
|
137
|
+
permanent: true,
|
|
138
|
+
archived: true
|
|
139
|
+
};
|
|
140
|
+
var MEMORY_SCOPE_LOOKUP = {
|
|
141
|
+
project: true,
|
|
142
|
+
ecosystem: true,
|
|
143
|
+
universe: true
|
|
144
|
+
};
|
|
145
|
+
var MEMORY_SOURCE_TYPE_LOOKUP = {
|
|
146
|
+
historian: true,
|
|
147
|
+
agent: true,
|
|
148
|
+
dreamer: true,
|
|
149
|
+
user: true
|
|
150
|
+
};
|
|
151
|
+
var VERIFICATION_STATUS_LOOKUP = {
|
|
152
|
+
unverified: true,
|
|
153
|
+
verified: true,
|
|
154
|
+
stale: true,
|
|
155
|
+
flagged: true
|
|
156
|
+
};
|
|
157
|
+
var insertMemoryStatements = new WeakMap;
|
|
158
|
+
var getMemoryByHashStatements = new WeakMap;
|
|
159
|
+
var getMemoryByIdStatements = new WeakMap;
|
|
160
|
+
var getMemoriesByIdsStatements = new Map;
|
|
161
|
+
var activeMemoriesNoExpiryStatements = new WeakMap;
|
|
162
|
+
var updateMemorySeenCountStatements = new WeakMap;
|
|
163
|
+
var updateMemoryRetrievalCountStatements = new WeakMap;
|
|
164
|
+
var updateMemoryStatusStatements = new WeakMap;
|
|
165
|
+
var updateArchivedMemoryStatements = new WeakMap;
|
|
166
|
+
var updateMemoryVerificationStatements = new WeakMap;
|
|
167
|
+
var updateMemoryContentStatements = new WeakMap;
|
|
168
|
+
var supersededMemoryStatements = new WeakMap;
|
|
169
|
+
var mergeMemoryStatsStatements = new WeakMap;
|
|
170
|
+
var deleteMemoryStatements = new WeakMap;
|
|
171
|
+
var deleteMemoryEmbeddingStatements = new WeakMap;
|
|
172
|
+
var deleteEmbeddingOnContentUpdateStatements = new WeakMap;
|
|
173
|
+
var getMemoryCountStatements = new WeakMap;
|
|
174
|
+
var getMemoryCountByProjectStatements = new WeakMap;
|
|
175
|
+
var getMemoryCountsByStatusStatements = new WeakMap;
|
|
176
|
+
var memoriesByProjectStatements = new Map;
|
|
177
|
+
var memoryImportanceColumnCache = new WeakMap;
|
|
178
|
+
var memoryScopeColumnCache = new WeakMap;
|
|
179
|
+
var memoryShareableColumnCache = new WeakMap;
|
|
180
|
+
var memoryClassifiedAtColumnCache = new WeakMap;
|
|
181
|
+
var memoryVerificationsTableCache = new WeakMap;
|
|
182
|
+
function hasMemoryImportanceColumn(db) {
|
|
183
|
+
const cached = memoryImportanceColumnCache.get(db);
|
|
184
|
+
if (cached !== undefined)
|
|
185
|
+
return cached;
|
|
186
|
+
const columns = db.prepare("PRAGMA table_info(memories)").all();
|
|
187
|
+
const hasColumn = columns.some((column) => column.name === "importance");
|
|
188
|
+
memoryImportanceColumnCache.set(db, hasColumn);
|
|
189
|
+
return hasColumn;
|
|
190
|
+
}
|
|
191
|
+
function hasMemoryScopeColumn(db) {
|
|
192
|
+
const cached = memoryScopeColumnCache.get(db);
|
|
193
|
+
if (cached !== undefined)
|
|
194
|
+
return cached;
|
|
195
|
+
const columns = db.prepare("PRAGMA table_info(memories)").all();
|
|
196
|
+
const hasColumn = columns.some((column) => column.name === "scope");
|
|
197
|
+
memoryScopeColumnCache.set(db, hasColumn);
|
|
198
|
+
return hasColumn;
|
|
199
|
+
}
|
|
200
|
+
function hasMemoryShareableColumn2(db) {
|
|
201
|
+
const cached = memoryShareableColumnCache.get(db);
|
|
202
|
+
if (cached !== undefined)
|
|
203
|
+
return cached;
|
|
204
|
+
const columns = db.prepare("PRAGMA table_info(memories)").all();
|
|
205
|
+
const hasColumn = columns.some((column) => column.name === "shareable");
|
|
206
|
+
memoryShareableColumnCache.set(db, hasColumn);
|
|
207
|
+
return hasColumn;
|
|
208
|
+
}
|
|
209
|
+
function hasMemoryClassifiedAtColumn2(db) {
|
|
210
|
+
const cached = memoryClassifiedAtColumnCache.get(db);
|
|
211
|
+
if (cached !== undefined)
|
|
212
|
+
return cached;
|
|
213
|
+
const columns = db.prepare("PRAGMA table_info(memories)").all();
|
|
214
|
+
const hasColumn = columns.some((column) => column.name === "classified_at");
|
|
215
|
+
memoryClassifiedAtColumnCache.set(db, hasColumn);
|
|
216
|
+
return hasColumn;
|
|
217
|
+
}
|
|
218
|
+
function hasMemoryVerificationsTable(db) {
|
|
219
|
+
const cached = memoryVerificationsTableCache.get(db);
|
|
220
|
+
if (cached !== undefined)
|
|
221
|
+
return cached;
|
|
222
|
+
const hasTable = Boolean(db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'memory_verifications'").get());
|
|
223
|
+
memoryVerificationsTableCache.set(db, hasTable);
|
|
224
|
+
return hasTable;
|
|
225
|
+
}
|
|
226
|
+
function getUnclassifiedMemoryIds2(db, memoryIds) {
|
|
227
|
+
if (!hasMemoryClassifiedAtColumn2(db))
|
|
228
|
+
return [...memoryIds];
|
|
229
|
+
const ids = Array.from(new Set(memoryIds.filter(Number.isInteger)));
|
|
230
|
+
if (ids.length === 0)
|
|
231
|
+
return [];
|
|
232
|
+
const rows = db.prepare("SELECT id FROM memories WHERE id IN (SELECT value FROM json_each(?)) AND classified_at IS NOT NULL").all(JSON.stringify(ids));
|
|
233
|
+
const classified = new Set(rows.map((r) => r.id));
|
|
234
|
+
return ids.filter((id) => !classified.has(id));
|
|
235
|
+
}
|
|
236
|
+
function getMemorySelectColumns2(db, tableName = "memories") {
|
|
237
|
+
return Object.entries(COLUMN_MAP2).map(([property, column]) => {
|
|
238
|
+
if (property === "importance" && !hasMemoryImportanceColumn(db)) {
|
|
239
|
+
return "50 AS importance";
|
|
240
|
+
}
|
|
241
|
+
if (property === "importance") {
|
|
242
|
+
return `COALESCE(${tableName}.${column}, 50) AS ${property}`;
|
|
243
|
+
}
|
|
244
|
+
if (property === "scope" && !hasMemoryScopeColumn(db)) {
|
|
245
|
+
return "'project' AS scope";
|
|
246
|
+
}
|
|
247
|
+
if (property === "scope") {
|
|
248
|
+
return `COALESCE(${tableName}.${column}, 'project') AS ${property}`;
|
|
249
|
+
}
|
|
250
|
+
if (property === "shareable" && !hasMemoryShareableColumn2(db)) {
|
|
251
|
+
return "0 AS shareable";
|
|
252
|
+
}
|
|
253
|
+
if (property === "shareable") {
|
|
254
|
+
return `COALESCE(${tableName}.${column}, 0) AS ${property}`;
|
|
255
|
+
}
|
|
256
|
+
return `${tableName}.${column} AS ${property}`;
|
|
257
|
+
}).join(", ");
|
|
258
|
+
}
|
|
259
|
+
function isMemoryCategory(value) {
|
|
260
|
+
return typeof value === "string" && value in MEMORY_CATEGORY_LOOKUP;
|
|
261
|
+
}
|
|
262
|
+
function isMemoryStatus(value) {
|
|
263
|
+
return typeof value === "string" && value in MEMORY_STATUS_LOOKUP;
|
|
264
|
+
}
|
|
265
|
+
function isMemoryScope(value) {
|
|
266
|
+
return typeof value === "string" && value in MEMORY_SCOPE_LOOKUP;
|
|
267
|
+
}
|
|
268
|
+
function isMemorySourceType(value) {
|
|
269
|
+
return typeof value === "string" && value in MEMORY_SOURCE_TYPE_LOOKUP;
|
|
270
|
+
}
|
|
271
|
+
function isVerificationStatus(value) {
|
|
272
|
+
return typeof value === "string" && value in VERIFICATION_STATUS_LOOKUP;
|
|
273
|
+
}
|
|
274
|
+
function isUniqueConstraintError(error) {
|
|
275
|
+
return error instanceof Error && "code" in error && error.code === "SQLITE_CONSTRAINT_UNIQUE";
|
|
276
|
+
}
|
|
277
|
+
function isNullableString(value) {
|
|
278
|
+
return value === null || typeof value === "string";
|
|
279
|
+
}
|
|
280
|
+
function isNullableNumber(value) {
|
|
281
|
+
return value === null || typeof value === "number";
|
|
282
|
+
}
|
|
283
|
+
function isMemoryCountByStatusRow(row) {
|
|
284
|
+
if (row === null || typeof row !== "object")
|
|
285
|
+
return false;
|
|
286
|
+
const candidate = row;
|
|
287
|
+
return typeof candidate.id === "number" && isMemoryStatus(candidate.status) && isNullableNumber(candidate.superseded_by_memory_id);
|
|
288
|
+
}
|
|
289
|
+
function isMemoryRow2(row) {
|
|
290
|
+
if (row === null || typeof row !== "object")
|
|
291
|
+
return false;
|
|
292
|
+
const candidate = row;
|
|
293
|
+
return typeof candidate.id === "number" && typeof candidate.projectPath === "string" && isMemoryCategory(candidate.category) && typeof candidate.content === "string" && typeof candidate.normalizedHash === "string" && typeof candidate.importance === "number" && isMemoryScope(candidate.scope) && typeof candidate.shareable === "number" && isNullableString(candidate.sourceSessionId) && isMemorySourceType(candidate.sourceType) && typeof candidate.seenCount === "number" && typeof candidate.retrievalCount === "number" && typeof candidate.firstSeenAt === "number" && typeof candidate.createdAt === "number" && typeof candidate.updatedAt === "number" && typeof candidate.lastSeenAt === "number" && isNullableNumber(candidate.lastRetrievedAt) && isMemoryStatus(candidate.status) && isNullableNumber(candidate.expiresAt) && isVerificationStatus(candidate.verificationStatus) && isNullableNumber(candidate.verifiedAt) && isNullableNumber(candidate.supersededByMemoryId) && isNullableString(candidate.mergedFrom) && isNullableString(candidate.metadataJson);
|
|
294
|
+
}
|
|
295
|
+
function toMemory2(row) {
|
|
296
|
+
return {
|
|
297
|
+
id: row.id,
|
|
298
|
+
projectPath: row.projectPath,
|
|
299
|
+
category: row.category,
|
|
300
|
+
content: row.content,
|
|
301
|
+
normalizedHash: row.normalizedHash,
|
|
302
|
+
importance: row.importance,
|
|
303
|
+
scope: row.scope,
|
|
304
|
+
shareable: row.shareable,
|
|
305
|
+
sourceSessionId: row.sourceSessionId,
|
|
306
|
+
sourceType: row.sourceType,
|
|
307
|
+
seenCount: row.seenCount,
|
|
308
|
+
retrievalCount: row.retrievalCount,
|
|
309
|
+
firstSeenAt: row.firstSeenAt,
|
|
310
|
+
createdAt: row.createdAt,
|
|
311
|
+
updatedAt: row.updatedAt,
|
|
312
|
+
lastSeenAt: row.lastSeenAt,
|
|
313
|
+
lastRetrievedAt: row.lastRetrievedAt,
|
|
314
|
+
status: row.status,
|
|
315
|
+
expiresAt: row.expiresAt,
|
|
316
|
+
verificationStatus: row.verificationStatus,
|
|
317
|
+
verifiedAt: row.verifiedAt,
|
|
318
|
+
supersededByMemoryId: row.supersededByMemoryId,
|
|
319
|
+
mergedFrom: row.mergedFrom,
|
|
320
|
+
metadataJson: row.metadataJson
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
function getInsertMemoryStatement(db) {
|
|
324
|
+
let stmt = insertMemoryStatements.get(db);
|
|
325
|
+
if (!stmt) {
|
|
326
|
+
stmt = hasMemoryImportanceColumn(db) ? db.prepare("INSERT INTO memories (project_path, category, content, normalized_hash, importance, source_session_id, source_type, seen_count, retrieval_count, first_seen_at, created_at, updated_at, last_seen_at, last_retrieved_at, status, expires_at, verification_status, verified_at, superseded_by_memory_id, merged_from, metadata_json) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") : db.prepare("INSERT INTO memories (project_path, category, content, normalized_hash, source_session_id, source_type, seen_count, retrieval_count, first_seen_at, created_at, updated_at, last_seen_at, last_retrieved_at, status, expires_at, verification_status, verified_at, superseded_by_memory_id, merged_from, metadata_json) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
|
327
|
+
insertMemoryStatements.set(db, stmt);
|
|
328
|
+
}
|
|
329
|
+
return stmt;
|
|
330
|
+
}
|
|
331
|
+
function getMemoryByHashStatement(db) {
|
|
332
|
+
let stmt = getMemoryByHashStatements.get(db);
|
|
333
|
+
if (!stmt) {
|
|
334
|
+
stmt = db.prepare(`SELECT ${getMemorySelectColumns2(db)} FROM memories WHERE project_path = ? AND category = ? AND normalized_hash = ?`);
|
|
335
|
+
getMemoryByHashStatements.set(db, stmt);
|
|
336
|
+
}
|
|
337
|
+
return stmt;
|
|
338
|
+
}
|
|
339
|
+
function getMemoryByIdStatement(db) {
|
|
340
|
+
let stmt = getMemoryByIdStatements.get(db);
|
|
341
|
+
if (!stmt) {
|
|
342
|
+
stmt = db.prepare(`SELECT ${getMemorySelectColumns2(db)} FROM memories WHERE id = ?`);
|
|
343
|
+
getMemoryByIdStatements.set(db, stmt);
|
|
344
|
+
}
|
|
345
|
+
return stmt;
|
|
346
|
+
}
|
|
347
|
+
function getMemoriesByIdsStatement(db, idCount) {
|
|
348
|
+
const key = `n${idCount}`;
|
|
349
|
+
let map = getMemoriesByIdsStatements.get(key);
|
|
350
|
+
if (!map) {
|
|
351
|
+
map = new WeakMap;
|
|
352
|
+
getMemoriesByIdsStatements.set(key, map);
|
|
353
|
+
}
|
|
354
|
+
let stmt = map.get(db);
|
|
355
|
+
if (!stmt) {
|
|
356
|
+
const placeholders = new Array(idCount).fill("?").join(", ");
|
|
357
|
+
stmt = db.prepare(`SELECT ${getMemorySelectColumns2(db)} FROM memories WHERE id IN (${placeholders})`);
|
|
358
|
+
map.set(db, stmt);
|
|
359
|
+
}
|
|
360
|
+
return stmt;
|
|
361
|
+
}
|
|
362
|
+
function getMemoriesByProjectStatement(db, statuses) {
|
|
363
|
+
const key = statuses.join(",");
|
|
364
|
+
let statements = memoriesByProjectStatements.get(key);
|
|
365
|
+
if (!statements) {
|
|
366
|
+
statements = new WeakMap;
|
|
367
|
+
memoriesByProjectStatements.set(key, statements);
|
|
368
|
+
}
|
|
369
|
+
let stmt = statements.get(db);
|
|
370
|
+
if (!stmt) {
|
|
371
|
+
const placeholders = statuses.map(() => "?").join(", ");
|
|
372
|
+
stmt = db.prepare(`SELECT ${getMemorySelectColumns2(db)} FROM memories WHERE project_path = ? AND status IN (${placeholders}) AND (expires_at IS NULL OR expires_at > ?) ORDER BY category ASC, updated_at DESC, id ASC`);
|
|
373
|
+
statements.set(db, stmt);
|
|
374
|
+
}
|
|
375
|
+
return stmt;
|
|
376
|
+
}
|
|
377
|
+
function getActiveMemoriesNoExpiryStatement(db) {
|
|
378
|
+
let stmt = activeMemoriesNoExpiryStatements.get(db);
|
|
379
|
+
if (!stmt) {
|
|
380
|
+
stmt = db.prepare(`SELECT ${getMemorySelectColumns2(db)} FROM memories WHERE project_path = ? AND status = 'active' ORDER BY category ASC, updated_at DESC, id ASC`);
|
|
381
|
+
activeMemoriesNoExpiryStatements.set(db, stmt);
|
|
382
|
+
}
|
|
383
|
+
return stmt;
|
|
384
|
+
}
|
|
385
|
+
function getUpdateMemorySeenCountStatement(db) {
|
|
386
|
+
let stmt = updateMemorySeenCountStatements.get(db);
|
|
387
|
+
if (!stmt) {
|
|
388
|
+
stmt = db.prepare("UPDATE memories SET seen_count = seen_count + 1, last_seen_at = ?, updated_at = ? WHERE id = ?");
|
|
389
|
+
updateMemorySeenCountStatements.set(db, stmt);
|
|
390
|
+
}
|
|
391
|
+
return stmt;
|
|
392
|
+
}
|
|
393
|
+
function getUpdateMemoryRetrievalCountStatement(db) {
|
|
394
|
+
let stmt = updateMemoryRetrievalCountStatements.get(db);
|
|
395
|
+
if (!stmt) {
|
|
396
|
+
stmt = db.prepare("UPDATE memories SET retrieval_count = retrieval_count + 1, last_retrieved_at = ?, updated_at = ? WHERE id = ?");
|
|
397
|
+
updateMemoryRetrievalCountStatements.set(db, stmt);
|
|
398
|
+
}
|
|
399
|
+
return stmt;
|
|
400
|
+
}
|
|
401
|
+
function getUpdateMemoryStatusStatement(db) {
|
|
402
|
+
let stmt = updateMemoryStatusStatements.get(db);
|
|
403
|
+
if (!stmt) {
|
|
404
|
+
stmt = db.prepare("UPDATE memories SET status = ?, updated_at = ? WHERE id = ?");
|
|
405
|
+
updateMemoryStatusStatements.set(db, stmt);
|
|
406
|
+
}
|
|
407
|
+
return stmt;
|
|
408
|
+
}
|
|
409
|
+
function getUpdateArchivedMemoryStatement(db) {
|
|
410
|
+
let stmt = updateArchivedMemoryStatements.get(db);
|
|
411
|
+
if (!stmt) {
|
|
412
|
+
stmt = db.prepare("UPDATE memories SET status = 'archived', metadata_json = ?, updated_at = ? WHERE id = ?");
|
|
413
|
+
updateArchivedMemoryStatements.set(db, stmt);
|
|
414
|
+
}
|
|
415
|
+
return stmt;
|
|
416
|
+
}
|
|
417
|
+
function getUpdateMemoryVerificationStatement(db) {
|
|
418
|
+
let stmt = updateMemoryVerificationStatements.get(db);
|
|
419
|
+
if (!stmt) {
|
|
420
|
+
stmt = db.prepare("UPDATE memories SET verification_status = ?, verified_at = CASE WHEN ? = 'verified' THEN ? ELSE verified_at END, updated_at = ? WHERE id = ?");
|
|
421
|
+
updateMemoryVerificationStatements.set(db, stmt);
|
|
422
|
+
}
|
|
423
|
+
return stmt;
|
|
424
|
+
}
|
|
425
|
+
function getUpdateMemoryContentStatement(db) {
|
|
426
|
+
let stmt = updateMemoryContentStatements.get(db);
|
|
427
|
+
if (!stmt) {
|
|
428
|
+
stmt = db.prepare("UPDATE memories SET content = ?, normalized_hash = ?, updated_at = ? WHERE id = ?");
|
|
429
|
+
updateMemoryContentStatements.set(db, stmt);
|
|
430
|
+
}
|
|
431
|
+
return stmt;
|
|
432
|
+
}
|
|
433
|
+
function getSupersededMemoryStatement(db) {
|
|
434
|
+
let stmt = supersededMemoryStatements.get(db);
|
|
435
|
+
if (!stmt) {
|
|
436
|
+
stmt = db.prepare("UPDATE memories SET superseded_by_memory_id = ?, status = 'archived', updated_at = ? WHERE id = ?");
|
|
437
|
+
supersededMemoryStatements.set(db, stmt);
|
|
438
|
+
}
|
|
439
|
+
return stmt;
|
|
440
|
+
}
|
|
441
|
+
function getMergeMemoryStatsStatement(db) {
|
|
442
|
+
let stmt = mergeMemoryStatsStatements.get(db);
|
|
443
|
+
if (!stmt) {
|
|
444
|
+
stmt = db.prepare("UPDATE memories SET seen_count = ?, retrieval_count = ?, merged_from = ?, status = ?, updated_at = ? WHERE id = ?");
|
|
445
|
+
mergeMemoryStatsStatements.set(db, stmt);
|
|
446
|
+
}
|
|
447
|
+
return stmt;
|
|
448
|
+
}
|
|
449
|
+
function getDeleteMemoryStatement(db) {
|
|
450
|
+
let stmt = deleteMemoryStatements.get(db);
|
|
451
|
+
if (!stmt) {
|
|
452
|
+
stmt = db.prepare("DELETE FROM memories WHERE id = ?");
|
|
453
|
+
deleteMemoryStatements.set(db, stmt);
|
|
454
|
+
}
|
|
455
|
+
return stmt;
|
|
456
|
+
}
|
|
457
|
+
function getDeleteMemoryEmbeddingStatement(db) {
|
|
458
|
+
let stmt = deleteMemoryEmbeddingStatements.get(db);
|
|
459
|
+
if (!stmt) {
|
|
460
|
+
stmt = db.prepare("DELETE FROM memory_embeddings WHERE memory_id = ?");
|
|
461
|
+
deleteMemoryEmbeddingStatements.set(db, stmt);
|
|
462
|
+
}
|
|
463
|
+
return stmt;
|
|
464
|
+
}
|
|
465
|
+
function getMemoryCountStatement(db) {
|
|
466
|
+
let stmt = getMemoryCountStatements.get(db);
|
|
467
|
+
if (!stmt) {
|
|
468
|
+
stmt = db.prepare("SELECT COUNT(*) AS count FROM memories");
|
|
469
|
+
getMemoryCountStatements.set(db, stmt);
|
|
470
|
+
}
|
|
471
|
+
return stmt;
|
|
472
|
+
}
|
|
473
|
+
function getMemoryCountByProjectStatement(db) {
|
|
474
|
+
let stmt = getMemoryCountByProjectStatements.get(db);
|
|
475
|
+
if (!stmt) {
|
|
476
|
+
stmt = db.prepare("SELECT COUNT(*) AS count FROM memories WHERE project_path = ?");
|
|
477
|
+
getMemoryCountByProjectStatements.set(db, stmt);
|
|
478
|
+
}
|
|
479
|
+
return stmt;
|
|
480
|
+
}
|
|
481
|
+
function getMemoryCountsByStatusStatement(db) {
|
|
482
|
+
let stmt = getMemoryCountsByStatusStatements.get(db);
|
|
483
|
+
if (!stmt) {
|
|
484
|
+
stmt = db.prepare("SELECT id, status, superseded_by_memory_id FROM memories WHERE project_path = ?");
|
|
485
|
+
getMemoryCountsByStatusStatements.set(db, stmt);
|
|
486
|
+
}
|
|
487
|
+
return stmt;
|
|
488
|
+
}
|
|
489
|
+
function buildInsertMemoryValues(input, normalizedHash, now, includeImportance) {
|
|
490
|
+
const insertValues = [
|
|
491
|
+
input.projectPath,
|
|
492
|
+
input.category,
|
|
493
|
+
input.content,
|
|
494
|
+
normalizedHash
|
|
495
|
+
];
|
|
496
|
+
if (includeImportance) {
|
|
497
|
+
insertValues.push(input.importance ?? 50);
|
|
498
|
+
}
|
|
499
|
+
insertValues.push(input.sourceSessionId ?? null, input.sourceType ?? "historian", 1, 0, now, now, now, now, null, "active", input.expiresAt ?? null, "unverified", null, null, null, input.metadataJson ?? null);
|
|
500
|
+
return insertValues;
|
|
501
|
+
}
|
|
502
|
+
function loadInsertedMemory(db, rowid) {
|
|
503
|
+
const inserted = getMemoryById2(db, Number(rowid));
|
|
504
|
+
if (!inserted) {
|
|
505
|
+
throw new Error("Failed to load inserted memory row");
|
|
506
|
+
}
|
|
507
|
+
return inserted;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
class ModuleMemoryAuthorityError2 extends Error {
|
|
511
|
+
projectPath;
|
|
512
|
+
code = "MEMORY_MODULE_AUTHORITY";
|
|
513
|
+
constructor(projectPath) {
|
|
514
|
+
super(`memory writes for module-managed project ${projectPath} must use the Rust ctx_memory module facade`);
|
|
515
|
+
this.projectPath = projectPath;
|
|
516
|
+
this.name = "ModuleMemoryAuthorityError";
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
function assertTsMemoryWriteAllowed(db, projectPath) {
|
|
520
|
+
try {
|
|
521
|
+
const managed = db.prepare("SELECT 1 FROM authority_managed WHERE project_path = ? UNION SELECT 1 FROM authority_repair_pending WHERE project_path = ? LIMIT 1").get(projectPath, projectPath);
|
|
522
|
+
if (managed)
|
|
523
|
+
throw new ModuleMemoryAuthorityError2(projectPath);
|
|
524
|
+
} catch (error) {
|
|
525
|
+
if (!(error instanceof Error) || !error.message.includes("no such table"))
|
|
526
|
+
throw error;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
function assertTsMemoryIdWriteAllowed(db, id) {
|
|
530
|
+
const memory = getMemoryById2(db, id);
|
|
531
|
+
if (memory)
|
|
532
|
+
assertTsMemoryWriteAllowed(db, memory.projectPath);
|
|
533
|
+
return memory;
|
|
534
|
+
}
|
|
535
|
+
function insertMemory2(db, input) {
|
|
536
|
+
if (input.sourceType === "user") {
|
|
537
|
+
throw new Error(`sourceType "user" is reserved for future dashboard manual entry and cannot be written by agent paths`);
|
|
538
|
+
}
|
|
539
|
+
assertTsMemoryWriteAllowed(db, input.projectPath);
|
|
540
|
+
const now = Date.now();
|
|
541
|
+
const normalizedHash = computeNormalizedHash(input.content);
|
|
542
|
+
const insertValues = buildInsertMemoryValues(input, normalizedHash, now, hasMemoryImportanceColumn(db));
|
|
543
|
+
const result = getInsertMemoryStatement(db).run(...insertValues);
|
|
544
|
+
const insertedResult = result;
|
|
545
|
+
const inserted = loadInsertedMemory(db, insertedResult.lastInsertRowid);
|
|
546
|
+
invalidateProject2(input.projectPath);
|
|
547
|
+
return inserted;
|
|
548
|
+
}
|
|
549
|
+
function insertMemoryIdempotent2(db, input) {
|
|
550
|
+
try {
|
|
551
|
+
return { memory: insertMemory2(db, input), inserted: true };
|
|
552
|
+
} catch (error) {
|
|
553
|
+
if (!isUniqueConstraintError(error)) {
|
|
554
|
+
throw error;
|
|
555
|
+
}
|
|
556
|
+
const normalizedHash = computeNormalizedHash(input.content);
|
|
557
|
+
const existing = getMemoryByHash2(db, input.projectPath, input.category, normalizedHash);
|
|
558
|
+
if (!existing) {
|
|
559
|
+
throw error;
|
|
560
|
+
}
|
|
561
|
+
updateMemorySeenCount2(db, existing.id);
|
|
562
|
+
return {
|
|
563
|
+
memory: getMemoryById2(db, existing.id) ?? existing,
|
|
564
|
+
inserted: false
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
function getMemoryByHash2(db, projectPath, category, normalizedHash) {
|
|
569
|
+
const result = getMemoryByHashStatement(db).get(projectPath, category, normalizedHash);
|
|
570
|
+
if (!isMemoryRow2(result)) {
|
|
571
|
+
return null;
|
|
572
|
+
}
|
|
573
|
+
return toMemory2(result);
|
|
574
|
+
}
|
|
575
|
+
function getMemoriesByProject2(db, projectPath, statuses = ["active", "permanent"], expiryCutoff = Date.now()) {
|
|
576
|
+
if (statuses.length === 0) {
|
|
577
|
+
return [];
|
|
578
|
+
}
|
|
579
|
+
const rows = getMemoriesByProjectStatement(db, statuses).all(projectPath, ...statuses, expiryCutoff).filter(isMemoryRow2);
|
|
580
|
+
return rows.map(toMemory2);
|
|
581
|
+
}
|
|
582
|
+
var memoryListStatements = new WeakMap;
|
|
583
|
+
function getMemoriesForList2(db, projectPath, categories, limit) {
|
|
584
|
+
if (limit <= 0)
|
|
585
|
+
return [];
|
|
586
|
+
let statement = memoryListStatements.get(db);
|
|
587
|
+
if (!statement) {
|
|
588
|
+
statement = db.prepare(`SELECT ${getMemorySelectColumns2(db)} FROM memories
|
|
589
|
+
WHERE project_path = ? AND status IN ('active', 'permanent')
|
|
590
|
+
AND (expires_at IS NULL OR expires_at > ?)
|
|
591
|
+
AND (? IS NULL OR category IN (SELECT value FROM json_each(?)))
|
|
592
|
+
ORDER BY category ASC, updated_at DESC, id ASC LIMIT ? OFFSET ?`);
|
|
593
|
+
memoryListStatements.set(db, statement);
|
|
594
|
+
}
|
|
595
|
+
const categoryJson = categories === null ? null : JSON.stringify(categories);
|
|
596
|
+
const cutoff = Date.now();
|
|
597
|
+
const pageSize = Math.min(256, limit);
|
|
598
|
+
const result = [];
|
|
599
|
+
for (let offset = 0;result.length < limit; offset += pageSize) {
|
|
600
|
+
const rows = statement.all(projectPath, cutoff, categoryJson, categoryJson, pageSize, offset);
|
|
601
|
+
result.push(...rows.filter(isMemoryRow2).map(toMemory2));
|
|
602
|
+
if (rows.length < pageSize)
|
|
603
|
+
break;
|
|
604
|
+
}
|
|
605
|
+
return result.slice(0, limit);
|
|
606
|
+
}
|
|
607
|
+
function sqlPlaceholders(values) {
|
|
608
|
+
return values.map(() => "?").join(", ");
|
|
609
|
+
}
|
|
610
|
+
function uniqueValues(values) {
|
|
611
|
+
return [...new Set(values.filter((value) => value.length > 0))];
|
|
612
|
+
}
|
|
613
|
+
function buildWorkspaceMemorySqlFilter2(args) {
|
|
614
|
+
if (args.shareCategories === null || args.shareCategories === undefined) {
|
|
615
|
+
return { clause: "", params: [], active: false, predicate: FOREIGN_VISIBLE_SQL };
|
|
616
|
+
}
|
|
617
|
+
const identities = uniqueValues(args.identities);
|
|
618
|
+
const identitySet = new Set(identities);
|
|
619
|
+
const ownSet = new Set(uniqueValues(args.ownIdentities ?? []).filter((identity) => identitySet.has(identity)));
|
|
620
|
+
const foreignIdentities = identities.filter((identity) => !ownSet.has(identity));
|
|
621
|
+
if (foreignIdentities.length === 0) {
|
|
622
|
+
return { clause: "", params: [], active: false, predicate: FOREIGN_VISIBLE_SQL };
|
|
623
|
+
}
|
|
624
|
+
const ownIdentities = identities.filter((identity) => ownSet.has(identity));
|
|
625
|
+
const shareCategories = uniqueValues([...args.shareCategories]);
|
|
626
|
+
const qualifier = args.tableName ? `${args.tableName}.` : "";
|
|
627
|
+
const classification = args.includeClassificationFields === false ? "" : ` AND ${qualifier}shareable = 1 AND ${qualifier}scope IN ('project','ecosystem','universe')`;
|
|
628
|
+
const predicates = [];
|
|
629
|
+
const params = [];
|
|
630
|
+
if (ownIdentities.length > 0) {
|
|
631
|
+
predicates.push(`${qualifier}project_path IN (${sqlPlaceholders(ownIdentities)})`);
|
|
632
|
+
params.push(...ownIdentities);
|
|
633
|
+
}
|
|
634
|
+
if (foreignIdentities.length > 0 && shareCategories.length > 0) {
|
|
635
|
+
predicates.push(`(${qualifier}project_path IN (${sqlPlaceholders(foreignIdentities)}) AND ${qualifier}category IN (${sqlPlaceholders(shareCategories)})${classification})`);
|
|
636
|
+
params.push(...foreignIdentities, ...shareCategories);
|
|
637
|
+
}
|
|
638
|
+
if (predicates.length === 0) {
|
|
639
|
+
return { clause: " AND 0 = 1", params: [], active: true, predicate: FOREIGN_VISIBLE_SQL };
|
|
640
|
+
}
|
|
641
|
+
return {
|
|
642
|
+
clause: ` AND (${predicates.join(" OR ")})`,
|
|
643
|
+
params,
|
|
644
|
+
active: true,
|
|
645
|
+
predicate: FOREIGN_VISIBLE_SQL
|
|
646
|
+
};
|
|
647
|
+
}
|
|
648
|
+
function getMemoriesByProjects2(db, projectPaths, statuses = ["active", "permanent"], expiryCutoff = Date.now(), ownIdentities, shareCategories) {
|
|
649
|
+
const identities = uniqueValues(projectPaths);
|
|
650
|
+
if (identities.length === 0 || statuses.length === 0)
|
|
651
|
+
return [];
|
|
652
|
+
const identitySet = new Set(identities);
|
|
653
|
+
const ownSet = new Set(uniqueValues(ownIdentities ?? []).filter((identity) => identitySet.has(identity)));
|
|
654
|
+
const foreignIdentities = identities.filter((identity) => !ownSet.has(identity));
|
|
655
|
+
const ownIdentitiesResolved = identities.filter((identity) => ownSet.has(identity));
|
|
656
|
+
if (foreignIdentities.length === 0 || shareCategories === null || shareCategories === undefined) {
|
|
657
|
+
if (identities.length === 1) {
|
|
658
|
+
return getMemoriesByProject2(db, identities[0], statuses, expiryCutoff);
|
|
659
|
+
}
|
|
660
|
+
const rows = db.prepare(`SELECT ${getMemorySelectColumns2(db)}
|
|
661
|
+
FROM memories
|
|
662
|
+
WHERE project_path IN (${sqlPlaceholders(identities)})
|
|
663
|
+
AND status IN (${sqlPlaceholders(statuses)})
|
|
664
|
+
AND (expires_at IS NULL OR expires_at > ?)
|
|
665
|
+
ORDER BY category ASC, updated_at DESC, id ASC`).all(...identities, ...statuses, expiryCutoff).filter(isMemoryRow2);
|
|
666
|
+
return rows.map(toMemory2);
|
|
667
|
+
}
|
|
668
|
+
const shareCats = uniqueValues([...shareCategories]);
|
|
669
|
+
const hasClassification = hasMemoryShareableColumn2(db) && hasMemoryScopeColumn(db);
|
|
670
|
+
const predicates = [];
|
|
671
|
+
const params = [];
|
|
672
|
+
if (ownIdentitiesResolved.length > 0) {
|
|
673
|
+
predicates.push(`(project_path IN (${sqlPlaceholders(ownIdentitiesResolved)})
|
|
674
|
+
AND status IN (${sqlPlaceholders(statuses)})
|
|
675
|
+
AND (expires_at IS NULL OR expires_at > ?))`);
|
|
676
|
+
params.push(...ownIdentitiesResolved, ...statuses, expiryCutoff);
|
|
677
|
+
}
|
|
678
|
+
if (foreignIdentities.length > 0 && shareCats.length > 0) {
|
|
679
|
+
const classification = hasClassification ? " AND shareable = 1 AND scope IN ('project','ecosystem','universe')" : "";
|
|
680
|
+
predicates.push(`(project_path IN (${sqlPlaceholders(foreignIdentities)})
|
|
681
|
+
AND status IN ('active','permanent')
|
|
682
|
+
AND (expires_at IS NULL OR expires_at > ?)
|
|
683
|
+
AND category IN (${sqlPlaceholders(shareCats)})${classification})`);
|
|
684
|
+
params.push(...foreignIdentities, expiryCutoff, ...shareCats);
|
|
685
|
+
}
|
|
686
|
+
if (predicates.length === 0)
|
|
687
|
+
return [];
|
|
688
|
+
const rows = db.prepare(`SELECT ${getMemorySelectColumns2(db)}
|
|
689
|
+
FROM memories
|
|
690
|
+
WHERE (${predicates.join(" OR ")})
|
|
691
|
+
ORDER BY category ASC, updated_at DESC, id ASC`).all(...params).filter(isMemoryRow2);
|
|
692
|
+
return rows.map(toMemory2);
|
|
693
|
+
}
|
|
694
|
+
function getMaxMemoryIdForProjects2(db, projectPaths, ownIdentities, shareCategories, expiryCutoff = Date.now()) {
|
|
695
|
+
const identities = uniqueValues(projectPaths);
|
|
696
|
+
if (identities.length === 0)
|
|
697
|
+
return 0;
|
|
698
|
+
const sharingFilter = buildWorkspaceMemorySqlFilter2({
|
|
699
|
+
identities,
|
|
700
|
+
ownIdentities,
|
|
701
|
+
shareCategories,
|
|
702
|
+
includeClassificationFields: hasMemoryShareableColumn2(db) && hasMemoryScopeColumn(db)
|
|
703
|
+
});
|
|
704
|
+
const row = db.prepare(`SELECT COALESCE(MAX(id), 0) AS max_id
|
|
705
|
+
FROM memories
|
|
706
|
+
WHERE project_path IN (${sqlPlaceholders(identities)})
|
|
707
|
+
AND status IN ('active', 'permanent')
|
|
708
|
+
AND (expires_at IS NULL OR expires_at > ?)${sharingFilter.clause}`).get(...identities, expiryCutoff, ...sharingFilter.params);
|
|
709
|
+
return typeof row?.max_id === "number" ? row.max_id : 0;
|
|
710
|
+
}
|
|
711
|
+
function readNewMemoriesForM1Union2(db, projectPaths, afterId, expiryCutoff, ownIdentities, shareCategories) {
|
|
712
|
+
const identities = uniqueValues(projectPaths);
|
|
713
|
+
if (identities.length === 0)
|
|
714
|
+
return [];
|
|
715
|
+
const sharingFilter = buildWorkspaceMemorySqlFilter2({
|
|
716
|
+
identities,
|
|
717
|
+
ownIdentities,
|
|
718
|
+
shareCategories,
|
|
719
|
+
includeClassificationFields: hasMemoryShareableColumn2(db) && hasMemoryScopeColumn(db)
|
|
720
|
+
});
|
|
721
|
+
const rows = db.prepare(`SELECT ${getMemorySelectColumns2(db)}
|
|
722
|
+
FROM memories
|
|
723
|
+
WHERE project_path IN (${sqlPlaceholders(identities)})
|
|
724
|
+
AND id > ?
|
|
725
|
+
AND status IN ('active', 'permanent')
|
|
726
|
+
AND (expires_at IS NULL OR expires_at > ?)${sharingFilter.clause}
|
|
727
|
+
ORDER BY ${MEMORY_CATEGORY_ORDER_SQL}, id ASC`).all(...identities, afterId, expiryCutoff, ...sharingFilter.params).filter(isMemoryRow2);
|
|
728
|
+
return rows.map(toMemory2);
|
|
729
|
+
}
|
|
730
|
+
function getAllActiveMemoriesForMigration2(db, projectPath) {
|
|
731
|
+
const rows = getActiveMemoriesNoExpiryStatement(db).all(projectPath).filter(isMemoryRow2);
|
|
732
|
+
return rows.map(toMemory2);
|
|
733
|
+
}
|
|
734
|
+
function getMemoryById2(db, id) {
|
|
735
|
+
const result = getMemoryByIdStatement(db).get(id);
|
|
736
|
+
if (!isMemoryRow2(result)) {
|
|
737
|
+
return null;
|
|
738
|
+
}
|
|
739
|
+
return toMemory2(result);
|
|
740
|
+
}
|
|
741
|
+
function getMemoriesByIds2(db, ids) {
|
|
742
|
+
const uniqueIds = Array.from(new Set(ids.filter((id) => Number.isInteger(id))));
|
|
743
|
+
if (uniqueIds.length === 0) {
|
|
744
|
+
return [];
|
|
745
|
+
}
|
|
746
|
+
const rows = getMemoriesByIdsStatement(db, uniqueIds.length).all(...uniqueIds).filter(isMemoryRow2);
|
|
747
|
+
return rows.map(toMemory2);
|
|
748
|
+
}
|
|
749
|
+
function updateMemorySeenCount2(db, id) {
|
|
750
|
+
assertTsMemoryIdWriteAllowed(db, id);
|
|
751
|
+
const now = Date.now();
|
|
752
|
+
getUpdateMemorySeenCountStatement(db).run(now, now, id);
|
|
753
|
+
}
|
|
754
|
+
function updateMemoryRetrievalCount2(db, id) {
|
|
755
|
+
assertTsMemoryIdWriteAllowed(db, id);
|
|
756
|
+
const now = Date.now();
|
|
757
|
+
getUpdateMemoryRetrievalCountStatement(db).run(now, now, id);
|
|
758
|
+
}
|
|
759
|
+
function updateMemoryStatus2(db, id, status) {
|
|
760
|
+
assertTsMemoryIdWriteAllowed(db, id);
|
|
761
|
+
getUpdateMemoryStatusStatement(db).run(status, Date.now(), id);
|
|
762
|
+
}
|
|
763
|
+
function mergeMetadataJson(existing, patch) {
|
|
764
|
+
let base = {};
|
|
765
|
+
if (existing) {
|
|
766
|
+
try {
|
|
767
|
+
const parsed = JSON.parse(existing);
|
|
768
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
769
|
+
base = parsed;
|
|
770
|
+
}
|
|
771
|
+
} catch {
|
|
772
|
+
base = {};
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
return JSON.stringify({ ...base, ...patch });
|
|
776
|
+
}
|
|
777
|
+
function updateMemoryVerification2(db, id, verificationStatus) {
|
|
778
|
+
assertTsMemoryIdWriteAllowed(db, id);
|
|
779
|
+
const now = Date.now();
|
|
780
|
+
getUpdateMemoryVerificationStatement(db).run(verificationStatus, verificationStatus, now, now, id);
|
|
781
|
+
}
|
|
782
|
+
function updateMemoryContent2(db, id, content, normalizedHash) {
|
|
783
|
+
const memory = assertTsMemoryIdWriteAllowed(db, id);
|
|
784
|
+
db.transaction(() => {
|
|
785
|
+
getUpdateMemoryContentStatement(db).run(content, normalizedHash, Date.now(), id);
|
|
786
|
+
if (hasMemoryShareableColumn2(db)) {
|
|
787
|
+
db.prepare("UPDATE memories SET shareable = 0 WHERE id = ?").run(id);
|
|
788
|
+
}
|
|
789
|
+
if (hasMemoryClassifiedAtColumn2(db)) {
|
|
790
|
+
db.prepare("UPDATE memories SET classified_at = NULL WHERE id = ?").run(id);
|
|
791
|
+
}
|
|
792
|
+
if (hasMuralCueColumns(db)) {
|
|
793
|
+
const rejectionReset = hasMuralCueRejectionCountColumn(db) ? ", mural_cue_rejection_count = 0" : "";
|
|
794
|
+
db.prepare(`UPDATE memories SET mural_cue = NULL, mural_cue_hash = NULL, mural_cue_at = NULL${rejectionReset} WHERE id = ?`).run(id);
|
|
795
|
+
}
|
|
796
|
+
if (hasMemoryVerificationsTable(db)) {
|
|
797
|
+
db.prepare("DELETE FROM memory_verifications WHERE memory_id = ?").run(id);
|
|
798
|
+
}
|
|
799
|
+
let stmt = deleteEmbeddingOnContentUpdateStatements.get(db);
|
|
800
|
+
if (!stmt) {
|
|
801
|
+
stmt = db.prepare("DELETE FROM memory_embeddings WHERE memory_id = ?");
|
|
802
|
+
deleteEmbeddingOnContentUpdateStatements.set(db, stmt);
|
|
803
|
+
}
|
|
804
|
+
stmt.run(id);
|
|
805
|
+
}).immediate();
|
|
806
|
+
if (memory) {
|
|
807
|
+
invalidateMemory2(memory.projectPath, id);
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
function normalizeImportance(value) {
|
|
811
|
+
if (!Number.isFinite(value))
|
|
812
|
+
return 50;
|
|
813
|
+
return Math.max(1, Math.min(100, Math.round(value)));
|
|
814
|
+
}
|
|
815
|
+
function setMemoryClassification2(db, id, classification) {
|
|
816
|
+
const hasImportance = classification.importance !== undefined;
|
|
817
|
+
const hasScope = classification.scope !== undefined;
|
|
818
|
+
const hasShareable = classification.shareable !== undefined;
|
|
819
|
+
if (!hasImportance && !hasScope && !hasShareable) {
|
|
820
|
+
throw new Error("setMemoryClassification requires at least one supplied field");
|
|
821
|
+
}
|
|
822
|
+
const memory = assertTsMemoryIdWriteAllowed(db, id);
|
|
823
|
+
if (!memory)
|
|
824
|
+
return false;
|
|
825
|
+
const assignments = [];
|
|
826
|
+
const values = [];
|
|
827
|
+
if (hasImportance) {
|
|
828
|
+
const next = normalizeImportance(classification.importance);
|
|
829
|
+
if (memory.importance !== next) {
|
|
830
|
+
assignments.push("importance = ?");
|
|
831
|
+
values.push(next);
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
if (hasScope) {
|
|
835
|
+
const next = classification.scope;
|
|
836
|
+
if (!isMemoryScope(next)) {
|
|
837
|
+
throw new Error(`invalid memory scope: ${String(next)}`);
|
|
838
|
+
}
|
|
839
|
+
if (memory.scope !== next) {
|
|
840
|
+
assignments.push("scope = ?");
|
|
841
|
+
values.push(next);
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
if (hasShareable) {
|
|
845
|
+
const next = classification.shareable ? 1 : 0;
|
|
846
|
+
if ((memory.shareable ? 1 : 0) !== next) {
|
|
847
|
+
assignments.push("shareable = ?");
|
|
848
|
+
values.push(next);
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
const fieldChanged = assignments.length > 0;
|
|
852
|
+
if (hasMemoryClassifiedAtColumn2(db)) {
|
|
853
|
+
assignments.push("classified_at = ?");
|
|
854
|
+
values.push(Date.now());
|
|
855
|
+
}
|
|
856
|
+
if (assignments.length === 0)
|
|
857
|
+
return false;
|
|
858
|
+
db.prepare(`UPDATE memories SET ${assignments.join(", ")} WHERE id = ?`).run(...values, id);
|
|
859
|
+
return fieldChanged;
|
|
860
|
+
}
|
|
861
|
+
function supersededMemory2(db, id, supersededById) {
|
|
862
|
+
assertTsMemoryIdWriteAllowed(db, id);
|
|
863
|
+
getSupersededMemoryStatement(db).run(supersededById, Date.now(), id);
|
|
864
|
+
}
|
|
865
|
+
function mergeMemoryStats2(db, id, seenCount, retrievalCount, mergedFrom, status) {
|
|
866
|
+
assertTsMemoryIdWriteAllowed(db, id);
|
|
867
|
+
getMergeMemoryStatsStatement(db).run(seenCount, retrievalCount, mergedFrom, status, Date.now(), id);
|
|
868
|
+
}
|
|
869
|
+
function archiveMemory2(db, id, reason) {
|
|
870
|
+
const trimmedReason = reason?.trim();
|
|
871
|
+
if (!trimmedReason) {
|
|
872
|
+
updateMemoryStatus2(db, id, "archived");
|
|
873
|
+
return;
|
|
874
|
+
}
|
|
875
|
+
const memory = assertTsMemoryIdWriteAllowed(db, id);
|
|
876
|
+
if (!memory) {
|
|
877
|
+
return;
|
|
878
|
+
}
|
|
879
|
+
getUpdateArchivedMemoryStatement(db).run(mergeMetadataJson(memory.metadataJson, { archive_reason: trimmedReason }), Date.now(), id);
|
|
880
|
+
}
|
|
881
|
+
function deleteMemory2(db, id) {
|
|
882
|
+
const memory = assertTsMemoryIdWriteAllowed(db, id);
|
|
883
|
+
db.transaction(() => {
|
|
884
|
+
getDeleteMemoryEmbeddingStatement(db).run(id);
|
|
885
|
+
getDeleteMemoryStatement(db).run(id);
|
|
886
|
+
}).immediate();
|
|
887
|
+
if (memory) {
|
|
888
|
+
invalidateMemory2(memory.projectPath, id);
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
function getMemoryCount2(db, projectPath) {
|
|
892
|
+
const result = projectPath ? getMemoryCountByProjectStatement(db).get(projectPath) : getMemoryCountStatement(db).get();
|
|
893
|
+
if (result === null || typeof result !== "object") {
|
|
894
|
+
return 0;
|
|
895
|
+
}
|
|
896
|
+
const count = result.count;
|
|
897
|
+
return typeof count === "number" ? count : 0;
|
|
898
|
+
}
|
|
899
|
+
function getMemoryCountsByStatus2(db, projectPath) {
|
|
900
|
+
const rows = getMemoryCountsByStatusStatement(db).all(projectPath).filter(isMemoryCountByStatusRow);
|
|
901
|
+
const counts = {
|
|
902
|
+
total: rows.length,
|
|
903
|
+
active: 0,
|
|
904
|
+
permanent: 0,
|
|
905
|
+
archived: 0,
|
|
906
|
+
merged: 0,
|
|
907
|
+
ids: [],
|
|
908
|
+
archivedIds: [],
|
|
909
|
+
mergedIds: []
|
|
910
|
+
};
|
|
911
|
+
for (const row of rows) {
|
|
912
|
+
counts.ids.push(row.id);
|
|
913
|
+
if (typeof row.superseded_by_memory_id === "number") {
|
|
914
|
+
counts.merged += 1;
|
|
915
|
+
counts.mergedIds.push(row.id);
|
|
916
|
+
} else if (row.status === "active") {
|
|
917
|
+
counts.active += 1;
|
|
918
|
+
} else if (row.status === "permanent") {
|
|
919
|
+
counts.permanent += 1;
|
|
920
|
+
} else {
|
|
921
|
+
counts.archived += 1;
|
|
922
|
+
counts.archivedIds.push(row.id);
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
counts.ids.sort((left, right) => left - right);
|
|
926
|
+
counts.archivedIds.sort((left, right) => left - right);
|
|
927
|
+
counts.mergedIds.sort((left, right) => left - right);
|
|
928
|
+
return counts;
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
export { computeCueContentHash, hasMuralCueColumns, getMuralCueState, memoryNeedsCue, setMuralCue, recordMuralCueRejection, COLUMN_MAP2, hasMemoryShareableColumn2, hasMemoryClassifiedAtColumn2, getUnclassifiedMemoryIds2, getMemorySelectColumns2, isMemoryRow2, toMemory2, ModuleMemoryAuthorityError2, insertMemory2, insertMemoryIdempotent2, getMemoryByHash2, getMemoriesByProject2, getMemoriesForList2, buildWorkspaceMemorySqlFilter2, getMemoriesByProjects2, getMaxMemoryIdForProjects2, readNewMemoriesForM1Union2, getAllActiveMemoriesForMigration2, getMemoryById2, getMemoriesByIds2, updateMemorySeenCount2, updateMemoryRetrievalCount2, updateMemoryStatus2, updateMemoryVerification2, updateMemoryContent2, setMemoryClassification2, supersededMemory2, mergeMemoryStats2, archiveMemory2, deleteMemory2, getMemoryCount2, getMemoryCountsByStatus2 };
|