@cortexkit/opencode-magic-context 0.49.70 → 0.49.72

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 (76) hide show
  1. package/dist/auto-search-worker.js +3 -3
  2. package/dist/chunk-embedding-write-worker.js +1 -1
  3. package/dist/{context-rcts8w54.js → context-830ksymq.js} +18 -18
  4. package/dist/{embedding-backfill-sk7agn5v.js → embedding-backfill-exnyad7d.js} +2 -2
  5. package/dist/features/magic-context/dreamer/docs-proposals.d.ts +10 -2
  6. package/dist/features/magic-context/dreamer/docs-proposals.d.ts.map +1 -1
  7. package/dist/features/magic-context/memory/embedding-backfill.d.ts.map +1 -1
  8. package/dist/features/magic-context/overflow-detection.d.ts +2 -2
  9. package/dist/features/magic-context/project-embedding-registry.d.ts +1 -0
  10. package/dist/features/magic-context/project-embedding-registry.d.ts.map +1 -1
  11. package/dist/hooks/magic-context/sentinel.d.ts.map +1 -1
  12. package/dist/{index-0dbc9rxd.js → index-2m1j98fj.js} +3 -3
  13. package/dist/{index-fcrp1k8s.js → index-3mx8math.js} +1 -1
  14. package/dist/{index-d0mb17q4.js → index-64qpnmjb.js} +2 -2
  15. package/dist/{index-gq1g9a3a.js → index-9swgykdd.js} +4 -3
  16. package/dist/{index-mxjdj2cz.js → index-bdnak4d0.js} +17 -3
  17. package/dist/{index-y664y8kq.js → index-cw3j0pwy.js} +1 -1
  18. package/dist/{index-5hc4kjg0.js → index-etm62gd7.js} +1 -1
  19. package/dist/{index-51anehwt.js → index-jeckjrh0.js} +13 -13
  20. package/dist/{index-cdyhpdqx.js → index-q5rcetym.js} +4 -4
  21. package/dist/index-q9ywd8b2.js +65 -0
  22. package/dist/{index-gvnt9yka.js → index-sc5segqg.js} +7 -7
  23. package/dist/{index-n6aye6ny.js → index-ve863q40.js} +98 -2
  24. package/dist/{index-mejvnav7.js → index-w8sv1v0j.js} +10 -10
  25. package/dist/{index-mey1nc1v.js → index-xha0yxhy.js} +1 -1
  26. package/dist/{index-rzxzap49.js → index-y6q5qvdz.js} +5 -5
  27. package/dist/{index-95475ngp.js → index-yh7hxjxm.js} +191 -121
  28. package/dist/{index-fm0bpxc6.js → index-yhz1w3ss.js} +1 -1
  29. package/dist/{index-n19pqsnh.js → index-zt6d9fag.js} +2 -2
  30. package/dist/index.js +21 -21
  31. package/dist/{message-index-bounded-n2j33x8n.js → message-index-bounded-vf70t44t.js} +3 -3
  32. package/dist/migration-worker.js +1 -1
  33. package/dist/{project-embedding-registry-c2sfnamh.js → project-embedding-registry-n50fbax6.js} +1 -1
  34. package/dist/raw-ordinal-warmup-worker.js +4 -4
  35. package/dist/{read-session-chunk-6kdtfa7k.js → read-session-chunk-9jtq1swq.js} +2 -2
  36. package/dist/{recomp-orchestrator-t9670x13.js → recomp-orchestrator-sa4f2mkj.js} +10 -10
  37. package/dist/{render-re3akx9j.js → render-qkjgrg31.js} +6 -6
  38. package/dist/{search-rppmngr5.js → search-0v2v9yd5.js} +8 -8
  39. package/dist/{search-archive-0q8rdnrd.js → search-archive-cmfs3myg.js} +4 -4
  40. package/dist/{storage-tags-rptkad9p.js → storage-tags-d3nqrva7.js} +1 -1
  41. package/dist/{transform-postprocess-phase-qtd2wr52.js → transform-postprocess-phase-ecrcsc2w.js} +11 -11
  42. package/dist/v2/auto-search-worker.js +3 -3
  43. package/dist/v2/chunk-embedding-write-worker.js +1 -1
  44. package/dist/v2/{context-wv122q62.js → context-q846asea.js} +188 -117
  45. package/dist/v2/{embedding-backfill-j2xj86zn.js → embedding-backfill-jhmn81cz.js} +2 -2
  46. package/dist/v2/{message-index-bounded-hfnsznj0.js → message-index-bounded-ev9sarf6.js} +3 -3
  47. package/dist/v2/migration-worker.js +1 -1
  48. package/dist/v2/{project-embedding-registry-k0hjqt11.js → project-embedding-registry-07nz4qas.js} +1 -1
  49. package/dist/v2/raw-ordinal-warmup-worker.js +4 -4
  50. package/dist/v2/{read-session-chunk-qzd376gb.js → read-session-chunk-eb49qfzz.js} +2 -2
  51. package/dist/v2/{recomp-orchestrator-rrsbcsmc.js → recomp-orchestrator-egbf57qa.js} +9 -9
  52. package/dist/v2/{render-qwy9ydnb.js → render-47vjswds.js} +6 -6
  53. package/dist/v2/{search-q3xcyyq8.js → search-03pzsd5w.js} +7 -7
  54. package/dist/v2/{search-archive-gewpafej.js → search-archive-3tpaqkg4.js} +4 -4
  55. package/dist/v2/{server-ssdfdrpv.js → server-3jggqcpa.js} +12 -12
  56. package/dist/v2/{server-xxy28mq5.js → server-4nh02tdw.js} +2 -2
  57. package/dist/v2/{server-fczyr89c.js → server-ar3awhcy.js} +11 -11
  58. package/dist/v2/{server-vzrj39bj.js → server-canf6f29.js} +1 -1
  59. package/dist/v2/{server-vqkqv7ze.js → server-cxkb9725.js} +17 -3
  60. package/dist/v2/{server-07z334y6.js → server-d0ec5f7b.js} +1 -1
  61. package/dist/v2/{server-axmk8rr2.js → server-k8mj4ccb.js} +1 -1
  62. package/dist/v2/{server-d07yxksx.js → server-ndkzagjz.js} +98 -2
  63. package/dist/v2/server-rd7v8c8y.js +65 -0
  64. package/dist/v2/{server-nc4qrjde.js → server-rpdbmk63.js} +1 -1
  65. package/dist/v2/{server-0c7egkzr.js → server-sk08dem3.js} +2 -2
  66. package/dist/v2/{server-z5255w05.js → server-t091cjj4.js} +4 -3
  67. package/dist/v2/{server-h8y2948e.js → server-wb00e7b0.js} +3 -3
  68. package/dist/v2/server.js +2 -2
  69. package/dist/v2/{storage-tags-msa1qvk8.js → storage-tags-j4he6hwe.js} +1 -1
  70. package/dist/v2/{v2-archive-reader-nwaw9qph.js → v2-archive-reader-x1yvzqs8.js} +1 -1
  71. package/dist/v2/{wrapup-orchestrator-xyd3r2t1.js → wrapup-orchestrator-5bccsgy0.js} +9 -9
  72. package/dist/{v2-archive-reader-dv00gb2a.js → v2-archive-reader-xnnwexnw.js} +1 -1
  73. package/dist/{wrapup-orchestrator-fzygp85w.js → wrapup-orchestrator-yrpqmwc7.js} +11 -11
  74. package/package.json +1 -1
  75. package/dist/index-zxj39ba2.js +0 -155
  76. package/dist/v2/server-d9aayyxk.js +0 -155
