@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
@@ -24,6 +24,7 @@ import {
24
24
  import { SCHEMA_EXTRAS } from '@/shared/lib/omp/config/schema-extras';
25
25
  import { ALL_SCHEMA_ENTRIES, OMP_SCHEMA, configValue, entriesForTab, isConditionMet, matchesSearch } from '@/shared/lib/omp/config/schema';
26
26
  import type { ConfigEntry } from '@/server/lib/omp/config/config-cli';
27
+ import type { SchemaEntry } from '@/shared/lib/omp/config/schema-types';
27
28
 
28
29
  /** Build a config snapshot from `{ key: value }` pairs. */
29
30
  function snapshot(values: Record<string, unknown>): Record<string, ConfigEntry> {
@@ -86,6 +87,44 @@ describe('OMP_SCHEMA', () => {
86
87
  expect(entry?.ui.tab).toBe('interaction');
87
88
  expect(entry?.ui.group).toBe('Approvals');
88
89
  });
90
+
91
+ test('the rows omp 18.15.0 adds are offered', () => {
92
+ // Measured against `omp config list --json` on 18.15.0: all four exist and
93
+ // every one accepts a write through `omp config set`. A schema regenerated
94
+ // without them is a release of settings the panel cannot reach.
95
+ const expected: Record<string, { type: SchemaEntry['type']; tab: string; group: string }> = {
96
+ 'providers.openai-codex.daybreak': { type: 'boolean', tab: 'providers', group: 'Protocol' },
97
+ 'task.perCallModel': { type: 'enum', tab: 'tasks', group: 'Subagents' },
98
+ 'task.perCallModelAllow': { type: 'array', tab: 'tasks', group: 'Subagents' },
99
+ 'title.refreshAfterPrompts': { type: 'number', tab: 'tasks', group: 'Modes' },
100
+ };
101
+ for (const [key, want] of Object.entries(expected)) {
102
+ const entry = OMP_SCHEMA.entries[key];
103
+ expect({ key, entry: entry && { type: entry.type, tab: entry.ui.tab, group: entry.ui.group } }).toEqual({
104
+ key,
105
+ entry: want,
106
+ });
107
+ }
108
+ });
109
+
110
+ test('the rows omp 18.16.0 adds are offered', () => {
111
+ // Measured against `omp config list --json` on 18.16.0: all three exist and
112
+ // `omp config get` answers each. Two are TUI-composer features Kabmo has no
113
+ // surface for, but the panel is the only place a user CAN reach an omp
114
+ // setting, so a regenerated schema that drops them removes the row entirely.
115
+ const expected: Record<string, { type: SchemaEntry['type']; tab: string; group: string }> = {
116
+ 'btw.inject': { type: 'boolean', tab: 'interaction', group: 'Input' },
117
+ 'composer.predictionAlternatives': { type: 'boolean', tab: 'interaction', group: 'Input' },
118
+ 'hindsight.globalScope': { type: 'boolean', tab: 'memory', group: 'Hindsight' },
119
+ };
120
+ for (const [key, want] of Object.entries(expected)) {
121
+ const entry = OMP_SCHEMA.entries[key];
122
+ expect({ key, entry: entry && { type: entry.type, tab: entry.ui.tab, group: entry.ui.group } }).toEqual({
123
+ key,
124
+ entry: want,
125
+ });
126
+ }
127
+ });
89
128
  });
90
129
 
