@cortexkit/opencode-magic-context 0.47.0 → 0.48.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agents/magic-context-prompt.d.ts +1 -1
- package/dist/agents/magic-context-prompt.d.ts.map +1 -1
- package/dist/{announcement-y35wzg2r.js → announcement-fp14dw0n.js} +3 -2
- package/dist/auto-search-worker.js +27 -30
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/mural-model-deprecation.d.ts +15 -0
- package/dist/config/mural-model-deprecation.d.ts.map +1 -0
- package/dist/config/project-security.d.ts +0 -3
- package/dist/config/project-security.d.ts.map +1 -1
- package/dist/config/schema/magic-context.d.ts +10 -6
- package/dist/config/schema/magic-context.d.ts.map +1 -1
- package/dist/{conflict-warning-hook-z44ynfz7.js → conflict-warning-hook-w8cykrnf.js} +12 -10
- package/dist/{context-wq4ffwyb.js → context-m0cy262m.js} +2690 -1903
- package/dist/{derive-budgets-ke12jnnh.js → derive-budgets-sg0xsq7s.js} +4 -3
- package/dist/embedding-activity-g1dhes6g.js +10 -0
- package/dist/embedding-backfill-9rcm1mfy.js +21 -0
- package/dist/embedding-cache-mgyr73ef.js +16 -0
- package/dist/embedding-worker.js +11 -9
- package/dist/features/magic-context/compaction-marker.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/evaluate-smart-notes.d.ts +1 -0
- package/dist/features/magic-context/dreamer/evaluate-smart-notes.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-config.d.ts +3 -3
- package/dist/features/magic-context/dreamer/task-config.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-executor.d.ts +1 -1
- package/dist/features/magic-context/dreamer/task-executor.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-registry.d.ts +1 -0
- package/dist/features/magic-context/dreamer/task-registry.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/verify.d.ts.map +1 -1
- package/dist/features/magic-context/message-index-async.d.ts +16 -3
- package/dist/features/magic-context/message-index-async.d.ts.map +1 -1
- package/dist/features/magic-context/message-index-bounded.d.ts +17 -0
- package/dist/features/magic-context/message-index-bounded.d.ts.map +1 -0
- package/dist/features/magic-context/message-index.d.ts +7 -1
- package/dist/features/magic-context/message-index.d.ts.map +1 -1
- package/dist/features/magic-context/mural/render-trigger.d.ts +7 -4
- package/dist/features/magic-context/mural/render-trigger.d.ts.map +1 -1
- package/dist/features/magic-context/pi-content-decisions.d.ts +7 -1
- package/dist/features/magic-context/pi-content-decisions.d.ts.map +1 -1
- package/dist/features/magic-context/search.d.ts +29 -0
- package/dist/features/magic-context/search.d.ts.map +1 -1
- package/dist/features/magic-context/session-activity.d.ts.map +1 -1
- package/dist/features/magic-context/smart-notes/runner.d.ts +1 -0
- package/dist/features/magic-context/smart-notes/runner.d.ts.map +1 -1
- package/dist/features/magic-context/storage-db.d.ts.map +1 -1
- package/dist/features/magic-context/storage-meta-session.d.ts +6 -0
- package/dist/features/magic-context/storage-meta-session.d.ts.map +1 -1
- package/dist/features/magic-context/storage-tag-identity-revision.d.ts +30 -0
- package/dist/features/magic-context/storage-tag-identity-revision.d.ts.map +1 -0
- package/dist/features/magic-context/storage-tags.d.ts +144 -4
- package/dist/features/magic-context/storage-tags.d.ts.map +1 -1
- package/dist/features/magic-context/subagent-token-capture.d.ts.map +1 -1
- package/dist/features/magic-context/transform-decision-log.d.ts +1 -1
- package/dist/features/magic-context/transform-decision-log.d.ts.map +1 -1
- package/dist/harness-e4avh192.js +10 -0
- package/dist/hooks/magic-context/active-anthropic-turn.d.ts +2 -0
- package/dist/hooks/magic-context/active-anthropic-turn.d.ts.map +1 -1
- package/dist/hooks/magic-context/auto-search-worker-client.d.ts +32 -3
- package/dist/hooks/magic-context/auto-search-worker-client.d.ts.map +1 -1
- package/dist/hooks/magic-context/command-handler.d.ts +1 -0
- package/dist/hooks/magic-context/command-handler.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-incremental.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-recomp.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-trigger.d.ts.map +1 -1
- package/dist/hooks/magic-context/event-handler.d.ts.map +1 -1
- package/dist/hooks/magic-context/hook.d.ts +1 -1
- package/dist/hooks/magic-context/hook.d.ts.map +1 -1
- package/dist/hooks/magic-context/inject-compartments.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-persist.d.ts +4 -3
- package/dist/hooks/magic-context/lkg-persist.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-replay.d.ts +13 -8
- package/dist/hooks/magic-context/lkg-replay.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-slot.d.ts +139 -2
- package/dist/hooks/magic-context/lkg-slot.d.ts.map +1 -1
- package/dist/hooks/magic-context/message-search-accepting-silent-worker.fixture.d.ts +2 -0
- package/dist/hooks/magic-context/message-search-accepting-silent-worker.fixture.d.ts.map +1 -0
- package/dist/hooks/magic-context/oc-stall-r2-warmup-worker.fixture.d.ts +2 -0
- package/dist/hooks/magic-context/oc-stall-r2-warmup-worker.fixture.d.ts.map +1 -0
- package/dist/hooks/magic-context/oc-stall-search-review.fixture.d.ts +2 -0
- package/dist/hooks/magic-context/oc-stall-search-review.fixture.d.ts.map +1 -0
- package/dist/hooks/magic-context/opencode1-to-model-messages.fixture.d.ts +63 -0
- package/dist/hooks/magic-context/opencode1-to-model-messages.fixture.d.ts.map +1 -0
- package/dist/hooks/magic-context/provider-visible-parts.d.ts +45 -0
- package/dist/hooks/magic-context/provider-visible-parts.d.ts.map +1 -0
- package/dist/hooks/magic-context/raw-ordinal-warmup-silent-worker.fixture.d.ts +2 -0
- package/dist/hooks/magic-context/raw-ordinal-warmup-silent-worker.fixture.d.ts.map +1 -0
- package/dist/hooks/magic-context/raw-ordinal-warmup-worker.d.ts +2 -0
- package/dist/hooks/magic-context/raw-ordinal-warmup-worker.d.ts.map +1 -0
- package/dist/hooks/magic-context/raw-ordinal-warmup.d.ts +87 -0
- package/dist/hooks/magic-context/raw-ordinal-warmup.d.ts.map +1 -0
- package/dist/hooks/magic-context/read-session-chunk.d.ts +12 -0
- package/dist/hooks/magic-context/read-session-chunk.d.ts.map +1 -1
- package/dist/hooks/magic-context/read-session-db.d.ts.map +1 -1
- package/dist/hooks/magic-context/read-session-formatting.d.ts +5 -0
- package/dist/hooks/magic-context/read-session-formatting.d.ts.map +1 -1
- package/dist/hooks/magic-context/read-session-raw.d.ts +83 -1
- package/dist/hooks/magic-context/read-session-raw.d.ts.map +1 -1
- package/dist/hooks/magic-context/read-session-true-raw-tokens.d.ts.map +1 -1
- package/dist/hooks/magic-context/reasoning-budget.d.ts.map +1 -1
- package/dist/hooks/magic-context/sentinel.d.ts +41 -1
- package/dist/hooks/magic-context/sentinel.d.ts.map +1 -1
- package/dist/hooks/magic-context/strip-content.d.ts +14 -2
- package/dist/hooks/magic-context/strip-content.d.ts.map +1 -1
- package/dist/hooks/magic-context/system-prompt-hash.d.ts +1 -0
- package/dist/hooks/magic-context/system-prompt-hash.d.ts.map +1 -1
- package/dist/hooks/magic-context/tag-messages.d.ts +8 -0
- package/dist/hooks/magic-context/tag-messages.d.ts.map +1 -1
- package/dist/hooks/magic-context/tag-owner-warmup.d.ts +6 -0
- package/dist/hooks/magic-context/tag-owner-warmup.d.ts.map +1 -0
- package/dist/hooks/magic-context/tail-hygiene-walk.d.ts.map +1 -1
- package/dist/hooks/magic-context/token-count-exact.d.ts +35 -0
- package/dist/hooks/magic-context/token-count-exact.d.ts.map +1 -0
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform.d.ts +8 -2
- package/dist/hooks/magic-context/transform.d.ts.map +1 -1
- package/dist/hooks/magic-context/wrapup-orchestrator.d.ts.map +1 -1
- package/dist/{index-w2t4ah5j.js → index-0an7742d.js} +14072 -14286
- package/dist/index-0qhce371.js +120 -0
- package/dist/{index-q6hef7fh.js → index-0sahzkwr.js} +6 -19
- package/dist/{index-k5bdx1bx.js → index-0w56v4fm.js} +3 -5
- package/dist/index-14cjxt20.js +819 -0
- package/dist/{v2/server-51dv1pr5.js → index-1qb0z7wa.js} +301 -27
- package/dist/index-2bvekkfy.js +11 -0
- package/dist/{index-sj29b3z2.js → index-2y0s2hep.js} +3 -3
- package/dist/index-4dhv7mqz.js +131 -0
- package/dist/{index-b35pxds2.js → index-58e3y90n.js} +1 -18
- package/dist/index-5zygecde.js +152 -0
- package/dist/{index-6d9e1m08.js → index-692jzy0p.js} +17775 -17450
- package/dist/index-72nhv486.js +2307 -0
- package/dist/index-7jzrrxap.js +931 -0
- package/dist/{v2/server-njt3np1k.js → index-7mx8v0pw.js} +220 -961
- package/dist/index-8ajstryz.js +18 -0
- package/dist/{index-sfpzqvdz.js → index-8cd2j99z.js} +2 -3
- package/dist/{index-hybnrwq0.js → index-8j7gqj40.js} +131 -128
- package/dist/index-bdckkfw6.js +3261 -0
- package/dist/{index-m5fe6jch.js → index-bhvjj0ys.js} +152 -2453
- package/dist/index-c43kr12f.js +3030 -0
- package/dist/index-cb7emxgj.js +984 -0
- package/dist/index-d9vfe7xq.js +16 -0
- package/dist/{index-5gq3b2ya.js → index-db7zwa3v.js} +147 -209
- package/dist/index-dhwzyd54.js +1142 -0
- package/dist/{index-8da2zjhz.js → index-eeezr5zz.js} +9 -7
- package/dist/{index-cwf6s3ay.js → index-f0h6xwqm.js} +2828 -2618
- package/dist/index-fb3zxn06.js +13 -0
- package/dist/index-fbv1dn35.js +171 -0
- package/dist/index-fr0wbhdn.js +43 -0
- package/dist/{index-mc22ayvf.js → index-ghc9f0n7.js} +11 -9
- package/dist/{index-fzbvakh0.js → index-jcbd3znx.js} +3 -3
- package/dist/{index-5a2r0p9f.js → index-k1xb52kd.js} +20 -13
- package/dist/index-k9nnwad5.js +3532 -0
- package/dist/{index-wx8a6bw3.js → index-kb9nn0a0.js} +270 -53
- package/dist/index-knh4y330.js +566 -0
- package/dist/{v2/server-fq7kq32k.js → index-mfkzp7qj.js} +1 -16
- package/dist/{index-gg8j07zz.js → index-mmyh6d8f.js} +4 -4
- package/dist/index-pavzsdc6.js +17 -0
- package/dist/{index-0c82743p.js → index-pdecwzrd.js} +17 -15
- package/dist/index-pg50n748.js +1060 -0
- package/dist/{index-92bp57hg.js → index-q2tqeqde.js} +123 -80
- package/dist/{index-rrrsepyw.js → index-q7h7csab.js} +90 -85
- package/dist/{v2/server-yr3zj7e7.js → index-qt1qqasc.js} +6 -7
- package/dist/{index-6wkcswft.js → index-ty64eqcn.js} +28 -18
- package/dist/{index-adwfkpex.js → index-yq8n9qcb.js} +23 -23
- package/dist/{index-9pk9exrb.js → index-z8e0psj8.js} +18 -18
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +586 -344
- package/dist/logger-d3wex3dz.js +20 -0
- package/dist/message-index-bounded-7ezbgddp.js +124 -0
- package/dist/{v2/message-time-backfill-1f9tzvcs.js → message-time-backfill-brbd63hv.js} +8 -6
- package/dist/migration-worker.js +25 -18
- package/dist/{model-resolution-xhfmyyvy.js → model-resolution-nx97z3x7.js} +1 -1
- package/dist/plugin/dream-timer.d.ts +1 -1
- package/dist/plugin/dream-timer.d.ts.map +1 -1
- package/dist/plugin/hooks/create-session-hooks.d.ts +1 -0
- package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
- package/dist/plugin/host-stall-profiler-report.d.ts +1 -66
- package/dist/plugin/host-stall-profiler-report.d.ts.map +1 -1
- package/dist/plugin/host-stall-profiler.d.ts +2 -95
- package/dist/plugin/host-stall-profiler.d.ts.map +1 -1
- package/dist/plugin/messages-transform.d.ts +0 -13
- package/dist/plugin/messages-transform.d.ts.map +1 -1
- package/dist/plugin/rpc-handlers.d.ts.map +1 -1
- package/dist/plugin/tool-registry.d.ts.map +1 -1
- package/dist/project-embedding-registry-7qzptcw7.js +88 -0
- package/dist/raw-ordinal-warmup-worker.js +60 -0
- package/dist/{read-session-chunk-4jey7hpt.js → read-session-chunk-6k83m4fj.js} +15 -9
- package/dist/read-session-raw-3g9qy1xa.js +58 -0
- package/dist/recomp-orchestrator-d3fp1cy0.js +57 -0
- package/dist/{v2/safe-notification-target-eb1n1vfb.js → safe-notification-target-5ffqq32m.js} +4 -2
- package/dist/search-epax1ecv.js +45 -0
- package/dist/{v2/send-session-notification-c0wtscea.js → send-session-notification-erecz4y4.js} +10 -7
- package/dist/shared/conflict-detector.d.ts.map +1 -1
- package/dist/shared/host-stall-profiler-bun.d.ts +46 -0
- package/dist/shared/host-stall-profiler-bun.d.ts.map +1 -0
- package/dist/shared/host-stall-profiler-common.d.ts +58 -0
- package/dist/shared/host-stall-profiler-common.d.ts.map +1 -0
- package/dist/shared/host-stall-profiler-node.d.ts +36 -0
- package/dist/shared/host-stall-profiler-node.d.ts.map +1 -0
- package/dist/shared/host-stall-profiler-report.d.ts +68 -0
- package/dist/shared/host-stall-profiler-report.d.ts.map +1 -0
- package/dist/shared/host-stall-profiler.d.ts +5 -0
- package/dist/shared/host-stall-profiler.d.ts.map +1 -0
- package/dist/shared/model-resolution.d.ts +2 -3
- package/dist/shared/model-resolution.d.ts.map +1 -1
- package/dist/shared/sqlite.d.ts +30 -0
- package/dist/shared/sqlite.d.ts.map +1 -1
- package/dist/shared/stable-json.d.ts.map +1 -1
- package/dist/shared/user-facing-codes.d.ts +0 -5
- package/dist/shared/user-facing-codes.d.ts.map +1 -1
- package/dist/sqlite-context-pragmas-mv9jqwjh.js +6 -0
- package/dist/sqlite-mhjkerzq.js +46 -0
- package/dist/storage-memory-07fx57k6.js +71 -0
- package/dist/storage-tags-d3b0v2ss.js +131 -0
- package/dist/{task-config-v81k8jvk.js → task-config-cgpg0nvh.js} +2 -2
- package/dist/tools/ctx-expand/tools.d.ts.map +1 -1
- package/dist/tools/ctx-note/constants.d.ts +4 -0
- package/dist/tools/ctx-note/constants.d.ts.map +1 -1
- package/dist/tools/ctx-note/tools.d.ts +1 -0
- package/dist/tools/ctx-note/tools.d.ts.map +1 -1
- package/dist/tools/ctx-search/tools.d.ts.map +1 -1
- package/dist/tools/parameter-descriptions.d.ts +2 -2
- package/dist/tools/parameter-descriptions.d.ts.map +1 -1
- package/dist/{transform-postprocess-phase-z5hzpsxv.js → transform-postprocess-phase-spcy2qre.js} +35 -20
- package/dist/transformers-node-wasm.js +18415 -18415
- package/dist/v2/auto-search-worker.js +27 -30
- package/dist/v2/{context-14v1hr8b.js → context-sf98kstd.js} +3737 -3004
- package/dist/v2/{derive-budgets-nc9avxz8.js → derive-budgets-3vc0y84t.js} +4 -3
- package/dist/v2/embedding-activity-g1dhes6g.js +10 -0
- package/dist/v2/embedding-backfill-vn8g1nh1.js +21 -0
- package/dist/v2/embedding-cache-mgyr73ef.js +16 -0
- package/dist/v2/embedding-worker.js +12 -9
- package/dist/v2/fold/host-media.d.ts +4 -0
- package/dist/v2/fold/host-media.d.ts.map +1 -1
- package/dist/v2/fold/memory-cache.d.ts +70 -0
- package/dist/v2/fold/memory-cache.d.ts.map +1 -0
- package/dist/v2/fold/native-codec.d.ts +10 -0
- package/dist/v2/fold/native-codec.d.ts.map +1 -0
- package/dist/v2/fold/native-replay.d.ts +58 -0
- package/dist/v2/fold/native-replay.d.ts.map +1 -0
- package/dist/v2/fold/policy.d.ts +24 -0
- package/dist/v2/fold/policy.d.ts.map +1 -0
- package/dist/v2/harness-e4avh192.js +10 -0
- package/dist/v2/hooks/context.d.ts +2 -2
- package/dist/v2/hooks/context.d.ts.map +1 -1
- package/dist/v2/hooks/dream-manual.d.ts +1 -1
- package/dist/v2/hooks/dream-manual.d.ts.map +1 -1
- package/dist/v2/hooks/dream-timer.d.ts.map +1 -1
- package/dist/v2/hooks/dream-trigger.d.ts +1 -2
- package/dist/v2/hooks/dream-trigger.d.ts.map +1 -1
- package/dist/v2/hooks/payload.d.ts.map +1 -1
- package/dist/v2/hooks/tools.d.ts.map +1 -1
- package/dist/v2/hooks/types.d.ts +6 -0
- package/dist/v2/hooks/types.d.ts.map +1 -1
- package/dist/v2/logger-mxd0ym09.js +19 -0
- package/dist/v2/message-index-bounded-dy3s2k1e.js +123 -0
- package/dist/{message-time-backfill-r5epkzj3.js → v2/message-time-backfill-gtx1pwk1.js} +7 -7
- package/dist/v2/migration-worker.js +24 -17
- package/dist/v2/{model-resolution-xhfmyyvy.js → model-resolution-nx97z3x7.js} +1 -1
- package/dist/v2/project-embedding-registry-1tgba5dv.js +86 -0
- package/dist/v2/raw-ordinal-warmup-worker.js +60 -0
- package/dist/v2/{read-session-chunk-gyyv7w2r.js → read-session-chunk-rh4khdkv.js} +14 -8
- package/dist/v2/read-session-raw-bsbmf0vj.js +57 -0
- package/dist/v2/recomp-orchestrator-az61rfcg.js +57 -0
- package/dist/{safe-notification-target-43r8jsxw.js → v2/safe-notification-target-73ax1p5v.js} +3 -3
- package/dist/v2/search-nzkwrc6n.js +45 -0
- package/dist/{send-session-notification-0m68ms3n.js → v2/send-session-notification-6km439kn.js} +9 -8
- package/dist/{index-5eqk6z3s.js → v2/server-1r6pmz4f.js} +301 -27
- package/dist/v2/server-2bvekkfy.js +11 -0
- package/dist/v2/server-2fbhp79z.js +3205 -0
- package/dist/v2/{server-ajzeteqw.js → server-2ra6pwf3.js} +1 -18
- package/dist/v2/server-4dhv7mqz.js +131 -0
- package/dist/v2/{server-y10vbq6y.js → server-4k748ke6.js} +11 -1053
- package/dist/v2/{server-vs5gpnd4.js → server-52awr2mw.js} +81 -145
- package/dist/v2/{server-1qbnzc80.js → server-5m3dt5r1.js} +136 -148
- package/dist/v2/server-686jg6eb.js +3508 -0
- package/dist/v2/server-7jzrrxap.js +931 -0
- package/dist/v2/server-7wwc2nga.js +3023 -0
- package/dist/v2/server-8ajstryz.js +18 -0
- package/dist/v2/{server-sfpzqvdz.js → server-8cd2j99z.js} +2 -3
- package/dist/v2/{server-d0sraw7m.js → server-8pyt7hev.js} +291 -286
- package/dist/v2/server-8tqanswc.js +984 -0
- package/dist/v2/{server-14vq4kpm.js → server-aan4q8mx.js} +3 -3
- package/dist/v2/server-d9vfe7xq.js +16 -0
- package/dist/{index-x3kwrmqk.js → v2/server-e0vdaae2.js} +35 -792
- package/dist/v2/server-ezhze64f.js +1048 -0
- package/dist/v2/server-fb3zxn06.js +13 -0
- package/dist/v2/server-fr0wbhdn.js +43 -0
- package/dist/v2/server-g5r0n3b6.js +1137 -0
- package/dist/v2/server-gjcr4w98.js +154 -0
- package/dist/v2/server-k228xhjg.js +171 -0
- package/dist/v2/{server-nf82q6pt.js → server-k8x2rbxc.js} +5946 -5602
- package/dist/v2/{server-wx8a6bw3.js → server-kb9nn0a0.js} +270 -53
- package/dist/{index-rrbbspwh.js → v2/server-mfkzp7qj.js} +1 -16
- package/dist/v2/server-pavzsdc6.js +17 -0
- package/dist/v2/{server-e0c1b7a7.js → server-psqc7e9n.js} +122 -79
- package/dist/{index-yr3zj7e7.js → v2/server-qt1qqasc.js} +6 -7
- package/dist/v2/server-qye6ykf7.js +120 -0
- package/dist/v2/{server-qdjnb2z1.js → server-r5p3b1wy.js} +11 -9
- package/dist/v2/server-sggvvzhb.js +759 -0
- package/dist/v2/{server-cpepxy2q.js → server-v06jcv0w.js} +14 -12
- package/dist/v2/server-vqpf3167.js +1048 -0
- package/dist/v2/{server-rz514f14.js → server-x2g40a71.js} +2044 -2060
- package/dist/v2/{server-vd4e7174.js → server-xdfwt6kh.js} +20 -16
- package/dist/v2/{server-efhwzx05.js → server-xxm59eww.js} +23 -23
- package/dist/v2/server-yczc713m.js +564 -0
- package/dist/v2/{server-fcdehk1s.js → server-z2037m6z.js} +4 -4
- package/dist/v2/{server-50hvkg3v.js → server-zm570tr2.js} +160 -158
- package/dist/v2/{server-6r257mf5.js → server-zxhgvsf9.js} +3 -3
- package/dist/v2/server.js +16 -14
- package/dist/v2/sqlite-context-pragmas-mv9jqwjh.js +6 -0
- package/dist/v2/sqlite-mhjkerzq.js +46 -0
- package/dist/v2/storage-memory-07fx57k6.js +71 -0
- package/dist/v2/storage-tags-w4tv77sn.js +130 -0
- package/dist/v2/store-reader.d.ts +16 -0
- package/dist/v2/store-reader.d.ts.map +1 -1
- package/dist/v2/{task-config-tbndqyny.js → task-config-x0hq3qfd.js} +2 -2
- package/dist/v2/transformers-node-wasm.js +18415 -18415
- package/dist/v2/tui/index.d.ts.map +1 -1
- package/dist/v2/tui/types.d.ts +1 -10
- package/dist/v2/tui/types.d.ts.map +1 -1
- package/dist/v2/{wrapup-orchestrator-nbz854vc.js → wrapup-orchestrator-mz7efs7w.js} +51 -30
- package/dist/wrapup-orchestrator-amzta1t4.js +44 -0
- package/package.json +4 -3
- package/src/agents/magic-context-prompt.ts +27 -2
- package/src/agents/smart-notes-enabled.test.ts +294 -0
- package/src/agents/smart-notes-on.golden.json +70 -0
- package/src/config/index.test.ts +67 -1
- package/src/config/index.ts +2 -0
- package/src/config/latch-permanence-guard.test.ts +4 -0
- package/src/config/mural-model-deprecation.ts +24 -0
- package/src/config/project-security.hostile-matrix.test.ts +4 -44
- package/src/config/project-security.test.ts +9 -14
- package/src/config/project-security.ts +13 -55
- package/src/config/schema/magic-context.test.ts +2 -2
- package/src/config/schema/magic-context.ts +16 -10
- package/src/features/magic-context/dreamer/task-registry.ts +6 -0
- package/src/shared/conflict-detector.test.ts +56 -0
- package/src/shared/conflict-detector.ts +16 -5
- package/src/shared/host-stall-profiler-bun.ts +358 -0
- package/src/shared/host-stall-profiler-common.ts +159 -0
- package/src/shared/host-stall-profiler-node.test.ts +234 -0
- package/src/shared/host-stall-profiler-node.ts +274 -0
- package/src/shared/host-stall-profiler-report.ts +248 -0
- package/src/shared/host-stall-profiler.ts +57 -0
- package/src/shared/model-resolution.test.ts +54 -17
- package/src/shared/model-resolution.ts +6 -17
- package/src/shared/sqlite.test.ts +52 -0
- package/src/shared/sqlite.ts +339 -23
- package/src/shared/stable-json-linear.test.ts +109 -0
- package/src/shared/stable-json.ts +37 -7
- package/src/shared/user-facing-codes.ts +2 -6
- package/src/shared/write-transaction-attribution.test.ts +2 -2
- package/src/v2/tui/host-contract.test.ts +41 -67
- package/src/v2/tui/index.ts +6 -214
- package/src/v2/tui/types.ts +5 -17
- package/dist/features/magic-context/checkout-claim-fake-subc.test-support.d.ts +0 -45
- package/dist/features/magic-context/checkout-claim-fake-subc.test-support.d.ts.map +0 -1
- package/dist/features/magic-context/checkout-claim.d.ts +0 -155
- package/dist/features/magic-context/checkout-claim.d.ts.map +0 -1
- package/dist/index-bb36vgr3.js +0 -6608
- package/dist/index-fnn5pjtt.js +0 -6554
- package/dist/recomp-orchestrator-rervg6q4.js +0 -42
- package/dist/v2/recomp-orchestrator-42vjba7p.js +0 -42
- package/dist/v2/server-3trjk1hx.js +0 -6360
- package/dist/v2/server-nm9n3aqq.js +0 -6461
- package/dist/wrapup-orchestrator-b2dztrar.js +0 -29
- /package/dist/{index-5prbx026.js → index-2pp04pmg.js} +0 -0
- /package/dist/v2/{index-5prbx026.js → index-2pp04pmg.js} +0 -0
package/dist/index.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
setHarness2
|
|
3
|
+
} from "./index-pavzsdc6.js";
|
|
4
|
+
import {
|
|
3
5
|
getOpenCodeStorageDir,
|
|
4
6
|
getMagicContextStorageDir
|
|
5
|
-
} from "./index-
|
|
7
|
+
} from "./index-0sahzkwr.js";
|
|
6
8
|
import {
|
|
7
9
|
registerStalePluginBuildHost,
|
|
8
10
|
importPluginModule,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
} from "./index-
|
|
11
|
+
log2,
|
|
12
|
+
sessionLog2,
|
|
13
|
+
flushLogger2
|
|
14
|
+
} from "./index-8j7gqj40.js";
|
|
13
15
|
import {
|
|
14
16
|
withContentLanguageDirective,
|
|
15
17
|
string,
|
|
@@ -21,7 +23,7 @@ import {
|
|
|
21
23
|
record,
|
|
22
24
|
DEFAULT_EXECUTE_THRESHOLD_PERCENTAGE,
|
|
23
25
|
DEFAULT_HISTORIAN_TIMEOUT_MS
|
|
24
|
-
} from "./index-
|
|
26
|
+
} from "./index-bhvjj0ys.js";
|
|
25
27
|
import {
|
|
26
28
|
denyTaskRoutingToCallerAgents,
|
|
27
29
|
buildHiddenAgentRegistrations,
|
|
@@ -79,13 +81,14 @@ import {
|
|
|
79
81
|
markSessionCleanupPending,
|
|
80
82
|
clearSession,
|
|
81
83
|
recordPromptSessionError,
|
|
84
|
+
CTX_NOTE_LIGHT_DESCRIPTION,
|
|
82
85
|
createPromptSurfaceRuntime,
|
|
83
86
|
setKeepSubagents,
|
|
84
87
|
removeCompactionMarkerForSession,
|
|
85
88
|
checkCompactionMarkerConsistency,
|
|
86
89
|
clearInjectionCache,
|
|
87
90
|
clearNoteNudgeTriggerOnly
|
|
88
|
-
} from "./index-
|
|
91
|
+
} from "./index-692jzy0p.js";
|
|
89
92
|
import"./index-sd3egckz.js";
|
|
90
93
|
import {
|
|
91
94
|
reloadWindowOverlay,
|
|
@@ -96,19 +99,16 @@ import {
|
|
|
96
99
|
deriveHistorianChunkTokens2,
|
|
97
100
|
resolveKnownHistorianContextLimit2,
|
|
98
101
|
resolveHistorianContextLimit2
|
|
99
|
-
} from "./index-
|
|
100
|
-
import"./index-
|
|
102
|
+
} from "./index-pdecwzrd.js";
|
|
103
|
+
import"./index-mfkzp7qj.js";
|
|
101
104
|
import {
|
|
102
105
|
resolveOpenCodeDbPath,
|
|
103
106
|
openCodeDbPathExists,
|
|
104
107
|
formatOpenCodeDbMissingBanner,
|
|
105
|
-
claimOpenCodeDbDiagnosticOnce
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
import"./index-wx8a6bw3.js";
|
|
108
|
+
claimOpenCodeDbDiagnosticOnce
|
|
109
|
+
} from "./index-58e3y90n.js";
|
|
110
|
+
import"./index-kb9nn0a0.js";
|
|
109
111
|
import {
|
|
110
|
-
createSubcCheckoutClaimGate,
|
|
111
|
-
openCodeEventSessionId,
|
|
112
112
|
openOpenCodeDb,
|
|
113
113
|
DREAMER_SYSTEM_PROMPT,
|
|
114
114
|
runSessionProjectBackfill,
|
|
@@ -171,12 +171,13 @@ import {
|
|
|
171
171
|
CTX_MEMORY_ACTIONS,
|
|
172
172
|
createCtxMemoryTools,
|
|
173
173
|
createCtxMemoryListTools,
|
|
174
|
+
withoutSmartNoteText,
|
|
174
175
|
createCtxNoteTools,
|
|
175
176
|
createCtxReduceTools,
|
|
176
177
|
createCtxSearchTools,
|
|
177
178
|
parameterDescriptionsFor,
|
|
178
179
|
MagicContextRpcServer
|
|
179
|
-
} from "./index-
|
|
180
|
+
} from "./index-0an7742d.js";
|
|
180
181
|
import {
|
|
181
182
|
formatFailClosedBlockingMessage,
|
|
182
183
|
createFailClosedController,
|
|
@@ -191,7 +192,7 @@ import {
|
|
|
191
192
|
openDatabaseAsync,
|
|
192
193
|
isDatabasePersisted,
|
|
193
194
|
getDatabasePersistenceError
|
|
194
|
-
} from "./index-
|
|
195
|
+
} from "./index-q7h7csab.js";
|
|
195
196
|
import {
|
|
196
197
|
setHomeProjectPermission,
|
|
197
198
|
ProjectIdentityError,
|
|
@@ -202,28 +203,33 @@ import {
|
|
|
202
203
|
beginBootQuietPeriod,
|
|
203
204
|
bootQuietRemainingMs,
|
|
204
205
|
scheduleAfterBootQuiet
|
|
205
|
-
} from "./index-
|
|
206
|
+
} from "./index-knh4y330.js";
|
|
207
|
+
import {
|
|
208
|
+
deleteTemporalDecision
|
|
209
|
+
} from "./index-db7zwa3v.js";
|
|
206
210
|
import {
|
|
207
211
|
observeSessionActivity,
|
|
208
212
|
backfillSessionActivity,
|
|
213
|
+
deleteIndexedMessage
|
|
214
|
+
} from "./index-14cjxt20.js";
|
|
215
|
+
import {
|
|
209
216
|
recordSessionProjectIdentity,
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
217
|
+
getProjectEmbeddingSnapshot2,
|
|
218
|
+
getEmbeddingCoverageStatus2,
|
|
219
|
+
getAutoEmbeddingSessionCoverage2
|
|
220
|
+
} from "./index-c43kr12f.js";
|
|
221
|
+
import"./index-fb3zxn06.js";
|
|
222
|
+
import"./index-fbv1dn35.js";
|
|
223
|
+
import"./index-7mx8v0pw.js";
|
|
224
|
+
import"./index-fr0wbhdn.js";
|
|
225
|
+
import {
|
|
226
|
+
preloadTokenizer
|
|
227
|
+
} from "./index-1qb0z7wa.js";
|
|
215
228
|
import {
|
|
216
|
-
deleteTemporalDecision,
|
|
217
229
|
getCurrentToolSetHash,
|
|
218
230
|
recordToolDefinition
|
|
219
|
-
} from "./index-
|
|
231
|
+
} from "./index-0qhce371.js";
|
|
220
232
|
import {
|
|
221
|
-
preloadTokenizer
|
|
222
|
-
} from "./index-5eqk6z3s.js";
|
|
223
|
-
import {
|
|
224
|
-
stripPersistedAssistantText,
|
|
225
|
-
deleteTagsByMessageId,
|
|
226
|
-
getMaxTagNumberBySession,
|
|
227
233
|
invalidateTrueRawTokenCache,
|
|
228
234
|
recordToolParameters,
|
|
229
235
|
createDroppedInputToolExecuteBeforeHook,
|
|
@@ -233,60 +239,76 @@ import {
|
|
|
233
239
|
detectOverflow,
|
|
234
240
|
isAnthropicFamilyRoute,
|
|
235
241
|
readRawSessionMessages2
|
|
236
|
-
} from "./index-
|
|
242
|
+
} from "./index-bdckkfw6.js";
|
|
243
|
+
import"./index-72nhv486.js";
|
|
237
244
|
import {
|
|
238
|
-
|
|
239
|
-
} from "./index-
|
|
240
|
-
import"./index-
|
|
245
|
+
isEmbeddingHostBusy2
|
|
246
|
+
} from "./index-qt1qqasc.js";
|
|
247
|
+
import"./index-jcbd3znx.js";
|
|
248
|
+
import {
|
|
249
|
+
registerExitAbort,
|
|
250
|
+
unregisterExitAbort,
|
|
251
|
+
forgetRawSessionOrdinalWatermark2
|
|
252
|
+
} from "./index-dhwzyd54.js";
|
|
241
253
|
import {
|
|
242
254
|
observeOpenCodeTurnEvent,
|
|
243
255
|
clearTrackedOpenCodeSession,
|
|
244
256
|
findLastAssistantModelFromOpenCodeDb
|
|
245
|
-
} from "./index-
|
|
257
|
+
} from "./index-ty64eqcn.js";
|
|
246
258
|
import {
|
|
247
259
|
sendCommandResult2,
|
|
248
260
|
sendStatusNotification2
|
|
249
|
-
} from "./index-
|
|
261
|
+
} from "./index-yq8n9qcb.js";
|
|
250
262
|
import {
|
|
251
263
|
detectConflicts,
|
|
252
264
|
resolveCompactionForBoot
|
|
253
|
-
} from "./index-
|
|
265
|
+
} from "./index-eeezr5zz.js";
|
|
254
266
|
import {
|
|
255
267
|
sendConflictWarning2,
|
|
256
268
|
cleanupConflictWarnings2
|
|
257
|
-
} from "./index-
|
|
269
|
+
} from "./index-z8e0psj8.js";
|
|
258
270
|
import"./index-1zx87sdm.js";
|
|
271
|
+
import {
|
|
272
|
+
stripPersistedAssistantText,
|
|
273
|
+
deleteTagsByMessageId2,
|
|
274
|
+
getMaxTagNumberBySession2
|
|
275
|
+
} from "./index-k9nnwad5.js";
|
|
259
276
|
import {
|
|
260
277
|
resolveHistorianModel2,
|
|
261
278
|
resolveOpenCodeAgentOverrides2,
|
|
262
279
|
resolveHistorianAgentOverrides2
|
|
263
|
-
} from "./index-
|
|
280
|
+
} from "./index-8cd2j99z.js";
|
|
264
281
|
import {
|
|
265
282
|
buildDreamTaskRuntimeConfigs2,
|
|
266
283
|
userMemoryCollectionEnabled2
|
|
267
|
-
} from "./index-
|
|
284
|
+
} from "./index-ghc9f0n7.js";
|
|
285
|
+
import"./index-pg50n748.js";
|
|
286
|
+
import"./index-cb7emxgj.js";
|
|
268
287
|
import {
|
|
269
288
|
pushNotification2
|
|
270
289
|
} from "./index-x8a7jmkh.js";
|
|
271
|
-
import"./index-
|
|
290
|
+
import"./index-4dhv7mqz.js";
|
|
291
|
+
import"./index-5zygecde.js";
|
|
292
|
+
import"./index-7jzrrxap.js";
|
|
293
|
+
import"./index-q2tqeqde.js";
|
|
272
294
|
import {
|
|
273
295
|
createTagger,
|
|
274
296
|
cavemanWordRulesForLanguage,
|
|
275
297
|
setCtxReduceRegisteredGlobally,
|
|
276
298
|
clearToolPermissionDenied,
|
|
277
299
|
resetDegradedCacheCount2
|
|
278
|
-
} from "./index-
|
|
300
|
+
} from "./index-f0h6xwqm.js";
|
|
279
301
|
import {
|
|
280
302
|
runManagedRecomp2
|
|
281
|
-
} from "./index-
|
|
303
|
+
} from "./index-mmyh6d8f.js";
|
|
282
304
|
import {
|
|
283
305
|
isValidSemver,
|
|
284
306
|
compareSemverCore
|
|
285
|
-
} from "./index-
|
|
307
|
+
} from "./index-0w56v4fm.js";
|
|
286
308
|
import"./index-fmsr7v69.js";
|
|
287
309
|
import {
|
|
288
310
|
runManagedWrapup2
|
|
289
|
-
} from "./index-
|
|
311
|
+
} from "./index-k1xb52kd.js";
|
|
290
312
|
import {
|
|
291
313
|
__toESM,
|
|
292
314
|
__commonJS
|
|
@@ -303,7 +325,10 @@ import {
|
|
|
303
325
|
import {
|
|
304
326
|
piModelRefToCanonical
|
|
305
327
|
} from "./index-avwt563y.js";
|
|
306
|
-
import
|
|
328
|
+
import {
|
|
329
|
+
closeQuietly
|
|
330
|
+
} from "./index-8ajstryz.js";
|
|
331
|
+
import"./index-2y0s2hep.js";
|
|
307
332
|
|
|
308
333
|
// ../../node_modules/.bun/esprima@4.0.1/node_modules/esprima/dist/esprima.js
|
|
309
334
|
var require_esprima = __commonJS(function(exports, module) {
|
|
@@ -8359,9 +8384,9 @@ async function runDeferredV22Backfill(db, options = {}) {
|
|
|
8359
8384
|
const status = updateFinalBackfillStatus(db);
|
|
8360
8385
|
const failureCount = countFailures(db);
|
|
8361
8386
|
if (failureCount > 0) {
|
|
8362
|
-
|
|
8387
|
+
log2(`[v22-backfill] completed with ${failureCount} unresolved failure(s); run doctor --retry-v22-backfill`);
|
|
8363
8388
|
} else {
|
|
8364
|
-
|
|
8389
|
+
log2(`[v22-backfill] completed; processed=${processedRows}, changed=${changedRows}`);
|
|
8365
8390
|
}
|
|
8366
8391
|
return {
|
|
8367
8392
|
status,
|
|
@@ -8460,7 +8485,7 @@ var PackageJsonSchema = object({
|
|
|
8460
8485
|
|
|
8461
8486
|
// src/hooks/auto-update-checker/checker.ts
|
|
8462
8487
|
function warn(message) {
|
|
8463
|
-
|
|
8488
|
+
log2(`WARN: ${message}`);
|
|
8464
8489
|
}
|
|
8465
8490
|
function isString(value) {
|
|
8466
8491
|
return typeof value === "string";
|
|
@@ -8530,7 +8555,7 @@ function getWinningConfig(directory, surface) {
|
|
|
8530
8555
|
const entries = getPluginEntries(parsed);
|
|
8531
8556
|
if (entries.some((entry) => entry === PACKAGE_NAME || entry.startsWith(`${PACKAGE_NAME}@`))) {
|
|
8532
8557
|
if (winner) {
|
|
8533
|
-
|
|
8558
|
+
log2(`[auto-update-checker] ${surface} config ${winner.path} is shadowed by ${path}`);
|
|
8534
8559
|
}
|
|
8535
8560
|
winner = { path, entries };
|
|
8536
8561
|
}
|
|
@@ -8830,7 +8855,7 @@ var DEFAULT_INIT_DELAY_MS = 5000;
|
|
|
8830
8855
|
var PENDING_UPDATE_FILENAME = "pending-plugin-update.json";
|
|
8831
8856
|
var PENDING_UPDATE_MAX_AGE_MS = 7 * 24 * 60 * 60 * 1000;
|
|
8832
8857
|
function warn2(message) {
|
|
8833
|
-
|
|
8858
|
+
log2(`WARN: ${message}`);
|
|
8834
8859
|
}
|
|
8835
8860
|
function createAutoUpdateCheckerHook(ctx, options = {}) {
|
|
8836
8861
|
const {
|
|
@@ -8873,7 +8898,7 @@ async function maybeRunCheck(ctx, options) {
|
|
|
8873
8898
|
if (options.signal.aborted)
|
|
8874
8899
|
return;
|
|
8875
8900
|
if (!claimCheckSlot(options.storageDir, options.checkIntervalMs)) {
|
|
8876
|
-
|
|
8901
|
+
log2("[auto-update-checker] Skipping check (another instance ran one recently)");
|
|
8877
8902
|
return;
|
|
8878
8903
|
}
|
|
8879
8904
|
await runStartupCheck(ctx, options);
|
|
@@ -8937,7 +8962,7 @@ function consumePendingUpdateMarker(storageDir, loadedVersion) {
|
|
|
8937
8962
|
const olderThanLoaded = typeof marker.version === "string" && typeof loadedVersion === "string" && (compareSemverCore(marker.version, loadedVersion) ?? 0) < 0;
|
|
8938
8963
|
if (marker.version === loadedVersion && marker.spec === `${PACKAGE_NAME}@${loadedVersion}` && Array.isArray(marker.configPaths) && marker.configPaths.length === 2) {
|
|
8939
8964
|
rmSync(path, { force: true });
|
|
8940
|
-
|
|
8965
|
+
log2(`[auto-update-checker] Pending update applied: ${marker.spec}`);
|
|
8941
8966
|
} else if (age > PENDING_UPDATE_MAX_AGE_MS || olderThanLoaded) {
|
|
8942
8967
|
rmSync(path, { force: true });
|
|
8943
8968
|
warn2("[auto-update-checker] Discarded stale or mismatched pending update marker");
|
|
@@ -8960,7 +8985,7 @@ async function runStartupCheck(ctx, options) {
|
|
|
8960
8985
|
if (options.showStartupToast) {
|
|
8961
8986
|
showToast(ctx, `Magic Context ${displayVersion} (dev)`, "Running in local development mode.", "info");
|
|
8962
8987
|
}
|
|
8963
|
-
|
|
8988
|
+
log2("[auto-update-checker] Local development mode");
|
|
8964
8989
|
return;
|
|
8965
8990
|
}
|
|
8966
8991
|
if (options.showStartupToast) {
|
|
@@ -8973,19 +8998,19 @@ async function runBackgroundUpdateCheck(ctx, options) {
|
|
|
8973
8998
|
return;
|
|
8974
8999
|
const pluginInfo = findPluginEntry(ctx.directory);
|
|
8975
9000
|
if (!pluginInfo) {
|
|
8976
|
-
|
|
9001
|
+
log2("[auto-update-checker] Plugin not found in config");
|
|
8977
9002
|
return;
|
|
8978
9003
|
}
|
|
8979
9004
|
if (hasExplicitNonExactPluginVersion(pluginInfo.entry)) {
|
|
8980
9005
|
if (pluginInfo.entry === `${PACKAGE_NAME}@latest`) {
|
|
8981
|
-
|
|
9006
|
+
log2("[auto-update-checker] Explicit @latest leaves the active package unpinned; OpenCode may delete it mid-session.");
|
|
8982
9007
|
}
|
|
8983
9008
|
return;
|
|
8984
9009
|
}
|
|
8985
9010
|
const cachedVersion = getCachedVersion(pluginInfo.entry);
|
|
8986
9011
|
const currentVersion = cachedVersion ?? pluginInfo.pinnedVersion;
|
|
8987
9012
|
if (!currentVersion) {
|
|
8988
|
-
|
|
9013
|
+
log2("[auto-update-checker] No version found (cached or pinned)");
|
|
8989
9014
|
return;
|
|
8990
9015
|
}
|
|
8991
9016
|
const channel = extractChannel(pluginInfo.pinnedVersion ?? currentVersion);
|
|
@@ -9000,22 +9025,22 @@ async function runBackgroundUpdateCheck(ctx, options) {
|
|
|
9000
9025
|
return;
|
|
9001
9026
|
}
|
|
9002
9027
|
if (currentVersion === latestVersion) {
|
|
9003
|
-
|
|
9028
|
+
log2(`[auto-update-checker] Already on latest version for channel: ${channel}`);
|
|
9004
9029
|
return;
|
|
9005
9030
|
}
|
|
9006
|
-
|
|
9031
|
+
log2(`[auto-update-checker] Update available (${channel}): ${currentVersion} → ${latestVersion}`);
|
|
9007
9032
|
const updaterOwnedPin = pluginInfo.isPinned && isUpdaterPinnedSpec(readAutoUpdateCheckState(checkStatePath(options.storageDir)), pluginInfo.entry);
|
|
9008
9033
|
if (pluginInfo.isPinned && !updaterOwnedPin) {
|
|
9009
9034
|
showToast(ctx, `Magic Context ${latestVersion}`, `v${latestVersion} available. This version was pinned by you; update your OpenCode plugin config to upgrade.`, "info", 8000);
|
|
9010
|
-
|
|
9035
|
+
log2("[auto-update-checker] Version was pinned by you; skipping auto-update");
|
|
9011
9036
|
return;
|
|
9012
9037
|
}
|
|
9013
9038
|
if (updaterOwnedPin) {
|
|
9014
|
-
|
|
9039
|
+
log2("[auto-update-checker] Version was pinned by the updater; continuing auto-update");
|
|
9015
9040
|
}
|
|
9016
9041
|
if (!options.autoUpdate) {
|
|
9017
9042
|
showToast(ctx, `Magic Context ${latestVersion}`, `v${latestVersion} available. Auto-update is disabled.`, "info", 8000);
|
|
9018
|
-
|
|
9043
|
+
log2("[auto-update-checker] Auto-update disabled, notification only");
|
|
9019
9044
|
return;
|
|
9020
9045
|
}
|
|
9021
9046
|
const preparedUpdate = await preparePluginUpdate(ctx.directory, pluginInfo, latestVersion, {
|
|
@@ -9025,7 +9050,7 @@ async function runBackgroundUpdateCheck(ctx, options) {
|
|
|
9025
9050
|
writePendingUpdateMarker(options.storageDir, preparedUpdate, latestVersion);
|
|
9026
9051
|
showToast(ctx, "Magic Context Update Ready", `v${currentVersion} → v${latestVersion}
|
|
9027
9052
|
Restart OpenCode to apply.`, "success", 8000);
|
|
9028
|
-
|
|
9053
|
+
log2(`[auto-update-checker] Update ready: ${currentVersion} → ${latestVersion}`);
|
|
9029
9054
|
return;
|
|
9030
9055
|
}
|
|
9031
9056
|
showToast(ctx, `Magic Context ${latestVersion}`, `v${latestVersion} available, but auto-update failed to update both plugin configs.`, "error", 8000);
|
|
@@ -9276,7 +9301,7 @@ function recordSwallowedWrite(error) {
|
|
|
9276
9301
|
try {
|
|
9277
9302
|
swallowedWriteCount++;
|
|
9278
9303
|
lastErrorMessage = error instanceof Error ? error.message : String(error);
|
|
9279
|
-
|
|
9304
|
+
log2("[magic-context] window report ledger write failed:", error);
|
|
9280
9305
|
} catch {}
|
|
9281
9306
|
}
|
|
9282
9307
|
function positiveFiniteNumber(value) {
|
|
@@ -9433,12 +9458,12 @@ function noteContextLimitResolution(sessionId, resolution) {
|
|
|
9433
9458
|
const previous = lastResolutionBySession.get(sessionId);
|
|
9434
9459
|
lastResolutionBySession.set(sessionId, resolution);
|
|
9435
9460
|
if (!previous) {
|
|
9436
|
-
|
|
9461
|
+
sessionLog2(sessionId, `context limit resolved: ${resolution.limit} for ${resolution.modelKey ?? "unknown model"} (catalog ${resolution.catalog ?? "unknown"}, overflow-detected ${resolution.detected}, proven accepted input ${resolution.provenFloor})`);
|
|
9437
9462
|
return;
|
|
9438
9463
|
}
|
|
9439
9464
|
const change = describeContextLimitChange(previous, resolution);
|
|
9440
9465
|
if (change)
|
|
9441
|
-
|
|
9466
|
+
sessionLog2(sessionId, change);
|
|
9442
9467
|
}
|
|
9443
9468
|
|
|
9444
9469
|
// src/hooks/magic-context/event-handler.ts
|
|
@@ -9472,16 +9497,16 @@ async function deliverChannel2IfPending(deps, sessionId) {
|
|
|
9472
9497
|
deps.channel2DirectiveTextBySession?.delete(sessionId);
|
|
9473
9498
|
}
|
|
9474
9499
|
} catch (error) {
|
|
9475
|
-
|
|
9500
|
+
sessionLog2(sessionId, "channel2 delivery wrapper failed (ignored):", error);
|
|
9476
9501
|
}
|
|
9477
9502
|
}
|
|
9478
9503
|
function cleanupRemovedMessageState(deps, sessionId, messageId) {
|
|
9479
9504
|
return deps.db.transaction(() => {
|
|
9480
|
-
const removedTagNumbers =
|
|
9505
|
+
const removedTagNumbers = deleteTagsByMessageId2(deps.db, sessionId, messageId);
|
|
9481
9506
|
deleteTemporalDecision(deps.db, sessionId, messageId);
|
|
9482
|
-
|
|
9507
|
+
sessionLog2(sessionId, `event message.removed: deleted ${removedTagNumbers.length} tag(s) for message ${messageId}`);
|
|
9483
9508
|
const strippedPlaceholderRemoved = removeStrippedPlaceholderId(deps.db, sessionId, messageId);
|
|
9484
|
-
|
|
9509
|
+
sessionLog2(sessionId, strippedPlaceholderRemoved ? `event message.removed: removed ${messageId} from stripped placeholder ids` : `event message.removed: stripped placeholder ids unchanged for ${messageId}`);
|
|
9485
9510
|
const removedNoteNudgeAnchor = removeNoteNudgeAnchorByMessageId(deps.db, sessionId, messageId);
|
|
9486
9511
|
const removedAutoSearchDecision = removeAutoSearchHintDecisionByMessageId(deps.db, sessionId, messageId);
|
|
9487
9512
|
const persistedNoteNudge = getPersistedNoteNudge(deps.db, sessionId);
|
|
@@ -9490,18 +9515,18 @@ function cleanupRemovedMessageState(deps, sessionId, messageId) {
|
|
|
9490
9515
|
clearNoteNudgeTriggerOnly(deps.db, sessionId);
|
|
9491
9516
|
}
|
|
9492
9517
|
const clearedNoteNudge = removedNoteNudgeAnchor || clearedNoteNudgeTrigger;
|
|
9493
|
-
|
|
9494
|
-
|
|
9518
|
+
sessionLog2(sessionId, clearedNoteNudge ? `event message.removed: pruned note nudge state for ${messageId}` : `event message.removed: note nudge state unchanged for ${messageId}`);
|
|
9519
|
+
sessionLog2(sessionId, removedAutoSearchDecision ? `event message.removed: pruned auto-search decision for ${messageId}` : `event message.removed: auto-search decision unchanged for ${messageId}`);
|
|
9495
9520
|
const currentWatermark = getPersistedReasoningWatermark(deps.db, sessionId);
|
|
9496
|
-
const maxRemainingTag =
|
|
9521
|
+
const maxRemainingTag = getMaxTagNumberBySession2(deps.db, sessionId);
|
|
9497
9522
|
if (currentWatermark > maxRemainingTag) {
|
|
9498
9523
|
setPersistedReasoningWatermark(deps.db, sessionId, maxRemainingTag);
|
|
9499
|
-
|
|
9524
|
+
sessionLog2(sessionId, `event message.removed: reset reasoning watermark ${currentWatermark}→${maxRemainingTag}`);
|
|
9500
9525
|
} else {
|
|
9501
|
-
|
|
9526
|
+
sessionLog2(sessionId, `event message.removed: reasoning watermark unchanged at ${currentWatermark} (max tag ${maxRemainingTag})`);
|
|
9502
9527
|
}
|
|
9503
9528
|
const removedIndexedMessages = deleteIndexedMessage(deps.db, sessionId, messageId);
|
|
9504
|
-
|
|
9529
|
+
sessionLog2(sessionId, `event message.removed: deleted ${removedIndexedMessages} indexed message row(s) for ${messageId}`);
|
|
9505
9530
|
return {
|
|
9506
9531
|
clearedNoteNudge
|
|
9507
9532
|
};
|
|
@@ -9520,7 +9545,7 @@ function createEventHandler2(deps) {
|
|
|
9520
9545
|
}
|
|
9521
9546
|
if (deps.internalChildSessions && info.parentID.length > 0 && typeof info.title === "string" && info.title.startsWith(INTERNAL_CHILD_TITLE_PREFIX)) {
|
|
9522
9547
|
deps.internalChildSessions.add(info.id);
|
|
9523
|
-
|
|
9548
|
+
sessionLog2(info.id, `marked internal magic-context child (title="${info.title}") — exempt from transform + injection`);
|
|
9524
9549
|
}
|
|
9525
9550
|
try {
|
|
9526
9551
|
if (info.directory) {
|
|
@@ -9533,7 +9558,7 @@ function createEventHandler2(deps) {
|
|
|
9533
9558
|
cacheTtl: resolveSessionCacheTtl(deps.db, info.id, ttlConfig.cache_ttl, modelKey, ttlConfig.cacheTtlConfigured).value
|
|
9534
9559
|
});
|
|
9535
9560
|
} catch (error) {
|
|
9536
|
-
|
|
9561
|
+
sessionLog2(info.id, "event session.created persistence failed:", error);
|
|
9537
9562
|
}
|
|
9538
9563
|
return;
|
|
9539
9564
|
}
|
|
@@ -9558,7 +9583,7 @@ function createEventHandler2(deps) {
|
|
|
9558
9583
|
const model = findLastAssistantModelFromOpenCodeDb(errInfo.sessionID);
|
|
9559
9584
|
if (deps.thinkingBindingRecoveryEnabled !== false && !deps.compactionOff && isPrefixBoundThinkingModel(model?.providerID, model?.modelID)) {
|
|
9560
9585
|
armBindingRecoverySafely(deps.db, errInfo.sessionID);
|
|
9561
|
-
|
|
9586
|
+
sessionLog2(errInfo.sessionID, `thinking binding recovery armed from session.error (provider paths: failing=${bindingMismatch.failingBlockPath ?? "?"} firstChanged=${bindingMismatch.firstChangedPath ?? "?"})`);
|
|
9562
9587
|
dropSlot(errInfo.sessionID, "thinking-binding-recovery-arm");
|
|
9563
9588
|
deps.onSessionCacheInvalidated?.(errInfo.sessionID);
|
|
9564
9589
|
}
|
|
@@ -9584,7 +9609,7 @@ function createEventHandler2(deps) {
|
|
|
9584
9609
|
if (typeof detection.reportedLimit === "number" && detection.reportedLimit > 0) {
|
|
9585
9610
|
recordDetectedContextLimit(deps.db, errInfo.sessionID, detection.reportedLimit, overflowModelKey, detection.reportedLimitProvenance);
|
|
9586
9611
|
}
|
|
9587
|
-
|
|
9612
|
+
sessionLog2(errInfo.sessionID, `overflow detected on subagent: reportedLimit=${detection.reportedLimit ?? "unknown"} provenance=${detection.reportedLimitProvenance ?? "n/a"} pattern=${detection.matchedPattern ?? "n/a"} — recorded limit only (subagents cannot run historian)`);
|
|
9588
9613
|
return;
|
|
9589
9614
|
}
|
|
9590
9615
|
const existing = getOverflowState(deps.db, errInfo.sessionID);
|
|
@@ -9592,7 +9617,7 @@ function createEventHandler2(deps) {
|
|
|
9592
9617
|
if (typeof detection.reportedLimit === "number" && detection.reportedLimit > 0) {
|
|
9593
9618
|
recordDetectedContextLimit(deps.db, errInfo.sessionID, detection.reportedLimit, overflowModelKey, detection.reportedLimitProvenance);
|
|
9594
9619
|
}
|
|
9595
|
-
|
|
9620
|
+
sessionLog2(errInfo.sessionID, `overflow detected in compaction-off mode: reportedLimit=${detection.reportedLimit ?? "unknown"} provenance=${detection.reportedLimitProvenance ?? "n/a"} pattern=${detection.matchedPattern ?? "n/a"} — recorded limit only (recovery disarmed; native compaction owns the window)`);
|
|
9596
9621
|
return;
|
|
9597
9622
|
}
|
|
9598
9623
|
dropSlot(errInfo.sessionID, "overflow-recovery-arm");
|
|
@@ -9608,10 +9633,10 @@ function createEventHandler2(deps) {
|
|
|
9608
9633
|
updatedAt: Date.now()
|
|
9609
9634
|
});
|
|
9610
9635
|
}
|
|
9611
|
-
|
|
9636
|
+
sessionLog2(errInfo.sessionID, `overflow detected via session.error: reportedLimit=${detection.reportedLimit ?? "unknown"} provenance=${detection.reportedLimitProvenance ?? "n/a"} pattern=${detection.matchedPattern ?? "n/a"} (previousRecovery=${existing.needsEmergencyRecovery})`);
|
|
9612
9637
|
deps.onSessionCacheInvalidated?.(errInfo.sessionID);
|
|
9613
9638
|
} catch (error) {
|
|
9614
|
-
|
|
9639
|
+
sessionLog2(errInfo.sessionID, "event session.error handling failed:", error);
|
|
9615
9640
|
}
|
|
9616
9641
|
return;
|
|
9617
9642
|
}
|
|
@@ -9623,7 +9648,7 @@ function createEventHandler2(deps) {
|
|
|
9623
9648
|
const time = rawInfo && typeof rawInfo === "object" && "time" in rawInfo ? rawInfo.time?.created : undefined;
|
|
9624
9649
|
observeSessionActivity(deps.db, message.sessionID, typeof time === "number" ? time : Date.now());
|
|
9625
9650
|
} catch (error) {
|
|
9626
|
-
|
|
9651
|
+
sessionLog2(message.sessionID, "event message.updated activity persistence failed:", error);
|
|
9627
9652
|
}
|
|
9628
9653
|
}
|
|
9629
9654
|
const info = getMessageUpdatedAssistantInfo(input.event.properties);
|
|
@@ -9633,9 +9658,9 @@ function createEventHandler2(deps) {
|
|
|
9633
9658
|
return;
|
|
9634
9659
|
const sessionId = properties ? resolveSessionId(properties) : null;
|
|
9635
9660
|
if (sessionId) {
|
|
9636
|
-
|
|
9661
|
+
sessionLog2(sessionId, "event message.updated: no assistant info extracted from event");
|
|
9637
9662
|
} else {
|
|
9638
|
-
|
|
9663
|
+
log2("[magic-context] event message.updated: no assistant info extracted from event");
|
|
9639
9664
|
}
|
|
9640
9665
|
return;
|
|
9641
9666
|
}
|
|
@@ -9674,11 +9699,11 @@ function createEventHandler2(deps) {
|
|
|
9674
9699
|
if (bindingMismatch.isBindingMismatch && deps.thinkingBindingRecoveryEnabled !== false && !deps.compactionOff && isPrefixBoundThinkingModel(info.providerID, info.modelID)) {
|
|
9675
9700
|
try {
|
|
9676
9701
|
armBindingRecoverySafely(deps.db, info.sessionID);
|
|
9677
|
-
|
|
9702
|
+
sessionLog2(info.sessionID, `thinking binding recovery armed from message.updated (provider paths: failing=${bindingMismatch.failingBlockPath ?? "?"} firstChanged=${bindingMismatch.firstChangedPath ?? "?"})`);
|
|
9678
9703
|
dropSlot(info.sessionID, "thinking-binding-recovery-arm");
|
|
9679
9704
|
deps.onSessionCacheInvalidated?.(info.sessionID);
|
|
9680
9705
|
} catch (error) {
|
|
9681
|
-
|
|
9706
|
+
sessionLog2(info.sessionID, "event message.updated thinking binding recovery persistence failed:", error);
|
|
9682
9707
|
}
|
|
9683
9708
|
}
|
|
9684
9709
|
}
|
|
@@ -9704,12 +9729,12 @@ function createEventHandler2(deps) {
|
|
|
9704
9729
|
if (typeof detection.reportedLimit === "number" && detection.reportedLimit > 0) {
|
|
9705
9730
|
recordDetectedContextLimit(deps.db, info.sessionID, detection.reportedLimit, overflowModelKey, detection.reportedLimitProvenance);
|
|
9706
9731
|
}
|
|
9707
|
-
|
|
9732
|
+
sessionLog2(info.sessionID, `overflow detected on subagent via message.updated: reportedLimit=${detection.reportedLimit ?? "unknown"} provenance=${detection.reportedLimitProvenance ?? "n/a"} pattern=${detection.matchedPattern ?? "n/a"} — recorded limit only`);
|
|
9708
9733
|
} else if (deps.compactionOff) {
|
|
9709
9734
|
if (typeof detection.reportedLimit === "number" && detection.reportedLimit > 0) {
|
|
9710
9735
|
recordDetectedContextLimit(deps.db, info.sessionID, detection.reportedLimit, overflowModelKey, detection.reportedLimitProvenance);
|
|
9711
9736
|
}
|
|
9712
|
-
|
|
9737
|
+
sessionLog2(info.sessionID, `overflow detected in compaction-off mode via message.updated: reportedLimit=${detection.reportedLimit ?? "unknown"} provenance=${detection.reportedLimitProvenance ?? "n/a"} pattern=${detection.matchedPattern ?? "n/a"} — recorded limit only`);
|
|
9713
9738
|
} else {
|
|
9714
9739
|
dropSlot(info.sessionID, "overflow-recovery-arm");
|
|
9715
9740
|
recordOverflowDetected(deps.db, info.sessionID, detection.reportedLimit, overflowModelKey, "provider_overflow", detection.reportedLimitProvenance, detection.reportedInputTokens);
|
|
@@ -9724,11 +9749,11 @@ function createEventHandler2(deps) {
|
|
|
9724
9749
|
updatedAt: Date.now()
|
|
9725
9750
|
});
|
|
9726
9751
|
}
|
|
9727
|
-
|
|
9752
|
+
sessionLog2(info.sessionID, `overflow detected via message.updated: reportedLimit=${detection.reportedLimit ?? "unknown"} provenance=${detection.reportedLimitProvenance ?? "n/a"} pattern=${detection.matchedPattern ?? "n/a"}`);
|
|
9728
9753
|
deps.onSessionCacheInvalidated?.(info.sessionID);
|
|
9729
9754
|
}
|
|
9730
9755
|
} catch (error) {
|
|
9731
|
-
|
|
9756
|
+
sessionLog2(info.sessionID, "event message.updated overflow persistence failed:", error);
|
|
9732
9757
|
}
|
|
9733
9758
|
}
|
|
9734
9759
|
}
|
|
@@ -9758,7 +9783,7 @@ function createEventHandler2(deps) {
|
|
|
9758
9783
|
inputTokens: (info.tokens?.input ?? 0) + (info.tokens?.cache?.read ?? 0) + (info.tokens?.cache?.write ?? 0)
|
|
9759
9784
|
});
|
|
9760
9785
|
}
|
|
9761
|
-
|
|
9786
|
+
sessionLog2(info.sessionID, `event message.updated: provider=${info.providerID} model=${info.modelID} hasUsageTokens=${hasUsageTokens} tokens.input=${info.tokens?.input} cache.read=${info.tokens?.cache?.read} cache.write=${info.tokens?.cache?.write} message.id=${info.messageID} session.id=${info.sessionID}`);
|
|
9762
9787
|
const hasKnownUsage = hasUsageTokens || deps.contextUsageMap.has(info.sessionID);
|
|
9763
9788
|
if (successfulCompletion && !hasUsageTokens) {
|
|
9764
9789
|
try {
|
|
@@ -9770,11 +9795,11 @@ function createEventHandler2(deps) {
|
|
|
9770
9795
|
});
|
|
9771
9796
|
}
|
|
9772
9797
|
} catch (error) {
|
|
9773
|
-
|
|
9798
|
+
sessionLog2(info.sessionID, "event completion clock persistence failed:", error);
|
|
9774
9799
|
}
|
|
9775
9800
|
}
|
|
9776
9801
|
if (!hasKnownUsage) {
|
|
9777
|
-
|
|
9802
|
+
sessionLog2(info.sessionID, "event message.updated: skipping — no usage tokens and no known usage");
|
|
9778
9803
|
return;
|
|
9779
9804
|
}
|
|
9780
9805
|
try {
|
|
@@ -9797,7 +9822,7 @@ function createEventHandler2(deps) {
|
|
|
9797
9822
|
if (hasUsageTokens && aboveTrustedWall) {
|
|
9798
9823
|
if (!usageAboveWallLogSeen.has(aboveWallLogKey)) {
|
|
9799
9824
|
usageAboveWallLogSeen.add(aboveWallLogKey);
|
|
9800
|
-
|
|
9825
|
+
sessionLog2(info.sessionID, `provider usage ${totalInputTokens} exceeds configured window ${trustedAbsoluteWall}; counted as real pressure against the configured limit`);
|
|
9801
9826
|
}
|
|
9802
9827
|
} else {
|
|
9803
9828
|
usageAboveWallLogSeen.delete(aboveWallLogKey);
|
|
@@ -9812,7 +9837,7 @@ function createEventHandler2(deps) {
|
|
|
9812
9837
|
const detectedLimitMatchesModel = rawOverflow.detectedContextLimitModelKey === null || modelKey !== undefined && rawOverflow.detectedContextLimitModelKey === modelKey;
|
|
9813
9838
|
if (rawOverflow.detectedContextLimit > 0 && detectedLimitMatchesModel && pressureInputTokens > rawOverflow.detectedContextLimit) {
|
|
9814
9839
|
clearDetectedContextLimit(deps.db, info.sessionID);
|
|
9815
|
-
|
|
9840
|
+
sessionLog2(info.sessionID, `detected limit ${rawOverflow.detectedContextLimit} invalidated by a successful ${pressureInputTokens}-token request; using catalog/default`);
|
|
9816
9841
|
deps.onSessionCacheInvalidated?.(info.sessionID);
|
|
9817
9842
|
}
|
|
9818
9843
|
}
|
|
@@ -9837,7 +9862,7 @@ function createEventHandler2(deps) {
|
|
|
9837
9862
|
};
|
|
9838
9863
|
const newestMessageId = newestUsageMessageIdBySession.get(info.sessionID);
|
|
9839
9864
|
if (info.messageID !== undefined && newestMessageId !== undefined && info.messageID < newestMessageId) {
|
|
9840
|
-
|
|
9865
|
+
sessionLog2(info.sessionID, `event message.updated: usage ${pressureInputTokens} from ${info.messageID} arrived after newer message ${newestMessageId}; keeping the newer reading`);
|
|
9841
9866
|
return;
|
|
9842
9867
|
}
|
|
9843
9868
|
if (info.messageID !== undefined) {
|
|
@@ -9851,7 +9876,7 @@ function createEventHandler2(deps) {
|
|
|
9851
9876
|
detected: getOverflowState(deps.db, info.sessionID, modelKey).detectedContextLimit,
|
|
9852
9877
|
provenFloor: successfulUsageProof ? provenSafeInputTokens : observedSafeInputTokens
|
|
9853
9878
|
});
|
|
9854
|
-
|
|
9879
|
+
sessionLog2(info.sessionID, `event message.updated: totalInputTokens=${pressureInputTokens} contextLimit=${pressure.contextLimit} percentage=${pressure.percentage.toFixed(1)}%`);
|
|
9855
9880
|
const entry = {
|
|
9856
9881
|
usage: {
|
|
9857
9882
|
percentage: pressure.percentage,
|
|
@@ -9865,7 +9890,7 @@ function createEventHandler2(deps) {
|
|
|
9865
9890
|
const historianFailureState = getHistorianFailureState(deps.db, info.sessionID);
|
|
9866
9891
|
if (historianFailureState.failureCount > 0 && pressure.percentage < 90) {
|
|
9867
9892
|
clearHistorianFailureState(deps.db, info.sessionID);
|
|
9868
|
-
|
|
9893
|
+
sessionLog2(info.sessionID, `event message.updated: cleared historian failure state at ${pressure.percentage.toFixed(1)}%`);
|
|
9869
9894
|
}
|
|
9870
9895
|
return entry;
|
|
9871
9896
|
};
|
|
@@ -9887,7 +9912,7 @@ function createEventHandler2(deps) {
|
|
|
9887
9912
|
await refreshModelLimitsFromApi(deps.client);
|
|
9888
9913
|
catalogLimit = readCatalogLimit();
|
|
9889
9914
|
if (catalogLimit !== undefined && catalogLimit >= provenSafeInputTokens) {
|
|
9890
|
-
|
|
9915
|
+
sessionLog2(info.sessionID, `models-dev-cache: regression recovered for ${info.providerID}/${info.modelID} via refresh (was=${oldLimit}, now=${catalogLimit})`);
|
|
9891
9916
|
}
|
|
9892
9917
|
}
|
|
9893
9918
|
const refreshedUpdates = {};
|
|
@@ -9916,7 +9941,7 @@ function createEventHandler2(deps) {
|
|
|
9916
9941
|
await refreshLimitsAfterRecording();
|
|
9917
9942
|
}
|
|
9918
9943
|
} catch (error) {
|
|
9919
|
-
|
|
9944
|
+
sessionLog2(info.sessionID, "event message.updated persistence failed:", error);
|
|
9920
9945
|
}
|
|
9921
9946
|
if ((info.finish === "stop" || info.finish === "tool-calls") && deps.client && deps.channel1StateBySession && !deps.compactionOff) {
|
|
9922
9947
|
deliverChannel2IfPending(deps, info.sessionID);
|
|
@@ -9928,24 +9953,25 @@ function createEventHandler2(deps) {
|
|
|
9928
9953
|
if (!info) {
|
|
9929
9954
|
const sessionId = properties ? resolveSessionId(properties) : null;
|
|
9930
9955
|
if (sessionId) {
|
|
9931
|
-
|
|
9956
|
+
sessionLog2(sessionId, "event message.removed: no message removal info extracted from event");
|
|
9932
9957
|
} else {
|
|
9933
|
-
|
|
9958
|
+
log2("[magic-context] event message.removed: no message removal info extracted from event");
|
|
9934
9959
|
}
|
|
9935
9960
|
return;
|
|
9936
9961
|
}
|
|
9937
9962
|
dropSlot(info.sessionID, "message.removed");
|
|
9963
|
+
forgetRawSessionOrdinalWatermark2(info.sessionID);
|
|
9938
9964
|
deps.onRustWireInvalidated?.(info.sessionID);
|
|
9939
|
-
|
|
9965
|
+
sessionLog2(info.sessionID, `event message.removed: invalidating state for message ${info.messageID}`);
|
|
9940
9966
|
try {
|
|
9941
9967
|
cleanupRemovedMessageState(deps, info.sessionID, info.messageID);
|
|
9942
9968
|
scheduleClearAndReindex(deps.db, info.sessionID, readRawSessionMessages2);
|
|
9943
9969
|
deps.tagger.cleanup(info.sessionID);
|
|
9944
|
-
|
|
9970
|
+
sessionLog2(info.sessionID, "event message.removed: invalidated tagger session cache");
|
|
9945
9971
|
const markerState = getPersistedCompactionMarkerState(deps.db, info.sessionID);
|
|
9946
9972
|
if (markerState && (markerState.boundaryMessageId === info.messageID || markerState.summaryMessageId === info.messageID)) {
|
|
9947
9973
|
removeCompactionMarkerForSession(deps.db, info.sessionID);
|
|
9948
|
-
|
|
9974
|
+
sessionLog2(info.sessionID, `event message.removed: cleared compaction marker (boundary or summary message removed)`);
|
|
9949
9975
|
}
|
|
9950
9976
|
clearMessageTokensCache(info.sessionID, info.messageID);
|
|
9951
9977
|
invalidateTrueRawTokenCache({
|
|
@@ -9954,9 +9980,9 @@ function createEventHandler2(deps) {
|
|
|
9954
9980
|
reason: "message.removed"
|
|
9955
9981
|
});
|
|
9956
9982
|
deps.onSessionCacheInvalidated?.(info.sessionID);
|
|
9957
|
-
|
|
9983
|
+
sessionLog2(info.sessionID, "event message.removed: cleared session injection cache");
|
|
9958
9984
|
} catch (error) {
|
|
9959
|
-
|
|
9985
|
+
sessionLog2(info.sessionID, "event message.removed cleanup failed:", error);
|
|
9960
9986
|
}
|
|
9961
9987
|
return;
|
|
9962
9988
|
}
|
|
@@ -9969,12 +9995,12 @@ function createEventHandler2(deps) {
|
|
|
9969
9995
|
try {
|
|
9970
9996
|
deps.compactionHandler.onCompacted(sessionId, deps.db);
|
|
9971
9997
|
} catch (error) {
|
|
9972
|
-
|
|
9998
|
+
sessionLog2(sessionId, "event session.compacted handling failed:", error);
|
|
9973
9999
|
}
|
|
9974
10000
|
try {
|
|
9975
10001
|
removeCompactionMarkerForSession(deps.db, sessionId);
|
|
9976
10002
|
} catch (error) {
|
|
9977
|
-
|
|
10003
|
+
sessionLog2(sessionId, "event session.compacted marker cleanup failed:", error);
|
|
9978
10004
|
}
|
|
9979
10005
|
try {
|
|
9980
10006
|
const pending = getPendingCompactionMarkerState(deps.db, sessionId);
|
|
@@ -9982,7 +10008,7 @@ function createEventHandler2(deps) {
|
|
|
9982
10008
|
clearPendingCompactionMarkerStateIf(deps.db, sessionId, pending);
|
|
9983
10009
|
}
|
|
9984
10010
|
} catch (error) {
|
|
9985
|
-
|
|
10011
|
+
sessionLog2(sessionId, "event session.compacted pending-marker cleanup failed:", error);
|
|
9986
10012
|
}
|
|
9987
10013
|
resetDegradedCacheCount2(sessionId);
|
|
9988
10014
|
clearMessageTokensCache(sessionId);
|
|
@@ -10005,7 +10031,7 @@ function createEventHandler2(deps) {
|
|
|
10005
10031
|
clearSession(deps.db, sessionId, deps.rustSessionCleanup === true);
|
|
10006
10032
|
}
|
|
10007
10033
|
} catch (error) {
|
|
10008
|
-
|
|
10034
|
+
sessionLog2(sessionId, "event session.deleted persistence failed:", error);
|
|
10009
10035
|
}
|
|
10010
10036
|
resetDegradedCacheCount2(sessionId);
|
|
10011
10037
|
deps.onSessionCacheInvalidated?.(sessionId);
|
|
@@ -10074,7 +10100,7 @@ function notifyMagicContextDisabled(client, reason) {
|
|
|
10074
10100
|
duration: 8000
|
|
10075
10101
|
}
|
|
10076
10102
|
}).catch((error) => {
|
|
10077
|
-
|
|
10103
|
+
log2("[magic-context] failed to show disabled toast:", error);
|
|
10078
10104
|
});
|
|
10079
10105
|
}
|
|
10080
10106
|
function createMagicContextHook(deps) {
|
|
@@ -10086,7 +10112,7 @@ function createMagicContextHook(deps) {
|
|
|
10086
10112
|
if (!opened || !isDatabasePersisted(opened)) {
|
|
10087
10113
|
const reason = describeStorageUnavailability((opened ? getDatabasePersistenceError(opened) : null) ?? "Failed to initialize the persistent SQLite database.");
|
|
10088
10114
|
const detail = formatFailClosedBlockingMessage(reason);
|
|
10089
|
-
|
|
10115
|
+
log2("[magic-context] disabling feature because persistent storage is unavailable:", detail);
|
|
10090
10116
|
notifyMagicContextDisabled(deps.client, detail);
|
|
10091
10117
|
recordHookInitFailure({ type: "storage", reason });
|
|
10092
10118
|
return null;
|
|
@@ -10094,7 +10120,7 @@ function createMagicContextHook(deps) {
|
|
|
10094
10120
|
db = opened;
|
|
10095
10121
|
} catch (error) {
|
|
10096
10122
|
const reason = getErrorMessage(error);
|
|
10097
|
-
|
|
10123
|
+
log2("[magic-context] hook failed to open storage; disabling feature:", error);
|
|
10098
10124
|
notifyMagicContextDisabled(deps.client, reason);
|
|
10099
10125
|
clearHookInitFailure();
|
|
10100
10126
|
recordHookInitFailure({
|
|
@@ -10105,7 +10131,7 @@ function createMagicContextHook(deps) {
|
|
|
10105
10131
|
}
|
|
10106
10132
|
const projectPath = resolveProjectIdentityForSession(deps.directory, deps.config.allow_home_project);
|
|
10107
10133
|
if (!projectPath) {
|
|
10108
|
-
|
|
10134
|
+
log2("[magic-context] not binding a project identity for this directory");
|
|
10109
10135
|
clearHookInitFailure();
|
|
10110
10136
|
recordHookInitFailure({ type: "no_project" });
|
|
10111
10137
|
return null;
|
|
@@ -10113,7 +10139,7 @@ function createMagicContextHook(deps) {
|
|
|
10113
10139
|
try {
|
|
10114
10140
|
checkCompactionMarkerConsistency(db);
|
|
10115
10141
|
} catch (error) {
|
|
10116
|
-
|
|
10142
|
+
log2("[magic-context] startup compaction-marker consistency check failed:", error);
|
|
10117
10143
|
}
|
|
10118
10144
|
let lastScheduleCheckMs = 0;
|
|
10119
10145
|
let dreamQueueQuietScheduled = false;
|
|
@@ -10149,10 +10175,10 @@ function createMagicContextHook(deps) {
|
|
|
10149
10175
|
deferredHistoryRefreshSessions.add(sid);
|
|
10150
10176
|
deferredMaterializationSessions.add(sid);
|
|
10151
10177
|
}
|
|
10152
|
-
|
|
10178
|
+
log2(`[magic-context] rehydrated ${sessionsWithPending.length} session(s) with pending compaction-marker drain at hook init`);
|
|
10153
10179
|
}
|
|
10154
10180
|
} catch (error) {
|
|
10155
|
-
|
|
10181
|
+
log2("[magic-context] hook init: pending-marker rehydration failed:", error);
|
|
10156
10182
|
}
|
|
10157
10183
|
const lastHeuristicsTurnId = new Map;
|
|
10158
10184
|
const commitSeenLastPass = new Map;
|
|
@@ -10184,7 +10210,7 @@ function createMagicContextHook(deps) {
|
|
|
10184
10210
|
return;
|
|
10185
10211
|
const notificationParams = getLiveNotificationParams(sessionId, liveModelBySession, variantBySession, agentBySession, (deps.sampleDreamConfig?.() ?? deps.config).toast_duration_ms);
|
|
10186
10212
|
sendStatusNotification2(deps.client, sessionId, warning, notificationParams).catch((error) => {
|
|
10187
|
-
|
|
10213
|
+
log2(`[magic-context] failed to send project identity warning for ${directory}: ${getErrorMessage(error)}`);
|
|
10188
10214
|
});
|
|
10189
10215
|
};
|
|
10190
10216
|
const dreamerRunnable = isDreamerRunnable(deps.config);
|
|
@@ -10265,7 +10291,7 @@ function createMagicContextHook(deps) {
|
|
|
10265
10291
|
if (!sessionProjectIdentity)
|
|
10266
10292
|
return "No project identity is bound for the home directory.";
|
|
10267
10293
|
maybeSendProjectIdentitySessionWarning(sessionId, directory);
|
|
10268
|
-
const coverage =
|
|
10294
|
+
const coverage = getEmbeddingCoverageStatus2(db, sessionProjectIdentity, sessionId);
|
|
10269
10295
|
const progress = recompProgressBySession.get(sessionId);
|
|
10270
10296
|
const drainUi = getEmbedDrainUiStatus(sessionId, progress);
|
|
10271
10297
|
return formatEmbedStatusText(coverage, {
|
|
@@ -10275,11 +10301,11 @@ function createMagicContextHook(deps) {
|
|
|
10275
10301
|
});
|
|
10276
10302
|
};
|
|
10277
10303
|
const maybeAutoEmbedSession = (sessionId) => {
|
|
10278
|
-
if (
|
|
10304
|
+
if (isEmbeddingHostBusy2())
|
|
10279
10305
|
return;
|
|
10280
10306
|
const directory = sessionDirectoryBySession.get(sessionId) ?? deps.directory;
|
|
10281
10307
|
const identity = resolveProjectIdentityForSession(directory, deps.config.allow_home_project);
|
|
10282
|
-
const snapshot = identity ?
|
|
10308
|
+
const snapshot = identity ? getProjectEmbeddingSnapshot2(identity) : undefined;
|
|
10283
10309
|
const embedIdentity = snapshot ? JSON.stringify([
|
|
10284
10310
|
snapshot.providerIdentity,
|
|
10285
10311
|
snapshot.chunkModelId,
|
|
@@ -10297,7 +10323,7 @@ function createMagicContextHook(deps) {
|
|
|
10297
10323
|
(async () => {
|
|
10298
10324
|
try {
|
|
10299
10325
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
10300
|
-
if (
|
|
10326
|
+
if (isEmbeddingHostBusy2()) {
|
|
10301
10327
|
invalidateAutoEmbedSession(sessionId);
|
|
10302
10328
|
return;
|
|
10303
10329
|
}
|
|
@@ -10308,7 +10334,7 @@ function createMagicContextHook(deps) {
|
|
|
10308
10334
|
return;
|
|
10309
10335
|
}
|
|
10310
10336
|
maybeSendProjectIdentitySessionWarning(sessionId, directory);
|
|
10311
|
-
const coverage = await
|
|
10337
|
+
const coverage = await getAutoEmbeddingSessionCoverage2(db, sessionProjectIdentity, sessionId);
|
|
10312
10338
|
if (!coverage.enabled) {
|
|
10313
10339
|
invalidateAutoEmbedSession(sessionId);
|
|
10314
10340
|
return;
|
|
@@ -10318,7 +10344,7 @@ function createMagicContextHook(deps) {
|
|
|
10318
10344
|
return;
|
|
10319
10345
|
await executeEmbedHistory(sessionId, { silent: true });
|
|
10320
10346
|
} catch (error) {
|
|
10321
|
-
|
|
10347
|
+
log2("[magic-context] auto-embed drain failed:", error);
|
|
10322
10348
|
}
|
|
10323
10349
|
})();
|
|
10324
10350
|
};
|
|
@@ -10347,7 +10373,7 @@ function createMagicContextHook(deps) {
|
|
|
10347
10373
|
variant: "warning",
|
|
10348
10374
|
duration: 8000
|
|
10349
10375
|
}
|
|
10350
|
-
}).catch((error) =>
|
|
10376
|
+
}).catch((error) => log2(`[magic-context] rust park toast failed for ${sessionId}:`, error));
|
|
10351
10377
|
};
|
|
10352
10378
|
registerLkgPersistence(createDbLkgPersistence(db));
|
|
10353
10379
|
const transform = createTransform({
|
|
@@ -10513,7 +10539,7 @@ function createMagicContextHook(deps) {
|
|
|
10513
10539
|
return;
|
|
10514
10540
|
}
|
|
10515
10541
|
lastScheduleCheckMs = now;
|
|
10516
|
-
const runtimeConfigs = buildDreamTaskRuntimeConfigs2(dreaming, "opencode", deps.config.language,
|
|
10542
|
+
const runtimeConfigs = buildDreamTaskRuntimeConfigs2(dreaming, "opencode", deps.config.language, deps.config.smart_notes?.enabled);
|
|
10517
10543
|
const executor = createDreamTaskExecutor({
|
|
10518
10544
|
client: deps.client,
|
|
10519
10545
|
sessionDirectory: deps.directory,
|
|
@@ -10525,6 +10551,7 @@ function createMagicContextHook(deps) {
|
|
|
10525
10551
|
userMemoryCollectionEnabled: userMemoryCollectionEnabled2(dreaming),
|
|
10526
10552
|
language: deps.config.language,
|
|
10527
10553
|
retinaHandoff: deps.config.smart_notes?.retina_handoff === true,
|
|
10554
|
+
smartNotesEnabled: deps.config.smart_notes?.enabled,
|
|
10528
10555
|
transformMode: deps.config.transform_mode,
|
|
10529
10556
|
moduleClient: rustModeModuleClient,
|
|
10530
10557
|
onProgress: (progress, completedTask) => {
|
|
@@ -10542,10 +10569,11 @@ function createMagicContextHook(deps) {
|
|
|
10542
10569
|
executor,
|
|
10543
10570
|
projectMemoryEnabled: deps.config.memory?.enabled !== false
|
|
10544
10571
|
}).catch((error) => {
|
|
10545
|
-
|
|
10572
|
+
log2("[dreamer] scheduled task run failed:", error);
|
|
10546
10573
|
});
|
|
10547
10574
|
};
|
|
10548
10575
|
const commandHandler = createMagicContextCommandHandler({
|
|
10576
|
+
smartNotesEnabled: deps.config.smart_notes?.enabled,
|
|
10549
10577
|
db,
|
|
10550
10578
|
compactionOff,
|
|
10551
10579
|
toastDurationMs: deps.config.toast_duration_ms,
|
|
@@ -10602,7 +10630,7 @@ function createMagicContextHook(deps) {
|
|
|
10602
10630
|
return runManualDream({
|
|
10603
10631
|
db,
|
|
10604
10632
|
projectIdentity: projectPath,
|
|
10605
|
-
tasks: buildDreamTaskRuntimeConfigs2(currentDreamer, "opencode", deps.config.language,
|
|
10633
|
+
tasks: buildDreamTaskRuntimeConfigs2(currentDreamer, "opencode", deps.config.language, deps.config.smart_notes?.enabled),
|
|
10606
10634
|
executor: createDreamTaskExecutor({
|
|
10607
10635
|
client: deps.client,
|
|
10608
10636
|
sessionDirectory: deps.directory,
|
|
@@ -10616,6 +10644,7 @@ function createMagicContextHook(deps) {
|
|
|
10616
10644
|
mural: sampledDream.mural,
|
|
10617
10645
|
memoryInjectionBudgetTokens: deps.config.memory?.injection_budget_tokens,
|
|
10618
10646
|
retinaHandoff: deps.config.smart_notes?.retina_handoff === true,
|
|
10647
|
+
smartNotesEnabled: deps.config.smart_notes?.enabled,
|
|
10619
10648
|
transformMode: deps.config.transform_mode,
|
|
10620
10649
|
moduleClient: rustModeModuleClient,
|
|
10621
10650
|
onProgress: (progress, completedTask) => {
|
|
@@ -10634,6 +10663,7 @@ function createMagicContextHook(deps) {
|
|
|
10634
10663
|
const systemPromptHash = createSystemPromptHashHandler({
|
|
10635
10664
|
db,
|
|
10636
10665
|
dreamerEnabled: dreamerRunnable,
|
|
10666
|
+
smartNotesEnabled: deps.config.smart_notes?.enabled,
|
|
10637
10667
|
memoryEnabled: deps.config.memory?.enabled !== false,
|
|
10638
10668
|
language: deps.config.language,
|
|
10639
10669
|
promptSurface: deps.config.prompt_surface,
|
|
@@ -10759,7 +10789,7 @@ async function createMagicContextHookAsync(deps) {
|
|
|
10759
10789
|
database = await openDatabaseAsync({ onBootTimings: deps.onStorageBootTimings });
|
|
10760
10790
|
} catch (error) {
|
|
10761
10791
|
const reason = getErrorMessage(error);
|
|
10762
|
-
|
|
10792
|
+
log2("[magic-context] hook failed to open storage; disabling feature:", error);
|
|
10763
10793
|
notifyMagicContextDisabled(deps.client, reason);
|
|
10764
10794
|
clearHookInitFailure();
|
|
10765
10795
|
recordHookInitFailure({
|
|
@@ -10816,18 +10846,25 @@ async function createSessionHooksAsync(args) {
|
|
|
10816
10846
|
};
|
|
10817
10847
|
}
|
|
10818
10848
|
|
|
10819
|
-
// src/
|
|
10820
|
-
import
|
|
10849
|
+
// src/shared/host-stall-profiler.ts
|
|
10850
|
+
import * as path7 from "node:path";
|
|
10851
|
+
|
|
10852
|
+
// src/shared/host-stall-profiler-bun.ts
|
|
10853
|
+
import { existsSync as existsSync6, readFileSync as readFileSync5 } from "node:fs";
|
|
10854
|
+
import * as path5 from "node:path";
|
|
10855
|
+
|
|
10856
|
+
// src/shared/host-stall-profiler-common.ts
|
|
10857
|
+
import { chmodSync, existsSync as existsSync5, readdirSync, unlinkSync } from "node:fs";
|
|
10821
10858
|
import * as path4 from "node:path";
|
|
10822
10859
|
|
|
10823
|
-
// src/
|
|
10860
|
+
// src/shared/host-stall-profiler-report.ts
|
|
10824
10861
|
import { readFileSync as readFileSync4 } from "node:fs";
|
|
10825
10862
|
import * as path3 from "node:path";
|
|
10826
10863
|
var MAX_STACK_DEPTH = 64;
|
|
10827
10864
|
var TOP_STACK_COUNT = 30;
|
|
10828
10865
|
var TOP_FRAME_COUNT = 30;
|
|
10829
10866
|
var UNKNOWN_POSITION = 4294967295;
|
|
10830
|
-
var BACKGROUND_OWNERS = new Set(["native", "runtime", "opencode"]);
|
|
10867
|
+
var BACKGROUND_OWNERS = new Set(["native", "runtime", "opencode", "pi", "omp"]);
|
|
10831
10868
|
var packageNameCache = new Map;
|
|
10832
10869
|
function urlToPath(url) {
|
|
10833
10870
|
if (url.startsWith("file://")) {
|
|
@@ -10878,8 +10915,21 @@ function sourceOwner(sourceURL) {
|
|
|
10878
10915
|
const filePath = urlToPath(sourceURL).replaceAll("\\", "/");
|
|
10879
10916
|
const modules = [...filePath.matchAll(/\/node_modules\/((?:@[^/]+\/)?[^/]+)/g)];
|
|
10880
10917
|
const innermost = modules.at(-1);
|
|
10881
|
-
if (innermost)
|
|
10882
|
-
|
|
10918
|
+
if (innermost) {
|
|
10919
|
+
const name = innermost[1];
|
|
10920
|
+
if (name === "@cortexkit/pi-magic-context")
|
|
10921
|
+
return `pkg:${name}`;
|
|
10922
|
+
if (/^@(?:earendil-works|mariozechner)\/pi-(?:coding-agent|agent-core|ai|tui)$/.test(name))
|
|
10923
|
+
return "pi";
|
|
10924
|
+
if (/^@oh-my-pi\/pi-(?:coding-agent|agent-core|ai|tui)$/.test(name))
|
|
10925
|
+
return "omp";
|
|
10926
|
+
return `npm:${name}`;
|
|
10927
|
+
}
|
|
10928
|
+
const extension = filePath.match(/\/(?:\.pi|\.omp)\/agent\/extensions\/([^/]+)/);
|
|
10929
|
+
if (extension) {
|
|
10930
|
+
const name = nearestPackageName(filePath);
|
|
10931
|
+
return name ? `pkg:${name}` : `extension:${extension[1]}`;
|
|
10932
|
+
}
|
|
10883
10933
|
const pluginDir = filePath.match(/\/plugins?\/([^/]+)$/);
|
|
10884
10934
|
if (pluginDir && /\/(?:\.?opencode)\/plugins?\//.test(filePath)) {
|
|
10885
10935
|
return `plugin:${pluginDir[1]}`;
|
|
@@ -10971,39 +11021,33 @@ function aggregateTraces(traces) {
|
|
|
10971
11021
|
};
|
|
10972
11022
|
}
|
|
10973
11023
|
|
|
10974
|
-
// src/
|
|
11024
|
+
// src/shared/host-stall-profiler-common.ts
|
|
10975
11025
|
var HOST_PROFILER_DIRNAME = "host-profiler";
|
|
10976
11026
|
var HOST_PROFILER_ENABLE_FILENAME = "enable";
|
|
10977
|
-
var SWITCH_POLL_MS =
|
|
11027
|
+
var SWITCH_POLL_MS = 5000;
|
|
10978
11028
|
var WATCHDOG_INTERVAL_MS = 250;
|
|
10979
11029
|
var DEFAULT_STALL_THRESHOLD_MS = 3000;
|
|
10980
11030
|
var DEFAULT_SAMPLE_INTERVAL_MS = 10;
|
|
10981
11031
|
var MAX_REPORT_FILES = 50;
|
|
10982
11032
|
var MAX_SAMPLES_PER_WINDOW = 20000;
|
|
10983
|
-
var
|
|
10984
|
-
var CALIBRATION_CHUNK_MS = 3;
|
|
10985
|
-
var CALIBRATION_MAX_CHUNKS = 30;
|
|
10986
|
-
function clamp(value, min, max) {
|
|
10987
|
-
return Math.min(max, Math.max(min, value));
|
|
10988
|
-
}
|
|
11033
|
+
var PROFILE_WINDOW_MS = 1e4;
|
|
10989
11034
|
function parseEnableFile(content) {
|
|
10990
11035
|
const options = {
|
|
10991
11036
|
thresholdMs: DEFAULT_STALL_THRESHOLD_MS,
|
|
10992
11037
|
sampleIntervalMs: DEFAULT_SAMPLE_INTERVAL_MS
|
|
10993
11038
|
};
|
|
10994
|
-
|
|
10995
|
-
if (trimmed === "")
|
|
11039
|
+
if (!content.trim())
|
|
10996
11040
|
return { options, error: null };
|
|
10997
11041
|
try {
|
|
10998
|
-
const parsed = JSON.parse(
|
|
11042
|
+
const parsed = JSON.parse(content);
|
|
10999
11043
|
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
11000
11044
|
return { options, error: "enable file is not a JSON object" };
|
|
11001
11045
|
}
|
|
11002
11046
|
if (typeof parsed.threshold_ms === "number" && Number.isFinite(parsed.threshold_ms)) {
|
|
11003
|
-
options.thresholdMs =
|
|
11047
|
+
options.thresholdMs = Math.min(600000, Math.max(500, parsed.threshold_ms));
|
|
11004
11048
|
}
|
|
11005
11049
|
if (typeof parsed.sample_interval_ms === "number" && Number.isFinite(parsed.sample_interval_ms)) {
|
|
11006
|
-
options.sampleIntervalMs =
|
|
11050
|
+
options.sampleIntervalMs = Math.min(100, Math.max(1, parsed.sample_interval_ms));
|
|
11007
11051
|
}
|
|
11008
11052
|
return { options, error: null };
|
|
11009
11053
|
} catch (error) {
|
|
@@ -11013,6 +11057,66 @@ function parseEnableFile(content) {
|
|
|
11013
11057
|
};
|
|
11014
11058
|
}
|
|
11015
11059
|
}
|
|
11060
|
+
function emitStallReport(deps, input) {
|
|
11061
|
+
const { traces, windowed, options, startMs, endMs } = input;
|
|
11062
|
+
const stride = windowed.length / MAX_SAMPLES_PER_WINDOW;
|
|
11063
|
+
const kept = windowed.length <= MAX_SAMPLES_PER_WINDOW ? windowed : Array.from({ length: MAX_SAMPLES_PER_WINDOW }, (_, i) => windowed[Math.floor(i * stride)]);
|
|
11064
|
+
const aggregate = aggregateTraces(kept);
|
|
11065
|
+
const gapMs = endMs - startMs;
|
|
11066
|
+
const endWallMs = deps.wallNow();
|
|
11067
|
+
const report = {
|
|
11068
|
+
kind: "magic-context-host-stall",
|
|
11069
|
+
schema_version: 1,
|
|
11070
|
+
pid: deps.pid,
|
|
11071
|
+
bun_version: deps.bunVersion,
|
|
11072
|
+
node_version: input.backend === "v8" ? process.versions.node : undefined,
|
|
11073
|
+
backend: input.backend,
|
|
11074
|
+
platform: process.platform,
|
|
11075
|
+
window: {
|
|
11076
|
+
start: new Date(endWallMs - gapMs).toISOString(),
|
|
11077
|
+
end: new Date(endWallMs).toISOString(),
|
|
11078
|
+
duration_ms: Math.round(gapMs),
|
|
11079
|
+
lag_ms: Math.round(gapMs - WATCHDOG_INTERVAL_MS),
|
|
11080
|
+
threshold_ms: options.thresholdMs
|
|
11081
|
+
},
|
|
11082
|
+
sampling: {
|
|
11083
|
+
interval_ms: options.sampleIntervalMs,
|
|
11084
|
+
samples_collected: traces.length,
|
|
11085
|
+
samples_in_window: windowed.length,
|
|
11086
|
+
samples_aggregated: kept.length,
|
|
11087
|
+
window_filter: input.windowFilter,
|
|
11088
|
+
note: aggregate.samples === 0 ? "No JavaScript samples in the window: the main thread was not executing inside the JavaScript VM (idle wait, process suspension, or native work outside any JS call)." : undefined
|
|
11089
|
+
},
|
|
11090
|
+
memory: { before: input.before, after: input.after },
|
|
11091
|
+
owners: aggregate.owners,
|
|
11092
|
+
top_frames: aggregate.top_frames,
|
|
11093
|
+
top_js_frames: aggregate.top_js_frames,
|
|
11094
|
+
top_stacks: aggregate.top_stacks
|
|
11095
|
+
};
|
|
11096
|
+
const dir = deps.profilerDir();
|
|
11097
|
+
ensureStorageDirectorySync(dir, true);
|
|
11098
|
+
chmodSync(dir, 448);
|
|
11099
|
+
const stamp = new Date(endWallMs).toISOString().replaceAll(":", "-");
|
|
11100
|
+
let name = `stall-${stamp}.json`;
|
|
11101
|
+
for (let n = 1;existsSync5(path4.join(dir, name)); n++)
|
|
11102
|
+
name = `stall-${stamp}-${n}.json`;
|
|
11103
|
+
const file = path4.join(dir, name);
|
|
11104
|
+
writeStorageFileAtomicSync(file, `${JSON.stringify(report, null, 2)}
|
|
11105
|
+
`, true);
|
|
11106
|
+
const reports = readdirSync(dir).filter((entry) => /^stall-.*\.json$/.test(entry)).sort();
|
|
11107
|
+
for (const stale of reports.slice(0, Math.max(0, reports.length - MAX_REPORT_FILES))) {
|
|
11108
|
+
try {
|
|
11109
|
+
unlinkSync(path4.join(dir, stale));
|
|
11110
|
+
} catch {}
|
|
11111
|
+
}
|
|
11112
|
+
const top = aggregate.owners[0];
|
|
11113
|
+
deps.log(`[magic-context] host stall profiler: ${Math.round(gapMs)}ms main-thread stall, ${aggregate.samples} samples, top owner ${top ? `${top.owner} (${top.percent}%)` : "none"} → ${file}`);
|
|
11114
|
+
}
|
|
11115
|
+
|
|
11116
|
+
// src/shared/host-stall-profiler-bun.ts
|
|
11117
|
+
var MEMORY_SNAPSHOT_EVERY_TICKS = 4;
|
|
11118
|
+
var CALIBRATION_CHUNK_MS = 3;
|
|
11119
|
+
var CALIBRATION_MAX_CHUNKS = 30;
|
|
11016
11120
|
function asJscApi(module) {
|
|
11017
11121
|
const candidate = module ?? null;
|
|
11018
11122
|
for (const value of [candidate, candidate?.default]) {
|
|
@@ -11023,18 +11127,6 @@ function asJscApi(module) {
|
|
|
11023
11127
|
}
|
|
11024
11128
|
return null;
|
|
11025
11129
|
}
|
|
11026
|
-
function thin(items, limit) {
|
|
11027
|
-
if (items.length <= limit)
|
|
11028
|
-
return items;
|
|
11029
|
-
const stride = items.length / limit;
|
|
11030
|
-
const out = [];
|
|
11031
|
-
for (let i = 0;i < limit; i++)
|
|
11032
|
-
out.push(items[Math.floor(i * stride)]);
|
|
11033
|
-
return out;
|
|
11034
|
-
}
|
|
11035
|
-
function reportFileStamp(epochMs) {
|
|
11036
|
-
return new Date(epochMs).toISOString().replaceAll(":", "-");
|
|
11037
|
-
}
|
|
11038
11130
|
function createHostStallProfiler(deps) {
|
|
11039
11131
|
let jsc = null;
|
|
11040
11132
|
let unavailable = false;
|
|
@@ -11109,30 +11201,8 @@ function createHostStallProfiler(deps) {
|
|
|
11109
11201
|
percent_available_memory_in_use: read(() => api.percentAvailableMemoryInUse?.() ?? null)
|
|
11110
11202
|
};
|
|
11111
11203
|
};
|
|
11112
|
-
const writeReport = (report, endWallMs) => {
|
|
11113
|
-
const dir = deps.profilerDir();
|
|
11114
|
-
ensureStorageDirectorySync(dir, true);
|
|
11115
|
-
chmodSync(dir, 448);
|
|
11116
|
-
const stamp = reportFileStamp(endWallMs);
|
|
11117
|
-
let name = `stall-${stamp}.json`;
|
|
11118
|
-
for (let n = 1;existsSync5(path4.join(dir, name)); n++)
|
|
11119
|
-
name = `stall-${stamp}-${n}.json`;
|
|
11120
|
-
const finalPath = path4.join(dir, name);
|
|
11121
|
-
writeStorageFileAtomicSync(finalPath, `${JSON.stringify(report, null, 2)}
|
|
11122
|
-
`, true);
|
|
11123
|
-
const reports = readdirSync(dir).filter((entry) => /^stall-.*\.json$/.test(entry)).sort();
|
|
11124
|
-
for (const stale of reports.slice(0, Math.max(0, reports.length - MAX_REPORT_FILES))) {
|
|
11125
|
-
try {
|
|
11126
|
-
unlinkSync(path4.join(dir, stale));
|
|
11127
|
-
} catch (error) {
|
|
11128
|
-
logOnce("prune", "could not prune an old report", error);
|
|
11129
|
-
}
|
|
11130
|
-
}
|
|
11131
|
-
return finalPath;
|
|
11132
|
-
};
|
|
11133
11204
|
const recordStall = (api, startMs, endMs, traces) => {
|
|
11134
11205
|
const after = snapshot(api);
|
|
11135
|
-
const gapMs = endMs - startMs;
|
|
11136
11206
|
let windowed = traces;
|
|
11137
11207
|
let windowFilter = "since-last-collection";
|
|
11138
11208
|
if (clockOffsetMs !== null) {
|
|
@@ -11150,40 +11220,17 @@ function createHostStallProfiler(deps) {
|
|
|
11150
11220
|
windowFilter = "since-last-collection (timestamp filter matched no sample)";
|
|
11151
11221
|
}
|
|
11152
11222
|
}
|
|
11153
|
-
|
|
11154
|
-
|
|
11155
|
-
|
|
11156
|
-
|
|
11157
|
-
|
|
11158
|
-
|
|
11159
|
-
|
|
11160
|
-
|
|
11161
|
-
|
|
11162
|
-
|
|
11163
|
-
|
|
11164
|
-
start: new Date(startWallMs).toISOString(),
|
|
11165
|
-
end: new Date(endWallMs).toISOString(),
|
|
11166
|
-
duration_ms: Math.round(gapMs),
|
|
11167
|
-
lag_ms: Math.round(gapMs - WATCHDOG_INTERVAL_MS),
|
|
11168
|
-
threshold_ms: options.thresholdMs
|
|
11169
|
-
},
|
|
11170
|
-
sampling: {
|
|
11171
|
-
interval_ms: options.sampleIntervalMs,
|
|
11172
|
-
samples_collected: traces.length,
|
|
11173
|
-
samples_in_window: windowed.length,
|
|
11174
|
-
samples_aggregated: kept.length,
|
|
11175
|
-
window_filter: windowFilter,
|
|
11176
|
-
note: aggregate.samples === 0 ? "No JavaScript samples in the window: the main thread was not executing inside the JavaScript VM (idle wait, process suspension, or native work outside any JS call)." : undefined
|
|
11177
|
-
},
|
|
11178
|
-
memory: { before: memoryBefore, after },
|
|
11179
|
-
owners: aggregate.owners,
|
|
11180
|
-
top_frames: aggregate.top_frames,
|
|
11181
|
-
top_js_frames: aggregate.top_js_frames,
|
|
11182
|
-
top_stacks: aggregate.top_stacks
|
|
11183
|
-
};
|
|
11184
|
-
const file = writeReport(report, endWallMs);
|
|
11185
|
-
const top = aggregate.owners[0];
|
|
11186
|
-
safeLog(`[magic-context] host stall profiler: ${Math.round(gapMs)}ms main-thread stall, ${aggregate.samples} samples, top owner ${top ? `${top.owner} (${top.percent}%)` : "none"} → ${file}`);
|
|
11223
|
+
emitStallReport(deps, {
|
|
11224
|
+
startMs,
|
|
11225
|
+
endMs,
|
|
11226
|
+
traces,
|
|
11227
|
+
windowed,
|
|
11228
|
+
windowFilter,
|
|
11229
|
+
options,
|
|
11230
|
+
before: memoryBefore,
|
|
11231
|
+
after,
|
|
11232
|
+
backend: "jsc"
|
|
11233
|
+
});
|
|
11187
11234
|
memoryBefore = after;
|
|
11188
11235
|
};
|
|
11189
11236
|
const tick = () => {
|
|
@@ -11195,7 +11242,7 @@ function createHostStallProfiler(deps) {
|
|
|
11195
11242
|
const startMs = lastTickAt;
|
|
11196
11243
|
lastTickAt = now;
|
|
11197
11244
|
const traces = drain(api);
|
|
11198
|
-
if (now - startMs
|
|
11245
|
+
if (now - startMs - WATCHDOG_INTERVAL_MS >= options.thresholdMs) {
|
|
11199
11246
|
try {
|
|
11200
11247
|
recordStall(api, startMs, now, traces);
|
|
11201
11248
|
} catch (error) {
|
|
@@ -11265,8 +11312,8 @@ function createHostStallProfiler(deps) {
|
|
|
11265
11312
|
if (unavailable)
|
|
11266
11313
|
return;
|
|
11267
11314
|
try {
|
|
11268
|
-
const enablePath =
|
|
11269
|
-
if (!
|
|
11315
|
+
const enablePath = path5.join(deps.profilerDir(), HOST_PROFILER_ENABLE_FILENAME);
|
|
11316
|
+
if (!existsSync6(enablePath)) {
|
|
11270
11317
|
if (watchdog !== null)
|
|
11271
11318
|
disable("enable file removed");
|
|
11272
11319
|
return;
|
|
@@ -11283,7 +11330,7 @@ function createHostStallProfiler(deps) {
|
|
|
11283
11330
|
return;
|
|
11284
11331
|
}
|
|
11285
11332
|
const api = await ensureJsc();
|
|
11286
|
-
if (!api || watchdog !== null || !
|
|
11333
|
+
if (!api || watchdog !== null || !existsSync6(enablePath))
|
|
11287
11334
|
return;
|
|
11288
11335
|
enable(api, parsed.options);
|
|
11289
11336
|
} catch (error) {
|
|
@@ -11317,45 +11364,285 @@ function createHostStallProfiler(deps) {
|
|
|
11317
11364
|
isUnavailable: () => unavailable
|
|
11318
11365
|
};
|
|
11319
11366
|
}
|
|
11320
|
-
|
|
11321
|
-
|
|
11367
|
+
|
|
11368
|
+
// src/shared/host-stall-profiler-node.ts
|
|
11369
|
+
import { existsSync as existsSync7, readFileSync as readFileSync6 } from "node:fs";
|
|
11370
|
+
import * as path6 from "node:path";
|
|
11371
|
+
function v8ProfileTraces(profile, windowStartMs) {
|
|
11372
|
+
const nodes = new Map(profile.nodes.map((node) => [node.id, node]));
|
|
11373
|
+
const parents = new Map;
|
|
11374
|
+
for (const node of profile.nodes)
|
|
11375
|
+
for (const child of node.children ?? [])
|
|
11376
|
+
parents.set(child, node.id);
|
|
11377
|
+
const stacks = new Map;
|
|
11378
|
+
const stackFor = (id) => {
|
|
11379
|
+
const cached = stacks.get(id);
|
|
11380
|
+
if (cached)
|
|
11381
|
+
return cached;
|
|
11382
|
+
const frames = [];
|
|
11383
|
+
const seen = new Set;
|
|
11384
|
+
let next = id;
|
|
11385
|
+
while (next !== undefined && !seen.has(next)) {
|
|
11386
|
+
seen.add(next);
|
|
11387
|
+
const node = nodes.get(next);
|
|
11388
|
+
if (!node)
|
|
11389
|
+
break;
|
|
11390
|
+
const frame = node.callFrame;
|
|
11391
|
+
if (frame.functionName !== "(root)" && frame.functionName !== "(idle)") {
|
|
11392
|
+
frames.push({
|
|
11393
|
+
name: frame.functionName,
|
|
11394
|
+
sourceURL: frame.url || undefined,
|
|
11395
|
+
line: frame.lineNumber >= 0 ? frame.lineNumber + 1 : undefined,
|
|
11396
|
+
column: frame.columnNumber >= 0 ? frame.columnNumber + 1 : undefined
|
|
11397
|
+
});
|
|
11398
|
+
}
|
|
11399
|
+
next = parents.get(next);
|
|
11400
|
+
}
|
|
11401
|
+
stacks.set(id, frames);
|
|
11402
|
+
return frames;
|
|
11403
|
+
};
|
|
11404
|
+
let elapsedMicros = 0;
|
|
11405
|
+
return (profile.samples ?? []).flatMap((id, index) => {
|
|
11406
|
+
const delta = profile.timeDeltas?.[index];
|
|
11407
|
+
if (typeof delta !== "number" || !Number.isFinite(delta))
|
|
11408
|
+
return [];
|
|
11409
|
+
elapsedMicros += delta;
|
|
11410
|
+
return [{ timestamp: (windowStartMs + elapsedMicros / 1000) / 1000, frames: stackFor(id) }];
|
|
11411
|
+
});
|
|
11322
11412
|
}
|
|
11323
|
-
function
|
|
11413
|
+
function createNodeHostStallProfiler(deps) {
|
|
11414
|
+
let session = null;
|
|
11415
|
+
let pollTimer = null;
|
|
11416
|
+
let watchdog = null;
|
|
11417
|
+
let stopped = false;
|
|
11418
|
+
let unavailable = false;
|
|
11419
|
+
let options = {
|
|
11420
|
+
thresholdMs: DEFAULT_STALL_THRESHOLD_MS,
|
|
11421
|
+
sampleIntervalMs: DEFAULT_SAMPLE_INTERVAL_MS
|
|
11422
|
+
};
|
|
11423
|
+
let lastTickAt = 0;
|
|
11424
|
+
let windowStartMs = 0;
|
|
11425
|
+
let memoryBefore = null;
|
|
11426
|
+
let work = Promise.resolve();
|
|
11427
|
+
const logged = new Set;
|
|
11428
|
+
const safeLog = (message) => {
|
|
11429
|
+
try {
|
|
11430
|
+
deps.log(message);
|
|
11431
|
+
} catch {}
|
|
11432
|
+
};
|
|
11433
|
+
const fail = (key, error) => {
|
|
11434
|
+
if (logged.has(key))
|
|
11435
|
+
return;
|
|
11436
|
+
logged.add(key);
|
|
11437
|
+
safeLog(`[magic-context] host stall profiler: ${key}: ${error instanceof Error ? error.message : String(error)}`);
|
|
11438
|
+
};
|
|
11439
|
+
const post = (api, method, params = {}) => new Promise((resolve, reject) => {
|
|
11440
|
+
api.post(method, params, (error, result) => error ? reject(error) : resolve(result ?? {}));
|
|
11441
|
+
});
|
|
11442
|
+
const snapshot = () => {
|
|
11443
|
+
const memory = deps.memoryUsage();
|
|
11444
|
+
return {
|
|
11445
|
+
at: new Date(deps.wallNow()).toISOString(),
|
|
11446
|
+
heap_size_bytes: memory.heapUsed,
|
|
11447
|
+
rss_bytes: memory.rss,
|
|
11448
|
+
jsc_memory: null,
|
|
11449
|
+
percent_available_memory_in_use: null
|
|
11450
|
+
};
|
|
11451
|
+
};
|
|
11452
|
+
const disable = async (reason) => {
|
|
11453
|
+
if (watchdog !== null)
|
|
11454
|
+
deps.clearInterval(watchdog);
|
|
11455
|
+
watchdog = null;
|
|
11456
|
+
const api = session;
|
|
11457
|
+
session = null;
|
|
11458
|
+
memoryBefore = null;
|
|
11459
|
+
if (!api)
|
|
11460
|
+
return;
|
|
11461
|
+
try {
|
|
11462
|
+
await post(api, "Profiler.stop");
|
|
11463
|
+
} catch (error) {
|
|
11464
|
+
fail("stop failed", error);
|
|
11465
|
+
} finally {
|
|
11466
|
+
try {
|
|
11467
|
+
api.disconnect();
|
|
11468
|
+
} catch (error) {
|
|
11469
|
+
fail("disconnect failed", error);
|
|
11470
|
+
}
|
|
11471
|
+
}
|
|
11472
|
+
safeLog(`[magic-context] host stall profiler disabled: ${reason}`);
|
|
11473
|
+
};
|
|
11474
|
+
const startWindow = async (api) => {
|
|
11475
|
+
windowStartMs = deps.now();
|
|
11476
|
+
await post(api, "Profiler.start");
|
|
11477
|
+
};
|
|
11478
|
+
const tick = async () => {
|
|
11479
|
+
const api = session;
|
|
11480
|
+
if (!api || watchdog === null)
|
|
11481
|
+
return;
|
|
11482
|
+
const now = deps.now();
|
|
11483
|
+
const startMs = lastTickAt;
|
|
11484
|
+
lastTickAt = now;
|
|
11485
|
+
const stall = now - startMs - WATCHDOG_INTERVAL_MS >= options.thresholdMs;
|
|
11486
|
+
if (!stall && now - windowStartMs < PROFILE_WINDOW_MS)
|
|
11487
|
+
return;
|
|
11488
|
+
try {
|
|
11489
|
+
const { profile } = await post(api, "Profiler.stop");
|
|
11490
|
+
const profileStartMs = windowStartMs;
|
|
11491
|
+
if (session !== api || stopped)
|
|
11492
|
+
return;
|
|
11493
|
+
await startWindow(api);
|
|
11494
|
+
const after = snapshot();
|
|
11495
|
+
if (stall && profile) {
|
|
11496
|
+
const traces = v8ProfileTraces(profile, profileStartMs);
|
|
11497
|
+
const slackMs = 2 * options.sampleIntervalMs + 20;
|
|
11498
|
+
const windowed = traces.filter((trace) => {
|
|
11499
|
+
const at = (trace.timestamp ?? 0) * 1000;
|
|
11500
|
+
return at >= startMs - slackMs && at <= now + slackMs;
|
|
11501
|
+
});
|
|
11502
|
+
try {
|
|
11503
|
+
emitStallReport(deps, {
|
|
11504
|
+
startMs,
|
|
11505
|
+
endMs: now,
|
|
11506
|
+
traces,
|
|
11507
|
+
windowed,
|
|
11508
|
+
windowFilter: "timestamp",
|
|
11509
|
+
options,
|
|
11510
|
+
before: memoryBefore,
|
|
11511
|
+
after,
|
|
11512
|
+
backend: "v8"
|
|
11513
|
+
});
|
|
11514
|
+
} catch (error) {
|
|
11515
|
+
fail("could not write a stall report", error);
|
|
11516
|
+
}
|
|
11517
|
+
}
|
|
11518
|
+
memoryBefore = after;
|
|
11519
|
+
} catch (error) {
|
|
11520
|
+
fail("watchdog tick failed", error);
|
|
11521
|
+
await disable("sampling failed");
|
|
11522
|
+
}
|
|
11523
|
+
};
|
|
11524
|
+
const enqueue = (fn) => {
|
|
11525
|
+
work = work.then(fn).catch((error) => fail("profiler operation failed", error));
|
|
11526
|
+
return work;
|
|
11527
|
+
};
|
|
11528
|
+
const runCheck = async () => {
|
|
11529
|
+
if (stopped || unavailable)
|
|
11530
|
+
return;
|
|
11531
|
+
const enablePath = path6.join(deps.profilerDir(), HOST_PROFILER_ENABLE_FILENAME);
|
|
11532
|
+
if (!existsSync7(enablePath)) {
|
|
11533
|
+
await disable("enable file removed");
|
|
11534
|
+
return;
|
|
11535
|
+
}
|
|
11536
|
+
const parsed = parseEnableFile(readFileSync6(enablePath, "utf8"));
|
|
11537
|
+
if (parsed.error)
|
|
11538
|
+
fail("enable options", parsed.error);
|
|
11539
|
+
if (session && parsed.options.sampleIntervalMs === options.sampleIntervalMs) {
|
|
11540
|
+
options = parsed.options;
|
|
11541
|
+
return;
|
|
11542
|
+
}
|
|
11543
|
+
if (session)
|
|
11544
|
+
await disable("sample interval changed");
|
|
11545
|
+
options = parsed.options;
|
|
11546
|
+
try {
|
|
11547
|
+
const api = await deps.createSession();
|
|
11548
|
+
if (stopped || !existsSync7(enablePath))
|
|
11549
|
+
return;
|
|
11550
|
+
session = api;
|
|
11551
|
+
api.connect();
|
|
11552
|
+
await post(api, "Profiler.enable");
|
|
11553
|
+
await post(api, "Profiler.setSamplingInterval", {
|
|
11554
|
+
interval: Math.round(options.sampleIntervalMs * 1000)
|
|
11555
|
+
});
|
|
11556
|
+
await startWindow(api);
|
|
11557
|
+
if (stopped || !existsSync7(enablePath)) {
|
|
11558
|
+
await disable("enable file removed");
|
|
11559
|
+
return;
|
|
11560
|
+
}
|
|
11561
|
+
lastTickAt = deps.now();
|
|
11562
|
+
memoryBefore = snapshot();
|
|
11563
|
+
watchdog = deps.setInterval(() => {
|
|
11564
|
+
enqueue(tick);
|
|
11565
|
+
}, WATCHDOG_INTERVAL_MS);
|
|
11566
|
+
safeLog(`[magic-context] host stall profiler enabled: threshold ${options.thresholdMs}ms, sample interval ${options.sampleIntervalMs}ms, backend v8, rotation ${PROFILE_WINDOW_MS}ms, reports in ${deps.profilerDir()}`);
|
|
11567
|
+
} catch (error) {
|
|
11568
|
+
fail("could not start inspector profiler", error);
|
|
11569
|
+
await disable("inspector unavailable");
|
|
11570
|
+
unavailable = true;
|
|
11571
|
+
if (pollTimer !== null)
|
|
11572
|
+
deps.clearInterval(pollTimer);
|
|
11573
|
+
pollTimer = null;
|
|
11574
|
+
}
|
|
11575
|
+
};
|
|
11324
11576
|
return {
|
|
11325
|
-
|
|
11326
|
-
|
|
11327
|
-
|
|
11328
|
-
|
|
11329
|
-
|
|
11330
|
-
|
|
11331
|
-
|
|
11332
|
-
|
|
11577
|
+
start() {
|
|
11578
|
+
if (pollTimer !== null || unavailable)
|
|
11579
|
+
return;
|
|
11580
|
+
stopped = false;
|
|
11581
|
+
pollTimer = deps.setInterval(() => {
|
|
11582
|
+
enqueue(runCheck);
|
|
11583
|
+
}, SWITCH_POLL_MS);
|
|
11584
|
+
enqueue(runCheck);
|
|
11333
11585
|
},
|
|
11334
|
-
|
|
11335
|
-
|
|
11336
|
-
|
|
11337
|
-
|
|
11338
|
-
|
|
11586
|
+
checkNow: () => enqueue(runCheck),
|
|
11587
|
+
stop() {
|
|
11588
|
+
stopped = true;
|
|
11589
|
+
if (pollTimer !== null)
|
|
11590
|
+
deps.clearInterval(pollTimer);
|
|
11591
|
+
pollTimer = null;
|
|
11592
|
+
if (watchdog !== null)
|
|
11593
|
+
deps.clearInterval(watchdog);
|
|
11594
|
+
watchdog = null;
|
|
11595
|
+
enqueue(() => disable("stopped"));
|
|
11596
|
+
},
|
|
11597
|
+
isActive: () => watchdog !== null,
|
|
11598
|
+
isUnavailable: () => unavailable
|
|
11339
11599
|
};
|
|
11340
11600
|
}
|
|
11601
|
+
|
|
11602
|
+
// src/shared/host-stall-profiler.ts
|
|
11603
|
+
function hostStallProfilerDir() {
|
|
11604
|
+
return path7.join(getMagicContextStorageDir(), HOST_PROFILER_DIRNAME);
|
|
11605
|
+
}
|
|
11341
11606
|
var PROCESS_PROFILER_KEY = Symbol.for("cortexkit.magic-context.host-stall-profiler");
|
|
11607
|
+
var jscModule = "bun:jsc";
|
|
11342
11608
|
function startHostStallProfilerSwitch() {
|
|
11343
11609
|
try {
|
|
11344
11610
|
const holder = globalThis;
|
|
11345
11611
|
if (holder[PROCESS_PROFILER_KEY])
|
|
11346
11612
|
return;
|
|
11347
|
-
const
|
|
11613
|
+
const deps = {
|
|
11614
|
+
profilerDir: hostStallProfilerDir,
|
|
11615
|
+
now: () => performance.now(),
|
|
11616
|
+
wallNow: () => Date.now(),
|
|
11617
|
+
setInterval: (callback, ms) => {
|
|
11618
|
+
const handle = setInterval(callback, ms);
|
|
11619
|
+
handle.unref?.();
|
|
11620
|
+
return handle;
|
|
11621
|
+
},
|
|
11622
|
+
clearInterval: (handle) => clearInterval(handle),
|
|
11623
|
+
rss: () => process.memoryUsage.rss(),
|
|
11624
|
+
log: log2,
|
|
11625
|
+
pid: process.pid,
|
|
11626
|
+
bunVersion: process.versions.bun ?? null
|
|
11627
|
+
};
|
|
11628
|
+
const handle = process.versions.bun ? createHostStallProfiler({ ...deps, loadJsc: () => import(jscModule) }) : createNodeHostStallProfiler({
|
|
11629
|
+
...deps,
|
|
11630
|
+
createSession: async () => {
|
|
11631
|
+
const { Session } = await import("node:inspector");
|
|
11632
|
+
return new Session;
|
|
11633
|
+
},
|
|
11634
|
+
memoryUsage: () => process.memoryUsage()
|
|
11635
|
+
});
|
|
11348
11636
|
holder[PROCESS_PROFILER_KEY] = handle;
|
|
11349
11637
|
handle.start();
|
|
11350
11638
|
} catch (error) {
|
|
11351
|
-
|
|
11639
|
+
log2("[magic-context] host stall profiler: could not start the enable-file switch", error);
|
|
11352
11640
|
}
|
|
11353
11641
|
}
|
|
11354
|
-
|
|
11355
11642
|
// src/plugin/instance-disposal.ts
|
|
11356
|
-
import
|
|
11643
|
+
import path8 from "node:path";
|
|
11357
11644
|
function isDisposedInstanceDirectory(ownDirectory, disposedDirectory) {
|
|
11358
|
-
return
|
|
11645
|
+
return path8.resolve(disposedDirectory) === path8.resolve(ownDirectory);
|
|
11359
11646
|
}
|
|
11360
11647
|
|
|
11361
11648
|
// src/plugin/native-compaction-guard.ts
|
|
@@ -11364,7 +11651,7 @@ function disableNativeAutoCompaction(config) {
|
|
|
11364
11651
|
if (target.compaction?.auto === false)
|
|
11365
11652
|
return false;
|
|
11366
11653
|
target.compaction = { ...target.compaction ?? {}, auto: false };
|
|
11367
|
-
|
|
11654
|
+
log2("[magic-context] OpenCode auto-compaction was not disabled in any config layer; turned it off for this instance because Magic Context manages compaction");
|
|
11368
11655
|
return true;
|
|
11369
11656
|
}
|
|
11370
11657
|
|
|
@@ -11435,7 +11722,7 @@ function createToolRegistry(args) {
|
|
|
11435
11722
|
return {};
|
|
11436
11723
|
}
|
|
11437
11724
|
ensureProjectRegisteredFromOpenCodeDirectory(ctx.directory, db).catch((error) => {
|
|
11438
|
-
|
|
11725
|
+
log2(`[magic-context] embedding registration skipped: ${getErrorMessage(error)}`);
|
|
11439
11726
|
});
|
|
11440
11727
|
const resolveProjectPath = (directory) => resolveProjectIdentityForSession(directory, pluginConfig.allow_home_project);
|
|
11441
11728
|
const memoryEnabled = pluginConfig.memory?.enabled !== false;
|
|
@@ -11450,6 +11737,7 @@ function createToolRegistry(args) {
|
|
|
11450
11737
|
...createCtxNoteTools({
|
|
11451
11738
|
db,
|
|
11452
11739
|
dreamerEnabled: isDreamerRunnable(pluginConfig),
|
|
11740
|
+
smartNotesEnabled: pluginConfig.smart_notes?.enabled,
|
|
11453
11741
|
resolveProjectPath,
|
|
11454
11742
|
rustToolBackends
|
|
11455
11743
|
}),
|
|
@@ -11475,11 +11763,11 @@ function createToolRegistry(args) {
|
|
|
11475
11763
|
const promptSurfaceRuntime = args.promptSurfaceRuntime ?? createPromptSurfaceRuntime({
|
|
11476
11764
|
harness: "opencode",
|
|
11477
11765
|
directory: ctx.directory,
|
|
11478
|
-
warn: (message) =>
|
|
11766
|
+
warn: (message) => log2(`[magic-context] config warning: ${message}`)
|
|
11479
11767
|
});
|
|
11480
11768
|
const registration = promptSurfaceRuntime.resolveRegistration(args.registrationPromptSurface ?? pluginConfig.prompt_surface);
|
|
11481
11769
|
const surfacedTools = Object.fromEntries(Object.entries(allTools).map(([toolId, definition]) => {
|
|
11482
|
-
const parameterDescriptions = parameterDescriptionsFor(toolId, registration.preset);
|
|
11770
|
+
const parameterDescriptions = parameterDescriptionsFor(toolId, registration.preset, pluginConfig.smart_notes?.enabled);
|
|
11483
11771
|
const argsWithPresetDescriptions = parameterDescriptions ? Object.fromEntries(Object.entries(definition.args).map(([name, schema]) => [
|
|
11484
11772
|
name,
|
|
11485
11773
|
parameterDescriptions[name] ? schema.describe(parameterDescriptions[name]) : schema
|
|
@@ -11489,7 +11777,7 @@ function createToolRegistry(args) {
|
|
|
11489
11777
|
{
|
|
11490
11778
|
...definition,
|
|
11491
11779
|
args: argsWithPresetDescriptions,
|
|
11492
|
-
description: registration.descriptionFor(toolId, definition.description ?? "")
|
|
11780
|
+
description: toolId === "ctx_note" && pluginConfig.smart_notes?.enabled === false ? withoutSmartNoteText(registration.preset === "light" ? CTX_NOTE_LIGHT_DESCRIPTION : definition.description ?? "") : registration.descriptionFor(toolId, definition.description ?? "")
|
|
11493
11781
|
}
|
|
11494
11782
|
];
|
|
11495
11783
|
}));
|
|
@@ -11517,30 +11805,9 @@ function buildOpenCodeConfigWarningBanner(warnings, parseFailures, allParseFailu
|
|
|
11517
11805
|
`);
|
|
11518
11806
|
}
|
|
11519
11807
|
|
|
11520
|
-
// src/shared/exit-abort-registry.ts
|
|
11521
|
-
var controllers = new Set;
|
|
11522
|
-
var listenerRegistered = false;
|
|
11523
|
-
function abortAll() {
|
|
11524
|
-
for (const controller of controllers) {
|
|
11525
|
-
try {
|
|
11526
|
-
controller.abort();
|
|
11527
|
-
} catch {}
|
|
11528
|
-
}
|
|
11529
|
-
}
|
|
11530
|
-
function registerExitAbort(controller) {
|
|
11531
|
-
controllers.add(controller);
|
|
11532
|
-
if (listenerRegistered)
|
|
11533
|
-
return;
|
|
11534
|
-
listenerRegistered = true;
|
|
11535
|
-
process.once("exit", abortAll);
|
|
11536
|
-
}
|
|
11537
|
-
function unregisterExitAbort(controller) {
|
|
11538
|
-
controllers.delete(controller);
|
|
11539
|
-
}
|
|
11540
|
-
|
|
11541
11808
|
// src/v2/hooks/update-check.ts
|
|
11542
|
-
import { existsSync as
|
|
11543
|
-
import { dirname as dirname4, join as
|
|
11809
|
+
import { existsSync as existsSync8, readFileSync as readFileSync7 } from "node:fs";
|
|
11810
|
+
import { dirname as dirname4, join as join10 } from "node:path";
|
|
11544
11811
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
11545
11812
|
var cachedPackageInfo;
|
|
11546
11813
|
function packageInfo() {
|
|
@@ -11549,11 +11816,11 @@ function packageInfo() {
|
|
|
11549
11816
|
let directory = dirname4(fileURLToPath2(import.meta.url));
|
|
11550
11817
|
for (;; ) {
|
|
11551
11818
|
try {
|
|
11552
|
-
const pkg = JSON.parse(
|
|
11819
|
+
const pkg = JSON.parse(readFileSync7(join10(directory, "package.json"), "utf8"));
|
|
11553
11820
|
if (pkg.name === "@cortexkit/opencode-magic-context" && typeof pkg.version === "string") {
|
|
11554
11821
|
cachedPackageInfo = {
|
|
11555
11822
|
version: pkg.version,
|
|
11556
|
-
development:
|
|
11823
|
+
development: existsSync8(join10(directory, "src/v2/server.ts"))
|
|
11557
11824
|
};
|
|
11558
11825
|
return cachedPackageInfo;
|
|
11559
11826
|
}
|
|
@@ -11599,7 +11866,7 @@ function startUpdateChecks(context, check = (signal) => {
|
|
|
11599
11866
|
}
|
|
11600
11867
|
} catch (error) {
|
|
11601
11868
|
if (!controller.signal.aborted)
|
|
11602
|
-
|
|
11869
|
+
log2("[magic-context] v2 update check unavailable", error);
|
|
11603
11870
|
}
|
|
11604
11871
|
})();
|
|
11605
11872
|
return {
|
|
@@ -11620,16 +11887,16 @@ function isOpenCode2HostContext(context) {
|
|
|
11620
11887
|
}
|
|
11621
11888
|
async function setup(context) {
|
|
11622
11889
|
if (!isOpenCode2HostContext(context)) {
|
|
11623
|
-
|
|
11890
|
+
log2("v2 setup() called on a host without session.hook; v1 server lane owns this host, v2 lane inert");
|
|
11624
11891
|
return async () => {};
|
|
11625
11892
|
}
|
|
11626
|
-
const { registerContext } = await import("./context-
|
|
11627
|
-
|
|
11893
|
+
const { registerContext } = await import("./context-m0cy262m.js");
|
|
11894
|
+
setHarness2("opencode2");
|
|
11628
11895
|
bindStaleBuildNotice({}, import.meta.url, "opencode2");
|
|
11629
11896
|
const duties = await registerContext(context);
|
|
11630
11897
|
const checks = loadPluginConfigDetailed(context.location.directory).config.auto_update === false ? undefined : startUpdateChecks(context);
|
|
11631
|
-
|
|
11632
|
-
|
|
11898
|
+
log2("[magic-context] @cortexkit/opencode-magic-context v2 setup");
|
|
11899
|
+
flushLogger2();
|
|
11633
11900
|
return async () => {
|
|
11634
11901
|
await checks?.dispose();
|
|
11635
11902
|
await duties?.dispose();
|
|
@@ -11649,14 +11916,14 @@ var server = async (ctx) => {
|
|
|
11649
11916
|
let rpcMs = 0;
|
|
11650
11917
|
let hooksDeadlineReason = null;
|
|
11651
11918
|
let deadlinePhase = null;
|
|
11652
|
-
emitBootEnteringBreadcrumb(process.pid, ctx.directory,
|
|
11653
|
-
|
|
11919
|
+
emitBootEnteringBreadcrumb(process.pid, ctx.directory, log2, flushLogger2);
|
|
11920
|
+
setHarness2("opencode");
|
|
11654
11921
|
startHostStallProfilerSwitch();
|
|
11655
11922
|
const configStartedAt = performance.now();
|
|
11656
11923
|
beginBootQuietPeriod();
|
|
11657
11924
|
const configMigrationWarnings = migrateMagicContextConfigLocations(ctx.directory, {
|
|
11658
|
-
warn: (m) =>
|
|
11659
|
-
info: (m) =>
|
|
11925
|
+
warn: (m) => log2(`[magic-context] ${m}`),
|
|
11926
|
+
info: (m) => log2(`[magic-context] ${m}`)
|
|
11660
11927
|
});
|
|
11661
11928
|
const loadedPluginConfig = loadPluginConfigDetailed(ctx.directory);
|
|
11662
11929
|
const pluginConfig = loadedPluginConfig.config;
|
|
@@ -11667,7 +11934,7 @@ var server = async (ctx) => {
|
|
|
11667
11934
|
const promptSurfaceRuntime = createPromptSurfaceRuntime({
|
|
11668
11935
|
harness: "opencode",
|
|
11669
11936
|
directory: ctx.directory,
|
|
11670
|
-
warn: (message) =>
|
|
11937
|
+
warn: (message) => log2(`[magic-context] config warning: ${message}`)
|
|
11671
11938
|
});
|
|
11672
11939
|
if (configMigrationWarnings.length > 0) {
|
|
11673
11940
|
pluginConfig.configWarnings = [
|
|
@@ -11685,7 +11952,7 @@ var server = async (ctx) => {
|
|
|
11685
11952
|
registerExitAbort(autoUpdateAbort);
|
|
11686
11953
|
if (pluginConfig.configWarnings?.length) {
|
|
11687
11954
|
for (const w of pluginConfig.configWarnings) {
|
|
11688
|
-
|
|
11955
|
+
log2(`[magic-context] config warning: ${w}`);
|
|
11689
11956
|
}
|
|
11690
11957
|
const allParseFailures = loadedPluginConfig.configParseFailures;
|
|
11691
11958
|
const parseFailuresToShow = claimConfigParseFailuresOnce("opencode", allParseFailures);
|
|
@@ -11694,7 +11961,7 @@ var server = async (ctx) => {
|
|
|
11694
11961
|
if (hasBannerEntries)
|
|
11695
11962
|
setTimeout(async () => {
|
|
11696
11963
|
try {
|
|
11697
|
-
const { sendStatusNotification } = await importPluginModule(() => import("./send-session-notification-
|
|
11964
|
+
const { sendStatusNotification } = await importPluginModule(() => import("./send-session-notification-erecz4y4.js"));
|
|
11698
11965
|
const clientWithSessions = ctx.client;
|
|
11699
11966
|
const sessions = await Promise.resolve(clientWithSessions.session?.list?.()).catch(() => null);
|
|
11700
11967
|
const sessionList = Array.isArray(sessions) ? sessions : sessions?.data;
|
|
@@ -11708,10 +11975,10 @@ var server = async (ctx) => {
|
|
|
11708
11975
|
const openCodeDbResolution = resolveOpenCodeDbPath();
|
|
11709
11976
|
if (!openCodeDbPathExists(openCodeDbResolution) && claimOpenCodeDbDiagnosticOnce("boot-banner", openCodeDbResolution)) {
|
|
11710
11977
|
const missingDbBanner = formatOpenCodeDbMissingBanner(openCodeDbResolution);
|
|
11711
|
-
|
|
11978
|
+
log2(`[magic-context] opencode_db_missing path=${openCodeDbResolution.path} source=${openCodeDbResolution.source}`);
|
|
11712
11979
|
setTimeout(async () => {
|
|
11713
11980
|
try {
|
|
11714
|
-
const { sendStatusNotification } = await importPluginModule(() => import("./send-session-notification-
|
|
11981
|
+
const { sendStatusNotification } = await importPluginModule(() => import("./send-session-notification-erecz4y4.js"));
|
|
11715
11982
|
const clientWithSessions = ctx.client;
|
|
11716
11983
|
const sessions = await Promise.resolve(clientWithSessions.session?.list?.()).catch(() => null);
|
|
11717
11984
|
const sessionList = Array.isArray(sessions) ? sessions : sessions?.data;
|
|
@@ -11728,7 +11995,7 @@ var server = async (ctx) => {
|
|
|
11728
11995
|
const resolvedConfigTimeoutMs = Math.min(RESOLVED_CONFIG_TIMEOUT_MS, remainingBootBudgetMs(bootBudget));
|
|
11729
11996
|
const resolvedCompaction = resolvedConfigTimeoutMs > 0 ? await resolveCompactionForBoot(ctx.client, resolvedConfigTimeoutMs) : null;
|
|
11730
11997
|
if (resolvedCompaction === null) {
|
|
11731
|
-
|
|
11998
|
+
log2("[magic-context] resolved-config fetch failed; using file-based compaction detection (the running server's resolved config may differ — `opencode debug config` is authoritative)");
|
|
11732
11999
|
}
|
|
11733
12000
|
conflictResult = detectConflicts(ctx.directory, {
|
|
11734
12001
|
compactionEnabled: isCompactionEnabled(pluginConfig),
|
|
@@ -11736,9 +12003,9 @@ var server = async (ctx) => {
|
|
|
11736
12003
|
});
|
|
11737
12004
|
if (conflictResult.hasConflict) {
|
|
11738
12005
|
pluginConfig.enabled = false;
|
|
11739
|
-
|
|
12006
|
+
log2(`[magic-context] disabled due to conflicts: ${conflictResult.reasons.join("; ")}`);
|
|
11740
12007
|
} else {
|
|
11741
|
-
|
|
12008
|
+
log2("[magic-context] no conflicts detected, plugin enabled");
|
|
11742
12009
|
}
|
|
11743
12010
|
}
|
|
11744
12011
|
conflictMs = performance.now() - conflictStartedAt;
|
|
@@ -11754,7 +12021,7 @@ var server = async (ctx) => {
|
|
|
11754
12021
|
rustModeModuleClient,
|
|
11755
12022
|
promptSurfaceRuntime,
|
|
11756
12023
|
onStorageBootTimings: (timings) => Object.assign(storageBootTimings, timings)
|
|
11757
|
-
}),
|
|
12024
|
+
}), log2);
|
|
11758
12025
|
const hooks = hooksPhase.status === "completed" ? hooksPhase.value : { magicContext: null, rustToolBackends: undefined };
|
|
11759
12026
|
if (hooksPhase.status === "timed_out") {
|
|
11760
12027
|
deadlinePhase = "hooks";
|
|
@@ -11772,7 +12039,7 @@ var server = async (ctx) => {
|
|
|
11772
12039
|
const storageFailureReason = hooksDeadlineReason ? { kind: "storage_failure", cause: hooksDeadlineReason } : initFailure?.type === "storage" ? initFailure.reason : null;
|
|
11773
12040
|
if (storageFailureReason) {
|
|
11774
12041
|
failClosed.arm(storageFailureReason);
|
|
11775
|
-
|
|
12042
|
+
log2(`[magic-context] fail-closed blocking armed (${storageFailureReason.kind}); primary sessions will error until storage recovers or the build is upgraded`);
|
|
11776
12043
|
}
|
|
11777
12044
|
}
|
|
11778
12045
|
if (hooksPhase.status === "timed_out") {
|
|
@@ -11782,7 +12049,7 @@ var server = async (ctx) => {
|
|
|
11782
12049
|
magicContextRuntime.magicContext = late.magicContext;
|
|
11783
12050
|
magicContextRuntime.rustToolBackends = late.rustToolBackends;
|
|
11784
12051
|
failClosed.clear();
|
|
11785
|
-
|
|
12052
|
+
log2("[magic-context] boot hooks phase settled after its deadline; Magic Context runtime installed and fail-closed cleared");
|
|
11786
12053
|
});
|
|
11787
12054
|
}
|
|
11788
12055
|
const tryReopenStorage = async () => {
|
|
@@ -11804,10 +12071,10 @@ var server = async (ctx) => {
|
|
|
11804
12071
|
magicContextRuntime.magicContext = reopened.magicContext;
|
|
11805
12072
|
magicContextRuntime.rustToolBackends = reopened.rustToolBackends;
|
|
11806
12073
|
failClosed.clear();
|
|
11807
|
-
|
|
12074
|
+
log2("[magic-context] storage re-probe succeeded; Magic Context runtime restored");
|
|
11808
12075
|
return true;
|
|
11809
12076
|
} catch (error) {
|
|
11810
|
-
|
|
12077
|
+
log2(`[magic-context] storage re-probe failed: ${error}`);
|
|
11811
12078
|
return false;
|
|
11812
12079
|
}
|
|
11813
12080
|
};
|
|
@@ -11826,12 +12093,12 @@ var server = async (ctx) => {
|
|
|
11826
12093
|
if (db && isDatabasePersisted(db)) {
|
|
11827
12094
|
scheduleAfterBootQuiet(() => {
|
|
11828
12095
|
runDeferredV22Backfill(db).catch((err) => {
|
|
11829
|
-
|
|
12096
|
+
log2(`[v22-backfill] background runner failed: ${err}`);
|
|
11830
12097
|
});
|
|
11831
12098
|
});
|
|
11832
12099
|
}
|
|
11833
12100
|
} catch (err) {
|
|
11834
|
-
|
|
12101
|
+
log2(`[v22-backfill] failed to start background runner: ${err}`);
|
|
11835
12102
|
}
|
|
11836
12103
|
}
|
|
11837
12104
|
if (pluginConfig.enabled && magicContextRuntime.magicContext) {
|
|
@@ -11869,7 +12136,7 @@ var server = async (ctx) => {
|
|
|
11869
12136
|
closeQuietly(ocDb);
|
|
11870
12137
|
}
|
|
11871
12138
|
})().catch((err) => {
|
|
11872
|
-
|
|
12139
|
+
log2(`[session-projects] background runner failed: ${err}`);
|
|
11873
12140
|
});
|
|
11874
12141
|
}, 0);
|
|
11875
12142
|
}
|
|
@@ -11881,7 +12148,7 @@ var server = async (ctx) => {
|
|
|
11881
12148
|
const classifyModuleClient = createDreamTimerModuleClient(rustModeModuleClient);
|
|
11882
12149
|
const timerProjectIdentity = resolveProjectIdentityForSession(ctx.directory, pluginConfig.allow_home_project);
|
|
11883
12150
|
if (!timerProjectIdentity) {
|
|
11884
|
-
|
|
12151
|
+
log2("[magic-context] dream timer skipped: no project identity is bound for this directory");
|
|
11885
12152
|
} else {
|
|
11886
12153
|
const timerRegistration = {
|
|
11887
12154
|
directory: ctx.directory,
|
|
@@ -11919,6 +12186,7 @@ var server = async (ctx) => {
|
|
|
11919
12186
|
},
|
|
11920
12187
|
mural: pluginConfig.mural,
|
|
11921
12188
|
retinaHandoff: pluginConfig.smart_notes.retina_handoff,
|
|
12189
|
+
smartNotesEnabled: pluginConfig.smart_notes.enabled,
|
|
11922
12190
|
gitCommitIndexing: pluginConfig.memory.git_commit_indexing?.enabled ? {
|
|
11923
12191
|
enabled: true,
|
|
11924
12192
|
since_days: pluginConfig.memory.git_commit_indexing.since_days,
|
|
@@ -11939,7 +12207,7 @@ var server = async (ctx) => {
|
|
|
11939
12207
|
startDreamScheduleTimer(timerRegistration).then((stop) => {
|
|
11940
12208
|
stopDreamTimerRegistration = stop;
|
|
11941
12209
|
}).catch((err) => {
|
|
11942
|
-
|
|
12210
|
+
log2(`[magic-context] dream timer registration failed (continuing without it): ${err}`);
|
|
11943
12211
|
});
|
|
11944
12212
|
}, 0);
|
|
11945
12213
|
}
|
|
@@ -11957,9 +12225,9 @@ var server = async (ctx) => {
|
|
|
11957
12225
|
setTimeout(() => {
|
|
11958
12226
|
const rpcStartedAt = performance.now();
|
|
11959
12227
|
rpcServer?.start().then(() => {
|
|
11960
|
-
|
|
12228
|
+
log2(`[magic-context] boot deferred phase: rpc=${Math.round(performance.now() - rpcStartedAt)}ms`);
|
|
11961
12229
|
}).catch((err) => {
|
|
11962
|
-
|
|
12230
|
+
log2(`[magic-context] RPC server failed to start: ${err}`);
|
|
11963
12231
|
});
|
|
11964
12232
|
}, 0);
|
|
11965
12233
|
rpcMs = performance.now() - rpcScheduledAt;
|
|
@@ -11979,21 +12247,21 @@ var server = async (ctx) => {
|
|
|
11979
12247
|
});
|
|
11980
12248
|
setTimeout(() => {
|
|
11981
12249
|
rpcServer?.start().catch((err) => {
|
|
11982
|
-
|
|
12250
|
+
log2(`[magic-context] debug-only RPC server failed to start: ${err}`);
|
|
11983
12251
|
});
|
|
11984
12252
|
}, 0);
|
|
11985
12253
|
}
|
|
11986
12254
|
{
|
|
11987
12255
|
const fence = getSchemaFenceRejection();
|
|
11988
12256
|
if (fence) {
|
|
11989
|
-
importPluginModule(() => import("./conflict-warning-hook-
|
|
12257
|
+
importPluginModule(() => import("./conflict-warning-hook-w8cykrnf.js")).then(({ sendSchemaFenceWarning }) => sendSchemaFenceWarning(ctx.client, ctx.directory, fence)).catch((error) => log2("[magic-context] schema-fence warning unavailable:", error));
|
|
11990
12258
|
}
|
|
11991
12259
|
}
|
|
11992
12260
|
const serverUrl = ctx.serverUrl;
|
|
11993
12261
|
const serverUrlStr = serverUrl instanceof URL ? serverUrl.toString().replace(/\/$/, "") : typeof serverUrl === "string" ? serverUrl.replace(/\/$/, "") : undefined;
|
|
11994
|
-
importPluginModule(() => import("./send-session-notification-
|
|
12262
|
+
importPluginModule(() => import("./send-session-notification-erecz4y4.js")).then(({ setNotificationServerUrl }) => {
|
|
11995
12263
|
setNotificationServerUrl(serverUrlStr);
|
|
11996
|
-
}).catch((error) =>
|
|
12264
|
+
}).catch((error) => log2("[magic-context] notification transport unavailable:", error));
|
|
11997
12265
|
if (conflictResult?.hasConflict) {
|
|
11998
12266
|
setTimeout(() => {
|
|
11999
12267
|
sendConflictWarning2(ctx.client, ctx.directory, conflictResult);
|
|
@@ -12005,7 +12273,7 @@ var server = async (ctx) => {
|
|
|
12005
12273
|
}
|
|
12006
12274
|
if (pluginConfig.enabled && !conflictResult?.hasConflict) {
|
|
12007
12275
|
setTimeout(() => {
|
|
12008
|
-
importPluginModule(() => import("./announcement-
|
|
12276
|
+
importPluginModule(() => import("./announcement-fp14dw0n.js")).then(({
|
|
12009
12277
|
shouldShowAnnouncement,
|
|
12010
12278
|
ANNOUNCEMENT_VERSION,
|
|
12011
12279
|
ANNOUNCEMENT_FEATURES,
|
|
@@ -12014,7 +12282,7 @@ var server = async (ctx) => {
|
|
|
12014
12282
|
}) => {
|
|
12015
12283
|
if (!shouldShowAnnouncement())
|
|
12016
12284
|
return;
|
|
12017
|
-
return importPluginModule(() => import("./conflict-warning-hook-
|
|
12285
|
+
return importPluginModule(() => import("./conflict-warning-hook-w8cykrnf.js")).then(({ sendStartupAnnouncement }) => sendStartupAnnouncement(ctx.client, ctx.directory, ANNOUNCEMENT_VERSION, ANNOUNCEMENT_FEATURES, ANNOUNCEMENT_FOOTER, markAnnouncementSeen));
|
|
12018
12286
|
}).catch(() => {});
|
|
12019
12287
|
}, 8000);
|
|
12020
12288
|
}
|
|
@@ -12024,7 +12292,7 @@ var server = async (ctx) => {
|
|
|
12024
12292
|
const measuredStorageMs = storageBootTimings.openMs + storageBootTimings.guardMs + storageBootTimings.migrateMs;
|
|
12025
12293
|
const hooksMs = Math.max(0, hooksPhase.elapsedMs - measuredStorageMs);
|
|
12026
12294
|
const postMs = Math.max(0, performance.now() - postStartedAt - rpcMs);
|
|
12027
|
-
|
|
12295
|
+
log2(formatBootPhaseDiagnostics({
|
|
12028
12296
|
configMs,
|
|
12029
12297
|
conflictMs,
|
|
12030
12298
|
guardMs: storageBootTimings.guardMs,
|
|
@@ -12037,14 +12305,6 @@ var server = async (ctx) => {
|
|
|
12037
12305
|
budgetMs: BOOT_SERVER_DEADLINE_MS,
|
|
12038
12306
|
deadlinePhase
|
|
12039
12307
|
}));
|
|
12040
|
-
const checkoutClaimGate = pluginConfig.enabled ? createSubcCheckoutClaimGate("opencode", () => pluginConfig.subc?.connection_file ?? getDefaultSubcConnectionFile()) : undefined;
|
|
12041
|
-
const isCheckoutClaimRefused = async (sessionId) => {
|
|
12042
|
-
if (!checkoutClaimGate || !sessionId)
|
|
12043
|
-
return false;
|
|
12044
|
-
if (liveSessionState.internalChildSessions.has(sessionId))
|
|
12045
|
-
return false;
|
|
12046
|
-
return await checkoutClaimGate.refusal(sessionId, ctx.directory) !== null;
|
|
12047
|
-
};
|
|
12048
12308
|
return {
|
|
12049
12309
|
tool: tools,
|
|
12050
12310
|
event: createEventHandler({
|
|
@@ -12054,8 +12314,6 @@ var server = async (ctx) => {
|
|
|
12054
12314
|
const properties = input.event.properties;
|
|
12055
12315
|
if (properties.info?.id)
|
|
12056
12316
|
dreamerCap.delete(properties.info.id);
|
|
12057
|
-
} else if (await isCheckoutClaimRefused(openCodeEventSessionId(input.event))) {
|
|
12058
|
-
return;
|
|
12059
12317
|
}
|
|
12060
12318
|
await magicContextRuntime.magicContext?.event?.(input);
|
|
12061
12319
|
}
|
|
@@ -12081,7 +12339,7 @@ var server = async (ctx) => {
|
|
|
12081
12339
|
try {
|
|
12082
12340
|
magicContextRuntime.magicContext?.disposeRustAdapter?.();
|
|
12083
12341
|
} catch {}
|
|
12084
|
-
|
|
12342
|
+
log2("[magic-context] instance disposed — stopped RPC server, dream timer, auto-update, Rust replay registration");
|
|
12085
12343
|
}
|
|
12086
12344
|
}),
|
|
12087
12345
|
"chat.params": async (input, output) => {
|
|
@@ -12092,25 +12350,13 @@ var server = async (ctx) => {
|
|
|
12092
12350
|
getMagicContext: () => magicContextRuntime.magicContext,
|
|
12093
12351
|
failClosed,
|
|
12094
12352
|
failClosedBlockingEnabled,
|
|
12095
|
-
checkoutClaim: checkoutClaimGate ? {
|
|
12096
|
-
gate: checkoutClaimGate,
|
|
12097
|
-
projectRoot: ctx.directory,
|
|
12098
|
-
onRefusal: async (sessionId, message) => {
|
|
12099
|
-
const { sendStatusNotification } = await importPluginModule(() => import("./send-session-notification-0m68ms3n.js"));
|
|
12100
|
-
const { abortSessionFailClosed } = await importPluginModule(() => import("./transform-postprocess-phase-z5hzpsxv.js"));
|
|
12101
|
-
await sendStatusNotification(ctx.client, sessionId, message, {
|
|
12102
|
-
toastDurationMs: 15000
|
|
12103
|
-
});
|
|
12104
|
-
await abortSessionFailClosed(ctx.client, sessionId);
|
|
12105
|
-
}
|
|
12106
|
-
} : undefined,
|
|
12107
12353
|
compactionOff: !isCompactionEnabled(pluginConfig),
|
|
12108
12354
|
internalChildSessions: liveSessionState.internalChildSessions,
|
|
12109
12355
|
tryReopenStorage,
|
|
12110
12356
|
rustReplayParticipant: () => magicContextRuntime.magicContext?.getRustReplayParticipant?.() ?? null,
|
|
12111
12357
|
onStorageBusyRefusal: async (sessionId, message) => {
|
|
12112
|
-
const { sendStatusNotification } = await importPluginModule(() => import("./send-session-notification-
|
|
12113
|
-
const { abortSessionFailClosed } = await importPluginModule(() => import("./transform-postprocess-phase-
|
|
12358
|
+
const { sendStatusNotification } = await importPluginModule(() => import("./send-session-notification-erecz4y4.js"));
|
|
12359
|
+
const { abortSessionFailClosed } = await importPluginModule(() => import("./transform-postprocess-phase-spcy2qre.js"));
|
|
12114
12360
|
await sendStatusNotification(ctx.client, sessionId, message, {
|
|
12115
12361
|
toastDurationMs: 15000
|
|
12116
12362
|
});
|
|
@@ -12118,8 +12364,6 @@ var server = async (ctx) => {
|
|
|
12118
12364
|
}
|
|
12119
12365
|
}),
|
|
12120
12366
|
"experimental.chat.system.transform": async (input, output) => {
|
|
12121
|
-
if (await isCheckoutClaimRefused(input.sessionID))
|
|
12122
|
-
return;
|
|
12123
12367
|
await magicContextRuntime.magicContext?.["experimental.chat.system.transform"]?.(input, output);
|
|
12124
12368
|
},
|
|
12125
12369
|
"command.execute.before": async (input, output) => {
|
|
@@ -12132,8 +12376,6 @@ var server = async (ctx) => {
|
|
|
12132
12376
|
const modId = typed.model?.modelID;
|
|
12133
12377
|
const agent = typed.agent;
|
|
12134
12378
|
lastChatContext = provId && modId ? { providerID: provId, modelID: modId, agentName: agent || "default" } : null;
|
|
12135
|
-
if (await isCheckoutClaimRefused(input.sessionID))
|
|
12136
|
-
return;
|
|
12137
12379
|
await magicContextRuntime.magicContext?.["chat.message"]?.(input, output);
|
|
12138
12380
|
},
|
|
12139
12381
|
"tool.definition": async (input, output) => {
|
|
@@ -12209,7 +12451,7 @@ var server = async (ctx) => {
|
|
|
12209
12451
|
const internalAgentIds = registrations.map((registration) => registration.id);
|
|
12210
12452
|
for (const reg of registrations) {
|
|
12211
12453
|
if (typeof reg.prompt !== "string" || reg.prompt.length === 0) {
|
|
12212
|
-
|
|
12454
|
+
log2(`[magic-context] skipping hidden agent '${reg.id}' — prompt unavailable at config time (dir=${ctx.directory}); will re-register on a later complete pass`);
|
|
12213
12455
|
continue;
|
|
12214
12456
|
}
|
|
12215
12457
|
agentConfigRecord[reg.id] = buildHiddenAgentConfig(reg.prompt, reg.allowedTools, reg.maxSteps, reg.overrides, reg.id, reg.lockPermissions === true, reg.description);
|
|
@@ -12218,7 +12460,7 @@ var server = async (ctx) => {
|
|
|
12218
12460
|
config.agent = callerAgentConfig;
|
|
12219
12461
|
} catch (error) {
|
|
12220
12462
|
const e = error;
|
|
12221
|
-
|
|
12463
|
+
log2(`[magic-context] config hook failed (commands/agents NOT registered; transform still active): ${e?.message ?? error}`, e?.stack ? { stackHead: e.stack.split(`
|
|
12222
12464
|
`).slice(0, 6).join(`
|
|
12223
12465
|
`) } : undefined);
|
|
12224
12466
|
}
|