@kabmo-labs/kabmo 0.16.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 (381) hide show
  1. package/README.md +2 -2
  2. package/dist/client/index.html +1 -1
  3. package/dist/client/index.js +552 -471
  4. package/dist/client/static/js/index-hp75vsv9.css +1 -0
  5. package/dist/client/static/js/{index-cpydmygd.js → index-tc09dtca.js} +897 -886
  6. package/package.json +1 -1
  7. package/src/client/components/common/MarkdownRenderer.tsx +136 -89
  8. package/src/client/components/common/anchored-menu/index.test.tsx +141 -0
  9. package/src/client/components/common/anchored-menu/index.tsx +143 -0
  10. package/src/client/components/common/code-surface/bracket-guide.test.ts +2 -2
  11. package/src/client/components/common/code-surface/bracket-guide.ts +2 -2
  12. package/src/client/components/common/code-surface/conflict-markers.ts +5 -5
  13. package/src/client/components/common/code-surface/extensions.ts +7 -4
  14. package/src/client/components/common/code-surface/theme.ts +34 -9
  15. package/src/client/components/common/code-surface/whitespace.test.ts +223 -0
  16. package/src/client/components/common/code-surface/whitespace.ts +140 -0
  17. package/src/client/components/common/markdown-review/ReviewPopover.tsx +144 -0
  18. package/src/client/components/common/markdown-review/ReviewSummary.tsx +108 -0
  19. package/src/client/components/common/markdown-review/index.tsx +129 -0
  20. package/src/client/components/common/{server-switcher/index.tsx → server-control/Panel.tsx} +92 -44
  21. package/src/client/components/common/server-control/index.test.tsx +217 -0
  22. package/src/client/components/common/server-control/index.tsx +120 -0
  23. package/src/client/components/layout/desktop-layout/TopNavbar.tsx +8 -50
  24. package/src/client/components/layout/session-sidebar/CategoryHeader.tsx +42 -21
  25. package/src/client/components/layout/session-sidebar/CategoryHeader.worktree.test.tsx +36 -17
  26. package/src/client/components/layout/session-sidebar/CategoryItem.tsx +8 -7
  27. package/src/client/components/layout/session-sidebar/about-modal/NotesDialog.tsx +94 -0
  28. package/src/client/components/layout/session-sidebar/about-modal/VersionLine.test.tsx +68 -0
  29. package/src/client/components/layout/session-sidebar/about-modal/VersionLine.tsx +36 -0
  30. package/src/client/components/layout/session-sidebar/about-modal/index.tsx +57 -34
  31. package/src/client/components/layout/session-sidebar/modern/WorkspaceHeader.tsx +28 -10
  32. package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +7 -6
  33. package/src/client/components/layout/session-sidebar/modern/workspace-header.test.tsx +1 -1
  34. package/src/client/components/layout/update-popup/ReleaseNotes.tsx +8 -3
  35. package/src/client/components/layout/update-popup/index.tsx +5 -1
  36. package/src/client/components/mobile/mobile-main-view/Header.tsx +6 -12
  37. package/src/client/components/mobile/mobile-right-sidebar/FullEditor.tsx +13 -15
  38. package/src/client/components/mobile/mobile-right-sidebar/Header.tsx +23 -1
  39. package/src/client/components/mobile/mobile-right-sidebar/MissingFileBanner.tsx +30 -0
  40. package/src/client/components/mobile/mobile-right-sidebar/PreviewScroller.tsx +18 -2
  41. package/src/client/components/mobile/mobile-session-sidebar/Header.tsx +41 -13
  42. package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +22 -67
  43. package/src/client/components/mobile/mobile-session-sidebar/ItemMenu.tsx +110 -0
  44. package/src/client/components/settings/Modal.tsx +9 -3
  45. package/src/client/components/settings/ProjectSelectorDropdown.tsx +19 -9
  46. package/src/client/components/settings/SettingsSidebarList.tsx +20 -0
  47. package/src/client/components/settings/categories/AgentSettings.tsx +38 -44
  48. package/src/client/components/settings/categories/CommandSettings.tsx +2 -2
  49. package/src/client/components/settings/categories/McpSettings.tsx +4 -21
  50. package/src/client/components/settings/categories/OmpSettings.tsx +147 -194
  51. package/src/client/components/settings/categories/ProjectSettings.tsx +122 -156
  52. package/src/client/components/settings/categories/SkillCatalogSettings.tsx +220 -260
  53. package/src/client/components/settings/categories/SkillSettings.tsx +8 -5
  54. package/src/client/components/settings/categories/TokenUsageSettings.tsx +211 -229
  55. package/src/client/components/settings/categories/agent-settings/DetailPane.tsx +229 -237
  56. package/src/client/components/settings/categories/agent-settings/ModelPicker.tsx +71 -0
  57. package/src/client/components/settings/categories/agent-settings/SidebarList.tsx +14 -2
  58. package/src/client/components/settings/categories/agent-settings/levels.ts +38 -0
  59. package/src/client/components/settings/categories/behavior-settings/Editor.tsx +27 -7
  60. package/src/client/components/settings/categories/chat-settings/ToolRenderSection.tsx +23 -5
  61. package/src/client/components/settings/categories/command-settings/DetailPane.tsx +75 -33
  62. package/src/client/components/settings/categories/command-settings/SidebarList.tsx +7 -0
  63. package/src/client/components/settings/categories/mcp-settings/DetailPane.tsx +91 -76
  64. package/src/client/components/settings/categories/mcp-settings/EnvVarsSection.tsx +83 -0
  65. package/src/client/components/settings/categories/mcp-settings/ImportModal.tsx +26 -13
  66. package/src/client/components/settings/categories/mcp-settings/SidebarList.tsx +20 -0
  67. package/src/client/components/settings/categories/omp-settings/ConfigTabs.tsx +97 -36
  68. package/src/client/components/settings/categories/omp-settings/EngineHeader.tsx +151 -0
  69. package/src/client/components/settings/categories/omp-settings/ExtensionsPanel.tsx +68 -32
  70. package/src/client/components/settings/categories/omp-settings/OrderedChips.tsx +119 -0
  71. package/src/client/components/settings/categories/omp-settings/PresetBar.tsx +14 -7
  72. package/src/client/components/settings/categories/omp-settings/RoleEditor.tsx +15 -6
  73. package/src/client/components/settings/categories/omp-settings/RowEditor.tsx +165 -226
  74. package/src/client/components/settings/categories/omp-settings/types.ts +28 -0
  75. package/src/client/components/settings/categories/project-settings/AccentPalette.test.tsx +189 -0
  76. package/src/client/components/settings/categories/project-settings/AccentPalette.tsx +156 -24
  77. package/src/client/components/settings/categories/project-settings/AddProjectModal.tsx +175 -0
  78. package/src/client/components/settings/categories/project-settings/DeleteProjectModal.tsx +107 -0
  79. package/src/client/components/settings/categories/project-settings/DetailsForm.tsx +40 -24
  80. package/src/client/components/settings/categories/project-settings/DetailsHeader.tsx +17 -7
  81. package/src/client/components/settings/categories/project-settings/IconGrid.tsx +164 -69
  82. package/src/client/components/settings/categories/project-settings/ModelDropdown.test.tsx +122 -0
  83. package/src/client/components/settings/categories/project-settings/ModelDropdown.tsx +124 -53
  84. package/src/client/components/settings/categories/project-settings/NameInput.tsx +57 -11
  85. package/src/client/components/settings/categories/project-settings/PathField.tsx +122 -0
  86. package/src/client/components/settings/categories/project-settings/SidebarList.tsx +100 -59
  87. package/src/client/components/settings/categories/skill-catalog/GitImportPanel.tsx +253 -0
  88. package/src/client/components/settings/categories/skill-catalog/SkillCard.tsx +89 -0
  89. package/src/client/components/settings/categories/skill-catalog/SourceRail.tsx +122 -0
  90. package/src/client/components/settings/categories/skill-catalog/catalog-ui.test.tsx +179 -0
  91. package/src/client/components/settings/categories/skill-settings/DetailHeader.tsx +236 -0
  92. package/src/client/components/settings/categories/skill-settings/DetailPane.tsx +164 -239
  93. package/src/client/components/settings/categories/skill-settings/InstructionsEditor.tsx +84 -0
  94. package/src/client/components/settings/categories/skill-settings/SidebarList.tsx +144 -87
  95. package/src/client/components/settings/categories/skill-settings/pane.test.tsx +188 -0
  96. package/src/client/components/settings/categories/skill-settings/row-meta.ts +58 -0
  97. package/src/client/components/settings/categories/token-usage-settings/Breakdown.tsx +242 -102
  98. package/src/client/components/settings/categories/token-usage-settings/Chart.tsx +130 -56
  99. package/src/client/components/settings/categories/token-usage-settings/Controls.tsx +135 -0
  100. package/src/client/components/settings/categories/token-usage-settings/MetricsGrid.tsx +55 -33
  101. package/src/client/components/settings/categories/token-usage-settings/Provenance.tsx +59 -0
  102. package/src/client/components/settings/categories/token-usage-settings/panel.test.tsx +239 -0
  103. package/src/client/components/workspace/browser-panel/Screencast.test.ts +1 -0
  104. package/src/client/components/workspace/browser-panel/Screencast.tsx +17 -22
  105. package/src/client/components/workspace/browser-panel/TabStrip.test.tsx +158 -0
  106. package/src/client/components/workspace/browser-panel/TabStrip.tsx +90 -0
  107. package/src/client/components/workspace/browser-panel/index.tsx +50 -4
  108. package/src/client/components/workspace/browser-toolbar/index.tsx +41 -1
  109. package/src/client/components/workspace/chat-timeline/ThinkingSection.tsx +3 -1
  110. package/src/client/components/workspace/chat-timeline/ToolCallingSection.tsx +2 -0
  111. package/src/client/components/workspace/chat-timeline/block-chrome.test.tsx +13 -2
  112. package/src/client/components/workspace/chat-timeline/index.tsx +6 -1
  113. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Bash.test.ts +88 -0
  114. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Bash.tsx +24 -1
  115. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Proc.test.ts +46 -0
  116. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Proc.tsx +15 -6
  117. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Read.test.ts +34 -0
  118. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Read.tsx +5 -1
  119. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.test.ts +29 -0
  120. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.tsx +11 -3
  121. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/ArtifactChip.tsx +7 -6
  122. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/card-header.test.ts +24 -1
  123. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/card-header.ts +6 -2
  124. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Tui.test.tsx +237 -0
  125. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Tui.tsx +191 -0
  126. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/styles.test.tsx +1 -1
  127. package/src/client/components/workspace/diff-panel/MergeDiffView.tsx +21 -7
  128. package/src/client/components/workspace/diff-panel/changes.test.ts +51 -0
  129. package/src/client/components/workspace/diff-panel/changes.ts +28 -12
  130. package/src/client/components/workspace/diff-panel/merge.test.ts +28 -0
  131. package/src/client/components/workspace/diff-panel/merge.ts +21 -1
  132. package/src/client/components/workspace/editor/Body.tsx +7 -0
  133. package/src/client/components/workspace/editor/FileDocument.tsx +15 -21
  134. package/src/client/components/workspace/editor/FilePane.tsx +12 -0
  135. package/src/client/components/workspace/editor/PreviewPane.tsx +70 -0
  136. package/src/client/components/workspace/editor/Toolbar.tsx +17 -1
  137. package/src/client/components/workspace/editor/index.tsx +25 -22
  138. package/src/client/components/workspace/editor/toolbar-clusters.test.ts +14 -0
  139. package/src/client/components/workspace/editor/toolbar-clusters.tsx +12 -86
  140. package/src/client/components/workspace/editor/toolbar-toggle.tsx +53 -0
  141. package/src/client/components/workspace/editor/toolbar-write-clusters.tsx +112 -0
  142. package/src/client/components/workspace/editor/viewers/SvgPreview.tsx +18 -2
  143. package/src/client/components/workspace/editor/viewers/viewers.test.ts +39 -0
  144. package/src/client/components/workspace/file-explorer/ContextMenu.tsx +18 -5
  145. package/src/client/components/workspace/file-explorer/Modals.tsx +15 -1
  146. package/src/client/components/workspace/file-explorer/RowLabel.tsx +68 -0
  147. package/src/client/components/workspace/file-explorer/TreeItem.tsx +47 -57
  148. package/src/client/components/workspace/file-explorer/collapsed-chain.test.ts +167 -0
  149. package/src/client/components/workspace/file-explorer/drag-props.ts +42 -0
  150. package/src/client/components/workspace/file-explorer/drag.test.ts +43 -0
  151. package/src/client/components/workspace/file-explorer/index.tsx +21 -20
  152. package/src/client/components/workspace/git-panel/commit-modal.test.ts +5 -3
  153. package/src/client/components/workspace/user-browser-panel/AddressBar.tsx +5 -0
  154. package/src/client/components/workspace/user-browser-panel/AnnotateBar.test.tsx +201 -0
  155. package/src/client/components/workspace/user-browser-panel/AnnotateBar.tsx +112 -0
  156. package/src/client/components/workspace/user-browser-panel/AnnotateLayer.test.tsx +225 -0
  157. package/src/client/components/workspace/user-browser-panel/AnnotateLayer.tsx +217 -0
  158. package/src/client/components/workspace/user-browser-panel/AnnotateTarget.tsx +99 -0
  159. package/src/client/components/workspace/user-browser-panel/Frame.tsx +30 -1
  160. package/src/client/components/workspace/user-browser-panel/index.tsx +81 -2
  161. package/src/client/data/agent-data/builtin.ts +0 -10
  162. package/src/client/data/agent-data/orchestrator.ts +0 -45
  163. package/src/client/data/agent-data/specialist.ts +0 -100
  164. package/src/client/data/mock/token-usage.ts +170 -120
  165. package/src/client/data/settings/omp-schema.json +123 -4
  166. package/src/client/data/settings/project.ts +9 -28
  167. package/src/client/data/settings/skill.ts +6 -32
  168. package/src/client/hooks/browser/use-annotate.test.ts +143 -0
  169. package/src/client/hooks/browser/use-annotate.ts +98 -0
  170. package/src/client/hooks/browser/use-close-tab.test.ts +148 -0
  171. package/src/client/hooks/browser/use-close-tab.ts +67 -0
  172. package/src/client/hooks/browser/use-screencast.ts +13 -1
  173. package/src/client/hooks/chat/composer/browser-context.test.ts +117 -0
  174. package/src/client/hooks/chat/composer/browser-context.ts +40 -16
  175. package/src/client/hooks/chat/composer/items.test.ts +1 -1
  176. package/src/client/hooks/chat/composer/review-context.ts +38 -0
  177. package/src/client/hooks/chat/composer/use-draft.test.ts +132 -0
  178. package/src/client/hooks/chat/composer/use-draft.ts +31 -2
  179. package/src/client/hooks/chat/timeline/pending-model.ts +28 -0
  180. package/src/client/hooks/chat/timeline/row-window.test.ts +15 -2
  181. package/src/client/hooks/editor/use-document-annotations.ts +124 -0
  182. package/src/client/hooks/editor/use-editor-panel-ui.ts +52 -0
  183. package/src/client/hooks/editor/use-file-review-mode.ts +35 -0
  184. package/src/client/hooks/editor/use-preview-review.ts +148 -0
  185. package/src/client/hooks/settings/agents.ts +149 -0
  186. package/src/client/hooks/settings/crud-list.test.ts +28 -6
  187. package/src/client/hooks/settings/crud-list.ts +96 -57
  188. package/src/client/hooks/settings/omp-config.ts +164 -0
  189. package/src/client/hooks/settings/projects/index.ts +294 -0
  190. package/src/client/hooks/settings/projects.test.ts +237 -0
  191. package/src/client/hooks/settings/skill-catalog.ts +101 -9
  192. package/src/client/hooks/settings/skill-git-import.ts +153 -0
  193. package/src/client/hooks/settings/useTokenUsage.ts +125 -0
  194. package/src/client/hooks/settings/write-feedback.test.ts +104 -0
  195. package/src/client/hooks/settings/write-feedback.ts +63 -0
  196. package/src/client/hooks/shell/servers.test.ts +166 -0
  197. package/src/client/hooks/{desktop → shell}/servers.ts +17 -14
  198. package/src/client/hooks/ui/markdown-hydration.ts +125 -0
  199. package/src/client/hooks/ui/updates/index.test.ts +100 -1
  200. package/src/client/hooks/ui/updates/index.ts +50 -0
  201. package/src/client/hooks/ui/updates/notes.test.ts +138 -0
  202. package/src/client/hooks/ui/updates/notes.ts +57 -0
  203. package/src/client/hooks/ui/updates/shell-download.ts +1 -1
  204. package/src/client/hooks/ui/updates/shell-update.ts +2 -6
  205. package/src/client/hooks/workspace/file-row-drag.ts +41 -0
  206. package/src/client/hooks/workspace/file-tree-actions.ts +25 -1
  207. package/src/client/hooks/workspace/file-tree-edits.ts +23 -6
  208. package/src/client/hooks/workspace/root-drop-target.ts +77 -0
  209. package/src/client/hooks/workspace/unfolded-chains.ts +165 -0
  210. package/src/client/lib/browser/element-at.test.ts +229 -0
  211. package/src/client/lib/browser/element-at.ts +139 -0
  212. package/src/client/lib/desktop/dropped-paths.ts +1 -1
  213. package/src/client/lib/desktop/titlebar.test.ts +12 -3
  214. package/src/client/lib/desktop/titlebar.ts +1 -1
  215. package/src/client/lib/review/client.ts +73 -0
  216. package/src/client/lib/router/search-params.ts +42 -20
  217. package/src/client/lib/shell/desktop.ts +117 -0
  218. package/src/client/lib/shell/servers.ts +75 -0
  219. package/src/client/lib/shell/transport.ts +216 -0
  220. package/src/client/main.tsx +9 -0
  221. package/src/client/tailwind.css +65 -0
  222. package/src/server/lib/btw/lifecycle.server.ts +2 -2
  223. package/src/server/lib/db/schema.ts +7 -0
  224. package/src/server/lib/db/seed-terminal.test.ts +4 -0
  225. package/src/server/lib/fs/git-merge-conflict.test.ts +14 -1
  226. package/src/server/lib/omp/config/agent-definitions.test.ts +273 -0
  227. package/src/server/lib/omp/config/agents.ts +231 -61
  228. package/src/server/lib/omp/config/definitions.test.ts +9 -105
  229. package/src/server/lib/omp/config/extensions.ts +16 -7
  230. package/src/server/lib/omp/config/omp-config-files.test.ts +27 -0
  231. package/src/server/lib/omp/config/skill-sources.ts +49 -0
  232. package/src/server/lib/omp/config/skills-git-install.ts +155 -0
  233. package/src/server/lib/omp/config/skills-git-repo.ts +288 -0
  234. package/src/server/lib/omp/config/skills-git.test.ts +220 -0
  235. package/src/server/lib/omp/rpc/constants.test.ts +11 -0
  236. package/src/server/lib/omp/rpc/constants.ts +15 -0
  237. package/src/server/lib/omp/rpc/process.ts +11 -14
  238. package/src/server/lib/omp/rpc/session-commands.ts +6 -3
  239. package/src/server/lib/omp/rpc/utility-agent-dir.test.ts +134 -0
  240. package/src/server/lib/omp/rpc/utility-agent-dir.ts +138 -0
  241. package/src/server/lib/omp/rpc/utility.ts +12 -0
  242. package/src/server/lib/review/schema.server.ts +45 -0
  243. package/src/server/lib/review/store.server.ts +138 -0
  244. package/src/server/lib/terminal/attach-replay.test.ts +132 -0
  245. package/src/server/lib/terminal/output.test.ts +166 -0
  246. package/src/server/lib/terminal/output.ts +104 -0
  247. package/src/server/lib/terminal/runtime.server.ts +5 -0
  248. package/src/server/lib/terminal/send-result.test.ts +33 -0
  249. package/src/server/lib/terminal/send-result.ts +32 -0
  250. package/src/server/lib/terminal/session.server.ts +45 -11
  251. package/src/server/lib/terminal/store-liveness.test.ts +4 -0
  252. package/src/server/lib/updates/active-notes.test.ts +149 -0
  253. package/src/server/lib/updates/active-notes.ts +75 -0
  254. package/src/server/lib/updates/changelog-file.ts +42 -11
  255. package/src/server/lib/updates/changelog.test.ts +15 -1
  256. package/src/server/lib/updates/omp.ts +42 -15
  257. package/src/server/lib/updates/release-url.ts +27 -1
  258. package/src/server/lib/usage/index-parse.test.ts +200 -0
  259. package/src/server/lib/usage/index-parse.ts +178 -0
  260. package/src/server/lib/usage/index-query.server.ts +248 -0
  261. package/src/server/lib/usage/index-scan.server.ts +343 -0
  262. package/src/server/lib/usage/index-schema.server.ts +82 -0
  263. package/src/server/lib/usage/index.test.ts +234 -0
  264. package/src/server/lib/usage/providers.server.ts +4 -53
  265. package/src/server/lib/workspace/project-model.server.test.ts +102 -0
  266. package/src/server/lib/workspace/project-model.server.ts +47 -0
  267. package/src/server/lib/workspace/project-patch.server.ts +156 -0
  268. package/src/server/routes/agent/new.ts +8 -1
  269. package/src/server/routes/browser/index.ts +3 -0
  270. package/src/server/routes/browser/stream.ts +31 -2
  271. package/src/server/routes/browser/tabs.test.ts +94 -0
  272. package/src/server/routes/browser/tabs.ts +85 -0
  273. package/src/server/routes/index.ts +2 -0
  274. package/src/server/routes/review/bindings.ts +11 -0
  275. package/src/server/routes/review/index.ts +127 -0
  276. package/src/server/routes/review/routes.test.ts +191 -0
  277. package/src/server/routes/settings/agents.test.ts +180 -0
  278. package/src/server/routes/settings/agents.ts +99 -94
  279. package/src/server/routes/settings/mcp.test.ts +135 -0
  280. package/src/server/routes/settings/mcp.ts +14 -6
  281. package/src/server/routes/settings/projects.ts +53 -19
  282. package/src/server/routes/settings/settings-projects-routes.test.ts +214 -0
  283. package/src/server/routes/settings/settings-store-routes.test.ts +11 -115
  284. package/src/server/routes/settings/skills-catalog-actions.ts +195 -0
  285. package/src/server/routes/settings/skills.test.ts +225 -0
  286. package/src/server/routes/settings/skills.ts +18 -15
  287. package/src/server/routes/telemetry/tokens.test.ts +145 -0
  288. package/src/server/routes/telemetry/tokens.ts +70 -149
  289. package/src/server/routes/terminal/ws.ts +6 -5
  290. package/src/server/routes/updates/index.ts +2 -0
  291. package/src/server/routes/updates/notes.ts +34 -0
  292. package/src/server/routes/updates/routes.test.ts +49 -0
  293. package/src/shared/lib/browser/annotate.test.ts +283 -0
  294. package/src/shared/lib/browser/annotate.ts +231 -0
  295. package/src/shared/lib/browser/browser-viewer.test.ts +26 -4
  296. package/src/shared/lib/browser/frame-gate.test.ts +91 -0
  297. package/src/shared/lib/browser/frame-gate.ts +69 -0
  298. package/src/shared/lib/browser/frame-params.test.ts +43 -0
  299. package/src/shared/lib/browser/frame-params.ts +60 -0
  300. package/src/shared/lib/browser/frame-pipeline.test.ts +132 -0
  301. package/src/shared/lib/browser/frame-pipeline.ts +80 -0
  302. package/src/shared/lib/browser/page-context.ts +60 -4
  303. package/src/shared/lib/browser/snapshot.test.ts +115 -0
  304. package/src/shared/lib/browser/snapshot.ts +112 -0
  305. package/src/shared/lib/browser/tab-close.test.ts +74 -0
  306. package/src/shared/lib/browser/tab-close.ts +77 -0
  307. package/src/shared/lib/browser/viewer.ts +45 -26
  308. package/src/shared/lib/chat/timeline/block-chrome.ts +19 -0
  309. package/src/shared/lib/chat/timeline/tool-render-mode.ts +17 -4
  310. package/src/shared/lib/chat/tool/artifact.ts +55 -20
  311. package/src/shared/lib/chat/tool/bash-facts.ts +96 -0
  312. package/src/shared/lib/chat/tool/minimized.test.ts +98 -0
  313. package/src/shared/lib/chat/tool/minimized.ts +64 -0
  314. package/src/shared/lib/chat/tool/summary.test.ts +28 -8
  315. package/src/shared/lib/chat/tool/summary.ts +3 -32
  316. package/src/shared/lib/fs/folder-chain.test.ts +81 -1
  317. package/src/shared/lib/fs/folder-chain.ts +84 -0
  318. package/src/shared/lib/markdown/blocks/anchor.ts +63 -0
  319. package/src/shared/lib/markdown/blocks/blocks.test.ts +141 -0
  320. package/src/shared/lib/markdown/blocks/renderer.ts +120 -0
  321. package/src/shared/lib/markdown/blocks/scan.ts +100 -0
  322. package/src/shared/lib/markdown/blocks/types.ts +62 -0
  323. package/src/shared/lib/markdown/marked.ts +58 -147
  324. package/src/shared/lib/markdown/math-extensions.ts +168 -0
  325. package/src/shared/lib/markdown/review/prompt.ts +77 -0
  326. package/src/shared/lib/markdown/review/reconcile.ts +55 -0
  327. package/src/shared/lib/markdown/review/review.test.ts +96 -0
  328. package/src/shared/lib/markdown/xml-sections.test.ts +140 -0
  329. package/src/shared/lib/markdown/xml-sections.ts +139 -0
  330. package/src/shared/lib/models/provider/label.ts +57 -0
  331. package/src/shared/lib/omp/config/agent-file.test.ts +54 -0
  332. package/src/shared/lib/omp/config/agent-file.ts +43 -0
  333. package/src/shared/lib/omp/config/row-value.test.ts +95 -0
  334. package/src/shared/lib/omp/config/row-value.ts +97 -0
  335. package/src/shared/lib/omp/config/schema.test.ts +66 -0
  336. package/src/shared/lib/omp/config/schema.ts +6 -0
  337. package/src/shared/lib/omp/rpc/frame.test.ts +48 -47
  338. package/src/shared/lib/omp/rpc/frame.ts +49 -40
  339. package/src/shared/lib/omp/session/job-progress.test.ts +37 -1
  340. package/src/shared/lib/omp/session/job-progress.ts +31 -0
  341. package/src/shared/lib/omp/session/proc.ts +5 -0
  342. package/src/shared/lib/omp/session/wait.ts +5 -0
  343. package/src/shared/lib/ui/menu-anchor.test.ts +69 -0
  344. package/src/shared/lib/ui/menu-anchor.ts +89 -0
  345. package/src/shared/lib/ui/mobile-overlay.ts +61 -0
  346. package/src/shared/lib/ui/svg-scope.test.ts +97 -0
  347. package/src/shared/lib/ui/svg-scope.ts +134 -0
  348. package/src/shared/lib/usage/breakdown.test.ts +197 -0
  349. package/src/shared/lib/usage/breakdown.ts +241 -0
  350. package/src/shared/lib/usage/range.test.ts +204 -0
  351. package/src/shared/lib/usage/range.ts +240 -0
  352. package/src/shared/lib/usage/view.test.ts +85 -0
  353. package/src/shared/lib/usage/view.ts +74 -0
  354. package/src/shared/lib/workspace/project-accent.test.ts +69 -0
  355. package/src/shared/lib/workspace/project-accent.ts +63 -0
  356. package/src/shared/lib/workspace/project-icon.ts +40 -0
  357. package/src/shared/lib/workspace/project-model.test.ts +79 -0
  358. package/src/shared/lib/workspace/project-model.ts +64 -0
  359. package/src/shared/types/browser.ts +78 -0
  360. package/src/shared/types/index.ts +1 -0
  361. package/src/shared/types/settings/agent.ts +28 -6
  362. package/src/shared/types/settings/skill.ts +53 -3
  363. package/src/shared/types/settings/state.ts +4 -3
  364. package/src/shared/types/settings/write.ts +6 -0
  365. package/src/shared/types/tokenUsage.ts +128 -21
  366. package/src/shared/types/updates.ts +20 -0
  367. package/src/test-support/file-explorer-disk.test-util.ts +25 -1
  368. package/src/test-support/file-explorer-drag.test-util.ts +88 -0
  369. package/src/test-support/file-explorer.test-util.ts +47 -47
  370. package/dist/client/static/js/index-fjnq2z2d.css +0 -1
  371. package/src/client/components/common/code-surface/indent-guide.ts +0 -104
  372. package/src/client/components/common/server-switcher/index.test.tsx +0 -150
  373. package/src/client/components/settings/categories/skill-catalog/AddSourceModal.tsx +0 -133
  374. package/src/client/hooks/desktop/servers.test.ts +0 -73
  375. package/src/client/lib/desktop/bridge.ts +0 -203
  376. package/src/server/lib/omp/session/usage/aggregate-shaping.test.ts +0 -149
  377. package/src/server/lib/omp/session/usage/aggregate.test.ts +0 -243
  378. package/src/server/lib/omp/session/usage/aggregate.ts +0 -330
  379. package/src/server/lib/omp/session/usage/shaping.ts +0 -130
  380. package/src/shared/lib/code/editor/indent-guide-rule.test.ts +0 -65
  381. package/src/shared/lib/code/editor/indent-guide-rule.ts +0 -47
