@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,80 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The frame pipeline between the CDP reader and the SSE stream: one place that
8
+ * decides WHICH picture the panel gets, and one that decides how often.
9
+ *
10
+ * Both halves exist because a screencast alone cannot be trusted to produce a
11
+ * first frame. Chromium only pushes `Page.screencastFrame` when the page paints,
12
+ * so an idle tab — the normal state of a tab an agent finished with — sends
13
+ * nothing and the panel sits on "Menunggu frame pertama dari browser…" forever.
14
+ * Measured on Chromium 1248: a static page attached to and left alone delivered
15
+ * zero frames at any `everyNthFrame`, while `Page.captureScreenshot` answered in
16
+ * 8–40 ms with the page's real pixels, background tab or not (`snapshot.ts`).
17
+ *
18
+ * So the pipeline is: a snapshot seeds the view while the page has painted
19
+ * nothing for us, a live frame always beats a snapshot that is still in flight,
20
+ * and the rate gate defers — never discards — the newest frame.
21
+ */
22
+
23
+ import type { CdpConnection } from '@/shared/lib/browser/cdp';
24
+ import { FRAME_MIN_INTERVAL_MS } from '@/shared/lib/browser/frame-params';
25
+ import { createFrameGate } from '@/shared/lib/browser/frame-gate';
26
+ import { createFrameSeeder } from '@/shared/lib/browser/snapshot';
27
+ import type { BrowserViewFrame } from '@/shared/types';
28
+
29
+ export interface FramePipeline {
30
+ /** The attached tab changed: forget the pixels and the clock. */
31
+ reset: () => void;
32
+ /** A `Page.screencastFrame` arrived for the attached tab. */
33
+ pushLive: (frame: BrowserViewFrame) => void;
34
+ /**
35
+ * Take a snapshot unless a picture has already crossed downstream. Safe to
36
+ * call from the poll loop: a capture already in flight is not stacked.
37
+ */
38
+ seed: () => void;
39
+ /** A load settled: the new page counts as unpainted, so seed again. */
40
+ seedAfterLoad: () => void;
41
+ }
42
+
43
+ /** `readAttached` is null while nothing is attached (no snapshot possible). */
44
+ export function createFramePipeline(
45
+ conn: CdpConnection,
46
+ readAttached: () => { sessionId: string; targetId: string } | null,
47
+ emit: (frame: BrowserViewFrame) => void,
48
+ ): FramePipeline {
49
+ // Whether any picture (snapshot or live) has crossed downstream for the
50
+ // attached page. Only the downstream sink sets it, so a frame the rate gate
51
+ // is still holding counts as delivered — it will land within a frame budget.
52
+ let painted = false;
53
+ const deliver = (frame: BrowserViewFrame): void => {
54
+ painted = true;
55
+ emit(frame);
56
+ };
57
+ const gate = createFrameGate(deliver, FRAME_MIN_INTERVAL_MS);
58
+ const seeder = createFrameSeeder(conn, readAttached, deliver);
59
+
60
+ return {
61
+ reset: () => {
62
+ painted = false;
63
+ gate.reset();
64
+ seeder.invalidate();
65
+ },
66
+ pushLive: (frame) => {
67
+ // A live frame is newer than any snapshot still in flight: cancel it.
68
+ seeder.invalidate();
69
+ gate.push(frame);
70
+ },
71
+ seed: () => {
72
+ if (painted) return;
73
+ seeder.seed();
74
+ },
75
+ seedAfterLoad: () => {
76
+ painted = false;
77
+ seeder.seed();
78
+ },
79
+ };
80
+ }
@@ -4,17 +4,73 @@
4
4
  */
5
5
 
6
6
  /**
7
- * Sibling-panel bridge that hands the AGENT browser's current page to the chat
8
- * composer. The agent panel and the chat timeline are separate trees, so the
9
- * page is passed through a DOM event rather than shared React state.
7
+ * Sibling-panel bridge that hands a browser panel's page to the chat composer.
8
+ *
9
+ * The panel and the chat timeline are separate trees, so the page travels as a
10
+ * DOM event rather than shared React state. This module owns BOTH halves of
11
+ * that contract: the event, and the exact text a page context becomes in the
12
+ * draft (`formatPageContextBlock`). The formatter lives here rather than in the
13
+ * listener because the same block is read back by tests and by anyone
14
+ * re-dispatching the event; two spellings of it is how the shared page and the
15
+ * annotated page start saying different things.
10
16
  */