@@ -196,7 +196,7 @@ import {
196
196
  snapRangeToCompartments,
197
197
  getActiveCompartmentRun,
198
198
  startCompartmentAgent
199
- } from "./index-gvnt9yka.js";
199
+ } from "./index-sc5segqg.js";
200
200
  import {
201
201
  hasTrustedAbsoluteWall,
202
202
  applyProvenInputFloor,
@@ -355,7 +355,7 @@ import {
355
355
  getTagsByNumbers2,
356
356
  getDroppedTagsByNumbers2,
357
357
  getMaxDroppedTagNumber2
358
- } from "./index-mxjdj2cz.js";
358
+ } from "./index-bdnak4d0.js";
359
359
  import {
360
360
  BoundedSessionMap,
361
361
  observeTemporalDecisions,
@@ -427,7 +427,7 @@ import {
427
427
  readRawSessionMessageById2,
428
428
  readSessionChunk2,
429
429
  readRawSessionSeedTail2
430
- } from "./index-fm0bpxc6.js";
430
+ } from "./index-yhz1w3ss.js";
431
431
  import {
432
432
  isFailClosedBlockingError,
433
433
  shouldBypassFailClosedBlock,
@@ -453,7 +453,7 @@ import {
453
453
  runSqliteOptimize,
454
454
  openDatabase,
455
455
  openCurrentDatabase
456
- } from "./index-fcrp1k8s.js";
456
+ } from "./index-3mx8math.js";
457
457
  import {
458
458
  unescapeXml,
459
459
  resolveWorkspaceShareCategories,
@@ -569,10 +569,10 @@ import {
569
569
  GLOBAL_USER_PROFILE_PROJECT_PATH,
570
570
  getProjectState,
571
571
  bumpProjectUserProfileVersion
572
- } from "./index-y664y8kq.js";
572
+ } from "./index-cw3j0pwy.js";
573
573
  import {
574
574
  getLastIndexedOrdinal
575
- } from "./index-5hc4kjg0.js";
575
+ } from "./index-etm62gd7.js";
576
576
  import {
577
577
  SESSION_NOTE_CONDITION_ERROR,
578
578
  getNoteByIdInScope,
@@ -631,15 +631,33 @@ import {
631
631
  embedSessionCompartmentChunks2,
632
632
  getEmbeddingCoverageStatus2,
633
633
  getAutoEmbeddingSessionCoverage2
634
- } from "./index-gq1g9a3a.js";
634
+ } from "./index-9swgykdd.js";
635
635
  import {
636
636
  saveEmbeddingIfHashMatches,
637
637
  invalidateProject2,
638
638
  invalidateMemory2
639
639
  } from "./index-4dhv7mqz.js";
