@cortexkit/opencode-magic-context 0.46.1 → 0.48.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agents/magic-context-prompt.d.ts +1 -1
- package/dist/agents/magic-context-prompt.d.ts.map +1 -1
- package/dist/{announcement-y35wzg2r.js → announcement-fp14dw0n.js} +3 -2
- package/dist/auto-search-worker.js +112 -0
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/live-run-config.d.ts.map +1 -1
- package/dist/config/migrate-config-location.d.ts.map +1 -1
- package/dist/config/mural-model-deprecation.d.ts +15 -0
- package/dist/config/mural-model-deprecation.d.ts.map +1 -0
- package/dist/config/project-security.d.ts +0 -3
- package/dist/config/project-security.d.ts.map +1 -1
- package/dist/config/schema/magic-context.d.ts +21 -9
- package/dist/config/schema/magic-context.d.ts.map +1 -1
- package/dist/{conflict-warning-hook-7fj2b9jw.js → conflict-warning-hook-w8cykrnf.js} +12 -9
- package/dist/{context-sh2m2vde.js → context-m0cy262m.js} +1785 -913
- package/dist/{derive-budgets-7nj7r1rv.js → derive-budgets-sg0xsq7s.js} +4 -3
- package/dist/embedding-activity-g1dhes6g.js +10 -0
- package/dist/embedding-backfill-9rcm1mfy.js +21 -0
- package/dist/embedding-cache-mgyr73ef.js +16 -0
- package/dist/embedding-worker.js +11 -9
- package/dist/features/magic-context/compaction-marker.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/evaluate-smart-notes.d.ts +1 -0
- package/dist/features/magic-context/dreamer/evaluate-smart-notes.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-config.d.ts +3 -3
- package/dist/features/magic-context/dreamer/task-config.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-executor.d.ts +1 -1
- package/dist/features/magic-context/dreamer/task-executor.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-gates.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-registry.d.ts +1 -0
- package/dist/features/magic-context/dreamer/task-registry.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/verify.d.ts.map +1 -1
- package/dist/features/magic-context/message-index-async.d.ts +16 -3
- package/dist/features/magic-context/message-index-async.d.ts.map +1 -1
- package/dist/features/magic-context/message-index-bounded.d.ts +17 -0
- package/dist/features/magic-context/message-index-bounded.d.ts.map +1 -0
- package/dist/features/magic-context/message-index.d.ts +7 -1
- package/dist/features/magic-context/message-index.d.ts.map +1 -1
- package/dist/features/magic-context/mural/render-trigger.d.ts +7 -4
- package/dist/features/magic-context/mural/render-trigger.d.ts.map +1 -1
- package/dist/features/magic-context/overflow-detection.d.ts +2 -0
- package/dist/features/magic-context/overflow-detection.d.ts.map +1 -1
- package/dist/features/magic-context/pi-content-decisions.d.ts +7 -1
- package/dist/features/magic-context/pi-content-decisions.d.ts.map +1 -1
- package/dist/features/magic-context/project-embedding-registry.d.ts +7 -0
- package/dist/features/magic-context/project-embedding-registry.d.ts.map +1 -1
- package/dist/features/magic-context/search.d.ts +31 -0
- package/dist/features/magic-context/search.d.ts.map +1 -1
- package/dist/features/magic-context/session-activity.d.ts.map +1 -1
- package/dist/features/magic-context/session-project-storage.d.ts +8 -2
- package/dist/features/magic-context/session-project-storage.d.ts.map +1 -1
- package/dist/features/magic-context/smart-notes/runner.d.ts +1 -0
- package/dist/features/magic-context/smart-notes/runner.d.ts.map +1 -1
- package/dist/features/magic-context/storage-db.d.ts.map +1 -1
- package/dist/features/magic-context/storage-historian-runs.d.ts +2 -5
- package/dist/features/magic-context/storage-historian-runs.d.ts.map +1 -1
- package/dist/features/magic-context/storage-meta-persisted.d.ts +12 -0
- package/dist/features/magic-context/storage-meta-persisted.d.ts.map +1 -1
- package/dist/features/magic-context/storage-meta-session.d.ts +6 -0
- package/dist/features/magic-context/storage-meta-session.d.ts.map +1 -1
- package/dist/features/magic-context/storage-tag-identity-revision.d.ts +30 -0
- package/dist/features/magic-context/storage-tag-identity-revision.d.ts.map +1 -0
- package/dist/features/magic-context/storage-tags.d.ts +148 -3
- package/dist/features/magic-context/storage-tags.d.ts.map +1 -1
- package/dist/features/magic-context/storage.d.ts +1 -0
- package/dist/features/magic-context/storage.d.ts.map +1 -1
- package/dist/features/magic-context/subagent-token-capture.d.ts.map +1 -1
- package/dist/features/magic-context/transform-decision-log.d.ts +4 -2
- package/dist/features/magic-context/transform-decision-log.d.ts.map +1 -1
- package/dist/harness-e4avh192.js +10 -0
- package/dist/hooks/magic-context/active-anthropic-turn.d.ts +10 -0
- package/dist/hooks/magic-context/active-anthropic-turn.d.ts.map +1 -0
- package/dist/hooks/magic-context/apply-operations.d.ts.map +1 -1
- package/dist/hooks/magic-context/auto-search-blocking.fixture.d.ts +2 -0
- package/dist/hooks/magic-context/auto-search-blocking.fixture.d.ts.map +1 -0
- package/dist/hooks/magic-context/auto-search-deadline.d.ts +7 -0
- package/dist/hooks/magic-context/auto-search-deadline.d.ts.map +1 -1
- package/dist/hooks/magic-context/auto-search-host-review.fixture.d.ts +3 -0
- package/dist/hooks/magic-context/auto-search-host-review.fixture.d.ts.map +1 -0
- package/dist/hooks/magic-context/auto-search-lock-review.fixture.d.ts +2 -0
- package/dist/hooks/magic-context/auto-search-lock-review.fixture.d.ts.map +1 -0
- package/dist/hooks/magic-context/auto-search-long-lock-review.fixture.d.ts +2 -0
- package/dist/hooks/magic-context/auto-search-long-lock-review.fixture.d.ts.map +1 -0
- package/dist/hooks/magic-context/auto-search-omp-host-review.fixture.d.ts +4 -0
- package/dist/hooks/magic-context/auto-search-omp-host-review.fixture.d.ts.map +1 -0
- package/dist/hooks/magic-context/auto-search-omp-loader.fixture.d.ts +3 -0
- package/dist/hooks/magic-context/auto-search-omp-loader.fixture.d.ts.map +1 -0
- package/dist/hooks/magic-context/auto-search-runner.d.ts +1 -1
- package/dist/hooks/magic-context/auto-search-runner.d.ts.map +1 -1
- package/dist/hooks/magic-context/auto-search-snapshot.fixture.d.ts +4 -0
- package/dist/hooks/magic-context/auto-search-snapshot.fixture.d.ts.map +1 -0
- package/dist/hooks/magic-context/auto-search-worker-client.d.ts +98 -0
- package/dist/hooks/magic-context/auto-search-worker-client.d.ts.map +1 -0
- package/dist/hooks/magic-context/auto-search-worker.d.ts +2 -0
- package/dist/hooks/magic-context/auto-search-worker.d.ts.map +1 -0
- package/dist/hooks/magic-context/caveman-cleanup.d.ts.map +1 -1
- package/dist/hooks/magic-context/command-handler.d.ts +1 -0
- package/dist/hooks/magic-context/command-handler.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-incremental.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-recomp.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-types.d.ts +3 -5
- package/dist/hooks/magic-context/compartment-runner-types.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner.d.ts +2 -1
- package/dist/hooks/magic-context/compartment-runner.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-trigger.d.ts +3 -1
- package/dist/hooks/magic-context/compartment-trigger.d.ts.map +1 -1
- package/dist/hooks/magic-context/event-handler.d.ts +1 -1
- package/dist/hooks/magic-context/event-handler.d.ts.map +1 -1
- package/dist/hooks/magic-context/event-resolvers.d.ts.map +1 -1
- package/dist/hooks/magic-context/execute-status.d.ts.map +1 -1
- package/dist/hooks/magic-context/final-wire-token-estimate.d.ts +2 -0
- package/dist/hooks/magic-context/final-wire-token-estimate.d.ts.map +1 -1
- package/dist/hooks/magic-context/heuristic-cleanup.d.ts.map +1 -1
- package/dist/hooks/magic-context/historian-drain-gate.d.ts +11 -0
- package/dist/hooks/magic-context/historian-drain-gate.d.ts.map +1 -0
- package/dist/hooks/magic-context/hook.d.ts +3 -2
- package/dist/hooks/magic-context/hook.d.ts.map +1 -1
- package/dist/hooks/magic-context/inject-compartments.d.ts.map +1 -1
- package/dist/hooks/magic-context/latest-assistant-turn.d.ts +25 -0
- package/dist/hooks/magic-context/latest-assistant-turn.d.ts.map +1 -0
- package/dist/hooks/magic-context/latest-thinking-recovery.d.ts +61 -0
- package/dist/hooks/magic-context/latest-thinking-recovery.d.ts.map +1 -0
- package/dist/hooks/magic-context/lkg-persist.d.ts +4 -3
- package/dist/hooks/magic-context/lkg-persist.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-replay.d.ts +13 -8
- package/dist/hooks/magic-context/lkg-replay.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-slot.d.ts +139 -2
- package/dist/hooks/magic-context/lkg-slot.d.ts.map +1 -1
- package/dist/hooks/magic-context/message-search-accepting-silent-worker.fixture.d.ts +2 -0
- package/dist/hooks/magic-context/message-search-accepting-silent-worker.fixture.d.ts.map +1 -0
- package/dist/hooks/magic-context/module-wire.d.ts.map +1 -1
- package/dist/hooks/magic-context/oc-stall-r2-warmup-worker.fixture.d.ts +2 -0
- package/dist/hooks/magic-context/oc-stall-r2-warmup-worker.fixture.d.ts.map +1 -0
- package/dist/hooks/magic-context/oc-stall-search-review.fixture.d.ts +2 -0
- package/dist/hooks/magic-context/oc-stall-search-review.fixture.d.ts.map +1 -0
- package/dist/hooks/magic-context/opencode-proven-floor.d.ts +6 -0
- package/dist/hooks/magic-context/opencode-proven-floor.d.ts.map +1 -0
- package/dist/hooks/magic-context/opencode1-to-model-messages.fixture.d.ts +63 -0
- package/dist/hooks/magic-context/opencode1-to-model-messages.fixture.d.ts.map +1 -0
- package/dist/hooks/magic-context/pass-outcome.d.ts.map +1 -1
- package/dist/hooks/magic-context/protected-tail-boundary.d.ts.map +1 -1
- package/dist/hooks/magic-context/provider-visible-parts.d.ts +45 -0
- package/dist/hooks/magic-context/provider-visible-parts.d.ts.map +1 -0
- package/dist/hooks/magic-context/raw-ordinal-warmup-silent-worker.fixture.d.ts +2 -0
- package/dist/hooks/magic-context/raw-ordinal-warmup-silent-worker.fixture.d.ts.map +1 -0
- package/dist/hooks/magic-context/raw-ordinal-warmup-worker.d.ts +2 -0
- package/dist/hooks/magic-context/raw-ordinal-warmup-worker.d.ts.map +1 -0
- package/dist/hooks/magic-context/raw-ordinal-warmup.d.ts +87 -0
- package/dist/hooks/magic-context/raw-ordinal-warmup.d.ts.map +1 -0
- package/dist/hooks/magic-context/read-session-chunk.d.ts +12 -0
- package/dist/hooks/magic-context/read-session-chunk.d.ts.map +1 -1
- package/dist/hooks/magic-context/read-session-db.d.ts.map +1 -1
- package/dist/hooks/magic-context/read-session-formatting.d.ts +5 -0
- package/dist/hooks/magic-context/read-session-formatting.d.ts.map +1 -1
- package/dist/hooks/magic-context/read-session-raw.d.ts +83 -1
- package/dist/hooks/magic-context/read-session-raw.d.ts.map +1 -1
- package/dist/hooks/magic-context/read-session-true-raw-tokens.d.ts.map +1 -1
- package/dist/hooks/magic-context/reasoning-budget-status.d.ts +15 -0
- package/dist/hooks/magic-context/reasoning-budget-status.d.ts.map +1 -0
- package/dist/hooks/magic-context/reasoning-budget.d.ts +40 -0
- package/dist/hooks/magic-context/reasoning-budget.d.ts.map +1 -0
- package/dist/hooks/magic-context/reasoning-removal.d.ts +6 -6
- package/dist/hooks/magic-context/reasoning-removal.d.ts.map +1 -1
- package/dist/hooks/magic-context/rust-mode-transform.d.ts.map +1 -1
- package/dist/hooks/magic-context/sentinel.d.ts +45 -1
- package/dist/hooks/magic-context/sentinel.d.ts.map +1 -1
- package/dist/hooks/magic-context/strip-content.d.ts +21 -5
- package/dist/hooks/magic-context/strip-content.d.ts.map +1 -1
- package/dist/hooks/magic-context/system-prompt-hash.d.ts +1 -0
- package/dist/hooks/magic-context/system-prompt-hash.d.ts.map +1 -1
- package/dist/hooks/magic-context/tag-messages.d.ts +21 -0
- package/dist/hooks/magic-context/tag-messages.d.ts.map +1 -1
- package/dist/hooks/magic-context/tag-owner-warmup.d.ts +6 -0
- package/dist/hooks/magic-context/tag-owner-warmup.d.ts.map +1 -0
- package/dist/hooks/magic-context/tail-hygiene-walk.d.ts.map +1 -1
- package/dist/hooks/magic-context/token-count-exact.d.ts +35 -0
- package/dist/hooks/magic-context/token-count-exact.d.ts.map +1 -0
- package/dist/hooks/magic-context/tool-drop-target.d.ts +5 -0
- package/dist/hooks/magic-context/tool-drop-target.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-compartment-phase.d.ts +3 -28
- package/dist/hooks/magic-context/transform-compartment-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +28 -6
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform.d.ts +11 -3
- package/dist/hooks/magic-context/transform.d.ts.map +1 -1
- package/dist/hooks/magic-context/wrapup-orchestrator.d.ts.map +1 -1
- package/dist/{index-hpecdzec.js → index-0an7742d.js} +6820 -6587
- package/dist/index-0qhce371.js +120 -0
- package/dist/{index-q6hef7fh.js → index-0sahzkwr.js} +6 -19
- package/dist/{index-k5bdx1bx.js → index-0w56v4fm.js} +3 -5
- package/dist/index-14cjxt20.js +819 -0
- package/dist/{v2/server-51dv1pr5.js → index-1qb0z7wa.js} +301 -27
- package/dist/index-2bvekkfy.js +11 -0
- package/dist/{index-sj29b3z2.js → index-2y0s2hep.js} +3 -3
- package/dist/index-4dhv7mqz.js +131 -0
- package/dist/{index-b35pxds2.js → index-58e3y90n.js} +1 -18
- package/dist/index-5zygecde.js +152 -0
- package/dist/{index-sjthx78w.js → index-692jzy0p.js} +16879 -22907
- package/dist/index-72nhv486.js +2307 -0
- package/dist/index-7jzrrxap.js +931 -0
- package/dist/index-7mx8v0pw.js +3591 -0
- package/dist/index-8ajstryz.js +18 -0
- package/dist/{index-sfpzqvdz.js → index-8cd2j99z.js} +2 -3
- package/dist/{index-hybnrwq0.js → index-8j7gqj40.js} +131 -128
- package/dist/index-bdckkfw6.js +3261 -0
- package/dist/{index-8x2v7gg9.js → index-bhvjj0ys.js} +158 -2455
- package/dist/index-c43kr12f.js +3030 -0
- package/dist/index-cb7emxgj.js +984 -0
- package/dist/index-d9vfe7xq.js +16 -0
- package/dist/{index-5gq3b2ya.js → index-db7zwa3v.js} +147 -209
- package/dist/index-dhwzyd54.js +1142 -0
- package/dist/{index-8da2zjhz.js → index-eeezr5zz.js} +9 -7
- package/dist/{index-pkbcrdqs.js → index-f0h6xwqm.js} +3412 -4552
- package/dist/index-fb3zxn06.js +13 -0
- package/dist/index-fbv1dn35.js +171 -0
- package/dist/index-fr0wbhdn.js +43 -0
- package/dist/{index-mc22ayvf.js → index-ghc9f0n7.js} +11 -9
- package/dist/{index-fzbvakh0.js → index-jcbd3znx.js} +3 -3
- package/dist/{index-5p8jdswx.js → index-k1xb52kd.js} +20 -13
- package/dist/index-k9nnwad5.js +3532 -0
- package/dist/{v2/server-fg34g6a5.js → index-kb9nn0a0.js} +309 -52
- package/dist/index-knh4y330.js +566 -0
- package/dist/{index-q4yp4b52.js → index-mfkzp7qj.js} +28 -28
- package/dist/{index-sgthv3f7.js → index-mmyh6d8f.js} +4 -4
- package/dist/index-pavzsdc6.js +17 -0
- package/dist/{index-0d3g3461.js → index-pdecwzrd.js} +19 -16
- package/dist/index-pg50n748.js +1060 -0
- package/dist/index-q2tqeqde.js +2106 -0
- package/dist/index-q7h7csab.js +3469 -0
- package/dist/index-qt1qqasc.js +22 -0
- package/dist/{index-majxda46.js → index-ty64eqcn.js} +28 -18
- package/dist/{index-7qw742ev.js → index-yq8n9qcb.js} +25 -44
- package/dist/{index-sfnj6h8h.js → index-z8e0psj8.js} +20 -20
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1061 -260
- package/dist/logger-d3wex3dz.js +20 -0
- package/dist/message-index-bounded-7ezbgddp.js +124 -0
- package/dist/{v2/message-time-backfill-r6qkem1x.js → message-time-backfill-brbd63hv.js} +8 -6
- package/dist/migration-worker.js +25 -16
- package/dist/{model-resolution-xhfmyyvy.js → model-resolution-nx97z3x7.js} +1 -1
- package/dist/plugin/dream-timer.d.ts +1 -1
- package/dist/plugin/dream-timer.d.ts.map +1 -1
- package/dist/plugin/hooks/create-session-hooks.d.ts +3 -1
- package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
- package/dist/plugin/host-stall-profiler-report.d.ts +2 -0
- package/dist/plugin/host-stall-profiler-report.d.ts.map +1 -0
- package/dist/plugin/host-stall-profiler.d.ts +3 -0
- package/dist/plugin/host-stall-profiler.d.ts.map +1 -0
- package/dist/plugin/messages-transform.d.ts +21 -19
- package/dist/plugin/messages-transform.d.ts.map +1 -1
- package/dist/plugin/rpc-handlers.d.ts.map +1 -1
- package/dist/plugin/tool-registry.d.ts.map +1 -1
- package/dist/project-embedding-registry-7qzptcw7.js +88 -0
- package/dist/raw-ordinal-warmup-worker.js +60 -0
- package/dist/{read-session-chunk-egz7r68d.js → read-session-chunk-6k83m4fj.js} +15 -9
- package/dist/read-session-raw-3g9qy1xa.js +58 -0
- package/dist/recomp-orchestrator-d3fp1cy0.js +57 -0
- package/dist/{v2/safe-notification-target-eb1n1vfb.js → safe-notification-target-5ffqq32m.js} +4 -2
- package/dist/search-epax1ecv.js +45 -0
- package/dist/{v2/send-session-notification-qs0j78v6.js → send-session-notification-erecz4y4.js} +10 -6
- package/dist/shared/auto-search-lifecycle.d.ts +7 -0
- package/dist/shared/auto-search-lifecycle.d.ts.map +1 -0
- package/dist/shared/conflict-detector.d.ts.map +1 -1
- package/dist/shared/historian-tool-expansions.d.ts +1 -1
- package/dist/shared/historian-tool-expansions.d.ts.map +1 -1
- package/dist/shared/historian-tool-template.d.ts +2 -2
- package/dist/shared/historian-tool-template.d.ts.map +1 -1
- package/dist/shared/host-stall-profiler-bun.d.ts +46 -0
- package/dist/shared/host-stall-profiler-bun.d.ts.map +1 -0
- package/dist/shared/host-stall-profiler-common.d.ts +58 -0
- package/dist/shared/host-stall-profiler-common.d.ts.map +1 -0
- package/dist/shared/host-stall-profiler-node.d.ts +36 -0
- package/dist/shared/host-stall-profiler-node.d.ts.map +1 -0
- package/dist/shared/host-stall-profiler-report.d.ts +68 -0
- package/dist/shared/host-stall-profiler-report.d.ts.map +1 -0
- package/dist/shared/host-stall-profiler.d.ts +5 -0
- package/dist/shared/host-stall-profiler.d.ts.map +1 -0
- package/dist/shared/model-resolution.d.ts +2 -3
- package/dist/shared/model-resolution.d.ts.map +1 -1
- package/dist/shared/sqlite.d.ts +46 -1
- package/dist/shared/sqlite.d.ts.map +1 -1
- package/dist/shared/stable-json.d.ts.map +1 -1
- package/dist/shared/status-view.d.ts.map +1 -1
- package/dist/shared/user-facing-codes.d.ts +0 -5
- package/dist/shared/user-facing-codes.d.ts.map +1 -1
- package/dist/shared/window-geometry.d.ts +4 -0
- package/dist/shared/window-geometry.d.ts.map +1 -1
- package/dist/sqlite-context-pragmas-mv9jqwjh.js +6 -0
- package/dist/sqlite-mhjkerzq.js +46 -0
- package/dist/storage-memory-07fx57k6.js +71 -0
- package/dist/storage-tags-d3b0v2ss.js +131 -0
- package/dist/{task-config-v81k8jvk.js → task-config-cgpg0nvh.js} +2 -2
- package/dist/tools/ctx-expand/render.d.ts.map +1 -1
- package/dist/tools/ctx-expand/tools.d.ts.map +1 -1
- package/dist/tools/ctx-note/constants.d.ts +4 -0
- package/dist/tools/ctx-note/constants.d.ts.map +1 -1
- package/dist/tools/ctx-note/tools.d.ts +1 -0
- package/dist/tools/ctx-note/tools.d.ts.map +1 -1
- package/dist/tools/ctx-search/tools.d.ts.map +1 -1
- package/dist/tools/parameter-descriptions.d.ts +2 -2
- package/dist/tools/parameter-descriptions.d.ts.map +1 -1
- package/dist/{transform-postprocess-phase-bqhz6vdr.js → transform-postprocess-phase-spcy2qre.js} +35 -17
- package/dist/transformers-node-wasm.js +18415 -18415
- package/dist/v2/auto-search-worker.js +112 -0
- package/dist/v2/{context-zecmzk5s.js → context-sf98kstd.js} +8378 -8530
- package/dist/v2/{derive-budgets-kdgp4s3r.js → derive-budgets-3vc0y84t.js} +4 -3
- package/dist/v2/embedding-activity-g1dhes6g.js +10 -0
- package/dist/v2/embedding-backfill-vn8g1nh1.js +21 -0
- package/dist/v2/embedding-cache-mgyr73ef.js +16 -0
- package/dist/v2/embedding-worker.js +12 -9
- package/dist/v2/fold/host-media.d.ts +4 -0
- package/dist/v2/fold/host-media.d.ts.map +1 -1
- package/dist/v2/fold/memory-cache.d.ts +70 -0
- package/dist/v2/fold/memory-cache.d.ts.map +1 -0
- package/dist/v2/fold/native-codec.d.ts +10 -0
- package/dist/v2/fold/native-codec.d.ts.map +1 -0
- package/dist/v2/fold/native-replay.d.ts +58 -0
- package/dist/v2/fold/native-replay.d.ts.map +1 -0
- package/dist/v2/fold/policy.d.ts +24 -0
- package/dist/v2/fold/policy.d.ts.map +1 -0
- package/dist/v2/harness-e4avh192.js +10 -0
- package/dist/v2/hidden-completion.d.ts.map +1 -1
- package/dist/v2/hooks/context.d.ts +2 -2
- package/dist/v2/hooks/context.d.ts.map +1 -1
- package/dist/v2/hooks/dream-manual.d.ts +1 -1
- package/dist/v2/hooks/dream-manual.d.ts.map +1 -1
- package/dist/v2/hooks/dream-timer.d.ts.map +1 -1
- package/dist/v2/hooks/dream-trigger.d.ts +1 -2
- package/dist/v2/hooks/dream-trigger.d.ts.map +1 -1
- package/dist/v2/hooks/payload.d.ts.map +1 -1
- package/dist/v2/hooks/tools.d.ts.map +1 -1
- package/dist/v2/hooks/types.d.ts +6 -0
- package/dist/v2/hooks/types.d.ts.map +1 -1
- package/dist/v2/logger-mxd0ym09.js +19 -0
- package/dist/v2/message-index-bounded-dy3s2k1e.js +123 -0
- package/dist/{message-time-backfill-68gj6t3e.js → v2/message-time-backfill-gtx1pwk1.js} +7 -7
- package/dist/v2/migration-worker.js +24 -15
- package/dist/v2/{model-resolution-xhfmyyvy.js → model-resolution-nx97z3x7.js} +1 -1
- package/dist/v2/project-embedding-registry-1tgba5dv.js +86 -0
- package/dist/v2/raw-ordinal-warmup-worker.js +60 -0
- package/dist/v2/{read-session-chunk-8vjp6581.js → read-session-chunk-rh4khdkv.js} +14 -8
- package/dist/v2/read-session-raw-bsbmf0vj.js +57 -0
- package/dist/v2/recomp-orchestrator-az61rfcg.js +57 -0
- package/dist/{safe-notification-target-43r8jsxw.js → v2/safe-notification-target-73ax1p5v.js} +3 -3
- package/dist/v2/search-nzkwrc6n.js +45 -0
- package/dist/{send-session-notification-dyw42dtr.js → v2/send-session-notification-6km439kn.js} +9 -7
- package/dist/{index-5eqk6z3s.js → v2/server-1r6pmz4f.js} +301 -27
- package/dist/v2/server-2bvekkfy.js +11 -0
- package/dist/v2/server-2fbhp79z.js +3205 -0
- package/dist/v2/{server-ajzeteqw.js → server-2ra6pwf3.js} +1 -18
- package/dist/v2/server-4dhv7mqz.js +131 -0
- package/dist/v2/{server-xa4xe3rv.js → server-4k748ke6.js} +11 -1053
- package/dist/v2/{server-vs5gpnd4.js → server-52awr2mw.js} +81 -145
- package/dist/v2/{server-1qbnzc80.js → server-5m3dt5r1.js} +136 -148
- package/dist/v2/server-686jg6eb.js +3508 -0
- package/dist/v2/server-7jzrrxap.js +931 -0
- package/dist/v2/server-7wwc2nga.js +3023 -0
- package/dist/v2/server-8ajstryz.js +18 -0
- package/dist/v2/{server-sfpzqvdz.js → server-8cd2j99z.js} +2 -3
- package/dist/v2/server-8pyt7hev.js +3408 -0
- package/dist/v2/server-8tqanswc.js +984 -0
- package/dist/v2/{server-14vq4kpm.js → server-aan4q8mx.js} +3 -3
- package/dist/v2/server-d9vfe7xq.js +16 -0
- package/dist/v2/server-e0vdaae2.js +3591 -0
- package/dist/v2/server-ezhze64f.js +1048 -0
- package/dist/v2/server-fb3zxn06.js +13 -0
- package/dist/v2/server-fr0wbhdn.js +43 -0
- package/dist/v2/server-g5r0n3b6.js +1137 -0
- package/dist/v2/server-gjcr4w98.js +154 -0
- package/dist/v2/server-k228xhjg.js +171 -0
- package/dist/v2/{server-jc7y02q0.js → server-k8x2rbxc.js} +5119 -10948
- package/dist/{index-fg34g6a5.js → v2/server-kb9nn0a0.js} +309 -52
- package/dist/v2/{server-g0fjrkta.js → server-mfkzp7qj.js} +28 -28
- package/dist/v2/server-pavzsdc6.js +17 -0
- package/dist/v2/server-psqc7e9n.js +2106 -0
- package/dist/v2/server-qt1qqasc.js +22 -0
- package/dist/v2/server-qye6ykf7.js +120 -0
- package/dist/v2/{server-qdjnb2z1.js → server-r5p3b1wy.js} +11 -9
- package/dist/v2/server-sggvvzhb.js +759 -0
- package/dist/v2/{server-y8maxeft.js → server-v06jcv0w.js} +16 -13
- package/dist/v2/server-vqpf3167.js +1048 -0
- package/dist/v2/{server-c5gz8wph.js → server-x2g40a71.js} +2048 -2059
- package/dist/v2/{server-wvjvfhck.js → server-xdfwt6kh.js} +20 -16
- package/dist/v2/{server-mcfawjgc.js → server-xxm59eww.js} +25 -44
- package/dist/v2/server-yczc713m.js +564 -0
- package/dist/v2/{server-3n4q9xme.js → server-z2037m6z.js} +4 -4
- package/dist/v2/{server-e29d7p7c.js → server-zm570tr2.js} +166 -160
- package/dist/v2/{server-6r257mf5.js → server-zxhgvsf9.js} +3 -3
- package/dist/v2/server.js +16 -14
- package/dist/v2/sqlite-context-pragmas-mv9jqwjh.js +6 -0
- package/dist/v2/sqlite-mhjkerzq.js +46 -0
- package/dist/v2/storage-memory-07fx57k6.js +71 -0
- package/dist/v2/storage-tags-w4tv77sn.js +130 -0
- package/dist/v2/store-reader.d.ts +16 -0
- package/dist/v2/store-reader.d.ts.map +1 -1
- package/dist/v2/{task-config-tbndqyny.js → task-config-x0hq3qfd.js} +2 -2
- package/dist/v2/transformers-node-wasm.js +18415 -18415
- package/dist/v2/tui/index.d.ts.map +1 -1
- package/dist/v2/tui/types.d.ts +1 -10
- package/dist/v2/tui/types.d.ts.map +1 -1
- package/dist/v2/{wrapup-orchestrator-0snhvwcv.js → wrapup-orchestrator-mz7efs7w.js} +51 -27
- package/dist/wrapup-orchestrator-amzta1t4.js +44 -0
- package/package.json +4 -3
- package/src/agents/magic-context-prompt.ts +27 -2
- package/src/agents/smart-notes-enabled.test.ts +294 -0
- package/src/agents/smart-notes-on.golden.json +70 -0
- package/src/config/index.test.ts +67 -1
- package/src/config/index.ts +8 -0
- package/src/config/latch-permanence-guard.test.ts +4 -0
- package/src/config/live-run-config.test.ts +37 -1
- package/src/config/live-run-config.ts +28 -0
- package/src/config/migrate-config-location.ts +10 -3
- package/src/config/mural-model-deprecation.ts +24 -0
- package/src/config/project-security.hostile-matrix.test.ts +4 -44
- package/src/config/project-security.test.ts +9 -14
- package/src/config/project-security.ts +13 -55
- package/src/config/schema/magic-context.test.ts +6 -5
- package/src/config/schema/magic-context.ts +34 -16
- package/src/features/magic-context/dreamer/task-registry.ts +6 -0
- package/src/shared/auto-search-lifecycle.ts +27 -0
- package/src/shared/conflict-detector.test.ts +56 -0
- package/src/shared/conflict-detector.ts +16 -5
- package/src/shared/historian-tool-defaults.json +6 -6
- package/src/shared/historian-tool-expansions.ts +65 -8
- package/src/shared/historian-tool-preview-defaults.json +13 -0
- package/src/shared/historian-tool-template.ts +48 -14
- package/src/shared/host-stall-profiler-bun.ts +358 -0
- package/src/shared/host-stall-profiler-common.ts +159 -0
- package/src/shared/host-stall-profiler-node.test.ts +234 -0
- package/src/shared/host-stall-profiler-node.ts +274 -0
- package/src/shared/host-stall-profiler-report.ts +248 -0
- package/src/shared/host-stall-profiler.ts +57 -0
- package/src/shared/model-resolution.test.ts +54 -17
- package/src/shared/model-resolution.ts +6 -17
- package/src/shared/sqlite-640-review-r2.test.ts +136 -0
- package/src/shared/sqlite-640-review.test.ts +183 -0
- package/src/shared/sqlite-acquisition-routing.test.ts +18 -0
- package/src/shared/sqlite.test.ts +52 -0
- package/src/shared/sqlite.ts +423 -37
- package/src/shared/stable-json-linear.test.ts +109 -0
- package/src/shared/stable-json.ts +37 -7
- package/src/shared/status-view.test.ts +6 -1
- package/src/shared/status-view.ts +15 -1
- package/src/shared/tag-transcript.ts +6 -0
- package/src/shared/user-facing-codes.ts +2 -6
- package/src/shared/window-geometry.ts +10 -0
- package/src/shared/write-transaction-attribution.test.ts +2 -2
- package/src/v2/tui/host-contract.test.ts +41 -67
- package/src/v2/tui/index.ts +6 -214
- package/src/v2/tui/types.ts +5 -17
- package/dist/features/magic-context/checkout-claim-fake-subc.test-support.d.ts +0 -45
- package/dist/features/magic-context/checkout-claim-fake-subc.test-support.d.ts.map +0 -1
- package/dist/features/magic-context/checkout-claim.d.ts +0 -155
- package/dist/features/magic-context/checkout-claim.d.ts.map +0 -1
- package/dist/index-3h0ybwah.js +0 -6540
- package/dist/index-r5hmbx3t.js +0 -7773
- package/dist/recomp-orchestrator-y15j0rb9.js +0 -39
- package/dist/v2/recomp-orchestrator-8ejxvrzz.js +0 -39
- package/dist/v2/server-frbm99q5.js +0 -7698
- package/dist/v2/server-qp5hx1ad.js +0 -6366
- package/dist/wrapup-orchestrator-39amhv9s.js +0 -26
- /package/dist/{index-en1k8h8m.js → index-2pp04pmg.js} +0 -0
- /package/dist/v2/{index-en1k8h8m.js → index-2pp04pmg.js} +0 -0
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,
|
|
@@ -40,9 +42,6 @@ import {
|
|
|
40
42
|
dreamerRunConfig,
|
|
41
43
|
pluginConfigReader,
|
|
42
44
|
createDreamerOutputCapSampler,
|
|
43
|
-
observeSessionActivity,
|
|
44
|
-
backfillSessionActivity,
|
|
45
|
-
recordSessionProjectIdentity,
|
|
46
45
|
COMPARTMENT_AGENT_SYSTEM_PROMPT,
|
|
47
46
|
HISTORIAN_EDITOR_SYSTEM_PROMPT,
|
|
48
47
|
COMPARTMENT_STRUCTURAL_SYSTEM_PROMPT,
|
|
@@ -52,7 +51,6 @@ import {
|
|
|
52
51
|
invalidateAutoEmbedSession,
|
|
53
52
|
getEmbedDrainUiStatus,
|
|
54
53
|
clearEmbedSessionState,
|
|
55
|
-
deleteIndexedMessage,
|
|
56
54
|
getProtectionWindowForSession,
|
|
57
55
|
getPersistedReasoningWatermark,
|
|
58
56
|
setPersistedReasoningWatermark,
|
|
@@ -68,7 +66,6 @@ import {
|
|
|
68
66
|
clearDetectedContextLimit,
|
|
69
67
|
getPersistedCompactionMarkerState,
|
|
70
68
|
removeStrippedPlaceholderId,
|
|
71
|
-
armThinkingBindingRecovery,
|
|
72
69
|
getPendingCompactionMarkerState,
|
|
73
70
|
clearPendingCompactionMarkerStateIf,
|
|
74
71
|
getSessionsWithPendingMarker,
|
|
@@ -84,16 +81,14 @@ import {
|
|
|
84
81
|
markSessionCleanupPending,
|
|
85
82
|
clearSession,
|
|
86
83
|
recordPromptSessionError,
|
|
84
|
+
CTX_NOTE_LIGHT_DESCRIPTION,
|
|
87
85
|
createPromptSurfaceRuntime,
|
|
88
86
|
setKeepSubagents,
|
|
89
|
-
getProjectEmbeddingSnapshot,
|
|
90
|
-
getEmbeddingCoverageStatus,
|
|
91
|
-
getAutoEmbeddingSessionCoverage,
|
|
92
87
|
removeCompactionMarkerForSession,
|
|
93
88
|
checkCompactionMarkerConsistency,
|
|
94
89
|
clearInjectionCache,
|
|
95
90
|
clearNoteNudgeTriggerOnly
|
|
96
|
-
} from "./index-
|
|
91
|
+
} from "./index-692jzy0p.js";
|
|
97
92
|
import"./index-sd3egckz.js";
|
|
98
93
|
import {
|
|
99
94
|
reloadWindowOverlay,
|
|
@@ -104,19 +99,16 @@ import {
|
|
|
104
99
|
deriveHistorianChunkTokens2,
|
|
105
100
|
resolveKnownHistorianContextLimit2,
|
|
106
101
|
resolveHistorianContextLimit2
|
|
107
|
-
} from "./index-
|
|
108
|
-
import"./index-
|
|
102
|
+
} from "./index-pdecwzrd.js";
|
|
103
|
+
import"./index-mfkzp7qj.js";
|
|
109
104
|
import {
|
|
110
105
|
resolveOpenCodeDbPath,
|
|
111
106
|
openCodeDbPathExists,
|
|
112
107
|
formatOpenCodeDbMissingBanner,
|
|
113
|
-
claimOpenCodeDbDiagnosticOnce
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
import"./index-fg34g6a5.js";
|
|
108
|
+
claimOpenCodeDbDiagnosticOnce
|
|
109
|
+
} from "./index-58e3y90n.js";
|
|
110
|
+
import"./index-kb9nn0a0.js";
|
|
117
111
|
import {
|
|
118
|
-
createSubcCheckoutClaimGate,
|
|
119
|
-
openCodeEventSessionId,
|
|
120
112
|
openOpenCodeDb,
|
|
121
113
|
DREAMER_SYSTEM_PROMPT,
|
|
122
114
|
runSessionProjectBackfill,
|
|
@@ -131,6 +123,8 @@ import {
|
|
|
131
123
|
createDbLkgPersistence,
|
|
132
124
|
startDreamScheduleTimer,
|
|
133
125
|
ensureProjectRegisteredFromOpenCodeDirectory,
|
|
126
|
+
recordOpenCodeProvenInputFloor,
|
|
127
|
+
resolveOpenCodeProvenInputFloor,
|
|
134
128
|
resolveContextWindowGeometry,
|
|
135
129
|
resolveContextLimit,
|
|
136
130
|
resolveExecuteThresholdDetail,
|
|
@@ -161,6 +155,8 @@ import {
|
|
|
161
155
|
clearTransformDecisionSession,
|
|
162
156
|
scheduleOpenCodeTransformDecisionWrite,
|
|
163
157
|
maybeDeliverChannel2,
|
|
158
|
+
armLatestThinkingRecovery,
|
|
159
|
+
armBindingRecoverySafely,
|
|
164
160
|
clearMessageTokensCache,
|
|
165
161
|
createTransform,
|
|
166
162
|
createSubcModuleClient,
|
|
@@ -175,27 +171,19 @@ import {
|
|
|
175
171
|
CTX_MEMORY_ACTIONS,
|
|
176
172
|
createCtxMemoryTools,
|
|
177
173
|
createCtxMemoryListTools,
|
|
174
|
+
withoutSmartNoteText,
|
|
178
175
|
createCtxNoteTools,
|
|
179
176
|
createCtxReduceTools,
|
|
180
177
|
createCtxSearchTools,
|
|
181
178
|
parameterDescriptionsFor,
|
|
182
179
|
MagicContextRpcServer
|
|
183
|
-
} from "./index-
|
|
180
|
+
} from "./index-0an7742d.js";
|
|
184
181
|
import {
|
|
185
182
|
formatFailClosedBlockingMessage,
|
|
186
183
|
createFailClosedController,
|
|
187
184
|
recordHookInitFailure,
|
|
188
185
|
clearHookInitFailure,
|
|
189
186
|
getLastHookInitFailure,
|
|
190
|
-
setHomeProjectPermission,
|
|
191
|
-
ProjectIdentityError,
|
|
192
|
-
resolveProjectIdentityStrict,
|
|
193
|
-
takeDubiousOwnershipProjectIdentityWarning,
|
|
194
|
-
resolveProjectIdentity,
|
|
195
|
-
resolveProjectIdentityForSession,
|
|
196
|
-
beginBootQuietPeriod,
|
|
197
|
-
bootQuietRemainingMs,
|
|
198
|
-
scheduleAfterBootQuiet,
|
|
199
187
|
startBootDeadline,
|
|
200
188
|
getSchemaFenceRejection,
|
|
201
189
|
setSqlitePragmaConfig,
|
|
@@ -204,77 +192,123 @@ import {
|
|
|
204
192
|
openDatabaseAsync,
|
|
205
193
|
isDatabasePersisted,
|
|
206
194
|
getDatabasePersistenceError
|
|
207
|
-
} from "./index-
|
|
195
|
+
} from "./index-q7h7csab.js";
|
|
208
196
|
import {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
197
|
+
setHomeProjectPermission,
|
|
198
|
+
ProjectIdentityError,
|
|
199
|
+
resolveProjectIdentityStrict,
|
|
200
|
+
takeDubiousOwnershipProjectIdentityWarning,
|
|
201
|
+
resolveProjectIdentity,
|
|
202
|
+
resolveProjectIdentityForSession,
|
|
203
|
+
beginBootQuietPeriod,
|
|
204
|
+
bootQuietRemainingMs,
|
|
205
|
+
scheduleAfterBootQuiet
|
|
206
|
+
} from "./index-knh4y330.js";
|
|
207
|
+
import {
|
|
208
|
+
deleteTemporalDecision
|
|
209
|
+
} from "./index-db7zwa3v.js";
|
|
210
|
+
import {
|
|
211
|
+
observeSessionActivity,
|
|
212
|
+
backfillSessionActivity,
|
|
213
|
+
deleteIndexedMessage
|
|
214
|
+
} from "./index-14cjxt20.js";
|
|
215
|
+
import {
|
|
216
|
+
recordSessionProjectIdentity,
|
|
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";
|
|
213
225
|
import {
|
|
214
226
|
preloadTokenizer
|
|
215
|
-
} from "./index-
|
|
227
|
+
} from "./index-1qb0z7wa.js";
|
|
228
|
+
import {
|
|
229
|
+
getCurrentToolSetHash,
|
|
230
|
+
recordToolDefinition
|
|
231
|
+
} from "./index-0qhce371.js";
|
|
216
232
|
import {
|
|
217
|
-
stripPersistedAssistantText,
|
|
218
|
-
deleteTagsByMessageId,
|
|
219
|
-
getMaxTagNumberBySession,
|
|
220
233
|
invalidateTrueRawTokenCache,
|
|
221
234
|
recordToolParameters,
|
|
222
235
|
createDroppedInputToolExecuteBeforeHook,
|
|
223
236
|
detectThinkingBindingMismatch,
|
|
237
|
+
detectLatestTurnThinkingMismatch,
|
|
224
238
|
isPrefixBoundThinkingModel,
|
|
225
239
|
detectOverflow,
|
|
240
|
+
isAnthropicFamilyRoute,
|
|
226
241
|
readRawSessionMessages2
|
|
227
|
-
} from "./index-
|
|
242
|
+
} from "./index-bdckkfw6.js";
|
|
243
|
+
import"./index-72nhv486.js";
|
|
228
244
|
import {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
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";
|
|
234
253
|
import {
|
|
235
254
|
observeOpenCodeTurnEvent,
|
|
236
255
|
clearTrackedOpenCodeSession,
|
|
237
256
|
findLastAssistantModelFromOpenCodeDb
|
|
238
|
-
} from "./index-
|
|
257
|
+
} from "./index-ty64eqcn.js";
|
|
258
|
+
import {
|
|
259
|
+
sendCommandResult2,
|
|
260
|
+
sendStatusNotification2
|
|
261
|
+
} from "./index-yq8n9qcb.js";
|
|
239
262
|
import {
|
|
240
263
|
detectConflicts,
|
|
241
264
|
resolveCompactionForBoot
|
|
242
|
-
} from "./index-
|
|
265
|
+
} from "./index-eeezr5zz.js";
|
|
243
266
|
import {
|
|
244
267
|
sendConflictWarning2,
|
|
245
268
|
cleanupConflictWarnings2
|
|
246
|
-
} from "./index-
|
|
269
|
+
} from "./index-z8e0psj8.js";
|
|
247
270
|
import"./index-1zx87sdm.js";
|
|
271
|
+
import {
|
|
272
|
+
stripPersistedAssistantText,
|
|
273
|
+
deleteTagsByMessageId2,
|
|
274
|
+
getMaxTagNumberBySession2
|
|
275
|
+
} from "./index-k9nnwad5.js";
|
|
248
276
|
import {
|
|
249
277
|
resolveHistorianModel2,
|
|
250
278
|
resolveOpenCodeAgentOverrides2,
|
|
251
279
|
resolveHistorianAgentOverrides2
|
|
252
|
-
} from "./index-
|
|
280
|
+
} from "./index-8cd2j99z.js";
|
|
253
281
|
import {
|
|
254
282
|
buildDreamTaskRuntimeConfigs2,
|
|
255
283
|
userMemoryCollectionEnabled2
|
|
256
|
-
} from "./index-
|
|
284
|
+
} from "./index-ghc9f0n7.js";
|
|
285
|
+
import"./index-pg50n748.js";
|
|
286
|
+
import"./index-cb7emxgj.js";
|
|
257
287
|
import {
|
|
258
288
|
pushNotification2
|
|
259
289
|
} from "./index-x8a7jmkh.js";
|
|
290
|
+
import"./index-4dhv7mqz.js";
|
|
291
|
+
import"./index-5zygecde.js";
|
|
292
|
+
import"./index-7jzrrxap.js";
|
|
293
|
+
import"./index-q2tqeqde.js";
|
|
260
294
|
import {
|
|
261
295
|
createTagger,
|
|
262
296
|
cavemanWordRulesForLanguage,
|
|
263
297
|
setCtxReduceRegisteredGlobally,
|
|
264
298
|
clearToolPermissionDenied,
|
|
265
299
|
resetDegradedCacheCount2
|
|
266
|
-
} from "./index-
|
|
300
|
+
} from "./index-f0h6xwqm.js";
|
|
267
301
|
import {
|
|
268
302
|
runManagedRecomp2
|
|
269
|
-
} from "./index-
|
|
303
|
+
} from "./index-mmyh6d8f.js";
|
|
270
304
|
import {
|
|
271
305
|
isValidSemver,
|
|
272
306
|
compareSemverCore
|
|
273
|
-
} from "./index-
|
|
307
|
+
} from "./index-0w56v4fm.js";
|
|
274
308
|
import"./index-fmsr7v69.js";
|
|
275
309
|
import {
|
|
276
310
|
runManagedWrapup2
|
|
277
|
-
} from "./index-
|
|
311
|
+
} from "./index-k1xb52kd.js";
|
|
278
312
|
import {
|
|
279
313
|
__toESM,
|
|
280
314
|
__commonJS
|
|
@@ -291,7 +325,10 @@ import {
|
|
|
291
325
|
import {
|
|
292
326
|
piModelRefToCanonical
|
|
293
327
|
} from "./index-avwt563y.js";
|
|
294
|
-
import
|
|
328
|
+
import {
|
|
329
|
+
closeQuietly
|
|
330
|
+
} from "./index-8ajstryz.js";
|
|
331
|
+
import"./index-2y0s2hep.js";
|
|
295
332
|
|
|
296
333
|
// ../../node_modules/.bun/esprima@4.0.1/node_modules/esprima/dist/esprima.js
|
|
297
334
|
var require_esprima = __commonJS(function(exports, module) {
|
|
@@ -8347,9 +8384,9 @@ async function runDeferredV22Backfill(db, options = {}) {
|
|
|
8347
8384
|
const status = updateFinalBackfillStatus(db);
|
|
8348
8385
|
const failureCount = countFailures(db);
|
|
8349
8386
|
if (failureCount > 0) {
|
|
8350
|
-
|
|
8387
|
+
log2(`[v22-backfill] completed with ${failureCount} unresolved failure(s); run doctor --retry-v22-backfill`);
|
|
8351
8388
|
} else {
|
|
8352
|
-
|
|
8389
|
+
log2(`[v22-backfill] completed; processed=${processedRows}, changed=${changedRows}`);
|
|
8353
8390
|
}
|
|
8354
8391
|
return {
|
|
8355
8392
|
status,
|
|
@@ -8448,7 +8485,7 @@ var PackageJsonSchema = object({
|
|
|
8448
8485
|
|
|
8449
8486
|
// src/hooks/auto-update-checker/checker.ts
|
|
8450
8487
|
function warn(message) {
|
|
8451
|
-
|
|
8488
|
+
log2(`WARN: ${message}`);
|
|
8452
8489
|
}
|
|
8453
8490
|
function isString(value) {
|
|
8454
8491
|
return typeof value === "string";
|
|
@@ -8518,7 +8555,7 @@ function getWinningConfig(directory, surface) {
|
|
|
8518
8555
|
const entries = getPluginEntries(parsed);
|
|
8519
8556
|
if (entries.some((entry) => entry === PACKAGE_NAME || entry.startsWith(`${PACKAGE_NAME}@`))) {
|
|
8520
8557
|
if (winner) {
|
|
8521
|
-
|
|
8558
|
+
log2(`[auto-update-checker] ${surface} config ${winner.path} is shadowed by ${path}`);
|
|
8522
8559
|
}
|
|
8523
8560
|
winner = { path, entries };
|
|
8524
8561
|
}
|
|
@@ -8818,7 +8855,7 @@ var DEFAULT_INIT_DELAY_MS = 5000;
|
|
|
8818
8855
|
var PENDING_UPDATE_FILENAME = "pending-plugin-update.json";
|
|
8819
8856
|
var PENDING_UPDATE_MAX_AGE_MS = 7 * 24 * 60 * 60 * 1000;
|
|
8820
8857
|
function warn2(message) {
|
|
8821
|
-
|
|
8858
|
+
log2(`WARN: ${message}`);
|
|
8822
8859
|
}
|
|
8823
8860
|
function createAutoUpdateCheckerHook(ctx, options = {}) {
|
|
8824
8861
|
const {
|
|
@@ -8861,7 +8898,7 @@ async function maybeRunCheck(ctx, options) {
|
|
|
8861
8898
|
if (options.signal.aborted)
|
|
8862
8899
|
return;
|
|
8863
8900
|
if (!claimCheckSlot(options.storageDir, options.checkIntervalMs)) {
|
|
8864
|
-
|
|
8901
|
+
log2("[auto-update-checker] Skipping check (another instance ran one recently)");
|
|
8865
8902
|
return;
|
|
8866
8903
|
}
|
|
8867
8904
|
await runStartupCheck(ctx, options);
|
|
@@ -8925,7 +8962,7 @@ function consumePendingUpdateMarker(storageDir, loadedVersion) {
|
|
|
8925
8962
|
const olderThanLoaded = typeof marker.version === "string" && typeof loadedVersion === "string" && (compareSemverCore(marker.version, loadedVersion) ?? 0) < 0;
|
|
8926
8963
|
if (marker.version === loadedVersion && marker.spec === `${PACKAGE_NAME}@${loadedVersion}` && Array.isArray(marker.configPaths) && marker.configPaths.length === 2) {
|
|
8927
8964
|
rmSync(path, { force: true });
|
|
8928
|
-
|
|
8965
|
+
log2(`[auto-update-checker] Pending update applied: ${marker.spec}`);
|
|
8929
8966
|
} else if (age > PENDING_UPDATE_MAX_AGE_MS || olderThanLoaded) {
|
|
8930
8967
|
rmSync(path, { force: true });
|
|
8931
8968
|
warn2("[auto-update-checker] Discarded stale or mismatched pending update marker");
|
|
@@ -8948,7 +8985,7 @@ async function runStartupCheck(ctx, options) {
|
|
|
8948
8985
|
if (options.showStartupToast) {
|
|
8949
8986
|
showToast(ctx, `Magic Context ${displayVersion} (dev)`, "Running in local development mode.", "info");
|
|
8950
8987
|
}
|
|
8951
|
-
|
|
8988
|
+
log2("[auto-update-checker] Local development mode");
|
|
8952
8989
|
return;
|
|
8953
8990
|
}
|
|
8954
8991
|
if (options.showStartupToast) {
|
|
@@ -8961,19 +8998,19 @@ async function runBackgroundUpdateCheck(ctx, options) {
|
|
|
8961
8998
|
return;
|
|
8962
8999
|
const pluginInfo = findPluginEntry(ctx.directory);
|
|
8963
9000
|
if (!pluginInfo) {
|
|
8964
|
-
|
|
9001
|
+
log2("[auto-update-checker] Plugin not found in config");
|
|
8965
9002
|
return;
|
|
8966
9003
|
}
|
|
8967
9004
|
if (hasExplicitNonExactPluginVersion(pluginInfo.entry)) {
|
|
8968
9005
|
if (pluginInfo.entry === `${PACKAGE_NAME}@latest`) {
|
|
8969
|
-
|
|
9006
|
+
log2("[auto-update-checker] Explicit @latest leaves the active package unpinned; OpenCode may delete it mid-session.");
|
|
8970
9007
|
}
|
|
8971
9008
|
return;
|
|
8972
9009
|
}
|
|
8973
9010
|
const cachedVersion = getCachedVersion(pluginInfo.entry);
|
|
8974
9011
|
const currentVersion = cachedVersion ?? pluginInfo.pinnedVersion;
|
|
8975
9012
|
if (!currentVersion) {
|
|
8976
|
-
|
|
9013
|
+
log2("[auto-update-checker] No version found (cached or pinned)");
|
|
8977
9014
|
return;
|
|
8978
9015
|
}
|
|
8979
9016
|
const channel = extractChannel(pluginInfo.pinnedVersion ?? currentVersion);
|
|
@@ -8988,22 +9025,22 @@ async function runBackgroundUpdateCheck(ctx, options) {
|
|
|
8988
9025
|
return;
|
|
8989
9026
|
}
|
|
8990
9027
|
if (currentVersion === latestVersion) {
|
|
8991
|
-
|
|
9028
|
+
log2(`[auto-update-checker] Already on latest version for channel: ${channel}`);
|
|
8992
9029
|
return;
|
|
8993
9030
|
}
|
|
8994
|
-
|
|
9031
|
+
log2(`[auto-update-checker] Update available (${channel}): ${currentVersion} → ${latestVersion}`);
|
|
8995
9032
|
const updaterOwnedPin = pluginInfo.isPinned && isUpdaterPinnedSpec(readAutoUpdateCheckState(checkStatePath(options.storageDir)), pluginInfo.entry);
|
|
8996
9033
|
if (pluginInfo.isPinned && !updaterOwnedPin) {
|
|
8997
9034
|
showToast(ctx, `Magic Context ${latestVersion}`, `v${latestVersion} available. This version was pinned by you; update your OpenCode plugin config to upgrade.`, "info", 8000);
|
|
8998
|
-
|
|
9035
|
+
log2("[auto-update-checker] Version was pinned by you; skipping auto-update");
|
|
8999
9036
|
return;
|
|
9000
9037
|
}
|
|
9001
9038
|
if (updaterOwnedPin) {
|
|
9002
|
-
|
|
9039
|
+
log2("[auto-update-checker] Version was pinned by the updater; continuing auto-update");
|
|
9003
9040
|
}
|
|
9004
9041
|
if (!options.autoUpdate) {
|
|
9005
9042
|
showToast(ctx, `Magic Context ${latestVersion}`, `v${latestVersion} available. Auto-update is disabled.`, "info", 8000);
|
|
9006
|
-
|
|
9043
|
+
log2("[auto-update-checker] Auto-update disabled, notification only");
|
|
9007
9044
|
return;
|
|
9008
9045
|
}
|
|
9009
9046
|
const preparedUpdate = await preparePluginUpdate(ctx.directory, pluginInfo, latestVersion, {
|
|
@@ -9013,7 +9050,7 @@ async function runBackgroundUpdateCheck(ctx, options) {
|
|
|
9013
9050
|
writePendingUpdateMarker(options.storageDir, preparedUpdate, latestVersion);
|
|
9014
9051
|
showToast(ctx, "Magic Context Update Ready", `v${currentVersion} → v${latestVersion}
|
|
9015
9052
|
Restart OpenCode to apply.`, "success", 8000);
|
|
9016
|
-
|
|
9053
|
+
log2(`[auto-update-checker] Update ready: ${currentVersion} → ${latestVersion}`);
|
|
9017
9054
|
return;
|
|
9018
9055
|
}
|
|
9019
9056
|
showToast(ctx, `Magic Context ${latestVersion}`, `v${latestVersion} available, but auto-update failed to update both plugin configs.`, "error", 8000);
|
|
@@ -9264,7 +9301,7 @@ function recordSwallowedWrite(error) {
|
|
|
9264
9301
|
try {
|
|
9265
9302
|
swallowedWriteCount++;
|
|
9266
9303
|
lastErrorMessage = error instanceof Error ? error.message : String(error);
|
|
9267
|
-
|
|
9304
|
+
log2("[magic-context] window report ledger write failed:", error);
|
|
9268
9305
|
} catch {}
|
|
9269
9306
|
}
|
|
9270
9307
|
function positiveFiniteNumber(value) {
|
|
@@ -9398,14 +9435,6 @@ function captureWindowReport(input) {
|
|
|
9398
9435
|
}
|
|
9399
9436
|
|
|
9400
9437
|
// src/hooks/magic-context/context-limit-resolution.ts
|
|
9401
|
-
function provenFloorForModel(storedFloor, storedModelKey, modelKey) {
|
|
9402
|
-
if (typeof storedFloor !== "number" || !Number.isFinite(storedFloor) || storedFloor <= 0) {
|
|
9403
|
-
return 0;
|
|
9404
|
-
}
|
|
9405
|
-
if (!storedModelKey || !modelKey)
|
|
9406
|
-
return 0;
|
|
9407
|
-
return piModelRefToCanonical(storedModelKey) === piModelRefToCanonical(modelKey) ? storedFloor : 0;
|
|
9408
|
-
}
|
|
9409
9438
|
function describeContextLimitChange(previous, next) {
|
|
9410
9439
|
if (previous.limit === next.limit && previous.modelKey === next.modelKey)
|
|
9411
9440
|
return null;
|
|
@@ -9429,12 +9458,12 @@ function noteContextLimitResolution(sessionId, resolution) {
|
|
|
9429
9458
|
const previous = lastResolutionBySession.get(sessionId);
|
|
9430
9459
|
lastResolutionBySession.set(sessionId, resolution);
|
|
9431
9460
|
if (!previous) {
|
|
9432
|
-
|
|
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})`);
|
|
9433
9462
|
return;
|
|
9434
9463
|
}
|
|
9435
9464
|
const change = describeContextLimitChange(previous, resolution);
|
|
9436
9465
|
if (change)
|
|
9437
|
-
|
|
9466
|
+
sessionLog2(sessionId, change);
|
|
9438
9467
|
}
|
|
9439
9468
|
|
|
9440
9469
|
// src/hooks/magic-context/event-handler.ts
|
|
@@ -9468,16 +9497,16 @@ async function deliverChannel2IfPending(deps, sessionId) {
|
|
|
9468
9497
|
deps.channel2DirectiveTextBySession?.delete(sessionId);
|
|
9469
9498
|
}
|
|
9470
9499
|
} catch (error) {
|
|
9471
|
-
|
|
9500
|
+
sessionLog2(sessionId, "channel2 delivery wrapper failed (ignored):", error);
|
|
9472
9501
|
}
|
|
9473
9502
|
}
|
|
9474
9503
|
function cleanupRemovedMessageState(deps, sessionId, messageId) {
|
|
9475
9504
|
return deps.db.transaction(() => {
|
|
9476
|
-
const removedTagNumbers =
|
|
9505
|
+
const removedTagNumbers = deleteTagsByMessageId2(deps.db, sessionId, messageId);
|
|
9477
9506
|
deleteTemporalDecision(deps.db, sessionId, messageId);
|
|
9478
|
-
|
|
9507
|
+
sessionLog2(sessionId, `event message.removed: deleted ${removedTagNumbers.length} tag(s) for message ${messageId}`);
|
|
9479
9508
|
const strippedPlaceholderRemoved = removeStrippedPlaceholderId(deps.db, sessionId, messageId);
|
|
9480
|
-
|
|
9509
|
+
sessionLog2(sessionId, strippedPlaceholderRemoved ? `event message.removed: removed ${messageId} from stripped placeholder ids` : `event message.removed: stripped placeholder ids unchanged for ${messageId}`);
|
|
9481
9510
|
const removedNoteNudgeAnchor = removeNoteNudgeAnchorByMessageId(deps.db, sessionId, messageId);
|
|
9482
9511
|
const removedAutoSearchDecision = removeAutoSearchHintDecisionByMessageId(deps.db, sessionId, messageId);
|
|
9483
9512
|
const persistedNoteNudge = getPersistedNoteNudge(deps.db, sessionId);
|
|
@@ -9486,18 +9515,18 @@ function cleanupRemovedMessageState(deps, sessionId, messageId) {
|
|
|
9486
9515
|
clearNoteNudgeTriggerOnly(deps.db, sessionId);
|
|
9487
9516
|
}
|
|
9488
9517
|
const clearedNoteNudge = removedNoteNudgeAnchor || clearedNoteNudgeTrigger;
|
|
9489
|
-
|
|
9490
|
-
|
|
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}`);
|
|
9491
9520
|
const currentWatermark = getPersistedReasoningWatermark(deps.db, sessionId);
|
|
9492
|
-
const maxRemainingTag =
|
|
9521
|
+
const maxRemainingTag = getMaxTagNumberBySession2(deps.db, sessionId);
|
|
9493
9522
|
if (currentWatermark > maxRemainingTag) {
|
|
9494
9523
|
setPersistedReasoningWatermark(deps.db, sessionId, maxRemainingTag);
|
|
9495
|
-
|
|
9524
|
+
sessionLog2(sessionId, `event message.removed: reset reasoning watermark ${currentWatermark}→${maxRemainingTag}`);
|
|
9496
9525
|
} else {
|
|
9497
|
-
|
|
9526
|
+
sessionLog2(sessionId, `event message.removed: reasoning watermark unchanged at ${currentWatermark} (max tag ${maxRemainingTag})`);
|
|
9498
9527
|
}
|
|
9499
9528
|
const removedIndexedMessages = deleteIndexedMessage(deps.db, sessionId, messageId);
|
|
9500
|
-
|
|
9529
|
+
sessionLog2(sessionId, `event message.removed: deleted ${removedIndexedMessages} indexed message row(s) for ${messageId}`);
|
|
9501
9530
|
return {
|
|
9502
9531
|
clearedNoteNudge
|
|
9503
9532
|
};
|
|
@@ -9516,7 +9545,7 @@ function createEventHandler2(deps) {
|
|
|
9516
9545
|
}
|
|
9517
9546
|
if (deps.internalChildSessions && info.parentID.length > 0 && typeof info.title === "string" && info.title.startsWith(INTERNAL_CHILD_TITLE_PREFIX)) {
|
|
9518
9547
|
deps.internalChildSessions.add(info.id);
|
|
9519
|
-
|
|
9548
|
+
sessionLog2(info.id, `marked internal magic-context child (title="${info.title}") — exempt from transform + injection`);
|
|
9520
9549
|
}
|
|
9521
9550
|
try {
|
|
9522
9551
|
if (info.directory) {
|
|
@@ -9529,7 +9558,7 @@ function createEventHandler2(deps) {
|
|
|
9529
9558
|
cacheTtl: resolveSessionCacheTtl(deps.db, info.id, ttlConfig.cache_ttl, modelKey, ttlConfig.cacheTtlConfigured).value
|
|
9530
9559
|
});
|
|
9531
9560
|
} catch (error) {
|
|
9532
|
-
|
|
9561
|
+
sessionLog2(info.id, "event session.created persistence failed:", error);
|
|
9533
9562
|
}
|
|
9534
9563
|
return;
|
|
9535
9564
|
}
|
|
@@ -9540,12 +9569,21 @@ function createEventHandler2(deps) {
|
|
|
9540
9569
|
}
|
|
9541
9570
|
recordPromptSessionError(errInfo.sessionID, errInfo.error);
|
|
9542
9571
|
try {
|
|
9572
|
+
if (detectLatestTurnThinkingMismatch(errInfo.error)) {
|
|
9573
|
+
const model = findLastAssistantModelFromOpenCodeDb(errInfo.sessionID);
|
|
9574
|
+
if (!deps.compactionOff && isAnthropicFamilyRoute(model?.providerID, model?.modelID)) {
|
|
9575
|
+
armLatestThinkingRecovery(deps.db, errInfo.sessionID);
|
|
9576
|
+
dropSlot(errInfo.sessionID, "latest-thinking-recovery-arm");
|
|
9577
|
+
deps.onSessionCacheInvalidated?.(errInfo.sessionID);
|
|
9578
|
+
}
|
|
9579
|
+
return;
|
|
9580
|
+
}
|
|
9543
9581
|
const bindingMismatch = detectThinkingBindingMismatch(errInfo.error);
|
|
9544
9582
|
if (bindingMismatch.isBindingMismatch) {
|
|
9545
9583
|
const model = findLastAssistantModelFromOpenCodeDb(errInfo.sessionID);
|
|
9546
9584
|
if (deps.thinkingBindingRecoveryEnabled !== false && !deps.compactionOff && isPrefixBoundThinkingModel(model?.providerID, model?.modelID)) {
|
|
9547
|
-
|
|
9548
|
-
|
|
9585
|
+
armBindingRecoverySafely(deps.db, errInfo.sessionID);
|
|
9586
|
+
sessionLog2(errInfo.sessionID, `thinking binding recovery armed from session.error (provider paths: failing=${bindingMismatch.failingBlockPath ?? "?"} firstChanged=${bindingMismatch.firstChangedPath ?? "?"})`);
|
|
9549
9587
|
dropSlot(errInfo.sessionID, "thinking-binding-recovery-arm");
|
|
9550
9588
|
deps.onSessionCacheInvalidated?.(errInfo.sessionID);
|
|
9551
9589
|
}
|
|
@@ -9571,7 +9609,7 @@ function createEventHandler2(deps) {
|
|
|
9571
9609
|
if (typeof detection.reportedLimit === "number" && detection.reportedLimit > 0) {
|
|
9572
9610
|
recordDetectedContextLimit(deps.db, errInfo.sessionID, detection.reportedLimit, overflowModelKey, detection.reportedLimitProvenance);
|
|
9573
9611
|
}
|
|
9574
|
-
|
|
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)`);
|
|
9575
9613
|
return;
|
|
9576
9614
|
}
|
|
9577
9615
|
const existing = getOverflowState(deps.db, errInfo.sessionID);
|
|
@@ -9579,7 +9617,7 @@ function createEventHandler2(deps) {
|
|
|
9579
9617
|
if (typeof detection.reportedLimit === "number" && detection.reportedLimit > 0) {
|
|
9580
9618
|
recordDetectedContextLimit(deps.db, errInfo.sessionID, detection.reportedLimit, overflowModelKey, detection.reportedLimitProvenance);
|
|
9581
9619
|
}
|
|
9582
|
-
|
|
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)`);
|
|
9583
9621
|
return;
|
|
9584
9622
|
}
|
|
9585
9623
|
dropSlot(errInfo.sessionID, "overflow-recovery-arm");
|
|
@@ -9595,10 +9633,10 @@ function createEventHandler2(deps) {
|
|
|
9595
9633
|
updatedAt: Date.now()
|
|
9596
9634
|
});
|
|
9597
9635
|
}
|
|
9598
|
-
|
|
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})`);
|
|
9599
9637
|
deps.onSessionCacheInvalidated?.(errInfo.sessionID);
|
|
9600
9638
|
} catch (error) {
|
|
9601
|
-
|
|
9639
|
+
sessionLog2(errInfo.sessionID, "event session.error handling failed:", error);
|
|
9602
9640
|
}
|
|
9603
9641
|
return;
|
|
9604
9642
|
}
|
|
@@ -9610,7 +9648,7 @@ function createEventHandler2(deps) {
|
|
|
9610
9648
|
const time = rawInfo && typeof rawInfo === "object" && "time" in rawInfo ? rawInfo.time?.created : undefined;
|
|
9611
9649
|
observeSessionActivity(deps.db, message.sessionID, typeof time === "number" ? time : Date.now());
|
|
9612
9650
|
} catch (error) {
|
|
9613
|
-
|
|
9651
|
+
sessionLog2(message.sessionID, "event message.updated activity persistence failed:", error);
|
|
9614
9652
|
}
|
|
9615
9653
|
}
|
|
9616
9654
|
const info = getMessageUpdatedAssistantInfo(input.event.properties);
|
|
@@ -9620,9 +9658,9 @@ function createEventHandler2(deps) {
|
|
|
9620
9658
|
return;
|
|
9621
9659
|
const sessionId = properties ? resolveSessionId(properties) : null;
|
|
9622
9660
|
if (sessionId) {
|
|
9623
|
-
|
|
9661
|
+
sessionLog2(sessionId, "event message.updated: no assistant info extracted from event");
|
|
9624
9662
|
} else {
|
|
9625
|
-
|
|
9663
|
+
log2("[magic-context] event message.updated: no assistant info extracted from event");
|
|
9626
9664
|
}
|
|
9627
9665
|
return;
|
|
9628
9666
|
}
|
|
@@ -9651,15 +9689,21 @@ function createEventHandler2(deps) {
|
|
|
9651
9689
|
}
|
|
9652
9690
|
let messageHadOverflowError = false;
|
|
9653
9691
|
if (info.error !== undefined && info.error !== null) {
|
|
9692
|
+
if (detectLatestTurnThinkingMismatch(info.error) && !deps.compactionOff && isAnthropicFamilyRoute(info.providerID, info.modelID)) {
|
|
9693
|
+
armLatestThinkingRecovery(deps.db, info.sessionID);
|
|
9694
|
+
dropSlot(info.sessionID, "latest-thinking-recovery-arm");
|
|
9695
|
+
deps.onSessionCacheInvalidated?.(info.sessionID);
|
|
9696
|
+
return;
|
|
9697
|
+
}
|
|
9654
9698
|
const bindingMismatch = detectThinkingBindingMismatch(info.error);
|
|
9655
9699
|
if (bindingMismatch.isBindingMismatch && deps.thinkingBindingRecoveryEnabled !== false && !deps.compactionOff && isPrefixBoundThinkingModel(info.providerID, info.modelID)) {
|
|
9656
9700
|
try {
|
|
9657
|
-
|
|
9658
|
-
|
|
9701
|
+
armBindingRecoverySafely(deps.db, info.sessionID);
|
|
9702
|
+
sessionLog2(info.sessionID, `thinking binding recovery armed from message.updated (provider paths: failing=${bindingMismatch.failingBlockPath ?? "?"} firstChanged=${bindingMismatch.firstChangedPath ?? "?"})`);
|
|
9659
9703
|
dropSlot(info.sessionID, "thinking-binding-recovery-arm");
|
|
9660
9704
|
deps.onSessionCacheInvalidated?.(info.sessionID);
|
|
9661
9705
|
} catch (error) {
|
|
9662
|
-
|
|
9706
|
+
sessionLog2(info.sessionID, "event message.updated thinking binding recovery persistence failed:", error);
|
|
9663
9707
|
}
|
|
9664
9708
|
}
|
|
9665
9709
|
}
|
|
@@ -9685,12 +9729,12 @@ function createEventHandler2(deps) {
|
|
|
9685
9729
|
if (typeof detection.reportedLimit === "number" && detection.reportedLimit > 0) {
|
|
9686
9730
|
recordDetectedContextLimit(deps.db, info.sessionID, detection.reportedLimit, overflowModelKey, detection.reportedLimitProvenance);
|
|
9687
9731
|
}
|
|
9688
|
-
|
|
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`);
|
|
9689
9733
|
} else if (deps.compactionOff) {
|
|
9690
9734
|
if (typeof detection.reportedLimit === "number" && detection.reportedLimit > 0) {
|
|
9691
9735
|
recordDetectedContextLimit(deps.db, info.sessionID, detection.reportedLimit, overflowModelKey, detection.reportedLimitProvenance);
|
|
9692
9736
|
}
|
|
9693
|
-
|
|
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`);
|
|
9694
9738
|
} else {
|
|
9695
9739
|
dropSlot(info.sessionID, "overflow-recovery-arm");
|
|
9696
9740
|
recordOverflowDetected(deps.db, info.sessionID, detection.reportedLimit, overflowModelKey, "provider_overflow", detection.reportedLimitProvenance, detection.reportedInputTokens);
|
|
@@ -9705,11 +9749,11 @@ function createEventHandler2(deps) {
|
|
|
9705
9749
|
updatedAt: Date.now()
|
|
9706
9750
|
});
|
|
9707
9751
|
}
|
|
9708
|
-
|
|
9752
|
+
sessionLog2(info.sessionID, `overflow detected via message.updated: reportedLimit=${detection.reportedLimit ?? "unknown"} provenance=${detection.reportedLimitProvenance ?? "n/a"} pattern=${detection.matchedPattern ?? "n/a"}`);
|
|
9709
9753
|
deps.onSessionCacheInvalidated?.(info.sessionID);
|
|
9710
9754
|
}
|
|
9711
9755
|
} catch (error) {
|
|
9712
|
-
|
|
9756
|
+
sessionLog2(info.sessionID, "event message.updated overflow persistence failed:", error);
|
|
9713
9757
|
}
|
|
9714
9758
|
}
|
|
9715
9759
|
}
|
|
@@ -9739,7 +9783,7 @@ function createEventHandler2(deps) {
|
|
|
9739
9783
|
inputTokens: (info.tokens?.input ?? 0) + (info.tokens?.cache?.read ?? 0) + (info.tokens?.cache?.write ?? 0)
|
|
9740
9784
|
});
|
|
9741
9785
|
}
|
|
9742
|
-
|
|
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}`);
|
|
9743
9787
|
const hasKnownUsage = hasUsageTokens || deps.contextUsageMap.has(info.sessionID);
|
|
9744
9788
|
if (successfulCompletion && !hasUsageTokens) {
|
|
9745
9789
|
try {
|
|
@@ -9751,11 +9795,11 @@ function createEventHandler2(deps) {
|
|
|
9751
9795
|
});
|
|
9752
9796
|
}
|
|
9753
9797
|
} catch (error) {
|
|
9754
|
-
|
|
9798
|
+
sessionLog2(info.sessionID, "event completion clock persistence failed:", error);
|
|
9755
9799
|
}
|
|
9756
9800
|
}
|
|
9757
9801
|
if (!hasKnownUsage) {
|
|
9758
|
-
|
|
9802
|
+
sessionLog2(info.sessionID, "event message.updated: skipping — no usage tokens and no known usage");
|
|
9759
9803
|
return;
|
|
9760
9804
|
}
|
|
9761
9805
|
try {
|
|
@@ -9778,7 +9822,7 @@ function createEventHandler2(deps) {
|
|
|
9778
9822
|
if (hasUsageTokens && aboveTrustedWall) {
|
|
9779
9823
|
if (!usageAboveWallLogSeen.has(aboveWallLogKey)) {
|
|
9780
9824
|
usageAboveWallLogSeen.add(aboveWallLogKey);
|
|
9781
|
-
|
|
9825
|
+
sessionLog2(info.sessionID, `provider usage ${totalInputTokens} exceeds configured window ${trustedAbsoluteWall}; counted as real pressure against the configured limit`);
|
|
9782
9826
|
}
|
|
9783
9827
|
} else {
|
|
9784
9828
|
usageAboveWallLogSeen.delete(aboveWallLogKey);
|
|
@@ -9786,14 +9830,14 @@ function createEventHandler2(deps) {
|
|
|
9786
9830
|
let refreshLimitsAfterRecording;
|
|
9787
9831
|
if (hasUsageTokens) {
|
|
9788
9832
|
const pressureInputTokens = totalInputTokens;
|
|
9789
|
-
const requestSucceeded = !messageHadOverflowError;
|
|
9833
|
+
const requestSucceeded = !messageHadOverflowError && !responseFailed;
|
|
9790
9834
|
const successfulUsageProof = requestSucceeded && !aboveTrustedWall;
|
|
9791
9835
|
if (requestSucceeded) {
|
|
9792
9836
|
const rawOverflow = getOverflowState(deps.db, info.sessionID);
|
|
9793
9837
|
const detectedLimitMatchesModel = rawOverflow.detectedContextLimitModelKey === null || modelKey !== undefined && rawOverflow.detectedContextLimitModelKey === modelKey;
|
|
9794
9838
|
if (rawOverflow.detectedContextLimit > 0 && detectedLimitMatchesModel && pressureInputTokens > rawOverflow.detectedContextLimit) {
|
|
9795
9839
|
clearDetectedContextLimit(deps.db, info.sessionID);
|
|
9796
|
-
|
|
9840
|
+
sessionLog2(info.sessionID, `detected limit ${rawOverflow.detectedContextLimit} invalidated by a successful ${pressureInputTokens}-token request; using catalog/default`);
|
|
9797
9841
|
deps.onSessionCacheInvalidated?.(info.sessionID);
|
|
9798
9842
|
}
|
|
9799
9843
|
}
|
|
@@ -9801,7 +9845,7 @@ function createEventHandler2(deps) {
|
|
|
9801
9845
|
if (!responseFailed) {
|
|
9802
9846
|
updates.lastResponseTime = Math.max(sessionMeta.lastResponseTime, responseTime);
|
|
9803
9847
|
}
|
|
9804
|
-
const observedSafeInputTokens =
|
|
9848
|
+
const observedSafeInputTokens = resolveOpenCodeProvenInputFloor(deps.db, info.sessionID, modelKey);
|
|
9805
9849
|
const provenSafeInputTokens = successfulUsageProof ? Math.max(observedSafeInputTokens, pressureInputTokens) : observedSafeInputTokens;
|
|
9806
9850
|
const readCatalogLimit = () => info.providerID && info.modelID ? getSdkContextLimit(info.providerID, info.modelID) : undefined;
|
|
9807
9851
|
const resolvePressure = () => {
|
|
@@ -9818,7 +9862,7 @@ function createEventHandler2(deps) {
|
|
|
9818
9862
|
};
|
|
9819
9863
|
const newestMessageId = newestUsageMessageIdBySession.get(info.sessionID);
|
|
9820
9864
|
if (info.messageID !== undefined && newestMessageId !== undefined && info.messageID < newestMessageId) {
|
|
9821
|
-
|
|
9865
|
+
sessionLog2(info.sessionID, `event message.updated: usage ${pressureInputTokens} from ${info.messageID} arrived after newer message ${newestMessageId}; keeping the newer reading`);
|
|
9822
9866
|
return;
|
|
9823
9867
|
}
|
|
9824
9868
|
if (info.messageID !== undefined) {
|
|
@@ -9832,7 +9876,7 @@ function createEventHandler2(deps) {
|
|
|
9832
9876
|
detected: getOverflowState(deps.db, info.sessionID, modelKey).detectedContextLimit,
|
|
9833
9877
|
provenFloor: successfulUsageProof ? provenSafeInputTokens : observedSafeInputTokens
|
|
9834
9878
|
});
|
|
9835
|
-
|
|
9879
|
+
sessionLog2(info.sessionID, `event message.updated: totalInputTokens=${pressureInputTokens} contextLimit=${pressure.contextLimit} percentage=${pressure.percentage.toFixed(1)}%`);
|
|
9836
9880
|
const entry = {
|
|
9837
9881
|
usage: {
|
|
9838
9882
|
percentage: pressure.percentage,
|
|
@@ -9846,7 +9890,7 @@ function createEventHandler2(deps) {
|
|
|
9846
9890
|
const historianFailureState = getHistorianFailureState(deps.db, info.sessionID);
|
|
9847
9891
|
if (historianFailureState.failureCount > 0 && pressure.percentage < 90) {
|
|
9848
9892
|
clearHistorianFailureState(deps.db, info.sessionID);
|
|
9849
|
-
|
|
9893
|
+
sessionLog2(info.sessionID, `event message.updated: cleared historian failure state at ${pressure.percentage.toFixed(1)}%`);
|
|
9850
9894
|
}
|
|
9851
9895
|
return entry;
|
|
9852
9896
|
};
|
|
@@ -9868,7 +9912,7 @@ function createEventHandler2(deps) {
|
|
|
9868
9912
|
await refreshModelLimitsFromApi(deps.client);
|
|
9869
9913
|
catalogLimit = readCatalogLimit();
|
|
9870
9914
|
if (catalogLimit !== undefined && catalogLimit >= provenSafeInputTokens) {
|
|
9871
|
-
|
|
9915
|
+
sessionLog2(info.sessionID, `models-dev-cache: regression recovered for ${info.providerID}/${info.modelID} via refresh (was=${oldLimit}, now=${catalogLimit})`);
|
|
9872
9916
|
}
|
|
9873
9917
|
}
|
|
9874
9918
|
const refreshedUpdates = {};
|
|
@@ -9890,11 +9934,14 @@ function createEventHandler2(deps) {
|
|
|
9890
9934
|
};
|
|
9891
9935
|
}
|
|
9892
9936
|
updateSessionMeta(deps.db, info.sessionID, updates);
|
|
9937
|
+
if (modelKey && updates.observedSafeInputTokens !== undefined) {
|
|
9938
|
+
recordOpenCodeProvenInputFloor(deps.db, info.sessionID, modelKey, updates.observedSafeInputTokens);
|
|
9939
|
+
}
|
|
9893
9940
|
if (refreshLimitsAfterRecording) {
|
|
9894
9941
|
await refreshLimitsAfterRecording();
|
|
9895
9942
|
}
|
|
9896
9943
|
} catch (error) {
|
|
9897
|
-
|
|
9944
|
+
sessionLog2(info.sessionID, "event message.updated persistence failed:", error);
|
|
9898
9945
|
}
|
|
9899
9946
|
if ((info.finish === "stop" || info.finish === "tool-calls") && deps.client && deps.channel1StateBySession && !deps.compactionOff) {
|
|
9900
9947
|
deliverChannel2IfPending(deps, info.sessionID);
|
|
@@ -9906,24 +9953,25 @@ function createEventHandler2(deps) {
|
|
|
9906
9953
|
if (!info) {
|
|
9907
9954
|
const sessionId = properties ? resolveSessionId(properties) : null;
|
|
9908
9955
|
if (sessionId) {
|
|
9909
|
-
|
|
9956
|
+
sessionLog2(sessionId, "event message.removed: no message removal info extracted from event");
|
|
9910
9957
|
} else {
|
|
9911
|
-
|
|
9958
|
+
log2("[magic-context] event message.removed: no message removal info extracted from event");
|
|
9912
9959
|
}
|
|
9913
9960
|
return;
|
|
9914
9961
|
}
|
|
9915
9962
|
dropSlot(info.sessionID, "message.removed");
|
|
9963
|
+
forgetRawSessionOrdinalWatermark2(info.sessionID);
|
|
9916
9964
|
deps.onRustWireInvalidated?.(info.sessionID);
|
|
9917
|
-
|
|
9965
|
+
sessionLog2(info.sessionID, `event message.removed: invalidating state for message ${info.messageID}`);
|
|
9918
9966
|
try {
|
|
9919
9967
|
cleanupRemovedMessageState(deps, info.sessionID, info.messageID);
|
|
9920
9968
|
scheduleClearAndReindex(deps.db, info.sessionID, readRawSessionMessages2);
|
|
9921
9969
|
deps.tagger.cleanup(info.sessionID);
|
|
9922
|
-
|
|
9970
|
+
sessionLog2(info.sessionID, "event message.removed: invalidated tagger session cache");
|
|
9923
9971
|
const markerState = getPersistedCompactionMarkerState(deps.db, info.sessionID);
|
|
9924
9972
|
if (markerState && (markerState.boundaryMessageId === info.messageID || markerState.summaryMessageId === info.messageID)) {
|
|
9925
9973
|
removeCompactionMarkerForSession(deps.db, info.sessionID);
|
|
9926
|
-
|
|
9974
|
+
sessionLog2(info.sessionID, `event message.removed: cleared compaction marker (boundary or summary message removed)`);
|
|
9927
9975
|
}
|
|
9928
9976
|
clearMessageTokensCache(info.sessionID, info.messageID);
|
|
9929
9977
|
invalidateTrueRawTokenCache({
|
|
@@ -9932,9 +9980,9 @@ function createEventHandler2(deps) {
|
|
|
9932
9980
|
reason: "message.removed"
|
|
9933
9981
|
});
|
|
9934
9982
|
deps.onSessionCacheInvalidated?.(info.sessionID);
|
|
9935
|
-
|
|
9983
|
+
sessionLog2(info.sessionID, "event message.removed: cleared session injection cache");
|
|
9936
9984
|
} catch (error) {
|
|
9937
|
-
|
|
9985
|
+
sessionLog2(info.sessionID, "event message.removed cleanup failed:", error);
|
|
9938
9986
|
}
|
|
9939
9987
|
return;
|
|
9940
9988
|
}
|
|
@@ -9947,12 +9995,12 @@ function createEventHandler2(deps) {
|
|
|
9947
9995
|
try {
|
|
9948
9996
|
deps.compactionHandler.onCompacted(sessionId, deps.db);
|
|
9949
9997
|
} catch (error) {
|
|
9950
|
-
|
|
9998
|
+
sessionLog2(sessionId, "event session.compacted handling failed:", error);
|
|
9951
9999
|
}
|
|
9952
10000
|
try {
|
|
9953
10001
|
removeCompactionMarkerForSession(deps.db, sessionId);
|
|
9954
10002
|
} catch (error) {
|
|
9955
|
-
|
|
10003
|
+
sessionLog2(sessionId, "event session.compacted marker cleanup failed:", error);
|
|
9956
10004
|
}
|
|
9957
10005
|
try {
|
|
9958
10006
|
const pending = getPendingCompactionMarkerState(deps.db, sessionId);
|
|
@@ -9960,7 +10008,7 @@ function createEventHandler2(deps) {
|
|
|
9960
10008
|
clearPendingCompactionMarkerStateIf(deps.db, sessionId, pending);
|
|
9961
10009
|
}
|
|
9962
10010
|
} catch (error) {
|
|
9963
|
-
|
|
10011
|
+
sessionLog2(sessionId, "event session.compacted pending-marker cleanup failed:", error);
|
|
9964
10012
|
}
|
|
9965
10013
|
resetDegradedCacheCount2(sessionId);
|
|
9966
10014
|
clearMessageTokensCache(sessionId);
|
|
@@ -9983,7 +10031,7 @@ function createEventHandler2(deps) {
|
|
|
9983
10031
|
clearSession(deps.db, sessionId, deps.rustSessionCleanup === true);
|
|
9984
10032
|
}
|
|
9985
10033
|
} catch (error) {
|
|
9986
|
-
|
|
10034
|
+
sessionLog2(sessionId, "event session.deleted persistence failed:", error);
|
|
9987
10035
|
}
|
|
9988
10036
|
resetDegradedCacheCount2(sessionId);
|
|
9989
10037
|
deps.onSessionCacheInvalidated?.(sessionId);
|
|
@@ -10052,7 +10100,7 @@ function notifyMagicContextDisabled(client, reason) {
|
|
|
10052
10100
|
duration: 8000
|
|
10053
10101
|
}
|
|
10054
10102
|
}).catch((error) => {
|
|
10055
|
-
|
|
10103
|
+
log2("[magic-context] failed to show disabled toast:", error);
|
|
10056
10104
|
});
|
|
10057
10105
|
}
|
|
10058
10106
|
function createMagicContextHook(deps) {
|
|
@@ -10064,7 +10112,7 @@ function createMagicContextHook(deps) {
|
|
|
10064
10112
|
if (!opened || !isDatabasePersisted(opened)) {
|
|
10065
10113
|
const reason = describeStorageUnavailability((opened ? getDatabasePersistenceError(opened) : null) ?? "Failed to initialize the persistent SQLite database.");
|
|
10066
10114
|
const detail = formatFailClosedBlockingMessage(reason);
|
|
10067
|
-
|
|
10115
|
+
log2("[magic-context] disabling feature because persistent storage is unavailable:", detail);
|
|
10068
10116
|
notifyMagicContextDisabled(deps.client, detail);
|
|
10069
10117
|
recordHookInitFailure({ type: "storage", reason });
|
|
10070
10118
|
return null;
|
|
@@ -10072,7 +10120,7 @@ function createMagicContextHook(deps) {
|
|
|
10072
10120
|
db = opened;
|
|
10073
10121
|
} catch (error) {
|
|
10074
10122
|
const reason = getErrorMessage(error);
|
|
10075
|
-
|
|
10123
|
+
log2("[magic-context] hook failed to open storage; disabling feature:", error);
|
|
10076
10124
|
notifyMagicContextDisabled(deps.client, reason);
|
|
10077
10125
|
clearHookInitFailure();
|
|
10078
10126
|
recordHookInitFailure({
|
|
@@ -10083,7 +10131,7 @@ function createMagicContextHook(deps) {
|
|
|
10083
10131
|
}
|
|
10084
10132
|
const projectPath = resolveProjectIdentityForSession(deps.directory, deps.config.allow_home_project);
|
|
10085
10133
|
if (!projectPath) {
|
|
10086
|
-
|
|
10134
|
+
log2("[magic-context] not binding a project identity for this directory");
|
|
10087
10135
|
clearHookInitFailure();
|
|
10088
10136
|
recordHookInitFailure({ type: "no_project" });
|
|
10089
10137
|
return null;
|
|
@@ -10091,7 +10139,7 @@ function createMagicContextHook(deps) {
|
|
|
10091
10139
|
try {
|
|
10092
10140
|
checkCompactionMarkerConsistency(db);
|
|
10093
10141
|
} catch (error) {
|
|
10094
|
-
|
|
10142
|
+
log2("[magic-context] startup compaction-marker consistency check failed:", error);
|
|
10095
10143
|
}
|
|
10096
10144
|
let lastScheduleCheckMs = 0;
|
|
10097
10145
|
let dreamQueueQuietScheduled = false;
|
|
@@ -10127,10 +10175,10 @@ function createMagicContextHook(deps) {
|
|
|
10127
10175
|
deferredHistoryRefreshSessions.add(sid);
|
|
10128
10176
|
deferredMaterializationSessions.add(sid);
|
|
10129
10177
|
}
|
|
10130
|
-
|
|
10178
|
+
log2(`[magic-context] rehydrated ${sessionsWithPending.length} session(s) with pending compaction-marker drain at hook init`);
|
|
10131
10179
|
}
|
|
10132
10180
|
} catch (error) {
|
|
10133
|
-
|
|
10181
|
+
log2("[magic-context] hook init: pending-marker rehydration failed:", error);
|
|
10134
10182
|
}
|
|
10135
10183
|
const lastHeuristicsTurnId = new Map;
|
|
10136
10184
|
const commitSeenLastPass = new Map;
|
|
@@ -10162,7 +10210,7 @@ function createMagicContextHook(deps) {
|
|
|
10162
10210
|
return;
|
|
10163
10211
|
const notificationParams = getLiveNotificationParams(sessionId, liveModelBySession, variantBySession, agentBySession, (deps.sampleDreamConfig?.() ?? deps.config).toast_duration_ms);
|
|
10164
10212
|
sendStatusNotification2(deps.client, sessionId, warning, notificationParams).catch((error) => {
|
|
10165
|
-
|
|
10213
|
+
log2(`[magic-context] failed to send project identity warning for ${directory}: ${getErrorMessage(error)}`);
|
|
10166
10214
|
});
|
|
10167
10215
|
};
|
|
10168
10216
|
const dreamerRunnable = isDreamerRunnable(deps.config);
|
|
@@ -10243,7 +10291,7 @@ function createMagicContextHook(deps) {
|
|
|
10243
10291
|
if (!sessionProjectIdentity)
|
|
10244
10292
|
return "No project identity is bound for the home directory.";
|
|
10245
10293
|
maybeSendProjectIdentitySessionWarning(sessionId, directory);
|
|
10246
|
-
const coverage =
|
|
10294
|
+
const coverage = getEmbeddingCoverageStatus2(db, sessionProjectIdentity, sessionId);
|
|
10247
10295
|
const progress = recompProgressBySession.get(sessionId);
|
|
10248
10296
|
const drainUi = getEmbedDrainUiStatus(sessionId, progress);
|
|
10249
10297
|
return formatEmbedStatusText(coverage, {
|
|
@@ -10253,11 +10301,11 @@ function createMagicContextHook(deps) {
|
|
|
10253
10301
|
});
|
|
10254
10302
|
};
|
|
10255
10303
|
const maybeAutoEmbedSession = (sessionId) => {
|
|
10256
|
-
if (
|
|
10304
|
+
if (isEmbeddingHostBusy2())
|
|
10257
10305
|
return;
|
|
10258
10306
|
const directory = sessionDirectoryBySession.get(sessionId) ?? deps.directory;
|
|
10259
10307
|
const identity = resolveProjectIdentityForSession(directory, deps.config.allow_home_project);
|
|
10260
|
-
const snapshot = identity ?
|
|
10308
|
+
const snapshot = identity ? getProjectEmbeddingSnapshot2(identity) : undefined;
|
|
10261
10309
|
const embedIdentity = snapshot ? JSON.stringify([
|
|
10262
10310
|
snapshot.providerIdentity,
|
|
10263
10311
|
snapshot.chunkModelId,
|
|
@@ -10275,7 +10323,7 @@ function createMagicContextHook(deps) {
|
|
|
10275
10323
|
(async () => {
|
|
10276
10324
|
try {
|
|
10277
10325
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
10278
|
-
if (
|
|
10326
|
+
if (isEmbeddingHostBusy2()) {
|
|
10279
10327
|
invalidateAutoEmbedSession(sessionId);
|
|
10280
10328
|
return;
|
|
10281
10329
|
}
|
|
@@ -10286,7 +10334,7 @@ function createMagicContextHook(deps) {
|
|
|
10286
10334
|
return;
|
|
10287
10335
|
}
|
|
10288
10336
|
maybeSendProjectIdentitySessionWarning(sessionId, directory);
|
|
10289
|
-
const coverage = await
|
|
10337
|
+
const coverage = await getAutoEmbeddingSessionCoverage2(db, sessionProjectIdentity, sessionId);
|
|
10290
10338
|
if (!coverage.enabled) {
|
|
10291
10339
|
invalidateAutoEmbedSession(sessionId);
|
|
10292
10340
|
return;
|
|
@@ -10296,7 +10344,7 @@ function createMagicContextHook(deps) {
|
|
|
10296
10344
|
return;
|
|
10297
10345
|
await executeEmbedHistory(sessionId, { silent: true });
|
|
10298
10346
|
} catch (error) {
|
|
10299
|
-
|
|
10347
|
+
log2("[magic-context] auto-embed drain failed:", error);
|
|
10300
10348
|
}
|
|
10301
10349
|
})();
|
|
10302
10350
|
};
|
|
@@ -10325,7 +10373,7 @@ function createMagicContextHook(deps) {
|
|
|
10325
10373
|
variant: "warning",
|
|
10326
10374
|
duration: 8000
|
|
10327
10375
|
}
|
|
10328
|
-
}).catch((error) =>
|
|
10376
|
+
}).catch((error) => log2(`[magic-context] rust park toast failed for ${sessionId}:`, error));
|
|
10329
10377
|
};
|
|
10330
10378
|
registerLkgPersistence(createDbLkgPersistence(db));
|
|
10331
10379
|
const transform = createTransform({
|
|
@@ -10343,7 +10391,7 @@ function createMagicContextHook(deps) {
|
|
|
10343
10391
|
protectedTokens: deps.config.protected_tokens,
|
|
10344
10392
|
protectedTokenTierOverrides: deps.config.protectedTokenTierOverrides,
|
|
10345
10393
|
protectedTools: deps.config.protected_tools,
|
|
10346
|
-
|
|
10394
|
+
keepReasoningTokens: deps.config.keep_reasoning_tokens,
|
|
10347
10395
|
commitClusterTrigger: bootHistorian.commitClusterTrigger,
|
|
10348
10396
|
historyRefreshSessions,
|
|
10349
10397
|
deferredHistoryRefreshSessions,
|
|
@@ -10491,7 +10539,7 @@ function createMagicContextHook(deps) {
|
|
|
10491
10539
|
return;
|
|
10492
10540
|
}
|
|
10493
10541
|
lastScheduleCheckMs = now;
|
|
10494
|
-
const runtimeConfigs = buildDreamTaskRuntimeConfigs2(dreaming, "opencode", deps.config.language,
|
|
10542
|
+
const runtimeConfigs = buildDreamTaskRuntimeConfigs2(dreaming, "opencode", deps.config.language, deps.config.smart_notes?.enabled);
|
|
10495
10543
|
const executor = createDreamTaskExecutor({
|
|
10496
10544
|
client: deps.client,
|
|
10497
10545
|
sessionDirectory: deps.directory,
|
|
@@ -10503,6 +10551,7 @@ function createMagicContextHook(deps) {
|
|
|
10503
10551
|
userMemoryCollectionEnabled: userMemoryCollectionEnabled2(dreaming),
|
|
10504
10552
|
language: deps.config.language,
|
|
10505
10553
|
retinaHandoff: deps.config.smart_notes?.retina_handoff === true,
|
|
10554
|
+
smartNotesEnabled: deps.config.smart_notes?.enabled,
|
|
10506
10555
|
transformMode: deps.config.transform_mode,
|
|
10507
10556
|
moduleClient: rustModeModuleClient,
|
|
10508
10557
|
onProgress: (progress, completedTask) => {
|
|
@@ -10520,10 +10569,11 @@ function createMagicContextHook(deps) {
|
|
|
10520
10569
|
executor,
|
|
10521
10570
|
projectMemoryEnabled: deps.config.memory?.enabled !== false
|
|
10522
10571
|
}).catch((error) => {
|
|
10523
|
-
|
|
10572
|
+
log2("[dreamer] scheduled task run failed:", error);
|
|
10524
10573
|
});
|
|
10525
10574
|
};
|
|
10526
10575
|
const commandHandler = createMagicContextCommandHandler({
|
|
10576
|
+
smartNotesEnabled: deps.config.smart_notes?.enabled,
|
|
10527
10577
|
db,
|
|
10528
10578
|
compactionOff,
|
|
10529
10579
|
toastDurationMs: deps.config.toast_duration_ms,
|
|
@@ -10580,7 +10630,7 @@ function createMagicContextHook(deps) {
|
|
|
10580
10630
|
return runManualDream({
|
|
10581
10631
|
db,
|
|
10582
10632
|
projectIdentity: projectPath,
|
|
10583
|
-
tasks: buildDreamTaskRuntimeConfigs2(currentDreamer, "opencode", deps.config.language,
|
|
10633
|
+
tasks: buildDreamTaskRuntimeConfigs2(currentDreamer, "opencode", deps.config.language, deps.config.smart_notes?.enabled),
|
|
10584
10634
|
executor: createDreamTaskExecutor({
|
|
10585
10635
|
client: deps.client,
|
|
10586
10636
|
sessionDirectory: deps.directory,
|
|
@@ -10594,6 +10644,7 @@ function createMagicContextHook(deps) {
|
|
|
10594
10644
|
mural: sampledDream.mural,
|
|
10595
10645
|
memoryInjectionBudgetTokens: deps.config.memory?.injection_budget_tokens,
|
|
10596
10646
|
retinaHandoff: deps.config.smart_notes?.retina_handoff === true,
|
|
10647
|
+
smartNotesEnabled: deps.config.smart_notes?.enabled,
|
|
10597
10648
|
transformMode: deps.config.transform_mode,
|
|
10598
10649
|
moduleClient: rustModeModuleClient,
|
|
10599
10650
|
onProgress: (progress, completedTask) => {
|
|
@@ -10612,6 +10663,7 @@ function createMagicContextHook(deps) {
|
|
|
10612
10663
|
const systemPromptHash = createSystemPromptHashHandler({
|
|
10613
10664
|
db,
|
|
10614
10665
|
dreamerEnabled: dreamerRunnable,
|
|
10666
|
+
smartNotesEnabled: deps.config.smart_notes?.enabled,
|
|
10615
10667
|
memoryEnabled: deps.config.memory?.enabled !== false,
|
|
10616
10668
|
language: deps.config.language,
|
|
10617
10669
|
promptSurface: deps.config.prompt_surface,
|
|
@@ -10737,7 +10789,7 @@ async function createMagicContextHookAsync(deps) {
|
|
|
10737
10789
|
database = await openDatabaseAsync({ onBootTimings: deps.onStorageBootTimings });
|
|
10738
10790
|
} catch (error) {
|
|
10739
10791
|
const reason = getErrorMessage(error);
|
|
10740
|
-
|
|
10792
|
+
log2("[magic-context] hook failed to open storage; disabling feature:", error);
|
|
10741
10793
|
notifyMagicContextDisabled(deps.client, reason);
|
|
10742
10794
|
clearHookInitFailure();
|
|
10743
10795
|
recordHookInitFailure({
|
|
@@ -10794,10 +10846,803 @@ async function createSessionHooksAsync(args) {
|
|
|
10794
10846
|
};
|
|
10795
10847
|
}
|
|
10796
10848
|
|
|
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";
|
|
10858
|
+
import * as path4 from "node:path";
|
|
10859
|
+
|
|
10860
|
+
// src/shared/host-stall-profiler-report.ts
|
|
10861
|
+
import { readFileSync as readFileSync4 } from "node:fs";
|
|
10862
|
+
import * as path3 from "node:path";
|
|
10863
|
+
var MAX_STACK_DEPTH = 64;
|
|
10864
|
+
var TOP_STACK_COUNT = 30;
|
|
10865
|
+
var TOP_FRAME_COUNT = 30;
|
|
10866
|
+
var UNKNOWN_POSITION = 4294967295;
|
|
10867
|
+
var BACKGROUND_OWNERS = new Set(["native", "runtime", "opencode", "pi", "omp"]);
|
|
10868
|
+
var packageNameCache = new Map;
|
|
10869
|
+
function urlToPath(url) {
|
|
10870
|
+
if (url.startsWith("file://")) {
|
|
10871
|
+
try {
|
|
10872
|
+
return decodeURIComponent(new URL(url).pathname);
|
|
10873
|
+
} catch {
|
|
10874
|
+
return url.slice("file://".length);
|
|
10875
|
+
}
|
|
10876
|
+
}
|
|
10877
|
+
return url;
|
|
10878
|
+
}
|
|
10879
|
+
function nearestPackageName(filePath) {
|
|
10880
|
+
let dir = path3.dirname(filePath);
|
|
10881
|
+
const visited = [];
|
|
10882
|
+
for (let depth = 0;depth < 12; depth++) {
|
|
10883
|
+
const cached = packageNameCache.get(dir);
|
|
10884
|
+
if (cached !== undefined) {
|
|
10885
|
+
for (const seen of visited)
|
|
10886
|
+
packageNameCache.set(seen, cached);
|
|
10887
|
+
return cached;
|
|
10888
|
+
}
|
|
10889
|
+
visited.push(dir);
|
|
10890
|
+
try {
|
|
10891
|
+
const parsed = JSON.parse(readFileSync4(path3.join(dir, "package.json"), "utf8"));
|
|
10892
|
+
const name = typeof parsed.name === "string" && parsed.name ? parsed.name : null;
|
|
10893
|
+
if (name) {
|
|
10894
|
+
for (const seen of visited)
|
|
10895
|
+
packageNameCache.set(seen, name);
|
|
10896
|
+
return name;
|
|
10897
|
+
}
|
|
10898
|
+
} catch {}
|
|
10899
|
+
const parent = path3.dirname(dir);
|
|
10900
|
+
if (parent === dir)
|
|
10901
|
+
break;
|
|
10902
|
+
dir = parent;
|
|
10903
|
+
}
|
|
10904
|
+
for (const seen of visited)
|
|
10905
|
+
packageNameCache.set(seen, null);
|
|
10906
|
+
return null;
|
|
10907
|
+
}
|
|
10908
|
+
function sourceOwner(sourceURL) {
|
|
10909
|
+
if (!sourceURL)
|
|
10910
|
+
return "native";
|
|
10911
|
+
if (/^(?:node|bun|builtin|internal):/.test(sourceURL))
|
|
10912
|
+
return "runtime";
|
|
10913
|
+
if (sourceURL.includes("$bunfs") || sourceURL.includes("~BUN"))
|
|
10914
|
+
return "opencode";
|
|
10915
|
+
const filePath = urlToPath(sourceURL).replaceAll("\\", "/");
|
|
10916
|
+
const modules = [...filePath.matchAll(/\/node_modules\/((?:@[^/]+\/)?[^/]+)/g)];
|
|
10917
|
+
const innermost = modules.at(-1);
|
|
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
|
+
}
|
|
10933
|
+
const pluginDir = filePath.match(/\/plugins?\/([^/]+)$/);
|
|
10934
|
+
if (pluginDir && /\/(?:\.?opencode)\/plugins?\//.test(filePath)) {
|
|
10935
|
+
return `plugin:${pluginDir[1]}`;
|
|
10936
|
+
}
|
|
10937
|
+
const name = nearestPackageName(filePath);
|
|
10938
|
+
return name ? `pkg:${name}` : `file:${filePath}`;
|
|
10939
|
+
}
|
|
10940
|
+
function frameLabel(frame) {
|
|
10941
|
+
const name = frame.name && frame.name.length > 0 ? frame.name : "(anonymous)";
|
|
10942
|
+
if (!frame.sourceURL)
|
|
10943
|
+
return `${name} [native]`;
|
|
10944
|
+
const line = typeof frame.line === "number" && frame.line !== UNKNOWN_POSITION ? `:${frame.line}` : "";
|
|
10945
|
+
return `${name} ${frame.sourceURL}${line}`;
|
|
10946
|
+
}
|
|
10947
|
+
function attributeSample(frames) {
|
|
10948
|
+
for (const frame of frames) {
|
|
10949
|
+
if (!BACKGROUND_OWNERS.has(frame.owner))
|
|
10950
|
+
return frame.owner;
|
|
10951
|
+
}
|
|
10952
|
+
for (const frame of frames) {
|
|
10953
|
+
if (frame.owner !== "native")
|
|
10954
|
+
return frame.owner;
|
|
10955
|
+
}
|
|
10956
|
+
return "native";
|
|
10957
|
+
}
|
|
10958
|
+
function bump(map, key, init) {
|
|
10959
|
+
const existing = map.get(key);
|
|
10960
|
+
if (existing)
|
|
10961
|
+
existing.samples += 1;
|
|
10962
|
+
else
|
|
10963
|
+
map.set(key, { ...init(), samples: 1 });
|
|
10964
|
+
}
|
|
10965
|
+
function topBySamples(values, limit) {
|
|
10966
|
+
return [...values].sort((a, b) => b.samples - a.samples).slice(0, limit);
|
|
10967
|
+
}
|
|
10968
|
+
function aggregateTraces(traces) {
|
|
10969
|
+
const ownerOf = new Map;
|
|
10970
|
+
const owned = (frame) => {
|
|
10971
|
+
const url = frame.sourceURL ?? "";
|
|
10972
|
+
let owner = ownerOf.get(url);
|
|
10973
|
+
if (owner === undefined) {
|
|
10974
|
+
owner = sourceOwner(frame.sourceURL);
|
|
10975
|
+
ownerOf.set(url, owner);
|
|
10976
|
+
}
|
|
10977
|
+
return { label: frameLabel(frame), owner };
|
|
10978
|
+
};
|
|
10979
|
+
const owners = new Map;
|
|
10980
|
+
const topFrames = new Map;
|
|
10981
|
+
const topJsFrames = new Map;
|
|
10982
|
+
const stacks = new Map;
|
|
10983
|
+
let samples = 0;
|
|
10984
|
+
for (const trace of traces) {
|
|
10985
|
+
const raw = Array.isArray(trace.frames) ? trace.frames : [];
|
|
10986
|
+
if (raw.length === 0)
|
|
10987
|
+
continue;
|
|
10988
|
+
samples += 1;
|
|
10989
|
+
const frames = raw.slice(0, MAX_STACK_DEPTH).map(owned);
|
|
10990
|
+
const owner = attributeSample(frames);
|
|
10991
|
+
bump(owners, owner, () => ({ owner }));
|
|
10992
|
+
const leaf = frames[0];
|
|
10993
|
+
bump(topFrames, `${leaf.owner}\x00${leaf.label}`, () => ({
|
|
10994
|
+
frame: leaf.label,
|
|
10995
|
+
owner: leaf.owner
|
|
10996
|
+
}));
|
|
10997
|
+
const jsIndex = raw.findIndex((frame, index) => index < MAX_STACK_DEPTH && !!frame.sourceURL);
|
|
10998
|
+
if (jsIndex >= 0) {
|
|
10999
|
+
const js = frames[jsIndex];
|
|
11000
|
+
bump(topJsFrames, `${js.owner}\x00${js.label}`, () => ({
|
|
11001
|
+
frame: js.label,
|
|
11002
|
+
owner: js.owner
|
|
11003
|
+
}));
|
|
11004
|
+
}
|
|
11005
|
+
const labels = frames.map((frame) => `${frame.label} (${frame.owner})`);
|
|
11006
|
+
if (raw.length > MAX_STACK_DEPTH) {
|
|
11007
|
+
labels.push(`… ${raw.length - MAX_STACK_DEPTH} outer frames omitted`);
|
|
11008
|
+
}
|
|
11009
|
+
bump(stacks, labels.join(`
|
|
11010
|
+
`), () => ({ owner, frames: labels }));
|
|
11011
|
+
}
|
|
11012
|
+
return {
|
|
11013
|
+
samples,
|
|
11014
|
+
owners: topBySamples(owners.values(), Number.POSITIVE_INFINITY).map((entry) => ({
|
|
11015
|
+
...entry,
|
|
11016
|
+
percent: samples === 0 ? 0 : Math.round(entry.samples / samples * 1000) / 10
|
|
11017
|
+
})),
|
|
11018
|
+
top_frames: topBySamples(topFrames.values(), TOP_FRAME_COUNT),
|
|
11019
|
+
top_js_frames: topBySamples(topJsFrames.values(), TOP_FRAME_COUNT),
|
|
11020
|
+
top_stacks: topBySamples(stacks.values(), TOP_STACK_COUNT)
|
|
11021
|
+
};
|
|
11022
|
+
}
|
|
11023
|
+
|
|
11024
|
+
// src/shared/host-stall-profiler-common.ts
|
|
11025
|
+
var HOST_PROFILER_DIRNAME = "host-profiler";
|
|
11026
|
+
var HOST_PROFILER_ENABLE_FILENAME = "enable";
|
|
11027
|
+
var SWITCH_POLL_MS = 5000;
|
|
11028
|
+
var WATCHDOG_INTERVAL_MS = 250;
|
|
11029
|
+
var DEFAULT_STALL_THRESHOLD_MS = 3000;
|
|
11030
|
+
var DEFAULT_SAMPLE_INTERVAL_MS = 10;
|
|
11031
|
+
var MAX_REPORT_FILES = 50;
|
|
11032
|
+
var MAX_SAMPLES_PER_WINDOW = 20000;
|
|
11033
|
+
var PROFILE_WINDOW_MS = 1e4;
|
|
11034
|
+
function parseEnableFile(content) {
|
|
11035
|
+
const options = {
|
|
11036
|
+
thresholdMs: DEFAULT_STALL_THRESHOLD_MS,
|
|
11037
|
+
sampleIntervalMs: DEFAULT_SAMPLE_INTERVAL_MS
|
|
11038
|
+
};
|
|
11039
|
+
if (!content.trim())
|
|
11040
|
+
return { options, error: null };
|
|
11041
|
+
try {
|
|
11042
|
+
const parsed = JSON.parse(content);
|
|
11043
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
11044
|
+
return { options, error: "enable file is not a JSON object" };
|
|
11045
|
+
}
|
|
11046
|
+
if (typeof parsed.threshold_ms === "number" && Number.isFinite(parsed.threshold_ms)) {
|
|
11047
|
+
options.thresholdMs = Math.min(600000, Math.max(500, parsed.threshold_ms));
|
|
11048
|
+
}
|
|
11049
|
+
if (typeof parsed.sample_interval_ms === "number" && Number.isFinite(parsed.sample_interval_ms)) {
|
|
11050
|
+
options.sampleIntervalMs = Math.min(100, Math.max(1, parsed.sample_interval_ms));
|
|
11051
|
+
}
|
|
11052
|
+
return { options, error: null };
|
|
11053
|
+
} catch (error) {
|
|
11054
|
+
return {
|
|
11055
|
+
options,
|
|
11056
|
+
error: `enable file is not valid JSON (${error instanceof Error ? error.message : String(error)})`
|
|
11057
|
+
};
|
|
11058
|
+
}
|
|
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;
|
|
11120
|
+
function asJscApi(module) {
|
|
11121
|
+
const candidate = module ?? null;
|
|
11122
|
+
for (const value of [candidate, candidate?.default]) {
|
|
11123
|
+
const api = value;
|
|
11124
|
+
if (api && typeof api.startSamplingProfiler === "function" && typeof api.samplingProfilerStackTraces === "function" && typeof api.profile === "function") {
|
|
11125
|
+
return api;
|
|
11126
|
+
}
|
|
11127
|
+
}
|
|
11128
|
+
return null;
|
|
11129
|
+
}
|
|
11130
|
+
function createHostStallProfiler(deps) {
|
|
11131
|
+
let jsc = null;
|
|
11132
|
+
let unavailable = false;
|
|
11133
|
+
let pollTimer = null;
|
|
11134
|
+
let watchdog = null;
|
|
11135
|
+
let options = {
|
|
11136
|
+
thresholdMs: DEFAULT_STALL_THRESHOLD_MS,
|
|
11137
|
+
sampleIntervalMs: DEFAULT_SAMPLE_INTERVAL_MS
|
|
11138
|
+
};
|
|
11139
|
+
let lastTickAt = 0;
|
|
11140
|
+
let tickCount = 0;
|
|
11141
|
+
let memoryBefore = null;
|
|
11142
|
+
let clockOffsetMs = null;
|
|
11143
|
+
let checking = null;
|
|
11144
|
+
const loggedOnce = new Set;
|
|
11145
|
+
const safeLog = (message) => {
|
|
11146
|
+
try {
|
|
11147
|
+
deps.log(message);
|
|
11148
|
+
} catch {}
|
|
11149
|
+
};
|
|
11150
|
+
const logOnce = (key, message, error) => {
|
|
11151
|
+
if (loggedOnce.has(key))
|
|
11152
|
+
return;
|
|
11153
|
+
loggedOnce.add(key);
|
|
11154
|
+
const detail = error === undefined ? "" : `: ${error instanceof Error ? error.message : String(error)}`;
|
|
11155
|
+
safeLog(`[magic-context] host stall profiler: ${message}${detail}`);
|
|
11156
|
+
};
|
|
11157
|
+
const drain = (api) => {
|
|
11158
|
+
const raw = api.samplingProfilerStackTraces();
|
|
11159
|
+
return Array.isArray(raw?.traces) ? raw.traces : [];
|
|
11160
|
+
};
|
|
11161
|
+
const pauseSampler = (api, intervalMs) => {
|
|
11162
|
+
try {
|
|
11163
|
+
drain(api);
|
|
11164
|
+
} catch {}
|
|
11165
|
+
api.profile(() => {
|
|
11166
|
+
return;
|
|
11167
|
+
}, Math.round(intervalMs * 1000));
|
|
11168
|
+
drain(api);
|
|
11169
|
+
};
|
|
11170
|
+
const calibrate = (api) => {
|
|
11171
|
+
pauseSampler(api, 1);
|
|
11172
|
+
api.startSamplingProfiler();
|
|
11173
|
+
let offset = null;
|
|
11174
|
+
for (let chunk = 0;chunk < CALIBRATION_MAX_CHUNKS && offset === null; chunk++) {
|
|
11175
|
+
const start = deps.now();
|
|
11176
|
+
let end = start;
|
|
11177
|
+
for (let i = 0;i < 50000000 && end - start < CALIBRATION_CHUNK_MS; i++) {
|
|
11178
|
+
end = deps.now();
|
|
11179
|
+
}
|
|
11180
|
+
const stamps = drain(api).map((trace) => trace.timestamp).filter((value) => typeof value === "number" && Number.isFinite(value)).map((seconds) => seconds * 1000);
|
|
11181
|
+
if (stamps.length >= 2) {
|
|
11182
|
+
offset = (Math.max(...stamps) - end + (Math.min(...stamps) - start)) / 2;
|
|
11183
|
+
}
|
|
11184
|
+
}
|
|
11185
|
+
pauseSampler(api, 1);
|
|
11186
|
+
return offset;
|
|
11187
|
+
};
|
|
11188
|
+
const snapshot = (api) => {
|
|
11189
|
+
const read = (fn) => {
|
|
11190
|
+
try {
|
|
11191
|
+
return fn();
|
|
11192
|
+
} catch {
|
|
11193
|
+
return null;
|
|
11194
|
+
}
|
|
11195
|
+
};
|
|
11196
|
+
return {
|
|
11197
|
+
at: new Date(deps.wallNow()).toISOString(),
|
|
11198
|
+
heap_size_bytes: read(() => api.heapSize?.() ?? null),
|
|
11199
|
+
jsc_memory: read(() => api.memoryUsage?.() ?? null),
|
|
11200
|
+
rss_bytes: read(() => deps.rss()),
|
|
11201
|
+
percent_available_memory_in_use: read(() => api.percentAvailableMemoryInUse?.() ?? null)
|
|
11202
|
+
};
|
|
11203
|
+
};
|
|
11204
|
+
const recordStall = (api, startMs, endMs, traces) => {
|
|
11205
|
+
const after = snapshot(api);
|
|
11206
|
+
let windowed = traces;
|
|
11207
|
+
let windowFilter = "since-last-collection";
|
|
11208
|
+
if (clockOffsetMs !== null) {
|
|
11209
|
+
const slackMs = 2 * options.sampleIntervalMs + 20;
|
|
11210
|
+
const lo = startMs + clockOffsetMs - slackMs;
|
|
11211
|
+
const hi = endMs + clockOffsetMs + slackMs;
|
|
11212
|
+
const inWindow = traces.filter((trace) => {
|
|
11213
|
+
const at = typeof trace.timestamp === "number" ? trace.timestamp * 1000 : Number.NaN;
|
|
11214
|
+
return at >= lo && at <= hi;
|
|
11215
|
+
});
|
|
11216
|
+
if (inWindow.length > 0 || traces.length === 0) {
|
|
11217
|
+
windowed = inWindow;
|
|
11218
|
+
windowFilter = "timestamp";
|
|
11219
|
+
} else {
|
|
11220
|
+
windowFilter = "since-last-collection (timestamp filter matched no sample)";
|
|
11221
|
+
}
|
|
11222
|
+
}
|
|
11223
|
+
emitStallReport(deps, {
|
|
11224
|
+
startMs,
|
|
11225
|
+
endMs,
|
|
11226
|
+
traces,
|
|
11227
|
+
windowed,
|
|
11228
|
+
windowFilter,
|
|
11229
|
+
options,
|
|
11230
|
+
before: memoryBefore,
|
|
11231
|
+
after,
|
|
11232
|
+
backend: "jsc"
|
|
11233
|
+
});
|
|
11234
|
+
memoryBefore = after;
|
|
11235
|
+
};
|
|
11236
|
+
const tick = () => {
|
|
11237
|
+
const api = jsc;
|
|
11238
|
+
if (!api || watchdog === null)
|
|
11239
|
+
return;
|
|
11240
|
+
try {
|
|
11241
|
+
const now = deps.now();
|
|
11242
|
+
const startMs = lastTickAt;
|
|
11243
|
+
lastTickAt = now;
|
|
11244
|
+
const traces = drain(api);
|
|
11245
|
+
if (now - startMs - WATCHDOG_INTERVAL_MS >= options.thresholdMs) {
|
|
11246
|
+
try {
|
|
11247
|
+
recordStall(api, startMs, now, traces);
|
|
11248
|
+
} catch (error) {
|
|
11249
|
+
logOnce("report", "could not write a stall report", error);
|
|
11250
|
+
}
|
|
11251
|
+
}
|
|
11252
|
+
tickCount += 1;
|
|
11253
|
+
if (tickCount % MEMORY_SNAPSHOT_EVERY_TICKS === 0)
|
|
11254
|
+
memoryBefore = snapshot(api);
|
|
11255
|
+
} catch (error) {
|
|
11256
|
+
logOnce("tick", "watchdog tick failed", error);
|
|
11257
|
+
}
|
|
11258
|
+
};
|
|
11259
|
+
const enable = (api, next) => {
|
|
11260
|
+
const startedAt = deps.now();
|
|
11261
|
+
try {
|
|
11262
|
+
options = next;
|
|
11263
|
+
clockOffsetMs = calibrate(api);
|
|
11264
|
+
pauseSampler(api, options.sampleIntervalMs);
|
|
11265
|
+
api.startSamplingProfiler();
|
|
11266
|
+
lastTickAt = deps.now();
|
|
11267
|
+
tickCount = 0;
|
|
11268
|
+
memoryBefore = snapshot(api);
|
|
11269
|
+
watchdog = deps.setInterval(tick, WATCHDOG_INTERVAL_MS);
|
|
11270
|
+
safeLog(`[magic-context] host stall profiler enabled: threshold ${options.thresholdMs}ms, sample interval ${options.sampleIntervalMs}ms, clock calibration ${clockOffsetMs === null ? "unavailable" : "ok"}, setup ${Math.round(deps.now() - startedAt)}ms, reports in ${deps.profilerDir()}`);
|
|
11271
|
+
} catch (error) {
|
|
11272
|
+
watchdog = null;
|
|
11273
|
+
try {
|
|
11274
|
+
pauseSampler(api, options.sampleIntervalMs);
|
|
11275
|
+
} catch {}
|
|
11276
|
+
logOnce("enable", "could not start", error);
|
|
11277
|
+
}
|
|
11278
|
+
};
|
|
11279
|
+
const disable = (reason) => {
|
|
11280
|
+
if (watchdog !== null)
|
|
11281
|
+
deps.clearInterval(watchdog);
|
|
11282
|
+
watchdog = null;
|
|
11283
|
+
memoryBefore = null;
|
|
11284
|
+
if (jsc) {
|
|
11285
|
+
try {
|
|
11286
|
+
pauseSampler(jsc, options.sampleIntervalMs);
|
|
11287
|
+
} catch (error) {
|
|
11288
|
+
logOnce("disable", "could not pause the sampler", error);
|
|
11289
|
+
}
|
|
11290
|
+
}
|
|
11291
|
+
safeLog(`[magic-context] host stall profiler disabled: ${reason}`);
|
|
11292
|
+
};
|
|
11293
|
+
const ensureJsc = async () => {
|
|
11294
|
+
if (jsc)
|
|
11295
|
+
return jsc;
|
|
11296
|
+
try {
|
|
11297
|
+
const api = asJscApi(await deps.loadJsc());
|
|
11298
|
+
if (!api)
|
|
11299
|
+
throw new Error("bun:jsc lacks the sampling profiler API");
|
|
11300
|
+
jsc = api;
|
|
11301
|
+
return api;
|
|
11302
|
+
} catch (error) {
|
|
11303
|
+
unavailable = true;
|
|
11304
|
+
if (pollTimer !== null)
|
|
11305
|
+
deps.clearInterval(pollTimer);
|
|
11306
|
+
pollTimer = null;
|
|
11307
|
+
logOnce("jsc", "bun:jsc is unavailable, profiler disabled for this process", error);
|
|
11308
|
+
return null;
|
|
11309
|
+
}
|
|
11310
|
+
};
|
|
11311
|
+
const runCheck = async () => {
|
|
11312
|
+
if (unavailable)
|
|
11313
|
+
return;
|
|
11314
|
+
try {
|
|
11315
|
+
const enablePath = path5.join(deps.profilerDir(), HOST_PROFILER_ENABLE_FILENAME);
|
|
11316
|
+
if (!existsSync6(enablePath)) {
|
|
11317
|
+
if (watchdog !== null)
|
|
11318
|
+
disable("enable file removed");
|
|
11319
|
+
return;
|
|
11320
|
+
}
|
|
11321
|
+
const parsed = parseEnableFile(readFileSync5(enablePath, "utf8"));
|
|
11322
|
+
if (parsed.error)
|
|
11323
|
+
logOnce(`options:${parsed.error}`, parsed.error);
|
|
11324
|
+
if (watchdog !== null) {
|
|
11325
|
+
if (jsc && parsed.options.sampleIntervalMs !== options.sampleIntervalMs) {
|
|
11326
|
+
pauseSampler(jsc, parsed.options.sampleIntervalMs);
|
|
11327
|
+
jsc.startSamplingProfiler();
|
|
11328
|
+
}
|
|
11329
|
+
options = parsed.options;
|
|
11330
|
+
return;
|
|
11331
|
+
}
|
|
11332
|
+
const api = await ensureJsc();
|
|
11333
|
+
if (!api || watchdog !== null || !existsSync6(enablePath))
|
|
11334
|
+
return;
|
|
11335
|
+
enable(api, parsed.options);
|
|
11336
|
+
} catch (error) {
|
|
11337
|
+
logOnce("check", "enable-file check failed", error);
|
|
11338
|
+
}
|
|
11339
|
+
};
|
|
11340
|
+
const checkNow = () => {
|
|
11341
|
+
if (!checking) {
|
|
11342
|
+
checking = runCheck().finally(() => {
|
|
11343
|
+
checking = null;
|
|
11344
|
+
});
|
|
11345
|
+
}
|
|
11346
|
+
return checking;
|
|
11347
|
+
};
|
|
11348
|
+
return {
|
|
11349
|
+
start() {
|
|
11350
|
+
if (pollTimer !== null || unavailable)
|
|
11351
|
+
return;
|
|
11352
|
+
pollTimer = deps.setInterval(() => void checkNow(), SWITCH_POLL_MS);
|
|
11353
|
+
checkNow();
|
|
11354
|
+
},
|
|
11355
|
+
checkNow,
|
|
11356
|
+
stop() {
|
|
11357
|
+
if (pollTimer !== null)
|
|
11358
|
+
deps.clearInterval(pollTimer);
|
|
11359
|
+
pollTimer = null;
|
|
11360
|
+
if (watchdog !== null)
|
|
11361
|
+
disable("stopped");
|
|
11362
|
+
},
|
|
11363
|
+
isActive: () => watchdog !== null,
|
|
11364
|
+
isUnavailable: () => unavailable
|
|
11365
|
+
};
|
|
11366
|
+
}
|
|
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
|
+
});
|
|
11412
|
+
}
|
|
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
|
+
};
|
|
11576
|
+
return {
|
|
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);
|
|
11585
|
+
},
|
|
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
|
|
11599
|
+
};
|
|
11600
|
+
}
|
|
11601
|
+
|
|
11602
|
+
// src/shared/host-stall-profiler.ts
|
|
11603
|
+
function hostStallProfilerDir() {
|
|
11604
|
+
return path7.join(getMagicContextStorageDir(), HOST_PROFILER_DIRNAME);
|
|
11605
|
+
}
|
|
11606
|
+
var PROCESS_PROFILER_KEY = Symbol.for("cortexkit.magic-context.host-stall-profiler");
|
|
11607
|
+
var jscModule = "bun:jsc";
|
|
11608
|
+
function startHostStallProfilerSwitch() {
|
|
11609
|
+
try {
|
|
11610
|
+
const holder = globalThis;
|
|
11611
|
+
if (holder[PROCESS_PROFILER_KEY])
|
|
11612
|
+
return;
|
|
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
|
+
});
|
|
11636
|
+
holder[PROCESS_PROFILER_KEY] = handle;
|
|
11637
|
+
handle.start();
|
|
11638
|
+
} catch (error) {
|
|
11639
|
+
log2("[magic-context] host stall profiler: could not start the enable-file switch", error);
|
|
11640
|
+
}
|
|
11641
|
+
}
|
|
10797
11642
|
// src/plugin/instance-disposal.ts
|
|
10798
|
-
import
|
|
11643
|
+
import path8 from "node:path";
|
|
10799
11644
|
function isDisposedInstanceDirectory(ownDirectory, disposedDirectory) {
|
|
10800
|
-
return
|
|
11645
|
+
return path8.resolve(disposedDirectory) === path8.resolve(ownDirectory);
|
|
10801
11646
|
}
|
|
10802
11647
|
|
|
10803
11648
|
// src/plugin/native-compaction-guard.ts
|
|
@@ -10806,7 +11651,7 @@ function disableNativeAutoCompaction(config) {
|
|
|
10806
11651
|
if (target.compaction?.auto === false)
|
|
10807
11652
|
return false;
|
|
10808
11653
|
target.compaction = { ...target.compaction ?? {}, auto: false };
|
|
10809
|
-
|
|
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");
|
|
10810
11655
|
return true;
|
|
10811
11656
|
}
|
|
10812
11657
|
|
|
@@ -10877,7 +11722,7 @@ function createToolRegistry(args) {
|
|
|
10877
11722
|
return {};
|
|
10878
11723
|
}
|
|
10879
11724
|
ensureProjectRegisteredFromOpenCodeDirectory(ctx.directory, db).catch((error) => {
|
|
10880
|
-
|
|
11725
|
+
log2(`[magic-context] embedding registration skipped: ${getErrorMessage(error)}`);
|
|
10881
11726
|
});
|
|
10882
11727
|
const resolveProjectPath = (directory) => resolveProjectIdentityForSession(directory, pluginConfig.allow_home_project);
|
|
10883
11728
|
const memoryEnabled = pluginConfig.memory?.enabled !== false;
|
|
@@ -10892,6 +11737,7 @@ function createToolRegistry(args) {
|
|
|
10892
11737
|
...createCtxNoteTools({
|
|
10893
11738
|
db,
|
|
10894
11739
|
dreamerEnabled: isDreamerRunnable(pluginConfig),
|
|
11740
|
+
smartNotesEnabled: pluginConfig.smart_notes?.enabled,
|
|
10895
11741
|
resolveProjectPath,
|
|
10896
11742
|
rustToolBackends
|
|
10897
11743
|
}),
|
|
@@ -10917,11 +11763,11 @@ function createToolRegistry(args) {
|
|
|
10917
11763
|
const promptSurfaceRuntime = args.promptSurfaceRuntime ?? createPromptSurfaceRuntime({
|
|
10918
11764
|
harness: "opencode",
|
|
10919
11765
|
directory: ctx.directory,
|
|
10920
|
-
warn: (message) =>
|
|
11766
|
+
warn: (message) => log2(`[magic-context] config warning: ${message}`)
|
|
10921
11767
|
});
|
|
10922
11768
|
const registration = promptSurfaceRuntime.resolveRegistration(args.registrationPromptSurface ?? pluginConfig.prompt_surface);
|
|
10923
11769
|
const surfacedTools = Object.fromEntries(Object.entries(allTools).map(([toolId, definition]) => {
|
|
10924
|
-
const parameterDescriptions = parameterDescriptionsFor(toolId, registration.preset);
|
|
11770
|
+
const parameterDescriptions = parameterDescriptionsFor(toolId, registration.preset, pluginConfig.smart_notes?.enabled);
|
|
10925
11771
|
const argsWithPresetDescriptions = parameterDescriptions ? Object.fromEntries(Object.entries(definition.args).map(([name, schema]) => [
|
|
10926
11772
|
name,
|
|
10927
11773
|
parameterDescriptions[name] ? schema.describe(parameterDescriptions[name]) : schema
|
|
@@ -10931,7 +11777,7 @@ function createToolRegistry(args) {
|
|
|
10931
11777
|
{
|
|
10932
11778
|
...definition,
|
|
10933
11779
|
args: argsWithPresetDescriptions,
|
|
10934
|
-
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 ?? "")
|
|
10935
11781
|
}
|
|
10936
11782
|
];
|
|
10937
11783
|
}));
|
|
@@ -10959,48 +11805,27 @@ function buildOpenCodeConfigWarningBanner(warnings, parseFailures, allParseFailu
|
|
|
10959
11805
|
`);
|
|
10960
11806
|
}
|
|
10961
11807
|
|
|
10962
|
-
// src/shared/exit-abort-registry.ts
|
|
10963
|
-
var controllers = new Set;
|
|
10964
|
-
var listenerRegistered = false;
|
|
10965
|
-
function abortAll() {
|
|
10966
|
-
for (const controller of controllers) {
|
|
10967
|
-
try {
|
|
10968
|
-
controller.abort();
|
|
10969
|
-
} catch {}
|
|
10970
|
-
}
|
|
10971
|
-
}
|
|
10972
|
-
function registerExitAbort(controller) {
|
|
10973
|
-
controllers.add(controller);
|
|
10974
|
-
if (listenerRegistered)
|
|
10975
|
-
return;
|
|
10976
|
-
listenerRegistered = true;
|
|
10977
|
-
process.once("exit", abortAll);
|
|
10978
|
-
}
|
|
10979
|
-
function unregisterExitAbort(controller) {
|
|
10980
|
-
controllers.delete(controller);
|
|
10981
|
-
}
|
|
10982
|
-
|
|
10983
11808
|
// src/v2/hooks/update-check.ts
|
|
10984
|
-
import { existsSync as
|
|
10985
|
-
import { dirname as
|
|
11809
|
+
import { existsSync as existsSync8, readFileSync as readFileSync7 } from "node:fs";
|
|
11810
|
+
import { dirname as dirname4, join as join10 } from "node:path";
|
|
10986
11811
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
10987
11812
|
var cachedPackageInfo;
|
|
10988
11813
|
function packageInfo() {
|
|
10989
11814
|
if (cachedPackageInfo)
|
|
10990
11815
|
return cachedPackageInfo;
|
|
10991
|
-
let directory =
|
|
11816
|
+
let directory = dirname4(fileURLToPath2(import.meta.url));
|
|
10992
11817
|
for (;; ) {
|
|
10993
11818
|
try {
|
|
10994
|
-
const pkg = JSON.parse(
|
|
11819
|
+
const pkg = JSON.parse(readFileSync7(join10(directory, "package.json"), "utf8"));
|
|
10995
11820
|
if (pkg.name === "@cortexkit/opencode-magic-context" && typeof pkg.version === "string") {
|
|
10996
11821
|
cachedPackageInfo = {
|
|
10997
11822
|
version: pkg.version,
|
|
10998
|
-
development:
|
|
11823
|
+
development: existsSync8(join10(directory, "src/v2/server.ts"))
|
|
10999
11824
|
};
|
|
11000
11825
|
return cachedPackageInfo;
|
|
11001
11826
|
}
|
|
11002
11827
|
} catch {}
|
|
11003
|
-
const parent =
|
|
11828
|
+
const parent = dirname4(directory);
|
|
11004
11829
|
if (parent === directory)
|
|
11005
11830
|
throw new Error("Magic Context package manifest is unavailable");
|
|
11006
11831
|
directory = parent;
|
|
@@ -11041,7 +11866,7 @@ function startUpdateChecks(context, check = (signal) => {
|
|
|
11041
11866
|
}
|
|
11042
11867
|
} catch (error) {
|
|
11043
11868
|
if (!controller.signal.aborted)
|
|
11044
|
-
|
|
11869
|
+
log2("[magic-context] v2 update check unavailable", error);
|
|
11045
11870
|
}
|
|
11046
11871
|
})();
|
|
11047
11872
|
return {
|
|
@@ -11062,16 +11887,16 @@ function isOpenCode2HostContext(context) {
|
|
|
11062
11887
|
}
|
|
11063
11888
|
async function setup(context) {
|
|
11064
11889
|
if (!isOpenCode2HostContext(context)) {
|
|
11065
|
-
|
|
11890
|
+
log2("v2 setup() called on a host without session.hook; v1 server lane owns this host, v2 lane inert");
|
|
11066
11891
|
return async () => {};
|
|
11067
11892
|
}
|
|
11068
|
-
const { registerContext } = await import("./context-
|
|
11069
|
-
|
|
11893
|
+
const { registerContext } = await import("./context-m0cy262m.js");
|
|
11894
|
+
setHarness2("opencode2");
|
|
11070
11895
|
bindStaleBuildNotice({}, import.meta.url, "opencode2");
|
|
11071
11896
|
const duties = await registerContext(context);
|
|
11072
11897
|
const checks = loadPluginConfigDetailed(context.location.directory).config.auto_update === false ? undefined : startUpdateChecks(context);
|
|
11073
|
-
|
|
11074
|
-
|
|
11898
|
+
log2("[magic-context] @cortexkit/opencode-magic-context v2 setup");
|
|
11899
|
+
flushLogger2();
|
|
11075
11900
|
return async () => {
|
|
11076
11901
|
await checks?.dispose();
|
|
11077
11902
|
await duties?.dispose();
|
|
@@ -11091,13 +11916,14 @@ var server = async (ctx) => {
|
|
|
11091
11916
|
let rpcMs = 0;
|
|
11092
11917
|
let hooksDeadlineReason = null;
|
|
11093
11918
|
let deadlinePhase = null;
|
|
11094
|
-
emitBootEnteringBreadcrumb(process.pid, ctx.directory,
|
|
11095
|
-
|
|
11919
|
+
emitBootEnteringBreadcrumb(process.pid, ctx.directory, log2, flushLogger2);
|
|
11920
|
+
setHarness2("opencode");
|
|
11921
|
+
startHostStallProfilerSwitch();
|
|
11096
11922
|
const configStartedAt = performance.now();
|
|
11097
11923
|
beginBootQuietPeriod();
|
|
11098
11924
|
const configMigrationWarnings = migrateMagicContextConfigLocations(ctx.directory, {
|
|
11099
|
-
warn: (m) =>
|
|
11100
|
-
info: (m) =>
|
|
11925
|
+
warn: (m) => log2(`[magic-context] ${m}`),
|
|
11926
|
+
info: (m) => log2(`[magic-context] ${m}`)
|
|
11101
11927
|
});
|
|
11102
11928
|
const loadedPluginConfig = loadPluginConfigDetailed(ctx.directory);
|
|
11103
11929
|
const pluginConfig = loadedPluginConfig.config;
|
|
@@ -11108,7 +11934,7 @@ var server = async (ctx) => {
|
|
|
11108
11934
|
const promptSurfaceRuntime = createPromptSurfaceRuntime({
|
|
11109
11935
|
harness: "opencode",
|
|
11110
11936
|
directory: ctx.directory,
|
|
11111
|
-
warn: (message) =>
|
|
11937
|
+
warn: (message) => log2(`[magic-context] config warning: ${message}`)
|
|
11112
11938
|
});
|
|
11113
11939
|
if (configMigrationWarnings.length > 0) {
|
|
11114
11940
|
pluginConfig.configWarnings = [
|
|
@@ -11126,7 +11952,7 @@ var server = async (ctx) => {
|
|
|
11126
11952
|
registerExitAbort(autoUpdateAbort);
|
|
11127
11953
|
if (pluginConfig.configWarnings?.length) {
|
|
11128
11954
|
for (const w of pluginConfig.configWarnings) {
|
|
11129
|
-
|
|
11955
|
+
log2(`[magic-context] config warning: ${w}`);
|
|
11130
11956
|
}
|
|
11131
11957
|
const allParseFailures = loadedPluginConfig.configParseFailures;
|
|
11132
11958
|
const parseFailuresToShow = claimConfigParseFailuresOnce("opencode", allParseFailures);
|
|
@@ -11135,7 +11961,7 @@ var server = async (ctx) => {
|
|
|
11135
11961
|
if (hasBannerEntries)
|
|
11136
11962
|
setTimeout(async () => {
|
|
11137
11963
|
try {
|
|
11138
|
-
const { sendStatusNotification } = await importPluginModule(() => import("./send-session-notification-
|
|
11964
|
+
const { sendStatusNotification } = await importPluginModule(() => import("./send-session-notification-erecz4y4.js"));
|
|
11139
11965
|
const clientWithSessions = ctx.client;
|
|
11140
11966
|
const sessions = await Promise.resolve(clientWithSessions.session?.list?.()).catch(() => null);
|
|
11141
11967
|
const sessionList = Array.isArray(sessions) ? sessions : sessions?.data;
|
|
@@ -11149,10 +11975,10 @@ var server = async (ctx) => {
|
|
|
11149
11975
|
const openCodeDbResolution = resolveOpenCodeDbPath();
|
|
11150
11976
|
if (!openCodeDbPathExists(openCodeDbResolution) && claimOpenCodeDbDiagnosticOnce("boot-banner", openCodeDbResolution)) {
|
|
11151
11977
|
const missingDbBanner = formatOpenCodeDbMissingBanner(openCodeDbResolution);
|
|
11152
|
-
|
|
11978
|
+
log2(`[magic-context] opencode_db_missing path=${openCodeDbResolution.path} source=${openCodeDbResolution.source}`);
|
|
11153
11979
|
setTimeout(async () => {
|
|
11154
11980
|
try {
|
|
11155
|
-
const { sendStatusNotification } = await importPluginModule(() => import("./send-session-notification-
|
|
11981
|
+
const { sendStatusNotification } = await importPluginModule(() => import("./send-session-notification-erecz4y4.js"));
|
|
11156
11982
|
const clientWithSessions = ctx.client;
|
|
11157
11983
|
const sessions = await Promise.resolve(clientWithSessions.session?.list?.()).catch(() => null);
|
|
11158
11984
|
const sessionList = Array.isArray(sessions) ? sessions : sessions?.data;
|
|
@@ -11169,7 +11995,7 @@ var server = async (ctx) => {
|
|
|
11169
11995
|
const resolvedConfigTimeoutMs = Math.min(RESOLVED_CONFIG_TIMEOUT_MS, remainingBootBudgetMs(bootBudget));
|
|
11170
11996
|
const resolvedCompaction = resolvedConfigTimeoutMs > 0 ? await resolveCompactionForBoot(ctx.client, resolvedConfigTimeoutMs) : null;
|
|
11171
11997
|
if (resolvedCompaction === null) {
|
|
11172
|
-
|
|
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)");
|
|
11173
11999
|
}
|
|
11174
12000
|
conflictResult = detectConflicts(ctx.directory, {
|
|
11175
12001
|
compactionEnabled: isCompactionEnabled(pluginConfig),
|
|
@@ -11177,9 +12003,9 @@ var server = async (ctx) => {
|
|
|
11177
12003
|
});
|
|
11178
12004
|
if (conflictResult.hasConflict) {
|
|
11179
12005
|
pluginConfig.enabled = false;
|
|
11180
|
-
|
|
12006
|
+
log2(`[magic-context] disabled due to conflicts: ${conflictResult.reasons.join("; ")}`);
|
|
11181
12007
|
} else {
|
|
11182
|
-
|
|
12008
|
+
log2("[magic-context] no conflicts detected, plugin enabled");
|
|
11183
12009
|
}
|
|
11184
12010
|
}
|
|
11185
12011
|
conflictMs = performance.now() - conflictStartedAt;
|
|
@@ -11195,7 +12021,7 @@ var server = async (ctx) => {
|
|
|
11195
12021
|
rustModeModuleClient,
|
|
11196
12022
|
promptSurfaceRuntime,
|
|
11197
12023
|
onStorageBootTimings: (timings) => Object.assign(storageBootTimings, timings)
|
|
11198
|
-
}),
|
|
12024
|
+
}), log2);
|
|
11199
12025
|
const hooks = hooksPhase.status === "completed" ? hooksPhase.value : { magicContext: null, rustToolBackends: undefined };
|
|
11200
12026
|
if (hooksPhase.status === "timed_out") {
|
|
11201
12027
|
deadlinePhase = "hooks";
|
|
@@ -11213,7 +12039,7 @@ var server = async (ctx) => {
|
|
|
11213
12039
|
const storageFailureReason = hooksDeadlineReason ? { kind: "storage_failure", cause: hooksDeadlineReason } : initFailure?.type === "storage" ? initFailure.reason : null;
|
|
11214
12040
|
if (storageFailureReason) {
|
|
11215
12041
|
failClosed.arm(storageFailureReason);
|
|
11216
|
-
|
|
12042
|
+
log2(`[magic-context] fail-closed blocking armed (${storageFailureReason.kind}); primary sessions will error until storage recovers or the build is upgraded`);
|
|
11217
12043
|
}
|
|
11218
12044
|
}
|
|
11219
12045
|
if (hooksPhase.status === "timed_out") {
|
|
@@ -11223,7 +12049,7 @@ var server = async (ctx) => {
|
|
|
11223
12049
|
magicContextRuntime.magicContext = late.magicContext;
|
|
11224
12050
|
magicContextRuntime.rustToolBackends = late.rustToolBackends;
|
|
11225
12051
|
failClosed.clear();
|
|
11226
|
-
|
|
12052
|
+
log2("[magic-context] boot hooks phase settled after its deadline; Magic Context runtime installed and fail-closed cleared");
|
|
11227
12053
|
});
|
|
11228
12054
|
}
|
|
11229
12055
|
const tryReopenStorage = async () => {
|
|
@@ -11245,10 +12071,10 @@ var server = async (ctx) => {
|
|
|
11245
12071
|
magicContextRuntime.magicContext = reopened.magicContext;
|
|
11246
12072
|
magicContextRuntime.rustToolBackends = reopened.rustToolBackends;
|
|
11247
12073
|
failClosed.clear();
|
|
11248
|
-
|
|
12074
|
+
log2("[magic-context] storage re-probe succeeded; Magic Context runtime restored");
|
|
11249
12075
|
return true;
|
|
11250
12076
|
} catch (error) {
|
|
11251
|
-
|
|
12077
|
+
log2(`[magic-context] storage re-probe failed: ${error}`);
|
|
11252
12078
|
return false;
|
|
11253
12079
|
}
|
|
11254
12080
|
};
|
|
@@ -11267,12 +12093,12 @@ var server = async (ctx) => {
|
|
|
11267
12093
|
if (db && isDatabasePersisted(db)) {
|
|
11268
12094
|
scheduleAfterBootQuiet(() => {
|
|
11269
12095
|
runDeferredV22Backfill(db).catch((err) => {
|
|
11270
|
-
|
|
12096
|
+
log2(`[v22-backfill] background runner failed: ${err}`);
|
|
11271
12097
|
});
|
|
11272
12098
|
});
|
|
11273
12099
|
}
|
|
11274
12100
|
} catch (err) {
|
|
11275
|
-
|
|
12101
|
+
log2(`[v22-backfill] failed to start background runner: ${err}`);
|
|
11276
12102
|
}
|
|
11277
12103
|
}
|
|
11278
12104
|
if (pluginConfig.enabled && magicContextRuntime.magicContext) {
|
|
@@ -11310,7 +12136,7 @@ var server = async (ctx) => {
|
|
|
11310
12136
|
closeQuietly(ocDb);
|
|
11311
12137
|
}
|
|
11312
12138
|
})().catch((err) => {
|
|
11313
|
-
|
|
12139
|
+
log2(`[session-projects] background runner failed: ${err}`);
|
|
11314
12140
|
});
|
|
11315
12141
|
}, 0);
|
|
11316
12142
|
}
|
|
@@ -11322,7 +12148,7 @@ var server = async (ctx) => {
|
|
|
11322
12148
|
const classifyModuleClient = createDreamTimerModuleClient(rustModeModuleClient);
|
|
11323
12149
|
const timerProjectIdentity = resolveProjectIdentityForSession(ctx.directory, pluginConfig.allow_home_project);
|
|
11324
12150
|
if (!timerProjectIdentity) {
|
|
11325
|
-
|
|
12151
|
+
log2("[magic-context] dream timer skipped: no project identity is bound for this directory");
|
|
11326
12152
|
} else {
|
|
11327
12153
|
const timerRegistration = {
|
|
11328
12154
|
directory: ctx.directory,
|
|
@@ -11360,6 +12186,7 @@ var server = async (ctx) => {
|
|
|
11360
12186
|
},
|
|
11361
12187
|
mural: pluginConfig.mural,
|
|
11362
12188
|
retinaHandoff: pluginConfig.smart_notes.retina_handoff,
|
|
12189
|
+
smartNotesEnabled: pluginConfig.smart_notes.enabled,
|
|
11363
12190
|
gitCommitIndexing: pluginConfig.memory.git_commit_indexing?.enabled ? {
|
|
11364
12191
|
enabled: true,
|
|
11365
12192
|
since_days: pluginConfig.memory.git_commit_indexing.since_days,
|
|
@@ -11380,7 +12207,7 @@ var server = async (ctx) => {
|
|
|
11380
12207
|
startDreamScheduleTimer(timerRegistration).then((stop) => {
|
|
11381
12208
|
stopDreamTimerRegistration = stop;
|
|
11382
12209
|
}).catch((err) => {
|
|
11383
|
-
|
|
12210
|
+
log2(`[magic-context] dream timer registration failed (continuing without it): ${err}`);
|
|
11384
12211
|
});
|
|
11385
12212
|
}, 0);
|
|
11386
12213
|
}
|
|
@@ -11398,9 +12225,9 @@ var server = async (ctx) => {
|
|
|
11398
12225
|
setTimeout(() => {
|
|
11399
12226
|
const rpcStartedAt = performance.now();
|
|
11400
12227
|
rpcServer?.start().then(() => {
|
|
11401
|
-
|
|
12228
|
+
log2(`[magic-context] boot deferred phase: rpc=${Math.round(performance.now() - rpcStartedAt)}ms`);
|
|
11402
12229
|
}).catch((err) => {
|
|
11403
|
-
|
|
12230
|
+
log2(`[magic-context] RPC server failed to start: ${err}`);
|
|
11404
12231
|
});
|
|
11405
12232
|
}, 0);
|
|
11406
12233
|
rpcMs = performance.now() - rpcScheduledAt;
|
|
@@ -11420,21 +12247,21 @@ var server = async (ctx) => {
|
|
|
11420
12247
|
});
|
|
11421
12248
|
setTimeout(() => {
|
|
11422
12249
|
rpcServer?.start().catch((err) => {
|
|
11423
|
-
|
|
12250
|
+
log2(`[magic-context] debug-only RPC server failed to start: ${err}`);
|
|
11424
12251
|
});
|
|
11425
12252
|
}, 0);
|
|
11426
12253
|
}
|
|
11427
12254
|
{
|
|
11428
12255
|
const fence = getSchemaFenceRejection();
|
|
11429
12256
|
if (fence) {
|
|
11430
|
-
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));
|
|
11431
12258
|
}
|
|
11432
12259
|
}
|
|
11433
12260
|
const serverUrl = ctx.serverUrl;
|
|
11434
12261
|
const serverUrlStr = serverUrl instanceof URL ? serverUrl.toString().replace(/\/$/, "") : typeof serverUrl === "string" ? serverUrl.replace(/\/$/, "") : undefined;
|
|
11435
|
-
importPluginModule(() => import("./send-session-notification-
|
|
12262
|
+
importPluginModule(() => import("./send-session-notification-erecz4y4.js")).then(({ setNotificationServerUrl }) => {
|
|
11436
12263
|
setNotificationServerUrl(serverUrlStr);
|
|
11437
|
-
}).catch((error) =>
|
|
12264
|
+
}).catch((error) => log2("[magic-context] notification transport unavailable:", error));
|
|
11438
12265
|
if (conflictResult?.hasConflict) {
|
|
11439
12266
|
setTimeout(() => {
|
|
11440
12267
|
sendConflictWarning2(ctx.client, ctx.directory, conflictResult);
|
|
@@ -11446,7 +12273,7 @@ var server = async (ctx) => {
|
|
|
11446
12273
|
}
|
|
11447
12274
|
if (pluginConfig.enabled && !conflictResult?.hasConflict) {
|
|
11448
12275
|
setTimeout(() => {
|
|
11449
|
-
importPluginModule(() => import("./announcement-
|
|
12276
|
+
importPluginModule(() => import("./announcement-fp14dw0n.js")).then(({
|
|
11450
12277
|
shouldShowAnnouncement,
|
|
11451
12278
|
ANNOUNCEMENT_VERSION,
|
|
11452
12279
|
ANNOUNCEMENT_FEATURES,
|
|
@@ -11455,7 +12282,7 @@ var server = async (ctx) => {
|
|
|
11455
12282
|
}) => {
|
|
11456
12283
|
if (!shouldShowAnnouncement())
|
|
11457
12284
|
return;
|
|
11458
|
-
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));
|
|
11459
12286
|
}).catch(() => {});
|
|
11460
12287
|
}, 8000);
|
|
11461
12288
|
}
|
|
@@ -11465,7 +12292,7 @@ var server = async (ctx) => {
|
|
|
11465
12292
|
const measuredStorageMs = storageBootTimings.openMs + storageBootTimings.guardMs + storageBootTimings.migrateMs;
|
|
11466
12293
|
const hooksMs = Math.max(0, hooksPhase.elapsedMs - measuredStorageMs);
|
|
11467
12294
|
const postMs = Math.max(0, performance.now() - postStartedAt - rpcMs);
|
|
11468
|
-
|
|
12295
|
+
log2(formatBootPhaseDiagnostics({
|
|
11469
12296
|
configMs,
|
|
11470
12297
|
conflictMs,
|
|
11471
12298
|
guardMs: storageBootTimings.guardMs,
|
|
@@ -11478,14 +12305,6 @@ var server = async (ctx) => {
|
|
|
11478
12305
|
budgetMs: BOOT_SERVER_DEADLINE_MS,
|
|
11479
12306
|
deadlinePhase
|
|
11480
12307
|
}));
|
|
11481
|
-
const checkoutClaimGate = pluginConfig.enabled ? createSubcCheckoutClaimGate("opencode", () => pluginConfig.subc?.connection_file ?? getDefaultSubcConnectionFile()) : undefined;
|
|
11482
|
-
const isCheckoutClaimRefused = async (sessionId) => {
|
|
11483
|
-
if (!checkoutClaimGate || !sessionId)
|
|
11484
|
-
return false;
|
|
11485
|
-
if (liveSessionState.internalChildSessions.has(sessionId))
|
|
11486
|
-
return false;
|
|
11487
|
-
return await checkoutClaimGate.refusal(sessionId, ctx.directory) !== null;
|
|
11488
|
-
};
|
|
11489
12308
|
return {
|
|
11490
12309
|
tool: tools,
|
|
11491
12310
|
event: createEventHandler({
|
|
@@ -11495,8 +12314,6 @@ var server = async (ctx) => {
|
|
|
11495
12314
|
const properties = input.event.properties;
|
|
11496
12315
|
if (properties.info?.id)
|
|
11497
12316
|
dreamerCap.delete(properties.info.id);
|
|
11498
|
-
} else if (await isCheckoutClaimRefused(openCodeEventSessionId(input.event))) {
|
|
11499
|
-
return;
|
|
11500
12317
|
}
|
|
11501
12318
|
await magicContextRuntime.magicContext?.event?.(input);
|
|
11502
12319
|
}
|
|
@@ -11522,7 +12339,7 @@ var server = async (ctx) => {
|
|
|
11522
12339
|
try {
|
|
11523
12340
|
magicContextRuntime.magicContext?.disposeRustAdapter?.();
|
|
11524
12341
|
} catch {}
|
|
11525
|
-
|
|
12342
|
+
log2("[magic-context] instance disposed — stopped RPC server, dream timer, auto-update, Rust replay registration");
|
|
11526
12343
|
}
|
|
11527
12344
|
}),
|
|
11528
12345
|
"chat.params": async (input, output) => {
|
|
@@ -11533,25 +12350,13 @@ var server = async (ctx) => {
|
|
|
11533
12350
|
getMagicContext: () => magicContextRuntime.magicContext,
|
|
11534
12351
|
failClosed,
|
|
11535
12352
|
failClosedBlockingEnabled,
|
|
11536
|
-
checkoutClaim: checkoutClaimGate ? {
|
|
11537
|
-
gate: checkoutClaimGate,
|
|
11538
|
-
projectRoot: ctx.directory,
|
|
11539
|
-
onRefusal: async (sessionId, message) => {
|
|
11540
|
-
const { sendStatusNotification } = await importPluginModule(() => import("./send-session-notification-dyw42dtr.js"));
|
|
11541
|
-
const { abortSessionFailClosed } = await importPluginModule(() => import("./transform-postprocess-phase-bqhz6vdr.js"));
|
|
11542
|
-
await sendStatusNotification(ctx.client, sessionId, message, {
|
|
11543
|
-
toastDurationMs: 15000
|
|
11544
|
-
});
|
|
11545
|
-
await abortSessionFailClosed(ctx.client, sessionId);
|
|
11546
|
-
}
|
|
11547
|
-
} : undefined,
|
|
11548
12353
|
compactionOff: !isCompactionEnabled(pluginConfig),
|
|
11549
12354
|
internalChildSessions: liveSessionState.internalChildSessions,
|
|
11550
12355
|
tryReopenStorage,
|
|
11551
12356
|
rustReplayParticipant: () => magicContextRuntime.magicContext?.getRustReplayParticipant?.() ?? null,
|
|
11552
12357
|
onStorageBusyRefusal: async (sessionId, message) => {
|
|
11553
|
-
const { sendStatusNotification } = await importPluginModule(() => import("./send-session-notification-
|
|
11554
|
-
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"));
|
|
11555
12360
|
await sendStatusNotification(ctx.client, sessionId, message, {
|
|
11556
12361
|
toastDurationMs: 15000
|
|
11557
12362
|
});
|
|
@@ -11559,8 +12364,6 @@ var server = async (ctx) => {
|
|
|
11559
12364
|
}
|
|
11560
12365
|
}),
|
|
11561
12366
|
"experimental.chat.system.transform": async (input, output) => {
|
|
11562
|
-
if (await isCheckoutClaimRefused(input.sessionID))
|
|
11563
|
-
return;
|
|
11564
12367
|
await magicContextRuntime.magicContext?.["experimental.chat.system.transform"]?.(input, output);
|
|
11565
12368
|
},
|
|
11566
12369
|
"command.execute.before": async (input, output) => {
|
|
@@ -11573,8 +12376,6 @@ var server = async (ctx) => {
|
|
|
11573
12376
|
const modId = typed.model?.modelID;
|
|
11574
12377
|
const agent = typed.agent;
|
|
11575
12378
|
lastChatContext = provId && modId ? { providerID: provId, modelID: modId, agentName: agent || "default" } : null;
|
|
11576
|
-
if (await isCheckoutClaimRefused(input.sessionID))
|
|
11577
|
-
return;
|
|
11578
12379
|
await magicContextRuntime.magicContext?.["chat.message"]?.(input, output);
|
|
11579
12380
|
},
|
|
11580
12381
|
"tool.definition": async (input, output) => {
|
|
@@ -11650,7 +12451,7 @@ var server = async (ctx) => {
|
|
|
11650
12451
|
const internalAgentIds = registrations.map((registration) => registration.id);
|
|
11651
12452
|
for (const reg of registrations) {
|
|
11652
12453
|
if (typeof reg.prompt !== "string" || reg.prompt.length === 0) {
|
|
11653
|
-
|
|
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`);
|
|
11654
12455
|
continue;
|
|
11655
12456
|
}
|
|
11656
12457
|
agentConfigRecord[reg.id] = buildHiddenAgentConfig(reg.prompt, reg.allowedTools, reg.maxSteps, reg.overrides, reg.id, reg.lockPermissions === true, reg.description);
|
|
@@ -11659,7 +12460,7 @@ var server = async (ctx) => {
|
|
|
11659
12460
|
config.agent = callerAgentConfig;
|
|
11660
12461
|
} catch (error) {
|
|
11661
12462
|
const e = error;
|
|
11662
|
-
|
|
12463
|
+
log2(`[magic-context] config hook failed (commands/agents NOT registered; transform still active): ${e?.message ?? error}`, e?.stack ? { stackHead: e.stack.split(`
|
|
11663
12464
|
`).slice(0, 6).join(`
|
|
11664
12465
|
`) } : undefined);
|
|
11665
12466
|
}
|