@openchamber/web 2.0.4 → 2.1.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 (264) hide show
  1. package/dist/assets/{CodeMirrorCommentWidgets-C_zL-eri.js → CodeMirrorCommentWidgets-qlshRzAf.js} +1 -1
  2. package/dist/assets/{DiffView-BeN2_YYF.js → DiffView-BI_YgdKl.js} +3 -3
  3. package/dist/assets/FilesView-B_NJFLBH.js +17 -0
  4. package/dist/assets/{GitView-DLDazOo1.js → GitView-BWKg6TNS.js} +4 -4
  5. package/dist/assets/{GuestAttachDialog-C0xe_Lyy.js → GuestAttachDialog-DO4x4vIR.js} +1 -1
  6. package/dist/assets/{GuestSurfacePane-BdaurnDr.js → GuestSurfacePane-4PY11vEP.js} +1 -1
  7. package/dist/assets/JsonTreeView-u4yx65zn.js +1 -0
  8. package/dist/assets/{LinearIssuesView-BryoAHow.js → LinearIssuesView-C4gGBhU8.js} +1 -1
  9. package/dist/assets/{MarkdownImageGallery-DfuEoaGq.js → MarkdownImageGallery-fqVRCTdC.js} +1 -1
  10. package/dist/assets/MarkdownRendererImpl-Cfb5fTnq.js +39 -0
  11. package/dist/assets/OnboardingScreen-CiTV2_OT.js +1 -0
  12. package/dist/assets/PatchDiff-BrjhzXDM.js +1 -0
  13. package/dist/assets/{PierreDiffViewer-BC950e3F.js → PierreDiffViewer-CVx2e1cx.js} +5 -5
  14. package/dist/assets/{PlanView-B7Xgihqk.js → PlanView-DP9DOnI-.js} +4 -4
  15. package/dist/assets/{PluginPane-2C71F8uF.js → PluginPane-rZvoMQSi.js} +3 -3
  16. package/dist/assets/SettingsView-Dp9jubRs.js +30 -0
  17. package/dist/assets/SettingsWindow-Dst0yiV7.js +1 -0
  18. package/dist/assets/{SubmoduleDiffSummary-BSA9gnIO.js → SubmoduleDiffSummary-CixkM4fI.js} +1 -1
  19. package/dist/assets/{ToolOutputDialog-DprkVKcj.js → ToolOutputDialog-f0cS2DIf.js} +6 -6
  20. package/dist/assets/ToolPartDiffPreview-CFFIAFFY.js +8 -0
  21. package/dist/assets/{VirtualizedFileDiff-Kp8hKJdT.js → VirtualizedFileDiff-B-U_aQwV.js} +4 -4
  22. package/dist/assets/{WalkthroughView-DGnTzqIU.js → WalkthroughView-C1uB3Pl3.js} +2 -2
  23. package/dist/assets/{appThemeRegistry-BdEHBA4s.js → appThemeRegistry-DU-UKEHq.js} +1 -1
  24. package/dist/assets/{commitAndPush-LwtVa2Oc.js → commitAndPush-CtWGqrtW.js} +1 -1
  25. package/dist/assets/{computeVirtualFileMetrics-6V1xNpO9.js → computeVirtualFileMetrics-BmhViPMt.js} +1 -1
  26. package/dist/assets/de-D4hpTCNY.js +10 -0
  27. package/dist/assets/es-Bw9m3H62.js +16 -0
  28. package/dist/assets/fileTreeStatus-CvPnAWSi.js +1 -0
  29. package/dist/assets/fr-Bhll42P0.js +14 -0
  30. package/dist/assets/index-Btd2mmYT.js +42 -0
  31. package/dist/assets/index-C-7hQnEc.css +1 -0
  32. package/dist/assets/{index-CmNPYddV.js → index-DwtCnbiK.js} +1 -1
  33. package/dist/assets/{isDiffPlainText-1bXcWCrw.js → isDiffPlainText-CPDhzF1K.js} +1 -1
  34. package/dist/assets/{isFilePlainText-CBAppvy1.js → isFilePlainText-n8k0lMTZ.js} +1 -1
  35. package/dist/assets/ja-CsHoT43d.js +16 -0
  36. package/dist/assets/ko-BBNdtFa4.js +16 -0
  37. package/dist/assets/{main-CzjTMTfW.js → main-D6rlXjug.js} +2 -2
  38. package/dist/assets/main-kYkr_urz.js +1000 -0
  39. package/dist/assets/markdownCore-CHm8ycaW.js +7 -0
  40. package/dist/assets/{miniChat-CP68IL8Q.js → miniChat-2JY8K3Qw.js} +2 -2
  41. package/dist/assets/mobile-CviaXnnU.js +2 -0
  42. package/dist/assets/nl-DszyktfH.js +16 -0
  43. package/dist/assets/openSessionFromRoute-BIlcJIf3.js +1 -0
  44. package/dist/assets/{web-components-ngpHPEDU.js → parseDiffFromFile-DeZzEah8.js} +5 -5
  45. package/dist/assets/{patchFileDiff-pqRSHLHI.js → patchFileDiff-BnEHIdM2.js} +2 -2
  46. package/dist/assets/pl-Bk9_mUXc.js +16 -0
  47. package/dist/assets/pt-BR-BIXmm3Gw.js +16 -0
  48. package/dist/assets/{renderElectronMiniChatApp-DKIilR7N.js → renderElectronMiniChatApp-DvUphkjj.js} +2 -2
  49. package/dist/assets/renderMobileApp-Cdc49X8Y.js +25 -0
  50. package/dist/assets/runtimeEndpointReset-Cu6RUve4.js +56 -0
  51. package/dist/assets/shikiHighlight-CcVzlYit.js +1 -0
  52. package/dist/assets/space-apply-CgJ5JYPK.js +1 -0
  53. package/dist/assets/space-close-C1tL-_0t.js +1 -0
  54. package/dist/assets/{textMateThemeFromAppTheme-BSUFChBY.js → textMateThemeFromAppTheme-CAOCeVjl.js} +1 -1
  55. package/dist/assets/tr-C_13w7CX.js +7 -0
  56. package/dist/assets/uk-BZTsG-q_.js +16 -0
  57. package/dist/assets/{useAppFontEffects-Dsl_sLrj.js → useAppFontEffects-CeMgbeVa.js} +185 -177
  58. package/dist/assets/{useInlineCommentController-d5vntsQ_.js → useInlineCommentController-U97JJifS.js} +2 -2
  59. package/dist/assets/useRootScrollLock-DMBY2aTT.js +2 -0
  60. package/dist/assets/{vendor-base-ui-DnNniUWp.js → vendor-base-ui-DWgyZK2k.js} +1 -1
  61. package/dist/assets/vendor-codemirror-autocomplete-DetzHhtC.js +1 -0
  62. package/dist/assets/{vendor-codemirror-commands-B7H_j0iU.js → vendor-codemirror-commands-ConqfjLn.js} +1 -1
  63. package/dist/assets/{vendor-codemirror-lang-angular-DEPs2M5t.js → vendor-codemirror-lang-angular-Dbpx8qe-.js} +1 -1
  64. package/dist/assets/{vendor-codemirror-lang-cpp-DhkseaMo.js → vendor-codemirror-lang-cpp-TRtQWrpl.js} +1 -1
  65. package/dist/assets/{vendor-codemirror-lang-css-O0cZX78y.js → vendor-codemirror-lang-css-DY4CGDG2.js} +1 -1
  66. package/dist/assets/{vendor-codemirror-lang-go-fMdQYcON.js → vendor-codemirror-lang-go-CLKXh6B8.js} +1 -1
  67. package/dist/assets/{vendor-codemirror-lang-html-CfgK872x.js → vendor-codemirror-lang-html-CQnNjmg9.js} +1 -1
  68. package/dist/assets/{vendor-codemirror-lang-java-CQj4S3zl.js → vendor-codemirror-lang-java-CokZKqls.js} +1 -1
  69. package/dist/assets/{vendor-codemirror-lang-javascript-Cc2ZYbgX.js → vendor-codemirror-lang-javascript-Kgp6fZRE.js} +1 -1
  70. package/dist/assets/{vendor-codemirror-lang-jinja-BmZZv8g-.js → vendor-codemirror-lang-jinja-DZchyrN1.js} +1 -1
  71. package/dist/assets/{vendor-codemirror-lang-json-CMBS2tG9.js → vendor-codemirror-lang-json-CkdBRvqj.js} +1 -1
  72. package/dist/assets/{vendor-codemirror-lang-less-C6Eo8hVS.js → vendor-codemirror-lang-less-_k-GKz0A.js} +1 -1
  73. package/dist/assets/{vendor-codemirror-lang-liquid-DSTR47-H.js → vendor-codemirror-lang-liquid-DuHUMKoh.js} +1 -1
  74. package/dist/assets/{vendor-codemirror-lang-markdown-BPGOH9ye.js → vendor-codemirror-lang-markdown-CdG1RXm1.js} +1 -1
  75. package/dist/assets/{vendor-codemirror-lang-php-DD9udfPH.js → vendor-codemirror-lang-php-Ca15KQSA.js} +1 -1
  76. package/dist/assets/{vendor-codemirror-lang-python-HahnQaAS.js → vendor-codemirror-lang-python-B4MRHRva.js} +1 -1
  77. package/dist/assets/{vendor-codemirror-lang-rust-nLTovbjv.js → vendor-codemirror-lang-rust-8fLJdxQA.js} +1 -1
  78. package/dist/assets/{vendor-codemirror-lang-sass-pL2Yc72v.js → vendor-codemirror-lang-sass-CASr_yQ1.js} +1 -1
  79. package/dist/assets/{vendor-codemirror-lang-sql-BVBnan19.js → vendor-codemirror-lang-sql-Dc4ER-re.js} +1 -1
  80. package/dist/assets/{vendor-codemirror-lang-vue-BqGzJVm1.js → vendor-codemirror-lang-vue-fu2BqdK2.js} +1 -1
  81. package/dist/assets/{vendor-codemirror-lang-wast-B0_m5DqU.js → vendor-codemirror-lang-wast-BkCOgSpV.js} +1 -1
  82. package/dist/assets/{vendor-codemirror-lang-xml-Dj3voadT.js → vendor-codemirror-lang-xml-7e-kPepH.js} +1 -1
  83. package/dist/assets/{vendor-codemirror-lang-yaml-yu-9Z5u7.js → vendor-codemirror-lang-yaml-Cq3p_9DI.js} +1 -1
  84. package/dist/assets/vendor-codemirror-language-CZcLdzDM.js +3 -0
  85. package/dist/assets/{vendor-codemirror-language-data-B1EetJur.js → vendor-codemirror-language-data-B8HKnqZy.js} +2 -2
  86. package/dist/assets/vendor-codemirror-search-BZNojiZO.js +2 -0
  87. package/dist/assets/{vendor-codemirror-state-C9awkmn-.js → vendor-codemirror-state--21VQleR.js} +1 -1
  88. package/dist/assets/vendor-codemirror-view-8PpN-8l4.js +4 -0
  89. package/dist/assets/vendor-opencode-client-Byb4ZSqI.js +12 -0
  90. package/dist/assets/vendor-remend-DcBOpbSu.js +24 -0
  91. package/dist/assets/{vendor-replit-codemirror-vim-B2DJlAhT.js → vendor-replit-codemirror-vim-EX7OnecQ.js} +1 -1
  92. package/dist/assets/zh-CN-C62wm2Tg.js +16 -0
  93. package/dist/assets/zh-TW-BgGTiQA6.js +16 -0
  94. package/dist/index.html +4 -4
  95. package/dist/mini-chat.html +4 -4
  96. package/dist/mobile.html +4 -4
  97. package/package.json +4 -4
  98. package/server/index.js +58 -1
  99. package/server/lib/browser-control/DOCUMENTATION.md +8 -1
  100. package/server/lib/dev-tunnel/DOCUMENTATION.md +6 -0
  101. package/server/lib/dev-tunnel/runtime.js +94 -38
  102. package/server/lib/dev-tunnel/tunnel.test.js +16 -2
  103. package/server/lib/dictation/DOCUMENTATION.md +23 -10
  104. package/server/lib/dictation/audio.js +28 -0
  105. package/server/lib/dictation/local/sherpa-recognizer.js +33 -7
  106. package/server/lib/dictation/local/sherpa-recognizer.test.js +94 -0
  107. package/server/lib/dictation/local/worker-client.js +28 -10
  108. package/server/lib/dictation/local/worker-process.js +25 -1
  109. package/server/lib/dictation/stream-manager.js +160 -53
  110. package/server/lib/dictation/stream-manager.test.js +108 -7
  111. package/server/lib/enterprise-mode.d.ts +2 -0
  112. package/server/lib/enterprise-mode.js +84 -9
  113. package/server/lib/enterprise-mode.test.js +115 -0
  114. package/server/lib/fs/DOCUMENTATION.md +3 -2
  115. package/server/lib/fs/routes.js +28 -1
  116. package/server/lib/fs/routes.test.js +31 -5
  117. package/server/lib/git/DOCUMENTATION.md +1 -1
  118. package/server/lib/git/service.js +61 -2
  119. package/server/lib/git/service.test.js +141 -0
  120. package/server/lib/github/DOCUMENTATION.md +18 -0
  121. package/server/lib/github/checks-summary.js +76 -0
  122. package/server/lib/github/pr-summaries.js +282 -0
  123. package/server/lib/github/pr-summaries.test.js +209 -0
  124. package/server/lib/github/routes.js +42 -77
  125. package/server/lib/github/routes.test.js +77 -0
  126. package/server/lib/inherited-env.js +51 -0
  127. package/server/lib/inherited-env.test.js +59 -0
  128. package/server/lib/message-search/DOCUMENTATION.md +83 -0
  129. package/server/lib/message-search/indexer.js +336 -0
  130. package/server/lib/message-search/indexer.test.js +341 -0
  131. package/server/lib/message-search/routes.js +92 -0
  132. package/server/lib/message-search/runtime.js +234 -0
  133. package/server/lib/message-search/runtime.test.js +108 -0
  134. package/server/lib/message-search/sqlite.js +74 -0
  135. package/server/lib/message-search/store.js +289 -0
  136. package/server/lib/openchamber-control/DOCUMENTATION.md +6 -1
  137. package/server/lib/openchamber-control/actions.js +1 -1
  138. package/server/lib/openchamber-control/service.js +21 -2
  139. package/server/lib/openchamber-control/service.test.js +50 -0
  140. package/server/lib/openchamber-sessions/routes.js +15 -0
  141. package/server/lib/openchamber-sessions/routes.test.js +31 -0
  142. package/server/lib/opencode/DOCUMENTATION.md +43 -38
  143. package/server/lib/opencode/auth.d.ts +24 -0
  144. package/server/lib/opencode/auth.js +130 -66
  145. package/server/lib/opencode/auth.test.js +114 -70
  146. package/server/lib/opencode/compatibility.js +4 -3
  147. package/server/lib/opencode/compatibility.test.js +10 -10
  148. package/server/lib/opencode/feature-routes-runtime.js +3 -0
  149. package/server/lib/opencode/lifecycle.js +21 -12
  150. package/server/lib/opencode/lifecycle.test.js +38 -5
  151. package/server/lib/opencode/provider-source-route.test.js +55 -2
  152. package/server/lib/opencode/routes.js +17 -4
  153. package/server/lib/opencode/settings-helpers.js +6 -0
  154. package/server/lib/opencode/settings-helpers.test.js +1 -1
  155. package/server/lib/opencode/settings-registry.json +16 -0
  156. package/server/lib/opencode/settings-runtime.js +9 -0
  157. package/server/lib/opencode/shutdown-runtime.js +2 -0
  158. package/server/lib/opencode/v1-migration-topup.js +13 -3
  159. package/server/lib/opencode/v2-install.test.js +13 -13
  160. package/server/lib/quota/DOCUMENTATION.md +11 -5
  161. package/server/lib/quota/providers/claude/auth.js +19 -6
  162. package/server/lib/quota/providers/claude/auth.test.js +22 -9
  163. package/server/lib/quota/providers/claude/index.js +3 -3
  164. package/server/lib/quota/providers/claude/index.test.js +3 -2
  165. package/server/lib/quota/providers/cline-pass.js +4 -4
  166. package/server/lib/quota/providers/codex.js +3 -4
  167. package/server/lib/quota/providers/codex.test.js +1 -1
  168. package/server/lib/quota/providers/copilot.js +4 -5
  169. package/server/lib/quota/providers/copilot.test.js +1 -1
  170. package/server/lib/quota/providers/deepseek.js +3 -4
  171. package/server/lib/quota/providers/deepseek.test.js +1 -1
  172. package/server/lib/quota/providers/google/auth.js +1 -3
  173. package/server/lib/quota/providers/google/index.js +3 -2
  174. package/server/lib/quota/providers/hyper.js +4 -4
  175. package/server/lib/quota/providers/index.js +9 -2
  176. package/server/lib/quota/providers/index.test.js +5 -3
  177. package/server/lib/quota/providers/kimi.js +16 -11
  178. package/server/lib/quota/providers/kimi.test.js +81 -38
  179. package/server/lib/quota/providers/minimax-shared.js +3 -4
  180. package/server/lib/quota/providers/nanogpt.js +3 -4
  181. package/server/lib/quota/providers/neuralwatt.js +3 -4
  182. package/server/lib/quota/providers/neuralwatt.test.js +1 -1
  183. package/server/lib/quota/providers/openai.js +2 -8
  184. package/server/lib/quota/providers/opencode-go.js +5 -5
  185. package/server/lib/quota/providers/opencode-go.test.js +1 -1
  186. package/server/lib/quota/providers/openrouter.js +30 -6
  187. package/server/lib/quota/providers/openrouter.test.js +122 -1
  188. package/server/lib/quota/providers/wafer.js +3 -4
  189. package/server/lib/quota/providers/xai.js +12 -12
  190. package/server/lib/quota/providers/zai.js +3 -4
  191. package/server/lib/quota/providers/zai.test.js +1 -1
  192. package/server/lib/quota/providers/zhipuai-coding-plan.js +5 -6
  193. package/server/lib/quota/providers/zhipuai-coding-plan.test.js +1 -1
  194. package/server/lib/quota/routes.js +1 -1
  195. package/server/lib/routing/DOCUMENTATION.md +4 -0
  196. package/server/lib/routing/runtime.js +45 -4
  197. package/server/lib/routing/runtime.test.js +35 -6
  198. package/server/lib/scheduled-tasks/DOCUMENTATION.md +27 -0
  199. package/server/lib/scheduled-tasks/chats-scope.js +50 -0
  200. package/server/lib/scheduled-tasks/runtime.js +57 -23
  201. package/server/lib/scheduled-tasks/runtime.test.js +103 -1
  202. package/server/lib/scheduled-tasks/service.js +37 -29
  203. package/server/lib/scheduled-tasks/service.test.js +39 -0
  204. package/server/lib/spaces/DOCUMENTATION.md +54 -9
  205. package/server/lib/spaces/host.js +24 -3
  206. package/server/lib/spaces/journey.js +111 -11
  207. package/server/lib/spaces/journey.test.js +189 -8
  208. package/server/lib/spaces/places/docker-disk.js +151 -0
  209. package/server/lib/spaces/places/docker-disk.test.js +167 -0
  210. package/server/lib/spaces/places/docker-tools.js +11 -1
  211. package/server/lib/spaces/places/docker.js +4 -2
  212. package/server/lib/spaces/places/fake-docker.js +36 -2
  213. package/server/lib/spaces/routes.js +21 -4
  214. package/server/lib/spaces/routes.test.js +6 -2
  215. package/server/lib/spaces/space-archive.js +275 -0
  216. package/server/lib/spaces/space-archive.test.js +194 -0
  217. package/server/lib/spaces/space-opencode.js +139 -6
  218. package/server/lib/spaces/space-opencode.test.js +82 -1
  219. package/server/lib/spaces/space-records.js +3 -0
  220. package/server/lib/spaces/space-setup.js +10 -5
  221. package/server/lib/spaces/space-setup.test.js +8 -2
  222. package/server/lib/terminal/DOCUMENTATION.md +1 -0
  223. package/server/lib/terminal/runtime.js +6 -1
  224. package/server/lib/terminal/runtime.test.js +19 -0
  225. package/server/lib/tts/routes.js +2 -2
  226. package/server/lib/tts/service.js +8 -8
  227. package/dist/assets/FilesView-CN34wm_N.js +0 -17
  228. package/dist/assets/JsonTreeView-B1Xq-k2t.js +0 -1
  229. package/dist/assets/MarkdownRendererImpl-B_ZcWOvX.js +0 -12
  230. package/dist/assets/OnboardingScreen-C22bGmnP.js +0 -1
  231. package/dist/assets/PatchDiff-0xd6UeFB.js +0 -1
  232. package/dist/assets/SettingsView-m_zoFiaT.js +0 -30
  233. package/dist/assets/SettingsWindow-CofS020b.js +0 -1
  234. package/dist/assets/ToolPartDiffPreview-Dq0go_fX.js +0 -8
  235. package/dist/assets/de-DlgBHUAI.js +0 -10
  236. package/dist/assets/es-BC8G41U8.js +0 -16
  237. package/dist/assets/fr-I0z3vVjy.js +0 -14
  238. package/dist/assets/index-CgR5rJq_.js +0 -41
  239. package/dist/assets/index-adyy_sEk.css +0 -1
  240. package/dist/assets/ja-BIElEsY8.js +0 -16
  241. package/dist/assets/ko-DRnnHetA.js +0 -16
  242. package/dist/assets/main-DVX34beR.js +0 -886
  243. package/dist/assets/markdownCore-Cxbkn5NR.js +0 -7
  244. package/dist/assets/mobile-BrlBrNfZ.js +0 -2
  245. package/dist/assets/nl-DzUV-kwp.js +0 -16
  246. package/dist/assets/pl-Bb-cb7k7.js +0 -16
  247. package/dist/assets/pt-BR-CyIWrTcE.js +0 -16
  248. package/dist/assets/renderMobileApp-B0z6-x58.js +0 -25
  249. package/dist/assets/runtimeEndpointReset-uu1DBwLL.js +0 -52
  250. package/dist/assets/scheduledTasksApi-BuzWT445.js +0 -1
  251. package/dist/assets/shikiHighlight-BWGrY5YU.js +0 -1
  252. package/dist/assets/tr-DXEDSoYO.js +0 -7
  253. package/dist/assets/uk-C8hN--q_.js +0 -16
  254. package/dist/assets/useRootScrollLock-2rd5Y6gR.js +0 -2
  255. package/dist/assets/vendor-codemirror-autocomplete-DzPz9Wgq.js +0 -1
  256. package/dist/assets/vendor-codemirror-language-BgPj_McA.js +0 -3
  257. package/dist/assets/vendor-codemirror-search-BmS-GmcX.js +0 -2
  258. package/dist/assets/vendor-codemirror-view-CiLROUVV.js +0 -4
  259. package/dist/assets/vendor-opencode-client-DSZl7jSi.js +0 -12
  260. package/dist/assets/vendor-remend-BWYYytN3.js +0 -22
  261. package/dist/assets/zh-CN-CtzXdjMZ.js +0 -16
  262. package/dist/assets/zh-TW-Ds0CADSz.js +0 -16
  263. package/server/lib/opencode/credential-db.js +0 -144
  264. package/server/lib/opencode/credential-db.test.js +0 -104
