@cortexkit/opencode-magic-context 0.49.50 → 0.49.52

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 (75) hide show
  1. package/dist/auto-search-worker.js +1 -1
  2. package/dist/chunk-embedding-write-worker.js +1 -1
  3. package/dist/{context-4js5qnnm.js → context-bkkd7br4.js} +14 -14
  4. package/dist/features/magic-context/search-rerank.d.ts +2 -2
  5. package/dist/features/magic-context/search-rerank.d.ts.map +1 -1
  6. package/dist/features/magic-context/storage-meta-persisted.d.ts +1 -1
  7. package/dist/features/magic-context/storage-meta-persisted.d.ts.map +1 -1
  8. package/dist/hooks/magic-context/history-boundary-recovery.d.ts +15 -0
  9. package/dist/hooks/magic-context/history-boundary-recovery.d.ts.map +1 -0
  10. package/dist/hooks/magic-context/inject-compartments.d.ts +11 -0
  11. package/dist/hooks/magic-context/inject-compartments.d.ts.map +1 -1
  12. package/dist/hooks/magic-context/persist-filtered-noise.d.ts +1 -1
  13. package/dist/hooks/magic-context/persist-filtered-noise.d.ts.map +1 -1
  14. package/dist/hooks/magic-context/rust-mode-transform.d.ts +1 -1
  15. package/dist/hooks/magic-context/rust-mode-transform.d.ts.map +1 -1
  16. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +4 -2
  17. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
  18. package/dist/hooks/magic-context/transform.d.ts.map +1 -1
  19. package/dist/hooks/magic-context/unresolved-history-boundary.d.ts +21 -2
  20. package/dist/hooks/magic-context/unresolved-history-boundary.d.ts.map +1 -1
  21. package/dist/{index-ct3ettqt.js → index-0jc25yjf.js} +3 -3
  22. package/dist/{index-h8g08nxs.js → index-42n4fhxy.js} +92 -57
  23. package/dist/{index-wr2t8zb0.js → index-4xpff2m1.js} +7 -6
  24. package/dist/{index-07rp6xcn.js → index-9gs34125.js} +1 -1
  25. package/dist/{index-z4832qfe.js → index-a4zmmhxs.js} +1 -1
  26. package/dist/{index-5dptmnvd.js → index-fxgaaptn.js} +2 -2
  27. package/dist/{index-s131svmx.js → index-g3j49m95.js} +1 -1
  28. package/dist/{index-v4a1pnny.js → index-k2efzh9r.js} +4 -4
  29. package/dist/{index-5g6npyw5.js → index-kanfby7e.js} +137 -41
  30. package/dist/{index-mjh63zvw.js → index-q9m97m5g.js} +1 -1
  31. package/dist/{index-5t1mr0bt.js → index-qbda6a8k.js} +25 -7
  32. package/dist/{index-97bjd14c.js → index-qtpkkzan.js} +4 -4
  33. package/dist/{index-hkveze74.js → index-x4h461yf.js} +1 -1
  34. package/dist/{index-n0twfvah.js → index-x7jcqpy6.js} +1 -1
  35. package/dist/{index-cwj6qhmf.js → index-xqhejxmd.js} +7 -2
  36. package/dist/index.js +18 -18
  37. package/dist/{message-index-bounded-k0ebpy3y.js → message-index-bounded-71b75npz.js} +2 -2
  38. package/dist/migration-worker.js +1 -1
  39. package/dist/raw-ordinal-warmup-worker.js +3 -3
  40. package/dist/{read-session-chunk-6712p893.js → read-session-chunk-bfv831yx.js} +1 -1
  41. package/dist/{recomp-orchestrator-8ebydg5j.js → recomp-orchestrator-8gj1b7pz.js} +7 -7
  42. package/dist/{render-dtc4qkq4.js → render-b3zcz9x4.js} +5 -5
  43. package/dist/{search-archive-f6hjbnsa.js → search-archive-dp9afcv1.js} +3 -3
  44. package/dist/{search-edv0gy1d.js → search-y3w590tn.js} +5 -5
  45. package/dist/shared/user-facing-codes.d.ts +7 -2
  46. package/dist/shared/user-facing-codes.d.ts.map +1 -1
  47. package/dist/{transform-postprocess-phase-1bg25094.js → transform-postprocess-phase-8awze16a.js} +8 -8
  48. package/dist/v2/auto-search-worker.js +1 -1
  49. package/dist/v2/chunk-embedding-write-worker.js +1 -1
  50. package/dist/v2/{context-qkr7z6d0.js → context-99v7x7fm.js} +135 -38
  51. package/dist/v2/{message-index-bounded-a36rw93p.js → message-index-bounded-2pev910h.js} +2 -2
  52. package/dist/v2/migration-worker.js +1 -1
  53. package/dist/v2/raw-ordinal-warmup-worker.js +3 -3
  54. package/dist/v2/{read-session-chunk-hzhxvhyv.js → read-session-chunk-a454a4d2.js} +1 -1
  55. package/dist/v2/{recomp-orchestrator-yzr49pd0.js → recomp-orchestrator-03fskpsa.js} +6 -6
  56. package/dist/v2/{render-rhaevxv1.js → render-cryx4xsj.js} +5 -5
  57. package/dist/v2/{search-ggvexvv7.js → search-2qj4w7rw.js} +4 -4
  58. package/dist/v2/{search-archive-9924fyk8.js → search-archive-xw2rsq81.js} +3 -3
  59. package/dist/v2/{server-88yvx6r9.js → server-b3h8vqa6.js} +1 -1
  60. package/dist/v2/{server-0k586y7d.js → server-cpstyzvy.js} +3 -3
  61. package/dist/v2/{server-sgn61hht.js → server-dkfs58nq.js} +7 -2
  62. package/dist/v2/{server-16kfxcxj.js → server-kfw4m268.js} +1 -1
  63. package/dist/v2/{server-scp3y4dh.js → server-kreheyw5.js} +1 -1
  64. package/dist/v2/{server-3bfc26r7.js → server-qsvm6w79.js} +1 -1
  65. package/dist/v2/{server-jxrqsn84.js → server-txdsx71h.js} +1 -1
  66. package/dist/v2/{server-016a1whm.js → server-wq9y9a03.js} +92 -57
  67. package/dist/v2/{server-3qf9n5ck.js → server-xjzx27w2.js} +24 -6
  68. package/dist/v2/{server-q93jdtz8.js → server-y5cma2j1.js} +2 -2
  69. package/dist/v2/server.js +2 -2
  70. package/dist/v2/{v2-archive-reader-5ggewg8q.js → v2-archive-reader-3575hw8s.js} +1 -1
  71. package/dist/v2/{wrapup-orchestrator-36c5wyvq.js → wrapup-orchestrator-shzv6t4v.js} +6 -6
  72. package/dist/{v2-archive-reader-gx5ke1d7.js → v2-archive-reader-75fdm0te.js} +1 -1
  73. package/dist/{wrapup-orchestrator-ya31knav.js → wrapup-orchestrator-e0z7nvnx.js} +8 -8
  74. package/package.json +1 -1
  75. package/src/shared/user-facing-codes.ts +8 -2