11
17
 
12
18
  import type { BrowserPageContext } from '@/shared/types';
19
+ import { describeAnnotations } from '@/shared/lib/browser/annotate';
13
20
 
14
- /** DOM event the agent browser panel dispatches to append page context to the draft. */
21
+ /** DOM event the browser panels dispatch to append page context to the draft. */
15
22
  export const BROWSER_INCLUDE_PAGE_EVENT = 'omp:browser-include-page';
16
23
 
17
24
  export function emitBrowserPageContext(detail: BrowserPageContext): void {
18
25
  if (typeof window === 'undefined') return;
19
26
  window.dispatchEvent(new CustomEvent<BrowserPageContext>(BROWSER_INCLUDE_PAGE_EVENT, { detail }));
20
27
  }
28
+
29
+ /**
30
+ * The block a page context adds to the composer draft.
31
+ *
32
+ * The trailing instruction is what makes a bare URL useful: the agent's browser
33
+ * is its own, so "continue from this page" would otherwise be a claim about a
34
+ * page the agent never loaded. With marks attached the block also states that
35
+ * only the user can see the page — the marks are coordinates, not a picture —
36
+ * so the agent knows to open the URL itself before acting.
37
+ */
38
+ export function formatPageContextBlock(detail: BrowserPageContext): string {
39
+ const lines = ['[Konteks halaman browser]', `URL: ${detail.url}`];
40
+ if (detail.title) lines.push(`Judul: ${detail.title}`);
41
+
42
+ const panel = detail.panel;
43
+ const description = detail.annotations && panel
44
+ ? describeAnnotations(detail.annotations, panel)
45
+ : [];
46
+ if (panel && detail.annotations) {
47
+ lines.push(`Panel: ${panel.viewportMode} ${Math.round(panel.width)}×${Math.round(panel.height)} px @${panel.zoom}%`);
48
+ }
49
+ if (description.length > 0 && panel) {
50
+ lines.push(`Anotasi (${description.length}):`, ...description);
51
+ lines.push('Halaman ini hanya terlihat oleh user — buka URL di atas sendiri sebelum mengubah apa pun.');
52
+ // The coordinates are fractions of the panel the user was looking at, not
53
+ // of whatever viewport the agent opens. Saying so is what lets the agent
54
+ // resolve them (`elementFromPoint` at the same box, or scaled) instead of
55
+ // treating a percentage as an absolute position.
56
+ lines.push(
57
+ `Koordinat relatif ke viewport ${Math.round(panel.width)}×${Math.round(panel.height)} px; pakai ukuran yang sama saat membuka halaman ini, lalu cari elemennya di titik itu.`,
58
+ );
59
+ }
60
+ lines.push('(Lanjutkan dari halaman ini.)');
61
+ return lines.join('\n');
62
+ }
63
+
64
+ /**
65
+ * Append one page-context block to an existing draft.
66
+ *
67
+ * A blank draft gets the block alone; otherwise it is separated by one blank
68
+ * line, so two "include page" clicks read as two blocks instead of one run-on
69
+ * paragraph.
70
+ */
71
+ export function appendPageContext(previous: string, detail: BrowserPageContext): string {
72
+ const block = formatPageContextBlock(detail);
73
+ if (!previous) return block;
74
+ const separator = previous.endsWith('\n\n') ? '' : previous.endsWith('\n') ? '\n' : '\n\n';
75
+ return `${previous}${separator}${block}`;
76
+ }
@@ -0,0 +1,115 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The snapshot that seeds the panel.
8
+ *
9
+ * `Page.startScreencast` pushes a frame only when the page PAINTS, so an idle
10
+ * tab sends nothing and the panel waited on "Menunggu frame pertama dari
11
+ * browser…" indefinitely (measured on Chromium 1248 for a static page, and for
12
+ * a page that changed once and went idle — see `frame-pipeline.ts`). The
13
+ * snapshot is the fix, and these pin its two contracts: it is boxed like the
14
+ * screencast, and a live frame that lands first wins.
15
+ */
16
+
17
+ import { afterEach, beforeEach, describe, expect, jest, test } from 'bun:test';
18
+
19
+ import type { CdpConnection } from '@/shared/lib/browser/cdp';
20
+ import type { FrameSeeder } from '@/shared/lib/browser/snapshot';
21
+ import { createFrameSeeder } from '@/shared/lib/browser/snapshot';
22
+ import type { BrowserViewFrame } from '@/shared/types';
23
+
24
+ type Reply = unknown | Error;
25
+
26
+ /** Minimal CDP connection: answers from a table, records what was asked. */
27
+ function fakeConnection(replies: Record<string, Reply>) {
28
+ const sent: Array<{ method: string; params: Record<string, unknown>; sessionId?: string }> = [];
29
+ const conn = {
30
+ send: (method: string, params: Record<string, unknown> = {}, sessionId?: string) => {
31
+ sent.push({ method, params, sessionId });
32
+ const reply = replies[method];
33
+ return reply instanceof Error ? Promise.reject(reply) : Promise.resolve(reply);
34
+ },
35
+ };
36
+ return { conn: conn as unknown as CdpConnection, sent };
37
+ }
38
+
39
+ const ATTACHED = { sessionId: 'S1', targetId: 'T1' };
40
+
41
+ async function settle(): Promise<void> {
42
+ for (let i = 0; i < 8; i += 1) await Promise.resolve();
43
+ }
44
+
45
+ describe('createFrameSeeder', () => {
46
+ beforeEach(() => {
47
+ jest.useFakeTimers();
48
+ jest.setSystemTime(0);
49
+ });
50
+
51
+ afterEach(() => {
52
+ jest.useRealTimers();
53
+ });
54
+
55
+ function seeder(conn: CdpConnection, frames: BrowserViewFrame[], attached: typeof ATTACHED | null = ATTACHED): FrameSeeder {
56
+ return createFrameSeeder(conn, () => attached, (frame) => frames.push(frame));
57
+ }
58
+
59
+ test('captures the attached page clipped and scaled into the frame box', async () => {
60
+ const { conn, sent } = fakeConnection({
61
+ 'Page.getLayoutMetrics': { cssVisualViewport: { clientWidth: 1600, clientHeight: 1000 } },
62
+ 'Page.captureScreenshot': { data: 'SNAP' },
63
+ });
64
+ const frames: BrowserViewFrame[] = [];
65
+ seeder(conn, frames).seed();
66
+ await settle();
67
+ const capture = sent.find((entry) => entry.method === 'Page.captureScreenshot');
68
+ expect(capture?.params).toEqual({
69
+ format: 'jpeg',
70
+ quality: 60,
71
+ clip: { x: 0, y: 0, width: 1600, height: 1000, scale: 0.8 },
72
+ captureBeyondViewport: false,
73
+ });
74
+ expect(capture?.sessionId).toBe('S1');
75
+ expect(frames).toEqual([{ data: 'SNAP', mimeType: 'image/jpeg', targetId: 'T1' }]);
76
+ });
77
+
78
+ test('captures without a clip when the page will not report a viewport', async () => {
79
+ const { conn, sent } = fakeConnection({ 'Page.captureScreenshot': { data: 'SNAP' } });
80
+ const frames: BrowserViewFrame[] = [];
81
+ seeder(conn, frames).seed();
82
+ await settle();
83
+ const capture = sent.find((entry) => entry.method === 'Page.captureScreenshot');
84
+ expect(capture?.params).toEqual({ format: 'jpeg', quality: 60, captureBeyondViewport: false });
85
+ expect(frames).toHaveLength(1);
86
+ });
87
+
88
+ test('a refused capture emits nothing and keeps the previous pixels', async () => {
89
+ const { conn } = fakeConnection({ 'Page.captureScreenshot': new Error('no compositor') });
90
+ const frames: BrowserViewFrame[] = [];
91
+ seeder(conn, frames).seed();
92
+ await settle();
93
+ expect(frames).toEqual([]);
94
+ });
95
+
96
+ test('a live frame that landed first wins over the late snapshot', async () => {
97
+ const { conn } = fakeConnection({ 'Page.captureScreenshot': { data: 'SNAP' } });
98
+ const frames: BrowserViewFrame[] = [];
99
+ const target = seeder(conn, frames);
100
+ target.seed();
101
+ // The page painted while the capture was in flight.
102
+ target.invalidate();
103
+ await settle();
104
+ expect(frames).toEqual([]);
105
+ });
106
+
107
+ test('nothing is captured while no tab is attached', async () => {
108
+ const { conn, sent } = fakeConnection({ 'Page.captureScreenshot': { data: 'SNAP' } });
109
+ const frames: BrowserViewFrame[] = [];
110
+ seeder(conn, frames, null).seed();
111
+ await settle();
112
+ expect(sent).toEqual([]);
113
+ expect(frames).toEqual([]);
114
+ });
115
+ });
@@ -0,0 +1,112 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The one-off snapshot that seeds the panel before the screencast can paint.
8
+ *
9
+ * `Page.startScreencast` only pushes frames when the page PRODUCES a new one.
10
+ * A tab the agent finished with is static, and Chromium measures a burst: a
11
+ * page that is attached to and left alone delivers **zero** `Page.screencastFrame`
12
+ * events no matter which `everyNthFrame` is asked for (Chromium 1248, both
13
+ * `chrome-headless-shell` and `--headless=new`; a page that changed once and
14
+ * went idle likewise stayed on the previous pixels at `everyNthFrame: 2`).
15
+ * So the panel sat on "Menunggu frame pertama dari browser…" for a live tab
16
+ * that simply had nothing to redraw.
17
+ *
18
+ * `Page.captureScreenshot` is unaffected: measured on the same build it
19
+ * answers for a BACKGROUND tab (a neighbouring page focused, so the surface is
20
+ * no longer composited on screen), for a just-navigated tab, and in 8–40 ms.
21
+ * Decoded with ffmpeg, the pixels are the page's own — yellow `#ffff00` for a
22
+ * background tab painted yellow, magenta after it navigated to magenta — not a
23
+ * blank surface. This module is that call, boxed to the screencast's size so
24
+ * the snapshot and the first live frame line up instead of popping.
25
+ */
26
+
27
+ import type { CdpConnection } from '@/shared/lib/browser/cdp';
28
+ import { FRAME_QUALITY, frameScale } from '@/shared/lib/browser/frame-params';
29
+ import { readNumber, readString } from '@/shared/lib/browser/util';
30
+ import { isRecord } from '@/shared/lib/util/guards';
31
+ import type { BrowserViewFrame } from '@/shared/types';
32
+
33
+ /** CSS viewport size of the attached page, or null when the page will not say. */
34
+ async function readViewport(conn: CdpConnection, sessionId: string): Promise<{ width: number; height: number } | null> {
35
+ const metrics = await conn.send('Page.getLayoutMetrics', {}, sessionId).catch(() => null);
36
+ if (!isRecord(metrics)) return null;
37
+ const viewport = isRecord(metrics.cssVisualViewport) ? metrics.cssVisualViewport : metrics;
38
+ const width = readNumber(viewport, 'clientWidth');
39
+ const height = readNumber(viewport, 'clientHeight');
40
+ if (!width || !height) return null;
41
+ return { width, height };
42
+ }
43
+
44
+ /**
45
+ * Capture one JPEG of the attached page, scaled into the frame box.
46
+ *
47
+ * Best-effort by contract: a page that refuses (crash, no compositor) yields
48
+ * null and the caller falls back to waiting for a live frame. The clip is the
49
+ * whole viewport at `frameScale`, which is the only knob that makes a snapshot
50
+ * honour `maxWidth`/`maxHeight` — `captureScreenshot` has no such parameter.
51
+ */
52
+ export async function captureFrame(
53
+ conn: CdpConnection,
54
+ sessionId: string,
55
+ targetId: string,
56
+ ): Promise<BrowserViewFrame | null> {
57
+ const viewport = await readViewport(conn, sessionId);
58
+ const clip = viewport
59
+ ? { x: 0, y: 0, width: viewport.width, height: viewport.height, scale: frameScale(viewport.width, viewport.height) }
60
+ : undefined;
61
+ const captured = await conn
62
+ .send('Page.captureScreenshot', { format: 'jpeg', quality: FRAME_QUALITY, ...(clip ? { clip } : {}), captureBeyondViewport: false }, sessionId)
63
+ .catch(() => null);
64
+ const data = isRecord(captured) ? readString(captured, 'data') : undefined;
65
+ if (!data) return null;
66
+ return { data, mimeType: 'image/jpeg', targetId };
67
+ }
68
+
69
+ export interface FrameSeeder {
70
+ /** Snapshot the attached page now; a live frame landing first wins. */
71
+ seed: () => void;
72
+ /** A live frame arrived (or the tab changed): drop any snapshot in flight. */
73
+ invalidate: () => void;
74
+ }
75
+
76
+ /**
77
+ * Snapshot scheduling for one viewer.
78
+ *
79
+ * `seed()` is what removes the "waiting for the first frame" hang: it is called
80
+ * on attach and after a load, the two moments the page will not push a frame
81
+ * of its own. A snapshot that was overtaken by a live frame is DISCARDED —
82
+ * those pixels are newer, and repainting them would show the older page.
83
+ */
84
+ export function createFrameSeeder(
85
+ conn: CdpConnection,
86
+ readAttached: () => { sessionId: string; targetId: string } | null,
87
+ emit: (frame: BrowserViewFrame) => void,
88
+ ): FrameSeeder {
89
+ let generation = 0;
90
+ let inFlight = false;
91
+ return {
92
+ seed: () => {
93
+ const attached = readAttached();
94
+ // A retry loop (the viewer asks again each tick until a picture lands)
95
+ // must not stack captures: one is in flight, the next one starts after.
96
+ if (!attached || inFlight) return;
97
+ generation += 1;
98
+ const mine = generation;
99
+ inFlight = true;
100
+ void captureFrame(conn, attached.sessionId, attached.targetId)
101
+ .then((frame) => {
102
+ if (frame && mine === generation) emit(frame);
103
+ })
104
+ .finally(() => {
105
+ inFlight = false;
106
+ });
107
+ },
108
+ invalidate: () => {
109
+ generation += 1;
110
+ },
111
+ };
112
+ }
@@ -0,0 +1,74 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * What "close this tab" means for the agent's browser.
8
+ *
9
+ * The rules are shared by the route and the panel, and both halves matter:
10
+ * a target id from ANOTHER session must be refused (the daemon is
11
+ * project-shared), and the tab the panel watches after a close must be the
12
+ * neighbour, not whichever page happens to be newest.
13
+ */
14
+
15
+ import { describe, expect, test } from 'bun:test';
16
+
17
+ import { closeVerdict, neighbourTargetId, readCloseTarget } from '@/shared/lib/browser/tab-close';
18
+
19
+ describe('readCloseTarget', () => {
20
+ test('accepts an opaque target id', () => {
21
+ expect(readCloseTarget('3A863DE80D88040BA983CA1949531524')).toBe('3A863DE80D88040BA983CA1949531524');
22
+ expect(readCloseTarget(' ABC123 ')).toBe('ABC123');
23
+ });
24
+
25
+ test('rejects anything that is not a bare id', () => {
26
+ expect(readCloseTarget(undefined)).toBeNull();
27
+ expect(readCloseTarget(null)).toBeNull();
28
+ expect(readCloseTarget('')).toBeNull();
29
+ expect(readCloseTarget(42)).toBeNull();
30
+ expect(readCloseTarget({ targetId: 'x' })).toBeNull();
31
+ expect(readCloseTarget('a b')).toBeNull();
32
+ expect(readCloseTarget('../escape')).toBeNull();
33
+ expect(readCloseTarget('a:b')).toBeNull();
34
+ expect(readCloseTarget('x'.repeat(129))).toBeNull();
35
+ });
36
+ });
37
+
38
+ describe('closeVerdict', () => {
39
+ test('closes a tab this session owns and reports the survivors', () => {
40
+ expect(closeVerdict('mine-2', ['mine-1', 'mine-2', 'mine-3'])).toEqual({
41
+ ok: true,
42
+ remaining: ['mine-1', 'mine-3'],
43
+ });
44
+ });
45
+
46
+ test('refuses a tab another session owns, and keeps the list intact', () => {
47
+ const verdict = closeVerdict('other-1', ['mine-1']);
48
+ expect(verdict.ok).toBe(false);
49
+ expect(verdict.reason).toContain('does not belong to this session');
50
+ expect(verdict.remaining).toEqual(['mine-1']);
51
+ });
52
+
53
+ test('a session with no tabs refuses everything', () => {
54
+ expect(closeVerdict('mine-1', []).ok).toBe(false);
55
+ });
56
+ });
57
+
58
+ describe('neighbourTargetId', () => {
59
+ test('prefers the tab to the right, in registry (creation) order', () => {
60
+ expect(neighbourTargetId(['a', 'b', 'c'], 'b')).toBe('c');
61
+ });
62
+
63
+ test('falls back to the left when the closed tab was the newest', () => {
64
+ expect(neighbourTargetId(['a', 'b', 'c'], 'c')).toBe('b');
65
+ });
66
+
67
+ test('nothing left to select when the last tab closes', () => {
68
+ expect(neighbourTargetId(['only'], 'only')).toBeNull();
69
+ });
70
+
71
+ test('an id outside the list names no neighbour', () => {
72
+ expect(neighbourTargetId(['a'], 'nope')).toBeNull();
73
+ });
74
+ });
@@ -0,0 +1,77 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * What "close this tab" MEANS for the agent's browser, decided once.
8
+ *
9
+ * A session's omp agent routinely opens several pages in the project-shared
10
+ * Chromium, and a finished tab keeps costing the panel: the viewer attaches to
11
+ * the newest owned target, so every stale tab is one more reason the panel
12
+ * shows the wrong page, and it keeps its renderer alive in the daemon.
13
+ *
14
+ * Two rules live here because both the route and the panel need them and a
15
+ * second copy would drift:
16
+ *
17
+ * - **Only the session's OWN tabs are closable.** The daemon is project-shared,
18
+ * so a target id from another session must be refused by name rather than
19
+ * attempted (`pickTargetId`/`ownedPages` already scope the view this way).
20
+ * - **`Target.closeTarget` is the whole close.** Measured on Chromium 1248
21
+ * against a tab that is mid-screencast: it answers `{"success":true}`, the
22
+ * browser socket STAYS OPEN, the attached session dies on its own
23
+ * (`Page.stopScreencast` then answers "Session with given id not found" and
24
+ * `Target.detachedFromTarget` arrives browser-level), and the remaining tabs
25
+ * are still attachable. So the viewer needs no special teardown — but it does
26
+ * need to know the page it was watching is gone, which the 1s target poll
27
+ * already covers.
28
+ */
29
+
30
+ /** The tab id the client asks to close, or null when it is not a usable id. */
31
+ export function readCloseTarget(value: unknown): string | null {
32
+ if (typeof value !== 'string') return null;
33
+ const targetId = value.trim();
34
+ // A CDP target id is an opaque hex string; anything with whitespace or a
35
+ // path separator is a caller bug, not a tab.
36
+ if (!targetId || targetId.length > 128) return null;
37
+ if (/[\s/\\:]/.test(targetId)) return null;
38
+ return targetId;
39
+ }
40
+
41
+ export interface CloseVerdict {
42
+ ok: boolean;
43
+ /** Present when `ok` is false: why the tab was not closed. */
44
+ reason?: string;
45
+ /** Tabs that survive the close, in registry order. */
46
+ remaining: string[];
47
+ }
48
+
49
+ /**
50
+ * Decide whether `targetId` may be closed, given what this session owns.
51
+ *
52
+ * `ownedIds` is the on-disk registry read, so a tab another session opened is
53
+ * not merely "not listed here" — it is refused, and the refusal names the
54
+ * ownership rule so a client bug does not look like a browser failure.
55
+ */
56
+ export function closeVerdict(targetId: string, ownedIds: readonly string[]): CloseVerdict {
57
+ const remaining = ownedIds.filter((id) => id !== targetId);
58
+ if (!ownedIds.includes(targetId)) {
59
+ return { ok: false, reason: 'That tab does not belong to this session', remaining: [...ownedIds] };
60
+ }
61
+ return { ok: true, remaining };
62
+ }
63
+
64
+ /**
65
+ * Which tab the panel should watch after `closed` is gone: the neighbour to its
66
+ * RIGHT in registry order (the newest remaining owned tab), else the one to its
67
+ * left, else nothing.
68
+ *
69
+ * Deliberately not "always the newest": the registry is in creation order, so
70
+ * after closing one of several tabs the user is looking at, staying put in that
71
+ * region is what keeps the panel on the page they were watching.
72
+ */
73
+ export function neighbourTargetId(ownedIds: readonly string[], closed: string): string | null {
74
+ const index = ownedIds.indexOf(closed);
75
+ if (index === -1) return null;
76
+ return ownedIds[index + 1] ?? ownedIds[index - 1] ?? null;
77
+ }
@@ -26,31 +26,12 @@ import { CdpConnection } from '@/shared/lib/browser/cdp';
26
26
  import { acquireConnection, releaseConnection } from '@/shared/lib/browser/connection';
