@cortexkit/opencode-magic-context 0.49.19 → 0.49.21
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/auto-search-worker.js +48 -9
- package/dist/chunk-embedding-write-worker.js +30 -23
- package/dist/{compaction-marker-candidates-n4krhat4.js → compaction-marker-candidates-31h86ph0.js} +3 -3
- package/dist/compaction-marker-candidates-worker.js +2 -2
- package/dist/compartment-chunk-embedding-he60aaa2.js +65 -0
- package/dist/config/project-security.d.ts.map +1 -1
- package/dist/config/schema/magic-context.d.ts +43 -9
- package/dist/config/schema/magic-context.d.ts.map +1 -1
- package/dist/{conflict-warning-hook-4pmz879v.js → conflict-warning-hook-2r32hyx6.js} +9 -8
- package/dist/{context-j31m2dv7.js → context-j7hp43a0.js} +576 -185
- package/dist/{derive-budgets-zn7yzd2d.js → derive-budgets-pqybnx09.js} +2 -2
- package/dist/embedding-backfill-dtke6tck.js +25 -0
- package/dist/embedding-worker-process.js +2 -2
- package/dist/embedding-worker.js +6 -6
- package/dist/features/magic-context/chunk-embedding-writer.d.ts.map +1 -1
- package/dist/features/magic-context/compartment-chunk-embedding.d.ts +44 -1
- package/dist/features/magic-context/compartment-chunk-embedding.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/docs-proposals.d.ts +1 -0
- package/dist/features/magic-context/dreamer/docs-proposals.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/hidden-single-shot.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-config.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-executor.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-scheduler.d.ts +2 -0
- package/dist/features/magic-context/dreamer/task-scheduler.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding-identity.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding-local.d.ts +1 -0
- package/dist/features/magic-context/memory/embedding-local.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding-synapse.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding-worker-client.d.ts +7 -1
- package/dist/features/magic-context/memory/embedding-worker-client.d.ts.map +1 -1
- package/dist/features/magic-context/memory/local-embedding-pooling.d.ts +22 -0
- package/dist/features/magic-context/memory/local-embedding-pooling.d.ts.map +1 -0
- package/dist/features/magic-context/message-index-async.d.ts +7 -2
- package/dist/features/magic-context/message-index-async.d.ts.map +1 -1
- package/dist/features/magic-context/message-index.d.ts +2 -0
- package/dist/features/magic-context/message-index.d.ts.map +1 -1
- package/dist/features/magic-context/mural/compress-cues.d.ts.map +1 -1
- package/dist/features/magic-context/project-embedding-registry.d.ts +2 -0
- package/dist/features/magic-context/project-embedding-registry.d.ts.map +1 -1
- package/dist/features/magic-context/search-rerank.d.ts +9 -2
- package/dist/features/magic-context/search-rerank.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/smart-notes/compiler.d.ts.map +1 -1
- package/dist/features/magic-context/storage-db.d.ts +2 -0
- package/dist/features/magic-context/storage-db.d.ts.map +1 -1
- package/dist/features/magic-context/storage-meta-persisted.d.ts +2 -0
- package/dist/features/magic-context/storage-meta-persisted.d.ts.map +1 -1
- package/dist/features/magic-context/subagent-token-capture.d.ts +20 -0
- package/dist/features/magic-context/subagent-token-capture.d.ts.map +1 -1
- package/dist/features/magic-context/user-memory/review-user-memories.d.ts.map +1 -1
- package/dist/{history-owner-xp3pngv7.js → history-owner-36wp3mkb.js} +2 -2
- package/dist/hooks/magic-context/apply-operations.d.ts.map +1 -1
- package/dist/hooks/magic-context/auto-embed-session.d.ts.map +1 -1
- package/dist/hooks/magic-context/auto-search-hint.d.ts +7 -1
- package/dist/hooks/magic-context/auto-search-hint.d.ts.map +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 +33 -6
- package/dist/hooks/magic-context/auto-search-worker-client.d.ts.map +1 -1
- package/dist/hooks/magic-context/cache-busting-signals.d.ts +6 -2
- package/dist/hooks/magic-context/cache-busting-signals.d.ts.map +1 -1
- package/dist/hooks/magic-context/channel2-delivery.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-historian.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-types.d.ts +5 -0
- package/dist/hooks/magic-context/compartment-runner-types.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-trigger.d.ts +1 -1
- package/dist/hooks/magic-context/compartment-trigger.d.ts.map +1 -1
- package/dist/hooks/magic-context/diagnostic-log-state.d.ts +4 -0
- package/dist/hooks/magic-context/diagnostic-log-state.d.ts.map +1 -0
- package/dist/hooks/magic-context/execute-reclaim.d.ts +35 -0
- package/dist/hooks/magic-context/execute-reclaim.d.ts.map +1 -0
- package/dist/hooks/magic-context/hook-handlers.d.ts.map +1 -1
- package/dist/hooks/magic-context/hook.d.ts +1 -3
- package/dist/hooks/magic-context/hook.d.ts.map +1 -1
- package/dist/hooks/magic-context/latest-assistant-turn.d.ts +8 -0
- package/dist/hooks/magic-context/latest-assistant-turn.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-recovery-fence.d.ts +5 -0
- package/dist/hooks/magic-context/lkg-recovery-fence.d.ts.map +1 -1
- package/dist/hooks/magic-context/nudge-evaluation-log.d.ts +3 -0
- package/dist/hooks/magic-context/nudge-evaluation-log.d.ts.map +1 -0
- package/dist/hooks/magic-context/pending-drop-eligibility.d.ts.map +1 -1
- package/dist/hooks/magic-context/protected-tail-boundary.d.ts +4 -0
- package/dist/hooks/magic-context/protected-tail-boundary.d.ts.map +1 -1
- package/dist/hooks/magic-context/raw-ordinal-warmup.d.ts.map +1 -1
- package/dist/hooks/magic-context/served-shape-repair.d.ts +19 -0
- package/dist/hooks/magic-context/served-shape-repair.d.ts.map +1 -0
- package/dist/hooks/magic-context/strip-content.d.ts +4 -2
- package/dist/hooks/magic-context/strip-content.d.ts.map +1 -1
- package/dist/hooks/magic-context/system-date-refresh.d.ts +5 -5
- package/dist/hooks/magic-context/system-prompt-hash.d.ts.map +1 -1
- package/dist/hooks/magic-context/system-prompt-sticky-date.d.ts +10 -0
- package/dist/hooks/magic-context/system-prompt-sticky-date.d.ts.map +1 -0
- package/dist/hooks/magic-context/tag-content-primitives.d.ts +1 -1
- package/dist/hooks/magic-context/tag-content-primitives.d.ts.map +1 -1
- package/dist/hooks/magic-context/tag-messages.d.ts +4 -1
- package/dist/hooks/magic-context/tag-messages.d.ts.map +1 -1
- package/dist/hooks/magic-context/text-complete.d.ts +1 -1
- package/dist/hooks/magic-context/text-complete.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-compartment-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +21 -6
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform.d.ts +2 -2
- package/dist/hooks/magic-context/transform.d.ts.map +1 -1
- package/dist/{index-3esx8tkf.js → index-11gzxvf4.js} +394 -125
- package/dist/{index-jn12fvvh.js → index-1gtfne2c.js} +3 -3
- package/dist/{index-jhghdnsm.js → index-1kbznkft.js} +521 -214
- package/dist/{index-3h4dp9wb.js → index-3svaejkh.js} +5 -5
- package/dist/{index-kee4kn5j.js → index-4pnsgvfk.js} +1 -1
- package/dist/{index-bjcnntmz.js → index-51rdvtkz.js} +501 -20
- package/dist/{v2/server-8cd2j99z.js → index-5kym00ag.js} +32 -13
- package/dist/{index-s74zqahq.js → index-66eby7hx.js} +4 -4
- package/dist/{index-63k48rv9.js → index-9q1g3c5q.js} +5 -5
- package/dist/{index-jrr131e0.js → index-a9zvn5fe.js} +29 -15
- package/dist/{index-c5pytzne.js → index-b88dwwrh.js} +1 -1
- package/dist/{index-nj7yykkx.js → index-c7phnbvk.js} +1 -1
- package/dist/index-cpjk5jd2.js +82 -0
- package/dist/{index-c1p88z1y.js → index-ffzhwfzy.js} +4 -4
- package/dist/{v2/server-beht37jy.js → index-gzy5w8ya.js} +194 -5
- package/dist/{index-j75v2476.js → index-h7tgn49j.js} +12 -15
- package/dist/{index-edmpdxcw.js → index-j32jj2t8.js} +5 -5
- package/dist/{index-ke416mdc.js → index-j76ah6d7.js} +2 -2
- package/dist/{index-s734jcsr.js → index-jfem3dgz.js} +9 -3
- package/dist/{index-n37sebck.js → index-jjvbk92s.js} +1 -1
- package/dist/{index-4911rn0b.js → index-jmq8kfe7.js} +6 -6
- package/dist/{index-rr2bb45z.js → index-kfyb3k6n.js} +2 -2
- package/dist/{index-2vxtcb95.js → index-kq5w68dp.js} +2 -2
- package/dist/{index-kq82mtg0.js → index-ksq50rg0.js} +3 -3
- package/dist/{index-b5vqckbw.js → index-m32esgmj.js} +314 -127
- package/dist/{index-9zcsy3hh.js → index-mnhcdfxg.js} +161 -13
- package/dist/{index-se4m2g6w.js → index-mnnkgq0q.js} +111 -19
- package/dist/{index-p5y3k4g7.js → index-nda0zgna.js} +2 -1
- package/dist/{index-wgypt3cs.js → index-nxrsns5x.js} +2466 -1290
- package/dist/{index-4s3t0nd0.js → index-qgh1qwjj.js} +2 -2
- package/dist/{index-y9f76s3f.js → index-rrv26qjz.js} +1 -1
- package/dist/{index-24fezq97.js → index-rxqr723x.js} +5 -5
- package/dist/{index-v10f1rjv.js → index-spwjbkc7.js} +1 -1
- package/dist/{index-dxmq29t1.js → index-syaazvy2.js} +182 -47
- package/dist/{index-k29z4aqh.js → index-t5pck3ss.js} +1 -1
- package/dist/{index-6x57ar45.js → index-wfybj1dw.js} +4 -6
- package/dist/{index-cf74k5ak.js → index-whcgcfrv.js} +9 -6
- package/dist/{index-a6mc0v4d.js → index-x6cbrv9h.js} +3 -3
- package/dist/{index-bp5083x2.js → index-x9k3mqrf.js} +1 -1
- package/dist/{index-rpxdjkm0.js → index-y76rhsnr.js} +319 -61
- package/dist/{index-ze7mvk54.js → index-zy67whjr.js} +95 -59
- package/dist/index.js +58 -54
- package/dist/{logger-jm3sqqzr.js → logger-94kew5wm.js} +1 -1
- package/dist/{message-fts-rowid-map-17s0dfn4.js → message-fts-rowid-map-e79b7b6x.js} +6 -5
- package/dist/{message-index-gtpqnj8w.js → message-index-4q8ek2fc.js} +17 -16
- package/dist/{message-index-bounded-zyc8h32y.js → message-index-bounded-rydsg9r5.js} +17 -16
- package/dist/{message-time-backfill-73mmm76q.js → message-time-backfill-4qva0b4f.js} +3 -3
- package/dist/migration-worker.js +13 -12
- package/dist/{model-resolution-nx97z3x7.js → model-resolution-280gmqvd.js} +1 -1
- package/dist/plugin/embedding-bootstrap.d.ts +4 -1
- package/dist/plugin/embedding-bootstrap.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/rpc-handlers.d.ts +8 -0
- package/dist/plugin/rpc-handlers.d.ts.map +1 -1
- package/dist/plugin/subagent-tool-policy.d.ts +9 -0
- package/dist/plugin/subagent-tool-policy.d.ts.map +1 -1
- package/dist/plugin/tool-registry.d.ts.map +1 -1
- package/dist/{project-embedding-registry-z74mhqkf.js → project-embedding-registry-hn529988.js} +16 -13
- package/dist/raw-ordinal-warmup-worker.js +136 -101
- package/dist/{read-session-chunk-jjb48bt9.js → read-session-chunk-t039f0m5.js} +12 -11
- package/dist/{read-session-raw-rsc8c7qy.js → read-session-raw-aw6jgvwg.js} +4 -3
- package/dist/recomp-orchestrator-hbm53jj5.js +62 -0
- package/dist/{safe-notification-target-1szv1k5k.js → safe-notification-target-mkr9yzvr.js} +2 -2
- package/dist/search-archive-weh164mh.js +26 -0
- package/dist/search-hea079d7.js +50 -0
- package/dist/{send-session-notification-6ve0e8p4.js → send-session-notification-gqzkz7da.js} +7 -6
- package/dist/shared/logger.d.ts.map +1 -1
- package/dist/shared/model-resolution.d.ts +2 -0
- package/dist/shared/model-resolution.d.ts.map +1 -1
- package/dist/shared/prompt-async-transport.d.ts +3 -0
- package/dist/shared/prompt-async-transport.d.ts.map +1 -1
- package/dist/shared/rpc-types.d.ts +7 -0
- package/dist/shared/rpc-types.d.ts.map +1 -1
- package/dist/shared/sqlite.d.ts +6 -1
- package/dist/shared/sqlite.d.ts.map +1 -1
- package/dist/shared/subagent-runner.d.ts +2 -0
- package/dist/shared/subagent-runner.d.ts.map +1 -1
- package/dist/shared/tag-transcript.d.ts +2 -0
- package/dist/shared/tag-transcript.d.ts.map +1 -1
- package/dist/shared/worker-shutdown.d.ts +68 -0
- package/dist/shared/worker-shutdown.d.ts.map +1 -0
- package/dist/shared/worker-shutdown.fixture.d.ts +2 -0
- package/dist/shared/worker-shutdown.fixture.d.ts.map +1 -0
- package/dist/{sqlite-zf72c52d.js → sqlite-zdgm52sv.js} +5 -1
- package/dist/{storage-memory-y3qmy00r.js → storage-memory-e6a7mb0k.js} +2 -2
- package/dist/{storage-tags-r7k9tjcv.js → storage-tags-a77q4v77.js} +5 -5
- package/dist/{task-config-x3qmayd2.js → task-config-t6bpyka7.js} +2 -2
- 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-jj99r7z2.js → transform-postprocess-phase-0b04tm1p.js} +35 -32
- package/dist/v2/auto-search-worker.js +48 -9
- package/dist/v2/chunk-embedding-write-worker.js +30 -23
- package/dist/v2/{compaction-marker-candidates-ebx3388k.js → compaction-marker-candidates-m4vmye3w.js} +3 -3
- package/dist/v2/compaction-marker-candidates-worker.js +2 -2
- package/dist/v2/compartment-chunk-embedding-8jjmcgeg.js +64 -0
- package/dist/v2/{context-y5yamxak.js → context-ea3x7smm.js} +1797 -810
- package/dist/v2/{derive-budgets-2zh4gm2c.js → derive-budgets-knf763tt.js} +3 -3
- package/dist/v2/embedding-backfill-5e74ae0m.js +24 -0
- package/dist/v2/embedding-worker-process.js +2 -2
- package/dist/v2/embedding-worker.js +6 -6
- package/dist/v2/hidden-child-record.d.ts +2 -0
- package/dist/v2/hidden-child-record.d.ts.map +1 -1
- package/dist/v2/hidden-completion.d.ts +2 -0
- package/dist/v2/hidden-completion.d.ts.map +1 -1
- package/dist/v2/hidden-model-activity.d.ts +7 -0
- package/dist/v2/hidden-model-activity.d.ts.map +1 -0
- package/dist/v2/{history-owner-42e16w0n.js → history-owner-ad0crnrn.js} +2 -2
- package/dist/v2/hooks/context.d.ts.map +1 -1
- package/dist/v2/hooks/copied-tag-notation.d.ts +1 -1
- package/dist/v2/hooks/copied-tag-notation.d.ts.map +1 -1
- package/dist/v2/hooks/dream-timer.d.ts +2 -0
- package/dist/v2/hooks/dream-timer.d.ts.map +1 -1
- package/dist/v2/hooks/embedding-lifecycle.d.ts +7 -0
- package/dist/v2/hooks/embedding-lifecycle.d.ts.map +1 -0
- package/dist/v2/hooks/generate.d.ts +36 -1
- package/dist/v2/hooks/generate.d.ts.map +1 -1
- package/dist/v2/hooks/lkg-system.d.ts +35 -4
- package/dist/v2/hooks/lkg-system.d.ts.map +1 -1
- package/dist/v2/hooks/payload.d.ts +16 -1
- package/dist/v2/hooks/payload.d.ts.map +1 -1
- package/dist/v2/hooks/store.d.ts +2 -0
- package/dist/v2/hooks/store.d.ts.map +1 -1
- package/dist/v2/hooks/tools.d.ts +2 -1
- package/dist/v2/hooks/tools.d.ts.map +1 -1
- package/dist/v2/hooks/transform-features.d.ts +2 -2
- package/dist/v2/hooks/transform-features.d.ts.map +1 -1
- package/dist/v2/{logger-7qt02bnb.js → logger-p34mjtja.js} +1 -1
- package/dist/v2/{message-fts-rowid-map-wfx67gfd.js → message-fts-rowid-map-n8fdg2ja.js} +6 -5
- package/dist/v2/{message-index-bounded-spd8r7pj.js → message-index-bounded-8rcd7qq9.js} +17 -16
- package/dist/v2/{message-index-8vz2pq76.js → message-index-qz9wdp82.js} +17 -16
- package/dist/v2/{message-time-backfill-04t0km1z.js → message-time-backfill-zvthw6xb.js} +3 -3
- package/dist/v2/migration-worker.js +13 -12
- package/dist/v2/{model-resolution-nx97z3x7.js → model-resolution-280gmqvd.js} +1 -1
- package/dist/v2/{project-embedding-registry-gnkj56xp.js → project-embedding-registry-v38q4xd5.js} +16 -13
- package/dist/v2/raw-ordinal-warmup-worker.js +136 -101
- package/dist/v2/{read-session-chunk-cwkxrmns.js → read-session-chunk-wazfyxcg.js} +12 -11
- package/dist/v2/{read-session-raw-yaegtjzh.js → read-session-raw-b70cpwzj.js} +4 -3
- package/dist/v2/recomp-orchestrator-b12zaptj.js +61 -0
- package/dist/v2/{safe-notification-target-qg7n2s77.js → safe-notification-target-khnzg57c.js} +2 -2
- package/dist/v2/search-archive-x64rtz1z.js +25 -0
- package/dist/v2/search-hza9x72a.js +49 -0
- package/dist/v2/{send-session-notification-3pxn658x.js → send-session-notification-8eqe259v.js} +7 -6
- package/dist/v2/{server-45q69hkq.js → server-132h8twc.js} +5 -5
- package/dist/v2/{server-h0410h0v.js → server-1bw1wcbp.js} +1 -1
- package/dist/v2/{server-271qxsf5.js → server-24g8r2d0.js} +2466 -1290
- package/dist/v2/{server-tbe1femw.js → server-29qp8nz4.js} +1 -1
- package/dist/v2/{server-gsxjv2q2.js → server-33nqbqkw.js} +182 -47
- package/dist/v2/{server-tgnbmwah.js → server-3mz2qh5a.js} +1 -1
- package/dist/v2/{server-n1prf1g6.js → server-3vhxy2k5.js} +2 -2
- package/dist/v2/{server-xj136kt8.js → server-4kjmrjn4.js} +9 -3
- package/dist/v2/{server-34kwfsr4.js → server-53eh1r8r.js} +2 -2
- package/dist/{index-8cd2j99z.js → v2/server-5kym00ag.js} +32 -13
- package/dist/v2/{server-46neh5fa.js → server-62g58aaz.js} +314 -127
- package/dist/v2/{server-f2xf5gcb.js → server-6495nmn9.js} +12 -15
- package/dist/v2/{server-a9xqj88f.js → server-6v3cdzsx.js} +4 -4
- package/dist/v2/{server-d04vrx0j.js → server-806rzhs6.js} +2 -2
- package/dist/v2/{server-qd11g795.js → server-92g7d776.js} +2 -1
- package/dist/v2/{server-nj659894.js → server-94wk1ey3.js} +14 -3
- package/dist/v2/{server-6tmj0s7j.js → server-ab1g0wn9.js} +4 -6
- package/dist/v2/{server-8by8qfec.js → server-ad18djzs.js} +95 -59
- package/dist/v2/{server-hy3d3vsx.js → server-bsgd4dk1.js} +2 -2
- package/dist/v2/server-cpjk5jd2.js +82 -0
- package/dist/v2/{server-g3qma5c0.js → server-d1dzgvwd.js} +2 -2
- package/dist/v2/{server-hm38q7r0.js → server-d48x3m4x.js} +5 -5
- package/dist/v2/{server-1wy7b9de.js → server-dtp8hcjh.js} +3 -3
- package/dist/v2/{server-27gq4mfz.js → server-fa7vtp40.js} +9 -6
- package/dist/v2/{server-6pmqg9m4.js → server-gyy4k6mf.js} +1 -1
- package/dist/{index-beht37jy.js → v2/server-gzy5w8ya.js} +194 -5
- package/dist/v2/{server-bmymkx73.js → server-j8h7bsca.js} +29 -15
- package/dist/v2/{server-n37sebck.js → server-jjvbk92s.js} +1 -1
- package/dist/v2/{server-da07v4xp.js → server-k3t06fxr.js} +1 -1
- package/dist/v2/{server-9hx7g5jp.js → server-m4bfaevz.js} +1197 -1049
- package/dist/v2/{server-2ar62dyx.js → server-ppcd1qxh.js} +191 -99
- package/dist/v2/{server-rmygf5pn.js → server-qjvk4a9t.js} +2 -2
- package/dist/v2/{server-zzkj2fch.js → server-qteg2kt9.js} +5 -5
- package/dist/v2/{server-pwv4ezb0.js → server-rqebawx1.js} +2 -2
- package/dist/v2/{server-h1v0pyxb.js → server-vr4szghm.js} +501 -20
- package/dist/v2/{server-xq7dfjke.js → server-wwaw5npa.js} +5 -5
- package/dist/v2/{server-6vdzn1td.js → server-zg5y109h.js} +323 -76
- package/dist/v2/server.js +8 -8
- package/dist/v2/{sqlite-zf72c52d.js → sqlite-zdgm52sv.js} +5 -1
- package/dist/v2/{storage-memory-y3qmy00r.js → storage-memory-e6a7mb0k.js} +2 -2
- package/dist/v2/{storage-tags-3wdb8zph.js → storage-tags-q71rnr9f.js} +5 -5
- package/dist/v2/store-reader.d.ts +10 -0
- package/dist/v2/store-reader.d.ts.map +1 -1
- package/dist/v2/{task-config-nvz8mapa.js → task-config-7md27rx8.js} +2 -2
- package/dist/v2/{wrapup-orchestrator-embdz8gj.js → wrapup-orchestrator-3ssd5yy1.js} +33 -32
- package/dist/wrapup-orchestrator-5vpcd1zx.js +49 -0
- package/package.json +2 -2
- package/src/config/index.test.ts +72 -6
- package/src/config/project-security.ts +15 -0
- package/src/config/rerank.test.ts +60 -0
- package/src/config/schema/magic-context.ts +57 -0
- package/src/shared/logger.test.ts +42 -1
- package/src/shared/logger.ts +11 -13
- package/src/shared/model-resolution.test.ts +67 -12
- package/src/shared/model-resolution.ts +43 -16
- package/src/shared/model-suggestion-retry.ts +2 -2
- package/src/shared/prompt-async-transport.ts +47 -3
- package/src/shared/rpc-types.ts +7 -0
- package/src/shared/sqlite-busy-budget-review.test.ts +6 -1
- package/src/shared/sqlite-turn-deadline.test.ts +270 -0
- package/src/shared/sqlite.ts +239 -9
- package/src/shared/subagent-runner.ts +2 -0
- package/src/shared/tag-transcript.ts +9 -1
- package/src/shared/worker-shutdown-fence.test.ts +87 -0
- package/src/shared/worker-shutdown.fixture.ts +25 -0
- package/src/shared/worker-shutdown.test.ts +127 -0
- package/src/shared/worker-shutdown.ts +160 -0
- package/dist/embedding-backfill-fmz50tsy.js +0 -24
- package/dist/recomp-orchestrator-999jj4bc.js +0 -61
- package/dist/search-archive-6vm0e2f5.js +0 -25
- package/dist/search-xsqk1bj4.js +0 -49
- package/dist/v2/embedding-backfill-7c7yr69y.js +0 -23
- package/dist/v2/recomp-orchestrator-f6m9jr7p.js +0 -60
- package/dist/v2/search-archive-wve3tq1k.js +0 -24
- package/dist/v2/search-hwg7jfbj.js +0 -48
- package/dist/wrapup-orchestrator-whhbjmaz.js +0 -48
|
@@ -44,6 +44,11 @@ import {
|
|
|
44
44
|
HiddenChildHook,
|
|
45
45
|
parseProviderModel,
|
|
46
46
|
toModelEntry,
|
|
47
|
+
ModelProducedNoOutputError,
|
|
48
|
+
noteModelActivityMonitored,
|
|
49
|
+
noteModelOutputReceived,
|
|
50
|
+
annotateSubagentInvocationError,
|
|
51
|
+
recordChildInvocation,
|
|
47
52
|
CTX_NOTE_LIGHT_DESCRIPTION,
|
|
48
53
|
ACTIVE_TOOL_IDS,
|
|
49
54
|
createPromptSurfaceRuntime,
|
|
@@ -54,7 +59,7 @@ import {
|
|
|
54
59
|
rebaseSessionCoordinatesAsync,
|
|
55
60
|
resolveOpenCodeProtectedTailBoundary,
|
|
56
61
|
getActiveCompartmentRun
|
|
57
|
-
} from "./index-
|
|
62
|
+
} from "./index-y76rhsnr.js";
|
|
58
63
|
import"./index-sd3egckz.js";
|
|
59
64
|
import {
|
|
60
65
|
getHarness2
|
|
@@ -66,7 +71,7 @@ import {
|
|
|
66
71
|
import {
|
|
67
72
|
log2,
|
|
68
73
|
sessionLog2
|
|
69
|
-
} from "./index-
|
|
74
|
+
} from "./index-h7tgn49j.js";
|
|
70
75
|
import {
|
|
71
76
|
isSaneLimit,
|
|
72
77
|
setOutputReserveConfig,
|
|
@@ -76,8 +81,8 @@ import {
|
|
|
76
81
|
deriveHistorianChunkTokens2,
|
|
77
82
|
resolveKnownHistorianContextLimit2,
|
|
78
83
|
resolveHistorianContextLimit2
|
|
79
|
-
} from "./index-
|
|
80
|
-
import"./index-
|
|
84
|
+
} from "./index-spwjbkc7.js";
|
|
85
|
+
import"./index-nxrsns5x.js";
|
|
81
86
|
import {
|
|
82
87
|
CANONICAL_DREAM_TASKS,
|
|
83
88
|
DREAM_TASK_CAPABILITIES,
|
|
@@ -86,7 +91,7 @@ import {
|
|
|
86
91
|
buildDreamTaskRuntimeConfigs2,
|
|
87
92
|
userObservationCollectionEnabled2,
|
|
88
93
|
userObservationsRequested2
|
|
89
|
-
} from "./index-
|
|
94
|
+
} from "./index-nda0zgna.js";
|
|
90
95
|
import {
|
|
91
96
|
logConfigDependencyNotesOnce,
|
|
92
97
|
runSessionProjectBackfill,
|
|
@@ -96,6 +101,7 @@ import {
|
|
|
96
101
|
createDreamTaskExecutor,
|
|
97
102
|
runManualDream,
|
|
98
103
|
runDueTasksForProject,
|
|
104
|
+
scheduleClearAndReindex,
|
|
99
105
|
startDreamScheduleTimer,
|
|
100
106
|
createDreamTimerModuleClient,
|
|
101
107
|
ensureProjectRegisteredFromOpenCodeDirectory,
|
|
@@ -132,6 +138,8 @@ import {
|
|
|
132
138
|
createMessagesTransformHandler,
|
|
133
139
|
subagentToolRefusal,
|
|
134
140
|
hideSubagentTools,
|
|
141
|
+
removePrimaryOnlyTools,
|
|
142
|
+
storedSubagentMode,
|
|
135
143
|
createCtxExpandTools,
|
|
136
144
|
createCtxMemoryTools,
|
|
137
145
|
createCtxMemoryListTools,
|
|
@@ -143,10 +151,10 @@ import {
|
|
|
143
151
|
applyJsonSchemaParameterDescriptions,
|
|
144
152
|
MagicContextRpcServer,
|
|
145
153
|
subagentTemperature
|
|
146
|
-
} from "./index-
|
|
154
|
+
} from "./index-11gzxvf4.js";
|
|
147
155
|
import {
|
|
148
156
|
resolveHistorianModel2
|
|
149
|
-
} from "./index-
|
|
157
|
+
} from "./index-5kym00ag.js";
|
|
150
158
|
import {
|
|
151
159
|
formatFailClosedBlockingMessage,
|
|
152
160
|
formatFailClosedBlockingSummary,
|
|
@@ -158,12 +166,49 @@ import {
|
|
|
158
166
|
openDatabaseAsync,
|
|
159
167
|
isDatabasePersisted,
|
|
160
168
|
getDatabasePersistenceError
|
|
161
|
-
} from "./index-
|
|
169
|
+
} from "./index-a9zvn5fe.js";
|
|
162
170
|
import {
|
|
163
171
|
setHomeProjectPermission,
|
|
164
172
|
resolveProjectIdentityForSession,
|
|
165
173
|
scheduleAfterBootQuiet
|
|
166
|
-
} from "./index-
|
|
174
|
+
} from "./index-kq5w68dp.js";
|
|
175
|
+
import"./index-c7phnbvk.js";
|
|
176
|
+
import {
|
|
177
|
+
BoundedSessionMap,
|
|
178
|
+
advanceSessionActivity,
|
|
179
|
+
backfillSessionActivity,
|
|
180
|
+
gaDatabasePath,
|
|
181
|
+
RAW_MESSAGE_TYPES,
|
|
182
|
+
V2StoreReaderPool,
|
|
183
|
+
V2StoreReader
|
|
184
|
+
} from "./index-mnnkgq0q.js";
|
|
185
|
+
import"./index-v0p37hm2.js";
|
|
186
|
+
import {
|
|
187
|
+
inRootAsyncContext2,
|
|
188
|
+
withSqliteTransformPass2,
|
|
189
|
+
withoutSqliteTransformPass2,
|
|
190
|
+
isTransientSqliteError2,
|
|
191
|
+
withAsyncPrivilegedWriter2
|
|
192
|
+
} from "./index-gzy5w8ya.js";
|
|
193
|
+
import"./index-cpjk5jd2.js";
|
|
194
|
+
import"./index-jfem3dgz.js";
|
|
195
|
+
import"./index-58e3y90n.js";
|
|
196
|
+
import"./index-1zx87sdm.js";
|
|
197
|
+
import {
|
|
198
|
+
stripPersistedAssistantText,
|
|
199
|
+
currentReclaimableToolOutputCount,
|
|
200
|
+
isRecord,
|
|
201
|
+
isDroppedToolOutput,
|
|
202
|
+
evaluateChannel2,
|
|
203
|
+
buildChannel2Reminder
|
|
204
|
+
} from "./index-whcgcfrv.js";
|
|
205
|
+
import {
|
|
206
|
+
hasMeaningfulUserText2,
|
|
207
|
+
preloadTokenizer,
|
|
208
|
+
estimateTokens
|
|
209
|
+
} from "./index-b88dwwrh.js";
|
|
210
|
+
import"./index-x9k3mqrf.js";
|
|
211
|
+
import"./index-ksq50rg0.js";
|
|
167
212
|
import {
|
|
168
213
|
needsBlockedRead,
|
|
169
214
|
markHostUnservedRow,
|
|
@@ -191,6 +236,7 @@ import {
|
|
|
191
236
|
getObservedEpochFloor,
|
|
192
237
|
detectOverflow,
|
|
193
238
|
modelAcceptsEmptyContent,
|
|
239
|
+
markServedShapeRepair,
|
|
194
240
|
getEmptyImageParts,
|
|
195
241
|
estimateFinalWireInputTokens,
|
|
196
242
|
hasRawMessageProvider2,
|
|
@@ -198,62 +244,28 @@ import {
|
|
|
198
244
|
cleanUserText2,
|
|
199
245
|
readRawSessionMessageIdOrdinalsForRange2,
|
|
200
246
|
readRawSessionMessageOrdinalById2
|
|
201
|
-
} from "./index-
|
|
202
|
-
import {
|
|
203
|
-
invalidateAutoEmbedSession,
|
|
204
|
-
clearEmbedSessionState
|
|
205
|
-
} from "./index-ze7mvk54.js";
|
|
206
|
-
import {
|
|
207
|
-
hasMeaningfulUserText2,
|
|
208
|
-
preloadTokenizer,
|
|
209
|
-
estimateTokens
|
|
210
|
-
} from "./index-c5pytzne.js";
|
|
211
|
-
import"./index-6x57ar45.js";
|
|
212
|
-
import {
|
|
213
|
-
inRootAsyncContext2,
|
|
214
|
-
withSqliteTransformPass2,
|
|
215
|
-
withoutSqliteTransformPass2,
|
|
216
|
-
isTransientSqliteError2,
|
|
217
|
-
withAsyncPrivilegedWriter2
|
|
218
|
-
} from "./index-beht37jy.js";
|
|
219
|
-
import"./index-v0p37hm2.js";
|
|
220
|
-
import"./index-s734jcsr.js";
|
|
221
|
-
import"./index-a6mc0v4d.js";
|
|
222
|
-
import {
|
|
223
|
-
deleteChunkEmbedBackoffForSession
|
|
224
|
-
} from "./index-b5vqckbw.js";
|
|
225
|
-
import"./index-nj7yykkx.js";
|
|
226
|
-
import {
|
|
227
|
-
BoundedSessionMap,
|
|
228
|
-
advanceSessionActivity,
|
|
229
|
-
backfillSessionActivity,
|
|
230
|
-
gaDatabasePath,
|
|
231
|
-
RAW_MESSAGE_TYPES,
|
|
232
|
-
V2StoreReaderPool,
|
|
233
|
-
V2StoreReader
|
|
234
|
-
} from "./index-se4m2g6w.js";
|
|
235
|
-
import"./index-bp5083x2.js";
|
|
236
|
-
import"./index-1zx87sdm.js";
|
|
237
|
-
import {
|
|
238
|
-
stripPersistedAssistantText,
|
|
239
|
-
currentReclaimableToolOutputCount,
|
|
240
|
-
isDroppedToolOutput,
|
|
241
|
-
evaluateChannel2,
|
|
242
|
-
buildChannel2Reminder
|
|
243
|
-
} from "./index-cf74k5ak.js";
|
|
244
|
-
import"./index-58e3y90n.js";
|
|
245
|
-
import"./index-kq82mtg0.js";
|
|
247
|
+
} from "./index-mnhcdfxg.js";
|
|
246
248
|
import {
|
|
247
249
|
getCurrentToolSetHash,
|
|
248
250
|
recordToolDefinition
|
|
249
|
-
} from "./index-
|
|
251
|
+
} from "./index-j76ah6d7.js";
|
|
252
|
+
import"./index-x6cbrv9h.js";
|
|
253
|
+
import"./index-wfybj1dw.js";
|
|
254
|
+
import {
|
|
255
|
+
deleteChunkEmbedBackoffForSession2
|
|
256
|
+
} from "./index-m32esgmj.js";
|
|
257
|
+
import {
|
|
258
|
+
invalidateAutoEmbedSession,
|
|
259
|
+
clearEmbedSessionState,
|
|
260
|
+
retainProjectEmbedding2
|
|
261
|
+
} from "./index-zy67whjr.js";
|
|
250
262
|
import"./index-fr0wbhdn.js";
|
|
251
|
-
import"./index-
|
|
263
|
+
import"./index-9q1g3c5q.js";
|
|
252
264
|
import"./index-fb3zxn06.js";
|
|
253
265
|
import {
|
|
254
266
|
renderUserFacingFailure,
|
|
255
267
|
userFacingFailureCode
|
|
256
|
-
} from "./index-
|
|
268
|
+
} from "./index-3svaejkh.js";
|
|
257
269
|
import {
|
|
258
270
|
createTagger,
|
|
259
271
|
cavemanWordRulesForLanguage,
|
|
@@ -262,29 +274,29 @@ import {
|
|
|
262
274
|
EmergencyFailClosedError,
|
|
263
275
|
DegradedPassRefusalError,
|
|
264
276
|
isSyntheticHeadMessage2
|
|
265
|
-
} from "./index-
|
|
266
|
-
import"./index-
|
|
277
|
+
} from "./index-1kbznkft.js";
|
|
278
|
+
import"./index-qgh1qwjj.js";
|
|
267
279
|
import"./index-qt1qqasc.js";
|
|
268
|
-
import"./index-
|
|
280
|
+
import"./index-kfyb3k6n.js";
|
|
269
281
|
import"./index-4dhv7mqz.js";
|
|
270
|
-
import"./index-
|
|
271
|
-
import"./index-
|
|
272
|
-
import"./index-
|
|
282
|
+
import"./index-51rdvtkz.js";
|
|
283
|
+
import"./index-rxqr723x.js";
|
|
284
|
+
import"./index-jjvbk92s.js";
|
|
273
285
|
import {
|
|
274
286
|
pushNotification2,
|
|
275
287
|
isTuiConnected2
|
|
276
288
|
} from "./index-x8a7jmkh.js";
|
|
277
|
-
import"./index-
|
|
278
|
-
import"./index-
|
|
279
|
-
import"./index-
|
|
280
|
-
import"./index-
|
|
289
|
+
import"./index-rrv26qjz.js";
|
|
290
|
+
import"./index-66eby7hx.js";
|
|
291
|
+
import"./index-syaazvy2.js";
|
|
292
|
+
import"./index-ffzhwfzy.js";
|
|
281
293
|
import"./index-gp3kcpc4.js";
|
|
282
294
|
import {
|
|
283
295
|
detectConflicts
|
|
284
|
-
} from "./index-
|
|
296
|
+
} from "./index-4pnsgvfk.js";
|
|
285
297
|
import"./index-fmsr7v69.js";
|
|
286
298
|
import"./index-kaqs6h31.js";
|
|
287
|
-
import"./index-
|
|
299
|
+
import"./index-j32jj2t8.js";
|
|
288
300
|
import {
|
|
289
301
|
isDreamerRunnable,
|
|
290
302
|
isSmartNoteSurfaceAvailable,
|
|
@@ -296,7 +308,7 @@ import {
|
|
|
296
308
|
import {
|
|
297
309
|
getErrorMessage
|
|
298
310
|
} from "./index-y8v6yerm.js";
|
|
299
|
-
import"./index-
|
|
311
|
+
import"./index-t5pck3ss.js";
|
|
300
312
|
|
|
301
313
|
// src/v2/hooks/context.ts
|
|
302
314
|
import { setTimeout as delay } from "node:timers/promises";
|
|
@@ -350,7 +362,7 @@ function dropCompartmentsAfter(db, sessionId, anchor, holderId, activeBranch = f
|
|
|
350
362
|
if (marker && clearPendingPiCompactionMarkerStateIf(db, sessionId, marker, null))
|
|
351
363
|
clearedMarker = marker;
|
|
352
364
|
}
|
|
353
|
-
|
|
365
|
+
deleteChunkEmbedBackoffForSession2(db, sessionId);
|
|
354
366
|
queueM0Mutation(db, { sessionId, mutationType: "recomp_boundary_change" });
|
|
355
367
|
clearCachedM0M1(db, sessionId);
|
|
356
368
|
db.exec("COMMIT");
|
|
@@ -602,9 +614,9 @@ function trimToRecordedBoundary(db, sessionId, messages) {
|
|
|
602
614
|
}
|
|
603
615
|
|
|
604
616
|
// src/v2/fold/host-media.ts
|
|
605
|
-
var
|
|
617
|
+
var isRecord2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
606
618
|
function isClassInstance(value) {
|
|
607
|
-
if (!
|
|
619
|
+
if (!isRecord2(value))
|
|
608
620
|
return false;
|
|
609
621
|
const prototype = Object.getPrototypeOf(value);
|
|
610
622
|
return prototype !== Object.prototype && prototype !== null;
|
|
@@ -623,10 +635,10 @@ function rememberHostMedia(messages) {
|
|
|
623
635
|
if (!Array.isArray(content))
|
|
624
636
|
continue;
|
|
625
637
|
for (const part of content) {
|
|
626
|
-
if (!
|
|
638
|
+
if (!isRecord2(part) || part.type !== "media")
|
|
627
639
|
continue;
|
|
628
640
|
const media = part.media;
|
|
629
|
-
if (isClassInstance(media) &&
|
|
641
|
+
if (isClassInstance(media) && isRecord2(media.source)) {
|
|
630
642
|
rememberedAssetClass = Object.getPrototypeOf(media).constructor;
|
|
631
643
|
return;
|
|
632
644
|
}
|
|
@@ -683,7 +695,7 @@ function hostMediaAsset(data, mediaType) {
|
|
|
683
695
|
return hostMediaFromEncoded({ source: { type: "base64", data, mediaType } });
|
|
684
696
|
}
|
|
685
697
|
function hostMediaFromEncoded(value) {
|
|
686
|
-
if (!
|
|
698
|
+
if (!isRecord2(value.source))
|
|
687
699
|
return "missing Media.Asset source";
|
|
688
700
|
const encoded = structuredClone(value);
|
|
689
701
|
if (encoded.source.type === "bytes") {
|
|
@@ -1026,8 +1038,8 @@ function toolStateContent(state) {
|
|
|
1026
1038
|
}
|
|
1027
1039
|
|
|
1028
1040
|
// src/v2/hooks/copied-tag-notation.ts
|
|
1029
|
-
function stripCopiedTagNotation(text) {
|
|
1030
|
-
return text.includes("§") ? stripPersistedAssistantText(text) : text;
|
|
1041
|
+
function stripCopiedTagNotation(text, acceptsEmpty = true) {
|
|
1042
|
+
return text.includes("§") ? stripPersistedAssistantText(text, acceptsEmpty) : text;
|
|
1031
1043
|
}
|
|
1032
1044
|
|
|
1033
1045
|
// src/v2/hooks/payload.ts
|
|
@@ -1094,18 +1106,56 @@ function containsHostInstance(value) {
|
|
|
1094
1106
|
return false;
|
|
1095
1107
|
}
|
|
1096
1108
|
function clonePreservingInstances(value) {
|
|
1097
|
-
|
|
1109
|
+
return cloneCounting(value, undefined);
|
|
1110
|
+
}
|
|
1111
|
+
function clonePreservingInstancesMeasured(value) {
|
|
1112
|
+
const meter = { bytes: 0 };
|
|
1113
|
+
const copy = cloneCounting(value, meter);
|
|
1114
|
+
return { copy, bytes: meter.bytes };
|
|
1115
|
+
}
|
|
1116
|
+
function cloneCounting(value, meter) {
|
|
1117
|
+
if (isHostInstance(value)) {
|
|
1118
|
+
if (meter)
|
|
1119
|
+
meter.bytes += instanceBytes(value, new WeakSet);
|
|
1098
1120
|
return value;
|
|
1099
|
-
|
|
1100
|
-
|
|
1121
|
+
}
|
|
1122
|
+
if (Array.isArray(value)) {
|
|
1123
|
+
if (meter)
|
|
1124
|
+
meter.bytes += 16 + 8 * value.length;
|
|
1125
|
+
return value.map((entry) => cloneCounting(entry, meter));
|
|
1126
|
+
}
|
|
1101
1127
|
if (value && typeof value === "object") {
|
|
1102
1128
|
const copy = {};
|
|
1103
|
-
|
|
1104
|
-
|
|
1129
|
+
if (meter)
|
|
1130
|
+
meter.bytes += 32;
|
|
1131
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
1132
|
+
if (meter)
|
|
1133
|
+
meter.bytes += 16;
|
|
1134
|
+
copy[key] = cloneCounting(entry, meter);
|
|
1135
|
+
}
|
|
1105
1136
|
return copy;
|
|
1106
1137
|
}
|
|
1138
|
+
if (meter)
|
|
1139
|
+
meter.bytes += typeof value === "string" ? 2 * value.length : 8;
|
|
1107
1140
|
return value;
|
|
1108
1141
|
}
|
|
1142
|
+
function instanceBytes(value, seen) {
|
|
1143
|
+
if (typeof value === "string")
|
|
1144
|
+
return 2 * value.length;
|
|
1145
|
+
if (!value || typeof value !== "object")
|
|
1146
|
+
return 8;
|
|
1147
|
+
if (seen.has(value))
|
|
1148
|
+
return 0;
|
|
1149
|
+
seen.add(value);
|
|
1150
|
+
if (ArrayBuffer.isView(value))
|
|
1151
|
+
return value.byteLength;
|
|
1152
|
+
if (value instanceof ArrayBuffer)
|
|
1153
|
+
return value.byteLength;
|
|
1154
|
+
let bytes = 32;
|
|
1155
|
+
for (const entry of Object.values(value))
|
|
1156
|
+
bytes += 16 + instanceBytes(entry, seen);
|
|
1157
|
+
return bytes;
|
|
1158
|
+
}
|
|
1109
1159
|
function contentKey(value) {
|
|
1110
1160
|
const plain = (entry) => {
|
|
1111
1161
|
if (ArrayBuffer.isView(entry)) {
|
|
@@ -1161,7 +1211,7 @@ function rebuildFileContent(value, output, attachments) {
|
|
|
1161
1211
|
rebuilt.unshift({ type: "text", text: output });
|
|
1162
1212
|
return { type: "content", value: rebuilt };
|
|
1163
1213
|
}
|
|
1164
|
-
function adaptPayload(draft, admittedIDs = new Set, messageTimes = new Map) {
|
|
1214
|
+
function adaptPayload(draft, admittedIDs = new Set, messageTimes = new Map, hiddenTimes = false) {
|
|
1165
1215
|
const existingHeads = new Map(draft.messages.filter((m) => HEAD_IDS.some((id) => m.id === id)).map((m) => [m.id, m]));
|
|
1166
1216
|
const source = draft.messages.filter((m) => !existingHeads.has(m.id));
|
|
1167
1217
|
const results = new Map;
|
|
@@ -1244,12 +1294,16 @@ function adaptPayload(draft, admittedIDs = new Set, messageTimes = new Map) {
|
|
|
1244
1294
|
const messages = [];
|
|
1245
1295
|
for (const message of source) {
|
|
1246
1296
|
const parts = [];
|
|
1297
|
+
const copiedTagOnly = [];
|
|
1247
1298
|
for (const content of message.content) {
|
|
1248
1299
|
if (paired.has(content))
|
|
1249
1300
|
continue;
|
|
1250
1301
|
const part = callParts.get(content) ?? (content.type === "tool-result" ? nativeTool(undefined, { part: content, message }) : clonePreservingInstances(content));
|
|
1251
|
-
if (message.role === "assistant" && part.type === "text" && typeof part.text === "string")
|
|
1252
|
-
part.text
|
|
1302
|
+
if (message.role === "assistant" && part.type === "text" && typeof part.text === "string") {
|
|
1303
|
+
if (!modelAcceptsEmptyContent(draft.model.providerID) && part.text.trim().length > 0 && stripCopiedTagNotation(part.text).trim().length === 0)
|
|
1304
|
+
copiedTagOnly.push({ index: parts.length, text: part.text });
|
|
1305
|
+
part.text = stripCopiedTagNotation(part.text, modelAcceptsEmptyContent(draft.model.providerID));
|
|
1306
|
+
}
|
|
1253
1307
|
if (message.id && admittedIDs.has(message.id))
|
|
1254
1308
|
part.synthetic = true;
|
|
1255
1309
|
parts.push(part);
|
|
@@ -1280,7 +1334,18 @@ function adaptPayload(draft, admittedIDs = new Set, messageTimes = new Map) {
|
|
|
1280
1334
|
},
|
|
1281
1335
|
parts
|
|
1282
1336
|
};
|
|
1337
|
+
if (hiddenTimes && mapped.info.time !== undefined) {
|
|
1338
|
+
const time = mapped.info.time;
|
|
1339
|
+
delete mapped.info.time;
|
|
1340
|
+
Object.defineProperty(mapped.info, "time", {
|
|
1341
|
+
value: time,
|
|
1342
|
+
enumerable: false,
|
|
1343
|
+
configurable: true,
|
|
1344
|
+
writable: true
|
|
1345
|
+
});
|
|
1346
|
+
}
|
|
1283
1347
|
originals.set(mapped, message);
|
|
1348
|
+
markServedShapeRepair(mapped.info, copiedTagOnly);
|
|
1284
1349
|
if (isCoveredInstructionRow(message))
|
|
1285
1350
|
markCoveredInstructionRow(mapped.info);
|
|
1286
1351
|
if (typeof message.id !== "string")
|
|
@@ -2675,10 +2740,12 @@ function assistantText(row) {
|
|
|
2675
2740
|
|
|
2676
2741
|
class HiddenProviderError extends Error {
|
|
2677
2742
|
settled;
|
|
2743
|
+
hostError;
|
|
2678
2744
|
constructor(detail, options = {}) {
|
|
2679
2745
|
super(`Hidden completion provider error: ${detail}`);
|
|
2680
2746
|
this.name = "HiddenProviderError";
|
|
2681
2747
|
this.settled = options.settled ?? true;
|
|
2748
|
+
this.hostError = options.hostError;
|
|
2682
2749
|
}
|
|
2683
2750
|
}
|
|
2684
2751
|
function requestModel(request, current) {
|
|
@@ -2742,7 +2809,9 @@ async function awaitAssistantRow(openReader, readSessionError, localFailure, chi
|
|
|
2742
2809
|
`terminal_row=${errorText(newIdle)}`,
|
|
2743
2810
|
`session_error=${sessionError === undefined ? "unavailable" : errorText(sessionError)}`
|
|
2744
2811
|
];
|
|
2745
|
-
throw sessionError === undefined || !isProviderFailure(sessionError) ? new Error(`Hidden completion failed: ${details.join("; ")}
|
|
2812
|
+
throw sessionError === undefined || !isProviderFailure(sessionError) ? new Error(`Hidden completion failed: ${details.join("; ")}`, {
|
|
2813
|
+
cause: sessionError
|
|
2814
|
+
}) : new HiddenProviderError(details.join("; "), { hostError: sessionError });
|
|
2746
2815
|
}
|
|
2747
2816
|
if (outcome === "succeeded" && newAssistant)
|
|
2748
2817
|
return newAssistant;
|
|
@@ -2756,7 +2825,9 @@ async function awaitAssistantRow(openReader, readSessionError, localFailure, chi
|
|
|
2756
2825
|
`terminal_row=${errorText(newAssistant)}`,
|
|
2757
2826
|
`session_error=${sessionError === undefined ? "unavailable" : errorText(sessionError)}`
|
|
2758
2827
|
];
|
|
2759
|
-
throw sessionError === undefined || !isProviderFailure(sessionError) ? new Error(`Hidden completion failed: ${details.join("; ")}
|
|
2828
|
+
throw sessionError === undefined || !isProviderFailure(sessionError) ? new Error(`Hidden completion failed: ${details.join("; ")}`, {
|
|
2829
|
+
cause: sessionError
|
|
2830
|
+
}) : new HiddenProviderError(details.join("; "), { hostError: sessionError });
|
|
2760
2831
|
}
|
|
2761
2832
|
if (newAssistant.data.error !== undefined) {
|
|
2762
2833
|
throw new HiddenProviderError(errorText(newAssistant.data.error), {
|
|
@@ -2911,7 +2982,13 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
2911
2982
|
const head = await resolveHead(identity);
|
|
2912
2983
|
const active = await lifecycle.open(identity, role, head);
|
|
2913
2984
|
openedChild = active;
|
|
2914
|
-
const
|
|
2985
|
+
const configuredModel = toModelEntry(identity.model);
|
|
2986
|
+
const handle = {
|
|
2987
|
+
id: active.id,
|
|
2988
|
+
childSessionId: active.id,
|
|
2989
|
+
attemptedModel: modelKey(head),
|
|
2990
|
+
...configuredModel?.sourceConfigKey ? { modelConfigKey: configuredModel.sourceConfigKey } : {}
|
|
2991
|
+
};
|
|
2915
2992
|
const tokenBudget = identity.metadata?.tokenBudget;
|
|
2916
2993
|
const run = {
|
|
2917
2994
|
identity,
|
|
@@ -2942,6 +3019,7 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
2942
3019
|
}
|
|
2943
3020
|
},
|
|
2944
3021
|
async attempt(handle, request) {
|
|
3022
|
+
const startedAt = Date.now();
|
|
2945
3023
|
const run = runs.get(handle);
|
|
2946
3024
|
if (!run)
|
|
2947
3025
|
throw new Error("Unknown hidden completion run");
|
|
@@ -2959,6 +3037,10 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
2959
3037
|
throw new Error("Hidden completion prompt aborted");
|
|
2960
3038
|
}
|
|
2961
3039
|
const requested = await validateVariant(requestModel(request, run.child.model));
|
|
3040
|
+
const requestedRef = modelKey(requested);
|
|
3041
|
+
const configuredModel = [run.identity.model, ...run.identity.configuredModels ?? []].map(toModelEntry).find((entry) => entry?.model === requestedRef);
|
|
3042
|
+
handle.attemptedModel = requestedRef;
|
|
3043
|
+
handle.modelConfigKey = configuredModel?.sourceConfigKey ?? handle.modelConfigKey;
|
|
2962
3044
|
if (run.identity.kind !== "dreamer-task" && request.body.temperature === undefined) {
|
|
2963
3045
|
const configured = options.historianTemperature?.();
|
|
2964
3046
|
if (typeof configured === "number" && Number.isFinite(configured))
|
|
@@ -3053,6 +3135,22 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
3053
3135
|
abortReject = reject;
|
|
3054
3136
|
});
|
|
3055
3137
|
const onAbort = () => {
|
|
3138
|
+
const reason = request.signal?.reason;
|
|
3139
|
+
if (reason instanceof ModelProducedNoOutputError && run.identity.kind === "dreamer-task") {
|
|
3140
|
+
recordChildInvocation({
|
|
3141
|
+
db: options.db,
|
|
3142
|
+
parentSessionId: run.identity.parentSessionId ?? options.projectIdentity,
|
|
3143
|
+
parentInvocationId: run.identity.parentInvocationId,
|
|
3144
|
+
harness: "opencode2",
|
|
3145
|
+
subagent: "dreamer",
|
|
3146
|
+
task: run.identity.title.replace(/^magic-context-dream-/, ""),
|
|
3147
|
+
startedAt,
|
|
3148
|
+
status: "timed_out",
|
|
3149
|
+
error: reason,
|
|
3150
|
+
providerId: requested.providerID,
|
|
3151
|
+
modelId: requested.modelID
|
|
3152
|
+
});
|
|
3153
|
+
}
|
|
3056
3154
|
interruptAndRetire(run, "prompt-aborted").finally(() => abortReject(new Error("Hidden completion prompt aborted")));
|
|
3057
3155
|
};
|
|
3058
3156
|
const deadlineTimer = setTimeout(() => {
|
|
@@ -3081,6 +3179,9 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
3081
3179
|
})
|
|
3082
3180
|
};
|
|
3083
3181
|
inFlight.add(entry);
|
|
3182
|
+
const stopWatching = host.watchModelActivity?.(run.child.id, () => noteModelOutputReceived(request.signal));
|
|
3183
|
+
if (stopWatching)
|
|
3184
|
+
noteModelActivityMonitored(request.signal);
|
|
3084
3185
|
try {
|
|
3085
3186
|
await Promise.race([
|
|
3086
3187
|
host.prompt({ sessionID: run.child.id, text: marker }),
|
|
@@ -3136,12 +3237,20 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
3136
3237
|
usage: reportedUsage ? usage : meter(system, promptText(request), text ?? ""),
|
|
3137
3238
|
lengthCapped: ["length", "max_tokens"].includes(row.data.finish ?? ""),
|
|
3138
3239
|
providerId: row.data.model?.providerID ?? requested.providerID,
|
|
3139
|
-
modelId: row.data.model?.id ?? requested.modelID
|
|
3240
|
+
modelId: row.data.model?.id ?? requested.modelID,
|
|
3241
|
+
attemptedModel: requestedRef,
|
|
3242
|
+
modelConfigKey: handle.modelConfigKey
|
|
3140
3243
|
};
|
|
3141
3244
|
if (!run.child.ever_settled)
|
|
3142
3245
|
run.child = lifecycle.markEverSettled(run.child);
|
|
3143
3246
|
} catch (caught) {
|
|
3144
3247
|
const error = attempt.budgetExceeded ?? attempt.stepLimit ?? attempt.refusal ?? caught;
|
|
3248
|
+
const hostError = error instanceof HiddenProviderError ? error.hostError : error instanceof Error && error.message.startsWith("Hidden completion failed:") ? error.cause : undefined;
|
|
3249
|
+
annotateSubagentInvocationError(error, {
|
|
3250
|
+
attemptedModel: handle.attemptedModel,
|
|
3251
|
+
modelConfigKey: handle.modelConfigKey,
|
|
3252
|
+
...hostError === undefined ? {} : { hostError }
|
|
3253
|
+
});
|
|
3145
3254
|
run.failed = true;
|
|
3146
3255
|
if (!(error instanceof HiddenProviderError)) {
|
|
3147
3256
|
run.unsettledFailure = true;
|
|
@@ -3155,6 +3264,7 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
3155
3264
|
}
|
|
3156
3265
|
throw error;
|
|
3157
3266
|
} finally {
|
|
3267
|
+
stopWatching?.();
|
|
3158
3268
|
clearTimeout(deadlineTimer);
|
|
3159
3269
|
if (budgetPoll)
|
|
3160
3270
|
clearInterval(budgetPoll);
|
|
@@ -3210,6 +3320,30 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
3210
3320
|
};
|
|
3211
3321
|
}
|
|
3212
3322
|
|
|
3323
|
+
// src/v2/hidden-model-activity.ts
|
|
3324
|
+
class HiddenModelActivity {
|
|
3325
|
+
watchers = new Map;
|
|
3326
|
+
watch(sessionID, onOutput) {
|
|
3327
|
+
this.watchers.set(sessionID, onOutput);
|
|
3328
|
+
return () => {
|
|
3329
|
+
if (this.watchers.get(sessionID) === onOutput)
|
|
3330
|
+
this.watchers.delete(sessionID);
|
|
3331
|
+
};
|
|
3332
|
+
}
|
|
3333
|
+
observe(event) {
|
|
3334
|
+
if (!isRecord(event) || !isRecord(event.data))
|
|
3335
|
+
return;
|
|
3336
|
+
const { sessionID, delta, text } = event.data;
|
|
3337
|
+
if (typeof sessionID !== "string")
|
|
3338
|
+
return;
|
|
3339
|
+
const streamed = ["session.text.delta", "session.reasoning.delta", "session.tool.input.delta"].includes(String(event.type)) && typeof delta === "string" && delta.length > 0;
|
|
3340
|
+
const ended = ["session.text.ended", "session.reasoning.ended"].includes(String(event.type)) && typeof text === "string" && text.length > 0;
|
|
3341
|
+
if (streamed || ended || event.type === "session.tool.input.started") {
|
|
3342
|
+
this.watchers.get(sessionID)?.();
|
|
3343
|
+
}
|
|
3344
|
+
}
|
|
3345
|
+
}
|
|
3346
|
+
|
|
3213
3347
|
// src/v2/hooks/channel2.ts
|
|
3214
3348
|
import { randomBytes } from "node:crypto";
|
|
3215
3349
|
var pendingCandidates = new WeakMap;
|
|
@@ -3611,7 +3745,7 @@ function registerV2DreamScheduleTimer(args) {
|
|
|
3611
3745
|
since_days: gitCommitIndexing.since_days,
|
|
3612
3746
|
max_commits: gitCommitIndexing.max_commits
|
|
3613
3747
|
} : undefined,
|
|
3614
|
-
ensureRegistered: ensureProjectRegisteredFromOpenCodeDirectory
|
|
3748
|
+
ensureRegistered: args.ensureRegistered ?? ensureProjectRegisteredFromOpenCodeDirectory
|
|
3615
3749
|
}).catch((error) => {
|
|
3616
3750
|
log2(`[magic-context] v2 dream timer registration failed (continuing without it): ${error}`);
|
|
3617
3751
|
return;
|
|
@@ -3706,6 +3840,41 @@ function startDreamTrigger(context, args) {
|
|
|
3706
3840
|
};
|
|
3707
3841
|
}
|
|
3708
3842
|
|
|
3843
|
+
// src/v2/hooks/embedding-lifecycle.ts
|
|
3844
|
+
function createV2EmbeddingScope(initialProject) {
|
|
3845
|
+
const releases = new Map;
|
|
3846
|
+
const pending = new Set;
|
|
3847
|
+
let disposed = false;
|
|
3848
|
+
let disposal;
|
|
3849
|
+
const claim = (project) => {
|
|
3850
|
+
if (!releases.has(project))
|
|
3851
|
+
releases.set(project, retainProjectEmbedding2(project));
|
|
3852
|
+
};
|
|
3853
|
+
if (initialProject)
|
|
3854
|
+
claim(initialProject);
|
|
3855
|
+
return {
|
|
3856
|
+
ensureRegistered(directory, db) {
|
|
3857
|
+
if (disposed)
|
|
3858
|
+
return Promise.resolve();
|
|
3859
|
+
const registration = ensureProjectRegisteredFromOpenCodeDirectory(directory, db, {
|
|
3860
|
+
onRegistered: claim
|
|
3861
|
+
});
|
|
3862
|
+
pending.add(registration);
|
|
3863
|
+
return registration.finally(() => pending.delete(registration));
|
|
3864
|
+
},
|
|
3865
|
+
dispose() {
|
|
3866
|
+
disposed = true;
|
|
3867
|
+
disposal ??= (async () => {
|
|
3868
|
+
await Promise.allSettled([...pending]);
|
|
3869
|
+
for (const release of releases.values())
|
|
3870
|
+
release();
|
|
3871
|
+
releases.clear();
|
|
3872
|
+
})();
|
|
3873
|
+
return disposal;
|
|
3874
|
+
}
|
|
3875
|
+
};
|
|
3876
|
+
}
|
|
3877
|
+
|
|
3709
3878
|
// src/v2/hooks/generate.ts
|
|
3710
3879
|
function generateReplayAnchor(messages) {
|
|
3711
3880
|
let index = messages.length - 1;
|
|
@@ -3718,26 +3887,70 @@ function generateReplayAnchor(messages) {
|
|
|
3718
3887
|
return;
|
|
3719
3888
|
return { id, tail: clonePreservingInstances(messages.slice(index + 1)) };
|
|
3720
3889
|
}
|
|
3890
|
+
var DEFAULT_GENERATE_REPLAY_LIMITS = Object.freeze({
|
|
3891
|
+
maxSessions: 16,
|
|
3892
|
+
sessionMaxBytes: 128 * 1024 * 1024,
|
|
3893
|
+
totalMaxBytes: 256 * 1024 * 1024
|
|
3894
|
+
});
|
|
3721
3895
|
|
|
3722
3896
|
class V2GenerateReplay {
|
|
3723
3897
|
prefixes = new Map;
|
|
3898
|
+
totalBytes = 0;
|
|
3899
|
+
limits;
|
|
3900
|
+
constructor(limits = DEFAULT_GENERATE_REPLAY_LIMITS) {
|
|
3901
|
+
if (!Number.isSafeInteger(limits.maxSessions) || limits.maxSessions < 1 || !Number.isSafeInteger(limits.sessionMaxBytes) || limits.sessionMaxBytes < 1 || !Number.isSafeInteger(limits.totalMaxBytes) || limits.totalMaxBytes < 1)
|
|
3902
|
+
throw new Error("Generate replay limits must be positive integers");
|
|
3903
|
+
this.limits = { ...limits };
|
|
3904
|
+
}
|
|
3724
3905
|
capture(draft, anchor) {
|
|
3906
|
+
this.forget(draft.sessionID);
|
|
3725
3907
|
if (!anchor) {
|
|
3726
|
-
this.prefixes.delete(draft.sessionID);
|
|
3727
3908
|
sessionLog2(draft.sessionID, "generate replay capture skipped: no-anchor");
|
|
3728
3909
|
return;
|
|
3729
3910
|
}
|
|
3911
|
+
const parts = {
|
|
3912
|
+
anchor: clonePreservingInstancesMeasured(anchor),
|
|
3913
|
+
system: clonePreservingInstancesMeasured(draft.system),
|
|
3914
|
+
messages: clonePreservingInstancesMeasured(draft.messages),
|
|
3915
|
+
tools: clonePreservingInstancesMeasured(draft.tools)
|
|
3916
|
+
};
|
|
3917
|
+
const bytes = 256 + parts.anchor.bytes + parts.system.bytes + parts.messages.bytes + parts.tools.bytes;
|
|
3918
|
+
if (bytes > this.limits.sessionMaxBytes || bytes > this.limits.totalMaxBytes) {
|
|
3919
|
+
sessionLog2(draft.sessionID, `generate replay capture skipped: over-session-cap (${bytes} > ${Math.min(this.limits.sessionMaxBytes, this.limits.totalMaxBytes)} bytes)`);
|
|
3920
|
+
return;
|
|
3921
|
+
}
|
|
3922
|
+
while (this.prefixes.size > 0 && (this.prefixes.size >= this.limits.maxSessions || this.totalBytes + bytes > this.limits.totalMaxBytes)) {
|
|
3923
|
+
const oldest = this.prefixes.keys().next().value;
|
|
3924
|
+
if (oldest === undefined)
|
|
3925
|
+
break;
|
|
3926
|
+
this.forget(oldest);
|
|
3927
|
+
}
|
|
3730
3928
|
this.prefixes.set(draft.sessionID, {
|
|
3731
|
-
anchor:
|
|
3929
|
+
anchor: parts.anchor.copy,
|
|
3732
3930
|
model: `${draft.model.providerID}/${draft.model.id}`,
|
|
3733
3931
|
agent: draft.agent,
|
|
3734
|
-
system:
|
|
3735
|
-
messages:
|
|
3736
|
-
tools:
|
|
3932
|
+
system: parts.system.copy,
|
|
3933
|
+
messages: parts.messages.copy,
|
|
3934
|
+
tools: parts.tools.copy,
|
|
3935
|
+
bytes
|
|
3737
3936
|
});
|
|
3937
|
+
this.totalBytes += bytes;
|
|
3738
3938
|
}
|
|
3739
3939
|
forget(sessionID) {
|
|
3940
|
+
const prefix = this.prefixes.get(sessionID);
|
|
3941
|
+
if (!prefix)
|
|
3942
|
+
return;
|
|
3740
3943
|
this.prefixes.delete(sessionID);
|
|
3944
|
+
this.totalBytes -= prefix.bytes;
|
|
3945
|
+
}
|
|
3946
|
+
stats() {
|
|
3947
|
+
return {
|
|
3948
|
+
totalBytes: this.totalBytes,
|
|
3949
|
+
sessions: [...this.prefixes].map(([sessionId, prefix]) => ({
|
|
3950
|
+
sessionId,
|
|
3951
|
+
bytes: prefix.bytes
|
|
3952
|
+
}))
|
|
3953
|
+
};
|
|
3741
3954
|
}
|
|
3742
3955
|
apply(draft) {
|
|
3743
3956
|
const prefix = this.prefixes.get(draft.sessionID);
|
|
@@ -3747,6 +3960,8 @@ class V2GenerateReplay {
|
|
|
3747
3960
|
};
|
|
3748
3961
|
if (!prefix)
|
|
3749
3962
|
return skip("no-prefix");
|
|
3963
|
+
this.prefixes.delete(draft.sessionID);
|
|
3964
|
+
this.prefixes.set(draft.sessionID, prefix);
|
|
3750
3965
|
if (prefix.model !== `${draft.model.providerID}/${draft.model.id}`)
|
|
3751
3966
|
return skip("model-mismatch");
|
|
3752
3967
|
if (prefix.agent !== draft.agent)
|
|
@@ -3790,21 +4005,25 @@ function identity(slot) {
|
|
|
3790
4005
|
|
|
3791
4006
|
class V2LkgSystemReplay {
|
|
3792
4007
|
systems = new BoundedSessionMap(1000);
|
|
3793
|
-
capture(sessionId, slot, input, served) {
|
|
4008
|
+
capture(sessionId, slot, input, served, head) {
|
|
3794
4009
|
this.systems.set(sessionId, {
|
|
3795
4010
|
slot: identity(slot),
|
|
3796
|
-
input:
|
|
3797
|
-
served: structuredClone(served)
|
|
4011
|
+
input: hostInputKey(input),
|
|
4012
|
+
served: structuredClone(served),
|
|
4013
|
+
head: head ? structuredClone(head) : null
|
|
3798
4014
|
});
|
|
3799
4015
|
}
|
|
3800
4016
|
restore(sessionId, slot, input, target) {
|
|
3801
4017
|
const saved = this.systems.get(sessionId);
|
|
3802
|
-
if (!slot || !saved || saved.slot !== identity(slot) || saved.input !==
|
|
3803
|
-
return
|
|
4018
|
+
if (!slot || !saved || saved.slot !== identity(slot) || saved.input !== hostInputKey(input))
|
|
4019
|
+
return;
|
|
3804
4020
|
target.splice(0, target.length, ...structuredClone(saved.served));
|
|
3805
|
-
return
|
|
4021
|
+
return { head: saved.head ? structuredClone(saved.head) : null };
|
|
3806
4022
|
}
|
|
3807
4023
|
}
|
|
4024
|
+
function hostInputKey(input) {
|
|
4025
|
+
return JSON.stringify({ system: input.system, checkpoint: input.checkpoint });
|
|
4026
|
+
}
|
|
3808
4027
|
|
|
3809
4028
|
// src/v2/hooks/model-limit-cache.ts
|
|
3810
4029
|
var warmStarted = false;
|
|
@@ -4197,6 +4416,22 @@ function* readV2RawMessagePagesForConversion(openReader, sessionID, pageRows = C
|
|
|
4197
4416
|
function createV2RawMessageReader(openReader) {
|
|
4198
4417
|
const servedBoundaryCache = new Map;
|
|
4199
4418
|
return {
|
|
4419
|
+
getRevision: (sessionID) => {
|
|
4420
|
+
const reader = openReader();
|
|
4421
|
+
try {
|
|
4422
|
+
return reader.latestSequence(sessionID);
|
|
4423
|
+
} finally {
|
|
4424
|
+
reader.close();
|
|
4425
|
+
}
|
|
4426
|
+
},
|
|
4427
|
+
getCountAfterRevision: (sessionID, after, through) => {
|
|
4428
|
+
const reader = openReader();
|
|
4429
|
+
try {
|
|
4430
|
+
return reader.messageCountAfterSequence(sessionID, after, through);
|
|
4431
|
+
} finally {
|
|
4432
|
+
reader.close();
|
|
4433
|
+
}
|
|
4434
|
+
},
|
|
4200
4435
|
readPage: (sessionID, afterOrdinal, limit, finalWatermark, after) => {
|
|
4201
4436
|
const reader = openReader();
|
|
4202
4437
|
try {
|
|
@@ -4340,13 +4575,13 @@ function bindV2SystemPromptResponse(sessionId, reader) {
|
|
|
4340
4575
|
|
|
4341
4576
|
// src/v2/hooks/tools.ts
|
|
4342
4577
|
import { tool } from "@opencode-ai/plugin";
|
|
4343
|
-
async function registerTools(context, db, config, rustToolBackends, isInternalChild) {
|
|
4578
|
+
async function registerTools(context, db, config, rustToolBackends, isInternalChild, ensureProjectRegistered = ensureProjectRegisteredFromOpenCodeDirectory) {
|
|
4344
4579
|
const compaction = isCompactionEnabled(config);
|
|
4345
4580
|
setCtxReduceRegisteredGlobally(compaction);
|
|
4346
4581
|
const project = {
|
|
4347
4582
|
db,
|
|
4348
4583
|
resolveProjectPath: (directory) => resolveProjectIdentityForSession(directory, config.allow_home_project),
|
|
4349
|
-
ensureProjectRegistered
|
|
4584
|
+
ensureProjectRegistered
|
|
4350
4585
|
};
|
|
4351
4586
|
const definitions = {
|
|
4352
4587
|
...compaction ? createCtxReduceTools({
|
|
@@ -4366,7 +4601,11 @@ async function registerTools(context, db, config, rustToolBackends, isInternalCh
|
|
|
4366
4601
|
smartNotesEnabled: config.smart_notes.enabled,
|
|
4367
4602
|
...rustToolBackends ? { rustToolBackends } : {}
|
|
4368
4603
|
}),
|
|
4369
|
-
...createCtxSearchTools({
|
|
4604
|
+
...createCtxSearchTools({
|
|
4605
|
+
...project,
|
|
4606
|
+
rerankConnectionFile: config.subc?.connection_file,
|
|
4607
|
+
rerankConfig: config.rerank
|
|
4608
|
+
}),
|
|
4370
4609
|
...config.memory.enabled ? {
|
|
4371
4610
|
...createCtxMemoryTools({
|
|
4372
4611
|
...project,
|
|
@@ -4446,7 +4685,7 @@ function bindV2TransformDecision(args) {
|
|
|
4446
4685
|
}
|
|
4447
4686
|
|
|
4448
4687
|
// src/v2/hooks/transform-features.ts
|
|
4449
|
-
function createV2TransformFeatureDeps(config, compactionOff, directory) {
|
|
4688
|
+
function createV2TransformFeatureDeps(config, compactionOff, directory, ensureProjectRegistered = ensureProjectRegisteredFromOpenCodeDirectory) {
|
|
4450
4689
|
return {
|
|
4451
4690
|
protectedTools: config.protected_tools,
|
|
4452
4691
|
commitClusterTrigger: config.commit_cluster_trigger,
|
|
@@ -4457,7 +4696,7 @@ function createV2TransformFeatureDeps(config, compactionOff, directory) {
|
|
|
4457
4696
|
injectionBudgetTokens: config.memory.injection_budget_tokens,
|
|
4458
4697
|
autoPromote: config.memory.auto_promote
|
|
4459
4698
|
},
|
|
4460
|
-
ensureProjectRegistered
|
|
4699
|
+
ensureProjectRegistered,
|
|
4461
4700
|
historyBudgetPercentage: config.history_budget_percentage,
|
|
4462
4701
|
experimentalUserMemories: userObservationCollectionEnabled2(config.dreamer),
|
|
4463
4702
|
userObservationsRequested: userObservationsRequested2(config.dreamer),
|
|
@@ -4468,7 +4707,7 @@ function createV2TransformFeatureDeps(config, compactionOff, directory) {
|
|
|
4468
4707
|
scoreThreshold: config.memory.auto_search?.score_threshold ?? 0.6,
|
|
4469
4708
|
minPromptChars: config.memory.auto_search?.min_prompt_chars ?? 20,
|
|
4470
4709
|
directory,
|
|
4471
|
-
ensureProjectRegistered
|
|
4710
|
+
ensureProjectRegistered,
|
|
4472
4711
|
wordRules: cavemanWordRulesForLanguage(config.language)
|
|
4473
4712
|
},
|
|
4474
4713
|
cavemanTextCompression: compactionOff ? undefined : config.caveman_text_compression?.enabled === true ? {
|
|
@@ -4478,7 +4717,7 @@ function createV2TransformFeatureDeps(config, compactionOff, directory) {
|
|
|
4478
4717
|
} : undefined
|
|
4479
4718
|
};
|
|
4480
4719
|
}
|
|
4481
|
-
function createV2AutoEmbedSession(deps) {
|
|
4720
|
+
function createV2AutoEmbedSession(deps, ensureProjectRegistered = ensureProjectRegisteredFromOpenCodeDirectory) {
|
|
4482
4721
|
return (sessionId) => {
|
|
4483
4722
|
const directory = deps.resolveDirectory(sessionId);
|
|
4484
4723
|
const projectIdentity = resolveProjectIdentityForSession(directory, deps.allowHomeProject);
|
|
@@ -4488,7 +4727,7 @@ function createV2AutoEmbedSession(deps) {
|
|
|
4488
4727
|
db: deps.db,
|
|
4489
4728
|
projectIdentity,
|
|
4490
4729
|
ensureRegistered: async () => {
|
|
4491
|
-
await
|
|
4730
|
+
await ensureProjectRegistered(directory, deps.db);
|
|
4492
4731
|
deps.onDirectoryResolved?.(sessionId, directory);
|
|
4493
4732
|
}
|
|
4494
4733
|
}, sessionId);
|
|
@@ -4577,6 +4816,26 @@ function persistV2UsageReading(args) {
|
|
|
4577
4816
|
// src/v2/hooks/context.ts
|
|
4578
4817
|
class V2LkgAdmissionReplay extends Error {
|
|
4579
4818
|
}
|
|
4819
|
+
function applyCheckpointHead(draft, head) {
|
|
4820
|
+
const { checkpoint, submitted } = head;
|
|
4821
|
+
const first = draft.messages.find((message) => message.id === HEAD_IDS[0]);
|
|
4822
|
+
const baseline = first?.content.find((part) => part.type === "text")?.text;
|
|
4823
|
+
if (typeof baseline !== "string")
|
|
4824
|
+
return false;
|
|
4825
|
+
for (const part of checkpoint.content)
|
|
4826
|
+
if (part.type === "text" && typeof part.text === "string") {
|
|
4827
|
+
part.text = part.text.replace(`<summary>
|
|
4828
|
+
${submitted}
|
|
4829
|
+
</summary>`, `<summary>
|
|
4830
|
+
${baseline}
|
|
4831
|
+
</summary>`);
|
|
4832
|
+
}
|
|
4833
|
+
const volatile = draft.messages.find((message) => message.id === HEAD_IDS[1]);
|
|
4834
|
+
if (volatile && first)
|
|
4835
|
+
volatile.content.push(...first.content.filter((part) => part.type !== "text"));
|
|
4836
|
+
draft.messages.splice(0, draft.messages.length, checkpoint, ...draft.messages.filter((message) => message !== first));
|
|
4837
|
+
return true;
|
|
4838
|
+
}
|
|
4580
4839
|
var HIDDEN_SESSION_ERROR_GRACE_MS = 50;
|
|
4581
4840
|
var STORE_POOL_DISPOSE_WAIT_MS = 1000;
|
|
4582
4841
|
function isBlockingV2TransformError(error) {
|
|
@@ -4802,6 +5061,7 @@ async function registerContext(context) {
|
|
|
4802
5061
|
console.warn(`[magic-context] v2 setup disabled by conflicting context hooks: ${conflicts.reasons.join("; ")}`);
|
|
4803
5062
|
return;
|
|
4804
5063
|
}
|
|
5064
|
+
const embeddings = createV2EmbeddingScope(resolveProjectIdentityForSession(directory, config.allow_home_project));
|
|
4805
5065
|
const folds = new FoldOwner(context.storage);
|
|
4806
5066
|
const nativeFoldMemory = !compactionOff && process.env.MC_OC2_INVISIBLE_FOLD === "1" ? nativeFoldCache(() => storage.require()) : undefined;
|
|
4807
5067
|
const nativeFoldReplay = nativeFoldMemory ? new NativeFoldReplay(nativeFoldMemory, () => openStoreReader(), context.storage) : undefined;
|
|
@@ -4809,6 +5069,7 @@ async function registerContext(context) {
|
|
|
4809
5069
|
const queriedModels = new Set;
|
|
4810
5070
|
const rawLimits = new Map;
|
|
4811
5071
|
const hiddenSessionErrors = new Map;
|
|
5072
|
+
const hiddenModelActivity = new HiddenModelActivity;
|
|
4812
5073
|
const liveModels = new Map;
|
|
4813
5074
|
const promptSurfaceRuntime = createPromptSurfaceRuntime({
|
|
4814
5075
|
harness: "opencode2",
|
|
@@ -4857,7 +5118,7 @@ async function registerContext(context) {
|
|
|
4857
5118
|
}) : undefined;
|
|
4858
5119
|
const hiddenChildHook = new HiddenChildHook;
|
|
4859
5120
|
await context.session.hook("http.request", (draft) => hiddenChildHook.cacheRequest(draft));
|
|
4860
|
-
const tools = db && isDatabasePersisted(db) ? await registerTools(context, db, config, moduleToolBackends?.backends, (id) => hiddenChildHook.owns(id)) : undefined;
|
|
5121
|
+
const tools = db && isDatabasePersisted(db) ? await registerTools(context, db, config, moduleToolBackends?.backends, (id) => hiddenChildHook.owns(id), embeddings.ensureRegistered) : undefined;
|
|
4861
5122
|
const usage = new Map;
|
|
4862
5123
|
const generateReplay = new V2GenerateReplay;
|
|
4863
5124
|
await context.session.hook("http.response", async (draft) => {
|
|
@@ -4903,6 +5164,7 @@ async function registerContext(context) {
|
|
|
4903
5164
|
await cleanupLegacyOnce(database);
|
|
4904
5165
|
return createV2HiddenCompletionExecutor({
|
|
4905
5166
|
...context.session,
|
|
5167
|
+
watchModelActivity: (sessionID, onOutput) => hiddenModelActivity.watch(sessionID, onOutput),
|
|
4906
5168
|
get: async (input) => {
|
|
4907
5169
|
const session = await context.session.get(input);
|
|
4908
5170
|
const error = hiddenSessionErrors.get(input.sessionID);
|
|
@@ -4978,7 +5240,8 @@ async function registerContext(context) {
|
|
|
4978
5240
|
liveConfig: () => liveConfigReader.poll().effective,
|
|
4979
5241
|
executor: withLiveDreamerOutputCap(lateHiddenExecutor, config, () => liveConfigReader.poll().effective),
|
|
4980
5242
|
openReader: openStoreReader,
|
|
4981
|
-
rustModeModuleClient
|
|
5243
|
+
rustModeModuleClient,
|
|
5244
|
+
ensureRegistered: embeddings.ensureRegistered
|
|
4982
5245
|
});
|
|
4983
5246
|
};
|
|
4984
5247
|
if (db && isDatabasePersisted(db))
|
|
@@ -5244,6 +5507,7 @@ async function registerContext(context) {
|
|
|
5244
5507
|
break;
|
|
5245
5508
|
const event = value;
|
|
5246
5509
|
try {
|
|
5510
|
+
hiddenModelActivity.observe(event);
|
|
5247
5511
|
if (event.type === "provider.updated" || event.type === "model.updated") {
|
|
5248
5512
|
queriedModels.clear();
|
|
5249
5513
|
continue;
|
|
@@ -5251,6 +5515,10 @@ async function registerContext(context) {
|
|
|
5251
5515
|
if (!event.data?.sessionID)
|
|
5252
5516
|
continue;
|
|
5253
5517
|
const sessionID = event.data.sessionID;
|
|
5518
|
+
if (db && event.type === "session.revert.committed") {
|
|
5519
|
+
const indexDb = db;
|
|
5520
|
+
withoutSqliteTransformPass2(() => scheduleClearAndReindex(indexDb, sessionID, pagedRead));
|
|
5521
|
+
}
|
|
5254
5522
|
if (event.type?.startsWith("session.revert.") || event.type === "session.message.content.updated") {
|
|
5255
5523
|
nativeFoldReplay?.onEvent(event);
|
|
5256
5524
|
restoredRows.forget(sessionID);
|
|
@@ -5278,34 +5546,47 @@ async function registerContext(context) {
|
|
|
5278
5546
|
if (event.type === "session.deleted") {
|
|
5279
5547
|
clearLkgMeasuredRequest(sessionID);
|
|
5280
5548
|
deletedSessions.add(sessionID);
|
|
5281
|
-
|
|
5282
|
-
|
|
5283
|
-
|
|
5284
|
-
|
|
5549
|
+
const failures = [];
|
|
5550
|
+
try {
|
|
5551
|
+
transform?.clearSessionLogState(sessionID);
|
|
5552
|
+
if (db) {
|
|
5553
|
+
markSessionCleanupPending(db, sessionID);
|
|
5554
|
+
clearSession(db, sessionID, false, true);
|
|
5555
|
+
}
|
|
5556
|
+
} catch (error) {
|
|
5557
|
+
failures.push(error);
|
|
5285
5558
|
}
|
|
5286
|
-
|
|
5287
|
-
|
|
5288
|
-
|
|
5289
|
-
|
|
5290
|
-
|
|
5291
|
-
|
|
5292
|
-
|
|
5293
|
-
|
|
5294
|
-
|
|
5295
|
-
|
|
5296
|
-
|
|
5297
|
-
|
|
5298
|
-
|
|
5299
|
-
|
|
5300
|
-
|
|
5301
|
-
|
|
5302
|
-
|
|
5303
|
-
|
|
5304
|
-
|
|
5305
|
-
|
|
5306
|
-
|
|
5307
|
-
|
|
5308
|
-
|
|
5559
|
+
try {
|
|
5560
|
+
rawProviders.get(sessionID)?.();
|
|
5561
|
+
rawProviders.delete(sessionID);
|
|
5562
|
+
usage.delete(sessionID);
|
|
5563
|
+
hiddenSessionErrors.delete(sessionID);
|
|
5564
|
+
storageNoticeBySession.delete(sessionID);
|
|
5565
|
+
liveModels.delete(sessionID);
|
|
5566
|
+
variants.delete(sessionID);
|
|
5567
|
+
agents.delete(sessionID);
|
|
5568
|
+
channel1.delete(sessionID);
|
|
5569
|
+
commitSeenLastPass.delete(sessionID);
|
|
5570
|
+
clearEmbedSessionState(sessionID);
|
|
5571
|
+
historyRefreshSessions.delete(sessionID);
|
|
5572
|
+
clearPendingMaterialization(pendingMaterializationSessions, sessionID);
|
|
5573
|
+
lastHeuristicsTurnId.delete(sessionID);
|
|
5574
|
+
restoredRows.forget(sessionID);
|
|
5575
|
+
if (nativeFoldReplay)
|
|
5576
|
+
await nativeFoldReplay.forget(sessionID);
|
|
5577
|
+
else
|
|
5578
|
+
await forgetNativeFoldProvenance(context.storage, sessionID);
|
|
5579
|
+
generateReplay.forget(sessionID);
|
|
5580
|
+
systemPromptRefreshSessions.delete(sessionID);
|
|
5581
|
+
systemPrompt?.clearSession(sessionID);
|
|
5582
|
+
tagger.cleanup(sessionID);
|
|
5583
|
+
} catch (error) {
|
|
5584
|
+
failures.push(error);
|
|
5585
|
+
}
|
|
5586
|
+
if (failures.length === 1)
|
|
5587
|
+
throw failures[0];
|
|
5588
|
+
if (failures.length > 1)
|
|
5589
|
+
throw new AggregateError(failures, "session deletion failed in both the store clear and the in-memory cleanup");
|
|
5309
5590
|
continue;
|
|
5310
5591
|
}
|
|
5311
5592
|
if (event.type !== "session.execution.succeeded")
|
|
@@ -5353,7 +5634,7 @@ async function registerContext(context) {
|
|
|
5353
5634
|
}) || draft.model.limit?.context || (state.lastObservedModelKey === modelKey ? state.lastUsageContextLimit : undefined);
|
|
5354
5635
|
return materializeM0({
|
|
5355
5636
|
...createM0RenderOptions({
|
|
5356
|
-
...createV2TransformFeatureDeps(config, compactionOff, directory),
|
|
5637
|
+
...createV2TransformFeatureDeps(config, compactionOff, directory, embeddings.ensureRegistered),
|
|
5357
5638
|
...createV2ThresholdDeps(config)
|
|
5358
5639
|
}, usage.get(draft.sessionID)?.usage ?? { percentage: 0, inputTokens: 0 }, modelKey, contextLimit, resolveProjectIdentityForSession(directory, config.allow_home_project)),
|
|
5359
5640
|
db,
|
|
@@ -5423,6 +5704,42 @@ async function registerContext(context) {
|
|
|
5423
5704
|
reader.close();
|
|
5424
5705
|
}
|
|
5425
5706
|
});
|
|
5707
|
+
const temporalTimes = config.temporal_awareness === true;
|
|
5708
|
+
const anchorTimesOnly = !temporalTimes && !rustModeModuleClient;
|
|
5709
|
+
const timeIds = (messages) => {
|
|
5710
|
+
if (temporalTimes)
|
|
5711
|
+
return messages.flatMap((message) => message.id ? [message.id] : []);
|
|
5712
|
+
if (!anchorTimesOnly)
|
|
5713
|
+
return [];
|
|
5714
|
+
const ids = [];
|
|
5715
|
+
for (const message of [...messages].reverse()) {
|
|
5716
|
+
if (message.id)
|
|
5717
|
+
ids.push(message.id);
|
|
5718
|
+
if (message.role === "assistant")
|
|
5719
|
+
break;
|
|
5720
|
+
}
|
|
5721
|
+
return ids;
|
|
5722
|
+
};
|
|
5723
|
+
const restoreAfterCheckpoint = (args) => {
|
|
5724
|
+
const { db, reader, draft, cut, boundaryRepair } = args;
|
|
5725
|
+
const moduleBoundaryID = rustModeModuleClient ? getPersistedCompactionMarkerState(db, draft.sessionID)?.boundaryMessageId ?? null : null;
|
|
5726
|
+
const moduleBoundarySeq = moduleBoundaryID ? reader.sequenceForId(draft.sessionID, moduleBoundaryID) : undefined;
|
|
5727
|
+
const boundaryID = db.prepare("SELECT cached_m0_last_baseline_end_message_id AS id FROM session_meta WHERE session_id = ?").get(draft.sessionID)?.id ?? (boundaryRepair?.kind === "repaired" || boundaryRepair?.kind === "baseline-reset" ? boundaryRepair.anchorEndMessageId : null);
|
|
5728
|
+
const servedBoundary = boundaryID ? servedBoundaryRow(reader, draft.sessionID, boundaryID) : null;
|
|
5729
|
+
const boundary = (nativeFoldReplay?.sourceChanged(draft.sessionID) && !rustModeModuleClient ? (reader.earliestSequence(draft.sessionID) ?? 0) - 1 : undefined) ?? (moduleBoundarySeq !== undefined ? moduleBoundarySeq - 1 : undefined) ?? servedBoundary?.seq ?? reader.sequenceForId(draft.sessionID, boundaryID) ?? (reader.earliestSequence(draft.sessionID) ?? 0) - 1;
|
|
5730
|
+
if (moduleBoundarySeq !== undefined)
|
|
5731
|
+
sessionLog2(draft.sessionID, `v2 restore: from the module boundary ${moduleBoundaryID} to the host checkpoint`);
|
|
5732
|
+
const present = new Set(args.messages.map((message) => message.id));
|
|
5733
|
+
const restored = restoredRows.rows(reader, draft.sessionID, boundary, cut.seq).filter((row) => !present.has(row.id)).flatMap((row) => restoreRow(row, draft.model, hostUsesMediaAssets() ? {
|
|
5734
|
+
asset: hostMediaAsset,
|
|
5735
|
+
unavailable: (detail) => sessionLog2(draft.sessionID, `v2 restore: attachment replaced by a note row=${detail.rowID} name=${JSON.stringify(detail.name ?? null)} mediaType=${detail.mediaType} reason=${JSON.stringify(detail.reason)}`)
|
|
5736
|
+
} : undefined));
|
|
5737
|
+
return [
|
|
5738
|
+
...rustModeModuleClient ? [] : coveredInstructionRows(reader, draft.sessionID, Math.min(boundary, cut.seq), draft.model),
|
|
5739
|
+
...restored,
|
|
5740
|
+
...args.messages.filter((message) => message !== args.incoming)
|
|
5741
|
+
];
|
|
5742
|
+
};
|
|
5426
5743
|
const runManagedContext = async (draft) => {
|
|
5427
5744
|
rememberHostMedia(draft.messages);
|
|
5428
5745
|
if (hiddenChildHook.apply(draft))
|
|
@@ -5434,12 +5751,18 @@ async function registerContext(context) {
|
|
|
5434
5751
|
return;
|
|
5435
5752
|
const systemAtEntry = structuredClone(draft.system);
|
|
5436
5753
|
const slotAtEntry = getSlot(draft.sessionID);
|
|
5754
|
+
let checkpointAtEntry;
|
|
5755
|
+
let replayHead;
|
|
5756
|
+
const hostInput = () => checkpointAtEntry === undefined ? undefined : { system: systemAtEntry, checkpoint: checkpointAtEntry };
|
|
5437
5757
|
const restoreLkgSystem = () => {
|
|
5438
5758
|
retirePendingSystemPromptDelivery(draft.sessionID);
|
|
5439
|
-
|
|
5759
|
+
const input = hostInput();
|
|
5760
|
+
const restored = input && lkgSystems.restore(draft.sessionID, getSlot(draft.sessionID), input, draft.system);
|
|
5761
|
+
if (!restored) {
|
|
5440
5762
|
sessionLog2(draft.sessionID, "lkg_system_state_mismatch");
|
|
5441
5763
|
throw new Error("LKG system identity is unavailable or changed");
|
|
5442
5764
|
}
|
|
5765
|
+
replayHead = restored.head;
|
|
5443
5766
|
};
|
|
5444
5767
|
const isMagicContextSynthetic = (id) => isAdmittedSynthetic(context, draft.sessionID, id);
|
|
5445
5768
|
const newest = draft.messages.at(-1);
|
|
@@ -5448,6 +5771,24 @@ async function registerContext(context) {
|
|
|
5448
5771
|
return;
|
|
5449
5772
|
}
|
|
5450
5773
|
await dropStorageNotices(draft.messages, isMagicContextSynthetic);
|
|
5774
|
+
const hostMessagesAtEntry = [...draft.messages];
|
|
5775
|
+
const passTimes = new Map;
|
|
5776
|
+
const readTimes = (reader, messages) => {
|
|
5777
|
+
const ids = timeIds(messages);
|
|
5778
|
+
const missing = ids.filter((id) => !passTimes.has(id));
|
|
5779
|
+
if (missing.length > 0) {
|
|
5780
|
+
const read = reader.messageTimes(draft.sessionID, missing);
|
|
5781
|
+
for (const id of missing)
|
|
5782
|
+
passTimes.set(id, read.get(id) ?? null);
|
|
5783
|
+
}
|
|
5784
|
+
const times = new Map;
|
|
5785
|
+
for (const id of ids) {
|
|
5786
|
+
const time = passTimes.get(id);
|
|
5787
|
+
if (time)
|
|
5788
|
+
times.set(id, time);
|
|
5789
|
+
}
|
|
5790
|
+
return times;
|
|
5791
|
+
};
|
|
5451
5792
|
liveModels.set(draft.sessionID, {
|
|
5452
5793
|
providerID: draft.model.providerID,
|
|
5453
5794
|
modelID: draft.model.id
|
|
@@ -5459,8 +5800,9 @@ async function registerContext(context) {
|
|
|
5459
5800
|
applyV2PromptSurfaceTools(draft, promptSurfaceRuntime, config.prompt_surface, isSmartNoteSurfaceAvailable(config));
|
|
5460
5801
|
const admissionDb = db ?? storage.current();
|
|
5461
5802
|
const replayFits = (messages) => {
|
|
5462
|
-
const system =
|
|
5463
|
-
|
|
5803
|
+
const system = [];
|
|
5804
|
+
const input = hostInput();
|
|
5805
|
+
if (!admissionDb || !draft.tools || !input || !lkgSystems.restore(draft.sessionID, getSlot(draft.sessionID), input, system))
|
|
5464
5806
|
return false;
|
|
5465
5807
|
const limit = lkgReplayLimit({
|
|
5466
5808
|
db: admissionDb,
|
|
@@ -5495,14 +5837,75 @@ async function registerContext(context) {
|
|
|
5495
5837
|
})
|
|
5496
5838
|
}).fit === "under";
|
|
5497
5839
|
};
|
|
5840
|
+
const buildReplayInput = async () => {
|
|
5841
|
+
let messages = [...hostMessagesAtEntry];
|
|
5842
|
+
const admitted = new Set;
|
|
5843
|
+
let times;
|
|
5844
|
+
try {
|
|
5845
|
+
const reader = openStoreReader();
|
|
5846
|
+
try {
|
|
5847
|
+
const cut = reader.latestCompaction(draft.sessionID);
|
|
5848
|
+
const localCut = cut && isLocalCheckpoint(cut) ? cut : undefined;
|
|
5849
|
+
const incoming = localCut && messages.find((message) => message.id === localCut.id);
|
|
5850
|
+
if (localCut && !incoming || cut && nativeFoldReplay)
|
|
5851
|
+
return;
|
|
5852
|
+
checkpointAtEntry = incoming || null;
|
|
5853
|
+
const modeDb = db ?? storage.current();
|
|
5854
|
+
const subagent = modeDb ? storedSubagentMode(modeDb, draft.sessionID) : undefined;
|
|
5855
|
+
if (subagent === undefined)
|
|
5856
|
+
return;
|
|
5857
|
+
if (subagent)
|
|
5858
|
+
removePrimaryOnlyTools(draft.tools);
|
|
5859
|
+
if (!rustModeModuleClient) {
|
|
5860
|
+
const candidates = syntheticCandidates(context, draft.sessionID, reader.syntheticMessageIDs(draft.sessionID));
|
|
5861
|
+
for (const message of messages)
|
|
5862
|
+
if (message.id && candidates.has(message.id) && await isAdmittedSynthetic(context, draft.sessionID, message.id))
|
|
5863
|
+
admitted.add(message.id);
|
|
5864
|
+
const replayDb = db ?? storage.current();
|
|
5865
|
+
if (localCut && incoming && replayDb)
|
|
5866
|
+
messages = restoreAfterCheckpoint({
|
|
5867
|
+
db: replayDb,
|
|
5868
|
+
reader,
|
|
5869
|
+
draft,
|
|
5870
|
+
messages,
|
|
5871
|
+
cut: localCut,
|
|
5872
|
+
incoming,
|
|
5873
|
+
boundaryRepair: undefined
|
|
5874
|
+
});
|
|
5875
|
+
else if (localCut)
|
|
5876
|
+
return;
|
|
5877
|
+
times = readTimes(reader, messages);
|
|
5878
|
+
}
|
|
5879
|
+
} finally {
|
|
5880
|
+
reader.close();
|
|
5881
|
+
}
|
|
5882
|
+
} catch (error) {
|
|
5883
|
+
sessionLog2(draft.sessionID, "lkg replay input unavailable", error);
|
|
5884
|
+
return;
|
|
5885
|
+
}
|
|
5886
|
+
const replayDraft = { ...draft, messages };
|
|
5887
|
+
return {
|
|
5888
|
+
draft: replayDraft,
|
|
5889
|
+
mapped: adaptPayload(replayDraft, admitted, times, anchorTimesOnly)
|
|
5890
|
+
};
|
|
5891
|
+
};
|
|
5892
|
+
const adoptReplay = (replayed) => {
|
|
5893
|
+
if (replayed !== draft)
|
|
5894
|
+
draft.messages.splice(0, draft.messages.length, ...replayed.messages);
|
|
5895
|
+
if (replayHead)
|
|
5896
|
+
applyCheckpointHead(draft, replayHead);
|
|
5897
|
+
};
|
|
5498
5898
|
let postFold = false;
|
|
5499
5899
|
try {
|
|
5500
5900
|
if (!compactionOff && admissionDb)
|
|
5501
5901
|
await withAsyncPrivilegedWriter2(admissionDb, () => {
|
|
5502
5902
|
return;
|
|
5503
5903
|
}, {
|
|
5504
|
-
beforeRetry: (error) => {
|
|
5505
|
-
const
|
|
5904
|
+
beforeRetry: async (error) => {
|
|
5905
|
+
const input = await buildReplayInput();
|
|
5906
|
+
if (!input)
|
|
5907
|
+
return;
|
|
5908
|
+
const { mapped } = input;
|
|
5506
5909
|
if (tryMessagesTransformLkgReplay({
|
|
5507
5910
|
output: mapped,
|
|
5508
5911
|
sessionId: draft.sessionID,
|
|
@@ -5513,6 +5916,7 @@ async function registerContext(context) {
|
|
|
5513
5916
|
onLkgReplay: restoreLkgSystem
|
|
5514
5917
|
})) {
|
|
5515
5918
|
mapped.commit();
|
|
5919
|
+
adoptReplay(input.draft);
|
|
5516
5920
|
throw new V2LkgAdmissionReplay;
|
|
5517
5921
|
}
|
|
5518
5922
|
}
|
|
@@ -5602,7 +6006,7 @@ async function registerContext(context) {
|
|
|
5602
6006
|
await cacheV2SessionDirectory(context.session, draft.sessionID, sessionDirectories);
|
|
5603
6007
|
prepareHistorySession(draft.sessionID);
|
|
5604
6008
|
transform ??= createTransform({
|
|
5605
|
-
...createV2TransformFeatureDeps(config, compactionOff, directory),
|
|
6009
|
+
...createV2TransformFeatureDeps(config, compactionOff, directory, embeddings.ensureRegistered),
|
|
5606
6010
|
cacheTtlConfig: config.cache_ttl,
|
|
5607
6011
|
cacheTtlConfigured: config.cacheTtlConfigured,
|
|
5608
6012
|
sampleCacheTtlConfig: () => liveConfigReader.poll().effective,
|
|
@@ -5612,7 +6016,7 @@ async function registerContext(context) {
|
|
|
5612
6016
|
contextUsageMap: usage,
|
|
5613
6017
|
compactionOff,
|
|
5614
6018
|
storeGeneration: "v2",
|
|
5615
|
-
normalizeRestoredAssistantText: stripCopiedTagNotation,
|
|
6019
|
+
normalizeRestoredAssistantText: (text, providerID) => stripCopiedTagNotation(text, providerID === "anthropic"),
|
|
5616
6020
|
refreshSourceContents: (sessionID) => nativeFoldReplay?.needsHeadRebuild(sessionID) ?? false,
|
|
5617
6021
|
hostCleanupCompactionMarkers: () => ({
|
|
5618
6022
|
verified: true,
|
|
@@ -5649,7 +6053,7 @@ async function registerContext(context) {
|
|
|
5649
6053
|
resolveDirectory: (sessionID) => sessionDirectories.get(sessionID) ?? directory,
|
|
5650
6054
|
allowHomeProject: config.allow_home_project,
|
|
5651
6055
|
recompProgressBySession: new Map
|
|
5652
|
-
}),
|
|
6056
|
+
}, embeddings.ensureRegistered),
|
|
5653
6057
|
hiddenCompletionExecutor,
|
|
5654
6058
|
historianRunnable: !compactionOff && hiddenCompletionExecutor !== undefined && config.historian?.disable !== true,
|
|
5655
6059
|
historianModel: historianModels.primary,
|
|
@@ -5707,6 +6111,7 @@ async function registerContext(context) {
|
|
|
5707
6111
|
postFold = cut !== undefined;
|
|
5708
6112
|
if (localCut && !incoming)
|
|
5709
6113
|
throw new Error("The host checkpoint disappeared from the context draft");
|
|
6114
|
+
checkpointAtEntry = incoming || null;
|
|
5710
6115
|
let nativeRestored;
|
|
5711
6116
|
if (cut && nativeFoldReplay && await nativeFoldReplay.admits(draft.sessionID, cut, reader)) {
|
|
5712
6117
|
try {
|
|
@@ -5748,22 +6153,17 @@ async function registerContext(context) {
|
|
|
5748
6153
|
checkpoint = structuredClone(identity.rendered ?? incoming);
|
|
5749
6154
|
submitted = identity.rendered ? identity.renderedSummary ?? identity.submitted : cut.data.summary ?? "";
|
|
5750
6155
|
}
|
|
5751
|
-
|
|
5752
|
-
|
|
5753
|
-
|
|
5754
|
-
|
|
5755
|
-
|
|
5756
|
-
|
|
5757
|
-
|
|
5758
|
-
|
|
5759
|
-
|
|
5760
|
-
asset: hostMediaAsset,
|
|
5761
|
-
unavailable: (detail) => sessionLog2(draft.sessionID, `v2 restore: attachment replaced by a note row=${detail.rowID} name=${JSON.stringify(detail.name ?? null)} mediaType=${detail.mediaType} reason=${JSON.stringify(detail.reason)}`)
|
|
5762
|
-
} : undefined));
|
|
5763
|
-
draft.messages.splice(0, draft.messages.length, ...rustModeModuleClient ? [] : coveredInstructionRows(reader, draft.sessionID, Math.min(boundary, cut.seq), draft.model), ...restored, ...draft.messages.filter((message) => message !== incoming));
|
|
6156
|
+
draft.messages.splice(0, draft.messages.length, ...restoreAfterCheckpoint({
|
|
6157
|
+
db,
|
|
6158
|
+
reader,
|
|
6159
|
+
draft,
|
|
6160
|
+
messages: draft.messages,
|
|
6161
|
+
cut: localCut,
|
|
6162
|
+
incoming,
|
|
6163
|
+
boundaryRepair
|
|
6164
|
+
}));
|
|
5764
6165
|
}
|
|
5765
|
-
|
|
5766
|
-
messageTimes = reader.messageTimes(draft.sessionID, draft.messages.flatMap((message) => message.id ? [message.id] : []));
|
|
6166
|
+
messageTimes = readTimes(reader, draft.messages);
|
|
5767
6167
|
} finally {
|
|
5768
6168
|
reader.close();
|
|
5769
6169
|
}
|
|
@@ -5780,7 +6180,7 @@ async function registerContext(context) {
|
|
|
5780
6180
|
nativeFoldReplay.invalidate(draft.sessionID, true);
|
|
5781
6181
|
}
|
|
5782
6182
|
}
|
|
5783
|
-
const mapped = adaptPayload(draft, admitted, messageTimes);
|
|
6183
|
+
const mapped = adaptPayload(draft, admitted, messageTimes, anchorTimesOnly);
|
|
5784
6184
|
bindSystemDateRequestIdentity(mapped, draft);
|
|
5785
6185
|
await createMessagesTransformHandler({
|
|
5786
6186
|
magicContext: { "experimental.chat.messages.transform": transform },
|
|
@@ -5797,24 +6197,9 @@ async function registerContext(context) {
|
|
|
5797
6197
|
if (db) {
|
|
5798
6198
|
await deliverPendingChannel2(context, db, draft.sessionID, channel1.get(draft.sessionID));
|
|
5799
6199
|
}
|
|
5800
|
-
|
|
5801
|
-
|
|
5802
|
-
|
|
5803
|
-
if (typeof baseline === "string") {
|
|
5804
|
-
for (const part of checkpoint.content)
|
|
5805
|
-
if (part.type === "text" && typeof part.text === "string") {
|
|
5806
|
-
part.text = part.text.replace(`<summary>
|
|
5807
|
-
${submitted}
|
|
5808
|
-
</summary>`, `<summary>
|
|
5809
|
-
${baseline}
|
|
5810
|
-
</summary>`);
|
|
5811
|
-
}
|
|
5812
|
-
const volatile = draft.messages.find((message) => message.id === HEAD_IDS[1]);
|
|
5813
|
-
if (volatile && head)
|
|
5814
|
-
volatile.content.push(...head.content.filter((part) => part.type !== "text"));
|
|
5815
|
-
draft.messages.splice(0, draft.messages.length, checkpoint, ...draft.messages.filter((message) => message !== head));
|
|
5816
|
-
}
|
|
5817
|
-
}
|
|
6200
|
+
const head = replayHead !== undefined ? replayHead : checkpoint && submitted !== undefined ? { checkpoint, submitted } : null;
|
|
6201
|
+
const servedHead = head && structuredClone(head);
|
|
6202
|
+
const headApplied = head ? applyCheckpointHead(draft, head) : false;
|
|
5818
6203
|
if (nativeMessages && !checkpoint) {
|
|
5819
6204
|
try {
|
|
5820
6205
|
await nativeFoldReplay?.capture(draft, nativeMessages);
|
|
@@ -5825,7 +6210,7 @@ ${baseline}
|
|
|
5825
6210
|
}
|
|
5826
6211
|
const capturedSlot = getSlot(draft.sessionID);
|
|
5827
6212
|
if (capturedSlot && (!slotAtEntry || capturedSlot.capturedAt !== slotAtEntry.capturedAt || capturedSlot.captureSequence !== slotAtEntry.captureSequence || capturedSlot.jsonPrefix !== slotAtEntry.jsonPrefix)) {
|
|
5828
|
-
lkgSystems.capture(draft.sessionID, capturedSlot, systemAtEntry, draft.system);
|
|
6213
|
+
lkgSystems.capture(draft.sessionID, capturedSlot, { system: systemAtEntry, checkpoint: checkpointAtEntry ?? null }, draft.system, headApplied ? servedHead : null);
|
|
5829
6214
|
}
|
|
5830
6215
|
} catch (error) {
|
|
5831
6216
|
if (error instanceof V2LkgAdmissionReplay)
|
|
@@ -5834,8 +6219,11 @@ ${baseline}
|
|
|
5834
6219
|
throw error;
|
|
5835
6220
|
if (!compactionOff && (isTransientSqliteError2(error) || error instanceof StorageBusyRefusalError)) {
|
|
5836
6221
|
if (isTransientSqliteError2(error)) {
|
|
5837
|
-
const
|
|
6222
|
+
const input = await buildReplayInput();
|
|
5838
6223
|
try {
|
|
6224
|
+
if (!input)
|
|
6225
|
+
throw new StorageBusyRefusalError(error, "v2-context");
|
|
6226
|
+
const { mapped } = input;
|
|
5839
6227
|
await createMessagesTransformHandler({
|
|
5840
6228
|
replayFits,
|
|
5841
6229
|
onLkgReplay: restoreLkgSystem,
|
|
@@ -5847,6 +6235,7 @@ ${baseline}
|
|
|
5847
6235
|
}
|
|
5848
6236
|
})({}, mapped);
|
|
5849
6237
|
mapped.commit();
|
|
6238
|
+
adoptReplay(input.draft);
|
|
5850
6239
|
return;
|
|
5851
6240
|
} catch (replayError) {
|
|
5852
6241
|
if (!(replayError instanceof StorageBusyRefusalError))
|
|
@@ -5928,7 +6317,8 @@ ${baseline}
|
|
|
5928
6317
|
return null;
|
|
5929
6318
|
}
|
|
5930
6319
|
},
|
|
5931
|
-
storageDir
|
|
6320
|
+
storageDir,
|
|
6321
|
+
getDebugMemoryHolders: () => ({ generateReplay: generateReplay.stats() })
|
|
5932
6322
|
});
|
|
5933
6323
|
rpcServer.handle("dream", async (params) => {
|
|
5934
6324
|
const sessionId = String(params.sessionId ?? "");
|
|
@@ -6013,6 +6403,7 @@ ${baseline}
|
|
|
6013
6403
|
deletedSessions.clear();
|
|
6014
6404
|
await dreamTrigger?.dispose();
|
|
6015
6405
|
await maintenanceTimer?.dispose();
|
|
6406
|
+
await embeddings.dispose();
|
|
6016
6407
|
for (const release of rawProviders.values())
|
|
6017
6408
|
release();
|
|
6018
6409
|
rawProviders.clear();
|