@cortexkit/opencode-magic-context 0.49.15 → 0.49.16

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 (123) hide show
  1. package/dist/auto-search-worker.js +3 -3
  2. package/dist/chunk-embedding-write-worker.js +5 -3
  3. package/dist/config/schema/magic-context.d.ts +65 -65
  4. package/dist/config/schema/magic-context.d.ts.map +1 -1
  5. package/dist/{conflict-warning-hook-mgq17yr3.js → conflict-warning-hook-znry4j76.js} +5 -5
  6. package/dist/{context-0m46day0.js → context-3znk23va.js} +26 -20
  7. package/dist/{embedding-backfill-5e1t5wha.js → embedding-backfill-q4n8dend.js} +8 -6
  8. package/dist/embedding-worker.js +2 -2
  9. package/dist/features/magic-context/message-fts-rowid-map.d.ts +2 -2
  10. package/dist/features/magic-context/message-fts-rowid-map.d.ts.map +1 -1
  11. package/dist/features/magic-context/message-fts-session-filter.d.ts +2 -0
  12. package/dist/features/magic-context/message-fts-session-filter.d.ts.map +1 -1
  13. package/dist/features/magic-context/message-time-backfill.d.ts +2 -2
  14. package/dist/features/magic-context/message-time-backfill.d.ts.map +1 -1
  15. package/dist/features/magic-context/storage-db.d.ts +2 -1
  16. package/dist/features/magic-context/storage-db.d.ts.map +1 -1
  17. package/dist/hooks/magic-context/compartment-runner-historian.d.ts +2 -2
  18. package/dist/hooks/magic-context/compartment-runner-incremental.d.ts.map +1 -1
  19. package/dist/hooks/magic-context/compartment-runner-validation.d.ts.map +1 -1
  20. package/dist/hooks/magic-context/emergency-drop.d.ts.map +1 -1
  21. package/dist/hooks/magic-context/historian-host-runner.d.ts.map +1 -1
  22. package/dist/hooks/magic-context/historian-prompt-fit.d.ts +2 -1
  23. package/dist/hooks/magic-context/historian-prompt-fit.d.ts.map +1 -1
  24. package/dist/hooks/magic-context/raw-ordinal-warmup.d.ts +26 -0
  25. package/dist/hooks/magic-context/raw-ordinal-warmup.d.ts.map +1 -1
  26. package/dist/hooks/magic-context/recomp-orchestrator.d.ts +3 -3
  27. package/dist/hooks/magic-context/recomp-orchestrator.d.ts.map +1 -1
  28. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
  29. package/dist/hooks/magic-context/transform.d.ts.map +1 -1
  30. package/dist/{index-xn6q9pg6.js → index-4qfy7v57.js} +11 -62
  31. package/dist/{index-e4dsjj1p.js → index-5mwk1nek.js} +1 -1
  32. package/dist/index-6a6dq53h.js +96 -0
  33. package/dist/{index-e20m7284.js → index-7b2cfmaz.js} +1 -1
  34. package/dist/{index-mmfa86mt.js → index-7pa32z07.js} +169 -149
  35. package/dist/{index-3kdm78zp.js → index-9nkg2dzk.js} +3 -3
  36. package/dist/{index-snp5wbge.js → index-ayym1x7f.js} +25 -23
  37. package/dist/{index-dgs16axy.js → index-b17m64g9.js} +1 -1
  38. package/dist/{index-yxycg7fs.js → index-cj9g0j7a.js} +22 -14
  39. package/dist/{index-dyvbsvga.js → index-dqe8pq4x.js} +21 -10
  40. package/dist/{index-42vcjcwe.js → index-ek1yxvvz.js} +34 -76
  41. package/dist/{index-3kx0kg0f.js → index-hehkf6zm.js} +3 -3
  42. package/dist/{index-944w16m0.js → index-j6zw70pf.js} +4 -4
  43. package/dist/index-kaqs6h31.js +58 -0
  44. package/dist/{index-ts1hjk1h.js → index-kn4t1haw.js} +15 -12
  45. package/dist/{index-1d289pq2.js → index-mtw9e71a.js} +1 -1
  46. package/dist/{index-mht7bq0z.js → index-nd7m2a5a.js} +7 -5
  47. package/dist/{index-thvnpfsv.js → index-p4vde22c.js} +14 -14
  48. package/dist/{index-y1qysm3q.js → index-qrahzcqv.js} +3 -3
  49. package/dist/{index-1vc7jrkg.js → index-v63beg1z.js} +3 -3
  50. package/dist/{index-mc1cqza6.js → index-v9asb16b.js} +4 -4
  51. package/dist/{index-1sarmj9z.js → index-wgypt3cs.js} +6 -6
  52. package/dist/{index-bxdg2nbt.js → index-wv9n2zcq.js} +1 -1
  53. package/dist/index.js +38 -36
  54. package/dist/message-fts-rowid-map-yvx5a9jw.js +23 -0
  55. package/dist/{message-index-bounded-vtgpq6b4.js → message-index-bounded-6th8djy9.js} +8 -8
  56. package/dist/{message-index-a6gztaqx.js → message-index-t4pz7akd.js} +9 -9
  57. package/dist/{message-time-backfill-qjge9044.js → message-time-backfill-8egzkd3z.js} +4 -4
  58. package/dist/migration-worker.js +4 -2
  59. package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
  60. package/dist/{project-embedding-registry-x45bv3qr.js → project-embedding-registry-2dea0a77.js} +7 -5
  61. package/dist/raw-ordinal-warmup-worker.js +37 -7
  62. package/dist/{read-session-chunk-3ae3nfdn.js → read-session-chunk-4pwqxm5a.js} +6 -6
  63. package/dist/{read-session-raw-m56hc7v2.js → read-session-raw-5ar8se5v.js} +1 -1
  64. package/dist/{recomp-orchestrator-nwzcfhx4.js → recomp-orchestrator-tjcaj5x7.js} +17 -17
  65. package/dist/search-archive-02jws7hw.js +25 -0
  66. package/dist/{search-deajrd90.js → search-rb01n29x.js} +15 -14
  67. package/dist/{send-session-notification-24r4esbh.js → send-session-notification-2x9edkrp.js} +4 -4
  68. package/dist/shared/model-suggestion-retry.d.ts +2 -0
  69. package/dist/shared/model-suggestion-retry.d.ts.map +1 -1
  70. package/dist/shared/resolve-fallbacks.d.ts +3 -3
  71. package/dist/{storage-tags-s5bg1ahx.js → storage-tags-4z1w27xa.js} +1 -1
  72. package/dist/tools/ctx-expand/search-archive.d.ts +5 -1
  73. package/dist/tools/ctx-expand/search-archive.d.ts.map +1 -1
  74. package/dist/{transform-postprocess-phase-ne3z1zmt.js → transform-postprocess-phase-xaw5c3xp.js} +17 -17
  75. package/dist/v2/auto-search-worker.js +3 -3
  76. package/dist/v2/chunk-embedding-write-worker.js +8 -6
  77. package/dist/v2/{context-4qczzck7.js → context-acw1nhv8.js} +52 -86
  78. package/dist/v2/{embedding-backfill-jmaf8zrr.js → embedding-backfill-jyd6492b.js} +10 -8
  79. package/dist/v2/embedding-worker.js +2 -2
  80. package/dist/v2/hooks/context.d.ts.map +1 -1
  81. package/dist/v2/message-fts-rowid-map-8vf0v7cr.js +22 -0
  82. package/dist/v2/{message-index-bounded-rxxznd34.js → message-index-bounded-dsrf49y7.js} +7 -7
  83. package/dist/v2/{message-index-f947qtbz.js → message-index-e6qzw477.js} +8 -8
  84. package/dist/v2/{message-time-backfill-bsteyc4d.js → message-time-backfill-q5pgxf0d.js} +4 -4
  85. package/dist/v2/migration-worker.js +6 -4
  86. package/dist/v2/{project-embedding-registry-0msp56p8.js → project-embedding-registry-rek75aqw.js} +9 -7
  87. package/dist/v2/raw-ordinal-warmup-worker.js +37 -7
  88. package/dist/v2/{read-session-chunk-rq9nx1nn.js → read-session-chunk-7bpygfv2.js} +5 -5
  89. package/dist/v2/{read-session-raw-b3tf6ra1.js → read-session-raw-pw2n1qgc.js} +1 -1
  90. package/dist/v2/{recomp-orchestrator-5zhxtwha.js → recomp-orchestrator-hzpgg06e.js} +18 -18
  91. package/dist/v2/search-archive-fn4wy8sx.js +24 -0
  92. package/dist/v2/{search-n8wqxb1j.js → search-sf2vg5pk.js} +17 -16
  93. package/dist/v2/{send-session-notification-8ghn9tnv.js → send-session-notification-hmr7q0nt.js} +2 -2
  94. package/dist/v2/{server-k2bzedxk.js → server-00hx04yn.js} +1 -1
  95. package/dist/v2/{server-atbc19ab.js → server-0mzjjw3s.js} +7 -5
  96. package/dist/v2/{server-ehyava47.js → server-1hcbw661.js} +3 -3
  97. package/dist/v2/{server-th4y11y7.js → server-271qxsf5.js} +6 -6
  98. package/dist/v2/{server-prg55b7k.js → server-6714jebr.js} +22 -2
  99. package/dist/v2/{server-dd0tz6cn.js → server-6fyp0v67.js} +26 -24
  100. package/dist/v2/{server-yrvqaswb.js → server-785mb90s.js} +21 -10
  101. package/dist/v2/{server-ef89gdsx.js → server-aavz8pm6.js} +3 -3
  102. package/dist/v2/{server-gvkm8xaj.js → server-e3ftpk7v.js} +1 -1
  103. package/dist/v2/{server-e298hswg.js → server-g59aatsz.js} +14 -14
  104. package/dist/v2/{server-g10mdym6.js → server-gha9x4qq.js} +1 -1
  105. package/dist/v2/{server-4gn3z5an.js → server-hgg55hde.js} +1 -1
  106. package/dist/v2/server-kaqs6h31.js +58 -0
  107. package/dist/v2/{server-qhfvvfxj.js → server-kqpawe1a.js} +3 -3
  108. package/dist/v2/{server-hek6z3w6.js → server-kr2kc9dz.js} +5 -5
  109. package/dist/v2/{server-cfbr1s2x.js → server-n5q841qn.js} +12 -63
  110. package/dist/v2/{server-kmbarfmn.js → server-r9gjxcte.js} +24 -16
  111. package/dist/v2/{server-6cdy4rc0.js → server-vgpab6rd.js} +2 -2
  112. package/dist/v2/{server-zc3e54vy.js → server-y5pznjt9.js} +1 -1
  113. package/dist/v2/server-zyw55ygv.js +96 -0
  114. package/dist/v2/server.js +4 -4
  115. package/dist/v2/{storage-tags-hcc2adpf.js → storage-tags-hkwtbp3g.js} +1 -1
  116. package/dist/v2/{wrapup-orchestrator-65pwye0d.js → wrapup-orchestrator-x4xj1782.js} +18 -18
  117. package/dist/{wrapup-orchestrator-28xzsj5q.js → wrapup-orchestrator-vj2tbp22.js} +18 -18
  118. package/package.json +1 -1
  119. package/src/config/schema/magic-context.ts +14 -6
  120. package/src/shared/model-resolution.test.ts +22 -0
  121. package/src/shared/model-suggestion-retry.ts +9 -3
  122. package/src/shared/resolve-fallbacks.test.ts +2 -3
  123. package/src/shared/resolve-fallbacks.ts +3 -3
