@cortexkit/opencode-magic-context 0.49.20 → 0.49.21

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 (188) hide show
  1. package/dist/auto-search-worker.js +6 -6
  2. package/dist/chunk-embedding-write-worker.js +9 -9
  3. package/dist/{compaction-marker-candidates-b2q30cft.js → compaction-marker-candidates-31h86ph0.js} +2 -2
  4. package/dist/compaction-marker-candidates-worker.js +2 -2
  5. package/dist/{compartment-chunk-embedding-va090as0.js → compartment-chunk-embedding-he60aaa2.js} +5 -5
  6. package/dist/config/project-security.d.ts.map +1 -1
  7. package/dist/config/schema/magic-context.d.ts +37 -3
  8. package/dist/config/schema/magic-context.d.ts.map +1 -1
  9. package/dist/{conflict-warning-hook-frp3z2wk.js → conflict-warning-hook-2r32hyx6.js} +5 -5
  10. package/dist/{context-mkece1db.js → context-j7hp43a0.js} +153 -83
  11. package/dist/{embedding-backfill-gy3p78py.js → embedding-backfill-dtke6tck.js} +11 -11
  12. package/dist/embedding-worker-process.js +1 -1
  13. package/dist/embedding-worker.js +4 -4
  14. package/dist/features/magic-context/dreamer/docs-proposals.d.ts +1 -0
  15. package/dist/features/magic-context/dreamer/docs-proposals.d.ts.map +1 -1
  16. package/dist/features/magic-context/dreamer/task-executor.d.ts.map +1 -1
  17. package/dist/features/magic-context/memory/embedding-synapse.d.ts.map +1 -1
  18. package/dist/features/magic-context/memory/embedding-worker-client.d.ts +7 -1
  19. package/dist/features/magic-context/memory/embedding-worker-client.d.ts.map +1 -1
  20. package/dist/features/magic-context/message-index-async.d.ts +7 -2
  21. package/dist/features/magic-context/message-index-async.d.ts.map +1 -1
  22. package/dist/features/magic-context/project-embedding-registry.d.ts +2 -0
  23. package/dist/features/magic-context/project-embedding-registry.d.ts.map +1 -1
  24. package/dist/features/magic-context/search-rerank.d.ts +9 -2
  25. package/dist/features/magic-context/search-rerank.d.ts.map +1 -1
  26. package/dist/features/magic-context/search.d.ts +2 -0
  27. package/dist/features/magic-context/search.d.ts.map +1 -1
  28. package/dist/features/magic-context/storage-db.d.ts +2 -0
  29. package/dist/features/magic-context/storage-db.d.ts.map +1 -1
  30. package/dist/features/magic-context/storage-meta-persisted.d.ts +1 -0
  31. package/dist/features/magic-context/storage-meta-persisted.d.ts.map +1 -1
  32. package/dist/hooks/magic-context/auto-search-worker-client.d.ts.map +1 -1
  33. package/dist/hooks/magic-context/cache-busting-signals.d.ts +1 -0
  34. package/dist/hooks/magic-context/cache-busting-signals.d.ts.map +1 -1
  35. package/dist/hooks/magic-context/hook.d.ts.map +1 -1
  36. package/dist/hooks/magic-context/served-shape-repair.d.ts +19 -0
  37. package/dist/hooks/magic-context/served-shape-repair.d.ts.map +1 -0
  38. package/dist/hooks/magic-context/strip-content.d.ts +4 -2
  39. package/dist/hooks/magic-context/strip-content.d.ts.map +1 -1
  40. package/dist/hooks/magic-context/tag-content-primitives.d.ts +1 -1
  41. package/dist/hooks/magic-context/tag-content-primitives.d.ts.map +1 -1
  42. package/dist/hooks/magic-context/tag-messages.d.ts +2 -1
  43. package/dist/hooks/magic-context/tag-messages.d.ts.map +1 -1
  44. package/dist/hooks/magic-context/text-complete.d.ts +1 -1
  45. package/dist/hooks/magic-context/text-complete.d.ts.map +1 -1
  46. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
  47. package/dist/hooks/magic-context/transform.d.ts +2 -2
  48. package/dist/hooks/magic-context/transform.d.ts.map +1 -1
  49. package/dist/{index-t7hx3qcb.js → index-11gzxvf4.js} +101 -46
  50. package/dist/{index-neb2jaed.js → index-1gtfne2c.js} +1 -1
  51. package/dist/{index-67nyj0gy.js → index-1kbznkft.js} +48 -24
  52. package/dist/{index-1pefp8ar.js → index-3svaejkh.js} +4 -4
  53. package/dist/{index-0wthn7fp.js → index-51rdvtkz.js} +35 -4
  54. package/dist/{index-kc9pn495.js → index-66eby7hx.js} +1 -1
  55. package/dist/{index-pnjwa6qa.js → index-9q1g3c5q.js} +2 -2
  56. package/dist/{index-rmd0069m.js → index-a9zvn5fe.js} +24 -10
  57. package/dist/{index-jfh3cktr.js → index-ffzhwfzy.js} +3 -3
  58. package/dist/{v2/server-1zx2pa5d.js → index-gzy5w8ya.js} +193 -4
  59. package/dist/{index-d6rp4dxh.js → index-j32jj2t8.js} +4 -4
  60. package/dist/{index-35qc6606.js → index-jfem3dgz.js} +1 -1
  61. package/dist/{index-y4a3nhtk.js → index-jjvbk92s.js} +1 -1
  62. package/dist/{index-4n7w9rad.js → index-jmq8kfe7.js} +5 -5
  63. package/dist/{index-c4b76d4t.js → index-kfyb3k6n.js} +1 -1
  64. package/dist/{index-vkc1ca9p.js → index-kq5w68dp.js} +1 -1
  65. package/dist/{index-11zf2wwc.js → index-ksq50rg0.js} +2 -2
  66. package/dist/{index-153r2q6z.js → index-m32esgmj.js} +2 -2
  67. package/dist/{index-x4k3f4mf.js → index-mnhcdfxg.js} +148 -8
  68. package/dist/{index-48stjd56.js → index-mnnkgq0q.js} +10 -4
  69. package/dist/{index-wgypt3cs.js → index-nxrsns5x.js} +2466 -1290
  70. package/dist/{index-616rsjrv.js → index-qgh1qwjj.js} +1 -1
  71. package/dist/{index-jr5na10t.js → index-rxqr723x.js} +4 -4
  72. package/dist/{index-dc8hy95c.js → index-syaazvy2.js} +123 -40
  73. package/dist/{index-adk2z5d8.js → index-wfybj1dw.js} +2 -4
  74. package/dist/{index-305y133n.js → index-whcgcfrv.js} +6 -3
  75. package/dist/{index-jmycsey7.js → index-x6cbrv9h.js} +2 -2
  76. package/dist/{index-v7r4td4c.js → index-y76rhsnr.js} +28 -17
  77. package/dist/{index-2yhtnfcf.js → index-zy67whjr.js} +26 -8
  78. package/dist/index.js +43 -42
  79. package/dist/{message-fts-rowid-map-22tevnnj.js → message-fts-rowid-map-e79b7b6x.js} +3 -3
  80. package/dist/{message-index-5qxcz6h7.js → message-index-4q8ek2fc.js} +10 -10
  81. package/dist/{message-index-bounded-n0m0t7tv.js → message-index-bounded-rydsg9r5.js} +10 -10
  82. package/dist/{message-time-backfill-0myx7fz3.js → message-time-backfill-4qva0b4f.js} +1 -1
  83. package/dist/migration-worker.js +6 -6
  84. package/dist/plugin/embedding-bootstrap.d.ts +1 -0
  85. package/dist/plugin/embedding-bootstrap.d.ts.map +1 -1
  86. package/dist/plugin/hooks/create-session-hooks.d.ts +1 -0
  87. package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
  88. package/dist/plugin/tool-registry.d.ts.map +1 -1
  89. package/dist/{project-embedding-registry-s2pqgec9.js → project-embedding-registry-hn529988.js} +12 -10
  90. package/dist/raw-ordinal-warmup-worker.js +8 -8
  91. package/dist/{read-session-chunk-0a8vdyqp.js → read-session-chunk-t039f0m5.js} +6 -6
  92. package/dist/{read-session-raw-y5cszf0b.js → read-session-raw-aw6jgvwg.js} +2 -2
  93. package/dist/{recomp-orchestrator-61vyha9j.js → recomp-orchestrator-hbm53jj5.js} +23 -23
  94. package/dist/{search-archive-8q9s49p5.js → search-archive-weh164mh.js} +7 -7
  95. package/dist/{search-v1y9ejws.js → search-hea079d7.js} +19 -19
  96. package/dist/{send-session-notification-0k6qzydk.js → send-session-notification-gqzkz7da.js} +4 -4
  97. package/dist/shared/sqlite.d.ts +5 -0
  98. package/dist/shared/sqlite.d.ts.map +1 -1
  99. package/dist/shared/tag-transcript.d.ts +2 -0
  100. package/dist/shared/tag-transcript.d.ts.map +1 -1
  101. package/dist/{sqlite-1rpvw2rj.js → sqlite-zdgm52sv.js} +5 -1
  102. package/dist/{storage-memory-nm7v82mj.js → storage-memory-e6a7mb0k.js} +2 -2
  103. package/dist/{storage-tags-r6nk29n4.js → storage-tags-a77q4v77.js} +2 -2
  104. package/dist/tools/ctx-search/tools.d.ts.map +1 -1
  105. package/dist/tools/ctx-search/types.d.ts +1 -0
  106. package/dist/tools/ctx-search/types.d.ts.map +1 -1
  107. package/dist/{transform-postprocess-phase-vtrgb7m6.js → transform-postprocess-phase-0b04tm1p.js} +23 -23
  108. package/dist/v2/auto-search-worker.js +6 -6
  109. package/dist/v2/chunk-embedding-write-worker.js +11 -11
  110. package/dist/v2/{compaction-marker-candidates-cfab70cs.js → compaction-marker-candidates-m4vmye3w.js} +2 -2
  111. package/dist/v2/compaction-marker-candidates-worker.js +2 -2
  112. package/dist/v2/{compartment-chunk-embedding-nbdqx1td.js → compartment-chunk-embedding-8jjmcgeg.js} +5 -5
  113. package/dist/v2/{context-cc33tv2z.js → context-ea3x7smm.js} +652 -468
  114. package/dist/v2/{embedding-backfill-yxv2h5mc.js → embedding-backfill-5e74ae0m.js} +11 -11
  115. package/dist/v2/embedding-worker-process.js +1 -1
  116. package/dist/v2/embedding-worker.js +4 -4
  117. package/dist/v2/hooks/context.d.ts.map +1 -1
  118. package/dist/v2/hooks/copied-tag-notation.d.ts +1 -1
  119. package/dist/v2/hooks/copied-tag-notation.d.ts.map +1 -1
  120. package/dist/v2/hooks/dream-timer.d.ts +2 -0
  121. package/dist/v2/hooks/dream-timer.d.ts.map +1 -1
  122. package/dist/v2/hooks/embedding-lifecycle.d.ts +7 -0
  123. package/dist/v2/hooks/embedding-lifecycle.d.ts.map +1 -0
  124. package/dist/v2/hooks/payload.d.ts.map +1 -1
  125. package/dist/v2/hooks/store.d.ts +2 -0
  126. package/dist/v2/hooks/store.d.ts.map +1 -1
  127. package/dist/v2/hooks/tools.d.ts +2 -1
  128. package/dist/v2/hooks/tools.d.ts.map +1 -1
  129. package/dist/v2/hooks/transform-features.d.ts +2 -2
  130. package/dist/v2/hooks/transform-features.d.ts.map +1 -1
  131. package/dist/v2/{message-fts-rowid-map-dg12wymk.js → message-fts-rowid-map-n8fdg2ja.js} +3 -3
  132. package/dist/v2/{message-index-bounded-f4e01xk0.js → message-index-bounded-8rcd7qq9.js} +12 -12
  133. package/dist/v2/{message-index-ydzrp6y6.js → message-index-qz9wdp82.js} +12 -12
  134. package/dist/v2/{message-time-backfill-ddh8n9gy.js → message-time-backfill-zvthw6xb.js} +1 -1
  135. package/dist/v2/migration-worker.js +8 -8
  136. package/dist/v2/{project-embedding-registry-deza9ksw.js → project-embedding-registry-v38q4xd5.js} +12 -10
  137. package/dist/v2/raw-ordinal-warmup-worker.js +8 -8
  138. package/dist/v2/{read-session-chunk-8cxfagky.js → read-session-chunk-wazfyxcg.js} +8 -8
  139. package/dist/v2/{read-session-raw-1nrrecvx.js → read-session-raw-b70cpwzj.js} +2 -2
  140. package/dist/v2/{recomp-orchestrator-47m4hv5g.js → recomp-orchestrator-b12zaptj.js} +25 -25
  141. package/dist/v2/{search-archive-e80cvc09.js → search-archive-x64rtz1z.js} +9 -9
  142. package/dist/v2/{search-fjz746zr.js → search-hza9x72a.js} +21 -21
  143. package/dist/v2/{send-session-notification-nwvrv34d.js → send-session-notification-8eqe259v.js} +4 -4
  144. package/dist/v2/{server-4sxjs6hn.js → server-132h8twc.js} +4 -4
  145. package/dist/v2/{server-271qxsf5.js → server-24g8r2d0.js} +2466 -1290
  146. package/dist/v2/{server-m91f9m5s.js → server-33nqbqkw.js} +123 -40
  147. package/dist/v2/{server-brj8j2gk.js → server-3vhxy2k5.js} +1 -1
  148. package/dist/v2/{server-55rgxfrw.js → server-4kjmrjn4.js} +1 -1
  149. package/dist/v2/{server-wyawsa88.js → server-62g58aaz.js} +2 -2
  150. package/dist/v2/{server-230fnbws.js → server-6v3cdzsx.js} +1 -1
  151. package/dist/v2/{server-ygtykank.js → server-806rzhs6.js} +1 -1
  152. package/dist/v2/{server-5arr9ecn.js → server-94wk1ey3.js} +12 -1
  153. package/dist/v2/{server-af2pght7.js → server-ab1g0wn9.js} +2 -4
  154. package/dist/v2/{server-0epqaxhd.js → server-ad18djzs.js} +26 -8
  155. package/dist/v2/{server-4nw4fqhr.js → server-bsgd4dk1.js} +1 -1
  156. package/dist/v2/{server-dj7tz4ph.js → server-d1dzgvwd.js} +1 -1
  157. package/dist/v2/{server-vn2nwcv6.js → server-d48x3m4x.js} +4 -4
  158. package/dist/v2/{server-br1x0tev.js → server-dtp8hcjh.js} +2 -2
  159. package/dist/v2/{server-a3dwxfgd.js → server-fa7vtp40.js} +7 -4
  160. package/dist/{index-1zx2pa5d.js → v2/server-gzy5w8ya.js} +193 -4
  161. package/dist/v2/{server-hqzyq8n4.js → server-j8h7bsca.js} +26 -12
  162. package/dist/v2/{server-y4a3nhtk.js → server-jjvbk92s.js} +1 -1
  163. package/dist/v2/{server-ej96a39v.js → server-m4bfaevz.js} +1186 -1046
  164. package/dist/v2/{server-63fqdghs.js → server-ppcd1qxh.js} +92 -86
  165. package/dist/v2/{server-ne8arh8t.js → server-qjvk4a9t.js} +1 -1
  166. package/dist/v2/{server-xsryvyf6.js → server-qteg2kt9.js} +4 -4
  167. package/dist/v2/{server-168pb207.js → server-rqebawx1.js} +1 -1
  168. package/dist/v2/{server-j4jnp9b5.js → server-vr4szghm.js} +35 -4
  169. package/dist/v2/{server-9x0kmta4.js → server-wwaw5npa.js} +3 -3
  170. package/dist/v2/{server-c7dxxsj7.js → server-zg5y109h.js} +33 -33
  171. package/dist/v2/server.js +6 -6
  172. package/dist/v2/{sqlite-1rpvw2rj.js → sqlite-zdgm52sv.js} +5 -1
  173. package/dist/v2/{storage-memory-nm7v82mj.js → storage-memory-e6a7mb0k.js} +2 -2
  174. package/dist/v2/{storage-tags-ss08kj5r.js → storage-tags-q71rnr9f.js} +3 -3
  175. package/dist/v2/store-reader.d.ts +2 -0
  176. package/dist/v2/store-reader.d.ts.map +1 -1
  177. package/dist/v2/{wrapup-orchestrator-639whfhq.js → wrapup-orchestrator-3ssd5yy1.js} +25 -25
  178. package/dist/wrapup-orchestrator-5vpcd1zx.js +49 -0
  179. package/package.json +2 -2
  180. package/src/config/index.test.ts +44 -0
  181. package/src/config/project-security.ts +15 -0
  182. package/src/config/rerank.test.ts +60 -0
  183. package/src/config/schema/magic-context.ts +57 -0
  184. package/src/shared/model-suggestion-retry.ts +1 -1
  185. package/src/shared/sqlite-turn-deadline.test.ts +270 -0
  186. package/src/shared/sqlite.ts +235 -7
  187. package/src/shared/tag-transcript.ts +9 -1
  188. package/dist/wrapup-orchestrator-mnvt2g8m.js +0 -49
