@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/dist/index.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(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
+
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
- DatabaseImpl = isBun ? sqliteModule.Database : sqliteModule.default;
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
 
@@ -15065,9 +15392,9 @@ __export(exports_read_session_db, {
15065
15392
  findLastAssistantModelFromOpenCodeDb: () => findLastAssistantModelFromOpenCodeDb,
15066
15393
  closeReadOnlySessionDb: () => closeReadOnlySessionDb
15067
15394
  });
15068
- import { join as join4 } from "node:path";
15395
+ import { join as join5 } from "node:path";
15069
15396
  function getOpenCodeDbPath() {
15070
- return join4(getDataDir(), "opencode", "opencode.db");
15397
+ return join5(getDataDir(), "opencode", "opencode.db");
15071
15398
  }
15072
15399
  function closeCachedReadOnlyDb() {
15073
15400
  if (!cachedReadOnlyDb) {
@@ -22785,10 +23112,10 @@ var require_stringify = __commonJS((exports, module) => {
22785
23112
  replacer = null;
22786
23113
  indent = EMPTY;
22787
23114
  };
22788
- var join11 = (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;
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;
22789
23116
  var join_content = (inside, value, gap) => {
22790
23117
  const comment = process_comments(value, PREFIX_BEFORE, gap + indent, true);
22791
- return join11(comment, inside, gap);
23118
+ return join12(comment, inside, gap);
22792
23119
  };
22793
23120
  var stringify_string = (holder, key, value) => {
22794
23121
  const raw = get_raw_string_literal(holder, key);
@@ -22810,13 +23137,13 @@ var require_stringify = __commonJS((exports, module) => {
22810
23137
  if (i !== 0) {
22811
23138
  inside += COMMA;
22812
23139
  }
22813
- const before = join11(after_comma, process_comments(value, BEFORE(i), deeper_gap), deeper_gap);
23140
+ const before = join12(after_comma, process_comments(value, BEFORE(i), deeper_gap), deeper_gap);
22814
23141
  inside += before || LF + deeper_gap;
22815
23142
  inside += stringify(i, value, deeper_gap) || STR_NULL;
22816
23143
  inside += process_comments(value, AFTER_VALUE(i), deeper_gap);
22817
23144
  after_comma = process_comments(value, AFTER(i), deeper_gap);
22818
23145
  }
22819
- inside += join11(after_comma, process_comments(value, PREFIX_AFTER, deeper_gap), deeper_gap);
23146
+ inside += join12(after_comma, process_comments(value, PREFIX_AFTER, deeper_gap), deeper_gap);
22820
23147
  return BRACKET_OPEN + join_content(inside, value, gap) + BRACKET_CLOSE;
22821
23148
  };
22822
23149
  var object_stringify = (value, gap) => {
@@ -22837,13 +23164,13 @@ var require_stringify = __commonJS((exports, module) => {
22837
23164
  inside += COMMA;
22838
23165
  }
22839
23166
  first = false;
22840
- const before = join11(after_comma, process_comments(value, BEFORE(key), deeper_gap), deeper_gap);
23167
+ const before = join12(after_comma, process_comments(value, BEFORE(key), deeper_gap), deeper_gap);
22841
23168
  inside += before || LF + deeper_gap;
22842
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);
22843
23170
  after_comma = process_comments(value, AFTER(key), deeper_gap);
22844
23171
  };
22845
23172
  keys.forEach(iteratee);
22846
- inside += join11(after_comma, process_comments(value, PREFIX_AFTER, deeper_gap), deeper_gap);
23173
+ inside += join12(after_comma, process_comments(value, PREFIX_AFTER, deeper_gap), deeper_gap);
22847
23174
  return CURLY_BRACKET_OPEN + join_content(inside, value, gap) + CURLY_BRACKET_CLOSE;
22848
23175
  };
22849
23176
  function stringify(key, holder, gap) {
@@ -22937,8 +23264,8 @@ var require_src2 = __commonJS((exports, module) => {
22937
23264
 
22938
23265
  // src/index.ts
22939
23266
  init_embedding();
22940
- import { createRequire } from "node:module";
22941
- import { join as join13 } from "node:path";
23267
+ import { createRequire as createRequire2 } from "node:module";
23268
+ import { join as join14 } from "node:path";
22942
23269
 
22943
23270
  // ../plugin/src/features/magic-context/memory/project-identity.ts
22944
23271
  import { execSync } from "node:child_process";
@@ -156421,8 +156748,8 @@ function ensureMessagesIndexed(db, sessionId, readMessages) {
156421
156748
  }
156422
156749
  // ../plugin/src/features/magic-context/storage-db.ts
156423
156750
  init_data_path();
156424
- import { copyFileSync, cpSync, existsSync, mkdirSync as mkdirSync2 } from "node:fs";
156425
- import { join as join5 } from "node:path";
156751
+ import { copyFileSync, cpSync, existsSync as existsSync2, mkdirSync as mkdirSync3 } from "node:fs";
156752
+ import { join as join6 } from "node:path";
156426
156753
 
156427
156754
  // ../plugin/src/shared/error-message.ts
156428
156755
  function getErrorMessage(error48) {
@@ -156751,21 +157078,21 @@ var persistenceByDatabase = new WeakMap;
156751
157078
  var persistenceErrorByDatabase = new WeakMap;
156752
157079
  function resolveDatabasePath() {
156753
157080
  const dbDir = getMagicContextStorageDir();
156754
- return { dbDir, dbPath: join5(dbDir, "context.db") };
157081
+ return { dbDir, dbPath: join6(dbDir, "context.db") };
156755
157082
  }
156756
157083
  function migrateLegacyStorageIfNeeded(targetDbPath, targetDbDir) {
156757
- if (existsSync(targetDbPath))
157084
+ if (existsSync2(targetDbPath))
156758
157085
  return;
156759
157086
  const legacyDir = getLegacyOpenCodeMagicContextStorageDir();
156760
- const legacyDbPath = join5(legacyDir, "context.db");
156761
- if (!existsSync(legacyDbPath))
157087
+ const legacyDbPath = join6(legacyDir, "context.db");
157088
+ if (!existsSync2(legacyDbPath))
156762
157089
  return;
156763
157090
  log(`[magic-context] migrating legacy plugin storage: ${legacyDir} -> ${targetDbDir} (legacy left in place as backup)`);
156764
- mkdirSync2(targetDbDir, { recursive: true });
157091
+ mkdirSync3(targetDbDir, { recursive: true });
156765
157092
  for (const suffix of ["", "-wal", "-shm"]) {
156766
157093
  const src = `${legacyDbPath}${suffix}`;
156767
- const dst = join5(targetDbDir, `context.db${suffix}`);
156768
- if (existsSync(src)) {
157094
+ const dst = join6(targetDbDir, `context.db${suffix}`);
157095
+ if (existsSync2(src)) {
156769
157096
  try {
156770
157097
  copyFileSync(src, dst);
156771
157098
  } catch (error48) {
@@ -156773,9 +157100,9 @@ function migrateLegacyStorageIfNeeded(targetDbPath, targetDbDir) {
156773
157100
  }
156774
157101
  }
156775
157102
  }
156776
- const legacyModelsDir = join5(legacyDir, "models");
156777
- const targetModelsDir = join5(targetDbDir, "models");
156778
- if (existsSync(legacyModelsDir) && !existsSync(targetModelsDir)) {
157103
+ const legacyModelsDir = join6(legacyDir, "models");
157104
+ const targetModelsDir = join6(targetDbDir, "models");
157105
+ if (existsSync2(legacyModelsDir) && !existsSync2(targetModelsDir)) {
156779
157106
  try {
156780
157107
  cpSync(legacyModelsDir, targetModelsDir, { recursive: true });
156781
157108
  } catch (error48) {
@@ -157155,7 +157482,7 @@ function openDatabase() {
157155
157482
  }
157156
157483
  try {
157157
157484
  migrateLegacyStorageIfNeeded(dbPath, dbDir);
157158
- mkdirSync2(dbDir, { recursive: true });
157485
+ mkdirSync3(dbDir, { recursive: true });
157159
157486
  const db = new Database(dbPath);
157160
157487
  initializeDatabase(db);
157161
157488
  runMigrations(db);
@@ -157951,9 +158278,9 @@ function expandFallbackChain(chain) {
157951
158278
  init_data_path();
157952
158279
  init_logger();
157953
158280
  import { createHash as createHash3 } from "node:crypto";
157954
- import { existsSync as existsSync2, readFileSync } from "node:fs";
158281
+ import { existsSync as existsSync3, readFileSync } from "node:fs";
157955
158282
  import { homedir as homedir2, platform } from "node:os";
157956
- import { join as join6 } from "node:path";
158283
+ import { join as join7 } from "node:path";
157957
158284
  var RELOAD_INTERVAL_MS = 5 * 60 * 1000;
157958
158285
  var apiCache = null;
157959
158286
  var fileCache = null;
@@ -157968,16 +158295,16 @@ function getModelsJsonPath() {
157968
158295
  const cacheBase = getCacheDir();
157969
158296
  const source = process.env.OPENCODE_MODELS_URL?.trim();
157970
158297
  const filename = source && source !== "https://models.dev" ? `models-${hashFast(source)}.json` : "models.json";
157971
- return join6(cacheBase, "opencode", filename);
158298
+ return join7(cacheBase, "opencode", filename);
157972
158299
  }
157973
158300
  function getOpencodeConfigPath() {
157974
158301
  const envDir = process.env.OPENCODE_CONFIG_DIR?.trim();
157975
- const configDir = envDir ? envDir : platform() === "win32" ? join6(homedir2(), ".config", "opencode") : join6(process.env.XDG_CONFIG_HOME || join6(homedir2(), ".config"), "opencode");
157976
- const jsonc = join6(configDir, "opencode.jsonc");
157977
- if (existsSync2(jsonc))
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))
157978
158305
  return jsonc;
157979
- const json2 = join6(configDir, "opencode.json");
157980
- if (existsSync2(json2))
158306
+ const json2 = join7(configDir, "opencode.json");
158307
+ if (existsSync3(json2))
157981
158308
  return json2;
157982
158309
  return null;
157983
158310
  }
@@ -158020,7 +158347,7 @@ function loadModelsDevMetadataFromFile() {
158020
158347
  const modelsJsonPath = getModelsJsonPath();
158021
158348
  let fileFound = false;
158022
158349
  try {
158023
- if (existsSync2(modelsJsonPath)) {
158350
+ if (existsSync3(modelsJsonPath)) {
158024
158351
  fileFound = true;
158025
158352
  const raw = readFileSync(modelsJsonPath, "utf-8");
158026
158353
  const data = JSON.parse(raw);
@@ -158037,7 +158364,7 @@ function loadModelsDevMetadataFromFile() {
158037
158364
  }
158038
158365
  try {
158039
158366
  const configPath = getOpencodeConfigPath();
158040
- if (configPath && existsSync2(configPath)) {
158367
+ if (configPath && existsSync3(configPath)) {
158041
158368
  let raw = readFileSync(configPath, "utf-8");
158042
158369
  raw = raw.replace(/"(?:[^"\\]|\\.)*"|\/\/.*$/gm, (match) => match.startsWith('"') ? match : "");
158043
158370
  const config2 = JSON.parse(raw);
@@ -158380,15 +158707,15 @@ init_logger();
158380
158707
 
158381
158708
  // src/subagent-runner.ts
158382
158709
  import * as childProcess from "node:child_process";
158383
- import { existsSync as existsSync3 } from "node:fs";
158384
- 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";
158385
158712
  import { createInterface } from "node:readline";
158386
158713
  import { fileURLToPath } from "node:url";
158387
158714
  function resolveSubagentEntryPath() {
158388
158715
  try {
158389
- const here = dirname(fileURLToPath(import.meta.url));
158716
+ const here = dirname2(fileURLToPath(import.meta.url));
158390
158717
  const candidate = resolvePath(here, "subagent-entry.js");
158391
- if (existsSync3(candidate))
158718
+ if (existsSync4(candidate))
158392
158719
  return candidate;
158393
158720
  return;
158394
158721
  } catch {
@@ -158848,8 +159175,8 @@ function enqueueDream(db, projectIdentity, reason, force = false) {
158848
159175
  };
158849
159176
  })();
158850
159177
  }
158851
- function peekQueue(db) {
158852
- const row = db.prepare("SELECT id, project_path, reason, enqueued_at FROM dream_queue WHERE started_at IS NULL ORDER BY enqueued_at ASC LIMIT 1").get();
159178
+ function peekQueue(db, projectIdentity) {
159179
+ const row = projectIdentity ? db.prepare("SELECT id, project_path, reason, enqueued_at FROM dream_queue WHERE started_at IS NULL AND project_path = ? ORDER BY enqueued_at ASC LIMIT 1").get(projectIdentity) : db.prepare("SELECT id, project_path, reason, enqueued_at FROM dream_queue WHERE started_at IS NULL ORDER BY enqueued_at ASC LIMIT 1").get();
158853
159180
  if (!row)
158854
159181
  return null;
158855
159182
  return {
@@ -158860,10 +159187,10 @@ function peekQueue(db) {
158860
159187
  startedAt: null
158861
159188
  };
158862
159189
  }
158863
- function dequeueNext(db) {
159190
+ function dequeueNext(db, projectIdentity) {
158864
159191
  const now = Date.now();
158865
159192
  return db.transaction(() => {
158866
- const entry = peekQueue(db);
159193
+ const entry = peekQueue(db, projectIdentity);
158867
159194
  if (!entry)
158868
159195
  return null;
158869
159196
  const result = db.prepare("UPDATE dream_queue SET started_at = ? WHERE id = ? AND started_at IS NULL").run(now, entry.id);
@@ -158987,8 +159314,8 @@ function releaseLease(db, holderId) {
158987
159314
  })();
158988
159315
  }
158989
159316
  // ../plugin/src/features/magic-context/dreamer/runner.ts
158990
- import { existsSync as existsSync4 } from "node:fs";
158991
- import { join as join7 } from "node:path";
159317
+ import { existsSync as existsSync5 } from "node:fs";
159318
+ import { join as join8 } from "node:path";
158992
159319
 
158993
159320
  // ../plugin/src/shared/index.ts
158994
159321
  init_logger();
@@ -160276,7 +160603,7 @@ If no promotions are warranted, return empty arrays. Always consume reviewed can
160276
160603
  body: {
160277
160604
  agent: DREAMER_AGENT,
160278
160605
  system: DREAMER_SYSTEM_PROMPT,
160279
- parts: [{ type: "text", text: prompt }]
160606
+ parts: [{ type: "text", text: prompt, synthetic: true }]
160280
160607
  }
160281
160608
  }, { timeoutMs: Math.min(remainingMs, 5 * 60 * 1000), signal: abortController.signal });
160282
160609
  const messagesResponse = await args.client.session.messages({
@@ -160386,11 +160713,11 @@ function countNewIds(beforeIds, afterIds) {
160386
160713
  return count;
160387
160714
  }
160388
160715
  function getOpenCodeDbPath2() {
160389
- return join7(getDataDir(), "opencode", "opencode.db");
160716
+ return join8(getDataDir(), "opencode", "opencode.db");
160390
160717
  }
160391
160718
  function openOpenCodeDb() {
160392
160719
  const dbPath = getOpenCodeDbPath2();
160393
- if (!existsSync4(dbPath)) {
160720
+ if (!existsSync5(dbPath)) {
160394
160721
  log(`[key-files] OpenCode DB not found at ${dbPath} — skipping`);
160395
160722
  return null;
160396
160723
  }
@@ -160488,7 +160815,7 @@ async function identifyKeyFilesForSession(args) {
160488
160815
  body: {
160489
160816
  agent: DREAMER_AGENT,
160490
160817
  system: KEY_FILES_SYSTEM_PROMPT,
160491
- parts: [{ type: "text", text: prompt }]
160818
+ parts: [{ type: "text", text: prompt, synthetic: true }]
160492
160819
  }
160493
160820
  }, { timeoutMs: Math.min(remainingMs, 300000), signal: abortController.signal });
160494
160821
  const messagesResponse = await args.client.session.messages({
@@ -160640,8 +160967,8 @@ async function runDream(args) {
160640
160967
  try {
160641
160968
  const docsDir = args.sessionDirectory ?? args.projectIdentity;
160642
160969
  const existingDocs = taskName === "maintain-docs" ? {
160643
- architecture: existsSync4(join7(docsDir, "ARCHITECTURE.md")),
160644
- structure: existsSync4(join7(docsDir, "STRUCTURE.md"))
160970
+ architecture: existsSync5(join8(docsDir, "ARCHITECTURE.md")),
160971
+ structure: existsSync5(join8(docsDir, "STRUCTURE.md"))
160645
160972
  } : undefined;
160646
160973
  const userMemories = taskName === "archive-stale" ? getActiveUserMemories(args.db).map((um) => ({
160647
160974
  id: um.id,
@@ -160672,7 +160999,7 @@ async function runDream(args) {
160672
160999
  body: {
160673
161000
  agent: DREAMER_AGENT,
160674
161001
  system: DREAMER_SYSTEM_PROMPT,
160675
- parts: [{ type: "text", text: taskPrompt }]
161002
+ parts: [{ type: "text", text: taskPrompt, synthetic: true }]
160676
161003
  }
160677
161004
  }, {
160678
161005
  timeoutMs: args.taskTimeoutMinutes * 60 * 1000,
@@ -160901,7 +161228,7 @@ Only include notes whose conditions you could definitively evaluate. Skip notes
160901
161228
  body: {
160902
161229
  agent: DREAMER_AGENT,
160903
161230
  system: DREAMER_SYSTEM_PROMPT,
160904
- parts: [{ type: "text", text: evaluationPrompt }]
161231
+ parts: [{ type: "text", text: evaluationPrompt, synthetic: true }]
160905
161232
  }
160906
161233
  }, { timeoutMs: Math.min(remainingMs, 300000), signal: abortController.signal });
160907
161234
  const messagesResponse = await args.client.session.messages({
@@ -160986,7 +161313,7 @@ var MAX_LEASE_RETRIES = 3;
160986
161313
  async function processDreamQueue(args) {
160987
161314
  const maxRuntimeMs = args.maxRuntimeMinutes * 60 * 1000;
160988
161315
  clearStaleEntries(args.db, maxRuntimeMs + 1800000);
160989
- const entry = dequeueNext(args.db);
161316
+ const entry = dequeueNext(args.db, args.projectIdentity);
160990
161317
  if (!entry) {
160991
161318
  return null;
160992
161319
  }
@@ -161081,7 +161408,7 @@ function findProjectsNeedingDream(db) {
161081
161408
  }
161082
161409
  return projects;
161083
161410
  }
161084
- function checkScheduleAndEnqueue(db, schedule) {
161411
+ function checkScheduleAndEnqueue(db, schedule, ownProjectIdentity) {
161085
161412
  if (!isInScheduleWindow(schedule)) {
161086
161413
  return 0;
161087
161414
  }
@@ -161089,8 +161416,9 @@ function checkScheduleAndEnqueue(db, schedule) {
161089
161416
  if (projects.length === 0) {
161090
161417
  return 0;
161091
161418
  }
161419
+ const eligible = ownProjectIdentity ? projects.filter((id) => id === ownProjectIdentity) : projects;
161092
161420
  let enqueued = 0;
161093
- for (const projectIdentity of projects) {
161421
+ for (const projectIdentity of eligible) {
161094
161422
  const entry = enqueueDream(db, projectIdentity, "scheduled");
161095
161423
  if (entry) {
161096
161424
  log(`[dreamer] enqueued project for scheduled dream: ${projectIdentity}`);
@@ -161716,7 +162044,8 @@ async function sweepProject(reg, origin) {
161716
162044
  try {
161717
162045
  const db = openDatabase();
161718
162046
  log(`[dreamer] timer tick (${origin}) ${reg.directory} — checking schedule window "${reg.dreamerConfig.schedule}"`);
161719
- checkScheduleAndEnqueue(db, reg.dreamerConfig.schedule);
162047
+ const registrationIdentity = resolveProjectIdentity(reg.directory);
162048
+ checkScheduleAndEnqueue(db, reg.dreamerConfig.schedule, registrationIdentity);
161720
162049
  await processDreamQueue({
161721
162050
  db,
161722
162051
  client: reg.client,
@@ -161724,7 +162053,8 @@ async function sweepProject(reg, origin) {
161724
162053
  taskTimeoutMinutes: reg.dreamerConfig.task_timeout_minutes,
161725
162054
  maxRuntimeMinutes: reg.dreamerConfig.max_runtime_minutes,
161726
162055
  experimentalUserMemories: reg.experimentalUserMemories,
161727
- experimentalPinKeyFiles: reg.experimentalPinKeyFiles
162056
+ experimentalPinKeyFiles: reg.experimentalPinKeyFiles,
162057
+ projectIdentity: registrationIdentity
161728
162058
  });
161729
162059
  } catch (error48) {
161730
162060
  log(`[dreamer] timer-triggered queue processing failed for ${reg.directory}:`, error48);
@@ -161797,7 +162127,8 @@ function registerPiDreamerProject(opts) {
161797
162127
  taskTimeoutMinutes: opts.config.task_timeout_minutes,
161798
162128
  maxRuntimeMinutes: opts.config.max_runtime_minutes,
161799
162129
  experimentalUserMemories,
161800
- experimentalPinKeyFiles
162130
+ experimentalPinKeyFiles,
162131
+ projectIdentity: opts.projectIdentity
161801
162132
  });
161802
162133
  registeredProjects2.set(opts.projectIdentity, { cleanup, runOnce });
161803
162134
  }
@@ -165801,28 +166132,28 @@ function getReducedRecompTokenBudget(currentBudget) {
165801
166132
  }
165802
166133
 
165803
166134
  // ../plugin/src/hooks/magic-context/historian-state-file.ts
165804
- import { mkdirSync as mkdirSync3, unlinkSync, writeFileSync } from "node:fs";
166135
+ import { mkdirSync as mkdirSync4, unlinkSync, writeFileSync as writeFileSync2 } from "node:fs";
165805
166136
  import { tmpdir as tmpdir2 } from "node:os";
165806
- import { join as join8 } from "node:path";
166137
+ import { join as join9 } from "node:path";
165807
166138
  var HISTORIAN_STATE_INLINE_THRESHOLD = 30000;
165808
- var HISTORIAN_STATE_DIR = join8(tmpdir2(), "magic-context-historian");
166139
+ var HISTORIAN_STATE_DIR = join9(tmpdir2(), "magic-context-historian");
165809
166140
  function maybeWriteHistorianStateFile(sessionId, existingState) {
165810
166141
  if (existingState.length <= HISTORIAN_STATE_INLINE_THRESHOLD)
165811
166142
  return;
165812
166143
  try {
165813
- mkdirSync3(HISTORIAN_STATE_DIR, { recursive: true });
165814
- const path4 = join8(HISTORIAN_STATE_DIR, `state-${sessionId}-${Date.now()}.xml`);
165815
- writeFileSync(path4, existingState, "utf8");
165816
- return path4;
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;
165817
166148
  } catch {
165818
166149
  return;
165819
166150
  }
165820
166151
  }
165821
- function cleanupHistorianStateFile(path4) {
165822
- if (!path4)
166152
+ function cleanupHistorianStateFile(path5) {
166153
+ if (!path5)
165823
166154
  return;
165824
166155
  try {
165825
- unlinkSync(path4);
166156
+ unlinkSync(path5);
165826
166157
  } catch {}
165827
166158
  }
165828
166159
 
@@ -168027,7 +168358,7 @@ init_logger();
168027
168358
  init_data_path();
168028
168359
  init_logger();
168029
168360
  await init_sqlite();
168030
- import { join as join9 } from "node:path";
168361
+ import { join as join10 } from "node:path";
168031
168362
  var BASE62_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
168032
168363
  function randomBase62(length) {
168033
168364
  const chars = [];
@@ -168048,7 +168379,7 @@ function generatePartId(timestampMs, counter = 0n) {
168048
168379
  return generateId("prt", timestampMs, counter);
168049
168380
  }
168050
168381
  function getOpenCodeDbPath3() {
168051
- return join9(getDataDir(), "opencode", "opencode.db");
168382
+ return join10(getDataDir(), "opencode", "opencode.db");
168052
168383
  }
168053
168384
  var cachedWriteDb = null;
168054
168385
  var REQUIRED_MESSAGE_COLUMNS = ["id", "session_id", "time_created", "time_updated", "data"];
@@ -168559,7 +168890,7 @@ async function runCompressorPass2(args) {
168559
168890
  query: { directory },
168560
168891
  body: {
168561
168892
  agent: HISTORIAN_AGENT2,
168562
- parts: [{ type: "text", text: prompt }]
168893
+ parts: [{ type: "text", text: prompt, synthetic: true }]
168563
168894
  }
168564
168895
  }, { timeoutMs: historianTimeoutMs ?? DEFAULT_HISTORIAN_TIMEOUT_MS });
168565
168896
  const messagesResponse = await client.session.messages({
@@ -168601,11 +168932,11 @@ async function runCompressorPass2(args) {
168601
168932
  }
168602
168933
 
168603
168934
  // ../plugin/src/hooks/magic-context/compartment-runner-historian.ts
168604
- import { mkdirSync as mkdirSync4, unlinkSync as unlinkSync2, writeFileSync as writeFileSync2 } from "node:fs";
168935
+ import { mkdirSync as mkdirSync5, unlinkSync as unlinkSync2, writeFileSync as writeFileSync3 } from "node:fs";
168605
168936
  import { tmpdir as tmpdir3 } from "node:os";
168606
- import { join as join10 } from "node:path";
168937
+ import { join as join11 } from "node:path";
168607
168938
  init_magic_context();
168608
- var HISTORIAN_RESPONSE_DUMP_DIR = join10(tmpdir3(), "magic-context-historian");
168939
+ var HISTORIAN_RESPONSE_DUMP_DIR = join11(tmpdir3(), "magic-context-historian");
168609
168940
  var MAX_HISTORIAN_RETRIES = 2;
168610
168941
  async function runValidatedHistorianPass(args) {
168611
168942
  const firstRun = await runHistorianPrompt({
@@ -168724,7 +169055,7 @@ async function runHistorianPrompt(args) {
168724
169055
  body: {
168725
169056
  agent: agentId,
168726
169057
  ...modelOverride ? { model: modelOverride } : {},
168727
- parts: [{ type: "text", text: prompt }]
169058
+ parts: [{ type: "text", text: prompt, synthetic: true }]
168728
169059
  }
168729
169060
  }, { timeoutMs: timeoutMs ?? DEFAULT_HISTORIAN_TIMEOUT_MS });
168730
169061
  sessionLog(parentSessionId, `historian: prompt completed (attempt ${retryIndex + 1}/${MAX_HISTORIAN_RETRIES + 1})`);
@@ -168846,11 +169177,11 @@ function cleanupHistorianDump(sessionId, dumpPath) {
168846
169177
  }
168847
169178
  function dumpHistorianResponse(sessionId, label, text) {
168848
169179
  try {
168849
- mkdirSync4(HISTORIAN_RESPONSE_DUMP_DIR, { recursive: true });
169180
+ mkdirSync5(HISTORIAN_RESPONSE_DUMP_DIR, { recursive: true });
168850
169181
  const safeSessionId = sanitizeDumpName(sessionId);
168851
169182
  const safeLabel = sanitizeDumpName(label);
168852
- const dumpPath = join10(HISTORIAN_RESPONSE_DUMP_DIR, `${safeSessionId}-${safeLabel}-${Date.now()}.xml`);
168853
- writeFileSync2(dumpPath, text, "utf8");
169183
+ const dumpPath = join11(HISTORIAN_RESPONSE_DUMP_DIR, `${safeSessionId}-${safeLabel}-${Date.now()}.xml`);
169184
+ writeFileSync3(dumpPath, text, "utf8");
168854
169185
  sessionLog(sessionId, "compartment agent: historian response dumped", {
168855
169186
  label,
168856
169187
  dumpPath
@@ -169861,8 +170192,8 @@ function createPiRecompClient(args) {
169861
170192
  function readPathId(input) {
169862
170193
  if (typeof input !== "object" || input === null)
169863
170194
  return "";
169864
- const path4 = input.path;
169865
- return typeof path4?.id === "string" ? path4.id : "";
170195
+ const path5 = input.path;
170196
+ return typeof path5?.id === "string" ? path5.id : "";
169866
170197
  }
169867
170198
  function readBody(input) {
169868
170199
  if (typeof input !== "object" || input === null)
@@ -170017,7 +170348,7 @@ import {
170017
170348
  // package.json
170018
170349
  var package_default = {
170019
170350
  name: "@cortexkit/pi-magic-context",
170020
- version: "0.16.1",
170351
+ version: "0.16.3",
170021
170352
  type: "module",
170022
170353
  description: "Pi coding agent extension for Magic Context — cross-session memory and context management",
170023
170354
  main: "dist/index.js",
@@ -170554,14 +170885,14 @@ function readHistorianState(db, sessionId, meta3) {
170554
170885
 
170555
170886
  // src/config/index.ts
170556
170887
  init_magic_context();
170557
- import { existsSync as existsSync6, readFileSync as readFileSync3 } from "node:fs";
170888
+ import { existsSync as existsSync7, readFileSync as readFileSync3 } from "node:fs";
170558
170889
  import { homedir as homedir4 } from "node:os";
170559
- import { join as join11 } from "node:path";
170890
+ import { join as join12 } from "node:path";
170560
170891
 
170561
170892
  // ../plugin/src/config/variable.ts
170562
- import { existsSync as existsSync5, readFileSync as readFileSync2 } from "node:fs";
170893
+ import { existsSync as existsSync6, readFileSync as readFileSync2 } from "node:fs";
170563
170894
  import { homedir as homedir3 } from "node:os";
170564
- import { dirname as dirname2, isAbsolute, resolve } from "node:path";
170895
+ import { dirname as dirname3, isAbsolute, resolve } from "node:path";
170565
170896
  var ENV_PATTERN = /\{env:([^}]+)\}/g;
170566
170897
  var FILE_PATTERN = /\{file:([^}]+)\}/g;
170567
170898
  function substituteConfigVariables(input) {
@@ -170580,7 +170911,7 @@ function substituteConfigVariables(input) {
170580
170911
  if (fileMatches.length === 0) {
170581
170912
  return { text, warnings };
170582
170913
  }
170583
- const configDir = input.configPath ? dirname2(input.configPath) : process.cwd();
170914
+ const configDir = input.configPath ? dirname3(input.configPath) : process.cwd();
170584
170915
  let output = "";
170585
170916
  let cursor = 0;
170586
170917
  for (const match of fileMatches) {
@@ -170602,7 +170933,7 @@ function substituteConfigVariables(input) {
170602
170933
  } else if (!isAbsolute(filePath)) {
170603
170934
  filePath = resolve(configDir, filePath);
170604
170935
  }
170605
- if (!existsSync5(filePath)) {
170936
+ if (!existsSync6(filePath)) {
170606
170937
  warnings.push(`File not found for ${token} (resolved to ${filePath}); using empty string`);
170607
170938
  continue;
170608
170939
  }
@@ -170624,38 +170955,38 @@ function substituteConfigVariables(input) {
170624
170955
  var import_comment_json = __toESM(require_src2(), 1);
170625
170956
  var CONFIG_FILE_NAME = "magic-context";
170626
170957
  function getProjectConfigPaths(cwd) {
170627
- const basePath = join11(cwd, ".pi", CONFIG_FILE_NAME);
170958
+ const basePath = join12(cwd, ".pi", CONFIG_FILE_NAME);
170628
170959
  return [`${basePath}.jsonc`, `${basePath}.json`];
170629
170960
  }
170630
170961
  function getUserConfigPaths() {
170631
170962
  const home = process.env.HOME ?? homedir4();
170632
- const basePath = join11(home, ".pi", "agent", CONFIG_FILE_NAME);
170963
+ const basePath = join12(home, ".pi", "agent", CONFIG_FILE_NAME);
170633
170964
  return [`${basePath}.jsonc`, `${basePath}.json`];
170634
170965
  }
170635
170966
  function resolveFirstExisting(paths) {
170636
- return paths.find((path4) => existsSync6(path4));
170967
+ return paths.find((path5) => existsSync7(path5));
170637
170968
  }
170638
- function loadConfigFile(path4, scope) {
170969
+ function loadConfigFile(path5, scope) {
170639
170970
  try {
170640
- const rawText = readFileSync3(path4, "utf-8");
170971
+ const rawText = readFileSync3(path5, "utf-8");
170641
170972
  const substituted = substituteConfigVariables({
170642
170973
  text: rawText,
170643
- configPath: path4
170974
+ configPath: path5
170644
170975
  });
170645
170976
  return {
170646
- path: path4,
170977
+ path: path5,
170647
170978
  scope,
170648
170979
  config: import_comment_json.parse(substituted.text),
170649
- warnings: substituted.warnings.map((warning) => `${path4}: ${warning}`)
170980
+ warnings: substituted.warnings.map((warning) => `${path5}: ${warning}`)
170650
170981
  };
170651
170982
  } catch (error48) {
170652
170983
  const message = error48 instanceof Error ? error48.message : String(error48);
170653
170984
  return {
170654
- path: path4,
170985
+ path: path5,
170655
170986
  scope,
170656
170987
  config: {},
170657
170988
  warnings: [
170658
- `${path4}: failed to load config: ${message}; using defaults for this file.`
170989
+ `${path5}: failed to load config: ${message}; using defaults for this file.`
170659
170990
  ]
170660
170991
  };
170661
170992
  }
@@ -170785,8 +171116,8 @@ function stripTagPrefixFromAssistantMessage(message) {
170785
171116
 
170786
171117
  // src/system-prompt.ts
170787
171118
  import { createHash as createHash4 } from "node:crypto";
170788
- import { existsSync as existsSync7, readFileSync as readFileSync4, realpathSync } from "node:fs";
170789
- import { join as join12, resolve as resolve2, sep } from "node:path";
171119
+ import { existsSync as existsSync8, readFileSync as readFileSync4, realpathSync } from "node:fs";
171120
+ import { join as join13, resolve as resolve2, sep } from "node:path";
170790
171121
 
170791
171122
  // ../plugin/src/agents/magic-context-prompt.ts
170792
171123
  function getToolHistoryGuidance(dropToolStructure) {
@@ -170888,9 +171219,9 @@ var DOC_FILES = ["ARCHITECTURE.md", "STRUCTURE.md"];
170888
171219
  function readProjectDocs(directory) {
170889
171220
  const sections = [];
170890
171221
  for (const filename of DOC_FILES) {
170891
- const filePath = join12(directory, filename);
171222
+ const filePath = join13(directory, filename);
170892
171223
  try {
170893
- if (existsSync7(filePath)) {
171224
+ if (existsSync8(filePath)) {
170894
171225
  const content = readFileSync4(filePath, "utf-8").trim();
170895
171226
  if (content.length > 0) {
170896
171227
  sections.push(`<${filename}>
@@ -170934,7 +171265,7 @@ function buildKeyFilesBlock(db, sessionId, directory, tokenBudget) {
170934
171265
  log(`[magic-context-pi] key file path escapes project root, skipping: ${entry.filePath}`);
170935
171266
  continue;
170936
171267
  }
170937
- if (!existsSync7(absPath))
171268
+ if (!existsSync8(absPath))
170938
171269
  continue;
170939
171270
  let realPath;
170940
171271
  try {
@@ -176011,7 +176342,7 @@ function registerMagicContextTools(pi, opts) {
176011
176342
  }
176012
176343
 
176013
176344
  // src/index.ts
176014
- var PREFIX = "[magic-context][pi]";
176345
+ var PREFIX2 = "[magic-context][pi]";
176015
176346
  function persistPiMessageEndModelMeta(args) {
176016
176347
  if (!args.message || typeof args.message !== "object")
176017
176348
  return;
@@ -176028,14 +176359,14 @@ function persistPiMessageEndModelMeta(args) {
176028
176359
  }
176029
176360
  }
176030
176361
  function info(message, data) {
176031
- log(`${PREFIX} ${message}`, data);
176362
+ log(`${PREFIX2} ${message}`, data);
176032
176363
  }
176033
176364
  function warn(message, data) {
176034
- log(`${PREFIX} WARN ${message}`, data);
176365
+ log(`${PREFIX2} WARN ${message}`, data);
176035
176366
  }
176036
176367
  var PLUGIN_VERSION = (() => {
176037
176368
  try {
176038
- const req = createRequire(import.meta.url);
176369
+ const req = createRequire2(import.meta.url);
176039
176370
  return req("../package.json").version;
176040
176371
  } catch {
176041
176372
  return "0.0.0";
@@ -176116,7 +176447,7 @@ function resolveDreamerFromConfig(config2) {
176116
176447
  }
176117
176448
  async function src_default2(pi) {
176118
176449
  const storageDir = getMagicContextStorageDir();
176119
- const dbPath = join13(storageDir, "context.db");
176450
+ const dbPath = join14(storageDir, "context.db");
176120
176451
  let db;
176121
176452
  try {
176122
176453
  db = openDatabase();