@@ -38,7 +38,7 @@ import {
38
38
  readSessionChunk2,
39
39
  getRawSessionMessageIdsThrough2,
40
40
  readRawSessionSeedTail2
41
- } from "./server-3bfc26r7.js";
41
+ } from "./server-qsvm6w79.js";
42
42
  import"./server-rcchadw0.js";
43
43
  import"./server-1zx87sdm.js";
44
44
  import"./server-7vrtk78d.js";
@@ -7,22 +7,22 @@ import {
7
7
  setRecompTerminal2,
8
8
  buildRecompDeps2,
9
9
  runManagedRecomp2
10
- } from "./server-016a1whm.js";
10
+ } from "./server-wq9y9a03.js";
11
11
  import"./server-c8z2grq0.js";
12
- import"./server-sgn61hht.js";
12
+ import"./server-dkfs58nq.js";
13
13
  import"./server-vjadwb3j.js";
14
14
  import"./server-jjvbk92s.js";
15
15
  import"./server-4h4acntc.js";
16
16
  import"./server-4dhv7mqz.js";
17
- import"./server-88yvx6r9.js";
17
+ import"./server-b3h8vqa6.js";
18
18
  import"./server-t8n27rbt.js";
19
- import"./server-16kfxcxj.js";
19
+ import"./server-kfw4m268.js";
20
20
  import"./server-2amn2s73.js";
21
21
  import"./server-rthnpmbp.js";
22
22
  import"./server-5kgesxck.js";
23
23
  import"./server-vqq3g1t7.js";
24
24
  import"./server-qt1qqasc.js";
25
- import"./server-3bfc26r7.js";
25
+ import"./server-qsvm6w79.js";
26
26
  import"./server-rcchadw0.js";
27
27
  import"./server-1zx87sdm.js";
28
28
  import"./server-7vrtk78d.js";
@@ -35,7 +35,7 @@ import"./server-0ms13pc8.js";
35
35
  import"./server-qp5sj6n5.js";
36
36
  import"./server-g61hgy1y.js";
37
37
  import"./server-mxsy9h1d.js";
38
- import"./server-scp3y4dh.js";
38
+ import"./server-kreheyw5.js";
39
39
  import"./server-fb3zxn06.js";
40
40
  import"./server-58h6rrnx.js";
41
41
  import"./server-fr0wbhdn.js";
@@ -2,20 +2,20 @@ import {
2
2
  renderMessageByOrdinal2,
3
3
  renderVerboseRangeForTool2,
4
4
  renderItemByTag2
5
- } from "./server-jxrqsn84.js";
6
- import"./server-88yvx6r9.js";
5
+ } from "./server-txdsx71h.js";
6
+ import"./server-b3h8vqa6.js";
7
7
  import"./server-t8n27rbt.js";
8
- import"./server-16kfxcxj.js";
8
+ import"./server-kfw4m268.js";
9
9
  import"./server-2amn2s73.js";
10
10
  import"./server-rthnpmbp.js";
11
- import"./server-3bfc26r7.js";
11
+ import"./server-qsvm6w79.js";
12
12
  import"./server-rcchadw0.js";
13
13
  import"./server-1zx87sdm.js";
14
14
  import"./server-7vrtk78d.js";
15
15
  import"./server-0ms13pc8.js";
16
16
  import"./server-g61hgy1y.js";
17
17
  import"./server-mxsy9h1d.js";
18
- import"./server-scp3y4dh.js";
18
+ import"./server-kreheyw5.js";
19
19
  import"./server-fb3zxn06.js";
20
20
  import"./server-58h6rrnx.js";
21
21
  import"./server-fr0wbhdn.js";
