@openchamber/web 1.18.4 → 1.20.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 (251) hide show
  1. package/README.md +1 -0
  2. package/dist/assets/{CodeMirrorCommentWidgets-4qZbrEXU.js → CodeMirrorCommentWidgets-C36E738Y.js} +1 -1
  3. package/dist/assets/{CommitSection-MJmntVPJ.js → CommitSection-C-F3AX6D.js} +1 -1
  4. package/dist/assets/{DiagramEditor-jnG3Hbxg.js → DiagramEditor-BPECg1jS.js} +1 -1
  5. package/dist/assets/DiagramView-D0YNMix8.js +1 -0
  6. package/dist/assets/DiffView-BHWaMYCC.js +4 -0
  7. package/dist/assets/FilesView-NMBCW2Tm.js +14 -0
  8. package/dist/assets/{GitView-DBFrDDBv.js → GitView-Rp8P1KEI.js} +4 -4
  9. package/dist/assets/{JsonTreeView-DLW2Wy1g.js → JsonTreeView-KnXFN2A-.js} +1 -1
  10. package/dist/assets/MarkdownImageGallery-BMn3mtor.js +1 -0
  11. package/dist/assets/MarkdownRendererImpl-kD6N03pH.js +12 -0
  12. package/dist/assets/OnboardingScreen-CenIeD4v.js +1 -0
  13. package/dist/assets/{PatchDiff-BuLPx7AN.js → PatchDiff-BzVOVog8.js} +1 -1
  14. package/dist/assets/{PierreDiffViewer-BHm4Yr0X.js → PierreDiffViewer-Dlby4XqT.js} +2 -2
  15. package/dist/assets/PlanView-Czu1KMJa.js +4 -0
  16. package/dist/assets/SessionSwitcherDropdown-IETz58DB.js +1 -0
  17. package/dist/assets/SettingsView-B6vmuf-c.js +28 -0
  18. package/dist/assets/SettingsWindow-CauZpdD3.js +1 -0
  19. package/dist/assets/ToolOutputDialog-BB1c--Zr.js +15 -0
  20. package/dist/assets/ToolPartDiffPreview-DaOIDISD.js +8 -0
  21. package/dist/assets/{VirtualizedFileDiff-CwGocYQd.js → VirtualizedFileDiff-lESMT-2b.js} +4 -4
  22. package/dist/assets/{WalkthroughView-5DyvN03T.js → WalkthroughView-CaSYE0lw.js} +2 -2
  23. package/dist/assets/{computeVirtualFileMetrics-Da00Jg7M.js → computeVirtualFileMetrics-DkRR5b75.js} +2 -2
  24. package/dist/assets/contextPanelEmbeddedChat-BEARQjgn.js +1 -0
  25. package/dist/assets/de-DFdX3ABv.js +9 -0
  26. package/dist/assets/document-attachments-DFAWlG3U.js +31 -0
  27. package/dist/assets/es-iC-FKvV9.js +15 -0
  28. package/dist/assets/fr-BBbi_1AL.js +13 -0
  29. package/dist/assets/index-BiEgzzkg.js +1 -0
  30. package/dist/assets/index-Cwmuwk3V.js +7 -0
  31. package/dist/assets/index-GNm1wgUH.css +1 -0
  32. package/dist/assets/{isDiffPlainText-D9YpoLrV.js → isDiffPlainText-BG53Ixxy.js} +1 -1
  33. package/dist/assets/{isFilePlainText-gTibdNIe.js → isFilePlainText-BbV-39jl.js} +1 -1
  34. package/dist/assets/ja-DQLQJL2J.js +15 -0
  35. package/dist/assets/ko-BeElEB4Y.js +15 -0
  36. package/dist/assets/{lua-BgMRiT3U.js → lua-VAEuO923.js} +1 -1
  37. package/dist/assets/main-Dpzo18z7.js +2 -0
  38. package/dist/assets/main-WMjtYzJs.js +921 -0
  39. package/dist/assets/markdownCore--tDmyI_v.js +2 -0
  40. package/dist/assets/miniChat-ldEghBLB.js +2 -0
  41. package/dist/assets/mobile-Dk-VGreF.js +2 -0
  42. package/dist/assets/{patchFileDiff-KNkxM1C1.js → patchFileDiff-BcFaMtMu.js} +1 -1
  43. package/dist/assets/pl-CLHt2_vV.js +15 -0
  44. package/dist/assets/pt-BR-C_MPUq7e.js +15 -0
  45. package/dist/assets/renderElectronMiniChatApp-DIgCOmXY.js +2 -0
  46. package/dist/assets/renderMobileApp-CDfHS5rr.js +25 -0
  47. package/dist/assets/runtimeEndpointReset-ovNbaZ-x.js +15 -0
  48. package/dist/assets/scheduledTasksApi-BFSlqgnG.js +1 -0
  49. package/dist/assets/{shikiHighlight-C7LTbwFx.js → shikiHighlight-DCT2Sq_z.js} +1 -1
  50. package/dist/assets/uk-PhsC-c4-.js +15 -0
  51. package/dist/assets/{useAppFontEffects-BikB6enL.js → useAppFontEffects-B53Rb6m7.js} +168 -164
  52. package/dist/assets/useInlineCommentController-DSfrIBKT.js +2 -0
  53. package/dist/assets/{vendor-base-ui-D_V6hAcE.js → vendor-base-ui-DsHmyMwp.js} +1 -1
  54. package/dist/assets/vendor-codemirror-autocomplete-DzPz9Wgq.js +1 -0
  55. package/dist/assets/vendor-codemirror-commands-B7H_j0iU.js +1 -0
  56. package/dist/assets/{vendor-codemirror-lang-angular-CgY7_gQ1.js → vendor-codemirror-lang-angular-DEPs2M5t.js} +1 -1
  57. package/dist/assets/{vendor-codemirror-lang-cpp-B5Ta4enQ.js → vendor-codemirror-lang-cpp-DhkseaMo.js} +1 -1
  58. package/dist/assets/{vendor-codemirror-lang-css-VgNqFSH-.js → vendor-codemirror-lang-css-O0cZX78y.js} +1 -1
  59. package/dist/assets/{vendor-codemirror-lang-go-LxLz62pp.js → vendor-codemirror-lang-go-fMdQYcON.js} +1 -1
  60. package/dist/assets/vendor-codemirror-lang-html-CfgK872x.js +1 -0
  61. package/dist/assets/{vendor-codemirror-lang-java-Bksi1PH4.js → vendor-codemirror-lang-java-CQj4S3zl.js} +1 -1
  62. package/dist/assets/vendor-codemirror-lang-javascript-Cc2ZYbgX.js +13 -0
  63. package/dist/assets/{vendor-codemirror-lang-jinja-C7npuDD7.js → vendor-codemirror-lang-jinja-BmZZv8g-.js} +1 -1
  64. package/dist/assets/{vendor-codemirror-lang-json-ryCw7nab.js → vendor-codemirror-lang-json-CMBS2tG9.js} +1 -1
  65. package/dist/assets/{vendor-codemirror-lang-less-BxsZJD6N.js → vendor-codemirror-lang-less-C6Eo8hVS.js} +1 -1
  66. package/dist/assets/{vendor-codemirror-lang-liquid-De6qch10.js → vendor-codemirror-lang-liquid-DSTR47-H.js} +1 -1
  67. package/dist/assets/vendor-codemirror-lang-markdown-BPGOH9ye.js +1 -0
  68. package/dist/assets/{vendor-codemirror-lang-php-Cm1es33p.js → vendor-codemirror-lang-php-DD9udfPH.js} +1 -1
  69. package/dist/assets/{vendor-codemirror-lang-python-N414WYK-.js → vendor-codemirror-lang-python-HahnQaAS.js} +1 -1
  70. package/dist/assets/{vendor-codemirror-lang-rust-C_WuUStH.js → vendor-codemirror-lang-rust-nLTovbjv.js} +1 -1
  71. package/dist/assets/{vendor-codemirror-lang-sass-8UHTCAOM.js → vendor-codemirror-lang-sass-pL2Yc72v.js} +1 -1
  72. package/dist/assets/{vendor-codemirror-lang-sql-CV3sMA5D.js → vendor-codemirror-lang-sql-BVBnan19.js} +1 -1
  73. package/dist/assets/{vendor-codemirror-lang-vue-DzvC1Dhk.js → vendor-codemirror-lang-vue-BqGzJVm1.js} +1 -1
  74. package/dist/assets/{vendor-codemirror-lang-wast-jlr-LDdA.js → vendor-codemirror-lang-wast-B0_m5DqU.js} +1 -1
  75. package/dist/assets/{vendor-codemirror-lang-xml-CrO63OVp.js → vendor-codemirror-lang-xml-Dj3voadT.js} +1 -1
  76. package/dist/assets/{vendor-codemirror-lang-yaml-dxi6CISW.js → vendor-codemirror-lang-yaml-yu-9Z5u7.js} +1 -1
  77. package/dist/assets/vendor-codemirror-language-BgPj_McA.js +3 -0
  78. package/dist/assets/{vendor-codemirror-language-data-CLHw8NWn.js → vendor-codemirror-language-data-vch3tJ4c.js} +2 -2
  79. package/dist/assets/vendor-codemirror-search-BmS-GmcX.js +2 -0
  80. package/dist/assets/{vendor-codemirror-state-CNWM3Q8V.js → vendor-codemirror-state-C9awkmn-.js} +5 -5
  81. package/dist/assets/vendor-codemirror-view-CiLROUVV.js +4 -0
  82. package/dist/assets/vendor-replit-codemirror-vim-B2DJlAhT.js +6 -0
  83. package/dist/assets/vendor-replit-codemirror-vim-core-FHzKdNUS.js +34 -0
  84. package/dist/assets/vendor-zod-C9ioTTSo.js +39 -0
  85. package/dist/assets/{web-components-GMc3oR3i.js → web-components-pcwCTWjC.js} +4 -4
  86. package/dist/assets/zh-CN-wF-NOFHM.js +15 -0
  87. package/dist/assets/zh-TW-4m4-A7rT.js +15 -0
  88. package/dist/index.html +5 -4
  89. package/dist/mini-chat.html +4 -3
  90. package/dist/mobile.html +4 -3
  91. package/package.json +3 -5
  92. package/server/index.js +152 -3
  93. package/server/lib/agent-memory/actions.js +243 -0
  94. package/server/lib/agent-memory/actions.test.js +343 -0
  95. package/server/lib/agent-memory/feature-flag.js +19 -0
  96. package/server/lib/agent-memory/feature-flag.test.js +38 -0
  97. package/server/lib/agent-memory/project-resolution.js +65 -0
  98. package/server/lib/agent-memory/project-resolution.test.js +94 -0
  99. package/server/lib/agent-memory/routes.http.test.js +270 -0
  100. package/server/lib/agent-memory/routes.js +169 -0
  101. package/server/lib/agent-memory/runtime.js +432 -0
  102. package/server/lib/agent-memory/runtime.test.js +344 -0
  103. package/server/lib/agent-memory/threat-patterns.js +61 -0
  104. package/server/lib/agent-memory/threat-patterns.test.js +61 -0
  105. package/server/lib/agent-tool/DOCUMENTATION.md +14 -0
  106. package/server/lib/agent-tool/runtime.js +63 -13
  107. package/server/lib/agent-tool/runtime.test.js +85 -2
  108. package/server/lib/context-obligatory/runtime.js +34 -3
  109. package/server/lib/context-obligatory/runtime.test.js +114 -0
  110. package/server/lib/dictation/DOCUMENTATION.md +32 -8
  111. package/server/lib/dictation/local/sherpa-recognizer.js +35 -78
  112. package/server/lib/dictation/local/worker-process.js +2 -2
  113. package/server/lib/dictation/openai-compatible-session.js +3 -2
  114. package/server/lib/dictation/stream-manager.js +77 -34
  115. package/server/lib/dictation/stream-manager.test.js +60 -2
  116. package/server/lib/fs/DOCUMENTATION.md +3 -0
  117. package/server/lib/fs/routes.js +149 -32
  118. package/server/lib/fs/routes.test.js +301 -0
  119. package/server/lib/git/DOCUMENTATION.md +8 -0
  120. package/server/lib/git/routes.js +43 -0
  121. package/server/lib/git/service.js +206 -72
  122. package/server/lib/git/service.test.js +222 -0
  123. package/server/lib/github/DOCUMENTATION.md +14 -3
  124. package/server/lib/github/pr-status.js +188 -83
  125. package/server/lib/github/pr-status.test.js +182 -0
  126. package/server/lib/github/routes.js +36 -30
  127. package/server/lib/notifications/template-runtime.js +2 -3
  128. package/server/lib/openchamber-control/action-resolution.test.js +65 -0
  129. package/server/lib/openchamber-control/actions.js +78 -0
  130. package/server/lib/openchamber-control/service.js +7 -0
  131. package/server/lib/openchamber-sessions/routes.js +14 -0
  132. package/server/lib/opencode/DOCUMENTATION.md +12 -6
  133. package/server/lib/opencode/claude-cli-auth.js +60 -0
  134. package/server/lib/opencode/claude-cli-auth.test.js +54 -0
  135. package/server/lib/opencode/feature-routes-runtime.js +16 -9
  136. package/server/lib/opencode/lifecycle.js +202 -26
  137. package/server/lib/opencode/lifecycle.test.js +179 -1
  138. package/server/lib/opencode/plugins.js +12 -3
  139. package/server/lib/opencode/plugins.test.js +18 -0
  140. package/server/lib/opencode/providers.js +9 -4
  141. package/server/lib/opencode/providers.test.js +27 -0
  142. package/server/lib/opencode/proxy-agent-wiring.test.js +152 -0
  143. package/server/lib/opencode/proxy.js +116 -6
  144. package/server/lib/opencode/proxy.test.js +158 -1
  145. package/server/lib/opencode/restart-session-recovery.test.js +59 -0
  146. package/server/lib/opencode/routes.js +4 -1
  147. package/server/lib/opencode/session-runtime.js +39 -2
  148. package/server/lib/opencode/session-runtime.test.js +74 -0
  149. package/server/lib/opencode/settings-helpers.js +26 -0
  150. package/server/lib/opencode/settings-helpers.test.js +57 -0
  151. package/server/lib/opencode/settings-normalization-runtime.js +3 -0
  152. package/server/lib/opencode/settings-normalization-runtime.test.js +16 -0
  153. package/server/lib/opencode/settings-runtime.js +83 -10
  154. package/server/lib/opencode/settings-runtime.test.js +85 -0
  155. package/server/lib/opencode/shared.js +120 -16
  156. package/server/lib/opencode/shared.test.js +185 -1
  157. package/server/lib/opencode/skill-routes.js +29 -73
  158. package/server/lib/opencode/skill-routes.test.js +2 -5
  159. package/server/lib/project-context/DOCUMENTATION.md +160 -0
  160. package/server/lib/project-context/routes.http.test.js +264 -0
  161. package/server/lib/project-context/routes.js +237 -0
  162. package/server/lib/project-context/runtime.js +672 -0
  163. package/server/lib/project-context/runtime.test.js +498 -0
  164. package/server/lib/projects/project-config.js +7 -2
  165. package/server/lib/quota/DOCUMENTATION.md +17 -2
  166. package/server/lib/quota/providers/claude/auth.js +113 -0
  167. package/server/lib/quota/providers/claude/auth.test.js +117 -0
  168. package/server/lib/quota/providers/claude/index.js +151 -0
  169. package/server/lib/quota/providers/claude/index.test.js +147 -0
  170. package/server/lib/quota/providers/claude/transforms.js +127 -0
  171. package/server/lib/quota/providers/claude/transforms.test.js +82 -0
  172. package/server/lib/quota/providers/command-code.js +90 -0
  173. package/server/lib/quota/providers/command-code.test.js +85 -0
  174. package/server/lib/quota/providers/index.js +30 -2
  175. package/server/lib/quota/providers/index.test.js +10 -1
  176. package/server/lib/quota/providers/zai.js +26 -6
  177. package/server/lib/quota/providers/zai.test.js +33 -0
  178. package/server/lib/quota/utils/formatters.js +2 -1
  179. package/server/lib/scheduled-tasks/runtime.js +21 -2
  180. package/server/lib/session-knowledge/DOCUMENTATION.md +89 -0
  181. package/server/lib/session-knowledge/routes.js +107 -0
  182. package/server/lib/session-knowledge/runtime.js +331 -0
  183. package/server/lib/session-knowledge/runtime.test.js +275 -0
  184. package/server/lib/skills-catalog/DOCUMENTATION.md +18 -45
  185. package/server/lib/skills-catalog/cache.js +120 -1
  186. package/server/lib/skills-catalog/cache.test.js +77 -0
  187. package/server/lib/skills-catalog/curated-sources.js +21 -5
  188. package/server/lib/skills-catalog/curated-sources.test.js +10 -0
  189. package/server/lib/skills-catalog/disk-cache.js +52 -0
  190. package/server/lib/skills-catalog/github-meta.js +139 -0
  191. package/server/lib/skills-catalog/github-meta.test.js +71 -0
  192. package/server/lib/skills-catalog/source.js +0 -5
  193. package/server/lib/small-model/DOCUMENTATION.md +74 -6
  194. package/server/lib/small-model/call.js +46 -12
  195. package/server/lib/small-model/call.test.js +79 -0
  196. package/server/lib/small-model/index.js +57 -6
  197. package/server/lib/small-model/index.test.js +102 -2
  198. package/server/lib/small-model/routes.js +4 -2
  199. package/server/lib/small-model/runtime-providers.js +156 -0
  200. package/server/lib/small-model/runtime-providers.test.js +112 -0
  201. package/dist/assets/DiagramView-CFXxgg_a.js +0 -1
  202. package/dist/assets/DiffView-DZIoOnV7.js +0 -4
  203. package/dist/assets/FilesView-BKL6YlKG.js +0 -14
  204. package/dist/assets/MarkdownImageGallery-DKIylIK7.js +0 -1
  205. package/dist/assets/MarkdownRendererImpl-CLv8hxvv.js +0 -12
  206. package/dist/assets/OnboardingScreen-D2Y6djMw.js +0 -1
  207. package/dist/assets/PlanView-ZYEJn8A_.js +0 -4
  208. package/dist/assets/SessionSwitcherDropdown-rro-SsaO.js +0 -1
  209. package/dist/assets/SettingsView-5RmswFZe.js +0 -28
  210. package/dist/assets/SettingsWindow-BZhAYFdS.js +0 -1
  211. package/dist/assets/ToolOutputDialog-Za6V4VMJ.js +0 -15
  212. package/dist/assets/ToolPartDiffPreview-BL-9ixyC.js +0 -8
  213. package/dist/assets/contextPanelEmbeddedChat-B-bSg3P5.js +0 -1
  214. package/dist/assets/de-u7gSnqWs.js +0 -9
  215. package/dist/assets/document-attachments-CX_YaDsu.js +0 -30
  216. package/dist/assets/es-T9O7aAOr.js +0 -15
  217. package/dist/assets/fr-Oor7ewbE.js +0 -13
  218. package/dist/assets/index-BzIpNlNE.css +0 -1
  219. package/dist/assets/index-C0yNhuZw.js +0 -1
  220. package/dist/assets/index-DRpChWux.js +0 -7
  221. package/dist/assets/ja-DHpqbVmr.js +0 -15
  222. package/dist/assets/ko-CwLkS3nx.js +0 -15
  223. package/dist/assets/main-D7UcL3VQ.js +0 -2
  224. package/dist/assets/main-DPMd2iKS.js +0 -915
  225. package/dist/assets/markdownCore-DDrHVneM.js +0 -2
  226. package/dist/assets/miniChat-O_GVoEbc.js +0 -2
  227. package/dist/assets/mobile-Br4TtAqc.js +0 -2
  228. package/dist/assets/pl-CcZILN8q.js +0 -15
  229. package/dist/assets/pt-BR-DYHhVK6o.js +0 -15
  230. package/dist/assets/renderElectronMiniChatApp-CJpdxTT1.js +0 -2
  231. package/dist/assets/renderMobileApp-toj9cXoh.js +0 -25
  232. package/dist/assets/runtimeEndpointReset-BVmispdD.js +0 -13
  233. package/dist/assets/scheduledTasksApi-ByKya3Un.js +0 -1
  234. package/dist/assets/uk-BA2kZR38.js +0 -15
  235. package/dist/assets/useInlineCommentController-CYPvYJDt.js +0 -2
  236. package/dist/assets/vendor-codemirror-autocomplete-BjbBRsUA.js +0 -1
  237. package/dist/assets/vendor-codemirror-commands-ARAOgp1x.js +0 -1
  238. package/dist/assets/vendor-codemirror-lang-html-B3Qe3OpS.js +0 -1
  239. package/dist/assets/vendor-codemirror-lang-javascript-Bbw3D7r0.js +0 -13
  240. package/dist/assets/vendor-codemirror-lang-markdown-FGQydhTc.js +0 -1
  241. package/dist/assets/vendor-codemirror-language-DUOssd4j.js +0 -3
  242. package/dist/assets/vendor-codemirror-search-8kyQdB3f.js +0 -2
  243. package/dist/assets/vendor-codemirror-view-DSzLbZiS.js +0 -4
  244. package/dist/assets/vendor-replit-codemirror-vim-B0Ecqnlh.js +0 -39
  245. package/dist/assets/zh-CN-dlOQK6v9.js +0 -15
  246. package/dist/assets/zh-TW-BnqQ-WL5.js +0 -15
  247. package/server/lib/quota/providers/claude.js +0 -107
  248. package/server/lib/skills-catalog/clawdhub/api.js +0 -126
  249. package/server/lib/skills-catalog/clawdhub/install.js +0 -238
  250. package/server/lib/skills-catalog/clawdhub/install.test.js +0 -100
  251. package/server/lib/skills-catalog/clawdhub/scan.js +0 -61
