@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
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
resolveLegacyConfigSources,
|
|
7
7
|
getProtectedTokensTierOverrides,
|
|
8
8
|
loadPluginConfigDetailed
|
|
9
|
-
} from "./server-
|
|
9
|
+
} from "./server-nj659894.js";
|
|
10
10
|
import {
|
|
11
11
|
getHarness2,
|
|
12
12
|
harnessOwnsOpenCodeStore2
|
|
@@ -86,10 +86,6 @@ import {
|
|
|
86
86
|
getUnpublishedAutoSearchNoHint,
|
|
87
87
|
forgetUnpublishedAutoSearchNoHint,
|
|
88
88
|
registerAutoSearchWork,
|
|
89
|
-
gaDatabasePath,
|
|
90
|
-
RAW_MESSAGE_TYPES,
|
|
91
|
-
V2StoreReaderPool,
|
|
92
|
-
V2StoreReader,
|
|
93
89
|
getOrCreateSessionMeta,
|
|
94
90
|
updateSessionMeta,
|
|
95
91
|
advanceToolReclaimWatermark,
|
|
@@ -271,6 +267,7 @@ import {
|
|
|
271
267
|
peekNoteNudgeText,
|
|
272
268
|
markNoteNudgeDelivered,
|
|
273
269
|
clearNoteNudgeTriggerAndCooldown,
|
|
270
|
+
omitIncompleteFileTokenTotals,
|
|
274
271
|
RECOVERY_NO_HEAD_LIMIT,
|
|
275
272
|
deriveProtectedTailTokenTarget,
|
|
276
273
|
selectPerRunCap,
|
|
@@ -283,7 +280,7 @@ import {
|
|
|
283
280
|
startCompartmentAgent,
|
|
284
281
|
setRecompStarting2,
|
|
285
282
|
setRecompTerminal2
|
|
286
|
-
} from "./server-
|
|
283
|
+
} from "./server-bfpda1tb.js";
|
|
287
284
|
import {
|
|
288
285
|
resolveHistorianModel2
|
|
289
286
|
} from "./server-8cd2j99z.js";
|
|
@@ -308,8 +305,9 @@ import {
|
|
|
308
305
|
openDatabaseAsync,
|
|
309
306
|
isDatabasePersisted,
|
|
310
307
|
getDatabasePersistenceError
|
|
311
|
-
} from "./server-
|
|
308
|
+
} from "./server-a2eqhkxr.js";
|
|
312
309
|
import {
|
|
310
|
+
pruneMissingProjectIdentities,
|
|
313
311
|
setHomeProjectPermission,
|
|
314
312
|
shouldSkipHomeProjectMemory,
|
|
315
313
|
ProjectIdentityError,
|
|
@@ -324,21 +322,25 @@ import {
|
|
|
324
322
|
storedPathBelongsToIdentity,
|
|
325
323
|
beginBootQuietPeriod,
|
|
326
324
|
scheduleAfterBootQuiet
|
|
327
|
-
} from "./server-
|
|
325
|
+
} from "./server-rmygf5pn.js";
|
|
328
326
|
import {
|
|
329
327
|
detectLatestTurnThinkingMismatch,
|
|
330
328
|
isPrefixBoundThinkingModel,
|
|
331
329
|
detectOverflow,
|
|
332
330
|
ensureSessionMetaRow,
|
|
333
331
|
clearCachedM0M1,
|
|
332
|
+
clearCachedM0,
|
|
334
333
|
expandToolPart,
|
|
335
334
|
markHostUnservedRow,
|
|
335
|
+
markCoveredInstructionRow,
|
|
336
|
+
isCoveredInstructionRow,
|
|
337
|
+
takeCoveredInstructionRows,
|
|
338
|
+
cloneKeepingCoveredInstructionMarks,
|
|
336
339
|
estimateTrueRawMessageTokens,
|
|
337
340
|
stripSystemInjection,
|
|
338
341
|
isTextPart,
|
|
339
342
|
isToolPartWithOutput,
|
|
340
343
|
isFilePart,
|
|
341
|
-
buildFileSourceContent,
|
|
342
344
|
toolPartHasUserAnswer,
|
|
343
345
|
DreamTokenBudgetExceeded,
|
|
344
346
|
createDreamTokenBudget,
|
|
@@ -476,6 +478,7 @@ import {
|
|
|
476
478
|
projectOpencodeReasoningBudgetCutoff,
|
|
477
479
|
DEFAULT_KEEP_REASONING_TOKENS,
|
|
478
480
|
resolveKeepReasoningTokens,
|
|
481
|
+
reasoningStepCost,
|
|
479
482
|
reasoningBudgetCutoff,
|
|
480
483
|
reasoningTextAndOpaque,
|
|
481
484
|
opencodeReasoningBudgetCutoff,
|
|
@@ -512,7 +515,7 @@ import {
|
|
|
512
515
|
readRawSessionMessageById2,
|
|
513
516
|
readSessionChunk2,
|
|
514
517
|
readRawSessionSeedTail2
|
|
515
|
-
} from "./server-
|
|
518
|
+
} from "./server-xhab8jx8.js";
|
|
516
519
|
import {
|
|
517
520
|
embedPauseBySession,
|
|
518
521
|
embedRunStateBySession,
|
|
@@ -541,7 +544,7 @@ import {
|
|
|
541
544
|
embedSessionCompartmentChunks2,
|
|
542
545
|
getEmbeddingCoverageStatus2,
|
|
543
546
|
getAutoEmbeddingSessionCoverage2
|
|
544
|
-
} from "./server-
|
|
547
|
+
} from "./server-8by8qfec.js";
|
|
545
548
|
import {
|
|
546
549
|
textMentionsRecentCommit,
|
|
547
550
|
hasMeaningfulUserText2,
|
|
@@ -552,7 +555,7 @@ import {
|
|
|
552
555
|
estimateTokens,
|
|
553
556
|
estimateFixedPromptTokens,
|
|
554
557
|
normalizeText
|
|
555
|
-
} from "./server-
|
|
558
|
+
} from "./server-tgnbmwah.js";
|
|
556
559
|
import {
|
|
557
560
|
SubcClient,
|
|
558
561
|
connectionFileExists,
|
|
@@ -560,7 +563,7 @@ import {
|
|
|
560
563
|
toSynapseLaneDescriptor,
|
|
561
564
|
formatSynapseLaneDescriptor,
|
|
562
565
|
SynapseEmbeddingProvider
|
|
563
|
-
} from "./server-
|
|
566
|
+
} from "./server-6tmj0s7j.js";
|
|
564
567
|
import {
|
|
565
568
|
inRootAsyncContext2,
|
|
566
569
|
getTagIdentityWriteGeneration2,
|
|
@@ -574,7 +577,7 @@ import {
|
|
|
574
577
|
isTransientSqliteError2,
|
|
575
578
|
SqliteAcquisitionBusyError2,
|
|
576
579
|
withAsyncPrivilegedWriter2
|
|
577
|
-
} from "./server-
|
|
580
|
+
} from "./server-beht37jy.js";
|
|
578
581
|
import"./server-51779zs2.js";
|
|
579
582
|
import {
|
|
580
583
|
isRawCompactionSummaryInfo2,
|
|
@@ -582,11 +585,11 @@ import {
|
|
|
582
585
|
buildInMemoryTailRawMessages2,
|
|
583
586
|
RawOrdinalsNotReady2,
|
|
584
587
|
runSessionWarmupWorker
|
|
585
|
-
} from "./server-
|
|
586
|
-
import"./server-
|
|
588
|
+
} from "./server-xj136kt8.js";
|
|
589
|
+
import"./server-1wy7b9de.js";
|
|
587
590
|
import {
|
|
588
591
|
deleteChunkEmbedBackoffForSession
|
|
589
|
-
} from "./server-
|
|
592
|
+
} from "./server-46neh5fa.js";
|
|
590
593
|
import {
|
|
591
594
|
registerOwnRpcServerInstance,
|
|
592
595
|
rpcPortDir,
|
|
@@ -605,14 +608,20 @@ import {
|
|
|
605
608
|
prepareLkgCaptureFence,
|
|
606
609
|
certifyCommittedLkgCapture,
|
|
607
610
|
markLkgRecoveryDirty,
|
|
611
|
+
cleanSearchText,
|
|
612
|
+
matchedSearchSnippet,
|
|
613
|
+
gaDatabasePath,
|
|
614
|
+
RAW_MESSAGE_TYPES,
|
|
615
|
+
V2StoreReaderPool,
|
|
616
|
+
V2StoreReader,
|
|
608
617
|
advanceSessionActivity,
|
|
609
618
|
backfillSessionActivity,
|
|
610
619
|
getLastIndexedOrdinal2,
|
|
611
620
|
getMessageIndexReconciliationStartOrdinal2,
|
|
612
621
|
isMessageIndexReconciledThrough2,
|
|
613
622
|
indexMessagesAfterOrdinal2,
|
|
614
|
-
|
|
615
|
-
} from "./server-
|
|
623
|
+
sweepOrphanedOpenCodeMessageIndexesCooperatively2
|
|
624
|
+
} from "./server-2ehj0bw7.js";
|
|
616
625
|
import {
|
|
617
626
|
stableStringify,
|
|
618
627
|
getTemporalDecisions,
|
|
@@ -671,12 +680,14 @@ import {
|
|
|
671
680
|
getPendingOpsCount,
|
|
672
681
|
clearPendingOps,
|
|
673
682
|
removePendingOp,
|
|
683
|
+
updateTagByteSize2,
|
|
674
684
|
getRecentTagOwnerMessageIds2,
|
|
675
685
|
AGE_RECLAIM_MIN_TOKENS2,
|
|
676
686
|
getOldestActiveUnprotectedToolTags2,
|
|
677
687
|
getActiveToolTagsForAgeReclaim2,
|
|
678
688
|
getTriggerTagTokenUpperBound2,
|
|
679
689
|
getActiveTagTokenTotalsByMessage2,
|
|
690
|
+
updateTagTokenCount2,
|
|
680
691
|
tryGetReasoningTokenEstimatesByMessage2,
|
|
681
692
|
cachedTagOwnerRatios2,
|
|
682
693
|
tagOwnerWarmupState2,
|
|
@@ -713,7 +724,7 @@ import {
|
|
|
713
724
|
adoptNullOwnerToolTag2,
|
|
714
725
|
getCandidateToolOwners2,
|
|
715
726
|
pickNearestPriorOwner2
|
|
716
|
-
} from "./server-
|
|
727
|
+
} from "./server-27gq4mfz.js";
|
|
717
728
|
import {
|
|
718
729
|
resolveOpenCodeDbPath,
|
|
719
730
|
assertOpenCodeStoreGeneration,
|
|
@@ -729,12 +740,12 @@ import {
|
|
|
729
740
|
latestRealUserTurnIdFromOpenCodeDb,
|
|
730
741
|
getMessageTimesFromOpenCodeDb,
|
|
731
742
|
findLastAssistantModelFromOpenCodeDb
|
|
732
|
-
} from "./server-
|
|
743
|
+
} from "./server-n1prf1g6.js";
|
|
733
744
|
import {
|
|
734
745
|
getCurrentToolSetHash,
|
|
735
746
|
recordToolDefinition,
|
|
736
747
|
getMeasuredToolDefinitionTokens
|
|
737
|
-
} from "./server-
|
|
748
|
+
} from "./server-g3qma5c0.js";
|
|
738
749
|
import {
|
|
739
750
|
V2_MEMORY_CATEGORIES,
|
|
740
751
|
CATEGORY_PRIORITY
|
|
@@ -747,7 +758,7 @@ import {
|
|
|
747
758
|
resolveStoredPathWorkspaceIdentity,
|
|
748
759
|
storedPathBelongsToWorkspace,
|
|
749
760
|
computeWorkspaceEpochFingerprint
|
|
750
|
-
} from "./server-
|
|
761
|
+
} from "./server-gpvay0xz.js";
|
|
751
762
|
import {
|
|
752
763
|
configureContextDatabasePragmas2
|
|
753
764
|
} from "./server-fb3zxn06.js";
|
|
@@ -793,7 +804,7 @@ import {
|
|
|
793
804
|
readGitFileChangeTimesSince,
|
|
794
805
|
verificationFileExists,
|
|
795
806
|
normalizeVerificationFiles
|
|
796
|
-
} from "./server-
|
|
807
|
+
} from "./server-my7k4eds.js";
|
|
797
808
|
import {
|
|
798
809
|
deriveTriggerBudget2,
|
|
799
810
|
deriveHistorianChunkTokens2,
|
|
@@ -801,7 +812,7 @@ import {
|
|
|
801
812
|
resolveHistorianProducerLimits2,
|
|
802
813
|
resolveHistorianContextLimit2
|
|
803
814
|
} from "./server-34kwfsr4.js";
|
|
804
|
-
import"./server-
|
|
815
|
+
import"./server-d04vrx0j.js";
|
|
805
816
|
import {
|
|
806
817
|
isEmbeddingHostBusy2
|
|
807
818
|
} from "./server-qt1qqasc.js";
|
|
@@ -814,7 +825,7 @@ import {
|
|
|
814
825
|
releaseGitSweepLease,
|
|
815
826
|
recordSessionProjectIdentity,
|
|
816
827
|
hasRecordedSessionProjectIdentity
|
|
817
|
-
} from "./server-
|
|
828
|
+
} from "./server-hy3d3vsx.js";
|
|
818
829
|
import {
|
|
819
830
|
saveEmbeddingIfHashMatches,
|
|
820
831
|
invalidateProject2,
|
|
@@ -822,10 +833,10 @@ import {
|
|
|
822
833
|
} from "./server-4dhv7mqz.js";
|
|
823
834
|
import {
|
|
824
835
|
getLocalEmbeddingNativeMemoryStats
|
|
825
|
-
} from "./server-
|
|
836
|
+
} from "./server-h1v0pyxb.js";
|
|
826
837
|
import {
|
|
827
838
|
cosineSimilarity
|
|
828
|
-
} from "./server-
|
|
839
|
+
} from "./server-zzkj2fch.js";
|
|
829
840
|
import {
|
|
830
841
|
computeCueContentHash,
|
|
831
842
|
hasMuralCueColumns,
|
|
@@ -850,7 +861,7 @@ import {
|
|
|
850
861
|
mergeMemoryStats2,
|
|
851
862
|
archiveMemory2,
|
|
852
863
|
getMemoryCountsByStatus2
|
|
853
|
-
} from "./server-
|
|
864
|
+
} from "./server-n37sebck.js";
|
|
854
865
|
import {
|
|
855
866
|
registerNotificationSink2,
|
|
856
867
|
pushNotification2,
|
|
@@ -862,7 +873,7 @@ import"./server-h0410h0v.js";
|
|
|
862
873
|
import {
|
|
863
874
|
flushIgnoredMessages2,
|
|
864
875
|
sendStatusNotification2
|
|
865
|
-
} from "./server-
|
|
876
|
+
} from "./server-a9xqj88f.js";
|
|
866
877
|
import {
|
|
867
878
|
renderSingleStoreMigrationRequiredRefusal,
|
|
868
879
|
SingleStoreMigrationRequiredError,
|
|
@@ -882,14 +893,14 @@ import {
|
|
|
882
893
|
resolveMemoriesByIdsForSearch2,
|
|
883
894
|
unifiedSearch2,
|
|
884
895
|
formatSearchResults2
|
|
885
|
-
} from "./server-
|
|
896
|
+
} from "./server-1nyybqan.js";
|
|
886
897
|
import {
|
|
887
898
|
resolvePromptContext2
|
|
888
899
|
} from "./server-fmsr7v69.js";
|
|
889
900
|
import"./server-kaqs6h31.js";
|
|
890
901
|
import {
|
|
891
902
|
renderSearchArchiveOffThread2
|
|
892
|
-
} from "./server-
|
|
903
|
+
} from "./server-qv7f0hhe.js";
|
|
893
904
|
import {
|
|
894
905
|
compareSemverCore
|
|
895
906
|
} from "./server-84w6rvvf.js";
|
|
@@ -1636,6 +1647,9 @@ __export(exports_coerce, {
|
|
|
1636
1647
|
string: () => string3
|
|
1637
1648
|
});
|
|
1638
1649
|
|
|
1650
|
+
// src/v2/hooks/context.ts
|
|
1651
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
1652
|
+
|
|
1639
1653
|
// src/config/dependency-notes.ts
|
|
1640
1654
|
function scheduledTasks(config) {
|
|
1641
1655
|
const tasks = config.dreamer?.tasks ?? {};
|
|
@@ -3423,9 +3437,14 @@ function scheduleReconciliation(db, sessionId, readMessages) {
|
|
|
3423
3437
|
});
|
|
3424
3438
|
}
|
|
3425
3439
|
async function sweepOrphanedOpenCodeMessageIndexesOffThread(db, openSource, options = {}) {
|
|
3440
|
+
if (getHarness2() === "opencode2")
|
|
3441
|
+
openSource = () => new Database2(gaDatabasePath(getDataDir(), process.env.OPENCODE_CHANNEL ?? "latest"), {
|
|
3442
|
+
readonly: true,
|
|
3443
|
+
fileMustExist: true
|
|
3444
|
+
});
|
|
3426
3445
|
const path = getSqliteDatabasePath2(db);
|
|
3427
|
-
if (!path || getHarness2() !== "opencode")
|
|
3428
|
-
return
|
|
3446
|
+
if (!path || getHarness2() !== "opencode" && getHarness2() !== "opencode2")
|
|
3447
|
+
return sweepOrphanedOpenCodeMessageIndexesCooperatively2(db, openSource, options);
|
|
3429
3448
|
let source = null;
|
|
3430
3449
|
let sourcePath = null;
|
|
3431
3450
|
try {
|
|
@@ -3437,7 +3456,7 @@ async function sweepOrphanedOpenCodeMessageIndexesOffThread(db, openSource, opti
|
|
|
3437
3456
|
source?.close();
|
|
3438
3457
|
}
|
|
3439
3458
|
if (!sourcePath)
|
|
3440
|
-
return
|
|
3459
|
+
return sweepOrphanedOpenCodeMessageIndexesCooperatively2(db, () => source, options);
|
|
3441
3460
|
const reply = await runSessionWarmupWorker({
|
|
3442
3461
|
path,
|
|
3443
3462
|
sessionId: "",
|
|
@@ -3512,7 +3531,8 @@ function seedSessionCacheTtlIfUnsynced(args) {
|
|
|
3512
3531
|
}
|
|
3513
3532
|
|
|
3514
3533
|
// src/hooks/magic-context/auto-search-deadline.ts
|
|
3515
|
-
var AUTO_SEARCH_TIMEOUT_MS =
|
|
3534
|
+
var AUTO_SEARCH_TIMEOUT_MS = 1000;
|
|
3535
|
+
var AUTO_SEARCH_VECTOR_TIMEOUT_MS = 200;
|
|
3516
3536
|
var operationDeadlines = new WeakMap;
|
|
3517
3537
|
function autoSearchDeadlineUnixMs(signal) {
|
|
3518
3538
|
const deadline = signal && operationDeadlines.get(signal);
|
|
@@ -4061,32 +4081,32 @@ function formatAge(committedAtMs) {
|
|
|
4061
4081
|
const years = Math.floor(days / 365);
|
|
4062
4082
|
return years === 1 ? "1y ago" : `${years}y ago`;
|
|
4063
4083
|
}
|
|
4064
|
-
function renderFragment(result, charCap, wordRules) {
|
|
4084
|
+
function renderFragment(result, charCap, wordRules, query) {
|
|
4065
4085
|
switch (result.source) {
|
|
4066
4086
|
case "memory": {
|
|
4067
|
-
const compressed = cavemanCompress(result.content, "ultra", CURRENT_CAVEMAN_RULES, wordRules);
|
|
4087
|
+
const compressed = cavemanCompress(cleanSearchText(result.content), "ultra", CURRENT_CAVEMAN_RULES, wordRules);
|
|
4068
4088
|
return truncate(compressed, charCap);
|
|
4069
4089
|
}
|
|
4070
4090
|
case "git_commit": {
|
|
4071
|
-
const subject = result.content.split(/\r?\n/)[0] ?? result.content;
|
|
4091
|
+
const subject = cleanSearchText(result.content.split(/\r?\n/)[0] ?? result.content);
|
|
4072
4092
|
const body = truncate(subject, Math.max(10, charCap - 20));
|
|
4073
4093
|
return `commit ${result.shortSha} ${formatAge(result.committedAtMs)}: ${body}`;
|
|
4074
4094
|
}
|
|
4075
4095
|
case "message": {
|
|
4076
|
-
const compressed = cavemanCompress(result.content, "ultra", CURRENT_CAVEMAN_RULES, wordRules);
|
|
4096
|
+
const compressed = cavemanCompress(query ? matchedSearchSnippet(result.content, query, charCap) : cleanSearchText(result.content), "ultra", CURRENT_CAVEMAN_RULES, wordRules);
|
|
4077
4097
|
return truncate(compressed, charCap);
|
|
4078
4098
|
}
|
|
4079
4099
|
case "compartment": {
|
|
4080
|
-
const source = result.
|
|
4100
|
+
const source = cleanSearchText(result.title);
|
|
4081
4101
|
const compressed = cavemanCompress(source, "ultra", CURRENT_CAVEMAN_RULES, wordRules);
|
|
4082
4102
|
return truncate(compressed, charCap);
|
|
4083
4103
|
}
|
|
4084
4104
|
case "primer": {
|
|
4085
|
-
const compressed = cavemanCompress(result.content, "ultra", CURRENT_CAVEMAN_RULES, wordRules);
|
|
4105
|
+
const compressed = cavemanCompress(cleanSearchText(result.content), "ultra", CURRENT_CAVEMAN_RULES, wordRules);
|
|
4086
4106
|
return truncate(compressed, charCap);
|
|
4087
4107
|
}
|
|
4088
4108
|
case "note": {
|
|
4089
|
-
const compressed = cavemanCompress(result.content, "ultra", CURRENT_CAVEMAN_RULES, wordRules);
|
|
4109
|
+
const compressed = cavemanCompress(cleanSearchText(result.content), "ultra", CURRENT_CAVEMAN_RULES, wordRules);
|
|
4090
4110
|
return truncate(compressed, charCap);
|
|
4091
4111
|
}
|
|
4092
4112
|
}
|
|
@@ -4097,7 +4117,7 @@ function buildAutoSearchHint(results, options = {}) {
|
|
|
4097
4117
|
const picks = results.slice(0, maxFragments);
|
|
4098
4118
|
const lines = [];
|
|
4099
4119
|
for (const result of picks) {
|
|
4100
|
-
const fragment = renderFragment(result, fragmentCharCap, options.wordRules ?? "english");
|
|
4120
|
+
const fragment = renderFragment(result, fragmentCharCap, options.wordRules ?? "english", options.query ?? "");
|
|
4101
4121
|
if (fragment.length === 0)
|
|
4102
4122
|
continue;
|
|
4103
4123
|
lines.push(`- ${fragment}`);
|
|
@@ -4120,6 +4140,9 @@ ${trimmedBody}…
|
|
|
4120
4140
|
}
|
|
4121
4141
|
return wrapped;
|
|
4122
4142
|
}
|
|
4143
|
+
function selectAutoSearchResults(results, threshold) {
|
|
4144
|
+
return results.filter((result) => (result.relevanceScore ?? result.score) >= threshold);
|
|
4145
|
+
}
|
|
4123
4146
|
|
|
4124
4147
|
// src/hooks/magic-context/auto-search-worker-client.ts
|
|
4125
4148
|
import { Worker } from "node:worker_threads";
|
|
@@ -4215,6 +4238,63 @@ async function searchAutoHint(db, sessionId, projectPath, query, options, entry
|
|
|
4215
4238
|
return executeAutoSearchWorker(db, sessionId, projectPath, query, options, entry, "search");
|
|
4216
4239
|
}
|
|
4217
4240
|
var pendingBackfills = new WeakMap;
|
|
4241
|
+
var searchWorkers = new WeakMap;
|
|
4242
|
+
var liveSearchWorkers = new Set;
|
|
4243
|
+
var MAX_IDLE_SEARCH_WORKERS = 4;
|
|
4244
|
+
var SEARCH_WORKER_IDLE_MS = 5 * 60000;
|
|
4245
|
+
var workersCreated = 0;
|
|
4246
|
+
var workersReused = 0;
|
|
4247
|
+
async function acquireSearchWorker(db, key, entry, input, signal) {
|
|
4248
|
+
const pool = searchWorkers.get(db) ?? new Map;
|
|
4249
|
+
searchWorkers.set(db, pool);
|
|
4250
|
+
while (!signal.aborted) {
|
|
4251
|
+
let slot = pool.get(key);
|
|
4252
|
+
if (slot?.busy) {
|
|
4253
|
+
const current = slot;
|
|
4254
|
+
await new Promise((resolve) => {
|
|
4255
|
+
const done = () => {
|
|
4256
|
+
signal.removeEventListener("abort", done);
|
|
4257
|
+
resolve();
|
|
4258
|
+
};
|
|
4259
|
+
signal.addEventListener("abort", done, { once: true });
|
|
4260
|
+
current.busy?.then(done);
|
|
4261
|
+
if (signal.aborted)
|
|
4262
|
+
done();
|
|
4263
|
+
});
|
|
4264
|
+
continue;
|
|
4265
|
+
}
|
|
4266
|
+
const fresh = !slot;
|
|
4267
|
+
if (!slot) {
|
|
4268
|
+
const worker = inRootAsyncContext2(() => new Worker(entry, { workerData: { ...input, persistent: true } }));
|
|
4269
|
+
slot = {
|
|
4270
|
+
worker,
|
|
4271
|
+
dispose() {
|
|
4272
|
+
clearTimeout(this.idleTimer);
|
|
4273
|
+
if (pool.get(key) === this)
|
|
4274
|
+
pool.delete(key);
|
|
4275
|
+
liveSearchWorkers.delete(this);
|
|
4276
|
+
worker.terminate();
|
|
4277
|
+
worker.unref();
|
|
4278
|
+
}
|
|
4279
|
+
};
|
|
4280
|
+
workersCreated++;
|
|
4281
|
+
pool.set(key, slot);
|
|
4282
|
+
liveSearchWorkers.add(slot);
|
|
4283
|
+
const current = slot;
|
|
4284
|
+
worker.on("error", () => current.dispose());
|
|
4285
|
+
worker.on("exit", () => current.dispose());
|
|
4286
|
+
} else
|
|
4287
|
+
workersReused++;
|
|
4288
|
+
clearTimeout(slot.idleTimer);
|
|
4289
|
+
const current = slot;
|
|
4290
|
+
current.busy = new Promise((resolve) => {
|
|
4291
|
+
current.release = resolve;
|
|
4292
|
+
});
|
|
4293
|
+
current.worker.ref();
|
|
4294
|
+
return { slot: current, fresh };
|
|
4295
|
+
}
|
|
4296
|
+
return null;
|
|
4297
|
+
}
|
|
4218
4298
|
function queueAutoSearchBackfill(db, sessionId, projectPath, query) {
|
|
4219
4299
|
if (isEmbeddingHostBusy2())
|
|
4220
4300
|
return Promise.resolve();
|
|
@@ -4279,6 +4359,7 @@ async function executeAutoSearchWorker(db, sessionId, projectPath, query, option
|
|
|
4279
4359
|
query,
|
|
4280
4360
|
options: {
|
|
4281
4361
|
...serializable,
|
|
4362
|
+
autoHint: true,
|
|
4282
4363
|
backfillMemoryEmbeddings: false,
|
|
4283
4364
|
countRetrievals: false,
|
|
4284
4365
|
measurementDisabled: true
|
|
@@ -4288,8 +4369,20 @@ async function executeAutoSearchWorker(db, sessionId, projectPath, query, option
|
|
|
4288
4369
|
snapshot,
|
|
4289
4370
|
deadlineUnixMs: autoSearchDeadlineUnixMs(deadlineSignal)
|
|
4290
4371
|
};
|
|
4372
|
+
let lease;
|
|
4373
|
+
try {
|
|
4374
|
+
lease = await acquireSearchWorker(db, `${input.harness}\x00${projectPath}\x00${job}\x00${entry.href}`, entry, input, signal);
|
|
4375
|
+
} catch (error) {
|
|
4376
|
+
lifecycle.done();
|
|
4377
|
+
throw error;
|
|
4378
|
+
}
|
|
4379
|
+
if (!lease) {
|
|
4380
|
+
lifecycle.done();
|
|
4381
|
+
return [];
|
|
4382
|
+
}
|
|
4383
|
+
const { slot, fresh } = lease;
|
|
4384
|
+
const worker = slot.worker;
|
|
4291
4385
|
return new Promise((resolve, reject) => {
|
|
4292
|
-
const worker = inRootAsyncContext2(() => new Worker(entry, { workerData: input }));
|
|
4293
4386
|
let settled = false;
|
|
4294
4387
|
const finish = (results, error) => {
|
|
4295
4388
|
if (settled)
|
|
@@ -4298,7 +4391,25 @@ async function executeAutoSearchWorker(db, sessionId, projectPath, query, option
|
|
|
4298
4391
|
signal?.removeEventListener("abort", abort);
|
|
4299
4392
|
lifecycle.signal.removeEventListener("abort", abort);
|
|
4300
4393
|
lifecycle.done();
|
|
4301
|
-
worker.
|
|
4394
|
+
worker.off("message", onMessage);
|
|
4395
|
+
worker.off("error", onError);
|
|
4396
|
+
worker.off("exit", onExit);
|
|
4397
|
+
if (error || signal.aborted || entry.href !== defaultAutoSearchWorkerEntry().href)
|
|
4398
|
+
slot.dispose();
|
|
4399
|
+
else {
|
|
4400
|
+
slot.idleTimer = setTimeout(() => slot.dispose(), SEARCH_WORKER_IDLE_MS);
|
|
4401
|
+
slot.idleTimer.unref?.();
|
|
4402
|
+
}
|
|
4403
|
+
const release = slot.release;
|
|
4404
|
+
slot.busy = undefined;
|
|
4405
|
+
slot.release = undefined;
|
|
4406
|
+
release?.();
|
|
4407
|
+
const reusable = liveSearchWorkers.delete(slot);
|
|
4408
|
+
if (reusable)
|
|
4409
|
+
liveSearchWorkers.add(slot);
|
|
4410
|
+
const idle = [...liveSearchWorkers].filter((candidate) => !candidate.busy);
|
|
4411
|
+
for (const prior of idle.slice(0, Math.max(0, idle.length - MAX_IDLE_SEARCH_WORKERS)))
|
|
4412
|
+
prior.dispose();
|
|
4302
4413
|
worker.unref();
|
|
4303
4414
|
if (error)
|
|
4304
4415
|
reject(error);
|
|
@@ -4308,9 +4419,9 @@ async function executeAutoSearchWorker(db, sessionId, projectPath, query, option
|
|
|
4308
4419
|
const abort = () => finish([]);
|
|
4309
4420
|
signal?.addEventListener("abort", abort, { once: true });
|
|
4310
4421
|
lifecycle.signal.addEventListener("abort", abort, { once: true });
|
|
4311
|
-
|
|
4312
|
-
|
|
4313
|
-
|
|
4422
|
+
const onError = (error) => finish([], error);
|
|
4423
|
+
const onExit = (code) => finish([], new Error(`auto-search worker exited (${code})`));
|
|
4424
|
+
const onMessage = async (reply) => {
|
|
4314
4425
|
if (settled)
|
|
4315
4426
|
return;
|
|
4316
4427
|
if (reply.kind === "result") {
|
|
@@ -4329,7 +4440,7 @@ async function executeAutoSearchWorker(db, sessionId, projectPath, query, option
|
|
|
4329
4440
|
const response = { id: reply.id };
|
|
4330
4441
|
try {
|
|
4331
4442
|
if (reply.kind === "query")
|
|
4332
|
-
response.result = await (job === "backfill" ? embedTextForProject2(projectPath, reply.text, signal, "query") : embedQuery
|
|
4443
|
+
response.result = await (job === "backfill" ? embedTextForProject2(projectPath, reply.text, signal, "query") : boundedHintEmbedding(embedQuery, reply.text, signal)) ?? null;
|
|
4333
4444
|
else {
|
|
4334
4445
|
const passage = await embedBatchForProject2(projectPath, reply.texts, signal, reply.purpose);
|
|
4335
4446
|
const current = getProjectEmbeddingSnapshot2(projectPath);
|
|
@@ -4344,13 +4455,46 @@ async function executeAutoSearchWorker(db, sessionId, projectPath, query, option
|
|
|
4344
4455
|
response.error = error instanceof Error ? error.message : String(error);
|
|
4345
4456
|
}
|
|
4346
4457
|
response.embeddingHostBusy = isEmbeddingHostBusy2();
|
|
4347
|
-
if (!settled && !signal?.aborted)
|
|
4348
|
-
|
|
4349
|
-
|
|
4458
|
+
if (!settled && !signal?.aborted) {
|
|
4459
|
+
try {
|
|
4460
|
+
worker.postMessage(response);
|
|
4461
|
+
} catch (error) {
|
|
4462
|
+
finish([], error instanceof Error ? error : new Error(String(error)));
|
|
4463
|
+
}
|
|
4464
|
+
}
|
|
4465
|
+
};
|
|
4466
|
+
worker.on("error", onError);
|
|
4467
|
+
worker.on("exit", onExit);
|
|
4468
|
+
worker.on("message", onMessage);
|
|
4350
4469
|
if (signal?.aborted)
|
|
4351
4470
|
abort();
|
|
4471
|
+
else if (!fresh) {
|
|
4472
|
+
try {
|
|
4473
|
+
worker.postMessage({ kind: "run", input });
|
|
4474
|
+
} catch (error) {
|
|
4475
|
+
finish([], error instanceof Error ? error : new Error(String(error)));
|
|
4476
|
+
}
|
|
4477
|
+
}
|
|
4352
4478
|
});
|
|
4353
4479
|
}
|
|
4480
|
+
async function boundedHintEmbedding(embed, text, signal) {
|
|
4481
|
+
const controller = new AbortController;
|
|
4482
|
+
const combined = AbortSignal.any([signal, controller.signal]);
|
|
4483
|
+
let timer;
|
|
4484
|
+
try {
|
|
4485
|
+
return await Promise.race([
|
|
4486
|
+
Promise.resolve().then(() => embed?.(text, combined) ?? null),
|
|
4487
|
+
new Promise((resolve) => {
|
|
4488
|
+
timer = setTimeout(() => {
|
|
4489
|
+
resolve(null);
|
|
4490
|
+
controller.abort();
|
|
4491
|
+
}, AUTO_SEARCH_VECTOR_TIMEOUT_MS);
|
|
4492
|
+
})
|
|
4493
|
+
]);
|
|
4494
|
+
} finally {
|
|
4495
|
+
clearTimeout(timer);
|
|
4496
|
+
}
|
|
4497
|
+
}
|
|
4354
4498
|
function defaultAutoSearchWorkerEntry() {
|
|
4355
4499
|
return new URL(new URL(import.meta.url).pathname.endsWith(".ts") ? "./auto-search-worker.ts" : "./auto-search-worker.js", import.meta.url);
|
|
4356
4500
|
}
|
|
@@ -4658,6 +4802,8 @@ async function runAutoSearchHint(args) {
|
|
|
4658
4802
|
const gitCommitsEnabled = embeddingSnapshot?.gitCommitEnabled ?? options.gitCommitsEnabled ?? false;
|
|
4659
4803
|
const searchOptions = {
|
|
4660
4804
|
limit: 10,
|
|
4805
|
+
maxMessageOrdinal: Math.max(0, getLastCompartmentEndMessage(db, sessionId)),
|
|
4806
|
+
excludeMessageId: userMsgId,
|
|
4661
4807
|
memoryEnabled,
|
|
4662
4808
|
embeddingEnabled,
|
|
4663
4809
|
gitCommitsEnabled,
|
|
@@ -4695,11 +4841,15 @@ async function runAutoSearchHint(args) {
|
|
|
4695
4841
|
if (results.length === 0) {
|
|
4696
4842
|
return writeNoHintAndReconcile("empty");
|
|
4697
4843
|
}
|
|
4698
|
-
|
|
4699
|
-
|
|
4844
|
+
results = selectAutoSearchResults(results, options.scoreThreshold);
|
|
4845
|
+
if (results.length === 0) {
|
|
4846
|
+
sessionLog2(sessionId, `auto-search: no fragment meets relevance threshold ${options.scoreThreshold}`);
|
|
4700
4847
|
return writeNoHintAndReconcile("below-threshold");
|
|
4701
4848
|
}
|
|
4702
|
-
const hintText = buildAutoSearchHint(results, {
|
|
4849
|
+
const hintText = buildAutoSearchHint(results, {
|
|
4850
|
+
wordRules: options.wordRules,
|
|
4851
|
+
query: rawPrompt
|
|
4852
|
+
});
|
|
4703
4853
|
if (!hintText) {
|
|
4704
4854
|
return writeNoHintAndReconcile("empty");
|
|
4705
4855
|
}
|
|
@@ -5659,6 +5809,12 @@ function canConsumeDeferredOnThisPass(args) {
|
|
|
5659
5809
|
function hasReclaimRide(signals) {
|
|
5660
5810
|
return signals.hardFold || signals.force || signals.explicitFlush || signals.publishedHistory || signals.subagentExecute === true;
|
|
5661
5811
|
}
|
|
5812
|
+
function prefixMutationPermitted(gate) {
|
|
5813
|
+
return !gate.signedThinkingHold || gate.firstRender || gate.idleExpiry || gate.emergency;
|
|
5814
|
+
}
|
|
5815
|
+
function reclaimRidePermitted(signals, gate) {
|
|
5816
|
+
return prefixMutationPermitted(gate) && hasReclaimRide(signals);
|
|
5817
|
+
}
|
|
5662
5818
|
var RECLAIM_RIDE_NAMES = [
|
|
5663
5819
|
"hardFold",
|
|
5664
5820
|
"force",
|
|
@@ -5954,8 +6110,9 @@ function checkCompartmentTrigger(db, sessionId, sessionMeta, usage, _previousPer
|
|
|
5954
6110
|
const canClearReasoning = reasoningProjection?.canClearReasoning ?? modelAcceptsEmptyContent(reasoningProjection?.providerID);
|
|
5955
6111
|
const projectedPostDropPercentage = estimateProjectedPostDropPercentage(db, sessionId, usage, preloadedActiveTags ?? getActiveTagsBySession2(db, sessionId), keepReasoningTokens, sessionMeta.clearedReasoningThroughTag, canClearReasoning, reasoningProjection?.budgetCutoff, eligiblePendingDropTagIds);
|
|
5956
6112
|
const relativePostDropTarget = executeThresholdPercentage * POST_DROP_TARGET_RATIO;
|
|
6113
|
+
const ridePermitted = reclaimRide !== undefined && (reclaimRide.permission ? reclaimRidePermitted(reclaimRide, reclaimRide.permission) : hasReclaimRide(reclaimRide));
|
|
5957
6114
|
const rideLabel = reclaimRide ? reclaimRideLabel(reclaimRide) : "ride=none";
|
|
5958
|
-
const dropsCanLand =
|
|
6115
|
+
const dropsCanLand = ridePermitted;
|
|
5959
6116
|
const forceMaterializationPercentage = escalationBands(executeThresholdPercentage).forceMaterializationPercentage;
|
|
5960
6117
|
if (usage.percentage >= forceMaterializationPercentage) {
|
|
5961
6118
|
if (dropsCanLand && projectedPostDropPercentage !== null && projectedPostDropPercentage <= relativePostDropTarget) {
|
|
@@ -6878,6 +7035,27 @@ function resolveHistoryBudgetTokens(historyBudgetPercentage, contextUsage, execu
|
|
|
6878
7035
|
}) / 100) * historyBudgetPercentage);
|
|
6879
7036
|
}
|
|
6880
7037
|
|
|
7038
|
+
// src/features/magic-context/storage-host-instruction-retention.ts
|
|
7039
|
+
var NAMESPACE = "hostInstructionRetention";
|
|
7040
|
+
var enabled = true;
|
|
7041
|
+
function hostInstructionRetentionEnabled() {
|
|
7042
|
+
return enabled;
|
|
7043
|
+
}
|
|
7044
|
+
function isHostInstructionRetentionOn(db, sessionId) {
|
|
7045
|
+
const lane = readReplayEnvelope(db, sessionId)[NAMESPACE];
|
|
7046
|
+
return typeof lane === "object" && lane !== null && lane.on === true;
|
|
7047
|
+
}
|
|
7048
|
+
function markHostInstructionRetention(db, sessionId) {
|
|
7049
|
+
return updateReplayDocument(db, sessionId, (doc) => {
|
|
7050
|
+
const lane = doc[NAMESPACE];
|
|
7051
|
+
if (typeof lane === "object" && lane !== null && lane.on === true)
|
|
7052
|
+
return false;
|
|
7053
|
+
doc.version = 2;
|
|
7054
|
+
doc[NAMESPACE] = { on: true };
|
|
7055
|
+
return true;
|
|
7056
|
+
});
|
|
7057
|
+
}
|
|
7058
|
+
|
|
6881
7059
|
// src/hooks/magic-context/pending-drop-eligibility.ts
|
|
6882
7060
|
function pendingDropVeto(tagNumber, target, protectedTagIds) {
|
|
6883
7061
|
if (protectedTagIds.has(tagNumber))
|
|
@@ -6954,27 +7132,43 @@ function buildReplacementContent(tagId) {
|
|
|
6954
7132
|
return `[dropped §${tagId}§]`;
|
|
6955
7133
|
}
|
|
6956
7134
|
function applyNewToolDrop(target, options) {
|
|
6957
|
-
|
|
7135
|
+
const plan = planNewToolDrop(target, options, !!options.persist);
|
|
7136
|
+
if (!plan)
|
|
6958
7137
|
return { result: "incomplete", mode: "full" };
|
|
7138
|
+
options.persist?.(plan.mode);
|
|
7139
|
+
return plan.apply();
|
|
7140
|
+
}
|
|
7141
|
+
function planNewToolDrop(target, options, prepare, plannedRemovals) {
|
|
7142
|
+
if (prepare && (target?.prepareDrop?.() ?? target?.canDrop?.()) === false) {
|
|
7143
|
+
return;
|
|
6959
7144
|
}
|
|
6960
7145
|
if (!target) {
|
|
6961
|
-
|
|
6962
|
-
return { result: "absent", mode: "full" };
|
|
7146
|
+
return { mode: "full", apply: () => ({ result: "absent", mode: "full" }) };
|
|
6963
7147
|
}
|
|
6964
|
-
if (options.inWindow && hasSmallToolInput(target) || options.keepSkeleton === true || target.cannotRemove?.() === true || target.wouldStrandConversationEnd?.() === true) {
|
|
7148
|
+
if (options.inWindow && hasSmallToolInput(target) || options.keepSkeleton === true || target.cannotRemove?.() === true || target.wouldStrandConversationEnd?.(plannedRemovals) === true) {
|
|
6965
7149
|
const strip = target.hasAttachments?.() === true;
|
|
6966
|
-
|
|
7150
|
+
const mode = strip ? "skeleton_stripped" : "skeleton_real";
|
|
6967
7151
|
return {
|
|
6968
|
-
|
|
6969
|
-
|
|
7152
|
+
mode,
|
|
7153
|
+
apply: () => ({
|
|
7154
|
+
result: (strip ? target.skeletonStripped?.() : target.skeletonReal?.()) ?? "absent",
|
|
7155
|
+
mode
|
|
7156
|
+
})
|
|
6970
7157
|
};
|
|
6971
7158
|
}
|
|
6972
|
-
|
|
6973
|
-
|
|
6974
|
-
|
|
6975
|
-
|
|
6976
|
-
|
|
6977
|
-
|
|
7159
|
+
return {
|
|
7160
|
+
mode: "full",
|
|
7161
|
+
apply: () => {
|
|
7162
|
+
const result = target.drop?.() ?? "absent";
|
|
7163
|
+
if (result === "truncated" && target.hasAttachments?.() === true) {
|
|
7164
|
+
return {
|
|
7165
|
+
result: target.skeletonStripped?.() ?? "absent",
|
|
7166
|
+
mode: "skeleton_stripped"
|
|
7167
|
+
};
|
|
7168
|
+
}
|
|
7169
|
+
return { result, mode: result === "truncated" ? "skeleton_real" : "full" };
|
|
7170
|
+
}
|
|
7171
|
+
};
|
|
6978
7172
|
}
|
|
6979
7173
|
function applyPersistedToolDrop(db, sessionId, tagNumber, target, options, afterWrite) {
|
|
6980
7174
|
return applyNewToolDrop(target, {
|
|
@@ -7068,6 +7262,7 @@ function renderConvertedToolSkeletons(targets, converted) {
|
|
|
7068
7262
|
}
|
|
7069
7263
|
return didMutate;
|
|
7070
7264
|
}
|
|
7265
|
+
var PENDING_OPERATION_CHUNK_SIZE = 64;
|
|
7071
7266
|
function applyPendingOperations(sessionId, db, targets, protectedTagIds, preloadedTags, preloadedPendingOps, syntheticPendingOps = [], editMarkerTagIds = new Set, onTagReduced, onBatchComplete, onEligibilitySnapshot) {
|
|
7072
7267
|
let didMutateMessage = false;
|
|
7073
7268
|
let diagnostics;
|
|
@@ -7077,153 +7272,184 @@ function applyPendingOperations(sessionId, db, targets, protectedTagIds, preload
|
|
|
7077
7272
|
diagnostics.reasons[reason] = (diagnostics.reasons[reason] ?? 0) + 1;
|
|
7078
7273
|
};
|
|
7079
7274
|
let admitted = false;
|
|
7080
|
-
|
|
7081
|
-
|
|
7082
|
-
|
|
7083
|
-
|
|
7084
|
-
|
|
7085
|
-
|
|
7086
|
-
|
|
7087
|
-
|
|
7088
|
-
|
|
7089
|
-
|
|
7090
|
-
|
|
7091
|
-
|
|
7092
|
-
|
|
7093
|
-
|
|
7094
|
-
const tagStatusById = new Map(tags.map((tag) => [tag.tagNumber, tag.status]));
|
|
7095
|
-
const tagTypeById = new Map(tags.map((tag) => [tag.tagNumber, tag.type]));
|
|
7096
|
-
const opsToApply = [
|
|
7097
|
-
...pendingOps.map((op) => ({ op, synthetic: false })),
|
|
7098
|
-
...syntheticPendingOps.map((op) => ({ op, synthetic: true }))
|
|
7099
|
-
];
|
|
7100
|
-
diagnostics = {
|
|
7101
|
-
source: pendingOps.length > 0 && syntheticPendingOps.length > 0 ? "mixed" : syntheticPendingOps.length > 0 ? "synthetic" : "pending",
|
|
7102
|
-
total: opsToApply.length,
|
|
7103
|
-
mutated: 0,
|
|
7104
|
-
persistedWithoutMutation: 0,
|
|
7105
|
-
reasons: {}
|
|
7106
|
-
};
|
|
7107
|
-
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));
|
|
7108
|
-
for (const { op: pendingOp, synthetic } of opsToApply) {
|
|
7109
|
-
let operationMutated = false;
|
|
7110
|
-
const tagStatus = tagStatusById.get(pendingOp.tagId);
|
|
7111
|
-
if (tagStatus === "compacted" || tagStatus === "dropped") {
|
|
7112
|
-
reject("already_reduced");
|
|
7113
|
-
if (!synthetic)
|
|
7114
|
-
removePendingOp(db, sessionId, pendingOp.tagId);
|
|
7115
|
-
continue;
|
|
7116
|
-
}
|
|
7117
|
-
const target = targets.get(pendingOp.tagId);
|
|
7118
|
-
const veto = pendingDropVeto(pendingOp.tagId, target, protectedTagIds);
|
|
7119
|
-
if (veto) {
|
|
7120
|
-
reject(veto);
|
|
7121
|
-
continue;
|
|
7122
|
-
}
|
|
7123
|
-
const isToolTag = tagTypeById.get(pendingOp.tagId) === "tool";
|
|
7124
|
-
if (synthetic) {
|
|
7125
|
-
if (!isToolTag) {
|
|
7126
|
-
reject("synthetic_non_tool");
|
|
7127
|
-
continue;
|
|
7128
|
-
}
|
|
7129
|
-
if (target?.canDrop?.() !== true) {
|
|
7130
|
-
reject("synthetic_target_not_droppable");
|
|
7131
|
-
continue;
|
|
7132
|
-
}
|
|
7275
|
+
let startedAt = 0;
|
|
7276
|
+
const mutations = [];
|
|
7277
|
+
let drainChunk;
|
|
7278
|
+
let hasMore = false;
|
|
7279
|
+
do {
|
|
7280
|
+
admitted = false;
|
|
7281
|
+
startedAt = 0;
|
|
7282
|
+
try {
|
|
7283
|
+
db.transaction(() => {
|
|
7284
|
+
admitted = true;
|
|
7285
|
+
startedAt = performance.now();
|
|
7286
|
+
if (drainChunk) {
|
|
7287
|
+
drainChunk();
|
|
7288
|
+
return;
|
|
7133
7289
|
}
|
|
7134
|
-
const
|
|
7135
|
-
|
|
7136
|
-
|
|
7137
|
-
|
|
7138
|
-
|
|
7139
|
-
|
|
7290
|
+
const pendingOps = preloadedPendingOps ?? getPendingOps(db, sessionId);
|
|
7291
|
+
onEligibilitySnapshot?.(capturePendingDropEligibility(targets, protectedTagIds));
|
|
7292
|
+
const tags = preloadedTags ?? getTagsByNumbers2(db, sessionId, [
|
|
7293
|
+
...new Set([
|
|
7294
|
+
...pendingOps.map((op) => op.tagId),
|
|
7295
|
+
...syntheticPendingOps.map((op) => op.tagId)
|
|
7296
|
+
])
|
|
7297
|
+
]);
|
|
7298
|
+
const tagById = new Map(tags.map((tag) => [tag.tagNumber, tag]));
|
|
7299
|
+
const tagStatusById = new Map(tags.map((tag) => [tag.tagNumber, tag.status]));
|
|
7300
|
+
const tagTypeById = new Map(tags.map((tag) => [tag.tagNumber, tag.type]));
|
|
7301
|
+
const opsToApply = [
|
|
7302
|
+
...pendingOps.map((op) => ({ op, synthetic: false })),
|
|
7303
|
+
...syntheticPendingOps.map((op) => ({ op, synthetic: true }))
|
|
7304
|
+
];
|
|
7305
|
+
diagnostics = {
|
|
7306
|
+
source: pendingOps.length > 0 && syntheticPendingOps.length > 0 ? "mixed" : syntheticPendingOps.length > 0 ? "synthetic" : "pending",
|
|
7307
|
+
total: opsToApply.length,
|
|
7308
|
+
mutated: 0,
|
|
7309
|
+
persistedWithoutMutation: 0,
|
|
7310
|
+
reasons: {}
|
|
7311
|
+
};
|
|
7312
|
+
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));
|
|
7313
|
+
const plannedRemovals = new Set;
|
|
7314
|
+
const removedTagIds = new Set;
|
|
7315
|
+
const record = (mutated) => {
|
|
7316
|
+
if (!diagnostics)
|
|
7317
|
+
return;
|
|
7318
|
+
if (mutated) {
|
|
7319
|
+
didMutateMessage = true;
|
|
7320
|
+
diagnostics.mutated += 1;
|
|
7321
|
+
} else
|
|
7322
|
+
diagnostics.persistedWithoutMutation += 1;
|
|
7323
|
+
};
|
|
7324
|
+
let cursor = 0;
|
|
7325
|
+
drainChunk = () => {
|
|
7326
|
+
const chunk = opsToApply.slice(cursor, cursor + PENDING_OPERATION_CHUNK_SIZE);
|
|
7327
|
+
cursor += chunk.length;
|
|
7328
|
+
hasMore = cursor < opsToApply.length;
|
|
7329
|
+
for (const { op: pendingOp, synthetic } of chunk) {
|
|
7330
|
+
const tagStatus = tagStatusById.get(pendingOp.tagId);
|
|
7331
|
+
if (tagStatus === "compacted" || tagStatus === "dropped") {
|
|
7332
|
+
reject("already_reduced");
|
|
7140
7333
|
if (!synthetic)
|
|
7141
7334
|
removePendingOp(db, sessionId, pendingOp.tagId);
|
|
7142
|
-
}).immediate();
|
|
7143
|
-
} finally {
|
|
7144
|
-
if (startedAt)
|
|
7145
|
-
logSlowWriteTransaction("apply_pending_operation", startedAt);
|
|
7146
|
-
}
|
|
7147
|
-
};
|
|
7148
|
-
let shouldPersistDrop = false;
|
|
7149
|
-
if (isToolTag) {
|
|
7150
|
-
if (editMarkerTagIds.has(pendingOp.tagId)) {
|
|
7151
|
-
const strip = target?.hasAttachments?.() === true;
|
|
7152
|
-
if (target?.canDrop?.() === false || target?.prepareDrop?.() === false || !target) {
|
|
7153
|
-
reject("edit_marker_incomplete");
|
|
7154
7335
|
continue;
|
|
7155
7336
|
}
|
|
7156
|
-
|
|
7157
|
-
|
|
7158
|
-
if (markResult === "incomplete" || markResult === "absent") {
|
|
7159
|
-
reject(`edit_marker_${markResult}`);
|
|
7337
|
+
if (removedTagIds.has(pendingOp.tagId)) {
|
|
7338
|
+
reject("drop_incomplete");
|
|
7160
7339
|
continue;
|
|
7161
7340
|
}
|
|
7162
|
-
|
|
7163
|
-
|
|
7164
|
-
|
|
7165
|
-
|
|
7166
|
-
} else {
|
|
7167
|
-
const { result: dropResult, mode: appliedMode } = applyNewToolDrop(target, {
|
|
7168
|
-
inWindow: skeletonWindow.has(pendingOp.tagId),
|
|
7169
|
-
persist: persistDrop
|
|
7170
|
-
});
|
|
7171
|
-
if (dropResult === "incomplete" || synthetic && dropResult !== "removed" && dropResult !== "truncated") {
|
|
7172
|
-
reject(`drop_${dropResult}`);
|
|
7341
|
+
const target = targets.get(pendingOp.tagId);
|
|
7342
|
+
const veto = pendingDropVeto(pendingOp.tagId, target, protectedTagIds);
|
|
7343
|
+
if (veto) {
|
|
7344
|
+
reject(veto);
|
|
7173
7345
|
continue;
|
|
7174
7346
|
}
|
|
7175
|
-
|
|
7176
|
-
|
|
7177
|
-
|
|
7178
|
-
|
|
7179
|
-
|
|
7180
|
-
|
|
7347
|
+
const isToolTag = tagTypeById.get(pendingOp.tagId) === "tool";
|
|
7348
|
+
if (synthetic) {
|
|
7349
|
+
if (!isToolTag) {
|
|
7350
|
+
reject("synthetic_non_tool");
|
|
7351
|
+
continue;
|
|
7352
|
+
}
|
|
7353
|
+
if (target?.canDrop?.() !== true) {
|
|
7354
|
+
reject("synthetic_target_not_droppable");
|
|
7355
|
+
continue;
|
|
7356
|
+
}
|
|
7357
|
+
}
|
|
7358
|
+
const persistDrop = (mode) => {
|
|
7359
|
+
markTagDropped2(db, sessionId, pendingOp.tagId, mode);
|
|
7360
|
+
if (!synthetic)
|
|
7361
|
+
removePendingOp(db, sessionId, pendingOp.tagId);
|
|
7362
|
+
};
|
|
7363
|
+
if (isToolTag) {
|
|
7364
|
+
if (editMarkerTagIds.has(pendingOp.tagId)) {
|
|
7365
|
+
const strip = target?.hasAttachments?.() === true;
|
|
7366
|
+
if (target?.canDrop?.() === false || target?.prepareDrop?.() === false || !target) {
|
|
7367
|
+
reject("edit_marker_incomplete");
|
|
7368
|
+
continue;
|
|
7369
|
+
}
|
|
7370
|
+
persistDrop(strip ? "edit_marker_stripped" : "edit_marker");
|
|
7371
|
+
mutations.push(() => {
|
|
7372
|
+
const markResult = (strip ? target?.editMarkerStripped?.() : target?.editMarker?.()) ?? "absent";
|
|
7373
|
+
if (markResult === "incomplete" || markResult === "absent") {
|
|
7374
|
+
reject(`edit_marker_${markResult}`);
|
|
7375
|
+
return;
|
|
7376
|
+
}
|
|
7377
|
+
record(true);
|
|
7378
|
+
onTagReduced?.({
|
|
7379
|
+
tagNumber: pendingOp.tagId,
|
|
7380
|
+
mode: "edit_marker"
|
|
7381
|
+
});
|
|
7382
|
+
});
|
|
7383
|
+
} else {
|
|
7384
|
+
const plan = planNewToolDrop(target, { inWindow: skeletonWindow.has(pendingOp.tagId) }, true, plannedRemovals);
|
|
7385
|
+
if (!plan) {
|
|
7386
|
+
reject("drop_incomplete");
|
|
7387
|
+
continue;
|
|
7388
|
+
}
|
|
7389
|
+
persistDrop(plan.mode);
|
|
7390
|
+
if (plan.mode === "full" && target?.drop) {
|
|
7391
|
+
target.notePlannedRemoval?.(plannedRemovals);
|
|
7392
|
+
removedTagIds.add(pendingOp.tagId);
|
|
7393
|
+
}
|
|
7394
|
+
mutations.push(() => {
|
|
7395
|
+
const { result: dropResult, mode: appliedMode } = plan.apply();
|
|
7396
|
+
if (dropResult === "incomplete" || synthetic && dropResult !== "removed" && dropResult !== "truncated") {
|
|
7397
|
+
reject(`drop_${dropResult}`);
|
|
7398
|
+
return;
|
|
7399
|
+
}
|
|
7400
|
+
if (dropResult === "removed" || dropResult === "truncated") {
|
|
7401
|
+
record(true);
|
|
7402
|
+
onTagReduced?.({
|
|
7403
|
+
tagNumber: pendingOp.tagId,
|
|
7404
|
+
mode: appliedMode === "full" ? "full" : "truncated"
|
|
7405
|
+
});
|
|
7406
|
+
} else {
|
|
7407
|
+
reject(`drop_${dropResult}`);
|
|
7408
|
+
record(false);
|
|
7409
|
+
}
|
|
7410
|
+
});
|
|
7411
|
+
}
|
|
7412
|
+
} else if (target) {
|
|
7413
|
+
const replacement = buildReplacementContent(pendingOp.tagId);
|
|
7414
|
+
persistDrop();
|
|
7415
|
+
mutations.push(() => {
|
|
7416
|
+
const priorContent = target.getContent?.();
|
|
7417
|
+
const changed = target.setContent(replacement);
|
|
7418
|
+
record(changed);
|
|
7419
|
+
if (changed) {
|
|
7420
|
+
const originalCharacters = typeof priorContent === "string" ? priorContent.length : tagById.get(pendingOp.tagId)?.byteSize ?? replacement.length;
|
|
7421
|
+
onTagReduced?.({
|
|
7422
|
+
tagNumber: pendingOp.tagId,
|
|
7423
|
+
mode: "partial",
|
|
7424
|
+
removedCharacters: Math.max(0, originalCharacters - replacement.length)
|
|
7425
|
+
});
|
|
7426
|
+
} else {
|
|
7427
|
+
reject("content_unchanged");
|
|
7428
|
+
}
|
|
7181
7429
|
});
|
|
7182
|
-
} else {
|
|
7183
|
-
reject(
|
|
7430
|
+
} else if (!synthetic) {
|
|
7431
|
+
reject("target_absent");
|
|
7432
|
+
persistDrop();
|
|
7433
|
+
mutations.push(() => record(false));
|
|
7184
7434
|
}
|
|
7185
|
-
shouldPersistDrop = true;
|
|
7186
7435
|
}
|
|
7187
|
-
}
|
|
7188
|
-
|
|
7189
|
-
|
|
7190
|
-
|
|
7191
|
-
|
|
7192
|
-
|
|
7193
|
-
|
|
7194
|
-
|
|
7195
|
-
|
|
7196
|
-
onTagReduced?.({
|
|
7197
|
-
tagNumber: pendingOp.tagId,
|
|
7198
|
-
mode: "partial",
|
|
7199
|
-
removedCharacters: Math.max(0, originalCharacters - replacement.length)
|
|
7200
|
-
});
|
|
7201
|
-
} else {
|
|
7202
|
-
reject("content_unchanged");
|
|
7203
|
-
}
|
|
7204
|
-
shouldPersistDrop = true;
|
|
7205
|
-
} else if (!synthetic) {
|
|
7206
|
-
reject("target_absent");
|
|
7207
|
-
persistDrop();
|
|
7208
|
-
shouldPersistDrop = true;
|
|
7209
|
-
}
|
|
7210
|
-
if (!shouldPersistDrop) {
|
|
7211
|
-
reject("not_persisted");
|
|
7212
|
-
continue;
|
|
7213
|
-
}
|
|
7214
|
-
if (operationMutated)
|
|
7215
|
-
diagnostics.mutated += 1;
|
|
7216
|
-
else
|
|
7217
|
-
diagnostics.persistedWithoutMutation += 1;
|
|
7436
|
+
};
|
|
7437
|
+
drainChunk();
|
|
7438
|
+
}).immediate();
|
|
7439
|
+
} catch (error) {
|
|
7440
|
+
if (!admitted && /database (?:table )?is locked|sqlite_(busy|locked)/i.test(String(error))) {
|
|
7441
|
+
sessionLog2(sessionId, "pending operations write admission busy; retaining remaining operations for retry");
|
|
7442
|
+
hasMore = false;
|
|
7443
|
+
} else {
|
|
7444
|
+
throw error;
|
|
7218
7445
|
}
|
|
7446
|
+
} finally {
|
|
7447
|
+
if (startedAt)
|
|
7448
|
+
logSlowWriteTransaction("apply_pending_operations", startedAt);
|
|
7219
7449
|
}
|
|
7220
|
-
|
|
7221
|
-
|
|
7222
|
-
|
|
7223
|
-
return false;
|
|
7224
|
-
}
|
|
7225
|
-
throw error;
|
|
7226
|
-
}
|
|
7450
|
+
for (const mutate of mutations.splice(0))
|
|
7451
|
+
mutate();
|
|
7452
|
+
} while (hasMore);
|
|
7227
7453
|
if (diagnostics) {
|
|
7228
7454
|
onBatchComplete?.(diagnostics);
|
|
7229
7455
|
if (diagnostics.total > 0 && diagnostics.mutated === 0) {
|
|
@@ -7453,7 +7679,7 @@ function foldExecutesThisPass(foldDue, materialized) {
|
|
|
7453
7679
|
}
|
|
7454
7680
|
|
|
7455
7681
|
// src/features/magic-context/storage-caveman-rules.ts
|
|
7456
|
-
var
|
|
7682
|
+
var NAMESPACE2 = "caveman";
|
|
7457
7683
|
var CURRENT_RULES_VERSION = 2;
|
|
7458
7684
|
var ORIGINAL_RULES = {
|
|
7459
7685
|
currentRules: false,
|
|
@@ -7472,7 +7698,7 @@ function parseState(lane) {
|
|
|
7472
7698
|
}
|
|
7473
7699
|
function getCavemanReplayState(db, sessionId) {
|
|
7474
7700
|
try {
|
|
7475
|
-
return parseState(readReplayEnvelope(db, sessionId)[
|
|
7701
|
+
return parseState(readReplayEnvelope(db, sessionId)[NAMESPACE2]);
|
|
7476
7702
|
} catch (error) {
|
|
7477
7703
|
if (error instanceof ReplayDocumentError)
|
|
7478
7704
|
return ORIGINAL_RULES;
|
|
@@ -7482,11 +7708,11 @@ function getCavemanReplayState(db, sessionId) {
|
|
|
7482
7708
|
function recordCavemanCurrentRules(db, sessionId, englishWordRules, legacyReasoningTags) {
|
|
7483
7709
|
const tags = [...new Set(legacyReasoningTags)].sort((a, b) => a - b);
|
|
7484
7710
|
const persisted = updateReplayDocument(db, sessionId, (doc) => {
|
|
7485
|
-
const current = parseState(doc[
|
|
7711
|
+
const current = parseState(doc[NAMESPACE2]);
|
|
7486
7712
|
if (current.currentRules && current.englishWordRules === englishWordRules)
|
|
7487
7713
|
return false;
|
|
7488
7714
|
doc.version = 2;
|
|
7489
|
-
doc[
|
|
7715
|
+
doc[NAMESPACE2] = {
|
|
7490
7716
|
rules: CURRENT_RULES_VERSION,
|
|
7491
7717
|
legacyReasoningTags: current.currentRules ? [...current.legacyReasoningTags].sort((a, b) => a - b) : tags,
|
|
7492
7718
|
...englishWordRules ? {} : { englishWordRules: false }
|
|
@@ -8475,10 +8701,41 @@ function createExistingTagResolver(sessionId, tagger, db) {
|
|
|
8475
8701
|
}
|
|
8476
8702
|
|
|
8477
8703
|
// src/hooks/magic-context/transform-stage-logger.ts
|
|
8478
|
-
|
|
8479
|
-
|
|
8704
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
8705
|
+
var SLOW_STAGE_MS = 100;
|
|
8706
|
+
var passes = new AsyncLocalStorage;
|
|
8707
|
+
async function withTransformTimingSummary(run) {
|
|
8708
|
+
const pass = {
|
|
8709
|
+
stages: [],
|
|
8710
|
+
slow: [],
|
|
8711
|
+
closed: false,
|
|
8712
|
+
sessionId: undefined
|
|
8713
|
+
};
|
|
8714
|
+
return passes.run(pass, async () => {
|
|
8715
|
+
try {
|
|
8716
|
+
return await run();
|
|
8717
|
+
} finally {
|
|
8718
|
+
pass.closed = true;
|
|
8719
|
+
if (pass.sessionId)
|
|
8720
|
+
sessionLog2(pass.sessionId, `transform stages: ${pass.stages.join(" ")} slow>=${SLOW_STAGE_MS}ms=[${pass.slow.join(",")}]`);
|
|
8721
|
+
}
|
|
8722
|
+
});
|
|
8723
|
+
}
|
|
8724
|
+
function logTransformElapsed(sessionId, stage, elapsedMs, extra) {
|
|
8725
|
+
const elapsed = elapsedMs.toFixed(1);
|
|
8480
8726
|
const suffix = extra ? ` ${extra}` : "";
|
|
8481
|
-
|
|
8727
|
+
const pass = passes.getStore();
|
|
8728
|
+
if (pass && !pass.closed) {
|
|
8729
|
+
pass.sessionId = sessionId;
|
|
8730
|
+
pass.stages.push(`${stage}=${elapsed}ms${extra ? `(${extra})` : ""}`);
|
|
8731
|
+
if (elapsedMs >= SLOW_STAGE_MS)
|
|
8732
|
+
pass.slow.push(stage);
|
|
8733
|
+
}
|
|
8734
|
+
if (elapsedMs >= SLOW_STAGE_MS)
|
|
8735
|
+
sessionLog2(sessionId, `transform stage: stage=${stage} elapsed=${elapsed}ms${suffix}`);
|
|
8736
|
+
}
|
|
8737
|
+
function logTransformTiming(sessionId, stage, startMs, extra) {
|
|
8738
|
+
logTransformElapsed(sessionId, stage, performance.now() - startMs, extra);
|
|
8482
8739
|
}
|
|
8483
8740
|
|
|
8484
8741
|
// src/hooks/magic-context/tag-messages.ts
|
|
@@ -8844,13 +9101,18 @@ function tagMessages(sessionId, messages, tagger, db, options = {}) {
|
|
|
8844
9101
|
}));
|
|
8845
9102
|
accAssignTag += performance.now() - _tAssignText;
|
|
8846
9103
|
const persistedSource = sourceContents.get(tagId);
|
|
8847
|
-
if (persistedSource !== undefined) {
|
|
9104
|
+
if (persistedSource !== undefined && !options.refreshSourceContents) {
|
|
8848
9105
|
textPart.text = options.normalizeRestoredAssistantText && message.info.role === "assistant" ? options.normalizeRestoredAssistantText(persistedSource) : persistedSource;
|
|
8849
9106
|
} else {
|
|
8850
9107
|
const sourceContent = stripTagPrefix(textPart.text);
|
|
8851
|
-
if (sourceContent.trim().length > 0) {
|
|
9108
|
+
if (sourceContent.trim().length > 0 || options.refreshSourceContents) {
|
|
8852
9109
|
const _tSaveText = performance.now();
|
|
8853
|
-
|
|
9110
|
+
if (options.refreshSourceContents) {
|
|
9111
|
+
replaceSourceContent(db, sessionId, tagId, sourceContent);
|
|
9112
|
+
updateTagByteSize2(db, sessionId, tagId, byteSize(sourceContent));
|
|
9113
|
+
updateTagTokenCount2(db, sessionId, tagId, estimateTextTagTokenCount(sourceContent));
|
|
9114
|
+
} else
|
|
9115
|
+
saveSourceContent(db, sessionId, tagId, sourceContent);
|
|
8854
9116
|
accSaveSource += performance.now() - _tSaveText;
|
|
8855
9117
|
}
|
|
8856
9118
|
}
|
|
@@ -8931,22 +9193,12 @@ function tagMessages(sessionId, messages, tagger, db, options = {}) {
|
|
|
8931
9193
|
const filePart = part;
|
|
8932
9194
|
const messageParts = message.parts;
|
|
8933
9195
|
const contentId = `${messageId}:file${partIndex}`;
|
|
8934
|
-
const existingTagId = resolver.resolve(messageId, "file", contentId, fileOrdinal);
|
|
8935
|
-
|
|
8936
|
-
|
|
8937
|
-
|
|
8938
|
-
|
|
8939
|
-
|
|
8940
|
-
}));
|
|
8941
|
-
accAssignTag += performance.now() - _tAssignFile;
|
|
8942
|
-
if (existingTagId === undefined) {
|
|
8943
|
-
const sourceContent = buildFileSourceContent(message.parts);
|
|
8944
|
-
if (sourceContent) {
|
|
8945
|
-
const _tSaveFile = performance.now();
|
|
8946
|
-
saveSourceContent(db, sessionId, tagId, sourceContent);
|
|
8947
|
-
accSaveSource += performance.now() - _tSaveFile;
|
|
8948
|
-
}
|
|
8949
|
-
}
|
|
9196
|
+
const existingTagId = resolver.resolve(messageId, "file", contentId, fileOrdinal) ?? getTagNumberByMessageId2(db, sessionId, contentId) ?? undefined;
|
|
9197
|
+
fileOrdinal += 1;
|
|
9198
|
+
if (existingTagId === undefined)
|
|
9199
|
+
continue;
|
|
9200
|
+
const tagId = existingTagId;
|
|
9201
|
+
tagger.bindTag(sessionId, contentId, tagId);
|
|
8950
9202
|
messageTagNumbers.set(message, Math.max(messageTagNumbers.get(message) ?? 0, tagId));
|
|
8951
9203
|
targets.set(tagId, {
|
|
8952
9204
|
message,
|
|
@@ -8968,7 +9220,6 @@ function tagMessages(sessionId, messages, tagger, db, options = {}) {
|
|
|
8968
9220
|
return true;
|
|
8969
9221
|
}
|
|
8970
9222
|
});
|
|
8971
|
-
fileOrdinal += 1;
|
|
8972
9223
|
}
|
|
8973
9224
|
}
|
|
8974
9225
|
if (message.info.role === "assistant" && !messageHasTextPart) {
|
|
@@ -9732,7 +9983,7 @@ async function runPostTransformPhase(args) {
|
|
|
9732
9983
|
routinePressureAppliedBySession.set(args.sessionId, true);
|
|
9733
9984
|
}
|
|
9734
9985
|
const routinePressureAlreadyApplied = args.fullFeatureMode && executePressureEligible && routinePressureAppliedBySession.get(args.sessionId) === true;
|
|
9735
|
-
if (args.contextUsage.percentage > 0 && args.contextUsage.percentage < args.forceMaterializationPercentage - 5 && getEmergencyInputSample(args.db, args.sessionId) > 0) {
|
|
9986
|
+
if (args.contextUsageFromEstimate !== true && args.contextUsage.percentage > 0 && args.contextUsage.percentage < args.forceMaterializationPercentage - 5 && getEmergencyInputSample(args.db, args.sessionId) > 0) {
|
|
9736
9987
|
clearEmergencyDropSample(args.db, args.sessionId);
|
|
9737
9988
|
}
|
|
9738
9989
|
const activeCompartmentRun = args.canRunCompartments ? getActiveCompartmentRun(args.sessionId) : undefined;
|
|
@@ -9762,7 +10013,7 @@ async function runPostTransformPhase(args) {
|
|
|
9762
10013
|
if (tag && tag > 0)
|
|
9763
10014
|
safeReasoningCutoff = Math.min(safeReasoningCutoff, tag - 1);
|
|
9764
10015
|
}
|
|
9765
|
-
let activeThinkingPrefixHold = args.activeThinkingPrefixHold === true
|
|
10016
|
+
let activeThinkingPrefixHold = args.activeThinkingPrefixHold === true;
|
|
9766
10017
|
let freezeM0M1 = args.freezeM0M1 === true || activeThinkingPrefixHold;
|
|
9767
10018
|
let rewritingSignedPrefix = false;
|
|
9768
10019
|
let thinkingReleasedForFit = false;
|
|
@@ -9784,7 +10035,7 @@ async function runPostTransformPhase(args) {
|
|
|
9784
10035
|
rewritingSignedPrefix = true;
|
|
9785
10036
|
thinkingReleasedForFit ||= forFit;
|
|
9786
10037
|
};
|
|
9787
|
-
if (activeThinkingPrefixHold && args.
|
|
10038
|
+
if (args.forceSignedRebuildForFit && (activeThinkingPrefixHold || activeThinkingTurn && args.thinkingBindingRecoveryEnabledForModel === true)) {
|
|
9788
10039
|
releaseThinkingForRewrite(true);
|
|
9789
10040
|
}
|
|
9790
10041
|
const foldDueDecision = m0M1EnabledForFold && args.m0M1 && !freezeM0M1 ? mustMaterialize({
|
|
@@ -9921,7 +10172,7 @@ async function runPostTransformPhase(args) {
|
|
|
9921
10172
|
const shouldReadPendingOps = !compactionOff && (materializationRequested || publishedM1RefreshedThisPass || args.schedulerDecision === "execute" || forceMaterialization || foldExecutedThisPass || firstRenderBust || compartmentRunning);
|
|
9922
10173
|
const pendingOps = shouldReadPendingOps ? getPendingOps(args.db, args.sessionId) : [];
|
|
9923
10174
|
const hasPendingUserOps = pendingOps.length > 0;
|
|
9924
|
-
if (args.schedulerDecision === "execute" && pendingOps.some((op) => newTargets.get(op.tagId)?.thinkingDropProtected))
|
|
10175
|
+
if (args.schedulerDecision === "execute" && args.thinkingBindingRecoveryEnabledForModel !== true && pendingOps.some((op) => newTargets.get(op.tagId)?.thinkingDropProtected))
|
|
9925
10176
|
requestPendingMaterialization(args.pendingMaterializationSessions, args.sessionId, "thinking_hold");
|
|
9926
10177
|
const formatPendingOpsDepth = () => {
|
|
9927
10178
|
const depth = getPendingOpsCount(args.db, args.sessionId);
|
|
@@ -9932,16 +10183,34 @@ async function runPostTransformPhase(args) {
|
|
|
9932
10183
|
const rideSignals = {
|
|
9933
10184
|
subagentExecute: !args.fullFeatureMode && args.schedulerDecision === "execute",
|
|
9934
10185
|
hardFold: rewritingSignedPrefix || foldBustsServedPrefixThisPass || firstRenderBust || idleExpiryRebuild,
|
|
9935
|
-
force: emergencyDropEligible && (args.contextUsage.percentage >= 95 || getEmergencyInputSample(args.db, args.sessionId) === 0),
|
|
10186
|
+
force: emergencyDropEligible && (args.contextUsage.percentage >= 95 || args.contextUsageFromEstimate !== true && getEmergencyInputSample(args.db, args.sessionId) === 0),
|
|
9936
10187
|
explicitFlush: isExplicitFlush && hasPendingMaterializationOrigin(args.pendingMaterializationSessions, args.sessionId, "user_flush"),
|
|
9937
10188
|
publishedHistory: !prefixPreflightFailed && (publishedM1RefreshedThisPass || !m0M1EnabledForFold && (args.pendingCompartmentInjection?.compartmentCount ?? 0) > 0 && legacyPublishedHeadChanged(args))
|
|
9938
10189
|
};
|
|
9939
|
-
const publishedWorkDrainAllowed = !compactionOff && (
|
|
10190
|
+
const publishedWorkDrainAllowed = !compactionOff && reclaimRidePermitted(rideSignals, {
|
|
10191
|
+
signedThinkingHold: activeThinkingPrefixHold,
|
|
10192
|
+
firstRender: firstRenderBust,
|
|
10193
|
+
idleExpiry: idleExpiryRebuild,
|
|
10194
|
+
emergency: emergencyDropEligible
|
|
10195
|
+
});
|
|
9940
10196
|
const shouldApplyPendingOps = publishedWorkDrainAllowed;
|
|
9941
10197
|
const shouldRunHeuristics = publishedWorkDrainAllowed && (rideSignals.publishedHistory || materializationRequested || forceMaterialization || foldBustsServedPrefixThisPass || firstRenderBust || heldIdleExpiryRebuild || emergencyDropEligible || args.schedulerDecision === "execute" && (!alreadyRanThisTurn || !args.fullFeatureMode));
|
|
9942
10198
|
const isCacheBustingPass = publishedWorkDrainAllowed;
|
|
9943
|
-
|
|
10199
|
+
let unheldSignedTurnBust = false;
|
|
10200
|
+
if (isCacheBustingPass && !activeThinkingPrefixHold && activeThinkingTurn && args.thinkingBindingRecoveryEnabledForModel === true) {
|
|
10201
|
+
if (foldBustsServedPrefixThisPass || firstRenderBust || publishedM1RefreshedThisPass)
|
|
10202
|
+
releaseThinkingForRewrite();
|
|
10203
|
+
else {
|
|
10204
|
+
unheldSignedTurnBust = true;
|
|
10205
|
+
retainedThinking.clear();
|
|
10206
|
+
protectedThinkingMessages.clear();
|
|
10207
|
+
newTargets = args.targets;
|
|
10208
|
+
}
|
|
10209
|
+
}
|
|
10210
|
+
let recoveryTailNormalizedThisPass = false;
|
|
10211
|
+
if (args.normalizeRecoveryTail && isCacheBustingPass && !activeThinkingPrefixHold) {
|
|
9944
10212
|
args.normalizeRecoveryTail();
|
|
10213
|
+
recoveryTailNormalizedThisPass = true;
|
|
9945
10214
|
args.tags = getTagsBySession2(args.db, args.sessionId);
|
|
9946
10215
|
newTargets = protectNewTagMutations(args.messages, args.targets, retainedThinking, args.thinkingBindingRecoveryEnabledForModel === true);
|
|
9947
10216
|
}
|
|
@@ -10412,6 +10681,26 @@ async function runPostTransformPhase(args) {
|
|
|
10412
10681
|
}
|
|
10413
10682
|
}
|
|
10414
10683
|
const m0M1Enabled = m0M1EnabledForFold;
|
|
10684
|
+
if (m0M1Enabled && args.m0M1 && !compactionOff && args.opencode2) {
|
|
10685
|
+
const covered = args.coveredHostInstructions ?? [];
|
|
10686
|
+
if (covered.length > 0 || canEditWholePrefix) {
|
|
10687
|
+
let retain = false;
|
|
10688
|
+
if (hostInstructionRetentionEnabled()) {
|
|
10689
|
+
try {
|
|
10690
|
+
retain = isHostInstructionRetentionOn(args.db, args.sessionId);
|
|
10691
|
+
} catch (error) {
|
|
10692
|
+
failPass("host-instruction-retention-read-failure", error);
|
|
10693
|
+
}
|
|
10694
|
+
if (!retain && canEditWholePrefix) {
|
|
10695
|
+
if (!markHostInstructionRetention(args.db, args.sessionId))
|
|
10696
|
+
failPass("host-instruction-retention-persistence-failure");
|
|
10697
|
+
retain = true;
|
|
10698
|
+
}
|
|
10699
|
+
}
|
|
10700
|
+
if (retain && covered.length > 0)
|
|
10701
|
+
args.messages.unshift(...covered);
|
|
10702
|
+
}
|
|
10703
|
+
}
|
|
10415
10704
|
if (m0M1Enabled && args.m0M1) {
|
|
10416
10705
|
if (freezeM0M1 && !preparedPrefix) {
|
|
10417
10706
|
preparedPrefix = prepareCachedM0M1Replay(args.db, args.sessionId);
|
|
@@ -10934,7 +11223,7 @@ async function runPostTransformPhase(args) {
|
|
|
10934
11223
|
}
|
|
10935
11224
|
}
|
|
10936
11225
|
}
|
|
10937
|
-
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;
|
|
11226
|
+
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;
|
|
10938
11227
|
let proactiveThinkingStrip = null;
|
|
10939
11228
|
if (!compactionOff && args.thinkingBindingRecoveryEnabledForModel === true && proactiveThinkingStripPermitted && prefixEditBesidesReasoningTrim) {
|
|
10940
11229
|
const outcome = freezeReasoningOnBustingPass({
|
|
@@ -10951,7 +11240,11 @@ async function runPostTransformPhase(args) {
|
|
|
10951
11240
|
mergedReasoningStrippedIds.add(thinkingBindingRecoveryFrozenId(messageId));
|
|
10952
11241
|
}
|
|
10953
11242
|
bustedThisPass = true;
|
|
11243
|
+
if (unheldSignedTurnBust)
|
|
11244
|
+
rewritingSignedPrefix = true;
|
|
10954
11245
|
} else if (outcome.persistenceFailed) {
|
|
11246
|
+
if (unheldSignedTurnBust)
|
|
11247
|
+
throw new Error("Cannot persist signed thinking omission after a mid-turn edit");
|
|
10955
11248
|
failPass("proactive-thinking-strip-persistence-failure");
|
|
10956
11249
|
}
|
|
10957
11250
|
}
|
|
@@ -11110,7 +11403,8 @@ async function runPostTransformPhase(args) {
|
|
|
11110
11403
|
prefixTrimStatus: deliveredPrefix?.prefixTrimStatus ?? null,
|
|
11111
11404
|
thinkingBindingRecovery,
|
|
11112
11405
|
proactiveThinkingStrip,
|
|
11113
|
-
thinkingReleasedForFit
|
|
11406
|
+
thinkingReleasedForFit,
|
|
11407
|
+
openTurnSignedThinkingKept: args.thinkingBindingRecoveryEnabledForModel === true && activeThinkingTurn && !rewritingSignedPrefix
|
|
11114
11408
|
};
|
|
11115
11409
|
}
|
|
11116
11410
|
function checkM0MutationDriftAndSignal(args) {
|
|
@@ -11190,6 +11484,26 @@ function systemPromptDates(prompt, sticky) {
|
|
|
11190
11484
|
return { live: values.length ? JSON.stringify(values) : undefined, stable };
|
|
11191
11485
|
}
|
|
11192
11486
|
|
|
11487
|
+
// src/hooks/magic-context/system-prompt-diagnostics.ts
|
|
11488
|
+
import { createHash } from "node:crypto";
|
|
11489
|
+
function snapshotSystemPrompt(system, preset) {
|
|
11490
|
+
return { elements: system.map((element) => Buffer.from(element)), preset };
|
|
11491
|
+
}
|
|
11492
|
+
function describeSystemPromptChange(previous, current) {
|
|
11493
|
+
const metadata = (element) => element === undefined ? "absent" : `bytes=${element.length},md5=${createHash("md5").update(element).digest("hex")}`;
|
|
11494
|
+
const elements = [];
|
|
11495
|
+
for (let index = 0;index < Math.max(previous?.elements.length ?? 0, current.elements.length); index++) {
|
|
11496
|
+
const before = previous?.elements[index];
|
|
11497
|
+
const after = current.elements[index];
|
|
11498
|
+
let offset = 0;
|
|
11499
|
+
while (before && after && offset < Math.min(before.length, after.length) && before[offset] === after[offset])
|
|
11500
|
+
offset++;
|
|
11501
|
+
const status = !previous ? "unknown" : !before ? "added" : !after ? "removed" : before.equals(after) ? "unchanged" : "changed";
|
|
11502
|
+
elements.push(`${index}:${status}(${metadata(before)} -> ${metadata(after)},firstDiffByte=${!previous ? "unknown" : status === "unchanged" ? "none" : offset})`);
|
|
11503
|
+
}
|
|
11504
|
+
return `presetChanged=${previous ? previous.preset !== current.preset : "unknown"} elements=[${elements.join("; ")}]`;
|
|
11505
|
+
}
|
|
11506
|
+
|
|
11193
11507
|
// src/hooks/magic-context/system-date-refresh.ts
|
|
11194
11508
|
var channels = new WeakMap;
|
|
11195
11509
|
var outputUpdates = new WeakMap;
|
|
@@ -11347,6 +11661,7 @@ function createSystemPromptHashHandler(deps) {
|
|
|
11347
11661
|
});
|
|
11348
11662
|
const guidanceEpochs = createPromptSurfaceGuidanceEpochCache(promptSurfaceRuntime);
|
|
11349
11663
|
const stickyDateBySession = new Map;
|
|
11664
|
+
const diagnosticPrompts = new Map;
|
|
11350
11665
|
const processSystemPrompt = async (input, output) => {
|
|
11351
11666
|
const sessionId = input.sessionID;
|
|
11352
11667
|
if (!sessionId)
|
|
@@ -11479,8 +11794,11 @@ function createSystemPromptHashHandler(deps) {
|
|
|
11479
11794
|
return;
|
|
11480
11795
|
}
|
|
11481
11796
|
const sessionMeta = sessionMetaEarly;
|
|
11797
|
+
const previousPrompt = diagnosticPrompts.get(sessionId);
|
|
11798
|
+
const currentPrompt = previousPrompt && previousHash === currentHash ? previousPrompt : snapshotSystemPrompt(output.system, promptSurface.preset);
|
|
11799
|
+
diagnosticPrompts.set(sessionId, currentPrompt);
|
|
11482
11800
|
if (previousHash !== "" && previousHash !== "0" && previousHash !== currentHash) {
|
|
11483
|
-
sessionLog2(sessionId, `system prompt hash changed: ${previousHash} → ${currentHash} (len=${systemContent.length}), ${idleCacheExpired ? "adopting on idle-expired request" : requestMessagesFinal ? "adopting on the request whose messages are already final" : "triggering flush"}`);
|
|
11801
|
+
sessionLog2(sessionId, `system prompt hash changed: ${previousHash} → ${currentHash} (len=${systemContent.length}), ${idleCacheExpired ? "adopting on idle-expired request" : requestMessagesFinal ? "adopting on the request whose messages are already final" : "triggering flush"}; ${describeSystemPromptChange(previousPrompt, currentPrompt)}`);
|
|
11484
11802
|
noteSystemPromptHashChange(sessionId);
|
|
11485
11803
|
if (!adoptSystemChange) {
|
|
11486
11804
|
deps.historyRefreshSessions.add(sessionId);
|
|
@@ -11524,6 +11842,7 @@ function createSystemPromptHashHandler(deps) {
|
|
|
11524
11842
|
return {
|
|
11525
11843
|
handler,
|
|
11526
11844
|
clearSession: (sessionId) => {
|
|
11845
|
+
diagnosticPrompts.delete(sessionId);
|
|
11527
11846
|
clearSystemDateRefresh(deps.historyRefreshSessions, sessionId);
|
|
11528
11847
|
guidanceEpochs.clear(sessionId);
|
|
11529
11848
|
clearSystemPromptHashSession(sessionId, {
|
|
@@ -11724,7 +12043,9 @@ var PASS_DEGRADATION_EFFECTS = {
|
|
|
11724
12043
|
"trailing-blank-decision-exception": "changes-request",
|
|
11725
12044
|
"proactive-thinking-strip-persistence-failure": "changes-request",
|
|
11726
12045
|
"reasoning-removal-read-failure": "changes-request",
|
|
11727
|
-
"reasoning-removal-persistence-failure": "changes-request"
|
|
12046
|
+
"reasoning-removal-persistence-failure": "changes-request",
|
|
12047
|
+
"host-instruction-retention-read-failure": "changes-request",
|
|
12048
|
+
"host-instruction-retention-persistence-failure": "changes-request"
|
|
11728
12049
|
};
|
|
11729
12050
|
function degradationChangesRequest(site) {
|
|
11730
12051
|
return PASS_DEGRADATION_EFFECTS[site] === "changes-request";
|
|
@@ -11753,7 +12074,7 @@ function createPassOutcome() {
|
|
|
11753
12074
|
}
|
|
11754
12075
|
|
|
11755
12076
|
// src/hooks/magic-context/rust-mode-transform.ts
|
|
11756
|
-
import { createHash as
|
|
12077
|
+
import { createHash as createHash5, randomUUID as randomUUID2 } from "node:crypto";
|
|
11757
12078
|
|
|
11758
12079
|
// src/features/magic-context/memory/single-store-embedding-drain.ts
|
|
11759
12080
|
function isWatermarkRow(row) {
|
|
@@ -11817,7 +12138,7 @@ function advanceEmbeddedWatermark(db, projectPath, upTo) {
|
|
|
11817
12138
|
}
|
|
11818
12139
|
|
|
11819
12140
|
// src/features/magic-context/mural/source-revision.ts
|
|
11820
|
-
import { createHash } from "node:crypto";
|
|
12141
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
11821
12142
|
var statements = new WeakMap;
|
|
11822
12143
|
function muralSourceRevision(db, projectPath) {
|
|
11823
12144
|
let statement = statements.get(db);
|
|
@@ -11834,7 +12155,7 @@ function muralSourceRevision(db, projectPath) {
|
|
|
11834
12155
|
statements.set(db, statement);
|
|
11835
12156
|
}
|
|
11836
12157
|
const row = statement.get(projectPath, Date.now());
|
|
11837
|
-
return
|
|
12158
|
+
return createHash2("sha256").update(row.revision).digest("hex");
|
|
11838
12159
|
}
|
|
11839
12160
|
|
|
11840
12161
|
// src/features/magic-context/install-instance-id.ts
|
|
@@ -12261,6 +12582,7 @@ class HistorianHostRunner {
|
|
|
12261
12582
|
throw new Error("hidden completion carrier returned no session id");
|
|
12262
12583
|
const run = await promptSyncWithValidatedOutputRetry(undefined, {
|
|
12263
12584
|
path: { id: handle.id },
|
|
12585
|
+
cacheTail: "skip",
|
|
12264
12586
|
query: { directory: sessionDirectory },
|
|
12265
12587
|
body: {
|
|
12266
12588
|
agent: "historian",
|
|
@@ -14209,7 +14531,7 @@ function noteExternalLkgReplay(participant, sessionId, inputMessages, servedMess
|
|
|
14209
14531
|
}
|
|
14210
14532
|
|
|
14211
14533
|
// src/hooks/magic-context/rust-served-raw.ts
|
|
14212
|
-
import { createHash as
|
|
14534
|
+
import { createHash as createHash4 } from "node:crypto";
|
|
14213
14535
|
class RustServedRawConflict extends EmergencyFailClosedError {
|
|
14214
14536
|
reason;
|
|
14215
14537
|
messageIds;
|
|
@@ -14223,7 +14545,7 @@ class RustServedRawConflict extends EmergencyFailClosedError {
|
|
|
14223
14545
|
}
|
|
14224
14546
|
function partDigest(part) {
|
|
14225
14547
|
const serialized = JSON.stringify(part);
|
|
14226
|
-
return
|
|
14548
|
+
return createHash4("sha256").update(stableStringify(serialized === undefined ? undefined : JSON.parse(serialized))).digest("hex");
|
|
14227
14549
|
}
|
|
14228
14550
|
function records(doc) {
|
|
14229
14551
|
if (doc.rustServedRaw === undefined)
|
|
@@ -14453,6 +14775,24 @@ function contextUsagePassSnapshot(sessionMeta) {
|
|
|
14453
14775
|
} : null
|
|
14454
14776
|
};
|
|
14455
14777
|
}
|
|
14778
|
+
function savedProviderReadingForPass(input) {
|
|
14779
|
+
const persisted = input.persisted;
|
|
14780
|
+
if (!persisted)
|
|
14781
|
+
return null;
|
|
14782
|
+
const { percentage, inputTokens } = persisted.usage;
|
|
14783
|
+
if (!Number.isFinite(percentage) || percentage <= 0 || !Number.isFinite(inputTokens) || inputTokens <= 0) {
|
|
14784
|
+
return null;
|
|
14785
|
+
}
|
|
14786
|
+
if (!(input.lastResponseTime > 0) || input.cacheExpired)
|
|
14787
|
+
return null;
|
|
14788
|
+
if (persisted.lastObservedModelKey === null || input.currentModelKey === undefined || input.currentModelKey.length === 0 || piModelRefToCanonical(persisted.lastObservedModelKey) !== piModelRefToCanonical(input.currentModelKey)) {
|
|
14789
|
+
return null;
|
|
14790
|
+
}
|
|
14791
|
+
if (typeof input.contextLimit !== "number" || !(input.contextLimit > 0) || persisted.lastUsageContextLimit !== input.contextLimit) {
|
|
14792
|
+
return null;
|
|
14793
|
+
}
|
|
14794
|
+
return { percentage, inputTokens };
|
|
14795
|
+
}
|
|
14456
14796
|
function resolveUnknownUsageFromWireEstimate(input) {
|
|
14457
14797
|
if (input.usage.inputTokens > 0 || !input.pricedPass)
|
|
14458
14798
|
return input.usage;
|
|
@@ -14711,10 +15051,10 @@ function messageCacheSignature(message) {
|
|
|
14711
15051
|
const parts = Array.isArray(message.parts) ? message.parts : [];
|
|
14712
15052
|
const serializedParts = JSON.stringify(parts) ?? "null";
|
|
14713
15053
|
const serializedMessage = JSON.stringify(message) ?? "null";
|
|
14714
|
-
return `${messageIdOf(message) ?? ""}:${parts.length}:${Buffer.byteLength(serializedParts)}:${
|
|
15054
|
+
return `${messageIdOf(message) ?? ""}:${parts.length}:${Buffer.byteLength(serializedParts)}:${createHash5("sha256").update(serializedMessage).digest("hex")}`;
|
|
14715
15055
|
}
|
|
14716
15056
|
function advanceWireFingerprint(previous, encoded) {
|
|
14717
|
-
return
|
|
15057
|
+
return createHash5("sha256").update(previous).update("\\0").update(JSON.stringify(encoded) ?? "null").digest("hex");
|
|
14718
15058
|
}
|
|
14719
15059
|
function buildWireFingerprint(encoded) {
|
|
14720
15060
|
let fingerprint = "rust-wire-v1";
|
|
@@ -16495,7 +16835,7 @@ function createRustModeTransform(deps, options) {
|
|
|
16495
16835
|
const id = messageIdOf(message) ?? `index:${todoStart + offset}`;
|
|
16496
16836
|
const parts = message.parts?.filter((part) => isRecord4(part) && part.type === "tool" && part.tool === "todowrite");
|
|
16497
16837
|
if (parts?.length) {
|
|
16498
|
-
todoCalls.set(id,
|
|
16838
|
+
todoCalls.set(id, createHash5("sha256").update(JSON.stringify(parts)).digest("hex"));
|
|
16499
16839
|
} else {
|
|
16500
16840
|
todoCalls.delete(id);
|
|
16501
16841
|
}
|
|
@@ -17660,6 +18000,101 @@ function createRustModeTransform(deps, options) {
|
|
|
17660
18000
|
return adapter;
|
|
17661
18001
|
}
|
|
17662
18002
|
|
|
18003
|
+
// src/hooks/magic-context/signed-thinking-hold.ts
|
|
18004
|
+
var HEAVY_REASONING_TOKENS = 1500;
|
|
18005
|
+
var HEAVY_REASONING_WINDOW_STEPS = 15;
|
|
18006
|
+
var HOLD_CAP_POINTS = 10;
|
|
18007
|
+
var REASONING_TYPES = new Set(["reasoning", "thinking"]);
|
|
18008
|
+
function role2(message) {
|
|
18009
|
+
if (!isRecord(message))
|
|
18010
|
+
return;
|
|
18011
|
+
return isRecord(message.info) ? message.info.role : message.role;
|
|
18012
|
+
}
|
|
18013
|
+
function parts(message) {
|
|
18014
|
+
if (!isRecord(message))
|
|
18015
|
+
return [];
|
|
18016
|
+
if (Array.isArray(message.parts))
|
|
18017
|
+
return message.parts;
|
|
18018
|
+
return Array.isArray(message.content) ? message.content : [];
|
|
18019
|
+
}
|
|
18020
|
+
function recordedReasoningTokens(message) {
|
|
18021
|
+
if (!isRecord(message))
|
|
18022
|
+
return;
|
|
18023
|
+
const info = isRecord(message.info) ? message.info : undefined;
|
|
18024
|
+
const candidates = [];
|
|
18025
|
+
if (info && isRecord(info.tokens))
|
|
18026
|
+
candidates.push(info.tokens.reasoning);
|
|
18027
|
+
if (isRecord(message.usage)) {
|
|
18028
|
+
candidates.push(message.usage.reasoning, message.usage.reasoningTokens);
|
|
18029
|
+
}
|
|
18030
|
+
for (const value of candidates) {
|
|
18031
|
+
if (typeof value === "number" && Number.isFinite(value) && value > 0)
|
|
18032
|
+
return value;
|
|
18033
|
+
}
|
|
18034
|
+
return;
|
|
18035
|
+
}
|
|
18036
|
+
function stepReasoningTokens(message, estimateTextTokens) {
|
|
18037
|
+
let text = "";
|
|
18038
|
+
let opaque = false;
|
|
18039
|
+
for (const part of parts(message)) {
|
|
18040
|
+
if (!isRecord(part))
|
|
18041
|
+
continue;
|
|
18042
|
+
const type = String(part.type ?? part.kind);
|
|
18043
|
+
if (type === "redacted_thinking" || part.redacted === true) {
|
|
18044
|
+
opaque = true;
|
|
18045
|
+
continue;
|
|
18046
|
+
}
|
|
18047
|
+
if (!REASONING_TYPES.has(type))
|
|
18048
|
+
continue;
|
|
18049
|
+
const body = typeof part.thinking === "string" ? part.thinking : typeof part.text === "string" ? part.text : "";
|
|
18050
|
+
if (body.length > 0)
|
|
18051
|
+
text += body;
|
|
18052
|
+
else
|
|
18053
|
+
opaque = true;
|
|
18054
|
+
}
|
|
18055
|
+
if (!text && !opaque)
|
|
18056
|
+
return 0;
|
|
18057
|
+
return reasoningStepCost(recordedReasoningTokens(message), text ? estimateTextTokens(text) : 0, opaque);
|
|
18058
|
+
}
|
|
18059
|
+
function decideSignedThinkingHold(args) {
|
|
18060
|
+
const capPercentage = args.executeThresholdPercentage + HOLD_CAP_POINTS;
|
|
18061
|
+
let heavyStepsBack = null;
|
|
18062
|
+
let heavyStepTokens = 0;
|
|
18063
|
+
const start = latestAssistantTurnStart(args.messages);
|
|
18064
|
+
let stepsBack = 0;
|
|
18065
|
+
for (let index = args.messages.length - 1;index >= start; index--) {
|
|
18066
|
+
const message = args.messages[index];
|
|
18067
|
+
if (role2(message) !== "assistant" || parts(message).length === 0)
|
|
18068
|
+
continue;
|
|
18069
|
+
stepsBack++;
|
|
18070
|
+
if (stepsBack > HEAVY_REASONING_WINDOW_STEPS)
|
|
18071
|
+
break;
|
|
18072
|
+
const tokens = stepReasoningTokens(message, args.estimateTextTokens);
|
|
18073
|
+
if (tokens > HEAVY_REASONING_TOKENS) {
|
|
18074
|
+
heavyStepsBack = stepsBack;
|
|
18075
|
+
heavyStepTokens = tokens;
|
|
18076
|
+
break;
|
|
18077
|
+
}
|
|
18078
|
+
}
|
|
18079
|
+
if (heavyStepsBack === null)
|
|
18080
|
+
return {
|
|
18081
|
+
held: false,
|
|
18082
|
+
reason: "no_recent_heavy_reasoning",
|
|
18083
|
+
heavyStepsBack,
|
|
18084
|
+
heavyStepTokens,
|
|
18085
|
+
capPercentage
|
|
18086
|
+
};
|
|
18087
|
+
if (!(args.usagePercentage < capPercentage))
|
|
18088
|
+
return { held: false, reason: "above_cap", heavyStepsBack, heavyStepTokens, capPercentage };
|
|
18089
|
+
return {
|
|
18090
|
+
held: true,
|
|
18091
|
+
reason: "heavy_reasoning",
|
|
18092
|
+
heavyStepsBack,
|
|
18093
|
+
heavyStepTokens,
|
|
18094
|
+
capPercentage
|
|
18095
|
+
};
|
|
18096
|
+
}
|
|
18097
|
+
|
|
17663
18098
|
// src/hooks/magic-context/temporal-served-projection.ts
|
|
17664
18099
|
function readLkgTemporalDecisions(db, sessionId, runtime) {
|
|
17665
18100
|
const slot = getInMemorySlot(sessionId) ?? loadPersistedLkgSlot(db, sessionId);
|
|
@@ -17883,7 +18318,7 @@ async function runCompartmentPhaseImpl(args) {
|
|
|
17883
18318
|
justAwaitedPublication = activeRun.published;
|
|
17884
18319
|
published = published || activeRun.published;
|
|
17885
18320
|
const historyReprepareShouldBust = activeRun.published && args.deferredHistoryRefreshSessions.has(args.sessionId);
|
|
17886
|
-
pendingCompartmentInjection = prepareCompartmentInjection(args.db, args.resolvedSessionId, args.messages, historyReprepareShouldBust, args.projectPath, args.injectionBudgetTokens, args.experimentalTemporalAwareness);
|
|
18321
|
+
pendingCompartmentInjection = prepareCompartmentInjection(args.db, args.resolvedSessionId, args.messages, historyReprepareShouldBust, args.coveredInstructions, args.projectPath, args.injectionBudgetTokens, args.experimentalTemporalAwareness);
|
|
17887
18322
|
if (historyReprepareShouldBust) {
|
|
17888
18323
|
rebuiltHistoryThisPass = true;
|
|
17889
18324
|
}
|
|
@@ -18174,7 +18609,8 @@ function createTransform(deps) {
|
|
|
18174
18609
|
const startTime = performance.now();
|
|
18175
18610
|
const historianRun = deps.resolveHistorianRun?.();
|
|
18176
18611
|
const messages = output.messages;
|
|
18177
|
-
const originalForThinkingFit = messages.some((message) => message.parts.some((part) => isRecord(part) && ["reasoning", "thinking", "redacted_thinking"].includes(String(part.type)))) ?
|
|
18612
|
+
const originalForThinkingFit = messages.some((message) => message.parts.some((part) => isRecord(part) && ["reasoning", "thinking", "redacted_thinking"].includes(String(part.type)))) ? cloneKeepingCoveredInstructionMarks(messages) : null;
|
|
18613
|
+
const coveredHostInstructions = takeCoveredInstructionRows(messages);
|
|
18178
18614
|
const passOutcome = createPassOutcome();
|
|
18179
18615
|
const tSessionId = performance.now();
|
|
18180
18616
|
const sessionId = findSessionId(messages);
|
|
@@ -18372,8 +18808,8 @@ function createTransform(deps) {
|
|
|
18372
18808
|
return true;
|
|
18373
18809
|
}
|
|
18374
18810
|
})();
|
|
18375
|
-
let activeThinkingPrefixHold =
|
|
18376
|
-
let freezeM0M1 = unresolvedDirectoryHold
|
|
18811
|
+
let activeThinkingPrefixHold = false;
|
|
18812
|
+
let freezeM0M1 = unresolvedDirectoryHold;
|
|
18377
18813
|
const compartmentDirectory = sessionDirectory;
|
|
18378
18814
|
const historianRunnable = deps.historianRunnable !== false;
|
|
18379
18815
|
const canRunCompartments = fullFeatureMode && !compactionOff && historianRunnable && (deps.client !== undefined || deps.hiddenCompletionExecutor !== undefined) && compartmentDirectory.length > 0;
|
|
@@ -18501,13 +18937,7 @@ function createTransform(deps) {
|
|
|
18501
18937
|
}
|
|
18502
18938
|
const resolvedProviderID = modelForBudget?.providerID;
|
|
18503
18939
|
activeThinkingTurn ||= hasActiveAnthropicThinkingTurn(messages, resolvedProviderID, modelForBudget?.modelID);
|
|
18504
|
-
|
|
18505
|
-
freezeM0M1 ||= activeThinkingPrefixHold;
|
|
18506
|
-
if (freezeM0M1 && prefixHoldLogTurnIds.get(sessionId) !== currentTurnId) {
|
|
18507
|
-
prefixHoldLogTurnIds.set(sessionId, currentTurnId);
|
|
18508
|
-
const reason = activeThinkingPrefixHold ? "active thinking turn (prefix-bound model)" : "session directory unresolved";
|
|
18509
|
-
sessionLog2(sessionId, `m[0]/m[1] frozen: ${reason}; replaying the frozen prefix and deferring any rebuild`);
|
|
18510
|
-
}
|
|
18940
|
+
const signedThinkingPrefixBound = activeThinkingTurn && (isPrefixBoundThinkingModel(activeThinkingModel?.providerID, activeThinkingModel?.modelID) || isPrefixBoundThinkingModel(resolvedProviderID, modelForBudget?.modelID));
|
|
18511
18941
|
const canUseEmptySentinels = modelAcceptsEmptyContent(resolvedProviderID);
|
|
18512
18942
|
const protectedThinkingMessages = activeThinkingTurn || isAnthropicFamilyRoute(resolvedProviderID, modelForBudget?.modelID) ? latestAssistantTurnMessages(messages) : new Set;
|
|
18513
18943
|
const resolvedContextLimit = modelForBudget ? resolveTrustedContextLimit(modelForBudget.providerID, modelForBudget.modelID, {
|
|
@@ -18561,6 +18991,29 @@ function createTransform(deps) {
|
|
|
18561
18991
|
const effectiveExecuteThresholdPercentage = executeThresholdDetail.percentage;
|
|
18562
18992
|
sessionLog2(sessionId, `transform threshold: model=${currentModelKeyForBoundary ?? "unknown"} matchedModel=${executeThresholdDetail.matchedKey ?? "scalar"} mode=${executeThresholdDetail.mode} threshold=${effectiveExecuteThresholdPercentage}% proactiveFloor=${getProactiveCompartmentTriggerPercentage(effectiveExecuteThresholdPercentage)}%`);
|
|
18563
18993
|
const { forceMaterializationPercentage } = escalationBands(effectiveExecuteThresholdPercentage);
|
|
18994
|
+
let holdProseRatio;
|
|
18995
|
+
const signedThinkingHold = signedThinkingPrefixBound ? decideSignedThinkingHold({
|
|
18996
|
+
messages,
|
|
18997
|
+
usagePercentage: contextUsageEarly.percentage,
|
|
18998
|
+
executeThresholdPercentage: effectiveExecuteThresholdPercentage,
|
|
18999
|
+
estimateTextTokens: (text) => {
|
|
19000
|
+
holdProseRatio ??= sessionDecisionCalibration(db, sessionId).proseRatio;
|
|
19001
|
+
return estimateTokens(text) * holdProseRatio;
|
|
19002
|
+
}
|
|
19003
|
+
}) : null;
|
|
19004
|
+
activeThinkingPrefixHold = signedThinkingPrefixBound && (compactionOff || signedThinkingHold?.held === true);
|
|
19005
|
+
freezeM0M1 ||= activeThinkingPrefixHold;
|
|
19006
|
+
const prefixHoldLogKey = signedThinkingHold ? `${currentTurnId}:${signedThinkingHold.reason}:${signedThinkingHold.heavyStepsBack ?? "none"}` : freezeM0M1 ? `${currentTurnId}:directory` : null;
|
|
19007
|
+
if (prefixHoldLogKey !== null && prefixHoldLogTurnIds.get(sessionId) !== prefixHoldLogKey) {
|
|
19008
|
+
prefixHoldLogTurnIds.set(sessionId, prefixHoldLogKey);
|
|
19009
|
+
if (signedThinkingHold) {
|
|
19010
|
+
sessionLog2(sessionId, `signed thinking hold: held=${signedThinkingHold.held} reason=${signedThinkingHold.reason} heavyStepsBack=${signedThinkingHold.heavyStepsBack ?? "none"} heavyStepTokens=${signedThinkingHold.heavyStepTokens} usage=${contextUsageEarly.percentage.toFixed(1)}% cap=${signedThinkingHold.capPercentage}%`);
|
|
19011
|
+
}
|
|
19012
|
+
if (freezeM0M1) {
|
|
19013
|
+
const reason = activeThinkingPrefixHold ? compactionOff ? "active thinking turn in compaction-off mode (prefix-bound model)" : "recent heavy reasoning in the active thinking turn (prefix-bound model)" : "session directory unresolved";
|
|
19014
|
+
sessionLog2(sessionId, `m[0]/m[1] frozen: ${reason}; replaying the frozen prefix and deferring any rebuild`);
|
|
19015
|
+
}
|
|
19016
|
+
}
|
|
18564
19017
|
const persistedUsageFreshForBoundary = persistedUsageBeforeResets && Date.now() - persistedUsageBeforeResets.updatedAt <= 10 * 60 * 1000 && (persistedUsageBeforeResets.lastObservedModelKey === null || currentModelKeyForBoundary === undefined || piModelRefToCanonical(persistedUsageBeforeResets.lastObservedModelKey) === piModelRefToCanonical(currentModelKeyForBoundary)) && (resolvedContextLimit === undefined || persistedUsageBeforeResets.lastUsageContextLimit === 0 || persistedUsageBeforeResets.lastUsageContextLimit === resolvedContextLimit) ? persistedUsageBeforeResets.usage : null;
|
|
18565
19018
|
const boundaryUsageForProtectedTail = persistedUsageFreshForBoundary ?? contextUsageEarly;
|
|
18566
19019
|
const boundaryUsageSource = persistedUsageFreshForBoundary ? "persisted" : "live";
|
|
@@ -18747,8 +19200,14 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
18747
19200
|
}, {
|
|
18748
19201
|
hardFold: false,
|
|
18749
19202
|
force: contextUsageEarly.percentage >= forceMaterializationPercentage && (contextUsageEarly.percentage >= 95 || getEmergencyInputSample(db, sessionId) === 0),
|
|
18750
|
-
explicitFlush: deps.pendingMaterializationSessions
|
|
18751
|
-
publishedHistory: isCacheBusting
|
|
19203
|
+
explicitFlush: hasPendingMaterializationOrigin(deps.pendingMaterializationSessions, sessionId, "user_flush"),
|
|
19204
|
+
publishedHistory: isCacheBusting,
|
|
19205
|
+
permission: {
|
|
19206
|
+
signedThinkingHold: activeThinkingPrefixHold,
|
|
19207
|
+
firstRender: false,
|
|
19208
|
+
idleExpiry: false,
|
|
19209
|
+
emergency: contextUsageEarly.percentage >= forceMaterializationPercentage
|
|
19210
|
+
}
|
|
18752
19211
|
}, pendingDropEligibility.read(sessionId, dropProjectionKey()));
|
|
18753
19212
|
if (triggerResult.shouldFire) {
|
|
18754
19213
|
sessionLog2(sessionId, `compartment trigger: firing (reason=${triggerResult.reason})`);
|
|
@@ -18768,7 +19227,7 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
18768
19227
|
const messagesBeforeInitialPrepare = isCacheBusting && deferredHistoryWasPendingAtPassStart ? [...messages] : null;
|
|
18769
19228
|
if (fullFeatureMode && !compactionOff) {
|
|
18770
19229
|
const tInj = performance.now();
|
|
18771
|
-
pendingCompartmentInjection = prepareCompartmentInjection(db, sessionId, messages, isCacheBusting, projectIdentity, deps.memoryConfig?.injectionBudgetTokens, deps.experimentalTemporalAwareness);
|
|
19230
|
+
pendingCompartmentInjection = prepareCompartmentInjection(db, sessionId, messages, isCacheBusting, coveredHostInstructions, projectIdentity, deps.memoryConfig?.injectionBudgetTokens, deps.experimentalTemporalAwareness);
|
|
18772
19231
|
if (messagesBeforeInitialPrepare) {
|
|
18773
19232
|
const skippedVisibleMessages = pendingCompartmentInjection?.skippedVisibleMessages ?? 0;
|
|
18774
19233
|
trimmedMessagesAtCompactionBoundary = messagesBeforeInitialPrepare.slice(0, skippedVisibleMessages);
|
|
@@ -18807,7 +19266,8 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
18807
19266
|
const tagged = tagMessages(sessionId, tail, deps.tagger, db, {
|
|
18808
19267
|
skipPrefixInjection: !ctxReduceCallable,
|
|
18809
19268
|
servedMessages: messages,
|
|
18810
|
-
normalizeRestoredAssistantText: deps.normalizeRestoredAssistantText
|
|
19269
|
+
normalizeRestoredAssistantText: deps.normalizeRestoredAssistantText,
|
|
19270
|
+
refreshSourceContents: deps.refreshSourceContents?.(sessionId)
|
|
18811
19271
|
});
|
|
18812
19272
|
for (const [number, target] of tagged.targets)
|
|
18813
19273
|
targets.set(number, target);
|
|
@@ -18832,7 +19292,8 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
18832
19292
|
skipPrefixInjection,
|
|
18833
19293
|
scopedToolSweep,
|
|
18834
19294
|
servedMessages: messages,
|
|
18835
|
-
normalizeRestoredAssistantText: deps.normalizeRestoredAssistantText
|
|
19295
|
+
normalizeRestoredAssistantText: deps.normalizeRestoredAssistantText,
|
|
19296
|
+
refreshSourceContents: deps.refreshSourceContents?.(sessionId)
|
|
18836
19297
|
});
|
|
18837
19298
|
targets = result.targets;
|
|
18838
19299
|
if (thinkingRecovery.restore)
|
|
@@ -18940,6 +19401,7 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
18940
19401
|
fallbackModels: historianRun?.fallbackModels ?? deps.fallbackModels,
|
|
18941
19402
|
compartmentDirectory,
|
|
18942
19403
|
messages,
|
|
19404
|
+
coveredInstructions: coveredHostInstructions,
|
|
18943
19405
|
pendingCompartmentInjection,
|
|
18944
19406
|
fallbackModelId,
|
|
18945
19407
|
projectPath: projectIdentity,
|
|
@@ -19011,30 +19473,53 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
19011
19473
|
bustReason: calibrationBustReason,
|
|
19012
19474
|
onAdopt: (message) => sessionLog2(sessionId, message)
|
|
19013
19475
|
});
|
|
19476
|
+
let contextUsageFromEstimate = false;
|
|
19014
19477
|
if (contextUsage.inputTokens <= 0 && protectionCacheBustingPass) {
|
|
19478
|
+
const overflowRecoveryPass = usagePercentageSynthetic || emergencyRecoveryArmed;
|
|
19479
|
+
const savedProviderReading = overflowRecoveryPass ? null : savedProviderReadingForPass({
|
|
19480
|
+
persisted: persistedUsageBeforeResets,
|
|
19481
|
+
currentModelKey: currentModelKeyForBoundary ?? (hardModelKey || undefined),
|
|
19482
|
+
contextLimit: resolvedContextLimit,
|
|
19483
|
+
lastResponseTime: sessionMeta.lastResponseTime,
|
|
19484
|
+
cacheExpired: hardCacheExpired
|
|
19485
|
+
});
|
|
19486
|
+
let pressureEstimate;
|
|
19015
19487
|
try {
|
|
19016
|
-
|
|
19488
|
+
pressureEstimate = estimateFinalWireInputTokens({
|
|
19017
19489
|
messages,
|
|
19018
19490
|
systemPromptTokens: sessionMeta.systemPromptTokens,
|
|
19019
19491
|
providerID: modelForBudget?.providerID,
|
|
19020
19492
|
modelID: modelForBudget?.modelID,
|
|
19021
19493
|
agentName: notificationParams.agent
|
|
19022
19494
|
});
|
|
19495
|
+
} catch (error) {
|
|
19496
|
+
sessionLog2(sessionId, `transform: wire-estimate pressure fallback unavailable: ${getErrorMessage(error)}`);
|
|
19497
|
+
}
|
|
19498
|
+
const usableHard = windowGeometry?.usableHard;
|
|
19499
|
+
const countPercentage = pressureEstimate?.pressureTokens !== undefined && Number.isFinite(pressureEstimate.pressureTokens) && typeof usableHard === "number" && usableHard > 0 ? pressureEstimate.pressureTokens / usableHard * 100 : 0;
|
|
19500
|
+
const grewPastSavedReading = savedProviderReading !== null && countPercentage >= 95 && countPercentage > savedProviderReading.percentage;
|
|
19501
|
+
if (savedProviderReading && !grewPastSavedReading) {
|
|
19502
|
+
contextUsage = {
|
|
19503
|
+
inputTokens: savedProviderReading.inputTokens,
|
|
19504
|
+
percentage: Math.max(contextUsage.percentage, savedProviderReading.percentage)
|
|
19505
|
+
};
|
|
19506
|
+
sessionLog2(sessionId, `transform: unknown provider usage; using saved provider reading for priced pass inputTokens=${contextUsage.inputTokens} percentage=${contextUsage.percentage.toFixed(1)} countPercentage=${countPercentage.toFixed(1)}`);
|
|
19507
|
+
} else if (pressureEstimate) {
|
|
19508
|
+
const percentageBeforeEstimate = contextUsage.percentage;
|
|
19023
19509
|
contextUsage = resolveUnknownUsageFromWireEstimate({
|
|
19024
19510
|
usage: contextUsage,
|
|
19025
19511
|
pricedPass: true,
|
|
19026
|
-
wireEstimateTokens: pressureEstimate.tokens,
|
|
19512
|
+
wireEstimateTokens: overflowRecoveryPass ? pressureEstimate.tokens : pressureEstimate.pressureTokens,
|
|
19027
19513
|
wireEstimateTrusted: pressureEstimate.trusted,
|
|
19028
19514
|
providerProvenInputTokens: providerProvenInputForRecovery,
|
|
19029
19515
|
providerProvenLimitTokens: providerProvenLimitForRecovery,
|
|
19030
|
-
usableHardLimit:
|
|
19516
|
+
usableHardLimit: usableHard
|
|
19031
19517
|
});
|
|
19032
19518
|
if (contextUsage.inputTokens > 0) {
|
|
19033
19519
|
const usedProviderInput = !pressureEstimate.trusted && providerProvenLimitForRecovery !== undefined && providerProvenInputForRecovery !== undefined && contextUsage.inputTokens >= providerProvenInputForRecovery;
|
|
19034
|
-
|
|
19520
|
+
contextUsageFromEstimate = !overflowRecoveryPass && !usedProviderInput && !usagePercentageSynthetic && contextUsage.percentage > percentageBeforeEstimate;
|
|
19521
|
+
sessionLog2(sessionId, `transform: unknown provider usage; using ${usedProviderInput ? "provider-proven input" : "wire estimate"} for priced pass inputTokens=${contextUsage.inputTokens} percentage=${contextUsage.percentage.toFixed(1)} trusted=${pressureEstimate.trusted} wireTokens=${pressureEstimate.tokens} pressureTokens=${pressureEstimate.pressureTokens}${grewPastSavedReading ? ` grewPastSavedReading=${savedProviderReading?.percentage.toFixed(1)}` : ""}`);
|
|
19035
19522
|
}
|
|
19036
|
-
} catch (error) {
|
|
19037
|
-
sessionLog2(sessionId, `transform: wire-estimate pressure fallback unavailable: ${getErrorMessage(error)}`);
|
|
19038
19523
|
}
|
|
19039
19524
|
}
|
|
19040
19525
|
const protectionUsableSoft = windowGeometry?.usableSoft ?? boundaryContextLimit;
|
|
@@ -19075,6 +19560,7 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
19075
19560
|
activeAgent,
|
|
19076
19561
|
batch,
|
|
19077
19562
|
contextUsage,
|
|
19563
|
+
contextUsageFromEstimate,
|
|
19078
19564
|
usableWindow: resolvedContextLimit ?? 0,
|
|
19079
19565
|
schedulerDecision,
|
|
19080
19566
|
schedulerDeferReason,
|
|
@@ -19120,6 +19606,7 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
19120
19606
|
emergencyCeilingTokens,
|
|
19121
19607
|
pendingCompartmentInjection,
|
|
19122
19608
|
prefixTrimSourceOrder,
|
|
19609
|
+
coveredHostInstructions,
|
|
19123
19610
|
hiddenMessagesAtCompactionSeam,
|
|
19124
19611
|
trimmedMessagesAtCompactionBoundary,
|
|
19125
19612
|
didMutateFromFlushedStatuses,
|
|
@@ -19320,7 +19807,7 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
19320
19807
|
if (!finalWireEstimate) {
|
|
19321
19808
|
sessionLog2(sessionId, `transform: final-wire telemetry estimate=unavailable trusted=false conversation=unknown tools=unknown system=unknown toolDefinitions=unknown tail=${finalWireTail}`);
|
|
19322
19809
|
}
|
|
19323
|
-
finishSystemDateRefresh(deps.historyRefreshSessions, dateRequest, postTransformResult.bustedThisPass && !activeThinkingPrefixHold || postTransformResult.thinkingReleasedForFit === true);
|
|
19810
|
+
finishSystemDateRefresh(deps.historyRefreshSessions, dateRequest, postTransformResult.bustedThisPass && !activeThinkingPrefixHold && postTransformResult.openTurnSignedThinkingKept !== true || postTransformResult.thinkingReleasedForFit === true);
|
|
19324
19811
|
if (activeThinkingPrefixHold && !postTransformResult.thinkingReleasedForFit && sessionMeta.cachedM0Bytes != null && sessionMeta.cachedM1Bytes != null) {
|
|
19325
19812
|
recordHeldHeadForRequest(sessionId, currentLkgRequestIdentity(sessionId), (ownsHistory) => deferDeliveredSystemRefresh(deps, sessionId, ownsHistory));
|
|
19326
19813
|
}
|
|
@@ -19421,7 +19908,7 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
19421
19908
|
});
|
|
19422
19909
|
if (uncachedMessageIds.length > 0) {
|
|
19423
19910
|
try {
|
|
19424
|
-
storedByMessage = getActiveTagTokenTotalsByMessage2(db, sessionId, uncachedMessageIds);
|
|
19911
|
+
storedByMessage = omitIncompleteFileTokenTotals(db, sessionId, messages.flatMap((message) => message.info.id ? [{ id: message.info.id, parts: message.parts }] : []), getActiveTagTokenTotalsByMessage2(db, sessionId, uncachedMessageIds));
|
|
19425
19912
|
} catch {
|
|
19426
19913
|
storedByMessage = new Map;
|
|
19427
19914
|
}
|
|
@@ -19516,7 +20003,8 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
19516
20003
|
systemPromptHash: sessionMeta.systemPromptHash
|
|
19517
20004
|
});
|
|
19518
20005
|
};
|
|
19519
|
-
|
|
20006
|
+
const timedTransform = (input, output) => withTransformTimingSummary(() => transform(input, output));
|
|
20007
|
+
return Object.assign(timedTransform, {
|
|
19520
20008
|
clearSessionLogState,
|
|
19521
20009
|
invalidateRustWireState(sessionId) {
|
|
19522
20010
|
rustModeTransform?.invalidateWireState(sessionId);
|
|
@@ -21183,7 +21671,7 @@ function computeOpenCodeWorkMetricsIncremental(openCodeDb, sessionId, carry) {
|
|
|
21183
21671
|
import { readFileSync, statSync } from "node:fs";
|
|
21184
21672
|
|
|
21185
21673
|
// src/plugin/embedding-bootstrap-helpers.ts
|
|
21186
|
-
import { createHash as
|
|
21674
|
+
import { createHash as createHash6 } from "node:crypto";
|
|
21187
21675
|
var EMBEDDING_AFFECTING_KEYS = new Set([
|
|
21188
21676
|
"embedding.api_key",
|
|
21189
21677
|
"embedding.endpoint",
|
|
@@ -21231,7 +21719,7 @@ var EMBEDDING_WARNING_TERMS = [
|
|
|
21231
21719
|
];
|
|
21232
21720
|
var loggedFailureSignatures = new Map;
|
|
21233
21721
|
function sha256Prefix(value, length = 16) {
|
|
21234
|
-
return
|
|
21722
|
+
return createHash6("sha256").update(value).digest("hex").slice(0, length);
|
|
21235
21723
|
}
|
|
21236
21724
|
function warningLooksEmbeddingRelated(message) {
|
|
21237
21725
|
const lower = message.toLowerCase();
|
|
@@ -22738,8 +23226,8 @@ function registerRpcHandlers(rpcServer, args) {
|
|
|
22738
23226
|
const db = readDatabase();
|
|
22739
23227
|
if (!db)
|
|
22740
23228
|
return { ok: false, error: "db unavailable" };
|
|
22741
|
-
const { runManagedRecomp } = await importPluginModule(() => import("./recomp-orchestrator-
|
|
22742
|
-
const { sendIgnoredMessage } = await importPluginModule(() => import("./send-session-notification-
|
|
23229
|
+
const { runManagedRecomp } = await importPluginModule(() => import("./recomp-orchestrator-4vfxej9t.js"));
|
|
23230
|
+
const { sendIgnoredMessage } = await importPluginModule(() => import("./send-session-notification-3pxn658x.js"));
|
|
22743
23231
|
log2(`[rpc] recomp requested for session ${sessionId}`);
|
|
22744
23232
|
if (!args.client && !args.hiddenCompletionExecutor) {
|
|
22745
23233
|
return {
|
|
@@ -22823,7 +23311,7 @@ function registerRpcHandlers(rpcServer, args) {
|
|
|
22823
23311
|
const db = readDatabase();
|
|
22824
23312
|
if (!db)
|
|
22825
23313
|
return { ok: false, error: "db unavailable" };
|
|
22826
|
-
const { runManagedWrapup } = await importPluginModule(() => import("./wrapup-orchestrator-
|
|
23314
|
+
const { runManagedWrapup } = await importPluginModule(() => import("./wrapup-orchestrator-psqz7yh0.js"));
|
|
22827
23315
|
const model = liveSessionState.liveModelBySession.get(sessionId);
|
|
22828
23316
|
const contextLimit = model ? resolveContextLimit(model.providerID, model.modelID, { db, sessionID: sessionId }) : 128000;
|
|
22829
23317
|
const ctx = {
|
|
@@ -23195,7 +23683,58 @@ function readOmoDisabledHooks(directory) {
|
|
|
23195
23683
|
|
|
23196
23684
|
// src/shared/rpc-server.ts
|
|
23197
23685
|
import { randomBytes, timingSafeEqual } from "node:crypto";
|
|
23198
|
-
import { readdirSync, readFileSync as readFileSync4, unlinkSync } from "node:fs";
|
|
23686
|
+
import { readdirSync, readFileSync as readFileSync4, rmdirSync, unlinkSync } from "node:fs";
|
|
23687
|
+
|
|
23688
|
+
// src/shared/rpc-discovery-cleanup.ts
|
|
23689
|
+
import { promises as fs } from "node:fs";
|
|
23690
|
+
import { join as join6 } from "node:path";
|
|
23691
|
+
async function reapDeadRpcDiscovery(storageDir) {
|
|
23692
|
+
const root = join6(storageDir, "rpc");
|
|
23693
|
+
let directories;
|
|
23694
|
+
try {
|
|
23695
|
+
directories = await fs.readdir(root, { withFileTypes: true });
|
|
23696
|
+
} catch {
|
|
23697
|
+
return;
|
|
23698
|
+
}
|
|
23699
|
+
const records = [];
|
|
23700
|
+
const projectDirs = [];
|
|
23701
|
+
for (const entry of directories) {
|
|
23702
|
+
if (!entry.isDirectory() || !/^[0-9a-f]{16}$/.test(entry.name))
|
|
23703
|
+
continue;
|
|
23704
|
+
const directory = join6(root, entry.name);
|
|
23705
|
+
projectDirs.push(directory);
|
|
23706
|
+
try {
|
|
23707
|
+
for (const name of await fs.readdir(directory)) {
|
|
23708
|
+
const match = /^port-(\d+)(?:-[0-9a-f]+)?\.json$/.exec(name);
|
|
23709
|
+
if (!match)
|
|
23710
|
+
continue;
|
|
23711
|
+
const path = join6(directory, name);
|
|
23712
|
+
try {
|
|
23713
|
+
const content = await fs.readFile(path, "utf8");
|
|
23714
|
+
const record = parseRpcPortFile(content, Number(match[1]));
|
|
23715
|
+
if (record && record.pid === Number(match[1]))
|
|
23716
|
+
records.push({ path, content, pid: record.pid });
|
|
23717
|
+
} catch {}
|
|
23718
|
+
}
|
|
23719
|
+
} catch {}
|
|
23720
|
+
}
|
|
23721
|
+
const processes = records.length ? await inspectProcessesAsync(true) : undefined;
|
|
23722
|
+
for (const record of records) {
|
|
23723
|
+
if (processes?.liveness(record.pid) !== "dead")
|
|
23724
|
+
continue;
|
|
23725
|
+
try {
|
|
23726
|
+
if (await fs.readFile(record.path, "utf8") === record.content)
|
|
23727
|
+
await fs.unlink(record.path);
|
|
23728
|
+
} catch {}
|
|
23729
|
+
}
|
|
23730
|
+
for (const directory of projectDirs) {
|
|
23731
|
+
try {
|
|
23732
|
+
await fs.rmdir(directory);
|
|
23733
|
+
} catch {}
|
|
23734
|
+
}
|
|
23735
|
+
}
|
|
23736
|
+
|
|
23737
|
+
// src/shared/rpc-server.ts
|
|
23199
23738
|
var MAX_BODY_BYTES = 1048576;
|
|
23200
23739
|
var WS_AUTH_TIMEOUT_MS = 5000;
|
|
23201
23740
|
var WS_CLOSE_UNAUTHORIZED = 4401;
|
|
@@ -23218,17 +23757,20 @@ function websocketToken(req) {
|
|
|
23218
23757
|
}
|
|
23219
23758
|
|
|
23220
23759
|
class MagicContextRpcServer {
|
|
23760
|
+
storageDir;
|
|
23221
23761
|
server = null;
|
|
23222
23762
|
port = 0;
|
|
23223
23763
|
handlers = new Map;
|
|
23224
23764
|
portFilePath;
|
|
23225
23765
|
portDir;
|
|
23226
23766
|
startedAt = Date.now();
|
|
23767
|
+
stopped = false;
|
|
23227
23768
|
instanceId = randomBytes(8).toString("hex");
|
|
23228
23769
|
unregisterOwnInstance = null;
|
|
23229
23770
|
sockets = new Set;
|
|
23230
23771
|
token = randomBytes(32).toString("hex");
|
|
23231
23772
|
constructor(storageDir, directory) {
|
|
23773
|
+
this.storageDir = storageDir;
|
|
23232
23774
|
this.portFilePath = rpcPortFilePath(storageDir, directory, process.pid, this.instanceId);
|
|
23233
23775
|
this.portDir = rpcPortDir(storageDir, directory);
|
|
23234
23776
|
}
|
|
@@ -23246,6 +23788,10 @@ class MagicContextRpcServer {
|
|
|
23246
23788
|
log2("rpc server skipped: Bun runtime not available (no TUI consumer)");
|
|
23247
23789
|
return 0;
|
|
23248
23790
|
}
|
|
23791
|
+
this.stopped = false;
|
|
23792
|
+
await reapDeadRpcDiscovery(this.storageDir);
|
|
23793
|
+
if (this.stopped)
|
|
23794
|
+
return 0;
|
|
23249
23795
|
this.startedAt = Date.now();
|
|
23250
23796
|
const self = this;
|
|
23251
23797
|
const server = inRootAsyncContext2(() => Bun.serve({
|
|
@@ -23277,7 +23823,7 @@ class MagicContextRpcServer {
|
|
|
23277
23823
|
try {
|
|
23278
23824
|
this.warnIfOtherLiveInstance();
|
|
23279
23825
|
this.unregisterOwnInstance ??= registerOwnRpcServerInstance(this.instanceId);
|
|
23280
|
-
writeStorageFileAtomicSync(this.portFilePath, JSON.stringify({
|
|
23826
|
+
const publish = () => writeStorageFileAtomicSync(this.portFilePath, JSON.stringify({
|
|
23281
23827
|
port: this.port,
|
|
23282
23828
|
pid: process.pid,
|
|
23283
23829
|
started_at: this.startedAt,
|
|
@@ -23285,6 +23831,13 @@ class MagicContextRpcServer {
|
|
|
23285
23831
|
token: this.token,
|
|
23286
23832
|
instance_id: this.instanceId
|
|
23287
23833
|
}));
|
|
23834
|
+
try {
|
|
23835
|
+
publish();
|
|
23836
|
+
} catch (error) {
|
|
23837
|
+
if (error.code !== "ENOENT")
|
|
23838
|
+
throw error;
|
|
23839
|
+
publish();
|
|
23840
|
+
}
|
|
23288
23841
|
log2(`[rpc] server listening on 127.0.0.1:${this.port}`);
|
|
23289
23842
|
} catch (err) {
|
|
23290
23843
|
log2(`[rpc] failed to write port file: ${err}`);
|
|
@@ -23292,6 +23845,7 @@ class MagicContextRpcServer {
|
|
|
23292
23845
|
return this.port;
|
|
23293
23846
|
}
|
|
23294
23847
|
stop() {
|
|
23848
|
+
this.stopped = true;
|
|
23295
23849
|
for (const ws of this.sockets) {
|
|
23296
23850
|
try {
|
|
23297
23851
|
if (ws.data.authTimer)
|
|
@@ -23308,6 +23862,9 @@ class MagicContextRpcServer {
|
|
|
23308
23862
|
try {
|
|
23309
23863
|
unlinkSync(this.portFilePath);
|
|
23310
23864
|
} catch {}
|
|
23865
|
+
try {
|
|
23866
|
+
rmdirSync(this.portDir);
|
|
23867
|
+
} catch {}
|
|
23311
23868
|
this.unregisterOwnInstance?.();
|
|
23312
23869
|
this.unregisterOwnInstance = null;
|
|
23313
23870
|
}
|
|
@@ -23812,8 +24369,8 @@ function hostMediaFromEncoded(value) {
|
|
|
23812
24369
|
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
23813
24370
|
|
|
23814
24371
|
// src/v2/fold/owner.ts
|
|
23815
|
-
import { createHash as
|
|
23816
|
-
var foldDigest = (value) =>
|
|
24372
|
+
import { createHash as createHash7 } from "node:crypto";
|
|
24373
|
+
var foldDigest = (value) => createHash7("sha256").update(value).digest("hex");
|
|
23817
24374
|
|
|
23818
24375
|
class FoldOwner {
|
|
23819
24376
|
storage;
|
|
@@ -24376,6 +24933,8 @@ function adaptPayload(draft, admittedIDs = new Set, messageTimes = new Map) {
|
|
|
24376
24933
|
parts
|
|
24377
24934
|
};
|
|
24378
24935
|
originals.set(mapped, message);
|
|
24936
|
+
if (isCoveredInstructionRow(message))
|
|
24937
|
+
markCoveredInstructionRow(mapped.info);
|
|
24379
24938
|
if (typeof message.id !== "string")
|
|
24380
24939
|
bridgesByCarrier.set(mapped, byCallID);
|
|
24381
24940
|
messages.push(mapped);
|
|
@@ -24732,24 +25291,31 @@ ${data.output?.output ?? ""}`
|
|
|
24732
25291
|
const sameModel = sameProvider && previousModel?.id === model.id;
|
|
24733
25292
|
const reuse = sameModel && data.error === undefined;
|
|
24734
25293
|
const metadata = (state) => state === undefined ? undefined : { [model.providerID]: state };
|
|
25294
|
+
const reasoningInterrupted = data.content?.some((part) => part.type === "reasoning" && part.time !== undefined && part.time.completed === undefined);
|
|
24735
25295
|
const content = [];
|
|
24736
25296
|
const results = [];
|
|
24737
25297
|
for (const part of data.content ?? []) {
|
|
25298
|
+
let native = "native" in part ? part.native : part.type === "tool" ? part.providerState : part.state;
|
|
25299
|
+
if (part.type === "tool" && part.providerResultState !== null && typeof part.providerResultState === "object" && !Array.isArray(part.providerResultState))
|
|
25300
|
+
native = {
|
|
25301
|
+
...native !== null && typeof native === "object" && !Array.isArray(native) ? native : {},
|
|
25302
|
+
...part.providerResultState
|
|
25303
|
+
};
|
|
24738
25304
|
if (part.type === "text") {
|
|
24739
25305
|
if (part.text !== "")
|
|
24740
25306
|
content.push({
|
|
24741
25307
|
type: "text",
|
|
24742
25308
|
text: part.text,
|
|
24743
|
-
providerMetadata: reuse ? metadata(
|
|
25309
|
+
providerMetadata: reuse ? metadata(native) : undefined
|
|
24744
25310
|
});
|
|
24745
25311
|
continue;
|
|
24746
25312
|
}
|
|
24747
25313
|
if (part.type === "reasoning") {
|
|
24748
|
-
if (part.text !== "" || reuse &&
|
|
25314
|
+
if (part.text !== "" || reuse && !reasoningInterrupted && native !== undefined)
|
|
24749
25315
|
content.push({
|
|
24750
|
-
type:
|
|
25316
|
+
type: data.error === undefined && !reasoningInterrupted ? "reasoning" : "text",
|
|
24751
25317
|
text: part.text,
|
|
24752
|
-
providerMetadata: reuse ? metadata(
|
|
25318
|
+
providerMetadata: reuse && !reasoningInterrupted ? metadata(native) : undefined
|
|
24753
25319
|
});
|
|
24754
25320
|
continue;
|
|
24755
25321
|
}
|
|
@@ -24768,7 +25334,7 @@ ${data.output?.output ?? ""}`
|
|
|
24768
25334
|
name: part.name,
|
|
24769
25335
|
input,
|
|
24770
25336
|
providerExecuted: part.executed,
|
|
24771
|
-
providerMetadata: toolReuse ? metadata(
|
|
25337
|
+
providerMetadata: toolReuse ? metadata(native) : undefined
|
|
24772
25338
|
});
|
|
24773
25339
|
if (!completed)
|
|
24774
25340
|
continue;
|
|
@@ -24779,7 +25345,7 @@ ${data.output?.output ?? ""}`
|
|
|
24779
25345
|
id: part.id,
|
|
24780
25346
|
name: part.name,
|
|
24781
25347
|
providerExecuted: part.executed,
|
|
24782
|
-
providerMetadata:
|
|
25348
|
+
providerMetadata: (part.executed === true ? sameProvider : reuse) ? metadata(native) : undefined,
|
|
24783
25349
|
result: state.status === "error" ? { error: state.error, content: toolContent } : single?.type === "text" ? { type: "text", value: single.text } : { type: "content", value: toolContent },
|
|
24784
25350
|
...state.status === "error" ? { resultType: "error" } : {}
|
|
24785
25351
|
};
|
|
@@ -24807,13 +25373,50 @@ function copyNativeInput(messages) {
|
|
|
24807
25373
|
return copies;
|
|
24808
25374
|
}
|
|
24809
25375
|
function isLocalCheckpoint(row) {
|
|
24810
|
-
return row.type === "compaction" && row.data.status === "completed" && row.data.providerContext === undefined;
|
|
25376
|
+
return row.type === "compaction" && row.data.status === "completed" && row.data.providerContext === undefined && row.data.native?.messages === undefined;
|
|
25377
|
+
}
|
|
25378
|
+
function isAdmittedLocalCheckpoint(storage, sessionID, cut) {
|
|
25379
|
+
if (!isLocalCheckpoint(cut) || cut.session_id !== sessionID)
|
|
25380
|
+
return false;
|
|
25381
|
+
const admission = storage.admission(sessionID, cut.id);
|
|
25382
|
+
if (!admission?.payload || admission.digest !== foldDigest(admission.payload))
|
|
25383
|
+
return false;
|
|
25384
|
+
try {
|
|
25385
|
+
const snapshot = JSON.parse(admission.payload);
|
|
25386
|
+
return snapshot.source === storage.sourceID && snapshot.sessionID === sessionID && snapshot.admissionID === cut.id && snapshot.summary === cut.data.summary;
|
|
25387
|
+
} catch {
|
|
25388
|
+
return false;
|
|
25389
|
+
}
|
|
24811
25390
|
}
|
|
24812
25391
|
var conversational = (row) => RAW_MESSAGE_TYPES.includes(row.type) || row.type === "location-switched";
|
|
25392
|
+
var historyDigest = (reader, sessionID, through) => foldDigest(JSON.stringify(reader.range(sessionID, -1, through).filter(conversational)));
|
|
25393
|
+
var admissionKey = (sessionID) => `native-fold/v2/${encodeURIComponent(sessionID)}`;
|
|
25394
|
+
async function forgetNativeFoldProvenance(storage, sessionID, legacyOnly = false) {
|
|
25395
|
+
const remove = async (key) => {
|
|
25396
|
+
if (storage.remove)
|
|
25397
|
+
await storage.remove(key);
|
|
25398
|
+
else
|
|
25399
|
+
await storage.set(key, null);
|
|
25400
|
+
};
|
|
25401
|
+
if (!legacyOnly)
|
|
25402
|
+
await remove(admissionKey(sessionID));
|
|
25403
|
+
if (!storage.scan)
|
|
25404
|
+
return;
|
|
25405
|
+
let after;
|
|
25406
|
+
do {
|
|
25407
|
+
const page = await storage.scan({ prefix: "native-fold/v1/", after, limit: 100 });
|
|
25408
|
+
for (const { key } of page.entries) {
|
|
25409
|
+
if (key.slice("native-fold/v1/".length).split("/").slice(1).join("/") === sessionID)
|
|
25410
|
+
await remove(key);
|
|
25411
|
+
}
|
|
25412
|
+
after = page.next;
|
|
25413
|
+
} while (after);
|
|
25414
|
+
}
|
|
24813
25415
|
|
|
24814
25416
|
class NativeFoldReplay {
|
|
24815
25417
|
storage;
|
|
24816
25418
|
openReader;
|
|
25419
|
+
admissions;
|
|
24817
25420
|
changed = new Set;
|
|
24818
25421
|
dirty = new Set;
|
|
24819
25422
|
unavailable = new Set;
|
|
@@ -24821,9 +25424,11 @@ class NativeFoldReplay {
|
|
|
24821
25424
|
metadataThrough = new Map;
|
|
24822
25425
|
loaded = new Map;
|
|
24823
25426
|
sources = new Map;
|
|
24824
|
-
|
|
25427
|
+
staleHeads = new Set;
|
|
25428
|
+
constructor(storage, openReader, admissions) {
|
|
24825
25429
|
this.storage = storage;
|
|
24826
25430
|
this.openReader = openReader;
|
|
25431
|
+
this.admissions = admissions;
|
|
24827
25432
|
storage.onEvict((sessionID) => this.clear(sessionID));
|
|
24828
25433
|
}
|
|
24829
25434
|
account(sessionID) {
|
|
@@ -24862,6 +25467,51 @@ class NativeFoldReplay {
|
|
|
24862
25467
|
async baseline(sessionID) {
|
|
24863
25468
|
return this.tail(sessionID)?.baseline;
|
|
24864
25469
|
}
|
|
25470
|
+
admissionKey(sessionID) {
|
|
25471
|
+
return admissionKey(sessionID);
|
|
25472
|
+
}
|
|
25473
|
+
async removeAdmission(key) {
|
|
25474
|
+
if (this.admissions?.remove)
|
|
25475
|
+
await this.admissions.remove(key);
|
|
25476
|
+
else
|
|
25477
|
+
await this.admissions?.set(key, null);
|
|
25478
|
+
}
|
|
25479
|
+
async removeLegacyAdmissions(sessionID) {
|
|
25480
|
+
if (this.admissions)
|
|
25481
|
+
await forgetNativeFoldProvenance(this.admissions, sessionID, true);
|
|
25482
|
+
}
|
|
25483
|
+
async admits(sessionID, cut, reader) {
|
|
25484
|
+
if (!isLocalCheckpoint(cut) || cut.session_id !== sessionID)
|
|
25485
|
+
return false;
|
|
25486
|
+
if (isAdmittedLocalCheckpoint(this.storage, sessionID, cut))
|
|
25487
|
+
return true;
|
|
25488
|
+
if (!this.admissions)
|
|
25489
|
+
return false;
|
|
25490
|
+
try {
|
|
25491
|
+
const source = reader.hostIdentity();
|
|
25492
|
+
const saved = await this.admissions.get(this.admissionKey(sessionID));
|
|
25493
|
+
if (!saved?.payload || saved.digest !== foldDigest(saved.payload))
|
|
25494
|
+
return false;
|
|
25495
|
+
const snapshot = JSON.parse(saved.payload);
|
|
25496
|
+
if (snapshot.sourceDigest !== foldDigest(source) || snapshot.sessionID !== sessionID || snapshot.admissionID !== cut.id || snapshot.summaryDigest !== foldDigest(cut.data.summary ?? ""))
|
|
25497
|
+
return false;
|
|
25498
|
+
if (snapshot.historyDigest !== historyDigest(reader, sessionID, cut.seq - 1)) {
|
|
25499
|
+
this.staleHeads.add(sessionID);
|
|
25500
|
+
this.invalidate(sessionID);
|
|
25501
|
+
await this.removeAdmission(this.admissionKey(sessionID));
|
|
25502
|
+
return false;
|
|
25503
|
+
}
|
|
25504
|
+
await this.storage.supply(sessionID, cut.id, JSON.stringify({
|
|
25505
|
+
source: this.storage.sourceID,
|
|
25506
|
+
sessionID,
|
|
25507
|
+
admissionID: cut.id,
|
|
25508
|
+
summary: cut.data.summary
|
|
25509
|
+
}));
|
|
25510
|
+
return true;
|
|
25511
|
+
} catch {
|
|
25512
|
+
return false;
|
|
25513
|
+
}
|
|
25514
|
+
}
|
|
24865
25515
|
rendered(row, model) {
|
|
24866
25516
|
return restoreRow(row, model, hostUsesMediaAssets() ? {
|
|
24867
25517
|
asset: hostMediaAsset,
|
|
@@ -24939,6 +25589,7 @@ class NativeFoldReplay {
|
|
|
24939
25589
|
this.loaded.set(draft.sessionID, through);
|
|
24940
25590
|
this.unavailable.delete(draft.sessionID);
|
|
24941
25591
|
this.changed.delete(draft.sessionID);
|
|
25592
|
+
this.staleHeads.delete(draft.sessionID);
|
|
24942
25593
|
} finally {
|
|
24943
25594
|
reader.close();
|
|
24944
25595
|
}
|
|
@@ -24965,7 +25616,8 @@ class NativeFoldReplay {
|
|
|
24965
25616
|
async supplyHeld(args) {
|
|
24966
25617
|
const { draft, reader, summary } = args;
|
|
24967
25618
|
const tail = this.tail(draft.sessionID);
|
|
24968
|
-
const
|
|
25619
|
+
const running = reader.latestRunningCompaction(draft.sessionID);
|
|
25620
|
+
const id = running?.id;
|
|
24969
25621
|
if (!id || !tail || tail.model !== `${draft.model.providerID}/${draft.model.id}`)
|
|
24970
25622
|
return false;
|
|
24971
25623
|
const through = reader.latestSequence(draft.sessionID);
|
|
@@ -24989,6 +25641,21 @@ class NativeFoldReplay {
|
|
|
24989
25641
|
summary
|
|
24990
25642
|
};
|
|
24991
25643
|
await this.storage.supply(draft.sessionID, id, JSON.stringify(snapshot));
|
|
25644
|
+
if (this.admissions) {
|
|
25645
|
+
const provenance = {
|
|
25646
|
+
sourceDigest: foldDigest(reader.hostIdentity()),
|
|
25647
|
+
sessionID: draft.sessionID,
|
|
25648
|
+
admissionID: id,
|
|
25649
|
+
summaryDigest: foldDigest(summary),
|
|
25650
|
+
historyDigest: historyDigest(reader, draft.sessionID, (running?.seq ?? through) - 1)
|
|
25651
|
+
};
|
|
25652
|
+
const payload = JSON.stringify(provenance);
|
|
25653
|
+
await this.admissions.set(this.admissionKey(draft.sessionID), {
|
|
25654
|
+
payload,
|
|
25655
|
+
digest: foldDigest(payload)
|
|
25656
|
+
});
|
|
25657
|
+
await this.removeLegacyAdmissions(draft.sessionID);
|
|
25658
|
+
}
|
|
24992
25659
|
return true;
|
|
24993
25660
|
}
|
|
24994
25661
|
async restore(sessionID, cut, model, options = {}) {
|
|
@@ -25073,6 +25740,9 @@ class NativeFoldReplay {
|
|
|
25073
25740
|
sourceChanged(sessionID) {
|
|
25074
25741
|
return this.changed.has(sessionID);
|
|
25075
25742
|
}
|
|
25743
|
+
needsHeadRebuild(sessionID) {
|
|
25744
|
+
return this.staleHeads.has(sessionID);
|
|
25745
|
+
}
|
|
25076
25746
|
clear(sessionID) {
|
|
25077
25747
|
this.sources.delete(sessionID);
|
|
25078
25748
|
this.metadata.delete(sessionID);
|
|
@@ -25081,8 +25751,11 @@ class NativeFoldReplay {
|
|
|
25081
25751
|
this.unavailable.delete(sessionID);
|
|
25082
25752
|
this.dirty.delete(sessionID);
|
|
25083
25753
|
this.changed.delete(sessionID);
|
|
25754
|
+
this.staleHeads.delete(sessionID);
|
|
25084
25755
|
}
|
|
25085
25756
|
async forget(sessionID) {
|
|
25757
|
+
if (this.admissions)
|
|
25758
|
+
await forgetNativeFoldProvenance(this.admissions, sessionID);
|
|
25086
25759
|
await this.storage.forget(sessionID);
|
|
25087
25760
|
}
|
|
25088
25761
|
}
|
|
@@ -25097,11 +25770,7 @@ class HostFoldPolicy {
|
|
|
25097
25770
|
this.deps = deps;
|
|
25098
25771
|
}
|
|
25099
25772
|
owned(sessionID, cut, id) {
|
|
25100
|
-
|
|
25101
|
-
if (!isLocalCheckpoint(cut) || cut.id !== id || !row?.payload || row.digest !== foldDigest(row.payload))
|
|
25102
|
-
return false;
|
|
25103
|
-
const snapshot = JSON.parse(row.payload);
|
|
25104
|
-
return snapshot.summary === cut.data.summary && snapshot.source === this.deps.storage.sourceID && snapshot.sessionID === sessionID && snapshot.admissionID === id;
|
|
25773
|
+
return cut.id === id && isAdmittedLocalCheckpoint(this.deps.storage, sessionID, cut);
|
|
25105
25774
|
}
|
|
25106
25775
|
async idle(sessionID) {
|
|
25107
25776
|
const { storage, session, threshold } = this.deps;
|
|
@@ -25524,7 +26193,7 @@ async function cleanupLegacyHiddenChildren(db, remove, note, options = {}) {
|
|
|
25524
26193
|
// src/shared/models-dev-temperature.ts
|
|
25525
26194
|
import { readFileSync as readFileSync5, statSync as statSync2 } from "node:fs";
|
|
25526
26195
|
import { homedir as homedir3 } from "node:os";
|
|
25527
|
-
import { join as
|
|
26196
|
+
import { join as join7 } from "node:path";
|
|
25528
26197
|
var CATALOG_PROVIDER_ALIASES = {
|
|
25529
26198
|
"google-antigravity": "google",
|
|
25530
26199
|
"opencode-zen": "opencode"
|
|
@@ -25534,7 +26203,7 @@ var cached;
|
|
|
25534
26203
|
function modelsDevCatalogPath(env = process.env) {
|
|
25535
26204
|
if (env.OPENCODE_MODELS_PATH)
|
|
25536
26205
|
return env.OPENCODE_MODELS_PATH;
|
|
25537
|
-
return
|
|
26206
|
+
return join7(env.XDG_CACHE_HOME || join7(homedir3(), ".cache"), "opencode", "models.json");
|
|
25538
26207
|
}
|
|
25539
26208
|
function buildIndex(raw) {
|
|
25540
26209
|
const index = new Map;
|
|
@@ -26532,11 +27201,11 @@ class DeletedSessionTombstones {
|
|
|
26532
27201
|
}
|
|
26533
27202
|
|
|
26534
27203
|
// src/features/magic-context/dreamer/task-executor.ts
|
|
26535
|
-
import { createHash as
|
|
27204
|
+
import { createHash as createHash14 } from "node:crypto";
|
|
26536
27205
|
import { existsSync as existsSync7, readFileSync as readFileSync8 } from "node:fs";
|
|
26537
27206
|
|
|
26538
27207
|
// src/features/magic-context/mural/compress-cues.ts
|
|
26539
|
-
import { createHash as
|
|
27208
|
+
import { createHash as createHash8 } from "node:crypto";
|
|
26540
27209
|
|
|
26541
27210
|
// src/features/magic-context/dreamer/storage-dream-state.ts
|
|
26542
27211
|
var getDreamStateStatements = new WeakMap;
|
|
@@ -27279,7 +27948,7 @@ async function applyCuesThroughModule(args, chunk, manifestText, signal) {
|
|
|
27279
27948
|
log2(`[dreamer] compress-cues: skipped cue for memory ${entry.id} (${failure.reason}; rejection ${rejectionCount}/${CUE_REJECTION_LATCH_THRESHOLD})`);
|
|
27280
27949
|
}
|
|
27281
27950
|
}
|
|
27282
|
-
const commandId = `mural-cues:${route.moduleCommandId}:${
|
|
27951
|
+
const commandId = `mural-cues:${route.moduleCommandId}:${createHash8("sha256").update(chunk.map((candidate) => candidate.memory.id).join(",")).digest("hex").slice(0, 24)}`;
|
|
27283
27952
|
let response;
|
|
27284
27953
|
try {
|
|
27285
27954
|
response = await route.moduleClient.call({
|
|
@@ -27882,7 +28551,7 @@ function applyReviewVerdict(args, leaseKey, parsed, result) {
|
|
|
27882
28551
|
}
|
|
27883
28552
|
|
|
27884
28553
|
// src/features/magic-context/dreamer/classify.ts
|
|
27885
|
-
import { createHash as
|
|
28554
|
+
import { createHash as createHash9 } from "node:crypto";
|
|
27886
28555
|
|
|
27887
28556
|
// src/plugin/rust-tool-backends.ts
|
|
27888
28557
|
function isRustAuthorityDrainingError(error) {
|
|
@@ -28319,7 +28988,7 @@ async function runClassifyThroughModule(args, chunk, anchors, signal, runOnHost)
|
|
|
28319
28988
|
if (entry.qualifier)
|
|
28320
28989
|
modelVariants[entry.model] = entry.qualifier;
|
|
28321
28990
|
}
|
|
28322
|
-
const commandId = `classify:${args.moduleCommandId ?? Date.now()}:${
|
|
28991
|
+
const commandId = `classify:${args.moduleCommandId ?? Date.now()}:${createHash9("sha256").update(chunk.map((candidate) => candidate.id).join(",")).digest("hex").slice(0, 24)}`;
|
|
28323
28992
|
const runTask = (hostCompletion) => args.moduleClient?.call({
|
|
28324
28993
|
sessionId: args.moduleSessionId,
|
|
28325
28994
|
projectRoot: args.moduleProjectRoot,
|
|
@@ -28594,7 +29263,7 @@ function takeCurateSafetyRefusalCount(sessionId) {
|
|
|
28594
29263
|
|
|
28595
29264
|
// src/features/magic-context/dreamer/docs-proposals.ts
|
|
28596
29265
|
import { execFileSync } from "node:child_process";
|
|
28597
|
-
import { createHash as
|
|
29266
|
+
import { createHash as createHash10 } from "node:crypto";
|
|
28598
29267
|
import {
|
|
28599
29268
|
existsSync as existsSync4,
|
|
28600
29269
|
mkdirSync,
|
|
@@ -28607,19 +29276,19 @@ import {
|
|
|
28607
29276
|
writeFileSync
|
|
28608
29277
|
} from "node:fs";
|
|
28609
29278
|
import { tmpdir } from "node:os";
|
|
28610
|
-
import { join as
|
|
29279
|
+
import { join as join8 } from "node:path";
|
|
28611
29280
|
var FILES = ["ARCHITECTURE.md", "STRUCTURE.md"];
|
|
28612
|
-
var hash = (text) =>
|
|
28613
|
-
var proposalDir = (projectDir) =>
|
|
29281
|
+
var hash = (text) => createHash10("sha256").update(text).digest("hex");
|
|
29282
|
+
var proposalDir = (projectDir) => join8(projectDir, ".cortexkit/magic-context/docs-update-proposals");
|
|
28614
29283
|
function docsBaseHashes(projectDir) {
|
|
28615
29284
|
return Object.fromEntries(FILES.map((name) => [
|
|
28616
29285
|
name,
|
|
28617
|
-
hash(existsSync4(
|
|
29286
|
+
hash(existsSync4(join8(projectDir, name)) ? readFileSync6(join8(projectDir, name), "utf8") : "")
|
|
28618
29287
|
]));
|
|
28619
29288
|
}
|
|
28620
29289
|
function listPendingDocsProposals(projectDir) {
|
|
28621
29290
|
const dir = proposalDir(projectDir);
|
|
28622
|
-
return existsSync4(dir) ? readdirSync2(dir).filter((name) => name.endsWith(".md")).sort().map((name) =>
|
|
29291
|
+
return existsSync4(dir) ? readdirSync2(dir).filter((name) => name.endsWith(".md")).sort().map((name) => join8(dir, name)) : [];
|
|
28623
29292
|
}
|
|
28624
29293
|
function hasCurrentDocsProposal(projectDir) {
|
|
28625
29294
|
const hashes = docsBaseHashes(projectDir);
|
|
@@ -28677,7 +29346,7 @@ function docsChangeSet(projectDir, storedAnchor) {
|
|
|
28677
29346
|
const files = [
|
|
28678
29347
|
...new Set(changed.flat().filter((file) => file !== "ARCHITECTURE.md" && file !== "STRUCTURE.md" && !/(?:^|[./-])(test|spec)(?:[./-]|$)/.test(file) && !file.endsWith(".lock")))
|
|
28679
29348
|
];
|
|
28680
|
-
const docs = FILES.map((file) => existsSync4(
|
|
29349
|
+
const docs = FILES.map((file) => existsSync4(join8(projectDir, file)) ? readFileSync6(join8(projectDir, file), "utf8") : "").join(`
|
|
28681
29350
|
`);
|
|
28682
29351
|
const relevant = files.some((file) => {
|
|
28683
29352
|
const directory = file.split("/").slice(0, -1).join("/");
|
|
@@ -28805,14 +29474,14 @@ function protectedBytes(text) {
|
|
|
28805
29474
|
].map((match) => match[0]);
|
|
28806
29475
|
}
|
|
28807
29476
|
function diff(name, before, after) {
|
|
28808
|
-
const dir = mkdtempSync(
|
|
29477
|
+
const dir = mkdtempSync(join8(tmpdir(), "mc-doc-diff-"));
|
|
28809
29478
|
try {
|
|
28810
|
-
writeFileSync(
|
|
28811
|
-
writeFileSync(
|
|
29479
|
+
writeFileSync(join8(dir, "before"), before);
|
|
29480
|
+
writeFileSync(join8(dir, "after"), after);
|
|
28812
29481
|
try {
|
|
28813
|
-
return execFileSync("git", ["diff", "--no-index", "--",
|
|
29482
|
+
return execFileSync("git", ["diff", "--no-index", "--", join8(dir, "before"), join8(dir, "after")], { windowsHide: true, encoding: "utf8" });
|
|
28814
29483
|
} catch (error) {
|
|
28815
|
-
return error.stdout?.replaceAll(
|
|
29484
|
+
return error.stdout?.replaceAll(join8(dir, "before"), `a/${name}`).replaceAll(join8(dir, "after"), `b/${name}`) ?? "";
|
|
28816
29485
|
}
|
|
28817
29486
|
} finally {
|
|
28818
29487
|
rmSync2(dir, { recursive: true, force: true });
|
|
@@ -28833,7 +29502,7 @@ function validateDocsProposal(projectDir, output, budget, expected) {
|
|
|
28833
29502
|
let tokens = 0;
|
|
28834
29503
|
let diffs = "";
|
|
28835
29504
|
for (const file of FILES) {
|
|
28836
|
-
const before = existsSync4(
|
|
29505
|
+
const before = existsSync4(join8(projectDir, file)) ? readFileSync6(join8(projectDir, file), "utf8") : "";
|
|
28837
29506
|
let after = before;
|
|
28838
29507
|
const seen = new Set;
|
|
28839
29508
|
for (const change of changes.filter((item) => item.file === file)) {
|
|
@@ -28883,9 +29552,9 @@ ${change.text.trimEnd()}
|
|
|
28883
29552
|
function writeDocsProposal(projectDir, output, budget, expected, head) {
|
|
28884
29553
|
const result = validateDocsProposal(projectDir, output, budget, expected);
|
|
28885
29554
|
const dir = proposalDir(projectDir);
|
|
28886
|
-
mkdirSync(
|
|
29555
|
+
mkdirSync(join8(dir, "superseded"), { recursive: true });
|
|
28887
29556
|
const stamp = `${new Date().toISOString().replace(/[:.]/g, "-")}-${Math.random().toString(36).slice(2, 8)}`;
|
|
28888
|
-
const path =
|
|
29557
|
+
const path = join8(dir, `${stamp}.md`);
|
|
28889
29558
|
const body = `# Docs update proposal
|
|
28890
29559
|
|
|
28891
29560
|
Base commit: ${head}
|
|
@@ -28913,7 +29582,7 @@ ${result.diffs}
|
|
|
28913
29582
|
writeFileSync(path, body, { flag: "wx" });
|
|
28914
29583
|
for (const old of listPendingDocsProposals(projectDir))
|
|
28915
29584
|
if (old !== path)
|
|
28916
|
-
renameSync(old,
|
|
29585
|
+
renameSync(old, join8(dir, "superseded", old.split("/").at(-1) ?? "proposal.md"));
|
|
28917
29586
|
return path;
|
|
28918
29587
|
}
|
|
28919
29588
|
|
|
@@ -29145,7 +29814,7 @@ function throwIfAborted2(signal) {
|
|
|
29145
29814
|
}
|
|
29146
29815
|
|
|
29147
29816
|
// src/features/magic-context/smart-notes/compiler.ts
|
|
29148
|
-
import { createHash as
|
|
29817
|
+
import { createHash as createHash11 } from "node:crypto";
|
|
29149
29818
|
|
|
29150
29819
|
// src/features/magic-context/smart-notes/compiler-prompt.ts
|
|
29151
29820
|
var SMART_NOTE_COMPILER_SYSTEM_PROMPT = `You are the Magic Context smart-note compiler for the magic-context system.
|
|
@@ -29484,7 +30153,7 @@ function manifestAdvisoryWarnings(code, manifest) {
|
|
|
29484
30153
|
return warnings;
|
|
29485
30154
|
}
|
|
29486
30155
|
function hashCheck(surfaceCondition, compiledCheck, manifest, checkCron) {
|
|
29487
|
-
return
|
|
30156
|
+
return createHash11("sha256").update(surfaceCondition ?? "").update("\x00").update(compiledCheck).update("\x00").update(JSON.stringify(manifest)).update("\x00").update(checkCron).digest("hex");
|
|
29488
30157
|
}
|
|
29489
30158
|
function extractJsonObject(output) {
|
|
29490
30159
|
const fenced = output.match(/```(?:json)?\s*([\s\S]*?)```/i);
|
|
@@ -29562,7 +30231,7 @@ function deterministicJitterMs(intervalMs, noteId, hash) {
|
|
|
29562
30231
|
}
|
|
29563
30232
|
|
|
29564
30233
|
// src/features/magic-context/smart-notes/wake-plane.ts
|
|
29565
|
-
import { join as
|
|
30234
|
+
import { join as join9 } from "node:path";
|
|
29566
30235
|
var WAKE_PLANE_CAPABILITY = "wake.create";
|
|
29567
30236
|
var WAKE_PLANE_STATUS_TTL_MS = 5 * 60 * 1000;
|
|
29568
30237
|
var WAKE_PLANE_HANDSHAKE_TIMEOUT_MS = 2000;
|
|
@@ -29571,7 +30240,7 @@ var inFlightProbe = null;
|
|
|
29571
30240
|
var catalogProbe = probeWakePlaneCatalog;
|
|
29572
30241
|
var now = () => Date.now();
|
|
29573
30242
|
function connectionFile() {
|
|
29574
|
-
return
|
|
30243
|
+
return join9(getDataDir(), "cortexkit", "run", "subc-connection.json");
|
|
29575
30244
|
}
|
|
29576
30245
|
async function probeWakePlaneCatalog() {
|
|
29577
30246
|
const file = connectionFile();
|
|
@@ -30234,12 +30903,12 @@ async function archiveExpiredMemories(args) {
|
|
|
30234
30903
|
|
|
30235
30904
|
// src/features/magic-context/dreamer/maintain-docs-protected-enforcement.ts
|
|
30236
30905
|
import { existsSync as existsSync5, readFileSync as readFileSync7, writeFileSync as writeFileSync2 } from "node:fs";
|
|
30237
|
-
import { join as
|
|
30906
|
+
import { join as join10 } from "node:path";
|
|
30238
30907
|
var MAINTAIN_DOCS_SNAPSHOT_FILES = ["ARCHITECTURE.md", "STRUCTURE.md"];
|
|
30239
30908
|
function snapshotMaintainDocsFiles(docsDir) {
|
|
30240
30909
|
const snapshot = new Map;
|
|
30241
30910
|
for (const name of MAINTAIN_DOCS_SNAPSHOT_FILES) {
|
|
30242
|
-
const path =
|
|
30911
|
+
const path = join10(docsDir, name);
|
|
30243
30912
|
try {
|
|
30244
30913
|
if (existsSync5(path)) {
|
|
30245
30914
|
snapshot.set(name, readFileSync7(path, "utf8"));
|
|
@@ -30250,7 +30919,7 @@ function snapshotMaintainDocsFiles(docsDir) {
|
|
|
30250
30919
|
}
|
|
30251
30920
|
|
|
30252
30921
|
// src/features/magic-context/dreamer/map-memories.ts
|
|
30253
|
-
import { createHash as
|
|
30922
|
+
import { createHash as createHash12 } from "node:crypto";
|
|
30254
30923
|
|
|
30255
30924
|
// src/features/magic-context/dreamer/map-memories-prompt.ts
|
|
30256
30925
|
import { execFile as execFile2 } from "node:child_process";
|
|
@@ -30485,7 +31154,7 @@ function readRetries(db, project) {
|
|
|
30485
31154
|
}
|
|
30486
31155
|
}
|
|
30487
31156
|
function contentKey2(memory) {
|
|
30488
|
-
return
|
|
31157
|
+
return createHash12("sha256").update(`${memory.category}
|
|
30489
31158
|
${memory.content}`).digest("hex");
|
|
30490
31159
|
}
|
|
30491
31160
|
function isDeferred(memory, retries) {
|
|
@@ -30907,7 +31576,7 @@ async function applyParsedBatchMappings(args, batch, parsed, budgetFinalized = f
|
|
|
30907
31576
|
name: "memory.set_mapping",
|
|
30908
31577
|
arguments: {
|
|
30909
31578
|
memory_project: args.projectIdentity,
|
|
30910
|
-
command_id: `${args.moduleRoute.moduleCommandId}:${
|
|
31579
|
+
command_id: `${args.moduleRoute.moduleCommandId}:${createHash12("sha256").update(rows.map((row) => row.memory_id).join(",")).digest("hex").slice(0, 16)}`,
|
|
30911
31580
|
rows
|
|
30912
31581
|
}
|
|
30913
31582
|
}
|
|
@@ -32208,7 +32877,7 @@ function insertDreamRun(db, run) {
|
|
|
32208
32877
|
}
|
|
32209
32878
|
|
|
32210
32879
|
// src/features/magic-context/dreamer/verify.ts
|
|
32211
|
-
import { createHash as
|
|
32880
|
+
import { createHash as createHash13 } from "node:crypto";
|
|
32212
32881
|
|
|
32213
32882
|
// src/features/magic-context/dreamer/verify-diff.ts
|
|
32214
32883
|
import { execFile as execFile3 } from "node:child_process";
|
|
@@ -33073,7 +33742,7 @@ async function applyParsedVerifyManifest(args, batch, parsed, headAtPrompt, budg
|
|
|
33073
33742
|
name: "memory.set_verification",
|
|
33074
33743
|
arguments: {
|
|
33075
33744
|
memory_project: args.projectIdentity,
|
|
33076
|
-
command_id: `${args.moduleRoute.moduleCommandId}:${
|
|
33745
|
+
command_id: `${args.moduleRoute.moduleCommandId}:${createHash13("sha256").update(rows.map((row) => row.memory_id).join(",")).digest("hex").slice(0, 16)}`,
|
|
33077
33746
|
rows
|
|
33078
33747
|
}
|
|
33079
33748
|
}
|
|
@@ -33907,7 +34576,7 @@ function parseFrictionGateVerdict(verdict) {
|
|
|
33907
34576
|
}
|
|
33908
34577
|
function computeRetrospectiveWindowKey(flagged) {
|
|
33909
34578
|
const anchors = flagged.map((message) => `${message.sessionId}:${message.ts}`).sort().join("|");
|
|
33910
|
-
return
|
|
34579
|
+
return createHash14("sha256").update(anchors).digest("hex").slice(0, 32);
|
|
33911
34580
|
}
|
|
33912
34581
|
function renderFrictionWindow(messages, flaggedOrdinals, radius = 2) {
|
|
33913
34582
|
const flagged = new Set(flaggedOrdinals);
|
|
@@ -35345,7 +36014,7 @@ function runTick(origin) {
|
|
|
35345
36014
|
if (tickInFlight)
|
|
35346
36015
|
return;
|
|
35347
36016
|
tickInFlight = true;
|
|
35348
|
-
log2(`[
|
|
36017
|
+
log2(`[magic-context] maintenance tick (${origin}) — projects=${registeredProjects.size}`);
|
|
35349
36018
|
(async () => {
|
|
35350
36019
|
try {
|
|
35351
36020
|
const db = openTimerDatabaseOrNull("maintenance tick");
|
|
@@ -35395,6 +36064,9 @@ function persistTickOutcome(db, failure) {
|
|
|
35395
36064
|
}
|
|
35396
36065
|
}
|
|
35397
36066
|
async function runMessageHistoryMaintenance(db) {
|
|
36067
|
+
const prunedIdentities = await pruneMissingProjectIdentities();
|
|
36068
|
+
if (prunedIdentities > 0)
|
|
36069
|
+
log2(`[magic-context] pruned ${prunedIdentities} missing project identities`);
|
|
35398
36070
|
try {
|
|
35399
36071
|
await drainStaleLkgSlots(db);
|
|
35400
36072
|
} catch (error) {
|
|
@@ -35628,10 +36300,20 @@ async function sweepGitCommits(args) {
|
|
|
35628
36300
|
const holderId = crypto.randomUUID();
|
|
35629
36301
|
const lease = acquireGitSweepLease(db, projectIdentity, holderId);
|
|
35630
36302
|
if (!lease.acquired) {
|
|
35631
|
-
|
|
36303
|
+
if (lease.reason === "cooldown_active")
|
|
36304
|
+
return;
|
|
36305
|
+
const reason = `lease held by ${lease.leaseHolder ?? "another holder"} until ${lease.leaseExpiresAt ?? "unknown"}`;
|
|
35632
36306
|
log2(`[git-commits] sweep skipped for ${projectIdentity}: ${reason}`);
|
|
35633
36307
|
return;
|
|
35634
36308
|
}
|
|
36309
|
+
if (projectIdentity.startsWith("dir:")) {
|
|
36310
|
+
if (parkGitSweepNonIndexable(db, projectIdentity, holderId)) {
|
|
36311
|
+
log2(`[git-commits] sweep parked for ${projectIdentity}: directory identity has no commits`);
|
|
36312
|
+
} else {
|
|
36313
|
+
releaseGitSweepLease(db, projectIdentity, holderId);
|
|
36314
|
+
}
|
|
36315
|
+
return;
|
|
36316
|
+
}
|
|
35635
36317
|
const startedAt = Date.now();
|
|
35636
36318
|
const stopRenewal = startGitSweepLeaseRenewal(db, projectIdentity, holderId);
|
|
35637
36319
|
log2(`[git-commits] sweep starting for ${projectIdentity} (sinceDays=${gitCommitIndexing.since_days} maxCommits=${gitCommitIndexing.max_commits})`);
|
|
@@ -35892,9 +36574,9 @@ function hiddenTerminalError(event) {
|
|
|
35892
36574
|
}
|
|
35893
36575
|
|
|
35894
36576
|
// src/v2/hooks/lkg-system.ts
|
|
35895
|
-
import { createHash as
|
|
36577
|
+
import { createHash as createHash15 } from "node:crypto";
|
|
35896
36578
|
function identity(slot) {
|
|
35897
|
-
return
|
|
36579
|
+
return createHash15("sha256").update(JSON.stringify({
|
|
35898
36580
|
capturedAt: slot.capturedAt,
|
|
35899
36581
|
captureSequence: slot.captureSequence,
|
|
35900
36582
|
rowVersion: slot.rowVersion,
|
|
@@ -48722,7 +49404,7 @@ function resolveCtxExpandMode(args, domain) {
|
|
|
48722
49404
|
}
|
|
48723
49405
|
|
|
48724
49406
|
// src/tools/ctx-expand/render.ts
|
|
48725
|
-
import { createHash as
|
|
49407
|
+
import { createHash as createHash16 } from "node:crypto";
|
|
48726
49408
|
function isRecord6(value) {
|
|
48727
49409
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
48728
49410
|
}
|
|
@@ -48946,7 +49628,7 @@ function renderItemByTag(db, sessionId, number, textIndexDomain = "part") {
|
|
|
48946
49628
|
const index = scoped ? Number(scoped[2]) : 0;
|
|
48947
49629
|
const piText = message.parts.filter((part) => isRecord6(part) && part.type === "text");
|
|
48948
49630
|
const part = message.parts[index];
|
|
48949
|
-
const matching = derived ? piText.filter((part) => isRecord6(part) && typeof part.text === "string" &&
|
|
49631
|
+
const matching = derived ? piText.filter((part) => isRecord6(part) && typeof part.text === "string" && createHash16("sha256").update(part.text).digest("hex") === derived[3]) : [];
|
|
48950
49632
|
const selected = derived ? matching[Number(derived[4])] : textIndexDomain === "text" ? piText[index] : part;
|
|
48951
49633
|
return selected ? renderPartFull(selected) ?? "" : `Tag ${number}'s original text part is no longer in stored history.`;
|
|
48952
49634
|
}
|
|
@@ -49701,7 +50383,7 @@ import { isAbsolute as isAbsolute2 } from "node:path";
|
|
|
49701
50383
|
// ../retina-local-fs/src/path-fence.ts
|
|
49702
50384
|
import { lstat as lstat2, realpath as realpath2 } from "node:fs/promises";
|
|
49703
50385
|
import { homedir as homedir4 } from "node:os";
|
|
49704
|
-
import { basename, dirname as dirname2, isAbsolute, join as
|
|
50386
|
+
import { basename, dirname as dirname2, isAbsolute, join as join11, relative, resolve as resolve2, sep } from "node:path";
|
|
49705
50387
|
|
|
49706
50388
|
// ../retina-local-fs/src/errors.ts
|
|
49707
50389
|
class ProviderError extends Error {
|
|
@@ -49716,7 +50398,7 @@ class ProviderError extends Error {
|
|
|
49716
50398
|
// ../retina-local-fs/src/path-fence.ts
|
|
49717
50399
|
async function resolveAndFenceProviderPath(configuredPath, options) {
|
|
49718
50400
|
const { home, dataDirectory, aliases } = await resolveFenceRoots(options);
|
|
49719
|
-
const expanded = configuredPath.startsWith("~/") ?
|
|
50401
|
+
const expanded = configuredPath.startsWith("~/") ? join11(home, configuredPath.slice(2)) : configuredPath === "~" ? home : configuredPath;
|
|
49720
50402
|
const absolute = isAbsolute(expanded) ? resolve2(expanded) : resolve2(options.cwd ?? process.cwd(), expanded);
|
|
49721
50403
|
const canonical = await canonicalPath(absolute, options.allowMissing);
|
|
49722
50404
|
if (fenceCandidates(canonical, aliases).some((candidate) => isFencedPath(candidate, home, dataDirectory))) {
|
|
@@ -49733,13 +50415,13 @@ async function resolveFenceRoots(options) {
|
|
|
49733
50415
|
} catch (error) {
|
|
49734
50416
|
throw fsError(configuredHomePath, error);
|
|
49735
50417
|
}
|
|
49736
|
-
const configuredDataDirectory = resolve2(options.dataDirectory ?? process.env.XDG_DATA_HOME ??
|
|
50418
|
+
const configuredDataDirectory = resolve2(options.dataDirectory ?? process.env.XDG_DATA_HOME ?? join11(home, ".local", "share"));
|
|
49737
50419
|
const dataDirectory = await canonicalPath(configuredDataDirectory, true);
|
|
49738
50420
|
const aliases = [];
|
|
49739
|
-
const logicalCortexkit =
|
|
50421
|
+
const logicalCortexkit = join11(dataDirectory, "cortexkit");
|
|
49740
50422
|
for (const logical of [
|
|
49741
50423
|
logicalCortexkit,
|
|
49742
|
-
...FENCED_CORTEXKIT_ROOTS.map((root) =>
|
|
50424
|
+
...FENCED_CORTEXKIT_ROOTS.map((root) => join11(logicalCortexkit, root))
|
|
49743
50425
|
]) {
|
|
49744
50426
|
const canonical = await canonicalPath(logical, true);
|
|
49745
50427
|
if (canonical !== logical)
|
|
@@ -49753,7 +50435,7 @@ function fenceCandidates(canonical, aliases) {
|
|
|
49753
50435
|
const relativeToAlias = relative(alias.canonical, canonical);
|
|
49754
50436
|
const inside = relativeToAlias === "" || relativeToAlias !== ".." && !relativeToAlias.startsWith(`..${sep}`) && !isAbsolute(relativeToAlias);
|
|
49755
50437
|
if (inside)
|
|
49756
|
-
candidates.push(
|
|
50438
|
+
candidates.push(join11(alias.logical, relativeToAlias));
|
|
49757
50439
|
}
|
|
49758
50440
|
return candidates;
|
|
49759
50441
|
}
|
|
@@ -49784,7 +50466,7 @@ async function canonicalPath(path, allowMissing) {
|
|
|
49784
50466
|
suffix.unshift(basename(candidate));
|
|
49785
50467
|
candidate = parent;
|
|
49786
50468
|
try {
|
|
49787
|
-
return
|
|
50469
|
+
return join11(await realpath2(candidate), ...suffix);
|
|
49788
50470
|
} catch (parentError) {
|
|
49789
50471
|
if (!isMissingError(parentError)) {
|
|
49790
50472
|
throw fsError(path, parentError);
|
|
@@ -49793,8 +50475,8 @@ async function canonicalPath(path, allowMissing) {
|
|
|
49793
50475
|
}
|
|
49794
50476
|
}
|
|
49795
50477
|
}
|
|
49796
|
-
function isFencedPath(canonicalPath, homeDirectory, dataDirectory = process.env.XDG_DATA_HOME ??
|
|
49797
|
-
const cortexkitRoot =
|
|
50478
|
+
function isFencedPath(canonicalPath, homeDirectory, dataDirectory = process.env.XDG_DATA_HOME ?? join11(resolve2(homeDirectory), ".local", "share")) {
|
|
50479
|
+
const cortexkitRoot = join11(resolve2(dataDirectory), "cortexkit");
|
|
49798
50480
|
const relativeToCortexkit = relative(cortexkitRoot, canonicalPath);
|
|
49799
50481
|
const insideCortexkit = relativeToCortexkit !== "" && relativeToCortexkit !== ".." && !relativeToCortexkit.startsWith(`..${sep}`) && !isAbsolute(relativeToCortexkit);
|
|
49800
50482
|
const parts = insideCortexkit ? relativeToCortexkit.split(sep) : [];
|
|
@@ -50473,7 +51155,7 @@ function formatCtxReduceReply(stampedCount, selfStampCount = 0) {
|
|
|
50473
51155
|
return parts.join(" ");
|
|
50474
51156
|
}
|
|
50475
51157
|
// src/tools/ctx-reduce/tools.ts
|
|
50476
|
-
import { createHash as
|
|
51158
|
+
import { createHash as createHash17 } from "node:crypto";
|
|
50477
51159
|
|
|
50478
51160
|
// src/features/magic-context/range-parser.ts
|
|
50479
51161
|
function parseRangeString(input) {
|
|
@@ -50536,11 +51218,11 @@ function createCtxReduceTool(deps) {
|
|
|
50536
51218
|
const stableId = `oc-${sessionId}-${callId}`;
|
|
50537
51219
|
if (Buffer.byteLength(stableId) <= 128)
|
|
50538
51220
|
return stableId;
|
|
50539
|
-
return `oc-${
|
|
51221
|
+
return `oc-${createHash17("sha256").update(stableId).digest("hex")}`;
|
|
50540
51222
|
}
|
|
50541
51223
|
fallbackCommandSequence += 1;
|
|
50542
51224
|
const monotonicId = `oc-${sessionId}-${fallbackCommandSequence}`;
|
|
50543
|
-
return Buffer.byteLength(monotonicId) <= 128 ? monotonicId : `oc-${
|
|
51225
|
+
return Buffer.byteLength(monotonicId) <= 128 ? monotonicId : `oc-${createHash17("sha256").update(monotonicId).digest("hex")}`;
|
|
50544
51226
|
};
|
|
50545
51227
|
return tool({
|
|
50546
51228
|
description: CTX_REDUCE_DESCRIPTION,
|
|
@@ -51343,6 +52025,11 @@ async function applyV2SystemPrompt(systemPrompt, draft) {
|
|
|
51343
52025
|
text
|
|
51344
52026
|
})));
|
|
51345
52027
|
}
|
|
52028
|
+
function coveredInstructionRows(reader, sessionID, throughSeq, model) {
|
|
52029
|
+
if (throughSeq < 0)
|
|
52030
|
+
return [];
|
|
52031
|
+
return reader.instructionRowsThrough(sessionID, throughSeq).flatMap((row) => restoreRow(row, model)).map((message) => markCoveredInstructionRow(message));
|
|
52032
|
+
}
|
|
51346
52033
|
async function registerContext(context) {
|
|
51347
52034
|
const directory = context.location.directory;
|
|
51348
52035
|
const config = loadPluginConfigDetailed(directory).config;
|
|
@@ -51382,7 +52069,7 @@ async function registerContext(context) {
|
|
|
51382
52069
|
}
|
|
51383
52070
|
const folds = new FoldOwner(context.storage);
|
|
51384
52071
|
const nativeFoldMemory = !compactionOff && process.env.MC_OC2_INVISIBLE_FOLD === "1" ? nativeFoldCache(() => storage.require()) : undefined;
|
|
51385
|
-
const nativeFoldReplay = nativeFoldMemory ? new NativeFoldReplay(nativeFoldMemory, () => openStoreReader()) : undefined;
|
|
52072
|
+
const nativeFoldReplay = nativeFoldMemory ? new NativeFoldReplay(nativeFoldMemory, () => openStoreReader(), context.storage) : undefined;
|
|
51386
52073
|
setOutputReserveConfig(config.output_reserve);
|
|
51387
52074
|
const queriedModels = new Set;
|
|
51388
52075
|
const rawLimits = new Map;
|
|
@@ -51434,6 +52121,7 @@ async function registerContext(context) {
|
|
|
51434
52121
|
memorySyncRequestedSessions: rustMemorySyncRequestedSessions
|
|
51435
52122
|
}) : undefined;
|
|
51436
52123
|
const hiddenChildHook = new HiddenChildHook;
|
|
52124
|
+
await context.session.hook("http.request", (draft) => hiddenChildHook.cacheRequest(draft));
|
|
51437
52125
|
const tools = db && isDatabasePersisted(db) ? await registerTools(context, db, config, moduleToolBackends?.backends, (id) => hiddenChildHook.owns(id)) : undefined;
|
|
51438
52126
|
const usage = new Map;
|
|
51439
52127
|
const generateReplay = new V2GenerateReplay;
|
|
@@ -51810,87 +52498,114 @@ async function registerContext(context) {
|
|
|
51810
52498
|
}) : undefined;
|
|
51811
52499
|
const usageController = new AbortController;
|
|
51812
52500
|
const usageDone = (async () => {
|
|
51813
|
-
|
|
51814
|
-
|
|
51815
|
-
|
|
51816
|
-
|
|
51817
|
-
const
|
|
51818
|
-
|
|
51819
|
-
|
|
51820
|
-
|
|
51821
|
-
|
|
51822
|
-
|
|
51823
|
-
|
|
51824
|
-
|
|
51825
|
-
|
|
51826
|
-
|
|
51827
|
-
|
|
51828
|
-
|
|
51829
|
-
|
|
51830
|
-
|
|
51831
|
-
|
|
51832
|
-
|
|
51833
|
-
|
|
52501
|
+
let retry = 0;
|
|
52502
|
+
while (!usageController.signal.aborted) {
|
|
52503
|
+
const subscribedAt = Date.now();
|
|
52504
|
+
try {
|
|
52505
|
+
for await (const value of context.event.subscribe({
|
|
52506
|
+
signal: usageController.signal
|
|
52507
|
+
})) {
|
|
52508
|
+
if (usageController.signal.aborted)
|
|
52509
|
+
break;
|
|
52510
|
+
const event = value;
|
|
52511
|
+
try {
|
|
52512
|
+
if (event.type === "provider.updated" || event.type === "model.updated") {
|
|
52513
|
+
queriedModels.clear();
|
|
52514
|
+
continue;
|
|
52515
|
+
}
|
|
52516
|
+
if (!event.data?.sessionID)
|
|
52517
|
+
continue;
|
|
52518
|
+
const sessionID = event.data.sessionID;
|
|
52519
|
+
if (event.type?.startsWith("session.revert.") || event.type === "session.message.content.updated") {
|
|
52520
|
+
nativeFoldReplay?.onEvent(event);
|
|
52521
|
+
restoredRows.forget(sessionID);
|
|
52522
|
+
}
|
|
52523
|
+
if (event.type === "session.error" || event.type === "session.execution.failed") {
|
|
52524
|
+
const error = hiddenTerminalError(event);
|
|
52525
|
+
if (error !== undefined)
|
|
52526
|
+
hiddenSessionErrors.set(sessionID, error);
|
|
52527
|
+
if (error !== undefined && db && !compactionOff) {
|
|
52528
|
+
const model = liveModels.get(sessionID);
|
|
52529
|
+
try {
|
|
52530
|
+
armLatestThinkingRecoveryFromError({
|
|
52531
|
+
db,
|
|
52532
|
+
sessionId: sessionID,
|
|
52533
|
+
error,
|
|
52534
|
+
providerID: model?.providerID,
|
|
52535
|
+
modelID: model?.modelID
|
|
52536
|
+
});
|
|
52537
|
+
} catch (armError) {
|
|
52538
|
+
log2("[magic-context] v2 latest-thinking recovery arm failed", armError);
|
|
52539
|
+
}
|
|
52540
|
+
}
|
|
52541
|
+
continue;
|
|
52542
|
+
}
|
|
52543
|
+
if (event.type === "session.deleted") {
|
|
52544
|
+
clearLkgMeasuredRequest(sessionID);
|
|
52545
|
+
deletedSessions.add(sessionID);
|
|
52546
|
+
transform?.clearSessionLogState(sessionID);
|
|
52547
|
+
if (db) {
|
|
52548
|
+
markSessionCleanupPending(db, sessionID);
|
|
52549
|
+
clearSession(db, sessionID);
|
|
52550
|
+
}
|
|
52551
|
+
rawProviders.get(sessionID)?.();
|
|
52552
|
+
rawProviders.delete(sessionID);
|
|
52553
|
+
usage.delete(sessionID);
|
|
52554
|
+
hiddenSessionErrors.delete(sessionID);
|
|
52555
|
+
storageNoticeBySession.delete(sessionID);
|
|
52556
|
+
liveModels.delete(sessionID);
|
|
52557
|
+
variants.delete(sessionID);
|
|
52558
|
+
agents.delete(sessionID);
|
|
52559
|
+
channel1.delete(sessionID);
|
|
52560
|
+
commitSeenLastPass.delete(sessionID);
|
|
52561
|
+
clearEmbedSessionState(sessionID);
|
|
52562
|
+
historyRefreshSessions.delete(sessionID);
|
|
52563
|
+
clearPendingMaterialization(pendingMaterializationSessions, sessionID);
|
|
52564
|
+
lastHeuristicsTurnId.delete(sessionID);
|
|
52565
|
+
restoredRows.forget(sessionID);
|
|
52566
|
+
if (nativeFoldReplay)
|
|
52567
|
+
await nativeFoldReplay.forget(sessionID);
|
|
52568
|
+
else
|
|
52569
|
+
await forgetNativeFoldProvenance(context.storage, sessionID);
|
|
52570
|
+
generateReplay.forget(sessionID);
|
|
52571
|
+
systemPromptRefreshSessions.delete(sessionID);
|
|
52572
|
+
systemPrompt?.clearSession(sessionID);
|
|
52573
|
+
tagger.cleanup(sessionID);
|
|
52574
|
+
continue;
|
|
52575
|
+
}
|
|
52576
|
+
if (event.type !== "session.execution.succeeded")
|
|
52577
|
+
continue;
|
|
51834
52578
|
const model = liveModels.get(sessionID);
|
|
51835
|
-
|
|
51836
|
-
|
|
51837
|
-
|
|
51838
|
-
|
|
51839
|
-
error,
|
|
51840
|
-
providerID: model?.providerID,
|
|
51841
|
-
modelID: model?.modelID
|
|
52579
|
+
if (model) {
|
|
52580
|
+
await recordUsage({
|
|
52581
|
+
sessionID,
|
|
52582
|
+
model: { providerID: model.providerID, id: model.modelID }
|
|
51842
52583
|
});
|
|
51843
|
-
|
|
51844
|
-
|
|
52584
|
+
if (!compactionOff && typeof await nativeFoldReplay?.baseline(sessionID) === "string")
|
|
52585
|
+
hostFolds?.idle(sessionID);
|
|
51845
52586
|
}
|
|
52587
|
+
} catch (error) {
|
|
52588
|
+
log2(`[magic-context] v2 event handler failed (type=${event.type ?? "unknown"}, session=${event.data?.sessionID ?? "none"})`, error);
|
|
51846
52589
|
}
|
|
51847
|
-
continue;
|
|
51848
|
-
}
|
|
51849
|
-
if (event.type === "session.deleted") {
|
|
51850
|
-
clearLkgMeasuredRequest(sessionID);
|
|
51851
|
-
deletedSessions.add(sessionID);
|
|
51852
|
-
transform?.clearSessionLogState(sessionID);
|
|
51853
|
-
if (db) {
|
|
51854
|
-
markSessionCleanupPending(db, sessionID);
|
|
51855
|
-
clearSession(db, sessionID);
|
|
51856
|
-
}
|
|
51857
|
-
rawProviders.get(sessionID)?.();
|
|
51858
|
-
rawProviders.delete(sessionID);
|
|
51859
|
-
usage.delete(sessionID);
|
|
51860
|
-
hiddenSessionErrors.delete(sessionID);
|
|
51861
|
-
storageNoticeBySession.delete(sessionID);
|
|
51862
|
-
liveModels.delete(sessionID);
|
|
51863
|
-
variants.delete(sessionID);
|
|
51864
|
-
agents.delete(sessionID);
|
|
51865
|
-
channel1.delete(sessionID);
|
|
51866
|
-
commitSeenLastPass.delete(sessionID);
|
|
51867
|
-
clearEmbedSessionState(sessionID);
|
|
51868
|
-
historyRefreshSessions.delete(sessionID);
|
|
51869
|
-
clearPendingMaterialization(pendingMaterializationSessions, sessionID);
|
|
51870
|
-
lastHeuristicsTurnId.delete(sessionID);
|
|
51871
|
-
restoredRows.forget(sessionID);
|
|
51872
|
-
await nativeFoldReplay?.forget(sessionID);
|
|
51873
|
-
generateReplay.forget(sessionID);
|
|
51874
|
-
systemPromptRefreshSessions.delete(sessionID);
|
|
51875
|
-
systemPrompt?.clearSession(sessionID);
|
|
51876
|
-
tagger.cleanup(sessionID);
|
|
51877
|
-
continue;
|
|
51878
|
-
}
|
|
51879
|
-
if (event.type !== "session.execution.succeeded")
|
|
51880
|
-
continue;
|
|
51881
|
-
const model = liveModels.get(sessionID);
|
|
51882
|
-
if (model) {
|
|
51883
|
-
await recordUsage({
|
|
51884
|
-
sessionID,
|
|
51885
|
-
model: { providerID: model.providerID, id: model.modelID }
|
|
51886
|
-
});
|
|
51887
|
-
if (!compactionOff && typeof await nativeFoldReplay?.baseline(sessionID) === "string")
|
|
51888
|
-
hostFolds?.idle(sessionID);
|
|
51889
52590
|
}
|
|
52591
|
+
} catch (error) {
|
|
52592
|
+
if (!usageController.signal.aborted)
|
|
52593
|
+
log2("[magic-context] v2 usage subscription failed", error);
|
|
52594
|
+
}
|
|
52595
|
+
if (usageController.signal.aborted)
|
|
52596
|
+
break;
|
|
52597
|
+
if (Date.now() - subscribedAt >= 30000)
|
|
52598
|
+
retry = 0;
|
|
52599
|
+
const ceiling = Math.min(30000, 250 * 2 ** retry);
|
|
52600
|
+
retry = Math.min(retry + 1, 7);
|
|
52601
|
+
try {
|
|
52602
|
+
await delay(ceiling * (0.5 + Math.random() * 0.5), undefined, {
|
|
52603
|
+
signal: usageController.signal
|
|
52604
|
+
});
|
|
52605
|
+
} catch (error) {
|
|
52606
|
+
if (!usageController.signal.aborted)
|
|
52607
|
+
throw error;
|
|
51890
52608
|
}
|
|
51891
|
-
} catch (error) {
|
|
51892
|
-
if (!usageController.signal.aborted)
|
|
51893
|
-
log2("[magic-context] v2 usage subscription failed", error);
|
|
51894
52609
|
}
|
|
51895
52610
|
})();
|
|
51896
52611
|
const materialize = (draft) => {
|
|
@@ -52163,6 +52878,7 @@ async function registerContext(context) {
|
|
|
52163
52878
|
compactionOff,
|
|
52164
52879
|
storeGeneration: "v2",
|
|
52165
52880
|
normalizeRestoredAssistantText: stripCopiedTagNotation,
|
|
52881
|
+
refreshSourceContents: (sessionID) => nativeFoldReplay?.needsHeadRebuild(sessionID) ?? false,
|
|
52166
52882
|
hostCleanupCompactionMarkers: () => ({
|
|
52167
52883
|
verified: true,
|
|
52168
52884
|
removedLineages: 0,
|
|
@@ -52251,12 +52967,13 @@ async function registerContext(context) {
|
|
|
52251
52967
|
historyRefreshSessions.add(draft.sessionID);
|
|
52252
52968
|
requestPendingMaterialization(pendingMaterializationSessions, draft.sessionID, "boundary_repair");
|
|
52253
52969
|
}
|
|
52254
|
-
const
|
|
52970
|
+
const localCut = cut && isLocalCheckpoint(cut) ? cut : undefined;
|
|
52971
|
+
const incoming = localCut && draft.messages.find((message) => message.id === localCut.id);
|
|
52255
52972
|
postFold = cut !== undefined;
|
|
52256
|
-
if (
|
|
52973
|
+
if (localCut && !incoming)
|
|
52257
52974
|
throw new Error("The host checkpoint disappeared from the context draft");
|
|
52258
52975
|
let nativeRestored;
|
|
52259
|
-
if (cut && nativeFoldReplay &&
|
|
52976
|
+
if (cut && nativeFoldReplay && await nativeFoldReplay.admits(draft.sessionID, cut, reader)) {
|
|
52260
52977
|
try {
|
|
52261
52978
|
nativeRestored = await nativeFoldReplay.restore(draft.sessionID, cut, `${draft.model.providerID}/${draft.model.id}`, { bounded: !rustModeModuleClient });
|
|
52262
52979
|
} catch (error) {
|
|
@@ -52265,7 +52982,11 @@ async function registerContext(context) {
|
|
|
52265
52982
|
nativeRestored = await nativeFoldReplay.restoreRead(draft.sessionID, cut, draft.model);
|
|
52266
52983
|
}
|
|
52267
52984
|
}
|
|
52268
|
-
if (
|
|
52985
|
+
if (cut && nativeFoldReplay?.sourceChanged(draft.sessionID)) {
|
|
52986
|
+
if (db && !rustModeModuleClient && nativeFoldReplay.needsHeadRebuild(draft.sessionID))
|
|
52987
|
+
clearCachedM0(db, draft.sessionID);
|
|
52988
|
+
if (nativeFoldReplay.needsHeadRebuild(draft.sessionID))
|
|
52989
|
+
restoredRows.forget(draft.sessionID);
|
|
52269
52990
|
historyRefreshSessions.add(draft.sessionID);
|
|
52270
52991
|
requestPendingMaterialization(pendingMaterializationSessions, draft.sessionID, "host_history_change");
|
|
52271
52992
|
}
|
|
@@ -52276,25 +52997,27 @@ async function registerContext(context) {
|
|
|
52276
52997
|
return !id || !present.has(id);
|
|
52277
52998
|
});
|
|
52278
52999
|
draft.messages.splice(0, draft.messages.length, ...hidden, ...draft.messages.filter((message) => message !== incoming));
|
|
52279
|
-
} else if (cut && incoming) {
|
|
52280
|
-
|
|
52281
|
-
|
|
52282
|
-
|
|
52283
|
-
|
|
52284
|
-
|
|
52285
|
-
|
|
52286
|
-
|
|
52287
|
-
|
|
52288
|
-
|
|
52289
|
-
|
|
52290
|
-
|
|
52291
|
-
|
|
52292
|
-
|
|
53000
|
+
} else if (localCut && cut && incoming) {
|
|
53001
|
+
if (!nativeFoldReplay) {
|
|
53002
|
+
const identity = await folds.observe({
|
|
53003
|
+
sessionID: draft.sessionID,
|
|
53004
|
+
cutSeq: cut.seq,
|
|
53005
|
+
summary: cut.data.summary ?? "",
|
|
53006
|
+
rendered: incoming,
|
|
53007
|
+
onHard: (reason) => {
|
|
53008
|
+
sessionLog2(draft.sessionID, `HARD reason=${reason}`);
|
|
53009
|
+
materialize(draft);
|
|
53010
|
+
requestPendingMaterialization(pendingMaterializationSessions, draft.sessionID, "host_compaction");
|
|
53011
|
+
}
|
|
53012
|
+
});
|
|
53013
|
+
checkpoint = structuredClone(identity.rendered ?? incoming);
|
|
53014
|
+
submitted = identity.rendered ? identity.renderedSummary ?? identity.submitted : cut.data.summary ?? "";
|
|
53015
|
+
}
|
|
52293
53016
|
const moduleBoundaryID = rustModeModuleClient ? getPersistedCompactionMarkerState(db, draft.sessionID)?.boundaryMessageId ?? null : null;
|
|
52294
53017
|
const moduleBoundarySeq = moduleBoundaryID ? reader.sequenceForId(draft.sessionID, moduleBoundaryID) : undefined;
|
|
52295
53018
|
const boundaryID = db.prepare("SELECT cached_m0_last_baseline_end_message_id AS id FROM session_meta WHERE session_id = ?").get(draft.sessionID)?.id ?? (boundaryRepair?.kind === "repaired" || boundaryRepair?.kind === "baseline-reset" ? boundaryRepair.anchorEndMessageId : null);
|
|
52296
53019
|
const servedBoundary = boundaryID ? servedBoundaryRow(reader, draft.sessionID, boundaryID) : null;
|
|
52297
|
-
const boundary = (moduleBoundarySeq !== undefined ? moduleBoundarySeq - 1 : undefined) ?? servedBoundary?.seq ?? reader.sequenceForId(draft.sessionID, boundaryID) ?? (reader.earliestSequence(draft.sessionID) ?? 0) - 1;
|
|
53020
|
+
const boundary = (nativeFoldReplay?.sourceChanged(draft.sessionID) && !rustModeModuleClient ? (reader.earliestSequence(draft.sessionID) ?? 0) - 1 : undefined) ?? (moduleBoundarySeq !== undefined ? moduleBoundarySeq - 1 : undefined) ?? servedBoundary?.seq ?? reader.sequenceForId(draft.sessionID, boundaryID) ?? (reader.earliestSequence(draft.sessionID) ?? 0) - 1;
|
|
52298
53021
|
if (moduleBoundarySeq !== undefined)
|
|
52299
53022
|
sessionLog2(draft.sessionID, `v2 restore: from the module boundary ${moduleBoundaryID} to the host checkpoint`);
|
|
52300
53023
|
const present = new Set(draft.messages.map((message) => message.id));
|
|
@@ -52302,7 +53025,7 @@ async function registerContext(context) {
|
|
|
52302
53025
|
asset: hostMediaAsset,
|
|
52303
53026
|
unavailable: (detail) => sessionLog2(draft.sessionID, `v2 restore: attachment replaced by a note row=${detail.rowID} name=${JSON.stringify(detail.name ?? null)} mediaType=${detail.mediaType} reason=${JSON.stringify(detail.reason)}`)
|
|
52304
53027
|
} : undefined));
|
|
52305
|
-
draft.messages.splice(0, draft.messages.length, ...restored, ...draft.messages.filter((message) => message !== incoming));
|
|
53028
|
+
draft.messages.splice(0, draft.messages.length, ...rustModeModuleClient ? [] : coveredInstructionRows(reader, draft.sessionID, Math.min(boundary, cut.seq), draft.model), ...restored, ...draft.messages.filter((message) => message !== incoming));
|
|
52306
53029
|
}
|
|
52307
53030
|
if (config.temporal_awareness === true)
|
|
52308
53031
|
messageTimes = reader.messageTimes(draft.sessionID, draft.messages.flatMap((message) => message.id ? [message.id] : []));
|
|
@@ -52545,13 +53268,13 @@ ${baseline}
|
|
|
52545
53268
|
}, 0));
|
|
52546
53269
|
return {
|
|
52547
53270
|
async dispose() {
|
|
53271
|
+
usageController.abort();
|
|
52548
53272
|
await hiddenCompletionExecutor?.dispose();
|
|
53273
|
+
await usageDone;
|
|
52549
53274
|
rpcStopped = true;
|
|
52550
53275
|
rpcServer.stop();
|
|
52551
53276
|
transform?.disposeRust();
|
|
52552
53277
|
tools?.dispose();
|
|
52553
|
-
usageController.abort();
|
|
52554
|
-
await usageDone;
|
|
52555
53278
|
deletedSessions.clear();
|
|
52556
53279
|
await dreamTrigger?.dispose();
|
|
52557
53280
|
await maintenanceTimer?.dispose();
|