@cortexkit/pi-magic-context 0.49.83 → 0.49.85
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 +3 -3
- package/dist/chunk-embedding-write-worker.js +5 -4
- package/dist/{embedding-backfill-yh10bmx5.js → embedding-backfill-7a01ns95.js} +6 -5
- package/dist/embedding-worker.js +14 -27
- package/dist/{index-e0zdn1p3.js → index-53fgdt6n.js} +1 -1
- package/dist/{index-47g3pgzk.js → index-7v0z62ek.js} +6 -6
- package/dist/{index-xz5b9t4g.js → index-7yz95h83.js} +38 -736
- package/dist/index-8x8wtn3t.js +1083 -0
- package/dist/{index-hna2sxy8.js → index-94z1xzmr.js} +3 -3
- package/dist/{index-qz43gkqe.js → index-bjr11ay6.js} +24 -26
- package/dist/{index-qky62xze.js → index-ddfjg278.js} +23 -0
- package/dist/{index-gdy08gn6.js → index-ex9te7tc.js} +1 -1
- package/dist/{index-wtqv3vha.js → index-fd57gfnn.js} +4 -4
- package/dist/{index-nmmge3j6.js → index-gbc29ysq.js} +1 -1
- package/dist/{index-txcs0vnj.js → index-rqdjb6j3.js} +461 -273
- package/dist/{index-k8xz22jc.js → index-sqp84q6s.js} +1 -1
- package/dist/{index-y573dt51.js → index-ty0tvxhm.js} +43 -20
- package/dist/{index-3g1wy4z9.js → index-wy6h2wn2.js} +22 -10
- package/dist/index.js +61 -57
- package/dist/migration-worker.js +5 -4
- package/dist/{project-embedding-registry-3sss39rx.js → project-embedding-registry-agkd7egh.js} +7 -4
- package/dist/raw-ordinal-warmup-worker.js +2 -2
- package/dist/{render-9xgp0jka.js → render-rphfegr8.js} +7 -6
- package/dist/{search-archive-wr38qtkw.js → search-archive-7p43e77j.js} +1 -1
- package/dist/{search-dh4ryftv.js → search-pwafh0v5.js} +9 -8
- package/dist/{store-xg9ez6jn.js → store-ekaexkvc.js} +5 -2
- package/dist/{store-reader-8j41p18c.js → store-reader-vwphd51b.js} +1 -1
- package/dist/subagent-entry.js +17 -17
- package/dist/tag-snapshot-worker-pi.js +5 -4
- package/dist/{v2-archive-reader-8m9mw6sv.js → v2-archive-reader-qc4c9wrp.js} +1 -1
- package/package.json +1 -1
- package/dist/index-81nthk8j.js +0 -193
|
@@ -2,15 +2,15 @@ import {
|
|
|
2
2
|
getMagicContextStorageDir,
|
|
3
3
|
log2
|
|
4
4
|
} from "./index-tm11k42a.js";
|
|
5
|
+
import {
|
|
6
|
+
writeStorageFileAtomicSync
|
|
7
|
+
} from "./index-8x8wtn3t.js";
|
|
5
8
|
import {
|
|
6
9
|
inRootAsyncContext2
|
|
7
10
|
} from "./index-2qtx0q6h.js";
|
|
8
11
|
import {
|
|
9
12
|
projectDirectoryKey
|
|
10
13
|
} from "./index-wrr9rp9a.js";
|
|
11
|
-
import {
|
|
12
|
-
writeStorageFileAtomicSync
|
|
13
|
-
} from "./index-81nthk8j.js";
|
|
14
14
|
|
|
15
15
|
// ../plugin/src/features/magic-context/memory/project-identity.ts
|
|
16
16
|
import { execFileSync } from "node:child_process";
|
|
@@ -60,8 +60,13 @@ import {
|
|
|
60
60
|
} from "./index-2qtx0q6h.js";
|
|
61
61
|
import {
|
|
62
62
|
isPidAlive,
|
|
63
|
-
readProcessStartTime
|
|
64
|
-
|
|
63
|
+
readProcessStartTime,
|
|
64
|
+
ensurePrivateStorageDirectorySync,
|
|
65
|
+
writeStorageFileSync,
|
|
66
|
+
writeStorageFileAtomicSync,
|
|
67
|
+
syncStorageDirectorySync,
|
|
68
|
+
writeStorageFileDurableAtomicSync
|
|
69
|
+
} from "./index-8x8wtn3t.js";
|
|
65
70
|
import {
|
|
66
71
|
withReadOnlySessionDb,
|
|
67
72
|
expandToolPart,
|
|
@@ -71,7 +76,7 @@ import {
|
|
|
71
76
|
import {
|
|
72
77
|
gaDatabasePath2,
|
|
73
78
|
V2StoreReader2
|
|
74
|
-
} from "./index-
|
|
79
|
+
} from "./index-ddfjg278.js";
|
|
75
80
|
import {
|
|
76
81
|
deleteUnmappedMessageFtsRows2
|
|
77
82
|
} from "./index-ghp32f9m.js";
|
|
@@ -85,29 +90,22 @@ import {
|
|
|
85
90
|
import {
|
|
86
91
|
layoutLkgPrefix,
|
|
87
92
|
assembleLkgPrefix
|
|
88
|
-
} from "./index-
|
|
93
|
+
} from "./index-53fgdt6n.js";
|
|
89
94
|
import {
|
|
90
95
|
logSlowWriteTransaction
|
|
91
96
|
} from "./index-1ts77n1b.js";
|
|
92
|
-
import {
|
|
93
|
-
ensurePrivateStorageDirectorySync,
|
|
94
|
-
writeStorageFileSync,
|
|
95
|
-
writeStorageFileAtomicSync,
|
|
96
|
-
syncStorageDirectorySync,
|
|
97
|
-
writeStorageFileDurableAtomicSync
|
|
98
|
-
} from "./index-81nthk8j.js";
|
|
99
97
|
// ../plugin/src/features/magic-context/storage-meta-session.ts
|
|
100
98
|
import { Buffer as Buffer2 } from "node:buffer";
|
|
101
99
|
|
|
102
100
|
// ../plugin/src/hooks/magic-context/lkg-recovery-fence.ts
|
|
103
101
|
import { createHash as createHash2, randomUUID as randomUUID2 } from "node:crypto";
|
|
104
|
-
import { lstatSync,
|
|
105
|
-
import {
|
|
102
|
+
import { lstatSync, readFileSync as readFileSync2, rmdirSync as rmdirSync2, rmSync as rmSync2 } from "node:fs";
|
|
103
|
+
import { dirname, join as join2 } from "node:path";
|
|
106
104
|
|
|
107
105
|
// ../plugin/src/shared/storage-file-mutex.ts
|
|
108
106
|
import { execFileSync } from "node:child_process";
|
|
109
107
|
import { createHash, randomUUID } from "node:crypto";
|
|
110
|
-
import { readdirSync, readFileSync, rmSync } from "node:fs";
|
|
108
|
+
import { readdirSync, readFileSync, rmdirSync, rmSync } from "node:fs";
|
|
111
109
|
import { join } from "node:path";
|
|
112
110
|
var ticketChecksum = (name, ticket) => createHash("sha256").update(JSON.stringify([name, ticket.choosing, ticket.number, ticket.birth])).digest("hex");
|
|
113
111
|
function processBirth(pid) {
|
|
@@ -140,23 +138,23 @@ function processBirth(pid) {
|
|
|
140
138
|
}
|
|
141
139
|
var pause = new Int32Array(new SharedArrayBuffer(4));
|
|
142
140
|
function withStorageFileMutex(directory, work, timeoutMs = 1000) {
|
|
143
|
-
|
|
141
|
+
const deadline = performance.now() + timeoutMs;
|
|
144
142
|
const name = `${process.pid}-${randomUUID()}.lock`;
|
|
145
143
|
const ownPath = join(directory, name);
|
|
146
144
|
const birth = processBirth(process.pid);
|
|
147
145
|
const ticket = { choosing: true, number: 0, birth, checksum: "" };
|
|
148
146
|
const encodedTicket = () => JSON.stringify({ ...ticket, checksum: ticketChecksum(name, ticket) });
|
|
149
|
-
for (
|
|
147
|
+
for (;; ) {
|
|
150
148
|
try {
|
|
149
|
+
ensurePrivateStorageDirectorySync(directory);
|
|
151
150
|
writeStorageFileSync(ownPath, encodedTicket(), { flag: "wx", forcePrivate: true });
|
|
152
151
|
break;
|
|
153
152
|
} catch (error) {
|
|
154
|
-
|
|
153
|
+
const code = error.code;
|
|
154
|
+
if (code !== "ENOENT" && code !== "EEXIST" && code !== "EINVAL" || performance.now() >= deadline)
|
|
155
155
|
throw error;
|
|
156
|
-
ensurePrivateStorageDirectorySync(directory);
|
|
157
156
|
}
|
|
158
157
|
}
|
|
159
|
-
const deadline = performance.now() + timeoutMs;
|
|
160
158
|
const peers = () => {
|
|
161
159
|
const found = [];
|
|
162
160
|
for (const other of readdirSync(directory)) {
|
|
@@ -198,6 +196,9 @@ function withStorageFileMutex(directory, work, timeoutMs = 1000) {
|
|
|
198
196
|
return result;
|
|
199
197
|
} finally {
|
|
200
198
|
rmSync(ownPath, { force: true });
|
|
199
|
+
try {
|
|
200
|
+
rmdirSync(directory);
|
|
201
|
+
} catch {}
|
|
201
202
|
}
|
|
202
203
|
}
|
|
203
204
|
|
|
@@ -283,7 +284,7 @@ function publishRecord(record) {
|
|
|
283
284
|
try {
|
|
284
285
|
if (record.state === "clean")
|
|
285
286
|
observer?.("clean");
|
|
286
|
-
writeStorageFileDurableAtomicSync(lkgRecoveryFencePath(record.sessionId), JSON.stringify({ ...record, checksum: hash(JSON.stringify(payload(record))) }), () => observer?.("temp-synced"));
|
|
287
|
+
writeStorageFileDurableAtomicSync(lkgRecoveryFencePath(record.sessionId), JSON.stringify({ ...record, checksum: hash(JSON.stringify(payload(record))) }), () => observer?.("temp-synced"), `${lkgRecoveryFencePath(record.sessionId)}.tmp`);
|
|
287
288
|
if (record.state === "dirty")
|
|
288
289
|
observer?.("dirty");
|
|
289
290
|
remember(record.sessionId, {
|
|
@@ -294,7 +295,7 @@ function publishRecord(record) {
|
|
|
294
295
|
const visible = read(record.sessionId);
|
|
295
296
|
if (record.state === "clean" && visible?.state === "clean" && visible.revision === record.revision && visible.slotKey === record.slotKey) {
|
|
296
297
|
const dirty = { ...record, state: "dirty" };
|
|
297
|
-
writeStorageFileDurableAtomicSync(lkgRecoveryFencePath(record.sessionId), JSON.stringify({ ...dirty, checksum: hash(JSON.stringify(payload(dirty))) }));
|
|
298
|
+
writeStorageFileDurableAtomicSync(lkgRecoveryFencePath(record.sessionId), JSON.stringify({ ...dirty, checksum: hash(JSON.stringify(payload(dirty))) }), undefined, `${lkgRecoveryFencePath(record.sessionId)}.tmp`);
|
|
298
299
|
}
|
|
299
300
|
remember(record.sessionId, { state: "invalid", record: null });
|
|
300
301
|
throw error;
|
|
@@ -334,10 +335,7 @@ function locked(sessionId, work) {
|
|
|
334
335
|
ioObserver?.("mutex");
|
|
335
336
|
return withStorageFileMutex(`${lkgRecoveryFencePath(sessionId)}.locks`, () => {
|
|
336
337
|
const path = lkgRecoveryFencePath(sessionId);
|
|
337
|
-
|
|
338
|
-
if (name.startsWith(`${basename(path)}.`) && name.endsWith(".tmp"))
|
|
339
|
-
rmSync2(join2(dirname(path), name), { force: true });
|
|
340
|
-
}
|
|
338
|
+
rmSync2(`${path}.tmp`, { force: true });
|
|
341
339
|
return work();
|
|
342
340
|
});
|
|
343
341
|
}
|
|
@@ -477,7 +475,7 @@ function clearLkgRecoveryFence(sessionId, remove, shouldClear) {
|
|
|
477
475
|
});
|
|
478
476
|
} finally {
|
|
479
477
|
try {
|
|
480
|
-
|
|
478
|
+
rmdirSync2(`${path}.locks`);
|
|
481
479
|
} catch {}
|
|
482
480
|
}
|
|
483
481
|
}
|
|
@@ -736,6 +736,29 @@ class V2StoreReader2 {
|
|
|
736
736
|
return null;
|
|
737
737
|
}
|
|
738
738
|
}
|
|
739
|
+
revertSuffix(sessionID, cutoff, limit) {
|
|
740
|
+
const rows = this.prepare(`WITH target AS (SELECT seq FROM session_message WHERE session_id = ? AND id = ?),
|
|
741
|
+
preceding AS (SELECT MAX(seq) AS seq FROM session_message
|
|
742
|
+
WHERE session_id = ? AND seq < (SELECT seq FROM target))
|
|
743
|
+
SELECT id, seq FROM session_message
|
|
744
|
+
WHERE session_id = ? AND seq >= (SELECT seq FROM preceding)
|
|
745
|
+
ORDER BY seq ASC LIMIT ?`).all(sessionID, cutoff, sessionID, sessionID, limit + 2);
|
|
746
|
+
const [predecessor, boundary] = rows;
|
|
747
|
+
if (!predecessor || boundary?.id !== cutoff || rows.length > limit + 1)
|
|
748
|
+
return;
|
|
749
|
+
return { predecessor, messageIDs: rows.slice(1).map(({ id }) => id) };
|
|
750
|
+
}
|
|
751
|
+
removedRevertMessages(sessionID, suffix) {
|
|
752
|
+
const { predecessor, messageIDs } = suffix;
|
|
753
|
+
const result = this.prepare(`SELECT CASE WHEN EXISTS (SELECT 1 FROM session_v2 WHERE id = ?)
|
|
754
|
+
AND EXISTS (SELECT 1 FROM session_message
|
|
755
|
+
WHERE session_id = ? AND id = ? AND seq = ?)
|
|
756
|
+
THEN (SELECT json_group_array(value) FROM json_each(?) AS staged
|
|
757
|
+
WHERE NOT EXISTS (SELECT 1 FROM session_message AS retained
|
|
758
|
+
WHERE retained.session_id = ? AND retained.id = staged.value))
|
|
759
|
+
END AS missing`).get(sessionID, sessionID, predecessor.id, predecessor.seq, JSON.stringify(messageIDs), sessionID);
|
|
760
|
+
return result.missing === null ? undefined : new Set(JSON.parse(result.missing));
|
|
761
|
+
}
|
|
739
762
|
sessionExists(sessionID) {
|
|
740
763
|
return this.prepare("SELECT 1 FROM session_v2 WHERE id = ?").get(sessionID) != null;
|
|
741
764
|
}
|
|
@@ -137,11 +137,11 @@ async function serveV2ArchiveReads2(port, openConnections) {
|
|
|
137
137
|
{ createV2RecoveryAttachments }
|
|
138
138
|
] = await Promise.all([
|
|
139
139
|
import("./sqlite-v89bj0yy.js"),
|
|
140
|
-
import("./store-reader-
|
|
141
|
-
import("./store-
|
|
140
|
+
import("./store-reader-vwphd51b.js"),
|
|
141
|
+
import("./store-ekaexkvc.js"),
|
|
142
142
|
import("./read-session-chunk-wek7gb7j.js"),
|
|
143
|
-
import("./render-
|
|
144
|
-
import("./search-archive-
|
|
143
|
+
import("./render-rphfegr8.js"),
|
|
144
|
+
import("./search-archive-7p43e77j.js"),
|
|
145
145
|
import("./expand-attachments-8sxeyj26.js")
|
|
146
146
|
]);
|
|
147
147
|
const pool = new V2StoreReaderPool;
|