@cortexkit/pi-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/README.md +8 -13
- package/dist/index.js +439 -108
- package/dist/subagent-entry.js +369 -42
- package/package.json +1 -1
package/dist/subagent-entry.js
CHANGED
|
@@ -14064,6 +14064,13 @@ var init_magic_context = __esm(() => {
|
|
|
14064
14064
|
min_clusters: exports_external.number().min(1).default(3)
|
|
14065
14065
|
}).default({ enabled: true, min_clusters: 3 }),
|
|
14066
14066
|
compaction_markers: exports_external.boolean().default(true),
|
|
14067
|
+
system_prompt_injection: exports_external.object({
|
|
14068
|
+
enabled: exports_external.boolean().default(true),
|
|
14069
|
+
skip_signatures: exports_external.array(exports_external.string()).default(["<!-- magic-context: skip -->"])
|
|
14070
|
+
}).default({
|
|
14071
|
+
enabled: true,
|
|
14072
|
+
skip_signatures: ["<!-- magic-context: skip -->"]
|
|
14073
|
+
}),
|
|
14067
14074
|
compressor: exports_external.object({
|
|
14068
14075
|
enabled: exports_external.boolean().default(true),
|
|
14069
14076
|
min_compartment_ratio: exports_external.number().min(100).max(1e4).default(DEFAULT_COMPRESSOR_MIN_COMPARTMENT_RATIO),
|
|
@@ -15036,14 +15043,334 @@ var init_embedding = __esm(() => {
|
|
|
15036
15043
|
SWEEP_MAX_WALL_CLOCK_MS = 10 * 60 * 1000;
|
|
15037
15044
|
});
|
|
15038
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
|
+
|
|
15039
15353
|
// ../plugin/src/shared/sqlite.ts
|
|
15040
|
-
var isBun, bunSpec, betterSpec, sqliteModule, DatabaseImpl, Database;
|
|
15354
|
+
var isBun, bunSpec, betterSpec, electronNativeBinding, sqliteModule, RawDatabaseImpl, DatabaseImpl, Database;
|
|
15041
15355
|
var init_sqlite = __esm(async () => {
|
|
15042
15356
|
isBun = typeof process !== "undefined" && typeof process.versions?.bun === "string";
|
|
15043
15357
|
bunSpec = "bun:" + "sqlite";
|
|
15044
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
|
+
})();
|
|
15045
15363
|
sqliteModule = isBun ? await import(bunSpec) : await import(betterSpec);
|
|
15046
|
-
|
|
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
|
+
};
|
|
15047
15374
|
Database = DatabaseImpl;
|
|
15048
15375
|
});
|
|
15049
15376
|
|
|
@@ -22663,10 +22990,10 @@ var require_stringify = __commonJS((exports, module) => {
|
|
|
22663
22990
|
replacer = null;
|
|
22664
22991
|
indent = EMPTY;
|
|
22665
22992
|
};
|
|
22666
|
-
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;
|
|
22667
22994
|
var join_content = (inside, value, gap) => {
|
|
22668
22995
|
const comment = process_comments(value, PREFIX_BEFORE, gap + indent, true);
|
|
22669
|
-
return
|
|
22996
|
+
return join6(comment, inside, gap);
|
|
22670
22997
|
};
|
|
22671
22998
|
var stringify_string = (holder, key, value) => {
|
|
22672
22999
|
const raw = get_raw_string_literal(holder, key);
|
|
@@ -22688,13 +23015,13 @@ var require_stringify = __commonJS((exports, module) => {
|
|
|
22688
23015
|
if (i !== 0) {
|
|
22689
23016
|
inside += COMMA;
|
|
22690
23017
|
}
|
|
22691
|
-
const before =
|
|
23018
|
+
const before = join6(after_comma, process_comments(value, BEFORE(i), deeper_gap), deeper_gap);
|
|
22692
23019
|
inside += before || LF + deeper_gap;
|
|
22693
23020
|
inside += stringify(i, value, deeper_gap) || STR_NULL;
|
|
22694
23021
|
inside += process_comments(value, AFTER_VALUE(i), deeper_gap);
|
|
22695
23022
|
after_comma = process_comments(value, AFTER(i), deeper_gap);
|
|
22696
23023
|
}
|
|
22697
|
-
inside +=
|
|
23024
|
+
inside += join6(after_comma, process_comments(value, PREFIX_AFTER, deeper_gap), deeper_gap);
|
|
22698
23025
|
return BRACKET_OPEN + join_content(inside, value, gap) + BRACKET_CLOSE;
|
|
22699
23026
|
};
|
|
22700
23027
|
var object_stringify = (value, gap) => {
|
|
@@ -22715,13 +23042,13 @@ var require_stringify = __commonJS((exports, module) => {
|
|
|
22715
23042
|
inside += COMMA;
|
|
22716
23043
|
}
|
|
22717
23044
|
first = false;
|
|
22718
|
-
const before =
|
|
23045
|
+
const before = join6(after_comma, process_comments(value, BEFORE(key), deeper_gap), deeper_gap);
|
|
22719
23046
|
inside += before || LF + deeper_gap;
|
|
22720
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);
|
|
22721
23048
|
after_comma = process_comments(value, AFTER(key), deeper_gap);
|
|
22722
23049
|
};
|
|
22723
23050
|
keys.forEach(iteratee);
|
|
22724
|
-
inside +=
|
|
23051
|
+
inside += join6(after_comma, process_comments(value, PREFIX_AFTER, deeper_gap), deeper_gap);
|
|
22725
23052
|
return CURLY_BRACKET_OPEN + join_content(inside, value, gap) + CURLY_BRACKET_CLOSE;
|
|
22726
23053
|
};
|
|
22727
23054
|
function stringify(key, holder, gap) {
|
|
@@ -22822,9 +23149,9 @@ __export(exports_read_session_db, {
|
|
|
22822
23149
|
findLastAssistantModelFromOpenCodeDb: () => findLastAssistantModelFromOpenCodeDb,
|
|
22823
23150
|
closeReadOnlySessionDb: () => closeReadOnlySessionDb
|
|
22824
23151
|
});
|
|
22825
|
-
import { join as
|
|
23152
|
+
import { join as join7 } from "node:path";
|
|
22826
23153
|
function getOpenCodeDbPath() {
|
|
22827
|
-
return
|
|
23154
|
+
return join7(getDataDir(), "opencode", "opencode.db");
|
|
22828
23155
|
}
|
|
22829
23156
|
function closeCachedReadOnlyDb() {
|
|
22830
23157
|
if (!cachedReadOnlyDb) {
|
|
@@ -22913,8 +23240,8 @@ init_embedding();
|
|
|
22913
23240
|
|
|
22914
23241
|
// ../plugin/src/features/magic-context/storage-db.ts
|
|
22915
23242
|
init_data_path();
|
|
22916
|
-
import { copyFileSync, cpSync, existsSync, mkdirSync as
|
|
22917
|
-
import { join as
|
|
23243
|
+
import { copyFileSync, cpSync, existsSync as existsSync2, mkdirSync as mkdirSync3 } from "node:fs";
|
|
23244
|
+
import { join as join5 } from "node:path";
|
|
22918
23245
|
|
|
22919
23246
|
// ../plugin/src/shared/error-message.ts
|
|
22920
23247
|
function getErrorMessage(error48) {
|
|
@@ -23243,21 +23570,21 @@ var persistenceByDatabase = new WeakMap;
|
|
|
23243
23570
|
var persistenceErrorByDatabase = new WeakMap;
|
|
23244
23571
|
function resolveDatabasePath() {
|
|
23245
23572
|
const dbDir = getMagicContextStorageDir();
|
|
23246
|
-
return { dbDir, dbPath:
|
|
23573
|
+
return { dbDir, dbPath: join5(dbDir, "context.db") };
|
|
23247
23574
|
}
|
|
23248
23575
|
function migrateLegacyStorageIfNeeded(targetDbPath, targetDbDir) {
|
|
23249
|
-
if (
|
|
23576
|
+
if (existsSync2(targetDbPath))
|
|
23250
23577
|
return;
|
|
23251
23578
|
const legacyDir = getLegacyOpenCodeMagicContextStorageDir();
|
|
23252
|
-
const legacyDbPath =
|
|
23253
|
-
if (!
|
|
23579
|
+
const legacyDbPath = join5(legacyDir, "context.db");
|
|
23580
|
+
if (!existsSync2(legacyDbPath))
|
|
23254
23581
|
return;
|
|
23255
23582
|
log(`[magic-context] migrating legacy plugin storage: ${legacyDir} -> ${targetDbDir} (legacy left in place as backup)`);
|
|
23256
|
-
|
|
23583
|
+
mkdirSync3(targetDbDir, { recursive: true });
|
|
23257
23584
|
for (const suffix of ["", "-wal", "-shm"]) {
|
|
23258
23585
|
const src = `${legacyDbPath}${suffix}`;
|
|
23259
|
-
const dst =
|
|
23260
|
-
if (
|
|
23586
|
+
const dst = join5(targetDbDir, `context.db${suffix}`);
|
|
23587
|
+
if (existsSync2(src)) {
|
|
23261
23588
|
try {
|
|
23262
23589
|
copyFileSync(src, dst);
|
|
23263
23590
|
} catch (error48) {
|
|
@@ -23265,9 +23592,9 @@ function migrateLegacyStorageIfNeeded(targetDbPath, targetDbDir) {
|
|
|
23265
23592
|
}
|
|
23266
23593
|
}
|
|
23267
23594
|
}
|
|
23268
|
-
const legacyModelsDir =
|
|
23269
|
-
const targetModelsDir =
|
|
23270
|
-
if (
|
|
23595
|
+
const legacyModelsDir = join5(legacyDir, "models");
|
|
23596
|
+
const targetModelsDir = join5(targetDbDir, "models");
|
|
23597
|
+
if (existsSync2(legacyModelsDir) && !existsSync2(targetModelsDir)) {
|
|
23271
23598
|
try {
|
|
23272
23599
|
cpSync(legacyModelsDir, targetModelsDir, { recursive: true });
|
|
23273
23600
|
} catch (error48) {
|
|
@@ -23647,7 +23974,7 @@ function openDatabase() {
|
|
|
23647
23974
|
}
|
|
23648
23975
|
try {
|
|
23649
23976
|
migrateLegacyStorageIfNeeded(dbPath, dbDir);
|
|
23650
|
-
|
|
23977
|
+
mkdirSync3(dbDir, { recursive: true });
|
|
23651
23978
|
const db = new Database(dbPath);
|
|
23652
23979
|
initializeDatabase(db);
|
|
23653
23980
|
runMigrations(db);
|
|
@@ -23681,14 +24008,14 @@ init_logger();
|
|
|
23681
24008
|
|
|
23682
24009
|
// src/config/index.ts
|
|
23683
24010
|
init_magic_context();
|
|
23684
|
-
import { existsSync as
|
|
24011
|
+
import { existsSync as existsSync4, readFileSync as readFileSync2 } from "node:fs";
|
|
23685
24012
|
import { homedir as homedir3 } from "node:os";
|
|
23686
|
-
import { join as
|
|
24013
|
+
import { join as join6 } from "node:path";
|
|
23687
24014
|
|
|
23688
24015
|
// ../plugin/src/config/variable.ts
|
|
23689
|
-
import { existsSync as
|
|
24016
|
+
import { existsSync as existsSync3, readFileSync } from "node:fs";
|
|
23690
24017
|
import { homedir as homedir2 } from "node:os";
|
|
23691
|
-
import { dirname, isAbsolute, resolve } from "node:path";
|
|
24018
|
+
import { dirname as dirname2, isAbsolute, resolve } from "node:path";
|
|
23692
24019
|
var ENV_PATTERN = /\{env:([^}]+)\}/g;
|
|
23693
24020
|
var FILE_PATTERN = /\{file:([^}]+)\}/g;
|
|
23694
24021
|
function substituteConfigVariables(input) {
|
|
@@ -23707,7 +24034,7 @@ function substituteConfigVariables(input) {
|
|
|
23707
24034
|
if (fileMatches.length === 0) {
|
|
23708
24035
|
return { text, warnings };
|
|
23709
24036
|
}
|
|
23710
|
-
const configDir = input.configPath ?
|
|
24037
|
+
const configDir = input.configPath ? dirname2(input.configPath) : process.cwd();
|
|
23711
24038
|
let output = "";
|
|
23712
24039
|
let cursor = 0;
|
|
23713
24040
|
for (const match of fileMatches) {
|
|
@@ -23729,7 +24056,7 @@ function substituteConfigVariables(input) {
|
|
|
23729
24056
|
} else if (!isAbsolute(filePath)) {
|
|
23730
24057
|
filePath = resolve(configDir, filePath);
|
|
23731
24058
|
}
|
|
23732
|
-
if (!
|
|
24059
|
+
if (!existsSync3(filePath)) {
|
|
23733
24060
|
warnings.push(`File not found for ${token} (resolved to ${filePath}); using empty string`);
|
|
23734
24061
|
continue;
|
|
23735
24062
|
}
|
|
@@ -23751,38 +24078,38 @@ function substituteConfigVariables(input) {
|
|
|
23751
24078
|
var import_comment_json = __toESM(require_src2(), 1);
|
|
23752
24079
|
var CONFIG_FILE_NAME = "magic-context";
|
|
23753
24080
|
function getProjectConfigPaths(cwd) {
|
|
23754
|
-
const basePath =
|
|
24081
|
+
const basePath = join6(cwd, ".pi", CONFIG_FILE_NAME);
|
|
23755
24082
|
return [`${basePath}.jsonc`, `${basePath}.json`];
|
|
23756
24083
|
}
|
|
23757
24084
|
function getUserConfigPaths() {
|
|
23758
24085
|
const home = process.env.HOME ?? homedir3();
|
|
23759
|
-
const basePath =
|
|
24086
|
+
const basePath = join6(home, ".pi", "agent", CONFIG_FILE_NAME);
|
|
23760
24087
|
return [`${basePath}.jsonc`, `${basePath}.json`];
|
|
23761
24088
|
}
|
|
23762
24089
|
function resolveFirstExisting(paths) {
|
|
23763
|
-
return paths.find((
|
|
24090
|
+
return paths.find((path4) => existsSync4(path4));
|
|
23764
24091
|
}
|
|
23765
|
-
function loadConfigFile(
|
|
24092
|
+
function loadConfigFile(path4, scope) {
|
|
23766
24093
|
try {
|
|
23767
|
-
const rawText = readFileSync2(
|
|
24094
|
+
const rawText = readFileSync2(path4, "utf-8");
|
|
23768
24095
|
const substituted = substituteConfigVariables({
|
|
23769
24096
|
text: rawText,
|
|
23770
|
-
configPath:
|
|
24097
|
+
configPath: path4
|
|
23771
24098
|
});
|
|
23772
24099
|
return {
|
|
23773
|
-
path:
|
|
24100
|
+
path: path4,
|
|
23774
24101
|
scope,
|
|
23775
24102
|
config: import_comment_json.parse(substituted.text),
|
|
23776
|
-
warnings: substituted.warnings.map((warning) => `${
|
|
24103
|
+
warnings: substituted.warnings.map((warning) => `${path4}: ${warning}`)
|
|
23777
24104
|
};
|
|
23778
24105
|
} catch (error48) {
|
|
23779
24106
|
const message = error48 instanceof Error ? error48.message : String(error48);
|
|
23780
24107
|
return {
|
|
23781
|
-
path:
|
|
24108
|
+
path: path4,
|
|
23782
24109
|
scope,
|
|
23783
24110
|
config: {},
|
|
23784
24111
|
warnings: [
|
|
23785
|
-
`${
|
|
24112
|
+
`${path4}: failed to load config: ${message}; using defaults for this file.`
|
|
23786
24113
|
]
|
|
23787
24114
|
};
|
|
23788
24115
|
}
|
|
@@ -161449,7 +161776,7 @@ init_normalize_hash();
|
|
|
161449
161776
|
// ../plugin/src/features/magic-context/memory/project-identity.ts
|
|
161450
161777
|
import { execSync } from "node:child_process";
|
|
161451
161778
|
import { createHash as createHash2 } from "node:crypto";
|
|
161452
|
-
import
|
|
161779
|
+
import path4 from "node:path";
|
|
161453
161780
|
var GIT_TIMEOUT_MS = 5000;
|
|
161454
161781
|
var resolvedCache = new Map;
|
|
161455
161782
|
function getRootCommitHash(directory) {
|
|
@@ -161468,12 +161795,12 @@ function getRootCommitHash(directory) {
|
|
|
161468
161795
|
}
|
|
161469
161796
|
}
|
|
161470
161797
|
function directoryFallback(directory) {
|
|
161471
|
-
const canonical =
|
|
161798
|
+
const canonical = path4.resolve(directory);
|
|
161472
161799
|
const hash2 = createHash2("md5").update(canonical).digest("hex").slice(0, 12);
|
|
161473
161800
|
return `dir:${hash2}`;
|
|
161474
161801
|
}
|
|
161475
161802
|
function resolveProjectIdentity(directory) {
|
|
161476
|
-
const resolved =
|
|
161803
|
+
const resolved = path4.resolve(directory);
|
|
161477
161804
|
const cached2 = resolvedCache.get(resolved);
|
|
161478
161805
|
if (cached2 !== undefined) {
|
|
161479
161806
|
return cached2;
|
package/package.json
CHANGED