@cueloop/client 0.1.0-alpha.10 → 0.1.0-alpha.101

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 (356) hide show
  1. package/native/build-pty.sh +51 -0
  2. package/native/build.sh +82 -0
  3. package/native/darwin-arm64/libcuelooppty.dylib +0 -0
  4. package/native/darwin-arm64/libcueloopvt.dylib +0 -0
  5. package/native/src/pty.zig +193 -0
  6. package/native/src/shim.zig +114 -0
  7. package/package.json +42 -34
  8. package/src/annotations/annotation-palette.ts +62 -0
  9. package/src/annotations/components/AnnotationCards.stories.tsx +86 -0
  10. package/src/annotations/components/AnnotationCards.test.tsx +42 -0
  11. package/src/annotations/components/AnnotationCards.tsx +369 -0
  12. package/src/annotations/components/DiscussionMarkerRail.stories.tsx +54 -0
  13. package/src/annotations/components/DiscussionMarkerRail.tsx +186 -0
  14. package/src/annotations/discussions.ts +77 -0
  15. package/src/annotations/thread-selection.test.ts +210 -0
  16. package/src/annotations/thread-selection.ts +242 -0
  17. package/src/annotations/use-annotation-surface.tsx +1243 -0
  18. package/src/app/App.appearance.test.tsx +53 -0
  19. package/src/{App.autoclose.test.tsx → app/App.autoclose.test.tsx} +77 -51
  20. package/src/app/App.deleted-scroll.test.tsx +187 -0
  21. package/src/app/App.diff.test.tsx +313 -0
  22. package/src/app/App.export.test.tsx +105 -0
  23. package/src/app/App.focus.test.ts +89 -0
  24. package/src/app/App.identity.test.tsx +84 -0
  25. package/src/app/App.plan-render.test.tsx +209 -0
  26. package/src/app/App.plan-review.test.tsx +428 -0
  27. package/src/app/App.prototype-markdown.test.tsx +128 -0
  28. package/src/app/App.prototype.test.tsx +176 -0
  29. package/src/app/App.readonly.test.tsx +210 -0
  30. package/src/app/App.regression.test.tsx +99 -0
  31. package/src/app/App.rendering.test.tsx +134 -0
  32. package/src/app/App.share-dialog.test.tsx +177 -0
  33. package/src/app/App.submit-confirm.test.tsx +267 -0
  34. package/src/app/App.test.tsx +496 -0
  35. package/src/app/App.thread-agent.test.ts +20 -0
  36. package/src/app/App.toast.test.tsx +124 -0
  37. package/src/app/App.tsx +1667 -0
  38. package/src/app/App.visual.test.tsx +59 -0
  39. package/src/app/App.walk.test.tsx +299 -0
  40. package/src/app/App.workbench.test.tsx +1149 -0
  41. package/src/app/app-key-state.ts +61 -0
  42. package/src/app/app-screens.tsx +606 -0
  43. package/src/app/app-view-model.ts +168 -0
  44. package/src/app/components/AppHeader.stories.tsx +50 -0
  45. package/src/app/components/AppHeader.tsx +81 -0
  46. package/src/app/components/AppShell.brand.test.tsx +58 -0
  47. package/src/app/components/AppShell.extensions.test.tsx +191 -0
  48. package/src/app/components/AppShell.stories.tsx +89 -0
  49. package/src/app/components/AppShell.tsx +358 -0
  50. package/src/app/components/AppShell.zoom.test.tsx +149 -0
  51. package/src/app/components/Breadcrumb.stories.tsx +19 -0
  52. package/src/app/components/Breadcrumb.tsx +45 -0
  53. package/src/app/components/MenuBar.stories.tsx +28 -0
  54. package/src/app/components/MenuBar.tsx +44 -0
  55. package/src/app/components/PaneGrid.stories.tsx +84 -0
  56. package/src/app/components/PaneGrid.tsx +128 -0
  57. package/src/app/components/PanelColumn.stories.tsx +25 -0
  58. package/src/app/components/PanelColumn.tsx +93 -0
  59. package/src/app/components/ShellHeader.stories.tsx +50 -0
  60. package/src/app/components/ShellHeader.tsx +137 -0
  61. package/src/app/components/WorkspacePanels.stories.tsx +36 -0
  62. package/src/app/components/WorkspacePanels.tsx +120 -0
  63. package/src/app/components/pages/Workspace.stories.tsx +181 -0
  64. package/src/app/intent-dispatch.test.ts +728 -0
  65. package/src/app/intent-dispatch.ts +687 -0
  66. package/src/app/launch-layout.test.ts +78 -0
  67. package/src/app/launch-layout.ts +57 -0
  68. package/src/app/ready-signal.test.ts +85 -0
  69. package/src/app/ready-signal.ts +52 -0
  70. package/src/app/run.ts +109 -0
  71. package/src/{serve.test.ts → app/serve.test.ts} +24 -12
  72. package/src/app/serve.ts +111 -0
  73. package/src/app/version.ts +5 -0
  74. package/src/appearance/components/theme-context.stories.tsx +46 -0
  75. package/src/appearance/components/theme-context.tsx +37 -0
  76. package/src/appearance/theme-presets.test.ts +51 -0
  77. package/src/appearance/theme-presets.ts +219 -0
  78. package/src/appearance/theme.ts +112 -0
  79. package/src/appearance/visual/contrast.test.ts +35 -0
  80. package/src/appearance/visual/contrast.ts +33 -0
  81. package/src/diff/components/AnnotatableFileView.stories.tsx +42 -0
  82. package/src/diff/components/AnnotatableFileView.test.tsx +157 -0
  83. package/src/diff/components/AnnotatableFileView.tsx +141 -0
  84. package/src/diff/components/BareWorkbenchFileView.stories.tsx +27 -0
  85. package/src/diff/components/BareWorkbenchFileView.tsx +63 -0
  86. package/src/diff/components/DiffContentView.scroll.test.tsx +434 -0
  87. package/src/diff/components/DiffContentView.split.test.tsx +140 -0
  88. package/src/diff/components/DiffContentView.stories.tsx +80 -0
  89. package/src/diff/components/DiffContentView.syntax.test.tsx +82 -0
  90. package/src/diff/components/DiffContentView.tsx +1055 -0
  91. package/src/diff/components/WalkWizard.stories.tsx +100 -0
  92. package/src/diff/components/WalkWizard.tsx +146 -0
  93. package/src/diff/components/diff-content-view-layout.test.ts +198 -0
  94. package/src/diff/components/diff-content-view-layout.ts +84 -0
  95. package/src/diff/diff-fold.test.ts +78 -0
  96. package/src/diff/diff-fold.ts +126 -0
  97. package/src/diff/diff-hunk-curate.test.ts +315 -0
  98. package/src/diff/diff-hunk-curate.ts +152 -0
  99. package/src/diff/diff-intraline.test.ts +239 -0
  100. package/src/diff/diff-intraline.ts +238 -0
  101. package/src/diff/diff-syntax.test.ts +125 -0
  102. package/src/diff/diff-syntax.ts +186 -0
  103. package/src/diff/split-diff.test.ts +110 -0
  104. package/src/diff/split-diff.ts +144 -0
  105. package/src/diff/view-diff.test.ts +325 -0
  106. package/src/diff/view-diff.ts +522 -0
  107. package/src/diff/walk.test.ts +121 -0
  108. package/src/diff/walk.ts +73 -0
  109. package/src/index.ts +31 -2
  110. package/src/integrations/attribution.test.ts +31 -0
  111. package/src/integrations/attribution.ts +42 -0
  112. package/src/integrations/client-extension-registry.test.tsx +61 -0
  113. package/src/integrations/client-extension-registry.ts +159 -0
  114. package/src/integrations/clipboard.test.ts +23 -0
  115. package/src/integrations/clipboard.ts +33 -0
  116. package/src/integrations/components/ExtensionZone.stories.tsx +28 -0
  117. package/src/integrations/components/ExtensionZone.tsx +145 -0
  118. package/src/integrations/components/ShareDialog.agent.test.tsx +50 -0
  119. package/src/integrations/components/ShareDialog.stories.tsx +121 -0
  120. package/src/integrations/components/ShareDialog.tsx +574 -0
  121. package/src/integrations/components/share-dialog-store.ts +59 -0
  122. package/src/integrations/editor.test.ts +149 -0
  123. package/src/integrations/editor.ts +160 -0
  124. package/src/integrations/github-identity.test.ts +58 -0
  125. package/src/integrations/github-identity.ts +41 -0
  126. package/src/integrations/herdr.test.ts +43 -0
  127. package/src/integrations/herdr.ts +38 -0
  128. package/src/integrations/integrations.test.ts +41 -0
  129. package/src/integrations/integrations.ts +32 -0
  130. package/src/integrations/pasted-image.test.ts +67 -0
  131. package/src/integrations/pasted-image.ts +60 -0
  132. package/src/integrations/share.ts +238 -0
  133. package/src/keyboard/components/CompletionOverlay.stories.tsx +37 -0
  134. package/src/keyboard/components/CompletionOverlay.tsx +75 -0
  135. package/src/keyboard/components/HandleChipsInput.stories.tsx +24 -0
  136. package/src/keyboard/components/HandleChipsInput.test.tsx +35 -0
  137. package/src/keyboard/components/HandleChipsInput.tsx +143 -0
  138. package/src/keyboard/components/KeybindsDialog.stories.tsx +31 -0
  139. package/src/keyboard/components/KeybindsDialog.tsx +103 -0
  140. package/src/keyboard/components/NavModeHint.stories.tsx +40 -0
  141. package/src/keyboard/components/NavModeHint.tsx +31 -0
  142. package/src/keyboard/components/SlashComposer.stories.tsx +37 -0
  143. package/src/keyboard/components/SlashComposer.tsx +87 -0
  144. package/src/keyboard/key-bindings.test.ts +156 -0
  145. package/src/keyboard/key-bindings.ts +459 -0
  146. package/src/keyboard/keymap.test.ts +611 -0
  147. package/src/keyboard/keymap.ts +395 -0
  148. package/src/keyboard/skills.test.ts +74 -0
  149. package/src/keyboard/skills.ts +75 -0
  150. package/src/keyboard/slash-palette.test.ts +103 -0
  151. package/src/keyboard/slash-palette.ts +129 -0
  152. package/src/keyboard/thread-chords.test.ts +79 -0
  153. package/src/keyboard/thread-chords.ts +163 -0
  154. package/src/keyboard/use-shared-keyboard.ts +55 -0
  155. package/src/markdown/__snapshots__/view-plan.regression.test.ts.snap +100 -0
  156. package/src/markdown/components/MarkdownGridBlock.stories.tsx +33 -0
  157. package/src/markdown/components/MarkdownGridBlock.tsx +72 -0
  158. package/src/markdown/components/MarkdownThreadEditor.stories.tsx +15 -0
  159. package/src/markdown/components/MarkdownThreadEditor.test.tsx +98 -0
  160. package/src/markdown/components/MarkdownThreadEditor.tsx +160 -0
  161. package/src/markdown/components/ThreadView.selection.test.tsx +951 -0
  162. package/src/markdown/components/ThreadView.slash.test.tsx +146 -0
  163. package/src/markdown/components/ThreadView.stories.tsx +26 -0
  164. package/src/markdown/components/ThreadView.tsx +560 -0
  165. package/src/markdown/mark-runs.ts +121 -0
  166. package/src/markdown/markdown-editor-syntax-style.ts +50 -0
  167. package/src/markdown/markdown-grid.test.ts +101 -0
  168. package/src/markdown/markdown-grid.ts +203 -0
  169. package/src/markdown/markdown-highlight.test.ts +61 -0
  170. package/src/markdown/markdown-highlight.ts +124 -0
  171. package/src/markdown/thread-code-syntax.ts +45 -0
  172. package/src/markdown/use-thread-body-editing.tsx +54 -0
  173. package/src/markdown/view-plan.regression.test.ts +60 -0
  174. package/src/markdown/view-plan.test.ts +545 -0
  175. package/src/markdown/view-plan.ts +1009 -0
  176. package/src/performance/otlp-trace.test.ts +119 -0
  177. package/src/performance/otlp-trace.ts +134 -0
  178. package/src/performance/perf-report.ts +18 -0
  179. package/src/performance/perf-timings.test.ts +18 -0
  180. package/src/performance/perf-timings.ts +39 -0
  181. package/src/prototype/components/PrototypeContentView.stories.tsx +19 -0
  182. package/src/prototype/components/PrototypeContentView.tsx +442 -0
  183. package/src/prototype/prototype-browser.test.ts +81 -0
  184. package/src/prototype/prototype-browser.ts +321 -0
  185. package/src/prototype/prototype-pixels.tsx +35 -0
  186. package/src/settings/components/SettingsDialog.stories.tsx +117 -0
  187. package/src/settings/components/SettingsDialog.tsx +183 -0
  188. package/src/settings/components/SettingsRows.stories.tsx +18 -0
  189. package/src/settings/components/SettingsRows.tsx +112 -0
  190. package/src/settings/components/quick-actions-editor.stories.tsx +58 -0
  191. package/src/settings/components/quick-actions-editor.test.tsx +120 -0
  192. package/src/settings/components/quick-actions-editor.tsx +222 -0
  193. package/src/settings/config-identity.test.ts +78 -0
  194. package/src/settings/config.test.ts +676 -0
  195. package/src/settings/config.ts +628 -0
  196. package/src/settings/use-settings-dialog.tsx +351 -0
  197. package/src/stories/__snapshots__/stories.test.tsx.snap +2358 -0
  198. package/src/stories/stories-app.tsx +196 -0
  199. package/src/stories/stories.test.tsx +74 -0
  200. package/src/stories/story-fixtures.ts +102 -0
  201. package/src/stories/story-tree.test.ts +108 -0
  202. package/src/stories/story.ts +154 -0
  203. package/src/terminal/ansi-screen.test.ts +28 -0
  204. package/src/terminal/ansi-screen.ts +72 -0
  205. package/src/terminal/components/AnsiScreen.stories.tsx +12 -0
  206. package/src/terminal/components/AnsiScreen.tsx +28 -0
  207. package/src/terminal/components/terminal-pane.test.tsx +40 -0
  208. package/src/terminal/components/terminal-pane.ts +196 -0
  209. package/src/terminal/ghostty-terminal.test.ts +85 -0
  210. package/src/terminal/ghostty-terminal.ts +197 -0
  211. package/src/terminal/kitty-image.test.ts +66 -0
  212. package/src/terminal/kitty-image.ts +137 -0
  213. package/src/terminal/pty.test.ts +81 -0
  214. package/src/terminal/pty.ts +246 -0
  215. package/src/testing/test-support.test.ts +264 -0
  216. package/src/testing/test-support.ts +367 -0
  217. package/src/thread/agent-continuation.test.ts +32 -0
  218. package/src/thread/agent-continuation.ts +13 -0
  219. package/src/thread/agent-transcript.test.ts +161 -0
  220. package/src/thread/agent-transcript.ts +336 -0
  221. package/src/thread/components/AgentConfigControls.stories.tsx +39 -0
  222. package/src/thread/components/AgentConfigControls.test.tsx +112 -0
  223. package/src/thread/components/AgentConfigControls.tsx +114 -0
  224. package/src/thread/components/AgentThreadPane.stories.tsx +105 -0
  225. package/src/thread/components/AgentThreadPane.test.tsx +935 -0
  226. package/src/thread/components/AgentThreadPane.tsx +377 -0
  227. package/src/thread/components/ThreadFooter.stories.tsx +30 -0
  228. package/src/thread/components/ThreadFooter.test.tsx +49 -0
  229. package/src/thread/components/ThreadFooter.tsx +77 -0
  230. package/src/thread/components/ThreadTree.stories.tsx +46 -0
  231. package/src/thread/components/ThreadTree.test.tsx +41 -0
  232. package/src/thread/components/ThreadTree.tsx +267 -0
  233. package/src/thread/components/thread-tree.test.ts +137 -0
  234. package/src/thread/components/thread-tree.ts +112 -0
  235. package/src/thread/thread-controller.curate.test.ts +502 -0
  236. package/src/thread/thread-controller.derivation.test.ts +62 -0
  237. package/src/thread/thread-controller.live-diff.test.ts +357 -0
  238. package/src/thread/thread-controller.optimistic.test.ts +69 -0
  239. package/src/thread/thread-controller.share.test.ts +573 -0
  240. package/src/thread/thread-controller.switch-cache.test.ts +174 -0
  241. package/src/thread/thread-controller.tree.test.ts +263 -0
  242. package/src/thread/thread-controller.ts +2026 -0
  243. package/src/thread/tree-view.test.ts +128 -0
  244. package/src/thread/tree-view.ts +146 -0
  245. package/src/thread/use-thread-agent.test.tsx +208 -0
  246. package/src/thread/use-thread-agent.ts +117 -0
  247. package/src/ui/components/CodeBlock.stories.tsx +42 -0
  248. package/src/ui/components/CodeBlock.tsx +80 -0
  249. package/src/ui/components/ConfirmCard.stories.tsx +37 -0
  250. package/src/ui/components/ConfirmCard.tsx +151 -0
  251. package/src/ui/components/ConfirmDialog.stories.tsx +21 -0
  252. package/src/ui/components/ConfirmDialog.tsx +72 -0
  253. package/src/ui/components/OverlayScrollbar.stories.tsx +33 -0
  254. package/src/ui/components/OverlayScrollbar.test.tsx +139 -0
  255. package/src/ui/components/OverlayScrollbar.tsx +129 -0
  256. package/src/ui/components/PromptDialog.stories.tsx +36 -0
  257. package/src/ui/components/PromptDialog.test.tsx +65 -0
  258. package/src/ui/components/PromptDialog.tsx +99 -0
  259. package/src/ui/components/RootOverlay.stories.tsx +45 -0
  260. package/src/ui/components/RootOverlay.tsx +49 -0
  261. package/src/ui/components/ScrollArea.stories.tsx +20 -0
  262. package/src/ui/components/ScrollArea.tsx +61 -0
  263. package/src/ui/components/Toast.stories.tsx +19 -0
  264. package/src/ui/components/Toast.tsx +54 -0
  265. package/src/ui/components/Tooltip.stories.tsx +26 -0
  266. package/src/ui/components/Tooltip.tsx +72 -0
  267. package/src/ui/components/menu-control.stories.tsx +35 -0
  268. package/src/ui/components/menu-control.tsx +43 -0
  269. package/src/ui/components/primitives/Button.stories.tsx +32 -0
  270. package/src/ui/components/primitives/Button.tsx +57 -0
  271. package/src/ui/components/primitives/Card.stories.tsx +25 -0
  272. package/src/ui/components/primitives/Card.tsx +62 -0
  273. package/src/ui/components/primitives/Dialog.stories.tsx +24 -0
  274. package/src/ui/components/primitives/Dialog.test.tsx +38 -0
  275. package/src/ui/components/primitives/Dialog.tsx +69 -0
  276. package/src/ui/components/primitives/DialogActions.stories.tsx +20 -0
  277. package/src/ui/components/primitives/DialogActions.tsx +39 -0
  278. package/src/ui/components/primitives/IconButton.stories.tsx +36 -0
  279. package/src/ui/components/primitives/IconButton.tsx +58 -0
  280. package/src/ui/components/primitives/StatusBar.stories.tsx +11 -0
  281. package/src/ui/components/primitives/StatusBar.tsx +23 -0
  282. package/src/ui/components/primitives/Switch.stories.tsx +17 -0
  283. package/src/ui/components/primitives/Switch.tsx +32 -0
  284. package/src/ui/components/primitives/Tabs.stories.tsx +29 -0
  285. package/src/ui/components/primitives/Tabs.tsx +101 -0
  286. package/src/ui/components/primitives/Toolbar.stories.tsx +17 -0
  287. package/src/ui/components/primitives/Toolbar.tsx +14 -0
  288. package/src/ui/components/primitives/Tree.stories.tsx +124 -0
  289. package/src/ui/components/primitives/Tree.tsx +133 -0
  290. package/src/ui/components/primitives/frame.test.ts +12 -0
  291. package/src/ui/components/primitives/frame.ts +17 -0
  292. package/src/ui/components/primitives/icons.ts +61 -0
  293. package/src/ui/components/primitives/tree-model.test.ts +99 -0
  294. package/src/ui/components/primitives/tree-model.ts +137 -0
  295. package/src/ui/components/syntax-highlight.ts +133 -0
  296. package/src/ui/components/truncate-text.ts +7 -0
  297. package/src/ui/components/truncate-title.test.ts +31 -0
  298. package/src/ui/components/truncate-title.ts +15 -0
  299. package/src/ui/use-frame-measure.ts +74 -0
  300. package/src/ui/use-terminal-virtualizer.ts +259 -0
  301. package/src/workbench/components/ChangesColumn.stories.tsx +44 -0
  302. package/src/workbench/components/ChangesColumn.tsx +203 -0
  303. package/src/workbench/components/ChangesFileTree.test.tsx +181 -0
  304. package/src/workbench/components/EditorGrid.split.test.tsx +118 -0
  305. package/src/workbench/components/EditorGrid.stories.tsx +86 -0
  306. package/src/workbench/components/EditorGrid.tabs.test.tsx +118 -0
  307. package/src/workbench/components/EditorGrid.tsx +544 -0
  308. package/src/workbench/components/EditorGrid.zoom.test.tsx +132 -0
  309. package/src/workbench/components/FileContentsView.stories.tsx +16 -0
  310. package/src/workbench/components/FileContentsView.test.tsx +29 -0
  311. package/src/workbench/components/FileContentsView.tsx +100 -0
  312. package/src/workbench/components/GridTabContent.actions.test.tsx +151 -0
  313. package/src/workbench/components/GridTabContent.stories.tsx +59 -0
  314. package/src/workbench/components/GridTabContent.tsx +193 -0
  315. package/src/workbench/components/ProjectTreeView.stories.tsx +25 -0
  316. package/src/workbench/components/ProjectTreeView.test.tsx +236 -0
  317. package/src/workbench/components/ProjectTreeView.tsx +151 -0
  318. package/src/workbench/components/TreePane.stories.tsx +106 -0
  319. package/src/workbench/components/TreePane.tsx +155 -0
  320. package/src/workbench/components/WelcomePlayground.stories.tsx +12 -0
  321. package/src/workbench/components/WelcomePlayground.test.tsx +83 -0
  322. package/src/workbench/components/WelcomePlayground.tsx +138 -0
  323. package/src/workbench/components/editor-grid.test.ts +184 -0
  324. package/src/workbench/components/editor-grid.ts +281 -0
  325. package/src/workbench/components/file-tree.test.ts +60 -0
  326. package/src/workbench/components/file-tree.ts +112 -0
  327. package/src/workbench/use-changes-workbench.ts +205 -0
  328. package/src/workbench/use-remember-layout.ts +31 -0
  329. package/src/workbench/use-repo-changes.ts +91 -0
  330. package/src/workbench/workbench-snapshot.test.ts +99 -0
  331. package/src/workbench/workbench-snapshot.ts +59 -0
  332. package/src/App.diff.test.tsx +0 -99
  333. package/src/App.export.test.tsx +0 -88
  334. package/src/App.plan-review.test.tsx +0 -259
  335. package/src/App.readonly.test.tsx +0 -148
  336. package/src/App.rendering.test.tsx +0 -108
  337. package/src/App.submit-confirm.test.tsx +0 -183
  338. package/src/App.test.tsx +0 -218
  339. package/src/App.tsx +0 -1249
  340. package/src/config.test.ts +0 -116
  341. package/src/config.ts +0 -150
  342. package/src/editor.ts +0 -34
  343. package/src/herdr.test.ts +0 -68
  344. package/src/herdr.ts +0 -34
  345. package/src/keymap.test.ts +0 -270
  346. package/src/keymap.ts +0 -173
  347. package/src/run.ts +0 -30
  348. package/src/serve.ts +0 -75
  349. package/src/session-controller.ts +0 -398
  350. package/src/syntax.test.ts +0 -41
  351. package/src/syntax.ts +0 -88
  352. package/src/theme.ts +0 -46
  353. package/src/view-diff.test.ts +0 -55
  354. package/src/view-diff.ts +0 -86
  355. package/src/view.test.ts +0 -157
  356. package/src/view.ts +0 -364
