@cortexkit/opencode-magic-context 0.49.15 → 0.49.17
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 +12 -10
- 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 +343 -343
- package/dist/config/schema/magic-context.d.ts.map +1 -1
- package/dist/{conflict-warning-hook-mgq17yr3.js → conflict-warning-hook-4pmz879v.js} +6 -6
- package/dist/{context-0m46day0.js → context-yhetp0kn.js} +297 -141
- package/dist/embedding-backfill-fmz50tsy.js +24 -0
- package/dist/embedding-worker-process.js +1 -1
- package/dist/embedding-worker.js +5 -5
- 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-fts-rowid-map.d.ts +2 -2
- package/dist/features/magic-context/message-fts-rowid-map.d.ts.map +1 -1
- package/dist/features/magic-context/message-fts-session-filter.d.ts +2 -0
- package/dist/features/magic-context/message-fts-session-filter.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/message-time-backfill.d.ts +2 -2
- package/dist/features/magic-context/message-time-backfill.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-db.d.ts +2 -1
- package/dist/features/magic-context/storage-db.d.ts.map +1 -1
- 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/compartment-runner-historian.d.ts +4 -2
- package/dist/hooks/magic-context/compartment-runner-historian.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-incremental.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-validation.d.ts.map +1 -1
- package/dist/hooks/magic-context/emergency-drop.d.ts.map +1 -1
- package/dist/hooks/magic-context/historian-host-runner.d.ts.map +1 -1
- package/dist/hooks/magic-context/historian-prompt-fit.d.ts +2 -1
- package/dist/hooks/magic-context/historian-prompt-fit.d.ts.map +1 -1
- package/dist/hooks/magic-context/hook.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-recovery-fence.d.ts.map +1 -1
- package/dist/hooks/magic-context/raw-ordinal-warmup.d.ts +26 -0
- package/dist/hooks/magic-context/raw-ordinal-warmup.d.ts.map +1 -1
- package/dist/hooks/magic-context/read-session-chunk.d.ts.map +1 -1
- package/dist/hooks/magic-context/recomp-orchestrator.d.ts +3 -3
- package/dist/hooks/magic-context/recomp-orchestrator.d.ts.map +1 -1
- 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-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-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-3kdm78zp.js → index-24fezq97.js} +4 -4
- package/dist/{index-a8bvhwqs.js → index-2vxtcb95.js} +32 -3
- package/dist/{index-f71thw8j.js → index-4s3t0nd0.js} +1 -1
- package/dist/{index-ts1hjk1h.js → index-4yt7dtf4.js} +453 -227
- package/dist/{index-mc1cqza6.js → index-5a1ex6x8.js} +5 -5
- package/dist/{index-fkx2qnvw.js → index-6x57ar45.js} +2 -2
- package/dist/{index-dyvbsvga.js → index-a6mc0v4d.js} +25 -11
- package/dist/{index-snp5wbge.js → index-a7c4r5re.js} +160 -749
- package/dist/{index-42vcjcwe.js → index-aabzay3h.js} +180 -103
- package/dist/{index-3kx0kg0f.js → index-b5vqckbw.js} +14 -8
- package/dist/{v2/server-wafzvyhg.js → index-beht37jy.js} +8 -0
- package/dist/{index-e20m7284.js → index-bjcnntmz.js} +3 -3
- package/dist/{index-hqkczed7.js → index-c5pytzne.js} +22 -2
- package/dist/{index-thvnpfsv.js → index-cwzfcbtq.js} +967 -88
- package/dist/{index-yxycg7fs.js → index-fb2qxs2y.js} +26 -18
- package/dist/{index-mht7bq0z.js → index-hqhm3wke.js} +32 -8
- package/dist/{index-e4dsjj1p.js → index-jn12fvvh.js} +1 -1
- package/dist/index-kaqs6h31.js +58 -0
- package/dist/{index-n6m03s3n.js → index-ke416mdc.js} +1 -1
- package/dist/index-kmdj7dsq.js +96 -0
- package/dist/{index-1d289pq2.js → index-kq82mtg0.js} +2 -2
- package/dist/{index-n78avt2p.js → index-n37sebck.js} +1 -1
- package/dist/{index-1vc7jrkg.js → index-nkpmm9q8.js} +3 -3
- package/dist/{index-944w16m0.js → index-p7m7j0cp.js} +25 -17
- package/dist/{index-wk0n1cgt.js → index-qn7xstt2.js} +2 -2
- package/dist/{index-saews2s3.js → index-rr2bb45z.js} +1 -1
- package/dist/{index-mmfa86mt.js → index-s734jcsr.js} +169 -149
- package/dist/{index-dgs16axy.js → index-s74zqahq.js} +1 -1
- package/dist/{index-bxdg2nbt.js → index-v8awdgvd.js} +4 -4
- package/dist/{index-xn6q9pg6.js → index-vrzjhftj.js} +36 -76
- package/dist/{index-1sarmj9z.js → index-wgypt3cs.js} +6 -6
- package/dist/{index-y1qysm3q.js → index-ze7mvk54.js} +11 -8
- package/dist/index.js +47 -45
- package/dist/message-fts-rowid-map-17s0dfn4.js +25 -0
- package/dist/{message-index-bounded-vtgpq6b4.js → message-index-bounded-1633vc7f.js} +17 -17
- package/dist/{message-index-a6gztaqx.js → message-index-dprebmtt.js} +15 -15
- package/dist/{message-time-backfill-qjge9044.js → message-time-backfill-73mmm76q.js} +5 -5
- package/dist/migration-worker.js +9 -7
- 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-x45bv3qr.js → project-embedding-registry-z74mhqkf.js} +12 -10
- package/dist/raw-ordinal-warmup-worker.js +40 -10
- package/dist/{read-session-chunk-3ae3nfdn.js → read-session-chunk-4zp09ejb.js} +9 -9
- package/dist/{read-session-raw-m56hc7v2.js → read-session-raw-rsc8c7qy.js} +2 -2
- package/dist/{recomp-orchestrator-nwzcfhx4.js → recomp-orchestrator-z3ecszx6.js} +26 -26
- package/dist/{search-deajrd90.js → search-6mee3vty.js} +23 -22
- package/dist/search-archive-znyy44ve.js +25 -0
- package/dist/{send-session-notification-24r4esbh.js → send-session-notification-6ve0e8p4.js} +5 -5
- 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 +4 -0
- package/dist/shared/model-suggestion-retry.d.ts.map +1 -1
- package/dist/shared/resolve-fallbacks.d.ts +3 -3
- 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-s5bg1ahx.js → storage-tags-8qns3012.js} +8 -4
- package/dist/tools/ctx-expand/search-archive.d.ts +5 -1
- package/dist/tools/ctx-expand/search-archive.d.ts.map +1 -1
- package/dist/{transform-postprocess-phase-ne3z1zmt.js → transform-postprocess-phase-3ydzxa62.js} +26 -26
- package/dist/v2/auto-search-worker.js +76 -63
- package/dist/v2/chunk-embedding-write-worker.js +12 -10
- 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-4qczzck7.js → context-jn3zpeqh.js} +909 -454
- package/dist/v2/embedding-backfill-7c7yr69y.js +23 -0
- package/dist/v2/embedding-worker-process.js +1 -1
- package/dist/v2/embedding-worker.js +5 -5
- 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/types.d.ts +17 -0
- package/dist/v2/hooks/types.d.ts.map +1 -1
- package/dist/v2/message-fts-rowid-map-wfx67gfd.js +24 -0
- package/dist/v2/{message-index-bounded-rxxznd34.js → message-index-bounded-hpejqyd8.js} +17 -17
- package/dist/v2/{message-index-f947qtbz.js → message-index-pxehjpzx.js} +15 -15
- package/dist/v2/{message-time-backfill-bsteyc4d.js → message-time-backfill-04t0km1z.js} +5 -5
- package/dist/v2/migration-worker.js +9 -7
- package/dist/v2/{project-embedding-registry-0msp56p8.js → project-embedding-registry-gnkj56xp.js} +12 -10
- package/dist/v2/raw-ordinal-warmup-worker.js +40 -10
- package/dist/v2/{read-session-chunk-rq9nx1nn.js → read-session-chunk-zdppn4bj.js} +9 -9
- package/dist/v2/{read-session-raw-b3tf6ra1.js → read-session-raw-yaegtjzh.js} +2 -2
- package/dist/v2/{recomp-orchestrator-5zhxtwha.js → recomp-orchestrator-cmqnfpp3.js} +26 -26
- package/dist/v2/{search-n8wqxb1j.js → search-66842dya.js} +23 -22
- package/dist/v2/search-archive-gfh11vs0.js +24 -0
- package/dist/v2/{send-session-notification-8ghn9tnv.js → send-session-notification-3pxn658x.js} +5 -5
- package/dist/v2/{server-yrvqaswb.js → server-1wy7b9de.js} +25 -11
- package/dist/v2/{server-th4y11y7.js → server-271qxsf5.js} +6 -6
- package/dist/v2/{server-e298hswg.js → server-3rhpvy84.js} +967 -88
- package/dist/v2/{server-qhfvvfxj.js → server-46neh5fa.js} +14 -8
- package/dist/v2/{server-rrqpvwqd.js → server-6tmj0s7j.js} +2 -2
- package/dist/v2/{server-hek6z3w6.js → server-8by8qfec.js} +11 -8
- 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-05xjtq6c.js → server-d04vrx0j.js} +1 -1
- package/dist/v2/server-ec4ca92p.js +96 -0
- package/dist/v2/{server-dd0tz6cn.js → server-fw7wrk01.js} +160 -750
- package/dist/v2/{server-zs8d0s3b.js → server-g3qma5c0.js} +1 -1
- package/dist/v2/{server-k2bzedxk.js → server-gpvay0xz.js} +2 -2
- package/dist/v2/{server-kmbarfmn.js → server-gtfhttbr.js} +26 -18
- package/dist/v2/{server-g10mdym6.js → server-h1v0pyxb.js} +3 -3
- package/dist/v2/{server-4gn3z5an.js → server-hy3d3vsx.js} +1 -1
- package/dist/v2/server-kaqs6h31.js +58 -0
- package/dist/v2/{server-ehyava47.js → server-kh7dpa1a.js} +25 -17
- package/dist/v2/{server-6cdy4rc0.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-zc3e54vy.js → server-nj659894.js} +6 -6
- package/dist/v2/{server-gvkm8xaj.js → server-rmygf5pn.js} +32 -3
- package/dist/v2/{server-0ppsweh6.js → server-tgnbmwah.js} +22 -2
- package/dist/v2/{server-cfbr1s2x.js → server-vsw8tmm6.js} +36 -76
- package/dist/v2/{server-prg55b7k.js → server-xj136kt8.js} +23 -3
- package/dist/v2/{server-atbc19ab.js → server-zyzawhdw.js} +32 -8
- package/dist/v2/{server-ef89gdsx.js → server-zzkj2fch.js} +4 -4
- package/dist/v2/server.js +5 -5
- 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-hcc2adpf.js → storage-tags-1h8k6ra9.js} +8 -4
- package/dist/v2/store-reader.d.ts +2 -0
- package/dist/v2/store-reader.d.ts.map +1 -1
- package/dist/v2/{wrapup-orchestrator-65pwye0d.js → wrapup-orchestrator-xs8redz9.js} +26 -26
- package/dist/wrapup-orchestrator-j7d7ry5b.js +48 -0
- package/package.json +1 -1
- package/src/config/latch-permanence-guard.test.ts +4 -0
- package/src/config/schema/magic-context.ts +14 -6
- package/src/shared/historian-cache.test.ts +69 -0
- package/src/shared/historian-cache.ts +55 -0
- package/src/shared/model-resolution.test.ts +22 -0
- package/src/shared/model-suggestion-retry.ts +11 -3
- package/src/shared/resolve-fallbacks.test.ts +2 -3
- package/src/shared/resolve-fallbacks.ts +3 -3
- 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/embedding-backfill-5e1t5wha.js +0 -22
- package/dist/v2/embedding-backfill-jmaf8zrr.js +0 -21
- package/dist/wrapup-orchestrator-28xzsj5q.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
|
|
@@ -46,7 +46,7 @@ import {
|
|
|
46
46
|
DEFAULT_HISTORIAN_TIMEOUT_MS,
|
|
47
47
|
DEFAULT_LOCAL_EMBEDDING_MODEL,
|
|
48
48
|
DREAM_TASK_PROMOTION_DEFAULTS
|
|
49
|
-
} from "./server-
|
|
49
|
+
} from "./server-271qxsf5.js";
|
|
50
50
|
import {
|
|
51
51
|
CANONICAL_DREAM_TASKS,
|
|
52
52
|
DREAM_TASK_CAPABILITIES,
|
|
@@ -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,
|
|
@@ -283,7 +279,7 @@ import {
|
|
|
283
279
|
startCompartmentAgent,
|
|
284
280
|
setRecompStarting2,
|
|
285
281
|
setRecompTerminal2
|
|
286
|
-
} from "./server-
|
|
282
|
+
} from "./server-fw7wrk01.js";
|
|
287
283
|
import {
|
|
288
284
|
resolveHistorianModel2
|
|
289
285
|
} from "./server-8cd2j99z.js";
|
|
@@ -308,8 +304,9 @@ import {
|
|
|
308
304
|
openDatabaseAsync,
|
|
309
305
|
isDatabasePersisted,
|
|
310
306
|
getDatabasePersistenceError
|
|
311
|
-
} from "./server-
|
|
307
|
+
} from "./server-gtfhttbr.js";
|
|
312
308
|
import {
|
|
309
|
+
pruneMissingProjectIdentities,
|
|
313
310
|
setHomeProjectPermission,
|
|
314
311
|
shouldSkipHomeProjectMemory,
|
|
315
312
|
ProjectIdentityError,
|
|
@@ -324,13 +321,14 @@ import {
|
|
|
324
321
|
storedPathBelongsToIdentity,
|
|
325
322
|
beginBootQuietPeriod,
|
|
326
323
|
scheduleAfterBootQuiet
|
|
327
|
-
} from "./server-
|
|
324
|
+
} from "./server-rmygf5pn.js";
|
|
328
325
|
import {
|
|
329
326
|
detectLatestTurnThinkingMismatch,
|
|
330
327
|
isPrefixBoundThinkingModel,
|
|
331
328
|
detectOverflow,
|
|
332
329
|
ensureSessionMetaRow,
|
|
333
330
|
clearCachedM0M1,
|
|
331
|
+
clearCachedM0,
|
|
334
332
|
expandToolPart,
|
|
335
333
|
markHostUnservedRow,
|
|
336
334
|
estimateTrueRawMessageTokens,
|
|
@@ -512,7 +510,7 @@ import {
|
|
|
512
510
|
readRawSessionMessageById2,
|
|
513
511
|
readSessionChunk2,
|
|
514
512
|
readRawSessionSeedTail2
|
|
515
|
-
} from "./server-
|
|
513
|
+
} from "./server-kh7dpa1a.js";
|
|
516
514
|
import {
|
|
517
515
|
embedPauseBySession,
|
|
518
516
|
embedRunStateBySession,
|
|
@@ -541,7 +539,7 @@ import {
|
|
|
541
539
|
embedSessionCompartmentChunks2,
|
|
542
540
|
getEmbeddingCoverageStatus2,
|
|
543
541
|
getAutoEmbeddingSessionCoverage2
|
|
544
|
-
} from "./server-
|
|
542
|
+
} from "./server-8by8qfec.js";
|
|
545
543
|
import {
|
|
546
544
|
textMentionsRecentCommit,
|
|
547
545
|
hasMeaningfulUserText2,
|
|
@@ -552,7 +550,7 @@ import {
|
|
|
552
550
|
estimateTokens,
|
|
553
551
|
estimateFixedPromptTokens,
|
|
554
552
|
normalizeText
|
|
555
|
-
} from "./server-
|
|
553
|
+
} from "./server-tgnbmwah.js";
|
|
556
554
|
import {
|
|
557
555
|
SubcClient,
|
|
558
556
|
connectionFileExists,
|
|
@@ -560,7 +558,7 @@ import {
|
|
|
560
558
|
toSynapseLaneDescriptor,
|
|
561
559
|
formatSynapseLaneDescriptor,
|
|
562
560
|
SynapseEmbeddingProvider
|
|
563
|
-
} from "./server-
|
|
561
|
+
} from "./server-6tmj0s7j.js";
|
|
564
562
|
import {
|
|
565
563
|
inRootAsyncContext2,
|
|
566
564
|
getTagIdentityWriteGeneration2,
|
|
@@ -574,11 +572,19 @@ import {
|
|
|
574
572
|
isTransientSqliteError2,
|
|
575
573
|
SqliteAcquisitionBusyError2,
|
|
576
574
|
withAsyncPrivilegedWriter2
|
|
577
|
-
} from "./server-
|
|
578
|
-
import"./server-
|
|
575
|
+
} from "./server-beht37jy.js";
|
|
576
|
+
import"./server-51779zs2.js";
|
|
577
|
+
import {
|
|
578
|
+
isRawCompactionSummaryInfo2,
|
|
579
|
+
extractInMemoryMessageViews2,
|
|
580
|
+
buildInMemoryTailRawMessages2,
|
|
581
|
+
RawOrdinalsNotReady2,
|
|
582
|
+
runSessionWarmupWorker
|
|
583
|
+
} from "./server-xj136kt8.js";
|
|
584
|
+
import"./server-1wy7b9de.js";
|
|
579
585
|
import {
|
|
580
586
|
deleteChunkEmbedBackoffForSession
|
|
581
|
-
} from "./server-
|
|
587
|
+
} from "./server-46neh5fa.js";
|
|
582
588
|
import {
|
|
583
589
|
registerOwnRpcServerInstance,
|
|
584
590
|
rpcPortDir,
|
|
@@ -597,14 +603,20 @@ import {
|
|
|
597
603
|
prepareLkgCaptureFence,
|
|
598
604
|
certifyCommittedLkgCapture,
|
|
599
605
|
markLkgRecoveryDirty,
|
|
606
|
+
cleanSearchText,
|
|
607
|
+
matchedSearchSnippet,
|
|
608
|
+
gaDatabasePath,
|
|
609
|
+
RAW_MESSAGE_TYPES,
|
|
610
|
+
V2StoreReaderPool,
|
|
611
|
+
V2StoreReader,
|
|
600
612
|
advanceSessionActivity,
|
|
601
613
|
backfillSessionActivity,
|
|
602
614
|
getLastIndexedOrdinal2,
|
|
603
615
|
getMessageIndexReconciliationStartOrdinal2,
|
|
604
616
|
isMessageIndexReconciledThrough2,
|
|
605
617
|
indexMessagesAfterOrdinal2,
|
|
606
|
-
|
|
607
|
-
} from "./server-
|
|
618
|
+
sweepOrphanedOpenCodeMessageIndexesCooperatively2
|
|
619
|
+
} from "./server-3rhpvy84.js";
|
|
608
620
|
import {
|
|
609
621
|
stableStringify,
|
|
610
622
|
getTemporalDecisions,
|
|
@@ -663,12 +675,14 @@ import {
|
|
|
663
675
|
getPendingOpsCount,
|
|
664
676
|
clearPendingOps,
|
|
665
677
|
removePendingOp,
|
|
678
|
+
updateTagByteSize2,
|
|
666
679
|
getRecentTagOwnerMessageIds2,
|
|
667
680
|
AGE_RECLAIM_MIN_TOKENS2,
|
|
668
681
|
getOldestActiveUnprotectedToolTags2,
|
|
669
682
|
getActiveToolTagsForAgeReclaim2,
|
|
670
683
|
getTriggerTagTokenUpperBound2,
|
|
671
684
|
getActiveTagTokenTotalsByMessage2,
|
|
685
|
+
updateTagTokenCount2,
|
|
672
686
|
tryGetReasoningTokenEstimatesByMessage2,
|
|
673
687
|
cachedTagOwnerRatios2,
|
|
674
688
|
tagOwnerWarmupState2,
|
|
@@ -705,15 +719,7 @@ import {
|
|
|
705
719
|
adoptNullOwnerToolTag2,
|
|
706
720
|
getCandidateToolOwners2,
|
|
707
721
|
pickNearestPriorOwner2
|
|
708
|
-
} from "./server-
|
|
709
|
-
import"./server-51779zs2.js";
|
|
710
|
-
import {
|
|
711
|
-
isRawCompactionSummaryInfo2,
|
|
712
|
-
extractInMemoryMessageViews2,
|
|
713
|
-
buildInMemoryTailRawMessages2,
|
|
714
|
-
RawOrdinalsNotReady2,
|
|
715
|
-
runSessionWarmupWorker
|
|
716
|
-
} from "./server-prg55b7k.js";
|
|
722
|
+
} from "./server-zyzawhdw.js";
|
|
717
723
|
import {
|
|
718
724
|
resolveOpenCodeDbPath,
|
|
719
725
|
assertOpenCodeStoreGeneration,
|
|
@@ -729,12 +735,12 @@ import {
|
|
|
729
735
|
latestRealUserTurnIdFromOpenCodeDb,
|
|
730
736
|
getMessageTimesFromOpenCodeDb,
|
|
731
737
|
findLastAssistantModelFromOpenCodeDb
|
|
732
|
-
} from "./server-
|
|
738
|
+
} from "./server-n1prf1g6.js";
|
|
733
739
|
import {
|
|
734
740
|
getCurrentToolSetHash,
|
|
735
741
|
recordToolDefinition,
|
|
736
742
|
getMeasuredToolDefinitionTokens
|
|
737
|
-
} from "./server-
|
|
743
|
+
} from "./server-g3qma5c0.js";
|
|
738
744
|
import {
|
|
739
745
|
V2_MEMORY_CATEGORIES,
|
|
740
746
|
CATEGORY_PRIORITY
|
|
@@ -747,7 +753,7 @@ import {
|
|
|
747
753
|
resolveStoredPathWorkspaceIdentity,
|
|
748
754
|
storedPathBelongsToWorkspace,
|
|
749
755
|
computeWorkspaceEpochFingerprint
|
|
750
|
-
} from "./server-
|
|
756
|
+
} from "./server-gpvay0xz.js";
|
|
751
757
|
import {
|
|
752
758
|
configureContextDatabasePragmas2
|
|
753
759
|
} from "./server-fb3zxn06.js";
|
|
@@ -793,7 +799,7 @@ import {
|
|
|
793
799
|
readGitFileChangeTimesSince,
|
|
794
800
|
verificationFileExists,
|
|
795
801
|
normalizeVerificationFiles
|
|
796
|
-
} from "./server-
|
|
802
|
+
} from "./server-my7k4eds.js";
|
|
797
803
|
import {
|
|
798
804
|
deriveTriggerBudget2,
|
|
799
805
|
deriveHistorianChunkTokens2,
|
|
@@ -801,7 +807,7 @@ import {
|
|
|
801
807
|
resolveHistorianProducerLimits2,
|
|
802
808
|
resolveHistorianContextLimit2
|
|
803
809
|
} from "./server-34kwfsr4.js";
|
|
804
|
-
import"./server-
|
|
810
|
+
import"./server-d04vrx0j.js";
|
|
805
811
|
import {
|
|
806
812
|
isEmbeddingHostBusy2
|
|
807
813
|
} from "./server-qt1qqasc.js";
|
|
@@ -814,7 +820,7 @@ import {
|
|
|
814
820
|
releaseGitSweepLease,
|
|
815
821
|
recordSessionProjectIdentity,
|
|
816
822
|
hasRecordedSessionProjectIdentity
|
|
817
|
-
} from "./server-
|
|
823
|
+
} from "./server-hy3d3vsx.js";
|
|
818
824
|
import {
|
|
819
825
|
saveEmbeddingIfHashMatches,
|
|
820
826
|
invalidateProject2,
|
|
@@ -822,10 +828,10 @@ import {
|
|
|
822
828
|
} from "./server-4dhv7mqz.js";
|
|
823
829
|
import {
|
|
824
830
|
getLocalEmbeddingNativeMemoryStats
|
|
825
|
-
} from "./server-
|
|
831
|
+
} from "./server-h1v0pyxb.js";
|
|
826
832
|
import {
|
|
827
833
|
cosineSimilarity
|
|
828
|
-
} from "./server-
|
|
834
|
+
} from "./server-zzkj2fch.js";
|
|
829
835
|
import {
|
|
830
836
|
computeCueContentHash,
|
|
831
837
|
hasMuralCueColumns,
|
|
@@ -850,7 +856,7 @@ import {
|
|
|
850
856
|
mergeMemoryStats2,
|
|
851
857
|
archiveMemory2,
|
|
852
858
|
getMemoryCountsByStatus2
|
|
853
|
-
} from "./server-
|
|
859
|
+
} from "./server-n37sebck.js";
|
|
854
860
|
import {
|
|
855
861
|
registerNotificationSink2,
|
|
856
862
|
pushNotification2,
|
|
@@ -862,7 +868,7 @@ import"./server-h0410h0v.js";
|
|
|
862
868
|
import {
|
|
863
869
|
flushIgnoredMessages2,
|
|
864
870
|
sendStatusNotification2
|
|
865
|
-
} from "./server-
|
|
871
|
+
} from "./server-a9xqj88f.js";
|
|
866
872
|
import {
|
|
867
873
|
renderSingleStoreMigrationRequiredRefusal,
|
|
868
874
|
SingleStoreMigrationRequiredError,
|
|
@@ -877,16 +883,19 @@ import {
|
|
|
877
883
|
SubcModuleTransport,
|
|
878
884
|
indexCommitsForProject,
|
|
879
885
|
embedUnembeddedCommits,
|
|
880
|
-
withMessageFtsSessionFilter,
|
|
881
886
|
createUnifiedSearchDiagnostics2,
|
|
882
887
|
parseIdShapedQuery2,
|
|
883
888
|
resolveMemoriesByIdsForSearch2,
|
|
884
889
|
unifiedSearch2,
|
|
885
890
|
formatSearchResults2
|
|
886
|
-
} from "./server-
|
|
891
|
+
} from "./server-vsw8tmm6.js";
|
|
887
892
|
import {
|
|
888
893
|
resolvePromptContext2
|
|
889
894
|
} from "./server-fmsr7v69.js";
|
|
895
|
+
import"./server-kaqs6h31.js";
|
|
896
|
+
import {
|
|
897
|
+
renderSearchArchiveOffThread2
|
|
898
|
+
} from "./server-ec4ca92p.js";
|
|
890
899
|
import {
|
|
891
900
|
compareSemverCore
|
|
892
901
|
} from "./server-84w6rvvf.js";
|
|
@@ -1633,6 +1642,9 @@ __export(exports_coerce, {
|
|
|
1633
1642
|
string: () => string3
|
|
1634
1643
|
});
|
|
1635
1644
|
|
|
1645
|
+
// src/v2/hooks/context.ts
|
|
1646
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
1647
|
+
|
|
1636
1648
|
// src/config/dependency-notes.ts
|
|
1637
1649
|
function scheduledTasks(config) {
|
|
1638
1650
|
const tasks = config.dreamer?.tasks ?? {};
|
|
@@ -3420,9 +3432,14 @@ function scheduleReconciliation(db, sessionId, readMessages) {
|
|
|
3420
3432
|
});
|
|
3421
3433
|
}
|
|
3422
3434
|
async function sweepOrphanedOpenCodeMessageIndexesOffThread(db, openSource, options = {}) {
|
|
3435
|
+
if (getHarness2() === "opencode2")
|
|
3436
|
+
openSource = () => new Database2(gaDatabasePath(getDataDir(), process.env.OPENCODE_CHANNEL ?? "latest"), {
|
|
3437
|
+
readonly: true,
|
|
3438
|
+
fileMustExist: true
|
|
3439
|
+
});
|
|
3423
3440
|
const path = getSqliteDatabasePath2(db);
|
|
3424
|
-
if (!path || getHarness2() !== "opencode")
|
|
3425
|
-
return
|
|
3441
|
+
if (!path || getHarness2() !== "opencode" && getHarness2() !== "opencode2")
|
|
3442
|
+
return sweepOrphanedOpenCodeMessageIndexesCooperatively2(db, openSource, options);
|
|
3426
3443
|
let source = null;
|
|
3427
3444
|
let sourcePath = null;
|
|
3428
3445
|
try {
|
|
@@ -3434,7 +3451,7 @@ async function sweepOrphanedOpenCodeMessageIndexesOffThread(db, openSource, opti
|
|
|
3434
3451
|
source?.close();
|
|
3435
3452
|
}
|
|
3436
3453
|
if (!sourcePath)
|
|
3437
|
-
return
|
|
3454
|
+
return sweepOrphanedOpenCodeMessageIndexesCooperatively2(db, () => source, options);
|
|
3438
3455
|
const reply = await runSessionWarmupWorker({
|
|
3439
3456
|
path,
|
|
3440
3457
|
sessionId: "",
|
|
@@ -3509,7 +3526,8 @@ function seedSessionCacheTtlIfUnsynced(args) {
|
|
|
3509
3526
|
}
|
|
3510
3527
|
|
|
3511
3528
|
// src/hooks/magic-context/auto-search-deadline.ts
|
|
3512
|
-
var AUTO_SEARCH_TIMEOUT_MS =
|
|
3529
|
+
var AUTO_SEARCH_TIMEOUT_MS = 1000;
|
|
3530
|
+
var AUTO_SEARCH_VECTOR_TIMEOUT_MS = 200;
|
|
3513
3531
|
var operationDeadlines = new WeakMap;
|
|
3514
3532
|
function autoSearchDeadlineUnixMs(signal) {
|
|
3515
3533
|
const deadline = signal && operationDeadlines.get(signal);
|
|
@@ -4058,32 +4076,32 @@ function formatAge(committedAtMs) {
|
|
|
4058
4076
|
const years = Math.floor(days / 365);
|
|
4059
4077
|
return years === 1 ? "1y ago" : `${years}y ago`;
|
|
4060
4078
|
}
|
|
4061
|
-
function renderFragment(result, charCap, wordRules) {
|
|
4079
|
+
function renderFragment(result, charCap, wordRules, query) {
|
|
4062
4080
|
switch (result.source) {
|
|
4063
4081
|
case "memory": {
|
|
4064
|
-
const compressed = cavemanCompress(result.content, "ultra", CURRENT_CAVEMAN_RULES, wordRules);
|
|
4082
|
+
const compressed = cavemanCompress(cleanSearchText(result.content), "ultra", CURRENT_CAVEMAN_RULES, wordRules);
|
|
4065
4083
|
return truncate(compressed, charCap);
|
|
4066
4084
|
}
|
|
4067
4085
|
case "git_commit": {
|
|
4068
|
-
const subject = result.content.split(/\r?\n/)[0] ?? result.content;
|
|
4086
|
+
const subject = cleanSearchText(result.content.split(/\r?\n/)[0] ?? result.content);
|
|
4069
4087
|
const body = truncate(subject, Math.max(10, charCap - 20));
|
|
4070
4088
|
return `commit ${result.shortSha} ${formatAge(result.committedAtMs)}: ${body}`;
|
|
4071
4089
|
}
|
|
4072
4090
|
case "message": {
|
|
4073
|
-
const compressed = cavemanCompress(result.content, "ultra", CURRENT_CAVEMAN_RULES, wordRules);
|
|
4091
|
+
const compressed = cavemanCompress(query ? matchedSearchSnippet(result.content, query, charCap) : cleanSearchText(result.content), "ultra", CURRENT_CAVEMAN_RULES, wordRules);
|
|
4074
4092
|
return truncate(compressed, charCap);
|
|
4075
4093
|
}
|
|
4076
4094
|
case "compartment": {
|
|
4077
|
-
const source = result.
|
|
4095
|
+
const source = cleanSearchText(result.title);
|
|
4078
4096
|
const compressed = cavemanCompress(source, "ultra", CURRENT_CAVEMAN_RULES, wordRules);
|
|
4079
4097
|
return truncate(compressed, charCap);
|
|
4080
4098
|
}
|
|
4081
4099
|
case "primer": {
|
|
4082
|
-
const compressed = cavemanCompress(result.content, "ultra", CURRENT_CAVEMAN_RULES, wordRules);
|
|
4100
|
+
const compressed = cavemanCompress(cleanSearchText(result.content), "ultra", CURRENT_CAVEMAN_RULES, wordRules);
|
|
4083
4101
|
return truncate(compressed, charCap);
|
|
4084
4102
|
}
|
|
4085
4103
|
case "note": {
|
|
4086
|
-
const compressed = cavemanCompress(result.content, "ultra", CURRENT_CAVEMAN_RULES, wordRules);
|
|
4104
|
+
const compressed = cavemanCompress(cleanSearchText(result.content), "ultra", CURRENT_CAVEMAN_RULES, wordRules);
|
|
4087
4105
|
return truncate(compressed, charCap);
|
|
4088
4106
|
}
|
|
4089
4107
|
}
|
|
@@ -4094,7 +4112,7 @@ function buildAutoSearchHint(results, options = {}) {
|
|
|
4094
4112
|
const picks = results.slice(0, maxFragments);
|
|
4095
4113
|
const lines = [];
|
|
4096
4114
|
for (const result of picks) {
|
|
4097
|
-
const fragment = renderFragment(result, fragmentCharCap, options.wordRules ?? "english");
|
|
4115
|
+
const fragment = renderFragment(result, fragmentCharCap, options.wordRules ?? "english", options.query ?? "");
|
|
4098
4116
|
if (fragment.length === 0)
|
|
4099
4117
|
continue;
|
|
4100
4118
|
lines.push(`- ${fragment}`);
|
|
@@ -4117,6 +4135,9 @@ ${trimmedBody}…
|
|
|
4117
4135
|
}
|
|
4118
4136
|
return wrapped;
|
|
4119
4137
|
}
|
|
4138
|
+
function selectAutoSearchResults(results, threshold) {
|
|
4139
|
+
return results.filter((result) => (result.relevanceScore ?? result.score) >= threshold);
|
|
4140
|
+
}
|
|
4120
4141
|
|
|
4121
4142
|
// src/hooks/magic-context/auto-search-worker-client.ts
|
|
4122
4143
|
import { Worker } from "node:worker_threads";
|
|
@@ -4212,6 +4233,63 @@ async function searchAutoHint(db, sessionId, projectPath, query, options, entry
|
|
|
4212
4233
|
return executeAutoSearchWorker(db, sessionId, projectPath, query, options, entry, "search");
|
|
4213
4234
|
}
|
|
4214
4235
|
var pendingBackfills = new WeakMap;
|
|
4236
|
+
var searchWorkers = new WeakMap;
|
|
4237
|
+
var liveSearchWorkers = new Set;
|
|
4238
|
+
var MAX_IDLE_SEARCH_WORKERS = 4;
|
|
4239
|
+
var SEARCH_WORKER_IDLE_MS = 5 * 60000;
|
|
4240
|
+
var workersCreated = 0;
|
|
4241
|
+
var workersReused = 0;
|
|
4242
|
+
async function acquireSearchWorker(db, key, entry, input, signal) {
|
|
4243
|
+
const pool = searchWorkers.get(db) ?? new Map;
|
|
4244
|
+
searchWorkers.set(db, pool);
|
|
4245
|
+
while (!signal.aborted) {
|
|
4246
|
+
let slot = pool.get(key);
|
|
4247
|
+
if (slot?.busy) {
|
|
4248
|
+
const current = slot;
|
|
4249
|
+
await new Promise((resolve) => {
|
|
4250
|
+
const done = () => {
|
|
4251
|
+
signal.removeEventListener("abort", done);
|
|
4252
|
+
resolve();
|
|
4253
|
+
};
|
|
4254
|
+
signal.addEventListener("abort", done, { once: true });
|
|
4255
|
+
current.busy?.then(done);
|
|
4256
|
+
if (signal.aborted)
|
|
4257
|
+
done();
|
|
4258
|
+
});
|
|
4259
|
+
continue;
|
|
4260
|
+
}
|
|
4261
|
+
const fresh = !slot;
|
|
4262
|
+
if (!slot) {
|
|
4263
|
+
const worker = inRootAsyncContext2(() => new Worker(entry, { workerData: { ...input, persistent: true } }));
|
|
4264
|
+
slot = {
|
|
4265
|
+
worker,
|
|
4266
|
+
dispose() {
|
|
4267
|
+
clearTimeout(this.idleTimer);
|
|
4268
|
+
if (pool.get(key) === this)
|
|
4269
|
+
pool.delete(key);
|
|
4270
|
+
liveSearchWorkers.delete(this);
|
|
4271
|
+
worker.terminate();
|
|
4272
|
+
worker.unref();
|
|
4273
|
+
}
|
|
4274
|
+
};
|
|
4275
|
+
workersCreated++;
|
|
4276
|
+
pool.set(key, slot);
|
|
4277
|
+
liveSearchWorkers.add(slot);
|
|
4278
|
+
const current = slot;
|
|
4279
|
+
worker.on("error", () => current.dispose());
|
|
4280
|
+
worker.on("exit", () => current.dispose());
|
|
4281
|
+
} else
|
|
4282
|
+
workersReused++;
|
|
4283
|
+
clearTimeout(slot.idleTimer);
|
|
4284
|
+
const current = slot;
|
|
4285
|
+
current.busy = new Promise((resolve) => {
|
|
4286
|
+
current.release = resolve;
|
|
4287
|
+
});
|
|
4288
|
+
current.worker.ref();
|
|
4289
|
+
return { slot: current, fresh };
|
|
4290
|
+
}
|
|
4291
|
+
return null;
|
|
4292
|
+
}
|
|
4215
4293
|
function queueAutoSearchBackfill(db, sessionId, projectPath, query) {
|
|
4216
4294
|
if (isEmbeddingHostBusy2())
|
|
4217
4295
|
return Promise.resolve();
|
|
@@ -4276,6 +4354,7 @@ async function executeAutoSearchWorker(db, sessionId, projectPath, query, option
|
|
|
4276
4354
|
query,
|
|
4277
4355
|
options: {
|
|
4278
4356
|
...serializable,
|
|
4357
|
+
autoHint: true,
|
|
4279
4358
|
backfillMemoryEmbeddings: false,
|
|
4280
4359
|
countRetrievals: false,
|
|
4281
4360
|
measurementDisabled: true
|
|
@@ -4285,8 +4364,20 @@ async function executeAutoSearchWorker(db, sessionId, projectPath, query, option
|
|
|
4285
4364
|
snapshot,
|
|
4286
4365
|
deadlineUnixMs: autoSearchDeadlineUnixMs(deadlineSignal)
|
|
4287
4366
|
};
|
|
4367
|
+
let lease;
|
|
4368
|
+
try {
|
|
4369
|
+
lease = await acquireSearchWorker(db, `${input.harness}\x00${projectPath}\x00${job}\x00${entry.href}`, entry, input, signal);
|
|
4370
|
+
} catch (error) {
|
|
4371
|
+
lifecycle.done();
|
|
4372
|
+
throw error;
|
|
4373
|
+
}
|
|
4374
|
+
if (!lease) {
|
|
4375
|
+
lifecycle.done();
|
|
4376
|
+
return [];
|
|
4377
|
+
}
|
|
4378
|
+
const { slot, fresh } = lease;
|
|
4379
|
+
const worker = slot.worker;
|
|
4288
4380
|
return new Promise((resolve, reject) => {
|
|
4289
|
-
const worker = inRootAsyncContext2(() => new Worker(entry, { workerData: input }));
|
|
4290
4381
|
let settled = false;
|
|
4291
4382
|
const finish = (results, error) => {
|
|
4292
4383
|
if (settled)
|
|
@@ -4295,7 +4386,25 @@ async function executeAutoSearchWorker(db, sessionId, projectPath, query, option
|
|
|
4295
4386
|
signal?.removeEventListener("abort", abort);
|
|
4296
4387
|
lifecycle.signal.removeEventListener("abort", abort);
|
|
4297
4388
|
lifecycle.done();
|
|
4298
|
-
worker.
|
|
4389
|
+
worker.off("message", onMessage);
|
|
4390
|
+
worker.off("error", onError);
|
|
4391
|
+
worker.off("exit", onExit);
|
|
4392
|
+
if (error || signal.aborted || entry.href !== defaultAutoSearchWorkerEntry().href)
|
|
4393
|
+
slot.dispose();
|
|
4394
|
+
else {
|
|
4395
|
+
slot.idleTimer = setTimeout(() => slot.dispose(), SEARCH_WORKER_IDLE_MS);
|
|
4396
|
+
slot.idleTimer.unref?.();
|
|
4397
|
+
}
|
|
4398
|
+
const release = slot.release;
|
|
4399
|
+
slot.busy = undefined;
|
|
4400
|
+
slot.release = undefined;
|
|
4401
|
+
release?.();
|
|
4402
|
+
const reusable = liveSearchWorkers.delete(slot);
|
|
4403
|
+
if (reusable)
|
|
4404
|
+
liveSearchWorkers.add(slot);
|
|
4405
|
+
const idle = [...liveSearchWorkers].filter((candidate) => !candidate.busy);
|
|
4406
|
+
for (const prior of idle.slice(0, Math.max(0, idle.length - MAX_IDLE_SEARCH_WORKERS)))
|
|
4407
|
+
prior.dispose();
|
|
4299
4408
|
worker.unref();
|
|
4300
4409
|
if (error)
|
|
4301
4410
|
reject(error);
|
|
@@ -4305,9 +4414,9 @@ async function executeAutoSearchWorker(db, sessionId, projectPath, query, option
|
|
|
4305
4414
|
const abort = () => finish([]);
|
|
4306
4415
|
signal?.addEventListener("abort", abort, { once: true });
|
|
4307
4416
|
lifecycle.signal.addEventListener("abort", abort, { once: true });
|
|
4308
|
-
|
|
4309
|
-
|
|
4310
|
-
|
|
4417
|
+
const onError = (error) => finish([], error);
|
|
4418
|
+
const onExit = (code) => finish([], new Error(`auto-search worker exited (${code})`));
|
|
4419
|
+
const onMessage = async (reply) => {
|
|
4311
4420
|
if (settled)
|
|
4312
4421
|
return;
|
|
4313
4422
|
if (reply.kind === "result") {
|
|
@@ -4326,7 +4435,7 @@ async function executeAutoSearchWorker(db, sessionId, projectPath, query, option
|
|
|
4326
4435
|
const response = { id: reply.id };
|
|
4327
4436
|
try {
|
|
4328
4437
|
if (reply.kind === "query")
|
|
4329
|
-
response.result = await (job === "backfill" ? embedTextForProject2(projectPath, reply.text, signal, "query") : embedQuery
|
|
4438
|
+
response.result = await (job === "backfill" ? embedTextForProject2(projectPath, reply.text, signal, "query") : boundedHintEmbedding(embedQuery, reply.text, signal)) ?? null;
|
|
4330
4439
|
else {
|
|
4331
4440
|
const passage = await embedBatchForProject2(projectPath, reply.texts, signal, reply.purpose);
|
|
4332
4441
|
const current = getProjectEmbeddingSnapshot2(projectPath);
|
|
@@ -4341,13 +4450,46 @@ async function executeAutoSearchWorker(db, sessionId, projectPath, query, option
|
|
|
4341
4450
|
response.error = error instanceof Error ? error.message : String(error);
|
|
4342
4451
|
}
|
|
4343
4452
|
response.embeddingHostBusy = isEmbeddingHostBusy2();
|
|
4344
|
-
if (!settled && !signal?.aborted)
|
|
4345
|
-
|
|
4346
|
-
|
|
4453
|
+
if (!settled && !signal?.aborted) {
|
|
4454
|
+
try {
|
|
4455
|
+
worker.postMessage(response);
|
|
4456
|
+
} catch (error) {
|
|
4457
|
+
finish([], error instanceof Error ? error : new Error(String(error)));
|
|
4458
|
+
}
|
|
4459
|
+
}
|
|
4460
|
+
};
|
|
4461
|
+
worker.on("error", onError);
|
|
4462
|
+
worker.on("exit", onExit);
|
|
4463
|
+
worker.on("message", onMessage);
|
|
4347
4464
|
if (signal?.aborted)
|
|
4348
4465
|
abort();
|
|
4466
|
+
else if (!fresh) {
|
|
4467
|
+
try {
|
|
4468
|
+
worker.postMessage({ kind: "run", input });
|
|
4469
|
+
} catch (error) {
|
|
4470
|
+
finish([], error instanceof Error ? error : new Error(String(error)));
|
|
4471
|
+
}
|
|
4472
|
+
}
|
|
4349
4473
|
});
|
|
4350
4474
|
}
|
|
4475
|
+
async function boundedHintEmbedding(embed, text, signal) {
|
|
4476
|
+
const controller = new AbortController;
|
|
4477
|
+
const combined = AbortSignal.any([signal, controller.signal]);
|
|
4478
|
+
let timer;
|
|
4479
|
+
try {
|
|
4480
|
+
return await Promise.race([
|
|
4481
|
+
Promise.resolve().then(() => embed?.(text, combined) ?? null),
|
|
4482
|
+
new Promise((resolve) => {
|
|
4483
|
+
timer = setTimeout(() => {
|
|
4484
|
+
resolve(null);
|
|
4485
|
+
controller.abort();
|
|
4486
|
+
}, AUTO_SEARCH_VECTOR_TIMEOUT_MS);
|
|
4487
|
+
})
|
|
4488
|
+
]);
|
|
4489
|
+
} finally {
|
|
4490
|
+
clearTimeout(timer);
|
|
4491
|
+
}
|
|
4492
|
+
}
|
|
4351
4493
|
function defaultAutoSearchWorkerEntry() {
|
|
4352
4494
|
return new URL(new URL(import.meta.url).pathname.endsWith(".ts") ? "./auto-search-worker.ts" : "./auto-search-worker.js", import.meta.url);
|
|
4353
4495
|
}
|
|
@@ -4655,6 +4797,8 @@ async function runAutoSearchHint(args) {
|
|
|
4655
4797
|
const gitCommitsEnabled = embeddingSnapshot?.gitCommitEnabled ?? options.gitCommitsEnabled ?? false;
|
|
4656
4798
|
const searchOptions = {
|
|
4657
4799
|
limit: 10,
|
|
4800
|
+
maxMessageOrdinal: Math.max(0, getLastCompartmentEndMessage(db, sessionId)),
|
|
4801
|
+
excludeMessageId: userMsgId,
|
|
4658
4802
|
memoryEnabled,
|
|
4659
4803
|
embeddingEnabled,
|
|
4660
4804
|
gitCommitsEnabled,
|
|
@@ -4692,11 +4836,15 @@ async function runAutoSearchHint(args) {
|
|
|
4692
4836
|
if (results.length === 0) {
|
|
4693
4837
|
return writeNoHintAndReconcile("empty");
|
|
4694
4838
|
}
|
|
4695
|
-
|
|
4696
|
-
|
|
4839
|
+
results = selectAutoSearchResults(results, options.scoreThreshold);
|
|
4840
|
+
if (results.length === 0) {
|
|
4841
|
+
sessionLog2(sessionId, `auto-search: no fragment meets relevance threshold ${options.scoreThreshold}`);
|
|
4697
4842
|
return writeNoHintAndReconcile("below-threshold");
|
|
4698
4843
|
}
|
|
4699
|
-
const hintText = buildAutoSearchHint(results, {
|
|
4844
|
+
const hintText = buildAutoSearchHint(results, {
|
|
4845
|
+
wordRules: options.wordRules,
|
|
4846
|
+
query: rawPrompt
|
|
4847
|
+
});
|
|
4700
4848
|
if (!hintText) {
|
|
4701
4849
|
return writeNoHintAndReconcile("empty");
|
|
4702
4850
|
}
|
|
@@ -6951,27 +7099,43 @@ function buildReplacementContent(tagId) {
|
|
|
6951
7099
|
return `[dropped §${tagId}§]`;
|
|
6952
7100
|
}
|
|
6953
7101
|
function applyNewToolDrop(target, options) {
|
|
6954
|
-
|
|
7102
|
+
const plan = planNewToolDrop(target, options, !!options.persist);
|
|
7103
|
+
if (!plan)
|
|
6955
7104
|
return { result: "incomplete", mode: "full" };
|
|
7105
|
+
options.persist?.(plan.mode);
|
|
7106
|
+
return plan.apply();
|
|
7107
|
+
}
|
|
7108
|
+
function planNewToolDrop(target, options, prepare, plannedRemovals) {
|
|
7109
|
+
if (prepare && (target?.prepareDrop?.() ?? target?.canDrop?.()) === false) {
|
|
7110
|
+
return;
|
|
6956
7111
|
}
|
|
6957
7112
|
if (!target) {
|
|
6958
|
-
|
|
6959
|
-
return { result: "absent", mode: "full" };
|
|
7113
|
+
return { mode: "full", apply: () => ({ result: "absent", mode: "full" }) };
|
|
6960
7114
|
}
|
|
6961
|
-
if (options.inWindow && hasSmallToolInput(target) || options.keepSkeleton === true || target.cannotRemove?.() === true || target.wouldStrandConversationEnd?.() === true) {
|
|
7115
|
+
if (options.inWindow && hasSmallToolInput(target) || options.keepSkeleton === true || target.cannotRemove?.() === true || target.wouldStrandConversationEnd?.(plannedRemovals) === true) {
|
|
6962
7116
|
const strip = target.hasAttachments?.() === true;
|
|
6963
|
-
|
|
7117
|
+
const mode = strip ? "skeleton_stripped" : "skeleton_real";
|
|
6964
7118
|
return {
|
|
6965
|
-
|
|
6966
|
-
|
|
7119
|
+
mode,
|
|
7120
|
+
apply: () => ({
|
|
7121
|
+
result: (strip ? target.skeletonStripped?.() : target.skeletonReal?.()) ?? "absent",
|
|
7122
|
+
mode
|
|
7123
|
+
})
|
|
6967
7124
|
};
|
|
6968
7125
|
}
|
|
6969
|
-
|
|
6970
|
-
|
|
6971
|
-
|
|
6972
|
-
|
|
6973
|
-
|
|
6974
|
-
|
|
7126
|
+
return {
|
|
7127
|
+
mode: "full",
|
|
7128
|
+
apply: () => {
|
|
7129
|
+
const result = target.drop?.() ?? "absent";
|
|
7130
|
+
if (result === "truncated" && target.hasAttachments?.() === true) {
|
|
7131
|
+
return {
|
|
7132
|
+
result: target.skeletonStripped?.() ?? "absent",
|
|
7133
|
+
mode: "skeleton_stripped"
|
|
7134
|
+
};
|
|
7135
|
+
}
|
|
7136
|
+
return { result, mode: result === "truncated" ? "skeleton_real" : "full" };
|
|
7137
|
+
}
|
|
7138
|
+
};
|
|
6975
7139
|
}
|
|
6976
7140
|
function applyPersistedToolDrop(db, sessionId, tagNumber, target, options, afterWrite) {
|
|
6977
7141
|
return applyNewToolDrop(target, {
|
|
@@ -7065,6 +7229,7 @@ function renderConvertedToolSkeletons(targets, converted) {
|
|
|
7065
7229
|
}
|
|
7066
7230
|
return didMutate;
|
|
7067
7231
|
}
|
|
7232
|
+
var PENDING_OPERATION_CHUNK_SIZE = 64;
|
|
7068
7233
|
function applyPendingOperations(sessionId, db, targets, protectedTagIds, preloadedTags, preloadedPendingOps, syntheticPendingOps = [], editMarkerTagIds = new Set, onTagReduced, onBatchComplete, onEligibilitySnapshot) {
|
|
7069
7234
|
let didMutateMessage = false;
|
|
7070
7235
|
let diagnostics;
|
|
@@ -7074,153 +7239,184 @@ function applyPendingOperations(sessionId, db, targets, protectedTagIds, preload
|
|
|
7074
7239
|
diagnostics.reasons[reason] = (diagnostics.reasons[reason] ?? 0) + 1;
|
|
7075
7240
|
};
|
|
7076
7241
|
let admitted = false;
|
|
7077
|
-
|
|
7078
|
-
|
|
7079
|
-
|
|
7080
|
-
|
|
7081
|
-
|
|
7082
|
-
|
|
7083
|
-
|
|
7084
|
-
|
|
7085
|
-
|
|
7086
|
-
|
|
7087
|
-
|
|
7088
|
-
|
|
7089
|
-
|
|
7090
|
-
|
|
7091
|
-
const tagStatusById = new Map(tags.map((tag) => [tag.tagNumber, tag.status]));
|
|
7092
|
-
const tagTypeById = new Map(tags.map((tag) => [tag.tagNumber, tag.type]));
|
|
7093
|
-
const opsToApply = [
|
|
7094
|
-
...pendingOps.map((op) => ({ op, synthetic: false })),
|
|
7095
|
-
...syntheticPendingOps.map((op) => ({ op, synthetic: true }))
|
|
7096
|
-
];
|
|
7097
|
-
diagnostics = {
|
|
7098
|
-
source: pendingOps.length > 0 && syntheticPendingOps.length > 0 ? "mixed" : syntheticPendingOps.length > 0 ? "synthetic" : "pending",
|
|
7099
|
-
total: opsToApply.length,
|
|
7100
|
-
mutated: 0,
|
|
7101
|
-
persistedWithoutMutation: 0,
|
|
7102
|
-
reasons: {}
|
|
7103
|
-
};
|
|
7104
|
-
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));
|
|
7105
|
-
for (const { op: pendingOp, synthetic } of opsToApply) {
|
|
7106
|
-
let operationMutated = false;
|
|
7107
|
-
const tagStatus = tagStatusById.get(pendingOp.tagId);
|
|
7108
|
-
if (tagStatus === "compacted" || tagStatus === "dropped") {
|
|
7109
|
-
reject("already_reduced");
|
|
7110
|
-
if (!synthetic)
|
|
7111
|
-
removePendingOp(db, sessionId, pendingOp.tagId);
|
|
7112
|
-
continue;
|
|
7113
|
-
}
|
|
7114
|
-
const target = targets.get(pendingOp.tagId);
|
|
7115
|
-
const veto = pendingDropVeto(pendingOp.tagId, target, protectedTagIds);
|
|
7116
|
-
if (veto) {
|
|
7117
|
-
reject(veto);
|
|
7118
|
-
continue;
|
|
7119
|
-
}
|
|
7120
|
-
const isToolTag = tagTypeById.get(pendingOp.tagId) === "tool";
|
|
7121
|
-
if (synthetic) {
|
|
7122
|
-
if (!isToolTag) {
|
|
7123
|
-
reject("synthetic_non_tool");
|
|
7124
|
-
continue;
|
|
7125
|
-
}
|
|
7126
|
-
if (target?.canDrop?.() !== true) {
|
|
7127
|
-
reject("synthetic_target_not_droppable");
|
|
7128
|
-
continue;
|
|
7129
|
-
}
|
|
7242
|
+
let startedAt = 0;
|
|
7243
|
+
const mutations = [];
|
|
7244
|
+
let drainChunk;
|
|
7245
|
+
let hasMore = false;
|
|
7246
|
+
do {
|
|
7247
|
+
admitted = false;
|
|
7248
|
+
startedAt = 0;
|
|
7249
|
+
try {
|
|
7250
|
+
db.transaction(() => {
|
|
7251
|
+
admitted = true;
|
|
7252
|
+
startedAt = performance.now();
|
|
7253
|
+
if (drainChunk) {
|
|
7254
|
+
drainChunk();
|
|
7255
|
+
return;
|
|
7130
7256
|
}
|
|
7131
|
-
const
|
|
7132
|
-
|
|
7133
|
-
|
|
7134
|
-
|
|
7135
|
-
|
|
7136
|
-
|
|
7257
|
+
const pendingOps = preloadedPendingOps ?? getPendingOps(db, sessionId);
|
|
7258
|
+
onEligibilitySnapshot?.(capturePendingDropEligibility(targets, protectedTagIds));
|
|
7259
|
+
const tags = preloadedTags ?? getTagsByNumbers2(db, sessionId, [
|
|
7260
|
+
...new Set([
|
|
7261
|
+
...pendingOps.map((op) => op.tagId),
|
|
7262
|
+
...syntheticPendingOps.map((op) => op.tagId)
|
|
7263
|
+
])
|
|
7264
|
+
]);
|
|
7265
|
+
const tagById = new Map(tags.map((tag) => [tag.tagNumber, tag]));
|
|
7266
|
+
const tagStatusById = new Map(tags.map((tag) => [tag.tagNumber, tag.status]));
|
|
7267
|
+
const tagTypeById = new Map(tags.map((tag) => [tag.tagNumber, tag.type]));
|
|
7268
|
+
const opsToApply = [
|
|
7269
|
+
...pendingOps.map((op) => ({ op, synthetic: false })),
|
|
7270
|
+
...syntheticPendingOps.map((op) => ({ op, synthetic: true }))
|
|
7271
|
+
];
|
|
7272
|
+
diagnostics = {
|
|
7273
|
+
source: pendingOps.length > 0 && syntheticPendingOps.length > 0 ? "mixed" : syntheticPendingOps.length > 0 ? "synthetic" : "pending",
|
|
7274
|
+
total: opsToApply.length,
|
|
7275
|
+
mutated: 0,
|
|
7276
|
+
persistedWithoutMutation: 0,
|
|
7277
|
+
reasons: {}
|
|
7278
|
+
};
|
|
7279
|
+
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));
|
|
7280
|
+
const plannedRemovals = new Set;
|
|
7281
|
+
const removedTagIds = new Set;
|
|
7282
|
+
const record = (mutated) => {
|
|
7283
|
+
if (!diagnostics)
|
|
7284
|
+
return;
|
|
7285
|
+
if (mutated) {
|
|
7286
|
+
didMutateMessage = true;
|
|
7287
|
+
diagnostics.mutated += 1;
|
|
7288
|
+
} else
|
|
7289
|
+
diagnostics.persistedWithoutMutation += 1;
|
|
7290
|
+
};
|
|
7291
|
+
let cursor = 0;
|
|
7292
|
+
drainChunk = () => {
|
|
7293
|
+
const chunk = opsToApply.slice(cursor, cursor + PENDING_OPERATION_CHUNK_SIZE);
|
|
7294
|
+
cursor += chunk.length;
|
|
7295
|
+
hasMore = cursor < opsToApply.length;
|
|
7296
|
+
for (const { op: pendingOp, synthetic } of chunk) {
|
|
7297
|
+
const tagStatus = tagStatusById.get(pendingOp.tagId);
|
|
7298
|
+
if (tagStatus === "compacted" || tagStatus === "dropped") {
|
|
7299
|
+
reject("already_reduced");
|
|
7137
7300
|
if (!synthetic)
|
|
7138
7301
|
removePendingOp(db, sessionId, pendingOp.tagId);
|
|
7139
|
-
}).immediate();
|
|
7140
|
-
} finally {
|
|
7141
|
-
if (startedAt)
|
|
7142
|
-
logSlowWriteTransaction("apply_pending_operation", startedAt);
|
|
7143
|
-
}
|
|
7144
|
-
};
|
|
7145
|
-
let shouldPersistDrop = false;
|
|
7146
|
-
if (isToolTag) {
|
|
7147
|
-
if (editMarkerTagIds.has(pendingOp.tagId)) {
|
|
7148
|
-
const strip = target?.hasAttachments?.() === true;
|
|
7149
|
-
if (target?.canDrop?.() === false || target?.prepareDrop?.() === false || !target) {
|
|
7150
|
-
reject("edit_marker_incomplete");
|
|
7151
7302
|
continue;
|
|
7152
7303
|
}
|
|
7153
|
-
|
|
7154
|
-
|
|
7155
|
-
if (markResult === "incomplete" || markResult === "absent") {
|
|
7156
|
-
reject(`edit_marker_${markResult}`);
|
|
7304
|
+
if (removedTagIds.has(pendingOp.tagId)) {
|
|
7305
|
+
reject("drop_incomplete");
|
|
7157
7306
|
continue;
|
|
7158
7307
|
}
|
|
7159
|
-
|
|
7160
|
-
|
|
7161
|
-
|
|
7162
|
-
|
|
7163
|
-
} else {
|
|
7164
|
-
const { result: dropResult, mode: appliedMode } = applyNewToolDrop(target, {
|
|
7165
|
-
inWindow: skeletonWindow.has(pendingOp.tagId),
|
|
7166
|
-
persist: persistDrop
|
|
7167
|
-
});
|
|
7168
|
-
if (dropResult === "incomplete" || synthetic && dropResult !== "removed" && dropResult !== "truncated") {
|
|
7169
|
-
reject(`drop_${dropResult}`);
|
|
7308
|
+
const target = targets.get(pendingOp.tagId);
|
|
7309
|
+
const veto = pendingDropVeto(pendingOp.tagId, target, protectedTagIds);
|
|
7310
|
+
if (veto) {
|
|
7311
|
+
reject(veto);
|
|
7170
7312
|
continue;
|
|
7171
7313
|
}
|
|
7172
|
-
|
|
7173
|
-
|
|
7174
|
-
|
|
7175
|
-
|
|
7176
|
-
|
|
7177
|
-
|
|
7314
|
+
const isToolTag = tagTypeById.get(pendingOp.tagId) === "tool";
|
|
7315
|
+
if (synthetic) {
|
|
7316
|
+
if (!isToolTag) {
|
|
7317
|
+
reject("synthetic_non_tool");
|
|
7318
|
+
continue;
|
|
7319
|
+
}
|
|
7320
|
+
if (target?.canDrop?.() !== true) {
|
|
7321
|
+
reject("synthetic_target_not_droppable");
|
|
7322
|
+
continue;
|
|
7323
|
+
}
|
|
7324
|
+
}
|
|
7325
|
+
const persistDrop = (mode) => {
|
|
7326
|
+
markTagDropped2(db, sessionId, pendingOp.tagId, mode);
|
|
7327
|
+
if (!synthetic)
|
|
7328
|
+
removePendingOp(db, sessionId, pendingOp.tagId);
|
|
7329
|
+
};
|
|
7330
|
+
if (isToolTag) {
|
|
7331
|
+
if (editMarkerTagIds.has(pendingOp.tagId)) {
|
|
7332
|
+
const strip = target?.hasAttachments?.() === true;
|
|
7333
|
+
if (target?.canDrop?.() === false || target?.prepareDrop?.() === false || !target) {
|
|
7334
|
+
reject("edit_marker_incomplete");
|
|
7335
|
+
continue;
|
|
7336
|
+
}
|
|
7337
|
+
persistDrop(strip ? "edit_marker_stripped" : "edit_marker");
|
|
7338
|
+
mutations.push(() => {
|
|
7339
|
+
const markResult = (strip ? target?.editMarkerStripped?.() : target?.editMarker?.()) ?? "absent";
|
|
7340
|
+
if (markResult === "incomplete" || markResult === "absent") {
|
|
7341
|
+
reject(`edit_marker_${markResult}`);
|
|
7342
|
+
return;
|
|
7343
|
+
}
|
|
7344
|
+
record(true);
|
|
7345
|
+
onTagReduced?.({
|
|
7346
|
+
tagNumber: pendingOp.tagId,
|
|
7347
|
+
mode: "edit_marker"
|
|
7348
|
+
});
|
|
7349
|
+
});
|
|
7350
|
+
} else {
|
|
7351
|
+
const plan = planNewToolDrop(target, { inWindow: skeletonWindow.has(pendingOp.tagId) }, true, plannedRemovals);
|
|
7352
|
+
if (!plan) {
|
|
7353
|
+
reject("drop_incomplete");
|
|
7354
|
+
continue;
|
|
7355
|
+
}
|
|
7356
|
+
persistDrop(plan.mode);
|
|
7357
|
+
if (plan.mode === "full" && target?.drop) {
|
|
7358
|
+
target.notePlannedRemoval?.(plannedRemovals);
|
|
7359
|
+
removedTagIds.add(pendingOp.tagId);
|
|
7360
|
+
}
|
|
7361
|
+
mutations.push(() => {
|
|
7362
|
+
const { result: dropResult, mode: appliedMode } = plan.apply();
|
|
7363
|
+
if (dropResult === "incomplete" || synthetic && dropResult !== "removed" && dropResult !== "truncated") {
|
|
7364
|
+
reject(`drop_${dropResult}`);
|
|
7365
|
+
return;
|
|
7366
|
+
}
|
|
7367
|
+
if (dropResult === "removed" || dropResult === "truncated") {
|
|
7368
|
+
record(true);
|
|
7369
|
+
onTagReduced?.({
|
|
7370
|
+
tagNumber: pendingOp.tagId,
|
|
7371
|
+
mode: appliedMode === "full" ? "full" : "truncated"
|
|
7372
|
+
});
|
|
7373
|
+
} else {
|
|
7374
|
+
reject(`drop_${dropResult}`);
|
|
7375
|
+
record(false);
|
|
7376
|
+
}
|
|
7377
|
+
});
|
|
7378
|
+
}
|
|
7379
|
+
} else if (target) {
|
|
7380
|
+
const replacement = buildReplacementContent(pendingOp.tagId);
|
|
7381
|
+
persistDrop();
|
|
7382
|
+
mutations.push(() => {
|
|
7383
|
+
const priorContent = target.getContent?.();
|
|
7384
|
+
const changed = target.setContent(replacement);
|
|
7385
|
+
record(changed);
|
|
7386
|
+
if (changed) {
|
|
7387
|
+
const originalCharacters = typeof priorContent === "string" ? priorContent.length : tagById.get(pendingOp.tagId)?.byteSize ?? replacement.length;
|
|
7388
|
+
onTagReduced?.({
|
|
7389
|
+
tagNumber: pendingOp.tagId,
|
|
7390
|
+
mode: "partial",
|
|
7391
|
+
removedCharacters: Math.max(0, originalCharacters - replacement.length)
|
|
7392
|
+
});
|
|
7393
|
+
} else {
|
|
7394
|
+
reject("content_unchanged");
|
|
7395
|
+
}
|
|
7178
7396
|
});
|
|
7179
|
-
} else {
|
|
7180
|
-
reject(
|
|
7397
|
+
} else if (!synthetic) {
|
|
7398
|
+
reject("target_absent");
|
|
7399
|
+
persistDrop();
|
|
7400
|
+
mutations.push(() => record(false));
|
|
7181
7401
|
}
|
|
7182
|
-
shouldPersistDrop = true;
|
|
7183
|
-
}
|
|
7184
|
-
} else if (target) {
|
|
7185
|
-
const replacement = buildReplacementContent(pendingOp.tagId);
|
|
7186
|
-
const priorContent = target.getContent?.();
|
|
7187
|
-
persistDrop();
|
|
7188
|
-
const changed = target.setContent(replacement);
|
|
7189
|
-
if (changed) {
|
|
7190
|
-
didMutateMessage = true;
|
|
7191
|
-
operationMutated = true;
|
|
7192
|
-
const originalCharacters = typeof priorContent === "string" ? priorContent.length : tagById.get(pendingOp.tagId)?.byteSize ?? replacement.length;
|
|
7193
|
-
onTagReduced?.({
|
|
7194
|
-
tagNumber: pendingOp.tagId,
|
|
7195
|
-
mode: "partial",
|
|
7196
|
-
removedCharacters: Math.max(0, originalCharacters - replacement.length)
|
|
7197
|
-
});
|
|
7198
|
-
} else {
|
|
7199
|
-
reject("content_unchanged");
|
|
7200
7402
|
}
|
|
7201
|
-
|
|
7202
|
-
|
|
7203
|
-
|
|
7204
|
-
|
|
7205
|
-
|
|
7206
|
-
|
|
7207
|
-
|
|
7208
|
-
|
|
7209
|
-
|
|
7210
|
-
}
|
|
7211
|
-
if (operationMutated)
|
|
7212
|
-
diagnostics.mutated += 1;
|
|
7213
|
-
else
|
|
7214
|
-
diagnostics.persistedWithoutMutation += 1;
|
|
7403
|
+
};
|
|
7404
|
+
drainChunk();
|
|
7405
|
+
}).immediate();
|
|
7406
|
+
} catch (error) {
|
|
7407
|
+
if (!admitted && /database (?:table )?is locked|sqlite_(busy|locked)/i.test(String(error))) {
|
|
7408
|
+
sessionLog2(sessionId, "pending operations write admission busy; retaining remaining operations for retry");
|
|
7409
|
+
hasMore = false;
|
|
7410
|
+
} else {
|
|
7411
|
+
throw error;
|
|
7215
7412
|
}
|
|
7413
|
+
} finally {
|
|
7414
|
+
if (startedAt)
|
|
7415
|
+
logSlowWriteTransaction("apply_pending_operations", startedAt);
|
|
7216
7416
|
}
|
|
7217
|
-
|
|
7218
|
-
|
|
7219
|
-
|
|
7220
|
-
return false;
|
|
7221
|
-
}
|
|
7222
|
-
throw error;
|
|
7223
|
-
}
|
|
7417
|
+
for (const mutate of mutations.splice(0))
|
|
7418
|
+
mutate();
|
|
7419
|
+
} while (hasMore);
|
|
7224
7420
|
if (diagnostics) {
|
|
7225
7421
|
onBatchComplete?.(diagnostics);
|
|
7226
7422
|
if (diagnostics.total > 0 && diagnostics.mutated === 0) {
|
|
@@ -8472,10 +8668,41 @@ function createExistingTagResolver(sessionId, tagger, db) {
|
|
|
8472
8668
|
}
|
|
8473
8669
|
|
|
8474
8670
|
// src/hooks/magic-context/transform-stage-logger.ts
|
|
8475
|
-
|
|
8476
|
-
|
|
8671
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
8672
|
+
var SLOW_STAGE_MS = 100;
|
|
8673
|
+
var passes = new AsyncLocalStorage;
|
|
8674
|
+
async function withTransformTimingSummary(run) {
|
|
8675
|
+
const pass = {
|
|
8676
|
+
stages: [],
|
|
8677
|
+
slow: [],
|
|
8678
|
+
closed: false,
|
|
8679
|
+
sessionId: undefined
|
|
8680
|
+
};
|
|
8681
|
+
return passes.run(pass, async () => {
|
|
8682
|
+
try {
|
|
8683
|
+
return await run();
|
|
8684
|
+
} finally {
|
|
8685
|
+
pass.closed = true;
|
|
8686
|
+
if (pass.sessionId)
|
|
8687
|
+
sessionLog2(pass.sessionId, `transform stages: ${pass.stages.join(" ")} slow>=${SLOW_STAGE_MS}ms=[${pass.slow.join(",")}]`);
|
|
8688
|
+
}
|
|
8689
|
+
});
|
|
8690
|
+
}
|
|
8691
|
+
function logTransformElapsed(sessionId, stage, elapsedMs, extra) {
|
|
8692
|
+
const elapsed = elapsedMs.toFixed(1);
|
|
8477
8693
|
const suffix = extra ? ` ${extra}` : "";
|
|
8478
|
-
|
|
8694
|
+
const pass = passes.getStore();
|
|
8695
|
+
if (pass && !pass.closed) {
|
|
8696
|
+
pass.sessionId = sessionId;
|
|
8697
|
+
pass.stages.push(`${stage}=${elapsed}ms${extra ? `(${extra})` : ""}`);
|
|
8698
|
+
if (elapsedMs >= SLOW_STAGE_MS)
|
|
8699
|
+
pass.slow.push(stage);
|
|
8700
|
+
}
|
|
8701
|
+
if (elapsedMs >= SLOW_STAGE_MS)
|
|
8702
|
+
sessionLog2(sessionId, `transform stage: stage=${stage} elapsed=${elapsed}ms${suffix}`);
|
|
8703
|
+
}
|
|
8704
|
+
function logTransformTiming(sessionId, stage, startMs, extra) {
|
|
8705
|
+
logTransformElapsed(sessionId, stage, performance.now() - startMs, extra);
|
|
8479
8706
|
}
|
|
8480
8707
|
|
|
8481
8708
|
// src/hooks/magic-context/tag-messages.ts
|
|
@@ -8841,13 +9068,18 @@ function tagMessages(sessionId, messages, tagger, db, options = {}) {
|
|
|
8841
9068
|
}));
|
|
8842
9069
|
accAssignTag += performance.now() - _tAssignText;
|
|
8843
9070
|
const persistedSource = sourceContents.get(tagId);
|
|
8844
|
-
if (persistedSource !== undefined) {
|
|
9071
|
+
if (persistedSource !== undefined && !options.refreshSourceContents) {
|
|
8845
9072
|
textPart.text = options.normalizeRestoredAssistantText && message.info.role === "assistant" ? options.normalizeRestoredAssistantText(persistedSource) : persistedSource;
|
|
8846
9073
|
} else {
|
|
8847
9074
|
const sourceContent = stripTagPrefix(textPart.text);
|
|
8848
|
-
if (sourceContent.trim().length > 0) {
|
|
9075
|
+
if (sourceContent.trim().length > 0 || options.refreshSourceContents) {
|
|
8849
9076
|
const _tSaveText = performance.now();
|
|
8850
|
-
|
|
9077
|
+
if (options.refreshSourceContents) {
|
|
9078
|
+
replaceSourceContent(db, sessionId, tagId, sourceContent);
|
|
9079
|
+
updateTagByteSize2(db, sessionId, tagId, byteSize(sourceContent));
|
|
9080
|
+
updateTagTokenCount2(db, sessionId, tagId, estimateTextTagTokenCount(sourceContent));
|
|
9081
|
+
} else
|
|
9082
|
+
saveSourceContent(db, sessionId, tagId, sourceContent);
|
|
8851
9083
|
accSaveSource += performance.now() - _tSaveText;
|
|
8852
9084
|
}
|
|
8853
9085
|
}
|
|
@@ -8940,7 +9172,10 @@ function tagMessages(sessionId, messages, tagger, db, options = {}) {
|
|
|
8940
9172
|
const sourceContent = buildFileSourceContent(message.parts);
|
|
8941
9173
|
if (sourceContent) {
|
|
8942
9174
|
const _tSaveFile = performance.now();
|
|
8943
|
-
|
|
9175
|
+
if (options.refreshSourceContents)
|
|
9176
|
+
replaceSourceContent(db, sessionId, tagId, sourceContent);
|
|
9177
|
+
else
|
|
9178
|
+
saveSourceContent(db, sessionId, tagId, sourceContent);
|
|
8944
9179
|
accSaveSource += performance.now() - _tSaveFile;
|
|
8945
9180
|
}
|
|
8946
9181
|
}
|
|
@@ -9781,6 +10016,9 @@ async function runPostTransformPhase(args) {
|
|
|
9781
10016
|
rewritingSignedPrefix = true;
|
|
9782
10017
|
thinkingReleasedForFit ||= forFit;
|
|
9783
10018
|
};
|
|
10019
|
+
if (activeThinkingPrefixHold && args.forceSignedRebuildForFit) {
|
|
10020
|
+
releaseThinkingForRewrite(true);
|
|
10021
|
+
}
|
|
9784
10022
|
const foldDueDecision = m0M1EnabledForFold && args.m0M1 && !freezeM0M1 ? mustMaterialize({
|
|
9785
10023
|
db: args.db,
|
|
9786
10024
|
sessionId: args.sessionId,
|
|
@@ -9925,7 +10163,7 @@ async function runPostTransformPhase(args) {
|
|
|
9925
10163
|
const idleExpiryRebuild = (!freezeM0M1 || activeThinkingPrefixHold) && args.m0M1?.hardSignals?.cacheExpired === true;
|
|
9926
10164
|
const rideSignals = {
|
|
9927
10165
|
subagentExecute: !args.fullFeatureMode && args.schedulerDecision === "execute",
|
|
9928
|
-
hardFold: foldBustsServedPrefixThisPass || firstRenderBust || idleExpiryRebuild,
|
|
10166
|
+
hardFold: rewritingSignedPrefix || foldBustsServedPrefixThisPass || firstRenderBust || idleExpiryRebuild,
|
|
9929
10167
|
force: emergencyDropEligible && (args.contextUsage.percentage >= 95 || getEmergencyInputSample(args.db, args.sessionId) === 0),
|
|
9930
10168
|
explicitFlush: isExplicitFlush && hasPendingMaterializationOrigin(args.pendingMaterializationSessions, args.sessionId, "user_flush"),
|
|
9931
10169
|
publishedHistory: !prefixPreflightFailed && (publishedM1RefreshedThisPass || !m0M1EnabledForFold && (args.pendingCompartmentInjection?.compartmentCount ?? 0) > 0 && legacyPublishedHeadChanged(args))
|
|
@@ -11184,6 +11422,26 @@ function systemPromptDates(prompt, sticky) {
|
|
|
11184
11422
|
return { live: values.length ? JSON.stringify(values) : undefined, stable };
|
|
11185
11423
|
}
|
|
11186
11424
|
|
|
11425
|
+
// src/hooks/magic-context/system-prompt-diagnostics.ts
|
|
11426
|
+
import { createHash } from "node:crypto";
|
|
11427
|
+
function snapshotSystemPrompt(system, preset) {
|
|
11428
|
+
return { elements: system.map((element) => Buffer.from(element)), preset };
|
|
11429
|
+
}
|
|
11430
|
+
function describeSystemPromptChange(previous, current) {
|
|
11431
|
+
const metadata = (element) => element === undefined ? "absent" : `bytes=${element.length},md5=${createHash("md5").update(element).digest("hex")}`;
|
|
11432
|
+
const elements = [];
|
|
11433
|
+
for (let index = 0;index < Math.max(previous?.elements.length ?? 0, current.elements.length); index++) {
|
|
11434
|
+
const before = previous?.elements[index];
|
|
11435
|
+
const after = current.elements[index];
|
|
11436
|
+
let offset = 0;
|
|
11437
|
+
while (before && after && offset < Math.min(before.length, after.length) && before[offset] === after[offset])
|
|
11438
|
+
offset++;
|
|
11439
|
+
const status = !previous ? "unknown" : !before ? "added" : !after ? "removed" : before.equals(after) ? "unchanged" : "changed";
|
|
11440
|
+
elements.push(`${index}:${status}(${metadata(before)} -> ${metadata(after)},firstDiffByte=${!previous ? "unknown" : status === "unchanged" ? "none" : offset})`);
|
|
11441
|
+
}
|
|
11442
|
+
return `presetChanged=${previous ? previous.preset !== current.preset : "unknown"} elements=[${elements.join("; ")}]`;
|
|
11443
|
+
}
|
|
11444
|
+
|
|
11187
11445
|
// src/hooks/magic-context/system-date-refresh.ts
|
|
11188
11446
|
var channels = new WeakMap;
|
|
11189
11447
|
var outputUpdates = new WeakMap;
|
|
@@ -11341,6 +11599,7 @@ function createSystemPromptHashHandler(deps) {
|
|
|
11341
11599
|
});
|
|
11342
11600
|
const guidanceEpochs = createPromptSurfaceGuidanceEpochCache(promptSurfaceRuntime);
|
|
11343
11601
|
const stickyDateBySession = new Map;
|
|
11602
|
+
const diagnosticPrompts = new Map;
|
|
11344
11603
|
const processSystemPrompt = async (input, output) => {
|
|
11345
11604
|
const sessionId = input.sessionID;
|
|
11346
11605
|
if (!sessionId)
|
|
@@ -11473,8 +11732,11 @@ function createSystemPromptHashHandler(deps) {
|
|
|
11473
11732
|
return;
|
|
11474
11733
|
}
|
|
11475
11734
|
const sessionMeta = sessionMetaEarly;
|
|
11735
|
+
const previousPrompt = diagnosticPrompts.get(sessionId);
|
|
11736
|
+
const currentPrompt = previousPrompt && previousHash === currentHash ? previousPrompt : snapshotSystemPrompt(output.system, promptSurface.preset);
|
|
11737
|
+
diagnosticPrompts.set(sessionId, currentPrompt);
|
|
11476
11738
|
if (previousHash !== "" && previousHash !== "0" && previousHash !== currentHash) {
|
|
11477
|
-
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"}`);
|
|
11739
|
+
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)}`);
|
|
11478
11740
|
noteSystemPromptHashChange(sessionId);
|
|
11479
11741
|
if (!adoptSystemChange) {
|
|
11480
11742
|
deps.historyRefreshSessions.add(sessionId);
|
|
@@ -11518,6 +11780,7 @@ function createSystemPromptHashHandler(deps) {
|
|
|
11518
11780
|
return {
|
|
11519
11781
|
handler,
|
|
11520
11782
|
clearSession: (sessionId) => {
|
|
11783
|
+
diagnosticPrompts.delete(sessionId);
|
|
11521
11784
|
clearSystemDateRefresh(deps.historyRefreshSessions, sessionId);
|
|
11522
11785
|
guidanceEpochs.clear(sessionId);
|
|
11523
11786
|
clearSystemPromptHashSession(sessionId, {
|
|
@@ -11747,7 +12010,7 @@ function createPassOutcome() {
|
|
|
11747
12010
|
}
|
|
11748
12011
|
|
|
11749
12012
|
// src/hooks/magic-context/rust-mode-transform.ts
|
|
11750
|
-
import { createHash as
|
|
12013
|
+
import { createHash as createHash5, randomUUID as randomUUID2 } from "node:crypto";
|
|
11751
12014
|
|
|
11752
12015
|
// src/features/magic-context/memory/single-store-embedding-drain.ts
|
|
11753
12016
|
function isWatermarkRow(row) {
|
|
@@ -11811,7 +12074,7 @@ function advanceEmbeddedWatermark(db, projectPath, upTo) {
|
|
|
11811
12074
|
}
|
|
11812
12075
|
|
|
11813
12076
|
// src/features/magic-context/mural/source-revision.ts
|
|
11814
|
-
import { createHash } from "node:crypto";
|
|
12077
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
11815
12078
|
var statements = new WeakMap;
|
|
11816
12079
|
function muralSourceRevision(db, projectPath) {
|
|
11817
12080
|
let statement = statements.get(db);
|
|
@@ -11828,7 +12091,7 @@ function muralSourceRevision(db, projectPath) {
|
|
|
11828
12091
|
statements.set(db, statement);
|
|
11829
12092
|
}
|
|
11830
12093
|
const row = statement.get(projectPath, Date.now());
|
|
11831
|
-
return
|
|
12094
|
+
return createHash2("sha256").update(row.revision).digest("hex");
|
|
11832
12095
|
}
|
|
11833
12096
|
|
|
11834
12097
|
// src/features/magic-context/install-instance-id.ts
|
|
@@ -12255,6 +12518,7 @@ class HistorianHostRunner {
|
|
|
12255
12518
|
throw new Error("hidden completion carrier returned no session id");
|
|
12256
12519
|
const run = await promptSyncWithValidatedOutputRetry(undefined, {
|
|
12257
12520
|
path: { id: handle.id },
|
|
12521
|
+
cacheTail: "skip",
|
|
12258
12522
|
query: { directory: sessionDirectory },
|
|
12259
12523
|
body: {
|
|
12260
12524
|
agent: "historian",
|
|
@@ -12285,6 +12549,7 @@ class HistorianHostRunner {
|
|
|
12285
12549
|
timeoutMs: attemptMs,
|
|
12286
12550
|
signal,
|
|
12287
12551
|
fallbackModels: rest.map(withVariant),
|
|
12552
|
+
allowModelSuggestions: false,
|
|
12288
12553
|
callContext: `historian-host:${claim.runId}`,
|
|
12289
12554
|
fetchOutput: () => withinAttempt(executor.collect(handle, 50), attemptStartedAt + attemptMs - Date.now(), attemptMs, signal).catch((error) => {
|
|
12290
12555
|
recordAttempt(undefined, error);
|
|
@@ -14202,7 +14467,7 @@ function noteExternalLkgReplay(participant, sessionId, inputMessages, servedMess
|
|
|
14202
14467
|
}
|
|
14203
14468
|
|
|
14204
14469
|
// src/hooks/magic-context/rust-served-raw.ts
|
|
14205
|
-
import { createHash as
|
|
14470
|
+
import { createHash as createHash4 } from "node:crypto";
|
|
14206
14471
|
class RustServedRawConflict extends EmergencyFailClosedError {
|
|
14207
14472
|
reason;
|
|
14208
14473
|
messageIds;
|
|
@@ -14216,7 +14481,7 @@ class RustServedRawConflict extends EmergencyFailClosedError {
|
|
|
14216
14481
|
}
|
|
14217
14482
|
function partDigest(part) {
|
|
14218
14483
|
const serialized = JSON.stringify(part);
|
|
14219
|
-
return
|
|
14484
|
+
return createHash4("sha256").update(stableStringify(serialized === undefined ? undefined : JSON.parse(serialized))).digest("hex");
|
|
14220
14485
|
}
|
|
14221
14486
|
function records(doc) {
|
|
14222
14487
|
if (doc.rustServedRaw === undefined)
|
|
@@ -14704,10 +14969,10 @@ function messageCacheSignature(message) {
|
|
|
14704
14969
|
const parts = Array.isArray(message.parts) ? message.parts : [];
|
|
14705
14970
|
const serializedParts = JSON.stringify(parts) ?? "null";
|
|
14706
14971
|
const serializedMessage = JSON.stringify(message) ?? "null";
|
|
14707
|
-
return `${messageIdOf(message) ?? ""}:${parts.length}:${Buffer.byteLength(serializedParts)}:${
|
|
14972
|
+
return `${messageIdOf(message) ?? ""}:${parts.length}:${Buffer.byteLength(serializedParts)}:${createHash5("sha256").update(serializedMessage).digest("hex")}`;
|
|
14708
14973
|
}
|
|
14709
14974
|
function advanceWireFingerprint(previous, encoded) {
|
|
14710
|
-
return
|
|
14975
|
+
return createHash5("sha256").update(previous).update("\\0").update(JSON.stringify(encoded) ?? "null").digest("hex");
|
|
14711
14976
|
}
|
|
14712
14977
|
function buildWireFingerprint(encoded) {
|
|
14713
14978
|
let fingerprint = "rust-wire-v1";
|
|
@@ -16488,7 +16753,7 @@ function createRustModeTransform(deps, options) {
|
|
|
16488
16753
|
const id = messageIdOf(message) ?? `index:${todoStart + offset}`;
|
|
16489
16754
|
const parts = message.parts?.filter((part) => isRecord4(part) && part.type === "tool" && part.tool === "todowrite");
|
|
16490
16755
|
if (parts?.length) {
|
|
16491
|
-
todoCalls.set(id,
|
|
16756
|
+
todoCalls.set(id, createHash5("sha256").update(JSON.stringify(parts)).digest("hex"));
|
|
16492
16757
|
} else {
|
|
16493
16758
|
todoCalls.delete(id);
|
|
16494
16759
|
}
|
|
@@ -18126,6 +18391,7 @@ function resolveTransformHostSeams(deps) {
|
|
|
18126
18391
|
hostRefuse: deps.hostRefuse ?? abortSessionFailClosed
|
|
18127
18392
|
};
|
|
18128
18393
|
}
|
|
18394
|
+
var SIGNED_FIT_REFUSED_MARKER = "signed_fit:refused:v1";
|
|
18129
18395
|
function createTransform(deps) {
|
|
18130
18396
|
registerSystemDateRefresh(deps.historyRefreshSessions);
|
|
18131
18397
|
const finalWireUsage = createFinalWireUsageTracker();
|
|
@@ -18799,7 +19065,8 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
18799
19065
|
const tagged = tagMessages(sessionId, tail, deps.tagger, db, {
|
|
18800
19066
|
skipPrefixInjection: !ctxReduceCallable,
|
|
18801
19067
|
servedMessages: messages,
|
|
18802
|
-
normalizeRestoredAssistantText: deps.normalizeRestoredAssistantText
|
|
19068
|
+
normalizeRestoredAssistantText: deps.normalizeRestoredAssistantText,
|
|
19069
|
+
refreshSourceContents: deps.refreshSourceContents?.(sessionId)
|
|
18803
19070
|
});
|
|
18804
19071
|
for (const [number, target] of tagged.targets)
|
|
18805
19072
|
targets.set(number, target);
|
|
@@ -18824,7 +19091,8 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
18824
19091
|
skipPrefixInjection,
|
|
18825
19092
|
scopedToolSweep,
|
|
18826
19093
|
servedMessages: messages,
|
|
18827
|
-
normalizeRestoredAssistantText: deps.normalizeRestoredAssistantText
|
|
19094
|
+
normalizeRestoredAssistantText: deps.normalizeRestoredAssistantText,
|
|
19095
|
+
refreshSourceContents: deps.refreshSourceContents?.(sessionId)
|
|
18828
19096
|
});
|
|
18829
19097
|
targets = result.targets;
|
|
18830
19098
|
if (thinkingRecovery.restore)
|
|
@@ -19047,7 +19315,7 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
19047
19315
|
const protectedTagIds = protectedTagNumbers;
|
|
19048
19316
|
const protectedCutoff = protectionWindow.cutoff;
|
|
19049
19317
|
const tPostProcess = performance.now();
|
|
19050
|
-
dropProjectionEmergency =
|
|
19318
|
+
dropProjectionEmergency = contextUsage.percentage >= 95;
|
|
19051
19319
|
const postTransformResult = await runPostTransformPhase({
|
|
19052
19320
|
opencode2: deps.storeGeneration === "v2",
|
|
19053
19321
|
normalizeRecoveryTail,
|
|
@@ -19066,7 +19334,7 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
19066
19334
|
client: deps.client,
|
|
19067
19335
|
activeAgent,
|
|
19068
19336
|
batch,
|
|
19069
|
-
contextUsage
|
|
19337
|
+
contextUsage,
|
|
19070
19338
|
usableWindow: resolvedContextLimit ?? 0,
|
|
19071
19339
|
schedulerDecision,
|
|
19072
19340
|
schedulerDeferReason,
|
|
@@ -19151,6 +19419,7 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
19151
19419
|
postTransformResult.bustedThisPass = true;
|
|
19152
19420
|
passOutcome.markFinalized();
|
|
19153
19421
|
const finalWireTail = describeFinalWireTail(messages);
|
|
19422
|
+
const signedFitPreviouslyRefused = !compactionOff && getMergedReasoningStrippedIds(db, sessionId).has(SIGNED_FIT_REFUSED_MARKER);
|
|
19154
19423
|
let finalWireEstimate;
|
|
19155
19424
|
if (postTransformResult.bustedThisPass) {
|
|
19156
19425
|
try {
|
|
@@ -19168,7 +19437,7 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
19168
19437
|
}
|
|
19169
19438
|
if (!compactionOff) {
|
|
19170
19439
|
const emergencyUsagePercentage = usagePercentageSynthetic ? Math.max(95, contextUsage.percentage) : windowGeometry?.usableHard && contextUsage.inputTokens > 0 ? contextUsage.inputTokens / windowGeometry.usableHard * 100 : contextUsage.percentage;
|
|
19171
|
-
finalWireEstimate = finalWireEstimate ?? (emergencyUsagePercentage >= 95 || schedulerDecision === "execute" ? finalWireUsage.estimate(sessionId, {
|
|
19440
|
+
finalWireEstimate = finalWireEstimate ?? (emergencyUsagePercentage >= 95 || schedulerDecision === "execute" || signedFitPreviouslyRefused ? finalWireUsage.estimate(sessionId, {
|
|
19172
19441
|
messages,
|
|
19173
19442
|
systemPromptTokens: sessionMeta.systemPromptTokens,
|
|
19174
19443
|
providerID: modelForBudget?.providerID,
|
|
@@ -19191,8 +19460,11 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
19191
19460
|
}
|
|
19192
19461
|
return;
|
|
19193
19462
|
}
|
|
19194
|
-
if (thinkingFitRetries.has(sessionId) || postTransformResult.thinkingReleasedForFit)
|
|
19463
|
+
if (thinkingFitRetries.has(sessionId) || postTransformResult.thinkingReleasedForFit || signedFitPreviouslyRefused) {
|
|
19464
|
+
if (!signedFitPreviouslyRefused && !addMergedReasoningStrippedIds(db, sessionId, [SIGNED_FIT_REFUSED_MARKER]))
|
|
19465
|
+
throw contextRefusalError("Cannot persist the signed-fit refusal");
|
|
19195
19466
|
throw contextRefusalError("The request remains over the model window after stripping signed thinking and reclaiming context");
|
|
19467
|
+
}
|
|
19196
19468
|
}
|
|
19197
19469
|
if (postTransformResult.prefixTrimStatus === "refused") {
|
|
19198
19470
|
const untrimmed = finalWireEstimate ?? estimateFinalWireInputTokens({
|
|
@@ -19504,7 +19776,8 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
19504
19776
|
systemPromptHash: sessionMeta.systemPromptHash
|
|
19505
19777
|
});
|
|
19506
19778
|
};
|
|
19507
|
-
|
|
19779
|
+
const timedTransform = (input, output) => withTransformTimingSummary(() => transform(input, output));
|
|
19780
|
+
return Object.assign(timedTransform, {
|
|
19508
19781
|
clearSessionLogState,
|
|
19509
19782
|
invalidateRustWireState(sessionId) {
|
|
19510
19783
|
rustModeTransform?.invalidateWireState(sessionId);
|
|
@@ -21171,7 +21444,7 @@ function computeOpenCodeWorkMetricsIncremental(openCodeDb, sessionId, carry) {
|
|
|
21171
21444
|
import { readFileSync, statSync } from "node:fs";
|
|
21172
21445
|
|
|
21173
21446
|
// src/plugin/embedding-bootstrap-helpers.ts
|
|
21174
|
-
import { createHash as
|
|
21447
|
+
import { createHash as createHash6 } from "node:crypto";
|
|
21175
21448
|
var EMBEDDING_AFFECTING_KEYS = new Set([
|
|
21176
21449
|
"embedding.api_key",
|
|
21177
21450
|
"embedding.endpoint",
|
|
@@ -21219,7 +21492,7 @@ var EMBEDDING_WARNING_TERMS = [
|
|
|
21219
21492
|
];
|
|
21220
21493
|
var loggedFailureSignatures = new Map;
|
|
21221
21494
|
function sha256Prefix(value, length = 16) {
|
|
21222
|
-
return
|
|
21495
|
+
return createHash6("sha256").update(value).digest("hex").slice(0, length);
|
|
21223
21496
|
}
|
|
21224
21497
|
function warningLooksEmbeddingRelated(message) {
|
|
21225
21498
|
const lower = message.toLowerCase();
|
|
@@ -22726,8 +22999,8 @@ function registerRpcHandlers(rpcServer, args) {
|
|
|
22726
22999
|
const db = readDatabase();
|
|
22727
23000
|
if (!db)
|
|
22728
23001
|
return { ok: false, error: "db unavailable" };
|
|
22729
|
-
const { runManagedRecomp } = await importPluginModule(() => import("./recomp-orchestrator-
|
|
22730
|
-
const { sendIgnoredMessage } = await importPluginModule(() => import("./send-session-notification-
|
|
23002
|
+
const { runManagedRecomp } = await importPluginModule(() => import("./recomp-orchestrator-cmqnfpp3.js"));
|
|
23003
|
+
const { sendIgnoredMessage } = await importPluginModule(() => import("./send-session-notification-3pxn658x.js"));
|
|
22731
23004
|
log2(`[rpc] recomp requested for session ${sessionId}`);
|
|
22732
23005
|
if (!args.client && !args.hiddenCompletionExecutor) {
|
|
22733
23006
|
return {
|
|
@@ -22811,7 +23084,7 @@ function registerRpcHandlers(rpcServer, args) {
|
|
|
22811
23084
|
const db = readDatabase();
|
|
22812
23085
|
if (!db)
|
|
22813
23086
|
return { ok: false, error: "db unavailable" };
|
|
22814
|
-
const { runManagedWrapup } = await importPluginModule(() => import("./wrapup-orchestrator-
|
|
23087
|
+
const { runManagedWrapup } = await importPluginModule(() => import("./wrapup-orchestrator-xs8redz9.js"));
|
|
22815
23088
|
const model = liveSessionState.liveModelBySession.get(sessionId);
|
|
22816
23089
|
const contextLimit = model ? resolveContextLimit(model.providerID, model.modelID, { db, sessionID: sessionId }) : 128000;
|
|
22817
23090
|
const ctx = {
|
|
@@ -23183,7 +23456,58 @@ function readOmoDisabledHooks(directory) {
|
|
|
23183
23456
|
|
|
23184
23457
|
// src/shared/rpc-server.ts
|
|
23185
23458
|
import { randomBytes, timingSafeEqual } from "node:crypto";
|
|
23186
|
-
import { readdirSync, readFileSync as readFileSync4, unlinkSync } from "node:fs";
|
|
23459
|
+
import { readdirSync, readFileSync as readFileSync4, rmdirSync, unlinkSync } from "node:fs";
|
|
23460
|
+
|
|
23461
|
+
// src/shared/rpc-discovery-cleanup.ts
|
|
23462
|
+
import { promises as fs } from "node:fs";
|
|
23463
|
+
import { join as join6 } from "node:path";
|
|
23464
|
+
async function reapDeadRpcDiscovery(storageDir) {
|
|
23465
|
+
const root = join6(storageDir, "rpc");
|
|
23466
|
+
let directories;
|
|
23467
|
+
try {
|
|
23468
|
+
directories = await fs.readdir(root, { withFileTypes: true });
|
|
23469
|
+
} catch {
|
|
23470
|
+
return;
|
|
23471
|
+
}
|
|
23472
|
+
const records = [];
|
|
23473
|
+
const projectDirs = [];
|
|
23474
|
+
for (const entry of directories) {
|
|
23475
|
+
if (!entry.isDirectory() || !/^[0-9a-f]{16}$/.test(entry.name))
|
|
23476
|
+
continue;
|
|
23477
|
+
const directory = join6(root, entry.name);
|
|
23478
|
+
projectDirs.push(directory);
|
|
23479
|
+
try {
|
|
23480
|
+
for (const name of await fs.readdir(directory)) {
|
|
23481
|
+
const match = /^port-(\d+)(?:-[0-9a-f]+)?\.json$/.exec(name);
|
|
23482
|
+
if (!match)
|
|
23483
|
+
continue;
|
|
23484
|
+
const path = join6(directory, name);
|
|
23485
|
+
try {
|
|
23486
|
+
const content = await fs.readFile(path, "utf8");
|
|
23487
|
+
const record = parseRpcPortFile(content, Number(match[1]));
|
|
23488
|
+
if (record && record.pid === Number(match[1]))
|
|
23489
|
+
records.push({ path, content, pid: record.pid });
|
|
23490
|
+
} catch {}
|
|
23491
|
+
}
|
|
23492
|
+
} catch {}
|
|
23493
|
+
}
|
|
23494
|
+
const processes = records.length ? await inspectProcessesAsync(true) : undefined;
|
|
23495
|
+
for (const record of records) {
|
|
23496
|
+
if (processes?.liveness(record.pid) !== "dead")
|
|
23497
|
+
continue;
|
|
23498
|
+
try {
|
|
23499
|
+
if (await fs.readFile(record.path, "utf8") === record.content)
|
|
23500
|
+
await fs.unlink(record.path);
|
|
23501
|
+
} catch {}
|
|
23502
|
+
}
|
|
23503
|
+
for (const directory of projectDirs) {
|
|
23504
|
+
try {
|
|
23505
|
+
await fs.rmdir(directory);
|
|
23506
|
+
} catch {}
|
|
23507
|
+
}
|
|
23508
|
+
}
|
|
23509
|
+
|
|
23510
|
+
// src/shared/rpc-server.ts
|
|
23187
23511
|
var MAX_BODY_BYTES = 1048576;
|
|
23188
23512
|
var WS_AUTH_TIMEOUT_MS = 5000;
|
|
23189
23513
|
var WS_CLOSE_UNAUTHORIZED = 4401;
|
|
@@ -23206,17 +23530,20 @@ function websocketToken(req) {
|
|
|
23206
23530
|
}
|
|
23207
23531
|
|
|
23208
23532
|
class MagicContextRpcServer {
|
|
23533
|
+
storageDir;
|
|
23209
23534
|
server = null;
|
|
23210
23535
|
port = 0;
|
|
23211
23536
|
handlers = new Map;
|
|
23212
23537
|
portFilePath;
|
|
23213
23538
|
portDir;
|
|
23214
23539
|
startedAt = Date.now();
|
|
23540
|
+
stopped = false;
|
|
23215
23541
|
instanceId = randomBytes(8).toString("hex");
|
|
23216
23542
|
unregisterOwnInstance = null;
|
|
23217
23543
|
sockets = new Set;
|
|
23218
23544
|
token = randomBytes(32).toString("hex");
|
|
23219
23545
|
constructor(storageDir, directory) {
|
|
23546
|
+
this.storageDir = storageDir;
|
|
23220
23547
|
this.portFilePath = rpcPortFilePath(storageDir, directory, process.pid, this.instanceId);
|
|
23221
23548
|
this.portDir = rpcPortDir(storageDir, directory);
|
|
23222
23549
|
}
|
|
@@ -23234,6 +23561,10 @@ class MagicContextRpcServer {
|
|
|
23234
23561
|
log2("rpc server skipped: Bun runtime not available (no TUI consumer)");
|
|
23235
23562
|
return 0;
|
|
23236
23563
|
}
|
|
23564
|
+
this.stopped = false;
|
|
23565
|
+
await reapDeadRpcDiscovery(this.storageDir);
|
|
23566
|
+
if (this.stopped)
|
|
23567
|
+
return 0;
|
|
23237
23568
|
this.startedAt = Date.now();
|
|
23238
23569
|
const self = this;
|
|
23239
23570
|
const server = inRootAsyncContext2(() => Bun.serve({
|
|
@@ -23265,7 +23596,7 @@ class MagicContextRpcServer {
|
|
|
23265
23596
|
try {
|
|
23266
23597
|
this.warnIfOtherLiveInstance();
|
|
23267
23598
|
this.unregisterOwnInstance ??= registerOwnRpcServerInstance(this.instanceId);
|
|
23268
|
-
writeStorageFileAtomicSync(this.portFilePath, JSON.stringify({
|
|
23599
|
+
const publish = () => writeStorageFileAtomicSync(this.portFilePath, JSON.stringify({
|
|
23269
23600
|
port: this.port,
|
|
23270
23601
|
pid: process.pid,
|
|
23271
23602
|
started_at: this.startedAt,
|
|
@@ -23273,6 +23604,13 @@ class MagicContextRpcServer {
|
|
|
23273
23604
|
token: this.token,
|
|
23274
23605
|
instance_id: this.instanceId
|
|
23275
23606
|
}));
|
|
23607
|
+
try {
|
|
23608
|
+
publish();
|
|
23609
|
+
} catch (error) {
|
|
23610
|
+
if (error.code !== "ENOENT")
|
|
23611
|
+
throw error;
|
|
23612
|
+
publish();
|
|
23613
|
+
}
|
|
23276
23614
|
log2(`[rpc] server listening on 127.0.0.1:${this.port}`);
|
|
23277
23615
|
} catch (err) {
|
|
23278
23616
|
log2(`[rpc] failed to write port file: ${err}`);
|
|
@@ -23280,6 +23618,7 @@ class MagicContextRpcServer {
|
|
|
23280
23618
|
return this.port;
|
|
23281
23619
|
}
|
|
23282
23620
|
stop() {
|
|
23621
|
+
this.stopped = true;
|
|
23283
23622
|
for (const ws of this.sockets) {
|
|
23284
23623
|
try {
|
|
23285
23624
|
if (ws.data.authTimer)
|
|
@@ -23296,6 +23635,9 @@ class MagicContextRpcServer {
|
|
|
23296
23635
|
try {
|
|
23297
23636
|
unlinkSync(this.portFilePath);
|
|
23298
23637
|
} catch {}
|
|
23638
|
+
try {
|
|
23639
|
+
rmdirSync(this.portDir);
|
|
23640
|
+
} catch {}
|
|
23299
23641
|
this.unregisterOwnInstance?.();
|
|
23300
23642
|
this.unregisterOwnInstance = null;
|
|
23301
23643
|
}
|
|
@@ -23800,8 +24142,8 @@ function hostMediaFromEncoded(value) {
|
|
|
23800
24142
|
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
23801
24143
|
|
|
23802
24144
|
// src/v2/fold/owner.ts
|
|
23803
|
-
import { createHash as
|
|
23804
|
-
var foldDigest = (value) =>
|
|
24145
|
+
import { createHash as createHash7 } from "node:crypto";
|
|
24146
|
+
var foldDigest = (value) => createHash7("sha256").update(value).digest("hex");
|
|
23805
24147
|
|
|
23806
24148
|
class FoldOwner {
|
|
23807
24149
|
storage;
|
|
@@ -24720,24 +25062,31 @@ ${data.output?.output ?? ""}`
|
|
|
24720
25062
|
const sameModel = sameProvider && previousModel?.id === model.id;
|
|
24721
25063
|
const reuse = sameModel && data.error === undefined;
|
|
24722
25064
|
const metadata = (state) => state === undefined ? undefined : { [model.providerID]: state };
|
|
25065
|
+
const reasoningInterrupted = data.content?.some((part) => part.type === "reasoning" && part.time !== undefined && part.time.completed === undefined);
|
|
24723
25066
|
const content = [];
|
|
24724
25067
|
const results = [];
|
|
24725
25068
|
for (const part of data.content ?? []) {
|
|
25069
|
+
let native = "native" in part ? part.native : part.type === "tool" ? part.providerState : part.state;
|
|
25070
|
+
if (part.type === "tool" && part.providerResultState !== null && typeof part.providerResultState === "object" && !Array.isArray(part.providerResultState))
|
|
25071
|
+
native = {
|
|
25072
|
+
...native !== null && typeof native === "object" && !Array.isArray(native) ? native : {},
|
|
25073
|
+
...part.providerResultState
|
|
25074
|
+
};
|
|
24726
25075
|
if (part.type === "text") {
|
|
24727
25076
|
if (part.text !== "")
|
|
24728
25077
|
content.push({
|
|
24729
25078
|
type: "text",
|
|
24730
25079
|
text: part.text,
|
|
24731
|
-
providerMetadata: reuse ? metadata(
|
|
25080
|
+
providerMetadata: reuse ? metadata(native) : undefined
|
|
24732
25081
|
});
|
|
24733
25082
|
continue;
|
|
24734
25083
|
}
|
|
24735
25084
|
if (part.type === "reasoning") {
|
|
24736
|
-
if (part.text !== "" || reuse &&
|
|
25085
|
+
if (part.text !== "" || reuse && !reasoningInterrupted && native !== undefined)
|
|
24737
25086
|
content.push({
|
|
24738
|
-
type:
|
|
25087
|
+
type: data.error === undefined && !reasoningInterrupted ? "reasoning" : "text",
|
|
24739
25088
|
text: part.text,
|
|
24740
|
-
providerMetadata: reuse ? metadata(
|
|
25089
|
+
providerMetadata: reuse && !reasoningInterrupted ? metadata(native) : undefined
|
|
24741
25090
|
});
|
|
24742
25091
|
continue;
|
|
24743
25092
|
}
|
|
@@ -24756,7 +25105,7 @@ ${data.output?.output ?? ""}`
|
|
|
24756
25105
|
name: part.name,
|
|
24757
25106
|
input,
|
|
24758
25107
|
providerExecuted: part.executed,
|
|
24759
|
-
providerMetadata: toolReuse ? metadata(
|
|
25108
|
+
providerMetadata: toolReuse ? metadata(native) : undefined
|
|
24760
25109
|
});
|
|
24761
25110
|
if (!completed)
|
|
24762
25111
|
continue;
|
|
@@ -24767,7 +25116,7 @@ ${data.output?.output ?? ""}`
|
|
|
24767
25116
|
id: part.id,
|
|
24768
25117
|
name: part.name,
|
|
24769
25118
|
providerExecuted: part.executed,
|
|
24770
|
-
providerMetadata:
|
|
25119
|
+
providerMetadata: (part.executed === true ? sameProvider : reuse) ? metadata(native) : undefined,
|
|
24771
25120
|
result: state.status === "error" ? { error: state.error, content: toolContent } : single?.type === "text" ? { type: "text", value: single.text } : { type: "content", value: toolContent },
|
|
24772
25121
|
...state.status === "error" ? { resultType: "error" } : {}
|
|
24773
25122
|
};
|
|
@@ -24795,13 +25144,50 @@ function copyNativeInput(messages) {
|
|
|
24795
25144
|
return copies;
|
|
24796
25145
|
}
|
|
24797
25146
|
function isLocalCheckpoint(row) {
|
|
24798
|
-
return row.type === "compaction" && row.data.status === "completed" && row.data.providerContext === undefined;
|
|
25147
|
+
return row.type === "compaction" && row.data.status === "completed" && row.data.providerContext === undefined && row.data.native?.messages === undefined;
|
|
25148
|
+
}
|
|
25149
|
+
function isAdmittedLocalCheckpoint(storage, sessionID, cut) {
|
|
25150
|
+
if (!isLocalCheckpoint(cut) || cut.session_id !== sessionID)
|
|
25151
|
+
return false;
|
|
25152
|
+
const admission = storage.admission(sessionID, cut.id);
|
|
25153
|
+
if (!admission?.payload || admission.digest !== foldDigest(admission.payload))
|
|
25154
|
+
return false;
|
|
25155
|
+
try {
|
|
25156
|
+
const snapshot = JSON.parse(admission.payload);
|
|
25157
|
+
return snapshot.source === storage.sourceID && snapshot.sessionID === sessionID && snapshot.admissionID === cut.id && snapshot.summary === cut.data.summary;
|
|
25158
|
+
} catch {
|
|
25159
|
+
return false;
|
|
25160
|
+
}
|
|
24799
25161
|
}
|
|
24800
25162
|
var conversational = (row) => RAW_MESSAGE_TYPES.includes(row.type) || row.type === "location-switched";
|
|
25163
|
+
var historyDigest = (reader, sessionID, through) => foldDigest(JSON.stringify(reader.range(sessionID, -1, through).filter(conversational)));
|
|
25164
|
+
var admissionKey = (sessionID) => `native-fold/v2/${encodeURIComponent(sessionID)}`;
|
|
25165
|
+
async function forgetNativeFoldProvenance(storage, sessionID, legacyOnly = false) {
|
|
25166
|
+
const remove = async (key) => {
|
|
25167
|
+
if (storage.remove)
|
|
25168
|
+
await storage.remove(key);
|
|
25169
|
+
else
|
|
25170
|
+
await storage.set(key, null);
|
|
25171
|
+
};
|
|
25172
|
+
if (!legacyOnly)
|
|
25173
|
+
await remove(admissionKey(sessionID));
|
|
25174
|
+
if (!storage.scan)
|
|
25175
|
+
return;
|
|
25176
|
+
let after;
|
|
25177
|
+
do {
|
|
25178
|
+
const page = await storage.scan({ prefix: "native-fold/v1/", after, limit: 100 });
|
|
25179
|
+
for (const { key } of page.entries) {
|
|
25180
|
+
if (key.slice("native-fold/v1/".length).split("/").slice(1).join("/") === sessionID)
|
|
25181
|
+
await remove(key);
|
|
25182
|
+
}
|
|
25183
|
+
after = page.next;
|
|
25184
|
+
} while (after);
|
|
25185
|
+
}
|
|
24801
25186
|
|
|
24802
25187
|
class NativeFoldReplay {
|
|
24803
25188
|
storage;
|
|
24804
25189
|
openReader;
|
|
25190
|
+
admissions;
|
|
24805
25191
|
changed = new Set;
|
|
24806
25192
|
dirty = new Set;
|
|
24807
25193
|
unavailable = new Set;
|
|
@@ -24809,9 +25195,11 @@ class NativeFoldReplay {
|
|
|
24809
25195
|
metadataThrough = new Map;
|
|
24810
25196
|
loaded = new Map;
|
|
24811
25197
|
sources = new Map;
|
|
24812
|
-
|
|
25198
|
+
staleHeads = new Set;
|
|
25199
|
+
constructor(storage, openReader, admissions) {
|
|
24813
25200
|
this.storage = storage;
|
|
24814
25201
|
this.openReader = openReader;
|
|
25202
|
+
this.admissions = admissions;
|
|
24815
25203
|
storage.onEvict((sessionID) => this.clear(sessionID));
|
|
24816
25204
|
}
|
|
24817
25205
|
account(sessionID) {
|
|
@@ -24850,6 +25238,51 @@ class NativeFoldReplay {
|
|
|
24850
25238
|
async baseline(sessionID) {
|
|
24851
25239
|
return this.tail(sessionID)?.baseline;
|
|
24852
25240
|
}
|
|
25241
|
+
admissionKey(sessionID) {
|
|
25242
|
+
return admissionKey(sessionID);
|
|
25243
|
+
}
|
|
25244
|
+
async removeAdmission(key) {
|
|
25245
|
+
if (this.admissions?.remove)
|
|
25246
|
+
await this.admissions.remove(key);
|
|
25247
|
+
else
|
|
25248
|
+
await this.admissions?.set(key, null);
|
|
25249
|
+
}
|
|
25250
|
+
async removeLegacyAdmissions(sessionID) {
|
|
25251
|
+
if (this.admissions)
|
|
25252
|
+
await forgetNativeFoldProvenance(this.admissions, sessionID, true);
|
|
25253
|
+
}
|
|
25254
|
+
async admits(sessionID, cut, reader) {
|
|
25255
|
+
if (!isLocalCheckpoint(cut) || cut.session_id !== sessionID)
|
|
25256
|
+
return false;
|
|
25257
|
+
if (isAdmittedLocalCheckpoint(this.storage, sessionID, cut))
|
|
25258
|
+
return true;
|
|
25259
|
+
if (!this.admissions)
|
|
25260
|
+
return false;
|
|
25261
|
+
try {
|
|
25262
|
+
const source = reader.hostIdentity();
|
|
25263
|
+
const saved = await this.admissions.get(this.admissionKey(sessionID));
|
|
25264
|
+
if (!saved?.payload || saved.digest !== foldDigest(saved.payload))
|
|
25265
|
+
return false;
|
|
25266
|
+
const snapshot = JSON.parse(saved.payload);
|
|
25267
|
+
if (snapshot.sourceDigest !== foldDigest(source) || snapshot.sessionID !== sessionID || snapshot.admissionID !== cut.id || snapshot.summaryDigest !== foldDigest(cut.data.summary ?? ""))
|
|
25268
|
+
return false;
|
|
25269
|
+
if (snapshot.historyDigest !== historyDigest(reader, sessionID, cut.seq - 1)) {
|
|
25270
|
+
this.staleHeads.add(sessionID);
|
|
25271
|
+
this.invalidate(sessionID);
|
|
25272
|
+
await this.removeAdmission(this.admissionKey(sessionID));
|
|
25273
|
+
return false;
|
|
25274
|
+
}
|
|
25275
|
+
await this.storage.supply(sessionID, cut.id, JSON.stringify({
|
|
25276
|
+
source: this.storage.sourceID,
|
|
25277
|
+
sessionID,
|
|
25278
|
+
admissionID: cut.id,
|
|
25279
|
+
summary: cut.data.summary
|
|
25280
|
+
}));
|
|
25281
|
+
return true;
|
|
25282
|
+
} catch {
|
|
25283
|
+
return false;
|
|
25284
|
+
}
|
|
25285
|
+
}
|
|
24853
25286
|
rendered(row, model) {
|
|
24854
25287
|
return restoreRow(row, model, hostUsesMediaAssets() ? {
|
|
24855
25288
|
asset: hostMediaAsset,
|
|
@@ -24927,6 +25360,7 @@ class NativeFoldReplay {
|
|
|
24927
25360
|
this.loaded.set(draft.sessionID, through);
|
|
24928
25361
|
this.unavailable.delete(draft.sessionID);
|
|
24929
25362
|
this.changed.delete(draft.sessionID);
|
|
25363
|
+
this.staleHeads.delete(draft.sessionID);
|
|
24930
25364
|
} finally {
|
|
24931
25365
|
reader.close();
|
|
24932
25366
|
}
|
|
@@ -24953,7 +25387,8 @@ class NativeFoldReplay {
|
|
|
24953
25387
|
async supplyHeld(args) {
|
|
24954
25388
|
const { draft, reader, summary } = args;
|
|
24955
25389
|
const tail = this.tail(draft.sessionID);
|
|
24956
|
-
const
|
|
25390
|
+
const running = reader.latestRunningCompaction(draft.sessionID);
|
|
25391
|
+
const id = running?.id;
|
|
24957
25392
|
if (!id || !tail || tail.model !== `${draft.model.providerID}/${draft.model.id}`)
|
|
24958
25393
|
return false;
|
|
24959
25394
|
const through = reader.latestSequence(draft.sessionID);
|
|
@@ -24977,6 +25412,21 @@ class NativeFoldReplay {
|
|
|
24977
25412
|
summary
|
|
24978
25413
|
};
|
|
24979
25414
|
await this.storage.supply(draft.sessionID, id, JSON.stringify(snapshot));
|
|
25415
|
+
if (this.admissions) {
|
|
25416
|
+
const provenance = {
|
|
25417
|
+
sourceDigest: foldDigest(reader.hostIdentity()),
|
|
25418
|
+
sessionID: draft.sessionID,
|
|
25419
|
+
admissionID: id,
|
|
25420
|
+
summaryDigest: foldDigest(summary),
|
|
25421
|
+
historyDigest: historyDigest(reader, draft.sessionID, (running?.seq ?? through) - 1)
|
|
25422
|
+
};
|
|
25423
|
+
const payload = JSON.stringify(provenance);
|
|
25424
|
+
await this.admissions.set(this.admissionKey(draft.sessionID), {
|
|
25425
|
+
payload,
|
|
25426
|
+
digest: foldDigest(payload)
|
|
25427
|
+
});
|
|
25428
|
+
await this.removeLegacyAdmissions(draft.sessionID);
|
|
25429
|
+
}
|
|
24980
25430
|
return true;
|
|
24981
25431
|
}
|
|
24982
25432
|
async restore(sessionID, cut, model, options = {}) {
|
|
@@ -25061,6 +25511,9 @@ class NativeFoldReplay {
|
|
|
25061
25511
|
sourceChanged(sessionID) {
|
|
25062
25512
|
return this.changed.has(sessionID);
|
|
25063
25513
|
}
|
|
25514
|
+
needsHeadRebuild(sessionID) {
|
|
25515
|
+
return this.staleHeads.has(sessionID);
|
|
25516
|
+
}
|
|
25064
25517
|
clear(sessionID) {
|
|
25065
25518
|
this.sources.delete(sessionID);
|
|
25066
25519
|
this.metadata.delete(sessionID);
|
|
@@ -25069,8 +25522,11 @@ class NativeFoldReplay {
|
|
|
25069
25522
|
this.unavailable.delete(sessionID);
|
|
25070
25523
|
this.dirty.delete(sessionID);
|
|
25071
25524
|
this.changed.delete(sessionID);
|
|
25525
|
+
this.staleHeads.delete(sessionID);
|
|
25072
25526
|
}
|
|
25073
25527
|
async forget(sessionID) {
|
|
25528
|
+
if (this.admissions)
|
|
25529
|
+
await forgetNativeFoldProvenance(this.admissions, sessionID);
|
|
25074
25530
|
await this.storage.forget(sessionID);
|
|
25075
25531
|
}
|
|
25076
25532
|
}
|
|
@@ -25085,11 +25541,7 @@ class HostFoldPolicy {
|
|
|
25085
25541
|
this.deps = deps;
|
|
25086
25542
|
}
|
|
25087
25543
|
owned(sessionID, cut, id) {
|
|
25088
|
-
|
|
25089
|
-
if (!isLocalCheckpoint(cut) || cut.id !== id || !row?.payload || row.digest !== foldDigest(row.payload))
|
|
25090
|
-
return false;
|
|
25091
|
-
const snapshot = JSON.parse(row.payload);
|
|
25092
|
-
return snapshot.summary === cut.data.summary && snapshot.source === this.deps.storage.sourceID && snapshot.sessionID === sessionID && snapshot.admissionID === id;
|
|
25544
|
+
return cut.id === id && isAdmittedLocalCheckpoint(this.deps.storage, sessionID, cut);
|
|
25093
25545
|
}
|
|
25094
25546
|
async idle(sessionID) {
|
|
25095
25547
|
const { storage, session, threshold } = this.deps;
|
|
@@ -25512,7 +25964,7 @@ async function cleanupLegacyHiddenChildren(db, remove, note, options = {}) {
|
|
|
25512
25964
|
// src/shared/models-dev-temperature.ts
|
|
25513
25965
|
import { readFileSync as readFileSync5, statSync as statSync2 } from "node:fs";
|
|
25514
25966
|
import { homedir as homedir3 } from "node:os";
|
|
25515
|
-
import { join as
|
|
25967
|
+
import { join as join7 } from "node:path";
|
|
25516
25968
|
var CATALOG_PROVIDER_ALIASES = {
|
|
25517
25969
|
"google-antigravity": "google",
|
|
25518
25970
|
"opencode-zen": "opencode"
|
|
@@ -25522,7 +25974,7 @@ var cached;
|
|
|
25522
25974
|
function modelsDevCatalogPath(env = process.env) {
|
|
25523
25975
|
if (env.OPENCODE_MODELS_PATH)
|
|
25524
25976
|
return env.OPENCODE_MODELS_PATH;
|
|
25525
|
-
return
|
|
25977
|
+
return join7(env.XDG_CACHE_HOME || join7(homedir3(), ".cache"), "opencode", "models.json");
|
|
25526
25978
|
}
|
|
25527
25979
|
function buildIndex(raw) {
|
|
25528
25980
|
const index = new Map;
|
|
@@ -26520,11 +26972,11 @@ class DeletedSessionTombstones {
|
|
|
26520
26972
|
}
|
|
26521
26973
|
|
|
26522
26974
|
// src/features/magic-context/dreamer/task-executor.ts
|
|
26523
|
-
import { createHash as
|
|
26975
|
+
import { createHash as createHash14 } from "node:crypto";
|
|
26524
26976
|
import { existsSync as existsSync7, readFileSync as readFileSync8 } from "node:fs";
|
|
26525
26977
|
|
|
26526
26978
|
// src/features/magic-context/mural/compress-cues.ts
|
|
26527
|
-
import { createHash as
|
|
26979
|
+
import { createHash as createHash8 } from "node:crypto";
|
|
26528
26980
|
|
|
26529
26981
|
// src/features/magic-context/dreamer/storage-dream-state.ts
|
|
26530
26982
|
var getDreamStateStatements = new WeakMap;
|
|
@@ -27267,7 +27719,7 @@ async function applyCuesThroughModule(args, chunk, manifestText, signal) {
|
|
|
27267
27719
|
log2(`[dreamer] compress-cues: skipped cue for memory ${entry.id} (${failure.reason}; rejection ${rejectionCount}/${CUE_REJECTION_LATCH_THRESHOLD})`);
|
|
27268
27720
|
}
|
|
27269
27721
|
}
|
|
27270
|
-
const commandId = `mural-cues:${route.moduleCommandId}:${
|
|
27722
|
+
const commandId = `mural-cues:${route.moduleCommandId}:${createHash8("sha256").update(chunk.map((candidate) => candidate.memory.id).join(",")).digest("hex").slice(0, 24)}`;
|
|
27271
27723
|
let response;
|
|
27272
27724
|
try {
|
|
27273
27725
|
response = await route.moduleClient.call({
|
|
@@ -27870,7 +28322,7 @@ function applyReviewVerdict(args, leaseKey, parsed, result) {
|
|
|
27870
28322
|
}
|
|
27871
28323
|
|
|
27872
28324
|
// src/features/magic-context/dreamer/classify.ts
|
|
27873
|
-
import { createHash as
|
|
28325
|
+
import { createHash as createHash9 } from "node:crypto";
|
|
27874
28326
|
|
|
27875
28327
|
// src/plugin/rust-tool-backends.ts
|
|
27876
28328
|
function isRustAuthorityDrainingError(error) {
|
|
@@ -28307,7 +28759,7 @@ async function runClassifyThroughModule(args, chunk, anchors, signal, runOnHost)
|
|
|
28307
28759
|
if (entry.qualifier)
|
|
28308
28760
|
modelVariants[entry.model] = entry.qualifier;
|
|
28309
28761
|
}
|
|
28310
|
-
const commandId = `classify:${args.moduleCommandId ?? Date.now()}:${
|
|
28762
|
+
const commandId = `classify:${args.moduleCommandId ?? Date.now()}:${createHash9("sha256").update(chunk.map((candidate) => candidate.id).join(",")).digest("hex").slice(0, 24)}`;
|
|
28311
28763
|
const runTask = (hostCompletion) => args.moduleClient?.call({
|
|
28312
28764
|
sessionId: args.moduleSessionId,
|
|
28313
28765
|
projectRoot: args.moduleProjectRoot,
|
|
@@ -28582,7 +29034,7 @@ function takeCurateSafetyRefusalCount(sessionId) {
|
|
|
28582
29034
|
|
|
28583
29035
|
// src/features/magic-context/dreamer/docs-proposals.ts
|
|
28584
29036
|
import { execFileSync } from "node:child_process";
|
|
28585
|
-
import { createHash as
|
|
29037
|
+
import { createHash as createHash10 } from "node:crypto";
|
|
28586
29038
|
import {
|
|
28587
29039
|
existsSync as existsSync4,
|
|
28588
29040
|
mkdirSync,
|
|
@@ -28595,19 +29047,19 @@ import {
|
|
|
28595
29047
|
writeFileSync
|
|
28596
29048
|
} from "node:fs";
|
|
28597
29049
|
import { tmpdir } from "node:os";
|
|
28598
|
-
import { join as
|
|
29050
|
+
import { join as join8 } from "node:path";
|
|
28599
29051
|
var FILES = ["ARCHITECTURE.md", "STRUCTURE.md"];
|
|
28600
|
-
var hash = (text) =>
|
|
28601
|
-
var proposalDir = (projectDir) =>
|
|
29052
|
+
var hash = (text) => createHash10("sha256").update(text).digest("hex");
|
|
29053
|
+
var proposalDir = (projectDir) => join8(projectDir, ".cortexkit/magic-context/docs-update-proposals");
|
|
28602
29054
|
function docsBaseHashes(projectDir) {
|
|
28603
29055
|
return Object.fromEntries(FILES.map((name) => [
|
|
28604
29056
|
name,
|
|
28605
|
-
hash(existsSync4(
|
|
29057
|
+
hash(existsSync4(join8(projectDir, name)) ? readFileSync6(join8(projectDir, name), "utf8") : "")
|
|
28606
29058
|
]));
|
|
28607
29059
|
}
|
|
28608
29060
|
function listPendingDocsProposals(projectDir) {
|
|
28609
29061
|
const dir = proposalDir(projectDir);
|
|
28610
|
-
return existsSync4(dir) ? readdirSync2(dir).filter((name) => name.endsWith(".md")).sort().map((name) =>
|
|
29062
|
+
return existsSync4(dir) ? readdirSync2(dir).filter((name) => name.endsWith(".md")).sort().map((name) => join8(dir, name)) : [];
|
|
28611
29063
|
}
|
|
28612
29064
|
function hasCurrentDocsProposal(projectDir) {
|
|
28613
29065
|
const hashes = docsBaseHashes(projectDir);
|
|
@@ -28665,7 +29117,7 @@ function docsChangeSet(projectDir, storedAnchor) {
|
|
|
28665
29117
|
const files = [
|
|
28666
29118
|
...new Set(changed.flat().filter((file) => file !== "ARCHITECTURE.md" && file !== "STRUCTURE.md" && !/(?:^|[./-])(test|spec)(?:[./-]|$)/.test(file) && !file.endsWith(".lock")))
|
|
28667
29119
|
];
|
|
28668
|
-
const docs = FILES.map((file) => existsSync4(
|
|
29120
|
+
const docs = FILES.map((file) => existsSync4(join8(projectDir, file)) ? readFileSync6(join8(projectDir, file), "utf8") : "").join(`
|
|
28669
29121
|
`);
|
|
28670
29122
|
const relevant = files.some((file) => {
|
|
28671
29123
|
const directory = file.split("/").slice(0, -1).join("/");
|
|
@@ -28793,14 +29245,14 @@ function protectedBytes(text) {
|
|
|
28793
29245
|
].map((match) => match[0]);
|
|
28794
29246
|
}
|
|
28795
29247
|
function diff(name, before, after) {
|
|
28796
|
-
const dir = mkdtempSync(
|
|
29248
|
+
const dir = mkdtempSync(join8(tmpdir(), "mc-doc-diff-"));
|
|
28797
29249
|
try {
|
|
28798
|
-
writeFileSync(
|
|
28799
|
-
writeFileSync(
|
|
29250
|
+
writeFileSync(join8(dir, "before"), before);
|
|
29251
|
+
writeFileSync(join8(dir, "after"), after);
|
|
28800
29252
|
try {
|
|
28801
|
-
return execFileSync("git", ["diff", "--no-index", "--",
|
|
29253
|
+
return execFileSync("git", ["diff", "--no-index", "--", join8(dir, "before"), join8(dir, "after")], { windowsHide: true, encoding: "utf8" });
|
|
28802
29254
|
} catch (error) {
|
|
28803
|
-
return error.stdout?.replaceAll(
|
|
29255
|
+
return error.stdout?.replaceAll(join8(dir, "before"), `a/${name}`).replaceAll(join8(dir, "after"), `b/${name}`) ?? "";
|
|
28804
29256
|
}
|
|
28805
29257
|
} finally {
|
|
28806
29258
|
rmSync2(dir, { recursive: true, force: true });
|
|
@@ -28821,7 +29273,7 @@ function validateDocsProposal(projectDir, output, budget, expected) {
|
|
|
28821
29273
|
let tokens = 0;
|
|
28822
29274
|
let diffs = "";
|
|
28823
29275
|
for (const file of FILES) {
|
|
28824
|
-
const before = existsSync4(
|
|
29276
|
+
const before = existsSync4(join8(projectDir, file)) ? readFileSync6(join8(projectDir, file), "utf8") : "";
|
|
28825
29277
|
let after = before;
|
|
28826
29278
|
const seen = new Set;
|
|
28827
29279
|
for (const change of changes.filter((item) => item.file === file)) {
|
|
@@ -28871,9 +29323,9 @@ ${change.text.trimEnd()}
|
|
|
28871
29323
|
function writeDocsProposal(projectDir, output, budget, expected, head) {
|
|
28872
29324
|
const result = validateDocsProposal(projectDir, output, budget, expected);
|
|
28873
29325
|
const dir = proposalDir(projectDir);
|
|
28874
|
-
mkdirSync(
|
|
29326
|
+
mkdirSync(join8(dir, "superseded"), { recursive: true });
|
|
28875
29327
|
const stamp = `${new Date().toISOString().replace(/[:.]/g, "-")}-${Math.random().toString(36).slice(2, 8)}`;
|
|
28876
|
-
const path =
|
|
29328
|
+
const path = join8(dir, `${stamp}.md`);
|
|
28877
29329
|
const body = `# Docs update proposal
|
|
28878
29330
|
|
|
28879
29331
|
Base commit: ${head}
|
|
@@ -28901,7 +29353,7 @@ ${result.diffs}
|
|
|
28901
29353
|
writeFileSync(path, body, { flag: "wx" });
|
|
28902
29354
|
for (const old of listPendingDocsProposals(projectDir))
|
|
28903
29355
|
if (old !== path)
|
|
28904
|
-
renameSync(old,
|
|
29356
|
+
renameSync(old, join8(dir, "superseded", old.split("/").at(-1) ?? "proposal.md"));
|
|
28905
29357
|
return path;
|
|
28906
29358
|
}
|
|
28907
29359
|
|
|
@@ -29133,7 +29585,7 @@ function throwIfAborted2(signal) {
|
|
|
29133
29585
|
}
|
|
29134
29586
|
|
|
29135
29587
|
// src/features/magic-context/smart-notes/compiler.ts
|
|
29136
|
-
import { createHash as
|
|
29588
|
+
import { createHash as createHash11 } from "node:crypto";
|
|
29137
29589
|
|
|
29138
29590
|
// src/features/magic-context/smart-notes/compiler-prompt.ts
|
|
29139
29591
|
var SMART_NOTE_COMPILER_SYSTEM_PROMPT = `You are the Magic Context smart-note compiler for the magic-context system.
|
|
@@ -29472,7 +29924,7 @@ function manifestAdvisoryWarnings(code, manifest) {
|
|
|
29472
29924
|
return warnings;
|
|
29473
29925
|
}
|
|
29474
29926
|
function hashCheck(surfaceCondition, compiledCheck, manifest, checkCron) {
|
|
29475
|
-
return
|
|
29927
|
+
return createHash11("sha256").update(surfaceCondition ?? "").update("\x00").update(compiledCheck).update("\x00").update(JSON.stringify(manifest)).update("\x00").update(checkCron).digest("hex");
|
|
29476
29928
|
}
|
|
29477
29929
|
function extractJsonObject(output) {
|
|
29478
29930
|
const fenced = output.match(/```(?:json)?\s*([\s\S]*?)```/i);
|
|
@@ -29550,7 +30002,7 @@ function deterministicJitterMs(intervalMs, noteId, hash) {
|
|
|
29550
30002
|
}
|
|
29551
30003
|
|
|
29552
30004
|
// src/features/magic-context/smart-notes/wake-plane.ts
|
|
29553
|
-
import { join as
|
|
30005
|
+
import { join as join9 } from "node:path";
|
|
29554
30006
|
var WAKE_PLANE_CAPABILITY = "wake.create";
|
|
29555
30007
|
var WAKE_PLANE_STATUS_TTL_MS = 5 * 60 * 1000;
|
|
29556
30008
|
var WAKE_PLANE_HANDSHAKE_TIMEOUT_MS = 2000;
|
|
@@ -29559,7 +30011,7 @@ var inFlightProbe = null;
|
|
|
29559
30011
|
var catalogProbe = probeWakePlaneCatalog;
|
|
29560
30012
|
var now = () => Date.now();
|
|
29561
30013
|
function connectionFile() {
|
|
29562
|
-
return
|
|
30014
|
+
return join9(getDataDir(), "cortexkit", "run", "subc-connection.json");
|
|
29563
30015
|
}
|
|
29564
30016
|
async function probeWakePlaneCatalog() {
|
|
29565
30017
|
const file = connectionFile();
|
|
@@ -30222,12 +30674,12 @@ async function archiveExpiredMemories(args) {
|
|
|
30222
30674
|
|
|
30223
30675
|
// src/features/magic-context/dreamer/maintain-docs-protected-enforcement.ts
|
|
30224
30676
|
import { existsSync as existsSync5, readFileSync as readFileSync7, writeFileSync as writeFileSync2 } from "node:fs";
|
|
30225
|
-
import { join as
|
|
30677
|
+
import { join as join10 } from "node:path";
|
|
30226
30678
|
var MAINTAIN_DOCS_SNAPSHOT_FILES = ["ARCHITECTURE.md", "STRUCTURE.md"];
|
|
30227
30679
|
function snapshotMaintainDocsFiles(docsDir) {
|
|
30228
30680
|
const snapshot = new Map;
|
|
30229
30681
|
for (const name of MAINTAIN_DOCS_SNAPSHOT_FILES) {
|
|
30230
|
-
const path =
|
|
30682
|
+
const path = join10(docsDir, name);
|
|
30231
30683
|
try {
|
|
30232
30684
|
if (existsSync5(path)) {
|
|
30233
30685
|
snapshot.set(name, readFileSync7(path, "utf8"));
|
|
@@ -30238,7 +30690,7 @@ function snapshotMaintainDocsFiles(docsDir) {
|
|
|
30238
30690
|
}
|
|
30239
30691
|
|
|
30240
30692
|
// src/features/magic-context/dreamer/map-memories.ts
|
|
30241
|
-
import { createHash as
|
|
30693
|
+
import { createHash as createHash12 } from "node:crypto";
|
|
30242
30694
|
|
|
30243
30695
|
// src/features/magic-context/dreamer/map-memories-prompt.ts
|
|
30244
30696
|
import { execFile as execFile2 } from "node:child_process";
|
|
@@ -30473,7 +30925,7 @@ function readRetries(db, project) {
|
|
|
30473
30925
|
}
|
|
30474
30926
|
}
|
|
30475
30927
|
function contentKey2(memory) {
|
|
30476
|
-
return
|
|
30928
|
+
return createHash12("sha256").update(`${memory.category}
|
|
30477
30929
|
${memory.content}`).digest("hex");
|
|
30478
30930
|
}
|
|
30479
30931
|
function isDeferred(memory, retries) {
|
|
@@ -30895,7 +31347,7 @@ async function applyParsedBatchMappings(args, batch, parsed, budgetFinalized = f
|
|
|
30895
31347
|
name: "memory.set_mapping",
|
|
30896
31348
|
arguments: {
|
|
30897
31349
|
memory_project: args.projectIdentity,
|
|
30898
|
-
command_id: `${args.moduleRoute.moduleCommandId}:${
|
|
31350
|
+
command_id: `${args.moduleRoute.moduleCommandId}:${createHash12("sha256").update(rows.map((row) => row.memory_id).join(",")).digest("hex").slice(0, 16)}`,
|
|
30899
31351
|
rows
|
|
30900
31352
|
}
|
|
30901
31353
|
}
|
|
@@ -32196,7 +32648,7 @@ function insertDreamRun(db, run) {
|
|
|
32196
32648
|
}
|
|
32197
32649
|
|
|
32198
32650
|
// src/features/magic-context/dreamer/verify.ts
|
|
32199
|
-
import { createHash as
|
|
32651
|
+
import { createHash as createHash13 } from "node:crypto";
|
|
32200
32652
|
|
|
32201
32653
|
// src/features/magic-context/dreamer/verify-diff.ts
|
|
32202
32654
|
import { execFile as execFile3 } from "node:child_process";
|
|
@@ -33061,7 +33513,7 @@ async function applyParsedVerifyManifest(args, batch, parsed, headAtPrompt, budg
|
|
|
33061
33513
|
name: "memory.set_verification",
|
|
33062
33514
|
arguments: {
|
|
33063
33515
|
memory_project: args.projectIdentity,
|
|
33064
|
-
command_id: `${args.moduleRoute.moduleCommandId}:${
|
|
33516
|
+
command_id: `${args.moduleRoute.moduleCommandId}:${createHash13("sha256").update(rows.map((row) => row.memory_id).join(",")).digest("hex").slice(0, 16)}`,
|
|
33065
33517
|
rows
|
|
33066
33518
|
}
|
|
33067
33519
|
}
|
|
@@ -33895,7 +34347,7 @@ function parseFrictionGateVerdict(verdict) {
|
|
|
33895
34347
|
}
|
|
33896
34348
|
function computeRetrospectiveWindowKey(flagged) {
|
|
33897
34349
|
const anchors = flagged.map((message) => `${message.sessionId}:${message.ts}`).sort().join("|");
|
|
33898
|
-
return
|
|
34350
|
+
return createHash14("sha256").update(anchors).digest("hex").slice(0, 32);
|
|
33899
34351
|
}
|
|
33900
34352
|
function renderFrictionWindow(messages, flaggedOrdinals, radius = 2) {
|
|
33901
34353
|
const flagged = new Set(flaggedOrdinals);
|
|
@@ -35333,7 +35785,7 @@ function runTick(origin) {
|
|
|
35333
35785
|
if (tickInFlight)
|
|
35334
35786
|
return;
|
|
35335
35787
|
tickInFlight = true;
|
|
35336
|
-
log2(`[
|
|
35788
|
+
log2(`[magic-context] maintenance tick (${origin}) — projects=${registeredProjects.size}`);
|
|
35337
35789
|
(async () => {
|
|
35338
35790
|
try {
|
|
35339
35791
|
const db = openTimerDatabaseOrNull("maintenance tick");
|
|
@@ -35383,6 +35835,9 @@ function persistTickOutcome(db, failure) {
|
|
|
35383
35835
|
}
|
|
35384
35836
|
}
|
|
35385
35837
|
async function runMessageHistoryMaintenance(db) {
|
|
35838
|
+
const prunedIdentities = await pruneMissingProjectIdentities();
|
|
35839
|
+
if (prunedIdentities > 0)
|
|
35840
|
+
log2(`[magic-context] pruned ${prunedIdentities} missing project identities`);
|
|
35386
35841
|
try {
|
|
35387
35842
|
await drainStaleLkgSlots(db);
|
|
35388
35843
|
} catch (error) {
|
|
@@ -35616,10 +36071,20 @@ async function sweepGitCommits(args) {
|
|
|
35616
36071
|
const holderId = crypto.randomUUID();
|
|
35617
36072
|
const lease = acquireGitSweepLease(db, projectIdentity, holderId);
|
|
35618
36073
|
if (!lease.acquired) {
|
|
35619
|
-
|
|
36074
|
+
if (lease.reason === "cooldown_active")
|
|
36075
|
+
return;
|
|
36076
|
+
const reason = `lease held by ${lease.leaseHolder ?? "another holder"} until ${lease.leaseExpiresAt ?? "unknown"}`;
|
|
35620
36077
|
log2(`[git-commits] sweep skipped for ${projectIdentity}: ${reason}`);
|
|
35621
36078
|
return;
|
|
35622
36079
|
}
|
|
36080
|
+
if (projectIdentity.startsWith("dir:")) {
|
|
36081
|
+
if (parkGitSweepNonIndexable(db, projectIdentity, holderId)) {
|
|
36082
|
+
log2(`[git-commits] sweep parked for ${projectIdentity}: directory identity has no commits`);
|
|
36083
|
+
} else {
|
|
36084
|
+
releaseGitSweepLease(db, projectIdentity, holderId);
|
|
36085
|
+
}
|
|
36086
|
+
return;
|
|
36087
|
+
}
|
|
35623
36088
|
const startedAt = Date.now();
|
|
35624
36089
|
const stopRenewal = startGitSweepLeaseRenewal(db, projectIdentity, holderId);
|
|
35625
36090
|
log2(`[git-commits] sweep starting for ${projectIdentity} (sinceDays=${gitCommitIndexing.since_days} maxCommits=${gitCommitIndexing.max_commits})`);
|
|
@@ -35880,9 +36345,9 @@ function hiddenTerminalError(event) {
|
|
|
35880
36345
|
}
|
|
35881
36346
|
|
|
35882
36347
|
// src/v2/hooks/lkg-system.ts
|
|
35883
|
-
import { createHash as
|
|
36348
|
+
import { createHash as createHash15 } from "node:crypto";
|
|
35884
36349
|
function identity(slot) {
|
|
35885
|
-
return
|
|
36350
|
+
return createHash15("sha256").update(JSON.stringify({
|
|
35886
36351
|
capturedAt: slot.capturedAt,
|
|
35887
36352
|
captureSequence: slot.captureSequence,
|
|
35888
36353
|
rowVersion: slot.rowVersion,
|
|
@@ -48710,7 +49175,7 @@ function resolveCtxExpandMode(args, domain) {
|
|
|
48710
49175
|
}
|
|
48711
49176
|
|
|
48712
49177
|
// src/tools/ctx-expand/render.ts
|
|
48713
|
-
import { createHash as
|
|
49178
|
+
import { createHash as createHash16 } from "node:crypto";
|
|
48714
49179
|
function isRecord6(value) {
|
|
48715
49180
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
48716
49181
|
}
|
|
@@ -48934,61 +49399,11 @@ function renderItemByTag(db, sessionId, number, textIndexDomain = "part") {
|
|
|
48934
49399
|
const index = scoped ? Number(scoped[2]) : 0;
|
|
48935
49400
|
const piText = message.parts.filter((part) => isRecord6(part) && part.type === "text");
|
|
48936
49401
|
const part = message.parts[index];
|
|
48937
|
-
const matching = derived ? piText.filter((part) => isRecord6(part) && typeof part.text === "string" &&
|
|
49402
|
+
const matching = derived ? piText.filter((part) => isRecord6(part) && typeof part.text === "string" && createHash16("sha256").update(part.text).digest("hex") === derived[3]) : [];
|
|
48938
49403
|
const selected = derived ? matching[Number(derived[4])] : textIndexDomain === "text" ? piText[index] : part;
|
|
48939
49404
|
return selected ? renderPartFull(selected) ?? "" : `Tag ${number}'s original text part is no longer in stored history.`;
|
|
48940
49405
|
}
|
|
48941
49406
|
|
|
48942
|
-
// src/tools/ctx-expand/search-archive.ts
|
|
48943
|
-
function renderSearchArchive(db, sessionId, start, end, tokenBudget, archiveOnly = false) {
|
|
48944
|
-
return withMessageFtsSessionFilter(db, sessionId, (sessionFirst) => {
|
|
48945
|
-
let rawIds;
|
|
48946
|
-
const rows = db.prepare(sessionFirst ? `SELECT f.message_ordinal AS ordinal, f.message_id AS id, f.role, f.content
|
|
48947
|
-
FROM message_fts_rowid_map AS m
|
|
48948
|
-
JOIN message_history_fts AS f ON f.rowid = m.fts_rowid
|
|
48949
|
-
WHERE m.session_id = ?1 AND m.message_ordinal BETWEEN ?2 AND ?3
|
|
48950
|
-
AND f.session_id = ?1 AND f.message_ordinal BETWEEN ?2 AND ?3
|
|
48951
|
-
ORDER BY m.message_ordinal` : `SELECT message_ordinal AS ordinal, message_id AS id, role, content
|
|
48952
|
-
FROM message_history_fts
|
|
48953
|
-
WHERE session_id = ?1 AND message_ordinal BETWEEN ?2 AND ?3
|
|
48954
|
-
ORDER BY CAST(message_ordinal AS INTEGER)`);
|
|
48955
|
-
const blocks = [];
|
|
48956
|
-
let tokens = 0;
|
|
48957
|
-
let lastOrdinal = start - 1;
|
|
48958
|
-
let truncated = false;
|
|
48959
|
-
for (const row of rows.iterate(sessionId, start, end)) {
|
|
48960
|
-
if (!row.content)
|
|
48961
|
-
continue;
|
|
48962
|
-
if (!archiveOnly) {
|
|
48963
|
-
rawIds ??= readRawSessionMessageIdOrdinalsForRange2(sessionId, start, end);
|
|
48964
|
-
if (rawIds.get(row.id) === row.ordinal)
|
|
48965
|
-
continue;
|
|
48966
|
-
}
|
|
48967
|
-
const block = `[${row.ordinal}] ${row.role === "user" ? "U" : "A"}: ${row.content}`;
|
|
48968
|
-
const cost = estimateTokens(block);
|
|
48969
|
-
if (blocks.length > 0 && tokens + cost > tokenBudget) {
|
|
48970
|
-
truncated = true;
|
|
48971
|
-
break;
|
|
48972
|
-
}
|
|
48973
|
-
blocks.push(block);
|
|
48974
|
-
tokens += cost;
|
|
48975
|
-
lastOrdinal = row.ordinal;
|
|
48976
|
-
}
|
|
48977
|
-
if (blocks.length === 0)
|
|
48978
|
-
return null;
|
|
48979
|
-
const text = [
|
|
48980
|
-
"From the search archive: indexed text only; no surrounding messages or tool output.",
|
|
48981
|
-
"",
|
|
48982
|
-
...blocks
|
|
48983
|
-
];
|
|
48984
|
-
if (truncated) {
|
|
48985
|
-
text.push("", `Truncated at message ${lastOrdinal} (budget: ~${tokenBudget} tokens). Call ctx_expand(start=${lastOrdinal + 1}, end=${end}) for more archived text.`);
|
|
48986
|
-
}
|
|
48987
|
-
return text.join(`
|
|
48988
|
-
`);
|
|
48989
|
-
});
|
|
48990
|
-
}
|
|
48991
|
-
|
|
48992
49407
|
// src/tools/ctx-expand/tools.ts
|
|
48993
49408
|
var ctxExpandArgsShape = {
|
|
48994
49409
|
tag: tool.schema.union([tool.schema.number(), tool.schema.string()]).optional().describe("Tag number from a §N§ tag or a [dropped §N§] placeholder, not a message ordinal. Returns that one item in full. Use alone."),
|
|
@@ -49022,7 +49437,7 @@ function createCtxExpandTool(deps) {
|
|
|
49022
49437
|
return renderItemByTag(deps.db, sessionId, mode.tag);
|
|
49023
49438
|
}
|
|
49024
49439
|
if (mode.kind === "message") {
|
|
49025
|
-
return
|
|
49440
|
+
return await renderSearchArchiveOffThread2(deps.db, sessionId, mode.message, mode.message, CTX_EXPAND_TOKEN_BUDGET) ?? renderMessageByOrdinal(sessionId, mode.message);
|
|
49026
49441
|
}
|
|
49027
49442
|
const { start, end, verbose } = mode;
|
|
49028
49443
|
const lastCompartmentEnd = getLastCompartmentEndMessage(deps.db, sessionId);
|
|
@@ -49030,7 +49445,7 @@ function createCtxExpandTool(deps) {
|
|
|
49030
49445
|
return `Range ${start}-${end} is entirely within the live tail (after the last compacted message ${lastCompartmentEnd}); those messages are already visible in context.`;
|
|
49031
49446
|
}
|
|
49032
49447
|
const effectiveEnd = lastCompartmentEnd >= 0 ? Math.min(end, lastCompartmentEnd) : end;
|
|
49033
|
-
const archived =
|
|
49448
|
+
const archived = await renderSearchArchiveOffThread2(deps.db, sessionId, start, effectiveEnd, CTX_EXPAND_TOKEN_BUDGET);
|
|
49034
49449
|
if (archived)
|
|
49035
49450
|
return archived;
|
|
49036
49451
|
if (verbose) {
|
|
@@ -49739,7 +50154,7 @@ import { isAbsolute as isAbsolute2 } from "node:path";
|
|
|
49739
50154
|
// ../retina-local-fs/src/path-fence.ts
|
|
49740
50155
|
import { lstat as lstat2, realpath as realpath2 } from "node:fs/promises";
|
|
49741
50156
|
import { homedir as homedir4 } from "node:os";
|
|
49742
|
-
import { basename, dirname as dirname2, isAbsolute, join as
|
|
50157
|
+
import { basename, dirname as dirname2, isAbsolute, join as join11, relative, resolve as resolve2, sep } from "node:path";
|
|
49743
50158
|
|
|
49744
50159
|
// ../retina-local-fs/src/errors.ts
|
|
49745
50160
|
class ProviderError extends Error {
|
|
@@ -49754,7 +50169,7 @@ class ProviderError extends Error {
|
|
|
49754
50169
|
// ../retina-local-fs/src/path-fence.ts
|
|
49755
50170
|
async function resolveAndFenceProviderPath(configuredPath, options) {
|
|
49756
50171
|
const { home, dataDirectory, aliases } = await resolveFenceRoots(options);
|
|
49757
|
-
const expanded = configuredPath.startsWith("~/") ?
|
|
50172
|
+
const expanded = configuredPath.startsWith("~/") ? join11(home, configuredPath.slice(2)) : configuredPath === "~" ? home : configuredPath;
|
|
49758
50173
|
const absolute = isAbsolute(expanded) ? resolve2(expanded) : resolve2(options.cwd ?? process.cwd(), expanded);
|
|
49759
50174
|
const canonical = await canonicalPath(absolute, options.allowMissing);
|
|
49760
50175
|
if (fenceCandidates(canonical, aliases).some((candidate) => isFencedPath(candidate, home, dataDirectory))) {
|
|
@@ -49771,13 +50186,13 @@ async function resolveFenceRoots(options) {
|
|
|
49771
50186
|
} catch (error) {
|
|
49772
50187
|
throw fsError(configuredHomePath, error);
|
|
49773
50188
|
}
|
|
49774
|
-
const configuredDataDirectory = resolve2(options.dataDirectory ?? process.env.XDG_DATA_HOME ??
|
|
50189
|
+
const configuredDataDirectory = resolve2(options.dataDirectory ?? process.env.XDG_DATA_HOME ?? join11(home, ".local", "share"));
|
|
49775
50190
|
const dataDirectory = await canonicalPath(configuredDataDirectory, true);
|
|
49776
50191
|
const aliases = [];
|
|
49777
|
-
const logicalCortexkit =
|
|
50192
|
+
const logicalCortexkit = join11(dataDirectory, "cortexkit");
|
|
49778
50193
|
for (const logical of [
|
|
49779
50194
|
logicalCortexkit,
|
|
49780
|
-
...FENCED_CORTEXKIT_ROOTS.map((root) =>
|
|
50195
|
+
...FENCED_CORTEXKIT_ROOTS.map((root) => join11(logicalCortexkit, root))
|
|
49781
50196
|
]) {
|
|
49782
50197
|
const canonical = await canonicalPath(logical, true);
|
|
49783
50198
|
if (canonical !== logical)
|
|
@@ -49791,7 +50206,7 @@ function fenceCandidates(canonical, aliases) {
|
|
|
49791
50206
|
const relativeToAlias = relative(alias.canonical, canonical);
|
|
49792
50207
|
const inside = relativeToAlias === "" || relativeToAlias !== ".." && !relativeToAlias.startsWith(`..${sep}`) && !isAbsolute(relativeToAlias);
|
|
49793
50208
|
if (inside)
|
|
49794
|
-
candidates.push(
|
|
50209
|
+
candidates.push(join11(alias.logical, relativeToAlias));
|
|
49795
50210
|
}
|
|
49796
50211
|
return candidates;
|
|
49797
50212
|
}
|
|
@@ -49822,7 +50237,7 @@ async function canonicalPath(path, allowMissing) {
|
|
|
49822
50237
|
suffix.unshift(basename(candidate));
|
|
49823
50238
|
candidate = parent;
|
|
49824
50239
|
try {
|
|
49825
|
-
return
|
|
50240
|
+
return join11(await realpath2(candidate), ...suffix);
|
|
49826
50241
|
} catch (parentError) {
|
|
49827
50242
|
if (!isMissingError(parentError)) {
|
|
49828
50243
|
throw fsError(path, parentError);
|
|
@@ -49831,8 +50246,8 @@ async function canonicalPath(path, allowMissing) {
|
|
|
49831
50246
|
}
|
|
49832
50247
|
}
|
|
49833
50248
|
}
|
|
49834
|
-
function isFencedPath(canonicalPath, homeDirectory, dataDirectory = process.env.XDG_DATA_HOME ??
|
|
49835
|
-
const cortexkitRoot =
|
|
50249
|
+
function isFencedPath(canonicalPath, homeDirectory, dataDirectory = process.env.XDG_DATA_HOME ?? join11(resolve2(homeDirectory), ".local", "share")) {
|
|
50250
|
+
const cortexkitRoot = join11(resolve2(dataDirectory), "cortexkit");
|
|
49836
50251
|
const relativeToCortexkit = relative(cortexkitRoot, canonicalPath);
|
|
49837
50252
|
const insideCortexkit = relativeToCortexkit !== "" && relativeToCortexkit !== ".." && !relativeToCortexkit.startsWith(`..${sep}`) && !isAbsolute(relativeToCortexkit);
|
|
49838
50253
|
const parts = insideCortexkit ? relativeToCortexkit.split(sep) : [];
|
|
@@ -50511,7 +50926,7 @@ function formatCtxReduceReply(stampedCount, selfStampCount = 0) {
|
|
|
50511
50926
|
return parts.join(" ");
|
|
50512
50927
|
}
|
|
50513
50928
|
// src/tools/ctx-reduce/tools.ts
|
|
50514
|
-
import { createHash as
|
|
50929
|
+
import { createHash as createHash17 } from "node:crypto";
|
|
50515
50930
|
|
|
50516
50931
|
// src/features/magic-context/range-parser.ts
|
|
50517
50932
|
function parseRangeString(input) {
|
|
@@ -50574,11 +50989,11 @@ function createCtxReduceTool(deps) {
|
|
|
50574
50989
|
const stableId = `oc-${sessionId}-${callId}`;
|
|
50575
50990
|
if (Buffer.byteLength(stableId) <= 128)
|
|
50576
50991
|
return stableId;
|
|
50577
|
-
return `oc-${
|
|
50992
|
+
return `oc-${createHash17("sha256").update(stableId).digest("hex")}`;
|
|
50578
50993
|
}
|
|
50579
50994
|
fallbackCommandSequence += 1;
|
|
50580
50995
|
const monotonicId = `oc-${sessionId}-${fallbackCommandSequence}`;
|
|
50581
|
-
return Buffer.byteLength(monotonicId) <= 128 ? monotonicId : `oc-${
|
|
50996
|
+
return Buffer.byteLength(monotonicId) <= 128 ? monotonicId : `oc-${createHash17("sha256").update(monotonicId).digest("hex")}`;
|
|
50582
50997
|
};
|
|
50583
50998
|
return tool({
|
|
50584
50999
|
description: CTX_REDUCE_DESCRIPTION,
|
|
@@ -51420,7 +51835,7 @@ async function registerContext(context) {
|
|
|
51420
51835
|
}
|
|
51421
51836
|
const folds = new FoldOwner(context.storage);
|
|
51422
51837
|
const nativeFoldMemory = !compactionOff && process.env.MC_OC2_INVISIBLE_FOLD === "1" ? nativeFoldCache(() => storage.require()) : undefined;
|
|
51423
|
-
const nativeFoldReplay = nativeFoldMemory ? new NativeFoldReplay(nativeFoldMemory, () => openStoreReader()) : undefined;
|
|
51838
|
+
const nativeFoldReplay = nativeFoldMemory ? new NativeFoldReplay(nativeFoldMemory, () => openStoreReader(), context.storage) : undefined;
|
|
51424
51839
|
setOutputReserveConfig(config.output_reserve);
|
|
51425
51840
|
const queriedModels = new Set;
|
|
51426
51841
|
const rawLimits = new Map;
|
|
@@ -51472,6 +51887,7 @@ async function registerContext(context) {
|
|
|
51472
51887
|
memorySyncRequestedSessions: rustMemorySyncRequestedSessions
|
|
51473
51888
|
}) : undefined;
|
|
51474
51889
|
const hiddenChildHook = new HiddenChildHook;
|
|
51890
|
+
await context.session.hook("http.request", (draft) => hiddenChildHook.cacheRequest(draft));
|
|
51475
51891
|
const tools = db && isDatabasePersisted(db) ? await registerTools(context, db, config, moduleToolBackends?.backends, (id) => hiddenChildHook.owns(id)) : undefined;
|
|
51476
51892
|
const usage = new Map;
|
|
51477
51893
|
const generateReplay = new V2GenerateReplay;
|
|
@@ -51848,83 +52264,114 @@ async function registerContext(context) {
|
|
|
51848
52264
|
}) : undefined;
|
|
51849
52265
|
const usageController = new AbortController;
|
|
51850
52266
|
const usageDone = (async () => {
|
|
51851
|
-
|
|
51852
|
-
|
|
51853
|
-
|
|
51854
|
-
|
|
51855
|
-
const
|
|
51856
|
-
|
|
51857
|
-
|
|
51858
|
-
|
|
51859
|
-
|
|
51860
|
-
|
|
51861
|
-
|
|
51862
|
-
|
|
51863
|
-
|
|
51864
|
-
|
|
51865
|
-
|
|
51866
|
-
|
|
51867
|
-
|
|
52267
|
+
let retry = 0;
|
|
52268
|
+
while (!usageController.signal.aborted) {
|
|
52269
|
+
const subscribedAt = Date.now();
|
|
52270
|
+
try {
|
|
52271
|
+
for await (const value of context.event.subscribe({
|
|
52272
|
+
signal: usageController.signal
|
|
52273
|
+
})) {
|
|
52274
|
+
if (usageController.signal.aborted)
|
|
52275
|
+
break;
|
|
52276
|
+
const event = value;
|
|
52277
|
+
try {
|
|
52278
|
+
if (event.type === "provider.updated" || event.type === "model.updated") {
|
|
52279
|
+
queriedModels.clear();
|
|
52280
|
+
continue;
|
|
52281
|
+
}
|
|
52282
|
+
if (!event.data?.sessionID)
|
|
52283
|
+
continue;
|
|
52284
|
+
const sessionID = event.data.sessionID;
|
|
52285
|
+
if (event.type?.startsWith("session.revert.") || event.type === "session.message.content.updated") {
|
|
52286
|
+
nativeFoldReplay?.onEvent(event);
|
|
52287
|
+
restoredRows.forget(sessionID);
|
|
52288
|
+
}
|
|
52289
|
+
if (event.type === "session.error" || event.type === "session.execution.failed") {
|
|
52290
|
+
const error = hiddenTerminalError(event);
|
|
52291
|
+
if (error !== undefined)
|
|
52292
|
+
hiddenSessionErrors.set(sessionID, error);
|
|
52293
|
+
if (error !== undefined && db && !compactionOff) {
|
|
52294
|
+
const model = liveModels.get(sessionID);
|
|
52295
|
+
try {
|
|
52296
|
+
armLatestThinkingRecoveryFromError({
|
|
52297
|
+
db,
|
|
52298
|
+
sessionId: sessionID,
|
|
52299
|
+
error,
|
|
52300
|
+
providerID: model?.providerID,
|
|
52301
|
+
modelID: model?.modelID
|
|
52302
|
+
});
|
|
52303
|
+
} catch (armError) {
|
|
52304
|
+
log2("[magic-context] v2 latest-thinking recovery arm failed", armError);
|
|
52305
|
+
}
|
|
52306
|
+
}
|
|
52307
|
+
continue;
|
|
52308
|
+
}
|
|
52309
|
+
if (event.type === "session.deleted") {
|
|
52310
|
+
clearLkgMeasuredRequest(sessionID);
|
|
52311
|
+
deletedSessions.add(sessionID);
|
|
52312
|
+
transform?.clearSessionLogState(sessionID);
|
|
52313
|
+
if (db) {
|
|
52314
|
+
markSessionCleanupPending(db, sessionID);
|
|
52315
|
+
clearSession(db, sessionID);
|
|
52316
|
+
}
|
|
52317
|
+
rawProviders.get(sessionID)?.();
|
|
52318
|
+
rawProviders.delete(sessionID);
|
|
52319
|
+
usage.delete(sessionID);
|
|
52320
|
+
hiddenSessionErrors.delete(sessionID);
|
|
52321
|
+
storageNoticeBySession.delete(sessionID);
|
|
52322
|
+
liveModels.delete(sessionID);
|
|
52323
|
+
variants.delete(sessionID);
|
|
52324
|
+
agents.delete(sessionID);
|
|
52325
|
+
channel1.delete(sessionID);
|
|
52326
|
+
commitSeenLastPass.delete(sessionID);
|
|
52327
|
+
clearEmbedSessionState(sessionID);
|
|
52328
|
+
historyRefreshSessions.delete(sessionID);
|
|
52329
|
+
clearPendingMaterialization(pendingMaterializationSessions, sessionID);
|
|
52330
|
+
lastHeuristicsTurnId.delete(sessionID);
|
|
52331
|
+
restoredRows.forget(sessionID);
|
|
52332
|
+
if (nativeFoldReplay)
|
|
52333
|
+
await nativeFoldReplay.forget(sessionID);
|
|
52334
|
+
else
|
|
52335
|
+
await forgetNativeFoldProvenance(context.storage, sessionID);
|
|
52336
|
+
generateReplay.forget(sessionID);
|
|
52337
|
+
systemPromptRefreshSessions.delete(sessionID);
|
|
52338
|
+
systemPrompt?.clearSession(sessionID);
|
|
52339
|
+
tagger.cleanup(sessionID);
|
|
52340
|
+
continue;
|
|
52341
|
+
}
|
|
52342
|
+
if (event.type !== "session.execution.succeeded")
|
|
52343
|
+
continue;
|
|
51868
52344
|
const model = liveModels.get(sessionID);
|
|
51869
|
-
|
|
51870
|
-
|
|
51871
|
-
|
|
51872
|
-
|
|
51873
|
-
error,
|
|
51874
|
-
providerID: model?.providerID,
|
|
51875
|
-
modelID: model?.modelID
|
|
52345
|
+
if (model) {
|
|
52346
|
+
await recordUsage({
|
|
52347
|
+
sessionID,
|
|
52348
|
+
model: { providerID: model.providerID, id: model.modelID }
|
|
51876
52349
|
});
|
|
51877
|
-
|
|
51878
|
-
|
|
52350
|
+
if (!compactionOff && typeof await nativeFoldReplay?.baseline(sessionID) === "string")
|
|
52351
|
+
hostFolds?.idle(sessionID);
|
|
51879
52352
|
}
|
|
52353
|
+
} catch (error) {
|
|
52354
|
+
log2(`[magic-context] v2 event handler failed (type=${event.type ?? "unknown"}, session=${event.data?.sessionID ?? "none"})`, error);
|
|
51880
52355
|
}
|
|
51881
|
-
continue;
|
|
51882
|
-
}
|
|
51883
|
-
if (event.type === "session.deleted") {
|
|
51884
|
-
clearLkgMeasuredRequest(sessionID);
|
|
51885
|
-
deletedSessions.add(sessionID);
|
|
51886
|
-
transform?.clearSessionLogState(sessionID);
|
|
51887
|
-
if (db) {
|
|
51888
|
-
markSessionCleanupPending(db, sessionID);
|
|
51889
|
-
clearSession(db, sessionID);
|
|
51890
|
-
}
|
|
51891
|
-
rawProviders.get(sessionID)?.();
|
|
51892
|
-
rawProviders.delete(sessionID);
|
|
51893
|
-
usage.delete(sessionID);
|
|
51894
|
-
hiddenSessionErrors.delete(sessionID);
|
|
51895
|
-
storageNoticeBySession.delete(sessionID);
|
|
51896
|
-
liveModels.delete(sessionID);
|
|
51897
|
-
variants.delete(sessionID);
|
|
51898
|
-
agents.delete(sessionID);
|
|
51899
|
-
channel1.delete(sessionID);
|
|
51900
|
-
commitSeenLastPass.delete(sessionID);
|
|
51901
|
-
clearEmbedSessionState(sessionID);
|
|
51902
|
-
historyRefreshSessions.delete(sessionID);
|
|
51903
|
-
clearPendingMaterialization(pendingMaterializationSessions, sessionID);
|
|
51904
|
-
lastHeuristicsTurnId.delete(sessionID);
|
|
51905
|
-
restoredRows.forget(sessionID);
|
|
51906
|
-
await nativeFoldReplay?.forget(sessionID);
|
|
51907
|
-
generateReplay.forget(sessionID);
|
|
51908
|
-
systemPromptRefreshSessions.delete(sessionID);
|
|
51909
|
-
systemPrompt?.clearSession(sessionID);
|
|
51910
|
-
tagger.cleanup(sessionID);
|
|
51911
|
-
continue;
|
|
51912
|
-
}
|
|
51913
|
-
if (event.type !== "session.execution.succeeded")
|
|
51914
|
-
continue;
|
|
51915
|
-
const model = liveModels.get(sessionID);
|
|
51916
|
-
if (model) {
|
|
51917
|
-
await recordUsage({
|
|
51918
|
-
sessionID,
|
|
51919
|
-
model: { providerID: model.providerID, id: model.modelID }
|
|
51920
|
-
});
|
|
51921
|
-
if (!compactionOff && typeof await nativeFoldReplay?.baseline(sessionID) === "string")
|
|
51922
|
-
hostFolds?.idle(sessionID);
|
|
51923
52356
|
}
|
|
52357
|
+
} catch (error) {
|
|
52358
|
+
if (!usageController.signal.aborted)
|
|
52359
|
+
log2("[magic-context] v2 usage subscription failed", error);
|
|
52360
|
+
}
|
|
52361
|
+
if (usageController.signal.aborted)
|
|
52362
|
+
break;
|
|
52363
|
+
if (Date.now() - subscribedAt >= 30000)
|
|
52364
|
+
retry = 0;
|
|
52365
|
+
const ceiling = Math.min(30000, 250 * 2 ** retry);
|
|
52366
|
+
retry = Math.min(retry + 1, 7);
|
|
52367
|
+
try {
|
|
52368
|
+
await delay(ceiling * (0.5 + Math.random() * 0.5), undefined, {
|
|
52369
|
+
signal: usageController.signal
|
|
52370
|
+
});
|
|
52371
|
+
} catch (error) {
|
|
52372
|
+
if (!usageController.signal.aborted)
|
|
52373
|
+
throw error;
|
|
51924
52374
|
}
|
|
51925
|
-
} catch (error) {
|
|
51926
|
-
if (!usageController.signal.aborted)
|
|
51927
|
-
log2("[magic-context] v2 usage subscription failed", error);
|
|
51928
52375
|
}
|
|
51929
52376
|
})();
|
|
51930
52377
|
const materialize = (draft) => {
|
|
@@ -52197,6 +52644,7 @@ async function registerContext(context) {
|
|
|
52197
52644
|
compactionOff,
|
|
52198
52645
|
storeGeneration: "v2",
|
|
52199
52646
|
normalizeRestoredAssistantText: stripCopiedTagNotation,
|
|
52647
|
+
refreshSourceContents: (sessionID) => nativeFoldReplay?.needsHeadRebuild(sessionID) ?? false,
|
|
52200
52648
|
hostCleanupCompactionMarkers: () => ({
|
|
52201
52649
|
verified: true,
|
|
52202
52650
|
removedLineages: 0,
|
|
@@ -52285,12 +52733,13 @@ async function registerContext(context) {
|
|
|
52285
52733
|
historyRefreshSessions.add(draft.sessionID);
|
|
52286
52734
|
requestPendingMaterialization(pendingMaterializationSessions, draft.sessionID, "boundary_repair");
|
|
52287
52735
|
}
|
|
52288
|
-
const
|
|
52736
|
+
const localCut = cut && isLocalCheckpoint(cut) ? cut : undefined;
|
|
52737
|
+
const incoming = localCut && draft.messages.find((message) => message.id === localCut.id);
|
|
52289
52738
|
postFold = cut !== undefined;
|
|
52290
|
-
if (
|
|
52739
|
+
if (localCut && !incoming)
|
|
52291
52740
|
throw new Error("The host checkpoint disappeared from the context draft");
|
|
52292
52741
|
let nativeRestored;
|
|
52293
|
-
if (cut && nativeFoldReplay &&
|
|
52742
|
+
if (cut && nativeFoldReplay && await nativeFoldReplay.admits(draft.sessionID, cut, reader)) {
|
|
52294
52743
|
try {
|
|
52295
52744
|
nativeRestored = await nativeFoldReplay.restore(draft.sessionID, cut, `${draft.model.providerID}/${draft.model.id}`, { bounded: !rustModeModuleClient });
|
|
52296
52745
|
} catch (error) {
|
|
@@ -52299,7 +52748,11 @@ async function registerContext(context) {
|
|
|
52299
52748
|
nativeRestored = await nativeFoldReplay.restoreRead(draft.sessionID, cut, draft.model);
|
|
52300
52749
|
}
|
|
52301
52750
|
}
|
|
52302
|
-
if (
|
|
52751
|
+
if (cut && nativeFoldReplay?.sourceChanged(draft.sessionID)) {
|
|
52752
|
+
if (db && !rustModeModuleClient && nativeFoldReplay.needsHeadRebuild(draft.sessionID))
|
|
52753
|
+
clearCachedM0(db, draft.sessionID);
|
|
52754
|
+
if (nativeFoldReplay.needsHeadRebuild(draft.sessionID))
|
|
52755
|
+
restoredRows.forget(draft.sessionID);
|
|
52303
52756
|
historyRefreshSessions.add(draft.sessionID);
|
|
52304
52757
|
requestPendingMaterialization(pendingMaterializationSessions, draft.sessionID, "host_history_change");
|
|
52305
52758
|
}
|
|
@@ -52310,25 +52763,27 @@ async function registerContext(context) {
|
|
|
52310
52763
|
return !id || !present.has(id);
|
|
52311
52764
|
});
|
|
52312
52765
|
draft.messages.splice(0, draft.messages.length, ...hidden, ...draft.messages.filter((message) => message !== incoming));
|
|
52313
|
-
} else if (cut && incoming) {
|
|
52314
|
-
|
|
52315
|
-
|
|
52316
|
-
|
|
52317
|
-
|
|
52318
|
-
|
|
52319
|
-
|
|
52320
|
-
|
|
52321
|
-
|
|
52322
|
-
|
|
52323
|
-
|
|
52324
|
-
|
|
52325
|
-
|
|
52326
|
-
|
|
52766
|
+
} else if (localCut && cut && incoming) {
|
|
52767
|
+
if (!nativeFoldReplay) {
|
|
52768
|
+
const identity = await folds.observe({
|
|
52769
|
+
sessionID: draft.sessionID,
|
|
52770
|
+
cutSeq: cut.seq,
|
|
52771
|
+
summary: cut.data.summary ?? "",
|
|
52772
|
+
rendered: incoming,
|
|
52773
|
+
onHard: (reason) => {
|
|
52774
|
+
sessionLog2(draft.sessionID, `HARD reason=${reason}`);
|
|
52775
|
+
materialize(draft);
|
|
52776
|
+
requestPendingMaterialization(pendingMaterializationSessions, draft.sessionID, "host_compaction");
|
|
52777
|
+
}
|
|
52778
|
+
});
|
|
52779
|
+
checkpoint = structuredClone(identity.rendered ?? incoming);
|
|
52780
|
+
submitted = identity.rendered ? identity.renderedSummary ?? identity.submitted : cut.data.summary ?? "";
|
|
52781
|
+
}
|
|
52327
52782
|
const moduleBoundaryID = rustModeModuleClient ? getPersistedCompactionMarkerState(db, draft.sessionID)?.boundaryMessageId ?? null : null;
|
|
52328
52783
|
const moduleBoundarySeq = moduleBoundaryID ? reader.sequenceForId(draft.sessionID, moduleBoundaryID) : undefined;
|
|
52329
52784
|
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);
|
|
52330
52785
|
const servedBoundary = boundaryID ? servedBoundaryRow(reader, draft.sessionID, boundaryID) : null;
|
|
52331
|
-
const boundary = (moduleBoundarySeq !== undefined ? moduleBoundarySeq - 1 : undefined) ?? servedBoundary?.seq ?? reader.sequenceForId(draft.sessionID, boundaryID) ?? (reader.earliestSequence(draft.sessionID) ?? 0) - 1;
|
|
52786
|
+
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;
|
|
52332
52787
|
if (moduleBoundarySeq !== undefined)
|
|
52333
52788
|
sessionLog2(draft.sessionID, `v2 restore: from the module boundary ${moduleBoundaryID} to the host checkpoint`);
|
|
52334
52789
|
const present = new Set(draft.messages.map((message) => message.id));
|
|
@@ -52579,13 +53034,13 @@ ${baseline}
|
|
|
52579
53034
|
}, 0));
|
|
52580
53035
|
return {
|
|
52581
53036
|
async dispose() {
|
|
53037
|
+
usageController.abort();
|
|
52582
53038
|
await hiddenCompletionExecutor?.dispose();
|
|
53039
|
+
await usageDone;
|
|
52583
53040
|
rpcStopped = true;
|
|
52584
53041
|
rpcServer.stop();
|
|
52585
53042
|
transform?.disposeRust();
|
|
52586
53043
|
tools?.dispose();
|
|
52587
|
-
usageController.abort();
|
|
52588
|
-
await usageDone;
|
|
52589
53044
|
deletedSessions.clear();
|
|
52590
53045
|
await dreamTrigger?.dispose();
|
|
52591
53046
|
await maintenanceTimer?.dispose();
|