@@ -2,7 +2,7 @@ import fs from 'fs';
2
2
  import path from 'path';
3
3
  import os from 'os';
4
4
  import yaml from 'yaml';
5
- import { parse as parseJsonc } from 'jsonc-parser';
5
+ import { parse as parseJsonc, printParseErrorCode } from 'jsonc-parser';
6
6
 
7
7
  // ============== PATH CONSTANTS ==============
8
8
 
@@ -168,6 +168,42 @@ function getPrimaryUserConfigPath(userPaths) {
168
168
  return CONFIG_FILE;
169
169
  }
170
170
 
171
+ const INVALID_JSONC = 'INVALID_JSONC';
172
+
173
+ function isInvalidJsoncError(error) {
174
+ return Boolean(error && typeof error === 'object' && error.code === INVALID_JSONC);
175
+ }
176
+
177
+ function formatJsoncParseError(filePath, errors) {
178
+ const first = Array.isArray(errors) && errors.length > 0 ? errors[0] : null;
179
+ const location = first && Number.isFinite(first.offset)
180
+ ? ` (${printParseErrorCode(first.error)} at offset ${first.offset})`
181
+ : '';
182
+ return `OpenCode configuration at ${filePath} contains invalid JSONC and cannot be loaded safely${location}`;
183
+ }
184
+
185
+ function isCommentOnlyParse(parsed, errors) {
186
+ // Comment-only / whitespace-only files parse to undefined with nothing but
187
+ // ValueExpected. Any other error means real content we failed to understand
188
+ // (YAML, plain text, a stray leading token), which must not read as empty.
189
+ return parsed === undefined
190
+ && errors.every((entry) => printParseErrorCode(entry.error) === 'ValueExpected');
191
+ }
192
+
193
+ function parseConfigObject(content, filePath) {
194
+ const errors = [];
195
+ const parsed = parseJsonc(content, errors, { allowTrailingComma: true });
196
+ if (isCommentOnlyParse(parsed, errors)) {
197
+ return {};
198
+ }
199
+ if (errors.length > 0 || !parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
200
+ const error = new Error(formatJsoncParseError(filePath, errors));
201
+ error.code = INVALID_JSONC;
202
+ throw error;
203
+ }
204
+ return parsed;
205
+ }
206
+
171
207
  function readConfigFile(filePath) {
172
208
  if (!filePath || !fs.existsSync(filePath)) {
173
209
  return {};
@@ -178,8 +214,13 @@ function readConfigFile(filePath) {
178
214
  if (!normalized) {
179
215
  return {};
180
216
  }
181
- return parseJsonc(normalized, [], { allowTrailingComma: true });
217
+ // Refuse partial jsonc-parser trees. Ignoring errors previously let mutations
218
+ // rewrite a truncated object (often only `$schema`) over the full config.
219
+ return parseConfigObject(normalized, filePath);
182
220
  } catch (error) {
221
+ if (isInvalidJsoncError(error)) {
222
+ throw error;
223
+ }
183
224
  console.error(`Failed to read config file: ${filePath}`, error);
184
225
  throw new Error('Failed to read OpenCode configuration');
185
226
  }
@@ -209,20 +250,47 @@ function mergeConfigs(base, override) {
209
250
  return result;
210
251
  }
211
252
 
253
+ function readConfigLayer(filePath) {
254
+ try {
255
+ return { config: readConfigFile(filePath), error: null };
256
+ } catch (error) {
257
+ if (isInvalidJsoncError(error)) {
258
+ console.error(error.message);
259
+ return { config: {}, error };
260
+ }
261
+ throw error;
262
+ }
263
+ }
264
+
212
265
  function readConfigLayers(workingDirectory) {
213
266
  const { userPaths, projectPath, customPath } = getConfigPaths(workingDirectory);
214
267
  const userPath = getPrimaryUserConfigPath(userPaths);
215
- const userConfig = readConfigFile(userPath);
216
- const projectConfig = readConfigFile(projectPath);
217
- const customConfig = readConfigFile(customPath);
218
- const mergedConfig = mergeConfigs(mergeConfigs(userConfig, projectConfig), customConfig);
268
+ const userLayer = readConfigLayer(userPath);
269
+ const projectLayer = readConfigLayer(projectPath);
270
+ const customLayer = readConfigLayer(customPath);
271
+ const mergedConfig = mergeConfigs(
272
+ mergeConfigs(userLayer.config, projectLayer.config),
273
+ customLayer.config,
274
+ );
275
+
276
+ const layerErrors = [];
277
+ if (userLayer.error) {
278
+ layerErrors.push({ path: userPath, code: userLayer.error.code, message: userLayer.error.message });
279
+ }
280
+ if (projectLayer.error && projectPath) {
281
+ layerErrors.push({ path: projectPath, code: projectLayer.error.code, message: projectLayer.error.message });
282
+ }
283
+ if (customLayer.error && customPath) {
284
+ layerErrors.push({ path: customPath, code: customLayer.error.code, message: customLayer.error.message });
285
+ }
219
286
 
220
287
  return {
221
- userConfig,
222
- projectConfig,
223
- customConfig,
288
+ userConfig: userLayer.config,
289
+ projectConfig: projectLayer.config,
290
+ customConfig: customLayer.config,
224
291
  mergedConfig,
225
- paths: { userPath, projectPath, customPath }
292
+ paths: { userPath, projectPath, customPath },
293
+ layerErrors,
226
294
  };
227
295
  }
228
296
 
@@ -246,6 +314,12 @@ function getConfigForPath(layers, targetPath) {
246
314
  function writeConfig(config, filePath = CONFIG_FILE) {
247
315
  try {
248
316
  if (fs.existsSync(filePath)) {
317
+ // Defense in depth: never overwrite a file we cannot fully parse.
318
+ const existing = fs.readFileSync(filePath, 'utf8').trim();
319
+ if (existing) {
320
+ parseConfigObject(existing, filePath);
321
+ }
322
+
249
323
  const backupFile = `${filePath}.openchamber.backup`;
250
324
  fs.copyFileSync(filePath, backupFile);
251
325
  console.log(`Created config backup: ${backupFile}`);
@@ -255,23 +329,49 @@ function writeConfig(config, filePath = CONFIG_FILE) {
255
329
  fs.writeFileSync(filePath, JSON.stringify(config, null, 2), 'utf8');
256
330
  console.log(`Successfully wrote config file: ${filePath}`);
257
331
  } catch (error) {
332
+ if (isInvalidJsoncError(error)) {
333
+ throw error;
334
+ }
258
335
  console.error(`Failed to write config file: ${filePath}`, error);
259
336
  throw new Error('Failed to write OpenCode configuration');
260
337
  }
261
338
  }
262
339
 
340
+ function getLayerError(layers, filePath) {
341
+ if (!filePath || !Array.isArray(layers?.layerErrors)) {
342
+ return null;
343
+ }
344
+ return layers.layerErrors.find((entry) => entry.path === filePath) || null;
345
+ }
346
+
347
+ function throwIfLayerError(layers, filePath) {
348
+ const failed = getLayerError(layers, filePath);
349
+ if (!failed) {
350
+ return;
351
+ }
352
+ const error = new Error(failed.message);
353
+ error.code = failed.code;
354
+ throw error;
355
+ }
356
+
263
357
  function getJsonEntrySource(layers, sectionKey, entryName) {
264
358
  const { userConfig, projectConfig, customConfig, paths } = layers;
265
- const customSection = customConfig?.[sectionKey]?.[entryName];
266
- if (customSection !== undefined) {
267
- return { section: customSection, config: customConfig, path: paths.customPath, exists: true };
359
+ if (paths.customPath) {
360
+ throwIfLayerError(layers, paths.customPath);
361
+ const customSection = customConfig?.[sectionKey]?.[entryName];
362
+ if (customSection !== undefined) {
363
+ return { section: customSection, config: customConfig, path: paths.customPath, exists: true };
364
+ }
268
365
  }
269
366
 
270
- const projectSection = projectConfig?.[sectionKey]?.[entryName];
271
- if (projectSection !== undefined) {
272
- return { section: projectSection, config: projectConfig, path: paths.projectPath, exists: true };
367
+ if (paths.projectPath && !getLayerError(layers, paths.projectPath)) {
368
+ const projectSection = projectConfig?.[sectionKey]?.[entryName];
369
+ if (projectSection !== undefined) {
370
+ return { section: projectSection, config: projectConfig, path: paths.projectPath, exists: true };
371
+ }
273
372
  }
274
373
 
374
+ throwIfLayerError(layers, paths.userPath);
275
375
  const userSection = userConfig?.[sectionKey]?.[entryName];
276
376
  if (userSection !== undefined) {
277
377
  return { section: userSection, config: userConfig, path: paths.userPath, exists: true };
@@ -283,11 +383,14 @@ function getJsonEntrySource(layers, sectionKey, entryName) {
283
383
  function getJsonWriteTarget(layers, preferredScope) {
284
384
  const { userConfig, projectConfig, customConfig, paths } = layers;
285
385
  if (paths.customPath) {
386
+ throwIfLayerError(layers, paths.customPath);
286
387
  return { config: customConfig, path: paths.customPath };
287
388
  }
288
389
  if (preferredScope === AGENT_SCOPE.PROJECT && paths.projectPath) {
390
+ throwIfLayerError(layers, paths.projectPath);
289
391
  return { config: projectConfig, path: paths.projectPath };
290
392
  }
393
+ throwIfLayerError(layers, paths.userPath);
291
394
  return { config: userConfig, path: paths.userPath };
292
395
  }
293
396
 
@@ -547,6 +650,7 @@ export {
547
650
  parseMdFile,
548
651
  writeMdFile,
549
652
  readConfigFile,
653
+ readConfigLayer,
550
654
  isPlainObject,
551
655
  readConfigLayers,
552
656
  readConfig,
@@ -3,8 +3,9 @@ import fs from 'fs';
3
3
  import os from 'os';
4
4
  import path from 'path';
5
5
 
6
- import { parseMdFile, writeMdFile } from './shared.js';
6
+ import { parseMdFile, writeMdFile, readConfigFile, readConfigLayers, writeConfig } from './shared.js';
7
7
  import { updateAgent } from './agents.js';
8
+ import { updateMcpConfig } from './mcp.js';
8
9
 
9
10
  const FIXTURE_DIR = path.join(os.tmpdir(), `openchamber-shared-test-${process.pid}`);
10
11
 
@@ -200,3 +201,186 @@ describe('updateAgent frontmatter preservation', () => {
200
201
  expect(parsed.body).toBe('Body of strateg.');
201
202
  });
202
203
  });
204
+
205
+ describe('readConfigFile / writeConfig JSONC safety (issue #2923)', () => {
206
+ beforeEach(() => {
207
+ fs.rmSync(FIXTURE_DIR, { recursive: true, force: true });
208
+ fs.mkdirSync(FIXTURE_DIR, { recursive: true });
209
+ });
210
+
211
+ afterEach(() => {
212
+ fs.rmSync(FIXTURE_DIR, { recursive: true, force: true });
213
+ });
214
+
215
+ const VALID_CONFIG = [
216
+ '{',
217
+ ' "$schema": "https://opencode.ai/config.json",',
218
+ ' // keep me',
219
+ ' "plugin": ["opencode-see-image"],',
220
+ ' "mcp": {',
221
+ ' "openproject": {',
222
+ ' "type": "remote",',
223
+ ' "url": "https://openproject.example.com/mcp",',
224
+ ' "enabled": true,',
225
+ ' }',
226
+ ' },',
227
+ ' "provider": {',
228
+ ' "ollama-cloud": {',
229
+ ' "npm": "@ai-sdk/openai-compatible",',
230
+ ' "name": "Ollama Cloud"',
231
+ ' }',
232
+ ' }',
233
+ '}',
234
+ '',
235
+ ].join('\n');
236
+
237
+ // JSON5-style unquoted keys after $schema — jsonc-parser returns a partial
238
+ // tree of only `{ $schema }` when errors are ignored.
239
+ const PARTIAL_PARSE_CONFIG = [
240
+ '{',
241
+ ' "$schema": "https://opencode.ai/config.json",',
242
+ ' plugin: ["opencode-see-image"],',
243
+ ' mcp: {',
244
+ ' openproject: {',
245
+ ' type: "remote",',
246
+ ' url: "https://openproject.example.com/mcp",',
247
+ ' enabled: true',
248
+ ' }',
249
+ ' },',
250
+ ' provider: {',
251
+ ' "ollama-cloud": {',
252
+ ' npm: "@ai-sdk/openai-compatible",',
253
+ ' name: "Ollama Cloud"',
254
+ ' }',
255
+ ' }',
256
+ '}',
257
+ '',
258
+ ].join('\n');
259
+
260
+ it('parses valid JSONC with comments and trailing commas without dropping keys', () => {
261
+ const file = writeFixture('opencode.jsonc', VALID_CONFIG);
262
+ expect(readConfigFile(file)).toEqual({
263
+ $schema: 'https://opencode.ai/config.json',
264
+ plugin: ['opencode-see-image'],
265
+ mcp: {
266
+ openproject: {
267
+ type: 'remote',
268
+ url: 'https://openproject.example.com/mcp',
269
+ enabled: true,
270
+ },
271
+ },
272
+ provider: {
273
+ 'ollama-cloud': {
274
+ npm: '@ai-sdk/openai-compatible',
275
+ name: 'Ollama Cloud',
276
+ },
277
+ },
278
+ });
279
+ });
280
+
281
+ it('returns an empty object for a missing or whitespace-only file', () => {
282
+ expect(readConfigFile(path.join(FIXTURE_DIR, 'missing.jsonc'))).toEqual({});
283
+ const empty = writeFixture('empty.jsonc', ' \n');
284
+ expect(readConfigFile(empty)).toEqual({});
285
+ });
286
+
287
+ it('throws INVALID_JSONC on partial-parse JSONC instead of returning a $schema-only stub', () => {
288
+ const file = writeFixture('opencode.jsonc', PARTIAL_PARSE_CONFIG);
289
+ expect(() => readConfigFile(file)).toThrow(/cannot be loaded safely/);
290
+ try {
291
+ readConfigFile(file);
292
+ } catch (error) {
293
+ expect(error.code).toBe('INVALID_JSONC');
294
+ }
295
+ });
296
+
297
+ it('throws INVALID_JSONC for a non-object JSONC root', () => {
298
+ const file = writeFixture('array.jsonc', '["plugin"]\n');
299
+ expect(() => readConfigFile(file)).toThrow(/cannot be loaded safely/);
300
+ });
301
+
302
+ it('refuses to overwrite an unparseable config file', () => {
303
+ const file = writeFixture('opencode.jsonc', PARTIAL_PARSE_CONFIG);
304
+ expect(() => writeConfig({ $schema: 'https://opencode.ai/config.json' }, file)).toThrow(
305
+ /cannot be loaded safely/,
306
+ );
307
+ expect(fs.readFileSync(file, 'utf8')).toBe(PARTIAL_PARSE_CONFIG);
308
+ expect(fs.existsSync(`${file}.openchamber.backup`)).toBe(false);
309
+ });
310
+
311
+ it('preserves a valid config across MCP updates', () => {
312
+ const file = writeFixture('opencode.jsonc', VALID_CONFIG);
313
+ const config = readConfigFile(file);
314
+ config.mcp.openproject.enabled = false;
315
+ writeConfig(config, file);
316
+
317
+ const rewritten = JSON.parse(fs.readFileSync(file, 'utf8'));
318
+ expect(rewritten.plugin).toEqual(['opencode-see-image']);
319
+ expect(rewritten.provider['ollama-cloud'].name).toBe('Ollama Cloud');
320
+ expect(rewritten.mcp.openproject.enabled).toBe(false);
321
+ expect(fs.readFileSync(`${file}.openchamber.backup`, 'utf8')).toBe(VALID_CONFIG);
322
+ });
323
+
324
+ it('does not wipe an unparseable user config during MCP mutation attempts', () => {
325
+ const file = writeFixture('opencode.jsonc', PARTIAL_PARSE_CONFIG);
326
+ const previousOpenCodeConfig = process.env.OPENCODE_CONFIG;
327
+
328
+ try {
329
+ process.env.OPENCODE_CONFIG = file;
330
+ expect(() => updateMcpConfig('openproject', { enabled: true })).toThrow(
331
+ /cannot be loaded safely/,
332
+ );
333
+ expect(fs.readFileSync(file, 'utf8')).toBe(PARTIAL_PARSE_CONFIG);
334
+ expect(fs.existsSync(`${file}.openchamber.backup`)).toBe(false);
335
+ } finally {
336
+ if (previousOpenCodeConfig === undefined) delete process.env.OPENCODE_CONFIG;
337
+ else process.env.OPENCODE_CONFIG = previousOpenCodeConfig;
338
+ }
339
+ });
340
+
341
+ it('returns an empty object for a comment-only config file', () => {
342
+ const file = writeFixture('comments.jsonc', '// placeholder\n/* still empty */\n');
343
+ expect(readConfigFile(file)).toEqual({});
344
+ });
345
+
346
+ it('throws INVALID_JSONC for content that yields no JSON value at all', () => {
347
+ const yamlish = writeFixture('yamlish.jsonc', 'mcp:\n openproject:\n type: remote\n');
348
+ expect(() => readConfigFile(yamlish)).toThrow(/cannot be loaded safely/);
349
+ expect(() => writeConfig({ $schema: 'https://opencode.ai/config.json' }, yamlish)).toThrow(
350
+ /cannot be loaded safely/,
351
+ );
352
+ expect(fs.readFileSync(yamlish, 'utf8')).toBe('mcp:\n openproject:\n type: remote\n');
353
+ expect(fs.existsSync(`${yamlish}.openchamber.backup`)).toBe(false);
354
+ });
355
+
356
+ it('keeps a valid custom layer readable when a project layer is unparseable', () => {
357
+ const custom = writeFixture('custom.jsonc', VALID_CONFIG);
358
+ const projectDir = path.join(FIXTURE_DIR, 'project');
359
+ const projectFile = writeFixture(path.join('project', '.opencode', 'opencode.jsonc'), PARTIAL_PARSE_CONFIG);
360
+ const previousOpenCodeConfig = process.env.OPENCODE_CONFIG;
361
+
362
+ try {
363
+ process.env.OPENCODE_CONFIG = custom;
364
+ const layers = readConfigLayers(projectDir);
365
+ expect(layers.customConfig.plugin).toEqual(['opencode-see-image']);
366
+ expect(layers.projectConfig).toEqual({});
367
+ expect(layers.mergedConfig.plugin).toEqual(['opencode-see-image']);
368
+ expect(layers.layerErrors).toEqual([
369
+ expect.objectContaining({
370
+ path: projectFile,
371
+ code: 'INVALID_JSONC',
372
+ }),
373
+ ]);
374
+
375
+ updateMcpConfig('openproject', { enabled: false }, projectDir);
376
+ const rewritten = JSON.parse(fs.readFileSync(custom, 'utf8'));
377
+ expect(rewritten.plugin).toEqual(['opencode-see-image']);
378
+ expect(rewritten.mcp.openproject.enabled).toBe(false);
379
+ expect(fs.readFileSync(projectFile, 'utf8')).toBe(PARTIAL_PARSE_CONFIG);
380
+ expect(fs.existsSync(`${projectFile}.openchamber.backup`)).toBe(false);
381
+ } finally {
382
+ if (previousOpenCodeConfig === undefined) delete process.env.OPENCODE_CONFIG;
383
+ else process.env.OPENCODE_CONFIG = previousOpenCodeConfig;
384
+ }
385
+ });
386
+ });
@@ -40,14 +40,11 @@ export const registerSkillRoutes = (app, dependencies) => {
40
40
  SKILL_DIR,
41
41
  getCuratedSkillsSources,
42
42
  getCacheKey,
43
- getCachedScan,
44
- setCachedScan,
43
+ scanWithCache,
45
44
  parseSkillRepoSource,
46
45
  scanSkillsRepository,
47
46
  installSkillsFromRepository,
48
- scanClawdHubPage,
49
- installSkillsFromClawdHub,
50
- isClawdHubSource,
47
+ fetchGitHubRepoMetas,
51
48
  getProfiles,
52
49
  getProfile,
53
50
  } = dependencies;
@@ -305,9 +302,26 @@ export const registerSkillRoutes = (app, dependencies) => {
305
302
  }));
306
303
 
307
304
  const sources = [...curatedSources, ...customSources];
308
- const sourcesForUi = sources.map(({ gitIdentityId, ...rest }) => rest);
309
305
 
310
- res.json({ ok: true, sources: sourcesForUi, itemsBySource: {}, pageInfoBySource: {} });
306
+ const githubRepos = sources
307
+ .map((src) => parseSkillRepoSource(src.source))
308
+ .filter((parsed) => parsed.ok && parsed.host === 'github.com')
309
+ .map((parsed) => parsed.normalizedRepo);
310
+ const repoMetas = await fetchGitHubRepoMetas(githubRepos);
311
+
312
+ const sourcesForUi = sources.map(({ gitIdentityId, ...rest }) => {
313
+ const parsed = parseSkillRepoSource(rest.source);
314
+ const meta = parsed.ok && parsed.host === 'github.com'
315
+ ? repoMetas[parsed.normalizedRepo] || {}
316
+ : {};
317
+ return {
318
+ ...rest,
319
+ stars: typeof meta.stars === 'number' ? meta.stars : null,
320
+ repoUpdatedAt: typeof meta.repoUpdatedAt === 'string' ? meta.repoUpdatedAt : null,
321
+ };
322
+ });
323
+
324
+ res.json({ ok: true, sources: sourcesForUi, itemsBySource: {} });
311
325
  } catch (error) {
312
326
  console.error('Failed to load skills catalog:', error);
313
327
  res.status(500).json({ ok: false, error: { kind: 'unknown', message: error.message || 'Failed to load catalog' } });
@@ -327,7 +341,6 @@ export const registerSkillRoutes = (app, dependencies) => {
327
341
  }
328
342
 
329
343
  const refresh = String(req.query.refresh || '').toLowerCase() === 'true';
330
- const cursor = typeof req.query.cursor === 'string' ? req.query.cursor : null;
331
344
 
332
345
  const curatedSources = getCuratedSkillsSources();
333
346
  const settings = await readSettingsFromDisk();
@@ -355,26 +368,6 @@ export const registerSkillRoutes = (app, dependencies) => {
355
368
  );
356
369
  const installedByName = new Map(resolvedDiscovered.map((s) => [s.name, s]));
357
370
 
358
- if (src.sourceType === 'clawdhub' || isClawdHubSource(src.source)) {
359
- const scanned = await scanClawdHubPage({ cursor: cursor || null });
360
- if (!scanned.ok) {
361
- return res.status(500).json({ ok: false, error: scanned.error });
362
- }
363
-
364
- const items = (scanned.items || []).map((item) => {
365
- const installed = installedByName.get(item.skillName);
366
- return {
367
- ...item,
368
- sourceId: src.id,
369
- installed: installed
370
- ? { isInstalled: true, scope: installed.scope, source: installed.source }
371
- : { isInstalled: false },
372
- };
373
- });
374
-
375
- return res.json({ ok: true, items, nextCursor: scanned.nextCursor || null });
376
- }
377
-
378
371
  const parsed = parseSkillRepoSource(src.source);
379
372
  if (!parsed.ok) {
380
373
  return res.status(400).json({ ok: false, error: parsed.error });
@@ -387,21 +380,19 @@ export const registerSkillRoutes = (app, dependencies) => {
387
380
  identityId: src.gitIdentityId || '',
388
381
  });
389
382
 
390
- let scanResult = !refresh ? getCachedScan(cacheKey) : null;
391
- if (!scanResult) {
392
- const scanned = await scanSkillsRepository({
383
+ const scanResult = await scanWithCache(
384
+ cacheKey,
385
+ () => scanSkillsRepository({
393
386
  source: src.source,
394
387
  subpath: src.defaultSubpath,
395
388
  defaultSubpath: src.defaultSubpath,
396
389
  identity: resolveGitIdentity(src.gitIdentityId),
397
- });
398
-
399
- if (!scanned.ok) {
400
- return res.status(500).json({ ok: false, error: scanned.error });
401
- }
390
+ }),
391
+ { refresh },
392
+ );
402
393
 
403
- scanResult = scanned;
404
- setCachedScan(cacheKey, scanResult);
394
+ if (!scanResult.ok) {
395
+ return res.status(500).json({ ok: false, error: scanResult.error });
405
396
  }
406
397
 
407
398
  const items = (scanResult.items || []).map((item) => {
@@ -483,41 +474,6 @@ export const registerSkillRoutes = (app, dependencies) => {
483
474
  workingDirectory = resolved.directory;
484
475
  }
485
476
 
486
- if (isClawdHubSource(source)) {
487
- const result = await installSkillsFromClawdHub({
488
- scope,
489
- targetSource,
490
- workingDirectory,
491
- userSkillDir: SKILL_DIR,
492
- selections,
493
- conflictPolicy,
494
- conflictDecisions,
495
- });
496
-
497
- if (!result.ok) {
498
- if (result.error?.kind === 'conflicts') {
499
- return res.status(409).json({ ok: false, error: result.error });
500
- }
501
- return res.status(400).json({ ok: false, error: result.error });
502
- }
503
-
504
- const installed = result.installed || [];
505
- const skipped = result.skipped || [];
506
- const requiresRestart = installed.length > 0;
507
-
508
- return res.json({
509
- ok: true,
510
- installed,
511
- skipped,
512
- ...(requiresRestart
513
- ? buildDeferredRestartResponse('Skills installed successfully. Restart OpenCode to apply.')
514
- : {
515
- requiresReload: false,
516
- message: 'No skills were installed',
517
- }),
518
- });
519
- }
520
-
521
477
  const identity = resolveGitIdentity(gitIdentityId);
522
478
 
523
479
  const result = await installSkillsFromRepository({
@@ -69,14 +69,11 @@ const startSkillsApp = ({ projectRoot }) => {
69
69
  SKILL_DIR,
70
70
  getCuratedSkillsSources: () => [],
71
71
  getCacheKey: () => 'k',
72
- getCachedScan: () => null,
73
- setCachedScan: () => {},
72
+ scanWithCache: async (_key, loader) => loader(),
74
73
  parseSkillRepoSource: () => ({ ok: false }),
75
74
  scanSkillsRepository: async () => ({ ok: false }),
76
75
  installSkillsFromRepository: async () => ({ ok: false }),
77
- scanClawdHubPage: async () => ({ ok: false }),
78
- installSkillsFromClawdHub: async () => ({ ok: false }),
79
- isClawdHubSource: () => false,
76
+ fetchGitHubRepoMetas: async () => ({}),
80
77
  getProfiles: () => [],
81
78
  getProfile: () => null,
82
79
  });