@kabmo-labs/kabmo 0.17.0 → 0.18.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 (269) hide show
  1. package/dist/client/index.html +1 -1
  2. package/dist/client/index.js +538 -457
  3. package/dist/client/static/js/index-hp75vsv9.css +1 -0
  4. package/dist/client/static/js/{index-rerjq5th.js → index-tc09dtca.js} +823 -814
  5. package/package.json +1 -1
  6. package/src/client/components/common/MarkdownRenderer.tsx +136 -89
  7. package/src/client/components/common/anchored-menu/index.test.tsx +141 -0
  8. package/src/client/components/common/anchored-menu/index.tsx +143 -0
  9. package/src/client/components/common/markdown-review/ReviewPopover.tsx +144 -0
  10. package/src/client/components/common/markdown-review/ReviewSummary.tsx +108 -0
  11. package/src/client/components/common/markdown-review/index.tsx +129 -0
  12. package/src/client/components/common/server-control/Panel.tsx +33 -23
  13. package/src/client/components/common/server-control/index.test.tsx +11 -5
  14. package/src/client/components/common/server-control/index.tsx +10 -8
  15. package/src/client/components/layout/session-sidebar/CategoryHeader.tsx +42 -21
  16. package/src/client/components/layout/session-sidebar/CategoryHeader.worktree.test.tsx +36 -17
  17. package/src/client/components/layout/session-sidebar/CategoryItem.tsx +8 -7
  18. package/src/client/components/layout/session-sidebar/about-modal/NotesDialog.tsx +94 -0
  19. package/src/client/components/layout/session-sidebar/about-modal/VersionLine.test.tsx +68 -0
  20. package/src/client/components/layout/session-sidebar/about-modal/VersionLine.tsx +36 -0
  21. package/src/client/components/layout/session-sidebar/about-modal/index.tsx +57 -34
  22. package/src/client/components/layout/session-sidebar/modern/WorkspaceHeader.tsx +28 -10
  23. package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +7 -6
  24. package/src/client/components/layout/session-sidebar/modern/workspace-header.test.tsx +1 -1
  25. package/src/client/components/layout/update-popup/ReleaseNotes.tsx +8 -3
  26. package/src/client/components/layout/update-popup/index.tsx +5 -1
  27. package/src/client/components/mobile/mobile-right-sidebar/FullEditor.tsx +13 -15
  28. package/src/client/components/mobile/mobile-right-sidebar/Header.tsx +23 -1
  29. package/src/client/components/mobile/mobile-right-sidebar/MissingFileBanner.tsx +30 -0
  30. package/src/client/components/mobile/mobile-right-sidebar/PreviewScroller.tsx +18 -2
  31. package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +22 -67
  32. package/src/client/components/mobile/mobile-session-sidebar/ItemMenu.tsx +110 -0
  33. package/src/client/components/settings/SettingsSidebarList.tsx +20 -0
  34. package/src/client/components/settings/categories/AgentSettings.tsx +23 -50
  35. package/src/client/components/settings/categories/CommandSettings.tsx +2 -2
  36. package/src/client/components/settings/categories/McpSettings.tsx +4 -21
  37. package/src/client/components/settings/categories/OmpSettings.tsx +147 -194
  38. package/src/client/components/settings/categories/SkillSettings.tsx +2 -2
  39. package/src/client/components/settings/categories/TokenUsageSettings.tsx +211 -229
  40. package/src/client/components/settings/categories/agent-settings/DetailPane.tsx +229 -237
  41. package/src/client/components/settings/categories/agent-settings/ModelPicker.tsx +71 -0
  42. package/src/client/components/settings/categories/agent-settings/SidebarList.tsx +9 -2
  43. package/src/client/components/settings/categories/agent-settings/levels.ts +38 -0
  44. package/src/client/components/settings/categories/behavior-settings/Editor.tsx +27 -7
  45. package/src/client/components/settings/categories/chat-settings/ToolRenderSection.tsx +23 -5
  46. package/src/client/components/settings/categories/command-settings/DetailPane.tsx +75 -33
  47. package/src/client/components/settings/categories/command-settings/SidebarList.tsx +7 -0
  48. package/src/client/components/settings/categories/mcp-settings/DetailPane.tsx +91 -76
  49. package/src/client/components/settings/categories/mcp-settings/EnvVarsSection.tsx +83 -0
  50. package/src/client/components/settings/categories/mcp-settings/ImportModal.tsx +26 -13
  51. package/src/client/components/settings/categories/mcp-settings/SidebarList.tsx +20 -0
  52. package/src/client/components/settings/categories/omp-settings/ConfigTabs.tsx +97 -36
  53. package/src/client/components/settings/categories/omp-settings/EngineHeader.tsx +151 -0
  54. package/src/client/components/settings/categories/omp-settings/ExtensionsPanel.tsx +68 -32
  55. package/src/client/components/settings/categories/omp-settings/OrderedChips.tsx +119 -0
  56. package/src/client/components/settings/categories/omp-settings/PresetBar.tsx +14 -7
  57. package/src/client/components/settings/categories/omp-settings/RoleEditor.tsx +15 -6
  58. package/src/client/components/settings/categories/omp-settings/RowEditor.tsx +165 -226
  59. package/src/client/components/settings/categories/omp-settings/types.ts +28 -0
  60. package/src/client/components/settings/categories/skill-settings/DetailHeader.tsx +35 -7
  61. package/src/client/components/settings/categories/skill-settings/DetailPane.tsx +34 -14
  62. package/src/client/components/settings/categories/skill-settings/SidebarList.tsx +21 -0
  63. package/src/client/components/settings/categories/skill-settings/pane.test.tsx +15 -6
  64. package/src/client/components/settings/categories/token-usage-settings/Breakdown.tsx +242 -102
  65. package/src/client/components/settings/categories/token-usage-settings/Chart.tsx +130 -56
  66. package/src/client/components/settings/categories/token-usage-settings/Controls.tsx +135 -0
  67. package/src/client/components/settings/categories/token-usage-settings/MetricsGrid.tsx +55 -33
  68. package/src/client/components/settings/categories/token-usage-settings/Provenance.tsx +59 -0
  69. package/src/client/components/settings/categories/token-usage-settings/panel.test.tsx +239 -0
  70. package/src/client/components/workspace/browser-panel/Screencast.test.ts +1 -0
  71. package/src/client/components/workspace/browser-panel/Screencast.tsx +17 -22
  72. package/src/client/components/workspace/browser-panel/TabStrip.test.tsx +158 -0
  73. package/src/client/components/workspace/browser-panel/TabStrip.tsx +90 -0
  74. package/src/client/components/workspace/browser-panel/index.tsx +50 -4
  75. package/src/client/components/workspace/browser-toolbar/index.tsx +41 -1
  76. package/src/client/components/workspace/chat-timeline/ThinkingSection.tsx +3 -1
  77. package/src/client/components/workspace/chat-timeline/ToolCallingSection.tsx +2 -0
  78. package/src/client/components/workspace/chat-timeline/block-chrome.test.tsx +13 -2
  79. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Bash.test.ts +88 -0
  80. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Bash.tsx +24 -1
  81. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Read.test.ts +34 -0
  82. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Read.tsx +5 -1
  83. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/ArtifactChip.tsx +7 -6
  84. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Tui.test.tsx +237 -0
  85. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Tui.tsx +191 -0
  86. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/styles.test.tsx +1 -1
  87. package/src/client/components/workspace/diff-panel/MergeDiffView.tsx +21 -7
  88. package/src/client/components/workspace/diff-panel/changes.test.ts +51 -0
  89. package/src/client/components/workspace/diff-panel/changes.ts +28 -12
  90. package/src/client/components/workspace/diff-panel/merge.test.ts +28 -0
  91. package/src/client/components/workspace/diff-panel/merge.ts +21 -1
  92. package/src/client/components/workspace/editor/Body.tsx +7 -0
  93. package/src/client/components/workspace/editor/FileDocument.tsx +15 -21
  94. package/src/client/components/workspace/editor/FilePane.tsx +12 -0
  95. package/src/client/components/workspace/editor/PreviewPane.tsx +70 -0
  96. package/src/client/components/workspace/editor/Toolbar.tsx +17 -1
  97. package/src/client/components/workspace/editor/index.tsx +25 -22
  98. package/src/client/components/workspace/editor/toolbar-clusters.test.ts +14 -0
  99. package/src/client/components/workspace/editor/toolbar-clusters.tsx +12 -86
  100. package/src/client/components/workspace/editor/toolbar-toggle.tsx +53 -0
  101. package/src/client/components/workspace/editor/toolbar-write-clusters.tsx +112 -0
  102. package/src/client/components/workspace/git-panel/commit-modal.test.ts +5 -3
  103. package/src/client/components/workspace/user-browser-panel/AddressBar.tsx +5 -0
  104. package/src/client/components/workspace/user-browser-panel/AnnotateBar.test.tsx +201 -0
  105. package/src/client/components/workspace/user-browser-panel/AnnotateBar.tsx +112 -0
  106. package/src/client/components/workspace/user-browser-panel/AnnotateLayer.test.tsx +225 -0
  107. package/src/client/components/workspace/user-browser-panel/AnnotateLayer.tsx +217 -0
  108. package/src/client/components/workspace/user-browser-panel/AnnotateTarget.tsx +99 -0
  109. package/src/client/components/workspace/user-browser-panel/Frame.tsx +30 -1
  110. package/src/client/components/workspace/user-browser-panel/index.tsx +81 -2
  111. package/src/client/data/agent-data/builtin.ts +0 -10
  112. package/src/client/data/agent-data/orchestrator.ts +0 -45
  113. package/src/client/data/agent-data/specialist.ts +0 -100
  114. package/src/client/data/mock/token-usage.ts +170 -120
  115. package/src/client/data/settings/omp-schema.json +33 -1
  116. package/src/client/hooks/browser/use-annotate.test.ts +143 -0
  117. package/src/client/hooks/browser/use-annotate.ts +98 -0
  118. package/src/client/hooks/browser/use-close-tab.test.ts +148 -0
  119. package/src/client/hooks/browser/use-close-tab.ts +67 -0
  120. package/src/client/hooks/browser/use-screencast.ts +13 -1
  121. package/src/client/hooks/chat/composer/browser-context.test.ts +117 -0
  122. package/src/client/hooks/chat/composer/browser-context.ts +40 -16
  123. package/src/client/hooks/chat/composer/items.test.ts +1 -1
  124. package/src/client/hooks/chat/composer/review-context.ts +38 -0
  125. package/src/client/hooks/chat/composer/use-draft.test.ts +132 -0
  126. package/src/client/hooks/chat/composer/use-draft.ts +31 -2
  127. package/src/client/hooks/chat/timeline/row-window.test.ts +15 -2
  128. package/src/client/hooks/editor/use-document-annotations.ts +124 -0
  129. package/src/client/hooks/editor/use-editor-panel-ui.ts +52 -0
  130. package/src/client/hooks/editor/use-file-review-mode.ts +35 -0
  131. package/src/client/hooks/editor/use-preview-review.ts +148 -0
  132. package/src/client/hooks/settings/agents.ts +149 -0
  133. package/src/client/hooks/settings/crud-list.test.ts +28 -6
  134. package/src/client/hooks/settings/crud-list.ts +96 -57
  135. package/src/client/hooks/settings/omp-config.ts +164 -0
  136. package/src/client/hooks/settings/useTokenUsage.ts +125 -0
  137. package/src/client/hooks/settings/write-feedback.test.ts +104 -0
  138. package/src/client/hooks/settings/write-feedback.ts +63 -0
  139. package/src/client/hooks/ui/markdown-hydration.ts +125 -0
  140. package/src/client/hooks/ui/updates/index.test.ts +100 -1
  141. package/src/client/hooks/ui/updates/index.ts +50 -0
  142. package/src/client/hooks/ui/updates/notes.test.ts +138 -0
  143. package/src/client/hooks/ui/updates/notes.ts +57 -0
  144. package/src/client/lib/browser/element-at.test.ts +229 -0
  145. package/src/client/lib/browser/element-at.ts +139 -0
  146. package/src/client/lib/review/client.ts +73 -0
  147. package/src/client/lib/router/search-params.ts +42 -20
  148. package/src/client/tailwind.css +65 -0
  149. package/src/server/lib/btw/lifecycle.server.ts +2 -2
  150. package/src/server/lib/db/schema.ts +7 -0
  151. package/src/server/lib/db/seed-terminal.test.ts +4 -0
  152. package/src/server/lib/omp/config/agent-definitions.test.ts +273 -0
  153. package/src/server/lib/omp/config/agents.ts +231 -61
  154. package/src/server/lib/omp/config/definitions.test.ts +9 -105
  155. package/src/server/lib/omp/config/extensions.ts +16 -7
  156. package/src/server/lib/omp/config/omp-config-files.test.ts +27 -0
  157. package/src/server/lib/omp/rpc/constants.test.ts +11 -0
  158. package/src/server/lib/omp/rpc/constants.ts +15 -0
  159. package/src/server/lib/omp/rpc/process.ts +11 -14
  160. package/src/server/lib/omp/rpc/session-commands.ts +6 -3
  161. package/src/server/lib/omp/rpc/utility-agent-dir.test.ts +134 -0
  162. package/src/server/lib/omp/rpc/utility-agent-dir.ts +138 -0
  163. package/src/server/lib/omp/rpc/utility.ts +12 -0
  164. package/src/server/lib/review/schema.server.ts +45 -0
  165. package/src/server/lib/review/store.server.ts +138 -0
  166. package/src/server/lib/terminal/attach-replay.test.ts +132 -0
  167. package/src/server/lib/terminal/output.test.ts +166 -0
  168. package/src/server/lib/terminal/output.ts +104 -0
  169. package/src/server/lib/terminal/runtime.server.ts +5 -0
  170. package/src/server/lib/terminal/send-result.test.ts +33 -0
  171. package/src/server/lib/terminal/send-result.ts +32 -0
  172. package/src/server/lib/terminal/session.server.ts +45 -11
  173. package/src/server/lib/terminal/store-liveness.test.ts +4 -0
  174. package/src/server/lib/updates/active-notes.test.ts +149 -0
  175. package/src/server/lib/updates/active-notes.ts +75 -0
  176. package/src/server/lib/updates/changelog-file.ts +42 -11
  177. package/src/server/lib/updates/changelog.test.ts +15 -1
  178. package/src/server/lib/updates/omp.ts +42 -15
  179. package/src/server/lib/updates/release-url.ts +27 -1
  180. package/src/server/lib/usage/index-parse.test.ts +200 -0
  181. package/src/server/lib/usage/index-parse.ts +178 -0
  182. package/src/server/lib/usage/index-query.server.ts +248 -0
  183. package/src/server/lib/usage/index-scan.server.ts +343 -0
  184. package/src/server/lib/usage/index-schema.server.ts +82 -0
  185. package/src/server/lib/usage/index.test.ts +234 -0
  186. package/src/server/lib/usage/providers.server.ts +4 -53
  187. package/src/server/routes/browser/index.ts +3 -0
  188. package/src/server/routes/browser/stream.ts +31 -2
  189. package/src/server/routes/browser/tabs.test.ts +94 -0
  190. package/src/server/routes/browser/tabs.ts +85 -0
  191. package/src/server/routes/index.ts +2 -0
  192. package/src/server/routes/review/bindings.ts +11 -0
  193. package/src/server/routes/review/index.ts +127 -0
  194. package/src/server/routes/review/routes.test.ts +191 -0
  195. package/src/server/routes/settings/agents.test.ts +180 -0
  196. package/src/server/routes/settings/agents.ts +95 -102
  197. package/src/server/routes/settings/mcp.test.ts +135 -0
  198. package/src/server/routes/settings/mcp.ts +14 -6
  199. package/src/server/routes/settings/settings-store-routes.test.ts +6 -113
  200. package/src/server/routes/telemetry/tokens.test.ts +145 -0
  201. package/src/server/routes/telemetry/tokens.ts +70 -149
  202. package/src/server/routes/terminal/ws.ts +6 -5
  203. package/src/server/routes/updates/index.ts +2 -0
  204. package/src/server/routes/updates/notes.ts +34 -0
  205. package/src/server/routes/updates/routes.test.ts +49 -0
  206. package/src/shared/lib/browser/annotate.test.ts +283 -0
  207. package/src/shared/lib/browser/annotate.ts +231 -0
  208. package/src/shared/lib/browser/browser-viewer.test.ts +26 -4
  209. package/src/shared/lib/browser/frame-gate.test.ts +91 -0
  210. package/src/shared/lib/browser/frame-gate.ts +69 -0
  211. package/src/shared/lib/browser/frame-params.test.ts +43 -0
  212. package/src/shared/lib/browser/frame-params.ts +60 -0
  213. package/src/shared/lib/browser/frame-pipeline.test.ts +132 -0
  214. package/src/shared/lib/browser/frame-pipeline.ts +80 -0
  215. package/src/shared/lib/browser/page-context.ts +60 -4
  216. package/src/shared/lib/browser/snapshot.test.ts +115 -0
  217. package/src/shared/lib/browser/snapshot.ts +112 -0
  218. package/src/shared/lib/browser/tab-close.test.ts +74 -0
  219. package/src/shared/lib/browser/tab-close.ts +77 -0
  220. package/src/shared/lib/browser/viewer.ts +45 -26
  221. package/src/shared/lib/chat/timeline/block-chrome.ts +19 -0
  222. package/src/shared/lib/chat/timeline/tool-render-mode.ts +17 -4
  223. package/src/shared/lib/chat/tool/artifact.ts +55 -20
  224. package/src/shared/lib/chat/tool/bash-facts.ts +96 -0
  225. package/src/shared/lib/chat/tool/minimized.test.ts +98 -0
  226. package/src/shared/lib/chat/tool/minimized.ts +64 -0
  227. package/src/shared/lib/chat/tool/summary.test.ts +28 -8
  228. package/src/shared/lib/chat/tool/summary.ts +3 -32
  229. package/src/shared/lib/markdown/blocks/anchor.ts +63 -0
  230. package/src/shared/lib/markdown/blocks/blocks.test.ts +141 -0
  231. package/src/shared/lib/markdown/blocks/renderer.ts +120 -0
  232. package/src/shared/lib/markdown/blocks/scan.ts +100 -0
  233. package/src/shared/lib/markdown/blocks/types.ts +62 -0
  234. package/src/shared/lib/markdown/marked.ts +58 -147
  235. package/src/shared/lib/markdown/math-extensions.ts +168 -0
  236. package/src/shared/lib/markdown/review/prompt.ts +77 -0
  237. package/src/shared/lib/markdown/review/reconcile.ts +55 -0
  238. package/src/shared/lib/markdown/review/review.test.ts +96 -0
  239. package/src/shared/lib/markdown/xml-sections.test.ts +140 -0
  240. package/src/shared/lib/markdown/xml-sections.ts +139 -0
  241. package/src/shared/lib/models/provider/label.ts +57 -0
  242. package/src/shared/lib/omp/config/agent-file.test.ts +54 -0
  243. package/src/shared/lib/omp/config/agent-file.ts +43 -0
  244. package/src/shared/lib/omp/config/row-value.test.ts +95 -0
  245. package/src/shared/lib/omp/config/row-value.ts +97 -0
  246. package/src/shared/lib/omp/config/schema.test.ts +31 -0
  247. package/src/shared/lib/omp/config/schema.ts +6 -0
  248. package/src/shared/lib/omp/rpc/frame.test.ts +48 -47
  249. package/src/shared/lib/omp/rpc/frame.ts +49 -40
  250. package/src/shared/lib/ui/menu-anchor.test.ts +69 -0
  251. package/src/shared/lib/ui/menu-anchor.ts +89 -0
  252. package/src/shared/lib/usage/breakdown.test.ts +197 -0
  253. package/src/shared/lib/usage/breakdown.ts +241 -0
  254. package/src/shared/lib/usage/range.test.ts +204 -0
  255. package/src/shared/lib/usage/range.ts +240 -0
  256. package/src/shared/lib/usage/view.test.ts +85 -0
  257. package/src/shared/lib/usage/view.ts +74 -0
  258. package/src/shared/types/browser.ts +78 -0
  259. package/src/shared/types/index.ts +1 -0
  260. package/src/shared/types/settings/agent.ts +28 -6
  261. package/src/shared/types/settings/state.ts +4 -3
  262. package/src/shared/types/settings/write.ts +6 -0
  263. package/src/shared/types/tokenUsage.ts +128 -21
  264. package/src/shared/types/updates.ts +20 -0
  265. package/dist/client/static/js/index-3ve31rzx.css +0 -1
  266. package/src/server/lib/omp/session/usage/aggregate-shaping.test.ts +0 -149
  267. package/src/server/lib/omp/session/usage/aggregate.test.ts +0 -243
  268. package/src/server/lib/omp/session/usage/aggregate.ts +0 -330
  269. package/src/server/lib/omp/session/usage/shaping.ts +0 -130