@@ -0,0 +1,1667 @@
1
+ import React, {
2
+ useCallback,
3
+ useEffect,
4
+ useMemo,
5
+ useRef,
6
+ useState,
7
+ useSyncExternalStore,
8
+ } from "react";
9
+ import { useKeyboard, useRenderer, useTerminalDimensions } from "@opentui/react";
10
+ import type { Clock, KeyEvent } from "@opentui/core";
11
+ import { buildDisplay, marksByDisplay, type Mark } from "../markdown/view-plan";
12
+ import {
13
+ DEFAULT_KEYS,
14
+ DEFAULT_QUICK_ACTIONS,
15
+ loadConfig,
16
+ persistAuthorName,
17
+ persistDiffView,
18
+ persistIdentity,
19
+ persistPins,
20
+ type AutoClose,
21
+ type DiffViewMode,
22
+ type IdentityConfig,
23
+ type QuickAction,
24
+ type ReviewWorkspaceMode,
25
+ } from "../settings/config";
26
+ import { resolveDisplayName } from "../integrations/attribution";
27
+ import { resolveGithubIdentity } from "../integrations/github-identity";
28
+ import { loadSkills, PaletteNamesContext, SlashSkillsContext } from "../keyboard/skills";
29
+ import { mergeSlashItems, slashItemsFrom, type SlashItem } from "../keyboard/slash-palette";
30
+ import {
31
+ composeTheme,
32
+ DEFAULT_THEME_NAME,
33
+ themeForName,
34
+ type Appearance,
35
+ type ThemeName,
36
+ } from "../appearance/theme-presets";
37
+ import type { Theme } from "../appearance/theme";
38
+ import {
39
+ createReviewController,
40
+ type ShareTransport,
41
+ type ReviewController,
42
+ } from "../thread/thread-controller";
43
+ import type { ThreadClient } from "@cueloop/daemon/client";
44
+ import { createIntentDispatch, type Mode, type RailTab } from "./intent-dispatch";
45
+ import { reduceKey, type KeyState } from "../keyboard/keymap";
46
+ import { KeyBindings, type CheatsheetSection } from "../keyboard/key-bindings";
47
+ import { useReadySignal } from "./ready-signal";
48
+ import { ThemeProvider } from "../appearance/components/theme-context";
49
+ import { Button } from "../ui/components/primitives/Button";
50
+ import { ShareDialog } from "../integrations/components/ShareDialog";
51
+ import { shareDialogStore } from "../integrations/components/share-dialog-store";
52
+ import { Toolbar } from "../ui/components/primitives/Toolbar";
53
+ import { groupInbox, projectName, threadTitle } from "../thread/components/thread-tree";
54
+ import { ThreadTree } from "../thread/components/ThreadTree";
55
+ import { ChangesFileTree } from "../workbench/components/ChangesColumn";
56
+ import { MenuControlProvider, useMenuControlState } from "../ui/components/menu-control";
57
+ import { ProjectTreeView } from "../workbench/components/ProjectTreeView";
58
+ import { AppShell, type FocusPane, type ProjectPanelMode } from "./components/AppShell";
59
+ import type { ClientExtensionRegistry } from "../integrations/client-extension-registry";
60
+ import type { ExtensionUIContext } from "@cueloop/extension-api/client";
61
+ import { EditorGrid } from "../workbench/components/EditorGrid";
62
+ import { GridTabContent } from "../workbench/components/GridTabContent";
63
+ import { useChangesWorkbench } from "../workbench/use-changes-workbench";
64
+ import { useRepoChanges } from "../workbench/use-repo-changes";
65
+ import { useThreadBodyEditing } from "../markdown/use-thread-body-editing";
66
+ import { useRememberLayout } from "../workbench/use-remember-layout";
67
+ import type { LaunchLayout } from "./launch-layout";
68
+ import { ThreadFooter, THREAD_FOOTER_HEIGHT } from "../thread/components/ThreadFooter";
69
+ import { AgentThreadPrototype, agentOwnsKeyboard } from "../thread/components/AgentThreadPane";
70
+ import { ConfirmCard } from "../ui/components/ConfirmCard";
71
+ import { THREAD_VIEW_CHEATSHEET, ThreadView } from "../markdown/components/ThreadView";
72
+ import {
73
+ curationCommandEntries,
74
+ diffCommandEntries,
75
+ resolveNavKey,
76
+ resolveSessionChord,
77
+ sessionCommandEntries,
78
+ treeCommandEntries,
79
+ } from "../keyboard/thread-chords";
80
+ import { type DiffFoldControls } from "../diff/components/DiffContentView";
81
+ import { commentCountsByFile, readsFrozenDiff } from "../diff/view-diff";
82
+ import { annotationTarget, isAddressed, isAgentNote } from "@cueloop/schema";
83
+ import type {
84
+ Annotation,
85
+ Artifact,
86
+ DiffFileContents,
87
+ Identity,
88
+ ShareLink,
89
+ Thread,
90
+ MessageOutcome,
91
+ } from "@cueloop/schema";
92
+ import { PrototypePixels } from "../prototype/prototype-pixels";
93
+ import type { PrototypeElement } from "../prototype/prototype-browser";
94
+ import {
95
+ buildRenderFlags,
96
+ buildSubmitConfirmState,
97
+ computeRoleCapabilities,
98
+ deriveReviewFlags,
99
+ isPixelPrototypeMode,
100
+ isCompletionOverlayPhase,
101
+ isWalking,
102
+ resolveOverlay,
103
+ } from "./app-view-model";
104
+ import { buildKeyState } from "./app-key-state";
105
+ import { useSettingsDialog } from "../settings/use-settings-dialog";
106
+ import {
107
+ CompletionScreen,
108
+ ConnectingScreen,
109
+ ErrorScreen,
110
+ MenuChrome,
111
+ NoThreadShell,
112
+ TrailingOverlays,
113
+ } from "./app-screens";
114
+ /** A toast clears itself after this idle; esc dismisses it sooner. */
115
+ const TOAST_DISMISS_MS = 2000;
116
+
117
+ export interface AppProps {
118
+ home?: string;
119
+ sessionId?: string;
120
+ initialReview?: { session: Thread; diff: { patch: string; files: DiffFileContents[] } };
121
+ initialClient?: ThreadClient;
122
+ agentClient?: import("../thread/use-thread-agent").ThreadAgentClient;
123
+ cwd?: string;
124
+ readOnly?: boolean;
125
+ onExit?: (code: number) => void;
126
+ onReady?: () => void;
127
+ clock?: Clock;
128
+ openClient?: () => Promise<ThreadClient>;
129
+ shareTransport?: ShareTransport;
130
+ role?: "owner" | "observer" | "collaborator";
131
+ selfAuthor?: string;
132
+ appearance?: Appearance;
133
+ layout?: LaunchLayout;
134
+ servedArtifact?: Artifact;
135
+ extensionRegistry?: ClientExtensionRegistry;
136
+ }
137
+
138
+ function initialReviewControllerOptions(initialReview: AppProps["initialReview"]) {
139
+ const options = { initialSession: initialReview?.session, initialDiff: initialReview?.diff };
140
+
141
+ return options;
142
+ }
143
+
144
+ function initialReviewFiles(initialReview: AppProps["initialReview"], sessionId: string) {
145
+ const files = initialReview?.session.id === sessionId ? initialReview.diff.files : undefined;
146
+
147
+ return files;
148
+ }
149
+
150
+ function extensionContext(cwd: string | undefined, threadId: string | null): ExtensionUIContext {
151
+ return { workspace: cwd ?? process.cwd(), threadId };
152
+ }
153
+
154
+ /** True while the drop-up or one of its dialogs is open and owns the keyboard. */
155
+ function menuChromeOpen(menuDialog: "keybinds" | "settings" | null): boolean {
156
+ return menuDialog !== null;
157
+ }
158
+
159
+ /** Whether a thread already has at least one live share link. */
160
+ function isSharedThread(session: Thread | null): boolean {
161
+ return session !== null && (session.shares?.length ?? 0) > 0;
162
+ }
163
+
164
+ /** A thread's live share links for the share dialog, or an empty list with no session. */
165
+ function shareLinksFor(session: Thread | null): ShareLink[] {
166
+ return session ? (session.shares ?? []) : [];
167
+ }
168
+
169
+ /** The title the share dialog shows and prefills a new link with, or empty with no session. */
170
+ function shareThreadName(session: Thread | null): string {
171
+ return session ? threadTitle(session) : "";
172
+ }
173
+
174
+ /** Show the diff source before long titles can truncate it in the header. */
175
+ function reviewThreadTitle(session: Thread): string {
176
+ if (session.artifact.type === "diff" && session.artifact.meta.vcs)
177
+ return `vcs: ${session.artifact.meta.vcs} · ${threadTitle(session)}`;
178
+
179
+ return threadTitle(session);
180
+ }
181
+
182
+ /** The drop-up chrome or a floating popover menu (thread actions, editor split) holds the keyboard. */
183
+ function keyboardHeldByMenu(
184
+ menuDialog: "keybinds" | "settings" | null,
185
+ openMenuId: string | null,
186
+ ): boolean {
187
+ return menuChromeOpen(menuDialog) || openMenuId !== null;
188
+ }
189
+
190
+ /** A non-modal toast: escape dismisses it only when nothing else owns escape (no overlay, not span mode). */
191
+ export function toastDismissRequested(
192
+ toastOpen: boolean,
193
+ key: { name: string },
194
+ overlay: KeyState["overlay"],
195
+ spanMode: boolean,
196
+ ): boolean {
197
+ return toastOpen && key.name === "escape" && overlay === "none" && !spanMode;
198
+ }
199
+
200
+ /** ctrl+q quits from anywhere, ahead of every focus/menu/overlay gate, with no confirmation. */
201
+ export function quitKeyHandled(
202
+ key: { name: string; ctrl?: boolean },
203
+ onExit?: (code: number) => void,
204
+ ): boolean {
205
+ if (!key.ctrl || key.name !== "q") return false;
206
+ onExit?.(0);
207
+
208
+ return true;
209
+ }
210
+
211
+ /** A popover menu is open, so the shell keyboard is modal: escape closes it, every other key is swallowed. */
212
+ function menuModalHandled(
213
+ menuControl: { openMenuId: string | null; closeMenu: () => void },
214
+ key: { name: string },
215
+ ): boolean {
216
+ if (menuControl.openMenuId === null) return false;
217
+ if (key.name === "escape") menuControl.closeMenu();
218
+
219
+ return true;
220
+ }
221
+
222
+ /** True while a menu, an overlay, or the share dialog owns the keyboard instead of the thread view. */
223
+ function keyboardOwnedElsewhere(
224
+ menuOwnsKeyboard: boolean,
225
+ overlay: KeyState["overlay"],
226
+ shareDialogOpen: boolean,
227
+ ): boolean {
228
+ return menuOwnsKeyboard || overlay !== "none" || shareDialogOpen;
229
+ }
230
+
231
+ /** The footer submit fires only for the owner of an unresolved review, never an observer. */
232
+ function canSubmitReview(isOwner: boolean, resolved: boolean, observer: boolean): boolean {
233
+ return isOwner && !resolved && !observer;
234
+ }
235
+
236
+ /** The thread body edits inline only for its owner, on an unresolved markdown thread (never a diff). */
237
+ function canEditThreadBody(
238
+ threadViewActive: boolean,
239
+ isDiff: boolean,
240
+ isOwner: boolean,
241
+ resolved: boolean,
242
+ ): boolean {
243
+ return threadViewActive && !isDiff && isOwner && !resolved;
244
+ }
245
+
246
+ /** The owner's header actions: an edit/normal toggle that opens or leaves the inline editor, plus share when not editing. */
247
+ function ownerThreadActions(actions: {
248
+ editing: boolean;
249
+ onEdit: () => void;
250
+ onExitEdit: () => void;
251
+ onShare: () => void;
252
+ theme: Theme;
253
+ }): React.ReactNode {
254
+ return (
255
+ <Toolbar>
256
+ <Button onPress={actions.editing ? actions.onExitEdit : actions.onEdit} theme={actions.theme}>
257
+ {actions.editing ? " normal " : " edit "}
258
+ </Button>
259
+ {actions.editing ? null : (
260
+ <Button onPress={actions.onShare} theme={actions.theme}>
261
+ {" share "}
262
+ </Button>
263
+ )}
264
+ </Toolbar>
265
+ );
266
+ }
267
+
268
+ function refreshDiffAction(onRefresh: () => void, theme: Theme): React.ReactNode {
269
+ return (
270
+ <Toolbar>
271
+ <Button onPress={onRefresh} foreground={theme.warning} theme={theme}>
272
+ {" refresh "}
273
+ </Button>
274
+ </Toolbar>
275
+ );
276
+ }
277
+
278
+ /** Present pull request context with the ordinary read-only Thread renderer. */
279
+ function pullRequestBriefThread(session: Thread): Thread {
280
+ return {
281
+ ...session,
282
+ artifact: {
283
+ ...session.artifact,
284
+ type: "reply",
285
+ content: session.artifact.meta.prBrief ?? "",
286
+ },
287
+ workingCopy: undefined,
288
+ annotations: [],
289
+ };
290
+ }
291
+
292
+ /** Pick the thread pane's body: the pixel prototype, the diff placeholder, the inline editor, or the read-only view. */
293
+ function chooseThreadBody(choice: {
294
+ isPixelPrototype: boolean;
295
+ isDiff: boolean;
296
+ editingBody: boolean;
297
+ prototype: React.ReactNode;
298
+ diffPlaceholder: React.ReactNode;
299
+ editor: React.ReactNode;
300
+ threadView: React.ReactNode;
301
+ }): React.ReactNode {
302
+ if (choice.isPixelPrototype) return choice.prototype;
303
+ if (choice.isDiff) return choice.diffPlaceholder;
304
+ if (choice.editingBody) return choice.editor;
305
+
306
+ return choice.threadView;
307
+ }
308
+
309
+ /** The author display name for a comment's hover tooltip: the reviewer's own name for their notes, else the resolved collaborator name. */
310
+ function authorLabelResolver(
311
+ ownName: string | undefined,
312
+ participants: Identity[] | undefined,
313
+ overrides: Record<string, string>,
314
+ ): (annotation: Annotation) => string | undefined {
315
+ return (annotation) =>
316
+ annotation.author === undefined
317
+ ? (ownName ?? "you")
318
+ : resolveDisplayName(annotation.author, participants, overrides);
319
+ }
320
+
321
+ /** The Project pane body: the resolved repo's changed files in changes mode, its full tree otherwise. */
322
+ function ProjectPanelBody(props: {
323
+ mode: ProjectPanelMode;
324
+ loadChanges: () => Promise<readonly DiffFileContents[]>;
325
+ initialFiles?: readonly DiffFileContents[];
326
+ loadProjectFiles: () => Promise<string[]>;
327
+ diffSourceKey: string;
328
+ liveWorkingTree: boolean;
329
+ frozenFiles?: readonly DiffFileContents[];
330
+ onOpenChangedFile: (path: string, persistent?: boolean) => void;
331
+ onOpenProjectFile: (path: string, persistent?: boolean) => void;
332
+ commentCounts?: ReadonlyMap<string, number>;
333
+ focused?: boolean;
334
+ theme: Theme;
335
+ }): React.ReactNode {
336
+ const changes = useRepoChanges({
337
+ loadChanges: props.loadChanges,
338
+ visible: props.mode === "changes" && props.liveWorkingTree,
339
+ diffSourceKey: props.diffSourceKey,
340
+ initialFiles: props.initialFiles,
341
+ });
342
+
343
+ if (props.mode === "changes") {
344
+ return (
345
+ <ChangesFileTree
346
+ files={props.liveWorkingTree ? changes : (props.frozenFiles ?? [])}
347
+ onSelectFile={props.onOpenChangedFile}
348
+ commentCounts={props.commentCounts}
349
+ focused={props.focused}
350
+ theme={props.theme}
351
+ />
352
+ );
353
+ }
354
+
355
+ return (
356
+ <ProjectTreeView
357
+ key={props.diffSourceKey}
358
+ loadFiles={props.loadProjectFiles}
359
+ onSelectFile={props.onOpenProjectFile}
360
+ focused={props.focused}
361
+ theme={props.theme}
362
+ />
363
+ );
364
+ }
365
+
366
+ /** Frozen reviews read their captured files directly; live workspaces poll the repo. */
367
+ interface ProjectDiffFiles {
368
+ liveWorkingTree: boolean;
369
+ frozenFiles?: readonly DiffFileContents[];
370
+ }
371
+
372
+ function projectDiffFiles(session: Thread): ProjectDiffFiles {
373
+ const frozen = readsFrozenDiff(session);
374
+
375
+ return {
376
+ liveWorkingTree: !frozen,
377
+ frozenFiles: frozen ? session.artifact.files : undefined,
378
+ };
379
+ }
380
+
381
+ /** The render tree has left the connecting screen: an error, a session, or the no-thread shell. */
382
+ function usableScreenReached(
383
+ error: string | null,
384
+ session: Thread | null,
385
+ inbox: Thread[] | null,
386
+ ): boolean {
387
+ return Boolean(error) || session !== null || inbox !== null;
388
+ }
389
+
390
+ /** The keybinds dialog content: the thread grammar while the thread view owns the keys. */
391
+ function cheatsheetFor(keyBindings: KeyBindings, threadViewActive: boolean): CheatsheetSection[] {
392
+ const base = keyBindings.cheatsheet();
393
+ const fileTree: CheatsheetSection = {
394
+ title: "Changes / Project files",
395
+ entries: [
396
+ { keys: "enter", label: "open selected file or toggle folder" },
397
+ { keys: "tab", label: "cycle panes" },
398
+ ],
399
+ };
400
+
401
+ if (!threadViewActive) {
402
+ return [fileTree, ...base];
403
+ }
404
+
405
+ return [
406
+ fileTree,
407
+ ...THREAD_VIEW_CHEATSHEET,
408
+ { title: "Nav mode · session", entries: sessionCommandEntries() },
409
+ { title: "Nav mode · diff", entries: diffCommandEntries() },
410
+ { title: "Nav mode · discussion", entries: curationCommandEntries() },
411
+ { title: "Nav mode · history", entries: treeCommandEntries() },
412
+ ];
413
+ }
414
+
415
+ /** The Threads sidebar opens from the launch layout; a bare launch opens it only on the inbox. */
416
+ function initialThreadsOpen(
417
+ layout: LaunchLayout | undefined,
418
+ sessionId: string | undefined,
419
+ ): boolean {
420
+ return layout ? layout.threads : sessionId === undefined;
421
+ }
422
+
423
+ function initialFocusedPane(
424
+ sessionId: string | undefined,
425
+ zoomed: boolean,
426
+ layout?: LaunchLayout,
427
+ ): FocusPane {
428
+ if (sessionId === undefined) return "threads";
429
+
430
+ return layout?.focusPane ?? (zoomed ? "changes" : "thread");
431
+ }
432
+
433
+ function bareShellDefersKeys(
434
+ sessionIsNull: boolean,
435
+ overlayIsNone: boolean,
436
+ focusedPane: FocusPane,
437
+ ): boolean {
438
+ return sessionIsNull && overlayIsNone && focusedPane !== "threads";
439
+ }
440
+
441
+ function surfaceSuspended(base: boolean, focusedPane: FocusPane, pane: FocusPane): boolean {
442
+ return base || focusedPane !== pane;
443
+ }
444
+
445
+ export function threadsNavHandled(params: {
446
+ focusedPane: FocusPane;
447
+ quiet: boolean;
448
+ key: { name: string };
449
+ count: number;
450
+ setInboxCursor: (update: (cursor: number) => number) => void;
451
+ openSession: () => void;
452
+ }): boolean {
453
+ const { focusedPane, quiet, key, count } = params;
454
+
455
+ if (focusedPane !== "threads" || !quiet || count === 0) return false;
456
+ if (key.name === "j" || key.name === "down") {
457
+ params.setInboxCursor((cursor) => Math.min(cursor + 1, count - 1));
458
+
459
+ return true;
460
+ }
461
+ if (key.name === "k" || key.name === "up") {
462
+ params.setInboxCursor((cursor) => Math.max(cursor - 1, 0));
463
+
464
+ return true;
465
+ }
466
+ if (key.name === "return" || key.name === "enter") {
467
+ params.openSession();
468
+
469
+ return true;
470
+ }
471
+
472
+ return false;
473
+ }
474
+
475
+ export function paneCycleRequested(
476
+ key: { name: string },
477
+ overlay: string,
478
+ menuOwnsKeyboard: boolean,
479
+ threadComposing: boolean,
480
+ ): boolean {
481
+ return key.name === "tab" && overlay === "none" && !menuOwnsKeyboard && !threadComposing;
482
+ }
483
+
484
+ export function visiblePanes(
485
+ sidebarOpen: boolean,
486
+ threadShown: boolean,
487
+ changesOpen: boolean,
488
+ projectOpen: boolean,
489
+ ): FocusPane[] {
490
+ const panes: FocusPane[] = [];
491
+
492
+ if (sidebarOpen) panes.push("threads");
493
+ if (threadShown) panes.push("thread");
494
+ if (changesOpen) panes.push("changes");
495
+ if (projectOpen) panes.push("project");
496
+
497
+ return panes;
498
+ }
499
+
500
+ export function nextFocusPane(
501
+ current: FocusPane,
502
+ panes: FocusPane[],
503
+ backward: boolean,
504
+ ): FocusPane {
505
+ if (panes.length === 0) return current;
506
+ const index = panes.indexOf(current);
507
+ const step = backward ? -1 : 1;
508
+
509
+ return panes[(index + step + panes.length) % panes.length] ?? current;
510
+ }
511
+
512
+ /** The panes that can own the keyboard: a diff's Thread pane is an inert placeholder, so it is out. */
513
+ function navigableFocusPanes(
514
+ sidebarOpen: boolean,
515
+ zoomed: boolean,
516
+ isDiff: boolean,
517
+ changesOpen: boolean,
518
+ projectOpen: boolean,
519
+ ): FocusPane[] {
520
+ return visiblePanes(sidebarOpen, !zoomed && !isDiff, changesOpen, projectOpen);
521
+ }
522
+
523
+ /** The layout hid or inert-ed the focused pane: fall back to the first navigable one, else stay put. */
524
+ export function reconciledFocus(navigable: FocusPane[], focusedPane: FocusPane): FocusPane | null {
525
+ if (navigable.length === 0 || navigable.includes(focusedPane)) return null;
526
+
527
+ return navigable[0] ?? null;
528
+ }
529
+
530
+ export function App({
531
+ home,
532
+ sessionId,
533
+ initialReview,
534
+ initialClient,
535
+ agentClient,
536
+ cwd,
537
+ readOnly = false,
538
+ onExit,
539
+ onReady,
540
+ clock,
541
+ openClient,
542
+ shareTransport,
543
+ role = "owner",
544
+ selfAuthor,
545
+ appearance = "dark",
546
+ layout,
547
+ servedArtifact,
548
+ extensionRegistry,
549
+ }: AppProps): React.ReactNode {
550
+ const { observer, isOwner } = computeRoleCapabilities(readOnly, role);
551
+ const controller = useMemo(
552
+ () =>
553
+ createReviewController({
554
+ home,
555
+ sessionId,
556
+ ...initialReviewControllerOptions(initialReview),
557
+ initialClient,
558
+ cwd,
559
+ readOnly: observer,
560
+ onExit,
561
+ clock,
562
+ openClient,
563
+ shareTransport,
564
+ servedArtifact,
565
+ }),
566
+ // eslint-disable-next-line react-hooks/exhaustive-deps
567
+ [home, sessionId],
568
+ );
569
+ const showExtensionError = useCallback(
570
+ (message: string) => controller.showToast(message),
571
+ [controller],
572
+ );
573
+
574
+ useEffect(() => {
575
+ controller.connect();
576
+
577
+ return () => controller.close();
578
+ }, [controller]);
579
+ // stable across renders so the memoized PrototypeContentView is not
580
+ // re-rendered by unrelated App state (status ticks, a rail-width drag)
581
+ const onCommentPrototype = useCallback(
582
+ (element: PrototypeElement, body: string) =>
583
+ controller.annotatePrototype(element.selector, element.quote, body),
584
+ [controller],
585
+ );
586
+ const { session, inbox, status, toast, error, completion, editOrphanCount, walk } =
587
+ useSyncExternalStore(controller.subscribe, controller.getSnapshot, controller.getSnapshot);
588
+ const initialReviewForFirstMount = useRef(initialReview);
589
+
590
+ useEffect(() => {
591
+ initialReviewForFirstMount.current = undefined;
592
+ }, []);
593
+
594
+ // A shared plan you own polls for collaborator notes while it is open; the
595
+ // merge refreshes through the normal event path. Stops on leave.
596
+ const threadShared = isSharedThread(session);
597
+
598
+ useEffect(() => {
599
+ if (!isOwner || !threadShared) return;
600
+
601
+ return controller.startShareSync();
602
+ }, [isOwner, session?.id, threadShared, controller]);
603
+ const renderer = useRenderer();
604
+ const { width: terminalWidth } = useTerminalDimensions();
605
+
606
+ // ── view state ──────────────────────────────
607
+ const [cursor, setCursor] = useState(0);
608
+ const [inboxCursor, setInboxCursor] = useState(0);
609
+ // Projects and Threads grouping; ordered is the flat sequence the inbox cursor walks
610
+ // pinned threads are client-local view state, seeded from the user config and
611
+ // persisted on toggle; a pin lifts the thread into the sidebar's Pinned section
612
+ const [pinnedIds, setPinnedIds] = useState<Set<string>>(new Set());
613
+ const grouped = useMemo(() => groupInbox(inbox ?? [], pinnedIds), [inbox, pinnedIds]);
614
+ const togglePin = (id: string): void =>
615
+ setPinnedIds((current) => {
616
+ const next = new Set(current);
617
+
618
+ if (next.has(id)) next.delete(id);
619
+ else next.add(id);
620
+ persistPins([...next]);
621
+
622
+ return next;
623
+ });
624
+ // the left Projects and Threads column; collapsed by default per the context
625
+ // matrix (the thread owns the width), toggled open to jump between threads
626
+ // one sidebar-open state across the no-thread shell and the thread view, so
627
+ // picking a thread keeps the sidebar as it was. It opens when the app lands with
628
+ // nothing selected (pick a thread) and stays collapsed on a direct thread open,
629
+ // where the thread owns the width.
630
+ const [sidebarOpen, setSidebarOpen] = useState(() => initialThreadsOpen(layout, sessionId));
631
+ // the Changes + Project right region and its editor grid (tabs, splits, zoom)
632
+ const workbench = useChangesWorkbench({ layout });
633
+ const [focusedPane, setFocusedPane] = useState<FocusPane>(() =>
634
+ initialFocusedPane(sessionId, workbench.zoomed, layout),
635
+ );
636
+
637
+ // only the session view persists from here; the bare shell owns its own (NoThreadShell), so this
638
+ // workbench stays inactive with no session and never clobbers what the shell saved
639
+ useRememberLayout(
640
+ layout,
641
+ session !== null,
642
+ sidebarOpen,
643
+ workbench.changesOpen,
644
+ workbench.projectOpen,
645
+ workbench.zoomed,
646
+ );
647
+ const [mode, setMode] = useState<Mode>({ type: "normal" });
648
+ // the top-left settings gear drop-down and the centered dialog it opens
649
+ const [menuDialog, setMenuDialog] = useState<"keybinds" | "settings" | null>(null);
650
+ const [shareDialogOpen, setShareDialogOpen] = useState(false);
651
+ const [autoClose, setAutoClose] = useState<AutoClose>("off");
652
+ // unified or side-by-side diff; split lays out when the Changes pane is zoomed
653
+ const [diffView, setDiffView] = useState<DiffViewMode>("split");
654
+ const [defaultMessage, setDefaultMessage] = useState<MessageOutcome>("approved");
655
+ const [focusedAnnotationId, setFocusedAnnotationId] = useState<string | undefined>(undefined);
656
+ const [selectedCurationId, setSelectedCurationId] = useState<string | undefined>(undefined);
657
+ const [railTab, setRailTab] = useState<RailTab>("review");
658
+ // the tree row the reviewer stands on in the session tree
659
+ const [selectedEntryId, setSelectedEntryId] = useState<string | undefined>(undefined);
660
+ // ~2s focus pulse on the document highlight when a card is activated
661
+ const [pulsedAnnotationId, setPulsedAnnotationId] = useState<string | null>(null);
662
+ const pulseTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
663
+ // live mirror of overlay input text: refs commit synchronously, so the
664
+ // RETURN handler never reads a stale value mid-typing
665
+ const liveInput = useRef("");
666
+ // keymap from layered config; the loaded theme swaps the provider value
667
+ const keysRef = useRef(DEFAULT_KEYS);
668
+ const keyBindings = useMemo(() => new KeyBindings(DEFAULT_KEYS), []);
669
+ const [theme, setTheme] = useState(() => themeForName(DEFAULT_THEME_NAME, appearance));
670
+ const [themeName, setThemeName] = useState<ThemeName>(DEFAULT_THEME_NAME);
671
+ const [themeOverrides, setThemeOverrides] = useState<Partial<Theme>>({});
672
+ const [authorNames, setAuthorNames] = useState<Record<string, string>>({});
673
+ const [identity, setIdentity] = useState<IdentityConfig>({ provider: "typed" });
674
+ const [quickActions, setQuickActions] = useState<QuickAction[]>(DEFAULT_QUICK_ACTIONS);
675
+ const [skills, setSkills] = useState<SlashItem[]>([]);
676
+ const [reviewSkill, setReviewSkill] = useState("code-review");
677
+ const [reviewWorkspace, setReviewWorkspace] = useState<ReviewWorkspaceMode>("worktree");
678
+ const paletteNames = useMemo(
679
+ () => new Set(mergeSlashItems(slashItemsFrom(quickActions), skills).map((item) => item.name)),
680
+ [quickActions, skills],
681
+ );
682
+ // opt-in: render a prototype as a kitty pixel mockup instead of the markdown doc
683
+ const [prototypePixels, setPrototypePixels] = useState(false);
684
+ const [threadAgentEnabled, setThreadAgentEnabled] = useState(false);
685
+
686
+ useEffect(() => {
687
+ const config = loadConfig({ repoRoot: session?.workspace.repoRoot });
688
+
689
+ setPrototypePixels(config.experimental.prototypePixels);
690
+ setThreadAgentEnabled(config.experimental.threadAgent);
691
+ keysRef.current = config.keys;
692
+ keyBindings.setKeys(config.keys);
693
+ setTheme(composeTheme(config.ui.theme, config.themeOverrides, appearance));
694
+ setThemeName(config.ui.theme);
695
+ setThemeOverrides(config.themeOverrides);
696
+ setAuthorNames(config.authors);
697
+ setIdentity(config.identity);
698
+ setQuickActions(config.actions);
699
+ setSkills(loadSkills(config.skillsPath));
700
+ setReviewSkill(config.review.skill);
701
+ setReviewWorkspace(config.review.workspace);
702
+ setAutoClose(config.ui.autoClose);
703
+ setDiffView(config.ui.diffView);
704
+ setDefaultMessage(config.ui.defaultMessage);
705
+ setPinnedIds(new Set(config.ui.pins));
706
+ controller.applyConfig(config);
707
+ }, [session?.workspace.repoRoot, controller, keyBindings, appearance]);
708
+ useEffect(
709
+ () => () => {
710
+ if (pulseTimer.current) clearTimeout(pulseTimer.current);
711
+ },
712
+ [],
713
+ );
714
+
715
+ useEffect(() => {
716
+ if (!toast) return;
717
+ const timer = setTimeout(() => controller.dismissToast(), TOAST_DISMISS_MS);
718
+
719
+ return () => clearTimeout(timer);
720
+ }, [toast, controller]);
721
+
722
+ // First open of a share: ask the collaborator for a display name once, unless
723
+ // a past visit already recorded one. esc skips and their notes read anonymous.
724
+ const promptedSelfRef = useRef(false);
725
+
726
+ useEffect(() => {
727
+ if (promptedSelfRef.current || role !== "collaborator" || !selfAuthor || !session) return;
728
+ promptedSelfRef.current = true;
729
+ const known = session.participants?.find((participant) => participant.id === selfAuthor)?.name;
730
+
731
+ if (!known) setMode({ type: "nameSelf", text: "" });
732
+ }, [role, selfAuthor, session]);
733
+
734
+ // Bumped on every identity change so a slow GitHub sync that lands after a newer rename is discarded.
735
+ const identityGenerationRef = useRef(0);
736
+ const applyIdentity = (next: IdentityConfig): void => {
737
+ identityGenerationRef.current += 1;
738
+ setIdentity(next);
739
+ try {
740
+ persistIdentity(next);
741
+ } catch {
742
+ controller.setStatus("could not save identity to config");
743
+ }
744
+ };
745
+ const syncGithubIdentity = (): void => {
746
+ const generation = (identityGenerationRef.current += 1);
747
+
748
+ void resolveGithubIdentity().then((github) => {
749
+ if (identityGenerationRef.current !== generation) return;
750
+ if (!github) return controller.setStatus("GitHub not connected - run gh auth login");
751
+ const name = github.name?.trim() || github.login;
752
+
753
+ applyIdentity({ name, provider: "github" });
754
+ });
755
+ };
756
+
757
+ // ── settings dialog: config-backed model, navigation, persistence ──
758
+ const {
759
+ settingsNav,
760
+ settingsCategories,
761
+ settingsValues,
762
+ cycleSetting,
763
+ handleSettingsKey,
764
+ onCategorySelect,
765
+ openSettings,
766
+ } = useSettingsDialog({
767
+ theme,
768
+ appearance,
769
+ autoClose,
770
+ setAutoClose,
771
+ diffView,
772
+ setDiffView,
773
+ themeName,
774
+ setThemeName,
775
+ themeOverrides,
776
+ setTheme,
777
+ quickActions,
778
+ setQuickActions,
779
+ setMenuDialog,
780
+ identityName: identity.name,
781
+ identityProvider: identity.provider,
782
+ onSyncGithubIdentity: syncGithubIdentity,
783
+ onRenameDisplayName: () => {
784
+ setMenuDialog(null);
785
+ setMode({ type: "renameSelf", text: identity.name ?? "" });
786
+ },
787
+ reviewSkill,
788
+ reviewWorkspace,
789
+ setReviewWorkspace,
790
+ });
791
+
792
+ // ── derived view model ──────────────────────
793
+ const display = controller.display();
794
+ const rows = controller.rows();
795
+ const rejectedRows = controller.rejectedRows();
796
+ const marks = useMemo(
797
+ () =>
798
+ session
799
+ ? marksByDisplay(
800
+ // the plan thread shows only artifact notes; Changes-diff notes render on that surface
801
+ session.annotations.filter(
802
+ (annotation) => annotationTarget(annotation).kind === "artifact",
803
+ ),
804
+ display,
805
+ pulsedAnnotationId ?? undefined,
806
+ )
807
+ : new Map<number, Mark[]>(),
808
+ [session, display, pulsedAnnotationId],
809
+ );
810
+ /** Annotation ids whose anchor resolved against the working copy. */
811
+ const resolvedIds = useMemo(() => {
812
+ const ids = new Set<string>();
813
+
814
+ for (const blockMarks of marks.values()) {
815
+ for (const mark of blockMarks) if (mark.annotationId) ids.add(mark.annotationId);
816
+ }
817
+
818
+ return ids;
819
+ }, [marks]);
820
+ const { isDiff, isPrototype, resolved } = deriveReviewFlags(session);
821
+ // a prototype is a markdown design doc by default; only the opt-in experimental
822
+ // pixel mode (flag on + an HTML entry) renders it as a kitty mockup instead
823
+ const isPixelPrototype = isPixelPrototypeMode(
824
+ isPrototype,
825
+ prototypePixels,
826
+ session?.artifact.meta.prototypePath,
827
+ );
828
+ // comments per changed-file path, for the changed-files tree and tab badges
829
+ const diffCommentCounts = useMemo(
830
+ () => (session && isDiff ? commentCountsByFile(session, rows) : undefined),
831
+ [session, isDiff, rows],
832
+ );
833
+
834
+ // entering a diff opens the right region in changed-files mode; a plan or reply opens it closed
835
+ workbench.syncSession(session?.id, isDiff);
836
+ // plans, replies, and the default (markdown) prototype open in the thread view, diffs in the
837
+ // diff sheet: both drive the shared annotation surface; only the pixel prototype keeps the keymap
838
+ const threadViewActive = session !== null && !isPixelPrototype;
839
+ const [threadComposing, setThreadComposing] = useState(false);
840
+ const [agentActive, setAgentActive] = useState(false);
841
+ const [agentControls, setAgentControls] = useState<React.ReactNode>(null);
842
+ const agentActions = useRef<(id: string) => { label: string; run: () => void } | undefined>(
843
+ () => undefined,
844
+ );
845
+ const agentInvoke = useRef<(() => void) | undefined>(undefined);
846
+ const [agentState, setAgentState] = useState<import("@cueloop/schema").ThreadAgentState>();
847
+ const [prototypeComposing, setPrototypeComposing] = useState(false);
848
+ const [welcomeComposing, setWelcomeComposing] = useState(false);
849
+ // inline body edit: the markdown editor owns the thread pane and all keys while open
850
+ const canEditBody = canEditThreadBody(threadViewActive, isDiff, isOwner, resolved);
851
+ const bodyEditing = useThreadBodyEditing({
852
+ controller,
853
+ sessionId: session?.id,
854
+ canEdit: canEditBody,
855
+ });
856
+ // sort position per annotation so the rail interleaves annotation and removal
857
+ // cards in one line-ordered stack: a diff row carries its blockIndex; a plan
858
+ // annotation resolves to the display index it marked
859
+ // ── the guided walk's view model ────────────
860
+ const walkFileList = controller.files();
861
+ const walking = isWalking(isDiff, walk);
862
+ const viewedPaths = useMemo(() => new Set(session?.viewedPaths ?? []), [session]);
863
+
864
+ // ── selection symmetry: one selected id, both sides ──
865
+ const selectCardFromDocument = (annotationId: string): void => {
866
+ setFocusedAnnotationId(annotationId);
867
+ };
868
+
869
+ const openCardEdit = (annotationId: string): void => {
870
+ if (observer) return controller.setStatus("observer - read-only");
871
+ const annotation = session?.annotations.find((candidate) => candidate.id === annotationId);
872
+
873
+ if (!annotation) return;
874
+ // a collaborator's note is theirs to word: activating it (click or e) renames
875
+ // the author rather than editing the body the planner does not own
876
+ if (annotation.author) {
877
+ setFocusedAnnotationId(annotationId);
878
+
879
+ return void setMode({
880
+ type: "rename",
881
+ authorId: annotation.author,
882
+ text: authorNames[annotation.author] ?? "",
883
+ });
884
+ }
885
+ if (resolved) return controller.setStatus("review submitted - read-only");
886
+ liveInput.current = annotation.body;
887
+ setMode({ type: "railEdit", id: annotation.id, text: annotation.body });
888
+ };
889
+
890
+ // a markdown thread edits inline; a diff is not markdown, so it keeps the external-editor hand-off
891
+ const openBodyEditor = (): void => {
892
+ if (canEditBody) {
893
+ bodyEditing.openEditor();
894
+
895
+ return;
896
+ }
897
+ renderer?.suspend();
898
+ try {
899
+ controller.edit();
900
+ } finally {
901
+ renderer?.resume();
902
+ }
903
+ };
904
+
905
+ // ── keyboard grammar: build state, reduce, dispatch ──
906
+ const dispatch = createIntentDispatch({
907
+ controller,
908
+ onExit,
909
+ isDiff,
910
+ display,
911
+ rows,
912
+ cursor,
913
+ inbox: inbox === null ? null : grouped.ordered,
914
+ inboxCursor,
915
+ mode,
916
+ session,
917
+ defaultMessage,
918
+ focusedAnnotationId,
919
+ selectedCurationId,
920
+ railTab,
921
+ selectedEntryId,
922
+ authorNames,
923
+ quickActions,
924
+ renameAuthor: (id: string, name: string) => {
925
+ persistAuthorName(id, name);
926
+ setAuthorNames((prev) => ({ ...prev, [id]: name }));
927
+ },
928
+ renameThread: (id: string, title: string) => controller.renameSession(id, title),
929
+ setLocalIdentityName: (name: string) => {
930
+ applyIdentity(name ? { name, provider: "typed" } : { provider: "typed" });
931
+ },
932
+ liveInput,
933
+ setCursor,
934
+ setInboxCursor,
935
+ setMode,
936
+ setRailTab,
937
+ setSelectedEntryId,
938
+ setFocusedAnnotationId,
939
+ setSelectedCurationId,
940
+ setPulsedAnnotationId,
941
+ selectCardFromDocument,
942
+ openBodyEditor,
943
+ openCardEdit,
944
+ toggleDiffView: () => {
945
+ const next: DiffViewMode = diffView === "stacked" ? "split" : "stacked";
946
+
947
+ setDiffView(next);
948
+ persistDiffView(next);
949
+ },
950
+ openShareDialog: () => {
951
+ if (!isOwner) return controller.setStatus("only the plan owner can share");
952
+ shareDialogStore.getState().reset();
953
+ setShareDialogOpen(true);
954
+ },
955
+ });
956
+
957
+ const overlay = resolveOverlay(mode, completion.phase, walking);
958
+
959
+ const menuControl = useMenuControlState();
960
+ const menuOwnsKeyboard = keyboardHeldByMenu(menuDialog, menuControl.openMenuId);
961
+ // an overlay (submit, walk, prompt, confirm, share choice), the manage-access
962
+ // dialog, or the menu takes the keyboard from the thread view; the view suspends
963
+ // its own grammar meanwhile so typing lands in the dialog, not the thread
964
+ const threadViewSuspended = keyboardOwnedElsewhere(menuOwnsKeyboard, overlay, shareDialogOpen);
965
+
966
+ const navigablePanes = navigableFocusPanes(
967
+ sidebarOpen,
968
+ workbench.zoomed,
969
+ isDiff,
970
+ workbench.changesOpen,
971
+ workbench.projectOpen,
972
+ );
973
+
974
+ useEffect(() => {
975
+ // the bare shell drives its panes from its own workbench, so only reconcile against this one
976
+ if (!session) return;
977
+ const next = reconciledFocus(navigablePanes, focusedPane);
978
+
979
+ if (next) setFocusedPane(next);
980
+ }, [session, navigablePanes, focusedPane]);
981
+ const cyclePanes = (backward: boolean): void =>
982
+ setFocusedPane((current) => nextFocusPane(current, navigablePanes, backward));
983
+ const runNavCommand = (
984
+ key: { name: string; shift?: boolean },
985
+ selection: {
986
+ start: { blockIndex: number; char: number };
987
+ end: { blockIndex: number; char: number };
988
+ } | null = null,
989
+ ): boolean => {
990
+ const intent = resolveNavKey(key, {
991
+ isOwner,
992
+ resolved,
993
+ treeActive: railTab === "tree",
994
+ isDiff,
995
+ });
996
+
997
+ if (!intent) return false;
998
+ if (intent.type === "cut" && selection) {
999
+ controller.cut(
1000
+ selection.start.blockIndex,
1001
+ selection.start.char,
1002
+ selection.end.char,
1003
+ selection.end.blockIndex,
1004
+ );
1005
+ } else dispatch(intent);
1006
+
1007
+ return true;
1008
+ };
1009
+ // clicking a sidebar thread moves the cursor onto it too, so the row shows its selected backdrop at once
1010
+ const openThread = (id: string): void => {
1011
+ // save the open editor into the leaving thread's working copy before the switch, so a click away never drops edits
1012
+ if (bodyEditing.editing) bodyEditing.requestExit();
1013
+ const index = grouped.ordered.findIndex((thread) => thread.id === id);
1014
+
1015
+ if (index >= 0) setInboxCursor(() => index);
1016
+ controller.open(id);
1017
+ };
1018
+
1019
+ const createEmptyThread = enabledThreadAction(
1020
+ canRunThreadAgent({
1021
+ enabled: threadAgentEnabled,
1022
+ owner: isOwner,
1023
+ editing: false,
1024
+ shared: isSharedThreadConnection(openClient, shareTransport),
1025
+ }),
1026
+ () => {
1027
+ void controller.createEmptyThread();
1028
+ setFocusedPane("thread");
1029
+ },
1030
+ );
1031
+
1032
+ const threadSurfaceHandledKey = (key: KeyEvent): boolean => {
1033
+ if (
1034
+ agentOwnsKeyboard(agentActive, focusedPane) &&
1035
+ (key.name === "return" || key.name === "enter") &&
1036
+ key.ctrl &&
1037
+ !key.meta &&
1038
+ !key.super
1039
+ )
1040
+ return true;
1041
+ if (!threadViewActive || threadViewSuspended) return false;
1042
+ if (!threadComposing) {
1043
+ const chord = resolveSessionChord(key, { isOwner, resolved });
1044
+
1045
+ if (chord) dispatch(chord);
1046
+ }
1047
+
1048
+ return true;
1049
+ };
1050
+
1051
+ useKeyboard((key) => {
1052
+ if (quitKeyHandled(key, onExit)) return;
1053
+ // the inline body editor owns the pane and every key while open
1054
+ if (bodyEditing.editing) return;
1055
+ // the share dialog owns its own keys while open; the shell grammar stands down
1056
+ if (shareDialogOpen) return;
1057
+ if (menuModalHandled(menuControl, key)) return;
1058
+ if (paneCycleRequested(key, overlay, menuOwnsKeyboard, threadComposing)) {
1059
+ return cyclePanes(Boolean(key.shift));
1060
+ }
1061
+ if (
1062
+ threadsNavHandled({
1063
+ focusedPane,
1064
+ quiet: overlay === "none" && !menuOwnsKeyboard && !threadComposing,
1065
+ key,
1066
+ count: grouped.ordered.length,
1067
+ setInboxCursor,
1068
+ openSession: () => dispatch({ type: "openSession" }),
1069
+ })
1070
+ )
1071
+ return;
1072
+ if (threadSurfaceHandledKey(key)) return;
1073
+ // A compose textarea owns the keyboard while open: let it receive the typed note instead of the
1074
+ // global keymap acting on each letter (the prototype, and the bare-shell welcome playground).
1075
+ if (prototypeComposing || welcomeComposing) return;
1076
+ if (menuDialog === "settings") return void handleSettingsKey(key.name);
1077
+ if (menuDialog) return void (key.name === "escape" && setMenuDialog(null));
1078
+ // the toast is non-modal: escape only dismisses it when nothing else owns
1079
+ // escape, so an open overlay (compose, submit, prompt, walk) still cancels
1080
+ if (toastDismissRequested(toast !== null, key, overlay, mode.type === "span"))
1081
+ return controller.dismissToast();
1082
+ if (bareShellDefersKeys(session === null, overlay === "none", focusedPane)) return;
1083
+ const state = buildKeyState({
1084
+ keys: keysRef.current,
1085
+ observer,
1086
+ isOwner,
1087
+ overlay,
1088
+ session,
1089
+ isDiff,
1090
+ mode,
1091
+ resolved,
1092
+ inbox,
1093
+ focusedAnnotationId,
1094
+ walk,
1095
+ walkFileList,
1096
+ rows,
1097
+ cursor,
1098
+ display,
1099
+ });
1100
+
1101
+ keyBindings.setContext({
1102
+ overlay: state.overlay,
1103
+ spanMode: state.spanMode,
1104
+ });
1105
+ const action = keyBindings.resolveAction({
1106
+ name: key.name,
1107
+ shift: !!key.shift,
1108
+ });
1109
+
1110
+ for (const intent of reduceKey(
1111
+ state,
1112
+ { name: key.name, shift: !!key.shift, meta: !!key.meta },
1113
+ action,
1114
+ ))
1115
+ dispatch(intent);
1116
+ });
1117
+
1118
+ // after every keyboard hook above, so their subscriptions precede the signal
1119
+ useReadySignal(usableScreenReached(error, session, inbox), onReady);
1120
+
1121
+ // ── shared bottom chrome: the menu bar and its drop-up dialogs, one render
1122
+ // reused by the inbox and by plan/diff review so the two never drift ──
1123
+ const menuChrome = (
1124
+ <MenuChrome
1125
+ menuDialog={menuDialog}
1126
+ theme={theme}
1127
+ keybindsSections={cheatsheetFor(keyBindings, threadViewActive)}
1128
+ settingsCategories={settingsCategories}
1129
+ settingsValues={settingsValues}
1130
+ settingsNav={settingsNav}
1131
+ onCategorySelect={onCategorySelect}
1132
+ cycleSetting={cycleSetting}
1133
+ onClose={() => setMenuDialog(null)}
1134
+ />
1135
+ );
1136
+
1137
+ // ── render ──────────────────────────────────
1138
+ if (error) return <ErrorScreen error={error} theme={theme} />;
1139
+ if (!session)
1140
+ return inbox ? (
1141
+ <SlashSkillsContext.Provider value={skills}>
1142
+ <PaletteNamesContext.Provider value={paletteNames}>
1143
+ <NoThreadShell
1144
+ toast={toast}
1145
+ extensionRegistry={extensionRegistry}
1146
+ extensionContext={extensionContext(cwd, null)}
1147
+ rows={grouped.rows}
1148
+ inboxCursor={inboxCursor}
1149
+ onOpenThread={openThread}
1150
+ onCreateThread={createEmptyThread}
1151
+ mode={mode}
1152
+ theme={theme}
1153
+ controller={controller}
1154
+ setMode={setMode}
1155
+ menuChrome={menuChrome}
1156
+ onOpenMenu={openSettings}
1157
+ sidebarOpen={sidebarOpen}
1158
+ onToggleSidebar={() => setSidebarOpen((open) => !open)}
1159
+ focusedPane={focusedPane}
1160
+ onFocusPane={setFocusedPane}
1161
+ menuControl={menuControl}
1162
+ pinnedIds={pinnedIds}
1163
+ onPin={togglePin}
1164
+ onRename={(id, title) => setMode({ type: "renameThread", sessionId: id, text: title })}
1165
+ quickActions={quickActions}
1166
+ diffView={diffView}
1167
+ onWelcomeComposingChange={setWelcomeComposing}
1168
+ layout={layout}
1169
+ />
1170
+ </PaletteNamesContext.Provider>
1171
+ </SlashSkillsContext.Provider>
1172
+ ) : (
1173
+ <ConnectingScreen theme={theme} />
1174
+ );
1175
+
1176
+ const activeSession = session;
1177
+ const resolveAuthorLabel = authorLabelResolver(
1178
+ identity.name,
1179
+ activeSession.participants,
1180
+ authorNames,
1181
+ );
1182
+
1183
+ if (isCompletionOverlayPhase(completion) && activeSession.message)
1184
+ return (
1185
+ <CompletionScreen
1186
+ theme={theme}
1187
+ session={activeSession}
1188
+ message={activeSession.message.outcome}
1189
+ completion={completion}
1190
+ status={status}
1191
+ onClose={() => dispatch({ type: "finishReview" })}
1192
+ onBackToPlan={() => dispatch({ type: "dismissCompletion" })}
1193
+ onAlways={() => dispatch({ type: "optInAutoClose" })}
1194
+ />
1195
+ );
1196
+
1197
+ const diffFold: DiffFoldControls = {
1198
+ isCollapsed: (file) => controller.isFileCollapsed(file),
1199
+ isExpanded: (file) => controller.isFileExpanded(file),
1200
+ canExpand: (file) => controller.canExpandFile(file),
1201
+ onToggleCollapse: (file) =>
1202
+ controller.setFileCollapsed(file, !controller.isFileCollapsed(file)),
1203
+ onToggleExpand: (file) => controller.setFileExpanded(file, !controller.isFileExpanded(file)),
1204
+ onCopyPath: (file) => controller.copyFilePath(file),
1205
+ };
1206
+ const submitConfirmState = buildSubmitConfirmState({
1207
+ mode,
1208
+ isDiff,
1209
+ session: activeSession,
1210
+ walkFileList,
1211
+ viewedPaths,
1212
+ quickActions,
1213
+ liveInput,
1214
+ setMode,
1215
+ dispatch,
1216
+ });
1217
+ const { showOwnerActions, showDiffRefresh, prototypeCanComment, chromeHidden, prototypePath } =
1218
+ buildRenderFlags({
1219
+ session: activeSession,
1220
+ isOwner,
1221
+ isDiff,
1222
+ isPixelPrototype,
1223
+ resolved,
1224
+ menuDialog,
1225
+ resolvedIds,
1226
+ });
1227
+
1228
+ const onEditRequest = (): void => {
1229
+ // A share viewer/observer has no Edit affordance (the button is hidden), so
1230
+ // this is owner-only; stay silent rather than nag if it is ever reached.
1231
+ if (!isOwner) return;
1232
+ if (resolved) return controller.setStatus("review submitted - read-only");
1233
+ openBodyEditor();
1234
+ };
1235
+
1236
+ // clicking the rail Submit button: same read-only answer as the submit key
1237
+ const onSubmitRequest = (): void => {
1238
+ if (observer) return controller.setStatus("observer - read-only");
1239
+ if (!isOwner) return controller.setStatus("shared view - your notes save as you go");
1240
+ if (resolved) return;
1241
+ dispatch({ type: "openSubmit" });
1242
+ };
1243
+
1244
+ const threadFooter = (
1245
+ <ThreadFooter
1246
+ controls={threadAgentControls(agentActive, agentControls)}
1247
+ repo={projectName(activeSession.workspace)}
1248
+ branch={activeSession.workspace.branch}
1249
+ onSubmit={onSubmitRequest}
1250
+ canSubmit={canSubmitReview(isOwner, resolved, observer)}
1251
+ pendingAnnotations={
1252
+ activeSession.annotations.filter(
1253
+ (annotation) => !isAddressed(annotation) && !isAgentNote(annotation),
1254
+ ).length
1255
+ }
1256
+ theme={theme}
1257
+ />
1258
+ );
1259
+
1260
+ return (
1261
+ <SlashSkillsContext.Provider value={skills}>
1262
+ <PaletteNamesContext.Provider value={paletteNames}>
1263
+ <ThemeProvider theme={theme}>
1264
+ <MenuControlProvider value={menuControl}>
1265
+ <AppShell
1266
+ extensionRegistry={extensionRegistry}
1267
+ extensionContext={{
1268
+ workspace: activeSession.workspace.repoRoot,
1269
+ threadId: activeSession.id,
1270
+ }}
1271
+ onExtensionError={showExtensionError}
1272
+ sidebarOpen={sidebarOpen}
1273
+ onToggleSidebar={() => setSidebarOpen((open) => !open)}
1274
+ onOpenMenu={openSettings}
1275
+ onFocusPane={setFocusedPane}
1276
+ focusedPane={focusedPane}
1277
+ threadsPanel={
1278
+ <scrollbox style={{ flexGrow: 1 }} focused={false}>
1279
+ <ThreadTree
1280
+ rows={grouped.rows}
1281
+ cursor={inboxCursor}
1282
+ activeId={activeSession.id}
1283
+ focused={focusedPane === "threads"}
1284
+ pinnedIds={pinnedIds}
1285
+ width={30}
1286
+ onSelect={openThread}
1287
+ onCreateThread={createEmptyThread}
1288
+ onPin={togglePin}
1289
+ onRename={(id, title) =>
1290
+ setMode({ type: "renameThread", sessionId: id, text: title })
1291
+ }
1292
+ onRequestDelete={(id, title) =>
1293
+ setMode({ type: "confirmDelete", sessionId: id, title })
1294
+ }
1295
+ theme={theme}
1296
+ />
1297
+ </scrollbox>
1298
+ }
1299
+ threadTitle={reviewThreadTitle(activeSession)}
1300
+ threadActions={
1301
+ <>
1302
+ {showOwnerActions
1303
+ ? ownerThreadActions({
1304
+ editing: bodyEditing.editing,
1305
+ onEdit: onEditRequest,
1306
+ onExitEdit: bodyEditing.requestExit,
1307
+ onShare: () => dispatch({ type: "share" }),
1308
+ theme,
1309
+ })
1310
+ : showDiffRefresh
1311
+ ? refreshDiffAction(() => void controller.refreshDiff(), theme)
1312
+ : undefined}
1313
+ </>
1314
+ }
1315
+ threadPanel={
1316
+ <box style={{ flexGrow: 1, flexDirection: "column" }}>
1317
+ <box style={{ flexGrow: 1, flexDirection: "row" }}>
1318
+ <AgentThreadPrototype
1319
+ key={activeSession.id}
1320
+ client={agentClient}
1321
+ enabled={canRunThreadAgent({
1322
+ enabled: threadAgentEnabled,
1323
+ owner: isOwner,
1324
+ editing: bodyEditing.editing,
1325
+ shared: isSharedThreadConnection(openClient, shareTransport),
1326
+ sharedAgent: sharedAgentAvailable(agentClient, activeSession),
1327
+ })}
1328
+ observer={observer}
1329
+ pixelPrototype={isPixelPrototype}
1330
+ thread={activeSession}
1331
+ home={home}
1332
+ theme={theme}
1333
+ focused={focusedPane === "thread"}
1334
+ suspended={threadViewSuspended}
1335
+ onActiveChange={setAgentActive}
1336
+ onControlsChange={setAgentControls}
1337
+ onStateChange={setAgentState}
1338
+ onActionsChange={(actions) => {
1339
+ agentActions.current = actions;
1340
+ }}
1341
+ onInvokeChange={(invoke) => {
1342
+ agentInvoke.current = invoke;
1343
+ }}
1344
+ onRevealReply={() => setFocusedPane("thread")}
1345
+ flushMutations={() => flushReviewMutations(controller)}
1346
+ onOpenFile={(path) => workbench.openFile(path, "contents", true)}
1347
+ onNextPane={cyclePanes}
1348
+ >
1349
+ {chooseThreadBody({
1350
+ isPixelPrototype,
1351
+ isDiff,
1352
+ editingBody: bodyEditing.editing,
1353
+ prototype: (
1354
+ <PrototypePixels
1355
+ prototypePath={prototypePath}
1356
+ canComment={prototypeCanComment}
1357
+ onCommentElement={onCommentPrototype}
1358
+ onComposingChange={setPrototypeComposing}
1359
+ hidden={chromeHidden}
1360
+ />
1361
+ ),
1362
+ diffPlaceholder: activeSession.artifact.meta.prBrief ? (
1363
+ <ThreadView
1364
+ session={pullRequestBriefThread(activeSession)}
1365
+ display={buildDisplay(activeSession.artifact.meta.prBrief)}
1366
+ marks={new Map()}
1367
+ quickActions={quickActions}
1368
+ suspended={threadViewSuspended}
1369
+ resolved
1370
+ observer
1371
+ onComposingChange={() => {}}
1372
+ onObserverBlocked={() => {}}
1373
+ onCursorChange={() => {}}
1374
+ onAnnotate={() => {}}
1375
+ onReply={() => {}}
1376
+ onUpdateAnnotation={() => {}}
1377
+ resolveAuthorLabel={() => undefined}
1378
+ onExit={() => onExit?.(0)}
1379
+ />
1380
+ ) : (
1381
+ <box
1382
+ style={{
1383
+ flexGrow: 1,
1384
+ flexDirection: "column",
1385
+ alignItems: "center",
1386
+ justifyContent: "center",
1387
+ }}
1388
+ >
1389
+ <text fg={theme.textDim}>Select a thread</text>
1390
+ </box>
1391
+ ),
1392
+ editor: bodyEditing.renderEditor(theme),
1393
+ threadView: (
1394
+ <ThreadView
1395
+ session={activeSession}
1396
+ suspended={surfaceSuspended(threadViewSuspended, focusedPane, "thread")}
1397
+ editOrphanCount={editOrphanCount}
1398
+ onComposingChange={setThreadComposing}
1399
+ onNavCommand={runNavCommand}
1400
+ resolved={resolved}
1401
+ onObserverBlocked={(reason) =>
1402
+ controller.setStatus(
1403
+ reason === "observer"
1404
+ ? "observer - read-only"
1405
+ : "review submitted - read-only",
1406
+ )
1407
+ }
1408
+ onCursorChange={setCursor}
1409
+ focusedAnnotationId={focusedAnnotationId}
1410
+ onFocusAnnotation={setFocusedAnnotationId}
1411
+ display={display}
1412
+ marks={marks}
1413
+ quickActions={quickActions}
1414
+ observer={observer}
1415
+ onAnnotate={(span, body) =>
1416
+ controller.annotate(
1417
+ "comment",
1418
+ span.start.blockIndex,
1419
+ span.start.char,
1420
+ span.end.char,
1421
+ body,
1422
+ span.end.blockIndex,
1423
+ )
1424
+ }
1425
+ onReply={(rootAnnotationId, body) =>
1426
+ controller.reply(rootAnnotationId, body)
1427
+ }
1428
+ onUpdateAnnotation={(id, body) => controller.updateAnnotation(id, body)}
1429
+ resolveAuthorLabel={resolveAuthorLabel}
1430
+ onExit={() => onExit?.(0)}
1431
+ />
1432
+ ),
1433
+ })}
1434
+ </AgentThreadPrototype>
1435
+ </box>
1436
+ {threadFooter}
1437
+ </box>
1438
+ }
1439
+ changesOpen={workbench.changesOpen}
1440
+ projectOpen={workbench.projectOpen}
1441
+ onToggleChanges={workbench.toggleChanges}
1442
+ onToggleProject={workbench.toggleProject}
1443
+ onToggleRight={workbench.toggleRight}
1444
+ projectMode={workbench.projectMode}
1445
+ zoomHideThread={workbench.zoomed}
1446
+ changesFooter={threadFooter}
1447
+ changesPanel={
1448
+ <EditorGrid
1449
+ tree={workbench.grid}
1450
+ focusedGroupId={workbench.activeGroup}
1451
+ commentCounts={diffCommentCounts}
1452
+ onFocusGroup={workbench.focusGroup}
1453
+ onActivateTab={workbench.activate}
1454
+ onKeepTab={workbench.keepTab}
1455
+ onCloseTab={workbench.close}
1456
+ onSplit={workbench.split}
1457
+ onZoom={workbench.toggleZoom}
1458
+ zoomed={workbench.zoomed}
1459
+ renderTab={(tab, groupFocused) => (
1460
+ <GridTabContent
1461
+ tab={tab}
1462
+ rows={rows}
1463
+ surface={{
1464
+ session: activeSession,
1465
+ quickActions,
1466
+ observer,
1467
+ commentsEnabled: true,
1468
+ resolved,
1469
+ suspended: surfaceSuspended(
1470
+ threadViewSuspended || !groupFocused,
1471
+ focusedPane,
1472
+ "changes",
1473
+ ),
1474
+ onComposingChange: setThreadComposing,
1475
+ onObserverBlocked: (reason) =>
1476
+ controller.setStatus(
1477
+ reason === "observer"
1478
+ ? "observer - read-only"
1479
+ : "review submitted - read-only",
1480
+ ),
1481
+ onCursorChange: setCursor,
1482
+ focusedAnnotationId,
1483
+ onFocusAnnotation: setFocusedAnnotationId,
1484
+ // a diff thread's Changes view is the artifact itself; any other thread's is the
1485
+ // live working-tree diff, so its notes carry a file target and anchor there
1486
+ onAnnotate: (span, body) =>
1487
+ void controller.annotate(
1488
+ "comment",
1489
+ span.start.blockIndex,
1490
+ span.start.char,
1491
+ span.end.char,
1492
+ body,
1493
+ span.end.blockIndex,
1494
+ isDiff
1495
+ ? { kind: "artifact" }
1496
+ : { kind: "file", path: "", rev: "worktree" },
1497
+ ),
1498
+ onReply: (rootAnnotationId, body) =>
1499
+ void controller.reply(rootAnnotationId, body),
1500
+ onUpdateAnnotation: (id, body) => controller.updateAnnotation(id, body),
1501
+ onInvoke: agentActive
1502
+ ? () => {
1503
+ agentInvoke.current?.();
1504
+ setFocusedPane("thread");
1505
+ }
1506
+ : undefined,
1507
+ annotationAction: (id) => agentActions.current(id),
1508
+ isAnnotationReadOnly: (id) =>
1509
+ isSubmittedComment(agentState, activeSession.id, id),
1510
+ resolveAuthorLabel,
1511
+ onNavCommand: runNavCommand,
1512
+ onExit: () => onExit?.(0),
1513
+ }}
1514
+ rejectedRows={rejectedRows}
1515
+ fold={diffFold}
1516
+ fileStats={controller.fileStats()}
1517
+ split={diffView === "split" && workbench.zoomed}
1518
+ dimmed={walking}
1519
+ readFile={(path) => controller.repoReadFile(path)}
1520
+ onAddFileComment={(path, anchor, body) =>
1521
+ void controller.addComment(
1522
+ anchor,
1523
+ { kind: "file", path, rev: "worktree" },
1524
+ body,
1525
+ )
1526
+ }
1527
+ // zoomed, the footer already rides the Changes pane, so no extra offset is needed
1528
+ emptyBottomPadding={workbench.zoomed ? 0 : THREAD_FOOTER_HEIGHT}
1529
+ theme={theme}
1530
+ />
1531
+ )}
1532
+ theme={theme}
1533
+ />
1534
+ }
1535
+ projectPanel={
1536
+ <ProjectPanelBody
1537
+ mode={workbench.projectMode}
1538
+ loadChanges={() => controller.repoChanges()}
1539
+ initialFiles={initialReviewFiles(
1540
+ initialReviewForFirstMount.current,
1541
+ activeSession.id,
1542
+ )}
1543
+ loadProjectFiles={() => controller.repoFiles()}
1544
+ diffSourceKey={activeSession.id}
1545
+ {...projectDiffFiles(activeSession)}
1546
+ // the Changes navigator always opens a changed file as a diff - a diff review shows its
1547
+ // captured snapshot, every other thread the live working-tree diff
1548
+ onOpenChangedFile={(path, persistent) =>
1549
+ workbench.openFile(path, "diff", persistent)
1550
+ }
1551
+ onOpenProjectFile={(path, persistent) =>
1552
+ workbench.openFile(path, "contents", persistent)
1553
+ }
1554
+ commentCounts={diffCommentCounts}
1555
+ focused={focusedPane === "project"}
1556
+ theme={theme}
1557
+ />
1558
+ }
1559
+ theme={theme}
1560
+ >
1561
+ <TrailingOverlays
1562
+ walking={walking}
1563
+ walk={walk}
1564
+ walkFileList={walkFileList}
1565
+ viewedPaths={viewedPaths}
1566
+ session={activeSession}
1567
+ terminalWidth={terminalWidth}
1568
+ theme={theme}
1569
+ mode={mode}
1570
+ toast={toast}
1571
+ onDismissToast={() => controller.dismissToast()}
1572
+ setMode={setMode}
1573
+ dispatch={dispatch}
1574
+ />
1575
+ {submitConfirmState !== null ? (
1576
+ <box
1577
+ onMouseUp={submitConfirmState.onCancel}
1578
+ style={{
1579
+ position: "absolute",
1580
+ left: 0,
1581
+ top: 0,
1582
+ width: "100%",
1583
+ height: "100%",
1584
+ justifyContent: "center",
1585
+ alignItems: "center",
1586
+ }}
1587
+ >
1588
+ <box onMouseUp={(event) => event.stopPropagation()}>
1589
+ <ConfirmCard {...submitConfirmState} theme={theme} />
1590
+ </box>
1591
+ </box>
1592
+ ) : null}
1593
+ <ShareDialog
1594
+ key={String(shareDialogOpen)}
1595
+ isOpen={shareDialogOpen}
1596
+ threadName={shareThreadName(session)}
1597
+ links={shareLinksFor(session)}
1598
+ isOwner={isOwner}
1599
+ agentAvailable={canRunThreadAgent({
1600
+ enabled: threadAgentEnabled,
1601
+ owner: isOwner,
1602
+ editing: false,
1603
+ shared: isSharedThreadConnection(openClient, shareTransport),
1604
+ })}
1605
+ onCreateLink={(input) => controller.createShareLink(input)}
1606
+ onUpdateLink={(id, input) => controller.updateShareLink(id, input)}
1607
+ onDeleteLink={(id) => controller.deleteShareLink(id)}
1608
+ onCopyLink={(id) => controller.copyShareLink(id)}
1609
+ onClose={() => setShareDialogOpen(false)}
1610
+ theme={theme}
1611
+ />
1612
+ {menuChrome}
1613
+ </AppShell>
1614
+ </MenuControlProvider>
1615
+ </ThemeProvider>
1616
+ </PaletteNamesContext.Provider>
1617
+ </SlashSkillsContext.Provider>
1618
+ );
1619
+ }
1620
+
1621
+ function enabledThreadAction(enabled: boolean, action: () => void): (() => void) | undefined {
1622
+ return enabled ? action : undefined;
1623
+ }
1624
+
1625
+ /** Experimental agent UI is available only in a local owner's review. */
1626
+ export function canRunThreadAgent(options: {
1627
+ enabled: boolean;
1628
+ owner: boolean;
1629
+ editing: boolean;
1630
+ shared: boolean;
1631
+ sharedAgent?: boolean;
1632
+ }): boolean {
1633
+ if (options.editing) return false;
1634
+
1635
+ return Boolean(options.sharedAgent || (options.enabled && options.owner && !options.shared));
1636
+ }
1637
+
1638
+ function sharedAgentAvailable(client: AppProps["agentClient"], thread: Thread): boolean {
1639
+ return Boolean(client && thread.shares?.[0]?.agentEnabled);
1640
+ }
1641
+
1642
+ function isSubmittedComment(
1643
+ state: import("@cueloop/schema").ThreadAgentState | undefined,
1644
+ threadId: string,
1645
+ commentId: string,
1646
+ ): boolean {
1647
+ return (
1648
+ state?.threadId === threadId &&
1649
+ Boolean(state.submissions?.some((entry) => entry.commentId === commentId))
1650
+ );
1651
+ }
1652
+
1653
+ function flushReviewMutations(controller: ReviewController): Promise<void> {
1654
+ return controller.flushMutations?.() ?? Promise.resolve();
1655
+ }
1656
+
1657
+ function threadAgentControls(active: boolean, controls: React.ReactNode): React.ReactNode {
1658
+ return active ? controls : undefined;
1659
+ }
1660
+
1661
+ /** Injected shared transports never own a local harness connection. */
1662
+ function isSharedThreadConnection(
1663
+ openClient: AppProps["openClient"],
1664
+ shareTransport: ShareTransport | undefined,
1665
+ ): boolean {
1666
+ return Boolean(openClient || shareTransport);
1667
+ }