@@ -10,6 +10,7 @@ import {
10
10
  } from "./index-x9k3mqrf.js";
11
11
  import {
12
12
  protectedToolTagNumbers,
13
+ stripPersistedAssistantText,
13
14
  byteSize,
14
15
  stripTagPrefix,
15
16
  prependTag,
@@ -73,7 +74,7 @@ import {
73
74
  adoptNullOwnerToolTag2,
74
75
  getCandidateToolOwners2,
75
76
  pickNearestPriorOwner2
76
- } from "./index-305y133n.js";
77
+ } from "./index-whcgcfrv.js";
77
78
  import {
78
79
  textMentionsRecentCommit,
79
80
  hasMeaningfulUserText2,
@@ -92,18 +93,18 @@ import {
92
93
  getSqliteDatabasePath2,
93
94
  assertTransformWrite2,
94
95
  isTransientSqliteError2
95
- } from "./index-1zx2pa5d.js";
96
+ } from "./index-gzy5w8ya.js";
96
97
  import {
97
98
  getProjectEmbeddingSnapshot2,
98
99
  embedTextForProject2,
99
100
  embedBatchForProject2
100
- } from "./index-2yhtnfcf.js";
101
+ } from "./index-zy67whjr.js";
101
102
  import {
102
103
  createWorkerShutdown
103
104
  } from "./index-cpjk5jd2.js";
