@kabmo-labs/kabmo 0.17.0 → 0.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 (438) hide show
  1. package/README.md +10 -7
  2. package/dist/client/index.html +1 -1
  3. package/dist/client/index.js +523 -441
  4. package/dist/client/static/js/{index-rerjq5th.js → index-fcee4c13.js} +828 -818
  5. package/dist/client/static/js/index-sxdw908m.css +1 -0
  6. package/marketplace/plugins/command-runner/package.json +3 -2
  7. package/marketplace/plugins/git-forge/package.json +3 -2
  8. package/marketplace/plugins/session-info/package.json +3 -2
  9. package/marketplace/plugins/stats/package.json +3 -2
  10. package/package.json +3 -1
  11. package/src/client/components/auth/login-screen/index.tsx +2 -1
  12. package/src/client/components/common/ComposerPicker.tsx +1 -1
  13. package/src/client/components/common/FolderPicker.tsx +2 -2
  14. package/src/client/components/common/MarkdownRenderer.tsx +136 -89
  15. package/src/client/components/common/Modal.tsx +2 -2
  16. package/src/client/components/common/PWAInstallButton.tsx +2 -2
  17. package/src/client/components/common/ViewportSelector.tsx +1 -1
  18. package/src/client/components/common/anchored-menu/index.test.tsx +141 -0
  19. package/src/client/components/common/anchored-menu/index.tsx +147 -0
  20. package/src/client/components/common/batch-selection/SelectionCheckbox.tsx +2 -1
  21. package/src/client/components/common/brand-wordmark/index.test.tsx +13 -2
  22. package/src/client/components/common/brand-wordmark/index.tsx +13 -2
  23. package/src/client/components/common/checkbox/style.test.ts +139 -0
  24. package/src/client/components/common/checkbox/style.ts +51 -0
  25. package/src/client/components/common/context-usage-button/index.tsx +2 -2
  26. package/src/client/components/common/file-icon/index.tsx +23 -9
  27. package/src/client/components/common/header-controls/MoreMenu.tsx +1 -1
  28. package/src/client/components/common/markdown-review/ReviewPopover.tsx +144 -0
  29. package/src/client/components/common/markdown-review/ReviewSummary.tsx +108 -0
  30. package/src/client/components/common/markdown-review/index.tsx +129 -0
  31. package/src/client/components/common/panel-mark/index.tsx +97 -0
  32. package/src/client/components/common/provider-icon/glyphs.test.ts +1 -1
  33. package/src/client/components/common/provider-icon/index.test.ts +14 -0
  34. package/src/client/components/common/provider-icon/index.tsx +4 -0
  35. package/src/client/components/common/provider-icon/resolve.test.ts +8 -7
  36. package/src/client/components/common/provider-icon/resolve.ts +16 -3
  37. package/src/client/components/common/server-control/Panel.tsx +33 -23
  38. package/src/client/components/common/server-control/index.test.tsx +11 -5
  39. package/src/client/components/common/server-control/index.tsx +10 -8
  40. package/src/client/components/common/session-actions-menu/index.tsx +1 -1
  41. package/src/client/components/common/toolbar-row/index.tsx +1 -1
  42. package/src/client/components/layout/ActivityBar.tsx +22 -3
  43. package/src/client/components/layout/LeftDock.tsx +9 -2
  44. package/src/client/components/layout/PanelVisibilityMenu.tsx +1 -1
  45. package/src/client/components/layout/WindowAura.tsx +27 -0
  46. package/src/client/components/layout/desktop-layout/LeftColumn.tsx +1 -1
  47. package/src/client/components/layout/desktop-layout/TopNavbar.tsx +2 -2
  48. package/src/client/components/layout/desktop-layout/WorkspacePanels.tsx +11 -2
  49. package/src/client/components/layout/desktop-layout/index.tsx +3 -1
  50. package/src/client/components/layout/session-sidebar/CategoryHeader.tsx +44 -23
  51. package/src/client/components/layout/session-sidebar/CategoryHeader.worktree.test.tsx +36 -17
  52. package/src/client/components/layout/session-sidebar/CategoryItem.tsx +8 -7
  53. package/src/client/components/layout/session-sidebar/Header.tsx +1 -1
  54. package/src/client/components/layout/session-sidebar/OverflowMenu.tsx +1 -1
  55. package/src/client/components/layout/session-sidebar/Toolbar.tsx +1 -1
  56. package/src/client/components/layout/session-sidebar/about-modal/NotesDialog.tsx +94 -0
  57. package/src/client/components/layout/session-sidebar/about-modal/VersionLine.test.tsx +68 -0
  58. package/src/client/components/layout/session-sidebar/about-modal/VersionLine.tsx +36 -0
  59. package/src/client/components/layout/session-sidebar/about-modal/index.tsx +57 -34
  60. package/src/client/components/layout/session-sidebar/modern/ActionRow.tsx +1 -1
  61. package/src/client/components/layout/session-sidebar/modern/WorkspaceHeader.tsx +40 -14
  62. package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +7 -6
  63. package/src/client/components/layout/session-sidebar/modern/workspace-header.test.tsx +1 -1
  64. package/src/client/components/layout/session-sidebar/new-workspace-modal/index.tsx +2 -2
  65. package/src/client/components/layout/session-sidebar/scheduler-modal/TaskForm.tsx +2 -1
  66. package/src/client/components/layout/session-sidebar/scheduler-modal/index.tsx +2 -2
  67. package/src/client/components/layout/update-popup/ReleaseNotes.tsx +8 -3
  68. package/src/client/components/layout/update-popup/index.tsx +5 -1
  69. package/src/client/components/mobile/LayoutWrapper.tsx +3 -1
  70. package/src/client/components/mobile/mobile-main-view/Header.tsx +2 -2
  71. package/src/client/components/mobile/mobile-right-sidebar/FullEditor.tsx +13 -15
  72. package/src/client/components/mobile/mobile-right-sidebar/Header.tsx +23 -1
  73. package/src/client/components/mobile/mobile-right-sidebar/MissingFileBanner.tsx +30 -0
  74. package/src/client/components/mobile/mobile-right-sidebar/PreviewScroller.tsx +18 -2
  75. package/src/client/components/mobile/mobile-session-sidebar/Header.tsx +1 -1
  76. package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +22 -67
  77. package/src/client/components/mobile/mobile-session-sidebar/ItemMenu.tsx +110 -0
  78. package/src/client/components/mobile/mobile-session-sidebar/Toolbar.tsx +1 -1
  79. package/src/client/components/mobile/panel-chips.tsx +10 -2
  80. package/src/client/components/settings/Modal.tsx +4 -4
  81. package/src/client/components/settings/ProjectSelectorDropdown.tsx +2 -2
  82. package/src/client/components/settings/SettingsSidebarList.tsx +20 -0
  83. package/src/client/components/settings/apply-side-effects.test.ts +30 -0
  84. package/src/client/components/settings/apply-side-effects.ts +14 -0
  85. package/src/client/components/settings/categories/AgentSettings.tsx +23 -50
  86. package/src/client/components/settings/categories/AppearanceSettings.tsx +6 -0
  87. package/src/client/components/settings/categories/CommandSettings.tsx +2 -2
  88. package/src/client/components/settings/categories/McpSettings.tsx +4 -21
  89. package/src/client/components/settings/categories/OmpSettings.tsx +147 -194
  90. package/src/client/components/settings/categories/SkillSettings.tsx +2 -2
  91. package/src/client/components/settings/categories/TokenUsageSettings.tsx +211 -229
  92. package/src/client/components/settings/categories/agent-settings/DetailPane.tsx +229 -237
  93. package/src/client/components/settings/categories/agent-settings/ModelPicker.tsx +71 -0
  94. package/src/client/components/settings/categories/agent-settings/SidebarList.tsx +9 -2
  95. package/src/client/components/settings/categories/agent-settings/levels.ts +38 -0
  96. package/src/client/components/settings/categories/appearance-settings/EditorBlameSection.tsx +2 -1
  97. package/src/client/components/settings/categories/appearance-settings/EditorTypingSection.tsx +2 -1
  98. package/src/client/components/settings/categories/appearance-settings/IconStyleSection.tsx +144 -0
  99. package/src/client/components/settings/categories/appearance-settings/SurfaceStyleSection.test.tsx +120 -0
  100. package/src/client/components/settings/categories/appearance-settings/SurfaceStyleSection.tsx +180 -0
  101. package/src/client/components/settings/categories/behavior-settings/Editor.tsx +27 -7
  102. package/src/client/components/settings/categories/chat-settings/ToolRenderSection.tsx +23 -5
  103. package/src/client/components/settings/categories/command-settings/DetailPane.tsx +75 -33
  104. package/src/client/components/settings/categories/command-settings/SidebarList.tsx +7 -0
  105. package/src/client/components/settings/categories/mcp-settings/DetailPane.tsx +93 -77
  106. package/src/client/components/settings/categories/mcp-settings/EnvVarsSection.tsx +83 -0
  107. package/src/client/components/settings/categories/mcp-settings/ImportModal.tsx +28 -15
  108. package/src/client/components/settings/categories/mcp-settings/SidebarList.tsx +20 -0
  109. package/src/client/components/settings/categories/omp-settings/ConfigTabs.tsx +97 -36
  110. package/src/client/components/settings/categories/omp-settings/EngineHeader.tsx +151 -0
  111. package/src/client/components/settings/categories/omp-settings/ExtensionsPanel.tsx +68 -32
  112. package/src/client/components/settings/categories/omp-settings/OrderedChips.tsx +119 -0
  113. package/src/client/components/settings/categories/omp-settings/PresetBar.tsx +14 -7
  114. package/src/client/components/settings/categories/omp-settings/RoleEditor.tsx +15 -6
  115. package/src/client/components/settings/categories/omp-settings/RowEditor.tsx +165 -226
  116. package/src/client/components/settings/categories/omp-settings/types.ts +28 -0
  117. package/src/client/components/settings/categories/panel-plugins/AvailableList.tsx +1 -1
  118. package/src/client/components/settings/categories/panel-plugins/BuiltinList.tsx +21 -3
  119. package/src/client/components/settings/categories/panel-plugins/PluginCard.tsx +1 -1
  120. package/src/client/components/settings/categories/panel-plugins/PluginMark.test.ts +51 -2
  121. package/src/client/components/settings/categories/panel-plugins/PluginMark.tsx +43 -10
  122. package/src/client/components/settings/categories/plugin-settings/DetailPane.tsx +2 -1
  123. package/src/client/components/settings/categories/plugin-settings/SettingsSection.tsx +2 -1
  124. package/src/client/components/settings/categories/project-settings/ModelDropdown.tsx +1 -1
  125. package/src/client/components/settings/categories/project-settings/WorktreeSettings.tsx +2 -1
  126. package/src/client/components/settings/categories/provider-settings/DeleteProviderModal.tsx +2 -2
  127. package/src/client/components/settings/categories/provider-settings/EntryAdvanced.tsx +3 -2
  128. package/src/client/components/settings/categories/provider-settings/LogoutProviderModal.tsx +2 -2
  129. package/src/client/components/settings/categories/skill-catalog/GitImportPanel.tsx +3 -2
  130. package/src/client/components/settings/categories/skill-settings/DetailHeader.tsx +37 -8
  131. package/src/client/components/settings/categories/skill-settings/DetailPane.tsx +34 -14
  132. package/src/client/components/settings/categories/skill-settings/SidebarList.tsx +21 -0
  133. package/src/client/components/settings/categories/skill-settings/pane.test.tsx +15 -6
  134. package/src/client/components/settings/categories/token-usage-settings/Breakdown.tsx +242 -102
  135. package/src/client/components/settings/categories/token-usage-settings/Chart.tsx +130 -56
  136. package/src/client/components/settings/categories/token-usage-settings/Controls.tsx +135 -0
  137. package/src/client/components/settings/categories/token-usage-settings/MetricsGrid.tsx +55 -33
  138. package/src/client/components/settings/categories/token-usage-settings/Provenance.tsx +59 -0
  139. package/src/client/components/settings/categories/token-usage-settings/panel.test.tsx +239 -0
  140. package/src/client/components/workspace/browser-panel/Screencast.test.ts +1 -0
  141. package/src/client/components/workspace/browser-panel/Screencast.tsx +17 -22
  142. package/src/client/components/workspace/browser-panel/TabStrip.test.tsx +158 -0
  143. package/src/client/components/workspace/browser-panel/TabStrip.tsx +90 -0
  144. package/src/client/components/workspace/browser-panel/index.tsx +50 -4
  145. package/src/client/components/workspace/browser-toolbar/index.tsx +41 -1
  146. package/src/client/components/workspace/btw-panel/TopicMenu.tsx +1 -1
  147. package/src/client/components/workspace/chat-timeline/AiMessageFooter.tsx +2 -2
  148. package/src/client/components/workspace/chat-timeline/NewChatModal.tsx +3 -3
  149. package/src/client/components/workspace/chat-timeline/ThinkingSection.tsx +3 -1
  150. package/src/client/components/workspace/chat-timeline/ToolCallingSection.tsx +2 -0
  151. package/src/client/components/workspace/chat-timeline/UndoConfirmModal.tsx +2 -2
  152. package/src/client/components/workspace/chat-timeline/block-chrome.test.tsx +13 -2
  153. package/src/client/components/workspace/chat-timeline/chat-input/AccessDropdown.tsx +1 -1
  154. package/src/client/components/workspace/chat-timeline/chat-input/GoalModal.tsx +4 -3
  155. package/src/client/components/workspace/chat-timeline/chat-input/ThinkingLevelDropdown.tsx +1 -1
  156. package/src/client/components/workspace/chat-timeline/chat-input/WaitingDependencyPicker.tsx +1 -1
  157. package/src/client/components/workspace/chat-timeline/plan-review/index.tsx +2 -2
  158. package/src/client/components/workspace/chat-timeline/target-picker/WorkspacePicker.tsx +1 -1
  159. package/src/client/components/workspace/chat-timeline/target-picker/WorktreePicker.tsx +1 -1
  160. package/src/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/index.tsx +2 -6
  161. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Bash.test.ts +88 -0
  162. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Bash.tsx +24 -1
  163. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Read.test.ts +34 -0
  164. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Read.tsx +5 -1
  165. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/ArtifactChip.tsx +7 -6
  166. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Tui.test.tsx +237 -0
  167. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Tui.tsx +191 -0
  168. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/styles.test.tsx +1 -1
  169. package/src/client/components/workspace/context-panel/CostBreakdownPopover.tsx +1 -1
  170. package/src/client/components/workspace/diff-panel/MergeDiffView.tsx +21 -7
  171. package/src/client/components/workspace/diff-panel/changes.test.ts +51 -0
  172. package/src/client/components/workspace/diff-panel/changes.ts +28 -12
  173. package/src/client/components/workspace/diff-panel/index.tsx +2 -2
  174. package/src/client/components/workspace/diff-panel/merge.test.ts +28 -0
  175. package/src/client/components/workspace/diff-panel/merge.ts +21 -1
  176. package/src/client/components/workspace/editor/Body.tsx +7 -0
  177. package/src/client/components/workspace/editor/FileDocument.tsx +15 -21
  178. package/src/client/components/workspace/editor/FilePane.tsx +12 -0
  179. package/src/client/components/workspace/editor/PluginRail.tsx +1 -1
  180. package/src/client/components/workspace/editor/PreviewPane.tsx +70 -0
  181. package/src/client/components/workspace/editor/SaveDeletedFileModal.tsx +2 -2
  182. package/src/client/components/workspace/editor/TabContextMenu.tsx +1 -1
  183. package/src/client/components/workspace/editor/Tabs.tsx +1 -1
  184. package/src/client/components/workspace/editor/Toolbar.tsx +17 -1
  185. package/src/client/components/workspace/editor/index.tsx +25 -22
  186. package/src/client/components/workspace/editor/toolbar-clusters.test.ts +14 -0
  187. package/src/client/components/workspace/editor/toolbar-clusters.tsx +12 -86
  188. package/src/client/components/workspace/editor/toolbar-toggle.tsx +53 -0
  189. package/src/client/components/workspace/editor/toolbar-write-clusters.tsx +112 -0
  190. package/src/client/components/workspace/file-explorer/ContextMenu.tsx +1 -1
  191. package/src/client/components/workspace/file-explorer/Modals.tsx +10 -10
  192. package/src/client/components/workspace/file-explorer/RootMenu.tsx +1 -1
  193. package/src/client/components/workspace/git-panel/BranchToolbar.test.tsx +130 -0
  194. package/src/client/components/workspace/git-panel/BranchToolbar.tsx +21 -11
  195. package/src/client/components/workspace/git-panel/CommitBox.tsx +2 -1
  196. package/src/client/components/workspace/git-panel/Modals.tsx +2 -2
  197. package/src/client/components/workspace/git-panel/StashSection.tsx +2 -1
  198. package/src/client/components/workspace/git-panel/branch-modal/DeleteDialog.tsx +2 -1
  199. package/src/client/components/workspace/git-panel/branch-modal/RenameDialog.tsx +2 -1
  200. package/src/client/components/workspace/git-panel/commit-modal/index.tsx +2 -2
  201. package/src/client/components/workspace/git-panel/commit-modal.test.ts +5 -3
  202. package/src/client/components/workspace/git-panel/index.tsx +7 -0
  203. package/src/client/components/workspace/model-dropdown/Panel.tsx +1 -1
  204. package/src/client/components/workspace/model-dropdown/SpecsTooltip.tsx +1 -1
  205. package/src/client/components/workspace/plugin-panel/catalog.tsx +7 -0
  206. package/src/client/components/workspace/plugin-panel/resolve.tsx +4 -0
  207. package/src/client/components/workspace/search-panel/Body.tsx +1 -1
  208. package/src/client/components/workspace/usage-panel/ProviderSelect.tsx +1 -1
  209. package/src/client/components/workspace/user-browser-panel/AddressBar.tsx +5 -0
  210. package/src/client/components/workspace/user-browser-panel/AnnotateBar.test.tsx +201 -0
  211. package/src/client/components/workspace/user-browser-panel/AnnotateBar.tsx +112 -0
  212. package/src/client/components/workspace/user-browser-panel/AnnotateLayer.test.tsx +225 -0
  213. package/src/client/components/workspace/user-browser-panel/AnnotateLayer.tsx +217 -0
  214. package/src/client/components/workspace/user-browser-panel/AnnotateTarget.tsx +99 -0
  215. package/src/client/components/workspace/user-browser-panel/Frame.tsx +30 -1
  216. package/src/client/components/workspace/user-browser-panel/index.tsx +81 -2
  217. package/src/client/data/agent-data/builtin.ts +0 -10
  218. package/src/client/data/agent-data/orchestrator.ts +0 -45
  219. package/src/client/data/agent-data/specialist.ts +0 -100
  220. package/src/client/data/mock/token-usage.ts +170 -120
  221. package/src/client/data/settings/omp-schema.json +33 -1
  222. package/src/client/glass.css +785 -0
  223. package/src/client/glass.test.ts +346 -0
  224. package/src/client/hooks/browser/use-annotate.test.ts +143 -0
  225. package/src/client/hooks/browser/use-annotate.ts +98 -0
  226. package/src/client/hooks/browser/use-close-tab.test.ts +148 -0
  227. package/src/client/hooks/browser/use-close-tab.ts +67 -0
  228. package/src/client/hooks/browser/use-screencast.ts +13 -1
  229. package/src/client/hooks/chat/composer/browser-context.test.ts +117 -0
  230. package/src/client/hooks/chat/composer/browser-context.ts +40 -16
  231. package/src/client/hooks/chat/composer/items.test.ts +1 -1
  232. package/src/client/hooks/chat/composer/review-context.ts +38 -0
  233. package/src/client/hooks/chat/composer/use-draft.test.ts +132 -0
  234. package/src/client/hooks/chat/composer/use-draft.ts +31 -2
  235. package/src/client/hooks/chat/timeline/row-window.test.ts +15 -2
  236. package/src/client/hooks/editor/use-document-annotations.ts +124 -0
  237. package/src/client/hooks/editor/use-editor-panel-ui.ts +52 -0
  238. package/src/client/hooks/editor/use-file-review-mode.ts +35 -0
  239. package/src/client/hooks/editor/use-preview-review.ts +148 -0
  240. package/src/client/hooks/settings/agents.ts +149 -0
  241. package/src/client/hooks/settings/crud-list.test.ts +28 -6
  242. package/src/client/hooks/settings/crud-list.ts +96 -57
  243. package/src/client/hooks/settings/omp-config.ts +164 -0
  244. package/src/client/hooks/settings/useTokenUsage.ts +125 -0
  245. package/src/client/hooks/settings/write-feedback.test.ts +104 -0
  246. package/src/client/hooks/settings/write-feedback.ts +63 -0
  247. package/src/client/hooks/ui/glass-support.ts +57 -0
  248. package/src/client/hooks/ui/icon-style.ts +59 -0
  249. package/src/client/hooks/ui/markdown-hydration.ts +125 -0
  250. package/src/client/hooks/ui/stuck-header.test.ts +188 -0
  251. package/src/client/hooks/ui/stuck-header.ts +91 -0
  252. package/src/client/hooks/ui/style-attributes.test.ts +120 -0
  253. package/src/client/hooks/ui/surface-style.ts +56 -0
  254. package/src/client/hooks/ui/updates/index.test.ts +100 -1
  255. package/src/client/hooks/ui/updates/index.ts +50 -0
  256. package/src/client/hooks/ui/updates/notes.test.ts +138 -0
  257. package/src/client/hooks/ui/updates/notes.ts +57 -0
  258. package/src/client/hooks/workspace/panel-hues.ts +23 -0
  259. package/src/client/lib/browser/element-at.test.ts +229 -0
  260. package/src/client/lib/browser/element-at.ts +139 -0
  261. package/src/client/lib/review/client.ts +73 -0
  262. package/src/client/lib/router/search-params.ts +42 -20
  263. package/src/client/main.tsx +10 -0
  264. package/src/client/tailwind.css +329 -11
  265. package/src/server/lib/assets/shell-attributes.server.ts +80 -0
  266. package/src/server/lib/assets/shell-attributes.test.ts +86 -0
  267. package/src/server/lib/btw/lifecycle.server.ts +2 -2
  268. package/src/server/lib/db/schema.ts +7 -0
  269. package/src/server/lib/db/seed-terminal.test.ts +4 -0
  270. package/src/server/lib/omp/config/agent-definitions.test.ts +273 -0
  271. package/src/server/lib/omp/config/agents.ts +231 -61
  272. package/src/server/lib/omp/config/definitions.test.ts +9 -105
  273. package/src/server/lib/omp/config/extensions.ts +16 -7
  274. package/src/server/lib/omp/config/omp-config-files.test.ts +27 -0
  275. package/src/server/lib/omp/rpc/constants.test.ts +11 -0
  276. package/src/server/lib/omp/rpc/constants.ts +15 -0
  277. package/src/server/lib/omp/rpc/frame-fold-host.test-util.ts +1 -0
  278. package/src/server/lib/omp/rpc/frame-fold-signals.test.ts +2 -30
  279. package/src/server/lib/omp/rpc/frame-fold.test.ts +55 -0
  280. package/src/server/lib/omp/rpc/frame-fold.ts +4 -0
  281. package/src/server/lib/omp/rpc/manager.ts +2 -2
  282. package/src/server/lib/omp/rpc/process-helpers.ts +11 -0
  283. package/src/server/lib/omp/rpc/process.test.ts +106 -0
  284. package/src/server/lib/omp/rpc/process.ts +39 -18
  285. package/src/server/lib/omp/rpc/run-settle.server.ts +12 -0
  286. package/src/server/lib/omp/rpc/run-settle.test.ts +22 -0
  287. package/src/server/lib/omp/rpc/session-command-guards.ts +5 -0
  288. package/src/server/lib/omp/rpc/session-commands.test.ts +9 -1
  289. package/src/server/lib/omp/rpc/session-commands.ts +17 -3
  290. package/src/server/lib/omp/rpc/terminal-settle.ts +29 -7
  291. package/src/server/lib/omp/rpc/utility-agent-dir.test.ts +134 -0
  292. package/src/server/lib/omp/rpc/utility-agent-dir.ts +138 -0
  293. package/src/server/lib/omp/rpc/utility.ts +12 -0
  294. package/src/server/lib/panels/bundled-catalog.server.ts +1 -0
  295. package/src/server/lib/panels/manifest.test.ts +20 -0
  296. package/src/server/lib/panels/manifest.ts +12 -0
  297. package/src/server/lib/panels/scan.server.ts +4 -0
  298. package/src/server/lib/queue/delivery-dispatch.server.test.ts +48 -0
  299. package/src/server/lib/queue/delivery-harness.ts +8 -4
  300. package/src/server/lib/queue/delivery.server.test.ts +29 -0
  301. package/src/server/lib/queue/delivery.server.ts +39 -0
  302. package/src/server/lib/queue/store.server.test.ts +22 -2
  303. package/src/server/lib/queue/store.server.ts +33 -11
  304. package/src/server/lib/review/schema.server.ts +45 -0
  305. package/src/server/lib/review/store.server.ts +138 -0
  306. package/src/server/lib/terminal/attach-replay.test.ts +132 -0
  307. package/src/server/lib/terminal/output.test.ts +166 -0
  308. package/src/server/lib/terminal/output.ts +104 -0
  309. package/src/server/lib/terminal/runtime.server.ts +5 -0
  310. package/src/server/lib/terminal/send-result.test.ts +33 -0
  311. package/src/server/lib/terminal/send-result.ts +32 -0
  312. package/src/server/lib/terminal/session.server.ts +45 -11
  313. package/src/server/lib/terminal/store-liveness.test.ts +4 -0
  314. package/src/server/lib/updates/active-notes.test.ts +149 -0
  315. package/src/server/lib/updates/active-notes.ts +75 -0
  316. package/src/server/lib/updates/changelog-file.ts +42 -11
  317. package/src/server/lib/updates/changelog.test.ts +15 -1
  318. package/src/server/lib/updates/omp.ts +42 -15
  319. package/src/server/lib/updates/release-url.ts +27 -1
  320. package/src/server/lib/usage/index-parse.test.ts +200 -0
  321. package/src/server/lib/usage/index-parse.ts +178 -0
  322. package/src/server/lib/usage/index-query.server.ts +248 -0
  323. package/src/server/lib/usage/index-scan.server.ts +343 -0
  324. package/src/server/lib/usage/index-schema.server.ts +82 -0
  325. package/src/server/lib/usage/index.test.ts +234 -0
  326. package/src/server/lib/usage/providers.server.ts +4 -53
  327. package/src/server/plugins/ssr.ts +22 -5
  328. package/src/server/routes/browser/index.ts +3 -0
  329. package/src/server/routes/browser/stream.ts +31 -2
  330. package/src/server/routes/browser/tabs.test.ts +94 -0
  331. package/src/server/routes/browser/tabs.ts +85 -0
  332. package/src/server/routes/index.ts +2 -0
  333. package/src/server/routes/review/bindings.ts +11 -0
  334. package/src/server/routes/review/index.ts +127 -0
  335. package/src/server/routes/review/routes.test.ts +191 -0
  336. package/src/server/routes/settings/agents.test.ts +180 -0
  337. package/src/server/routes/settings/agents.ts +95 -102
  338. package/src/server/routes/settings/mcp.test.ts +135 -0
  339. package/src/server/routes/settings/mcp.ts +14 -6
  340. package/src/server/routes/settings/settings-store-routes.test.ts +6 -113
  341. package/src/server/routes/telemetry/tokens.test.ts +145 -0
  342. package/src/server/routes/telemetry/tokens.ts +70 -149
  343. package/src/server/routes/terminal/ws.ts +6 -5
  344. package/src/server/routes/updates/index.ts +2 -0
  345. package/src/server/routes/updates/notes.ts +34 -0
  346. package/src/server/routes/updates/routes.test.ts +49 -0
  347. package/src/shared/lib/browser/annotate.test.ts +283 -0
  348. package/src/shared/lib/browser/annotate.ts +231 -0
  349. package/src/shared/lib/browser/browser-viewer.test.ts +26 -4
  350. package/src/shared/lib/browser/frame-gate.test.ts +91 -0
  351. package/src/shared/lib/browser/frame-gate.ts +69 -0
  352. package/src/shared/lib/browser/frame-params.test.ts +43 -0
  353. package/src/shared/lib/browser/frame-params.ts +60 -0
  354. package/src/shared/lib/browser/frame-pipeline.test.ts +132 -0
  355. package/src/shared/lib/browser/frame-pipeline.ts +80 -0
  356. package/src/shared/lib/browser/page-context.ts +60 -4
  357. package/src/shared/lib/browser/snapshot.test.ts +115 -0
  358. package/src/shared/lib/browser/snapshot.ts +112 -0
  359. package/src/shared/lib/browser/tab-close.test.ts +74 -0
  360. package/src/shared/lib/browser/tab-close.ts +77 -0
  361. package/src/shared/lib/browser/viewer.ts +45 -26
  362. package/src/shared/lib/chat/timeline/block-chrome.ts +19 -0
  363. package/src/shared/lib/chat/timeline/tool-render-mode.ts +17 -4
  364. package/src/shared/lib/chat/tool/artifact.ts +55 -20
  365. package/src/shared/lib/chat/tool/bash-facts.ts +96 -0
  366. package/src/shared/lib/chat/tool/minimized.test.ts +98 -0
  367. package/src/shared/lib/chat/tool/minimized.ts +64 -0
  368. package/src/shared/lib/chat/tool/summary.test.ts +28 -8
  369. package/src/shared/lib/chat/tool/summary.ts +3 -32
  370. package/src/shared/lib/icons/file-brand-color.ts +38 -0
  371. package/src/shared/lib/icons/icon-paint-css.test.ts +234 -0
  372. package/src/shared/lib/icons/icon-paint-css.ts +284 -0
  373. package/src/shared/lib/icons/icon-paint-panel.ts +100 -0
  374. package/src/shared/lib/icons/tint-hues.generated.ts +230 -0
  375. package/src/shared/lib/icons/tint.test.ts +273 -0
  376. package/src/shared/lib/icons/tint.ts +219 -0
  377. package/src/shared/lib/markdown/blocks/anchor.ts +63 -0
  378. package/src/shared/lib/markdown/blocks/blocks.test.ts +141 -0
  379. package/src/shared/lib/markdown/blocks/renderer.ts +120 -0
  380. package/src/shared/lib/markdown/blocks/scan.ts +100 -0
  381. package/src/shared/lib/markdown/blocks/types.ts +62 -0
  382. package/src/shared/lib/markdown/marked.ts +58 -147
  383. package/src/shared/lib/markdown/math-extensions.ts +168 -0
  384. package/src/shared/lib/markdown/review/prompt.ts +77 -0
  385. package/src/shared/lib/markdown/review/reconcile.ts +55 -0
  386. package/src/shared/lib/markdown/review/review.test.ts +96 -0
  387. package/src/shared/lib/markdown/xml-sections.test.ts +140 -0
  388. package/src/shared/lib/markdown/xml-sections.ts +139 -0
  389. package/src/shared/lib/models/provider/brand-color.test.ts +116 -0
  390. package/src/shared/lib/models/provider/brand-color.ts +103 -0
  391. package/src/shared/lib/models/provider/label.ts +57 -0
  392. package/src/shared/lib/omp/config/agent-file.test.ts +54 -0
  393. package/src/shared/lib/omp/config/agent-file.ts +43 -0
  394. package/src/shared/lib/omp/config/row-value.test.ts +95 -0
  395. package/src/shared/lib/omp/config/row-value.ts +97 -0
  396. package/src/shared/lib/omp/config/schema.test.ts +31 -0
  397. package/src/shared/lib/omp/config/schema.ts +6 -0
  398. package/src/shared/lib/omp/rpc/frame.test.ts +113 -47
  399. package/src/shared/lib/omp/rpc/frame.ts +107 -43
  400. package/src/shared/lib/settings/defaults.ts +4 -0
  401. package/src/shared/lib/theme/catalog.test.ts +5 -4
  402. package/src/shared/lib/theme/catalog.ts +18 -3
  403. package/src/shared/lib/theme/glass-support.test.ts +38 -0
  404. package/src/shared/lib/theme/glass-support.ts +73 -0
  405. package/src/shared/lib/theme/icon-style.test.ts +74 -0
  406. package/src/shared/lib/theme/icon-style.ts +90 -0
  407. package/src/shared/lib/theme/legibility.ts +91 -0
  408. package/src/shared/lib/theme/palettes/dark-extended.ts +152 -0
  409. package/src/shared/lib/theme/palettes/light-extended.ts +157 -0
  410. package/src/shared/lib/theme/surface-style.test.ts +68 -0
  411. package/src/shared/lib/theme/surface-style.ts +91 -0
  412. package/src/shared/lib/theme/theme.test.ts +11 -7
  413. package/src/shared/lib/ui/menu-anchor.test.ts +69 -0
  414. package/src/shared/lib/ui/menu-anchor.ts +89 -0
  415. package/src/shared/lib/usage/breakdown.test.ts +197 -0
  416. package/src/shared/lib/usage/breakdown.ts +241 -0
  417. package/src/shared/lib/usage/range.test.ts +204 -0
  418. package/src/shared/lib/usage/range.ts +240 -0
  419. package/src/shared/lib/usage/view.test.ts +85 -0
  420. package/src/shared/lib/usage/view.ts +74 -0
  421. package/src/shared/lib/workspace/panel-hues.test.ts +68 -0
  422. package/src/shared/lib/workspace/panel-hues.ts +57 -0
  423. package/src/shared/types/browser.ts +78 -0
  424. package/src/shared/types/index.ts +1 -0
  425. package/src/shared/types/panels-registry.ts +6 -0
  426. package/src/shared/types/panels.ts +14 -0
  427. package/src/shared/types/settings/agent.ts +28 -6
  428. package/src/shared/types/settings/state.ts +30 -3
  429. package/src/shared/types/settings/write.ts +6 -0
  430. package/src/shared/types/tokenUsage.ts +128 -21
  431. package/src/shared/types/updates.ts +20 -0
  432. package/src/test-support/fake-omp-frames.ts +163 -0
  433. package/dist/client/static/js/index-3ve31rzx.css +0 -1
  434. package/src/server/lib/omp/session/usage/aggregate-shaping.test.ts +0 -149
  435. package/src/server/lib/omp/session/usage/aggregate.test.ts +0 -243
  436. package/src/server/lib/omp/session/usage/aggregate.ts +0 -330
  437. package/src/server/lib/omp/session/usage/shaping.ts +0 -130
  438. /package/src/{client/components/common/file-icon/brand-paths.ts → shared/lib/icons/file-brand-paths.ts} +0 -0
