@cortexkit/magic-context 0.21.5 → 0.21.7

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 +269 -40
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -10987,25 +10987,28 @@ function writeMagicContextConfig(configPath, options) {
10987
10987
  historian.model = options.historianModel;
10988
10988
  config.historian = historian;
10989
10989
  }
10990
+ const dreamer = config.dreamer ?? {};
10991
+ delete dreamer.enabled;
10990
10992
  if (options.dreamerEnabled) {
10991
- const dreamer = config.dreamer ?? {};
10992
- dreamer.enabled = true;
10993
+ delete dreamer.disable;
10993
10994
  if (options.dreamerModel) {
10994
10995
  dreamer.model = options.dreamerModel;
10995
10996
  }
10996
- config.dreamer = dreamer;
10997
10997
  } else {
10998
- const dreamer = config.dreamer ?? {};
10999
- dreamer.enabled = false;
11000
- config.dreamer = dreamer;
10998
+ dreamer.disable = true;
11001
10999
  }
11000
+ config.dreamer = dreamer;
11001
+ const sidekick = config.sidekick ?? {};
11002
+ delete sidekick.enabled;
11002
11003
  if (options.sidekickEnabled) {
11003
- const sidekick = config.sidekick ?? {};
11004
- sidekick.enabled = true;
11004
+ delete sidekick.disable;
11005
11005
  if (options.sidekickModel) {
11006
11006
  sidekick.model = options.sidekickModel;
11007
11007
  }
11008
11008
  config.sidekick = sidekick;
11009
+ } else {
11010
+ sidekick.disable = true;
11011
+ config.sidekick = sidekick;
11009
11012
  }
11010
11013
  if (options.claudeMax) {
11011
11014
  const cacheTtl = config.cache_ttl ?? {};
@@ -11311,23 +11314,20 @@ function writeMagicContextConfig2(configPath, options) {
11311
11314
  model: options.historianModel,
11312
11315
  thinking_level: options.historianThinkingLevel
11313
11316
  });
11314
- config.dreamer = {
11317
+ const dreamer = {
11315
11318
  ...config.dreamer ?? {},
11316
- enabled: options.dreamerEnabled,
11317
- model: options.dreamerModel
11319
+ model: options.dreamerModel,
11320
+ disable: options.dreamerEnabled ? undefined : true,
11321
+ enabled: undefined
11318
11322
  };
11319
- if (options.sidekickEnabled) {
11320
- config.sidekick = compactObject({
11321
- ...config.sidekick ?? {},
11322
- enabled: true,
11323
- model: options.sidekickModel
11324
- });
11325
- } else {
11326
- config.sidekick = {
11327
- ...config.sidekick ?? {},
11328
- enabled: false
11329
- };
11330
- }
11323
+ config.dreamer = compactObject(dreamer);
11324
+ const sidekick = {
11325
+ ...config.sidekick ?? {},
11326
+ model: options.sidekickEnabled ? options.sidekickModel : undefined,
11327
+ disable: options.sidekickEnabled ? undefined : true,
11328
+ enabled: undefined
11329
+ };
11330
+ config.sidekick = compactObject(sidekick);
11331
11331
  config.embedding = options.embedding;
11332
11332
  writeFileSync5(configPath, `${import_comment_json5.stringify(config, null, 2)}
11333
11333
  `);
@@ -12532,6 +12532,53 @@ var init_migrate = __esm(async () => {
12532
12532
  await init_sqlite();
12533
12533
  });
12534
12534
 
12535
+ // ../plugin/src/config/agent-disable.ts
12536
+ function clonePlainObject(value) {
12537
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
12538
+ return;
12539
+ }
12540
+ return { ...value };
12541
+ }
12542
+ function migrateLegacyEnabledForAgent(args) {
12543
+ const agent = clonePlainObject(args.patched[args.agentName]);
12544
+ if (!agent || !("enabled" in agent))
12545
+ return;
12546
+ const enabled = agent.enabled;
12547
+ const disable = agent.disable;
12548
+ delete agent.enabled;
12549
+ if (args.agentName === "historian") {
12550
+ args.warnings.push('Removed invalid "historian.enabled" in-memory (run doctor to persist).');
12551
+ args.patched.historian = agent;
12552
+ return;
12553
+ }
12554
+ if (args.agentName === "dreamer") {
12555
+ if (disable !== true && enabled === false) {
12556
+ agent.disable = true;
12557
+ args.warnings.push('Migrated "dreamer.enabled=false" → "dreamer.disable=true" in-memory (run doctor to persist). This now also disables manual /ctx-dream; for manual-only remove disable and set schedule="".');
12558
+ }
12559
+ args.patched.dreamer = agent;
12560
+ return;
12561
+ }
12562
+ if (disable !== true && enabled === false) {
12563
+ agent.disable = true;
12564
+ args.warnings.push('Migrated "sidekick.enabled=false" → "sidekick.disable=true" in-memory (run doctor to persist).');
12565
+ }
12566
+ args.patched.sidekick = agent;
12567
+ }
12568
+ function migrateLegacyAgentEnabledInMemory(rawConfig, warnings) {
12569
+ const shouldPatch = ["dreamer", "sidekick", "historian"].some((key) => {
12570
+ const agent = rawConfig[key];
12571
+ return typeof agent === "object" && agent !== null && !Array.isArray(agent) && "enabled" in agent;
12572
+ });
12573
+ if (!shouldPatch)
12574
+ return rawConfig;
12575
+ const patched = { ...rawConfig };
12576
+ migrateLegacyEnabledForAgent({ patched, agentName: "dreamer", warnings });
12577
+ migrateLegacyEnabledForAgent({ patched, agentName: "sidekick", warnings });
12578
+ migrateLegacyEnabledForAgent({ patched, agentName: "historian", warnings });
12579
+ return patched;
12580
+ }
12581
+
12535
12582
  // ../../node_modules/.bun/zod@4.4.3/node_modules/zod/v4/core/core.js
