@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
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "./index-pavzsdc6.js";
|
|
4
4
|
import {
|
|
5
5
|
sessionLog2
|
|
6
|
-
} from "./index-
|
|
6
|
+
} from "./index-jrfre9ah.js";
|
|
7
7
|
import {
|
|
8
8
|
UNKNOWN_FIT_RATIO,
|
|
9
9
|
resolveDecisionCalibration,
|
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
TAG_SELECT_COLUMNS2,
|
|
25
25
|
getCandidateToolOwners2,
|
|
26
26
|
pickNearestPriorOwner2
|
|
27
|
-
} from "./index-
|
|
27
|
+
} from "./index-ksv0a31x.js";
|
|
28
28
|
import {
|
|
29
29
|
OMO_INTERNAL_INITIATOR_MARKER,
|
|
30
30
|
isSystemDirective,
|
|
@@ -42,13 +42,13 @@ import {
|
|
|
42
42
|
formatBlock,
|
|
43
43
|
compactTextForSummary,
|
|
44
44
|
mergeCommitHashes
|
|
45
|
-
} from "./index-
|
|
45
|
+
} from "./index-4xyjr62e.js";
|
|
46
46
|
import {
|
|
47
47
|
prepareCachedStatement2
|
|
48
48
|
} from "./index-gzy5w8ya.js";
|
|
49
49
|
import {
|
|
50
50
|
stableStringify
|
|
51
|
-
} from "./index-
|
|
51
|
+
} from "./index-9wnbnx8f.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 "./index-
|
|
73
|
+
} from "./index-qncw9hey.js";
|
|
74
74
|
import {
|
|
75
75
|
openCodeDbExists,
|
|
76
76
|
withReadOnlySessionDb,
|
|
77
77
|
getRawSessionMessageCountFromDb,
|
|
78
78
|
getMessageTimesFromOpenCodeDb
|
|
79
|
-
} from "./index-
|
|
79
|
+
} from "./index-pztqab6k.js";
|
|
80
80
|
import {
|
|
81
81
|
getToolDefinitionMeasurementSignature,
|
|
82
82
|
getMeasuredToolDefinitionTokens,
|
|
83
83
|
getSessionToolDefinitionTokens
|
|
84
|
-
} from "./index-
|
|
84
|
+
} from "./index-jkanybgq.js";
|
|
85
|
+
import {
|
|
86
|
+
markHostUnservedRow,
|
|
87
|
+
isHostUnservedRow
|
|
88
|
+
} from "./index-z9zygwse.js";
|
|
85
89
|
import {
|
|
86
90
|
canonicalModelIdentity,
|
|
87
91
|
piModelRefToCanonical
|
|
88
92
|
} from "./index-avwt563y.js";
|
|
89
93
|
import {
|
|
90
94
|
logSlowWriteTransaction
|
|
91
|
-
} from "./index-
|
|
95
|
+
} from "./index-fxbk7gk3.js";
|
|
92
96
|
|
|
93
97
|
// src/shared/hidden-zen-read.ts
|
|
94
98
|
function isToolFreeHiddenAgent(agent) {
|
|
@@ -556,92 +560,22 @@ function askAnswerLines(text) {
|
|
|
556
560
|
return extractAskAnswerNotices(text).map(formatAskAnswerNotice);
|
|
557
561
|
}
|
|
558
562
|
|
|
559
|
-
// src/hooks/magic-context/
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
value: true,
|
|
564
|
-
enumerable: false,
|
|
565
|
-
configurable: true
|
|
566
|
-
});
|
|
567
|
-
return target;
|
|
568
|
-
}
|
|
569
|
-
function isHostUnservedRow(value) {
|
|
570
|
-
return typeof value === "object" && value !== null && value[HOST_UNSERVED_ROW] === true;
|
|
571
|
-
}
|
|
572
|
-
function retreatPastHostUnservedRows(messages, exclusiveEnd, floor) {
|
|
573
|
-
if (!messages.some(isHostUnservedRow))
|
|
574
|
-
return exclusiveEnd;
|
|
575
|
-
const byOrdinal = new Map(messages.map((message) => [message.ordinal, message]));
|
|
576
|
-
let end = exclusiveEnd;
|
|
577
|
-
while (end - 1 >= floor && isHostUnservedRow(byOrdinal.get(end - 1)))
|
|
578
|
-
end -= 1;
|
|
579
|
-
return end;
|
|
580
|
-
}
|
|
581
|
-
function snapTerminalCompartmentToServedRow(compartments, lines) {
|
|
582
|
-
if (!lines.some(isHostUnservedRow))
|
|
583
|
-
return { compartments: [...compartments], snapped: false };
|
|
584
|
-
const byOrdinal = new Map(lines.map((line) => [line.ordinal, line]));
|
|
585
|
-
const result = [...compartments];
|
|
586
|
-
let snapped = false;
|
|
587
|
-
while (result.length > 0) {
|
|
588
|
-
const last = result[result.length - 1];
|
|
589
|
-
if (!isHostUnservedRow(byOrdinal.get(last.endMessage)))
|
|
590
|
-
break;
|
|
591
|
-
snapped = true;
|
|
592
|
-
let served;
|
|
593
|
-
for (let ordinal = last.endMessage - 1;ordinal >= last.startMessage; ordinal -= 1) {
|
|
594
|
-
const line = byOrdinal.get(ordinal);
|
|
595
|
-
if (line && !isHostUnservedRow(line)) {
|
|
596
|
-
served = line;
|
|
597
|
-
break;
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
if (!served) {
|
|
601
|
-
result.pop();
|
|
602
|
-
continue;
|
|
603
|
-
}
|
|
604
|
-
result[result.length - 1] = {
|
|
605
|
-
...last,
|
|
606
|
-
endMessage: served.ordinal,
|
|
607
|
-
endMessageId: served.messageId
|
|
608
|
-
};
|
|
609
|
-
break;
|
|
563
|
+
// src/hooks/magic-context/compartment-commit-hashes.ts
|
|
564
|
+
function rawCommitHashes(value) {
|
|
565
|
+
if (typeof value === "string") {
|
|
566
|
+
return Array.from(value.matchAll(/\b[0-9a-f]{7,40}\b/gi), (match) => match[0].toLowerCase());
|
|
610
567
|
}
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
enumerable: false,
|
|
622
|
-
configurable: true
|
|
623
|
-
});
|
|
624
|
-
return target;
|
|
625
|
-
}
|
|
626
|
-
function isCoveredInstructionRow(value) {
|
|
627
|
-
return typeof value === "object" && value !== null && value[COVERED_INSTRUCTION_ROW] === true;
|
|
628
|
-
}
|
|
629
|
-
function takeCoveredInstructionRows(messages) {
|
|
630
|
-
const taken = messages.filter((message) => isCoveredInstructionRow(message.info));
|
|
631
|
-
if (taken.length > 0) {
|
|
632
|
-
const kept = messages.filter((message) => !isCoveredInstructionRow(message.info));
|
|
633
|
-
messages.splice(0, messages.length, ...kept);
|
|
634
|
-
}
|
|
635
|
-
return taken;
|
|
636
|
-
}
|
|
637
|
-
function cloneKeepingCoveredInstructionMarks(messages) {
|
|
638
|
-
const copy = structuredClone(messages);
|
|
639
|
-
messages.forEach((message, index) => {
|
|
640
|
-
const copied = copy[index];
|
|
641
|
-
if (copied && isCoveredInstructionRow(message.info))
|
|
642
|
-
markCoveredInstructionRow(copied.info);
|
|
568
|
+
if (value === null || typeof value !== "object")
|
|
569
|
+
return [];
|
|
570
|
+
return Object.values(value).flatMap(rawCommitHashes);
|
|
571
|
+
}
|
|
572
|
+
function removeUnsupportedCommitHashes(text, supported) {
|
|
573
|
+
return text.replace(/`?\b([0-9a-f]{7,40})\b`?/gi, (token, hash) => {
|
|
574
|
+
const normalized = hash.toLowerCase();
|
|
575
|
+
if (!/[a-f]/.test(normalized))
|
|
576
|
+
return token;
|
|
577
|
+
return Array.from(supported).some((source) => source.startsWith(normalized)) ? token : "";
|
|
643
578
|
});
|
|
644
|
-
return copy;
|
|
645
579
|
}
|
|
646
580
|
|
|
647
581
|
// src/hooks/magic-context/read-session-true-raw-tokens.ts
|
|
@@ -1362,6 +1296,78 @@ function applyEditMarkerToInput(input) {
|
|
|
1362
1296
|
}
|
|
1363
1297
|
}
|
|
1364
1298
|
|
|
1299
|
+
// src/hooks/magic-context/final-wire-completeness.ts
|
|
1300
|
+
function incompleteWirePartFields(part) {
|
|
1301
|
+
if (!part || typeof part !== "object")
|
|
1302
|
+
return ["part"];
|
|
1303
|
+
const p = part;
|
|
1304
|
+
if (p.ignored === true)
|
|
1305
|
+
return [];
|
|
1306
|
+
const missing = (present, field) => present ? [] : [field];
|
|
1307
|
+
switch (p.type) {
|
|
1308
|
+
case "text":
|
|
1309
|
+
case "reasoning":
|
|
1310
|
+
return missing(typeof p.text === "string", "text");
|
|
1311
|
+
case "thinking":
|
|
1312
|
+
return missing(typeof p.thinking === "string", "thinking");
|
|
1313
|
+
case "redacted_thinking":
|
|
1314
|
+
return missing(typeof p.data === "string", "data");
|
|
1315
|
+
case "tool": {
|
|
1316
|
+
const state = p.state !== null && typeof p.state === "object" ? p.state : undefined;
|
|
1317
|
+
const input = state?.input !== undefined || p.input !== undefined || p.args !== undefined;
|
|
1318
|
+
const result = state?.output !== undefined || state?.content !== undefined || state?.error !== undefined || p.output !== undefined || p.result !== undefined || p.content !== undefined;
|
|
1319
|
+
return [...missing(input, "input"), ...missing(result, "result")];
|
|
1320
|
+
}
|
|
1321
|
+
case "tool-call":
|
|
1322
|
+
case "tool_use":
|
|
1323
|
+
return missing(p.input !== undefined || p.args !== undefined, "input");
|
|
1324
|
+
case "tool-invocation":
|
|
1325
|
+
return [
|
|
1326
|
+
...missing(p.args !== undefined || p.input !== undefined, "input"),
|
|
1327
|
+
...missing(p.result !== undefined || p.output !== undefined || p.state !== null && typeof p.state === "object", "result")
|
|
1328
|
+
];
|
|
1329
|
+
case "tool-result":
|
|
1330
|
+
case "tool_result":
|
|
1331
|
+
return missing(p.result !== undefined || p.content !== undefined || p.output !== undefined, "result");
|
|
1332
|
+
case "step-start":
|
|
1333
|
+
case "step-finish":
|
|
1334
|
+
return [];
|
|
1335
|
+
case "file":
|
|
1336
|
+
return missing(typeof p.url === "string" && p.url.startsWith("data:image/"), "url (data:image/)");
|
|
1337
|
+
default:
|
|
1338
|
+
return ["supported type"];
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
function label(value) {
|
|
1342
|
+
return typeof value === "string" ? value.replace(/[^a-zA-Z0-9_.-]/g, "_").slice(0, 128) : null;
|
|
1343
|
+
}
|
|
1344
|
+
function incompleteWireParts(messages) {
|
|
1345
|
+
return messages.flatMap((message) => message.parts.flatMap((part, partIndex) => {
|
|
1346
|
+
const missingFields = incompleteWirePartFields(part);
|
|
1347
|
+
if (!missingFields.length)
|
|
1348
|
+
return [];
|
|
1349
|
+
const p = part && typeof part === "object" ? part : undefined;
|
|
1350
|
+
return [
|
|
1351
|
+
{
|
|
1352
|
+
messageId: label(message.info.id),
|
|
1353
|
+
partId: label(p?.id),
|
|
1354
|
+
partIndex,
|
|
1355
|
+
type: label(p?.type) ?? "unknown",
|
|
1356
|
+
missingFields
|
|
1357
|
+
}
|
|
1358
|
+
];
|
|
1359
|
+
}));
|
|
1360
|
+
}
|
|
1361
|
+
function createFinalWireIncompleteLogger(sessionID) {
|
|
1362
|
+
let logged = false;
|
|
1363
|
+
return (estimate, messages) => {
|
|
1364
|
+
if (logged || estimate?.trusted)
|
|
1365
|
+
return;
|
|
1366
|
+
logged = true;
|
|
1367
|
+
sessionLog2(sessionID, `transform: final-wire untrusted incompleteParts=${JSON.stringify(incompleteWireParts(messages))}`);
|
|
1368
|
+
};
|
|
1369
|
+
}
|
|
1370
|
+
|
|
1365
1371
|
// src/features/magic-context/merged-reasoning-decisions.ts
|
|
1366
1372
|
var MERGED_REASONING_PARTS_PREFIX = "__merged_reasoning_parts_v1__:";
|
|
1367
1373
|
var decodedDecisions = new Map;
|
|
@@ -3649,7 +3655,11 @@ function parsePersistedCompactionMarkerState(raw, storedTargetEndMessageId) {
|
|
|
3649
3655
|
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") {
|
|
3650
3656
|
const targetEndMessageId = typeof storedTargetEndMessageId === "string" && storedTargetEndMessageId.length > 0 ? storedTargetEndMessageId : typeof parsed.targetEndMessageId === "string" && parsed.targetEndMessageId.length > 0 ? parsed.targetEndMessageId : null;
|
|
3651
3657
|
return {
|
|
3652
|
-
|
|
3658
|
+
boundaryMessageId: parsed.boundaryMessageId,
|
|
3659
|
+
summaryMessageId: parsed.summaryMessageId,
|
|
3660
|
+
compactionPartId: parsed.compactionPartId,
|
|
3661
|
+
summaryPartId: parsed.summaryPartId,
|
|
3662
|
+
boundaryOrdinal: parsed.boundaryOrdinal,
|
|
3653
3663
|
targetEndMessageId
|
|
3654
3664
|
};
|
|
3655
3665
|
}
|
|
@@ -3660,6 +3670,34 @@ function getPersistedCompactionMarkerState(db, sessionId) {
|
|
|
3660
3670
|
const row = db.prepare("SELECT compaction_marker_state, compaction_marker_target_end_message_id FROM session_meta WHERE session_id = ?").get(sessionId);
|
|
3661
3671
|
return parsePersistedCompactionMarkerState(row?.compaction_marker_state, row?.compaction_marker_target_end_message_id);
|
|
3662
3672
|
}
|
|
3673
|
+
function getCompactionMarkerPublicationState(db, sessionId) {
|
|
3674
|
+
const row = db.prepare("SELECT compaction_marker_state FROM session_meta WHERE session_id = ?").get(sessionId);
|
|
3675
|
+
const raw = row?.compaction_marker_state ?? "";
|
|
3676
|
+
let pending = null;
|
|
3677
|
+
try {
|
|
3678
|
+
pending = parsePersistedCompactionMarkerState(JSON.stringify(JSON.parse(raw).pending));
|
|
3679
|
+
} catch {}
|
|
3680
|
+
return { raw, pending };
|
|
3681
|
+
}
|
|
3682
|
+
function compareAndSetCompactionMarkerPublicationState(db, sessionId, expectedRaw, state, pending) {
|
|
3683
|
+
return db.transaction(() => {
|
|
3684
|
+
ensureSessionMetaRow(db, sessionId);
|
|
3685
|
+
let envelope = {};
|
|
3686
|
+
if (pending) {
|
|
3687
|
+
try {
|
|
3688
|
+
const parsed = JSON.parse(expectedRaw);
|
|
3689
|
+
if (parsed && typeof parsed === "object")
|
|
3690
|
+
envelope = parsed;
|
|
3691
|
+
} catch {}
|
|
3692
|
+
}
|
|
3693
|
+
const raw = JSON.stringify(pending ? { ...envelope, pending } : state);
|
|
3694
|
+
const result = db.prepare(`UPDATE session_meta SET compaction_marker_state = ?, compaction_marker_target_end_message_id = ?
|
|
3695
|
+
WHERE session_id = ? AND COALESCE(compaction_marker_state, '') = ?`).run(raw, state?.targetEndMessageId ?? null, sessionId, expectedRaw);
|
|
3696
|
+
if (result.changes !== 1)
|
|
3697
|
+
throw new Error("marker publication state changed concurrently");
|
|
3698
|
+
return raw;
|
|
3699
|
+
}).immediate();
|
|
3700
|
+
}
|
|
3663
3701
|
function setPersistedCompactionMarkerState(db, sessionId, state) {
|
|
3664
3702
|
db.transaction(() => {
|
|
3665
3703
|
ensureSessionMetaRow(db, sessionId);
|
|
@@ -6077,45 +6115,7 @@ function estimateAppendedWireTokens(input) {
|
|
|
6077
6115
|
};
|
|
6078
6116
|
}
|
|
6079
6117
|
function hasCountableParts(message) {
|
|
6080
|
-
return message.parts.every((part) =>
|
|
6081
|
-
if (!part || typeof part !== "object")
|
|
6082
|
-
return false;
|
|
6083
|
-
const p = part;
|
|
6084
|
-
if (p.ignored === true)
|
|
6085
|
-
return true;
|
|
6086
|
-
switch (p.type) {
|
|
6087
|
-
case "text":
|
|
6088
|
-
case "reasoning":
|
|
6089
|
-
return typeof p.text === "string";
|
|
6090
|
-
case "thinking":
|
|
6091
|
-
return typeof p.thinking === "string";
|
|
6092
|
-
case "redacted_thinking":
|
|
6093
|
-
return typeof p.data === "string";
|
|
6094
|
-
case "tool": {
|
|
6095
|
-
const state = p.state !== null && typeof p.state === "object" ? p.state : undefined;
|
|
6096
|
-
const hasInput = state?.input !== undefined || p.input !== undefined || p.args !== undefined;
|
|
6097
|
-
const hasResult = state?.output !== undefined || state?.content !== undefined || state?.error !== undefined || p.output !== undefined || p.result !== undefined || p.content !== undefined;
|
|
6098
|
-
return hasInput && hasResult;
|
|
6099
|
-
}
|
|
6100
|
-
case "tool-call":
|
|
6101
|
-
return p.input !== undefined || p.args !== undefined;
|
|
6102
|
-
case "tool-invocation":
|
|
6103
|
-
return (p.args !== undefined || p.input !== undefined) && (p.result !== undefined || p.output !== undefined || p.state !== null && typeof p.state === "object");
|
|
6104
|
-
case "tool-result":
|
|
6105
|
-
return p.result !== undefined || p.content !== undefined || p.output !== undefined;
|
|
6106
|
-
case "tool_use":
|
|
6107
|
-
return p.input !== undefined || p.args !== undefined;
|
|
6108
|
-
case "tool_result":
|
|
6109
|
-
return p.content !== undefined || p.result !== undefined || p.output !== undefined;
|
|
6110
|
-
case "step-start":
|
|
6111
|
-
case "step-finish":
|
|
6112
|
-
return true;
|
|
6113
|
-
case "file":
|
|
6114
|
-
return typeof p.url === "string" && p.url.startsWith("data:image/");
|
|
6115
|
-
default:
|
|
6116
|
-
return false;
|
|
6117
|
-
}
|
|
6118
|
-
});
|
|
6118
|
+
return message.parts.every((part) => incompleteWirePartFields(part).length === 0);
|
|
6119
6119
|
}
|
|
6120
6120
|
|
|
6121
6121
|
// src/hooks/magic-context/tool-input-size.ts
|
|
@@ -6624,6 +6624,13 @@ function resolveHostServedBoundaryId2(sessionId, messageId) {
|
|
|
6624
6624
|
function hasRawMessageProvider2(sessionId) {
|
|
6625
6625
|
return sessionProviders.has(sessionId);
|
|
6626
6626
|
}
|
|
6627
|
+
function rawMessageWorkerSource2(sessionId) {
|
|
6628
|
+
return sessionProviders.get(sessionId)?.provider.workerSource;
|
|
6629
|
+
}
|
|
6630
|
+
function rawMessageOffThreadRangeReader2(sessionId) {
|
|
6631
|
+
const provider = sessionProviders.get(sessionId)?.provider;
|
|
6632
|
+
return provider?.readMessageIdOrdinalsForRangeOffThread?.bind(provider);
|
|
6633
|
+
}
|
|
6627
6634
|
function setRawMessageProvider2(sessionId, provider) {
|
|
6628
6635
|
const current = sessionProviders.get(sessionId);
|
|
6629
6636
|
const registration = current?.provider === provider ? current : { provider, scopes: 0 };
|
|
@@ -7410,7 +7417,12 @@ function readSessionChunk2(sessionId, tokenBudget, offset = 1, eligibleEndOrdina
|
|
|
7410
7417
|
}
|
|
7411
7418
|
if (msg.ordinal < startOrdinal)
|
|
7412
7419
|
continue;
|
|
7413
|
-
const
|
|
7420
|
+
const commitHashes = rawCommitHashes(msg.parts);
|
|
7421
|
+
const meta = {
|
|
7422
|
+
ordinal: msg.ordinal,
|
|
7423
|
+
messageId: msg.id
|
|
7424
|
+
};
|
|
7425
|
+
Object.defineProperty(meta, "commitHashes", { value: commitHashes });
|
|
7414
7426
|
if (isHostUnservedRow(msg))
|
|
7415
7427
|
markHostUnservedRow(meta);
|
|
7416
7428
|
if (msg.role === "system") {
|
|
@@ -7588,4 +7600,4 @@ function readRawSessionSeedTail2(sessionId, boundaryId, onQuery) {
|
|
|
7588
7600
|
});
|
|
7589
7601
|
}
|
|
7590
7602
|
|
|
7591
|
-
export { isToolFreeHiddenAgent, TOOL_USE_DISABLED, ZEN_READ_AGENT_SUFFIX, needsBlockedRead, withBlockedReadInstruction, rememberV1HiddenRun, shapeV1HiddenMessage, expandToolPart, askAnswerLines,
|
|
7603
|
+
export { isToolFreeHiddenAgent, TOOL_USE_DISABLED, ZEN_READ_AGENT_SUFFIX, needsBlockedRead, withBlockedReadInstruction, rememberV1HiddenRun, shapeV1HiddenMessage, expandToolPart, askAnswerLines, removeUnsupportedCommitHashes, completedToolArcCrossesBoundary, estimateTrueRawMessageTokens, buildToolArcs, fenceBoundaryForCompletedToolArcs, fenceBoundaryForToolArcs, buildTrueRawTokenIndex, computeRawRangeFingerprint, invalidateTrueRawTokenCache, stripSystemInjection, isTextPart, isToolPartWithOutput, isFilePart, toolPartHasUserAnswer, DreamTokenBudgetExceeded, TOKEN_BUDGET_FINALIZE_MESSAGE, registerBudgetFinalizeChild, releaseBudgetFinalizeChild, createDreamTokenBudget, recordToolParameters, createDroppedInputGuard, assertExecutableToolInput, createDroppedInputToolExecuteBeforeHook, 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, getPersistedReasoningWatermark, setPersistedReasoningWatermark, clearPersistedReasoningWatermark, getEmergencyInputSample, setEmergencyDropSample, clearEmergencyDropSample, getLastNudgeUndropped, setLastNudgeUndropped, getChannel1NudgeState, setChannel1NudgeState, markChannel1PostReduceGracePending, captureChannel1PostReduceGraceBaseline, getChannel2NudgeState, getChannel2NudgeClaim, setChannel2NudgeState, casChannel2NudgeState, claimChannel2NudgeState, casChannel2NudgeClaim, getPersistedNoteNudge, setPersistedNoteNudgeTrigger, setPersistedNoteNudgeTriggerMessageId, getNoteNudgeAnchors, getAutoSearchHintDecisions, deliverNoteNudgeAtomic, appendAutoSearchHintDecision, pruneNoteNudgeAnchors, removeNoteNudgeAnchorByMessageId, queueAutoSearchHintDecisionRetirement, flushAutoSearchHintDecisionRetirement, removeAutoSearchHintDecisionByMessageId, 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, removeStrippedPlaceholderId, THINKING_BINDING_RECOVERY_FROZEN_PREFIX, THINKING_BINDING_STRIP_ORDER_END_MARKER, thinkingBindingRecoveryFrozenId, COMPACTION_OFF_THINKING_FROZEN_PREFIX, compactionOffThinkingFrozenId, compactionOffFrozenThinkingIds, getThinkingBindingRecoveryTarget, armThinkingBindingRecovery, clearThinkingBindingRecoveryIf, getMergedReasoningStrippedIds, addMergedReasoningStrippedIds, getTrailingBlankDecisions, addTrailingBlankDecisions, demoteTrailingBlankKeepDecisions, getStaleReduceStrippedIds, addStaleReduceStrippedIds, getProcessedImageStrippedIds, parseProcessedImageMarkers, serializeProcessedImageMarkers, getProcessedImageMarkers, addProcessedImageStrippedIds, getPendingCompactionMarkerState, getCompactionMarkerHealth, loadPostprocessReplaySnapshot, setPendingCompactionMarkerState, replacePendingCompactionMarkerStateIf, clearPendingCompactionMarkerStateIf, getPendingPiCompactionMarkerState, clearPendingPiCompactionMarkerStateIf, logPiCompactionMarkerClear, getSessionsWithPendingMarker, setSessionWorkMetrics, getObservedEpochFloor, resolveEpochFloorForPass, getReasoningRemovalState, addRemovedReasoningIds, markDropLeavesReasoning, detectThinkingBindingMismatch, 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,194 @@
|
|
|
1
|
+
import {
|
|
2
|
+
registerExitAbort
|
|
3
|
+
} from "./index-v0p37hm2.js";
|
|
4
|
+
import {
|
|
5
|
+
inRootAsyncContext2
|
|
6
|
+
} from "./index-gzy5w8ya.js";
|
|
7
|
+
import {
|
|
8
|
+
createWorkerShutdown
|
|
9
|
+
} from "./index-cpjk5jd2.js";
|
|
10
|
+
|
|
11
|
+
// src/tools/ctx-expand/v2-archive-reader.ts
|
|
12
|
+
import { Worker } from "node:worker_threads";
|
|
13
|
+
var worker;
|
|
14
|
+
var shutdown;
|
|
15
|
+
var ready;
|
|
16
|
+
var idle;
|
|
17
|
+
var startingTimer;
|
|
18
|
+
var rejectStart;
|
|
19
|
+
var nextId = 0;
|
|
20
|
+
var exitRegistered = false;
|
|
21
|
+
var pending = new Map;
|
|
22
|
+
async function stopV2ArchiveReader() {
|
|
23
|
+
const closing = shutdown;
|
|
24
|
+
worker = undefined;
|
|
25
|
+
shutdown = undefined;
|
|
26
|
+
ready = undefined;
|
|
27
|
+
clearTimeout(idle);
|
|
28
|
+
clearTimeout(startingTimer);
|
|
29
|
+
rejectStart?.(new Error("Search archive worker unavailable: reader stopped"));
|
|
30
|
+
rejectStart = undefined;
|
|
31
|
+
for (const item of pending.values()) {
|
|
32
|
+
clearTimeout(item.timer);
|
|
33
|
+
item.reject(new Error("Search archive worker unavailable: reader stopped"));
|
|
34
|
+
}
|
|
35
|
+
pending.clear();
|
|
36
|
+
await closing?.close();
|
|
37
|
+
}
|
|
38
|
+
function start() {
|
|
39
|
+
if (ready)
|
|
40
|
+
return ready;
|
|
41
|
+
if (!exitRegistered) {
|
|
42
|
+
exitRegistered = true;
|
|
43
|
+
const controller = new AbortController;
|
|
44
|
+
controller.signal.addEventListener("abort", () => {
|
|
45
|
+
stopV2ArchiveReader();
|
|
46
|
+
}, { once: true });
|
|
47
|
+
registerExitAbort(controller);
|
|
48
|
+
}
|
|
49
|
+
ready = new Promise((resolve, reject) => {
|
|
50
|
+
rejectStart = reject;
|
|
51
|
+
const entry = new URL(import.meta.url.endsWith(".ts") ? "../../hooks/magic-context/raw-ordinal-warmup-worker.ts" : "./raw-ordinal-warmup-worker.js", import.meta.url);
|
|
52
|
+
const current = inRootAsyncContext2(() => new Worker(entry, { workerData: { v2ArchiveReader: true } }));
|
|
53
|
+
worker = current;
|
|
54
|
+
shutdown = createWorkerShutdown(current, "v2-archive-reader", 2000);
|
|
55
|
+
current.unref();
|
|
56
|
+
const fail = (detail) => {
|
|
57
|
+
if (worker !== current)
|
|
58
|
+
return;
|
|
59
|
+
clearTimeout(startingTimer);
|
|
60
|
+
reject(new Error(`Search archive worker unavailable: ${detail}`));
|
|
61
|
+
stopV2ArchiveReader();
|
|
62
|
+
};
|
|
63
|
+
startingTimer = setTimeout(() => fail("reader did not start"), 1e4);
|
|
64
|
+
startingTimer.unref?.();
|
|
65
|
+
current.on("error", (error) => fail(String(error)));
|
|
66
|
+
current.on("exit", (code) => fail(`exit code ${code}`));
|
|
67
|
+
current.on("message", (reply) => {
|
|
68
|
+
if (worker !== current)
|
|
69
|
+
return;
|
|
70
|
+
if (reply.kind === "v2-archive-ready") {
|
|
71
|
+
clearTimeout(startingTimer);
|
|
72
|
+
rejectStart = undefined;
|
|
73
|
+
resolve();
|
|
74
|
+
} else if (reply.kind === "v2-archive-result") {
|
|
75
|
+
const item = pending.get(reply.id);
|
|
76
|
+
if (!item)
|
|
77
|
+
return;
|
|
78
|
+
pending.delete(reply.id);
|
|
79
|
+
clearTimeout(item.timer);
|
|
80
|
+
if (reply.error)
|
|
81
|
+
item.reject(new Error(`Search archive worker unavailable: ${reply.error}`));
|
|
82
|
+
else
|
|
83
|
+
item.resolve(reply.text);
|
|
84
|
+
if (pending.size === 0) {
|
|
85
|
+
idle = setTimeout(() => {
|
|
86
|
+
stopV2ArchiveReader();
|
|
87
|
+
}, 60000);
|
|
88
|
+
idle.unref?.();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
return ready;
|
|
94
|
+
}
|
|
95
|
+
async function readV2ArchiveOffThread2(path, rawPath, sessionId, read) {
|
|
96
|
+
try {
|
|
97
|
+
clearTimeout(idle);
|
|
98
|
+
await start();
|
|
99
|
+
const current = worker;
|
|
100
|
+
if (!current)
|
|
101
|
+
throw new Error("Search archive worker unavailable: reader stopped");
|
|
102
|
+
return await new Promise((resolve, reject) => {
|
|
103
|
+
const id = ++nextId;
|
|
104
|
+
const timer = setTimeout(() => {
|
|
105
|
+
stopV2ArchiveReader();
|
|
106
|
+
}, 10 * 60000);
|
|
107
|
+
timer.unref?.();
|
|
108
|
+
pending.set(id, { resolve, reject, timer });
|
|
109
|
+
try {
|
|
110
|
+
current.postMessage({
|
|
111
|
+
kind: "v2-archive-read",
|
|
112
|
+
id,
|
|
113
|
+
path,
|
|
114
|
+
rawPath,
|
|
115
|
+
sessionId,
|
|
116
|
+
read
|
|
117
|
+
});
|
|
118
|
+
} catch {
|
|
119
|
+
stopV2ArchiveReader();
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
} catch (error) {
|
|
123
|
+
await stopV2ArchiveReader();
|
|
124
|
+
if (error instanceof Error && error.message.startsWith("Search archive worker unavailable:"))
|
|
125
|
+
throw error;
|
|
126
|
+
throw new Error(`Search archive worker unavailable: ${String(error)}`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
async function serveV2ArchiveReads2(port, openConnections) {
|
|
130
|
+
const [
|
|
131
|
+
{ Database },
|
|
132
|
+
{ V2StoreReaderPool },
|
|
133
|
+
{ createV2RawMessageReader, createV2RawMessageProvider },
|
|
134
|
+
{ setBoundedRawMessageProvider },
|
|
135
|
+
{ renderItemByTag, renderMessageByOrdinal, renderVerboseRangeForTool },
|
|
136
|
+
{ renderSearchArchive },
|
|
137
|
+
{ createV2RecoveryAttachments }
|
|
138
|
+
] = await Promise.all([
|
|
139
|
+
import("./sqlite-zdgm52sv.js"),
|
|
140
|
+
import("./store-reader-yh19h38c.js"),
|
|
141
|
+
import("./store-620rjzt9.js"),
|
|
142
|
+
import("./read-session-chunk-vmg1zjg0.js"),
|
|
143
|
+
import("./render-c5p0k846.js"),
|
|
144
|
+
import("./search-archive-0ny7p3bw.js"),
|
|
145
|
+
import("./expand-attachments-h33jbgyz.js")
|
|
146
|
+
]);
|
|
147
|
+
const pool = new V2StoreReaderPool;
|
|
148
|
+
openConnections.add(pool);
|
|
149
|
+
port.on("message", (request) => {
|
|
150
|
+
if (request.kind !== "v2-archive-read")
|
|
151
|
+
return;
|
|
152
|
+
let db;
|
|
153
|
+
let unregister;
|
|
154
|
+
let rawReader;
|
|
155
|
+
let reply;
|
|
156
|
+
try {
|
|
157
|
+
db = new Database(request.path, { readonly: true, fileMustExist: true });
|
|
158
|
+
openConnections.add(db);
|
|
159
|
+
db.exec("PRAGMA busy_timeout = 250");
|
|
160
|
+
const raw = pool.open(request.rawPath);
|
|
161
|
+
rawReader = raw;
|
|
162
|
+
const reader = createV2RawMessageReader(() => raw, undefined, () => {});
|
|
163
|
+
const attachments = createV2RecoveryAttachments(raw);
|
|
164
|
+
unregister = setBoundedRawMessageProvider(request.sessionId, createV2RawMessageProvider(reader, request.sessionId));
|
|
165
|
+
const read = request.read;
|
|
166
|
+
let text;
|
|
167
|
+
if (read.kind === "tag") {
|
|
168
|
+
text = renderItemByTag(db, request.sessionId, read.tag, "part", attachments);
|
|
169
|
+
} else {
|
|
170
|
+
const start = read.kind === "message" ? read.message : read.start;
|
|
171
|
+
const end = read.kind === "message" ? read.message : read.end;
|
|
172
|
+
text = renderSearchArchive(db, request.sessionId, start, end, read.tokenBudget, read.kind === "archive" && read.archiveOnly, () => reader.ordinalMapForRange(request.sessionId, start, end));
|
|
173
|
+
if (text === null && read.kind === "message") {
|
|
174
|
+
text = renderMessageByOrdinal(request.sessionId, read.message, attachments);
|
|
175
|
+
} else if (text === null && read.kind === "verbose") {
|
|
176
|
+
text = renderVerboseRangeForTool(request.sessionId, start, end, read.tokenBudget, read.expandTools, attachments);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
reply = { kind: "v2-archive-result", id: request.id, text };
|
|
180
|
+
} catch (error) {
|
|
181
|
+
reply = { kind: "v2-archive-result", id: request.id, text: null, error: String(error) };
|
|
182
|
+
} finally {
|
|
183
|
+
unregister?.();
|
|
184
|
+
rawReader?.close();
|
|
185
|
+
if (db)
|
|
186
|
+
openConnections.delete(db);
|
|
187
|
+
db?.close();
|
|
188
|
+
}
|
|
189
|
+
port.postMessage(reply);
|
|
190
|
+
});
|
|
191
|
+
port.postMessage({ kind: "v2-archive-ready" });
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export { readV2ArchiveOffThread2, serveV2ArchiveReads2 };
|