@cortexkit/magic-context 0.16.1 → 0.16.3
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 +680 -332
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -7888,9 +7888,6 @@ function getMagicContextLogPath() {
|
|
|
7888
7888
|
return join(tmpdir(), "magic-context.log");
|
|
7889
7889
|
}
|
|
7890
7890
|
function getOpenCodePluginCacheDir() {
|
|
7891
|
-
if (process.platform === "win32") {
|
|
7892
|
-
return join(homedir(), "AppData", "Local", "opencode", "Cache", "packages");
|
|
7893
|
-
}
|
|
7894
7891
|
const xdg = process.env.XDG_CACHE_HOME || join(homedir(), ".cache");
|
|
7895
7892
|
return join(xdg, "opencode", "packages");
|
|
7896
7893
|
}
|
|
@@ -10508,12 +10505,13 @@ function addPluginToOpenCodeConfig(configPath, format) {
|
|
|
10508
10505
|
log.warn(`Could not parse ${configPath} — skipping to avoid data loss`);
|
|
10509
10506
|
return;
|
|
10510
10507
|
}
|
|
10511
|
-
const
|
|
10512
|
-
const
|
|
10513
|
-
|
|
10514
|
-
|
|
10508
|
+
const rawPlugins = Array.isArray(existing.plugin) ? existing.plugin : [];
|
|
10509
|
+
const hasNpmEntry = rawPlugins.some((p) => matchesPluginEntry(p, PLUGIN_NAME3));
|
|
10510
|
+
const hasDevEntry = rawPlugins.some((p) => isDevPathPluginEntry(p));
|
|
10511
|
+
if (!hasNpmEntry && !hasDevEntry) {
|
|
10512
|
+
rawPlugins.push(PLUGIN_ENTRY2);
|
|
10515
10513
|
}
|
|
10516
|
-
existing.plugin =
|
|
10514
|
+
existing.plugin = rawPlugins;
|
|
10517
10515
|
const compaction = existing.compaction ?? {};
|
|
10518
10516
|
compaction.auto = false;
|
|
10519
10517
|
compaction.prune = false;
|
|
@@ -10533,12 +10531,13 @@ function addPluginToTuiConfig(configPath, format) {
|
|
|
10533
10531
|
log.warn(`Could not parse ${configPath} — skipping to avoid data loss`);
|
|
10534
10532
|
return;
|
|
10535
10533
|
}
|
|
10536
|
-
const
|
|
10537
|
-
const
|
|
10538
|
-
|
|
10539
|
-
|
|
10534
|
+
const rawPlugins = Array.isArray(existing.plugin) ? existing.plugin : [];
|
|
10535
|
+
const hasNpmEntry = rawPlugins.some((p) => matchesPluginEntry(p, PLUGIN_NAME3));
|
|
10536
|
+
const hasDevEntry = rawPlugins.some((p) => isDevPathPluginEntry(p));
|
|
10537
|
+
if (!hasNpmEntry && !hasDevEntry) {
|
|
10538
|
+
rawPlugins.push(PLUGIN_ENTRY2);
|
|
10540
10539
|
}
|
|
10541
|
-
existing.plugin =
|
|
10540
|
+
existing.plugin = rawPlugins;
|
|
10542
10541
|
writeFileSync4(configPath, `${import_comment_json3.stringify(existing, null, 2)}
|
|
10543
10542
|
`);
|
|
10544
10543
|
}
|
|
@@ -10772,6 +10771,7 @@ var import_comment_json3, PLUGIN_NAME3 = "@cortexkit/opencode-magic-context", PL
|
|
|
10772
10771
|
var init_setup_opencode = __esm(() => {
|
|
10773
10772
|
init_conflict_detector();
|
|
10774
10773
|
init_conflict_fixer();
|
|
10774
|
+
init_opencode();
|
|
10775
10775
|
init_opencode_helpers();
|
|
10776
10776
|
init_paths();
|
|
10777
10777
|
init_prompts();
|
|
@@ -11053,7 +11053,7 @@ function printNextSteps(adapter) {
|
|
|
11053
11053
|
if (adapter.kind === "opencode") {
|
|
11054
11054
|
note([
|
|
11055
11055
|
"Restart OpenCode (or reload your session) so the plugin loads.",
|
|
11056
|
-
"Verify with:
|
|
11056
|
+
"Verify with: npx @cortexkit/magic-context@latest doctor"
|
|
11057
11057
|
].join(`
|
|
11058
11058
|
`), "Next steps");
|
|
11059
11059
|
return;
|
|
@@ -11061,7 +11061,7 @@ function printNextSteps(adapter) {
|
|
|
11061
11061
|
if (adapter.kind === "pi") {
|
|
11062
11062
|
note([
|
|
11063
11063
|
"Restart your Pi session so the extension registers.",
|
|
11064
|
-
"Verify with:
|
|
11064
|
+
"Verify with: npx @cortexkit/magic-context@latest doctor --harness pi"
|
|
11065
11065
|
].join(`
|
|
11066
11066
|
`), "Next steps");
|
|
11067
11067
|
}
|
|
@@ -11096,14 +11096,384 @@ function getOpenCodeCacheDir() {
|
|
|
11096
11096
|
}
|
|
11097
11097
|
var init_data_path = () => {};
|
|
11098
11098
|
|
|
11099
|
+
// ../../node_modules/.bun/nanotar@0.3.0/node_modules/nanotar/dist/index.mjs
|
|
11100
|
+
function parseTar(data, opts) {
|
|
11101
|
+
const buffer = data.buffer || data;
|
|
11102
|
+
const files = [];
|
|
11103
|
+
let offset = 0;
|
|
11104
|
+
let nextExtendedHeader;
|
|
11105
|
+
let globalExtendedHeader;
|
|
11106
|
+
while (offset < buffer.byteLength - 512) {
|
|
11107
|
+
let name = _readString(buffer, offset, 100);
|
|
11108
|
+
if (name.length === 0) {
|
|
11109
|
+
break;
|
|
11110
|
+
}
|
|
11111
|
+
if (nextExtendedHeader) {
|
|
11112
|
+
const longName = nextExtendedHeader.path || nextExtendedHeader.linkpath;
|
|
11113
|
+
if (longName) {
|
|
11114
|
+
name = longName;
|
|
11115
|
+
}
|
|
11116
|
+
}
|
|
11117
|
+
const mode = _readString(buffer, offset + 100, 8).trim();
|
|
11118
|
+
const uid = Number.parseInt(_readString(buffer, offset + 108, 8));
|
|
11119
|
+
const gid = Number.parseInt(_readString(buffer, offset + 116, 8));
|
|
11120
|
+
const size = _readNumber(buffer, offset + 124, 12);
|
|
11121
|
+
const seek = 512 + 512 * Math.trunc(size / 512) + (size % 512 ? 512 : 0);
|
|
11122
|
+
const mtime = _readNumber(buffer, offset + 136, 12);
|
|
11123
|
+
const _type = _readString(buffer, offset + 156, 1) || "0";
|
|
11124
|
+
const type = tarItemTypeMap[_type] || _type;
|
|
11125
|
+
switch (type) {
|
|
11126
|
+
case "extendedHeader":
|
|
11127
|
+
case "globalExtendedHeader": {
|
|
11128
|
+
const headers = _parseExtendedHeaders(new Uint8Array(buffer, offset + 512, size));
|
|
11129
|
+
if (type === "extendedHeader") {
|
|
11130
|
+
nextExtendedHeader = headers;
|
|
11131
|
+
} else {
|
|
11132
|
+
nextExtendedHeader = undefined;
|
|
11133
|
+
globalExtendedHeader = {
|
|
11134
|
+
...globalExtendedHeader,
|
|
11135
|
+
...headers
|
|
11136
|
+
};
|
|
11137
|
+
}
|
|
11138
|
+
offset += seek;
|
|
11139
|
+
continue;
|
|
11140
|
+
}
|
|
11141
|
+
case "gnuLongFileName":
|
|
11142
|
+
case "gnuOldLongFileName":
|
|
11143
|
+
case "gnuLongLinkName": {
|
|
11144
|
+
nextExtendedHeader = { path: _readString(buffer, offset + 512, size) };
|
|
11145
|
+
offset += seek;
|
|
11146
|
+
continue;
|
|
11147
|
+
}
|
|
11148
|
+
}
|
|
11149
|
+
const user = _readString(buffer, offset + 265, 32);
|
|
11150
|
+
const group = _readString(buffer, offset + 297, 32);
|
|
11151
|
+
name = _sanitizePath(name);
|
|
11152
|
+
const meta = {
|
|
11153
|
+
name,
|
|
11154
|
+
type,
|
|
11155
|
+
size,
|
|
11156
|
+
attrs: {
|
|
11157
|
+
...globalExtendedHeader,
|
|
11158
|
+
...nextExtendedHeader,
|
|
11159
|
+
mode,
|
|
11160
|
+
uid,
|
|
11161
|
+
gid,
|
|
11162
|
+
mtime,
|
|
11163
|
+
user,
|
|
11164
|
+
group
|
|
11165
|
+
}
|
|
11166
|
+
};
|
|
11167
|
+
nextExtendedHeader = undefined;
|
|
11168
|
+
if (opts?.filter && !opts.filter(meta)) {
|
|
11169
|
+
offset += seek;
|
|
11170
|
+
continue;
|
|
11171
|
+
}
|
|
11172
|
+
if (opts?.metaOnly) {
|
|
11173
|
+
files.push(meta);
|
|
11174
|
+
offset += seek;
|
|
11175
|
+
continue;
|
|
11176
|
+
}
|
|
11177
|
+
const data2 = size === 0 ? undefined : new Uint8Array(buffer, offset + 512, size);
|
|
11178
|
+
files.push({
|
|
11179
|
+
...meta,
|
|
11180
|
+
data: data2,
|
|
11181
|
+
get text() {
|
|
11182
|
+
return new TextDecoder().decode(this.data);
|
|
11183
|
+
}
|
|
11184
|
+
});
|
|
11185
|
+
offset += seek;
|
|
11186
|
+
}
|
|
11187
|
+
return files;
|
|
11188
|
+
}
|
|
11189
|
+
async function parseTarGzip(data, opts = {}) {
|
|
11190
|
+
const stream = new ReadableStream({
|
|
11191
|
+
start(controller) {
|
|
11192
|
+
controller.enqueue(new Uint8Array(data));
|
|
11193
|
+
controller.close();
|
|
11194
|
+
}
|
|
11195
|
+
}).pipeThrough(new DecompressionStream(opts.compression ?? "gzip"));
|
|
11196
|
+
const decompressedData = await new Response(stream).arrayBuffer();
|
|
11197
|
+
return parseTar(decompressedData, opts);
|
|
11198
|
+
}
|
|
11199
|
+
function _sanitizePath(path2) {
|
|
11200
|
+
let normalized = path2.replace(/\\/g, "/");
|
|
11201
|
+
normalized = normalized.replace(/^[a-zA-Z]:\//, "");
|
|
11202
|
+
normalized = normalized.replace(/^\/+/, "");
|
|
11203
|
+
const hasLeadingDotSlash = normalized.startsWith("./");
|
|
11204
|
+
const parts = normalized.split("/");
|
|
11205
|
+
const resolved = [];
|
|
11206
|
+
for (const part of parts) {
|
|
11207
|
+
if (part === "..") {
|
|
11208
|
+
resolved.pop();
|
|
11209
|
+
} else if (part !== "." && part !== "") {
|
|
11210
|
+
resolved.push(part);
|
|
11211
|
+
}
|
|
11212
|
+
}
|
|
11213
|
+
let result = resolved.join("/");
|
|
11214
|
+
if (hasLeadingDotSlash && !result.startsWith("./")) {
|
|
11215
|
+
result = "./" + result;
|
|
11216
|
+
}
|
|
11217
|
+
if (path2.endsWith("/") && !result.endsWith("/")) {
|
|
11218
|
+
result += "/";
|
|
11219
|
+
}
|
|
11220
|
+
return result;
|
|
11221
|
+
}
|
|
11222
|
+
function _readString(buffer, offset, size) {
|
|
11223
|
+
const view = new Uint8Array(buffer, offset, size);
|
|
11224
|
+
const i = view.indexOf(0);
|
|
11225
|
+
const td = new TextDecoder;
|
|
11226
|
+
return td.decode(i === -1 ? view : view.slice(0, i));
|
|
11227
|
+
}
|
|
11228
|
+
function _readNumber(buffer, offset, size) {
|
|
11229
|
+
const view = new Uint8Array(buffer, offset, size);
|
|
11230
|
+
let str = "";
|
|
11231
|
+
for (let i = 0;i < size; i++) {
|
|
11232
|
+
str += String.fromCodePoint(view[i]);
|
|
11233
|
+
}
|
|
11234
|
+
return Number.parseInt(str, 8);
|
|
11235
|
+
}
|
|
11236
|
+
function _parseExtendedHeaders(data) {
|
|
11237
|
+
const dataStr = new TextDecoder().decode(data);
|
|
11238
|
+
const headers = {};
|
|
11239
|
+
for (const line of dataStr.split(`
|
|
11240
|
+
`)) {
|
|
11241
|
+
const s = line.split(" ")[1]?.split("=");
|
|
11242
|
+
if (s) {
|
|
11243
|
+
headers[s[0]] = s[1];
|
|
11244
|
+
}
|
|
11245
|
+
}
|
|
11246
|
+
return headers;
|
|
11247
|
+
}
|
|
11248
|
+
var tarItemTypeMap;
|
|
11249
|
+
var init_dist3 = __esm(() => {
|
|
11250
|
+
tarItemTypeMap = {
|
|
11251
|
+
"0": "file",
|
|
11252
|
+
"1": "hardLink",
|
|
11253
|
+
"2": "symbolicLink",
|
|
11254
|
+
"3": "characterDevice",
|
|
11255
|
+
"4": "blockDevice",
|
|
11256
|
+
"5": "directory",
|
|
11257
|
+
"6": "fifo",
|
|
11258
|
+
"7": "contiguousFile",
|
|
11259
|
+
g: "globalExtendedHeader",
|
|
11260
|
+
x: "extendedHeader",
|
|
11261
|
+
D: "gnuDirectory",
|
|
11262
|
+
I: "gnuInodeMetadata",
|
|
11263
|
+
K: "gnuLongLinkName",
|
|
11264
|
+
L: "gnuLongFileName",
|
|
11265
|
+
N: "gnuOldLongFileName",
|
|
11266
|
+
M: "gnuMultiVolume",
|
|
11267
|
+
S: "gnuSparseFile",
|
|
11268
|
+
E: "gnuExtendedSparse",
|
|
11269
|
+
A: "solarisAcl",
|
|
11270
|
+
V: "solarisVolumeLabel",
|
|
11271
|
+
X: "solarisOldExtendedHeader"
|
|
11272
|
+
};
|
|
11273
|
+
});
|
|
11274
|
+
|
|
11275
|
+
// ../plugin/src/shared/logger.ts
|
|
11276
|
+
import * as fs from "node:fs";
|
|
11277
|
+
import * as os2 from "node:os";
|
|
11278
|
+
import * as path2 from "node:path";
|
|
11279
|
+
function flush() {
|
|
11280
|
+
if (flushTimer) {
|
|
11281
|
+
clearTimeout(flushTimer);
|
|
11282
|
+
flushTimer = null;
|
|
11283
|
+
}
|
|
11284
|
+
if (buffer.length === 0)
|
|
11285
|
+
return;
|
|
11286
|
+
const data = buffer.join("");
|
|
11287
|
+
buffer = [];
|
|
11288
|
+
try {
|
|
11289
|
+
fs.appendFileSync(logFile, data);
|
|
11290
|
+
} catch {}
|
|
11291
|
+
}
|
|
11292
|
+
function scheduleFlush() {
|
|
11293
|
+
if (flushTimer)
|
|
11294
|
+
return;
|
|
11295
|
+
flushTimer = setTimeout(() => {
|
|
11296
|
+
flushTimer = null;
|
|
11297
|
+
flush();
|
|
11298
|
+
}, FLUSH_INTERVAL_MS);
|
|
11299
|
+
}
|
|
11300
|
+
function log2(message, data) {
|
|
11301
|
+
if (isTestEnv)
|
|
11302
|
+
return;
|
|
11303
|
+
try {
|
|
11304
|
+
const timestamp = new Date().toISOString();
|
|
11305
|
+
const serialized = data === undefined ? "" : data instanceof Error ? ` ${data.message}${data.stack ? `
|
|
11306
|
+
${data.stack}` : ""}` : ` ${JSON.stringify(data)}`;
|
|
11307
|
+
buffer.push(`[${timestamp}] ${message}${serialized}
|
|
11308
|
+
`);
|
|
11309
|
+
if (buffer.length >= BUFFER_SIZE_LIMIT) {
|
|
11310
|
+
flush();
|
|
11311
|
+
} else {
|
|
11312
|
+
scheduleFlush();
|
|
11313
|
+
}
|
|
11314
|
+
} catch {}
|
|
11315
|
+
}
|
|
11316
|
+
var logFile, isTestEnv = false, buffer, flushTimer = null, FLUSH_INTERVAL_MS = 500, BUFFER_SIZE_LIMIT = 50;
|
|
11317
|
+
var init_logger = __esm(() => {
|
|
11318
|
+
logFile = path2.join(os2.tmpdir(), "magic-context.log");
|
|
11319
|
+
buffer = [];
|
|
11320
|
+
if (!isTestEnv) {
|
|
11321
|
+
process.on("exit", flush);
|
|
11322
|
+
}
|
|
11323
|
+
});
|
|
11324
|
+
|
|
11325
|
+
// ../plugin/src/shared/native-binding.ts
|
|
11326
|
+
var exports_native_binding = {};
|
|
11327
|
+
__export(exports_native_binding, {
|
|
11328
|
+
resolveBetterSqliteNativeBinding: () => resolveBetterSqliteNativeBinding
|
|
11329
|
+
});
|
|
11330
|
+
import { existsSync as existsSync9, mkdirSync as mkdirSync4, writeFileSync as writeFileSync6 } from "node:fs";
|
|
11331
|
+
import { createRequire as createRequire2 } from "node:module";
|
|
11332
|
+
import * as path3 from "node:path";
|
|
11333
|
+
function logInfo(message) {
|
|
11334
|
+
log2(`${PREFIX} ${message}`);
|
|
11335
|
+
}
|
|
11336
|
+
function logWarn(message) {
|
|
11337
|
+
log2(`${PREFIX} WARN ${message}`);
|
|
11338
|
+
}
|
|
11339
|
+
function probeAbi(binaryPath) {
|
|
11340
|
+
const expected = process.versions.modules;
|
|
11341
|
+
try {
|
|
11342
|
+
const sandbox = { exports: {} };
|
|
11343
|
+
process.dlopen(sandbox, binaryPath);
|
|
11344
|
+
return { ok: true };
|
|
11345
|
+
} catch (err) {
|
|
11346
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
11347
|
+
const pair = message.match(/NODE_MODULE_VERSION (\d+).*NODE_MODULE_VERSION (\d+)/s);
|
|
11348
|
+
if (pair?.[1] && pair[2]) {
|
|
11349
|
+
return { ok: false, expected: pair[2], actual: pair[1] };
|
|
11350
|
+
}
|
|
11351
|
+
const single = message.match(/NODE_MODULE_VERSION[ =:]+(\d+)/);
|
|
11352
|
+
if (single?.[1]) {
|
|
11353
|
+
return { ok: false, expected, actual: single[1] };
|
|
11354
|
+
}
|
|
11355
|
+
logWarn(`could not parse ABI from dlopen error: ${message}`);
|
|
11356
|
+
return { ok: false, expected, actual: null };
|
|
11357
|
+
}
|
|
11358
|
+
}
|
|
11359
|
+
function resolveBetterSqlite3OnDisk(requireFn) {
|
|
11360
|
+
try {
|
|
11361
|
+
const pkgJsonPath = requireFn.resolve("better-sqlite3/package.json");
|
|
11362
|
+
const pkgDir = path3.dirname(pkgJsonPath);
|
|
11363
|
+
const pkgJson = requireFn(pkgJsonPath);
|
|
11364
|
+
const binaryPath = path3.join(pkgDir, "build", "Release", "better_sqlite3.node");
|
|
11365
|
+
return { binaryPath, pkgVersion: pkgJson.version };
|
|
11366
|
+
} catch (err) {
|
|
11367
|
+
logWarn(`could not resolve better-sqlite3 in node_modules: ${err instanceof Error ? err.message : String(err)}`);
|
|
11368
|
+
return null;
|
|
11369
|
+
}
|
|
11370
|
+
}
|
|
11371
|
+
function getCachedBinaryPath(pkgVersion, abi) {
|
|
11372
|
+
return path3.join(getCacheDir(), "cortexkit", "native-bindings", "better-sqlite3", `v${pkgVersion}`, `electron-v${abi}-${process.platform}-${process.arch}`, "better_sqlite3.node");
|
|
11373
|
+
}
|
|
11374
|
+
async function downloadElectronPrebuild(pkgVersion, abi) {
|
|
11375
|
+
const filename = `better-sqlite3-v${pkgVersion}-electron-v${abi}-${process.platform}-${process.arch}.tar.gz`;
|
|
11376
|
+
const url = `https://github.com/WiseLibs/better-sqlite3/releases/download/v${pkgVersion}/${filename}`;
|
|
11377
|
+
logInfo(`downloading ${url}`);
|
|
11378
|
+
const response = await fetch(url, {
|
|
11379
|
+
redirect: "follow",
|
|
11380
|
+
headers: { "User-Agent": "magic-context-plugin/native-binding" }
|
|
11381
|
+
});
|
|
11382
|
+
if (!response.ok) {
|
|
11383
|
+
throw new Error(`failed to download Electron prebuild (HTTP ${response.status} ${response.statusText}) from ${url}`);
|
|
11384
|
+
}
|
|
11385
|
+
const tarballBytes = new Uint8Array(await response.arrayBuffer());
|
|
11386
|
+
logInfo(`downloaded ${(tarballBytes.length / 1024).toFixed(1)} KB; extracting`);
|
|
11387
|
+
const files = await parseTarGzip(tarballBytes);
|
|
11388
|
+
const nodeFile = files.find((f) => f.name.endsWith("better_sqlite3.node"));
|
|
11389
|
+
if (!nodeFile?.data) {
|
|
11390
|
+
const names = files.map((f) => f.name).join(", ");
|
|
11391
|
+
throw new Error(`Electron prebuild tarball did not contain better_sqlite3.node; got: [${names}]`);
|
|
11392
|
+
}
|
|
11393
|
+
return nodeFile.data instanceof Uint8Array ? nodeFile.data : new Uint8Array(nodeFile.data);
|
|
11394
|
+
}
|
|
11395
|
+
async function resolveBetterSqliteNativeBinding() {
|
|
11396
|
+
if (!process.versions.electron) {
|
|
11397
|
+
return null;
|
|
11398
|
+
}
|
|
11399
|
+
if (inFlight) {
|
|
11400
|
+
return inFlight;
|
|
11401
|
+
}
|
|
11402
|
+
const promise = (async () => {
|
|
11403
|
+
const expected = process.versions.modules;
|
|
11404
|
+
logInfo(`Electron detected (v${process.versions.electron}, NODE_MODULE_VERSION ${expected}); verifying better-sqlite3 binding`);
|
|
11405
|
+
const requireFn = createRequire2(import.meta.url);
|
|
11406
|
+
const resolved = resolveBetterSqlite3OnDisk(requireFn);
|
|
11407
|
+
if (!resolved) {
|
|
11408
|
+
return null;
|
|
11409
|
+
}
|
|
11410
|
+
const { binaryPath: diskPath, pkgVersion } = resolved;
|
|
11411
|
+
if (existsSync9(diskPath)) {
|
|
11412
|
+
const diskProbe = probeAbi(diskPath);
|
|
11413
|
+
if (diskProbe.ok) {
|
|
11414
|
+
logInfo(`on-disk binary already matches Electron ABI v${expected}; using default bindings() lookup`);
|
|
11415
|
+
return null;
|
|
11416
|
+
}
|
|
11417
|
+
logInfo(`on-disk binary ABI ${diskProbe.actual ?? "unknown"} != required ${expected}; will use Electron prebuild`);
|
|
11418
|
+
} else {
|
|
11419
|
+
logWarn(`expected better-sqlite3 binary not found at ${diskPath}; will fetch Electron prebuild anyway`);
|
|
11420
|
+
}
|
|
11421
|
+
const cachedPath = getCachedBinaryPath(pkgVersion, expected);
|
|
11422
|
+
if (existsSync9(cachedPath)) {
|
|
11423
|
+
const cachedProbe = probeAbi(cachedPath);
|
|
11424
|
+
if (cachedProbe.ok) {
|
|
11425
|
+
logInfo(`using cached Electron prebuild at ${cachedPath}`);
|
|
11426
|
+
return cachedPath;
|
|
11427
|
+
}
|
|
11428
|
+
logWarn(`cached binary at ${cachedPath} has wrong ABI (${cachedProbe.actual ?? "unknown"} != ${expected}); refetching`);
|
|
11429
|
+
}
|
|
11430
|
+
mkdirSync4(path3.dirname(cachedPath), { recursive: true });
|
|
11431
|
+
const nodeFileBytes = await downloadElectronPrebuild(pkgVersion, expected);
|
|
11432
|
+
writeFileSync6(cachedPath, nodeFileBytes);
|
|
11433
|
+
logInfo(`cached Electron prebuild at ${cachedPath} (${(nodeFileBytes.length / 1024).toFixed(1)} KB)`);
|
|
11434
|
+
const finalProbe = probeAbi(cachedPath);
|
|
11435
|
+
if (!finalProbe.ok) {
|
|
11436
|
+
throw new Error(`downloaded Electron prebuild has wrong ABI (${finalProbe.actual ?? "unknown"} != ${expected}); refusing to use`);
|
|
11437
|
+
}
|
|
11438
|
+
return cachedPath;
|
|
11439
|
+
})();
|
|
11440
|
+
inFlight = promise;
|
|
11441
|
+
try {
|
|
11442
|
+
return await promise;
|
|
11443
|
+
} finally {
|
|
11444
|
+
if (inFlight === promise) {
|
|
11445
|
+
inFlight = null;
|
|
11446
|
+
}
|
|
11447
|
+
}
|
|
11448
|
+
}
|
|
11449
|
+
var PREFIX = "[native-binding]", inFlight = null;
|
|
11450
|
+
var init_native_binding = __esm(() => {
|
|
11451
|
+
init_dist3();
|
|
11452
|
+
init_data_path();
|
|
11453
|
+
init_logger();
|
|
11454
|
+
});
|
|
11455
|
+
|
|
11099
11456
|
// ../plugin/src/shared/sqlite.ts
|
|
11100
|
-
var isBun, bunSpec, betterSpec, sqliteModule, DatabaseImpl, Database;
|
|
11457
|
+
var isBun, bunSpec, betterSpec, electronNativeBinding, sqliteModule, RawDatabaseImpl, DatabaseImpl, Database;
|
|
11101
11458
|
var init_sqlite = __esm(async () => {
|
|
11102
11459
|
isBun = typeof process !== "undefined" && typeof process.versions?.bun === "string";
|
|
11103
11460
|
bunSpec = "bun:" + "sqlite";
|
|
11104
11461
|
betterSpec = "better-" + "sqlite3";
|
|
11462
|
+
electronNativeBinding = isBun ? null : await (async () => {
|
|
11463
|
+
const mod = await Promise.resolve().then(() => (init_native_binding(), exports_native_binding));
|
|
11464
|
+
return mod.resolveBetterSqliteNativeBinding();
|
|
11465
|
+
})();
|
|
11105
11466
|
sqliteModule = isBun ? await import(bunSpec) : await import(betterSpec);
|
|
11106
|
-
|
|
11467
|
+
RawDatabaseImpl = isBun ? sqliteModule.Database : sqliteModule.default;
|
|
11468
|
+
DatabaseImpl = electronNativeBinding == null ? RawDatabaseImpl : class DatabaseWithElectronBinding extends RawDatabaseImpl {
|
|
11469
|
+
constructor(filename, options) {
|
|
11470
|
+
const fallback = electronNativeBinding;
|
|
11471
|
+
super(filename, {
|
|
11472
|
+
...options,
|
|
11473
|
+
nativeBinding: options?.nativeBinding ?? fallback
|
|
11474
|
+
});
|
|
11475
|
+
}
|
|
11476
|
+
};
|
|
11107
11477
|
Database = DatabaseImpl;
|
|
11108
11478
|
});
|
|
11109
11479
|
|
|
@@ -11119,20 +11489,20 @@ __export(exports_migrate, {
|
|
|
11119
11489
|
formatPiFilenameTimestamp: () => formatPiFilenameTimestamp
|
|
11120
11490
|
});
|
|
11121
11491
|
import { randomBytes } from "node:crypto";
|
|
11122
|
-
import { existsSync as
|
|
11492
|
+
import { existsSync as existsSync10, mkdirSync as mkdirSync5, writeFileSync as writeFileSync7 } from "node:fs";
|
|
11123
11493
|
import { homedir as homedir5 } from "node:os";
|
|
11124
|
-
import { join as
|
|
11494
|
+
import { join as join9 } from "node:path";
|
|
11125
11495
|
function defaultOpenCodeDbPath() {
|
|
11126
|
-
return
|
|
11496
|
+
return join9(homedir5(), ".local", "share", "opencode", "opencode.db");
|
|
11127
11497
|
}
|
|
11128
11498
|
function defaultCortexkitDbPath() {
|
|
11129
|
-
return
|
|
11499
|
+
return join9(getMagicContextStorageDir(), "context.db");
|
|
11130
11500
|
}
|
|
11131
11501
|
function defaultPiSessionsRoot() {
|
|
11132
|
-
return
|
|
11502
|
+
return join9(homedir5(), ".pi", "agent", "sessions");
|
|
11133
11503
|
}
|
|
11134
11504
|
function defaultFs() {
|
|
11135
|
-
return { existsSync:
|
|
11505
|
+
return { existsSync: existsSync10, mkdirSync: mkdirSync5, writeFileSync: writeFileSync7 };
|
|
11136
11506
|
}
|
|
11137
11507
|
function stmt(db, sql) {
|
|
11138
11508
|
return db.prepare(sql);
|
|
@@ -11529,7 +11899,7 @@ function ensureValidOptions(opts) {
|
|
|
11529
11899
|
}
|
|
11530
11900
|
}
|
|
11531
11901
|
function migrateOpenCodeSessionToPi(opts) {
|
|
11532
|
-
const
|
|
11902
|
+
const fs2 = opts.fs ?? defaultFs();
|
|
11533
11903
|
const now = opts.now ?? new Date;
|
|
11534
11904
|
const opencodeDbPath = opts.opencodeDbPath ?? defaultOpenCodeDbPath();
|
|
11535
11905
|
const piSessionsRoot = opts.piSessionsRoot ?? defaultPiSessionsRoot();
|
|
@@ -11555,7 +11925,7 @@ function migrateOpenCodeSessionToPi(opts) {
|
|
|
11555
11925
|
const provider = opts.provider ?? model.provider;
|
|
11556
11926
|
const modelId = opts.modelId ?? model.modelId;
|
|
11557
11927
|
const cwd = session.directory ?? session.path ?? process.cwd();
|
|
11558
|
-
const outputDir =
|
|
11928
|
+
const outputDir = join9(piSessionsRoot, projectPathToPiDirSlug(cwd));
|
|
11559
11929
|
const buildResult = buildPiEntries({
|
|
11560
11930
|
session,
|
|
11561
11931
|
messages,
|
|
@@ -11581,14 +11951,14 @@ function migrateOpenCodeSessionToPi(opts) {
|
|
|
11581
11951
|
});
|
|
11582
11952
|
}
|
|
11583
11953
|
const compactionMarker = insertCompactionMarker(buildResult.entries, copyResult.lastCompartmentEndPiEntryId);
|
|
11584
|
-
const outputPath =
|
|
11954
|
+
const outputPath = join9(outputDir, `${formatPiFilenameTimestamp(now)}_${buildResult.piSessionId}.jsonl`);
|
|
11585
11955
|
const jsonl = `${buildResult.entries.map((entry) => JSON.stringify(entry)).join(`
|
|
11586
11956
|
`)}
|
|
11587
11957
|
`;
|
|
11588
11958
|
if (!opts.dryRun) {
|
|
11589
|
-
if (!
|
|
11590
|
-
|
|
11591
|
-
|
|
11959
|
+
if (!fs2.existsSync(outputDir))
|
|
11960
|
+
fs2.mkdirSync(outputDir, { recursive: true });
|
|
11961
|
+
fs2.writeFileSync(outputPath, jsonl);
|
|
11592
11962
|
}
|
|
11593
11963
|
return {
|
|
11594
11964
|
outputPath,
|
|
@@ -11651,7 +12021,7 @@ function printMigrateHelp() {
|
|
|
11651
12021
|
--from opencode --to pi
|
|
11652
12022
|
|
|
11653
12023
|
Usage:
|
|
11654
|
-
|
|
12024
|
+
npx @cortexkit/opencode-magic-context@latest doctor migrate \\
|
|
11655
12025
|
--from opencode --to pi --session ses_xxx [--max-messages N] [--dry-run]
|
|
11656
12026
|
|
|
11657
12027
|
Fidelity:
|
|
@@ -11955,10 +12325,10 @@ function mergeDefs(...defs) {
|
|
|
11955
12325
|
function cloneDef(schema) {
|
|
11956
12326
|
return mergeDefs(schema._zod.def);
|
|
11957
12327
|
}
|
|
11958
|
-
function getElementAtPath(obj,
|
|
11959
|
-
if (!
|
|
12328
|
+
function getElementAtPath(obj, path4) {
|
|
12329
|
+
if (!path4)
|
|
11960
12330
|
return obj;
|
|
11961
|
-
return
|
|
12331
|
+
return path4.reduce((acc, key) => acc?.[key], obj);
|
|
11962
12332
|
}
|
|
11963
12333
|
function promiseAllObject(promisesObj) {
|
|
11964
12334
|
const keys = Object.keys(promisesObj);
|
|
@@ -12269,11 +12639,11 @@ function aborted(x3, startIndex = 0) {
|
|
|
12269
12639
|
}
|
|
12270
12640
|
return false;
|
|
12271
12641
|
}
|
|
12272
|
-
function prefixIssues(
|
|
12642
|
+
function prefixIssues(path4, issues) {
|
|
12273
12643
|
return issues.map((iss) => {
|
|
12274
12644
|
var _a;
|
|
12275
12645
|
(_a = iss).path ?? (_a.path = []);
|
|
12276
|
-
iss.path.unshift(
|
|
12646
|
+
iss.path.unshift(path4);
|
|
12277
12647
|
return iss;
|
|
12278
12648
|
});
|
|
12279
12649
|
}
|
|
@@ -12511,7 +12881,7 @@ function formatError(error, mapper = (issue2) => issue2.message) {
|
|
|
12511
12881
|
}
|
|
12512
12882
|
function treeifyError(error, mapper = (issue2) => issue2.message) {
|
|
12513
12883
|
const result = { errors: [] };
|
|
12514
|
-
const processError = (error2,
|
|
12884
|
+
const processError = (error2, path4 = []) => {
|
|
12515
12885
|
var _a, _b;
|
|
12516
12886
|
for (const issue2 of error2.issues) {
|
|
12517
12887
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
@@ -12521,7 +12891,7 @@ function treeifyError(error, mapper = (issue2) => issue2.message) {
|
|
|
12521
12891
|
} else if (issue2.code === "invalid_element") {
|
|
12522
12892
|
processError({ issues: issue2.issues }, issue2.path);
|
|
12523
12893
|
} else {
|
|
12524
|
-
const fullpath = [...
|
|
12894
|
+
const fullpath = [...path4, ...issue2.path];
|
|
12525
12895
|
if (fullpath.length === 0) {
|
|
12526
12896
|
result.errors.push(mapper(issue2));
|
|
12527
12897
|
continue;
|
|
@@ -12553,8 +12923,8 @@ function treeifyError(error, mapper = (issue2) => issue2.message) {
|
|
|
12553
12923
|
}
|
|
12554
12924
|
function toDotPath(_path) {
|
|
12555
12925
|
const segs = [];
|
|
12556
|
-
const
|
|
12557
|
-
for (const seg of
|
|
12926
|
+
const path4 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
|
|
12927
|
+
for (const seg of path4) {
|
|
12558
12928
|
if (typeof seg === "number")
|
|
12559
12929
|
segs.push(`[${seg}]`);
|
|
12560
12930
|
else if (typeof seg === "symbol")
|
|
@@ -24829,13 +25199,13 @@ function resolveRef(ref, ctx) {
|
|
|
24829
25199
|
if (!ref.startsWith("#")) {
|
|
24830
25200
|
throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
|
|
24831
25201
|
}
|
|
24832
|
-
const
|
|
24833
|
-
if (
|
|
25202
|
+
const path4 = ref.slice(1).split("/").filter(Boolean);
|
|
25203
|
+
if (path4.length === 0) {
|
|
24834
25204
|
return ctx.rootSchema;
|
|
24835
25205
|
}
|
|
24836
25206
|
const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
|
|
24837
|
-
if (
|
|
24838
|
-
const key =
|
|
25207
|
+
if (path4[0] === defsKey) {
|
|
25208
|
+
const key = path4[1];
|
|
24839
25209
|
if (!key || !ctx.defs[key]) {
|
|
24840
25210
|
throw new Error(`Reference not found: ${ref}`);
|
|
24841
25211
|
}
|
|
@@ -25721,6 +26091,13 @@ var init_magic_context = __esm(() => {
|
|
|
25721
26091
|
min_clusters: exports_external.number().min(1).default(3)
|
|
25722
26092
|
}).default({ enabled: true, min_clusters: 3 }),
|
|
25723
26093
|
compaction_markers: exports_external.boolean().default(true),
|
|
26094
|
+
system_prompt_injection: exports_external.object({
|
|
26095
|
+
enabled: exports_external.boolean().default(true),
|
|
26096
|
+
skip_signatures: exports_external.array(exports_external.string()).default(["<!-- magic-context: skip -->"])
|
|
26097
|
+
}).default({
|
|
26098
|
+
enabled: true,
|
|
26099
|
+
skip_signatures: ["<!-- magic-context: skip -->"]
|
|
26100
|
+
}),
|
|
25724
26101
|
compressor: exports_external.object({
|
|
25725
26102
|
enabled: exports_external.boolean().default(true),
|
|
25726
26103
|
min_compartment_ratio: exports_external.number().min(100).max(1e4).default(DEFAULT_COMPRESSOR_MIN_COMPARTMENT_RATIO),
|
|
@@ -25783,9 +26160,9 @@ var init_magic_context = __esm(() => {
|
|
|
25783
26160
|
});
|
|
25784
26161
|
|
|
25785
26162
|
// ../plugin/src/config/variable.ts
|
|
25786
|
-
import { existsSync as
|
|
26163
|
+
import { existsSync as existsSync11, readFileSync as readFileSync6 } from "node:fs";
|
|
25787
26164
|
import { homedir as homedir6 } from "node:os";
|
|
25788
|
-
import { dirname as
|
|
26165
|
+
import { dirname as dirname7, isAbsolute, resolve as resolve2 } from "node:path";
|
|
25789
26166
|
function substituteConfigVariables(input) {
|
|
25790
26167
|
const warnings = [];
|
|
25791
26168
|
let text2 = input.text;
|
|
@@ -25802,7 +26179,7 @@ function substituteConfigVariables(input) {
|
|
|
25802
26179
|
if (fileMatches.length === 0) {
|
|
25803
26180
|
return { text: text2, warnings };
|
|
25804
26181
|
}
|
|
25805
|
-
const configDir = input.configPath ?
|
|
26182
|
+
const configDir = input.configPath ? dirname7(input.configPath) : process.cwd();
|
|
25806
26183
|
let output = "";
|
|
25807
26184
|
let cursor = 0;
|
|
25808
26185
|
for (const match of fileMatches) {
|
|
@@ -25824,7 +26201,7 @@ function substituteConfigVariables(input) {
|
|
|
25824
26201
|
} else if (!isAbsolute(filePath)) {
|
|
25825
26202
|
filePath = resolve2(configDir, filePath);
|
|
25826
26203
|
}
|
|
25827
|
-
if (!
|
|
26204
|
+
if (!existsSync11(filePath)) {
|
|
25828
26205
|
warnings.push(`File not found for ${token} (resolved to ${filePath}); using empty string`);
|
|
25829
26206
|
continue;
|
|
25830
26207
|
}
|
|
@@ -25848,19 +26225,19 @@ var init_variable = __esm(() => {
|
|
|
25848
26225
|
});
|
|
25849
26226
|
|
|
25850
26227
|
// ../plugin/src/config/index.ts
|
|
25851
|
-
import { existsSync as
|
|
26228
|
+
import { existsSync as existsSync12, readFileSync as readFileSync7 } from "node:fs";
|
|
25852
26229
|
import { homedir as homedir7 } from "node:os";
|
|
25853
|
-
import { join as
|
|
26230
|
+
import { join as join10 } from "node:path";
|
|
25854
26231
|
function getUserConfigBasePath() {
|
|
25855
|
-
const configRoot = process.env.XDG_CONFIG_HOME ??
|
|
25856
|
-
return
|
|
26232
|
+
const configRoot = process.env.XDG_CONFIG_HOME ?? join10(homedir7(), ".config");
|
|
26233
|
+
return join10(configRoot, "opencode", CONFIG_FILE_BASENAME);
|
|
25857
26234
|
}
|
|
25858
26235
|
function getProjectConfigBasePath(directory) {
|
|
25859
|
-
return
|
|
26236
|
+
return join10(directory, ".opencode", CONFIG_FILE_BASENAME);
|
|
25860
26237
|
}
|
|
25861
26238
|
function loadConfigFile(configPath) {
|
|
25862
26239
|
try {
|
|
25863
|
-
if (!
|
|
26240
|
+
if (!existsSync12(configPath)) {
|
|
25864
26241
|
return null;
|
|
25865
26242
|
}
|
|
25866
26243
|
const rawText = readFileSync7(configPath, "utf-8");
|
|
@@ -26037,7 +26414,7 @@ function parsePluginConfig(rawConfig) {
|
|
|
26037
26414
|
}
|
|
26038
26415
|
function loadPluginConfig(directory) {
|
|
26039
26416
|
const userDetected = detectConfigFile(getUserConfigBasePath());
|
|
26040
|
-
const rootDetected = detectConfigFile(
|
|
26417
|
+
const rootDetected = detectConfigFile(join10(directory, CONFIG_FILE_BASENAME));
|
|
26041
26418
|
const dotOpenCodeDetected = detectConfigFile(getProjectConfigBasePath(directory));
|
|
26042
26419
|
const projectDetected = rootDetected.format !== "none" ? rootDetected : dotOpenCodeDetected;
|
|
26043
26420
|
const userLoaded = userDetected.format === "none" ? null : loadConfigFile(userDetected.path);
|
|
@@ -26180,59 +26557,9 @@ function truncate(text2) {
|
|
|
26180
26557
|
}
|
|
26181
26558
|
var DEFAULT_TIMEOUT_MS = 1e4, MAX_PREVIEW_CHARS = 240;
|
|
26182
26559
|
|
|
26183
|
-
// ../plugin/src/shared/logger.ts
|
|
26184
|
-
import * as fs from "node:fs";
|
|
26185
|
-
import * as os2 from "node:os";
|
|
26186
|
-
import * as path2 from "node:path";
|
|
26187
|
-
function flush() {
|
|
26188
|
-
if (flushTimer) {
|
|
26189
|
-
clearTimeout(flushTimer);
|
|
26190
|
-
flushTimer = null;
|
|
26191
|
-
}
|
|
26192
|
-
if (buffer.length === 0)
|
|
26193
|
-
return;
|
|
26194
|
-
const data = buffer.join("");
|
|
26195
|
-
buffer = [];
|
|
26196
|
-
try {
|
|
26197
|
-
fs.appendFileSync(logFile, data);
|
|
26198
|
-
} catch {}
|
|
26199
|
-
}
|
|
26200
|
-
function scheduleFlush() {
|
|
26201
|
-
if (flushTimer)
|
|
26202
|
-
return;
|
|
26203
|
-
flushTimer = setTimeout(() => {
|
|
26204
|
-
flushTimer = null;
|
|
26205
|
-
flush();
|
|
26206
|
-
}, FLUSH_INTERVAL_MS);
|
|
26207
|
-
}
|
|
26208
|
-
function log2(message, data) {
|
|
26209
|
-
if (isTestEnv)
|
|
26210
|
-
return;
|
|
26211
|
-
try {
|
|
26212
|
-
const timestamp = new Date().toISOString();
|
|
26213
|
-
const serialized = data === undefined ? "" : data instanceof Error ? ` ${data.message}${data.stack ? `
|
|
26214
|
-
${data.stack}` : ""}` : ` ${JSON.stringify(data)}`;
|
|
26215
|
-
buffer.push(`[${timestamp}] ${message}${serialized}
|
|
26216
|
-
`);
|
|
26217
|
-
if (buffer.length >= BUFFER_SIZE_LIMIT) {
|
|
26218
|
-
flush();
|
|
26219
|
-
} else {
|
|
26220
|
-
scheduleFlush();
|
|
26221
|
-
}
|
|
26222
|
-
} catch {}
|
|
26223
|
-
}
|
|
26224
|
-
var logFile, isTestEnv = false, buffer, flushTimer = null, FLUSH_INTERVAL_MS = 500, BUFFER_SIZE_LIMIT = 50;
|
|
26225
|
-
var init_logger = __esm(() => {
|
|
26226
|
-
logFile = path2.join(os2.tmpdir(), "magic-context.log");
|
|
26227
|
-
buffer = [];
|
|
26228
|
-
if (!isTestEnv) {
|
|
26229
|
-
process.on("exit", flush);
|
|
26230
|
-
}
|
|
26231
|
-
});
|
|
26232
|
-
|
|
26233
26560
|
// ../plugin/src/shared/tui-config.ts
|
|
26234
|
-
import { existsSync as
|
|
26235
|
-
import { dirname as
|
|
26561
|
+
import { existsSync as existsSync13, mkdirSync as mkdirSync6, readFileSync as readFileSync8, writeFileSync as writeFileSync8 } from "node:fs";
|
|
26562
|
+
import { dirname as dirname8, join as join11 } from "node:path";
|
|
26236
26563
|
function isMagicContextEntry(entry) {
|
|
26237
26564
|
if (!entry)
|
|
26238
26565
|
return false;
|
|
@@ -26246,11 +26573,11 @@ function isMagicContextEntry(entry) {
|
|
|
26246
26573
|
}
|
|
26247
26574
|
function resolveTuiConfigPath() {
|
|
26248
26575
|
const configDir = getOpenCodeConfigPaths({ binary: "opencode" }).configDir;
|
|
26249
|
-
const jsoncPath =
|
|
26250
|
-
const jsonPath =
|
|
26251
|
-
if (
|
|
26576
|
+
const jsoncPath = join11(configDir, "tui.jsonc");
|
|
26577
|
+
const jsonPath = join11(configDir, "tui.json");
|
|
26578
|
+
if (existsSync13(jsoncPath))
|
|
26252
26579
|
return jsoncPath;
|
|
26253
|
-
if (
|
|
26580
|
+
if (existsSync13(jsonPath))
|
|
26254
26581
|
return jsonPath;
|
|
26255
26582
|
return jsonPath;
|
|
26256
26583
|
}
|
|
@@ -26258,7 +26585,7 @@ function ensureTuiPluginEntry() {
|
|
|
26258
26585
|
try {
|
|
26259
26586
|
const configPath = resolveTuiConfigPath();
|
|
26260
26587
|
let config2 = {};
|
|
26261
|
-
if (
|
|
26588
|
+
if (existsSync13(configPath)) {
|
|
26262
26589
|
const raw = readFileSync8(configPath, "utf-8");
|
|
26263
26590
|
config2 = import_comment_json5.parse(raw) ?? {};
|
|
26264
26591
|
}
|
|
@@ -26278,8 +26605,8 @@ function ensureTuiPluginEntry() {
|
|
|
26278
26605
|
plugins.push(PLUGIN_ENTRY3);
|
|
26279
26606
|
}
|
|
26280
26607
|
config2.plugin = plugins;
|
|
26281
|
-
|
|
26282
|
-
|
|
26608
|
+
mkdirSync6(dirname8(configPath), { recursive: true });
|
|
26609
|
+
writeFileSync8(configPath, `${import_comment_json5.stringify(config2, null, 2)}
|
|
26283
26610
|
`);
|
|
26284
26611
|
log2(`[magic-context] updated TUI plugin entry in ${configPath}`);
|
|
26285
26612
|
return true;
|
|
@@ -26347,12 +26674,12 @@ var init_compartment_parser = __esm(() => {
|
|
|
26347
26674
|
});
|
|
26348
26675
|
|
|
26349
26676
|
// src/lib/diagnostics-opencode.ts
|
|
26350
|
-
import { existsSync as
|
|
26351
|
-
import { createRequire as
|
|
26677
|
+
import { existsSync as existsSync14, readdirSync as readdirSync2, readFileSync as readFileSync9, statSync as statSync2 } from "node:fs";
|
|
26678
|
+
import { createRequire as createRequire3 } from "node:module";
|
|
26352
26679
|
import { homedir as homedir8, tmpdir as tmpdir3, userInfo } from "node:os";
|
|
26353
|
-
import { join as
|
|
26680
|
+
import { join as join12 } from "node:path";
|
|
26354
26681
|
function getSelfVersion() {
|
|
26355
|
-
const require2 =
|
|
26682
|
+
const require2 = createRequire3(import.meta.url);
|
|
26356
26683
|
for (const relPath of ["../../package.json", "../package.json"]) {
|
|
26357
26684
|
try {
|
|
26358
26685
|
const pkg = require2(relPath);
|
|
@@ -26364,26 +26691,26 @@ function getSelfVersion() {
|
|
|
26364
26691
|
return "unknown";
|
|
26365
26692
|
}
|
|
26366
26693
|
function getPluginCacheInfo() {
|
|
26367
|
-
const
|
|
26694
|
+
const path4 = join12(getOpenCodeCacheDir(), "packages", PLUGIN_ENTRY_WITH_VERSION);
|
|
26368
26695
|
let cached2;
|
|
26369
26696
|
try {
|
|
26370
|
-
const installedPkgPath =
|
|
26371
|
-
if (
|
|
26697
|
+
const installedPkgPath = join12(path4, "node_modules", "@cortexkit", "opencode-magic-context", "package.json");
|
|
26698
|
+
if (existsSync14(installedPkgPath)) {
|
|
26372
26699
|
const pkg = JSON.parse(readFileSync9(installedPkgPath, "utf-8"));
|
|
26373
26700
|
cached2 = typeof pkg.version === "string" ? pkg.version : undefined;
|
|
26374
26701
|
}
|
|
26375
26702
|
} catch {
|
|
26376
26703
|
cached2 = undefined;
|
|
26377
26704
|
}
|
|
26378
|
-
return { path:
|
|
26705
|
+
return { path: path4, cached: cached2, latest: getSelfVersion() };
|
|
26379
26706
|
}
|
|
26380
26707
|
function getStorageDir() {
|
|
26381
|
-
const dataHome = process.env.XDG_DATA_HOME ||
|
|
26382
|
-
return
|
|
26708
|
+
const dataHome = process.env.XDG_DATA_HOME || join12(homedir8(), ".local", "share");
|
|
26709
|
+
return join12(dataHome, "cortexkit", "magic-context");
|
|
26383
26710
|
}
|
|
26384
|
-
function fileSize(
|
|
26711
|
+
function fileSize(path4) {
|
|
26385
26712
|
try {
|
|
26386
|
-
return
|
|
26713
|
+
return existsSync14(path4) ? statSync2(path4).size : 0;
|
|
26387
26714
|
} catch {
|
|
26388
26715
|
return 0;
|
|
26389
26716
|
}
|
|
@@ -26416,11 +26743,11 @@ function sanitizeValue(value) {
|
|
|
26416
26743
|
}
|
|
26417
26744
|
return value;
|
|
26418
26745
|
}
|
|
26419
|
-
function readConfig2(
|
|
26420
|
-
if (!
|
|
26746
|
+
function readConfig2(path4) {
|
|
26747
|
+
if (!existsSync14(path4))
|
|
26421
26748
|
return { value: null };
|
|
26422
26749
|
try {
|
|
26423
|
-
const raw = readFileSync9(
|
|
26750
|
+
const raw = readFileSync9(path4, "utf-8");
|
|
26424
26751
|
const value = import_comment_json6.parse(raw);
|
|
26425
26752
|
return { value };
|
|
26426
26753
|
} catch (error48) {
|
|
@@ -26441,9 +26768,9 @@ function configHasPluginEntry(config2) {
|
|
|
26441
26768
|
return false;
|
|
26442
26769
|
});
|
|
26443
26770
|
}
|
|
26444
|
-
function parseHistorianDumpMeta(
|
|
26771
|
+
function parseHistorianDumpMeta(path4) {
|
|
26445
26772
|
try {
|
|
26446
|
-
const xml = readFileSync9(
|
|
26773
|
+
const xml = readFileSync9(path4, "utf-8");
|
|
26447
26774
|
const parsed = parseCompartmentOutput(xml);
|
|
26448
26775
|
const factCountByCategory = {};
|
|
26449
26776
|
for (const fact of parsed.facts) {
|
|
@@ -26476,13 +26803,13 @@ function parseHistorianDumpMeta(path3) {
|
|
|
26476
26803
|
}
|
|
26477
26804
|
}
|
|
26478
26805
|
function collectHistorianDumps() {
|
|
26479
|
-
const dir =
|
|
26480
|
-
if (!
|
|
26806
|
+
const dir = join12(tmpdir3(), "magic-context-historian");
|
|
26807
|
+
if (!existsSync14(dir)) {
|
|
26481
26808
|
return { dir, count: 0, recent: [] };
|
|
26482
26809
|
}
|
|
26483
26810
|
try {
|
|
26484
26811
|
const entries = readdirSync2(dir).filter((name) => name.endsWith(".xml")).map((name) => {
|
|
26485
|
-
const stat = statSync2(
|
|
26812
|
+
const stat = statSync2(join12(dir, name));
|
|
26486
26813
|
return {
|
|
26487
26814
|
name,
|
|
26488
26815
|
mtime: stat.mtimeMs,
|
|
@@ -26491,7 +26818,7 @@ function collectHistorianDumps() {
|
|
|
26491
26818
|
}).sort((a, b) => b.mtime - a.mtime);
|
|
26492
26819
|
const now = Date.now();
|
|
26493
26820
|
const recent = entries.slice(0, 5).map((entry) => {
|
|
26494
|
-
const meta3 = parseHistorianDumpMeta(
|
|
26821
|
+
const meta3 = parseHistorianDumpMeta(join12(dir, entry.name));
|
|
26495
26822
|
const summary = {
|
|
26496
26823
|
name: entry.name,
|
|
26497
26824
|
ageMinutes: Math.round((now - entry.mtime) / 60000),
|
|
@@ -26510,8 +26837,8 @@ function collectHistorianDumps() {
|
|
|
26510
26837
|
}
|
|
26511
26838
|
}
|
|
26512
26839
|
async function collectHistorianFailures(storageDirPath) {
|
|
26513
|
-
const contextDbPath =
|
|
26514
|
-
if (!
|
|
26840
|
+
const contextDbPath = join12(storageDirPath, "context.db");
|
|
26841
|
+
if (!existsSync14(contextDbPath))
|
|
26515
26842
|
return [];
|
|
26516
26843
|
if (typeof globalThis.Bun === "undefined") {
|
|
26517
26844
|
return [];
|
|
@@ -26550,9 +26877,9 @@ async function collectDiagnostics() {
|
|
|
26550
26877
|
const tuiConfig = readConfig2(configPaths.tuiConfig);
|
|
26551
26878
|
const magicContextConfig = readConfig2(configPaths.magicContextConfig);
|
|
26552
26879
|
const storageDirPath = getStorageDir();
|
|
26553
|
-
const contextDbPath =
|
|
26554
|
-
const logPath =
|
|
26555
|
-
const logFileSize =
|
|
26880
|
+
const contextDbPath = join12(storageDirPath, "context.db");
|
|
26881
|
+
const logPath = join12(tmpdir3(), "magic-context.log");
|
|
26882
|
+
const logFileSize = existsSync14(logPath) ? statSync2(logPath).size : 0;
|
|
26556
26883
|
const conflictResult = detectConflicts(process.cwd());
|
|
26557
26884
|
return {
|
|
26558
26885
|
timestamp: new Date().toISOString(),
|
|
@@ -26566,14 +26893,14 @@ async function collectDiagnostics() {
|
|
|
26566
26893
|
opencodeConfigHasPlugin: configHasPluginEntry(opencodeConfig.value),
|
|
26567
26894
|
tuiConfigHasPlugin: configHasPluginEntry(tuiConfig.value),
|
|
26568
26895
|
magicContextConfig: {
|
|
26569
|
-
exists:
|
|
26896
|
+
exists: existsSync14(configPaths.magicContextConfig),
|
|
26570
26897
|
...magicContextConfig.error ? { parseError: magicContextConfig.error } : {},
|
|
26571
26898
|
flags: sanitizeValue(magicContextConfig.value ?? {}) ?? {}
|
|
26572
26899
|
},
|
|
26573
26900
|
pluginCache: getPluginCacheInfo(),
|
|
26574
26901
|
storageDir: {
|
|
26575
26902
|
path: storageDirPath,
|
|
26576
|
-
exists:
|
|
26903
|
+
exists: existsSync14(storageDirPath),
|
|
26577
26904
|
contextDbSizeBytes: fileSize(contextDbPath)
|
|
26578
26905
|
},
|
|
26579
26906
|
conflicts: {
|
|
@@ -26582,7 +26909,7 @@ async function collectDiagnostics() {
|
|
|
26582
26909
|
},
|
|
26583
26910
|
logFile: {
|
|
26584
26911
|
path: logPath,
|
|
26585
|
-
exists:
|
|
26912
|
+
exists: existsSync14(logPath),
|
|
26586
26913
|
sizeKb: Math.round(logFileSize / 1024)
|
|
26587
26914
|
},
|
|
26588
26915
|
historianDumps: collectHistorianDumps(),
|
|
@@ -26683,9 +27010,9 @@ var init_diagnostics_opencode = __esm(() => {
|
|
|
26683
27010
|
});
|
|
26684
27011
|
|
|
26685
27012
|
// src/lib/logs-opencode.ts
|
|
26686
|
-
import { readFileSync as readFileSync10, writeFileSync as
|
|
27013
|
+
import { readFileSync as readFileSync10, writeFileSync as writeFileSync9 } from "node:fs";
|
|
26687
27014
|
import { homedir as homedir9, userInfo as userInfo2 } from "node:os";
|
|
26688
|
-
import { join as
|
|
27015
|
+
import { join as join13 } from "node:path";
|
|
26689
27016
|
function escapeRegex3(value) {
|
|
26690
27017
|
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
26691
27018
|
}
|
|
@@ -26776,10 +27103,10 @@ async function bundleIssueReport(report, description, _title) {
|
|
|
26776
27103
|
"```"
|
|
26777
27104
|
].join(`
|
|
26778
27105
|
`);
|
|
26779
|
-
const
|
|
26780
|
-
|
|
27106
|
+
const path4 = join13(process.cwd(), `magic-context-issue-${formatTimestamp(new Date)}.md`);
|
|
27107
|
+
writeFileSync9(path4, `${bodyMarkdown}
|
|
26781
27108
|
`);
|
|
26782
|
-
return { path:
|
|
27109
|
+
return { path: path4, bodyMarkdown };
|
|
26783
27110
|
}
|
|
26784
27111
|
var SECRET_PATTERNS, HISTORIAN_LOG_PATTERNS;
|
|
26785
27112
|
var init_logs_opencode = __esm(() => {
|
|
@@ -26864,10 +27191,10 @@ var init_logs_opencode = __esm(() => {
|
|
|
26864
27191
|
|
|
26865
27192
|
// src/commands/doctor-opencode.ts
|
|
26866
27193
|
import { execSync as execSync3, spawnSync as spawnSync2 } from "node:child_process";
|
|
26867
|
-
import { existsSync as
|
|
26868
|
-
import { createRequire as
|
|
27194
|
+
import { existsSync as existsSync15, readdirSync as readdirSync3, readFileSync as readFileSync11, rmSync, statSync as statSync3, writeFileSync as writeFileSync10 } from "node:fs";
|
|
27195
|
+
import { createRequire as createRequire4 } from "node:module";
|
|
26869
27196
|
import { homedir as homedir10, tmpdir as tmpdir4 } from "node:os";
|
|
26870
|
-
import { join as
|
|
27197
|
+
import { join as join14 } from "node:path";
|
|
26871
27198
|
async function fetchNpmLatest(pkg, timeoutMs = 5000) {
|
|
26872
27199
|
try {
|
|
26873
27200
|
const controller = new AbortController;
|
|
@@ -26889,7 +27216,7 @@ async function fetchNpmLatest(pkg, timeoutMs = 5000) {
|
|
|
26889
27216
|
}
|
|
26890
27217
|
}
|
|
26891
27218
|
function getSelfVersion2() {
|
|
26892
|
-
const req =
|
|
27219
|
+
const req = createRequire4(import.meta.url);
|
|
26893
27220
|
for (const relPath of ["../../package.json", "../package.json"]) {
|
|
26894
27221
|
try {
|
|
26895
27222
|
const pkg = req(relPath);
|
|
@@ -26917,21 +27244,21 @@ function compareVersions(a, b) {
|
|
|
26917
27244
|
}
|
|
26918
27245
|
async function clearPluginCache(force = false) {
|
|
26919
27246
|
const cacheDir = getOpenCodeCacheDir();
|
|
26920
|
-
const pluginCacheDir =
|
|
26921
|
-
if (!
|
|
27247
|
+
const pluginCacheDir = join14(cacheDir, "packages", PLUGIN_ENTRY_WITH_VERSION2);
|
|
27248
|
+
if (!existsSync15(pluginCacheDir)) {
|
|
26922
27249
|
return { action: "not_found", path: pluginCacheDir };
|
|
26923
27250
|
}
|
|
26924
27251
|
let cachedVersion;
|
|
26925
27252
|
try {
|
|
26926
|
-
const installedPkgPath =
|
|
26927
|
-
if (
|
|
27253
|
+
const installedPkgPath = join14(pluginCacheDir, "node_modules", "@cortexkit", "opencode-magic-context", "package.json");
|
|
27254
|
+
if (existsSync15(installedPkgPath)) {
|
|
26928
27255
|
const pkg = JSON.parse(readFileSync11(installedPkgPath, "utf-8"));
|
|
26929
27256
|
if (typeof pkg?.version === "string") {
|
|
26930
27257
|
cachedVersion = pkg.version;
|
|
26931
27258
|
}
|
|
26932
27259
|
}
|
|
26933
27260
|
} catch {}
|
|
26934
|
-
const require2 =
|
|
27261
|
+
const require2 = createRequire4(import.meta.url);
|
|
26935
27262
|
let selfVersion;
|
|
26936
27263
|
for (const relPath of ["../../package.json", "../package.json"]) {
|
|
26937
27264
|
try {
|
|
@@ -27037,7 +27364,7 @@ async function runIssueFlow() {
|
|
|
27037
27364
|
}
|
|
27038
27365
|
}
|
|
27039
27366
|
async function checkEmbeddingConfig(magicContextConfigPath) {
|
|
27040
|
-
if (!
|
|
27367
|
+
if (!existsSync15(magicContextConfigPath)) {
|
|
27041
27368
|
return { issues: 0 };
|
|
27042
27369
|
}
|
|
27043
27370
|
let rawText;
|
|
@@ -27190,7 +27517,7 @@ async function runDoctor(options = {}) {
|
|
|
27190
27517
|
} else {
|
|
27191
27518
|
pass(`OpenCode config: ${paths.opencodeConfig}`);
|
|
27192
27519
|
}
|
|
27193
|
-
if (
|
|
27520
|
+
if (existsSync15(paths.magicContextConfig)) {
|
|
27194
27521
|
pass(`Magic Context config: ${paths.magicContextConfig}`);
|
|
27195
27522
|
try {
|
|
27196
27523
|
const raw = readFileSync11(paths.magicContextConfig, "utf-8");
|
|
@@ -27218,7 +27545,7 @@ async function runDoctor(options = {}) {
|
|
|
27218
27545
|
warn(`No magic-context.jsonc found — using defaults`);
|
|
27219
27546
|
log.info(" Run 'setup' to create one with model recommendations");
|
|
27220
27547
|
}
|
|
27221
|
-
if (
|
|
27548
|
+
if (existsSync15(paths.magicContextConfig)) {
|
|
27222
27549
|
try {
|
|
27223
27550
|
const mcRaw = readFileSync11(paths.magicContextConfig, "utf-8");
|
|
27224
27551
|
const mcConfig = import_comment_json7.parse(mcRaw);
|
|
@@ -27296,7 +27623,7 @@ async function runDoctor(options = {}) {
|
|
|
27296
27623
|
fixed++;
|
|
27297
27624
|
}
|
|
27298
27625
|
if (mcChanged) {
|
|
27299
|
-
|
|
27626
|
+
writeFileSync10(paths.magicContextConfig, `${import_comment_json7.stringify(mcConfig, null, 2)}
|
|
27300
27627
|
`);
|
|
27301
27628
|
}
|
|
27302
27629
|
} catch {
|
|
@@ -27307,34 +27634,46 @@ async function runDoctor(options = {}) {
|
|
|
27307
27634
|
try {
|
|
27308
27635
|
const raw = readFileSync11(paths.opencodeConfig, "utf-8");
|
|
27309
27636
|
const config2 = import_comment_json7.parse(raw);
|
|
27310
|
-
const
|
|
27311
|
-
const
|
|
27312
|
-
const isDevPathEntry = (p) => p.startsWith("file://") || p.startsWith("/") || p.startsWith("./");
|
|
27313
|
-
const existingIdx = pluginList.findIndex((p) => p === PLUGIN_NAME6 || p.startsWith(`${PLUGIN_NAME6}@`) || isDevPathEntry(p) && p.includes("opencode-magic-context"));
|
|
27637
|
+
const rawPlugins = Array.isArray(config2?.plugin) ? config2.plugin : [];
|
|
27638
|
+
const existingIdx = rawPlugins.findIndex((entry) => matchesPluginEntry(entry, PLUGIN_NAME6) || isDevPathPluginEntry(entry));
|
|
27314
27639
|
const configName = paths.opencodeConfigFormat === "jsonc" ? "opencode.jsonc" : "opencode.json";
|
|
27315
|
-
|
|
27640
|
+
const entryAsString = (entry) => {
|
|
27641
|
+
if (typeof entry === "string")
|
|
27642
|
+
return entry;
|
|
27643
|
+
if (Array.isArray(entry) && typeof entry[0] === "string")
|
|
27644
|
+
return entry[0];
|
|
27645
|
+
return null;
|
|
27646
|
+
};
|
|
27647
|
+
if (existingIdx >= 0 && rawPlugins[existingIdx] === PLUGIN_ENTRY_WITH_VERSION2) {
|
|
27316
27648
|
pass(`Plugin registered in ${configName}`);
|
|
27317
27649
|
} else if (existingIdx >= 0) {
|
|
27318
|
-
const oldEntry =
|
|
27319
|
-
|
|
27320
|
-
|
|
27650
|
+
const oldEntry = rawPlugins[existingIdx];
|
|
27651
|
+
const oldEntryStr = entryAsString(oldEntry) ?? "";
|
|
27652
|
+
if (isDevPathPluginEntry(oldEntry)) {
|
|
27653
|
+
pass(`Plugin registered in ${configName} (dev path: ${oldEntryStr})`);
|
|
27321
27654
|
} else {
|
|
27322
|
-
const isPinned =
|
|
27655
|
+
const isPinned = oldEntryStr !== PLUGIN_NAME6 && oldEntryStr !== PLUGIN_ENTRY_WITH_VERSION2 && /^@cortexkit\/opencode-magic-context@\d/.test(oldEntryStr);
|
|
27323
27656
|
if (isPinned && !options.force) {
|
|
27324
|
-
warn(`Plugin pinned to ${
|
|
27657
|
+
warn(`Plugin pinned to ${oldEntryStr} in ${configName} — use 'doctor --force' to upgrade`);
|
|
27325
27658
|
} else {
|
|
27326
|
-
|
|
27327
|
-
|
|
27328
|
-
|
|
27659
|
+
if (Array.isArray(oldEntry) && oldEntry.length >= 1) {
|
|
27660
|
+
const replacement = [...oldEntry];
|
|
27661
|
+
replacement[0] = PLUGIN_ENTRY_WITH_VERSION2;
|
|
27662
|
+
rawPlugins[existingIdx] = replacement;
|
|
27663
|
+
} else {
|
|
27664
|
+
rawPlugins[existingIdx] = PLUGIN_ENTRY_WITH_VERSION2;
|
|
27665
|
+
}
|
|
27666
|
+
config2.plugin = rawPlugins;
|
|
27667
|
+
writeFileSync10(paths.opencodeConfig, `${import_comment_json7.stringify(config2, null, 2)}
|
|
27329
27668
|
`);
|
|
27330
|
-
pass(`Upgraded plugin entry in ${configName}: ${
|
|
27669
|
+
pass(`Upgraded plugin entry in ${configName}: ${oldEntryStr} → ${PLUGIN_ENTRY_WITH_VERSION2}`);
|
|
27331
27670
|
fixed++;
|
|
27332
27671
|
}
|
|
27333
27672
|
}
|
|
27334
27673
|
} else {
|
|
27335
|
-
|
|
27336
|
-
config2.plugin =
|
|
27337
|
-
|
|
27674
|
+
rawPlugins.push(PLUGIN_ENTRY_WITH_VERSION2);
|
|
27675
|
+
config2.plugin = rawPlugins;
|
|
27676
|
+
writeFileSync10(paths.opencodeConfig, `${import_comment_json7.stringify(config2, null, 2)}
|
|
27338
27677
|
`);
|
|
27339
27678
|
pass(`Added plugin to ${configName}`);
|
|
27340
27679
|
fixed++;
|
|
@@ -27365,26 +27704,44 @@ async function runDoctor(options = {}) {
|
|
|
27365
27704
|
pass("Added TUI sidebar plugin to tui.json");
|
|
27366
27705
|
warn("Restart OpenCode to see the sidebar");
|
|
27367
27706
|
fixed++;
|
|
27368
|
-
} else if (
|
|
27707
|
+
} else if (existsSync15(paths.tuiConfig)) {
|
|
27369
27708
|
try {
|
|
27370
27709
|
const tuiRaw = readFileSync11(paths.tuiConfig, "utf-8");
|
|
27371
27710
|
const tuiConfig = import_comment_json7.parse(tuiRaw);
|
|
27372
|
-
const
|
|
27373
|
-
const tuiIdx =
|
|
27711
|
+
const tuiRawPlugins = Array.isArray(tuiConfig?.plugin) ? tuiConfig.plugin : [];
|
|
27712
|
+
const tuiIdx = tuiRawPlugins.findIndex((entry) => matchesPluginEntry(entry, PLUGIN_NAME6) || isDevPathPluginEntry(entry));
|
|
27713
|
+
const tuiEntryAsString = (entry) => {
|
|
27714
|
+
if (typeof entry === "string")
|
|
27715
|
+
return entry;
|
|
27716
|
+
if (Array.isArray(entry) && typeof entry[0] === "string")
|
|
27717
|
+
return entry[0];
|
|
27718
|
+
return "";
|
|
27719
|
+
};
|
|
27374
27720
|
if (tuiIdx >= 0) {
|
|
27375
|
-
const tuiEntry =
|
|
27376
|
-
const
|
|
27377
|
-
if (
|
|
27378
|
-
|
|
27379
|
-
} else if (tuiPinned && options.force) {
|
|
27380
|
-
tuiPlugins[tuiIdx] = PLUGIN_ENTRY_WITH_VERSION2;
|
|
27381
|
-
tuiConfig.plugin = tuiPlugins;
|
|
27382
|
-
writeFileSync9(paths.tuiConfig, `${import_comment_json7.stringify(tuiConfig, null, 2)}
|
|
27383
|
-
`);
|
|
27384
|
-
pass(`Upgraded TUI plugin: ${tuiEntry} → ${PLUGIN_ENTRY_WITH_VERSION2}`);
|
|
27385
|
-
fixed++;
|
|
27721
|
+
const tuiEntry = tuiRawPlugins[tuiIdx];
|
|
27722
|
+
const tuiEntryStr = tuiEntryAsString(tuiEntry);
|
|
27723
|
+
if (isDevPathPluginEntry(tuiEntry)) {
|
|
27724
|
+
pass(`TUI sidebar plugin configured (dev path: ${tuiEntryStr})`);
|
|
27386
27725
|
} else {
|
|
27387
|
-
|
|
27726
|
+
const tuiPinned = tuiEntryStr !== PLUGIN_NAME6 && tuiEntryStr !== PLUGIN_ENTRY_WITH_VERSION2 && /^@cortexkit\/opencode-magic-context@\d/.test(tuiEntryStr);
|
|
27727
|
+
if (tuiPinned && !options.force) {
|
|
27728
|
+
warn(`TUI plugin pinned to ${tuiEntryStr} — use 'doctor --force' to upgrade`);
|
|
27729
|
+
} else if (tuiPinned && options.force) {
|
|
27730
|
+
if (Array.isArray(tuiEntry) && tuiEntry.length >= 1) {
|
|
27731
|
+
const replacement = [...tuiEntry];
|
|
27732
|
+
replacement[0] = PLUGIN_ENTRY_WITH_VERSION2;
|
|
27733
|
+
tuiRawPlugins[tuiIdx] = replacement;
|
|
27734
|
+
} else {
|
|
27735
|
+
tuiRawPlugins[tuiIdx] = PLUGIN_ENTRY_WITH_VERSION2;
|
|
27736
|
+
}
|
|
27737
|
+
tuiConfig.plugin = tuiRawPlugins;
|
|
27738
|
+
writeFileSync10(paths.tuiConfig, `${import_comment_json7.stringify(tuiConfig, null, 2)}
|
|
27739
|
+
`);
|
|
27740
|
+
pass(`Upgraded TUI plugin: ${tuiEntryStr} → ${PLUGIN_ENTRY_WITH_VERSION2}`);
|
|
27741
|
+
fixed++;
|
|
27742
|
+
} else {
|
|
27743
|
+
pass("TUI sidebar plugin configured");
|
|
27744
|
+
}
|
|
27388
27745
|
}
|
|
27389
27746
|
} else {
|
|
27390
27747
|
pass("TUI sidebar plugin configured");
|
|
@@ -27395,7 +27752,7 @@ async function runDoctor(options = {}) {
|
|
|
27395
27752
|
} else {
|
|
27396
27753
|
pass("TUI sidebar plugin configured (tui.json created)");
|
|
27397
27754
|
}
|
|
27398
|
-
if (
|
|
27755
|
+
if (existsSync15(paths.magicContextConfig)) {
|
|
27399
27756
|
try {
|
|
27400
27757
|
const mcRaw = readFileSync11(paths.magicContextConfig, "utf-8");
|
|
27401
27758
|
const mcConfig = import_comment_json7.parse(mcRaw);
|
|
@@ -27415,8 +27772,8 @@ async function runDoctor(options = {}) {
|
|
|
27415
27772
|
failCount += embeddingCheck.issues;
|
|
27416
27773
|
else
|
|
27417
27774
|
passCount++;
|
|
27418
|
-
const dbPath =
|
|
27419
|
-
if (!
|
|
27775
|
+
const dbPath = join14(getMagicContextStorageDir(), "context.db");
|
|
27776
|
+
if (!existsSync15(dbPath)) {
|
|
27420
27777
|
log.info(`Shared context DB not yet created at ${dbPath} (will be created on first run)`);
|
|
27421
27778
|
} else {
|
|
27422
27779
|
pass(`Shared context DB exists at ${dbPath}`);
|
|
@@ -27477,8 +27834,8 @@ async function runDoctor(options = {}) {
|
|
|
27477
27834
|
}
|
|
27478
27835
|
{
|
|
27479
27836
|
const ageWarnings = [];
|
|
27480
|
-
const npmrcPath =
|
|
27481
|
-
if (
|
|
27837
|
+
const npmrcPath = join14(homedir10(), ".npmrc");
|
|
27838
|
+
if (existsSync15(npmrcPath)) {
|
|
27482
27839
|
try {
|
|
27483
27840
|
const npmrc = readFileSync11(npmrcPath, "utf-8");
|
|
27484
27841
|
for (const line of npmrc.split(`
|
|
@@ -27493,23 +27850,8 @@ async function runDoctor(options = {}) {
|
|
|
27493
27850
|
}
|
|
27494
27851
|
} catch {}
|
|
27495
27852
|
}
|
|
27496
|
-
const bunfigPath = join13(homedir10(), ".bunfig.toml");
|
|
27497
|
-
if (existsSync14(bunfigPath)) {
|
|
27498
|
-
try {
|
|
27499
|
-
const bunfig = readFileSync11(bunfigPath, "utf-8");
|
|
27500
|
-
for (const line of bunfig.split(`
|
|
27501
|
-
`)) {
|
|
27502
|
-
const trimmed = line.trim();
|
|
27503
|
-
if (trimmed.startsWith("#"))
|
|
27504
|
-
continue;
|
|
27505
|
-
if (/minimumReleaseAge\s*=/.test(trimmed)) {
|
|
27506
|
-
ageWarnings.push(`~/.bunfig.toml has '${trimmed}'`);
|
|
27507
|
-
}
|
|
27508
|
-
}
|
|
27509
|
-
} catch {}
|
|
27510
|
-
}
|
|
27511
27853
|
if (ageWarnings.length > 0) {
|
|
27512
|
-
log.warn("
|
|
27854
|
+
log.warn("npm min-release-age restriction detected — this can prevent OpenCode from installing the latest plugin version");
|
|
27513
27855
|
for (const w of ageWarnings) {
|
|
27514
27856
|
log.info(` ${w}`);
|
|
27515
27857
|
}
|
|
@@ -27518,20 +27860,20 @@ async function runDoctor(options = {}) {
|
|
|
27518
27860
|
issues++;
|
|
27519
27861
|
}
|
|
27520
27862
|
}
|
|
27521
|
-
const logPath =
|
|
27522
|
-
if (
|
|
27863
|
+
const logPath = join14(tmpdir4(), "magic-context.log");
|
|
27864
|
+
if (existsSync15(logPath)) {
|
|
27523
27865
|
const logStat = statSync3(logPath);
|
|
27524
27866
|
const sizeKb = (logStat.size / 1024).toFixed(0);
|
|
27525
27867
|
log.info(`Log file: ${logPath} (${sizeKb} KB)`);
|
|
27526
27868
|
} else {
|
|
27527
27869
|
log.info(`Log file: ${logPath} (not yet created)`);
|
|
27528
27870
|
}
|
|
27529
|
-
const historianDumpDir =
|
|
27530
|
-
if (
|
|
27871
|
+
const historianDumpDir = join14(tmpdir4(), "magic-context-historian");
|
|
27872
|
+
if (existsSync15(historianDumpDir)) {
|
|
27531
27873
|
try {
|
|
27532
27874
|
const dumps = readdirSync3(historianDumpDir).filter((f) => f.endsWith(".xml")).map((f) => ({
|
|
27533
27875
|
name: f,
|
|
27534
|
-
mtime: statSync3(
|
|
27876
|
+
mtime: statSync3(join14(historianDumpDir, f)).mtimeMs
|
|
27535
27877
|
})).sort((a, b) => b.mtime - a.mtime);
|
|
27536
27878
|
if (dumps.length > 0) {
|
|
27537
27879
|
warn(`Historian debug dumps: ${dumps.length} file(s) in ${historianDumpDir}`);
|
|
@@ -27571,6 +27913,7 @@ var init_doctor_opencode = __esm(async () => {
|
|
|
27571
27913
|
init_conflict_fixer();
|
|
27572
27914
|
init_data_path();
|
|
27573
27915
|
init_tui_config();
|
|
27916
|
+
init_opencode();
|
|
27574
27917
|
init_diagnostics_opencode();
|
|
27575
27918
|
init_logs_opencode();
|
|
27576
27919
|
init_opencode_helpers();
|
|
@@ -27967,7 +28310,7 @@ var Tokenizer = class {
|
|
|
27967
28310
|
return this.encode(input).length;
|
|
27968
28311
|
}
|
|
27969
28312
|
}, NO_RANK = 4294967295, textEncoder, textDecoder, src_default;
|
|
27970
|
-
var
|
|
28313
|
+
var init_dist4 = __esm(() => {
|
|
27971
28314
|
textEncoder = new TextEncoder;
|
|
27972
28315
|
textDecoder = new TextDecoder("utf-8");
|
|
27973
28316
|
src_default = Tokenizer;
|
|
@@ -160061,7 +160404,7 @@ var init_claude = __esm(() => {
|
|
|
160061
160404
|
// ../plugin/src/hooks/magic-context/read-session-formatting.ts
|
|
160062
160405
|
var tokenizer;
|
|
160063
160406
|
var init_read_session_formatting = __esm(() => {
|
|
160064
|
-
|
|
160407
|
+
init_dist4();
|
|
160065
160408
|
init_claude();
|
|
160066
160409
|
tokenizer = new src_default(exports_claude);
|
|
160067
160410
|
});
|
|
@@ -160350,25 +160693,25 @@ var init_migrations = __esm(async () => {
|
|
|
160350
160693
|
});
|
|
160351
160694
|
|
|
160352
160695
|
// ../plugin/src/features/magic-context/storage-db.ts
|
|
160353
|
-
import { copyFileSync, cpSync, existsSync as
|
|
160354
|
-
import { join as
|
|
160696
|
+
import { copyFileSync, cpSync, existsSync as existsSync16, mkdirSync as mkdirSync7 } from "node:fs";
|
|
160697
|
+
import { join as join15 } from "node:path";
|
|
160355
160698
|
function resolveDatabasePath() {
|
|
160356
160699
|
const dbDir = getMagicContextStorageDir();
|
|
160357
|
-
return { dbDir, dbPath:
|
|
160700
|
+
return { dbDir, dbPath: join15(dbDir, "context.db") };
|
|
160358
160701
|
}
|
|
160359
160702
|
function migrateLegacyStorageIfNeeded(targetDbPath, targetDbDir) {
|
|
160360
|
-
if (
|
|
160703
|
+
if (existsSync16(targetDbPath))
|
|
160361
160704
|
return;
|
|
160362
160705
|
const legacyDir = getLegacyOpenCodeMagicContextStorageDir();
|
|
160363
|
-
const legacyDbPath =
|
|
160364
|
-
if (!
|
|
160706
|
+
const legacyDbPath = join15(legacyDir, "context.db");
|
|
160707
|
+
if (!existsSync16(legacyDbPath))
|
|
160365
160708
|
return;
|
|
160366
160709
|
log2(`[magic-context] migrating legacy plugin storage: ${legacyDir} -> ${targetDbDir} (legacy left in place as backup)`);
|
|
160367
|
-
|
|
160710
|
+
mkdirSync7(targetDbDir, { recursive: true });
|
|
160368
160711
|
for (const suffix of ["", "-wal", "-shm"]) {
|
|
160369
160712
|
const src = `${legacyDbPath}${suffix}`;
|
|
160370
|
-
const dst =
|
|
160371
|
-
if (
|
|
160713
|
+
const dst = join15(targetDbDir, `context.db${suffix}`);
|
|
160714
|
+
if (existsSync16(src)) {
|
|
160372
160715
|
try {
|
|
160373
160716
|
copyFileSync(src, dst);
|
|
160374
160717
|
} catch (error48) {
|
|
@@ -160376,9 +160719,9 @@ function migrateLegacyStorageIfNeeded(targetDbPath, targetDbDir) {
|
|
|
160376
160719
|
}
|
|
160377
160720
|
}
|
|
160378
160721
|
}
|
|
160379
|
-
const legacyModelsDir =
|
|
160380
|
-
const targetModelsDir =
|
|
160381
|
-
if (
|
|
160722
|
+
const legacyModelsDir = join15(legacyDir, "models");
|
|
160723
|
+
const targetModelsDir = join15(targetDbDir, "models");
|
|
160724
|
+
if (existsSync16(legacyModelsDir) && !existsSync16(targetModelsDir)) {
|
|
160382
160725
|
try {
|
|
160383
160726
|
cpSync(legacyModelsDir, targetModelsDir, { recursive: true });
|
|
160384
160727
|
} catch (error48) {
|
|
@@ -160758,7 +161101,7 @@ function openDatabase() {
|
|
|
160758
161101
|
}
|
|
160759
161102
|
try {
|
|
160760
161103
|
migrateLegacyStorageIfNeeded(dbPath, dbDir);
|
|
160761
|
-
|
|
161104
|
+
mkdirSync7(dbDir, { recursive: true });
|
|
160762
161105
|
const db = new Database(dbPath);
|
|
160763
161106
|
initializeDatabase(db);
|
|
160764
161107
|
runMigrations(db);
|
|
@@ -160884,42 +161227,42 @@ var init_storage = __esm(async () => {
|
|
|
160884
161227
|
});
|
|
160885
161228
|
|
|
160886
161229
|
// ../pi-plugin/src/config/index.ts
|
|
160887
|
-
import { existsSync as
|
|
161230
|
+
import { existsSync as existsSync17, readFileSync as readFileSync12 } from "node:fs";
|
|
160888
161231
|
import { homedir as homedir11 } from "node:os";
|
|
160889
|
-
import { join as
|
|
161232
|
+
import { join as join16 } from "node:path";
|
|
160890
161233
|
function getProjectConfigPaths(cwd) {
|
|
160891
|
-
const basePath =
|
|
161234
|
+
const basePath = join16(cwd, ".pi", CONFIG_FILE_NAME);
|
|
160892
161235
|
return [`${basePath}.jsonc`, `${basePath}.json`];
|
|
160893
161236
|
}
|
|
160894
161237
|
function getUserConfigPaths() {
|
|
160895
161238
|
const home = process.env.HOME ?? homedir11();
|
|
160896
|
-
const basePath =
|
|
161239
|
+
const basePath = join16(home, ".pi", "agent", CONFIG_FILE_NAME);
|
|
160897
161240
|
return [`${basePath}.jsonc`, `${basePath}.json`];
|
|
160898
161241
|
}
|
|
160899
161242
|
function resolveFirstExisting(paths) {
|
|
160900
|
-
return paths.find((
|
|
161243
|
+
return paths.find((path4) => existsSync17(path4));
|
|
160901
161244
|
}
|
|
160902
|
-
function loadConfigFile2(
|
|
161245
|
+
function loadConfigFile2(path4, scope) {
|
|
160903
161246
|
try {
|
|
160904
|
-
const rawText = readFileSync12(
|
|
161247
|
+
const rawText = readFileSync12(path4, "utf-8");
|
|
160905
161248
|
const substituted = substituteConfigVariables({
|
|
160906
161249
|
text: rawText,
|
|
160907
|
-
configPath:
|
|
161250
|
+
configPath: path4
|
|
160908
161251
|
});
|
|
160909
161252
|
return {
|
|
160910
|
-
path:
|
|
161253
|
+
path: path4,
|
|
160911
161254
|
scope,
|
|
160912
161255
|
config: import_comment_json8.parse(substituted.text),
|
|
160913
|
-
warnings: substituted.warnings.map((warning) => `${
|
|
161256
|
+
warnings: substituted.warnings.map((warning) => `${path4}: ${warning}`)
|
|
160914
161257
|
};
|
|
160915
161258
|
} catch (error48) {
|
|
160916
161259
|
const message = error48 instanceof Error ? error48.message : String(error48);
|
|
160917
161260
|
return {
|
|
160918
|
-
path:
|
|
161261
|
+
path: path4,
|
|
160919
161262
|
scope,
|
|
160920
161263
|
config: {},
|
|
160921
161264
|
warnings: [
|
|
160922
|
-
`${
|
|
161265
|
+
`${path4}: failed to load config: ${message}; using defaults for this file.`
|
|
160923
161266
|
]
|
|
160924
161267
|
};
|
|
160925
161268
|
}
|
|
@@ -161031,12 +161374,12 @@ var init_config2 = __esm(() => {
|
|
|
161031
161374
|
|
|
161032
161375
|
// src/lib/diagnostics-pi.ts
|
|
161033
161376
|
import { createHash } from "node:crypto";
|
|
161034
|
-
import { existsSync as
|
|
161035
|
-
import { createRequire as
|
|
161377
|
+
import { existsSync as existsSync18, readFileSync as readFileSync13, statSync as statSync4 } from "node:fs";
|
|
161378
|
+
import { createRequire as createRequire5 } from "node:module";
|
|
161036
161379
|
import { homedir as homedir12, tmpdir as tmpdir5, userInfo as userInfo3 } from "node:os";
|
|
161037
|
-
import { join as
|
|
161380
|
+
import { join as join17 } from "node:path";
|
|
161038
161381
|
function getSelfVersion3() {
|
|
161039
|
-
const req =
|
|
161382
|
+
const req = createRequire5(import.meta.url);
|
|
161040
161383
|
for (const relPath of ["../../package.json", "../package.json"]) {
|
|
161041
161384
|
try {
|
|
161042
161385
|
const pkg = req(relPath);
|
|
@@ -161047,9 +161390,9 @@ function getSelfVersion3() {
|
|
|
161047
161390
|
}
|
|
161048
161391
|
return "unknown";
|
|
161049
161392
|
}
|
|
161050
|
-
function fileSize2(
|
|
161393
|
+
function fileSize2(path4) {
|
|
161051
161394
|
try {
|
|
161052
|
-
return
|
|
161395
|
+
return existsSync18(path4) ? statSync4(path4).size : 0;
|
|
161053
161396
|
} catch {
|
|
161054
161397
|
return 0;
|
|
161055
161398
|
}
|
|
@@ -161098,12 +161441,12 @@ function sanitizeValue2(value, key = "") {
|
|
|
161098
161441
|
}
|
|
161099
161442
|
return value;
|
|
161100
161443
|
}
|
|
161101
|
-
function readJsonc3(
|
|
161102
|
-
if (!
|
|
161444
|
+
function readJsonc3(path4) {
|
|
161445
|
+
if (!existsSync18(path4))
|
|
161103
161446
|
return { value: {} };
|
|
161104
161447
|
try {
|
|
161105
161448
|
return {
|
|
161106
|
-
value: import_comment_json9.parse(readFileSync13(
|
|
161449
|
+
value: import_comment_json9.parse(readFileSync13(path4, "utf-8"))
|
|
161107
161450
|
};
|
|
161108
161451
|
} catch (error48) {
|
|
161109
161452
|
return {
|
|
@@ -161113,13 +161456,13 @@ function readJsonc3(path3) {
|
|
|
161113
161456
|
}
|
|
161114
161457
|
}
|
|
161115
161458
|
function getProjectConfigPath(cwd) {
|
|
161116
|
-
return
|
|
161459
|
+
return join17(cwd, ".pi", "magic-context.jsonc");
|
|
161117
161460
|
}
|
|
161118
|
-
function readConfigDiagnostic(
|
|
161119
|
-
const parsed = readJsonc3(
|
|
161461
|
+
function readConfigDiagnostic(path4) {
|
|
161462
|
+
const parsed = readJsonc3(path4);
|
|
161120
161463
|
return {
|
|
161121
|
-
path:
|
|
161122
|
-
exists:
|
|
161464
|
+
path: path4,
|
|
161465
|
+
exists: existsSync18(path4),
|
|
161123
161466
|
...parsed.parseError ? { parseError: parsed.parseError } : {},
|
|
161124
161467
|
flags: sanitizeValue2(parsed.value)
|
|
161125
161468
|
};
|
|
@@ -161139,9 +161482,9 @@ async function collectDiagnostics2(cwd = process.cwd()) {
|
|
|
161139
161482
|
const projectConfigPath = getProjectConfigPath(cwd);
|
|
161140
161483
|
const loaded = loadPiConfig({ cwd });
|
|
161141
161484
|
const storageDirPath = getMagicContextStorageDir();
|
|
161142
|
-
const dbPath =
|
|
161143
|
-
const logPath =
|
|
161144
|
-
const logFileSize =
|
|
161485
|
+
const dbPath = join17(storageDirPath, "context.db");
|
|
161486
|
+
const logPath = join17(tmpdir5(), "magic-context.log");
|
|
161487
|
+
const logFileSize = existsSync18(logPath) ? statSync4(logPath).size : 0;
|
|
161145
161488
|
const otherPiExtensions = packages.filter((entry) => !hasMagicContextPackage([entry]));
|
|
161146
161489
|
return {
|
|
161147
161490
|
timestamp: new Date().toISOString(),
|
|
@@ -161154,7 +161497,7 @@ async function collectDiagnostics2(cwd = process.cwd()) {
|
|
|
161154
161497
|
piVersion: pi ? getPiVersion(pi.path) : null,
|
|
161155
161498
|
settings: {
|
|
161156
161499
|
path: settingsPath,
|
|
161157
|
-
exists:
|
|
161500
|
+
exists: existsSync18(settingsPath),
|
|
161158
161501
|
...settingsParsed.parseError ? { parseError: settingsParsed.parseError } : {},
|
|
161159
161502
|
hasMagicContextPackage: hasMagicContextPackage(packages),
|
|
161160
161503
|
packages: packages.map(sanitizeString2)
|
|
@@ -161170,7 +161513,7 @@ async function collectDiagnostics2(cwd = process.cwd()) {
|
|
|
161170
161513
|
loadWarnings: loaded.warnings.map(sanitizeString2),
|
|
161171
161514
|
storageDir: {
|
|
161172
161515
|
path: storageDirPath,
|
|
161173
|
-
exists:
|
|
161516
|
+
exists: existsSync18(storageDirPath),
|
|
161174
161517
|
contextDbSizeBytes: fileSize2(dbPath)
|
|
161175
161518
|
},
|
|
161176
161519
|
conflicts: {
|
|
@@ -161179,7 +161522,7 @@ async function collectDiagnostics2(cwd = process.cwd()) {
|
|
|
161179
161522
|
},
|
|
161180
161523
|
logFile: {
|
|
161181
161524
|
path: logPath,
|
|
161182
|
-
exists:
|
|
161525
|
+
exists: existsSync18(logPath),
|
|
161183
161526
|
sizeKb: Math.round(logFileSize / 1024)
|
|
161184
161527
|
}
|
|
161185
161528
|
};
|
|
@@ -161233,7 +161576,7 @@ function renderDiagnosticsMarkdown2(report) {
|
|
|
161233
161576
|
"```",
|
|
161234
161577
|
"",
|
|
161235
161578
|
"### Loaded config paths",
|
|
161236
|
-
report.loadedConfigPaths.length === 0 ? "_No config files loaded; defaults are in use._" : report.loadedConfigPaths.map((
|
|
161579
|
+
report.loadedConfigPaths.length === 0 ? "_No config files loaded; defaults are in use._" : report.loadedConfigPaths.map((path4) => `- ${path4}`).join(`
|
|
161237
161580
|
`),
|
|
161238
161581
|
"",
|
|
161239
161582
|
"### Config load warnings",
|
|
@@ -161268,8 +161611,8 @@ var init_diagnostics_pi = __esm(() => {
|
|
|
161268
161611
|
});
|
|
161269
161612
|
|
|
161270
161613
|
// src/lib/logs-pi.ts
|
|
161271
|
-
import { readFileSync as readFileSync14, writeFileSync as
|
|
161272
|
-
import { join as
|
|
161614
|
+
import { readFileSync as readFileSync14, writeFileSync as writeFileSync11 } from "node:fs";
|
|
161615
|
+
import { join as join18 } from "node:path";
|
|
161273
161616
|
function sanitizeLogContent2(content) {
|
|
161274
161617
|
return sanitizeString2(content);
|
|
161275
161618
|
}
|
|
@@ -161313,10 +161656,10 @@ async function bundleIssueReport2(report, description, title, options = {}) {
|
|
|
161313
161656
|
].join(`
|
|
161314
161657
|
`);
|
|
161315
161658
|
const cwd = options.cwd ?? process.cwd();
|
|
161316
|
-
const
|
|
161317
|
-
|
|
161659
|
+
const path4 = join18(cwd, `magic-context-pi-issue-${formatTimestamp2(options.now ?? new Date)}.md`);
|
|
161660
|
+
writeFileSync11(path4, `${bodyMarkdown}
|
|
161318
161661
|
`);
|
|
161319
|
-
return { path:
|
|
161662
|
+
return { path: path4, bodyMarkdown };
|
|
161320
161663
|
}
|
|
161321
161664
|
var init_logs_pi = __esm(() => {
|
|
161322
161665
|
init_diagnostics_pi();
|
|
@@ -161325,17 +161668,17 @@ var init_logs_pi = __esm(() => {
|
|
|
161325
161668
|
// src/commands/doctor-pi.ts
|
|
161326
161669
|
import { execFileSync as execFileSync3, spawnSync as spawnSync3 } from "node:child_process";
|
|
161327
161670
|
import {
|
|
161328
|
-
existsSync as
|
|
161329
|
-
mkdirSync as
|
|
161671
|
+
existsSync as existsSync19,
|
|
161672
|
+
mkdirSync as mkdirSync8,
|
|
161330
161673
|
readdirSync as readdirSync4,
|
|
161331
161674
|
readFileSync as readFileSync15,
|
|
161332
161675
|
rmSync as rmSync2,
|
|
161333
161676
|
statSync as statSync5,
|
|
161334
|
-
writeFileSync as
|
|
161677
|
+
writeFileSync as writeFileSync12
|
|
161335
161678
|
} from "node:fs";
|
|
161336
|
-
import { createRequire as
|
|
161679
|
+
import { createRequire as createRequire6 } from "node:module";
|
|
161337
161680
|
import { homedir as homedir13, tmpdir as tmpdir6 } from "node:os";
|
|
161338
|
-
import { dirname as
|
|
161681
|
+
import { dirname as dirname9, join as join19 } from "node:path";
|
|
161339
161682
|
function depsFrom(options) {
|
|
161340
161683
|
return {
|
|
161341
161684
|
...DEFAULT_DEPS,
|
|
@@ -161356,7 +161699,7 @@ function printDoctorHelp() {
|
|
|
161356
161699
|
console.log("");
|
|
161357
161700
|
}
|
|
161358
161701
|
function selfVersion() {
|
|
161359
|
-
const req =
|
|
161702
|
+
const req = createRequire6(import.meta.url);
|
|
161360
161703
|
for (const relPath of ["../../package.json", "../package.json"]) {
|
|
161361
161704
|
try {
|
|
161362
161705
|
const pkg = req(relPath);
|
|
@@ -161419,10 +161762,10 @@ function summarize(results) {
|
|
|
161419
161762
|
fail: results.filter((result) => result.status === "fail").length
|
|
161420
161763
|
};
|
|
161421
161764
|
}
|
|
161422
|
-
function readJsonc4(
|
|
161765
|
+
function readJsonc4(path4) {
|
|
161423
161766
|
try {
|
|
161424
161767
|
return {
|
|
161425
|
-
value: import_comment_json10.parse(readFileSync15(
|
|
161768
|
+
value: import_comment_json10.parse(readFileSync15(path4, "utf-8"))
|
|
161426
161769
|
};
|
|
161427
161770
|
} catch (error48) {
|
|
161428
161771
|
return {
|
|
@@ -161438,16 +161781,16 @@ function hasPiPackage(packages) {
|
|
|
161438
161781
|
return packages.some((entry) => entry === PI_PACKAGE_SOURCE || entry === PACKAGE_NAME2 || entry.includes("pi-magic-context"));
|
|
161439
161782
|
}
|
|
161440
161783
|
function projectConfigPath(cwd) {
|
|
161441
|
-
return
|
|
161784
|
+
return join19(cwd, ".pi", "magic-context.jsonc");
|
|
161442
161785
|
}
|
|
161443
|
-
function readConfigForEmbedding(
|
|
161444
|
-
if (!
|
|
161786
|
+
function readConfigForEmbedding(path4) {
|
|
161787
|
+
if (!existsSync19(path4))
|
|
161445
161788
|
return null;
|
|
161446
161789
|
try {
|
|
161447
|
-
const rawText = readFileSync15(
|
|
161790
|
+
const rawText = readFileSync15(path4, "utf-8");
|
|
161448
161791
|
const substituted = substituteConfigVariables({
|
|
161449
161792
|
text: rawText,
|
|
161450
|
-
configPath:
|
|
161793
|
+
configPath: path4
|
|
161451
161794
|
});
|
|
161452
161795
|
return import_comment_json10.parse(substituted.text);
|
|
161453
161796
|
} catch {
|
|
@@ -161503,51 +161846,51 @@ function countTable(db, table) {
|
|
|
161503
161846
|
}
|
|
161504
161847
|
function cacheRoots() {
|
|
161505
161848
|
const home = homedir13();
|
|
161506
|
-
const cacheHome = process.env.XDG_CACHE_HOME ||
|
|
161849
|
+
const cacheHome = process.env.XDG_CACHE_HOME || join19(home, ".cache");
|
|
161507
161850
|
return [
|
|
161508
|
-
|
|
161509
|
-
|
|
161510
|
-
|
|
161511
|
-
|
|
161512
|
-
|
|
161851
|
+
join19(home, ".pi", "cache", "extensions"),
|
|
161852
|
+
join19(home, ".pi", "cache", "packages"),
|
|
161853
|
+
join19(cacheHome, "pi", "extensions"),
|
|
161854
|
+
join19(cacheHome, "pi", "packages"),
|
|
161855
|
+
join19(getPiAgentConfigDir(), "cache", "extensions")
|
|
161513
161856
|
];
|
|
161514
161857
|
}
|
|
161515
161858
|
function findPiMagicContextCacheDirs(self, force = false) {
|
|
161516
161859
|
const found = new Map;
|
|
161517
|
-
const visit = (
|
|
161518
|
-
if (depth < 0 || !
|
|
161860
|
+
const visit = (path4, depth) => {
|
|
161861
|
+
if (depth < 0 || !existsSync19(path4))
|
|
161519
161862
|
return;
|
|
161520
161863
|
let stat;
|
|
161521
161864
|
try {
|
|
161522
|
-
stat = statSync5(
|
|
161865
|
+
stat = statSync5(path4);
|
|
161523
161866
|
} catch {
|
|
161524
161867
|
return;
|
|
161525
161868
|
}
|
|
161526
161869
|
if (!stat.isDirectory())
|
|
161527
161870
|
return;
|
|
161528
|
-
const packageJson =
|
|
161529
|
-
if (
|
|
161871
|
+
const packageJson = join19(path4, "package.json");
|
|
161872
|
+
if (existsSync19(packageJson)) {
|
|
161530
161873
|
try {
|
|
161531
161874
|
const pkg = JSON.parse(readFileSync15(packageJson, "utf-8"));
|
|
161532
161875
|
const name2 = typeof pkg.name === "string" ? pkg.name : "";
|
|
161533
161876
|
const version2 = typeof pkg.version === "string" ? pkg.version : undefined;
|
|
161534
|
-
if (name2 === PACKAGE_NAME2 ||
|
|
161877
|
+
if (name2 === PACKAGE_NAME2 || path4.includes("pi-magic-context")) {
|
|
161535
161878
|
if (force || !version2 || version2 !== self)
|
|
161536
|
-
found.set(
|
|
161879
|
+
found.set(path4, { path: path4, version: version2 });
|
|
161537
161880
|
}
|
|
161538
161881
|
} catch {
|
|
161539
|
-
if (
|
|
161540
|
-
found.set(
|
|
161882
|
+
if (path4.includes("pi-magic-context"))
|
|
161883
|
+
found.set(path4, { path: path4 });
|
|
161541
161884
|
}
|
|
161542
161885
|
}
|
|
161543
161886
|
let entries = [];
|
|
161544
161887
|
try {
|
|
161545
|
-
entries = readdirSync4(
|
|
161888
|
+
entries = readdirSync4(path4);
|
|
161546
161889
|
} catch {
|
|
161547
161890
|
return;
|
|
161548
161891
|
}
|
|
161549
161892
|
for (const entry of entries)
|
|
161550
|
-
visit(
|
|
161893
|
+
visit(join19(path4, entry), depth - 1);
|
|
161551
161894
|
};
|
|
161552
161895
|
for (const root of cacheRoots())
|
|
161553
161896
|
visit(root, 5);
|
|
@@ -161584,7 +161927,7 @@ async function runHealthChecks(options) {
|
|
|
161584
161927
|
}
|
|
161585
161928
|
const settingsPath = getPiUserExtensionsPath();
|
|
161586
161929
|
let packages = [];
|
|
161587
|
-
if (!
|
|
161930
|
+
if (!existsSync19(settingsPath)) {
|
|
161588
161931
|
add(results, "warn", `Pi settings not found at ${settingsPath}`);
|
|
161589
161932
|
repairPlan.addPackageEntry = true;
|
|
161590
161933
|
} else {
|
|
@@ -161604,24 +161947,24 @@ async function runHealthChecks(options) {
|
|
|
161604
161947
|
}
|
|
161605
161948
|
const userConfigPath = getPiUserConfigPath();
|
|
161606
161949
|
const projectPath = projectConfigPath(options.cwd);
|
|
161607
|
-
for (const [label,
|
|
161950
|
+
for (const [label, path4, required2] of [
|
|
161608
161951
|
["user", userConfigPath, true],
|
|
161609
161952
|
["project", projectPath, false]
|
|
161610
161953
|
]) {
|
|
161611
|
-
if (!
|
|
161954
|
+
if (!existsSync19(path4)) {
|
|
161612
161955
|
if (required2) {
|
|
161613
|
-
add(results, "warn", `No ${label} magic-context.jsonc found at ${
|
|
161956
|
+
add(results, "warn", `No ${label} magic-context.jsonc found at ${path4}`);
|
|
161614
161957
|
repairPlan.writeUserConfig = true;
|
|
161615
161958
|
} else {
|
|
161616
|
-
add(results, "info", `No project Pi magic-context.jsonc found at ${
|
|
161959
|
+
add(results, "info", `No project Pi magic-context.jsonc found at ${path4}`);
|
|
161617
161960
|
}
|
|
161618
161961
|
continue;
|
|
161619
161962
|
}
|
|
161620
|
-
const parsed = readJsonc4(
|
|
161963
|
+
const parsed = readJsonc4(path4);
|
|
161621
161964
|
if (parsed.error)
|
|
161622
161965
|
add(results, "fail", `${label} magic-context.jsonc is invalid JSONC: ${parsed.error}`);
|
|
161623
161966
|
else
|
|
161624
|
-
add(results, "pass", `${label} magic-context.jsonc is valid JSONC: ${
|
|
161967
|
+
add(results, "pass", `${label} magic-context.jsonc is valid JSONC: ${path4}`);
|
|
161625
161968
|
}
|
|
161626
161969
|
const loadedConfig = loadPiConfig({ cwd: options.cwd });
|
|
161627
161970
|
if (loadedConfig.warnings.length > 0) {
|
|
@@ -161641,8 +161984,8 @@ async function runHealthChecks(options) {
|
|
|
161641
161984
|
add(results, "pass", `historian.model "${historianModel}" has thinking_level "${historianThinkingLevel}" configured`);
|
|
161642
161985
|
}
|
|
161643
161986
|
const storageDir = getMagicContextStorageDir();
|
|
161644
|
-
const dbPath =
|
|
161645
|
-
const existedBeforeOpen =
|
|
161987
|
+
const dbPath = join19(storageDir, "context.db");
|
|
161988
|
+
const existedBeforeOpen = existsSync19(dbPath);
|
|
161646
161989
|
if (existedBeforeOpen)
|
|
161647
161990
|
add(results, "pass", `Shared context DB exists at ${dbPath}`);
|
|
161648
161991
|
else
|
|
@@ -161699,7 +162042,12 @@ async function runHealthChecks(options) {
|
|
|
161699
162042
|
} else {
|
|
161700
162043
|
add(results, "pass", `Embedding provider: ${loadedConfig.config.embedding.provider}`);
|
|
161701
162044
|
}
|
|
161702
|
-
|
|
162045
|
+
const piEntries = packages.filter((entry) => hasPiPackage([entry]));
|
|
162046
|
+
if (piEntries.length > 1) {
|
|
162047
|
+
add(results, "fail", `Multiple magic-context entries in Pi packages[] — this loads the plugin twice: ${piEntries.join(", ")}`);
|
|
162048
|
+
} else {
|
|
162049
|
+
add(results, "pass", "No conflicting magic-context entries in Pi packages[]");
|
|
162050
|
+
}
|
|
161703
162051
|
const otherExtensions = packages.filter((entry) => !hasPiPackage([entry]));
|
|
161704
162052
|
if (otherExtensions.length > 0) {
|
|
161705
162053
|
add(results, "info", `Other Pi extensions registered: ${otherExtensions.join(", ")}`);
|
|
@@ -161713,8 +162061,8 @@ async function runHealthChecks(options) {
|
|
|
161713
162061
|
} else {
|
|
161714
162062
|
add(results, "pass", "Pi extension cache clean (no stale cached package found)");
|
|
161715
162063
|
}
|
|
161716
|
-
const logPath =
|
|
161717
|
-
if (
|
|
162064
|
+
const logPath = join19(tmpdir6(), "magic-context.log");
|
|
162065
|
+
if (existsSync19(logPath)) {
|
|
161718
162066
|
const stat = statSync5(logPath);
|
|
161719
162067
|
const sizeKb = (stat.size / 1024).toFixed(0);
|
|
161720
162068
|
const lines = readFileSync15(logPath, "utf-8").split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
|
|
@@ -161723,10 +162071,10 @@ async function runHealthChecks(options) {
|
|
|
161723
162071
|
} else {
|
|
161724
162072
|
add(results, "info", `No plugin log file yet at ${logPath}`);
|
|
161725
162073
|
}
|
|
161726
|
-
const historianDumpDir =
|
|
161727
|
-
if (
|
|
162074
|
+
const historianDumpDir = join19(tmpdir6(), "magic-context-historian");
|
|
162075
|
+
if (existsSync19(historianDumpDir)) {
|
|
161728
162076
|
try {
|
|
161729
|
-
const dumps = readdirSync4(historianDumpDir).filter((f) => f.endsWith(".xml")).map((f) => ({ name: f, mtime: statSync5(
|
|
162077
|
+
const dumps = readdirSync4(historianDumpDir).filter((f) => f.endsWith(".xml")).map((f) => ({ name: f, mtime: statSync5(join19(historianDumpDir, f)).mtimeMs })).sort((a, b) => b.mtime - a.mtime);
|
|
161730
162078
|
if (dumps.length > 0) {
|
|
161731
162079
|
add(results, "warn", `Historian debug dumps: ${dumps.length} file(s) in ${historianDumpDir}`);
|
|
161732
162080
|
for (const dump of dumps.slice(0, 3)) {
|
|
@@ -161746,13 +162094,13 @@ async function runHealthChecks(options) {
|
|
|
161746
162094
|
}
|
|
161747
162095
|
return { results, repairPlan, ...summarize(results) };
|
|
161748
162096
|
}
|
|
161749
|
-
function writeDefaultMagicContextConfig(
|
|
161750
|
-
|
|
162097
|
+
function writeDefaultMagicContextConfig(path4) {
|
|
162098
|
+
mkdirSync8(dirname9(path4), { recursive: true });
|
|
161751
162099
|
const config2 = {
|
|
161752
162100
|
$schema: "https://raw.githubusercontent.com/cortexkit/magic-context/master/assets/magic-context.schema.json",
|
|
161753
162101
|
...MagicContextConfigSchema.parse({})
|
|
161754
162102
|
};
|
|
161755
|
-
|
|
162103
|
+
writeFileSync12(path4, `${import_comment_json10.stringify(config2, null, 2)}
|
|
161756
162104
|
`);
|
|
161757
162105
|
}
|
|
161758
162106
|
function repair(plan, prompts) {
|
|
@@ -161769,7 +162117,7 @@ function repair(plan, prompts) {
|
|
|
161769
162117
|
}
|
|
161770
162118
|
if (plan.writeUserConfig) {
|
|
161771
162119
|
const configPath = getPiUserConfigPath();
|
|
161772
|
-
if (!
|
|
162120
|
+
if (!existsSync19(configPath)) {
|
|
161773
162121
|
try {
|
|
161774
162122
|
writeDefaultMagicContextConfig(configPath);
|
|
161775
162123
|
prompts.log.success(`Wrote default Magic Context config to ${configPath}`);
|
|
@@ -161779,13 +162127,13 @@ function repair(plan, prompts) {
|
|
|
161779
162127
|
}
|
|
161780
162128
|
}
|
|
161781
162129
|
}
|
|
161782
|
-
for (const
|
|
162130
|
+
for (const path4 of plan.clearCachePaths) {
|
|
161783
162131
|
try {
|
|
161784
|
-
rmSync2(
|
|
161785
|
-
prompts.log.success(`Cleared stale Pi extension cache: ${
|
|
162132
|
+
rmSync2(path4, { recursive: true, force: true });
|
|
162133
|
+
prompts.log.success(`Cleared stale Pi extension cache: ${path4}`);
|
|
161786
162134
|
fixed += 1;
|
|
161787
162135
|
} catch (error48) {
|
|
161788
|
-
console.error(`FAIL Could not clear ${
|
|
162136
|
+
console.error(`FAIL Could not clear ${path4}: ${error48 instanceof Error ? error48.message : String(error48)}`);
|
|
161789
162137
|
}
|
|
161790
162138
|
}
|
|
161791
162139
|
return fixed;
|
|
@@ -161930,7 +162278,7 @@ var exports_doctor = {};
|
|
|
161930
162278
|
__export(exports_doctor, {
|
|
161931
162279
|
runDoctor: () => runDoctor3
|
|
161932
162280
|
});
|
|
161933
|
-
import { existsSync as
|
|
162281
|
+
import { existsSync as existsSync20, rmSync as rmSync3 } from "node:fs";
|
|
161934
162282
|
async function runDoctor3(options) {
|
|
161935
162283
|
if (options.clear)
|
|
161936
162284
|
return runClear();
|
|
@@ -162014,7 +162362,7 @@ async function runClear() {
|
|
|
162014
162362
|
const s = spinner();
|
|
162015
162363
|
s.start(`Clearing ${item.path}`);
|
|
162016
162364
|
try {
|
|
162017
|
-
if (
|
|
162365
|
+
if (existsSync20(item.path)) {
|
|
162018
162366
|
rmSync3(item.path, { recursive: true, force: true });
|
|
162019
162367
|
}
|
|
162020
162368
|
s.stop(`Cleared ${item.path}`);
|
|
@@ -162047,9 +162395,9 @@ var init_doctor = __esm(async () => {
|
|
|
162047
162395
|
});
|
|
162048
162396
|
|
|
162049
162397
|
// src/index.ts
|
|
162050
|
-
import { createRequire as
|
|
162398
|
+
import { createRequire as createRequire7 } from "node:module";
|
|
162051
162399
|
function getVersion() {
|
|
162052
|
-
const req =
|
|
162400
|
+
const req = createRequire7(import.meta.url);
|
|
162053
162401
|
for (const relPath of ["../../package.json", "../package.json"]) {
|
|
162054
162402
|
try {
|
|
162055
162403
|
const pkg = req(relPath);
|
|
@@ -162079,10 +162427,10 @@ function printUsage() {
|
|
|
162079
162427
|
console.log(" (default: auto-detect, prompt if multiple installed)");
|
|
162080
162428
|
console.log("");
|
|
162081
162429
|
console.log(" Usage:");
|
|
162082
|
-
console.log("
|
|
162083
|
-
console.log("
|
|
162084
|
-
console.log("
|
|
162085
|
-
console.log("
|
|
162430
|
+
console.log(" npx @cortexkit/magic-context@latest setup");
|
|
162431
|
+
console.log(" npx @cortexkit/magic-context@latest doctor");
|
|
162432
|
+
console.log(" npx @cortexkit/magic-context@latest doctor --issue");
|
|
162433
|
+
console.log(" npx @cortexkit/magic-context@latest doctor migrate \\");
|
|
162086
162434
|
console.log(" --from opencode --to pi --session ses_xxx --dry-run");
|
|
162087
162435
|
console.log("");
|
|
162088
162436
|
}
|