@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
|
@@ -1,628 +1,33 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "./
|
|
2
|
+
V2_MEMORY_CATEGORIES
|
|
3
|
+
} from "./server-fr0wbhdn.js";
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
} from "./
|
|
5
|
+
log2
|
|
6
|
+
} from "./server-5m3dt5r1.js";
|
|
7
7
|
import {
|
|
8
8
|
ensureColumn,
|
|
9
9
|
healAllNullColumns,
|
|
10
10
|
installV95PerfSchema
|
|
11
|
-
} from "./
|
|
11
|
+
} from "./server-52awr2mw.js";
|
|
12
12
|
import {
|
|
13
13
|
resolveOpenCodeDbPath,
|
|
14
14
|
openCodeDbPathExists,
|
|
15
15
|
getOpenCodeDbProbeDescriptions
|
|
16
|
-
} from "./
|
|
16
|
+
} from "./server-2ra6pwf3.js";
|
|
17
17
|
import {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
withoutSqliteTransformPass
|
|
21
|
-
} from "./index-wx8a6bw3.js";
|
|
18
|
+
Database2
|
|
19
|
+
} from "./server-kb9nn0a0.js";
|
|
22
20
|
import {
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
normalizeStoredProjectPath,
|
|
22
|
+
storedPathBelongsToIdentity
|
|
23
|
+
} from "./server-yczc713m.js";
|
|
25
24
|
import {
|
|
26
25
|
logSlowWriteTransaction
|
|
27
|
-
} from "./
|
|
28
|
-
|
|
29
|
-
// src/features/magic-context/memory/project-identity.ts
|
|
30
|
-
import { execFileSync } from "node:child_process";
|
|
31
|
-
import { createHash as createHash2 } from "node:crypto";
|
|
32
|
-
import { existsSync, realpathSync as realpathSync2, statSync } from "node:fs";
|
|
33
|
-
import { homedir } from "node:os";
|
|
34
|
-
import path3 from "node:path";
|
|
35
|
-
|
|
36
|
-
// src/features/magic-context/memory/project-identity-cache.ts
|
|
37
|
-
import { createHash } from "node:crypto";
|
|
38
|
-
import { readFileSync } from "node:fs";
|
|
39
|
-
import path2 from "node:path";
|
|
40
|
-
|
|
41
|
-
// src/shared/project-directory-key.ts
|
|
42
|
-
import { realpathSync } from "node:fs";
|
|
43
|
-
import path from "node:path";
|
|
44
|
-
function projectDirectoryKey(directory) {
|
|
45
|
-
const slashed = directory.replaceAll("\\", "/").replace(/^\/\/\?\/UNC\//i, "//").replace(/^\/\/\?\//, "");
|
|
46
|
-
if (/^[a-z]:\//i.test(slashed) || slashed.startsWith("//")) {
|
|
47
|
-
return path.win32.normalize(slashed).replaceAll("\\", "/").replace(/\/$/, "").toLowerCase();
|
|
48
|
-
}
|
|
49
|
-
return path.resolve(directory);
|
|
50
|
-
}
|
|
51
|
-
var realpathForCanonicalDirectory = (directory) => realpathSync.native(directory);
|
|
52
|
-
function canonicalProjectDirectory(directory) {
|
|
53
|
-
let resolved = directory;
|
|
54
|
-
try {
|
|
55
|
-
resolved = realpathForCanonicalDirectory(directory);
|
|
56
|
-
} catch {}
|
|
57
|
-
return projectDirectoryKey(resolved);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// src/features/magic-context/memory/project-identity-cache.ts
|
|
61
|
-
function cachePath(directory, storageDir = getMagicContextStorageDir()) {
|
|
62
|
-
const hash = createHash("sha256").update(projectDirectoryKey(directory)).digest("hex");
|
|
63
|
-
return path2.join(storageDir, "project-identities", `${hash}.json`);
|
|
64
|
-
}
|
|
65
|
-
function rememberGitIdentity(directory, identity) {
|
|
66
|
-
try {
|
|
67
|
-
const destination = cachePath(directory);
|
|
68
|
-
writeStorageFileAtomicSync(destination, JSON.stringify({ directory: projectDirectoryKey(directory), identity }));
|
|
69
|
-
} catch {}
|
|
70
|
-
}
|
|
71
|
-
function readRememberedGitIdentity(directory, storageDir) {
|
|
72
|
-
try {
|
|
73
|
-
const record = JSON.parse(readFileSync(cachePath(directory, storageDir), "utf8"));
|
|
74
|
-
if (record.directory === projectDirectoryKey(directory) && /^git:[0-9a-f]{7,64}$/.test(record.identity))
|
|
75
|
-
return record.identity;
|
|
76
|
-
} catch {}
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// src/features/magic-context/memory/project-identity.ts
|
|
81
|
-
var GIT_TIMEOUT_MS = 5000;
|
|
82
|
-
var TRANSIENT_FAILURE_COOLDOWN_MS = 5 * 60 * 1000;
|
|
83
|
-
var identityCache = new Map;
|
|
84
|
-
var linkedGitWorktreeCache = new Map;
|
|
85
|
-
var lastKnownGitIdentityCache = new Map;
|
|
86
|
-
var directoryFallbackCache = new Map;
|
|
87
|
-
var transientFailureCooldown = new Map;
|
|
88
|
-
var dubiousOwnershipFallbackDirectories = new Set;
|
|
89
|
-
var dubiousOwnershipLoggedDirectories = new Set;
|
|
90
|
-
var dubiousOwnershipWarnedDirectories = new Set;
|
|
91
|
-
var transientGitIdentityReuseLoggedDirectories = new Set;
|
|
92
|
-
var sessionIdentityCache = new Map;
|
|
93
|
-
var homeProjectPermission = false;
|
|
94
|
-
var homeProjectSkipLogged = false;
|
|
95
|
-
var pausedIdentityReasons = new Map;
|
|
96
|
-
var pausedIdentityLogged = new Set;
|
|
97
|
-
function setHomeProjectPermission(allowed) {
|
|
98
|
-
homeProjectPermission = allowed;
|
|
99
|
-
}
|
|
100
|
-
function shouldSkipHomeProjectMemory(directory) {
|
|
101
|
-
try {
|
|
102
|
-
assertProjectAllowed(directory, homeProjectPermission);
|
|
103
|
-
return false;
|
|
104
|
-
} catch (error) {
|
|
105
|
-
if (!(error instanceof ProjectIdentityError) || error.errorClass !== "home_project_disabled")
|
|
106
|
-
throw error;
|
|
107
|
-
if (!homeProjectSkipLogged) {
|
|
108
|
-
homeProjectSkipLogged = true;
|
|
109
|
-
log("[magic-context] home project memory disabled; skipping memory features");
|
|
110
|
-
}
|
|
111
|
-
return true;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
var execFileSyncForIdentity = execFileSync;
|
|
115
|
-
var userHomeDirectoryForIdentity = () => homedir();
|
|
116
|
-
var nowMs = () => Date.now();
|
|
117
|
-
var filesystemProbeObserverForTests;
|
|
118
|
-
|
|
119
|
-
class ProjectIdentityError extends Error {
|
|
120
|
-
errorClass;
|
|
121
|
-
rawDirectory;
|
|
122
|
-
constructor(errorClass, rawDirectory, message, cause) {
|
|
123
|
-
super(message);
|
|
124
|
-
this.name = "ProjectIdentityError";
|
|
125
|
-
this.errorClass = errorClass;
|
|
126
|
-
this.rawDirectory = rawDirectory;
|
|
127
|
-
if (cause) {
|
|
128
|
-
this.cause = cause;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
function asError(error) {
|
|
133
|
-
return error instanceof Error ? error : undefined;
|
|
134
|
-
}
|
|
135
|
-
function getErrorCode(error) {
|
|
136
|
-
if (error === null || typeof error !== "object" || !("code" in error)) {
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
const code = error.code;
|
|
140
|
-
return typeof code === "string" ? code : undefined;
|
|
141
|
-
}
|
|
142
|
-
function getErrorSignal(error) {
|
|
143
|
-
if (error === null || typeof error !== "object" || !("signal" in error)) {
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
const signal = error.signal;
|
|
147
|
-
return typeof signal === "string" ? signal : undefined;
|
|
148
|
-
}
|
|
149
|
-
function getErrorKilled(error) {
|
|
150
|
-
if (error === null || typeof error !== "object" || !("killed" in error)) {
|
|
151
|
-
return false;
|
|
152
|
-
}
|
|
153
|
-
return error.killed === true;
|
|
154
|
-
}
|
|
155
|
-
function getErrorStderr(error) {
|
|
156
|
-
if (error === null || typeof error !== "object" || !("stderr" in error)) {
|
|
157
|
-
return "";
|
|
158
|
-
}
|
|
159
|
-
const stderr = error.stderr;
|
|
160
|
-
if (typeof stderr === "string") {
|
|
161
|
-
return stderr;
|
|
162
|
-
}
|
|
163
|
-
if (Buffer.isBuffer(stderr)) {
|
|
164
|
-
return stderr.toString("utf8");
|
|
165
|
-
}
|
|
166
|
-
return "";
|
|
167
|
-
}
|
|
168
|
-
function directoryFallback(directory) {
|
|
169
|
-
const canonical = path3.resolve(directory);
|
|
170
|
-
const hash = createHash2("md5").update(canonical, "utf8").digest("hex").slice(0, 12);
|
|
171
|
-
return `dir:${hash}`;
|
|
172
|
-
}
|
|
173
|
-
function rememberedIdentityOrDirectoryFallback(canonical) {
|
|
174
|
-
return readRememberedGitIdentity(canonical) ?? directoryFallback(canonical);
|
|
175
|
-
}
|
|
176
|
-
function assertDirectoryUsable(canonicalDirectory, rawDirectory) {
|
|
177
|
-
try {
|
|
178
|
-
const stat = statSync(canonicalDirectory);
|
|
179
|
-
if (!stat.isDirectory()) {
|
|
180
|
-
throw new ProjectIdentityError("unknown", rawDirectory, `Project path is not a directory: ${canonicalDirectory}`);
|
|
181
|
-
}
|
|
182
|
-
} catch (error) {
|
|
183
|
-
if (error instanceof ProjectIdentityError) {
|
|
184
|
-
throw error;
|
|
185
|
-
}
|
|
186
|
-
const code = getErrorCode(error);
|
|
187
|
-
if (code === "EACCES" || code === "EPERM") {
|
|
188
|
-
throw new ProjectIdentityError("permission_denied", rawDirectory, `Permission denied while accessing project directory: ${canonicalDirectory}`, asError(error));
|
|
189
|
-
}
|
|
190
|
-
throw new ProjectIdentityError("unknown", rawDirectory, `Unable to access project directory: ${canonicalDirectory}`, asError(error));
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
function isGitTimeoutError(error) {
|
|
194
|
-
const code = getErrorCode(error);
|
|
195
|
-
const signal = getErrorSignal(error);
|
|
196
|
-
return code === "ETIMEDOUT" || signal === "SIGTERM" || signal === "SIGKILL" || getErrorKilled(error);
|
|
197
|
-
}
|
|
198
|
-
function hasUnbornHead(directory) {
|
|
199
|
-
const options = {
|
|
200
|
-
cwd: directory,
|
|
201
|
-
encoding: "utf8",
|
|
202
|
-
env: { ...process.env, LC_ALL: "C", LANG: "C" },
|
|
203
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
204
|
-
timeout: GIT_TIMEOUT_MS,
|
|
205
|
-
windowsHide: true
|
|
206
|
-
};
|
|
207
|
-
try {
|
|
208
|
-
execFileSyncForIdentity("git", ["rev-parse", "--git-dir"], options);
|
|
209
|
-
try {
|
|
210
|
-
execFileSyncForIdentity("git", ["rev-parse", "--verify", "--quiet", "HEAD"], options);
|
|
211
|
-
return false;
|
|
212
|
-
} catch (error) {
|
|
213
|
-
return !isGitTimeoutError(error) && typeof error === "object" && error !== null && "status" in error && error.status === 1 && getErrorStderr(error) === "";
|
|
214
|
-
}
|
|
215
|
-
} catch {
|
|
216
|
-
return false;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
function classifyGitError(error, rawDirectory) {
|
|
220
|
-
if (isGitTimeoutError(error)) {
|
|
221
|
-
return new ProjectIdentityError("git_timeout", rawDirectory, `git rev-list timed out after ${GIT_TIMEOUT_MS}ms`, asError(error));
|
|
222
|
-
}
|
|
223
|
-
const code = getErrorCode(error);
|
|
224
|
-
if (code === "ENOENT") {
|
|
225
|
-
return new ProjectIdentityError("git_missing", rawDirectory, "git binary is not available in PATH", asError(error));
|
|
226
|
-
}
|
|
227
|
-
if (code === "EACCES" || code === "EPERM") {
|
|
228
|
-
return new ProjectIdentityError("permission_denied", rawDirectory, "Permission denied while spawning git", asError(error));
|
|
229
|
-
}
|
|
230
|
-
const stderr = getErrorStderr(error).toLowerCase();
|
|
231
|
-
if (stderr.includes("detected dubious ownership")) {
|
|
232
|
-
return new ProjectIdentityError("dubious_ownership", rawDirectory, "git refused to read the repository because it detected dubious ownership", asError(error));
|
|
233
|
-
}
|
|
234
|
-
if (stderr.includes("not a git repository") || stderr.includes("does not have any commits yet") || stderr.includes("ambiguous argument 'head'") || stderr.includes("unknown revision or path")) {
|
|
235
|
-
return new ProjectIdentityError("not_git_repo", rawDirectory, "Directory has no git root commit; caller may use directory fallback", asError(error));
|
|
236
|
-
}
|
|
237
|
-
return new ProjectIdentityError("unknown", rawDirectory, "git rev-list failed while resolving project identity", asError(error));
|
|
238
|
-
}
|
|
239
|
-
function resolveProjectIdentityStrict(directory, allowHomeProject = homeProjectPermission) {
|
|
240
|
-
assertProjectAllowed(directory, allowHomeProject);
|
|
241
|
-
const canonical = path3.resolve(directory);
|
|
242
|
-
const cached = identityCache.get(canonical);
|
|
243
|
-
if (cached !== undefined) {
|
|
244
|
-
return cached;
|
|
245
|
-
}
|
|
246
|
-
assertDirectoryUsable(canonical, directory);
|
|
247
|
-
if (!hasGitDir(canonical)) {
|
|
248
|
-
throw new ProjectIdentityError("not_git_repo", directory, "Directory has no git metadata; caller may use directory fallback");
|
|
249
|
-
}
|
|
250
|
-
let output;
|
|
251
|
-
try {
|
|
252
|
-
output = execFileSyncForIdentity("git", ["rev-list", "--max-parents=0", "HEAD"], {
|
|
253
|
-
cwd: canonical,
|
|
254
|
-
encoding: "utf8",
|
|
255
|
-
env: { ...process.env, LC_ALL: "C", LANG: "C" },
|
|
256
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
257
|
-
timeout: GIT_TIMEOUT_MS,
|
|
258
|
-
windowsHide: true
|
|
259
|
-
});
|
|
260
|
-
} catch (error) {
|
|
261
|
-
const classified = classifyGitError(error, directory);
|
|
262
|
-
if (classified.errorClass === "not_git_repo" && hasUnbornHead(canonical)) {
|
|
263
|
-
throw new ProjectIdentityError("no_commits", directory, "Git repository has no commits yet");
|
|
264
|
-
}
|
|
265
|
-
throw classified;
|
|
266
|
-
}
|
|
267
|
-
const rootCommit = output.split(`
|
|
268
|
-
`).map((line) => line.trim().slice(0, 64)).filter((line) => /^[0-9a-f]{7,64}$/.test(line)).sort()[0];
|
|
269
|
-
if (!rootCommit) {
|
|
270
|
-
throw new ProjectIdentityError("unknown", directory, "git rev-list returned no valid root commit hash");
|
|
271
|
-
}
|
|
272
|
-
const identity = `git:${rootCommit}`;
|
|
273
|
-
identityCache.set(canonical, identity);
|
|
274
|
-
lastKnownGitIdentityCache.set(canonical, identity);
|
|
275
|
-
rememberGitIdentity(canonical, identity);
|
|
276
|
-
const root = gitRootDirectory(canonical);
|
|
277
|
-
if (root && root !== canonical)
|
|
278
|
-
rememberGitIdentity(root, identity);
|
|
279
|
-
transientFailureCooldown.delete(canonical);
|
|
280
|
-
dubiousOwnershipFallbackDirectories.delete(canonical);
|
|
281
|
-
transientGitIdentityReuseLoggedDirectories.delete(canonical);
|
|
282
|
-
return identity;
|
|
283
|
-
}
|
|
284
|
-
function shouldUseDirectoryFallback(error) {
|
|
285
|
-
return error.errorClass !== "home_project_disabled";
|
|
286
|
-
}
|
|
287
|
-
function getActiveCooldown(canonical) {
|
|
288
|
-
const until = transientFailureCooldown.get(canonical);
|
|
289
|
-
if (until === undefined)
|
|
290
|
-
return;
|
|
291
|
-
if (nowMs() < until)
|
|
292
|
-
return until;
|
|
293
|
-
transientFailureCooldown.delete(canonical);
|
|
294
|
-
return;
|
|
295
|
-
}
|
|
296
|
-
function lastKnownGitIdentity(canonical) {
|
|
297
|
-
return lastKnownGitIdentityCache.get(canonical) ?? identityCache.get(canonical) ?? readRememberedGitIdentity(canonical);
|
|
298
|
-
}
|
|
299
|
-
function nearestLastKnownGitIdentity(canonical) {
|
|
300
|
-
const visited = new Set;
|
|
301
|
-
const walk = (start) => {
|
|
302
|
-
let current = start;
|
|
303
|
-
while (!visited.has(current)) {
|
|
304
|
-
visited.add(current);
|
|
305
|
-
const cached = lastKnownGitIdentity(current);
|
|
306
|
-
if (cached !== undefined)
|
|
307
|
-
return { identity: cached, source: current };
|
|
308
|
-
if (existsSync(path3.join(current, ".git")))
|
|
309
|
-
break;
|
|
310
|
-
const parent = path3.dirname(current);
|
|
311
|
-
if (parent === current)
|
|
312
|
-
break;
|
|
313
|
-
current = parent;
|
|
314
|
-
}
|
|
315
|
-
return;
|
|
316
|
-
};
|
|
317
|
-
const exactOrAncestor = walk(canonical);
|
|
318
|
-
if (exactOrAncestor)
|
|
319
|
-
return exactOrAncestor;
|
|
320
|
-
try {
|
|
321
|
-
const realCanonical = realpathSync2.native(canonical);
|
|
322
|
-
if (realCanonical !== canonical)
|
|
323
|
-
return walk(realCanonical);
|
|
324
|
-
} catch {}
|
|
325
|
-
return;
|
|
326
|
-
}
|
|
327
|
-
function reuseLastKnownGitIdentity(canonical) {
|
|
328
|
-
const cached = nearestLastKnownGitIdentity(canonical);
|
|
329
|
-
if (cached === undefined)
|
|
330
|
-
return;
|
|
331
|
-
if (!transientGitIdentityReuseLoggedDirectories.has(canonical)) {
|
|
332
|
-
transientGitIdentityReuseLoggedDirectories.add(canonical);
|
|
333
|
-
const sourceNote = cached.source === canonical ? "" : ` from ancestor ${cached.source}`;
|
|
334
|
-
log(`[magic-context] git identity resolution is temporarily unavailable for ${canonical}; reusing the last successful project identity${sourceNote} to avoid splitting project-scoped memory`);
|
|
335
|
-
}
|
|
336
|
-
return cached.identity;
|
|
337
|
-
}
|
|
338
|
-
function formatDubiousOwnershipWarning(canonical) {
|
|
339
|
-
return `Magic Context: git refused to read ${canonical} (dubious ownership — the repo is owned by a different user). Memory features are paused unless a previous git identity is available. Fix: git config --global --add safe.directory ${canonical}`;
|
|
340
|
-
}
|
|
341
|
-
function recordDubiousOwnershipFallback(canonical) {
|
|
342
|
-
dubiousOwnershipFallbackDirectories.add(canonical);
|
|
343
|
-
if (dubiousOwnershipLoggedDirectories.has(canonical))
|
|
344
|
-
return;
|
|
345
|
-
dubiousOwnershipLoggedDirectories.add(canonical);
|
|
346
|
-
log(`[magic-context] ${formatDubiousOwnershipWarning(canonical)}`);
|
|
347
|
-
}
|
|
348
|
-
function takeDubiousOwnershipProjectIdentityWarning(directory) {
|
|
349
|
-
const canonical = path3.resolve(directory);
|
|
350
|
-
if (!dubiousOwnershipFallbackDirectories.has(canonical))
|
|
351
|
-
return null;
|
|
352
|
-
if (dubiousOwnershipWarnedDirectories.has(canonical))
|
|
353
|
-
return null;
|
|
354
|
-
dubiousOwnershipWarnedDirectories.add(canonical);
|
|
355
|
-
return formatDubiousOwnershipWarning(canonical);
|
|
356
|
-
}
|
|
357
|
-
function canonicalUserHomeDirectory() {
|
|
358
|
-
const homeDirectory = userHomeDirectoryForIdentity();
|
|
359
|
-
try {
|
|
360
|
-
return realpathSync2.native(homeDirectory);
|
|
361
|
-
} catch {
|
|
362
|
-
return homeDirectory;
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
function isUserHomeDirectory(directory) {
|
|
366
|
-
if (projectDirectoryKey(directory) === projectDirectoryKey(userHomeDirectoryForIdentity()))
|
|
367
|
-
return true;
|
|
368
|
-
try {
|
|
369
|
-
return projectDirectoryKey(realpathSync2.native(path3.resolve(directory))) === projectDirectoryKey(canonicalUserHomeDirectory());
|
|
370
|
-
} catch {
|
|
371
|
-
return false;
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
function assertProjectAllowed(directory, allowHomeProject) {
|
|
375
|
-
const canonical = path3.resolve(directory);
|
|
376
|
-
if (!allowHomeProject && (isUserHomeDirectory(directory) || isUserHomeDirectory(gitRootDirectory(canonical) ?? canonical))) {
|
|
377
|
-
throw new ProjectIdentityError("home_project_disabled", directory, "Home project memory is disabled; set allow_home_project to opt in");
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
function resolveProjectIdentity(directory, allowHomeProject = homeProjectPermission) {
|
|
381
|
-
assertProjectAllowed(directory, allowHomeProject);
|
|
382
|
-
const canonical = path3.resolve(directory);
|
|
383
|
-
const cachedFallback = directoryFallbackCache.get(canonical);
|
|
384
|
-
if (cachedFallback !== undefined) {
|
|
385
|
-
if (!hasGitDir(canonical)) {
|
|
386
|
-
return cachedFallback;
|
|
387
|
-
}
|
|
388
|
-
directoryFallbackCache.delete(canonical);
|
|
389
|
-
}
|
|
390
|
-
if (getActiveCooldown(canonical) !== undefined) {
|
|
391
|
-
if (hasGitDir(canonical)) {
|
|
392
|
-
const cachedGitIdentity = reuseLastKnownGitIdentity(canonical);
|
|
393
|
-
if (cachedGitIdentity !== undefined) {
|
|
394
|
-
return cachedGitIdentity;
|
|
395
|
-
}
|
|
396
|
-
throw new ProjectIdentityError("git_identity_unavailable", directory, "Git identity unavailable; memory features paused until the retry cooldown expires");
|
|
397
|
-
}
|
|
398
|
-
return rememberedIdentityOrDirectoryFallback(canonical);
|
|
399
|
-
}
|
|
400
|
-
try {
|
|
401
|
-
return resolveProjectIdentityStrict(directory, allowHomeProject);
|
|
402
|
-
} catch (error) {
|
|
403
|
-
if (error instanceof ProjectIdentityError && shouldUseDirectoryFallback(error)) {
|
|
404
|
-
if (error.errorClass === "no_commits")
|
|
405
|
-
return directoryFallback(canonical);
|
|
406
|
-
if (!hasGitDir(canonical)) {
|
|
407
|
-
if (error.errorClass === "permission_denied")
|
|
408
|
-
throw error;
|
|
409
|
-
const resolved = rememberedIdentityOrDirectoryFallback(canonical);
|
|
410
|
-
directoryFallbackCache.set(canonical, resolved);
|
|
411
|
-
transientFailureCooldown.delete(canonical);
|
|
412
|
-
return resolved;
|
|
413
|
-
}
|
|
414
|
-
transientFailureCooldown.set(canonical, nowMs() + TRANSIENT_FAILURE_COOLDOWN_MS);
|
|
415
|
-
const cachedGitIdentity = reuseLastKnownGitIdentity(canonical);
|
|
416
|
-
if (error.errorClass === "dubious_ownership")
|
|
417
|
-
recordDubiousOwnershipFallback(canonical);
|
|
418
|
-
if (cachedGitIdentity !== undefined) {
|
|
419
|
-
return cachedGitIdentity;
|
|
420
|
-
}
|
|
421
|
-
throw error;
|
|
422
|
-
}
|
|
423
|
-
throw error;
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
function resolveProjectIdentityOrFallback(directory, allowHomeProject = homeProjectPermission) {
|
|
427
|
-
try {
|
|
428
|
-
return resolveProjectIdentity(directory, allowHomeProject);
|
|
429
|
-
} catch (error) {
|
|
430
|
-
const canonical = path3.resolve(directory);
|
|
431
|
-
if (hasGitDir(canonical) || error instanceof ProjectIdentityError && error.errorClass === "home_project_disabled")
|
|
432
|
-
throw error;
|
|
433
|
-
const fallback = rememberedIdentityOrDirectoryFallback(canonical);
|
|
434
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
435
|
-
log(`[magic-context] project identity resolution failed for ${canonical}; using directory fallback ${fallback}: ${message}`);
|
|
436
|
-
return fallback;
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
function hasGitDir(canonical) {
|
|
440
|
-
if (hasGitDirInAncestorChain(canonical)) {
|
|
441
|
-
return true;
|
|
442
|
-
}
|
|
443
|
-
try {
|
|
444
|
-
const realCanonical = realpathSync2.native(canonical);
|
|
445
|
-
return realCanonical !== canonical && hasGitDirInAncestorChain(realCanonical);
|
|
446
|
-
} catch {
|
|
447
|
-
return false;
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
function gitRootInAncestorChain(startDirectory) {
|
|
451
|
-
let current = startDirectory;
|
|
452
|
-
while (true) {
|
|
453
|
-
if (existsSync(path3.join(current, ".git"))) {
|
|
454
|
-
try {
|
|
455
|
-
return realpathSync2.native(current);
|
|
456
|
-
} catch {
|
|
457
|
-
return path3.resolve(current);
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
const parent = path3.dirname(current);
|
|
461
|
-
if (parent === current) {
|
|
462
|
-
return null;
|
|
463
|
-
}
|
|
464
|
-
current = parent;
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
function hasGitDirInAncestorChain(startDirectory) {
|
|
468
|
-
return gitRootInAncestorChain(startDirectory) !== null;
|
|
469
|
-
}
|
|
470
|
-
function gitRootDirectory(canonical) {
|
|
471
|
-
const direct = gitRootInAncestorChain(canonical);
|
|
472
|
-
if (direct)
|
|
473
|
-
return direct;
|
|
474
|
-
try {
|
|
475
|
-
const realCanonical = realpathSync2.native(canonical);
|
|
476
|
-
return realCanonical === canonical ? null : gitRootInAncestorChain(realCanonical);
|
|
477
|
-
} catch {
|
|
478
|
-
return null;
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
function directoryHasGitMetadata(directory) {
|
|
482
|
-
return gitRootDirectory(path3.resolve(directory)) !== null;
|
|
483
|
-
}
|
|
484
|
-
function describeUnresolvedProjectIdentity(directory) {
|
|
485
|
-
const resolvedDirectory = path3.resolve(directory);
|
|
486
|
-
const canonicalHome = canonicalUserHomeDirectory();
|
|
487
|
-
const canonicalDirectory = (() => {
|
|
488
|
-
try {
|
|
489
|
-
return realpathSync2.native(resolvedDirectory);
|
|
490
|
-
} catch {
|
|
491
|
-
return resolvedDirectory;
|
|
492
|
-
}
|
|
493
|
-
})();
|
|
494
|
-
if (isUserHomeDirectory(directory) || gitRootDirectory(canonicalDirectory) === canonicalHome) {
|
|
495
|
-
return `this session runs in your home directory (${canonicalHome}), which Magic Context does not treat as a project. ` + "Start OpenCode inside a project folder, or set `allow_home_project: true` in the user-level " + "magic-context.jsonc (~/.config/cortexkit/) to give home sessions their own memory.";
|
|
496
|
-
}
|
|
497
|
-
if (hasGitDir(resolvedDirectory))
|
|
498
|
-
return `git identity resolution for ${resolvedDirectory} is temporarily unavailable. Memory features are paused; retry after git access recovers.`;
|
|
499
|
-
return `the session directory ${resolvedDirectory} could not be read as a project.`;
|
|
500
|
-
}
|
|
501
|
-
function isUsableProjectIdentity(identity) {
|
|
502
|
-
return typeof identity === "string" && identity.trim().length > 0;
|
|
503
|
-
}
|
|
504
|
-
function resolveProjectIdentityForSession(directory, allowHomeProject = homeProjectPermission) {
|
|
505
|
-
const resolvedDirectory = path3.resolve(directory);
|
|
506
|
-
const cacheKey = `${allowHomeProject ? "1" : "0"}\x00${resolvedDirectory}`;
|
|
507
|
-
const cached = sessionIdentityCache.get(cacheKey);
|
|
508
|
-
if (cached && (cached.revalidateAt === null || nowMs() < cached.revalidateAt) && !(cached.identity?.startsWith("dir:") && hasGitDir(resolvedDirectory))) {
|
|
509
|
-
return cached.identity;
|
|
510
|
-
}
|
|
511
|
-
sessionIdentityCache.delete(cacheKey);
|
|
512
|
-
filesystemProbeObserverForTests?.();
|
|
513
|
-
const canonicalDirectory = (() => {
|
|
514
|
-
try {
|
|
515
|
-
filesystemProbeObserverForTests?.();
|
|
516
|
-
return realpathSync2.native(resolvedDirectory);
|
|
517
|
-
} catch {
|
|
518
|
-
return resolvedDirectory;
|
|
519
|
-
}
|
|
520
|
-
})();
|
|
521
|
-
filesystemProbeObserverForTests?.();
|
|
522
|
-
const homeRoot = gitRootDirectory(canonicalDirectory);
|
|
523
|
-
const inheritsHomeRepository = homeRoot !== null && isUserHomeDirectory(homeRoot);
|
|
524
|
-
let identity;
|
|
525
|
-
if (!allowHomeProject && (isUserHomeDirectory(directory) || inheritsHomeRepository)) {
|
|
526
|
-
identity = undefined;
|
|
527
|
-
} else {
|
|
528
|
-
try {
|
|
529
|
-
identity = resolveProjectIdentityOrFallback(isUserHomeDirectory(directory) ? canonicalUserHomeDirectory() : directory, allowHomeProject);
|
|
530
|
-
} catch (error) {
|
|
531
|
-
if (!(error instanceof ProjectIdentityError))
|
|
532
|
-
throw error;
|
|
533
|
-
const reason = error.errorClass === "git_identity_unavailable" ? pausedIdentityReasons.get(resolvedDirectory) ?? error.errorClass : error.errorClass;
|
|
534
|
-
pausedIdentityReasons.set(resolvedDirectory, reason);
|
|
535
|
-
const logKey = `${resolvedDirectory}\x00${reason}`;
|
|
536
|
-
if (!pausedIdentityLogged.has(logKey)) {
|
|
537
|
-
pausedIdentityLogged.add(logKey);
|
|
538
|
-
log(`[magic-context] memory features paused for ${resolvedDirectory}: ${reason}`);
|
|
539
|
-
}
|
|
540
|
-
identity = undefined;
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
if (identity !== undefined)
|
|
544
|
-
pausedIdentityReasons.delete(resolvedDirectory);
|
|
545
|
-
sessionIdentityCache.set(cacheKey, {
|
|
546
|
-
identity,
|
|
547
|
-
revalidateAt: identity?.startsWith("git:") === true ? null : nowMs() + TRANSIENT_FAILURE_COOLDOWN_MS
|
|
548
|
-
});
|
|
549
|
-
return identity;
|
|
550
|
-
}
|
|
551
|
-
function normalizeStoredProjectPath(rawOrStored) {
|
|
552
|
-
if (rawOrStored.startsWith("git:") || rawOrStored.startsWith("dir:")) {
|
|
553
|
-
return rawOrStored;
|
|
554
|
-
}
|
|
555
|
-
try {
|
|
556
|
-
return resolveProjectIdentity(rawOrStored);
|
|
557
|
-
} catch {
|
|
558
|
-
return rawOrStored;
|
|
559
|
-
}
|
|
560
|
-
}
|
|
561
|
-
function storedPathBelongsToIdentity(storedProjectPath, projectIdentity) {
|
|
562
|
-
return storedProjectPath === projectIdentity || normalizeStoredProjectPath(storedProjectPath) === projectIdentity;
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
// src/plugin/boot-quiet.ts
|
|
566
|
-
var BOOT_QUIET_MS = 120000;
|
|
567
|
-
var bootQuietUntilMs = 0;
|
|
568
|
-
function beginBootQuietPeriod(now = Date.now()) {
|
|
569
|
-
if (bootQuietUntilMs === 0)
|
|
570
|
-
bootQuietUntilMs = now + BOOT_QUIET_MS;
|
|
571
|
-
}
|
|
572
|
-
function bootQuietRemainingMs(now = Date.now()) {
|
|
573
|
-
return Math.max(0, bootQuietUntilMs - now);
|
|
574
|
-
}
|
|
575
|
-
function scheduleAfterBootQuiet(task, additionalDelayMs = 0) {
|
|
576
|
-
const timer = setTimeout(task, bootQuietRemainingMs() + Math.max(0, additionalDelayMs));
|
|
577
|
-
timer.unref?.();
|
|
578
|
-
return timer;
|
|
579
|
-
}
|
|
26
|
+
} from "./server-aan4q8mx.js";
|
|
580
27
|
|
|
581
28
|
// src/features/magic-context/migrations.ts
|
|
582
29
|
import { isMainThread } from "node:worker_threads";
|
|
583
30
|
|
|
584
|
-
// src/features/magic-context/memory/constants.ts
|
|
585
|
-
var V2_MEMORY_CATEGORIES = [
|
|
586
|
-
"PROJECT_RULES",
|
|
587
|
-
"ARCHITECTURE",
|
|
588
|
-
"CONSTRAINTS",
|
|
589
|
-
"CONFIG_VALUES",
|
|
590
|
-
"NAMING"
|
|
591
|
-
];
|
|
592
|
-
var PROMOTABLE_CATEGORIES = [
|
|
593
|
-
...V2_MEMORY_CATEGORIES,
|
|
594
|
-
"ARCHITECTURE_DECISIONS",
|
|
595
|
-
"CONFIG_DEFAULTS",
|
|
596
|
-
"USER_PREFERENCES",
|
|
597
|
-
"USER_DIRECTIVES",
|
|
598
|
-
"ENVIRONMENT",
|
|
599
|
-
"WORKFLOW_RULES",
|
|
600
|
-
"KNOWN_ISSUES"
|
|
601
|
-
];
|
|
602
|
-
var CATEGORY_PRIORITY = [
|
|
603
|
-
...V2_MEMORY_CATEGORIES,
|
|
604
|
-
"USER_DIRECTIVES",
|
|
605
|
-
"USER_PREFERENCES",
|
|
606
|
-
"CONFIG_DEFAULTS",
|
|
607
|
-
"ARCHITECTURE_DECISIONS",
|
|
608
|
-
"ENVIRONMENT",
|
|
609
|
-
"WORKFLOW_RULES",
|
|
610
|
-
"KNOWN_ISSUES"
|
|
611
|
-
];
|
|
612
|
-
var MEMORY_CATEGORY_ORDER_UNKNOWN = 99;
|
|
613
|
-
var MEMORY_CATEGORY_ORDER_PRIORITY = CATEGORY_PRIORITY.reduce((acc, category, index) => {
|
|
614
|
-
acc[category] = index;
|
|
615
|
-
return acc;
|
|
616
|
-
}, {});
|
|
617
|
-
var MEMORY_CATEGORY_ORDER_SQL = `CASE category ${CATEGORY_PRIORITY.map((category, index) => `WHEN '${category}' THEN ${index}`).join(" ")} ELSE ${MEMORY_CATEGORY_ORDER_UNKNOWN} END`;
|
|
618
|
-
function getMemoryCategoryOrder(category) {
|
|
619
|
-
return MEMORY_CATEGORY_ORDER_PRIORITY[category] ?? MEMORY_CATEGORY_ORDER_UNKNOWN;
|
|
620
|
-
}
|
|
621
|
-
var CATEGORY_DEFAULT_TTL = {
|
|
622
|
-
WORKFLOW_RULES: 90 * 24 * 60 * 60 * 1000,
|
|
623
|
-
KNOWN_ISSUES: 30 * 24 * 60 * 60 * 1000
|
|
624
|
-
};
|
|
625
|
-
|
|
626
31
|
// src/shared/xml-unescape.ts
|
|
627
32
|
var XML_ENTITY_REGEX = /&(amp|apos|quot|lt|gt);/g;
|
|
628
33
|
var XML_ENTITIES = {
|
|
@@ -832,7 +237,7 @@ function parseCompartmentOutput(text) {
|
|
|
832
237
|
continue;
|
|
833
238
|
droppedFactBlocks++;
|
|
834
239
|
droppedFacts += items.length;
|
|
835
|
-
|
|
240
|
+
log2(`[historian] Dropped <facts> category ${category} (${items.length} facts)`);
|
|
836
241
|
continue;
|
|
837
242
|
}
|
|
838
243
|
for (const content of items)
|
|
@@ -916,7 +321,7 @@ function parseEvents(text) {
|
|
|
916
321
|
}
|
|
917
322
|
|
|
918
323
|
// src/features/magic-context/lkg-prefix-chunks.ts
|
|
919
|
-
import { createHash
|
|
324
|
+
import { createHash } from "node:crypto";
|
|
920
325
|
var LKG_PREFIX_CHUNK_CHARS = 64 * 1024;
|
|
921
326
|
function splitLkgPrefix(jsonPrefix) {
|
|
922
327
|
const chunks = [];
|
|
@@ -934,10 +339,10 @@ function splitLkgPrefix(jsonPrefix) {
|
|
|
934
339
|
return chunks;
|
|
935
340
|
}
|
|
936
341
|
function hashLkgChunk(body) {
|
|
937
|
-
return
|
|
342
|
+
return createHash("sha256").update(body).digest("hex");
|
|
938
343
|
}
|
|
939
344
|
function hashLkgChunkList(chunkHashes) {
|
|
940
|
-
return
|
|
345
|
+
return createHash("sha256").update(chunkHashes.join(`
|
|
941
346
|
`)).digest("hex");
|
|
942
347
|
}
|
|
943
348
|
function layoutLkgPrefix(jsonPrefix) {
|
|
@@ -1181,7 +586,7 @@ function collectCandidateSessions(db, shapes) {
|
|
|
1181
586
|
return [...sessions].sort();
|
|
1182
587
|
}
|
|
1183
588
|
function openEvidenceStore(path) {
|
|
1184
|
-
const store = new
|
|
589
|
+
const store = new Database2(path, { readonly: true, fileMustExist: true });
|
|
1185
590
|
try {
|
|
1186
591
|
const hasV1Messages = tableExists2(store, "message");
|
|
1187
592
|
const hasV1Session = tableExists2(store, "session");
|
|
@@ -1292,13 +697,13 @@ function repairOpenCode2HarnessLabels(db, options) {
|
|
|
1292
697
|
reason = "store_schema_unknown";
|
|
1293
698
|
} catch (error) {
|
|
1294
699
|
reason = "store_unreadable";
|
|
1295
|
-
|
|
700
|
+
log2(`[migration] OpenCode session database at ${resolution.path} could not be read: ${error instanceof Error ? error.message : String(error)}`);
|
|
1296
701
|
}
|
|
1297
702
|
}
|
|
1298
703
|
if (!evidence || reason !== null) {
|
|
1299
704
|
evidence?.close();
|
|
1300
705
|
writeUnresolvedState(db, reason ?? "store_not_found", resolution, candidateSessionIds);
|
|
1301
|
-
|
|
706
|
+
log2(`[migration] OpenCode harness labels left unverified for ${candidateSessionIds.length} session(s): ` + `no readable OpenCode session database (${reason ?? "store_not_found"}) at ${resolution.path}. ` + "Nothing was relabelled; `magic-context doctor` reports the affected sessions.");
|
|
1302
707
|
return {
|
|
1303
708
|
status: "unresolved",
|
|
1304
709
|
reason: reason ?? "store_not_found",
|
|
@@ -1332,7 +737,7 @@ function repairOpenCode2HarnessLabels(db, options) {
|
|
|
1332
737
|
clearUnresolvedState(db);
|
|
1333
738
|
if (relabelledSessions.length > 0) {
|
|
1334
739
|
const toOpenCode2 = relabelledSessions.filter((entry) => entry.harness === "opencode2").length;
|
|
1335
|
-
|
|
740
|
+
log2(`[migration] OpenCode harness labels repaired from ${resolution.path}: ` + `${toOpenCode2} session(s) restored to opencode2, ` + `${relabelledSessions.length - toOpenCode2} session(s) set to opencode.`);
|
|
1336
741
|
}
|
|
1337
742
|
return {
|
|
1338
743
|
status: "resolved",
|
|
@@ -1424,7 +829,7 @@ function installCompartmentHistoryVersions(db) {
|
|
|
1424
829
|
}
|
|
1425
830
|
|
|
1426
831
|
// src/features/magic-context/workspaces.ts
|
|
1427
|
-
import { createHash as
|
|
832
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
1428
833
|
var VALID_SHARE_CATEGORIES = new Set(V2_MEMORY_CATEGORIES);
|
|
1429
834
|
var DEFAULT_WORKSPACE_SHARE_CATEGORIES = ["CONSTRAINTS"];
|
|
1430
835
|
function tableExists3(db, tableName) {
|
|
@@ -1445,7 +850,7 @@ function defaultWorkspaceShareCategories() {
|
|
|
1445
850
|
return [...DEFAULT_WORKSPACE_SHARE_CATEGORIES];
|
|
1446
851
|
}
|
|
1447
852
|
function warnInvalidShareCategories(reason, raw) {
|
|
1448
|
-
|
|
853
|
+
log2("[magic-context] WARN: invalid workspace share_categories; sharing no foreign memory categories", {
|
|
1449
854
|
reason,
|
|
1450
855
|
raw
|
|
1451
856
|
});
|
|
@@ -1492,7 +897,7 @@ function selectWorkspaceShareCategories(db, identities) {
|
|
|
1492
897
|
if (!hasMembership)
|
|
1493
898
|
return null;
|
|
1494
899
|
if (!tableExists3(db, "workspaces")) {
|
|
1495
|
-
|
|
900
|
+
log2("[magic-context] WARN: workspace member has no workspaces table; sharing no foreign memory categories");
|
|
1496
901
|
return [];
|
|
1497
902
|
}
|
|
1498
903
|
if (!columnExists2(db, "workspaces", "share_categories")) {
|
|
@@ -1505,7 +910,7 @@ function selectWorkspaceShareCategories(db, identities) {
|
|
|
1505
910
|
ORDER BY workspace.id ASC
|
|
1506
911
|
LIMIT 1`).get(...candidates);
|
|
1507
912
|
if (!row) {
|
|
1508
|
-
|
|
913
|
+
log2("[magic-context] WARN: workspace member has no workspace share_categories row; sharing no foreign memory categories");
|
|
1509
914
|
return [];
|
|
1510
915
|
}
|
|
1511
916
|
return normalizeShareCategories(row.shareCategories);
|
|
@@ -1610,7 +1015,7 @@ function computeWorkspaceEpochFingerprint(db, identities) {
|
|
|
1610
1015
|
const canonical = uniqueSorted(identities.filter((identity) => identity.length > 0));
|
|
1611
1016
|
const epochs = getEpochMap(db, canonical);
|
|
1612
1017
|
const shareCategories = selectWorkspaceShareCategories(db, canonical);
|
|
1613
|
-
const hash =
|
|
1018
|
+
const hash = createHash2("sha256");
|
|
1614
1019
|
hash.update("share_categories", "utf8");
|
|
1615
1020
|
hash.update("\x00");
|
|
1616
1021
|
hash.update(shareCategories === null ? "NO_WORKSPACE" : JSON.stringify(shareCategories), "utf8");
|
|
@@ -2093,10 +1498,10 @@ var MIGRATIONS = [
|
|
|
2093
1498
|
const hasTable = (name) => Boolean(db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name = ?").get(name));
|
|
2094
1499
|
const memoryEmbeddings = hasTable("memory_embeddings") ? db.prepare(`DELETE FROM memory_embeddings
|
|
2095
1500
|
WHERE memory_id NOT IN (SELECT id FROM memories)`).run().changes : 0;
|
|
2096
|
-
|
|
1501
|
+
log2(`[migrations] v12 cleaned ${memoryEmbeddings} orphan memory_embeddings row(s)`);
|
|
2097
1502
|
const gitCommitEmbeddings = hasTable("git_commit_embeddings") ? db.prepare(`DELETE FROM git_commit_embeddings
|
|
2098
1503
|
WHERE sha NOT IN (SELECT sha FROM git_commits)`).run().changes : 0;
|
|
2099
|
-
|
|
1504
|
+
log2(`[migrations] v12 cleaned ${gitCommitEmbeddings} orphan git_commit_embeddings row(s)`);
|
|
2100
1505
|
}
|
|
2101
1506
|
},
|
|
2102
1507
|
{
|
|
@@ -4113,7 +3518,7 @@ function runMigrations(db) {
|
|
|
4113
3518
|
return false;
|
|
4114
3519
|
if (!loggedPlan) {
|
|
4115
3520
|
const pendingCount = MIGRATIONS.filter((candidate) => candidate.version > currentVersion && !isMigrationApplied(db, candidate.version)).length;
|
|
4116
|
-
|
|
3521
|
+
log2(`[migrations] current upstream migration lane: ${currentVersion}, applying ${pendingCount} migration(s)`);
|
|
4117
3522
|
loggedPlan = true;
|
|
4118
3523
|
}
|
|
4119
3524
|
if (isMainThread)
|
|
@@ -4128,13 +3533,13 @@ function runMigrations(db) {
|
|
|
4128
3533
|
break;
|
|
4129
3534
|
if (migration.version <= 61)
|
|
4130
3535
|
touchedLegacyAuthorityBatch = true;
|
|
4131
|
-
|
|
3536
|
+
log2(`[migrations] applied v${migration.version}: ${migration.description}`);
|
|
4132
3537
|
} catch (error) {
|
|
4133
3538
|
if (!migration && isSqliteLockError(error)) {
|
|
4134
3539
|
throw new MigrationLockBusyError(`failed to acquire migration write lock: ${error instanceof Error ? error.message : String(error)}`);
|
|
4135
3540
|
}
|
|
4136
3541
|
if (migration && isSiblingMigrationConflict(db, error, migration.version)) {
|
|
4137
|
-
|
|
3542
|
+
log2(`[migrations] v${migration.version} already applied by sibling instance — resuming with re-read version`);
|
|
4138
3543
|
const reReadVersion = getCurrentVersion(db);
|
|
4139
3544
|
if (reReadVersion > currentVersion)
|
|
4140
3545
|
continue;
|
|
@@ -4142,7 +3547,7 @@ function runMigrations(db) {
|
|
|
4142
3547
|
}
|
|
4143
3548
|
const version = migration?.version ?? currentVersion + 1;
|
|
4144
3549
|
const description = migration?.description ?? "acquire migration write lock";
|
|
4145
|
-
|
|
3550
|
+
log2(`[migrations] FAILED v${version}: ${description} — ${error instanceof Error ? error.message : String(error)}`);
|
|
4146
3551
|
throw new Error(`Migration v${version} failed: ${error instanceof Error ? error.message : String(error)}. Database may need manual repair.`);
|
|
4147
3552
|
}
|
|
4148
3553
|
}
|
|
@@ -4159,7 +3564,7 @@ function runMigrations(db) {
|
|
|
4159
3564
|
}
|
|
4160
3565
|
}
|
|
4161
3566
|
if (loggedPlan) {
|
|
4162
|
-
|
|
3567
|
+
log2(`[migrations] upstream migration lane now: ${MIGRATIONS[MIGRATIONS.length - 1].version}`);
|
|
4163
3568
|
}
|
|
4164
3569
|
}
|
|
4165
3570
|
async function runMigrationsWithRetry(db, options = {}) {
|
|
@@ -4167,7 +3572,7 @@ async function runMigrationsWithRetry(db, options = {}) {
|
|
|
4167
3572
|
const sleep = options.sleep ?? ((delayMs) => new Promise((resolve) => setTimeout(resolve, delayMs)));
|
|
4168
3573
|
const totalAttempts = retryDelaysMs.length + 1;
|
|
4169
3574
|
for (let attempt = 1;attempt <= totalAttempts; attempt += 1) {
|
|
4170
|
-
|
|
3575
|
+
log2(`[migrations] migration lock check attempt ${attempt}/${totalAttempts}`);
|
|
4171
3576
|
try {
|
|
4172
3577
|
runMigrations(db);
|
|
4173
3578
|
return;
|
|
@@ -4177,172 +3582,10 @@ async function runMigrationsWithRetry(db, options = {}) {
|
|
|
4177
3582
|
const delayMs = retryDelaysMs[attempt - 1];
|
|
4178
3583
|
if (delayMs === undefined)
|
|
4179
3584
|
throw error;
|
|
4180
|
-
|
|
3585
|
+
log2(`[migrations] migration write lock is busy; retrying attempt ${attempt + 1}/${totalAttempts} in ${delayMs}ms`);
|
|
4181
3586
|
await sleep(delayMs);
|
|
4182
3587
|
}
|
|
4183
3588
|
}
|
|
4184
3589
|
}
|
|
4185
3590
|
|
|
4186
|
-
|
|
4187
|
-
import { createHash as createHash5 } from "node:crypto";
|
|
4188
|
-
var MESSAGE_FTS_ROWID_MAP_BACKFILL_BATCH_SIZE = 100;
|
|
4189
|
-
var BACKFILL_STATE_ID = 1;
|
|
4190
|
-
var EMPTY_INDEX_CONTENT_HASH = createHash5("sha256").update("").digest("hex");
|
|
4191
|
-
var upsertMapStatements = new WeakMap;
|
|
4192
|
-
var rangeReadyStatements = new WeakMap;
|
|
4193
|
-
var updateTimeStatements = new WeakMap;
|
|
4194
|
-
var activeBackfills = new WeakMap;
|
|
4195
|
-
function getUpsertMapStatement(db) {
|
|
4196
|
-
let statement = upsertMapStatements.get(db);
|
|
4197
|
-
if (!statement) {
|
|
4198
|
-
statement = db.prepare(`INSERT INTO message_fts_rowid_map
|
|
4199
|
-
(session_id, message_ordinal, fts_rowid, message_time_ms)
|
|
4200
|
-
VALUES (?, ?, ?, ?)
|
|
4201
|
-
ON CONFLICT(session_id, message_ordinal) DO UPDATE SET
|
|
4202
|
-
fts_rowid = excluded.fts_rowid,
|
|
4203
|
-
message_time_ms = COALESCE(
|
|
4204
|
-
excluded.message_time_ms,
|
|
4205
|
-
message_fts_rowid_map.message_time_ms
|
|
4206
|
-
)`);
|
|
4207
|
-
upsertMapStatements.set(db, statement);
|
|
4208
|
-
}
|
|
4209
|
-
return statement;
|
|
4210
|
-
}
|
|
4211
|
-
function getBackfillState(db) {
|
|
4212
|
-
const row = db.prepare(`SELECT watermark_rowid AS watermarkRowid, completed
|
|
4213
|
-
FROM message_fts_rowid_map_backfill_state
|
|
4214
|
-
WHERE id = ?`).get(BACKFILL_STATE_ID);
|
|
4215
|
-
return {
|
|
4216
|
-
processed: 0,
|
|
4217
|
-
watermarkRowid: typeof row?.watermarkRowid === "number" && Number.isSafeInteger(row.watermarkRowid) ? row.watermarkRowid : 0,
|
|
4218
|
-
completed: row?.completed === 1
|
|
4219
|
-
};
|
|
4220
|
-
}
|
|
4221
|
-
function recordMessageFtsRowid(db, sessionId, messageOrdinal, ftsRowid, messageTimeMs = null) {
|
|
4222
|
-
const numericRowid = Number(ftsRowid);
|
|
4223
|
-
if (!Number.isSafeInteger(numericRowid) || numericRowid <= 0) {
|
|
4224
|
-
throw new Error(`invalid message FTS rowid: ${String(ftsRowid)}`);
|
|
4225
|
-
}
|
|
4226
|
-
const normalizedTime = typeof messageTimeMs === "number" && Number.isSafeInteger(messageTimeMs) && messageTimeMs >= 0 ? messageTimeMs : null;
|
|
4227
|
-
getUpsertMapStatement(db).run(sessionId, messageOrdinal, numericRowid, normalizedTime);
|
|
4228
|
-
}
|
|
4229
|
-
function recordIndexedMessageTime(db, sessionId, messageOrdinal, messageTimeMs) {
|
|
4230
|
-
if (typeof messageTimeMs !== "number" || !Number.isSafeInteger(messageTimeMs) || messageTimeMs < 0) {
|
|
4231
|
-
return;
|
|
4232
|
-
}
|
|
4233
|
-
let statement = updateTimeStatements.get(db);
|
|
4234
|
-
if (!statement) {
|
|
4235
|
-
statement = db.prepare(`UPDATE message_fts_rowid_map
|
|
4236
|
-
SET message_time_ms = ?
|
|
4237
|
-
WHERE session_id = ? AND message_ordinal = ?
|
|
4238
|
-
AND message_time_ms IS NULL`);
|
|
4239
|
-
updateTimeStatements.set(db, statement);
|
|
4240
|
-
}
|
|
4241
|
-
statement.run(messageTimeMs, sessionId, messageOrdinal);
|
|
4242
|
-
}
|
|
4243
|
-
function backfillMessageFtsRowidMapBatch(db, batchSize = MESSAGE_FTS_ROWID_MAP_BACKFILL_BATCH_SIZE) {
|
|
4244
|
-
const boundedBatchSize = Number.isFinite(batchSize) ? Math.min(MESSAGE_FTS_ROWID_MAP_BACKFILL_BATCH_SIZE, Math.max(1, Math.floor(batchSize))) : MESSAGE_FTS_ROWID_MAP_BACKFILL_BATCH_SIZE;
|
|
4245
|
-
let progress = {
|
|
4246
|
-
processed: 0,
|
|
4247
|
-
watermarkRowid: 0,
|
|
4248
|
-
completed: false
|
|
4249
|
-
};
|
|
4250
|
-
let transactionStartedAt = 0;
|
|
4251
|
-
db.transaction(() => {
|
|
4252
|
-
transactionStartedAt = performance.now();
|
|
4253
|
-
db.prepare(`INSERT OR IGNORE INTO message_fts_rowid_map_backfill_state
|
|
4254
|
-
(id, watermark_rowid, completed) VALUES (?, 0, 0)`).run(BACKFILL_STATE_ID);
|
|
4255
|
-
const state = getBackfillState(db);
|
|
4256
|
-
if (state.completed) {
|
|
4257
|
-
progress = state;
|
|
4258
|
-
return;
|
|
4259
|
-
}
|
|
4260
|
-
const rows = db.prepare(`SELECT rowid AS ftsRowid,
|
|
4261
|
-
session_id AS sessionId, message_ordinal AS messageOrdinal
|
|
4262
|
-
FROM message_history_fts WHERE rowid > ? ORDER BY rowid ASC LIMIT ?`).all(state.watermarkRowid, boundedBatchSize);
|
|
4263
|
-
let watermarkRowid = state.watermarkRowid;
|
|
4264
|
-
for (const row of rows) {
|
|
4265
|
-
const ftsRowid = Number(row.ftsRowid);
|
|
4266
|
-
const messageOrdinal = Number(row.messageOrdinal);
|
|
4267
|
-
if (Number.isSafeInteger(ftsRowid) && ftsRowid > watermarkRowid) {
|
|
4268
|
-
watermarkRowid = ftsRowid;
|
|
4269
|
-
}
|
|
4270
|
-
if (typeof row.sessionId === "string" && Number.isSafeInteger(messageOrdinal) && messageOrdinal >= 0 && Number.isSafeInteger(ftsRowid) && ftsRowid > 0) {
|
|
4271
|
-
recordMessageFtsRowid(db, row.sessionId, messageOrdinal, ftsRowid);
|
|
4272
|
-
}
|
|
4273
|
-
}
|
|
4274
|
-
const completed = rows.length < boundedBatchSize;
|
|
4275
|
-
db.prepare(`UPDATE message_fts_rowid_map_backfill_state
|
|
4276
|
-
SET watermark_rowid = ?, completed = ?, updated_at = ?
|
|
4277
|
-
WHERE id = ?`).run(watermarkRowid, completed ? 1 : 0, Date.now(), BACKFILL_STATE_ID);
|
|
4278
|
-
progress = {
|
|
4279
|
-
processed: rows.length,
|
|
4280
|
-
watermarkRowid,
|
|
4281
|
-
completed
|
|
4282
|
-
};
|
|
4283
|
-
}).immediate();
|
|
4284
|
-
logSlowWriteTransaction("message_fts_rowid_backfill", transactionStartedAt);
|
|
4285
|
-
return progress;
|
|
4286
|
-
}
|
|
4287
|
-
async function runMessageFtsRowidMapBackfill(db) {
|
|
4288
|
-
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
4289
|
-
for (;; ) {
|
|
4290
|
-
const progress = backfillMessageFtsRowidMapBatch(db);
|
|
4291
|
-
if (progress.completed)
|
|
4292
|
-
return;
|
|
4293
|
-
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
4294
|
-
}
|
|
4295
|
-
}
|
|
4296
|
-
function startMessageFtsRowidMapBackfill(db) {
|
|
4297
|
-
const active = activeBackfills.get(db);
|
|
4298
|
-
if (active)
|
|
4299
|
-
return active;
|
|
4300
|
-
const run = withoutSqliteTransformPass(() => withSqliteBackgroundWriter(() => runMessageFtsRowidMapBackfill(db))).finally(() => {
|
|
4301
|
-
activeBackfills.delete(db);
|
|
4302
|
-
});
|
|
4303
|
-
activeBackfills.set(db, run);
|
|
4304
|
-
return run;
|
|
4305
|
-
}
|
|
4306
|
-
function messageFtsOrdinalRangeIsMapped(db, sessionId, startOrdinal, endOrdinal) {
|
|
4307
|
-
if (endOrdinal < startOrdinal)
|
|
4308
|
-
return true;
|
|
4309
|
-
if (getBackfillState(db).completed)
|
|
4310
|
-
return true;
|
|
4311
|
-
let statement = rangeReadyStatements.get(db);
|
|
4312
|
-
if (!statement) {
|
|
4313
|
-
statement = db.prepare(`SELECT COUNT(DISTINCT source.message_ordinal) AS sourceOrdinalCount,
|
|
4314
|
-
COUNT(DISTINCT CASE
|
|
4315
|
-
WHEN source.role IN ('user', 'assistant')
|
|
4316
|
-
AND source.normalized_content_hash != ?
|
|
4317
|
-
THEN source.message_ordinal
|
|
4318
|
-
END) AS expectedMapCount,
|
|
4319
|
-
COUNT(DISTINCT CASE
|
|
4320
|
-
WHEN source.role IN ('user', 'assistant')
|
|
4321
|
-
AND source.normalized_content_hash != ?
|
|
4322
|
-
AND map.fts_rowid IS NOT NULL
|
|
4323
|
-
THEN source.message_ordinal
|
|
4324
|
-
END) AS mappedCount
|
|
4325
|
-
FROM message_history_source AS source
|
|
4326
|
-
LEFT JOIN message_fts_rowid_map AS map
|
|
4327
|
-
ON map.session_id = source.session_id
|
|
4328
|
-
AND map.message_ordinal = source.message_ordinal
|
|
4329
|
-
WHERE source.session_id = ?
|
|
4330
|
-
AND source.message_ordinal BETWEEN ? AND ?`);
|
|
4331
|
-
rangeReadyStatements.set(db, statement);
|
|
4332
|
-
}
|
|
4333
|
-
const row = statement.get(EMPTY_INDEX_CONTENT_HASH, EMPTY_INDEX_CONTENT_HASH, sessionId, startOrdinal, endOrdinal);
|
|
4334
|
-
const ordinalCount = endOrdinal - startOrdinal + 1;
|
|
4335
|
-
return row?.sourceOrdinalCount === ordinalCount && row.expectedMapCount === row.mappedCount;
|
|
4336
|
-
}
|
|
4337
|
-
function deleteUnmappedMessageFtsRows(db, sessionIds) {
|
|
4338
|
-
if (sessionIds.length === 0)
|
|
4339
|
-
return;
|
|
4340
|
-
const state = getBackfillState(db);
|
|
4341
|
-
if (state.completed)
|
|
4342
|
-
return;
|
|
4343
|
-
const placeholders = sessionIds.map(() => "?").join(", ");
|
|
4344
|
-
db.prepare(`DELETE FROM message_history_fts
|
|
4345
|
-
WHERE rowid > ? AND session_id IN (${placeholders})`).run(state.watermarkRowid, ...sessionIds);
|
|
4346
|
-
}
|
|
4347
|
-
|
|
4348
|
-
export { canonicalProjectDirectory, setHomeProjectPermission, shouldSkipHomeProjectMemory, ProjectIdentityError, resolveProjectIdentityStrict, takeDubiousOwnershipProjectIdentityWarning, isUserHomeDirectory, resolveProjectIdentity, directoryHasGitMetadata, describeUnresolvedProjectIdentity, isUsableProjectIdentity, resolveProjectIdentityForSession, normalizeStoredProjectPath, storedPathBelongsToIdentity, beginBootQuietPeriod, bootQuietRemainingMs, scheduleAfterBootQuiet, recordMessageFtsRowid, recordIndexedMessageTime, startMessageFtsRowidMapBackfill, messageFtsOrdinalRangeIsMapped, deleteUnmappedMessageFtsRows, layoutLkgPrefix, assembleLkgPrefix, LKG_SLOT_CHUNKS_DDL, SESSION_REPLAY_DECISIONS_DDL, LKG_SLOTS_DDL, V2_MEMORY_CATEGORIES, PROMOTABLE_CATEGORIES, CATEGORY_PRIORITY, getMemoryCategoryOrder, CATEGORY_DEFAULT_TTL, unescapeXml, parseCompartmentOutput, installCompartmentHistoryVersions, resolveWorkspaceShareCategories, resolveWorkspaceIdentitySet, expandWorkspaceIdentitySetWithAliases, resolveStoredPathWorkspaceIdentity, storedPathBelongsToWorkspace, sourceNameForMemory, computeWorkspaceEpochFingerprint, FORK_MIGRATION_VERSION_FLOOR, managedAuthorityNoteRow, hasPendingMigrations, getMainThreadMigrationBodyCount, runMigrations, runMigrationsWithRetry };
|
|
3591
|
+
export { unescapeXml, parseCompartmentOutput, layoutLkgPrefix, assembleLkgPrefix, LKG_SLOT_CHUNKS_DDL, SESSION_REPLAY_DECISIONS_DDL, LKG_SLOTS_DDL, installCompartmentHistoryVersions, resolveWorkspaceShareCategories, resolveWorkspaceIdentitySet, expandWorkspaceIdentitySetWithAliases, resolveStoredPathWorkspaceIdentity, storedPathBelongsToWorkspace, sourceNameForMemory, computeWorkspaceEpochFingerprint, FORK_MIGRATION_VERSION_FLOOR, managedAuthorityNoteRow, hasPendingMigrations, getMainThreadMigrationBodyCount, runMigrations, runMigrationsWithRetry };
|