@cortexkit/opencode-magic-context 0.49.92 → 0.49.95
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 +4 -4
- package/dist/chunk-embedding-write-worker.js +3 -3
- package/dist/{compartment-chunk-embedding-rp4asvk0.js → compartment-chunk-embedding-4nn3hsw2.js} +2 -2
- package/dist/{context-e8qd2v00.js → context-h9x9m2p3.js} +192 -68
- package/dist/{embedding-backfill-w0yq71q2.js → embedding-backfill-wdrqkw09.js} +6 -6
- package/dist/embedding-worker.js +3 -3
- package/dist/features/magic-context/compartment-storage.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/docs-proposals.d.ts +5 -2
- package/dist/features/magic-context/dreamer/docs-proposals.d.ts.map +1 -1
- package/dist/features/magic-context/history-gap-recovery.d.ts +42 -0
- package/dist/features/magic-context/history-gap-recovery.d.ts.map +1 -0
- package/dist/features/magic-context/memory/embedding-local.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding-synapse.d.ts +18 -5
- package/dist/features/magic-context/memory/embedding-synapse.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding-worker-client.d.ts +3 -0
- package/dist/features/magic-context/memory/embedding-worker-client.d.ts.map +1 -1
- package/dist/features/magic-context/message-visibility.d.ts +10 -0
- package/dist/features/magic-context/message-visibility.d.ts.map +1 -0
- 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/session-decision-calibration.d.ts.map +1 -1
- package/dist/features/magic-context/session-project-backfill.d.ts.map +1 -1
- package/dist/features/magic-context/store-generation-rebase.d.ts.map +1 -1
- package/dist/features/magic-context/transform-decision-log.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-recomp.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-trigger.d.ts +1 -1
- package/dist/hooks/magic-context/compartment-trigger.d.ts.map +1 -1
- package/dist/hooks/magic-context/history-boundary-repair.d.ts +2 -2
- package/dist/hooks/magic-context/history-boundary-repair.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-measured-request.d.ts +1 -0
- package/dist/hooks/magic-context/lkg-measured-request.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-persist.d.ts +3 -1
- package/dist/hooks/magic-context/lkg-persist.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-recovery-fence.d.ts +1 -0
- package/dist/hooks/magic-context/lkg-recovery-fence.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-replay.d.ts +4 -0
- package/dist/hooks/magic-context/lkg-replay.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/tail-hygiene-output-count.d.ts +4 -0
- package/dist/hooks/magic-context/tail-hygiene-output-count.d.ts.map +1 -1
- package/dist/hooks/magic-context/tail-hygiene-walk.d.ts +2 -0
- package/dist/hooks/magic-context/tail-hygiene-walk.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-stage-logger.d.ts +6 -0
- package/dist/hooks/magic-context/transform-stage-logger.d.ts.map +1 -1
- package/dist/{index-3f3d548g.js → index-2gewejcz.js} +18 -9
- package/dist/{index-n71006wq.js → index-2v9qpmb3.js} +5 -5
- package/dist/{index-zzhcshdk.js → index-3tmbvn0z.js} +9 -9
- package/dist/{index-f25ha337.js → index-3ywyr4zx.js} +1 -1
- package/dist/{index-hbn5g7rt.js → index-47hst5me.js} +1 -1
- package/dist/{index-xg1zjht5.js → index-7dzaamqg.js} +6 -6
- package/dist/{index-5y9w2ax7.js → index-7r11k4xr.js} +2 -2
- package/dist/{index-5pmf4jpj.js → index-7skgrbsg.js} +100 -52
- package/dist/{index-6rk44cer.js → index-c81tggen.js} +1 -1
- package/dist/{index-0twg41mh.js → index-ejgp0z9p.js} +1 -1
- package/dist/{index-hre29c1a.js → index-esacb9d0.js} +1 -1
- package/dist/{index-5a9kwapd.js → index-ewta5h87.js} +4 -4
- package/dist/{index-6r99v53h.js → index-j7n64sg4.js} +162 -60
- package/dist/{index-r3tdqqtq.js → index-jm62g83a.js} +180 -64
- package/dist/{index-anwy2mfb.js → index-pc49a7zt.js} +162 -31
- package/dist/{index-ydhymf0b.js → index-qmm8xpbc.js} +4 -4
- package/dist/{index-3n376ann.js → index-tedck05r.js} +4 -4
- package/dist/{index-j2w79s9r.js → index-tm799pq7.js} +1 -1
- package/dist/{index-01h7tqe3.js → index-tr4ep2ej.js} +21 -6
- package/dist/{index-wvbg9m0h.js → index-wqwjawer.js} +27 -11
- package/dist/index-xe34pwb6.js +119 -0
- package/dist/{index-xn9efn18.js → index-xjaf9g90.js} +13 -6
- package/dist/{index-6nqz8hsz.js → index-y915t3ey.js} +1 -1
- package/dist/{index-41bma6qs.js → index-yzzxb5e1.js} +2 -2
- package/dist/{index-901exj0f.js → index-zk6gtf43.js} +45 -9
- package/dist/index.js +27 -27
- package/dist/{message-index-bounded-f6fc00ze.js → message-index-bounded-d3x8rhpz.js} +4 -4
- package/dist/migration-worker.js +1 -1
- package/dist/{project-embedding-registry-8je0xg18.js → project-embedding-registry-az68q792.js} +5 -5
- package/dist/raw-ordinal-warmup-worker.js +5 -5
- package/dist/{read-session-chunk-y2ew3630.js → read-session-chunk-70r1snq3.js} +3 -3
- package/dist/{recomp-orchestrator-ggtcvb9g.js → recomp-orchestrator-cn4r2gz6.js} +15 -15
- package/dist/{render-q8c6wrq9.js → render-g45k3gts.js} +10 -10
- package/dist/{search-archive-pz1jf655.js → search-archive-s9t3exc1.js} +9 -7
- package/dist/{search-gjyrwapc.js → search-b0cb342r.js} +13 -13
- package/dist/shared/storage-file-mutex.d.ts.map +1 -1
- package/dist/{storage-tags-7raphcw6.js → storage-tags-xvbje7jm.js} +2 -2
- package/dist/{store-yr443ye8.js → store-91kawq9a.js} +2 -2
- package/dist/{store-reader-qbq6q4v0.js → store-reader-dgh3ssxx.js} +1 -1
- package/dist/tools/ctx-expand/search-archive.d.ts +3 -2
- package/dist/tools/ctx-expand/search-archive.d.ts.map +1 -1
- package/dist/tools/ctx-expand/tools.d.ts.map +1 -1
- package/dist/tools/ctx-expand/v2-archive-reader.d.ts +2 -0
- package/dist/tools/ctx-expand/v2-archive-reader.d.ts.map +1 -1
- package/dist/tools/ctx-search/tools.d.ts.map +1 -1
- package/dist/{transform-postprocess-phase-pmzdd3s2.js → transform-postprocess-phase-r1xhsjrh.js} +16 -16
- package/dist/v2/auto-search-worker.js +4 -4
- package/dist/v2/chunk-embedding-write-worker.js +3 -3
- package/dist/v2/{compartment-chunk-embedding-w7ht0t9v.js → compartment-chunk-embedding-a7ddvz7v.js} +2 -2
- package/dist/v2/{context-qqbpzk1q.js → context-2hssw26q.js} +351 -111
- package/dist/v2/{embedding-backfill-95m72gxa.js → embedding-backfill-gveter8p.js} +6 -6
- package/dist/v2/embedding-worker.js +3 -3
- package/dist/v2/fold/memory-cache.d.ts +2 -0
- package/dist/v2/fold/memory-cache.d.ts.map +1 -1
- package/dist/v2/fold/native-replay.d.ts +22 -5
- package/dist/v2/fold/native-replay.d.ts.map +1 -1
- package/dist/v2/hooks/context.d.ts.map +1 -1
- package/dist/v2/hooks/revert-message-state.d.ts.map +1 -1
- package/dist/v2/hooks/session-project-backfill.d.ts +2 -1
- package/dist/v2/hooks/session-project-backfill.d.ts.map +1 -1
- package/dist/v2/{message-index-bounded-70g28hyg.js → message-index-bounded-tbwrff24.js} +4 -4
- package/dist/v2/migration-worker.js +1 -1
- package/dist/v2/{project-embedding-registry-fcxf4qht.js → project-embedding-registry-2zeycxek.js} +5 -5
- package/dist/v2/raw-ordinal-warmup-worker.js +5 -5
- package/dist/v2/{read-session-chunk-9rf0n9e6.js → read-session-chunk-cvgsfsgr.js} +3 -3
- package/dist/v2/{recomp-orchestrator-cwghhjc9.js → recomp-orchestrator-k4cj62f2.js} +15 -15
- package/dist/v2/{render-e852zmxz.js → render-ys7a3zks.js} +10 -10
- package/dist/v2/{search-archive-tmn6b5w8.js → search-archive-k2yh0jj3.js} +9 -7
- package/dist/v2/{search-jd3vczhn.js → search-x1cac8t6.js} +12 -12
- package/dist/v2/{server-vsqmkvxc.js → server-00adcfjd.js} +1 -1
- package/dist/v2/{server-rkj44mez.js → server-476anw1w.js} +1 -1
- package/dist/v2/{server-barj0mjz.js → server-5016ccyn.js} +1 -1
- package/dist/v2/{server-72k2r3kt.js → server-6aj72z52.js} +4 -4
- package/dist/v2/{server-7x5a46hf.js → server-6nh36020.js} +70 -61
- package/dist/v2/{server-fj3pekz2.js → server-88pjnecb.js} +1 -1
- package/dist/v2/{server-js2v309w.js → server-bfct1yvb.js} +99 -51
- package/dist/v2/{server-6t3asmx8.js → server-cd93xyyx.js} +162 -31
- package/dist/v2/{server-ysjjcatk.js → server-cvm1qrqc.js} +2 -2
- package/dist/v2/{server-rz6g5xne.js → server-e6xneh68.js} +1 -1
- package/dist/v2/{server-d4trxrj3.js → server-gj259dqy.js} +45 -9
- package/dist/v2/{server-8ps3717t.js → server-prrx17q3.js} +4 -4
- package/dist/v2/{server-7e89a2kf.js → server-qy58c11s.js} +13 -6
- package/dist/v2/{server-9011eteb.js → server-s81b3nct.js} +2 -2
- package/dist/v2/{server-p4g021y5.js → server-s8mk882p.js} +27 -11
- package/dist/v2/{server-mgxqfprb.js → server-srtq37nh.js} +1 -1
- package/dist/v2/{server-bvr9xs8h.js → server-vbr1rdkg.js} +6 -6
- package/dist/v2/{server-vtgeyhq6.js → server-vtkbxzw1.js} +21 -6
- package/dist/v2/{server-ps6zrzwj.js → server-xepfjgv5.js} +162 -60
- package/dist/v2/server-y0pd600x.js +119 -0
- package/dist/v2/{server-b4efn08m.js → server-zc8s06gx.js} +1 -1
- package/dist/v2/server.js +4 -4
- package/dist/v2/{storage-tags-wgsemtw1.js → storage-tags-y20j3jdp.js} +2 -2
- package/dist/v2/{store-enef5jcn.js → store-b95snz31.js} +2 -2
- package/dist/v2/{store-reader-jbaqv1yp.js → store-reader-qt2msa8z.js} +1 -1
- package/dist/v2/store-reader.d.ts +1 -1
- package/dist/v2/store-reader.d.ts.map +1 -1
- package/dist/v2/{v2-archive-reader-dm1aeqk2.js → v2-archive-reader-q92kwkr5.js} +1 -1
- package/dist/v2/{wrapup-orchestrator-cke368np.js → wrapup-orchestrator-ydqkxkhj.js} +15 -15
- package/dist/{v2-archive-reader-39ye0d3b.js → v2-archive-reader-x62hsr4c.js} +1 -1
- package/dist/{wrapup-orchestrator-ggnk0r4r.js → wrapup-orchestrator-kt81d6et.js} +16 -16
- package/package.json +1 -1
- package/src/config/schema/magic-context.ts +1 -1
- package/src/shared/storage-file-mutex-review.test.ts +110 -0
- package/src/shared/storage-file-mutex.ts +12 -0
- package/dist/index-52x68mj4.js +0 -58
- package/dist/v2/server-52x68mj4.js +0 -58
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
estimateMessageTokens,
|
|
7
7
|
getCandidateToolOwners2,
|
|
8
8
|
pickNearestPriorOwner2
|
|
9
|
-
} from "./server-
|
|
9
|
+
} from "./server-gj259dqy.js";
|
|
10
10
|
import {
|
|
11
11
|
OMO_INTERNAL_INITIATOR_MARKER,
|
|
12
12
|
isSystemDirective,
|
|
@@ -30,7 +30,7 @@ import {
|
|
|
30
30
|
} from "./server-qntmqaca.js";
|
|
31
31
|
import {
|
|
32
32
|
renderToolTemplate
|
|
33
|
-
} from "./server-
|
|
33
|
+
} from "./server-e6xneh68.js";
|
|
34
34
|
import {
|
|
35
35
|
readRawSessionMessagesFromDb2,
|
|
36
36
|
readRawSessionMessagePageFromDb2,
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
|
-
withMessageFtsSessionFilter
|
|
3
|
-
|
|
2
|
+
withMessageFtsSessionFilter,
|
|
3
|
+
liveTailRangeTouchesUnresolvedCoverage,
|
|
4
|
+
rangeHasHiddenMessages
|
|
5
|
+
} from "./server-y0pd600x.js";
|
|
4
6
|
import {
|
|
5
7
|
getSqliteDatabasePath2
|
|
6
8
|
} from "./server-gzy5w8ya.js";
|
|
@@ -19,17 +21,29 @@ import {
|
|
|
19
21
|
rawMessageWorkerSource2,
|
|
20
22
|
rawMessageOffThreadRangeReader2,
|
|
21
23
|
readRawSessionMessageIdOrdinalsForRange2
|
|
22
|
-
} from "./server-
|
|
24
|
+
} from "./server-s81b3nct.js";
|
|
23
25
|
import {
|
|
24
26
|
readV2ArchiveOffThread2
|
|
25
|
-
} from "./server-
|
|
27
|
+
} from "./server-vbr1rdkg.js";
|
|
26
28
|
|
|
27
29
|
// src/tools/ctx-expand/search-archive.ts
|
|
28
30
|
var archiveReadsOnThisThread = 0;
|
|
29
|
-
function
|
|
31
|
+
function liveTailRefusal(start, end, lastCompartmentEnd) {
|
|
32
|
+
return `Range ${start}-${end} is entirely within the live tail (after the last compacted message ${lastCompartmentEnd}); those messages are already visible in context.`;
|
|
33
|
+
}
|
|
34
|
+
function unresolvedLiveTailRefusal2(db, sessionId, start, end, lastCompartmentEnd) {
|
|
35
|
+
return liveTailRangeTouchesUnresolvedCoverage(db, sessionId, start, end, lastCompartmentEnd) ? liveTailRefusal(start, end, lastCompartmentEnd) : null;
|
|
36
|
+
}
|
|
37
|
+
function renderSearchArchive2(db, sessionId, start, end, tokenBudget, archiveOnly = false, readRawIds = () => readRawSessionMessageIdOrdinalsForRange2(sessionId, start, end), liveTailAfter) {
|
|
30
38
|
archiveReadsOnThisThread += 1;
|
|
39
|
+
let rawIds;
|
|
40
|
+
if (liveTailAfter !== undefined) {
|
|
41
|
+
rawIds = readRawIds();
|
|
42
|
+
if (!rangeHasHiddenMessages(db, sessionId, rawIds, liveTailAfter, start, end)) {
|
|
43
|
+
return liveTailRefusal(start, end, liveTailAfter);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
31
46
|
return withMessageFtsSessionFilter(db, sessionId, (sessionFirst) => {
|
|
32
|
-
let rawIds;
|
|
33
47
|
const rows = db.prepare(sessionFirst ? `SELECT f.message_ordinal AS ordinal, f.message_id AS id, f.role, f.content
|
|
34
48
|
FROM message_fts_rowid_map AS m
|
|
35
49
|
JOIN message_history_fts AS f ON f.rowid = m.fts_rowid
|
|
@@ -76,7 +90,7 @@ function renderSearchArchive2(db, sessionId, start, end, tokenBudget, archiveOnl
|
|
|
76
90
|
`);
|
|
77
91
|
});
|
|
78
92
|
}
|
|
79
|
-
async function renderSearchArchiveOffThread2(db, sessionId, start, end, tokenBudget, archiveOnly = false) {
|
|
93
|
+
async function renderSearchArchiveOffThread2(db, sessionId, start, end, tokenBudget, archiveOnly = false, liveTailAfter) {
|
|
80
94
|
const path = getSqliteDatabasePath2(db);
|
|
81
95
|
const provider = hasRawMessageProvider2(sessionId);
|
|
82
96
|
const source = rawMessageWorkerSource2(sessionId);
|
|
@@ -92,7 +106,7 @@ async function renderSearchArchiveOffThread2(db, sessionId, start, end, tokenBud
|
|
|
92
106
|
if (!path) {
|
|
93
107
|
return renderSearchArchive2(db, sessionId, start, end, tokenBudget, archiveOnly, rawIds ? () => rawIds : provider ? () => {
|
|
94
108
|
throw new Error("Search archive worker unavailable: private archive has no off-thread source");
|
|
95
|
-
} : undefined);
|
|
109
|
+
} : undefined, liveTailAfter);
|
|
96
110
|
}
|
|
97
111
|
if (!archiveOnly && source) {
|
|
98
112
|
return readV2ArchiveOffThread2(path, source.path, sessionId, {
|
|
@@ -100,7 +114,8 @@ async function renderSearchArchiveOffThread2(db, sessionId, start, end, tokenBud
|
|
|
100
114
|
start,
|
|
101
115
|
end,
|
|
102
116
|
tokenBudget,
|
|
103
|
-
archiveOnly
|
|
117
|
+
archiveOnly,
|
|
118
|
+
liveTailAfter
|
|
104
119
|
});
|
|
105
120
|
}
|
|
106
121
|
if (!archiveOnly && provider && !rawIds) {
|
|
@@ -116,7 +131,8 @@ async function renderSearchArchiveOffThread2(db, sessionId, start, end, tokenBud
|
|
|
116
131
|
tokenBudget,
|
|
117
132
|
archiveOnly,
|
|
118
133
|
rawPath,
|
|
119
|
-
rawIds: rawIds ? [...rawIds] : undefined
|
|
134
|
+
rawIds: rawIds ? [...rawIds] : undefined,
|
|
135
|
+
liveTailAfter
|
|
120
136
|
}
|
|
121
137
|
}, {});
|
|
122
138
|
if ("searchArchive" in result)
|
|
@@ -124,4 +140,4 @@ async function renderSearchArchiveOffThread2(db, sessionId, start, end, tokenBud
|
|
|
124
140
|
throw new Error(`Search archive worker unavailable: ${"failure" in result ? `${result.failure}: ${result.detail}` : "unexpected reply"}`);
|
|
125
141
|
}
|
|
126
142
|
|
|
127
|
-
export { renderSearchArchive2, renderSearchArchiveOffThread2 };
|
|
143
|
+
export { unresolvedLiveTailRefusal2, renderSearchArchive2, renderSearchArchiveOffThread2 };
|
|
@@ -137,11 +137,11 @@ async function serveV2ArchiveReads2(port, openConnections) {
|
|
|
137
137
|
{ createV2RecoveryAttachments }
|
|
138
138
|
] = await Promise.all([
|
|
139
139
|
import("./sqlite-zdgm52sv.js"),
|
|
140
|
-
import("./store-reader-
|
|
141
|
-
import("./store-
|
|
142
|
-
import("./read-session-chunk-
|
|
143
|
-
import("./render-
|
|
144
|
-
import("./search-archive-
|
|
140
|
+
import("./store-reader-qt2msa8z.js"),
|
|
141
|
+
import("./store-b95snz31.js"),
|
|
142
|
+
import("./read-session-chunk-cvgsfsgr.js"),
|
|
143
|
+
import("./render-ys7a3zks.js"),
|
|
144
|
+
import("./search-archive-k2yh0jj3.js"),
|
|
145
145
|
import("./expand-attachments-h33jbgyz.js")
|
|
146
146
|
]);
|
|
147
147
|
const pool = new V2StoreReaderPool;
|
|
@@ -169,7 +169,7 @@ async function serveV2ArchiveReads2(port, openConnections) {
|
|
|
169
169
|
} else {
|
|
170
170
|
const start = read.kind === "message" ? read.message : read.start;
|
|
171
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));
|
|
172
|
+
text = renderSearchArchive(db, request.sessionId, start, end, read.tokenBudget, read.kind === "archive" && read.archiveOnly, () => reader.ordinalMapForRange(request.sessionId, start, end), read.kind === "message" ? undefined : read.liveTailAfter);
|
|
173
173
|
if (text === null && read.kind === "message") {
|
|
174
174
|
text = renderMessageByOrdinal(request.sessionId, read.message, attachments);
|
|
175
175
|
} else if (text === null && read.kind === "verbose") {
|
|
@@ -122,16 +122,32 @@ function decode(row) {
|
|
|
122
122
|
}
|
|
123
123
|
return { ...row, data };
|
|
124
124
|
}
|
|
125
|
-
function
|
|
125
|
+
function fileIdentity(path) {
|
|
126
126
|
const stat = statSync(path);
|
|
127
|
-
|
|
127
|
+
return `${stat.dev}:${stat.ino}:${stat.birthtimeMs}`;
|
|
128
|
+
}
|
|
129
|
+
function openConfirmed(path, identity) {
|
|
128
130
|
const db = new Database2(path, { readonly: true, fileMustExist: true });
|
|
129
131
|
try {
|
|
130
|
-
|
|
132
|
+
if (fileIdentity(path) === identity) {
|
|
133
|
+
assertOpenCodeStoreGeneration(db, "v2", path);
|
|
134
|
+
return db;
|
|
135
|
+
}
|
|
131
136
|
} catch (error) {
|
|
132
137
|
db.close();
|
|
133
138
|
throw error;
|
|
134
139
|
}
|
|
140
|
+
db.close();
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
function connect(path, identity = fileIdentity(path)) {
|
|
144
|
+
let db = openConfirmed(path, identity);
|
|
145
|
+
if (!db) {
|
|
146
|
+
identity = fileIdentity(path);
|
|
147
|
+
db = openConfirmed(path, identity);
|
|
148
|
+
if (!db)
|
|
149
|
+
throw new Error("OpenCode database file changed during reader open");
|
|
150
|
+
}
|
|
135
151
|
const counters = debugCounters();
|
|
136
152
|
counters.openReaders += 1;
|
|
137
153
|
counters.readersOpened += 1;
|
|
@@ -139,7 +155,7 @@ function connect(path, identity = "") {
|
|
|
139
155
|
return {
|
|
140
156
|
db,
|
|
141
157
|
statements: new Map,
|
|
142
|
-
identity
|
|
158
|
+
identity,
|
|
143
159
|
leases: 0,
|
|
144
160
|
retired: false,
|
|
145
161
|
ordinalSequences: new Map
|
|
@@ -175,8 +191,7 @@ class V2StoreReaderPool2 {
|
|
|
175
191
|
if (this.closed)
|
|
176
192
|
throw new Error("Store reader pool is closed");
|
|
177
193
|
const key = resolve(path);
|
|
178
|
-
const
|
|
179
|
-
const identity = `${stat.dev}:${stat.ino}:${stat.birthtimeMs}`;
|
|
194
|
+
const identity = fileIdentity(key);
|
|
180
195
|
let connection = this.connections.get(key);
|
|
181
196
|
if (connection && connection.identity !== identity) {
|
|
182
197
|
this.connections.delete(key);
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
|
|
14
14
|
// src/features/magic-context/memory/embedding-synapse.ts
|
|
15
15
|
import { createHash } from "node:crypto";
|
|
16
|
+
import { setTimeout as sleep } from "node:timers/promises";
|
|
16
17
|
|
|
17
18
|
// ../../node_modules/.bun/@cortexkit+subc-client@0.11.1/node_modules/@cortexkit/subc-client/dist/client.js
|
|
18
19
|
import { promises as fs2 } from "node:fs";
|
|
@@ -1605,6 +1606,9 @@ function pendingKey(handle, corr) {
|
|
|
1605
1606
|
var SYNAPSE_DEFAULT_MODEL = "gte-modernbert-base-f16";
|
|
1606
1607
|
var SYNAPSE_DEFAULT_QUERY_TIMEOUT_MS = 3000;
|
|
1607
1608
|
var SYNAPSE_DEFAULT_BATCH_TIMEOUT_MS = 120000;
|
|
1609
|
+
var SYNAPSE_DEFAULT_POLL_TIMEOUT_MS = 5 * 60000;
|
|
1610
|
+
var SYNAPSE_INITIAL_POLL_DELAY_MS = 250;
|
|
1611
|
+
var SYNAPSE_MAX_POLL_DELAY_MS = 2000;
|
|
1608
1612
|
var SYNAPSE_CERTIFICATION_REFUSAL_REASONS = new Set([
|
|
1609
1613
|
"not_certified",
|
|
1610
1614
|
"probe_required",
|
|
@@ -1639,6 +1643,9 @@ function formatSynapseLaneDescriptor(descriptor) {
|
|
|
1639
1643
|
const certified = descriptor.certified === undefined ? "unknown" : String(descriptor.certified);
|
|
1640
1644
|
return `lane=${descriptor.lane}; device_class=${descriptor.device_class ?? "unknown"}; ` + `max_tokens=${descriptor.max_tokens} (${descriptor.max_tokens_source}); ` + `certified=${certified}; warm=${descriptor.warm ? "yes" : "no"}; ` + `warm_load_cost_hint_ms=${descriptor.warm_load_cost_hint_ms ?? "unknown"}`;
|
|
1641
1645
|
}
|
|
1646
|
+
function isPollState(state) {
|
|
1647
|
+
return state === "queued" || state === "running" || state === "done" || state === "failed_transient" || state === "failed_permanent";
|
|
1648
|
+
}
|
|
1642
1649
|
|
|
1643
1650
|
class SynapseEmbeddingError extends Error {
|
|
1644
1651
|
code;
|
|
@@ -1767,6 +1774,21 @@ function embeddingFailureFor(error) {
|
|
|
1767
1774
|
function wait(ms) {
|
|
1768
1775
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
1769
1776
|
}
|
|
1777
|
+
async function untilAborted(request, signal) {
|
|
1778
|
+
let onAbort = () => {};
|
|
1779
|
+
const aborted = new Promise((_, reject) => {
|
|
1780
|
+
onAbort = () => reject(signal.reason);
|
|
1781
|
+
if (signal.aborted)
|
|
1782
|
+
onAbort();
|
|
1783
|
+
else
|
|
1784
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
1785
|
+
});
|
|
1786
|
+
try {
|
|
1787
|
+
return await Promise.race([request, aborted]);
|
|
1788
|
+
} finally {
|
|
1789
|
+
signal.removeEventListener("abort", onAbort);
|
|
1790
|
+
}
|
|
1791
|
+
}
|
|
1770
1792
|
function sha256(value) {
|
|
1771
1793
|
return createHash("sha256").update(value).digest("hex");
|
|
1772
1794
|
}
|
|
@@ -2104,43 +2126,42 @@ class SynapseEmbeddingProvider {
|
|
|
2104
2126
|
break;
|
|
2105
2127
|
const page = this.nextPage(eligibleItems, start);
|
|
2106
2128
|
start += page.length;
|
|
2129
|
+
let job;
|
|
2107
2130
|
try {
|
|
2108
2131
|
const requestKey = this.requestKey(page, purpose);
|
|
2109
|
-
let body = {};
|
|
2110
2132
|
let restarted = false;
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
+
try {
|
|
2134
|
+
for (;; ) {
|
|
2135
|
+
try {
|
|
2136
|
+
const body = await this.callWithRetry("embed.batch", this.batchRequest(page, requestKey, purpose), this.options.batchTimeoutMs ?? SYNAPSE_DEFAULT_BATCH_TIMEOUT_MS, true, signal, job);
|
|
2137
|
+
const first = responseBody(body);
|
|
2138
|
+
if (typeof first.job_id === "string" && first.job_id) {
|
|
2139
|
+
job ??= this.startPoll(first.job_id, first.state, signal);
|
|
2140
|
+
job.id = first.job_id;
|
|
2141
|
+
await this.pollBatch(job, page);
|
|
2142
|
+
} else {
|
|
2143
|
+
this.acceptBatchRows(body, page, output);
|
|
2144
|
+
}
|
|
2145
|
+
break;
|
|
2146
|
+
} catch (error) {
|
|
2147
|
+
if (job && (signal?.aborted || this.pollRemainingMs(job) <= 0)) {
|
|
2148
|
+
if (!signal?.aborted) {
|
|
2149
|
+
log2(`[magic-context] Synapse embed.result polling limit reached: job_id=${job.id} state=${job.state} pages_read=${job.pagesRead.size}`);
|
|
2150
|
+
}
|
|
2151
|
+
break;
|
|
2152
|
+
}
|
|
2153
|
+
const classified = classifyError(error);
|
|
2154
|
+
if (classified.code !== "module_restarted" || restarted)
|
|
2155
|
+
throw classified;
|
|
2156
|
+
restarted = true;
|
|
2157
|
+
}
|
|
2133
2158
|
}
|
|
2134
|
-
|
|
2135
|
-
if (!
|
|
2136
|
-
|
|
2159
|
+
} finally {
|
|
2160
|
+
if (!signal?.aborted && job?.rows.size) {
|
|
2161
|
+
for (const [id, vector] of job.rows)
|
|
2162
|
+
output.set(id, vector);
|
|
2163
|
+
this.recordSuccess();
|
|
2137
2164
|
}
|
|
2138
|
-
const rowMetadata = validateWireRow(item, disclosures[index] ?? null, expected);
|
|
2139
|
-
const vectorArray = Float32Array.from(vector);
|
|
2140
|
-
this.validateResponse({ ...batchEnvelope, ...item }, vectorArray.length);
|
|
2141
|
-
embeddingRowMetadata.set(vectorArray, rowMetadata);
|
|
2142
|
-
output.set(id, vectorArray);
|
|
2143
|
-
this.recordSuccess();
|
|
2144
2165
|
}
|
|
2145
2166
|
} catch (error) {
|
|
2146
2167
|
const classified = classifyError(error);
|
|
@@ -2157,6 +2178,30 @@ class SynapseEmbeddingProvider {
|
|
|
2157
2178
|
}
|
|
2158
2179
|
return output;
|
|
2159
2180
|
}
|
|
2181
|
+
acceptBatchRows(body, requested, output, polling = false) {
|
|
2182
|
+
const batchEnvelope = responseBody(body);
|
|
2183
|
+
const disclosures = extractTruncationDisclosures(body);
|
|
2184
|
+
for (const [index, item] of extractBatchItems(body).entries()) {
|
|
2185
|
+
const id = typeof item.id === "string" ? item.id : "";
|
|
2186
|
+
const vector = item.vector ?? item.embedding;
|
|
2187
|
+
if (!id || !Array.isArray(vector) || vector.some((component) => typeof component !== "number" || !Number.isFinite(component))) {
|
|
2188
|
+
throw new SynapseEmbeddingError("schema_violation", "Synapse batch item is malformed");
|
|
2189
|
+
}
|
|
2190
|
+
const expected = requested.find((candidate) => candidate.id === id);
|
|
2191
|
+
if (!expected) {
|
|
2192
|
+
throw new SynapseEmbeddingError("schema_violation", `Synapse returned unknown item ${id}`);
|
|
2193
|
+
}
|
|
2194
|
+
const rowMetadata = validateWireRow(item, disclosures[index] ?? null, expected);
|
|
2195
|
+
this.validateResponse(polling ? batchEnvelope : { ...batchEnvelope, ...item }, vector.length);
|
|
2196
|
+
if (polling && output.has(id))
|
|
2197
|
+
continue;
|
|
2198
|
+
const vectorArray = Float32Array.from(vector);
|
|
2199
|
+
embeddingRowMetadata.set(vectorArray, rowMetadata);
|
|
2200
|
+
output.set(id, vectorArray);
|
|
2201
|
+
if (!polling)
|
|
2202
|
+
this.recordSuccess();
|
|
2203
|
+
}
|
|
2204
|
+
}
|
|
2160
2205
|
async dispose() {
|
|
2161
2206
|
this.initialized = false;
|
|
2162
2207
|
this.client = null;
|
|
@@ -2201,45 +2246,91 @@ class SynapseEmbeddingProvider {
|
|
|
2201
2246
|
purpose
|
|
2202
2247
|
});
|
|
2203
2248
|
}
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
const
|
|
2207
|
-
|
|
2249
|
+
startPoll(id, state, signal) {
|
|
2250
|
+
const timeoutMs = this.options.pollTimeoutMs ?? SYNAPSE_DEFAULT_POLL_TIMEOUT_MS;
|
|
2251
|
+
const timeout = this.options.pollClock?.timeoutSignal(timeoutMs) ?? AbortSignal.timeout(timeoutMs);
|
|
2252
|
+
return {
|
|
2253
|
+
id,
|
|
2254
|
+
state: isPollState(state) ? state : "unknown",
|
|
2255
|
+
deadline: this.pollNow() + timeoutMs,
|
|
2256
|
+
signal: signal ? AbortSignal.any([signal, timeout]) : timeout,
|
|
2257
|
+
delayMs: SYNAPSE_INITIAL_POLL_DELAY_MS,
|
|
2258
|
+
pagesRead: new Set,
|
|
2259
|
+
rows: new Map
|
|
2260
|
+
};
|
|
2261
|
+
}
|
|
2262
|
+
pollNow() {
|
|
2263
|
+
return this.options.pollClock?.now() ?? performance.now();
|
|
2264
|
+
}
|
|
2265
|
+
pollRemainingMs(job) {
|
|
2266
|
+
return job.signal.aborted ? 0 : Math.ceil(job.deadline - this.pollNow());
|
|
2267
|
+
}
|
|
2268
|
+
async pollWait(ms, signal) {
|
|
2269
|
+
const clock = this.options.pollClock;
|
|
2270
|
+
if (clock)
|
|
2271
|
+
await clock.sleep(ms, signal);
|
|
2272
|
+
else
|
|
2273
|
+
await sleep(ms, undefined, { signal });
|
|
2274
|
+
}
|
|
2275
|
+
async pollBatch(job, requested) {
|
|
2276
|
+
let page = 0;
|
|
2208
2277
|
for (;; ) {
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2278
|
+
let body;
|
|
2279
|
+
try {
|
|
2280
|
+
body = await this.callWithRetry("embed.result", { job_id: job.id, page }, this.options.batchTimeoutMs ?? SYNAPSE_DEFAULT_BATCH_TIMEOUT_MS, true, job.signal, job);
|
|
2281
|
+
} catch (error) {
|
|
2282
|
+
if (readErrorCode(error) !== "invalid_request")
|
|
2283
|
+
throw error;
|
|
2284
|
+
log2(`[magic-context] Synapse embed.result stopped: job_id=${job.id} page=${page} code=invalid_request`);
|
|
2285
|
+
return;
|
|
2286
|
+
}
|
|
2216
2287
|
const parsed = responseBody(body);
|
|
2217
|
-
const
|
|
2218
|
-
const
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2288
|
+
const state = parsed.state;
|
|
2289
|
+
const malformed = () => new SynapseEmbeddingError("schema_violation", "Synapse embed.result returned a malformed page or status");
|
|
2290
|
+
if (!isPollState(state) || parsed.job_id !== job.id || typeof parsed.pages_available !== "number" || !Number.isInteger(parsed.pages_available) || parsed.pages_available < 0)
|
|
2291
|
+
throw malformed();
|
|
2292
|
+
job.state = state;
|
|
2293
|
+
if (Array.isArray(parsed.vectors)) {
|
|
2294
|
+
const pageCount = parsed.page_count;
|
|
2295
|
+
if (parsed.page !== page || typeof pageCount !== "number" || !Number.isInteger(pageCount) || pageCount <= page || parsed.pages_available <= page || parsed.vectors.length === 0 || parsed.vectors.some((row) => !asRecord(row)))
|
|
2296
|
+
throw malformed();
|
|
2297
|
+
this.acceptBatchRows(body, requested, job.rows, true);
|
|
2298
|
+
job.pagesRead.add(page);
|
|
2299
|
+
page += 1;
|
|
2300
|
+
if (state === "done" && page === pageCount)
|
|
2301
|
+
return;
|
|
2302
|
+
continue;
|
|
2303
|
+
}
|
|
2304
|
+
if (parsed.vectors !== undefined || parsed.page !== undefined || parsed.page_count !== undefined || typeof parsed.request_key !== "string")
|
|
2305
|
+
throw malformed();
|
|
2306
|
+
if (state === "failed_transient" || state === "failed_permanent") {
|
|
2307
|
+
const error = asRecord(parsed.error);
|
|
2308
|
+
if (typeof error?.code !== "string" || typeof error.message !== "string") {
|
|
2309
|
+
throw malformed();
|
|
2310
|
+
}
|
|
2311
|
+
throw Object.assign(new Error(error.message), { code: error.code });
|
|
2229
2312
|
}
|
|
2230
|
-
|
|
2313
|
+
if (state !== "queued" && state !== "running")
|
|
2314
|
+
throw malformed();
|
|
2315
|
+
const delay = Math.min(job.delayMs, this.pollRemainingMs(job));
|
|
2316
|
+
if (delay > 0)
|
|
2317
|
+
await this.pollWait(delay, job.signal);
|
|
2318
|
+
job.delayMs = Math.min(job.delayMs * 2, SYNAPSE_MAX_POLL_DELAY_MS);
|
|
2231
2319
|
}
|
|
2232
2320
|
}
|
|
2233
|
-
async callWithRetry(method, params, timeoutMs, retryEmbeddings, signal) {
|
|
2321
|
+
async callWithRetry(method, params, timeoutMs, retryEmbeddings, signal, job) {
|
|
2234
2322
|
let attempt = 0;
|
|
2235
2323
|
for (;; ) {
|
|
2236
2324
|
if (signal?.aborted)
|
|
2237
2325
|
throw new SynapseEmbeddingError("transport", "Synapse request aborted");
|
|
2326
|
+
const remainingMs = job ? this.pollRemainingMs(job) : timeoutMs;
|
|
2327
|
+
if (job && remainingMs <= 0)
|
|
2328
|
+
throw new SynapseEmbeddingError("timeout", "Synapse polling limit reached");
|
|
2238
2329
|
try {
|
|
2239
2330
|
if (!this.client)
|
|
2240
2331
|
throw new SynapseEmbeddingError("transport", "Synapse client is unavailable");
|
|
2241
|
-
|
|
2242
|
-
timeoutMs,
|
|
2332
|
+
const request = this.client.call(this.options.moduleId ?? "synapse", method, params, {
|
|
2333
|
+
timeoutMs: Math.min(timeoutMs, remainingMs),
|
|
2243
2334
|
targetKind: "management_surface",
|
|
2244
2335
|
identity: {
|
|
2245
2336
|
project_root: this.options.projectRoot,
|
|
@@ -2247,8 +2338,16 @@ class SynapseEmbeddingProvider {
|
|
|
2247
2338
|
session: this.options.session
|
|
2248
2339
|
}
|
|
2249
2340
|
});
|
|
2341
|
+
if (!job)
|
|
2342
|
+
return await request;
|
|
2343
|
+
const reply = await untilAborted(request, job.signal);
|
|
2344
|
+
if (this.pollRemainingMs(job) <= 0)
|
|
2345
|
+
throw new SynapseEmbeddingError("timeout", "Synapse polling limit reached");
|
|
2346
|
+
return reply;
|
|
2250
2347
|
} catch (error) {
|
|
2251
2348
|
const classified = classifyError(error);
|
|
2349
|
+
if (job && (this.pollRemainingMs(job) <= 0 || classified.code === "module_restarted" || method === "embed.result" && readErrorCode(error) === "invalid_request"))
|
|
2350
|
+
throw error;
|
|
2252
2351
|
if (classified.code === "idempotency_conflict")
|
|
2253
2352
|
throw classified;
|
|
2254
2353
|
const outcomeUnknown = error instanceof SubcCallError && error.kind === "outcome_unknown";
|
|
@@ -2257,7 +2356,10 @@ class SynapseEmbeddingProvider {
|
|
|
2257
2356
|
throw classified;
|
|
2258
2357
|
const delay = classified.retryAfterMs ?? Math.min(2000, 100 * 2 ** attempt);
|
|
2259
2358
|
attempt += 1;
|
|
2260
|
-
|
|
2359
|
+
if (job)
|
|
2360
|
+
await this.pollWait(Math.min(delay, this.pollRemainingMs(job)), job.signal);
|
|
2361
|
+
else
|
|
2362
|
+
await wait(delay);
|
|
2261
2363
|
}
|
|
2262
2364
|
}
|
|
2263
2365
|
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import {
|
|
2
|
+
TEXT_TAG_IDENTITY_MARKER
|
|
3
|
+
} from "./server-gj259dqy.js";
|
|
4
|
+
|
|
5
|
+
// src/features/magic-context/message-fts-session-filter.ts
|
|
6
|
+
var MESSAGE_FTS_SESSION_FILTER_SQL = `+message_history_fts.rowid IN (
|
|
7
|
+
SELECT fts_rowid FROM message_fts_rowid_map WHERE session_id = ?
|
|
8
|
+
) AND `;
|
|
9
|
+
var coverageCaches = new WeakMap;
|
|
10
|
+
var coverageScansOnThisThread = 0;
|
|
11
|
+
function getCoverageCache(db) {
|
|
12
|
+
let cache = coverageCaches.get(db);
|
|
13
|
+
if (!cache) {
|
|
14
|
+
cache = {
|
|
15
|
+
pin: db.prepare("SELECT fts_rowid FROM message_fts_rowid_map LIMIT 1"),
|
|
16
|
+
stamp: db.prepare("SELECT total_changes() AS changes, data_version AS version FROM pragma_data_version"),
|
|
17
|
+
missing: db.prepare(`SELECT DISTINCT session_id AS sessionId
|
|
18
|
+
FROM message_history_fts WHERE rowid IN (
|
|
19
|
+
SELECT id FROM message_history_fts_docsize
|
|
20
|
+
EXCEPT SELECT fts_rowid FROM message_fts_rowid_map
|
|
21
|
+
)`)
|
|
22
|
+
};
|
|
23
|
+
coverageCaches.set(db, cache);
|
|
24
|
+
}
|
|
25
|
+
return cache;
|
|
26
|
+
}
|
|
27
|
+
function withMessageFtsSessionFilter(db, sessionId, read) {
|
|
28
|
+
let cacheable = false;
|
|
29
|
+
try {
|
|
30
|
+
const transaction = db;
|
|
31
|
+
cacheable = transaction.inTransaction === false || transaction.isTransaction === false;
|
|
32
|
+
if (!cacheable)
|
|
33
|
+
coverageCaches.delete(db);
|
|
34
|
+
} catch {
|
|
35
|
+
coverageCaches.delete(db);
|
|
36
|
+
}
|
|
37
|
+
return db.transaction(() => {
|
|
38
|
+
let sessionFirst = false;
|
|
39
|
+
try {
|
|
40
|
+
const cache = getCoverageCache(db);
|
|
41
|
+
cache.pin.get();
|
|
42
|
+
const stamp = cache.stamp.get();
|
|
43
|
+
let incomplete = cache.incompleteSessions;
|
|
44
|
+
if (!cacheable || !incomplete || cache.version !== stamp.version || cache.changes !== stamp.changes) {
|
|
45
|
+
coverageScansOnThisThread += 1;
|
|
46
|
+
const rows = cache.missing.all();
|
|
47
|
+
incomplete = new Set(rows.map((row) => row.sessionId));
|
|
48
|
+
if (cacheable) {
|
|
49
|
+
cache.version = stamp.version;
|
|
50
|
+
cache.changes = stamp.changes;
|
|
51
|
+
cache.incompleteSessions = incomplete;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
sessionFirst = !incomplete.has(sessionId);
|
|
55
|
+
} catch {
|
|
56
|
+
coverageCaches.delete(db);
|
|
57
|
+
}
|
|
58
|
+
return read(sessionFirst);
|
|
59
|
+
}).deferred();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// src/features/magic-context/message-visibility.ts
|
|
63
|
+
function partDropSql(session, id, prefix, type, validSuffix) {
|
|
64
|
+
const next = prefix.slice(0, -1) + String.fromCharCode(prefix.charCodeAt(prefix.length - 1) + 1);
|
|
65
|
+
const suffix = `substr(t.message_id, length(${id}) + ${prefix.length + 1})`;
|
|
66
|
+
return `EXISTS (SELECT 1 FROM tags AS t INDEXED BY idx_tags_session_message_id
|
|
67
|
+
WHERE t.session_id = ${session} AND t.message_id >= ${id} || '${prefix}'
|
|
68
|
+
AND t.message_id < ${id} || '${next}' AND t.type = '${type}' AND t.status = 'dropped'
|
|
69
|
+
AND (${validSuffix(suffix)}))`;
|
|
70
|
+
}
|
|
71
|
+
var numericSuffix = (suffix) => `${suffix} <> '' AND ${suffix} NOT GLOB '*[^0-9]*'`;
|
|
72
|
+
function textDropSql(session, id) {
|
|
73
|
+
return `EXISTS (SELECT 1 FROM tags AS t INDEXED BY idx_tags_session_message_id
|
|
74
|
+
WHERE t.session_id = ${session} AND t.message_id = ${id} AND t.status = 'dropped'
|
|
75
|
+
AND t.type = 'message')
|
|
76
|
+
OR ${partDropSql(session, id, ":p", "message", numericSuffix)}
|
|
77
|
+
OR ${partDropSql(session, id, TEXT_TAG_IDENTITY_MARKER, "message", (suffix) => `${suffix} GLOB '[0-9a-f]*:[0-9a-f]*:o[0-9]*' AND ${suffix} NOT GLOB '*[^0-9a-f:o]*'
|
|
78
|
+
AND length(${suffix}) - length(replace(${suffix}, ':', '')) = 2`)}`;
|
|
79
|
+
}
|
|
80
|
+
function unresolvedCoverageSql(session, start, end) {
|
|
81
|
+
return `EXISTS (SELECT 1 FROM compartments AS unresolved
|
|
82
|
+
WHERE unresolved.session_id = ${session} AND unresolved.rebase_status = 'unresolved'
|
|
83
|
+
AND unresolved.start_message <= ${end} AND unresolved.end_message >= ${start})`;
|
|
84
|
+
}
|
|
85
|
+
function visibleSql(session, ordinal, lastSummaryEnd, dropped) {
|
|
86
|
+
return `CASE WHEN ${ordinal} <= ${lastSummaryEnd} THEN 0
|
|
87
|
+
WHEN ${unresolvedCoverageSql(session, ordinal, ordinal)} THEN 1 ELSE NOT (${dropped}) END`;
|
|
88
|
+
}
|
|
89
|
+
function liveTailRangeTouchesUnresolvedCoverage(db, sessionId, start, end, lastSummaryEnd) {
|
|
90
|
+
if (lastSummaryEnd < 0 || start <= lastSummaryEnd)
|
|
91
|
+
return false;
|
|
92
|
+
return !!db.prepare(`SELECT 1 WHERE ${unresolvedCoverageSql("?", "?", "?")}`).get(sessionId, end, start);
|
|
93
|
+
}
|
|
94
|
+
function messageTextVisibleInRequestSql(session, id, ordinal, lastSummaryEnd) {
|
|
95
|
+
return visibleSql(session, ordinal, lastSummaryEnd, textDropSql(session, id));
|
|
96
|
+
}
|
|
97
|
+
function messageVisibleInRequestSql(session, id, ordinal, lastSummaryEnd) {
|
|
98
|
+
return visibleSql(session, ordinal, lastSummaryEnd, `${textDropSql(session, id)}
|
|
99
|
+
OR ${partDropSql(session, id, ":file", "file", numericSuffix)}
|
|
100
|
+
OR EXISTS (SELECT 1 FROM tags AS t INDEXED BY idx_tags_pi_fallback_tool_owner
|
|
101
|
+
WHERE t.session_id = ${session} AND t.tool_owner_message_id = ${id}
|
|
102
|
+
AND t.type = 'tool' AND t.status = 'dropped')`);
|
|
103
|
+
}
|
|
104
|
+
function rangeHasHiddenMessages(db, sessionId, candidates, lastSummaryEnd, start, end) {
|
|
105
|
+
return !!db.prepare(`
|
|
106
|
+
WITH range(sessionId, start, end) AS (VALUES (?, ?, ?)), candidates(id, ordinal) AS (
|
|
107
|
+
SELECT json_extract(value, '$[0]'), json_extract(value, '$[1]') FROM json_each(?)
|
|
108
|
+
UNION
|
|
109
|
+
SELECT message_id, message_ordinal FROM range CROSS JOIN message_history_source
|
|
110
|
+
INDEXED BY idx_message_history_source_session_ordinal
|
|
111
|
+
WHERE session_id = range.sessionId AND message_ordinal BETWEEN range.start AND range.end
|
|
112
|
+
)
|
|
113
|
+
SELECT 1 FROM range CROSS JOIN candidates
|
|
114
|
+
WHERE NOT (${messageVisibleInRequestSql("range.sessionId", "candidates.id", "candidates.ordinal", "?")})
|
|
115
|
+
LIMIT 1
|
|
116
|
+
`).get(sessionId, start, end, JSON.stringify([...candidates]), lastSummaryEnd);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export { MESSAGE_FTS_SESSION_FILTER_SQL, withMessageFtsSessionFilter, liveTailRangeTouchesUnresolvedCoverage, messageTextVisibleInRequestSql, rangeHasHiddenMessages };
|
package/dist/v2/server.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
loadPluginConfigDetailed
|
|
3
|
-
} from "./server-
|
|
3
|
+
} from "./server-00adcfjd.js";
|
|
4
4
|
import {
|
|
5
5
|
setHarness2
|
|
6
6
|
} from "./server-pavzsdc6.js";
|
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
union,
|
|
26
26
|
tuple,
|
|
27
27
|
record
|
|
28
|
-
} from "./server-
|
|
28
|
+
} from "./server-e6xneh68.js";
|
|
29
29
|
import {
|
|
30
30
|
pushNotification2
|
|
31
31
|
} from "./server-y14pawe1.js";
|
|
@@ -7878,7 +7878,7 @@ var require_src2 = __commonJS(function(exports, module) {
|
|
|
7878
7878
|
// package.json
|
|
7879
7879
|
var package_default = {
|
|
7880
7880
|
name: "@cortexkit/opencode-magic-context",
|
|
7881
|
-
version: "0.49.
|
|
7881
|
+
version: "0.49.95",
|
|
7882
7882
|
type: "module",
|
|
7883
7883
|
description: "OpenCode plugin for Magic Context — cross-session memory and context management",
|
|
7884
7884
|
main: "dist/index.js",
|
|
@@ -8199,7 +8199,7 @@ async function setup(context) {
|
|
|
8199
8199
|
if (claimStorageBackupWarningCheck() && isMagicContextStorageOutsideEngram(storageDir)) {
|
|
8200
8200
|
log2(`[magic-context] Magic Context storage is at ${storageDir}, outside the folder Engram backs up (~/.local/share/cortexkit/magic-context). It is not included in CortexKit backups.`);
|
|
8201
8201
|
}
|
|
8202
|
-
const { registerContext } = await import("./context-
|
|
8202
|
+
const { registerContext } = await import("./context-2hssw26q.js");
|
|
8203
8203
|
setHarness2("opencode2");
|
|
8204
8204
|
bindStaleBuildNotice({}, import.meta.url, "opencode2");
|
|
8205
8205
|
const duties = await registerContext(context);
|