91
130
  describe('ALL_SCHEMA_ENTRIES', () => {
@@ -160,9 +199,36 @@ describe('isConditionMet', () => {
160
199
  expect(isConditionMet('hasImageProtocol', {})).toBe(true);
161
200
  });
162
201
 
202
+ test('the prediction-alternatives row follows composer predictions (omp 18.16.0)', () => {
203
+ // Upstream: `cfgComposerPredictionAlternatives` is gated on
204
+ // `cfgComposerPredictions.get(s) === true`. Falling through to the default
205
+ // arm would keep the modifier row visible with its parent switched off.
206
+ expect(isConditionMet('composerPredictionsEnabled', snapshot({ 'composer.predictions': true }))).toBe(true);
207
+ expect(isConditionMet('composerPredictionsEnabled', snapshot({ 'composer.predictions': false }))).toBe(false);
208
+ expect(isConditionMet('composerPredictionsEnabled', {})).toBe(false);
209
+ // And the row really is the one carrying that condition.
210
+ expect(OMP_SCHEMA.entries['composer.predictionAlternatives']?.ui.condition).toBe('composerPredictionsEnabled');
211
+ expect(OMP_SCHEMA.entries['composer.predictions']?.ui.condition).toBeUndefined();
212
+ });
213
+
163
214
  test('an unknown condition degrades to visible', () => {
164
215
  expect(isConditionMet('someFutureCondition', {})).toBe(true);
165
216
  });
217
+
218
+ test('the provenance conditions degrade to visible, deliberately', () => {
219
+ // These three hide an editor row when a PROJECT layer supplies the value,
220
+ // because the editor writes the GLOBAL layer and promoting a repository's
221
+ // list would be the bug. `omp config list --json` carries no provenance, so
222
+ // the client cannot answer them — visible is the decision, not an oversight.
223
+ // `perCallModelAllowNotProject` arrived with 18.15.0's `task.perCallModelAllow`.
224
+ for (const condition of [
225
+ 'contextFilesExtraNotProject',
226
+ 'restrictedFoldersNotProject',
227
+ 'perCallModelAllowNotProject',
228
+ ]) {
229
+ expect({ condition, met: isConditionMet(condition, {}) }).toEqual({ condition, met: true });
230
+ }
231
+ });
166
232
  });
167
233
 
