@cortexkit/opencode-magic-context 0.49.16 → 0.49.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auto-search-worker.js +76 -63
- package/dist/chunk-embedding-write-worker.js +11 -11
- package/dist/{compaction-marker-candidates-v5c6997n.js → compaction-marker-candidates-n4krhat4.js} +2 -2
- package/dist/compaction-marker-candidates-worker.js +2 -2
- package/dist/config/schema/magic-context.d.ts +394 -394
- package/dist/{conflict-warning-hook-znry4j76.js → conflict-warning-hook-4pmz879v.js} +5 -5
- package/dist/{context-3znk23va.js → context-m897gfp9.js} +304 -145
- package/dist/{embedding-backfill-q4n8dend.js → embedding-backfill-fmz50tsy.js} +11 -11
- package/dist/embedding-worker-process.js +1 -1
- package/dist/embedding-worker.js +4 -4
- package/dist/features/magic-context/compartment-chunk-embedding.d.ts +1 -1
- package/dist/features/magic-context/compartment-chunk-embedding.d.ts.map +1 -1
- package/dist/features/magic-context/git-commits/indexer.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding-openai.d.ts.map +1 -1
- package/dist/features/magic-context/memory/project-identity-cache.d.ts +2 -0
- package/dist/features/magic-context/memory/project-identity-cache.d.ts.map +1 -1
- package/dist/features/magic-context/message-index-async.d.ts +1 -1
- package/dist/features/magic-context/message-index-async.d.ts.map +1 -1
- package/dist/features/magic-context/message-index.d.ts +5 -0
- package/dist/features/magic-context/message-index.d.ts.map +1 -1
- package/dist/features/magic-context/search.d.ts +6 -1
- package/dist/features/magic-context/search.d.ts.map +1 -1
- package/dist/features/magic-context/storage-host-instruction-retention.d.ts +11 -0
- package/dist/features/magic-context/storage-host-instruction-retention.d.ts.map +1 -0
- package/dist/features/magic-context/storage-meta-session.d.ts.map +1 -1
- package/dist/features/magic-context/storage-meta-shared.d.ts +2 -2
- package/dist/features/magic-context/storage-meta-shared.d.ts.map +1 -1
- package/dist/features/magic-context/storage-session-tables.d.ts +9 -1
- package/dist/features/magic-context/storage-session-tables.d.ts.map +1 -1
- package/dist/hooks/magic-context/apply-operations.d.ts.map +1 -1
- package/dist/hooks/magic-context/auto-search-deadline.d.ts +2 -1
- package/dist/hooks/magic-context/auto-search-deadline.d.ts.map +1 -1
- package/dist/hooks/magic-context/auto-search-hint.d.ts +3 -0
- package/dist/hooks/magic-context/auto-search-hint.d.ts.map +1 -1
- package/dist/hooks/magic-context/auto-search-runner.d.ts.map +1 -1
- package/dist/hooks/magic-context/auto-search-worker-client.d.ts +10 -2
- package/dist/hooks/magic-context/auto-search-worker-client.d.ts.map +1 -1
- package/dist/hooks/magic-context/cache-busting-signals.d.ts +22 -1
- package/dist/hooks/magic-context/cache-busting-signals.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-historian.d.ts +2 -0
- package/dist/hooks/magic-context/compartment-runner-historian.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-trigger.d.ts +4 -2
- package/dist/hooks/magic-context/compartment-trigger.d.ts.map +1 -1
- package/dist/hooks/magic-context/file-token-coverage.d.ts +11 -0
- package/dist/hooks/magic-context/file-token-coverage.d.ts.map +1 -0
- package/dist/hooks/magic-context/final-wire-token-estimate.d.ts +9 -0
- package/dist/hooks/magic-context/final-wire-token-estimate.d.ts.map +1 -1
- package/dist/hooks/magic-context/historian-host-runner.d.ts.map +1 -1
- package/dist/hooks/magic-context/hook.d.ts.map +1 -1
- package/dist/hooks/magic-context/host-served-rows.d.ts +25 -0
- package/dist/hooks/magic-context/host-served-rows.d.ts.map +1 -1
- package/dist/hooks/magic-context/inject-compartments.d.ts +7 -1
- package/dist/hooks/magic-context/inject-compartments.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-recovery-fence.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-replay.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-slot.d.ts +1 -1
- package/dist/hooks/magic-context/lkg-slot.d.ts.map +1 -1
- package/dist/hooks/magic-context/pass-outcome.d.ts +2 -0
- package/dist/hooks/magic-context/pass-outcome.d.ts.map +1 -1
- package/dist/hooks/magic-context/protected-tail-boundary.d.ts +2 -1
- package/dist/hooks/magic-context/protected-tail-boundary.d.ts.map +1 -1
- package/dist/hooks/magic-context/read-session-chunk.d.ts.map +1 -1
- package/dist/hooks/magic-context/signed-thinking-hold.d.ts +59 -0
- package/dist/hooks/magic-context/signed-thinking-hold.d.ts.map +1 -0
- package/dist/hooks/magic-context/system-prompt-diagnostics.d.ts +8 -0
- package/dist/hooks/magic-context/system-prompt-diagnostics.d.ts.map +1 -0
- package/dist/hooks/magic-context/system-prompt-hash.d.ts.map +1 -1
- package/dist/hooks/magic-context/tag-content-primitives.d.ts.map +1 -1
- package/dist/hooks/magic-context/tag-messages.d.ts +6 -1
- package/dist/hooks/magic-context/tag-messages.d.ts.map +1 -1
- package/dist/hooks/magic-context/todo-view.d.ts +2 -2
- package/dist/hooks/magic-context/tool-drop-target.d.ts +3 -2
- package/dist/hooks/magic-context/tool-drop-target.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-compartment-phase.d.ts +6 -0
- package/dist/hooks/magic-context/transform-compartment-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-context-state.d.ts +19 -0
- package/dist/hooks/magic-context/transform-context-state.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +19 -0
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-stage-logger.d.ts +3 -0
- package/dist/hooks/magic-context/transform-stage-logger.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform.d.ts +1 -0
- package/dist/hooks/magic-context/transform.d.ts.map +1 -1
- package/dist/{index-9nkg2dzk.js → index-24fezq97.js} +3 -3
- package/dist/{index-v9asb16b.js → index-24jbw52d.js} +5 -5
- package/dist/{index-a8bvhwqs.js → index-2vxtcb95.js} +32 -3
- package/dist/{index-f71thw8j.js → index-4s3t0nd0.js} +1 -1
- package/dist/{index-6a6dq53h.js → index-6s5941tm.js} +5 -5
- package/dist/{index-fkx2qnvw.js → index-6x57ar45.js} +2 -2
- package/dist/{index-ek1yxvvz.js → index-936py2wm.js} +361 -70
- package/dist/{index-dqe8pq4x.js → index-a6mc0v4d.js} +6 -3
- package/dist/{index-hehkf6zm.js → index-b5vqckbw.js} +12 -6
- package/dist/{v2/server-wafzvyhg.js → index-beht37jy.js} +8 -0
- package/dist/{index-7b2cfmaz.js → index-bjcnntmz.js} +2 -2
- package/dist/{index-hqkczed7.js → index-c5pytzne.js} +22 -2
- package/dist/{index-nd7m2a5a.js → index-cf74k5ak.js} +27 -5
- package/dist/{index-kn4t1haw.js → index-e4xv8890.js} +531 -253
- package/dist/{index-cj9g0j7a.js → index-fgncb0ng.js} +7 -7
- package/dist/{index-5mwk1nek.js → index-jn12fvvh.js} +1 -1
- package/dist/{index-n6m03s3n.js → index-ke416mdc.js} +1 -1
- package/dist/{index-mtw9e71a.js → index-kq82mtg0.js} +2 -2
- package/dist/{index-n78avt2p.js → index-n37sebck.js} +1 -1
- package/dist/{index-wk0n1cgt.js → index-qn7xstt2.js} +2 -2
- package/dist/{index-v63beg1z.js → index-r4nkrs05.js} +3 -3
- package/dist/{index-j6zw70pf.js → index-rmwykbbb.js} +60 -21
- package/dist/{index-saews2s3.js → index-rr2bb45z.js} +1 -1
- package/dist/{index-ayym1x7f.js → index-s1ex9y6p.js} +195 -748
- package/dist/{index-7pa32z07.js → index-s734jcsr.js} +1 -1
- package/dist/{index-b17m64g9.js → index-s74zqahq.js} +1 -1
- package/dist/{index-4qfy7v57.js → index-s7j8tvhv.js} +31 -20
- package/dist/{index-wv9n2zcq.js → index-v8awdgvd.js} +4 -4
- package/dist/{index-p4vde22c.js → index-x4njr8df.js} +965 -77
- package/dist/{index-qrahzcqv.js → index-ze7mvk54.js} +10 -7
- package/dist/index.js +39 -39
- package/dist/{message-fts-rowid-map-yvx5a9jw.js → message-fts-rowid-map-17s0dfn4.js} +5 -3
- package/dist/{message-index-t4pz7akd.js → message-index-66jv6fh4.js} +13 -13
- package/dist/{message-index-bounded-6th8djy9.js → message-index-bounded-n1frdn85.js} +17 -17
- package/dist/{message-time-backfill-8egzkd3z.js → message-time-backfill-73mmm76q.js} +1 -1
- package/dist/migration-worker.js +8 -8
- package/dist/plugin/dream-timer.d.ts +11 -0
- package/dist/plugin/dream-timer.d.ts.map +1 -1
- package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
- package/dist/{project-embedding-registry-2dea0a77.js → project-embedding-registry-z74mhqkf.js} +10 -10
- package/dist/raw-ordinal-warmup-worker.js +10 -10
- package/dist/{read-session-chunk-4pwqxm5a.js → read-session-chunk-v06g3vka.js} +7 -7
- package/dist/{read-session-raw-5ar8se5v.js → read-session-raw-rsc8c7qy.js} +2 -2
- package/dist/{recomp-orchestrator-tjcaj5x7.js → recomp-orchestrator-ghpk2dtq.js} +24 -24
- package/dist/{search-archive-02jws7hw.js → search-archive-4d53y23e.js} +8 -8
- package/dist/{search-rb01n29x.js → search-nkf271d4.js} +20 -20
- package/dist/{send-session-notification-2x9edkrp.js → send-session-notification-6ve0e8p4.js} +4 -4
- package/dist/shared/historian-cache.d.ts +8 -0
- package/dist/shared/historian-cache.d.ts.map +1 -0
- package/dist/shared/model-suggestion-retry.d.ts +2 -0
- package/dist/shared/model-suggestion-retry.d.ts.map +1 -1
- package/dist/shared/rpc-discovery-cleanup.d.ts +3 -0
- package/dist/shared/rpc-discovery-cleanup.d.ts.map +1 -0
- package/dist/shared/rpc-server.d.ts +2 -0
- package/dist/shared/rpc-server.d.ts.map +1 -1
- package/dist/shared/search-text.d.ts +8 -0
- package/dist/shared/search-text.d.ts.map +1 -0
- package/dist/shared/sqlite.d.ts +4 -2
- package/dist/shared/sqlite.d.ts.map +1 -1
- package/dist/shared/storage-file-mutex.d.ts.map +1 -1
- package/dist/shared/subagent-runner.d.ts +2 -0
- package/dist/shared/subagent-runner.d.ts.map +1 -1
- package/dist/shared/system-directive.d.ts +2 -0
- package/dist/shared/system-directive.d.ts.map +1 -1
- package/dist/{sqlite-4pqyynrs.js → sqlite-zf72c52d.js} +1 -1
- package/dist/{storage-memory-j3v3hc83.js → storage-memory-y3qmy00r.js} +2 -2
- package/dist/{storage-tags-4z1w27xa.js → storage-tags-r7k9tjcv.js} +8 -4
- package/dist/{transform-postprocess-phase-xaw5c3xp.js → transform-postprocess-phase-zpgav0h7.js} +24 -24
- package/dist/v2/auto-search-worker.js +76 -63
- package/dist/v2/chunk-embedding-write-worker.js +11 -11
- package/dist/v2/{compaction-marker-candidates-1vqwr3s5.js → compaction-marker-candidates-ebx3388k.js} +2 -2
- package/dist/v2/compaction-marker-candidates-worker.js +2 -2
- package/dist/v2/{context-acw1nhv8.js → context-f2xh7ba4.js} +1171 -448
- package/dist/v2/embedding-backfill-7c7yr69y.js +23 -0
- package/dist/v2/embedding-worker-process.js +1 -1
- package/dist/v2/embedding-worker.js +4 -4
- package/dist/v2/fold/native-replay.d.ts +11 -2
- package/dist/v2/fold/native-replay.d.ts.map +1 -1
- package/dist/v2/fold/policy.d.ts.map +1 -1
- package/dist/v2/fold/restore.d.ts.map +1 -1
- package/dist/v2/hooks/context.d.ts.map +1 -1
- package/dist/v2/hooks/hidden-child.d.ts +8 -0
- package/dist/v2/hooks/hidden-child.d.ts.map +1 -1
- package/dist/v2/hooks/payload.d.ts.map +1 -1
- package/dist/v2/hooks/types.d.ts +17 -0
- package/dist/v2/hooks/types.d.ts.map +1 -1
- package/dist/v2/{message-fts-rowid-map-8vf0v7cr.js → message-fts-rowid-map-wfx67gfd.js} +5 -3
- package/dist/v2/{message-index-e6qzw477.js → message-index-48f7hw7a.js} +13 -13
- package/dist/v2/{message-index-bounded-dsrf49y7.js → message-index-bounded-w3hfm29z.js} +17 -17
- package/dist/v2/{message-time-backfill-q5pgxf0d.js → message-time-backfill-04t0km1z.js} +1 -1
- package/dist/v2/migration-worker.js +8 -8
- package/dist/v2/{project-embedding-registry-rek75aqw.js → project-embedding-registry-gnkj56xp.js} +10 -10
- package/dist/v2/raw-ordinal-warmup-worker.js +10 -10
- package/dist/v2/{read-session-chunk-7bpygfv2.js → read-session-chunk-zpgmxwte.js} +7 -7
- package/dist/v2/{read-session-raw-pw2n1qgc.js → read-session-raw-yaegtjzh.js} +2 -2
- package/dist/v2/{recomp-orchestrator-hzpgg06e.js → recomp-orchestrator-4vfxej9t.js} +24 -24
- package/dist/v2/{search-archive-fn4wy8sx.js → search-archive-vv48s2aa.js} +8 -8
- package/dist/v2/{search-sf2vg5pk.js → search-kza414f0.js} +20 -20
- package/dist/v2/{send-session-notification-hmr7q0nt.js → send-session-notification-3pxn658x.js} +4 -4
- package/dist/v2/{server-n5q841qn.js → server-1nyybqan.js} +31 -20
- package/dist/v2/{server-785mb90s.js → server-1wy7b9de.js} +6 -3
- package/dist/v2/{server-0mzjjw3s.js → server-27gq4mfz.js} +27 -5
- package/dist/v2/{server-g59aatsz.js → server-2ehj0bw7.js} +965 -77
- package/dist/v2/{server-kqpawe1a.js → server-46neh5fa.js} +12 -6
- package/dist/v2/{server-rrqpvwqd.js → server-6tmj0s7j.js} +2 -2
- package/dist/v2/{server-kr2kc9dz.js → server-8by8qfec.js} +10 -7
- package/dist/v2/{server-r9gjxcte.js → server-a2eqhkxr.js} +7 -7
- package/dist/v2/{server-vbe4se57.js → server-a9xqj88f.js} +1 -1
- package/dist/{index-wafzvyhg.js → v2/server-beht37jy.js} +8 -0
- package/dist/v2/{server-6fyp0v67.js → server-bfpda1tb.js} +195 -749
- package/dist/v2/{server-05xjtq6c.js → server-d04vrx0j.js} +1 -1
- package/dist/v2/{server-zs8d0s3b.js → server-g3qma5c0.js} +1 -1
- package/dist/v2/{server-00hx04yn.js → server-gpvay0xz.js} +2 -2
- package/dist/v2/{server-gha9x4qq.js → server-h1v0pyxb.js} +2 -2
- package/dist/v2/{server-hgg55hde.js → server-hy3d3vsx.js} +1 -1
- package/dist/v2/{server-vgpab6rd.js → server-my7k4eds.js} +4 -4
- package/dist/v2/{server-d8tj10db.js → server-n1prf1g6.js} +1 -1
- package/dist/v2/{server-n78avt2p.js → server-n37sebck.js} +1 -1
- package/dist/v2/{server-y5pznjt9.js → server-nj659894.js} +5 -5
- package/dist/v2/{server-zyw55ygv.js → server-qv7f0hhe.js} +5 -5
- package/dist/v2/{server-e3ftpk7v.js → server-rmygf5pn.js} +32 -3
- package/dist/v2/{server-0ppsweh6.js → server-tgnbmwah.js} +22 -2
- package/dist/v2/{server-1hcbw661.js → server-xhab8jx8.js} +60 -21
- package/dist/v2/{server-6714jebr.js → server-xj136kt8.js} +1 -1
- package/dist/v2/{server-aavz8pm6.js → server-zzkj2fch.js} +3 -3
- package/dist/v2/server.js +4 -4
- package/dist/v2/{sqlite-4pqyynrs.js → sqlite-zf72c52d.js} +1 -1
- package/dist/v2/{storage-memory-j3v3hc83.js → storage-memory-y3qmy00r.js} +2 -2
- package/dist/v2/{storage-tags-hkwtbp3g.js → storage-tags-3wdb8zph.js} +8 -4
- package/dist/v2/store-reader.d.ts +8 -0
- package/dist/v2/store-reader.d.ts.map +1 -1
- package/dist/v2/{wrapup-orchestrator-x4xj1782.js → wrapup-orchestrator-psqz7yh0.js} +24 -24
- package/dist/wrapup-orchestrator-s9zc5b00.js +48 -0
- package/package.json +1 -1
- package/src/config/latch-permanence-guard.test.ts +4 -0
- package/src/shared/historian-cache.test.ts +69 -0
- package/src/shared/historian-cache.ts +55 -0
- package/src/shared/model-suggestion-retry.ts +2 -0
- package/src/shared/rpc-discovery-cleanup.test.ts +57 -0
- package/src/shared/rpc-discovery-cleanup.ts +57 -0
- package/src/shared/rpc-server.ts +36 -13
- package/src/shared/search-text.test.ts +47 -0
- package/src/shared/search-text.ts +63 -0
- package/src/shared/sqlite.test.ts +56 -0
- package/src/shared/sqlite.ts +51 -2
- package/src/shared/storage-file-mutex-review.test.ts +22 -2
- package/src/shared/storage-file-mutex.ts +11 -1
- package/src/shared/subagent-runner.ts +2 -0
- package/src/shared/system-directive.ts +19 -1
- package/src/shared/tag-transcript.ts +12 -4
- package/dist/v2/embedding-backfill-jyd6492b.js +0 -23
- package/dist/wrapup-orchestrator-vj2tbp22.js +0 -48
|
@@ -34,10 +34,12 @@ import {
|
|
|
34
34
|
getPendingOps,
|
|
35
35
|
getPendingOpsCount,
|
|
36
36
|
removePendingOp,
|
|
37
|
+
updateTagByteSize2,
|
|
37
38
|
getRecentTagOwnerMessageIds2,
|
|
38
39
|
AGE_RECLAIM_MIN_TOKENS2,
|
|
39
40
|
getOldestActiveUnprotectedToolTags2,
|
|
40
41
|
getActiveToolTagsForAgeReclaim2,
|
|
42
|
+
updateTagTokenCount2,
|
|
41
43
|
tryGetReasoningTokenEstimatesByMessage2,
|
|
42
44
|
cachedTagOwnerRatios2,
|
|
43
45
|
tagOwnerWarmupState2,
|
|
@@ -71,12 +73,12 @@ import {
|
|
|
71
73
|
adoptNullOwnerToolTag2,
|
|
72
74
|
getCandidateToolOwners2,
|
|
73
75
|
pickNearestPriorOwner2
|
|
74
|
-
} from "./index-
|
|
76
|
+
} from "./index-cf74k5ak.js";
|
|
75
77
|
import {
|
|
76
78
|
textMentionsRecentCommit,
|
|
77
79
|
hasMeaningfulUserText2,
|
|
78
80
|
estimateTokens
|
|
79
|
-
} from "./index-
|
|
81
|
+
} from "./index-c5pytzne.js";
|
|
80
82
|
import {
|
|
81
83
|
log2,
|
|
82
84
|
sessionLog2
|
|
@@ -87,27 +89,61 @@ import {
|
|
|
87
89
|
getSqliteDatabasePath2,
|
|
88
90
|
assertTransformWrite2,
|
|
89
91
|
isTransientSqliteError2
|
|
90
|
-
} from "./index-
|
|
91
|
-
import {
|
|
92
|
-
isValidLanguageCode
|
|
93
|
-
} from "./index-wgypt3cs.js";
|
|
94
|
-
import {
|
|
95
|
-
runSessionWarmupWorker
|
|
96
|
-
} from "./index-7pa32z07.js";
|
|
92
|
+
} from "./index-beht37jy.js";
|
|
97
93
|
import {
|
|
98
94
|
getProjectEmbeddingSnapshot2,
|
|
99
95
|
embedTextForProject2,
|
|
100
96
|
embedBatchForProject2
|
|
101
|
-
} from "./index-
|
|
97
|
+
} from "./index-ze7mvk54.js";
|
|
102
98
|
import {
|
|
103
|
-
|
|
104
|
-
} from "./index-
|
|
99
|
+
runSessionWarmupWorker
|
|
100
|
+
} from "./index-s734jcsr.js";
|
|
101
|
+
import {
|
|
102
|
+
getMaxM0MutationId,
|
|
103
|
+
getLastCompartmentEndMessage,
|
|
104
|
+
rememberUnpublishedAutoSearchNoHint,
|
|
105
|
+
getUnpublishedAutoSearchNoHint,
|
|
106
|
+
forgetUnpublishedAutoSearchNoHint,
|
|
107
|
+
registerAutoSearchWork,
|
|
108
|
+
cancelAutoSearchWork,
|
|
109
|
+
updateSessionMeta,
|
|
110
|
+
advanceToolReclaimWatermark,
|
|
111
|
+
requestPendingMaterialization,
|
|
112
|
+
pendingMaterializationOrigin,
|
|
113
|
+
hasPendingMaterializationOrigin,
|
|
114
|
+
clearPendingMaterialization,
|
|
115
|
+
saveSourceContent,
|
|
116
|
+
replaceSourceContent,
|
|
117
|
+
getSourceContents,
|
|
118
|
+
compareOpenCodeMessagesByCanonicalOrder,
|
|
119
|
+
prepareCompactionMarkerCandidates,
|
|
120
|
+
MARKER_SUMMARY_TEXT,
|
|
121
|
+
applyDeferredCompactionMarker,
|
|
122
|
+
injectTemporalMarkers,
|
|
123
|
+
clearInjectionCache,
|
|
124
|
+
getVisibleMemoryIds,
|
|
125
|
+
renderCompartmentInjection,
|
|
126
|
+
MaterializeContentionError,
|
|
127
|
+
mustMaterialize,
|
|
128
|
+
hydrateCachedM0Mural,
|
|
129
|
+
prepareCachedM0M1Replay,
|
|
130
|
+
hasCompleteCachedM0M1,
|
|
131
|
+
injectM0M1,
|
|
132
|
+
observeNoteNudgeServe,
|
|
133
|
+
peekNoteNudgeText,
|
|
134
|
+
markNoteNudgeDelivered,
|
|
135
|
+
getActiveCompartmentRun
|
|
136
|
+
} from "./index-s1ex9y6p.js";
|
|
137
|
+
import {
|
|
138
|
+
BoundedSessionMap,
|
|
139
|
+
cleanSearchText,
|
|
140
|
+
matchedSearchSnippet
|
|
141
|
+
} from "./index-x4njr8df.js";
|
|
105
142
|
import {
|
|
106
143
|
stripSystemInjection,
|
|
107
144
|
isTextPart,
|
|
108
145
|
isToolPartWithOutput,
|
|
109
146
|
isFilePart,
|
|
110
|
-
buildFileSourceContent,
|
|
111
147
|
toolPartHasUserAnswer,
|
|
112
148
|
isEditTool,
|
|
113
149
|
escalationBands,
|
|
@@ -196,53 +232,21 @@ import {
|
|
|
196
232
|
extractToolCallObservation,
|
|
197
233
|
ToolMutationBatch,
|
|
198
234
|
createToolDropTarget
|
|
199
|
-
} from "./index-
|
|
235
|
+
} from "./index-rmwykbbb.js";
|
|
200
236
|
import {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
cancelAutoSearchWork,
|
|
207
|
-
updateSessionMeta,
|
|
208
|
-
advanceToolReclaimWatermark,
|
|
209
|
-
requestPendingMaterialization,
|
|
210
|
-
pendingMaterializationOrigin,
|
|
211
|
-
hasPendingMaterializationOrigin,
|
|
212
|
-
clearPendingMaterialization,
|
|
213
|
-
saveSourceContent,
|
|
214
|
-
replaceSourceContent,
|
|
215
|
-
getSourceContents,
|
|
216
|
-
compareOpenCodeMessagesByCanonicalOrder,
|
|
217
|
-
prepareCompactionMarkerCandidates,
|
|
218
|
-
MARKER_SUMMARY_TEXT,
|
|
219
|
-
applyDeferredCompactionMarker,
|
|
220
|
-
injectTemporalMarkers,
|
|
221
|
-
clearInjectionCache,
|
|
222
|
-
getVisibleMemoryIds,
|
|
223
|
-
renderCompartmentInjection,
|
|
224
|
-
MaterializeContentionError,
|
|
225
|
-
mustMaterialize,
|
|
226
|
-
hydrateCachedM0Mural,
|
|
227
|
-
prepareCachedM0M1Replay,
|
|
228
|
-
hasCompleteCachedM0M1,
|
|
229
|
-
injectM0M1,
|
|
230
|
-
observeNoteNudgeServe,
|
|
231
|
-
peekNoteNudgeText,
|
|
232
|
-
markNoteNudgeDelivered,
|
|
233
|
-
getActiveCompartmentRun
|
|
234
|
-
} from "./index-ayym1x7f.js";
|
|
237
|
+
isValidLanguageCode
|
|
238
|
+
} from "./index-wgypt3cs.js";
|
|
239
|
+
import {
|
|
240
|
+
isEmbeddingHostBusy2
|
|
241
|
+
} from "./index-qt1qqasc.js";
|
|
235
242
|
import {
|
|
236
243
|
openCodeDbExists,
|
|
237
244
|
withReadOnlySessionDb,
|
|
238
245
|
getMessageTimesFromOpenCodeDb
|
|
239
|
-
} from "./index-
|
|
240
|
-
import {
|
|
241
|
-
BoundedSessionMap
|
|
242
|
-
} from "./index-p4vde22c.js";
|
|
246
|
+
} from "./index-kq82mtg0.js";
|
|
243
247
|
import {
|
|
244
248
|
userFacingFailureCode
|
|
245
|
-
} from "./index-
|
|
249
|
+
} from "./index-v8awdgvd.js";
|
|
246
250
|
import {
|
|
247
251
|
normalizeProtectedToolName,
|
|
248
252
|
mergeProtectedTools
|
|
@@ -620,7 +624,8 @@ function createTagger() {
|
|
|
620
624
|
}
|
|
621
625
|
|
|
622
626
|
// src/hooks/magic-context/auto-search-deadline.ts
|
|
623
|
-
var AUTO_SEARCH_TIMEOUT_MS =
|
|
627
|
+
var AUTO_SEARCH_TIMEOUT_MS = 1000;
|
|
628
|
+
var AUTO_SEARCH_VECTOR_TIMEOUT_MS = 200;
|
|
624
629
|
var operationDeadlines = new WeakMap;
|
|
625
630
|
function autoSearchDeadlineUnixMs(signal) {
|
|
626
631
|
const deadline = signal && operationDeadlines.get(signal);
|
|
@@ -1176,32 +1181,32 @@ function formatAge(committedAtMs) {
|
|
|
1176
1181
|
const years = Math.floor(days / 365);
|
|
1177
1182
|
return years === 1 ? "1y ago" : `${years}y ago`;
|
|
1178
1183
|
}
|
|
1179
|
-
function renderFragment(result, charCap, wordRules) {
|
|
1184
|
+
function renderFragment(result, charCap, wordRules, query) {
|
|
1180
1185
|
switch (result.source) {
|
|
1181
1186
|
case "memory": {
|
|
1182
|
-
const compressed = cavemanCompress(result.content, "ultra", CURRENT_CAVEMAN_RULES, wordRules);
|
|
1187
|
+
const compressed = cavemanCompress(cleanSearchText(result.content), "ultra", CURRENT_CAVEMAN_RULES, wordRules);
|
|
1183
1188
|
return truncate(compressed, charCap);
|
|
1184
1189
|
}
|
|
1185
1190
|
case "git_commit": {
|
|
1186
|
-
const subject = result.content.split(/\r?\n/)[0] ?? result.content;
|
|
1191
|
+
const subject = cleanSearchText(result.content.split(/\r?\n/)[0] ?? result.content);
|
|
1187
1192
|
const body = truncate(subject, Math.max(10, charCap - 20));
|
|
1188
1193
|
return `commit ${result.shortSha} ${formatAge(result.committedAtMs)}: ${body}`;
|
|
1189
1194
|
}
|
|
1190
1195
|
case "message": {
|
|
1191
|
-
const compressed = cavemanCompress(result.content, "ultra", CURRENT_CAVEMAN_RULES, wordRules);
|
|
1196
|
+
const compressed = cavemanCompress(query ? matchedSearchSnippet(result.content, query, charCap) : cleanSearchText(result.content), "ultra", CURRENT_CAVEMAN_RULES, wordRules);
|
|
1192
1197
|
return truncate(compressed, charCap);
|
|
1193
1198
|
}
|
|
1194
1199
|
case "compartment": {
|
|
1195
|
-
const source = result.
|
|
1200
|
+
const source = cleanSearchText(result.title);
|
|
1196
1201
|
const compressed = cavemanCompress(source, "ultra", CURRENT_CAVEMAN_RULES, wordRules);
|
|
1197
1202
|
return truncate(compressed, charCap);
|
|
1198
1203
|
}
|
|
1199
1204
|
case "primer": {
|
|
1200
|
-
const compressed = cavemanCompress(result.content, "ultra", CURRENT_CAVEMAN_RULES, wordRules);
|
|
1205
|
+
const compressed = cavemanCompress(cleanSearchText(result.content), "ultra", CURRENT_CAVEMAN_RULES, wordRules);
|
|
1201
1206
|
return truncate(compressed, charCap);
|
|
1202
1207
|
}
|
|
1203
1208
|
case "note": {
|
|
1204
|
-
const compressed = cavemanCompress(result.content, "ultra", CURRENT_CAVEMAN_RULES, wordRules);
|
|
1209
|
+
const compressed = cavemanCompress(cleanSearchText(result.content), "ultra", CURRENT_CAVEMAN_RULES, wordRules);
|
|
1205
1210
|
return truncate(compressed, charCap);
|
|
1206
1211
|
}
|
|
1207
1212
|
}
|
|
@@ -1212,7 +1217,7 @@ function buildAutoSearchHint(results, options = {}) {
|
|
|
1212
1217
|
const picks = results.slice(0, maxFragments);
|
|
1213
1218
|
const lines = [];
|
|
1214
1219
|
for (const result of picks) {
|
|
1215
|
-
const fragment = renderFragment(result, fragmentCharCap, options.wordRules ?? "english");
|
|
1220
|
+
const fragment = renderFragment(result, fragmentCharCap, options.wordRules ?? "english", options.query ?? "");
|
|
1216
1221
|
if (fragment.length === 0)
|
|
1217
1222
|
continue;
|
|
1218
1223
|
lines.push(`- ${fragment}`);
|
|
@@ -1235,6 +1240,9 @@ ${trimmedBody}…
|
|
|
1235
1240
|
}
|
|
1236
1241
|
return wrapped;
|
|
1237
1242
|
}
|
|
1243
|
+
function selectAutoSearchResults(results, threshold) {
|
|
1244
|
+
return results.filter((result) => (result.relevanceScore ?? result.score) >= threshold);
|
|
1245
|
+
}
|
|
1238
1246
|
|
|
1239
1247
|
// src/hooks/magic-context/auto-search-worker-client.ts
|
|
1240
1248
|
import { Worker } from "node:worker_threads";
|
|
@@ -1330,6 +1338,63 @@ async function searchAutoHint(db, sessionId, projectPath, query, options, entry
|
|
|
1330
1338
|
return executeAutoSearchWorker(db, sessionId, projectPath, query, options, entry, "search");
|
|
1331
1339
|
}
|
|
1332
1340
|
var pendingBackfills = new WeakMap;
|
|
1341
|
+
var searchWorkers = new WeakMap;
|
|
1342
|
+
var liveSearchWorkers = new Set;
|
|
1343
|
+
var MAX_IDLE_SEARCH_WORKERS = 4;
|
|
1344
|
+
var SEARCH_WORKER_IDLE_MS = 5 * 60000;
|
|
1345
|
+
var workersCreated = 0;
|
|
1346
|
+
var workersReused = 0;
|
|
1347
|
+
async function acquireSearchWorker(db, key, entry, input, signal) {
|
|
1348
|
+
const pool = searchWorkers.get(db) ?? new Map;
|
|
1349
|
+
searchWorkers.set(db, pool);
|
|
1350
|
+
while (!signal.aborted) {
|
|
1351
|
+
let slot = pool.get(key);
|
|
1352
|
+
if (slot?.busy) {
|
|
1353
|
+
const current = slot;
|
|
1354
|
+
await new Promise((resolve) => {
|
|
1355
|
+
const done = () => {
|
|
1356
|
+
signal.removeEventListener("abort", done);
|
|
1357
|
+
resolve();
|
|
1358
|
+
};
|
|
1359
|
+
signal.addEventListener("abort", done, { once: true });
|
|
1360
|
+
current.busy?.then(done);
|
|
1361
|
+
if (signal.aborted)
|
|
1362
|
+
done();
|
|
1363
|
+
});
|
|
1364
|
+
continue;
|
|
1365
|
+
}
|
|
1366
|
+
const fresh = !slot;
|
|
1367
|
+
if (!slot) {
|
|
1368
|
+
const worker = inRootAsyncContext2(() => new Worker(entry, { workerData: { ...input, persistent: true } }));
|
|
1369
|
+
slot = {
|
|
1370
|
+
worker,
|
|
1371
|
+
dispose() {
|
|
1372
|
+
clearTimeout(this.idleTimer);
|
|
1373
|
+
if (pool.get(key) === this)
|
|
1374
|
+
pool.delete(key);
|
|
1375
|
+
liveSearchWorkers.delete(this);
|
|
1376
|
+
worker.terminate();
|
|
1377
|
+
worker.unref();
|
|
1378
|
+
}
|
|
1379
|
+
};
|
|
1380
|
+
workersCreated++;
|
|
1381
|
+
pool.set(key, slot);
|
|
1382
|
+
liveSearchWorkers.add(slot);
|
|
1383
|
+
const current = slot;
|
|
1384
|
+
worker.on("error", () => current.dispose());
|
|
1385
|
+
worker.on("exit", () => current.dispose());
|
|
1386
|
+
} else
|
|
1387
|
+
workersReused++;
|
|
1388
|
+
clearTimeout(slot.idleTimer);
|
|
1389
|
+
const current = slot;
|
|
1390
|
+
current.busy = new Promise((resolve) => {
|
|
1391
|
+
current.release = resolve;
|
|
1392
|
+
});
|
|
1393
|
+
current.worker.ref();
|
|
1394
|
+
return { slot: current, fresh };
|
|
1395
|
+
}
|
|
1396
|
+
return null;
|
|
1397
|
+
}
|
|
1333
1398
|
function queueAutoSearchBackfill(db, sessionId, projectPath, query) {
|
|
1334
1399
|
if (isEmbeddingHostBusy2())
|
|
1335
1400
|
return Promise.resolve();
|
|
@@ -1394,6 +1459,7 @@ async function executeAutoSearchWorker(db, sessionId, projectPath, query, option
|
|
|
1394
1459
|
query,
|
|
1395
1460
|
options: {
|
|
1396
1461
|
...serializable,
|
|
1462
|
+
autoHint: true,
|
|
1397
1463
|
backfillMemoryEmbeddings: false,
|
|
1398
1464
|
countRetrievals: false,
|
|
1399
1465
|
measurementDisabled: true
|
|
@@ -1403,8 +1469,20 @@ async function executeAutoSearchWorker(db, sessionId, projectPath, query, option
|
|
|
1403
1469
|
snapshot,
|
|
1404
1470
|
deadlineUnixMs: autoSearchDeadlineUnixMs(deadlineSignal)
|
|
1405
1471
|
};
|
|
1472
|
+
let lease;
|
|
1473
|
+
try {
|
|
1474
|
+
lease = await acquireSearchWorker(db, `${input.harness}\x00${projectPath}\x00${job}\x00${entry.href}`, entry, input, signal);
|
|
1475
|
+
} catch (error) {
|
|
1476
|
+
lifecycle.done();
|
|
1477
|
+
throw error;
|
|
1478
|
+
}
|
|
1479
|
+
if (!lease) {
|
|
1480
|
+
lifecycle.done();
|
|
1481
|
+
return [];
|
|
1482
|
+
}
|
|
1483
|
+
const { slot, fresh } = lease;
|
|
1484
|
+
const worker = slot.worker;
|
|
1406
1485
|
return new Promise((resolve, reject) => {
|
|
1407
|
-
const worker = inRootAsyncContext2(() => new Worker(entry, { workerData: input }));
|
|
1408
1486
|
let settled = false;
|
|
1409
1487
|
const finish = (results, error) => {
|
|
1410
1488
|
if (settled)
|
|
@@ -1413,7 +1491,25 @@ async function executeAutoSearchWorker(db, sessionId, projectPath, query, option
|
|
|
1413
1491
|
signal?.removeEventListener("abort", abort);
|
|
1414
1492
|
lifecycle.signal.removeEventListener("abort", abort);
|
|
1415
1493
|
lifecycle.done();
|
|
1416
|
-
worker.
|
|
1494
|
+
worker.off("message", onMessage);
|
|
1495
|
+
worker.off("error", onError);
|
|
1496
|
+
worker.off("exit", onExit);
|
|
1497
|
+
if (error || signal.aborted || entry.href !== defaultAutoSearchWorkerEntry().href)
|
|
1498
|
+
slot.dispose();
|
|
1499
|
+
else {
|
|
1500
|
+
slot.idleTimer = setTimeout(() => slot.dispose(), SEARCH_WORKER_IDLE_MS);
|
|
1501
|
+
slot.idleTimer.unref?.();
|
|
1502
|
+
}
|
|
1503
|
+
const release = slot.release;
|
|
1504
|
+
slot.busy = undefined;
|
|
1505
|
+
slot.release = undefined;
|
|
1506
|
+
release?.();
|
|
1507
|
+
const reusable = liveSearchWorkers.delete(slot);
|
|
1508
|
+
if (reusable)
|
|
1509
|
+
liveSearchWorkers.add(slot);
|
|
1510
|
+
const idle = [...liveSearchWorkers].filter((candidate) => !candidate.busy);
|
|
1511
|
+
for (const prior of idle.slice(0, Math.max(0, idle.length - MAX_IDLE_SEARCH_WORKERS)))
|
|
1512
|
+
prior.dispose();
|
|
1417
1513
|
worker.unref();
|
|
1418
1514
|
if (error)
|
|
1419
1515
|
reject(error);
|
|
@@ -1423,9 +1519,9 @@ async function executeAutoSearchWorker(db, sessionId, projectPath, query, option
|
|
|
1423
1519
|
const abort = () => finish([]);
|
|
1424
1520
|
signal?.addEventListener("abort", abort, { once: true });
|
|
1425
1521
|
lifecycle.signal.addEventListener("abort", abort, { once: true });
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1522
|
+
const onError = (error) => finish([], error);
|
|
1523
|
+
const onExit = (code) => finish([], new Error(`auto-search worker exited (${code})`));
|
|
1524
|
+
const onMessage = async (reply) => {
|
|
1429
1525
|
if (settled)
|
|
1430
1526
|
return;
|
|
1431
1527
|
if (reply.kind === "result") {
|
|
@@ -1444,7 +1540,7 @@ async function executeAutoSearchWorker(db, sessionId, projectPath, query, option
|
|
|
1444
1540
|
const response = { id: reply.id };
|
|
1445
1541
|
try {
|
|
1446
1542
|
if (reply.kind === "query")
|
|
1447
|
-
response.result = await (job === "backfill" ? embedTextForProject2(projectPath, reply.text, signal, "query") : embedQuery
|
|
1543
|
+
response.result = await (job === "backfill" ? embedTextForProject2(projectPath, reply.text, signal, "query") : boundedHintEmbedding(embedQuery, reply.text, signal)) ?? null;
|
|
1448
1544
|
else {
|
|
1449
1545
|
const passage = await embedBatchForProject2(projectPath, reply.texts, signal, reply.purpose);
|
|
1450
1546
|
const current = getProjectEmbeddingSnapshot2(projectPath);
|
|
@@ -1459,13 +1555,46 @@ async function executeAutoSearchWorker(db, sessionId, projectPath, query, option
|
|
|
1459
1555
|
response.error = error instanceof Error ? error.message : String(error);
|
|
1460
1556
|
}
|
|
1461
1557
|
response.embeddingHostBusy = isEmbeddingHostBusy2();
|
|
1462
|
-
if (!settled && !signal?.aborted)
|
|
1463
|
-
|
|
1464
|
-
|
|
1558
|
+
if (!settled && !signal?.aborted) {
|
|
1559
|
+
try {
|
|
1560
|
+
worker.postMessage(response);
|
|
1561
|
+
} catch (error) {
|
|
1562
|
+
finish([], error instanceof Error ? error : new Error(String(error)));
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
};
|
|
1566
|
+
worker.on("error", onError);
|
|
1567
|
+
worker.on("exit", onExit);
|
|
1568
|
+
worker.on("message", onMessage);
|
|
1465
1569
|
if (signal?.aborted)
|
|
1466
1570
|
abort();
|
|
1571
|
+
else if (!fresh) {
|
|
1572
|
+
try {
|
|
1573
|
+
worker.postMessage({ kind: "run", input });
|
|
1574
|
+
} catch (error) {
|
|
1575
|
+
finish([], error instanceof Error ? error : new Error(String(error)));
|
|
1576
|
+
}
|
|
1577
|
+
}
|
|
1467
1578
|
});
|
|
1468
1579
|
}
|
|
1580
|
+
async function boundedHintEmbedding(embed, text, signal) {
|
|
1581
|
+
const controller = new AbortController;
|
|
1582
|
+
const combined = AbortSignal.any([signal, controller.signal]);
|
|
1583
|
+
let timer;
|
|
1584
|
+
try {
|
|
1585
|
+
return await Promise.race([
|
|
1586
|
+
Promise.resolve().then(() => embed?.(text, combined) ?? null),
|
|
1587
|
+
new Promise((resolve) => {
|
|
1588
|
+
timer = setTimeout(() => {
|
|
1589
|
+
resolve(null);
|
|
1590
|
+
controller.abort();
|
|
1591
|
+
}, AUTO_SEARCH_VECTOR_TIMEOUT_MS);
|
|
1592
|
+
})
|
|
1593
|
+
]);
|
|
1594
|
+
} finally {
|
|
1595
|
+
clearTimeout(timer);
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1469
1598
|
function defaultAutoSearchWorkerEntry() {
|
|
1470
1599
|
return new URL(new URL(import.meta.url).pathname.endsWith(".ts") ? "./auto-search-worker.ts" : "./auto-search-worker.js", import.meta.url);
|
|
1471
1600
|
}
|
|
@@ -1773,6 +1902,8 @@ async function runAutoSearchHint(args) {
|
|
|
1773
1902
|
const gitCommitsEnabled = embeddingSnapshot?.gitCommitEnabled ?? options.gitCommitsEnabled ?? false;
|
|
1774
1903
|
const searchOptions = {
|
|
1775
1904
|
limit: 10,
|
|
1905
|
+
maxMessageOrdinal: Math.max(0, getLastCompartmentEndMessage(db, sessionId)),
|
|
1906
|
+
excludeMessageId: userMsgId,
|
|
1776
1907
|
memoryEnabled,
|
|
1777
1908
|
embeddingEnabled,
|
|
1778
1909
|
gitCommitsEnabled,
|
|
@@ -1810,11 +1941,15 @@ async function runAutoSearchHint(args) {
|
|
|
1810
1941
|
if (results.length === 0) {
|
|
1811
1942
|
return writeNoHintAndReconcile("empty");
|
|
1812
1943
|
}
|
|
1813
|
-
|
|
1814
|
-
|
|
1944
|
+
results = selectAutoSearchResults(results, options.scoreThreshold);
|
|
1945
|
+
if (results.length === 0) {
|
|
1946
|
+
sessionLog2(sessionId, `auto-search: no fragment meets relevance threshold ${options.scoreThreshold}`);
|
|
1815
1947
|
return writeNoHintAndReconcile("below-threshold");
|
|
1816
1948
|
}
|
|
1817
|
-
const hintText = buildAutoSearchHint(results, {
|
|
1949
|
+
const hintText = buildAutoSearchHint(results, {
|
|
1950
|
+
wordRules: options.wordRules,
|
|
1951
|
+
query: rawPrompt
|
|
1952
|
+
});
|
|
1818
1953
|
if (!hintText) {
|
|
1819
1954
|
return writeNoHintAndReconcile("empty");
|
|
1820
1955
|
}
|
|
@@ -2157,6 +2292,12 @@ function canConsumeDeferredOnThisPass(args) {
|
|
|
2157
2292
|
function hasReclaimRide(signals) {
|
|
2158
2293
|
return signals.hardFold || signals.force || signals.explicitFlush || signals.publishedHistory || signals.subagentExecute === true;
|
|
2159
2294
|
}
|
|
2295
|
+
function prefixMutationPermitted(gate) {
|
|
2296
|
+
return !gate.signedThinkingHold || gate.firstRender || gate.idleExpiry || gate.emergency;
|
|
2297
|
+
}
|
|
2298
|
+
function reclaimRidePermitted(signals, gate) {
|
|
2299
|
+
return prefixMutationPermitted(gate) && hasReclaimRide(signals);
|
|
2300
|
+
}
|
|
2160
2301
|
var RECLAIM_RIDE_NAMES = [
|
|
2161
2302
|
"hardFold",
|
|
2162
2303
|
"force",
|
|
@@ -2852,33 +2993,70 @@ function createPendingDropEligibilityCache() {
|
|
|
2852
2993
|
};
|
|
2853
2994
|
}
|
|
2854
2995
|
|
|
2996
|
+
// src/features/magic-context/storage-host-instruction-retention.ts
|
|
2997
|
+
var NAMESPACE2 = "hostInstructionRetention";
|
|
2998
|
+
var enabled = true;
|
|
2999
|
+
function hostInstructionRetentionEnabled() {
|
|
3000
|
+
return enabled;
|
|
3001
|
+
}
|
|
3002
|
+
function isHostInstructionRetentionOn(db, sessionId) {
|
|
3003
|
+
const lane = readReplayEnvelope(db, sessionId)[NAMESPACE2];
|
|
3004
|
+
return typeof lane === "object" && lane !== null && lane.on === true;
|
|
3005
|
+
}
|
|
3006
|
+
function markHostInstructionRetention(db, sessionId) {
|
|
3007
|
+
return updateReplayDocument(db, sessionId, (doc) => {
|
|
3008
|
+
const lane = doc[NAMESPACE2];
|
|
3009
|
+
if (typeof lane === "object" && lane !== null && lane.on === true)
|
|
3010
|
+
return false;
|
|
3011
|
+
doc.version = 2;
|
|
3012
|
+
doc[NAMESPACE2] = { on: true };
|
|
3013
|
+
return true;
|
|
3014
|
+
});
|
|
3015
|
+
}
|
|
3016
|
+
|
|
2855
3017
|
// src/hooks/magic-context/apply-operations.ts
|
|
2856
3018
|
var RECENT_TOOL_SKELETON_WINDOW = 20;
|
|
2857
3019
|
function buildReplacementContent(tagId) {
|
|
2858
3020
|
return `[dropped §${tagId}§]`;
|
|
2859
3021
|
}
|
|
2860
3022
|
function applyNewToolDrop(target, options) {
|
|
2861
|
-
|
|
3023
|
+
const plan = planNewToolDrop(target, options, !!options.persist);
|
|
3024
|
+
if (!plan)
|
|
2862
3025
|
return { result: "incomplete", mode: "full" };
|
|
3026
|
+
options.persist?.(plan.mode);
|
|
3027
|
+
return plan.apply();
|
|
3028
|
+
}
|
|
3029
|
+
function planNewToolDrop(target, options, prepare, plannedRemovals) {
|
|
3030
|
+
if (prepare && (target?.prepareDrop?.() ?? target?.canDrop?.()) === false) {
|
|
3031
|
+
return;
|
|
2863
3032
|
}
|
|
2864
3033
|
if (!target) {
|
|
2865
|
-
|
|
2866
|
-
return { result: "absent", mode: "full" };
|
|
3034
|
+
return { mode: "full", apply: () => ({ result: "absent", mode: "full" }) };
|
|
2867
3035
|
}
|
|
2868
|
-
if (options.inWindow && hasSmallToolInput(target) || options.keepSkeleton === true || target.cannotRemove?.() === true || target.wouldStrandConversationEnd?.() === true) {
|
|
3036
|
+
if (options.inWindow && hasSmallToolInput(target) || options.keepSkeleton === true || target.cannotRemove?.() === true || target.wouldStrandConversationEnd?.(plannedRemovals) === true) {
|
|
2869
3037
|
const strip = target.hasAttachments?.() === true;
|
|
2870
|
-
|
|
3038
|
+
const mode = strip ? "skeleton_stripped" : "skeleton_real";
|
|
2871
3039
|
return {
|
|
2872
|
-
|
|
2873
|
-
|
|
3040
|
+
mode,
|
|
3041
|
+
apply: () => ({
|
|
3042
|
+
result: (strip ? target.skeletonStripped?.() : target.skeletonReal?.()) ?? "absent",
|
|
3043
|
+
mode
|
|
3044
|
+
})
|
|
2874
3045
|
};
|
|
2875
3046
|
}
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
3047
|
+
return {
|
|
3048
|
+
mode: "full",
|
|
3049
|
+
apply: () => {
|
|
3050
|
+
const result = target.drop?.() ?? "absent";
|
|
3051
|
+
if (result === "truncated" && target.hasAttachments?.() === true) {
|
|
3052
|
+
return {
|
|
3053
|
+
result: target.skeletonStripped?.() ?? "absent",
|
|
3054
|
+
mode: "skeleton_stripped"
|
|
3055
|
+
};
|
|
3056
|
+
}
|
|
3057
|
+
return { result, mode: result === "truncated" ? "skeleton_real" : "full" };
|
|
3058
|
+
}
|
|
3059
|
+
};
|
|
2882
3060
|
}
|
|
2883
3061
|
function applyPersistedToolDrop(db, sessionId, tagNumber, target, options, afterWrite) {
|
|
2884
3062
|
return applyNewToolDrop(target, {
|
|
@@ -2972,6 +3150,7 @@ function renderConvertedToolSkeletons(targets, converted) {
|
|
|
2972
3150
|
}
|
|
2973
3151
|
return didMutate;
|
|
2974
3152
|
}
|
|
3153
|
+
var PENDING_OPERATION_CHUNK_SIZE = 64;
|
|
2975
3154
|
function applyPendingOperations(sessionId, db, targets, protectedTagIds, preloadedTags, preloadedPendingOps, syntheticPendingOps = [], editMarkerTagIds = new Set, onTagReduced, onBatchComplete, onEligibilitySnapshot) {
|
|
2976
3155
|
let didMutateMessage = false;
|
|
2977
3156
|
let diagnostics;
|
|
@@ -2981,153 +3160,184 @@ function applyPendingOperations(sessionId, db, targets, protectedTagIds, preload
|
|
|
2981
3160
|
diagnostics.reasons[reason] = (diagnostics.reasons[reason] ?? 0) + 1;
|
|
2982
3161
|
};
|
|
2983
3162
|
let admitted = false;
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
const tagStatusById = new Map(tags.map((tag) => [tag.tagNumber, tag.status]));
|
|
2999
|
-
const tagTypeById = new Map(tags.map((tag) => [tag.tagNumber, tag.type]));
|
|
3000
|
-
const opsToApply = [
|
|
3001
|
-
...pendingOps.map((op) => ({ op, synthetic: false })),
|
|
3002
|
-
...syntheticPendingOps.map((op) => ({ op, synthetic: true }))
|
|
3003
|
-
];
|
|
3004
|
-
diagnostics = {
|
|
3005
|
-
source: pendingOps.length > 0 && syntheticPendingOps.length > 0 ? "mixed" : syntheticPendingOps.length > 0 ? "synthetic" : "pending",
|
|
3006
|
-
total: opsToApply.length,
|
|
3007
|
-
mutated: 0,
|
|
3008
|
-
persistedWithoutMutation: 0,
|
|
3009
|
-
reasons: {}
|
|
3010
|
-
};
|
|
3011
|
-
const skeletonWindow = new Set(preloadedTags ? tags.filter((tag) => tag.type === "tool").map((tag) => tag.tagNumber).sort((left, right) => right - left).slice(0, RECENT_TOOL_SKELETON_WINDOW) : getNewestToolTagNumbers2(db, sessionId, RECENT_TOOL_SKELETON_WINDOW));
|
|
3012
|
-
for (const { op: pendingOp, synthetic } of opsToApply) {
|
|
3013
|
-
let operationMutated = false;
|
|
3014
|
-
const tagStatus = tagStatusById.get(pendingOp.tagId);
|
|
3015
|
-
if (tagStatus === "compacted" || tagStatus === "dropped") {
|
|
3016
|
-
reject("already_reduced");
|
|
3017
|
-
if (!synthetic)
|
|
3018
|
-
removePendingOp(db, sessionId, pendingOp.tagId);
|
|
3019
|
-
continue;
|
|
3020
|
-
}
|
|
3021
|
-
const target = targets.get(pendingOp.tagId);
|
|
3022
|
-
const veto = pendingDropVeto(pendingOp.tagId, target, protectedTagIds);
|
|
3023
|
-
if (veto) {
|
|
3024
|
-
reject(veto);
|
|
3025
|
-
continue;
|
|
3026
|
-
}
|
|
3027
|
-
const isToolTag = tagTypeById.get(pendingOp.tagId) === "tool";
|
|
3028
|
-
if (synthetic) {
|
|
3029
|
-
if (!isToolTag) {
|
|
3030
|
-
reject("synthetic_non_tool");
|
|
3031
|
-
continue;
|
|
3032
|
-
}
|
|
3033
|
-
if (target?.canDrop?.() !== true) {
|
|
3034
|
-
reject("synthetic_target_not_droppable");
|
|
3035
|
-
continue;
|
|
3036
|
-
}
|
|
3163
|
+
let startedAt = 0;
|
|
3164
|
+
const mutations = [];
|
|
3165
|
+
let drainChunk;
|
|
3166
|
+
let hasMore = false;
|
|
3167
|
+
do {
|
|
3168
|
+
admitted = false;
|
|
3169
|
+
startedAt = 0;
|
|
3170
|
+
try {
|
|
3171
|
+
db.transaction(() => {
|
|
3172
|
+
admitted = true;
|
|
3173
|
+
startedAt = performance.now();
|
|
3174
|
+
if (drainChunk) {
|
|
3175
|
+
drainChunk();
|
|
3176
|
+
return;
|
|
3037
3177
|
}
|
|
3038
|
-
const
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
3178
|
+
const pendingOps = preloadedPendingOps ?? getPendingOps(db, sessionId);
|
|
3179
|
+
onEligibilitySnapshot?.(capturePendingDropEligibility(targets, protectedTagIds));
|
|
3180
|
+
const tags = preloadedTags ?? getTagsByNumbers2(db, sessionId, [
|
|
3181
|
+
...new Set([
|
|
3182
|
+
...pendingOps.map((op) => op.tagId),
|
|
3183
|
+
...syntheticPendingOps.map((op) => op.tagId)
|
|
3184
|
+
])
|
|
3185
|
+
]);
|
|
3186
|
+
const tagById = new Map(tags.map((tag) => [tag.tagNumber, tag]));
|
|
3187
|
+
const tagStatusById = new Map(tags.map((tag) => [tag.tagNumber, tag.status]));
|
|
3188
|
+
const tagTypeById = new Map(tags.map((tag) => [tag.tagNumber, tag.type]));
|
|
3189
|
+
const opsToApply = [
|
|
3190
|
+
...pendingOps.map((op) => ({ op, synthetic: false })),
|
|
3191
|
+
...syntheticPendingOps.map((op) => ({ op, synthetic: true }))
|
|
3192
|
+
];
|
|
3193
|
+
diagnostics = {
|
|
3194
|
+
source: pendingOps.length > 0 && syntheticPendingOps.length > 0 ? "mixed" : syntheticPendingOps.length > 0 ? "synthetic" : "pending",
|
|
3195
|
+
total: opsToApply.length,
|
|
3196
|
+
mutated: 0,
|
|
3197
|
+
persistedWithoutMutation: 0,
|
|
3198
|
+
reasons: {}
|
|
3199
|
+
};
|
|
3200
|
+
const skeletonWindow = new Set(preloadedTags ? tags.filter((tag) => tag.type === "tool").map((tag) => tag.tagNumber).sort((left, right) => right - left).slice(0, RECENT_TOOL_SKELETON_WINDOW) : getNewestToolTagNumbers2(db, sessionId, RECENT_TOOL_SKELETON_WINDOW));
|
|
3201
|
+
const plannedRemovals = new Set;
|
|
3202
|
+
const removedTagIds = new Set;
|
|
3203
|
+
const record = (mutated) => {
|
|
3204
|
+
if (!diagnostics)
|
|
3205
|
+
return;
|
|
3206
|
+
if (mutated) {
|
|
3207
|
+
didMutateMessage = true;
|
|
3208
|
+
diagnostics.mutated += 1;
|
|
3209
|
+
} else
|
|
3210
|
+
diagnostics.persistedWithoutMutation += 1;
|
|
3211
|
+
};
|
|
3212
|
+
let cursor = 0;
|
|
3213
|
+
drainChunk = () => {
|
|
3214
|
+
const chunk = opsToApply.slice(cursor, cursor + PENDING_OPERATION_CHUNK_SIZE);
|
|
3215
|
+
cursor += chunk.length;
|
|
3216
|
+
hasMore = cursor < opsToApply.length;
|
|
3217
|
+
for (const { op: pendingOp, synthetic } of chunk) {
|
|
3218
|
+
const tagStatus = tagStatusById.get(pendingOp.tagId);
|
|
3219
|
+
if (tagStatus === "compacted" || tagStatus === "dropped") {
|
|
3220
|
+
reject("already_reduced");
|
|
3044
3221
|
if (!synthetic)
|
|
3045
3222
|
removePendingOp(db, sessionId, pendingOp.tagId);
|
|
3046
|
-
}).immediate();
|
|
3047
|
-
} finally {
|
|
3048
|
-
if (startedAt)
|
|
3049
|
-
logSlowWriteTransaction("apply_pending_operation", startedAt);
|
|
3050
|
-
}
|
|
3051
|
-
};
|
|
3052
|
-
let shouldPersistDrop = false;
|
|
3053
|
-
if (isToolTag) {
|
|
3054
|
-
if (editMarkerTagIds.has(pendingOp.tagId)) {
|
|
3055
|
-
const strip = target?.hasAttachments?.() === true;
|
|
3056
|
-
if (target?.canDrop?.() === false || target?.prepareDrop?.() === false || !target) {
|
|
3057
|
-
reject("edit_marker_incomplete");
|
|
3058
3223
|
continue;
|
|
3059
3224
|
}
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
if (markResult === "incomplete" || markResult === "absent") {
|
|
3063
|
-
reject(`edit_marker_${markResult}`);
|
|
3225
|
+
if (removedTagIds.has(pendingOp.tagId)) {
|
|
3226
|
+
reject("drop_incomplete");
|
|
3064
3227
|
continue;
|
|
3065
3228
|
}
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
} else {
|
|
3071
|
-
const { result: dropResult, mode: appliedMode } = applyNewToolDrop(target, {
|
|
3072
|
-
inWindow: skeletonWindow.has(pendingOp.tagId),
|
|
3073
|
-
persist: persistDrop
|
|
3074
|
-
});
|
|
3075
|
-
if (dropResult === "incomplete" || synthetic && dropResult !== "removed" && dropResult !== "truncated") {
|
|
3076
|
-
reject(`drop_${dropResult}`);
|
|
3229
|
+
const target = targets.get(pendingOp.tagId);
|
|
3230
|
+
const veto = pendingDropVeto(pendingOp.tagId, target, protectedTagIds);
|
|
3231
|
+
if (veto) {
|
|
3232
|
+
reject(veto);
|
|
3077
3233
|
continue;
|
|
3078
3234
|
}
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3235
|
+
const isToolTag = tagTypeById.get(pendingOp.tagId) === "tool";
|
|
3236
|
+
if (synthetic) {
|
|
3237
|
+
if (!isToolTag) {
|
|
3238
|
+
reject("synthetic_non_tool");
|
|
3239
|
+
continue;
|
|
3240
|
+
}
|
|
3241
|
+
if (target?.canDrop?.() !== true) {
|
|
3242
|
+
reject("synthetic_target_not_droppable");
|
|
3243
|
+
continue;
|
|
3244
|
+
}
|
|
3245
|
+
}
|
|
3246
|
+
const persistDrop = (mode) => {
|
|
3247
|
+
markTagDropped2(db, sessionId, pendingOp.tagId, mode);
|
|
3248
|
+
if (!synthetic)
|
|
3249
|
+
removePendingOp(db, sessionId, pendingOp.tagId);
|
|
3250
|
+
};
|
|
3251
|
+
if (isToolTag) {
|
|
3252
|
+
if (editMarkerTagIds.has(pendingOp.tagId)) {
|
|
3253
|
+
const strip = target?.hasAttachments?.() === true;
|
|
3254
|
+
if (target?.canDrop?.() === false || target?.prepareDrop?.() === false || !target) {
|
|
3255
|
+
reject("edit_marker_incomplete");
|
|
3256
|
+
continue;
|
|
3257
|
+
}
|
|
3258
|
+
persistDrop(strip ? "edit_marker_stripped" : "edit_marker");
|
|
3259
|
+
mutations.push(() => {
|
|
3260
|
+
const markResult = (strip ? target?.editMarkerStripped?.() : target?.editMarker?.()) ?? "absent";
|
|
3261
|
+
if (markResult === "incomplete" || markResult === "absent") {
|
|
3262
|
+
reject(`edit_marker_${markResult}`);
|
|
3263
|
+
return;
|
|
3264
|
+
}
|
|
3265
|
+
record(true);
|
|
3266
|
+
onTagReduced?.({
|
|
3267
|
+
tagNumber: pendingOp.tagId,
|
|
3268
|
+
mode: "edit_marker"
|
|
3269
|
+
});
|
|
3270
|
+
});
|
|
3271
|
+
} else {
|
|
3272
|
+
const plan = planNewToolDrop(target, { inWindow: skeletonWindow.has(pendingOp.tagId) }, true, plannedRemovals);
|
|
3273
|
+
if (!plan) {
|
|
3274
|
+
reject("drop_incomplete");
|
|
3275
|
+
continue;
|
|
3276
|
+
}
|
|
3277
|
+
persistDrop(plan.mode);
|
|
3278
|
+
if (plan.mode === "full" && target?.drop) {
|
|
3279
|
+
target.notePlannedRemoval?.(plannedRemovals);
|
|
3280
|
+
removedTagIds.add(pendingOp.tagId);
|
|
3281
|
+
}
|
|
3282
|
+
mutations.push(() => {
|
|
3283
|
+
const { result: dropResult, mode: appliedMode } = plan.apply();
|
|
3284
|
+
if (dropResult === "incomplete" || synthetic && dropResult !== "removed" && dropResult !== "truncated") {
|
|
3285
|
+
reject(`drop_${dropResult}`);
|
|
3286
|
+
return;
|
|
3287
|
+
}
|
|
3288
|
+
if (dropResult === "removed" || dropResult === "truncated") {
|
|
3289
|
+
record(true);
|
|
3290
|
+
onTagReduced?.({
|
|
3291
|
+
tagNumber: pendingOp.tagId,
|
|
3292
|
+
mode: appliedMode === "full" ? "full" : "truncated"
|
|
3293
|
+
});
|
|
3294
|
+
} else {
|
|
3295
|
+
reject(`drop_${dropResult}`);
|
|
3296
|
+
record(false);
|
|
3297
|
+
}
|
|
3298
|
+
});
|
|
3299
|
+
}
|
|
3300
|
+
} else if (target) {
|
|
3301
|
+
const replacement = buildReplacementContent(pendingOp.tagId);
|
|
3302
|
+
persistDrop();
|
|
3303
|
+
mutations.push(() => {
|
|
3304
|
+
const priorContent = target.getContent?.();
|
|
3305
|
+
const changed = target.setContent(replacement);
|
|
3306
|
+
record(changed);
|
|
3307
|
+
if (changed) {
|
|
3308
|
+
const originalCharacters = typeof priorContent === "string" ? priorContent.length : tagById.get(pendingOp.tagId)?.byteSize ?? replacement.length;
|
|
3309
|
+
onTagReduced?.({
|
|
3310
|
+
tagNumber: pendingOp.tagId,
|
|
3311
|
+
mode: "partial",
|
|
3312
|
+
removedCharacters: Math.max(0, originalCharacters - replacement.length)
|
|
3313
|
+
});
|
|
3314
|
+
} else {
|
|
3315
|
+
reject("content_unchanged");
|
|
3316
|
+
}
|
|
3085
3317
|
});
|
|
3086
|
-
} else {
|
|
3087
|
-
reject(
|
|
3318
|
+
} else if (!synthetic) {
|
|
3319
|
+
reject("target_absent");
|
|
3320
|
+
persistDrop();
|
|
3321
|
+
mutations.push(() => record(false));
|
|
3088
3322
|
}
|
|
3089
|
-
shouldPersistDrop = true;
|
|
3090
3323
|
}
|
|
3091
|
-
}
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
onTagReduced?.({
|
|
3101
|
-
tagNumber: pendingOp.tagId,
|
|
3102
|
-
mode: "partial",
|
|
3103
|
-
removedCharacters: Math.max(0, originalCharacters - replacement.length)
|
|
3104
|
-
});
|
|
3105
|
-
} else {
|
|
3106
|
-
reject("content_unchanged");
|
|
3107
|
-
}
|
|
3108
|
-
shouldPersistDrop = true;
|
|
3109
|
-
} else if (!synthetic) {
|
|
3110
|
-
reject("target_absent");
|
|
3111
|
-
persistDrop();
|
|
3112
|
-
shouldPersistDrop = true;
|
|
3113
|
-
}
|
|
3114
|
-
if (!shouldPersistDrop) {
|
|
3115
|
-
reject("not_persisted");
|
|
3116
|
-
continue;
|
|
3117
|
-
}
|
|
3118
|
-
if (operationMutated)
|
|
3119
|
-
diagnostics.mutated += 1;
|
|
3120
|
-
else
|
|
3121
|
-
diagnostics.persistedWithoutMutation += 1;
|
|
3324
|
+
};
|
|
3325
|
+
drainChunk();
|
|
3326
|
+
}).immediate();
|
|
3327
|
+
} catch (error) {
|
|
3328
|
+
if (!admitted && /database (?:table )?is locked|sqlite_(busy|locked)/i.test(String(error))) {
|
|
3329
|
+
sessionLog2(sessionId, "pending operations write admission busy; retaining remaining operations for retry");
|
|
3330
|
+
hasMore = false;
|
|
3331
|
+
} else {
|
|
3332
|
+
throw error;
|
|
3122
3333
|
}
|
|
3334
|
+
} finally {
|
|
3335
|
+
if (startedAt)
|
|
3336
|
+
logSlowWriteTransaction("apply_pending_operations", startedAt);
|
|
3123
3337
|
}
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
return false;
|
|
3128
|
-
}
|
|
3129
|
-
throw error;
|
|
3130
|
-
}
|
|
3338
|
+
for (const mutate of mutations.splice(0))
|
|
3339
|
+
mutate();
|
|
3340
|
+
} while (hasMore);
|
|
3131
3341
|
if (diagnostics) {
|
|
3132
3342
|
onBatchComplete?.(diagnostics);
|
|
3133
3343
|
if (diagnostics.total > 0 && diagnostics.mutated === 0) {
|
|
@@ -4170,10 +4380,41 @@ function createExistingTagResolver(sessionId, tagger, db) {
|
|
|
4170
4380
|
}
|
|
4171
4381
|
|
|
4172
4382
|
// src/hooks/magic-context/transform-stage-logger.ts
|
|
4173
|
-
|
|
4174
|
-
|
|
4383
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
4384
|
+
var SLOW_STAGE_MS = 100;
|
|
4385
|
+
var passes = new AsyncLocalStorage;
|
|
4386
|
+
async function withTransformTimingSummary(run) {
|
|
4387
|
+
const pass = {
|
|
4388
|
+
stages: [],
|
|
4389
|
+
slow: [],
|
|
4390
|
+
closed: false,
|
|
4391
|
+
sessionId: undefined
|
|
4392
|
+
};
|
|
4393
|
+
return passes.run(pass, async () => {
|
|
4394
|
+
try {
|
|
4395
|
+
return await run();
|
|
4396
|
+
} finally {
|
|
4397
|
+
pass.closed = true;
|
|
4398
|
+
if (pass.sessionId)
|
|
4399
|
+
sessionLog2(pass.sessionId, `transform stages: ${pass.stages.join(" ")} slow>=${SLOW_STAGE_MS}ms=[${pass.slow.join(",")}]`);
|
|
4400
|
+
}
|
|
4401
|
+
});
|
|
4402
|
+
}
|
|
4403
|
+
function logTransformElapsed(sessionId, stage, elapsedMs, extra) {
|
|
4404
|
+
const elapsed = elapsedMs.toFixed(1);
|
|
4175
4405
|
const suffix = extra ? ` ${extra}` : "";
|
|
4176
|
-
|
|
4406
|
+
const pass = passes.getStore();
|
|
4407
|
+
if (pass && !pass.closed) {
|
|
4408
|
+
pass.sessionId = sessionId;
|
|
4409
|
+
pass.stages.push(`${stage}=${elapsed}ms${extra ? `(${extra})` : ""}`);
|
|
4410
|
+
if (elapsedMs >= SLOW_STAGE_MS)
|
|
4411
|
+
pass.slow.push(stage);
|
|
4412
|
+
}
|
|
4413
|
+
if (elapsedMs >= SLOW_STAGE_MS)
|
|
4414
|
+
sessionLog2(sessionId, `transform stage: stage=${stage} elapsed=${elapsed}ms${suffix}`);
|
|
4415
|
+
}
|
|
4416
|
+
function logTransformTiming(sessionId, stage, startMs, extra) {
|
|
4417
|
+
logTransformElapsed(sessionId, stage, performance.now() - startMs, extra);
|
|
4177
4418
|
}
|
|
4178
4419
|
|
|
4179
4420
|
// src/hooks/magic-context/tag-messages.ts
|
|
@@ -4539,13 +4780,18 @@ function tagMessages(sessionId, messages, tagger, db, options = {}) {
|
|
|
4539
4780
|
}));
|
|
4540
4781
|
accAssignTag += performance.now() - _tAssignText;
|
|
4541
4782
|
const persistedSource = sourceContents.get(tagId);
|
|
4542
|
-
if (persistedSource !== undefined) {
|
|
4783
|
+
if (persistedSource !== undefined && !options.refreshSourceContents) {
|
|
4543
4784
|
textPart.text = options.normalizeRestoredAssistantText && message.info.role === "assistant" ? options.normalizeRestoredAssistantText(persistedSource) : persistedSource;
|
|
4544
4785
|
} else {
|
|
4545
4786
|
const sourceContent = stripTagPrefix(textPart.text);
|
|
4546
|
-
if (sourceContent.trim().length > 0) {
|
|
4787
|
+
if (sourceContent.trim().length > 0 || options.refreshSourceContents) {
|
|
4547
4788
|
const _tSaveText = performance.now();
|
|
4548
|
-
|
|
4789
|
+
if (options.refreshSourceContents) {
|
|
4790
|
+
replaceSourceContent(db, sessionId, tagId, sourceContent);
|
|
4791
|
+
updateTagByteSize2(db, sessionId, tagId, byteSize(sourceContent));
|
|
4792
|
+
updateTagTokenCount2(db, sessionId, tagId, estimateTextTagTokenCount(sourceContent));
|
|
4793
|
+
} else
|
|
4794
|
+
saveSourceContent(db, sessionId, tagId, sourceContent);
|
|
4549
4795
|
accSaveSource += performance.now() - _tSaveText;
|
|
4550
4796
|
}
|
|
4551
4797
|
}
|
|
@@ -4626,22 +4872,12 @@ function tagMessages(sessionId, messages, tagger, db, options = {}) {
|
|
|
4626
4872
|
const filePart = part;
|
|
4627
4873
|
const messageParts = message.parts;
|
|
4628
4874
|
const contentId = `${messageId}:file${partIndex}`;
|
|
4629
|
-
const existingTagId = resolver.resolve(messageId, "file", contentId, fileOrdinal);
|
|
4630
|
-
|
|
4631
|
-
|
|
4632
|
-
|
|
4633
|
-
|
|
4634
|
-
|
|
4635
|
-
}));
|
|
4636
|
-
accAssignTag += performance.now() - _tAssignFile;
|
|
4637
|
-
if (existingTagId === undefined) {
|
|
4638
|
-
const sourceContent = buildFileSourceContent(message.parts);
|
|
4639
|
-
if (sourceContent) {
|
|
4640
|
-
const _tSaveFile = performance.now();
|
|
4641
|
-
saveSourceContent(db, sessionId, tagId, sourceContent);
|
|
4642
|
-
accSaveSource += performance.now() - _tSaveFile;
|
|
4643
|
-
}
|
|
4644
|
-
}
|
|
4875
|
+
const existingTagId = resolver.resolve(messageId, "file", contentId, fileOrdinal) ?? getTagNumberByMessageId2(db, sessionId, contentId) ?? undefined;
|
|
4876
|
+
fileOrdinal += 1;
|
|
4877
|
+
if (existingTagId === undefined)
|
|
4878
|
+
continue;
|
|
4879
|
+
const tagId = existingTagId;
|
|
4880
|
+
tagger.bindTag(sessionId, contentId, tagId);
|
|
4645
4881
|
messageTagNumbers.set(message, Math.max(messageTagNumbers.get(message) ?? 0, tagId));
|
|
4646
4882
|
targets.set(tagId, {
|
|
4647
4883
|
message,
|
|
@@ -4663,7 +4899,6 @@ function tagMessages(sessionId, messages, tagger, db, options = {}) {
|
|
|
4663
4899
|
return true;
|
|
4664
4900
|
}
|
|
4665
4901
|
});
|
|
4666
|
-
fileOrdinal += 1;
|
|
4667
4902
|
}
|
|
4668
4903
|
}
|
|
4669
4904
|
if (message.info.role === "assistant" && !messageHasTextPart) {
|
|
@@ -5431,7 +5666,7 @@ async function runPostTransformPhase2(args) {
|
|
|
5431
5666
|
routinePressureAppliedBySession.set(args.sessionId, true);
|
|
5432
5667
|
}
|
|
5433
5668
|
const routinePressureAlreadyApplied = args.fullFeatureMode && executePressureEligible && routinePressureAppliedBySession.get(args.sessionId) === true;
|
|
5434
|
-
if (args.contextUsage.percentage > 0 && args.contextUsage.percentage < args.forceMaterializationPercentage - 5 && getEmergencyInputSample(args.db, args.sessionId) > 0) {
|
|
5669
|
+
if (args.contextUsageFromEstimate !== true && args.contextUsage.percentage > 0 && args.contextUsage.percentage < args.forceMaterializationPercentage - 5 && getEmergencyInputSample(args.db, args.sessionId) > 0) {
|
|
5435
5670
|
clearEmergencyDropSample(args.db, args.sessionId);
|
|
5436
5671
|
}
|
|
5437
5672
|
const activeCompartmentRun = args.canRunCompartments ? getActiveCompartmentRun(args.sessionId) : undefined;
|
|
@@ -5461,7 +5696,7 @@ async function runPostTransformPhase2(args) {
|
|
|
5461
5696
|
if (tag && tag > 0)
|
|
5462
5697
|
safeReasoningCutoff = Math.min(safeReasoningCutoff, tag - 1);
|
|
5463
5698
|
}
|
|
5464
|
-
let activeThinkingPrefixHold = args.activeThinkingPrefixHold === true
|
|
5699
|
+
let activeThinkingPrefixHold = args.activeThinkingPrefixHold === true;
|
|
5465
5700
|
let freezeM0M1 = args.freezeM0M1 === true || activeThinkingPrefixHold;
|
|
5466
5701
|
let rewritingSignedPrefix = false;
|
|
5467
5702
|
let thinkingReleasedForFit = false;
|
|
@@ -5483,7 +5718,7 @@ async function runPostTransformPhase2(args) {
|
|
|
5483
5718
|
rewritingSignedPrefix = true;
|
|
5484
5719
|
thinkingReleasedForFit ||= forFit;
|
|
5485
5720
|
};
|
|
5486
|
-
if (activeThinkingPrefixHold && args.
|
|
5721
|
+
if (args.forceSignedRebuildForFit && (activeThinkingPrefixHold || activeThinkingTurn && args.thinkingBindingRecoveryEnabledForModel === true)) {
|
|
5487
5722
|
releaseThinkingForRewrite(true);
|
|
5488
5723
|
}
|
|
5489
5724
|
const foldDueDecision = m0M1EnabledForFold && args.m0M1 && !freezeM0M1 ? mustMaterialize({
|
|
@@ -5620,7 +5855,7 @@ async function runPostTransformPhase2(args) {
|
|
|
5620
5855
|
const shouldReadPendingOps = !compactionOff && (materializationRequested || publishedM1RefreshedThisPass || args.schedulerDecision === "execute" || forceMaterialization || foldExecutedThisPass || firstRenderBust || compartmentRunning);
|
|
5621
5856
|
const pendingOps = shouldReadPendingOps ? getPendingOps(args.db, args.sessionId) : [];
|
|
5622
5857
|
const hasPendingUserOps = pendingOps.length > 0;
|
|
5623
|
-
if (args.schedulerDecision === "execute" && pendingOps.some((op) => newTargets.get(op.tagId)?.thinkingDropProtected))
|
|
5858
|
+
if (args.schedulerDecision === "execute" && args.thinkingBindingRecoveryEnabledForModel !== true && pendingOps.some((op) => newTargets.get(op.tagId)?.thinkingDropProtected))
|
|
5624
5859
|
requestPendingMaterialization(args.pendingMaterializationSessions, args.sessionId, "thinking_hold");
|
|
5625
5860
|
const formatPendingOpsDepth = () => {
|
|
5626
5861
|
const depth = getPendingOpsCount(args.db, args.sessionId);
|
|
@@ -5631,16 +5866,34 @@ async function runPostTransformPhase2(args) {
|
|
|
5631
5866
|
const rideSignals = {
|
|
5632
5867
|
subagentExecute: !args.fullFeatureMode && args.schedulerDecision === "execute",
|
|
5633
5868
|
hardFold: rewritingSignedPrefix || foldBustsServedPrefixThisPass || firstRenderBust || idleExpiryRebuild,
|
|
5634
|
-
force: emergencyDropEligible && (args.contextUsage.percentage >= 95 || getEmergencyInputSample(args.db, args.sessionId) === 0),
|
|
5869
|
+
force: emergencyDropEligible && (args.contextUsage.percentage >= 95 || args.contextUsageFromEstimate !== true && getEmergencyInputSample(args.db, args.sessionId) === 0),
|
|
5635
5870
|
explicitFlush: isExplicitFlush && hasPendingMaterializationOrigin(args.pendingMaterializationSessions, args.sessionId, "user_flush"),
|
|
5636
5871
|
publishedHistory: !prefixPreflightFailed && (publishedM1RefreshedThisPass || !m0M1EnabledForFold && (args.pendingCompartmentInjection?.compartmentCount ?? 0) > 0 && legacyPublishedHeadChanged(args))
|
|
5637
5872
|
};
|
|
5638
|
-
const publishedWorkDrainAllowed = !compactionOff && (
|
|
5873
|
+
const publishedWorkDrainAllowed = !compactionOff && reclaimRidePermitted(rideSignals, {
|
|
5874
|
+
signedThinkingHold: activeThinkingPrefixHold,
|
|
5875
|
+
firstRender: firstRenderBust,
|
|
5876
|
+
idleExpiry: idleExpiryRebuild,
|
|
5877
|
+
emergency: emergencyDropEligible
|
|
5878
|
+
});
|
|
5639
5879
|
const shouldApplyPendingOps = publishedWorkDrainAllowed;
|
|
5640
5880
|
const shouldRunHeuristics = publishedWorkDrainAllowed && (rideSignals.publishedHistory || materializationRequested || forceMaterialization || foldBustsServedPrefixThisPass || firstRenderBust || heldIdleExpiryRebuild || emergencyDropEligible || args.schedulerDecision === "execute" && (!alreadyRanThisTurn || !args.fullFeatureMode));
|
|
5641
5881
|
const isCacheBustingPass = publishedWorkDrainAllowed;
|
|
5642
|
-
|
|
5882
|
+
let unheldSignedTurnBust = false;
|
|
5883
|
+
if (isCacheBustingPass && !activeThinkingPrefixHold && activeThinkingTurn && args.thinkingBindingRecoveryEnabledForModel === true) {
|
|
5884
|
+
if (foldBustsServedPrefixThisPass || firstRenderBust || publishedM1RefreshedThisPass)
|
|
5885
|
+
releaseThinkingForRewrite();
|
|
5886
|
+
else {
|
|
5887
|
+
unheldSignedTurnBust = true;
|
|
5888
|
+
retainedThinking.clear();
|
|
5889
|
+
protectedThinkingMessages.clear();
|
|
5890
|
+
newTargets = args.targets;
|
|
5891
|
+
}
|
|
5892
|
+
}
|
|
5893
|
+
let recoveryTailNormalizedThisPass = false;
|
|
5894
|
+
if (args.normalizeRecoveryTail && isCacheBustingPass && !activeThinkingPrefixHold) {
|
|
5643
5895
|
args.normalizeRecoveryTail();
|
|
5896
|
+
recoveryTailNormalizedThisPass = true;
|
|
5644
5897
|
args.tags = getTagsBySession2(args.db, args.sessionId);
|
|
5645
5898
|
newTargets = protectNewTagMutations(args.messages, args.targets, retainedThinking, args.thinkingBindingRecoveryEnabledForModel === true);
|
|
5646
5899
|
}
|
|
@@ -6111,6 +6364,26 @@ async function runPostTransformPhase2(args) {
|
|
|
6111
6364
|
}
|
|
6112
6365
|
}
|
|
6113
6366
|
const m0M1Enabled = m0M1EnabledForFold;
|
|
6367
|
+
if (m0M1Enabled && args.m0M1 && !compactionOff && args.opencode2) {
|
|
6368
|
+
const covered = args.coveredHostInstructions ?? [];
|
|
6369
|
+
if (covered.length > 0 || canEditWholePrefix) {
|
|
6370
|
+
let retain = false;
|
|
6371
|
+
if (hostInstructionRetentionEnabled()) {
|
|
6372
|
+
try {
|
|
6373
|
+
retain = isHostInstructionRetentionOn(args.db, args.sessionId);
|
|
6374
|
+
} catch (error) {
|
|
6375
|
+
failPass("host-instruction-retention-read-failure", error);
|
|
6376
|
+
}
|
|
6377
|
+
if (!retain && canEditWholePrefix) {
|
|
6378
|
+
if (!markHostInstructionRetention(args.db, args.sessionId))
|
|
6379
|
+
failPass("host-instruction-retention-persistence-failure");
|
|
6380
|
+
retain = true;
|
|
6381
|
+
}
|
|
6382
|
+
}
|
|
6383
|
+
if (retain && covered.length > 0)
|
|
6384
|
+
args.messages.unshift(...covered);
|
|
6385
|
+
}
|
|
6386
|
+
}
|
|
6114
6387
|
if (m0M1Enabled && args.m0M1) {
|
|
6115
6388
|
if (freezeM0M1 && !preparedPrefix) {
|
|
6116
6389
|
preparedPrefix = prepareCachedM0M1Replay(args.db, args.sessionId);
|
|
@@ -6633,7 +6906,7 @@ async function runPostTransformPhase2(args) {
|
|
|
6633
6906
|
}
|
|
6634
6907
|
}
|
|
6635
6908
|
}
|
|
6636
|
-
const prefixEditBesidesReasoningTrim = firstRenderBust || heldIdleExpiryRebuild || materializationRequested || explicitMaterializedSuccessfully || deferredMaterializedSuccessfully || foldBustsServedPrefixThisPass || publishedM1RefreshedThisPass || m0RematerializedThisPass || m0M1InjectedThisPass && historyWasConsumedThisPass || historyWasConsumedThisPass || pendingOpsDidMutate || heuristicOrReasoningEditBesidesTrim || emergency || autoReclaimDidMutateThisPass || convertedToolSkeletonsDidMutate || deferredClearedMarkerRetires || noteNudgeAppendedThisPass || todoAnchorMovedThisPass || autoSearchHintAppendedThisPass || dropModeSwitchesThisPass || firstApplicationEdits.beforeNewerThinking;
|
|
6909
|
+
const prefixEditBesidesReasoningTrim = firstRenderBust || heldIdleExpiryRebuild || materializationRequested || explicitMaterializedSuccessfully || deferredMaterializedSuccessfully || foldBustsServedPrefixThisPass || publishedM1RefreshedThisPass || m0RematerializedThisPass || m0M1InjectedThisPass && historyWasConsumedThisPass || historyWasConsumedThisPass || pendingOpsDidMutate || heuristicOrReasoningEditBesidesTrim || emergency || autoReclaimDidMutateThisPass || convertedToolSkeletonsDidMutate || deferredClearedMarkerRetires || noteNudgeAppendedThisPass || todoAnchorMovedThisPass || autoSearchHintAppendedThisPass || dropModeSwitchesThisPass || recoveryTailNormalizedThisPass || firstApplicationEdits.beforeNewerThinking;
|
|
6637
6910
|
let proactiveThinkingStrip = null;
|
|
6638
6911
|
if (!compactionOff && args.thinkingBindingRecoveryEnabledForModel === true && proactiveThinkingStripPermitted && prefixEditBesidesReasoningTrim) {
|
|
6639
6912
|
const outcome = freezeReasoningOnBustingPass2({
|
|
@@ -6650,7 +6923,11 @@ async function runPostTransformPhase2(args) {
|
|
|
6650
6923
|
mergedReasoningStrippedIds.add(thinkingBindingRecoveryFrozenId(messageId));
|
|
6651
6924
|
}
|
|
6652
6925
|
bustedThisPass = true;
|
|
6926
|
+
if (unheldSignedTurnBust)
|
|
6927
|
+
rewritingSignedPrefix = true;
|
|
6653
6928
|
} else if (outcome.persistenceFailed) {
|
|
6929
|
+
if (unheldSignedTurnBust)
|
|
6930
|
+
throw new Error("Cannot persist signed thinking omission after a mid-turn edit");
|
|
6654
6931
|
failPass("proactive-thinking-strip-persistence-failure");
|
|
6655
6932
|
}
|
|
6656
6933
|
}
|
|
@@ -6809,7 +7086,8 @@ async function runPostTransformPhase2(args) {
|
|
|
6809
7086
|
prefixTrimStatus: deliveredPrefix?.prefixTrimStatus ?? null,
|
|
6810
7087
|
thinkingBindingRecovery,
|
|
6811
7088
|
proactiveThinkingStrip,
|
|
6812
|
-
thinkingReleasedForFit
|
|
7089
|
+
thinkingReleasedForFit,
|
|
7090
|
+
openTurnSignedThinkingKept: args.thinkingBindingRecoveryEnabledForModel === true && activeThinkingTurn && !rewritingSignedPrefix
|
|
6813
7091
|
};
|
|
6814
7092
|
}
|
|
6815
7093
|
function checkM0MutationDriftAndSignal2(args) {
|
|
@@ -6824,4 +7102,4 @@ function checkM0MutationDriftAndSignal2(args) {
|
|
|
6824
7102
|
return false;
|
|
6825
7103
|
}
|
|
6826
7104
|
|
|
6827
|
-
export { makeToolCompositeKey, createTagger, cavemanWordRulesForLanguage, searchMessageHistoryOffThread, findSessionId, findLastUserMessageId, clearAutoSearchForSession, setCtxReduceRegisteredGlobally, resolveCtxReduceAvailabilityFromMessages, resolveCtxReduceAvailability, primeCtxReduceSpawnPermission, ctxReduceSpawnPermissionReadNeeded, spawnAgentFromMessages, spawnAgentFromOpenCodeDb, todowritePermissionDenied, cachedToolPermissionDenied, clearToolPermissionDenied, resolveTodowriteAvailabilityFromMessages, resolveTodowriteAvailability, canConsumeDeferredOnThisPass, hasReclaimRide, reclaimRideLabel, captureOpencodeReasoningBudgetStatus, reasoningBudgetStatusLine, ENGINE_RECONNECTING_USER_MESSAGE, ENGINE_BUSY_USER_MESSAGE, SIGNED_THINKING_RESET_FENCE_FAILED, contextRefusalError, protectedToolRefusal, outgoingContextRefusal, signedTurnContextRefusal, EmergencyFailClosedError, latestAssistantTurnStart, latestAssistantTurnMessages, hasActiveAnthropicThinkingTurn, replayCavemanCompression, DegradedPassRefusalError, degradedPassError, pendingDropEligibilityKey, createPendingDropEligibilityCache, applyFlushedStatuses, prewarmTagOwners, waitForTagOwners, stripStructuralNoise, logTransformTiming, hasRecentAssistantCommit, tagMessages, resetDegradedCacheCount2, isSyntheticHeadMessage2, applyTodoSynthesis2, freezeReasoningOnBustingPass2, firstServedDivergenceIndex2, rustModeServedKeyAfterPersistedStrips2, replayRustModeBindingMismatchStrips2, RUST_MARKER_LOCK_SKIP_LOG2, applyRustModeDeferredCompactionMarker2, clearRustModeBoundaryRecord2, runRustModePostprocess2, reconcileMarkerRepresentation2, clearPendingCompactionMarkerAfterSuccessfulDrain2, defaultCompactionMarkerStrategy2, abortSessionFailClosed2, evaluateEmergencyFailClosed2, finalizeMessageRepresentation2, runPostTransformPhase2, checkM0MutationDriftAndSignal2 };
|
|
7105
|
+
export { makeToolCompositeKey, createTagger, cavemanWordRulesForLanguage, searchMessageHistoryOffThread, findSessionId, findLastUserMessageId, clearAutoSearchForSession, setCtxReduceRegisteredGlobally, resolveCtxReduceAvailabilityFromMessages, resolveCtxReduceAvailability, primeCtxReduceSpawnPermission, ctxReduceSpawnPermissionReadNeeded, spawnAgentFromMessages, spawnAgentFromOpenCodeDb, todowritePermissionDenied, cachedToolPermissionDenied, clearToolPermissionDenied, resolveTodowriteAvailabilityFromMessages, resolveTodowriteAvailability, canConsumeDeferredOnThisPass, hasReclaimRide, reclaimRidePermitted, reclaimRideLabel, captureOpencodeReasoningBudgetStatus, reasoningBudgetStatusLine, ENGINE_RECONNECTING_USER_MESSAGE, ENGINE_BUSY_USER_MESSAGE, SIGNED_THINKING_RESET_FENCE_FAILED, contextRefusalError, protectedToolRefusal, outgoingContextRefusal, signedTurnContextRefusal, EmergencyFailClosedError, latestAssistantTurnStart, latestAssistantTurnMessages, hasActiveAnthropicThinkingTurn, replayCavemanCompression, DegradedPassRefusalError, degradedPassError, pendingDropEligibilityKey, createPendingDropEligibilityCache, applyFlushedStatuses, prewarmTagOwners, waitForTagOwners, stripStructuralNoise, withTransformTimingSummary, logTransformTiming, hasRecentAssistantCommit, tagMessages, resetDegradedCacheCount2, isSyntheticHeadMessage2, applyTodoSynthesis2, freezeReasoningOnBustingPass2, firstServedDivergenceIndex2, rustModeServedKeyAfterPersistedStrips2, replayRustModeBindingMismatchStrips2, RUST_MARKER_LOCK_SKIP_LOG2, applyRustModeDeferredCompactionMarker2, clearRustModeBoundaryRecord2, runRustModePostprocess2, reconcileMarkerRepresentation2, clearPendingCompactionMarkerAfterSuccessfulDrain2, defaultCompactionMarkerStrategy2, abortSessionFailClosed2, evaluateEmergencyFailClosed2, finalizeMessageRepresentation2, runPostTransformPhase2, checkM0MutationDriftAndSignal2 };
|