@cortexkit/opencode-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 +8 -8
- package/dist/hooks/auto-update-checker/cache.d.ts +12 -1
- package/dist/hooks/auto-update-checker/cache.d.ts.map +1 -1
- package/dist/hooks/magic-context/hook-handlers.d.ts +6 -0
- package/dist/hooks/magic-context/hook-handlers.d.ts.map +1 -1
- package/dist/hooks/magic-context/hook.d.ts.map +1 -1
- package/dist/hooks/magic-context/live-session-state.d.ts +13 -0
- package/dist/hooks/magic-context/live-session-state.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform.d.ts +7 -0
- package/dist/hooks/magic-context/transform.d.ts.map +1 -1
- package/dist/index.js +431 -99
- package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
- package/dist/shared/native-binding.d.ts +87 -0
- package/dist/shared/native-binding.d.ts.map +1 -0
- package/dist/shared/sqlite.d.ts +0 -12
- package/dist/shared/sqlite.d.ts.map +1 -1
- package/package.json +2 -1
- package/src/shared/conflict-detector.ts +1 -1
- package/src/shared/native-binding.ts +311 -0
- package/src/shared/sqlite.ts +57 -14
- package/src/tui/index.tsx +2 -2
package/dist/index.js
CHANGED
|
@@ -155708,7 +155708,7 @@ function formatConflictShort(result) {
|
|
|
155708
155708
|
"",
|
|
155709
155709
|
...result.reasons.map((r) => `• ${r}`),
|
|
155710
155710
|
"",
|
|
155711
|
-
"Fix: run `
|
|
155711
|
+
"Fix: run `npx @cortexkit/opencode-magic-context@latest doctor`"
|
|
155712
155712
|
];
|
|
155713
155713
|
return lines.join(`
|
|
155714
155714
|
`);
|
|
@@ -156108,14 +156108,334 @@ function safeString(value) {
|
|
|
156108
156108
|
}
|
|
156109
156109
|
}
|
|
156110
156110
|
|
|
156111
|
+
// ../../node_modules/.bun/nanotar@0.3.0/node_modules/nanotar/dist/index.mjs
|
|
156112
|
+
function parseTar(data, opts) {
|
|
156113
|
+
const buffer2 = data.buffer || data;
|
|
156114
|
+
const files = [];
|
|
156115
|
+
let offset = 0;
|
|
156116
|
+
let nextExtendedHeader;
|
|
156117
|
+
let globalExtendedHeader;
|
|
156118
|
+
while (offset < buffer2.byteLength - 512) {
|
|
156119
|
+
let name2 = _readString(buffer2, offset, 100);
|
|
156120
|
+
if (name2.length === 0) {
|
|
156121
|
+
break;
|
|
156122
|
+
}
|
|
156123
|
+
if (nextExtendedHeader) {
|
|
156124
|
+
const longName = nextExtendedHeader.path || nextExtendedHeader.linkpath;
|
|
156125
|
+
if (longName) {
|
|
156126
|
+
name2 = longName;
|
|
156127
|
+
}
|
|
156128
|
+
}
|
|
156129
|
+
const mode = _readString(buffer2, offset + 100, 8).trim();
|
|
156130
|
+
const uid = Number.parseInt(_readString(buffer2, offset + 108, 8));
|
|
156131
|
+
const gid = Number.parseInt(_readString(buffer2, offset + 116, 8));
|
|
156132
|
+
const size = _readNumber(buffer2, offset + 124, 12);
|
|
156133
|
+
const seek = 512 + 512 * Math.trunc(size / 512) + (size % 512 ? 512 : 0);
|
|
156134
|
+
const mtime = _readNumber(buffer2, offset + 136, 12);
|
|
156135
|
+
const _type = _readString(buffer2, offset + 156, 1) || "0";
|
|
156136
|
+
const type = tarItemTypeMap[_type] || _type;
|
|
156137
|
+
switch (type) {
|
|
156138
|
+
case "extendedHeader":
|
|
156139
|
+
case "globalExtendedHeader": {
|
|
156140
|
+
const headers = _parseExtendedHeaders(new Uint8Array(buffer2, offset + 512, size));
|
|
156141
|
+
if (type === "extendedHeader") {
|
|
156142
|
+
nextExtendedHeader = headers;
|
|
156143
|
+
} else {
|
|
156144
|
+
nextExtendedHeader = undefined;
|
|
156145
|
+
globalExtendedHeader = {
|
|
156146
|
+
...globalExtendedHeader,
|
|
156147
|
+
...headers
|
|
156148
|
+
};
|
|
156149
|
+
}
|
|
156150
|
+
offset += seek;
|
|
156151
|
+
continue;
|
|
156152
|
+
}
|
|
156153
|
+
case "gnuLongFileName":
|
|
156154
|
+
case "gnuOldLongFileName":
|
|
156155
|
+
case "gnuLongLinkName": {
|
|
156156
|
+
nextExtendedHeader = { path: _readString(buffer2, offset + 512, size) };
|
|
156157
|
+
offset += seek;
|
|
156158
|
+
continue;
|
|
156159
|
+
}
|
|
156160
|
+
}
|
|
156161
|
+
const user = _readString(buffer2, offset + 265, 32);
|
|
156162
|
+
const group = _readString(buffer2, offset + 297, 32);
|
|
156163
|
+
name2 = _sanitizePath(name2);
|
|
156164
|
+
const meta3 = {
|
|
156165
|
+
name: name2,
|
|
156166
|
+
type,
|
|
156167
|
+
size,
|
|
156168
|
+
attrs: {
|
|
156169
|
+
...globalExtendedHeader,
|
|
156170
|
+
...nextExtendedHeader,
|
|
156171
|
+
mode,
|
|
156172
|
+
uid,
|
|
156173
|
+
gid,
|
|
156174
|
+
mtime,
|
|
156175
|
+
user,
|
|
156176
|
+
group
|
|
156177
|
+
}
|
|
156178
|
+
};
|
|
156179
|
+
nextExtendedHeader = undefined;
|
|
156180
|
+
if (opts?.filter && !opts.filter(meta3)) {
|
|
156181
|
+
offset += seek;
|
|
156182
|
+
continue;
|
|
156183
|
+
}
|
|
156184
|
+
if (opts?.metaOnly) {
|
|
156185
|
+
files.push(meta3);
|
|
156186
|
+
offset += seek;
|
|
156187
|
+
continue;
|
|
156188
|
+
}
|
|
156189
|
+
const data2 = size === 0 ? undefined : new Uint8Array(buffer2, offset + 512, size);
|
|
156190
|
+
files.push({
|
|
156191
|
+
...meta3,
|
|
156192
|
+
data: data2,
|
|
156193
|
+
get text() {
|
|
156194
|
+
return new TextDecoder().decode(this.data);
|
|
156195
|
+
}
|
|
156196
|
+
});
|
|
156197
|
+
offset += seek;
|
|
156198
|
+
}
|
|
156199
|
+
return files;
|
|
156200
|
+
}
|
|
156201
|
+
async function parseTarGzip(data, opts = {}) {
|
|
156202
|
+
const stream = new ReadableStream({
|
|
156203
|
+
start(controller) {
|
|
156204
|
+
controller.enqueue(new Uint8Array(data));
|
|
156205
|
+
controller.close();
|
|
156206
|
+
}
|
|
156207
|
+
}).pipeThrough(new DecompressionStream(opts.compression ?? "gzip"));
|
|
156208
|
+
const decompressedData = await new Response(stream).arrayBuffer();
|
|
156209
|
+
return parseTar(decompressedData, opts);
|
|
156210
|
+
}
|
|
156211
|
+
function _sanitizePath(path3) {
|
|
156212
|
+
let normalized = path3.replace(/\\/g, "/");
|
|
156213
|
+
normalized = normalized.replace(/^[a-zA-Z]:\//, "");
|
|
156214
|
+
normalized = normalized.replace(/^\/+/, "");
|
|
156215
|
+
const hasLeadingDotSlash = normalized.startsWith("./");
|
|
156216
|
+
const parts = normalized.split("/");
|
|
156217
|
+
const resolved = [];
|
|
156218
|
+
for (const part of parts) {
|
|
156219
|
+
if (part === "..") {
|
|
156220
|
+
resolved.pop();
|
|
156221
|
+
} else if (part !== "." && part !== "") {
|
|
156222
|
+
resolved.push(part);
|
|
156223
|
+
}
|
|
156224
|
+
}
|
|
156225
|
+
let result = resolved.join("/");
|
|
156226
|
+
if (hasLeadingDotSlash && !result.startsWith("./")) {
|
|
156227
|
+
result = "./" + result;
|
|
156228
|
+
}
|
|
156229
|
+
if (path3.endsWith("/") && !result.endsWith("/")) {
|
|
156230
|
+
result += "/";
|
|
156231
|
+
}
|
|
156232
|
+
return result;
|
|
156233
|
+
}
|
|
156234
|
+
function _readString(buffer2, offset, size) {
|
|
156235
|
+
const view = new Uint8Array(buffer2, offset, size);
|
|
156236
|
+
const i = view.indexOf(0);
|
|
156237
|
+
const td = new TextDecoder;
|
|
156238
|
+
return td.decode(i === -1 ? view : view.slice(0, i));
|
|
156239
|
+
}
|
|
156240
|
+
function _readNumber(buffer2, offset, size) {
|
|
156241
|
+
const view = new Uint8Array(buffer2, offset, size);
|
|
156242
|
+
let str = "";
|
|
156243
|
+
for (let i = 0;i < size; i++) {
|
|
156244
|
+
str += String.fromCodePoint(view[i]);
|
|
156245
|
+
}
|
|
156246
|
+
return Number.parseInt(str, 8);
|
|
156247
|
+
}
|
|
156248
|
+
function _parseExtendedHeaders(data) {
|
|
156249
|
+
const dataStr = new TextDecoder().decode(data);
|
|
156250
|
+
const headers = {};
|
|
156251
|
+
for (const line of dataStr.split(`
|
|
156252
|
+
`)) {
|
|
156253
|
+
const s = line.split(" ")[1]?.split("=");
|
|
156254
|
+
if (s) {
|
|
156255
|
+
headers[s[0]] = s[1];
|
|
156256
|
+
}
|
|
156257
|
+
}
|
|
156258
|
+
return headers;
|
|
156259
|
+
}
|
|
156260
|
+
var tarItemTypeMap;
|
|
156261
|
+
var init_dist2 = __esm(() => {
|
|
156262
|
+
tarItemTypeMap = {
|
|
156263
|
+
"0": "file",
|
|
156264
|
+
"1": "hardLink",
|
|
156265
|
+
"2": "symbolicLink",
|
|
156266
|
+
"3": "characterDevice",
|
|
156267
|
+
"4": "blockDevice",
|
|
156268
|
+
"5": "directory",
|
|
156269
|
+
"6": "fifo",
|
|
156270
|
+
"7": "contiguousFile",
|
|
156271
|
+
g: "globalExtendedHeader",
|
|
156272
|
+
x: "extendedHeader",
|
|
156273
|
+
D: "gnuDirectory",
|
|
156274
|
+
I: "gnuInodeMetadata",
|
|
156275
|
+
K: "gnuLongLinkName",
|
|
156276
|
+
L: "gnuLongFileName",
|
|
156277
|
+
N: "gnuOldLongFileName",
|
|
156278
|
+
M: "gnuMultiVolume",
|
|
156279
|
+
S: "gnuSparseFile",
|
|
156280
|
+
E: "gnuExtendedSparse",
|
|
156281
|
+
A: "solarisAcl",
|
|
156282
|
+
V: "solarisVolumeLabel",
|
|
156283
|
+
X: "solarisOldExtendedHeader"
|
|
156284
|
+
};
|
|
156285
|
+
});
|
|
156286
|
+
|
|
156287
|
+
// src/shared/native-binding.ts
|
|
156288
|
+
var exports_native_binding = {};
|
|
156289
|
+
__export(exports_native_binding, {
|
|
156290
|
+
resolveBetterSqliteNativeBinding: () => resolveBetterSqliteNativeBinding
|
|
156291
|
+
});
|
|
156292
|
+
import { existsSync as existsSync7, mkdirSync, writeFileSync as writeFileSync3 } from "node:fs";
|
|
156293
|
+
import { createRequire } from "node:module";
|
|
156294
|
+
import * as path3 from "node:path";
|
|
156295
|
+
function logInfo(message) {
|
|
156296
|
+
log(`${PREFIX} ${message}`);
|
|
156297
|
+
}
|
|
156298
|
+
function logWarn(message) {
|
|
156299
|
+
log(`${PREFIX} WARN ${message}`);
|
|
156300
|
+
}
|
|
156301
|
+
function probeAbi(binaryPath) {
|
|
156302
|
+
const expected = process.versions.modules;
|
|
156303
|
+
try {
|
|
156304
|
+
const sandbox = { exports: {} };
|
|
156305
|
+
process.dlopen(sandbox, binaryPath);
|
|
156306
|
+
return { ok: true };
|
|
156307
|
+
} catch (err) {
|
|
156308
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
156309
|
+
const pair = message.match(/NODE_MODULE_VERSION (\d+).*NODE_MODULE_VERSION (\d+)/s);
|
|
156310
|
+
if (pair?.[1] && pair[2]) {
|
|
156311
|
+
return { ok: false, expected: pair[2], actual: pair[1] };
|
|
156312
|
+
}
|
|
156313
|
+
const single = message.match(/NODE_MODULE_VERSION[ =:]+(\d+)/);
|
|
156314
|
+
if (single?.[1]) {
|
|
156315
|
+
return { ok: false, expected, actual: single[1] };
|
|
156316
|
+
}
|
|
156317
|
+
logWarn(`could not parse ABI from dlopen error: ${message}`);
|
|
156318
|
+
return { ok: false, expected, actual: null };
|
|
156319
|
+
}
|
|
156320
|
+
}
|
|
156321
|
+
function resolveBetterSqlite3OnDisk(requireFn) {
|
|
156322
|
+
try {
|
|
156323
|
+
const pkgJsonPath = requireFn.resolve("better-sqlite3/package.json");
|
|
156324
|
+
const pkgDir = path3.dirname(pkgJsonPath);
|
|
156325
|
+
const pkgJson = requireFn(pkgJsonPath);
|
|
156326
|
+
const binaryPath = path3.join(pkgDir, "build", "Release", "better_sqlite3.node");
|
|
156327
|
+
return { binaryPath, pkgVersion: pkgJson.version };
|
|
156328
|
+
} catch (err) {
|
|
156329
|
+
logWarn(`could not resolve better-sqlite3 in node_modules: ${err instanceof Error ? err.message : String(err)}`);
|
|
156330
|
+
return null;
|
|
156331
|
+
}
|
|
156332
|
+
}
|
|
156333
|
+
function getCachedBinaryPath(pkgVersion, abi) {
|
|
156334
|
+
return path3.join(getCacheDir(), "cortexkit", "native-bindings", "better-sqlite3", `v${pkgVersion}`, `electron-v${abi}-${process.platform}-${process.arch}`, "better_sqlite3.node");
|
|
156335
|
+
}
|
|
156336
|
+
async function downloadElectronPrebuild(pkgVersion, abi) {
|
|
156337
|
+
const filename = `better-sqlite3-v${pkgVersion}-electron-v${abi}-${process.platform}-${process.arch}.tar.gz`;
|
|
156338
|
+
const url2 = `https://github.com/WiseLibs/better-sqlite3/releases/download/v${pkgVersion}/${filename}`;
|
|
156339
|
+
logInfo(`downloading ${url2}`);
|
|
156340
|
+
const response = await fetch(url2, {
|
|
156341
|
+
redirect: "follow",
|
|
156342
|
+
headers: { "User-Agent": "magic-context-plugin/native-binding" }
|
|
156343
|
+
});
|
|
156344
|
+
if (!response.ok) {
|
|
156345
|
+
throw new Error(`failed to download Electron prebuild (HTTP ${response.status} ${response.statusText}) from ${url2}`);
|
|
156346
|
+
}
|
|
156347
|
+
const tarballBytes = new Uint8Array(await response.arrayBuffer());
|
|
156348
|
+
logInfo(`downloaded ${(tarballBytes.length / 1024).toFixed(1)} KB; extracting`);
|
|
156349
|
+
const files = await parseTarGzip(tarballBytes);
|
|
156350
|
+
const nodeFile = files.find((f) => f.name.endsWith("better_sqlite3.node"));
|
|
156351
|
+
if (!nodeFile?.data) {
|
|
156352
|
+
const names = files.map((f) => f.name).join(", ");
|
|
156353
|
+
throw new Error(`Electron prebuild tarball did not contain better_sqlite3.node; got: [${names}]`);
|
|
156354
|
+
}
|
|
156355
|
+
return nodeFile.data instanceof Uint8Array ? nodeFile.data : new Uint8Array(nodeFile.data);
|
|
156356
|
+
}
|
|
156357
|
+
async function resolveBetterSqliteNativeBinding() {
|
|
156358
|
+
if (!process.versions.electron) {
|
|
156359
|
+
return null;
|
|
156360
|
+
}
|
|
156361
|
+
if (inFlight) {
|
|
156362
|
+
return inFlight;
|
|
156363
|
+
}
|
|
156364
|
+
const promise2 = (async () => {
|
|
156365
|
+
const expected = process.versions.modules;
|
|
156366
|
+
logInfo(`Electron detected (v${process.versions.electron}, NODE_MODULE_VERSION ${expected}); verifying better-sqlite3 binding`);
|
|
156367
|
+
const requireFn = createRequire(import.meta.url);
|
|
156368
|
+
const resolved = resolveBetterSqlite3OnDisk(requireFn);
|
|
156369
|
+
if (!resolved) {
|
|
156370
|
+
return null;
|
|
156371
|
+
}
|
|
156372
|
+
const { binaryPath: diskPath, pkgVersion } = resolved;
|
|
156373
|
+
if (existsSync7(diskPath)) {
|
|
156374
|
+
const diskProbe = probeAbi(diskPath);
|
|
156375
|
+
if (diskProbe.ok) {
|
|
156376
|
+
logInfo(`on-disk binary already matches Electron ABI v${expected}; using default bindings() lookup`);
|
|
156377
|
+
return null;
|
|
156378
|
+
}
|
|
156379
|
+
logInfo(`on-disk binary ABI ${diskProbe.actual ?? "unknown"} != required ${expected}; will use Electron prebuild`);
|
|
156380
|
+
} else {
|
|
156381
|
+
logWarn(`expected better-sqlite3 binary not found at ${diskPath}; will fetch Electron prebuild anyway`);
|
|
156382
|
+
}
|
|
156383
|
+
const cachedPath = getCachedBinaryPath(pkgVersion, expected);
|
|
156384
|
+
if (existsSync7(cachedPath)) {
|
|
156385
|
+
const cachedProbe = probeAbi(cachedPath);
|
|
156386
|
+
if (cachedProbe.ok) {
|
|
156387
|
+
logInfo(`using cached Electron prebuild at ${cachedPath}`);
|
|
156388
|
+
return cachedPath;
|
|
156389
|
+
}
|
|
156390
|
+
logWarn(`cached binary at ${cachedPath} has wrong ABI (${cachedProbe.actual ?? "unknown"} != ${expected}); refetching`);
|
|
156391
|
+
}
|
|
156392
|
+
mkdirSync(path3.dirname(cachedPath), { recursive: true });
|
|
156393
|
+
const nodeFileBytes = await downloadElectronPrebuild(pkgVersion, expected);
|
|
156394
|
+
writeFileSync3(cachedPath, nodeFileBytes);
|
|
156395
|
+
logInfo(`cached Electron prebuild at ${cachedPath} (${(nodeFileBytes.length / 1024).toFixed(1)} KB)`);
|
|
156396
|
+
const finalProbe = probeAbi(cachedPath);
|
|
156397
|
+
if (!finalProbe.ok) {
|
|
156398
|
+
throw new Error(`downloaded Electron prebuild has wrong ABI (${finalProbe.actual ?? "unknown"} != ${expected}); refusing to use`);
|
|
156399
|
+
}
|
|
156400
|
+
return cachedPath;
|
|
156401
|
+
})();
|
|
156402
|
+
inFlight = promise2;
|
|
156403
|
+
try {
|
|
156404
|
+
return await promise2;
|
|
156405
|
+
} finally {
|
|
156406
|
+
if (inFlight === promise2) {
|
|
156407
|
+
inFlight = null;
|
|
156408
|
+
}
|
|
156409
|
+
}
|
|
156410
|
+
}
|
|
156411
|
+
var PREFIX = "[native-binding]", inFlight = null;
|
|
156412
|
+
var init_native_binding = __esm(() => {
|
|
156413
|
+
init_dist2();
|
|
156414
|
+
init_data_path();
|
|
156415
|
+
init_logger();
|
|
156416
|
+
});
|
|
156417
|
+
|
|
156111
156418
|
// src/shared/sqlite.ts
|
|
156112
|
-
var isBun, bunSpec, betterSpec, sqliteModule, DatabaseImpl, Database;
|
|
156419
|
+
var isBun, bunSpec, betterSpec, electronNativeBinding, sqliteModule, RawDatabaseImpl, DatabaseImpl, Database;
|
|
156113
156420
|
var init_sqlite = __esm(async () => {
|
|
156114
156421
|
isBun = typeof process !== "undefined" && typeof process.versions?.bun === "string";
|
|
156115
156422
|
bunSpec = "bun:" + "sqlite";
|
|
156116
156423
|
betterSpec = "better-" + "sqlite3";
|
|
156424
|
+
electronNativeBinding = isBun ? null : await (async () => {
|
|
156425
|
+
const mod = await Promise.resolve().then(() => (init_native_binding(), exports_native_binding));
|
|
156426
|
+
return mod.resolveBetterSqliteNativeBinding();
|
|
156427
|
+
})();
|
|
156117
156428
|
sqliteModule = isBun ? await import(bunSpec) : await import(betterSpec);
|
|
156118
|
-
|
|
156429
|
+
RawDatabaseImpl = isBun ? sqliteModule.Database : sqliteModule.default;
|
|
156430
|
+
DatabaseImpl = electronNativeBinding == null ? RawDatabaseImpl : class DatabaseWithElectronBinding extends RawDatabaseImpl {
|
|
156431
|
+
constructor(filename, options) {
|
|
156432
|
+
const fallback = electronNativeBinding;
|
|
156433
|
+
super(filename, {
|
|
156434
|
+
...options,
|
|
156435
|
+
nativeBinding: options?.nativeBinding ?? fallback
|
|
156436
|
+
});
|
|
156437
|
+
}
|
|
156438
|
+
};
|
|
156119
156439
|
Database = DatabaseImpl;
|
|
156120
156440
|
});
|
|
156121
156441
|
|
|
@@ -156847,9 +157167,9 @@ __export(exports_read_session_db, {
|
|
|
156847
157167
|
findLastAssistantModelFromOpenCodeDb: () => findLastAssistantModelFromOpenCodeDb,
|
|
156848
157168
|
closeReadOnlySessionDb: () => closeReadOnlySessionDb
|
|
156849
157169
|
});
|
|
156850
|
-
import { join as
|
|
157170
|
+
import { join as join11 } from "node:path";
|
|
156851
157171
|
function getOpenCodeDbPath() {
|
|
156852
|
-
return
|
|
157172
|
+
return join11(getDataDir(), "opencode", "opencode.db");
|
|
156853
157173
|
}
|
|
156854
157174
|
function closeCachedReadOnlyDb() {
|
|
156855
157175
|
if (!cachedReadOnlyDb) {
|
|
@@ -156951,9 +157271,9 @@ function cosineSimilarity(a, b) {
|
|
|
156951
157271
|
}
|
|
156952
157272
|
|
|
156953
157273
|
// src/features/magic-context/memory/embedding-local.ts
|
|
156954
|
-
import { mkdirSync } from "node:fs";
|
|
157274
|
+
import { mkdirSync as mkdirSync2 } from "node:fs";
|
|
156955
157275
|
import { open, stat, unlink, writeFile } from "node:fs/promises";
|
|
156956
|
-
import { join as
|
|
157276
|
+
import { join as join13 } from "node:path";
|
|
156957
157277
|
async function acquireModelLoadLock(lockPath) {
|
|
156958
157278
|
const waitStart = Date.now();
|
|
156959
157279
|
while (true) {
|
|
@@ -157087,15 +157407,15 @@ class LocalEmbeddingProvider {
|
|
|
157087
157407
|
if (LogLevel && "ERROR" in LogLevel) {
|
|
157088
157408
|
env.logLevel = LogLevel.ERROR;
|
|
157089
157409
|
}
|
|
157090
|
-
const modelCacheDir =
|
|
157410
|
+
const modelCacheDir = join13(getMagicContextStorageDir(), "models");
|
|
157091
157411
|
try {
|
|
157092
|
-
|
|
157412
|
+
mkdirSync2(modelCacheDir, { recursive: true });
|
|
157093
157413
|
env.cacheDir = modelCacheDir;
|
|
157094
157414
|
} catch {
|
|
157095
157415
|
log("[magic-context] could not create model cache dir, using library default");
|
|
157096
157416
|
}
|
|
157097
157417
|
const createPipeline = transformersModule.pipeline;
|
|
157098
|
-
const lockPath =
|
|
157418
|
+
const lockPath = join13(modelCacheDir, ".load.lock");
|
|
157099
157419
|
const releaseLock = await acquireModelLoadLock(lockPath);
|
|
157100
157420
|
const stopHeartbeat = startLockHeartbeat(lockPath);
|
|
157101
157421
|
try {
|
|
@@ -157666,7 +157986,7 @@ var init_storage_memory_fts = __esm(() => {
|
|
|
157666
157986
|
// src/features/magic-context/memory/project-identity.ts
|
|
157667
157987
|
import { execSync } from "node:child_process";
|
|
157668
157988
|
import { createHash as createHash2 } from "node:crypto";
|
|
157669
|
-
import
|
|
157989
|
+
import path4 from "node:path";
|
|
157670
157990
|
function getRootCommitHash(directory) {
|
|
157671
157991
|
try {
|
|
157672
157992
|
const hash2 = execSync("git rev-list --max-parents=0 HEAD", {
|
|
@@ -157683,12 +158003,12 @@ function getRootCommitHash(directory) {
|
|
|
157683
158003
|
}
|
|
157684
158004
|
}
|
|
157685
158005
|
function directoryFallback(directory) {
|
|
157686
|
-
const canonical =
|
|
158006
|
+
const canonical = path4.resolve(directory);
|
|
157687
158007
|
const hash2 = createHash2("md5").update(canonical).digest("hex").slice(0, 12);
|
|
157688
158008
|
return `dir:${hash2}`;
|
|
157689
158009
|
}
|
|
157690
158010
|
function resolveProjectIdentity(directory) {
|
|
157691
|
-
const resolved =
|
|
158011
|
+
const resolved = path4.resolve(directory);
|
|
157692
158012
|
const cached2 = resolvedCache.get(resolved);
|
|
157693
158013
|
if (cached2 !== undefined) {
|
|
157694
158014
|
return cached2;
|
|
@@ -158467,25 +158787,25 @@ var init_migrations = __esm(async () => {
|
|
|
158467
158787
|
});
|
|
158468
158788
|
|
|
158469
158789
|
// src/features/magic-context/storage-db.ts
|
|
158470
|
-
import { copyFileSync, cpSync, existsSync as
|
|
158471
|
-
import { join as
|
|
158790
|
+
import { copyFileSync, cpSync, existsSync as existsSync9, mkdirSync as mkdirSync3 } from "node:fs";
|
|
158791
|
+
import { join as join14 } from "node:path";
|
|
158472
158792
|
function resolveDatabasePath() {
|
|
158473
158793
|
const dbDir = getMagicContextStorageDir();
|
|
158474
|
-
return { dbDir, dbPath:
|
|
158794
|
+
return { dbDir, dbPath: join14(dbDir, "context.db") };
|
|
158475
158795
|
}
|
|
158476
158796
|
function migrateLegacyStorageIfNeeded(targetDbPath, targetDbDir) {
|
|
158477
|
-
if (
|
|
158797
|
+
if (existsSync9(targetDbPath))
|
|
158478
158798
|
return;
|
|
158479
158799
|
const legacyDir = getLegacyOpenCodeMagicContextStorageDir();
|
|
158480
|
-
const legacyDbPath =
|
|
158481
|
-
if (!
|
|
158800
|
+
const legacyDbPath = join14(legacyDir, "context.db");
|
|
158801
|
+
if (!existsSync9(legacyDbPath))
|
|
158482
158802
|
return;
|
|
158483
158803
|
log(`[magic-context] migrating legacy plugin storage: ${legacyDir} -> ${targetDbDir} (legacy left in place as backup)`);
|
|
158484
|
-
|
|
158804
|
+
mkdirSync3(targetDbDir, { recursive: true });
|
|
158485
158805
|
for (const suffix of ["", "-wal", "-shm"]) {
|
|
158486
158806
|
const src = `${legacyDbPath}${suffix}`;
|
|
158487
|
-
const dst =
|
|
158488
|
-
if (
|
|
158807
|
+
const dst = join14(targetDbDir, `context.db${suffix}`);
|
|
158808
|
+
if (existsSync9(src)) {
|
|
158489
158809
|
try {
|
|
158490
158810
|
copyFileSync(src, dst);
|
|
158491
158811
|
} catch (error48) {
|
|
@@ -158493,9 +158813,9 @@ function migrateLegacyStorageIfNeeded(targetDbPath, targetDbDir) {
|
|
|
158493
158813
|
}
|
|
158494
158814
|
}
|
|
158495
158815
|
}
|
|
158496
|
-
const legacyModelsDir =
|
|
158497
|
-
const targetModelsDir =
|
|
158498
|
-
if (
|
|
158816
|
+
const legacyModelsDir = join14(legacyDir, "models");
|
|
158817
|
+
const targetModelsDir = join14(targetDbDir, "models");
|
|
158818
|
+
if (existsSync9(legacyModelsDir) && !existsSync9(targetModelsDir)) {
|
|
158499
158819
|
try {
|
|
158500
158820
|
cpSync(legacyModelsDir, targetModelsDir, { recursive: true });
|
|
158501
158821
|
} catch (error48) {
|
|
@@ -158875,7 +159195,7 @@ function openDatabase() {
|
|
|
158875
159195
|
}
|
|
158876
159196
|
try {
|
|
158877
159197
|
migrateLegacyStorageIfNeeded(dbPath, dbDir);
|
|
158878
|
-
|
|
159198
|
+
mkdirSync3(dbDir, { recursive: true });
|
|
158879
159199
|
const db = new Database(dbPath);
|
|
158880
159200
|
initializeDatabase(db);
|
|
158881
159201
|
runMigrations(db);
|
|
@@ -159645,9 +159965,9 @@ var init_storage = __esm(async () => {
|
|
|
159645
159965
|
|
|
159646
159966
|
// src/shared/models-dev-cache.ts
|
|
159647
159967
|
import { createHash as createHash3 } from "node:crypto";
|
|
159648
|
-
import { existsSync as
|
|
159968
|
+
import { existsSync as existsSync10, readFileSync as readFileSync7 } from "node:fs";
|
|
159649
159969
|
import { homedir as homedir8, platform as platform3 } from "node:os";
|
|
159650
|
-
import { join as
|
|
159970
|
+
import { join as join15 } from "node:path";
|
|
159651
159971
|
function hashFast(input) {
|
|
159652
159972
|
return createHash3("sha1").update(input).digest("hex");
|
|
159653
159973
|
}
|
|
@@ -159658,16 +159978,16 @@ function getModelsJsonPath() {
|
|
|
159658
159978
|
const cacheBase = getCacheDir();
|
|
159659
159979
|
const source = process.env.OPENCODE_MODELS_URL?.trim();
|
|
159660
159980
|
const filename = source && source !== "https://models.dev" ? `models-${hashFast(source)}.json` : "models.json";
|
|
159661
|
-
return
|
|
159981
|
+
return join15(cacheBase, "opencode", filename);
|
|
159662
159982
|
}
|
|
159663
159983
|
function getOpencodeConfigPath() {
|
|
159664
159984
|
const envDir = process.env.OPENCODE_CONFIG_DIR?.trim();
|
|
159665
|
-
const configDir = envDir ? envDir : platform3() === "win32" ?
|
|
159666
|
-
const jsonc =
|
|
159667
|
-
if (
|
|
159985
|
+
const configDir = envDir ? envDir : platform3() === "win32" ? join15(homedir8(), ".config", "opencode") : join15(process.env.XDG_CONFIG_HOME || join15(homedir8(), ".config"), "opencode");
|
|
159986
|
+
const jsonc = join15(configDir, "opencode.jsonc");
|
|
159987
|
+
if (existsSync10(jsonc))
|
|
159668
159988
|
return jsonc;
|
|
159669
|
-
const json2 =
|
|
159670
|
-
if (
|
|
159989
|
+
const json2 = join15(configDir, "opencode.json");
|
|
159990
|
+
if (existsSync10(json2))
|
|
159671
159991
|
return json2;
|
|
159672
159992
|
return null;
|
|
159673
159993
|
}
|
|
@@ -159710,7 +160030,7 @@ function loadModelsDevMetadataFromFile() {
|
|
|
159710
160030
|
const modelsJsonPath = getModelsJsonPath();
|
|
159711
160031
|
let fileFound = false;
|
|
159712
160032
|
try {
|
|
159713
|
-
if (
|
|
160033
|
+
if (existsSync10(modelsJsonPath)) {
|
|
159714
160034
|
fileFound = true;
|
|
159715
160035
|
const raw = readFileSync7(modelsJsonPath, "utf-8");
|
|
159716
160036
|
const data = JSON.parse(raw);
|
|
@@ -159727,7 +160047,7 @@ function loadModelsDevMetadataFromFile() {
|
|
|
159727
160047
|
}
|
|
159728
160048
|
try {
|
|
159729
160049
|
const configPath = getOpencodeConfigPath();
|
|
159730
|
-
if (configPath &&
|
|
160050
|
+
if (configPath && existsSync10(configPath)) {
|
|
159731
160051
|
let raw = readFileSync7(configPath, "utf-8");
|
|
159732
160052
|
raw = raw.replace(/"(?:[^"\\]|\\.)*"|\/\/.*$/gm, (match) => match.startsWith('"') ? match : "");
|
|
159733
160053
|
const config2 = JSON.parse(raw);
|
|
@@ -160059,9 +160379,9 @@ var init_compartment_runner_validation = __esm(async () => {
|
|
|
160059
160379
|
});
|
|
160060
160380
|
|
|
160061
160381
|
// src/hooks/magic-context/compartment-runner-historian.ts
|
|
160062
|
-
import { mkdirSync as
|
|
160382
|
+
import { mkdirSync as mkdirSync4, unlinkSync, writeFileSync as writeFileSync4 } from "node:fs";
|
|
160063
160383
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
160064
|
-
import { join as
|
|
160384
|
+
import { join as join16 } from "node:path";
|
|
160065
160385
|
async function runValidatedHistorianPass(args) {
|
|
160066
160386
|
const firstRun = await runHistorianPrompt({
|
|
160067
160387
|
...args,
|
|
@@ -160301,11 +160621,11 @@ function cleanupHistorianDump(sessionId, dumpPath) {
|
|
|
160301
160621
|
}
|
|
160302
160622
|
function dumpHistorianResponse(sessionId, label, text) {
|
|
160303
160623
|
try {
|
|
160304
|
-
|
|
160624
|
+
mkdirSync4(HISTORIAN_RESPONSE_DUMP_DIR, { recursive: true });
|
|
160305
160625
|
const safeSessionId = sanitizeDumpName(sessionId);
|
|
160306
160626
|
const safeLabel = sanitizeDumpName(label);
|
|
160307
|
-
const dumpPath =
|
|
160308
|
-
|
|
160627
|
+
const dumpPath = join16(HISTORIAN_RESPONSE_DUMP_DIR, `${safeSessionId}-${safeLabel}-${Date.now()}.xml`);
|
|
160628
|
+
writeFileSync4(dumpPath, text, "utf8");
|
|
160309
160629
|
sessionLog(sessionId, "compartment agent: historian response dumped", {
|
|
160310
160630
|
label,
|
|
160311
160631
|
dumpPath
|
|
@@ -160329,7 +160649,7 @@ var init_compartment_runner_historian = __esm(async () => {
|
|
|
160329
160649
|
init_assistant_message_extractor();
|
|
160330
160650
|
init_compartment_prompt();
|
|
160331
160651
|
await init_compartment_runner_validation();
|
|
160332
|
-
HISTORIAN_RESPONSE_DUMP_DIR =
|
|
160652
|
+
HISTORIAN_RESPONSE_DUMP_DIR = join16(tmpdir2(), "magic-context-historian");
|
|
160333
160653
|
});
|
|
160334
160654
|
|
|
160335
160655
|
// src/hooks/magic-context/compartment-runner-state-xml.ts
|
|
@@ -161308,7 +161628,7 @@ var init_derive_budgets = __esm(() => {
|
|
|
161308
161628
|
});
|
|
161309
161629
|
|
|
161310
161630
|
// src/features/magic-context/compaction-marker.ts
|
|
161311
|
-
import { join as
|
|
161631
|
+
import { join as join17 } from "node:path";
|
|
161312
161632
|
function randomBase62(length) {
|
|
161313
161633
|
const chars = [];
|
|
161314
161634
|
for (let i = 0;i < length; i++) {
|
|
@@ -161328,7 +161648,7 @@ function generatePartId(timestampMs, counter = 0n) {
|
|
|
161328
161648
|
return generateId("prt", timestampMs, counter);
|
|
161329
161649
|
}
|
|
161330
161650
|
function getOpenCodeDbPath3() {
|
|
161331
|
-
return
|
|
161651
|
+
return join17(getDataDir(), "opencode", "opencode.db");
|
|
161332
161652
|
}
|
|
161333
161653
|
function isOpenCodeSchemaCompatible(db, dbPath) {
|
|
161334
161654
|
if (cachedSchemaCompatible?.path === dbPath) {
|
|
@@ -161465,7 +161785,7 @@ var init_compaction_marker = __esm(async () => {
|
|
|
161465
161785
|
});
|
|
161466
161786
|
|
|
161467
161787
|
// src/hooks/magic-context/compaction-marker-manager.ts
|
|
161468
|
-
import { join as
|
|
161788
|
+
import { join as join18 } from "node:path";
|
|
161469
161789
|
function updateCompactionMarkerAfterPublication(db, sessionId, lastCompartmentEnd, directory) {
|
|
161470
161790
|
const existing = getPersistedCompactionMarkerState(db, sessionId);
|
|
161471
161791
|
if (existing) {
|
|
@@ -161508,7 +161828,7 @@ function removeCompactionMarkerForSession(db, sessionId) {
|
|
|
161508
161828
|
}
|
|
161509
161829
|
}
|
|
161510
161830
|
function checkCompactionMarkerConsistency(db) {
|
|
161511
|
-
const opencodeDbPath =
|
|
161831
|
+
const opencodeDbPath = join18(getDataDir(), "opencode", "opencode.db");
|
|
161512
161832
|
let opencodeDb;
|
|
161513
161833
|
try {
|
|
161514
161834
|
opencodeDb = new Database(opencodeDbPath, { readonly: true });
|
|
@@ -161895,31 +162215,31 @@ var init_caveman = __esm(() => {
|
|
|
161895
162215
|
});
|
|
161896
162216
|
|
|
161897
162217
|
// src/hooks/magic-context/historian-state-file.ts
|
|
161898
|
-
import { mkdirSync as
|
|
162218
|
+
import { mkdirSync as mkdirSync5, unlinkSync as unlinkSync2, writeFileSync as writeFileSync5 } from "node:fs";
|
|
161899
162219
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
161900
|
-
import { join as
|
|
162220
|
+
import { join as join19 } from "node:path";
|
|
161901
162221
|
function maybeWriteHistorianStateFile(sessionId, existingState) {
|
|
161902
162222
|
if (existingState.length <= HISTORIAN_STATE_INLINE_THRESHOLD)
|
|
161903
162223
|
return;
|
|
161904
162224
|
try {
|
|
161905
|
-
|
|
161906
|
-
const
|
|
161907
|
-
|
|
161908
|
-
return
|
|
162225
|
+
mkdirSync5(HISTORIAN_STATE_DIR, { recursive: true });
|
|
162226
|
+
const path5 = join19(HISTORIAN_STATE_DIR, `state-${sessionId}-${Date.now()}.xml`);
|
|
162227
|
+
writeFileSync5(path5, existingState, "utf8");
|
|
162228
|
+
return path5;
|
|
161909
162229
|
} catch {
|
|
161910
162230
|
return;
|
|
161911
162231
|
}
|
|
161912
162232
|
}
|
|
161913
|
-
function cleanupHistorianStateFile(
|
|
161914
|
-
if (!
|
|
162233
|
+
function cleanupHistorianStateFile(path5) {
|
|
162234
|
+
if (!path5)
|
|
161915
162235
|
return;
|
|
161916
162236
|
try {
|
|
161917
|
-
unlinkSync2(
|
|
162237
|
+
unlinkSync2(path5);
|
|
161918
162238
|
} catch {}
|
|
161919
162239
|
}
|
|
161920
162240
|
var HISTORIAN_STATE_INLINE_THRESHOLD = 30000, HISTORIAN_STATE_DIR;
|
|
161921
162241
|
var init_historian_state_file = __esm(() => {
|
|
161922
|
-
HISTORIAN_STATE_DIR =
|
|
162242
|
+
HISTORIAN_STATE_DIR = join19(tmpdir3(), "magic-context-historian");
|
|
161923
162243
|
});
|
|
161924
162244
|
|
|
161925
162245
|
// src/features/magic-context/memory/embedding-backfill.ts
|
|
@@ -162989,8 +163309,8 @@ var exports_tui_config = {};
|
|
|
162989
163309
|
__export(exports_tui_config, {
|
|
162990
163310
|
ensureTuiPluginEntry: () => ensureTuiPluginEntry
|
|
162991
163311
|
});
|
|
162992
|
-
import { existsSync as
|
|
162993
|
-
import { dirname as
|
|
163312
|
+
import { existsSync as existsSync12, mkdirSync as mkdirSync7, readFileSync as readFileSync9, writeFileSync as writeFileSync7 } from "node:fs";
|
|
163313
|
+
import { dirname as dirname6, join as join22 } from "node:path";
|
|
162994
163314
|
function isMagicContextEntry(entry) {
|
|
162995
163315
|
if (!entry)
|
|
162996
163316
|
return false;
|
|
@@ -163004,11 +163324,11 @@ function isMagicContextEntry(entry) {
|
|
|
163004
163324
|
}
|
|
163005
163325
|
function resolveTuiConfigPath() {
|
|
163006
163326
|
const configDir = getOpenCodeConfigPaths({ binary: "opencode" }).configDir;
|
|
163007
|
-
const jsoncPath =
|
|
163008
|
-
const jsonPath =
|
|
163009
|
-
if (
|
|
163327
|
+
const jsoncPath = join22(configDir, "tui.jsonc");
|
|
163328
|
+
const jsonPath = join22(configDir, "tui.json");
|
|
163329
|
+
if (existsSync12(jsoncPath))
|
|
163010
163330
|
return jsoncPath;
|
|
163011
|
-
if (
|
|
163331
|
+
if (existsSync12(jsonPath))
|
|
163012
163332
|
return jsonPath;
|
|
163013
163333
|
return jsonPath;
|
|
163014
163334
|
}
|
|
@@ -163016,7 +163336,7 @@ function ensureTuiPluginEntry() {
|
|
|
163016
163336
|
try {
|
|
163017
163337
|
const configPath = resolveTuiConfigPath();
|
|
163018
163338
|
let config2 = {};
|
|
163019
|
-
if (
|
|
163339
|
+
if (existsSync12(configPath)) {
|
|
163020
163340
|
const raw = readFileSync9(configPath, "utf-8");
|
|
163021
163341
|
config2 = import_comment_json3.parse(raw) ?? {};
|
|
163022
163342
|
}
|
|
@@ -163036,8 +163356,8 @@ function ensureTuiPluginEntry() {
|
|
|
163036
163356
|
plugins.push(PLUGIN_ENTRY);
|
|
163037
163357
|
}
|
|
163038
163358
|
config2.plugin = plugins;
|
|
163039
|
-
|
|
163040
|
-
|
|
163359
|
+
mkdirSync7(dirname6(configPath), { recursive: true });
|
|
163360
|
+
writeFileSync7(configPath, `${import_comment_json3.stringify(config2, null, 2)}
|
|
163041
163361
|
`);
|
|
163042
163362
|
log(`[magic-context] updated TUI plugin entry in ${configPath}`);
|
|
163043
163363
|
return true;
|
|
@@ -164130,24 +164450,27 @@ function stripPackageNameFromPath(pathValue, packageName) {
|
|
|
164130
164450
|
}
|
|
164131
164451
|
return current;
|
|
164132
164452
|
}
|
|
164133
|
-
function
|
|
164134
|
-
const lockPath = join5(installDir, "
|
|
164453
|
+
function removeFromPackageLock(installDir, packageName) {
|
|
164454
|
+
const lockPath = join5(installDir, "package-lock.json");
|
|
164135
164455
|
if (!existsSync5(lockPath))
|
|
164136
164456
|
return false;
|
|
164137
164457
|
try {
|
|
164138
164458
|
const lock = import_comment_json2.parse(readFileSync5(lockPath, "utf-8"));
|
|
164139
164459
|
let modified = false;
|
|
164140
|
-
if (lock.
|
|
164141
|
-
|
|
164142
|
-
|
|
164460
|
+
if (lock.packages) {
|
|
164461
|
+
const key = `node_modules/${packageName}`;
|
|
164462
|
+
if (lock.packages[key] !== undefined) {
|
|
164463
|
+
delete lock.packages[key];
|
|
164464
|
+
modified = true;
|
|
164465
|
+
}
|
|
164143
164466
|
}
|
|
164144
|
-
if (lock.
|
|
164145
|
-
delete lock.
|
|
164467
|
+
if (lock.dependencies?.[packageName]) {
|
|
164468
|
+
delete lock.dependencies[packageName];
|
|
164146
164469
|
modified = true;
|
|
164147
164470
|
}
|
|
164148
164471
|
if (modified) {
|
|
164149
164472
|
writeFileSync2(lockPath, JSON.stringify(lock, null, 2));
|
|
164150
|
-
log(`[auto-update-checker] Removed from
|
|
164473
|
+
log(`[auto-update-checker] Removed from package-lock.json: ${packageName}`);
|
|
164151
164474
|
}
|
|
164152
164475
|
return modified;
|
|
164153
164476
|
} catch {
|
|
@@ -164212,7 +164535,7 @@ function preparePackageUpdate(version2, packageName = PACKAGE_NAME, runtimePacka
|
|
|
164212
164535
|
if (!ensureDependencyVersion(installContext.packageJsonPath, packageName, version2))
|
|
164213
164536
|
return null;
|
|
164214
164537
|
const packageRemoved = removeInstalledPackage(installContext.installDir, packageName);
|
|
164215
|
-
const lockRemoved =
|
|
164538
|
+
const lockRemoved = removeFromPackageLock(installContext.installDir, packageName);
|
|
164216
164539
|
if (!packageRemoved && !lockRemoved) {
|
|
164217
164540
|
log(`[auto-update-checker] No cached package artifacts removed for ${packageName}; continuing with updated dependency spec`);
|
|
164218
164541
|
}
|
|
@@ -164222,12 +164545,12 @@ function preparePackageUpdate(version2, packageName = PACKAGE_NAME, runtimePacka
|
|
|
164222
164545
|
return null;
|
|
164223
164546
|
}
|
|
164224
164547
|
}
|
|
164225
|
-
async function
|
|
164548
|
+
async function runNpmInstallSafe(installDir, options = {}) {
|
|
164226
164549
|
let timeout = null;
|
|
164227
164550
|
try {
|
|
164228
164551
|
if (options.signal?.aborted)
|
|
164229
164552
|
return false;
|
|
164230
|
-
const proc = spawn("
|
|
164553
|
+
const proc = spawn("npm", ["install", "--no-audit", "--no-fund", "--no-progress"], {
|
|
164231
164554
|
cwd: installDir,
|
|
164232
164555
|
stdio: "pipe"
|
|
164233
164556
|
});
|
|
@@ -164252,7 +164575,7 @@ async function runBunInstallSafe(installDir, options = {}) {
|
|
|
164252
164575
|
}
|
|
164253
164576
|
return result;
|
|
164254
164577
|
} catch (err) {
|
|
164255
|
-
warn2(`[auto-update-checker]
|
|
164578
|
+
warn2(`[auto-update-checker] npm install error: ${String(err)}`);
|
|
164256
164579
|
return false;
|
|
164257
164580
|
} finally {
|
|
164258
164581
|
if (timeout)
|
|
@@ -164370,7 +164693,7 @@ async function runBackgroundUpdateCheck(ctx, options) {
|
|
|
164370
164693
|
warn3("[auto-update-checker] Failed to prepare install root for auto-update");
|
|
164371
164694
|
return;
|
|
164372
164695
|
}
|
|
164373
|
-
const installSuccess = await
|
|
164696
|
+
const installSuccess = await runNpmInstallSafe(installDir, { signal: options.signal });
|
|
164374
164697
|
if (installSuccess) {
|
|
164375
164698
|
showToast(ctx, "Magic Context Updated!", `v${currentVersion} → v${latestVersion}
|
|
164376
164699
|
Restart OpenCode to apply.`, "success", 8000);
|
|
@@ -164378,7 +164701,7 @@ Restart OpenCode to apply.`, "success", 8000);
|
|
|
164378
164701
|
return;
|
|
164379
164702
|
}
|
|
164380
164703
|
showToast(ctx, `Magic Context ${latestVersion}`, `v${latestVersion} available, but auto-update failed to install it. Check logs or retry manually.`, "error", 8000);
|
|
164381
|
-
warn3("[auto-update-checker]
|
|
164704
|
+
warn3("[auto-update-checker] npm install failed; update not installed");
|
|
164382
164705
|
}
|
|
164383
164706
|
function showToast(ctx, title, message, variant = "info", duration3 = 3000) {
|
|
164384
164707
|
ctx.client.tui.showToast({ body: { title, message, variant, duration: duration3 } }).catch(() => {});
|
|
@@ -164395,7 +164718,8 @@ function createLiveSessionState() {
|
|
|
164395
164718
|
agentBySession: new Map,
|
|
164396
164719
|
historyRefreshSessions: new Set,
|
|
164397
164720
|
systemPromptRefreshSessions: new Set,
|
|
164398
|
-
pendingMaterializationSessions: new Set
|
|
164721
|
+
pendingMaterializationSessions: new Set,
|
|
164722
|
+
sessionDirectoryBySession: new Map
|
|
164399
164723
|
};
|
|
164400
164724
|
}
|
|
164401
164725
|
|
|
@@ -164562,8 +164886,8 @@ init_assistant_message_extractor();
|
|
|
164562
164886
|
init_data_path();
|
|
164563
164887
|
init_logger();
|
|
164564
164888
|
await init_sqlite();
|
|
164565
|
-
import { existsSync as
|
|
164566
|
-
import { join as
|
|
164889
|
+
import { existsSync as existsSync8 } from "node:fs";
|
|
164890
|
+
import { join as join12 } from "node:path";
|
|
164567
164891
|
|
|
164568
164892
|
// src/features/magic-context/key-files/identify-key-files.ts
|
|
164569
164893
|
init_logger();
|
|
@@ -164954,11 +165278,11 @@ function countNewIds(beforeIds, afterIds) {
|
|
|
164954
165278
|
return count;
|
|
164955
165279
|
}
|
|
164956
165280
|
function getOpenCodeDbPath2() {
|
|
164957
|
-
return
|
|
165281
|
+
return join12(getDataDir(), "opencode", "opencode.db");
|
|
164958
165282
|
}
|
|
164959
165283
|
function openOpenCodeDb() {
|
|
164960
165284
|
const dbPath = getOpenCodeDbPath2();
|
|
164961
|
-
if (!
|
|
165285
|
+
if (!existsSync8(dbPath)) {
|
|
164962
165286
|
log(`[key-files] OpenCode DB not found at ${dbPath} — skipping`);
|
|
164963
165287
|
return null;
|
|
164964
165288
|
}
|
|
@@ -165208,8 +165532,8 @@ async function runDream(args) {
|
|
|
165208
165532
|
try {
|
|
165209
165533
|
const docsDir = args.sessionDirectory ?? args.projectIdentity;
|
|
165210
165534
|
const existingDocs = taskName === "maintain-docs" ? {
|
|
165211
|
-
architecture:
|
|
165212
|
-
structure:
|
|
165535
|
+
architecture: existsSync8(join12(docsDir, "ARCHITECTURE.md")),
|
|
165536
|
+
structure: existsSync8(join12(docsDir, "STRUCTURE.md"))
|
|
165213
165537
|
} : undefined;
|
|
165214
165538
|
const userMemories = taskName === "archive-stale" ? getActiveUserMemories(args.db).map((um) => ({
|
|
165215
165539
|
id: um.id,
|
|
@@ -170508,12 +170832,16 @@ function createTransform(deps) {
|
|
|
170508
170832
|
const reducedMode = sessionMeta.isSubagent;
|
|
170509
170833
|
const fullFeatureMode = !reducedMode;
|
|
170510
170834
|
let sessionDirectory = deps.directory ?? "";
|
|
170511
|
-
|
|
170835
|
+
const cachedDirectory = deps.sessionDirectoryBySession?.get(sessionId);
|
|
170836
|
+
if (cachedDirectory && cachedDirectory.length > 0) {
|
|
170837
|
+
sessionDirectory = cachedDirectory;
|
|
170838
|
+
} else if (deps.client !== undefined) {
|
|
170512
170839
|
try {
|
|
170513
170840
|
const sessionResponse = await deps.client.session.get({ path: { id: sessionId } }).catch(() => null);
|
|
170514
170841
|
const sessionInfo = sessionResponse?.data;
|
|
170515
170842
|
if (sessionInfo && typeof sessionInfo.directory === "string" && sessionInfo.directory.length > 0) {
|
|
170516
170843
|
sessionDirectory = sessionInfo.directory;
|
|
170844
|
+
deps.sessionDirectoryBySession?.set(sessionId, sessionDirectory);
|
|
170517
170845
|
}
|
|
170518
170846
|
} catch {}
|
|
170519
170847
|
}
|
|
@@ -171570,6 +171898,7 @@ function createEventHook(args) {
|
|
|
171570
171898
|
args.liveModelBySession.delete(sessionId);
|
|
171571
171899
|
args.variantBySession.delete(sessionId);
|
|
171572
171900
|
args.agentBySession.delete(sessionId);
|
|
171901
|
+
args.sessionDirectoryBySession.delete(sessionId);
|
|
171573
171902
|
args.recentReduceBySession.delete(sessionId);
|
|
171574
171903
|
args.toolUsageSinceUserTurn.delete(sessionId);
|
|
171575
171904
|
args.historyRefreshSessions.delete(sessionId);
|
|
@@ -171627,8 +171956,8 @@ init_send_session_notification();
|
|
|
171627
171956
|
|
|
171628
171957
|
// src/hooks/magic-context/system-prompt-hash.ts
|
|
171629
171958
|
import { createHash as createHash4 } from "node:crypto";
|
|
171630
|
-
import { existsSync as
|
|
171631
|
-
import { join as
|
|
171959
|
+
import { existsSync as existsSync11, readFileSync as readFileSync8, realpathSync } from "node:fs";
|
|
171960
|
+
import { join as join20, resolve as resolve4, sep } from "node:path";
|
|
171632
171961
|
|
|
171633
171962
|
// src/agents/magic-context-prompt.ts
|
|
171634
171963
|
function getToolHistoryGuidance(dropToolStructure) {
|
|
@@ -171741,9 +172070,9 @@ var DOC_FILES = ["ARCHITECTURE.md", "STRUCTURE.md"];
|
|
|
171741
172070
|
function readProjectDocs(directory) {
|
|
171742
172071
|
const sections = [];
|
|
171743
172072
|
for (const filename of DOC_FILES) {
|
|
171744
|
-
const filePath =
|
|
172073
|
+
const filePath = join20(directory, filename);
|
|
171745
172074
|
try {
|
|
171746
|
-
if (
|
|
172075
|
+
if (existsSync11(filePath)) {
|
|
171747
172076
|
const content = readFileSync8(filePath, "utf-8").trim();
|
|
171748
172077
|
if (content.length > 0) {
|
|
171749
172078
|
sections.push(`<${filename}>
|
|
@@ -171856,7 +172185,7 @@ ${items}
|
|
|
171856
172185
|
log(`[magic-context] key file path escapes project root, skipping: ${entry.filePath}`);
|
|
171857
172186
|
continue;
|
|
171858
172187
|
}
|
|
171859
|
-
if (!
|
|
172188
|
+
if (!existsSync11(absPath))
|
|
171860
172189
|
continue;
|
|
171861
172190
|
let realPath;
|
|
171862
172191
|
try {
|
|
@@ -172024,6 +172353,7 @@ function createMagicContextHook(deps) {
|
|
|
172024
172353
|
const variantBySession = deps.liveSessionState?.variantBySession ?? new Map;
|
|
172025
172354
|
const liveModelBySession = deps.liveSessionState?.liveModelBySession ?? new Map;
|
|
172026
172355
|
const agentBySession = deps.liveSessionState?.agentBySession ?? new Map;
|
|
172356
|
+
const sessionDirectoryBySession = deps.liveSessionState?.sessionDirectoryBySession ?? new Map;
|
|
172027
172357
|
const recentReduceBySession = new Map;
|
|
172028
172358
|
const toolUsageSinceUserTurn = new Map;
|
|
172029
172359
|
const resolveLiveModel = (sessionId) => {
|
|
@@ -172091,6 +172421,7 @@ function createMagicContextHook(deps) {
|
|
|
172091
172421
|
compressorMaxMergeDepth: deps.config.compressor?.enabled === false ? undefined : deps.config.compressor?.max_merge_depth,
|
|
172092
172422
|
compressorCooldownMs: deps.config.compressor?.enabled === false ? undefined : deps.config.compressor?.cooldown_ms,
|
|
172093
172423
|
liveModelBySession,
|
|
172424
|
+
sessionDirectoryBySession,
|
|
172094
172425
|
autoSearch: deps.config.experimental?.auto_search?.enabled ? {
|
|
172095
172426
|
enabled: true,
|
|
172096
172427
|
scoreThreshold: deps.config.experimental.auto_search.score_threshold,
|
|
@@ -172255,6 +172586,7 @@ function createMagicContextHook(deps) {
|
|
|
172255
172586
|
liveModelBySession,
|
|
172256
172587
|
variantBySession,
|
|
172257
172588
|
agentBySession,
|
|
172589
|
+
sessionDirectoryBySession,
|
|
172258
172590
|
recentReduceBySession,
|
|
172259
172591
|
toolUsageSinceUserTurn,
|
|
172260
172592
|
historyRefreshSessions,
|
|
@@ -173898,19 +174230,19 @@ init_models_dev_cache();
|
|
|
173898
174230
|
|
|
173899
174231
|
// src/shared/rpc-server.ts
|
|
173900
174232
|
init_logger();
|
|
173901
|
-
import { mkdirSync as
|
|
174233
|
+
import { mkdirSync as mkdirSync6, renameSync, unlinkSync as unlinkSync3, writeFileSync as writeFileSync6 } from "node:fs";
|
|
173902
174234
|
import { createServer } from "node:http";
|
|
173903
|
-
import { dirname as
|
|
174235
|
+
import { dirname as dirname5 } from "node:path";
|
|
173904
174236
|
|
|
173905
174237
|
// src/shared/rpc-utils.ts
|
|
173906
174238
|
import { createHash as createHash5 } from "node:crypto";
|
|
173907
|
-
import { join as
|
|
174239
|
+
import { join as join21 } from "node:path";
|
|
173908
174240
|
function projectHash(directory) {
|
|
173909
174241
|
const normalized = directory.replace(/\/+$/, "");
|
|
173910
174242
|
return createHash5("sha256").update(normalized).digest("hex").slice(0, 16);
|
|
173911
174243
|
}
|
|
173912
174244
|
function rpcPortFilePath(storageDir, directory) {
|
|
173913
|
-
return
|
|
174245
|
+
return join21(storageDir, "rpc", projectHash(directory), "port");
|
|
173914
174246
|
}
|
|
173915
174247
|
|
|
173916
174248
|
// src/shared/rpc-server.ts
|
|
@@ -173941,10 +174273,10 @@ class MagicContextRpcServer {
|
|
|
173941
174273
|
this.port = addr.port;
|
|
173942
174274
|
this.server = server;
|
|
173943
174275
|
try {
|
|
173944
|
-
const dir =
|
|
173945
|
-
|
|
174276
|
+
const dir = dirname5(this.portFilePath);
|
|
174277
|
+
mkdirSync6(dir, { recursive: true });
|
|
173946
174278
|
const tmpPath = `${this.portFilePath}.tmp`;
|
|
173947
|
-
|
|
174279
|
+
writeFileSync6(tmpPath, String(this.port), "utf-8");
|
|
173948
174280
|
renameSync(tmpPath, this.portFilePath);
|
|
173949
174281
|
log(`[rpc] server listening on 127.0.0.1:${this.port}`);
|
|
173950
174282
|
} catch (err) {
|