@retaw106/mmc-oc 2.2.1 → 2.4.0

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 (285) hide show
  1. package/dist/cli.js +14 -3
  2. package/dist/config/deprecated-config.d.ts +4 -0
  3. package/dist/config/deprecated-config.d.ts.map +1 -0
  4. package/dist/config/index.d.ts.map +1 -1
  5. package/dist/config/project-security.d.ts +2 -2
  6. package/dist/config/schema/magic-context.d.ts +36 -3
  7. package/dist/config/schema/magic-context.d.ts.map +1 -1
  8. package/dist/config-init.js +14 -3
  9. package/dist/{context-mrvm92n8.js → context-c72brxe5.js} +2410 -1801
  10. package/dist/{derive-budgets-rjjz5f7y.js → derive-budgets-s1p37t2g.js} +2 -2
  11. package/dist/features/magic-context/compaction-marker.d.ts.map +1 -1
  12. package/dist/features/magic-context/historian-failure-reason.d.ts +7 -0
  13. package/dist/features/magic-context/historian-failure-reason.d.ts.map +1 -0
  14. package/dist/features/magic-context/memory-maintainer/launcher.d.ts +13 -4
  15. package/dist/features/magic-context/memory-maintainer/launcher.d.ts.map +1 -1
  16. package/dist/features/magic-context/memory-maintainer/manual-commands.d.ts.map +1 -1
  17. package/dist/features/magic-context/memory-maintainer/model-chain.d.ts +47 -0
  18. package/dist/features/magic-context/memory-maintainer/model-chain.d.ts.map +1 -0
  19. package/dist/features/magic-context/memory-maintainer/oc2-adapter.d.ts +17 -4
  20. package/dist/features/magic-context/memory-maintainer/oc2-adapter.d.ts.map +1 -1
  21. package/dist/features/magic-context/memory-maintainer/pipeline.d.ts +6 -0
  22. package/dist/features/magic-context/memory-maintainer/pipeline.d.ts.map +1 -1
  23. package/dist/features/magic-context/message-index-async.d.ts +21 -3
  24. package/dist/features/magic-context/message-index-async.d.ts.map +1 -1
  25. package/dist/features/magic-context/message-index.d.ts +7 -1
  26. package/dist/features/magic-context/message-index.d.ts.map +1 -1
  27. package/dist/features/magic-context/migrations.d.ts.map +1 -1
  28. package/dist/features/magic-context/pi-content-decisions.d.ts +7 -1
  29. package/dist/features/magic-context/pi-content-decisions.d.ts.map +1 -1
  30. package/dist/features/magic-context/search.d.ts +29 -0
  31. package/dist/features/magic-context/search.d.ts.map +1 -1
  32. package/dist/features/magic-context/storage-clone.d.ts +2 -0
  33. package/dist/features/magic-context/storage-clone.d.ts.map +1 -1
  34. package/dist/features/magic-context/storage-compartment-history-version.d.ts +4 -0
  35. package/dist/features/magic-context/storage-compartment-history-version.d.ts.map +1 -0
  36. package/dist/features/magic-context/storage-db.d.ts +1 -1
  37. package/dist/features/magic-context/storage-db.d.ts.map +1 -1
  38. package/dist/features/magic-context/storage-historian-runs.d.ts.map +1 -1
  39. package/dist/features/magic-context/storage-meta-persisted.d.ts +23 -5
  40. package/dist/features/magic-context/storage-meta-persisted.d.ts.map +1 -1
  41. package/dist/features/magic-context/storage-meta-session.d.ts +7 -1
  42. package/dist/features/magic-context/storage-meta-session.d.ts.map +1 -1
  43. package/dist/features/magic-context/storage-session-tables.d.ts +5 -1
  44. package/dist/features/magic-context/storage-session-tables.d.ts.map +1 -1
  45. package/dist/features/magic-context/storage-tag-identity-revision.d.ts +50 -0
  46. package/dist/features/magic-context/storage-tag-identity-revision.d.ts.map +1 -0
  47. package/dist/features/magic-context/storage-tags.d.ts +159 -5
  48. package/dist/features/magic-context/storage-tags.d.ts.map +1 -1
  49. package/dist/features/magic-context/tagger.d.ts +2 -0
  50. package/dist/features/magic-context/tagger.d.ts.map +1 -1
  51. package/dist/features/magic-context/transform-decision-log.d.ts +60 -2
  52. package/dist/features/magic-context/transform-decision-log.d.ts.map +1 -1
  53. package/dist/hooks/magic-context/__fixtures__/tail-hygiene-refresh.d.ts +34 -0
  54. package/dist/hooks/magic-context/__fixtures__/tail-hygiene-refresh.d.ts.map +1 -0
  55. package/dist/hooks/magic-context/active-anthropic-turn.d.ts +2 -0
  56. package/dist/hooks/magic-context/active-anthropic-turn.d.ts.map +1 -1
  57. package/dist/hooks/magic-context/apply-operations.d.ts +10 -1
  58. package/dist/hooks/magic-context/apply-operations.d.ts.map +1 -1
  59. package/dist/hooks/magic-context/auto-search-runner.d.ts +2 -2
  60. package/dist/hooks/magic-context/auto-search-runner.d.ts.map +1 -1
  61. package/dist/hooks/magic-context/compartment-runner-types.d.ts +2 -2
  62. package/dist/hooks/magic-context/compartment-runner-types.d.ts.map +1 -1
  63. package/dist/hooks/magic-context/compartment-runner.d.ts +4 -0
  64. package/dist/hooks/magic-context/compartment-runner.d.ts.map +1 -1
  65. package/dist/hooks/magic-context/compartment-trigger-error.d.ts +11 -0
  66. package/dist/hooks/magic-context/compartment-trigger-error.d.ts.map +1 -0
  67. package/dist/hooks/magic-context/compartment-trigger.d.ts +1 -1
  68. package/dist/hooks/magic-context/compartment-trigger.d.ts.map +1 -1
  69. package/dist/hooks/magic-context/ctx-reduce-nudge.d.ts +1 -0
  70. package/dist/hooks/magic-context/ctx-reduce-nudge.d.ts.map +1 -1
  71. package/dist/hooks/magic-context/degraded-pass-refusal.d.ts +2 -0
  72. package/dist/hooks/magic-context/degraded-pass-refusal.d.ts.map +1 -1
  73. package/dist/hooks/magic-context/edit-marker.d.ts +2 -0
  74. package/dist/hooks/magic-context/edit-marker.d.ts.map +1 -1
  75. package/dist/hooks/magic-context/final-wire-token-estimate.d.ts +2 -0
  76. package/dist/hooks/magic-context/final-wire-token-estimate.d.ts.map +1 -1
  77. package/dist/hooks/magic-context/heuristic-cleanup.d.ts.map +1 -1
  78. package/dist/hooks/magic-context/history-boundary-repair.d.ts +11 -2
  79. package/dist/hooks/magic-context/history-boundary-repair.d.ts.map +1 -1
  80. package/dist/hooks/magic-context/hook-handlers.d.ts.map +1 -1
  81. package/dist/hooks/magic-context/lkg-measured-request.d.ts +3 -1
  82. package/dist/hooks/magic-context/lkg-measured-request.d.ts.map +1 -1
  83. package/dist/hooks/magic-context/lkg-persist.d.ts +10 -13
  84. package/dist/hooks/magic-context/lkg-persist.d.ts.map +1 -1
  85. package/dist/hooks/magic-context/lkg-recovery-fence.d.ts +62 -0
  86. package/dist/hooks/magic-context/lkg-recovery-fence.d.ts.map +1 -0
  87. package/dist/hooks/magic-context/lkg-recovery-prefix.d.ts +38 -0
  88. package/dist/hooks/magic-context/lkg-recovery-prefix.d.ts.map +1 -0
  89. package/dist/hooks/magic-context/lkg-replay.d.ts +16 -9
  90. package/dist/hooks/magic-context/lkg-replay.d.ts.map +1 -1
  91. package/dist/hooks/magic-context/lkg-slot.d.ts +141 -2
  92. package/dist/hooks/magic-context/lkg-slot.d.ts.map +1 -1
  93. package/dist/hooks/magic-context/opaque-thinking.d.ts +12 -0
  94. package/dist/hooks/magic-context/opaque-thinking.d.ts.map +1 -0
  95. package/dist/hooks/magic-context/pass-outcome.d.ts +1 -0
  96. package/dist/hooks/magic-context/pass-outcome.d.ts.map +1 -1
  97. package/dist/hooks/magic-context/pending-drop-eligibility.d.ts +14 -0
  98. package/dist/hooks/magic-context/pending-drop-eligibility.d.ts.map +1 -0
  99. package/dist/hooks/magic-context/pending-materialization.d.ts +10 -0
  100. package/dist/hooks/magic-context/pending-materialization.d.ts.map +1 -0
  101. package/dist/hooks/magic-context/postprocess-read-cache.d.ts.map +1 -1
  102. package/dist/hooks/magic-context/provider-visible-parts.d.ts +51 -0
  103. package/dist/hooks/magic-context/provider-visible-parts.d.ts.map +1 -0
  104. package/dist/hooks/magic-context/read-session-chunk.d.ts +22 -1
  105. package/dist/hooks/magic-context/read-session-chunk.d.ts.map +1 -1
  106. package/dist/hooks/magic-context/read-session-db.d.ts +3 -0
  107. package/dist/hooks/magic-context/read-session-db.d.ts.map +1 -1
  108. package/dist/hooks/magic-context/read-session-formatting.d.ts +5 -0
  109. package/dist/hooks/magic-context/read-session-formatting.d.ts.map +1 -1
  110. package/dist/hooks/magic-context/read-session-raw.d.ts +123 -1
  111. package/dist/hooks/magic-context/read-session-raw.d.ts.map +1 -1
  112. package/dist/hooks/magic-context/read-session-true-raw-tokens.d.ts.map +1 -1
  113. package/dist/hooks/magic-context/reasoning-budget.d.ts.map +1 -1
  114. package/dist/hooks/magic-context/render-options.d.ts +19 -0
  115. package/dist/hooks/magic-context/render-options.d.ts.map +1 -0
  116. package/dist/hooks/magic-context/sentinel.d.ts +41 -1
  117. package/dist/hooks/magic-context/sentinel.d.ts.map +1 -1
  118. package/dist/hooks/magic-context/strict-thinking-prefix.d.ts +8 -0
  119. package/dist/hooks/magic-context/strict-thinking-prefix.d.ts.map +1 -0
  120. package/dist/hooks/magic-context/strip-content.d.ts +38 -24
  121. package/dist/hooks/magic-context/strip-content.d.ts.map +1 -1
  122. package/dist/hooks/magic-context/supersession-reclaim.d.ts +5 -3
  123. package/dist/hooks/magic-context/supersession-reclaim.d.ts.map +1 -1
  124. package/dist/hooks/magic-context/system-date-refresh.d.ts +29 -0
  125. package/dist/hooks/magic-context/system-date-refresh.d.ts.map +1 -0
  126. package/dist/hooks/magic-context/system-prompt-dates.d.ts +6 -0
  127. package/dist/hooks/magic-context/system-prompt-dates.d.ts.map +1 -0
  128. package/dist/hooks/magic-context/system-prompt-delivery.d.ts +47 -0
  129. package/dist/hooks/magic-context/system-prompt-delivery.d.ts.map +1 -0
  130. package/dist/hooks/magic-context/system-prompt-hash.d.ts +18 -5
  131. package/dist/hooks/magic-context/system-prompt-hash.d.ts.map +1 -1
  132. package/dist/hooks/magic-context/tag-messages.d.ts +19 -0
  133. package/dist/hooks/magic-context/tag-messages.d.ts.map +1 -1
  134. package/dist/hooks/magic-context/tag-owner-warmup.d.ts +14 -0
  135. package/dist/hooks/magic-context/tag-owner-warmup.d.ts.map +1 -0
  136. package/dist/hooks/magic-context/tail-hygiene-output-count.d.ts +18 -0
  137. package/dist/hooks/magic-context/tail-hygiene-output-count.d.ts.map +1 -0
  138. package/dist/hooks/magic-context/tail-hygiene-walk.d.ts +8 -4
  139. package/dist/hooks/magic-context/tail-hygiene-walk.d.ts.map +1 -1
  140. package/dist/hooks/magic-context/token-count-exact.d.ts +35 -0
  141. package/dist/hooks/magic-context/token-count-exact.d.ts.map +1 -0
  142. package/dist/hooks/magic-context/tool-drop-target.d.ts +2 -0
  143. package/dist/hooks/magic-context/tool-drop-target.d.ts.map +1 -1
  144. package/dist/hooks/magic-context/tool-reclaim.d.ts +5 -2
  145. package/dist/hooks/magic-context/tool-reclaim.d.ts.map +1 -1
  146. package/dist/hooks/magic-context/transform-compartment-phase.d.ts.map +1 -1
  147. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +9 -0
  148. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
  149. package/dist/hooks/magic-context/transform.d.ts +21 -11
  150. package/dist/hooks/magic-context/transform.d.ts.map +1 -1
  151. package/dist/hooks/magic-context/unresolved-history-boundary.d.ts +5 -1
  152. package/dist/hooks/magic-context/unresolved-history-boundary.d.ts.map +1 -1
  153. package/dist/{index-g2z2k5m4.js → index-27ddyx39.js} +2 -2
  154. package/dist/{index-btp5tdc8.js → index-48e9znrc.js} +1248 -570
  155. package/dist/{index-5cep2r9n.js → index-5ty9rnbx.js} +60 -258
  156. package/dist/{index-z2g20msd.js → index-azbmnekv.js} +4 -4
  157. package/dist/{index-1j34a56j.js → index-dwh99z66.js} +293 -36
  158. package/dist/{index-qbkzdkk0.js → index-k59af64t.js} +6 -2
  159. package/dist/{index-5b7x80ec.js → index-kahkxcqw.js} +12532 -10348
  160. package/dist/{index-53g38ggt.js → index-kmbme1v1.js} +1 -1
  161. package/dist/{index-amycb7b1.js → index-r7s7d350.js} +3 -3
  162. package/dist/{index-33gprt9g.js → index-yjv8dpht.js} +1 -1
  163. package/dist/index-ykq24x1n.js +1477 -0
  164. package/dist/index.d.ts.map +1 -1
  165. package/dist/index.js +114 -2
  166. package/dist/{message-time-backfill-phrwp2fz.js → message-time-backfill-j96x1sab.js} +3 -3
  167. package/dist/model-resolution-cvyrrcjw.js +8 -0
  168. package/dist/plugin/rpc-handlers.d.ts.map +1 -1
  169. package/dist/{read-session-chunk-2xm4sc4y.js → read-session-chunk-t8bg6wkz.js} +6 -4
  170. package/dist/recomp-orchestrator-k760qy1n.js +21 -0
  171. package/dist/{safe-notification-target-ph3xd1ve.js → safe-notification-target-1jkf0m82.js} +2 -2
  172. package/dist/{send-session-notification-rnc4nrsr.js → send-session-notification-njjf3b4s.js} +5 -5
  173. package/dist/shared/auto-search-lifecycle.d.ts +14 -0
  174. package/dist/shared/auto-search-lifecycle.d.ts.map +1 -1
  175. package/dist/shared/logger.d.ts.map +1 -1
  176. package/dist/shared/model-suggestion-retry.d.ts +21 -0
  177. package/dist/shared/model-suggestion-retry.d.ts.map +1 -1
  178. package/dist/shared/models-dev-cache.d.ts.map +1 -1
  179. package/dist/shared/models-dev-temperature.d.ts +18 -0
  180. package/dist/shared/models-dev-temperature.d.ts.map +1 -0
  181. package/dist/shared/processed-image-eligibility.d.ts +22 -0
  182. package/dist/shared/processed-image-eligibility.d.ts.map +1 -0
  183. package/dist/shared/project-directory-key.d.ts +16 -0
  184. package/dist/shared/project-directory-key.d.ts.map +1 -1
  185. package/dist/shared/prompt-surface-runtime.d.ts +5 -0
  186. package/dist/shared/prompt-surface-runtime.d.ts.map +1 -1
  187. package/dist/shared/reclaim-distance.d.ts +33 -0
  188. package/dist/shared/reclaim-distance.d.ts.map +1 -0
  189. package/dist/shared/recovery-reasoning-prefix.d.ts +9 -0
  190. package/dist/shared/recovery-reasoning-prefix.d.ts.map +1 -0
  191. package/dist/shared/sqlite.d.ts +35 -1
  192. package/dist/shared/sqlite.d.ts.map +1 -1
  193. package/dist/shared/stable-json.d.ts +7 -0
  194. package/dist/shared/stable-json.d.ts.map +1 -1
  195. package/dist/shared/storage-file-mutex.d.ts +9 -0
  196. package/dist/shared/storage-file-mutex.d.ts.map +1 -0
  197. package/dist/shared/storage-permissions.d.ts +6 -0
  198. package/dist/shared/storage-permissions.d.ts.map +1 -1
  199. package/dist/shared/subagent-temperature.d.ts +46 -0
  200. package/dist/shared/subagent-temperature.d.ts.map +1 -0
  201. package/dist/shared/tag-owner-id.d.ts +1 -0
  202. package/dist/shared/tag-owner-id.d.ts.map +1 -1
  203. package/dist/shared/tag-transcript.d.ts +9 -0
  204. package/dist/shared/tag-transcript.d.ts.map +1 -1
  205. package/dist/shared/tail-hygiene-json.d.ts +22 -0
  206. package/dist/shared/tail-hygiene-json.d.ts.map +1 -0
  207. package/dist/shared/user-facing-codes.d.ts +2 -2
  208. package/dist/shared/window-geometry.d.ts +9 -66
  209. package/dist/shared/window-geometry.d.ts.map +1 -1
  210. package/dist/standalone-plugin-marker.d.ts +8 -0
  211. package/dist/standalone-plugin-marker.d.ts.map +1 -0
  212. package/dist/tools/ctx-expand/search-archive.d.ts +4 -0
  213. package/dist/tools/ctx-expand/search-archive.d.ts.map +1 -0
  214. package/dist/tools/ctx-expand/tools.d.ts.map +1 -1
  215. package/dist/tools/ctx-reduce/constants.d.ts +1 -2
  216. package/dist/tools/ctx-reduce/constants.d.ts.map +1 -1
  217. package/dist/tools/ctx-reduce/tools.d.ts +1 -1
  218. package/dist/tools/ctx-reduce/tools.d.ts.map +1 -1
  219. package/dist/v2/hidden-completion.d.ts +20 -1
  220. package/dist/v2/hidden-completion.d.ts.map +1 -1
  221. package/dist/v2/hooks/context.d.ts +1 -1
  222. package/dist/v2/hooks/context.d.ts.map +1 -1
  223. package/dist/v2/hooks/copied-tag-notation.d.ts +19 -0
  224. package/dist/v2/hooks/copied-tag-notation.d.ts.map +1 -0
  225. package/dist/v2/hooks/generate.d.ts +9 -2
  226. package/dist/v2/hooks/generate.d.ts.map +1 -1
  227. package/dist/v2/hooks/hidden-child.d.ts +22 -1
  228. package/dist/v2/hooks/hidden-child.d.ts.map +1 -1
  229. package/dist/v2/hooks/payload.d.ts.map +1 -1
  230. package/dist/v2/hooks/system-prompt-response.d.ts +5 -0
  231. package/dist/v2/hooks/system-prompt-response.d.ts.map +1 -0
  232. package/dist/v2/server.d.ts.map +1 -1
  233. package/dist/v2/server.js +26593 -21940
  234. package/dist/v2/store-reader.d.ts +27 -1
  235. package/dist/v2/store-reader.d.ts.map +1 -1
  236. package/dist/web/main.js +401 -23
  237. package/dist/{wrapup-orchestrator-yknks3ad.js → wrapup-orchestrator-b2gswatj.js} +10 -10
  238. package/package.json +1 -1
  239. package/src/config/deprecated-config.ts +18 -0
  240. package/src/config/index.test.ts +13 -37
  241. package/src/config/index.ts +2 -2
  242. package/src/config/latch-permanence-guard.test.ts +4 -0
  243. package/src/config/project-security.test.ts +17 -0
  244. package/src/config/project-security.ts +3 -3
  245. package/src/config/schema/magic-context.test.ts +50 -0
  246. package/src/config/schema/magic-context.ts +44 -7
  247. package/src/shared/auto-search-lifecycle.ts +43 -0
  248. package/src/shared/logger.ts +10 -2
  249. package/src/shared/model-suggestion-retry.ts +5 -1
  250. package/src/shared/models-dev-cache.ts +1 -7
  251. package/src/shared/models-dev-temperature.ts +107 -0
  252. package/src/shared/processed-image-eligibility.test.ts +68 -0
  253. package/src/shared/processed-image-eligibility.ts +41 -0
  254. package/src/shared/processed-image-position-review.json +20 -0
  255. package/src/shared/processed-image-position-review.test.ts +19 -0
  256. package/src/shared/project-directory-key.ts +20 -0
  257. package/src/shared/prompt-surface-runtime.ts +12 -0
  258. package/src/shared/reclaim-distance.test.ts +111 -0
  259. package/src/shared/reclaim-distance.ts +91 -0
  260. package/src/shared/recovery-reasoning-prefix.test.ts +34 -0
  261. package/src/shared/recovery-reasoning-prefix.ts +35 -0
  262. package/src/shared/root-async-context.probe.mjs +36 -0
  263. package/src/shared/root-async-context.test.ts +49 -0
  264. package/src/shared/sqlite-acquisition-routing.test.ts +4 -3
  265. package/src/shared/sqlite-busy-budget-review.test.ts +291 -0
  266. package/src/shared/sqlite-foreground-wait.test.ts +304 -0
  267. package/src/shared/sqlite-pass-scope.test.ts +4 -4
  268. package/src/shared/sqlite-writer-diagnostics.test.ts +52 -12
  269. package/src/shared/sqlite.ts +428 -46
  270. package/src/shared/stable-json.ts +79 -7
  271. package/src/shared/storage-file-mutex.test.ts +50 -0
  272. package/src/shared/storage-file-mutex.ts +130 -0
  273. package/src/shared/storage-permissions.ts +46 -0
  274. package/src/shared/subagent-temperature.ts +110 -0
  275. package/src/shared/tag-owner-id.ts +13 -0
  276. package/src/shared/tag-transcript.ts +118 -0
  277. package/src/shared/tail-hygiene-json.test.ts +117 -0
  278. package/src/shared/tail-hygiene-json.ts +217 -0
  279. package/src/shared/user-facing-codes.ts +2 -2
  280. package/src/shared/window-geometry.test.ts +102 -236
  281. package/src/shared/window-geometry.ts +23 -413
  282. package/dist/index-ramz5kkm.js +0 -514
  283. package/dist/model-resolution-wazv26n0.js +0 -6
  284. package/dist/recomp-orchestrator-frmwj9hz.js +0 -21
  285. package/src/shared/__fixtures__/window-overlay.v1.json +0 -337
