@cortexkit/magic-context 0.17.1 → 0.18.0
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 +174 -133
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -7926,19 +7926,27 @@ function dirSizeBytes(path) {
|
|
|
7926
7926
|
var init_paths = () => {};
|
|
7927
7927
|
|
|
7928
7928
|
// src/adapters/opencode.ts
|
|
7929
|
-
import {
|
|
7929
|
+
import { execFileSync } from "node:child_process";
|
|
7930
7930
|
import { existsSync as existsSync2, readFileSync, writeFileSync } from "node:fs";
|
|
7931
|
-
import {
|
|
7931
|
+
import { homedir as homedir2 } from "node:os";
|
|
7932
|
+
import { dirname, join as join2 } from "node:path";
|
|
7932
7933
|
|
|
7933
7934
|
class OpenCodeAdapter {
|
|
7934
7935
|
kind = "opencode";
|
|
7935
7936
|
displayName = "OpenCode";
|
|
7936
7937
|
pluginPackageName = PLUGIN_NAME;
|
|
7937
7938
|
isInstalled() {
|
|
7938
|
-
|
|
7939
|
+
const isWindows = process.platform === "win32";
|
|
7940
|
+
const stockBin = isWindows ? join2(homedir2(), ".opencode", "bin", "opencode.exe") : join2(homedir2(), ".opencode", "bin", "opencode");
|
|
7941
|
+
if (existsSync2(stockBin))
|
|
7939
7942
|
return true;
|
|
7943
|
+
const probe = isWindows ? { cmd: "where", args: ["opencode"] } : { cmd: "command", args: ["-v", "opencode"] };
|
|
7940
7944
|
try {
|
|
7941
|
-
|
|
7945
|
+
if (!isWindows) {
|
|
7946
|
+
execFileSync("which", ["opencode"], { stdio: "ignore" });
|
|
7947
|
+
} else {
|
|
7948
|
+
execFileSync(probe.cmd, probe.args, { stdio: "ignore" });
|
|
7949
|
+
}
|
|
7942
7950
|
return true;
|
|
7943
7951
|
} catch {
|
|
7944
7952
|
return false;
|
|
@@ -8175,16 +8183,16 @@ var init_opencode = __esm(() => {
|
|
|
8175
8183
|
});
|
|
8176
8184
|
|
|
8177
8185
|
// src/lib/pi-helpers.ts
|
|
8178
|
-
import { execFileSync, spawnSync } from "node:child_process";
|
|
8186
|
+
import { execFileSync as execFileSync2, spawnSync } from "node:child_process";
|
|
8179
8187
|
import { existsSync as existsSync3 } from "node:fs";
|
|
8180
|
-
import { homedir as
|
|
8181
|
-
import { join as
|
|
8188
|
+
import { homedir as homedir3 } from "node:os";
|
|
8189
|
+
import { join as join3 } from "node:path";
|
|
8182
8190
|
function getStaticModels() {
|
|
8183
8191
|
return [...STATIC_MODELS];
|
|
8184
8192
|
}
|
|
8185
8193
|
function commandExists(command, args) {
|
|
8186
8194
|
try {
|
|
8187
|
-
const output =
|
|
8195
|
+
const output = execFileSync2(command, args, {
|
|
8188
8196
|
encoding: "utf-8",
|
|
8189
8197
|
stdio: ["ignore", "pipe", "ignore"]
|
|
8190
8198
|
}).trim();
|
|
@@ -8200,7 +8208,7 @@ function detectPiBinary() {
|
|
|
8200
8208
|
if (first)
|
|
8201
8209
|
return { path: first, source: "path" };
|
|
8202
8210
|
}
|
|
8203
|
-
const homeCandidate = process.platform === "win32" ?
|
|
8211
|
+
const homeCandidate = process.platform === "win32" ? join3(homedir3(), ".pi", "bin", "pi.cmd") : join3(homedir3(), ".pi", "bin", "pi");
|
|
8204
8212
|
if (existsSync3(homeCandidate))
|
|
8205
8213
|
return { path: homeCandidate, source: "home" };
|
|
8206
8214
|
return null;
|
|
@@ -8224,7 +8232,7 @@ function getPiVersion(piPath) {
|
|
|
8224
8232
|
}
|
|
8225
8233
|
function runPi(piPath, args) {
|
|
8226
8234
|
try {
|
|
8227
|
-
return
|
|
8235
|
+
return execFileSync2(piPath, args, {
|
|
8228
8236
|
encoding: "utf-8",
|
|
8229
8237
|
stdio: ["ignore", "pipe", "ignore"],
|
|
8230
8238
|
timeout: 20000
|
|
@@ -8351,7 +8359,7 @@ var init_pi_helpers = __esm(() => {
|
|
|
8351
8359
|
});
|
|
8352
8360
|
|
|
8353
8361
|
// src/adapters/pi.ts
|
|
8354
|
-
import { execFileSync as
|
|
8362
|
+
import { execFileSync as execFileSync3 } from "node:child_process";
|
|
8355
8363
|
import { existsSync as existsSync4, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
8356
8364
|
import { dirname as dirname2 } from "node:path";
|
|
8357
8365
|
|
|
@@ -8462,7 +8470,7 @@ class PiAdapter {
|
|
|
8462
8470
|
if (!piBin)
|
|
8463
8471
|
return null;
|
|
8464
8472
|
try {
|
|
8465
|
-
const output =
|
|
8473
|
+
const output = execFileSync3(piBin.path, ["list"], {
|
|
8466
8474
|
encoding: "utf-8",
|
|
8467
8475
|
stdio: ["ignore", "pipe", "ignore"],
|
|
8468
8476
|
timeout: 5000
|
|
@@ -10319,17 +10327,17 @@ function detectConfigFile(basePath) {
|
|
|
10319
10327
|
var init_jsonc_parser = () => {};
|
|
10320
10328
|
|
|
10321
10329
|
// ../plugin/src/shared/opencode-config-dir.ts
|
|
10322
|
-
import { homedir as
|
|
10323
|
-
import { join as
|
|
10330
|
+
import { homedir as homedir4 } from "node:os";
|
|
10331
|
+
import { join as join4, resolve } from "node:path";
|
|
10324
10332
|
function getCliConfigDir() {
|
|
10325
10333
|
const envConfigDir = process.env.OPENCODE_CONFIG_DIR?.trim();
|
|
10326
10334
|
if (envConfigDir) {
|
|
10327
10335
|
return resolve(envConfigDir);
|
|
10328
10336
|
}
|
|
10329
10337
|
if (process.platform === "win32") {
|
|
10330
|
-
return
|
|
10338
|
+
return join4(homedir4(), ".config", "opencode");
|
|
10331
10339
|
}
|
|
10332
|
-
return
|
|
10340
|
+
return join4(process.env.XDG_CONFIG_HOME || join4(homedir4(), ".config"), "opencode");
|
|
10333
10341
|
}
|
|
10334
10342
|
function getOpenCodeConfigDir2(_options) {
|
|
10335
10343
|
return getCliConfigDir();
|
|
@@ -10338,16 +10346,16 @@ function getOpenCodeConfigPaths(options) {
|
|
|
10338
10346
|
const configDir = getOpenCodeConfigDir2(options);
|
|
10339
10347
|
return {
|
|
10340
10348
|
configDir,
|
|
10341
|
-
configJson:
|
|
10342
|
-
configJsonc:
|
|
10343
|
-
packageJson:
|
|
10344
|
-
omoConfig:
|
|
10349
|
+
configJson: join4(configDir, "opencode.json"),
|
|
10350
|
+
configJsonc: join4(configDir, "opencode.jsonc"),
|
|
10351
|
+
packageJson: join4(configDir, "package.json"),
|
|
10352
|
+
omoConfig: join4(configDir, "magic-context.jsonc")
|
|
10345
10353
|
};
|
|
10346
10354
|
}
|
|
10347
10355
|
var init_opencode_config_dir = () => {};
|
|
10348
10356
|
|
|
10349
10357
|
// ../plugin/src/shared/conflict-detector.ts
|
|
10350
|
-
import { join as
|
|
10358
|
+
import { join as join5 } from "node:path";
|
|
10351
10359
|
function detectConflicts(directory) {
|
|
10352
10360
|
const conflicts = {
|
|
10353
10361
|
compactionAuto: false,
|
|
@@ -10404,8 +10412,8 @@ function checkCompaction(directory) {
|
|
|
10404
10412
|
return { auto: true, prune: false };
|
|
10405
10413
|
}
|
|
10406
10414
|
function readProjectCompaction(directory) {
|
|
10407
|
-
const dotOcJsonc =
|
|
10408
|
-
const dotOcJson =
|
|
10415
|
+
const dotOcJsonc = join5(directory, ".opencode", "opencode.jsonc");
|
|
10416
|
+
const dotOcJson = join5(directory, ".opencode", "opencode.json");
|
|
10409
10417
|
const dotOcConfig = readJsoncFile(dotOcJsonc) ?? readJsoncFile(dotOcJson);
|
|
10410
10418
|
if (dotOcConfig?.compaction) {
|
|
10411
10419
|
const c2 = dotOcConfig.compaction;
|
|
@@ -10413,8 +10421,8 @@ function readProjectCompaction(directory) {
|
|
|
10413
10421
|
return { auto: c2.auto === true, prune: c2.prune === true, resolved: true };
|
|
10414
10422
|
}
|
|
10415
10423
|
}
|
|
10416
|
-
const rootJsonc =
|
|
10417
|
-
const rootJson =
|
|
10424
|
+
const rootJsonc = join5(directory, "opencode.jsonc");
|
|
10425
|
+
const rootJson = join5(directory, "opencode.json");
|
|
10418
10426
|
const rootConfig = readJsoncFile(rootJsonc) ?? readJsoncFile(rootJson);
|
|
10419
10427
|
if (rootConfig?.compaction) {
|
|
10420
10428
|
const c2 = rootConfig.compaction;
|
|
@@ -10468,10 +10476,10 @@ function collectPluginEntries(directory) {
|
|
|
10468
10476
|
}
|
|
10469
10477
|
};
|
|
10470
10478
|
for (const configPath of [
|
|
10471
|
-
|
|
10472
|
-
|
|
10473
|
-
|
|
10474
|
-
|
|
10479
|
+
join5(directory, ".opencode", "opencode.jsonc"),
|
|
10480
|
+
join5(directory, ".opencode", "opencode.json"),
|
|
10481
|
+
join5(directory, "opencode.jsonc"),
|
|
10482
|
+
join5(directory, "opencode.json")
|
|
10475
10483
|
]) {
|
|
10476
10484
|
const config = readJsoncFile(configPath);
|
|
10477
10485
|
pushFrom(config?.plugin);
|
|
@@ -10512,7 +10520,7 @@ function readOmoDisabledHooks(directory) {
|
|
|
10512
10520
|
try {
|
|
10513
10521
|
const paths = getOpenCodeConfigPaths({ binary: "opencode" });
|
|
10514
10522
|
for (const name of configNames) {
|
|
10515
|
-
const configPath =
|
|
10523
|
+
const configPath = join5(paths.configDir, name);
|
|
10516
10524
|
const config = readJsoncFile(configPath);
|
|
10517
10525
|
if (config?.disabled_hooks) {
|
|
10518
10526
|
for (const hook of config.disabled_hooks) {
|
|
@@ -10522,7 +10530,7 @@ function readOmoDisabledHooks(directory) {
|
|
|
10522
10530
|
}
|
|
10523
10531
|
} catch {}
|
|
10524
10532
|
for (const name of configNames) {
|
|
10525
|
-
const config = readJsoncFile(
|
|
10533
|
+
const config = readJsoncFile(join5(directory, name));
|
|
10526
10534
|
if (config?.disabled_hooks) {
|
|
10527
10535
|
for (const hook of config.disabled_hooks) {
|
|
10528
10536
|
disabled.add(hook);
|
|
@@ -10541,7 +10549,7 @@ var init_conflict_detector = __esm(() => {
|
|
|
10541
10549
|
|
|
10542
10550
|
// ../plugin/src/shared/conflict-fixer.ts
|
|
10543
10551
|
import { existsSync as existsSync6, mkdirSync, writeFileSync as writeFileSync3 } from "node:fs";
|
|
10544
|
-
import { dirname as dirname3, join as
|
|
10552
|
+
import { dirname as dirname3, join as join6 } from "node:path";
|
|
10545
10553
|
function ensureParentDir(filePath) {
|
|
10546
10554
|
mkdirSync(dirname3(filePath), { recursive: true });
|
|
10547
10555
|
}
|
|
@@ -10573,10 +10581,10 @@ function collectOpenCodeConfigPaths(directory) {
|
|
|
10573
10581
|
const userConfig = resolveUserOpenCodeConfigPath();
|
|
10574
10582
|
paths.add(userConfig);
|
|
10575
10583
|
for (const filePath of [
|
|
10576
|
-
|
|
10577
|
-
|
|
10578
|
-
|
|
10579
|
-
|
|
10584
|
+
join6(directory, ".opencode", "opencode.jsonc"),
|
|
10585
|
+
join6(directory, ".opencode", "opencode.json"),
|
|
10586
|
+
join6(directory, "opencode.jsonc"),
|
|
10587
|
+
join6(directory, "opencode.json")
|
|
10580
10588
|
]) {
|
|
10581
10589
|
if (existsSync6(filePath)) {
|
|
10582
10590
|
paths.add(filePath);
|
|
@@ -10588,8 +10596,8 @@ function collectOmoConfigPaths(directory) {
|
|
|
10588
10596
|
const paths = new Set;
|
|
10589
10597
|
const configDir = getOpenCodeConfigPaths({ binary: "opencode" }).configDir;
|
|
10590
10598
|
for (const fileName of OMO_CONFIG_NAMES) {
|
|
10591
|
-
const userPath =
|
|
10592
|
-
const projectPath =
|
|
10599
|
+
const userPath = join6(configDir, fileName);
|
|
10600
|
+
const projectPath = join6(directory, fileName);
|
|
10593
10601
|
if (existsSync6(userPath)) {
|
|
10594
10602
|
paths.add(userPath);
|
|
10595
10603
|
}
|
|
@@ -10598,7 +10606,7 @@ function collectOmoConfigPaths(directory) {
|
|
|
10598
10606
|
}
|
|
10599
10607
|
}
|
|
10600
10608
|
if (paths.size === 0) {
|
|
10601
|
-
paths.add(
|
|
10609
|
+
paths.add(join6(configDir, "oh-my-openagent.json"));
|
|
10602
10610
|
}
|
|
10603
10611
|
return [...paths];
|
|
10604
10612
|
}
|
|
@@ -10705,10 +10713,10 @@ var init_conflict_fixer = __esm(() => {
|
|
|
10705
10713
|
});
|
|
10706
10714
|
|
|
10707
10715
|
// src/lib/opencode-helpers.ts
|
|
10708
|
-
import { execSync
|
|
10716
|
+
import { execSync } from "node:child_process";
|
|
10709
10717
|
function isOpenCodeInstalled() {
|
|
10710
10718
|
try {
|
|
10711
|
-
|
|
10719
|
+
execSync("opencode --version", { stdio: "pipe" });
|
|
10712
10720
|
return true;
|
|
10713
10721
|
} catch {
|
|
10714
10722
|
return false;
|
|
@@ -10716,14 +10724,14 @@ function isOpenCodeInstalled() {
|
|
|
10716
10724
|
}
|
|
10717
10725
|
function getOpenCodeVersion() {
|
|
10718
10726
|
try {
|
|
10719
|
-
return
|
|
10727
|
+
return execSync("opencode --version", { stdio: "pipe" }).toString().trim();
|
|
10720
10728
|
} catch {
|
|
10721
10729
|
return null;
|
|
10722
10730
|
}
|
|
10723
10731
|
}
|
|
10724
10732
|
function getAvailableModels2() {
|
|
10725
10733
|
try {
|
|
10726
|
-
const output =
|
|
10734
|
+
const output = execSync("opencode models", { stdio: "pipe" }).toString().trim();
|
|
10727
10735
|
return output.split(`
|
|
10728
10736
|
`).map((l) => l.trim()).filter(Boolean);
|
|
10729
10737
|
} catch {
|
|
@@ -11062,8 +11070,8 @@ async function runSetup() {
|
|
|
11062
11070
|
const shouldStar = await confirm("★ Star the repo on GitHub?", true);
|
|
11063
11071
|
if (shouldStar) {
|
|
11064
11072
|
try {
|
|
11065
|
-
const { execSync:
|
|
11066
|
-
|
|
11073
|
+
const { execSync: execSync2 } = await import("node:child_process");
|
|
11074
|
+
execSync2("gh api --silent --method PUT /user/starred/cortexkit/magic-context", {
|
|
11067
11075
|
stdio: "ignore",
|
|
11068
11076
|
timeout: 1e4
|
|
11069
11077
|
});
|
|
@@ -11799,16 +11807,16 @@ __export(exports_migrate, {
|
|
|
11799
11807
|
});
|
|
11800
11808
|
import { randomBytes } from "node:crypto";
|
|
11801
11809
|
import { existsSync as existsSync10, mkdirSync as mkdirSync5, writeFileSync as writeFileSync7 } from "node:fs";
|
|
11802
|
-
import { homedir as
|
|
11803
|
-
import { join as
|
|
11810
|
+
import { homedir as homedir6 } from "node:os";
|
|
11811
|
+
import { join as join10 } from "node:path";
|
|
11804
11812
|
function defaultOpenCodeDbPath() {
|
|
11805
|
-
return
|
|
11813
|
+
return join10(homedir6(), ".local", "share", "opencode", "opencode.db");
|
|
11806
11814
|
}
|
|
11807
11815
|
function defaultCortexkitDbPath() {
|
|
11808
|
-
return
|
|
11816
|
+
return join10(getMagicContextStorageDir(), "context.db");
|
|
11809
11817
|
}
|
|
11810
11818
|
function defaultPiSessionsRoot() {
|
|
11811
|
-
return
|
|
11819
|
+
return join10(homedir6(), ".pi", "agent", "sessions");
|
|
11812
11820
|
}
|
|
11813
11821
|
function defaultFs() {
|
|
11814
11822
|
return { existsSync: existsSync10, mkdirSync: mkdirSync5, writeFileSync: writeFileSync7 };
|
|
@@ -12234,7 +12242,7 @@ function migrateOpenCodeSessionToPi(opts) {
|
|
|
12234
12242
|
const provider = opts.provider ?? model.provider;
|
|
12235
12243
|
const modelId = opts.modelId ?? model.modelId;
|
|
12236
12244
|
const cwd = session.directory ?? session.path ?? process.cwd();
|
|
12237
|
-
const outputDir =
|
|
12245
|
+
const outputDir = join10(piSessionsRoot, projectPathToPiDirSlug(cwd));
|
|
12238
12246
|
const buildResult = buildPiEntries({
|
|
12239
12247
|
session,
|
|
12240
12248
|
messages,
|
|
@@ -12260,7 +12268,7 @@ function migrateOpenCodeSessionToPi(opts) {
|
|
|
12260
12268
|
});
|
|
12261
12269
|
}
|
|
12262
12270
|
const compactionMarker = insertCompactionMarker(buildResult.entries, copyResult.lastCompartmentEndPiEntryId);
|
|
12263
|
-
const outputPath =
|
|
12271
|
+
const outputPath = join10(outputDir, `${formatPiFilenameTimestamp(now)}_${buildResult.piSessionId}.jsonl`);
|
|
12264
12272
|
const jsonl = `${buildResult.entries.map((entry) => JSON.stringify(entry)).join(`
|
|
12265
12273
|
`)}
|
|
12266
12274
|
`;
|
|
@@ -27229,7 +27237,7 @@ var init_magic_context = __esm(() => {
|
|
|
27229
27237
|
|
|
27230
27238
|
// ../plugin/src/config/variable.ts
|
|
27231
27239
|
import { existsSync as existsSync11, readFileSync as readFileSync6 } from "node:fs";
|
|
27232
|
-
import { homedir as
|
|
27240
|
+
import { homedir as homedir7 } from "node:os";
|
|
27233
27241
|
import { dirname as dirname7, isAbsolute, resolve as resolve2 } from "node:path";
|
|
27234
27242
|
function substituteConfigVariables(input) {
|
|
27235
27243
|
const warnings = [];
|
|
@@ -27265,7 +27273,7 @@ function substituteConfigVariables(input) {
|
|
|
27265
27273
|
}
|
|
27266
27274
|
let filePath = rawPath.trim();
|
|
27267
27275
|
if (filePath.startsWith("~/")) {
|
|
27268
|
-
filePath = resolve2(
|
|
27276
|
+
filePath = resolve2(homedir7(), filePath.slice(2));
|
|
27269
27277
|
} else if (!isAbsolute(filePath)) {
|
|
27270
27278
|
filePath = resolve2(configDir, filePath);
|
|
27271
27279
|
}
|
|
@@ -27294,14 +27302,14 @@ var init_variable = __esm(() => {
|
|
|
27294
27302
|
|
|
27295
27303
|
// ../plugin/src/config/index.ts
|
|
27296
27304
|
import { existsSync as existsSync12, readFileSync as readFileSync7 } from "node:fs";
|
|
27297
|
-
import { homedir as
|
|
27298
|
-
import { join as
|
|
27305
|
+
import { homedir as homedir8 } from "node:os";
|
|
27306
|
+
import { join as join11 } from "node:path";
|
|
27299
27307
|
function getUserConfigBasePath() {
|
|
27300
|
-
const configRoot = process.env.XDG_CONFIG_HOME ??
|
|
27301
|
-
return
|
|
27308
|
+
const configRoot = process.env.XDG_CONFIG_HOME ?? join11(homedir8(), ".config");
|
|
27309
|
+
return join11(configRoot, "opencode", CONFIG_FILE_BASENAME);
|
|
27302
27310
|
}
|
|
27303
27311
|
function getProjectConfigBasePath(directory) {
|
|
27304
|
-
return
|
|
27312
|
+
return join11(directory, ".opencode", CONFIG_FILE_BASENAME);
|
|
27305
27313
|
}
|
|
27306
27314
|
function loadConfigFile(configPath) {
|
|
27307
27315
|
try {
|
|
@@ -27482,7 +27490,7 @@ function parsePluginConfig(rawConfig) {
|
|
|
27482
27490
|
}
|
|
27483
27491
|
function loadPluginConfig(directory) {
|
|
27484
27492
|
const userDetected = detectConfigFile(getUserConfigBasePath());
|
|
27485
|
-
const rootDetected = detectConfigFile(
|
|
27493
|
+
const rootDetected = detectConfigFile(join11(directory, CONFIG_FILE_BASENAME));
|
|
27486
27494
|
const dotOpenCodeDetected = detectConfigFile(getProjectConfigBasePath(directory));
|
|
27487
27495
|
const projectDetected = rootDetected.format !== "none" ? rootDetected : dotOpenCodeDetected;
|
|
27488
27496
|
const userLoaded = userDetected.format === "none" ? null : loadConfigFile(userDetected.path);
|
|
@@ -27627,7 +27635,7 @@ var DEFAULT_TIMEOUT_MS = 1e4, MAX_PREVIEW_CHARS = 240;
|
|
|
27627
27635
|
|
|
27628
27636
|
// ../plugin/src/shared/tui-config.ts
|
|
27629
27637
|
import { existsSync as existsSync13, mkdirSync as mkdirSync6, readFileSync as readFileSync8, writeFileSync as writeFileSync8 } from "node:fs";
|
|
27630
|
-
import { dirname as dirname8, join as
|
|
27638
|
+
import { dirname as dirname8, join as join12 } from "node:path";
|
|
27631
27639
|
function isMagicContextEntry(entry) {
|
|
27632
27640
|
if (!entry)
|
|
27633
27641
|
return false;
|
|
@@ -27641,8 +27649,8 @@ function isMagicContextEntry(entry) {
|
|
|
27641
27649
|
}
|
|
27642
27650
|
function resolveTuiConfigPath() {
|
|
27643
27651
|
const configDir = getOpenCodeConfigPaths({ binary: "opencode" }).configDir;
|
|
27644
|
-
const jsoncPath =
|
|
27645
|
-
const jsonPath =
|
|
27652
|
+
const jsoncPath = join12(configDir, "tui.jsonc");
|
|
27653
|
+
const jsonPath = join12(configDir, "tui.json");
|
|
27646
27654
|
if (existsSync13(jsoncPath))
|
|
27647
27655
|
return jsoncPath;
|
|
27648
27656
|
if (existsSync13(jsonPath))
|
|
@@ -27744,8 +27752,8 @@ var init_compartment_parser = __esm(() => {
|
|
|
27744
27752
|
// src/lib/diagnostics-opencode.ts
|
|
27745
27753
|
import { existsSync as existsSync14, readdirSync as readdirSync2, readFileSync as readFileSync9, statSync as statSync2 } from "node:fs";
|
|
27746
27754
|
import { createRequire as createRequire3 } from "node:module";
|
|
27747
|
-
import { homedir as
|
|
27748
|
-
import { join as
|
|
27755
|
+
import { homedir as homedir9, tmpdir as tmpdir3, userInfo } from "node:os";
|
|
27756
|
+
import { join as join13 } from "node:path";
|
|
27749
27757
|
function getSelfVersion() {
|
|
27750
27758
|
const require2 = createRequire3(import.meta.url);
|
|
27751
27759
|
for (const relPath of ["../../package.json", "../package.json"]) {
|
|
@@ -27759,10 +27767,10 @@ function getSelfVersion() {
|
|
|
27759
27767
|
return "unknown";
|
|
27760
27768
|
}
|
|
27761
27769
|
function getPluginCacheInfo() {
|
|
27762
|
-
const path4 =
|
|
27770
|
+
const path4 = join13(getOpenCodeCacheDir(), "packages", PLUGIN_ENTRY_WITH_VERSION);
|
|
27763
27771
|
let cached2;
|
|
27764
27772
|
try {
|
|
27765
|
-
const installedPkgPath =
|
|
27773
|
+
const installedPkgPath = join13(path4, "node_modules", "@cortexkit", "opencode-magic-context", "package.json");
|
|
27766
27774
|
if (existsSync14(installedPkgPath)) {
|
|
27767
27775
|
const pkg = JSON.parse(readFileSync9(installedPkgPath, "utf-8"));
|
|
27768
27776
|
cached2 = typeof pkg.version === "string" ? pkg.version : undefined;
|
|
@@ -27773,8 +27781,8 @@ function getPluginCacheInfo() {
|
|
|
27773
27781
|
return { path: path4, cached: cached2, latest: getSelfVersion() };
|
|
27774
27782
|
}
|
|
27775
27783
|
function getStorageDir() {
|
|
27776
|
-
const dataHome = process.env.XDG_DATA_HOME ||
|
|
27777
|
-
return
|
|
27784
|
+
const dataHome = process.env.XDG_DATA_HOME || join13(homedir9(), ".local", "share");
|
|
27785
|
+
return join13(dataHome, "cortexkit", "magic-context");
|
|
27778
27786
|
}
|
|
27779
27787
|
function fileSize(path4) {
|
|
27780
27788
|
try {
|
|
@@ -27787,7 +27795,7 @@ function escapeRegex2(value) {
|
|
|
27787
27795
|
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
27788
27796
|
}
|
|
27789
27797
|
function sanitizeString(value) {
|
|
27790
|
-
const home =
|
|
27798
|
+
const home = homedir9();
|
|
27791
27799
|
const username = userInfo().username;
|
|
27792
27800
|
let sanitized = value;
|
|
27793
27801
|
if (home) {
|
|
@@ -27871,13 +27879,13 @@ function parseHistorianDumpMeta(path4) {
|
|
|
27871
27879
|
}
|
|
27872
27880
|
}
|
|
27873
27881
|
function collectHistorianDumps() {
|
|
27874
|
-
const dir =
|
|
27882
|
+
const dir = join13(tmpdir3(), "magic-context-historian");
|
|
27875
27883
|
if (!existsSync14(dir)) {
|
|
27876
27884
|
return { dir, count: 0, recent: [] };
|
|
27877
27885
|
}
|
|
27878
27886
|
try {
|
|
27879
27887
|
const entries = readdirSync2(dir).filter((name) => name.endsWith(".xml")).map((name) => {
|
|
27880
|
-
const stat = statSync2(
|
|
27888
|
+
const stat = statSync2(join13(dir, name));
|
|
27881
27889
|
return {
|
|
27882
27890
|
name,
|
|
27883
27891
|
mtime: stat.mtimeMs,
|
|
@@ -27886,7 +27894,7 @@ function collectHistorianDumps() {
|
|
|
27886
27894
|
}).sort((a, b2) => b2.mtime - a.mtime);
|
|
27887
27895
|
const now = Date.now();
|
|
27888
27896
|
const recent = entries.slice(0, 5).map((entry) => {
|
|
27889
|
-
const meta3 = parseHistorianDumpMeta(
|
|
27897
|
+
const meta3 = parseHistorianDumpMeta(join13(dir, entry.name));
|
|
27890
27898
|
const summary = {
|
|
27891
27899
|
name: entry.name,
|
|
27892
27900
|
ageMinutes: Math.round((now - entry.mtime) / 60000),
|
|
@@ -27905,7 +27913,7 @@ function collectHistorianDumps() {
|
|
|
27905
27913
|
}
|
|
27906
27914
|
}
|
|
27907
27915
|
async function collectHistorianFailures(storageDirPath) {
|
|
27908
|
-
const contextDbPath =
|
|
27916
|
+
const contextDbPath = join13(storageDirPath, "context.db");
|
|
27909
27917
|
if (!existsSync14(contextDbPath))
|
|
27910
27918
|
return [];
|
|
27911
27919
|
if (typeof globalThis.Bun === "undefined") {
|
|
@@ -27945,8 +27953,8 @@ async function collectDiagnostics() {
|
|
|
27945
27953
|
const tuiConfig = readConfig2(configPaths.tuiConfig);
|
|
27946
27954
|
const magicContextConfig = readConfig2(configPaths.magicContextConfig);
|
|
27947
27955
|
const storageDirPath = getStorageDir();
|
|
27948
|
-
const contextDbPath =
|
|
27949
|
-
const logPath =
|
|
27956
|
+
const contextDbPath = join13(storageDirPath, "context.db");
|
|
27957
|
+
const logPath = join13(tmpdir3(), "magic-context.log");
|
|
27950
27958
|
const logFileSize = existsSync14(logPath) ? statSync2(logPath).size : 0;
|
|
27951
27959
|
const conflictResult = detectConflicts(process.cwd());
|
|
27952
27960
|
return {
|
|
@@ -28079,13 +28087,13 @@ var init_diagnostics_opencode = __esm(() => {
|
|
|
28079
28087
|
|
|
28080
28088
|
// src/lib/logs-opencode.ts
|
|
28081
28089
|
import { readFileSync as readFileSync10, writeFileSync as writeFileSync9 } from "node:fs";
|
|
28082
|
-
import { homedir as
|
|
28083
|
-
import { join as
|
|
28090
|
+
import { homedir as homedir10, userInfo as userInfo2 } from "node:os";
|
|
28091
|
+
import { join as join14 } from "node:path";
|
|
28084
28092
|
function escapeRegex3(value) {
|
|
28085
28093
|
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
28086
28094
|
}
|
|
28087
28095
|
function sanitizeLogContent(content) {
|
|
28088
|
-
const home =
|
|
28096
|
+
const home = homedir10();
|
|
28089
28097
|
const username = userInfo2().username;
|
|
28090
28098
|
let sanitized = content;
|
|
28091
28099
|
if (home) {
|
|
@@ -28140,7 +28148,7 @@ async function bundleIssueReport(report, description, _title) {
|
|
|
28140
28148
|
`));
|
|
28141
28149
|
const historianFailureLines = extractHistorianFailureLines(historianScanWindow, 30);
|
|
28142
28150
|
const configBody = JSON.stringify(report.magicContextConfig.flags, null, 2);
|
|
28143
|
-
const sanitizedConfigPath = report.configPaths.magicContextConfig.replace(
|
|
28151
|
+
const sanitizedConfigPath = report.configPaths.magicContextConfig.replace(homedir10(), "~");
|
|
28144
28152
|
const bodyMarkdown = [
|
|
28145
28153
|
"## Description",
|
|
28146
28154
|
description,
|
|
@@ -28171,7 +28179,7 @@ async function bundleIssueReport(report, description, _title) {
|
|
|
28171
28179
|
"```"
|
|
28172
28180
|
].join(`
|
|
28173
28181
|
`);
|
|
28174
|
-
const path4 =
|
|
28182
|
+
const path4 = join14(process.cwd(), `magic-context-issue-${formatTimestamp(new Date)}.md`);
|
|
28175
28183
|
writeFileSync9(path4, `${bodyMarkdown}
|
|
28176
28184
|
`);
|
|
28177
28185
|
return { path: path4, bodyMarkdown };
|
|
@@ -28258,11 +28266,11 @@ var init_logs_opencode = __esm(() => {
|
|
|
28258
28266
|
});
|
|
28259
28267
|
|
|
28260
28268
|
// src/commands/doctor-opencode.ts
|
|
28261
|
-
import { execSync as
|
|
28269
|
+
import { execSync as execSync2, spawnSync as spawnSync2 } from "node:child_process";
|
|
28262
28270
|
import { existsSync as existsSync15, readdirSync as readdirSync3, readFileSync as readFileSync11, rmSync, statSync as statSync3, writeFileSync as writeFileSync10 } from "node:fs";
|
|
28263
28271
|
import { createRequire as createRequire4 } from "node:module";
|
|
28264
|
-
import { homedir as
|
|
28265
|
-
import { join as
|
|
28272
|
+
import { homedir as homedir11, tmpdir as tmpdir4 } from "node:os";
|
|
28273
|
+
import { join as join15 } from "node:path";
|
|
28266
28274
|
async function fetchNpmLatest(pkg, timeoutMs = 5000) {
|
|
28267
28275
|
try {
|
|
28268
28276
|
const controller = new AbortController;
|
|
@@ -28312,13 +28320,13 @@ function compareVersions(a, b2) {
|
|
|
28312
28320
|
}
|
|
28313
28321
|
async function clearPluginCache(force = false) {
|
|
28314
28322
|
const cacheDir = getOpenCodeCacheDir();
|
|
28315
|
-
const pluginCacheDir =
|
|
28323
|
+
const pluginCacheDir = join15(cacheDir, "packages", PLUGIN_ENTRY_WITH_VERSION2);
|
|
28316
28324
|
if (!existsSync15(pluginCacheDir)) {
|
|
28317
28325
|
return { action: "not_found", path: pluginCacheDir };
|
|
28318
28326
|
}
|
|
28319
28327
|
let cachedVersion;
|
|
28320
28328
|
try {
|
|
28321
|
-
const installedPkgPath =
|
|
28329
|
+
const installedPkgPath = join15(pluginCacheDir, "node_modules", "@cortexkit", "opencode-magic-context", "package.json");
|
|
28322
28330
|
if (existsSync15(installedPkgPath)) {
|
|
28323
28331
|
const pkg = JSON.parse(readFileSync11(installedPkgPath, "utf-8"));
|
|
28324
28332
|
if (typeof pkg?.version === "string") {
|
|
@@ -28358,7 +28366,7 @@ async function clearPluginCache(force = false) {
|
|
|
28358
28366
|
}
|
|
28359
28367
|
function isGhInstalled() {
|
|
28360
28368
|
try {
|
|
28361
|
-
|
|
28369
|
+
execSync2("gh --version", { stdio: "pipe" });
|
|
28362
28370
|
return true;
|
|
28363
28371
|
} catch {
|
|
28364
28372
|
return false;
|
|
@@ -28840,7 +28848,7 @@ async function runDoctor(options = {}) {
|
|
|
28840
28848
|
failCount += embeddingCheck.issues;
|
|
28841
28849
|
else
|
|
28842
28850
|
passCount++;
|
|
28843
|
-
const dbPath =
|
|
28851
|
+
const dbPath = join15(getMagicContextStorageDir(), "context.db");
|
|
28844
28852
|
if (!existsSync15(dbPath)) {
|
|
28845
28853
|
log.info(`Shared context DB not yet created at ${dbPath} (will be created on first run)`);
|
|
28846
28854
|
} else {
|
|
@@ -28902,7 +28910,7 @@ async function runDoctor(options = {}) {
|
|
|
28902
28910
|
}
|
|
28903
28911
|
{
|
|
28904
28912
|
const ageWarnings = [];
|
|
28905
|
-
const npmrcPath =
|
|
28913
|
+
const npmrcPath = join15(homedir11(), ".npmrc");
|
|
28906
28914
|
if (existsSync15(npmrcPath)) {
|
|
28907
28915
|
try {
|
|
28908
28916
|
const npmrc = readFileSync11(npmrcPath, "utf-8");
|
|
@@ -28928,7 +28936,7 @@ async function runDoctor(options = {}) {
|
|
|
28928
28936
|
issues++;
|
|
28929
28937
|
}
|
|
28930
28938
|
}
|
|
28931
|
-
const logPath =
|
|
28939
|
+
const logPath = join15(tmpdir4(), "magic-context.log");
|
|
28932
28940
|
if (existsSync15(logPath)) {
|
|
28933
28941
|
const logStat = statSync3(logPath);
|
|
28934
28942
|
const sizeKb = (logStat.size / 1024).toFixed(0);
|
|
@@ -28936,12 +28944,12 @@ async function runDoctor(options = {}) {
|
|
|
28936
28944
|
} else {
|
|
28937
28945
|
log.info(`Log file: ${logPath} (not yet created)`);
|
|
28938
28946
|
}
|
|
28939
|
-
const historianDumpDir =
|
|
28947
|
+
const historianDumpDir = join15(tmpdir4(), "magic-context-historian");
|
|
28940
28948
|
if (existsSync15(historianDumpDir)) {
|
|
28941
28949
|
try {
|
|
28942
28950
|
const dumps = readdirSync3(historianDumpDir).filter((f) => f.endsWith(".xml")).map((f) => ({
|
|
28943
28951
|
name: f,
|
|
28944
|
-
mtime: statSync3(
|
|
28952
|
+
mtime: statSync3(join15(historianDumpDir, f)).mtimeMs
|
|
28945
28953
|
})).sort((a, b2) => b2.mtime - a.mtime);
|
|
28946
28954
|
if (dumps.length > 0) {
|
|
28947
28955
|
warn(`Historian debug dumps: ${dumps.length} file(s) in ${historianDumpDir}`);
|
|
@@ -161896,6 +161904,25 @@ var init_migrations = __esm(async () => {
|
|
|
161896
161904
|
WHERE type = 'tool' AND tool_owner_message_id IS NULL;
|
|
161897
161905
|
`);
|
|
161898
161906
|
}
|
|
161907
|
+
},
|
|
161908
|
+
{
|
|
161909
|
+
version: 11,
|
|
161910
|
+
description: "Add todo state synthesis columns to session_meta",
|
|
161911
|
+
up: (db) => {
|
|
161912
|
+
const cols = db.prepare("PRAGMA table_info(session_meta)").all();
|
|
161913
|
+
if (!cols.some((c2) => c2.name === "last_todo_state")) {
|
|
161914
|
+
db.exec("ALTER TABLE session_meta ADD COLUMN last_todo_state TEXT DEFAULT ''");
|
|
161915
|
+
}
|
|
161916
|
+
if (!cols.some((c2) => c2.name === "todo_synthetic_call_id")) {
|
|
161917
|
+
db.exec("ALTER TABLE session_meta ADD COLUMN todo_synthetic_call_id TEXT DEFAULT ''");
|
|
161918
|
+
}
|
|
161919
|
+
if (!cols.some((c2) => c2.name === "todo_synthetic_anchor_message_id")) {
|
|
161920
|
+
db.exec("ALTER TABLE session_meta ADD COLUMN todo_synthetic_anchor_message_id TEXT DEFAULT ''");
|
|
161921
|
+
}
|
|
161922
|
+
if (!cols.some((c2) => c2.name === "todo_synthetic_state_json")) {
|
|
161923
|
+
db.exec("ALTER TABLE session_meta ADD COLUMN todo_synthetic_state_json TEXT DEFAULT ''");
|
|
161924
|
+
}
|
|
161925
|
+
}
|
|
161899
161926
|
}
|
|
161900
161927
|
];
|
|
161901
161928
|
});
|
|
@@ -161907,6 +161934,7 @@ function keyFor(providerID, modelID, agentName) {
|
|
|
161907
161934
|
}
|
|
161908
161935
|
function setDatabase(db) {
|
|
161909
161936
|
persistenceDb = db;
|
|
161937
|
+
cachedInsertStmt = null;
|
|
161910
161938
|
}
|
|
161911
161939
|
function loadToolDefinitionMeasurements(db) {
|
|
161912
161940
|
let rows = [];
|
|
@@ -161925,17 +161953,18 @@ function loadToolDefinitionMeasurements(db) {
|
|
|
161925
161953
|
inner.set(row.tool_id, row.token_count);
|
|
161926
161954
|
}
|
|
161927
161955
|
}
|
|
161928
|
-
var measurements, persistenceDb = null;
|
|
161956
|
+
var measurements, fingerprints, persistenceDb = null, cachedInsertStmt = null;
|
|
161929
161957
|
var init_tool_definition_tokens = __esm(() => {
|
|
161930
161958
|
init_read_session_formatting();
|
|
161931
161959
|
measurements = new Map;
|
|
161960
|
+
fingerprints = new Map;
|
|
161932
161961
|
});
|
|
161933
161962
|
|
|
161934
161963
|
// ../plugin/src/features/magic-context/tool-owner-backfill.ts
|
|
161935
161964
|
import { existsSync as existsSync16 } from "node:fs";
|
|
161936
|
-
import { join as
|
|
161965
|
+
import { join as join16 } from "node:path";
|
|
161937
161966
|
function resolveOpencodeDbPath() {
|
|
161938
|
-
return
|
|
161967
|
+
return join16(getDataDir(), "opencode", "opencode.db");
|
|
161939
161968
|
}
|
|
161940
161969
|
function ensureBackfillStateTable(db) {
|
|
161941
161970
|
db.exec(`
|
|
@@ -162181,23 +162210,23 @@ var init_tool_owner_backfill = __esm(() => {
|
|
|
162181
162210
|
|
|
162182
162211
|
// ../plugin/src/features/magic-context/storage-db.ts
|
|
162183
162212
|
import { copyFileSync, cpSync, existsSync as existsSync17, mkdirSync as mkdirSync7 } from "node:fs";
|
|
162184
|
-
import { join as
|
|
162213
|
+
import { join as join17 } from "node:path";
|
|
162185
162214
|
function resolveDatabasePath() {
|
|
162186
162215
|
const dbDir = getMagicContextStorageDir();
|
|
162187
|
-
return { dbDir, dbPath:
|
|
162216
|
+
return { dbDir, dbPath: join17(dbDir, "context.db") };
|
|
162188
162217
|
}
|
|
162189
162218
|
function migrateLegacyStorageIfNeeded(targetDbPath, targetDbDir) {
|
|
162190
162219
|
if (existsSync17(targetDbPath))
|
|
162191
162220
|
return;
|
|
162192
162221
|
const legacyDir = getLegacyOpenCodeMagicContextStorageDir();
|
|
162193
|
-
const legacyDbPath =
|
|
162222
|
+
const legacyDbPath = join17(legacyDir, "context.db");
|
|
162194
162223
|
if (!existsSync17(legacyDbPath))
|
|
162195
162224
|
return;
|
|
162196
162225
|
log2(`[magic-context] migrating legacy plugin storage: ${legacyDir} -> ${targetDbDir} (legacy left in place as backup)`);
|
|
162197
162226
|
mkdirSync7(targetDbDir, { recursive: true });
|
|
162198
162227
|
for (const suffix of ["", "-wal", "-shm"]) {
|
|
162199
162228
|
const src = `${legacyDbPath}${suffix}`;
|
|
162200
|
-
const dst =
|
|
162229
|
+
const dst = join17(targetDbDir, `context.db${suffix}`);
|
|
162201
162230
|
if (existsSync17(src)) {
|
|
162202
162231
|
try {
|
|
162203
162232
|
copyFileSync(src, dst);
|
|
@@ -162206,8 +162235,8 @@ function migrateLegacyStorageIfNeeded(targetDbPath, targetDbDir) {
|
|
|
162206
162235
|
}
|
|
162207
162236
|
}
|
|
162208
162237
|
}
|
|
162209
|
-
const legacyModelsDir =
|
|
162210
|
-
const targetModelsDir =
|
|
162238
|
+
const legacyModelsDir = join17(legacyDir, "models");
|
|
162239
|
+
const targetModelsDir = join17(targetDbDir, "models");
|
|
162211
162240
|
if (existsSync17(legacyModelsDir) && !existsSync17(targetModelsDir)) {
|
|
162212
162241
|
try {
|
|
162213
162242
|
cpSync(legacyModelsDir, targetModelsDir, { recursive: true });
|
|
@@ -162409,6 +162438,10 @@ CREATE INDEX IF NOT EXISTS idx_dream_queue_pending ON dream_queue(started_at, en
|
|
|
162409
162438
|
note_nudge_trigger_message_id TEXT DEFAULT '',
|
|
162410
162439
|
note_nudge_sticky_text TEXT DEFAULT '',
|
|
162411
162440
|
note_nudge_sticky_message_id TEXT DEFAULT '',
|
|
162441
|
+
last_todo_state TEXT DEFAULT '',
|
|
162442
|
+
todo_synthetic_call_id TEXT DEFAULT '',
|
|
162443
|
+
todo_synthetic_anchor_message_id TEXT DEFAULT '',
|
|
162444
|
+
todo_synthetic_state_json TEXT DEFAULT '',
|
|
162412
162445
|
is_subagent INTEGER DEFAULT 0,
|
|
162413
162446
|
last_context_percentage REAL DEFAULT 0,
|
|
162414
162447
|
last_input_tokens INTEGER DEFAULT 0,
|
|
@@ -162473,6 +162506,10 @@ CREATE INDEX IF NOT EXISTS idx_dream_queue_pending ON dream_queue(started_at, en
|
|
|
162473
162506
|
ensureColumn(db, "session_meta", "note_nudge_trigger_message_id", "TEXT DEFAULT ''");
|
|
162474
162507
|
ensureColumn(db, "session_meta", "note_nudge_sticky_text", "TEXT DEFAULT ''");
|
|
162475
162508
|
ensureColumn(db, "session_meta", "note_nudge_sticky_message_id", "TEXT DEFAULT ''");
|
|
162509
|
+
ensureColumn(db, "session_meta", "last_todo_state", "TEXT DEFAULT ''");
|
|
162510
|
+
ensureColumn(db, "session_meta", "todo_synthetic_call_id", "TEXT DEFAULT ''");
|
|
162511
|
+
ensureColumn(db, "session_meta", "todo_synthetic_anchor_message_id", "TEXT DEFAULT ''");
|
|
162512
|
+
ensureColumn(db, "session_meta", "todo_synthetic_state_json", "TEXT DEFAULT ''");
|
|
162476
162513
|
ensureColumn(db, "session_meta", "note_last_read_at", "INTEGER DEFAULT 0");
|
|
162477
162514
|
ensureColumn(db, "session_meta", "times_execute_threshold_reached", "INTEGER DEFAULT 0");
|
|
162478
162515
|
ensureColumn(db, "session_meta", "compartment_in_progress", "INTEGER DEFAULT 0");
|
|
@@ -162537,6 +162574,10 @@ function healNullTextColumns(db) {
|
|
|
162537
162574
|
["note_nudge_trigger_message_id", ""],
|
|
162538
162575
|
["note_nudge_sticky_text", ""],
|
|
162539
162576
|
["note_nudge_sticky_message_id", ""],
|
|
162577
|
+
["last_todo_state", ""],
|
|
162578
|
+
["todo_synthetic_call_id", ""],
|
|
162579
|
+
["todo_synthetic_anchor_message_id", ""],
|
|
162580
|
+
["todo_synthetic_state_json", ""],
|
|
162540
162581
|
["system_prompt_hash", ""],
|
|
162541
162582
|
["stripped_placeholder_ids", ""],
|
|
162542
162583
|
["memory_block_cache", ""],
|
|
@@ -162732,15 +162773,15 @@ var init_storage = __esm(async () => {
|
|
|
162732
162773
|
|
|
162733
162774
|
// ../pi-plugin/src/config/index.ts
|
|
162734
162775
|
import { existsSync as existsSync18, readFileSync as readFileSync12 } from "node:fs";
|
|
162735
|
-
import { homedir as
|
|
162736
|
-
import { join as
|
|
162776
|
+
import { homedir as homedir12 } from "node:os";
|
|
162777
|
+
import { join as join18 } from "node:path";
|
|
162737
162778
|
function getProjectConfigPaths(cwd) {
|
|
162738
|
-
const basePath =
|
|
162779
|
+
const basePath = join18(cwd, ".pi", CONFIG_FILE_NAME);
|
|
162739
162780
|
return [`${basePath}.jsonc`, `${basePath}.json`];
|
|
162740
162781
|
}
|
|
162741
162782
|
function getUserConfigPaths() {
|
|
162742
|
-
const home = process.env.HOME ??
|
|
162743
|
-
const basePath =
|
|
162783
|
+
const home = process.env.HOME ?? homedir12();
|
|
162784
|
+
const basePath = join18(home, ".pi", "agent", CONFIG_FILE_NAME);
|
|
162744
162785
|
return [`${basePath}.jsonc`, `${basePath}.json`];
|
|
162745
162786
|
}
|
|
162746
162787
|
function resolveFirstExisting(paths) {
|
|
@@ -162880,8 +162921,8 @@ var init_config2 = __esm(() => {
|
|
|
162880
162921
|
import { createHash } from "node:crypto";
|
|
162881
162922
|
import { existsSync as existsSync19, readFileSync as readFileSync13, statSync as statSync4 } from "node:fs";
|
|
162882
162923
|
import { createRequire as createRequire5 } from "node:module";
|
|
162883
|
-
import { homedir as
|
|
162884
|
-
import { join as
|
|
162924
|
+
import { homedir as homedir13, tmpdir as tmpdir5, userInfo as userInfo3 } from "node:os";
|
|
162925
|
+
import { join as join19 } from "node:path";
|
|
162885
162926
|
function getSelfVersion3() {
|
|
162886
162927
|
const req = createRequire5(import.meta.url);
|
|
162887
162928
|
for (const relPath of ["../../package.json", "../package.json"]) {
|
|
@@ -162912,7 +162953,7 @@ function redactSecretString(value) {
|
|
|
162912
162953
|
return value.replace(/Bearer\s+[A-Za-z0-9._~+\-/=]+/g, "Bearer <REDACTED>").replace(/sk-[A-Za-z0-9_-]{12,}/g, "sk-<REDACTED>").replace(/api[_-]?key=([^\s&]+)/gi, "api_key=<REDACTED>").replace(/token=([^\s&]+)/gi, "token=<REDACTED>");
|
|
162913
162954
|
}
|
|
162914
162955
|
function sanitizeString2(value) {
|
|
162915
|
-
const home = process.env.HOME ||
|
|
162956
|
+
const home = process.env.HOME || homedir13();
|
|
162916
162957
|
const username = userInfo3().username;
|
|
162917
162958
|
const userHash = `<USER:${currentUserHash()}>`;
|
|
162918
162959
|
let sanitized = redactSecretString(value);
|
|
@@ -162960,7 +163001,7 @@ function readJsonc3(path4) {
|
|
|
162960
163001
|
}
|
|
162961
163002
|
}
|
|
162962
163003
|
function getProjectConfigPath(cwd) {
|
|
162963
|
-
return
|
|
163004
|
+
return join19(cwd, ".pi", "magic-context.jsonc");
|
|
162964
163005
|
}
|
|
162965
163006
|
function readConfigDiagnostic(path4) {
|
|
162966
163007
|
const parsed = readJsonc3(path4);
|
|
@@ -162986,8 +163027,8 @@ async function collectDiagnostics2(cwd = process.cwd()) {
|
|
|
162986
163027
|
const projectConfigPath = getProjectConfigPath(cwd);
|
|
162987
163028
|
const loaded = loadPiConfig({ cwd });
|
|
162988
163029
|
const storageDirPath = getMagicContextStorageDir();
|
|
162989
|
-
const dbPath =
|
|
162990
|
-
const logPath =
|
|
163030
|
+
const dbPath = join19(storageDirPath, "context.db");
|
|
163031
|
+
const logPath = join19(tmpdir5(), "magic-context.log");
|
|
162991
163032
|
const logFileSize = existsSync19(logPath) ? statSync4(logPath).size : 0;
|
|
162992
163033
|
const otherPiExtensions = packages.filter((entry) => !hasMagicContextPackage([entry]));
|
|
162993
163034
|
return {
|
|
@@ -163116,7 +163157,7 @@ var init_diagnostics_pi = __esm(() => {
|
|
|
163116
163157
|
|
|
163117
163158
|
// src/lib/logs-pi.ts
|
|
163118
163159
|
import { readFileSync as readFileSync14, writeFileSync as writeFileSync11 } from "node:fs";
|
|
163119
|
-
import { join as
|
|
163160
|
+
import { join as join20 } from "node:path";
|
|
163120
163161
|
function sanitizeLogContent2(content) {
|
|
163121
163162
|
return sanitizeString2(content);
|
|
163122
163163
|
}
|
|
@@ -163160,7 +163201,7 @@ async function bundleIssueReport2(report, description, title, options = {}) {
|
|
|
163160
163201
|
].join(`
|
|
163161
163202
|
`);
|
|
163162
163203
|
const cwd = options.cwd ?? process.cwd();
|
|
163163
|
-
const path4 =
|
|
163204
|
+
const path4 = join20(cwd, `magic-context-pi-issue-${formatTimestamp2(options.now ?? new Date)}.md`);
|
|
163164
163205
|
writeFileSync11(path4, `${bodyMarkdown}
|
|
163165
163206
|
`);
|
|
163166
163207
|
return { path: path4, bodyMarkdown };
|
|
@@ -163170,7 +163211,7 @@ var init_logs_pi = __esm(() => {
|
|
|
163170
163211
|
});
|
|
163171
163212
|
|
|
163172
163213
|
// src/commands/doctor-pi.ts
|
|
163173
|
-
import { execFileSync as
|
|
163214
|
+
import { execFileSync as execFileSync4, spawnSync as spawnSync3 } from "node:child_process";
|
|
163174
163215
|
import {
|
|
163175
163216
|
existsSync as existsSync20,
|
|
163176
163217
|
mkdirSync as mkdirSync8,
|
|
@@ -163181,8 +163222,8 @@ import {
|
|
|
163181
163222
|
writeFileSync as writeFileSync12
|
|
163182
163223
|
} from "node:fs";
|
|
163183
163224
|
import { createRequire as createRequire6 } from "node:module";
|
|
163184
|
-
import { homedir as
|
|
163185
|
-
import { dirname as dirname9, join as
|
|
163225
|
+
import { homedir as homedir14, tmpdir as tmpdir6 } from "node:os";
|
|
163226
|
+
import { dirname as dirname9, join as join21 } from "node:path";
|
|
163186
163227
|
function depsFrom(options) {
|
|
163187
163228
|
return {
|
|
163188
163229
|
...DEFAULT_DEPS,
|
|
@@ -163215,7 +163256,7 @@ function selfVersion() {
|
|
|
163215
163256
|
}
|
|
163216
163257
|
function getLatestNpmVersion(packageName) {
|
|
163217
163258
|
try {
|
|
163218
|
-
return
|
|
163259
|
+
return execFileSync4("npm", ["view", packageName, "version"], {
|
|
163219
163260
|
encoding: "utf-8",
|
|
163220
163261
|
stdio: ["ignore", "pipe", "ignore"],
|
|
163221
163262
|
timeout: 1e4
|
|
@@ -163285,7 +163326,7 @@ function hasPiPackage(packages) {
|
|
|
163285
163326
|
return packages.some((entry) => entry === PI_PACKAGE_SOURCE || entry === PACKAGE_NAME2 || entry.includes("pi-magic-context"));
|
|
163286
163327
|
}
|
|
163287
163328
|
function projectConfigPath(cwd) {
|
|
163288
|
-
return
|
|
163329
|
+
return join21(cwd, ".pi", "magic-context.jsonc");
|
|
163289
163330
|
}
|
|
163290
163331
|
function readConfigForEmbedding(path4) {
|
|
163291
163332
|
if (!existsSync20(path4))
|
|
@@ -163349,14 +163390,14 @@ function countTable(db, table) {
|
|
|
163349
163390
|
}
|
|
163350
163391
|
}
|
|
163351
163392
|
function cacheRoots() {
|
|
163352
|
-
const home =
|
|
163353
|
-
const cacheHome = process.env.XDG_CACHE_HOME ||
|
|
163393
|
+
const home = homedir14();
|
|
163394
|
+
const cacheHome = process.env.XDG_CACHE_HOME || join21(home, ".cache");
|
|
163354
163395
|
return [
|
|
163355
|
-
|
|
163356
|
-
|
|
163357
|
-
|
|
163358
|
-
|
|
163359
|
-
|
|
163396
|
+
join21(home, ".pi", "cache", "extensions"),
|
|
163397
|
+
join21(home, ".pi", "cache", "packages"),
|
|
163398
|
+
join21(cacheHome, "pi", "extensions"),
|
|
163399
|
+
join21(cacheHome, "pi", "packages"),
|
|
163400
|
+
join21(getPiAgentConfigDir(), "cache", "extensions")
|
|
163360
163401
|
];
|
|
163361
163402
|
}
|
|
163362
163403
|
function findPiMagicContextCacheDirs(self, force = false) {
|
|
@@ -163372,7 +163413,7 @@ function findPiMagicContextCacheDirs(self, force = false) {
|
|
|
163372
163413
|
}
|
|
163373
163414
|
if (!stat.isDirectory())
|
|
163374
163415
|
return;
|
|
163375
|
-
const packageJson =
|
|
163416
|
+
const packageJson = join21(path4, "package.json");
|
|
163376
163417
|
if (existsSync20(packageJson)) {
|
|
163377
163418
|
try {
|
|
163378
163419
|
const pkg = JSON.parse(readFileSync15(packageJson, "utf-8"));
|
|
@@ -163394,7 +163435,7 @@ function findPiMagicContextCacheDirs(self, force = false) {
|
|
|
163394
163435
|
return;
|
|
163395
163436
|
}
|
|
163396
163437
|
for (const entry of entries)
|
|
163397
|
-
visit(
|
|
163438
|
+
visit(join21(path4, entry), depth - 1);
|
|
163398
163439
|
};
|
|
163399
163440
|
for (const root of cacheRoots())
|
|
163400
163441
|
visit(root, 5);
|
|
@@ -163488,7 +163529,7 @@ async function runHealthChecks(options) {
|
|
|
163488
163529
|
add(results, "pass", `historian.model "${historianModel}" has thinking_level "${historianThinkingLevel}" configured`);
|
|
163489
163530
|
}
|
|
163490
163531
|
const storageDir = getMagicContextStorageDir();
|
|
163491
|
-
const dbPath =
|
|
163532
|
+
const dbPath = join21(storageDir, "context.db");
|
|
163492
163533
|
const existedBeforeOpen = existsSync20(dbPath);
|
|
163493
163534
|
if (existedBeforeOpen)
|
|
163494
163535
|
add(results, "pass", `Shared context DB exists at ${dbPath}`);
|
|
@@ -163565,7 +163606,7 @@ async function runHealthChecks(options) {
|
|
|
163565
163606
|
} else {
|
|
163566
163607
|
add(results, "pass", "Pi extension cache clean (no stale cached package found)");
|
|
163567
163608
|
}
|
|
163568
|
-
const logPath =
|
|
163609
|
+
const logPath = join21(tmpdir6(), "magic-context.log");
|
|
163569
163610
|
if (existsSync20(logPath)) {
|
|
163570
163611
|
const stat = statSync5(logPath);
|
|
163571
163612
|
const sizeKb = (stat.size / 1024).toFixed(0);
|
|
@@ -163575,10 +163616,10 @@ async function runHealthChecks(options) {
|
|
|
163575
163616
|
} else {
|
|
163576
163617
|
add(results, "info", `No plugin log file yet at ${logPath}`);
|
|
163577
163618
|
}
|
|
163578
|
-
const historianDumpDir =
|
|
163619
|
+
const historianDumpDir = join21(tmpdir6(), "magic-context-historian");
|
|
163579
163620
|
if (existsSync20(historianDumpDir)) {
|
|
163580
163621
|
try {
|
|
163581
|
-
const dumps = readdirSync4(historianDumpDir).filter((f) => f.endsWith(".xml")).map((f) => ({ name: f, mtime: statSync5(
|
|
163622
|
+
const dumps = readdirSync4(historianDumpDir).filter((f) => f.endsWith(".xml")).map((f) => ({ name: f, mtime: statSync5(join21(historianDumpDir, f)).mtimeMs })).sort((a, b2) => b2.mtime - a.mtime);
|
|
163582
163623
|
if (dumps.length > 0) {
|
|
163583
163624
|
add(results, "warn", `Historian debug dumps: ${dumps.length} file(s) in ${historianDumpDir}`);
|
|
163584
163625
|
for (const dump of dumps.slice(0, 3)) {
|
|
@@ -163772,7 +163813,7 @@ var init_doctor_pi = __esm(async () => {
|
|
|
163772
163813
|
isDatabasePersisted,
|
|
163773
163814
|
closeDatabase,
|
|
163774
163815
|
now: () => new Date,
|
|
163775
|
-
execFileSync:
|
|
163816
|
+
execFileSync: execFileSync4,
|
|
163776
163817
|
spawnSync: spawnSync3
|
|
163777
163818
|
};
|
|
163778
163819
|
});
|