@north-light/cli 0.3.707 → 0.3.708

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 (183) 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/human.d.ts +9 -6
  6. package/dist/api/dto/inbox.d.ts +2 -0
  7. package/dist/api/dto/review-comments.d.ts +12 -35
  8. package/dist/api/dto/reviews.d.ts +3 -10
  9. package/dist/api/routes.d.ts +0 -1
  10. package/dist/api/routes.js +1 -1
  11. package/dist/builtin-memory/05-kinds/review/companion/00-base.md +2 -2
  12. package/dist/builtin-memory/crouter-sdk/release-notes.md +6 -0
  13. package/dist/clients/attach/chrome/canvas-panels.d.ts +1 -1
  14. package/dist/clients/attach/chrome/canvas-panels.js +1 -1
  15. package/dist/clients/attach/chrome/roster.js +6 -6
  16. package/dist/clients/attach/chrome/status-line.js +1 -1
  17. package/dist/clients/attach/chrome/ticket-panel.js +1 -1
  18. package/dist/clients/attach/input/controller.d.ts +0 -1
  19. package/dist/clients/attach/input/controller.js +3 -3
  20. package/dist/clients/attach/input/overlay-owner.d.ts +0 -1
  21. package/dist/clients/attach/input/overlay-owner.js +1 -1
  22. package/dist/clients/attach/session/keys.d.ts +0 -2
  23. package/dist/clients/attach/session/keys.js +1 -1
  24. package/dist/clients/attach/session/surface-host.d.ts +0 -5
  25. package/dist/clients/attach/session/surface-host.js +1 -1
  26. package/dist/clients/attach/viewer.js +544 -559
  27. package/dist/clients/editor-roundtrip.js +3 -0
  28. package/dist/clients/inbox/controller.d.ts +1 -6
  29. package/dist/clients/inbox/controller.js +1 -1
  30. package/dist/clients/inbox/dto-adapt.js +1 -1
  31. package/dist/clients/inbox/tui/page-body.js +1 -1
  32. package/dist/clients/inbox/tui/render.js +2 -2
  33. package/dist/clients/open-browser.d.ts +2 -0
  34. package/dist/clients/open-browser.js +1 -0
  35. package/dist/clients/surfaces/host.d.ts +0 -6
  36. package/dist/commands/human/review.js +1 -1
  37. package/dist/commands/sys/context/admin/shell.js +1 -1
  38. package/dist/core/canvas/schema-pg/025-review-anchors.sql +19 -0
  39. package/dist/core/canvas/schema-version.d.ts +1 -1
  40. package/dist/core/canvas/schema-version.js +1 -1
  41. package/dist/core/human/page-markdown.js +10 -12
  42. package/dist/core/human/tickets.js +1 -1
  43. package/dist/core/human/types.d.ts +4 -6
  44. package/dist/core/keybindings/attach-control.d.ts +0 -3
  45. package/dist/core/keybindings/attach-control.js +1 -1
  46. package/dist/core/keybindings/catalog.d.ts +1 -1
  47. package/dist/core/keybindings/catalog.js +1 -1
  48. package/dist/core/review/anchors.d.ts +28 -0
  49. package/dist/core/review/anchors.js +6 -0
  50. package/dist/core/review/comments.d.ts +2 -2
  51. package/dist/core/review/comments.js +7 -8
  52. package/dist/core/review/companion.d.ts +2 -1
  53. package/dist/core/review/companion.js +1 -1
  54. package/dist/core/review/document.d.ts +4 -17
  55. package/dist/core/review/document.js +1 -2
  56. package/dist/core/review/fork.js +2 -4
  57. package/dist/core/review/project.d.ts +1 -1
  58. package/dist/core/review/project.js +2 -2
  59. package/dist/core/review/realize.js +1 -1
  60. package/dist/core/review/stage.d.ts +2 -9
  61. package/dist/core/review/stage.js +1 -1
  62. package/dist/core/review/types.d.ts +16 -12
  63. package/dist/core/review/types.js +1 -1
  64. package/dist/core/runtime/broker-cli.js +3 -3
  65. package/dist/core/runtime/broker-extension-render.js +1 -1
  66. package/dist/core/runtime/tmux-bindings.js +3 -3
  67. package/dist/daemon/api/canvas-host.js +1 -1
  68. package/dist/daemon/api/document-page.d.ts +12 -1
  69. package/dist/daemon/api/document-page.js +6 -6
  70. package/dist/daemon/api/handlers/inbox.js +1 -1
  71. package/dist/daemon/api/handlers/review-comments.js +1 -1
  72. package/dist/daemon/api/handlers/reviews.js +1 -1
  73. package/dist/daemon/api/map.js +2 -2
  74. package/dist/daemon/api/review-page.d.ts +3 -0
  75. package/dist/daemon/api/review-page.js +13 -0
  76. package/dist/daemon/broker-memory-cap.d.ts +9 -0
  77. package/dist/daemon/broker-memory-cap.js +2 -0
  78. package/dist/daemon/broker-signals/bus.d.ts +1 -1
  79. package/dist/daemon/broker-signals/bus.js +1 -1
  80. package/dist/daemon/crtrd.js +14 -14
  81. package/dist/daemon/machine-daemon.js +1 -1
  82. package/dist/daemon/review/comment-notify.js +2 -2
  83. package/dist/daemon/review/deliver.d.ts +2 -2
  84. package/dist/daemon/review/deliver.js +6 -2
  85. package/dist/daemon/review/finish.js +1 -1
  86. package/dist/doc-editor/Geist-Variable.woff2 +0 -0
  87. package/dist/doc-editor/GeistMono-Variable.woff2 +0 -0
  88. package/dist/doc-editor/editor.css +1 -1
  89. package/dist/doc-editor/review.css +2 -0
  90. package/dist/doc-editor/review.js +149 -0
  91. package/dist/pi-extensions/canvas-review-boundary.js +3 -3
  92. package/docs/sdk/release-notes.md +6 -0
  93. package/package.json +13 -4
  94. package/packages/crouter-api/dist/api/client.js +0 -3
  95. package/packages/crouter-api/dist/api/contract.js +1 -1
  96. package/packages/crouter-api/dist/api/routes.js +0 -1
  97. package/packages/crouter-api/dist/clients/attach/chrome/canvas-panels.js +3 -3
  98. package/packages/crouter-api/dist/clients/attach/chrome/roster.js +9 -20
  99. package/packages/crouter-api/dist/clients/attach/chrome/status-line.js +1 -6
  100. package/packages/crouter-api/dist/clients/attach/chrome/ticket-panel.js +1 -1
  101. package/packages/crouter-api/dist/clients/attach/input/controller.js +0 -3
  102. package/packages/crouter-api/dist/clients/attach/input/overlay-owner.js +0 -7
  103. package/packages/crouter-api/dist/clients/attach/session/keys.js +0 -1
  104. package/packages/crouter-api/dist/clients/attach/session/surface-host.js +0 -17
  105. package/packages/crouter-api/dist/clients/attach/viewer.js +0 -37
  106. package/packages/crouter-api/dist/clients/{inbox/review/roundtrip.js → editor-roundtrip.js} +1 -1
  107. package/packages/crouter-api/dist/clients/inbox/controller.js +12 -31
  108. package/packages/crouter-api/dist/clients/inbox/dto-adapt.js +1 -0
  109. package/packages/crouter-api/dist/clients/inbox/tui/page-body.js +0 -7
  110. package/packages/crouter-api/dist/clients/inbox/tui/render.js +0 -7
  111. package/packages/crouter-api/dist/clients/open-browser.js +6 -0
  112. package/packages/crouter-api/dist/commands/human/review.js +17 -18
  113. package/packages/crouter-api/dist/commands/sys/context/admin/shell.js +1 -1
  114. package/packages/crouter-api/dist/core/canvas/schema-version.js +1 -1
  115. package/packages/crouter-api/dist/core/human/page-markdown.js +2 -6
  116. package/packages/crouter-api/dist/core/human/tickets.js +2 -11
  117. package/packages/crouter-api/dist/core/keybindings/attach-control.js +0 -1
  118. package/packages/crouter-api/dist/core/keybindings/catalog.js +1 -3
  119. package/packages/crouter-api/dist/core/review/anchors.js +91 -0
  120. package/packages/crouter-api/dist/core/review/comments.js +27 -46
  121. package/packages/crouter-api/dist/core/review/companion.js +5 -9
  122. package/packages/crouter-api/dist/core/review/document.js +17 -89
  123. package/packages/crouter-api/dist/core/review/project.js +2 -1
  124. package/packages/crouter-api/dist/core/review/types.js +2 -2
  125. package/packages/crouter-api/dist/core/runtime/tmux-bindings.js +0 -5
  126. package/packages/crouter-api/dist/daemon/api/map.js +2 -6
  127. package/packages/crouter-api/dist/daemon/broker-signals/bus.js +1 -1
  128. package/packages/crouter-api/dist/daemon/review/deliver.js +4 -3
  129. package/packages/crouter-api/dist/daemon/review/finish.js +26 -47
  130. package/packages/crouter-api/package.json +1 -1
  131. package/packages/crouter-identity/package.json +1 -1
  132. package/packages/crouter-plugin/package.json +3 -3
  133. package/runtime.lock.json +1740 -505
  134. package/dist/clients/attach/overlays/file-review.d.ts +0 -10
  135. package/dist/clients/attach/overlays/file-review.js +0 -2
  136. package/dist/clients/inbox/review/anchors.d.ts +0 -41
  137. package/dist/clients/inbox/review/anchors.js +0 -1
  138. package/dist/clients/inbox/review/comments-client.d.ts +0 -74
  139. package/dist/clients/inbox/review/comments-client.js +0 -1
  140. package/dist/clients/inbox/review/companion-pane.d.ts +0 -47
  141. package/dist/clients/inbox/review/companion-pane.js +0 -1
  142. package/dist/clients/inbox/review/document-surface.d.ts +0 -212
  143. package/dist/clients/inbox/review/document-surface.js +0 -2
  144. package/dist/clients/inbox/review/frame.d.ts +0 -57
  145. package/dist/clients/inbox/review/frame.js +0 -1
  146. package/dist/clients/inbox/review/keys.d.ts +0 -69
  147. package/dist/clients/inbox/review/keys.js +0 -1
  148. package/dist/clients/inbox/review/launch.d.ts +0 -16
  149. package/dist/clients/inbox/review/launch.js +0 -1
  150. package/dist/clients/inbox/review/live-source.d.ts +0 -24
  151. package/dist/clients/inbox/review/live-source.js +0 -1
  152. package/dist/clients/inbox/review/nvim.d.ts +0 -15
  153. package/dist/clients/inbox/review/nvim.js +0 -1
  154. package/dist/clients/inbox/review/remap.d.ts +0 -51
  155. package/dist/clients/inbox/review/remap.js +0 -1
  156. package/dist/clients/inbox/review/review-client.d.ts +0 -43
  157. package/dist/clients/inbox/review/review-client.js +0 -1
  158. package/dist/clients/inbox/review/roundtrip.js +0 -3
  159. package/dist/clients/inbox/review/state.d.ts +0 -153
  160. package/dist/clients/inbox/review/state.js +0 -4
  161. package/dist/clients/inbox/review-adapter.d.ts +0 -17
  162. package/dist/clients/inbox/review-adapter.js +0 -1
  163. package/dist/core/review/remap.d.ts +0 -24
  164. package/dist/core/review/remap.js +0 -19
  165. package/dist/core/review/signal.d.ts +0 -5
  166. package/dist/core/review/signal.js +0 -1
  167. package/packages/crouter-api/dist/clients/attach/overlays/file-review.js +0 -146
  168. package/packages/crouter-api/dist/clients/inbox/review/anchors.js +0 -89
  169. package/packages/crouter-api/dist/clients/inbox/review/comments-client.js +0 -103
  170. package/packages/crouter-api/dist/clients/inbox/review/companion-pane.js +0 -109
  171. package/packages/crouter-api/dist/clients/inbox/review/document-surface.js +0 -1268
  172. package/packages/crouter-api/dist/clients/inbox/review/frame.js +0 -309
  173. package/packages/crouter-api/dist/clients/inbox/review/keys.js +0 -133
  174. package/packages/crouter-api/dist/clients/inbox/review/launch.js +0 -170
  175. package/packages/crouter-api/dist/clients/inbox/review/live-source.js +0 -160
  176. package/packages/crouter-api/dist/clients/inbox/review/nvim.js +0 -43
  177. package/packages/crouter-api/dist/clients/inbox/review/remap.js +0 -157
  178. package/packages/crouter-api/dist/clients/inbox/review/review-client.js +0 -125
  179. package/packages/crouter-api/dist/clients/inbox/review/state.js +0 -315
  180. package/packages/crouter-api/dist/clients/inbox/review-adapter.js +0 -43
  181. package/packages/crouter-api/dist/core/review/signal.js +0 -12
  182. package/packages/crouter-api/dist/core/termrender/code-doc.js +0 -92
  183. /package/dist/clients/{inbox/review/roundtrip.d.ts → editor-roundtrip.d.ts} +0 -0