168
234
  describe('entriesForTab', () => {
@@ -55,6 +55,12 @@ export function isConditionMet(condition: string | undefined, entries: Record<st
55
55
  return configValue(entries, 'retry.usageAwareFallback') === true;
56
56
  case 'planModeEnabled':
57
57
  return configValue(entries, 'plan.enabled') === true;
58
+ // omp 18.16.0's `composer.predictionAlternatives` hangs off this one: the
59
+ // alternatives row is a modifier of composer predictions, and offering it
60
+ // while predictions are off would present a setting the user cannot reach
61
+ // a use for. Upstream evaluates `cfgComposerPredictions.get(s) === true`.
62
+ case 'composerPredictionsEnabled':
63
+ return configValue(entries, 'composer.predictions') === true;
58
64
  case 'planAutosaveEnabled':
59
65
  return configValue(entries, 'plan.enabled') === true && configValue(entries, 'plan.autosave') === true;
60
66
  case 'unexpectedStopSmart':
@@ -8,19 +8,21 @@
8
8
  *
9
9
  * Framing bugs are silent data corruption: a frame read as two lines, or a
10
10
  * chunk sequence reassembled with the wrong bytes, reaches the session wrapper
11
- * as a plausible-looking but wrong event. These tests pin the length boundary
12
- * that selects single-line vs chunked encoding, the exact chunk sequence
13
- * bookkeeping (ordering, count, declared byte length), the strict base64 and
14
- * UTF-8 decoding, and the failure modes that must reject rather than guess.
11
+ * as a plausible-looking but wrong event. These tests pin the OUTBOUND rule
12
+ * (one line, never chunked — omp does not reassemble what Kabmo writes), the
13
+ * inbound chunk bookkeeping (ordering, count, declared byte length), the strict
14
+ * base64 and UTF-8 decoding, and the failure modes that must reject rather than
15
+ * guess.
15
16
  */
16
17
 
17
18
  import { describe, expect, test } from 'bun:test';
18
19
 
19
20
  import {
21
+ MAX_OUTBOUND_FRAME_BYTES,
20
22
  MAX_RPC_FRAME_BYTES,
21
23
  MAX_RPC_REASSEMBLED_BYTES,
22
24
  RpcFrameDecoder,
23
- encodeRpcFrames,
25
+ encodeRpcFrameLine,
24
26
  type RpcFrameRecord,
25
27
  } from '@/shared/lib/omp/rpc/frame';
26
28
 
@@ -36,6 +38,21 @@ function chunk(overrides: Record<string, unknown>): Record<string, unknown> {
36
38
  return { type: 'rpc_chunk', chunkId: 'c1', index: 0, count: 2, byteLength: MAX_RPC_FRAME_BYTES, data: 'AAAA', ...overrides };
37
39
  }
38
40
 
41
+ /** A complete inbound `rpc_chunk` sequence for `frame`, the shape omp emits.
42
+ * Kabmo never writes one (see `encodeRpcFrameLine`), so the test owns it. */
43
+ function chunkSequence(frame: RpcFrameRecord, chunkId: string): Record<string, unknown>[] {
44
+ const bytes = new TextEncoder().encode(JSON.stringify(frame));
45
+ const count = Math.ceil(bytes.byteLength / (256 * 1024));
46
+ return Array.from({ length: count }, (_, index) => ({
47
+ type: 'rpc_chunk',
48
+ chunkId,
49
+ index,
50
+ count,
51
+ byteLength: bytes.byteLength,
52
+ data: bytes.subarray(index * 256 * 1024, (index + 1) * 256 * 1024).toBase64(),
53
+ }));
54
+ }
55
+
39
56
  describe('transport limits', () => {
40
57
  test('the frame and reassembly ceilings are the documented values', () => {
41
58
  expect(MAX_RPC_FRAME_BYTES).toBe(1024 * 1024);
@@ -43,54 +60,27 @@ describe('transport limits', () => {
43
60
  });
44
61
  });
45
62
 
46
- describe('encodeRpcFrames — single-line path', () => {
63
+ describe('encodeRpcFrameLine — one line, never chunked', () => {
47
64
  test('a small frame is one JSON line terminated by a newline', () => {
48
65
  const frame = { type: 'ready', n: 1 };
49
- expect(encodeRpcFrames(frame, 1, 'chunk')).toEqual([`${JSON.stringify(frame)}\n`]);
50
- });
51
-
52
- test('the exact boundary is a frame whose JSON is MAX-1 bytes (plus newline = MAX)', () => {
53
- const frame = frameOfBytes(MAX_RPC_FRAME_BYTES - 1);
54
- const lines = encodeRpcFrames(frame, 1, 'chunk');
55
- expect(lines.length).toBe(1);
56
- expect(lines[0].length).toBe(MAX_RPC_FRAME_BYTES);
57
- });
58
-
59
- test('one byte over the boundary stops being a single line', () => {
60
- const frame = frameOfBytes(MAX_RPC_FRAME_BYTES);
61
- // v1 has no fallback: an oversized frame is a hard error.
62
- expect(() => encodeRpcFrames(frame, 1, 'chunk')).toThrow('RPC frame exceeds the v1 transport limit');
66
+ expect(encodeRpcFrameLine(frame)).toBe(`${JSON.stringify(frame)}\n`);
63
67
  });
64
- });
65
68
 
66
- describe('encodeRpcFrames — v2 chunking', () => {
67
- test('an oversized frame becomes a contiguous chunk sequence that round-trips', () => {
69
+ test('a frame ABOVE the inbound frame limit is still a single line', () => {
70
+ // The regression this pins: a >1 MiB prompt (any real screenshot) used to be
71
+ // split into `rpc_chunk` records, which omp's rpc-ui stdin loop rejects with
72
+ // `Unknown command: rpc_chunk` — the prompt was never dispatched and the
73
+ // session was reset on ack timeout.
68
74
  const frame = frameOfBytes(MAX_RPC_FRAME_BYTES + 5_000);
69
- const lines = encodeRpcFrames(frame, 2, 'chunk-1');
70
- const payload = new TextEncoder().encode(JSON.stringify(frame));
71
- const expectedCount = Math.ceil(payload.byteLength / (256 * 1024));
72
- expect(lines.length).toBe(expectedCount);
73
-
74
- const decoder = new RpcFrameDecoder();
75
- const records = lines.map((line) => JSON.parse(line));
76
- for (let i = 0; i < records.length; i++) {
77
- expect(records[i].type).toBe('rpc_chunk');
78
- expect(records[i].chunkId).toBe('chunk-1');
79
- expect(records[i].index).toBe(i);
80
- expect(records[i].count).toBe(expectedCount);
81
- expect(records[i].byteLength).toBe(payload.byteLength);
82
- expect(lines[i].endsWith('\n')).toBe(true);
83
- // Every push before the last must yield nothing — the decoder is holding
84
- // an incomplete logical frame.
85
- const out = decoder.push(records[i]);
86
- if (i < records.length - 1) expect(out).toBeUndefined();
87
- else expect(out).toEqual(frame);
88
- }
75
+ const line = encodeRpcFrameLine(frame);
76
+ expect(line.endsWith('\n')).toBe(true);
77
+ expect(line.indexOf('\n')).toBe(line.length - 1);
78
+ expect(JSON.parse(line)).toEqual(frame);
89
79
  });
90
80
 
91
- test('a frame over the reassembly ceiling is refused before chunking', () => {
92
- const frame = { type: 'x', pad: 'A'.repeat(MAX_RPC_REASSEMBLED_BYTES) };
93
- expect(() => encodeRpcFrames(frame, 2, 'chunk')).toThrow('RPC frame exceeds the v2 reassembly limit');
81
+ test('a frame over the outbound ceiling is refused instead of chunked', () => {
82
+ const frame = { type: 'x', pad: 'A'.repeat(MAX_OUTBOUND_FRAME_BYTES) };
83
+ expect(() => encodeRpcFrameLine(frame)).toThrow('exceeds the');
94
84
  });
95
85
  });
96
86
 
@@ -232,10 +222,21 @@ describe('RpcFrameDecoder — sequence bookkeeping', () => {
232
222
  expect(() => decoder.push({ type: 'rpc_chunk', ...base, index: 3, data: last })).toThrow();
233
223
  });
234
224
 
225
+ test('an inbound sequence reassembles to the frame omp emitted', () => {
226
+ // omp → Kabmo is the direction that DOES chunk, so the decoder must keep
227
+ // reassembling: an oversized event (a big tool result) arrives this way.
228
+ const frame = frameOfBytes(MAX_RPC_FRAME_BYTES + 5_000);
229
+ const decoder = new RpcFrameDecoder();
230
+ const records = chunkSequence(frame, 'chunk-1');
231
+ expect(records.length).toBeGreaterThan(1);
232
+ for (const record of records.slice(0, -1)) expect(decoder.push(record)).toBeUndefined();
233
+ expect(decoder.push(records.at(-1))).toEqual(frame);
234
+ });
235
+
235
236
  test('a fresh sequence can start after a completed one', () => {
236
237
  const decoder = new RpcFrameDecoder();
237
238
  const frame = frameOfBytes(MAX_RPC_FRAME_BYTES + 1_000);
238
- for (const line of encodeRpcFrames(frame, 2, 'a')) decoder.push(JSON.parse(line));
239
+ for (const record of chunkSequence(frame, 'a')) decoder.push(record);
239
240
  expect(decoder.push({ type: 'ready' })).toEqual({ type: 'ready' });
240
241
  });
241
242
  });
@@ -4,12 +4,25 @@
4
4
  */
5
5
 
6
6
  /**
7
- * Bounded protocol-v2 framing for OMP's NDJSON RPC transport.
7
+ * NDJSON framing for OMP's RPC transport, in both directions.
8
8
  *
9
- * Faithful port of omp-web/lib/omp/rpc-frame.ts. Logical RPC frames are
10
- * carried as single JSONL lines when small; frames larger than the transport
11
- * limit are split into `rpc_chunk` sequences (base64 payloads) and
12
- * reassembled on the receiving side.
9
+ * The two directions are NOT symmetric, and treating them as if they were is
10
+ * what silently dropped every prompt carrying a real image:
11
+ *
12
+ * - **omp → Kabmo** frames are bounded at `MAX_RPC_FRAME_BYTES`; under protocol
13
+ * v2 (`negotiate_protocol`) a larger event arrives as an `rpc_chunk`
14
+ * sequence, which `RpcFrameDecoder` reassembles.
15
+ * - **Kabmo → omp** frames must go out as ONE line, however long. omp
16
+ * advertises protocol v2 and acks the negotiation, but its rpc-ui stdin loop
17
+ * has no `rpc_chunk` handler: measured against omp 18.14.0 and 18.16.0, every
18
+ * chunk came back `{success:false,error:"Unknown command: rpc_chunk"}` and the
19
+ * prompt was never dispatched — 6 records for a 1.3 MB image, no `agent_start`,
20
+ * no ack, and Kabmo reset the session after `PROMPT_ACK_TIMEOUT_MS`. A single
21
+ * 30 MB line for the same image is accepted and acked in ~26 s, so the limit
22
+ * here is a guard against unbounded writes, not a transport limit.
23
+ *
24
+ * Hence: one encoder (`encodeRpcFrameLine`) that never chunks, and a decoder
25
+ * that still understands chunks.
13
26
  */
14
27
 
15
28
  import { isRecord } from '@/shared/lib/util/guards';
@@ -35,26 +48,15 @@ function isSafeInteger(value: unknown): value is number {
35
48
  }
36
49
 
37
50
  /**
38
- * One encoder for every length check on this path.
51
+ * The byte-length probe for an outbound frame.
39
52
  *
40
- * `encode()` allocates a throwaway array just to read `.byteLength`, and this
41
- * runs once per frame written to the child's stdin — every `message_update`,
42
- * every steer, every tool result. Hoisting it measured 17.2 ms → 8.6 ms per
43
- * 200k checks. A hoisted encoder rather than `Buffer.byteLength` because this
44
- * module is in `src/shared/` and is therefore browser-safe: `Buffer` is not.
53
+ * A hoisted encoder rather than `Buffer.byteLength` because this module is in
54
+ * `src/shared/` and is therefore browser-safe: `Buffer` is not.
45
55
  */
46
56
  const utf8 = new TextEncoder();
47
57
  /** Strict decoder for reassembled chunk payloads — a truncated sequence is an error. */
48
58
  const fatalUtf8 = new TextDecoder('utf-8', { fatal: true });
49
59
 
50
- function utf8ByteLength(value: string): number {
51
- return utf8.encode(value).byteLength;
52
- }
53
-
54
- function lineByteLength(value: string): number {
55
- return utf8ByteLength(value) + 1;
56
- }
57
-
58
60
  /** Strict base64 decode (canonical padding + round-trip equality). */
59
61
  function decodeBase64(value: unknown): Uint8Array {
60
62
  if (
@@ -125,27 +127,34 @@ export class RpcFrameDecoder {
125
127
  }
126
128
  }
127
129
 
128
- /** Physical JSONL records for a logical RPC frame at the selected protocol. */
129
- export function encodeRpcFrames(frame: RpcFrameRecord, protocolVersion: RpcProtocolVersion, chunkId: string): string[] {
130
+ /**
131
+ * Largest logical frame Kabmo will WRITE to an omp child, as one JSONL line.
132
+ *
133
+ * omp reads its command loop line by line, so this is only a guard against an
134
+ * unbounded write (a runaway attachment, a corrupted payload) — not a
135
+ * transport limit. Measured: a 30 MB prompt line is accepted and acked in
136
+ * ~26 s, while the same payload split into `rpc_chunk`s is rejected outright.
137
+ * The ceiling matches the reassembly limit omp advertises for the other
138
+ * direction (`maxReassembledFrameBytes`), so neither side can claim a payload
139
+ * the other refuses.
140
+ */
141
+ export const MAX_OUTBOUND_FRAME_BYTES = MAX_RPC_REASSEMBLED_BYTES;
142
+
143
+ /**
144
+ * One physical JSONL line for a logical RPC frame.
145
+ *
146
+ * NEVER chunked, whatever `negotiate_protocol` answered: omp's rpc-ui stdin
147
+ * loop answers `Unknown command: rpc_chunk` to every chunk record (verified on
148
+ * 18.14.0 and 18.16.0) and the command is then never dispatched — a prompt
149
+ * carrying a >1 MiB image sat unacked until the ack timeout reset the session.
150
+ * The refusal is thrown at the caller instead, so a payload omp would drop is
151
+ * reported rather than silently lost.
152
+ */
153
+ export function encodeRpcFrameLine(frame: RpcFrameRecord): string {
130
154
  const json = JSON.stringify(frame);
131
- // Encode once and keep the bytes: the length check needs them either way, and
132
- // the oversized path below needs them again. Previously this encoded the
133
- // whole frame to measure it, discarded that array, then encoded it a second
134
- // time to slice it.
135
- const bytes = utf8.encode(json);
136
- if (bytes.byteLength + 1 <= MAX_RPC_FRAME_BYTES) return [`${json}\n`];
137
- if (protocolVersion === 1) throw new Error('RPC frame exceeds the v1 transport limit');
138
- if (bytes.byteLength > MAX_RPC_REASSEMBLED_BYTES) throw new Error('RPC frame exceeds the v2 reassembly limit');
139
- const count = Math.ceil(bytes.byteLength / RPC_CHUNK_PAYLOAD_BYTES);
140
- const lines: string[] = [];
141
- for (let index = 0; index < count; index++) {
142
- const chunk = {
143
- type: 'rpc_chunk', chunkId, index, count, byteLength: bytes.byteLength,
144
- data: bytes.subarray(index * RPC_CHUNK_PAYLOAD_BYTES, (index + 1) * RPC_CHUNK_PAYLOAD_BYTES).toBase64(),
145
- };
146
- const line = JSON.stringify(chunk);
147
- if (lineByteLength(line) > MAX_RPC_FRAME_BYTES) throw new Error('RPC chunk exceeds the transport limit');
148
- lines.push(`${line}\n`);
155
+ const bytes = utf8.encode(json).byteLength + 1;
156
+ if (bytes > MAX_OUTBOUND_FRAME_BYTES) {
157
+ throw new Error(`RPC frame of ${bytes} bytes exceeds the ${MAX_OUTBOUND_FRAME_BYTES}-byte outbound limit`);
149
158
  }
150
- return lines;
159
+ return `${json}\n`;
151
160
  }
@@ -10,7 +10,7 @@
10
10
  */
11
11
 
12
12
  import { describe, expect, test } from 'bun:test';
13
- import { jobProgressLine, jobProgressParts } from '@/shared/lib/omp/session/job-progress';
13
+ import { jobSubject, jobProgressLine, jobProgressParts } from '@/shared/lib/omp/session/job-progress';
14
14
 
15
15
  const RUNNING = {
16
16
  status: 'running',
@@ -74,3 +74,39 @@ describe('jobProgressLine', () => {
74
74
  expect(jobProgressLine({ status: 'failed', requests: 12 })).toBeUndefined();
75
75
  });
76
76
  });
77
+
78
+ /**
79
+ * omp 18.15.0 records the caller's `i` intent on the job and leads its own
80
+ * `/jobs` rows with it. Measured with the release's own `snapshotJobs`, given a
81
+ * bash job whose call carried `intent: "Start the dev server"`:
82
+ *
83
+ * [{ id: 'bg_1', type: 'bash', status: 'running', label: 'bun run dev',
84
+ * intent: 'Start the dev server', durationMs: 42000 }]
85
+ *
86
+ * The label is still the raw command line, so both lines are drawn: the purpose
87
+ * as the subject, the command beneath it.
88
+ */
89
+ describe('jobSubject', () => {
90
+ test('leads with the model\'s intent and keeps the command beneath', () => {
91
+ expect(jobSubject({ intent: 'Start the dev server', label: 'bun run dev' })).toEqual({
92
+ primary: 'Start the dev server',
93
+ secondary: 'bun run dev',
94
+ });
95
+ });
96
+
97
+ test('a row without an intent falls back to its label alone', () => {
98
+ // Every `task` job, and every job omp recorded before 18.15.0.
99
+ expect(jobSubject({ label: 'audit the diff' })).toEqual({ primary: 'audit the diff' });
100
+ expect(jobSubject({})).toEqual({ primary: undefined });
101
+ });
102
+
103
+ test('a multi-line intent is collapsed to one line', () => {
104
+ expect(jobSubject({ intent: 'Start\nthe dev server', label: 'bun run dev' }).primary).toBe(
105
+ 'Start the dev server',
106
+ );
107
+ });
108
+
109
+ test('a blank intent is an absence, not an empty subject', () => {
110
+ expect(jobSubject({ intent: ' ', label: 'bun run dev' })).toEqual({ primary: 'bun run dev' });
111
+ });
112
+ });
@@ -82,3 +82,34 @@ export function jobProgressLine(job: JobProgressFields, options: JobProgressOpti
82
82
  const parts = jobProgressParts(job, options);
83
83
  return parts.length > 0 ? parts.join(' · ') : undefined;
84
84
  }
85
+
86
+ /** The two fields a job row leads with. */
87
+ export interface JobSubjectFields {
88
+ /** What the job is for, in the MODEL's words — the `i` intent of the call
89
+ * that started it (omp 18.15.0). Only the tools that start a single job set
90
+ * it, so a subagent task row never has one. */
91
+ intent?: string;
92
+ /** The raw command line (bash) or the task's own label. */
93
+ label?: string;
94
+ }
95
+
96
+ /**
97
+ * What a job row says: the intent first, the command beneath it.
98
+ *
99
+ * omp 18.15.0 records the caller's `i` intent on the job and leads its own
100
+ * `/jobs` rows with it, because `bun run dev` does not say what the job is FOR.
101
+ * Kabmo drew the label alone, so the purpose the model had already stated was
102
+ * dropped and the raw command stood in for it. Resolved in one place so the
103
+ * `wait` card, the `proc://` card and their fact chips cannot disagree about
104
+ * which line is the subject.
105
+ *
106
+ * `primary` falls back to the label when there is no intent, so a row always
107
+ * has something to draw; `secondary` is only present when both exist (the
108
+ * command is still worth reading, under the purpose it serves).
109
+ */
110
+ export function jobSubject(job: JobSubjectFields): { primary?: string; secondary?: string } {
111
+ const intent = job.intent?.replace(/\s+/g, ' ').trim();
112
+ const label = job.label?.trim();
113
+ if (!intent) return { primary: label };
114
+ return { primary: intent, secondary: label };
115
+ }
@@ -93,6 +93,10 @@ export interface ProcJob {
93
93
  type?: string;
94
94
  status?: string;
95
95
  label?: string;
96
+ /** What the job is for, in the MODEL's words — the `i` intent of the call
97
+ * that started it (omp 18.15.0). Absent on rows omp built before the
98
+ * release, on subagent tasks, and on a call the model gave no intent. */
99
+ intent?: string;
96
100
  durationMs?: number;
97
101
  exitCode?: number;
98
102
  /** Self-estimated completion of a subagent task (0–100). */
@@ -181,6 +185,7 @@ function jobOf(value: unknown): ProcJob | undefined {
181
185
  type: asString(value.type),
182
186
  status: asString(value.status),
183
187
  label: asString(value.label),
188
+ intent: asString(value.intent),
184
189
  durationMs: asNumber(value.durationMs),
185
190
  exitCode: asNumber(value.exitCode),
186
191
  completionPercent: asNumber(value.completionPercent),
@@ -38,6 +38,10 @@ export interface WaitJob {
38
38
  type?: string;
39
39
  status?: string;
40
40
  label?: string;
41
+ /** What the job is for, in the MODEL's words — the `i` intent of the call
42
+ * that started it (omp 18.15.0); absent on subagent tasks and on a call the
43
+ * model gave no intent. */
44
+ intent?: string;
41
45
  /** Elapsed time AT SNAPSHOT TIME — omp computes `now - startTime` while the
42
46
  * job runs, so a live snapshot's value is the real elapsed clock. */
43
47
  durationMs?: number;
@@ -124,6 +128,7 @@ function jobOf(value: unknown): WaitJob | undefined {
124
128
  type: asString(value.type),
125
129
  status: asString(value.status),
126
130
  label: asString(value.label),
131
+ intent: asString(value.intent),
127
132
  durationMs: asNumber(value.durationMs),
128
133
  exitCode: asNumber(value.exitCode),
129
134
  completionPercent: asNumber(value.completionPercent),
@@ -0,0 +1,69 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The menu placement arithmetic, without a layout engine.
8
+ *
9
+ * These are the three outcomes a user can SEE: the panel hangs below the
10
+ * trigger, flips above it near the bottom edge, and clamps inside the window's
11
+ * left/right edges. Each was a real defect before the portal existed — the
12
+ * sidebar's folder menu ran off the bottom of a 460px window, and the phone's
13
+ * server sheet was written `absolute` at 340px, which runs off the right edge of
14
+ * a 390px screen.
15
+ */
16
+
17
+ import { describe, expect, test } from 'bun:test';
18
+ import { placeMenu, type AnchorRect } from '@/shared/lib/ui/menu-anchor';
19
+
20
+ const VIEWPORT = { width: 1200, height: 800 };
21
+
22
+ /** A trailing `⋯` at (x, y): 22px wide, 22px tall. */
23
+ function anchorAt(left: number, top: number): AnchorRect {
24
+ return { left, right: left + 22, top, bottom: top + 22 };
25
+ }
26
+
27
+ describe('placeMenu', () => {
28
+ test('it hangs below the trigger, right edges aligned', () => {
29
+ const placement = placeMenu(anchorAt(200, 100), { width: 176, height: 94 }, VIEWPORT);
30
+ // 4px gap below the trigger, and the menu's right edge on the trigger's.
31
+ expect(placement.top).toBe(126);
32
+ expect(placement.left).toBe(222 - 176);
33
+ });
34
+
35
+ test('it flips above when the space below cannot hold it', () => {
36
+ const placement = placeMenu(anchorAt(200, 740), { width: 176, height: 94 }, VIEWPORT);
37
+ // Above the trigger rather than past the bottom edge.
38
+ expect(placement.top).toBe(740 - 4 - 94);
39
+ expect(placement.top + 94).toBeLessThanOrEqual(VIEWPORT.height);
40
+ });
41
+
42
+ test('a menu taller than the window pins to the margin and becomes scrollable', () => {
43
+ const placement = placeMenu(anchorAt(200, 300), { width: 176, height: 2000 }, VIEWPORT);
44
+ expect(placement.top).toBe(8);
45
+ expect(placement.maxHeight).toBe(VIEWPORT.height - 8 - 8);
46
+ });
47
+
48
+ test('a trailing menu cannot run past the right edge', () => {
49
+ // This trigger's right edge is 32px off the window: aligned to it, the menu
50
+ // is still inside the margin, so the clamp is what a trigger ON the edge
51
+ // exercises.
52
+ const placement = placeMenu(anchorAt(1150, 100), { width: 176, height: 94 }, VIEWPORT);
53
+ expect(placement.left + 176).toBe(1172);
54
+ expect(placement.left + 176).toBeLessThanOrEqual(VIEWPORT.width - 8);
55
+
56
+ const onEdge = placeMenu(anchorAt(1190, 100), { width: 176, height: 94 }, VIEWPORT);
57
+ expect(onEdge.left).toBe(VIEWPORT.width - 176 - 8);
58
+ });
59
+
60
+ test('a start-aligned menu cannot run past the left edge', () => {
61
+ const placement = placeMenu(anchorAt(-40, 100), { width: 176, height: 94 }, VIEWPORT, 'start');
62
+ expect(placement.left).toBe(8);
63
+ });
64
+
65
+ test('start alignment puts the menu’s left edge on the trigger’s', () => {
66
+ const placement = placeMenu(anchorAt(500, 100), { width: 176, height: 94 }, VIEWPORT, 'start');
67
+ expect(placement.left).toBe(500);
68
+ });
69
+ });
@@ -0,0 +1,89 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Where a popover hangs, as arithmetic.
8
+ *
9
+ * A menu that is placed by CSS alone (`absolute right-0 top-full`) cannot see
10
+ * the edge of the window, so it runs off the bottom of a short window and off
11
+ * the right of a narrow one, and it is placed inside whatever stacking context
12
+ * its trigger happens to live in. Both failure modes were measured on this
13
+ * app's own folder menu and server panel (see `common/anchored-menu/`), which
14
+ * is why the geometry below is computed from the VIEWPORT and then applied to
15
+ * a portalled, `fixed` panel.
16
+ *
17
+ * Pure and viewport-injected (no `window` read) so a test can assert the flip
18
+ * and the clamp without a layout engine.
19
+ */
20
+
21
+ /** The trigger's rectangle in viewport coordinates. */
22
+ export interface AnchorRect {
23
+ top: number;
24
+ right: number;
25
+ bottom: number;
26
+ left: number;
27
+ }
28
+
29
+ /**
30
+ * Which edge of the trigger the menu aligns to.
31
+ *
32
+ * `end` hangs the menu's right edge off the trigger's — what a trailing `⋯`
33
+ * expects. `start` puts the menu's left edge at the trigger's.
34
+ */
35
+ export type MenuAlign = 'start' | 'end';
36
+
37
+ export interface MenuPlacement {
38
+ top: number;
39
+ left: number;
40
+ /** The panel must scroll rather than run past the bottom edge. */
41
+ maxHeight: number;
42
+ }
43
+
44
+ /** Room kept between a menu and the window's edges. */
45
+ const MARGIN = 8;
46
+
47
+ /** Room between the trigger and the menu that hangs off it. */
48
+ const GAP = 4;
49
+
50
+ function clamp(value: number, min: number, max: number): number {
51
+ return Math.max(min, Math.min(value, max));
52
+ }
53
+
54
+ /**
55
+ * Place a menu of `size` against `anchor`, inside `viewport`.
56
+ *
57
+ * Below the trigger first, because that is where a menu is expected; above it
58
+ * when the space below cannot hold it and the space above can. When neither
59
+ * fits, it pins to the top margin and `maxHeight` makes the panel scroll — a
60
+ * menu taller than the window is readable, one pushed past the bottom edge is
61
+ * not.
62
+ */
63
+ export function placeMenu(
64
+ anchor: AnchorRect,
65
+ size: { width: number; height: number },
66
+ viewport: { width: number; height: number },
67
+ align: MenuAlign = 'end',
68
+ ): MenuPlacement {
69
+ const below = anchor.bottom + GAP;
70
+ const above = anchor.top - GAP;
71
+
72
+ let top: number;
73
+ if (below + size.height + MARGIN <= viewport.height) top = below;
74
+ else if (above - size.height >= MARGIN) top = above - size.height;
75
+ else top = MARGIN;
76
+
77
+ const widest = Math.max(MARGIN, viewport.width - size.width - MARGIN);
78
+ const left = align === 'end'
79
+ ? clamp(anchor.right - size.width, MARGIN, widest)
80
+ : clamp(anchor.left, MARGIN, widest);
81
+
82
+ return { top, left, maxHeight: Math.max(MARGIN, viewport.height - top - MARGIN) };
83
+ }
84
+
85
+ /** The trigger's rect, as the anchor type above. */
86
+ export function anchorRectOf(element: Element): AnchorRect {
87
+ const rect = element.getBoundingClientRect();
88
+ return { top: rect.top, right: rect.right, bottom: rect.bottom, left: rect.left };
89
+ }