@@ -10,9 +10,8 @@ import {
10
10
  withPrivilegedWriter2
11
11
  } from "./server-wafzvyhg.js";
12
12
  import {
13
- bootQuietRemainingMs,
14
13
  scheduleAfterBootQuiet
15
- } from "./server-gvkm8xaj.js";
14
+ } from "./server-e3ftpk7v.js";
16
15
  import {
17
16
  getHarness2,
18
17
  harnessOwnsOpenCodeStore2
@@ -40,8 +39,8 @@ import {
40
39
  configureContextDatabasePragmas2
41
40
  } from "./server-fb3zxn06.js";
42
41
  import {
43
- startMessageFtsRowidMapBackfill
44
- } from "./server-yrvqaswb.js";
42
+ startMessageFtsRowidMapBackfill2
43
+ } from "./server-785mb90s.js";
45
44
  import {
46
45
  LKG_SLOT_CHUNKS_DDL,
47
46
  SESSION_REPLAY_DECISIONS_DDL,
@@ -51,7 +50,7 @@ import {
51
50
  hasPendingMigrations,
52
51
  getMainThreadMigrationBodyCount,
53
52
  runMigrations
54
- } from "./server-k2bzedxk.js";
53
+ } from "./server-00hx04yn.js";
55
54
  import {
56
55
  ensureColumn,
57
56
  installV95PerfSchema,
@@ -763,6 +762,8 @@ registerSlowWriteReporter2(logSlowWriteTransaction);
763
762
  registerSqliteDiagnosticSink2((message) => log2(message), getHarness2);
764
763
  var databases = new Map;
765
764
  var pendingAsyncOpens = new Map;
765
+ var pendingDatabaseCloses = new Set;
766
+ var startupBackfills = new WeakMap;
766
767
  var persistenceByDatabase = new WeakMap;
767
768
  var persistenceErrorByDatabase = new WeakMap;
768
769
  var pathByDatabase = new WeakMap;
@@ -1200,8 +1201,14 @@ function finishDatabaseOpen(db, dbPath, explicitDbPath, latestSupportedVersion)
1200
1201
  healWedgedChannel2Claims(db);
1201
1202
  if (!explicitDbPath) {
1202
1203
  const readsOpenCodeStore = harnessOwnsOpenCodeStore2();
1204
+ const state = { controller: new AbortController };
1205
+ startupBackfills.set(db, state);
1206
+ const { signal } = state.controller;
1203
1207
  let busyRetryMs = 100;
1204
1208
  const runBackfills = () => withoutSqliteTransformPass2(() => withSqliteBackgroundWriter2(() => {
1209
+ state.timer = undefined;
1210
+ if (signal.aborted)
1211
+ return;
1205
1212
  if (readsOpenCodeStore) {
1206
1213
  try {
1207
1214
  runToolOwnerBackfill(db);
@@ -1209,19 +1216,23 @@ function finishDatabaseOpen(db, dbPath, explicitDbPath, latestSupportedVersion)
1209
1216
  log2(`[magic-context] tool-owner backfill failed (continuing with lazy adoption fallback): ${getErrorMessage(error)}`);
1210
1217
  }
1211
1218
  }
1212
- startMessageFtsRowidMapBackfill(db).then(async () => {
1213
- if (!readsOpenCodeStore)
1219
+ state.running = startMessageFtsRowidMapBackfill2(db, signal).then(async () => {
1220
+ if (signal.aborted || !readsOpenCodeStore)
1221
+ return;
1222
+ const { readRawSessionMessagePage, readRawSessionMessages } = await importPluginModule(() => import("./read-session-chunk-7bpygfv2.js"));
1223
+ const { startMessageTimeBackfill } = await importPluginModule(() => import("./message-time-backfill-q5pgxf0d.js"));
1224
+ if (signal.aborted)
1214
1225
  return;
1215
- const { readRawSessionMessagePage, readRawSessionMessages } = await importPluginModule(() => import("./read-session-chunk-rq9nx1nn.js"));
1216
- const { startMessageTimeBackfill } = await importPluginModule(() => import("./message-time-backfill-bsteyc4d.js"));
1217
1226
  await startMessageTimeBackfill(db, Object.assign(readRawSessionMessages, {
1218
1227
  readPage: readRawSessionMessagePage
1219
- }));
1228
+ }), signal);
1220
1229
  }).catch((error) => {
1230
+ if (signal.aborted)
1231
+ return;
1221
1232
  if (isTransientSqliteError2(error)) {
1222
1233
  withoutSqliteTransformPass2(() => {
1223
- const timer = setTimeout(runBackfills, busyRetryMs);
1224
- timer.unref();
1234
+ state.timer = setTimeout(runBackfills, busyRetryMs);
1235
+ state.timer.unref?.();
1225
1236
  });
1226
1237
  busyRetryMs = Math.min(30000, busyRetryMs * 2);
1227
1238
  return;
@@ -1229,10 +1240,7 @@ function finishDatabaseOpen(db, dbPath, explicitDbPath, latestSupportedVersion)
1229
1240
  log2(`[magic-context] message-index backfill failed (will resume next startup): ${getErrorMessage(error)}`);
1230
1241
  });
1231
1242
  }));
1232
- if (bootQuietRemainingMs() > 0)
1233
- scheduleAfterBootQuiet(runBackfills);
1234
- else
1235
- runBackfills();
1243
+ state.timer = scheduleAfterBootQuiet(runBackfills);
1236
1244
  }
1237
1245
  setDatabase(db);
1238
1246
  loadToolDefinitionMeasurements(db);
@@ -14,10 +14,10 @@ import {
14
14
  } from "./server-f2xf5gcb.js";
15
15
  import {
16
16
  managedAuthorityNoteRow
17
- } from "./server-k2bzedxk.js";
17
+ } from "./server-00hx04yn.js";
18
18
  import {
19
19
  embedTextForProject2
20
- } from "./server-hek6z3w6.js";
20
+ } from "./server-kr2kc9dz.js";
21
21
  import {
22
22
  saveEmbeddingIfHashMatches
23
23
  } from "./server-4dhv7mqz.js";
