@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,229 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Reading the element under a mark.
8
+ *
9
+ * Two rules are pinned here, and they are the ones that keep the panel honest:
10
+ *
11
+ * - A cross-origin frame answers a REASON, never an element and never a blank.
12
+ * Measured in Chromium, `127.0.0.1:7101` embedding `127.0.0.1:7102` reports
13
+ * `contentDocument === null`; the same origin reports a live document.
14
+ * - A `<select>` reports its CHOSEN VALUE and option count. That is the fact a
15
+ * screenshot cannot give an agent and a user would have to type out — and it
16
+ * is why the user-browser panel asks for elements at all.
17
+ */
18
+
19
+ import { afterAll, beforeAll, beforeEach, describe, expect, test } from 'bun:test';
20
+ import { Window } from 'happy-dom';
21
+
22
+ import { describeElement, elementAtPoint, elementPath, frameReadability } from '@/client/lib/browser/element-at';
23
+
24
+ const DOM_GLOBALS = ['window', 'document', 'navigator', 'Node', 'Element', 'HTMLElement', 'HTMLSelectElement'] as const;
25
+ const native: Partial<Record<(typeof DOM_GLOBALS)[number], unknown>> = {};
26
+
27
+ let win: Window;
28
+ /**
29
+ * The fixture document, typed as the runner's `lib.dom` `Document`.
30
+ *
31
+ * The cast is the whole point of the harness: happy-dom's `Document` is a
32
+ * different type from `lib.dom`'s (it lacks `currentCSSZoom`, `part` and the
33
+ * rest), while at runtime it is the object `highlight` reads. Typing it as
34
+ * happy-dom's own class would force every `createElement` result through a
35
+ * second cast.
36
+ */
37
+ let doc: Document;
38
+
39
+ beforeAll(() => {
40
+ win = new Window({ url: 'http://localhost' });
41
+ const target = globalThis as unknown as Record<string, unknown>;
42
+ for (const key of DOM_GLOBALS) {
43
+ if (!(key in native)) native[key] = target[key];
44
+ target[key] = (win as unknown as Record<string, unknown>)[key];
45
+ }
46
+ });
47
+
48
+ afterAll(() => {
49
+ const target = globalThis as unknown as Record<string, unknown>;
50
+ for (const key of DOM_GLOBALS) {
51
+ if (native[key] === undefined) delete target[key];
52
+ else target[key] = native[key];
53
+ }
54
+ });
55
+
56
+ /** A readable iframe: its `contentDocument` IS the fixture document. */
57
+ function readableFrame(): HTMLIFrameElement {
58
+ return { contentDocument: doc, contentWindow: win } as unknown as HTMLIFrameElement;
59
+ }
60
+
61
+ /** A frame whose document this origin cannot touch — the real production case. */
62
+ function crossOriginFrame(): HTMLIFrameElement {
63
+ return { contentDocument: null, contentWindow: null } as unknown as HTMLIFrameElement;
64
+ }
65
+
66
+ beforeEach(() => {
67
+ doc = win.document as unknown as Document;
68
+ doc.body.innerHTML = '';
69
+ // happy-dom has no layout, so the frame's viewport is stated and
70
+ // `elementFromPoint` is answered from the point these cases aim at.
71
+ Object.defineProperty(win, 'innerWidth', { value: 1000, configurable: true });
72
+ Object.defineProperty(win, 'innerHeight', { value: 500, configurable: true });
73
+ });
74
+
75
+ /** Make `elementFromPoint` answer whatever sits at the given fractions. */
76
+ function hitAt(fractions: { x: number; y: number }, element: Element | null): { asked: string[] } {
77
+ const asked: string[] = [];
78
+ (doc as unknown as Record<string, unknown>).elementFromPoint = (x: number, y: number) => {
79
+ asked.push(`${x},${y}`);
80
+ const matchesX = Math.abs(x - fractions.x * 1000) < 1;
81
+ const matchesY = Math.abs(y - fractions.y * 500) < 1;
82
+ return matchesX && matchesY ? element : null;
83
+ };
84
+ return { asked };
85
+ }
86
+
87
+ describe('frameReadability', () => {
88
+ test('a live document is readable', () => {
89
+ expect(frameReadability(readableFrame())).toBe('readable');
90
+ });
91
+
92
+ test('a null document is cross-origin, not an error', () => {
93
+ expect(frameReadability(crossOriginFrame())).toBe('cross-origin');
94
+ });
95
+
96
+ test('a frame that throws while being read is treated as cross-origin', () => {
97
+ const trap = Object.defineProperty({}, 'contentDocument', {
98
+ get() {
99
+ throw new Error('SecurityError');
100
+ },
101
+ }) as unknown as HTMLIFrameElement;
102
+ expect(frameReadability(trap)).toBe('cross-origin');
103
+ });
104
+
105
+ test('no frame at all is its own reason', () => {
106
+ expect(frameReadability(null)).toBe('no-frame');
107
+ });
108
+ });
109
+
110
+ describe('elementAtPoint', () => {
111
+ test('a cross-origin frame answers a reason and never guesses an element', () => {
112
+ const result = elementAtPoint(crossOriginFrame(), { x: 0.5, y: 0.5 });
113
+ expect(result).toEqual({ ok: false, reason: 'cross-origin' });
114
+ });
115
+
116
+ test('a mark over empty space is no-element, which is not the same fact', () => {
117
+ hitAt({ x: 0.5, y: 0.5 }, null);
118
+ expect(elementAtPoint(readableFrame(), { x: 0.5, y: 0.5 })).toEqual({ ok: false, reason: 'no-element' });
119
+ });
120
+
121
+ test('the marked point maps onto the FRAME viewport, not the panel box', () => {
122
+ const button = doc.createElement('button');
123
+ button.id = 'pay';
124
+ doc.body.appendChild(button);
125
+ const probe = hitAt({ x: 0.25, y: 0.4 }, button);
126
+ const result = elementAtPoint(readableFrame(), { x: 0.25, y: 0.4 });
127
+ expect(result.ok).toBe(true);
128
+ // 25% of a 1000px viewport, 40% of a 500px one.
129
+ expect(probe.asked).toEqual(['250,200']);
130
+ });
131
+
132
+ test('a section reports its aria-label in the path', () => {
133
+ const section = doc.createElement('section');
134
+ section.setAttribute('aria-label', 'Ringkasan pesanan');
135
+ doc.body.appendChild(section);
136
+ hitAt({ x: 0.5, y: 0.5 }, section);
137
+ const result = elementAtPoint(readableFrame(), { x: 0.5, y: 0.5 });
138
+ expect(result.ok).toBe(true);
139
+ if (!result.ok) return;
140
+ expect(result.element.path).toContain('section[aria-label="Ringkasan pesanan"]');
141
+ expect(result.element.tag).toBe('section');
142
+ });
143
+
144
+ test('a select reports its chosen value and option count', () => {
145
+ const select = doc.createElement('select');
146
+ select.id = 'prov';
147
+ for (const name of ['Aceh', 'Jawa Barat', 'Bali']) {
148
+ const option = doc.createElement('option');
149
+ option.value = name.toLowerCase();
150
+ option.textContent = name;
151
+ select.appendChild(option);
152
+ }
153
+ select.value = 'jawa barat';
154
+ doc.body.appendChild(select);
155
+ hitAt({ x: 0.3, y: 0.3 }, select);
156
+ const result = elementAtPoint(readableFrame(), { x: 0.3, y: 0.3 });
157
+ expect(result.ok).toBe(true);
158
+ if (!result.ok) return;
159
+ expect(result.element.tag).toBe('select');
160
+ expect(result.element.state).toContain('nilai "Jawa Barat"');
161
+ expect(result.element.state).toContain('3 opsi');
162
+ });
163
+
164
+ test('a disabled control says so, which is the bug users report most', () => {
165
+ const button = doc.createElement('button');
166
+ button.textContent = 'Bayar';
167
+ button.setAttribute('disabled', '');
168
+ doc.body.appendChild(button);
169
+ hitAt({ x: 0.5, y: 0.5 }, button);
170
+ const result = elementAtPoint(readableFrame(), { x: 0.5, y: 0.5 });
171
+ expect(result.ok).toBe(true);
172
+ if (!result.ok) return;
173
+ expect(result.element.state).toContain('nonaktif');
174
+ expect(result.element.text).toBe('Bayar');
175
+ });
176
+
177
+ test('a password input never reports its value', () => {
178
+ const input = doc.createElement('input');
179
+ input.type = 'password';
180
+ input.value = 'rahasia-sekali';
181
+ doc.body.appendChild(input);
182
+ hitAt({ x: 0.5, y: 0.5 }, input);
183
+ const result = elementAtPoint(readableFrame(), { x: 0.5, y: 0.5 });
184
+ expect(result.ok).toBe(true);
185
+ if (!result.ok) return;
186
+ expect(JSON.stringify(result.element)).not.toContain('rahasia-sekali');
187
+ expect(result.element.state).toContain('tipe password');
188
+ });
189
+
190
+ test('body and html are not "an element under the mark"', () => {
191
+ hitAt({ x: 0.5, y: 0.5 }, doc.body);
192
+ expect(elementAtPoint(readableFrame(), { x: 0.5, y: 0.5 })).toEqual({ ok: false, reason: 'no-element' });
193
+ });
194
+ });
195
+
196
+ describe('elementPath', () => {
197
+ test('keeps at most four levels and stops at html', () => {
198
+ const outer = doc.createElement('main');
199
+ const middle = doc.createElement('section');
200
+ const inner = doc.createElement('div');
201
+ const leaf = doc.createElement('button');
202
+ inner.appendChild(leaf);
203
+ middle.appendChild(inner);
204
+ outer.appendChild(middle);
205
+ doc.body.appendChild(outer);
206
+ const path = elementPath(leaf);
207
+ expect(path.split(' > ')).toHaveLength(4);
208
+ expect(path.endsWith('button')).toBe(true);
209
+ expect(path).not.toContain('html');
210
+ });
211
+
212
+ test('an id wins over a tag alone', () => {
213
+ const node = doc.createElement('div');
214
+ node.id = 'cart';
215
+ doc.body.appendChild(node);
216
+ expect(elementPath(node)).toContain('div#cart');
217
+ });
218
+ });
219
+
220
+ describe('describeElement', () => {
221
+ test('collapses whitespace and cuts long text', () => {
222
+ const node = doc.createElement('p');
223
+ node.textContent = ` ${'kata '.repeat(40)} `;
224
+ doc.body.appendChild(node);
225
+ const info = describeElement(node);
226
+ expect(info.text?.length).toBeLessThanOrEqual(60);
227
+ expect(info.text?.startsWith('kata kata')).toBe(true);
228
+ });
229
+ });
@@ -0,0 +1,139 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Reading what is under a mark, when the page allows it at all.
8
+ *
9
+ * The panel renders the user's page in an iframe, and a real dev server is a
10
+ * DIFFERENT ORIGIN from Kabmo even on the same host: measured in Chromium, a
11
+ * page on `127.0.0.1:7101` embedding `127.0.0.1:7102` reports
12
+ * `contentDocument === null` (no throw — the check is free), while the same
13
+ * origin reports a live document whose `elementFromPoint` answers `H2`.
14
+ *
15
+ * So this module has exactly two honest outcomes, and it never guesses:
16
+ * an element, or a stated reason. A mark with no element is still a complete
17
+ * mark — the user's label and note carry it — and the prompt says the page was
18
+ * not readable instead of silently looking less capable.
19
+ *
20
+ * Coordinates arrive normalized to the panel (0..1) because that is what the
21
+ * overlay stores. Inside the frame they map onto the frame's own viewport,
22
+ * which is the one box `zoom` and a viewport preset never change the meaning of.
23
+ */
24
+
25
+ import type { AnnotateElement, AnnotatePoint } from '@/shared/types';
26
+
27
+ /** Why a mark carries no element, or that it does. */
28
+ export type ElementAtResult =
29
+ | { ok: true; element: AnnotateElement }
30
+ | { ok: false; reason: 'no-frame' | 'cross-origin' | 'no-element' };
31
+
32
+ /** Longest visible text kept from a marked element, in UTF-16 units. */
33
+ const ELEMENT_TEXT_MAX_LEN = 60;
34
+ /** Levels of ancestry kept in a path; deeper paths stop telling the agent more. */
35
+ const ELEMENT_PATH_MAX_DEPTH = 4;
36
+
37
+ /** Whether the frame's document is readable at all — the whole game for this module. */
38
+ export function frameReadability(frame: HTMLIFrameElement | null): 'readable' | 'cross-origin' | 'no-frame' {
39
+ if (!frame) return 'no-frame';
40
+ try {
41
+ return frame.contentDocument ? 'readable' : 'cross-origin';
42
+ } catch {
43
+ // A frame that throws is as unreadable as one that answers null.
44
+ return 'cross-origin';
45
+ }
46
+ }
47
+
48
+ /** Collapse whitespace and cut to the stored maximum, ending with an ellipsis. */
49
+ function shortText(value: string): string {
50
+ const collapsed = value.replace(/\s+/g, ' ').trim();
51
+ return collapsed.length > ELEMENT_TEXT_MAX_LEN
52
+ ? `${collapsed.slice(0, ELEMENT_TEXT_MAX_LEN - 1)}…`
53
+ : collapsed;
54
+ }
55
+
56
+ /** One step of a path: id wins, then the one identifying attribute, then the tag. */
57
+ function pathStep(element: Element): string {
58
+ const tag = element.tagName.toLowerCase();
59
+ if (element.id) return `${tag}#${element.id}`;
60
+ for (const attribute of ['data-testid', 'data-test', 'aria-label']) {
61
+ const value = element.getAttribute(attribute);
62
+ if (value) return `${tag}[${attribute}="${shortText(value)}"]`;
63
+ }
64
+ const role = element.getAttribute('role');
65
+ if (role) return `${tag}[role="${role}"]`;
66
+ return tag;
67
+ }
68
+
69
+ /** `html > body > section … > select`, at most `ELEMENT_PATH_MAX_DEPTH` steps. */
70
+ export function elementPath(element: Element): string {
71
+ const steps: string[] = [];
72
+ let current: Element | null = element;
73
+ while (current && steps.length < ELEMENT_PATH_MAX_DEPTH) {
74
+ if (current.tagName.toLowerCase() === 'html') break;
75
+ steps.unshift(pathStep(current));
76
+ current = current.parentElement;
77
+ }
78
+ return steps.join(' > ');
79
+ }
80
+
81
+ /**
82
+ * The state a form control is in — the part a screenshot could not tell the
83
+ * agent and a user would have to type out by hand.
84
+ */
85
+ function controlState(element: Element): string | undefined {
86
+ const parts: string[] = [];
87
+ if ((element as HTMLInputElement).disabled) parts.push('nonaktif');
88
+ if (element instanceof HTMLSelectElement || element.tagName.toLowerCase() === 'select') {
89
+ const select = element as HTMLSelectElement;
90
+ const chosen = select.selectedOptions?.[0];
91
+ const value = chosen?.textContent?.trim() || select.value;
92
+ if (value) parts.push(`nilai "${shortText(value)}"`);
93
+ const count = select.options?.length ?? 0;
94
+ if (count > 0) parts.push(`${count} opsi`);
95
+ } else if (element.tagName.toLowerCase() === 'input') {
96
+ const input = element as HTMLInputElement;
97
+ if (input.type) parts.push(`tipe ${input.type}`);
98
+ // A password's value is never read; a placeholder is what the user sees.
99
+ if (input.type !== 'password' && input.placeholder) parts.push(`placeholder "${shortText(input.placeholder)}"`);
100
+ }
101
+ return parts.length > 0 ? parts.join(', ') : undefined;
102
+ }
103
+
104
+ /** The element summary, without the coordinate work. */
105
+ export function describeElement(element: Element): AnnotateElement {
106
+ const info: AnnotateElement = { path: elementPath(element), tag: element.tagName.toLowerCase() };
107
+ const role = element.getAttribute('role');
108
+ if (role) info.role = role;
109
+ const text = shortText((element as HTMLElement).innerText ?? element.textContent ?? '');
110
+ if (text) info.text = text;
111
+ const state = controlState(element);
112
+ if (state) info.state = state;
113
+ return info;
114
+ }
115
+
116
+ /**
117
+ * The element under a normalized point of the panel.
118
+ *
119
+ * `no-element` is a real answer: a mark over empty space has nothing beneath it,
120
+ * and that is not the same fact as an unreadable page.
121
+ */
122
+ export function elementAtPoint(frame: HTMLIFrameElement | null, point: AnnotatePoint): ElementAtResult {
123
+ const readability = frameReadability(frame);
124
+ if (readability !== 'readable') return { ok: false, reason: readability };
125
+ const win = frame!.contentWindow;
126
+ const doc = frame!.contentDocument;
127
+ if (!win || !doc) return { ok: false, reason: 'cross-origin' };
128
+ try {
129
+ // The frame's own viewport is the box the normalized point is a fraction of;
130
+ // the panel's CSS zoom and its viewport preset never enter this mapping.
131
+ const x = Math.min(Math.max(point.x, 0), 1) * win.innerWidth;
132
+ const y = Math.min(Math.max(point.y, 0), 1) * win.innerHeight;
133
+ const hit = doc.elementFromPoint(x, y);
134
+ if (!hit || hit === doc.documentElement || hit === doc.body) return { ok: false, reason: 'no-element' };
135
+ return { ok: true, element: describeElement(hit) };
136
+ } catch {
137
+ return { ok: false, reason: 'cross-origin' };
138
+ }
139
+ }
@@ -0,0 +1,73 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The review surface's HTTP calls, typed.
8
+ *
9
+ * One module because three callers share the contract: the loading hook, the
10
+ * save, and the delete. `root`/`repo` travel on every request — a document in a
11
+ * nested repo is a different document from a same-named path at the workspace
12
+ * root, and the server keys its rows by the resolved pair.
13
+ *
14
+ * A refusal is REPORTED, never swallowed: a save that silently failed would
15
+ * leave the reader believing a judgement is stored when it is not, which is the
16
+ * one failure this feature cannot tolerate.
17
+ */
18
+
19
+ import type { AnnotationDraft, BlockVerdict, DocumentAnnotation, ReviewTarget } from '@/shared/lib/markdown/blocks/types';
20
+
21
+ /** The body a save sends, minus the scope the server resolves from root/repo. */
22
+ export interface SaveAnnotationBody {
23
+ path: string;
24
+ root?: string | null;
25
+ repo?: string | null;
26
+ blockKey: string;
27
+ lineStart: number;
28
+ lineEnd: number;
29
+ verdict: BlockVerdict;
30
+ note: string;
31
+ quote: string;
32
+ }
33
+
34
+ function scopeParams(target: ReviewTarget): URLSearchParams {
35
+ const params = new URLSearchParams({ path: target.path });
36
+ if (target.root) params.set('root', target.root);
37
+ if (target.repo && target.repo !== '.') params.set('repo', target.repo);
38
+ return params;
39
+ }
40
+
41
+ /** The refusal text a failed request carries, or a status-shaped fallback. */
42
+ async function refusal(response: Response): Promise<string> {
43
+ const payload = (await response.json().catch(() => null)) as { error?: unknown } | null;
44
+ return typeof payload?.error === 'string' ? payload.error : `Request failed (${response.status})`;
45
+ }
46
+
47
+ /** Every judgement stored for one document. */
48
+ export async function fetchAnnotations(target: ReviewTarget, signal?: AbortSignal): Promise<DocumentAnnotation[]> {
49
+ const response = await fetch(`/api/review?${scopeParams(target).toString()}`, { signal });
50
+ if (!response.ok) throw new Error(await refusal(response));
51
+ const payload = (await response.json()) as { annotations?: DocumentAnnotation[] };
52
+ return Array.isArray(payload.annotations) ? payload.annotations : [];
53
+ }
54
+
55
+ /** Store one judgement, answering the row as the server stored it. */
56
+ export async function saveAnnotation(target: ReviewTarget, draft: Omit<AnnotationDraft, 'scope' | 'path'>): Promise<DocumentAnnotation> {
57
+ const body: SaveAnnotationBody = { ...draft, path: target.path, root: target.root, repo: target.repo };
58
+ const response = await fetch('/api/review', {
59
+ method: 'POST',
60
+ headers: { 'Content-Type': 'application/json' },
61
+ body: JSON.stringify(body),
62
+ });
63
+ if (!response.ok) throw new Error(await refusal(response));
64
+ const payload = (await response.json()) as { annotation?: DocumentAnnotation };
65
+ if (!payload.annotation) throw new Error('The server answered without the saved annotation');
66
+ return payload.annotation;
67
+ }
68
+
69
+ /** Remove one judgement. A missing row is an error, not a silent success. */
70
+ export async function removeAnnotation(id: string): Promise<void> {
71
+ const response = await fetch(`/api/review?id=${encodeURIComponent(id)}`, { method: 'DELETE' });
72
+ if (!response.ok) throw new Error(await refusal(response));
73
+ }
@@ -23,29 +23,54 @@ type SetParams = (next: SetParamsInit | SetParamsFn, options?: { replace?: boole
23
23
  export type SetSearchParams = SetParams;
24
24
 
25
25
  const listeners = new Set<() => void>();
26
- let currentSearch = typeof window === 'undefined' ? '' : window.location.search;
27
26
 
28
27
  function emit(): void {
29
28
  for (const listener of listeners) listener();
30
29
  }
31
30
 
32
- function subscribe(listener: () => void): () => void {
33
- listeners.add(listener);
34
- return () => listeners.delete(listener);
31
+ /**
32
+ * The search string of the window in scope RIGHT NOW, never a value cached when
33
+ * this module was first evaluated.
34
+ *
35
+ * A module-level `currentSearch` reads as a harmless cache and is not: it pins
36
+ * the store to whichever `window` existed at import time, and so does the
37
+ * `popstate` listener below. In the browser there is one window forever and the
38
+ * two are equivalent; under `bun test` every DOM suite installs its OWN window,
39
+ * so the pinned pair made the router answer a URL nobody can see and miss
40
+ * `popstate` on the window the suite is actually driving — measured: a suite
41
+ * that set `?sessionId=` and mounted the composer read `''` and drew the
42
+ * landing, failing a case that passes when its file runs alone.
43
+ */
44
+ function liveSearch(): string {
45
+ return typeof window === 'undefined' ? '' : window.location.search;
35
46
  }
36
47
 
37
- /** Re-read `location.search` and notify only when it actually changed. */
38
- function syncFromLocation(): void {
39
- const next = typeof window === 'undefined' ? '' : window.location.search;
40
- if (next === currentSearch) return;
41
- currentSearch = next;
48
+ /**
49
+ * The window this store is currently listening on.
50
+ *
51
+ * Rebound on subscribe rather than once at module load, for the reason above:
52
+ * a suite that replaces `globalThis.window` must get a router that follows it.
53
+ */
54
+ let boundWindow: Window | undefined;
55
+
56
+ function onPopState(): void {
42
57
  emit();
43
58
  }
44
59
 
45
- if (typeof window !== 'undefined') {
60
+ function bindToCurrentWindow(): void {
61
+ const next = typeof window === 'undefined' ? undefined : window;
62
+ if (next === boundWindow) return;
63
+ boundWindow?.removeEventListener('popstate', onPopState);
64
+ boundWindow = next;
46
65
  // Back/forward navigation. `pushState`/`replaceState` do NOT fire popstate,
47
66
  // so setParams notifies directly.
48
- window.addEventListener('popstate', syncFromLocation);
67
+ next?.addEventListener('popstate', onPopState);
68
+ }
69
+
70
+ function subscribe(listener: () => void): () => void {
71
+ listeners.add(listener);
72
+ bindToCurrentWindow();
73
+ return () => listeners.delete(listener);
49
74
  }
50
75
 
51
76
  function toSearchString(init: SetParamsInit): string {
@@ -63,22 +88,19 @@ function resolveNext(next: SetParamsInit | SetParamsFn, current: URLSearchParams
63
88
  return toSearchString(next);
64
89
  }
65
90
 
66
- function getSnapshot(): string {
67
- return currentSearch;
68
- }
69
-
70
91
  export function useSearchParams(): [URLSearchParams, SetParams] {
71
92
  // Preact's `useSyncExternalStore` takes only (subscribe, getSnapshot) — no
72
- // server-snapshot argument — and the app is client-rendered, so `currentSearch`
73
- // is the single source of truth.
74
- const search = useSyncExternalStore(subscribe, getSnapshot);
93
+ // server-snapshot argument — and the app is client-rendered, so the live
94
+ // `location.search` is the single source of truth. It is read on demand, and
95
+ // `useSyncExternalStore` compares snapshots by value, so an unchanged URL
96
+ // costs one string comparison and no render.
97
+ const search = useSyncExternalStore(subscribe, liveSearch);
75
98
 
76
99
  const setParams = useCallback<SetParams>((next, options) => {
77
- const searchString = resolveNext(next, new URLSearchParams(currentSearch));
100
+ const searchString = resolveNext(next, new URLSearchParams(liveSearch()));
78
101
  const url = `${window.location.pathname}${searchString}${window.location.hash}`;
79
102
  if (options?.replace) window.history.replaceState(null, '', url);
80
103
  else window.history.pushState(null, '', url);
81
- currentSearch = searchString;
82
104
  emit();
83
105
  }, []);
84
106
 
@@ -5,6 +5,8 @@ import { warmSyntaxTokenizers } from '@/shared/lib/code/highlighter-warmup';
5
5
  import { primeKabmoSettings } from '@/shared/lib/settings/client';
6
6
  import { initDocumentTheme } from '@/client/hooks/ui/theme';
7
7
  import { initChatWidthMode } from '@/client/hooks/chat/timeline/width-mode';
8
+ import { initSurfaceStyle } from '@/client/hooks/ui/surface-style';
9
+ import { initIconStyle } from '@/client/hooks/ui/icon-style';
8
10
  import { primeWindowChrome } from '@/client/hooks/ui/window-chrome';
9
11
  import { installAuthFetchBridge, primeAuthState } from '@/client/hooks/ui/auth';
10
12
  import { installPluginRuntime } from '@/client/lib/plugins/runtime';
@@ -19,6 +21,7 @@ import { installOpenPaths } from '@/client/lib/native/open-paths';
19
21
  import { installDeviceFiles } from '@/client/lib/launch/device-files';
20
22
 
21
23
  import '@/client/tailwind.css';
24
+ import '@/client/glass.css';
22
25
  import '@/shared/lib/markdown/katex-fonts.css';
23
26
  import '@/shared/lib/markdown/fira-code-fonts.css';
24
27
  import '@/shared/lib/fonts/nerd-symbols.css';
@@ -41,6 +44,13 @@ primeKabmoSettings(bootstrap?.appSettings);
41
44
  // lazily mounted subtree, and a hook would not run until it mounted.
42
45
  initChatWidthMode();
43
46
 
47
+ // The surface material and the brand-mark paint, also before the first render:
48
+ // a glass install that painted the opaque shell first would swap every panel
49
+ // one frame later, and a colour install would draw ink marks and then repaint
50
+ // them. Both write an attribute CSS reads — no event, no re-render.
51
+ initSurfaceStyle();
52
+ initIconStyle();
53
+
44
54
  // BEFORE the theme init, which writes the chrome meta: a phone that repainted
45
55
  // it from the module default would flash the desktop's color for a frame. The
46
56
  // server's two facts (user agent, authentication) are baked into the document,