@cortexkit/magic-context 0.49.69 → 0.49.70
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 +74 -14
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -53013,6 +53013,12 @@ async function runDoctor(options = {}) {
|
|
|
53013
53013
|
prompts.intro("Magic Context for Oh My Pi (OMP) Doctor");
|
|
53014
53014
|
const first = await runHealthChecks({ cwd, prompts, deps });
|
|
53015
53015
|
prompts.log.message(`Summary: PASS ${first.pass} / WARN ${first.warn} / FAIL ${first.fail}`);
|
|
53016
|
+
if (options.fix || options.force) {
|
|
53017
|
+
prompts.log.info(`Doctor does not upgrade the installed Oh My Pi plugin. Run \`omp plugin install ${OMP_PLUGIN_PACKAGE}@latest\`, then restart running Oh My Pi sessions.`);
|
|
53018
|
+
}
|
|
53019
|
+
if (options.fix && !options.force) {
|
|
53020
|
+
prompts.log.info("Oh My Pi config repairs need --force.");
|
|
53021
|
+
}
|
|
53016
53022
|
if (!options.force)
|
|
53017
53023
|
return first.fail === 0 ? 0 : 1;
|
|
53018
53024
|
if (first.fail === 0 && !first.repairPlan.writeUserConfig)
|
|
@@ -58299,7 +58305,7 @@ import { execFileSync as execFileSync9, spawnSync as spawnSync11 } from "node:ch
|
|
|
58299
58305
|
import { existsSync as existsSync51, readdirSync as readdirSync12, readFileSync as readFileSync33, rmSync as rmSync10, statSync as statSync28 } from "node:fs";
|
|
58300
58306
|
import { createRequire as createRequire8 } from "node:module";
|
|
58301
58307
|
import { homedir as homedir22 } from "node:os";
|
|
58302
|
-
import { isAbsolute as isAbsolute9, join as join43 } from "node:path";
|
|
58308
|
+
import { basename as basename7, isAbsolute as isAbsolute9, join as join43 } from "node:path";
|
|
58303
58309
|
function depsFrom(options) {
|
|
58304
58310
|
return {
|
|
58305
58311
|
...DEFAULT_DEPS5,
|
|
@@ -58314,7 +58320,8 @@ function printDoctorHelp() {
|
|
|
58314
58320
|
console.log("");
|
|
58315
58321
|
console.log(" Usage:");
|
|
58316
58322
|
console.log(" magic-context-pi doctor Run health checks");
|
|
58317
|
-
console.log(" magic-context-pi doctor --
|
|
58323
|
+
console.log(" magic-context-pi doctor --fix Repair config and clear stale caches, then re-check");
|
|
58324
|
+
console.log(" magic-context-pi doctor --force Repair config and clear caches even if current");
|
|
58318
58325
|
console.log(" magic-context-pi doctor --issue Create a sanitized bug report");
|
|
58319
58326
|
console.log(" magic-context-pi doctor --issue --report <path> Write a report without prompting");
|
|
58320
58327
|
console.log(" magic-context-pi doctor --check-v22-backfill Show v22 memory backfill status");
|
|
@@ -58919,9 +58926,11 @@ ${formatDatabaseRepairGuidance(dbPath)}`);
|
|
|
58919
58926
|
const configuredSpecifier = getPiMagicContextPackageSpecifier(configuredEntry);
|
|
58920
58927
|
const expectedPluginVersion = pinnedVersionFromPackageSpecifier(configuredSpecifier) ?? latest ?? null;
|
|
58921
58928
|
const staleCaches = findPiMagicContextCacheDirs(options.cwd, expectedPluginVersion, options.force === true);
|
|
58922
|
-
if (
|
|
58929
|
+
if (!expectedPluginVersion && !options.force) {
|
|
58930
|
+
add2(results, "warn", "Pi extension cache version check unavailable; preserving cached packages. Use doctor --force to clear them.");
|
|
58931
|
+
} else if (staleCaches.length > 0) {
|
|
58923
58932
|
repairPlan.clearCachePaths = staleCaches.map((entry) => entry.path);
|
|
58924
|
-
add2(results, "warn",
|
|
58933
|
+
add2(results, "warn", `${options.force ? "Pi extension cache selected for clearing" : "Stale Pi extension cache found"}: ${staleCaches.map((entry) => `${entry.path}${entry.version ? ` (v${entry.version})` : ""}`).join(", ")}`);
|
|
58925
58934
|
} else {
|
|
58926
58935
|
add2(results, "pass", "Pi extension cache clean (no stale cached package found)");
|
|
58927
58936
|
}
|
|
@@ -58989,7 +58998,41 @@ function writeDefaultMagicContextConfig(path) {
|
|
|
58989
58998
|
writeFileAtomic(path, `${import_comment_json13.stringify(config, null, 2)}
|
|
58990
58999
|
`, { ownerOnly: true });
|
|
58991
59000
|
}
|
|
58992
|
-
function
|
|
59001
|
+
function cacheHolderName(command) {
|
|
59002
|
+
const [executable, script] = command?.replaceAll("\x00", " ").trim().split(/\s+/, 2) ?? [];
|
|
59003
|
+
if (classifyProcessKind(command) === "Pi") {
|
|
59004
|
+
return piHarnessKindFromExecutable(executable) === "omp" || piHarnessKindFromExecutable(script) === "omp" || script?.includes("/@oh-my-pi/") ? "Oh My Pi" : "Pi";
|
|
59005
|
+
}
|
|
59006
|
+
const name = basename7(executable?.replaceAll("\\", "/") ?? "");
|
|
59007
|
+
return /^[\w.-]+$/.test(name) ? name : "process";
|
|
59008
|
+
}
|
|
59009
|
+
function piCacheClearBlocker(paths, deps) {
|
|
59010
|
+
const cache = deps.probeCacheUse({ files: [], directories: paths });
|
|
59011
|
+
if (cache.status === "unknown")
|
|
59012
|
+
return cache.reason;
|
|
59013
|
+
if (cache.status === "in_use") {
|
|
59014
|
+
const holders = cache.pids.map((pid) => `${cacheHolderName(deps.readProcessCommand(pid))} (PID ${pid})`);
|
|
59015
|
+
return `cache files are in use by ${holders.join(", ")}`;
|
|
59016
|
+
}
|
|
59017
|
+
const db = join43(getMagicContextStorageDir(), "context.db");
|
|
59018
|
+
const use = deps.probeCacheUse({ files: [db, `${db}-wal`, `${db}-shm`], directories: [] });
|
|
59019
|
+
if (use.status === "unknown")
|
|
59020
|
+
return use.reason;
|
|
59021
|
+
if (use.status === "free")
|
|
59022
|
+
return;
|
|
59023
|
+
const holders = [];
|
|
59024
|
+
for (const pid of use.pids) {
|
|
59025
|
+
const command = deps.readProcessCommand(pid);
|
|
59026
|
+
if (!command?.trim())
|
|
59027
|
+
return `could not identify shared database holder (PID ${pid})`;
|
|
59028
|
+
if (classifyProcessKind(command) === "Pi") {
|
|
59029
|
+
holders.push(`${cacheHolderName(command)} (PID ${pid})`);
|
|
59030
|
+
}
|
|
59031
|
+
}
|
|
59032
|
+
if (holders.length)
|
|
59033
|
+
return `shared database is in use by ${holders.join(", ")}`;
|
|
59034
|
+
}
|
|
59035
|
+
function repair2(plan, prompts, deps) {
|
|
58993
59036
|
let fixed = 0;
|
|
58994
59037
|
for (const path of plan.reasoningAgeConfigPaths) {
|
|
58995
59038
|
const content = readFileSync33(path, "utf8");
|
|
@@ -59028,16 +59071,23 @@ function repair2(plan, prompts) {
|
|
|
59028
59071
|
}
|
|
59029
59072
|
}
|
|
59030
59073
|
}
|
|
59074
|
+
if (plan.clearCachePaths.length === 0)
|
|
59075
|
+
return { fixed, cacheBlocked: false };
|
|
59076
|
+
const blocker = piCacheClearBlocker(plan.clearCachePaths, deps);
|
|
59077
|
+
if (blocker !== undefined) {
|
|
59078
|
+
prompts.log.warn(`Pi extension cache was not cleared: ${blocker}. Quit Pi or Oh My Pi and rerun doctor.`);
|
|
59079
|
+
return { fixed, cacheBlocked: true };
|
|
59080
|
+
}
|
|
59031
59081
|
for (const path of plan.clearCachePaths) {
|
|
59032
59082
|
try {
|
|
59033
59083
|
rmSync10(path, { recursive: true, force: true });
|
|
59034
|
-
prompts.log.success(`Cleared
|
|
59084
|
+
prompts.log.success(`Cleared Pi extension cache: ${path}`);
|
|
59035
59085
|
fixed += 1;
|
|
59036
59086
|
} catch (error) {
|
|
59037
59087
|
console.error(`FAIL Could not clear ${path}: ${error instanceof Error ? error.message : String(error)}`);
|
|
59038
59088
|
}
|
|
59039
59089
|
}
|
|
59040
|
-
return fixed;
|
|
59090
|
+
return { fixed, cacheBlocked: false };
|
|
59041
59091
|
}
|
|
59042
59092
|
function runGhCommandWithDeps2(deps, args) {
|
|
59043
59093
|
if (args[0] === "issue") {
|
|
@@ -59179,8 +59229,8 @@ async function runDoctor3(options = {}) {
|
|
|
59179
59229
|
});
|
|
59180
59230
|
console.log("");
|
|
59181
59231
|
prompts.log.message(`Summary: PASS ${first.pass} / WARN ${first.warn} / FAIL ${first.fail}`);
|
|
59182
|
-
if (options.force) {
|
|
59183
|
-
const fixed = repair2(first.repairPlan, prompts);
|
|
59232
|
+
if (options.fix || options.force) {
|
|
59233
|
+
const { fixed, cacheBlocked } = repair2(first.repairPlan, prompts, deps);
|
|
59184
59234
|
console.log("");
|
|
59185
59235
|
prompts.log.message(`Repair attempted; ${fixed} item(s) changed. Re-running health checks.`);
|
|
59186
59236
|
const second = await runHealthChecks2({
|
|
@@ -59192,8 +59242,9 @@ async function runDoctor3(options = {}) {
|
|
|
59192
59242
|
});
|
|
59193
59243
|
console.log("");
|
|
59194
59244
|
prompts.log.message(`Summary: PASS ${second.pass} / WARN ${second.warn} / FAIL ${second.fail}`);
|
|
59195
|
-
|
|
59196
|
-
|
|
59245
|
+
const failed = second.fail > 0 || cacheBlocked;
|
|
59246
|
+
prompts.outro(failed ? "Doctor found issues that need manual attention" : "Doctor repair complete");
|
|
59247
|
+
return failed ? 1 : 0;
|
|
59197
59248
|
}
|
|
59198
59249
|
prompts.outro(first.fail > 0 ? "Doctor found failures" : "Doctor complete");
|
|
59199
59250
|
return first.fail > 0 ? 1 : 0;
|
|
@@ -59212,6 +59263,7 @@ function parseDoctorArgs(args) {
|
|
|
59212
59263
|
const report = valueAfter2(args, "--report");
|
|
59213
59264
|
return {
|
|
59214
59265
|
force: args.includes("--force"),
|
|
59266
|
+
fix: args.includes("--fix"),
|
|
59215
59267
|
issue: args.includes("--issue") || report !== null,
|
|
59216
59268
|
...report !== null ? { report } : {},
|
|
59217
59269
|
help: args.includes("--help") || args.includes("-h"),
|
|
@@ -59233,6 +59285,8 @@ var init_doctor_pi = __esm(async () => {
|
|
|
59233
59285
|
init_data_path();
|
|
59234
59286
|
init_jsonc_edit();
|
|
59235
59287
|
init_jsonc_parser();
|
|
59288
|
+
init_pi_executable();
|
|
59289
|
+
init_rpc_utils();
|
|
59236
59290
|
init_config2();
|
|
59237
59291
|
init_model_chain_health();
|
|
59238
59292
|
init_atomic_write();
|
|
@@ -59253,7 +59307,8 @@ var init_doctor_pi = __esm(async () => {
|
|
|
59253
59307
|
init_database_access(),
|
|
59254
59308
|
init_embedding_runtime(),
|
|
59255
59309
|
init_storage_versions(),
|
|
59256
|
-
init_v22_backfill_commands()
|
|
59310
|
+
init_v22_backfill_commands(),
|
|
59311
|
+
init_doctor_opencode2_cache()
|
|
59257
59312
|
]);
|
|
59258
59313
|
import_comment_json13 = __toESM(require_src3(), 1);
|
|
59259
59314
|
ROW_COUNT_TABLES2 = ["tags", "compartments", "memories", "notes", "dream_runs"];
|
|
@@ -59267,6 +59322,8 @@ var init_doctor_pi = __esm(async () => {
|
|
|
59267
59322
|
selfVersion: selfVersion2,
|
|
59268
59323
|
probeEmbeddingEndpoint,
|
|
59269
59324
|
openExistingContextDatabase,
|
|
59325
|
+
probeCacheUse: probeHostProcessesUsing,
|
|
59326
|
+
readProcessCommand,
|
|
59270
59327
|
now: () => new Date,
|
|
59271
59328
|
execFileSync: execFileSync9,
|
|
59272
59329
|
spawnSync: spawnSync11
|
|
@@ -59357,6 +59414,8 @@ async function dispatchDoctor(adapter, options) {
|
|
|
59357
59414
|
const piArgs = [];
|
|
59358
59415
|
if (options.force)
|
|
59359
59416
|
piArgs.push("--force");
|
|
59417
|
+
if (options.fix)
|
|
59418
|
+
piArgs.push("--fix");
|
|
59360
59419
|
if (options.issue)
|
|
59361
59420
|
piArgs.push("--issue");
|
|
59362
59421
|
if (options.report)
|
|
@@ -59366,6 +59425,7 @@ async function dispatchDoctor(adapter, options) {
|
|
|
59366
59425
|
case "omp":
|
|
59367
59426
|
return runDoctor({
|
|
59368
59427
|
force: options.force,
|
|
59428
|
+
fix: options.fix,
|
|
59369
59429
|
issue: options.issue,
|
|
59370
59430
|
report: options.report
|
|
59371
59431
|
});
|
|
@@ -59514,8 +59574,8 @@ var DOCTOR_HELP = [
|
|
|
59514
59574
|
" Check the installed harnesses and fix configuration issues.",
|
|
59515
59575
|
"",
|
|
59516
59576
|
" Options:",
|
|
59517
|
-
" --fix Repair safe
|
|
59518
|
-
" --force
|
|
59577
|
+
" --fix Repair safe issues and clear outdated OpenCode 2 or Pi plugin caches",
|
|
59578
|
+
" --force Clear plugin caches even if current; repair Oh My Pi config",
|
|
59519
59579
|
" --clear Interactive cache cleanup picker",
|
|
59520
59580
|
" --verbose Print long listings in full instead of a capped summary",
|
|
59521
59581
|
" --prune-discovery [--yes] List RPC discovery records that block offline maintenance, then remove them after confirmation",
|