@@ -11,7 +11,7 @@ import {
11
11
  PER_HARNESS_MODEL_KEYS,
12
12
  ConfigProfilesSchema,
13
13
  MagicContextConfigSchema
14
- } from "./server-th4y11y7.js";
14
+ } from "./server-271qxsf5.js";
15
15
  import {
16
16
  isCompactionEnabled,
17
17
  migrateLegacyAgentEnabledInMemory
@@ -0,0 +1,96 @@
1
+ import {
2
+ withMessageFtsSessionFilter
3
+ } from "./server-kaqs6h31.js";
4
+ import {
5
+ getSqliteDatabasePath2
6
+ } from "./server-wafzvyhg.js";
7
+ import {
8
+ runSessionWarmupWorker
9
+ } from "./server-6714jebr.js";
10
+ import {
11
+ estimateTokens
12
+ } from "./server-0ppsweh6.js";
13
+ import {
14
+ openCodeDbExists,
15
+ withReadOnlySessionDb
16
+ } from "./server-d8tj10db.js";
17
+ import {
18
+ hasRawMessageProvider2,
19
+ readRawSessionMessageIdOrdinalsForRange2
20
+ } from "./server-1hcbw661.js";
21
+
22
+ // src/tools/ctx-expand/search-archive.ts
23
+ var archiveReadsOnThisThread = 0;
24
+ function renderSearchArchive2(db, sessionId, start, end, tokenBudget, archiveOnly = false, readRawIds = () => readRawSessionMessageIdOrdinalsForRange2(sessionId, start, end)) {
25
+ archiveReadsOnThisThread += 1;
26
+ return withMessageFtsSessionFilter(db, sessionId, (sessionFirst) => {
27
+ let rawIds;
28
+ const rows = db.prepare(sessionFirst ? `SELECT f.message_ordinal AS ordinal, f.message_id AS id, f.role, f.content
29
+ FROM message_fts_rowid_map AS m
30
+ JOIN message_history_fts AS f ON f.rowid = m.fts_rowid
31
+ WHERE m.session_id = ?1 AND m.message_ordinal BETWEEN ?2 AND ?3
32
+ AND f.session_id = ?1 AND f.message_ordinal BETWEEN ?2 AND ?3
33
+ ORDER BY m.message_ordinal` : `SELECT message_ordinal AS ordinal, message_id AS id, role, content
34
+ FROM message_history_fts
35
+ WHERE session_id = ?1 AND message_ordinal BETWEEN ?2 AND ?3
36
+ ORDER BY CAST(message_ordinal AS INTEGER)`);
37
+ const blocks = [];
38
+ let tokens = 0;
39
+ let lastOrdinal = start - 1;
40
+ let truncated = false;
41
+ for (const row of rows.iterate(sessionId, start, end)) {
42
+ if (!row.content)
43
+ continue;
44
+ if (!archiveOnly) {
45
+ rawIds ??= readRawIds();
46
+ if (rawIds.get(row.id) === row.ordinal)
47
+ continue;
48
+ }
49
+ const block = `[${row.ordinal}] ${row.role === "user" ? "U" : "A"}: ${row.content}`;
50
+ const cost = estimateTokens(block);
51
+ if (blocks.length > 0 && tokens + cost > tokenBudget) {
52
+ truncated = true;
53
+ break;
54
+ }
55
+ blocks.push(block);
56
+ tokens += cost;
57
+ lastOrdinal = row.ordinal;
58
+ }
59
+ if (blocks.length === 0)
60
+ return null;
61
+ const text = [
62
+ "From the search archive: indexed text only; no surrounding messages or tool output.",
63
+ "",
64
+ ...blocks
65
+ ];
66
+ if (truncated) {
67
+ text.push("", `Truncated at message ${lastOrdinal} (budget: ~${tokenBudget} tokens). Call ctx_expand(start=${lastOrdinal + 1}, end=${end}) for more archived text.`);
68
+ }
69
+ return text.join(`
70
+ `);
71
+ });
72
+ }
73
+ async function renderSearchArchiveOffThread2(db, sessionId, start, end, tokenBudget, archiveOnly = false) {
74
+ const path = getSqliteDatabasePath2(db);
75
+ if (!path)
76
+ return renderSearchArchive2(db, sessionId, start, end, tokenBudget, archiveOnly);
77
+ const provider = hasRawMessageProvider2(sessionId);
78
+ const rawPath = !archiveOnly && !provider && openCodeDbExists() ? withReadOnlySessionDb(getSqliteDatabasePath2) : null;
79
+ const result = await runSessionWarmupWorker({
80
+ path,
81
+ sessionId,
82
+ searchArchive: {
83
+ start,
84
+ end,
85
+ tokenBudget,
86
+ archiveOnly,
87
+ rawPath,
88
+ rawIds: !archiveOnly && provider ? [...readRawSessionMessageIdOrdinalsForRange2(sessionId, start, end)] : undefined
89
+ }
90
+ }, {});
91
+ if ("searchArchive" in result)
92
+ return result.searchArchive;
93
+ throw new Error(`Search archive worker unavailable: ${"failure" in result ? `${result.failure}: ${result.detail}` : "unexpected reply"}`);
94
+ }
95
+
96
+ export { renderSearchArchive2, renderSearchArchiveOffThread2 };
package/dist/v2/server.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  loadPluginConfigDetailed
3
- } from "./server-zc3e54vy.js";
3
+ } from "./server-y5pznjt9.js";
4
4
  import {
5
5
  setHarness2
6
6
  } from "./server-pavzsdc6.js";
