@cortexkit/pi-magic-context 0.49.34 → 0.49.36
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 +163 -155
- package/dist/chunk-embedding-write-worker.js +71 -66
- package/dist/{compaction-marker-candidates-p1kqkqhq.js → compaction-marker-candidates-9fzqg6y0.js} +6 -3
- package/dist/compaction-marker-candidates-worker.js +24 -23
- package/dist/{compartment-chunk-embedding-8c85ebce.js → compartment-chunk-embedding-jpcme6tz.js} +11 -9
- package/dist/embedding-backfill-002vyexq.js +27 -0
- package/dist/embedding-worker-process.js +2 -1
- package/dist/embedding-worker.js +5 -4
- package/dist/expand-attachments-8sxeyj26.js +21 -0
- package/dist/historian-calibration-extension.js +2 -1
- package/dist/{index-hqw0rt9k.js → index-0wtm7g7f.js} +1 -1
- package/dist/{index-wqpjhx1p.js → index-2qqsnh1b.js} +2 -2
- package/dist/index-3bb24eb6.js +229 -0
- package/dist/{index-48twbev2.js → index-6pk49fc3.js} +37 -51
- package/dist/{index-399p688g.js → index-8sqebjzk.js} +4 -1
- package/dist/{index-np9ryr8y.js → index-a7sj2bam.js} +24 -241
- package/dist/index-by1bzjcd.js +24 -0
- package/dist/{index-6981g1xv.js → index-c1dqxr10.js} +35 -5
- package/dist/index-c6wbq66z.js +168 -0
- package/dist/{index-bvpar0bg.js → index-ck8wj35v.js} +2 -2
- package/dist/{index-jn44h81p.js → index-cq71g4dk.js} +1 -1
- package/dist/{index-pb3ea2tq.js → index-d107f484.js} +5 -5
- package/dist/{index-f4fz95fy.js → index-dgqjq8sg.js} +398 -4996
- package/dist/index-dnp1jjar.js +222 -0
- package/dist/index-ea37qn4x.js +777 -0
- package/dist/{index-g2tfayfc.js → index-f6y7mdq9.js} +98 -552
- package/dist/{index-0gymvr5j.js → index-f9qet7y8.js} +19 -8
- package/dist/index-gxqmh9hq.js +194 -0
- package/dist/{index-fgs78jyd.js → index-gymgz20n.js} +5 -222
- package/dist/index-hgd00nas.js +113 -0
- package/dist/{index-9xd7qveg.js → index-jbkwszd5.js} +4 -4
- package/dist/{index-e61zxfts.js → index-kj49vs41.js} +4 -4
- package/dist/{index-4zemngt7.js → index-mp0gh04g.js} +2 -2
- package/dist/{index-eenxm3t3.js → index-mx757f3g.js} +51 -32
- package/dist/{index-23t8ryqw.js → index-n0zjvs3h.js} +1 -168
- package/dist/index-nypgv96r.js +58 -0
- package/dist/index-p9jfa33t.js +4171 -0
- package/dist/{index-eqw9t2ty.js → index-pwp6zyx3.js} +15 -4
- package/dist/{index-cj3bkd16.js → index-ry84c8dr.js} +2 -2
- package/dist/{index-gwxaz0z5.js → index-rzfr7wdv.js} +2 -2
- package/dist/index-w26zvs1q.js +528 -0
- package/dist/index-wfqysrwq.js +204 -0
- package/dist/index-wrr9rp9a.js +16 -0
- package/dist/{index-my0dn413.js → index-wt7vmyj4.js} +1 -1
- package/dist/{index-0mc0vv97.js → index-wwsfevck.js} +8 -5
- package/dist/{index-54wmg4rj.js → index-x2n261wp.js} +16 -14
- package/dist/{index-6wdwv3a6.js → index-y90fxz4t.js} +10 -4
- package/dist/{index-c474g0gj.js → index-yacs388s.js} +1 -1
- package/dist/{index-xn5yh0pn.js → index-z7dktknj.js} +34 -131
- package/dist/index.js +1316 -488
- package/dist/{logger-shetp43v.js → logger-2j70hhz4.js} +2 -1
- package/dist/{message-fts-rowid-map-3mbvdgn9.js → message-fts-rowid-map-hmgyfxxa.js} +8 -6
- package/dist/{message-index-bounded-a6na71rg.js → message-index-bounded-82sergz7.js} +15 -12
- package/dist/{message-time-backfill-e3r8ddh1.js → message-time-backfill-x45573rs.js} +3 -2
- package/dist/migration-worker.js +56 -48
- package/dist/{project-embedding-registry-acqb6be4.js → project-embedding-registry-16pj4vyf.js} +16 -13
- package/dist/raw-ordinal-warmup-worker.js +114 -113
- package/dist/{read-session-chunk-2xcp6f40.js → read-session-chunk-jxq427v6.js} +17 -10
- package/dist/{read-session-raw-g9b1zdn5.js → read-session-raw-a9ntjqap.js} +6 -4
- package/dist/render-2wan3bfh.js +42 -0
- package/dist/{safe-notification-target-zcpchea6.js → safe-notification-target-jk69jxwp.js} +3 -2
- package/dist/search-3p18trsb.js +50 -0
- package/dist/search-archive-pgrv04gv.js +25 -0
- package/dist/{storage-tags-6409qq18.js → storage-tags-p9y3bnw7.js} +5 -4
- package/dist/store-reader-2m80zs5z.js +14 -0
- package/dist/store-v60q7dje.js +452 -0
- package/dist/subagent-entry.js +34 -25
- package/dist/tag-snapshot-worker-pi.js +218 -209
- package/dist/v2-archive-reader-5zpj8hrg.js +11 -0
- package/package.json +1 -1
- package/dist/embedding-backfill-rwfmyvze.js +0 -24
- package/dist/search-archive-jate39w5.js +0 -21
- package/dist/search-b6hp64hc.js +0 -45
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import {
|
|
2
|
+
registerExitAbort,
|
|
3
|
+
unregisterExitAbort
|
|
4
|
+
} from "./index-8sqebjzk.js";
|
|
5
|
+
import {
|
|
6
|
+
inRootAsyncContext2
|
|
7
|
+
} from "./index-2qtx0q6h.js";
|
|
8
|
+
|
|
9
|
+
// ../plugin/src/shared/reusable-worker.ts
|
|
10
|
+
import { EventEmitter } from "node:events";
|
|
11
|
+
import * as timers from "node:timers";
|
|
12
|
+
import {
|
|
13
|
+
MessageChannel,
|
|
14
|
+
receiveMessageOnPort,
|
|
15
|
+
Worker
|
|
16
|
+
} from "node:worker_threads";
|
|
17
|
+
var pools = new Map;
|
|
18
|
+
var liveSlots = new Set;
|
|
19
|
+
var nextId = 0;
|
|
20
|
+
var IDLE_MS = 60000;
|
|
21
|
+
var sharedCloneWorks = (() => {
|
|
22
|
+
const source = new SharedArrayBuffer(1);
|
|
23
|
+
const clone = structuredClone(source);
|
|
24
|
+
new Uint8Array(source)[0] = 1;
|
|
25
|
+
return new Uint8Array(clone)[0] === 1;
|
|
26
|
+
})();
|
|
27
|
+
var cloneChannel;
|
|
28
|
+
function cloneJobValue(value, transferList) {
|
|
29
|
+
if (sharedCloneWorks)
|
|
30
|
+
return structuredClone(value, { transfer: transferList });
|
|
31
|
+
if (!cloneChannel) {
|
|
32
|
+
cloneChannel = inRootAsyncContext2(() => new MessageChannel);
|
|
33
|
+
cloneChannel.port1.unref();
|
|
34
|
+
cloneChannel.port2.unref();
|
|
35
|
+
}
|
|
36
|
+
cloneChannel.port1.postMessage(value, transferList);
|
|
37
|
+
const packet = receiveMessageOnPort(cloneChannel.port2);
|
|
38
|
+
if (!packet)
|
|
39
|
+
throw new Error("worker input clone did not arrive synchronously");
|
|
40
|
+
return packet.message;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
class Lease extends EventEmitter {
|
|
44
|
+
slot;
|
|
45
|
+
data;
|
|
46
|
+
id = ++nextId;
|
|
47
|
+
ended = false;
|
|
48
|
+
referenced = true;
|
|
49
|
+
outbox = [];
|
|
50
|
+
constructor(slot, data) {
|
|
51
|
+
super();
|
|
52
|
+
this.slot = slot;
|
|
53
|
+
this.data = data;
|
|
54
|
+
}
|
|
55
|
+
postMessage(value, transferList) {
|
|
56
|
+
if (this.ended)
|
|
57
|
+
return;
|
|
58
|
+
if (this.slot.active === this)
|
|
59
|
+
this.slot.worker.postMessage({ jobId: this.id, value }, transferList);
|
|
60
|
+
else
|
|
61
|
+
this.outbox.push(cloneJobValue({ value, transferList }, transferList));
|
|
62
|
+
}
|
|
63
|
+
start() {
|
|
64
|
+
if (this.referenced)
|
|
65
|
+
this.slot.worker.ref();
|
|
66
|
+
else
|
|
67
|
+
this.slot.worker.unref();
|
|
68
|
+
this.emit("online");
|
|
69
|
+
this.slot.worker.postMessage({ jobId: this.id, start: this.data });
|
|
70
|
+
for (const { value, transferList } of this.outbox.splice(0))
|
|
71
|
+
this.postMessage(value, transferList);
|
|
72
|
+
}
|
|
73
|
+
ref() {
|
|
74
|
+
this.referenced = true;
|
|
75
|
+
if (this.slot.active === this)
|
|
76
|
+
this.slot.worker.ref();
|
|
77
|
+
return this;
|
|
78
|
+
}
|
|
79
|
+
unref() {
|
|
80
|
+
this.referenced = false;
|
|
81
|
+
if (this.slot.active === this)
|
|
82
|
+
this.slot.worker.unref();
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
85
|
+
async terminate() {
|
|
86
|
+
if (this.ended)
|
|
87
|
+
return 0;
|
|
88
|
+
if (this.slot.active === this)
|
|
89
|
+
return await this.slot.worker.terminate();
|
|
90
|
+
this.ended = true;
|
|
91
|
+
this.slot.queue.splice(this.slot.queue.indexOf(this), 1);
|
|
92
|
+
this.emit("exit", 0);
|
|
93
|
+
return 0;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function reuseWorker(entry, options, idleMs = IDLE_MS) {
|
|
97
|
+
const data = cloneJobValue(options.workerData);
|
|
98
|
+
const slot = acquireSlot(entry, options, idleMs);
|
|
99
|
+
const lease = new Lease(slot, data);
|
|
100
|
+
enqueue(slot, lease);
|
|
101
|
+
return lease;
|
|
102
|
+
}
|
|
103
|
+
function enqueue(slot, lease) {
|
|
104
|
+
timers.clearTimeout(slot.idle);
|
|
105
|
+
lease.slot = slot;
|
|
106
|
+
slot.queue.push(lease);
|
|
107
|
+
queueMicrotask(() => slot.advance());
|
|
108
|
+
}
|
|
109
|
+
function acquireSlot(entry, options, idleMs) {
|
|
110
|
+
const data = options.workerData;
|
|
111
|
+
const key = JSON.stringify([
|
|
112
|
+
String(entry),
|
|
113
|
+
data?.path ?? data?.dbPath,
|
|
114
|
+
data?.harness,
|
|
115
|
+
data?.job
|
|
116
|
+
]);
|
|
117
|
+
let slot = pools.get(key);
|
|
118
|
+
if (!slot) {
|
|
119
|
+
const worker = inRootAsyncContext2(() => new Worker(entry, { ...options, workerData: { reusableWorker: true } }));
|
|
120
|
+
const controller = new AbortController;
|
|
121
|
+
slot = { worker, controller, queue: [], advance: () => {} };
|
|
122
|
+
pools.set(key, slot);
|
|
123
|
+
liveSlots.add(slot);
|
|
124
|
+
const owned = slot;
|
|
125
|
+
const advance = () => {
|
|
126
|
+
if (controller.signal.aborted || owned.active)
|
|
127
|
+
return;
|
|
128
|
+
timers.clearTimeout(owned.idle);
|
|
129
|
+
const lease = owned.queue.shift();
|
|
130
|
+
owned.active = lease;
|
|
131
|
+
if (!lease) {
|
|
132
|
+
worker.unref();
|
|
133
|
+
owned.idle = timers.setTimeout(() => {
|
|
134
|
+
if (pools.get(key) === owned)
|
|
135
|
+
pools.delete(key);
|
|
136
|
+
worker.terminate();
|
|
137
|
+
}, idleMs);
|
|
138
|
+
owned.idle.unref();
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
lease.start();
|
|
142
|
+
};
|
|
143
|
+
owned.advance = advance;
|
|
144
|
+
worker.on("message", (message) => {
|
|
145
|
+
const lease = owned.active;
|
|
146
|
+
if (!lease || message.jobId !== lease.id)
|
|
147
|
+
return;
|
|
148
|
+
if (!message.finished) {
|
|
149
|
+
lease.emit("message", message.value);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
lease.ended = true;
|
|
153
|
+
owned.active = undefined;
|
|
154
|
+
if (message.code) {
|
|
155
|
+
if (pools.get(key) === owned)
|
|
156
|
+
pools.delete(key);
|
|
157
|
+
lease.emit("exit", message.code);
|
|
158
|
+
worker.terminate();
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
lease.emit("exit", 0);
|
|
162
|
+
advance();
|
|
163
|
+
});
|
|
164
|
+
worker.on("error", (error) => {
|
|
165
|
+
if (pools.get(key) === owned)
|
|
166
|
+
pools.delete(key);
|
|
167
|
+
owned.active?.emit("error", error);
|
|
168
|
+
});
|
|
169
|
+
worker.on("exit", (code) => {
|
|
170
|
+
liveSlots.delete(owned);
|
|
171
|
+
timers.clearTimeout(owned.idle);
|
|
172
|
+
if (pools.get(key) === owned)
|
|
173
|
+
pools.delete(key);
|
|
174
|
+
const active = owned.active;
|
|
175
|
+
owned.active = undefined;
|
|
176
|
+
if (active && !active.ended) {
|
|
177
|
+
active.ended = true;
|
|
178
|
+
active.emit("exit", code);
|
|
179
|
+
}
|
|
180
|
+
for (const lease of owned.queue.splice(0)) {
|
|
181
|
+
if (controller.signal.aborted) {
|
|
182
|
+
lease.ended = true;
|
|
183
|
+
lease.emit("exit", code);
|
|
184
|
+
} else {
|
|
185
|
+
try {
|
|
186
|
+
enqueue(acquireSlot(entry, options, idleMs), lease);
|
|
187
|
+
} catch (error) {
|
|
188
|
+
lease.ended = true;
|
|
189
|
+
lease.emit("error", error);
|
|
190
|
+
lease.emit("exit", 1);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
controller.signal.addEventListener("abort", () => {
|
|
196
|
+
worker.terminate();
|
|
197
|
+
}, { once: true });
|
|
198
|
+
registerExitAbort(controller);
|
|
199
|
+
worker.once("exit", () => unregisterExitAbort(controller));
|
|
200
|
+
}
|
|
201
|
+
return slot;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export { reuseWorker };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// ../plugin/src/shared/project-directory-key.ts
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
function projectDirectoryKey(directory) {
|
|
4
|
+
const slashed = directory.replaceAll("\\", "/").replace(/^\/\/\?\/UNC\//i, "//").replace(/^\/\/\?\//, "");
|
|
5
|
+
if (/^[a-z]:\//i.test(slashed) || slashed.startsWith("//")) {
|
|
6
|
+
return path.win32.normalize(slashed).replaceAll("\\", "/").replace(/\/$/, "").toLowerCase();
|
|
7
|
+
}
|
|
8
|
+
return path.resolve(directory);
|
|
9
|
+
}
|
|
10
|
+
function sameProjectDirectory(a, b) {
|
|
11
|
+
if (a.length === 0 || b.length === 0)
|
|
12
|
+
return false;
|
|
13
|
+
return projectDirectoryKey(a) === projectDirectoryKey(b);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { projectDirectoryKey, sameProjectDirectory };
|
|
@@ -3,11 +3,11 @@ import {
|
|
|
3
3
|
tagRevisionCountSql,
|
|
4
4
|
tagRevisionKey,
|
|
5
5
|
TAG_INSERT_CONFLICT_ROWS
|
|
6
|
-
} from "./index-
|
|
6
|
+
} from "./index-yacs388s.js";
|
|
7
7
|
import {
|
|
8
8
|
getTagsBySession2,
|
|
9
9
|
getTagsByNumbers2
|
|
10
|
-
} from "./index-
|
|
10
|
+
} from "./index-pwp6zyx3.js";
|
|
11
11
|
import {
|
|
12
12
|
inRootAsyncContext2,
|
|
13
13
|
getSqliteDatabasePath2,
|
|
@@ -15,10 +15,13 @@ import {
|
|
|
15
15
|
} from "./index-2qtx0q6h.js";
|
|
16
16
|
import {
|
|
17
17
|
createFailClosedBlockingError
|
|
18
|
-
} from "./index-
|
|
18
|
+
} from "./index-3bb24eb6.js";
|
|
19
|
+
import {
|
|
20
|
+
reuseWorker
|
|
21
|
+
} from "./index-wfqysrwq.js";
|
|
19
22
|
import {
|
|
20
23
|
createWorkerShutdown
|
|
21
|
-
} from "./index-
|
|
24
|
+
} from "./index-x2n261wp.js";
|
|
22
25
|
|
|
23
26
|
// src/pi-context-budget.ts
|
|
24
27
|
var PI_CONTEXT_BUDGET = {
|
|
@@ -348,7 +351,7 @@ function startPiTagSnapshotWorker(request, options = {}) {
|
|
|
348
351
|
const entry = options.entry ?? new URL(import.meta.url.endsWith(".ts") ? "./tag-snapshot-worker-pi.ts" : "./tag-snapshot-worker-pi.js", import.meta.url);
|
|
349
352
|
const started = performance.now();
|
|
350
353
|
const consumer = createPiHydrationPacketConsumer(request, options.cached, options.byteLimit, options.cachedFallback);
|
|
351
|
-
const worker = inRootAsyncContext2(() => new Worker(entry, { workerData: request }));
|
|
354
|
+
const worker = inRootAsyncContext2(() => options.entry ? new Worker(entry, { workerData: request }) : reuseWorker(entry, { workerData: request }));
|
|
352
355
|
const shutdown = createWorkerShutdown(worker, "pi-tag-snapshot", 1000);
|
|
353
356
|
let exited = false;
|
|
354
357
|
let settled = false;
|
|
@@ -3,31 +3,33 @@ var WORKER_CLOSE_MESSAGE = { kind: "close" };
|
|
|
3
3
|
function isWorkerCloseMessage(message) {
|
|
4
4
|
return typeof message === "object" && message !== null && message.kind === WORKER_CLOSE_MESSAGE.kind;
|
|
5
5
|
}
|
|
6
|
-
function exitOnWorkerClose(port, closeConnections) {
|
|
6
|
+
function exitOnWorkerClose(port, closeConnections, exitThread = true) {
|
|
7
7
|
const listener = (message) => {
|
|
8
8
|
if (!isWorkerCloseMessage(message))
|
|
9
9
|
return;
|
|
10
10
|
try {
|
|
11
11
|
closeConnections();
|
|
12
12
|
} finally {
|
|
13
|
-
|
|
13
|
+
if (exitThread)
|
|
14
|
+
process.exit(0);
|
|
15
|
+
closePort();
|
|
14
16
|
}
|
|
15
17
|
};
|
|
16
18
|
if (!port)
|
|
17
19
|
return { closePort() {} };
|
|
18
|
-
port
|
|
20
|
+
const owner = port;
|
|
21
|
+
owner.on("message", listener);
|
|
19
22
|
let closed = false;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
};
|
|
23
|
+
function closePort() {
|
|
24
|
+
if (closed)
|
|
25
|
+
return;
|
|
26
|
+
closed = true;
|
|
27
|
+
setTimeout(() => {
|
|
28
|
+
owner.off("message", listener);
|
|
29
|
+
owner.close();
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return { closePort };
|
|
31
33
|
}
|
|
32
34
|
var outcomes = new Map;
|
|
33
35
|
function createWorkerShutdown(worker, site, deadlineMs) {
|
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import {
|
|
2
2
|
registerExitAbort
|
|
3
|
-
} from "./index-
|
|
3
|
+
} from "./index-8sqebjzk.js";
|
|
4
4
|
import {
|
|
5
5
|
log2
|
|
6
|
-
} from "./index-
|
|
6
|
+
} from "./index-gymgz20n.js";
|
|
7
7
|
import {
|
|
8
8
|
inRootAsyncContext2,
|
|
9
9
|
getSqliteDatabasePath2
|
|
10
10
|
} from "./index-2qtx0q6h.js";
|
|
11
|
+
import {
|
|
12
|
+
reuseWorker
|
|
13
|
+
} from "./index-wfqysrwq.js";
|
|
14
|
+
import {
|
|
15
|
+
createWorkerShutdown
|
|
16
|
+
} from "./index-x2n261wp.js";
|
|
11
17
|
|
|
12
18
|
// ../plugin/src/features/magic-context/compaction-marker-candidates.ts
|
|
13
19
|
import { existsSync, realpathSync } from "node:fs";
|
|
@@ -140,7 +146,7 @@ function runCandidateWorker(path, sessionId, options) {
|
|
|
140
146
|
return;
|
|
141
147
|
}
|
|
142
148
|
workers.delete(worker);
|
|
143
|
-
const stopped = worker.terminate();
|
|
149
|
+
const stopped = snapshot ? createWorkerShutdown(worker, "marker-candidates", 1000).close() : worker.terminate();
|
|
144
150
|
worker.unref();
|
|
145
151
|
stopped.then(() => resolve(snapshot), () => resolve(snapshot));
|
|
146
152
|
};
|
|
@@ -153,7 +159,7 @@ function runCandidateWorker(path, sessionId, options) {
|
|
|
153
159
|
timer.unref?.();
|
|
154
160
|
};
|
|
155
161
|
try {
|
|
156
|
-
worker = inRootAsyncContext2(() => new Worker(entry, { workerData: { path, sessionId } }));
|
|
162
|
+
worker = inRootAsyncContext2(() => options.entry ? new Worker(entry, { workerData: { path, sessionId } }) : reuseWorker(entry, { workerData: { path, sessionId } }));
|
|
157
163
|
workers.add(worker);
|
|
158
164
|
worker.unref();
|
|
159
165
|
deadline(options.acceptMs ?? 2000);
|
|
@@ -1,29 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
inRootAsyncContext2,
|
|
3
|
-
getSqliteDatabasePath2,
|
|
4
|
-
withSqliteBackgroundWriter2,
|
|
5
|
-
withoutSqliteTransformPass2,
|
|
6
|
-
isTransientSqliteError2
|
|
7
|
-
} from "./index-2qtx0q6h.js";
|
|
8
1
|
import {
|
|
9
2
|
estimateTokens
|
|
10
|
-
} from "./index-
|
|
3
|
+
} from "./index-wt7vmyj4.js";
|
|
11
4
|
import {
|
|
12
5
|
getHarness2
|
|
13
6
|
} from "./index-0h2mkab2.js";
|
|
14
7
|
import {
|
|
15
|
-
sanitizeDiagnosticText,
|
|
16
8
|
log2
|
|
17
|
-
} from "./index-
|
|
9
|
+
} from "./index-gymgz20n.js";
|
|
10
|
+
import {
|
|
11
|
+
sanitizeDiagnosticText
|
|
12
|
+
} from "./index-dnp1jjar.js";
|
|
18
13
|
import {
|
|
19
14
|
SYNAPSE_DEFAULT_MODEL,
|
|
20
15
|
isSynapseEmbeddingTruncated,
|
|
21
16
|
getSynapseBatchRequestKey,
|
|
22
17
|
SynapseEmbeddingProvider
|
|
23
|
-
} from "./index-
|
|
18
|
+
} from "./index-rzfr7wdv.js";
|
|
19
|
+
import {
|
|
20
|
+
inRootAsyncContext2,
|
|
21
|
+
getSqliteDatabasePath2
|
|
22
|
+
} from "./index-2qtx0q6h.js";
|
|
23
|
+
import {
|
|
24
|
+
reuseWorker
|
|
25
|
+
} from "./index-wfqysrwq.js";
|
|
24
26
|
import {
|
|
25
27
|
createWorkerShutdown
|
|
26
|
-
} from "./index-
|
|
28
|
+
} from "./index-x2n261wp.js";
|
|
27
29
|
import {
|
|
28
30
|
DEFAULT_COMPARTMENT_CHUNK_MAX_INPUT_TOKENS2,
|
|
29
31
|
CHUNK_WINDOW_SAFETY_RATIO2,
|
|
@@ -41,7 +43,7 @@ import {
|
|
|
41
43
|
countSessionCompartmentEmbedCoverage2,
|
|
42
44
|
countSessionCompartmentEmbedCoveragePolite2,
|
|
43
45
|
countUnembeddedSessionCompartmentsPolite2
|
|
44
|
-
} from "./index-
|
|
46
|
+
} from "./index-f9qet7y8.js";
|
|
45
47
|
import {
|
|
46
48
|
DEFAULT_LOCAL_EMBEDDING_MODEL
|
|
47
49
|
} from "./index-ccanzg8p.js";
|
|
@@ -54,10 +56,18 @@ import {
|
|
|
54
56
|
getEmbeddingProviderIdentity,
|
|
55
57
|
dominantEmbeddingFailure,
|
|
56
58
|
LocalEmbeddingProvider
|
|
57
|
-
} from "./index-
|
|
59
|
+
} from "./index-2qqsnh1b.js";
|
|
60
|
+
import {
|
|
61
|
+
embedPauseBySession,
|
|
62
|
+
activeEmbeddingSessions,
|
|
63
|
+
drainBackgroundBatches,
|
|
64
|
+
beginSynapseBatchLedger,
|
|
65
|
+
finishSynapseBatchLedger,
|
|
66
|
+
pruneSynapseBatchLedgerForProject
|
|
67
|
+
} from "./index-hgd00nas.js";
|
|
58
68
|
import {
|
|
59
69
|
setBootQuietPeriodForTests
|
|
60
|
-
} from "./index-
|
|
70
|
+
} from "./index-6pk49fc3.js";
|
|
61
71
|
import {
|
|
62
72
|
isEmbeddingHostBusy2
|
|
63
73
|
} from "./index-9p40dgkm.js";
|
|
@@ -68,7 +78,7 @@ import {
|
|
|
68
78
|
acquireGitSweepLease,
|
|
69
79
|
renewGitSweepLease,
|
|
70
80
|
releaseGitSweepLease
|
|
71
|
-
} from "./index-
|
|
81
|
+
} from "./index-mp0gh04g.js";
|
|
72
82
|
import {
|
|
73
83
|
saveEmbeddingIfHashMatches,
|
|
74
84
|
getMemoryEmbedCoverage,
|
|
@@ -79,116 +89,10 @@ import {
|
|
|
79
89
|
} from "./index-nrzkqte4.js";
|
|
80
90
|
import {
|
|
81
91
|
logSlowWriteTransaction
|
|
82
|
-
} from "./index-
|
|
83
|
-
|
|
84
|
-
// ../plugin/src/hooks/magic-context/embed-session-state.ts
|
|
85
|
-
var embedPauseBySession = new Set;
|
|
86
|
-
var embedRunStateBySession = new Map;
|
|
87
|
-
var activeEmbeddingSessions = new Map;
|
|
88
|
-
var autoEmbedAttemptedBySession = new Set;
|
|
89
|
-
var autoEmbedIdentityBySession = new Map;
|
|
90
|
-
var autoEmbedRetryAfterBySession = new Map;
|
|
91
|
-
function invalidateAutoEmbedSession(sessionId) {
|
|
92
|
-
autoEmbedAttemptedBySession.delete(sessionId);
|
|
93
|
-
autoEmbedIdentityBySession.delete(sessionId);
|
|
94
|
-
autoEmbedRetryAfterBySession.delete(sessionId);
|
|
95
|
-
}
|
|
96
|
-
function getEmbedDrainUiStatus(sessionId, progress) {
|
|
97
|
-
if (embedPauseBySession.has(sessionId)) {
|
|
98
|
-
return { status: "paused" };
|
|
99
|
-
}
|
|
100
|
-
const activeRun = embedRunStateBySession.get(sessionId);
|
|
101
|
-
if (activeRun && !activeRun.signal.aborted || progress?.kind === "embed" && progress.phase === "recomp") {
|
|
102
|
-
return { status: "running" };
|
|
103
|
-
}
|
|
104
|
-
if (progress?.kind === "embed" && (progress.phase === "failed" || progress.phase === "skipped") && progress.message) {
|
|
105
|
-
if (/provider/i.test(progress.message)) {
|
|
106
|
-
return { status: "stopped", detail: progress.message };
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
return { status: "idle" };
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// ../plugin/src/shared/background-batch-drain.ts
|
|
113
|
-
async function drainBackgroundBatches(step, options = {}) {
|
|
114
|
-
const now = options.now ?? (() => performance.now());
|
|
115
|
-
const deadline = now() + (options.budgetMs ?? 2000);
|
|
116
|
-
const yieldFn = options.yieldFn ?? (() => new Promise((resolve) => setTimeout(resolve, 0)));
|
|
117
|
-
let batches = 0;
|
|
118
|
-
while (now() < deadline) {
|
|
119
|
-
try {
|
|
120
|
-
if (!withoutSqliteTransformPass2(() => withSqliteBackgroundWriter2(step)))
|
|
121
|
-
break;
|
|
122
|
-
} catch (error) {
|
|
123
|
-
if (isTransientSqliteError2(error))
|
|
124
|
-
break;
|
|
125
|
-
throw error;
|
|
126
|
-
}
|
|
127
|
-
batches++;
|
|
128
|
-
await yieldFn();
|
|
129
|
-
}
|
|
130
|
-
return batches;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// ../plugin/src/features/magic-context/storage-embedding-measurements.ts
|
|
134
|
-
import { createHash } from "node:crypto";
|
|
135
|
-
function normalizedQueryHash(query) {
|
|
136
|
-
const normalized = query.trim().replace(/\s+/g, " ").toLowerCase();
|
|
137
|
-
return createHash("sha256").update(normalized).digest("hex");
|
|
138
|
-
}
|
|
139
|
-
var MEASUREMENT_CORPUS_SESSION_ROW_CAP = 2000;
|
|
140
|
-
function recordEmbeddingMeasurement(db, input, cap = MEASUREMENT_CORPUS_SESSION_ROW_CAP) {
|
|
141
|
-
const queryTextHash = normalizedQueryHash(input.queryText);
|
|
142
|
-
const dedupKey = queryTextHash;
|
|
143
|
-
const result = db.prepare(`INSERT OR IGNORE INTO embedding_measurement_corpus
|
|
144
|
-
(session_id, project_path, dedup_key, cohort_key, query_text_hash,
|
|
145
|
-
primary_result_ids_json, shadow_result_ids_json, primary_latency_ms, shadow_latency_ms,
|
|
146
|
-
primary_failed, shadow_failed, primary_model_id, shadow_model_id,
|
|
147
|
-
primary_fingerprint, shadow_fingerprint, primary_epoch, shadow_epoch,
|
|
148
|
-
corpus_hash, coverage_json, created_at)
|
|
149
|
-
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());
|
|
150
|
-
if (result.changes > 0) {
|
|
151
|
-
const rowCount = db.prepare("SELECT COUNT(*) AS count FROM embedding_measurement_corpus WHERE session_id = ?").get(input.sessionId).count;
|
|
152
|
-
const overflow = rowCount - cap;
|
|
153
|
-
if (overflow > 0) {
|
|
154
|
-
db.prepare(`DELETE FROM embedding_measurement_corpus
|
|
155
|
-
WHERE session_id = ?
|
|
156
|
-
AND id IN (
|
|
157
|
-
SELECT id FROM embedding_measurement_corpus
|
|
158
|
-
WHERE session_id = ?
|
|
159
|
-
ORDER BY id ASC
|
|
160
|
-
LIMIT ?
|
|
161
|
-
)`).run(input.sessionId, input.sessionId, overflow);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
return result.changes > 0;
|
|
165
|
-
}
|
|
166
|
-
function beginSynapseBatchLedger(db, input, now = Date.now()) {
|
|
167
|
-
db.prepare(`INSERT INTO synapse_batch_ledger
|
|
168
|
-
(session_id, project_path, scope, manifest_json, request_key, status, created_at, updated_at)
|
|
169
|
-
VALUES (?, ?, ?, ?, ?, 'pending', ?, ?)
|
|
170
|
-
ON CONFLICT(session_id, request_key) DO UPDATE SET
|
|
171
|
-
manifest_json = excluded.manifest_json,
|
|
172
|
-
updated_at = excluded.updated_at`).run(input.sessionId, input.projectPath, input.scope, JSON.stringify(input.manifest), input.requestKey, now, now);
|
|
173
|
-
}
|
|
174
|
-
function finishSynapseBatchLedger(db, sessionId, requestKey, status, now = Date.now()) {
|
|
175
|
-
db.prepare("UPDATE synapse_batch_ledger SET status = ?, updated_at = ? WHERE session_id = ? AND request_key = ?").run(status, now, sessionId, requestKey);
|
|
176
|
-
}
|
|
177
|
-
var SYNAPSE_BATCH_LEDGER_TTL_MS = 14 * 24 * 60 * 60 * 1000;
|
|
178
|
-
function pruneSynapseBatchLedgerForProject(db, projectIdentity, ttlMs = SYNAPSE_BATCH_LEDGER_TTL_MS) {
|
|
179
|
-
const ledgerTable = db.prepare("SELECT 1 AS present FROM sqlite_master WHERE type = 'table' AND name = 'synapse_batch_ledger'").get();
|
|
180
|
-
if (!ledgerTable)
|
|
181
|
-
return 0;
|
|
182
|
-
const shadow = `shadow:${projectIdentity}`;
|
|
183
|
-
const cutoff = Date.now() - ttlMs;
|
|
184
|
-
const predicate = "session_id IN (?, ?) AND updated_at < ?";
|
|
185
|
-
if (!db.prepare(`SELECT 1 FROM synapse_batch_ledger WHERE ${predicate} LIMIT 1`).get(projectIdentity, shadow, cutoff))
|
|
186
|
-
return 0;
|
|
187
|
-
return db.prepare(`DELETE FROM synapse_batch_ledger WHERE ${predicate}`).run(projectIdentity, shadow, cutoff).changes;
|
|
188
|
-
}
|
|
92
|
+
} from "./index-0wtm7g7f.js";
|
|
189
93
|
|
|
190
94
|
// ../plugin/src/features/magic-context/memory/embedding-openai.ts
|
|
191
|
-
import { createHash
|
|
95
|
+
import { createHash } from "node:crypto";
|
|
192
96
|
|
|
193
97
|
// ../plugin/src/features/magic-context/memory/embedding-ssrf.ts
|
|
194
98
|
var METADATA_HOSTNAMES = new Set(["metadata.google.internal", "metadata.goog"]);
|
|
@@ -295,7 +199,7 @@ var RATE_LIMIT_BACKOFF_CAP_MS = 30000;
|
|
|
295
199
|
var RATE_LIMIT_BACKOFF_JITTER = 0.25;
|
|
296
200
|
var rateLimitStates = new Map;
|
|
297
201
|
function rateLimitStateKey(endpoint, apiKey) {
|
|
298
|
-
const keyHash = apiKey ?
|
|
202
|
+
const keyHash = apiKey ? createHash("sha256").update(apiKey).digest("hex").slice(0, 16) : "";
|
|
299
203
|
return `${endpoint}\x00${keyHash}`;
|
|
300
204
|
}
|
|
301
205
|
function parseRetryAfterMs(value, nowMs) {
|
|
@@ -707,10 +611,9 @@ class OpenAICompatibleEmbeddingProvider {
|
|
|
707
611
|
}
|
|
708
612
|
|
|
709
613
|
// ../plugin/src/features/magic-context/project-embedding-registry.ts
|
|
710
|
-
import { createHash as
|
|
614
|
+
import { createHash as createHash2, randomUUID } from "node:crypto";
|
|
711
615
|
|
|
712
616
|
// ../plugin/src/features/magic-context/chunk-embedding-writer.ts
|
|
713
|
-
import { Worker } from "node:worker_threads";
|
|
714
617
|
function createChunkEmbeddingWriter(db) {
|
|
715
618
|
const path = getSqliteDatabasePath2(db);
|
|
716
619
|
if (!path)
|
|
@@ -719,7 +622,7 @@ function createChunkEmbeddingWriter(db) {
|
|
|
719
622
|
throw new Error("chunk embedding writer requires a filesystem path");
|
|
720
623
|
const entry = new URL(import.meta.url.endsWith(".ts") ? "./chunk-embedding-write-worker.ts" : "./chunk-embedding-write-worker.js", import.meta.url);
|
|
721
624
|
const timeout = db.prepare("PRAGMA busy_timeout").get().timeout;
|
|
722
|
-
const worker = inRootAsyncContext2(() =>
|
|
625
|
+
const worker = inRootAsyncContext2(() => reuseWorker(entry, { workerData: { path, harness: getHarness2(), timeout } }));
|
|
723
626
|
const shutdown = createWorkerShutdown(worker, "chunk-embedding-writer", timeout + 2000);
|
|
724
627
|
let pending;
|
|
725
628
|
let failure;
|
|
@@ -1379,10 +1282,10 @@ function stableStringify(value) {
|
|
|
1379
1282
|
return JSON.stringify(value);
|
|
1380
1283
|
}
|
|
1381
1284
|
function sha256Prefix(value, length = 16) {
|
|
1382
|
-
return
|
|
1285
|
+
return createHash2("sha256").update(value).digest("hex").slice(0, length);
|
|
1383
1286
|
}
|
|
1384
1287
|
function contentSha2562(value) {
|
|
1385
|
-
return
|
|
1288
|
+
return createHash2("sha256").update(value).digest("hex");
|
|
1386
1289
|
}
|
|
1387
1290
|
function getRuntimeFingerprint(config) {
|
|
1388
1291
|
if (config.provider === "off") {
|
|
@@ -3183,4 +3086,4 @@ function _resetProjectEmbeddingRegistryForTests2() {
|
|
|
3183
3086
|
setBootQuietPeriodForTests(null);
|
|
3184
3087
|
}
|
|
3185
3088
|
|
|
3186
|
-
export {
|
|
3089
|
+
export { OpenAICompatibleEmbeddingProvider, saveCommitEmbedding, loadProjectCommitEmbeddings, loadUnembeddedCommits, countEmbeddedCommits, upsertCommits, getLatestIndexedCommitSha, enforceProjectCap, describeShadowBackfillWriteRefusal2, listShadowBackfillStalls2, getShadowBackfillStopReason2, markProjectLoadUntrusted2, contentSha2562, drainProjectEmbeddingIdentityMaintenance2, drainStaleEmbeddingIdentitiesForProject2, registerProjectEmbedding2, registerProjectShadowEmbedding2, getShadowEmbeddingMeasurementCohort2, getPrimaryEmbeddingMeasurementCohort2, embedShadowTextForProject2, enqueueShadowEmbeddingItems2, getShadowBackfillRemaining2, flushShadowEmbeddingBacklog2, registerProjectInObservationMode2, unregisterProjectShadowEmbedding2, unregisterProjectEmbedding2, getProjectEmbeddingSnapshot2, installProjectEmbeddingSearchBridge2, getProjectChunkEmbeddingModelId2, getProjectEmbeddingMaxInputTokens2, embedTextForProject2, embedBatchForProject2, embedItemsForProject2, embedUnembeddedMemoriesForProject2, drainCommitBacklogForProject2, embedUnembeddedCompartmentChunksForProject2, embedSessionCompartmentChunks2, getEmbeddingCoverageStatus2, getAutoEmbeddingSessionCoverage2, sweepAllRegisteredProjects2, _setTestProviderFactoryForProject2, _resetProjectEmbeddingRegistryForTests2 };
|