27
27
  import { OBSERVER_BINDING, installObserver, parseObserverPayload, type ObserverHandle } from '@/shared/lib/browser/observer';
28
28
  import { ownedPages, parsePageTargets, pickTargetId, readTargetInfoPatch, type PageTarget } from '@/shared/lib/browser/targets';
29
+ import { SCREENCAST_PARAMS } from '@/shared/lib/browser/frame-params';
30
+ import { createFramePipeline, type FramePipeline } from '@/shared/lib/browser/frame-pipeline';
29
31
  import { readNumber, readString } from '@/shared/lib/browser/util';
30
32
  import { isRecord } from '@/shared/lib/util/guards';
31
33
  import { BROWSER_POLL_MS } from '@/shared/lib/workspace/refresh-cadence';
32
34
 
33
- /**
34
- * What the stream asks the page for.
35
- *
36
- * `everyNthFrame: 1` (every frame) is what the panel used to request, and it is
37
- * the wrong default for a viewer that is watched, not sampled: a 30 fps page
38
- * produced 30 decodes a second, each one a full RGBA surface the renderer has to
39
- * allocate and free. Measured in WebKit with the canvas sink in place, 1 760
40
- * frames at 16 fps still cost ~8 KB of WebContent footprint per frame, so the
41
- * frame RATE is a real lever on top of the sink (`client/lib/browser/frame-canvas.ts`).
42
- * Every second frame keeps the motion readable at half the decodes, and the
43
- * size is the panel's own display width — 1 600 px was above every panel width
44
- * the app renders, so it was only ever downscaled.
45
- */
46
- const SCREENCAST_PARAMS = {
47
- format: 'jpeg',
48
- quality: 60,
49
- maxWidth: 1280,
50
- maxHeight: 800,
51
- everyNthFrame: 2,
52
- };
53
-
54
35
  interface ScreencastOptions {
55
36
  /** Caller's preferred tab id; honored while it is still a live, owned page. */
56
37
  preferTargetId?: string;
@@ -102,10 +83,16 @@ class ScreencastSession {
102
83
  private unsubscribeClose: (() => void) | null = null;
103
84
  private ticking = false;
104
85
  private _closed = false;
86
+ private readonly frames: FramePipeline;
105
87
 
106
88
  constructor(conn: CdpConnection, opts: ScreencastOptions) {
107
89
  this.conn = conn;
108
90
  this.opts = opts;
91
+ this.frames = createFramePipeline(
92
+ conn,
93
+ () => (this.currentSessionId && this.currentTargetId ? { sessionId: this.currentSessionId, targetId: this.currentTargetId } : null),
94
+ (frame) => this.emitFrame(frame),
95
+ );
109
96
  }
110
97
 
111
98
  get closed(): boolean {
@@ -148,6 +135,7 @@ class ScreencastSession {
148
135
  this.targets = targets;
149
136
  const nextTargetId = pickTargetId(targets, ownedIds, this.opts.preferTargetId);
150
137
  if (nextTargetId !== this.currentTargetId) await this.switchTarget(nextTargetId);
138
+ else this.frames.seed();
151
139
  this.emitCurrent();
152
140
  } catch {
153
141
  this.fail();
@@ -168,13 +156,32 @@ class ScreencastSession {
168
156
  if (!sessionId) throw new Error('CDP attachToTarget returned no session id');
169
157
  this.currentTargetId = nextTargetId;
170
158
  this.currentSessionId = sessionId;
159
+ this.frames.reset();
171
160
  this.observer = await installObserver(this.conn, sessionId).catch(() => null);
172
161
  try {
162
+ // Page.loadEventFired is only delivered once the domain is enabled; the
163
+ // observer enables it too, but that install is best-effort and must not
164
+ // be what the snapshot depends on.
165
+ await this.conn.send('Page.enable', {}, sessionId).catch(() => {});
173
166
  await this.conn.send('Page.startScreencast', SCREENCAST_PARAMS, sessionId);
174
167
  } catch (error) {
175
168
  await this.detach();
176
169
  throw error;
177
170
  }
171
+ // The page has nothing to redraw right now — it may never push a frame
172
+ // until the agent touches it — so take a snapshot instead of spinning on
173
+ // "waiting for the first frame" (`frame-pipeline.ts` measures why).
174
+ this.frames.seed();
175
+ }
176
+
177
+ /** What actually crosses to the SSE stream. */
178
+ private emitFrame(frame: BrowserViewFrame): void {
179
+ if (this._closed) return;
180
+ try {
181
+ this.opts.onFrame(frame);
182
+ } catch {
183
+ // Subscriber bugs (SSE encode failure) must not break frame acking.
184
+ }
178
185
  }
179
186
 
180
187
  private async detach(): Promise<void> {
@@ -204,6 +211,10 @@ class ScreencastSession {
204
211
  this.handleFrameNavigated(params, sessionId);
205
212
  return;
206
213
  }
214
+ if (method === 'Page.loadEventFired') {
215
+ this.handleLoadEvent(sessionId);
216
+ return;
217
+ }
207
218
  if (method === 'Target.targetInfoChanged') {
208
219
  const patch = readTargetInfoPatch(params);
209
220
  if (!patch) return;
@@ -231,6 +242,18 @@ class ScreencastSession {
231
242
  this.emitAction({ kind: 'loaded', label: `Halaman dimuat: ${shortUrl(url)}` });
232
243
  }
233
244
 
245
+ /**
246
+ * A load settled: the page is idle now and may push nothing until the agent
247
+ * touches it, so take the picture. `Page.loadEventFired` is the signal a
248
+ * viewer session actually receives — measured on Chromium 1248, a
249
+ * background navigation delivers it (plus `domContentEventFired`) even
250
+ * though the screencast stays silent, and a 1.2s wait is enough.
251
+ */
252
+ private handleLoadEvent(sessionId?: string): void {
253
+ if (!sessionId || sessionId !== this.currentSessionId) return;
254
+ this.frames.seedAfterLoad();
255
+ }
256
+
234
257
  private emitAction(action: BrowserActionDraft): void {
235
258
  try {
236
259
  this.opts.onAction?.(action);
@@ -253,11 +276,7 @@ class ScreencastSession {
253
276
  mimeType: 'image/jpeg',
254
277
  targetId: this.currentTargetId ?? '',
255
278
  };
256
- try {
257
- this.opts.onFrame(frame);
258
- } catch {
259
- // Subscriber bugs (SSE encode failure) must not break frame acking.
260
- }
279
+ this.frames.pushLive(frame);
261
280
  }
262
281
 
263
282
  private emitCurrent(): void {