@@ -1,514 +0,0 @@
1
- import {
2
- harnessOwnsOpenCodeStore,
3
- log
4
- } from "./index-qbkzdkk0.js";
5
- import {
6
- Database
7
- } from "./index-1j34a56j.js";
8
-
9
- // src/shared/opencode-db-path.ts
10
- import { existsSync, readdirSync, statSync } from "node:fs";
11
- import { homedir } from "node:os";
12
- import { isAbsolute, join, resolve } from "node:path";
13
- var cachedResolution = null;
14
- var lastReadFailure = null;
15
- var claimedDiagnostics = new Set;
16
- function openCodeDataDir(env = process.env, dataHome) {
17
- return join(dataHome ?? env.XDG_DATA_HOME ?? join(homedir(), ".local", "share"), "opencode");
18
- }
19
- function environmentKey(dataDir, hostGeneration, channel, env) {
20
- return [
21
- hostGeneration,
22
- dataDir,
23
- env.OPENCODE_DB ?? "",
24
- env.OPENCODE_DISABLE_CHANNEL_DB ?? "",
25
- channel ?? env.OPENCODE_CHANNEL ?? ""
26
- ].join("\x00");
27
- }
28
- function channelPath(dataDir, channel) {
29
- return ["latest", "beta", "prod"].includes(channel) ? join(dataDir, "opencode.db") : join(dataDir, `opencode-${channel}.db`);
30
- }
31
- function discoveredCandidateNames(dataDir) {
32
- const names = ["opencode.db", "opencode-local.db", "opencode-dev.db"];
33
- try {
34
- const discovered = readdirSync(dataDir, { withFileTypes: true }).filter((entry) => /^opencode-.+\.db$/.test(entry.name) && !names.includes(entry.name)).map((entry) => entry.name).sort();
35
- names.push(...discovered);
36
- } catch {}
37
- return names;
38
- }
39
- function discoverOpenCodeDb(dataDir) {
40
- const candidates = discoveredCandidateNames(dataDir).map((name, order) => {
41
- const path = join(dataDir, name);
42
- try {
43
- const metadata = statSync(path);
44
- return metadata.isFile() ? { path, order, mtimeMs: metadata.mtimeMs } : null;
45
- } catch {
46
- return null;
47
- }
48
- });
49
- const existing = candidates.filter((candidate) => candidate !== null).sort((left, right) => right.mtimeMs - left.mtimeMs || left.order - right.order)[0];
50
- if (!existing) {
51
- return { path: join(dataDir, "opencode.db"), source: "default", channel: null };
52
- }
53
- const name = existing.path.slice(dataDir.length + 1);
54
- const channel = name === "opencode.db" ? null : name.slice("opencode-".length, -".db".length) || null;
55
- return { path: existing.path, source: "discovered", channel };
56
- }
57
- function resolveV1Fresh(dataDir, env = process.env) {
58
- const explicit = env.OPENCODE_DB;
59
- if (explicit !== undefined && explicit.length > 0) {
60
- if (explicit === ":memory:") {
61
- return { path: explicit, source: "OPENCODE_DB", channel: null };
62
- }
63
- return {
64
- path: isAbsolute(explicit) ? explicit : join(dataDir, explicit),
65
- source: "OPENCODE_DB",
66
- channel: null
67
- };
68
- }
69
- const disableChannelDb = env.OPENCODE_DISABLE_CHANNEL_DB;
70
- if (disableChannelDb === "1" || disableChannelDb === "true") {
71
- return { path: join(dataDir, "opencode.db"), source: "default", channel: null };
72
- }
73
- const channel = env.OPENCODE_CHANNEL;
74
- if (channel !== undefined && channel.length > 0) {
75
- return { path: channelPath(dataDir, channel), source: "channel", channel };
76
- }
77
- return discoverOpenCodeDb(dataDir);
78
- }
79
- function sourceOpenCodeDatabaseFilename(hostGeneration, channel, env = process.env) {
80
- if (hostGeneration === "v1") {
81
- const explicit = env.OPENCODE_DB;
82
- if (explicit !== undefined && explicit.length > 0)
83
- return explicit;
84
- if (env.OPENCODE_DISABLE_CHANNEL_DB === "1" || env.OPENCODE_DISABLE_CHANNEL_DB === "true") {
85
- return "opencode.db";
86
- }
87
- return ["latest", "beta", "prod"].includes(channel) ? "opencode.db" : `opencode-${channel}.db`;
88
- }
89
- return env.OPENCODE_DB ?? (["latest", "dev", "beta", "next", "prod"].includes(channel) || env.OPENCODE_DISABLE_CHANNEL_DB === "1" || env.OPENCODE_DISABLE_CHANNEL_DB === "true" ? "opencode.db" : `opencode-${channel.replace(/[^a-zA-Z0-9._-]/g, "")}.db`);
90
- }
91
- function resolveV2Fresh(dataDir, channel, env) {
92
- const filename = sourceOpenCodeDatabaseFilename("v2", channel, env);
93
- const explicit = env.OPENCODE_DB !== undefined;
94
- return {
95
- path: filename === ":memory:" ? filename : resolve(dataDir, filename),
96
- source: explicit ? "OPENCODE_DB" : env.OPENCODE_CHANNEL ? "channel" : "default",
97
- channel: explicit ? null : channel
98
- };
99
- }
100
- function resolveOpenCodeDbPath(hostGeneration = "v1", options = {}) {
101
- const env = options.env ?? process.env;
102
- const dataDir = openCodeDataDir(env, options.dataHome);
103
- const channel = options.channel ?? env.OPENCODE_CHANNEL;
104
- const key = environmentKey(dataDir, hostGeneration, channel, env);
105
- if (cachedResolution?.key === key && (!cachedResolution.existed || existsSync(cachedResolution.resolution.path))) {
106
- if (cachedResolution.existed)
107
- return cachedResolution.resolution;
108
- }
109
- const resolution = hostGeneration === "v2" ? resolveV2Fresh(dataDir, channel ?? "latest", env) : resolveV1Fresh(dataDir, env);
110
- cachedResolution = {
111
- key,
112
- resolution,
113
- existed: resolution.path !== ":memory:" && existsSync(resolution.path)
114
- };
115
- return resolution;
116
- }
117
- function schemaTableNames(db, schema = "main") {
118
- const rows = db.prepare(`SELECT name FROM ${schema}.sqlite_master WHERE type = 'table' AND name IN ('message', 'part', 'session', 'project', 'session_message', 'session_v2')`).all();
119
- return new Set(rows.flatMap((row) => typeof row.name === "string" ? [row.name] : []));
120
- }
121
- function hasV1MessageTables(db, schema = "main") {
122
- const tables = schemaTableNames(db, schema);
123
- return tables.has("message") && tables.has("part");
124
- }
125
- function detectOpenCodeStoreGeneration(db, schema = "main") {
126
- const tables = schemaTableNames(db, schema);
127
- const hasV1Messages = tables.has("message") && tables.has("part");
128
- if (hasV1Messages)
129
- return "v1";
130
- if (tables.has("session_message"))
131
- return "v2";
132
- if (tables.has("session") || tables.has("project"))
133
- return "v1";
134
- return "unknown";
135
- }
136
- function hasMigratedV2Schema(tables) {
137
- return tables.has("session_message") && tables.has("session_v2");
138
- }
139
- function isOpenCodeV2Store(db, schema = "main") {
140
- return detectOpenCodeStoreGeneration(db, schema) === "v2" || hasMigratedV2Schema(schemaTableNames(db, schema));
141
- }
142
- function assertOpenCodeStoreGeneration(db, expected, path, schema = "main") {
143
- const actual = detectOpenCodeStoreGeneration(db, schema);
144
- if (actual === expected)
145
- return;
146
- if (expected === "v2" && isOpenCodeV2Store(db, schema))
147
- return;
148
- if (actual === "unknown")
149
- return;
150
- throw new Error(`OpenCode store generation mismatch at ${path}: expected ${expected}, found ${actual}; refusing generation-specific database access`);
151
- }
152
- function openCodeDbPathExists(resolution = resolveOpenCodeDbPath()) {
153
- return resolution.path !== ":memory:" && existsSync(resolution.path);
154
- }
155
- function recordOpenCodeDbReadFailure(resolution, error) {
156
- const message = error instanceof Error ? error.message : String(error);
157
- lastReadFailure = { ...resolution, message };
158
- return lastReadFailure;
159
- }
160
- function clearOpenCodeDbReadFailure(path) {
161
- if (path === undefined || lastReadFailure?.path === path)
162
- lastReadFailure = null;
163
- }
164
- function claimOpenCodeDbDiagnosticOnce(surface, resolution) {
165
- const key = `${surface}\x00${resolution.path}\x00${resolution.source}`;
166
- if (claimedDiagnostics.has(key))
167
- return false;
168
- claimedDiagnostics.add(key);
169
- return true;
170
- }
171
-
172
- // src/shared/sqlite-helpers.ts
173
- function closeQuietly(db) {
174
- if (!db)
175
- return;
176
- try {
177
- db.close();
178
- } catch {}
179
- }
180
- function isKnownAutocommit(db) {
181
- const state = db;
182
- try {
183
- return state.inTransaction === false || state.isTransaction === false;
184
- } catch {
185
- return false;
186
- }
187
- }
188
-
189
- // src/hooks/magic-context/read-session-db.ts
190
- function openCodeDbExists() {
191
- return harnessOwnsOpenCodeStore() && openCodeDbPathExists(resolveOpenCodeDbPath());
192
- }
193
- var cachedReadOnlyDb = null;
194
- function closeCachedReadOnlyDb() {
195
- if (!cachedReadOnlyDb) {
196
- return;
197
- }
198
- try {
199
- closeQuietly(cachedReadOnlyDb.db);
200
- } catch (error) {
201
- log("[magic-context] failed to close cached OpenCode read-only DB:", error);
202
- } finally {
203
- cachedReadOnlyDb = null;
204
- }
205
- }
206
- function getReadOnlySessionDb() {
207
- if (!harnessOwnsOpenCodeStore()) {
208
- throw new Error("OpenCode session database is not readable from a Pi-compatible process; its history lives in Pi sessions");
209
- }
210
- const resolution = resolveOpenCodeDbPath();
211
- const dbPath = resolution.path;
212
- if (!openCodeDbPathExists(resolution)) {
213
- throw new Error(`OpenCode session database is unavailable at ${dbPath} (source=${resolution.source})`);
214
- }
215
- if (cachedReadOnlyDb?.path === dbPath) {
216
- return cachedReadOnlyDb.db;
217
- }
218
- closeCachedReadOnlyDb();
219
- const db = new Database(dbPath, { readonly: true });
220
- try {
221
- assertOpenCodeStoreGeneration(db, "v1", dbPath);
222
- } catch (error) {
223
- closeQuietly(db);
224
- throw error;
225
- }
226
- cachedReadOnlyDb = { path: dbPath, db };
227
- clearOpenCodeDbReadFailure();
228
- return db;
229
- }
230
- function withReadOnlySessionDb(fn) {
231
- return fn(getReadOnlySessionDb());
232
- }
233
- function getRawSessionMessageCountFromDb(db, sessionId) {
234
- const row = db.prepare(`SELECT COUNT(*) as count FROM message WHERE session_id = ?
235
- AND NOT (COALESCE(json_extract(data, '$.summary'), 0) = 1
236
- AND COALESCE(json_extract(data, '$.finish'), '') = 'stop')`).get(sessionId);
237
- return typeof row?.count === "number" ? row.count : 0;
238
- }
239
- var trackedSessions = new Map;
240
- var pendingParts = new Map;
241
- var probeLogObserverForTests;
242
- function asRecord(value) {
243
- return value !== null && typeof value === "object" ? value : null;
244
- }
245
- function truthyStoredFlag(value) {
246
- return value === true || value === 1 || value === "true";
247
- }
248
- function isMachineGeneratedPart(value) {
249
- const part = asRecord(value);
250
- if (!part)
251
- return false;
252
- const metadata = asRecord(part.metadata);
253
- const marker = asRecord(metadata?.marker);
254
- return truthyStoredFlag(part.synthetic) || truthyStoredFlag(part.ignored) || marker !== null && marker.kind !== null && marker.kind !== undefined;
255
- }
256
- function messageTimeCreated(message, fallback) {
257
- const time = asRecord(message.info.time);
258
- return typeof time?.created === "number" ? time.created : fallback;
259
- }
260
- function latestMessageByRole(messages, role, realUserOnly = false) {
261
- let latest = null;
262
- for (const [index, message] of messages.entries()) {
263
- if (message.info.role !== role)
264
- continue;
265
- if (realUserOnly && message.parts.length > 0 && message.parts.every(isMachineGeneratedPart)) {
266
- continue;
267
- }
268
- const timeCreated = messageTimeCreated(message, index);
269
- if (latest === null || timeCreated > latest.timeCreated || timeCreated === latest.timeCreated && index > latest.index) {
270
- latest = { message, timeCreated, index };
271
- }
272
- }
273
- return latest;
274
- }
275
- function assistantAwaitingToolsFromMessages(messages) {
276
- const latestAssistant = latestMessageByRole(messages, "assistant");
277
- if (!latestAssistant)
278
- return false;
279
- const assistantTime = asRecord(latestAssistant.message.info.time);
280
- if (typeof assistantTime?.created !== "number")
281
- return false;
282
- const latestRealUser = latestMessageByRole(messages, "user", true);
283
- if (latestRealUser && latestRealUser.timeCreated > latestAssistant.timeCreated)
284
- return false;
285
- if (latestAssistant.message.info.finish === "tool-calls")
286
- return true;
287
- return latestAssistant.message.parts.some((value) => {
288
- const part = asRecord(value);
289
- return part?.type === "tool" && part.providerExecuted !== true;
290
- });
291
- }
292
- function shouldHoldIgnoredNotificationFromMessages(messages) {
293
- if (assistantAwaitingToolsFromMessages(messages))
294
- return true;
295
- const latestAssistant = latestMessageByRole(messages, "assistant");
296
- if (latestAssistant) {
297
- const finish = latestAssistant.message.info.finish;
298
- if (typeof finish !== "string" || finish.length === 0)
299
- return true;
300
- if (finish === "tool-calls" || finish === "unknown")
301
- return true;
302
- }
303
- const latestRealUser = latestMessageByRole(messages, "user", true);
304
- return latestRealUser !== null && latestRealUser.timeCreated > (latestAssistant?.timeCreated ?? -1);
305
- }
306
- function trackedMessages(session) {
307
- let assistant;
308
- let user;
309
- for (const message of session.messages.values()) {
310
- if (message.role === "assistant" && (!assistant || message.timeCreated >= assistant.timeCreated))
311
- assistant = message;
312
- if (message.role === "user" && (!user || message.timeCreated >= user.timeCreated) && (message.parts.size === 0 || ![...message.parts.values()].every(isMachineGeneratedPart)))
313
- user = message;
314
- }
315
- return [user, assistant].filter((message) => !!message).map((message) => ({
316
- info: {
317
- id: message.id,
318
- role: message.role,
319
- time: { created: message.timeCreated },
320
- ...message.finish === undefined ? {} : { finish: message.finish }
321
- },
322
- parts: [...message.parts.values()]
323
- }));
324
- }
325
- function logProbeFailureOnce(resolution, error) {
326
- const failure = recordOpenCodeDbReadFailure(resolution, error);
327
- if (!claimOpenCodeDbDiagnosticOnce("session-state-probe", resolution))
328
- return;
329
- const message = `[magic-context] OpenCode DB probe failed: path=${resolution.path} source=${resolution.source} cause=${failure.message}`;
330
- probeLogObserverForTests?.(message);
331
- log(message);
332
- }
333
- function resolvedDbIsAvailable() {
334
- const resolution = resolveOpenCodeDbPath();
335
- if (!harnessOwnsOpenCodeStore())
336
- return { resolution, available: false };
337
- const available = openCodeDbPathExists(resolution);
338
- if (available)
339
- clearOpenCodeDbReadFailure(resolution.path);
340
- else
341
- logProbeFailureOnce(resolution, "opencode_db_missing");
342
- return { resolution, available };
343
- }
344
- function shouldHoldIgnoredNotificationFromOpenCodeDb(db, sessionId) {
345
- if (assistantAwaitingToolsFromOpenCodeDb(db, sessionId))
346
- return true;
347
- if (hasUnfinishedAssistant(db, sessionId))
348
- return true;
349
- if (hasUnansweredRealUser(db, sessionId))
350
- return true;
351
- return false;
352
- }
353
- function shouldHoldIgnoredNotification(sessionId) {
354
- if (process.env.MMC_NOTICE_GATE === "bypass")
355
- return false;
356
- if (process.env.MMC_NOTICE_GATE === "hold")
357
- return true;
358
- const availability = resolvedDbIsAvailable();
359
- const tracked = trackedSessions.get(sessionId);
360
- if (tracked)
361
- return shouldHoldIgnoredNotificationFromMessages(trackedMessages(tracked));
362
- if (!availability.available)
363
- return false;
364
- try {
365
- return withReadOnlySessionDb((db) => shouldHoldIgnoredNotificationFromOpenCodeDb(db, sessionId));
366
- } catch (error) {
367
- logProbeFailureOnce(availability.resolution, error);
368
- return false;
369
- }
370
- }
371
- function assistantAwaitingToolsFromOpenCodeDb(db, sessionId) {
372
- const latestAssistant = latestAssistantRow(db, sessionId);
373
- if (typeof latestAssistant?.id !== "string")
374
- return false;
375
- if (hasNewerRealUserMessage(db, sessionId, latestAssistant.timeCreated))
376
- return false;
377
- if (latestAssistant.finish === "tool-calls")
378
- return true;
379
- const partRows = db.prepare("SELECT data FROM part WHERE +session_id = ? AND likelihood(message_id = ?, 0.000001)").all(sessionId, latestAssistant.id);
380
- return partRows.some((row) => {
381
- if (typeof row.data !== "string" || row.data.length === 0)
382
- return false;
383
- try {
384
- const part = JSON.parse(row.data);
385
- return part.type === "tool" && part.providerExecuted !== true;
386
- } catch {
387
- return false;
388
- }
389
- });
390
- }
391
- function hasNewerRealUserMessage(db, sessionId, latestAssistantTimeCreated) {
392
- if (typeof latestAssistantTimeCreated !== "number")
393
- return false;
394
- const row = db.prepare(`SELECT 1 as one
395
- FROM message m
396
- WHERE m.session_id = ?
397
- AND m.time_created > ?
398
- AND json_extract(m.data, '$.role') = 'user'
399
- AND NOT (
400
- EXISTS (SELECT 1 FROM part p WHERE p.message_id = m.id)
401
- AND NOT EXISTS (
402
- SELECT 1 FROM part p
403
- WHERE p.message_id = m.id
404
- AND COALESCE(json_extract(p.data, '$.synthetic'), 0) NOT IN (1, 'true')
405
- AND json_extract(p.data, '$.metadata.marker.kind') IS NULL
406
- AND COALESCE(json_extract(p.data, '$.ignored'), 0) NOT IN (1, 'true')
407
- )
408
- )
409
- LIMIT 1`).get(sessionId, latestAssistantTimeCreated);
410
- return row?.one === 1;
411
- }
412
- function latestAssistantRow(db, sessionId) {
413
- return db.prepare(`SELECT id,
414
- json_extract(data, '$.finish') as finish,
415
- time_created as timeCreated
416
- FROM message
417
- WHERE session_id = ?
418
- AND json_extract(data, '$.role') = 'assistant'
419
- ORDER BY time_created DESC
420
- LIMIT 1`).get(sessionId);
421
- }
422
- function hasUnfinishedAssistant(db, sessionId) {
423
- const latestAssistant = latestAssistantRow(db, sessionId);
424
- if (typeof latestAssistant?.id !== "string")
425
- return false;
426
- const finish = latestAssistant.finish;
427
- if (typeof finish !== "string" || finish.length === 0)
428
- return true;
429
- return finish === "tool-calls" || finish === "unknown";
430
- }
431
- function hasUnansweredRealUser(db, sessionId) {
432
- const latestAssistant = latestAssistantRow(db, sessionId);
433
- const latestAssistantTime = typeof latestAssistant?.timeCreated === "number" ? latestAssistant.timeCreated : -1;
434
- return hasNewerRealUserMessage(db, sessionId, latestAssistantTime);
435
- }
436
- function getMessageTimesFromOpenCodeDb(sessionId, messageIds) {
437
- const result = new Map;
438
- if (messageIds.length === 0 || !harnessOwnsOpenCodeStore())
439
- return result;
440
- try {
441
- withReadOnlySessionDb((db) => {
442
- const placeholders = messageIds.map(() => "?").join(",");
443
- const rows = db.prepare(`SELECT id, time_created FROM message WHERE session_id = ? AND id IN (${placeholders})`).all(sessionId, ...messageIds);
444
- for (const row of rows) {
445
- if (typeof row.id === "string" && typeof row.time_created === "number") {
446
- result.set(row.id, row.time_created);
447
- }
448
- }
449
- });
450
- } catch (error) {
451
- logProbeFailureOnce(resolveOpenCodeDbPath(), error);
452
- }
453
- return result;
454
- }
455
- function findLastAssistantModelFromOpenCodeDb(sessionId) {
456
- if (!harnessOwnsOpenCodeStore())
457
- return null;
458
- const resolution = resolveOpenCodeDbPath();
459
- try {
460
- if (!openCodeDbPathExists(resolution)) {
461
- throw new Error(`OpenCode session database is unavailable at ${resolution.path}`);
462
- }
463
- const db = new Database(resolution.path, { readonly: true });
464
- try {
465
- const queryV2 = () => db.prepare(`SELECT json_extract(data, '$.model.providerID') as providerID,
466
- json_extract(data, '$.model.id') as modelID,
467
- json_extract(data, '$.agent') as agent
468
- FROM session_message
469
- WHERE session_id = ?
470
- AND type = 'assistant'
471
- AND json_extract(data, '$.model.providerID') IS NOT NULL
472
- AND json_extract(data, '$.model.id') IS NOT NULL
473
- ORDER BY seq DESC
474
- LIMIT 1`).get(sessionId);
475
- const queryV1 = () => db.prepare(`SELECT json_extract(data, '$.providerID') as providerID,
476
- json_extract(data, '$.modelID') as modelID,
477
- json_extract(data, '$.agent') as agent
478
- FROM message
479
- WHERE session_id = ?
480
- AND json_extract(data, '$.role') = 'assistant'
481
- AND json_extract(data, '$.providerID') IS NOT NULL
482
- AND json_extract(data, '$.modelID') IS NOT NULL
483
- ORDER BY time_created DESC
484
- LIMIT 1`).get(sessionId);
485
- let row = null;
486
- try {
487
- assertOpenCodeStoreGeneration(db, "v2", resolution.path);
488
- row = queryV2();
489
- } catch {}
490
- if (!row) {
491
- try {
492
- assertOpenCodeStoreGeneration(db, "v1", resolution.path);
493
- row = queryV1();
494
- } catch {}
495
- }
496
- if (!row || typeof row.providerID !== "string" || typeof row.modelID !== "string") {
497
- return null;
498
- }
499
- const agent = typeof row.agent === "string" && row.agent.length > 0 ? row.agent : undefined;
500
- return {
501
- providerID: row.providerID,
502
- modelID: row.modelID,
503
- ...agent ? { agent } : {}
504
- };
505
- } finally {
506
- closeQuietly(db);
507
- }
508
- } catch (error) {
509
- logProbeFailureOnce(resolution, error);
510
- return null;
511
- }
512
- }
513
-
514
- export { closeQuietly, isKnownAutocommit, resolveOpenCodeDbPath, hasV1MessageTables, assertOpenCodeStoreGeneration, openCodeDbPathExists, claimOpenCodeDbDiagnosticOnce, openCodeDbExists, withReadOnlySessionDb, getRawSessionMessageCountFromDb, shouldHoldIgnoredNotification, getMessageTimesFromOpenCodeDb, findLastAssistantModelFromOpenCodeDb };
@@ -1,6 +0,0 @@
1
- import {
2
- resolveHistorianModel2
3
- } from "./index-z2g20msd.js";
4
- export {
5
- resolveHistorianModel2 as resolveHistorianModel
6
- };
@@ -1,21 +0,0 @@
1
- import {
2
- setRecompStarting2,
3
- setRecompTerminal2,
4
- runManagedRecomp2
5
- } from "./index-g2z2k5m4.js";
6
- import"./index-5b7x80ec.js";
7
- import"./index-amycb7b1.js";
8
- import"./index-btp5tdc8.js";
9
- import"./index-ramz5kkm.js";
10
- import"./index-33gprt9g.js";
11
- import"./index-1j34a56j.js";
12
- import"./index-jdxxq8cz.js";
13
- import"./index-53g38ggt.js";
14
- import"./index-5cep2r9n.js";
15
- import"./index-x37vg474.js";
16
- import"./index-qbkzdkk0.js";
17
- export {
18
- runManagedRecomp2 as runManagedRecomp,
19
- setRecompStarting2 as setRecompStarting,
20
- setRecompTerminal2 as setRecompTerminal
21
- };