@cortexkit/opencode-magic-context 0.49.33 → 0.49.35
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 +11 -6
- package/dist/chunk-embedding-write-worker.js +16 -14
- package/dist/{compaction-marker-candidates-31h86ph0.js → compaction-marker-candidates-g0p67ced.js} +3 -2
- package/dist/compaction-marker-candidates-worker.js +1 -1
- package/dist/{compartment-chunk-embedding-5q5gj67r.js → compartment-chunk-embedding-y4136are.js} +8 -7
- package/dist/{conflict-warning-hook-xgskea1v.js → conflict-warning-hook-hhw8z5ak.js} +9 -8
- package/dist/{context-jyzkstnr.js → context-fk8e3h9p.js} +1400 -701
- package/dist/{derive-budgets-pqybnx09.js → derive-budgets-htj16n4x.js} +3 -2
- package/dist/embedding-backfill-q6n72sy0.js +27 -0
- package/dist/embedding-worker-process.js +2 -1
- package/dist/embedding-worker.js +5 -4
- package/dist/expand-attachments-h33jbgyz.js +21 -0
- package/dist/features/magic-context/auto-search-diagnostics.d.ts +21 -0
- package/dist/features/magic-context/auto-search-diagnostics.d.ts.map +1 -0
- package/dist/features/magic-context/compaction-marker.d.ts +22 -6
- package/dist/features/magic-context/compaction-marker.d.ts.map +1 -1
- 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/search.d.ts +4 -0
- package/dist/features/magic-context/search.d.ts.map +1 -1
- package/dist/features/magic-context/storage-meta-persisted.d.ts +7 -0
- package/dist/features/magic-context/storage-meta-persisted.d.ts.map +1 -1
- package/dist/features/magic-context/store-generation-rebase-labels.d.ts +6 -0
- package/dist/features/magic-context/store-generation-rebase-labels.d.ts.map +1 -0
- package/dist/features/magic-context/store-generation-rebase.d.ts.map +1 -1
- package/dist/{history-owner-36wp3mkb.js → history-owner-0z620wgz.js} +3 -2
- package/dist/hooks/magic-context/apply-operations.d.ts +20 -3
- package/dist/hooks/magic-context/apply-operations.d.ts.map +1 -1
- package/dist/hooks/magic-context/auto-search-observation.d.ts +13 -0
- package/dist/hooks/magic-context/auto-search-observation.d.ts.map +1 -0
- package/dist/hooks/magic-context/auto-search-runner.d.ts.map +1 -1
- package/dist/hooks/magic-context/auto-search-worker-client.d.ts +5 -1
- package/dist/hooks/magic-context/auto-search-worker-client.d.ts.map +1 -1
- package/dist/hooks/magic-context/compaction-marker-manager.d.ts +5 -5
- package/dist/hooks/magic-context/compaction-marker-manager.d.ts.map +1 -1
- package/dist/hooks/magic-context/compaction-marker-publication.d.ts +9 -0
- package/dist/hooks/magic-context/compaction-marker-publication.d.ts.map +1 -0
- package/dist/hooks/magic-context/compartment-commit-hashes.d.ts +4 -0
- package/dist/hooks/magic-context/compartment-commit-hashes.d.ts.map +1 -0
- package/dist/hooks/magic-context/compartment-runner-validation.d.ts +1 -0
- package/dist/hooks/magic-context/compartment-runner-validation.d.ts.map +1 -1
- package/dist/hooks/magic-context/event-resolvers.d.ts.map +1 -1
- package/dist/hooks/magic-context/final-wire-completeness.d.ts +15 -0
- package/dist/hooks/magic-context/final-wire-completeness.d.ts.map +1 -0
- package/dist/hooks/magic-context/final-wire-token-estimate.d.ts.map +1 -1
- package/dist/hooks/magic-context/inject-compartments.d.ts.map +1 -1
- package/dist/hooks/magic-context/raw-ordinal-warmup.d.ts +1 -0
- package/dist/hooks/magic-context/raw-ordinal-warmup.d.ts.map +1 -1
- package/dist/hooks/magic-context/read-session-chunk.d.ts +11 -0
- package/dist/hooks/magic-context/read-session-chunk.d.ts.map +1 -1
- package/dist/hooks/magic-context/read-session-formatting.d.ts +2 -0
- package/dist/hooks/magic-context/read-session-formatting.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform.d.ts.map +1 -1
- package/dist/{index-as2amvn3.js → index-0c7p8mq5.js} +6 -531
- package/dist/{index-51rdvtkz.js → index-1rhgxqs8.js} +2 -2
- package/dist/index-2amn2s73.js +123 -0
- package/dist/{index-c7phnbvk.js → index-2p37txes.js} +1 -1
- package/dist/index-2qbtqg1w.js +529 -0
- package/dist/{index-waktfbjy.js → index-2v6nvy3k.js} +4 -4
- package/dist/{index-dq5xzeb9.js → index-3d3872c6.js} +7 -5
- package/dist/{index-qr2mb02j.js → index-3j9t1v4n.js} +55 -21
- package/dist/{index-2xh37qn5.js → index-4bgk5ztz.js} +576 -5524
- package/dist/{index-b88dwwrh.js → index-4xyjr62e.js} +1 -1
- package/dist/index-66a50f3e.js +777 -0
- package/dist/{index-94ef0qe2.js → index-87ctnzz9.js} +33 -5
- package/dist/{index-xrnsygfq.js → index-9wnbnx8f.js} +1 -1
- package/dist/{index-3fkk2gwj.js → index-b6xz3qbe.js} +246 -420
- package/dist/{index-0fe4q77z.js → index-brg2w6qc.js} +146 -134
- package/dist/{index-spwjbkc7.js → index-dnqqqc5f.js} +1 -1
- package/dist/index-dy7w6wm4.js +194 -0
- package/dist/{index-3jmx3fae.js → index-ezv6dz3y.js} +37 -7
- package/dist/index-f297z1n8.js +4557 -0
- package/dist/{index-qgh1qwjj.js → index-f9b3vtt1.js} +1 -1
- package/dist/{index-v15ne3a3.js → index-faxb7mck.js} +2 -2
- package/dist/{index-rrv26qjz.js → index-fw42ms3m.js} +1 -1
- package/dist/{index-t5pck3ss.js → index-fxbk7gk3.js} +1 -1
- package/dist/{index-wfybj1dw.js → index-g4t7850m.js} +2 -2
- package/dist/{index-hbt0sbv2.js → index-gyaa159j.js} +18 -276
- package/dist/{index-4pnsgvfk.js → index-hacf2tyx.js} +1 -1
- package/dist/{index-s1n8dd2n.js → index-jkanybgq.js} +2 -2
- package/dist/{index-2743x98y.js → index-jn0ddrhp.js} +29 -138
- package/dist/{index-h7tgn49j.js → index-jrfre9ah.js} +5 -222
- package/dist/{index-kfyb3k6n.js → index-jz5bk7xd.js} +2 -2
- package/dist/{index-np3rgfw4.js → index-ksv0a31x.js} +3 -3
- package/dist/{index-7kkphb6c.js → index-nj360hcs.js} +4 -4
- package/dist/{index-gkee6p4g.js → index-p56dszfp.js} +3 -3
- package/dist/{index-4s4zq97n.js → index-pq0dpwrc.js} +4 -4
- package/dist/{index-rfxzazzy.js → index-pswsyf1w.js} +4 -4
- package/dist/{index-y1qwzvxn.js → index-pztqab6k.js} +2 -2
- package/dist/{index-rverk2vz.js → index-qncw9hey.js} +1 -1
- package/dist/index-qx8j6kds.js +270 -0
- package/dist/{index-kq5w68dp.js → index-txs8tce6.js} +1 -1
- package/dist/index-vzhhr1ht.js +532 -0
- package/dist/index-wh9fxds5.js +265 -0
- package/dist/{index-b7w46fp2.js → index-x2mrq5xv.js} +170 -48
- package/dist/{index-43vqx0za.js → index-xwwsbsd3.js} +15 -13
- package/dist/index-z4p0ry94.js +222 -0
- package/dist/index-z9zygwse.js +89 -0
- package/dist/{index-v7287tzq.js → index-zhqwda72.js} +19 -8
- package/dist/index.js +83 -72
- package/dist/{logger-94kew5wm.js → logger-qwnbcfj9.js} +2 -1
- package/dist/{message-fts-rowid-map-va36knh4.js → message-fts-rowid-map-xg7hr0mk.js} +5 -4
- package/dist/{message-index-bounded-zq7a5nm6.js → message-index-bounded-narw7bnz.js} +12 -11
- package/dist/{message-time-backfill-4qva0b4f.js → message-time-backfill-39bm498k.js} +3 -2
- package/dist/migration-worker.js +13 -11
- package/dist/{project-embedding-registry-6yex0r9f.js → project-embedding-registry-tdz7985n.js} +13 -11
- package/dist/raw-ordinal-warmup-worker.js +12 -7
- package/dist/{read-session-chunk-1ndphmb8.js → read-session-chunk-vmg1zjg0.js} +15 -10
- package/dist/{read-session-raw-b2sd67v4.js → read-session-raw-mncmzbm9.js} +3 -2
- package/dist/recomp-orchestrator-qyyhnc9b.js +68 -0
- package/dist/render-c5p0k846.js +43 -0
- package/dist/{safe-notification-target-mkr9yzvr.js → safe-notification-target-wztd7bgk.js} +3 -2
- package/dist/{search-archive-sr07c6aj.js → search-archive-0ny7p3bw.js} +13 -11
- package/dist/{search-040pac3a.js → search-f6hwvcxk.js} +26 -23
- package/dist/{send-session-notification-vz86nt79.js → send-session-notification-0gwcz3fw.js} +7 -6
- package/dist/{storage-tags-6hvkk01c.js → storage-tags-zx1023km.js} +5 -4
- package/dist/store-620rjzt9.js +21 -0
- package/dist/store-reader-yh19h38c.js +14 -0
- package/dist/tools/ctx-expand/render.d.ts +5 -3
- package/dist/tools/ctx-expand/render.d.ts.map +1 -1
- package/dist/tools/ctx-expand/search-archive.d.ts.map +1 -1
- package/dist/tools/ctx-expand/tools.d.ts +2 -0
- package/dist/tools/ctx-expand/tools.d.ts.map +1 -1
- package/dist/tools/ctx-expand/v2-archive-reader.d.ts +33 -0
- package/dist/tools/ctx-expand/v2-archive-reader.d.ts.map +1 -0
- package/dist/{transform-postprocess-phase-zx1peqma.js → transform-postprocess-phase-807ff6t2.js} +36 -30
- package/dist/v2/auto-search-worker.js +11 -6
- package/dist/v2/chunk-embedding-write-worker.js +16 -14
- package/dist/v2/{compaction-marker-candidates-m4vmye3w.js → compaction-marker-candidates-t1aq6gsj.js} +3 -2
- package/dist/v2/compaction-marker-candidates-worker.js +1 -1
- package/dist/v2/{compartment-chunk-embedding-rc31e6md.js → compartment-chunk-embedding-ncsk0r9e.js} +8 -7
- package/dist/v2/{context-3c4z2wj5.js → context-znqfkap4.js} +1725 -1095
- package/dist/v2/{derive-budgets-knf763tt.js → derive-budgets-sa0v7bz0.js} +4 -3
- package/dist/v2/embedding-backfill-11j425e0.js +26 -0
- package/dist/v2/embedding-worker-process.js +2 -1
- package/dist/v2/embedding-worker.js +5 -4
- package/dist/v2/expand-attachments-h33jbgyz.js +21 -0
- package/dist/v2/fold/idle.d.ts +15 -0
- package/dist/v2/fold/idle.d.ts.map +1 -0
- package/dist/v2/fold/native-replay-v3.d.ts +68 -0
- package/dist/v2/fold/native-replay-v3.d.ts.map +1 -0
- package/dist/v2/fold/native-replay.d.ts +58 -2
- package/dist/v2/fold/native-replay.d.ts.map +1 -1
- package/dist/v2/fold/policy.d.ts +2 -1
- package/dist/v2/fold/policy.d.ts.map +1 -1
- package/dist/v2/{history-owner-ad0crnrn.js → history-owner-fpka43cn.js} +3 -2
- package/dist/v2/hooks/context.d.ts.map +1 -1
- package/dist/v2/hooks/expand-attachments.d.ts +8 -0
- package/dist/v2/hooks/expand-attachments.d.ts.map +1 -0
- package/dist/v2/hooks/overflow-recovery.d.ts +45 -0
- package/dist/v2/hooks/overflow-recovery.d.ts.map +1 -0
- package/dist/v2/hooks/store.d.ts +7 -2
- package/dist/v2/hooks/store.d.ts.map +1 -1
- package/dist/v2/{logger-p34mjtja.js → logger-4cj6d03m.js} +2 -1
- package/dist/v2/{message-fts-rowid-map-78awh03v.js → message-fts-rowid-map-rmk571mb.js} +5 -4
- package/dist/v2/{message-index-bounded-jvgz7vk9.js → message-index-bounded-620bppw7.js} +12 -11
- package/dist/v2/{message-time-backfill-zvthw6xb.js → message-time-backfill-0c4h7sg6.js} +3 -2
- package/dist/v2/migration-worker.js +13 -11
- package/dist/v2/ordinal-range.fixture.d.ts +7 -0
- package/dist/v2/ordinal-range.fixture.d.ts.map +1 -0
- package/dist/v2/{project-embedding-registry-1x5qe2fy.js → project-embedding-registry-bm5fe1a8.js} +13 -11
- package/dist/v2/raw-ordinal-warmup-worker.js +12 -7
- package/dist/v2/{read-session-chunk-djzgm4jg.js → read-session-chunk-qfwv1k71.js} +15 -10
- package/dist/v2/{read-session-raw-5x088amc.js → read-session-raw-q294t8xs.js} +3 -2
- package/dist/v2/recomp-orchestrator-fcnjref7.js +67 -0
- package/dist/v2/render-98a1qv0b.js +42 -0
- package/dist/v2/{safe-notification-target-khnzg57c.js → safe-notification-target-gphhast7.js} +3 -2
- package/dist/v2/{search-archive-n3dhns4r.js → search-archive-r0y1bafr.js} +13 -11
- package/dist/v2/{search-q3wkpe8t.js → search-z1zqzsmh.js} +25 -22
- package/dist/v2/{send-session-notification-x5nzy34v.js → send-session-notification-fst6hkg7.js} +7 -6
- package/dist/v2/{server-rb8m4vry.js → server-1xesqm5h.js} +146 -134
- package/dist/v2/server-2amn2s73.js +123 -0
- package/dist/v2/{server-6g98c227.js → server-3schkz95.js} +4 -4
- package/dist/v2/server-468mya5v.js +209 -0
- package/dist/v2/server-55v5hpth.js +270 -0
- package/dist/v2/server-5jp38p98.js +532 -0
- package/dist/v2/{server-qjvk4a9t.js → server-69m30b21.js} +1 -1
- package/dist/v2/{server-d01pe8q5.js → server-7ccxt4nq.js} +14 -216
- package/dist/v2/{server-3mz2qh5a.js → server-969cdpmg.js} +1 -1
- package/dist/v2/{server-835q39kd.js → server-9k0mjef7.js} +2 -2
- package/dist/v2/{server-qc915kw2.js → server-bez34e60.js} +4 -4
- package/dist/v2/{server-nxas8v1d.js → server-bpvsvtph.js} +3 -3
- package/dist/v2/{server-ab8017gw.js → server-bxpz2dcn.js} +29 -138
- package/dist/v2/{server-bsgd4dk1.js → server-dcws5831.js} +2 -2
- package/dist/v2/server-ef1mskas.js +777 -0
- package/dist/v2/{server-1bw1wcbp.js → server-f0j864ma.js} +1 -1
- package/dist/v2/{server-aqbm9c8d.js → server-fqj6ddpr.js} +632 -5540
- package/dist/v2/{server-rr4cbkr0.js → server-hnknwaz8.js} +37 -7
- package/dist/v2/{server-h1byrhwx.js → server-hsf0qsn5.js} +19 -8
- package/dist/v2/{server-6495nmn9.js → server-jb6tjyeb.js} +5 -222
- package/dist/v2/{server-2aasmpsp.js → server-kkxzwa6w.js} +4 -4
- package/dist/v2/{server-a7x00tw8.js → server-mfn1yf9d.js} +1 -1
- package/dist/v2/{server-tkdabx8q.js → server-q0z2q2dx.js} +5 -530
- package/dist/v2/{server-n14edf07.js → server-qa74bj91.js} +77 -17
- package/dist/v2/server-qf2kzsh2.js +4513 -0
- package/dist/v2/{server-gyy4k6mf.js → server-qmmkhz2z.js} +1 -1
- package/dist/v2/{server-29qp8nz4.js → server-qxzbmtqt.js} +1 -1
- package/dist/v2/{server-hwag0khr.js → server-r3chnxs5.js} +4 -4
- package/dist/v2/{server-vr4szghm.js → server-rktnzs89.js} +2 -2
- package/dist/v2/{server-6vd2n183.js → server-s9xgyyj9.js} +1 -1
- package/dist/v2/{server-53eh1r8r.js → server-sd8hvzte.js} +2 -2
- package/dist/v2/{server-k3t06fxr.js → server-sefxj8k1.js} +1 -1
- package/dist/v2/{server-v77xa5wj.js → server-tpt7bwq8.js} +1 -1
- package/dist/v2/{server-awr8qa4c.js → server-ws5exe6q.js} +2 -2
- package/dist/v2/server-x4m6xcn4.js +194 -0
- package/dist/v2/{server-806rzhs6.js → server-xbtw0p9t.js} +1 -1
- package/dist/v2/{server-cqjvxyrp.js → server-xy7w7hrd.js} +2 -2
- package/dist/v2/server-ypf1ap0v.js +529 -0
- package/dist/v2/server-z4p0ry94.js +222 -0
- package/dist/v2/server-z9zygwse.js +89 -0
- package/dist/v2/{server-ab1g0wn9.js → server-zzgtgqmd.js} +2 -2
- package/dist/v2/server.js +6 -5
- package/dist/v2/{storage-tags-18nbaanf.js → storage-tags-19s0ebf0.js} +5 -4
- package/dist/v2/store-reader-cgx47zkp.js +14 -0
- package/dist/v2/store-reader.d.ts +9 -2
- package/dist/v2/store-reader.d.ts.map +1 -1
- package/dist/v2/store-vdm8v3jd.js +21 -0
- package/dist/v2/v2-archive-reader-t2c0eypn.js +11 -0
- package/dist/v2/{wrapup-orchestrator-ga5vfmwr.js → wrapup-orchestrator-aqpqsveg.js} +46 -39
- package/dist/v2-archive-reader-tm2eayp2.js +11 -0
- package/dist/wrapup-orchestrator-k5yp19a6.js +55 -0
- package/package.json +1 -1
- package/src/shared/sqlite-transaction-mode-guard.test.ts +4 -0
- package/dist/embedding-backfill-0jgtqxen.js +0 -25
- package/dist/recomp-orchestrator-skqzzvby.js +0 -62
- package/dist/v2/embedding-backfill-f43hd8y6.js +0 -24
- package/dist/v2/recomp-orchestrator-qfqdvbta.js +0 -61
- package/dist/wrapup-orchestrator-dy8r3gp8.js +0 -49
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
TAG_SELECT_COLUMNS2,
|
|
19
19
|
getCandidateToolOwners2,
|
|
20
20
|
pickNearestPriorOwner2
|
|
21
|
-
} from "./server-
|
|
21
|
+
} from "./server-bpvsvtph.js";
|
|
22
22
|
import {
|
|
23
23
|
OMO_INTERNAL_INITIATOR_MARKER,
|
|
24
24
|
isSystemDirective,
|
|
@@ -36,19 +36,19 @@ import {
|
|
|
36
36
|
formatBlock,
|
|
37
37
|
compactTextForSummary,
|
|
38
38
|
mergeCommitHashes
|
|
39
|
-
} from "./server-
|
|
39
|
+
} from "./server-969cdpmg.js";
|
|
40
40
|
import {
|
|
41
41
|
getHarness2
|
|
42
42
|
} from "./server-pavzsdc6.js";
|
|
43
43
|
import {
|
|
44
44
|
sessionLog2
|
|
45
|
-
} from "./server-
|
|
45
|
+
} from "./server-jb6tjyeb.js";
|
|
46
46
|
import {
|
|
47
47
|
prepareCachedStatement2
|
|
48
48
|
} from "./server-gzy5w8ya.js";
|
|
49
49
|
import {
|
|
50
50
|
stableStringify
|
|
51
|
-
} from "./server-
|
|
51
|
+
} from "./server-tpt7bwq8.js";
|
|
52
52
|
import {
|
|
53
53
|
renderToolTemplate,
|
|
54
54
|
resolveModelConfigValue,
|
|
@@ -70,25 +70,29 @@ import {
|
|
|
70
70
|
readRawSeedTailFromDb2,
|
|
71
71
|
readRawSessionBoundaryEndpointsFromDb2,
|
|
72
72
|
prewarmRawSessionOrdinalsForDb
|
|
73
|
-
} from "./server-
|
|
73
|
+
} from "./server-s9xgyyj9.js";
|
|
74
74
|
import {
|
|
75
75
|
openCodeDbExists,
|
|
76
76
|
withReadOnlySessionDb,
|
|
77
77
|
getRawSessionMessageCountFromDb,
|
|
78
78
|
getMessageTimesFromOpenCodeDb
|
|
79
|
-
} from "./server-
|
|
79
|
+
} from "./server-mfn1yf9d.js";
|
|
80
80
|
import {
|
|
81
81
|
getToolDefinitionMeasurementSignature,
|
|
82
82
|
getMeasuredToolDefinitionTokens,
|
|
83
83
|
getSessionToolDefinitionTokens
|
|
84
|
-
} from "./server-
|
|
84
|
+
} from "./server-xy7w7hrd.js";
|
|
85
|
+
import {
|
|
86
|
+
markHostUnservedRow,
|
|
87
|
+
isHostUnservedRow
|
|
88
|
+
} from "./server-z9zygwse.js";
|
|
85
89
|
import {
|
|
86
90
|
canonicalModelIdentity,
|
|
87
91
|
piModelRefToCanonical
|
|
88
92
|
} from "./server-avwt563y.js";
|
|
89
93
|
import {
|
|
90
94
|
logSlowWriteTransaction
|
|
91
|
-
} from "./server-
|
|
95
|
+
} from "./server-qmmkhz2z.js";
|
|
92
96
|
// src/shared/historian-tool-defaults.json
|
|
93
97
|
var historian_tool_defaults_default = {
|
|
94
98
|
ctx_note: "Note ${input.action} ${input.note_ids}: ${input.content} → ${output.truncate(160)}",
|
|
@@ -227,92 +231,22 @@ function askAnswerLines(text) {
|
|
|
227
231
|
return extractAskAnswerNotices(text).map(formatAskAnswerNotice);
|
|
228
232
|
}
|
|
229
233
|
|
|
230
|
-
// src/hooks/magic-context/
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
value: true,
|
|
235
|
-
enumerable: false,
|
|
236
|
-
configurable: true
|
|
237
|
-
});
|
|
238
|
-
return target;
|
|
239
|
-
}
|
|
240
|
-
function isHostUnservedRow(value) {
|
|
241
|
-
return typeof value === "object" && value !== null && value[HOST_UNSERVED_ROW] === true;
|
|
242
|
-
}
|
|
243
|
-
function retreatPastHostUnservedRows(messages, exclusiveEnd, floor) {
|
|
244
|
-
if (!messages.some(isHostUnservedRow))
|
|
245
|
-
return exclusiveEnd;
|
|
246
|
-
const byOrdinal = new Map(messages.map((message) => [message.ordinal, message]));
|
|
247
|
-
let end = exclusiveEnd;
|
|
248
|
-
while (end - 1 >= floor && isHostUnservedRow(byOrdinal.get(end - 1)))
|
|
249
|
-
end -= 1;
|
|
250
|
-
return end;
|
|
251
|
-
}
|
|
252
|
-
function snapTerminalCompartmentToServedRow(compartments, lines) {
|
|
253
|
-
if (!lines.some(isHostUnservedRow))
|
|
254
|
-
return { compartments: [...compartments], snapped: false };
|
|
255
|
-
const byOrdinal = new Map(lines.map((line) => [line.ordinal, line]));
|
|
256
|
-
const result = [...compartments];
|
|
257
|
-
let snapped = false;
|
|
258
|
-
while (result.length > 0) {
|
|
259
|
-
const last = result[result.length - 1];
|
|
260
|
-
if (!isHostUnservedRow(byOrdinal.get(last.endMessage)))
|
|
261
|
-
break;
|
|
262
|
-
snapped = true;
|
|
263
|
-
let served;
|
|
264
|
-
for (let ordinal = last.endMessage - 1;ordinal >= last.startMessage; ordinal -= 1) {
|
|
265
|
-
const line = byOrdinal.get(ordinal);
|
|
266
|
-
if (line && !isHostUnservedRow(line)) {
|
|
267
|
-
served = line;
|
|
268
|
-
break;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
if (!served) {
|
|
272
|
-
result.pop();
|
|
273
|
-
continue;
|
|
274
|
-
}
|
|
275
|
-
result[result.length - 1] = {
|
|
276
|
-
...last,
|
|
277
|
-
endMessage: served.ordinal,
|
|
278
|
-
endMessageId: served.messageId
|
|
279
|
-
};
|
|
280
|
-
break;
|
|
234
|
+
// src/hooks/magic-context/compartment-commit-hashes.ts
|
|
235
|
+
function rawCommitHashes(value) {
|
|
236
|
+
if (typeof value === "string") {
|
|
237
|
+
return Array.from(value.matchAll(/\b[0-9a-f]{7,40}\b/gi), (match) => match[0].toLowerCase());
|
|
281
238
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
enumerable: false,
|
|
293
|
-
configurable: true
|
|
294
|
-
});
|
|
295
|
-
return target;
|
|
296
|
-
}
|
|
297
|
-
function isCoveredInstructionRow(value) {
|
|
298
|
-
return typeof value === "object" && value !== null && value[COVERED_INSTRUCTION_ROW] === true;
|
|
299
|
-
}
|
|
300
|
-
function takeCoveredInstructionRows(messages) {
|
|
301
|
-
const taken = messages.filter((message) => isCoveredInstructionRow(message.info));
|
|
302
|
-
if (taken.length > 0) {
|
|
303
|
-
const kept = messages.filter((message) => !isCoveredInstructionRow(message.info));
|
|
304
|
-
messages.splice(0, messages.length, ...kept);
|
|
305
|
-
}
|
|
306
|
-
return taken;
|
|
307
|
-
}
|
|
308
|
-
function cloneKeepingCoveredInstructionMarks(messages) {
|
|
309
|
-
const copy = structuredClone(messages);
|
|
310
|
-
messages.forEach((message, index) => {
|
|
311
|
-
const copied = copy[index];
|
|
312
|
-
if (copied && isCoveredInstructionRow(message.info))
|
|
313
|
-
markCoveredInstructionRow(copied.info);
|
|
239
|
+
if (value === null || typeof value !== "object")
|
|
240
|
+
return [];
|
|
241
|
+
return Object.values(value).flatMap(rawCommitHashes);
|
|
242
|
+
}
|
|
243
|
+
function removeUnsupportedCommitHashes(text, supported) {
|
|
244
|
+
return text.replace(/`?\b([0-9a-f]{7,40})\b`?/gi, (token, hash) => {
|
|
245
|
+
const normalized = hash.toLowerCase();
|
|
246
|
+
if (!/[a-f]/.test(normalized))
|
|
247
|
+
return token;
|
|
248
|
+
return Array.from(supported).some((source) => source.startsWith(normalized)) ? token : "";
|
|
314
249
|
});
|
|
315
|
-
return copy;
|
|
316
250
|
}
|
|
317
251
|
|
|
318
252
|
// src/hooks/magic-context/read-session-true-raw-tokens.ts
|
|
@@ -1302,6 +1236,78 @@ function applyEditMarkerToInput(input) {
|
|
|
1302
1236
|
}
|
|
1303
1237
|
}
|
|
1304
1238
|
|
|
1239
|
+
// src/hooks/magic-context/final-wire-completeness.ts
|
|
1240
|
+
function incompleteWirePartFields(part) {
|
|
1241
|
+
if (!part || typeof part !== "object")
|
|
1242
|
+
return ["part"];
|
|
1243
|
+
const p = part;
|
|
1244
|
+
if (p.ignored === true)
|
|
1245
|
+
return [];
|
|
1246
|
+
const missing = (present, field) => present ? [] : [field];
|
|
1247
|
+
switch (p.type) {
|
|
1248
|
+
case "text":
|
|
1249
|
+
case "reasoning":
|
|
1250
|
+
return missing(typeof p.text === "string", "text");
|
|
1251
|
+
case "thinking":
|
|
1252
|
+
return missing(typeof p.thinking === "string", "thinking");
|
|
1253
|
+
case "redacted_thinking":
|
|
1254
|
+
return missing(typeof p.data === "string", "data");
|
|
1255
|
+
case "tool": {
|
|
1256
|
+
const state = p.state !== null && typeof p.state === "object" ? p.state : undefined;
|
|
1257
|
+
const input = state?.input !== undefined || p.input !== undefined || p.args !== undefined;
|
|
1258
|
+
const result = state?.output !== undefined || state?.content !== undefined || state?.error !== undefined || p.output !== undefined || p.result !== undefined || p.content !== undefined;
|
|
1259
|
+
return [...missing(input, "input"), ...missing(result, "result")];
|
|
1260
|
+
}
|
|
1261
|
+
case "tool-call":
|
|
1262
|
+
case "tool_use":
|
|
1263
|
+
return missing(p.input !== undefined || p.args !== undefined, "input");
|
|
1264
|
+
case "tool-invocation":
|
|
1265
|
+
return [
|
|
1266
|
+
...missing(p.args !== undefined || p.input !== undefined, "input"),
|
|
1267
|
+
...missing(p.result !== undefined || p.output !== undefined || p.state !== null && typeof p.state === "object", "result")
|
|
1268
|
+
];
|
|
1269
|
+
case "tool-result":
|
|
1270
|
+
case "tool_result":
|
|
1271
|
+
return missing(p.result !== undefined || p.content !== undefined || p.output !== undefined, "result");
|
|
1272
|
+
case "step-start":
|
|
1273
|
+
case "step-finish":
|
|
1274
|
+
return [];
|
|
1275
|
+
case "file":
|
|
1276
|
+
return missing(typeof p.url === "string" && p.url.startsWith("data:image/"), "url (data:image/)");
|
|
1277
|
+
default:
|
|
1278
|
+
return ["supported type"];
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
function label(value) {
|
|
1282
|
+
return typeof value === "string" ? value.replace(/[^a-zA-Z0-9_.-]/g, "_").slice(0, 128) : null;
|
|
1283
|
+
}
|
|
1284
|
+
function incompleteWireParts(messages) {
|
|
1285
|
+
return messages.flatMap((message) => message.parts.flatMap((part, partIndex) => {
|
|
1286
|
+
const missingFields = incompleteWirePartFields(part);
|
|
1287
|
+
if (!missingFields.length)
|
|
1288
|
+
return [];
|
|
1289
|
+
const p = part && typeof part === "object" ? part : undefined;
|
|
1290
|
+
return [
|
|
1291
|
+
{
|
|
1292
|
+
messageId: label(message.info.id),
|
|
1293
|
+
partId: label(p?.id),
|
|
1294
|
+
partIndex,
|
|
1295
|
+
type: label(p?.type) ?? "unknown",
|
|
1296
|
+
missingFields
|
|
1297
|
+
}
|
|
1298
|
+
];
|
|
1299
|
+
}));
|
|
1300
|
+
}
|
|
1301
|
+
function createFinalWireIncompleteLogger(sessionID) {
|
|
1302
|
+
let logged = false;
|
|
1303
|
+
return (estimate, messages) => {
|
|
1304
|
+
if (logged || estimate?.trusted)
|
|
1305
|
+
return;
|
|
1306
|
+
logged = true;
|
|
1307
|
+
sessionLog2(sessionID, `transform: final-wire untrusted incompleteParts=${JSON.stringify(incompleteWireParts(messages))}`);
|
|
1308
|
+
};
|
|
1309
|
+
}
|
|
1310
|
+
|
|
1305
1311
|
// src/features/magic-context/merged-reasoning-decisions.ts
|
|
1306
1312
|
var MERGED_REASONING_PARTS_PREFIX = "__merged_reasoning_parts_v1__:";
|
|
1307
1313
|
var decodedDecisions = new Map;
|
|
@@ -3551,7 +3557,11 @@ function parsePersistedCompactionMarkerState(raw, storedTargetEndMessageId) {
|
|
|
3551
3557
|
if (parsed && typeof parsed === "object" && typeof parsed.boundaryMessageId === "string" && typeof parsed.summaryMessageId === "string" && typeof parsed.compactionPartId === "string" && typeof parsed.summaryPartId === "string" && typeof parsed.boundaryOrdinal === "number") {
|
|
3552
3558
|
const targetEndMessageId = typeof storedTargetEndMessageId === "string" && storedTargetEndMessageId.length > 0 ? storedTargetEndMessageId : typeof parsed.targetEndMessageId === "string" && parsed.targetEndMessageId.length > 0 ? parsed.targetEndMessageId : null;
|
|
3553
3559
|
return {
|
|
3554
|
-
|
|
3560
|
+
boundaryMessageId: parsed.boundaryMessageId,
|
|
3561
|
+
summaryMessageId: parsed.summaryMessageId,
|
|
3562
|
+
compactionPartId: parsed.compactionPartId,
|
|
3563
|
+
summaryPartId: parsed.summaryPartId,
|
|
3564
|
+
boundaryOrdinal: parsed.boundaryOrdinal,
|
|
3555
3565
|
targetEndMessageId
|
|
3556
3566
|
};
|
|
3557
3567
|
}
|
|
@@ -3562,6 +3572,34 @@ function getPersistedCompactionMarkerState(db, sessionId) {
|
|
|
3562
3572
|
const row = db.prepare("SELECT compaction_marker_state, compaction_marker_target_end_message_id FROM session_meta WHERE session_id = ?").get(sessionId);
|
|
3563
3573
|
return parsePersistedCompactionMarkerState(row?.compaction_marker_state, row?.compaction_marker_target_end_message_id);
|
|
3564
3574
|
}
|
|
3575
|
+
function getCompactionMarkerPublicationState(db, sessionId) {
|
|
3576
|
+
const row = db.prepare("SELECT compaction_marker_state FROM session_meta WHERE session_id = ?").get(sessionId);
|
|
3577
|
+
const raw = row?.compaction_marker_state ?? "";
|
|
3578
|
+
let pending = null;
|
|
3579
|
+
try {
|
|
3580
|
+
pending = parsePersistedCompactionMarkerState(JSON.stringify(JSON.parse(raw).pending));
|
|
3581
|
+
} catch {}
|
|
3582
|
+
return { raw, pending };
|
|
3583
|
+
}
|
|
3584
|
+
function compareAndSetCompactionMarkerPublicationState(db, sessionId, expectedRaw, state, pending) {
|
|
3585
|
+
return db.transaction(() => {
|
|
3586
|
+
ensureSessionMetaRow(db, sessionId);
|
|
3587
|
+
let envelope = {};
|
|
3588
|
+
if (pending) {
|
|
3589
|
+
try {
|
|
3590
|
+
const parsed = JSON.parse(expectedRaw);
|
|
3591
|
+
if (parsed && typeof parsed === "object")
|
|
3592
|
+
envelope = parsed;
|
|
3593
|
+
} catch {}
|
|
3594
|
+
}
|
|
3595
|
+
const raw = JSON.stringify(pending ? { ...envelope, pending } : state);
|
|
3596
|
+
const result = db.prepare(`UPDATE session_meta SET compaction_marker_state = ?, compaction_marker_target_end_message_id = ?
|
|
3597
|
+
WHERE session_id = ? AND COALESCE(compaction_marker_state, '') = ?`).run(raw, state?.targetEndMessageId ?? null, sessionId, expectedRaw);
|
|
3598
|
+
if (result.changes !== 1)
|
|
3599
|
+
throw new Error("marker publication state changed concurrently");
|
|
3600
|
+
return raw;
|
|
3601
|
+
}).immediate();
|
|
3602
|
+
}
|
|
3565
3603
|
function setPersistedCompactionMarkerState(db, sessionId, state) {
|
|
3566
3604
|
db.transaction(() => {
|
|
3567
3605
|
ensureSessionMetaRow(db, sessionId);
|
|
@@ -5943,45 +5981,7 @@ function estimateAppendedWireTokens(input) {
|
|
|
5943
5981
|
};
|
|
5944
5982
|
}
|
|
5945
5983
|
function hasCountableParts(message) {
|
|
5946
|
-
return message.parts.every((part) =>
|
|
5947
|
-
if (!part || typeof part !== "object")
|
|
5948
|
-
return false;
|
|
5949
|
-
const p = part;
|
|
5950
|
-
if (p.ignored === true)
|
|
5951
|
-
return true;
|
|
5952
|
-
switch (p.type) {
|
|
5953
|
-
case "text":
|
|
5954
|
-
case "reasoning":
|
|
5955
|
-
return typeof p.text === "string";
|
|
5956
|
-
case "thinking":
|
|
5957
|
-
return typeof p.thinking === "string";
|
|
5958
|
-
case "redacted_thinking":
|
|
5959
|
-
return typeof p.data === "string";
|
|
5960
|
-
case "tool": {
|
|
5961
|
-
const state = p.state !== null && typeof p.state === "object" ? p.state : undefined;
|
|
5962
|
-
const hasInput = state?.input !== undefined || p.input !== undefined || p.args !== undefined;
|
|
5963
|
-
const hasResult = state?.output !== undefined || state?.content !== undefined || state?.error !== undefined || p.output !== undefined || p.result !== undefined || p.content !== undefined;
|
|
5964
|
-
return hasInput && hasResult;
|
|
5965
|
-
}
|
|
5966
|
-
case "tool-call":
|
|
5967
|
-
return p.input !== undefined || p.args !== undefined;
|
|
5968
|
-
case "tool-invocation":
|
|
5969
|
-
return (p.args !== undefined || p.input !== undefined) && (p.result !== undefined || p.output !== undefined || p.state !== null && typeof p.state === "object");
|
|
5970
|
-
case "tool-result":
|
|
5971
|
-
return p.result !== undefined || p.content !== undefined || p.output !== undefined;
|
|
5972
|
-
case "tool_use":
|
|
5973
|
-
return p.input !== undefined || p.args !== undefined;
|
|
5974
|
-
case "tool_result":
|
|
5975
|
-
return p.content !== undefined || p.result !== undefined || p.output !== undefined;
|
|
5976
|
-
case "step-start":
|
|
5977
|
-
case "step-finish":
|
|
5978
|
-
return true;
|
|
5979
|
-
case "file":
|
|
5980
|
-
return typeof p.url === "string" && p.url.startsWith("data:image/");
|
|
5981
|
-
default:
|
|
5982
|
-
return false;
|
|
5983
|
-
}
|
|
5984
|
-
});
|
|
5984
|
+
return message.parts.every((part) => incompleteWirePartFields(part).length === 0);
|
|
5985
5985
|
}
|
|
5986
5986
|
|
|
5987
5987
|
// src/hooks/magic-context/tool-input-size.ts
|
|
@@ -6490,6 +6490,13 @@ function resolveHostServedBoundaryId2(sessionId, messageId) {
|
|
|
6490
6490
|
function hasRawMessageProvider2(sessionId) {
|
|
6491
6491
|
return sessionProviders.has(sessionId);
|
|
6492
6492
|
}
|
|
6493
|
+
function rawMessageWorkerSource2(sessionId) {
|
|
6494
|
+
return sessionProviders.get(sessionId)?.provider.workerSource;
|
|
6495
|
+
}
|
|
6496
|
+
function rawMessageOffThreadRangeReader2(sessionId) {
|
|
6497
|
+
const provider = sessionProviders.get(sessionId)?.provider;
|
|
6498
|
+
return provider?.readMessageIdOrdinalsForRangeOffThread?.bind(provider);
|
|
6499
|
+
}
|
|
6493
6500
|
function setRawMessageProvider2(sessionId, provider) {
|
|
6494
6501
|
const current = sessionProviders.get(sessionId);
|
|
6495
6502
|
const registration = current?.provider === provider ? current : { provider, scopes: 0 };
|
|
@@ -7276,7 +7283,12 @@ function readSessionChunk2(sessionId, tokenBudget, offset = 1, eligibleEndOrdina
|
|
|
7276
7283
|
}
|
|
7277
7284
|
if (msg.ordinal < startOrdinal)
|
|
7278
7285
|
continue;
|
|
7279
|
-
const
|
|
7286
|
+
const commitHashes = rawCommitHashes(msg.parts);
|
|
7287
|
+
const meta = {
|
|
7288
|
+
ordinal: msg.ordinal,
|
|
7289
|
+
messageId: msg.id
|
|
7290
|
+
};
|
|
7291
|
+
Object.defineProperty(meta, "commitHashes", { value: commitHashes });
|
|
7280
7292
|
if (isHostUnservedRow(msg))
|
|
7281
7293
|
markHostUnservedRow(meta);
|
|
7282
7294
|
if (msg.role === "system") {
|
|
@@ -7454,4 +7466,4 @@ function readRawSessionSeedTail2(sessionId, boundaryId, onQuery) {
|
|
|
7454
7466
|
});
|
|
7455
7467
|
}
|
|
7456
7468
|
|
|
7457
|
-
export { expandToolPart, askAnswerLines,
|
|
7469
|
+
export { expandToolPart, askAnswerLines, removeUnsupportedCommitHashes, completedToolArcCrossesBoundary, estimateTrueRawMessageTokens, buildToolArcs, fenceBoundaryForCompletedToolArcs, fenceBoundaryForToolArcs, buildTrueRawTokenIndex, computeRawRangeFingerprint, stripSystemInjection, isTextPart, isToolPartWithOutput, isFilePart, toolPartHasUserAnswer, DreamTokenBudgetExceeded, TOKEN_BUDGET_FINALIZE_MESSAGE, registerBudgetFinalizeChild, releaseBudgetFinalizeChild, createDreamTokenBudget, TOOL_USE_DISABLED, needsBlockedRead, withBlockedReadInstruction, rememberV1HiddenRun, recordToolParameters, createDroppedInputGuard, assertExecutableToolInput, isEditTool, createFinalWireIncompleteLogger, MERGED_REASONING_PARTS_PREFIX, decodeMergedReasoningParts, MAX_EXECUTE_THRESHOLD, escalationBands, HYGIENE_PROVIDER_UNITS_VERSION, sessionDecisionCalibration, transitionSessionHygieneUnits, readEpochFloorSnapshot, getProtectionWindowForSession, SESSION_META_SELECT_COLUMNS, META_COLUMNS, BOOLEAN_META_KEYS, NULL_BIND_META_KEYS, isSessionMetaRow, getDefaultSessionMeta, ensureSessionMetaRow, toSessionMeta, persistCachedM0, clearCachedM0M1, clearCachedM0, withReplayEnvelopeSnapshot, invalidateReplayEnvelopeSnapshot, isRustMarkerAdmissionFenced, setRustMarkerAdmissionFence, ReplayDocumentError, readReplayEnvelope, readReplayDocument, updateReplayDocument, writeReplayDocument, isEmergencyRecoveryArmed, isProviderOverflowReconfirmed, isProviderOverflowFailClosedProven, getEmergencyRecoveryArmedAt, describeProtectedTailDrainBudgetSkip, loadPersistedUsage, loadProtectedTailMeta, markProtectedTailPolicyV3Seeded, recordProtectedTailPublicationFloor, recordProtectedTailNoEligibleHead, resetProtectedTailNoEligibleHead, getWrapupInProgressState, isWrapupInProgress, acquireWrapupInProgress, updateWrapupInProgress, releaseWrapupInProgress, resolveCompactionModeRecord, getCompactionModeRecord, setCompactionModeRecord, getProtectedTailDrainBudgetSkip, reserveProtectedTailDrainTokens, clearEmergencyDrainLatch, recordHistorianDrainFailure, clearHistorianDrainFailure, rollbackProtectedTailDrainReservation, clearPersistedReasoningWatermark, getEmergencyInputSample, setEmergencyDropSample, clearEmergencyDropSample, getLastNudgeUndropped, setLastNudgeUndropped, getChannel1NudgeState, setChannel1NudgeState, markChannel1PostReduceGracePending, captureChannel1PostReduceGraceBaseline, getChannel2NudgeState, setChannel2NudgeState, casChannel2NudgeState, claimChannel2NudgeState, casChannel2NudgeClaim, getPersistedNoteNudge, setPersistedNoteNudgeTrigger, setPersistedNoteNudgeTriggerMessageId, getNoteNudgeAnchors, getAutoSearchHintDecisions, deliverNoteNudgeAtomic, appendAutoSearchHintDecision, pruneNoteNudgeAnchors, queueAutoSearchHintDecisionRetirement, flushAutoSearchHintDecisionRetirement, getPersistedTodoPermissionDenied, setPersistedTodoPermissionDenied, getPersistedTodoSyntheticAnchor, setPersistedTodoSyntheticAnchor, clearPersistedTodoSyntheticAnchor, getNoteLastReadAt, setNoteLastReadAt, getHistorianFailureState, incrementHistorianFailure, clearHistorianFailureState, getOverflowState, loadTransformPassStateSnapshot, recordOverflowDetected, recordDetectedContextLimit, clearEmergencyRecovery, clearDetectedContextLimit, getPersistedCompactionMarkerState, getCompactionMarkerPublicationState, compareAndSetCompactionMarkerPublicationState, setPersistedCompactionMarkerState, getDeferredClearedCompactionMarkerState, retireDeferredClearedCompactionMarkerState, parseStrippedPlaceholderState, serializeStrippedPlaceholderState, getStrippedPlaceholderIds, applyStrippedPlaceholderDelta, THINKING_BINDING_RECOVERY_FROZEN_PREFIX, THINKING_BINDING_STRIP_ORDER_END_MARKER, thinkingBindingRecoveryFrozenId, COMPACTION_OFF_THINKING_FROZEN_PREFIX, compactionOffThinkingFrozenId, compactionOffFrozenThinkingIds, getThinkingBindingRecoveryTarget, clearThinkingBindingRecoveryIf, getMergedReasoningStrippedIds, addMergedReasoningStrippedIds, getTrailingBlankDecisions, addTrailingBlankDecisions, demoteTrailingBlankKeepDecisions, getStaleReduceStrippedIds, addStaleReduceStrippedIds, getProcessedImageStrippedIds, parseProcessedImageMarkers, serializeProcessedImageMarkers, getProcessedImageMarkers, addProcessedImageStrippedIds, getPendingCompactionMarkerState, getCompactionMarkerHealth, loadPostprocessReplaySnapshot, setPendingCompactionMarkerState, replacePendingCompactionMarkerStateIf, clearPendingCompactionMarkerStateIf, getPendingPiCompactionMarkerState, clearPendingPiCompactionMarkerStateIf, logPiCompactionMarkerClear, setSessionWorkMetrics, getObservedEpochFloor, resolveEpochFloorForPass, getReasoningRemovalState, addRemovedReasoningIds, markDropLeavesReasoning, detectLatestTurnThinkingMismatch, isPrefixBoundThinkingModel, detectOverflow, modelAcceptsEmptyContent, isAnthropicFamilyRoute, neutralizeDroppedReasoningPart, restoreNeutralizedReasoningPart, isNeutralizedReasoningPart, variantChangeBustsProviderCache, makeSentinel, makeWholeMessageSentinel, isSentinel, replaySentinelByMessageIds, isInActiveAnthropicTurn, activeAnthropicTurnStart, hasAnthropicReasoning, markServedShapeRepair, prepareServedShapeRepair, stripSystemInjectedMessages, stripDroppedPlaceholderMessages, replayClearedReasoning, replayStrippedInlineThinking, clearOldReasoning, stripClearedReasoning, captureInlineThinkingRepairs, stripInlineThinking, findReasoningBearingAssistantIds, findLatestAssistantReasoningMutationExemptMessage, snapshotTrailingBlankSourceDecisions, findTrailingBlankDecisionCandidates, applyFrozenTrailingBlankDecisions, stripReasoningFromAssistantIds, findMergedReasoningStripDecisions, stripReasoningFromMergedAssistants, getEmptyImageParts, stripProcessedImages, projectOpencodeReasoningBudgetCutoff, DEFAULT_KEEP_REASONING_TOKENS, resolveKeepReasoningTokens, reasoningStepCost, reasoningBudgetCutoff, reasoningTextAndOpaque, opencodeReasoningBudgetCutoff, describeFinalWireTail, estimatePartImageTokens, estimateMessageTokens, wireContentBytes, createFinalWireUsageTracker, estimateFinalWireInputTokens, estimateAppendedWireTokens, SKELETON_REAL_INPUT_MAX_BYTES, partHasCompletedResult, extractToolCallObservation, ToolMutationBatch, createToolDropTarget, resolveHostServedBoundaryId2, hasRawMessageProvider2, rawMessageWorkerSource2, rawMessageOffThreadRangeReader2, setRawMessageProvider2, setBoundedRawMessageProvider2, withRawMessageProvider2, cleanUserText2, withRawSessionMessageCache2, readRawSessionMessages2, readRawSessionMessagePage2, getRawSessionMessageOrdinalCount2, RAW_MESSAGE_VISIT_PAGE_SIZE2, visitRawSessionMessages2, visitRawSessionMessagesAsync2, readRawSessionMessageRange2, prepareRawSessionOrdinals2, primeTailRawMessageCache2, getCachedAbsoluteMessageCount2, primeInMemoryTailRawMessageCache2, readRawSessionMessageOrdinalPage2, getRawSessionStoredMessageCount2, readRawSessionMessageIdOrdinalsForRange2, readRawSessionMessageIdOrdinals2, readRawSessionMessagePartsById2, readRawSessionBoundaryEndpoints2, hasRawSessionMessageById2, readRawSessionMessageOrdinalById2, resolveHistorianChunkStart2, compareRawSessionMessageOrder2, readRawSessionMessageById2, getRawSessionMessageCount2, RAW_SESSION_TAG_KEY_PAGE_SIZE2, getRawSessionTagKeysThrough2, getLegacyProtectedTailStartOrdinal2, getProtectedTailStartOrdinal2, readSessionChunk2, getRawSessionMessageIdsThrough2, readRawSessionSeedTail2 };
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import {
|
|
2
|
+
withSqliteBackgroundWriter2,
|
|
3
|
+
withoutSqliteTransformPass2,
|
|
4
|
+
isTransientSqliteError2
|
|
5
|
+
} from "./server-gzy5w8ya.js";
|
|
6
|
+
|
|
7
|
+
// src/hooks/magic-context/embed-session-state.ts
|
|
8
|
+
var embedPauseBySession = new Set;
|
|
9
|
+
var embedRunStateBySession = new Map;
|
|
10
|
+
var activeEmbeddingSessions = new Map;
|
|
11
|
+
var autoEmbedAttemptedBySession = new Set;
|
|
12
|
+
var autoEmbedIdentityBySession = new Map;
|
|
13
|
+
var autoEmbedRetryAfterBySession = new Map;
|
|
14
|
+
function invalidateAutoEmbedSession(sessionId) {
|
|
15
|
+
autoEmbedAttemptedBySession.delete(sessionId);
|
|
16
|
+
autoEmbedIdentityBySession.delete(sessionId);
|
|
17
|
+
autoEmbedRetryAfterBySession.delete(sessionId);
|
|
18
|
+
}
|
|
19
|
+
function getEmbedDrainUiStatus(sessionId, progress) {
|
|
20
|
+
if (embedPauseBySession.has(sessionId)) {
|
|
21
|
+
return { status: "paused" };
|
|
22
|
+
}
|
|
23
|
+
const activeRun = embedRunStateBySession.get(sessionId);
|
|
24
|
+
if (activeRun && !activeRun.signal.aborted || progress?.kind === "embed" && progress.phase === "recomp") {
|
|
25
|
+
return { status: "running" };
|
|
26
|
+
}
|
|
27
|
+
if (progress?.kind === "embed" && (progress.phase === "failed" || progress.phase === "skipped") && progress.message) {
|
|
28
|
+
if (/provider/i.test(progress.message)) {
|
|
29
|
+
return { status: "stopped", detail: progress.message };
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return { status: "idle" };
|
|
33
|
+
}
|
|
34
|
+
function clearEmbedSessionState(sessionId) {
|
|
35
|
+
activeEmbeddingSessions.delete(sessionId);
|
|
36
|
+
embedPauseBySession.delete(sessionId);
|
|
37
|
+
const ctrl = embedRunStateBySession.get(sessionId);
|
|
38
|
+
if (ctrl) {
|
|
39
|
+
ctrl.abort();
|
|
40
|
+
embedRunStateBySession.delete(sessionId);
|
|
41
|
+
}
|
|
42
|
+
invalidateAutoEmbedSession(sessionId);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// src/shared/background-batch-drain.ts
|
|
46
|
+
async function drainBackgroundBatches(step, options = {}) {
|
|
47
|
+
const now = options.now ?? (() => performance.now());
|
|
48
|
+
const deadline = now() + (options.budgetMs ?? 2000);
|
|
49
|
+
const yieldFn = options.yieldFn ?? (() => new Promise((resolve) => setTimeout(resolve, 0)));
|
|
50
|
+
let batches = 0;
|
|
51
|
+
while (now() < deadline) {
|
|
52
|
+
try {
|
|
53
|
+
if (!withoutSqliteTransformPass2(() => withSqliteBackgroundWriter2(step)))
|
|
54
|
+
break;
|
|
55
|
+
} catch (error) {
|
|
56
|
+
if (isTransientSqliteError2(error))
|
|
57
|
+
break;
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
60
|
+
batches++;
|
|
61
|
+
await yieldFn();
|
|
62
|
+
}
|
|
63
|
+
return batches;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// src/features/magic-context/storage-embedding-measurements.ts
|
|
67
|
+
import { createHash } from "node:crypto";
|
|
68
|
+
function normalizedQueryHash(query) {
|
|
69
|
+
const normalized = query.trim().replace(/\s+/g, " ").toLowerCase();
|
|
70
|
+
return createHash("sha256").update(normalized).digest("hex");
|
|
71
|
+
}
|
|
72
|
+
var MEASUREMENT_CORPUS_SESSION_ROW_CAP = 2000;
|
|
73
|
+
function recordEmbeddingMeasurement(db, input, cap = MEASUREMENT_CORPUS_SESSION_ROW_CAP) {
|
|
74
|
+
const queryTextHash = normalizedQueryHash(input.queryText);
|
|
75
|
+
const dedupKey = queryTextHash;
|
|
76
|
+
const result = db.prepare(`INSERT OR IGNORE INTO embedding_measurement_corpus
|
|
77
|
+
(session_id, project_path, dedup_key, cohort_key, query_text_hash,
|
|
78
|
+
primary_result_ids_json, shadow_result_ids_json, primary_latency_ms, shadow_latency_ms,
|
|
79
|
+
primary_failed, shadow_failed, primary_model_id, shadow_model_id,
|
|
80
|
+
primary_fingerprint, shadow_fingerprint, primary_epoch, shadow_epoch,
|
|
81
|
+
corpus_hash, coverage_json, created_at)
|
|
82
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(input.sessionId, input.projectPath, dedupKey, input.cohortKey, queryTextHash, JSON.stringify(input.primaryResultIds.slice(0, 10)), JSON.stringify(input.shadowResultIds.slice(0, 10)), input.primaryLatencyMs, input.shadowLatencyMs, input.primaryFailed ? 1 : 0, input.shadowFailed ? 1 : 0, input.primaryModelId, input.shadowModelId, input.primaryFingerprint, input.shadowFingerprint, input.primaryEpoch, input.shadowEpoch, input.corpusHash, JSON.stringify(input.coverage), Date.now());
|
|
83
|
+
if (result.changes > 0) {
|
|
84
|
+
const rowCount = db.prepare("SELECT COUNT(*) AS count FROM embedding_measurement_corpus WHERE session_id = ?").get(input.sessionId).count;
|
|
85
|
+
const overflow = rowCount - cap;
|
|
86
|
+
if (overflow > 0) {
|
|
87
|
+
db.prepare(`DELETE FROM embedding_measurement_corpus
|
|
88
|
+
WHERE session_id = ?
|
|
89
|
+
AND id IN (
|
|
90
|
+
SELECT id FROM embedding_measurement_corpus
|
|
91
|
+
WHERE session_id = ?
|
|
92
|
+
ORDER BY id ASC
|
|
93
|
+
LIMIT ?
|
|
94
|
+
)`).run(input.sessionId, input.sessionId, overflow);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return result.changes > 0;
|
|
98
|
+
}
|
|
99
|
+
function beginSynapseBatchLedger(db, input, now = Date.now()) {
|
|
100
|
+
db.prepare(`INSERT INTO synapse_batch_ledger
|
|
101
|
+
(session_id, project_path, scope, manifest_json, request_key, status, created_at, updated_at)
|
|
102
|
+
VALUES (?, ?, ?, ?, ?, 'pending', ?, ?)
|
|
103
|
+
ON CONFLICT(session_id, request_key) DO UPDATE SET
|
|
104
|
+
manifest_json = excluded.manifest_json,
|
|
105
|
+
updated_at = excluded.updated_at`).run(input.sessionId, input.projectPath, input.scope, JSON.stringify(input.manifest), input.requestKey, now, now);
|
|
106
|
+
}
|
|
107
|
+
function finishSynapseBatchLedger(db, sessionId, requestKey, status, now = Date.now()) {
|
|
108
|
+
db.prepare("UPDATE synapse_batch_ledger SET status = ?, updated_at = ? WHERE session_id = ? AND request_key = ?").run(status, now, sessionId, requestKey);
|
|
109
|
+
}
|
|
110
|
+
var SYNAPSE_BATCH_LEDGER_TTL_MS = 14 * 24 * 60 * 60 * 1000;
|
|
111
|
+
function pruneSynapseBatchLedgerForProject(db, projectIdentity, ttlMs = SYNAPSE_BATCH_LEDGER_TTL_MS) {
|
|
112
|
+
const ledgerTable = db.prepare("SELECT 1 AS present FROM sqlite_master WHERE type = 'table' AND name = 'synapse_batch_ledger'").get();
|
|
113
|
+
if (!ledgerTable)
|
|
114
|
+
return 0;
|
|
115
|
+
const shadow = `shadow:${projectIdentity}`;
|
|
116
|
+
const cutoff = Date.now() - ttlMs;
|
|
117
|
+
const predicate = "session_id IN (?, ?) AND updated_at < ?";
|
|
118
|
+
if (!db.prepare(`SELECT 1 FROM synapse_batch_ledger WHERE ${predicate} LIMIT 1`).get(projectIdentity, shadow, cutoff))
|
|
119
|
+
return 0;
|
|
120
|
+
return db.prepare(`DELETE FROM synapse_batch_ledger WHERE ${predicate}`).run(projectIdentity, shadow, cutoff).changes;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export { embedPauseBySession, embedRunStateBySession, activeEmbeddingSessions, autoEmbedAttemptedBySession, autoEmbedIdentityBySession, autoEmbedRetryAfterBySession, invalidateAutoEmbedSession, getEmbedDrainUiStatus, clearEmbedSessionState, drainBackgroundBatches, recordEmbeddingMeasurement, beginSynapseBatchLedger, finishSynapseBatchLedger, pruneSynapseBatchLedgerForProject };
|
|
@@ -3,12 +3,12 @@ import {
|
|
|
3
3
|
} from "./server-fr0wbhdn.js";
|
|
4
4
|
import {
|
|
5
5
|
log2
|
|
6
|
-
} from "./server-
|
|
6
|
+
} from "./server-jb6tjyeb.js";
|
|
7
7
|
import {
|
|
8
8
|
ensureColumn,
|
|
9
9
|
healAllNullColumns,
|
|
10
10
|
installV95PerfSchema
|
|
11
|
-
} from "./server-
|
|
11
|
+
} from "./server-tpt7bwq8.js";
|
|
12
12
|
import {
|
|
13
13
|
resolveOpenCodeDbPath,
|
|
14
14
|
openCodeDbPathExists,
|
|
@@ -20,10 +20,10 @@ import {
|
|
|
20
20
|
import {
|
|
21
21
|
normalizeStoredProjectPath,
|
|
22
22
|
storedPathBelongsToIdentity
|
|
23
|
-
} from "./server-
|
|
23
|
+
} from "./server-69m30b21.js";
|
|
24
24
|
import {
|
|
25
25
|
logSlowWriteTransaction
|
|
26
|
-
} from "./server-
|
|
26
|
+
} from "./server-qmmkhz2z.js";
|
|
27
27
|
|
|
28
28
|
// src/features/magic-context/migrations.ts
|
|
29
29
|
import { isMainThread } from "node:worker_threads";
|