@kabmo-labs/kabmo 0.17.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 (269) hide show
  1. package/dist/client/index.html +1 -1
  2. package/dist/client/index.js +538 -457
  3. package/dist/client/static/js/index-hp75vsv9.css +1 -0
  4. package/dist/client/static/js/{index-rerjq5th.js → index-tc09dtca.js} +823 -814
  5. package/package.json +1 -1
  6. package/src/client/components/common/MarkdownRenderer.tsx +136 -89
  7. package/src/client/components/common/anchored-menu/index.test.tsx +141 -0
  8. package/src/client/components/common/anchored-menu/index.tsx +143 -0
  9. package/src/client/components/common/markdown-review/ReviewPopover.tsx +144 -0
  10. package/src/client/components/common/markdown-review/ReviewSummary.tsx +108 -0
  11. package/src/client/components/common/markdown-review/index.tsx +129 -0
  12. package/src/client/components/common/server-control/Panel.tsx +33 -23
  13. package/src/client/components/common/server-control/index.test.tsx +11 -5
  14. package/src/client/components/common/server-control/index.tsx +10 -8
  15. package/src/client/components/layout/session-sidebar/CategoryHeader.tsx +42 -21
  16. package/src/client/components/layout/session-sidebar/CategoryHeader.worktree.test.tsx +36 -17
  17. package/src/client/components/layout/session-sidebar/CategoryItem.tsx +8 -7
  18. package/src/client/components/layout/session-sidebar/about-modal/NotesDialog.tsx +94 -0
  19. package/src/client/components/layout/session-sidebar/about-modal/VersionLine.test.tsx +68 -0
  20. package/src/client/components/layout/session-sidebar/about-modal/VersionLine.tsx +36 -0
  21. package/src/client/components/layout/session-sidebar/about-modal/index.tsx +57 -34
  22. package/src/client/components/layout/session-sidebar/modern/WorkspaceHeader.tsx +28 -10
  23. package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +7 -6
  24. package/src/client/components/layout/session-sidebar/modern/workspace-header.test.tsx +1 -1
  25. package/src/client/components/layout/update-popup/ReleaseNotes.tsx +8 -3
  26. package/src/client/components/layout/update-popup/index.tsx +5 -1
  27. package/src/client/components/mobile/mobile-right-sidebar/FullEditor.tsx +13 -15
  28. package/src/client/components/mobile/mobile-right-sidebar/Header.tsx +23 -1
  29. package/src/client/components/mobile/mobile-right-sidebar/MissingFileBanner.tsx +30 -0
  30. package/src/client/components/mobile/mobile-right-sidebar/PreviewScroller.tsx +18 -2
  31. package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +22 -67
  32. package/src/client/components/mobile/mobile-session-sidebar/ItemMenu.tsx +110 -0
  33. package/src/client/components/settings/SettingsSidebarList.tsx +20 -0
  34. package/src/client/components/settings/categories/AgentSettings.tsx +23 -50
  35. package/src/client/components/settings/categories/CommandSettings.tsx +2 -2
  36. package/src/client/components/settings/categories/McpSettings.tsx +4 -21
  37. package/src/client/components/settings/categories/OmpSettings.tsx +147 -194
  38. package/src/client/components/settings/categories/SkillSettings.tsx +2 -2
  39. package/src/client/components/settings/categories/TokenUsageSettings.tsx +211 -229
  40. package/src/client/components/settings/categories/agent-settings/DetailPane.tsx +229 -237
  41. package/src/client/components/settings/categories/agent-settings/ModelPicker.tsx +71 -0
  42. package/src/client/components/settings/categories/agent-settings/SidebarList.tsx +9 -2
  43. package/src/client/components/settings/categories/agent-settings/levels.ts +38 -0
  44. package/src/client/components/settings/categories/behavior-settings/Editor.tsx +27 -7
  45. package/src/client/components/settings/categories/chat-settings/ToolRenderSection.tsx +23 -5
  46. package/src/client/components/settings/categories/command-settings/DetailPane.tsx +75 -33
  47. package/src/client/components/settings/categories/command-settings/SidebarList.tsx +7 -0
  48. package/src/client/components/settings/categories/mcp-settings/DetailPane.tsx +91 -76
  49. package/src/client/components/settings/categories/mcp-settings/EnvVarsSection.tsx +83 -0
  50. package/src/client/components/settings/categories/mcp-settings/ImportModal.tsx +26 -13
  51. package/src/client/components/settings/categories/mcp-settings/SidebarList.tsx +20 -0
  52. package/src/client/components/settings/categories/omp-settings/ConfigTabs.tsx +97 -36
  53. package/src/client/components/settings/categories/omp-settings/EngineHeader.tsx +151 -0
  54. package/src/client/components/settings/categories/omp-settings/ExtensionsPanel.tsx +68 -32
  55. package/src/client/components/settings/categories/omp-settings/OrderedChips.tsx +119 -0
  56. package/src/client/components/settings/categories/omp-settings/PresetBar.tsx +14 -7
  57. package/src/client/components/settings/categories/omp-settings/RoleEditor.tsx +15 -6
  58. package/src/client/components/settings/categories/omp-settings/RowEditor.tsx +165 -226
  59. package/src/client/components/settings/categories/omp-settings/types.ts +28 -0
  60. package/src/client/components/settings/categories/skill-settings/DetailHeader.tsx +35 -7
  61. package/src/client/components/settings/categories/skill-settings/DetailPane.tsx +34 -14
  62. package/src/client/components/settings/categories/skill-settings/SidebarList.tsx +21 -0
  63. package/src/client/components/settings/categories/skill-settings/pane.test.tsx +15 -6
  64. package/src/client/components/settings/categories/token-usage-settings/Breakdown.tsx +242 -102
  65. package/src/client/components/settings/categories/token-usage-settings/Chart.tsx +130 -56
  66. package/src/client/components/settings/categories/token-usage-settings/Controls.tsx +135 -0
  67. package/src/client/components/settings/categories/token-usage-settings/MetricsGrid.tsx +55 -33
  68. package/src/client/components/settings/categories/token-usage-settings/Provenance.tsx +59 -0
  69. package/src/client/components/settings/categories/token-usage-settings/panel.test.tsx +239 -0
  70. package/src/client/components/workspace/browser-panel/Screencast.test.ts +1 -0
  71. package/src/client/components/workspace/browser-panel/Screencast.tsx +17 -22
  72. package/src/client/components/workspace/browser-panel/TabStrip.test.tsx +158 -0
  73. package/src/client/components/workspace/browser-panel/TabStrip.tsx +90 -0
  74. package/src/client/components/workspace/browser-panel/index.tsx +50 -4
  75. package/src/client/components/workspace/browser-toolbar/index.tsx +41 -1
  76. package/src/client/components/workspace/chat-timeline/ThinkingSection.tsx +3 -1
  77. package/src/client/components/workspace/chat-timeline/ToolCallingSection.tsx +2 -0
  78. package/src/client/components/workspace/chat-timeline/block-chrome.test.tsx +13 -2
  79. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Bash.test.ts +88 -0
  80. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Bash.tsx +24 -1
  81. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Read.test.ts +34 -0
  82. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Read.tsx +5 -1
  83. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/ArtifactChip.tsx +7 -6
  84. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Tui.test.tsx +237 -0
  85. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Tui.tsx +191 -0
  86. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/styles.test.tsx +1 -1
  87. package/src/client/components/workspace/diff-panel/MergeDiffView.tsx +21 -7
  88. package/src/client/components/workspace/diff-panel/changes.test.ts +51 -0
  89. package/src/client/components/workspace/diff-panel/changes.ts +28 -12
  90. package/src/client/components/workspace/diff-panel/merge.test.ts +28 -0
  91. package/src/client/components/workspace/diff-panel/merge.ts +21 -1
  92. package/src/client/components/workspace/editor/Body.tsx +7 -0
  93. package/src/client/components/workspace/editor/FileDocument.tsx +15 -21
  94. package/src/client/components/workspace/editor/FilePane.tsx +12 -0
  95. package/src/client/components/workspace/editor/PreviewPane.tsx +70 -0
  96. package/src/client/components/workspace/editor/Toolbar.tsx +17 -1
  97. package/src/client/components/workspace/editor/index.tsx +25 -22
  98. package/src/client/components/workspace/editor/toolbar-clusters.test.ts +14 -0
  99. package/src/client/components/workspace/editor/toolbar-clusters.tsx +12 -86
  100. package/src/client/components/workspace/editor/toolbar-toggle.tsx +53 -0
  101. package/src/client/components/workspace/editor/toolbar-write-clusters.tsx +112 -0
  102. package/src/client/components/workspace/git-panel/commit-modal.test.ts +5 -3
  103. package/src/client/components/workspace/user-browser-panel/AddressBar.tsx +5 -0
  104. package/src/client/components/workspace/user-browser-panel/AnnotateBar.test.tsx +201 -0
  105. package/src/client/components/workspace/user-browser-panel/AnnotateBar.tsx +112 -0
  106. package/src/client/components/workspace/user-browser-panel/AnnotateLayer.test.tsx +225 -0
  107. package/src/client/components/workspace/user-browser-panel/AnnotateLayer.tsx +217 -0
  108. package/src/client/components/workspace/user-browser-panel/AnnotateTarget.tsx +99 -0
  109. package/src/client/components/workspace/user-browser-panel/Frame.tsx +30 -1
  110. package/src/client/components/workspace/user-browser-panel/index.tsx +81 -2
  111. package/src/client/data/agent-data/builtin.ts +0 -10
  112. package/src/client/data/agent-data/orchestrator.ts +0 -45
  113. package/src/client/data/agent-data/specialist.ts +0 -100
  114. package/src/client/data/mock/token-usage.ts +170 -120
  115. package/src/client/data/settings/omp-schema.json +33 -1
  116. package/src/client/hooks/browser/use-annotate.test.ts +143 -0
  117. package/src/client/hooks/browser/use-annotate.ts +98 -0
  118. package/src/client/hooks/browser/use-close-tab.test.ts +148 -0
  119. package/src/client/hooks/browser/use-close-tab.ts +67 -0
  120. package/src/client/hooks/browser/use-screencast.ts +13 -1
  121. package/src/client/hooks/chat/composer/browser-context.test.ts +117 -0
  122. package/src/client/hooks/chat/composer/browser-context.ts +40 -16
  123. package/src/client/hooks/chat/composer/items.test.ts +1 -1
  124. package/src/client/hooks/chat/composer/review-context.ts +38 -0
  125. package/src/client/hooks/chat/composer/use-draft.test.ts +132 -0
  126. package/src/client/hooks/chat/composer/use-draft.ts +31 -2
  127. package/src/client/hooks/chat/timeline/row-window.test.ts +15 -2
  128. package/src/client/hooks/editor/use-document-annotations.ts +124 -0
  129. package/src/client/hooks/editor/use-editor-panel-ui.ts +52 -0
  130. package/src/client/hooks/editor/use-file-review-mode.ts +35 -0
  131. package/src/client/hooks/editor/use-preview-review.ts +148 -0
  132. package/src/client/hooks/settings/agents.ts +149 -0
  133. package/src/client/hooks/settings/crud-list.test.ts +28 -6
  134. package/src/client/hooks/settings/crud-list.ts +96 -57
  135. package/src/client/hooks/settings/omp-config.ts +164 -0
  136. package/src/client/hooks/settings/useTokenUsage.ts +125 -0
  137. package/src/client/hooks/settings/write-feedback.test.ts +104 -0
  138. package/src/client/hooks/settings/write-feedback.ts +63 -0
  139. package/src/client/hooks/ui/markdown-hydration.ts +125 -0
  140. package/src/client/hooks/ui/updates/index.test.ts +100 -1
  141. package/src/client/hooks/ui/updates/index.ts +50 -0
  142. package/src/client/hooks/ui/updates/notes.test.ts +138 -0
  143. package/src/client/hooks/ui/updates/notes.ts +57 -0
  144. package/src/client/lib/browser/element-at.test.ts +229 -0
  145. package/src/client/lib/browser/element-at.ts +139 -0
  146. package/src/client/lib/review/client.ts +73 -0
  147. package/src/client/lib/router/search-params.ts +42 -20
  148. package/src/client/tailwind.css +65 -0
  149. package/src/server/lib/btw/lifecycle.server.ts +2 -2
  150. package/src/server/lib/db/schema.ts +7 -0
  151. package/src/server/lib/db/seed-terminal.test.ts +4 -0
  152. package/src/server/lib/omp/config/agent-definitions.test.ts +273 -0
  153. package/src/server/lib/omp/config/agents.ts +231 -61
  154. package/src/server/lib/omp/config/definitions.test.ts +9 -105
  155. package/src/server/lib/omp/config/extensions.ts +16 -7
  156. package/src/server/lib/omp/config/omp-config-files.test.ts +27 -0
  157. package/src/server/lib/omp/rpc/constants.test.ts +11 -0
  158. package/src/server/lib/omp/rpc/constants.ts +15 -0
  159. package/src/server/lib/omp/rpc/process.ts +11 -14
  160. package/src/server/lib/omp/rpc/session-commands.ts +6 -3
  161. package/src/server/lib/omp/rpc/utility-agent-dir.test.ts +134 -0
  162. package/src/server/lib/omp/rpc/utility-agent-dir.ts +138 -0
  163. package/src/server/lib/omp/rpc/utility.ts +12 -0
  164. package/src/server/lib/review/schema.server.ts +45 -0
  165. package/src/server/lib/review/store.server.ts +138 -0
  166. package/src/server/lib/terminal/attach-replay.test.ts +132 -0
  167. package/src/server/lib/terminal/output.test.ts +166 -0
  168. package/src/server/lib/terminal/output.ts +104 -0
  169. package/src/server/lib/terminal/runtime.server.ts +5 -0
  170. package/src/server/lib/terminal/send-result.test.ts +33 -0
  171. package/src/server/lib/terminal/send-result.ts +32 -0
  172. package/src/server/lib/terminal/session.server.ts +45 -11
  173. package/src/server/lib/terminal/store-liveness.test.ts +4 -0
  174. package/src/server/lib/updates/active-notes.test.ts +149 -0
  175. package/src/server/lib/updates/active-notes.ts +75 -0
  176. package/src/server/lib/updates/changelog-file.ts +42 -11
  177. package/src/server/lib/updates/changelog.test.ts +15 -1
  178. package/src/server/lib/updates/omp.ts +42 -15
  179. package/src/server/lib/updates/release-url.ts +27 -1
  180. package/src/server/lib/usage/index-parse.test.ts +200 -0
  181. package/src/server/lib/usage/index-parse.ts +178 -0
  182. package/src/server/lib/usage/index-query.server.ts +248 -0
  183. package/src/server/lib/usage/index-scan.server.ts +343 -0
  184. package/src/server/lib/usage/index-schema.server.ts +82 -0
  185. package/src/server/lib/usage/index.test.ts +234 -0
  186. package/src/server/lib/usage/providers.server.ts +4 -53
  187. package/src/server/routes/browser/index.ts +3 -0
  188. package/src/server/routes/browser/stream.ts +31 -2
  189. package/src/server/routes/browser/tabs.test.ts +94 -0
  190. package/src/server/routes/browser/tabs.ts +85 -0
  191. package/src/server/routes/index.ts +2 -0
  192. package/src/server/routes/review/bindings.ts +11 -0
  193. package/src/server/routes/review/index.ts +127 -0
  194. package/src/server/routes/review/routes.test.ts +191 -0
  195. package/src/server/routes/settings/agents.test.ts +180 -0
  196. package/src/server/routes/settings/agents.ts +95 -102
  197. package/src/server/routes/settings/mcp.test.ts +135 -0
  198. package/src/server/routes/settings/mcp.ts +14 -6
  199. package/src/server/routes/settings/settings-store-routes.test.ts +6 -113
  200. package/src/server/routes/telemetry/tokens.test.ts +145 -0
  201. package/src/server/routes/telemetry/tokens.ts +70 -149
  202. package/src/server/routes/terminal/ws.ts +6 -5
  203. package/src/server/routes/updates/index.ts +2 -0
  204. package/src/server/routes/updates/notes.ts +34 -0
  205. package/src/server/routes/updates/routes.test.ts +49 -0
  206. package/src/shared/lib/browser/annotate.test.ts +283 -0
  207. package/src/shared/lib/browser/annotate.ts +231 -0
  208. package/src/shared/lib/browser/browser-viewer.test.ts +26 -4
  209. package/src/shared/lib/browser/frame-gate.test.ts +91 -0
  210. package/src/shared/lib/browser/frame-gate.ts +69 -0
  211. package/src/shared/lib/browser/frame-params.test.ts +43 -0
  212. package/src/shared/lib/browser/frame-params.ts +60 -0
  213. package/src/shared/lib/browser/frame-pipeline.test.ts +132 -0
  214. package/src/shared/lib/browser/frame-pipeline.ts +80 -0
  215. package/src/shared/lib/browser/page-context.ts +60 -4
  216. package/src/shared/lib/browser/snapshot.test.ts +115 -0
  217. package/src/shared/lib/browser/snapshot.ts +112 -0
  218. package/src/shared/lib/browser/tab-close.test.ts +74 -0
  219. package/src/shared/lib/browser/tab-close.ts +77 -0
  220. package/src/shared/lib/browser/viewer.ts +45 -26
  221. package/src/shared/lib/chat/timeline/block-chrome.ts +19 -0
  222. package/src/shared/lib/chat/timeline/tool-render-mode.ts +17 -4
  223. package/src/shared/lib/chat/tool/artifact.ts +55 -20
  224. package/src/shared/lib/chat/tool/bash-facts.ts +96 -0
  225. package/src/shared/lib/chat/tool/minimized.test.ts +98 -0
  226. package/src/shared/lib/chat/tool/minimized.ts +64 -0
  227. package/src/shared/lib/chat/tool/summary.test.ts +28 -8
  228. package/src/shared/lib/chat/tool/summary.ts +3 -32
  229. package/src/shared/lib/markdown/blocks/anchor.ts +63 -0
  230. package/src/shared/lib/markdown/blocks/blocks.test.ts +141 -0
  231. package/src/shared/lib/markdown/blocks/renderer.ts +120 -0
  232. package/src/shared/lib/markdown/blocks/scan.ts +100 -0
  233. package/src/shared/lib/markdown/blocks/types.ts +62 -0
  234. package/src/shared/lib/markdown/marked.ts +58 -147
  235. package/src/shared/lib/markdown/math-extensions.ts +168 -0
  236. package/src/shared/lib/markdown/review/prompt.ts +77 -0
  237. package/src/shared/lib/markdown/review/reconcile.ts +55 -0
  238. package/src/shared/lib/markdown/review/review.test.ts +96 -0
  239. package/src/shared/lib/markdown/xml-sections.test.ts +140 -0
  240. package/src/shared/lib/markdown/xml-sections.ts +139 -0
  241. package/src/shared/lib/models/provider/label.ts +57 -0
  242. package/src/shared/lib/omp/config/agent-file.test.ts +54 -0
  243. package/src/shared/lib/omp/config/agent-file.ts +43 -0
  244. package/src/shared/lib/omp/config/row-value.test.ts +95 -0
  245. package/src/shared/lib/omp/config/row-value.ts +97 -0
  246. package/src/shared/lib/omp/config/schema.test.ts +31 -0
  247. package/src/shared/lib/omp/config/schema.ts +6 -0
  248. package/src/shared/lib/omp/rpc/frame.test.ts +48 -47
  249. package/src/shared/lib/omp/rpc/frame.ts +49 -40
  250. package/src/shared/lib/ui/menu-anchor.test.ts +69 -0
  251. package/src/shared/lib/ui/menu-anchor.ts +89 -0
  252. package/src/shared/lib/usage/breakdown.test.ts +197 -0
  253. package/src/shared/lib/usage/breakdown.ts +241 -0
  254. package/src/shared/lib/usage/range.test.ts +204 -0
  255. package/src/shared/lib/usage/range.ts +240 -0
  256. package/src/shared/lib/usage/view.test.ts +85 -0
  257. package/src/shared/lib/usage/view.ts +74 -0
  258. package/src/shared/types/browser.ts +78 -0
  259. package/src/shared/types/index.ts +1 -0
  260. package/src/shared/types/settings/agent.ts +28 -6
  261. package/src/shared/types/settings/state.ts +4 -3
  262. package/src/shared/types/settings/write.ts +6 -0
  263. package/src/shared/types/tokenUsage.ts +128 -21
  264. package/src/shared/types/updates.ts +20 -0
  265. package/dist/client/static/js/index-3ve31rzx.css +0 -1
  266. package/src/server/lib/omp/session/usage/aggregate-shaping.test.ts +0 -149
  267. package/src/server/lib/omp/session/usage/aggregate.test.ts +0 -243
  268. package/src/server/lib/omp/session/usage/aggregate.ts +0 -330
  269. package/src/server/lib/omp/session/usage/shaping.ts +0 -130