@@ -5,18 +5,18 @@ import {
5
5
  resolveMemoriesByIdsForSearch2,
6
6
  unifiedSearch2,
7
7
  formatSearchResults2
8
- } from "./server-3qf9n5ck.js";
8
+ } from "./server-xjzx27w2.js";
9
9
  import"./server-kaqs6h31.js";
10
- import"./server-sgn61hht.js";
10
+ import"./server-dkfs58nq.js";
11
11
  import"./server-vjadwb3j.js";
12
12
  import"./server-jjvbk92s.js";
13
13
  import"./server-4h4acntc.js";
14
14
  import"./server-4dhv7mqz.js";
15
15
  import"./server-t8n27rbt.js";
16
- import"./server-16kfxcxj.js";
16
+ import"./server-kfw4m268.js";
17
17
  import"./server-2amn2s73.js";
18
18
  import"./server-qt1qqasc.js";
19
- import"./server-3bfc26r7.js";
19
+ import"./server-qsvm6w79.js";
20
20
  import"./server-rcchadw0.js";
21
21
  import"./server-1zx87sdm.js";
22
22
  import"./server-7vrtk78d.js";
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  renderSearchArchive2,
3
3
  renderSearchArchiveOffThread2
4
- } from "./server-q93jdtz8.js";
5
- import"./server-0k586y7d.js";
4
+ } from "./server-y5cma2j1.js";
5
+ import"./server-cpstyzvy.js";
6
6
  import"./server-kaqs6h31.js";
7
- import"./server-3bfc26r7.js";
7
+ import"./server-qsvm6w79.js";
8
8
  import"./server-rcchadw0.js";
9
9
  import"./server-1zx87sdm.js";
10
10
  import"./server-7vrtk78d.js";
@@ -53,7 +53,7 @@ import {
53
53
  serializeProcessedImageMarkers,
54
54
  getPendingPiCompactionMarkerState,
55
55
  logPiCompactionMarkerClear
56
- } from "./server-3bfc26r7.js";
56
+ } from "./server-qsvm6w79.js";
57
57
  import {
58
58
  getTableColumnNames,
59
59
  tagTombstoneOwnerRange,
@@ -139,9 +139,9 @@ async function serveV2ArchiveReads2(port, openConnections) {
139
139
  import("./sqlite-zdgm52sv.js"),
140
140
  import("./store-reader-yaxtdy6f.js"),
141
141
  import("./store-skkhh3rd.js"),
142
- import("./read-session-chunk-hzhxvhyv.js"),
143
- import("./render-rhaevxv1.js"),
144
- import("./search-archive-9924fyk8.js"),
142
+ import("./read-session-chunk-a454a4d2.js"),
143
+ import("./render-cryx4xsj.js"),
144
+ import("./search-archive-xw2rsq81.js"),
145
145
  import("./expand-attachments-h33jbgyz.js")
146
146
  ]);
147
147
  const pool = new V2StoreReaderPool;
@@ -42,8 +42,13 @@ var USER_FACING_FAILURES = {
42
42
  },
43
43
  history_boundary_unresolved: {
44
44
  code: "MC-H04",
45
- sentence: "This request was not sent: Magic Context could not safely place the history summary boundary in the loaded conversation, and the untrimmed request is larger than the model's context window.",
46
- action: "Reopen this session in its current project directory, then run /ctx-recomp to rebuild the history summary. A model with a larger context window can also help."
45
+ sentence: "This request was not sent: it is larger than the model's context window, and Magic Context could not cut the already-summarized history out of it.",
46
+ action: "Run /ctx-flush to compress the history now, then send your message again."
47
+ },
48
+ history_boundary_recovering: {
49
+ code: "MC-H08",
50
+ sentence: "This request was not sent: it is larger than the model's context window, and Magic Context could not cut the already-summarized history out of it.",
51
+ action: "Send your message again: Magic Context will first summarize more of the history and drop old tool output to make it fit."
47
52
  },
