@cortexkit/opencode-magic-context 0.48.0 → 0.49.1
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/{announcement-fp14dw0n.js → announcement-hdbkt8v5.js} +1 -1
- package/dist/auto-search-worker.js +3 -3
- package/dist/config/{mural-model-deprecation.d.ts → deprecated-config.d.ts} +4 -1
- package/dist/config/deprecated-config.d.ts.map +1 -0
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/project-security.d.ts +2 -2
- package/dist/config/schema/magic-context.d.ts +4 -4
- package/dist/config/schema/magic-context.d.ts.map +1 -1
- package/dist/{conflict-warning-hook-w8cykrnf.js → conflict-warning-hook-asnt6hfc.js} +7 -7
- package/dist/{context-m0cy262m.js → context-tfyhtdcs.js} +187 -68
- package/dist/{derive-budgets-sg0xsq7s.js → derive-budgets-j4ry8j8n.js} +2 -2
- package/dist/embedding-backfill-wyc3ykyf.js +21 -0
- package/dist/embedding-worker-process.js +30 -0
- package/dist/embedding-worker.js +6 -6
- package/dist/features/magic-context/dreamer/task-registry.d.ts +2 -3
- package/dist/features/magic-context/dreamer/task-registry.d.ts.map +1 -1
- package/dist/features/magic-context/git-commits/search-git-commits.d.ts +2 -0
- package/dist/features/magic-context/git-commits/search-git-commits.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding-worker-client.d.ts +8 -1
- package/dist/features/magic-context/memory/embedding-worker-client.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding-worker-process.d.ts +2 -0
- package/dist/features/magic-context/memory/embedding-worker-process.d.ts.map +1 -0
- package/dist/features/magic-context/memory/onnx-telemetry.d.ts +3 -0
- package/dist/features/magic-context/memory/onnx-telemetry.d.ts.map +1 -0
- package/dist/features/magic-context/message-index.d.ts.map +1 -1
- package/dist/features/magic-context/overflow-detection.d.ts +1 -2
- package/dist/features/magic-context/overflow-detection.d.ts.map +1 -1
- package/dist/features/magic-context/pi-content-decisions.d.ts +1 -1
- package/dist/features/magic-context/pi-content-decisions.d.ts.map +1 -1
- package/dist/features/magic-context/search-rerank.d.ts +35 -0
- package/dist/features/magic-context/search-rerank.d.ts.map +1 -0
- package/dist/features/magic-context/search.d.ts +11 -0
- package/dist/features/magic-context/search.d.ts.map +1 -1
- package/dist/features/magic-context/storage-meta-persisted.d.ts +13 -2
- package/dist/features/magic-context/storage-meta-persisted.d.ts.map +1 -1
- package/dist/features/magic-context/storage-meta-session.d.ts +1 -1
- package/dist/features/magic-context/storage-meta-session.d.ts.map +1 -1
- package/dist/features/magic-context/storage-meta.d.ts +1 -1
- package/dist/features/magic-context/storage-meta.d.ts.map +1 -1
- package/dist/features/magic-context/storage-session-tables.d.ts +2 -0
- package/dist/features/magic-context/storage-session-tables.d.ts.map +1 -1
- package/dist/features/magic-context/storage-tag-identity-revision.d.ts +29 -9
- package/dist/features/magic-context/storage-tag-identity-revision.d.ts.map +1 -1
- package/dist/features/magic-context/storage-tags.d.ts +9 -0
- package/dist/features/magic-context/storage-tags.d.ts.map +1 -1
- package/dist/features/magic-context/storage.d.ts +1 -1
- package/dist/features/magic-context/storage.d.ts.map +1 -1
- package/dist/features/magic-context/tagger.d.ts +2 -0
- package/dist/features/magic-context/tagger.d.ts.map +1 -1
- package/dist/features/magic-context/transform-decision-log.d.ts +4 -1
- package/dist/features/magic-context/transform-decision-log.d.ts.map +1 -1
- package/dist/features/magic-context/user-memory/storage-user-memory.d.ts +1 -0
- package/dist/features/magic-context/user-memory/storage-user-memory.d.ts.map +1 -1
- package/dist/hooks/magic-context/auto-search-deadline.d.ts.map +1 -1
- package/dist/hooks/magic-context/auto-search-replay.fixture.d.ts +24 -0
- package/dist/hooks/magic-context/auto-search-replay.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-worker-client.d.ts +2 -0
- package/dist/hooks/magic-context/auto-search-worker-client.d.ts.map +1 -1
- package/dist/hooks/magic-context/command-handler.d.ts +2 -0
- package/dist/hooks/magic-context/command-handler.d.ts.map +1 -1
- package/dist/hooks/magic-context/emergency-fail-closed.d.ts +28 -0
- package/dist/hooks/magic-context/emergency-fail-closed.d.ts.map +1 -1
- package/dist/hooks/magic-context/event-handler.d.ts.map +1 -1
- package/dist/hooks/magic-context/final-wire-token-estimate.d.ts +1 -0
- package/dist/hooks/magic-context/final-wire-token-estimate.d.ts.map +1 -1
- package/dist/hooks/magic-context/historian-host-runner.d.ts +8 -0
- package/dist/hooks/magic-context/historian-host-runner.d.ts.map +1 -1
- package/dist/hooks/magic-context/hook-handlers.d.ts.map +1 -1
- package/dist/hooks/magic-context/hook.d.ts +3 -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/latest-thinking-recovery.d.ts +7 -0
- package/dist/hooks/magic-context/latest-thinking-recovery.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-measured-request.d.ts +3 -1
- package/dist/hooks/magic-context/lkg-measured-request.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-persist.d.ts +8 -14
- package/dist/hooks/magic-context/lkg-persist.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-recovery-fence.d.ts +62 -0
- package/dist/hooks/magic-context/lkg-recovery-fence.d.ts.map +1 -0
- package/dist/hooks/magic-context/lkg-recovery-prefix.d.ts +38 -0
- package/dist/hooks/magic-context/lkg-recovery-prefix.d.ts.map +1 -0
- package/dist/hooks/magic-context/lkg-replay.d.ts +3 -1
- package/dist/hooks/magic-context/lkg-replay.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-slot.d.ts.map +1 -1
- package/dist/hooks/magic-context/opaque-thinking.d.ts +12 -0
- package/dist/hooks/magic-context/opaque-thinking.d.ts.map +1 -0
- package/dist/hooks/magic-context/pass-outcome.d.ts +3 -2
- package/dist/hooks/magic-context/pass-outcome.d.ts.map +1 -1
- package/dist/hooks/magic-context/pending-materialization.d.ts +8 -0
- package/dist/hooks/magic-context/pending-materialization.d.ts.map +1 -0
- package/dist/hooks/magic-context/read-session-chunk.d.ts +7 -1
- package/dist/hooks/magic-context/read-session-chunk.d.ts.map +1 -1
- package/dist/hooks/magic-context/read-session-db.d.ts +3 -0
- package/dist/hooks/magic-context/read-session-db.d.ts.map +1 -1
- package/dist/hooks/magic-context/read-session-raw.d.ts +35 -0
- package/dist/hooks/magic-context/read-session-raw.d.ts.map +1 -1
- package/dist/hooks/magic-context/recomp-orchestrator.d.ts.map +1 -1
- package/dist/hooks/magic-context/rust-mode-transform.d.ts +37 -0
- package/dist/hooks/magic-context/rust-mode-transform.d.ts.map +1 -1
- package/dist/hooks/magic-context/shared-compartment-boundaries.d.ts +8 -1
- package/dist/hooks/magic-context/shared-compartment-boundaries.d.ts.map +1 -1
- package/dist/hooks/magic-context/strict-thinking-prefix.d.ts +8 -0
- package/dist/hooks/magic-context/strict-thinking-prefix.d.ts.map +1 -0
- package/dist/hooks/magic-context/strip-content.d.ts +5 -2
- package/dist/hooks/magic-context/strip-content.d.ts.map +1 -1
- package/dist/hooks/magic-context/system-date-refresh.d.ts +29 -0
- package/dist/hooks/magic-context/system-date-refresh.d.ts.map +1 -0
- package/dist/hooks/magic-context/system-prompt-dates.d.ts +6 -0
- package/dist/hooks/magic-context/system-prompt-dates.d.ts.map +1 -0
- package/dist/hooks/magic-context/system-prompt-delivery.d.ts +47 -0
- package/dist/hooks/magic-context/system-prompt-delivery.d.ts.map +1 -0
- package/dist/hooks/magic-context/system-prompt-hash.d.ts +4 -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/transform-postprocess-phase.d.ts +15 -0
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform.d.ts +7 -0
- package/dist/hooks/magic-context/transform.d.ts.map +1 -1
- package/dist/{index-ty64eqcn.js → index-0pjvpfkf.js} +24 -4
- package/dist/{index-db7zwa3v.js → index-1bt88epp.js} +93 -9
- package/dist/{index-2y0s2hep.js → index-4mjhqadz.js} +1 -1
- package/dist/index-6m7rdv7y.js +733 -0
- package/dist/{index-k1xb52kd.js → index-6tfxmc4n.js} +11 -11
- package/dist/{index-fbv1dn35.js → index-7w18gg78.js} +26 -2
- package/dist/{index-7mx8v0pw.js → index-att4bfan.js} +4 -4
- package/dist/{index-mmyh6d8f.js → index-eypn4ba6.js} +11 -6
- package/dist/{index-q2tqeqde.js → index-fdtkt5r1.js} +1229 -78
- package/dist/{index-c43kr12f.js → index-fg00p1cg.js} +42 -40
- package/dist/{v2/server-1bc61ans.js → index-fvnzcnww.js} +44 -1
- package/dist/index-gbmqa9x9.js +1170 -0
- package/dist/{index-knh4y330.js → index-gzky5rva.js} +31 -49
- package/dist/{index-0qhce371.js → index-h2wc01qk.js} +2 -2
- package/dist/{index-dhwzyd54.js → index-h5zfkjyk.js} +160 -25
- package/dist/{index-bhvjj0ys.js → index-k6xvbj2e.js} +255 -1075
- package/dist/{index-0w56v4fm.js → index-mw7c950g.js} +1 -1
- package/dist/{index-8j7gqj40.js → index-nsjyysj0.js} +6 -2
- package/dist/{index-k9nnwad5.js → index-nydv6g8r.js} +44 -7
- package/dist/{index-f0h6xwqm.js → index-p0n5ryq8.js} +304 -960
- package/dist/{index-pg50n748.js → index-p1hnwfd8.js} +4 -4
- package/dist/{index-1qb0z7wa.js → index-qx53vezw.js} +1 -1
- package/dist/{index-5zygecde.js → index-r2zcs71c.js} +8 -6
- package/dist/{index-cb7emxgj.js → index-rafsaxac.js} +336 -6
- package/dist/{index-z8e0psj8.js → index-s7fc0fkn.js} +3 -3
- package/dist/{index-14cjxt20.js → index-sfhndpcb.js} +505 -11
- package/dist/index-sv0bb7vg.js +6972 -0
- package/dist/{index-jcbd3znx.js → index-tqf7yg27.js} +1 -1
- package/dist/{index-72nhv486.js → index-vkbqdnkj.js} +2 -2
- package/dist/{index-pdecwzrd.js → index-w23dh319.js} +18 -259
- package/dist/{index-yq8n9qcb.js → index-xgrwmj82.js} +4 -4
- package/dist/{index-0an7742d.js → index-xnanvj3w.js} +1364 -2278
- package/dist/{index-eeezr5zz.js → index-z1tjp257.js} +1 -1
- package/dist/{index-692jzy0p.js → index-zfzdpeq2.js} +2279 -4061
- package/dist/{index-q7h7csab.js → index-zg8yq4ya.js} +34 -749
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +241 -76
- package/dist/{logger-d3wex3dz.js → logger-ewak5q1s.js} +1 -1
- package/dist/{message-index-bounded-7ezbgddp.js → message-index-bounded-hqktkhdy.js} +15 -14
- package/dist/{message-time-backfill-brbd63hv.js → message-time-backfill-8x06r9kx.js} +2 -2
- package/dist/migration-worker.js +11 -10
- package/dist/plugin/hooks/create-session-hooks.d.ts +5 -1
- package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
- 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 → project-embedding-registry-0gv3h6y8.js} +10 -10
- package/dist/raw-ordinal-warmup-worker.js +4 -4
- package/dist/{read-session-chunk-6k83m4fj.js → read-session-chunk-5mh0bh8y.js} +12 -9
- package/dist/{read-session-raw-3g9qy1xa.js → read-session-raw-8sjbc9h0.js} +5 -3
- package/dist/{recomp-orchestrator-d3fp1cy0.js → recomp-orchestrator-kpkhkjhq.js} +28 -27
- package/dist/{safe-notification-target-5ffqq32m.js → safe-notification-target-q0cyrx3x.js} +2 -2
- package/dist/{search-epax1ecv.js → search-p9w39qv4.js} +22 -21
- package/dist/{send-session-notification-erecz4y4.js → send-session-notification-xffh3bbe.js} +5 -5
- package/dist/shared/auto-search-lifecycle.d.ts +14 -0
- package/dist/shared/auto-search-lifecycle.d.ts.map +1 -1
- package/dist/shared/logger.d.ts.map +1 -1
- package/dist/shared/models-dev-cache.d.ts.map +1 -1
- package/dist/shared/models-dev-temperature.d.ts +18 -0
- package/dist/shared/models-dev-temperature.d.ts.map +1 -0
- package/dist/shared/project-directory-key.d.ts +16 -0
- package/dist/shared/project-directory-key.d.ts.map +1 -1
- package/dist/shared/storage-file-mutex.d.ts +9 -0
- package/dist/shared/storage-file-mutex.d.ts.map +1 -0
- package/dist/shared/storage-permissions.d.ts +6 -0
- package/dist/shared/storage-permissions.d.ts.map +1 -1
- package/dist/shared/subagent-temperature.d.ts +46 -0
- package/dist/shared/subagent-temperature.d.ts.map +1 -0
- package/dist/shared/window-geometry.d.ts +9 -66
- package/dist/shared/window-geometry.d.ts.map +1 -1
- package/dist/standalone-plugin-marker.d.ts +8 -0
- package/dist/standalone-plugin-marker.d.ts.map +1 -0
- package/dist/{storage-tags-d3b0v2ss.js → storage-tags-k0pda32s.js} +6 -4
- package/dist/tools/ctx-reduce/constants.d.ts +1 -2
- package/dist/tools/ctx-reduce/constants.d.ts.map +1 -1
- package/dist/tools/ctx-reduce/tools.d.ts +1 -1
- package/dist/tools/ctx-reduce/tools.d.ts.map +1 -1
- package/dist/tools/ctx-search/tools.d.ts.map +1 -1
- package/dist/tools/ctx-search/types.d.ts +1 -0
- package/dist/tools/ctx-search/types.d.ts.map +1 -1
- package/dist/{transform-postprocess-phase-spcy2qre.js → transform-postprocess-phase-481j5a7z.js} +28 -27
- package/dist/v2/auto-search-worker.js +3 -3
- package/dist/v2/{context-sf98kstd.js → context-gsdtha5v.js} +1619 -3111
- package/dist/v2/{derive-budgets-3vc0y84t.js → derive-budgets-enckmg7y.js} +3 -3
- package/dist/v2/embedding-backfill-dbvjbcmm.js +20 -0
- package/dist/v2/embedding-worker-process.js +29 -0
- package/dist/v2/embedding-worker.js +6 -7
- package/dist/v2/hidden-child-native.d.ts.map +1 -1
- package/dist/v2/hidden-completion.d.ts +7 -0
- package/dist/v2/hidden-completion.d.ts.map +1 -1
- package/dist/v2/hooks/context.d.ts.map +1 -1
- package/dist/v2/hooks/copied-tag-notation.d.ts +19 -0
- package/dist/v2/hooks/copied-tag-notation.d.ts.map +1 -0
- package/dist/v2/hooks/dream-trigger.d.ts +4 -1
- package/dist/v2/hooks/dream-trigger.d.ts.map +1 -1
- package/dist/v2/hooks/generate.d.ts +9 -2
- package/dist/v2/hooks/generate.d.ts.map +1 -1
- package/dist/v2/hooks/payload.d.ts.map +1 -1
- package/dist/v2/hooks/system-prompt-response.d.ts +5 -0
- package/dist/v2/hooks/system-prompt-response.d.ts.map +1 -0
- package/dist/v2/{logger-mxd0ym09.js → logger-pj02s7sr.js} +1 -1
- package/dist/v2/{message-index-bounded-dy3s2k1e.js → message-index-bounded-p6v0n8qh.js} +15 -14
- package/dist/v2/{message-time-backfill-gtx1pwk1.js → message-time-backfill-cje68egj.js} +2 -2
- package/dist/v2/migration-worker.js +11 -10
- package/dist/v2/{project-embedding-registry-1tgba5dv.js → project-embedding-registry-nyq7z8y6.js} +11 -12
- package/dist/v2/raw-ordinal-warmup-worker.js +4 -4
- package/dist/v2/{read-session-chunk-rh4khdkv.js → read-session-chunk-fhyfe4qa.js} +12 -9
- package/dist/v2/{read-session-raw-bsbmf0vj.js → read-session-raw-j8dvp7f4.js} +5 -3
- package/dist/v2/recomp-orchestrator-5xy7w136.js +57 -0
- package/dist/v2/{safe-notification-target-73ax1p5v.js → safe-notification-target-y3p1hce9.js} +2 -2
- package/dist/v2/{search-nzkwrc6n.js → search-j7bakcwa.js} +23 -23
- package/dist/v2/{send-session-notification-6km439kn.js → send-session-notification-f6v698r5.js} +5 -5
- package/dist/v2/{server-7wwc2nga.js → server-1fszbabv.js} +32 -32
- package/dist/v2/{server-k228xhjg.js → server-2htmbqbv.js} +26 -2
- package/dist/v2/{server-aan4q8mx.js → server-3t0q2cqx.js} +1 -1
- package/dist/v2/{server-686jg6eb.js → server-4c7jt8gq.js} +68 -7
- package/dist/v2/{server-xxm59eww.js → server-4enr7s6x.js} +4 -4
- package/dist/v2/{server-zxhgvsf9.js → server-676xw7at.js} +1 -1
- package/dist/v2/{server-52awr2mw.js → server-6byqfbqf.js} +93 -9
- package/dist/v2/{server-e0vdaae2.js → server-6tcrjfw8.js} +4 -4
- package/dist/v2/{server-qye6ykf7.js → server-7ekna9zs.js} +2 -2
- package/dist/v2/{server-g5r0n3b6.js → server-7h861yms.js} +160 -25
- package/dist/v2/{server-k8x2rbxc.js → server-7spkq1y6.js} +3457 -5192
- package/dist/v2/{server-8pyt7hev.js → server-7vkj6zhb.js} +34 -749
- package/dist/v2/{server-yczc713m.js → server-8xmq9h3f.js} +31 -49
- package/dist/v2/{server-sggvvzhb.js → server-bgzy0phk.js} +505 -11
- package/dist/v2/server-c7n2ftng.js +6860 -0
- package/dist/v2/server-cvgn49tr.js +733 -0
- package/dist/v2/{server-zm570tr2.js → server-cw6521wn.js} +232 -7
- package/dist/v2/{server-xdfwt6kh.js → server-czb2rkpk.js} +23 -3
- package/dist/v2/{server-x2g40a71.js → server-d6g4whc2.js} +21 -15
- package/dist/{index-1bc61ans.js → v2/server-fvnzcnww.js} +44 -1
- package/dist/v2/{server-4k748ke6.js → server-hb6xhh9q.js} +2 -2
- package/dist/v2/{server-gjcr4w98.js → server-kh958yj8.js} +5 -5
- package/dist/v2/{server-1r6pmz4f.js → server-kzns2hbz.js} +1 -1
- package/dist/v2/{server-psqc7e9n.js → server-mqvtz7wz.js} +1227 -78
- package/dist/v2/{server-vqpf3167.js → server-ras2sxnc.js} +135 -15
- package/dist/v2/{server-ezhze64f.js → server-s2st631p.js} +4 -4
- package/dist/v2/{server-5m3dt5r1.js → server-t4k4qexw.js} +6 -2
- package/dist/v2/{server-z2037m6z.js → server-t528t8qm.js} +2 -2
- package/dist/v2/{server-v06jcv0w.js → server-vb7pbd9p.js} +18 -259
- package/dist/v2/{server-8tqanswc.js → server-zbxjj2mz.js} +331 -4
- package/dist/v2/server.d.ts.map +1 -1
- package/dist/v2/server.js +150 -6
- package/dist/v2/{storage-tags-w4tv77sn.js → storage-tags-5yxrvkaf.js} +6 -4
- package/dist/v2/store-reader.d.ts +8 -2
- package/dist/v2/store-reader.d.ts.map +1 -1
- package/dist/v2/{wrapup-orchestrator-mz7efs7w.js → wrapup-orchestrator-yem5422s.js} +36 -36
- package/dist/wrapup-orchestrator-xvrr27ws.js +45 -0
- package/package.json +4 -4
- package/src/config/{mural-model-deprecation.ts → deprecated-config.ts} +19 -0
- package/src/config/index.test.ts +15 -37
- package/src/config/index.ts +2 -3
- package/src/config/project-security.ts +3 -3
- package/src/config/schema/magic-context.ts +11 -7
- package/src/features/magic-context/dreamer/task-registry.ts +2 -3
- package/src/shared/auto-search-lifecycle.ts +43 -0
- package/src/shared/logger.test.ts +38 -0
- package/src/shared/logger.ts +10 -2
- package/src/shared/models-dev-cache.ts +1 -7
- package/src/shared/models-dev-temperature.ts +107 -0
- package/src/shared/project-directory-key.test.ts +59 -0
- package/src/shared/project-directory-key.ts +20 -0
- package/src/shared/sqlite-640-review.test.ts +5 -1
- package/src/shared/storage-file-mutex-review.test.ts +162 -0
- package/src/shared/storage-file-mutex.ts +130 -0
- package/src/shared/storage-permissions.ts +46 -0
- package/src/shared/subagent-temperature.test.ts +270 -0
- package/src/shared/subagent-temperature.ts +110 -0
- package/src/shared/window-geometry.test.ts +102 -236
- package/src/shared/window-geometry.ts +23 -413
- package/dist/config/mural-model-deprecation.d.ts.map +0 -1
- package/dist/embedding-backfill-9rcm1mfy.js +0 -21
- package/dist/index-bdckkfw6.js +0 -3261
- package/dist/index-mfkzp7qj.js +0 -229
- package/dist/v2/embedding-backfill-vn8g1nh1.js +0 -21
- package/dist/v2/recomp-orchestrator-az61rfcg.js +0 -57
- package/dist/v2/server-2fbhp79z.js +0 -3205
- package/dist/v2/server-mfkzp7qj.js +0 -229
- package/dist/wrapup-orchestrator-amzta1t4.js +0 -44
- package/src/shared/__fixtures__/window-overlay.v1.json +0 -337
- /package/dist/{index-2pp04pmg.js → index-69vas84q.js} +0 -0
- /package/dist/v2/{index-2pp04pmg.js → index-69vas84q.js} +0 -0
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
+
TAG_TOMBSTONE_OWNER_PREFIX,
|
|
3
|
+
tagTombstoneOwnerRange,
|
|
4
|
+
tagTombstoneOwnerKey,
|
|
5
|
+
tagRevisionKey,
|
|
6
|
+
tagIdentityRevisionKey,
|
|
2
7
|
deleteTagIdentityRevisions
|
|
3
|
-
} from "./index-
|
|
8
|
+
} from "./index-1bt88epp.js";
|
|
4
9
|
import {
|
|
5
10
|
getHarness2
|
|
6
11
|
} from "./index-pavzsdc6.js";
|
|
@@ -8,29 +13,88 @@ import {
|
|
|
8
13
|
removeSystemReminders,
|
|
9
14
|
hasMeaningfulUserText2,
|
|
10
15
|
extractTexts2
|
|
11
|
-
} from "./index-
|
|
16
|
+
} from "./index-qx53vezw.js";
|
|
17
|
+
import {
|
|
18
|
+
getMagicContextStorageDir
|
|
19
|
+
} from "./index-0sahzkwr.js";
|
|
12
20
|
import {
|
|
13
21
|
withSqliteBackgroundWriter2,
|
|
14
22
|
withoutSqliteTransformPass2
|
|
15
23
|
} from "./index-kb9nn0a0.js";
|
|
16
24
|
import {
|
|
17
25
|
cleanUserText2
|
|
18
|
-
} from "./index-
|
|
26
|
+
} from "./index-sv0bb7vg.js";
|
|
19
27
|
import {
|
|
20
28
|
recordMessageFtsRowid,
|
|
21
29
|
recordIndexedMessageTime,
|
|
22
30
|
messageFtsOrdinalRangeIsMapped,
|
|
23
31
|
deleteUnmappedMessageFtsRows
|
|
24
|
-
} from "./index-
|
|
32
|
+
} from "./index-7w18gg78.js";
|
|
33
|
+
import {
|
|
34
|
+
isPidAlive,
|
|
35
|
+
readProcessStartTime
|
|
36
|
+
} from "./index-6m7rdv7y.js";
|
|
25
37
|
import {
|
|
26
38
|
deleteChunkEmbedBackoffForSession
|
|
27
|
-
} from "./index-
|
|
39
|
+
} from "./index-p1hnwfd8.js";
|
|
40
|
+
import {
|
|
41
|
+
ensurePrivateStorageDirectorySync,
|
|
42
|
+
writeStorageFileSync,
|
|
43
|
+
writeStorageFileAtomicSync,
|
|
44
|
+
syncStorageDirectorySync,
|
|
45
|
+
writeStorageFileDurableAtomicSync
|
|
46
|
+
} from "./index-fvnzcnww.js";
|
|
28
47
|
import {
|
|
29
48
|
closeQuietly
|
|
30
49
|
} from "./index-8ajstryz.js";
|
|
31
50
|
import {
|
|
32
51
|
logSlowWriteTransaction
|
|
33
|
-
} from "./index-
|
|
52
|
+
} from "./index-4mjhqadz.js";
|
|
53
|
+
|
|
54
|
+
// src/shared/bounded-session-map.ts
|
|
55
|
+
class BoundedSessionMap {
|
|
56
|
+
maxEntries;
|
|
57
|
+
store = new Map;
|
|
58
|
+
constructor(maxEntries) {
|
|
59
|
+
if (!Number.isFinite(maxEntries) || maxEntries < 1) {
|
|
60
|
+
throw new Error(`BoundedSessionMap: maxEntries must be >= 1, got ${maxEntries}`);
|
|
61
|
+
}
|
|
62
|
+
this.maxEntries = maxEntries;
|
|
63
|
+
}
|
|
64
|
+
get(sessionId) {
|
|
65
|
+
const value = this.store.get(sessionId);
|
|
66
|
+
if (value === undefined)
|
|
67
|
+
return;
|
|
68
|
+
this.store.delete(sessionId);
|
|
69
|
+
this.store.set(sessionId, value);
|
|
70
|
+
return value;
|
|
71
|
+
}
|
|
72
|
+
peek(sessionId) {
|
|
73
|
+
return this.store.get(sessionId);
|
|
74
|
+
}
|
|
75
|
+
has(sessionId) {
|
|
76
|
+
return this.store.has(sessionId);
|
|
77
|
+
}
|
|
78
|
+
set(sessionId, value) {
|
|
79
|
+
if (this.store.has(sessionId)) {
|
|
80
|
+
this.store.delete(sessionId);
|
|
81
|
+
} else if (this.store.size >= this.maxEntries) {
|
|
82
|
+
const oldest = this.store.keys().next().value;
|
|
83
|
+
if (oldest !== undefined)
|
|
84
|
+
this.store.delete(oldest);
|
|
85
|
+
}
|
|
86
|
+
this.store.set(sessionId, value);
|
|
87
|
+
}
|
|
88
|
+
delete(sessionId) {
|
|
89
|
+
return this.store.delete(sessionId);
|
|
90
|
+
}
|
|
91
|
+
clear() {
|
|
92
|
+
this.store.clear();
|
|
93
|
+
}
|
|
94
|
+
get size() {
|
|
95
|
+
return this.store.size;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
34
98
|
|
|
35
99
|
// src/features/magic-context/session-activity.ts
|
|
36
100
|
var PREFIX = "retrospective_activity:";
|
|
@@ -134,7 +198,403 @@ function clearCompressionDepthRange(db, sessionId, startOrdinal, endOrdinal) {
|
|
|
134
198
|
}
|
|
135
199
|
|
|
136
200
|
// src/features/magic-context/message-index.ts
|
|
137
|
-
import { createHash } from "node:crypto";
|
|
201
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
202
|
+
|
|
203
|
+
// src/hooks/magic-context/lkg-recovery-fence.ts
|
|
204
|
+
import { createHash as createHash2, randomUUID as randomUUID2 } from "node:crypto";
|
|
205
|
+
import { lstatSync, readdirSync as readdirSync2, readFileSync as readFileSync2, rmSync as rmSync2 } from "node:fs";
|
|
206
|
+
import { basename, dirname, join as join2 } from "node:path";
|
|
207
|
+
|
|
208
|
+
// src/shared/storage-file-mutex.ts
|
|
209
|
+
import { execFileSync } from "node:child_process";
|
|
210
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
211
|
+
import { readdirSync, readFileSync, rmSync } from "node:fs";
|
|
212
|
+
import { join } from "node:path";
|
|
213
|
+
var ticketChecksum = (name, ticket) => createHash("sha256").update(JSON.stringify([name, ticket.choosing, ticket.number, ticket.birth])).digest("hex");
|
|
214
|
+
function processBirth(pid) {
|
|
215
|
+
if (process.platform === "linux") {
|
|
216
|
+
try {
|
|
217
|
+
const stat = readFileSync(`/proc/${pid}/stat`, "utf8");
|
|
218
|
+
const ticks = stat.slice(stat.lastIndexOf(")") + 2).trim().split(/\s+/)[19];
|
|
219
|
+
if (!ticks || !/^\d+$/.test(ticks))
|
|
220
|
+
return null;
|
|
221
|
+
return `${readFileSync("/proc/sys/kernel/random/boot_id", "utf8").trim()}:${ticks}`;
|
|
222
|
+
} catch {
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
if (process.platform === "darwin") {
|
|
227
|
+
try {
|
|
228
|
+
return execFileSync("ps", ["-p", String(pid), "-o", "lstart="], {
|
|
229
|
+
encoding: "utf8",
|
|
230
|
+
timeout: 1000,
|
|
231
|
+
windowsHide: true,
|
|
232
|
+
env: { ...process.env, TZ: "UTC", LC_ALL: "C" },
|
|
233
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
234
|
+
}).trim() || null;
|
|
235
|
+
} catch {
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
const start = readProcessStartTime(pid);
|
|
240
|
+
return start === null ? null : String(start);
|
|
241
|
+
}
|
|
242
|
+
var pause = new Int32Array(new SharedArrayBuffer(4));
|
|
243
|
+
function withStorageFileMutex(directory, work, timeoutMs = 1000) {
|
|
244
|
+
ensurePrivateStorageDirectorySync(directory);
|
|
245
|
+
const name = `${process.pid}-${randomUUID()}.lock`;
|
|
246
|
+
const ownPath = join(directory, name);
|
|
247
|
+
const birth = processBirth(process.pid);
|
|
248
|
+
const ticket = { choosing: true, number: 0, birth, checksum: "" };
|
|
249
|
+
const encodedTicket = () => JSON.stringify({ ...ticket, checksum: ticketChecksum(name, ticket) });
|
|
250
|
+
writeStorageFileSync(ownPath, encodedTicket(), { flag: "wx", forcePrivate: true });
|
|
251
|
+
const deadline = performance.now() + timeoutMs;
|
|
252
|
+
const peers = () => {
|
|
253
|
+
const found = [];
|
|
254
|
+
for (const other of readdirSync(directory)) {
|
|
255
|
+
if (other === name || !/^\d+-[\da-f-]+\.lock$/.test(other))
|
|
256
|
+
continue;
|
|
257
|
+
const pid = Number(other.split("-")[0]);
|
|
258
|
+
const otherPath = join(directory, other);
|
|
259
|
+
let value = null;
|
|
260
|
+
try {
|
|
261
|
+
const parsed = JSON.parse(readFileSync(otherPath, "utf8"));
|
|
262
|
+
if (typeof parsed.choosing === "boolean" && Number.isSafeInteger(parsed.number) && parsed.number >= 0 && (parsed.birth === null || typeof parsed.birth === "string") && parsed.checksum === ticketChecksum(other, parsed))
|
|
263
|
+
value = parsed;
|
|
264
|
+
} catch (error) {
|
|
265
|
+
if (error.code === "ENOENT")
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
const alive = isPidAlive(pid);
|
|
269
|
+
const actualBirth = alive === "alive" && value?.birth ? processBirth(pid) : null;
|
|
270
|
+
if (alive === "dead" || actualBirth !== null && value?.birth && actualBirth !== value.birth) {
|
|
271
|
+
rmSync(otherPath, { force: true });
|
|
272
|
+
continue;
|
|
273
|
+
}
|
|
274
|
+
found.push([other, value]);
|
|
275
|
+
}
|
|
276
|
+
return found;
|
|
277
|
+
};
|
|
278
|
+
try {
|
|
279
|
+
ticket.number = 1 + Math.max(0, ...peers().map(([, value]) => value?.number ?? 0));
|
|
280
|
+
ticket.choosing = false;
|
|
281
|
+
writeStorageFileAtomicSync(ownPath, encodedTicket(), true);
|
|
282
|
+
while (peers().some(([other, value]) => !value || value.choosing || value.number < ticket.number || value.number === ticket.number && other < name)) {
|
|
283
|
+
if (performance.now() >= deadline)
|
|
284
|
+
throw new Error("Storage safety publication lock is unavailable");
|
|
285
|
+
Atomics.wait(pause, 0, 0, 10);
|
|
286
|
+
}
|
|
287
|
+
const result = work();
|
|
288
|
+
if (result && typeof result.then === "function")
|
|
289
|
+
throw new TypeError("Storage publication mutex requires synchronous work");
|
|
290
|
+
return result;
|
|
291
|
+
} finally {
|
|
292
|
+
rmSync(ownPath, { force: true });
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// src/hooks/magic-context/lkg-recovery-fence.ts
|
|
297
|
+
class LkgRecoveryFenceError extends Error {
|
|
298
|
+
constructor(message) {
|
|
299
|
+
super(message);
|
|
300
|
+
this.name = "LkgRecoveryFenceError";
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
var platform = process.platform;
|
|
304
|
+
var observer;
|
|
305
|
+
var knownFences = new BoundedSessionMap(1000);
|
|
306
|
+
var ioObserver;
|
|
307
|
+
var cacheKey = (sessionId) => `${getMagicContextStorageDir()}\x00${getHarness2()}\x00${sessionId}`;
|
|
308
|
+
function remember(sessionId, value) {
|
|
309
|
+
knownFences.set(cacheKey(sessionId), value);
|
|
310
|
+
return value;
|
|
311
|
+
}
|
|
312
|
+
function known(sessionId) {
|
|
313
|
+
const prior = knownFences.get(cacheKey(sessionId));
|
|
314
|
+
if (prior)
|
|
315
|
+
return prior;
|
|
316
|
+
const record = read(sessionId);
|
|
317
|
+
if (record)
|
|
318
|
+
return remember(sessionId, { state: record.state, record });
|
|
319
|
+
try {
|
|
320
|
+
lstatSync(lkgRecoveryFencePath(sessionId));
|
|
321
|
+
} catch (error) {
|
|
322
|
+
if (error.code === "ENOENT")
|
|
323
|
+
return remember(sessionId, { state: "clean", record: null });
|
|
324
|
+
}
|
|
325
|
+
return remember(sessionId, { state: "invalid", record: null });
|
|
326
|
+
}
|
|
327
|
+
function clearLkgFenceProcessState(sessionId) {
|
|
328
|
+
if (sessionId)
|
|
329
|
+
knownFences.delete(cacheKey(sessionId));
|
|
330
|
+
else
|
|
331
|
+
knownFences.clear();
|
|
332
|
+
}
|
|
333
|
+
var durableFencesSupported = () => platform !== "win32";
|
|
334
|
+
var hash = (value) => createHash2("sha256").update(value).digest("hex");
|
|
335
|
+
var lkgServedArrayDigest = hash;
|
|
336
|
+
function lkgRecoveryFencePath(sessionId) {
|
|
337
|
+
return join2(getMagicContextStorageDir(), "lkg-recovery-fences", `${hash(sessionId)}.json`);
|
|
338
|
+
}
|
|
339
|
+
function metadata(slot) {
|
|
340
|
+
return [
|
|
341
|
+
slot.inputIdSeq,
|
|
342
|
+
slot.inputContentDigests,
|
|
343
|
+
slot.inputContentSignatures ?? null,
|
|
344
|
+
slot.piOutputEntryIds ?? null,
|
|
345
|
+
slot.lastInputMessageId,
|
|
346
|
+
slot.modelKey,
|
|
347
|
+
slot.providerKey
|
|
348
|
+
];
|
|
349
|
+
}
|
|
350
|
+
function representationKey(slot) {
|
|
351
|
+
return createHash2("sha256").update(slot.jsonPrefix).update(JSON.stringify(metadata(slot))).digest("hex");
|
|
352
|
+
}
|
|
353
|
+
function lkgRecoverySlotKey(slot) {
|
|
354
|
+
return hash(JSON.stringify([
|
|
355
|
+
representationKey(slot),
|
|
356
|
+
slot.capturedAt,
|
|
357
|
+
slot.rowVersion ?? null,
|
|
358
|
+
slot.captureSequence ?? null
|
|
359
|
+
]));
|
|
360
|
+
}
|
|
361
|
+
function payload(record) {
|
|
362
|
+
return [
|
|
363
|
+
record.version,
|
|
364
|
+
record.sessionId,
|
|
365
|
+
record.host,
|
|
366
|
+
record.modelKey,
|
|
367
|
+
record.providerKey,
|
|
368
|
+
record.slotKey,
|
|
369
|
+
record.servedDigest,
|
|
370
|
+
record.revision,
|
|
371
|
+
record.state
|
|
372
|
+
];
|
|
373
|
+
}
|
|
374
|
+
function publishRecord(record) {
|
|
375
|
+
ioObserver?.("write");
|
|
376
|
+
try {
|
|
377
|
+
if (record.state === "clean")
|
|
378
|
+
observer?.("clean");
|
|
379
|
+
writeStorageFileDurableAtomicSync(lkgRecoveryFencePath(record.sessionId), JSON.stringify({ ...record, checksum: hash(JSON.stringify(payload(record))) }), () => observer?.("temp-synced"));
|
|
380
|
+
if (record.state === "dirty")
|
|
381
|
+
observer?.("dirty");
|
|
382
|
+
remember(record.sessionId, {
|
|
383
|
+
state: record.state,
|
|
384
|
+
record: { ...record, checksum: hash(JSON.stringify(payload(record))) }
|
|
385
|
+
});
|
|
386
|
+
} catch (error) {
|
|
387
|
+
const visible = read(record.sessionId);
|
|
388
|
+
if (record.state === "clean" && visible?.state === "clean" && visible.revision === record.revision && visible.slotKey === record.slotKey) {
|
|
389
|
+
const dirty = { ...record, state: "dirty" };
|
|
390
|
+
writeStorageFileDurableAtomicSync(lkgRecoveryFencePath(record.sessionId), JSON.stringify({ ...dirty, checksum: hash(JSON.stringify(payload(dirty))) }));
|
|
391
|
+
}
|
|
392
|
+
remember(record.sessionId, { state: "invalid", record: null });
|
|
393
|
+
throw error;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
function read(sessionId) {
|
|
397
|
+
ioObserver?.("read");
|
|
398
|
+
try {
|
|
399
|
+
const path = lkgRecoveryFencePath(sessionId);
|
|
400
|
+
const stat = lstatSync(path);
|
|
401
|
+
const directory = lstatSync(dirname(path));
|
|
402
|
+
if (!stat.isFile() || stat.size > 4096 || !directory.isDirectory() || directory.isSymbolicLink() || process.platform !== "win32" && ((stat.mode & 63) !== 0 || (directory.mode & 63) !== 0 || process.getuid && stat.uid !== process.getuid()))
|
|
403
|
+
return null;
|
|
404
|
+
const value = JSON.parse(readFileSync2(path, "utf8"));
|
|
405
|
+
if (value.version !== 1 || value.sessionId !== sessionId || value.host !== getHarness2() || value.modelKey !== null && typeof value.modelKey !== "string" || value.providerKey !== null && typeof value.providerKey !== "string" || !/^[a-f0-9]{64}$/.test(value.slotKey) || !/^[a-f0-9]{64}$/.test(value.servedDigest) || typeof value.revision !== "string" || !["clean", "dirty"].includes(value.state) || value.checksum !== hash(JSON.stringify(payload(value))))
|
|
406
|
+
return null;
|
|
407
|
+
return value;
|
|
408
|
+
} catch {
|
|
409
|
+
return null;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
function publish(sessionId, slot, state, revision) {
|
|
413
|
+
const record = {
|
|
414
|
+
version: 1,
|
|
415
|
+
sessionId,
|
|
416
|
+
host: getHarness2(),
|
|
417
|
+
modelKey: slot.modelKey,
|
|
418
|
+
providerKey: slot.providerKey,
|
|
419
|
+
slotKey: lkgRecoverySlotKey(slot),
|
|
420
|
+
servedDigest: hash(slot.jsonPrefix),
|
|
421
|
+
revision,
|
|
422
|
+
state
|
|
423
|
+
};
|
|
424
|
+
publishRecord(record);
|
|
425
|
+
}
|
|
426
|
+
function locked(sessionId, work) {
|
|
427
|
+
ioObserver?.("mutex");
|
|
428
|
+
return withStorageFileMutex(`${lkgRecoveryFencePath(sessionId)}.locks`, () => {
|
|
429
|
+
const path = lkgRecoveryFencePath(sessionId);
|
|
430
|
+
for (const name of readdirSync2(dirname(path))) {
|
|
431
|
+
if (name.startsWith(`${basename(path)}.`) && name.endsWith(".tmp"))
|
|
432
|
+
rmSync2(join2(dirname(path), name), { force: true });
|
|
433
|
+
}
|
|
434
|
+
return work();
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
function hasCleanLkgRecoveryFence(sessionId, _slot) {
|
|
438
|
+
if (!durableFencesSupported())
|
|
439
|
+
return false;
|
|
440
|
+
const state = known(sessionId);
|
|
441
|
+
return state.state === "clean";
|
|
442
|
+
}
|
|
443
|
+
function lkgFenceRequiresRebuild(sessionId, slot, processLocalProof) {
|
|
444
|
+
return !processLocalProof && (durableFencesSupported() ? !hasCleanLkgRecoveryFence(sessionId, slot) : true);
|
|
445
|
+
}
|
|
446
|
+
function lkgRecoveryFenceUnclean(sessionId) {
|
|
447
|
+
return durableFencesSupported() && known(sessionId).state !== "clean";
|
|
448
|
+
}
|
|
449
|
+
function dirtyLkgRecoveryRevision(sessionId, _slot) {
|
|
450
|
+
if (!durableFencesSupported())
|
|
451
|
+
return;
|
|
452
|
+
const record = known(sessionId).record;
|
|
453
|
+
return record?.state === "dirty" ? record.revision : undefined;
|
|
454
|
+
}
|
|
455
|
+
function ownsLkgDirtyFence(sessionId, revision) {
|
|
456
|
+
if (!durableFencesSupported())
|
|
457
|
+
return revision === "process-local";
|
|
458
|
+
const record = known(sessionId).record;
|
|
459
|
+
return revision !== undefined && record?.state === "dirty" && record.revision === revision;
|
|
460
|
+
}
|
|
461
|
+
function invalidateCleanLkgRecoveryFence(sessionId, load, ownRevision) {
|
|
462
|
+
if (!durableFencesSupported())
|
|
463
|
+
return "process-local";
|
|
464
|
+
const prior = known(sessionId);
|
|
465
|
+
if (prior.state === "dirty")
|
|
466
|
+
return prior.record?.revision === ownRevision ? ownRevision : undefined;
|
|
467
|
+
return locked(sessionId, () => {
|
|
468
|
+
const slot = load() ?? {
|
|
469
|
+
jsonPrefix: "",
|
|
470
|
+
inputIdSeq: [],
|
|
471
|
+
inputContentDigests: [],
|
|
472
|
+
lastInputMessageId: "",
|
|
473
|
+
modelKey: null,
|
|
474
|
+
providerKey: null,
|
|
475
|
+
capturedAt: 0
|
|
476
|
+
};
|
|
477
|
+
const record = read(sessionId);
|
|
478
|
+
if (record?.state !== "dirty") {
|
|
479
|
+
const revision = randomUUID2();
|
|
480
|
+
publish(sessionId, slot, "dirty", revision);
|
|
481
|
+
return revision;
|
|
482
|
+
}
|
|
483
|
+
return record?.state === "dirty" && record.revision === ownRevision ? ownRevision : undefined;
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
function prepareLkgCaptureFence(args) {
|
|
487
|
+
if (!durableFencesSupported())
|
|
488
|
+
return "process-local";
|
|
489
|
+
return locked(args.sessionId, () => {
|
|
490
|
+
const before = read(args.sessionId);
|
|
491
|
+
const owns = before?.state === "dirty" && before.revision === args.ownDirtyRevision;
|
|
492
|
+
const unchangedBytes = before?.state === "clean" && before.servedDigest === hash(args.slot.jsonPrefix);
|
|
493
|
+
if (!args.rebuild && before && !owns && !unchangedBytes && before.state !== "clean")
|
|
494
|
+
throw new LkgRecoveryFenceError(`A concurrent recovery requires a declared prefix rebuild (state=${before?.state}, owned=${owns}, previous=${!!args.previousSlot}, bytes=${unchangedBytes})`);
|
|
495
|
+
const revision = randomUUID2();
|
|
496
|
+
if (before)
|
|
497
|
+
publishRecord({ ...before, state: "dirty", revision });
|
|
498
|
+
else
|
|
499
|
+
publish(args.sessionId, args.previousSlot ?? args.slot, "dirty", revision);
|
|
500
|
+
return revision;
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
function certifyCommittedLkgCapture(args) {
|
|
504
|
+
if (!durableFencesSupported())
|
|
505
|
+
return false;
|
|
506
|
+
const state = known(args.sessionId);
|
|
507
|
+
if (state.state !== "dirty" || state.record?.revision !== args.revision)
|
|
508
|
+
return false;
|
|
509
|
+
return locked(args.sessionId, () => {
|
|
510
|
+
const before = read(args.sessionId);
|
|
511
|
+
if (before?.state !== "dirty" || before.revision !== args.revision)
|
|
512
|
+
return false;
|
|
513
|
+
const saved = args.load();
|
|
514
|
+
if (!saved || representationKey(saved) !== representationKey(args.slot) || hash(saved.jsonPrefix) !== args.latestServedDigest)
|
|
515
|
+
return false;
|
|
516
|
+
publish(args.sessionId, saved, "clean", args.revision);
|
|
517
|
+
return true;
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
function markLkgRecoveryDirty(args) {
|
|
521
|
+
if (!durableFencesSupported()) {
|
|
522
|
+
if (!args.processLocalProof)
|
|
523
|
+
throw new LkgRecoveryFenceError("Restart replay requires a healthy rebuild on Windows");
|
|
524
|
+
return "process-local";
|
|
525
|
+
}
|
|
526
|
+
const state = known(args.sessionId);
|
|
527
|
+
if (state.state === "dirty" && args.processLocalProof && state.record && state.record.revision === args.ownDirtyRevision)
|
|
528
|
+
return state.record.revision;
|
|
529
|
+
if (state.state === "invalid")
|
|
530
|
+
throw new LkgRecoveryFenceError("No clean durable recovery certificate");
|
|
531
|
+
return locked(args.sessionId, () => {
|
|
532
|
+
const slot = args.slot;
|
|
533
|
+
const before = read(args.sessionId);
|
|
534
|
+
if (before?.state === "dirty") {
|
|
535
|
+
if (!args.processLocalProof || before.revision !== args.ownDirtyRevision)
|
|
536
|
+
throw new LkgRecoveryFenceError(`Recovery superseded this process's last-good request (local=${args.processLocalProof}, owned=${before.revision === args.ownDirtyRevision})`);
|
|
537
|
+
return before.revision;
|
|
538
|
+
}
|
|
539
|
+
if (before && before.state !== "clean")
|
|
540
|
+
throw new LkgRecoveryFenceError("No clean durable recovery certificate");
|
|
541
|
+
const revision = randomUUID2();
|
|
542
|
+
publish(args.sessionId, slot, "dirty", revision);
|
|
543
|
+
return revision;
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
function commitLkgWithRecoveryFence(args) {
|
|
547
|
+
if (!durableFencesSupported())
|
|
548
|
+
return args.commit();
|
|
549
|
+
const state = known(args.sessionId);
|
|
550
|
+
if (state.state === "clean" && !args.requiredRevision && !args.retainDirtyRevision) {
|
|
551
|
+
const committed = args.commit();
|
|
552
|
+
if (committed) {
|
|
553
|
+
observer?.("committed");
|
|
554
|
+
remember(args.sessionId, { state: "clean", record: null });
|
|
555
|
+
}
|
|
556
|
+
return committed;
|
|
557
|
+
}
|
|
558
|
+
if (state.state === "invalid" && !args.rebuild)
|
|
559
|
+
throw new LkgRecoveryFenceError("Unproven prior request requires a prefix rebuild");
|
|
560
|
+
return locked(args.sessionId, () => {
|
|
561
|
+
const before = read(args.sessionId);
|
|
562
|
+
if (args.requiredRevision && before?.revision !== args.requiredRevision)
|
|
563
|
+
throw new LkgRecoveryFenceError("A later publisher superseded the rollback snapshot");
|
|
564
|
+
const ownsDirty = before?.state === "dirty" && (before.revision === args.retainDirtyRevision || before.revision === args.ownDirtyRevision);
|
|
565
|
+
if (before?.state === "dirty" && !ownsDirty && !args.rebuild)
|
|
566
|
+
throw new LkgRecoveryFenceError("A concurrent recovery requires a declared prefix rebuild");
|
|
567
|
+
if (before?.state !== "dirty" && state.state === "invalid")
|
|
568
|
+
publish(args.sessionId, args.load() ?? args.slot, "dirty", randomUUID2());
|
|
569
|
+
if (!args.commit())
|
|
570
|
+
return false;
|
|
571
|
+
observer?.("committed");
|
|
572
|
+
const saved = args.load();
|
|
573
|
+
if (!saved || representationKey(saved) !== representationKey(args.slot))
|
|
574
|
+
throw new LkgRecoveryFenceError("Last-good commit did not match its certificate");
|
|
575
|
+
if (args.retainDirtyRevision || args.cleanDigest !== undefined && hash(saved.jsonPrefix) !== args.cleanDigest)
|
|
576
|
+
return true;
|
|
577
|
+
const dirty = read(args.sessionId);
|
|
578
|
+
if (dirty?.state === "dirty")
|
|
579
|
+
publish(args.sessionId, saved, "clean", dirty.revision);
|
|
580
|
+
else
|
|
581
|
+
remember(args.sessionId, { state: "clean", record: null });
|
|
582
|
+
return true;
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
function clearLkgRecoveryFence(sessionId, remove, shouldClear) {
|
|
586
|
+
if (!durableFencesSupported())
|
|
587
|
+
return remove?.();
|
|
588
|
+
return locked(sessionId, () => {
|
|
589
|
+
const result = remove?.();
|
|
590
|
+
if (shouldClear && !shouldClear(result))
|
|
591
|
+
return result;
|
|
592
|
+
rmSync2(lkgRecoveryFencePath(sessionId), { force: true });
|
|
593
|
+
syncStorageDirectorySync(dirname(lkgRecoveryFencePath(sessionId)));
|
|
594
|
+
clearLkgFenceProcessState(sessionId);
|
|
595
|
+
return result;
|
|
596
|
+
});
|
|
597
|
+
}
|
|
138
598
|
|
|
139
599
|
// src/features/magic-context/storage-session-tables.ts
|
|
140
600
|
var SESSION_SCOPED_TABLES = [
|
|
@@ -199,6 +659,17 @@ function deleteSessionScopedRows(db, sessionIds, harness, options = {}) {
|
|
|
199
659
|
if (deletableSessionIds.length === 0)
|
|
200
660
|
return 0;
|
|
201
661
|
const placeholders = deletableSessionIds.map(() => "?").join(", ");
|
|
662
|
+
const harnessTables = SESSION_SCOPED_TABLES.filter((definition) => definition.harnessScoped);
|
|
663
|
+
if (options.preserveTagRevisionTombstones) {
|
|
664
|
+
const owners = db.prepare(harnessTables.map((definition) => `SELECT session_id, harness FROM ${definition.table} WHERE session_id IN (${placeholders})${definition.extraPredicate ? ` AND ${definition.extraPredicate}` : ""}`).join(" UNION ")).all(...harnessTables.flatMap(() => deletableSessionIds));
|
|
665
|
+
const record = db.prepare("INSERT OR IGNORE INTO schema_migrations_meta (key, value) VALUES (?, ?)");
|
|
666
|
+
for (const owner of owners)
|
|
667
|
+
record.run(tagTombstoneOwnerKey(owner.session_id, owner.harness), owner.harness);
|
|
668
|
+
const fallback = db.prepare(`INSERT INTO schema_migrations_meta (key, value)
|
|
669
|
+
SELECT ?, ? WHERE NOT EXISTS (SELECT 1 FROM schema_migrations_meta WHERE key >= ? AND key < ?)`);
|
|
670
|
+
for (const id of deletableSessionIds)
|
|
671
|
+
fallback.run(tagTombstoneOwnerKey(id, getHarness2()), getHarness2(), ...tagTombstoneOwnerRange(id));
|
|
672
|
+
}
|
|
202
673
|
for (const sessionId of deletableSessionIds)
|
|
203
674
|
deleteChunkEmbedBackoffForSession(db, sessionId);
|
|
204
675
|
for (const definition of SESSION_SCOPED_TABLES) {
|
|
@@ -225,6 +696,22 @@ function deleteSessionScopedRows(db, sessionIds, harness, options = {}) {
|
|
|
225
696
|
statement.run(...deletableSessionIds);
|
|
226
697
|
}
|
|
227
698
|
deleteSessionActivity(db, deletableSessionIds);
|
|
699
|
+
if (!options.preserveTagRevisionTombstones) {
|
|
700
|
+
const retireOwner = db.prepare(harness === undefined ? "DELETE FROM schema_migrations_meta WHERE key >= ? AND key < ?" : "DELETE FROM schema_migrations_meta WHERE key = ?");
|
|
701
|
+
const survivingRows = harnessTables.map((definition) => `EXISTS (SELECT 1 FROM ${definition.table} WHERE session_id = ?${definition.extraPredicate ? ` AND ${definition.extraPredicate}` : ""})`).join(" OR ");
|
|
702
|
+
const retire = db.prepare(`DELETE FROM schema_migrations_meta WHERE key IN (?, ?)
|
|
703
|
+
AND NOT (${survivingRows})
|
|
704
|
+
AND NOT EXISTS (SELECT 1 FROM schema_migrations_meta AS owners WHERE owners.key >= ? AND owners.key < ?)`);
|
|
705
|
+
for (const id of deletableSessionIds) {
|
|
706
|
+
if (harness === undefined)
|
|
707
|
+
retireOwner.run(...tagTombstoneOwnerRange(id));
|
|
708
|
+
else
|
|
709
|
+
retireOwner.run(tagTombstoneOwnerKey(id, harness));
|
|
710
|
+
retire.run(tagIdentityRevisionKey(id), tagRevisionKey(id), ...harnessTables.map(() => id), ...tagTombstoneOwnerRange(id));
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
for (const sessionId of deletableSessionIds)
|
|
714
|
+
clearLkgRecoveryFence(sessionId);
|
|
228
715
|
return deletableSessionIds.length;
|
|
229
716
|
}
|
|
230
717
|
|
|
@@ -457,7 +944,7 @@ function toMessageIndexSource(message) {
|
|
|
457
944
|
role: message.role,
|
|
458
945
|
createdAt: message.createdAt,
|
|
459
946
|
sourceVersion: normalizeSourceVersion(message.version),
|
|
460
|
-
contentHash:
|
|
947
|
+
contentHash: createHash3("sha256").update(content).digest("hex"),
|
|
461
948
|
content
|
|
462
949
|
};
|
|
463
950
|
}
|
|
@@ -710,12 +1197,19 @@ function persistMessageHistoryOrphanSweepState(db, cursor, lastSweptAt, harness)
|
|
|
710
1197
|
last_swept_at = excluded.last_swept_at`).run(harness, cursor, lastSweptAt);
|
|
711
1198
|
}
|
|
712
1199
|
function getOpenCodeSessionScopedCandidateSourceSql(harness) {
|
|
713
|
-
|
|
1200
|
+
const sources = SESSION_SCOPED_TABLES.filter((definition) => definition.harnessScoped === true).map((definition) => {
|
|
714
1201
|
const predicates = ["session_id IS NOT NULL", `harness = '${harness}'`];
|
|
715
1202
|
if (definition.extraPredicate)
|
|
716
1203
|
predicates.push(definition.extraPredicate);
|
|
717
1204
|
return `SELECT session_id FROM ${definition.table} WHERE ${predicates.join(" AND ")}`;
|
|
718
|
-
})
|
|
1205
|
+
});
|
|
1206
|
+
const jsonId = `SUBSTR(key, ${TAG_TOMBSTONE_OWNER_PREFIX.length + 1}, LENGTH(key) - ${TAG_TOMBSTONE_OWNER_PREFIX.length + harness.length + 1})`;
|
|
1207
|
+
sources.push(`SELECT CASE WHEN json_valid(${jsonId}) THEN
|
|
1208
|
+
CASE WHEN json_type(${jsonId}) = 'text' THEN json_extract(${jsonId}, '$') END END AS session_id
|
|
1209
|
+
FROM schema_migrations_meta WHERE value = '${harness}'
|
|
1210
|
+
AND key >= '${TAG_TOMBSTONE_OWNER_PREFIX}' AND key < '${TAG_TOMBSTONE_OWNER_PREFIX.slice(0, -1)};'
|
|
1211
|
+
AND SUBSTR(key, -${harness.length + 1}) = ':${harness}'`);
|
|
1212
|
+
return sources.join(`
|
|
719
1213
|
UNION
|
|
720
1214
|
`);
|
|
721
1215
|
}
|
|
@@ -816,4 +1310,4 @@ function sweepOrphanedOpenCodeMessageIndexes(db, openReadableOpenCodeDb, options
|
|
|
816
1310
|
return withoutSqliteTransformPass2(() => withSqliteBackgroundWriter2(() => sweepOrphanedOpenCodeMessageIndexesInBackground(db, openReadableOpenCodeDb, options)));
|
|
817
1311
|
}
|
|
818
1312
|
|
|
819
|
-
export { advanceSessionActivity, observeSessionActivity, backfillSessionActivity, clearCompressionDepth, clearCompressionDepthRange, deleteSessionScopedRows, MESSAGE_INDEX_MAX_FTS_BYTES, messageIndexSkipKey, toMessageIndexSource, getMessageIndexSourceIdentity, isMessageIndexSourceCurrent, getLastIndexedOrdinal, getIndexedMessageCorpusSize, markMessageIndexDirty, getMessageIndexReconciliationStartOrdinal, isMessageIndexReconciledThrough, deleteIndexedMessage, clearIndexedMessagesInTransaction, clearIndexedMessages, getIndexableContent, indexSingleMessage, indexMessagesAfterOrdinal, indexSourcesAfterOrdinal, sweepOrphanedOpenCodeMessageIndexes };
|
|
1313
|
+
export { BoundedSessionMap, advanceSessionActivity, observeSessionActivity, backfillSessionActivity, clearCompressionDepth, clearCompressionDepthRange, LkgRecoveryFenceError, clearLkgFenceProcessState, lkgServedArrayDigest, hasCleanLkgRecoveryFence, lkgFenceRequiresRebuild, lkgRecoveryFenceUnclean, dirtyLkgRecoveryRevision, ownsLkgDirtyFence, invalidateCleanLkgRecoveryFence, prepareLkgCaptureFence, certifyCommittedLkgCapture, markLkgRecoveryDirty, commitLkgWithRecoveryFence, clearLkgRecoveryFence, deleteSessionScopedRows, MESSAGE_INDEX_MAX_FTS_BYTES, messageIndexSkipKey, toMessageIndexSource, getMessageIndexSourceIdentity, isMessageIndexSourceCurrent, getLastIndexedOrdinal, getIndexedMessageCorpusSize, markMessageIndexDirty, getMessageIndexReconciliationStartOrdinal, isMessageIndexReconciledThrough, deleteIndexedMessage, clearIndexedMessagesInTransaction, clearIndexedMessages, getIndexableContent, indexSingleMessage, indexMessagesAfterOrdinal, indexSourcesAfterOrdinal, sweepOrphanedOpenCodeMessageIndexes };
|