@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,166 +1,87 @@
1
- import { json } from '@/server/lib/remix-compat';
2
- import type { ActionFunctionArgs, LoaderFunctionArgs } from '@/server/lib/remix-compat';
3
- import { methodNotAllowed } from '@/server/lib/route-adapter';
4
- import { BREAKDOWN_DATA, MOCK_CHART_SERIES, MOCK_CUSTOM_RANGE_DATA, MOCK_RANGE_DATA, TIME_RANGES } from '@/client/data/mock/token-usage';
5
- import { isMockMode } from '@/server/mock.server';
6
- import { loadModelsDevCatalog } from '@/shared/lib/models/catalog';
7
- import { aggregateUsageWindows, PRESET_RANGES, type UsageWindow } from '@/server/lib/omp/session/usage/aggregate';
8
- import { buildChartSeries, toBreakdownRows, toMetricSet } from '@/server/lib/omp/session/usage/shaping';
9
- import type { BreakdownRow, BreakdownTab, CadenceType, ChartSeriesPoint, TimeRangeType, TokenUsageMetricSet } from '@/shared/types';
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
10
5
 
11
- const REAL_ZERO_METRIC: TokenUsageMetricSet = {
12
- rawCost: '$0.00',
13
- processedTokens: '0',
14
- activeRate: '0 per active day',
15
- cachedInput: '0',
16
- cachedPercent: '0.0% of observed input',
17
- uncachedInput: '0',
18
- outputTokens: '0',
19
- reasoning: 'includes 0 reasoning',
20
- cacheSavings: '$0.00',
21
- scannedTranscripts: 0,
22
- usageRecords: 0,
23
- };
6
+ /**
7
+ * `GET|POST /api/telemetry/tokens` — token and cost usage for the settings
8
+ * panel.
9
+ *
10
+ * The response is ONE payload carrying every view the panel can draw for the
11
+ * requested period (totals, the provider → model tree, daily rows with their
12
+ * per-provider split, project rows). Cadence and breakdown tabs are therefore
13
+ * client-side re-buckets, not requests — the previous shape answered a fresh
14
+ * full scan for each one.
15
+ *
16
+ * What is deliberately absent:
17
+ * - `rangeData` / `breakdownData`: three copies of data the panel never read.
18
+ * It kept only `metrics`, `breakdownRows` and `chartSeries`.
19
+ * - `pricing`: the models.dev catalog was fetched (5.96 MB, measured 5.63 s,
20
+ * 8 s timeout) on every request and no client code ever read the result.
21
+ *
22
+ * `?refresh=1` re-checks the sessions tree before answering; without it the
23
+ * index is at most 20 seconds stale, which is what makes a period change cost
24
+ * milliseconds.
25
+ */
24
26
 
25
- const CADENCES: CadenceType[] = ['daily', 'weekly', 'monthly'];
26
- const ISO_DATE = /^\d{4}-\d{2}-\d{2}$/;
27
+ import { json, type ActionFunctionArgs, type LoaderFunctionArgs } from '@/server/lib/remix-compat';
28
+ import { methodNotAllowed } from '@/server/lib/route-adapter';
29
+ import { isMockMode } from '@/server/mock.server';
30
+ import { buildTokenUsagePayload } from '@/server/lib/usage/index-query.server';
31
+ import { mockTokenUsagePayload } from '@/client/data/mock/token-usage';
32
+ import type { TimeRangeType } from '@/shared/types';
27
33
 
28
- function parseWindow(url: URL): UsageWindow {
29
- const timeRange = (url.searchParams.get('timeRange') as TimeRangeType) || '30d';
30
- if (timeRange === 'custom') {
31
- const from = url.searchParams.get('customFrom') || '';
32
- const to = url.searchParams.get('customTo') || '';
33
- if (ISO_DATE.test(from) && ISO_DATE.test(to) && from <= to) {
34
- return { kind: 'custom', from, to };
35
- }
36
- return { kind: 'preset', range: '30d' };
37
- }
38
- if (timeRange === 'all') return { kind: 'all' };
39
- if (PRESET_RANGES.includes(timeRange as Exclude<TimeRangeType, 'custom'>)) {
40
- return { kind: 'preset', range: timeRange as Exclude<TimeRangeType, 'custom'> };
41
- }
42
- return { kind: 'preset', range: '30d' };
43
- }
34
+ const RANGES: readonly TimeRangeType[] = ['today', '7d', '30d', '90d', 'all', 'custom'];
35
+ /** Never cached: the index can change under a client that is polling. */
36
+ const HEADERS = { 'cache-control': 'no-store' };
44
37
 
