@cortexkit/magic-context 0.49.79 → 0.49.81

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 +189 -70
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -2520,7 +2520,7 @@ var init_window_geometry = __esm(() => {
2520
2520
  function setOutputReserveConfig(config) {
2521
2521
  outputReserveConfig = config;
2522
2522
  }
2523
- var SEPARATE_OUTPUT_QUOTA_PROVIDERS, outputReserveConfig, reserveClampLogSeen;
2523
+ var SEPARATE_OUTPUT_QUOTA_PROVIDERS, outputReserveConfig, reserveClampLogSeen, v2DraftModelLimits, v2DraftModelLimitLogged;
2524
2524
  var init_models_dev_cache = __esm(() => {
2525
2525
  init_data_path();
2526
2526
  init_harness_provider_map();
@@ -2533,6 +2533,8 @@ var init_models_dev_cache = __esm(() => {
2533
2533
  "antigravity-cli"
2534
2534
  ]);
2535
2535
  reserveClampLogSeen = new Set;
2536
+ v2DraftModelLimits = new Map;
2537
+ v2DraftModelLimitLogged = new Set;
2536
2538
  });
2537
2539
 
2538
2540
  // ../plugin/src/config/agent-disable.ts
@@ -39640,6 +39642,7 @@ function getOpenCodeConfigDirs() {
39640
39642
  var init_opencode_config_dir = () => {};
39641
39643
 
39642
39644
  // ../plugin/src/shared/conflict-detector.ts
39645
+ import { readFileSync as readFileSync17 } from "node:fs";
39643
39646
  import { homedir as homedir14 } from "node:os";
39644
39647
  import { join as join18 } from "node:path";
39645
39648
  function detectConflicts(directory, options) {
@@ -39737,17 +39740,19 @@ function openCodeConfigFileChain(directory, hostGeneration) {
39737
39740
  ];
39738
39741
  return [...new Set(files)];
39739
39742
  }
39740
- function readCompactionFromConfigFiles(directory, hostGeneration) {
39743
+ function readCompactionFromConfigFiles(directory, hostGeneration, readConfig = readJsoncFile) {
39741
39744
  const merged = {};
39742
39745
  for (const filePath of openCodeConfigFileChain(directory, hostGeneration)) {
39743
39746
  let block;
39744
39747
  try {
39745
- block = readJsoncFile(filePath)?.compaction;
39748
+ block = readConfig(filePath)?.compaction;
39746
39749
  } catch {}
39747
39750
  if (!block || typeof block !== "object")
39748
39751
  continue;
39749
39752
  if (block.auto !== undefined)
39750
39753
  merged.auto = block.auto;
39754
+ if (block.background !== undefined)
39755
+ merged.background = block.background;
39751
39756
  if (block.prune !== undefined)
39752
39757
  merged.prune = block.prune;
39753
39758
  if (block.buffer !== undefined)
@@ -39757,6 +39762,31 @@ function readCompactionFromConfigFiles(directory, hostGeneration) {
39757
39762
  }
39758
39763
  return merged;
39759
39764
  }
39765
+ function readOpenCode2BackgroundCompaction(directory) {
39766
+ let backgroundSource;
39767
+ const unreadable = [];
39768
+ const compaction = readCompactionFromConfigFiles(directory, "v2", (path) => {
39769
+ try {
39770
+ const text = readFileSync17(path, "utf-8").replace(/^\uFEFF/, "");
39771
+ const config = parseJsonc(text);
39772
+ if (!config || typeof config !== "object" || Array.isArray(config)) {
39773
+ throw new Error("Expected an OpenCode config object");
39774
+ }
39775
+ if (config.compaction?.background !== undefined)
39776
+ backgroundSource = path;
39777
+ return config;
39778
+ } catch (error) {
39779
+ if (error.code !== "ENOENT")
39780
+ unreadable.push(path);
39781
+ return null;
39782
+ }
39783
+ });
39784
+ return {
39785
+ enabled: compaction.auto !== false && compaction.background !== false,
39786
+ backgroundSource,
39787
+ unreadable
39788
+ };
39789
+ }
39760
39790
  function isRelevantCompactionBlock(block, hostGeneration) {
39761
39791
  if (block.auto !== undefined)
39762
39792
  return true;
@@ -39901,7 +39931,7 @@ var init_conflict_detector = __esm(() => {
39901
39931
  });
39902
39932
 
39903
39933
  // ../plugin/src/shared/conflict-fixer.ts
39904
- import { existsSync as existsSync24, readFileSync as readFileSync17, writeFileSync as writeFileSync6 } from "node:fs";
39934
+ import { existsSync as existsSync24, readFileSync as readFileSync18, writeFileSync as writeFileSync6 } from "node:fs";
39905
39935
  import { homedir as homedir15 } from "node:os";
39906
39936
  import { join as join19 } from "node:path";
39907
39937
  function isRecord3(value) {
@@ -39915,7 +39945,7 @@ function readConfig(filePath) {
39915
39945
  return null;
39916
39946
  }
39917
39947
  try {
39918
- const text = readFileSync17(filePath, "utf-8");
39948
+ const text = readFileSync18(filePath, "utf-8");
39919
39949
  const parsed = import_comment_json5.parse(text);
39920
39950
  return isRecord3(parsed) ? { config: parsed, text } : null;
39921
39951
  } catch {
@@ -39931,18 +39961,21 @@ function resolveUserOpenCodeConfigPath() {
39931
39961
  return paths.configJsonc;
39932
39962
  return paths.configJson;
39933
39963
  }
39964
+ function projectOpenCodeConfigPaths(directory) {
39965
+ return [
39966
+ join19(directory, ".opencode", "opencode.jsonc"),
39967
+ join19(directory, ".opencode", "opencode.json"),
39968
+ join19(directory, "opencode.jsonc"),
39969
+ join19(directory, "opencode.json")
39970
+ ];
39971
+ }
39934
39972
  function collectOpenCodeConfigPaths(directory) {
39935
39973
  const paths = new Set;
39936
39974
  const userConfig = resolveUserOpenCodeConfigPath();
39937
39975
  if (existsSync24(userConfig)) {
39938
39976
  paths.add(userConfig);
39939
39977
  }
39940
- for (const filePath of [
39941
- join19(directory, ".opencode", "opencode.jsonc"),
39942
- join19(directory, ".opencode", "opencode.json"),
39943
- join19(directory, "opencode.jsonc"),
39944
- join19(directory, "opencode.json")
39945
- ]) {
39978
+ for (const filePath of projectOpenCodeConfigPaths(directory)) {
39946
39979
  if (existsSync24(filePath)) {
39947
39980
  paths.add(filePath);
39948
39981
  }
@@ -40116,12 +40149,17 @@ function isPlainObject5(value) {
40116
40149
  }
40117
40150
  function planOpenCodeConfigUpdate(configPath, removeDcp = false, compactionEnabled = true, hostGeneration = "v1") {
40118
40151
  const registrationKey = pluginConfigKeyFor(hostGeneration);
40152
+ const compactionDefaults = {
40153
+ auto: false,
40154
+ prune: false,
40155
+ ...hostGeneration === "v2" ? { background: false } : {}
40156
+ };
40119
40157
  const existsAtCommit = existsSync25(configPath);
40120
40158
  const existing = existsAtCommit ? readJsoncConfigForUpdate(configPath) : {};
40121
40159
  if (!existsAtCommit) {
40122
40160
  const created = { [registrationKey]: [OPENCODE_PLUGIN_ENTRY_WITH_VERSION] };
40123
40161
  if (compactionEnabled) {
40124
- created.compaction = { auto: false, prune: false };
40162
+ created.compaction = compactionDefaults;
40125
40163
  }
40126
40164
  return `${import_comment_json6.stringify(created, null, 2)}
40127
40165
  `;
@@ -40155,16 +40193,14 @@ function planOpenCodeConfigUpdate(configPath, removeDcp = false, compactionEnabl
40155
40193
  const compaction = existing.compaction;
40156
40194
  const hasCompactionObject = typeof compaction === "object" && compaction !== null && !Array.isArray(compaction);
40157
40195
  if (!hasCompactionObject) {
40158
- text = setJsoncValue(text, ["compaction"], { auto: false, prune: false });
40196
+ text = setJsoncValue(text, ["compaction"], compactionDefaults);
40159
40197
  changed = true;
40160
40198
  } else {
40161
40199
  const fields = compaction;
40162
- if (fields.auto !== false) {
40163
- text = setJsoncValue(text, ["compaction", "auto"], false);
40164
- changed = true;
40165
- }
40166
- if (fields.prune !== false) {
40167
- text = setJsoncValue(text, ["compaction", "prune"], false);
40200
+ for (const key of Object.keys(compactionDefaults)) {
40201
+ if (fields[key] === false)
40202
+ continue;
40203
+ text = setJsoncValue(text, ["compaction", key], false);
40168
40204
  changed = true;
40169
40205
  }
40170
40206
  }
@@ -40658,7 +40694,7 @@ import {
40658
40694
  accessSync as accessSync3,
40659
40695
  existsSync as existsSync27,
40660
40696
  constants as fsConstants,
40661
- readFileSync as readFileSync18,
40697
+ readFileSync as readFileSync19,
40662
40698
  renameSync as renameSync5,
40663
40699
  statSync as statSync15,
40664
40700
  writeFileSync as writeFileSync7
@@ -40712,7 +40748,7 @@ function getWinningConfig(directory, surface) {
40712
40748
  try {
40713
40749
  if (!existsSync27(path))
40714
40750
  continue;
40715
- const parsed = parseJsonConfig(readFileSync18(path, "utf-8"));
40751
+ const parsed = parseJsonConfig(readFileSync19(path, "utf-8"));
40716
40752
  const entries = getPluginEntries(parsed);
40717
40753
  if (entries.some((entry) => entry === PACKAGE_NAME || entry.startsWith(`${PACKAGE_NAME}@`))) {
40718
40754
  if (winner) {
@@ -40749,14 +40785,14 @@ var init_checker = __esm(async () => {
40749
40785
  });
40750
40786
 
40751
40787
  // src/lib/opencode-plugin-schema-fence.ts
40752
- import { existsSync as existsSync28, readdirSync as readdirSync6, readFileSync as readFileSync19 } from "node:fs";
40788
+ import { existsSync as existsSync28, readdirSync as readdirSync6, readFileSync as readFileSync20 } from "node:fs";
40753
40789
  import { join as join22 } from "node:path";
40754
40790
  import { gunzipSync as gunzipSync2 } from "node:zlib";
40755
40791
  function readPackageVersion(packageJsonPath) {
40756
40792
  try {
40757
40793
  if (!existsSync28(packageJsonPath))
40758
40794
  return null;
40759
- const packageJson = JSON.parse(readFileSync19(packageJsonPath, "utf-8"));
40795
+ const packageJson = JSON.parse(readFileSync20(packageJsonPath, "utf-8"));
40760
40796
  if (packageJson.name !== OPENCODE_PLUGIN_NAME || typeof packageJson.version !== "string") {
40761
40797
  return null;
40762
40798
  }
@@ -40793,7 +40829,7 @@ function readFenceFromDist(packageDirectory) {
40793
40829
  }
40794
40830
  if (!entry.isFile() || !/\.(?:[cm]?js|ts)$/.test(entry.name))
40795
40831
  continue;
40796
- const fence = readFenceValue(readFileSync19(path, "utf-8"));
40832
+ const fence = readFenceValue(readFileSync20(path, "utf-8"));
40797
40833
  if (fence !== null)
40798
40834
  fenceValues.add(fence);
40799
40835
  }
@@ -40962,13 +40998,13 @@ var init_opencode_plugin_schema_fence = __esm(async () => {
40962
40998
  });
40963
40999
 
40964
41000
  // src/commands/doctor-opencode-cache.ts
40965
- import { existsSync as existsSync29, readFileSync as readFileSync20, rmSync as rmSync7 } from "node:fs";
41001
+ import { existsSync as existsSync29, readFileSync as readFileSync21, rmSync as rmSync7 } from "node:fs";
40966
41002
  function readCachedPluginVersion(pluginCacheDir) {
40967
41003
  try {
40968
41004
  const installedPkgPath = getOpenCodePluginPackageJsonPath(pluginCacheDir);
40969
41005
  if (!existsSync29(installedPkgPath))
40970
41006
  return;
40971
- const pkg = JSON.parse(readFileSync20(installedPkgPath, "utf-8"));
41007
+ const pkg = JSON.parse(readFileSync21(installedPkgPath, "utf-8"));
40972
41008
  return typeof pkg.version === "string" ? pkg.version : undefined;
40973
41009
  } catch {
40974
41010
  return;
@@ -41332,7 +41368,7 @@ var init_doctor_prune_discovery = __esm(async () => {
41332
41368
 
41333
41369
  // src/commands/doctor-storage-holders.ts
41334
41370
  import { execFileSync as execFileSync5 } from "node:child_process";
41335
- import { readFileSync as readFileSync21, realpathSync as realpathSync7 } from "node:fs";
41371
+ import { readFileSync as readFileSync22, realpathSync as realpathSync7 } from "node:fs";
41336
41372
  import { join as join23, resolve as resolve12 } from "node:path";
41337
41373
  function canonicalStoragePath(path) {
41338
41374
  try {
@@ -41360,7 +41396,7 @@ function processReferencesStorage(pid, storageDir) {
41360
41396
  if (process.platform === "linux") {
41361
41397
  for (const name of ["cmdline", "environ"]) {
41362
41398
  try {
41363
- texts.push(readFileSync21(`/proc/${pid}/${name}`, "utf8"));
41399
+ texts.push(readFileSync22(`/proc/${pid}/${name}`, "utf8"));
41364
41400
  } catch {}
41365
41401
  }
41366
41402
  } else {
@@ -42914,7 +42950,7 @@ var init_doctor_identity_splits = __esm(async () => {
42914
42950
  // src/commands/doctor-merge-identity.ts
42915
42951
  import { execFileSync as execFileSync7 } from "node:child_process";
42916
42952
  import { createHash as createHash7 } from "node:crypto";
42917
- import { existsSync as existsSync35, mkdtempSync as mkdtempSync2, readdirSync as readdirSync8, readFileSync as readFileSync22, statSync as statSync20 } from "node:fs";
42953
+ import { existsSync as existsSync35, mkdtempSync as mkdtempSync2, readdirSync as readdirSync8, readFileSync as readFileSync23, statSync as statSync20 } from "node:fs";
42918
42954
  import { dirname as dirname22, join as join28, resolve as resolve16 } from "node:path";
42919
42955
  function parseMergeIdentityArgs(args) {
42920
42956
  const values = {};
@@ -43127,7 +43163,7 @@ function observations(db, hostPath, storageDir) {
43127
43163
  if (!file.endsWith(".json"))
43128
43164
  continue;
43129
43165
  try {
43130
- const record = JSON.parse(readFileSync22(join28(sidecars, file), "utf8"));
43166
+ const record = JSON.parse(readFileSync23(join28(sidecars, file), "utf8"));
43131
43167
  if (typeof record.directory === "string" && typeof record.identity === "string")
43132
43168
  add(record.directory, record.identity);
43133
43169
  } catch {}
@@ -43208,7 +43244,7 @@ function runMergeIdentityCli(args, deps = {}) {
43208
43244
  ensureStorageDirectorySync(sidecarBackup, true);
43209
43245
  let backupBytes = 0;
43210
43246
  for (const entry of sidecarEntries) {
43211
- const content = readFileSync22(join28(sidecarRoot, entry));
43247
+ const content = readFileSync23(join28(sidecarRoot, entry));
43212
43248
  writeStorageFileAtomicSync(join28(sidecarBackup, entry), content, true);
43213
43249
  backupBytes += content.byteLength;
43214
43250
  }
@@ -48320,7 +48356,7 @@ var DATABASE_REPAIR_COMMAND = "bunx @cortexkit/magic-context@latest doctor repai
48320
48356
 
48321
48357
  // src/lib/github-issue.ts
48322
48358
  import { spawnSync as spawnSync7 } from "node:child_process";
48323
- import { readFileSync as readFileSync23 } from "node:fs";
48359
+ import { readFileSync as readFileSync24 } from "node:fs";
48324
48360
  function runGhCommand(args) {
48325
48361
  try {
48326
48362
  const result = spawnSync7("gh", args, {
@@ -48347,7 +48383,7 @@ function failed(result) {
48347
48383
  function submitGithubIssue(title, bodyPath, runner = runGhCommand) {
48348
48384
  let body;
48349
48385
  try {
48350
- body = readFileSync23(bodyPath, "utf-8");
48386
+ body = readFileSync24(bodyPath, "utf-8");
48351
48387
  } catch (error) {
48352
48388
  return {
48353
48389
  ok: false,
@@ -49471,6 +49507,7 @@ var init_issue_log_templates_generated = __esm(() => {
49471
49507
  "pass permission report failed after the request was decided; serving the pass:",
49472
49508
  "system-prompt-hash skipped (OpenCode internal agent: title/summary/compaction)",
49473
49509
  "thinking binding recovery: persistence failed; leaving the bound blocks intact",
49510
+ "v2 compaction hook: fired answered=true source=typescript_fallback row=running",
49474
49511
  "v2 refusal: interrupting the turn before the provider request arm=storage-busy",
49475
49512
  "WARN: [auto-update-checker] Failed to fetch latest version for channel: latest",
49476
49513
  'Pi subagent agent "\x01" has no strict tool allow-list; forcing an empty tool list',
@@ -49555,6 +49592,7 @@ var init_issue_log_templates_generated = __esm(() => {
49555
49592
  "Pi publication commit_failed reason=capture_failed; serving managed context",
49556
49593
  "transform refused degraded pass site=reasoning-removal-persistence-failure:",
49557
49594
  "transform: historian unavailable; clearing stale compartmentInProgress flag",
49595
+ "v2 compaction hook: fired answered=true source=typescript_fallback row=none",
49558
49596
  "mc-module: finished \x01 pending context.db write(s) left by an earlier process",
49559
49597
  "prompt_surface.guidance_override_path (\x01) is empty; using built-in guidance.\x020p",
49560
49598
  "request tools changed (kind=\x01, model=\x01, schemas \x01→\x01): releasing signed thinking\x021m",
@@ -49767,6 +49805,7 @@ var init_issue_log_templates_generated = __esm(() => {
49767
49805
  "transform refused degraded pass site=compaction-marker-drain-failure:",
49768
49806
  "transform refused degraded pass site=store-generation-rebase-failure:",
49769
49807
  "transform: recovery chain stops: the next historian run did not start",
49808
+ "v2 compaction hook: fired answered=true source=typescript row=running",
49770
49809
  "v95 temporal metadata: malformed JSON skipped; original blob retained",
49771
49810
  "v95 temporal metadata: non-array JSON skipped; original blob retained",
49772
49811
  "prompt_surface.tool_descriptions.\x01 is empty; the override was ignored.",
@@ -49863,7 +49902,7 @@ var init_issue_log_templates_generated = __esm(() => {
49863
49902
  "historian no-op: waiting for new history after no forward progress",
49864
49903
  "transform refused degraded pass site=stale-reduce-strip-exception:",
49865
49904
  "transform: recovery chain stops: the request could not be counted:",
49866
- "v2 compaction hook: fired answered=true source=typescript_fallback",
49905
+ "v2 compaction hook: fired answered=true source=typescript row=none",
49867
49906
  "v2 response ownership unavailable; keeping system identity pending",
49868
49907
  "[git-commits] sweep parked for \x01: directory identity has no commits",
49869
49908
  "[dreamer] domain lease lost (memory:\x01) — stopping remaining task(s)",
@@ -49899,10 +49938,12 @@ var init_issue_log_templates_generated = __esm(() => {
49899
49938
  "transform refused degraded pass site=m0-m1-injection-degradation:",
49900
49939
  "transform refused degraded pass site=overflow-state-read-failure:",
49901
49940
  "transform refused degraded pass site=tagging-persistence-failure:",
49941
+ "v2 compaction hook: fired answered=true source=module row=running",
49902
49942
  "heartbeat for \x01 refused: malformed_response; abandoning this claim",
49903
49943
  "injected \x01 facts + \x01 memories into message[0] (no compartments yet)",
49904
49944
  "v2 fork inheritance: fork of \x01 already has state; not copied again\x020s",
49905
49945
  "Subagent temperature omitted for \x01: no host or models.dev metadata\x020m",
49946
+ "v2 model catalog lookup failed for \x01/\x01; using selected model limits\x020m,1m",
49906
49947
  "historian trigger eval: usage=\x01% (\x01 tokens) [\x01], checking trigger...",
49907
49948
  "[dreamer] domain lease busy (maintain-docs:\x01) — deferring \x01 task(s)",
49908
49949
  "[dreamer] domain lease busy (user-memories:\x01) — deferring \x01 task(s)",
@@ -50003,6 +50044,7 @@ var init_issue_log_templates_generated = __esm(() => {
50003
50044
  "system delivery acknowledgement failed (keeping pending work):",
50004
50045
  "transform: cannot force-start compartment agent without client",
50005
50046
  "transform: injected memories/facts block (no compartments yet)",
50047
+ "v2 compaction hook: fired answered=true source=module row=none",
50006
50048
  'invalid cache_ttl "\x01" in ctx-status; falling back to default 5m',
50007
50049
  "v2 boundary trim: dropped \x01 messages before the module boundary",
50008
50050
  "Subagent temperature sent for \x01: no host or models.dev metadata\x020m",
@@ -50180,7 +50222,6 @@ var init_issue_log_templates_generated = __esm(() => {
50180
50222
  "recomp skipped: compartment lease held by another process",
50181
50223
  "rust transform wire invariant failed; LKG replay required",
50182
50224
  "transform: compartmentInProgress flag set, starting agent",
50183
- "v2 compaction hook: fired answered=true source=typescript",
50184
50225
  "wrapup: timed out waiting for the compartment-state lease",
50185
50226
  "[migrations] v12 cleaned \x01 orphan memory_embeddings row(s)",
50186
50227
  "\x01: prompt unsettled — session \x01 left to the age-gated sweep\x021s",
@@ -50332,7 +50373,6 @@ var init_issue_log_templates_generated = __esm(() => {
50332
50373
  "LKG snapshot slices failed verification; slot cleared",
50333
50374
  "protected-tail migration seed fell back to ordinal 1:",
50334
50375
  "registered context handler (tagging + drops + nudges)",
50335
- "v2 compaction hook: fired answered=true source=module",
50336
50376
  "WARN: message_end: persist session_meta usage failed:",
50337
50377
  "[\x01] primary: model not found, retrying with suggestion",
50338
50378
  "injected \x01 facts into message[0] (no compartments yet)",
@@ -51568,7 +51608,7 @@ var init_issue_log_templates_generated = __esm(() => {
51568
51608
  });
51569
51609
 
51570
51610
  // src/lib/log-lines.ts
51571
- import { existsSync as existsSync40, readFileSync as readFileSync24, statSync as statSync22 } from "node:fs";
51611
+ import { existsSync as existsSync40, readFileSync as readFileSync25, statSync as statSync22 } from "node:fs";
51572
51612
  import { tmpdir as tmpdir3 } from "node:os";
51573
51613
  import { join as join33 } from "node:path";
51574
51614
  function tokenize(input, limit = Number.POSITIVE_INFINITY) {
@@ -51869,7 +51909,7 @@ function inspectLogFile(path) {
51869
51909
  return { path, exists: false, sizeKb: 0, lineCount: 0, grammar: "unknown" };
51870
51910
  }
51871
51911
  try {
51872
- const content = readFileSync24(path, "utf8");
51912
+ const content = readFileSync25(path, "utf8");
51873
51913
  const lines = content.split(/\r?\n/).filter((line) => line.length > 0);
51874
51914
  const grammars = new Set(lines.flatMap((line) => {
51875
51915
  const parsed = parseLogLine(line);
@@ -51896,7 +51936,7 @@ function readLogLines(files) {
51896
51936
  return [];
51897
51937
  try {
51898
51938
  let precedingTimestamp = "";
51899
- return readFileSync24(file.path, "utf8").split(/\r?\n/).filter((line) => line.length > 0).map((line, lineIndex) => {
51939
+ return readFileSync25(file.path, "utf8").split(/\r?\n/).filter((line) => line.length > 0).map((line, lineIndex) => {
51900
51940
  precedingTimestamp = parseLogLine(line)?.ts ?? precedingTimestamp;
51901
51941
  return { line, timestamp: precedingTimestamp, fileIndex, lineIndex };
51902
51942
  });
@@ -52505,7 +52545,7 @@ var init_issue_body = __esm(() => {
52505
52545
  });
52506
52546
 
52507
52547
  // src/lib/omp-hide-secrets.ts
52508
- import { existsSync as existsSync41, readdirSync as readdirSync9, readFileSync as readFileSync25, statSync as statSync23 } from "node:fs";
52548
+ import { existsSync as existsSync41, readdirSync as readdirSync9, readFileSync as readFileSync26, statSync as statSync23 } from "node:fs";
52509
52549
  import { join as join34, resolve as resolve18 } from "node:path";
52510
52550
  function stripYamlComment(line) {
52511
52551
  let quote = null;
@@ -52629,7 +52669,7 @@ function readHideSecretsFromJson(text) {
52629
52669
  function readSource(layer, path, format) {
52630
52670
  let text;
52631
52671
  try {
52632
- text = readFileSync25(path, "utf-8");
52672
+ text = readFileSync26(path, "utf-8");
52633
52673
  } catch (error) {
52634
52674
  const code = error.code;
52635
52675
  return {
@@ -52730,7 +52770,7 @@ var init_omp_hide_secrets = __esm(() => {
52730
52770
 
52731
52771
  // src/commands/doctor-omp.ts
52732
52772
  import { execFileSync as execFileSync8, spawnSync as spawnSync8 } from "node:child_process";
52733
- import { existsSync as existsSync42, readFileSync as readFileSync26 } from "node:fs";
52773
+ import { existsSync as existsSync42, readFileSync as readFileSync27 } from "node:fs";
52734
52774
  import { createRequire as createRequire3 } from "node:module";
52735
52775
  import { isAbsolute as isAbsolute9, join as join35, resolve as resolve19 } from "node:path";
52736
52776
  function parseSemver(value) {
@@ -52777,7 +52817,7 @@ function readConfig2(path) {
52777
52817
  if (!existsSync42(path))
52778
52818
  return {};
52779
52819
  try {
52780
- const parsed = import_comment_json8.parse(readFileSync26(path, "utf-8"));
52820
+ const parsed = import_comment_json8.parse(readFileSync27(path, "utf-8"));
52781
52821
  return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? {} : { error: "top level is not an object" };
52782
52822
  } catch (error) {
52783
52823
  return { error: error instanceof Error ? error.message : String(error) };
@@ -52787,7 +52827,7 @@ function pluginDeclaresOmp(path) {
52787
52827
  if (!path)
52788
52828
  return null;
52789
52829
  try {
52790
- const pkg = JSON.parse(readFileSync26(join35(path, "package.json"), "utf-8"));
52830
+ const pkg = JSON.parse(readFileSync27(join35(path, "package.json"), "utf-8"));
52791
52831
  return Array.isArray(pkg.omp?.extensions) || Array.isArray(pkg.pi?.extensions);
52792
52832
  } catch {
52793
52833
  return null;
@@ -54089,12 +54129,12 @@ function listShadowBackfillStalls(db, projectIdentity) {
54089
54129
  var SHADOW_BACKFILL_PROVENANCE_KEY = "_magicContextShadowBackfill";
54090
54130
 
54091
54131
  // ../plugin/src/shared/auto-update-provenance.ts
54092
- import { existsSync as existsSync43, readFileSync as readFileSync27 } from "node:fs";
54132
+ import { existsSync as existsSync43, readFileSync as readFileSync28 } from "node:fs";
54093
54133
  function readAutoUpdateCheckState(path) {
54094
54134
  if (!existsSync43(path))
54095
54135
  return null;
54096
54136
  try {
54097
- const value = JSON.parse(readFileSync27(path, "utf-8"));
54137
+ const value = JSON.parse(readFileSync28(path, "utf-8"));
54098
54138
  if (!value || typeof value !== "object" || Array.isArray(value))
54099
54139
  return null;
54100
54140
  const raw = value;
@@ -54124,7 +54164,7 @@ import {
54124
54164
  chmodSync as chmodSync4,
54125
54165
  existsSync as existsSync44,
54126
54166
  mkdirSync as mkdirSync8,
54127
- readFileSync as readFileSync28,
54167
+ readFileSync as readFileSync29,
54128
54168
  renameSync as renameSync8,
54129
54169
  statSync as statSync24,
54130
54170
  writeFileSync as writeFileSync8
@@ -54183,7 +54223,7 @@ function ensureTuiPluginEntry(options = {}) {
54183
54223
  const configPath = resolveTuiConfigPath(options.configDir);
54184
54224
  let config = {};
54185
54225
  if (existsSync44(configPath)) {
54186
- const raw = readFileSync28(configPath, "utf-8");
54226
+ const raw = readFileSync29(configPath, "utf-8");
54187
54227
  config = import_comment_json9.parse(raw) ?? {};
54188
54228
  }
54189
54229
  const plugins = Array.isArray(config.plugin) ? [...config.plugin] : [];
@@ -54270,7 +54310,7 @@ function scanHistorianSessionDumpDirs(root) {
54270
54310
  var init_historian_dump_dirs = () => {};
54271
54311
 
54272
54312
  // src/lib/diagnostics-opencode.ts
54273
- import { existsSync as existsSync46, readFileSync as readFileSync29, statSync as statSync26 } from "node:fs";
54313
+ import { existsSync as existsSync46, readFileSync as readFileSync30, statSync as statSync26 } from "node:fs";
54274
54314
  import { createRequire as createRequire4 } from "node:module";
54275
54315
  import { join as join38 } from "node:path";
54276
54316
  function getSelfVersion() {
@@ -54287,7 +54327,7 @@ function getSelfVersion() {
54287
54327
  }
54288
54328
  function readLegacyCachedVersion(root) {
54289
54329
  try {
54290
- const pkg = JSON.parse(readFileSync29(getOpenCodePluginPackageJsonPath(root), "utf-8"));
54330
+ const pkg = JSON.parse(readFileSync30(getOpenCodePluginPackageJsonPath(root), "utf-8"));
54291
54331
  return typeof pkg.version === "string" ? pkg.version : undefined;
54292
54332
  } catch {
54293
54333
  return;
@@ -54359,7 +54399,7 @@ function readConfig3(path) {
54359
54399
  if (!existsSync46(path))
54360
54400
  return { value: null };
54361
54401
  try {
54362
- const raw = readFileSync29(path, "utf-8");
54402
+ const raw = readFileSync30(path, "utf-8");
54363
54403
  const value = import_comment_json10.parse(raw);
54364
54404
  return { value };
54365
54405
  } catch (error) {
@@ -54384,7 +54424,7 @@ function configHasPluginEntry(config) {
54384
54424
  }
54385
54425
  function parseHistorianDumpMeta(path) {
54386
54426
  try {
54387
- const xml = readFileSync29(path, "utf-8");
54427
+ const xml = readFileSync30(path, "utf-8");
54388
54428
  const parsed = parseCompartmentOutput(xml);
54389
54429
  const factCountByCategory = {};
54390
54430
  for (const fact of parsed.facts) {
@@ -54961,7 +55001,7 @@ var init_embedding_local = __esm(async () => {
54961
55001
 
54962
55002
  // src/lib/embedding-runtime.ts
54963
55003
  import { spawnSync as spawnSync9 } from "node:child_process";
54964
- import { existsSync as existsSync47, readFileSync as readFileSync30 } from "node:fs";
55004
+ import { existsSync as existsSync47, readFileSync as readFileSync31 } from "node:fs";
54965
55005
  import { createRequire as createRequire5 } from "node:module";
54966
55006
  import { dirname as dirname25, join as join39, sep as sep3 } from "node:path";
54967
55007
  function describeError(error) {
@@ -55109,7 +55149,7 @@ function expectedBinaryRelPath(platform, arch) {
55109
55149
  }
55110
55150
  function onnxRuntimeNodeVersion(packageDir) {
55111
55151
  try {
55112
- const parsed = JSON.parse(readFileSync30(join39(packageDir, "package.json"), "utf8"));
55152
+ const parsed = JSON.parse(readFileSync31(join39(packageDir, "package.json"), "utf8"));
55113
55153
  return typeof parsed.version === "string" ? parsed.version : undefined;
55114
55154
  } catch {
55115
55155
  return;
@@ -56002,6 +56042,76 @@ var init_doctor_harness_relabel = __esm(async () => {
56002
56042
  await init_opencode2_relabel();
56003
56043
  });
56004
56044
 
56045
+ // src/commands/doctor-opencode-background-compaction.ts
56046
+ function checkOpenCodeBackgroundCompaction(directory, hostVersion, options, sink) {
56047
+ if (!options.compactionEnabled || !hostVersion)
56048
+ return;
56049
+ const comparison = compareSemverPrecedence(hostVersion, "2.3.1");
56050
+ if (comparison === null || comparison < 0)
56051
+ return;
56052
+ const before = readOpenCode2BackgroundCompaction(directory);
56053
+ if (!before.enabled)
56054
+ return;
56055
+ sink.warn("OpenCode prepares compactions before you ask for them (compaction.background). If /compact uses a prepared answer, Magic Context does not shrink the next request. Run doctor --fix to turn off background compaction.");
56056
+ if (!options.fix)
56057
+ return;
56058
+ const userPath = detectConfigPaths().opencodeConfig;
56059
+ for (const path of new Set([userPath, ...projectOpenCodeConfigPaths(directory)])) {
56060
+ try {
56061
+ const config = readJsoncConfig(path);
56062
+ if (config.kind === "parse-error")
56063
+ throw config.error;
56064
+ if (config.kind === "missing") {
56065
+ if (path !== userPath)
56066
+ continue;
56067
+ writeFileAtomic(path, `{
56068
+ "compaction": {
56069
+ "background": false
56070
+ }
56071
+ }
56072
+ `);
56073
+ } else {
56074
+ const block = config.value.compaction;
56075
+ const fields = block && typeof block === "object" && !Array.isArray(block) ? block : undefined;
56076
+ if (fields?.background === false)
56077
+ continue;
56078
+ if (path !== userPath && fields?.background === undefined)
56079
+ continue;
56080
+ const { bom, text } = readJsoncTextForEdit(path);
56081
+ const next = fields ? setJsoncValue(text, ["compaction", "background"], false) : setJsoncValue(text, ["compaction"], { background: false });
56082
+ writeFileAtomic(path, bom + next);
56083
+ }
56084
+ sink.wrote(`Set compaction.background: false in ${path}`);
56085
+ } catch (error) {
56086
+ sink.warn(`Could not set compaction.background in ${path}: ${String(error)}`);
56087
+ }
56088
+ }
56089
+ const after = readOpenCode2BackgroundCompaction(directory);
56090
+ const unchecked = [
56091
+ ...after.unreadable,
56092
+ ...process.env.OPENCODE_CONFIG_CONTENT ? ["the OPENCODE_CONFIG_CONTENT layer"] : []
56093
+ ];
56094
+ if (after.enabled || unchecked.length) {
56095
+ const sources = [
56096
+ ...after.enabled ? [after.backgroundSource ?? "OpenCode's default"] : [],
56097
+ ...unchecked
56098
+ ];
56099
+ sink.warn(`Background compaction may still be enabled. Check compaction.background in: ${[...new Set(sources)].join(", ")}.`);
56100
+ } else {
56101
+ sink.info("Background compaction is disabled in the config files doctor could check. Remote, organization, or managed OpenCode settings may override them.");
56102
+ }
56103
+ sink.info("No OpenCode restart is needed for changes to compaction.background.");
56104
+ }
56105
+ var init_doctor_opencode_background_compaction = __esm(async () => {
56106
+ init_conflict_detector();
56107
+ init_conflict_fixer();
56108
+ init_jsonc_edit();
56109
+ init_atomic_write();
56110
+ init_jsonc_config();
56111
+ init_paths();
56112
+ await init_doctor_opencode2_cache();
56113
+ });
56114
+
56005
56115
  // src/commands/doctor-opencode-plugin-duplicates.ts
56006
56116
  import { isDeepStrictEqual } from "node:util";
56007
56117
  function entryOptions(entry) {
@@ -56246,7 +56356,7 @@ function removeDeprecatedReasoningAge(config) {
56246
56356
 
56247
56357
  // src/commands/doctor-opencode.ts
56248
56358
  import { spawnSync as spawnSync10 } from "node:child_process";
56249
- import { existsSync as existsSync48, mkdtempSync as mkdtempSync4, readFileSync as readFileSync31, rmSync as rmSync9 } from "node:fs";
56359
+ import { existsSync as existsSync48, mkdtempSync as mkdtempSync4, readFileSync as readFileSync32, rmSync as rmSync9 } from "node:fs";
56250
56360
  import { createRequire as createRequire6 } from "node:module";
56251
56361
  import { homedir as homedir21, tmpdir as tmpdir4 } from "node:os";
56252
56362
  import { dirname as dirname27, join as join41, resolve as resolve20 } from "node:path";
@@ -56513,7 +56623,7 @@ function collectNpmReleaseAgeWarnings() {
56513
56623
  if (!existsSync48(npmrcPath))
56514
56624
  return ageWarnings;
56515
56625
  try {
56516
- const npmrc = readFileSync31(npmrcPath, "utf-8");
56626
+ const npmrc = readFileSync32(npmrcPath, "utf-8");
56517
56627
  for (const line of npmrc.split(`
56518
56628
  `)) {
56519
56629
  const trimmed = line.trim();
@@ -56557,7 +56667,7 @@ async function checkPluginFreshnessForIssue(deps = {}) {
56557
56667
  return { npmVersions: {} };
56558
56668
  let config;
56559
56669
  try {
56560
- config = import_comment_json11.parse(readFileSync31(paths.opencodeConfig, "utf-8"));
56670
+ config = import_comment_json11.parse(readFileSync32(paths.opencodeConfig, "utf-8"));
56561
56671
  } catch {}
56562
56672
  const configDir = dirname27(paths.opencodeConfig);
56563
56673
  if (config && !isOpenCodePluginRegistered(config, configDir))
@@ -56958,7 +57068,7 @@ async function runDoctor2(options = {}) {
56958
57068
  let magicContextStatusKnown = paths.opencodeConfigFormat === "none";
56959
57069
  if (!magicContextStatusKnown) {
56960
57070
  try {
56961
- const config = import_comment_json11.parse(readFileSync31(paths.opencodeConfig, "utf-8"));
57071
+ const config = import_comment_json11.parse(readFileSync32(paths.opencodeConfig, "utf-8"));
56962
57072
  magicContextInstalled = isOpenCodePluginRegistered(config, dirname27(paths.opencodeConfig));
56963
57073
  magicContextStatusKnown = true;
56964
57074
  } catch {}
@@ -57272,7 +57382,7 @@ async function runDoctor2(options = {}) {
57272
57382
  };
57273
57383
  if (paths.opencodeConfigFormat !== "none") {
57274
57384
  try {
57275
- const raw = readFileSync31(paths.opencodeConfig, "utf-8");
57385
+ const raw = readFileSync32(paths.opencodeConfig, "utf-8");
57276
57386
  const config = import_comment_json11.parse(raw);
57277
57387
  const configName = paths.opencodeConfigFormat === "jsonc" ? "opencode.jsonc" : "opencode.json";
57278
57388
  const configDir = dirname27(paths.opencodeConfig);
@@ -57333,6 +57443,14 @@ async function runDoctor2(options = {}) {
57333
57443
  const compactionEnabled = resolveCompactionEnabledForDoctor();
57334
57444
  const conflictResult = detectConflicts(cwd, { compactionEnabled });
57335
57445
  log3.info("Compaction check: file-based; the running server's resolved config may differ — `opencode debug config` is authoritative");
57446
+ checkOpenCodeBackgroundCompaction(cwd, activeInstallation.version, { compactionEnabled, fix: options.fix }, {
57447
+ warn,
57448
+ info: (message) => log3.info(message),
57449
+ wrote: (message) => {
57450
+ pass(message);
57451
+ fixed++;
57452
+ }
57453
+ });
57336
57454
  if (conflictResult.hasConflict) {
57337
57455
  for (const reason of conflictResult.reasons) {
57338
57456
  fail(`Conflict: ${reason}`);
@@ -57367,7 +57485,7 @@ async function runDoctor2(options = {}) {
57367
57485
  fixed++;
57368
57486
  } else if (existsSync48(paths.tuiConfig)) {
57369
57487
  try {
57370
- const tuiRaw = readFileSync31(paths.tuiConfig, "utf-8");
57488
+ const tuiRaw = readFileSync32(paths.tuiConfig, "utf-8");
57371
57489
  const tuiConfig = import_comment_json11.parse(tuiRaw);
57372
57490
  const tuiConfigDir = dirname27(paths.tuiConfig);
57373
57491
  const tuiRawPlugins = Array.isArray(tuiConfig?.plugin) ? tuiConfig.plugin : [];
@@ -57422,7 +57540,7 @@ async function runDoctor2(options = {}) {
57422
57540
  let embeddingHostConfig = null;
57423
57541
  try {
57424
57542
  if (paths.opencodeConfigFormat !== "none")
57425
- embeddingHostConfig = import_comment_json11.parse(readFileSync31(paths.opencodeConfig, "utf-8"));
57543
+ embeddingHostConfig = import_comment_json11.parse(readFileSync32(paths.opencodeConfig, "utf-8"));
57426
57544
  } catch {}
57427
57545
  const embeddingInstalls = getOpenCodeLoadedPluginInstallRoots(hostGeneration, embeddingHostConfig);
57428
57546
  const unusedInstalls = embeddingInstalls.others.filter((root) => existsSync48(root));
@@ -57522,7 +57640,7 @@ ${formatDatabaseRepairGuidance(dbPath)}`);
57522
57640
  let pluginConfigUse;
57523
57641
  if (paths.opencodeConfigFormat !== "none") {
57524
57642
  try {
57525
- pluginConfigUse = readOpenCodePluginConfigUse(import_comment_json11.parse(readFileSync31(paths.opencodeConfig, "utf-8")), dirname27(paths.opencodeConfig));
57643
+ pluginConfigUse = readOpenCodePluginConfigUse(import_comment_json11.parse(readFileSync32(paths.opencodeConfig, "utf-8")), dirname27(paths.opencodeConfig));
57526
57644
  } catch {}
57527
57645
  }
57528
57646
  const cacheResult = await clearPluginCache({
@@ -57576,7 +57694,7 @@ ${formatDatabaseRepairGuidance(dbPath)}`);
57576
57694
  let v2DistTag;
57577
57695
  if (paths.opencodeConfigFormat !== "none") {
57578
57696
  try {
57579
- v2DistTag = configuredOpenCodeV2DistTag(import_comment_json11.parse(readFileSync31(paths.opencodeConfig, "utf-8")));
57697
+ v2DistTag = configuredOpenCodeV2DistTag(import_comment_json11.parse(readFileSync32(paths.opencodeConfig, "utf-8")));
57580
57698
  } catch {}
57581
57699
  }
57582
57700
  const v2Cache = reportOpenCodeV2PluginCache(checkOpenCodeV2PluginCache({
@@ -57726,6 +57844,7 @@ var init_doctor_opencode = __esm(async () => {
57726
57844
  init_v22_backfill_commands(),
57727
57845
  init_doctor_cached_plugin_fence(),
57728
57846
  init_doctor_harness_relabel(),
57847
+ init_doctor_opencode_background_compaction(),
57729
57848
  init_doctor_opencode_cache(),
57730
57849
  init_doctor_opencode_plugin_duplicates(),
57731
57850
  init_doctor_opencode_plugin_entry(),
@@ -57996,7 +58115,7 @@ var init_model_chain_health = __esm(() => {
57996
58115
  });
57997
58116
 
57998
58117
  // src/lib/diagnostics-pi.ts
57999
- import { existsSync as existsSync49, readdirSync as readdirSync11, readFileSync as readFileSync32, statSync as statSync27 } from "node:fs";
58118
+ import { existsSync as existsSync49, readdirSync as readdirSync11, readFileSync as readFileSync33, statSync as statSync27 } from "node:fs";
58000
58119
  import { createRequire as createRequire7 } from "node:module";
58001
58120
  import { join as join42 } from "node:path";
58002
58121
  function getSelfVersion3() {
@@ -58029,7 +58148,7 @@ function readJsonc(path) {
58029
58148
  return { value: {} };
58030
58149
  try {
58031
58150
  return {
58032
- value: import_comment_json12.parse(readFileSync32(path, "utf-8"))
58151
+ value: import_comment_json12.parse(readFileSync33(path, "utf-8"))
58033
58152
  };
58034
58153
  } catch (error) {
58035
58154
  return {
@@ -58099,7 +58218,7 @@ function collectPiRecentSessions() {
58099
58218
  }
58100
58219
  function parseHistorianDumpMeta2(path) {
58101
58220
  try {
58102
- const xml = readFileSync32(path, "utf-8");
58221
+ const xml = readFileSync33(path, "utf-8");
58103
58222
  const parsed = parseCompartmentOutput(xml);
58104
58223
  const factCountByCategory = {};
58105
58224
  for (const fact of parsed.facts) {
@@ -58423,7 +58542,7 @@ var init_logs_pi = __esm(() => {
58423
58542
 
58424
58543
  // src/commands/doctor-pi.ts
58425
58544
  import { execFileSync as execFileSync9, spawnSync as spawnSync11 } from "node:child_process";
58426
- import { existsSync as existsSync50, lstatSync as lstatSync6, readdirSync as readdirSync12, readFileSync as readFileSync33, rmSync as rmSync10 } from "node:fs";
58545
+ import { existsSync as existsSync50, lstatSync as lstatSync6, readdirSync as readdirSync12, readFileSync as readFileSync34, rmSync as rmSync10 } from "node:fs";
58427
58546
  import { createRequire as createRequire8 } from "node:module";
58428
58547
  import { homedir as homedir22 } from "node:os";
58429
58548
  import { basename as basename7, isAbsolute as isAbsolute10, join as join44 } from "node:path";
@@ -58519,7 +58638,7 @@ function summarize(results) {
58519
58638
  function readJsonc2(path) {
58520
58639
  try {
58521
58640
  return {
58522
- value: import_comment_json13.parse(readFileSync33(path, "utf-8"))
58641
+ value: import_comment_json13.parse(readFileSync34(path, "utf-8"))
58523
58642
  };
58524
58643
  } catch (error) {
58525
58644
  return {
@@ -58702,7 +58821,7 @@ function findPiMagicContextCacheDirs(cwd, expectedVersion, force = false) {
58702
58821
  const packageJson = join44(path, "package.json");
58703
58822
  if (existsSync50(packageJson)) {
58704
58823
  try {
58705
- const pkg = JSON.parse(readFileSync33(packageJson, "utf-8"));
58824
+ const pkg = JSON.parse(readFileSync34(packageJson, "utf-8"));
58706
58825
  const name = typeof pkg.name === "string" ? pkg.name : "";
58707
58826
  const version = typeof pkg.version === "string" ? pkg.version : undefined;
58708
58827
  if (name === PACKAGE_NAME2) {
@@ -59171,7 +59290,7 @@ function piCacheClearBlocker(paths, deps) {
59171
59290
  function repair2(plan, prompts, deps) {
59172
59291
  let fixed = 0;
59173
59292
  for (const path of plan.reasoningAgeConfigPaths) {
59174
- const content = readFileSync33(path, "utf8");
59293
+ const content = readFileSync34(path, "utf8");
59175
59294
  const parsed = readJsonc2(path);
59176
59295
  if (parsed.error)
59177
59296
  continue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cortexkit/magic-context",
3
- "version": "0.49.79",
3
+ "version": "0.49.81",
4
4
  "description": "Unified CLI for Magic Context — setup, doctor, and migration across OpenCode, Pi, and OMP",
5
5
  "keywords": [
6
6
  "opencode",