@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
@@ -0,0 +1,149 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * "What's new" for the running version: the changelog section is chosen by the
8
+ * version this machine reports, not by anything the caller says.
9
+ *
10
+ * Pinned here: the exact section wins over a newer one, `v` prefixes normalize,
11
+ * a version the changelog does not name is reported rather than replaced by the
12
+ * newest section, and an unreadable install is an error. The omp half uses the
13
+ * same stub-binary shape as `omp.test.ts`, so no real binary or network is
14
+ * needed; both changelog reads are stubbed per source URL.
15
+ */
16
+
17
+ import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
18
+ import { tmpdir } from 'node:os';
19
+ import { join } from 'node:path';
20
+
21
+ import { executableStub } from '@/test-support/executable-stub';
22
+ import { invalidateOmpCliCache } from '@/server/lib/omp/core/cli';
23
+ import { buildActiveReleaseNotes, selectActiveNote } from '@/server/lib/updates/active-notes';
24
+ import { readInstalledVersion } from '@/server/lib/updates/install';
25
+ import { ompReleaseTagUrl, releaseTagUrl } from '@/server/lib/updates/release-url';
26
+ import type { ReleaseNote } from '@/shared/types/updates';
27
+
28
+ /** The runner's own fetch, reached through `Bun` so a stub leaked onto the global cannot be mistaken for it. */
29
+ const originalFetch = Bun.fetch;
30
+ const CACHE_SLOT = globalThis as { __kabmoChangelogCache?: unknown };
31
+
32
+ /** Same constant source as `omp.test.ts`: the compiled fixture is cached by source text. */
33
+ const OMP_STUB_SOURCE = `process.stdout.write(process.env.FAKE_OMP_VERSION_OUTPUT || '');`;
34
+
35
+ const note = (version: string): ReleaseNote => ({
36
+ version,
37
+ date: null,
38
+ url: releaseTagUrl(version),
39
+ body: `* notes for ${version}`,
40
+ });
41
+
42
+ /** A changelog naming each version, newest first as the real file is. */
43
+ function changelog(versions: string[]): string {
44
+ return [
45
+ '# Changelog',
46
+ '',
47
+ ...versions.flatMap((version) => [`## [${version}] — 2026-01-01`, '', note(version).body, '']),
48
+ ].join('\n');
49
+ }
50
+
51
+ describe('selectActiveNote', () => {
52
+ test('picks the section for the running version, not the newest one', () => {
53
+ const notes = [note('2.0.0'), note('1.5.0'), note('1.0.0')];
54
+ expect(selectActiveNote(notes, '1.5.0')?.version).toBe('1.5.0');
55
+ });
56
+
57
+ test('a heading `v` prefix and a bare binary version agree', () => {
58
+ expect(selectActiveNote([{ ...note('1.2.3'), version: 'v1.2.3' }], '1.2.3')?.version).toBe('v1.2.3');
59
+ });
60
+
61
+ test('an unnamed version is null, never the newest section', () => {
62
+ expect(selectActiveNote([note('2.0.0')], '1.0.0')).toBeNull();
63
+ });
64
+
65
+ test('no readable version is null', () => {
66
+ expect(selectActiveNote([note('2.0.0')], null)).toBeNull();
67
+ });
68
+ });
69
+
70
+ describe('buildActiveReleaseNotes', () => {
71
+ const realOverride = Bun.env.KABMO_OMP_BIN;
72
+ const realOutput = Bun.env.FAKE_OMP_VERSION_OUTPUT;
73
+
74
+ /** Every changelog read answers the same page; the target decides the URL. */
75
+ function stubChangelog(markdown: string, status = 200): void {
76
+ globalThis.fetch = (async () =>
77
+ new Response(markdown, { status, headers: { 'content-type': 'text/markdown' } })) as unknown as typeof fetch;
78
+ }
79
+
80
+ async function stubOmp(output: string): Promise<void> {
81
+ Bun.env.FAKE_OMP_VERSION_OUTPUT = output;
82
+ Bun.env.KABMO_OMP_BIN = await executableStub(OMP_STUB_SOURCE, 'fake-omp-version');
83
+ invalidateOmpCliCache();
84
+ }
85
+
86
+ beforeEach(() => {
87
+ delete CACHE_SLOT.__kabmoChangelogCache;
88
+ Bun.env.KABMO_OMP_BIN = join(tmpdir(), 'kabmo-definitely-absent', 'omp');
89
+ invalidateOmpCliCache();
90
+ });
91
+
92
+ afterEach(() => {
93
+ if (realOverride === undefined) delete Bun.env.KABMO_OMP_BIN;
94
+ else Bun.env.KABMO_OMP_BIN = realOverride;
95
+ if (realOutput === undefined) delete Bun.env.FAKE_OMP_VERSION_OUTPUT;
96
+ else Bun.env.FAKE_OMP_VERSION_OUTPUT = realOutput;
97
+ globalThis.fetch = originalFetch;
98
+ delete CACHE_SLOT.__kabmoChangelogCache;
99
+ invalidateOmpCliCache();
100
+ });
101
+
102
+ test('kabmo: the section for the version on disk', async () => {
103
+ const installed = await readInstalledVersion();
104
+ expect(installed).not.toBeNull();
105
+ stubChangelog(changelog(['999.0.0', installed!]));
106
+
107
+ const result = await buildActiveReleaseNotes('kabmo');
108
+
109
+ expect(result).toMatchObject({ target: 'kabmo', version: installed, error: null });
110
+ expect(result.note?.body).toBe(`* notes for ${installed}`);
111
+ expect(result.note?.url).toBe(releaseTagUrl(installed!));
112
+ expect(result.changelogUrl).toBe('https://github.com/kabmo-labs/kabmo/blob/HEAD/CHANGELOG.md');
113
+ });
114
+
115
+ test('kabmo: a version the changelog never named is reported, not faked', async () => {
116
+ stubChangelog(changelog(['999.0.0']));
117
+
118
+ const result = await buildActiveReleaseNotes('kabmo');
119
+
120
+ expect(result.note).toBeNull();
121
+ expect(result.error).toBe(`No changelog section for v${await readInstalledVersion()}`);
122
+ });
123
+
124
+ test('kabmo: an unreachable changelog is an error field, not a throw', async () => {
125
+ stubChangelog('', 500);
126
+
127
+ const result = await buildActiveReleaseNotes('kabmo');
128
+
129
+ expect(result.note).toBeNull();
130
+ expect(result.error).toBe('Release notes could not be fetched');
131
+ });
132
+
133
+ test('omp: the section for the version the binary reports', async () => {
134
+ await stubOmp('omp/18.3.0\n');
135
+ stubChangelog(changelog(['18.4.0', '18.3.0']));
136
+
137
+ const result = await buildActiveReleaseNotes('omp');
138
+
139
+ expect(result).toMatchObject({ target: 'omp', version: '18.3.0', error: null });
140
+ expect(result.note?.body).toBe('* notes for 18.3.0');
141
+ expect(result.note?.url).toBe(ompReleaseTagUrl('18.3.0'));
142
+ });
143
+
144
+ test('omp: no binary is an error, not notes for some other version', async () => {
145
+ const result = await buildActiveReleaseNotes('omp');
146
+
147
+ expect(result).toMatchObject({ target: 'omp', version: null, note: null, error: 'omp binary not found' });
148
+ });
149
+ });
@@ -0,0 +1,75 @@
1
+ /**
2
+ * "What's new" for the version that is running, per target.
3
+ *
4
+ * The update popup answers "what would I get" from the range between the
5
+ * installed version and npm's newest one. The About modal's pair of buttons
6
+ * answers the other question — "what am I running" — so this module reads the
7
+ * installed version from the machine (package.json on disk for Kabmo,
8
+ * `omp --version` for oh-my-pi) and takes exactly that version's changelog
9
+ * section. Nothing here trusts a client-supplied version: a caller cannot ask
10
+ * for notes belonging to a release this install never had.
11
+ *
12
+ * Never throws. A missing section, an unreadable install and an unreachable
13
+ * changelog are all `error` fields, because the dialog opens from a button and a
14
+ * 500 would surface as an empty panel with no explanation.
15
+ */
16
+
17
+ import { fetchChangelogNotes, fetchOmpChangelogNotes } from '@/server/lib/updates/changelog-file';
18
+ import { readInstalledVersion } from '@/server/lib/updates/install';
19
+ import { readOmpInstalledVersion } from '@/server/lib/updates/omp';
20
+ import { CHANGELOG_PAGE, OMP_CHANGELOG_PAGE } from '@/server/lib/updates/release-url';
21
+ import { normalizeVersion } from '@/shared/lib/updates/semver';
22
+ import type { ActiveReleaseNotes, ReleaseNote, UpdateTarget } from '@/shared/types/updates';
23
+
24
+ /**
25
+ * The section belonging to `version`, matched on normalized semver so a
26
+ * changelog heading's `v` prefix and the binary's bare version agree.
27
+ */
28
+ export function selectActiveNote(notes: ReleaseNote[], version: string | null): ReleaseNote | null {
29
+ const wanted = version ? normalizeVersion(version) : null;
30
+ if (!wanted) return null;
31
+ return notes.find((note) => normalizeVersion(note.version) === wanted) ?? null;
32
+ }
33
+
34
+ /** The notes for one target's running version. */
35
+ export async function buildActiveReleaseNotes(target: UpdateTarget): Promise<ActiveReleaseNotes> {
36
+ const changelogUrl = target === 'omp' ? OMP_CHANGELOG_PAGE : CHANGELOG_PAGE;
37
+
38
+ try {
39
+ const probe = target === 'omp' ? await readOmpInstalledVersion() : null;
40
+ const version = probe ? probe.current : await readInstalledVersion();
41
+ if (!version) {
42
+ return {
43
+ target,
44
+ version: null,
45
+ note: null,
46
+ changelogUrl,
47
+ error: probe
48
+ ? probe.error ?? 'Could not determine the installed omp version'
49
+ : 'The installed Kabmo version could not be read',
50
+ };
51
+ }
52
+
53
+ const notes = target === 'omp' ? await fetchOmpChangelogNotes() : await fetchChangelogNotes();
54
+ if (notes.length === 0) {
55
+ return { target, version, note: null, changelogUrl, error: 'Release notes could not be fetched' };
56
+ }
57
+
58
+ const note = selectActiveNote(notes, version);
59
+ return {
60
+ target,
61
+ version,
62
+ note,
63
+ changelogUrl,
64
+ error: note ? null : `No changelog section for v${version}`,
65
+ };
66
+ } catch (error) {
67
+ return {
68
+ target,
69
+ version: null,
70
+ note: null,
71
+ changelogUrl,
72
+ error: error instanceof Error ? error.message : 'Release notes could not be read',
73
+ };
74
+ }
75
+ }
@@ -15,7 +15,7 @@
15
15
  * the heading itself and links each section to that version's release page.