@@ -0,0 +1,191 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The `tui` style — omp's terminal transcript, drawn as TEXT in the browser.
8
+ *
9
+ * omp's terminal writes a call as a status line, not as a box: the glyph in the
10
+ * state's tone, the tool name in the title colour, `: subject` in the muted
11
+ * colour, the outcome in brackets, then the quiet facts joined by ` · `
12
+ * (`renderStatusLine` in `@oh-my-pi/pi-tui`). Framed boxes are reserved for
13
+ * tools whose OUTPUT is a bordered pane (bash, eval); the tool line itself is
14
+ * prose. This style follows that split — no border, no fill, no card — and the
15
+ * colour carries the structure instead:
16
+ *
17
+ * - the outcome glyph and its `[word]` take the call's state colour;
18
+ * - the tool name is the accent (`--theme-info`), the subject is the meta hue
19
+ * (`--theme-meta`), so the two halves of the head are never confused;
20
+ * - facts keep their own tones (`+4` green, `−1` red, a warning amber) and a
21
+ * neutral fact stays dim.
22
+ *
23
+ * The expand contract is the shared one — `toolToggleLabel`'s wording, the same
24
+ * `.code-surface` body, `▸` / `▾` as the affordance — so expand/collapse, the
25
+ * intent heading above the row and every e2e selector (`[aria-label^="Expand "]`,
26
+ * `/^Expand Bash/`) behave exactly as they do for the card.
27
+ *
28
+ * Nothing here derives text: `useToolView` owns what a call SAYS
29
+ * (`shared/tool-view.ts`), `ToolBody` owns what it SHOWS when opened, so this
30
+ * file is colour and line shape only.
31
+ */
32
+
33
+ import { useCallback, useState } from 'preact/hooks';
34
+ import { memo } from 'preact/compat';
35
+ import type { ToolCallData } from '@/shared/types';
36
+ import { ToolBody } from '@/client/components/workspace/chat-timeline/tool-renderers/shared/ToolBody';
37
+ import {
38
+ toolStatusGlyph,
39
+ type ToolStatusTone,
40
+ } from '@/client/components/workspace/chat-timeline/tool-renderers/shared/status-glyph';
41
+ import { useToolView } from '@/client/components/workspace/chat-timeline/tool-renderers/shared/tool-view';
42
+ import { toolToggleLabel } from '@/client/components/workspace/chat-timeline/tool-renderers/shared/toggle-label';
43
+ import type { ToolRowProps } from '@/client/components/workspace/chat-timeline/tool-renderers/styles/props';
44
+ import type { ToolFact } from '@/shared/lib/chat/tool/summary';
45
+
46
+ /**
47
+ * A run state, which is NOT the same axis as `ToolStatusTone`: omp paints a
48
+ * running call with its pending accent, where a one-line style just spins the
49
+ * glyph. `run` exists only here.
50
+ */
51
+ type TuiRunState = 'run' | 'ok' | 'error' | 'warn' | 'muted';
52
+
53
+ /**
54
+ * The colour of the outcome — the glyph, the bracketed word — per state. Only
55
+ * the outcome is allowed to be loud: a success stays green because that is what
56
+ * a terminal prints, and a run is the accent.
57
+ */
58
+ const STATE_COLOR: Record<TuiRunState, string> = {
59
+ run: 'text-info',
60
+ ok: 'text-success',
61
+ error: 'text-error',
62
+ warn: 'text-warning',
63
+ muted: 'text-ink/35',
64
+ };
65
+
66
+ function runState(tool: ToolCallData, status: ToolStatusTone): TuiRunState {
67
+ if (tool.status === 'running') return 'run';
68
+ if (status === 'error') return 'error';
69
+ if (status === 'warn') return 'warn';
70
+ if (status === 'muted') return 'muted';
71
+ return 'ok';
72
+ }
73
+
74
+ /** One fact as terminal text: `+4` green and `−1` red inside one statement. */
75
+ function FactText({ fact }: { fact: ToolFact }) {
76
+ if (fact.parts && fact.parts.length > 0) {
77
+ return (
78
+ <>
79
+ {fact.parts.map((part, index) => (
80
+ <span key={`${part.label}-${index}`} className={part.tone === 'ok' ? 'text-success' : 'text-error'}>
81
+ {part.label}
82
+ </span>
83
+ ))}
84
+ </>
85
+ );
86
+ }
87
+ const toneClass =
88
+ fact.tone === 'ok'
89
+ ? 'text-success'
90
+ : fact.tone === 'error'
91
+ ? 'text-error'
92
+ : fact.tone === 'warn'
93
+ ? 'text-warning'
94
+ : 'text-ink/45';
95
+ return <span className={toneClass}>{fact.label}</span>;
96
+ }
97
+
98
+ /** How many facts the one-line head states before the rest are dropped. */
99
+ const HEAD_FACT_LIMIT = 2;
100
+
101
+ /** The facts of one call, ` · `-joined in `toolSummary`'s order. */
102
+ function Facts({ facts, max = 4 }: { facts: ToolFact[]; max?: number }) {
103
+ return (
104
+ <>
105
+ {facts.slice(0, max).map((fact, index) => (
106
+ <span key={`${fact.kind}-${index}`}>
107
+ {index > 0 && <span className="text-ink/25"> · </span>}
108
+ <span title={fact.title ?? fact.label}>
109
+ <FactText fact={fact} />
110
+ </span>
111
+ </span>
112
+ ))}
113
+ </>
114
+ );
115
+ }
116
+
117
+ export const TuiRow = memo(function TuiRow({ tool, isOpen, onToggle, defaultExpanded = false }: ToolRowProps) {
118
+ const view = useToolView(tool);
119
+ const [internalOpen, setInternalOpen] = useState(defaultExpanded);
120
+ const isExpanded = view.alwaysExpanded || (isOpen ?? internalOpen);
121
+ const status = toolStatusGlyph(tool);
122
+ const tone = STATE_COLOR[runState(tool, status.tone)];
123
+ const facts = view.summary?.facts ?? [];
124
+ const canToggle = view.hasBody && !view.alwaysExpanded;
125
+
126
+ const handleToggle = useCallback(() => {
127
+ if (onToggle) onToggle(tool.id);
128
+ else setInternalOpen((prev) => !prev);
129
+ }, [onToggle, tool.id]);
130
+
131
+ return (
132
+ <div data-tool-row="tui" className="font-mono">
133
+ {/* The status line itself: glyph, name, subject, outcome, facts. Text
134
+ only — the colours separate the three claims (what ran, on what, how
135
+ it ended), which is what the terminal does with SGR and what a box
136
+ would otherwise have to do with borders. */}
137
+ <button
138
+ type="button"
139
+ onClick={handleToggle}
140
+ disabled={!canToggle}
141
+ aria-expanded={isExpanded}
142
+ aria-label={
143
+ canToggle ? toolToggleLabel(view.header.title, view.subtitle, isExpanded) : undefined
144
+ }
145
+ className={`flex w-full flex-wrap items-baseline gap-x-1 gap-y-0 rounded px-1 py-0.5 text-left text-[11.5px] leading-[1.55] transition-colors ${
146
+ canToggle ? 'cursor-pointer hover:bg-ink/[0.03]' : 'cursor-default'
147
+ } focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ink/20`}
148
+ >
149
+ <span className={`shrink-0 self-center ${tone}`} aria-hidden="true">
150
+ {status.glyph}
151
+ </span>
152
+ <span className="sr-only">{status.word}</span>
153
+ <span className="shrink-0 font-semibold text-info">{view.header.title}</span>
154
+ {view.subtitle && (
155
+ <>
156
+ <span className="shrink-0 text-ink/25">:</span>
157
+ <span className="min-w-0 flex-1 truncate text-meta">{view.subtitle}</span>
158
+ </>
159
+ )}
160
+ <span className={`shrink-0 font-semibold ${tone}`}>{`[${status.word.toLowerCase()}]`}</span>
161
+ {facts.length > 0 && (
162
+ // Facts are the LAST thing on the line and they clip as a unit, so a
163
+ // long `exit 1 · 412 B` can never widen the row past the panel —
164
+ // measured at 390 the unbounded group ran the section to 459/362.
165
+ // The whole group carries the tooltip with every fact, so a clipped
166
+ // tail is still recoverable.
167
+ <span
168
+ className="min-w-0 shrink truncate text-[10.5px]"
169
+ title={facts.map((fact) => fact.label).join(' · ')}
170
+ >
171
+ <span className="text-ink/25">· </span>
172
+ <Facts facts={facts} max={HEAD_FACT_LIMIT} />
173
+ </span>
174
+ )}
175
+ {canToggle && (
176
+ <span className="ml-auto shrink-0 pl-1 text-ink/40" aria-hidden="true">
177
+ {isExpanded ? '▾' : '▸'}
178
+ </span>
179
+ )}
180
+ </button>
181
+
182
+ {isExpanded && view.hasBody && (
183
+ // Indentation, not a frame: the body hangs off the line the way a
184
+ // terminal prints a command's output under it.
185
+ <div className="mb-1.5 ml-2 space-y-3 border-l border-ink/10 py-1.5 pl-3 code-surface">
186
+ <ToolBody tool={tool} view={view} />
187
+ </div>
188
+ )}
189
+ </div>
190
+ );
191
+ });
@@ -96,7 +96,7 @@ function toggle(el: HTMLElement): HTMLElement {
96
96
  return el.querySelector('[aria-label^="Expand "], [aria-label^="Collapse "]') as HTMLElement;
97
97
  }