45
- /** Optional per-model rates from the models.dev catalog (input/output per
46
- * 1M tokens). Failures degrade to an empty map — pricing is supplementary. */
47
- async function loadModelRates(modelNames: string[]): Promise<Record<string, { input?: number; output?: number }>> {
48
- try {
49
- const catalog = await loadModelsDevCatalog();
50
- const rates: Record<string, { input?: number; output?: number }> = {};
51
- for (const name of modelNames) {
52
- const bare = name.split('/').pop()?.toLowerCase() ?? name.toLowerCase();
53
- for (const provider of Object.values(catalog)) {
54
- const models = provider?.models;
55
- if (!models || typeof models !== 'object') continue;
56
- const match = Object.entries(models).find(([key, model]) => {
57
- const candidates = [key.toLowerCase(), (model?.name ?? '').toLowerCase()];
58
- return candidates.some((candidate) => candidate === bare || candidate === name.toLowerCase());
59
- });
60
- if (match) {
61
- rates[name] = { input: match[1]?.cost?.input, output: match[1]?.cost?.output };
62
- break;
63
- }
64
- }
65
- }
66
- return rates;
67
- } catch {
68
- return {};
69
- }
38
+ function readQuery(url: URL): { range: TimeRangeType; customFrom: string | null; customTo: string | null } {
39
+ const requested = url.searchParams.get('range') ?? url.searchParams.get('timeRange') ?? '30d';
40
+ const range = (RANGES as readonly string[]).includes(requested) ? (requested as TimeRangeType) : '30d';
41
+ return {
42
+ range,
43
+ customFrom: url.searchParams.get('customFrom'),
44
+ customTo: url.searchParams.get('customTo'),
45
+ };
70
46
  }
71
47
 
72
- export async function loader({ request }: LoaderFunctionArgs) {
48
+ export async function loader({ request, params }: LoaderFunctionArgs) {
49
+ if (request.method !== 'GET') return methodNotAllowed({ request, params });
73
50
  const url = new URL(request.url);
74
- const timeRange = (url.searchParams.get('timeRange') as TimeRangeType) || '30d';
75
- const breakdownTab = (url.searchParams.get('breakdownTab') as BreakdownTab) || 'model';
76
- const cadenceParam = url.searchParams.get('cadence');
77
- const cadence = CADENCES.includes(cadenceParam as CadenceType) ? (cadenceParam as CadenceType) : 'daily';
78
- const window = parseWindow(url);
79
- const mock = isMockMode();
80
-
81
- if (mock) {
82
- const activeMetrics = window.kind === 'custom'
83
- ? MOCK_CUSTOM_RANGE_DATA
84
- : (MOCK_RANGE_DATA[timeRange as Exclude<TimeRangeType, 'custom'>] || MOCK_RANGE_DATA['30d']);
85
- const activeBreakdownRows = BREAKDOWN_DATA[breakdownTab] || BREAKDOWN_DATA.model;
86
- const chartSeries = MOCK_CHART_SERIES[cadence] || MOCK_CHART_SERIES.daily;
51
+ const query = readQuery(url);
87
52
 
88
- return json({
89
- timeRanges: TIME_RANGES,
90
- rangeData: MOCK_RANGE_DATA,
91
- breakdownData: BREAKDOWN_DATA,
92
- activeMetrics,
93
- activeBreakdownRows,
94
- chartSeries,
95
- metrics: activeMetrics,
96
- breakdownRows: activeBreakdownRows,
97
- timeRange,
98
- breakdownTab,
99
- cadence,
100
- isMock: true,
101
- });
102
- }
53
+ if (isMockMode()) return json(mockTokenUsagePayload(query.range), { headers: HEADERS });
103
54
 
104
- // Real Mode: aggregate actual token/cost usage from omp session files.
105
55
  try {
106
- // One scan, every window: the tree read is the expensive part (measured
107
- // 795 ms over 455 transcripts), and folding six windows from one scan
108
- // replaced six separate reads — 3.3 s cold on this machine.
109
- const { ranges, active: activeAggregate } = await aggregateUsageWindows(window);
110
- const realRangeData = {} as Record<Exclude<TimeRangeType, 'custom'>, TokenUsageMetricSet>;
111
- for (const range of PRESET_RANGES) {
112
- realRangeData[range] = toMetricSet(ranges[range], cadence);
113
- }
114
-
115
- const realBreakdown: Record<BreakdownTab, BreakdownRow[]> = {
116
- model: toBreakdownRows(activeAggregate, 'model'),
117
- day: toBreakdownRows(activeAggregate, 'day', cadence),
118
- project: toBreakdownRows(activeAggregate, 'project'),
119
- };
120
- const activeMetrics = toMetricSet(activeAggregate, cadence);
121
- const activeBreakdownRows = realBreakdown[breakdownTab] || [];
122
- const perModelRates = await loadModelRates(
123
- realBreakdown.model.map((row) => row.name),
56
+ const payload = await buildTokenUsagePayload(query);
57
+ return json(payload, { headers: HEADERS });
58
+ } catch (error) {
59
+ // A failure is REPORTED, never rendered as "$0.00 usage": an empty panel
60
+ // claiming zero spend is indistinguishable from a month without work.
61
+ return json(
62
+ { error: error instanceof Error ? error.message : 'Failed to read token usage' },
63
+ { status: 500, headers: HEADERS },
124
64
  );
125
-
126
- return json({
127
- timeRanges: TIME_RANGES,
128
- rangeData: realRangeData,
129
- breakdownData: realBreakdown,
130
- activeMetrics,
131
- activeBreakdownRows,
132
- chartSeries: buildChartSeries(activeAggregate, cadence),
133
- metrics: activeMetrics,
134
- breakdownRows: activeBreakdownRows,
135
- pricing: perModelRates,
136
- timeRange,
137
- breakdownTab,
138
- cadence,
139
- isMock: false,
140
- });
141
- } catch (error: any) {
142
- const zeroBreakdown: Record<BreakdownTab, BreakdownRow[]> = { model: [], day: [], project: [] };
143
- return json({
144
- timeRanges: TIME_RANGES,
145
- rangeData: { today: REAL_ZERO_METRIC, '7d': REAL_ZERO_METRIC, '30d': REAL_ZERO_METRIC, '90d': REAL_ZERO_METRIC, all: REAL_ZERO_METRIC },
146
- breakdownData: zeroBreakdown,
147
- activeMetrics: REAL_ZERO_METRIC,
148
- activeBreakdownRows: [],
149
- chartSeries: [] as ChartSeriesPoint[],
150
- metrics: REAL_ZERO_METRIC,
151
- breakdownRows: [],
152
- timeRange,
153
- breakdownTab,
154
- cadence,
155
- isMock: false,
156
- error: error.message,
157
- });
158
65
  }
159
66
  }
160
67
 
68
+ /**
69
+ * POST — force a re-check of the sessions tree.
70
+ *
71
+ * The panel's Refresh button. It answers with the same payload shape so the
72
+ * client can replace its state in one step.
73
+ */
161
74
  export async function action({ request, params }: ActionFunctionArgs) {
162
- if (request.method === 'POST') {
163
- return json({ success: true, timestamp: new Date().toISOString() });
75
+ if (request.method !== 'POST') return methodNotAllowed({ request, params });
76
+ const url = new URL(request.url);
77
+ const query = readQuery(url);
78
+ if (isMockMode()) return json(mockTokenUsagePayload(query.range), { headers: HEADERS });
79
+ try {
80
+ return json(await buildTokenUsagePayload({ ...query, wait: true, force: true }), { headers: HEADERS });
81
+ } catch (error) {
82
+ return json(
83
+ { error: error instanceof Error ? error.message : 'Failed to read token usage' },
84
+ { status: 500, headers: HEADERS },
85
+ );
164
86
  }
165
- return methodNotAllowed({ request, params });
166
87
  }
@@ -31,6 +31,7 @@ import {
31
31
  writeTerminalInput,
32
32
  } from '@/server/lib/terminal/runtime.server';
33
33
  import { TerminalRuntimeError, type TerminalViewer } from '@/server/lib/terminal/session.server';
34
+ import { frameAccepted } from '@/server/lib/terminal/send-result';
34
35
  import {
35
36
  decodeClientFrame,
36
37
  encodeServerFrame,
@@ -67,11 +68,11 @@ export const terminalWsRoutes = new Elysia({ prefix: '/api/terminal' }).ws('/:te
67
68
  viewer: {
68
69
  send(frame) {
69
70
  try {
70
- // Bun returns -1 when the frame was dropped rather than queued
71
- // (the socket is over its high-water mark). Reporting it lets the
72
- // session close this viewer instead of buffering a PTY's output
73
- // into a socket nobody is reading.
74
- return ws.send(frame) !== -1;
71
+ // Only `0` is a drop; `-1` means "queued, draining". See
72
+ // `send-result.ts` for the measured contract — reading `-1` as
73
+ // failure closed healthy viewers at the first burst, and reading
74
+ // `0` as success left xterm attached to a stream with a hole.
75
+ return frameAccepted(ws.send(frame));
75
76
  } catch {
76
77
  // Socket closed mid-send; the close handler detaches.
77
78
  return false;
@@ -5,6 +5,7 @@ import * as updatesChangelog from '@/server/routes/updates/changelog';
5
5
  import * as updatesCheck from '@/server/routes/updates/check';
6
6
  import * as updatesDesktop from '@/server/routes/updates/desktop';
7
7
  import * as updatesIos from '@/server/routes/updates/ios';
8
+ import * as updatesNotes from '@/server/routes/updates/notes';
8
9
 
9
10
  export const updatesBindings: HandlerBinding[] = [
10
11
  ...bindingsFor(updatesAndroid, '/api/updates/android'),
@@ -13,4 +14,5 @@ export const updatesBindings: HandlerBinding[] = [
13
14
  ...bindingsFor(updatesCheck, '/api/updates/check'),
14
15
  ...bindingsFor(updatesDesktop, '/api/updates/desktop'),
15
16
  ...bindingsFor(updatesIos, '/api/updates/ios'),
17
+ ...bindingsFor(updatesNotes, '/api/updates/notes'),
16
18
  ];
@@ -0,0 +1,34 @@
1
+ import { json, NO_STORE_HEADERS, type LoaderFunctionArgs } from '@/server/lib/remix-compat';
2
+ import { buildActiveReleaseNotes } from '@/server/lib/updates/active-notes';
3
+ import type { UpdateTarget } from '@/shared/types/updates';
4
+
5
+ /**
6
+ * GET /api/updates/notes?target=kabmo|omp — the changelog section for the
7
+ * version this machine is RUNNING.
8
+ *
9
+ * `target` is the only input, and it selects a source, never a version: both
10
+ * versions are read server-side from the install itself, so this endpoint
11
+ * cannot be asked about a release the copy does not have. A payload always
12
+ * carries renderable fields — a failure is an `error`, not a 500 — because the
13
+ * dialog opens from a button inside About.
14
+ */
15
+ function readTarget(value: string | null): UpdateTarget | null {
16
+ return value === 'kabmo' || value === 'omp' ? value : null;
17
+ }
18
+
19
+ export async function loader({ request }: LoaderFunctionArgs) {
20
+ const target = readTarget(new URL(request.url).searchParams.get('target'));
21
+ if (!target) {
22
+ return json({ error: 'Unknown update target' }, { status: 400, headers: NO_STORE_HEADERS });
23
+ }
24
+
25
+ try {
26
+ return json(await buildActiveReleaseNotes(target), { headers: NO_STORE_HEADERS });
27
+ } catch (error) {
28
+ const message = error instanceof Error ? error.message : 'Failed to read release notes';
29
+ return json(
30
+ { target, version: null, note: null, changelogUrl: '', error: message },
31
+ { headers: NO_STORE_HEADERS },
32
+ );
33
+ }
34
+ }
@@ -26,6 +26,7 @@ import { action as applyUpdateRoute } from '@/server/routes/updates/apply';
26
26
  import { invalidateOmpCliCache } from '@/server/lib/omp/core/cli';
27
27
  import { loader as checkRoute } from '@/server/routes/updates/check';
28
28
  import { loader as changelogRoute } from '@/server/routes/updates/changelog';
29
+ import { loader as notesRoute } from '@/server/routes/updates/notes';
29
30
  import { readInstalledVersion } from '@/server/lib/updates/install';
30
31
  import { runningUpdate, withUpdateSlot } from '@/server/lib/updates/single-flight';
31
32
 
@@ -267,3 +268,51 @@ describe('GET /api/updates/changelog', () => {
267
268
  expect(result.error).toBeNull();
268
269
  });
269
270
  });
271
+
272
+ describe('GET /api/updates/notes', () => {
273
+ test('serves the section for the version this install is running', async () => {
274
+ const installed = await readInstalledVersion();
275
+ expect(installed).not.toBeNull();
276
+ globalThis.fetch = (async () =>
277
+ new Response(
278
+ `# Changelog\n\n## [${installed}] — 2026-01-01\n\n* running notes\n`,
279
+ { status: 200, headers: { 'content-type': 'text/markdown' } },
280
+ )) as unknown as typeof fetch;
281
+
282
+ const res = (await notesRoute({
283
+ request: new Request('http://localhost/api/updates/notes?target=kabmo'),
284
+ params: {},
285
+ })) as unknown as Response;
286
+
287
+ expect(res.status).toBe(200);
288
+ expect(res.headers.get('cache-control')).toBe('no-store');
289
+ const result = await payload(res);
290
+ expect(result).toMatchObject({ target: 'kabmo', version: installed, error: null });
291
+ expect(asRecord(result.note).body).toBe('* running notes');
292
+ expect(result.changelogUrl).toBe('https://github.com/kabmo-labs/kabmo/blob/HEAD/CHANGELOG.md');
293
+ });
294
+
295
+ test('an unknown or missing target is a 400, never a guessed source', async () => {
296
+ for (const query of ['', '?target=nope']) {
297
+ const res = (await notesRoute({
298
+ request: new Request(`http://localhost/api/updates/notes${query}`),
299
+ params: {},
300
+ })) as unknown as Response;
301
+ expect(res.status).toBe(400);
302
+ expect((await payload(res)).error).toBe('Unknown update target');
303
+ }
304
+ });
305
+
306
+ test('an install that cannot be read is an error field, not a 500', async () => {
307
+ const res = (await notesRoute({
308
+ request: new Request('http://localhost/api/updates/notes?target=omp'),
309
+ params: {},
310
+ })) as unknown as Response;
311
+
312
+ expect(res.status).toBe(200);
313
+ const result = await payload(res);
314
+ expect(result).toMatchObject({ target: 'omp', version: null, note: null });
315
+ // `KABMO_OMP_BIN` points at a path that cannot exist in `beforeEach`.
316
+ expect(result.error).toBe('omp binary not found');
317
+ });
318
+ });
@@ -0,0 +1,283 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Annotation geometry and prompt text.
8
+ *
9
+ * The failure these cases exist for is a prompt that sends a mark the agent
10
+ * cannot resolve. A percentage alone does not survive: 12% of a 1024px panel
11
+ * and 12% of a 375px panel are different places, and a mark dragged
12
+ * bottom-right-to-top-left has to describe the same box as one dragged the
13
+ * other way. Measured geometry, not rounded pixels, is what the agent re-opens
14
+ * the page with.
15
+ */
16
+
17
+ import { describe, expect, test } from 'bun:test';
18
+
19
+ import { clamp01, describeAnnotations, describeShape, isUsableShape, normalizePoint, readAnnotatePanel, readAnnotationShapes, shapeRegion } from '@/shared/lib/browser/annotate';
20
+ import { appendPageContext, formatPageContextBlock } from '@/shared/lib/browser/page-context';
21
+ import type { AnnotateShape } from '@/shared/types';
22
+
23
+ const PANEL = { width: 1024, height: 768 };
24
+
25
+ function shape(overrides: Partial<AnnotateShape> = {}): AnnotateShape {
26
+ return {
27
+ id: 'a1',
28
+ tool: 'box',
29
+ start: { x: 0.1, y: 0.2 },
30
+ end: { x: 0.3, y: 0.35 },
31
+ label: '',
32
+ note: '',
33
+ ...overrides,
34
+ };
35
+ }
36
+
37
+ describe('normalizePoint', () => {
38
+ test('expresses a pointer position as a fraction of the measured box', () => {
39
+ expect(normalizePoint(PANEL, { x: 256, y: 384 })).toEqual({ x: 0.25, y: 0.5 });
40
+ });
41
+
42
+ test('clamps a drag that leaves the panel instead of storing an out-of-range point', () => {
43
+ expect(normalizePoint(PANEL, { x: -40, y: 900 })).toEqual({ x: 0, y: 1 });
44
+ });
45
+
46
+ test('an unmeasured panel answers a zero point rather than NaN', () => {
47
+ expect(normalizePoint({ width: 0, height: 0 }, { x: 10, y: 10 })).toEqual({ x: 0, y: 0 });
48
+ });
49
+ });
50
+
51
+ describe('clamp01', () => {
52
+ test('keeps a fraction, clamps the ends and refuses a non-number', () => {
53
+ expect([clamp01(0.42), clamp01(-1), clamp01(2), clamp01(Number.NaN)]).toEqual([0.42, 0, 1, 0]);
54
+ });
55
+ });
56
+
57
+ describe('shapeRegion', () => {
58
+ test('a box dragged bottom-right to top-left has the same region as one dragged forward', () => {
59
+ const forward = shapeRegion({ start: { x: 0.1, y: 0.2 }, end: { x: 0.3, y: 0.35 } });
60
+ const backward = shapeRegion({ start: { x: 0.3, y: 0.35 }, end: { x: 0.1, y: 0.2 } });
61
+ expect(backward).toEqual(forward);
62
+ expect(forward.x).toBeCloseTo(0.1, 6);
63
+ expect(forward.width).toBeCloseTo(0.2, 6);
64
+ });
65
+ });
66
+
67
+ describe('isUsableShape', () => {
68
+ test('a click with no drag is not a mark', () => {
69
+ expect(isUsableShape({ start: { x: 0.5, y: 0.5 }, end: { x: 0.5, y: 0.5 }, note: '' })).toBe(false);
70
+ });
71
+
72
+ test('a note makes even a bare click worth sending', () => {
73
+ expect(isUsableShape({ start: { x: 0.5, y: 0.5 }, end: { x: 0.5, y: 0.5 }, note: 'tombol mati' })).toBe(true);
74
+ });
75
+
76
+ test('a dragged region counts without a note', () => {
77
+ expect(isUsableShape(shape())).toBe(true);
78
+ });
79
+ });
80
+
81
+ describe('describeShape', () => {
82
+ test('a box states the region in percent AND the pixel size the panel size makes resolvable', () => {
83
+ expect(describeShape(shape({ note: 'total harga terpotong' }), 1, PANEL))
84
+ .toBe('1. kotak kiri 10.0%, atas 20.0%, lebar 20.0%, tinggi 15.0% (205×115 px) — total harga terpotong');
85
+ });
86
+
87
+ test('a pin states one point, an arrow states where it points', () => {
88
+ expect(describeShape(shape({ tool: 'pin', note: 'badge salah' }), 2, PANEL))
89
+ .toBe('2. titik di (10.0%, 20.0%) (102×154 px) — badge salah');
90
+ expect(describeShape(shape({ tool: 'arrow', end: { x: 0.72, y: 0.185 } }), 3, PANEL))
91
+ .toBe('3. panah (10.0%, 20.0%) → (72.0%, 18.5%)');
92
+ });
93
+
94
+ test('a mark with no note ends at the geometry, with no dangling separator', () => {
95
+ expect(describeShape(shape(), 1, PANEL).endsWith('px)')).toBe(true);
96
+ });
97
+ });
98
+
99
+ describe('describeAnnotations', () => {
100
+ test('numbers from 1 in draw order and drops the unusable marks', () => {
101
+ const lines = describeAnnotations([
102
+ shape({ id: 'a', note: 'satu' }),
103
+ shape({ id: 'b', start: { x: 0.5, y: 0.5 }, end: { x: 0.5, y: 0.5 } }),
104
+ shape({ id: 'c', tool: 'pin', start: { x: 0.9, y: 0.1 }, end: { x: 0.9, y: 0.1 }, note: 'tiga' }),
105
+ ], PANEL);
106
+ expect(lines).toHaveLength(2);
107
+ expect(lines[0]?.startsWith('1. kotak')).toBe(true);
108
+ expect(lines[1]?.startsWith('2. titik')).toBe(true);
109
+ });
110
+ });
111
+
112
+ describe('readAnnotationShapes', () => {
113
+ test('keeps a well-formed mark', () => {
114
+ expect(readAnnotationShapes([shape()])).toEqual([shape()]);
115
+ });
116
+
117
+ test('drops a mark whose points are not numbers, instead of rendering NaN%', () => {
118
+ expect(readAnnotationShapes([{ id: 'x', tool: 'box', start: { x: 'a', y: 0 }, end: { x: 1, y: 1 } }])).toBeNull();
119
+ });
120
+
121
+ test('drops an unknown tool', () => {
122
+ expect(readAnnotationShapes([{ id: 'x', tool: 'lasso', start: { x: 0, y: 0 }, end: { x: 1, y: 1 } }])).toBeNull();
123
+ });
124
+
125
+ test('clamps points that arrive outside the panel', () => {
126
+ const parsed = readAnnotationShapes([{ id: 'x', tool: 'pin', start: { x: -5, y: 9 }, end: { x: -5, y: 9 } }]);
127
+ expect(parsed?.[0]?.start).toEqual({ x: 0, y: 1 });
128
+ });
129
+
130
+ test('a non-array is not a mark list', () => {
131
+ expect(readAnnotationShapes('nope')).toBeNull();
132
+ });
133
+ });
134
+
135
+ describe('readAnnotatePanel', () => {
136
+ test('reads a measured box', () => {
137
+ expect(readAnnotatePanel({ width: 1024, height: 768, viewportMode: 'laptop', zoom: 150 }))
138
+ .toEqual({ width: 1024, height: 768, viewportMode: 'laptop', zoom: 150 });
139
+ });
140
+
141
+ test('an unmeasured box is refused, because percentages against it mean nothing', () => {
142
+ expect(readAnnotatePanel({ width: 0, height: 400 })).toBeNull();
143
+ });
144
+
145
+ test('missing optional fields fall back to a responsive, unzoomed panel', () => {
146
+ expect(readAnnotatePanel({ width: 10, height: 20 })).toEqual({ width: 10, height: 20, viewportMode: 'responsive', zoom: 100 });
147
+ });
148
+ });
149
+
150
+ describe('formatPageContextBlock', () => {
151
+ test('a page with no marks keeps the shape the panel has always produced', () => {
152
+ expect(formatPageContextBlock({ url: 'https://a.test/x', title: 'A' })).toBe([
153
+ '[Konteks halaman browser]',
154
+ 'URL: https://a.test/x',
155
+ 'Judul: A',
156
+ '(Lanjutkan dari halaman ini.)',
157
+ ].join('\n'));
158
+ });
159
+
160
+ test('marks add a numbered list, the panel shape, and the user-only warning', () => {
161
+ const block = formatPageContextBlock({
162
+ url: 'http://localhost:5173/checkout',
163
+ panel: { width: 1024, height: 768, viewportMode: 'laptop', zoom: 100 },
164
+ annotations: [shape({ note: 'tombol Bayar nonaktif' })],
165
+ });
166
+ expect(block).toContain('Panel: laptop 1024×768 px @100%');
167
+ expect(block).toContain('Anotasi (1):\n1. kotak');
168
+ expect(block).toContain('hanya terlihat oleh user');
169
+ });
170
+
171
+ test('a panel size with only unusable marks sends no annotation section at all', () => {
172
+ const block = formatPageContextBlock({
173
+ url: 'https://a.test',
174
+ panel: { width: 100, height: 100, viewportMode: 'responsive', zoom: 100 },
175
+ annotations: [shape({ start: { x: 0.4, y: 0.4 }, end: { x: 0.4, y: 0.4 } })],
176
+ });
177
+ expect(block).not.toContain('Anotasi');
178
+ });
179
+ });
180
+
181
+ describe('appendPageContext', () => {
182
+ test('a blank draft receives the block alone', () => {
183
+ expect(appendPageContext('', { url: 'https://a.test' }).startsWith('[Konteks halaman browser]')).toBe(true);
184
+ });
185
+
186
+ test('existing text is separated by exactly one blank line', () => {
187
+ expect(appendPageContext('halo', { url: 'https://a.test' })).toBe(
188
+ 'halo\n\n[Konteks halaman browser]\nURL: https://a.test\n(Lanjutkan dari halaman ini.)',
189
+ );
190
+ });
191
+
192
+ test('a draft already ending in a blank line does not gain a third', () => {
193
+ expect(appendPageContext('halo\n\n', { url: 'https://a.test' })).toContain('halo\n\n[Konteks');
194
+ expect(appendPageContext('halo\n\n', { url: 'https://a.test' })).not.toContain('halo\n\n\n');
195
+ });
196
+ });
197
+
198
+ describe('label on a mark', () => {
199
+ test('a named region leads the line, so the agent knows WHAT before WHERE', () => {
200
+ expect(describeShape(shape({ label: 'Ringkasan pesanan', note: 'total terpotong' }), 1, PANEL))
201
+ .toBe('1. bagian "Ringkasan pesanan" — kotak kiri 10.0%, atas 20.0%, lebar 20.0%, tinggi 15.0% (205×115 px) — total terpotong');
202
+ });
203
+
204
+ test('an unnamed mark keeps exactly the line it produced before labels existed', () => {
205
+ expect(describeShape(shape(), 1, PANEL))
206
+ .toBe('1. kotak kiri 10.0%, atas 20.0%, lebar 20.0%, tinggi 15.0% (205×115 px)');
207
+ });
208
+
209
+ test('a label alone makes a zero-size mark worth sending', () => {
210
+ expect(isUsableShape({ start: { x: 0.5, y: 0.5 }, end: { x: 0.5, y: 0.5 }, note: '', label: 'modal' })).toBe(true);
211
+ });
212
+
213
+ test('a whitespace-only label is not a name', () => {
214
+ expect(isUsableShape({ start: { x: 0.5, y: 0.5 }, end: { x: 0.5, y: 0.5 }, note: '', label: ' ' })).toBe(false);
215
+ });
216
+ });
217
+
218
+ describe('element on a mark', () => {
219
+ const select = {
220
+ path: 'section[aria-label="Ringkasan"] > form > select#prov',
221
+ tag: 'select',
222
+ state: 'nilai "Jawa Barat", 5 opsi',
223
+ text: 'Provinsi',
224
+ };
225
+
226
+ test('a readable element adds its path, state and text after the geometry', () => {
227
+ const line = describeShape(shape({ element: select }), 1, PANEL);
228
+ expect(line).toContain('[elemen: section[aria-label="Ringkasan"] > form > select#prov');
229
+ expect(line).toContain('nilai "Jawa Barat", 5 opsi');
230
+ expect(line).toContain('teks "Provinsi"');
231
+ // The note still ends the line, after the element facts.
232
+ expect(line.endsWith('px) [elemen:')).toBe(false);
233
+ });
234
+
235
+ test('an unreadable mark says nothing about elements rather than printing an empty one', () => {
236
+ expect(describeShape(shape(), 1, PANEL)).not.toContain('elemen');
237
+ });
238
+
239
+ test('role is stated when the element declares one', () => {
240
+ const line = describeShape(shape({ element: { path: 'div > div', tag: 'div', role: 'dialog' } }), 2, PANEL);
241
+ expect(line).toContain('role dialog');
242
+ });
243
+ });
244
+
245
+ describe('readAnnotationShapes with the new fields', () => {
246
+ test('carries label and element through', () => {
247
+ const parsed = readAnnotationShapes([{
248
+ id: 'a', tool: 'pin', start: { x: 0.2, y: 0.3 }, end: { x: 0.2, y: 0.3 },
249
+ label: 'form', note: 'kosong',
250
+ element: { path: 'body > form', tag: 'form', state: 'nonaktif' },
251
+ }]);
252
+ expect(parsed?.[0]?.label).toBe('form');
253
+ expect(parsed?.[0]?.element).toEqual({ path: 'body > form', tag: 'form', state: 'nonaktif' });
254
+ });
255
+
256
+ test('a malformed element is dropped, and the mark survives with its label', () => {
257
+ const parsed = readAnnotationShapes([{
258
+ id: 'a', tool: 'pin', start: { x: 0.2, y: 0.3 }, end: { x: 0.2, y: 0.3 },
259
+ label: 'form', note: '',
260
+ element: { path: '', tag: 'form' },
261
+ }]);
262
+ expect(parsed?.[0]?.element).toBeUndefined();
263
+ expect(parsed?.[0]?.label).toBe('form');
264
+ });
265
+ });
266
+
267
+ describe('viewport resolution hint', () => {
268
+ const base = {
269
+ url: 'https://a.test',
270
+ panel: { width: 276, height: 620, viewportMode: 'laptop', zoom: 110 },
271
+ annotations: [shape({ note: 'mati' })],
272
+ };
273
+
274
+ test('the block states the viewport the coordinates are fractions of', () => {
275
+ const block = formatPageContextBlock(base);
276
+ expect(block).toContain('Koordinat relatif ke viewport 276×620 px');
277
+ expect(block).toContain('cari elemennya di titik itu');
278
+ });
279
+
280
+ test('the hint belongs to an annotated page, not to a plain one', () => {
281
+ expect(formatPageContextBlock({ url: 'https://a.test' })).not.toContain('Koordinat relatif');
282
+ });
283
+ });