@cortexkit/pi-magic-context 0.47.0 → 0.48.0
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 +27 -22
- package/dist/embedding-activity-ew6dshfd.js +10 -0
- package/dist/embedding-backfill-bnnytehy.js +20 -0
- package/dist/embedding-cache-7rp4gqzr.js +16 -0
- package/dist/embedding-worker.js +11 -8
- package/dist/harness-9872e0ym.js +10 -0
- package/dist/historian-calibration-extension.js +3 -2
- package/dist/index-0am8a7k1.js +152 -0
- package/dist/index-0h2mkab2.js +17 -0
- package/dist/index-135e8hvg.js +43 -0
- package/dist/{index-0qejsd7f.js → index-3cgbv47m.js} +289 -45
- package/dist/index-419bndtm.js +2309 -0
- package/dist/index-544c0e0x.js +3026 -0
- package/dist/index-5hd7h4rr.js +3098 -0
- package/dist/index-5jp1h0bz.js +750 -0
- package/dist/index-603mt6nm.js +171 -0
- package/dist/index-674f6qs2.js +16 -0
- package/dist/{index-vgcemg0n.js → index-6pgq5ns2.js} +151 -2452
- package/dist/{index-xpbh1ypk.js → index-72bdc1bd.js} +38 -741
- package/dist/index-8976mezv.js +209 -0
- package/dist/{index-td885aah.js → index-8y5knskr.js} +98 -231
- package/dist/{index-k3ezsjng.js → index-98z1c1r0.js} +14574 -13942
- package/dist/index-9p40dgkm.js +22 -0
- package/dist/index-9x1f96r8.js +11 -0
- package/dist/{index-266qrgss.js → index-9xb0axhc.js} +301 -27
- package/dist/{index-spk5vrhy.js → index-bgmv2kaf.js} +1 -16
- package/dist/index-dkx0b1kt.js +514 -0
- package/dist/{index-7n8gb6j3.js → index-f956htf3.js} +28 -31
- package/dist/index-fapenpch.js +13 -0
- package/dist/index-fm3ksh5e.js +1060 -0
- package/dist/{index-2p1e8706.js → index-fp37he9a.js} +3 -3
- package/dist/index-hrf13mn3.js +2388 -0
- package/dist/index-pvm4pd5d.js +3069 -0
- package/dist/{index-kztsbkqq.js → index-r7xg4hvw.js} +171 -168
- package/dist/index-rt5jgzp1.js +1127 -0
- package/dist/{index-n3g5mwa8.js → index-wrm4nbj7.js} +3 -3
- package/dist/index-xjqheg7a.js +931 -0
- package/dist/index-yhzhdp3m.js +143 -0
- package/dist/{index-w76x3af7.js → index-zrr5t5a7.js} +1 -3
- package/dist/index.js +4203 -2183
- package/dist/logger-v3dsxdnm.js +19 -0
- package/dist/message-index-bounded-t7vvty76.js +120 -0
- package/dist/{message-time-backfill-d3db2etr.js → message-time-backfill-4ndf7hrq.js} +7 -6
- package/dist/migration-worker.js +20 -14
- package/dist/project-embedding-registry-jy2hmq28.js +85 -0
- package/dist/raw-ordinal-warmup-worker.js +60 -0
- package/dist/{read-session-chunk-atxsyfqv.js → read-session-chunk-47pjn7fz.js} +12 -6
- package/dist/read-session-raw-yn8nawav.js +55 -0
- package/dist/{safe-notification-target-6cn3z99t.js → safe-notification-target-3c1ns931.js} +3 -2
- package/dist/search-42szfhwp.js +40 -0
- package/dist/sqlite-3yye76ht.js +44 -0
- package/dist/sqlite-context-pragmas-gcgch6qz.js +6 -0
- package/dist/storage-memory-1z20y55x.js +71 -0
- package/dist/storage-tags-jym5z6yk.js +127 -0
- package/dist/subagent-entry.js +34 -17
- package/dist/transformers-node-wasm.js +18415 -18415
- package/package.json +3 -3
- package/dist/index-7s8vw2y0.js +0 -5207
- package/dist/index-qaa5j277.js +0 -8544
- /package/dist/{index-en1k8h8m.js → index-5prbx026.js} +0 -0
|
@@ -1,24 +1,31 @@
|
|
|
1
1
|
import {
|
|
2
|
-
harnessOwnsOpenCodeStore,
|
|
3
2
|
getMagicContextStorageDir,
|
|
4
3
|
getLegacyOpenCodeMagicContextStorageDir,
|
|
5
4
|
sanitizeDiagnosticText,
|
|
6
5
|
importPluginModule,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} from "./index-
|
|
6
|
+
writeForwardedLogLine2,
|
|
7
|
+
log2
|
|
8
|
+
} from "./index-f956htf3.js";
|
|
10
9
|
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
10
|
+
harnessOwnsOpenCodeStore2
|
|
11
|
+
} from "./index-0h2mkab2.js";
|
|
12
|
+
import {
|
|
13
|
+
registerSlowWriteReporter2,
|
|
14
|
+
registerSqliteDiagnosticSink2,
|
|
15
|
+
detectSqliteRuntime2,
|
|
16
|
+
Database2,
|
|
17
|
+
withSqliteBackgroundWriter2,
|
|
18
|
+
withoutSqliteTransformPass2,
|
|
19
|
+
isTransientSqliteError2,
|
|
20
|
+
withPrivilegedWriter2
|
|
21
|
+
} from "./index-3cgbv47m.js";
|
|
22
|
+
import {
|
|
23
|
+
configureContextDatabasePragmas2
|
|
24
|
+
} from "./index-fapenpch.js";
|
|
25
|
+
import {
|
|
26
|
+
startMessageFtsRowidMapBackfill
|
|
27
|
+
} from "./index-603mt6nm.js";
|
|
20
28
|
import {
|
|
21
|
-
startMessageFtsRowidMapBackfill,
|
|
22
29
|
LKG_SLOT_CHUNKS_DDL,
|
|
23
30
|
SESSION_REPLAY_DECISIONS_DDL,
|
|
24
31
|
LKG_SLOTS_DDL,
|
|
@@ -26,19 +33,27 @@ import {
|
|
|
26
33
|
FORK_MIGRATION_VERSION_FLOOR,
|
|
27
34
|
hasPendingMigrations,
|
|
28
35
|
getMainThreadMigrationBodyCount,
|
|
29
|
-
runMigrations
|
|
30
|
-
|
|
31
|
-
scheduleAfterBootQuiet
|
|
32
|
-
} from "./index-xpbh1ypk.js";
|
|
36
|
+
runMigrations
|
|
37
|
+
} from "./index-72bdc1bd.js";
|
|
33
38
|
import {
|
|
34
39
|
closeQuietly,
|
|
35
40
|
ensureColumn,
|
|
36
41
|
installV95PerfSchema,
|
|
42
|
+
installTagIdentityRevisionTrigger
|
|
43
|
+
} from "./index-8y5knskr.js";
|
|
44
|
+
import {
|
|
37
45
|
resolveOpenCodeDbPath,
|
|
38
46
|
hasV1MessageTables,
|
|
39
47
|
setDatabase,
|
|
40
48
|
loadToolDefinitionMeasurements
|
|
41
|
-
} from "./index-
|
|
49
|
+
} from "./index-8976mezv.js";
|
|
50
|
+
import {
|
|
51
|
+
bootQuietRemainingMs,
|
|
52
|
+
scheduleAfterBootQuiet
|
|
53
|
+
} from "./index-dkx0b1kt.js";
|
|
54
|
+
import {
|
|
55
|
+
logSlowWriteTransaction
|
|
56
|
+
} from "./index-fp37he9a.js";
|
|
42
57
|
import {
|
|
43
58
|
shouldEnforcePrivateStoragePermissions,
|
|
44
59
|
ensureStorageDirectorySync,
|
|
@@ -47,9 +62,6 @@ import {
|
|
|
47
62
|
copyStorageTreeSync,
|
|
48
63
|
tightenStorageTreeSync
|
|
49
64
|
} from "./index-vf38qhee.js";
|
|
50
|
-
import {
|
|
51
|
-
logSlowWriteTransaction
|
|
52
|
-
} from "./index-2p1e8706.js";
|
|
53
65
|
|
|
54
66
|
// ../plugin/src/features/magic-context/fail-closed-block.ts
|
|
55
67
|
var FAIL_CLOSED_DOCTOR_COMMAND = "npx @cortexkit/magic-context@latest doctor";
|
|
@@ -275,93 +287,6 @@ function createFailClosedController(options) {
|
|
|
275
287
|
};
|
|
276
288
|
}
|
|
277
289
|
|
|
278
|
-
// ../plugin/src/features/magic-context/storage-db.ts
|
|
279
|
-
import {
|
|
280
|
-
existsSync as existsSync2,
|
|
281
|
-
readdirSync,
|
|
282
|
-
readFileSync as readFileSync2,
|
|
283
|
-
rmdirSync,
|
|
284
|
-
statSync,
|
|
285
|
-
unlinkSync
|
|
286
|
-
} from "node:fs";
|
|
287
|
-
import { basename, dirname, join, resolve } from "node:path";
|
|
288
|
-
|
|
289
|
-
// ../plugin/src/shared/error-message.ts
|
|
290
|
-
function getErrorMessage(error) {
|
|
291
|
-
return error instanceof Error ? error.message : String(error);
|
|
292
|
-
}
|
|
293
|
-
function readString(value) {
|
|
294
|
-
if (typeof value === "string" && value.length > 0)
|
|
295
|
-
return value;
|
|
296
|
-
if (typeof value === "number")
|
|
297
|
-
return String(value);
|
|
298
|
-
return;
|
|
299
|
-
}
|
|
300
|
-
function clip(value, max) {
|
|
301
|
-
if (value.length <= max)
|
|
302
|
-
return value;
|
|
303
|
-
return `${value.slice(0, max)}…`;
|
|
304
|
-
}
|
|
305
|
-
function describeError(error) {
|
|
306
|
-
const stringForm = clip(safeString(error), 400);
|
|
307
|
-
if (!(error instanceof Error) && !(error && typeof error === "object")) {
|
|
308
|
-
return {
|
|
309
|
-
name: typeof error,
|
|
310
|
-
message: "",
|
|
311
|
-
stringForm,
|
|
312
|
-
brief: stringForm || "<empty>"
|
|
313
|
-
};
|
|
314
|
-
}
|
|
315
|
-
const obj = error;
|
|
316
|
-
const nameFromField = readString(obj.name);
|
|
317
|
-
const nameFromCtor = error?.constructor?.name;
|
|
318
|
-
const name = nameFromField ?? nameFromCtor ?? "Error";
|
|
319
|
-
const message = readString(obj.message) ?? "";
|
|
320
|
-
const status = readString(obj.status) ?? readString(obj.statusCode);
|
|
321
|
-
const code = readString(obj.code);
|
|
322
|
-
let causeName;
|
|
323
|
-
const cause = obj.cause;
|
|
324
|
-
if (cause && typeof cause === "object") {
|
|
325
|
-
const causeRecord = cause;
|
|
326
|
-
causeName = readString(causeRecord.name) ?? cause.constructor?.name;
|
|
327
|
-
}
|
|
328
|
-
const stack = readString(obj.stack);
|
|
329
|
-
const stackHead = stack ? stack.split(`
|
|
330
|
-
`).slice(0, 4).map((l) => l.trim()).filter((l) => l.length > 0).join(" | ") : undefined;
|
|
331
|
-
const briefParts = [];
|
|
332
|
-
if (name)
|
|
333
|
-
briefParts.push(name);
|
|
334
|
-
if (message)
|
|
335
|
-
briefParts.push(`message="${clip(message, 200)}"`);
|
|
336
|
-
if (status)
|
|
337
|
-
briefParts.push(`status=${status}`);
|
|
338
|
-
if (code)
|
|
339
|
-
briefParts.push(`code=${code}`);
|
|
340
|
-
if (causeName)
|
|
341
|
-
briefParts.push(`cause=${causeName}`);
|
|
342
|
-
if (!message && stringForm && stringForm !== name) {
|
|
343
|
-
briefParts.push(`str="${clip(stringForm, 200)}"`);
|
|
344
|
-
}
|
|
345
|
-
const brief = briefParts.join(" ") || stringForm || name;
|
|
346
|
-
return {
|
|
347
|
-
name,
|
|
348
|
-
message,
|
|
349
|
-
...status ? { status } : {},
|
|
350
|
-
...code ? { code } : {},
|
|
351
|
-
...causeName ? { causeName } : {},
|
|
352
|
-
...stackHead ? { stackHead } : {},
|
|
353
|
-
stringForm,
|
|
354
|
-
brief
|
|
355
|
-
};
|
|
356
|
-
}
|
|
357
|
-
function safeString(value) {
|
|
358
|
-
try {
|
|
359
|
-
return String(value);
|
|
360
|
-
} catch {
|
|
361
|
-
return "<unstringifiable>";
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
|
|
365
290
|
// ../plugin/src/shared/rpc-utils.ts
|
|
366
291
|
import { execFile, execFileSync } from "node:child_process";
|
|
367
292
|
import { readFileSync } from "node:fs";
|
|
@@ -887,7 +812,7 @@ function classifyLivePiSnapshot(snapshot, probeParents = true) {
|
|
|
887
812
|
continue;
|
|
888
813
|
if (ancestors.has(fact.pid)) {
|
|
889
814
|
skippedAncestorPids.push(fact.pid);
|
|
890
|
-
|
|
815
|
+
log2(`[magic-context] Pi process scan: skipping ancestor PID ${fact.pid} (session launcher shim)`);
|
|
891
816
|
continue;
|
|
892
817
|
}
|
|
893
818
|
if (commandHasPiHarnessArc(command)) {
|
|
@@ -895,7 +820,7 @@ function classifyLivePiSnapshot(snapshot, probeParents = true) {
|
|
|
895
820
|
continue;
|
|
896
821
|
}
|
|
897
822
|
inconclusivePids.add(fact.pid);
|
|
898
|
-
|
|
823
|
+
log2(`[magic-context] Pi process scan: PID ${fact.pid} command line is ambiguous (image-name or missing Pi/OMP arc); treating as inconclusive`);
|
|
899
824
|
}
|
|
900
825
|
skippedAncestorPids.sort((left, right) => left - right);
|
|
901
826
|
const verified = [...processIds].sort((left, right) => left - right);
|
|
@@ -1069,18 +994,6 @@ function inspectWindowsProcessesSync() {
|
|
|
1069
994
|
};
|
|
1070
995
|
}
|
|
1071
996
|
|
|
1072
|
-
// ../plugin/src/shared/sqlite-context-pragmas.ts
|
|
1073
|
-
function configureContextDatabasePragmas(db, readonly = false) {
|
|
1074
|
-
const [row] = db.prepare(readonly ? "PRAGMA journal_mode" : "PRAGMA journal_mode=WAL").all();
|
|
1075
|
-
const mode = row?.journal_mode?.toLowerCase();
|
|
1076
|
-
if (mode === "memory" || readonly && mode !== "wal")
|
|
1077
|
-
return;
|
|
1078
|
-
if (mode !== "wal") {
|
|
1079
|
-
throw new Error(`context.db requires WAL before synchronous=NORMAL (got ${mode ?? "unknown"})`);
|
|
1080
|
-
}
|
|
1081
|
-
db.exec("PRAGMA synchronous=NORMAL");
|
|
1082
|
-
}
|
|
1083
|
-
|
|
1084
997
|
// ../plugin/src/features/magic-context/context-store-uuid.ts
|
|
1085
998
|
import { randomUUID } from "node:crypto";
|
|
1086
999
|
function getContextStoreUuid(db) {
|
|
@@ -1092,7 +1005,7 @@ function ensureContextStoreUuid(db) {
|
|
|
1092
1005
|
if (existing)
|
|
1093
1006
|
return existing;
|
|
1094
1007
|
const minted = randomUUID();
|
|
1095
|
-
|
|
1008
|
+
withPrivilegedWriter2(db, () => {
|
|
1096
1009
|
db.transaction(() => {
|
|
1097
1010
|
db.prepare("INSERT INTO context_store_meta(key, value) VALUES ('store_uuid', ?) ON CONFLICT(key) DO NOTHING").run(minted);
|
|
1098
1011
|
}).immediate();
|
|
@@ -1100,6 +1013,93 @@ function ensureContextStoreUuid(db) {
|
|
|
1100
1013
|
return getContextStoreUuid(db) ?? minted;
|
|
1101
1014
|
}
|
|
1102
1015
|
|
|
1016
|
+
// ../plugin/src/features/magic-context/storage-db.ts
|
|
1017
|
+
import {
|
|
1018
|
+
existsSync as existsSync2,
|
|
1019
|
+
readdirSync,
|
|
1020
|
+
readFileSync as readFileSync2,
|
|
1021
|
+
rmdirSync,
|
|
1022
|
+
statSync,
|
|
1023
|
+
unlinkSync
|
|
1024
|
+
} from "node:fs";
|
|
1025
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
1026
|
+
|
|
1027
|
+
// ../plugin/src/shared/error-message.ts
|
|
1028
|
+
function getErrorMessage(error) {
|
|
1029
|
+
return error instanceof Error ? error.message : String(error);
|
|
1030
|
+
}
|
|
1031
|
+
function readString(value) {
|
|
1032
|
+
if (typeof value === "string" && value.length > 0)
|
|
1033
|
+
return value;
|
|
1034
|
+
if (typeof value === "number")
|
|
1035
|
+
return String(value);
|
|
1036
|
+
return;
|
|
1037
|
+
}
|
|
1038
|
+
function clip(value, max) {
|
|
1039
|
+
if (value.length <= max)
|
|
1040
|
+
return value;
|
|
1041
|
+
return `${value.slice(0, max)}…`;
|
|
1042
|
+
}
|
|
1043
|
+
function describeError(error) {
|
|
1044
|
+
const stringForm = clip(safeString(error), 400);
|
|
1045
|
+
if (!(error instanceof Error) && !(error && typeof error === "object")) {
|
|
1046
|
+
return {
|
|
1047
|
+
name: typeof error,
|
|
1048
|
+
message: "",
|
|
1049
|
+
stringForm,
|
|
1050
|
+
brief: stringForm || "<empty>"
|
|
1051
|
+
};
|
|
1052
|
+
}
|
|
1053
|
+
const obj = error;
|
|
1054
|
+
const nameFromField = readString(obj.name);
|
|
1055
|
+
const nameFromCtor = error?.constructor?.name;
|
|
1056
|
+
const name = nameFromField ?? nameFromCtor ?? "Error";
|
|
1057
|
+
const message = readString(obj.message) ?? "";
|
|
1058
|
+
const status = readString(obj.status) ?? readString(obj.statusCode);
|
|
1059
|
+
const code = readString(obj.code);
|
|
1060
|
+
let causeName;
|
|
1061
|
+
const cause = obj.cause;
|
|
1062
|
+
if (cause && typeof cause === "object") {
|
|
1063
|
+
const causeRecord = cause;
|
|
1064
|
+
causeName = readString(causeRecord.name) ?? cause.constructor?.name;
|
|
1065
|
+
}
|
|
1066
|
+
const stack = readString(obj.stack);
|
|
1067
|
+
const stackHead = stack ? stack.split(`
|
|
1068
|
+
`).slice(0, 4).map((l) => l.trim()).filter((l) => l.length > 0).join(" | ") : undefined;
|
|
1069
|
+
const briefParts = [];
|
|
1070
|
+
if (name)
|
|
1071
|
+
briefParts.push(name);
|
|
1072
|
+
if (message)
|
|
1073
|
+
briefParts.push(`message="${clip(message, 200)}"`);
|
|
1074
|
+
if (status)
|
|
1075
|
+
briefParts.push(`status=${status}`);
|
|
1076
|
+
if (code)
|
|
1077
|
+
briefParts.push(`code=${code}`);
|
|
1078
|
+
if (causeName)
|
|
1079
|
+
briefParts.push(`cause=${causeName}`);
|
|
1080
|
+
if (!message && stringForm && stringForm !== name) {
|
|
1081
|
+
briefParts.push(`str="${clip(stringForm, 200)}"`);
|
|
1082
|
+
}
|
|
1083
|
+
const brief = briefParts.join(" ") || stringForm || name;
|
|
1084
|
+
return {
|
|
1085
|
+
name,
|
|
1086
|
+
message,
|
|
1087
|
+
...status ? { status } : {},
|
|
1088
|
+
...code ? { code } : {},
|
|
1089
|
+
...causeName ? { causeName } : {},
|
|
1090
|
+
...stackHead ? { stackHead } : {},
|
|
1091
|
+
stringForm,
|
|
1092
|
+
brief
|
|
1093
|
+
};
|
|
1094
|
+
}
|
|
1095
|
+
function safeString(value) {
|
|
1096
|
+
try {
|
|
1097
|
+
return String(value);
|
|
1098
|
+
} catch {
|
|
1099
|
+
return "<unstringifiable>";
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
1103
|
// ../plugin/src/features/magic-context/migration-worker-client.ts
|
|
1104
1104
|
import { Worker } from "node:worker_threads";
|
|
1105
1105
|
|
|
@@ -1202,7 +1202,7 @@ function runMigrationsOffThread(data) {
|
|
|
1202
1202
|
reject(workerStartError(error instanceof Error ? error.message : String(error)));
|
|
1203
1203
|
return;
|
|
1204
1204
|
}
|
|
1205
|
-
|
|
1205
|
+
log2(`[migrations] applying pending migrations on a worker thread: ${data.dbPath}`);
|
|
1206
1206
|
let ready = false;
|
|
1207
1207
|
let settled = false;
|
|
1208
1208
|
let endBusy = beginOffThreadMigration();
|
|
@@ -1230,10 +1230,10 @@ function runMigrationsOffThread(data) {
|
|
|
1230
1230
|
switch (message.type) {
|
|
1231
1231
|
case "ready":
|
|
1232
1232
|
ready = true;
|
|
1233
|
-
|
|
1233
|
+
log2(`[migrations] migration worker ready: ${data.dbPath}`);
|
|
1234
1234
|
return;
|
|
1235
1235
|
case "log":
|
|
1236
|
-
|
|
1236
|
+
writeForwardedLogLine2(message.line);
|
|
1237
1237
|
return;
|
|
1238
1238
|
case "lock-wait":
|
|
1239
1239
|
if (!settled)
|
|
@@ -1314,7 +1314,7 @@ function runToolOwnerBackfill(db) {
|
|
|
1314
1314
|
}
|
|
1315
1315
|
const opencodeDbPath = resolveOpencodeDbPath();
|
|
1316
1316
|
if (!existsSync(opencodeDbPath)) {
|
|
1317
|
-
|
|
1317
|
+
log2(`[backfill] OpenCode DB not found at ${opencodeDbPath} — marking all unbackfilled sessions as skipped. Lazy adoption (defense-in-depth) handles legacy rows at runtime.`);
|
|
1318
1318
|
markAllUnbackfilledSessionsSkipped(db);
|
|
1319
1319
|
result.sessionsSkippedNoOcDb = countSessionsByStatus(db, "skipped");
|
|
1320
1320
|
result.durationMs = performance.now() - startedAt;
|
|
@@ -1331,11 +1331,11 @@ function runToolOwnerBackfill(db) {
|
|
|
1331
1331
|
try {
|
|
1332
1332
|
db.exec("DETACH DATABASE oc_backfill");
|
|
1333
1333
|
} catch (error) {
|
|
1334
|
-
|
|
1334
|
+
log2(`[backfill] failed to detach oc_backfill database: ${error instanceof Error ? error.message : String(error)}`);
|
|
1335
1335
|
}
|
|
1336
1336
|
}
|
|
1337
1337
|
result.durationMs = performance.now() - startedAt;
|
|
1338
|
-
|
|
1338
|
+
log2(`[backfill] sessions=${result.sessionsProcessed} completed=${result.sessionsCompleted} skipped_no_oc=${result.sessionsSkippedNoOcDb} skipped_no_matches=${result.sessionsSkippedNoMatches} blocked_by_lease=${result.sessionsBlockedByLease} errored=${result.sessionsErrored} rows_updated=${result.rowsUpdated} rows_left_null=${result.rowsLeftNull} duration_ms=${Math.round(result.durationMs)}`);
|
|
1339
1339
|
return result;
|
|
1340
1340
|
}
|
|
1341
1341
|
function isToolOwnerBackfillNeeded(db) {
|
|
@@ -1520,7 +1520,7 @@ function backfillToolOwnersInChunks(db, result) {
|
|
|
1520
1520
|
result.sessionsCompleted += 1;
|
|
1521
1521
|
}
|
|
1522
1522
|
} catch (error) {
|
|
1523
|
-
|
|
1523
|
+
log2(`[backfill] session=${sessionId} errored: ${error instanceof Error ? error.message : String(error)}`);
|
|
1524
1524
|
markSessionErrored(db, sessionId, error);
|
|
1525
1525
|
result.sessionsErrored += 1;
|
|
1526
1526
|
}
|
|
@@ -1533,8 +1533,8 @@ function backfillToolOwnersInChunks(db, result) {
|
|
|
1533
1533
|
}
|
|
1534
1534
|
|
|
1535
1535
|
// ../plugin/src/features/magic-context/storage-db.ts
|
|
1536
|
-
|
|
1537
|
-
|
|
1536
|
+
registerSlowWriteReporter2(logSlowWriteTransaction);
|
|
1537
|
+
registerSqliteDiagnosticSink2((message) => log2(message));
|
|
1538
1538
|
var databases = new Map;
|
|
1539
1539
|
var pendingAsyncOpens = new Map;
|
|
1540
1540
|
var persistenceByDatabase = new WeakMap;
|
|
@@ -1556,7 +1556,7 @@ function ensureSecureStorageDir(dir) {
|
|
|
1556
1556
|
}
|
|
1557
1557
|
function tightenStorageTree(dir) {
|
|
1558
1558
|
const { failures } = tightenStorageTreeSync(dir);
|
|
1559
|
-
|
|
1559
|
+
log2(`[magic-context] storage permission tightening failures=${failures}`);
|
|
1560
1560
|
}
|
|
1561
1561
|
function resolveBootBusyTimeoutMs(value) {
|
|
1562
1562
|
if (value === undefined)
|
|
@@ -1565,9 +1565,9 @@ function resolveBootBusyTimeoutMs(value) {
|
|
|
1565
1565
|
return BOOT_SQLITE_BUSY_TIMEOUT_MS;
|
|
1566
1566
|
return Math.max(0, Math.min(BOOT_SQLITE_BUSY_TIMEOUT_MS, Math.floor(value)));
|
|
1567
1567
|
}
|
|
1568
|
-
function installBootBusyTimeout(db, dbPath, timeoutMs, report =
|
|
1568
|
+
function installBootBusyTimeout(db, dbPath, timeoutMs, report = log2) {
|
|
1569
1569
|
db.exec(`PRAGMA busy_timeout=${timeoutMs}`);
|
|
1570
|
-
report(`[magic-context] SQLite boot busy timeout: backend=${
|
|
1570
|
+
report(`[magic-context] SQLite boot busy timeout: backend=${detectSqliteRuntime2()} timeout=${timeoutMs}ms path=${dbPath}`);
|
|
1571
1571
|
}
|
|
1572
1572
|
function resolveDatabasePath(dbPathOverride) {
|
|
1573
1573
|
if (dbPathOverride) {
|
|
@@ -1590,18 +1590,18 @@ function migrateLegacyStorageIfNeeded(targetDbPath, targetDbDir) {
|
|
|
1590
1590
|
const legacyDbPath = join(legacyDir, "context.db");
|
|
1591
1591
|
if (!existsSync2(legacyDbPath))
|
|
1592
1592
|
return;
|
|
1593
|
-
|
|
1593
|
+
log2(`[magic-context] migrating legacy plugin storage: ${legacyDir} -> ${targetDbDir} (legacy left in place as backup)`);
|
|
1594
1594
|
ensureSecureStorageDir(targetDbDir);
|
|
1595
1595
|
try {
|
|
1596
|
-
const legacyDb = new
|
|
1596
|
+
const legacyDb = new Database2(legacyDbPath);
|
|
1597
1597
|
try {
|
|
1598
|
-
|
|
1598
|
+
configureContextDatabasePragmas2(legacyDb, true);
|
|
1599
1599
|
legacyDb.exec("PRAGMA wal_checkpoint(TRUNCATE)");
|
|
1600
1600
|
} finally {
|
|
1601
1601
|
closeQuietly(legacyDb);
|
|
1602
1602
|
}
|
|
1603
1603
|
} catch (error) {
|
|
1604
|
-
|
|
1604
|
+
log2(`[magic-context] legacy WAL checkpoint before copy failed (continuing with sidecar copy): ${getErrorMessage(error)}`);
|
|
1605
1605
|
}
|
|
1606
1606
|
for (const suffix of ["", "-wal", "-shm"]) {
|
|
1607
1607
|
const src = `${legacyDbPath}${suffix}`;
|
|
@@ -1610,7 +1610,7 @@ function migrateLegacyStorageIfNeeded(targetDbPath, targetDbDir) {
|
|
|
1610
1610
|
try {
|
|
1611
1611
|
copyStorageFileSync(src, dst);
|
|
1612
1612
|
} catch (error) {
|
|
1613
|
-
|
|
1613
|
+
log2(`[magic-context] failed to copy ${src}:`, getErrorMessage(error));
|
|
1614
1614
|
}
|
|
1615
1615
|
}
|
|
1616
1616
|
}
|
|
@@ -1620,7 +1620,7 @@ function migrateLegacyStorageIfNeeded(targetDbPath, targetDbDir) {
|
|
|
1620
1620
|
try {
|
|
1621
1621
|
copyStorageTreeSync(legacyModelsDir, targetModelsDir);
|
|
1622
1622
|
} catch (error) {
|
|
1623
|
-
|
|
1623
|
+
log2("[magic-context] failed to copy embedding model cache:", getErrorMessage(error));
|
|
1624
1624
|
}
|
|
1625
1625
|
}
|
|
1626
1626
|
}
|
|
@@ -1655,7 +1655,7 @@ function enforceSchemaFence(db, dbPath, latestSupportedVersion) {
|
|
|
1655
1655
|
return true;
|
|
1656
1656
|
}
|
|
1657
1657
|
lastSchemaFenceRejection = { persistedVersion, supportedVersion: latestSupportedVersion };
|
|
1658
|
-
|
|
1658
|
+
log2(`[magic-context] storage fatal: refusing to open ${dbPath}; upstream migration lane v${persistedVersion} is newer than this binary supports (max v${latestSupportedVersion}). A pinned or stale plugin is likely sharing this database with a newer instance; update or unpin Magic Context with 'npx @cortexkit/magic-context@latest doctor --force', then restart.`);
|
|
1659
1659
|
return false;
|
|
1660
1660
|
}
|
|
1661
1661
|
function unreadableDiscovery(path, arm) {
|
|
@@ -1727,7 +1727,7 @@ function classifyJunkDiscovery(portFile, raw, staleFiles) {
|
|
|
1727
1727
|
}
|
|
1728
1728
|
staleFiles.push(portFile);
|
|
1729
1729
|
const reason = invalidDiscoveryReason(raw);
|
|
1730
|
-
|
|
1730
|
+
log2(`[magic-context] removing stale RPC discovery file ${portFile}: ${reason} record older than 10 minutes`);
|
|
1731
1731
|
return null;
|
|
1732
1732
|
}
|
|
1733
1733
|
function inspectRpcServerDiscovery(storageDir, processes, options) {
|
|
@@ -1872,12 +1872,12 @@ function formatInconclusivePiMigrationWarning(dbPath, pids) {
|
|
|
1872
1872
|
function logInconclusiveMigrationProbes(dbPath, discovery, piDiscovery) {
|
|
1873
1873
|
const uncertainPids = discovery.inconclusivePids ?? [];
|
|
1874
1874
|
if (uncertainPids.length > 0) {
|
|
1875
|
-
|
|
1875
|
+
log2(formatInconclusiveOpenCodeMigrationWarning(dbPath, uncertainPids));
|
|
1876
1876
|
}
|
|
1877
1877
|
if (piDiscovery.state === "unreadable") {
|
|
1878
|
-
|
|
1878
|
+
log2(`[magic-context] storage warning: continuing migration for ${dbPath}; the Pi/OMP process-list probe could not run, which commonly means an OS sandbox denied ps. No live Pi harness was confirmed.`);
|
|
1879
1879
|
} else if ((piDiscovery.inconclusivePids?.length ?? 0) > 0) {
|
|
1880
|
-
|
|
1880
|
+
log2(formatInconclusivePiMigrationWarning(dbPath, piDiscovery.inconclusivePids ?? []));
|
|
1881
1881
|
}
|
|
1882
1882
|
}
|
|
1883
1883
|
function isDefaultSharedDatabasePath(dbPath) {
|
|
@@ -1939,9 +1939,9 @@ function enforceMigrationOnOpenGuard(db, dbPath, dbDir, latestSupportedVersion,
|
|
|
1939
1939
|
const unreadableFile = discovery.unreadableFile ?? "<unknown>";
|
|
1940
1940
|
const arm = discovery.unreadableArm ?? "io";
|
|
1941
1941
|
const recovery = arm === "io" ? `If no OpenCode server is running, it is safe to delete ${unreadableFile} and retry.` : `Retry after the file is older than the ten-minute grace window, or stop OpenCode before deleting it.`;
|
|
1942
|
-
|
|
1942
|
+
log2(`[magic-context] storage fatal: refusing to migrate ${dbPath} from upstream migration v${persistedVersion} to v${latestSupportedVersion} because RPC discovery file ${unreadableFile} is uncertain (${arm} arm), so the absence of a live OpenCode server cannot be proven. ${recovery}`);
|
|
1943
1943
|
} else {
|
|
1944
|
-
|
|
1944
|
+
log2(formatLiveProcessMigrationRefusal(dbPath, persistedVersion, latestSupportedVersion, discovery.serverPids, piPids));
|
|
1945
1945
|
}
|
|
1946
1946
|
return false;
|
|
1947
1947
|
}
|
|
@@ -1970,34 +1970,34 @@ function finishDatabaseOpen(db, dbPath, explicitDbPath, latestSupportedVersion)
|
|
|
1970
1970
|
}
|
|
1971
1971
|
healWedgedChannel2Claims(db);
|
|
1972
1972
|
if (!explicitDbPath) {
|
|
1973
|
-
const readsOpenCodeStore =
|
|
1973
|
+
const readsOpenCodeStore = harnessOwnsOpenCodeStore2();
|
|
1974
1974
|
let busyRetryMs = 100;
|
|
1975
|
-
const runBackfills = () =>
|
|
1975
|
+
const runBackfills = () => withoutSqliteTransformPass2(() => withSqliteBackgroundWriter2(() => {
|
|
1976
1976
|
if (readsOpenCodeStore) {
|
|
1977
1977
|
try {
|
|
1978
1978
|
runToolOwnerBackfill(db);
|
|
1979
1979
|
} catch (error) {
|
|
1980
|
-
|
|
1980
|
+
log2(`[magic-context] tool-owner backfill failed (continuing with lazy adoption fallback): ${getErrorMessage(error)}`);
|
|
1981
1981
|
}
|
|
1982
1982
|
}
|
|
1983
1983
|
startMessageFtsRowidMapBackfill(db).then(async () => {
|
|
1984
1984
|
if (!readsOpenCodeStore)
|
|
1985
1985
|
return;
|
|
1986
|
-
const { readRawSessionMessagePage, readRawSessionMessages } = await importPluginModule(() => import("./read-session-chunk-
|
|
1987
|
-
const { startMessageTimeBackfill } = await importPluginModule(() => import("./message-time-backfill-
|
|
1986
|
+
const { readRawSessionMessagePage, readRawSessionMessages } = await importPluginModule(() => import("./read-session-chunk-47pjn7fz.js"));
|
|
1987
|
+
const { startMessageTimeBackfill } = await importPluginModule(() => import("./message-time-backfill-4ndf7hrq.js"));
|
|
1988
1988
|
await startMessageTimeBackfill(db, Object.assign(readRawSessionMessages, {
|
|
1989
1989
|
readPage: readRawSessionMessagePage
|
|
1990
1990
|
}));
|
|
1991
1991
|
}).catch((error) => {
|
|
1992
|
-
if (
|
|
1993
|
-
|
|
1992
|
+
if (isTransientSqliteError2(error)) {
|
|
1993
|
+
withoutSqliteTransformPass2(() => {
|
|
1994
1994
|
const timer = setTimeout(runBackfills, busyRetryMs);
|
|
1995
1995
|
timer.unref();
|
|
1996
1996
|
});
|
|
1997
1997
|
busyRetryMs = Math.min(30000, busyRetryMs * 2);
|
|
1998
1998
|
return;
|
|
1999
1999
|
}
|
|
2000
|
-
|
|
2000
|
+
log2(`[magic-context] message-index backfill failed (will resume next startup): ${getErrorMessage(error)}`);
|
|
2001
2001
|
});
|
|
2002
2002
|
}));
|
|
2003
2003
|
if (bootQuietRemainingMs() > 0)
|
|
@@ -2013,14 +2013,14 @@ function finishDatabaseOpen(db, dbPath, explicitDbPath, latestSupportedVersion)
|
|
|
2013
2013
|
persistenceByDatabase.set(db, true);
|
|
2014
2014
|
persistenceErrorByDatabase.delete(db);
|
|
2015
2015
|
if (!explicitDbPath) {
|
|
2016
|
-
|
|
2016
|
+
log2(formatSchemaFenceBootLog(getPersistedSchemaVersion(db), latestSupportedVersion));
|
|
2017
2017
|
}
|
|
2018
2018
|
return db;
|
|
2019
2019
|
}
|
|
2020
2020
|
function initializeDatabase(db, busyTimeoutMs = BOOT_SQLITE_BUSY_TIMEOUT_MS) {
|
|
2021
2021
|
db.exec(`PRAGMA busy_timeout=${resolveBootBusyTimeoutMs(busyTimeoutMs)}`);
|
|
2022
2022
|
db.exec("PRAGMA foreign_keys=ON");
|
|
2023
|
-
|
|
2023
|
+
configureContextDatabasePragmas2(db);
|
|
2024
2024
|
applySqliteTuningPragmas(db);
|
|
2025
2025
|
db.exec(`
|
|
2026
2026
|
CREATE TABLE IF NOT EXISTS tags (
|
|
@@ -3254,6 +3254,7 @@ CREATE INDEX IF NOT EXISTS idx_dream_queue_pending ON dream_queue(started_at, en
|
|
|
3254
3254
|
const version = getPersistedSchemaVersion(db);
|
|
3255
3255
|
if (version === 0 || version >= 95)
|
|
3256
3256
|
installV95PerfSchema(db, false, version === 0);
|
|
3257
|
+
installTagIdentityRevisionTrigger(db);
|
|
3257
3258
|
}
|
|
3258
3259
|
var CHANNEL2_CLAIM_TTL_MS = 10 * 60000;
|
|
3259
3260
|
var channel2HealStatements = new WeakMap;
|
|
@@ -3283,7 +3284,7 @@ function openDatabase(dbPathOrOptions) {
|
|
|
3283
3284
|
lastMigrationOnOpenRefusal = null;
|
|
3284
3285
|
const existing = databases.get(dbPath);
|
|
3285
3286
|
if (!existing && pendingAsyncOpens.has(dbPath)) {
|
|
3286
|
-
|
|
3287
|
+
log2(`[magic-context] storage not ready: ${dbPath} is still being opened or migrated; refusing a second synchronous open`);
|
|
3287
3288
|
return null;
|
|
3288
3289
|
}
|
|
3289
3290
|
if (existing) {
|
|
@@ -3311,14 +3312,14 @@ function openDatabase(dbPathOrOptions) {
|
|
|
3311
3312
|
throw error;
|
|
3312
3313
|
}
|
|
3313
3314
|
}
|
|
3314
|
-
db = new
|
|
3315
|
+
db = new Database2(dbPath);
|
|
3315
3316
|
installBootBusyTimeout(db, dbPath, busyTimeoutMs, options?.onBootBusyTimeout);
|
|
3316
3317
|
if (!enforceSchemaFence(db, dbPath, latestSupportedVersion)) {
|
|
3317
3318
|
closeQuietly(db);
|
|
3318
3319
|
return null;
|
|
3319
3320
|
}
|
|
3320
3321
|
if (options?.allowMigrations === false && hasPendingMigrations(db)) {
|
|
3321
|
-
|
|
3322
|
+
log2(`[magic-context] storage not ready: pending migrations at ${dbPath}; host callers must await the async opener`);
|
|
3322
3323
|
closeQuietly(db);
|
|
3323
3324
|
return null;
|
|
3324
3325
|
}
|
|
@@ -3335,12 +3336,13 @@ function openDatabase(dbPathOrOptions) {
|
|
|
3335
3336
|
} else
|
|
3336
3337
|
runMigrations(db);
|
|
3337
3338
|
ensureContextStoreUuid(db);
|
|
3339
|
+
installTagIdentityRevisionTrigger(db);
|
|
3338
3340
|
return finishDatabaseOpen(db, dbPath, explicitDbPath, latestSupportedVersion);
|
|
3339
3341
|
} catch (error) {
|
|
3340
3342
|
if (db)
|
|
3341
3343
|
closeQuietly(db);
|
|
3342
3344
|
const detail = getErrorMessage(error);
|
|
3343
|
-
|
|
3345
|
+
log2(`[magic-context] storage fatal: failed to open ${dbPath}: ${detail}`);
|
|
3344
3346
|
throw new Error(`[magic-context] storage unavailable: ${detail}. Magic Context is disabled for this run; check log for details.`);
|
|
3345
3347
|
}
|
|
3346
3348
|
}
|
|
@@ -3399,7 +3401,7 @@ async function openDatabaseAsync(dbPathOrOptions) {
|
|
|
3399
3401
|
throw error;
|
|
3400
3402
|
}
|
|
3401
3403
|
}
|
|
3402
|
-
db = new
|
|
3404
|
+
db = new Database2(dbPath);
|
|
3403
3405
|
installBootBusyTimeout(db, dbPath, busyTimeoutMs, options?.onBootBusyTimeout);
|
|
3404
3406
|
openMs = performance.now() - openStartedAt;
|
|
3405
3407
|
guardStartedAt = performance.now();
|
|
@@ -3431,6 +3433,7 @@ async function openDatabaseAsync(dbPathOrOptions) {
|
|
|
3431
3433
|
throw new Error("storage initialization left a pending migration; reinstall or rebuild the plugin");
|
|
3432
3434
|
}
|
|
3433
3435
|
ensureContextStoreUuid(db);
|
|
3436
|
+
installTagIdentityRevisionTrigger(db);
|
|
3434
3437
|
const opened = finishDatabaseOpen(db, dbPath, explicitDbPath, latestSupportedVersion);
|
|
3435
3438
|
migrateMs = performance.now() - migrateStartedAt;
|
|
3436
3439
|
return opened;
|
|
@@ -3438,10 +3441,10 @@ async function openDatabaseAsync(dbPathOrOptions) {
|
|
|
3438
3441
|
if (db)
|
|
3439
3442
|
closeQuietly(db);
|
|
3440
3443
|
const detail = getErrorMessage(error);
|
|
3441
|
-
|
|
3444
|
+
log2(`[magic-context] storage fatal: failed to open ${dbPath}: ${detail}`);
|
|
3442
3445
|
throw new Error(`[magic-context] storage unavailable: ${detail}. Magic Context is disabled for this run; check log for details.`);
|
|
3443
3446
|
} finally {
|
|
3444
|
-
|
|
3447
|
+
log2(`[migrations] async open main-thread migration-body count: ${getMainThreadMigrationBodyCount() - mainThreadBodiesBefore} (total=${getMainThreadMigrationBodyCount()}) path=${dbPath}`);
|
|
3445
3448
|
if (openMs === 0)
|
|
3446
3449
|
openMs = performance.now() - openStartedAt;
|
|
3447
3450
|
if (guardStartedAt !== null && guardMs === 0) {
|
|
@@ -3467,11 +3470,11 @@ function closeDatabase() {
|
|
|
3467
3470
|
try {
|
|
3468
3471
|
closeQuietly(db);
|
|
3469
3472
|
} catch (error) {
|
|
3470
|
-
|
|
3473
|
+
log2("[magic-context] storage error:", error);
|
|
3471
3474
|
} finally {
|
|
3472
3475
|
databases.delete(key);
|
|
3473
3476
|
}
|
|
3474
3477
|
}
|
|
3475
3478
|
}
|
|
3476
3479
|
|
|
3477
|
-
export { FAIL_CLOSED_DOCTOR_COMMAND, formatFailClosedBlockingMessage, createFailClosedBlockingError, isFailClosedBlockingError, shouldBypassFailClosedBlock, createFailClosedController, piHarnessKindFromExecutable, isPidAlive, getErrorMessage, describeError,
|
|
3480
|
+
export { FAIL_CLOSED_DOCTOR_COMMAND, formatFailClosedBlockingMessage, createFailClosedBlockingError, isFailClosedBlockingError, shouldBypassFailClosedBlock, createFailClosedController, piHarnessKindFromExecutable, isPidAlive, getErrorMessage, describeError, startBootDeadline, getSchemaFenceRejection, getMigrationOnOpenRefusal, LATEST_SUPPORTED_VERSION, getDatabasePath, getPersistedSchemaVersion, setSqlitePragmaConfig, applySqliteTuningPragmas, runSqliteOptimize, initializeDatabase, openDatabase, openCurrentDatabase, openDatabaseAsync, closeDatabase };
|