@@ -0,0 +1,135 @@
1
+ import { useState } from 'preact/hooks';
2
+ import { CalendarRange, RefreshCw } from 'lucide-preact';
3
+ import { localDayKey } from '@/shared/lib/usage/range';
4
+ import type { TimeRangeOption, TimeRangeType } from '@/shared/types';
5
+
6
+ interface TokenUsageControlsProps {
7
+ range: TimeRangeType;
8
+ onRange: (range: TimeRangeType) => void;
9
+ ranges: TimeRangeOption[];
10
+ customFrom: string;
11
+ customTo: string;
12
+ onCustomFrom: (value: string) => void;
13
+ onCustomTo: (value: string) => void;
14
+ periodLabel: string;
15
+ /** Epoch ms the payload was generated; the custom window is relative to it. */
16
+ generatedAt: number;
17
+ refreshing: boolean;
18
+ onRefresh: () => void;
19
+ }
20
+
21
+ /**
22
+ * The panel's control bar: the PERIOD, and refresh.
23
+ *
24
+ * Day / Week / Month / 90 days / All time / Custom are one list — they are all
25
+ * the same kind of choice (which trailing span to report), so the panel has a
26
+ * single control and no separate daily/weekly/monthly switch. Every figure in
27
+ * the panel is the total for the span selected here.
28
+ */
29
+ export function TokenUsageControls({
30
+ range,
31
+ onRange,
32
+ ranges,
33
+ customFrom,
34
+ customTo,
35
+ onCustomFrom,
36
+ onCustomTo,
37
+ periodLabel,
38
+ generatedAt,
39
+ refreshing,
40
+ onRefresh,
41
+ }: TokenUsageControlsProps) {
42
+ const [open, setOpen] = useState(false);
43
+ // "Today" is the day the PAYLOAD was built on, so the picker's ceiling cannot
44
+ // drift from the dates the panel is showing (a tab left open across midnight).
45
+ const ceiling = localDayKey(generatedAt);
46
+
47
+ return (
48
+ <div className="flex flex-col gap-2 border-b border-ink/10 pb-3 sm:flex-row sm:items-center sm:justify-between">
49
+ <div className="flex min-w-0 flex-wrap items-baseline gap-x-2 gap-y-0.5">
50
+ <span className="truncate text-xs font-semibold text-ink/75">{periodLabel}</span>
51
+ {refreshing && <span className="text-[10px] text-ink/40">updating…</span>}
52
+ </div>
53
+
54
+ <div className="flex flex-wrap items-center gap-2">
55
+ <div className="relative min-w-0 flex-1 sm:flex-none">
56
+ <button
57
+ type="button"
58
+ aria-expanded={open}
59
+ onClick={() => setOpen((value) => !value)}
60
+ className="flex items-center gap-1.5 rounded-md border border-ink/15 bg-paper px-2.5 py-1 text-[11px] font-medium text-ink/80 transition-colors hover:bg-ink/5"
61
+ >
62
+ <CalendarRange size={12} aria-hidden="true" />
63
+ {/* A custom window names its dates: a bare "Custom…" is
64
+ indistinguishable from a range that did nothing when its dates
65
+ happen to equal the previous preset. */}
66
+ <span>
67
+ {range === 'custom'
68
+ ? `${customFrom} – ${customTo}`
69
+ : (ranges.find((entry) => entry.id === range)?.label ?? 'Month')}
70
+ </span>
71
+ </button>
72
+
73
+ {open && (
74
+ // Anchored LEFT on phones: the trigger fills the row there, and a
75
+ // `right-0` menu hung off its right edge landed at x=-157. From
76
+ // `sm` up the trigger is narrow and right-aligned, so the menu
77
+ // follows it.
78
+ <div className="glass-popover absolute left-0 top-full z-30 mt-1 w-64 max-w-[calc(100vw-2rem)] divide-y divide-ink/5 rounded-md border border-ink/15 bg-paper py-1 text-[11px] shadow-lg sm:left-auto sm:right-0">
79
+ {ranges.map((entry) => (
80
+ <button
81
+ key={entry.id}
82
+ type="button"
83
+ aria-current={range === entry.id ? 'true' : undefined}
84
+ onClick={() => {
85
+ onRange(entry.id);
86
+ if (entry.id !== 'custom') setOpen(false);
87
+ }}
88
+ className={`flex w-full items-center justify-between gap-2 px-3 py-1.5 text-left transition-colors hover:bg-ink/5 ${
89
+ range === entry.id ? 'bg-ink/5 font-semibold text-ink' : 'text-ink/70'
90
+ }`}
91
+ >
92
+ <span className="truncate">{entry.label}</span>
93
+ <span className="shrink-0 text-[10px] text-ink/40">{entry.dateRange}</span>
94
+ </button>
95
+ ))}
96
+
97
+ {range === 'custom' && (
98
+ <div className="space-y-2 px-3 py-2">
99
+ {(
100
+ [
101
+ { label: 'From', value: customFrom, set: onCustomFrom, min: undefined, max: customTo },
102
+ { label: 'To', value: customTo, set: onCustomTo, min: customFrom, max: ceiling },
103
+ ] as const
104
+ ).map((field) => (
105
+ <label key={field.label} className="block">
106
+ <span className="text-[9px] font-mono uppercase tracking-wider text-ink/40">{field.label}</span>
107
+ <input
108
+ type="date"
109
+ value={field.value}
110
+ min={field.min}
111
+ max={field.max}
112
+ onChange={(event) => field.set(event.currentTarget.value)}
113
+ className="mt-0.5 w-full rounded border border-ink/15 bg-paper px-1.5 py-1 text-[11px] text-ink focus:border-ink/40 focus:outline-none"
114
+ />
115
+ </label>
116
+ ))}
117
+ </div>
118
+ )}
119
+ </div>
120
+ )}
121
+ </div>
122
+
123
+ <button
124
+ type="button"
125
+ onClick={onRefresh}
126
+ title="Refresh token usage"
127
+ aria-label="Refresh token usage"
128
+ className="rounded-md border border-ink/15 bg-paper p-1.5 text-ink/80 transition-colors hover:bg-ink/5"
129
+ >
130
+ <RefreshCw size={12} className={refreshing ? 'animate-spin' : ''} aria-hidden="true" />
131
+ </button>
132
+ </div>
133
+ </div>
134
+ );
135
+ }
@@ -1,44 +1,66 @@
1
- import type { TokenUsageMetricSet } from '@/shared/types';
1
+ import type { UsageTotals } from '@/shared/types';
2
2
  import { StatCard } from '@/client/components/common/StatCard';