104
105
  import {
105
106
  runSessionWarmupWorker
106
- } from "./index-35qc6606.js";
107
+ } from "./index-jfem3dgz.js";
107
108
  import {
108
109
  getMaxM0MutationId,
109
110
  getLastCompartmentEndMessage,
@@ -139,12 +140,12 @@ import {
139
140
  peekNoteNudgeText,
140
141
  markNoteNudgeDelivered,
141
142
  getActiveCompartmentRun
142
- } from "./index-v7r4td4c.js";
143
+ } from "./index-y76rhsnr.js";
143
144
  import {
144
145
  BoundedSessionMap,
145
146
  cleanSearchText,
146
147
  matchedSearchSnippet
147
- } from "./index-48stjd56.js";
148
+ } from "./index-mnnkgq0q.js";
148
149
  import {
149
150
  stripSystemInjection,
150
151
  isTextPart,
@@ -214,12 +215,14 @@ import {
214
215
  replaySentinelByMessageIds,
215
216
  isInActiveAnthropicTurn,
216
217
  hasAnthropicReasoning,
218
+ prepareServedShapeRepair,
217
219
  stripSystemInjectedMessages,
218
220
  stripDroppedPlaceholderMessages,
219
221
  replayClearedReasoning,
220
222
  replayStrippedInlineThinking,
221
223
  clearOldReasoning,
222
224
  stripClearedReasoning,
225
+ captureInlineThinkingRepairs,
223
226
  stripInlineThinking,
224
227
  findReasoningBearingAssistantIds,
225
228
  findLatestAssistantReasoningMutationExemptMessage,
@@ -240,10 +243,10 @@ import {
240
243
  extractToolCallObservation,
241
244
  ToolMutationBatch,
242
245
  createToolDropTarget
243
- } from "./index-x4k3f4mf.js";
246
+ } from "./index-mnhcdfxg.js";
244
247
  import {
245
248
  isValidLanguageCode
246
- } from "./index-wgypt3cs.js";
249
+ } from "./index-nxrsns5x.js";
247
250
  import {
248
251
  isEmbeddingHostBusy2
249
252
  } from "./index-qt1qqasc.js";