48
53
  history_over_window_unmanaged: {
49
54
  code: "MC-H06",
@@ -9,7 +9,7 @@ import {
9
9
  } from "./server-pavzsdc6.js";
10
10
  import {
11
11
  cleanUserText2
12
- } from "./server-3bfc26r7.js";
12
+ } from "./server-qsvm6w79.js";
13
13
  import {
14
14
  recordMessageFtsRowid2,
15
15
  recordIndexedMessageTime2,
@@ -1023,7 +1023,7 @@ function finishDatabaseOpen(db, dbPath, explicitDbPath, latestSupportedVersion)
1023
1023
  state.running = startMessageFtsRowidMapBackfill2(db, signal).then(async () => {
1024
1024
  if (signal.aborted || !readsOpenCodeStore)
1025
1025
  return;
1026
- const { readRawSessionMessagePage, readRawSessionMessages } = await importPluginModule(() => import("./read-session-chunk-hzhxvhyv.js"));
1026
+ const { readRawSessionMessagePage, readRawSessionMessages } = await importPluginModule(() => import("./read-session-chunk-a454a4d2.js"));
1027
1027
  const { startMessageTimeBackfill } = await importPluginModule(() => import("./message-time-backfill-baxebka0.js"));
1028
1028
  if (signal.aborted)
1029
1029
  return;
@@ -3447,7 +3447,7 @@ function normalizeDetectedLimitModelKey(modelKey) {
3447
3447
  return typeof modelKey === "string" && modelKey.length > 0 ? piModelRefToCanonical(modelKey) : null;
3448
3448
  }
3449
3449
  function normalizeEmergencyRecoveryOrigin(value) {
3450
- return value === "provider_overflow" || value === "proactive_model_shrink" ? value : null;
3450
+ return value === "provider_overflow" || value === "proactive_model_shrink" || value === "history_boundary_over_window" ? value : null;
3451
3451
  }
3452
3452
  function parseOverflowState(result, modelKey) {
3453
3453
  if (!result) {
@@ -5,7 +5,7 @@ import {
5
5
  expandToolPart,
6
6
  visitRawSessionMessages2,
7
7
  readRawSessionMessageById2
8
- } from "./server-3bfc26r7.js";
8
+ } from "./server-qsvm6w79.js";
9
9
  import {
10
10
  getTagById2
11
11
  } from "./server-rcchadw0.js";
@@ -152,7 +152,7 @@ import {
152
152
  getRawSessionTagKeysThrough2,
153
153
  getLegacyProtectedTailStartOrdinal2,
154
154
  readSessionChunk2
155
- } from "./server-3bfc26r7.js";
155
+ } from "./server-qsvm6w79.js";
156
156
  import {
157
157
  BoundedSessionMap
158
158
  } from "./server-kgq2e2hh.js";
@@ -162,7 +162,7 @@ import {
162
162
  toMessageIndexSource,
163
163
  clearIndexedMessagesInTransaction,
164
164
  indexSourcesAfterOrdinal
165
- } from "./server-16kfxcxj.js";
165
+ } from "./server-kfw4m268.js";
166
166
  import {
167
167
  COMPARTMENT_LEASE_RENEWAL_MS,
168
168
  getCompartmentLeaseBlocker,
@@ -206,7 +206,7 @@ import {
206
206
  getProjectState,
207
207
  recordSubagentInvocation,
208
208
  getLatestHistorianInvocationId
209
- } from "./server-88yvx6r9.js";
209
+ } from "./server-b3h8vqa6.js";
210
210
  import {
211
211
  invalidateAutoEmbedSession
212
212
  } from "./server-2amn2s73.js";
@@ -260,13 +260,13 @@ import {
260
260
  userFacingFailureCode,
261
261
  promoteSessionFactsDurable,
262
262
  embedPromotedFacts
263
- } from "./server-sgn61hht.js";
263
+ } from "./server-dkfs58nq.js";
264
264
  import {
265
265
  getSchemaFenceRejection,
266
266
  LATEST_SUPPORTED_VERSION,
267
267
  getPersistedSchemaVersion,
268
268
  openDatabase
269
- } from "./server-scp3y4dh.js";
269
+ } from "./server-kreheyw5.js";
270
270
  import {
271
271
  parseCompartmentOutput,
272
272
  resolveWorkspaceShareCategories,
@@ -2548,7 +2548,7 @@ function updateUserMemoryContent(db, id, content) {
2548
2548
  db.prepare("UPDATE user_memories SET content = ?, updated_at = ? WHERE id = ?").run(content, Date.now(), id);
2549
2549
  }
2550
2550
  function dismissUserMemory(db, id) {
2551
- db.prepare("UPDATE user_memories SET status = 'dismissed', updated_at = ? WHERE id = ?").run(Date.now(), id);
2551
+ db.prepare("UPDATE user_memories SET status = 'dismissed', updated_at = ? WHERE id = ? AND status = 'active'").run(Date.now(), id);
2552
2552
  }
2553
2553
  function parseCandidateIds(raw) {
2554
2554
  try {
@@ -9838,10 +9838,10 @@ function findHostCompactionWindow(messages, readMagicContextSummaryMessageId) {
9838
9838
  completedAt
9839
9839
  };
9840
9840
  }
9841
- function boundaryPrecedesWindow(sessionId, boundary, firstLiveId) {
9841
+ function boundaryOrderAgainstWindow(sessionId, boundary, firstLiveId) {
9842
9842
  const cached = precedesVerdictBySession.get(sessionId);
9843
9843
  if (cached && cached.boundary === boundary && cached.firstLiveId === firstLiveId) {
9844
- return cached.precedes;
9844
+ return cached.verdict;
9845
9845
  }
9846
9846
  let order = null;
9847
9847
  try {
@@ -9854,9 +9854,9 @@ function boundaryPrecedesWindow(sessionId, boundary, firstLiveId) {
9854
9854
  sessionLog2(sessionId, `prefix trim: placing boundary ${boundary} failed:`, error);
9855
9855
  order = null;
9856
9856
  }
9857
- const precedes = order !== null && order < 0;
9858
- precedesVerdictBySession.set(sessionId, { boundary, firstLiveId, precedes });
9859
- return precedes;
9857
+ const verdict = order === null || !Number.isFinite(order) ? "unknown" : order < 0 ? "precedes" : "not-before";
9858
+ precedesVerdictBySession.set(sessionId, { boundary, firstLiveId, verdict });
9859
+ return verdict;
9860
9860
  }
9861
9861
  function logBoundaryPrecedesWindow(options, boundary, firstLiveId) {
9862
9862
  const { sessionId } = options;
@@ -9870,9 +9870,10 @@ function classifyAbsentBoundary(options, messages, boundary) {
9870
9870
  const { sessionId } = options;
9871
9871
  const pass = options.isCacheBustingPass ? "priced" : "defer";
9872
9872
  const firstLiveId = firstPersistedLiveId(messages);
9873
- if (firstLiveId !== null && boundaryPrecedesWindow(sessionId, boundary, firstLiveId)) {
9873
+ const order = firstLiveId === null ? "unknown" : boundaryOrderAgainstWindow(sessionId, boundary, firstLiveId);
9874
+ if (firstLiveId !== null && order === "precedes") {
9874
9875
  logBoundaryPrecedesWindow(options, boundary, firstLiveId);
9875
- return "boundary-precedes-window";
9876
+ return { status: "boundary-precedes-window" };
9876
9877
  }
9877
9878
  precedesWindowLoggedBySession.delete(sessionId);
9878
9879
  const current = absentBoundaryEpisodeBySession.get(sessionId);
@@ -9882,7 +9883,10 @@ function classifyAbsentBoundary(options, messages, boundary) {
9882
9883
  if (episode.passes === 1 || options.isCacheBustingPass) {
9883
9884
  sessionLog2(sessionId, `prefix trim: boundary ${boundary} absent from current messages; pass=${pass}; no in-pass trim applied (degraded pass ${episode.passes}; ${firstLiveId === null ? "no persisted live message to compare with" : `boundary does not sort before the first live message ${firstLiveId}`}; whole window served until a cache-busting pass moves the boundary into the window)`);
9884
9885
  }
9885
- return "refused";
9886
+ return {
9887
+ status: "refused",
9888
+ refusal: order === "not-before" ? "boundary-not-in-request" : "boundary-unordered"
9889
+ };
9886
9890
  }
9887
9891
  function isSyntheticPrefixHead(message) {
9888
9892
  if (message.info.id !== undefined || message.info.role !== "user" || message.parts.length === 0) {
@@ -9896,17 +9900,14 @@ function capturePrefixTrimSourceOrder(messages) {
9896
9900
  let syntheticHeadCount = 0;
9897
9901
  let sawPersistedRow = false;
9898
9902
  let invalidReason = null;
9899
- for (const [index, message] of messages.entries()) {
9903
+ for (const message of messages) {
9900
9904
  const id = message.info.id;
9901
9905
  if (isHostRenderedSystemMessage(message))
9902
9906
  continue;
9903
9907
  if (typeof id !== "string" || id.length === 0) {
9904
- if (!sawPersistedRow && isSyntheticPrefixHead(message)) {
9908
+ if (!sawPersistedRow && isSyntheticPrefixHead(message))
9905
9909
  syntheticHeadCount += 1;
9906
- continue;
9907
- }
9908
- invalidReason = `source message at index ${index} has no stable id outside the synthetic head`;
9909
- break;
9910
+ continue;
9910
9911
  }
9911
9912
  sawPersistedRow = true;
9912
9913
  if (seen.has(id)) {
@@ -9955,21 +9956,49 @@ function reanchorStoredBoundary(options, boundary) {
9955
9956
  }
9956
9957
  function trimToPreparedPrefix(options, prepared) {
9957
9958
  if (options.compactionOff || !options.messages)
9958
- return "not-attempted";
9959
+ return { status: "not-attempted" };
9960
+ const messages = options.messages;
9959
9961
  const boundary = prepared.preparedTrimBoundaryId;
9960
- let status = "not-required";
9962
+ let outcome = { status: "not-required" };
9961
9963
  if (boundary) {
9962
9964
  const retireDecisions = (messageIds) => {
9963
9965
  queueAutoSearchHintDecisionRetirement(options.db, options.sessionId, new Set(messageIds));
9964
9966
  };
9967
+ const trimAtVisibleBoundary = (reanchor) => {
9968
+ const index = findBoundaryIndex(options.sessionId, messages, boundary);
9969
+ if (index >= 0) {
9970
+ const cut = index + (isPartialCompartmentEnd(options.db, options.sessionId, boundary) ? 0 : 1);
9971
+ const unplaced = messages.slice(0, cut).filter(isHostRenderedSystemMessage);
9972
+ const removed = messages.splice(0, cut, ...unplaced);
9973
+ retireDecisions(removed.map((message) => message.info.id).filter((id) => typeof id === "string"));
9974
+ resetPrefixTrimFallbackState(options.sessionId);
9975
+ return { status: "applied" };
9976
+ }
9977
+ if (reanchor) {
9978
+ const reanchored = reanchorStoredBoundary(options, boundary);
9979
+ if (reanchored && reanchored.messageIds[0] !== boundary) {
9980
+ return trimToPreparedPrefix({ ...options, prefixTrimSourceOrder: reanchored }, prepared);
9981
+ }
9982
+ }
9983
+ return classifyAbsentBoundary(options, messages, boundary);
9984
+ };
9965
9985
  const sourceOrder = options.prefixTrimSourceOrder;
9966
9986
  if (sourceOrder) {
9967
- const refuse = (reason) => {
9968
- sessionLog2(options.sessionId, `prefix trim: boundary ${boundary}; pass=${options.isCacheBustingPass ? "priced" : "defer"}; no in-pass trim applied (${reason})`);
9969
- return "refused";
9987
+ const pass = options.isCacheBustingPass ? "priced" : "defer";
9988
+ const refuse = (reason, refusal) => {
9989
+ sessionLog2(options.sessionId, `prefix trim: boundary ${boundary}; pass=${pass}; no in-pass trim applied (${reason})`);
9990
+ return { status: "refused", refusal };
9991
+ };
9992
+ const placeWithoutSourceOrder = (reason) => {
9993
+ sessionLog2(options.sessionId, `prefix trim: boundary ${boundary}; pass=${pass}; source order not usable (${reason}); placing the boundary by the live messages`);
9994
+ const served = resolveHostServedBoundaryId2(options.sessionId, boundary);
9995
+ const copies = messages.filter((message) => message.info.id === boundary || message.info.id === served).length;
9996
+ if (copies > 1)
9997
+ return refuse(`boundary ${boundary} appears ${copies} times in the live messages`, "boundary-unordered");
9998
+ return trimAtVisibleBoundary(false);
9970
9999
  };
9971
10000
  if (sourceOrder.invalidReason) {
9972
- status = refuse(sourceOrder.invalidReason);
10001
+ outcome = placeWithoutSourceOrder(sourceOrder.invalidReason);
9973
10002
  } else {
9974
10003
  const sourcePosition = new Map;
9975
10004
  sourceOrder.messageIds.forEach((id, index) => {
@@ -9978,7 +10007,7 @@ function trimToPreparedPrefix(options, prepared) {
9978
10007
  const boundaryPosition = sourcePosition.get(boundary) ?? sourcePosition.get(resolveHostServedBoundaryId2(options.sessionId, boundary));
9979
10008
  if (boundaryPosition === undefined) {
9980
10009
  const reanchored = reanchorStoredBoundary(options, boundary);
9981
- status = reanchored ? trimToPreparedPrefix({ ...options, prefixTrimSourceOrder: reanchored }, prepared) : refuse("boundary absent from immutable source order");
10010
+ outcome = reanchored ? trimToPreparedPrefix({ ...options, prefixTrimSourceOrder: reanchored }, prepared) : refuse("boundary absent from immutable source order", "boundary-unordered");
9982
10011
  } else {
9983
10012
  let lastSourcePosition = -1;
9984
10013
  let sawPersistedRow = false;
@@ -9986,17 +10015,29 @@ function trimToPreparedPrefix(options, prepared) {
9986
10015
  let firstLiveId;
9987
10016
  let liveOrderError = null;
9988
10017
  const retained = [];
9989
- for (const [index, message] of options.messages.entries()) {
10018
+ let unplaced = [];
10019
+ const placeUnplaced = (cut) => {
10020
+ for (const message of unplaced) {
10021
+ if (!cut || isHostRenderedSystemMessage(message))
10022
+ retained.push(message);
10023
+ }
10024
+ unplaced = [];
10025
+ };
10026
+ for (const message of options.messages) {
9990
10027
  const id = message.info.id;
9991
10028
  if (isHostRenderedSystemMessage(message)) {
10029
+ if (unplaced.length > 0) {
10030
+ unplaced.push(message);
10031
+ continue;
10032
+ }
9992
10033
  retained.push(message);
9993
10034
  continue;
9994
10035
  }
9995
10036
  if (typeof id !== "string" || id.length === 0) {
9996
10037
  if (!sawPersistedRow && isSyntheticPrefixHead(message))
9997
10038
  continue;
9998
- liveOrderError = `live message at index ${index} has no stable id outside the synthetic head`;
9999
- break;
10039
+ unplaced.push(message);
10040
+ continue;
10000
10041
  }
10001
10042
  sawPersistedRow = true;
10002
10043
  const position = sourcePosition.get(id);
@@ -10013,44 +10054,31 @@ function trimToPreparedPrefix(options, prepared) {
10013
10054
  firstLiveId = id;
10014
10055
  }
10015
10056
  lastSourcePosition = position;
10057
+ placeUnplaced(position <= boundaryPosition);
10016
10058
  if (position > boundaryPosition || position === boundaryPosition && isPartialCompartmentEnd(options.db, options.sessionId, boundary))
10017
10059
  retained.push(message);
10018
10060
  }
10019
- if (liveOrderError)
10020
- status = refuse(liveOrderError);
10021
- else {
10061
+ placeUnplaced(false);
10062
+ if (liveOrderError) {
10063
+ outcome = placeWithoutSourceOrder(liveOrderError);
10064
+ } else {
10022
10065
  if (firstLiveId && firstLivePosition !== undefined && firstLivePosition > boundaryPosition) {
10023
10066
  logBoundaryPrecedesWindow(options, boundary, firstLiveId);
10024
10067
  }
10025
10068
  options.messages.splice(0, options.messages.length, ...retained);
10026
10069
  const preserveBoundary = isPartialCompartmentEnd(options.db, options.sessionId, boundary);
10027
10070
  retireDecisions(sourceOrder.messageIds.slice(0, boundaryPosition + (preserveBoundary ? 0 : 1)));
10028
- status = "applied";
10071
+ outcome = { status: "applied" };
10029
10072
  }
10030
10073
  }
10031
10074
  }
10032
10075
  } else {
10033
- const index = findBoundaryIndex(options.sessionId, options.messages, boundary);
10034
- if (index >= 0) {
10035
- const cut = index + (isPartialCompartmentEnd(options.db, options.sessionId, boundary) ? 0 : 1);
10036
- const unplaced = options.messages.slice(0, cut).filter(isHostRenderedSystemMessage);
10037
- const removed = options.messages.splice(0, cut, ...unplaced);
10038
- retireDecisions(removed.map((message) => message.info.id).filter((id) => typeof id === "string"));
10039
- resetPrefixTrimFallbackState(options.sessionId);
10040
- status = "applied";
10041
- } else {
10042
- const reanchored = reanchorStoredBoundary(options, boundary);
10043
- if (reanchored && reanchored.messageIds[0] !== boundary) {
10044
- status = trimToPreparedPrefix({ ...options, prefixTrimSourceOrder: reanchored }, prepared);
10045
- } else {
10046
- status = classifyAbsentBoundary(options, options.messages, boundary);
10047
- }
10048
- }
10076
+ outcome = trimAtVisibleBoundary(true);
10049
10077
  }
10050
10078
  }
10051
10079
  if (prepared.m0RematerializedThisPass || options.isCacheBustingPass && !prepared.materializationContentionRetryExhausted)
10052
10080
  clearInjectionCache(options.sessionId);
10053
- return status;
10081
+ return outcome;
10054
10082
  }
10055
10083
  function prepareCachedM0M1Replay(db, sessionId) {
10056
10084
  const row = readCachedM0M1Row(db, sessionId);
@@ -10103,15 +10131,16 @@ function injectM0M1(options) {
10103
10131
  const prepared = options.preparedPrefix;
10104
10132
  if (prepared?.preparedMessages) {
10105
10133
  const head = prepared.preparedMessages;
10106
- let prefixTrimStatus = "not-attempted";
10134
+ let prefixTrim = { status: "not-attempted" };
10107
10135
  if (options.messages) {
10108
- prefixTrimStatus = trimToPreparedPrefix(options, prepared);
10136
+ prefixTrim = trimToPreparedPrefix(options, prepared);
10109
10137
  options.messages.unshift(...structuredClone(head));
10110
10138
  }
10111
10139
  return {
10112
10140
  ...prepared,
10113
10141
  prependedMessageCount: options.messages ? head.length : 0,
10114
- prefixTrimStatus
10142
+ prefixTrimStatus: prefixTrim.status,
10143
+ prefixTrimRefusal: prefixTrim.refusal
10115
10144
  };
10116
10145
  }
10117
10146
  hydrateCachedM0Mural(options.db, options.sessionId, options.state);
@@ -10268,9 +10297,9 @@ function injectM0M1(options) {
10268
10297
  contentHash: options.state.cachedM0MuralHash ?? undefined
10269
10298
  } : undefined;
10270
10299
  let prependedMessageCount = prependM0M1Messages(options.sessionId, preparedMessages, m0Text, m1Text, muralForWire);
10271
- let prefixTrimStatus = "not-attempted";
10300
+ let prefixTrim = { status: "not-attempted" };
10272
10301
  if (options.messages) {
10273
- prefixTrimStatus = trimToPreparedPrefix(options, {
10302
+ prefixTrim = trimToPreparedPrefix(options, {
10274
10303
  m0RematerializedThisPass: rematerialized,
10275
10304
  materializationContentionRetryExhausted: contentionExhausted,
10276
10305
  preparedTrimBoundaryId
@@ -10288,7 +10317,8 @@ function injectM0M1(options) {
10288
10317
  m1Text,
10289
10318
  preparedMessages,
10290
10319
  preparedTrimBoundaryId,
10291
- prefixTrimStatus
10320
+ prefixTrimStatus: prefixTrim.status,
10321
+ ...prefixTrim.refusal ? { prefixTrimRefusal: prefixTrim.refusal } : {}
10292
10322
  };
10293
10323
  }
10294
10324
 
@@ -13393,6 +13423,11 @@ function persistFilteredNoise(db, sessionId, chunk, eligibleEnd) {
13393
13423
  const start = chunk.startIndex;
13394
13424
  if (chunk.text || chunk.messageCount !== 0 || eligibleEnd <= start || rows.length !== eligibleEnd - start || rows.some((row, index) => row.ordinal !== start + index || !row.messageId))
13395
13425
  return false;
13426
+ const endId = rows[rows.length - 1].messageId;
13427
+ if (!hasRawSessionMessageById2(sessionId, endId)) {
13428
+ sessionLog2(sessionId, `historian skipped a filtered-noise marker for ordinals ${start}-${eligibleEnd - 1}: its end row ${endId} is no longer in the host store`);
13429
+ return false;
13430
+ }
13396
13431
  const saved = db.transaction(() => {
13397
13432
  const prior = getCompartments(db, sessionId);
13398
13433
  const last = prior.at(-1);
@@ -25,7 +25,7 @@ import {
25
25
  isMessageIndexReconciledThrough,
26
26
  clearIndexedMessages,
27
27
  indexMessagesAfterOrdinal
28
- } from "./server-16kfxcxj.js";
28
+ } from "./server-kfw4m268.js";
29
29
  import {
30
30
  Priority,
31
31
  AdmissionClass,
@@ -81,7 +81,7 @@ import {
81
81
  sanitizeFtsQuery,
82
82
  searchMemoriesFTS,
83
83
  searchMemoriesFTSUnion
84
- } from "./server-sgn61hht.js";
84
+ } from "./server-dkfs58nq.js";
85
85
  import {
86
86
  MESSAGE_FTS_SESSION_FILTER_SQL,
87
87
  withMessageFtsSessionFilter
@@ -1771,6 +1771,8 @@ function sha256(value) {
1771
1771
  var RERANK_MODEL = "gte-reranker-modernbert-base-f32";
1772
1772
  var RERANK_LANE_LIMIT = 25;
1773
1773
  var DEADLINE_MS = 1500;
1774
+ var SYNAPSE_RESTART_BACKOFF_MS = 30000;
1775
+ var SYNAPSE_ABSENT_BACKOFF_MS = 10 * 60000;
1774
1776
  var DOCUMENT_BYTES = 1024;
1775
1777
  var proseWordSegmenter = new Intl.Segmenter(undefined, { granularity: "word" });
1776
1778
  function isProseQuery(query) {
@@ -1913,10 +1915,11 @@ async function bounded(promise) {
1913
1915
  }
1914
1916
  }
1915
1917
  var connections = new Map;
1918
+ var synapseRetryAt = new Map;
1916
1919
  async function connect(connectionFile) {
1917
1920
  let connection = connections.get(connectionFile);
1918
1921
  if (!connection) {
1919
- connection = inRootAsyncContext2(() => SubcClient.connect({ connectionFile }));
1922
+ connection = inRootAsyncContext2(() => SubcClient.connect({ connectionFile, routeOpenRetryDeadlineMs: 0 }));
1920
1923
  connections.set(connectionFile, connection);
1921
1924
  connection.catch(() => connections.delete(connectionFile));
1922
1925
  }
@@ -1986,24 +1989,39 @@ function remoteRerankSkipped(reason, onSkipped) {
1986
1989
  logRerankFallback(safe);
1987
1990
  onSkipped?.(line);
1988
1991
  }
1989
- async function prepareReranker(projectRoot, sessionId, connectionFile, injectedClient, config) {
1992
+ async function prepareReranker(projectRoot, sessionId, connectionFile, injectedClient, config, now = Date.now) {
1990
1993
  if (config?.provider === "off")
1991
1994
  return null;
1992
1995
  if (config?.provider === "remote")
1993
1996
  return { remote: config };
1997
+ const daemonFile = connectionFile ?? getDefaultSubcConnectionFile();
1998
+ const rememberAbsence = injectedClient === undefined;
1999
+ if (rememberAbsence && (synapseRetryAt.get(daemonFile) ?? 0) > now())
2000
+ return null;
2001
+ let catalogRequested = false;
1994
2002
  try {
1995
2003
  if (injectedClient === null)
1996
2004
  throw new RerankFailure("missing_synapse");
1997
- const client = injectedClient ?? await connect(connectionFile ?? getDefaultSubcConnectionFile());
2005
+ const client = injectedClient ?? await connect(daemonFile);
1998
2006
  const identity = {
1999
2007
  project_root: projectRoot,
2000
2008
  harness: "magic-context",
2001
2009
  session: sessionId
2002
2010
  };
2011
+ catalogRequested = true;
2003
2012
  const lane = pinReranker(await bounded(client.call("synapse", "models.list", {}, { timeoutMs: DEADLINE_MS, targetKind: "management_surface", identity })));
2013
+ if (rememberAbsence)
2014
+ synapseRetryAt.delete(daemonFile);
2004
2015
  return { client, lane, identity };
2005
2016
  } catch (error) {
2006
- logRerankFallback(reasonOf(error));
2017
+ const reason = reasonOf(error);
2018
+ if (rememberAbsence && catalogRequested && reason === "unknown_module") {
2019
+ const failedAt = now();
2020
+ const previousRetryAt = synapseRetryAt.get(daemonFile);
2021
+ const backoff = previousRetryAt !== undefined && failedAt - previousRetryAt < SYNAPSE_ABSENT_BACKOFF_MS ? SYNAPSE_ABSENT_BACKOFF_MS : SYNAPSE_RESTART_BACKOFF_MS;
2022
+ synapseRetryAt.set(daemonFile, failedAt + backoff);
2023
+ }
2024
+ logRerankFallback(reason);
2007
2025
  return null;
2008
2026
  }
2009
2027
  }
@@ -19,10 +19,10 @@ import {
19
19
  rawMessageWorkerSource2,
20
20
  rawMessageOffThreadRangeReader2,
21
21
  readRawSessionMessageIdOrdinalsForRange2
22
- } from "./server-3bfc26r7.js";
22
+ } from "./server-qsvm6w79.js";
23
23
  import {
24
24
  readV2ArchiveOffThread2
25
- } from "./server-0k586y7d.js";
25
+ } from "./server-cpstyzvy.js";
26
26
 
27
27
  // src/tools/ctx-expand/search-archive.ts
28
28
  var archiveReadsOnThisThread = 0;
package/dist/v2/server.js CHANGED
@@ -7875,7 +7875,7 @@ var require_src2 = __commonJS(function(exports, module) {
7875
7875
  // package.json
7876
7876
  var package_default = {
7877
7877
  name: "@cortexkit/opencode-magic-context",
7878
- version: "0.49.50",
7878
+ version: "0.49.52",
7879
7879
  type: "module",
7880
7880
  description: "OpenCode plugin for Magic Context — cross-session memory and context management",
7881
7881
  main: "dist/index.js",
@@ -8196,7 +8196,7 @@ async function setup(context) {
8196
8196
  if (claimStorageBackupWarningCheck() && isMagicContextStorageOutsideEngram(storageDir)) {
8197
8197
  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.`);
8198
8198
  }
8199
- const { registerContext } = await import("./context-qkr7z6d0.js");
8199
+ const { registerContext } = await import("./context-99v7x7fm.js");
8200
8200
  setHarness2("opencode2");
8201
8201
  bindStaleBuildNotice({}, import.meta.url, "opencode2");
8202
8202
  const duties = await registerContext(context);
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  readV2ArchiveOffThread2,
3
3
  serveV2ArchiveReads2
4
- } from "./server-0k586y7d.js";
4
+ } from "./server-cpstyzvy.js";
5
5
  import"./server-v0p37hm2.js";
6
6
  import"./server-gzy5w8ya.js";
7
7
  import"./server-1d042x6w.js";