@cortexkit/opencode-magic-context 0.46.1 → 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 +112 -0
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/live-run-config.d.ts.map +1 -1
- package/dist/config/migrate-config-location.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 +21 -9
- package/dist/config/schema/magic-context.d.ts.map +1 -1
- package/dist/{conflict-warning-hook-7fj2b9jw.js → conflict-warning-hook-w8cykrnf.js} +12 -9
- package/dist/{context-sh2m2vde.js → context-m0cy262m.js} +1785 -913
- package/dist/{derive-budgets-7nj7r1rv.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-gates.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/overflow-detection.d.ts +2 -0
- package/dist/features/magic-context/overflow-detection.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/project-embedding-registry.d.ts +7 -0
- package/dist/features/magic-context/project-embedding-registry.d.ts.map +1 -1
- package/dist/features/magic-context/search.d.ts +31 -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/session-project-storage.d.ts +8 -2
- package/dist/features/magic-context/session-project-storage.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-historian-runs.d.ts +2 -5
- package/dist/features/magic-context/storage-historian-runs.d.ts.map +1 -1
- package/dist/features/magic-context/storage-meta-persisted.d.ts +12 -0
- package/dist/features/magic-context/storage-meta-persisted.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 +148 -3
- package/dist/features/magic-context/storage-tags.d.ts.map +1 -1
- package/dist/features/magic-context/storage.d.ts +1 -0
- package/dist/features/magic-context/storage.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 +4 -2
- 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 +10 -0
- package/dist/hooks/magic-context/active-anthropic-turn.d.ts.map +1 -0
- package/dist/hooks/magic-context/apply-operations.d.ts.map +1 -1
- package/dist/hooks/magic-context/auto-search-blocking.fixture.d.ts +2 -0
- package/dist/hooks/magic-context/auto-search-blocking.fixture.d.ts.map +1 -0
- package/dist/hooks/magic-context/auto-search-deadline.d.ts +7 -0
- package/dist/hooks/magic-context/auto-search-deadline.d.ts.map +1 -1
- package/dist/hooks/magic-context/auto-search-host-review.fixture.d.ts +3 -0
- package/dist/hooks/magic-context/auto-search-host-review.fixture.d.ts.map +1 -0
- package/dist/hooks/magic-context/auto-search-lock-review.fixture.d.ts +2 -0
- package/dist/hooks/magic-context/auto-search-lock-review.fixture.d.ts.map +1 -0
- package/dist/hooks/magic-context/auto-search-long-lock-review.fixture.d.ts +2 -0
- package/dist/hooks/magic-context/auto-search-long-lock-review.fixture.d.ts.map +1 -0
- package/dist/hooks/magic-context/auto-search-omp-host-review.fixture.d.ts +4 -0
- package/dist/hooks/magic-context/auto-search-omp-host-review.fixture.d.ts.map +1 -0
- package/dist/hooks/magic-context/auto-search-omp-loader.fixture.d.ts +3 -0
- package/dist/hooks/magic-context/auto-search-omp-loader.fixture.d.ts.map +1 -0
- package/dist/hooks/magic-context/auto-search-runner.d.ts +1 -1
- package/dist/hooks/magic-context/auto-search-runner.d.ts.map +1 -1
- package/dist/hooks/magic-context/auto-search-snapshot.fixture.d.ts +4 -0
- package/dist/hooks/magic-context/auto-search-snapshot.fixture.d.ts.map +1 -0
- package/dist/hooks/magic-context/auto-search-worker-client.d.ts +98 -0
- package/dist/hooks/magic-context/auto-search-worker-client.d.ts.map +1 -0
- package/dist/hooks/magic-context/auto-search-worker.d.ts +2 -0
- package/dist/hooks/magic-context/auto-search-worker.d.ts.map +1 -0
- package/dist/hooks/magic-context/caveman-cleanup.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-runner-types.d.ts +3 -5
- package/dist/hooks/magic-context/compartment-runner-types.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner.d.ts +2 -1
- package/dist/hooks/magic-context/compartment-runner.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-trigger.d.ts +3 -1
- package/dist/hooks/magic-context/compartment-trigger.d.ts.map +1 -1
- package/dist/hooks/magic-context/event-handler.d.ts +1 -1
- package/dist/hooks/magic-context/event-handler.d.ts.map +1 -1
- package/dist/hooks/magic-context/event-resolvers.d.ts.map +1 -1
- package/dist/hooks/magic-context/execute-status.d.ts.map +1 -1
- package/dist/hooks/magic-context/final-wire-token-estimate.d.ts +2 -0
- package/dist/hooks/magic-context/final-wire-token-estimate.d.ts.map +1 -1
- package/dist/hooks/magic-context/heuristic-cleanup.d.ts.map +1 -1
- package/dist/hooks/magic-context/historian-drain-gate.d.ts +11 -0
- package/dist/hooks/magic-context/historian-drain-gate.d.ts.map +1 -0
- package/dist/hooks/magic-context/hook.d.ts +3 -2
- 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/latest-assistant-turn.d.ts +25 -0
- package/dist/hooks/magic-context/latest-assistant-turn.d.ts.map +1 -0
- package/dist/hooks/magic-context/latest-thinking-recovery.d.ts +61 -0
- package/dist/hooks/magic-context/latest-thinking-recovery.d.ts.map +1 -0
- 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/module-wire.d.ts.map +1 -1
- 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/opencode-proven-floor.d.ts +6 -0
- package/dist/hooks/magic-context/opencode-proven-floor.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/pass-outcome.d.ts.map +1 -1
- package/dist/hooks/magic-context/protected-tail-boundary.d.ts.map +1 -1
- 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-status.d.ts +15 -0
- package/dist/hooks/magic-context/reasoning-budget-status.d.ts.map +1 -0
- package/dist/hooks/magic-context/reasoning-budget.d.ts +40 -0
- package/dist/hooks/magic-context/reasoning-budget.d.ts.map +1 -0
- package/dist/hooks/magic-context/reasoning-removal.d.ts +6 -6
- package/dist/hooks/magic-context/reasoning-removal.d.ts.map +1 -1
- package/dist/hooks/magic-context/rust-mode-transform.d.ts.map +1 -1
- package/dist/hooks/magic-context/sentinel.d.ts +45 -1
- package/dist/hooks/magic-context/sentinel.d.ts.map +1 -1
- package/dist/hooks/magic-context/strip-content.d.ts +21 -5
- 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 +21 -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/tool-drop-target.d.ts +5 -0
- package/dist/hooks/magic-context/tool-drop-target.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-compartment-phase.d.ts +3 -28
- package/dist/hooks/magic-context/transform-compartment-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +28 -6
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform.d.ts +11 -3
- 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-hpecdzec.js → index-0an7742d.js} +6820 -6587
- 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-sjthx78w.js → index-692jzy0p.js} +16879 -22907
- package/dist/index-72nhv486.js +2307 -0
- package/dist/index-7jzrrxap.js +931 -0
- package/dist/index-7mx8v0pw.js +3591 -0
- 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-8x2v7gg9.js → index-bhvjj0ys.js} +158 -2455
- 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-pkbcrdqs.js → index-f0h6xwqm.js} +3412 -4552
- 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-5p8jdswx.js → index-k1xb52kd.js} +20 -13
- package/dist/index-k9nnwad5.js +3532 -0
- package/dist/{v2/server-fg34g6a5.js → index-kb9nn0a0.js} +309 -52
- package/dist/index-knh4y330.js +566 -0
- package/dist/{index-q4yp4b52.js → index-mfkzp7qj.js} +28 -28
- package/dist/{index-sgthv3f7.js → index-mmyh6d8f.js} +4 -4
- package/dist/index-pavzsdc6.js +17 -0
- package/dist/{index-0d3g3461.js → index-pdecwzrd.js} +19 -16
- package/dist/index-pg50n748.js +1060 -0
- package/dist/index-q2tqeqde.js +2106 -0
- package/dist/index-q7h7csab.js +3469 -0
- package/dist/index-qt1qqasc.js +22 -0
- package/dist/{index-majxda46.js → index-ty64eqcn.js} +28 -18
- package/dist/{index-7qw742ev.js → index-yq8n9qcb.js} +25 -44
- package/dist/{index-sfnj6h8h.js → index-z8e0psj8.js} +20 -20
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1061 -260
- package/dist/logger-d3wex3dz.js +20 -0
- package/dist/message-index-bounded-7ezbgddp.js +124 -0
- package/dist/{v2/message-time-backfill-r6qkem1x.js → message-time-backfill-brbd63hv.js} +8 -6
- package/dist/migration-worker.js +25 -16
- 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 +3 -1
- package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
- package/dist/plugin/host-stall-profiler-report.d.ts +2 -0
- package/dist/plugin/host-stall-profiler-report.d.ts.map +1 -0
- package/dist/plugin/host-stall-profiler.d.ts +3 -0
- package/dist/plugin/host-stall-profiler.d.ts.map +1 -0
- package/dist/plugin/messages-transform.d.ts +21 -19
- 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-egz7r68d.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-qs0j78v6.js → send-session-notification-erecz4y4.js} +10 -6
- package/dist/shared/auto-search-lifecycle.d.ts +7 -0
- package/dist/shared/auto-search-lifecycle.d.ts.map +1 -0
- package/dist/shared/conflict-detector.d.ts.map +1 -1
- package/dist/shared/historian-tool-expansions.d.ts +1 -1
- package/dist/shared/historian-tool-expansions.d.ts.map +1 -1
- package/dist/shared/historian-tool-template.d.ts +2 -2
- package/dist/shared/historian-tool-template.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 +46 -1
- package/dist/shared/sqlite.d.ts.map +1 -1
- package/dist/shared/stable-json.d.ts.map +1 -1
- package/dist/shared/status-view.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/shared/window-geometry.d.ts +4 -0
- package/dist/shared/window-geometry.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/render.d.ts.map +1 -1
- 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-bqhz6vdr.js → transform-postprocess-phase-spcy2qre.js} +35 -17
- package/dist/transformers-node-wasm.js +18415 -18415
- package/dist/v2/auto-search-worker.js +112 -0
- package/dist/v2/{context-zecmzk5s.js → context-sf98kstd.js} +8378 -8530
- package/dist/v2/{derive-budgets-kdgp4s3r.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/hidden-completion.d.ts.map +1 -1
- 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-68gj6t3e.js → v2/message-time-backfill-gtx1pwk1.js} +7 -7
- package/dist/v2/migration-worker.js +24 -15
- 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-8vjp6581.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-dyw42dtr.js → v2/send-session-notification-6km439kn.js} +9 -7
- 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-xa4xe3rv.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-8pyt7hev.js +3408 -0
- 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/v2/server-e0vdaae2.js +3591 -0
- 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-jc7y02q0.js → server-k8x2rbxc.js} +5119 -10948
- package/dist/{index-fg34g6a5.js → v2/server-kb9nn0a0.js} +309 -52
- package/dist/v2/{server-g0fjrkta.js → server-mfkzp7qj.js} +28 -28
- package/dist/v2/server-pavzsdc6.js +17 -0
- package/dist/v2/server-psqc7e9n.js +2106 -0
- package/dist/v2/server-qt1qqasc.js +22 -0
- 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-y8maxeft.js → server-v06jcv0w.js} +16 -13
- package/dist/v2/server-vqpf3167.js +1048 -0
- package/dist/v2/{server-c5gz8wph.js → server-x2g40a71.js} +2048 -2059
- package/dist/v2/{server-wvjvfhck.js → server-xdfwt6kh.js} +20 -16
- package/dist/v2/{server-mcfawjgc.js → server-xxm59eww.js} +25 -44
- package/dist/v2/server-yczc713m.js +564 -0
- package/dist/v2/{server-3n4q9xme.js → server-z2037m6z.js} +4 -4
- package/dist/v2/{server-e29d7p7c.js → server-zm570tr2.js} +166 -160
- 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-0snhvwcv.js → wrapup-orchestrator-mz7efs7w.js} +51 -27
- 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 +8 -0
- package/src/config/latch-permanence-guard.test.ts +4 -0
- package/src/config/live-run-config.test.ts +37 -1
- package/src/config/live-run-config.ts +28 -0
- package/src/config/migrate-config-location.ts +10 -3
- 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 +6 -5
- package/src/config/schema/magic-context.ts +34 -16
- package/src/features/magic-context/dreamer/task-registry.ts +6 -0
- package/src/shared/auto-search-lifecycle.ts +27 -0
- package/src/shared/conflict-detector.test.ts +56 -0
- package/src/shared/conflict-detector.ts +16 -5
- package/src/shared/historian-tool-defaults.json +6 -6
- package/src/shared/historian-tool-expansions.ts +65 -8
- package/src/shared/historian-tool-preview-defaults.json +13 -0
- package/src/shared/historian-tool-template.ts +48 -14
- 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-640-review-r2.test.ts +136 -0
- package/src/shared/sqlite-640-review.test.ts +183 -0
- package/src/shared/sqlite-acquisition-routing.test.ts +18 -0
- package/src/shared/sqlite.test.ts +52 -0
- package/src/shared/sqlite.ts +423 -37
- package/src/shared/stable-json-linear.test.ts +109 -0
- package/src/shared/stable-json.ts +37 -7
- package/src/shared/status-view.test.ts +6 -1
- package/src/shared/status-view.ts +15 -1
- package/src/shared/tag-transcript.ts +6 -0
- package/src/shared/user-facing-codes.ts +2 -6
- package/src/shared/window-geometry.ts +10 -0
- 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-3h0ybwah.js +0 -6540
- package/dist/index-r5hmbx3t.js +0 -7773
- package/dist/recomp-orchestrator-y15j0rb9.js +0 -39
- package/dist/v2/recomp-orchestrator-8ejxvrzz.js +0 -39
- package/dist/v2/server-frbm99q5.js +0 -7698
- package/dist/v2/server-qp5hx1ad.js +0 -6366
- package/dist/wrapup-orchestrator-39amhv9s.js +0 -26
- /package/dist/{index-en1k8h8m.js → index-2pp04pmg.js} +0 -0
- /package/dist/v2/{index-en1k8h8m.js → index-2pp04pmg.js} +0 -0
|
@@ -0,0 +1,984 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getHarness2
|
|
3
|
+
} from "./index-pavzsdc6.js";
|
|
4
|
+
import {
|
|
5
|
+
isTransientSqliteError2
|
|
6
|
+
} from "./index-kb9nn0a0.js";
|
|
7
|
+
import {
|
|
8
|
+
PROMOTABLE_CATEGORIES,
|
|
9
|
+
CATEGORY_DEFAULT_TTL
|
|
10
|
+
} from "./index-fr0wbhdn.js";
|
|
11
|
+
import {
|
|
12
|
+
sessionLog2
|
|
13
|
+
} from "./index-8j7gqj40.js";
|
|
14
|
+
import {
|
|
15
|
+
managedAuthorityNoteRow
|
|
16
|
+
} from "./index-7mx8v0pw.js";
|
|
17
|
+
import {
|
|
18
|
+
embedTextForProject2
|
|
19
|
+
} from "./index-c43kr12f.js";
|
|
20
|
+
import {
|
|
21
|
+
saveEmbeddingIfHashMatches
|
|
22
|
+
} from "./index-4dhv7mqz.js";
|
|
23
|
+
import {
|
|
24
|
+
getMemorySelectColumns2,
|
|
25
|
+
isMemoryRow2,
|
|
26
|
+
toMemory2,
|
|
27
|
+
insertMemory2,
|
|
28
|
+
getMemoryByHash2,
|
|
29
|
+
buildWorkspaceMemorySqlFilter2,
|
|
30
|
+
getMemoryById2,
|
|
31
|
+
updateMemorySeenCount2
|
|
32
|
+
} from "./index-7jzrrxap.js";
|
|
33
|
+
import {
|
|
34
|
+
computeNormalizedHash
|
|
35
|
+
} from "./index-2bvekkfy.js";
|
|
36
|
+
|
|
37
|
+
// src/features/magic-context/storage-notes.ts
|
|
38
|
+
var NOTE_TYPES = new Set(["session", "smart"]);
|
|
39
|
+
var NOTE_STATUSES = new Set(["active", "pending", "ready", "dismissed"]);
|
|
40
|
+
var NOTE_CHECK_STATUSES = new Set([
|
|
41
|
+
"uncompiled",
|
|
42
|
+
"compiled",
|
|
43
|
+
"failing",
|
|
44
|
+
"fallback",
|
|
45
|
+
"parked"
|
|
46
|
+
]);
|
|
47
|
+
var CONDITION_COMPILE_STATUSES = new Set([
|
|
48
|
+
"compiled",
|
|
49
|
+
"plain",
|
|
50
|
+
"refused"
|
|
51
|
+
]);
|
|
52
|
+
var DEFAULT_SMART_STATUSES = ["pending", "ready"];
|
|
53
|
+
function toNullableString(value) {
|
|
54
|
+
return typeof value === "string" && value.length > 0 ? value : null;
|
|
55
|
+
}
|
|
56
|
+
function toNullableNumber(value) {
|
|
57
|
+
return typeof value === "number" ? value : null;
|
|
58
|
+
}
|
|
59
|
+
function isNoteRow(row) {
|
|
60
|
+
if (row === null || typeof row !== "object")
|
|
61
|
+
return false;
|
|
62
|
+
const candidate = row;
|
|
63
|
+
return typeof candidate.id === "number" && typeof candidate.type === "string" && NOTE_TYPES.has(candidate.type) && typeof candidate.status === "string" && NOTE_STATUSES.has(candidate.status) && typeof candidate.content === "string" && (candidate.session_id === null || typeof candidate.session_id === "string") && (candidate.project_path === null || typeof candidate.project_path === "string") && (candidate.surface_condition === null || typeof candidate.surface_condition === "string") && typeof candidate.created_at === "number" && typeof candidate.updated_at === "number" && (candidate.last_checked_at === null || typeof candidate.last_checked_at === "number") && (candidate.ready_at === null || typeof candidate.ready_at === "number") && (candidate.ready_reason === null || typeof candidate.ready_reason === "string");
|
|
64
|
+
}
|
|
65
|
+
function toNote(row) {
|
|
66
|
+
return {
|
|
67
|
+
id: row.id,
|
|
68
|
+
type: row.type,
|
|
69
|
+
status: row.status,
|
|
70
|
+
content: row.content,
|
|
71
|
+
sessionId: toNullableString(row.session_id),
|
|
72
|
+
projectPath: toNullableString(row.project_path),
|
|
73
|
+
surfaceCondition: toNullableString(row.surface_condition),
|
|
74
|
+
compiledProvider: toNullableString(row.compiled_provider),
|
|
75
|
+
compiledConfig: toNullableString(row.compiled_config),
|
|
76
|
+
compiledAt: toNullableNumber(row.compiled_at),
|
|
77
|
+
compileStatus: typeof row.compile_status === "string" && CONDITION_COMPILE_STATUSES.has(row.compile_status) ? row.compile_status : null,
|
|
78
|
+
createdAt: row.created_at,
|
|
79
|
+
updatedAt: row.updated_at,
|
|
80
|
+
lastCheckedAt: toNullableNumber(row.last_checked_at),
|
|
81
|
+
readyAt: toNullableNumber(row.ready_at),
|
|
82
|
+
readyReason: toNullableString(row.ready_reason),
|
|
83
|
+
anchorOrdinal: toNullableNumber(row.anchor_ordinal),
|
|
84
|
+
compiledCheck: toNullableString(row.compiled_check),
|
|
85
|
+
manifestJson: toNullableString(row.manifest_json),
|
|
86
|
+
checkHash: toNullableString(row.check_hash),
|
|
87
|
+
checkCron: toNullableString(row.check_cron),
|
|
88
|
+
checkVersion: toNullableNumber(row.check_version),
|
|
89
|
+
checkStatus: typeof row.check_status === "string" && NOTE_CHECK_STATUSES.has(row.check_status) ? row.check_status : null,
|
|
90
|
+
checkFailureCount: toNullableNumber(row.check_failure_count) ?? 0,
|
|
91
|
+
checkNetworkFailureCount: toNullableNumber(row.check_network_failure_count) ?? 0,
|
|
92
|
+
checkQuarantinedUntil: toNullableNumber(row.check_quarantined_until),
|
|
93
|
+
checkNextDueAt: toNullableNumber(row.check_next_due_at),
|
|
94
|
+
checkCompiledAt: toNullableNumber(row.check_compiled_at),
|
|
95
|
+
checkFalseSinceAt: toNullableNumber(row.check_false_since_at),
|
|
96
|
+
checkLastLivenessAt: toNullableNumber(row.check_last_liveness_at),
|
|
97
|
+
policyVersion: toNullableNumber(row.policy_version)
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
function noteCheckColumnsExist(db) {
|
|
101
|
+
try {
|
|
102
|
+
const rows = db.prepare("PRAGMA table_info(notes)").all();
|
|
103
|
+
return rows.some((row) => row.name === "compiled_check");
|
|
104
|
+
} catch {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
var PENDING_SESSION_NOTE_PREDICATE = "type = 'session' AND status = 'pending' AND surface_condition IS NOT NULL";
|
|
109
|
+
function healPendingSessionNotes(db) {
|
|
110
|
+
let predicate = `${PENDING_SESSION_NOTE_PREDICATE} AND NOT ${managedAuthorityNoteRow("notes")}`;
|
|
111
|
+
let healable;
|
|
112
|
+
try {
|
|
113
|
+
healable = db.prepare(`SELECT 1 FROM notes WHERE ${predicate} LIMIT 1`).get();
|
|
114
|
+
} catch (error) {
|
|
115
|
+
if (!(error instanceof Error) || !error.message.includes("no such table"))
|
|
116
|
+
throw error;
|
|
117
|
+
predicate = PENDING_SESSION_NOTE_PREDICATE;
|
|
118
|
+
healable = db.prepare(`SELECT 1 FROM notes WHERE ${predicate} LIMIT 1`).get();
|
|
119
|
+
}
|
|
120
|
+
if (healable == null)
|
|
121
|
+
return;
|
|
122
|
+
try {
|
|
123
|
+
db.prepare(`UPDATE notes SET status = 'active', surface_condition = NULL WHERE ${predicate}`).run();
|
|
124
|
+
} catch (error) {
|
|
125
|
+
if (!isTransientSqliteError2(error))
|
|
126
|
+
throw error;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
var SESSION_NOTE_CONDITION_ERROR = "Only a note created with a condition can have one. Write a new note with surface_condition, and dismiss this one.";
|
|
130
|
+
function getNoteById(db, noteId) {
|
|
131
|
+
healPendingSessionNotes(db);
|
|
132
|
+
const row = db.prepare("SELECT * FROM notes WHERE id = ?").get(noteId);
|
|
133
|
+
return isNoteRow(row) ? toNote(row) : null;
|
|
134
|
+
}
|
|
135
|
+
function getNoteByIdInScope(db, noteId, scope) {
|
|
136
|
+
const note = getNoteById(db, noteId);
|
|
137
|
+
return note && noteBelongsToScope(note, scope) ? note : null;
|
|
138
|
+
}
|
|
139
|
+
function noteBelongsToScope(note, scope) {
|
|
140
|
+
if (note.type === "session") {
|
|
141
|
+
return note.sessionId === scope.sessionId;
|
|
142
|
+
}
|
|
143
|
+
return note.projectPath === scope.projectPath;
|
|
144
|
+
}
|
|
145
|
+
function buildStatusClause(status) {
|
|
146
|
+
if (status === undefined) {
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
const statuses = Array.isArray(status) ? status : [status];
|
|
150
|
+
if (statuses.length === 0) {
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
const placeholders = statuses.map(() => "?").join(", ");
|
|
154
|
+
return {
|
|
155
|
+
sql: `status IN (${placeholders})`,
|
|
156
|
+
params: statuses
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
function getNotes(db, options = {}) {
|
|
160
|
+
healPendingSessionNotes(db);
|
|
161
|
+
const clauses = [];
|
|
162
|
+
const params = [];
|
|
163
|
+
if (options.sessionId !== undefined) {
|
|
164
|
+
clauses.push("session_id = ?");
|
|
165
|
+
params.push(options.sessionId);
|
|
166
|
+
}
|
|
167
|
+
if (options.projectPath !== undefined) {
|
|
168
|
+
clauses.push("project_path = ?");
|
|
169
|
+
params.push(options.projectPath);
|
|
170
|
+
}
|
|
171
|
+
if (options.type !== undefined) {
|
|
172
|
+
clauses.push("type = ?");
|
|
173
|
+
params.push(options.type);
|
|
174
|
+
}
|
|
175
|
+
const statusClause = buildStatusClause(options.status);
|
|
176
|
+
if (statusClause) {
|
|
177
|
+
clauses.push(statusClause.sql);
|
|
178
|
+
params.push(...statusClause.params);
|
|
179
|
+
}
|
|
180
|
+
const where = clauses.length > 0 ? ` WHERE ${clauses.join(" AND ")}` : "";
|
|
181
|
+
return db.prepare(`SELECT * FROM notes${where} ORDER BY created_at ASC, id ASC`).all(...params).filter(isNoteRow).map(toNote);
|
|
182
|
+
}
|
|
183
|
+
function addNote(db, type, options) {
|
|
184
|
+
const now = Date.now();
|
|
185
|
+
const result = type === "session" ? db.prepare("INSERT INTO notes (type, status, content, session_id, created_at, updated_at, harness, anchor_ordinal) VALUES ('session', 'active', ?, ?, ?, ?, ?, ?) RETURNING *").get(options.content, options.sessionId, now, now, getHarness2(), options.anchorOrdinal ?? null) : db.prepare("INSERT INTO notes (type, status, content, session_id, project_path, surface_condition, compiled_provider, compiled_config, compiled_at, compile_status, created_at, updated_at, harness, anchor_ordinal) VALUES ('smart', 'pending', ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING *").get(options.content, options.sessionId ?? null, options.projectPath, options.surfaceCondition, options.compiledProvider ?? null, options.compiledConfig ?? null, options.compiledAt ?? null, options.compileStatus ?? null, now, now, getHarness2(), options.anchorOrdinal ?? null);
|
|
186
|
+
if (!isNoteRow(result)) {
|
|
187
|
+
throw new Error("[notes] failed to insert note");
|
|
188
|
+
}
|
|
189
|
+
return toNote(result);
|
|
190
|
+
}
|
|
191
|
+
function getSessionNotes(db, sessionId) {
|
|
192
|
+
return getNotes(db, { sessionId, type: "session", status: "active" });
|
|
193
|
+
}
|
|
194
|
+
function getSmartNotes(db, projectPath, status) {
|
|
195
|
+
return getNotes(db, {
|
|
196
|
+
projectPath,
|
|
197
|
+
type: "smart",
|
|
198
|
+
status: status ?? DEFAULT_SMART_STATUSES
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
function getPendingSmartNotes(db, projectPath) {
|
|
202
|
+
return getSmartNotes(db, projectPath, "pending");
|
|
203
|
+
}
|
|
204
|
+
function getReadySmartNotes(db, projectPath) {
|
|
205
|
+
return getSmartNotes(db, projectPath, "ready");
|
|
206
|
+
}
|
|
207
|
+
function updateNote(db, noteId, updates, scope) {
|
|
208
|
+
const existing = getNoteByIdInScope(db, noteId, scope);
|
|
209
|
+
if (!existing) {
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
if (updates.surfaceCondition !== undefined && existing.type !== "smart") {
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
const now = Date.now();
|
|
216
|
+
const sets = ["updated_at = ?"];
|
|
217
|
+
const params = [now];
|
|
218
|
+
if (updates.content !== undefined) {
|
|
219
|
+
sets.push("content = ?");
|
|
220
|
+
params.push(updates.content);
|
|
221
|
+
}
|
|
222
|
+
if (updates.sessionId !== undefined) {
|
|
223
|
+
sets.push("session_id = ?");
|
|
224
|
+
params.push(updates.sessionId);
|
|
225
|
+
}
|
|
226
|
+
const smartConditionChanged = existing.type === "smart" && updates.surfaceCondition !== undefined && updates.surfaceCondition !== existing.surfaceCondition;
|
|
227
|
+
if (updates.status !== undefined && !smartConditionChanged) {
|
|
228
|
+
sets.push("status = ?");
|
|
229
|
+
params.push(updates.status);
|
|
230
|
+
}
|
|
231
|
+
if (existing.type === "smart") {
|
|
232
|
+
if (updates.projectPath !== undefined) {
|
|
233
|
+
sets.push("project_path = ?");
|
|
234
|
+
params.push(updates.projectPath);
|
|
235
|
+
}
|
|
236
|
+
if (updates.surfaceCondition !== undefined) {
|
|
237
|
+
sets.push("surface_condition = ?");
|
|
238
|
+
params.push(updates.surfaceCondition);
|
|
239
|
+
}
|
|
240
|
+
if (smartConditionChanged) {
|
|
241
|
+
sets.push("status = 'pending'", "last_checked_at = NULL", "ready_at = NULL", "ready_reason = NULL");
|
|
242
|
+
sets.push("compiled_provider = ?", "compiled_config = ?", "compiled_at = ?", "compile_status = ?");
|
|
243
|
+
params.push(updates.compiledProvider ?? null, updates.compiledConfig ?? null, updates.compiledAt ?? null, updates.compileStatus ?? null);
|
|
244
|
+
if (noteCheckColumnsExist(db)) {
|
|
245
|
+
sets.push("compiled_check = NULL", "manifest_json = NULL", "check_hash = NULL", "check_cron = NULL", "check_version = 0", "check_status = 'uncompiled'", "check_failure_count = 0", "check_network_failure_count = 0", "check_quarantined_until = NULL", "check_next_due_at = NULL", "check_compiled_at = NULL", "check_false_since_at = NULL", "check_last_liveness_at = NULL");
|
|
246
|
+
}
|
|
247
|
+
} else {
|
|
248
|
+
if (updates.lastCheckedAt !== undefined) {
|
|
249
|
+
sets.push("last_checked_at = ?");
|
|
250
|
+
params.push(updates.lastCheckedAt);
|
|
251
|
+
}
|
|
252
|
+
if (updates.readyAt !== undefined) {
|
|
253
|
+
sets.push("ready_at = ?");
|
|
254
|
+
params.push(updates.readyAt);
|
|
255
|
+
}
|
|
256
|
+
if (updates.readyReason !== undefined) {
|
|
257
|
+
sets.push("ready_reason = ?");
|
|
258
|
+
params.push(updates.readyReason);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
if (sets.length === 1) {
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
265
|
+
params.push(noteId);
|
|
266
|
+
const result = db.prepare(`UPDATE notes SET ${sets.join(", ")} WHERE id = ? RETURNING *`).get(...params);
|
|
267
|
+
return isNoteRow(result) ? toNote(result) : null;
|
|
268
|
+
}
|
|
269
|
+
function dismissNotes(db, noteIds, scope) {
|
|
270
|
+
const now = Date.now();
|
|
271
|
+
return db.transaction(() => noteIds.map((noteId) => {
|
|
272
|
+
const existing = getNoteById(db, noteId);
|
|
273
|
+
if (!existing)
|
|
274
|
+
return { noteId, outcome: "not_found" };
|
|
275
|
+
if (!noteBelongsToScope(existing, scope)) {
|
|
276
|
+
return { noteId, outcome: "not_owned" };
|
|
277
|
+
}
|
|
278
|
+
if (existing.status === "dismissed") {
|
|
279
|
+
return { noteId, outcome: "already_dismissed" };
|
|
280
|
+
}
|
|
281
|
+
const result = db.prepare("UPDATE notes SET status = 'dismissed', updated_at = ? WHERE id = ? AND status != 'dismissed'").run(now, noteId);
|
|
282
|
+
return {
|
|
283
|
+
noteId,
|
|
284
|
+
outcome: result.changes > 0 ? "dismissed" : "already_dismissed"
|
|
285
|
+
};
|
|
286
|
+
})).immediate();
|
|
287
|
+
}
|
|
288
|
+
function dismissNote(db, noteId, scope) {
|
|
289
|
+
return dismissNotes(db, [noteId], scope)[0]?.outcome === "dismissed";
|
|
290
|
+
}
|
|
291
|
+
function markNoteReady(db, noteId, reason) {
|
|
292
|
+
const now = Date.now();
|
|
293
|
+
db.prepare("UPDATE notes SET status = 'ready', ready_at = ?, ready_reason = ?, updated_at = ?, last_checked_at = ? WHERE id = ? AND type = 'smart'").run(now, reason ?? null, now, now, noteId);
|
|
294
|
+
}
|
|
295
|
+
function markNoteChecked(db, noteId) {
|
|
296
|
+
const now = Date.now();
|
|
297
|
+
db.prepare("UPDATE notes SET last_checked_at = ?, updated_at = ? WHERE id = ? AND type = 'smart'").run(now, now, noteId);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// src/features/magic-context/storage-primers.ts
|
|
301
|
+
var PRIMER_CANDIDATE_TTL_MS = 90 * 24 * 60 * 60 * 1000;
|
|
302
|
+
var PRIMER_CANDIDATE_MAX_AGE_MS = 180 * 24 * 60 * 60 * 1000;
|
|
303
|
+
function normalizePrimerQuestion(question) {
|
|
304
|
+
return question.trim().toLowerCase().replace(/[“”]/g, '"').replace(/[’]/g, "'").replace(/\s+/g, " ").replace(/[?.!]+$/g, "").trim();
|
|
305
|
+
}
|
|
306
|
+
function primerOccurrenceKey(candidate) {
|
|
307
|
+
return [
|
|
308
|
+
candidate.projectPath,
|
|
309
|
+
candidate.harness,
|
|
310
|
+
candidate.sessionId,
|
|
311
|
+
candidate.sourceStartMessageId,
|
|
312
|
+
candidate.sourceEndMessageId
|
|
313
|
+
].join("\x1F");
|
|
314
|
+
}
|
|
315
|
+
function primerOccurrenceUtcDay(sourceMessageTime) {
|
|
316
|
+
return new Date(sourceMessageTime).toISOString().slice(0, 10);
|
|
317
|
+
}
|
|
318
|
+
function vectorBlob(vector) {
|
|
319
|
+
if (!vector)
|
|
320
|
+
return null;
|
|
321
|
+
return new Uint8Array(vector.buffer, vector.byteOffset, vector.byteLength);
|
|
322
|
+
}
|
|
323
|
+
function blobToFloat32Array(value) {
|
|
324
|
+
if (!value)
|
|
325
|
+
return null;
|
|
326
|
+
const bytes = value instanceof ArrayBuffer ? new Uint8Array(value) : value;
|
|
327
|
+
return new Float32Array(bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength));
|
|
328
|
+
}
|
|
329
|
+
function parseCandidateIds(raw) {
|
|
330
|
+
if (!raw)
|
|
331
|
+
return [];
|
|
332
|
+
try {
|
|
333
|
+
const parsed = JSON.parse(raw);
|
|
334
|
+
return Array.isArray(parsed) ? parsed.filter((id) => typeof id === "number" && Number.isFinite(id)) : [];
|
|
335
|
+
} catch {
|
|
336
|
+
return [];
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
function parsePrimerSourceProvenance(raw) {
|
|
340
|
+
if (raw === null)
|
|
341
|
+
return null;
|
|
342
|
+
try {
|
|
343
|
+
const parsed = JSON.parse(raw);
|
|
344
|
+
if (!Array.isArray(parsed))
|
|
345
|
+
return null;
|
|
346
|
+
const provenance = [];
|
|
347
|
+
for (const value of parsed) {
|
|
348
|
+
if (!value || typeof value !== "object")
|
|
349
|
+
return null;
|
|
350
|
+
const source = value;
|
|
351
|
+
if (typeof source.candidate_id !== "number" || !Number.isFinite(source.candidate_id) || typeof source.project_path !== "string" || typeof source.harness !== "string" || typeof source.session_id !== "string" || source.source_compartment_start !== null && typeof source.source_compartment_start !== "number" || source.source_compartment_end !== null && typeof source.source_compartment_end !== "number" || typeof source.source_start_message_id !== "string" || typeof source.source_end_message_id !== "string") {
|
|
352
|
+
return null;
|
|
353
|
+
}
|
|
354
|
+
provenance.push({
|
|
355
|
+
candidateId: source.candidate_id,
|
|
356
|
+
projectPath: source.project_path,
|
|
357
|
+
harness: source.harness,
|
|
358
|
+
sessionId: source.session_id,
|
|
359
|
+
sourceCompartmentStart: source.source_compartment_start,
|
|
360
|
+
sourceCompartmentEnd: source.source_compartment_end,
|
|
361
|
+
sourceStartMessageId: source.source_start_message_id,
|
|
362
|
+
sourceEndMessageId: source.source_end_message_id
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
return provenance;
|
|
366
|
+
} catch {
|
|
367
|
+
return null;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
function loadPrimerSourceProvenance(db, candidateIds) {
|
|
371
|
+
const ids = [...new Set(candidateIds)].sort((a, b) => a - b);
|
|
372
|
+
if (ids.length === 0)
|
|
373
|
+
return [];
|
|
374
|
+
const placeholders = ids.map(() => "?").join(",");
|
|
375
|
+
const rows = db.prepare(`SELECT id, project_path, harness, session_id,
|
|
376
|
+
source_compartment_start, source_compartment_end,
|
|
377
|
+
source_start_message_id, source_end_message_id
|
|
378
|
+
FROM primer_candidates
|
|
379
|
+
WHERE id IN (${placeholders})
|
|
380
|
+
ORDER BY id ASC`).all(...ids);
|
|
381
|
+
return rows.map((row) => ({
|
|
382
|
+
candidateId: row.id,
|
|
383
|
+
projectPath: row.project_path,
|
|
384
|
+
harness: row.harness,
|
|
385
|
+
sessionId: row.session_id,
|
|
386
|
+
sourceCompartmentStart: row.source_compartment_start,
|
|
387
|
+
sourceCompartmentEnd: row.source_compartment_end,
|
|
388
|
+
sourceStartMessageId: row.source_start_message_id,
|
|
389
|
+
sourceEndMessageId: row.source_end_message_id
|
|
390
|
+
}));
|
|
391
|
+
}
|
|
392
|
+
function serializePrimerSourceProvenance(provenance, sourceCandidateIds) {
|
|
393
|
+
if (provenance.length === 0 && sourceCandidateIds.length > 0)
|
|
394
|
+
return null;
|
|
395
|
+
return JSON.stringify(provenance.map((source) => ({
|
|
396
|
+
candidate_id: source.candidateId,
|
|
397
|
+
project_path: source.projectPath,
|
|
398
|
+
harness: source.harness,
|
|
399
|
+
session_id: source.sessionId,
|
|
400
|
+
source_compartment_start: source.sourceCompartmentStart,
|
|
401
|
+
source_compartment_end: source.sourceCompartmentEnd,
|
|
402
|
+
source_start_message_id: source.sourceStartMessageId,
|
|
403
|
+
source_end_message_id: source.sourceEndMessageId
|
|
404
|
+
})));
|
|
405
|
+
}
|
|
406
|
+
function normalizedCandidateIds(candidateIds) {
|
|
407
|
+
return [...new Set(candidateIds)].sort((a, b) => a - b);
|
|
408
|
+
}
|
|
409
|
+
function toCandidate(row) {
|
|
410
|
+
return {
|
|
411
|
+
id: row.id,
|
|
412
|
+
projectPath: row.project_path,
|
|
413
|
+
harness: row.harness,
|
|
414
|
+
sessionId: row.session_id,
|
|
415
|
+
question: row.question,
|
|
416
|
+
normalizedQuestion: row.normalized_question,
|
|
417
|
+
sourceCompartmentStart: row.source_compartment_start,
|
|
418
|
+
sourceCompartmentEnd: row.source_compartment_end,
|
|
419
|
+
sourceStartMessageId: row.source_start_message_id,
|
|
420
|
+
sourceEndMessageId: row.source_end_message_id,
|
|
421
|
+
sourceMessageTime: row.source_message_time,
|
|
422
|
+
questionEmbedding: blobToFloat32Array(row.question_embedding),
|
|
423
|
+
questionEmbeddingModelId: row.question_embedding_model_id,
|
|
424
|
+
createdAt: row.created_at
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
function toPrimer(row) {
|
|
428
|
+
const status = row.status === "archived" ? "archived" : "active";
|
|
429
|
+
return {
|
|
430
|
+
id: row.id,
|
|
431
|
+
projectPath: row.project_path,
|
|
432
|
+
question: row.question,
|
|
433
|
+
questionEmbedding: blobToFloat32Array(row.question_embedding),
|
|
434
|
+
questionEmbeddingModelId: row.question_embedding_model_id,
|
|
435
|
+
answer: row.answer,
|
|
436
|
+
status,
|
|
437
|
+
totalSupport: row.total_support,
|
|
438
|
+
lastObservedAt: row.last_observed_at,
|
|
439
|
+
answerRefreshedAt: row.answer_refreshed_at,
|
|
440
|
+
sourceCandidateIds: parseCandidateIds(row.source_candidate_ids),
|
|
441
|
+
sourceProvenance: parsePrimerSourceProvenance(row.source_candidate_provenance),
|
|
442
|
+
createdAt: row.created_at,
|
|
443
|
+
updatedAt: row.updated_at
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
function insertPrimerCandidates(db, candidates) {
|
|
447
|
+
const ids = [];
|
|
448
|
+
const stmt = db.prepare(`
|
|
449
|
+
INSERT INTO primer_candidates (
|
|
450
|
+
project_path, harness, session_id, question, normalized_question,
|
|
451
|
+
source_compartment_start, source_compartment_end,
|
|
452
|
+
source_start_message_id, source_end_message_id, source_message_time,
|
|
453
|
+
question_embedding, question_embedding_model_id, created_at
|
|
454
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
455
|
+
ON CONFLICT(project_path, harness, session_id, source_start_message_id, source_end_message_id)
|
|
456
|
+
DO UPDATE SET
|
|
457
|
+
question = excluded.question,
|
|
458
|
+
normalized_question = excluded.normalized_question,
|
|
459
|
+
source_compartment_start = excluded.source_compartment_start,
|
|
460
|
+
source_compartment_end = excluded.source_compartment_end,
|
|
461
|
+
source_message_time = excluded.source_message_time,
|
|
462
|
+
question_embedding = COALESCE(excluded.question_embedding, primer_candidates.question_embedding),
|
|
463
|
+
question_embedding_model_id = COALESCE(excluded.question_embedding_model_id, primer_candidates.question_embedding_model_id),
|
|
464
|
+
created_at = MIN(primer_candidates.created_at, excluded.created_at)
|
|
465
|
+
`);
|
|
466
|
+
const select = db.prepare(`
|
|
467
|
+
SELECT id FROM primer_candidates
|
|
468
|
+
WHERE project_path = ? AND harness = ? AND session_id = ?
|
|
469
|
+
AND source_start_message_id = ? AND source_end_message_id = ?
|
|
470
|
+
`);
|
|
471
|
+
db.transaction(() => {
|
|
472
|
+
for (const candidate of candidates) {
|
|
473
|
+
const question = candidate.question.trim();
|
|
474
|
+
if (!question)
|
|
475
|
+
continue;
|
|
476
|
+
const normalized = candidate.normalizedQuestion ?? normalizePrimerQuestion(question);
|
|
477
|
+
stmt.run(candidate.projectPath, candidate.harness || "opencode", candidate.sessionId, question, normalized, candidate.sourceCompartmentStart ?? null, candidate.sourceCompartmentEnd ?? null, candidate.sourceStartMessageId, candidate.sourceEndMessageId, candidate.sourceMessageTime, vectorBlob(candidate.questionEmbedding), candidate.questionEmbeddingModelId ?? null, candidate.createdAt ?? Date.now());
|
|
478
|
+
const row = select.get(candidate.projectPath, candidate.harness || "opencode", candidate.sessionId, candidate.sourceStartMessageId, candidate.sourceEndMessageId);
|
|
479
|
+
if (typeof row?.id === "number")
|
|
480
|
+
ids.push(row.id);
|
|
481
|
+
}
|
|
482
|
+
}).immediate();
|
|
483
|
+
return ids;
|
|
484
|
+
}
|
|
485
|
+
function updatePrimerCandidateEmbedding(db, candidateId, vector, modelId) {
|
|
486
|
+
db.prepare("UPDATE primer_candidates SET question_embedding = ?, question_embedding_model_id = ? WHERE id = ?").run(vectorBlob(vector), modelId, candidateId);
|
|
487
|
+
}
|
|
488
|
+
function getPrimerCandidatesByIds(db, ids) {
|
|
489
|
+
if (ids.length === 0)
|
|
490
|
+
return [];
|
|
491
|
+
const placeholders = ids.map(() => "?").join(",");
|
|
492
|
+
const rows = db.prepare(`SELECT * FROM primer_candidates WHERE id IN (${placeholders})`).all(...ids);
|
|
493
|
+
return rows.map(toCandidate);
|
|
494
|
+
}
|
|
495
|
+
function getPrimerCandidatesForPromotion(db, projectPath, now = Date.now(), ttlMs = PRIMER_CANDIDATE_TTL_MS) {
|
|
496
|
+
const cutoff = now - ttlMs;
|
|
497
|
+
const rows = db.prepare(`SELECT * FROM primer_candidates
|
|
498
|
+
WHERE project_path = ? AND source_message_time >= ?
|
|
499
|
+
ORDER BY project_path ASC, harness ASC, session_id ASC, source_start_message_id ASC, source_end_message_id ASC, id ASC`).all(projectPath, cutoff);
|
|
500
|
+
return rows.map(toCandidate);
|
|
501
|
+
}
|
|
502
|
+
function countPrimerCandidatesForProject(db, projectPath) {
|
|
503
|
+
const row = db.prepare("SELECT COUNT(*) AS count FROM primer_candidates WHERE project_path = ?").get(projectPath);
|
|
504
|
+
return row?.count ?? 0;
|
|
505
|
+
}
|
|
506
|
+
function getActivePrimers(db, projectPath) {
|
|
507
|
+
const rows = db.prepare(`SELECT * FROM primers
|
|
508
|
+
WHERE project_path = ? AND status = 'active'
|
|
509
|
+
ORDER BY COALESCE(last_observed_at, created_at) DESC, id ASC`).all(projectPath);
|
|
510
|
+
return rows.map(toPrimer);
|
|
511
|
+
}
|
|
512
|
+
function createPrimer(db, input) {
|
|
513
|
+
return db.transaction(() => {
|
|
514
|
+
const now = input.now ?? Date.now();
|
|
515
|
+
const sourceCandidateIds = normalizedCandidateIds(input.sourceCandidateIds);
|
|
516
|
+
const sourceProvenance = loadPrimerSourceProvenance(db, sourceCandidateIds);
|
|
517
|
+
const info = db.prepare(`INSERT INTO primers (
|
|
518
|
+
project_path, question, question_embedding, question_embedding_model_id, answer,
|
|
519
|
+
status, total_support, last_observed_at, answer_refreshed_at,
|
|
520
|
+
source_candidate_ids, source_candidate_provenance, created_at, updated_at
|
|
521
|
+
) VALUES (?, ?, ?, ?, ?, 'active', ?, ?, NULL, ?, ?, ?, ?)`).run(input.projectPath, input.question, vectorBlob(input.questionEmbedding), input.questionEmbeddingModelId ?? null, input.answer ?? "", input.totalSupport, input.lastObservedAt, JSON.stringify(sourceCandidateIds), serializePrimerSourceProvenance(sourceProvenance, sourceCandidateIds), now, now);
|
|
522
|
+
return Number(info.lastInsertRowid);
|
|
523
|
+
}).immediate();
|
|
524
|
+
}
|
|
525
|
+
function updatePrimerSupport(db, input) {
|
|
526
|
+
db.transaction(() => {
|
|
527
|
+
const sourceCandidateIds = normalizedCandidateIds(input.sourceCandidateIds);
|
|
528
|
+
const allowedIds = new Set(sourceCandidateIds);
|
|
529
|
+
const existingRow = db.prepare("SELECT source_candidate_provenance FROM primers WHERE id = ?").get(input.primerId);
|
|
530
|
+
const provenanceByCandidateId = new Map;
|
|
531
|
+
for (const source of parsePrimerSourceProvenance(existingRow?.source_candidate_provenance ?? null) ?? []) {
|
|
532
|
+
if (allowedIds.has(source.candidateId)) {
|
|
533
|
+
provenanceByCandidateId.set(source.candidateId, source);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
for (const source of loadPrimerSourceProvenance(db, sourceCandidateIds)) {
|
|
537
|
+
provenanceByCandidateId.set(source.candidateId, source);
|
|
538
|
+
}
|
|
539
|
+
const sourceProvenance = [...provenanceByCandidateId.values()].sort((a, b) => a.candidateId - b.candidateId);
|
|
540
|
+
db.prepare(`UPDATE primers
|
|
541
|
+
SET question_embedding = COALESCE(?, question_embedding),
|
|
542
|
+
question_embedding_model_id = COALESCE(?, question_embedding_model_id),
|
|
543
|
+
total_support = ?,
|
|
544
|
+
last_observed_at = ?,
|
|
545
|
+
source_candidate_ids = ?,
|
|
546
|
+
source_candidate_provenance = ?,
|
|
547
|
+
updated_at = ?
|
|
548
|
+
WHERE id = ?`).run(vectorBlob(input.questionEmbedding), input.questionEmbeddingModelId ?? null, input.totalSupport, input.lastObservedAt, JSON.stringify(sourceCandidateIds), serializePrimerSourceProvenance(sourceProvenance, sourceCandidateIds), input.now ?? Date.now(), input.primerId);
|
|
549
|
+
}).immediate();
|
|
550
|
+
}
|
|
551
|
+
function updatePrimerAnswer(db, primerId, answer, refreshedAt = Date.now()) {
|
|
552
|
+
db.prepare("UPDATE primers SET answer = ?, answer_refreshed_at = ?, updated_at = ? WHERE id = ?").run(answer, refreshedAt, refreshedAt, primerId);
|
|
553
|
+
}
|
|
554
|
+
// src/features/magic-context/memory/promotion.ts
|
|
555
|
+
function isPromotableCategory(category) {
|
|
556
|
+
return PROMOTABLE_CATEGORIES.some((promotableCategory) => promotableCategory === category);
|
|
557
|
+
}
|
|
558
|
+
function resolveExpiresAt(category) {
|
|
559
|
+
const ttl = CATEGORY_DEFAULT_TTL[category];
|
|
560
|
+
return ttl === undefined ? null : Date.now() + ttl;
|
|
561
|
+
}
|
|
562
|
+
function promoteSessionFactsDurable(db, sessionId, projectPath, facts) {
|
|
563
|
+
const newMemoryRefs = [];
|
|
564
|
+
let factsPromoted = 0;
|
|
565
|
+
for (const fact of facts) {
|
|
566
|
+
if (!fact || typeof fact.category !== "string" || typeof fact.content !== "string" || fact.content.trim().length === 0) {
|
|
567
|
+
continue;
|
|
568
|
+
}
|
|
569
|
+
if (!isPromotableCategory(fact.category)) {
|
|
570
|
+
continue;
|
|
571
|
+
}
|
|
572
|
+
const normalizedHash = computeNormalizedHash(fact.content);
|
|
573
|
+
const existingMemory = getMemoryByHash2(db, projectPath, fact.category, normalizedHash);
|
|
574
|
+
if (existingMemory) {
|
|
575
|
+
updateMemorySeenCount2(db, existingMemory.id);
|
|
576
|
+
factsPromoted += 1;
|
|
577
|
+
continue;
|
|
578
|
+
}
|
|
579
|
+
const memoryInput = {
|
|
580
|
+
projectPath,
|
|
581
|
+
category: fact.category,
|
|
582
|
+
content: fact.content,
|
|
583
|
+
sourceSessionId: sessionId,
|
|
584
|
+
sourceType: "historian",
|
|
585
|
+
expiresAt: resolveExpiresAt(fact.category)
|
|
586
|
+
};
|
|
587
|
+
const memory = insertMemory2(db, memoryInput);
|
|
588
|
+
newMemoryRefs.push({ memoryId: memory.id, content: memory.content });
|
|
589
|
+
factsPromoted += 1;
|
|
590
|
+
}
|
|
591
|
+
return { newMemoryRefs, factsPromoted };
|
|
592
|
+
}
|
|
593
|
+
async function embedPromotedFacts(db, sessionId, projectPath, refs) {
|
|
594
|
+
for (const ref of refs) {
|
|
595
|
+
await embedAndStoreMemory(db, sessionId, projectPath, ref.memoryId, ref.content);
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
async function embedAndStoreMemory(db, sessionId, projectPath, memoryId, content) {
|
|
599
|
+
try {
|
|
600
|
+
const hashBeforeEmbed = getMemoryById2(db, memoryId)?.normalizedHash;
|
|
601
|
+
if (!hashBeforeEmbed) {
|
|
602
|
+
return;
|
|
603
|
+
}
|
|
604
|
+
const result = await embedTextForProject2(projectPath, content);
|
|
605
|
+
if (result) {
|
|
606
|
+
db.transaction(() => {
|
|
607
|
+
saveEmbeddingIfHashMatches(db, memoryId, result.vector, result.modelId, hashBeforeEmbed);
|
|
608
|
+
}).immediate();
|
|
609
|
+
}
|
|
610
|
+
} catch (error) {
|
|
611
|
+
sessionLog2(sessionId, `memory embedding failed for memory ${memoryId}:`, error);
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
// src/features/magic-context/memory/storage-memory-fts.ts
|
|
615
|
+
var DEFAULT_SEARCH_LIMIT = 10;
|
|
616
|
+
var searchStatements = new WeakMap;
|
|
617
|
+
var datedSearchStatements = new WeakMap;
|
|
618
|
+
var unionSearchStatements = new Map;
|
|
619
|
+
var datedUnionSearchStatements = new Map;
|
|
620
|
+
function getSearchStatement(db, dated = false) {
|
|
621
|
+
const statements = dated ? datedSearchStatements : searchStatements;
|
|
622
|
+
let stmt = statements.get(db);
|
|
623
|
+
if (!stmt) {
|
|
624
|
+
stmt = db.prepare(`SELECT ${getMemorySelectColumns2(db)} FROM memories_fts INNER JOIN memories ON memories.id = memories_fts.rowid WHERE memories.project_path = ? AND memories.status IN ('active', 'permanent') AND (memories.expires_at IS NULL OR memories.expires_at > ?)${dated ? " AND memories.created_at BETWEEN ? AND ?" : ""} AND memories_fts MATCH ? ORDER BY bm25(memories_fts), memories.updated_at DESC, memories.id ASC LIMIT ?`);
|
|
625
|
+
statements.set(db, stmt);
|
|
626
|
+
}
|
|
627
|
+
return stmt;
|
|
628
|
+
}
|
|
629
|
+
function getUnionSearchStatement(db, arity, dated = false) {
|
|
630
|
+
const statementRegistry = dated ? datedUnionSearchStatements : unionSearchStatements;
|
|
631
|
+
let statements = statementRegistry.get(arity);
|
|
632
|
+
if (!statements) {
|
|
633
|
+
statements = new WeakMap;
|
|
634
|
+
statementRegistry.set(arity, statements);
|
|
635
|
+
}
|
|
636
|
+
let stmt = statements.get(db);
|
|
637
|
+
if (!stmt) {
|
|
638
|
+
const placeholders = Array.from({ length: arity }, () => "?").join(", ");
|
|
639
|
+
stmt = db.prepare(`SELECT ${getMemorySelectColumns2(db)} FROM memories_fts INNER JOIN memories ON memories.id = memories_fts.rowid WHERE memories.project_path IN (${placeholders}) AND memories.status IN ('active', 'permanent') AND (memories.expires_at IS NULL OR memories.expires_at > ?)${dated ? " AND memories.created_at BETWEEN ? AND ?" : ""} AND memories_fts MATCH ? ORDER BY bm25(memories_fts), memories.updated_at DESC, memories.id ASC LIMIT ?`);
|
|
640
|
+
statements.set(db, stmt);
|
|
641
|
+
}
|
|
642
|
+
return stmt;
|
|
643
|
+
}
|
|
644
|
+
function uniqueProjectPaths(projectPaths) {
|
|
645
|
+
return [...new Set(projectPaths.filter((path) => path.length > 0))];
|
|
646
|
+
}
|
|
647
|
+
function relaxedFtsQuery(query) {
|
|
648
|
+
const tokens = [...new Set(query.match(/[\p{L}\p{N}_]+/gu) ?? [])].filter((token) => token.length > 2 || /\d/.test(token)).slice(0, 16);
|
|
649
|
+
return tokens.map((token) => `"${token.replace(/"/g, '""')}"`).join(" OR ");
|
|
650
|
+
}
|
|
651
|
+
function sanitizeFtsQuery(query) {
|
|
652
|
+
const tokens = query.replaceAll("\x00", " ").split(/\s+/).filter((token) => token.length > 0);
|
|
653
|
+
if (tokens.length === 0)
|
|
654
|
+
return "";
|
|
655
|
+
return tokens.map((token) => `"${token.replace(/"/g, '""')}"`).join(" ");
|
|
656
|
+
}
|
|
657
|
+
function searchMemoriesFTS(db, projectPath, query, limit = DEFAULT_SEARCH_LIMIT, dateRange = null) {
|
|
658
|
+
const trimmedQuery = query.trim();
|
|
659
|
+
if (trimmedQuery.length === 0 || limit <= 0) {
|
|
660
|
+
return [];
|
|
661
|
+
}
|
|
662
|
+
const sanitized = sanitizeFtsQuery(trimmedQuery);
|
|
663
|
+
if (sanitized.length === 0) {
|
|
664
|
+
return [];
|
|
665
|
+
}
|
|
666
|
+
let rows = getSearchStatement(db, dateRange !== null).all(projectPath, Date.now(), ...dateRange === null ? [] : [dateRange.from, dateRange.to], sanitized, limit).filter(isMemoryRow2);
|
|
667
|
+
if (rows.length === 0) {
|
|
668
|
+
const relaxed = relaxedFtsQuery(trimmedQuery);
|
|
669
|
+
if (relaxed)
|
|
670
|
+
rows = getSearchStatement(db, dateRange !== null).all(projectPath, Date.now(), ...dateRange === null ? [] : [dateRange.from, dateRange.to], relaxed, limit).filter(isMemoryRow2);
|
|
671
|
+
}
|
|
672
|
+
return rows.map(toMemory2);
|
|
673
|
+
}
|
|
674
|
+
function searchMemoriesFTSUnion(db, projectPaths, query, limit = DEFAULT_SEARCH_LIMIT, ownIdentities, shareCategories, dateRange = null) {
|
|
675
|
+
const identities = uniqueProjectPaths(projectPaths);
|
|
676
|
+
if (identities.length === 0)
|
|
677
|
+
return [];
|
|
678
|
+
const sharingFilter = buildWorkspaceMemorySqlFilter2({
|
|
679
|
+
identities,
|
|
680
|
+
ownIdentities,
|
|
681
|
+
shareCategories,
|
|
682
|
+
tableName: "memories",
|
|
683
|
+
includeClassificationFields: (() => {
|
|
684
|
+
const columns = db.prepare("PRAGMA table_info(memories)").all();
|
|
685
|
+
return columns.some((row) => row.name === "shareable") && columns.some((row) => row.name === "scope");
|
|
686
|
+
})()
|
|
687
|
+
});
|
|
688
|
+
if (identities.length === 1 && !sharingFilter.active) {
|
|
689
|
+
return searchMemoriesFTS(db, identities[0], query, limit, dateRange);
|
|
690
|
+
}
|
|
691
|
+
const trimmedQuery = query.trim();
|
|
692
|
+
if (trimmedQuery.length === 0 || limit <= 0)
|
|
693
|
+
return [];
|
|
694
|
+
const sanitized = sanitizeFtsQuery(trimmedQuery);
|
|
695
|
+
if (sanitized.length === 0)
|
|
696
|
+
return [];
|
|
697
|
+
let rows = sharingFilter.active ? db.prepare(`SELECT ${getMemorySelectColumns2(db)} FROM memories_fts INNER JOIN memories ON memories.id = memories_fts.rowid WHERE memories.project_path IN (${identities.map(() => "?").join(", ")}) AND memories.status IN ('active', 'permanent') AND (memories.expires_at IS NULL OR memories.expires_at > ?)${dateRange === null ? "" : " AND memories.created_at BETWEEN ? AND ?"} AND memories_fts MATCH ?${sharingFilter.clause} ORDER BY bm25(memories_fts), memories.updated_at DESC, memories.id ASC LIMIT ?`).all(...identities, Date.now(), ...dateRange === null ? [] : [dateRange.from, dateRange.to], sanitized, ...sharingFilter.params, limit).filter(isMemoryRow2) : getUnionSearchStatement(db, identities.length, dateRange !== null).all(...identities, Date.now(), ...dateRange === null ? [] : [dateRange.from, dateRange.to], sanitized, limit).filter(isMemoryRow2);
|
|
698
|
+
if (rows.length === 0) {
|
|
699
|
+
const relaxed = relaxedFtsQuery(trimmedQuery);
|
|
700
|
+
if (relaxed) {
|
|
701
|
+
rows = (sharingFilter.active ? db.prepare(`SELECT ${getMemorySelectColumns2(db)} FROM memories_fts INNER JOIN memories ON memories.id = memories_fts.rowid WHERE memories.project_path IN (${identities.map(() => "?").join(", ")}) AND memories.status IN ('active', 'permanent') AND (memories.expires_at IS NULL OR memories.expires_at > ?)${dateRange === null ? "" : " AND memories.created_at BETWEEN ? AND ?"} AND memories_fts MATCH ?${sharingFilter.clause} ORDER BY bm25(memories_fts), memories.updated_at DESC, memories.id ASC LIMIT ?`) : getUnionSearchStatement(db, identities.length, dateRange !== null)).all(...identities, Date.now(), ...dateRange === null ? [] : [dateRange.from, dateRange.to], relaxed, ...sharingFilter.params, limit).filter(isMemoryRow2);
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
return rows.map(toMemory2);
|
|
705
|
+
}
|
|
706
|
+
// src/features/magic-context/memory/storage-memory-verifications.ts
|
|
707
|
+
var MEMORY_VERIFICATION_SENTINEL = "";
|
|
708
|
+
function uniqueSortedFiles(files) {
|
|
709
|
+
return Array.from(new Set(files.filter((file) => file !== MEMORY_VERIFICATION_SENTINEL))).sort();
|
|
710
|
+
}
|
|
711
|
+
function recordMemoryMapping(db, memoryId, normalizedFiles, now, mappingOrigin = "mapper") {
|
|
712
|
+
const realFiles = uniqueSortedFiles(normalizedFiles);
|
|
713
|
+
const filesToWrite = realFiles.length > 0 ? realFiles : [MEMORY_VERIFICATION_SENTINEL];
|
|
714
|
+
db.prepare("DELETE FROM memory_verifications WHERE memory_id = ?").run(memoryId);
|
|
715
|
+
const insert = db.prepare("INSERT INTO memory_verifications (memory_id, file_path, verified_at, mapped_at, mapping_origin) VALUES (?, ?, 0, ?, ?)");
|
|
716
|
+
for (const file of filesToWrite) {
|
|
717
|
+
insert.run(memoryId, file, now, mappingOrigin);
|
|
718
|
+
}
|
|
719
|
+
return filesToWrite.length;
|
|
720
|
+
}
|
|
721
|
+
function recordMemoryVerifications(db, memoryId, normalizedFiles, now) {
|
|
722
|
+
const realFiles = uniqueSortedFiles(normalizedFiles);
|
|
723
|
+
const filesToWrite = realFiles.length > 0 ? realFiles : [MEMORY_VERIFICATION_SENTINEL];
|
|
724
|
+
db.prepare("DELETE FROM memory_verifications WHERE memory_id = ?").run(memoryId);
|
|
725
|
+
const insert = db.prepare("INSERT INTO memory_verifications (memory_id, file_path, verified_at, mapped_at, mapping_origin) VALUES (?, ?, ?, ?, 'mapper')");
|
|
726
|
+
for (const file of filesToWrite) {
|
|
727
|
+
insert.run(memoryId, file, now, now);
|
|
728
|
+
}
|
|
729
|
+
return filesToWrite.length;
|
|
730
|
+
}
|
|
731
|
+
function getUnmappedMemoryIds(db, memoryIds) {
|
|
732
|
+
const ids = Array.from(new Set(memoryIds.filter(Number.isInteger)));
|
|
733
|
+
if (ids.length === 0)
|
|
734
|
+
return [];
|
|
735
|
+
const rows = db.prepare("SELECT DISTINCT memory_id FROM memory_verifications WHERE memory_id IN (SELECT value FROM json_each(?))").all(JSON.stringify(ids));
|
|
736
|
+
const mapped = new Set(rows.map((r) => r.memory_id));
|
|
737
|
+
return ids.filter((id) => !mapped.has(id));
|
|
738
|
+
}
|
|
739
|
+
function clearMemoryVerifications(db, memoryId) {
|
|
740
|
+
db.prepare("DELETE FROM memory_verifications WHERE memory_id = ?").run(memoryId);
|
|
741
|
+
}
|
|
742
|
+
function getMemoryVerifications(db, memoryIds) {
|
|
743
|
+
const ids = Array.from(new Set(memoryIds.filter(Number.isInteger)));
|
|
744
|
+
const result = new Map;
|
|
745
|
+
if (ids.length === 0)
|
|
746
|
+
return result;
|
|
747
|
+
const rows = db.prepare(`SELECT memory_id, file_path, verified_at, mapped_at, mapping_origin
|
|
748
|
+
FROM memory_verifications
|
|
749
|
+
WHERE memory_id IN (SELECT value FROM json_each(?))
|
|
750
|
+
ORDER BY memory_id, file_path`).all(JSON.stringify(ids));
|
|
751
|
+
for (const row of rows) {
|
|
752
|
+
const existing = result.get(row.memory_id) ?? {
|
|
753
|
+
files: [],
|
|
754
|
+
hasSentinel: false,
|
|
755
|
+
mappingOrigin: "mapper",
|
|
756
|
+
verifiedAt: 0,
|
|
757
|
+
mappedAt: 0
|
|
758
|
+
};
|
|
759
|
+
if (row.file_path === MEMORY_VERIFICATION_SENTINEL) {
|
|
760
|
+
existing.hasSentinel = true;
|
|
761
|
+
} else if (!existing.files.includes(row.file_path)) {
|
|
762
|
+
existing.files.push(row.file_path);
|
|
763
|
+
}
|
|
764
|
+
if (row.mapping_origin === "host_rejected_fallback") {
|
|
765
|
+
existing.mappingOrigin = "host_rejected_fallback";
|
|
766
|
+
}
|
|
767
|
+
existing.verifiedAt = Math.max(existing.verifiedAt, row.verified_at);
|
|
768
|
+
existing.mappedAt = Math.max(existing.mappedAt, row.mapped_at ?? 0);
|
|
769
|
+
result.set(row.memory_id, existing);
|
|
770
|
+
}
|
|
771
|
+
for (const state of result.values()) {
|
|
772
|
+
state.files.sort();
|
|
773
|
+
}
|
|
774
|
+
return result;
|
|
775
|
+
}
|
|
776
|
+
// src/features/magic-context/memory/verification-paths.ts
|
|
777
|
+
import { execFile } from "node:child_process";
|
|
778
|
+
import { existsSync, realpathSync, statSync } from "node:fs";
|
|
779
|
+
import path from "node:path";
|
|
780
|
+
import { promisify } from "node:util";
|
|
781
|
+
var execFileAsync = promisify(execFile);
|
|
782
|
+
var GIT_TIMEOUT_MS = 1e4;
|
|
783
|
+
var defaultExecFileForVerificationPaths = async (file, args, options) => await execFileAsync(file, [...args], {
|
|
784
|
+
...options,
|
|
785
|
+
windowsHide: true
|
|
786
|
+
});
|
|
787
|
+
var execFileForVerificationPaths = defaultExecFileForVerificationPaths;
|
|
788
|
+
async function runGit(cwd, args) {
|
|
789
|
+
try {
|
|
790
|
+
const result = await execFileForVerificationPaths("git", args, {
|
|
791
|
+
cwd,
|
|
792
|
+
timeout: GIT_TIMEOUT_MS,
|
|
793
|
+
maxBuffer: 16 * 1024 * 1024,
|
|
794
|
+
encoding: "utf8",
|
|
795
|
+
windowsHide: true
|
|
796
|
+
});
|
|
797
|
+
return String(result.stdout);
|
|
798
|
+
} catch (error) {
|
|
799
|
+
if (error.killed || error.code === "ETIMEDOUT") {
|
|
800
|
+
throw new Error(`Git verification command git ${args.join(" ")} timed out after ${GIT_TIMEOUT_MS}ms`, {
|
|
801
|
+
cause: error
|
|
802
|
+
});
|
|
803
|
+
}
|
|
804
|
+
return null;
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
function toPosixPath(value) {
|
|
808
|
+
return value.split(path.sep).join("/");
|
|
809
|
+
}
|
|
810
|
+
function isWithin(root, candidate) {
|
|
811
|
+
const rel = path.relative(root, candidate);
|
|
812
|
+
return rel === "" || !rel.startsWith("..") && !path.isAbsolute(rel);
|
|
813
|
+
}
|
|
814
|
+
function safeRealpath(value) {
|
|
815
|
+
try {
|
|
816
|
+
return realpathSync.native(value);
|
|
817
|
+
} catch {
|
|
818
|
+
return null;
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
async function resolveGitTopLevel(cwd) {
|
|
822
|
+
const stdout = await runGit(cwd, ["rev-parse", "--show-toplevel"]);
|
|
823
|
+
const root = stdout?.trim();
|
|
824
|
+
return root ? safeRealpath(root) ?? path.resolve(root) : null;
|
|
825
|
+
}
|
|
826
|
+
async function readGitHead(cwd) {
|
|
827
|
+
const stdout = await runGit(cwd, ["rev-parse", "HEAD"]);
|
|
828
|
+
const head = stdout?.trim();
|
|
829
|
+
return head && /^[0-9a-f]{40}$/i.test(head) ? head : null;
|
|
830
|
+
}
|
|
831
|
+
async function readGitChangedFilesSince(cwd, revision, knownGitRoot) {
|
|
832
|
+
if (!/^[0-9a-f]{7,40}$/i.test(revision))
|
|
833
|
+
return null;
|
|
834
|
+
const gitRoot = knownGitRoot ?? await resolveGitTopLevel(cwd);
|
|
835
|
+
if (!gitRoot)
|
|
836
|
+
return null;
|
|
837
|
+
const stdout = await runGit(gitRoot, ["diff", "--name-only", "-z", revision]);
|
|
838
|
+
if (stdout === null)
|
|
839
|
+
return null;
|
|
840
|
+
return new Set(stdout.split("\x00").filter(Boolean));
|
|
841
|
+
}
|
|
842
|
+
async function readGitFileChangeTimesSince(cwd, sinceMs, knownGitRoot) {
|
|
843
|
+
const gitRoot = knownGitRoot ?? await resolveGitTopLevel(cwd);
|
|
844
|
+
if (!gitRoot)
|
|
845
|
+
return null;
|
|
846
|
+
const sinceSec = Math.max(0, Math.floor(sinceMs / 1000));
|
|
847
|
+
const stdout = await runGit(gitRoot, [
|
|
848
|
+
"log",
|
|
849
|
+
`--since=@${sinceSec}`,
|
|
850
|
+
"--name-only",
|
|
851
|
+
"--format=%ct"
|
|
852
|
+
]);
|
|
853
|
+
if (stdout === null)
|
|
854
|
+
return null;
|
|
855
|
+
const times = new Map;
|
|
856
|
+
let currentMs = 0;
|
|
857
|
+
for (const rawLine of stdout.split(`
|
|
858
|
+
`)) {
|
|
859
|
+
const line = rawLine.trimEnd();
|
|
860
|
+
if (line === "")
|
|
861
|
+
continue;
|
|
862
|
+
if (/^\d+$/.test(line)) {
|
|
863
|
+
currentMs = Number.parseInt(line, 10) * 1000;
|
|
864
|
+
continue;
|
|
865
|
+
}
|
|
866
|
+
if (currentMs > 0 && !times.has(line)) {
|
|
867
|
+
times.set(line, currentMs);
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
return times;
|
|
871
|
+
}
|
|
872
|
+
async function gitTrackedPath(gitRoot, repoRelativePath) {
|
|
873
|
+
const stdout = await runGit(gitRoot, [
|
|
874
|
+
"ls-files",
|
|
875
|
+
"-z",
|
|
876
|
+
"--full-name",
|
|
877
|
+
"--error-unmatch",
|
|
878
|
+
"--",
|
|
879
|
+
repoRelativePath
|
|
880
|
+
]);
|
|
881
|
+
const fallbackStdout = stdout === null ? await runGit(gitRoot, ["ls-files", "-z", "--full-name"]) : null;
|
|
882
|
+
if (stdout === null && fallbackStdout === null)
|
|
883
|
+
return null;
|
|
884
|
+
const matches = (stdout ?? fallbackStdout ?? "").split("\x00").filter(Boolean);
|
|
885
|
+
if (matches.length === 0)
|
|
886
|
+
return null;
|
|
887
|
+
return matches.find((match) => match === repoRelativePath) ?? matches.find((match) => match.toLowerCase() === repoRelativePath.toLowerCase()) ?? (matches.length === 1 ? matches[0] : null);
|
|
888
|
+
}
|
|
889
|
+
function verificationFileExists(baseRoot, filePath) {
|
|
890
|
+
if (!filePath || filePath === ".")
|
|
891
|
+
return false;
|
|
892
|
+
const root = path.resolve(baseRoot);
|
|
893
|
+
const candidate = path.resolve(root, filePath);
|
|
894
|
+
return isWithin(root, candidate) && existsSync(candidate);
|
|
895
|
+
}
|
|
896
|
+
async function normalizeVerificationFiles(args) {
|
|
897
|
+
const cwd = path.resolve(args.cwd);
|
|
898
|
+
const gitRoot = await resolveGitTopLevel(cwd);
|
|
899
|
+
const root = gitRoot ?? cwd;
|
|
900
|
+
const rootReal = safeRealpath(root) ?? root;
|
|
901
|
+
const warnings = [];
|
|
902
|
+
const normalized = [];
|
|
903
|
+
let trackedPaths;
|
|
904
|
+
for (const raw of args.files) {
|
|
905
|
+
const value = typeof raw === "string" ? raw.trim() : "";
|
|
906
|
+
if (!value) {
|
|
907
|
+
warnings.push("Skipped blank verification path.");
|
|
908
|
+
continue;
|
|
909
|
+
}
|
|
910
|
+
if (value === ".") {
|
|
911
|
+
warnings.push('Skipped verification path "." (repo/project root is not a file).');
|
|
912
|
+
continue;
|
|
913
|
+
}
|
|
914
|
+
const candidate = path.resolve(cwd, value);
|
|
915
|
+
const candidateReal = safeRealpath(candidate);
|
|
916
|
+
if (candidateReal && !isWithin(rootReal, candidateReal)) {
|
|
917
|
+
warnings.push(`Skipped verification path "${value}" because it resolves outside the project.`);
|
|
918
|
+
continue;
|
|
919
|
+
}
|
|
920
|
+
if (!candidateReal && !isWithin(path.resolve(root), candidate)) {
|
|
921
|
+
warnings.push(`Skipped verification path "${value}" because it escapes the project.`);
|
|
922
|
+
continue;
|
|
923
|
+
}
|
|
924
|
+
if (path.resolve(root) === candidate) {
|
|
925
|
+
warnings.push(`Skipped verification path "${value}" because it is the repo/project root.`);
|
|
926
|
+
continue;
|
|
927
|
+
}
|
|
928
|
+
if (existsSync(candidate)) {
|
|
929
|
+
try {
|
|
930
|
+
if (statSync(candidate).isDirectory()) {
|
|
931
|
+
warnings.push(`Skipped verification path "${value}" because it is a directory.`);
|
|
932
|
+
continue;
|
|
933
|
+
}
|
|
934
|
+
} catch {
|
|
935
|
+
warnings.push(`Skipped verification path "${value}" because it could not be inspected.`);
|
|
936
|
+
continue;
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
if (gitRoot) {
|
|
940
|
+
const repoRelative = toPosixPath(path.relative(gitRoot, candidateReal ?? candidate));
|
|
941
|
+
if (!repoRelative || repoRelative === "." || repoRelative.startsWith("../")) {
|
|
942
|
+
warnings.push(`Skipped verification path "${value}" because it is not inside the git repo.`);
|
|
943
|
+
continue;
|
|
944
|
+
}
|
|
945
|
+
if (!trackedPaths) {
|
|
946
|
+
let trackedOutput = null;
|
|
947
|
+
try {
|
|
948
|
+
trackedOutput = await runGit(gitRoot, ["ls-files", "-z", "--full-name"]);
|
|
949
|
+
} catch {}
|
|
950
|
+
trackedPaths = new Set(trackedOutput?.split("\x00").filter(Boolean) ?? []);
|
|
951
|
+
}
|
|
952
|
+
const tracked = trackedPaths.has(repoRelative) ? repoRelative : await gitTrackedPath(gitRoot, repoRelative);
|
|
953
|
+
if (!tracked) {
|
|
954
|
+
warnings.push(`Skipped verification path "${value}" because it is not a tracked git file.`);
|
|
955
|
+
continue;
|
|
956
|
+
}
|
|
957
|
+
if (candidateReal && tracked !== repoRelative) {
|
|
958
|
+
const realRelative = toPosixPath(path.relative(gitRoot, candidateReal));
|
|
959
|
+
if (realRelative !== tracked) {
|
|
960
|
+
warnings.push(`Skipped verification path "${value}" because it is not a tracked git file.`);
|
|
961
|
+
continue;
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
normalized.push(tracked);
|
|
965
|
+
} else {
|
|
966
|
+
if (!existsSync(candidate)) {
|
|
967
|
+
warnings.push(`Skipped verification path "${value}" because it does not exist.`);
|
|
968
|
+
continue;
|
|
969
|
+
}
|
|
970
|
+
const projectRelative = toPosixPath(path.relative(cwd, candidate));
|
|
971
|
+
if (!projectRelative || projectRelative === "." || projectRelative.startsWith("../")) {
|
|
972
|
+
warnings.push(`Skipped verification path "${value}" because it is not inside the project.`);
|
|
973
|
+
continue;
|
|
974
|
+
}
|
|
975
|
+
normalized.push(projectRelative);
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
return {
|
|
979
|
+
files: Array.from(new Set(normalized)).sort(),
|
|
980
|
+
warnings,
|
|
981
|
+
gitRoot
|
|
982
|
+
};
|
|
983
|
+
}
|
|
984
|
+
export { SESSION_NOTE_CONDITION_ERROR, getNoteByIdInScope, getNotes, addNote, getSessionNotes, getPendingSmartNotes, getReadySmartNotes, updateNote, dismissNotes, dismissNote, markNoteReady, markNoteChecked, PRIMER_CANDIDATE_TTL_MS, PRIMER_CANDIDATE_MAX_AGE_MS, primerOccurrenceKey, primerOccurrenceUtcDay, insertPrimerCandidates, updatePrimerCandidateEmbedding, getPrimerCandidatesByIds, getPrimerCandidatesForPromotion, countPrimerCandidatesForProject, getActivePrimers, createPrimer, updatePrimerSupport, updatePrimerAnswer, promoteSessionFactsDurable, embedPromotedFacts, relaxedFtsQuery, sanitizeFtsQuery, searchMemoriesFTS, searchMemoriesFTSUnion, recordMemoryMapping, recordMemoryVerifications, getUnmappedMemoryIds, clearMemoryVerifications, getMemoryVerifications, resolveGitTopLevel, readGitHead, readGitChangedFilesSince, readGitFileChangeTimesSince, verificationFileExists, normalizeVerificationFiles };
|