@kabmo-labs/kabmo 0.16.0 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (381) hide show
  1. package/README.md +2 -2
  2. package/dist/client/index.html +1 -1
  3. package/dist/client/index.js +552 -471
  4. package/dist/client/static/js/index-hp75vsv9.css +1 -0
  5. package/dist/client/static/js/{index-cpydmygd.js → index-tc09dtca.js} +897 -886
  6. package/package.json +1 -1
  7. package/src/client/components/common/MarkdownRenderer.tsx +136 -89
  8. package/src/client/components/common/anchored-menu/index.test.tsx +141 -0
  9. package/src/client/components/common/anchored-menu/index.tsx +143 -0
  10. package/src/client/components/common/code-surface/bracket-guide.test.ts +2 -2
  11. package/src/client/components/common/code-surface/bracket-guide.ts +2 -2
  12. package/src/client/components/common/code-surface/conflict-markers.ts +5 -5
  13. package/src/client/components/common/code-surface/extensions.ts +7 -4
  14. package/src/client/components/common/code-surface/theme.ts +34 -9
  15. package/src/client/components/common/code-surface/whitespace.test.ts +223 -0
  16. package/src/client/components/common/code-surface/whitespace.ts +140 -0
  17. package/src/client/components/common/markdown-review/ReviewPopover.tsx +144 -0
  18. package/src/client/components/common/markdown-review/ReviewSummary.tsx +108 -0
  19. package/src/client/components/common/markdown-review/index.tsx +129 -0
  20. package/src/client/components/common/{server-switcher/index.tsx → server-control/Panel.tsx} +92 -44
  21. package/src/client/components/common/server-control/index.test.tsx +217 -0
  22. package/src/client/components/common/server-control/index.tsx +120 -0
  23. package/src/client/components/layout/desktop-layout/TopNavbar.tsx +8 -50
  24. package/src/client/components/layout/session-sidebar/CategoryHeader.tsx +42 -21
  25. package/src/client/components/layout/session-sidebar/CategoryHeader.worktree.test.tsx +36 -17
  26. package/src/client/components/layout/session-sidebar/CategoryItem.tsx +8 -7
  27. package/src/client/components/layout/session-sidebar/about-modal/NotesDialog.tsx +94 -0
  28. package/src/client/components/layout/session-sidebar/about-modal/VersionLine.test.tsx +68 -0
  29. package/src/client/components/layout/session-sidebar/about-modal/VersionLine.tsx +36 -0
  30. package/src/client/components/layout/session-sidebar/about-modal/index.tsx +57 -34
  31. package/src/client/components/layout/session-sidebar/modern/WorkspaceHeader.tsx +28 -10
  32. package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +7 -6
  33. package/src/client/components/layout/session-sidebar/modern/workspace-header.test.tsx +1 -1
  34. package/src/client/components/layout/update-popup/ReleaseNotes.tsx +8 -3
  35. package/src/client/components/layout/update-popup/index.tsx +5 -1
  36. package/src/client/components/mobile/mobile-main-view/Header.tsx +6 -12
  37. package/src/client/components/mobile/mobile-right-sidebar/FullEditor.tsx +13 -15
  38. package/src/client/components/mobile/mobile-right-sidebar/Header.tsx +23 -1
  39. package/src/client/components/mobile/mobile-right-sidebar/MissingFileBanner.tsx +30 -0
  40. package/src/client/components/mobile/mobile-right-sidebar/PreviewScroller.tsx +18 -2
  41. package/src/client/components/mobile/mobile-session-sidebar/Header.tsx +41 -13
  42. package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +22 -67
  43. package/src/client/components/mobile/mobile-session-sidebar/ItemMenu.tsx +110 -0
  44. package/src/client/components/settings/Modal.tsx +9 -3
  45. package/src/client/components/settings/ProjectSelectorDropdown.tsx +19 -9
  46. package/src/client/components/settings/SettingsSidebarList.tsx +20 -0
  47. package/src/client/components/settings/categories/AgentSettings.tsx +38 -44
  48. package/src/client/components/settings/categories/CommandSettings.tsx +2 -2
  49. package/src/client/components/settings/categories/McpSettings.tsx +4 -21
  50. package/src/client/components/settings/categories/OmpSettings.tsx +147 -194
  51. package/src/client/components/settings/categories/ProjectSettings.tsx +122 -156
  52. package/src/client/components/settings/categories/SkillCatalogSettings.tsx +220 -260
  53. package/src/client/components/settings/categories/SkillSettings.tsx +8 -5
  54. package/src/client/components/settings/categories/TokenUsageSettings.tsx +211 -229
  55. package/src/client/components/settings/categories/agent-settings/DetailPane.tsx +229 -237
  56. package/src/client/components/settings/categories/agent-settings/ModelPicker.tsx +71 -0
  57. package/src/client/components/settings/categories/agent-settings/SidebarList.tsx +14 -2
  58. package/src/client/components/settings/categories/agent-settings/levels.ts +38 -0
  59. package/src/client/components/settings/categories/behavior-settings/Editor.tsx +27 -7
  60. package/src/client/components/settings/categories/chat-settings/ToolRenderSection.tsx +23 -5
  61. package/src/client/components/settings/categories/command-settings/DetailPane.tsx +75 -33
  62. package/src/client/components/settings/categories/command-settings/SidebarList.tsx +7 -0
  63. package/src/client/components/settings/categories/mcp-settings/DetailPane.tsx +91 -76
  64. package/src/client/components/settings/categories/mcp-settings/EnvVarsSection.tsx +83 -0
  65. package/src/client/components/settings/categories/mcp-settings/ImportModal.tsx +26 -13
  66. package/src/client/components/settings/categories/mcp-settings/SidebarList.tsx +20 -0
  67. package/src/client/components/settings/categories/omp-settings/ConfigTabs.tsx +97 -36
  68. package/src/client/components/settings/categories/omp-settings/EngineHeader.tsx +151 -0
  69. package/src/client/components/settings/categories/omp-settings/ExtensionsPanel.tsx +68 -32
  70. package/src/client/components/settings/categories/omp-settings/OrderedChips.tsx +119 -0
  71. package/src/client/components/settings/categories/omp-settings/PresetBar.tsx +14 -7
  72. package/src/client/components/settings/categories/omp-settings/RoleEditor.tsx +15 -6
  73. package/src/client/components/settings/categories/omp-settings/RowEditor.tsx +165 -226
  74. package/src/client/components/settings/categories/omp-settings/types.ts +28 -0
  75. package/src/client/components/settings/categories/project-settings/AccentPalette.test.tsx +189 -0
  76. package/src/client/components/settings/categories/project-settings/AccentPalette.tsx +156 -24
  77. package/src/client/components/settings/categories/project-settings/AddProjectModal.tsx +175 -0
  78. package/src/client/components/settings/categories/project-settings/DeleteProjectModal.tsx +107 -0
  79. package/src/client/components/settings/categories/project-settings/DetailsForm.tsx +40 -24
  80. package/src/client/components/settings/categories/project-settings/DetailsHeader.tsx +17 -7
  81. package/src/client/components/settings/categories/project-settings/IconGrid.tsx +164 -69
  82. package/src/client/components/settings/categories/project-settings/ModelDropdown.test.tsx +122 -0
  83. package/src/client/components/settings/categories/project-settings/ModelDropdown.tsx +124 -53
  84. package/src/client/components/settings/categories/project-settings/NameInput.tsx +57 -11
  85. package/src/client/components/settings/categories/project-settings/PathField.tsx +122 -0
  86. package/src/client/components/settings/categories/project-settings/SidebarList.tsx +100 -59
  87. package/src/client/components/settings/categories/skill-catalog/GitImportPanel.tsx +253 -0
  88. package/src/client/components/settings/categories/skill-catalog/SkillCard.tsx +89 -0
  89. package/src/client/components/settings/categories/skill-catalog/SourceRail.tsx +122 -0
  90. package/src/client/components/settings/categories/skill-catalog/catalog-ui.test.tsx +179 -0
  91. package/src/client/components/settings/categories/skill-settings/DetailHeader.tsx +236 -0
  92. package/src/client/components/settings/categories/skill-settings/DetailPane.tsx +164 -239
  93. package/src/client/components/settings/categories/skill-settings/InstructionsEditor.tsx +84 -0
  94. package/src/client/components/settings/categories/skill-settings/SidebarList.tsx +144 -87
  95. package/src/client/components/settings/categories/skill-settings/pane.test.tsx +188 -0
  96. package/src/client/components/settings/categories/skill-settings/row-meta.ts +58 -0
  97. package/src/client/components/settings/categories/token-usage-settings/Breakdown.tsx +242 -102
  98. package/src/client/components/settings/categories/token-usage-settings/Chart.tsx +130 -56
  99. package/src/client/components/settings/categories/token-usage-settings/Controls.tsx +135 -0
  100. package/src/client/components/settings/categories/token-usage-settings/MetricsGrid.tsx +55 -33
  101. package/src/client/components/settings/categories/token-usage-settings/Provenance.tsx +59 -0
  102. package/src/client/components/settings/categories/token-usage-settings/panel.test.tsx +239 -0
  103. package/src/client/components/workspace/browser-panel/Screencast.test.ts +1 -0
  104. package/src/client/components/workspace/browser-panel/Screencast.tsx +17 -22
  105. package/src/client/components/workspace/browser-panel/TabStrip.test.tsx +158 -0
  106. package/src/client/components/workspace/browser-panel/TabStrip.tsx +90 -0
  107. package/src/client/components/workspace/browser-panel/index.tsx +50 -4
  108. package/src/client/components/workspace/browser-toolbar/index.tsx +41 -1
  109. package/src/client/components/workspace/chat-timeline/ThinkingSection.tsx +3 -1
  110. package/src/client/components/workspace/chat-timeline/ToolCallingSection.tsx +2 -0
  111. package/src/client/components/workspace/chat-timeline/block-chrome.test.tsx +13 -2
  112. package/src/client/components/workspace/chat-timeline/index.tsx +6 -1
  113. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Bash.test.ts +88 -0
  114. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Bash.tsx +24 -1
  115. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Proc.test.ts +46 -0
  116. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Proc.tsx +15 -6
  117. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Read.test.ts +34 -0
  118. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Read.tsx +5 -1
  119. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.test.ts +29 -0
  120. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.tsx +11 -3
  121. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/ArtifactChip.tsx +7 -6
  122. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/card-header.test.ts +24 -1
  123. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/card-header.ts +6 -2
  124. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Tui.test.tsx +237 -0
  125. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Tui.tsx +191 -0
  126. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/styles.test.tsx +1 -1
  127. package/src/client/components/workspace/diff-panel/MergeDiffView.tsx +21 -7
  128. package/src/client/components/workspace/diff-panel/changes.test.ts +51 -0
  129. package/src/client/components/workspace/diff-panel/changes.ts +28 -12
  130. package/src/client/components/workspace/diff-panel/merge.test.ts +28 -0
  131. package/src/client/components/workspace/diff-panel/merge.ts +21 -1
  132. package/src/client/components/workspace/editor/Body.tsx +7 -0
  133. package/src/client/components/workspace/editor/FileDocument.tsx +15 -21
  134. package/src/client/components/workspace/editor/FilePane.tsx +12 -0
  135. package/src/client/components/workspace/editor/PreviewPane.tsx +70 -0
  136. package/src/client/components/workspace/editor/Toolbar.tsx +17 -1
  137. package/src/client/components/workspace/editor/index.tsx +25 -22
  138. package/src/client/components/workspace/editor/toolbar-clusters.test.ts +14 -0
  139. package/src/client/components/workspace/editor/toolbar-clusters.tsx +12 -86
  140. package/src/client/components/workspace/editor/toolbar-toggle.tsx +53 -0
  141. package/src/client/components/workspace/editor/toolbar-write-clusters.tsx +112 -0
  142. package/src/client/components/workspace/editor/viewers/SvgPreview.tsx +18 -2
  143. package/src/client/components/workspace/editor/viewers/viewers.test.ts +39 -0
  144. package/src/client/components/workspace/file-explorer/ContextMenu.tsx +18 -5
  145. package/src/client/components/workspace/file-explorer/Modals.tsx +15 -1
  146. package/src/client/components/workspace/file-explorer/RowLabel.tsx +68 -0
  147. package/src/client/components/workspace/file-explorer/TreeItem.tsx +47 -57
  148. package/src/client/components/workspace/file-explorer/collapsed-chain.test.ts +167 -0
  149. package/src/client/components/workspace/file-explorer/drag-props.ts +42 -0
  150. package/src/client/components/workspace/file-explorer/drag.test.ts +43 -0
  151. package/src/client/components/workspace/file-explorer/index.tsx +21 -20
  152. package/src/client/components/workspace/git-panel/commit-modal.test.ts +5 -3
  153. package/src/client/components/workspace/user-browser-panel/AddressBar.tsx +5 -0
  154. package/src/client/components/workspace/user-browser-panel/AnnotateBar.test.tsx +201 -0
  155. package/src/client/components/workspace/user-browser-panel/AnnotateBar.tsx +112 -0
  156. package/src/client/components/workspace/user-browser-panel/AnnotateLayer.test.tsx +225 -0
  157. package/src/client/components/workspace/user-browser-panel/AnnotateLayer.tsx +217 -0
  158. package/src/client/components/workspace/user-browser-panel/AnnotateTarget.tsx +99 -0
  159. package/src/client/components/workspace/user-browser-panel/Frame.tsx +30 -1
  160. package/src/client/components/workspace/user-browser-panel/index.tsx +81 -2
  161. package/src/client/data/agent-data/builtin.ts +0 -10
  162. package/src/client/data/agent-data/orchestrator.ts +0 -45
  163. package/src/client/data/agent-data/specialist.ts +0 -100
  164. package/src/client/data/mock/token-usage.ts +170 -120
  165. package/src/client/data/settings/omp-schema.json +123 -4
  166. package/src/client/data/settings/project.ts +9 -28
  167. package/src/client/data/settings/skill.ts +6 -32
  168. package/src/client/hooks/browser/use-annotate.test.ts +143 -0
  169. package/src/client/hooks/browser/use-annotate.ts +98 -0
  170. package/src/client/hooks/browser/use-close-tab.test.ts +148 -0
  171. package/src/client/hooks/browser/use-close-tab.ts +67 -0
  172. package/src/client/hooks/browser/use-screencast.ts +13 -1
  173. package/src/client/hooks/chat/composer/browser-context.test.ts +117 -0
  174. package/src/client/hooks/chat/composer/browser-context.ts +40 -16
  175. package/src/client/hooks/chat/composer/items.test.ts +1 -1
  176. package/src/client/hooks/chat/composer/review-context.ts +38 -0
  177. package/src/client/hooks/chat/composer/use-draft.test.ts +132 -0
  178. package/src/client/hooks/chat/composer/use-draft.ts +31 -2
  179. package/src/client/hooks/chat/timeline/pending-model.ts +28 -0
  180. package/src/client/hooks/chat/timeline/row-window.test.ts +15 -2
  181. package/src/client/hooks/editor/use-document-annotations.ts +124 -0
  182. package/src/client/hooks/editor/use-editor-panel-ui.ts +52 -0
  183. package/src/client/hooks/editor/use-file-review-mode.ts +35 -0
  184. package/src/client/hooks/editor/use-preview-review.ts +148 -0
  185. package/src/client/hooks/settings/agents.ts +149 -0
  186. package/src/client/hooks/settings/crud-list.test.ts +28 -6
  187. package/src/client/hooks/settings/crud-list.ts +96 -57
  188. package/src/client/hooks/settings/omp-config.ts +164 -0
  189. package/src/client/hooks/settings/projects/index.ts +294 -0
  190. package/src/client/hooks/settings/projects.test.ts +237 -0
  191. package/src/client/hooks/settings/skill-catalog.ts +101 -9
  192. package/src/client/hooks/settings/skill-git-import.ts +153 -0
  193. package/src/client/hooks/settings/useTokenUsage.ts +125 -0
  194. package/src/client/hooks/settings/write-feedback.test.ts +104 -0
  195. package/src/client/hooks/settings/write-feedback.ts +63 -0
  196. package/src/client/hooks/shell/servers.test.ts +166 -0
  197. package/src/client/hooks/{desktop → shell}/servers.ts +17 -14
  198. package/src/client/hooks/ui/markdown-hydration.ts +125 -0
  199. package/src/client/hooks/ui/updates/index.test.ts +100 -1
  200. package/src/client/hooks/ui/updates/index.ts +50 -0
  201. package/src/client/hooks/ui/updates/notes.test.ts +138 -0
  202. package/src/client/hooks/ui/updates/notes.ts +57 -0
  203. package/src/client/hooks/ui/updates/shell-download.ts +1 -1
  204. package/src/client/hooks/ui/updates/shell-update.ts +2 -6
  205. package/src/client/hooks/workspace/file-row-drag.ts +41 -0
  206. package/src/client/hooks/workspace/file-tree-actions.ts +25 -1
  207. package/src/client/hooks/workspace/file-tree-edits.ts +23 -6
  208. package/src/client/hooks/workspace/root-drop-target.ts +77 -0
  209. package/src/client/hooks/workspace/unfolded-chains.ts +165 -0
  210. package/src/client/lib/browser/element-at.test.ts +229 -0
  211. package/src/client/lib/browser/element-at.ts +139 -0
  212. package/src/client/lib/desktop/dropped-paths.ts +1 -1
  213. package/src/client/lib/desktop/titlebar.test.ts +12 -3
  214. package/src/client/lib/desktop/titlebar.ts +1 -1
  215. package/src/client/lib/review/client.ts +73 -0
  216. package/src/client/lib/router/search-params.ts +42 -20
  217. package/src/client/lib/shell/desktop.ts +117 -0
  218. package/src/client/lib/shell/servers.ts +75 -0
  219. package/src/client/lib/shell/transport.ts +216 -0
  220. package/src/client/main.tsx +9 -0
  221. package/src/client/tailwind.css +65 -0
  222. package/src/server/lib/btw/lifecycle.server.ts +2 -2
  223. package/src/server/lib/db/schema.ts +7 -0
  224. package/src/server/lib/db/seed-terminal.test.ts +4 -0
  225. package/src/server/lib/fs/git-merge-conflict.test.ts +14 -1
  226. package/src/server/lib/omp/config/agent-definitions.test.ts +273 -0
  227. package/src/server/lib/omp/config/agents.ts +231 -61
  228. package/src/server/lib/omp/config/definitions.test.ts +9 -105
  229. package/src/server/lib/omp/config/extensions.ts +16 -7
  230. package/src/server/lib/omp/config/omp-config-files.test.ts +27 -0
  231. package/src/server/lib/omp/config/skill-sources.ts +49 -0
  232. package/src/server/lib/omp/config/skills-git-install.ts +155 -0
  233. package/src/server/lib/omp/config/skills-git-repo.ts +288 -0
  234. package/src/server/lib/omp/config/skills-git.test.ts +220 -0
  235. package/src/server/lib/omp/rpc/constants.test.ts +11 -0
  236. package/src/server/lib/omp/rpc/constants.ts +15 -0
  237. package/src/server/lib/omp/rpc/process.ts +11 -14
  238. package/src/server/lib/omp/rpc/session-commands.ts +6 -3
  239. package/src/server/lib/omp/rpc/utility-agent-dir.test.ts +134 -0
  240. package/src/server/lib/omp/rpc/utility-agent-dir.ts +138 -0
  241. package/src/server/lib/omp/rpc/utility.ts +12 -0
  242. package/src/server/lib/review/schema.server.ts +45 -0
  243. package/src/server/lib/review/store.server.ts +138 -0
  244. package/src/server/lib/terminal/attach-replay.test.ts +132 -0
  245. package/src/server/lib/terminal/output.test.ts +166 -0
  246. package/src/server/lib/terminal/output.ts +104 -0
  247. package/src/server/lib/terminal/runtime.server.ts +5 -0
  248. package/src/server/lib/terminal/send-result.test.ts +33 -0
  249. package/src/server/lib/terminal/send-result.ts +32 -0
  250. package/src/server/lib/terminal/session.server.ts +45 -11
  251. package/src/server/lib/terminal/store-liveness.test.ts +4 -0
  252. package/src/server/lib/updates/active-notes.test.ts +149 -0
  253. package/src/server/lib/updates/active-notes.ts +75 -0
  254. package/src/server/lib/updates/changelog-file.ts +42 -11
  255. package/src/server/lib/updates/changelog.test.ts +15 -1
  256. package/src/server/lib/updates/omp.ts +42 -15
  257. package/src/server/lib/updates/release-url.ts +27 -1
  258. package/src/server/lib/usage/index-parse.test.ts +200 -0
  259. package/src/server/lib/usage/index-parse.ts +178 -0
  260. package/src/server/lib/usage/index-query.server.ts +248 -0
  261. package/src/server/lib/usage/index-scan.server.ts +343 -0
  262. package/src/server/lib/usage/index-schema.server.ts +82 -0
  263. package/src/server/lib/usage/index.test.ts +234 -0
  264. package/src/server/lib/usage/providers.server.ts +4 -53
  265. package/src/server/lib/workspace/project-model.server.test.ts +102 -0
  266. package/src/server/lib/workspace/project-model.server.ts +47 -0
  267. package/src/server/lib/workspace/project-patch.server.ts +156 -0
  268. package/src/server/routes/agent/new.ts +8 -1
  269. package/src/server/routes/browser/index.ts +3 -0
  270. package/src/server/routes/browser/stream.ts +31 -2
  271. package/src/server/routes/browser/tabs.test.ts +94 -0
  272. package/src/server/routes/browser/tabs.ts +85 -0
  273. package/src/server/routes/index.ts +2 -0
  274. package/src/server/routes/review/bindings.ts +11 -0
  275. package/src/server/routes/review/index.ts +127 -0
  276. package/src/server/routes/review/routes.test.ts +191 -0
  277. package/src/server/routes/settings/agents.test.ts +180 -0
  278. package/src/server/routes/settings/agents.ts +99 -94
  279. package/src/server/routes/settings/mcp.test.ts +135 -0
  280. package/src/server/routes/settings/mcp.ts +14 -6
  281. package/src/server/routes/settings/projects.ts +53 -19
  282. package/src/server/routes/settings/settings-projects-routes.test.ts +214 -0
  283. package/src/server/routes/settings/settings-store-routes.test.ts +11 -115
  284. package/src/server/routes/settings/skills-catalog-actions.ts +195 -0
  285. package/src/server/routes/settings/skills.test.ts +225 -0
  286. package/src/server/routes/settings/skills.ts +18 -15
  287. package/src/server/routes/telemetry/tokens.test.ts +145 -0
  288. package/src/server/routes/telemetry/tokens.ts +70 -149
  289. package/src/server/routes/terminal/ws.ts +6 -5
  290. package/src/server/routes/updates/index.ts +2 -0
  291. package/src/server/routes/updates/notes.ts +34 -0
  292. package/src/server/routes/updates/routes.test.ts +49 -0
  293. package/src/shared/lib/browser/annotate.test.ts +283 -0
  294. package/src/shared/lib/browser/annotate.ts +231 -0
  295. package/src/shared/lib/browser/browser-viewer.test.ts +26 -4
  296. package/src/shared/lib/browser/frame-gate.test.ts +91 -0
  297. package/src/shared/lib/browser/frame-gate.ts +69 -0
  298. package/src/shared/lib/browser/frame-params.test.ts +43 -0
  299. package/src/shared/lib/browser/frame-params.ts +60 -0
  300. package/src/shared/lib/browser/frame-pipeline.test.ts +132 -0
  301. package/src/shared/lib/browser/frame-pipeline.ts +80 -0
  302. package/src/shared/lib/browser/page-context.ts +60 -4
  303. package/src/shared/lib/browser/snapshot.test.ts +115 -0
  304. package/src/shared/lib/browser/snapshot.ts +112 -0
  305. package/src/shared/lib/browser/tab-close.test.ts +74 -0
  306. package/src/shared/lib/browser/tab-close.ts +77 -0
  307. package/src/shared/lib/browser/viewer.ts +45 -26
  308. package/src/shared/lib/chat/timeline/block-chrome.ts +19 -0
  309. package/src/shared/lib/chat/timeline/tool-render-mode.ts +17 -4
  310. package/src/shared/lib/chat/tool/artifact.ts +55 -20
  311. package/src/shared/lib/chat/tool/bash-facts.ts +96 -0
  312. package/src/shared/lib/chat/tool/minimized.test.ts +98 -0
  313. package/src/shared/lib/chat/tool/minimized.ts +64 -0
  314. package/src/shared/lib/chat/tool/summary.test.ts +28 -8
  315. package/src/shared/lib/chat/tool/summary.ts +3 -32
  316. package/src/shared/lib/fs/folder-chain.test.ts +81 -1
  317. package/src/shared/lib/fs/folder-chain.ts +84 -0
  318. package/src/shared/lib/markdown/blocks/anchor.ts +63 -0
  319. package/src/shared/lib/markdown/blocks/blocks.test.ts +141 -0
  320. package/src/shared/lib/markdown/blocks/renderer.ts +120 -0
  321. package/src/shared/lib/markdown/blocks/scan.ts +100 -0
  322. package/src/shared/lib/markdown/blocks/types.ts +62 -0
  323. package/src/shared/lib/markdown/marked.ts +58 -147
  324. package/src/shared/lib/markdown/math-extensions.ts +168 -0
  325. package/src/shared/lib/markdown/review/prompt.ts +77 -0
  326. package/src/shared/lib/markdown/review/reconcile.ts +55 -0
  327. package/src/shared/lib/markdown/review/review.test.ts +96 -0
  328. package/src/shared/lib/markdown/xml-sections.test.ts +140 -0
  329. package/src/shared/lib/markdown/xml-sections.ts +139 -0
  330. package/src/shared/lib/models/provider/label.ts +57 -0
  331. package/src/shared/lib/omp/config/agent-file.test.ts +54 -0
  332. package/src/shared/lib/omp/config/agent-file.ts +43 -0
  333. package/src/shared/lib/omp/config/row-value.test.ts +95 -0
  334. package/src/shared/lib/omp/config/row-value.ts +97 -0
  335. package/src/shared/lib/omp/config/schema.test.ts +66 -0
  336. package/src/shared/lib/omp/config/schema.ts +6 -0
  337. package/src/shared/lib/omp/rpc/frame.test.ts +48 -47
  338. package/src/shared/lib/omp/rpc/frame.ts +49 -40
  339. package/src/shared/lib/omp/session/job-progress.test.ts +37 -1
  340. package/src/shared/lib/omp/session/job-progress.ts +31 -0
  341. package/src/shared/lib/omp/session/proc.ts +5 -0
  342. package/src/shared/lib/omp/session/wait.ts +5 -0
  343. package/src/shared/lib/ui/menu-anchor.test.ts +69 -0
  344. package/src/shared/lib/ui/menu-anchor.ts +89 -0
  345. package/src/shared/lib/ui/mobile-overlay.ts +61 -0
  346. package/src/shared/lib/ui/svg-scope.test.ts +97 -0
  347. package/src/shared/lib/ui/svg-scope.ts +134 -0
  348. package/src/shared/lib/usage/breakdown.test.ts +197 -0
  349. package/src/shared/lib/usage/breakdown.ts +241 -0
  350. package/src/shared/lib/usage/range.test.ts +204 -0
  351. package/src/shared/lib/usage/range.ts +240 -0
  352. package/src/shared/lib/usage/view.test.ts +85 -0
  353. package/src/shared/lib/usage/view.ts +74 -0
  354. package/src/shared/lib/workspace/project-accent.test.ts +69 -0
  355. package/src/shared/lib/workspace/project-accent.ts +63 -0
  356. package/src/shared/lib/workspace/project-icon.ts +40 -0
  357. package/src/shared/lib/workspace/project-model.test.ts +79 -0
  358. package/src/shared/lib/workspace/project-model.ts +64 -0
  359. package/src/shared/types/browser.ts +78 -0
  360. package/src/shared/types/index.ts +1 -0
  361. package/src/shared/types/settings/agent.ts +28 -6
  362. package/src/shared/types/settings/skill.ts +53 -3
  363. package/src/shared/types/settings/state.ts +4 -3
  364. package/src/shared/types/settings/write.ts +6 -0
  365. package/src/shared/types/tokenUsage.ts +128 -21
  366. package/src/shared/types/updates.ts +20 -0
  367. package/src/test-support/file-explorer-disk.test-util.ts +25 -1
  368. package/src/test-support/file-explorer-drag.test-util.ts +88 -0
  369. package/src/test-support/file-explorer.test-util.ts +47 -47
  370. package/dist/client/static/js/index-fjnq2z2d.css +0 -1
  371. package/src/client/components/common/code-surface/indent-guide.ts +0 -104
  372. package/src/client/components/common/server-switcher/index.test.tsx +0 -150
  373. package/src/client/components/settings/categories/skill-catalog/AddSourceModal.tsx +0 -133
  374. package/src/client/hooks/desktop/servers.test.ts +0 -73
  375. package/src/client/lib/desktop/bridge.ts +0 -203
  376. package/src/server/lib/omp/session/usage/aggregate-shaping.test.ts +0 -149
  377. package/src/server/lib/omp/session/usage/aggregate.test.ts +0 -243
  378. package/src/server/lib/omp/session/usage/aggregate.ts +0 -330
  379. package/src/server/lib/omp/session/usage/shaping.ts +0 -130
  380. package/src/shared/lib/code/editor/indent-guide-rule.test.ts +0 -65
  381. package/src/shared/lib/code/editor/indent-guide-rule.ts +0 -47
