@cortexkit/pi-magic-context 0.16.2 → 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/README.md +2 -2
- package/dist/index.js +412 -92
- package/dist/subagent-entry.js +362 -42
- package/package.json +1 -1
package/dist/subagent-entry.js
CHANGED
|
@@ -15043,14 +15043,334 @@ var init_embedding = __esm(() => {
|
|
|
15043
15043
|
SWEEP_MAX_WALL_CLOCK_MS = 10 * 60 * 1000;
|
|
15044
15044
|
});
|
|
15045
15045
|
|
|
15046
|
+
// ../../node_modules/.bun/nanotar@0.3.0/node_modules/nanotar/dist/index.mjs
|
|
15047
|
+
function parseTar(data, opts) {
|
|
15048
|
+
const buffer2 = data.buffer || data;
|
|
15049
|
+
const files = [];
|
|
15050
|
+
let offset = 0;
|
|
15051
|
+
let nextExtendedHeader;
|
|
15052
|
+
let globalExtendedHeader;
|
|
15053
|
+
while (offset < buffer2.byteLength - 512) {
|
|
15054
|
+
let name = _readString(buffer2, offset, 100);
|
|
15055
|
+
if (name.length === 0) {
|
|
15056
|
+
break;
|
|
15057
|
+
}
|
|
15058
|
+
if (nextExtendedHeader) {
|
|
15059
|
+
const longName = nextExtendedHeader.path || nextExtendedHeader.linkpath;
|
|
15060
|
+
if (longName) {
|
|
15061
|
+
name = longName;
|
|
15062
|
+
}
|
|
15063
|
+
}
|
|
15064
|
+
const mode = _readString(buffer2, offset + 100, 8).trim();
|
|
15065
|
+
const uid = Number.parseInt(_readString(buffer2, offset + 108, 8));
|
|
15066
|
+
const gid = Number.parseInt(_readString(buffer2, offset + 116, 8));
|
|
15067
|
+
const size = _readNumber(buffer2, offset + 124, 12);
|
|
15068
|
+
const seek = 512 + 512 * Math.trunc(size / 512) + (size % 512 ? 512 : 0);
|
|
15069
|
+
const mtime = _readNumber(buffer2, offset + 136, 12);
|
|
15070
|
+
const _type = _readString(buffer2, offset + 156, 1) || "0";
|
|
15071
|
+
const type = tarItemTypeMap[_type] || _type;
|
|
15072
|
+
switch (type) {
|
|
15073
|
+
case "extendedHeader":
|
|
15074
|
+
case "globalExtendedHeader": {
|
|
15075
|
+
const headers = _parseExtendedHeaders(new Uint8Array(buffer2, offset + 512, size));
|
|
15076
|
+
if (type === "extendedHeader") {
|
|
15077
|
+
nextExtendedHeader = headers;
|
|
15078
|
+
} else {
|
|
15079
|
+
nextExtendedHeader = undefined;
|
|
15080
|
+
globalExtendedHeader = {
|
|
15081
|
+
...globalExtendedHeader,
|
|
15082
|
+
...headers
|
|
15083
|
+
};
|
|
15084
|
+
}
|
|
15085
|
+
offset += seek;
|
|
15086
|
+
continue;
|
|
15087
|
+
}
|
|
15088
|
+
case "gnuLongFileName":
|
|
15089
|
+
case "gnuOldLongFileName":
|
|
15090
|
+
case "gnuLongLinkName": {
|
|
15091
|
+
nextExtendedHeader = { path: _readString(buffer2, offset + 512, size) };
|
|
15092
|
+
offset += seek;
|
|
15093
|
+
continue;
|
|
15094
|
+
}
|
|
15095
|
+
}
|
|
15096
|
+
const user = _readString(buffer2, offset + 265, 32);
|
|
15097
|
+
const group = _readString(buffer2, offset + 297, 32);
|
|
15098
|
+
name = _sanitizePath(name);
|
|
15099
|
+
const meta3 = {
|
|
15100
|
+
name,
|
|
15101
|
+
type,
|
|
15102
|
+
size,
|
|
15103
|
+
attrs: {
|
|
15104
|
+
...globalExtendedHeader,
|
|
15105
|
+
...nextExtendedHeader,
|
|
15106
|
+
mode,
|
|
15107
|
+
uid,
|
|
15108
|
+
gid,
|
|
15109
|
+
mtime,
|
|
15110
|
+
user,
|
|
15111
|
+
group
|
|
15112
|
+
}
|
|
15113
|
+
};
|
|
15114
|
+
nextExtendedHeader = undefined;
|
|
15115
|
+
if (opts?.filter && !opts.filter(meta3)) {
|
|
15116
|
+
offset += seek;
|
|
15117
|
+
continue;
|
|
15118
|
+
}
|
|
15119
|
+
if (opts?.metaOnly) {
|
|
15120
|
+
files.push(meta3);
|
|
15121
|
+
offset += seek;
|
|
15122
|
+
continue;
|
|
15123
|
+
}
|
|
15124
|
+
const data2 = size === 0 ? undefined : new Uint8Array(buffer2, offset + 512, size);
|
|
15125
|
+
files.push({
|
|
15126
|
+
...meta3,
|
|
15127
|
+
data: data2,
|
|
15128
|
+
get text() {
|
|
15129
|
+
return new TextDecoder().decode(this.data);
|
|
15130
|
+
}
|
|
15131
|
+
});
|
|
15132
|
+
offset += seek;
|
|
15133
|
+
}
|
|
15134
|
+
return files;
|
|
15135
|
+
}
|
|
15136
|
+
async function parseTarGzip(data, opts = {}) {
|
|
15137
|
+
const stream = new ReadableStream({
|
|
15138
|
+
start(controller) {
|
|
15139
|
+
controller.enqueue(new Uint8Array(data));
|
|
15140
|
+
controller.close();
|
|
15141
|
+
}
|
|
15142
|
+
}).pipeThrough(new DecompressionStream(opts.compression ?? "gzip"));
|
|
15143
|
+
const decompressedData = await new Response(stream).arrayBuffer();
|
|
15144
|
+
return parseTar(decompressedData, opts);
|
|
15145
|
+
}
|
|
15146
|
+
function _sanitizePath(path3) {
|
|
15147
|
+
let normalized = path3.replace(/\\/g, "/");
|
|
15148
|
+
normalized = normalized.replace(/^[a-zA-Z]:\//, "");
|
|
15149
|
+
normalized = normalized.replace(/^\/+/, "");
|
|
15150
|
+
const hasLeadingDotSlash = normalized.startsWith("./");
|
|
15151
|
+
const parts = normalized.split("/");
|
|
15152
|
+
const resolved = [];
|
|
15153
|
+
for (const part of parts) {
|
|
15154
|
+
if (part === "..") {
|
|
15155
|
+
resolved.pop();
|
|
15156
|
+
} else if (part !== "." && part !== "") {
|
|
15157
|
+
resolved.push(part);
|
|
15158
|
+
}
|
|
15159
|
+
}
|
|
15160
|
+
let result = resolved.join("/");
|
|
15161
|
+
if (hasLeadingDotSlash && !result.startsWith("./")) {
|
|
15162
|
+
result = "./" + result;
|
|
15163
|
+
}
|
|
15164
|
+
if (path3.endsWith("/") && !result.endsWith("/")) {
|
|
15165
|
+
result += "/";
|
|
15166
|
+
}
|
|
15167
|
+
return result;
|
|
15168
|
+
}
|
|
15169
|
+
function _readString(buffer2, offset, size) {
|
|
15170
|
+
const view = new Uint8Array(buffer2, offset, size);
|
|
15171
|
+
const i = view.indexOf(0);
|
|
15172
|
+
const td = new TextDecoder;
|
|
15173
|
+
return td.decode(i === -1 ? view : view.slice(0, i));
|
|
15174
|
+
}
|
|
15175
|
+
function _readNumber(buffer2, offset, size) {
|
|
15176
|
+
const view = new Uint8Array(buffer2, offset, size);
|
|
15177
|
+
let str = "";
|
|
15178
|
+
for (let i = 0;i < size; i++) {
|
|
15179
|
+
str += String.fromCodePoint(view[i]);
|
|
15180
|
+
}
|
|
15181
|
+
return Number.parseInt(str, 8);
|
|
15182
|
+
}
|
|
15183
|
+
function _parseExtendedHeaders(data) {
|
|
15184
|
+
const dataStr = new TextDecoder().decode(data);
|
|
15185
|
+
const headers = {};
|
|
15186
|
+
for (const line of dataStr.split(`
|
|
15187
|
+
`)) {
|
|
15188
|
+
const s = line.split(" ")[1]?.split("=");
|
|
15189
|
+
if (s) {
|
|
15190
|
+
headers[s[0]] = s[1];
|
|
15191
|
+
}
|
|
15192
|
+
}
|
|
15193
|
+
return headers;
|
|
15194
|
+
}
|
|
15195
|
+
var tarItemTypeMap;
|
|
15196
|
+
var init_dist = __esm(() => {
|
|
15197
|
+
tarItemTypeMap = {
|
|
15198
|
+
"0": "file",
|
|
15199
|
+
"1": "hardLink",
|
|
15200
|
+
"2": "symbolicLink",
|
|
15201
|
+
"3": "characterDevice",
|
|
15202
|
+
"4": "blockDevice",
|
|
15203
|
+
"5": "directory",
|
|
15204
|
+
"6": "fifo",
|
|
15205
|
+
"7": "contiguousFile",
|
|
15206
|
+
g: "globalExtendedHeader",
|
|
15207
|
+
x: "extendedHeader",
|
|
15208
|
+
D: "gnuDirectory",
|
|
15209
|
+
I: "gnuInodeMetadata",
|
|
15210
|
+
K: "gnuLongLinkName",
|
|
15211
|
+
L: "gnuLongFileName",
|
|
15212
|
+
N: "gnuOldLongFileName",
|
|
15213
|
+
M: "gnuMultiVolume",
|
|
15214
|
+
S: "gnuSparseFile",
|
|
15215
|
+
E: "gnuExtendedSparse",
|
|
15216
|
+
A: "solarisAcl",
|
|
15217
|
+
V: "solarisVolumeLabel",
|
|
15218
|
+
X: "solarisOldExtendedHeader"
|
|
15219
|
+
};
|
|
15220
|
+
});
|
|
15221
|
+
|
|
15222
|
+
// ../plugin/src/shared/native-binding.ts
|
|
15223
|
+
var exports_native_binding = {};
|
|
15224
|
+
__export(exports_native_binding, {
|
|
15225
|
+
resolveBetterSqliteNativeBinding: () => resolveBetterSqliteNativeBinding
|
|
15226
|
+
});
|
|
15227
|
+
import { existsSync, mkdirSync as mkdirSync2, writeFileSync } from "node:fs";
|
|
15228
|
+
import { createRequire } from "node:module";
|
|
15229
|
+
import * as path3 from "node:path";
|
|
15230
|
+
function logInfo(message) {
|
|
15231
|
+
log(`${PREFIX} ${message}`);
|
|
15232
|
+
}
|
|
15233
|
+
function logWarn(message) {
|
|
15234
|
+
log(`${PREFIX} WARN ${message}`);
|
|
15235
|
+
}
|
|
15236
|
+
function probeAbi(binaryPath) {
|
|
15237
|
+
const expected = process.versions.modules;
|
|
15238
|
+
try {
|
|
15239
|
+
const sandbox = { exports: {} };
|
|
15240
|
+
process.dlopen(sandbox, binaryPath);
|
|
15241
|
+
return { ok: true };
|
|
15242
|
+
} catch (err) {
|
|
15243
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
15244
|
+
const pair = message.match(/NODE_MODULE_VERSION (\d+).*NODE_MODULE_VERSION (\d+)/s);
|
|
15245
|
+
if (pair?.[1] && pair[2]) {
|
|
15246
|
+
return { ok: false, expected: pair[2], actual: pair[1] };
|
|
15247
|
+
}
|
|
15248
|
+
const single = message.match(/NODE_MODULE_VERSION[ =:]+(\d+)/);
|
|
15249
|
+
if (single?.[1]) {
|
|
15250
|
+
return { ok: false, expected, actual: single[1] };
|
|
15251
|
+
}
|
|
15252
|
+
logWarn(`could not parse ABI from dlopen error: ${message}`);
|
|
15253
|
+
return { ok: false, expected, actual: null };
|
|
15254
|
+
}
|
|
15255
|
+
}
|
|
15256
|
+
function resolveBetterSqlite3OnDisk(requireFn) {
|
|
15257
|
+
try {
|
|
15258
|
+
const pkgJsonPath = requireFn.resolve("better-sqlite3/package.json");
|
|
15259
|
+
const pkgDir = path3.dirname(pkgJsonPath);
|
|
15260
|
+
const pkgJson = requireFn(pkgJsonPath);
|
|
15261
|
+
const binaryPath = path3.join(pkgDir, "build", "Release", "better_sqlite3.node");
|
|
15262
|
+
return { binaryPath, pkgVersion: pkgJson.version };
|
|
15263
|
+
} catch (err) {
|
|
15264
|
+
logWarn(`could not resolve better-sqlite3 in node_modules: ${err instanceof Error ? err.message : String(err)}`);
|
|
15265
|
+
return null;
|
|
15266
|
+
}
|
|
15267
|
+
}
|
|
15268
|
+
function getCachedBinaryPath(pkgVersion, abi) {
|
|
15269
|
+
return path3.join(getCacheDir(), "cortexkit", "native-bindings", "better-sqlite3", `v${pkgVersion}`, `electron-v${abi}-${process.platform}-${process.arch}`, "better_sqlite3.node");
|
|
15270
|
+
}
|
|
15271
|
+
async function downloadElectronPrebuild(pkgVersion, abi) {
|
|
15272
|
+
const filename = `better-sqlite3-v${pkgVersion}-electron-v${abi}-${process.platform}-${process.arch}.tar.gz`;
|
|
15273
|
+
const url2 = `https://github.com/WiseLibs/better-sqlite3/releases/download/v${pkgVersion}/${filename}`;
|
|
15274
|
+
logInfo(`downloading ${url2}`);
|
|
15275
|
+
const response = await fetch(url2, {
|
|
15276
|
+
redirect: "follow",
|
|
15277
|
+
headers: { "User-Agent": "magic-context-plugin/native-binding" }
|
|
15278
|
+
});
|
|
15279
|
+
if (!response.ok) {
|
|
15280
|
+
throw new Error(`failed to download Electron prebuild (HTTP ${response.status} ${response.statusText}) from ${url2}`);
|
|
15281
|
+
}
|
|
15282
|
+
const tarballBytes = new Uint8Array(await response.arrayBuffer());
|
|
15283
|
+
logInfo(`downloaded ${(tarballBytes.length / 1024).toFixed(1)} KB; extracting`);
|
|
15284
|
+
const files = await parseTarGzip(tarballBytes);
|
|
15285
|
+
const nodeFile = files.find((f) => f.name.endsWith("better_sqlite3.node"));
|
|
15286
|
+
if (!nodeFile?.data) {
|
|
15287
|
+
const names = files.map((f) => f.name).join(", ");
|
|
15288
|
+
throw new Error(`Electron prebuild tarball did not contain better_sqlite3.node; got: [${names}]`);
|
|
15289
|
+
}
|
|
15290
|
+
return nodeFile.data instanceof Uint8Array ? nodeFile.data : new Uint8Array(nodeFile.data);
|
|
15291
|
+
}
|
|
15292
|
+
async function resolveBetterSqliteNativeBinding() {
|
|
15293
|
+
if (!process.versions.electron) {
|
|
15294
|
+
return null;
|
|
15295
|
+
}
|
|
15296
|
+
if (inFlight) {
|
|
15297
|
+
return inFlight;
|
|
15298
|
+
}
|
|
15299
|
+
const promise2 = (async () => {
|
|
15300
|
+
const expected = process.versions.modules;
|
|
15301
|
+
logInfo(`Electron detected (v${process.versions.electron}, NODE_MODULE_VERSION ${expected}); verifying better-sqlite3 binding`);
|
|
15302
|
+
const requireFn = createRequire(import.meta.url);
|
|
15303
|
+
const resolved = resolveBetterSqlite3OnDisk(requireFn);
|
|
15304
|
+
if (!resolved) {
|
|
15305
|
+
return null;
|
|
15306
|
+
}
|
|
15307
|
+
const { binaryPath: diskPath, pkgVersion } = resolved;
|
|
15308
|
+
if (existsSync(diskPath)) {
|
|
15309
|
+
const diskProbe = probeAbi(diskPath);
|
|
15310
|
+
if (diskProbe.ok) {
|
|
15311
|
+
logInfo(`on-disk binary already matches Electron ABI v${expected}; using default bindings() lookup`);
|
|
15312
|
+
return null;
|
|
15313
|
+
}
|
|
15314
|
+
logInfo(`on-disk binary ABI ${diskProbe.actual ?? "unknown"} != required ${expected}; will use Electron prebuild`);
|
|
15315
|
+
} else {
|
|
15316
|
+
logWarn(`expected better-sqlite3 binary not found at ${diskPath}; will fetch Electron prebuild anyway`);
|
|
15317
|
+
}
|
|
15318
|
+
const cachedPath = getCachedBinaryPath(pkgVersion, expected);
|
|
15319
|
+
if (existsSync(cachedPath)) {
|
|
15320
|
+
const cachedProbe = probeAbi(cachedPath);
|
|
15321
|
+
if (cachedProbe.ok) {
|
|
15322
|
+
logInfo(`using cached Electron prebuild at ${cachedPath}`);
|
|
15323
|
+
return cachedPath;
|
|
15324
|
+
}
|
|
15325
|
+
logWarn(`cached binary at ${cachedPath} has wrong ABI (${cachedProbe.actual ?? "unknown"} != ${expected}); refetching`);
|
|
15326
|
+
}
|
|
15327
|
+
mkdirSync2(path3.dirname(cachedPath), { recursive: true });
|
|
15328
|
+
const nodeFileBytes = await downloadElectronPrebuild(pkgVersion, expected);
|
|
15329
|
+
writeFileSync(cachedPath, nodeFileBytes);
|
|
15330
|
+
logInfo(`cached Electron prebuild at ${cachedPath} (${(nodeFileBytes.length / 1024).toFixed(1)} KB)`);
|
|
15331
|
+
const finalProbe = probeAbi(cachedPath);
|
|
15332
|
+
if (!finalProbe.ok) {
|
|
15333
|
+
throw new Error(`downloaded Electron prebuild has wrong ABI (${finalProbe.actual ?? "unknown"} != ${expected}); refusing to use`);
|
|
15334
|
+
}
|
|
15335
|
+
return cachedPath;
|
|
15336
|
+
})();
|
|
15337
|
+
inFlight = promise2;
|
|
15338
|
+
try {
|
|
15339
|
+
return await promise2;
|
|
15340
|
+
} finally {
|
|
15341
|
+
if (inFlight === promise2) {
|
|
15342
|
+
inFlight = null;
|
|
15343
|
+
}
|
|
15344
|
+
}
|
|
15345
|
+
}
|
|
15346
|
+
var PREFIX = "[native-binding]", inFlight = null;
|
|
15347
|
+
var init_native_binding = __esm(() => {
|
|
15348
|
+
init_dist();
|
|
15349
|
+
init_data_path();
|
|
15350
|
+
init_logger();
|
|
15351
|
+
});
|
|
15352
|
+
|
|
15046
15353
|
// ../plugin/src/shared/sqlite.ts
|
|
15047
|
-
var isBun, bunSpec, betterSpec, sqliteModule, DatabaseImpl, Database;
|
|
15354
|
+
var isBun, bunSpec, betterSpec, electronNativeBinding, sqliteModule, RawDatabaseImpl, DatabaseImpl, Database;
|
|
15048
15355
|
var init_sqlite = __esm(async () => {
|
|
15049
15356
|
isBun = typeof process !== "undefined" && typeof process.versions?.bun === "string";
|
|
15050
15357
|
bunSpec = "bun:" + "sqlite";
|
|
15051
15358
|
betterSpec = "better-" + "sqlite3";
|
|
15359
|
+
electronNativeBinding = isBun ? null : await (async () => {
|
|
15360
|
+
const mod = await Promise.resolve().then(() => (init_native_binding(), exports_native_binding));
|
|
15361
|
+
return mod.resolveBetterSqliteNativeBinding();
|
|
15362
|
+
})();
|
|
15052
15363
|
sqliteModule = isBun ? await import(bunSpec) : await import(betterSpec);
|
|
15053
|
-
|
|
15364
|
+
RawDatabaseImpl = isBun ? sqliteModule.Database : sqliteModule.default;
|
|
15365
|
+
DatabaseImpl = electronNativeBinding == null ? RawDatabaseImpl : class DatabaseWithElectronBinding extends RawDatabaseImpl {
|
|
15366
|
+
constructor(filename, options) {
|
|
15367
|
+
const fallback = electronNativeBinding;
|
|
15368
|
+
super(filename, {
|
|
15369
|
+
...options,
|
|
15370
|
+
nativeBinding: options?.nativeBinding ?? fallback
|
|
15371
|
+
});
|
|
15372
|
+
}
|
|
15373
|
+
};
|
|
15054
15374
|
Database = DatabaseImpl;
|
|
15055
15375
|
});
|
|
15056
15376
|
|
|
@@ -22670,10 +22990,10 @@ var require_stringify = __commonJS((exports, module) => {
|
|
|
22670
22990
|
replacer = null;
|
|
22671
22991
|
indent = EMPTY;
|
|
22672
22992
|
};
|
|
22673
|
-
var
|
|
22993
|
+
var join6 = (one, two, gap) => one ? two ? one + two.trim() + LF + gap : one.trimRight() + repeat_line_breaks(Math.max(1, count_trailing_line_breaks(one, gap)), gap) : two ? two.trimRight() + repeat_line_breaks(Math.max(1, count_trailing_line_breaks(two, gap)), gap) : EMPTY;
|
|
22674
22994
|
var join_content = (inside, value, gap) => {
|
|
22675
22995
|
const comment = process_comments(value, PREFIX_BEFORE, gap + indent, true);
|
|
22676
|
-
return
|
|
22996
|
+
return join6(comment, inside, gap);
|
|
22677
22997
|
};
|
|
22678
22998
|
var stringify_string = (holder, key, value) => {
|
|
22679
22999
|
const raw = get_raw_string_literal(holder, key);
|
|
@@ -22695,13 +23015,13 @@ var require_stringify = __commonJS((exports, module) => {
|
|
|
22695
23015
|
if (i !== 0) {
|
|
22696
23016
|
inside += COMMA;
|
|
22697
23017
|
}
|
|
22698
|
-
const before =
|
|
23018
|
+
const before = join6(after_comma, process_comments(value, BEFORE(i), deeper_gap), deeper_gap);
|
|
22699
23019
|
inside += before || LF + deeper_gap;
|
|
22700
23020
|
inside += stringify(i, value, deeper_gap) || STR_NULL;
|
|
22701
23021
|
inside += process_comments(value, AFTER_VALUE(i), deeper_gap);
|
|
22702
23022
|
after_comma = process_comments(value, AFTER(i), deeper_gap);
|
|
22703
23023
|
}
|
|
22704
|
-
inside +=
|
|
23024
|
+
inside += join6(after_comma, process_comments(value, PREFIX_AFTER, deeper_gap), deeper_gap);
|
|
22705
23025
|
return BRACKET_OPEN + join_content(inside, value, gap) + BRACKET_CLOSE;
|
|
22706
23026
|
};
|
|
22707
23027
|
var object_stringify = (value, gap) => {
|
|
@@ -22722,13 +23042,13 @@ var require_stringify = __commonJS((exports, module) => {
|
|
|
22722
23042
|
inside += COMMA;
|
|
22723
23043
|
}
|
|
22724
23044
|
first = false;
|
|
22725
|
-
const before =
|
|
23045
|
+
const before = join6(after_comma, process_comments(value, BEFORE(key), deeper_gap), deeper_gap);
|
|
22726
23046
|
inside += before || LF + deeper_gap;
|
|
22727
23047
|
inside += quote(key) + process_comments(value, AFTER_PROP(key), deeper_gap) + COLON + process_comments(value, AFTER_COLON(key), deeper_gap) + SPACE + sv + process_comments(value, AFTER_VALUE(key), deeper_gap);
|
|
22728
23048
|
after_comma = process_comments(value, AFTER(key), deeper_gap);
|
|
22729
23049
|
};
|
|
22730
23050
|
keys.forEach(iteratee);
|
|
22731
|
-
inside +=
|
|
23051
|
+
inside += join6(after_comma, process_comments(value, PREFIX_AFTER, deeper_gap), deeper_gap);
|
|
22732
23052
|
return CURLY_BRACKET_OPEN + join_content(inside, value, gap) + CURLY_BRACKET_CLOSE;
|
|
22733
23053
|
};
|
|
22734
23054
|
function stringify(key, holder, gap) {
|
|
@@ -22829,9 +23149,9 @@ __export(exports_read_session_db, {
|
|
|
22829
23149
|
findLastAssistantModelFromOpenCodeDb: () => findLastAssistantModelFromOpenCodeDb,
|
|
22830
23150
|
closeReadOnlySessionDb: () => closeReadOnlySessionDb
|
|
22831
23151
|
});
|
|
22832
|
-
import { join as
|
|
23152
|
+
import { join as join7 } from "node:path";
|
|
22833
23153
|
function getOpenCodeDbPath() {
|
|
22834
|
-
return
|
|
23154
|
+
return join7(getDataDir(), "opencode", "opencode.db");
|
|
22835
23155
|
}
|
|
22836
23156
|
function closeCachedReadOnlyDb() {
|
|
22837
23157
|
if (!cachedReadOnlyDb) {
|
|
@@ -22920,8 +23240,8 @@ init_embedding();
|
|
|
22920
23240
|
|
|
22921
23241
|
// ../plugin/src/features/magic-context/storage-db.ts
|
|
22922
23242
|
init_data_path();
|
|
22923
|
-
import { copyFileSync, cpSync, existsSync, mkdirSync as
|
|
22924
|
-
import { join as
|
|
23243
|
+
import { copyFileSync, cpSync, existsSync as existsSync2, mkdirSync as mkdirSync3 } from "node:fs";
|
|
23244
|
+
import { join as join5 } from "node:path";
|
|
22925
23245
|
|
|
22926
23246
|
// ../plugin/src/shared/error-message.ts
|
|
22927
23247
|
function getErrorMessage(error48) {
|
|
@@ -23250,21 +23570,21 @@ var persistenceByDatabase = new WeakMap;
|
|
|
23250
23570
|
var persistenceErrorByDatabase = new WeakMap;
|
|
23251
23571
|
function resolveDatabasePath() {
|
|
23252
23572
|
const dbDir = getMagicContextStorageDir();
|
|
23253
|
-
return { dbDir, dbPath:
|
|
23573
|
+
return { dbDir, dbPath: join5(dbDir, "context.db") };
|
|
23254
23574
|
}
|
|
23255
23575
|
function migrateLegacyStorageIfNeeded(targetDbPath, targetDbDir) {
|
|
23256
|
-
if (
|
|
23576
|
+
if (existsSync2(targetDbPath))
|
|
23257
23577
|
return;
|
|
23258
23578
|
const legacyDir = getLegacyOpenCodeMagicContextStorageDir();
|
|
23259
|
-
const legacyDbPath =
|
|
23260
|
-
if (!
|
|
23579
|
+
const legacyDbPath = join5(legacyDir, "context.db");
|
|
23580
|
+
if (!existsSync2(legacyDbPath))
|
|
23261
23581
|
return;
|
|
23262
23582
|
log(`[magic-context] migrating legacy plugin storage: ${legacyDir} -> ${targetDbDir} (legacy left in place as backup)`);
|
|
23263
|
-
|
|
23583
|
+
mkdirSync3(targetDbDir, { recursive: true });
|
|
23264
23584
|
for (const suffix of ["", "-wal", "-shm"]) {
|
|
23265
23585
|
const src = `${legacyDbPath}${suffix}`;
|
|
23266
|
-
const dst =
|
|
23267
|
-
if (
|
|
23586
|
+
const dst = join5(targetDbDir, `context.db${suffix}`);
|
|
23587
|
+
if (existsSync2(src)) {
|
|
23268
23588
|
try {
|
|
23269
23589
|
copyFileSync(src, dst);
|
|
23270
23590
|
} catch (error48) {
|
|
@@ -23272,9 +23592,9 @@ function migrateLegacyStorageIfNeeded(targetDbPath, targetDbDir) {
|
|
|
23272
23592
|
}
|
|
23273
23593
|
}
|
|
23274
23594
|
}
|
|
23275
|
-
const legacyModelsDir =
|
|
23276
|
-
const targetModelsDir =
|
|
23277
|
-
if (
|
|
23595
|
+
const legacyModelsDir = join5(legacyDir, "models");
|
|
23596
|
+
const targetModelsDir = join5(targetDbDir, "models");
|
|
23597
|
+
if (existsSync2(legacyModelsDir) && !existsSync2(targetModelsDir)) {
|
|
23278
23598
|
try {
|
|
23279
23599
|
cpSync(legacyModelsDir, targetModelsDir, { recursive: true });
|
|
23280
23600
|
} catch (error48) {
|
|
@@ -23654,7 +23974,7 @@ function openDatabase() {
|
|
|
23654
23974
|
}
|
|
23655
23975
|
try {
|
|
23656
23976
|
migrateLegacyStorageIfNeeded(dbPath, dbDir);
|
|
23657
|
-
|
|
23977
|
+
mkdirSync3(dbDir, { recursive: true });
|
|
23658
23978
|
const db = new Database(dbPath);
|
|
23659
23979
|
initializeDatabase(db);
|
|
23660
23980
|
runMigrations(db);
|
|
@@ -23688,14 +24008,14 @@ init_logger();
|
|
|
23688
24008
|
|
|
23689
24009
|
// src/config/index.ts
|
|
23690
24010
|
init_magic_context();
|
|
23691
|
-
import { existsSync as
|
|
24011
|
+
import { existsSync as existsSync4, readFileSync as readFileSync2 } from "node:fs";
|
|
23692
24012
|
import { homedir as homedir3 } from "node:os";
|
|
23693
|
-
import { join as
|
|
24013
|
+
import { join as join6 } from "node:path";
|
|
23694
24014
|
|
|
23695
24015
|
// ../plugin/src/config/variable.ts
|
|
23696
|
-
import { existsSync as
|
|
24016
|
+
import { existsSync as existsSync3, readFileSync } from "node:fs";
|
|
23697
24017
|
import { homedir as homedir2 } from "node:os";
|
|
23698
|
-
import { dirname, isAbsolute, resolve } from "node:path";
|
|
24018
|
+
import { dirname as dirname2, isAbsolute, resolve } from "node:path";
|
|
23699
24019
|
var ENV_PATTERN = /\{env:([^}]+)\}/g;
|
|
23700
24020
|
var FILE_PATTERN = /\{file:([^}]+)\}/g;
|
|
23701
24021
|
function substituteConfigVariables(input) {
|
|
@@ -23714,7 +24034,7 @@ function substituteConfigVariables(input) {
|
|
|
23714
24034
|
if (fileMatches.length === 0) {
|
|
23715
24035
|
return { text, warnings };
|
|
23716
24036
|
}
|
|
23717
|
-
const configDir = input.configPath ?
|
|
24037
|
+
const configDir = input.configPath ? dirname2(input.configPath) : process.cwd();
|
|
23718
24038
|
let output = "";
|
|
23719
24039
|
let cursor = 0;
|
|
23720
24040
|
for (const match of fileMatches) {
|
|
@@ -23736,7 +24056,7 @@ function substituteConfigVariables(input) {
|
|
|
23736
24056
|
} else if (!isAbsolute(filePath)) {
|
|
23737
24057
|
filePath = resolve(configDir, filePath);
|
|
23738
24058
|
}
|
|
23739
|
-
if (!
|
|
24059
|
+
if (!existsSync3(filePath)) {
|
|
23740
24060
|
warnings.push(`File not found for ${token} (resolved to ${filePath}); using empty string`);
|
|
23741
24061
|
continue;
|
|
23742
24062
|
}
|
|
@@ -23758,38 +24078,38 @@ function substituteConfigVariables(input) {
|
|
|
23758
24078
|
var import_comment_json = __toESM(require_src2(), 1);
|
|
23759
24079
|
var CONFIG_FILE_NAME = "magic-context";
|
|
23760
24080
|
function getProjectConfigPaths(cwd) {
|
|
23761
|
-
const basePath =
|
|
24081
|
+
const basePath = join6(cwd, ".pi", CONFIG_FILE_NAME);
|
|
23762
24082
|
return [`${basePath}.jsonc`, `${basePath}.json`];
|
|
23763
24083
|
}
|
|
23764
24084
|
function getUserConfigPaths() {
|
|
23765
24085
|
const home = process.env.HOME ?? homedir3();
|
|
23766
|
-
const basePath =
|
|
24086
|
+
const basePath = join6(home, ".pi", "agent", CONFIG_FILE_NAME);
|
|
23767
24087
|
return [`${basePath}.jsonc`, `${basePath}.json`];
|
|
23768
24088
|
}
|
|
23769
24089
|
function resolveFirstExisting(paths) {
|
|
23770
|
-
return paths.find((
|
|
24090
|
+
return paths.find((path4) => existsSync4(path4));
|
|
23771
24091
|
}
|
|
23772
|
-
function loadConfigFile(
|
|
24092
|
+
function loadConfigFile(path4, scope) {
|
|
23773
24093
|
try {
|
|
23774
|
-
const rawText = readFileSync2(
|
|
24094
|
+
const rawText = readFileSync2(path4, "utf-8");
|
|
23775
24095
|
const substituted = substituteConfigVariables({
|
|
23776
24096
|
text: rawText,
|
|
23777
|
-
configPath:
|
|
24097
|
+
configPath: path4
|
|
23778
24098
|
});
|
|
23779
24099
|
return {
|
|
23780
|
-
path:
|
|
24100
|
+
path: path4,
|
|
23781
24101
|
scope,
|
|
23782
24102
|
config: import_comment_json.parse(substituted.text),
|
|
23783
|
-
warnings: substituted.warnings.map((warning) => `${
|
|
24103
|
+
warnings: substituted.warnings.map((warning) => `${path4}: ${warning}`)
|
|
23784
24104
|
};
|
|
23785
24105
|
} catch (error48) {
|
|
23786
24106
|
const message = error48 instanceof Error ? error48.message : String(error48);
|
|
23787
24107
|
return {
|
|
23788
|
-
path:
|
|
24108
|
+
path: path4,
|
|
23789
24109
|
scope,
|
|
23790
24110
|
config: {},
|
|
23791
24111
|
warnings: [
|
|
23792
|
-
`${
|
|
24112
|
+
`${path4}: failed to load config: ${message}; using defaults for this file.`
|
|
23793
24113
|
]
|
|
23794
24114
|
};
|
|
23795
24115
|
}
|
|
@@ -161456,7 +161776,7 @@ init_normalize_hash();
|
|
|
161456
161776
|
// ../plugin/src/features/magic-context/memory/project-identity.ts
|
|
161457
161777
|
import { execSync } from "node:child_process";
|
|
161458
161778
|
import { createHash as createHash2 } from "node:crypto";
|
|
161459
|
-
import
|
|
161779
|
+
import path4 from "node:path";
|
|
161460
161780
|
var GIT_TIMEOUT_MS = 5000;
|
|
161461
161781
|
var resolvedCache = new Map;
|
|
161462
161782
|
function getRootCommitHash(directory) {
|
|
@@ -161475,12 +161795,12 @@ function getRootCommitHash(directory) {
|
|
|
161475
161795
|
}
|
|
161476
161796
|
}
|
|
161477
161797
|
function directoryFallback(directory) {
|
|
161478
|
-
const canonical =
|
|
161798
|
+
const canonical = path4.resolve(directory);
|
|
161479
161799
|
const hash2 = createHash2("md5").update(canonical).digest("hex").slice(0, 12);
|
|
161480
161800
|
return `dir:${hash2}`;
|
|
161481
161801
|
}
|
|
161482
161802
|
function resolveProjectIdentity(directory) {
|
|
161483
|
-
const resolved =
|
|
161803
|
+
const resolved = path4.resolve(directory);
|
|
161484
161804
|
const cached2 = resolvedCache.get(resolved);
|
|
161485
161805
|
if (cached2 !== undefined) {
|
|
161486
161806
|
return cached2;
|
package/package.json
CHANGED