@@ -21,7 +21,7 @@ import {
21
21
  union,
22
22
  tuple,
23
23
  record
24
- } from "./server-th4y11y7.js";
24
+ } from "./server-271qxsf5.js";
25
25
  import {
26
26
  pushNotification2
27
27
  } from "./server-x8a7jmkh.js";
@@ -7874,7 +7874,7 @@ var require_src2 = __commonJS(function(exports, module) {
7874
7874
  // package.json
7875
7875
  var package_default = {
7876
7876
  name: "@cortexkit/opencode-magic-context",
7877
- version: "0.49.15",
7877
+ version: "0.49.16",
7878
7878
  type: "module",
7879
7879
  description: "OpenCode plugin for Magic Context — cross-session memory and context management",
7880
7880
  main: "dist/index.js",
@@ -8195,7 +8195,7 @@ async function setup(context) {
8195
8195
  if (claimStorageBackupWarningCheck() && isMagicContextStorageOutsideEngram(storageDir)) {
8196
8196
  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.`);
8197
8197
  }
8198
- const { registerContext } = await import("./context-4qczzck7.js");
8198
+ const { registerContext } = await import("./context-acw1nhv8.js");
8199
8199
  setHarness2("opencode2");
8200
8200
  bindStaleBuildNotice({}, import.meta.url, "opencode2");
8201
8201
  const duties = await registerContext(context);
@@ -61,7 +61,7 @@ import {
61
61
  adoptNullOwnerToolTag2,
62
62
  getCandidateToolOwners2,
63
63
  pickNearestPriorOwner2
64
- } from "./server-atbc19ab.js";
64
+ } from "./server-0mzjjw3s.js";
65
65
  import"./server-1zx87sdm.js";
66
66
  import"./server-pwv4ezb0.js";
67
67
  import"./server-0ppsweh6.js";
@@ -19,16 +19,18 @@ import {
19
19
  registerActiveCompartmentRun,
20
20
  setRecompStarting2,
21
21
  setRecompTerminal2
22
- } from "./server-dd0tz6cn.js";
23
- import"./server-hek6z3w6.js";
22
+ } from "./server-6fyp0v67.js";
23
+ import"./server-kr2kc9dz.js";
24
24
  import"./server-0ppsweh6.js";
25
25
  import"./server-rrqpvwqd.js";
26
26
  import {
27
27
  inRootAsyncContext2
28
28
  } from "./server-wafzvyhg.js";
29
- import"./server-yrvqaswb.js";
30
- import"./server-qhfvvfxj.js";
31
- import"./server-e298hswg.js";
29
+ import"./server-51779zs2.js";
30
+ import"./server-6714jebr.js";
31
+ import"./server-785mb90s.js";
32
+ import"./server-kqpawe1a.js";
33
+ import"./server-g59aatsz.js";
32
34
  import {
33
35
  getWrapupInProgressState,
34
36
  acquireWrapupInProgress,
@@ -37,33 +39,31 @@ import {
37
39
  getHistorianFailureState,
38
40
  clearEmergencyRecovery,
39
41
  prepareRawSessionOrdinals2
40
- } from "./server-ehyava47.js";
42
+ } from "./server-1hcbw661.js";
41
43
  import"./server-pwv4ezb0.js";
42
- import"./server-kmbarfmn.js";
44
+ import"./server-r9gjxcte.js";
43
45
  import"./server-1zx87sdm.js";
44
- import"./server-atbc19ab.js";
45
- import"./server-th4y11y7.js";
46
- import"./server-51779zs2.js";
47
- import"./server-prg55b7k.js";
46
+ import"./server-0mzjjw3s.js";
47
+ import"./server-271qxsf5.js";
48
48
  import"./server-2ra6pwf3.js";
49
49
  import"./server-d8tj10db.js";
50
50
  import"./server-zs8d0s3b.js";
51
51
  import"./server-fr0wbhdn.js";
52
- import"./server-k2bzedxk.js";
53
- import"./server-gvkm8xaj.js";
52
+ import"./server-00hx04yn.js";
53
+ import"./server-e3ftpk7v.js";
54
54
  import"./server-fb3zxn06.js";
55
- import"./server-6cdy4rc0.js";
55
+ import"./server-vgpab6rd.js";
56
56
  import {
57
57
  pushNotification2
58
58
  } from "./server-x8a7jmkh.js";
59
59
  import"./server-05xjtq6c.js";
60
60
  import"./server-qt1qqasc.js";
61
- import"./server-4gn3z5an.js";
61
+ import"./server-hgg55hde.js";
62
62
  import"./server-4dhv7mqz.js";
63
- import"./server-g10mdym6.js";
64
- import"./server-ef89gdsx.js";
63
+ import"./server-gha9x4qq.js";
64
+ import"./server-aavz8pm6.js";
65
65
  import"./server-n78avt2p.js";
66
- import"./server-zc3e54vy.js";
66
+ import"./server-y5pznjt9.js";
67
67
  import"./server-tbe1femw.js";
68
68
  import"./server-34kwfsr4.js";
69
69
  import"./server-h0410h0v.js";
@@ -1,42 +1,42 @@
1
1
  import {
2
2
  runManagedWrapup2
3
- } from "./index-mc1cqza6.js";
4
- import"./index-1vc7jrkg.js";
5
- import"./index-snp5wbge.js";
3
+ } from "./index-v9asb16b.js";
4
+ import"./index-v63beg1z.js";
5
+ import"./index-ayym1x7f.js";
6
6
  import"./index-f71thw8j.js";
7
- import"./index-bxdg2nbt.js";
8
- import"./index-thvnpfsv.js";
7
+ import"./index-wv9n2zcq.js";
8
+ import"./index-p4vde22c.js";
9
9
  import"./index-sd3egckz.js";
10
- import"./index-3kdm78zp.js";
11
- import"./index-y1qysm3q.js";
10
+ import"./index-9nkg2dzk.js";
11
+ import"./index-qrahzcqv.js";
12
12
  import"./index-n78avt2p.js";
13
13
  import"./index-4dhv7mqz.js";
14
14
  import"./index-v10f1rjv.js";
15
- import"./index-dgs16axy.js";
15
+ import"./index-b17m64g9.js";
16
16
  import"./index-qt1qqasc.js";
17
- import"./index-944w16m0.js";
18
- import"./index-mht7bq0z.js";
17
+ import"./index-j6zw70pf.js";
18
+ import"./index-nd7m2a5a.js";
19
19
  import"./index-1zx87sdm.js";
20
- import"./index-1d289pq2.js";
21
- import"./index-mmfa86mt.js";
22
- import"./index-v0p37hm2.js";
20
+ import"./index-mtw9e71a.js";
23
21
  import"./index-x8a7jmkh.js";
24
22
  import"./index-y9f76s3f.js";
25
- import"./index-e20m7284.js";
26
- import"./index-1sarmj9z.js";
23
+ import"./index-7b2cfmaz.js";
24
+ import"./index-wgypt3cs.js";
27
25
  import"./index-saews2s3.js";
28
- import"./index-3kx0kg0f.js";
26
+ import"./index-hehkf6zm.js";
29
27
  import"./index-fkx2qnvw.js";
30
- import"./index-yxycg7fs.js";
28
+ import"./index-cj9g0j7a.js";
31
29
  import"./index-fb3zxn06.js";
32
30
  import"./index-wk0n1cgt.js";
33
31
  import"./index-a8bvhwqs.js";
34
- import"./index-dyvbsvga.js";
32
+ import"./index-dqe8pq4x.js";
35
33
  import"./index-fr0wbhdn.js";
36
34
  import"./index-nj7yykkx.js";
37
35
  import"./index-n6m03s3n.js";
38
36
  import"./index-bp5083x2.js";
39
37
  import"./index-58e3y90n.js";
38
+ import"./index-7pa32z07.js";
39
+ import"./index-v0p37hm2.js";
40
40
  import"./index-k29z4aqh.js";
41
41
  import"./index-hqkczed7.js";
42
42
  import"./index-wafzvyhg.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cortexkit/opencode-magic-context",
3
- "version": "0.49.15",
3
+ "version": "0.49.16",
4
4
  "type": "module",
5
5
  "description": "OpenCode plugin for Magic Context — cross-session memory and context management",
6
6
  "main": "dist/index.js",
@@ -205,12 +205,14 @@ export type OmpEntry = z.infer<typeof OmpEntrySchema>;
205
205
  /** Strict model-resolution block used by historian.opencode. */
206
206
  export const OpenCodeHarnessBlockSchema = z
207
207
  .object({
208
- model: OcEntrySchema.optional().describe("Primary OpenCode model entry."),
208
+ model: OcEntrySchema.optional().describe(
209
+ "Primary historian OpenCode model entry. When set, only this model and fallback_models are used; exhaustion reports failure, never the session model. When absent, OpenCode inherits the session model.",
210
+ ),
209
211
  fallback_models: z
210
212
  .array(OcEntrySchema)
211
213
  .optional()
212
214
  .describe(
213
- "Ordered fallback OpenCode entries. New-shape configuration requires an array; legacy singleton values migrate to a one-element array.",
215
+ "Ordered historian fallback OpenCode entries. A configured primary never adds the session model after this list. Requires an array; legacy singleton values migrate to a one-element array.",
214
216
  ),
215
217
  variant: z
216
218
  .string()
@@ -226,12 +228,14 @@ export type OpenCodeHarnessBlock = z.infer<typeof OpenCodeHarnessBlockSchema>;
226
228
  /** Strict model-resolution block used by historian.pi. */
227
229
  export const PiHarnessBlockSchema = z
228
230
  .object({
229
- model: PiEntrySchema.optional().describe("Primary Pi model entry."),
231
+ model: PiEntrySchema.optional().describe(
232
+ "Primary historian Pi model entry. When set, only this model and fallback_models are used; exhaustion reports failure, never the session model. When absent, Pi does not run the historian.",
233
+ ),
230
234
  fallback_models: z
231
235
  .array(PiEntrySchema)
232
236
  .optional()
233
237
  .describe(
234
- "Ordered fallback Pi entries. New-shape configuration requires an array; legacy singleton values migrate to a one-element array.",
238
+ "Ordered historian fallback Pi entries. The session model is never appended. Requires an array; legacy singleton values migrate to a one-element array.",
235
239
  ),
236
240
  thinking_level: PiThinkingLevelSchema.describe(
237
241
  "Pi thinking level for the primary entry when it declares none. Fallback entries declare thinking levels per-entry.",
@@ -244,11 +248,15 @@ export type PiHarnessBlock = z.infer<typeof PiHarnessBlockSchema>;
244
248
  /** Strict model-resolution block used by historian.omp. */
245
249
  export const OmpHarnessBlockSchema = z
246
250
  .object({
247
- model: OmpEntrySchema.optional().describe("Primary OMP model entry."),
251
+ model: OmpEntrySchema.optional().describe(
252
+ "Primary historian OMP model entry. When set, only this model and fallback_models are used; exhaustion reports failure, never the session model. An absent OMP block inherits the Pi block; a selected block without a model does not run the historian.",
253
+ ),
248
254
  fallback_models: z
249
255
  .array(OmpEntrySchema)
250
256
  .optional()
251
- .describe("Ordered fallback OMP entries."),
257
+ .describe(
258
+ "Ordered historian fallback OMP entries. The session model is never appended.",
259
+ ),
252
260
  thinking_level: OmpThinkingLevelSchema.describe(
253
261
  "OMP thinking level for the primary entry when it declares none. Fallback entries declare thinking levels per-entry.",
254
262
  ),
@@ -1,4 +1,5 @@
1
1
  import { describe, expect, test } from "bun:test";
2
+ import { parsePluginConfig } from "../config";
2
3
 
3
4
  import {
4
5
  normalizeModelEntry,
@@ -9,6 +10,27 @@ import {
9
10
  } from "./model-resolution";
10
11
 
11
12
  describe("model-resolution", () => {
13
+ test("loader defaults and historian metadata do not configure a primary model", () => {
14
+ for (const harness of ["opencode", "pi", "omp"] as const) {
15
+ for (const input of [
16
+ {},
17
+ { historian: {} },
18
+ { historian: { temperature: 0, [harness]: {} } },
19
+ ]) {
20
+ expect(
21
+ resolveHistorianModel(parsePluginConfig(input), harness).primary,
22
+ ).toBeUndefined();
23
+ }
24
+ for (const model of [" provider/explicit ", { model: "provider/explicit" }]) {
25
+ expect(
26
+ resolveHistorianModel(
27
+ parsePluginConfig({ historian: { [harness]: { model } } }),
28
+ harness,
29
+ ).primary?.model,
30
+ ).toBe("provider/explicit");
31
+ }
32
+ }
33
+ });
12
34
  test("keeps historian temperature opt-in while preserving explicit overrides", () => {
13
35
  const fixtures = [
14
36
  { temperature: undefined, expected: undefined },
@@ -72,6 +72,8 @@ export interface PromptAttemptInfo {
72
72
  export interface PromptRetryOptions {
73
73
  transport?: PromptTransport;
74
74
  timeoutMs?: number;
75
+ /** False for callers whose configured model chain must not accept provider suggestions. Defaults to true. */
76
+ allowModelSuggestions?: boolean;
75
77
  /** External abort signal — cancels the in-flight LLM prompt immediately when aborted */
76
78
  signal?: AbortSignal;
77
79
  /**
@@ -508,6 +510,7 @@ async function attemptOnce(
508
510
  callContext: string,
509
511
  label: string,
510
512
  transport?: PromptTransport,
513
+ allowModelSuggestions = true,
511
514
  ): Promise<void> {
512
515
  // Keep this snapshot separate from the object passed to the client. A
513
516
  // failed prompt facade may rewrite its request body before rejecting; the
@@ -518,9 +521,9 @@ async function attemptOnce(
518
521
  await promptWithTimeout(client, attemptArgs, timeoutMs, signal, transport);
519
522
  return;
520
523
  } catch (error) {
521
- // If non-retryable (abort, overflow, timeout), bubble up immediately.
522
- // Don't even try suggestion retry — caller needs the original error.
523
- if (isNonRetryable(error, signal)) throw error;
524
+ // Non-retryable failures and callers with model suggestions disabled
525
+ // must surface the original error without accepting a provider suggestion.
526
+ if (isNonRetryable(error, signal) || !allowModelSuggestions) throw error;
524
527
 
525
528
  const suggestion = parseModelSuggestion(error);
526
529
  if (!suggestion || !originalBody.model) {
@@ -596,6 +599,7 @@ export async function promptSyncWithModelSuggestionRetry(
596
599
  callContext,
597
600
  explicitPrimaryLabel,
598
601
  options.transport,
602
+ options.allowModelSuggestions,
599
603
  );
600
604
  return;
601
605
  } catch (error) {
@@ -640,6 +644,7 @@ export async function promptSyncWithModelSuggestionRetry(
640
644
  callContext,
641
645
  label,
642
646
  options.transport,
647
+ options.allowModelSuggestions,
643
648
  );
644
649
  log(
645
650
  `[${callContext}] fallback succeeded with ${label} (attempt ${i + 2}/${fallbacks.length + 1})`,
@@ -685,6 +690,7 @@ async function attemptAndValidate<TOutput, TValidated>(
685
690
  callContext,
686
691
  attempt.label,
687
692
  options.transport,
693
+ options.allowModelSuggestions,
688
694
  );
689
695
  } catch (error) {
690
696
  throw {
@@ -4,9 +4,8 @@ import { modelBodyField, parseProviderModel, resolveFallbackChain } from "./reso
4
4
 
5
5
  describe("resolveFallbackChain", () => {
6
6
  // Policy: user-config-only. There is NO builtin provider-agnostic chain —
7
- // when the user configures no fallback_models the result is EMPTY, and the
8
- // runner's session-model last resort (a model the user actually has) is the
9
- // only fallback. A hardcoded chain named providers the user may not have and
7
+ // when the user configures no fallback_models the result is empty.
8
+ // A hardcoded chain named providers the user may not have and
10
9
  // produced `Model not found` retry storms.
11
10
  test("returns empty when user provides nothing (no builtin chain)", () => {
12
11
  expect(resolveFallbackChain(undefined)).toEqual([]);
@@ -9,9 +9,9 @@ import type { ModelInput, ResolvedModelEntry } from "./model-resolution";
9
9
  * inevitably names providers the user doesn't have (e.g. a metapi-only user got
10
10
  * a chain of google/github-copilot/opencode entries, every one a
11
11
  * `Model not found` retry), which produced confusing errors and wasted
12
- * attempts. If the user configured nothing, this returns an empty list and the
13
- * runner's session-model last resort (the model the user is actually using) is
14
- * the only fallback.
12
+ * attempts. If the user configured no alternates, this returns an empty list.
13
+ * A configured historian never adds the session model to this list; only an
14
+ * unconfigured OpenCode historian inherits the session model.
15
15
  *
16
16
  * The returned list does NOT include the primary model — it's the ordered list
17
17
  * of *alternates* to try after the primary fails. Each entry is