@cortexkit/magic-context 0.24.1 → 0.25.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.
Files changed (2) hide show
  1. package/dist/index.js +227 -80
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -11544,6 +11544,14 @@ function buildNodeSqliteDatabaseClass(DatabaseSync) {
11544
11544
  }
11545
11545
  super(typeof filename === "string" ? filename : ":memory:", translated);
11546
11546
  }
11547
+ prepare(sql) {
11548
+ const stmt = super.prepare(sql);
11549
+ for (const method of ["run", "get", "all"]) {
11550
+ const original = stmt[method].bind(stmt);
11551
+ stmt[method] = (...args) => args.length === 1 && Array.isArray(args[0]) ? original(...args[0]) : original(...args);
11552
+ }
11553
+ return stmt;
11554
+ }
11547
11555
  transaction(fn) {
11548
11556
  const self = this;
11549
11557
  const wrapped = function(...args) {
@@ -144790,16 +144798,18 @@ function stripTagPrefix(value) {
144790
144798
  const prev = stripped;
144791
144799
  stripped = stripped.replace(MALFORMED_TAG_PREFIX_REGEX, "");
144792
144800
  stripped = stripped.replace(TAG_PREFIX_REGEX, "");
144801
+ stripped = stripped.replace(DANGLING_TAG_PREFIX_REGEX, "");
144793
144802
  if (stripped === prev)
144794
144803
  break;
144795
144804
  }
144796
144805
  return stripped;
144797
144806
  }
144798
- var encoder, TAG_PREFIX_REGEX, MALFORMED_TAG_PREFIX_REGEX;
144807
+ var encoder, TAG_PREFIX_REGEX, MALFORMED_TAG_PREFIX_REGEX, DANGLING_TAG_PREFIX_REGEX;
144799
144808
  var init_tag_content_primitives = __esm(() => {
144800
144809
  encoder = new TextEncoder;
144801
144810
  TAG_PREFIX_REGEX = /^(?:§\d+§\s*)+/;
144802
144811
  MALFORMED_TAG_PREFIX_REGEX = /^(?:§\d+">§(?:\d+§)?\s*)+/;
144812
+ DANGLING_TAG_PREFIX_REGEX = /^(?:\u00a7\d+(?!\.\d)[^\s\u00a7\w.]?\s*)+/;
144803
144813
  });
144804
144814
 
144805
144815
  // ../plugin/src/hooks/magic-context/tag-part-guards.ts
@@ -145876,6 +145886,7 @@ CREATE INDEX IF NOT EXISTS idx_dream_queue_pending ON dream_queue(started_at, en
145876
145886
  ensureColumn(db, "session_meta", "historian_last_failure_at", "INTEGER DEFAULT NULL");
145877
145887
  ensureColumn(db, "session_meta", "system_prompt_hash", "TEXT DEFAULT ''");
145878
145888
  ensureColumn(db, "session_meta", "cleared_reasoning_through_tag", "INTEGER DEFAULT 0");
145889
+ ensureColumn(db, "session_meta", "tool_reclaim_watermark", "INTEGER DEFAULT 0");
145879
145890
  ensureColumn(db, "session_meta", "stripped_placeholder_ids", "TEXT DEFAULT ''");
145880
145891
  ensureColumn(db, "session_meta", "stale_reduce_stripped_ids", "TEXT DEFAULT ''");
145881
145892
  ensureColumn(db, "session_meta", "processed_image_stripped_ids", "TEXT DEFAULT ''");
@@ -164260,6 +164271,99 @@ var init_diagnostics_opencode = __esm(() => {
164260
164271
  PLUGIN_ENTRY_WITH_VERSION = `${PLUGIN_NAME5}@latest`;
164261
164272
  });
164262
164273
 
164274
+ // src/lib/embedding-runtime.ts
164275
+ import { existsSync as existsSync19 } from "node:fs";
164276
+ import { createRequire as createRequire3 } from "node:module";
164277
+ import { dirname as dirname9, join as join16, sep } from "node:path";
164278
+ function expectedBinaryRelPath(platform, arch) {
164279
+ const supportedPlatform = platform === "linux" || platform === "darwin" || platform === "win32";
164280
+ const supportedArch = arch === "x64" || arch === "arm64";
164281
+ if (!supportedPlatform || !supportedArch)
164282
+ return null;
164283
+ return join16("bin", "napi-v6", platform, arch, "onnxruntime_binding.node");
164284
+ }
164285
+ function checkLocalEmbeddingRuntimeAt(installRoot, platform = process.platform, arch = process.arch) {
164286
+ const packageDir = join16(installRoot, "node_modules", "onnxruntime-node");
164287
+ if (!existsSync19(join16(packageDir, "package.json"))) {
164288
+ return { state: "package-missing", packageDir };
164289
+ }
164290
+ const rel = expectedBinaryRelPath(platform, arch);
164291
+ if (rel === null) {
164292
+ return { state: "ok", binaryPath: packageDir };
164293
+ }
164294
+ const binaryPath = join16(packageDir, rel);
164295
+ if (!existsSync19(binaryPath)) {
164296
+ return { state: "binary-missing", packageDir, expectedBinary: binaryPath };
164297
+ }
164298
+ return { state: "ok", binaryPath };
164299
+ }
164300
+ function checkLocalEmbeddingRuntime(installRoots, platform = process.platform, arch = process.arch) {
164301
+ const existing = installRoots.filter((root) => existsSync19(root));
164302
+ if (existing.length === 0) {
164303
+ return {
164304
+ state: "unknown",
164305
+ reason: "no installed plugin tree found to inspect"
164306
+ };
164307
+ }
164308
+ let firstFailure = null;
164309
+ for (const root of existing) {
164310
+ const status = checkLocalEmbeddingRuntimeAt(root, platform, arch);
164311
+ if (status.state === "ok")
164312
+ return status;
164313
+ if (firstFailure === null)
164314
+ firstFailure = status;
164315
+ }
164316
+ return firstFailure ?? { state: "unknown", reason: "no candidate roots" };
164317
+ }
164318
+ function packageDirFromResolved(resolvedPath, packageName) {
164319
+ const marker = `node_modules${sep}${packageName.split("/").join(sep)}`;
164320
+ const idx = resolvedPath.indexOf(marker);
164321
+ return idx >= 0 ? resolvedPath.slice(0, idx + marker.length) : dirname9(resolvedPath);
164322
+ }
164323
+ function checkLocalEmbeddingRuntimeByResolution(pluginDir, platform = process.platform, arch = process.arch) {
164324
+ if (!existsSync19(join16(pluginDir, "package.json"))) {
164325
+ return { state: "unknown", reason: "plugin package dir not found" };
164326
+ }
164327
+ let onnxDir = null;
164328
+ let resolveError;
164329
+ try {
164330
+ const reqPlugin = createRequire3(join16(pluginDir, "package.json"));
164331
+ try {
164332
+ onnxDir = packageDirFromResolved(reqPlugin.resolve("onnxruntime-node"), "onnxruntime-node");
164333
+ } catch {
164334
+ const tfResolved = reqPlugin.resolve("@huggingface/transformers");
164335
+ const tfDir = packageDirFromResolved(tfResolved, "@huggingface/transformers");
164336
+ const reqTf = createRequire3(join16(tfDir, "package.json"));
164337
+ onnxDir = packageDirFromResolved(reqTf.resolve("onnxruntime-node"), "onnxruntime-node");
164338
+ }
164339
+ } catch (error51) {
164340
+ resolveError = error51?.code;
164341
+ if (resolveError === "ERR_MODULE_NOT_FOUND" || resolveError === "MODULE_NOT_FOUND") {
164342
+ return {
164343
+ state: "package-missing",
164344
+ packageDir: join16(pluginDir, "node_modules", "onnxruntime-node")
164345
+ };
164346
+ }
164347
+ return {
164348
+ state: "unknown",
164349
+ reason: `could not resolve onnxruntime-node (${resolveError ?? "unknown error"})`
164350
+ };
164351
+ }
164352
+ if (!onnxDir) {
164353
+ return { state: "unknown", reason: "onnxruntime-node resolution produced no path" };
164354
+ }
164355
+ const rel = expectedBinaryRelPath(platform, arch);
164356
+ if (rel === null) {
164357
+ return { state: "ok", binaryPath: onnxDir };
164358
+ }
164359
+ const binaryPath = join16(onnxDir, rel);
164360
+ if (!existsSync19(binaryPath)) {
164361
+ return { state: "binary-missing", packageDir: onnxDir, expectedBinary: binaryPath };
164362
+ }
164363
+ return { state: "ok", binaryPath };
164364
+ }
164365
+ var init_embedding_runtime = () => {};
164366
+
164263
164367
  // src/lib/issue-body.ts
164264
164368
  function isErrorLogLine(line) {
164265
164369
  return ERROR_LOG_PATTERNS.some((rx) => rx.test(line));
@@ -164348,7 +164452,7 @@ var init_issue_body = __esm(() => {
164348
164452
  // src/lib/logs-opencode.ts
164349
164453
  import { readFileSync as readFileSync13, writeFileSync as writeFileSync8 } from "node:fs";
164350
164454
  import { homedir as homedir12 } from "node:os";
164351
- import { join as join16 } from "node:path";
164455
+ import { join as join17 } from "node:path";
164352
164456
  function sanitizeLogContent(content) {
164353
164457
  return sanitizeDiagnosticText(content);
164354
164458
  }
@@ -164438,7 +164542,7 @@ async function bundleIssueReport(report, description, _title, sessionFilter = nu
164438
164542
  ].join(`
164439
164543
  `);
164440
164544
  const bodyMarkdown = capBodyToGithubLimit(rawBodyMarkdown);
164441
- const path5 = join16(process.cwd(), `magic-context-issue-${formatTimestamp(new Date)}.md`);
164545
+ const path5 = join17(process.cwd(), `magic-context-issue-${formatTimestamp(new Date)}.md`);
164442
164546
  writeFileSync8(path5, `${bodyMarkdown}
164443
164547
  `);
164444
164548
  return { path: path5, bodyMarkdown };
@@ -164461,10 +164565,10 @@ var init_logs_opencode = __esm(() => {
164461
164565
 
164462
164566
  // src/commands/doctor-opencode.ts
164463
164567
  import { execSync as execSync2, spawnSync as spawnSync2 } from "node:child_process";
164464
- import { existsSync as existsSync19, readFileSync as readFileSync14, rmSync, statSync as statSync5, writeFileSync as writeFileSync9 } from "node:fs";
164465
- import { createRequire as createRequire3 } from "node:module";
164568
+ import { existsSync as existsSync20, readFileSync as readFileSync14, rmSync, statSync as statSync5, writeFileSync as writeFileSync9 } from "node:fs";
164569
+ import { createRequire as createRequire4 } from "node:module";
164466
164570
  import { homedir as homedir13 } from "node:os";
164467
- import { join as join17 } from "node:path";
164571
+ import { join as join18 } from "node:path";
164468
164572
  function migrateLegacyAgentEnabledConfigForDoctor(mcConfig, logs) {
164469
164573
  let changed = false;
164470
164574
  let fixes = 0;
@@ -164523,7 +164627,7 @@ async function fetchNpmLatest(pkg, timeoutMs = 5000) {
164523
164627
  }
164524
164628
  }
164525
164629
  function getSelfVersion2() {
164526
- const req = createRequire3(import.meta.url);
164630
+ const req = createRequire4(import.meta.url);
164527
164631
  for (const relPath of ["../../package.json", "../package.json"]) {
164528
164632
  try {
164529
164633
  const pkg = req(relPath);
@@ -164551,21 +164655,21 @@ function compareVersions(a, b2) {
164551
164655
  }
164552
164656
  async function clearPluginCache(force = false) {
164553
164657
  const cacheDir = getOpenCodeCacheDir();
164554
- const pluginCacheDir = join17(cacheDir, "packages", PLUGIN_ENTRY_WITH_VERSION2);
164555
- if (!existsSync19(pluginCacheDir)) {
164658
+ const pluginCacheDir = join18(cacheDir, "packages", PLUGIN_ENTRY_WITH_VERSION2);
164659
+ if (!existsSync20(pluginCacheDir)) {
164556
164660
  return { action: "not_found", path: pluginCacheDir };
164557
164661
  }
164558
164662
  let cachedVersion;
164559
164663
  try {
164560
- const installedPkgPath = join17(pluginCacheDir, "node_modules", "@cortexkit", "opencode-magic-context", "package.json");
164561
- if (existsSync19(installedPkgPath)) {
164664
+ const installedPkgPath = join18(pluginCacheDir, "node_modules", "@cortexkit", "opencode-magic-context", "package.json");
164665
+ if (existsSync20(installedPkgPath)) {
164562
164666
  const pkg = JSON.parse(readFileSync14(installedPkgPath, "utf-8"));
164563
164667
  if (typeof pkg?.version === "string") {
164564
164668
  cachedVersion = pkg.version;
164565
164669
  }
164566
164670
  }
164567
164671
  } catch {}
164568
- const require2 = createRequire3(import.meta.url);
164672
+ const require2 = createRequire4(import.meta.url);
164569
164673
  let selfVersion;
164570
164674
  for (const relPath of ["../../package.json", "../package.json"]) {
164571
164675
  try {
@@ -164690,9 +164794,21 @@ async function runIssueFlow() {
164690
164794
  return 1;
164691
164795
  }
164692
164796
  }
164797
+ function checkLocalEmbeddingRuntimeForDoctor() {
164798
+ const runtime = checkLocalEmbeddingRuntime([
164799
+ join18(getOpenCodeCacheDir(), "packages", PLUGIN_ENTRY_WITH_VERSION2),
164800
+ join18(getOpenCodeCacheDir(), "packages", PLUGIN_NAME6)
164801
+ ]);
164802
+ if (runtime.state === "package-missing" || runtime.state === "binary-missing") {
164803
+ log.warn("Embedding provider: local — but the native runtime (onnxruntime-node) " + `is ${runtime.state === "package-missing" ? "not installed" : "missing its platform binary"}. ` + "Local embeddings won't work. Fix: re-run with `doctor --force` to reinstall " + "the plugin, or set `embedding.provider` to `openai-compatible` (LM Studio / " + "Ollama) or `off`. Existing memories are unaffected.");
164804
+ return { issues: 1, localRuntimeBroken: true };
164805
+ }
164806
+ log.success("Embedding provider: local (Xenova/all-MiniLM-L6-v2 bundled)");
164807
+ return { issues: 0 };
164808
+ }
164693
164809
  async function checkEmbeddingConfig(magicContextConfigPath) {
164694
- if (!existsSync19(magicContextConfigPath)) {
164695
- return { issues: 0 };
164810
+ if (!existsSync20(magicContextConfigPath)) {
164811
+ return checkLocalEmbeddingRuntimeForDoctor();
164696
164812
  }
164697
164813
  let rawText;
164698
164814
  try {
@@ -164719,8 +164835,7 @@ async function checkEmbeddingConfig(magicContextConfigPath) {
164719
164835
  return { issues: 0 };
164720
164836
  }
164721
164837
  if (provider === undefined || provider === "local") {
164722
- log.success("Embedding provider: local (Xenova/all-MiniLM-L6-v2 bundled)");
164723
- return { issues: 0 };
164838
+ return checkLocalEmbeddingRuntimeForDoctor();
164724
164839
  }
164725
164840
  if (provider !== "openai-compatible") {
164726
164841
  log.warn(`Unknown embedding provider: ${String(provider)} (expected local | openai-compatible | off)`);
@@ -164859,7 +164974,7 @@ async function runDoctor(options = {}) {
164859
164974
  } else {
164860
164975
  pass(`OpenCode config: ${paths.opencodeConfig}`);
164861
164976
  }
164862
- if (existsSync19(paths.magicContextConfig)) {
164977
+ if (existsSync20(paths.magicContextConfig)) {
164863
164978
  pass(`Magic Context config: ${paths.magicContextConfig}`);
164864
164979
  try {
164865
164980
  const raw = readFileSync14(paths.magicContextConfig, "utf-8");
@@ -164887,7 +165002,7 @@ async function runDoctor(options = {}) {
164887
165002
  warn(`No magic-context.jsonc found — using defaults`);
164888
165003
  log.info(" Run 'setup' to create one with model recommendations");
164889
165004
  }
164890
- if (existsSync19(paths.magicContextConfig)) {
165005
+ if (existsSync20(paths.magicContextConfig)) {
164891
165006
  try {
164892
165007
  const mcRaw = readFileSync14(paths.magicContextConfig, "utf-8");
164893
165008
  const mcConfig = import_comment_json9.parse(mcRaw);
@@ -165094,7 +165209,7 @@ async function runDoctor(options = {}) {
165094
165209
  pass("Added TUI sidebar plugin to tui.json");
165095
165210
  warn("Restart OpenCode to see the sidebar");
165096
165211
  fixed++;
165097
- } else if (existsSync19(paths.tuiConfig)) {
165212
+ } else if (existsSync20(paths.tuiConfig)) {
165098
165213
  try {
165099
165214
  const tuiRaw = readFileSync14(paths.tuiConfig, "utf-8");
165100
165215
  const tuiConfig = import_comment_json9.parse(tuiRaw);
@@ -165142,7 +165257,7 @@ async function runDoctor(options = {}) {
165142
165257
  } else {
165143
165258
  pass("TUI sidebar plugin configured (tui.json created)");
165144
165259
  }
165145
- if (existsSync19(paths.magicContextConfig)) {
165260
+ if (existsSync20(paths.magicContextConfig)) {
165146
165261
  try {
165147
165262
  const mcRaw = readFileSync14(paths.magicContextConfig, "utf-8");
165148
165263
  const mcConfig = import_comment_json9.parse(mcRaw);
@@ -165171,8 +165286,8 @@ async function runDoctor(options = {}) {
165171
165286
  failCount += embeddingCheck.issues;
165172
165287
  else
165173
165288
  passCount++;
165174
- const dbPath = join17(getMagicContextStorageDir(), "context.db");
165175
- if (!existsSync19(dbPath)) {
165289
+ const dbPath = join18(getMagicContextStorageDir(), "context.db");
165290
+ if (!existsSync20(dbPath)) {
165176
165291
  log.info(`Shared context DB not yet created at ${dbPath} (will be created on first run)`);
165177
165292
  } else {
165178
165293
  pass(`Shared context DB exists at ${dbPath}`);
@@ -165233,8 +165348,8 @@ async function runDoctor(options = {}) {
165233
165348
  }
165234
165349
  {
165235
165350
  const ageWarnings = [];
165236
- const npmrcPath = join17(homedir13(), ".npmrc");
165237
- if (existsSync19(npmrcPath)) {
165351
+ const npmrcPath = join18(homedir13(), ".npmrc");
165352
+ if (existsSync20(npmrcPath)) {
165238
165353
  try {
165239
165354
  const npmrc = readFileSync14(npmrcPath, "utf-8");
165240
165355
  for (const line of npmrc.split(`
@@ -165260,7 +165375,7 @@ async function runDoctor(options = {}) {
165260
165375
  }
165261
165376
  }
165262
165377
  const logPath = getMagicContextLogPath2("opencode");
165263
- if (existsSync19(logPath)) {
165378
+ if (existsSync20(logPath)) {
165264
165379
  const logStat = statSync5(logPath);
165265
165380
  const sizeKb = (logStat.size / 1024).toFixed(0);
165266
165381
  log.info(`Log file: ${logPath} (${sizeKb} KB)`);
@@ -165317,6 +165432,7 @@ var init_doctor_opencode = __esm(async () => {
165317
165432
  init_tui_config();
165318
165433
  init_opencode();
165319
165434
  init_diagnostics_opencode();
165435
+ init_embedding_runtime();
165320
165436
  init_logs_opencode();
165321
165437
  init_opencode_helpers();
165322
165438
  init_paths();
@@ -165331,20 +165447,20 @@ var init_doctor_opencode = __esm(async () => {
165331
165447
  });
165332
165448
 
165333
165449
  // ../pi-plugin/src/config/index.ts
165334
- import { existsSync as existsSync20, readFileSync as readFileSync15 } from "node:fs";
165450
+ import { existsSync as existsSync21, readFileSync as readFileSync15 } from "node:fs";
165335
165451
  import { homedir as homedir14 } from "node:os";
165336
- import { join as join18 } from "node:path";
165452
+ import { join as join19 } from "node:path";
165337
165453
  function getProjectConfigPaths(cwd) {
165338
- const basePath = join18(cwd, ".pi", CONFIG_FILE_NAME);
165454
+ const basePath = join19(cwd, ".pi", CONFIG_FILE_NAME);
165339
165455
  return [`${basePath}.jsonc`, `${basePath}.json`];
165340
165456
  }
165341
165457
  function getUserConfigPaths() {
165342
165458
  const home = process.env.HOME ?? homedir14();
165343
- const basePath = join18(home, ".pi", "agent", CONFIG_FILE_NAME);
165459
+ const basePath = join19(home, ".pi", "agent", CONFIG_FILE_NAME);
165344
165460
  return [`${basePath}.jsonc`, `${basePath}.json`];
165345
165461
  }
165346
165462
  function resolveFirstExisting(paths) {
165347
- return paths.find((path5) => existsSync20(path5));
165463
+ return paths.find((path5) => existsSync21(path5));
165348
165464
  }
165349
165465
  function loadConfigFile2(path5, scope) {
165350
165466
  try {
@@ -165524,12 +165640,12 @@ var init_config2 = __esm(() => {
165524
165640
 
165525
165641
  // src/lib/diagnostics-pi.ts
165526
165642
  import { createHash as createHash3 } from "node:crypto";
165527
- import { existsSync as existsSync21, readdirSync as readdirSync3, readFileSync as readFileSync16, statSync as statSync6 } from "node:fs";
165528
- import { createRequire as createRequire4 } from "node:module";
165643
+ import { existsSync as existsSync22, readdirSync as readdirSync3, readFileSync as readFileSync16, statSync as statSync6 } from "node:fs";
165644
+ import { createRequire as createRequire5 } from "node:module";
165529
165645
  import { homedir as homedir15, userInfo as userInfo2 } from "node:os";
165530
- import { join as join19 } from "node:path";
165646
+ import { join as join20 } from "node:path";
165531
165647
  function getSelfVersion3() {
165532
- const req = createRequire4(import.meta.url);
165648
+ const req = createRequire5(import.meta.url);
165533
165649
  for (const relPath of ["../../package.json", "../package.json"]) {
165534
165650
  try {
165535
165651
  const pkg = req(relPath);
@@ -165542,7 +165658,7 @@ function getSelfVersion3() {
165542
165658
  }
165543
165659
  function fileSize2(path5) {
165544
165660
  try {
165545
- return existsSync21(path5) ? statSync6(path5).size : 0;
165661
+ return existsSync22(path5) ? statSync6(path5).size : 0;
165546
165662
  } catch {
165547
165663
  return 0;
165548
165664
  }
@@ -165592,7 +165708,7 @@ function sanitizeValue2(value, key = "") {
165592
165708
  return value;
165593
165709
  }
165594
165710
  function readJsonc3(path5) {
165595
- if (!existsSync21(path5))
165711
+ if (!existsSync22(path5))
165596
165712
  return { value: {} };
165597
165713
  try {
165598
165714
  return {
@@ -165606,13 +165722,13 @@ function readJsonc3(path5) {
165606
165722
  }
165607
165723
  }
165608
165724
  function getProjectConfigPath(cwd) {
165609
- return join19(cwd, ".pi", "magic-context.jsonc");
165725
+ return join20(cwd, ".pi", "magic-context.jsonc");
165610
165726
  }
165611
165727
  function readConfigDiagnostic(path5) {
165612
165728
  const parsed = readJsonc3(path5);
165613
165729
  return {
165614
165730
  path: path5,
165615
- exists: existsSync21(path5),
165731
+ exists: existsSync22(path5),
165616
165732
  ...parsed.parseError ? { parseError: parsed.parseError } : {},
165617
165733
  flags: sanitizeValue2(parsed.value)
165618
165734
  };
@@ -165629,8 +165745,8 @@ function reverseSlugToDirectory(slug) {
165629
165745
  return `/${inner.replace(/-/g, "/")}`;
165630
165746
  }
165631
165747
  function collectPiRecentSessions() {
165632
- const sessionsRoot = join19(homedir15(), ".pi", "agent", "sessions");
165633
- if (!existsSync21(sessionsRoot))
165748
+ const sessionsRoot = join20(homedir15(), ".pi", "agent", "sessions");
165749
+ if (!existsSync22(sessionsRoot))
165634
165750
  return [];
165635
165751
  try {
165636
165752
  const slugs = readdirSync3(sessionsRoot, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name);
@@ -165639,7 +165755,7 @@ function collectPiRecentSessions() {
165639
165755
  const directory = reverseSlugToDirectory(slug);
165640
165756
  if (!directory)
165641
165757
  continue;
165642
- const slugDir = join19(sessionsRoot, slug);
165758
+ const slugDir = join20(sessionsRoot, slug);
165643
165759
  let files;
165644
165760
  try {
165645
165761
  files = readdirSync3(slugDir).filter((name2) => name2.endsWith(".jsonl"));
@@ -165648,7 +165764,7 @@ function collectPiRecentSessions() {
165648
165764
  }
165649
165765
  for (const file2 of files) {
165650
165766
  try {
165651
- const mtime = statSync6(join19(slugDir, file2)).mtimeMs;
165767
+ const mtime = statSync6(join20(slugDir, file2)).mtimeMs;
165652
165768
  const sessionId = file2.replace(/\.jsonl$/, "");
165653
165769
  candidates.push({ sessionId, directory, mtime });
165654
165770
  } catch {}
@@ -165699,11 +165815,11 @@ function parseHistorianDumpMeta2(path5) {
165699
165815
  }
165700
165816
  }
165701
165817
  function listDumpsInDir2(dir, limit) {
165702
- if (!existsSync21(dir))
165818
+ if (!existsSync22(dir))
165703
165819
  return { count: 0, recent: [] };
165704
165820
  try {
165705
165821
  const entries = readdirSync3(dir).filter((name2) => name2.endsWith(".xml")).map((name2) => {
165706
- const stat = statSync6(join19(dir, name2));
165822
+ const stat = statSync6(join20(dir, name2));
165707
165823
  return {
165708
165824
  name: name2,
165709
165825
  mtime: stat.mtimeMs,
@@ -165712,7 +165828,7 @@ function listDumpsInDir2(dir, limit) {
165712
165828
  }).sort((a, b2) => b2.mtime - a.mtime);
165713
165829
  const now = Date.now();
165714
165830
  const recent = entries.slice(0, limit).map((entry) => {
165715
- const meta3 = parseHistorianDumpMeta2(join19(dir, entry.name));
165831
+ const meta3 = parseHistorianDumpMeta2(join20(dir, entry.name));
165716
165832
  const summary = {
165717
165833
  name: entry.name,
165718
165834
  ageMinutes: Math.round((now - entry.mtime) / 60000),
@@ -165775,9 +165891,9 @@ async function collectDiagnostics2(cwd = process.cwd()) {
165775
165891
  const projectConfigPath = getProjectConfigPath(cwd);
165776
165892
  const loaded = loadPiConfig({ cwd });
165777
165893
  const storageDirPath = getMagicContextStorageDir();
165778
- const dbPath = join19(storageDirPath, "context.db");
165894
+ const dbPath = join20(storageDirPath, "context.db");
165779
165895
  const logPath = getMagicContextLogPath2("pi");
165780
- const logFileSize = existsSync21(logPath) ? statSync6(logPath).size : 0;
165896
+ const logFileSize = existsSync22(logPath) ? statSync6(logPath).size : 0;
165781
165897
  const otherPiExtensions = packages.filter((entry) => !isPiMagicContextPackageEntry(entry)).map(describePiPackageEntry);
165782
165898
  const recentSessions = collectPiRecentSessions();
165783
165899
  const historianDumps = collectPiHistorianDumps(recentSessions);
@@ -165792,7 +165908,7 @@ async function collectDiagnostics2(cwd = process.cwd()) {
165792
165908
  piVersion: pi ? getPiVersion(pi.path) : null,
165793
165909
  settings: {
165794
165910
  path: settingsPath,
165795
- exists: existsSync21(settingsPath),
165911
+ exists: existsSync22(settingsPath),
165796
165912
  ...settingsParsed.parseError ? { parseError: settingsParsed.parseError } : {},
165797
165913
  hasMagicContextPackage: hasPiMagicContextPackage(packages),
165798
165914
  packages: sanitizeValue2(packages)
@@ -165808,7 +165924,7 @@ async function collectDiagnostics2(cwd = process.cwd()) {
165808
165924
  loadWarnings: loaded.warnings.map(sanitizeString2),
165809
165925
  storageDir: {
165810
165926
  path: storageDirPath,
165811
- exists: existsSync21(storageDirPath),
165927
+ exists: existsSync22(storageDirPath),
165812
165928
  contextDbSizeBytes: fileSize2(dbPath)
165813
165929
  },
165814
165930
  conflicts: {
@@ -165817,7 +165933,7 @@ async function collectDiagnostics2(cwd = process.cwd()) {
165817
165933
  },
165818
165934
  logFile: {
165819
165935
  path: logPath,
165820
- exists: existsSync21(logPath),
165936
+ exists: existsSync22(logPath),
165821
165937
  sizeKb: Math.round(logFileSize / 1024)
165822
165938
  },
165823
165939
  recentSessions,
@@ -165911,7 +166027,7 @@ var init_diagnostics_pi = __esm(() => {
165911
166027
 
165912
166028
  // src/lib/logs-pi.ts
165913
166029
  import { readFileSync as readFileSync17, writeFileSync as writeFileSync10 } from "node:fs";
165914
- import { join as join20 } from "node:path";
166030
+ import { join as join21 } from "node:path";
165915
166031
  function sanitizeLogContent2(content) {
165916
166032
  return sanitizeString2(content);
165917
166033
  }
@@ -165976,7 +166092,7 @@ async function bundleIssueReport2(report, description, title, options = {}) {
165976
166092
  `);
165977
166093
  const bodyMarkdown = capBodyToGithubLimit(rawBodyMarkdown);
165978
166094
  const cwd = options.cwd ?? process.cwd();
165979
- const path5 = join20(cwd, `magic-context-pi-issue-${formatTimestamp2(options.now ?? new Date)}.md`);
166095
+ const path5 = join21(cwd, `magic-context-pi-issue-${formatTimestamp2(options.now ?? new Date)}.md`);
165980
166096
  writeFileSync10(path5, `${bodyMarkdown}
165981
166097
  `);
165982
166098
  return { path: path5, bodyMarkdown };
@@ -165989,7 +166105,7 @@ var init_logs_pi = __esm(() => {
165989
166105
  // src/commands/doctor-pi.ts
165990
166106
  import { execFileSync as execFileSync4, spawnSync as spawnSync3 } from "node:child_process";
165991
166107
  import {
165992
- existsSync as existsSync22,
166108
+ existsSync as existsSync23,
165993
166109
  mkdirSync as mkdirSync7,
165994
166110
  readdirSync as readdirSync4,
165995
166111
  readFileSync as readFileSync18,
@@ -165997,9 +166113,9 @@ import {
165997
166113
  statSync as statSync7,
165998
166114
  writeFileSync as writeFileSync11
165999
166115
  } from "node:fs";
166000
- import { createRequire as createRequire5 } from "node:module";
166116
+ import { createRequire as createRequire6 } from "node:module";
166001
166117
  import { homedir as homedir16 } from "node:os";
166002
- import { dirname as dirname9, join as join21 } from "node:path";
166118
+ import { dirname as dirname10, isAbsolute as isAbsolute3, join as join22 } from "node:path";
166003
166119
  function depsFrom(options) {
166004
166120
  return {
166005
166121
  ...DEFAULT_DEPS,
@@ -166023,7 +166139,7 @@ function printDoctorHelp() {
166023
166139
  console.log("");
166024
166140
  }
166025
166141
  function selfVersion() {
166026
- const req = createRequire5(import.meta.url);
166142
+ const req = createRequire6(import.meta.url);
166027
166143
  for (const relPath of ["../../package.json", "../package.json"]) {
166028
166144
  try {
166029
166145
  const pkg = req(relPath);
@@ -166101,11 +166217,25 @@ function readJsonc4(path5) {
166101
166217
  function packagesFrom(settings) {
166102
166218
  return Array.isArray(settings.packages) ? settings.packages : [];
166103
166219
  }
166220
+ function piPluginDirCandidates(packages, cwd) {
166221
+ const dirs = [];
166222
+ const agentDir = getPiAgentConfigDir();
166223
+ for (const entry of packages) {
166224
+ const spec = typeof entry === "string" ? entry.trim() : "";
166225
+ if (!spec || spec.startsWith("npm:"))
166226
+ continue;
166227
+ const resolved = isAbsolute3(spec) ? spec : join22(agentDir, spec);
166228
+ dirs.push(resolved);
166229
+ }
166230
+ dirs.push(join22(agentDir, "npm", "node_modules", PACKAGE_NAME));
166231
+ dirs.push(join22(cwd, ".pi", "npm", "node_modules", PACKAGE_NAME));
166232
+ return dirs.filter((dir) => existsSync23(join22(dir, "package.json")));
166233
+ }
166104
166234
  function projectConfigPath(cwd) {
166105
- return join21(cwd, ".pi", "magic-context.jsonc");
166235
+ return join22(cwd, ".pi", "magic-context.jsonc");
166106
166236
  }
166107
166237
  function readConfigForEmbedding(path5) {
166108
- if (!existsSync22(path5))
166238
+ if (!existsSync23(path5))
166109
166239
  return null;
166110
166240
  try {
166111
166241
  const rawText = readFileSync18(path5, "utf-8");
@@ -166167,19 +166297,19 @@ function countTable(db, table) {
166167
166297
  }
166168
166298
  function cacheRoots() {
166169
166299
  const home = homedir16();
166170
- const cacheHome = process.env.XDG_CACHE_HOME || join21(home, ".cache");
166300
+ const cacheHome = process.env.XDG_CACHE_HOME || join22(home, ".cache");
166171
166301
  return [
166172
- join21(home, ".pi", "cache", "extensions"),
166173
- join21(home, ".pi", "cache", "packages"),
166174
- join21(cacheHome, "pi", "extensions"),
166175
- join21(cacheHome, "pi", "packages"),
166176
- join21(getPiAgentConfigDir(), "cache", "extensions")
166302
+ join22(home, ".pi", "cache", "extensions"),
166303
+ join22(home, ".pi", "cache", "packages"),
166304
+ join22(cacheHome, "pi", "extensions"),
166305
+ join22(cacheHome, "pi", "packages"),
166306
+ join22(getPiAgentConfigDir(), "cache", "extensions")
166177
166307
  ];
166178
166308
  }
166179
166309
  function findPiMagicContextCacheDirs(self, force = false) {
166180
166310
  const found = new Map;
166181
166311
  const visit = (path5, depth) => {
166182
- if (depth < 0 || !existsSync22(path5))
166312
+ if (depth < 0 || !existsSync23(path5))
166183
166313
  return;
166184
166314
  let stat;
166185
166315
  try {
@@ -166189,8 +166319,8 @@ function findPiMagicContextCacheDirs(self, force = false) {
166189
166319
  }
166190
166320
  if (!stat.isDirectory())
166191
166321
  return;
166192
- const packageJson = join21(path5, "package.json");
166193
- if (existsSync22(packageJson)) {
166322
+ const packageJson = join22(path5, "package.json");
166323
+ if (existsSync23(packageJson)) {
166194
166324
  try {
166195
166325
  const pkg = JSON.parse(readFileSync18(packageJson, "utf-8"));
166196
166326
  const name2 = typeof pkg.name === "string" ? pkg.name : "";
@@ -166211,7 +166341,7 @@ function findPiMagicContextCacheDirs(self, force = false) {
166211
166341
  return;
166212
166342
  }
166213
166343
  for (const entry of entries)
166214
- visit(join21(path5, entry), depth - 1);
166344
+ visit(join22(path5, entry), depth - 1);
166215
166345
  };
166216
166346
  for (const root of cacheRoots())
166217
166347
  visit(root, 5);
@@ -166248,7 +166378,7 @@ async function runHealthChecks(options) {
166248
166378
  }
166249
166379
  const settingsPath = getPiUserExtensionsPath();
166250
166380
  let packages = [];
166251
- if (!existsSync22(settingsPath)) {
166381
+ if (!existsSync23(settingsPath)) {
166252
166382
  add(results, "warn", `Pi settings not found at ${settingsPath}`);
166253
166383
  repairPlan.addPackageEntry = true;
166254
166384
  } else {
@@ -166272,7 +166402,7 @@ async function runHealthChecks(options) {
166272
166402
  ["user", userConfigPath, true],
166273
166403
  ["project", projectPath, false]
166274
166404
  ]) {
166275
- if (!existsSync22(path5)) {
166405
+ if (!existsSync23(path5)) {
166276
166406
  if (required2) {
166277
166407
  add(results, "warn", `No ${label} magic-context.jsonc found at ${path5}`);
166278
166408
  repairPlan.writeUserConfig = true;
@@ -166305,8 +166435,8 @@ async function runHealthChecks(options) {
166305
166435
  add(results, "pass", `historian.model "${historianModel}" has thinking_level "${historianThinkingLevel}" configured`);
166306
166436
  }
166307
166437
  const storageDir = getMagicContextStorageDir();
166308
- const dbPath = join21(storageDir, "context.db");
166309
- const existedBeforeOpen = existsSync22(dbPath);
166438
+ const dbPath = join22(storageDir, "context.db");
166439
+ const existedBeforeOpen = existsSync23(dbPath);
166310
166440
  if (existedBeforeOpen)
166311
166441
  add(results, "pass", `Shared context DB exists at ${dbPath}`);
166312
166442
  else
@@ -166369,7 +166499,23 @@ async function runHealthChecks(options) {
166369
166499
  } else if (loadedConfig.config.embedding.provider === "off") {
166370
166500
  add(results, "info", "Embedding provider disabled");
166371
166501
  } else {
166372
- add(results, "pass", `Embedding provider: ${loadedConfig.config.embedding.provider}`);
166502
+ let runtimeReported = false;
166503
+ for (const pluginDir of piPluginDirCandidates(packages, options.cwd)) {
166504
+ const runtime = checkLocalEmbeddingRuntimeByResolution(pluginDir);
166505
+ if (runtime.state === "ok") {
166506
+ add(results, "pass", `Embedding provider: ${loadedConfig.config.embedding.provider} (native runtime present)`);
166507
+ runtimeReported = true;
166508
+ break;
166509
+ }
166510
+ if (runtime.state === "package-missing" || runtime.state === "binary-missing") {
166511
+ add(results, "warn", `Embedding provider: local — native runtime (onnxruntime-node) is ${runtime.state === "package-missing" ? "not installed" : "missing its platform binary"}. Local embeddings won't work. Fix: reinstall the plugin, or set ` + "`embedding.provider` to `openai-compatible` (LM Studio / Ollama) or `off`. " + "Existing memories are unaffected.");
166512
+ runtimeReported = true;
166513
+ break;
166514
+ }
166515
+ }
166516
+ if (!runtimeReported) {
166517
+ add(results, "pass", `Embedding provider: ${loadedConfig.config.embedding.provider}`);
166518
+ }
166373
166519
  }
166374
166520
  const piEntries = packages.filter(isPiMagicContextPackageEntry).map(describePiPackageEntry);
166375
166521
  if (piEntries.length > 1) {
@@ -166391,7 +166537,7 @@ async function runHealthChecks(options) {
166391
166537
  add(results, "pass", "Pi extension cache clean (no stale cached package found)");
166392
166538
  }
166393
166539
  const logPath = getMagicContextLogPath2("pi");
166394
- if (existsSync22(logPath)) {
166540
+ if (existsSync23(logPath)) {
166395
166541
  const stat = statSync7(logPath);
166396
166542
  const sizeKb = (stat.size / 1024).toFixed(0);
166397
166543
  const lines = readFileSync18(logPath, "utf-8").split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
@@ -166428,7 +166574,7 @@ async function runHealthChecks(options) {
166428
166574
  return { results, repairPlan, ...summarize(results) };
166429
166575
  }
166430
166576
  function writeDefaultMagicContextConfig(path5) {
166431
- mkdirSync7(dirname9(path5), { recursive: true });
166577
+ mkdirSync7(dirname10(path5), { recursive: true });
166432
166578
  const config2 = {
166433
166579
  $schema: "https://raw.githubusercontent.com/cortexkit/magic-context/master/assets/magic-context.schema.json",
166434
166580
  ...MagicContextConfigSchema.parse({})
@@ -166450,7 +166596,7 @@ function repair(plan, prompts) {
166450
166596
  }
166451
166597
  if (plan.writeUserConfig) {
166452
166598
  const configPath = getPiUserConfigPath();
166453
- if (!existsSync22(configPath)) {
166599
+ if (!existsSync23(configPath)) {
166454
166600
  try {
166455
166601
  writeDefaultMagicContextConfig(configPath);
166456
166602
  prompts.log.success(`Wrote default Magic Context config to ${configPath}`);
@@ -166621,6 +166767,7 @@ var init_doctor_pi = __esm(async () => {
166621
166767
  init_data_path();
166622
166768
  init_config2();
166623
166769
  init_diagnostics_pi();
166770
+ init_embedding_runtime();
166624
166771
  init_logs_pi();
166625
166772
  init_paths();
166626
166773
  init_pi_helpers();
@@ -166652,7 +166799,7 @@ var exports_doctor = {};
166652
166799
  __export(exports_doctor, {
166653
166800
  runDoctor: () => runDoctor3
166654
166801
  });
166655
- import { existsSync as existsSync23, rmSync as rmSync3 } from "node:fs";
166802
+ import { existsSync as existsSync24, rmSync as rmSync3 } from "node:fs";
166656
166803
  async function runDoctor3(options) {
166657
166804
  if (options.clear)
166658
166805
  return runClear();
@@ -166741,7 +166888,7 @@ async function runClear() {
166741
166888
  const s = spinner();
166742
166889
  s.start(`Clearing ${item.path}`);
166743
166890
  try {
166744
- if (existsSync23(item.path)) {
166891
+ if (existsSync24(item.path)) {
166745
166892
  rmSync3(item.path, { recursive: true, force: true });
166746
166893
  }
166747
166894
  s.stop(`Cleared ${item.path}`);
@@ -166776,9 +166923,9 @@ var init_doctor = __esm(async () => {
166776
166923
  });
166777
166924
 
166778
166925
  // src/index.ts
166779
- import { createRequire as createRequire6 } from "node:module";
166926
+ import { createRequire as createRequire7 } from "node:module";
166780
166927
  function getVersion() {
166781
- const req = createRequire6(import.meta.url);
166928
+ const req = createRequire7(import.meta.url);
166782
166929
  for (const relPath of ["../../package.json", "../package.json"]) {
166783
166930
  try {
166784
166931
  const pkg = req(relPath);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cortexkit/magic-context",
3
- "version": "0.24.1",
3
+ "version": "0.25.0",
4
4
  "description": "Unified CLI for Magic Context — setup, doctor, and migration across OpenCode and Pi",
5
5
  "keywords": [
6
6
  "opencode",