@kabmo-labs/kabmo 0.17.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (438) hide show
  1. package/README.md +10 -7
  2. package/dist/client/index.html +1 -1
  3. package/dist/client/index.js +523 -441
  4. package/dist/client/static/js/{index-rerjq5th.js → index-fcee4c13.js} +828 -818
  5. package/dist/client/static/js/index-sxdw908m.css +1 -0
  6. package/marketplace/plugins/command-runner/package.json +3 -2
  7. package/marketplace/plugins/git-forge/package.json +3 -2
  8. package/marketplace/plugins/session-info/package.json +3 -2
  9. package/marketplace/plugins/stats/package.json +3 -2
  10. package/package.json +3 -1
  11. package/src/client/components/auth/login-screen/index.tsx +2 -1
  12. package/src/client/components/common/ComposerPicker.tsx +1 -1
  13. package/src/client/components/common/FolderPicker.tsx +2 -2
  14. package/src/client/components/common/MarkdownRenderer.tsx +136 -89
  15. package/src/client/components/common/Modal.tsx +2 -2
  16. package/src/client/components/common/PWAInstallButton.tsx +2 -2
  17. package/src/client/components/common/ViewportSelector.tsx +1 -1
  18. package/src/client/components/common/anchored-menu/index.test.tsx +141 -0
  19. package/src/client/components/common/anchored-menu/index.tsx +147 -0
  20. package/src/client/components/common/batch-selection/SelectionCheckbox.tsx +2 -1
  21. package/src/client/components/common/brand-wordmark/index.test.tsx +13 -2
  22. package/src/client/components/common/brand-wordmark/index.tsx +13 -2
  23. package/src/client/components/common/checkbox/style.test.ts +139 -0
  24. package/src/client/components/common/checkbox/style.ts +51 -0
  25. package/src/client/components/common/context-usage-button/index.tsx +2 -2
  26. package/src/client/components/common/file-icon/index.tsx +23 -9
  27. package/src/client/components/common/header-controls/MoreMenu.tsx +1 -1
  28. package/src/client/components/common/markdown-review/ReviewPopover.tsx +144 -0
  29. package/src/client/components/common/markdown-review/ReviewSummary.tsx +108 -0
  30. package/src/client/components/common/markdown-review/index.tsx +129 -0
  31. package/src/client/components/common/panel-mark/index.tsx +97 -0
  32. package/src/client/components/common/provider-icon/glyphs.test.ts +1 -1
  33. package/src/client/components/common/provider-icon/index.test.ts +14 -0
  34. package/src/client/components/common/provider-icon/index.tsx +4 -0
  35. package/src/client/components/common/provider-icon/resolve.test.ts +8 -7
  36. package/src/client/components/common/provider-icon/resolve.ts +16 -3
  37. package/src/client/components/common/server-control/Panel.tsx +33 -23
  38. package/src/client/components/common/server-control/index.test.tsx +11 -5
  39. package/src/client/components/common/server-control/index.tsx +10 -8
  40. package/src/client/components/common/session-actions-menu/index.tsx +1 -1
  41. package/src/client/components/common/toolbar-row/index.tsx +1 -1
  42. package/src/client/components/layout/ActivityBar.tsx +22 -3
  43. package/src/client/components/layout/LeftDock.tsx +9 -2
  44. package/src/client/components/layout/PanelVisibilityMenu.tsx +1 -1
  45. package/src/client/components/layout/WindowAura.tsx +27 -0
  46. package/src/client/components/layout/desktop-layout/LeftColumn.tsx +1 -1
  47. package/src/client/components/layout/desktop-layout/TopNavbar.tsx +2 -2
  48. package/src/client/components/layout/desktop-layout/WorkspacePanels.tsx +11 -2
  49. package/src/client/components/layout/desktop-layout/index.tsx +3 -1
  50. package/src/client/components/layout/session-sidebar/CategoryHeader.tsx +44 -23
  51. package/src/client/components/layout/session-sidebar/CategoryHeader.worktree.test.tsx +36 -17
  52. package/src/client/components/layout/session-sidebar/CategoryItem.tsx +8 -7
  53. package/src/client/components/layout/session-sidebar/Header.tsx +1 -1
  54. package/src/client/components/layout/session-sidebar/OverflowMenu.tsx +1 -1
  55. package/src/client/components/layout/session-sidebar/Toolbar.tsx +1 -1
  56. package/src/client/components/layout/session-sidebar/about-modal/NotesDialog.tsx +94 -0
  57. package/src/client/components/layout/session-sidebar/about-modal/VersionLine.test.tsx +68 -0
  58. package/src/client/components/layout/session-sidebar/about-modal/VersionLine.tsx +36 -0
  59. package/src/client/components/layout/session-sidebar/about-modal/index.tsx +57 -34
  60. package/src/client/components/layout/session-sidebar/modern/ActionRow.tsx +1 -1
  61. package/src/client/components/layout/session-sidebar/modern/WorkspaceHeader.tsx +40 -14
  62. package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +7 -6
  63. package/src/client/components/layout/session-sidebar/modern/workspace-header.test.tsx +1 -1
  64. package/src/client/components/layout/session-sidebar/new-workspace-modal/index.tsx +2 -2
  65. package/src/client/components/layout/session-sidebar/scheduler-modal/TaskForm.tsx +2 -1
  66. package/src/client/components/layout/session-sidebar/scheduler-modal/index.tsx +2 -2
  67. package/src/client/components/layout/update-popup/ReleaseNotes.tsx +8 -3
  68. package/src/client/components/layout/update-popup/index.tsx +5 -1
  69. package/src/client/components/mobile/LayoutWrapper.tsx +3 -1
  70. package/src/client/components/mobile/mobile-main-view/Header.tsx +2 -2
  71. package/src/client/components/mobile/mobile-right-sidebar/FullEditor.tsx +13 -15
  72. package/src/client/components/mobile/mobile-right-sidebar/Header.tsx +23 -1
  73. package/src/client/components/mobile/mobile-right-sidebar/MissingFileBanner.tsx +30 -0
  74. package/src/client/components/mobile/mobile-right-sidebar/PreviewScroller.tsx +18 -2
  75. package/src/client/components/mobile/mobile-session-sidebar/Header.tsx +1 -1
  76. package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +22 -67
  77. package/src/client/components/mobile/mobile-session-sidebar/ItemMenu.tsx +110 -0
  78. package/src/client/components/mobile/mobile-session-sidebar/Toolbar.tsx +1 -1
  79. package/src/client/components/mobile/panel-chips.tsx +10 -2
  80. package/src/client/components/settings/Modal.tsx +4 -4
  81. package/src/client/components/settings/ProjectSelectorDropdown.tsx +2 -2
  82. package/src/client/components/settings/SettingsSidebarList.tsx +20 -0
  83. package/src/client/components/settings/apply-side-effects.test.ts +30 -0
  84. package/src/client/components/settings/apply-side-effects.ts +14 -0
  85. package/src/client/components/settings/categories/AgentSettings.tsx +23 -50
  86. package/src/client/components/settings/categories/AppearanceSettings.tsx +6 -0
  87. package/src/client/components/settings/categories/CommandSettings.tsx +2 -2
  88. package/src/client/components/settings/categories/McpSettings.tsx +4 -21
  89. package/src/client/components/settings/categories/OmpSettings.tsx +147 -194
  90. package/src/client/components/settings/categories/SkillSettings.tsx +2 -2
  91. package/src/client/components/settings/categories/TokenUsageSettings.tsx +211 -229
  92. package/src/client/components/settings/categories/agent-settings/DetailPane.tsx +229 -237
  93. package/src/client/components/settings/categories/agent-settings/ModelPicker.tsx +71 -0
  94. package/src/client/components/settings/categories/agent-settings/SidebarList.tsx +9 -2
  95. package/src/client/components/settings/categories/agent-settings/levels.ts +38 -0
  96. package/src/client/components/settings/categories/appearance-settings/EditorBlameSection.tsx +2 -1
  97. package/src/client/components/settings/categories/appearance-settings/EditorTypingSection.tsx +2 -1
  98. package/src/client/components/settings/categories/appearance-settings/IconStyleSection.tsx +144 -0
  99. package/src/client/components/settings/categories/appearance-settings/SurfaceStyleSection.test.tsx +120 -0
  100. package/src/client/components/settings/categories/appearance-settings/SurfaceStyleSection.tsx +180 -0
  101. package/src/client/components/settings/categories/behavior-settings/Editor.tsx +27 -7
  102. package/src/client/components/settings/categories/chat-settings/ToolRenderSection.tsx +23 -5
  103. package/src/client/components/settings/categories/command-settings/DetailPane.tsx +75 -33
  104. package/src/client/components/settings/categories/command-settings/SidebarList.tsx +7 -0
  105. package/src/client/components/settings/categories/mcp-settings/DetailPane.tsx +93 -77
  106. package/src/client/components/settings/categories/mcp-settings/EnvVarsSection.tsx +83 -0
  107. package/src/client/components/settings/categories/mcp-settings/ImportModal.tsx +28 -15
  108. package/src/client/components/settings/categories/mcp-settings/SidebarList.tsx +20 -0
  109. package/src/client/components/settings/categories/omp-settings/ConfigTabs.tsx +97 -36
  110. package/src/client/components/settings/categories/omp-settings/EngineHeader.tsx +151 -0
  111. package/src/client/components/settings/categories/omp-settings/ExtensionsPanel.tsx +68 -32
  112. package/src/client/components/settings/categories/omp-settings/OrderedChips.tsx +119 -0
  113. package/src/client/components/settings/categories/omp-settings/PresetBar.tsx +14 -7
  114. package/src/client/components/settings/categories/omp-settings/RoleEditor.tsx +15 -6
  115. package/src/client/components/settings/categories/omp-settings/RowEditor.tsx +165 -226
  116. package/src/client/components/settings/categories/omp-settings/types.ts +28 -0
  117. package/src/client/components/settings/categories/panel-plugins/AvailableList.tsx +1 -1
  118. package/src/client/components/settings/categories/panel-plugins/BuiltinList.tsx +21 -3
  119. package/src/client/components/settings/categories/panel-plugins/PluginCard.tsx +1 -1
  120. package/src/client/components/settings/categories/panel-plugins/PluginMark.test.ts +51 -2
  121. package/src/client/components/settings/categories/panel-plugins/PluginMark.tsx +43 -10
  122. package/src/client/components/settings/categories/plugin-settings/DetailPane.tsx +2 -1
  123. package/src/client/components/settings/categories/plugin-settings/SettingsSection.tsx +2 -1
  124. package/src/client/components/settings/categories/project-settings/ModelDropdown.tsx +1 -1
  125. package/src/client/components/settings/categories/project-settings/WorktreeSettings.tsx +2 -1
  126. package/src/client/components/settings/categories/provider-settings/DeleteProviderModal.tsx +2 -2
  127. package/src/client/components/settings/categories/provider-settings/EntryAdvanced.tsx +3 -2
  128. package/src/client/components/settings/categories/provider-settings/LogoutProviderModal.tsx +2 -2
  129. package/src/client/components/settings/categories/skill-catalog/GitImportPanel.tsx +3 -2
  130. package/src/client/components/settings/categories/skill-settings/DetailHeader.tsx +37 -8
  131. package/src/client/components/settings/categories/skill-settings/DetailPane.tsx +34 -14
  132. package/src/client/components/settings/categories/skill-settings/SidebarList.tsx +21 -0
  133. package/src/client/components/settings/categories/skill-settings/pane.test.tsx +15 -6
  134. package/src/client/components/settings/categories/token-usage-settings/Breakdown.tsx +242 -102
  135. package/src/client/components/settings/categories/token-usage-settings/Chart.tsx +130 -56
  136. package/src/client/components/settings/categories/token-usage-settings/Controls.tsx +135 -0
  137. package/src/client/components/settings/categories/token-usage-settings/MetricsGrid.tsx +55 -33
  138. package/src/client/components/settings/categories/token-usage-settings/Provenance.tsx +59 -0
  139. package/src/client/components/settings/categories/token-usage-settings/panel.test.tsx +239 -0
  140. package/src/client/components/workspace/browser-panel/Screencast.test.ts +1 -0
  141. package/src/client/components/workspace/browser-panel/Screencast.tsx +17 -22
  142. package/src/client/components/workspace/browser-panel/TabStrip.test.tsx +158 -0
  143. package/src/client/components/workspace/browser-panel/TabStrip.tsx +90 -0
  144. package/src/client/components/workspace/browser-panel/index.tsx +50 -4
  145. package/src/client/components/workspace/browser-toolbar/index.tsx +41 -1
  146. package/src/client/components/workspace/btw-panel/TopicMenu.tsx +1 -1
  147. package/src/client/components/workspace/chat-timeline/AiMessageFooter.tsx +2 -2
  148. package/src/client/components/workspace/chat-timeline/NewChatModal.tsx +3 -3
  149. package/src/client/components/workspace/chat-timeline/ThinkingSection.tsx +3 -1
  150. package/src/client/components/workspace/chat-timeline/ToolCallingSection.tsx +2 -0
  151. package/src/client/components/workspace/chat-timeline/UndoConfirmModal.tsx +2 -2
  152. package/src/client/components/workspace/chat-timeline/block-chrome.test.tsx +13 -2
  153. package/src/client/components/workspace/chat-timeline/chat-input/AccessDropdown.tsx +1 -1
  154. package/src/client/components/workspace/chat-timeline/chat-input/GoalModal.tsx +4 -3
  155. package/src/client/components/workspace/chat-timeline/chat-input/ThinkingLevelDropdown.tsx +1 -1
  156. package/src/client/components/workspace/chat-timeline/chat-input/WaitingDependencyPicker.tsx +1 -1
  157. package/src/client/components/workspace/chat-timeline/plan-review/index.tsx +2 -2
  158. package/src/client/components/workspace/chat-timeline/target-picker/WorkspacePicker.tsx +1 -1
  159. package/src/client/components/workspace/chat-timeline/target-picker/WorktreePicker.tsx +1 -1
  160. package/src/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/index.tsx +2 -6
  161. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Bash.test.ts +88 -0
  162. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Bash.tsx +24 -1
  163. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Read.test.ts +34 -0
  164. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Read.tsx +5 -1
  165. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/ArtifactChip.tsx +7 -6
  166. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Tui.test.tsx +237 -0
  167. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Tui.tsx +191 -0
  168. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/styles.test.tsx +1 -1
  169. package/src/client/components/workspace/context-panel/CostBreakdownPopover.tsx +1 -1
  170. package/src/client/components/workspace/diff-panel/MergeDiffView.tsx +21 -7
  171. package/src/client/components/workspace/diff-panel/changes.test.ts +51 -0
  172. package/src/client/components/workspace/diff-panel/changes.ts +28 -12
  173. package/src/client/components/workspace/diff-panel/index.tsx +2 -2
  174. package/src/client/components/workspace/diff-panel/merge.test.ts +28 -0
  175. package/src/client/components/workspace/diff-panel/merge.ts +21 -1
  176. package/src/client/components/workspace/editor/Body.tsx +7 -0
  177. package/src/client/components/workspace/editor/FileDocument.tsx +15 -21
  178. package/src/client/components/workspace/editor/FilePane.tsx +12 -0
  179. package/src/client/components/workspace/editor/PluginRail.tsx +1 -1
  180. package/src/client/components/workspace/editor/PreviewPane.tsx +70 -0
  181. package/src/client/components/workspace/editor/SaveDeletedFileModal.tsx +2 -2
  182. package/src/client/components/workspace/editor/TabContextMenu.tsx +1 -1
  183. package/src/client/components/workspace/editor/Tabs.tsx +1 -1
  184. package/src/client/components/workspace/editor/Toolbar.tsx +17 -1
  185. package/src/client/components/workspace/editor/index.tsx +25 -22
  186. package/src/client/components/workspace/editor/toolbar-clusters.test.ts +14 -0
  187. package/src/client/components/workspace/editor/toolbar-clusters.tsx +12 -86
  188. package/src/client/components/workspace/editor/toolbar-toggle.tsx +53 -0
  189. package/src/client/components/workspace/editor/toolbar-write-clusters.tsx +112 -0
  190. package/src/client/components/workspace/file-explorer/ContextMenu.tsx +1 -1
  191. package/src/client/components/workspace/file-explorer/Modals.tsx +10 -10
  192. package/src/client/components/workspace/file-explorer/RootMenu.tsx +1 -1
  193. package/src/client/components/workspace/git-panel/BranchToolbar.test.tsx +130 -0
  194. package/src/client/components/workspace/git-panel/BranchToolbar.tsx +21 -11
  195. package/src/client/components/workspace/git-panel/CommitBox.tsx +2 -1
  196. package/src/client/components/workspace/git-panel/Modals.tsx +2 -2
  197. package/src/client/components/workspace/git-panel/StashSection.tsx +2 -1
  198. package/src/client/components/workspace/git-panel/branch-modal/DeleteDialog.tsx +2 -1
  199. package/src/client/components/workspace/git-panel/branch-modal/RenameDialog.tsx +2 -1
  200. package/src/client/components/workspace/git-panel/commit-modal/index.tsx +2 -2
  201. package/src/client/components/workspace/git-panel/commit-modal.test.ts +5 -3
  202. package/src/client/components/workspace/git-panel/index.tsx +7 -0
  203. package/src/client/components/workspace/model-dropdown/Panel.tsx +1 -1
  204. package/src/client/components/workspace/model-dropdown/SpecsTooltip.tsx +1 -1
  205. package/src/client/components/workspace/plugin-panel/catalog.tsx +7 -0
  206. package/src/client/components/workspace/plugin-panel/resolve.tsx +4 -0
  207. package/src/client/components/workspace/search-panel/Body.tsx +1 -1
  208. package/src/client/components/workspace/usage-panel/ProviderSelect.tsx +1 -1
  209. package/src/client/components/workspace/user-browser-panel/AddressBar.tsx +5 -0
  210. package/src/client/components/workspace/user-browser-panel/AnnotateBar.test.tsx +201 -0
  211. package/src/client/components/workspace/user-browser-panel/AnnotateBar.tsx +112 -0
  212. package/src/client/components/workspace/user-browser-panel/AnnotateLayer.test.tsx +225 -0
  213. package/src/client/components/workspace/user-browser-panel/AnnotateLayer.tsx +217 -0
  214. package/src/client/components/workspace/user-browser-panel/AnnotateTarget.tsx +99 -0
  215. package/src/client/components/workspace/user-browser-panel/Frame.tsx +30 -1
  216. package/src/client/components/workspace/user-browser-panel/index.tsx +81 -2
  217. package/src/client/data/agent-data/builtin.ts +0 -10
  218. package/src/client/data/agent-data/orchestrator.ts +0 -45
  219. package/src/client/data/agent-data/specialist.ts +0 -100
  220. package/src/client/data/mock/token-usage.ts +170 -120
  221. package/src/client/data/settings/omp-schema.json +33 -1
  222. package/src/client/glass.css +785 -0
  223. package/src/client/glass.test.ts +346 -0
  224. package/src/client/hooks/browser/use-annotate.test.ts +143 -0
  225. package/src/client/hooks/browser/use-annotate.ts +98 -0
  226. package/src/client/hooks/browser/use-close-tab.test.ts +148 -0
  227. package/src/client/hooks/browser/use-close-tab.ts +67 -0
  228. package/src/client/hooks/browser/use-screencast.ts +13 -1
  229. package/src/client/hooks/chat/composer/browser-context.test.ts +117 -0
  230. package/src/client/hooks/chat/composer/browser-context.ts +40 -16
  231. package/src/client/hooks/chat/composer/items.test.ts +1 -1
  232. package/src/client/hooks/chat/composer/review-context.ts +38 -0
  233. package/src/client/hooks/chat/composer/use-draft.test.ts +132 -0
  234. package/src/client/hooks/chat/composer/use-draft.ts +31 -2
  235. package/src/client/hooks/chat/timeline/row-window.test.ts +15 -2
  236. package/src/client/hooks/editor/use-document-annotations.ts +124 -0
  237. package/src/client/hooks/editor/use-editor-panel-ui.ts +52 -0
  238. package/src/client/hooks/editor/use-file-review-mode.ts +35 -0
  239. package/src/client/hooks/editor/use-preview-review.ts +148 -0
  240. package/src/client/hooks/settings/agents.ts +149 -0
  241. package/src/client/hooks/settings/crud-list.test.ts +28 -6
  242. package/src/client/hooks/settings/crud-list.ts +96 -57
  243. package/src/client/hooks/settings/omp-config.ts +164 -0
  244. package/src/client/hooks/settings/useTokenUsage.ts +125 -0
  245. package/src/client/hooks/settings/write-feedback.test.ts +104 -0
  246. package/src/client/hooks/settings/write-feedback.ts +63 -0
  247. package/src/client/hooks/ui/glass-support.ts +57 -0
  248. package/src/client/hooks/ui/icon-style.ts +59 -0
  249. package/src/client/hooks/ui/markdown-hydration.ts +125 -0
  250. package/src/client/hooks/ui/stuck-header.test.ts +188 -0
  251. package/src/client/hooks/ui/stuck-header.ts +91 -0
  252. package/src/client/hooks/ui/style-attributes.test.ts +120 -0
  253. package/src/client/hooks/ui/surface-style.ts +56 -0
  254. package/src/client/hooks/ui/updates/index.test.ts +100 -1
  255. package/src/client/hooks/ui/updates/index.ts +50 -0
  256. package/src/client/hooks/ui/updates/notes.test.ts +138 -0
  257. package/src/client/hooks/ui/updates/notes.ts +57 -0
  258. package/src/client/hooks/workspace/panel-hues.ts +23 -0
  259. package/src/client/lib/browser/element-at.test.ts +229 -0
  260. package/src/client/lib/browser/element-at.ts +139 -0
  261. package/src/client/lib/review/client.ts +73 -0
  262. package/src/client/lib/router/search-params.ts +42 -20
  263. package/src/client/main.tsx +10 -0
  264. package/src/client/tailwind.css +329 -11
  265. package/src/server/lib/assets/shell-attributes.server.ts +80 -0
  266. package/src/server/lib/assets/shell-attributes.test.ts +86 -0
  267. package/src/server/lib/btw/lifecycle.server.ts +2 -2
  268. package/src/server/lib/db/schema.ts +7 -0
  269. package/src/server/lib/db/seed-terminal.test.ts +4 -0
  270. package/src/server/lib/omp/config/agent-definitions.test.ts +273 -0
  271. package/src/server/lib/omp/config/agents.ts +231 -61
  272. package/src/server/lib/omp/config/definitions.test.ts +9 -105
  273. package/src/server/lib/omp/config/extensions.ts +16 -7
  274. package/src/server/lib/omp/config/omp-config-files.test.ts +27 -0
  275. package/src/server/lib/omp/rpc/constants.test.ts +11 -0
  276. package/src/server/lib/omp/rpc/constants.ts +15 -0
  277. package/src/server/lib/omp/rpc/frame-fold-host.test-util.ts +1 -0
  278. package/src/server/lib/omp/rpc/frame-fold-signals.test.ts +2 -30
  279. package/src/server/lib/omp/rpc/frame-fold.test.ts +55 -0
  280. package/src/server/lib/omp/rpc/frame-fold.ts +4 -0
  281. package/src/server/lib/omp/rpc/manager.ts +2 -2
  282. package/src/server/lib/omp/rpc/process-helpers.ts +11 -0
  283. package/src/server/lib/omp/rpc/process.test.ts +106 -0
  284. package/src/server/lib/omp/rpc/process.ts +39 -18
  285. package/src/server/lib/omp/rpc/run-settle.server.ts +12 -0
  286. package/src/server/lib/omp/rpc/run-settle.test.ts +22 -0
  287. package/src/server/lib/omp/rpc/session-command-guards.ts +5 -0
  288. package/src/server/lib/omp/rpc/session-commands.test.ts +9 -1
  289. package/src/server/lib/omp/rpc/session-commands.ts +17 -3
  290. package/src/server/lib/omp/rpc/terminal-settle.ts +29 -7
  291. package/src/server/lib/omp/rpc/utility-agent-dir.test.ts +134 -0
  292. package/src/server/lib/omp/rpc/utility-agent-dir.ts +138 -0
  293. package/src/server/lib/omp/rpc/utility.ts +12 -0
  294. package/src/server/lib/panels/bundled-catalog.server.ts +1 -0
  295. package/src/server/lib/panels/manifest.test.ts +20 -0
  296. package/src/server/lib/panels/manifest.ts +12 -0
  297. package/src/server/lib/panels/scan.server.ts +4 -0
  298. package/src/server/lib/queue/delivery-dispatch.server.test.ts +48 -0
  299. package/src/server/lib/queue/delivery-harness.ts +8 -4
  300. package/src/server/lib/queue/delivery.server.test.ts +29 -0
  301. package/src/server/lib/queue/delivery.server.ts +39 -0
  302. package/src/server/lib/queue/store.server.test.ts +22 -2
  303. package/src/server/lib/queue/store.server.ts +33 -11
  304. package/src/server/lib/review/schema.server.ts +45 -0
  305. package/src/server/lib/review/store.server.ts +138 -0
  306. package/src/server/lib/terminal/attach-replay.test.ts +132 -0
  307. package/src/server/lib/terminal/output.test.ts +166 -0
  308. package/src/server/lib/terminal/output.ts +104 -0
  309. package/src/server/lib/terminal/runtime.server.ts +5 -0
  310. package/src/server/lib/terminal/send-result.test.ts +33 -0
  311. package/src/server/lib/terminal/send-result.ts +32 -0
  312. package/src/server/lib/terminal/session.server.ts +45 -11
  313. package/src/server/lib/terminal/store-liveness.test.ts +4 -0
  314. package/src/server/lib/updates/active-notes.test.ts +149 -0
  315. package/src/server/lib/updates/active-notes.ts +75 -0
  316. package/src/server/lib/updates/changelog-file.ts +42 -11
  317. package/src/server/lib/updates/changelog.test.ts +15 -1
  318. package/src/server/lib/updates/omp.ts +42 -15
  319. package/src/server/lib/updates/release-url.ts +27 -1
  320. package/src/server/lib/usage/index-parse.test.ts +200 -0
  321. package/src/server/lib/usage/index-parse.ts +178 -0
  322. package/src/server/lib/usage/index-query.server.ts +248 -0
  323. package/src/server/lib/usage/index-scan.server.ts +343 -0
  324. package/src/server/lib/usage/index-schema.server.ts +82 -0
  325. package/src/server/lib/usage/index.test.ts +234 -0
  326. package/src/server/lib/usage/providers.server.ts +4 -53
  327. package/src/server/plugins/ssr.ts +22 -5
  328. package/src/server/routes/browser/index.ts +3 -0
  329. package/src/server/routes/browser/stream.ts +31 -2
  330. package/src/server/routes/browser/tabs.test.ts +94 -0
  331. package/src/server/routes/browser/tabs.ts +85 -0
  332. package/src/server/routes/index.ts +2 -0
  333. package/src/server/routes/review/bindings.ts +11 -0
  334. package/src/server/routes/review/index.ts +127 -0
  335. package/src/server/routes/review/routes.test.ts +191 -0
  336. package/src/server/routes/settings/agents.test.ts +180 -0
  337. package/src/server/routes/settings/agents.ts +95 -102
  338. package/src/server/routes/settings/mcp.test.ts +135 -0
  339. package/src/server/routes/settings/mcp.ts +14 -6
  340. package/src/server/routes/settings/settings-store-routes.test.ts +6 -113
  341. package/src/server/routes/telemetry/tokens.test.ts +145 -0
  342. package/src/server/routes/telemetry/tokens.ts +70 -149
  343. package/src/server/routes/terminal/ws.ts +6 -5
  344. package/src/server/routes/updates/index.ts +2 -0
  345. package/src/server/routes/updates/notes.ts +34 -0
  346. package/src/server/routes/updates/routes.test.ts +49 -0
  347. package/src/shared/lib/browser/annotate.test.ts +283 -0
  348. package/src/shared/lib/browser/annotate.ts +231 -0
  349. package/src/shared/lib/browser/browser-viewer.test.ts +26 -4
  350. package/src/shared/lib/browser/frame-gate.test.ts +91 -0
  351. package/src/shared/lib/browser/frame-gate.ts +69 -0
  352. package/src/shared/lib/browser/frame-params.test.ts +43 -0
  353. package/src/shared/lib/browser/frame-params.ts +60 -0
  354. package/src/shared/lib/browser/frame-pipeline.test.ts +132 -0
  355. package/src/shared/lib/browser/frame-pipeline.ts +80 -0
  356. package/src/shared/lib/browser/page-context.ts +60 -4
  357. package/src/shared/lib/browser/snapshot.test.ts +115 -0
  358. package/src/shared/lib/browser/snapshot.ts +112 -0
  359. package/src/shared/lib/browser/tab-close.test.ts +74 -0
  360. package/src/shared/lib/browser/tab-close.ts +77 -0
  361. package/src/shared/lib/browser/viewer.ts +45 -26
  362. package/src/shared/lib/chat/timeline/block-chrome.ts +19 -0
  363. package/src/shared/lib/chat/timeline/tool-render-mode.ts +17 -4
  364. package/src/shared/lib/chat/tool/artifact.ts +55 -20
  365. package/src/shared/lib/chat/tool/bash-facts.ts +96 -0
  366. package/src/shared/lib/chat/tool/minimized.test.ts +98 -0
  367. package/src/shared/lib/chat/tool/minimized.ts +64 -0
  368. package/src/shared/lib/chat/tool/summary.test.ts +28 -8
  369. package/src/shared/lib/chat/tool/summary.ts +3 -32
  370. package/src/shared/lib/icons/file-brand-color.ts +38 -0
  371. package/src/shared/lib/icons/icon-paint-css.test.ts +234 -0
  372. package/src/shared/lib/icons/icon-paint-css.ts +284 -0
  373. package/src/shared/lib/icons/icon-paint-panel.ts +100 -0
  374. package/src/shared/lib/icons/tint-hues.generated.ts +230 -0
  375. package/src/shared/lib/icons/tint.test.ts +273 -0
  376. package/src/shared/lib/icons/tint.ts +219 -0
  377. package/src/shared/lib/markdown/blocks/anchor.ts +63 -0
  378. package/src/shared/lib/markdown/blocks/blocks.test.ts +141 -0
  379. package/src/shared/lib/markdown/blocks/renderer.ts +120 -0
  380. package/src/shared/lib/markdown/blocks/scan.ts +100 -0
  381. package/src/shared/lib/markdown/blocks/types.ts +62 -0
  382. package/src/shared/lib/markdown/marked.ts +58 -147
  383. package/src/shared/lib/markdown/math-extensions.ts +168 -0
  384. package/src/shared/lib/markdown/review/prompt.ts +77 -0
  385. package/src/shared/lib/markdown/review/reconcile.ts +55 -0
  386. package/src/shared/lib/markdown/review/review.test.ts +96 -0
  387. package/src/shared/lib/markdown/xml-sections.test.ts +140 -0
  388. package/src/shared/lib/markdown/xml-sections.ts +139 -0
  389. package/src/shared/lib/models/provider/brand-color.test.ts +116 -0
  390. package/src/shared/lib/models/provider/brand-color.ts +103 -0
  391. package/src/shared/lib/models/provider/label.ts +57 -0
  392. package/src/shared/lib/omp/config/agent-file.test.ts +54 -0
  393. package/src/shared/lib/omp/config/agent-file.ts +43 -0
  394. package/src/shared/lib/omp/config/row-value.test.ts +95 -0
  395. package/src/shared/lib/omp/config/row-value.ts +97 -0
  396. package/src/shared/lib/omp/config/schema.test.ts +31 -0
  397. package/src/shared/lib/omp/config/schema.ts +6 -0
  398. package/src/shared/lib/omp/rpc/frame.test.ts +113 -47
  399. package/src/shared/lib/omp/rpc/frame.ts +107 -43
  400. package/src/shared/lib/settings/defaults.ts +4 -0
  401. package/src/shared/lib/theme/catalog.test.ts +5 -4
  402. package/src/shared/lib/theme/catalog.ts +18 -3
  403. package/src/shared/lib/theme/glass-support.test.ts +38 -0
  404. package/src/shared/lib/theme/glass-support.ts +73 -0
  405. package/src/shared/lib/theme/icon-style.test.ts +74 -0
  406. package/src/shared/lib/theme/icon-style.ts +90 -0
  407. package/src/shared/lib/theme/legibility.ts +91 -0
  408. package/src/shared/lib/theme/palettes/dark-extended.ts +152 -0
  409. package/src/shared/lib/theme/palettes/light-extended.ts +157 -0
  410. package/src/shared/lib/theme/surface-style.test.ts +68 -0
  411. package/src/shared/lib/theme/surface-style.ts +91 -0
  412. package/src/shared/lib/theme/theme.test.ts +11 -7
  413. package/src/shared/lib/ui/menu-anchor.test.ts +69 -0
  414. package/src/shared/lib/ui/menu-anchor.ts +89 -0
  415. package/src/shared/lib/usage/breakdown.test.ts +197 -0
  416. package/src/shared/lib/usage/breakdown.ts +241 -0
  417. package/src/shared/lib/usage/range.test.ts +204 -0
  418. package/src/shared/lib/usage/range.ts +240 -0
  419. package/src/shared/lib/usage/view.test.ts +85 -0
  420. package/src/shared/lib/usage/view.ts +74 -0
  421. package/src/shared/lib/workspace/panel-hues.test.ts +68 -0
  422. package/src/shared/lib/workspace/panel-hues.ts +57 -0
  423. package/src/shared/types/browser.ts +78 -0
  424. package/src/shared/types/index.ts +1 -0
  425. package/src/shared/types/panels-registry.ts +6 -0
  426. package/src/shared/types/panels.ts +14 -0
  427. package/src/shared/types/settings/agent.ts +28 -6
  428. package/src/shared/types/settings/state.ts +30 -3
  429. package/src/shared/types/settings/write.ts +6 -0
  430. package/src/shared/types/tokenUsage.ts +128 -21
  431. package/src/shared/types/updates.ts +20 -0
  432. package/src/test-support/fake-omp-frames.ts +163 -0
  433. package/dist/client/static/js/index-3ve31rzx.css +0 -1
  434. package/src/server/lib/omp/session/usage/aggregate-shaping.test.ts +0 -149
  435. package/src/server/lib/omp/session/usage/aggregate.test.ts +0 -243
  436. package/src/server/lib/omp/session/usage/aggregate.ts +0 -330
  437. package/src/server/lib/omp/session/usage/shaping.ts +0 -130
  438. /package/src/{client/components/common/file-icon/brand-paths.ts → shared/lib/icons/file-brand-paths.ts} +0 -0