@@ -1,309 +0,0 @@
1
- import stringWidth from 'string-width';
2
- import { renderMarkdownBlockAware } from '../../../core/termrender/termrender.js';
3
- import { fenceLanguageFor, isMarkdownFile } from '../../../core/termrender/code-doc.js';
4
- import { renderInputBuffer } from '../tui/render.js';
5
- import { BOLD, CYAN, DIM, ESC, RESET, YELLOW, centerHorizontal, clipLine, hline, panLine, sanitize, truncate, visibleWidth } from '../tui/ansi.js';
6
- import { commentedUnitSet, selectedUnitBounds } from './state.js';
7
- // ── Rendering (pure) ─────────────────────────────────────────────────────────
8
- /** Width prose is rendered at for a given terminal width: 2-col left
9
- * margin + 2-col gutter before the content, capped for readability. */
10
- export function renderWidthForCols(cols) {
11
- return Math.min(Math.max(20, cols - 6), 120);
12
- }
13
- /** The body rectangle a rendered row is painted into: the terminal minus the
14
- * 4-col gutter prefix. Diagram blocks render at this width (no prose cap),
15
- * and every emitted body row is contained within it. */
16
- export function contentWidthForCols(cols) {
17
- return Math.max(20, cols - 4);
18
- }
19
- /** Body width left after an optional line-number gutter. */
20
- export function bodyWidth(cols, gutterW = 0) {
21
- return Math.max(1, contentWidthForCols(cols) - (gutterW > 0 ? gutterW + 1 : 0));
22
- }
23
- /** The mapped render this surface paints: prose at the readability cap,
24
- * diagrams at the full body width. */
25
- export function renderReviewDoc(content, cols) {
26
- return renderMarkdownBlockAware(content, renderWidthForCols(cols), contentWidthForCols(cols));
27
- }
28
- /** Body rows as they are actually painted. Vertical-scroll indicators replace
29
- * their endpoint rows, so content behind one cannot advertise or claim h/l. */
30
- function paintedBodyRows(doc, scroll, bodyHeight) {
31
- const rows = [];
32
- for (let i = 0; i < bodyHeight; i++) {
33
- const abs = scroll + i;
34
- rows.push(abs < doc.lines.length ? { abs, line: doc.lines[abs] } : { abs: null, line: '' });
35
- }
36
- if (scroll > 0 && rows.length > 0)
37
- rows[0] = { abs: null, line: ` ${DIM}↑ ${scroll} more above${RESET}` };
38
- const remaining = doc.lines.length - (scroll + bodyHeight);
39
- if (remaining > 0 && rows.length > 0)
40
- rows[rows.length - 1] = { abs: null, line: ` ${DIM}↓ ${remaining} more below${RESET}` };
41
- return rows;
42
- }
43
- /** Widest painted row, in display cells, for a body window. */
44
- export function widestVisibleRow(doc, scroll, bodyHeight) {
45
- let widest = 0;
46
- for (const row of paintedBodyRows(doc, scroll, bodyHeight))
47
- widest = Math.max(widest, visibleWidth(row.line));
48
- return widest;
49
- }
50
- /** How far the body can pan right, given what is currently on screen. Zero
51
- * when nothing visible overflows — which is also what makes h/l contextual:
52
- * the keys only pan while an overflowing row is in view. */
53
- export function maxHScroll(state, doc, cols, rows, gutterW = 0) {
54
- const bodyHeight = Math.max(1, rows - reservedRows(state, cols));
55
- const maxScroll = Math.max(0, doc.lines.length - bodyHeight);
56
- const scroll = Math.max(0, Math.min(state.scroll, maxScroll));
57
- return Math.max(0, widestVisibleRow(doc, scroll, bodyHeight) - bodyWidth(cols, gutterW));
58
- }
59
- /** Pan the body horizontally, clamped to what is currently reachable. The
60
- * stored offset is only ever clamped against the live window, so vertical
61
- * scrolling and resize can never leave it pointing past the content. */
62
- export function panBy(state, delta, doc, cols, rows, gutterW = 0) {
63
- const max = maxHScroll(state, doc, cols, rows, gutterW);
64
- const next = Math.max(0, Math.min(state.hscroll + delta, max));
65
- return next === state.hscroll ? state : { ...state, hscroll: next };
66
- }
67
- /** Cells one h/l press pans by — a chunk large enough to cross a diagram in a
68
- * few presses, small enough to keep orientation. */
69
- export const PAN_STEP = 8;
70
- // Single-hue anchor tint (a dark neutral step below the CYAN gutter bar).
71
- // termrender's only reset is `\x1b[0m`, so re-arming the background after each
72
- // reset keeps the tint alive across inner styling. Heading rows carry their
73
- // own background and won't show the tint — the gutter bar still marks them.
74
- const TINT_BG = `${ESC}48;5;236m`;
75
- function tintRow(row, width) {
76
- const pad = Math.max(0, width - stringWidth(sanitize(row)));
77
- return TINT_BG + row.replaceAll(RESET, RESET + TINT_BG) + ' '.repeat(pad) + RESET;
78
- }
79
- /** Background for the review's own chrome — the key bar and the help panel —
80
- * one step lighter than the selection tint so the two never read as one. */
81
- const CHROME_BG = `${ESC}48;5;237m`;
82
- /** A row of chrome: `text` padded to `width` cells on {@link CHROME_BG}. The
83
- * background is re-armed after every reset so inner styling cannot end it. */
84
- function chromeRow(text, width) {
85
- const clipped = clipLine(text, width);
86
- const pad = Math.max(0, width - visibleWidth(clipped));
87
- return ` ${CHROME_BG}${clipped.replaceAll(RESET, RESET + CHROME_BG)}${' '.repeat(pad)}${RESET}`;
88
- }
89
- const VIEW_HINTS = [
90
- { key: 'c', label: 'comment', priority: 0 },
91
- { key: 'C', label: 'all comments', priority: 2 },
92
- { key: 'U', label: 'undo', priority: 6 },
93
- { key: 'a', label: 'agent pane', priority: 3 },
94
- { key: 'e', label: '$EDITOR', priority: 7 },
95
- { key: 's', label: 'submit', priority: 4 },
96
- { key: 'x', label: 'cancel', priority: 8 },
97
- { key: '?', label: 'all keys', priority: 1 },
98
- { key: 'esc', label: 'close', priority: 5 },
99
- ];
100
- const COMPOSE_HINTS = [
101
- { key: 'enter', label: 'save', priority: 0 },
102
- { key: '^⏎/^F', label: 'save + hand to its own agent', priority: 2 },
103
- { key: '^J/⌥⏎', label: 'newline', priority: 3 },
104
- { key: 'esc', label: 'discard', priority: 1 },
105
- ];
106
- const LIST_HINTS = [
107
- { key: '↑↓/jk', label: 'move', priority: 1 },
108
- { key: 'enter/e', label: 'edit', priority: 0 },
109
- { key: 'd', label: 'delete', priority: 2 },
110
- { key: 'c', label: 'new comment', priority: 3 },
111
- { key: 'esc', label: 'back', priority: 0 },
112
- ];
113
- function hintText(hint) {
114
- return `${BOLD}${CYAN}${hint.key}${RESET} ${hint.label}`;
115
- }
116
- /** The hints that fit `width`, in their declared order. When they do not all
117
- * fit, the least important are dropped whole — never cut mid-label. */
118
- export function fitHints(hints, width) {
119
- const sep = 3; // ' · '
120
- const cost = (set) => 1 + set.reduce((sum, hint, i) => sum + visibleWidth(`${hint.key} ${hint.label}`) + (i === 0 ? 0 : sep), 0);
121
- let kept = [...hints];
122
- const byDropOrder = [...hints].sort((a, b) => b.priority - a.priority);
123
- for (const drop of byDropOrder) {
124
- if (cost(kept) <= width)
125
- break;
126
- kept = kept.filter((hint) => hint !== drop);
127
- }
128
- return kept;
129
- }
130
- function hintBar(hints, width) {
131
- const fitted = fitHints(hints, width);
132
- return chromeRow(` ${fitted.map(hintText).join(` ${DIM}·${RESET} `)}`, width);
133
- }
134
- /** The comment list's key bar, for the grouped list the surface paints itself. */
135
- export function listHintBar(width) {
136
- return hintBar(LIST_HINTS, width);
137
- }
138
- /** The help panel: every key, each beside what it does, grouped by task. */
139
- const HELP_SECTIONS = [
140
- {
141
- title: 'Comment',
142
- rows: [
143
- ['c / enter', 'comment on the highlighted block (J/K widens it)'],
144
- ['C', 'all comments — edit or delete them there'],
145
- ['U', 'undo your last comment'],
146
- ['^⏎ / ^F', 'while writing: save + hand to its own agent'],
147
- ],
148
- },
149
- {
150
- title: 'Read',
151
- rows: [
152
- ['↑↓ / j k', 'next / previous block'],
153
- ['J / K', 'extend the highlight down / up'],
154
- ['u / d', 'half a page up / down'],
155
- ['←→ / h l', 'pan a diagram wider than the pane'],
156
- ],
157
- },
158
- {
159
- title: 'Finish',
160
- rows: [
161
- ['a', 'open the agent pane beside the document'],
162
- ['e', 'edit the document yourself in $EDITOR'],
163
- ['s s', 'approve and submit the review'],
164
- ['x x', 'cancel the review'],
165
- ['esc', 'leave — the review stays open in the inbox'],
166
- ],
167
- },
168
- ];
169
- const HELP_KEY_COL = 12;
170
- function helpPanel(width) {
171
- const lines = [chromeRow(` ${BOLD}Keys${RESET} ${DIM}? or esc closes this${RESET}`, width)];
172
- for (const section of HELP_SECTIONS) {
173
- lines.push(chromeRow('', width));
174
- lines.push(chromeRow(` ${YELLOW}${section.title}${RESET}`, width));
175
- for (const [key, label] of section.rows) {
176
- lines.push(chromeRow(` ${BOLD}${CYAN}${key.padEnd(HELP_KEY_COL)}${RESET}${label}`, width));
177
- }
178
- }
179
- return lines;
180
- }
181
- const HELP_ROWS = 1 + HELP_SECTIONS.reduce((sum, section) => sum + 2 + section.rows.length, 0);
182
- /** Reserved (non-body) rows for each mode's fixed header/footer chrome. Kept in
183
- * sync with renderReviewFrame so scroll math can clamp before a repaint — the
184
- * compose case counts the same hard-wrapped input lines the frame renders. */
185
- export function reservedRows(state, cols) {
186
- const header = 3; // blank, title, divider
187
- if (state.mode === 'view')
188
- return header + 1;
189
- if (state.mode === 'compose') {
190
- const c = state.compose;
191
- const maxW = Math.min(Math.max(20, cols - 4), 120);
192
- const bufLines = c ? renderInputBuffer(c.buffer, c.cursor, Math.max(10, maxW - 2)).length : 1;
193
- return header + 3 + bufLines;
194
- }
195
- if (state.mode === 'list')
196
- return header + Math.max(1, state.comments.length) + 2;
197
- return header + HELP_ROWS;
198
- }
199
- export function renderReviewFrame(state, fileLabel, doc, cols, rows, opts) {
200
- const maxW = Math.min(Math.max(20, cols - 4), 120);
201
- const docW = renderWidthForCols(cols);
202
- const header = [
203
- '',
204
- ` ${BOLD}${CYAN}Review — ${fileLabel}${RESET} ${DIM}${state.comments.length} comment${state.comments.length === 1 ? '' : 's'}${RESET}`,
205
- ` ${DIM}${hline(maxW)}${RESET}`,
206
- ];
207
- const footer = [];
208
- if (state.mode === 'compose' && state.compose) {
209
- const c = state.compose;
210
- const label = c.anchor.line === c.anchor.endLine ? `L${c.anchor.line}` : `L${c.anchor.line}-${c.anchor.endLine}`;
211
- footer.push(` ${YELLOW}${c.editingId !== null ? 'Edit comment' : 'Comment'} on ${label}:${RESET}`);
212
- for (const l of renderInputBuffer(c.buffer, c.cursor, Math.max(10, maxW - 2)))
213
- footer.push(` ${l}`);
214
- footer.push('');
215
- footer.push(hintBar(COMPOSE_HINTS, maxW));
216
- }
217
- else if (state.mode === 'list') {
218
- if (state.comments.length === 0) {
219
- footer.push(` ${DIM}(no comments yet — press c to comment on the highlighted block)${RESET}`);
220
- }
221
- else {
222
- state.comments.forEach((c, i) => {
223
- const loc = c.line === c.endLine ? `L${c.line}` : `L${c.line}-${c.endLine}`;
224
- const cursor = i === state.listIndex ? `${CYAN}▸${RESET}` : ' ';
225
- const text = truncate(c.comment.replace(/\n/g, ' / '), Math.max(10, maxW - 14));
226
- footer.push(` ${cursor} ${DIM}[${loc}]${RESET} ${text}`);
227
- });
228
- }
229
- footer.push('');
230
- footer.push(hintBar(LIST_HINTS, maxW));
231
- }
232
- else if (state.mode === 'help') {
233
- footer.push(...helpPanel(maxW));
234
- }
235
- else {
236
- footer.push(hintBar(VIEW_HINTS, maxW));
237
- }
238
- if (opts?.notice !== undefined && footer.length > 0) {
239
- footer[footer.length - 1] = chromeRow(` ${YELLOW}${opts.notice}${RESET}`, maxW);
240
- }
241
- const reserved = header.length + footer.length;
242
- const bodyHeight = Math.max(1, rows - reserved);
243
- const maxScroll = Math.max(0, doc.lines.length - bodyHeight);
244
- const scroll = Math.max(0, Math.min(state.scroll, maxScroll));
245
- const gutterW = opts?.lineNumbers === true ? String(doc.lines.length).length : 0;
246
- const contentW = bodyWidth(cols, gutterW);
247
- // Effective pan: the stored offset, clamped to what this window can reach.
248
- // Scrolling into narrow content parks the diagram offset rather than losing
249
- // it, so scrolling back restores the same horizontal position.
250
- const widest = widestVisibleRow(doc, scroll, bodyHeight);
251
- const overflow = Math.max(0, widest - contentW);
252
- const hscroll = Math.max(0, Math.min(state.hscroll, overflow));
253
- const { lo, hi } = selectedUnitBounds(state);
254
- const commented = commentedUnitSet(state);
255
- const body = [];
256
- for (const source of paintedBodyRows(doc, scroll, bodyHeight)) {
257
- if (source.abs === null) {
258
- // Indicator/fill rows reserve the same 4-col marker prefix and gutter a
259
- // source row does, so the content column never shifts while scrolling.
260
- body.push(` ${' '.repeat(gutterW > 0 ? gutterW + 1 : 0)}${source.line}`);
261
- continue;
262
- }
263
- // Every body row is windowed into the body rectangle: a diagram wider than
264
- // the pane pans instead of spilling past the right edge.
265
- const row = panLine(source.line, hscroll, contentW);
266
- const u = state.rowUnits[source.abs] ?? null;
267
- // A row with no span is chrome (the code panel's border), not a source
268
- // line — it gets blank gutter width rather than an invented line number.
269
- const gutterLine = doc.spans[source.abs]?.[0];
270
- const gutter = gutterW > 0
271
- ? (gutterLine === undefined ? ' '.repeat(gutterW + 1) : `${DIM}${String(gutterLine).padStart(gutterW)}${RESET} `)
272
- : '';
273
- // Tint the prose column at minimum, and a wide row across what it occupies.
274
- const tintW = Math.min(contentW, Math.max(docW, visibleWidth(row)));
275
- if (u !== null && u >= lo && u <= hi)
276
- body.push(` ${CYAN}▌${RESET} ${gutter}${tintRow(row, tintW)}`);
277
- else if (u !== null && commented.has(u))
278
- body.push(` ${YELLOW}▎${RESET} ${gutter}${row}`);
279
- else
280
- body.push(` ${gutter}${row}`);
281
- }
282
- while (body.length < bodyHeight)
283
- body.push('');
284
- // Keep the header, footer, and readable body rows in one stable centered
285
- // column. A full-width diagram drops only its own row padding, so it can use
286
- // the pane without shifting the surrounding review as it scrolls into view.
287
- const readableFrameW = Math.min(cols, Math.max(maxW + 2, docW + 4 + (gutterW > 0 ? gutterW + 1 : 0)));
288
- const centeredBody = body.map((line) => {
289
- const frameW = visibleWidth(line) > readableFrameW ? cols : readableFrameW;
290
- return centerHorizontal([line], cols, frameW)[0] ?? '';
291
- });
292
- const lines = [
293
- ...centerHorizontal(header, cols, readableFrameW),
294
- ...centeredBody,
295
- ...centerHorizontal(footer, cols, readableFrameW),
296
- ];
297
- while (lines.length < rows)
298
- lines.push('');
299
- // The frame is contained by construction: no row may exceed the terminal, or
300
- // it wraps and breaks the differ's one-line-per-row model.
301
- return lines.slice(0, rows).map((line) => clipLine(line, cols));
302
- }
303
- /** How a reviewed file is presented: markdown renders as a document, anything
304
- * else as a syntax-highlighted source panel. */
305
- export function docSurface(absFile) {
306
- return isMarkdownFile(absFile)
307
- ? { doc: 'markdown' }
308
- : { doc: 'code', language: fenceLanguageFor(absFile) };
309
- }
@@ -1,133 +0,0 @@
1
- import { Key, decodeKittyPrintable, matchesKey, parseKey } from '@earendil-works/pi-tui';
2
- import { normalizeShiftedMeta } from '../../../core/keybindings/index.js';
3
- /** Return text that compose mode inserts. Semantic textual commands deliberately
4
- * retain their payload so compose can preserve the old branch order. */
5
- export function reviewKeyText(key) {
6
- switch (key.type) {
7
- case 'moveUnit':
8
- case 'extendUnit':
9
- case 'space':
10
- case 'help':
11
- case 'listEdit':
12
- case 'printable':
13
- case 'paste':
14
- return key.text;
15
- case 'scrollPage':
16
- case 'pan':
17
- case 'cancel':
18
- return key.text;
19
- default:
20
- return undefined;
21
- }
22
- }
23
- /** Match one complete pi-tui input chunk. pi-tui owns ESC/meta disambiguation;
24
- * this function has neither terminal state nor a fallback raw-sequence parser. */
25
- export function matchReviewKey(data) {
26
- const normalized = normalizeShiftedMeta(data);
27
- // Compose-only chords precede their unmodified forms. The surface applies
28
- // these only while composing, preserving the terminal-review mode ladder.
29
- if (matchesKey(normalized, Key.ctrl('j')) || matchesKey(normalized, Key.alt('enter')))
30
- return { type: 'composeNewline' };
31
- if (matchesKey(normalized, Key.alt('backspace')) || matchesKey(normalized, Key.ctrl('w')))
32
- return { type: 'composeWordBackspace' };
33
- if (matchesKey(normalized, Key.backspace))
34
- return { type: 'composeBackspace' };
35
- if (matchesKey(normalized, Key.delete))
36
- return { type: 'composeDelete' };
37
- if (matchesKey(normalized, Key.alt('left')) || matchesKey(normalized, Key.ctrl('left')) || matchesKey(normalized, Key.super('left')) || matchesKey(normalized, Key.alt('b'))) {
38
- return { type: 'composeMove', direction: 'wordLeft' };
39
- }
40
- if (matchesKey(normalized, Key.alt('right')) || matchesKey(normalized, Key.ctrl('right')) || matchesKey(normalized, Key.super('right')) || matchesKey(normalized, Key.alt('f'))) {
41
- return { type: 'composeMove', direction: 'wordRight' };
42
- }
43
- if (matchesKey(normalized, Key.home) || matchesKey(normalized, Key.ctrl('a')))
44
- return { type: 'composeHome' };
45
- if (matchesKey(normalized, Key.end) || matchesKey(normalized, Key.ctrl('e')))
46
- return { type: 'composeEnd' };
47
- if (matchesKey(normalized, Key.shift('tab')))
48
- return { type: 'tab', reverse: true };
49
- if (matchesKey(normalized, Key.tab))
50
- return { type: 'tab', reverse: false };
51
- // Ctrl+Enter is only distinguishable from Enter under the kitty keyboard
52
- // protocol, so it is paired with a chord every terminal delivers.
53
- if (matchesKey(normalized, Key.ctrl('enter')) || matchesKey(normalized, Key.ctrl('f')))
54
- return { type: 'confirmFork' };
55
- if (matchesKey(normalized, Key.enter))
56
- return { type: 'confirm' };
57
- if (matchesKey(normalized, Key.escape))
58
- return { type: 'cancel' };
59
- // Arrow keys remain distinct because each mode gives them its own meaning.
60
- if (matchesKey(normalized, Key.up))
61
- return { type: 'arrow', direction: 'up' };
62
- if (matchesKey(normalized, Key.down))
63
- return { type: 'arrow', direction: 'down' };
64
- if (matchesKey(normalized, Key.left))
65
- return { type: 'arrow', direction: 'left' };
66
- if (matchesKey(normalized, Key.right))
67
- return { type: 'arrow', direction: 'right' };
68
- if (matchesKey(normalized, Key.pageUp))
69
- return { type: 'scrollPage', delta: -1 };
70
- if (matchesKey(normalized, Key.pageDown))
71
- return { type: 'scrollPage', delta: 1 };
72
- if (matchesKey(normalized, Key.shift('j')))
73
- return { type: 'extendUnit', delta: 1, text: 'J' };
74
- if (matchesKey(normalized, Key.shift('k')))
75
- return { type: 'extendUnit', delta: -1, text: 'K' };
76
- // Shift+C and Shift+U are view-mode commands. Matched explicitly, like J/K,
77
- // because a kitty report of either decodes to its unshifted letter.
78
- if (matchesKey(normalized, Key.shift('c')))
79
- return { type: 'printable', text: 'C' };
80
- if (matchesKey(normalized, Key.shift('u')))
81
- return { type: 'printable', text: 'U' };
82
- if (matchesKey(normalized, 'j'))
83
- return { type: 'moveUnit', delta: 1, text: 'j' };
84
- if (matchesKey(normalized, 'k'))
85
- return { type: 'moveUnit', delta: -1, text: 'k' };
86
- if (matchesKey(normalized, 'u'))
87
- return { type: 'scrollPage', delta: -1, text: 'u' };
88
- if (matchesKey(normalized, 'd'))
89
- return { type: 'scrollPage', delta: 1, text: 'd' };
90
- if (matchesKey(normalized, 'h'))
91
- return { type: 'pan', delta: -1, text: 'h' };
92
- if (matchesKey(normalized, 'l'))
93
- return { type: 'pan', delta: 1, text: 'l' };
94
- if (matchesKey(normalized, Key.space))
95
- return { type: 'space', text: ' ' };
96
- if (matchesKey(normalized, Key.question))
97
- return { type: 'help', text: '?' };
98
- if (matchesKey(normalized, 'e'))
99
- return { type: 'listEdit', text: 'e' };
100
- if (matchesKey(normalized, 'q'))
101
- return { type: 'cancel', text: 'q' };
102
- const parsed = parseKey(normalized);
103
- const text = printableText(data, parsed);
104
- // Kitty reports question mark as Shift+Slash, so the unmodified-key matcher
105
- // above cannot recognize it. Keep its text for compose through reviewKeyText.
106
- if (text === '?')
107
- return { type: 'help', text };
108
- if (text !== undefined)
109
- return { type: 'printable', text };
110
- // A recognized but unhandled modified key (notably Alt+I) is not text or a
111
- // paste. Its viewer-level owner may already have consumed it.
112
- if (parsed !== undefined)
113
- return null;
114
- if ([...data].length > 1)
115
- return { type: 'paste', text: data };
116
- return null;
117
- }
118
- function printableText(data, parsed) {
119
- const kitty = decodeKittyPrintable(data);
120
- if (kitty !== undefined && isPrintable(kitty))
121
- return kitty;
122
- if (parsed !== undefined) {
123
- const shifted = parsed.startsWith('shift+');
124
- const candidate = shifted ? parsed.slice('shift+'.length) : parsed;
125
- if ([...candidate].length === 1 && isPrintable(candidate)) {
126
- return shifted && /^[a-z]$/.test(candidate) ? candidate.toUpperCase() : candidate;
127
- }
128
- }
129
- return [...data].length === 1 && isPrintable(data) ? data : undefined;
130
- }
131
- function isPrintable(text) {
132
- return !/\p{C}/u.test(text);
133
- }
@@ -1,170 +0,0 @@
1
- import { basename } from 'node:path';
2
- import { displayMessage, getPaneOption, openNodeWindow, paneLocation, selectWindow, shellQuote, viewerSplitEnv, windowIndex, } from '../../../core/runtime/placement-tmux.js';
3
- import { ReviewDocumentSurface } from './document-surface.js';
4
- import { openLiveSource } from './live-source.js';
5
- import { createReviewClient, ReviewTerminalError, terminalRefusalNotice, } from './review-client.js';
6
- const ATTACH_REVIEW_ENV = 'CRTR_ATTACH_REVIEW_ID';
7
- /** Open a dedicated viewer window for a review without replacing the caller's
8
- * conversation window. The fresh viewer consumes the review id at startup. */
9
- export function openReviewWindow(host, review) {
10
- if (host.capabilities.remote) {
11
- host.notice('The review is unavailable in a remote attach — the file and companion live on the host.');
12
- return false;
13
- }
14
- const callerPane = host.capabilities.selfPane;
15
- if (callerPane === undefined || callerPane === '') {
16
- host.notice('Opening a review needs a local viewer in tmux.');
17
- return false;
18
- }
19
- const location = paneLocation(callerPane);
20
- const nodeId = getPaneOption(callerPane, '@crtr_node');
21
- if (location === null || nodeId === undefined || nodeId === '') {
22
- host.notice('Could not resolve the current viewer for this review.');
23
- return false;
24
- }
25
- const windowName = `review:${basename(review.file)}`;
26
- const opened = openNodeWindow({
27
- session: location.session,
28
- name: windowName,
29
- cwd: review.cwd,
30
- env: { ...viewerSplitEnv(), [ATTACH_REVIEW_ENV]: review.reviewId },
31
- command: `crtr surface attach to ${shellQuote(nodeId)}`,
32
- });
33
- if (opened === null) {
34
- host.notice('tmux could not open the review window.');
35
- return false;
36
- }
37
- const fromIndex = windowIndex(location.window);
38
- const toIndex = windowIndex(opened.window);
39
- selectWindow(location.session, opened.window);
40
- // Tell the person where the review went and how to get back; the caller's
41
- // pane targets the client now showing the new window in this session.
42
- if (toIndex !== null) {
43
- displayMessage(reviewOpenedMessage(toIndex, windowName, fromIndex), callerPane, 5000);
44
- }
45
- return true;
46
- }
47
- /** The status-line toast shown once a review window opens. */
48
- export function reviewOpenedMessage(toIndex, windowName, fromIndex) {
49
- // tmux binds only prefix 0–9 to select-window, so a two-digit window gets no
50
- // key hint — just the number to go back to.
51
- const back = fromIndex === null
52
- ? ''
53
- : fromIndex <= 9
54
- ? ` — prefix ${fromIndex} returns to window ${fromIndex}`
55
- : ` — you were in window ${fromIndex}`;
56
- return `Review opened in new window ${toIndex} (${windowName})${back}`;
57
- }
58
- /** Consume the review id handed to a dedicated attach viewer. */
59
- export function takeStartupReviewId() {
60
- const reviewId = process.env[ATTACH_REVIEW_ENV];
61
- delete process.env[ATTACH_REVIEW_ENV];
62
- return reviewId === undefined || reviewId === '' ? undefined : reviewId;
63
- }
64
- /** Resolve and mount the review seeded into a dedicated viewer window. */
65
- export async function openReviewSurfaceById(host, reviewId) {
66
- try {
67
- const review = await createReviewClient().byId(reviewId);
68
- await openReviewSurface(host, { review });
69
- }
70
- catch (error) {
71
- host.notice(error instanceof ReviewTerminalError
72
- ? terminalRefusalNotice(error)
73
- : `couldn't open review: ${describeError(error)}`);
74
- }
75
- }
76
- /** Mount the review document inside its dedicated viewer window. */
77
- export async function openReviewSurface(host, opts) {
78
- const review = opts.review;
79
- let source;
80
- try {
81
- source = openLiveSource(review.file);
82
- }
83
- catch (error) {
84
- host.notice(`couldn't open ${review.file}: ${describeError(error)}`);
85
- return;
86
- }
87
- let terminalConflict = false;
88
- const reviewClient = createReviewClient({
89
- onTerminalConflict: (notice) => {
90
- terminalConflict = true;
91
- finish(notice);
92
- },
93
- });
94
- const comments = reviewClient.comments(review.reviewId);
95
- let handle;
96
- let submitting = false;
97
- let canceling = false;
98
- const surface = new ReviewDocumentSurface({
99
- review,
100
- source,
101
- comments,
102
- callerPane: host.capabilities.selfPane,
103
- services: {
104
- notice: (text, opts) => host.notice(text, opts),
105
- suspendForChild: () => host.suspendForChild(),
106
- requestClose: () => handle?.close(),
107
- submit: () => { void submit(); },
108
- cancel: () => { void cancel(); },
109
- },
110
- });
111
- await surface.open();
112
- handle = host.mount(surface);
113
- surface.setHandle(handle);
114
- // The conversation is opened only once the document is standing, so a tmux
115
- // refusal costs the person a notice rather than the review. The tmux calls
116
- // are blocking subprocesses, so they are deferred past the render tick the
117
- // mount just scheduled — a macrotask lands after it, a microtask would not.
118
- setImmediate(() => { surface.openCompanion(); });
119
- async function submit() {
120
- if (submitting)
121
- return;
122
- submitting = true;
123
- try {
124
- const disposition = await reviewClient.submit(review.reviewId);
125
- if (disposition.outcome === 'approved') {
126
- finish(approvalNotice(disposition));
127
- return;
128
- }
129
- // The companion is mid-edit. The review is off the human's hands either
130
- // way: the daemon approves the document as it reads once the companion
131
- // stops, and the origin has already been told the approval is coming.
132
- // Sticky, because the wait outlives a three-second notice — the review's
133
- // cockpit row below the editor carries it from there.
134
- finish('Review submitted before the companion finished — the agent resumes when the review completes.', { sticky: true });
135
- }
136
- catch (error) {
137
- if (terminalConflict)
138
- return;
139
- submitting = false;
140
- host.notice(`couldn't submit review: ${describeError(error)}`);
141
- }
142
- }
143
- function finish(notice, opts) {
144
- surface.teardown(notice, opts);
145
- }
146
- async function cancel() {
147
- if (canceling)
148
- return;
149
- canceling = true;
150
- try {
151
- await reviewClient.cancel(review.reviewId, 'canceled from the review surface');
152
- finish('Review canceled.');
153
- }
154
- catch (error) {
155
- if (terminalConflict)
156
- return;
157
- // Nothing moved: the review is still open and both panes stand.
158
- canceling = false;
159
- host.notice(`couldn't cancel review: ${describeError(error)}`);
160
- }
161
- }
162
- }
163
- function approvalNotice(result) {
164
- return result.changed
165
- ? `Approved — the document changed during review. Result: ${result.resultPath}`
166
- : `Approved — the document was not modified. Result: ${result.resultPath}`;
167
- }
168
- function describeError(error) {
169
- return error instanceof Error ? error.message : String(error);
170
- }