@north-light/cli 0.3.707 → 0.3.709

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 (278) hide show
  1. package/dist/api/client.d.ts +1 -2
  2. package/dist/api/client.js +3 -3
  3. package/dist/api/contract.d.ts +1 -1
  4. package/dist/api/contract.js +1 -1
  5. package/dist/api/dto/crons.d.ts +3 -0
  6. package/dist/api/dto/human.d.ts +9 -6
  7. package/dist/api/dto/inbox.d.ts +2 -0
  8. package/dist/api/dto/review-comments.d.ts +12 -35
  9. package/dist/api/dto/reviews.d.ts +3 -10
  10. package/dist/api/routes.d.ts +0 -1
  11. package/dist/api/routes.js +1 -1
  12. package/dist/builtin-memory/05-kinds/review/companion/00-base.md +2 -2
  13. package/dist/builtin-memory/crouter-sdk/release-notes.md +6 -0
  14. package/dist/clients/attach/chrome/canvas-panels.d.ts +1 -1
  15. package/dist/clients/attach/chrome/canvas-panels.js +1 -1
  16. package/dist/clients/attach/chrome/inbox-strip.js +1 -1
  17. package/dist/clients/attach/chrome/roster.js +6 -6
  18. package/dist/clients/attach/chrome/status-line.d.ts +1 -1
  19. package/dist/clients/attach/chrome/status-line.js +1 -1
  20. package/dist/clients/attach/chrome/ticket-panel.js +1 -1
  21. package/dist/clients/attach/input/capabilities.js +1 -1
  22. package/dist/clients/attach/input/controller.d.ts +4 -1
  23. package/dist/clients/attach/input/controller.js +3 -3
  24. package/dist/clients/attach/input/overlay-owner.d.ts +0 -1
  25. package/dist/clients/attach/input/overlay-owner.js +1 -1
  26. package/dist/clients/attach/overlays/graph.d.ts +3 -2
  27. package/dist/clients/attach/overlays/graph.js +1 -1
  28. package/dist/clients/attach/render/chat-view.d.ts +2 -0
  29. package/dist/clients/attach/render/chat-view.js +1 -1
  30. package/dist/clients/attach/render/doc-links.d.ts +1 -1
  31. package/dist/clients/attach/session/chrome-refresh.js +1 -1
  32. package/dist/clients/attach/session/connection.d.ts +10 -9
  33. package/dist/clients/attach/session/connection.js +1 -1
  34. package/dist/clients/attach/session/context.d.ts +1 -1
  35. package/dist/clients/attach/session/document-links.d.ts +1 -1
  36. package/dist/clients/attach/session/document-links.js +1 -1
  37. package/dist/clients/attach/session/identity.d.ts +2 -0
  38. package/dist/clients/attach/session/identity.js +1 -1
  39. package/dist/clients/attach/session/input-wiring.d.ts +2 -0
  40. package/dist/clients/attach/session/input-wiring.js +1 -1
  41. package/dist/clients/attach/session/keys.d.ts +2 -2
  42. package/dist/clients/attach/session/keys.js +1 -1
  43. package/dist/clients/attach/session/pane-tag.d.ts +3 -1
  44. package/dist/clients/attach/session/pane-tag.js +1 -1
  45. package/dist/clients/attach/session/reconnect.js +1 -1
  46. package/dist/clients/attach/session/surface-host.d.ts +0 -5
  47. package/dist/clients/attach/session/surface-host.js +1 -1
  48. package/dist/clients/attach/session/teardown.d.ts +2 -2
  49. package/dist/clients/attach/session/teardown.js +9 -7
  50. package/dist/clients/attach/viewer.d.ts +7 -5
  51. package/dist/clients/attach/viewer.js +571 -584
  52. package/dist/clients/editor-roundtrip.js +3 -0
  53. package/dist/clients/inbox/controller.d.ts +1 -6
  54. package/dist/clients/inbox/controller.js +1 -1
  55. package/dist/clients/inbox/dto-adapt.js +1 -1
  56. package/dist/clients/inbox/tui/page-body.js +1 -1
  57. package/dist/clients/inbox/tui/render.js +2 -2
  58. package/dist/clients/open-browser.d.ts +2 -0
  59. package/dist/clients/open-browser.js +1 -0
  60. package/dist/clients/surfaces/host.d.ts +0 -6
  61. package/dist/commands/human/review.js +1 -1
  62. package/dist/commands/node/wait.js +2 -6
  63. package/dist/commands/sys/context/admin/shell.js +1 -1
  64. package/dist/core/broker-client/client.d.ts +6 -3
  65. package/dist/core/broker-client/client.js +1 -1
  66. package/dist/core/canvas/crons.d.ts +11 -1
  67. package/dist/core/canvas/crons.js +14 -14
  68. package/dist/core/canvas/executions.js +1 -1
  69. package/dist/core/canvas/schema-pg/025-review-anchors.sql +19 -0
  70. package/dist/core/canvas/schema-pg/026-cron-deadline-body.sql +9 -0
  71. package/dist/core/canvas/schema-pg/027-cron-fires.sql +4 -0
  72. package/dist/core/canvas/schema-version.d.ts +1 -1
  73. package/dist/core/canvas/schema-version.js +1 -1
  74. package/dist/core/command.js +5 -5
  75. package/dist/core/feed/messages.d.ts +5 -0
  76. package/dist/core/feed/messages.js +5 -5
  77. package/dist/core/human/page-markdown.js +10 -12
  78. package/dist/core/human/tickets.js +1 -1
  79. package/dist/core/human/types.d.ts +4 -6
  80. package/dist/core/keybindings/attach-control.d.ts +0 -3
  81. package/dist/core/keybindings/attach-control.js +1 -1
  82. package/dist/core/keybindings/catalog.d.ts +1 -1
  83. package/dist/core/keybindings/catalog.js +1 -1
  84. package/dist/core/review/anchors.d.ts +28 -0
  85. package/dist/core/review/anchors.js +6 -0
  86. package/dist/core/review/comments.d.ts +2 -2
  87. package/dist/core/review/comments.js +7 -8
  88. package/dist/core/review/companion.d.ts +2 -1
  89. package/dist/core/review/companion.js +1 -1
  90. package/dist/core/review/document.d.ts +4 -17
  91. package/dist/core/review/document.js +1 -2
  92. package/dist/core/review/fork.js +2 -4
  93. package/dist/core/review/project.d.ts +1 -1
  94. package/dist/core/review/project.js +2 -2
  95. package/dist/core/review/realize.js +1 -1
  96. package/dist/core/review/stage.d.ts +2 -9
  97. package/dist/core/review/stage.js +1 -1
  98. package/dist/core/review/types.d.ts +16 -12
  99. package/dist/core/review/types.js +1 -1
  100. package/dist/core/runtime/bearings.js +4 -4
  101. package/dist/core/runtime/boot-root.js +4 -4
  102. package/dist/core/runtime/broker-cli.js +3 -3
  103. package/dist/core/runtime/broker-extension-render.js +1 -1
  104. package/dist/core/runtime/lifecycle.js +2 -2
  105. package/dist/core/runtime/revive.js +2 -2
  106. package/dist/core/runtime/runner/blaxel/client.d.ts +4 -0
  107. package/dist/core/runtime/runner/blaxel/client.js +1 -1
  108. package/dist/core/runtime/runner/blaxel/runner.d.ts +2 -3
  109. package/dist/core/runtime/runner/blaxel/runner.js +3 -3
  110. package/dist/core/runtime/runner/delete-sandboxes.d.ts +5 -0
  111. package/dist/core/runtime/runner/delete-sandboxes.js +6 -1
  112. package/dist/core/runtime/runner/types.d.ts +19 -3
  113. package/dist/core/runtime/tmux-bindings.js +3 -3
  114. package/dist/daemon/api/bridge.d.ts +5 -0
  115. package/dist/daemon/api/bridge.js +3 -3
  116. package/dist/daemon/api/canvas-host.js +1 -1
  117. package/dist/daemon/api/document-page.d.ts +12 -1
  118. package/dist/daemon/api/document-page.js +6 -6
  119. package/dist/daemon/api/handlers/crons.d.ts +2 -0
  120. package/dist/daemon/api/handlers/crons.js +1 -1
  121. package/dist/daemon/api/handlers/inbox.js +1 -1
  122. package/dist/daemon/api/handlers/nodes.js +1 -1
  123. package/dist/daemon/api/handlers/review-comments.js +1 -1
  124. package/dist/daemon/api/handlers/reviews.js +1 -1
  125. package/dist/daemon/api/map.js +2 -2
  126. package/dist/daemon/api/operations.js +1 -1
  127. package/dist/daemon/api/review-page.d.ts +3 -0
  128. package/dist/daemon/api/review-page.js +13 -0
  129. package/dist/daemon/broker-memory-cap.d.ts +9 -0
  130. package/dist/daemon/broker-memory-cap.js +2 -0
  131. package/dist/daemon/broker-signals/bus.d.ts +1 -1
  132. package/dist/daemon/broker-signals/bus.js +1 -1
  133. package/dist/daemon/cron/ended.d.ts +3 -0
  134. package/dist/daemon/cron/ended.js +2 -2
  135. package/dist/daemon/cron/lease-recovery.js +1 -1
  136. package/dist/daemon/cron/machine-fire.d.ts +9 -2
  137. package/dist/daemon/cron/machine-fire.js +1 -1
  138. package/dist/daemon/cron/passes.js +1 -1
  139. package/dist/daemon/cron-run.js +2 -2
  140. package/dist/daemon/crtrd.js +14 -14
  141. package/dist/daemon/machine-daemon.js +1 -1
  142. package/dist/daemon/machine-link/client.js +1 -1
  143. package/dist/daemon/reconcilers/fault-retry-backstop.js +1 -1
  144. package/dist/daemon/reconcilers/idle-sandbox.d.ts +1 -1
  145. package/dist/daemon/reconcilers/idle-sandbox.js +2 -2
  146. package/dist/daemon/reconcilers/node-lifecycle/remote-wake.js +2 -2
  147. package/dist/daemon/review/comment-notify.js +2 -2
  148. package/dist/daemon/review/deliver.d.ts +2 -2
  149. package/dist/daemon/review/deliver.js +6 -2
  150. package/dist/daemon/review/finish.js +1 -1
  151. package/dist/doc-editor/Geist-Variable.woff2 +0 -0
  152. package/dist/doc-editor/GeistMono-Variable.woff2 +0 -0
  153. package/dist/doc-editor/editor.css +1 -1
  154. package/dist/doc-editor/review.css +2 -0
  155. package/dist/doc-editor/review.js +149 -0
  156. package/dist/pi-extensions/canvas-review-boundary.js +3 -3
  157. package/docs/sdk/release-notes.md +6 -0
  158. package/package.json +13 -4
  159. package/packages/crouter-api/dist/api/client.js +0 -3
  160. package/packages/crouter-api/dist/api/contract.js +1 -1
  161. package/packages/crouter-api/dist/api/routes.js +0 -1
  162. package/packages/crouter-api/dist/clients/attach/chrome/canvas-panels.js +3 -3
  163. package/packages/crouter-api/dist/clients/attach/chrome/inbox-strip.js +5 -5
  164. package/packages/crouter-api/dist/clients/attach/chrome/roster.js +17 -28
  165. package/packages/crouter-api/dist/clients/attach/chrome/status-line.js +2 -7
  166. package/packages/crouter-api/dist/clients/attach/chrome/ticket-panel.js +1 -1
  167. package/packages/crouter-api/dist/clients/attach/input/capabilities.js +2 -1
  168. package/packages/crouter-api/dist/clients/attach/input/controller.js +17 -3
  169. package/packages/crouter-api/dist/clients/attach/input/overlay-owner.js +0 -7
  170. package/packages/crouter-api/dist/clients/attach/overlays/graph.js +4 -3
  171. package/packages/crouter-api/dist/clients/attach/render/chat-view.js +9 -0
  172. package/packages/crouter-api/dist/clients/attach/session/chrome-refresh.js +6 -3
  173. package/packages/crouter-api/dist/clients/attach/session/connection.js +53 -53
  174. package/packages/crouter-api/dist/clients/attach/session/document-links.js +1 -1
  175. package/packages/crouter-api/dist/clients/attach/session/identity.js +1 -0
  176. package/packages/crouter-api/dist/clients/attach/session/input-wiring.js +4 -3
  177. package/packages/crouter-api/dist/clients/attach/session/keys.js +11 -5
  178. package/packages/crouter-api/dist/clients/attach/session/pane-tag.js +7 -1
  179. package/packages/crouter-api/dist/clients/attach/session/reconnect.js +3 -3
  180. package/packages/crouter-api/dist/clients/attach/session/surface-host.js +0 -17
  181. package/packages/crouter-api/dist/clients/attach/session/teardown.js +7 -4
  182. package/packages/crouter-api/dist/clients/attach/viewer.js +77 -67
  183. package/packages/crouter-api/dist/clients/{inbox/review/roundtrip.js → editor-roundtrip.js} +1 -1
  184. package/packages/crouter-api/dist/clients/inbox/controller.js +12 -31
  185. package/packages/crouter-api/dist/clients/inbox/dto-adapt.js +1 -0
  186. package/packages/crouter-api/dist/clients/inbox/tui/page-body.js +0 -7
  187. package/packages/crouter-api/dist/clients/inbox/tui/render.js +0 -7
  188. package/packages/crouter-api/dist/clients/open-browser.js +6 -0
  189. package/packages/crouter-api/dist/commands/human/review.js +17 -18
  190. package/packages/crouter-api/dist/commands/node/wait.js +2 -10
  191. package/packages/crouter-api/dist/commands/sys/context/admin/shell.js +1 -1
  192. package/packages/crouter-api/dist/core/broker-client/client.js +20 -10
  193. package/packages/crouter-api/dist/core/canvas/crons.js +26 -10
  194. package/packages/crouter-api/dist/core/canvas/executions.js +7 -2
  195. package/packages/crouter-api/dist/core/canvas/schema-version.js +1 -1
  196. package/packages/crouter-api/dist/core/command.js +3 -0
  197. package/packages/crouter-api/dist/core/feed/messages.js +15 -0
  198. package/packages/crouter-api/dist/core/human/page-markdown.js +2 -6
  199. package/packages/crouter-api/dist/core/human/tickets.js +2 -11
  200. package/packages/crouter-api/dist/core/keybindings/attach-control.js +0 -1
  201. package/packages/crouter-api/dist/core/keybindings/catalog.js +1 -3
  202. package/packages/crouter-api/dist/core/review/anchors.js +91 -0
  203. package/packages/crouter-api/dist/core/review/comments.js +27 -46
  204. package/packages/crouter-api/dist/core/review/companion.js +5 -9
  205. package/packages/crouter-api/dist/core/review/document.js +17 -89
  206. package/packages/crouter-api/dist/core/review/project.js +2 -1
  207. package/packages/crouter-api/dist/core/review/types.js +2 -2
  208. package/packages/crouter-api/dist/core/runtime/bearings.js +2 -2
  209. package/packages/crouter-api/dist/core/runtime/lifecycle.js +3 -0
  210. package/packages/crouter-api/dist/core/runtime/revive.js +5 -25
  211. package/packages/crouter-api/dist/core/runtime/runner/blaxel/client.js +15 -8
  212. package/packages/crouter-api/dist/core/runtime/runner/blaxel/runner.js +60 -19
  213. package/packages/crouter-api/dist/core/runtime/runner/delete-sandboxes.js +18 -2
  214. package/packages/crouter-api/dist/core/runtime/tmux-bindings.js +0 -5
  215. package/packages/crouter-api/dist/daemon/api/map.js +2 -6
  216. package/packages/crouter-api/dist/daemon/api/operations.js +2 -2
  217. package/packages/crouter-api/dist/daemon/broker-signals/bus.js +1 -1
  218. package/packages/crouter-api/dist/daemon/cron/ended.js +22 -11
  219. package/packages/crouter-api/dist/daemon/cron/machine-fire.js +69 -6
  220. package/packages/crouter-api/dist/daemon/reconcilers/node-lifecycle/remote-wake.js +2 -2
  221. package/packages/crouter-api/dist/daemon/review/deliver.js +4 -3
  222. package/packages/crouter-api/dist/daemon/review/finish.js +26 -47
  223. package/packages/crouter-api/package.json +1 -1
  224. package/packages/crouter-identity/package.json +1 -1
  225. package/packages/crouter-plugin/package.json +3 -3
  226. package/runtime.lock.json +1740 -505
  227. package/dist/clients/attach/overlays/file-review.d.ts +0 -10
  228. package/dist/clients/attach/overlays/file-review.js +0 -2
  229. package/dist/clients/inbox/review/anchors.d.ts +0 -41
  230. package/dist/clients/inbox/review/anchors.js +0 -1
  231. package/dist/clients/inbox/review/comments-client.d.ts +0 -74
  232. package/dist/clients/inbox/review/comments-client.js +0 -1
  233. package/dist/clients/inbox/review/companion-pane.d.ts +0 -47
  234. package/dist/clients/inbox/review/companion-pane.js +0 -1
  235. package/dist/clients/inbox/review/document-surface.d.ts +0 -212
  236. package/dist/clients/inbox/review/document-surface.js +0 -2
  237. package/dist/clients/inbox/review/frame.d.ts +0 -57
  238. package/dist/clients/inbox/review/frame.js +0 -1
  239. package/dist/clients/inbox/review/keys.d.ts +0 -69
  240. package/dist/clients/inbox/review/keys.js +0 -1
  241. package/dist/clients/inbox/review/launch.d.ts +0 -16
  242. package/dist/clients/inbox/review/launch.js +0 -1
  243. package/dist/clients/inbox/review/live-source.d.ts +0 -24
  244. package/dist/clients/inbox/review/live-source.js +0 -1
  245. package/dist/clients/inbox/review/nvim.d.ts +0 -15
  246. package/dist/clients/inbox/review/nvim.js +0 -1
  247. package/dist/clients/inbox/review/remap.d.ts +0 -51
  248. package/dist/clients/inbox/review/remap.js +0 -1
  249. package/dist/clients/inbox/review/review-client.d.ts +0 -43
  250. package/dist/clients/inbox/review/review-client.js +0 -1
  251. package/dist/clients/inbox/review/roundtrip.js +0 -3
  252. package/dist/clients/inbox/review/state.d.ts +0 -153
  253. package/dist/clients/inbox/review/state.js +0 -4
  254. package/dist/clients/inbox/review-adapter.d.ts +0 -17
  255. package/dist/clients/inbox/review-adapter.js +0 -1
  256. package/dist/core/review/remap.d.ts +0 -24
  257. package/dist/core/review/remap.js +0 -19
  258. package/dist/core/review/signal.d.ts +0 -5
  259. package/dist/core/review/signal.js +0 -1
  260. package/dist/core/runtime/starting-screen.d.ts +0 -12
  261. package/dist/core/runtime/starting-screen.js +0 -9
  262. package/packages/crouter-api/dist/clients/attach/overlays/file-review.js +0 -146
  263. package/packages/crouter-api/dist/clients/inbox/review/anchors.js +0 -89
  264. package/packages/crouter-api/dist/clients/inbox/review/comments-client.js +0 -103
  265. package/packages/crouter-api/dist/clients/inbox/review/companion-pane.js +0 -109
  266. package/packages/crouter-api/dist/clients/inbox/review/document-surface.js +0 -1268
  267. package/packages/crouter-api/dist/clients/inbox/review/frame.js +0 -309
  268. package/packages/crouter-api/dist/clients/inbox/review/keys.js +0 -133
  269. package/packages/crouter-api/dist/clients/inbox/review/launch.js +0 -170
  270. package/packages/crouter-api/dist/clients/inbox/review/live-source.js +0 -160
  271. package/packages/crouter-api/dist/clients/inbox/review/nvim.js +0 -43
  272. package/packages/crouter-api/dist/clients/inbox/review/remap.js +0 -157
  273. package/packages/crouter-api/dist/clients/inbox/review/review-client.js +0 -125
  274. package/packages/crouter-api/dist/clients/inbox/review/state.js +0 -315
  275. package/packages/crouter-api/dist/clients/inbox/review-adapter.js +0 -43
  276. package/packages/crouter-api/dist/core/review/signal.js +0 -12
  277. package/packages/crouter-api/dist/core/termrender/code-doc.js +0 -92
  278. /package/dist/clients/{inbox/review/roundtrip.d.ts → editor-roundtrip.d.ts} +0 -0