@@ -0,0 +1,148 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The client half of "close this tab".
8
+ *
9
+ * The rules live on the server (`tab-close.ts`, `routes/browser/tabs.ts`); what
10
+ * this hook must get right is the request it sends, the tab it names for the
11
+ * panel next, and — the failure that actually bites — that a refused close is
12
+ * REPORTED rather than looking like a tab that merely came back.
13
+ */
14
+
15
+ import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test } from 'bun:test';
16
+ import { Window } from 'happy-dom';
17
+ import { h, render } from 'preact';
18
+ import { act } from 'preact/test-utils';
19
+
20
+ import { useCloseBrowserTab } from '@/client/hooks/browser/use-close-tab';
21
+
22
+ const DOM_GLOBALS = ['window', 'document', 'navigator', 'Node', 'Element', 'HTMLElement', 'Event'] as const;
23
+ const native: Partial<Record<(typeof DOM_GLOBALS)[number], unknown>> = {};
24
+
25
+ beforeAll(() => {
26
+ const win = new Window({ url: 'http://localhost' });
27
+ const target = globalThis as unknown as Record<string, unknown>;
28
+ for (const key of DOM_GLOBALS) {
29
+ native[key] = target[key];
30
+ target[key] = (win as unknown as Record<string, unknown>)[key];
31
+ }
32
+ });
33
+
34
+ afterAll(() => {
35
+ const target = globalThis as unknown as Record<string, unknown>;
36
+ for (const key of DOM_GLOBALS) {
37
+ if (native[key] === undefined) delete target[key];
38
+ else target[key] = native[key];
39
+ }
40
+ });
41
+
42
+ const globals = globalThis as unknown as Record<string, unknown>;
43
+ const nativeFetch = globals.fetch;
44
+
45
+ interface Captured {
46
+ url: string;
47
+ method: string;
48
+ body: unknown;
49
+ }
50
+
51
+ let captured: Captured[] = [];
52
+ let reply: { status: number; body: unknown } = { status: 200, body: { ok: true, next: 't3' } };
53
+ let hook: ReturnType<typeof useCloseBrowserTab> | null = null;
54
+
55
+ function Probe({ sessionId }: { sessionId: string }) {
56
+ hook = useCloseBrowserTab(sessionId);
57
+ return h('div', null, hook.closing ?? '');
58
+ }
59
+
60
+ beforeEach(() => {
61
+ captured = [];
62
+ reply = { status: 200, body: { ok: true, next: 't3' } };
63
+ globals.fetch = (url: string, init: RequestInit) => {
64
+ captured.push({ url, method: init.method ?? 'GET', body: JSON.parse(String(init.body)) });
65
+ return Promise.resolve(new Response(JSON.stringify(reply.body), { status: reply.status }));
66
+ };
67
+ hook = null;
68
+ });
69
+
70
+ afterEach(() => {
71
+ globals.fetch = nativeFetch;
72
+ });
73
+
74
+ async function mount(sessionId = 'session-1'): Promise<void> {
75
+ const host = document.createElement('div');
76
+ await act(async () => {
77
+ render(h(Probe, { sessionId }), host);
78
+ });
79
+ }
80
+
81
+ describe('useCloseBrowserTab', () => {
82
+ test('posts the target id to the session’s own close route', async () => {
83
+ await mount();
84
+ const result = await hook!.closeTab('t2');
85
+ expect(captured).toEqual([
86
+ { url: '/api/browser/session-1/tabs/close', method: 'POST', body: { targetId: 't2' } },
87
+ ]);
88
+ expect(result).toEqual({ ok: true, next: 't3' });
89
+ });
90
+
91
+ test('returns null when no tab is left to select', async () => {
92
+ reply = { status: 200, body: { ok: true, next: null } };
93
+ await mount();
94
+ expect(await hook!.closeTab('only')).toEqual({ ok: true, next: null });
95
+ });
96
+
97
+ test('a refusal is reported with the server’s own wording', async () => {
98
+ reply = { status: 403, body: { error: 'That tab does not belong to this session' } };
99
+ await mount();
100
+ expect(await hook!.closeTab('other')).toEqual({
101
+ ok: false,
102
+ next: null,
103
+ error: 'That tab does not belong to this session',
104
+ });
105
+ });
106
+
107
+ test('a refusal with no message still names the status', async () => {
108
+ reply = { status: 503, body: {} };
109
+ await mount();
110
+ expect((await hook!.closeTab('t1')).error).toBe('Close failed (503)');
111
+ });
112
+
113
+ test('a network failure does not look like a closed tab', async () => {
114
+ globals.fetch = () => Promise.reject(new Error('offline'));
115
+ await mount();
116
+ const result = await hook!.closeTab('t1');
117
+ expect(result.ok).toBe(false);
118
+ expect(result.error).toContain('offline');
119
+ });
120
+
121
+ test('a closed tab id is percent-encoded into the URL', async () => {
122
+ await mount('a/b');
123
+ await hook!.closeTab('t1');
124
+ expect(captured[0].url).toBe('/api/browser/a%2Fb/tabs/close');
125
+ });
126
+
127
+ test('an empty target is refused without a request', async () => {
128
+ await mount();
129
+ expect(await hook!.closeTab('')).toEqual({ ok: false, next: null, error: 'No tab to close' });
130
+ expect(captured).toEqual([]);
131
+ });
132
+
133
+ test('a close already in flight leaves its tab marked, then clears', async () => {
134
+ const { promise, resolve } = Promise.withResolvers<Response>();
135
+ globals.fetch = () => promise;
136
+ await mount();
137
+ let pending: Promise<unknown> | null = null;
138
+ await act(async () => {
139
+ pending = hook!.closeTab('t2');
140
+ });
141
+ expect(hook!.closing).toBe('t2');
142
+ await act(async () => {
143
+ resolve(new Response(JSON.stringify({ ok: true, next: null }), { status: 200 }));
144
+ await pending;
145
+ });
146
+ expect(hook!.closing).toBeNull();
147
+ });
148
+ });
@@ -0,0 +1,67 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Closing one of the agent's browser tabs, from the panel.
8
+ *
9
+ * The server owns the rules (ownership, what CDP does to a screencast session);
10
+ * this hook owns only the client's half: refuse a second close while one is in
11
+ * flight, surface the refusal in words, and return the tab the panel should
12
+ * watch next so the strip does not jump to an unrelated page.
13
+ *
14
+ * Deliberately NOT optimistic: the tab strip is server state (the viewer's
15
+ * owned-target list), so removing a row before the browser confirms would show
16
+ * a tab that still exists — and a failed close would look like a refresh race.
17
+ */
18
+
19
+ import { useCallback, useState } from 'preact/hooks';
20
+
21
+ export interface CloseTabResult {
22
+ ok: boolean;
23
+ /** The tab to select once `targetId` is gone (null when none is left). */
24
+ next: string | null;
25
+ error?: string;
26
+ }
27
+
28
+ interface TabsCloseReply {
29
+ ok?: unknown;
30
+ error?: unknown;
31
+ next?: unknown;
32
+ }
33
+
34
+ function readNext(value: unknown): string | null {
35
+ return typeof value === 'string' && value ? value : null;
36
+ }
37
+
38
+ export function useCloseBrowserTab(sessionId: string | undefined) {
39
+ const [closing, setClosing] = useState<string | null>(null);
40
+
41
+ const closeTab = useCallback(
42
+ async (targetId: string): Promise<CloseTabResult> => {
43
+ if (!sessionId || !targetId) return { ok: false, next: null, error: 'No tab to close' };
44
+ setClosing(targetId);
45
+ try {
46
+ const response = await fetch(`/api/browser/${encodeURIComponent(sessionId)}/tabs/close`, {
47
+ method: 'POST',
48
+ headers: { 'content-type': 'application/json' },
49
+ body: JSON.stringify({ targetId }),
50
+ });
51
+ const body = (await response.json().catch(() => ({}))) as TabsCloseReply;
52
+ if (!response.ok) {
53
+ const error = typeof body.error === 'string' && body.error ? body.error : `Close failed (${response.status})`;
54
+ return { ok: false, next: null, error };
55
+ }
56
+ return { ok: true, next: readNext(body.next) };
57
+ } catch (error) {
58
+ return { ok: false, next: null, error: error instanceof Error ? error.message : String(error) };
59
+ } finally {
60
+ setClosing(null);
61
+ }
62
+ },
63
+ [sessionId],
64
+ );
65
+
66
+ return { closeTab, closing };
67
+ }
@@ -18,6 +18,8 @@ interface UseScreencastResult {
18
18
  */
19
19
  frame?: { data: string; mimeType: string } | null;
20
20
  actions: BrowserPanelAction[];
21
+ /** The session whose tabs these are; the tab-close request needs it. */
22
+ sessionId: string;
21
23
  /** Pin the viewer to one tab id; pass an empty string to follow the newest owned tab. */
22
24
  selectTarget: (targetId: string) => void;
23
25
  /** Drop the current SSE connection and open a fresh one. */
@@ -107,7 +109,13 @@ export function useScreencast(active = true): UseScreencastResult {
107
109
  source.addEventListener('state', (event) => {
108
110
  try {
109
111
  const next = JSON.parse((event as MessageEvent).data) as BrowserViewState;
110
- if (next.targetId !== currentTargetRef.current) setFrame(null);
112
+ // Do NOT clear the frame on a target change: the viewer seeds the new
113
+ // tab with a snapshot, and that frame can reach this handler BEFORE
114
+ // the state event that names the tab (measured: 26–47 ms from attach).
115
+ // Clearing here threw away the first picture of an idle tab, which is
116
+ // exactly the picture the snapshot exists to provide. A stale tab's
117
+ // pixels are dropped by the target check in the `frame` handler, and
118
+ // a non-live state below still clears.
111
119
  currentTargetRef.current = next.targetId;
112
120
  setState(next);
113
121
  if (next.status !== 'live') setFrame(null);
@@ -120,7 +128,10 @@ export function useScreencast(active = true): UseScreencastResult {
120
128
  try {
121
129
  const incoming = JSON.parse((event as MessageEvent).data) as BrowserViewFrame;
122
130
  const current = currentTargetRef.current;
131
+ // Adopt the frame's tab when no state has named one yet: the seed
132
+ // snapshot is the first thing this stream can deliver.
123
133
  if (current && incoming.targetId && incoming.targetId !== current) return;
134
+ if (!current && incoming.targetId) currentTargetRef.current = incoming.targetId;
124
135
  setFrame({ data: incoming.data, mimeType: incoming.mimeType });
125
136
  } catch {
126
137
  // Ignore malformed frame payloads.
@@ -180,6 +191,7 @@ export function useScreencast(active = true): UseScreencastResult {
180
191
  targetId: state.targetId,
181
192
  frame,
182
193
  actions,
194
+ sessionId,
183
195
  selectTarget,
184
196
  reconnect,
185
197
  };
@@ -0,0 +1,117 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The composer half of the browser-panel bridge.
8
+ *
9
+ * The failure this guards is a prompt that names a page the agent cannot place.
10
+ * The block is produced by `shared/lib/browser/page-context` (its own tests pin
11
+ * the text); what is pinned HERE is the wiring: an event appends, two events do
12
+ * not overwrite, and a malformed batch degrades to the plain block instead of
13
+ * rendering `NaN%` into the draft.
14
+ *
15
+ * An annotated page sends NO attachment — the user panel's page is a
16
+ * cross-origin iframe, so there are no bytes to attach.
17
+ */
18
+
19
+ import { afterAll, afterEach, beforeAll, describe, expect, test } from 'bun:test';
20
+ import { Window } from 'happy-dom';
21
+ import { h, render } from 'preact';
22
+ import { act } from 'preact/test-utils';
23
+
24
+ import { useBrowserPageContextInsert } from '@/client/hooks/chat/composer/browser-context';
25
+ import { emitBrowserPageContext } from '@/shared/lib/browser/page-context';
26
+
27
+ const DOM_GLOBALS = ['window', 'document', 'navigator', 'Node', 'Element', 'HTMLElement', 'Event', 'CustomEvent'] as const;
28
+ const native: Partial<Record<(typeof DOM_GLOBALS)[number], unknown>> = {};
29
+
30
+ beforeAll(() => {
31
+ const win = new Window({ url: 'http://localhost' });
32
+ const target = globalThis as unknown as Record<string, unknown>;
33
+ for (const key of DOM_GLOBALS) {
34
+ if (!(key in native)) native[key] = target[key];
35
+ target[key] = (win as unknown as Record<string, unknown>)[key];
36
+ }
37
+ });
38
+
39
+ afterAll(() => {
40
+ const target = globalThis as unknown as Record<string, unknown>;
41
+ for (const key of DOM_GLOBALS) {
42
+ if (native[key] === undefined) delete target[key];
43
+ else target[key] = native[key];
44
+ }
45
+ });
46
+
47
+ let container: HTMLElement | undefined;
48
+ let draft = '';
49
+
50
+ /** Mount the bridge over a draft string, the way the composer wires it. */
51
+ function mountBridge(): void {
52
+ draft = '';
53
+ const Probe = () => {
54
+ useBrowserPageContextInsert((next) => {
55
+ draft = typeof next === 'function' ? next(draft) : next;
56
+ });
57
+ return h('div', null);
58
+ };
59
+ container = document.body.appendChild(document.createElement('div'));
60
+ act(() => {
61
+ render(h(Probe, null), container!);
62
+ });
63
+ }
64
+
65
+ afterEach(() => {
66
+ if (container) render(null, container);
67
+ container?.remove();
68
+ container = undefined;
69
+ });
70
+
71
+ describe('useBrowserPageContextInsert', () => {
72
+ test('a plain page lands in the draft as the URL block', () => {
73
+ mountBridge();
74
+ act(() => emitBrowserPageContext({ url: 'https://a.test/x' }));
75
+ expect(draft).toBe('[Konteks halaman browser]\nURL: https://a.test/x\n(Lanjutkan dari halaman ini.)');
76
+ });
77
+
78
+ test('an annotated page lands as the block with its numbered marks', () => {
79
+ mountBridge();
80
+ act(() => emitBrowserPageContext({
81
+ url: 'https://a.test/x',
82
+ annotations: [{ id: 'a', tool: 'box', start: { x: 0.1, y: 0.1 }, end: { x: 0.2, y: 0.2 }, label: '', note: 'mati' }],
83
+ panel: { width: 1000, height: 500, viewportMode: 'laptop', zoom: 100 },
84
+ }));
85
+ expect(draft).toContain('Anotasi (1):');
86
+ expect(draft).toContain('1. kotak kiri 10.0%, atas 10.0%');
87
+ expect(draft).toContain('— mati');
88
+ });
89
+
90
+ test('two events append two blocks rather than overwriting the draft', () => {
91
+ mountBridge();
92
+ act(() => emitBrowserPageContext({ url: 'https://a.test' }));
93
+ act(() => emitBrowserPageContext({ url: 'https://b.test' }));
94
+ expect(draft.match(/\[Konteks halaman browser\]/g)).toHaveLength(2);
95
+ expect(draft).toContain('https://a.test');
96
+ expect(draft).toContain('https://b.test');
97
+ });
98
+
99
+ test('a detail with no url is ignored rather than pasting an empty block', () => {
100
+ mountBridge();
101
+ act(() => emitBrowserPageContext({ url: '' }));
102
+ expect(draft).toBe('');
103
+ });
104
+
105
+ test('a malformed mark batch degrades to the plain page block, never to NaN%', () => {
106
+ mountBridge();
107
+ act(() => emitBrowserPageContext({
108
+ url: 'https://a.test',
109
+ // A shape missing `end`/`note`, as a hand-written event or an older
110
+ // dispatch could carry: the reader must refuse it, not format it.
111
+ annotations: [{ id: 'a', tool: 'box', start: { x: 1, y: 0 } } as never],
112
+ panel: { width: 1000, height: 500, viewportMode: 'laptop', zoom: 100 },
113
+ }));
114
+ expect(draft).not.toContain('Anotasi');
115
+ expect(draft).toContain('URL: https://a.test');
116
+ });
117
+ });
@@ -4,35 +4,59 @@
4
4
  */
5
5
 
6
6
  /**
7
- * Sibling-panel bridge: listens for the browser panel's "include page" event
8
- * and appends a structured page-context block to the chat draft. Lives beside
9
- * the timeline hooks because they own the persisted draft (`chat.draft`).
7
+ * Sibling-panel bridge: listens for a browser panel's "include page" event and
8
+ * appends its block to the chat draft. Lives beside the timeline hooks because
9
+ * they own the persisted draft (`chat.draft`).
10
+ *
11
+ * The TEXT is built by `shared/lib/browser/page-context`, not here: the same
12
+ * block is produced by the formatter's own tests, so a second spelling in the
13
+ * listener would let the annotated page and the plain page drift apart.
14
+ *
15
+ * An annotated page sends no attachment. The user panel's page is a
16
+ * cross-origin iframe, so there are no bytes to attach — what it sends is the
17
+ * region and the note, which the agent resolves by opening the URL itself.
10
18
  */
11
19
 
12
20
  import { useEffect, useRef } from 'preact/hooks';
13
- import { BROWSER_INCLUDE_PAGE_EVENT } from '@/shared/lib/browser/page-context';
14
- import { readString } from '@/shared/lib/browser/util';
21
+ import { BROWSER_INCLUDE_PAGE_EVENT, appendPageContext } from '@/shared/lib/browser/page-context';
22
+ import { readAnnotatePanel, readAnnotationShapes } from '@/shared/lib/browser/annotate';
15
23
  import { isRecord } from '@/shared/lib/util/guards';
24
+ import { readString } from '@/shared/lib/browser/util';
25
+ import type { BrowserPageContext } from '@/shared/types';
16
26
 
17
27
  type DraftSetter = (value: string | ((prev: string) => string)) => void;
18
28
 
19
- /** Append the browser page-context block to the composer draft on the panel event. */
29
+ /** The parts of a dispatched detail this bridge trusts, from a DOM event. */
30
+ export function readPageContextDetail(raw: unknown): BrowserPageContext | null {
31
+ if (!isRecord(raw)) return null;
32
+ const url = readString(raw, 'url');
33
+ if (!url) return null;
34
+ const title = readString(raw, 'title');
35
+ const detail: BrowserPageContext = { url };
36
+ if (title) detail.title = title;
37
+ // The marks are echoed back only when BOTH halves survive validation: a shape
38
+ // list without its panel box cannot be turned into percentages of anything,
39
+ // and a malformed batch degrades to the plain page context rather than to a
40
+ // prompt carrying a broken annotation section.
41
+ const annotations = readAnnotationShapes(raw.annotations);
42
+ const panel = readAnnotatePanel(raw.panel);
43
+ if (annotations && panel) {
44
+ detail.annotations = annotations;
45
+ detail.panel = panel;
46
+ }
47
+ return detail;
48
+ }
49
+
50
+ /** Append a page-context block to the composer draft on the panel event. */
20
51
  export function useBrowserPageContextInsert(setInputValue: DraftSetter): void {
21
52
  const setterRef = useRef(setInputValue);
22
53
  setterRef.current = setInputValue;
23
54
 
24
55
  useEffect(() => {
25
56
  const handler = (event: Event): void => {
26
- const detail = event instanceof CustomEvent ? event.detail : null;
27
- if (!isRecord(detail)) return;
28
- const url = readString(detail, 'url');
29
- if (!url) return;
30
- const title = readString(detail, 'title');
31
- setterRef.current((prev) => {
32
- const separator = prev && !prev.endsWith('\n') ? '\n\n' : prev ? '\n' : '';
33
- const titleLine = title ? `\nJudul: ${title}` : '';
34
- return `${prev}${separator}[Konteks halaman browser]\nURL: ${url}${titleLine}\n(Lanjutkan dari halaman ini.)`;
35
- });
57
+ const detail = event instanceof CustomEvent ? readPageContextDetail(event.detail) : null;
58
+ if (!detail) return;
59
+ setterRef.current((prev) => appendPageContext(prev, detail));
36
60
  };
37
61
  window.addEventListener(BROWSER_INCLUDE_PAGE_EVENT, handler);
38
62
  return () => window.removeEventListener(BROWSER_INCLUDE_PAGE_EVENT, handler);
@@ -255,7 +255,7 @@ describe('plugin commands in the popup', () => {
255
255
  describe('pick item mapping', () => {
256
256
  test('an agent becomes a bare @name token', () => {
257
257
  const [item] = toAgentPickItems([
258
- { id: 'a1', name: 'sonic', description: 'fast', scope: 'user', mode: 'primary', systemPrompt: '' },
258
+ { id: 'a1', name: 'sonic', description: 'fast', scope: 'user', systemPrompt: '' },
259
259
  ]);
260
260
  expect(item).toMatchObject({ id: 'agent-sonic', name: 'sonic', kind: 'agent', source: 'agent', token: '@sonic' });
261
261
  });
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Sibling-surface bridge: the editor's document review appended to the chat
8
+ * draft.
9
+ *
10
+ * A DOM event rather than shared state, for the same reason the browser panel's
11
+ * page context is one: the editor column and the chat timeline are separate
12
+ * trees, and the draft belongs to the timeline's own persisted hook
13
+ * (`chat.draft`). `formatReviewBlock` in `shared/lib/markdown/review/prompt.ts`
14
+ * owns the TEXT — two spellings of it is how the annotated document and the
15
+ * plain one start saying different things.
16
+ */
17
+
18
+ import { useEffect, useRef } from 'preact/hooks';
19
+
20
+ import { REVIEW_INCLUDE_EVENT, appendReviewBlock } from '@/shared/lib/markdown/review/prompt';
21
+
22
+ type DraftSetter = (value: string | ((prev: string) => string)) => void;
23
+
24
+ /** Append a review block to the composer draft on the editor's event. */
25
+ export function useReviewIncludeInsert(setInputValue: DraftSetter): void {
26
+ const setterRef = useRef(setInputValue);
27
+ setterRef.current = setInputValue;
28
+
29
+ useEffect(() => {
30
+ const handler = (event: Event): void => {
31
+ const block = event instanceof CustomEvent && typeof event.detail === 'string' ? event.detail : '';
32
+ if (!block) return;
33
+ setterRef.current((previous) => appendReviewBlock(previous, block));
34
+ };
35
+ window.addEventListener(REVIEW_INCLUDE_EVENT, handler);
36
+ return () => window.removeEventListener(REVIEW_INCLUDE_EVENT, handler);
37
+ }, []);
38
+ }
@@ -0,0 +1,132 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The composer draft's SCOPE: a chat named in the URL, or the landing.
8
+ *
9
+ * The reported bug this pins: text appended while no session was open (an
10
+ * annotation sent from the browser panel) was stored on the provider's fallback
11
+ * id — the landing's own bucket — which is not a chat and never gets cleared,
12
+ * because the landing composer is disabled and nothing can send or clear it.
13
+ * Every later launch then opened with that text already in the box, reading as
14
+ * something the new chat had inherited.
15
+ *
16
+ * A landing draft is therefore memory-only. The cases below mount the real
17
+ * provider id the way `App` derives it (`?sessionId=` else `'1'`), so the
18
+ * fallback bucket is still the landing's store — it is just not WRITTEN.
19
+ *
20
+ * The hook is imported DYNAMICALLY, after the DOM exists: `useSearchParams`
21
+ * caches the search string and subscribes to `popstate` when its module loads,
22
+ * so a static import (evaluated before any `beforeAll` runs) would leave the
23
+ * router unable to see the URL these cases set. The module-load boundary is the
24
+ * subject here, which is the documented exception to static imports.
25
+ */
26
+
27
+ import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test } from 'bun:test';
28
+ import { Window } from 'happy-dom';
29
+ import { h, render } from 'preact';
30
+ import { act } from 'preact/test-utils';
31
+
32
+ import { forgetSession, getSessionValue, setSessionKey } from '@/shared/lib/workspace/session-state/store';
33
+ import { emitBrowserPageContext } from '@/shared/lib/browser/page-context';
34
+ import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
35
+ import { CHAT_DRAFT_KEY } from '@/shared/lib/chat/composer/draft';
36
+ import type { Context } from 'preact';
37
+ import type { ComposerDraftState } from '@/client/hooks/chat/composer/use-draft';
38
+ import type { SessionStateContextValue } from '@/client/hooks/workspace/session-state/context';
39
+
40
+ const LANDING_ID = '1';
41
+ const SEEDED = '[Konteks halaman browser]\nURL: http://localhost:7801/\n(Lanjutkan dari halaman ini.)';
42
+
43
+ let container: HTMLElement | undefined;
44
+ let holder: { api: ComposerDraftState | null };
45
+ let useComposerDraft: () => ComposerDraftState;
46
+ let SessionStateContext: Context<SessionStateContextValue | null>;
47
+ const nativeFetch = globalThis.fetch;
48
+
49
+ beforeAll(async () => {
50
+ installDomGlobals(new Window({ url: 'http://127.0.0.1/' }));
51
+ ({ useComposerDraft } = await import('@/client/hooks/chat/composer/use-draft'));
52
+ ({ SessionStateContext } = await import('@/client/hooks/workspace/session-state/context'));
53
+ });
54
+
55
+ beforeEach(() => {
56
+ // Writes are debounced-persisted; a stray POST is not what these cases read.
57
+ globalThis.fetch = (async () => new Response('{"state":{}}')) as unknown as typeof fetch;
58
+ forgetSession(LANDING_ID);
59
+ holder = { api: null };
60
+ pointAt('');
61
+ });
62
+
63
+ afterEach(() => {
64
+ if (container) render(null, container);
65
+ container?.remove();
66
+ container = undefined;
67
+ forgetSession(LANDING_ID);
68
+ });
69
+
70
+ afterAll(() => {
71
+ // The router caches `location.search` in a module and subscribes to
72
+ // `popstate` on the window that existed when IT loaded — this suite's. Put
73
+ // that cache back to the bare path before the window goes away, or every
74
+ // later suite in the same `bun test` process reads `?sessionId=1` off a
75
+ // window nobody can reach any more (measured: the sidebar controller drew a
76
+ // stray `1` row).
77
+ pointAt('');
78
+ globalThis.fetch = nativeFetch;
79
+ restoreDomGlobals();
80
+ });
81
+
82
+ function pointAt(search: string): void {
83
+ window.history.replaceState(null, '', `/${search}`);
84
+ window.dispatchEvent(new Event('popstate'));
85
+ }
86
+
87
+ /** Mount the draft hook for one URL, with the provider id `App` derives. */
88
+ function mount(search: string): void {
89
+ pointAt(search);
90
+ const sessionId = new URLSearchParams(search).get('sessionId') || LANDING_ID;
91
+ function Probe() {
92
+ holder.api = useComposerDraft();
93
+ return null;
94
+ }
95
+ container = document.body.appendChild(document.createElement('div'));
96
+ act(() => {
97
+ render(
98
+ h(SessionStateContext.Provider, { value: { sessionId, ready: true }, children: h(Probe, null) }),
99
+ container!,
100
+ );
101
+ });
102
+ }
103
+
104
+ describe('useComposerDraft', () => {
105
+ test('the landing does not restore the fallback bucket\'s draft', () => {
106
+ setSessionKey(LANDING_ID, CHAT_DRAFT_KEY, SEEDED);
107
+ mount('');
108
+ expect(holder.api!.inputValue).toBe('');
109
+ });
110
+
111
+ test('a landing draft is kept in memory and never written to a session slot', () => {
112
+ mount('');
113
+ act(() => holder.api!.setInputValue('typed at the landing'));
114
+ expect(holder.api!.inputValue).toBe('typed at the landing');
115
+ expect(getSessionValue(LANDING_ID, CHAT_DRAFT_KEY)).toBeUndefined();
116
+ });
117
+
118
+ test('an annotation sent at the landing stays out of the persisted draft', () => {
119
+ mount('');
120
+ act(() => emitBrowserPageContext({ url: 'https://a.test/x' }));
121
+ expect(holder.api!.inputValue).toContain('[Konteks halaman browser]');
122
+ expect(getSessionValue(LANDING_ID, CHAT_DRAFT_KEY)).toBeUndefined();
123
+ });
124
+
125
+ test('a session named in the URL still restores and persists its own draft', () => {
126
+ setSessionKey(LANDING_ID, CHAT_DRAFT_KEY, SEEDED);
127
+ mount(`?sessionId=${LANDING_ID}`);
128
+ expect(holder.api!.inputValue).toBe(SEEDED);
129
+ act(() => holder.api!.setInputValue('follow-up'));
130
+ expect(getSessionValue(LANDING_ID, CHAT_DRAFT_KEY)).toBe('follow-up');
131
+ });
132
+ });