@@ -1,5 +1,5 @@
1
1
  {
2
- "source": "@oh-my-pi/pi-coding-agent 10 tabs / 574 settings",
2
+ "source": "@oh-my-pi/pi-coding-agent 10 tabs / 582 settings",
3
3
  "tabs": [
4
4
  {
5
5
  "id": "appearance",
@@ -937,6 +937,16 @@
937
937
  "description": "When steering messages interrupt tool execution"
938
938
  }
939
939
  },
940
+ "btw.inject": {
941
+ "type": "boolean",
942
+ "default": false,
943
+ "ui": {
944
+ "tab": "interaction",
945
+ "group": "Input",
946
+ "label": "/btw Steering Inject",
947
+ "description": "When you ask /btw for a steering prompt, it drafts one in <inject> tags, highlighted in the answer; Alt+I (app.btw.inject) sends it to the main session"
948
+ }
949
+ },
940
950
  "tui.vimMode": {
941
951
  "type": "boolean",
942
952
  "default": false,
@@ -1203,6 +1213,17 @@
1203
1213
  "description": "After a completed turn, ask the active model to predict your next message and show it as ghost text in the empty composer; Tab or Right inserts it without sending. Extra usage: every completed turn sends one more billed request over the whole conversation (counted in /stats)"
1204
1214
  }
1205
1215
  },
