@cortexkit/magic-context 0.49.25 → 0.49.27
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/index.js +224 -14
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -25303,18 +25303,95 @@ var init_opencode_plugin_cache = __esm(() => {
|
|
|
25303
25303
|
|
|
25304
25304
|
// src/commands/doctor-windows-holders.ts
|
|
25305
25305
|
import { existsSync as existsSync14 } from "node:fs";
|
|
25306
|
+
function fileName(path) {
|
|
25307
|
+
return path.toLowerCase().replaceAll("\\", "/").split("/").at(-1) ?? "";
|
|
25308
|
+
}
|
|
25309
|
+
function commandTokens2(command) {
|
|
25310
|
+
const tokens = [];
|
|
25311
|
+
let token = "";
|
|
25312
|
+
let quoted = false;
|
|
25313
|
+
let started = false;
|
|
25314
|
+
for (let index = 0;index < command.length; index += 1) {
|
|
25315
|
+
const char = command[index];
|
|
25316
|
+
if (char === "\\") {
|
|
25317
|
+
started = true;
|
|
25318
|
+
let end = index;
|
|
25319
|
+
while (command[end] === "\\")
|
|
25320
|
+
end += 1;
|
|
25321
|
+
const count = end - index;
|
|
25322
|
+
if (command[end] === '"') {
|
|
25323
|
+
token += "\\".repeat(Math.floor(count / 2));
|
|
25324
|
+
if (count % 2)
|
|
25325
|
+
token += '"';
|
|
25326
|
+
else
|
|
25327
|
+
quoted = !quoted;
|
|
25328
|
+
index = end;
|
|
25329
|
+
} else {
|
|
25330
|
+
token += "\\".repeat(count);
|
|
25331
|
+
index = end - 1;
|
|
25332
|
+
}
|
|
25333
|
+
} else if (char === '"') {
|
|
25334
|
+
started = true;
|
|
25335
|
+
quoted = !quoted;
|
|
25336
|
+
} else if (/\s/.test(char) && !quoted) {
|
|
25337
|
+
if (started)
|
|
25338
|
+
tokens.push(token);
|
|
25339
|
+
token = "";
|
|
25340
|
+
started = false;
|
|
25341
|
+
} else {
|
|
25342
|
+
started = true;
|
|
25343
|
+
token += char;
|
|
25344
|
+
}
|
|
25345
|
+
}
|
|
25346
|
+
if (started)
|
|
25347
|
+
tokens.push(token);
|
|
25348
|
+
return tokens;
|
|
25349
|
+
}
|
|
25350
|
+
function runtimeScript(runtime, tokens) {
|
|
25351
|
+
let allowRun = runtime !== "node";
|
|
25352
|
+
for (let index = 1;index < tokens.length; index += 1) {
|
|
25353
|
+
const token = tokens[index];
|
|
25354
|
+
if (token === "--")
|
|
25355
|
+
return tokens[index + 1];
|
|
25356
|
+
if (/^(?:--eval|--print)(?:=|$)|^-[ep]/.test(token))
|
|
25357
|
+
return;
|
|
25358
|
+
if (token.startsWith("-")) {
|
|
25359
|
+
if (runtimeValueOptions[runtime].has(token))
|
|
25360
|
+
index += 1;
|
|
25361
|
+
continue;
|
|
25362
|
+
}
|
|
25363
|
+
if (allowRun && token === "run") {
|
|
25364
|
+
allowRun = false;
|
|
25365
|
+
continue;
|
|
25366
|
+
}
|
|
25367
|
+
return token;
|
|
25368
|
+
}
|
|
25369
|
+
return;
|
|
25370
|
+
}
|
|
25371
|
+
function isHostScript(script) {
|
|
25372
|
+
const path = script.toLowerCase().replaceAll("\\", "/");
|
|
25373
|
+
return /^(?:ck-mc|opencode2?)(?:\.exe|\.js|\.mjs)?$/.test(fileName(path)) || piHarnessKindFromExecutable(path.replace(/\.(?:js|mjs|cjs)$/, "")) !== undefined || /(?:^|\/)(?:pi-coding-agent|@?oh-my-pi)(?:\/|$)/.test(path) || /(?:^|\/)(?:cljs\/dist|dist\/bundle\/cli)(?:[/.]|$)/.test(path);
|
|
25374
|
+
}
|
|
25375
|
+
function isHostProcess(imageName, commandLine) {
|
|
25376
|
+
const tokens = commandTokens2(commandLine ?? "");
|
|
25377
|
+
const image = fileName(imageName ?? tokens[0] ?? "");
|
|
25378
|
+
if (/^(?:opencode|opencode2|ck-mc)(?:\.exe)?$/.test(image) || piHarnessKindFromExecutable(image) !== undefined) {
|
|
25379
|
+
return true;
|
|
25380
|
+
}
|
|
25381
|
+
if (!runtimes.test(image))
|
|
25382
|
+
return false;
|
|
25383
|
+
const script = runtimeScript(image.replace(/\.exe$/, ""), tokens);
|
|
25384
|
+
return script !== undefined && isHostScript(script);
|
|
25385
|
+
}
|
|
25306
25386
|
function assertWindowsStoresClosed(paths, processes) {
|
|
25307
|
-
if (processes.
|
|
25308
|
-
throw new Error(
|
|
25387
|
+
if (processes.processSnapshot?.source !== "cim") {
|
|
25388
|
+
throw new Error("Windows process probe could not rule out OpenCode, Pi or ck-mc holders");
|
|
25309
25389
|
}
|
|
25310
25390
|
const facts = processes.processSnapshot.facts.filter(({ pid }) => pid !== process.pid);
|
|
25311
|
-
const unknown = facts.filter(({ imageName, commandLine }) => !imageName && !commandLine ||
|
|
25391
|
+
const unknown = facts.filter(({ imageName, commandLine }) => !imageName && !commandLine || runtimes.test(fileName(imageName ?? "")) && !commandLine?.trim());
|
|
25312
25392
|
if (unknown.length)
|
|
25313
25393
|
throw new Error(`Windows process identity is unavailable (PID ${unknown.map(({ pid }) => pid).join(", ")})`);
|
|
25314
|
-
const blockers = facts.filter(({ imageName, commandLine }) =>
|
|
25315
|
-
const image = (imageName ?? "").toLowerCase().replaceAll("\\", "/").split("/").at(-1) ?? "";
|
|
25316
|
-
return /^(?:opencode|opencode2|pi|omp|ck-mc)(?:\.exe)?$/.test(image) || /(?:^|[\\/\s"'])(?:ck-mc|opencode2?)(?:\.exe|\.js|\.mjs)?(?:$|[\s"'])/i.test(commandLine ?? "");
|
|
25317
|
-
});
|
|
25394
|
+
const blockers = facts.filter(({ imageName, commandLine }) => isHostProcess(imageName, commandLine));
|
|
25318
25395
|
if (blockers.length)
|
|
25319
25396
|
throw new Error(`OpenCode, Pi or ck-mc process is running (${blockers.map(({ pid, imageName, commandLine }) => `${imageName ?? commandLine} PID ${pid}`).join(", ")})`);
|
|
25320
25397
|
for (const path of [...new Set(paths)]) {
|
|
@@ -25336,8 +25413,91 @@ function assertWindowsStoresClosed(paths, processes) {
|
|
|
25336
25413
|
}
|
|
25337
25414
|
}
|
|
25338
25415
|
}
|
|
25416
|
+
var runtimes, runtimeValueOptions;
|
|
25339
25417
|
var init_doctor_windows_holders = __esm(async () => {
|
|
25418
|
+
init_pi_executable();
|
|
25340
25419
|
await init_sqlite();
|
|
25420
|
+
runtimes = /^(?:bun|node|deno)(?:\.exe)?$/;
|
|
25421
|
+
runtimeValueOptions = {
|
|
25422
|
+
node: new Set([
|
|
25423
|
+
"-r",
|
|
25424
|
+
"--require",
|
|
25425
|
+
"--import",
|
|
25426
|
+
"--loader",
|
|
25427
|
+
"--experimental-loader",
|
|
25428
|
+
"-C",
|
|
25429
|
+
"--conditions",
|
|
25430
|
+
"--title",
|
|
25431
|
+
"--env-file",
|
|
25432
|
+
"--env-file-if-exists",
|
|
25433
|
+
"--icu-data-dir",
|
|
25434
|
+
"--openssl-config",
|
|
25435
|
+
"--redirect-warnings",
|
|
25436
|
+
"--diagnostic-dir",
|
|
25437
|
+
"--snapshot-blob",
|
|
25438
|
+
"--inspect-port",
|
|
25439
|
+
"--experimental-config-file",
|
|
25440
|
+
"--experimental-policy",
|
|
25441
|
+
"--experimental-sea-config",
|
|
25442
|
+
"--input-type",
|
|
25443
|
+
"--run",
|
|
25444
|
+
"--cpu-prof-dir",
|
|
25445
|
+
"--cpu-prof-name",
|
|
25446
|
+
"--heap-prof-dir",
|
|
25447
|
+
"--heap-prof-name",
|
|
25448
|
+
"--report-dir",
|
|
25449
|
+
"--report-directory",
|
|
25450
|
+
"--report-filename",
|
|
25451
|
+
"--heapsnapshot-signal",
|
|
25452
|
+
"--trace-event-categories",
|
|
25453
|
+
"--trace-event-file-pattern",
|
|
25454
|
+
"--watch-path",
|
|
25455
|
+
"--watch-kill-signal",
|
|
25456
|
+
"--test-name-pattern",
|
|
25457
|
+
"--test-skip-pattern",
|
|
25458
|
+
"--test-reporter",
|
|
25459
|
+
"--test-reporter-destination",
|
|
25460
|
+
"--test-global-setup"
|
|
25461
|
+
]),
|
|
25462
|
+
bun: new Set([
|
|
25463
|
+
"-r",
|
|
25464
|
+
"--require",
|
|
25465
|
+
"--preload",
|
|
25466
|
+
"--cwd",
|
|
25467
|
+
"--env-file",
|
|
25468
|
+
"-c",
|
|
25469
|
+
"--config",
|
|
25470
|
+
"--tsconfig-override",
|
|
25471
|
+
"--define",
|
|
25472
|
+
"--loader",
|
|
25473
|
+
"--origin",
|
|
25474
|
+
"--port",
|
|
25475
|
+
"--conditions",
|
|
25476
|
+
"--external",
|
|
25477
|
+
"--use",
|
|
25478
|
+
"-F",
|
|
25479
|
+
"--filter",
|
|
25480
|
+
"--shell",
|
|
25481
|
+
"--main-fields",
|
|
25482
|
+
"--extension-order",
|
|
25483
|
+
"--jsx-factory",
|
|
25484
|
+
"--jsx-fragment",
|
|
25485
|
+
"--jsx-import-source"
|
|
25486
|
+
]),
|
|
25487
|
+
deno: new Set([
|
|
25488
|
+
"-c",
|
|
25489
|
+
"--config",
|
|
25490
|
+
"--import-map",
|
|
25491
|
+
"--cert",
|
|
25492
|
+
"--location",
|
|
25493
|
+
"--lock",
|
|
25494
|
+
"--seed",
|
|
25495
|
+
"--v8-flags",
|
|
25496
|
+
"--preload",
|
|
25497
|
+
"--watch-exclude",
|
|
25498
|
+
"--strace-ops"
|
|
25499
|
+
])
|
|
25500
|
+
};
|
|
25341
25501
|
});
|
|
25342
25502
|
|
|
25343
25503
|
// src/commands/doctor-opencode2-cache.ts
|
|
@@ -27289,6 +27449,9 @@ function readStoreStamp(db) {
|
|
|
27289
27449
|
function sameStoreStamp(left, right) {
|
|
27290
27450
|
return left !== null && right !== null && left.dataVersion === right.dataVersion && left.totalChanges === right.totalChanges && left.schemaVersion === right.schemaVersion;
|
|
27291
27451
|
}
|
|
27452
|
+
function forgetRawSessionOrdinalWatermark(sessionId) {
|
|
27453
|
+
ordinalWatermarkEpochs.set(sessionId, (ordinalWatermarkEpochs.get(sessionId) ?? 0) + 1);
|
|
27454
|
+
}
|
|
27292
27455
|
function compareOrdinalKeys(left, right) {
|
|
27293
27456
|
if (left.timeCreated !== right.timeCreated)
|
|
27294
27457
|
return left.timeCreated < right.timeCreated ? -1 : 1;
|
|
@@ -27306,12 +27469,31 @@ function countEligibleOrdinals(db, sessionId, after, through) {
|
|
|
27306
27469
|
ordinalJsonRowsRead += visited;
|
|
27307
27470
|
return typeof row?.eligible === "number" ? row.eligible : 0;
|
|
27308
27471
|
}
|
|
27472
|
+
function forgetRawSessionSummaryRows(sessionId) {
|
|
27473
|
+
summaryCandidateEpochs.set(sessionId, (summaryCandidateEpochs.get(sessionId) ?? 0) + 1);
|
|
27474
|
+
writtenSummaryIds.delete(sessionId);
|
|
27475
|
+
forgetRawSessionOrdinalWatermark(sessionId);
|
|
27476
|
+
}
|
|
27309
27477
|
function survivingAnchor(db, set) {
|
|
27310
27478
|
if (set.anchors.length === 0)
|
|
27311
27479
|
return null;
|
|
27312
27480
|
const current = new Map(db.prepare(ANCHOR_CHECK_SQL).all(JSON.stringify(set.anchors.map((anchor) => anchor.rowid))).map((row) => [row.rid, row.id]));
|
|
27313
27481
|
return set.anchors.find((anchor) => current.get(anchor.rowid) === anchor.id);
|
|
27314
27482
|
}
|
|
27483
|
+
function hasLateCommitBehindCheckpoint(db, sessionId, scan) {
|
|
27484
|
+
const tail = scan.checkpoints?.at(-1);
|
|
27485
|
+
if (!tail || scan.maxRowid === undefined)
|
|
27486
|
+
return false;
|
|
27487
|
+
const row = db.prepare(`SELECT COUNT(*) AS count FROM message
|
|
27488
|
+
WHERE rowid > ? AND +session_id = ?
|
|
27489
|
+
AND (time_created, id) <= (?, ?)
|
|
27490
|
+
AND NOT (${EXCLUDED_ROW_SQL})`).get(scan.maxRowid, sessionId, tail.timeCreated, tail.id);
|
|
27491
|
+
return typeof row?.count === "number" && row.count > 0;
|
|
27492
|
+
}
|
|
27493
|
+
function discardRetainedOrdinalRanks(db, sessionId) {
|
|
27494
|
+
ordinalCheckpoints.get(db)?.delete(sessionId);
|
|
27495
|
+
ordinalSummarySeeds.get(db)?.delete(sessionId);
|
|
27496
|
+
}
|
|
27315
27497
|
function currentOrdinalCheckpoints(db, sessionId) {
|
|
27316
27498
|
const cached = ordinalCheckpoints.get(db)?.get(sessionId);
|
|
27317
27499
|
if (!cached)
|
|
@@ -27341,10 +27523,16 @@ function extendOrdinalCheckpoints(db, sessionId, scan, limit) {
|
|
|
27341
27523
|
scan.sessionRows = points.at(-1)?.storedCount ?? 0;
|
|
27342
27524
|
}
|
|
27343
27525
|
const tail = points.at(-1);
|
|
27344
|
-
const rows = db.prepare(`SELECT id, time_created AS timeCreated, ${EXCLUDED_ROW_SQL} AS excluded FROM message
|
|
27526
|
+
const rows = db.prepare(`SELECT id, time_created AS timeCreated, rowid AS rowid, ${EXCLUDED_ROW_SQL} AS excluded FROM message
|
|
27345
27527
|
WHERE session_id=?${tail ? " AND (time_created,id) > (?,?)" : ""}
|
|
27346
27528
|
ORDER BY time_created,id${limit === undefined ? "" : ` LIMIT ${limit + 1}`}`).all(sessionId, ...tail ? [tail.timeCreated, tail.id] : []);
|
|
27347
27529
|
ordinalJsonRowsRead += rows.length;
|
|
27530
|
+
if (hasLateCommitBehindCheckpoint(db, sessionId, scan)) {
|
|
27531
|
+
discardRetainedOrdinalRanks(db, sessionId);
|
|
27532
|
+
if (isMainThread)
|
|
27533
|
+
forgetRawSessionSummaryRows(sessionId);
|
|
27534
|
+
return false;
|
|
27535
|
+
}
|
|
27348
27536
|
if (limit !== undefined && rows.length > limit)
|
|
27349
27537
|
return false;
|
|
27350
27538
|
let total = scan.total ?? 0;
|
|
@@ -27361,6 +27549,13 @@ function extendOrdinalCheckpoints(db, sessionId, scan, limit) {
|
|
|
27361
27549
|
scan.checkpoints = points;
|
|
27362
27550
|
scan.sessionRows += rows.length;
|
|
27363
27551
|
scan.total = total;
|
|
27552
|
+
if (rows.length > 0) {
|
|
27553
|
+
let maxRowid = scan.maxRowid ?? -1;
|
|
27554
|
+
for (const row of rows)
|
|
27555
|
+
if (row.rowid > maxRowid)
|
|
27556
|
+
maxRowid = row.rowid;
|
|
27557
|
+
scan.maxRowid = maxRowid;
|
|
27558
|
+
}
|
|
27364
27559
|
return true;
|
|
27365
27560
|
}
|
|
27366
27561
|
function rawOrdinalSummarySeed(db, sessionId) {
|
|
@@ -27413,8 +27608,7 @@ function boundedOrdinalPrefix(db, sessionId, through) {
|
|
|
27413
27608
|
}
|
|
27414
27609
|
function scanRawSessionSummaryRows(db, sessionId, previous) {
|
|
27415
27610
|
return withReadSnapshot(db, () => {
|
|
27416
|
-
if (previous?.checkpoints) {
|
|
27417
|
-
extendOrdinalCheckpoints(db, sessionId, previous);
|
|
27611
|
+
if (previous?.checkpoints && extendOrdinalCheckpoints(db, sessionId, previous)) {
|
|
27418
27612
|
return previous;
|
|
27419
27613
|
}
|
|
27420
27614
|
if (previous) {
|
|
@@ -27446,12 +27640,15 @@ function scanRawSessionSummaryRows(db, sessionId, previous) {
|
|
|
27446
27640
|
}
|
|
27447
27641
|
anchors.sort((left, right) => right.rowid - left.rowid);
|
|
27448
27642
|
anchors.length = Math.min(anchors.length, SUMMARY_ANCHOR_LIMIT);
|
|
27449
|
-
const keys = db.prepare(`SELECT id, time_created AS timeCreated, ${EXCLUDED_ROW_SQL} AS excluded FROM message WHERE session_id = ?
|
|
27643
|
+
const keys = db.prepare(`SELECT id, time_created AS timeCreated, rowid AS rowid, ${EXCLUDED_ROW_SQL} AS excluded FROM message WHERE session_id = ?
|
|
27450
27644
|
ORDER BY time_created, id`).all(sessionId);
|
|
27451
27645
|
const checkpoints = [];
|
|
27452
27646
|
let total = 0;
|
|
27647
|
+
let maxRowid;
|
|
27453
27648
|
for (let index = 0;index < keys.length; index++) {
|
|
27454
27649
|
const key = keys[index];
|
|
27650
|
+
if (typeof key.rowid === "number")
|
|
27651
|
+
maxRowid = maxRowid === undefined ? key.rowid : Math.max(maxRowid, key.rowid);
|
|
27455
27652
|
if (key.excluded !== 1)
|
|
27456
27653
|
total++;
|
|
27457
27654
|
if (index % 256 === 255 || index === keys.length - 1)
|
|
@@ -27462,7 +27659,7 @@ function scanRawSessionSummaryRows(db, sessionId, previous) {
|
|
|
27462
27659
|
storedCount: index + 1
|
|
27463
27660
|
});
|
|
27464
27661
|
}
|
|
27465
|
-
return { anchors, ids, sessionRows, checkpoints, total };
|
|
27662
|
+
return { anchors, ids, sessionRows, checkpoints, total, maxRowid };
|
|
27466
27663
|
});
|
|
27467
27664
|
}
|
|
27468
27665
|
function getRawSessionSummaryEpoch(sessionId) {
|
|
@@ -28024,8 +28221,6 @@ function runSessionWarmupWorker(input, options) {
|
|
|
28024
28221
|
finish({ delta: reply.delta });
|
|
28025
28222
|
else if (reply.kind === "indexed")
|
|
28026
28223
|
finish({ inserted: reply.inserted, measurements: reply.measurements });
|
|
28027
|
-
else if (reply.kind === "orphan-sweep")
|
|
28028
|
-
finish({ orphanSweep: reply.result });
|
|
28029
28224
|
else if (reply.kind === "exact-ordinal-ids")
|
|
28030
28225
|
finish({ exactOrdinalIds: reply.ids });
|
|
28031
28226
|
else if (reply.kind === "search-archive")
|
|
@@ -35081,6 +35276,7 @@ __export(exports_read_session_chunk, {
|
|
|
35081
35276
|
readRawSessionMessages: () => readRawSessionMessages,
|
|
35082
35277
|
readRawSessionSeedTail: () => readRawSessionSeedTail,
|
|
35083
35278
|
readSessionChunk: () => readSessionChunk,
|
|
35279
|
+
resolveHistorianChunkStart: () => resolveHistorianChunkStart,
|
|
35084
35280
|
resolveHostServedBoundaryId: () => resolveHostServedBoundaryId,
|
|
35085
35281
|
setBoundedRawMessageProvider: () => setBoundedRawMessageProvider,
|
|
35086
35282
|
setRawMessageProvider: () => setRawMessageProvider,
|
|
@@ -35553,6 +35749,20 @@ function readRawSessionMessageOrdinalById(sessionId, messageId) {
|
|
|
35553
35749
|
return null;
|
|
35554
35750
|
return withReadOnlySessionDb((db) => readRawSessionMessageOrdinalByIdFromDb(db, sessionId, messageId));
|
|
35555
35751
|
}
|
|
35752
|
+
function resolveHistorianChunkStart(sessionId, newest) {
|
|
35753
|
+
if (!newest)
|
|
35754
|
+
return 1;
|
|
35755
|
+
const fallback = newest.endMessage + 1;
|
|
35756
|
+
if (hasRawMessageProvider(sessionId))
|
|
35757
|
+
return fallback;
|
|
35758
|
+
const endId = newest.endMessageId;
|
|
35759
|
+
if (typeof endId !== "string" || endId.length === 0)
|
|
35760
|
+
return fallback;
|
|
35761
|
+
const ordinal = readRawSessionMessageOrdinalById(sessionId, endId);
|
|
35762
|
+
if (typeof ordinal !== "number" || !Number.isFinite(ordinal) || ordinal < 1)
|
|
35763
|
+
return fallback;
|
|
35764
|
+
return ordinal + 1;
|
|
35765
|
+
}
|
|
35556
35766
|
function readRawSessionMessageOrderPosition(sessionId, messageId) {
|
|
35557
35767
|
const provider = sessionProviders.get(sessionId)?.provider;
|
|
35558
35768
|
if (provider) {
|