@@ -1,133 +0,0 @@
1
- import { useState } from 'preact/hooks';
2
- import type { FormEvent } from 'preact/compat';
3
- import { AlertCircle, GitBranch, Plus, X } from 'lucide-preact';
4
- import type { SkillCatalogSource } from '@/shared/types';
5
-
6
- interface AddSourceModalProps {
7
- isOpen: boolean;
8
- onClose: () => void;
9
- onAddSource: (source: SkillCatalogSource) => void;
10
- }
11
-
12
- export function AddSourceModal({ isOpen, onClose, onAddSource }: AddSourceModalProps) {
13
- const [repoUrl, setRepoUrl] = useState('');
14
- const [sourceName, setSourceName] = useState('');
15
- const [error, setError] = useState<string | null>(null);
16
-
17
- if (!isOpen) return null;
18
-
19
- const handleSubmit = (e: FormEvent) => {
20
- e.preventDefault();
21
- const cleanRepo = repoUrl.trim().replace(/^https?:\/\/github\.com\//, '').replace(/\/$/, '');
22
-
23
- if (!cleanRepo) {
24
- setError('Please provide a valid GitHub repository path (e.g. owner/repo).');
25
- return;
26
- }
27
-
28
- const name = sourceName.trim() || cleanRepo.split('/')[1] || cleanRepo;
29
-
30
- const newSource: SkillCatalogSource = {
31
- id: `custom-${Date.now()}`,
32
- name,
33
- repo: cleanRepo,
34
- stars: '1.2K',
35
- updatedAt: 'Just now',
36
- skillCount: 3,
37
- isCustom: true,
38
- };
39
-
40
- onAddSource(newSource);
41
- setRepoUrl('');
42
- setSourceName('');
43
- setError(null);
44
- onClose();
45
- };
46
-
47
- return (
48
- <div
49
- className="fixed inset-0 z-50 bg-ink/40 backdrop-blur-[2px] flex items-center justify-center p-4"
50
- onClick={onClose}
51
- >
52
- <div
53
- className="bg-paper border border-ink/20 rounded-xl max-w-md w-full p-6 shadow-2xl space-y-4 text-ink animate-in fade-in zoom-in-95 duration-150 max-h-full overflow-y-auto scrollbar-overlay-container"
54
- onClick={(e) => e.stopPropagation()}
55
- >
56
- <div className="flex items-center justify-between pb-3 border-b border-ink/10">
57
- <div className="flex items-center gap-2">
58
- <GitBranch className="w-4 h-4 text-ink/70" />
59
- <h2 className="text-xs font-bold uppercase tracking-wider text-ink">
60
- Add Custom Skill Source
61
- </h2>
62
- </div>
63
- <button
64
- type="button"
65
- onClick={onClose}
66
- className="p-1 rounded-md text-ink/50 hover:text-ink hover:bg-ink/5 transition-colors cursor-pointer"
67
- >
68
- <X className="w-4 h-4" />
69
- </button>
70
- </div>
71
-
72
- <p className="text-xs text-ink/70 leading-relaxed">
73
- Connect any public or private Git repository containing skill definitions and prompt directives.
74
- </p>
75
-
76
- <form onSubmit={handleSubmit} className="space-y-4">
77
- <div>
78
- <label className="block text-xs font-semibold text-ink/80 mb-1.5">
79
- Source Name
80
- </label>
81
- <input
82
- type="text"
83
- value={sourceName}
84
- onChange={(e) => setSourceName(e.currentTarget.value)}
85
- placeholder="e.g. Acme Internal Skills"
86
- className="w-full px-3 py-2 rounded-lg border border-ink/20 hover:border-ink/40 bg-paper focus:outline-none focus:border-ink text-xs text-ink transition-colors"
87
- />
88
- </div>
89
-
90
- <div>
91
- <label className="block text-xs font-semibold text-ink/80 mb-1.5">
92
- Git Repository <span className="text-error">*</span>
93
- </label>
94
- <input
95
- type="text"
96
- value={repoUrl}
97
- onChange={(e) => {
98
- setRepoUrl(e.currentTarget.value);
99
- setError(null);
100
- }}
101
- placeholder="e.g. owner/skills-repo or https://github.com/..."
102
- className="w-full px-3 py-2 rounded-lg border border-ink/20 hover:border-ink/40 bg-paper focus:outline-none focus:border-ink text-xs font-mono text-ink transition-colors"
103
- />
104
- </div>
105
-
106
- {error && (
107
- <div className="flex items-center gap-2 text-xs text-error p-2.5 rounded-lg bg-error/10 border border-error/20">
108
- <AlertCircle className="w-4 h-4 flex-shrink-0" />
109
- <span className="font-medium">{error}</span>
110
- </div>
111
- )}
112
-
113
- <div className="pt-3 border-t border-ink/10 flex items-center justify-end gap-2">
114
- <button
115
- type="button"
116
- onClick={onClose}
117
- className="px-3.5 py-2 rounded-lg border border-ink/20 hover:border-ink/40 text-xs font-medium text-ink/80 hover:text-ink transition-colors cursor-pointer"
118
- >
119
- Cancel
120
- </button>
121
- <button
122
- type="submit"
123
- className="flex items-center gap-1.5 px-4 py-2 rounded-lg bg-ink text-paper text-xs font-medium hover:bg-ink/90 transition-colors shadow-xs cursor-pointer"
124
- >
125
- <Plus size={14} />
126
- <span>Add Source</span>
127
- </button>
128
- </div>
129
- </form>
130
- </div>
131
- </div>
132
- );
133
- }
@@ -1,73 +0,0 @@
1
- /**
2
- * The bridge, driven through the transport the macOS shell installs.
3
- *
4
- * The interesting failures are about what the page can tell apart: a browser has
5
- * no shell at all, a shell announces itself before the first render, and a
6
- * refused command keeps the shell's own sentence. None of that is visible in the
7
- * panel's markup — a control that never works looks exactly like one that does
8
- * until it is pressed.
9
- */
10
-
11
- import { describe, expect, test, beforeEach } from 'bun:test';
12
-
13
- type Reply = (id: number, ok: boolean, payload: unknown) => void;
14
-
15
- interface ShellWindow {
16
- __kabmoCall?: (method: string, params?: Record<string, unknown>) => Promise<unknown>;
17
- __kabmoDesktop?: unknown;
18
- __kabmoReply?: Reply;
19
- }
20
-
21
- const shell = () => globalThis as unknown as { window?: ShellWindow };
22
-
23
- describe('desktop bridge', () => {
24
- beforeEach(() => {
25
- delete shell().window;
26
- });
27
-
28
- test('a browser has no shell, and every call refuses', async () => {
29
- shell().window = {};
30
- const bridge = await import('@/client/lib/desktop/bridge');
31
- expect(bridge.isDesktopShell()).toBe(false);
32
- expect(await bridge.desktopInfo()).toBeNull();
33
- await expect(bridge.readServers()).rejects.toThrow('Not running inside the Kabmo desktop shell.');
34
- });
35
-
36
- test('the injected identity is readable before any command runs', async () => {
37
- shell().window = {
38
- __kabmoCall: async () => null,
39
- __kabmoDesktop: { platform: 'macos', shellVersion: '0.1.0', overlayTitlebar: true, trafficLightInset: '5rem' },
40
- };
41
- const bridge = await import('@/client/lib/desktop/bridge');
42
- expect(bridge.isDesktopShell()).toBe(true);
43
- const info = await bridge.desktopInfo();
44
- expect(info?.overlayTitlebar).toBe(true);
45
- expect(info?.trafficLightInset).toBe('5rem');
46
- });
47
-
48
- test('a command answers through __kabmoCall', async () => {
49
- const seen: string[] = [];
50
- shell().window = {
51
- __kabmoCall: async (method) => {
52
- seen.push(method);
53
- return { entries: [], detected: [], activeId: 'local:1' };
54
- },
55
- };
56
- const bridge = await import('@/client/lib/desktop/bridge');
57
- const state = await bridge.readServers();
58
- expect(seen).toEqual(['servers_state']);
59
- expect(state.activeId).toBe('local:1');
60
- });
61
-
62
- /**
63
- * The shell sends its own sentence, which is what the UI shows. Stripping a
64
- * prefix would eat the first word of a message that starts with "Error".
65
- */
66
- test('a refused command keeps the shell’s own sentence, unstripped', async () => {
67
- const bridge = await import('@/client/lib/desktop/bridge');
68
- expect(bridge.bridgeError(new Error('Use the server’s root address — a base path is not supported.'))).toBe(
69
- 'Use the server’s root address — a base path is not supported.',
70
- );
71
- expect(bridge.bridgeError('plain')).toBe('plain');
72
- });
73
- });
@@ -1,203 +0,0 @@
1
- /**
2
- * @license
3
- * SPDX-License-Identifier: MIT
4
- */
5
-
6
- /**
7
- * The desktop shell's bridge, and the reason every other module asks this one
8
- * whether it is running inside the shell.
9
- *
10
- * THREE shells install the same transport, and that is the point of this module:
11
- *
12
- * - `packages/macos` (macOS, Swift + WKWebView)
13
- * - `packages/windows` (.NET + WPF + WebView2)
14
- * - `packages/linux` (Rust + GTK 3 + WebKitGTK 4.1)
15
- *
16
- * Each installs ONE transport before the page's own scripts run:
17
- * `window.__kabmoCall(method, params)` posts `{ id, method, params }` to a host
18
- * message handler named `kabmo`, and the shell answers by evaluating
19
- * `window.__kabmoReply(id, ok, payload)`. There is no capability file and no
20
- * per-origin allowance — the shell owns the webview, so the page cannot be
21
- * anything but one this window chose to load.
22
- *
23
- * This module must be safe in a BROWSER too: every function rejects with "not
24
- * inside the shell" when there is no bridge, and the navbar draws no server
25
- * control at all. A browser tab has no shell to control, and a control that
26
- * opened onto "not available" would be a button that never works.
27
- */
28
-
29
- /** What the shell reports about itself. */
30
- export interface DesktopInfo {
31
- platform: string;
32
- shellVersion: string;
33
- /**
34
- * The machine's architecture, in the canonical vocabulary (`arm64` / `x64`).
35
- *
36
- * Every desktop artifact is per-architecture, so without this the console can
37
- * only offer the release page. Absent on a shell too old to report it, which
38
- * degrades the offer to that page rather than breaking it.
39
- */
40
- arch?: string;
41
- /** True when the shell hides the native title bar and the page draws it. */
42
- overlayTitlebar: boolean;
43
- /**
44
- * macOS: the width of the traffic lights, which float over the page's LEFT
45
- * edge. Absent on a platform whose window controls are not on the left.
46
- */
47
- trafficLightInset?: string;
48
- /**
49
- * True when the shell is borderless and has NO controls of its own, so the
50
- * page must draw minimise / maximise / close.
51
- *
52
- * Windows and Linux. macOS gets its traffic lights from the system over a
53
- * full-size content view; a borderless Windows window has nothing at all, and
54
- * the webview there is an HWND — a WPF element cannot be drawn on top of it
55
- * (the airspace problem) — so the page is the only surface that can. Linux
56
- * could draw native buttons in a `GtkOverlay` (measured: an overlay child does
57
- * receive clicks over a WebView), but the page's set already exists, is tested,
58
- * and is the one every other shell's users see.
59
- */
60
- windowControls?: boolean;
61
- }
62
-
63
- /** One server in the shell's list, or one found on this machine. */
64
- export interface DesktopServer {
65
- id: string;
66
- label: string;
67
- url: string;
68
- kind: 'remote' | 'managed';
69
- port?: number;
70
- running: boolean;
71
- /** This shell started it (as opposed to a server found on the machine). */
72
- owned: boolean;
73
- version?: string;
74
- mode?: string;
75
- pid?: number;
76
- startedAt?: string;
77
- /** `stored` for the list, `record` for a local instance found on disk. */
78
- source: 'stored' | 'record';
79
- }
80
-
81
- export interface DesktopServersState {
82
- entries: DesktopServer[];
83
- /** Local instances this shell did NOT start — a `kabmo serve`, a dev server. */
84
- detected: DesktopServer[];
85
- activeId?: string;
86
- activeUrl?: string;
87
- }
88
-
89
- declare global {
90
- interface Window {
91
- __kabmoCall?: (method: string, params?: Record<string, unknown>) => Promise<unknown>;
92
- __kabmoDesktop?: DesktopInfo;
93
- __kabmoReply?: (id: number, ok: boolean, payload: unknown) => void;
94
- }
95
- }
96
-
97
- /** True when this page is inside the desktop shell. */
98
- export function isDesktopShell(): boolean {
99
- return typeof window !== 'undefined' && typeof window.__kabmoCall === 'function';
100
- }
101
-
102
- async function call<T>(method: string, params: Record<string, unknown> = {}): Promise<T> {
103
- const invoke = typeof window === 'undefined' ? undefined : window.__kabmoCall;
104
- if (!invoke) throw new Error('Not running inside the Kabmo desktop shell.');
105
- return (await invoke(method, params)) as T;
106
- }
107
-
108
- export function desktopInfo(): Promise<DesktopInfo | null> {
109
- if (!isDesktopShell()) return Promise.resolve(null);
110
- const injected = typeof window === 'undefined' ? undefined : window.__kabmoDesktop;
111
- // The shell injects this before the page's first script, so the navbar's first
112
- // paint is already correct; the command is only a fallback for a shell that
113
- // did not (an older build).
114
- if (injected) return Promise.resolve(injected);
115
- return call<DesktopInfo>('desktop_info');
116
- }
117
-
118
- export function readServers(): Promise<DesktopServersState> {
119
- return call<DesktopServersState>('servers_state');
120
- }
121
-
122
- export function addRemoteServer(label: string, url: string): Promise<DesktopServersState> {
123
- return call<DesktopServersState>('servers_add', { label, url });
124
- }
125
-
126
- export function removeServer(id: string): Promise<DesktopServersState> {
127
- return call<DesktopServersState>('servers_remove', { id });
128
- }
129
-
130
- /** Point the window at a server. The shell navigates, so this page goes away. */
131
- export function activateServer(id: string): Promise<DesktopServersState> {
132
- return call<DesktopServersState>('servers_activate', { id });
133
- }
134
-
135
- /** Start a local server as the shell's child, then navigate to it. */
136
- export function startLocalServer(port?: number, label?: string): Promise<DesktopServersState> {
137
- return call<DesktopServersState>('servers_start', { port: port ?? null, label: label ?? null });
138
- }
139
-
140
- export function stopLocalServer(id: string): Promise<DesktopServersState> {
141
- return call<DesktopServersState>('servers_stop', { id });
142
- }
143
-
144
- /**
145
- * A refused command's message.
146
- *
147
- * The shell sends its own sentence (a refused URL, a server that exited), which
148
- * is what the UI shows. Nothing is stripped: a message that genuinely starts with
149
- * "Error" would lose its first word.
150
- */
151
- export function bridgeError(error: unknown): string {
152
- return error instanceof Error ? error.message : String(error);
153
- }
154
-
155
- /** Minimise, maximise/restore and close, for a shell that draws no controls. */
156
- export function windowMinimize(): Promise<void> {
157
- return call<void>('window_minimize');
158
- }
159
-
160
- export function windowToggleMaximize(): Promise<void> {
161
- return call<void>('window_maximize');
162
- }
163
-
164
- export function windowClose(): Promise<void> {
165
- return call<void>('window_close');
166
- }
167
-
168
- /**
169
- * What the shell did with an update it was handed.
170
- *
171
- * The shell owns the whole run — download, verify, replace, relaunch — because
172
- * only it can do any of those things: a page cannot replace the executable it is
173
- * running inside, and a page's "download" leaves a file in a folder the user has
174
- * to find. This is the report it sends back.
175
- *
176
- * `relaunching` is the honest terminal state on success: the shell is about to
177
- * quit, so a caller that keeps a spinner going is describing a page that is
178
- * already gone.
179
- */
180
- export interface ShellUpdateOutcome {
181
- success: boolean;
182
- /** The version the shell installed, when it could read one. */
183
- version?: string | null;
184
- /** A sentence for the user — the shell's own, never a generic failure. */
185
- message: string;
186
- relaunching?: boolean;
187
- }
188
-
189
- /**
190
- * Ask the shell to install the build it just offered.
191
- *
192
- * `url` and `version` are the console's answer, passed through rather than
193
- * re-derived: the shell has no release list of its own, and asking it to fetch
194
- * one would be a second reader of the same GitHub endpoint.
195
- *
196
- * The shell VERIFIES the bytes before installing them (the platform's own check —
197
- * a code signature, an archive shape, a version floor). A console that is
198
- * compromised can therefore make the shell download, but not make it run
199
- * something the platform will not vouch for.
200
- */
201
- export function applyShellUpdate(url: string, version: string): Promise<ShellUpdateOutcome> {
202
- return call<ShellUpdateOutcome>('update_apply', { url, version });
203
- }
@@ -1,149 +0,0 @@
1
- /**
2
- * @license
3
- * SPDX-License-Identifier: MIT
4
- */
5
-
6
- /**
7
- * The presentation shaping over the usage rollup (`shaping.ts`): labels,
8
- * buckets, chart series and metric sets over an already-built aggregate.
9
- * Split verbatim from `aggregate.test.ts` so both files stay under the repo's
10
- * 350-line ceiling; the scanning and arithmetic live in that file.
11
- */
12
-
13
- import { describe, expect, test } from 'bun:test';
14
-
15
- import type { UsageAggregate } from '@/server/lib/omp/session/usage/aggregate';
16
- import { buildChartSeries, toBreakdownRows, toMetricSet } from '@/server/lib/omp/session/usage/shaping';
17
-
18
- function agg(partial: Partial<UsageAggregate> = {}): UsageAggregate {
19
- return {
20
- scannedTranscripts: 0, usageRecords: 0, costTotal: 0, costInput: 0, costOutput: 0,
21
- costCacheRead: 0, costCacheWrite: 0, inputTokens: 0, outputTokens: 0,
22
- cacheReadTokens: 0, cacheWriteTokens: 0, reasoningTokens: 0,
23
- activeDays: new Set<string>(), byModel: new Map(), byDay: new Map(), byProject: new Map(),
24
- ...partial,
25
- };
26
- }
27
-
28
- describe('buildChartSeries', () => {
29
- test('daily points are sorted ascending and labelled with the day', () => {
30
- const a = agg({ byDay: new Map([['1999-09-07', { tokens: 20, cost: 2 }], ['1999-09-05', { tokens: 10, cost: 1 }]]) });
31
- expect(buildChartSeries(a, 'daily')).toEqual([
32
- { label: 'Sep 5', cost: 1, tokens: 10 },
33
- { label: 'Sep 7', cost: 2, tokens: 20 },
34
- ]);
35
- });
36
-
37
- test('weekly buckets align to Monday, merging the days of one week', () => {
38
- const a = agg({
39
- byDay: new Map([
40
- ['1999-09-06', { tokens: 10, cost: 1 }], // Monday
41
- ['1999-09-08', { tokens: 20, cost: 2 }], // Wednesday, same week
42
- ['1999-09-20', { tokens: 30, cost: 3 }], // two weeks later
43
- ]),
44
- });
45
- expect(buildChartSeries(a, 'weekly')).toEqual([
46
- { label: 'Sep 6', cost: 3, tokens: 30 },
47
- { label: 'Sep 20', cost: 3, tokens: 30 },
48
- ]);
49
- });
50
-
51
- test('monthly buckets merge by calendar month and name the year when it is not the current one', () => {
52
- const a = agg({ byDay: new Map([['1999-09-05', { tokens: 10, cost: 1 }], ['1999-09-25', { tokens: 5, cost: 0.5 }], ['1998-12-01', { tokens: 1, cost: 0.1 }]]) });
53
- expect(buildChartSeries(a, 'monthly')).toEqual([
54
- { label: 'Dec 1998', cost: 0.1, tokens: 1 },
55
- { label: 'Sep 1999', cost: 1.5, tokens: 15 },
56
- ]);
57
- });
58
-
59
- test('truncates to the last 60 buckets', () => {
60
- const byDay = new Map<string, { tokens: number; cost: number }>();
61
- for (let i = 0; i < 61; i++) {
62
- const d = new Date(1999, 0, 1 + i);
63
- const key = `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;
64
- byDay.set(key, { tokens: i, cost: i });
65
- }
66
- const series = buildChartSeries(agg({ byDay }), 'daily');
67
- expect(series).toHaveLength(60);
68
- expect(series[0].tokens).toBe(1); // the oldest day fell off
69
- expect(series[59].tokens).toBe(60);
70
- });
71
- });
72
-
73
- describe('toMetricSet', () => {
74
- test('zeroes render as zeros, never NaN', () => {
75
- expect(toMetricSet(agg())).toEqual({
76
- rawCost: '$0.00', processedTokens: '0', activeRate: '0 active days', cachedInput: '0',
77
- cachedPercent: '0.0% of observed input', uncachedInput: '0', outputTokens: '0',
78
- reasoning: 'includes 0 reasoning', cacheSavings: '$0.00', scannedTranscripts: 0, usageRecords: 0,
79
- });
80
- });
81
-
82
- test('formats the aggregate, with the cache rate over observed input only', () => {
83
- const a = agg({
84
- costTotal: 2.95, costCacheRead: 0.05, inputTokens: 1000, outputTokens: 250,
85
- cacheReadTokens: 250, cacheWriteTokens: 0, reasoningTokens: 7, scannedTranscripts: 3, usageRecords: 4,
86
- activeDays: new Set(['d1', 'd2', 'd3']),
87
- });
88
- expect(toMetricSet(a)).toEqual({
89
- rawCost: '$2.95', processedTokens: '1,500', activeRate: '3 active days', cachedInput: '250',
90
- cachedPercent: '20.0% of observed input', uncachedInput: '1,000', outputTokens: '250',
91
- reasoning: 'includes 7 reasoning', cacheSavings: '$0.05', scannedTranscripts: 3, usageRecords: 4,
92
- });
93
- });
94
-
95
- test('the active-rate unit and plural follow the cadence', () => {
96
- const one = agg({ activeDays: new Set(['d1']) });
97
- expect(toMetricSet(one, 'weekly').activeRate).toBe('1 active week');
98
- expect(toMetricSet(one, 'monthly').activeRate).toBe('1 active month');
99
- expect(toMetricSet(one, 'daily').activeRate).toBe('1 active day');
100
- expect(toMetricSet(agg({ activeDays: new Set(['a', 'b']) }), 'monthly').activeRate).toBe('2 active months');
101
- });
102
- });
103
-
104
- describe('toBreakdownRows', () => {
105
- test('model rows are sorted by cost, formatted, and share the total', () => {
106
- const a = agg({
107
- costTotal: 2,
108
- byModel: new Map([['b', { tokens: 500, cost: 0.5 }], ['a', { tokens: 1500, cost: 1.5 }]]),
109
- });
110
- expect(toBreakdownRows(a, 'model')).toEqual([
111
- { name: 'a', tokens: '1,500', cost: '$1.50', share: '75%', sharePercent: 75, dotColorClass: 'bg-[var(--theme-ink)]' },
112
- { name: 'b', tokens: '500', cost: '$0.50', share: '25%', sharePercent: 25, dotColorClass: 'bg-[var(--theme-ink)]/70' },
113
- ]);
114
- });
115
-
116
- test('a zero-cost aggregate reports 0% shares instead of dividing by zero', () => {
117
- const rows = toBreakdownRows(agg({ byModel: new Map([['a', { tokens: 5, cost: 0 }]]) }), 'model');
118
- expect(rows[0].share).toBe('0%');
119
- expect(rows[0].sharePercent).toBe(0);
120
- });
121
-
122
- test('keeps only the twelve costliest rows and cycles the dot colours', () => {
123
- const byProject = new Map<string, { tokens: number; cost: number }>();
124
- for (let i = 0; i < 13; i++) byProject.set(`p${i}`, { tokens: i, cost: i });
125
- const rows = toBreakdownRows(agg({ costTotal: 78, byProject }), 'project');
126
- expect(rows).toHaveLength(12);
127
- expect(rows[0].name).toBe('p12');
128
- expect(rows[11].name).toBe('p1');
129
- expect(rows[5].dotColorClass).toBe(rows[0].dotColorClass); // five colours, cycled
130
- });
131
-
132
- test('the day tab is bucketed by the cadence', () => {
133
- const a = agg({ costTotal: 1.5, byDay: new Map([['1999-09-05', { tokens: 10, cost: 1 }], ['1999-09-25', { tokens: 5, cost: 0.5 }]]) });
134
- // A non-daily cadence buckets first, then re-enters with 'daily' — and the
135
- // 'YYYY-MM' bucket key is then labelled by `dayLabel`, which parses it as
136
- // the 1st of that month. The chart series for the same cadence says
137
- // "Sep 1999", so the two surfaces disagree (see the report note).
138
- expect(toBreakdownRows(a, 'day', 'monthly')).toEqual([
139
- { name: 'Sep 1', tokens: '15', cost: '$1.50', share: '100%', sharePercent: 100, dotColorClass: 'bg-[var(--theme-ink)]' },
140
- ]);
141
- // Sep 5 1999 is a Sunday (→ Mon Aug 30) and Sep 25 a Saturday (→ Mon Sep
142
- // 20), so the two days land in different weeks.
143
- expect(toBreakdownRows(a, 'day', 'weekly')).toEqual([
144
- { name: 'Aug 30', tokens: '10', cost: '$1.00', share: '67%', sharePercent: 67, dotColorClass: 'bg-[var(--theme-ink)]' },
145
- { name: 'Sep 20', tokens: '5', cost: '$0.50', share: '33%', sharePercent: 33, dotColorClass: 'bg-[var(--theme-ink)]/70' },
146
- ]);
147
- expect(toBreakdownRows(a, 'day', 'daily').map((r) => r.name)).toEqual(['Sep 5', 'Sep 25']);
148
- });
149
- });