640
640
  import {
641
- cosineSimilarity
642
- } from "./index-zxj39ba2.js";
641
+ renderUserFacingFailure,
642
+ userFacingFailureCode,
643
+ renderCapabilityRefusal,
644
+ capabilityRefusalCode,
645
+ renderDreamFailure,
646
+ dreamFailureCode,
647
+ renderEmbeddingFailure,
648
+ cosineSimilarity,
649
+ recordMemoryMapping,
650
+ recordMemoryVerifications,
651
+ getUnmappedMemoryIds,
652
+ clearMemoryVerifications,
653
+ getMemoryVerifications,
654
+ resolveGitTopLevel,
655
+ readGitHead,
656
+ readGitChangedFilesSince,
657
+ readGitFileChangeTimesSince,
658
+ verificationFileExists,
659
+ normalizeVerificationFiles
660
+ } from "./index-ve863q40.js";
643
661
  import {
644
662
  computeCueContentHash,
645
663
  hasMuralCueColumns,
@@ -666,26 +684,6 @@ import {
666
684
  archiveMemory2,
667
685
  getMemoryCountsByStatus2
668
686
  } from "./index-jjvbk92s.js";
669
- import {
670
- renderUserFacingFailure,
671
- userFacingFailureCode,
672
- renderCapabilityRefusal,
673
- capabilityRefusalCode,
674
- renderDreamFailure,
675
- dreamFailureCode,
676
- renderEmbeddingFailure,
677
- recordMemoryMapping,
678
- recordMemoryVerifications,
679
- getUnmappedMemoryIds,
680
- clearMemoryVerifications,
681
- getMemoryVerifications,
682
- resolveGitTopLevel,
683
- readGitHead,
684
- readGitChangedFilesSince,
685
- readGitFileChangeTimesSince,
686
- verificationFileExists,
687
- normalizeVerificationFiles
688
- } from "./index-n6aye6ny.js";
689
687
  import {
690
688
  renderSingleStoreMigrationRequiredRefusal,
691
689
  SingleStoreMigrationRequiredError,
@@ -706,13 +704,13 @@ import {
706
704
  resolveMemoriesByIdsForSearch2,
707
705
  unifiedSearch2,
708
706
  formatSearchResults2
709
- } from "./index-51anehwt.js";
707
+ } from "./index-jeckjrh0.js";
710
708
  import {
711
709
  scheduleReconciliation,
712
710
  scheduleIncrementalIndex,
713
711
  getMessageIndexQueueHeapStats,
714
712
  clearSessionTracking
715
- } from "./index-mey1nc1v.js";
713
+ } from "./index-xha0yxhy.js";
716
714
  import {
717
715
  flushIgnoredMessages2,
718
716
  clearIgnoredMessages2,
@@ -722,7 +720,7 @@ import {
722
720
  import {
723
721
  setRecompStarting2,
724
722
  setRecompTerminal2
725
- } from "./index-cdyhpdqx.js";
723
+ } from "./index-q5rcetym.js";
726
724
  import {
727
725
  makeToolCompositeKey,
728
726
  searchMessageHistoryOffThread,
@@ -807,7 +805,7 @@ import {
807
805
  abortSessionFailClosed2,
808
806
  evaluateEmergencyFailClosed2,
809
807
  runPostTransformPhase2
810
- } from "./index-mejvnav7.js";
808
+ } from "./index-w8sv1v0j.js";
811
809
  import {
812
810
  ANNOUNCEMENT_VERSION2,
813
811
  ANNOUNCEMENT_FEATURES2,
@@ -822,13 +820,13 @@ import {
822
820
  renderMessageByOrdinal2,
823
821
  renderVerboseRangeForTool2,
824
822
  renderItemByTag2
825
- } from "./index-n19pqsnh.js";
823
+ } from "./index-zt6d9fag.js";
826
824
  import {
827
825
  readV2ArchiveOffThread2
828
- } from "./index-0dbc9rxd.js";
826
+ } from "./index-2m1j98fj.js";
829
827
  import {
830
828
  renderSearchArchiveOffThread2
831
- } from "./index-d0mb17q4.js";
829
+ } from "./index-64qpnmjb.js";
832
830
  import {
833
831
  COMPACTION_ENABLED_PATH,
834
832
  isDreamerRunnable,
@@ -1120,7 +1118,7 @@ ${currentDocs?.structure ?? "(read from project)"}
1120
1118
 
1121
1119
  Find claims in these sections that the diff makes wrong or incomplete. Propose one focused change per claim or section. Do not investigate unrelated areas. Read the docs and relevant source with read-only tools. These files are short maps read by every agent in every session. Describe how the system works now, never what changed or when: no change log, dates, or commit lists. One short paragraph per subsystem at most. Mechanism detail belongs in docs/architecture/; you may name a docs page for it but never move that detail into these two files. Propose a change only when code contradicts the docs or a major piece is missing. Prefer rewriting a stale sentence to adding one. Propose nothing when nothing is wrong. Keep both files within the combined budget. Never touch protected regions (<!-- mc:protected START ... --> through <!-- mc:protected END -->); preserve their bytes.
1122
1120
 
1123
- Return ONLY a JSON array (or []), with each entry {"file":"ARCHITECTURE.md"|"STRUCTURE.md","action":"replace"|"add"|"remove","heading":"## Exact section heading","text":"## Full replacement section including heading and body (empty for remove)","reason":"one-line reason"}. A replacement includes the entire section, including its heading. Additions are appended at the end of the file. Do not include any unmodified sections. No file writes.`;
1121
+ Return ONLY a JSON array (or []), with each entry {"file":"ARCHITECTURE.md"|"STRUCTURE.md","action":"replace"|"add"|"remove","heading":"## Exact section heading","text":"## Full section including heading and body (empty for remove)","reason":"one-line reason"}. A section is its heading and everything under it until the next heading of the same or a higher level outside code fences, or the end of the file. Replace, add, or remove exactly one whole section per entry, including its subsections. Additions are appended at the end of the file. Do not include entries for unmodified sections. No file writes.`;
1124
1122
  }