1216
+ "composer.predictionAlternatives": {
1217
+ "type": "boolean",
1218
+ "default": false,
1219
+ "ui": {
1220
+ "tab": "interaction",
1221
+ "group": "Input",
1222
+ "label": "Prediction Alternatives",
1223
+ "description": "Ask for up to four distinct predictions instead of one, most likely first. The ghost text shows the first one your draft matches; after inserting one, press Tab again to pick another. The same single request returns a few more output tokens",
1224
+ "condition": "composerPredictionsEnabled"
1225
+ }
1226
+ },
1206
1227
  "spelling.autocorrect": {
1207
1228
  "type": "boolean",
1208
1229
  "default": false,
@@ -2291,7 +2312,7 @@
2291
2312
  {
2292
2313
  "value": "ultrafast",
2293
2314
  "label": "Ultrafast",
2294
- "description": "Lowest-latency serving; OpenAI API preview access, or Codex models that advertise it"
2315
+ "description": "Lowest-latency serving; OpenAI API preview access, or Codex and relay models that advertise it"
2295
2316
  }
2296
2317
  ]
2297
2318
  }
@@ -3155,6 +3176,16 @@
3155
3176
  "description": "Store Muse Code results on Meta's servers so a turn whose connection drops is recovered instead of re-run. Stored runs keep prompts and outputs on Meta's side."