@@ -251,10 +254,10 @@ import {
251
254
  openCodeDbExists,
252
255
  withReadOnlySessionDb,
253
256
  getMessageTimesFromOpenCodeDb
254
- } from "./index-11zf2wwc.js";
257
+ } from "./index-ksq50rg0.js";
255
258
  import {
256
259
  userFacingFailureCode
257
- } from "./index-1pefp8ar.js";
260
+ } from "./index-3svaejkh.js";
258
261
  import {
259
262
  normalizeProtectedToolName,
260
263
  mergeProtectedTools
@@ -1351,7 +1354,15 @@ class AutoSearchBusyError extends Error {
1351
1354
  }
1352
1355
  }
1353
1356
  async function searchAutoHint(db, sessionId, projectPath, query, options, entry = new URL(new URL(import.meta.url).pathname.endsWith(".ts") ? "./auto-search-worker.ts" : "./auto-search-worker.js", import.meta.url)) {
1354
- return executeAutoSearchWorker(db, sessionId, projectPath, query, options, entry, "search");
1357
+ const {
1358
+ rerankConfig: _rerankConfig,
1359
+ rerankClient: _rerankClient,
1360
+ rerankConnectionFile: _rerankConnectionFile,
1361
+ onRerankSkipped: _onRerankSkipped,
1362
+ captureRerankLanes: _captureRerankLanes,
1363
+ ...hintOptions
1364
+ } = options;
1365
+ return executeAutoSearchWorker(db, sessionId, projectPath, query, { ...hintOptions, explicitSearch: false, rerank: false }, entry, "search");
1355
1366
  }
1356
1367
  var pendingBackfills = new WeakMap;
1357
1368
  var searchWorkers = new WeakMap;
@@ -2414,7 +2425,7 @@ function canConsumeDeferredOnThisPass(args) {
2414
2425
  return args.schedulerDecision === "execute" || args.contextPercentage >= (args.forceMaterializationPercentage ?? escalationBands(65).forceMaterializationPercentage);
2415
2426
  }
2416
2427
  function hasReclaimRide(signals) {
2417
- return signals.hardFold || signals.force || signals.explicitFlush || signals.publishedHistory || signals.subagentExecute === true || signals.executeReclaim === true;
2428
+ return signals.hardFold || signals.force || signals.explicitFlush || signals.publishedHistory || signals.subagentExecute === true || signals.executeReclaim === true || signals.servedShapeRepair === true;
2418
2429
  }