@@ -26,58 +26,9 @@ import { buildKenariReport } from '@/server/lib/usage/kenari';
26
26
  import { fetchOmpUsageSnapshot, type OmpUsageSnapshot } from '@/server/lib/usage/omp-usage.server';
27
27
  import { fetchVendorBalance, type VendorBalance } from '@/server/lib/usage/vendor-balance.server';
28
28
  import { kenariProviderSlugs, listCredentialedProviders, type CredentialedProvider } from '@/server/lib/usage/provider-key';
29
- import { titleCaseProviderSlug } from '@/shared/lib/models/provider/label';
29
+ import { canonicalProviderSlug, providerDisplayName } from '@/shared/lib/models/provider/label';
30
30
  import type { KenariUsageReport, UsageProviderSummary } from '@/shared/types';
31
31
 
32
- /** Slug aliases omp uses interchangeably, folded onto one display entry. */
33
- const SLUG_ALIASES: Record<string, string> = {
34
- 'command-code': 'commandcode',
35
- };
36
-
37
- /**
38
- * Brand spellings a title-case pass cannot produce. Kept small on purpose: the
39
- * slug is the identity, this is only how it is printed.
40
- */
41
- const BRAND_NAMES: Record<string, string> = {
42
- openai: 'OpenAI',
43
- kenari: 'Kenari.id',
44
- deepseek: 'DeepSeek',
45
- 'openai-codex': 'OpenAI Codex',
46
- 'google-gemini-cli': 'Google Gemini CLI',
47
- 'google-antigravity': 'Google Antigravity',
48
- 'github-copilot': 'GitHub Copilot',
49
- zai: 'Z.AI',
50
- 'zai-coding-plan': 'Z.AI Coding Plan',
51
- xai: 'xAI',
52
- 'xai-oauth': 'xAI (OAuth)',
53
- 'kimi-code': 'Kimi Code',
54
- 'qwen-portal': 'Qwen Portal',
55
- 'minimax-code': 'MiniMax Code',
56
- 'minimax-code-cn': 'MiniMax Code (CN)',
57
- 'alibaba-token-plan': 'Alibaba Token Plan',
58
- 'alibaba-coding-plan': 'Alibaba Coding Plan',
59
- 'zhipu-coding-plan': 'Zhipu Coding Plan',
60
- 'gitlab-duo': 'GitLab Duo',
61
- 'gitlab-duo-agent': 'GitLab Duo Agent',
62
- 'charm-hyper': 'Charm Hyper',
63
- 'cline-pass': 'Cline Pass',
64
- 'opencode-go': 'OpenCode Go',
65
- 'xiaomi-token-plan-sgp': 'Xiaomi Token Plan (SGP)',
66
- 'xiaomi-token-plan-ams': 'Xiaomi Token Plan (AMS)',
67
- 'xiaomi-token-plan-cn': 'Xiaomi Token Plan (CN)',
68
- 'openai-codex-device': 'OpenAI Codex (Device)',
69
- };
70
-
71
- function canonicalSlug(slug: string): string {
72
- const lower = slug.trim().toLowerCase();
73
- return SLUG_ALIASES[lower] ?? lower;
74
- }
75
-
76
- /** Human-readable provider name: brand spelling when known, title case otherwise. */
77
- function displayName(slug: string): string {
78
- return BRAND_NAMES[slug] ?? titleCaseProviderSlug(slug);
79
- }
80
-
81
32
  /**
82
33
  * omp's own display names for the providers it knows (slug → name), e.g.
83
34
  * `commandcode` → "Command Code". Best-effort: a cold or busy omp degrades to
@@ -88,7 +39,7 @@ async function loadProviderNames(): Promise<Record<string, string>> {
88
39
  const { providers } = await fetchOmpRegistrySnapshot();
89
40
  const names: Record<string, string> = {};
90
41
  for (const provider of providers) {
91
- const slug = canonicalSlug(provider.id);
42
+ const slug = canonicalProviderSlug(provider.id);
92
43
  const name = provider.name.trim();
93
44
  if (slug && name) names[slug] = name;
94
45
  }
@@ -118,7 +69,7 @@ async function loadVendorBalances(slugs: string[]): Promise<Map<string, VendorBa
118
69
  function mergeCredentials(entries: CredentialedProvider[]): Map<string, string[]> {
119
70
  const bySlug = new Map<string, string[]>();
120
71
  for (const entry of entries) {
121
- const slug = canonicalSlug(entry.slug);
72
+ const slug = canonicalProviderSlug(entry.slug);
122
73
  if (!slug) continue;
123
74
  const sources = bySlug.get(slug) ?? [];
124
75
  for (const source of entry.sources) {
@@ -189,7 +140,7 @@ export async function buildUsageProviders(options: { force?: boolean } = {}): Pr
189
140
  const { tracked, limitsUnavailable } = resolveUsageTracking(slug, snapshot);
190
141
  const summary: UsageProviderSummary = {
191
142
  id: slug,
192
- name: names[slug] ?? displayName(slug),
143
+ name: names[slug] ?? providerDisplayName(slug),
193
144
  ...(iconUrls.get(slug) ? { iconUrl: iconUrls.get(slug) } : {}),
194
145
  credentialSources: sources,
195
146
  // A vendor balance is real quota data even when omp has no adapter for it.
@@ -1,6 +1,9 @@
1
1
  import { bindingsFor, type HandlerBinding } from '@/server/lib/route-adapter';
2
2
  import * as browserStream from '@/server/routes/browser/stream';
3
+ import * as browserTabs from '@/server/routes/browser/tabs';
3
4
 
4
5
  export const browserBindings: HandlerBinding[] = [
5
6
  ...bindingsFor(browserStream, '/api/browser/:sessionId/stream'),
7
+ // Mutating route: `bindingsFor` adds the 405 GET fallback on its own.
8
+ ...bindingsFor(browserTabs, '/api/browser/:sessionId/tabs/close'),
6
9
  ];
@@ -37,6 +37,9 @@ import { BROWSER_POLL_MS, STREAM_HEARTBEAT_MS } from '@/shared/lib/workspace/ref
37
37
 
38
38
  const BROWSER_OFFLINE: BrowserViewState = { status: 'browser-offline', tabs: [] };
39
39
 
40
+ /** How soon a frame held under backpressure is offered to the stream again. */
41
+ const FRAME_FLUSH_RETRY_MS = 120;
42
+
40
43
  export async function loader({ params, request }: LoaderFunctionArgs) {
41
44
  const sessionId = params.sessionId ?? '';
42
45
  const preferTargetId = new URL(request.url).searchParams.get('target') ?? undefined;
@@ -81,6 +84,11 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
81
84
  const cleanup = (): void => {
82
85
  if (closed) return;
83
86
  closed = true;
87
+ pendingFrame = null;
88
+ if (frameTimer !== null) {
89
+ clearTimeout(frameTimer);
90
+ frameTimer = null;
91
+ }
84
92
  detachViewer();
85
93
  dropWatcher();
86
94
  unsubscribeAgent?.();
@@ -104,12 +112,33 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
104
112
  handlers.send('action', payload);
105
113
  };
106
114
 
107
- const emitFrame = (frame: BrowserViewFrame): void => {
108
- // Backpressure: keep at most a couple of pending frames; drop the rest.
115
+ let pendingFrame: BrowserViewFrame | null = null;
116
+ let frameTimer: ReturnType<typeof setTimeout> | null = null;
117
+
118
+ const flushFrame = (): void => {
119
+ if (closed || !pendingFrame) return;
109
120
  if (handlers.isBackpressured()) return;
121
+ const frame = pendingFrame;
122
+ pendingFrame = null;
110
123
  handlers.send('frame', frame);
111
124
  };
112
125
 
126
+ const emitFrame = (frame: BrowserViewFrame): void => {
127
+ // Backpressure: hold the NEWEST frame instead of dropping it. A drop is
128
+ // only harmless while the page keeps painting; an idle tab (the normal
129
+ // state of a tab the agent finished with) produces exactly one frame —
130
+ // the seeding snapshot — so dropping it is what put the panel back on
131
+ // "waiting for the first frame".
132
+ pendingFrame = frame;
133
+ flushFrame();
134
+ if (!pendingFrame || frameTimer !== null) return;
135
+ frameTimer = setTimeout(() => {
136
+ frameTimer = null;
137
+ flushFrame();
138
+ if (pendingFrame) emitFrame(pendingFrame);
139
+ }, FRAME_FLUSH_RETRY_MS);
140
+ };
141
+
113
142
  const tick = async (): Promise<void> => {
114
143
  if (closed || tickInFlight) return;
115
144
  tickInFlight = true;
@@ -0,0 +1,94 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * `POST /api/browser/:sessionId/tabs/close` — the refusals, which are the whole
8
+ * contract reachable without a real Chromium.
9
+ *
10
+ * A close request is an ACT of the user on someone else's browser, so every
11
+ * path that does not close must say why: no session, no shared browser, a tab
12
+ * that belongs to another session, a malformed id. The happy path itself is a
13
+ * single CDP call whose behaviour is measured in `shared/lib/browser/tab-close.ts`
14
+ * (Chromium 1248: `{"success":true}`, the socket survives, the attached session
15
+ * dies on its own), and its policy — which ids may be closed at all — is pinned
16
+ * in `tab-close.test.ts`.
17
+ */
18
+
19
+ import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
20
+ import path from 'node:path';
21
+
22
+ import { action } from '@/server/routes/browser/tabs';
23
+
24
+ const originalMock = Bun.env.MOCK;
25
+ const globals = globalThis as unknown as { __ompSessions?: Map<string, unknown> };
26
+ const SESSION = 'tabs-close-test-session';
27
+
28
+ beforeEach(() => {
29
+ delete Bun.env.MOCK;
30
+ if (!globals.__ompSessions) globals.__ompSessions = new Map();
31
+ });
32
+
33
+ afterEach(() => {
34
+ globals.__ompSessions?.delete(SESSION);
35
+ if (originalMock === undefined) delete Bun.env.MOCK;
36
+ else Bun.env.MOCK = originalMock;
37
+ });
38
+
39
+ function post(body: unknown, sessionId = SESSION): Promise<Response> {
40
+ return action({
41
+ params: { sessionId },
42
+ request: new Request(`http://localhost/api/browser/${sessionId}/tabs/close`, {
43
+ method: 'POST',
44
+ headers: { 'content-type': 'application/json' },
45
+ body: typeof body === 'string' ? body : JSON.stringify(body),
46
+ }),
47
+ } as never) as Promise<Response>;
48
+ }
49
+
50
+ describe('browser tab close route', () => {
51
+ test('a session this process does not run owns no tabs to close', async () => {
52
+ const res = await post({ targetId: 'abc' });
53
+ expect(res.status).toBe(404);
54
+ expect(((await res.json()) as { error: string }).error).toContain('not running');
55
+ });
56
+
57
+ test('a malformed target id is refused before any browser is touched', async () => {
58
+ globals.__ompSessions?.set(SESSION, { pid: process.pid, cwd: process.cwd(), isAlive: () => true });
59
+ for (const targetId of [undefined, '', 'a b', '../x', 7]) {
60
+ const res = await post({ targetId });
61
+ expect(res.status).toBe(400);
62
+ }
63
+ });
64
+
65
+ test('a body that is not JSON is refused with 400, not a crash', async () => {
66
+ globals.__ompSessions?.set(SESSION, { pid: process.pid, cwd: process.cwd(), isAlive: () => true });
67
+ const res = await post('{not json');
68
+ expect(res.status).toBe(400);
69
+ });
70
+
71
+ test('a project with no running shared browser reports 503', async () => {
72
+ globals.__ompSessions?.set(SESSION, {
73
+ pid: process.pid,
74
+ // A directory with no scope.json: discovery finds no runtime for it.
75
+ cwd: path.join(process.cwd(), 'tmp-no-browser-here'),
76
+ isAlive: () => true,
77
+ });
78
+ const res = await post({ targetId: 'abc' });
79
+ expect(res.status).toBe(503);
80
+ expect(((await res.json()) as { error: string }).error).toContain('No shared browser');
81
+ });
82
+
83
+ test('MOCK mode never reaches a daemon', async () => {
84
+ Bun.env.MOCK = '1';
85
+ globals.__ompSessions?.set(SESSION, { pid: process.pid, cwd: process.cwd(), isAlive: () => true });
86
+ const res = await post({ targetId: 'abc' });
87
+ expect(res.status).toBe(503);
88
+ });
89
+
90
+ test('a missing sessionId is a client error, not a silent no-op', async () => {
91
+ const res = await post({ targetId: 'abc' }, '');
92
+ expect(res.status).toBe(400);
93
+ });
94
+ });
@@ -0,0 +1,85 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * POST /api/browser/:sessionId/tabs/close — close one page this session's omp
8
+ * agent opened in the project-shared Chromium.
9
+ *
10
+ * Why the panel needs it: an agent that visits several pages leaves them all
11
+ * open in the shared daemon. The panel attaches to the newest owned target, so
12
+ * a pile of stale tabs is one more reason it shows the wrong page, and each one
13
+ * keeps a renderer alive.
14
+ *
15
+ * The ownership rule and the CDP behaviour are `shared/lib/browser/tab-close.ts`
16
+ * (one copy, so the panel and this route cannot disagree). This module only
17
+ * turns them into status codes:
18
+ *
19
+ * - 404 the session is not running here — there is no agent whose tab to close
20
+ * - 503 no shared browser for the session's project (nothing to connect to)
21
+ * - 403 the target is not one of THIS session's tabs
22
+ * - 200 closed, with the surviving tabs and the neighbour to select next
23
+ *
24
+ * A target the browser no longer knows is reported as `alreadyClosed: true`
25
+ * rather than an error: the caller asked for a tab to be gone, and it is.
26
+ */
27
+
28
+ import { json, type ActionFunctionArgs } from '@/server/lib/remix-compat';
29
+ import { parseJsonBody, requireParam } from '@/server/lib/route-adapter';
30
+ import { isMockMode } from '@/server/mock.server';
31
+ import { getRpcSession } from '@/server/lib/omp/rpc/session-registry';
32
+ import { findProjectRuntimeDir, readOwnedTargetIds } from '@/server/lib/browser/runtime';
33
+ import { acquireConnection, releaseConnection } from '@/shared/lib/browser/connection';
34
+ import { closeVerdict, neighbourTargetId, readCloseTarget } from '@/shared/lib/browser/tab-close';
35
+
36
+ interface CloseBody {
37
+ targetId?: unknown;
38
+ }
39
+
40
+ export async function action({ request, params }: ActionFunctionArgs) {
41
+ const sessionId = requireParam(params, 'sessionId');
42
+ if (!sessionId) return json({ error: 'Missing session id' }, { status: 400 });
43
+ if (isMockMode()) {
44
+ return json({ error: 'The shared browser is not available in MOCK mode' }, { status: 503 });
45
+ }
46
+
47
+ const parsed = await parseJsonBody<CloseBody>(request);
48
+ if (!parsed.ok) return json({ error: 'Invalid JSON body' }, { status: 400 });
49
+ const targetId = readCloseTarget(parsed.body.targetId);
50
+ if (!targetId) return json({ error: 'Missing or malformed targetId' }, { status: 400 });
51
+
52
+ const session = getRpcSession(sessionId);
53
+ if (!session || !session.isAlive() || session.pid === undefined) {
54
+ return json({ error: 'This session is not running, so it owns no browser tabs' }, { status: 404 });
55
+ }
56
+
57
+ const runtime = await findProjectRuntimeDir(session.cwd);
58
+ if (!runtime) return json({ error: 'No shared browser is running for this project' }, { status: 503 });
59
+
60
+ // Ownership is decided against the on-disk registry, the same source the
61
+ // viewer scopes its tab list to: the daemon hosts every session's pages, so
62
+ // a target id from another one must be refused rather than attempted.
63
+ const owned = await readOwnedTargetIds(runtime.runtimeDir, runtime.daemonName, session.pid);
64
+ const verdict = closeVerdict(targetId, owned);
65
+ if (!verdict.ok) {
66
+ return json({ error: verdict.reason, remaining: verdict.remaining }, { status: 403 });
67
+ }
68
+
69
+ const conn = await acquireConnection(runtime.wsUrl).catch(() => null);
70
+ if (!conn) return json({ error: 'Could not reach the shared browser' }, { status: 503 });
71
+ try {
72
+ const reply = await conn.send('Target.closeTarget', { targetId }).catch((error: unknown) => error);
73
+ if (reply instanceof Error) {
74
+ // "No target found for targetId" is the page having gone away already:
75
+ // the outcome the caller asked for, not a failure of this request.
76
+ if (reply.message.includes('No target found')) {
77
+ return json({ ok: true, alreadyClosed: true, remaining: verdict.remaining, next: neighbourTargetId(owned, targetId) });
78
+ }
79
+ return json({ error: reply.message }, { status: 502 });
80
+ }
81
+ return json({ ok: true, alreadyClosed: false, remaining: verdict.remaining, next: neighbourTargetId(owned, targetId) });
82
+ } finally {
83
+ releaseConnection(runtime.wsUrl, conn);
84
+ }
85
+ }
@@ -23,6 +23,7 @@ import { modelsBindings } from '@/server/routes/models';
23
23
  import { ompBindings } from '@/server/routes/omp';
24
24
  import { updatesBindings } from '@/server/routes/updates';
25
25
  import { wikiBindings } from '@/server/routes/wiki';
26
+ import { reviewBindings } from '@/server/routes/review/bindings';
26
27
  import { panelsBindings } from '@/server/routes/panels/bindings';
27
28
  import { pluginsBindings } from '@/server/routes/plugins/bindings';
28
29
  import { realtimeWsRoutes } from '@/server/routes/realtime/ws';
@@ -52,6 +53,7 @@ const allBindings: HandlerBinding[] = [
52
53
  ...ompBindings,
53
54
  ...updatesBindings,
54
55
  ...wikiBindings,
56
+ ...reviewBindings,
55
57
  ...panelsBindings,
56
58
  ...pluginsBindings,
57
59
  ...healthBindings,
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import { bindingsFor, type HandlerBinding } from '@/server/lib/route-adapter';
7
+ import * as review from '@/server/routes/review/index';
8
+
9
+ export const reviewBindings: HandlerBinding[] = bindingsFor(review, '/api/review', {
10
+ mutating: ['POST', 'DELETE'],
11
+ });
@@ -0,0 +1,127 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * `/api/review` — a document's review annotations.
8
+ *
9
+ * GET `?path=&root=&repo=` → `{ annotations, scope }`
10
+ * POST → upsert one judgement for one block
11
+ * DELETE `?id=` → remove one
12
+ *
13
+ * The scope is resolved HERE, from the same `root`/`repo` pair every other file
14
+ * route takes, so an annotation can never name a directory the caller could not
15
+ * read: `resolveRoot` falls back the same way and `resolveWithinRoot` refuses an
16
+ * escape. The stored key is `<resolvedRoot>\0<repo>`, the spelling the realtime
17
+ * workspace topics already use for the same pair.
18
+ */
19
+
20
+ import { json, NO_STORE_HEADERS } from '@/server/lib/remix-compat';
21
+ import type { ActionFunctionArgs, LoaderFunctionArgs } from '@/server/lib/remix-compat';
22
+ import { methodNotAllowedResponse } from '@/server/lib/route-adapter';
23
+ import { getDefaultFsRoot, resolveRoot, resolveWithinRoot } from '@/server/lib/fs/root';
24
+ import { normalizeRelativePath } from '@/server/lib/fs/relative-path';
25
+ import { isMockMode } from '@/server/mock.server';
26
+ import { deleteAnnotation, listAnnotations, saveAnnotation } from '@/server/lib/review/store.server';
27
+ import type { BlockVerdict } from '@/shared/lib/markdown/blocks/types';
28
+
29
+ /** The scope key for one (root, repo) pair, or null when the pair is invalid. */
30
+ async function resolveScope(root: string | null, repo: string | null): Promise<{ scope: string; repo: string } | null> {
31
+ const resolvedRoot = await resolveRoot(root, await getDefaultFsRoot(isMockMode()));
32
+ const scopedRepo = repo && repo !== '.' ? repo : '.';
33
+ // A nested repo is only valid INSIDE this root; anything else is the same 403
34
+ // `/api/fs/dir` answers rather than a silently different document.
35
+ if (scopedRepo !== '.' && resolveWithinRoot(resolvedRoot, scopedRepo) === null) return null;
36
+ return { scope: `${resolvedRoot}\u0000${scopedRepo}`, repo: scopedRepo };
37
+ }
38
+
39
+ function normalizedPath(raw: unknown): string | null {
40
+ if (typeof raw !== 'string' || !raw.trim()) return null;
41
+ return normalizeRelativePath(raw);
42
+ }
43
+
44
+ export async function loader({ request }: LoaderFunctionArgs) {
45
+ const url = new URL(request.url);
46
+ const path = normalizedPath(url.searchParams.get('path'));
47
+ if (!path) return json({ error: 'path is required' }, { status: 400, headers: NO_STORE_HEADERS });
48
+ const target = await resolveScope(url.searchParams.get('root'), url.searchParams.get('repo'));
49
+ if (!target) return json({ error: 'Invalid repo path' }, { status: 403, headers: NO_STORE_HEADERS });
50
+
51
+ const annotations = await listAnnotations(target.scope, path);
52
+ return json({ annotations, scope: target.scope }, { headers: NO_STORE_HEADERS });
53
+ }
54
+
55
+ /** One field at a time, so a bad body names what is wrong instead of "invalid". */
56
+ interface ParsedBody {
57
+ scope?: never;
58
+ root: string | null;
59
+ repo: string | null;
60
+ path: string | null;
61
+ blockKey: string | null;
62
+ lineStart: number;
63
+ lineEnd: number;
64
+ verdict: BlockVerdict | null;
65
+ note: string;
66
+ quote: string;
67
+ }
68
+
69
+ function parseBody(raw: unknown): ParsedBody | string {
70
+ if (typeof raw !== 'object' || raw === null) return 'body must be an object';
71
+ const body = raw as Record<string, unknown>;
72
+ const blockKey = typeof body.blockKey === 'string' ? body.blockKey.trim() : '';
73
+ if (!blockKey) return 'blockKey is required';
74
+ if (body.verdict !== 'good' && body.verdict !== 'needs-work') return 'verdict must be "good" or "needs-work"';
75
+ const line = (value: unknown): number => (typeof value === 'number' && Number.isInteger(value) && value >= 0 ? value : 0);
76
+ return {
77
+ root: typeof body.root === 'string' ? body.root : null,
78
+ repo: typeof body.repo === 'string' ? body.repo : null,
79
+ path: normalizedPath(body.path),
80
+ blockKey,
81
+ lineStart: line(body.lineStart),
82
+ lineEnd: line(body.lineEnd),
83
+ verdict: body.verdict,
84
+ note: typeof body.note === 'string' ? body.note.slice(0, 4000) : '',
85
+ quote: typeof body.quote === 'string' ? body.quote.slice(0, 400) : '',
86
+ };
87
+ }
88
+
89
+ async function saveFrom({ request }: ActionFunctionArgs) {
90
+ const parsed = parseBody(await request.json().catch(() => null));
91
+ if (typeof parsed === 'string') return json({ error: parsed }, { status: 400 });
92
+ if (!parsed.path) return json({ error: 'path is required' }, { status: 400 });
93
+ if (!parsed.verdict) return json({ error: 'verdict is required' }, { status: 400 });
94
+ const target = await resolveScope(parsed.root, parsed.repo);
95
+ if (!target) return json({ error: 'Invalid repo path' }, { status: 403 });
96
+
97
+ const annotation = await saveAnnotation({
98
+ scope: target.scope,
99
+ path: parsed.path,
100
+ blockKey: parsed.blockKey as string,
101
+ lineStart: parsed.lineStart,
102
+ lineEnd: parsed.lineEnd,
103
+ verdict: parsed.verdict,
104
+ note: parsed.note,
105
+ quote: parsed.quote,
106
+ });
107
+ return json({ annotation }, { headers: NO_STORE_HEADERS });
108
+ }
109
+
110
+ async function removeFrom({ request }: ActionFunctionArgs) {
111
+ const id = new URL(request.url).searchParams.get('id');
112
+ if (!id) return json({ error: 'id is required' }, { status: 400 });
113
+ const removed = await deleteAnnotation(id);
114
+ if (!removed) return json({ error: 'No annotation with that id' }, { status: 404 });
115
+ return json({ success: true }, { headers: NO_STORE_HEADERS });
116
+ }
117
+
118
+ export async function action(args: ActionFunctionArgs) {
119
+ switch (args.request.method) {
120
+ case 'POST':
121
+ return saveFrom(args);
122
+ case 'DELETE':
123
+ return removeFrom(args);
124
+ default:
125
+ return methodNotAllowedResponse();
126
+ }
127
+ }