@openchamber/web 1.18.3 → 1.19.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 (215) hide show
  1. package/README.md +1 -0
  2. package/dist/assets/{CodeMirrorCommentWidgets-DbUi6I9s.js → CodeMirrorCommentWidgets-DAvopJvy.js} +1 -1
  3. package/dist/assets/{CommitSection-Jc2_hNPE.js → CommitSection-D9cV-qR9.js} +1 -1
  4. package/dist/assets/{DiagramEditor-PCrYHBko.js → DiagramEditor-B9NCadU7.js} +1 -1
  5. package/dist/assets/DiagramView-LKGBwf4G.js +1 -0
  6. package/dist/assets/{DiffView-DEGlNjMH.js → DiffView-BWNq-0ov.js} +2 -2
  7. package/dist/assets/FilesView-DB-Q0Gkz.js +14 -0
  8. package/dist/assets/{GitView-C-n17voy.js → GitView-DsWXqWx3.js} +3 -3
  9. package/dist/assets/{JsonTreeView-BYcgdTOQ.js → JsonTreeView-h4dHASlq.js} +1 -1
  10. package/dist/assets/MarkdownImageGallery-n0ikH-xm.js +1 -0
  11. package/dist/assets/MarkdownRendererImpl-CT2mjx-s.js +12 -0
  12. package/dist/assets/OnboardingScreen-CDjgzxEe.js +1 -0
  13. package/dist/assets/{PatchDiff-Bn7bfgUv.js → PatchDiff-jPKTJje5.js} +1 -1
  14. package/dist/assets/{PierreDiffViewer-D1fWvrUn.js → PierreDiffViewer-D_Gt4A_6.js} +1 -1
  15. package/dist/assets/PlanView-UvuxIl9-.js +4 -0
  16. package/dist/assets/SessionSwitcherDropdown-xKU4LRuQ.js +1 -0
  17. package/dist/assets/SettingsView-3B9VN6Ys.js +28 -0
  18. package/dist/assets/SettingsWindow-CqQNDKNd.js +1 -0
  19. package/dist/assets/{ToolOutputDialog-BtIJkFno.js → ToolOutputDialog-PmjlAxVE.js} +6 -6
  20. package/dist/assets/{ToolPartDiffPreview-i3PQo6_0.js → ToolPartDiffPreview-B34Xw9wq.js} +1 -1
  21. package/dist/assets/{VirtualizedFileDiff-DkcusvMa.js → VirtualizedFileDiff-B37yB9jZ.js} +3 -3
  22. package/dist/assets/{WalkthroughView-Cc5Hd6P5.js → WalkthroughView-Bxun3k66.js} +2 -2
  23. package/dist/assets/{computeVirtualFileMetrics-xPena3W2.js → computeVirtualFileMetrics-DYFv_yZS.js} +2 -2
  24. package/dist/assets/contextPanelEmbeddedChat-BO1wRpaN.js +1 -0
  25. package/dist/assets/de-DbV6CLxv.js +9 -0
  26. package/dist/assets/document-attachments-DFAWlG3U.js +31 -0
  27. package/dist/assets/es-CVDlyzZ4.js +15 -0
  28. package/dist/assets/fr-Czc-p0g-.js +13 -0
  29. package/dist/assets/index-1OhiMDBz.css +1 -0
  30. package/dist/assets/index-BSvmTvZl.js +1 -0
  31. package/dist/assets/index-DzriVon2.js +7 -0
  32. package/dist/assets/{isDiffPlainText-Dudf-dWx.js → isDiffPlainText-DwHKxDYc.js} +1 -1
  33. package/dist/assets/{isFilePlainText-DS4QV1dd.js → isFilePlainText-Dwq6ILxo.js} +1 -1
  34. package/dist/assets/ja-dwc9NM_S.js +15 -0
  35. package/dist/assets/ko-Ds1DZ8FX.js +15 -0
  36. package/dist/assets/{lua-BgMRiT3U.js → lua-VAEuO923.js} +1 -1
  37. package/dist/assets/main-BF51IOVF.js +921 -0
  38. package/dist/assets/{main-C0DyIwTb.js → main-D7UPARut.js} +2 -2
  39. package/dist/assets/markdownCore-BgeBDwD3.js +2 -0
  40. package/dist/assets/{miniChat-CGfrxKpJ.js → miniChat-BISXSGOo.js} +2 -2
  41. package/dist/assets/mobile-BnYxVuvw.js +2 -0
  42. package/dist/assets/{patchFileDiff-C5D1OPCa.js → patchFileDiff-BEDPDypx.js} +2 -2
  43. package/dist/assets/pl-CLiTO7i-.js +15 -0
  44. package/dist/assets/pt-BR-GIimJgpK.js +15 -0
  45. package/dist/assets/renderElectronMiniChatApp-BaOy72Gi.js +2 -0
  46. package/dist/assets/{renderMobileApp-B5HA4qbi.js → renderMobileApp-BiMbzPq9.js} +7 -7
  47. package/dist/assets/runtimeEndpointReset-BMBRhIbf.js +15 -0
  48. package/dist/assets/scheduledTasksApi-01zzfzqH.js +1 -0
  49. package/dist/assets/{shikiHighlight-CmanopUB.js → shikiHighlight-DXYW46vW.js} +1 -1
  50. package/dist/assets/uk-DLfgD1ki.js +15 -0
  51. package/dist/assets/{useAppFontEffects-sHmU5b8u.js → useAppFontEffects-CbzHzFop.js} +139 -142
  52. package/dist/assets/{useInlineCommentController-gt56WkxJ.js → useInlineCommentController-CegKdDXi.js} +2 -2
  53. package/dist/assets/{vendor-base-ui-D_V6hAcE.js → vendor-base-ui-BYlZTzrw.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-Dihw9MtL.js → vendor-codemirror-language-data-CiAYDJXN.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-adaMkgkm.js +39 -0
  85. package/dist/assets/{web-components-BL-Ur2Tb.js → web-components-DCLjCO9n.js} +1 -1
  86. package/dist/assets/zh-CN-DkeP5awK.js +15 -0
  87. package/dist/assets/zh-TW-BocaFm3d.js +15 -0
  88. package/dist/index.html +4 -4
  89. package/dist/mini-chat.html +3 -3
  90. package/dist/mobile.html +3 -3
  91. package/package.json +1 -1
  92. package/server/index.js +116 -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 +56 -0
  98. package/server/lib/agent-memory/project-resolution.test.js +85 -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 +427 -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/dev-tunnel/client.js +20 -1
  111. package/server/lib/dev-tunnel/tunnel.test.js +9 -0
  112. package/server/lib/fs/DOCUMENTATION.md +3 -0
  113. package/server/lib/fs/routes.js +149 -32
  114. package/server/lib/fs/routes.test.js +225 -0
  115. package/server/lib/git/DOCUMENTATION.md +8 -0
  116. package/server/lib/git/service.js +121 -67
  117. package/server/lib/git/service.test.js +129 -0
  118. package/server/lib/github/DOCUMENTATION.md +14 -3
  119. package/server/lib/github/pr-status.js +188 -83
  120. package/server/lib/github/pr-status.test.js +182 -0
  121. package/server/lib/github/routes.js +36 -30
  122. package/server/lib/markdown-image-grants/DOCUMENTATION.md +36 -0
  123. package/server/lib/markdown-image-grants/routes.js +340 -0
  124. package/server/lib/markdown-image-grants/routes.test.js +221 -0
  125. package/server/lib/notifications/template-runtime.js +2 -3
  126. package/server/lib/openchamber-control/action-resolution.test.js +65 -0
  127. package/server/lib/openchamber-control/actions.js +78 -0
  128. package/server/lib/openchamber-control/service.js +7 -0
  129. package/server/lib/openchamber-sessions/routes.js +14 -0
  130. package/server/lib/opencode/DOCUMENTATION.md +6 -4
  131. package/server/lib/opencode/claude-cli-auth.js +60 -0
  132. package/server/lib/opencode/claude-cli-auth.test.js +54 -0
  133. package/server/lib/opencode/feature-routes-runtime.js +22 -0
  134. package/server/lib/opencode/plugins.js +12 -3
  135. package/server/lib/opencode/plugins.test.js +18 -0
  136. package/server/lib/opencode/proxy-agent-wiring.test.js +152 -0
  137. package/server/lib/opencode/proxy.js +116 -6
  138. package/server/lib/opencode/proxy.test.js +158 -1
  139. package/server/lib/opencode/routes.js +4 -1
  140. package/server/lib/opencode/server-startup-runtime.js +22 -1
  141. package/server/lib/opencode/server-startup-runtime.test.js +44 -0
  142. package/server/lib/opencode/settings-helpers.js +11 -0
  143. package/server/lib/opencode/settings-helpers.test.js +35 -0
  144. package/server/lib/opencode/settings-runtime.js +51 -0
  145. package/server/lib/opencode/shared.js +120 -16
  146. package/server/lib/opencode/shared.test.js +185 -1
  147. package/server/lib/project-context/DOCUMENTATION.md +158 -0
  148. package/server/lib/project-context/routes.http.test.js +264 -0
  149. package/server/lib/project-context/routes.js +237 -0
  150. package/server/lib/project-context/runtime.js +667 -0
  151. package/server/lib/project-context/runtime.test.js +498 -0
  152. package/server/lib/quota/DOCUMENTATION.md +16 -1
  153. package/server/lib/quota/providers/claude/auth.js +113 -0
  154. package/server/lib/quota/providers/claude/auth.test.js +117 -0
  155. package/server/lib/quota/providers/claude/index.js +151 -0
  156. package/server/lib/quota/providers/claude/index.test.js +147 -0
  157. package/server/lib/quota/providers/claude/transforms.js +127 -0
  158. package/server/lib/quota/providers/claude/transforms.test.js +82 -0
  159. package/server/lib/quota/providers/command-code.js +90 -0
  160. package/server/lib/quota/providers/command-code.test.js +72 -0
  161. package/server/lib/quota/providers/index.js +22 -2
  162. package/server/lib/quota/providers/index.test.js +10 -1
  163. package/server/lib/quota/utils/formatters.js +2 -1
  164. package/server/lib/scheduled-tasks/runtime.js +21 -2
  165. package/server/lib/session-knowledge/DOCUMENTATION.md +87 -0
  166. package/server/lib/session-knowledge/routes.js +107 -0
  167. package/server/lib/session-knowledge/runtime.js +331 -0
  168. package/server/lib/session-knowledge/runtime.test.js +275 -0
  169. package/server/lib/skills-catalog/DOCUMENTATION.md +22 -22
  170. package/server/lib/skills-catalog/curated-sources.js +1 -1
  171. package/server/lib/skills-catalog/curated-sources.test.js +10 -0
  172. package/server/lib/small-model/index.js +8 -0
  173. package/server/lib/small-model/index.test.js +31 -1
  174. package/server/lib/small-model/routes.js +3 -1
  175. package/dist/assets/DiagramView-CndEcZNu.js +0 -1
  176. package/dist/assets/FilesView-CzUgIvUm.js +0 -14
  177. package/dist/assets/MarkdownImageGallery-DzHwkVIH.js +0 -1
  178. package/dist/assets/MarkdownRendererImpl-DUcIcWgs.js +0 -12
  179. package/dist/assets/OnboardingScreen-BmN0lhk4.js +0 -1
  180. package/dist/assets/PlanView-CWM0iyFk.js +0 -4
  181. package/dist/assets/SessionSwitcherDropdown-Cez-9xRh.js +0 -1
  182. package/dist/assets/SettingsView-Bl1drwPw.js +0 -28
  183. package/dist/assets/SettingsWindow-DL5axjDZ.js +0 -1
  184. package/dist/assets/contextPanelEmbeddedChat-tQekJUAF.js +0 -1
  185. package/dist/assets/de-u7gSnqWs.js +0 -9
  186. package/dist/assets/document-attachments-CX_YaDsu.js +0 -30
  187. package/dist/assets/es-T9O7aAOr.js +0 -15
  188. package/dist/assets/fr-Oor7ewbE.js +0 -13
  189. package/dist/assets/index-CVNuER6G.css +0 -1
  190. package/dist/assets/index-Crz1YOFl.js +0 -1
  191. package/dist/assets/index-iFY_N5aO.js +0 -7
  192. package/dist/assets/ja-DHpqbVmr.js +0 -15
  193. package/dist/assets/ko-CwLkS3nx.js +0 -15
  194. package/dist/assets/main-CAxX6DAN.js +0 -915
  195. package/dist/assets/markdownCore-DhfzuGXu.js +0 -2
  196. package/dist/assets/markdownImageAssets-BTNlRyjd.js +0 -1
  197. package/dist/assets/mobile-DEmhwNcV.js +0 -2
  198. package/dist/assets/pl-CcZILN8q.js +0 -15
  199. package/dist/assets/pt-BR-DYHhVK6o.js +0 -15
  200. package/dist/assets/renderElectronMiniChatApp-Dpbswpom.js +0 -2
  201. package/dist/assets/runtimeEndpointReset-cbahJ3hD.js +0 -13
  202. package/dist/assets/scheduledTasksApi-BxgGWTL8.js +0 -1
  203. package/dist/assets/uk-BA2kZR38.js +0 -15
  204. package/dist/assets/vendor-codemirror-autocomplete-BjbBRsUA.js +0 -1
  205. package/dist/assets/vendor-codemirror-commands-ARAOgp1x.js +0 -1
  206. package/dist/assets/vendor-codemirror-lang-html-B3Qe3OpS.js +0 -1
  207. package/dist/assets/vendor-codemirror-lang-javascript-Bbw3D7r0.js +0 -13
  208. package/dist/assets/vendor-codemirror-lang-markdown-FGQydhTc.js +0 -1
  209. package/dist/assets/vendor-codemirror-language-DUOssd4j.js +0 -3
  210. package/dist/assets/vendor-codemirror-search-8kyQdB3f.js +0 -2
  211. package/dist/assets/vendor-codemirror-view-DSzLbZiS.js +0 -4
  212. package/dist/assets/vendor-replit-codemirror-vim-B0Ecqnlh.js +0 -39
  213. package/dist/assets/zh-CN-dlOQK6v9.js +0 -15
  214. package/dist/assets/zh-TW-BnqQ-WL5.js +0 -15
  215. package/server/lib/quota/providers/claude.js +0 -107
@@ -0,0 +1,36 @@
1
+ # Markdown Image Grants
2
+
3
+ ## Purpose
4
+
5
+ This module lets the Markdown image gallery display images that an assistant
6
+ explicitly referenced from OpenCode's temporary directory when the UI is on a
7
+ different machine.
8
+
9
+ ## Contract
10
+
11
+ - Chat Markdown rendering is independent: assistant image syntax renders as an
12
+ icon and filename, while the gallery only reads finalized Markdown to collect
13
+ image candidates.
14
+ - `POST /api/openchamber/sessions/:sessionId/markdown-image-grants` prepares up to 12
15
+ local images in one message-level request. The server fetches the assistant
16
+ message once and verifies every exact image source before reading files.
17
+ - Authorization recognizes the same common inline and reference-style image
18
+ destinations collected by the UI, including balanced parentheses, while
19
+ excluding fenced and inline code.
20
+ - Relative and workspace-contained absolute paths resolve against the active
21
+ directory. Other absolute paths are accepted only inside
22
+ `os.tmpdir()/opencode` after `realpath` resolution.
23
+ - PNG, JPEG, GIF, and WebP files are signature-checked and limited to 10 MiB.
24
+ - Prepare requests inspect only file metadata and signatures. Workspace images
25
+ reuse the existing authenticated `/api/fs/raw` asset route directly. Images
26
+ under `os.tmpdir()/opencode` receive the existing path-bound `raw`
27
+ `outsideFileGrant`; this module does not add another asset lifetime, copy, or
28
+ storage layer. Missing files return per-source results so the gallery can
29
+ remove only those items.
30
+
31
+ The routes are OpenChamber-owned and must be registered before the generic
32
+ OpenCode proxy. Web, Electron, hosted mobile, and Capacitor use the shared
33
+ server implementation. VS Code does not call this route for workspace images;
34
+ those use its local filesystem bridge. If called, the grant route returns an
35
+ explicit unsupported response because OpenCode temporary images are not
36
+ supported there.
@@ -0,0 +1,340 @@
1
+ import express from 'express';
2
+ import { constants as fsConstants } from 'node:fs';
3
+ import { mintOutsideFileGrant } from '../fs/routes.js';
4
+
5
+ const MAX_IMAGE_BYTES = 10 * 1024 * 1024;
6
+ const MAX_IMAGE_SOURCES = 12;
7
+
8
+ const asString = (value) => typeof value === 'string' ? value.trim() : '';
9
+
10
+ const isWithin = (target, root, path) => {
11
+ const relative = path.relative(root, target);
12
+ return relative === '' || (!relative.startsWith('..') && !path.isAbsolute(relative));
13
+ };
14
+
15
+ const parseFileSource = (source) => {
16
+ if (/^file:\/\//i.test(source)) {
17
+ try {
18
+ const url = new URL(source);
19
+ if (url.protocol !== 'file:' || (url.host && url.host !== 'localhost')) return '';
20
+ const pathname = decodeURIComponent(url.pathname);
21
+ return /^\/[A-Za-z]:\//.test(pathname) ? pathname.slice(1) : pathname;
22
+ } catch {
23
+ return '';
24
+ }
25
+ }
26
+ const pathname = source.split(/[?#]/, 1)[0] || '';
27
+ try {
28
+ return decodeURIComponent(pathname);
29
+ } catch {
30
+ return pathname;
31
+ }
32
+ };
33
+
34
+ const hasImageSignature = (bytes) => {
35
+ if (bytes.length >= 8
36
+ && bytes[0] === 0x89 && bytes.subarray(1, 4).toString('ascii') === 'PNG'
37
+ && bytes[4] === 0x0d && bytes[5] === 0x0a && bytes[6] === 0x1a && bytes[7] === 0x0a) return true;
38
+ if (bytes.length >= 3 && bytes[0] === 0xff && bytes[1] === 0xd8 && bytes[2] === 0xff) return true;
39
+ const header = bytes.subarray(0, 12).toString('ascii');
40
+ return header.startsWith('GIF87a')
41
+ || header.startsWith('GIF89a')
42
+ || (header.startsWith('RIFF') && header.slice(8, 12) === 'WEBP');
43
+ };
44
+
45
+ const normalizeReferenceLabel = (value) => value.trim().replace(/\s+/g, ' ').toLowerCase();
46
+
47
+ const unescapeMarkdownDestination = (value) => value.replace(/\\([!"#$%&'()*+,\-./:;<=>?@[\]^_`{|}~\\])/g, '$1');
48
+
49
+ const isEscapedAt = (value, index) => {
50
+ let slashes = 0;
51
+ for (let cursor = index - 1; cursor >= 0 && value[cursor] === '\\'; cursor -= 1) slashes += 1;
52
+ return slashes % 2 === 1;
53
+ };
54
+
55
+ const findClosingBracket = (value, start) => {
56
+ for (let cursor = start; cursor < value.length; cursor += 1) {
57
+ if (value[cursor] === ']' && !isEscapedAt(value, cursor)) return cursor;
58
+ }
59
+ return -1;
60
+ };
61
+
62
+ const findInlineImageEnd = (value, start) => {
63
+ let cursor = start;
64
+ while (/\s/.test(value[cursor] || '')) cursor += 1;
65
+ if (value[cursor] === ')') return cursor;
66
+
67
+ const opener = value[cursor];
68
+ const closer = opener === '"' ? '"' : opener === "'" ? "'" : opener === '(' ? ')' : '';
69
+ if (!closer) return -1;
70
+ cursor += 1;
71
+ for (; cursor < value.length; cursor += 1) {
72
+ if (value[cursor] !== closer || isEscapedAt(value, cursor)) continue;
73
+ cursor += 1;
74
+ while (/\s/.test(value[cursor] || '')) cursor += 1;
75
+ return value[cursor] === ')' ? cursor : -1;
76
+ }
77
+ return -1;
78
+ };
79
+
80
+ const parseInlineDestination = (value, start) => {
81
+ let cursor = start;
82
+ while (/\s/.test(value[cursor] || '')) cursor += 1;
83
+ if (value[cursor] === '<') {
84
+ const end = value.indexOf('>', cursor + 1);
85
+ if (end < 0) return null;
86
+ const imageEnd = findInlineImageEnd(value, end + 1);
87
+ return imageEnd < 0
88
+ ? null
89
+ : { source: unescapeMarkdownDestination(value.slice(cursor + 1, end)), end: imageEnd };
90
+ }
91
+
92
+ let source = '';
93
+ let depth = 0;
94
+ for (; cursor < value.length; cursor += 1) {
95
+ const char = value[cursor];
96
+ if (char === '\\' && cursor + 1 < value.length) {
97
+ source += char + value[cursor + 1];
98
+ cursor += 1;
99
+ continue;
100
+ }
101
+ if (char === '(') {
102
+ depth += 1;
103
+ source += char;
104
+ continue;
105
+ }
106
+ if (char === ')') {
107
+ if (depth === 0) return { source: unescapeMarkdownDestination(source), end: cursor };
108
+ depth -= 1;
109
+ source += char;
110
+ continue;
111
+ }
112
+ if (/\s/.test(char) && depth === 0) {
113
+ const imageEnd = findInlineImageEnd(value, cursor);
114
+ return imageEnd < 0 ? null : { source: unescapeMarkdownDestination(source), end: imageEnd };
115
+ }
116
+ source += char;
117
+ }
118
+ return null;
119
+ };
120
+
121
+ const parseDefinitionDestination = (value) => {
122
+ const trimmed = value.trimStart();
123
+ if (trimmed.startsWith('<')) {
124
+ const end = trimmed.indexOf('>', 1);
125
+ return end < 0 ? '' : unescapeMarkdownDestination(trimmed.slice(1, end));
126
+ }
127
+ const match = /^(?:\\.|\S)+/.exec(trimmed);
128
+ return match ? unescapeMarkdownDestination(match[0]) : '';
129
+ };
130
+
131
+ const collectMarkdownLinesOutsideCode = (message) => {
132
+ const lines = [];
133
+ for (const part of Array.isArray(message?.parts) ? message.parts : []) {
134
+ if (part?.type !== 'text' || typeof part.text !== 'string') continue;
135
+ let fence = null;
136
+ for (const line of part.text.split('\n')) {
137
+ const fenceMatch = /^\s{0,3}(`{3,}|~{3,})/.exec(line);
138
+ if (fenceMatch) {
139
+ const marker = fenceMatch[1];
140
+ if (!fence) {
141
+ fence = { char: marker[0], size: marker.length };
142
+ } else if (marker[0] === fence.char && marker.length >= fence.size) {
143
+ fence = null;
144
+ }
145
+ continue;
146
+ }
147
+ if (fence) continue;
148
+ lines.push(line.replace(/`+[^`]*`+/g, ''));
149
+ }
150
+ }
151
+ return lines;
152
+ };
153
+
154
+ const markdownImageSources = (message) => {
155
+ const sources = new Set();
156
+ const markdownLines = collectMarkdownLinesOutsideCode(message);
157
+ const definitions = new Map();
158
+ for (const line of markdownLines) {
159
+ const match = /^\s{0,3}\[([^\]]+)]\s*:\s*(.*)$/.exec(line);
160
+ if (!match) continue;
161
+ const source = parseDefinitionDestination(match[2]);
162
+ if (source) definitions.set(normalizeReferenceLabel(match[1]), source);
163
+ }
164
+
165
+ for (const line of markdownLines) {
166
+ for (let cursor = 0; cursor < line.length; cursor += 1) {
167
+ if (line[cursor] !== '!' || line[cursor + 1] !== '[' || isEscapedAt(line, cursor)) continue;
168
+ const altEnd = findClosingBracket(line, cursor + 2);
169
+ if (altEnd < 0) continue;
170
+ const alt = line.slice(cursor + 2, altEnd);
171
+ const next = line[altEnd + 1];
172
+ if (next === '(') {
173
+ const parsed = parseInlineDestination(line, altEnd + 2);
174
+ if (parsed?.source) sources.add(parsed.source);
175
+ cursor = parsed?.end ?? altEnd;
176
+ continue;
177
+ }
178
+ let label = alt;
179
+ if (next === '[') {
180
+ const labelEnd = findClosingBracket(line, altEnd + 2);
181
+ if (labelEnd < 0) continue;
182
+ label = line.slice(altEnd + 2, labelEnd) || alt;
183
+ cursor = labelEnd;
184
+ } else {
185
+ cursor = altEnd;
186
+ }
187
+ const source = definitions.get(normalizeReferenceLabel(label));
188
+ if (source) sources.add(source);
189
+ }
190
+ }
191
+ return sources;
192
+ };
193
+
194
+ const fetchMessage = async ({ sessionId, messageId, directory, buildOpenCodeUrl, getOpenCodeAuthHeaders }) => {
195
+ const url = new URL(buildOpenCodeUrl(
196
+ `/session/${encodeURIComponent(sessionId)}/message/${encodeURIComponent(messageId)}`,
197
+ '',
198
+ ));
199
+ url.searchParams.set('directory', directory);
200
+ const response = await fetch(url, {
201
+ headers: {
202
+ accept: 'application/json',
203
+ 'x-opencode-directory': directory,
204
+ ...getOpenCodeAuthHeaders(),
205
+ },
206
+ signal: AbortSignal.timeout(10_000),
207
+ });
208
+ if (response.status === 404) return null;
209
+ if (!response.ok) throw new Error(`OpenCode returned ${response.status}`);
210
+ const message = await response.json().catch(() => null);
211
+ return message?.info && Array.isArray(message.parts) ? message : null;
212
+ };
213
+
214
+ const inspectImage = async ({ source, directory, approvedTempRoot, fsPromises, path }) => {
215
+ const parsed = parseFileSource(source);
216
+ if (!parsed) return { status: 'error' };
217
+ const sourcePath = path.isAbsolute(parsed) ? parsed : path.resolve(directory, parsed);
218
+ const workspaceRoot = path.resolve(directory);
219
+ const outsideWorkspace = !isWithin(path.resolve(sourcePath), workspaceRoot, path);
220
+ const root = outsideWorkspace ? approvedTempRoot : workspaceRoot;
221
+
222
+ try {
223
+ // Resolve symlinks before comparing roots; lexical prefixes are not an authorization boundary.
224
+ const [canonicalRoot, canonicalPath] = await Promise.all([
225
+ fsPromises.realpath(root),
226
+ fsPromises.realpath(sourcePath),
227
+ ]);
228
+ if (!isWithin(canonicalPath, canonicalRoot, path)) return { status: 'error' };
229
+ const handle = await fsPromises.open(canonicalPath, fsConstants.O_RDONLY | fsConstants.O_NOFOLLOW);
230
+ try {
231
+ const stats = await handle.stat();
232
+ if (!stats.isFile() || stats.size > MAX_IMAGE_BYTES) return { status: 'error' };
233
+ const header = Buffer.alloc(12);
234
+ const { bytesRead } = await handle.read(header, 0, header.length, 0);
235
+ if (!hasImageSignature(header.subarray(0, bytesRead))) return { status: 'error' };
236
+ return {
237
+ status: 'ready',
238
+ path: outsideWorkspace ? canonicalPath : path.resolve(sourcePath),
239
+ outsideWorkspace,
240
+ };
241
+ } finally {
242
+ await handle.close();
243
+ }
244
+ } catch (error) {
245
+ if (error?.code === 'ENOENT') return { status: 'missing' };
246
+ if (error?.code === 'EACCES' || error?.code === 'EPERM' || error?.code === 'ELOOP') {
247
+ return { status: 'error' };
248
+ }
249
+ throw error;
250
+ }
251
+ };
252
+
253
+ export const registerMarkdownImageGrantRoutes = (app, dependencies) => {
254
+ const {
255
+ fsPromises,
256
+ path,
257
+ os,
258
+ crypto,
259
+ validateDirectoryPath,
260
+ buildOpenCodeUrl,
261
+ getOpenCodeAuthHeaders,
262
+ approvedTempRoot = path.join(os.tmpdir(), 'opencode'),
263
+ } = dependencies;
264
+
265
+ app.post(
266
+ '/api/openchamber/sessions/:sessionId/markdown-image-grants',
267
+ express.json({ limit: '32kb' }),
268
+ async (req, res) => {
269
+ const sessionId = asString(req.params.sessionId);
270
+ const messageId = asString(req.body?.messageId);
271
+ const sources = Array.isArray(req.body?.sources)
272
+ ? [...new Set(req.body.sources.map(asString).filter(Boolean))]
273
+ : [];
274
+ if (!sessionId || !messageId || sources.length === 0 || sources.length > MAX_IMAGE_SOURCES) {
275
+ return res.status(400).json({ error: 'sessionId, messageId, and 1-12 sources are required' });
276
+ }
277
+ const validatedDirectory = await validateDirectoryPath(asString(req.body?.directory));
278
+ if (!validatedDirectory.ok) {
279
+ return res.status(400).json({ error: validatedDirectory.error || 'Invalid directory' });
280
+ }
281
+
282
+ try {
283
+ const message = await fetchMessage({
284
+ sessionId,
285
+ messageId,
286
+ directory: validatedDirectory.directory,
287
+ buildOpenCodeUrl,
288
+ getOpenCodeAuthHeaders,
289
+ });
290
+ if (!message || message.info?.id !== messageId || message.info?.role !== 'assistant') {
291
+ return res.status(404).json({ error: 'Assistant message not found' });
292
+ }
293
+ // Assistant text is authoritative: a remote client cannot mint grants for unreferenced paths.
294
+ const referenced = markdownImageSources(message);
295
+ const results = [];
296
+ for (const source of sources) {
297
+ if (!referenced.has(source)) {
298
+ results.push({ source, status: 'error' });
299
+ continue;
300
+ }
301
+ try {
302
+ const inspected = await inspectImage({
303
+ source,
304
+ directory: validatedDirectory.directory,
305
+ approvedTempRoot,
306
+ fsPromises,
307
+ path,
308
+ });
309
+ if (inspected.status !== 'ready') {
310
+ results.push({ source, status: inspected.status });
311
+ continue;
312
+ }
313
+ // Reuse the existing path-bound raw-file grant instead of creating another asset lifecycle.
314
+ const grant = inspected.outsideWorkspace
315
+ ? await mintOutsideFileGrant(inspected.path, {
316
+ scopes: ['raw'],
317
+ fsPromises,
318
+ path,
319
+ crypto,
320
+ })
321
+ : null;
322
+ results.push({
323
+ source,
324
+ status: 'ready',
325
+ path: inspected.path,
326
+ outsideFileGrant: grant?.outsideFileGrant,
327
+ expiresAt: grant?.expiresAt,
328
+ });
329
+ } catch {
330
+ results.push({ source, status: 'error' });
331
+ }
332
+ }
333
+ return res.json({ results });
334
+ } catch (error) {
335
+ console.warn('[MarkdownImageGrants] failed to prepare images:', error?.message || error);
336
+ return res.status(503).json({ error: 'Failed to prepare session images' });
337
+ }
338
+ },
339
+ );
340
+ };
@@ -0,0 +1,221 @@
1
+ import { afterEach, describe, expect, it, vi } from 'vitest';
2
+ import express from 'express';
3
+ import request from 'supertest';
4
+ import crypto from 'node:crypto';
5
+ import fs from 'node:fs/promises';
6
+ import os from 'node:os';
7
+ import path from 'node:path';
8
+ import { registerMarkdownImageGrantRoutes } from './routes.js';
9
+
10
+ const PNG = Buffer.from(
11
+ 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8DwHwAFBQIAX8jx0gAAAABJRU5ErkJggg==',
12
+ 'base64',
13
+ );
14
+ const roots = [];
15
+
16
+ afterEach(async () => {
17
+ vi.unstubAllGlobals();
18
+ await Promise.all(roots.splice(0).map((root) => fs.rm(root, { recursive: true, force: true })));
19
+ });
20
+
21
+ const createFixture = async ({ sources, markdown } = {}) => {
22
+ const root = await fs.mkdtemp(path.join(os.tmpdir(), 'openchamber-session-assets-'));
23
+ roots.push(root);
24
+ const approvedTempRoot = path.join(root, 'opencode');
25
+ const directory = path.join(root, 'workspace');
26
+ await Promise.all([
27
+ fs.mkdir(approvedTempRoot, { recursive: true }),
28
+ fs.mkdir(directory, { recursive: true }),
29
+ ]);
30
+ const defaultPath = path.join(approvedTempRoot, 'image.png');
31
+ await fs.writeFile(defaultPath, PNG);
32
+ const requestedSources = sources ?? [new URL(`file://${defaultPath}`).toString()];
33
+ const text = markdown ?? requestedSources.map((source) => `![image](${source})`).join('\n');
34
+ const fetchMock = vi.fn(async () => new Response(JSON.stringify({
35
+ info: { id: 'msg_1', role: 'assistant' },
36
+ parts: [{ type: 'text', text }],
37
+ }), { status: 200, headers: { 'content-type': 'application/json' } }));
38
+ vi.stubGlobal('fetch', fetchMock);
39
+
40
+ let fullReadCount = 0;
41
+ const app = express();
42
+ registerMarkdownImageGrantRoutes(app, {
43
+ fsPromises: {
44
+ ...fs,
45
+ readFile: async (...args) => {
46
+ fullReadCount += 1;
47
+ return fs.readFile(...args);
48
+ },
49
+ },
50
+ path,
51
+ os,
52
+ crypto,
53
+ approvedTempRoot,
54
+ validateDirectoryPath: async (candidate) => candidate === directory
55
+ ? { ok: true, directory }
56
+ : { ok: false, error: 'Invalid directory' },
57
+ buildOpenCodeUrl: (route) => `http://opencode.test${route}`,
58
+ getOpenCodeAuthHeaders: () => ({ authorization: 'Basic test' }),
59
+ });
60
+ return {
61
+ app,
62
+ approvedTempRoot,
63
+ directory,
64
+ fetchMock,
65
+ fullReadCount: () => fullReadCount,
66
+ root,
67
+ sources: requestedSources,
68
+ };
69
+ };
70
+
71
+ const prepare = (app, directory, sources) => request(app)
72
+ .post('/api/openchamber/sessions/ses_1/markdown-image-grants')
73
+ .send({ directory, messageId: 'msg_1', sources })
74
+ .expect(200);
75
+
76
+ describe('session image assets', () => {
77
+ it('prepares workspace and OpenCode temporary images with one message fetch', async () => {
78
+ const fixture = await createFixture({ sources: ['workspace.png'] });
79
+ await fs.writeFile(path.join(fixture.directory, 'workspace.png'), PNG);
80
+ const temporaryPath = path.join(fixture.approvedTempRoot, 'temporary.png');
81
+ await fs.writeFile(temporaryPath, PNG);
82
+ const temporarySource = new URL(`file://${temporaryPath}`).toString();
83
+ fixture.fetchMock.mockResolvedValueOnce(new Response(JSON.stringify({
84
+ info: { id: 'msg_1', role: 'assistant' },
85
+ parts: [{ type: 'text', text: `![workspace](workspace.png)\n![temporary](${temporarySource})` }],
86
+ }), { status: 200, headers: { 'content-type': 'application/json' } }));
87
+
88
+ const response = await prepare(fixture.app, fixture.directory, ['workspace.png', temporarySource]);
89
+
90
+ expect(fixture.fetchMock).toHaveBeenCalledTimes(1);
91
+ expect(fixture.fullReadCount()).toBe(0);
92
+ expect(response.body.results).toHaveLength(2);
93
+ const canonicalTemporaryPath = await fs.realpath(temporaryPath);
94
+ expect(response.body.results[0]).toEqual({
95
+ source: 'workspace.png',
96
+ status: 'ready',
97
+ path: path.join(fixture.directory, 'workspace.png'),
98
+ });
99
+ expect(response.body.results[1]).toEqual(expect.objectContaining({
100
+ source: temporarySource,
101
+ status: 'ready',
102
+ path: canonicalTemporaryPath,
103
+ outsideFileGrant: expect.any(String),
104
+ expiresAt: expect.any(Number),
105
+ }));
106
+ });
107
+
108
+ it('returns partial results without letting one missing image block valid images', async () => {
109
+ const fixture = await createFixture({ sources: ['present.png', 'deleted.png'] });
110
+ await fs.writeFile(path.join(fixture.directory, 'present.png'), PNG);
111
+
112
+ const response = await prepare(fixture.app, fixture.directory, fixture.sources);
113
+
114
+ expect(response.body.results).toEqual([
115
+ expect.objectContaining({ source: 'present.png', status: 'ready' }),
116
+ { source: 'deleted.png', status: 'missing' },
117
+ ]);
118
+ });
119
+
120
+ it('resolves encoded workspace paths without treating query or fragment text as a filename', async () => {
121
+ const source = 'screen%20shot.png?version=1#preview';
122
+ const fixture = await createFixture({ sources: [source] });
123
+ await fs.writeFile(path.join(fixture.directory, 'screen shot.png'), PNG);
124
+
125
+ const response = await prepare(fixture.app, fixture.directory, fixture.sources);
126
+
127
+ expect(response.body.results).toEqual([
128
+ expect.objectContaining({ source, status: 'ready' }),
129
+ ]);
130
+ });
131
+
132
+ it('authorizes reference-style image syntax using its resolved destination', async () => {
133
+ const source = 'reference.png';
134
+ const fixture = await createFixture({
135
+ sources: [source],
136
+ markdown: '![screenshot][result]\n\n[result]: reference.png',
137
+ });
138
+ await fs.writeFile(path.join(fixture.directory, source), PNG);
139
+
140
+ const response = await prepare(fixture.app, fixture.directory, fixture.sources);
141
+
142
+ expect(response.body.results).toEqual([
143
+ expect.objectContaining({ source, status: 'ready' }),
144
+ ]);
145
+ });
146
+
147
+ it('authorizes inline image destinations containing balanced parentheses', async () => {
148
+ const source = 'screen(1).png';
149
+ const fixture = await createFixture({
150
+ sources: [source],
151
+ markdown: `![screenshot](${source})`,
152
+ });
153
+ await fs.writeFile(path.join(fixture.directory, source), PNG);
154
+
155
+ const response = await prepare(fixture.app, fixture.directory, fixture.sources);
156
+
157
+ expect(response.body.results).toEqual([
158
+ expect.objectContaining({ source, status: 'ready' }),
159
+ ]);
160
+ });
161
+
162
+ it('requires inline image destinations with titles to close', async () => {
163
+ const sources = ['valid.png', 'malformed.png'];
164
+ const fixture = await createFixture({
165
+ sources,
166
+ markdown: '![valid](valid.png "preview")\n![malformed](malformed.png "preview"',
167
+ });
168
+ await Promise.all(sources.map((source) => fs.writeFile(path.join(fixture.directory, source), PNG)));
169
+
170
+ const response = await prepare(fixture.app, fixture.directory, sources);
171
+
172
+ expect(response.body.results).toEqual([
173
+ expect.objectContaining({ source: 'valid.png', status: 'ready' }),
174
+ { source: 'malformed.png', status: 'error' },
175
+ ]);
176
+ });
177
+
178
+ it('rejects a source that the message does not reference', async () => {
179
+ const fixture = await createFixture({ markdown: 'No image here.' });
180
+ const response = await prepare(fixture.app, fixture.directory, fixture.sources);
181
+ expect(response.body.results).toEqual([{ source: fixture.sources[0], status: 'error' }]);
182
+ });
183
+
184
+ it('does not authorize image syntax inside fenced or inline code', async () => {
185
+ const fixture = await createFixture({
186
+ markdown: '```md\n![fenced](FENCED)\n```\n`![inline](INLINE)`',
187
+ });
188
+ const sources = ['FENCED', 'INLINE'];
189
+
190
+ const response = await prepare(fixture.app, fixture.directory, sources);
191
+
192
+ expect(response.body.results).toEqual(sources.map((source) => ({ source, status: 'error' })));
193
+ });
194
+
195
+ it('rejects paths outside the workspace and approved temporary root', async () => {
196
+ const fixture = await createFixture();
197
+ const outsidePath = path.join(fixture.root, 'outside.png');
198
+ await fs.writeFile(outsidePath, PNG);
199
+ const source = new URL(`file://${outsidePath}`).toString();
200
+ fixture.fetchMock.mockResolvedValueOnce(new Response(JSON.stringify({
201
+ info: { id: 'msg_1', role: 'assistant' },
202
+ parts: [{ type: 'text', text: `![outside](${source})` }],
203
+ }), { status: 200, headers: { 'content-type': 'application/json' } }));
204
+
205
+ const response = await prepare(fixture.app, fixture.directory, [source]);
206
+ expect(response.body.results).toEqual([{ source, status: 'error' }]);
207
+ });
208
+
209
+ it('rejects non-image bytes and symlink escapes per source', async () => {
210
+ const fixture = await createFixture({ sources: ['invalid.png', 'linked.png'] });
211
+ await fs.writeFile(path.join(fixture.directory, 'invalid.png'), 'not an image');
212
+ await fs.writeFile(path.join(fixture.root, 'outside.png'), PNG);
213
+ await fs.symlink(path.join(fixture.root, 'outside.png'), path.join(fixture.directory, 'linked.png'));
214
+
215
+ const response = await prepare(fixture.app, fixture.directory, fixture.sources);
216
+ expect(response.body.results).toEqual([
217
+ { source: 'invalid.png', status: 'error' },
218
+ { source: 'linked.png', status: 'error' },
219
+ ]);
220
+ });
221
+ });
@@ -27,9 +27,8 @@ export const createNotificationTemplateRuntime = (deps) => {
27
27
 
28
28
  const formatProjectLabel = (label) => {
29
29
  if (!label || typeof label !== 'string') return '';
30
- return label
31
- .replace(/[-_]/g, ' ')
32
- .replace(/\b\w/g, (char) => char.toUpperCase());
30
+ // Folder names are shown exactly as they are on disk — no title-casing.
31
+ return label.trim();
33
32
  };
34
33
 
35
34
  const resolveNotificationTemplate = (template, variables) => {
@@ -0,0 +1,65 @@
1
+ import { describe, expect, test } from 'bun:test';
2
+
3
+ import { resolveAgentToolAction } from './actions.js';
4
+
5
+ /**
6
+ * Both cases here are from one real conversation: the model called `read` and
7
+ * then `get` on `openchamber_memory`, having dropped the namespace its own tool
8
+ * name appeared to supply, and gave up after the second bare "unsupported".
9
+ */
10
+ describe('a namespace the tool name already implies', () => {
11
+ test('resolves a bare action inside the calling tool', () => {
12
+ expect(resolveAgentToolAction('read', 'openchamber_memory')).toEqual({ action: 'memory.read' });
13
+ expect(resolveAgentToolAction('save', 'openchamber_memory')).toEqual({ action: 'memory.save' });
14
+ });
15
+
16
+ test('resolves a bare name that is ambiguous only across tools', () => {
17
+ // `delete` belongs to schedule and to memory; inside one tool it is plain.
18
+ expect(resolveAgentToolAction('delete', 'openchamber_memory')).toEqual({ action: 'memory.delete' });
19
+ expect(resolveAgentToolAction('delete', 'openchamber')).toEqual({ action: 'schedule.delete' });
20
+ });
21
+
22
+ test('keeps a fully qualified action as it is', () => {
23
+ expect(resolveAgentToolAction('memory.read', 'openchamber_memory')).toEqual({ action: 'memory.read' });
24
+ });
25
+
26
+ test('does not reach outside the tool that asked', () => {
27
+ // The memory tool asking for `open` must fail, not drive the browser.
28
+ expect(resolveAgentToolAction('open', 'openchamber_memory').action).toBeUndefined();
29
+ });
30
+ });
31
+
32
+ describe('an unidentified caller', () => {
33
+ test('still resolves a bare name that means one thing everywhere', () => {
34
+ expect(resolveAgentToolAction('snapshot', null)).toEqual({ action: 'browser.snapshot' });
35
+ });
36
+
37
+ test('refuses a bare name that several actions share', () => {
38
+ expect(resolveAgentToolAction('list', null).action).toBeUndefined();
39
+ });
40
+ });
41
+
42
+ describe('what an unresolvable action reports', () => {
43
+ test('names the actions the calling tool actually has', () => {
44
+ const { error } = resolveAgentToolAction('get', 'openchamber_memory');
45
+
46
+ expect(error).toContain('memory.read');
47
+ expect(error).toContain('memory.save');
48
+ // Listing every action of every tool would bury the four that apply.
49
+ expect(error).not.toContain('browser.open');
50
+ });
51
+
52
+ test('reports a missing action rather than resolving to something', () => {
53
+ const { error, action } = resolveAgentToolAction('', 'openchamber_memory');
54
+
55
+ expect(action).toBeUndefined();
56
+ expect(error).toContain('missing');
57
+ });
58
+
59
+ test('an unknown tool falls back to the full action list', () => {
60
+ const { error } = resolveAgentToolAction('nonsense', 'openchamber_future');
61
+
62
+ expect(error).toContain('memory.read');
63
+ expect(error).toContain('browser.open');
64
+ });
65
+ });