2419
2430
  function prefixMutationPermitted(gate) {
2420
2431
  return !gate.signedThinkingHold || gate.firstRender || gate.idleExpiry || gate.emergency;
@@ -2428,7 +2439,8 @@ var RECLAIM_RIDE_NAMES = [
2428
2439
  "explicitFlush",
2429
2440
  "publishedHistory",
2430
2441
  "subagentExecute",
2431
- "executeReclaim"
2442
+ "executeReclaim",
2443
+ "servedShapeRepair"
2432
2444
  ];
2433
2445
  function reclaimRideLabel(signals) {
2434
2446
  const active = RECLAIM_RIDE_NAMES.filter((name) => signals[name]);
@@ -4946,7 +4958,7 @@ function tagMessages(sessionId, messages, tagger, db, options = {}) {
4946
4958
  const textPart = part;
4947
4959
  const thinkingParts = messageThinkingParts;
4948
4960
  const contentId = `${messageId}:p${partIndex}`;
4949
- const whitespaceOnlyAssistant = message.info.role === "assistant" && stripTagPrefix(textPart.text).trim().length === 0;
4961
+ const whitespaceOnlyAssistant = message.info.role === "assistant" && (stripTagPrefix(textPart.text).trim().length === 0 || textPart.text.includes("§") && stripPersistedAssistantText(textPart.text).length === 0);
4950
4962
  let existingTagId;
4951
4963
  if (whitespaceOnlyAssistant) {
4952
4964
  const persistedWhitespaceTag = getTagNumberByMessageId2(db, sessionId, contentId);
@@ -4998,7 +5010,7 @@ function tagMessages(sessionId, messages, tagger, db, options = {}) {
4998
5010
  accAssignTag += performance.now() - _tAssignText;
4999
5011
  const persistedSource = sourceContents.get(tagId);
5000
5012
  if (persistedSource !== undefined && !options.refreshSourceContents) {
5001
- textPart.text = options.normalizeRestoredAssistantText && message.info.role === "assistant" ? options.normalizeRestoredAssistantText(persistedSource) : persistedSource;
5013
+ textPart.text = options.normalizeRestoredAssistantText && message.info.role === "assistant" ? options.normalizeRestoredAssistantText(persistedSource, message.info.providerID) : persistedSource;
5002
5014
  } else {
5003
5015
  const sourceContent = stripTagPrefix(textPart.text);
5004
5016
  if (sourceContent.trim().length > 0 || options.refreshSourceContents) {
@@ -5885,6 +5897,9 @@ async function runPostTransformPhase2(args) {
5885
5897
  }
5886
5898
  };
5887
5899
  const trailingBlankSourceDecisions = args.trailingBlankSourceDecisions ?? snapshotTrailingBlankSourceDecisions(args.messages);
5900
+ if (!modelAcceptsEmptyContent(args.resolvedProviderID) && !compactionOff)
5901
+ captureInlineThinkingRepairs(args.messages, args.messageTagNumbers, args.sessionMeta?.clearedReasoningThroughTag ?? 0);
5902
+ const servedShapeRepair = prepareServedShapeRepair(args.db, args.sessionId, args.messages, args.readLastServedMessages, compactionOff ? undefined : postprocessReplaySnapshot(args.db, args.sessionId));
5888
5903
  let trailingBlankNewestAssistant;
5889
5904
  for (let index = args.messages.length - 1;index >= 0; index -= 1) {
5890
5905
  const message = args.messages[index];
@@ -5914,8 +5929,8 @@ async function runPostTransformPhase2(args) {
5914
5929
  }
5915
5930
  const activeCompartmentRun = args.canRunCompartments ? getActiveCompartmentRun(args.sessionId) : undefined;
5916
5931
  const compartmentRunning = args.canRunCompartments && !args.awaitedCompartmentRun && activeCompartmentRun !== undefined;
5917
- let deferredMaterialize = args.canConsumeDeferredLate && deferredMaterializationWasPending;
5918
- let materializationRequested = isExplicitFlush || deferredMaterialize;
5932
+ let deferredMaterialize = (args.canConsumeDeferredLate || servedShapeRepair.needsRebuild) && deferredMaterializationWasPending;
5933
+ let materializationRequested = isExplicitFlush || deferredMaterialize || servedShapeRepair.needsRebuild;
5919
5934
  const m0M1EnabledForFold = args.m0M1 !== undefined && (!!args.m0M1.projectPath || !!args.m0M1.projectDirectory) && (args.fullFeatureMode || compactionOff);
5920
5935
  const frozenThinking = new Set(args.activeThinkingTurn || compactionOff ? getMergedReasoningStrippedIds(args.db, args.sessionId) : []);
5921
5936
  const compactionOffFrozenThinking = compactionOff ? compactionOffFrozenThinkingIds(frozenThinking) : new Set;
@@ -5969,6 +5984,8 @@ async function runPostTransformPhase2(args) {
5969
5984
  rewritingSignedPrefix = true;
5970
5985
  thinkingReleasedForFit ||= forFit;
5971
5986
  };
5987
+ if (servedShapeRepair.needsRebuild && activeThinkingTurn)
5988
+ releaseThinkingForRewrite(false, true);
5972
5989
  if (args.forceSignedRebuildForFit && (activeThinkingPrefixHold || activeThinkingTurn && args.thinkingBindingRecoveryEnabledForModel === true)) {
5973
5990
  releaseThinkingForRewrite(true);
5974
5991
  }
@@ -6000,7 +6017,7 @@ async function runPostTransformPhase2(args) {
6000
6017
  let foldBustsServedPrefixThisPass = false;
6001
6018
  let publishedM1RefreshedThisPass = false;
6002
6019
  let prefixPreflightFailed = false;
6003
- const softRefreshOpportunity = !freezeM0M1 && (args.schedulerDecision === "execute" || deferredMaterialize);
6020
+ const softRefreshOpportunity = !freezeM0M1 && (args.schedulerDecision === "execute" || deferredMaterialize || servedShapeRepair.needsRebuild);
6004
6021
  let m0RematerializedThisPass = false;
6005
6022
  const m0CoverageBeforeFold = args.sessionMeta.cachedM0Bytes === null ? -1 : args.sessionMeta.cachedM0MaxCompartmentSeq;
6006
6023
  let m0MaterializeReason = null;
@@ -6129,6 +6146,7 @@ async function runPostTransformPhase2(args) {
6129
6146
  const heldIdleExpiryRebuild = activeThinkingPrefixHold && args.m0M1?.hardSignals?.cacheExpired === true;
6130
6147
  const idleExpiryRebuild = (!freezeM0M1 || activeThinkingPrefixHold) && args.m0M1?.hardSignals?.cacheExpired === true;
6131
6148
  const rideSignals = {
6149
+ servedShapeRepair: servedShapeRepair.needsRebuild,
6132
6150
  executeReclaim: false,
6133
6151
  subagentExecute: !args.fullFeatureMode && args.schedulerDecision === "execute",
6134
6152
  hardFold: rewritingSignedPrefix || foldBustsServedPrefixThisPass || firstRenderBust || idleExpiryRebuild,
@@ -6153,15 +6171,18 @@ async function runPostTransformPhase2(args) {
6153
6171
  }),
6154
6172
  usableWindow: args.usableWindow
6155
6173
  });
6156
- const publishedWorkDrainAllowed = !compactionOff && reclaimRidePermitted(rideSignals, {
6174
+ const publishedWorkDrainAllowed = (!compactionOff || servedShapeRepair.needsRebuild) && reclaimRidePermitted(rideSignals, {
6157
6175
  signedThinkingHold: activeThinkingPrefixHold,
6158
6176
  firstRender: firstRenderBust,
6159
6177
  idleExpiry: idleExpiryRebuild,
6160
6178
  emergency: emergencyDropEligible
6161
6179
  });
6162
- const shouldApplyPendingOps = publishedWorkDrainAllowed;
6163
- const shouldRunHeuristics = publishedWorkDrainAllowed && (rideSignals.publishedHistory || rideSignals.executeReclaim || materializationRequested || forceMaterialization || foldBustsServedPrefixThisPass || firstRenderBust || heldIdleExpiryRebuild || emergencyDropEligible || args.schedulerDecision === "execute" && (!alreadyRanThisTurn || !args.fullFeatureMode));
6180
+ const shouldApplyPendingOps = !compactionOff && publishedWorkDrainAllowed;
6181
+ const shouldRunHeuristics = !compactionOff && publishedWorkDrainAllowed && (rideSignals.publishedHistory || rideSignals.executeReclaim || rideSignals.servedShapeRepair || materializationRequested || forceMaterialization || foldBustsServedPrefixThisPass || firstRenderBust || heldIdleExpiryRebuild || emergencyDropEligible || args.schedulerDecision === "execute" && (!alreadyRanThisTurn || !args.fullFeatureMode));
6164
6182
  const isCacheBustingPass = publishedWorkDrainAllowed;
6183
+ if (servedShapeRepair.needsRebuild && !isCacheBustingPass)
6184
+ throw new Error("Served-shape repair requires a rebuilding pass");
6185
+ servedShapeRepair.apply(isCacheBustingPass);
6165
6186
  let unheldSignedTurnBust = false;
6166
6187
  if (isCacheBustingPass && !activeThinkingPrefixHold && activeThinkingTurn && args.thinkingBindingRecoveryEnabledForModel === true) {
6167
6188
  if (foldBustsServedPrefixThisPass || firstRenderBust || publishedM1RefreshedThisPass)
@@ -6289,6 +6310,8 @@ async function runPostTransformPhase2(args) {
6289
6310
  };
6290
6311
  if (temporalFirstApplication)
6291
6312
  recordFirstApplicationWireEdit(true);
6313
+ if (servedShapeRepair.needsRebuild)
6314
+ recordFirstApplicationWireEdit(true);
6292
6315
  const firstApplicationLocations = new Map;
6293
6316
  const recordFirstApplicationAt = (message, partIndex) => {
6294
6317
  recordFirstApplicationWireEdit(false);
@@ -6431,11 +6454,12 @@ async function runPostTransformPhase2(args) {
6431
6454
  if (routineCleanupApplied && canUseEmptySentinels) {
6432
6455
  stripClearedReasoning(args.messages);
6433
6456
  }
6434
- const strippedInline = routineCleanupApplied && ageLaneAllowed ? stripInlineThinking(args.messages, args.messageTagNumbers, budgetCutoff) : 0;
6457
+ const strippedInline = routineCleanupApplied && ageLaneAllowed ? stripInlineThinking(args.messages, args.messageTagNumbers, budgetCutoff, !canUseEmptySentinels) : 0;
6435
6458
  const persistedInlineWatermark = args.sessionMeta?.clearedReasoningThroughTag ?? 0;
6436
6459
  if (routineCleanupApplied && persistedInlineWatermark > 0 && !compactionOff) {
6437
- replayStrippedInlineThinking(args.messages, args.messageTagNumbers, persistedInlineWatermark);
6460
+ replayStrippedInlineThinking(args.messages, args.messageTagNumbers, persistedInlineWatermark, !canUseEmptySentinels);
6438
6461
  }
6462
+ servedShapeRepair.apply(isCacheBustingPass);
6439
6463
  let removedReasoningMessages = 0;
6440
6464
  if (routineCleanupApplied && !prefixBoundModel && reasoningRemovalSelectable && reasoningRemovalReadable) {
6441
6465
  const newIds = selectReasoningRemovals({
@@ -6762,7 +6786,7 @@ async function runPostTransformPhase2(args) {
6762
6786
  }
6763
6787
  }
6764
6788
  if (isCacheBustingPass) {
6765
- const droppedResult = stripDroppedPlaceholderMessages(args.messages, args.resolvedProviderID, recordFirstApplicationAt);
6789
+ const droppedResult = stripDroppedPlaceholderMessages(args.messages.filter((message) => !servedShapeRepair.messageIDs.has(message.info.id ?? "")), args.resolvedProviderID, recordFirstApplicationAt);
6766
6790
  const protectedTailStart = Math.max(0, args.messages.length - SYSTEM_INJECTION_ACTIONABLE_TAIL_MESSAGES);
6767
6791
  const systemInjectedResult = stripSystemInjectedMessages(args.messages, protectedTailStart, args.resolvedProviderID, recordFirstApplicationAt);
6768
6792
  const hiddenMessages = args.hiddenMessagesAtCompactionSeam ?? [];
@@ -7,17 +7,17 @@ import {
7
7
  } from "./index-pavzsdc6.js";
8
8
  import {
9
9
  isTransientSqliteError2
10
- } from "./index-1zx2pa5d.js";
10
+ } from "./index-gzy5w8ya.js";
11
11
  import {
12
12
  PROMOTABLE_CATEGORIES,
13
13
  CATEGORY_DEFAULT_TTL
14
14
  } from "./index-fr0wbhdn.js";
15
15
  import {
16
16
  managedAuthorityNoteRow
17
- } from "./index-pnjwa6qa.js";
17
+ } from "./index-9q1g3c5q.js";
18
18
  import {
19
19
  embedTextForProject2
20
- } from "./index-2yhtnfcf.js";
20
+ } from "./index-zy67whjr.js";
21
21
  import {
22
22
  saveEmbeddingIfHashMatches
23
23
  } from "./index-4dhv7mqz.js";
@@ -30,7 +30,7 @@ import {
30
30
  buildWorkspaceMemorySqlFilter2,
31
31
  getMemoryById2,
32
32
  updateMemorySeenCount2
33
- } from "./index-y4a3nhtk.js";
33
+ } from "./index-jjvbk92s.js";
34
34
  import {
35
35
  computeNormalizedHash
36
36
  } from "./index-2bvekkfy.js";
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  DEFAULT_LOCAL_EMBEDDING_MODEL
3
- } from "./index-wgypt3cs.js";
3
+ } from "./index-nxrsns5x.js";
4
4
  import {
5
5
  getSynapseLaneIdentity
6
- } from "./index-adk2z5d8.js";
6
+ } from "./index-wfybj1dw.js";
7
7
  import {
8
8
  getHarness2
9
9
  } from "./index-pavzsdc6.js";
@@ -16,7 +16,7 @@ import {
16
16
  } from "./index-h7tgn49j.js";
17
17
  import {
18
18
  inRootAsyncContext2
19
- } from "./index-1zx2pa5d.js";
19
+ } from "./index-gzy5w8ya.js";
20
20
  import {
21
21
  computeNormalizedHash
22
22
  } from "./index-2bvekkfy.js";
@@ -727,16 +727,20 @@ class EmbeddingWorkerClient {
727
727
  entry;
728
728
  timeoutMs;
729
729
  prepareTelemetry;
730
+ idleMs;
730
731
  worker = null;
731
732
  startPromise = null;
732
733
  nextId = 1;
733
734
  pending = new Map;
734
735
  disposed = false;
735
- constructor(data, entry = new URL(new URL(import.meta.url).pathname.endsWith(".ts") ? "./embedding-worker.ts" : "./embedding-worker.js", import.meta.url), timeoutMs = 5 * 60000, prepareTelemetry = prepareNativeOnnxTelemetry) {
736
+ activeRequests = 0;
737
+ idleTimer = null;
738
+ constructor(data, entry = new URL(new URL(import.meta.url).pathname.endsWith(".ts") ? "./embedding-worker.ts" : "./embedding-worker.js", import.meta.url), timeoutMs = 5 * 60000, prepareTelemetry = prepareNativeOnnxTelemetry, idleMs = 10 * 60000) {
736
739
  this.data = data;
737
740
  this.entry = entry;
738
741
  this.timeoutMs = timeoutMs;
739
742
  this.prepareTelemetry = prepareTelemetry;
743
+ this.idleMs = idleMs;
740
744
  }
741
745
  start() {
742
746
  if (this.startPromise)
@@ -802,6 +806,7 @@ class EmbeddingWorkerClient {
802
806
  const fail = (error) => {
803
807
  if (this.worker !== worker)
804
808
  return;
809
+ this.clearIdleTimer();
805
810
  this.worker = null;
806
811
  for (const request of this.pending.values()) {
807
812
  clearTimeout(request.timer);
@@ -826,6 +831,31 @@ class EmbeddingWorkerClient {
826
831
  async request(texts, signal) {
827
832
  if (signal?.aborted)
828
833
  return Promise.reject(new Error("embedding request aborted"));
834
+ this.activeRequests++;
835
+ this.clearIdleTimer();
836
+ try {
837
+ return await this.requestOnWorker(texts, signal);
838
+ } finally {
839
+ this.activeRequests--;
840
+ this.armIdleTimer();
841
+ }
842
+ }
843
+ clearIdleTimer() {
844
+ if (this.idleTimer)
845
+ clearTimeout(this.idleTimer);
846
+ this.idleTimer = null;
847
+ }
848
+ armIdleTimer() {
849
+ if (this.disposed || this.activeRequests !== 0 || !this.worker)
850
+ return;
851
+ this.clearIdleTimer();
852
+ this.idleTimer = inRootAsyncContext2(() => setTimeout(() => {
853
+ this.idleTimer = null;
854
+ this.stop(new Error("embedding worker idle"));
855
+ }, this.idleMs));
856
+ this.idleTimer.unref();
857
+ }
858
+ async requestOnWorker(texts, signal) {
829
859
  const worker = await this.start();
830
860
  if (this.disposed)
831
861
  throw new Error("embedding worker disposed");
@@ -877,6 +907,7 @@ class EmbeddingWorkerClient {
877
907
  });
878
908
  }
879
909
  async stop(error) {
910
+ this.clearIdleTimer();
880
911
  const worker = this.worker;
881
912
  this.worker = null;
882
913
  for (const request of this.pending.values()) {
@@ -10,7 +10,7 @@ import {
10
10
  } from "./index-rrv26qjz.js";
11
11
  import {
12
12
  shouldHoldIgnoredNotification
13
- } from "./index-11zf2wwc.js";
13
+ } from "./index-ksq50rg0.js";
14
14
  import {
15
15
  getErrorMessage
16
16
  } from "./index-y8v6yerm.js";
@@ -16,11 +16,11 @@ import {
16
16
  } from "./index-58e3y90n.js";
17
17
  import {
18
18
  Database2
19
- } from "./index-1zx2pa5d.js";
19
+ } from "./index-gzy5w8ya.js";
20
20
  import {
21
21
  normalizeStoredProjectPath,
22
22
  storedPathBelongsToIdentity
23
- } from "./index-vkc1ca9p.js";
23
+ } from "./index-kq5w68dp.js";
24
24
  import {
25
25
  logSlowWriteTransaction
26
26
  } from "./index-t5pck3ss.js";
@@ -10,14 +10,16 @@ import {
10
10
  registerSqliteDiagnosticSink2,
11
11
  detectSqliteRuntime2,
12
12
  Database2,
13
+ createSqliteTurnDatabase2,
14
+ hasSqliteTurnDeadlineRouting2,
13
15
  withSqliteBackgroundWriter2,
14
16
  withoutSqliteTransformPass2,
15
17
  isTransientSqliteError2,
16
18
  withPrivilegedWriter2
17
- } from "./index-1zx2pa5d.js";
19
+ } from "./index-gzy5w8ya.js";
18
20
  import {
19
21
  scheduleAfterBootQuiet
20
- } from "./index-vkc1ca9p.js";
22
+ } from "./index-kq5w68dp.js";
21
23
  import {
22
24
  getHarness2,
23
25
  harnessOwnsOpenCodeStore2
@@ -42,7 +44,7 @@ import {
42
44
  } from "./index-fb3zxn06.js";
43
45
  import {
44
46
  startMessageFtsRowidMapBackfill2
45
- } from "./index-jmycsey7.js";
47
+ } from "./index-x6cbrv9h.js";
46
48
  import {
47
49
  LKG_SLOT_CHUNKS_DDL,
48
50
  SESSION_REPLAY_DECISIONS_DDL,
@@ -52,7 +54,7 @@ import {
52
54
  hasPendingMigrations,
53
55
  getMainThreadMigrationBodyCount,
54
56
  runMigrations
55
- } from "./index-pnjwa6qa.js";
57
+ } from "./index-9q1g3c5q.js";
56
58
  import {
57
59
  installTagIdentityRevisionTrigger,
58
60
  ensureColumn,
@@ -1277,8 +1279,8 @@ function finishDatabaseOpen(db, dbPath, explicitDbPath, latestSupportedVersion)
1277
1279
  state.running = startMessageFtsRowidMapBackfill2(db, signal).then(async () => {
1278
1280
  if (signal.aborted || !readsOpenCodeStore)
1279
1281
  return;
1280
- const { readRawSessionMessagePage, readRawSessionMessages } = await importPluginModule(() => import("./read-session-chunk-0a8vdyqp.js"));
1281
- const { startMessageTimeBackfill } = await importPluginModule(() => import("./message-time-backfill-0myx7fz3.js"));
1282
+ const { readRawSessionMessagePage, readRawSessionMessages } = await importPluginModule(() => import("./read-session-chunk-t039f0m5.js"));
1283
+ const { startMessageTimeBackfill } = await importPluginModule(() => import("./message-time-backfill-4qva0b4f.js"));
1282
1284
  if (signal.aborted)
1283
1285
  return;
1284
1286
  await startMessageTimeBackfill(db, Object.assign(readRawSessionMessages, {
@@ -2583,6 +2585,10 @@ function openDatabase(dbPathOrOptions) {
2583
2585
  return null;
2584
2586
  }
2585
2587
  if (existing) {
2588
+ if (options?.nativeTurnDeadlines && !hasSqliteTurnDeadlineRouting2(existing)) {
2589
+ log2("[magic-context] storage unavailable: native turn deadlines must be selected on the first open; restart the host");
2590
+ return null;
2591
+ }
2586
2592
  if (!enforceSchemaFence(existing, dbPath, latestSupportedVersion)) {
2587
2593
  return null;
2588
2594
  }
@@ -2607,7 +2613,7 @@ function openDatabase(dbPathOrOptions) {
2607
2613
  throw error;
2608
2614
  }
2609
2615
  }
2610
- db = new Database2(dbPath);
2616
+ db = options?.nativeTurnDeadlines ? createSqliteTurnDatabase2(dbPath) : new Database2(dbPath);
2611
2617
  installBootBusyTimeout(db, dbPath, busyTimeoutMs, options?.onBootBusyTimeout);
2612
2618
  if (!enforceSchemaFence(db, dbPath, latestSupportedVersion)) {
2613
2619
  closeQuietly(db);
@@ -2654,6 +2660,10 @@ async function openDatabaseAsync(dbPathOrOptions) {
2654
2660
  lastMigrationOnOpenRefusal = null;
2655
2661
  const existing = databases.get(dbPath);
2656
2662
  if (existing) {
2663
+ if (options?.nativeTurnDeadlines && !hasSqliteTurnDeadlineRouting2(existing)) {
2664
+ log2("[magic-context] storage unavailable: native turn deadlines must be selected on the first open; restart the host");
2665
+ return null;
2666
+ }
2657
2667
  const startedAt = performance.now();
2658
2668
  const accepted = enforceSchemaFence(existing, dbPath, latestSupportedVersion);
2659
2669
  if (accepted) {
@@ -2669,8 +2679,12 @@ async function openDatabaseAsync(dbPathOrOptions) {
2669
2679
  return accepted ? existing : null;
2670
2680
  }
2671
2681
  const pending = pendingAsyncOpens.get(dbPath);
2672
- if (pending)
2673
- return pending;
2682
+ if (pending) {
2683
+ if (!options?.nativeTurnDeadlines)
2684
+ return pending;
2685
+ const opened = await pending;
2686
+ return opened && hasSqliteTurnDeadlineRouting2(opened) ? opened : null;
2687
+ }
2674
2688
  if (!isFileBackedPath(dbPath)) {
2675
2689
  throw new Error("async migration requires a file-backed database; use the explicit synchronous opener for in-memory or URI test databases");
2676
2690
  }
@@ -2696,7 +2710,7 @@ async function openDatabaseAsync(dbPathOrOptions) {
2696
2710
  throw error;
2697
2711
  }
2698
2712
  }
2699
- db = new Database2(dbPath);
2713
+ db = options?.nativeTurnDeadlines ? createSqliteTurnDatabase2(dbPath) : new Database2(dbPath);
2700
2714
  installBootBusyTimeout(db, dbPath, busyTimeoutMs, options?.onBootBusyTimeout);
2701
2715
  openMs = performance.now() - openStartedAt;
2702
2716
  guardStartedAt = performance.now();
@@ -3,16 +3,16 @@ import {
3
3
  } from "./index-h7tgn49j.js";
4
4
  import {
5
5
  clearEmergencyRecovery
6
- } from "./index-x4k3f4mf.js";
6
+ } from "./index-mnhcdfxg.js";
7
7
  import {
8
8
  requestPendingMaterialization,
9
9
  dropSlot,
10
10
  executeContextRecomp
11
- } from "./index-v7r4td4c.js";
11
+ } from "./index-y76rhsnr.js";
12
12
  import {
13
13
  renderUserFacingFailure,
14
14
  userFacingFailureCode
15
- } from "./index-1pefp8ar.js";
15
+ } from "./index-3svaejkh.js";
16
16
 
17
17
  // src/hooks/magic-context/recomp-orchestrator.ts
18
18
  function resolveLiveModelKey(liveSessionState, sessionId) {