3156
3177
  }
3157
3178
  },
3179
+ "providers.openai-codex.daybreak": {
3180
+ "type": "boolean",
3181
+ "default": true,
3182
+ "ui": {
3183
+ "tab": "providers",
3184
+ "group": "Protocol",
3185
+ "label": "Codex Daybreak Blue",
3186
+ "description": "Automatically request the Daybreak Blue cyber access program on ChatGPT accounts eligible for it. OpenAI may use content from Daybreak Blue sessions to improve its models. Does not cover dedicated Daybreak Blue models (gpt-daybreak-blue-*), which may still run as Daybreak sessions."
3187
+ }
3188
+ },
3158
3189
  "providers.cacheRetention": {
3159
3190
  "type": "enum",
3160
3191
  "default": "auto",
@@ -5142,6 +5173,17 @@
5142
5173
  "condition": "hindsightActive"
5143
5174
  }
5144
5175
  },
5176
+ "hindsight.globalScope": {
5177
+ "type": "boolean",
5178
+ "default": false,
5179
+ "ui": {
5180
+ "tab": "memory",
5181
+ "group": "Hindsight",
5182
+ "label": "Hindsight Global Scope",
5183
+ "description": "Let retain and learn take scope: global, which stores a memory without the project tag so every project recalls it. Needs global or per-project-tagged scoping",
5184
+ "condition": "hindsightActive"
5185
+ }
5186
+ },
5145
5187
  "hindsight.autoRecall": {
5146
5188
  "type": "boolean",
5147
5189
  "default": true,
@@ -6644,7 +6686,7 @@
6644
6686
  "tab": "tools",
6645
6687
  "group": "Execution",
6646
6688
  "label": "Live Job Widgets",
6647
- "description": "Draw a live widget for each running background job (charts, bars, status grids derived from its output) in the wait card, the jobs pill and the jobs sheet. The `widget` model role (default: `smol`) writes one spec per job; updates need no further model calls"
6689
+ "description": "Draw a live widget for each running background job (charts, bars, status grids derived from its output) in the wait card, the jobs pill and the jobs sheet, and caption long shell commands with one line on what they do. The `widget` model role (default: `smol`) writes one spec and at most one caption per job; updates need no further model calls"
6648
6690
  }