98
98
 
99
- describe.each(['card', 'compact', 'trace', 'minimal'])('tool render style: %s', (style) => {
99
+ describe.each(['card', 'compact', 'trace', 'minimal', 'tui'])('tool render style: %s', (style) => {
100
100
  test('draws one row per call and names it', async () => {
101
101
  const el = await mount([OK_TOOL], style);
102
102
  expect(el.querySelector('[data-tool-section]')?.getAttribute('data-tool-style')).toBe(style);
@@ -16,14 +16,11 @@
16
16
  * existed only because the old table renderer could not collapse anything.
17
17
  */
18
18
 
19
- import { useEffect, useRef, useState } from 'preact/hooks';
19
+ import { useEffect, useMemo, useRef, useState } from 'preact/hooks';
20
20
 
21
21
  import { useScrollRestore } from '@/client/hooks/editor/use-scroll-restore';
22
22
  import { EDITOR_LINE_HEIGHT } from '@/shared/lib/code/editor/typography';
23
- import {
24
- countChanges,
25
- foldWhitespaceOnly,
26
- } from '@/client/components/workspace/diff-panel/changes';
23
+ import { foldWhitespaceOnly } from '@/client/components/workspace/diff-panel/changes';
27
24
  import {
28
25
  mountSplitDiff,
29
26
  mountUnifiedDiff,
@@ -98,7 +95,16 @@ export function MergeDiffView({
98
95
  /** The pair the live view holds, so a change is a re-state rather than a re-mount. */
99
96
  const pairRef = useRef<{ original: string; next: string }>({ original, next });
100
97
 
101
- const left = ignoreWhitespace ? foldWhitespaceOnly(original, next) : original;
98
+ // MEMOIZED, not computed in the render body: the fold is a character-level
99
+ // diff of both documents, and this component re-renders whenever the panel
100
+ // around it does — the count report, the hunk label, a busy flag. Measured on
101
+ // a 30 000-line pair, one fold of an untouched file cost 324 ms of main-thread
102
+ // work, and a 5 000-line pair that was wholly rewritten cost 12.7 s; paid per
103
+ // render it made the whitespace toggle the slowest thing in the panel.
104
+ const left = useMemo(
105
+ () => (ignoreWhitespace ? foldWhitespaceOnly(original, next) : original),
106
+ [ignoreWhitespace, original, next],
107
+ );
102
108
 
103
109
  // The scroll offset is per SHAPE: unified and split rows are different
104
110
  // heights, so one view's position says nothing about the other's. The hook
@@ -171,9 +177,17 @@ export function MergeDiffView({
171
177
 
172
178
  // Counts describe the pair ON SCREEN, so the badge cannot disagree with the
173
179
  // rows under it (git's own `+n/-n` still counts a hidden whitespace change).
180
+ // They are the view's own chunks: re-diffing the pair here cost a second full
181
+ // line diff per load (see `countChunks`).
174
182
  useEffect(() => {
175
183
  if (!onCounts) return;
176
- onCounts(empty ? { additions: 0, deletions: 0 } : countChanges(left, next));
184
+ if (empty) {
185
+ onCounts({ additions: 0, deletions: 0 });
186
+ return;
187
+ }
188
+ const handle = handleRef.current;
189
+ if (!handle) return;
190
+ onCounts(handle.counts());
177
191
  }, [left, next, empty, onCounts]);
178
192
 
179
193
  if (empty) {
@@ -0,0 +1,51 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The badge's arithmetic, on the chunks the merge view already built.
8
+ *
9
+ * `countChunks` replaced a `Chunk.build` of the same pair inside the panel, so
10
+ * the thing worth pinning is that it answers the same numbers from a chunk list
11
+ * the caller hands it — an edit counts on BOTH sides, an insertion only on the
12
+ * new one, and the hunks' line spans are read from their own documents rather
13
+ * than assumed to be one line each.
14
+ */
15
+
16
+ import { describe, expect, test } from 'bun:test';
17
+ import { Chunk } from '@codemirror/merge';
18
+ import { Text } from '@codemirror/state';
19
+
20
+ import { countChunks } from '@/client/components/workspace/diff-panel/changes';
21
+
22
+ function count(original: string[], next: string[]) {
23
+ const a = Text.of(original);
24
+ const b = Text.of(next);
25
+ return countChunks(a, b, Chunk.build(a, b));
26
+ }
27
+
28
+ describe('countChunks', () => {
29
+ test('an edited line is one deletion and one addition', () => {
30
+ expect(count(['one', 'two', 'three'], ['one', 'TWO', 'three'])).toEqual({
31
+ additions: 1,
32
+ deletions: 1,
33
+ });
34
+ });
35
+
36
+ test('a pure insertion counts additions only, and a pure deletion the opposite', () => {
37
+ expect(count(['one', 'three'], ['one', 'two', 'three'])).toEqual({ additions: 1, deletions: 0 });
38
+ expect(count(['one', 'two', 'three'], ['one', 'three'])).toEqual({ additions: 0, deletions: 1 });
39
+ });
40
+
41
+ test('a multi-line hunk counts every line it covers, not one per chunk', () => {
42
+ expect(count(['a', 'b', 'c', 'd', 'e'], ['a', 'B', 'C', 'D', 'e'])).toEqual({
43
+ additions: 3,
44
+ deletions: 3,
45
+ });
46
+ });
47
+
48
+ test('identical documents have no chunks and count zero', () => {
49
+ expect(count(['same', 'lines'], ['same', 'lines'])).toEqual({ additions: 0, deletions: 0 });
50
+ });
51
+ });
@@ -12,24 +12,40 @@
12
12
  * number describing rows that are not on screen.
13
13
  */
14
14
 
15
- import { Chunk, diff } from '@codemirror/merge';
16
- import { Text } from '@codemirror/state';
15
+ import { diff, type Chunk } from '@codemirror/merge';
16
+ import type { Text } from '@codemirror/state';
17
17
 
18
18
  /**
19
- * Additions and deletions, counted from the SAME line-level diff the view draws.
19
+ * Additions and deletions of a chunk list, against the two documents it
20
+ * describes.
20
21
  *
21
- * `Chunk.build` is the merge view's own chunking — a line-level diff, which is
22
- * what its rows are. `diff()` would be the wrong source here: it is a
23
- * CHARACTER diff, so changing `line 5` into `line 5 changed` reports one
24
- * insertion of `" changed"` and no deletion at all, and the badge would claim
25
- * two additions for two edited lines.
22
+ * The chunks come from the MERGE VIEW, never from a second `Chunk.build` of the
23
+ * same pair. That second build was the panel's slowest step and its only
24
+ * disagreement with itself, because it ran with NO diff config: the view builds
25
+ * its chunks with `defaultDiffConfig` (`scanLimit: 500`, so a large file falls
26
+ * back to a coarse match) while a bare `Chunk.build` scans without a limit.
27
+ * Measured on a 27 000-line pair of which 540 lines changed:
28
+ *
29
+ * - the badge's own diff took **4.0 s** of main thread and reported **540**
30
+ * additions/deletions;
31
+ * - the rows on screen reported **26 951** — the view's coarse fallback — so the
32
+ * badge described a diff the reader was not looking at, which is the one thing
33
+ * this module must never do.
34
+ *
35
+ * On a fully rewritten file the unconfigured scan is far worse: 3.4 s at 500
36
+ * lines, 14.5 s at 1 000, 55 s at 2 000, all still one chunk. `diff()` would be
37
+ * the wrong source even as a shortcut: it is a CHARACTER diff, so changing
38
+ * `line 5` into `line 5 changed` reports one insertion of `" changed"` and no
39
+ * deletion at all.
26
40
  */
27
- export function countChanges(original: string, next: string): { additions: number; deletions: number } {
28
- const a = Text.of(original.split('\n'));
29
- const b = Text.of(next.split('\n'));
41
+ export function countChunks(
42
+ a: Text,
43
+ b: Text,
44
+ chunks: readonly Chunk[],
45
+ ): { additions: number; deletions: number } {
30
46
  let additions = 0;
31
47
  let deletions = 0;
32
- for (const chunk of Chunk.build(a, b)) {
48
+ for (const chunk of chunks) {
33
49
  // `endA`/`endB` are the end of the chunk's last line, and equal the start
34
50
  // when the chunk covers no lines on that side (a pure insertion/deletion).
35
51
  if (chunk.endA > chunk.fromA) deletions += a.lineAt(chunk.endA).number - a.lineAt(chunk.fromA).number + 1;
@@ -99,6 +99,34 @@ describe('chunk position', () => {
99
99
  });
100
100
  });
101
101
 
102
+ describe('counts', () => {
103
+ test('both shapes report the pair on screen', () => {
104
+ for (const kind of ['unified', 'split'] as const) {
105
+ const { handle } = mount(kind);
106
+ // Two edited lines: one deletion and one addition each.
107
+ expect(handle.counts()).toEqual({ additions: 2, deletions: 2 });
108
+ handle.destroy();
109
+ }
110
+ });
111
+
112
+ test('a re-stated pair counts the NEW documents, not the ones it mounted with', () => {
113
+ for (const kind of ['unified', 'split'] as const) {
114
+ const { handle } = mount(kind);
115
+ handle.setDocuments('a\nb\nc', 'a\nc');
116
+ expect(handle.counts()).toEqual({ additions: 0, deletions: 1 });
117
+ handle.destroy();
118
+ }
119
+ });
120
+
121
+ test('an identical pair counts zero on both shapes', () => {
122
+ for (const kind of ['unified', 'split'] as const) {
123
+ const { handle } = mount(kind, ORIGINAL, ORIGINAL);
124
+ expect(handle.counts()).toEqual({ additions: 0, deletions: 0 });
125
+ handle.destroy();
126
+ }
127
+ });
128
+ });
129
+
102
130
  describe('stepChunk', () => {
103
131
  test('steps forward through every chunk and wraps', () => {
104
132
  const { handle } = mount('unified');
@@ -29,11 +29,12 @@
29
29
 
30
30
  import { Compartment, EditorState, type Extension } from '@codemirror/state';
31
31
  import { EditorView, lineNumbers } from '@codemirror/view';
32
- import { MergeView, unifiedMergeView } from '@codemirror/merge';
32
+ import { MergeView, getChunks, getOriginalDoc, unifiedMergeView } from '@codemirror/merge';
33
33
 
34
34
  import { shikiHighlight, type ShikiThemeNames } from '@/client/components/common/code-surface/shiki';
35
35
  import { surfaceTheme } from '@/client/components/common/code-surface/theme';
36
36
  import { diffFoldingExtensions } from '@/client/components/workspace/diff-panel/folding';
37
+ import { countChunks } from '@/client/components/workspace/diff-panel/changes';
37
38
  import {
38
39
  chunkPositionOf,
39
40
  chunkReporter,
@@ -156,6 +157,15 @@ export interface DiffViewHandle {
156
157
  * buttons inert rather than silently doing nothing.
157
158
  */
158
159
  stepChunk(direction: 1 | -1): boolean;
160
+ /**
161
+ * Additions and deletions of the pair ON SCREEN.
162
+ *
163
+ * Read from the view's own chunks rather than re-diffed: the merge package
164
+ * builds them when it is constructed and whenever the documents are
165
+ * re-stated, so this is the same arithmetic on work already done — and the
166
+ * badge cannot describe a different diff than the rows under it.
167
+ */
168
+ counts(): { additions: number; deletions: number };
159
169
  /** The element that actually scrolls, for scroll restore. */
160
170
  scroller(): HTMLElement | null;
161
171
  destroy(): void;
@@ -249,6 +259,15 @@ export function mountUnifiedDiff(parent: HTMLElement, options: DiffViewOptions):
249
259
  },
250
260
  chunkPosition: () => chunkPositionOf(view),
251
261
  stepChunk: (direction) => stepChunkIn(view, direction),
262
+ counts: () => {
263
+ // The unified field is keyed to the ORIGINAL document it was configured
264
+ // with, so both sides come from this state: re-reading `options` would
265
+ // describe the pair before the last `setDocuments`.
266
+ const chunks = getChunks(view.state);
267
+ return chunks
268
+ ? countChunks(getOriginalDoc(view.state), view.state.doc, chunks.chunks)
269
+ : { additions: 0, deletions: 0 };
270
+ },
252
271
  scroller: () => view.scrollDOM,
253
272
  destroy: () => {
254
273
  options.onScroller(null);
@@ -306,6 +325,7 @@ export function mountSplitDiff(parent: HTMLElement, options: DiffViewOptions): D
306
325
  // same either way.
307
326
  chunkPosition: () => chunkPositionOf(merge.b),
308
327
  stepChunk: (direction) => stepChunkIn(merge.b, direction),
328
+ counts: () => countChunks(merge.a.state.doc, merge.b.state.doc, merge.chunks),
309
329
  scroller: () => scroller,
310
330
  destroy: () => {
311
331
  options.onScroller(null);
@@ -21,6 +21,9 @@ interface EditorBodyProps {
21
21
  /** The surface this file's kind is drawn by (see `document-kind`). */
22
22
  viewerKind: ViewerKind;
23
23
  isPreview: boolean;
24
+ /** Review mode is on for this tab (and only ever for a rendered document). */
25
+ isReviewing: boolean;
26
+ onToggleReview: () => void;
24
27
  isMaximized: boolean;
25
28
  setIsMaximized: (next: boolean) => void;
26
29
  zoomLevel: number;
@@ -65,6 +68,8 @@ export function EditorBody({
65
68
  setWordWrap,
66
69
  viewerKind,
67
70
  isPreview,
71
+ isReviewing,
72
+ onToggleReview,
68
73
  isMaximized,
69
74
  setIsMaximized,
70
75
  zoomLevel,
@@ -124,6 +129,8 @@ export function EditorBody({
124
129
  setWordWrap={setWordWrap}
125
130
  viewerKind={viewerKind}
126
131
  isPreview={isPreview}
132
+ isReviewing={isReviewing}
133
+ onToggleReview={onToggleReview}
127
134
  isMaximized={isMaximized}
128
135
  setIsMaximized={setIsMaximized}
129
136
  zoomLevel={zoomLevel}
@@ -1,6 +1,6 @@
1
1
  import { useCallback, useEffect, useMemo, useState } from 'preact/hooks';
2
2
  import type { RefObject } from 'preact';
3
- import { MarkdownRenderer } from '@/client/components/common/MarkdownRenderer';
3
+ import { PreviewPane } from '@/client/components/workspace/editor/PreviewPane';
4
4
  import { CodeSurface, type CodeSurfaceHandle } from '@/client/components/common/code-surface';
5
5
  import { FindWidget } from '@/client/components/workspace/editor/FindWidget';
6
6
  import { CommandPalette } from '@/client/components/workspace/editor/CommandPalette';
@@ -51,6 +51,10 @@ interface FileDocumentProps {
51
51
  viewerKind: ViewerKind;
52
52
  /** The rendered view is on for the active file — render it, not the source. */
53
53
  isPreview: boolean;
54
+ /** Review mode is on for this file: blocks become clickable judgements. */
55
+ reviewActive: boolean;
56
+ /** Turns review mode on or off (the toolbar's own toggle). */
57
+ onToggleReview: () => void;
54
58
  /**
55
59
  * A search hit was jumped to in this file. The find bar is closed (a search
56
60
  * jump must not cover the lines it is showing), but its matches still have to
@@ -90,6 +94,8 @@ export function FileDocument({
90
94
  editorTheme,
91
95
  viewerKind,
92
96
  isPreview,
97
+ reviewActive,
98
+ onToggleReview,
93
99
  revealActive,
94
100
  }: FileDocumentProps) {
95
101
  // Only markdown reaches this component in preview mode; the CSV grid and the
@@ -223,27 +229,15 @@ export function FileDocument({
223
229
  />
224
230
  ) : null}
225
231
  {isMd && isPreview ? (
226
- <div
227
- ref={previewRef}
232
+ <PreviewPane
233
+ content={editor.content}
234
+ file={{ name: activeFile.name, path: activeFile.path, root: activeFile.root, repo: activeFile.repo }}
235
+ zoomLevel={zoomLevel}
236
+ reviewActive={reviewActive}
237
+ onExitReview={onToggleReview}
238
+ scrollRef={previewRef}
228
239
  onScroll={scroll.onScroll}
229
- // No accessible name exists for a scroll container, so the E2E layer
230
- // addresses it by testid (see `tests/e2e/fixtures/selectors.ts`).
231
- data-testid="editor-scroller"
232
- className="flex-1 overflow-auto bg-paper flex"
233
- >
234
- {/* No `prose` wrapper: markdown is styled by `.prose-content` alone
235
- (the same system the chat timeline uses). The typography plugin
236
- fought it — `.prose img` added 2em vertical margins that ballooned
237
- a badge row into its own line box, and `--tw-prose-*` colors
238
- ignored the theme. */}
239
- <div className="p-6 max-w-4xl mx-auto font-sans flex-1" style={{ fontSize: `${zoomLevel}px` }}>
240
- <MarkdownRenderer
241
- content={editor.content}
242
- document
243
- scope={{ path: activeFile.path, root: activeFile.root, repo: activeFile.repo }}
244
- />
245
- </div>
246
- </div>
240
+ />
247
241
  ) : (
248
242
  // The code surface owns its own scroller (CodeMirror's), so it is NOT
249
243
  // wrapped in one: an outer `overflow-auto` would take the document's
@@ -27,6 +27,9 @@ interface FilePaneProps {
27
27
  /** The surface this file's kind is drawn by (see `document-kind`). */
28
28
  viewerKind: ViewerKind;
29
29
  isPreview: boolean;
30
+ /** Review mode is on for this tab, and the document can be reviewed at all. */
31
+ isReviewing: boolean;
32
+ onToggleReview: () => void;
30
33
  isMaximized: boolean;
31
34
  setIsMaximized: (next: boolean) => void;
32
35
  zoomLevel: number;
@@ -78,6 +81,8 @@ export function FilePane({
78
81
  setWordWrap,
79
82
  viewerKind,
80
83
  isPreview,
84
+ isReviewing,
85
+ onToggleReview,
81
86
  isMaximized,
82
87
  setIsMaximized,
83
88
  zoomLevel,
@@ -112,6 +117,10 @@ export function FilePane({
112
117
  wordWrap={wordWrap}
113
118
  hasPreview={hasPreview}
114
119
  isPreview={isPreview}
120
+ // The toggle exists only while the RENDERED document is what is on
121
+ // screen: a markdown tab showing its source has no blocks to judge.
122
+ hasReview={viewerKind === 'markdown' && isPreview}
123
+ isReviewing={isReviewing}
115
124
  copied={editor.copied}
116
125
  byteViewer={byteViewer}
117
126
  saveDisabled={Boolean(editor.loadError) || editor.handleMissing || editor.deviceBacked}
@@ -123,6 +132,7 @@ export function FilePane({
123
132
  onToggleFind={() => (find.open ? find.close() : find.openFind())}
124
133
  onSave={editor.saveNow}
125
134
  onTogglePreview={togglePreview}
135
+ onToggleReview={onToggleReview}
126
136
  onToggleWordWrap={() => setWordWrap(!wordWrap)}
127
137
  onZoomIn={() => setZoomLevel((z) => Math.min(EDITOR_MAX_FONT_SIZE, z + 1))}
128
138
  onZoomOut={() => setZoomLevel((z) => Math.max(EDITOR_MIN_FONT_SIZE, z - 1))}
@@ -283,6 +293,8 @@ export function FilePane({
283
293
  editorFontFamily={editorFontFamily}
284
294
  editorTheme={editorTheme}
285
295
  isPreview={isPreview}
296
+ reviewActive={isReviewing}
297
+ onToggleReview={onToggleReview}
286
298
  viewerKind={viewerKind}
287
299
  revealActive={revealActive}
288
300
  />
@@ -0,0 +1,70 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The rendered markdown document — the preview half of a markdown tab.
8
+ *
9
+ * Extracted from `FileDocument` for the per-file ceiling, and it earns the
10
+ * boundary: everything here is "a document is on screen" (its scroller, its
11
+ * scroll memory, its zoom, its table of contents target) while what surrounds it
12
+ * is the editor's chrome.
13
+ *
14
+ * ## Two review states, one surface
15
+ *
16
+ * Review mode is a MODE the toolbar turns on. Off, the document is drawn exactly
17
+ * as it always was — `MarkdownReview` passes no review bridge, so no block
18
+ * attributes are emitted and every click keeps its meaning. On, the same
19
+ * component draws the marks and the judgement editor. There is deliberately no
20
+ * second preview component: one surface cannot drift from the other.
21
+ */
22
+
23
+ import { MarkdownReview } from '@/client/components/common/markdown-review';
24
+
25
+ export interface PreviewPaneProps {
26
+ content: string;
27
+ file: { name: string; path: string; root?: string | null; repo?: string | null };
28
+ zoomLevel: number;
29
+ /** Review mode, owned by the editor's toolbar. */
30
+ reviewActive: boolean;
31
+ onExitReview: () => void;
32
+ /** The scroller, shared by scroll restore and the table of contents. */
33
+ scrollRef: (element: HTMLElement | null) => void;
34
+ onScroll: () => void;
35
+ }
36
+
37
+ export function PreviewPane({
38
+ content,
39
+ file,
40
+ zoomLevel,
41
+ reviewActive,
42
+ onExitReview,
43
+ scrollRef,
44
+ onScroll,
45
+ }: PreviewPaneProps) {
46
+ return (
47
+ <div
48
+ ref={scrollRef}
49
+ onScroll={onScroll}
50
+ // No accessible name exists for a scroll container, so the E2E layer
51
+ // addresses it by testid (see `tests/e2e/fixtures/selectors.ts`).
52
+ data-testid="editor-scroller"
53
+ className="flex-1 overflow-auto bg-paper flex"
54
+ >
55
+ {/* No `prose` wrapper: markdown is styled by `.prose-content` alone
56
+ (the same system the chat timeline uses). The typography plugin
57
+ fought it — `.prose img` added 2em vertical margins that ballooned
58
+ a badge row into its own line box, and `--tw-prose-*` colors ignored
59
+ the theme. */}
60
+ <div className="p-6 max-w-4xl mx-auto font-sans flex-1" style={{ fontSize: `${zoomLevel}px` }}>
61
+ <MarkdownReview
62
+ content={content}
63
+ file={file}
64
+ active={reviewActive}
65
+ onExit={onExitReview}
66
+ />
67
+ </div>
68
+ </div>
69
+ );
70
+ }