3
+ import { cacheHitLabel, costLabel, costPerMillionLabel, toMetricSet } from '@/shared/lib/usage/view';
3
4
 
4
5
  interface TokenUsageMetricsGridProps {
5
- activeMetrics: TokenUsageMetricSet;
6
+ totals: UsageTotals;
7
+ /** Human period label (`Day`, `Week`, `Month`, …) for the cost caption. */
8
+ periodName: string;
6
9
  }
7
10
 
8
- export function TokenUsageMetricsGrid({ activeMetrics }: TokenUsageMetricsGridProps) {
9
- return (
10
- <div className="grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-5 gap-2.5 items-stretch">
11
- <StatCard
12
- value={activeMetrics.processedTokens}
13
- label="Processed tokens"
14
- hint={activeMetrics.activeRate}
15
- />
16
-
17
- <StatCard
18
- value={activeMetrics.cachedInput}
19
- label="Cached input"
20
- hint={activeMetrics.cachedPercent}
21
- />
11
+ /**
12
+ * The headline numbers for the selected period.
13
+ *
14
+ * Plain totals — the panel reports one span, so there is nothing to average and
15
+ * nothing that changes with a grouping choice. `periodName` only names the span
16
+ * the totals belong to.
17
+ */
18
+ export function TokenUsageMetricsGrid({ totals, periodName }: TokenUsageMetricsGridProps) {
19
+ const metrics = toMetricSet(totals);
20
+ const hitRate = totals.cacheRead + totals.input > 0 ? totals.cacheRead / (totals.cacheRead + totals.input) : 0;
22
21
 
23
- <StatCard
24
- value={activeMetrics.uncachedInput}
25
- label="Uncached input"
26
- hint="0 cache writes"
27
- />
22
+ return (
23
+ <div className="grid grid-cols-1 gap-3 xl:grid-cols-3">
24
+ <div className="flex flex-col justify-between rounded-lg border border-ink/15 bg-paper p-3.5 shadow-xs">
25
+ <div>
26
+ <div className="mb-2 flex items-baseline justify-between gap-2">
27
+ <span className="font-mono text-[10px] font-semibold uppercase tracking-wider text-ink/40">
28
+ Provider-reported cost
29
+ </span>
30
+ <span className="font-mono text-[9px] uppercase tracking-wider text-ink/30">{periodName}</span>
31
+ </div>
32
+ <div className="flex items-baseline gap-1.5">
33
+ <span className="text-2xl font-bold tracking-tight tabular-nums text-ink">{metrics.rawCost}</span>
34
+ <span className="text-[11px] text-ink/45">at API rates</span>
35
+ </div>
36
+ <p className="mt-1 text-[11px] text-ink/50">
37
+ {costPerMillionLabel(totals)} per 1M tokens · {metrics.processedTokens} tokens ·{' '}
38
+ {totals.records.toLocaleString('en-US')} turns
39
+ </p>
40
+ </div>
28
41
 
29
- <StatCard
30
- value={activeMetrics.outputTokens}
31
- label="Output"
32
- hint={activeMetrics.reasoning}
33
- />
42
+ <div className="mt-3">
43
+ <div className="h-1.5 w-full overflow-hidden rounded-full bg-ink/10">
44
+ <div className="h-full rounded-full bg-ink/80" style={{ width: `${Math.min(100, hitRate * 100)}%` }} />
45
+ </div>
46
+ <div className="mt-1.5 flex items-center justify-between text-[11px] text-ink/60">
47
+ <span>{cacheHitLabel(totals)} served from cache</span>
48
+ <span className="tabular-nums text-ink/80">{metrics.cachedInput} cached</span>
49
+ </div>
50
+ </div>
51
+ </div>
34
52
 
35
- <StatCard
36
- value={activeMetrics.cacheSavings}
37
- label="Cache savings"
38
- hint="0.0x the raw token cost"
39
- tone="muted"
40
- className="col-span-2 sm:col-span-1"
41
- />
53
+ <div className="grid grid-cols-2 gap-2.5 xl:col-span-2">
54
+ <StatCard value={metrics.processedTokens} label="Processed tokens" hint={metrics.activeRate} />
55
+ <StatCard value={metrics.outputTokens} label="Output" hint={metrics.reasoning} />
56
+ <StatCard value={metrics.uncachedInput} label="Uncached input" hint={`${metrics.cacheWrite} cache writes`} />
57
+ <StatCard
58
+ value={costLabel(totals.cacheReadCost)}
59
+ label="Paid for cache reads"
60
+ hint={`${metrics.cachedInput} read at the cache rate`}
61
+ tone="muted"
62
+ />
63
+ </div>
42
64
  </div>
43
65
  );
44
66
  }
@@ -0,0 +1,59 @@
1
+ import type { UsageIndexState } from '@/shared/types';
2
+
3
+ interface UsageProvenanceProps {
4
+ index: UsageIndexState;
5
+ /** Epoch ms the payload was built, so the age is independent of clock skew. */
6
+ generatedAt: number;
7
+ providers: number;
8
+ }
9
+
10
+ /** `3 s` / `2 min` / `1 h` — the index's own age, not the request's. */
11
+ function ageLabel(ms: number): string {
12
+ if (!Number.isFinite(ms) || ms < 1_000) return 'just now';
13
+ const seconds = Math.round(ms / 1_000);
14
+ if (seconds < 60) return `${seconds}s ago`;
15
+ const minutes = Math.round(seconds / 60);
16
+ if (minutes < 60) return `${minutes} min ago`;
17
+ return `${Math.round(minutes / 60)} h ago`;
18
+ }
19
+
20
+ /**
21
+ * The footer: where the numbers came from and how fresh they are.
22
+ *
23
+ * It used to be a hardcoded sentence (`… · 0.1s`, `(1 outside the window)`) that
24
+ * described a scan that had not happened. Every value here comes from the
25
+ * index's own report, and `rechecking` is used only once there is an index to
26
+ * recheck — a 40 ms background pass is not "indexing" and must not flash over
27
+ * data the user is reading.
28
+ */
29
+ export function UsageProvenance({ index, generatedAt, providers }: UsageProvenanceProps) {
30
+ const building = index.state === 'building';
31
+ const hasIndex = index.indexedAt > 0;
32
+ const status = !hasIndex
33
+ ? index.state === 'failed'
34
+ ? 'Index failed'
35
+ : 'No sessions indexed yet'
36
+ : building
37
+ ? `Updated ${ageLabel(generatedAt - index.indexedAt)} · rechecking`
38
+ : index.state === 'failed'
39
+ ? 'Index failed'
40
+ : `Updated ${ageLabel(generatedAt - index.indexedAt)}`;
41
+
42
+ return (
43
+ <div className="flex flex-wrap items-center justify-center gap-x-2 gap-y-1 pt-2 text-center text-[10px] text-ink/40">
44
+ <span>
45
+ {status} · {index.transcripts.toLocaleString('en-US')} transcripts ·{' '}
46
+ {index.records.toLocaleString('en-US')} records · {providers}{' '}
47
+ {providers === 1 ? 'provider' : 'providers'}
48
+ </span>
49
+ <span aria-hidden="true">·</span>
50
+ <span>index scan {index.scanMs.toLocaleString('en-US')} ms</span>
51
+ {index.state === 'failed' && index.error && (
52
+ <>
53
+ <span aria-hidden="true">·</span>
54
+ <span className="text-[var(--theme-error)]">{index.error}</span>
55
+ </>
56
+ )}
57
+ </div>
58
+ );
59
+ }
@@ -0,0 +1,239 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The Token Usage panel's period control and its breakdown table.
8
+ *
9
+ * The panel has ONE period control, because Day / Week / Month / 90 days / All
10
+ * time / Custom are all the same kind of choice: which trailing span to report.
11
+ * Two things are pinned here, because both were reported as bugs:
12
+ *
13
+ * - choosing a period must be a single click in one list (there is no second
14
+ * daily/weekly/monthly switch beside it);
15
+ * - no figure may be a per-day/per-week average — a period is one span, so
16
+ * every number is that span's total, and a derived "per day" number is what
17
+ * made the selector look like it only repainted the chart.
18
+ */
19
+
20
+ import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
21
+ import { Window } from 'happy-dom';
22
+ import { h, render } from 'preact';
23
+ import { act } from 'preact/test-utils';
24
+ import { TokenUsageControls } from '@/client/components/settings/categories/token-usage-settings/Controls';
25
+ import { TokenUsageBreakdown } from '@/client/components/settings/categories/token-usage-settings/Breakdown';
26
+ import { dayRows, providerModelRows } from '@/shared/lib/usage/breakdown';
27
+ import { timeRangeOptions } from '@/shared/lib/usage/range';
28
+ import type { UsageProviderRow, UsageTotals } from '@/shared/types';
29
+ import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
30
+
31
+ let container: HTMLElement;
32
+ let picked: string[];
33
+ let from: string[];
34
+ let to: string[];
35
+
36
+ const NOW = new Date(2026, 10, 3, 12).getTime();
37
+
38
+ function controls(): void {
39
+ render(
40
+ h(TokenUsageControls, {
41
+ range: '30d',
42
+ onRange: (value: string) => picked.push(value),
43
+ ranges: timeRangeOptions(NOW),
44
+ customFrom: '2026-10-05',
45
+ customTo: '2026-11-03',
46
+ onCustomFrom: (value: string) => from.push(value),
47
+ onCustomTo: (value: string) => to.push(value),
48
+ periodLabel: 'Oct 5 – Nov 3, 2026',
49
+ generatedAt: NOW,
50
+ refreshing: false,
51
+ onRefresh: () => {},
52
+ }),
53
+ container,
54
+ );
55
+ }
56
+
57
+ const buttons = (): HTMLButtonElement[] => [...container.querySelectorAll('button')];
58
+
59
+ beforeEach(() => {
60
+ installDomGlobals(new Window({ url: 'http://127.0.0.1/' }));
61
+ container = document.createElement('div');
62
+ document.body.append(container);
63
+ picked = [];
64
+ from = [];
65
+ to = [];
66
+ });
67
+
68
+ afterEach(() => {
69
+ render(null, container);
70
+ container.remove();
71
+ restoreDomGlobals();
72
+ });
73
+
74
+ describe('TokenUsageControls', () => {
75
+ test('the trigger names the ACTIVE period, not a generic "Custom…"', () => {
76
+ controls();
77
+ const trigger = buttons()[0];
78
+ expect(trigger.getAttribute('aria-expanded')).toBe('false');
79
+ expect(trigger.textContent).toContain('Month');
80
+ });
81
+
82
+ test('one list holds every span, so there is no second cadence switch', () => {
83
+ controls();
84
+ act(() => buttons()[0].click());
85
+ const labels = buttons().map((button) => button.textContent?.trim() ?? '');
86
+ // Day/Week/Month ARE periods here; a "Daily / Weekly / Monthly" group would
87
+ // be the duplicate control this replaced.
88
+ expect(labels.some((label) => label.startsWith('Day'))).toBe(true);
89
+ expect(labels.some((label) => label.startsWith('Week'))).toBe(true);
90
+ expect(labels.some((label) => label.startsWith('Month'))).toBe(true);
91
+ expect(labels.some((label) => label.startsWith('90 days'))).toBe(true);
92
+ expect(labels.some((label) => label.startsWith('All time'))).toBe(true);
93
+ expect(labels.some((label) => label.startsWith('Custom…'))).toBe(true);
94
+ expect(container.textContent).not.toContain('Daily');
95
+ });
96
+
97
+ test('choosing a span reports that range and closes the list', () => {
98
+ controls();
99
+ act(() => buttons()[0].click());
100
+ const week = buttons().find((button) => button.textContent?.trim().startsWith('Week'));
101
+ act(() => week?.click());
102
+ expect(picked).toEqual(['7d']);
103
+ expect(container.textContent).not.toContain('Custom…');
104
+ });
105
+
106
+ test('the period menu is anchored to the left edge on phones', () => {
107
+ controls();
108
+ act(() => buttons()[0].click());
109
+ const menu = [...container.querySelectorAll('div.absolute')].find((el) =>
110
+ (el.textContent ?? '').includes('Custom…'),
111
+ );
112
+ // `right-0` on a full-width trigger hung the menu off the LEFT of the
113
+ // viewport (measured at x=-157); it anchors left and only right-aligns from
114
+ // `sm` up.
115
+ expect(menu?.className).toContain('left-0');
116
+ expect(menu?.className).toContain('sm:right-0');
117
+ expect(menu?.className).toContain('max-w-[calc(100vw-2rem)]');
118
+ });
119
+
120
+ test('a custom span exposes both date inputs, capped at the payload day', () => {
121
+ render(
122
+ h(TokenUsageControls, {
123
+ range: 'custom',
124
+ onRange: (value: string) => picked.push(value),
125
+ ranges: timeRangeOptions(NOW),
126
+ customFrom: '2026-10-05',
127
+ customTo: '2026-11-03',
128
+ onCustomFrom: (value: string) => from.push(value),
129
+ onCustomTo: (value: string) => to.push(value),
130
+ periodLabel: 'Oct 5 – Nov 3, 2026',
131
+ generatedAt: NOW,
132
+ refreshing: false,
133
+ onRefresh: () => {},
134
+ }),
135
+ container,
136
+ );
137
+ // The button itself names the window, so an equal-to-preset range is still
138
+ // visibly a different state.
139
+ expect(buttons()[0].textContent).toContain('2026-10-05 – 2026-11-03');
140
+ act(() => buttons()[0].click());
141
+ const inputs = [...container.querySelectorAll('input[type=date]')] as HTMLInputElement[];
142
+ expect(inputs.map((input) => input.value)).toEqual(['2026-10-05', '2026-11-03']);
143
+ expect(inputs[1].max).toBe('2026-11-03');
144
+ });
145
+ });
146
+
147
+ describe('TokenUsageBreakdown', () => {
148
+ const totals: UsageTotals = {
149
+ cost: 20, tokens: 1_000_000, input: 50_000, output: 50_000, cacheRead: 900_000,
150
+ cacheWrite: 0, reasoning: 0, cacheReadCost: 1, records: 40, unpriced: 0, activeDays: 6,
151
+ };
152
+ const providers: UsageProviderRow[] = [
153
+ {
154
+ id: 'kenari-jatis', name: 'Kenari Jatis', cost: 18, tokens: 900, input: 0, output: 0,
155
+ cacheRead: 0, cacheWrite: 0, reasoning: 0, cacheReadCost: 0, records: 1, unpriced: 0,
156
+ models: [{
157
+ model: 'deepseek-v4-1-flash', cost: 18, tokens: 900, input: 0, output: 0,
158
+ cacheRead: 0, cacheWrite: 0, reasoning: 0, cacheReadCost: 0, records: 1, unpriced: 0,
159
+ }],
160
+ },
161
+ ];
162
+
163
+ function table(granularity: 'day' | 'week' | 'month'): void {
164
+ render(
165
+ h(TokenUsageBreakdown, {
166
+ tab: 'model',
167
+ onTab: () => {},
168
+ rows: providerModelRows(providers, totals.cost),
169
+ totals,
170
+ granularity,
171
+ providerNames: { 'kenari-jatis': 'Kenari Jatis' },
172
+ }),
173
+ container,
174
+ );
175
+ }
176
+
177
+ test('every cell is the period total — no per-day or per-week figure', () => {
178
+ table('day');
179
+ const text = container.textContent ?? '';
180
+ expect(text).toContain('$18.00');
181
+ expect(text).toContain('900');
182
+ // The averages that made the selector look inert are gone.
183
+ expect(text).not.toMatch(/\/day|\/wk|\/mo|per day|per week|per month/);
184
+ expect(text).toContain('period total');
185
+ });
186
+
187
+ test('the time tab is named for the bucket width the period implies', () => {
188
+ table('week');
189
+ const labels = [...container.querySelectorAll('[role="tab"]')].map((tab) => tab.textContent?.trim());
190
+ expect(labels).toContain('WEEK');
191
+ expect(labels).not.toContain('DAY');
192
+ });
193
+
194
+ test('a time tab renders every row of the period, never a truncated eight', () => {
195
+ // Eleven days of period, two of which saw usage: the table must list all
196
+ // eleven, because it describes the PERIOD, not the days that had work.
197
+ const days = Array.from({ length: 11 }, (_, index) => ({
198
+ day: `2026-11-${String(index + 1).padStart(2, '0')}`,
199
+ providers: {},
200
+ cost: index === 3 ? 4 : 0,
201
+ tokens: index === 3 ? 40 : 0,
202
+ input: 0, output: 0, cacheRead: 0, cacheWrite: 0, reasoning: 0,
203
+ cacheReadCost: 0, records: index === 3 ? 2 : 0, unpriced: 0,
204
+ }));
205
+ render(
206
+ h(TokenUsageBreakdown, {
207
+ tab: 'day',
208
+ onTab: () => {},
209
+ rows: dayRows(days, 'day', 4, { from: '2026-11-01', to: '2026-11-11' }),
210
+ totals,
211
+ granularity: 'day',
212
+ providerNames: {},
213
+ }),
214
+ container,
215
+ );
216
+ const bodyRows = container.querySelectorAll('tbody tr');
217
+ expect(bodyRows).toHaveLength(11);
218
+ // The period is fully listed, so there is no "show all" left to click.
219
+ expect(container.textContent).not.toContain('Show all');
220
+ expect(container.textContent).toContain('11 rows · day');
221
+ });
222
+
223
+ test('the tab row can wrap, so the last tab is never pushed out of the card', () => {
224
+ table('month');
225
+ const header = container.querySelector('[role="tablist"][aria-label="Breakdown"]')?.parentElement;
226
+ expect(header?.className).toContain('flex-wrap');
227
+ // The four tabs must stay inside the card at phone widths; measured in the
228
+ // browser, a non-wrapping row put PROJECT 14–84 px outside it.
229
+ const tabs = [...container.querySelectorAll('[aria-label="Breakdown"] [role="tab"]')];
230
+ expect(tabs.map((tab) => tab.textContent?.trim())).toEqual(['PROVIDER', 'MODEL', 'MONTH', 'PROJECT']);
231
+ });
232
+
233
+ test('the provider tree keeps both providers of one model id separate', () => {
234
+ table('day');
235
+ const text = container.textContent ?? '';
236
+ expect(text).toContain('Kenari Jatis');
237
+ expect(text.match(/deepseek-v4-1-flash/g)).toHaveLength(1);
238
+ });
239
+ });
@@ -74,6 +74,7 @@ async function mount(frame: { data: string; mimeType: string } | null): Promise<
74
74
  frame,
75
75
  actions: [],
76
76
  onSelectTarget: () => {},
77
+ onCloseTarget: () => {},
77
78
  zoomLevel: 100,
78
79
  }),