12536
12583
  function $constructor(name, initializer, params) {
12537
12584
  function init(inst, def) {
@@ -27211,7 +27258,6 @@ var init_magic_context = __esm(() => {
27211
27258
  ];
27212
27259
  PiThinkingLevelSchema = exports_external.enum(["off", "minimal", "low", "medium", "high", "xhigh"]).optional();
27213
27260
  DreamerConfigSchema = AgentOverrideConfigSchema.merge(exports_external.object({
27214
- enabled: exports_external.boolean().default(false),
27215
27261
  schedule: exports_external.string().default("02:00-06:00"),
27216
27262
  max_runtime_minutes: exports_external.number().min(10).default(120),
27217
27263
  tasks: exports_external.array(DreamingTaskSchema).default(DEFAULT_DREAMER_TASKS),
@@ -27229,7 +27275,6 @@ var init_magic_context = __esm(() => {
27229
27275
  thinking_level: PiThinkingLevelSchema
27230
27276
  }));
27231
27277
  SidekickConfigSchema = AgentOverrideConfigSchema.extend({
27232
- enabled: exports_external.boolean().default(false),
27233
27278
  timeout_ms: exports_external.number().default(30000),
27234
27279
  system_prompt: exports_external.string().optional(),
27235
27280
  thinking_level: PiThinkingLevelSchema
@@ -27579,7 +27624,8 @@ function migrateLegacyExperimental(rawConfig, warnings) {
27579
27624
  }
27580
27625
  function parsePluginConfig(rawConfig, recoveredTopLevelKeys = []) {
27581
27626
  const preMigrationWarnings = [];
27582
- const migrated = migrateLegacyExperimental(rawConfig, preMigrationWarnings);
27627
+ const migratedExperimental = migrateLegacyExperimental(rawConfig, preMigrationWarnings);
27628
+ const migrated = migrateLegacyAgentEnabledInMemory(migratedExperimental, preMigrationWarnings);
27583
27629
  const parsed = MagicContextConfigSchema.safeParse(migrated);
27584
27630
  const disabledHooks = Array.isArray(rawConfig.disabled_hooks) ? rawConfig.disabled_hooks.filter((value) => typeof value === "string") : undefined;
27585
27631
  const command = typeof rawConfig.command === "object" && rawConfig.command !== null ? rawConfig.command : undefined;
@@ -28563,6 +28609,91 @@ var init_diagnostics_opencode = __esm(() => {
28563
28609
  PLUGIN_ENTRY_WITH_VERSION = `${PLUGIN_NAME5}@latest`;
28564
28610
  });
28565
28611
 
28612
+ // src/lib/issue-body.ts
28613
+ function isErrorLogLine(line) {
28614
+ return ERROR_LOG_PATTERNS.some((rx) => rx.test(line));
28615
+ }
28616
+ function extractRecentErrors(sanitized, limit = 20) {
28617
+ const matches = [];
28618
+ const lines = sanitized.split(/\r?\n/);
28619
+ for (let i = lines.length - 1;i >= 0 && matches.length < limit; i -= 1) {
28620
+ if (isErrorLogLine(lines[i])) {
28621
+ matches.push(lines[i]);
28622
+ }
28623
+ }
28624
+ return matches.reverse();
28625
+ }
28626
+ function capBodyToGithubLimit(body, maxBytes = MAX_GITHUB_BODY_BYTES) {
28627
+ if (Buffer.byteLength(body, "utf8") <= maxBytes)
28628
+ return body;
28629
+ const heading = "## Log (last";
28630
+ const headingIdx = body.indexOf(heading);
28631
+ if (headingIdx === -1) {
28632
+ const marker = `
28633
+
28634
+ [truncated for GitHub 64KB limit]
28635
+ `;
28636
+ const markerBytes2 = Buffer.byteLength(marker, "utf8");
28637
+ return truncateToByteBudget(body, maxBytes - markerBytes2) + marker;
28638
+ }
28639
+ const fenceOpenIdx = body.indexOf("\n```", headingIdx);
28640
+ if (fenceOpenIdx === -1)
28641
+ return body;
28642
+ const logStart = fenceOpenIdx + "\n```\n".length;
28643
+ const fenceCloseIdx = body.indexOf("\n```", logStart);
28644
+ if (fenceCloseIdx === -1)
28645
+ return body;
28646
+ const head = body.slice(0, logStart);
28647
+ const log3 = body.slice(logStart, fenceCloseIdx);
28648
+ const tail = body.slice(fenceCloseIdx);
28649
+ const overheadBytes = Buffer.byteLength(head, "utf8") + Buffer.byteLength(tail, "utf8");
28650
+ const truncationMarker = `[truncated for GitHub 64KB limit — older log lines dropped]
28651
+ `;
28652
+ const markerBytes = Buffer.byteLength(truncationMarker, "utf8");
28653
+ const logBudget = maxBytes - overheadBytes - markerBytes;
28654
+ if (logBudget <= 0) {
28655
+ return `${head}${truncationMarker}${tail}`;
28656
+ }
28657
+ const lines = log3.split(`
28658
+ `);
28659
+ let keepLines = lines;
28660
+ let kept = keepLines.join(`
28661
+ `);
28662
+ while (Buffer.byteLength(kept, "utf8") > logBudget && keepLines.length > 1) {
28663
+ const dropCount = Math.max(1, Math.floor(keepLines.length * 0.05));
28664
+ keepLines = keepLines.slice(dropCount);
28665
+ kept = keepLines.join(`
28666
+ `);
28667
+ }
28668
+ if (Buffer.byteLength(kept, "utf8") > logBudget) {
28669
+ kept = truncateToByteBudget(kept, logBudget);
28670
+ }
28671
+ return `${head}${truncationMarker}${kept}${tail}`;
28672
+ }
28673
+ function truncateToByteBudget(input, maxBytes) {
28674
+ if (maxBytes <= 0)
28675
+ return "";
28676
+ const buf = Buffer.from(input, "utf8");
28677
+ if (buf.length <= maxBytes)
28678
+ return input;
28679
+ let end = maxBytes;
28680
+ while (end > 0 && (buf[end] & 192) === 128) {
28681
+ end -= 1;
28682
+ }
28683
+ return buf.subarray(0, end).toString("utf8");
28684
+ }
28685
+ var MAX_GITHUB_BODY_BYTES = 60000, ERROR_LOG_PATTERNS;
28686
+ var init_issue_body = __esm(() => {
28687
+ ERROR_LOG_PATTERNS = [
28688
+ /\bfailed:/i,
28689
+ /\b(?:[A-Z][a-zA-Z]*)?Error:\s/,
28690
+ /\bEMERGENCY\b/,
28691
+ /\bexception\b/i,
28692
+ /^\s+at\s+[\w.<>$]+\s+\(/,
28693
+ /^\s+at\s+(?:file:|node_modules\/|[^/\s]+:\d+)/
28694
+ ];
28695
+ });
28696
+
28566
28697
  // src/lib/logs-opencode.ts
28567
28698
  import { readFileSync as readFileSync12, writeFileSync as writeFileSync9 } from "node:fs";
28568
28699
  import { homedir as homedir12 } from "node:os";
@@ -28615,9 +28746,12 @@ async function bundleIssueReport(report, description, _title, sessionFilter = nu
28615
28746
  const historianScanWindow = sanitizeLogContent(logLines.slice(-4000).join(`
28616
28747
  `));
28617
28748
  const historianFailureLines = extractHistorianFailureLines(historianScanWindow, 30);
28749
+ const errorScanWindow = sanitizeLogContent(logLines.slice(-4000).join(`
28750
+ `));
28751
+ const recentErrorLines = extractRecentErrors(errorScanWindow, 20);
28618
28752
  const configBody = JSON.stringify(sanitizeConfigValue(report.magicContextConfig.flags), null, 2);
28619
28753
  const sanitizedConfigPath = report.configPaths.magicContextConfig.replace(homedir12(), "~");
28620
- const bodyMarkdown = [
28754
+ const rawBodyMarkdown = [
28621
28755
  "## Description",
28622
28756
  description,
28623
28757
  "",
@@ -28639,6 +28773,11 @@ async function bundleIssueReport(report, description, _title, sessionFilter = nu
28639
28773
  "## Historian failure signals (log, sanitized)",
28640
28774
  historianFailureLines.length === 0 ? "_No historian failure log lines found in recent history._" : ["```", historianFailureLines.join(`
28641
28775
  `), "```"].join(`
28776
+ `),
28777
+ "",
28778
+ "## Recent errors (last 20, sanitized)",
28779
+ recentErrorLines.length === 0 ? "_No error-shaped log lines found in recent history._" : ["```", recentErrorLines.join(`
28780
+ `), "```"].join(`
28642
28781
  `),
28643
28782
  "",
28644
28783
  `## Log (last ${LOG_TAIL_LINES} lines, sanitized)`,
@@ -28647,6 +28786,7 @@ async function bundleIssueReport(report, description, _title, sessionFilter = nu
28647
28786
  "```"
28648
28787
  ].join(`
28649
28788
  `);
28789
+ const bodyMarkdown = capBodyToGithubLimit(rawBodyMarkdown);
28650
28790
  const path4 = join15(process.cwd(), `magic-context-issue-${formatTimestamp(new Date)}.md`);
28651
28791
  writeFileSync9(path4, `${bodyMarkdown}
28652
28792
  `);
@@ -28655,6 +28795,7 @@ async function bundleIssueReport(report, description, _title, sessionFilter = nu
28655
28795
  var HISTORIAN_LOG_PATTERNS;
28656
28796
  var init_logs_opencode = __esm(() => {
28657
28797
  init_diagnostics_opencode();
28798
+ init_issue_body();
28658
28799
  init_redaction();
28659
28800
  HISTORIAN_LOG_PATTERNS = [
28660
28801
  /historian failure:/,
@@ -28673,6 +28814,43 @@ import { existsSync as existsSync17, readFileSync as readFileSync13, rmSync, sta
28673
28814
  import { createRequire as createRequire4 } from "node:module";
28674
28815
  import { homedir as homedir13 } from "node:os";
28675
28816
  import { join as join16 } from "node:path";
28817
+ function migrateLegacyAgentEnabledConfigForDoctor(mcConfig, logs) {
28818
+ let changed = false;
28819
+ let fixes = 0;
28820
+ const migrateLegacyAgentEnabled = (agentName) => {
28821
+ const agent = mcConfig[agentName];
28822
+ if (!agent || typeof agent !== "object" || !("enabled" in agent))
28823
+ return;
28824
+ const enabled = agent.enabled;
28825
+ const disable = agent.disable;
28826
+ delete agent.enabled;
28827
+ changed = true;
28828
+ fixes++;
28829
+ if (agentName === "historian") {
28830
+ logs.success("Removed invalid historian.enabled (historian uses disable=true to turn off).");
28831
+ return;
28832
+ }
28833
+ if (agentName === "dreamer") {
28834
+ if (disable !== true && enabled === false) {
28835
+ agent.disable = true;
28836
+ logs.warn("Migrated dreamer.enabled=false → dreamer.disable=true. This now also disables manual /ctx-dream. To keep manual dreaming, remove disable=true and set schedule to empty string.");
28837
+ } else {
28838
+ logs.success('Removed deprecated dreamer.enabled (use dreamer.disable=true to turn off the Dreamer agent; use schedule="" for manual-only dreaming).');
28839
+ }
28840
+ return;
28841
+ }
28842
+ if (disable !== true && enabled === false) {
28843
+ agent.disable = true;
28844
+ logs.success("Migrated sidekick.enabled=false → sidekick.disable=true.");
28845
+ } else {
28846
+ logs.success("Removed deprecated sidekick.enabled (use sidekick.disable=true to turn off Sidekick).");
28847
+ }
28848
+ };
28849
+ migrateLegacyAgentEnabled("dreamer");
28850
+ migrateLegacyAgentEnabled("sidekick");
28851
+ migrateLegacyAgentEnabled("historian");
28852
+ return { changed, fixes };
28853
+ }
28676
28854
  async function fetchNpmLatest(pkg, timeoutMs = 5000) {
28677
28855
  try {
28678
28856
  const controller = new AbortController;
@@ -29063,6 +29241,11 @@ async function runDoctor(options = {}) {
29063
29241
  log.success("Removed deprecated compaction_markers (always-on since v0.21.4)");
29064
29242
  fixed++;
29065
29243
  }
29244
+ const agentEnabledMigration = migrateLegacyAgentEnabledConfigForDoctor(mcConfig, log);
29245
+ if (agentEnabledMigration.changed) {
29246
+ mcChanged = true;
29247
+ fixed += agentEnabledMigration.fixes;
29248
+ }
29066
29249
  if (experimental && "user_memories" in experimental) {
29067
29250
  const dreamer = mcConfig.dreamer ?? {};
29068
29251
  const oldUM = experimental.user_memories;
@@ -29260,11 +29443,11 @@ async function runDoctor(options = {}) {
29260
29443
  const mcRaw = readFileSync13(paths.magicContextConfig, "utf-8");
29261
29444
  const mcConfig = import_comment_json9.parse(mcRaw);
29262
29445
  const dreamerObj = mcConfig?.dreamer;
29263
- const dreamerEnabled = dreamerObj?.enabled === true;
29446
+ const dreamerDisabled = dreamerObj?.disable === true;
29264
29447
  const userMemObj = dreamerObj?.user_memories;
29265
29448
  const userMemEnabled = userMemObj?.enabled !== false;
29266
- if (userMemEnabled && !dreamerEnabled) {
29267
- log.warn("dreamer.user_memories is enabled (default) but dreamer itself is disabled — user memory candidates will be collected but never promoted to stable memories. Enable `dreamer.enabled: true` or set `dreamer.user_memories.enabled: false` to silence this.");
29449
+ if (userMemEnabled && dreamerDisabled) {
29450
+ log.warn("dreamer.user_memories is enabled but dreamer.disable=true, so new promotions will not run. Remove dreamer.disable or set dreamer.user_memories.enabled=false.");
29268
29451
  issues++;
29269
29452
  }
29270
29453
  const pinKeyFilesObj = dreamerObj?.pin_key_files;
@@ -29439,11 +29622,11 @@ var init_doctor_opencode = __esm(async () => {
29439
29622
  PLUGIN_ENTRY_WITH_VERSION2 = `${PLUGIN_NAME6}@latest`;
29440
29623
  });
29441
29624
 
29442
- // ../plugin/src/features/magic-context/compartment-storage.ts
29443
- var insertCompartmentStatements, insertFactStatements;
29444
- var init_compartment_storage = __esm(() => {
29445
- insertCompartmentStatements = new WeakMap;
29446
- insertFactStatements = new WeakMap;
29625
+ // ../plugin/src/features/magic-context/compartment-lease.ts
29626
+ var COMPARTMENT_LEASE_TTL_MS, COMPARTMENT_LEASE_RENEWAL_MS;
29627
+ var init_compartment_lease = __esm(() => {
29628
+ COMPARTMENT_LEASE_TTL_MS = 5 * 60 * 1000;
29629
+ COMPARTMENT_LEASE_RENEWAL_MS = 60 * 1000;
29447
29630
  });
29448
29631
 
29449
29632
  // ../plugin/src/features/magic-context/compression-depth-storage.ts
@@ -29454,6 +29637,15 @@ var init_compression_depth_storage = __esm(() => {
29454
29637
  maxDepthStatements = new WeakMap;
29455
29638
  clearDepthStatements = new WeakMap;
29456
29639
  });
29640
+
29641
+ // ../plugin/src/features/magic-context/compartment-storage.ts
29642
+ var insertCompartmentStatements, insertFactStatements;
29643
+ var init_compartment_storage = __esm(() => {
29644
+ init_compartment_lease();
29645
+ init_compression_depth_storage();
29646
+ insertCompartmentStatements = new WeakMap;
29647
+ insertFactStatements = new WeakMap;
29648
+ });
29457
29649
  // ../plugin/src/shared/sqlite-helpers.ts
29458
29650
  function closeQuietly(db) {
29459
29651
  if (!db)
@@ -162516,6 +162708,22 @@ var init_migrations = __esm(async () => {
162516
162708
  db.exec("ALTER TABLE session_meta ADD COLUMN pending_pi_compaction_marker_state TEXT");
162517
162709
  }
162518
162710
  }
162711
+ },
162712
+ {
162713
+ version: 19,
162714
+ description: "Add compartment state lease table",
162715
+ up: (db) => {
162716
+ db.exec(`
162717
+ CREATE TABLE IF NOT EXISTS compartment_state_lease (
162718
+ session_id TEXT PRIMARY KEY NOT NULL,
162719
+ holder_id TEXT NOT NULL,
162720
+ acquired_at INTEGER NOT NULL,
162721
+ expires_at INTEGER NOT NULL
162722
+ );
162723
+ CREATE INDEX IF NOT EXISTS idx_compartment_state_lease_expires
162724
+ ON compartment_state_lease(expires_at);
162725
+ `);
162726
+ }
162519
162727
  }
162520
162728
  ];
162521
162729
  });
@@ -162888,6 +163096,15 @@ function initializeDatabase(db) {
162888
163096
  );
162889
163097
  CREATE INDEX IF NOT EXISTS idx_compartments_session ON compartments(session_id);
162890
163098
 
163099
+ CREATE TABLE IF NOT EXISTS compartment_state_lease (
163100
+ session_id TEXT PRIMARY KEY NOT NULL,
163101
+ holder_id TEXT NOT NULL,
163102
+ acquired_at INTEGER NOT NULL,
163103
+ expires_at INTEGER NOT NULL
163104
+ );
163105
+ CREATE INDEX IF NOT EXISTS idx_compartment_state_lease_expires
163106
+ ON compartment_state_lease(expires_at);
163107
+
162891
163108
  CREATE TABLE IF NOT EXISTS compression_depth (
162892
163109
  session_id TEXT NOT NULL,
162893
163110
  message_ordinal INTEGER NOT NULL,
@@ -163512,9 +163729,11 @@ function mergeRawConfigs(base, override) {
163512
163729
  return merged;
163513
163730
  }
163514
163731
  function parsePiConfig(rawConfig, recoveredTopLevelKeys = []) {
163515
- const parsed = MagicContextConfigSchema.safeParse(rawConfig);
163732
+ const preMigrationWarnings = [];
163733
+ const migrated = migrateLegacyAgentEnabledInMemory(rawConfig, preMigrationWarnings);
163734
+ const parsed = MagicContextConfigSchema.safeParse(migrated);
163516
163735
  if (parsed.success) {
163517
- return { config: parsed.data, warnings: [] };
163736
+ return { config: parsed.data, warnings: preMigrationWarnings };
163518
163737
  }
163519
163738
  const defaults = MagicContextConfigSchema.parse({});
163520
163739
  const errorPaths = new Set;
@@ -163524,8 +163743,8 @@ function parsePiConfig(rawConfig, recoveredTopLevelKeys = []) {
163524
163743
  errorPaths.add(String(topKey));
163525
163744
  }
163526
163745
  }
163527
- const patched = { ...rawConfig };
163528
- const warnings = [];
163746
+ const patched = { ...migrated };
163747
+ const warnings = [...preMigrationWarnings];
163529
163748
  for (const key of errorPaths) {
163530
163749
  recoveredTopLevelKeys.push(key);
163531
163750
  const isAgentConfig = key === "historian" || key === "dreamer" || key === "sidekick";
@@ -164008,7 +164227,10 @@ async function bundleIssueReport2(report, description, title, options = {}) {
164008
164227
  const logLines = filterLogLinesBySession2(allLogLines, options.sessionFilter ?? null);
164009
164228
  const recentLog = sanitizeLogContent2(logLines.slice(-LOG_TAIL_LINES).join(`
164010
164229
  `)).trim();
164011
- const bodyMarkdown = [
164230
+ const errorScanWindow = sanitizeLogContent2(logLines.slice(-4000).join(`
164231
+ `));
164232
+ const recentErrorLines = extractRecentErrors(errorScanWindow, 20);
164233
+ const rawBodyMarkdown = [
164012
164234
  "## Title",
164013
164235
  `[pi] ${sanitizeString2(title)}`,
164014
164236
  "",
@@ -164023,6 +164245,11 @@ async function bundleIssueReport2(report, description, title, options = {}) {
164023
164245
  "",
164024
164246
  "## Diagnostics",
164025
164247
  renderDiagnosticsMarkdown2(report),
164248
+ "",
164249
+ "## Recent errors (last 20, sanitized)",
164250
+ recentErrorLines.length === 0 ? "_No error-shaped log lines found in recent history._" : ["```", recentErrorLines.join(`
164251
+ `), "```"].join(`
164252
+ `),
164026
164253
  "",
164027
164254
  `## Log (last ${LOG_TAIL_LINES} lines, sanitized)`,
164028
164255
  "```",
@@ -164030,6 +164257,7 @@ async function bundleIssueReport2(report, description, title, options = {}) {
164030
164257
  "```"
164031
164258
  ].join(`
164032
164259
  `);
164260
+ const bodyMarkdown = capBodyToGithubLimit(rawBodyMarkdown);
164033
164261
  const cwd = options.cwd ?? process.cwd();
164034
164262
  const path4 = join21(cwd, `magic-context-pi-issue-${formatTimestamp2(options.now ?? new Date)}.md`);
164035
164263
  writeFileSync11(path4, `${bodyMarkdown}
@@ -164038,6 +164266,7 @@ async function bundleIssueReport2(report, description, title, options = {}) {
164038
164266
  }
164039
164267
  var init_logs_pi = __esm(() => {
164040
164268
  init_diagnostics_pi();
164269
+ init_issue_body();
164041
164270
  });
164042
164271
 
164043
164272
  // src/commands/doctor-pi.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cortexkit/magic-context",
3
- "version": "0.21.5",
3
+ "version": "0.21.7",
4
4
  "description": "Unified CLI for Magic Context — setup, doctor, and migration across OpenCode and Pi",
5
5
  "keywords": [
6
6
  "opencode",