16
16
  */
17
17
 
18
- import { releaseTagUrl, REPO } from '@/server/lib/updates/release-url';
18
+ import { OMP_REPO, releaseTagUrl, REPO, ompReleaseTagUrl } from '@/server/lib/updates/release-url';
19
19
  import type { ReleaseNote } from '@/shared/types/updates';
20
20
 
21
21
  /**
@@ -28,6 +28,12 @@ import type { ReleaseNote } from '@/shared/types/updates';
28
28
  */
29
29
  export const CHANGELOG_URL = `https://raw.githubusercontent.com/${REPO}/HEAD/CHANGELOG.md`;
30
30
 
31
+ /**
32
+ * oh-my-pi's changelog: the coding-agent package inside its monorepo. Same
33
+ * contract as Kabmo's — one `## [x.y.z]` section per release tag.
34
+ */
35
+ export const OMP_CHANGELOG_URL = `https://raw.githubusercontent.com/${OMP_REPO}/HEAD/packages/coding-agent/CHANGELOG.md`;
36
+
31
37
  /** How long a read is reused. The file changes on release, not on read. */
32
38
  const TTL_MS = 60_000;
33
39
 
@@ -57,7 +63,10 @@ const REFERENCE_DEFINITION = /^\[[^\]]+\]:\s/;
57
63
  * definitions, not notes, and without the guard they rendered as the last
