@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/index.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(path4) {
|
|
15147
|
+
let normalized = path4.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 (path4.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 path4 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 = path4.dirname(pkgJsonPath);
|
|
15260
|
+
const pkgJson = requireFn(pkgJsonPath);
|
|
15261
|
+
const binaryPath = path4.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 path4.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(path4.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
|
|
|
@@ -15072,9 +15392,9 @@ __export(exports_read_session_db, {
|
|
|
15072
15392
|
findLastAssistantModelFromOpenCodeDb: () => findLastAssistantModelFromOpenCodeDb,
|
|
15073
15393
|
closeReadOnlySessionDb: () => closeReadOnlySessionDb
|
|
15074
15394
|
});
|
|
15075
|
-
import { join as
|
|
15395
|
+
import { join as join5 } from "node:path";
|
|
15076
15396
|
function getOpenCodeDbPath() {
|
|
15077
|
-
return
|
|
15397
|
+
return join5(getDataDir(), "opencode", "opencode.db");
|
|
15078
15398
|
}
|
|
15079
15399
|
function closeCachedReadOnlyDb() {
|
|
15080
15400
|
if (!cachedReadOnlyDb) {
|
|
@@ -22792,10 +23112,10 @@ var require_stringify = __commonJS((exports, module) => {
|
|
|
22792
23112
|
replacer = null;
|
|
22793
23113
|
indent = EMPTY;
|
|
22794
23114
|
};
|
|
22795
|
-
var
|
|
23115
|
+
var join12 = (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;
|
|
22796
23116
|
var join_content = (inside, value, gap) => {
|
|
22797
23117
|
const comment = process_comments(value, PREFIX_BEFORE, gap + indent, true);
|
|
22798
|
-
return
|
|
23118
|
+
return join12(comment, inside, gap);
|
|
22799
23119
|
};
|
|
22800
23120
|
var stringify_string = (holder, key, value) => {
|
|
22801
23121
|
const raw = get_raw_string_literal(holder, key);
|
|
@@ -22817,13 +23137,13 @@ var require_stringify = __commonJS((exports, module) => {
|
|
|
22817
23137
|
if (i !== 0) {
|
|
22818
23138
|
inside += COMMA;
|
|
22819
23139
|
}
|
|
22820
|
-
const before =
|
|
23140
|
+
const before = join12(after_comma, process_comments(value, BEFORE(i), deeper_gap), deeper_gap);
|
|
22821
23141
|
inside += before || LF + deeper_gap;
|
|
22822
23142
|
inside += stringify(i, value, deeper_gap) || STR_NULL;
|
|
22823
23143
|
inside += process_comments(value, AFTER_VALUE(i), deeper_gap);
|
|
22824
23144
|
after_comma = process_comments(value, AFTER(i), deeper_gap);
|
|
22825
23145
|
}
|
|
22826
|
-
inside +=
|
|
23146
|
+
inside += join12(after_comma, process_comments(value, PREFIX_AFTER, deeper_gap), deeper_gap);
|
|
22827
23147
|
return BRACKET_OPEN + join_content(inside, value, gap) + BRACKET_CLOSE;
|
|
22828
23148
|
};
|
|
22829
23149
|
var object_stringify = (value, gap) => {
|
|
@@ -22844,13 +23164,13 @@ var require_stringify = __commonJS((exports, module) => {
|
|
|
22844
23164
|
inside += COMMA;
|
|
22845
23165
|
}
|
|
22846
23166
|
first = false;
|
|
22847
|
-
const before =
|
|
23167
|
+
const before = join12(after_comma, process_comments(value, BEFORE(key), deeper_gap), deeper_gap);
|
|
22848
23168
|
inside += before || LF + deeper_gap;
|
|
22849
23169
|
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);
|
|
22850
23170
|
after_comma = process_comments(value, AFTER(key), deeper_gap);
|
|
22851
23171
|
};
|
|
22852
23172
|
keys.forEach(iteratee);
|
|
22853
|
-
inside +=
|
|
23173
|
+
inside += join12(after_comma, process_comments(value, PREFIX_AFTER, deeper_gap), deeper_gap);
|
|
22854
23174
|
return CURLY_BRACKET_OPEN + join_content(inside, value, gap) + CURLY_BRACKET_CLOSE;
|
|
22855
23175
|
};
|
|
22856
23176
|
function stringify(key, holder, gap) {
|
|
@@ -22944,8 +23264,8 @@ var require_src2 = __commonJS((exports, module) => {
|
|
|
22944
23264
|
|
|
22945
23265
|
// src/index.ts
|
|
22946
23266
|
init_embedding();
|
|
22947
|
-
import { createRequire } from "node:module";
|
|
22948
|
-
import { join as
|
|
23267
|
+
import { createRequire as createRequire2 } from "node:module";
|
|
23268
|
+
import { join as join14 } from "node:path";
|
|
22949
23269
|
|
|
22950
23270
|
// ../plugin/src/features/magic-context/memory/project-identity.ts
|
|
22951
23271
|
import { execSync } from "node:child_process";
|
|
@@ -156428,8 +156748,8 @@ function ensureMessagesIndexed(db, sessionId, readMessages) {
|
|
|
156428
156748
|
}
|
|
156429
156749
|
// ../plugin/src/features/magic-context/storage-db.ts
|
|
156430
156750
|
init_data_path();
|
|
156431
|
-
import { copyFileSync, cpSync, existsSync, mkdirSync as
|
|
156432
|
-
import { join as
|
|
156751
|
+
import { copyFileSync, cpSync, existsSync as existsSync2, mkdirSync as mkdirSync3 } from "node:fs";
|
|
156752
|
+
import { join as join6 } from "node:path";
|
|
156433
156753
|
|
|
156434
156754
|
// ../plugin/src/shared/error-message.ts
|
|
156435
156755
|
function getErrorMessage(error48) {
|
|
@@ -156758,21 +157078,21 @@ var persistenceByDatabase = new WeakMap;
|
|
|
156758
157078
|
var persistenceErrorByDatabase = new WeakMap;
|
|
156759
157079
|
function resolveDatabasePath() {
|
|
156760
157080
|
const dbDir = getMagicContextStorageDir();
|
|
156761
|
-
return { dbDir, dbPath:
|
|
157081
|
+
return { dbDir, dbPath: join6(dbDir, "context.db") };
|
|
156762
157082
|
}
|
|
156763
157083
|
function migrateLegacyStorageIfNeeded(targetDbPath, targetDbDir) {
|
|
156764
|
-
if (
|
|
157084
|
+
if (existsSync2(targetDbPath))
|
|
156765
157085
|
return;
|
|
156766
157086
|
const legacyDir = getLegacyOpenCodeMagicContextStorageDir();
|
|
156767
|
-
const legacyDbPath =
|
|
156768
|
-
if (!
|
|
157087
|
+
const legacyDbPath = join6(legacyDir, "context.db");
|
|
157088
|
+
if (!existsSync2(legacyDbPath))
|
|
156769
157089
|
return;
|
|
156770
157090
|
log(`[magic-context] migrating legacy plugin storage: ${legacyDir} -> ${targetDbDir} (legacy left in place as backup)`);
|
|
156771
|
-
|
|
157091
|
+
mkdirSync3(targetDbDir, { recursive: true });
|
|
156772
157092
|
for (const suffix of ["", "-wal", "-shm"]) {
|
|
156773
157093
|
const src = `${legacyDbPath}${suffix}`;
|
|
156774
|
-
const dst =
|
|
156775
|
-
if (
|
|
157094
|
+
const dst = join6(targetDbDir, `context.db${suffix}`);
|
|
157095
|
+
if (existsSync2(src)) {
|
|
156776
157096
|
try {
|
|
156777
157097
|
copyFileSync(src, dst);
|
|
156778
157098
|
} catch (error48) {
|
|
@@ -156780,9 +157100,9 @@ function migrateLegacyStorageIfNeeded(targetDbPath, targetDbDir) {
|
|
|
156780
157100
|
}
|
|
156781
157101
|
}
|
|
156782
157102
|
}
|
|
156783
|
-
const legacyModelsDir =
|
|
156784
|
-
const targetModelsDir =
|
|
156785
|
-
if (
|
|
157103
|
+
const legacyModelsDir = join6(legacyDir, "models");
|
|
157104
|
+
const targetModelsDir = join6(targetDbDir, "models");
|
|
157105
|
+
if (existsSync2(legacyModelsDir) && !existsSync2(targetModelsDir)) {
|
|
156786
157106
|
try {
|
|
156787
157107
|
cpSync(legacyModelsDir, targetModelsDir, { recursive: true });
|
|
156788
157108
|
} catch (error48) {
|
|
@@ -157162,7 +157482,7 @@ function openDatabase() {
|
|
|
157162
157482
|
}
|
|
157163
157483
|
try {
|
|
157164
157484
|
migrateLegacyStorageIfNeeded(dbPath, dbDir);
|
|
157165
|
-
|
|
157485
|
+
mkdirSync3(dbDir, { recursive: true });
|
|
157166
157486
|
const db = new Database(dbPath);
|
|
157167
157487
|
initializeDatabase(db);
|
|
157168
157488
|
runMigrations(db);
|
|
@@ -157958,9 +158278,9 @@ function expandFallbackChain(chain) {
|
|
|
157958
158278
|
init_data_path();
|
|
157959
158279
|
init_logger();
|
|
157960
158280
|
import { createHash as createHash3 } from "node:crypto";
|
|
157961
|
-
import { existsSync as
|
|
158281
|
+
import { existsSync as existsSync3, readFileSync } from "node:fs";
|
|
157962
158282
|
import { homedir as homedir2, platform } from "node:os";
|
|
157963
|
-
import { join as
|
|
158283
|
+
import { join as join7 } from "node:path";
|
|
157964
158284
|
var RELOAD_INTERVAL_MS = 5 * 60 * 1000;
|
|
157965
158285
|
var apiCache = null;
|
|
157966
158286
|
var fileCache = null;
|
|
@@ -157975,16 +158295,16 @@ function getModelsJsonPath() {
|
|
|
157975
158295
|
const cacheBase = getCacheDir();
|
|
157976
158296
|
const source = process.env.OPENCODE_MODELS_URL?.trim();
|
|
157977
158297
|
const filename = source && source !== "https://models.dev" ? `models-${hashFast(source)}.json` : "models.json";
|
|
157978
|
-
return
|
|
158298
|
+
return join7(cacheBase, "opencode", filename);
|
|
157979
158299
|
}
|
|
157980
158300
|
function getOpencodeConfigPath() {
|
|
157981
158301
|
const envDir = process.env.OPENCODE_CONFIG_DIR?.trim();
|
|
157982
|
-
const configDir = envDir ? envDir : platform() === "win32" ?
|
|
157983
|
-
const jsonc =
|
|
157984
|
-
if (
|
|
158302
|
+
const configDir = envDir ? envDir : platform() === "win32" ? join7(homedir2(), ".config", "opencode") : join7(process.env.XDG_CONFIG_HOME || join7(homedir2(), ".config"), "opencode");
|
|
158303
|
+
const jsonc = join7(configDir, "opencode.jsonc");
|
|
158304
|
+
if (existsSync3(jsonc))
|
|
157985
158305
|
return jsonc;
|
|
157986
|
-
const json2 =
|
|
157987
|
-
if (
|
|
158306
|
+
const json2 = join7(configDir, "opencode.json");
|
|
158307
|
+
if (existsSync3(json2))
|
|
157988
158308
|
return json2;
|
|
157989
158309
|
return null;
|
|
157990
158310
|
}
|
|
@@ -158027,7 +158347,7 @@ function loadModelsDevMetadataFromFile() {
|
|
|
158027
158347
|
const modelsJsonPath = getModelsJsonPath();
|
|
158028
158348
|
let fileFound = false;
|
|
158029
158349
|
try {
|
|
158030
|
-
if (
|
|
158350
|
+
if (existsSync3(modelsJsonPath)) {
|
|
158031
158351
|
fileFound = true;
|
|
158032
158352
|
const raw = readFileSync(modelsJsonPath, "utf-8");
|
|
158033
158353
|
const data = JSON.parse(raw);
|
|
@@ -158044,7 +158364,7 @@ function loadModelsDevMetadataFromFile() {
|
|
|
158044
158364
|
}
|
|
158045
158365
|
try {
|
|
158046
158366
|
const configPath = getOpencodeConfigPath();
|
|
158047
|
-
if (configPath &&
|
|
158367
|
+
if (configPath && existsSync3(configPath)) {
|
|
158048
158368
|
let raw = readFileSync(configPath, "utf-8");
|
|
158049
158369
|
raw = raw.replace(/"(?:[^"\\]|\\.)*"|\/\/.*$/gm, (match) => match.startsWith('"') ? match : "");
|
|
158050
158370
|
const config2 = JSON.parse(raw);
|
|
@@ -158387,15 +158707,15 @@ init_logger();
|
|
|
158387
158707
|
|
|
158388
158708
|
// src/subagent-runner.ts
|
|
158389
158709
|
import * as childProcess from "node:child_process";
|
|
158390
|
-
import { existsSync as
|
|
158391
|
-
import { dirname, resolve as resolvePath } from "node:path";
|
|
158710
|
+
import { existsSync as existsSync4 } from "node:fs";
|
|
158711
|
+
import { dirname as dirname2, resolve as resolvePath } from "node:path";
|
|
158392
158712
|
import { createInterface } from "node:readline";
|
|
158393
158713
|
import { fileURLToPath } from "node:url";
|
|
158394
158714
|
function resolveSubagentEntryPath() {
|
|
158395
158715
|
try {
|
|
158396
|
-
const here =
|
|
158716
|
+
const here = dirname2(fileURLToPath(import.meta.url));
|
|
158397
158717
|
const candidate = resolvePath(here, "subagent-entry.js");
|
|
158398
|
-
if (
|
|
158718
|
+
if (existsSync4(candidate))
|
|
158399
158719
|
return candidate;
|
|
158400
158720
|
return;
|
|
158401
158721
|
} catch {
|
|
@@ -158994,8 +159314,8 @@ function releaseLease(db, holderId) {
|
|
|
158994
159314
|
})();
|
|
158995
159315
|
}
|
|
158996
159316
|
// ../plugin/src/features/magic-context/dreamer/runner.ts
|
|
158997
|
-
import { existsSync as
|
|
158998
|
-
import { join as
|
|
159317
|
+
import { existsSync as existsSync5 } from "node:fs";
|
|
159318
|
+
import { join as join8 } from "node:path";
|
|
158999
159319
|
|
|
159000
159320
|
// ../plugin/src/shared/index.ts
|
|
159001
159321
|
init_logger();
|
|
@@ -160393,11 +160713,11 @@ function countNewIds(beforeIds, afterIds) {
|
|
|
160393
160713
|
return count;
|
|
160394
160714
|
}
|
|
160395
160715
|
function getOpenCodeDbPath2() {
|
|
160396
|
-
return
|
|
160716
|
+
return join8(getDataDir(), "opencode", "opencode.db");
|
|
160397
160717
|
}
|
|
160398
160718
|
function openOpenCodeDb() {
|
|
160399
160719
|
const dbPath = getOpenCodeDbPath2();
|
|
160400
|
-
if (!
|
|
160720
|
+
if (!existsSync5(dbPath)) {
|
|
160401
160721
|
log(`[key-files] OpenCode DB not found at ${dbPath} — skipping`);
|
|
160402
160722
|
return null;
|
|
160403
160723
|
}
|
|
@@ -160647,8 +160967,8 @@ async function runDream(args) {
|
|
|
160647
160967
|
try {
|
|
160648
160968
|
const docsDir = args.sessionDirectory ?? args.projectIdentity;
|
|
160649
160969
|
const existingDocs = taskName === "maintain-docs" ? {
|
|
160650
|
-
architecture:
|
|
160651
|
-
structure:
|
|
160970
|
+
architecture: existsSync5(join8(docsDir, "ARCHITECTURE.md")),
|
|
160971
|
+
structure: existsSync5(join8(docsDir, "STRUCTURE.md"))
|
|
160652
160972
|
} : undefined;
|
|
160653
160973
|
const userMemories = taskName === "archive-stale" ? getActiveUserMemories(args.db).map((um) => ({
|
|
160654
160974
|
id: um.id,
|
|
@@ -165812,28 +166132,28 @@ function getReducedRecompTokenBudget(currentBudget) {
|
|
|
165812
166132
|
}
|
|
165813
166133
|
|
|
165814
166134
|
// ../plugin/src/hooks/magic-context/historian-state-file.ts
|
|
165815
|
-
import { mkdirSync as
|
|
166135
|
+
import { mkdirSync as mkdirSync4, unlinkSync, writeFileSync as writeFileSync2 } from "node:fs";
|
|
165816
166136
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
165817
|
-
import { join as
|
|
166137
|
+
import { join as join9 } from "node:path";
|
|
165818
166138
|
var HISTORIAN_STATE_INLINE_THRESHOLD = 30000;
|
|
165819
|
-
var HISTORIAN_STATE_DIR =
|
|
166139
|
+
var HISTORIAN_STATE_DIR = join9(tmpdir2(), "magic-context-historian");
|
|
165820
166140
|
function maybeWriteHistorianStateFile(sessionId, existingState) {
|
|
165821
166141
|
if (existingState.length <= HISTORIAN_STATE_INLINE_THRESHOLD)
|
|
165822
166142
|
return;
|
|
165823
166143
|
try {
|
|
165824
|
-
|
|
165825
|
-
const
|
|
165826
|
-
|
|
165827
|
-
return
|
|
166144
|
+
mkdirSync4(HISTORIAN_STATE_DIR, { recursive: true });
|
|
166145
|
+
const path5 = join9(HISTORIAN_STATE_DIR, `state-${sessionId}-${Date.now()}.xml`);
|
|
166146
|
+
writeFileSync2(path5, existingState, "utf8");
|
|
166147
|
+
return path5;
|
|
165828
166148
|
} catch {
|
|
165829
166149
|
return;
|
|
165830
166150
|
}
|
|
165831
166151
|
}
|
|
165832
|
-
function cleanupHistorianStateFile(
|
|
165833
|
-
if (!
|
|
166152
|
+
function cleanupHistorianStateFile(path5) {
|
|
166153
|
+
if (!path5)
|
|
165834
166154
|
return;
|
|
165835
166155
|
try {
|
|
165836
|
-
unlinkSync(
|
|
166156
|
+
unlinkSync(path5);
|
|
165837
166157
|
} catch {}
|
|
165838
166158
|
}
|
|
165839
166159
|
|
|
@@ -168038,7 +168358,7 @@ init_logger();
|
|
|
168038
168358
|
init_data_path();
|
|
168039
168359
|
init_logger();
|
|
168040
168360
|
await init_sqlite();
|
|
168041
|
-
import { join as
|
|
168361
|
+
import { join as join10 } from "node:path";
|
|
168042
168362
|
var BASE62_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
168043
168363
|
function randomBase62(length) {
|
|
168044
168364
|
const chars = [];
|
|
@@ -168059,7 +168379,7 @@ function generatePartId(timestampMs, counter = 0n) {
|
|
|
168059
168379
|
return generateId("prt", timestampMs, counter);
|
|
168060
168380
|
}
|
|
168061
168381
|
function getOpenCodeDbPath3() {
|
|
168062
|
-
return
|
|
168382
|
+
return join10(getDataDir(), "opencode", "opencode.db");
|
|
168063
168383
|
}
|
|
168064
168384
|
var cachedWriteDb = null;
|
|
168065
168385
|
var REQUIRED_MESSAGE_COLUMNS = ["id", "session_id", "time_created", "time_updated", "data"];
|
|
@@ -168612,11 +168932,11 @@ async function runCompressorPass2(args) {
|
|
|
168612
168932
|
}
|
|
168613
168933
|
|
|
168614
168934
|
// ../plugin/src/hooks/magic-context/compartment-runner-historian.ts
|
|
168615
|
-
import { mkdirSync as
|
|
168935
|
+
import { mkdirSync as mkdirSync5, unlinkSync as unlinkSync2, writeFileSync as writeFileSync3 } from "node:fs";
|
|
168616
168936
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
168617
|
-
import { join as
|
|
168937
|
+
import { join as join11 } from "node:path";
|
|
168618
168938
|
init_magic_context();
|
|
168619
|
-
var HISTORIAN_RESPONSE_DUMP_DIR =
|
|
168939
|
+
var HISTORIAN_RESPONSE_DUMP_DIR = join11(tmpdir3(), "magic-context-historian");
|
|
168620
168940
|
var MAX_HISTORIAN_RETRIES = 2;
|
|
168621
168941
|
async function runValidatedHistorianPass(args) {
|
|
168622
168942
|
const firstRun = await runHistorianPrompt({
|
|
@@ -168857,11 +169177,11 @@ function cleanupHistorianDump(sessionId, dumpPath) {
|
|
|
168857
169177
|
}
|
|
168858
169178
|
function dumpHistorianResponse(sessionId, label, text) {
|
|
168859
169179
|
try {
|
|
168860
|
-
|
|
169180
|
+
mkdirSync5(HISTORIAN_RESPONSE_DUMP_DIR, { recursive: true });
|
|
168861
169181
|
const safeSessionId = sanitizeDumpName(sessionId);
|
|
168862
169182
|
const safeLabel = sanitizeDumpName(label);
|
|
168863
|
-
const dumpPath =
|
|
168864
|
-
|
|
169183
|
+
const dumpPath = join11(HISTORIAN_RESPONSE_DUMP_DIR, `${safeSessionId}-${safeLabel}-${Date.now()}.xml`);
|
|
169184
|
+
writeFileSync3(dumpPath, text, "utf8");
|
|
168865
169185
|
sessionLog(sessionId, "compartment agent: historian response dumped", {
|
|
168866
169186
|
label,
|
|
168867
169187
|
dumpPath
|
|
@@ -169872,8 +170192,8 @@ function createPiRecompClient(args) {
|
|
|
169872
170192
|
function readPathId(input) {
|
|
169873
170193
|
if (typeof input !== "object" || input === null)
|
|
169874
170194
|
return "";
|
|
169875
|
-
const
|
|
169876
|
-
return typeof
|
|
170195
|
+
const path5 = input.path;
|
|
170196
|
+
return typeof path5?.id === "string" ? path5.id : "";
|
|
169877
170197
|
}
|
|
169878
170198
|
function readBody(input) {
|
|
169879
170199
|
if (typeof input !== "object" || input === null)
|
|
@@ -170028,7 +170348,7 @@ import {
|
|
|
170028
170348
|
// package.json
|
|
170029
170349
|
var package_default = {
|
|
170030
170350
|
name: "@cortexkit/pi-magic-context",
|
|
170031
|
-
version: "0.16.
|
|
170351
|
+
version: "0.16.3",
|
|
170032
170352
|
type: "module",
|
|
170033
170353
|
description: "Pi coding agent extension for Magic Context — cross-session memory and context management",
|
|
170034
170354
|
main: "dist/index.js",
|
|
@@ -170565,14 +170885,14 @@ function readHistorianState(db, sessionId, meta3) {
|
|
|
170565
170885
|
|
|
170566
170886
|
// src/config/index.ts
|
|
170567
170887
|
init_magic_context();
|
|
170568
|
-
import { existsSync as
|
|
170888
|
+
import { existsSync as existsSync7, readFileSync as readFileSync3 } from "node:fs";
|
|
170569
170889
|
import { homedir as homedir4 } from "node:os";
|
|
170570
|
-
import { join as
|
|
170890
|
+
import { join as join12 } from "node:path";
|
|
170571
170891
|
|
|
170572
170892
|
// ../plugin/src/config/variable.ts
|
|
170573
|
-
import { existsSync as
|
|
170893
|
+
import { existsSync as existsSync6, readFileSync as readFileSync2 } from "node:fs";
|
|
170574
170894
|
import { homedir as homedir3 } from "node:os";
|
|
170575
|
-
import { dirname as
|
|
170895
|
+
import { dirname as dirname3, isAbsolute, resolve } from "node:path";
|
|
170576
170896
|
var ENV_PATTERN = /\{env:([^}]+)\}/g;
|
|
170577
170897
|
var FILE_PATTERN = /\{file:([^}]+)\}/g;
|
|
170578
170898
|
function substituteConfigVariables(input) {
|
|
@@ -170591,7 +170911,7 @@ function substituteConfigVariables(input) {
|
|
|
170591
170911
|
if (fileMatches.length === 0) {
|
|
170592
170912
|
return { text, warnings };
|
|
170593
170913
|
}
|
|
170594
|
-
const configDir = input.configPath ?
|
|
170914
|
+
const configDir = input.configPath ? dirname3(input.configPath) : process.cwd();
|
|
170595
170915
|
let output = "";
|
|
170596
170916
|
let cursor = 0;
|
|
170597
170917
|
for (const match of fileMatches) {
|
|
@@ -170613,7 +170933,7 @@ function substituteConfigVariables(input) {
|
|
|
170613
170933
|
} else if (!isAbsolute(filePath)) {
|
|
170614
170934
|
filePath = resolve(configDir, filePath);
|
|
170615
170935
|
}
|
|
170616
|
-
if (!
|
|
170936
|
+
if (!existsSync6(filePath)) {
|
|
170617
170937
|
warnings.push(`File not found for ${token} (resolved to ${filePath}); using empty string`);
|
|
170618
170938
|
continue;
|
|
170619
170939
|
}
|
|
@@ -170635,38 +170955,38 @@ function substituteConfigVariables(input) {
|
|
|
170635
170955
|
var import_comment_json = __toESM(require_src2(), 1);
|
|
170636
170956
|
var CONFIG_FILE_NAME = "magic-context";
|
|
170637
170957
|
function getProjectConfigPaths(cwd) {
|
|
170638
|
-
const basePath =
|
|
170958
|
+
const basePath = join12(cwd, ".pi", CONFIG_FILE_NAME);
|
|
170639
170959
|
return [`${basePath}.jsonc`, `${basePath}.json`];
|
|
170640
170960
|
}
|
|
170641
170961
|
function getUserConfigPaths() {
|
|
170642
170962
|
const home = process.env.HOME ?? homedir4();
|
|
170643
|
-
const basePath =
|
|
170963
|
+
const basePath = join12(home, ".pi", "agent", CONFIG_FILE_NAME);
|
|
170644
170964
|
return [`${basePath}.jsonc`, `${basePath}.json`];
|
|
170645
170965
|
}
|
|
170646
170966
|
function resolveFirstExisting(paths) {
|
|
170647
|
-
return paths.find((
|
|
170967
|
+
return paths.find((path5) => existsSync7(path5));
|
|
170648
170968
|
}
|
|
170649
|
-
function loadConfigFile(
|
|
170969
|
+
function loadConfigFile(path5, scope) {
|
|
170650
170970
|
try {
|
|
170651
|
-
const rawText = readFileSync3(
|
|
170971
|
+
const rawText = readFileSync3(path5, "utf-8");
|
|
170652
170972
|
const substituted = substituteConfigVariables({
|
|
170653
170973
|
text: rawText,
|
|
170654
|
-
configPath:
|
|
170974
|
+
configPath: path5
|
|
170655
170975
|
});
|
|
170656
170976
|
return {
|
|
170657
|
-
path:
|
|
170977
|
+
path: path5,
|
|
170658
170978
|
scope,
|
|
170659
170979
|
config: import_comment_json.parse(substituted.text),
|
|
170660
|
-
warnings: substituted.warnings.map((warning) => `${
|
|
170980
|
+
warnings: substituted.warnings.map((warning) => `${path5}: ${warning}`)
|
|
170661
170981
|
};
|
|
170662
170982
|
} catch (error48) {
|
|
170663
170983
|
const message = error48 instanceof Error ? error48.message : String(error48);
|
|
170664
170984
|
return {
|
|
170665
|
-
path:
|
|
170985
|
+
path: path5,
|
|
170666
170986
|
scope,
|
|
170667
170987
|
config: {},
|
|
170668
170988
|
warnings: [
|
|
170669
|
-
`${
|
|
170989
|
+
`${path5}: failed to load config: ${message}; using defaults for this file.`
|
|
170670
170990
|
]
|
|
170671
170991
|
};
|
|
170672
170992
|
}
|
|
@@ -170796,8 +171116,8 @@ function stripTagPrefixFromAssistantMessage(message) {
|
|
|
170796
171116
|
|
|
170797
171117
|
// src/system-prompt.ts
|
|
170798
171118
|
import { createHash as createHash4 } from "node:crypto";
|
|
170799
|
-
import { existsSync as
|
|
170800
|
-
import { join as
|
|
171119
|
+
import { existsSync as existsSync8, readFileSync as readFileSync4, realpathSync } from "node:fs";
|
|
171120
|
+
import { join as join13, resolve as resolve2, sep } from "node:path";
|
|
170801
171121
|
|
|
170802
171122
|
// ../plugin/src/agents/magic-context-prompt.ts
|
|
170803
171123
|
function getToolHistoryGuidance(dropToolStructure) {
|
|
@@ -170899,9 +171219,9 @@ var DOC_FILES = ["ARCHITECTURE.md", "STRUCTURE.md"];
|
|
|
170899
171219
|
function readProjectDocs(directory) {
|
|
170900
171220
|
const sections = [];
|
|
170901
171221
|
for (const filename of DOC_FILES) {
|
|
170902
|
-
const filePath =
|
|
171222
|
+
const filePath = join13(directory, filename);
|
|
170903
171223
|
try {
|
|
170904
|
-
if (
|
|
171224
|
+
if (existsSync8(filePath)) {
|
|
170905
171225
|
const content = readFileSync4(filePath, "utf-8").trim();
|
|
170906
171226
|
if (content.length > 0) {
|
|
170907
171227
|
sections.push(`<${filename}>
|
|
@@ -170945,7 +171265,7 @@ function buildKeyFilesBlock(db, sessionId, directory, tokenBudget) {
|
|
|
170945
171265
|
log(`[magic-context-pi] key file path escapes project root, skipping: ${entry.filePath}`);
|
|
170946
171266
|
continue;
|
|
170947
171267
|
}
|
|
170948
|
-
if (!
|
|
171268
|
+
if (!existsSync8(absPath))
|
|
170949
171269
|
continue;
|
|
170950
171270
|
let realPath;
|
|
170951
171271
|
try {
|
|
@@ -176022,7 +176342,7 @@ function registerMagicContextTools(pi, opts) {
|
|
|
176022
176342
|
}
|
|
176023
176343
|
|
|
176024
176344
|
// src/index.ts
|
|
176025
|
-
var
|
|
176345
|
+
var PREFIX2 = "[magic-context][pi]";
|
|
176026
176346
|
function persistPiMessageEndModelMeta(args) {
|
|
176027
176347
|
if (!args.message || typeof args.message !== "object")
|
|
176028
176348
|
return;
|
|
@@ -176039,14 +176359,14 @@ function persistPiMessageEndModelMeta(args) {
|
|
|
176039
176359
|
}
|
|
176040
176360
|
}
|
|
176041
176361
|
function info(message, data) {
|
|
176042
|
-
log(`${
|
|
176362
|
+
log(`${PREFIX2} ${message}`, data);
|
|
176043
176363
|
}
|
|
176044
176364
|
function warn(message, data) {
|
|
176045
|
-
log(`${
|
|
176365
|
+
log(`${PREFIX2} WARN ${message}`, data);
|
|
176046
176366
|
}
|
|
176047
176367
|
var PLUGIN_VERSION = (() => {
|
|
176048
176368
|
try {
|
|
176049
|
-
const req =
|
|
176369
|
+
const req = createRequire2(import.meta.url);
|
|
176050
176370
|
return req("../package.json").version;
|
|
176051
176371
|
} catch {
|
|
176052
176372
|
return "0.0.0";
|
|
@@ -176127,7 +176447,7 @@ function resolveDreamerFromConfig(config2) {
|
|
|
176127
176447
|
}
|
|
176128
176448
|
async function src_default2(pi) {
|
|
176129
176449
|
const storageDir = getMagicContextStorageDir();
|
|
176130
|
-
const dbPath =
|
|
176450
|
+
const dbPath = join14(storageDir, "context.db");
|
|
176131
176451
|
let db;
|
|
176132
176452
|
try {
|
|
176133
176453
|
db = openDatabase();
|