1125
1123
  function buildDreamTaskPrompt(task, args) {
1126
1124
  switch (task) {
@@ -4302,23 +4300,35 @@ ${stat}`
4302
4300
  return null;
4303
4301
  }
4304
4302
  }
4305
- function sections(text) {
4306
- const lines = text.split(`
4307
- `);
4303
+ var ATX_HEADING = /^ {0,3}(#{1,6})(?=[ \t]|$)/;
4304
+ function sections(lines) {
4308
4305
  const result = [];
4309
- let fenced = false;
4306
+ const open = [];
4307
+ let fence;
4310
4308
  for (let i = 0;i < lines.length; i++) {
4311
- if (/^\s*(```|~~~)/.test(lines[i]))
4312
- fenced = !fenced;
4313
- if (!fenced && /^#{1,6} \S/.test(lines[i])) {
4314
- if (result.length)
4315
- result[result.length - 1].end = i;
4316
- result.push({ heading: lines[i], text: "", start: i, end: lines.length });
4309
+ const heading = lines[i].replace(/\r$/, "");
4310
+ const marker = heading.match(/^ {0,3}(`{3,}|~{3,})(.*)$/);
4311
+ if (fence) {
4312
+ if (marker?.[1].startsWith(fence) && !marker[2].trim())
4313
+ fence = undefined;
4314
+ continue;
4315
+ }
4316
+ if (marker && (marker[1][0] === "~" || !marker[2].includes("`"))) {
4317
+ fence = marker[1];
4318
+ continue;
4317
4319
  }
4320
+ const match = heading.match(ATX_HEADING);
4321
+ if (!match)
4322
+ continue;
4323
+ const level = match[1].length;
4324
+ for (let previous = open.at(-1);previous && previous.level >= level; previous = open.at(-1)) {
4325
+ previous.end = i;
4326
+ open.pop();
4327
+ }
4328
+ const section = { heading, level, start: i, end: lines.length };
4329
+ result.push(section);
4330
+ open.push(section);
4318
4331
  }
4319
- for (const section of result)
4320
- section.text = lines.slice(section.start, section.end).join(`
4321
- `);
4322
4332
  return result;
4323
4333
  }
4324
4334
  function protectedBytes(text) {
@@ -4341,76 +4351,142 @@ function diff(name, before, after) {
4341
4351
  }
4342
4352
  }