@@ -0,0 +1,92 @@
1
+ /**
2
+ * `GET /api/openchamber/message-search`
3
+ *
4
+ * q words to find (each must occur; 3+ characters each)
5
+ * session only this session (in-conversation search)
6
+ * directory only sessions in these directories (repeatable)
7
+ * role 'user' | 'assistant' | 'reasoning'
8
+ * reasoning '0' leaves reasoning hits out (the reader hides reasoning)
9
+ * order 'desc' (newest first, default) | 'asc'
10
+ * before page cursor from a previous answer's `next` (`<createdAt>:<id>`)
11
+ * limit page size, 1..200
12
+ *
13
+ * Answers `{ status: 'ok', hits, next, index }` or
14
+ * `{ status: 'query-too-short', hits: [] }`; 503 when no index is running
15
+ * (search is off, or this server has no SQLite).
16
+ * Snippets mark matches with U+E000 / U+E001 and are plain text.
17
+ *
18
+ * `GET /api/openchamber/message-search/status` answers
19
+ * `{ state: 'unsupported' | 'off' | 'on' | 'failed', sizeBytes, index }`.
20
+ *
21
+ * `DELETE /api/openchamber/message-search/index` deletes the index file; while
22
+ * search is on a new one starts at once. Answers the status afterwards.
23
+ */
24
+
25
+ import { z } from 'zod';
26
+
27
+ // Express hands repeated query keys over as arrays; each field is read as the
28
+ // shape it may take, once.
29
+ const text = z.string().trim().catch('');
30
+ const querySchema = z.object({
31
+ q: text,
32
+ session: text,
33
+ role: z.enum(['user', 'assistant', 'reasoning']).nullable().catch(null),
34
+ reasoning: z.enum(['0', '1']).catch('1'),
35
+ order: z.enum(['asc', 'desc']).catch('desc'),
36
+ before: text,
37
+ limit: z.coerce.number().int().catch(20),
38
+ directory: z.union([z.string(), z.array(z.string())]).catch([]),
39
+ });
40
+
41
+ const parseBefore = (raw) => {
42
+ const separator = raw.indexOf(':');
43
+ if (separator <= 0) return null;
44
+ const createdAt = Number(raw.slice(0, separator));
45
+ const id = raw.slice(separator + 1);
46
+ return Number.isFinite(createdAt) && id ? { createdAt, id } : null;
47
+ };
48
+
49
+ export const registerMessageSearchRoutes = (app, { messageSearchRuntime }) => {
50
+ app.get('/api/openchamber/message-search/status', async (_req, res) => {
51
+ try {
52
+ return res.json(await messageSearchRuntime.status());
53
+ } catch (error) {
54
+ return res.status(500).json({ error: error?.message || 'Could not read the search index status' });
55
+ }
56
+ });
57
+
58
+ app.delete('/api/openchamber/message-search/index', async (_req, res) => {
59
+ try {
60
+ await messageSearchRuntime.deleteIndex();
61
+ return res.json(await messageSearchRuntime.status());
62
+ } catch (error) {
63
+ return res.status(500).json({ error: error?.message || 'Could not delete the search index' });
64
+ }
65
+ });
66
+
67
+ app.get('/api/openchamber/message-search', (req, res) => {
68
+ const query = querySchema.parse({ role: null, ...req.query });
69
+ const directories = (Array.isArray(query.directory) ? query.directory : [query.directory])
70
+ .map((directory) => directory.trim())
71
+ .filter(Boolean);
72
+ try {
73
+ const result = messageSearchRuntime.search({
74
+ query: query.q,
75
+ sessionId: query.session || null,
76
+ directories,
77
+ role: query.role,
78
+ includeReasoning: query.reasoning === '1',
79
+ before: parseBefore(query.before),
80
+ limit: query.limit,
81
+ order: query.order,
82
+ });
83
+ if (!result) return res.status(503).json({ error: 'Message search is off on this server' });
84
+ return res.json({
85
+ ...result,
86
+ next: result.next ? `${result.next.createdAt}:${result.next.id}` : null,
87
+ });
88
+ } catch (error) {
89
+ return res.status(500).json({ error: error?.message || 'Search failed' });
90
+ }
91
+ });
92
+ };
@@ -0,0 +1,234 @@
1
+ import path from 'node:path';
2
+ import fsPromises from 'node:fs/promises';
3
+ import { OpenCode } from '@opencode/client';
4
+ import { z } from 'zod';
5
+
6
+ import { createMessageSearchIndexer } from './indexer.js';
7
+ import { loadSqliteOpener } from './sqlite.js';
8
+ import { buildSnippet, openMessageSearchStore, toMatchExpression, toSearchTerms } from './store.js';
9
+
10
+ const INDEX_FILE = 'message-search.sqlite';
11
+ // Whether the file holds reasoning rows, so a start can tell what to redo.
12
+ const REASONING_META_KEY = 'reasoning';
13
+ // SQLite's write-ahead log and its shared-memory index live beside the file.
14
+ const INDEX_FILE_SUFFIXES = ['', '-wal', '-shm'];
15
+ const MAX_LIMIT = 200;
16
+
17
+ // The hub's envelope: `directory` is 'global' for events with no location.
18
+ const envelopeSchema = z.object({ directory: z.string().nullish() });
19
+ const payloadDirectorySchema = z.object({ properties: z.object({ directory: z.string() }) });
20
+
21
+ /**
22
+ * Owns the search index for this server's OpenCode. Search is opt-in
23
+ * (`messageSearchEnabled`): while it is off nothing runs, no file is opened,
24
+ * no event is looked at. Turning it on opens the index, follows the event
25
+ * stream and walks the session list, which fills in whatever changed while it
26
+ * was off. Turning it off stops all of that and keeps the file, so the next
27
+ * start only catches up. Without a SQLite builtin search is unsupported.
28
+ *
29
+ * Reasoning is a second opt-in (`messageSearchReasoningEnabled`). Turning it
30
+ * on makes the next walk read every session's agent records again; turning it
31
+ * off drops the reasoning rows at once.
32
+ */
33
+ export const createMessageSearchRuntime = ({
34
+ dataDir,
35
+ buildOpenCodeUrl,
36
+ getOpenCodeAuthHeaders,
37
+ globalEventHub,
38
+ // () => Promise<{ enabled: boolean, reasoning: boolean }>, from settings.json.
39
+ readSettings,
40
+ logger = console,
41
+ }) => {
42
+ const indexPath = path.join(dataDir, INDEX_FILE);
43
+ const open = loadSqliteOpener();
44
+ let enabled = false;
45
+ let reasoning = false;
46
+ let engine = null;
47
+ let failed = false;
48
+ // Start, stop and delete run one after another, in the order asked.
49
+ let transition = Promise.resolve();
50
+ const enqueue = (work) => {
51
+ const run = transition.then(work);
52
+ transition = run.catch((error) => {
53
+ logger.warn?.('[message-search]', error?.message ?? error);
54
+ });
55
+ return run;
56
+ };
57
+
58
+ const createClient = (directory) => {
59
+ const headers = { ...getOpenCodeAuthHeaders() };
60
+ // v2 scopes by header and rejects non-ASCII header values.
61
+ if (directory) headers['x-opencode-directory'] = encodeURIComponent(directory);
62
+ return OpenCode.make({ baseUrl: buildOpenCodeUrl('/', '').replace(/\/$/, ''), headers });
63
+ };
64
+
65
+ // Brings the file in line with the reasoning switch. True when reasoning has
66
+ // to be read in, which the next session walk does.
67
+ const reconcileReasoning = (store) => {
68
+ const indexed = store.readMeta(REASONING_META_KEY) === '1';
69
+ if (reasoning && !indexed) {
70
+ store.rereadAssistantRecords();
71
+ store.writeMeta(REASONING_META_KEY, '1');
72
+ return true;
73
+ }
74
+ // Always, not only on a change: a session read while the switch flipped
75
+ // off can leave a stray row behind.
76
+ if (!reasoning) {
77
+ store.deleteRole('reasoning');
78
+ store.writeMeta(REASONING_META_KEY, '0');
79
+ }
80
+ return false;
81
+ };
82
+
83
+ const startEngine = () => {
84
+ const store = openMessageSearchStore(open(indexPath));
85
+ reconcileReasoning(store);
86
+ const indexer = createMessageSearchIndexer({ store, createClient, includeReasoning: () => reasoning, logger });
87
+ const unsubscribeEvents = globalEventHub.subscribeEvent((event) => {
88
+ const envelope = envelopeSchema.safeParse(event);
89
+ const directory = envelope.success && envelope.data.directory !== 'global' ? envelope.data.directory ?? '' : '';
90
+ for (const payload of event?.translated?.() ?? []) {
91
+ const own = payloadDirectorySchema.safeParse(payload);
92
+ indexer.processPayload(payload, directory || (own.success ? own.data.properties.directory : ''));
93
+ }
94
+ });
95
+ const unsubscribeStatus = globalEventHub.subscribeStatus((status) => {
96
+ if (status?.type === 'connect') indexer.onConnected();
97
+ });
98
+ if (globalEventHub.isConnected?.()) indexer.onConnected();
99
+ return {
100
+ store,
101
+ indexer,
102
+ stop: async () => {
103
+ unsubscribeEvents?.();
104
+ unsubscribeStatus?.();
105
+ indexer.stop();
106
+ // A session being read finishes before the file closes under it.
107
+ await indexer.idle();
108
+ store.close();
109
+ },
110
+ };
111
+ };
112
+
113
+ const apply = async () => {
114
+ if (enabled && !engine && open) {
115
+ try {
116
+ engine = startEngine();
117
+ failed = false;
118
+ } catch (error) {
119
+ failed = true;
120
+ logger.warn?.('[message-search] index unavailable:', error?.message ?? error);
121
+ }
122
+ } else if (!enabled && engine) {
123
+ const running = engine;
124
+ engine = null;
125
+ await running.stop();
126
+ }
127
+ };
128
+
129
+ const indexSize = async () => {
130
+ let bytes = 0;
131
+ for (const suffix of INDEX_FILE_SUFFIXES) {
132
+ const stat = await fsPromises.stat(`${indexPath}${suffix}`).catch(() => null);
133
+ if (stat) bytes += stat.size;
134
+ }
135
+ return bytes;
136
+ };
137
+
138
+ if (open) {
139
+ void enqueue(async () => {
140
+ const settings = await readSettings();
141
+ enabled = settings.enabled === true;
142
+ reasoning = settings.reasoning === true;
143
+ await apply();
144
+ });
145
+ }
146
+
147
+ return {
148
+ supported: Boolean(open),
149
+
150
+ /** Follows the setting; called after `messageSearchEnabled` is saved. */
151
+ setEnabled: (next) => enqueue(async () => {
152
+ enabled = next === true;
153
+ await apply();
154
+ }),
155
+
156
+ /** Follows `messageSearchReasoningEnabled`; applied to the file only while search runs. */
157
+ setReasoningEnabled: (next) => enqueue(async () => {
158
+ reasoning = next === true;
159
+ if (engine && reconcileReasoning(engine.store) && globalEventHub.isConnected?.()) engine.indexer.onConnected();
160
+ }),
161
+
162
+ /**
163
+ * Deletes the index file. While search is on, a fresh one is started at
164
+ * once, so this is "rebuild"; while it is off, the disk space comes back.
165
+ */
166
+ deleteIndex: () => enqueue(async () => {
167
+ if (engine) {
168
+ const running = engine;
169
+ engine = null;
170
+ await running.stop();
171
+ }
172
+ for (const suffix of INDEX_FILE_SUFFIXES) {
173
+ await fsPromises.rm(`${indexPath}${suffix}`, { force: true });
174
+ }
175
+ await apply();
176
+ }),
177
+
178
+ /**
179
+ * `null` match means the query has no word long enough to look up. The
180
+ * answer then says so instead of pretending nothing matched. `null`
181
+ * overall means no index is running.
182
+ */
183
+ search: ({ query, sessionId, directories, role, includeReasoning, before, limit, order }) => {
184
+ if (!engine) return null;
185
+ const match = toMatchExpression(query);
186
+ if (!match) return { status: 'query-too-short', hits: [] };
187
+ const size = Math.min(Math.max(1, limit), MAX_LIMIT);
188
+ const hits = engine.store.search({
189
+ match,
190
+ sessionId,
191
+ directories,
192
+ role,
193
+ // Stray rows from a switch that just flipped off stay out too.
194
+ includeReasoning: reasoning && includeReasoning !== false,
195
+ before,
196
+ limit: size + 1,
197
+ order,
198
+ });
199
+ const terms = toSearchTerms(query);
200
+ const page = hits.slice(0, size);
201
+ const last = page[page.length - 1];
202
+ return {
203
+ status: 'ok',
204
+ hits: page.map((hit) => ({
205
+ id: hit.id,
206
+ sessionId: hit.sessionId,
207
+ role: hit.role,
208
+ createdAt: hit.createdAt,
209
+ sessionTitle: hit.sessionTitle,
210
+ directory: hit.directory,
211
+ snippet: buildSnippet(hit.text, terms),
212
+ })),
213
+ // Pages by row: a reply and its reasoning share the message id.
214
+ next: hits.length > size && last ? { createdAt: last.createdAt, id: last.rowId } : null,
215
+ index: engine.indexer.status(),
216
+ };
217
+ },
218
+
219
+ /** What the Settings page shows; the counts exist only while the index is open. */
220
+ status: async () => {
221
+ if (!open) return { state: 'unsupported', sizeBytes: 0, index: null };
222
+ // A switch or delete already asked for is reported as done.
223
+ await transition;
224
+ const sizeBytes = await indexSize();
225
+ if (engine) return { state: 'on', sizeBytes, index: engine.indexer.status() };
226
+ return { state: enabled && failed ? 'failed' : 'off', sizeBytes, index: null };
227
+ },
228
+
229
+ stop: () => enqueue(async () => {
230
+ enabled = false;
231
+ await apply();
232
+ }),
233
+ };
234
+ };
@@ -0,0 +1,108 @@
1
+ import fs from 'node:fs';
2
+ import os from 'node:os';
3
+ import path from 'node:path';
4
+ import { afterEach, beforeEach, describe, expect, it } from 'vitest';
5
+
6
+ import { createMessageSearchRuntime } from './runtime.js';
7
+
8
+ // The hub as the runtime sees it: who is listening, nothing else. It stays
9
+ // disconnected so no background walk reaches for an OpenCode.
10
+ const createHub = () => {
11
+ const listeners = { event: 0, status: 0 };
12
+ return {
13
+ listeners,
14
+ subscribeEvent: () => {
15
+ listeners.event += 1;
16
+ return () => { listeners.event -= 1; };
17
+ },
18
+ subscribeStatus: () => {
19
+ listeners.status += 1;
20
+ return () => { listeners.status -= 1; };
21
+ },
22
+ isConnected: () => false,
23
+ };
24
+ };
25
+
26
+ describe('message search runtime', () => {
27
+ let dataDir;
28
+ let hub;
29
+ const indexFile = () => path.join(dataDir, 'message-search.sqlite');
30
+ const create = (enabled, reasoning = false) => createMessageSearchRuntime({
31
+ dataDir,
32
+ buildOpenCodeUrl: () => 'http://127.0.0.1:1/',
33
+ getOpenCodeAuthHeaders: () => ({}),
34
+ globalEventHub: hub,
35
+ readSettings: async () => ({ enabled, reasoning }),
36
+ logger: { warn: () => {} },
37
+ });
38
+
39
+ beforeEach(() => {
40
+ dataDir = fs.mkdtempSync(path.join(os.tmpdir(), 'message-search-runtime-'));
41
+ hub = createHub();
42
+ });
43
+ afterEach(() => {
44
+ fs.rmSync(dataDir, { recursive: true, force: true });
45
+ });
46
+
47
+ it('does nothing while the setting is off: no file, no listener, no answers', async () => {
48
+ const runtime = create(false);
49
+ const status = await runtime.status();
50
+ expect(status).toEqual({ state: 'off', sizeBytes: 0, index: null });
51
+ expect(fs.existsSync(indexFile())).toBe(false);
52
+ expect(hub.listeners).toEqual({ event: 0, status: 0 });
53
+ expect(runtime.search({ query: 'anything', limit: 5 })).toBeNull();
54
+ });
55
+
56
+ it('starts from the saved setting and follows it afterwards, keeping the file when switched off', async () => {
57
+ const runtime = create(true);
58
+ expect((await runtime.status()).state).toBe('on');
59
+ expect(hub.listeners).toEqual({ event: 1, status: 1 });
60
+ expect(runtime.search({ query: 'anything', limit: 5 })).toMatchObject({ status: 'ok', hits: [] });
61
+
62
+ await runtime.setEnabled(false);
63
+ const off = await runtime.status();
64
+ expect(off.state).toBe('off');
65
+ expect(off.sizeBytes).toBeGreaterThan(0);
66
+ expect(hub.listeners).toEqual({ event: 0, status: 0 });
67
+ expect(runtime.search({ query: 'anything', limit: 5 })).toBeNull();
68
+
69
+ await runtime.setEnabled(true);
70
+ expect((await runtime.status()).state).toBe('on');
71
+ expect(hub.listeners).toEqual({ event: 1, status: 1 });
72
+ await runtime.stop();
73
+ });
74
+
75
+ it('deletes the file while off, and starts a fresh index when deleted while on', async () => {
76
+ const runtime = create(true);
77
+ await runtime.setEnabled(false);
78
+ expect(fs.existsSync(indexFile())).toBe(true);
79
+ await runtime.deleteIndex();
80
+ expect(fs.existsSync(indexFile())).toBe(false);
81
+ expect(await runtime.status()).toEqual({ state: 'off', sizeBytes: 0, index: null });
82
+
83
+ await runtime.setEnabled(true);
84
+ await runtime.deleteIndex();
85
+ const rebuilt = await runtime.status();
86
+ expect(rebuilt.state).toBe('on');
87
+ expect(rebuilt.index).toMatchObject({ sessions: 0, messages: 0 });
88
+ expect(hub.listeners).toEqual({ event: 1, status: 1 });
89
+ await runtime.stop();
90
+ expect(hub.listeners).toEqual({ event: 0, status: 0 });
91
+ });
92
+
93
+ it('records whether reasoning is indexed and follows its switch only while search runs', async () => {
94
+ const runtime = create(true);
95
+ await runtime.status();
96
+ await runtime.setReasoningEnabled(true);
97
+ await runtime.setEnabled(false);
98
+ await runtime.setReasoningEnabled(false);
99
+ await runtime.setEnabled(true);
100
+ expect((await runtime.status()).state).toBe('on');
101
+ await runtime.stop();
102
+
103
+ const { DatabaseSync } = await import('node:sqlite');
104
+ const db = new DatabaseSync(indexFile(), { readOnly: true });
105
+ expect(db.prepare("SELECT value FROM meta WHERE key = 'reasoning'").get().value).toBe('0');
106
+ db.close();
107
+ });
108
+ });
@@ -0,0 +1,74 @@
1
+ import { createRequire } from 'node:module';
2
+
3
+ /**
4
+ * A SQLite connection from the runtime's builtin: `node:sqlite` on Node and
5
+ * Electron, `bun:sqlite` on Bun. No dependency is added. `null` when neither
6
+ * exists; the caller then has no index rather than a crash.
7
+ *
8
+ * Statements are prepared once per SQL string: the indexer inserts the same
9
+ * few statements tens of thousands of times during a backfill.
10
+ */
11
+ let opener;
12
+
13
+ const wrap = (db, prepare) => {
14
+ const statements = new Map();
15
+ const statement = (sql) => {
16
+ let prepared = statements.get(sql);
17
+ if (!prepared) {
18
+ prepared = prepare(sql);
19
+ statements.set(sql, prepared);
20
+ }
21
+ return prepared;
22
+ };
23
+ return {
24
+ exec: (sql) => db.exec(sql),
25
+ all: (sql, params = []) => statement(sql).all(...params),
26
+ get: (sql, params = []) => statement(sql).get(...params) ?? null,
27
+ run: (sql, params = []) => {
28
+ statement(sql).run(...params);
29
+ },
30
+ transaction: (work) => {
31
+ db.exec('BEGIN');
32
+ try {
33
+ const result = work();
34
+ db.exec('COMMIT');
35
+ return result;
36
+ } catch (error) {
37
+ db.exec('ROLLBACK');
38
+ throw error;
39
+ }
40
+ },
41
+ close: () => {
42
+ statements.clear();
43
+ db.close();
44
+ },
45
+ };
46
+ };
47
+
48
+ export const loadSqliteOpener = () => {
49
+ if (opener !== undefined) return opener;
50
+ const require = createRequire(import.meta.url);
51
+ opener = null;
52
+ try {
53
+ const { DatabaseSync } = process.getBuiltinModule?.('node:sqlite') ?? require('node:sqlite');
54
+ new DatabaseSync(':memory:').close();
55
+ opener = (dbPath) => {
56
+ const db = new DatabaseSync(dbPath);
57
+ return wrap(db, (sql) => db.prepare(sql));
58
+ };
59
+ return opener;
60
+ } catch {
61
+ // Not Node, or a Node without node:sqlite; try Bun next.
62
+ }
63
+ try {
64
+ const { Database } = require('bun:sqlite');
65
+ new Database(':memory:').close();
66
+ opener = (dbPath) => {
67
+ const db = new Database(dbPath);
68
+ return wrap(db, (sql) => db.query(sql));
69
+ };
70
+ } catch {
71
+ // No sqlite runtime at all.
72
+ }
73
+ return opener;
74
+ };