@@ -1,10 +0,0 @@
1
- import type { SurfaceHost } from '../../surfaces/host.js';
2
- import type { Picker } from './pickers.js';
3
- import { extractFilePaths } from '../../../core/human/visible-paths.js';
4
- export declare function buildFileReviewPicker(candidates: readonly string[], cwd: string, onChoose: (file: string) => void, close: () => void, notify: (message: string) => void): Picker;
5
- /** Open an inline review of a file path, or of a document given as `[[ref]]`. */
6
- export declare function launchFileReview(host: SurfaceHost, file: string, opts: {
7
- originNodeId: string;
8
- onNotice: (message: string) => void;
9
- }): Promise<void>;
10
- export { extractFilePaths };
@@ -1,2 +0,0 @@
1
- var v=Object.defineProperty;var c=(n,e)=>v(n,"name",{value:e,configurable:!0});import{homedir as a}from"node:os";import{isAbsolute as g,join as b,relative as S,resolve as y}from"node:path";import{Input as I,SelectList as d,getKeybindings as R}from"@earendil-works/pi-tui";import{getSelectListTheme as u}from"@earendil-works/pi-coding-agent";import{openReviewWindow as C}from"../../inbox/review/launch.js";import{createReviewClient as L,ReviewTerminalError as k,terminalRefusalNotice as x}from"../../inbox/review/review-client.js";import{checkReviewableFile as N,extractFilePaths as P}from"../../../core/human/visible-paths.js";import{docLinkText as F}from"../render/doc-links.js";const l=12;function h(n){const e=/^\[\[([^[\]\n]+)\]\]$/.exec(n.trim());return e===null?void 0:e[1].trim()}c(h,"documentRef");function m(n,e){const t=h(n);if(t!==void 0)return`${F(t)} (document)`;const i=S(e,n);if(i!==""&&!i.startsWith("..")&&!g(i))return i;const s=a();return n===s||n.startsWith(`${s}/`)?`~${n.slice(s.length)}`:n}c(m,"labelForPath");function f(n,e){const t=n==="~"?a():n.startsWith("~/")?b(a(),n.slice(2)):n;return y(e,t)}c(f,"resolveTypedPath");class W{static{c(this,"FileReviewPicker")}candidates;cwd;onChoose;close;notify;focused=!1;input=new I;list=new d([],l,u());constructor(e,t,i,s,o){this.candidates=e,this.cwd=t,this.onChoose=i,this.close=s,this.notify=o,this.input.onEscape=s,this.input.onSubmit=()=>this.chooseSelected(),this.refreshList()}render(e){this.input.focused=this.focused;const t=Math.max(1,e-8);return["Review a file or document named in this transcript",...this.input.render(t).map(i=>`Path: ${i}`),...this.list.render(e)]}handleInput(e){const t=R();if(t.matches(e,"tui.select.up")||t.matches(e,"tui.select.down")){this.list.handleInput(e);return}if(t.matches(e,"tui.select.confirm")||e===`
2
- `){this.chooseSelected();return}const i=this.input.getValue();this.input.handleInput(e),this.input.getValue()!==i&&this.refreshList()}invalidate(){this.input.invalidate(),this.list.invalidate()}refreshList(){const e=this.input.getValue(),t=e.toLowerCase(),i=this.candidates.filter(r=>{const w=m(r,this.cwd).toLowerCase();return t===""||w.includes(t)||r.toLowerCase().includes(t)}),s=e===""?void 0:h(e)!==void 0?e.trim():f(e,this.cwd),o=s!==void 0&&this.candidates.some(r=>r===s),p=[...i.map(r=>({value:r,label:m(r,this.cwd)})),...s!==void 0&&!o?[{value:s,label:`use ${JSON.stringify(e)}`,description:s}]:[]];this.list=new d(p,l,u()),this.list.onSelect=()=>this.chooseSelected(),this.list.onCancel=this.close}chooseSelected(){const e=this.input.getValue(),i=this.list.getSelectedItem()?.value??e;if(i==="")return;if(h(i)!==void 0){this.onChoose(i),this.close();return}const s=f(i,this.cwd),o=N(s);if(!o.ok){this.notify(o.reason);return}this.onChoose(s),this.close()}}function q(n,e,t,i,s){const o=new W(n,e,t,i,s);return{component:o,focus:o}}c(q,"buildFileReviewPicker");async function B(n,e,t){if(n.capabilities.remote){t.onNotice("The review is unavailable in a remote attach \u2014 the file and companion live on the host.");return}const i=h(e);let s;try{s=await L().createInline(i===void 0?{originNodeId:t.originNodeId,file:e}:{originNodeId:t.originNodeId,document:i})}catch(o){t.onNotice(o instanceof k?x(o):o instanceof Error?o.message:String(o));return}C(n,s)}c(B,"launchFileReview");export{q as buildFileReviewPicker,P as extractFilePaths,B as launchFileReview};
@@ -1,41 +0,0 @@
1
- import type { RenderedDoc } from '../../../core/termrender/termrender.js';
2
- /** One leaf anchor unit: the finest step j/k moves by. Consecutive rendered
3
- * rows sharing one source span collapse into a single unit that knows both
4
- * its source-line bounds and its rendered-row bounds. */
5
- export interface AnchorUnit {
6
- /** 1-indexed inclusive source-line bounds. */
7
- start: number;
8
- end: number;
9
- /** 0-indexed inclusive rendered-row bounds in the mapped doc. */
10
- firstRow: number;
11
- lastRow: number;
12
- }
13
- /** The anchorable shape of a rendered doc: ordered leaf units plus the
14
- * per-row owning-unit index the painter keys off. */
15
- export interface AnchorDoc {
16
- units: AnchorUnit[];
17
- /** Per rendered row: index into `units`, or null (separator rows). */
18
- rowUnits: (number | null)[];
19
- }
20
- /** Derive leaf anchor units from a mapped render: dedupe runs of consecutive
21
- * rows carrying the identical source span. A mapped row without a leaf span
22
- * (an unmapped block) anchors at its whole block's range, so every content
23
- * row belongs to a unit; separator rows belong to none. */
24
- export declare function deriveAnchorUnits(doc: RenderedDoc): AnchorDoc;
25
- /** Best unit for a source line: the NARROWEST unit containing it — code/table
26
- * chrome units carry their whole block's range and sit before the per-line
27
- * content units in rendered order, so "first whose end reaches the line"
28
- * would wrongly pick the chrome over the exact code line. A line no unit
29
- * contains (a blank separator) snaps forward to the next unit; past the end
30
- * clamps to the last. */
31
- export declare function unitIndexForLine(units: AnchorUnit[], line: number): number;
32
- /** Remap a unit from an old unit list into a re-derived one: an exact
33
- * source-range match wins (chrome and leaf units can share source lines),
34
- * else the best unit for its first line. */
35
- export declare function remapUnitIndex(units: AnchorUnit[], prev: AnchorUnit): number;
36
- /** First/last unit indices overlapping the source range `line..endLine`;
37
- * a range touching no unit snaps like unitIndexForLine. */
38
- export declare function unitRangeForSpan(units: AnchorUnit[], line: number, endLine: number): {
39
- lo: number;
40
- hi: number;
41
- };
@@ -1 +0,0 @@
1
- var h=Object.defineProperty;var a=(n,e)=>h(n,"name",{value:e,configurable:!0});function g(n){const e=[],r=new Array(n.lines.length).fill(null);for(let t=0;t<n.lines.length;t++){let l=n.spans[t]??null;if(l===null){const o=n.rows[t]??null,f=o!==null?n.blocks[o]:void 0;if(f===void 0)continue;l=[f.start,f.end]}const s=e[e.length-1];s!==void 0&&s.lastRow===t-1&&s.start===l[0]&&s.end===l[1]?s.lastRow=t:e.push({start:l[0],end:l[1],firstRow:t,lastRow:t}),r[t]=e.length-1}if(e.length===0){e.push({start:n.blocks[0]?.start??1,end:n.blocks[n.blocks.length-1]?.end??1,firstRow:0,lastRow:Math.max(0,n.lines.length-1)});for(let t=0;t<r.length;t++)r[t]=0}return{units:e,rowUnits:r}}a(g,"deriveAnchorUnits");function i(n,e){let r=-1;for(let t=0;t<n.length;t++){const l=n[t];l.start<=e&&l.end>=e&&(r===-1||l.end-l.start<n[r].end-n[r].start)&&(r=t)}if(r!==-1)return r;for(let t=0;t<n.length;t++)if(n[t].start>e)return t;return Math.max(0,n.length-1)}a(i,"unitIndexForLine");function d(n,e){for(let r=0;r<n.length;r++)if(n[r].start===e.start&&n[r].end===e.end)return r;return i(n,e.start)}a(d,"remapUnitIndex");function c(n,e,r){let t=-1,l=-1;if(n.forEach((s,o)=>{s.start<=r&&s.end>=e&&(t===-1&&(t=o),l=o)}),t===-1){const s=i(n,e);return{lo:s,hi:s}}return{lo:t,hi:l}}a(c,"unitRangeForSpan");export{g as deriveAnchorUnits,d as remapUnitIndex,i as unitIndexForLine,c as unitRangeForSpan};
@@ -1,74 +0,0 @@
1
- export interface AnchoredComment {
2
- id: string;
3
- revision: number;
4
- line: number;
5
- endLine: number;
6
- lineText: string;
7
- comment: string;
8
- status: 'open' | 'resolved' | 'deleted';
9
- authorKind: 'human' | 'node';
10
- createdAt: string;
11
- anchorStatus: 'live' | 'shifted' | 'detached';
12
- originalRange?: {
13
- line: number;
14
- endLine: number;
15
- };
16
- }
17
- /** A daemon rejection that leaves the rendered document or comment projection stale. */
18
- export declare class ReviewDocumentError extends Error {
19
- readonly code: 'stale_document' | 'stale_comment' | 'range_batch_incomplete' | 'range_batch_stale';
20
- readonly details: unknown;
21
- constructor(code: ReviewDocumentError['code'], message: string, details: unknown);
22
- }
23
- /** The approved document coordinates every stored comment anchor is expressed against. */
24
- export interface AnchorBase {
25
- /** Canonical reviewed file the base was captured from; the review surface rejects a mismatched target. */
26
- file: string;
27
- /** Full base document text, the left side of the base→current remap done before first paint. */
28
- text: string;
29
- /** Content hash of `text`, and the `fromDocHash` of that first remap batch. */
30
- docHash: string;
31
- }
32
- export type ReviewRequest = <T>(operation: () => Promise<T>) => Promise<T>;
33
- export interface CommentAuthority {
34
- anchorBase(): Promise<AnchorBase>;
35
- list(): Promise<AnchoredComment[]>;
36
- /** Resolves to the new comment's id, which forking it needs. */
37
- create(p: {
38
- line: number;
39
- endLine: number;
40
- text: string;
41
- docHash: string;
42
- }): Promise<string>;
43
- edit(p: {
44
- id: string;
45
- text: string;
46
- ifRevision: number;
47
- }): Promise<void>;
48
- resolve(id: string): Promise<void>;
49
- reopen(id: string): Promise<void>;
50
- remove(id: string): Promise<void>;
51
- remapRanges(p: {
52
- fromDocHash: string;
53
- toDocHash: string;
54
- entries: Array<{
55
- id: string;
56
- anchor: {
57
- line: number;
58
- endLine: number;
59
- };
60
- } | {
61
- id: string;
62
- detached: true;
63
- }>;
64
- }): Promise<void>;
65
- /** Hand one comment to its own fork of the review companion; resolves to the
66
- * newborn fork and the cwd a viewer for it runs in. */
67
- fork(commentId: string): Promise<{
68
- nodeId: string;
69
- cwd: string;
70
- }>;
71
- onChanged(fn: () => void): () => void;
72
- }
73
- /** The terminal's complete daemon seam for one review's comment projection. */
74
- export declare function createCommentAuthority(reviewId: string, request: ReviewRequest): CommentAuthority;
@@ -1 +0,0 @@
1
- var c=Object.defineProperty;var i=(t,n)=>c(t,"name",{value:n,configurable:!0});import{ApiError as s}from"../../../api/errors.js";import{cliClient as o}from"../../../commands/api-client.js";import{watchReviewActivity as d}from"../../../core/review/signal.js";class l extends Error{static{i(this,"ReviewDocumentError")}code;details;constructor(n,e,a){super(e),this.name="ReviewDocumentError",this.code=n,this.details=a}}function v(t,n){return{async anchorBase(){const e=await n(()=>o().getReviewDocumentBase(t));return{file:e.file,text:e.anchor_base_text,docHash:e.anchor_base_sha256}},async list(){return(await n(()=>o().listReviewComments(t,{status:"all"}))).comments.map(h)},async create(e){return(await r(()=>n(()=>o().createReviewComment(t,{text:e.text,anchor:{line:e.line,end_line:e.endLine},doc_hash:e.docHash,actor_node_id:null})))).comment.comment_id},async edit(e){await r(()=>n(()=>o().editReviewComment(e.id,{text:e.text,if_revision:e.ifRevision,actor_node_id:null})))},async resolve(e){await r(()=>n(()=>o().resolveReviewComment(e,{actor_node_id:null})))},async reopen(e){await r(()=>n(()=>o().reopenReviewComment(e,{actor_node_id:null})))},async remove(e){await r(()=>n(()=>o().deleteReviewComment(e,{actor_node_id:null})))},async remapRanges(e){await r(()=>n(()=>o().updateReviewCommentRanges(t,{from_doc_hash:e.fromDocHash,to_doc_hash:e.toDocHash,entries:e.entries.map(a=>"detached"in a?{comment_id:a.id,detached:!0}:{comment_id:a.id,anchor:{line:a.anchor.line,end_line:a.anchor.endLine}})})))},async fork(e){const a=await n(()=>o().forkReviewComment(e));return{nodeId:a.node_id,cwd:a.cwd}},onChanged(e){return d(e)}}}i(v,"createCommentAuthority");function h(t){const n={line:t.anchor.line,endLine:t.anchor.end_line};return{id:t.comment_id,revision:t.revision,...n,lineText:t.anchor_line_text,comment:t.text,status:t.status,authorKind:t.author.kind,createdAt:t.created_at,anchorStatus:t.anchor_state==="detached"?"detached":"live",...t.anchor_state==="detached"?{originalRange:n}:{}}}i(h,"projectComment");async function r(t){try{return await t()}catch(n){throw n instanceof s&&_(n.code)?new l(n.code,n.message,n.details):n}}i(r,"translateDocumentError");function _(t){return t==="stale_document"||t==="stale_comment"||t==="range_batch_incomplete"||t==="range_batch_stale"}i(_,"isDocumentErrorCode");export{l as ReviewDocumentError,v as createCommentAuthority};
@@ -1,47 +0,0 @@
1
- export declare const SPLIT_MIN_COLS = 99;
2
- export declare const MIN_COMPANION_COLS = 40;
3
- export declare const MIN_COMPANION_ROWS = 12;
4
- export declare const COMPANION_WIDTH_RATIO = 0.42;
5
- export declare const COMPANION_HEIGHT_RATIO = 0.4;
6
- /** A fork column narrower than this cannot hold a readable conversation, so the
7
- * split is refused rather than shipping an unusable pane. */
8
- export declare const MIN_FORK_COLS = 52;
9
- export type CompanionPaneOrigin = 'opened' | 'adopted';
10
- export type CompanionPaneResult = {
11
- ok: true;
12
- paneId: string;
13
- origin: CompanionPaneOrigin;
14
- } | {
15
- ok: false;
16
- reason: 'no_tmux' | 'no_caller_pane' | 'split_refused';
17
- };
18
- /** Open or adopt a companion pane for a review. Adoption succeeds only when
19
- * an existing validated-live companion viewer pane exists; otherwise, a
20
- * fresh pane is split beside the caller. */
21
- export declare function openCompanionPane(args: {
22
- companionNodeId: string;
23
- cwd: string;
24
- callerPane: string | undefined;
25
- }): CompanionPaneResult;
26
- /** Open a column for a comment's fork, splitting the rightmost review pane —
27
- * the newest fork, else the companion — so columns accumulate to the right and
28
- * the document keeps its width. */
29
- export declare function openForkPane(args: {
30
- nodeId: string;
31
- cwd: string;
32
- splitFrom: string | undefined;
33
- }): {
34
- ok: true;
35
- paneId: string;
36
- } | {
37
- ok: false;
38
- reason: 'no_tmux' | 'no_caller_pane' | 'split_refused' | 'no_room';
39
- };
40
- /** True while tmux can still describe `paneId` and its process is alive.
41
- * Deliberately tag-free: a companion pane carries `@crtr_node` only once its
42
- * viewer has connected, so a tag check would call a still-booting pane dead
43
- * and let a duplicate be split beside it. */
44
- export declare function companionPaneLive(paneId: string): boolean;
45
- /** Kill the pane only when it still exists AND still carries
46
- * `@crtr_node === companionNodeId`. */
47
- export declare function closeCompanionPane(paneId: string, companionNodeId: string): void;
@@ -1 +0,0 @@
1
- var M=Object.defineProperty;var a=(e,o)=>M(e,"name",{value:o,configurable:!0});import{inTmux as p,liveViewerPanes as O,paneRunning as d,paneSize as _,splitWindow as m,paneExists as I,getPaneOption as N,closePane as k}from"../../../core/runtime/placement-tmux.js";import{viewerEnv as P}from"../../../commands/surface/node/placement.js";const h=99,C=40,v=12,w=.42,S=.4,z=52;function L(e){const{companionNodeId:o,cwd:s,callerPane:n}=e;if(!p())return{ok:!1,reason:"no_tmux"};const t=O().filter(r=>r.nodeId===o&&d(r.pane)).sort((r,x)=>x.stampMs-r.stampMs);if(t.length>0)return{ok:!0,paneId:t[0].pane,origin:"adopted"};if(n===void 0||n==="")return{ok:!1,reason:"no_caller_pane"};const l=_(n);if(l===null)return{ok:!1,reason:"split_refused"};let c,u;l.cols>=h?(c=!1,u=Math.max(C,Math.round(l.cols*w))):(c=!0,u=Math.max(v,Math.round(l.rows*S)));const f=m(n,{cwd:s,env:P(),command:`crtr surface attach to ${o}`,vertical:c,size:u});return f===null?{ok:!1,reason:"split_refused"}:{ok:!0,paneId:f,origin:"opened"}}a(L,"openCompanionPane");function R(e){const{nodeId:o,cwd:s,splitFrom:n}=e;if(!p())return{ok:!1,reason:"no_tmux"};if(n===void 0||n==="")return{ok:!1,reason:"no_caller_pane"};const i=_(n);if(i===null)return{ok:!1,reason:"split_refused"};if(Math.floor(i.cols/2)<z)return{ok:!1,reason:"no_room"};const t=m(n,{cwd:s,env:P(),command:`crtr surface attach to ${o}`,vertical:!1,size:Math.floor(i.cols/2)});return t===null?{ok:!1,reason:"split_refused"}:{ok:!0,paneId:t}}a(R,"openForkPane");function E(e){return I(e)&&d(e)}a(E,"companionPaneLive");function F(e,o){!I(e)||N(e,"@crtr_node")!==o||k(e)}a(F,"closeCompanionPane");export{S as COMPANION_HEIGHT_RATIO,w as COMPANION_WIDTH_RATIO,C as MIN_COMPANION_COLS,v as MIN_COMPANION_ROWS,z as MIN_FORK_COLS,h as SPLIT_MIN_COLS,F as closeCompanionPane,E as companionPaneLive,L as openCompanionPane,R as openForkPane};
@@ -1,212 +0,0 @@
1
- import type { SurfaceComponent, SurfaceHandle, SurfaceNoticeOptions } from '../../surfaces/host.js';
2
- import { type CommentAuthority } from './comments-client.js';
3
- import type { LiveSource } from './live-source.js';
4
- import type { ResolvedReview } from './review-client.js';
5
- /** What the surface's owner supplies for everything outside the document.
6
- *
7
- * `submit` exists because the `s` key lives on the document while the review lifecycle adapter belongs to the owner: the
8
- * surface reports the intent, the owner runs `reviewClient.submit`. */
9
- export interface ReviewSurfaceServices {
10
- notice(text: string, opts?: SurfaceNoticeOptions): void;
11
- suspendForChild(): () => void;
12
- requestClose(): void;
13
- submit(): void;
14
- cancel(): void;
15
- }
16
- export interface ReviewDocumentSurfaceOptions {
17
- review: ResolvedReview;
18
- source: LiveSource;
19
- comments: CommentAuthority;
20
- /** `host.capabilities.selfPane` — the pane the companion splits against. */
21
- callerPane: string | undefined;
22
- services: ReviewSurfaceServices;
23
- }
24
- /** The one mounted review surface: existing review rendering and navigation
25
- * over a live file, with comments projected from the daemon and ranges
26
- * remapped by this terminal as the file changes, plus a status row naming the
27
- * companion pane the conversation lives in. */
28
- export declare class ReviewDocumentSurface implements SurfaceComponent {
29
- private readonly absFile;
30
- private readonly fileLabel;
31
- private readonly companionNodeId;
32
- private readonly companionCwd;
33
- private readonly callerPane;
34
- private readonly kind;
35
- private readonly source;
36
- private readonly comments;
37
- private readonly services;
38
- private readonly unsubscribeComments;
39
- private readonly ready;
40
- private cols;
41
- /** Rows the host assigned this surface; the document frame renders one
42
- * fewer, because the last line is this surface's status row. */
43
- private hostRows;
44
- /** The `hostRows` the current state was last reflowed against. A height
45
- * change matters as much as a width one: `reflow` is what re-runs
46
- * `ensureAnchorVisible` against the new body height, so a pane shrink
47
- * cannot strand the active anchor below the visible body. */
48
- private flowedRows;
49
- private _focused;
50
- private closed;
51
- private escapeConfirmArmed;
52
- private cancelArmed;
53
- private submitArmed;
54
- private tornDown;
55
- /** The disposition {@link teardown} stated, kept only while there was no
56
- * handle to close: the mount that follows disposes every standing notice,
57
- * so {@link setHandle} states it again once the surface is gone. */
58
- private tornDownNotice;
59
- private handle;
60
- /** The companion pane this surface is bound to, and how it came to be.
61
- * `paneOrigin` is status-row copy only: teardown reads `paneId`. */
62
- private paneId;
63
- private paneOrigin;
64
- /** Fork columns this surface opened, oldest first. The newest live one is
65
- * what the next fork splits against, so columns accumulate rightward. */
66
- private forkPanes;
67
- /** Row increments of a half-page move still to be painted, and the timer
68
- * walking them. A fresh press settles whatever is in flight before starting
69
- * its own move, so a held key cannot pile up overlapping animations. */
70
- private scrollSteps;
71
- private scrollTimer;
72
- private state;
73
- private cache;
74
- /** Every non-deleted comment the daemon currently projects, newest last. */
75
- private projection;
76
- private status;
77
- /** This surface's own error/summary state — never a host notice (D1). */
78
- private problem;
79
- private composeAnchorLost;
80
- /** Serializes base-hash transitions so B→C cannot overtake A→B. */
81
- private remapChain;
82
- constructor(opts: ReviewDocumentSurfaceOptions);
83
- /** Resolves once the daemon coordinate base has been aligned to the file on
84
- * disk. The owner may await it so the first painted frame already carries
85
- * current ranges; painting earlier shows only a preparing line, never a
86
- * comment at a coordinate the daemon has not accepted. */
87
- open(): Promise<void>;
88
- hasUnsentCompose(): boolean;
89
- get focused(): boolean;
90
- set focused(value: boolean);
91
- setRows(rows: number): void;
92
- /** Exactly the rows the host assigned: the document frame, then this
93
- * surface's status row. The document is capped at {@link DOC_MAX_COLS} and
94
- * every line is padded out to the full pane width. */
95
- render(width: number): string[];
96
- /** Rows the document frame itself owns. */
97
- private get rows();
98
- private renderDocument;
99
- /** The surface consumes every chunk: nothing typed into a mounted review may
100
- * reach the transcript beneath it. Esc is the one key this surface answers
101
- * itself — it closes the review unless an unsent comment holds it open. */
102
- handleInput(data: string): void;
103
- /** True when the document's own modes took the chunk. */
104
- private consume;
105
- /** A mounted review consumes every notch, ready or not: the transcript
106
- * beneath it must never scroll while the document stands over it. */
107
- handleWheel(direction: 'up' | 'down', lines: number): boolean;
108
- /** A half-page move of the view and the selection together, painted at three
109
- * midpoints before its destination so the document slides rather than jumps.
110
- * Whatever is still in flight lands first, keeping every press exact. */
111
- private startScrollAnimation;
112
- private scheduleScrollStep;
113
- /** Land every step still to be painted on the state at once. */
114
- private settleScrollAnimation;
115
- private stopScrollAnimation;
116
- private applyScrollRows;
117
- /** Repaints are scheduled by the host; this surface never draws directly. */
118
- invalidate(): void;
119
- /** The mounted handle is this surface's repaint and close channel, and the
120
- * host's close is what releases the document's resources. */
121
- setHandle(handle: SurfaceHandle): void;
122
- /** The status row's left segment: this document's state in one line. */
123
- private summary;
124
- /** The status row's right segment: where the companion conversation is. */
125
- private companionSegment;
126
- private statusRow;
127
- /** Bind the conversation's pane, opening one only when this surface holds no
128
- * live pane already and there is no live companion viewer to adopt. A second
129
- * call therefore keeps the bound pane, whatever state its viewer is in. */
130
- openCompanion(): void;
131
- /** The pane a new fork column splits from: the newest live fork, else the
132
- * companion, else this viewer. */
133
- private rightmostReviewPane;
134
- /** Hand one comment to its own fork of the companion and place its column.
135
- * The comment is already saved by the time this runs, so every failure here
136
- * is stated as a notice rather than failing the comment. */
137
- private forkComment;
138
- /** The one path out of a review that has reached a terminal state — approved,
139
- * canceled here, or decided elsewhere. The pane goes with the review, never
140
- * with Esc: closing the document leaves the conversation standing so the
141
- * review can be re-opened over it. Idempotent. The disposition is stated
142
- * only after the close, because the host's restoring close disposes every
143
- * notice raised over the closing surface — a notice raised first would die
144
- * with the surface and the disposition would never paint. */
145
- teardown(notice: string, opts?: SurfaceNoticeOptions): void;
146
- /** Releases this surface's render cache and stops every projected repaint.
147
- * This surface closes the source it was handed; that close stops its watcher.
148
- * The companion pane deliberately survives: only {@link teardown} closes it. */
149
- close(): void;
150
- /** Bring the daemon's comment coordinates onto the bytes now on disk, then
151
- * build the first state from what the daemon accepted. The zero-comment case
152
- * still submits its batch: the base digest itself is what advances, and a
153
- * later create against current bytes is rejected until it does. */
154
- private align;
155
- private movedSince;
156
- /** Re-derive this surface from the daemon's own coordinate base. The only
157
- * honest recovery once a batch is rejected: the local map that produced it
158
- * is no longer a true description of what the daemon holds. */
159
- private realign;
160
- private buildState;
161
- private onSourceChanged;
162
- /** One transaction covering every non-deleted comment. A rejection is stated
163
- * in this surface's own footer and the projection is re-read from the
164
- * authority, which is the only thing that can still be true afterwards. */
165
- private submitBatch;
166
- private refreshProjection;
167
- private mutate;
168
- private handleComposeKey;
169
- /** The document's single-key commands, shared by view mode. Returns false
170
- * for a key that is not one of them. Space was once a prefix for these; it
171
- * is now ignored, so a remembered `space c` still lands on `c`. */
172
- private handleCommandKey;
173
- private submit;
174
- /** Submitting ends the review, so it asks once. The armed state is answered
175
- * in {@link handleInput}, ahead of every mode's ladder. */
176
- private armSubmit;
177
- /** Cancelling discards the whole review, so it asks once. The armed state is
178
- * answered in {@link handleInput}, ahead of every mode's ladder. */
179
- private armCancel;
180
- private handleListKey;
181
- private handleViewKey;
182
- /** The reviewed file is the deliverable: the person's own editor writes it,
183
- * this surface never does. The source is re-read the moment the editor exits
184
- * rather than waiting for the watcher's coalescing window. */
185
- private editInEditor;
186
- /** The host owns cursor focus; a focused surface contributes exactly one
187
- * whole marker at the same visual location the document already calls
188
- * active. There is deliberately no synthetic fallback row: a marker is
189
- * only valid when it belongs to a rendered anchor or the compose/list cursor. */
190
- private markCursorLocation;
191
- /** The frame paints source rows after its three-line header. Scroll indicators
192
- * replace their source rows, so they are never cursor targets. */
193
- private activeAnchorFrameRow;
194
- private reflow;
195
- private document;
196
- private bodyHeight;
197
- private composeWidth;
198
- private gutterWidth;
199
- /** The document frame's own footer line: its error, then its stale verdict. */
200
- private footerLine;
201
- private renderPlaceholder;
202
- /** `frame.ts` renders the ordinary list. Detached anchors need stronger
203
- * treatment: their own leading group plus the original range and snippet,
204
- * because no document marker can lead a person back to them. */
205
- private renderGroupedList;
206
- /** The compose header states a lost anchor where the person is already
207
- * looking, leaving the footer's compose keys intact. */
208
- private statedComposeAnchor;
209
- private commentListRow;
210
- private topVisibleSourceLine;
211
- private repaint;
212
- }
@@ -1,2 +0,0 @@
1
- var k=Object.defineProperty;var d=(o,e)=>k(o,"name",{value:e,configurable:!0});import{relative as ee,resolve as j}from"node:path";import{CURSOR_MARKER as F,Key as te,matchesKey as se}from"@earendil-works/pi-tui";import{documentLines as ie}from"../../../core/document-lines.js";import{codeRenderedDoc as ne}from"../../../core/termrender/code-doc.js";import{deriveAnchorUnits as C,remapUnitIndex as T,unitIndexForLine as oe,unitRangeForSpan as W}from"./anchors.js";import{centerHorizontal as N,clipLine as w,CYAN as $,DIM as A,RESET as p,REVERSE as re,sanitize as O,truncate as ce,visibleWidth as v,YELLOW as B}from"../tui/ansi.js";import{ReviewDocumentError as ae}from"./comments-client.js";import{closeCompanionPane as K,companionPaneLive as I,openCompanionPane as he,openForkPane as de}from"./companion-pane.js";import{PAN_STEP as le,docSurface as ue,maxHScroll as fe,panBy as me,renderReviewDoc as pe,renderReviewFrame as ge,listHintBar as we,renderWidthForCols as be,reservedRows as _}from"./frame.js";import{matchReviewKey as M,reviewKeyText as S}from"./keys.js";import{renderInputBuffer as ve}from"../tui/render.js";import{openReviewedFileInEditor as Le}from"./nvim.js";import{buildLineMap as V,remapRange as xe}from"./remap.js";import{cleanPastedText as Re,closeCompose as Se,closeHelp as q,closeList as z,commitCompose as Ce,ensureAnchorVisible as g,halfPageRows as $e,initReviewState as Ae,moveActiveUnit as G,moveListIndex as Y,moveViewRows as Ie,openComposeEdit as Me,openComposeNew as ye,openHelp as Pe,openList as De,scrollBy as Ue,textBackspace as He,textDelete as Ee,textEnd as je,textHome as Fe,textInsert as y,textVerticalWrapped as Te,textWordBackspace as We,textWordLeft as Ne,textWordRight as Oe,deleteAtListIndex as Be,undoLast as Ke}from"./state.js";const _e=126,Ve=4,qe=24;class mt{static{d(this,"ReviewDocumentSurface")}absFile;fileLabel;companionNodeId;companionCwd;callerPane;kind;source;comments;services;unsubscribeComments;ready;cols=0;hostRows=0;flowedRows=-1;_focused=!1;closed=!1;escapeConfirmArmed=!1;cancelArmed=!1;submitArmed=!1;tornDown=!1;tornDownNotice;handle;paneId;paneOrigin;forkPanes=[];scrollSteps=[];scrollTimer;state;cache;projection=[];status="preparing";problem;composeAnchorLost=!1;remapChain=Promise.resolve();constructor(e){this.absFile=e.review.file,this.fileLabel=Xe(e.review.cwd,e.review.file),this.companionNodeId=e.review.companionNodeId,this.companionCwd=e.review.cwd,this.callerPane=e.callerPane,this.kind=ue(e.review.file),this.source=e.source,this.comments=e.comments,this.services=e.services,this.source.onChange((t,s)=>{this.onSourceChanged(t,s)}),this.unsubscribeComments=this.comments.onChanged(()=>{this.refreshProjection()}),this.ready=this.align().catch(t=>{this.closed||(this.status="refused",this.problem=b(t),this.repaint())})}open(){return this.ready}hasUnsentCompose(){const e=this.state;return e?.mode==="compose"&&e.compose!==null&&e.compose.buffer.length>0}get focused(){return this._focused}set focused(e){this._focused!==e&&(this._focused=e,this.repaint())}setRows(e){this.hostRows=Math.max(0,Math.floor(e))}render(e){const t=Math.max(0,Math.floor(e));if(this.hostRows<=0)return[];const s=Math.min(t,_e);(s!==this.cols||this.hostRows!==this.flowedRows)&&(this.cols=s,this.flowedRows=this.hostRows,this.reflow());const i=this.rows<=0||this.cols<=0?[]:this.renderDocument();return[...Ge(i,this.rows,t),this.statusRow(t)]}get rows(){return Math.max(0,this.hostRows-1)}renderDocument(){if(this.status!=="ready"||this.state===void 0)return this.renderPlaceholder();const e=this.document(this.cols,this.state.sourceRevision),t=ge(this.state,this.fileLabel,e,this.cols,this.rows,{lineNumbers:this.kind.doc==="code",...this.footerLine()===void 0?{}:{notice:this.footerLine()}}),s=this.state.mode==="list"&&this.state.comments.some(n=>n.anchorStatus==="detached")?this.renderGroupedList(t):t,i=this.state.mode==="compose"&&this.composeAnchorLost?this.statedComposeAnchor(s):s;return this.focused?this.markCursorLocation(i,this.state):i}handleInput(e){if(!this.closed){if(this.cancelArmed){this.cancelArmed=!1;const t=M(e);if(t!==null&&S(t)==="x"){this.services.cancel();return}}if(this.submitArmed){this.submitArmed=!1;const t=M(e);if(t!==null&&S(t)==="s"){this.submit();return}}if(se(e,te.escape)){if(this.escapeConfirmArmed){if(this.escapeConfirmArmed=!1,this.consume(e))return;this.services.requestClose();return}if(this.hasUnsentCompose()){this.escapeConfirmArmed=!0,this.services.notice("unsent comment \u2014 press esc again to discard"),this.repaint();return}if(this.consume(e))return;this.services.requestClose();return}this.escapeConfirmArmed&&(this.escapeConfirmArmed=!1),this.consume(e)}}consume(e){if(this.status!=="ready")return!1;const t=this.state;if(t===void 0)return!1;const s=M(e);if(s===null)return!1;if(t.mode==="compose")return this.handleComposeKey(s),this.repaint(),!0;if(t.mode==="list"){const i=this.handleListKey(s);return this.repaint(),i}return t.mode==="help"?s.type==="help"||s.type==="cancel"&&s.text===void 0?(this.state=q(t),this.repaint(),!0):s.type==="cancel"?(this.state=q(t),this.repaint(),!0):!1:this.handleViewKey(s)}handleWheel(e,t){if(this.closed)return!1;const s=this.state;if(this.status!=="ready"||s===void 0)return!0;this.settleScrollAnimation();const i=this.state??s,n=this.document(this.cols,i.sourceRevision),r=(e==="up"?-1:1)*Math.max(1,Math.floor(t));return this.state=Ue(i,r,this.bodyHeight(i),n.lines.length),this.repaint(),!0}startScrollAnimation(e){this.settleScrollAnimation();const t=ze(e),s=t.shift();s!==void 0&&(this.applyScrollRows(s),this.scrollSteps=t,this.scheduleScrollStep())}scheduleScrollStep(){this.scrollSteps.length!==0&&(this.scrollTimer=setTimeout(()=>{this.scrollTimer=void 0;const e=this.scrollSteps.shift();e===void 0||this.closed||(this.applyScrollRows(e),this.repaint(),this.scheduleScrollStep())},qe))}settleScrollAnimation(){this.stopScrollAnimation();const e=this.scrollSteps;this.scrollSteps=[];for(const t of e)this.applyScrollRows(t)}stopScrollAnimation(){this.scrollTimer!==void 0&&(clearTimeout(this.scrollTimer),this.scrollTimer=void 0)}applyScrollRows(e){const t=this.state;if(this.status!=="ready"||t===void 0)return;const s=this.document(this.cols,t.sourceRevision);this.state=Ie(t,e,this.bodyHeight(t),s.lines.length)}invalidate(){this.closed||this.handle?.invalidate()}setHandle(e){if(this.handle===void 0&&(this.handle=e,e.onClose(()=>this.close()),this.tornDown)){e.close();const t=this.tornDownNotice;this.tornDownNotice=void 0,t!==void 0&&this.services.notice(t.text,t.opts)}}summary(){if(this.status==="refused")return`${this.fileLabel} \u2014 unavailable`;if(this.status==="preparing")return`${this.fileLabel} \u2014 preparing`;const e=this.projection.filter(i=>i.status==="open").length,t=this.projection.filter(i=>i.anchorStatus==="detached").length,s=[this.fileLabel,`${e} open`];return t>0&&s.push(`${t} detached`),this.source.current().status==="stale"&&s.push(`stale (${this.source.current().staleReason??"unreadable"})`),s.join(" \xB7 ")}companionSegment(){const e=this.paneOrigin===void 0?"companion none":`companion ${this.paneOrigin}`,t=this.forkPanes.length;return t===0?e:`${e} \xB7 ${t} fork${t===1?"":"s"}`}statusRow(e){if(e<=0)return"";const t=w(this.companionSegment(),e),s=w(this.summary(),Math.max(0,e-v(t)-1)),i=Math.max(0,e-v(s)-v(t));return`${A}${s}${" ".repeat(i)}${t}${p}`}openCompanion(){if(this.closed||this.tornDown||this.paneId!==void 0&&I(this.paneId))return;const e=he({companionNodeId:this.companionNodeId,cwd:this.companionCwd,callerPane:this.callerPane});if(e.ok){this.paneId=e.paneId,this.paneOrigin=e.origin,this.repaint();return}if(e.reason==="split_refused"){this.services.notice("tmux refused the companion split \u2014 press a to retry");return}this.services.notice(`The review companion needs tmux \u2014 run: crtr surface attach to ${this.companionNodeId}`,{sticky:!0})}rightmostReviewPane(){for(let e=this.forkPanes.length-1;e>=0;e-=1){const t=this.forkPanes[e];if(I(t.paneId))return t.paneId}return this.paneId!==void 0&&I(this.paneId)?this.paneId:this.callerPane}async forkComment(e){if(this.closed||this.tornDown)return;let t;try{t=await this.comments.fork(e)}catch(i){this.services.notice(`the comment was saved, but its fork could not start \u2014 ${b(i)}`);return}if(this.closed||this.tornDown)return;const s=de({nodeId:t.nodeId,cwd:t.cwd,splitFrom:this.rightmostReviewPane()});if(s.ok){this.forkPanes.push({paneId:s.paneId,nodeId:t.nodeId}),this.repaint();return}this.services.notice(s.reason==="no_room"?`no room for another fork column \u2014 the fork is running: crtr surface attach to ${t.nodeId}`:`the fork is running, but tmux gave it no column \u2014 run: crtr surface attach to ${t.nodeId}`,{sticky:!0})}teardown(e,t){if(!this.tornDown){this.tornDown=!0;for(const s of this.forkPanes)K(s.paneId,s.nodeId);this.forkPanes=[],this.paneId!==void 0&&K(this.paneId,this.companionNodeId),this.paneId=void 0,this.paneOrigin=void 0,this.handle===void 0&&(this.tornDownNotice={text:e,...t===void 0?{}:{opts:t}}),this.handle?.close(),this.services.notice(e,t)}}close(){this.closed||(this.source.close(),this.closed=!0,this.stopScrollAnimation(),this.scrollSteps=[],this.unsubscribeComments(),this.cache=void 0)}async align(){for(;;){const e=await this.comments.anchorBase();if(this.closed)return;if(j(e.file)!==j(this.absFile))throw new Error(`review document mismatch \u2014 the daemon's canonical file is ${e.file}, not ${this.absFile}`);const t=this.source.current();if(t.status==="stale")throw new Error(`the reviewed file cannot be read (${t.staleReason??"unreadable"})`);if(e.docHash!==t.sha256){const i=await this.comments.list();if(this.closed)return;if(this.movedSince(t))continue;const n=V(ie(e.text),t.lines);if(await this.comments.remapRanges({fromDocHash:e.docHash,toDocHash:t.sha256,entries:Ze(P(i),n)}),this.closed)return}const s=await this.comments.list();if(this.closed)return;if(!this.movedSince(t)){this.projection=P(s),this.status="ready",this.buildState(t),this.repaint();return}}}movedSince(e){const t=this.source.current();return t.status==="live"&&t.sha256!==e.sha256}async realign(){if(!this.closed)try{await this.align()}catch(e){if(this.closed)return;this.status="refused",this.problem=b(e),this.repaint()}}buildState(e){const t=this.document(this.cols,e.revision);this.state=Ae(e.lines,C(t),D(this.projection),e.revision),this.state=g(this.state,t,this.bodyHeight(this.state))}onSourceChanged(e,t){if(this.closed||this.status!=="ready")return;const s=this.state;if(s===void 0)return;if(e.status==="stale"){this.problem=void 0,this.repaint();return}if(e.text===t.text){this.problem=void 0,this.repaint();return}const i=V(t.lines,e.lines),n=new Map;for(const a of this.projection)n.set(a.id,a.anchorStatus==="detached"?{range:a.originalRange??{line:a.line,endLine:a.endLine},detached:!0}:L(i,{line:a.line,endLine:a.endLine}));const r=s.compose===null||this.composeAnchorLost?void 0:L(i,s.compose.anchor),c=L(i,X(s,s.activeUnit)),u=s.selectionAnchor===null?void 0:L(i,X(s,s.selectionAnchor)),l=Je(i,this.topVisibleSourceLine(s),t.lines.length),f=this.document(this.cols,e.revision),{units:m,rowUnits:h}=C(f),J=W(m,c.range.line,c.range.endLine).hi,Q=u===void 0?null:W(m,u.range.line,u.range.endLine).lo,x=this.projection.map(a=>{const E=n.get(a.id);return E===void 0?a:Qe(a,E)});this.projection=x;const H={};for(const a of x)a.anchorStatus==="detached"&&(H[a.id]=a.originalRange??{line:a.line,endLine:a.endLine});this.composeAnchorLost=this.composeAnchorLost||r?.detached===!0;const Z=s.compose===null||r===void 0?s.compose:{...s.compose,anchor:r.range};let R={...s,sourceLines:e.lines,units:m,rowUnits:h,comments:D(x),sourceRevision:e.revision,detached:H,activeUnit:J,selectionAnchor:Q,compose:Z,listIndex:Math.max(0,Math.min(s.listIndex,x.length-1)),scroll:m[oe(m,l)]?.firstRow??0};R=g(R,f,this.bodyHeight(R)),this.state=R,this.problem=this.composeAnchorLost?"the commented lines were removed \u2014 this comment has no anchor":void 0,this.repaint(),this.remapChain=this.remapChain.then(()=>this.submitBatch(t.sha256,e.sha256,n),()=>this.submitBatch(t.sha256,e.sha256,n))}async submitBatch(e,t,s){if(this.closed)return;const i=[...s].map(([n,r])=>r.detached?{id:n,detached:!0}:{id:n,anchor:r.range});try{if(await this.comments.remapRanges({fromDocHash:e,toDocHash:t,entries:i}),this.closed)return;await this.refreshProjection()}catch(n){if(this.closed)return;this.problem=`comment ranges were rejected \u2014 ${b(n)}`,this.repaint(),await this.realign()}}async refreshProjection(){if(!(this.closed||this.status==="refused"))try{const e=P(await this.comments.list());if(this.closed)return;this.projection=e;const t=this.state;if(t!==void 0){const s=D(e);this.state={...t,comments:s,detached:Object.fromEntries(s.flatMap(i=>i.anchorStatus==="detached"?[[i.id,i.originalRange??{line:i.line,endLine:i.endLine}]]:[])),listIndex:Math.max(0,Math.min(t.listIndex,s.length-1))}}this.repaint()}catch(e){if(this.closed)return;this.problem=`comments could not be read \u2014 ${b(e)}`,this.repaint()}}async mutate(e){if(!this.closed){try{if(await e(),this.closed)return;this.problem=void 0}catch(t){if(this.closed)return;this.problem=t instanceof ae?`${t.code.replace(/_/g," ")} \u2014 the document moved under this comment`:b(t),this.repaint()}await this.refreshProjection()}}handleComposeKey(e){const t=this.state,s=t?.compose;if(t===void 0||s===null||s===void 0)return;if(e.type==="cancel"&&e.text===void 0){this.composeAnchorLost=!1,this.state=Se(t);return}if(e.type==="confirm"||e.type==="confirmFork"){if(this.composeAnchorLost){this.problem="comment not saved \u2014 its anchored lines were removed";return}const n=Ce(t);this.composeAnchorLost=!1,this.state=n.state;const r=n.commit;if(r===null)return;const c=e.type==="confirmFork",u=this.source.current().sha256;if(r.editingId===null){this.mutate(async()=>{const f=await this.comments.create({line:r.anchor.line,endLine:r.anchor.endLine,text:r.text,docHash:u});c&&await this.forkComment(f)});return}const l=this.projection.find(f=>f.id===r.editingId);if(l===void 0){this.problem="that comment no longer exists";return}this.mutate(async()=>{await this.comments.edit({id:l.id,text:r.text,ifRevision:l.revision}),c&&await this.forkComment(l.id)});return}if(e.type==="composeNewline"){this.state={...t,compose:{...s,...y(s.buffer,s.cursor,`
2
- `)}};return}if(e.type==="composeWordBackspace"){this.state={...t,compose:{...s,...We(s.buffer,s.cursor)}};return}if(e.type==="composeBackspace"){this.state={...t,compose:{...s,...He(s.buffer,s.cursor)}};return}if(e.type==="composeDelete"){this.state={...t,compose:{...s,...Ee(s.buffer,s.cursor)}};return}if(e.type==="composeMove"){const n=e.direction==="wordLeft"?Ne(s.buffer,s.cursor):Oe(s.buffer,s.cursor);this.state={...t,compose:{...s,cursor:n}};return}if(e.type==="arrow"&&e.direction==="left"){this.state={...t,compose:{...s,cursor:Math.max(0,s.cursor-1)}};return}if(e.type==="arrow"&&e.direction==="right"){this.state={...t,compose:{...s,cursor:Math.min([...s.buffer].length,s.cursor+1)}};return}if(e.type==="composeHome"){this.state={...t,compose:{...s,cursor:Fe(s.buffer,s.cursor)}};return}if(e.type==="composeEnd"){this.state={...t,compose:{...s,cursor:je(s.buffer,s.cursor)}};return}if(e.type==="arrow"&&(e.direction==="up"||e.direction==="down")){const n=e.direction==="up"?-1:1;this.state={...t,compose:{...s,cursor:Te(s.buffer,s.cursor,n,this.composeWidth())}};return}const i=S(e);if(i!==void 0){if(e.type==="paste"){const n=Re(i);if(n.length===0)return;this.state={...t,compose:{...s,...y(s.buffer,s.cursor,n)}};return}this.state={...t,compose:{...s,...y(s.buffer,s.cursor,i)}}}}handleCommandKey(e){const t=this.state;if(t===void 0)return!1;const s=e.type==="confirm"?"c":S(e);if(s==="c"){const i=ye(t);this.composeAnchorLost=!1,this.state=g(i,this.document(this.cols,i.sourceRevision),this.bodyHeight(i))}else if(s==="C")this.state=De(t);else if(s==="U"){const i=Ke(t);if(i.id!==null){const n=i.id;this.mutate(()=>this.comments.remove(n))}}else if(s==="e")this.editInEditor();else if(s==="s")this.armSubmit();else if(s==="a")this.openCompanion();else if(s==="x")this.armCancel();else if(s!==" ")return!1;return this.repaint(),!0}submit(){const e=this.source.current();if(e.status==="stale"){this.problem=`approval refused while the source is ${e.staleReason??"unreadable"}`,this.repaint();return}this.services.submit()}armSubmit(){this.submitArmed=!0,this.services.notice("submit and approve this review? press s again to confirm")}armCancel(){this.cancelArmed=!0,this.services.notice("cancel this review? press x again to confirm")}handleListKey(e){const t=this.state;if(t===void 0)return!1;if(e.type==="cancel")return this.state=z(t),!0;if(e.type==="moveUnit"&&e.text==="j"||e.type==="arrow"&&e.direction==="down")return this.state=Y(t,1),!0;if(e.type==="moveUnit"&&e.text==="k"||e.type==="arrow"&&e.direction==="up")return this.state=Y(t,-1),!0;if(e.type==="listEdit"||e.type==="confirm"){if(t.comments.length>0){const s=Me(t,t.listIndex);this.composeAnchorLost=!1,this.state=g(s,this.document(this.cols,s.sourceRevision),this.bodyHeight(s))}return!0}if(e.type==="scrollPage"&&e.text==="d"&&t.comments.length>0){const s=Be(t);if(s.id!==null){const i=s.id;this.mutate(()=>this.comments.remove(i))}return!0}return e.type==="printable"&&e.text==="c"?(this.state=z(t),this.handleCommandKey(e)):!1}handleViewKey(e){const t=this.state;if(t===void 0)return!1;const s=this.document(this.cols,t.sourceRevision),i=this.bodyHeight(t);if(e.type==="moveUnit"||e.type==="arrow"&&(e.direction==="up"||e.direction==="down")){const n=e.type==="moveUnit"?e.delta:e.direction==="down"?1:-1;this.state=g(G(t,n,!1),s,i)}else if(e.type==="extendUnit")this.state=g(G(t,e.delta,!0),s,i);else if(e.type==="scrollPage")this.startScrollAnimation(e.delta*$e(i));else if((e.type==="pan"||e.type==="arrow"&&(e.direction==="left"||e.direction==="right"))&&fe(t,s,this.cols,this.rows,this.gutterWidth())>0){const n=e.type==="pan"?e.delta:e.direction==="right"?1:-1;this.state=me(t,n*le,s,this.cols,this.rows,this.gutterWidth())}else if(e.type==="help")this.state=Pe(t);else return e.type==="cancel"&&e.text===void 0||e.type==="cancel"?!1:this.handleCommandKey(e);return this.repaint(),!0}editInEditor(){const e=this.state;if(e===void 0)return;const t=e.units[e.activeUnit]?.start??1,s=this.services.suspendForChild();try{const i=Le(this.absFile,t);i.error!==void 0&&(this.problem=`editor failed \u2014 ${i.error}`)}finally{s()}this.source.refreshNow()}markCursorLocation(e,t){if(t.mode==="compose")return U(e,re);if(t.mode==="list"){const i=U(e,`${$}\u25B8${p}`);if(i!==e)return i}const s=this.activeAnchorFrameRow(t);return s===void 0?e:U(e,`${$}\u258C${p}`,s)}activeAnchorFrameRow(e){const t=Math.max(1,this.rows-_(e,this.cols)),s=e.rowUnits.length,i=Math.max(0,Math.min(e.scroll,Math.max(0,s-t)));for(let n=0;n<t;n++){const r=i+n;if(!(n===0&&i>0||n===t-1&&r<s-1)&&e.rowUnits[r]===e.activeUnit)return 3+n}}reflow(){const e=this.state;if(e===void 0||this.cols<=0)return;const t=e.units[e.activeUnit],s=e.selectionAnchor===null?void 0:e.units[e.selectionAnchor],i=this.document(this.cols,e.sourceRevision),{units:n,rowUnits:r}=C(i),c={...e,units:n,rowUnits:r,activeUnit:t===void 0?0:T(n,t),selectionAnchor:s===void 0?null:T(n,s)};this.state=g(c,i,this.bodyHeight(c))}document(e,t){const s=this.cache;if(s!==void 0&&s.width===e&&s.sourceRevision===t)return s.doc;const i=this.source.current().text,n=this.kind.doc==="code"?ne(i,this.kind.language??"text",be(e)):pe(i,e);return this.cache={width:e,sourceRevision:t,doc:n},n}bodyHeight(e){const t=e.mode==="list"&&e.comments.some(s=>s.anchorStatus==="detached")?1+(e.comments.some(s=>s.anchorStatus!=="detached")?1:0):0;return Math.max(1,this.rows-_(e,this.cols)-t)}composeWidth(){return Math.max(10,Math.min(Math.max(20,this.cols-4),120)-2)}gutterWidth(){return this.kind.doc==="code"?String(this.source.current().lines.length).length:0}footerLine(){if(this.problem!==void 0)return this.problem;const e=this.source.current();if(e.status==="stale")return`source ${e.staleReason??"unreadable"} \u2014 showing the last good read; approval is refused`}renderPlaceholder(){const t=["",` ${this.status==="refused"?`Review unavailable \u2014 ${this.problem??"the document could not be prepared"}`:`Preparing ${this.fileLabel}\u2026`}`];for(;t.length<this.rows;)t.push("");return t.slice(0,this.rows).map(s=>w(s,this.cols))}renderGroupedList(e){const t=this.state,s=Math.min(Math.max(20,this.cols-4),120),i=t.comments.filter(h=>h.anchorStatus==="detached"),n=t.comments.filter(h=>h.anchorStatus!=="detached"),r=[` ${B}Detached${p}`];for(const h of i)r.push(this.commentListRow(h,t.comments.indexOf(h),s,!0));if(n.length>0){r.push(` ${A}Comments${p}`);for(const h of n)r.push(this.commentListRow(h,t.comments.indexOf(h),s,!1))}r.push(""),r.push(we(s));const c=Math.max(0,this.rows-3),u=r.slice(0,c),l=Math.max(3,this.rows-u.length),f=[...e],m=N(u,this.cols,Math.min(this.cols,s+2));for(let h=0;h<m.length;h++)f[l+h]=w(m[h]??"",this.cols);return f.slice(0,this.rows)}statedComposeAnchor(e){const t=this.state;if(t?.compose==null)return e;const s=Math.min(Math.max(20,this.cols-4),120),i=ve(t.compose.buffer,t.compose.cursor,Math.max(10,s-2)).length,n=this.rows-(i+3);if(n<0||n>=e.length)return e;const r=[...e];return r[n]=w(N([` ${B}Comment anchor removed by an edit \u2014 esc, then re-anchor:${p}`],this.cols,Math.min(this.cols,s+2))[0]??"",this.cols),r}commentListRow(e,t,s,i){const n=i?e.originalRange??{line:e.line,endLine:e.endLine}:{line:e.line,endLine:e.endLine},r=n.line===n.endLine?`L${n.line}`:`L${n.line}-${n.endLine}`,c=t===this.state.listIndex?`${$}\u25B8${p}`:" ",l=`${i?`\u201C${O(e.lineText).replace(/\s+/g," ").trim()}\u201D \xB7 `:""}${O(e.comment).replace(/\s+/g," ").trim()}`;return` ${c} ${A}[${r}]${p} ${ce(l,Math.max(10,s-14))}`}topVisibleSourceLine(e){const t=e.rowUnits[e.scroll];if(t!=null)return e.units[t]?.start??1;for(let s=e.scroll;s<e.rowUnits.length;s++){const i=e.rowUnits[s];if(i!=null)return e.units[i]?.start??1}return 1}repaint(){this.invalidate()}}function ze(o){const e=Math.abs(o);if(e===0)return[];const t=Math.sign(o),s=Math.min(Ve,e),i=[];let n=0;for(let r=1;r<=s;r++){const c=Math.round(e*r/s);i.push((c-n)*t),n=c}return i}d(ze,"splitScrollSteps");function Ge(o,e,t){const s=o.slice(0,e).map(i=>Ye(i,t));for(;s.length<e;)s.push(" ".repeat(t));return s}d(Ge,"exactRows");function Ye(o,e){const t=o.split(F).join(""),s=v(t);if(s>e){const i=w(t,e);return i+" ".repeat(Math.max(0,e-v(i)))}return o+" ".repeat(e-s)}d(Ye,"padTo");function Xe(o,e){const t=ee(o,e);return t===""||t.startsWith("..")?e:t}d(Xe,"labelFor");function P(o){return o.filter(e=>e.status!=="deleted")}d(P,"nonDeleted");function D(o){const e=o.filter(s=>s.anchorStatus==="detached"),t=o.filter(s=>s.anchorStatus!=="detached");return[...e,...t]}d(D,"orderedForDisplay");function X(o,e){const t=o.units[e];return t===void 0?{line:1,endLine:1}:{line:t.start,endLine:t.end}}d(X,"unitRange");function L(o,e){const t=xe(o,{line:e.line-1,endLine:e.endLine});return t.kind==="detached"?{range:e,detached:!0}:{range:{line:t.line+1,endLine:Math.max(t.line+1,t.endLine)},detached:!1}}d(L,"mapRange");function Je(o,e,t){const s=e-1,i=o.get(s);if(i!==void 0)return i+1;for(let n=1;n<t;n++){const r=o.get(s+n);if(r!==void 0)return r+1;const c=o.get(s-n);if(c!==void 0)return c+1}return 1}d(Je,"mapLine");function Qe(o,e){if(e.detached)return{...o,anchorStatus:"detached",originalRange:o.originalRange??{line:o.line,endLine:o.endLine}};if(o.anchorStatus==="detached")return o;const t=e.range.line!==o.line||e.range.endLine!==o.endLine;return{...o,line:e.range.line,endLine:e.range.endLine,anchorStatus:t?"shifted":o.anchorStatus}}d(Qe,"applyMappedRange");function Ze(o,e){return o.map(t=>{if(t.anchorStatus==="detached")return{id:t.id,detached:!0};const s=L(e,{line:t.line,endLine:t.endLine});return s.detached?{id:t.id,detached:!0}:{id:t.id,anchor:s.range}})}d(Ze,"batchEntries");function U(o,e,t){const s=t??o.findIndex(c=>c.includes(e)),i=o[s];if(i===void 0)return o;const n=i.indexOf(e);if(n===-1)return o;const r=[...o];return r[s]=`${i.slice(0,n)}${F}${i.slice(n)}`,r}d(U,"markAtToken");function b(o){return o instanceof Error?o.message:String(o)}d(b,"describe");export{mt as ReviewDocumentSurface};
@@ -1,57 +0,0 @@
1
- import type { RenderedDoc } from '../../../core/termrender/termrender.js';
2
- import type { ReviewState } from './state.js';
3
- /** Width prose is rendered at for a given terminal width: 2-col left
4
- * margin + 2-col gutter before the content, capped for readability. */
5
- export declare function renderWidthForCols(cols: number): number;
6
- /** The body rectangle a rendered row is painted into: the terminal minus the
7
- * 4-col gutter prefix. Diagram blocks render at this width (no prose cap),
8
- * and every emitted body row is contained within it. */
9
- export declare function contentWidthForCols(cols: number): number;
10
- /** Body width left after an optional line-number gutter. */
11
- export declare function bodyWidth(cols: number, gutterW?: number): number;
12
- /** The mapped render this surface paints: prose at the readability cap,
13
- * diagrams at the full body width. */
14
- export declare function renderReviewDoc(content: string, cols: number): RenderedDoc;
15
- /** Widest painted row, in display cells, for a body window. */
16
- export declare function widestVisibleRow(doc: RenderedDoc, scroll: number, bodyHeight: number): number;
17
- /** How far the body can pan right, given what is currently on screen. Zero
18
- * when nothing visible overflows — which is also what makes h/l contextual:
19
- * the keys only pan while an overflowing row is in view. */
20
- export declare function maxHScroll(state: ReviewState, doc: RenderedDoc, cols: number, rows: number, gutterW?: number): number;
21
- /** Pan the body horizontally, clamped to what is currently reachable. The
22
- * stored offset is only ever clamped against the live window, so vertical
23
- * scrolling and resize can never leave it pointing past the content. */
24
- export declare function panBy(state: ReviewState, delta: number, doc: RenderedDoc, cols: number, rows: number, gutterW?: number): ReviewState;
25
- /** Cells one h/l press pans by — a chunk large enough to cross a diagram in a
26
- * few presses, small enough to keep orientation. */
27
- export declare const PAN_STEP = 8;
28
- /** One labeled key. A key is never shown without what it does. */
29
- export interface KeyHint {
30
- key: string;
31
- label: string;
32
- /** Lower survives a narrow pane longer. */
33
- priority: number;
34
- }
35
- /** The hints that fit `width`, in their declared order. When they do not all
36
- * fit, the least important are dropped whole — never cut mid-label. */
37
- export declare function fitHints(hints: readonly KeyHint[], width: number): KeyHint[];
38
- /** The comment list's key bar, for the grouped list the surface paints itself. */
39
- export declare function listHintBar(width: number): string;
40
- /** Reserved (non-body) rows for each mode's fixed header/footer chrome. Kept in
41
- * sync with renderReviewFrame so scroll math can clamp before a repaint — the
42
- * compose case counts the same hard-wrapped input lines the frame renders. */
43
- export declare function reservedRows(state: ReviewState, cols: number): number;
44
- export declare function renderReviewFrame(state: ReviewState, fileLabel: string, doc: RenderedDoc, cols: number, rows: number, opts?: {
45
- lineNumbers?: boolean;
46
- notice?: string;
47
- }): string[];
48
- export interface ReviewSurfaceKind {
49
- /** `markdown` renders the file AS a document; `code` renders it as a
50
- * syntax-highlighted source panel with a line-number gutter. */
51
- doc: 'markdown' | 'code';
52
- /** Fence language for `doc: 'code'` (see `fenceLanguageFor`). */
53
- language?: string;
54
- }
55
- /** How a reviewed file is presented: markdown renders as a document, anything
56
- * else as a syntax-highlighted source panel. */
57
- export declare function docSurface(absFile: string): ReviewSurfaceKind;
@@ -1 +0,0 @@
1
- var ee=Object.defineProperty;var a=(e,n)=>ee(e,"name",{value:n,configurable:!0});import ne from"string-width";import{renderMarkdownBlockAware as te}from"../../../core/termrender/termrender.js";import{fenceLanguageFor as oe,isMarkdownFile as re}from"../../../core/termrender/code-doc.js";import{renderInputBuffer as H}from"../tui/render.js";import{BOLD as v,CYAN as g,DIM as $,ESC as T,RESET as i,YELLOW as S,centerHorizontal as I,clipLine as B,hline as ie,panLine as le,sanitize as se,truncate as ae,visibleWidth as M}from"../tui/ansi.js";import{commentedUnitSet as ce,selectedUnitBounds as he}from"./state.js";function O(e){return Math.min(Math.max(20,e-6),120)}a(O,"renderWidthForCols");function _(e){return Math.max(20,e-4)}a(_,"contentWidthForCols");function F(e,n=0){return Math.max(1,_(e)-(n>0?n+1:0))}a(F,"bodyWidth");function We(e,n){return te(e,O(n),_(n))}a(We,"renderReviewDoc");function N(e,n,o){const t=[];for(let h=0;h<o;h++){const l=n+h;t.push(l<e.lines.length?{abs:l,line:e.lines[l]}:{abs:null,line:""})}n>0&&t.length>0&&(t[0]={abs:null,line:` ${$}\u2191 ${n} more above${i}`});const s=e.lines.length-(n+o);return s>0&&t.length>0&&(t[t.length-1]={abs:null,line:` ${$}\u2193 ${s} more below${i}`}),t}a(N,"paintedBodyRows");function P(e,n,o){let t=0;for(const s of N(e,n,o))t=Math.max(t,M(s.line));return t}a(P,"widestVisibleRow");function me(e,n,o,t,s=0){const h=Math.max(1,t-ge(e,o)),l=Math.max(0,n.lines.length-h),m=Math.max(0,Math.min(e.scroll,l));return Math.max(0,P(n,m,h)-F(o,s))}a(me,"maxHScroll");function Re(e,n,o,t,s,h=0){const l=me(e,o,t,s,h),m=Math.max(0,Math.min(e.hscroll+n,l));return m===e.hscroll?e:{...e,hscroll:m}}a(Re,"panBy");const Ie=8,D=`${T}48;5;236m`;function ue(e,n){const o=Math.max(0,n-ne(se(e)));return D+e.replaceAll(i,i+D)+" ".repeat(o)+i}a(ue,"tintRow");const A=`${T}48;5;237m`;function y(e,n){const o=B(e,n),t=Math.max(0,n-M(o));return` ${A}${o.replaceAll(i,i+A)}${" ".repeat(t)}${i}`}a(y,"chromeRow");const pe=[{key:"c",label:"comment",priority:0},{key:"C",label:"all comments",priority:2},{key:"U",label:"undo",priority:6},{key:"a",label:"agent pane",priority:3},{key:"e",label:"$EDITOR",priority:7},{key:"s",label:"submit",priority:4},{key:"x",label:"cancel",priority:8},{key:"?",label:"all keys",priority:1},{key:"esc",label:"close",priority:5}],$e=[{key:"enter",label:"save",priority:0},{key:"^\u23CE/^F",label:"save + hand to its own agent",priority:2},{key:"^J/\u2325\u23CE",label:"newline",priority:3},{key:"esc",label:"discard",priority:1}],U=[{key:"\u2191\u2193/jk",label:"move",priority:1},{key:"enter/e",label:"edit",priority:0},{key:"d",label:"delete",priority:2},{key:"c",label:"new comment",priority:3},{key:"esc",label:"back",priority:0}];function de(e){return`${v}${g}${e.key}${i} ${e.label}`}a(de,"hintText");function fe(e,n){const t=a(l=>1+l.reduce((m,x,c)=>m+M(`${x.key} ${x.label}`)+(c===0?0:3),0),"cost");let s=[...e];const h=[...e].sort((l,m)=>m.priority-l.priority);for(const l of h){if(t(s)<=n)break;s=s.filter(m=>m!==l)}return s}a(fe,"fitHints");function E(e,n){const o=fe(e,n);return y(` ${o.map(de).join(` ${$}\xB7${i} `)}`,n)}a(E,"hintBar");function Ce(e){return E(U,e)}a(Ce,"listHintBar");const K=[{title:"Comment",rows:[["c / enter","comment on the highlighted block (J/K widens it)"],["C","all comments \u2014 edit or delete them there"],["U","undo your last comment"],["^\u23CE / ^F","while writing: save + hand to its own agent"]]},{title:"Read",rows:[["\u2191\u2193 / j k","next / previous block"],["J / K","extend the highlight down / up"],["u / d","half a page up / down"],["\u2190\u2192 / h l","pan a diagram wider than the pane"]]},{title:"Finish",rows:[["a","open the agent pane beside the document"],["e","edit the document yourself in $EDITOR"],["s s","approve and submit the review"],["x x","cancel the review"],["esc","leave \u2014 the review stays open in the inbox"]]}],ye=12;function xe(e){const n=[y(` ${v}Keys${i} ${$}? or esc closes this${i}`,e)];for(const o of K){n.push(y("",e)),n.push(y(` ${S}${o.title}${i}`,e));for(const[t,s]of o.rows)n.push(y(` ${v}${g}${t.padEnd(ye)}${i}${s}`,e))}return n}a(xe,"helpPanel");const be=1+K.reduce((e,n)=>e+2+n.rows.length,0);function ge(e,n){if(e.mode==="view")return 4;if(e.mode==="compose"){const t=e.compose,s=Math.min(Math.max(20,n-4),120);return 6+(t?H(t.buffer,t.cursor,Math.max(10,s-2)).length:1)}return e.mode==="list"?3+Math.max(1,e.comments.length)+2:3+be}a(ge,"reservedRows");function He(e,n,o,t,s,h){const l=Math.min(Math.max(20,t-4),120),m=O(t),x=["",` ${v}${g}Review \u2014 ${n}${i} ${$}${e.comments.length} comment${e.comments.length===1?"":"s"}${i}`,` ${$}${ie(l)}${i}`],c=[];if(e.mode==="compose"&&e.compose){const r=e.compose,u=r.anchor.line===r.anchor.endLine?`L${r.anchor.line}`:`L${r.anchor.line}-${r.anchor.endLine}`;c.push(` ${S}${r.editingId!==null?"Edit comment":"Comment"} on ${u}:${i}`);for(const p of H(r.buffer,r.cursor,Math.max(10,l-2)))c.push(` ${p}`);c.push(""),c.push(E($e,l))}else e.mode==="list"?(e.comments.length===0?c.push(` ${$}(no comments yet \u2014 press c to comment on the highlighted block)${i}`):e.comments.forEach((r,u)=>{const p=r.line===r.endLine?`L${r.line}`:`L${r.line}-${r.endLine}`,L=u===e.listIndex?`${g}\u25B8${i}`:" ",b=ae(r.comment.replace(/\n/g," / "),Math.max(10,l-14));c.push(` ${L} ${$}[${p}]${i} ${b}`)}),c.push(""),c.push(E(U,l))):e.mode==="help"?c.push(...xe(l)):c.push(E(pe,l));h?.notice!==void 0&&c.length>0&&(c[c.length-1]=y(` ${S}${h.notice}${i}`,l));const j=x.length+c.length,k=Math.max(1,s-j),J=Math.max(0,o.lines.length-k),C=Math.max(0,Math.min(e.scroll,J)),d=h?.lineNumbers===!0?String(o.lines.length).length:0,W=F(t,d),Y=P(o,C,k),z=Math.max(0,Y-W),G=Math.max(0,Math.min(e.hscroll,z)),{lo:V,hi:q}=he(e),Q=ce(e),f=[];for(const r of N(o,C,k)){if(r.abs===null){f.push(` ${" ".repeat(d>0?d+1:0)}${r.line}`);continue}const u=le(r.line,G,W),p=e.rowUnits[r.abs]??null,L=o.spans[r.abs]?.[0],b=d>0?L===void 0?" ".repeat(d+1):`${$}${String(L).padStart(d)}${i} `:"",Z=Math.min(W,Math.max(m,M(u)));p!==null&&p>=V&&p<=q?f.push(` ${g}\u258C${i} ${b}${ue(u,Z)}`):p!==null&&Q.has(p)?f.push(` ${S}\u258E${i} ${b}${u}`):f.push(` ${b}${u}`)}for(;f.length<k;)f.push("");const w=Math.min(t,Math.max(l+2,m+4+(d>0?d+1:0))),X=f.map(r=>{const u=M(r)>w?t:w;return I([r],t,u)[0]??""}),R=[...I(x,t,w),...X,...I(c,t,w)];for(;R.length<s;)R.push("");return R.slice(0,s).map(r=>B(r,t))}a(He,"renderReviewFrame");function Te(e){return re(e)?{doc:"markdown"}:{doc:"code",language:oe(e)}}a(Te,"docSurface");export{Ie as PAN_STEP,F as bodyWidth,_ as contentWidthForCols,Te as docSurface,fe as fitHints,Ce as listHintBar,me as maxHScroll,Re as panBy,We as renderReviewDoc,He as renderReviewFrame,O as renderWidthForCols,ge as reservedRows,P as widestVisibleRow};
@@ -1,69 +0,0 @@
1
- /** A semantic keypress for the review surface. Textual commands retain their
2
- * text because their meaning is mode-dependent: `j` navigates in view/list
3
- * mode and inserts in compose mode, for example. */
4
- export type ReviewKey = {
5
- type: 'moveUnit';
6
- delta: -1 | 1;
7
- text: 'j' | 'k';
8
- } | {
9
- type: 'extendUnit';
10
- delta: -1 | 1;
11
- text: 'J' | 'K';
12
- } | {
13
- type: 'scrollPage';
14
- delta: -1 | 1;
15
- text?: 'u' | 'd';
16
- } | {
17
- type: 'pan';
18
- delta: -1 | 1;
19
- text?: 'h' | 'l';
20
- } | {
21
- type: 'space';
22
- text: ' ';
23
- } | {
24
- type: 'help';
25
- text: '?';
26
- } | {
27
- type: 'listEdit';
28
- text: 'e';
29
- } | {
30
- type: 'cancel';
31
- text?: 'q';
32
- } | {
33
- type: 'confirm';
34
- } | {
35
- type: 'confirmFork';
36
- } | {
37
- type: 'tab';
38
- reverse: boolean;
39
- } | {
40
- type: 'composeNewline';
41
- } | {
42
- type: 'composeBackspace';
43
- } | {
44
- type: 'composeWordBackspace';
45
- } | {
46
- type: 'composeDelete';
47
- } | {
48
- type: 'composeHome';
49
- } | {
50
- type: 'composeEnd';
51
- } | {
52
- type: 'composeMove';
53
- direction: 'wordLeft' | 'wordRight';
54
- } | {
55
- type: 'arrow';
56
- direction: 'left' | 'right' | 'up' | 'down';
57
- } | {
58
- type: 'printable';
59
- text: string;
60
- } | {
61
- type: 'paste';
62
- text: string;
63
- };
64
- /** Return text that compose mode inserts. Semantic textual commands deliberately
65
- * retain their payload so compose can preserve the old branch order. */
66
- export declare function reviewKeyText(key: ReviewKey): string | undefined;
67
- /** Match one complete pi-tui input chunk. pi-tui owns ESC/meta disambiguation;
68
- * this function has neither terminal state nor a fallback raw-sequence parser. */
69
- export declare function matchReviewKey(data: string): ReviewKey | null;
@@ -1 +0,0 @@
1
- var a=Object.defineProperty;var f=(n,e)=>a(n,"name",{value:e,configurable:!0});import{Key as r,decodeKittyPrintable as o,matchesKey as t,parseKey as u}from"@earendil-works/pi-tui";import{normalizeShiftedMeta as s}from"../../../core/keybindings/index.js";function m(n){switch(n.type){case"moveUnit":case"extendUnit":case"space":case"help":case"listEdit":case"printable":case"paste":return n.text;case"scrollPage":case"pan":case"cancel":return n.text;default:return}}f(m,"reviewKeyText");function g(n){const e=s(n);if(t(e,r.ctrl("j"))||t(e,r.alt("enter")))return{type:"composeNewline"};if(t(e,r.alt("backspace"))||t(e,r.ctrl("w")))return{type:"composeWordBackspace"};if(t(e,r.backspace))return{type:"composeBackspace"};if(t(e,r.delete))return{type:"composeDelete"};if(t(e,r.alt("left"))||t(e,r.ctrl("left"))||t(e,r.super("left"))||t(e,r.alt("b")))return{type:"composeMove",direction:"wordLeft"};if(t(e,r.alt("right"))||t(e,r.ctrl("right"))||t(e,r.super("right"))||t(e,r.alt("f")))return{type:"composeMove",direction:"wordRight"};if(t(e,r.home)||t(e,r.ctrl("a")))return{type:"composeHome"};if(t(e,r.end)||t(e,r.ctrl("e")))return{type:"composeEnd"};if(t(e,r.shift("tab")))return{type:"tab",reverse:!0};if(t(e,r.tab))return{type:"tab",reverse:!1};if(t(e,r.ctrl("enter"))||t(e,r.ctrl("f")))return{type:"confirmFork"};if(t(e,r.enter))return{type:"confirm"};if(t(e,r.escape))return{type:"cancel"};if(t(e,r.up))return{type:"arrow",direction:"up"};if(t(e,r.down))return{type:"arrow",direction:"down"};if(t(e,r.left))return{type:"arrow",direction:"left"};if(t(e,r.right))return{type:"arrow",direction:"right"};if(t(e,r.pageUp))return{type:"scrollPage",delta:-1};if(t(e,r.pageDown))return{type:"scrollPage",delta:1};if(t(e,r.shift("j")))return{type:"extendUnit",delta:1,text:"J"};if(t(e,r.shift("k")))return{type:"extendUnit",delta:-1,text:"K"};if(t(e,r.shift("c")))return{type:"printable",text:"C"};if(t(e,r.shift("u")))return{type:"printable",text:"U"};if(t(e,"j"))return{type:"moveUnit",delta:1,text:"j"};if(t(e,"k"))return{type:"moveUnit",delta:-1,text:"k"};if(t(e,"u"))return{type:"scrollPage",delta:-1,text:"u"};if(t(e,"d"))return{type:"scrollPage",delta:1,text:"d"};if(t(e,"h"))return{type:"pan",delta:-1,text:"h"};if(t(e,"l"))return{type:"pan",delta:1,text:"l"};if(t(e,r.space))return{type:"space",text:" "};if(t(e,r.question))return{type:"help",text:"?"};if(t(e,"e"))return{type:"listEdit",text:"e"};if(t(e,"q"))return{type:"cancel",text:"q"};const p=u(e),i=d(n,p);return i==="?"?{type:"help",text:i}:i!==void 0?{type:"printable",text:i}:p!==void 0?null:[...n].length>1?{type:"paste",text:n}:null}f(g,"matchReviewKey");function d(n,e){const p=o(n);if(p!==void 0&&l(p))return p;if(e!==void 0){const i=e.startsWith("shift+"),c=i?e.slice(6):e;if([...c].length===1&&l(c))return i&&/^[a-z]$/.test(c)?c.toUpperCase():c}return[...n].length===1&&l(n)?n:void 0}f(d,"printableText");function l(n){return!new RegExp("\\p{C}","u").test(n)}f(l,"isPrintable");export{g as matchReviewKey,m as reviewKeyText};