4343
4353
  function parseDocsProposalOutput(output) {
4344
- const match = output.match(/```json\s*([\s\S]*?)```/);
4345
- const parsed = JSON.parse(match?.[1] ?? output);
4354
+ let parsed;
4355
+ try {
4356
+ parsed = JSON.parse(output);
4357
+ } catch (error) {
4358
+ const match = output.match(/```json[ \t]*\r?\n([\s\S]*?)\r?\n[ \t]*```(?=\s|$)/) ?? output.match(/```json\s*([\s\S]*?)```/);
4359
+ if (!match)
4360
+ throw error;
4361
+ parsed = JSON.parse(match[1]);
4362
+ }
4346
4363
  if (!Array.isArray(parsed))
4347
4364
  throw new Error("proposal must be a JSON array");
4348
- const changes = parsed;
4349
- if (changes.some((item) => !item || !FILES.includes(item.file)))
4350
- throw new Error("unknown proposal file");
4365
+ return parsed;
4366
+ }
4367
+ function readChange(item) {
4368
+ if (!item || typeof item !== "object" || Array.isArray(item))
4369
+ return "expected an object";
4370
+ const { file, action, heading, text, reason } = item;
4371
+ if (file !== "ARCHITECTURE.md" && file !== "STRUCTURE.md")
4372
+ return "unknown proposal file";
4373
+ if (action !== "replace" && action !== "add" && action !== "remove")
4374
+ return "invalid action";
4375
+ if (typeof heading !== "string" || /[\r\n]/.test(heading) || !ATX_HEADING.test(heading))
4376
+ return "invalid section heading";
4377
+ if (typeof text !== "string")
4378
+ return "section text must be a string";
4379
+ if (typeof reason !== "string" || !reason.trim() || /[\r\n]/.test(reason))
4380
+ return "expected a one-line reason";
4381
+ return { file, action, heading, text, reason };
4382
+ }
4383
+ function applyChange(before, change) {
4384
+ const lines = before.split(`
4385
+ `);
4386
+ const existing = sections(lines);
4387
+ const index = existing.findIndex((item) => item.heading === change.heading);
4388
+ const replacement = change.action === "remove" ? [] : change.text.trimEnd().split(`
4389
+ `);
4390
+ const inserted = sections(replacement);
4391
+ const wholeSection = inserted[0]?.heading === change.heading && inserted[0].start === 0 && inserted[0].end === replacement.length;
4392
+ const expectedHeadings = existing.map((item) => item.heading);
4393
+ const insertedHeadings = inserted.map((item) => item.heading);
4394
+ let after;
4395
+ if (change.action === "add") {
4396
+ if (index !== -1 || !wholeSection)
4397
+ return `invalid addition ${change.heading}`;
4398
+ after = `${before.endsWith(`
4399
+ `) ? before : `${before}
4400
+ `}
4401
+ ${replacement.join(`
4402
+ `)}
4403
+ `;
4404
+ expectedHeadings.push(...insertedHeadings);
4405
+ } else {
4406
+ if (index === -1)
4407
+ return `missing section ${change.heading}`;
4408
+ if (change.action === "replace" && !wholeSection)
4409
+ return `invalid replacement ${change.heading}`;
4410
+ const section = existing[index];
4411
+ const affected = existing.filter((item) => item.start >= section.start && item.start < section.end);
4412
+ expectedHeadings.splice(index, affected.length, ...insertedHeadings);
4413
+ if (change.action === "replace" && section.end === lines.length && before.endsWith(`
4414
+ `))
4415
+ replacement.push("");
4416
+ lines.splice(section.start, section.end - section.start, ...replacement);
4417
+ after = lines.join(`
4418
+ `);
4419
+ }
4420
+ if (JSON.stringify(protectedBytes(before)) !== JSON.stringify(protectedBytes(after)))
4421
+ return `protected region changed in ${change.file}`;
4422
+ if (JSON.stringify(sections(after.split(`
4423
+ `)).map((item) => item.heading)) !== JSON.stringify(expectedHeadings))
4424
+ return `markdown structure changed in ${change.file}`;
4425
+ if (after === before)
4426
+ return "no doc changes proposed";
4427
+ return { after };
4428
+ }
4429
+ function applyChanges(items, originals, overBudget) {
4430
+ const docs = { ...originals };
4431
+ const kept = [];
4432
+ const dropped = [];
4351
4433
  const seen = new Set;
4352
- for (const change of changes) {
4434
+ for (const [index, item] of items.entries()) {
4435
+ const change = overBudget.get(index) ?? readChange(item);
4436
+ if (typeof change === "string") {
4437
+ dropped.push({ index, reason: change });
4438
+ continue;
4439
+ }
4353
4440
  const key = `${change.file}:${change.heading}`;
4354
- if (!["replace", "add", "remove"].includes(change.action) || typeof change.heading !== "string" || !/^#{1,6} [^\r\n]+$/.test(change.heading) || typeof change.text !== "string" || typeof change.reason !== "string" || !change.reason.trim() || /[\r\n]/.test(change.reason) || seen.has(key))
4355
- throw new Error(`invalid section change in ${change.file}`);
4441
+ const before = docs[change.file];
4442
+ const result = seen.has(key) ? `duplicate section change ${change.heading}` : applyChange(before, change);
4443
+ if (typeof result === "string") {
4444
+ dropped.push({ index, reason: result });
4445
+ continue;
4446
+ }
4447
+ kept.push({ index, change, grew: result.after.length > before.length });
4448
+ docs[change.file] = result.after;
4356
4449
  seen.add(key);
4357
4450
  }
4358
- return changes;
4451
+ const tokens = FILES.reduce((sum, file) => sum + Math.ceil(docs[file].length / 3.5), 0);
4452
+ return { docs, kept, dropped, tokens };
4359
4453
  }
4360
4454
  function validateDocsProposal(projectDir, output, budget, expected) {
4361
- if (Object.entries(expected).some(([name, value]) => docsBaseHashes(projectDir)[name] !== value))
4455
+ const readDoc = (file) => {
4456
+ const path = join(projectDir, file);
4457
+ return existsSync2(path) ? readFileSync(path, "utf8") : "";
4458
+ };
4459
+ const originals = {
4460
+ "ARCHITECTURE.md": readDoc("ARCHITECTURE.md"),
4461
+ "STRUCTURE.md": readDoc("STRUCTURE.md")
4462
+ };
4463
+ if (Object.keys(expected).some((name) => !FILES.some((file) => file === name && hash(originals[file]) === expected[name])))
4362
4464
  throw new Error("base drifted");
4363
- const changes = parseDocsProposalOutput(output);
4364
- if (!changes.length)
4365
- throw new Error("empty proposal");
4366
- let tokens = 0;
4367
- let diffs = "";
4368
- for (const file of FILES) {
4369
- const before = existsSync2(join(projectDir, file)) ? readFileSync(join(projectDir, file), "utf8") : "";
4370
- let after = before;
4371
- for (const change of changes.filter((item) => item.file === file)) {
4372
- const section = sections(after).find((item) => item.heading === change.heading);
4373
- if (change.action === "add") {
4374
- if (section || !change.text.startsWith(`${change.heading}
4375
- `))
4376
- throw new Error(`invalid addition ${change.heading}`);
4377
- after += `${after.endsWith(`
4378
- `) ? "" : `
4379
- `}
4380
- ${change.text.trimEnd()}
4381
- `;
4382
- } else {
4383
- if (!section)
4384
- throw new Error(`missing section ${change.heading}`);
4385
- if (change.action === "replace" && (!change.text.startsWith(`${change.heading}
4386
- `) || sections(change.text).length !== 1))
4387
- throw new Error(`invalid replacement ${change.heading}`);
4388
- const lines = after.split(`
4389
- `);
4390
- lines.splice(section.start, section.end - section.start, ...change.action === "remove" ? [] : change.text.trimEnd().split(`
4391
- `));
4392
- after = lines.join(`
4393
- `);
4394
- }
4395
- }
4396
- if (JSON.stringify(protectedBytes(before)) !== JSON.stringify(protectedBytes(after)))
4397
- throw new Error(`protected region changed in ${file}`);
4398
- const originalHeadings = sections(before).map((item) => item.heading);
4399
- const expectedHeadings = originalHeadings.filter((heading) => !changes.some((item) => item.file === file && item.action === "remove" && item.heading === heading)).concat(changes.filter((item) => item.file === file && item.action === "add").map((item) => item.heading));
4400
- if (JSON.stringify(sections(after).map((item) => item.heading)) !== JSON.stringify(expectedHeadings))
4401
- throw new Error(`markdown structure changed in ${file}`);
4402
- tokens += Math.ceil(after.length / 3.5);
4403
- if (after !== before)
4404
- diffs += diff(file, before, after);
4465
+ const items = parseDocsProposalOutput(output);
4466
+ const overBudget = new Map;
4467
+ let result = applyChanges(items, originals, overBudget);
4468
+ while (result.tokens > budget && result.kept.length) {
4469
+ const reason = `over budget: ${result.tokens} > ${budget}`;
4470
+ const latestGrowth = [...result.kept].reverse().find((item) => item.grew);
4471
+ if (latestGrowth)
4472
+ overBudget.set(latestGrowth.index, reason);
4473
+ else
4474
+ for (const item of result.kept)
4475
+ overBudget.set(item.index, reason);
4476
+ result = applyChanges(items, originals, overBudget);
4405
4477
  }
4406
- if (tokens > budget)
4407
- throw new Error(`over budget: ${tokens} > ${budget}`);
4408
- if (!diffs)
4409
- throw new Error("no doc changes proposed");
4410
- return { changes, tokens, diffs };
4478
+ const diffs = FILES.filter((file) => originals[file] !== result.docs[file]).map((file) => diff(file, originals[file], result.docs[file])).join("");
4479
+ return {
4480
+ changes: result.kept.map((item) => item.change),
4481
+ dropped: result.dropped,
4482
+ tokens: result.tokens,
4483
+ diffs
4484
+ };
4411
4485
  }
4412
4486
  function writeDocsProposal(projectDir, output, budget, expected, head) {
4413
4487
  const result = validateDocsProposal(projectDir, output, budget, expected);
4488
+ if (!result.diffs)
4489
+ return { path: null, dropped: result.dropped };
4414
4490
  const dir = proposalDir(projectDir);
4415
4491
  mkdirSync(join(dir, "superseded"), { recursive: true });
4416
4492
  ensureCortexKitArtifactGitignore(projectDir);
@@ -4444,7 +4520,7 @@ ${result.diffs}
4444
4520
  for (const old of listPendingDocsProposals(projectDir))
4445
4521
  if (old !== path)
4446
4522
  renameSync(old, join(dir, "superseded", old.split("/").at(-1) ?? "proposal.md"));
4447
- return path;
4523
+ return { path, dropped: result.dropped };
4448
4524
  }
4449
4525
 
4450
4526
  // src/agents/smart-note-compiler.ts
@@ -11253,19 +11329,13 @@ async function runAgenticTask(config, ctx, helpers) {
11253
11329
  recordInvocation("completed", run.output);
11254
11330
  if (task === "maintain-docs" && docsHashes && changes) {
11255
11331
  try {
11256
- if (parseDocsProposalOutput(String(run.validated)).length === 0) {
11257
- helpers.recordRun("completed", null, { progress: "no corrections proposed" });
11258
- return {
11259
- status: "completed",
11260
- detail: "no corrections proposed",
11261
- schedulePatch: { taskStateJson: JSON.stringify({ head: changes.head }) }
11262
- };
11263
- }
11264
- const path = writeDocsProposal(docsDir, String(run.validated), config.docsMaxTokens ?? 12000, docsHashes, changes.head);
11265
- helpers.recordRun("completed", null, { progress: `proposal: ${path}` });
11332
+ const { path, dropped } = writeDocsProposal(docsDir, String(run.validated), config.docsMaxTokens ?? 12000, docsHashes, changes.head);
11333
+ const outcome = path ? `proposal: ${path}` : "no corrections proposed";
11334
+ const detail = dropped.length ? `${outcome}; dropped ${dropped.map(({ index, reason }) => `entry ${index + 1}: ${reason}`).join("; ")}` : outcome;
11335
+ helpers.recordRun("completed", null, { progress: detail });
11266
11336
  return {
11267
11337
  status: "completed",
11268
- detail: `proposal: ${path}`,
11338
+ detail,
11269
11339
  schedulePatch: { taskStateJson: JSON.stringify({ head: changes.head }) }
11270
11340
  };
11271
11341
  } catch (error) {
@@ -16468,7 +16538,7 @@ function registerRpcHandlers(rpcServer, args) {
16468
16538
  const db = readDatabase();
16469
16539
  if (!db)
16470
16540
  return { ok: false, error: "db unavailable" };
16471
- const { runManagedRecomp } = await importPluginModule(() => import("./recomp-orchestrator-t9670x13.js"));
16541
+ const { runManagedRecomp } = await importPluginModule(() => import("./recomp-orchestrator-sa4f2mkj.js"));
16472
16542
  const { sendIgnoredMessage } = await importPluginModule(() => import("./send-session-notification-ykvt5k2s.js"));
16473
16543
  log2(`[rpc] recomp requested for session ${sessionId}`);
16474
16544
  if (!args.client && !args.hiddenCompletionExecutor) {
@@ -16553,7 +16623,7 @@ function registerRpcHandlers(rpcServer, args) {
16553
16623
  const db = readDatabase();
16554
16624
  if (!db)
16555
16625
  return { ok: false, error: "db unavailable" };
16556
- const { runManagedWrapup } = await importPluginModule(() => import("./wrapup-orchestrator-fzygp85w.js"));
16626
+ const { runManagedWrapup } = await importPluginModule(() => import("./wrapup-orchestrator-yrpqmwc7.js"));
16557
16627
  const model = liveSessionState.liveModelBySession.get(sessionId);
16558
16628
  const contextLimit = model ? resolveContextLimit(model.providerID, model.modelID, { db, sessionID: sessionId }) : 128000;
16559
16629
  const ctx = {
@@ -9,7 +9,7 @@ import {
9
9
  estimateMessageTokens,
10
10
  getCandidateToolOwners2,
11
11
  pickNearestPriorOwner2
12
- } from "./index-mxjdj2cz.js";
12
+ } from "./index-bdnak4d0.js";
13
13
  import {
14
14
  OMO_INTERNAL_INITIATOR_MARKER,
15
15
  isSystemDirective,
@@ -3,12 +3,12 @@ import {
3
3
  } from "./index-5vsk2cpp.js";
4
4
  import {
5
5
  getTagById2
6
- } from "./index-mxjdj2cz.js";
6
+ } from "./index-bdnak4d0.js";
7
7
  import {
8
8
  expandToolPart,
9
9
  visitRawSessionMessages2,
10
10
  readRawSessionMessageById2
11
- } from "./index-fm0bpxc6.js";
11
+ } from "./index-yhz1w3ss.js";
12
12
 
13
13
  // src/tools/ctx-expand/render.ts
14
14
  import { createHash } from "node:crypto";
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  recordToolParameters,
5
5
  createDroppedInputToolExecuteBeforeHook,
6
6
  readRawSessionMessages2
7
- } from "./index-fm0bpxc6.js";
7
+ } from "./index-yhz1w3ss.js";
8
8
  import {
9
9
  setHarness2
10
10
  } from "./index-pavzsdc6.js";
@@ -58,7 +58,7 @@ import {
58
58
  checkCompactionMarkerConsistency,
59
59
  clearInjectionCache,
60
60
  clearNoteNudgeTriggerOnly
61
- } from "./index-gvnt9yka.js";
61
+ } from "./index-sc5segqg.js";
62
62
  import"./index-sd3egckz.js";
63
63
  import {
64
64
  hasTrustedAbsoluteWall,
@@ -143,7 +143,7 @@ import {
143
143
  parameterDescriptionsFor,
144
144
  MagicContextRpcServer,
145
145
  applyHiddenSubagentTemperature
146
- } from "./index-95475ngp.js";
146
+ } from "./index-yh7hxjxm.js";
147
147
  import {
148
148
  resolveOpenCodeDbPath,
149
149
  openCodeDbPathExists,
@@ -195,7 +195,7 @@ import {
195
195
  dropServedRecord,
196
196
  registerLkgPersistence,
197
197
  dropSlot
198
- } from "./index-y664y8kq.js";
198
+ } from "./index-cw3j0pwy.js";
199
199
  import {
200
200
  recordSessionProjectIdentity
201
201
  } from "./index-jg7sbt3v.js";
@@ -210,7 +210,7 @@ import {
210
210
  openDatabaseAsync,
211
211
  isDatabasePersisted,
212
212
  getDatabasePersistenceError
213
- } from "./index-fcrp1k8s.js";
213
+ } from "./index-3mx8math.js";
214
214
  import {
215
215
  registerExitAbort,
216
216
  unregisterExitAbort
@@ -230,7 +230,7 @@ import"./index-pxnzyvjc.js";
230
230
  import {
231
231
  getDefaultSubcConnectionFile,
232
232
  SubcModuleTransport
233
- } from "./index-51anehwt.js";
233
+ } from "./index-jeckjrh0.js";
234
234
  import"./index-qt1qqasc.js";
235
235
  import"./index-e6ncz7a6.js";
236
236
  import {
@@ -280,7 +280,7 @@ import {
280
280
  isAnthropicFamilyRoute,
281
281
  deleteTagsByMessageId2,
282
282
  getMaxTagNumberBySession2
283
- } from "./index-mxjdj2cz.js";
283
+ } from "./index-bdnak4d0.js";
284
284
  import {
285
285
  resolveHistorianModel2,
286
286
  resolveOpenCodeAgentOverrides2,
@@ -293,7 +293,7 @@ import {
293
293
  import"./index-snbpdpa3.js";
294
294
  import {
295
295
  deleteIndexedMessage
296
- } from "./index-5hc4kjg0.js";
296
+ } from "./index-etm62gd7.js";
297
297
  import"./index-6athgjba.js";
298
298
  import"./index-tebcx987.js";
299
299
  import {
@@ -302,11 +302,11 @@ import {
302
302
  import"./index-zb4h9nrk.js";
303
303
  import {
304
304
  getEmbeddingCoverageStatus2
305
- } from "./index-gq1g9a3a.js";
305
+ } from "./index-9swgykdd.js";
306
306
  import"./index-4dhv7mqz.js";
307
- import"./index-zxj39ba2.js";
307
+ import"./index-ve863q40.js";
308
+ import"./index-q9ywd8b2.js";
308
309
  import"./index-jjvbk92s.js";
309
- import"./index-n6aye6ny.js";
310
310
  import"./index-832w615x.js";
311
311
  import {
312
312
  createTagger,
@@ -317,13 +317,13 @@ import {
317
317
  armBindingRecoverySafely,
318
318
  collectForeignTextParts,
319
319
  resetDegradedCacheCount2
320
- } from "./index-mejvnav7.js";
320
+ } from "./index-w8sv1v0j.js";
321
321
  import {
322
322
  scheduleClearAndReindex
323
- } from "./index-mey1nc1v.js";
323
+ } from "./index-xha0yxhy.js";
324
324
  import {
325
325
  runManagedRecomp2
326
- } from "./index-cdyhpdqx.js";
326
+ } from "./index-q5rcetym.js";
327
327
  import {
328
328
  isValidSemver,
329
329
  compareSemverCore
@@ -331,11 +331,11 @@ import {
331
331
  import"./index-fmsr7v69.js";
332
332
  import {
333
333
  runManagedWrapup2
334
- } from "./index-rzxzap49.js";
335
- import"./index-n19pqsnh.js";
334
+ } from "./index-y6q5qvdz.js";
335
+ import"./index-zt6d9fag.js";
336
336
  import"./index-52x68mj4.js";
337
- import"./index-0dbc9rxd.js";
338
- import"./index-d0mb17q4.js";
337
+ import"./index-2m1j98fj.js";
338
+ import"./index-64qpnmjb.js";
339
339
  import {
340
340
  isDreamerRunnable,
341
341
  isSmartNoteSurfaceAvailable,
@@ -8203,7 +8203,7 @@ var require_src2 = __commonJS(function(exports, module) {
8203
8203
  // package.json
8204
8204
  var package_default = {
8205
8205
  name: "@cortexkit/opencode-magic-context",
8206
- version: "0.49.70",
8206
+ version: "0.49.72",
8207
8207
  type: "module",
8208
8208
  description: "OpenCode plugin for Magic Context — cross-session memory and context management",
8209
8209
  main: "dist/index.js",
@@ -12082,7 +12082,7 @@ async function setup(context) {
12082
12082
  if (claimStorageBackupWarningCheck() && isMagicContextStorageOutsideEngram(storageDir)) {
12083
12083
  log2(`[magic-context] Magic Context storage is at ${storageDir}, outside the folder Engram backs up (~/.local/share/cortexkit/magic-context). It is not included in CortexKit backups.`);
12084
12084
  }
12085
- const { registerContext } = await import("./context-rcts8w54.js");
12085
+ const { registerContext } = await import("./context-830ksymq.js");
12086
12086
  setHarness2("opencode2");
12087
12087
  bindStaleBuildNotice({}, import.meta.url, "opencode2");
12088
12088
  const duties = await registerContext(context);
@@ -12555,7 +12555,7 @@ var server = async (ctx) => {
12555
12555
  rustReplayParticipant: () => magicContextRuntime.magicContext?.getRustReplayParticipant?.() ?? null,
12556
12556
  onStorageBusyRefusal: async (sessionId, message) => {
12557
12557
  const { sendStatusNotification } = await importPluginModule(() => import("./send-session-notification-ykvt5k2s.js"));
12558
- const { abortSessionFailClosed } = await importPluginModule(() => import("./transform-postprocess-phase-qtd2wr52.js"));
12558
+ const { abortSessionFailClosed } = await importPluginModule(() => import("./transform-postprocess-phase-ecrcsc2w.js"));
12559
12559
  await sendStatusNotification(ctx.client, sessionId, message, {
12560
12560
  toastDurationMs: 15000
12561
12561
  });
@@ -4,7 +4,7 @@ import {
4
4
  yieldIndexChunk2
5
5
  } from "./index-gzy5w8ya.js";
6
6
  import"./index-1zx87sdm.js";
7
- import"./index-mxjdj2cz.js";
7
+ import"./index-bdnak4d0.js";
8
8
  import"./index-5vsk2cpp.js";
9
9
  import"./index-pavzsdc6.js";
10
10
  import"./index-ywrz4wy2.js";
@@ -17,7 +17,7 @@ import"./index-1d042x6w.js";
17
17
  import"./index-q7q6qp1f.js";
18
18
  import"./index-58e3y90n.js";
19
19
  import"./index-x40zr813.js";
20
- import"./index-fm0bpxc6.js";
20
+ import"./index-yhz1w3ss.js";
21
21
  import {
22
22
  MESSAGE_INDEX_MAX_FTS_BYTES,
23
23
  messageIndexSkipKey,
@@ -25,7 +25,7 @@ import {
25
25
  markMessageIndexDirty,
26
26
  getIndexableContent,
27
27
  indexSingleMessage
28
- } from "./index-5hc4kjg0.js";
28
+ } from "./index-etm62gd7.js";
29
29
  import"./index-s32f8y67.js";
30
30
  import"./index-m0pwswv9.js";
31
31
 
@@ -19,7 +19,7 @@ import"./index-fb3zxn06.js";
19
19
  import {
20
20
  setSqlitePragmaConfig,
21
21
  initializeDatabase
22
- } from "./index-fcrp1k8s.js";
22
+ } from "./index-3mx8math.js";
23
23
  import"./index-wh9fxds5.js";
24
24
  import"./index-v0p37hm2.js";
25
25
  import"./index-96ztjvkn.js";