79
80
  host,
@@ -1,6 +1,7 @@
1
1
  import { useEffect, useRef, useState } from 'preact/hooks';
2
2
  import { Globe, Loader2, Radio } from 'lucide-preact';
3
3
  import { ActivityToasts } from '@/client/components/workspace/browser-panel/ActivityToasts';
4
+ import { BrowserTabStrip } from '@/client/components/workspace/browser-panel/TabStrip';
4
5
  import { drawFrame } from '@/client/lib/browser/frame-canvas';
5
6
  import type { BrowserPanelAction, BrowserTabInfo, BrowserViewStatus } from '@/shared/types';
6
7
 
@@ -13,6 +14,10 @@ interface BrowserScreencastProps {
13
14
  frame?: { data: string; mimeType: string } | null;
14
15
  actions: BrowserPanelAction[];
15
16
  onSelectTarget: (targetId: string) => void;
17
+ /** Close one of the session's tabs; only the strip offers it. */
18
+ onCloseTarget: (targetId: string) => void;
19
+ /** Tab whose close request is in flight. */
20
+ closingTarget?: string | null;
16
21
  zoomLevel: number;
17
22
  }
18
23
 
@@ -39,6 +44,8 @@ export function BrowserScreencast({
39
44
  frame,
40
45
  actions,
41
46
  onSelectTarget,
47
+ onCloseTarget,
48
+ closingTarget,
42
49
  zoomLevel,
43
50
  }: BrowserScreencastProps) {
44
51
  const isLive = status === 'live';
@@ -69,28 +76,16 @@ export function BrowserScreencast({
69
76
  return (
70
77
  <div className="flex-1 flex flex-col min-h-0 bg-canvas/60 relative overflow-hidden">
71
78
  <ActivityToasts actions={actions} />
72
- {/* Tab strip: only useful when the session owns more than one page. */}
73
- {isLive && tabs.length > 1 && (
74
- <div className="px-2 py-1 border-b border-ink/10 bg-paper flex items-center gap-1 overflow-x-auto flex-shrink-0">
75
- {tabs.map((tab) => {
76
- const active = tab.targetId === targetId;
77
- return (
78
- <button
79
- key={tab.targetId}
80
- type="button"
81
- onClick={() => onSelectTarget(active ? '' : tab.targetId)}
82
- className={`px-2 py-0.5 rounded text-[11px] font-mono max-w-[220px] truncate border transition-colors cursor-pointer ${
83
- active
84
- ? 'bg-ink text-canvas border-ink'
85
- : 'bg-paper text-ink/70 border-ink/15 hover:border-ink/35 hover:text-ink'
86
- }`}
87
- title={tab.url || tab.title || tab.targetId}
88
- >
89
- {tab.title || tab.url || tab.targetId}
90
- </button>
91
- );
92
- })}
93
- </div>
79
+ {/* Tab strip: the selector needs two tabs, but the CLOSE control is the
80
+ point of the strip — a single leftover page must be closable too. */}
81
+ {isLive && tabs.length > 0 && (
82
+ <BrowserTabStrip
83
+ tabs={tabs}
84
+ targetId={targetId}
85
+ closing={closingTarget}
86
+ onSelectTarget={onSelectTarget}
87
+ onCloseTarget={onCloseTarget}
88
+ />
94
89
  )}
95
90
 
96
91
  <div className="flex-1 flex items-center justify-center p-2 min-h-0 overflow-auto">