6649
6691
  },
6650
6692
  "tools.xdev": {
@@ -7343,6 +7385,50 @@
7343
7385
  "description": "Expose the optional effort parameter on task spawns, allowing callers to override each subagent's thinking level"
7344
7386
  }
7345
7387
  },
7388
+ "task.perCallModel": {
7389
+ "type": "enum",
7390
+ "default": "off",
7391
+ "values": [
7392
+ "off",
7393
+ "eval",
7394
+ "on"
7395
+ ],
7396
+ "ui": {
7397
+ "tab": "tasks",
7398
+ "group": "Subagents",
7399
+ "label": "Per-Call Model",
7400
+ "description": "Whether a subagent call may pick its model with one exact provider/model-id[@upstream][:level] selector. An @upstream pin is part of the model identity and is supported only by aggregators. Only models the configuration already routes to are accepted. Project settings can turn it off but not on, and never approve a model.",
7401
+ "options": [
7402
+ {
7403
+ "value": "off",
7404
+ "label": "Off",
7405
+ "description": "Reject `model` on task items and eval agent()/workpool()"
7406
+ },
7407
+ {
7408
+ "value": "eval",
7409
+ "label": "Eval only",
7410
+ "description": "Accept `model` in eval agent() and workpool() only"
7411
+ },
7412
+ {
7413
+ "value": "on",
7414
+ "label": "On",
7415
+ "description": "Accept `model` on task items and in eval agent()/workpool()"
7416
+ }
7417
+ ]
7418
+ }
7419
+ },
7420
+ "task.perCallModelAllow": {
7421
+ "type": "array",
7422
+ "default": [],
7423
+ "ui": {
7424
+ "tab": "tasks",
7425
+ "group": "Subagents",
7426
+ "label": "Per-Call Model Allowlist",
7427
+ "editor": "json",
7428
+ "condition": "perCallModelAllowNotProject",
7429
+ "description": "Exact selectors: `provider/model-id`, including `@upstream` only for a pinned OpenRouter/Vercel route (e.g. `openrouter/x@y`). When set, a per-call model must also be listed here. Empty: every model the configuration grants. A project list can only narrow this one."
7430
+ }
7431
+ },
7346
7432
  "task.maxConcurrency": {
7347
7433
  "type": "number",
7348
7434
  "default": 32,
@@ -7536,7 +7622,7 @@
7536
7622
  "tab": "tasks",
7537
7623
  "group": "Subagents",
7538
7624
  "label": "Maximum Per-Spawn Effort",
7539
- "description": "Maximum reasoning effort allowed for the task tool's per-spawn effort hint. Lower values prevent callers from escalating subagents above this ceiling; the default preserves the model's full range.",
7625
+ "description": "Maximum reasoning effort allowed for the task tool's per-spawn effort hint or a per-call model. An explicit `:level` is clamped to the highest supported effort at or below this ceiling, and an omitted `:level` inherits the agent's thinking level capped at this value; cold revival re-applies the cap. Unset, `:inherit` and `:off` keep their existing meaning. A per-call model must support an effort at or below this ceiling; the default preserves the model's full range.",
7540
7626
  "options": [
7541
7627
  {
7542
7628
  "value": "minimal",
@@ -7733,6 +7819,39 @@
7733
7819
  "description": "Refresh generated session titles after todo init replans unless the title was set by the user"
7734
7820
  }
7735
7821
  },
7822
+ "title.refreshAfterPrompts": {
7823
+ "type": "number",
7824
+ "default": 0,
7825
+ "ui": {
7826
+ "tab": "tasks",
7827
+ "group": "Modes",
7828
+ "label": "Refresh Title After Prompts",
7829
+ "description": "Every this many operator prompts, ask the judge model whether a generated session title still fits the conversation, and regenerate it if not",
7830
+ "options": [
7831
+ {
7832
+ "value": "0",
7833
+ "label": "Off",
7834
+ "description": "Default"
7835
+ },
7836
+ {
7837
+ "value": "1",
7838
+ "label": "Every prompt"
7839
+ },
7840
+ {
7841
+ "value": "3",
7842
+ "label": "Every 3 prompts"
7843
+ },
7844
+ {
7845
+ "value": "5",
7846
+ "label": "Every 5 prompts"
7847
+ },
7848
+ {
7849
+ "value": "10",
7850
+ "label": "Every 10 prompts"
7851
+ }
7852
+ ]
7853
+ }
7854
+ },
7736
7855
  "skills.registryUrl": {
7737
7856
  "type": "string",
7738
7857
  "default": "https://skills.omp.sh",
@@ -1,5 +1,13 @@
1
- import type { AccentColorOption, ProjectConfigItem } from '@/shared/types';
1
+ import type { ProjectConfigItem } from '@/shared/types';
2
2
 
3
+ /**
4
+ * Legacy seed rows for the one-shot migration off `omp_projects_config`.
5
+ *
6
+ * Read ONLY by `migrateLegacyProjectSettings`: when the legacy row exists but
7
+ * is not an array, that migration falls back to this list. Nothing else may
8
+ * read it — the live project list comes from the `workspace_folders` table, and
9
+ * the accent palette lives in `@/shared/lib/workspace/project-accent`.
10
+ */
3
11
  export const DEFAULT_PROJECTS_LIST: ProjectConfigItem[] = [
4
12
  { id: 'proj-workspace', name: 'Workspace', path: '/Users/rajebdev/JatisMobile/Workspace', model: 'Not selected', accentColor: '#a3e635', icon: 'default' },
5
13
  { id: 'proj-drrealhandler', name: 'drrealhandler', path: '/Users/rajebdev/JatisMobile/drrealhandler', model: 'Not selected', accentColor: '#94a3b8', icon: 'default' },
@@ -29,30 +37,3 @@ export const DEFAULT_PROJECTS_LIST: ProjectConfigItem[] = [
29
37
  { id: 'proj-ompweb', name: 'ompweb', path: '/Users/rajebdev/JatisMobile/ompweb', model: 'Not selected', accentColor: '#f43f5e', icon: 'default' },
30
38
  { id: 'proj-kabmo', name: 'kabmo', path: '/Users/rajebdev/JatisMobile/kabmo', model: 'Not selected', accentColor: '#38bdf8', icon: 'default' },
31
39
  ];
32
-
33
- export const ACCENT_COLOR_OPTIONS: AccentColorOption[] = [
34
- { label: 'None', value: '', bgHex: 'transparent' },
35
- { label: 'Sky Blue', value: '#38bdf8', bgHex: '#38bdf8' },
36
- { label: 'Light Green', value: '#a3e635', bgHex: '#a3e635' },
37
- { label: 'Coral', value: '#f87171', bgHex: '#f87171' },
38
- { label: 'Amber', value: '#fbbf24', bgHex: '#fbbf24' },
39
- { label: 'Teal', value: '#2dd4bf', bgHex: '#2dd4bf' },
40
- { label: 'Slate', value: '#94a3b8', bgHex: '#94a3b8' },
41
- { label: 'Rose', value: '#f43f5e', bgHex: '#f43f5e' },
42
- { label: 'Vivid Blue', value: '#3b82f6', bgHex: '#3b82f6' },
43
- { label: 'Lime Green', value: '#84cc16', bgHex: '#84cc16' },
44
- ];
45
-
46
- export const AVAILABLE_PROJECT_MODELS: string[] = [
47
- 'Not selected',
48
- 'DeepSeek-V3',
49
- 'DeepSeek-R1',
50
- 'Claude 3.5 Sonnet',
51
- 'Claude 3.7 Sonnet',
52
- 'GPT-4o',
53
- 'GPT-4o-mini',
54
- 'Gemini 2.5 Flash',
55
- 'Gemini 2.5 Pro',
56
- 'Qwen 2.5 Coder 32B',
57
- 'Llama 3.3 70B',
58
- ];
@@ -153,38 +153,12 @@ description: "Automated pre-flight security review, secret leak inspection, and
153
153
  ];
154
154
 
155
155
  export const DEFAULT_CATALOG_SOURCES: SkillCatalogSource[] = [
156
- {
157
- id: 'anthropic',
158
- name: 'Anthropic',
159
- repo: 'anthropics/skills',
160
- stars: '175K',
161
- updatedAt: 'Updated 3d ago',
162
- skillCount: 20,
163
- },
164
- {
165
- id: 'openai',
166
- name: 'OpenAI',
167
- repo: 'openai/skills',
168
- stars: '26K',
169
- updatedAt: 'Updated 7w ago',
170
- skillCount: 14,
171
- },
172
- {
173
- id: 'cursor',
174
- name: 'Cursor',
175
- repo: 'cursor/plugins',
176
- stars: '7K',
177
- updatedAt: 'Updated 2d ago',
178
- skillCount: 18,
179
- },
180
- {
181
- id: 'matt-pocock',
182
- name: 'Matt Pocock',
183
- repo: 'mattpocock/skills',
184
- stars: '255K',
185
- updatedAt: 'Updated 2d ago',
186
- skillCount: 12,
187
- },
156
+ // `skillCount: null` — these counts are NOT known until a scan runs, and the
157
+ // card says "Not scanned" rather than printing an invented number.
158
+ { id: 'anthropic', name: 'Anthropic', repo: 'anthropics/skills', skillCount: null },
159
+ { id: 'openai', name: 'OpenAI', repo: 'openai/skills', skillCount: null },
160
+ { id: 'cursor', name: 'Cursor', repo: 'cursor/plugins', skillCount: null },
161
+ { id: 'matt-pocock', name: 'Matt Pocock', repo: 'mattpocock/skills', skillCount: null },
188
162
  ];
189
163
 
190
164
  export const DEFAULT_CATALOG_SKILLS: CatalogSkillItem[] = [
@@ -0,0 +1,143 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Annotating the user-browser panel.
8
+ *
9
+ * The failure this hook has to prevent is a mark outliving the page it was drawn
10
+ * on. An iframe's internal navigation is invisible from this origin — the host
11
+ * gets `onLoad` and nothing else — so a reload or a typed address is the only
12
+ * signal that the document under the marks changed. Sending that stale batch
13
+ * would point the agent at percentages of a page the user has left.
14
+ */
15
+
16
+ import { afterAll, beforeAll, beforeEach, describe, expect, test } from 'bun:test';
17
+ import { Window } from 'happy-dom';
18
+ import { h, render } from 'preact';
19
+ import { act } from 'preact/test-utils';
20
+ import { useState } from 'preact/hooks';
21
+ import { useAnnotate, type UseAnnotateResult } from '@/client/hooks/browser/use-annotate';
22
+ import type { AnnotateShape } from '@/shared/types';
23
+
24
+ const DOM_GLOBALS = ['window', 'document', 'navigator', 'Node', 'Element', 'HTMLElement', 'Event'] as const;
25
+ const native: Partial<Record<(typeof DOM_GLOBALS)[number], unknown>> = {};
26
+
27
+ beforeAll(() => {
28
+ const win = new Window({ url: 'http://localhost' });
29
+ const target = globalThis as unknown as Record<string, unknown>;
30
+ for (const key of DOM_GLOBALS) {
31
+ native[key] = target[key];
32
+ target[key] = (win as unknown as Record<string, unknown>)[key];
33
+ }
34
+ });
35
+
36
+ afterAll(() => {
37
+ const target = globalThis as unknown as Record<string, unknown>;
38
+ for (const key of DOM_GLOBALS) {
39
+ if (native[key] === undefined) delete target[key];
40
+ else target[key] = native[key];
41
+ }
42
+ });
43
+
44
+ function mark(id: string, note = ''): AnnotateShape {
45
+ return { id, tool: 'box', start: { x: 0.1, y: 0.1 }, end: { x: 0.3, y: 0.3 }, label: '', note };
46
+ }
47
+
48
+ let container: HTMLElement | undefined;
49
+ let latest: UseAnnotateResult | undefined;
50
+ /** Drives the hook's page key, the way the panel's `frameKey` does. */
51
+ let navigate: (key: number) => void;
52
+
53
+ const api = (): UseAnnotateResult => {
54
+ if (!latest) throw new Error('hook not rendered');
55
+ return latest;
56
+ };
57
+
58
+ /** Mount the hook with a page key the test can change. */
59
+ function mount(): void {
60
+ const Probe = () => {
61
+ const [frameKey, setFrameKey] = useState(0);
62
+ navigate = setFrameKey;
63
+ latest = useAnnotate(frameKey);
64
+ return h('div', null);
65
+ };
66
+ act(() => {
67
+ render(h(Probe, null), container!);
68
+ });
69
+ }
70
+
71
+ beforeEach(() => {
72
+ container?.remove();
73
+ container = document.body.appendChild(document.createElement('div'));
74
+ latest = undefined;
75
+ });
76
+
77
+ describe('useAnnotate', () => {
78
+ test('starts closed, with the box tool and no marks', () => {
79
+ mount();
80
+ expect(api().active).toBe(false);
81
+ expect(api().tool).toBe('box');
82
+ expect(api().shapes).toEqual([]);
83
+ });
84
+
85
+ test('toggle opens the mode and close shuts it, dropping the selection', () => {
86
+ mount();
87
+ act(() => api().toggle());
88
+ expect(api().active).toBe(true);
89
+ act(() => api().add(mark('a')));
90
+ expect(api().selectedId).toBe('a');
91
+ act(() => api().close());
92
+ expect(api().active).toBe(false);
93
+ expect(api().selectedId).toBeNull();
94
+ // Closing the mode is not the same as discarding the marks.
95
+ expect(api().shapes).toHaveLength(1);
96
+ });
97
+
98
+ test('a finished mark is committed and becomes the one being described', () => {
99
+ mount();
100
+ act(() => api().add(mark('a')));
101
+ act(() => api().add(mark('b')));
102
+ expect(api().shapes.map((shape) => shape.id)).toEqual(['a', 'b']);
103
+ expect(api().selectedId).toBe('b');
104
+ });
105
+
106
+ test('a note is stored on its own mark only', () => {
107
+ mount();
108
+ act(() => api().add(mark('a')));
109
+ act(() => api().add(mark('b')));
110
+ act(() => api().setNote('a', 'tombol mati'));
111
+ expect(api().shapes.map((shape) => shape.note)).toEqual(['tombol mati', '']);
112
+ });
113
+
114
+ test('removing the selected mark clears the selection; removing another leaves it', () => {
115
+ mount();
116
+ act(() => api().add(mark('a')));
117
+ act(() => api().add(mark('b')));
118
+ act(() => api().remove('a'));
119
+ expect(api().selectedId).toBe('b');
120
+ act(() => api().remove('b'));
121
+ expect(api().selectedId).toBeNull();
122
+ expect(api().shapes).toEqual([]);
123
+ });
124
+
125
+ test('reset clears the marks but leaves the mode as it was', () => {
126
+ mount();
127
+ act(() => api().toggle());
128
+ act(() => api().add(mark('a')));
129
+ act(() => api().reset());
130
+ expect(api().shapes).toEqual([]);
131
+ expect(api().active).toBe(true);
132
+ });
133
+
134
+ test('a new page drops every mark drawn on the old one', () => {
135
+ mount();
136
+ act(() => api().add(mark('a')));
137
+ act(() => api().add(mark('b')));
138
+ expect(api().shapes).toHaveLength(2);
139
+ act(() => navigate(1));
140
+ expect(api().shapes).toEqual([]);
141
+ expect(api().selectedId).toBeNull();
142
+ });
143
+ });
@@ -0,0 +1,98 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Annotating the user-browser panel.
8
+ *
9
+ * The marks belong to ONE page view. An iframe's internal navigation is not
10
+ * observable from this origin (`onLoad` is all the host gets), so a mark made
11
+ * before a navigation would otherwise point at a different document than the
12
+ * one it was drawn on. `frameKey` therefore clears the marks: a reload or a
13
+ * typed address is a new page, and keeping them would send the agent
14
+ * coordinates for a page the user is no longer looking at.
15
+ *
16
+ * The mark being DRAGGED is not state here — it lives in the overlay that draws
17
+ * it, and arrives as one finished shape through `add`. A pointermove-driven
18
+ * value in this hook would re-render the panel (iframe included) on every move.
19
+ */
20
+
21
+ import { useCallback, useEffect, useState } from 'preact/hooks';
22
+ import type { AnnotateShape, AnnotateTool } from '@/shared/types';
23
+
24
+ export interface UseAnnotateResult {
25
+ active: boolean;
26
+ tool: AnnotateTool;
27
+ shapes: AnnotateShape[];
28
+ /** The mark whose note field is open, if any. */
29
+ selectedId: string | null;
30
+ setTool: (tool: AnnotateTool) => void;
31
+ toggle: () => void;
32
+ close: () => void;
33
+ /** Commit one finished mark and open its note field. */
34
+ add: (shape: AnnotateShape) => void;
35
+ setNote: (id: string, note: string) => void;
36
+ /** Name the region a mark covers ("Ringkasan pesanan"); the user owns this fact. */
37
+ setLabel: (id: string, label: string) => void;
38
+ select: (id: string | null) => void;
39
+ remove: (id: string) => void;
40
+ reset: () => void;
41
+ }
42
+
43
+ let shapeSeq = 0;
44
+
45
+ /** Ids are unique per mark; the overlay stamps one when the drag starts. */
46
+ export function nextShapeId(): string {
47
+ shapeSeq += 1;
48
+ return `annot-${Date.now().toString(36)}-${shapeSeq}`;
49
+ }
50
+
51
+ export function useAnnotate(frameKey: number): UseAnnotateResult {
52
+ const [active, setActive] = useState(false);
53
+ const [tool, setTool] = useState<AnnotateTool>('box');
54
+ const [shapes, setShapes] = useState<AnnotateShape[]>([]);
55
+ const [selectedId, setSelectedId] = useState<string | null>(null);
56
+
57
+ // A new page invalidates every mark on the old one.
58
+ useEffect(() => {
59
+ setShapes([]);
60
+ setSelectedId(null);
61
+ }, [frameKey]);
62
+
63
+ const toggle = useCallback(() => {
64
+ setActive((prev) => !prev);
65
+ setSelectedId(null);
66
+ }, []);
67
+
68
+ const close = useCallback(() => {
69
+ setSelectedId(null);
70
+ setActive(false);
71
+ }, []);
72
+
73
+ const add = useCallback((shape: AnnotateShape) => {
74
+ setShapes((prev) => [...prev, shape]);
75
+ // A finished mark is the one the user is about to describe.
76
+ setSelectedId(shape.id);
77
+ }, []);
78
+
79
+ const setNote = useCallback((id: string, note: string) => {
80
+ setShapes((prev) => prev.map((shape) => (shape.id === id ? { ...shape, note } : shape)));
81
+ }, []);
82
+
83
+ const setLabel = useCallback((id: string, label: string) => {
84
+ setShapes((prev) => prev.map((shape) => (shape.id === id ? { ...shape, label } : shape)));
85
+ }, []);
86
+
87
+ const remove = useCallback((id: string) => {
88
+ setShapes((prev) => prev.filter((shape) => shape.id !== id));
89
+ setSelectedId((current) => (current === id ? null : current));
90
+ }, []);
91
+
92
+ const reset = useCallback(() => {
93
+ setShapes([]);
94
+ setSelectedId(null);
95
+ }, []);
96
+
97
+ return { active, tool, shapes, selectedId, setTool, toggle, close, add, setNote, setLabel, select: setSelectedId, remove, reset };
98
+ }
@@ -0,0 +1,148 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The client half of "close this tab".
8
+ *
9
+ * The rules live on the server (`tab-close.ts`, `routes/browser/tabs.ts`); what
10
+ * this hook must get right is the request it sends, the tab it names for the
11
+ * panel next, and — the failure that actually bites — that a refused close is
12
+ * REPORTED rather than looking like a tab that merely came back.
13
+ */
14
+
15
+ import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test } from 'bun:test';
16
+ import { Window } from 'happy-dom';
17
+ import { h, render } from 'preact';
18
+ import { act } from 'preact/test-utils';
19
+
20
+ import { useCloseBrowserTab } from '@/client/hooks/browser/use-close-tab';
21
+
22
+ const DOM_GLOBALS = ['window', 'document', 'navigator', 'Node', 'Element', 'HTMLElement', 'Event'] as const;
23
+ const native: Partial<Record<(typeof DOM_GLOBALS)[number], unknown>> = {};
24
+
25
+ beforeAll(() => {
26
+ const win = new Window({ url: 'http://localhost' });
27
+ const target = globalThis as unknown as Record<string, unknown>;
28
+ for (const key of DOM_GLOBALS) {
29
+ native[key] = target[key];
30
+ target[key] = (win as unknown as Record<string, unknown>)[key];
31
+ }
32
+ });
33
+
34
+ afterAll(() => {
35
+ const target = globalThis as unknown as Record<string, unknown>;
36
+ for (const key of DOM_GLOBALS) {
37
+ if (native[key] === undefined) delete target[key];
38
+ else target[key] = native[key];
39
+ }
40
+ });
41
+
42
+ const globals = globalThis as unknown as Record<string, unknown>;
43
+ const nativeFetch = globals.fetch;
44
+
45
+ interface Captured {
46
+ url: string;
47
+ method: string;
48
+ body: unknown;
49
+ }
50
+
51
+ let captured: Captured[] = [];
52
+ let reply: { status: number; body: unknown } = { status: 200, body: { ok: true, next: 't3' } };
53
+ let hook: ReturnType<typeof useCloseBrowserTab> | null = null;
54
+
55
+ function Probe({ sessionId }: { sessionId: string }) {
56
+ hook = useCloseBrowserTab(sessionId);
57
+ return h('div', null, hook.closing ?? '');
58
+ }
59
+
60
+ beforeEach(() => {
61
+ captured = [];
62
+ reply = { status: 200, body: { ok: true, next: 't3' } };
63
+ globals.fetch = (url: string, init: RequestInit) => {
64
+ captured.push({ url, method: init.method ?? 'GET', body: JSON.parse(String(init.body)) });
65
+ return Promise.resolve(new Response(JSON.stringify(reply.body), { status: reply.status }));
66
+ };
67
+ hook = null;
68
+ });
69
+
70
+ afterEach(() => {
71
+ globals.fetch = nativeFetch;
72
+ });
73
+
74
+ async function mount(sessionId = 'session-1'): Promise<void> {
75
+ const host = document.createElement('div');
76
+ await act(async () => {
77
+ render(h(Probe, { sessionId }), host);
78
+ });
79
+ }
80
+
81
+ describe('useCloseBrowserTab', () => {
82
+ test('posts the target id to the session’s own close route', async () => {
83
+ await mount();
84
+ const result = await hook!.closeTab('t2');
85
+ expect(captured).toEqual([
86
+ { url: '/api/browser/session-1/tabs/close', method: 'POST', body: { targetId: 't2' } },
87
+ ]);
88
+ expect(result).toEqual({ ok: true, next: 't3' });
89
+ });
90
+
91
+ test('returns null when no tab is left to select', async () => {
92
+ reply = { status: 200, body: { ok: true, next: null } };
93
+ await mount();
94
+ expect(await hook!.closeTab('only')).toEqual({ ok: true, next: null });
95
+ });
96
+
97
+ test('a refusal is reported with the server’s own wording', async () => {
98
+ reply = { status: 403, body: { error: 'That tab does not belong to this session' } };
99
+ await mount();
100
+ expect(await hook!.closeTab('other')).toEqual({
101
+ ok: false,
102
+ next: null,
103
+ error: 'That tab does not belong to this session',
104
+ });
105
+ });
106
+
107
+ test('a refusal with no message still names the status', async () => {
108
+ reply = { status: 503, body: {} };
109
+ await mount();
110
+ expect((await hook!.closeTab('t1')).error).toBe('Close failed (503)');
111
+ });
112
+
113
+ test('a network failure does not look like a closed tab', async () => {
114
+ globals.fetch = () => Promise.reject(new Error('offline'));
115
+ await mount();
116
+ const result = await hook!.closeTab('t1');
117
+ expect(result.ok).toBe(false);
118
+ expect(result.error).toContain('offline');
119
+ });
120
+
121
+ test('a closed tab id is percent-encoded into the URL', async () => {
122
+ await mount('a/b');
123
+ await hook!.closeTab('t1');
124
+ expect(captured[0].url).toBe('/api/browser/a%2Fb/tabs/close');
125
+ });
126
+
127
+ test('an empty target is refused without a request', async () => {
128
+ await mount();
129
+ expect(await hook!.closeTab('')).toEqual({ ok: false, next: null, error: 'No tab to close' });
130
+ expect(captured).toEqual([]);
131
+ });
132
+
133
+ test('a close already in flight leaves its tab marked, then clears', async () => {
134
+ const { promise, resolve } = Promise.withResolvers<Response>();
135
+ globals.fetch = () => promise;
136
+ await mount();
137
+ let pending: Promise<unknown> | null = null;
138
+ await act(async () => {
139
+ pending = hook!.closeTab('t2');
140
+ });
141
+ expect(hook!.closing).toBe('t2');
142
+ await act(async () => {
143
+ resolve(new Response(JSON.stringify({ ok: true, next: null }), { status: 200 }));
144
+ await pending;
145
+ });
146
+ expect(hook!.closing).toBeNull();
147
+ });
148
+ });