@cortexkit/opencode-magic-context 0.49.16 → 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 +11 -11
- package/dist/{compaction-marker-candidates-v5c6997n.js → compaction-marker-candidates-n4krhat4.js} +2 -2
- package/dist/compaction-marker-candidates-worker.js +2 -2
- package/dist/config/schema/magic-context.d.ts +394 -394
- package/dist/{conflict-warning-hook-znry4j76.js → conflict-warning-hook-4pmz879v.js} +5 -5
- package/dist/{context-3znk23va.js → context-yhetp0kn.js} +294 -144
- package/dist/{embedding-backfill-q4n8dend.js → embedding-backfill-fmz50tsy.js} +11 -11
- package/dist/embedding-worker-process.js +1 -1
- package/dist/embedding-worker.js +4 -4
- package/dist/features/magic-context/compartment-chunk-embedding.d.ts +1 -1
- package/dist/features/magic-context/compartment-chunk-embedding.d.ts.map +1 -1
- package/dist/features/magic-context/git-commits/indexer.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding-openai.d.ts.map +1 -1
- package/dist/features/magic-context/memory/project-identity-cache.d.ts +2 -0
- package/dist/features/magic-context/memory/project-identity-cache.d.ts.map +1 -1
- package/dist/features/magic-context/message-index-async.d.ts +1 -1
- package/dist/features/magic-context/message-index-async.d.ts.map +1 -1
- package/dist/features/magic-context/message-index.d.ts +5 -0
- package/dist/features/magic-context/message-index.d.ts.map +1 -1
- package/dist/features/magic-context/search.d.ts +6 -1
- package/dist/features/magic-context/search.d.ts.map +1 -1
- package/dist/features/magic-context/storage-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 +2 -0
- package/dist/hooks/magic-context/compartment-runner-historian.d.ts.map +1 -1
- package/dist/hooks/magic-context/historian-host-runner.d.ts.map +1 -1
- package/dist/hooks/magic-context/hook.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-recovery-fence.d.ts.map +1 -1
- package/dist/hooks/magic-context/read-session-chunk.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-stage-logger.d.ts +3 -0
- package/dist/hooks/magic-context/transform-stage-logger.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform.d.ts +1 -0
- package/dist/hooks/magic-context/transform.d.ts.map +1 -1
- package/dist/{index-9nkg2dzk.js → index-24fezq97.js} +3 -3
- package/dist/{index-a8bvhwqs.js → index-2vxtcb95.js} +32 -3
- package/dist/{index-f71thw8j.js → index-4s3t0nd0.js} +1 -1
- package/dist/{index-kn4t1haw.js → index-4yt7dtf4.js} +450 -227
- package/dist/{index-v9asb16b.js → index-5a1ex6x8.js} +5 -5
- package/dist/{index-fkx2qnvw.js → index-6x57ar45.js} +2 -2
- package/dist/{index-dqe8pq4x.js → index-a6mc0v4d.js} +6 -3
- package/dist/{index-ayym1x7f.js → index-a7c4r5re.js} +145 -736
- package/dist/{index-ek1yxvvz.js → index-aabzay3h.js} +165 -46
- package/dist/{index-hehkf6zm.js → index-b5vqckbw.js} +12 -6
- package/dist/{v2/server-wafzvyhg.js → index-beht37jy.js} +8 -0
- package/dist/{index-7b2cfmaz.js → index-bjcnntmz.js} +2 -2
- package/dist/{index-hqkczed7.js → index-c5pytzne.js} +22 -2
- package/dist/{index-p4vde22c.js → index-cwzfcbtq.js} +956 -77
- package/dist/{index-cj9g0j7a.js → index-fb2qxs2y.js} +7 -7
- package/dist/{index-nd7m2a5a.js → index-hqhm3wke.js} +25 -3
- package/dist/{index-5mwk1nek.js → index-jn12fvvh.js} +1 -1
- package/dist/{index-n6m03s3n.js → index-ke416mdc.js} +1 -1
- package/dist/{index-6a6dq53h.js → index-kmdj7dsq.js} +5 -5
- package/dist/{index-mtw9e71a.js → index-kq82mtg0.js} +2 -2
- package/dist/{index-n78avt2p.js → index-n37sebck.js} +1 -1
- package/dist/{index-v63beg1z.js → index-nkpmm9q8.js} +3 -3
- package/dist/{index-j6zw70pf.js → index-p7m7j0cp.js} +24 -16
- package/dist/{index-wk0n1cgt.js → index-qn7xstt2.js} +2 -2
- package/dist/{index-saews2s3.js → index-rr2bb45z.js} +1 -1
- package/dist/{index-7pa32z07.js → index-s734jcsr.js} +1 -1
- package/dist/{index-b17m64g9.js → index-s74zqahq.js} +1 -1
- package/dist/{index-wv9n2zcq.js → index-v8awdgvd.js} +4 -4
- package/dist/{index-4qfy7v57.js → index-vrzjhftj.js} +31 -20
- package/dist/{index-qrahzcqv.js → index-ze7mvk54.js} +10 -7
- package/dist/index.js +39 -39
- package/dist/{message-fts-rowid-map-yvx5a9jw.js → message-fts-rowid-map-17s0dfn4.js} +5 -3
- package/dist/{message-index-bounded-6th8djy9.js → message-index-bounded-1633vc7f.js} +17 -17
- package/dist/{message-index-t4pz7akd.js → message-index-dprebmtt.js} +13 -13
- package/dist/{message-time-backfill-8egzkd3z.js → message-time-backfill-73mmm76q.js} +1 -1
- package/dist/migration-worker.js +8 -8
- package/dist/plugin/dream-timer.d.ts +11 -0
- package/dist/plugin/dream-timer.d.ts.map +1 -1
- package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
- package/dist/{project-embedding-registry-2dea0a77.js → project-embedding-registry-z74mhqkf.js} +10 -10
- package/dist/raw-ordinal-warmup-worker.js +10 -10
- package/dist/{read-session-chunk-4pwqxm5a.js → read-session-chunk-4zp09ejb.js} +7 -7
- package/dist/{read-session-raw-5ar8se5v.js → read-session-raw-rsc8c7qy.js} +2 -2
- package/dist/{recomp-orchestrator-tjcaj5x7.js → recomp-orchestrator-z3ecszx6.js} +24 -24
- package/dist/{search-rb01n29x.js → search-6mee3vty.js} +20 -20
- package/dist/{search-archive-02jws7hw.js → search-archive-znyy44ve.js} +8 -8
- package/dist/{send-session-notification-2x9edkrp.js → send-session-notification-6ve0e8p4.js} +4 -4
- package/dist/shared/historian-cache.d.ts +8 -0
- package/dist/shared/historian-cache.d.ts.map +1 -0
- package/dist/shared/model-suggestion-retry.d.ts +2 -0
- package/dist/shared/model-suggestion-retry.d.ts.map +1 -1
- package/dist/shared/rpc-discovery-cleanup.d.ts +3 -0
- package/dist/shared/rpc-discovery-cleanup.d.ts.map +1 -0
- package/dist/shared/rpc-server.d.ts +2 -0
- package/dist/shared/rpc-server.d.ts.map +1 -1
- package/dist/shared/search-text.d.ts +8 -0
- package/dist/shared/search-text.d.ts.map +1 -0
- package/dist/shared/sqlite.d.ts +4 -2
- package/dist/shared/sqlite.d.ts.map +1 -1
- package/dist/shared/storage-file-mutex.d.ts.map +1 -1
- package/dist/shared/subagent-runner.d.ts +2 -0
- package/dist/shared/subagent-runner.d.ts.map +1 -1
- package/dist/shared/system-directive.d.ts +2 -0
- package/dist/shared/system-directive.d.ts.map +1 -1
- package/dist/{sqlite-4pqyynrs.js → sqlite-zf72c52d.js} +1 -1
- package/dist/{storage-memory-j3v3hc83.js → storage-memory-y3qmy00r.js} +2 -2
- package/dist/{storage-tags-4z1w27xa.js → storage-tags-8qns3012.js} +8 -4
- package/dist/{transform-postprocess-phase-xaw5c3xp.js → transform-postprocess-phase-3ydzxa62.js} +24 -24
- package/dist/v2/auto-search-worker.js +76 -63
- package/dist/v2/chunk-embedding-write-worker.js +11 -11
- package/dist/v2/{compaction-marker-candidates-1vqwr3s5.js → compaction-marker-candidates-ebx3388k.js} +2 -2
- package/dist/v2/compaction-marker-candidates-worker.js +2 -2
- package/dist/v2/{context-acw1nhv8.js → context-jn3zpeqh.js} +882 -393
- package/dist/v2/embedding-backfill-7c7yr69y.js +23 -0
- package/dist/v2/embedding-worker-process.js +1 -1
- package/dist/v2/embedding-worker.js +4 -4
- package/dist/v2/fold/native-replay.d.ts +11 -2
- package/dist/v2/fold/native-replay.d.ts.map +1 -1
- package/dist/v2/fold/policy.d.ts.map +1 -1
- package/dist/v2/fold/restore.d.ts.map +1 -1
- package/dist/v2/hooks/context.d.ts.map +1 -1
- package/dist/v2/hooks/hidden-child.d.ts +8 -0
- package/dist/v2/hooks/hidden-child.d.ts.map +1 -1
- package/dist/v2/hooks/types.d.ts +17 -0
- package/dist/v2/hooks/types.d.ts.map +1 -1
- package/dist/v2/{message-fts-rowid-map-8vf0v7cr.js → message-fts-rowid-map-wfx67gfd.js} +5 -3
- package/dist/v2/{message-index-bounded-dsrf49y7.js → message-index-bounded-hpejqyd8.js} +17 -17
- package/dist/v2/{message-index-e6qzw477.js → message-index-pxehjpzx.js} +13 -13
- package/dist/v2/{message-time-backfill-q5pgxf0d.js → message-time-backfill-04t0km1z.js} +1 -1
- package/dist/v2/migration-worker.js +8 -8
- package/dist/v2/{project-embedding-registry-rek75aqw.js → project-embedding-registry-gnkj56xp.js} +10 -10
- package/dist/v2/raw-ordinal-warmup-worker.js +10 -10
- package/dist/v2/{read-session-chunk-7bpygfv2.js → read-session-chunk-zdppn4bj.js} +7 -7
- package/dist/v2/{read-session-raw-pw2n1qgc.js → read-session-raw-yaegtjzh.js} +2 -2
- package/dist/v2/{recomp-orchestrator-hzpgg06e.js → recomp-orchestrator-cmqnfpp3.js} +24 -24
- package/dist/v2/{search-sf2vg5pk.js → search-66842dya.js} +20 -20
- package/dist/v2/{search-archive-fn4wy8sx.js → search-archive-gfh11vs0.js} +8 -8
- package/dist/v2/{send-session-notification-hmr7q0nt.js → send-session-notification-3pxn658x.js} +4 -4
- package/dist/v2/{server-785mb90s.js → server-1wy7b9de.js} +6 -3
- package/dist/v2/{server-g59aatsz.js → server-3rhpvy84.js} +956 -77
- package/dist/v2/{server-kqpawe1a.js → server-46neh5fa.js} +12 -6
- package/dist/v2/{server-rrqpvwqd.js → server-6tmj0s7j.js} +2 -2
- package/dist/v2/{server-kr2kc9dz.js → server-8by8qfec.js} +10 -7
- package/dist/v2/{server-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-zyw55ygv.js → server-ec4ca92p.js} +5 -5
- package/dist/v2/{server-6fyp0v67.js → server-fw7wrk01.js} +145 -737
- package/dist/v2/{server-zs8d0s3b.js → server-g3qma5c0.js} +1 -1
- package/dist/v2/{server-00hx04yn.js → server-gpvay0xz.js} +2 -2
- package/dist/v2/{server-r9gjxcte.js → server-gtfhttbr.js} +7 -7
- package/dist/v2/{server-gha9x4qq.js → server-h1v0pyxb.js} +2 -2
- package/dist/v2/{server-hgg55hde.js → server-hy3d3vsx.js} +1 -1
- package/dist/v2/{server-1hcbw661.js → server-kh7dpa1a.js} +24 -16
- package/dist/v2/{server-vgpab6rd.js → server-my7k4eds.js} +4 -4
- package/dist/v2/{server-d8tj10db.js → server-n1prf1g6.js} +1 -1
- package/dist/v2/{server-n78avt2p.js → server-n37sebck.js} +1 -1
- package/dist/v2/{server-y5pznjt9.js → server-nj659894.js} +5 -5
- package/dist/v2/{server-e3ftpk7v.js → server-rmygf5pn.js} +32 -3
- package/dist/v2/{server-0ppsweh6.js → server-tgnbmwah.js} +22 -2
- package/dist/v2/{server-n5q841qn.js → server-vsw8tmm6.js} +31 -20
- package/dist/v2/{server-6714jebr.js → server-xj136kt8.js} +1 -1
- package/dist/v2/{server-0mzjjw3s.js → server-zyzawhdw.js} +25 -3
- package/dist/v2/{server-aavz8pm6.js → server-zzkj2fch.js} +3 -3
- package/dist/v2/server.js +4 -4
- package/dist/v2/{sqlite-4pqyynrs.js → sqlite-zf72c52d.js} +1 -1
- package/dist/v2/{storage-memory-j3v3hc83.js → storage-memory-y3qmy00r.js} +2 -2
- package/dist/v2/{storage-tags-hkwtbp3g.js → storage-tags-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-x4xj1782.js → wrapup-orchestrator-xs8redz9.js} +24 -24
- 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/shared/historian-cache.test.ts +69 -0
- package/src/shared/historian-cache.ts +55 -0
- package/src/shared/model-suggestion-retry.ts +2 -0
- package/src/shared/rpc-discovery-cleanup.test.ts +57 -0
- package/src/shared/rpc-discovery-cleanup.ts +57 -0
- package/src/shared/rpc-server.ts +36 -13
- package/src/shared/search-text.test.ts +47 -0
- package/src/shared/search-text.ts +63 -0
- package/src/shared/sqlite.test.ts +56 -0
- package/src/shared/sqlite.ts +51 -2
- package/src/shared/storage-file-mutex-review.test.ts +22 -2
- package/src/shared/storage-file-mutex.ts +11 -1
- package/src/shared/subagent-runner.ts +2 -0
- package/src/shared/system-directive.ts +19 -1
- package/src/shared/tag-transcript.ts +12 -4
- package/dist/v2/embedding-backfill-jyd6492b.js +0 -23
- package/dist/wrapup-orchestrator-vj2tbp22.js +0 -48
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
resolveLegacyConfigSources,
|
|
7
7
|
getProtectedTokensTierOverrides,
|
|
8
8
|
loadPluginConfigDetailed
|
|
9
|
-
} from "./server-
|
|
9
|
+
} from "./server-nj659894.js";
|
|
10
10
|
import {
|
|
11
11
|
getHarness2,
|
|
12
12
|
harnessOwnsOpenCodeStore2
|
|
@@ -86,10 +86,6 @@ import {
|
|
|
86
86
|
getUnpublishedAutoSearchNoHint,
|
|
87
87
|
forgetUnpublishedAutoSearchNoHint,
|
|
88
88
|
registerAutoSearchWork,
|
|
89
|
-
gaDatabasePath,
|
|
90
|
-
RAW_MESSAGE_TYPES,
|
|
91
|
-
V2StoreReaderPool,
|
|
92
|
-
V2StoreReader,
|
|
93
89
|
getOrCreateSessionMeta,
|
|
94
90
|
updateSessionMeta,
|
|
95
91
|
advanceToolReclaimWatermark,
|
|
@@ -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,7 +572,7 @@ import {
|
|
|
574
572
|
isTransientSqliteError2,
|
|
575
573
|
SqliteAcquisitionBusyError2,
|
|
576
574
|
withAsyncPrivilegedWriter2
|
|
577
|
-
} from "./server-
|
|
575
|
+
} from "./server-beht37jy.js";
|
|
578
576
|
import"./server-51779zs2.js";
|
|
579
577
|
import {
|
|
580
578
|
isRawCompactionSummaryInfo2,
|
|
@@ -582,11 +580,11 @@ import {
|
|
|
582
580
|
buildInMemoryTailRawMessages2,
|
|
583
581
|
RawOrdinalsNotReady2,
|
|
584
582
|
runSessionWarmupWorker
|
|
585
|
-
} from "./server-
|
|
586
|
-
import"./server-
|
|
583
|
+
} from "./server-xj136kt8.js";
|
|
584
|
+
import"./server-1wy7b9de.js";
|
|
587
585
|
import {
|
|
588
586
|
deleteChunkEmbedBackoffForSession
|
|
589
|
-
} from "./server-
|
|
587
|
+
} from "./server-46neh5fa.js";
|
|
590
588
|
import {
|
|
591
589
|
registerOwnRpcServerInstance,
|
|
592
590
|
rpcPortDir,
|
|
@@ -605,14 +603,20 @@ import {
|
|
|
605
603
|
prepareLkgCaptureFence,
|
|
606
604
|
certifyCommittedLkgCapture,
|
|
607
605
|
markLkgRecoveryDirty,
|
|
606
|
+
cleanSearchText,
|
|
607
|
+
matchedSearchSnippet,
|
|
608
|
+
gaDatabasePath,
|
|
609
|
+
RAW_MESSAGE_TYPES,
|
|
610
|
+
V2StoreReaderPool,
|
|
611
|
+
V2StoreReader,
|
|
608
612
|
advanceSessionActivity,
|
|
609
613
|
backfillSessionActivity,
|
|
610
614
|
getLastIndexedOrdinal2,
|
|
611
615
|
getMessageIndexReconciliationStartOrdinal2,
|
|
612
616
|
isMessageIndexReconciledThrough2,
|
|
613
617
|
indexMessagesAfterOrdinal2,
|
|
614
|
-
|
|
615
|
-
} from "./server-
|
|
618
|
+
sweepOrphanedOpenCodeMessageIndexesCooperatively2
|
|
619
|
+
} from "./server-3rhpvy84.js";
|
|
616
620
|
import {
|
|
617
621
|
stableStringify,
|
|
618
622
|
getTemporalDecisions,
|
|
@@ -671,12 +675,14 @@ import {
|
|
|
671
675
|
getPendingOpsCount,
|
|
672
676
|
clearPendingOps,
|
|
673
677
|
removePendingOp,
|
|
678
|
+
updateTagByteSize2,
|
|
674
679
|
getRecentTagOwnerMessageIds2,
|
|
675
680
|
AGE_RECLAIM_MIN_TOKENS2,
|
|
676
681
|
getOldestActiveUnprotectedToolTags2,
|
|
677
682
|
getActiveToolTagsForAgeReclaim2,
|
|
678
683
|
getTriggerTagTokenUpperBound2,
|
|
679
684
|
getActiveTagTokenTotalsByMessage2,
|
|
685
|
+
updateTagTokenCount2,
|
|
680
686
|
tryGetReasoningTokenEstimatesByMessage2,
|
|
681
687
|
cachedTagOwnerRatios2,
|
|
682
688
|
tagOwnerWarmupState2,
|
|
@@ -713,7 +719,7 @@ import {
|
|
|
713
719
|
adoptNullOwnerToolTag2,
|
|
714
720
|
getCandidateToolOwners2,
|
|
715
721
|
pickNearestPriorOwner2
|
|
716
|
-
} from "./server-
|
|
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,
|
|
@@ -882,14 +888,14 @@ import {
|
|
|
882
888
|
resolveMemoriesByIdsForSearch2,
|
|
883
889
|
unifiedSearch2,
|
|
884
890
|
formatSearchResults2
|
|
885
|
-
} from "./server-
|
|
891
|
+
} from "./server-vsw8tmm6.js";
|
|
886
892
|
import {
|
|
887
893
|
resolvePromptContext2
|
|
888
894
|
} from "./server-fmsr7v69.js";
|
|
889
895
|
import"./server-kaqs6h31.js";
|
|
890
896
|
import {
|
|
891
897
|
renderSearchArchiveOffThread2
|
|
892
|
-
} from "./server-
|
|
898
|
+
} from "./server-ec4ca92p.js";
|
|
893
899
|
import {
|
|
894
900
|
compareSemverCore
|
|
895
901
|
} from "./server-84w6rvvf.js";
|
|
@@ -1636,6 +1642,9 @@ __export(exports_coerce, {
|
|
|
1636
1642
|
string: () => string3
|
|
1637
1643
|
});
|
|
1638
1644
|
|
|
1645
|
+
// src/v2/hooks/context.ts
|
|
1646
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
1647
|
+
|
|
1639
1648
|
// src/config/dependency-notes.ts
|
|
1640
1649
|
function scheduledTasks(config) {
|
|
1641
1650
|
const tasks = config.dreamer?.tasks ?? {};
|
|
@@ -3423,9 +3432,14 @@ function scheduleReconciliation(db, sessionId, readMessages) {
|
|
|
3423
3432
|
});
|
|
3424
3433
|
}
|
|
3425
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
|
+
});
|
|
3426
3440
|
const path = getSqliteDatabasePath2(db);
|
|
3427
|
-
if (!path || getHarness2() !== "opencode")
|
|
3428
|
-
return
|
|
3441
|
+
if (!path || getHarness2() !== "opencode" && getHarness2() !== "opencode2")
|
|
3442
|
+
return sweepOrphanedOpenCodeMessageIndexesCooperatively2(db, openSource, options);
|
|
3429
3443
|
let source = null;
|
|
3430
3444
|
let sourcePath = null;
|
|
3431
3445
|
try {
|
|
@@ -3437,7 +3451,7 @@ async function sweepOrphanedOpenCodeMessageIndexesOffThread(db, openSource, opti
|
|
|
3437
3451
|
source?.close();
|
|
3438
3452
|
}
|
|
3439
3453
|
if (!sourcePath)
|
|
3440
|
-
return
|
|
3454
|
+
return sweepOrphanedOpenCodeMessageIndexesCooperatively2(db, () => source, options);
|
|
3441
3455
|
const reply = await runSessionWarmupWorker({
|
|
3442
3456
|
path,
|
|
3443
3457
|
sessionId: "",
|
|
@@ -3512,7 +3526,8 @@ function seedSessionCacheTtlIfUnsynced(args) {
|
|
|
3512
3526
|
}
|
|
3513
3527
|
|
|
3514
3528
|
// src/hooks/magic-context/auto-search-deadline.ts
|
|
3515
|
-
var AUTO_SEARCH_TIMEOUT_MS =
|
|
3529
|
+
var AUTO_SEARCH_TIMEOUT_MS = 1000;
|
|
3530
|
+
var AUTO_SEARCH_VECTOR_TIMEOUT_MS = 200;
|
|
3516
3531
|
var operationDeadlines = new WeakMap;
|
|
3517
3532
|
function autoSearchDeadlineUnixMs(signal) {
|
|
3518
3533
|
const deadline = signal && operationDeadlines.get(signal);
|
|
@@ -4061,32 +4076,32 @@ function formatAge(committedAtMs) {
|
|
|
4061
4076
|
const years = Math.floor(days / 365);
|
|
4062
4077
|
return years === 1 ? "1y ago" : `${years}y ago`;
|
|
4063
4078
|
}
|
|
4064
|
-
function renderFragment(result, charCap, wordRules) {
|
|
4079
|
+
function renderFragment(result, charCap, wordRules, query) {
|
|
4065
4080
|
switch (result.source) {
|
|
4066
4081
|
case "memory": {
|
|
4067
|
-
const compressed = cavemanCompress(result.content, "ultra", CURRENT_CAVEMAN_RULES, wordRules);
|
|
4082
|
+
const compressed = cavemanCompress(cleanSearchText(result.content), "ultra", CURRENT_CAVEMAN_RULES, wordRules);
|
|
4068
4083
|
return truncate(compressed, charCap);
|
|
4069
4084
|
}
|
|
4070
4085
|
case "git_commit": {
|
|
4071
|
-
const subject = result.content.split(/\r?\n/)[0] ?? result.content;
|
|
4086
|
+
const subject = cleanSearchText(result.content.split(/\r?\n/)[0] ?? result.content);
|
|
4072
4087
|
const body = truncate(subject, Math.max(10, charCap - 20));
|
|
4073
4088
|
return `commit ${result.shortSha} ${formatAge(result.committedAtMs)}: ${body}`;
|
|
4074
4089
|
}
|
|
4075
4090
|
case "message": {
|
|
4076
|
-
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);
|
|
4077
4092
|
return truncate(compressed, charCap);
|
|
4078
4093
|
}
|
|
4079
4094
|
case "compartment": {
|
|
4080
|
-
const source = result.
|
|
4095
|
+
const source = cleanSearchText(result.title);
|
|
4081
4096
|
const compressed = cavemanCompress(source, "ultra", CURRENT_CAVEMAN_RULES, wordRules);
|
|
4082
4097
|
return truncate(compressed, charCap);
|
|
4083
4098
|
}
|
|
4084
4099
|
case "primer": {
|
|
4085
|
-
const compressed = cavemanCompress(result.content, "ultra", CURRENT_CAVEMAN_RULES, wordRules);
|
|
4100
|
+
const compressed = cavemanCompress(cleanSearchText(result.content), "ultra", CURRENT_CAVEMAN_RULES, wordRules);
|
|
4086
4101
|
return truncate(compressed, charCap);
|
|
4087
4102
|
}
|
|
4088
4103
|
case "note": {
|
|
4089
|
-
const compressed = cavemanCompress(result.content, "ultra", CURRENT_CAVEMAN_RULES, wordRules);
|
|
4104
|
+
const compressed = cavemanCompress(cleanSearchText(result.content), "ultra", CURRENT_CAVEMAN_RULES, wordRules);
|
|
4090
4105
|
return truncate(compressed, charCap);
|
|
4091
4106
|
}
|
|
4092
4107
|
}
|
|
@@ -4097,7 +4112,7 @@ function buildAutoSearchHint(results, options = {}) {
|
|
|
4097
4112
|
const picks = results.slice(0, maxFragments);
|
|
4098
4113
|
const lines = [];
|
|
4099
4114
|
for (const result of picks) {
|
|
4100
|
-
const fragment = renderFragment(result, fragmentCharCap, options.wordRules ?? "english");
|
|
4115
|
+
const fragment = renderFragment(result, fragmentCharCap, options.wordRules ?? "english", options.query ?? "");
|
|
4101
4116
|
if (fragment.length === 0)
|
|
4102
4117
|
continue;
|
|
4103
4118
|
lines.push(`- ${fragment}`);
|
|
@@ -4120,6 +4135,9 @@ ${trimmedBody}…
|
|
|
4120
4135
|
}
|
|
4121
4136
|
return wrapped;
|
|
4122
4137
|
}
|
|
4138
|
+
function selectAutoSearchResults(results, threshold) {
|
|
4139
|
+
return results.filter((result) => (result.relevanceScore ?? result.score) >= threshold);
|
|
4140
|
+
}
|
|
4123
4141
|
|
|
4124
4142
|
// src/hooks/magic-context/auto-search-worker-client.ts
|
|
4125
4143
|
import { Worker } from "node:worker_threads";
|
|
@@ -4215,6 +4233,63 @@ async function searchAutoHint(db, sessionId, projectPath, query, options, entry
|
|
|
4215
4233
|
return executeAutoSearchWorker(db, sessionId, projectPath, query, options, entry, "search");
|
|
4216
4234
|
}
|
|
4217
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
|
+
}
|
|
4218
4293
|
function queueAutoSearchBackfill(db, sessionId, projectPath, query) {
|
|
4219
4294
|
if (isEmbeddingHostBusy2())
|
|
4220
4295
|
return Promise.resolve();
|
|
@@ -4279,6 +4354,7 @@ async function executeAutoSearchWorker(db, sessionId, projectPath, query, option
|
|
|
4279
4354
|
query,
|
|
4280
4355
|
options: {
|
|
4281
4356
|
...serializable,
|
|
4357
|
+
autoHint: true,
|
|
4282
4358
|
backfillMemoryEmbeddings: false,
|
|
4283
4359
|
countRetrievals: false,
|
|
4284
4360
|
measurementDisabled: true
|
|
@@ -4288,8 +4364,20 @@ async function executeAutoSearchWorker(db, sessionId, projectPath, query, option
|
|
|
4288
4364
|
snapshot,
|
|
4289
4365
|
deadlineUnixMs: autoSearchDeadlineUnixMs(deadlineSignal)
|
|
4290
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;
|
|
4291
4380
|
return new Promise((resolve, reject) => {
|
|
4292
|
-
const worker = inRootAsyncContext2(() => new Worker(entry, { workerData: input }));
|
|
4293
4381
|
let settled = false;
|
|
4294
4382
|
const finish = (results, error) => {
|
|
4295
4383
|
if (settled)
|
|
@@ -4298,7 +4386,25 @@ async function executeAutoSearchWorker(db, sessionId, projectPath, query, option
|
|
|
4298
4386
|
signal?.removeEventListener("abort", abort);
|
|
4299
4387
|
lifecycle.signal.removeEventListener("abort", abort);
|
|
4300
4388
|
lifecycle.done();
|
|
4301
|
-
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();
|
|
4302
4408
|
worker.unref();
|
|
4303
4409
|
if (error)
|
|
4304
4410
|
reject(error);
|
|
@@ -4308,9 +4414,9 @@ async function executeAutoSearchWorker(db, sessionId, projectPath, query, option
|
|
|
4308
4414
|
const abort = () => finish([]);
|
|
4309
4415
|
signal?.addEventListener("abort", abort, { once: true });
|
|
4310
4416
|
lifecycle.signal.addEventListener("abort", abort, { once: true });
|
|
4311
|
-
|
|
4312
|
-
|
|
4313
|
-
|
|
4417
|
+
const onError = (error) => finish([], error);
|
|
4418
|
+
const onExit = (code) => finish([], new Error(`auto-search worker exited (${code})`));
|
|
4419
|
+
const onMessage = async (reply) => {
|
|
4314
4420
|
if (settled)
|
|
4315
4421
|
return;
|
|
4316
4422
|
if (reply.kind === "result") {
|
|
@@ -4329,7 +4435,7 @@ async function executeAutoSearchWorker(db, sessionId, projectPath, query, option
|
|
|
4329
4435
|
const response = { id: reply.id };
|
|
4330
4436
|
try {
|
|
4331
4437
|
if (reply.kind === "query")
|
|
4332
|
-
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;
|
|
4333
4439
|
else {
|
|
4334
4440
|
const passage = await embedBatchForProject2(projectPath, reply.texts, signal, reply.purpose);
|
|
4335
4441
|
const current = getProjectEmbeddingSnapshot2(projectPath);
|
|
@@ -4344,13 +4450,46 @@ async function executeAutoSearchWorker(db, sessionId, projectPath, query, option
|
|
|
4344
4450
|
response.error = error instanceof Error ? error.message : String(error);
|
|
4345
4451
|
}
|
|
4346
4452
|
response.embeddingHostBusy = isEmbeddingHostBusy2();
|
|
4347
|
-
if (!settled && !signal?.aborted)
|
|
4348
|
-
|
|
4349
|
-
|
|
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);
|
|
4350
4464
|
if (signal?.aborted)
|
|
4351
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
|
+
}
|
|
4352
4473
|
});
|
|
4353
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
|
+
}
|
|
4354
4493
|
function defaultAutoSearchWorkerEntry() {
|
|
4355
4494
|
return new URL(new URL(import.meta.url).pathname.endsWith(".ts") ? "./auto-search-worker.ts" : "./auto-search-worker.js", import.meta.url);
|
|
4356
4495
|
}
|
|
@@ -4658,6 +4797,8 @@ async function runAutoSearchHint(args) {
|
|
|
4658
4797
|
const gitCommitsEnabled = embeddingSnapshot?.gitCommitEnabled ?? options.gitCommitsEnabled ?? false;
|
|
4659
4798
|
const searchOptions = {
|
|
4660
4799
|
limit: 10,
|
|
4800
|
+
maxMessageOrdinal: Math.max(0, getLastCompartmentEndMessage(db, sessionId)),
|
|
4801
|
+
excludeMessageId: userMsgId,
|
|
4661
4802
|
memoryEnabled,
|
|
4662
4803
|
embeddingEnabled,
|
|
4663
4804
|
gitCommitsEnabled,
|
|
@@ -4695,11 +4836,15 @@ async function runAutoSearchHint(args) {
|
|
|
4695
4836
|
if (results.length === 0) {
|
|
4696
4837
|
return writeNoHintAndReconcile("empty");
|
|
4697
4838
|
}
|
|
4698
|
-
|
|
4699
|
-
|
|
4839
|
+
results = selectAutoSearchResults(results, options.scoreThreshold);
|
|
4840
|
+
if (results.length === 0) {
|
|
4841
|
+
sessionLog2(sessionId, `auto-search: no fragment meets relevance threshold ${options.scoreThreshold}`);
|
|
4700
4842
|
return writeNoHintAndReconcile("below-threshold");
|
|
4701
4843
|
}
|
|
4702
|
-
const hintText = buildAutoSearchHint(results, {
|
|
4844
|
+
const hintText = buildAutoSearchHint(results, {
|
|
4845
|
+
wordRules: options.wordRules,
|
|
4846
|
+
query: rawPrompt
|
|
4847
|
+
});
|
|
4703
4848
|
if (!hintText) {
|
|
4704
4849
|
return writeNoHintAndReconcile("empty");
|
|
4705
4850
|
}
|
|
@@ -6954,27 +7099,43 @@ function buildReplacementContent(tagId) {
|
|
|
6954
7099
|
return `[dropped §${tagId}§]`;
|
|
6955
7100
|
}
|
|
6956
7101
|
function applyNewToolDrop(target, options) {
|
|
6957
|
-
|
|
7102
|
+
const plan = planNewToolDrop(target, options, !!options.persist);
|
|
7103
|
+
if (!plan)
|
|
6958
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;
|
|
6959
7111
|
}
|
|
6960
7112
|
if (!target) {
|
|
6961
|
-
|
|
6962
|
-
return { result: "absent", mode: "full" };
|
|
7113
|
+
return { mode: "full", apply: () => ({ result: "absent", mode: "full" }) };
|
|
6963
7114
|
}
|
|
6964
|
-
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) {
|
|
6965
7116
|
const strip = target.hasAttachments?.() === true;
|
|
6966
|
-
|
|
7117
|
+
const mode = strip ? "skeleton_stripped" : "skeleton_real";
|
|
6967
7118
|
return {
|
|
6968
|
-
|
|
6969
|
-
|
|
7119
|
+
mode,
|
|
7120
|
+
apply: () => ({
|
|
7121
|
+
result: (strip ? target.skeletonStripped?.() : target.skeletonReal?.()) ?? "absent",
|
|
7122
|
+
mode
|
|
7123
|
+
})
|
|
6970
7124
|
};
|
|
6971
7125
|
}
|
|
6972
|
-
|
|
6973
|
-
|
|
6974
|
-
|
|
6975
|
-
|
|
6976
|
-
|
|
6977
|
-
|
|
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
|
+
};
|
|
6978
7139
|
}
|
|
6979
7140
|
function applyPersistedToolDrop(db, sessionId, tagNumber, target, options, afterWrite) {
|
|
6980
7141
|
return applyNewToolDrop(target, {
|
|
@@ -7068,6 +7229,7 @@ function renderConvertedToolSkeletons(targets, converted) {
|
|
|
7068
7229
|
}
|
|
7069
7230
|
return didMutate;
|
|
7070
7231
|
}
|
|
7232
|
+
var PENDING_OPERATION_CHUNK_SIZE = 64;
|
|
7071
7233
|
function applyPendingOperations(sessionId, db, targets, protectedTagIds, preloadedTags, preloadedPendingOps, syntheticPendingOps = [], editMarkerTagIds = new Set, onTagReduced, onBatchComplete, onEligibilitySnapshot) {
|
|
7072
7234
|
let didMutateMessage = false;
|
|
7073
7235
|
let diagnostics;
|
|
@@ -7077,153 +7239,184 @@ function applyPendingOperations(sessionId, db, targets, protectedTagIds, preload
|
|
|
7077
7239
|
diagnostics.reasons[reason] = (diagnostics.reasons[reason] ?? 0) + 1;
|
|
7078
7240
|
};
|
|
7079
7241
|
let admitted = false;
|
|
7080
|
-
|
|
7081
|
-
|
|
7082
|
-
|
|
7083
|
-
|
|
7084
|
-
|
|
7085
|
-
|
|
7086
|
-
|
|
7087
|
-
|
|
7088
|
-
|
|
7089
|
-
|
|
7090
|
-
|
|
7091
|
-
|
|
7092
|
-
|
|
7093
|
-
|
|
7094
|
-
const tagStatusById = new Map(tags.map((tag) => [tag.tagNumber, tag.status]));
|
|
7095
|
-
const tagTypeById = new Map(tags.map((tag) => [tag.tagNumber, tag.type]));
|
|
7096
|
-
const opsToApply = [
|
|
7097
|
-
...pendingOps.map((op) => ({ op, synthetic: false })),
|
|
7098
|
-
...syntheticPendingOps.map((op) => ({ op, synthetic: true }))
|
|
7099
|
-
];
|
|
7100
|
-
diagnostics = {
|
|
7101
|
-
source: pendingOps.length > 0 && syntheticPendingOps.length > 0 ? "mixed" : syntheticPendingOps.length > 0 ? "synthetic" : "pending",
|
|
7102
|
-
total: opsToApply.length,
|
|
7103
|
-
mutated: 0,
|
|
7104
|
-
persistedWithoutMutation: 0,
|
|
7105
|
-
reasons: {}
|
|
7106
|
-
};
|
|
7107
|
-
const skeletonWindow = new Set(preloadedTags ? tags.filter((tag) => tag.type === "tool").map((tag) => tag.tagNumber).sort((left, right) => right - left).slice(0, RECENT_TOOL_SKELETON_WINDOW) : getNewestToolTagNumbers2(db, sessionId, RECENT_TOOL_SKELETON_WINDOW));
|
|
7108
|
-
for (const { op: pendingOp, synthetic } of opsToApply) {
|
|
7109
|
-
let operationMutated = false;
|
|
7110
|
-
const tagStatus = tagStatusById.get(pendingOp.tagId);
|
|
7111
|
-
if (tagStatus === "compacted" || tagStatus === "dropped") {
|
|
7112
|
-
reject("already_reduced");
|
|
7113
|
-
if (!synthetic)
|
|
7114
|
-
removePendingOp(db, sessionId, pendingOp.tagId);
|
|
7115
|
-
continue;
|
|
7116
|
-
}
|
|
7117
|
-
const target = targets.get(pendingOp.tagId);
|
|
7118
|
-
const veto = pendingDropVeto(pendingOp.tagId, target, protectedTagIds);
|
|
7119
|
-
if (veto) {
|
|
7120
|
-
reject(veto);
|
|
7121
|
-
continue;
|
|
7122
|
-
}
|
|
7123
|
-
const isToolTag = tagTypeById.get(pendingOp.tagId) === "tool";
|
|
7124
|
-
if (synthetic) {
|
|
7125
|
-
if (!isToolTag) {
|
|
7126
|
-
reject("synthetic_non_tool");
|
|
7127
|
-
continue;
|
|
7128
|
-
}
|
|
7129
|
-
if (target?.canDrop?.() !== true) {
|
|
7130
|
-
reject("synthetic_target_not_droppable");
|
|
7131
|
-
continue;
|
|
7132
|
-
}
|
|
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;
|
|
7133
7256
|
}
|
|
7134
|
-
const
|
|
7135
|
-
|
|
7136
|
-
|
|
7137
|
-
|
|
7138
|
-
|
|
7139
|
-
|
|
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");
|
|
7140
7300
|
if (!synthetic)
|
|
7141
7301
|
removePendingOp(db, sessionId, pendingOp.tagId);
|
|
7142
|
-
}).immediate();
|
|
7143
|
-
} finally {
|
|
7144
|
-
if (startedAt)
|
|
7145
|
-
logSlowWriteTransaction("apply_pending_operation", startedAt);
|
|
7146
|
-
}
|
|
7147
|
-
};
|
|
7148
|
-
let shouldPersistDrop = false;
|
|
7149
|
-
if (isToolTag) {
|
|
7150
|
-
if (editMarkerTagIds.has(pendingOp.tagId)) {
|
|
7151
|
-
const strip = target?.hasAttachments?.() === true;
|
|
7152
|
-
if (target?.canDrop?.() === false || target?.prepareDrop?.() === false || !target) {
|
|
7153
|
-
reject("edit_marker_incomplete");
|
|
7154
7302
|
continue;
|
|
7155
7303
|
}
|
|
7156
|
-
|
|
7157
|
-
|
|
7158
|
-
if (markResult === "incomplete" || markResult === "absent") {
|
|
7159
|
-
reject(`edit_marker_${markResult}`);
|
|
7304
|
+
if (removedTagIds.has(pendingOp.tagId)) {
|
|
7305
|
+
reject("drop_incomplete");
|
|
7160
7306
|
continue;
|
|
7161
7307
|
}
|
|
7162
|
-
|
|
7163
|
-
|
|
7164
|
-
|
|
7165
|
-
|
|
7166
|
-
} else {
|
|
7167
|
-
const { result: dropResult, mode: appliedMode } = applyNewToolDrop(target, {
|
|
7168
|
-
inWindow: skeletonWindow.has(pendingOp.tagId),
|
|
7169
|
-
persist: persistDrop
|
|
7170
|
-
});
|
|
7171
|
-
if (dropResult === "incomplete" || synthetic && dropResult !== "removed" && dropResult !== "truncated") {
|
|
7172
|
-
reject(`drop_${dropResult}`);
|
|
7308
|
+
const target = targets.get(pendingOp.tagId);
|
|
7309
|
+
const veto = pendingDropVeto(pendingOp.tagId, target, protectedTagIds);
|
|
7310
|
+
if (veto) {
|
|
7311
|
+
reject(veto);
|
|
7173
7312
|
continue;
|
|
7174
7313
|
}
|
|
7175
|
-
|
|
7176
|
-
|
|
7177
|
-
|
|
7178
|
-
|
|
7179
|
-
|
|
7180
|
-
|
|
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
|
+
}
|
|
7181
7396
|
});
|
|
7182
|
-
} else {
|
|
7183
|
-
reject(
|
|
7397
|
+
} else if (!synthetic) {
|
|
7398
|
+
reject("target_absent");
|
|
7399
|
+
persistDrop();
|
|
7400
|
+
mutations.push(() => record(false));
|
|
7184
7401
|
}
|
|
7185
|
-
shouldPersistDrop = true;
|
|
7186
|
-
}
|
|
7187
|
-
} else if (target) {
|
|
7188
|
-
const replacement = buildReplacementContent(pendingOp.tagId);
|
|
7189
|
-
const priorContent = target.getContent?.();
|
|
7190
|
-
persistDrop();
|
|
7191
|
-
const changed = target.setContent(replacement);
|
|
7192
|
-
if (changed) {
|
|
7193
|
-
didMutateMessage = true;
|
|
7194
|
-
operationMutated = true;
|
|
7195
|
-
const originalCharacters = typeof priorContent === "string" ? priorContent.length : tagById.get(pendingOp.tagId)?.byteSize ?? replacement.length;
|
|
7196
|
-
onTagReduced?.({
|
|
7197
|
-
tagNumber: pendingOp.tagId,
|
|
7198
|
-
mode: "partial",
|
|
7199
|
-
removedCharacters: Math.max(0, originalCharacters - replacement.length)
|
|
7200
|
-
});
|
|
7201
|
-
} else {
|
|
7202
|
-
reject("content_unchanged");
|
|
7203
7402
|
}
|
|
7204
|
-
|
|
7205
|
-
|
|
7206
|
-
|
|
7207
|
-
|
|
7208
|
-
|
|
7209
|
-
|
|
7210
|
-
|
|
7211
|
-
|
|
7212
|
-
|
|
7213
|
-
}
|
|
7214
|
-
if (operationMutated)
|
|
7215
|
-
diagnostics.mutated += 1;
|
|
7216
|
-
else
|
|
7217
|
-
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;
|
|
7218
7412
|
}
|
|
7413
|
+
} finally {
|
|
7414
|
+
if (startedAt)
|
|
7415
|
+
logSlowWriteTransaction("apply_pending_operations", startedAt);
|
|
7219
7416
|
}
|
|
7220
|
-
|
|
7221
|
-
|
|
7222
|
-
|
|
7223
|
-
return false;
|
|
7224
|
-
}
|
|
7225
|
-
throw error;
|
|
7226
|
-
}
|
|
7417
|
+
for (const mutate of mutations.splice(0))
|
|
7418
|
+
mutate();
|
|
7419
|
+
} while (hasMore);
|
|
7227
7420
|
if (diagnostics) {
|
|
7228
7421
|
onBatchComplete?.(diagnostics);
|
|
7229
7422
|
if (diagnostics.total > 0 && diagnostics.mutated === 0) {
|
|
@@ -8475,10 +8668,41 @@ function createExistingTagResolver(sessionId, tagger, db) {
|
|
|
8475
8668
|
}
|
|
8476
8669
|
|
|
8477
8670
|
// src/hooks/magic-context/transform-stage-logger.ts
|
|
8478
|
-
|
|
8479
|
-
|
|
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);
|
|
8480
8693
|
const suffix = extra ? ` ${extra}` : "";
|
|
8481
|
-
|
|
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);
|
|
8482
8706
|
}
|
|
8483
8707
|
|
|
8484
8708
|
// src/hooks/magic-context/tag-messages.ts
|
|
@@ -8844,13 +9068,18 @@ function tagMessages(sessionId, messages, tagger, db, options = {}) {
|
|
|
8844
9068
|
}));
|
|
8845
9069
|
accAssignTag += performance.now() - _tAssignText;
|
|
8846
9070
|
const persistedSource = sourceContents.get(tagId);
|
|
8847
|
-
if (persistedSource !== undefined) {
|
|
9071
|
+
if (persistedSource !== undefined && !options.refreshSourceContents) {
|
|
8848
9072
|
textPart.text = options.normalizeRestoredAssistantText && message.info.role === "assistant" ? options.normalizeRestoredAssistantText(persistedSource) : persistedSource;
|
|
8849
9073
|
} else {
|
|
8850
9074
|
const sourceContent = stripTagPrefix(textPart.text);
|
|
8851
|
-
if (sourceContent.trim().length > 0) {
|
|
9075
|
+
if (sourceContent.trim().length > 0 || options.refreshSourceContents) {
|
|
8852
9076
|
const _tSaveText = performance.now();
|
|
8853
|
-
|
|
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);
|
|
8854
9083
|
accSaveSource += performance.now() - _tSaveText;
|
|
8855
9084
|
}
|
|
8856
9085
|
}
|
|
@@ -8943,7 +9172,10 @@ function tagMessages(sessionId, messages, tagger, db, options = {}) {
|
|
|
8943
9172
|
const sourceContent = buildFileSourceContent(message.parts);
|
|
8944
9173
|
if (sourceContent) {
|
|
8945
9174
|
const _tSaveFile = performance.now();
|
|
8946
|
-
|
|
9175
|
+
if (options.refreshSourceContents)
|
|
9176
|
+
replaceSourceContent(db, sessionId, tagId, sourceContent);
|
|
9177
|
+
else
|
|
9178
|
+
saveSourceContent(db, sessionId, tagId, sourceContent);
|
|
8947
9179
|
accSaveSource += performance.now() - _tSaveFile;
|
|
8948
9180
|
}
|
|
8949
9181
|
}
|
|
@@ -11190,6 +11422,26 @@ function systemPromptDates(prompt, sticky) {
|
|
|
11190
11422
|
return { live: values.length ? JSON.stringify(values) : undefined, stable };
|
|
11191
11423
|
}
|
|
11192
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
|
+
|
|
11193
11445
|
// src/hooks/magic-context/system-date-refresh.ts
|
|
11194
11446
|
var channels = new WeakMap;
|
|
11195
11447
|
var outputUpdates = new WeakMap;
|
|
@@ -11347,6 +11599,7 @@ function createSystemPromptHashHandler(deps) {
|
|
|
11347
11599
|
});
|
|
11348
11600
|
const guidanceEpochs = createPromptSurfaceGuidanceEpochCache(promptSurfaceRuntime);
|
|
11349
11601
|
const stickyDateBySession = new Map;
|
|
11602
|
+
const diagnosticPrompts = new Map;
|
|
11350
11603
|
const processSystemPrompt = async (input, output) => {
|
|
11351
11604
|
const sessionId = input.sessionID;
|
|
11352
11605
|
if (!sessionId)
|
|
@@ -11479,8 +11732,11 @@ function createSystemPromptHashHandler(deps) {
|
|
|
11479
11732
|
return;
|
|
11480
11733
|
}
|
|
11481
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);
|
|
11482
11738
|
if (previousHash !== "" && previousHash !== "0" && previousHash !== currentHash) {
|
|
11483
|
-
sessionLog2(sessionId, `system prompt hash changed: ${previousHash} → ${currentHash} (len=${systemContent.length}), ${idleCacheExpired ? "adopting on idle-expired request" : requestMessagesFinal ? "adopting on the request whose messages are already final" : "triggering flush"}`);
|
|
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)}`);
|
|
11484
11740
|
noteSystemPromptHashChange(sessionId);
|
|
11485
11741
|
if (!adoptSystemChange) {
|
|
11486
11742
|
deps.historyRefreshSessions.add(sessionId);
|
|
@@ -11524,6 +11780,7 @@ function createSystemPromptHashHandler(deps) {
|
|
|
11524
11780
|
return {
|
|
11525
11781
|
handler,
|
|
11526
11782
|
clearSession: (sessionId) => {
|
|
11783
|
+
diagnosticPrompts.delete(sessionId);
|
|
11527
11784
|
clearSystemDateRefresh(deps.historyRefreshSessions, sessionId);
|
|
11528
11785
|
guidanceEpochs.clear(sessionId);
|
|
11529
11786
|
clearSystemPromptHashSession(sessionId, {
|
|
@@ -11753,7 +12010,7 @@ function createPassOutcome() {
|
|
|
11753
12010
|
}
|
|
11754
12011
|
|
|
11755
12012
|
// src/hooks/magic-context/rust-mode-transform.ts
|
|
11756
|
-
import { createHash as
|
|
12013
|
+
import { createHash as createHash5, randomUUID as randomUUID2 } from "node:crypto";
|
|
11757
12014
|
|
|
11758
12015
|
// src/features/magic-context/memory/single-store-embedding-drain.ts
|
|
11759
12016
|
function isWatermarkRow(row) {
|
|
@@ -11817,7 +12074,7 @@ function advanceEmbeddedWatermark(db, projectPath, upTo) {
|
|
|
11817
12074
|
}
|
|
11818
12075
|
|
|
11819
12076
|
// src/features/magic-context/mural/source-revision.ts
|
|
11820
|
-
import { createHash } from "node:crypto";
|
|
12077
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
11821
12078
|
var statements = new WeakMap;
|
|
11822
12079
|
function muralSourceRevision(db, projectPath) {
|
|
11823
12080
|
let statement = statements.get(db);
|
|
@@ -11834,7 +12091,7 @@ function muralSourceRevision(db, projectPath) {
|
|
|
11834
12091
|
statements.set(db, statement);
|
|
11835
12092
|
}
|
|
11836
12093
|
const row = statement.get(projectPath, Date.now());
|
|
11837
|
-
return
|
|
12094
|
+
return createHash2("sha256").update(row.revision).digest("hex");
|
|
11838
12095
|
}
|
|
11839
12096
|
|
|
11840
12097
|
// src/features/magic-context/install-instance-id.ts
|
|
@@ -12261,6 +12518,7 @@ class HistorianHostRunner {
|
|
|
12261
12518
|
throw new Error("hidden completion carrier returned no session id");
|
|
12262
12519
|
const run = await promptSyncWithValidatedOutputRetry(undefined, {
|
|
12263
12520
|
path: { id: handle.id },
|
|
12521
|
+
cacheTail: "skip",
|
|
12264
12522
|
query: { directory: sessionDirectory },
|
|
12265
12523
|
body: {
|
|
12266
12524
|
agent: "historian",
|
|
@@ -14209,7 +14467,7 @@ function noteExternalLkgReplay(participant, sessionId, inputMessages, servedMess
|
|
|
14209
14467
|
}
|
|
14210
14468
|
|
|
14211
14469
|
// src/hooks/magic-context/rust-served-raw.ts
|
|
14212
|
-
import { createHash as
|
|
14470
|
+
import { createHash as createHash4 } from "node:crypto";
|
|
14213
14471
|
class RustServedRawConflict extends EmergencyFailClosedError {
|
|
14214
14472
|
reason;
|
|
14215
14473
|
messageIds;
|
|
@@ -14223,7 +14481,7 @@ class RustServedRawConflict extends EmergencyFailClosedError {
|
|
|
14223
14481
|
}
|
|
14224
14482
|
function partDigest(part) {
|
|
14225
14483
|
const serialized = JSON.stringify(part);
|
|
14226
|
-
return
|
|
14484
|
+
return createHash4("sha256").update(stableStringify(serialized === undefined ? undefined : JSON.parse(serialized))).digest("hex");
|
|
14227
14485
|
}
|
|
14228
14486
|
function records(doc) {
|
|
14229
14487
|
if (doc.rustServedRaw === undefined)
|
|
@@ -14711,10 +14969,10 @@ function messageCacheSignature(message) {
|
|
|
14711
14969
|
const parts = Array.isArray(message.parts) ? message.parts : [];
|
|
14712
14970
|
const serializedParts = JSON.stringify(parts) ?? "null";
|
|
14713
14971
|
const serializedMessage = JSON.stringify(message) ?? "null";
|
|
14714
|
-
return `${messageIdOf(message) ?? ""}:${parts.length}:${Buffer.byteLength(serializedParts)}:${
|
|
14972
|
+
return `${messageIdOf(message) ?? ""}:${parts.length}:${Buffer.byteLength(serializedParts)}:${createHash5("sha256").update(serializedMessage).digest("hex")}`;
|
|
14715
14973
|
}
|
|
14716
14974
|
function advanceWireFingerprint(previous, encoded) {
|
|
14717
|
-
return
|
|
14975
|
+
return createHash5("sha256").update(previous).update("\\0").update(JSON.stringify(encoded) ?? "null").digest("hex");
|
|
14718
14976
|
}
|
|
14719
14977
|
function buildWireFingerprint(encoded) {
|
|
14720
14978
|
let fingerprint = "rust-wire-v1";
|
|
@@ -16495,7 +16753,7 @@ function createRustModeTransform(deps, options) {
|
|
|
16495
16753
|
const id = messageIdOf(message) ?? `index:${todoStart + offset}`;
|
|
16496
16754
|
const parts = message.parts?.filter((part) => isRecord4(part) && part.type === "tool" && part.tool === "todowrite");
|
|
16497
16755
|
if (parts?.length) {
|
|
16498
|
-
todoCalls.set(id,
|
|
16756
|
+
todoCalls.set(id, createHash5("sha256").update(JSON.stringify(parts)).digest("hex"));
|
|
16499
16757
|
} else {
|
|
16500
16758
|
todoCalls.delete(id);
|
|
16501
16759
|
}
|
|
@@ -18807,7 +19065,8 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
18807
19065
|
const tagged = tagMessages(sessionId, tail, deps.tagger, db, {
|
|
18808
19066
|
skipPrefixInjection: !ctxReduceCallable,
|
|
18809
19067
|
servedMessages: messages,
|
|
18810
|
-
normalizeRestoredAssistantText: deps.normalizeRestoredAssistantText
|
|
19068
|
+
normalizeRestoredAssistantText: deps.normalizeRestoredAssistantText,
|
|
19069
|
+
refreshSourceContents: deps.refreshSourceContents?.(sessionId)
|
|
18811
19070
|
});
|
|
18812
19071
|
for (const [number, target] of tagged.targets)
|
|
18813
19072
|
targets.set(number, target);
|
|
@@ -18832,7 +19091,8 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
18832
19091
|
skipPrefixInjection,
|
|
18833
19092
|
scopedToolSweep,
|
|
18834
19093
|
servedMessages: messages,
|
|
18835
|
-
normalizeRestoredAssistantText: deps.normalizeRestoredAssistantText
|
|
19094
|
+
normalizeRestoredAssistantText: deps.normalizeRestoredAssistantText,
|
|
19095
|
+
refreshSourceContents: deps.refreshSourceContents?.(sessionId)
|
|
18836
19096
|
});
|
|
18837
19097
|
targets = result.targets;
|
|
18838
19098
|
if (thinkingRecovery.restore)
|
|
@@ -19516,7 +19776,8 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
19516
19776
|
systemPromptHash: sessionMeta.systemPromptHash
|
|
19517
19777
|
});
|
|
19518
19778
|
};
|
|
19519
|
-
|
|
19779
|
+
const timedTransform = (input, output) => withTransformTimingSummary(() => transform(input, output));
|
|
19780
|
+
return Object.assign(timedTransform, {
|
|
19520
19781
|
clearSessionLogState,
|
|
19521
19782
|
invalidateRustWireState(sessionId) {
|
|
19522
19783
|
rustModeTransform?.invalidateWireState(sessionId);
|
|
@@ -21183,7 +21444,7 @@ function computeOpenCodeWorkMetricsIncremental(openCodeDb, sessionId, carry) {
|
|
|
21183
21444
|
import { readFileSync, statSync } from "node:fs";
|
|
21184
21445
|
|
|
21185
21446
|
// src/plugin/embedding-bootstrap-helpers.ts
|
|
21186
|
-
import { createHash as
|
|
21447
|
+
import { createHash as createHash6 } from "node:crypto";
|
|
21187
21448
|
var EMBEDDING_AFFECTING_KEYS = new Set([
|
|
21188
21449
|
"embedding.api_key",
|
|
21189
21450
|
"embedding.endpoint",
|
|
@@ -21231,7 +21492,7 @@ var EMBEDDING_WARNING_TERMS = [
|
|
|
21231
21492
|
];
|
|
21232
21493
|
var loggedFailureSignatures = new Map;
|
|
21233
21494
|
function sha256Prefix(value, length = 16) {
|
|
21234
|
-
return
|
|
21495
|
+
return createHash6("sha256").update(value).digest("hex").slice(0, length);
|
|
21235
21496
|
}
|
|
21236
21497
|
function warningLooksEmbeddingRelated(message) {
|
|
21237
21498
|
const lower = message.toLowerCase();
|
|
@@ -22738,8 +22999,8 @@ function registerRpcHandlers(rpcServer, args) {
|
|
|
22738
22999
|
const db = readDatabase();
|
|
22739
23000
|
if (!db)
|
|
22740
23001
|
return { ok: false, error: "db unavailable" };
|
|
22741
|
-
const { runManagedRecomp } = await importPluginModule(() => import("./recomp-orchestrator-
|
|
22742
|
-
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"));
|
|
22743
23004
|
log2(`[rpc] recomp requested for session ${sessionId}`);
|
|
22744
23005
|
if (!args.client && !args.hiddenCompletionExecutor) {
|
|
22745
23006
|
return {
|
|
@@ -22823,7 +23084,7 @@ function registerRpcHandlers(rpcServer, args) {
|
|
|
22823
23084
|
const db = readDatabase();
|
|
22824
23085
|
if (!db)
|
|
22825
23086
|
return { ok: false, error: "db unavailable" };
|
|
22826
|
-
const { runManagedWrapup } = await importPluginModule(() => import("./wrapup-orchestrator-
|
|
23087
|
+
const { runManagedWrapup } = await importPluginModule(() => import("./wrapup-orchestrator-xs8redz9.js"));
|
|
22827
23088
|
const model = liveSessionState.liveModelBySession.get(sessionId);
|
|
22828
23089
|
const contextLimit = model ? resolveContextLimit(model.providerID, model.modelID, { db, sessionID: sessionId }) : 128000;
|
|
22829
23090
|
const ctx = {
|
|
@@ -23195,7 +23456,58 @@ function readOmoDisabledHooks(directory) {
|
|
|
23195
23456
|
|
|
23196
23457
|
// src/shared/rpc-server.ts
|
|
23197
23458
|
import { randomBytes, timingSafeEqual } from "node:crypto";
|
|
23198
|
-
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
|
|
23199
23511
|
var MAX_BODY_BYTES = 1048576;
|
|
23200
23512
|
var WS_AUTH_TIMEOUT_MS = 5000;
|
|
23201
23513
|
var WS_CLOSE_UNAUTHORIZED = 4401;
|
|
@@ -23218,17 +23530,20 @@ function websocketToken(req) {
|
|
|
23218
23530
|
}
|
|
23219
23531
|
|
|
23220
23532
|
class MagicContextRpcServer {
|
|
23533
|
+
storageDir;
|
|
23221
23534
|
server = null;
|
|
23222
23535
|
port = 0;
|
|
23223
23536
|
handlers = new Map;
|
|
23224
23537
|
portFilePath;
|
|
23225
23538
|
portDir;
|
|
23226
23539
|
startedAt = Date.now();
|
|
23540
|
+
stopped = false;
|
|
23227
23541
|
instanceId = randomBytes(8).toString("hex");
|
|
23228
23542
|
unregisterOwnInstance = null;
|
|
23229
23543
|
sockets = new Set;
|
|
23230
23544
|
token = randomBytes(32).toString("hex");
|
|
23231
23545
|
constructor(storageDir, directory) {
|
|
23546
|
+
this.storageDir = storageDir;
|
|
23232
23547
|
this.portFilePath = rpcPortFilePath(storageDir, directory, process.pid, this.instanceId);
|
|
23233
23548
|
this.portDir = rpcPortDir(storageDir, directory);
|
|
23234
23549
|
}
|
|
@@ -23246,6 +23561,10 @@ class MagicContextRpcServer {
|
|
|
23246
23561
|
log2("rpc server skipped: Bun runtime not available (no TUI consumer)");
|
|
23247
23562
|
return 0;
|
|
23248
23563
|
}
|
|
23564
|
+
this.stopped = false;
|
|
23565
|
+
await reapDeadRpcDiscovery(this.storageDir);
|
|
23566
|
+
if (this.stopped)
|
|
23567
|
+
return 0;
|
|
23249
23568
|
this.startedAt = Date.now();
|
|
23250
23569
|
const self = this;
|
|
23251
23570
|
const server = inRootAsyncContext2(() => Bun.serve({
|
|
@@ -23277,7 +23596,7 @@ class MagicContextRpcServer {
|
|
|
23277
23596
|
try {
|
|
23278
23597
|
this.warnIfOtherLiveInstance();
|
|
23279
23598
|
this.unregisterOwnInstance ??= registerOwnRpcServerInstance(this.instanceId);
|
|
23280
|
-
writeStorageFileAtomicSync(this.portFilePath, JSON.stringify({
|
|
23599
|
+
const publish = () => writeStorageFileAtomicSync(this.portFilePath, JSON.stringify({
|
|
23281
23600
|
port: this.port,
|
|
23282
23601
|
pid: process.pid,
|
|
23283
23602
|
started_at: this.startedAt,
|
|
@@ -23285,6 +23604,13 @@ class MagicContextRpcServer {
|
|
|
23285
23604
|
token: this.token,
|
|
23286
23605
|
instance_id: this.instanceId
|
|
23287
23606
|
}));
|
|
23607
|
+
try {
|
|
23608
|
+
publish();
|
|
23609
|
+
} catch (error) {
|
|
23610
|
+
if (error.code !== "ENOENT")
|
|
23611
|
+
throw error;
|
|
23612
|
+
publish();
|
|
23613
|
+
}
|
|
23288
23614
|
log2(`[rpc] server listening on 127.0.0.1:${this.port}`);
|
|
23289
23615
|
} catch (err) {
|
|
23290
23616
|
log2(`[rpc] failed to write port file: ${err}`);
|
|
@@ -23292,6 +23618,7 @@ class MagicContextRpcServer {
|
|
|
23292
23618
|
return this.port;
|
|
23293
23619
|
}
|
|
23294
23620
|
stop() {
|
|
23621
|
+
this.stopped = true;
|
|
23295
23622
|
for (const ws of this.sockets) {
|
|
23296
23623
|
try {
|
|
23297
23624
|
if (ws.data.authTimer)
|
|
@@ -23308,6 +23635,9 @@ class MagicContextRpcServer {
|
|
|
23308
23635
|
try {
|
|
23309
23636
|
unlinkSync(this.portFilePath);
|
|
23310
23637
|
} catch {}
|
|
23638
|
+
try {
|
|
23639
|
+
rmdirSync(this.portDir);
|
|
23640
|
+
} catch {}
|
|
23311
23641
|
this.unregisterOwnInstance?.();
|
|
23312
23642
|
this.unregisterOwnInstance = null;
|
|
23313
23643
|
}
|
|
@@ -23812,8 +24142,8 @@ function hostMediaFromEncoded(value) {
|
|
|
23812
24142
|
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
23813
24143
|
|
|
23814
24144
|
// src/v2/fold/owner.ts
|
|
23815
|
-
import { createHash as
|
|
23816
|
-
var foldDigest = (value) =>
|
|
24145
|
+
import { createHash as createHash7 } from "node:crypto";
|
|
24146
|
+
var foldDigest = (value) => createHash7("sha256").update(value).digest("hex");
|
|
23817
24147
|
|
|
23818
24148
|
class FoldOwner {
|
|
23819
24149
|
storage;
|
|
@@ -24732,24 +25062,31 @@ ${data.output?.output ?? ""}`
|
|
|
24732
25062
|
const sameModel = sameProvider && previousModel?.id === model.id;
|
|
24733
25063
|
const reuse = sameModel && data.error === undefined;
|
|
24734
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);
|
|
24735
25066
|
const content = [];
|
|
24736
25067
|
const results = [];
|
|
24737
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
|
+
};
|
|
24738
25075
|
if (part.type === "text") {
|
|
24739
25076
|
if (part.text !== "")
|
|
24740
25077
|
content.push({
|
|
24741
25078
|
type: "text",
|
|
24742
25079
|
text: part.text,
|
|
24743
|
-
providerMetadata: reuse ? metadata(
|
|
25080
|
+
providerMetadata: reuse ? metadata(native) : undefined
|
|
24744
25081
|
});
|
|
24745
25082
|
continue;
|
|
24746
25083
|
}
|
|
24747
25084
|
if (part.type === "reasoning") {
|
|
24748
|
-
if (part.text !== "" || reuse &&
|
|
25085
|
+
if (part.text !== "" || reuse && !reasoningInterrupted && native !== undefined)
|
|
24749
25086
|
content.push({
|
|
24750
|
-
type:
|
|
25087
|
+
type: data.error === undefined && !reasoningInterrupted ? "reasoning" : "text",
|
|
24751
25088
|
text: part.text,
|
|
24752
|
-
providerMetadata: reuse ? metadata(
|
|
25089
|
+
providerMetadata: reuse && !reasoningInterrupted ? metadata(native) : undefined
|
|
24753
25090
|
});
|
|
24754
25091
|
continue;
|
|
24755
25092
|
}
|
|
@@ -24768,7 +25105,7 @@ ${data.output?.output ?? ""}`
|
|
|
24768
25105
|
name: part.name,
|
|
24769
25106
|
input,
|
|
24770
25107
|
providerExecuted: part.executed,
|
|
24771
|
-
providerMetadata: toolReuse ? metadata(
|
|
25108
|
+
providerMetadata: toolReuse ? metadata(native) : undefined
|
|
24772
25109
|
});
|
|
24773
25110
|
if (!completed)
|
|
24774
25111
|
continue;
|
|
@@ -24779,7 +25116,7 @@ ${data.output?.output ?? ""}`
|
|
|
24779
25116
|
id: part.id,
|
|
24780
25117
|
name: part.name,
|
|
24781
25118
|
providerExecuted: part.executed,
|
|
24782
|
-
providerMetadata:
|
|
25119
|
+
providerMetadata: (part.executed === true ? sameProvider : reuse) ? metadata(native) : undefined,
|
|
24783
25120
|
result: state.status === "error" ? { error: state.error, content: toolContent } : single?.type === "text" ? { type: "text", value: single.text } : { type: "content", value: toolContent },
|
|
24784
25121
|
...state.status === "error" ? { resultType: "error" } : {}
|
|
24785
25122
|
};
|
|
@@ -24807,13 +25144,50 @@ function copyNativeInput(messages) {
|
|
|
24807
25144
|
return copies;
|
|
24808
25145
|
}
|
|
24809
25146
|
function isLocalCheckpoint(row) {
|
|
24810
|
-
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
|
+
}
|
|
24811
25161
|
}
|
|
24812
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
|
+
}
|
|
24813
25186
|
|
|
24814
25187
|
class NativeFoldReplay {
|
|
24815
25188
|
storage;
|
|
24816
25189
|
openReader;
|
|
25190
|
+
admissions;
|
|
24817
25191
|
changed = new Set;
|
|
24818
25192
|
dirty = new Set;
|
|
24819
25193
|
unavailable = new Set;
|
|
@@ -24821,9 +25195,11 @@ class NativeFoldReplay {
|
|
|
24821
25195
|
metadataThrough = new Map;
|
|
24822
25196
|
loaded = new Map;
|
|
24823
25197
|
sources = new Map;
|
|
24824
|
-
|
|
25198
|
+
staleHeads = new Set;
|
|
25199
|
+
constructor(storage, openReader, admissions) {
|
|
24825
25200
|
this.storage = storage;
|
|
24826
25201
|
this.openReader = openReader;
|
|
25202
|
+
this.admissions = admissions;
|
|
24827
25203
|
storage.onEvict((sessionID) => this.clear(sessionID));
|
|
24828
25204
|
}
|
|
24829
25205
|
account(sessionID) {
|
|
@@ -24862,6 +25238,51 @@ class NativeFoldReplay {
|
|
|
24862
25238
|
async baseline(sessionID) {
|
|
24863
25239
|
return this.tail(sessionID)?.baseline;
|
|
24864
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
|
+
}
|
|
24865
25286
|
rendered(row, model) {
|
|
24866
25287
|
return restoreRow(row, model, hostUsesMediaAssets() ? {
|
|
24867
25288
|
asset: hostMediaAsset,
|
|
@@ -24939,6 +25360,7 @@ class NativeFoldReplay {
|
|
|
24939
25360
|
this.loaded.set(draft.sessionID, through);
|
|
24940
25361
|
this.unavailable.delete(draft.sessionID);
|
|
24941
25362
|
this.changed.delete(draft.sessionID);
|
|
25363
|
+
this.staleHeads.delete(draft.sessionID);
|
|
24942
25364
|
} finally {
|
|
24943
25365
|
reader.close();
|
|
24944
25366
|
}
|
|
@@ -24965,7 +25387,8 @@ class NativeFoldReplay {
|
|
|
24965
25387
|
async supplyHeld(args) {
|
|
24966
25388
|
const { draft, reader, summary } = args;
|
|
24967
25389
|
const tail = this.tail(draft.sessionID);
|
|
24968
|
-
const
|
|
25390
|
+
const running = reader.latestRunningCompaction(draft.sessionID);
|
|
25391
|
+
const id = running?.id;
|
|
24969
25392
|
if (!id || !tail || tail.model !== `${draft.model.providerID}/${draft.model.id}`)
|
|
24970
25393
|
return false;
|
|
24971
25394
|
const through = reader.latestSequence(draft.sessionID);
|
|
@@ -24989,6 +25412,21 @@ class NativeFoldReplay {
|
|
|
24989
25412
|
summary
|
|
24990
25413
|
};
|
|
24991
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
|
+
}
|
|
24992
25430
|
return true;
|
|
24993
25431
|
}
|
|
24994
25432
|
async restore(sessionID, cut, model, options = {}) {
|
|
@@ -25073,6 +25511,9 @@ class NativeFoldReplay {
|
|
|
25073
25511
|
sourceChanged(sessionID) {
|
|
25074
25512
|
return this.changed.has(sessionID);
|
|
25075
25513
|
}
|
|
25514
|
+
needsHeadRebuild(sessionID) {
|
|
25515
|
+
return this.staleHeads.has(sessionID);
|
|
25516
|
+
}
|
|
25076
25517
|
clear(sessionID) {
|
|
25077
25518
|
this.sources.delete(sessionID);
|
|
25078
25519
|
this.metadata.delete(sessionID);
|
|
@@ -25081,8 +25522,11 @@ class NativeFoldReplay {
|
|
|
25081
25522
|
this.unavailable.delete(sessionID);
|
|
25082
25523
|
this.dirty.delete(sessionID);
|
|
25083
25524
|
this.changed.delete(sessionID);
|
|
25525
|
+
this.staleHeads.delete(sessionID);
|
|
25084
25526
|
}
|
|
25085
25527
|
async forget(sessionID) {
|
|
25528
|
+
if (this.admissions)
|
|
25529
|
+
await forgetNativeFoldProvenance(this.admissions, sessionID);
|
|
25086
25530
|
await this.storage.forget(sessionID);
|
|
25087
25531
|
}
|
|
25088
25532
|
}
|
|
@@ -25097,11 +25541,7 @@ class HostFoldPolicy {
|
|
|
25097
25541
|
this.deps = deps;
|
|
25098
25542
|
}
|
|
25099
25543
|
owned(sessionID, cut, id) {
|
|
25100
|
-
|
|
25101
|
-
if (!isLocalCheckpoint(cut) || cut.id !== id || !row?.payload || row.digest !== foldDigest(row.payload))
|
|
25102
|
-
return false;
|
|
25103
|
-
const snapshot = JSON.parse(row.payload);
|
|
25104
|
-
return snapshot.summary === cut.data.summary && snapshot.source === this.deps.storage.sourceID && snapshot.sessionID === sessionID && snapshot.admissionID === id;
|
|
25544
|
+
return cut.id === id && isAdmittedLocalCheckpoint(this.deps.storage, sessionID, cut);
|
|
25105
25545
|
}
|
|
25106
25546
|
async idle(sessionID) {
|
|
25107
25547
|
const { storage, session, threshold } = this.deps;
|
|
@@ -25524,7 +25964,7 @@ async function cleanupLegacyHiddenChildren(db, remove, note, options = {}) {
|
|
|
25524
25964
|
// src/shared/models-dev-temperature.ts
|
|
25525
25965
|
import { readFileSync as readFileSync5, statSync as statSync2 } from "node:fs";
|
|
25526
25966
|
import { homedir as homedir3 } from "node:os";
|
|
25527
|
-
import { join as
|
|
25967
|
+
import { join as join7 } from "node:path";
|
|
25528
25968
|
var CATALOG_PROVIDER_ALIASES = {
|
|
25529
25969
|
"google-antigravity": "google",
|
|
25530
25970
|
"opencode-zen": "opencode"
|
|
@@ -25534,7 +25974,7 @@ var cached;
|
|
|
25534
25974
|
function modelsDevCatalogPath(env = process.env) {
|
|
25535
25975
|
if (env.OPENCODE_MODELS_PATH)
|
|
25536
25976
|
return env.OPENCODE_MODELS_PATH;
|
|
25537
|
-
return
|
|
25977
|
+
return join7(env.XDG_CACHE_HOME || join7(homedir3(), ".cache"), "opencode", "models.json");
|
|
25538
25978
|
}
|
|
25539
25979
|
function buildIndex(raw) {
|
|
25540
25980
|
const index = new Map;
|
|
@@ -26532,11 +26972,11 @@ class DeletedSessionTombstones {
|
|
|
26532
26972
|
}
|
|
26533
26973
|
|
|
26534
26974
|
// src/features/magic-context/dreamer/task-executor.ts
|
|
26535
|
-
import { createHash as
|
|
26975
|
+
import { createHash as createHash14 } from "node:crypto";
|
|
26536
26976
|
import { existsSync as existsSync7, readFileSync as readFileSync8 } from "node:fs";
|
|
26537
26977
|
|
|
26538
26978
|
// src/features/magic-context/mural/compress-cues.ts
|
|
26539
|
-
import { createHash as
|
|
26979
|
+
import { createHash as createHash8 } from "node:crypto";
|
|
26540
26980
|
|
|
26541
26981
|
// src/features/magic-context/dreamer/storage-dream-state.ts
|
|
26542
26982
|
var getDreamStateStatements = new WeakMap;
|
|
@@ -27279,7 +27719,7 @@ async function applyCuesThroughModule(args, chunk, manifestText, signal) {
|
|
|
27279
27719
|
log2(`[dreamer] compress-cues: skipped cue for memory ${entry.id} (${failure.reason}; rejection ${rejectionCount}/${CUE_REJECTION_LATCH_THRESHOLD})`);
|
|
27280
27720
|
}
|
|
27281
27721
|
}
|
|
27282
|
-
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)}`;
|
|
27283
27723
|
let response;
|
|
27284
27724
|
try {
|
|
27285
27725
|
response = await route.moduleClient.call({
|
|
@@ -27882,7 +28322,7 @@ function applyReviewVerdict(args, leaseKey, parsed, result) {
|
|
|
27882
28322
|
}
|
|
27883
28323
|
|
|
27884
28324
|
// src/features/magic-context/dreamer/classify.ts
|
|
27885
|
-
import { createHash as
|
|
28325
|
+
import { createHash as createHash9 } from "node:crypto";
|
|
27886
28326
|
|
|
27887
28327
|
// src/plugin/rust-tool-backends.ts
|
|
27888
28328
|
function isRustAuthorityDrainingError(error) {
|
|
@@ -28319,7 +28759,7 @@ async function runClassifyThroughModule(args, chunk, anchors, signal, runOnHost)
|
|
|
28319
28759
|
if (entry.qualifier)
|
|
28320
28760
|
modelVariants[entry.model] = entry.qualifier;
|
|
28321
28761
|
}
|
|
28322
|
-
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)}`;
|
|
28323
28763
|
const runTask = (hostCompletion) => args.moduleClient?.call({
|
|
28324
28764
|
sessionId: args.moduleSessionId,
|
|
28325
28765
|
projectRoot: args.moduleProjectRoot,
|
|
@@ -28594,7 +29034,7 @@ function takeCurateSafetyRefusalCount(sessionId) {
|
|
|
28594
29034
|
|
|
28595
29035
|
// src/features/magic-context/dreamer/docs-proposals.ts
|
|
28596
29036
|
import { execFileSync } from "node:child_process";
|
|
28597
|
-
import { createHash as
|
|
29037
|
+
import { createHash as createHash10 } from "node:crypto";
|
|
28598
29038
|
import {
|
|
28599
29039
|
existsSync as existsSync4,
|
|
28600
29040
|
mkdirSync,
|
|
@@ -28607,19 +29047,19 @@ import {
|
|
|
28607
29047
|
writeFileSync
|
|
28608
29048
|
} from "node:fs";
|
|
28609
29049
|
import { tmpdir } from "node:os";
|
|
28610
|
-
import { join as
|
|
29050
|
+
import { join as join8 } from "node:path";
|
|
28611
29051
|
var FILES = ["ARCHITECTURE.md", "STRUCTURE.md"];
|
|
28612
|
-
var hash = (text) =>
|
|
28613
|
-
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");
|
|
28614
29054
|
function docsBaseHashes(projectDir) {
|
|
28615
29055
|
return Object.fromEntries(FILES.map((name) => [
|
|
28616
29056
|
name,
|
|
28617
|
-
hash(existsSync4(
|
|
29057
|
+
hash(existsSync4(join8(projectDir, name)) ? readFileSync6(join8(projectDir, name), "utf8") : "")
|
|
28618
29058
|
]));
|
|
28619
29059
|
}
|
|
28620
29060
|
function listPendingDocsProposals(projectDir) {
|
|
28621
29061
|
const dir = proposalDir(projectDir);
|
|
28622
|
-
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)) : [];
|
|
28623
29063
|
}
|
|
28624
29064
|
function hasCurrentDocsProposal(projectDir) {
|
|
28625
29065
|
const hashes = docsBaseHashes(projectDir);
|
|
@@ -28677,7 +29117,7 @@ function docsChangeSet(projectDir, storedAnchor) {
|
|
|
28677
29117
|
const files = [
|
|
28678
29118
|
...new Set(changed.flat().filter((file) => file !== "ARCHITECTURE.md" && file !== "STRUCTURE.md" && !/(?:^|[./-])(test|spec)(?:[./-]|$)/.test(file) && !file.endsWith(".lock")))
|
|
28679
29119
|
];
|
|
28680
|
-
const docs = FILES.map((file) => existsSync4(
|
|
29120
|
+
const docs = FILES.map((file) => existsSync4(join8(projectDir, file)) ? readFileSync6(join8(projectDir, file), "utf8") : "").join(`
|
|
28681
29121
|
`);
|
|
28682
29122
|
const relevant = files.some((file) => {
|
|
28683
29123
|
const directory = file.split("/").slice(0, -1).join("/");
|
|
@@ -28805,14 +29245,14 @@ function protectedBytes(text) {
|
|
|
28805
29245
|
].map((match) => match[0]);
|
|
28806
29246
|
}
|
|
28807
29247
|
function diff(name, before, after) {
|
|
28808
|
-
const dir = mkdtempSync(
|
|
29248
|
+
const dir = mkdtempSync(join8(tmpdir(), "mc-doc-diff-"));
|
|
28809
29249
|
try {
|
|
28810
|
-
writeFileSync(
|
|
28811
|
-
writeFileSync(
|
|
29250
|
+
writeFileSync(join8(dir, "before"), before);
|
|
29251
|
+
writeFileSync(join8(dir, "after"), after);
|
|
28812
29252
|
try {
|
|
28813
|
-
return execFileSync("git", ["diff", "--no-index", "--",
|
|
29253
|
+
return execFileSync("git", ["diff", "--no-index", "--", join8(dir, "before"), join8(dir, "after")], { windowsHide: true, encoding: "utf8" });
|
|
28814
29254
|
} catch (error) {
|
|
28815
|
-
return error.stdout?.replaceAll(
|
|
29255
|
+
return error.stdout?.replaceAll(join8(dir, "before"), `a/${name}`).replaceAll(join8(dir, "after"), `b/${name}`) ?? "";
|
|
28816
29256
|
}
|
|
28817
29257
|
} finally {
|
|
28818
29258
|
rmSync2(dir, { recursive: true, force: true });
|
|
@@ -28833,7 +29273,7 @@ function validateDocsProposal(projectDir, output, budget, expected) {
|
|
|
28833
29273
|
let tokens = 0;
|
|
28834
29274
|
let diffs = "";
|
|
28835
29275
|
for (const file of FILES) {
|
|
28836
|
-
const before = existsSync4(
|
|
29276
|
+
const before = existsSync4(join8(projectDir, file)) ? readFileSync6(join8(projectDir, file), "utf8") : "";
|
|
28837
29277
|
let after = before;
|
|
28838
29278
|
const seen = new Set;
|
|
28839
29279
|
for (const change of changes.filter((item) => item.file === file)) {
|
|
@@ -28883,9 +29323,9 @@ ${change.text.trimEnd()}
|
|
|
28883
29323
|
function writeDocsProposal(projectDir, output, budget, expected, head) {
|
|
28884
29324
|
const result = validateDocsProposal(projectDir, output, budget, expected);
|
|
28885
29325
|
const dir = proposalDir(projectDir);
|
|
28886
|
-
mkdirSync(
|
|
29326
|
+
mkdirSync(join8(dir, "superseded"), { recursive: true });
|
|
28887
29327
|
const stamp = `${new Date().toISOString().replace(/[:.]/g, "-")}-${Math.random().toString(36).slice(2, 8)}`;
|
|
28888
|
-
const path =
|
|
29328
|
+
const path = join8(dir, `${stamp}.md`);
|
|
28889
29329
|
const body = `# Docs update proposal
|
|
28890
29330
|
|
|
28891
29331
|
Base commit: ${head}
|
|
@@ -28913,7 +29353,7 @@ ${result.diffs}
|
|
|
28913
29353
|
writeFileSync(path, body, { flag: "wx" });
|
|
28914
29354
|
for (const old of listPendingDocsProposals(projectDir))
|
|
28915
29355
|
if (old !== path)
|
|
28916
|
-
renameSync(old,
|
|
29356
|
+
renameSync(old, join8(dir, "superseded", old.split("/").at(-1) ?? "proposal.md"));
|
|
28917
29357
|
return path;
|
|
28918
29358
|
}
|
|
28919
29359
|
|
|
@@ -29145,7 +29585,7 @@ function throwIfAborted2(signal) {
|
|
|
29145
29585
|
}
|
|
29146
29586
|
|
|
29147
29587
|
// src/features/magic-context/smart-notes/compiler.ts
|
|
29148
|
-
import { createHash as
|
|
29588
|
+
import { createHash as createHash11 } from "node:crypto";
|
|
29149
29589
|
|
|
29150
29590
|
// src/features/magic-context/smart-notes/compiler-prompt.ts
|
|
29151
29591
|
var SMART_NOTE_COMPILER_SYSTEM_PROMPT = `You are the Magic Context smart-note compiler for the magic-context system.
|
|
@@ -29484,7 +29924,7 @@ function manifestAdvisoryWarnings(code, manifest) {
|
|
|
29484
29924
|
return warnings;
|
|
29485
29925
|
}
|
|
29486
29926
|
function hashCheck(surfaceCondition, compiledCheck, manifest, checkCron) {
|
|
29487
|
-
return
|
|
29927
|
+
return createHash11("sha256").update(surfaceCondition ?? "").update("\x00").update(compiledCheck).update("\x00").update(JSON.stringify(manifest)).update("\x00").update(checkCron).digest("hex");
|
|
29488
29928
|
}
|
|
29489
29929
|
function extractJsonObject(output) {
|
|
29490
29930
|
const fenced = output.match(/```(?:json)?\s*([\s\S]*?)```/i);
|
|
@@ -29562,7 +30002,7 @@ function deterministicJitterMs(intervalMs, noteId, hash) {
|
|
|
29562
30002
|
}
|
|
29563
30003
|
|
|
29564
30004
|
// src/features/magic-context/smart-notes/wake-plane.ts
|
|
29565
|
-
import { join as
|
|
30005
|
+
import { join as join9 } from "node:path";
|
|
29566
30006
|
var WAKE_PLANE_CAPABILITY = "wake.create";
|
|
29567
30007
|
var WAKE_PLANE_STATUS_TTL_MS = 5 * 60 * 1000;
|
|
29568
30008
|
var WAKE_PLANE_HANDSHAKE_TIMEOUT_MS = 2000;
|
|
@@ -29571,7 +30011,7 @@ var inFlightProbe = null;
|
|
|
29571
30011
|
var catalogProbe = probeWakePlaneCatalog;
|
|
29572
30012
|
var now = () => Date.now();
|
|
29573
30013
|
function connectionFile() {
|
|
29574
|
-
return
|
|
30014
|
+
return join9(getDataDir(), "cortexkit", "run", "subc-connection.json");
|
|
29575
30015
|
}
|
|
29576
30016
|
async function probeWakePlaneCatalog() {
|
|
29577
30017
|
const file = connectionFile();
|
|
@@ -30234,12 +30674,12 @@ async function archiveExpiredMemories(args) {
|
|
|
30234
30674
|
|
|
30235
30675
|
// src/features/magic-context/dreamer/maintain-docs-protected-enforcement.ts
|
|
30236
30676
|
import { existsSync as existsSync5, readFileSync as readFileSync7, writeFileSync as writeFileSync2 } from "node:fs";
|
|
30237
|
-
import { join as
|
|
30677
|
+
import { join as join10 } from "node:path";
|
|
30238
30678
|
var MAINTAIN_DOCS_SNAPSHOT_FILES = ["ARCHITECTURE.md", "STRUCTURE.md"];
|
|
30239
30679
|
function snapshotMaintainDocsFiles(docsDir) {
|
|
30240
30680
|
const snapshot = new Map;
|
|
30241
30681
|
for (const name of MAINTAIN_DOCS_SNAPSHOT_FILES) {
|
|
30242
|
-
const path =
|
|
30682
|
+
const path = join10(docsDir, name);
|
|
30243
30683
|
try {
|
|
30244
30684
|
if (existsSync5(path)) {
|
|
30245
30685
|
snapshot.set(name, readFileSync7(path, "utf8"));
|
|
@@ -30250,7 +30690,7 @@ function snapshotMaintainDocsFiles(docsDir) {
|
|
|
30250
30690
|
}
|
|
30251
30691
|
|
|
30252
30692
|
// src/features/magic-context/dreamer/map-memories.ts
|
|
30253
|
-
import { createHash as
|
|
30693
|
+
import { createHash as createHash12 } from "node:crypto";
|
|
30254
30694
|
|
|
30255
30695
|
// src/features/magic-context/dreamer/map-memories-prompt.ts
|
|
30256
30696
|
import { execFile as execFile2 } from "node:child_process";
|
|
@@ -30485,7 +30925,7 @@ function readRetries(db, project) {
|
|
|
30485
30925
|
}
|
|
30486
30926
|
}
|
|
30487
30927
|
function contentKey2(memory) {
|
|
30488
|
-
return
|
|
30928
|
+
return createHash12("sha256").update(`${memory.category}
|
|
30489
30929
|
${memory.content}`).digest("hex");
|
|
30490
30930
|
}
|
|
30491
30931
|
function isDeferred(memory, retries) {
|
|
@@ -30907,7 +31347,7 @@ async function applyParsedBatchMappings(args, batch, parsed, budgetFinalized = f
|
|
|
30907
31347
|
name: "memory.set_mapping",
|
|
30908
31348
|
arguments: {
|
|
30909
31349
|
memory_project: args.projectIdentity,
|
|
30910
|
-
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)}`,
|
|
30911
31351
|
rows
|
|
30912
31352
|
}
|
|
30913
31353
|
}
|
|
@@ -32208,7 +32648,7 @@ function insertDreamRun(db, run) {
|
|
|
32208
32648
|
}
|
|
32209
32649
|
|
|
32210
32650
|
// src/features/magic-context/dreamer/verify.ts
|
|
32211
|
-
import { createHash as
|
|
32651
|
+
import { createHash as createHash13 } from "node:crypto";
|
|
32212
32652
|
|
|
32213
32653
|
// src/features/magic-context/dreamer/verify-diff.ts
|
|
32214
32654
|
import { execFile as execFile3 } from "node:child_process";
|
|
@@ -33073,7 +33513,7 @@ async function applyParsedVerifyManifest(args, batch, parsed, headAtPrompt, budg
|
|
|
33073
33513
|
name: "memory.set_verification",
|
|
33074
33514
|
arguments: {
|
|
33075
33515
|
memory_project: args.projectIdentity,
|
|
33076
|
-
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)}`,
|
|
33077
33517
|
rows
|
|
33078
33518
|
}
|
|
33079
33519
|
}
|
|
@@ -33907,7 +34347,7 @@ function parseFrictionGateVerdict(verdict) {
|
|
|
33907
34347
|
}
|
|
33908
34348
|
function computeRetrospectiveWindowKey(flagged) {
|
|
33909
34349
|
const anchors = flagged.map((message) => `${message.sessionId}:${message.ts}`).sort().join("|");
|
|
33910
|
-
return
|
|
34350
|
+
return createHash14("sha256").update(anchors).digest("hex").slice(0, 32);
|
|
33911
34351
|
}
|
|
33912
34352
|
function renderFrictionWindow(messages, flaggedOrdinals, radius = 2) {
|
|
33913
34353
|
const flagged = new Set(flaggedOrdinals);
|
|
@@ -35345,7 +35785,7 @@ function runTick(origin) {
|
|
|
35345
35785
|
if (tickInFlight)
|
|
35346
35786
|
return;
|
|
35347
35787
|
tickInFlight = true;
|
|
35348
|
-
log2(`[
|
|
35788
|
+
log2(`[magic-context] maintenance tick (${origin}) — projects=${registeredProjects.size}`);
|
|
35349
35789
|
(async () => {
|
|
35350
35790
|
try {
|
|
35351
35791
|
const db = openTimerDatabaseOrNull("maintenance tick");
|
|
@@ -35395,6 +35835,9 @@ function persistTickOutcome(db, failure) {
|
|
|
35395
35835
|
}
|
|
35396
35836
|
}
|
|
35397
35837
|
async function runMessageHistoryMaintenance(db) {
|
|
35838
|
+
const prunedIdentities = await pruneMissingProjectIdentities();
|
|
35839
|
+
if (prunedIdentities > 0)
|
|
35840
|
+
log2(`[magic-context] pruned ${prunedIdentities} missing project identities`);
|
|
35398
35841
|
try {
|
|
35399
35842
|
await drainStaleLkgSlots(db);
|
|
35400
35843
|
} catch (error) {
|
|
@@ -35628,10 +36071,20 @@ async function sweepGitCommits(args) {
|
|
|
35628
36071
|
const holderId = crypto.randomUUID();
|
|
35629
36072
|
const lease = acquireGitSweepLease(db, projectIdentity, holderId);
|
|
35630
36073
|
if (!lease.acquired) {
|
|
35631
|
-
|
|
36074
|
+
if (lease.reason === "cooldown_active")
|
|
36075
|
+
return;
|
|
36076
|
+
const reason = `lease held by ${lease.leaseHolder ?? "another holder"} until ${lease.leaseExpiresAt ?? "unknown"}`;
|
|
35632
36077
|
log2(`[git-commits] sweep skipped for ${projectIdentity}: ${reason}`);
|
|
35633
36078
|
return;
|
|
35634
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
|
+
}
|
|
35635
36088
|
const startedAt = Date.now();
|
|
35636
36089
|
const stopRenewal = startGitSweepLeaseRenewal(db, projectIdentity, holderId);
|
|
35637
36090
|
log2(`[git-commits] sweep starting for ${projectIdentity} (sinceDays=${gitCommitIndexing.since_days} maxCommits=${gitCommitIndexing.max_commits})`);
|
|
@@ -35892,9 +36345,9 @@ function hiddenTerminalError(event) {
|
|
|
35892
36345
|
}
|
|
35893
36346
|
|
|
35894
36347
|
// src/v2/hooks/lkg-system.ts
|
|
35895
|
-
import { createHash as
|
|
36348
|
+
import { createHash as createHash15 } from "node:crypto";
|
|
35896
36349
|
function identity(slot) {
|
|
35897
|
-
return
|
|
36350
|
+
return createHash15("sha256").update(JSON.stringify({
|
|
35898
36351
|
capturedAt: slot.capturedAt,
|
|
35899
36352
|
captureSequence: slot.captureSequence,
|
|
35900
36353
|
rowVersion: slot.rowVersion,
|
|
@@ -48722,7 +49175,7 @@ function resolveCtxExpandMode(args, domain) {
|
|
|
48722
49175
|
}
|
|
48723
49176
|
|
|
48724
49177
|
// src/tools/ctx-expand/render.ts
|
|
48725
|
-
import { createHash as
|
|
49178
|
+
import { createHash as createHash16 } from "node:crypto";
|
|
48726
49179
|
function isRecord6(value) {
|
|
48727
49180
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
48728
49181
|
}
|
|
@@ -48946,7 +49399,7 @@ function renderItemByTag(db, sessionId, number, textIndexDomain = "part") {
|
|
|
48946
49399
|
const index = scoped ? Number(scoped[2]) : 0;
|
|
48947
49400
|
const piText = message.parts.filter((part) => isRecord6(part) && part.type === "text");
|
|
48948
49401
|
const part = message.parts[index];
|
|
48949
|
-
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]) : [];
|
|
48950
49403
|
const selected = derived ? matching[Number(derived[4])] : textIndexDomain === "text" ? piText[index] : part;
|
|
48951
49404
|
return selected ? renderPartFull(selected) ?? "" : `Tag ${number}'s original text part is no longer in stored history.`;
|
|
48952
49405
|
}
|
|
@@ -49701,7 +50154,7 @@ import { isAbsolute as isAbsolute2 } from "node:path";
|
|
|
49701
50154
|
// ../retina-local-fs/src/path-fence.ts
|
|
49702
50155
|
import { lstat as lstat2, realpath as realpath2 } from "node:fs/promises";
|
|
49703
50156
|
import { homedir as homedir4 } from "node:os";
|
|
49704
|
-
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";
|
|
49705
50158
|
|
|
49706
50159
|
// ../retina-local-fs/src/errors.ts
|
|
49707
50160
|
class ProviderError extends Error {
|
|
@@ -49716,7 +50169,7 @@ class ProviderError extends Error {
|
|
|
49716
50169
|
// ../retina-local-fs/src/path-fence.ts
|
|
49717
50170
|
async function resolveAndFenceProviderPath(configuredPath, options) {
|
|
49718
50171
|
const { home, dataDirectory, aliases } = await resolveFenceRoots(options);
|
|
49719
|
-
const expanded = configuredPath.startsWith("~/") ?
|
|
50172
|
+
const expanded = configuredPath.startsWith("~/") ? join11(home, configuredPath.slice(2)) : configuredPath === "~" ? home : configuredPath;
|
|
49720
50173
|
const absolute = isAbsolute(expanded) ? resolve2(expanded) : resolve2(options.cwd ?? process.cwd(), expanded);
|
|
49721
50174
|
const canonical = await canonicalPath(absolute, options.allowMissing);
|
|
49722
50175
|
if (fenceCandidates(canonical, aliases).some((candidate) => isFencedPath(candidate, home, dataDirectory))) {
|
|
@@ -49733,13 +50186,13 @@ async function resolveFenceRoots(options) {
|
|
|
49733
50186
|
} catch (error) {
|
|
49734
50187
|
throw fsError(configuredHomePath, error);
|
|
49735
50188
|
}
|
|
49736
|
-
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"));
|
|
49737
50190
|
const dataDirectory = await canonicalPath(configuredDataDirectory, true);
|
|
49738
50191
|
const aliases = [];
|
|
49739
|
-
const logicalCortexkit =
|
|
50192
|
+
const logicalCortexkit = join11(dataDirectory, "cortexkit");
|
|
49740
50193
|
for (const logical of [
|
|
49741
50194
|
logicalCortexkit,
|
|
49742
|
-
...FENCED_CORTEXKIT_ROOTS.map((root) =>
|
|
50195
|
+
...FENCED_CORTEXKIT_ROOTS.map((root) => join11(logicalCortexkit, root))
|
|
49743
50196
|
]) {
|
|
49744
50197
|
const canonical = await canonicalPath(logical, true);
|
|
49745
50198
|
if (canonical !== logical)
|
|
@@ -49753,7 +50206,7 @@ function fenceCandidates(canonical, aliases) {
|
|
|
49753
50206
|
const relativeToAlias = relative(alias.canonical, canonical);
|
|
49754
50207
|
const inside = relativeToAlias === "" || relativeToAlias !== ".." && !relativeToAlias.startsWith(`..${sep}`) && !isAbsolute(relativeToAlias);
|
|
49755
50208
|
if (inside)
|
|
49756
|
-
candidates.push(
|
|
50209
|
+
candidates.push(join11(alias.logical, relativeToAlias));
|
|
49757
50210
|
}
|
|
49758
50211
|
return candidates;
|
|
49759
50212
|
}
|
|
@@ -49784,7 +50237,7 @@ async function canonicalPath(path, allowMissing) {
|
|
|
49784
50237
|
suffix.unshift(basename(candidate));
|
|
49785
50238
|
candidate = parent;
|
|
49786
50239
|
try {
|
|
49787
|
-
return
|
|
50240
|
+
return join11(await realpath2(candidate), ...suffix);
|
|
49788
50241
|
} catch (parentError) {
|
|
49789
50242
|
if (!isMissingError(parentError)) {
|
|
49790
50243
|
throw fsError(path, parentError);
|
|
@@ -49793,8 +50246,8 @@ async function canonicalPath(path, allowMissing) {
|
|
|
49793
50246
|
}
|
|
49794
50247
|
}
|
|
49795
50248
|
}
|
|
49796
|
-
function isFencedPath(canonicalPath, homeDirectory, dataDirectory = process.env.XDG_DATA_HOME ??
|
|
49797
|
-
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");
|
|
49798
50251
|
const relativeToCortexkit = relative(cortexkitRoot, canonicalPath);
|
|
49799
50252
|
const insideCortexkit = relativeToCortexkit !== "" && relativeToCortexkit !== ".." && !relativeToCortexkit.startsWith(`..${sep}`) && !isAbsolute(relativeToCortexkit);
|
|
49800
50253
|
const parts = insideCortexkit ? relativeToCortexkit.split(sep) : [];
|
|
@@ -50473,7 +50926,7 @@ function formatCtxReduceReply(stampedCount, selfStampCount = 0) {
|
|
|
50473
50926
|
return parts.join(" ");
|
|
50474
50927
|
}
|
|
50475
50928
|
// src/tools/ctx-reduce/tools.ts
|
|
50476
|
-
import { createHash as
|
|
50929
|
+
import { createHash as createHash17 } from "node:crypto";
|
|
50477
50930
|
|
|
50478
50931
|
// src/features/magic-context/range-parser.ts
|
|
50479
50932
|
function parseRangeString(input) {
|
|
@@ -50536,11 +50989,11 @@ function createCtxReduceTool(deps) {
|
|
|
50536
50989
|
const stableId = `oc-${sessionId}-${callId}`;
|
|
50537
50990
|
if (Buffer.byteLength(stableId) <= 128)
|
|
50538
50991
|
return stableId;
|
|
50539
|
-
return `oc-${
|
|
50992
|
+
return `oc-${createHash17("sha256").update(stableId).digest("hex")}`;
|
|
50540
50993
|
}
|
|
50541
50994
|
fallbackCommandSequence += 1;
|
|
50542
50995
|
const monotonicId = `oc-${sessionId}-${fallbackCommandSequence}`;
|
|
50543
|
-
return Buffer.byteLength(monotonicId) <= 128 ? monotonicId : `oc-${
|
|
50996
|
+
return Buffer.byteLength(monotonicId) <= 128 ? monotonicId : `oc-${createHash17("sha256").update(monotonicId).digest("hex")}`;
|
|
50544
50997
|
};
|
|
50545
50998
|
return tool({
|
|
50546
50999
|
description: CTX_REDUCE_DESCRIPTION,
|
|
@@ -51382,7 +51835,7 @@ async function registerContext(context) {
|
|
|
51382
51835
|
}
|
|
51383
51836
|
const folds = new FoldOwner(context.storage);
|
|
51384
51837
|
const nativeFoldMemory = !compactionOff && process.env.MC_OC2_INVISIBLE_FOLD === "1" ? nativeFoldCache(() => storage.require()) : undefined;
|
|
51385
|
-
const nativeFoldReplay = nativeFoldMemory ? new NativeFoldReplay(nativeFoldMemory, () => openStoreReader()) : undefined;
|
|
51838
|
+
const nativeFoldReplay = nativeFoldMemory ? new NativeFoldReplay(nativeFoldMemory, () => openStoreReader(), context.storage) : undefined;
|
|
51386
51839
|
setOutputReserveConfig(config.output_reserve);
|
|
51387
51840
|
const queriedModels = new Set;
|
|
51388
51841
|
const rawLimits = new Map;
|
|
@@ -51434,6 +51887,7 @@ async function registerContext(context) {
|
|
|
51434
51887
|
memorySyncRequestedSessions: rustMemorySyncRequestedSessions
|
|
51435
51888
|
}) : undefined;
|
|
51436
51889
|
const hiddenChildHook = new HiddenChildHook;
|
|
51890
|
+
await context.session.hook("http.request", (draft) => hiddenChildHook.cacheRequest(draft));
|
|
51437
51891
|
const tools = db && isDatabasePersisted(db) ? await registerTools(context, db, config, moduleToolBackends?.backends, (id) => hiddenChildHook.owns(id)) : undefined;
|
|
51438
51892
|
const usage = new Map;
|
|
51439
51893
|
const generateReplay = new V2GenerateReplay;
|
|
@@ -51810,87 +52264,114 @@ async function registerContext(context) {
|
|
|
51810
52264
|
}) : undefined;
|
|
51811
52265
|
const usageController = new AbortController;
|
|
51812
52266
|
const usageDone = (async () => {
|
|
51813
|
-
|
|
51814
|
-
|
|
51815
|
-
|
|
51816
|
-
|
|
51817
|
-
const
|
|
51818
|
-
|
|
51819
|
-
|
|
51820
|
-
|
|
51821
|
-
|
|
51822
|
-
|
|
51823
|
-
|
|
51824
|
-
|
|
51825
|
-
|
|
51826
|
-
|
|
51827
|
-
|
|
51828
|
-
|
|
51829
|
-
|
|
51830
|
-
|
|
51831
|
-
|
|
51832
|
-
|
|
51833
|
-
|
|
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;
|
|
51834
52344
|
const model = liveModels.get(sessionID);
|
|
51835
|
-
|
|
51836
|
-
|
|
51837
|
-
|
|
51838
|
-
|
|
51839
|
-
error,
|
|
51840
|
-
providerID: model?.providerID,
|
|
51841
|
-
modelID: model?.modelID
|
|
52345
|
+
if (model) {
|
|
52346
|
+
await recordUsage({
|
|
52347
|
+
sessionID,
|
|
52348
|
+
model: { providerID: model.providerID, id: model.modelID }
|
|
51842
52349
|
});
|
|
51843
|
-
|
|
51844
|
-
|
|
52350
|
+
if (!compactionOff && typeof await nativeFoldReplay?.baseline(sessionID) === "string")
|
|
52351
|
+
hostFolds?.idle(sessionID);
|
|
51845
52352
|
}
|
|
52353
|
+
} catch (error) {
|
|
52354
|
+
log2(`[magic-context] v2 event handler failed (type=${event.type ?? "unknown"}, session=${event.data?.sessionID ?? "none"})`, error);
|
|
51846
52355
|
}
|
|
51847
|
-
continue;
|
|
51848
|
-
}
|
|
51849
|
-
if (event.type === "session.deleted") {
|
|
51850
|
-
clearLkgMeasuredRequest(sessionID);
|
|
51851
|
-
deletedSessions.add(sessionID);
|
|
51852
|
-
transform?.clearSessionLogState(sessionID);
|
|
51853
|
-
if (db) {
|
|
51854
|
-
markSessionCleanupPending(db, sessionID);
|
|
51855
|
-
clearSession(db, sessionID);
|
|
51856
|
-
}
|
|
51857
|
-
rawProviders.get(sessionID)?.();
|
|
51858
|
-
rawProviders.delete(sessionID);
|
|
51859
|
-
usage.delete(sessionID);
|
|
51860
|
-
hiddenSessionErrors.delete(sessionID);
|
|
51861
|
-
storageNoticeBySession.delete(sessionID);
|
|
51862
|
-
liveModels.delete(sessionID);
|
|
51863
|
-
variants.delete(sessionID);
|
|
51864
|
-
agents.delete(sessionID);
|
|
51865
|
-
channel1.delete(sessionID);
|
|
51866
|
-
commitSeenLastPass.delete(sessionID);
|
|
51867
|
-
clearEmbedSessionState(sessionID);
|
|
51868
|
-
historyRefreshSessions.delete(sessionID);
|
|
51869
|
-
clearPendingMaterialization(pendingMaterializationSessions, sessionID);
|
|
51870
|
-
lastHeuristicsTurnId.delete(sessionID);
|
|
51871
|
-
restoredRows.forget(sessionID);
|
|
51872
|
-
await nativeFoldReplay?.forget(sessionID);
|
|
51873
|
-
generateReplay.forget(sessionID);
|
|
51874
|
-
systemPromptRefreshSessions.delete(sessionID);
|
|
51875
|
-
systemPrompt?.clearSession(sessionID);
|
|
51876
|
-
tagger.cleanup(sessionID);
|
|
51877
|
-
continue;
|
|
51878
|
-
}
|
|
51879
|
-
if (event.type !== "session.execution.succeeded")
|
|
51880
|
-
continue;
|
|
51881
|
-
const model = liveModels.get(sessionID);
|
|
51882
|
-
if (model) {
|
|
51883
|
-
await recordUsage({
|
|
51884
|
-
sessionID,
|
|
51885
|
-
model: { providerID: model.providerID, id: model.modelID }
|
|
51886
|
-
});
|
|
51887
|
-
if (!compactionOff && typeof await nativeFoldReplay?.baseline(sessionID) === "string")
|
|
51888
|
-
hostFolds?.idle(sessionID);
|
|
51889
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;
|
|
51890
52374
|
}
|
|
51891
|
-
} catch (error) {
|
|
51892
|
-
if (!usageController.signal.aborted)
|
|
51893
|
-
log2("[magic-context] v2 usage subscription failed", error);
|
|
51894
52375
|
}
|
|
51895
52376
|
})();
|
|
51896
52377
|
const materialize = (draft) => {
|
|
@@ -52163,6 +52644,7 @@ async function registerContext(context) {
|
|
|
52163
52644
|
compactionOff,
|
|
52164
52645
|
storeGeneration: "v2",
|
|
52165
52646
|
normalizeRestoredAssistantText: stripCopiedTagNotation,
|
|
52647
|
+
refreshSourceContents: (sessionID) => nativeFoldReplay?.needsHeadRebuild(sessionID) ?? false,
|
|
52166
52648
|
hostCleanupCompactionMarkers: () => ({
|
|
52167
52649
|
verified: true,
|
|
52168
52650
|
removedLineages: 0,
|
|
@@ -52251,12 +52733,13 @@ async function registerContext(context) {
|
|
|
52251
52733
|
historyRefreshSessions.add(draft.sessionID);
|
|
52252
52734
|
requestPendingMaterialization(pendingMaterializationSessions, draft.sessionID, "boundary_repair");
|
|
52253
52735
|
}
|
|
52254
|
-
const
|
|
52736
|
+
const localCut = cut && isLocalCheckpoint(cut) ? cut : undefined;
|
|
52737
|
+
const incoming = localCut && draft.messages.find((message) => message.id === localCut.id);
|
|
52255
52738
|
postFold = cut !== undefined;
|
|
52256
|
-
if (
|
|
52739
|
+
if (localCut && !incoming)
|
|
52257
52740
|
throw new Error("The host checkpoint disappeared from the context draft");
|
|
52258
52741
|
let nativeRestored;
|
|
52259
|
-
if (cut && nativeFoldReplay &&
|
|
52742
|
+
if (cut && nativeFoldReplay && await nativeFoldReplay.admits(draft.sessionID, cut, reader)) {
|
|
52260
52743
|
try {
|
|
52261
52744
|
nativeRestored = await nativeFoldReplay.restore(draft.sessionID, cut, `${draft.model.providerID}/${draft.model.id}`, { bounded: !rustModeModuleClient });
|
|
52262
52745
|
} catch (error) {
|
|
@@ -52265,7 +52748,11 @@ async function registerContext(context) {
|
|
|
52265
52748
|
nativeRestored = await nativeFoldReplay.restoreRead(draft.sessionID, cut, draft.model);
|
|
52266
52749
|
}
|
|
52267
52750
|
}
|
|
52268
|
-
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);
|
|
52269
52756
|
historyRefreshSessions.add(draft.sessionID);
|
|
52270
52757
|
requestPendingMaterialization(pendingMaterializationSessions, draft.sessionID, "host_history_change");
|
|
52271
52758
|
}
|
|
@@ -52276,25 +52763,27 @@ async function registerContext(context) {
|
|
|
52276
52763
|
return !id || !present.has(id);
|
|
52277
52764
|
});
|
|
52278
52765
|
draft.messages.splice(0, draft.messages.length, ...hidden, ...draft.messages.filter((message) => message !== incoming));
|
|
52279
|
-
} else if (cut && incoming) {
|
|
52280
|
-
|
|
52281
|
-
|
|
52282
|
-
|
|
52283
|
-
|
|
52284
|
-
|
|
52285
|
-
|
|
52286
|
-
|
|
52287
|
-
|
|
52288
|
-
|
|
52289
|
-
|
|
52290
|
-
|
|
52291
|
-
|
|
52292
|
-
|
|
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
|
+
}
|
|
52293
52782
|
const moduleBoundaryID = rustModeModuleClient ? getPersistedCompactionMarkerState(db, draft.sessionID)?.boundaryMessageId ?? null : null;
|
|
52294
52783
|
const moduleBoundarySeq = moduleBoundaryID ? reader.sequenceForId(draft.sessionID, moduleBoundaryID) : undefined;
|
|
52295
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);
|
|
52296
52785
|
const servedBoundary = boundaryID ? servedBoundaryRow(reader, draft.sessionID, boundaryID) : null;
|
|
52297
|
-
const boundary = (moduleBoundarySeq !== undefined ? moduleBoundarySeq - 1 : undefined) ?? servedBoundary?.seq ?? reader.sequenceForId(draft.sessionID, boundaryID) ?? (reader.earliestSequence(draft.sessionID) ?? 0) - 1;
|
|
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;
|
|
52298
52787
|
if (moduleBoundarySeq !== undefined)
|
|
52299
52788
|
sessionLog2(draft.sessionID, `v2 restore: from the module boundary ${moduleBoundaryID} to the host checkpoint`);
|
|
52300
52789
|
const present = new Set(draft.messages.map((message) => message.id));
|
|
@@ -52545,13 +53034,13 @@ ${baseline}
|
|
|
52545
53034
|
}, 0));
|
|
52546
53035
|
return {
|
|
52547
53036
|
async dispose() {
|
|
53037
|
+
usageController.abort();
|
|
52548
53038
|
await hiddenCompletionExecutor?.dispose();
|
|
53039
|
+
await usageDone;
|
|
52549
53040
|
rpcStopped = true;
|
|
52550
53041
|
rpcServer.stop();
|
|
52551
53042
|
transform?.disposeRust();
|
|
52552
53043
|
tools?.dispose();
|
|
52553
|
-
usageController.abort();
|
|
52554
|
-
await usageDone;
|
|
52555
53044
|
deletedSessions.clear();
|
|
52556
53045
|
await dreamTrigger?.dispose();
|
|
52557
53046
|
await maintenanceTimer?.dispose();
|