58
64
  * section's body.
59
65
  */
60
- export function parseChangelogSections(markdown: string): ReleaseNote[] {
66
+ export function parseChangelogSections(
67
+ markdown: string,
68
+ releaseUrl: (version: string) => string = releaseTagUrl,
69
+ ): ReleaseNote[] {
61
70
  const notes: ReleaseNote[] = [];
62
71
  let version: string | null = null;
63
72
  let date: string | null = null;
@@ -65,7 +74,7 @@ export function parseChangelogSections(markdown: string): ReleaseNote[] {
65
74
 
66
75
  const flush = () => {
67
76
  if (version === null) return;
68
- notes.push({ version, date, url: releaseTagUrl(version), body: body.join('\n').trim() });
77
+ notes.push({ version, date, url: releaseUrl(version), body: body.join('\n').trim() });
69
78
  };
70
79
 
71
80
  for (const raw of markdown.split('\n')) {
@@ -97,26 +106,48 @@ interface ChangelogCache {
97
106
  at: number;
98
107
  }
99
108
 
100
- const cacheSlot = globalThis as typeof globalThis & { __kabmoChangelogCache?: ChangelogCache };
109
+ /**
110
+ * Keyed by source URL: Kabmo and omp are two files, and a shared single slot
111
+ * made one target's read answer the other's — measured as omp notes rendering
112
+ * under the Kabmo heading. A `Map` also keeps the boot cost at one read per
113
+ * file rather than one per target.
114
+ */
115
+ type ChangelogCacheSlot = { __kabmoChangelogCache?: Map<string, ChangelogCache> };
101
116
 
102
- /** Never throws: an unreadable changelog is an empty list, and the caller words it. */
103
- export async function fetchChangelogNotes(force = false): Promise<ReleaseNote[]> {
104
- const cached = cacheSlot.__kabmoChangelogCache;
117
+ const cacheSlot = globalThis as typeof globalThis & ChangelogCacheSlot;
118
+
119
+ async function fetchNotes(
120
+ url: string,
121
+ releaseUrl: (version: string) => string,
122
+ force: boolean,
123
+ ): Promise<ReleaseNote[]> {
124
+ const cache = (cacheSlot.__kabmoChangelogCache ??= new Map<string, ChangelogCache>());
125
+ const cached = cache.get(url);
105
126
  if (!force && cached && Date.now() - cached.at < TTL_MS) return cached.notes;
106
127
 
107
128
  let notes: ReleaseNote[] = [];
108
129
  try {
109
- const response = await fetch(CHANGELOG_URL, {
130
+ const response = await fetch(url, {
110
131
  headers: { 'User-Agent': 'kabmo' },
111
132
  signal: AbortSignal.timeout(TIMEOUT_MS),
112
133
  });
113
- if (response.ok) notes = parseChangelogSections(await response.text());
134
+ if (response.ok) notes = parseChangelogSections(await response.text(), releaseUrl);
114
135
  } catch {
115
- // Reported as an empty list; the popup says the notes could not be fetched.
136
+ // Reported as an empty list; the caller words the failure.
116
137
  }
117
138
 
118
139
  // An empty read is not cached: a transient failure would otherwise pin "no
119
140
  // release notes" for a minute and hide a real update.
120
- if (notes.length > 0) cacheSlot.__kabmoChangelogCache = { notes, at: Date.now() };
141
+ if (notes.length > 0) cache.set(url, { notes, at: Date.now() });
121
142
  return notes;
122
143
  }
144
+
145
+ /** Never throws: an unreadable changelog is an empty list, and the caller words it. */
146
+ export function fetchChangelogNotes(force = false): Promise<ReleaseNote[]> {
147
+ return fetchNotes(CHANGELOG_URL, releaseTagUrl, force);
148
+ }
149
+
150
+ /** oh-my-pi's sections, linked to omp's own release tags. Never throws. */
151
+ export function fetchOmpChangelogNotes(force = false): Promise<ReleaseNote[]> {
152
+ return fetchNotes(OMP_CHANGELOG_URL, ompReleaseTagUrl, force);
153
+ }
@@ -25,7 +25,7 @@
25
25
  import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
26
26
 
27
27
  import { MAX_NOTES_BYTES, MAX_VERSIONS, capReleaseNotes, selectReleaseRange } from '@/server/lib/updates/changelog';
28
- import { CHANGELOG_URL, fetchChangelogNotes, parseChangelogSections } from '@/server/lib/updates/changelog-file';
28
+ import { CHANGELOG_URL, OMP_CHANGELOG_URL, fetchChangelogNotes, fetchOmpChangelogNotes, parseChangelogSections } from '@/server/lib/updates/changelog-file';
29
29
  import { releaseTagUrl } from '@/server/lib/updates/release-url';
30
30
  import type { ReleaseNote } from '@/shared/types/updates';
31
31
 
@@ -110,6 +110,8 @@ describe('fetchChangelogNotes', () => {
110
110
  beforeEach(() => {
111
111
  delete (globalThis as typeof globalThis & { __kabmoChangelogCache?: unknown }).__kabmoChangelogCache;
112
112
  urls = [];
113
+ body = CHANGELOG;
114
+ status = 200;
113
115
  globalThis.fetch = (async (input: RequestInfo | URL) => {
114
116
  urls.push(String(input));
115
117
  return new Response(body, { status, headers: { 'content-type': 'text/markdown' } });
@@ -145,6 +147,18 @@ describe('fetchChangelogNotes', () => {
145
147
  expect(await fetchChangelogNotes()).toEqual([]);
146
148
  expect(urls).toHaveLength(2);
147
149
  });
150
+
151
+ test('the omp source is its own URL and links omp release tags', async () => {
152
+ const notes = await fetchOmpChangelogNotes();
153
+ expect(urls[0]).toBe(OMP_CHANGELOG_URL);
154
+ expect(notes[0]!.url).toBe('https://github.com/can1357/oh-my-pi/releases/tag/v3.14.0');
155
+ });
156
+
157
+ test('a warm Kabmo cache does not answer the omp read', async () => {
158
+ await fetchChangelogNotes();
159
+ await fetchOmpChangelogNotes();
160
+ expect(urls).toEqual([CHANGELOG_URL, OMP_CHANGELOG_URL]);
161
+ });
148
162
  });
149
163
 
150
164
  describe('selectReleaseRange', () => {
@@ -48,35 +48,62 @@ function parseOmpVersion(output: string): string | null {
48
48
  return output.match(/^omp\/(\S+)/m)?.[1] ?? null;
49
49
  }
50
50
 
51
- export async function checkOmpUpdate(): Promise<UpdateTargetInfo> {
51
+ export interface OmpInstalledVersion {
52
+ /** Whether an `omp` binary was found at all. */
53
+ installed: boolean;
54
+ /** The version the binary names itself, or null when it could not be read. */
55
+ current: string | null;
56
+ error: string | null;
57
+ }
58
+
59
+ /**
60
+ * The version `omp --version` reports, split out of the update check because
61
+ * the About modal's "What's new in Oh-My-Pi" needs only this half: the notes
62
+ * belong to the running binary, and reading npm again would answer a different
63
+ * question (what is published, not what is installed).
64
+ */
65
+ export async function readOmpInstalledVersion(): Promise<OmpInstalledVersion> {
52
66
  const bin = resolveOmpBin();
53
- if (!bin) {
67
+ if (!bin) return { installed: false, current: null, error: 'omp binary not found' };
68
+
69
+ try {
70
+ const { stdout, stderr, exitCode } = await runCapture(bin, ['--version'], 30000, 1024 * 1024);
71
+ const current = parseOmpVersion(combined(stdout, stderr));
72
+ if (current) return { installed: true, current, error: null };
73
+ const error =
74
+ exitCode !== 0
75
+ ? `omp --version exited with code ${exitCode}`
76
+ : 'Could not determine the installed omp version';
77
+ return { installed: true, current: null, error };
78
+ } catch (err) {
79
+ return {
80
+ installed: true,
81
+ current: null,
82
+ error: err instanceof Error ? err.message : String(err),
83
+ };
84
+ }
85
+ }
86
+
87
+ export async function checkOmpUpdate(): Promise<UpdateTargetInfo> {
88
+ const probe = await readOmpInstalledVersion();
89
+ if (!probe.installed) {
54
90
  return {
55
91
  current: null,
56
92
  latest: null,
57
93
  updateAvailable: false,
58
94
  installed: false,
59
- error: 'omp binary not found',
95
+ error: probe.error,
60
96
  };
61
97
  }
62
98
 
63
- let current: string | null = null;
64
- let execMessage: string | null = null;
65
- try {
66
- const { stdout, stderr, exitCode } = await runCapture(bin, ['--version'], 30000, 1024 * 1024);
67
- current = parseOmpVersion(combined(stdout, stderr));
68
- if (exitCode !== 0) execMessage = `omp --version exited with code ${exitCode}`;
69
- } catch (err) {
70
- execMessage = err instanceof Error ? err.message : String(err);
71
- }
72
-
99
+ const current = probe.current;
73
100
  const latest = await fetchNpmLatest(OMP_PACKAGE);
74
101
  // With no version on disk there is nothing to compare, and "an update exists"
75
102
  // would be a claim about a copy that could not be read.
76
103
  const updateAvailable = Boolean(current && latest && isNewer(latest, current));
77
104
 
78
- let error: string | null = null;
79
- if (!current) error = execMessage ?? 'Could not determine the installed omp version';
105
+ let error: string | null = probe.error;
106
+ if (!current) error = probe.error ?? 'Could not determine the installed omp version';
80
107
  else if (!latest) error = 'Could not read the latest oh-my-pi version from npm';
81
108
 
82
109
  return { current, latest, updateAvailable, installed: true, error };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Where Kabmo's release notes live.
2
+ * Where the release notes live: Kabmo's repository, and oh-my-pi's.
3
3
  *
4
4
  * Two questions, two sources, deliberately. The VERSION an install can move to
5
5
  * comes from npm (see ./npm) — that is the channel `bun add -g kabmo@…`
@@ -8,6 +8,9 @@
8
8
  * hashes and contributor credits, and the release page is where a reader can
9
9
  * follow them. So the popup's links point at GitHub while the version it
10
10
  * announces comes from the registry.
11
+ *
12
+ * omp follows the same shape from its own monorepo; the coding-agent package
13
+ * owns the changelog, and its release tags are `v<version>`.
11
14
  */
12
15
 
13
16
  /**
@@ -23,3 +26,26 @@ export const RELEASES_URL = `https://github.com/${REPO}/releases`;
23
26
  export function releaseTagUrl(version: string): string {
24
27
  return `${RELEASES_URL}/tag/v${version}`;
25
28
  }
29
+
30
+ /** The Kabmo changelog file, as a reader follows it on GitHub. */
31
+ export const CHANGELOG_PAGE = `https://github.com/${REPO}/blob/HEAD/CHANGELOG.md`;
32
+
33
+ /**
34
+ * oh-my-pi's repository. `omp` publishes from a monorepo, and its release
35
+ * notes live in the coding-agent package's own changelog — the same prose the
36
+ * GitHub release bodies carry.
37
+ */
38
+ export const OMP_REPO = 'can1357/oh-my-pi';
39
+
40
+ /** The package directory inside that monorepo. */
41
+ const OMP_PACKAGE_DIR = 'packages/coding-agent';
42
+
43
+ export const OMP_RELEASES_URL = `https://github.com/${OMP_REPO}/releases`;
44
+
45
+ /** One omp release tag's page. */
46
+ export function ompReleaseTagUrl(version: string): string {
47
+ return `${OMP_RELEASES_URL}/tag/v${version}`;
48
+ }
49
+
50
+ /** The omp changelog file, as a reader follows it on GitHub. */
51
+ export const OMP_CHANGELOG_PAGE = `https://github.com/${OMP_REPO}/blob/HEAD/${OMP_PACKAGE_DIR}/CHANGELOG.md`;
@@ -0,0 +1,200 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Folding one transcript line into rollup counters — the pure half of the
8
+ * Token Usage index.
9
+ *
10
+ * Every case pins a number a user reads, so the assertions are exact:
11
+ *
12
+ * - a provider is part of a row's identity (two accounts serving one model id
13
+ * are two rows, not one merged cost);
14
+ * - the day is the reader's LOCAL calendar day, so "Today" and the chart agree;
15
+ * - a turn with tokens and no reported cost is unpriced, never free;
16
+ * - a torn final line must be dropped, or the next append would parse its
17
+ * remainder as a fresh entry.
18
+ */
19
+
20
+ import { describe, expect, test } from 'bun:test';
21
+
22
+ import {
23
+ completeLineOffset,
24
+ foldUsage,
25
+ foldUsageText,
26
+ parseUsageLine,
27
+ type ParsedUsageEntry,
28
+ type UsageRollupRow,
29
+ } from '@/server/lib/usage/index-parse';
30
+ import { localDayKey } from '@/shared/lib/usage/range';
31
+
32
+
33
+ function messageLine(options: {
34
+ timestamp?: string;
35
+ provider?: string;
36
+ model?: string;
37
+ usage?: Record<string, unknown>;
38
+ }): string {
39
+ return JSON.stringify({
40
+ type: 'message',
41
+ timestamp: options.timestamp,
42
+ message: {
43
+ role: 'assistant',
44
+ provider: options.provider,
45
+ model: options.model,
46
+ usage: options.usage ?? {},
47
+ },
48
+ });
49
+ }
50
+
51
+ function costed(options: {
52
+ timestamp: string;
53
+ provider: string;
54
+ model: string;
55
+ input: number;
56
+ output: number;
57
+ cacheRead: number;
58
+ cost: number;
59
+ }): string {
60
+ return messageLine({
61
+ timestamp: options.timestamp,
62
+ provider: options.provider,
63
+ model: options.model,
64
+ usage: {
65
+ input: options.input,
66
+ output: options.output,
67
+ cacheRead: options.cacheRead,
68
+ cacheWrite: 0,
69
+ totalTokens: options.input + options.output + options.cacheRead,
70
+ cost: { total: options.cost, input: options.cost / 2, output: options.cost / 4, cacheRead: options.cost / 4, cacheWrite: 0 },
71
+ },
72
+ });
73
+ }
74
+
75
+ describe('parseUsageLine', () => {
76
+ test('attributes the provider and model that served the turn', () => {
77
+ const parsed = parseUsageLine(costed({
78
+ timestamp: '2026-10-05T10:00:00.000Z',
79
+ provider: 'kenari-jatis',
80
+ model: 'deepseek-v4-1-flash',
81
+ input: 10,
82
+ output: 5,
83
+ cacheRead: 100,
84
+ cost: 1.5,
85
+ }));
86
+ expect(parsed).not.toBeNull();
87
+ expect(parsed?.provider).toBe('kenari-jatis');
88
+ expect(parsed?.model).toBe('deepseek-v4-1-flash');
89
+ });
90
+
91
+ test('folds a slug alias onto one provider identity', () => {
92
+ // omp writes both spellings; the breakdown must not grow a second
93
+ // `command-code` row beside `commandcode`.
94
+ const parsed = parseUsageLine(costed({
95
+ timestamp: '2026-10-05T10:00:00.000Z',
96
+ provider: 'command-code',
97
+ model: 'glm-5.3-flash',
98
+ input: 1,
99
+ output: 1,
100
+ cacheRead: 0,
101
+ cost: 0,
102
+ }));
103
+ expect(parsed?.provider).toBe('commandcode');
104
+ });
105
+
106
+ test('missing provider and model become `unknown`, not empty strings', () => {
107
+ const parsed = parseUsageLine(messageLine({ timestamp: '2026-10-05T10:00:00.000Z' }));
108
+ expect(parsed?.provider).toBe('unknown');
109
+ expect(parsed?.model).toBe('unknown');
110
+ });
111
+
112
+ test('the day is the local calendar day of the timestamp', () => {
113
+ const at = new Date(2026, 9, 5, 0, 30, 0).getTime();
114
+ const parsed = parseUsageLine(costed({
115
+ timestamp: new Date(at).toISOString(),
116
+ provider: 'kenari',
117
+ model: 'm',
118
+ input: 1,
119
+ output: 0,
120
+ cacheRead: 0,
121
+ cost: 0,
122
+ }));
123
+ // UTC is still Oct 4 for a 00:30 WIB record; the panel's "Today" is local.
124
+ expect(parsed?.day).toBe(localDayKey(at));
125
+ expect(parsed?.day).toBe('2026-10-05');
126
+ });
127
+
128
+ test('a line with no timestamp keeps an empty day so windows can include it', () => {
129
+ const parsed = parseUsageLine(messageLine({ provider: 'kenari', model: 'm' }));
130
+ expect(parsed?.day).toBe('');
131
+ });
132
+
133
+ test('non-message entries and torn lines are rejected', () => {
134
+ expect(parseUsageLine(JSON.stringify({ type: 'custom', message: { usage: { input: 1 } } }))).toBeNull();
135
+ expect(parseUsageLine(messageLine({}).slice(0, 20))).toBeNull();
136
+ expect(parseUsageLine('')).toBeNull();
137
+ });
138
+ });
139
+
140
+ describe('foldUsage', () => {
141
+ const rows = new Map<string, UsageRollupRow>();
142
+ const entry = (provider: string, model: string, cost: number, totalTokens = 10): ParsedUsageEntry => ({
143
+ day: '2026-10-05',
144
+ provider,
145
+ model,
146
+ usage: { input: 4, output: 2, cacheRead: 4, cacheWrite: 0, totalTokens, cost: { total: cost } },
147
+ });
148
+
149
+ test('keys on provider AND model, so two accounts stay separate', () => {
150
+ foldUsage(rows, 'p', entry('kenari-jatis', 'deepseek-v4-1-flash', 10));
151
+ foldUsage(rows, 'p', entry('kenari', 'deepseek-v4-1-flash', 2));
152
+ expect(rows.size).toBe(2);
153
+ expect([...rows.values()].map((row) => row.provider).sort()).toEqual(['kenari', 'kenari-jatis']);
154
+ });
155
+
156
+ test('one key accumulates its counters rather than replacing them', () => {
157
+ const single = new Map<string, UsageRollupRow>();
158
+ foldUsage(single, 'p', entry('kenari', 'm', 1.5));
159
+ foldUsage(single, 'p', entry('kenari', 'm', 2.5));
160
+ const row = [...single.values()][0];
161
+ expect(row.records).toBe(2);
162
+ expect(row.costTotal).toBeCloseTo(4, 10);
163
+ expect(row.total).toBe(20);
164
+ });
165
+
166
+ test('an explicit totalTokens wins over the re-derived sum', () => {
167
+ const single = new Map<string, UsageRollupRow>();
168
+ foldUsage(single, 'p', entry('kenari', 'm', 1, 999));
169
+ expect([...single.values()][0].total).toBe(999);
170
+ });
171
+
172
+ test('a turn with tokens and no reported cost counts as unpriced', () => {
173
+ const single = new Map<string, UsageRollupRow>();
174
+ foldUsage(single, 'p', entry('kenari', 'm', 0));
175
+ expect([...single.values()][0].unpriced).toBe(1);
176
+ });
177
+ });
178
+
179
+ describe('foldUsageText', () => {
180
+ test('a partial last line is dropped when only complete lines are wanted', () => {
181
+ const complete = costed({ timestamp: '2026-10-05T10:00:00.000Z', provider: 'kenari', model: 'm', input: 1, output: 1, cacheRead: 0, cost: 1 });
182
+ const text = `${complete}\n{"type":"message","message":{"usage":{"inp`;
183
+ const rows = new Map<string, UsageRollupRow>();
184
+ foldUsageText(rows, 'p', text, true);
185
+ expect([...rows.values()][0].records).toBe(1);
186
+
187
+ // The same text read as a whole file keeps the trailing fragment's parse
188
+ // failure silent rather than throwing.
189
+ const whole = new Map<string, UsageRollupRow>();
190
+ foldUsageText(whole, 'p', text, false);
191
+ expect([...whole.values()][0].records).toBe(1);
192
+ });
193
+
194
+ test('completeLineOffset stops at the last newline, never mid-line', () => {
195
+ expect(completeLineOffset('{"a":1}\n{"b":2}\n')).toBe(16);
196
+ expect(completeLineOffset('{"a":1}\n{"b":')).toBe(8);
197
+ expect(completeLineOffset('no newline')).toBe(0);
198
+ });
199
+ });
200
+