poly-weaver 0.5.1 → 0.6.1

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 (150) hide show
  1. package/dist/agents/implementors/handler.d.ts.map +1 -1
  2. package/dist/agents/implementors/handler.js +2 -1
  3. package/dist/agents/implementors/handler.js.map +1 -1
  4. package/dist/agents/planners/handler.d.ts.map +1 -1
  5. package/dist/agents/planners/handler.js +2 -1
  6. package/dist/agents/planners/handler.js.map +1 -1
  7. package/dist/agents/reviewers/handler.d.ts.map +1 -1
  8. package/dist/agents/reviewers/handler.js +9 -2
  9. package/dist/agents/reviewers/handler.js.map +1 -1
  10. package/dist/agents/runner.d.ts +40 -1
  11. package/dist/agents/runner.d.ts.map +1 -1
  12. package/dist/agents/runner.js +213 -14
  13. package/dist/agents/runner.js.map +1 -1
  14. package/dist/agents/simplifiers/handler.d.ts.map +1 -1
  15. package/dist/agents/simplifiers/handler.js +2 -1
  16. package/dist/agents/simplifiers/handler.js.map +1 -1
  17. package/dist/ansi.d.ts +26 -0
  18. package/dist/ansi.d.ts.map +1 -1
  19. package/dist/ansi.js +26 -0
  20. package/dist/ansi.js.map +1 -1
  21. package/dist/cli.js +46 -16
  22. package/dist/cli.js.map +1 -1
  23. package/dist/flow/built-in/default.js +1 -1
  24. package/dist/flow/built-in/default.js.map +1 -1
  25. package/dist/flow/built-in/default.ts +1 -1
  26. package/dist/flow/built-in/why-so-serious.js +1 -1
  27. package/dist/flow/built-in/why-so-serious.js.map +1 -1
  28. package/dist/flow/executor.d.ts.map +1 -1
  29. package/dist/flow/executor.js +7 -2
  30. package/dist/flow/executor.js.map +1 -1
  31. package/dist/flow/types.d.ts +5 -0
  32. package/dist/flow/types.d.ts.map +1 -1
  33. package/dist/flow/types.js.map +1 -1
  34. package/dist/markdown.d.ts +18 -0
  35. package/dist/markdown.d.ts.map +1 -0
  36. package/dist/markdown.js +63 -0
  37. package/dist/markdown.js.map +1 -0
  38. package/dist/orchestrator.d.ts +10 -4
  39. package/dist/orchestrator.d.ts.map +1 -1
  40. package/dist/orchestrator.js +34 -14
  41. package/dist/orchestrator.js.map +1 -1
  42. package/dist/providers/claude/session.d.ts +3 -1
  43. package/dist/providers/claude/session.d.ts.map +1 -1
  44. package/dist/providers/claude/session.js +2 -2
  45. package/dist/providers/claude/session.js.map +1 -1
  46. package/dist/providers/codex/session.d.ts +6 -3
  47. package/dist/providers/codex/session.d.ts.map +1 -1
  48. package/dist/providers/codex/session.js +24 -4
  49. package/dist/providers/codex/session.js.map +1 -1
  50. package/dist/providers/copilot/session.d.ts +3 -1
  51. package/dist/providers/copilot/session.d.ts.map +1 -1
  52. package/dist/providers/copilot/session.js +15 -2
  53. package/dist/providers/copilot/session.js.map +1 -1
  54. package/dist/providers/types.d.ts +14 -2
  55. package/dist/providers/types.d.ts.map +1 -1
  56. package/dist/providers/types.js.map +1 -1
  57. package/dist/pty/exit.d.ts +13 -5
  58. package/dist/pty/exit.d.ts.map +1 -1
  59. package/dist/pty/exit.js +19 -19
  60. package/dist/pty/exit.js.map +1 -1
  61. package/dist/pty/spawn.d.ts +12 -6
  62. package/dist/pty/spawn.d.ts.map +1 -1
  63. package/dist/pty/spawn.js +22 -70
  64. package/dist/pty/spawn.js.map +1 -1
  65. package/dist/pty/types.d.ts +12 -3
  66. package/dist/pty/types.d.ts.map +1 -1
  67. package/dist/session/locator.d.ts +23 -2
  68. package/dist/session/locator.d.ts.map +1 -1
  69. package/dist/session/locator.js +67 -4
  70. package/dist/session/locator.js.map +1 -1
  71. package/dist/status-bar.d.ts +21 -1
  72. package/dist/status-bar.d.ts.map +1 -1
  73. package/dist/status-bar.js +109 -34
  74. package/dist/status-bar.js.map +1 -1
  75. package/dist/terminal/cleanup.d.ts +21 -0
  76. package/dist/terminal/cleanup.d.ts.map +1 -0
  77. package/dist/terminal/cleanup.js +22 -0
  78. package/dist/terminal/cleanup.js.map +1 -0
  79. package/dist/terminal/host.d.ts +244 -0
  80. package/dist/terminal/host.d.ts.map +1 -0
  81. package/dist/terminal/host.js +642 -0
  82. package/dist/terminal/host.js.map +1 -0
  83. package/dist/terminal/input-router.d.ts +146 -0
  84. package/dist/terminal/input-router.d.ts.map +1 -0
  85. package/dist/terminal/input-router.js +426 -0
  86. package/dist/terminal/input-router.js.map +1 -0
  87. package/dist/terminal/layout.d.ts +55 -0
  88. package/dist/terminal/layout.d.ts.map +1 -0
  89. package/dist/terminal/layout.js +51 -0
  90. package/dist/terminal/layout.js.map +1 -0
  91. package/dist/terminal/output.d.ts +83 -0
  92. package/dist/terminal/output.d.ts.map +1 -0
  93. package/dist/terminal/output.js +107 -0
  94. package/dist/terminal/output.js.map +1 -0
  95. package/dist/terminal/render.d.ts +36 -0
  96. package/dist/terminal/render.d.ts.map +1 -0
  97. package/dist/terminal/render.js +233 -0
  98. package/dist/terminal/render.js.map +1 -0
  99. package/dist/terminal/virtual-terminal.d.ts +54 -0
  100. package/dist/terminal/virtual-terminal.d.ts.map +1 -0
  101. package/dist/terminal/virtual-terminal.js +110 -0
  102. package/dist/terminal/virtual-terminal.js.map +1 -0
  103. package/dist/terminal-input.d.ts +10 -0
  104. package/dist/terminal-input.d.ts.map +1 -1
  105. package/dist/terminal-input.js +46 -0
  106. package/dist/terminal-input.js.map +1 -1
  107. package/dist/user/auto-curate-prompt.d.ts +17 -0
  108. package/dist/user/auto-curate-prompt.d.ts.map +1 -0
  109. package/dist/user/auto-curate-prompt.js +22 -0
  110. package/dist/user/auto-curate-prompt.js.map +1 -0
  111. package/dist/user/curate-handler.d.ts.map +1 -1
  112. package/dist/user/curate-handler.js +10 -2
  113. package/dist/user/curate-handler.js.map +1 -1
  114. package/dist/user/curate-prompt.d.ts +9 -7
  115. package/dist/user/curate-prompt.d.ts.map +1 -1
  116. package/dist/user/curate-prompt.js +2 -341
  117. package/dist/user/curate-prompt.js.map +1 -1
  118. package/dist/user/handler.d.ts +13 -1
  119. package/dist/user/handler.d.ts.map +1 -1
  120. package/dist/user/handler.js +27 -15
  121. package/dist/user/handler.js.map +1 -1
  122. package/dist/user/hard-wrap.d.ts +11 -0
  123. package/dist/user/hard-wrap.d.ts.map +1 -0
  124. package/dist/user/hard-wrap.js +44 -0
  125. package/dist/user/hard-wrap.js.map +1 -0
  126. package/dist/user/host-curate-prompt.d.ts +34 -0
  127. package/dist/user/host-curate-prompt.d.ts.map +1 -0
  128. package/dist/user/host-curate-prompt.js +463 -0
  129. package/dist/user/host-curate-prompt.js.map +1 -0
  130. package/dist/user/host-prompt.d.ts +21 -0
  131. package/dist/user/host-prompt.d.ts.map +1 -0
  132. package/dist/user/host-prompt.js +337 -0
  133. package/dist/user/host-prompt.js.map +1 -0
  134. package/dist/user/index.d.ts +3 -3
  135. package/dist/user/index.d.ts.map +1 -1
  136. package/dist/user/index.js +2 -2
  137. package/dist/user/index.js.map +1 -1
  138. package/dist/user/plan-pane.d.ts +18 -0
  139. package/dist/user/plan-pane.d.ts.map +1 -0
  140. package/dist/user/plan-pane.js +34 -0
  141. package/dist/user/plan-pane.js.map +1 -0
  142. package/dist/user/prompt.d.ts +25 -42
  143. package/dist/user/prompt.d.ts.map +1 -1
  144. package/dist/user/prompt.js +16 -278
  145. package/dist/user/prompt.js.map +1 -1
  146. package/dist/user/split-surface.d.ts +32 -0
  147. package/dist/user/split-surface.d.ts.map +1 -0
  148. package/dist/user/split-surface.js +66 -0
  149. package/dist/user/split-surface.js.map +1 -0
  150. package/package.json +5 -1
@@ -0,0 +1,642 @@
1
+ import { ALT_SCREEN_OFF, ALT_SCREEN_ON, CLEAR_SCREEN, CURSOR_HOME, HIDE_CURSOR, MOUSE_OFF, MOUSE_ON, RESET_SCROLL_REGION, SHOW_CURSOR, visibleLength, } from "../ansi.js";
2
+ import { computeTerminalLayout } from "./layout.js";
3
+ import { VirtualTerminal } from "./virtual-terminal.js";
4
+ import { renderChildViewport, renderStatusLine } from "./render.js";
5
+ import { BufferOrchestrationOutput, formatOrchestrationMessage, } from "./output.js";
6
+ import { InputRouter } from "./input-router.js";
7
+ /**
8
+ * Parent-owned orchestration terminal host.
9
+ *
10
+ * While `started`, the host:
11
+ * - Owns the alternate screen, raw stdin mode, and `process.stdout` writes
12
+ * for the orchestration phase.
13
+ * - Maintains a `@xterm/headless` virtual terminal sized from the host
14
+ * layout. PTY data passes through the virtual terminal before display.
15
+ * - Schedules coalesced repaints so bursty PTY output renders as one frame.
16
+ * - Renders, in order: child viewport, parent UI / message area,
17
+ * and finally the status bar on `layout.statusRow`.
18
+ * - Routes stdin through global shortcuts (dump hotkey, host scrollback,
19
+ * host interrupt), then the active parent UI mode (review prompts,
20
+ * etc.), then the attached child.
21
+ * - Enables SGR mouse reporting on the real terminal so wheel events
22
+ * drive the host-managed scrollback viewport, and disables it on
23
+ * teardown / suspension so foreign UIs and the post-host shell are
24
+ * not left with mouse mode turned on.
25
+ */
26
+ export class TerminalHost {
27
+ stdin;
28
+ stdout;
29
+ router;
30
+ bufferOutput;
31
+ onDump;
32
+ interruptListeners = new Set();
33
+ statusBar;
34
+ childHandle;
35
+ vt;
36
+ layout;
37
+ started = false;
38
+ stopped = false;
39
+ suspended = false;
40
+ prevRawMode = false;
41
+ resizeListener;
42
+ renderScheduled = false;
43
+ pendingFlush = false;
44
+ /**
45
+ * Set whenever any caller requests a full repaint (PTY output, resize,
46
+ * output buffer changes, status updates, attach/detach). When false at
47
+ * flush time AND a parent UI is attached with a full-height surface,
48
+ * the host can skip the child viewport render and only repaint the
49
+ * parent UI surface + status row. Any subsequent full request before
50
+ * flush flips it back to true.
51
+ */
52
+ pendingFullRender = false;
53
+ stdinListener;
54
+ parentUi;
55
+ constructor(opts = {}) {
56
+ this.stdin = opts.stdin ?? process.stdin;
57
+ this.stdout = opts.stdout ?? process.stdout;
58
+ this.statusBar = opts.statusBar;
59
+ this.bufferOutput = opts.output ?? new BufferOrchestrationOutput();
60
+ // Always wire onChange to the host so phase/warn/error writes from
61
+ // anywhere — including a CLI-owned buffer passed in via opts — drive
62
+ // a layout recompute (the warning strip height tracks the buffer)
63
+ // followed by a coalesced repaint.
64
+ this.bufferOutput.setOnChange(() => this.handleOutputChange());
65
+ this.onDump = opts.onDump;
66
+ this.router = new InputRouter({
67
+ onDump: opts.onDump,
68
+ onInterrupt: () => this.fireInterrupt(),
69
+ onScrollBackLines: (lines) => this.handleScrollBackLines(lines),
70
+ onScrollForwardLines: (lines) => this.handleScrollForwardLines(lines),
71
+ onScrollPages: (pages) => this.handleScrollPages(pages),
72
+ onScrollToTop: () => this.handleScrollToTop(),
73
+ onScrollToBottom: () => this.handleScrollToBottom(),
74
+ });
75
+ if (this.statusBar) {
76
+ this.attachStatusBar(this.statusBar);
77
+ }
78
+ }
79
+ /** True only when the host has entered the alternate screen. */
80
+ get isActive() {
81
+ return this.started && !this.stopped;
82
+ }
83
+ /**
84
+ * True when the host's configured stdin is a TTY. Host-backed prompts
85
+ * gate interactivity on this — never on `process.stdin.isTTY` — so an
86
+ * embedded host with a non-default stdin still drives prompt I/O off
87
+ * the host-owned stream.
88
+ */
89
+ get isInteractive() {
90
+ return this.stdin.isTTY === true;
91
+ }
92
+ /** Public output sink — orchestration code writes here. */
93
+ get output() {
94
+ return this.bufferOutput;
95
+ }
96
+ /** Current layout snapshot. Computed on demand when not yet started. */
97
+ getLayout() {
98
+ if (!this.layout) {
99
+ this.layout = this.computeLayout();
100
+ }
101
+ return this.layout;
102
+ }
103
+ /** Replace the status model after construction. */
104
+ attachStatusBar(bar) {
105
+ this.statusBar = bar;
106
+ // Hook the host so any change to status content schedules a repaint.
107
+ bar.onChange = () => this.scheduleRender();
108
+ }
109
+ /**
110
+ * Subscribe to host interrupt events (raw Ctrl+C while no parent UI
111
+ * consumes the byte). Returns an idempotent unsubscribe function.
112
+ *
113
+ * The host does not rely on process-level `SIGINT` — raw mode prevents
114
+ * the parent process from receiving SIGINT normally. Listeners are
115
+ * cleared on `stop()` so stale callbacks cannot fire after teardown.
116
+ */
117
+ onInterrupt(callback) {
118
+ this.interruptListeners.add(callback);
119
+ let removed = false;
120
+ return () => {
121
+ if (removed)
122
+ return;
123
+ removed = true;
124
+ this.interruptListeners.delete(callback);
125
+ };
126
+ }
127
+ start() {
128
+ if (this.started)
129
+ return;
130
+ this.started = true;
131
+ this.stopped = false;
132
+ this.layout = this.computeLayout();
133
+ this.vt = new VirtualTerminal(this.layout.childCols, this.layout.childRows);
134
+ this.stdout.write(ALT_SCREEN_ON + CLEAR_SCREEN + CURSOR_HOME + HIDE_CURSOR + MOUSE_ON);
135
+ if (this.stdin.isTTY) {
136
+ this.prevRawMode = this.stdin.isRaw === true;
137
+ this.stdin.setRawMode(true);
138
+ this.stdin.resume();
139
+ this.stdinListener = (chunk) => this.router.handleChunk(chunk);
140
+ this.stdin.on("data", this.stdinListener);
141
+ }
142
+ this.resizeListener = () => this.handleResize();
143
+ this.stdout.on("resize", this.resizeListener);
144
+ this.scheduleRender();
145
+ }
146
+ stop() {
147
+ if (!this.started || this.stopped)
148
+ return;
149
+ this.stopped = true;
150
+ if (this.stdinListener) {
151
+ this.stdin.removeListener("data", this.stdinListener);
152
+ this.stdinListener = undefined;
153
+ }
154
+ if (this.stdin.isTTY) {
155
+ try {
156
+ this.stdin.setRawMode(this.prevRawMode);
157
+ }
158
+ catch { /* ignore */ }
159
+ }
160
+ if (this.resizeListener) {
161
+ this.stdout.removeListener("resize", this.resizeListener);
162
+ this.resizeListener = undefined;
163
+ }
164
+ this.detachChild();
165
+ this.router.destroy();
166
+ this.vt?.dispose();
167
+ this.vt = undefined;
168
+ this.stdout.write(MOUSE_OFF + RESET_SCROLL_REGION + CLEAR_SCREEN + CURSOR_HOME + ALT_SCREEN_OFF + SHOW_CURSOR);
169
+ // Drop any lingering subscribers — once the host has stopped, late
170
+ // interrupt callbacks would see torn-down state.
171
+ this.interruptListeners.clear();
172
+ }
173
+ /**
174
+ * Attach a PTY handle to the host. The host begins routing PTY data
175
+ * through the virtual terminal and displays it on the next render tick.
176
+ *
177
+ * The closure-bound handle is captured inside the data callback. After
178
+ * `detachChild()`, late `onData` events for the previously attached
179
+ * handle no longer feed the virtual terminal — so provider exit chatter
180
+ * cannot leak onto the screen even though node-pty does not expose an
181
+ * `off` for the listener.
182
+ *
183
+ * The returned function detaches the child idempotently.
184
+ */
185
+ attachChild(handle) {
186
+ this.detachChild();
187
+ // Each agent run starts with a fresh VT and empty scrollback so prior
188
+ // child output cannot remain visible or be reached via PageUp.
189
+ this.resetVirtualTerminal();
190
+ this.childHandle = handle;
191
+ this.router.attachChild(handle);
192
+ const boundHandle = handle;
193
+ handle.onData((data) => {
194
+ // Skip render writes if a different child has been attached or the
195
+ // host has detached this child entirely.
196
+ if (this.childHandle !== boundHandle)
197
+ return;
198
+ // Mid-attachment suppression: caller flagged the handle as
199
+ // render-suppressed (graceful exit).
200
+ if (boundHandle.renderSuppressed)
201
+ return;
202
+ if (!this.vt)
203
+ return;
204
+ // Capture the user's viewport position BEFORE the write. Two cases:
205
+ //
206
+ // stickyBottom=true: user is at the tail → keep them there.
207
+ // stickyBottom=false: user is scrolled back → preserve the
208
+ // rendered window so new output does not
209
+ // yank them to the live tail. xterm
210
+ // auto-advances the viewport on output;
211
+ // we counteract that by snapping
212
+ // viewportY back to its pre-write absolute
213
+ // position once the parser drains.
214
+ const stickyBottom = !this.vt.isScrolledBack;
215
+ const preWriteViewportY = this.vt.viewportY;
216
+ this.vt.write(data, () => {
217
+ if (!this.vt)
218
+ return;
219
+ if (stickyBottom) {
220
+ if (this.vt.isScrolledBack) {
221
+ // Defensive: snap to bottom if xterm pushed us into
222
+ // scrollback despite the tail-follow position.
223
+ this.vt.scrollToBottom();
224
+ }
225
+ }
226
+ else {
227
+ // Restore the user's scroll position. Compute the delta
228
+ // between the post-write viewportY and the pre-write
229
+ // viewportY in absolute scrollback coordinates, then move
230
+ // the viewport back by that delta.
231
+ const currentY = this.vt.viewportY;
232
+ const delta = preWriteViewportY - currentY;
233
+ if (delta < 0)
234
+ this.vt.scrollBack(-delta);
235
+ else if (delta > 0)
236
+ this.vt.scrollForward(delta);
237
+ }
238
+ this.scheduleRender();
239
+ });
240
+ });
241
+ // Resize the child to match the current layout immediately.
242
+ if (this.layout) {
243
+ handle.resize(this.layout.childCols, this.layout.childRows);
244
+ }
245
+ return () => this.detachChild(handle);
246
+ }
247
+ detachChild(handle) {
248
+ if (handle && this.childHandle !== handle)
249
+ return;
250
+ if (!this.childHandle)
251
+ return;
252
+ // Belt-and-suspenders: also flag the handle as render-suppressed so
253
+ // any onData listener still queued in the next tick is ignored.
254
+ this.childHandle.suppressOutput();
255
+ this.router.detachChild(this.childHandle);
256
+ this.childHandle = undefined;
257
+ }
258
+ /**
259
+ * Discard the current child surface (VT screen + scrollback) and
260
+ * schedule a render. Use this after a provider run completes so the
261
+ * next host frame is blank instead of showing the finished agent's
262
+ * trailing output.
263
+ */
264
+ clearChildSurface() {
265
+ this.resetVirtualTerminal();
266
+ this.scheduleRender();
267
+ }
268
+ /** Dispose the current `VirtualTerminal` and create a fresh one sized to the current layout. */
269
+ resetVirtualTerminal() {
270
+ if (!this.layout) {
271
+ this.layout = this.computeLayout();
272
+ }
273
+ this.vt?.dispose();
274
+ this.vt = new VirtualTerminal(this.layout.childCols, this.layout.childRows);
275
+ }
276
+ /**
277
+ * Attach a parent UI mode. The host routes stdin through the mode's
278
+ * `onInput` and queries `getSurface()` (when present) on every frame.
279
+ * Returns a detach function.
280
+ */
281
+ attachParentUi(mode) {
282
+ this.parentUi = mode;
283
+ this.router.attachParentUi(mode);
284
+ this.scheduleRender();
285
+ return () => this.detachParentUi(mode);
286
+ }
287
+ detachParentUi(mode) {
288
+ if (mode && this.parentUi !== mode)
289
+ return;
290
+ this.router.detachParentUi(this.parentUi);
291
+ this.parentUi = undefined;
292
+ this.scheduleRender();
293
+ }
294
+ /**
295
+ * Suspend the host and run `run` while a foreign UI owns the terminal.
296
+ *
297
+ * The host:
298
+ * - leaves its own alternate screen,
299
+ * - disables mouse reporting so the foreign UI is not flooded with
300
+ * SGR mouse sequences,
301
+ * - removes its stdin data listener,
302
+ * - restores the prior raw-mode state,
303
+ * - blocks `scheduleRender()`/`renderNow()` until resume,
304
+ * - keeps the virtual terminal, output buffer, router, and status bar
305
+ * intact so any data buffered during suspension is preserved for
306
+ * repaint after resume.
307
+ *
308
+ * On resume the host re-enters its alt screen, re-enables mouse
309
+ * reporting, re-installs its raw-mode stdin listener, recomputes
310
+ * layout, resizes the attached child if any, and schedules a repaint.
311
+ *
312
+ * Throws when the host is not active. The `finally` clause always
313
+ * restores host ownership, even when `run` throws.
314
+ */
315
+ async runIsolatedAltScreen(run) {
316
+ if (!this.isActive) {
317
+ throw new Error("TerminalHost.runIsolatedAltScreen: host is not active");
318
+ }
319
+ if (this.suspended) {
320
+ throw new Error("TerminalHost.runIsolatedAltScreen: already suspended");
321
+ }
322
+ this.suspended = true;
323
+ if (this.stdinListener) {
324
+ this.stdin.removeListener("data", this.stdinListener);
325
+ }
326
+ if (this.stdin.isTTY) {
327
+ try {
328
+ this.stdin.setRawMode(this.prevRawMode);
329
+ }
330
+ catch { /* ignore */ }
331
+ }
332
+ this.stdout.write(MOUSE_OFF + RESET_SCROLL_REGION + CLEAR_SCREEN + CURSOR_HOME + ALT_SCREEN_OFF + SHOW_CURSOR);
333
+ const layoutSnapshot = this.layout ?? this.computeLayout();
334
+ const io = {
335
+ stdin: this.stdin,
336
+ stdout: this.stdout,
337
+ columns: layoutSnapshot.columns,
338
+ rows: layoutSnapshot.rows,
339
+ triggerDump: () => this.onDump?.(),
340
+ };
341
+ try {
342
+ return await run(io);
343
+ }
344
+ finally {
345
+ this.stdout.write(ALT_SCREEN_ON + CLEAR_SCREEN + CURSOR_HOME + HIDE_CURSOR + MOUSE_ON);
346
+ if (this.stdin.isTTY) {
347
+ try {
348
+ this.stdin.setRawMode(true);
349
+ }
350
+ catch { /* ignore */ }
351
+ this.stdin.resume();
352
+ if (this.stdinListener) {
353
+ this.stdin.on("data", this.stdinListener);
354
+ }
355
+ }
356
+ this.suspended = false;
357
+ this.layout = this.computeLayout();
358
+ if (this.vt)
359
+ this.vt.resize(this.layout.childCols, this.layout.childRows);
360
+ if (this.childHandle) {
361
+ this.childHandle.resize(this.layout.childCols, this.layout.childRows);
362
+ }
363
+ this.scheduleRender();
364
+ }
365
+ }
366
+ /** Force an immediate render (synchronously composes one frame). */
367
+ renderNow() {
368
+ this.pendingFlush = false;
369
+ this.renderScheduled = false;
370
+ const fullRender = this.pendingFullRender;
371
+ this.pendingFullRender = false;
372
+ if (!this.isActive || this.suspended || !this.layout || !this.vt)
373
+ return;
374
+ const surface = this.parentUi && isHostParentUiMode(this.parentUi)
375
+ ? this.parentUi.getSurface()
376
+ : undefined;
377
+ // Parent-UI-only repaint is only safe when the surface fills the entire
378
+ // child area — otherwise rows above the surface would retain stale
379
+ // content from the previous frame. When that contract isn't met, fall
380
+ // back to a full render so correctness never depends on caller
381
+ // discipline alone.
382
+ const parentOnly = !fullRender
383
+ && surface !== undefined
384
+ && surface.lines.length >= this.layout.childRows;
385
+ let frame = "";
386
+ if (!parentOnly) {
387
+ frame += renderChildViewport(this.vt, this.layout);
388
+ }
389
+ if (surface) {
390
+ frame += this.renderUiSurface(this.layout, surface);
391
+ }
392
+ // Warning strip is host-owned and lives in its own dedicated rows
393
+ // (between the child viewport and the status bar), so it is rendered
394
+ // independently of the parent UI surface and the child viewport.
395
+ frame += this.renderMessages(this.layout);
396
+ if (this.statusBar) {
397
+ const text = this.statusBar.render(this.layout.columns);
398
+ frame += renderStatusLine(this.layout, text);
399
+ }
400
+ // Move the real cursor to a sensible position for terminal-state
401
+ // consistency, then keep it hidden. Host-rendered frames always end
402
+ // with HIDE_CURSOR — the visible blink/flicker the hardware cursor
403
+ // would otherwise produce during provider streaming, host-managed
404
+ // warning rows, and host-backed prompts is not desired. SHOW_CURSOR
405
+ // is reserved for stop() and runIsolatedAltScreen suspension paths
406
+ // where another UI or the post-host shell owns the terminal.
407
+ if (surface?.cursor) {
408
+ const placement = mapSurfaceCursorToScreen(this.layout, surface);
409
+ if (placement) {
410
+ frame += `\x1b[${placement.row};${placement.col}H`;
411
+ }
412
+ }
413
+ else if (!parentOnly && this.layout.statusRow !== undefined) {
414
+ const cy = Math.min(Math.max(0, this.vt.cursorY), this.layout.childRows - 1);
415
+ const cx = Math.min(Math.max(0, this.vt.cursorX), this.layout.columns - 1);
416
+ frame += `\x1b[${cy + 1};${cx + 1}H`;
417
+ }
418
+ frame += HIDE_CURSOR;
419
+ this.stdout.write(frame);
420
+ }
421
+ /**
422
+ * Schedule a coalesced full render; multiple events in the same tick
423
+ * produce one frame. Use this for any change that can affect the child
424
+ * viewport, output buffer, status content, or layout.
425
+ */
426
+ scheduleRender() {
427
+ if (!this.isActive || this.suspended)
428
+ return;
429
+ this.pendingFullRender = true;
430
+ this.scheduleFlush();
431
+ }
432
+ /**
433
+ * Schedule a coalesced parent-UI-only render. Used by host-backed
434
+ * prompts when only their own state changed (typing, scroll, cursor
435
+ * move). Skips the child viewport pass so prompt keystrokes do not
436
+ * cause a visible repaint of the unchanged child area.
437
+ *
438
+ * If any other request in the same tick demands a full render, the
439
+ * coalesced flush upgrades to a full render automatically.
440
+ *
441
+ * If the parent UI surface is shorter than `layout.childRows` at flush
442
+ * time, the host falls back to a full render — correctness must not
443
+ * depend on the prompt always producing a full-height surface.
444
+ */
445
+ scheduleParentUiRender() {
446
+ if (!this.isActive || this.suspended)
447
+ return;
448
+ this.scheduleFlush();
449
+ }
450
+ scheduleFlush() {
451
+ if (this.renderScheduled) {
452
+ this.pendingFlush = true;
453
+ return;
454
+ }
455
+ this.renderScheduled = true;
456
+ this.pendingFlush = false;
457
+ setImmediate(() => {
458
+ const wasPending = this.pendingFlush;
459
+ this.renderNow();
460
+ if (wasPending)
461
+ this.scheduleFlush();
462
+ });
463
+ }
464
+ fireInterrupt() {
465
+ if (this.interruptListeners.size === 0)
466
+ return;
467
+ // Snapshot before invoking — listeners may unsubscribe themselves.
468
+ const listeners = Array.from(this.interruptListeners);
469
+ for (const cb of listeners) {
470
+ try {
471
+ cb();
472
+ }
473
+ catch { /* ignore — host is not the right place to swallow user errors loudly */ }
474
+ }
475
+ }
476
+ handleScrollBackLines(lines) {
477
+ if (!this.vt || !this.isActive || this.suspended)
478
+ return;
479
+ this.vt.scrollBack(lines);
480
+ this.scheduleRender();
481
+ }
482
+ handleScrollForwardLines(lines) {
483
+ if (!this.vt || !this.isActive || this.suspended)
484
+ return;
485
+ this.vt.scrollForward(lines);
486
+ this.scheduleRender();
487
+ }
488
+ handleScrollPages(pages) {
489
+ if (!this.vt || !this.isActive || this.suspended)
490
+ return;
491
+ this.vt.scrollPages(pages);
492
+ this.scheduleRender();
493
+ }
494
+ handleScrollToTop() {
495
+ if (!this.vt || !this.isActive || this.suspended)
496
+ return;
497
+ this.vt.scrollToTop();
498
+ this.scheduleRender();
499
+ }
500
+ handleScrollToBottom() {
501
+ if (!this.vt || !this.isActive || this.suspended)
502
+ return;
503
+ this.vt.scrollToBottom();
504
+ this.scheduleRender();
505
+ }
506
+ renderUiSurface(layout, surface) {
507
+ if (surface.lines.length === 0)
508
+ return "";
509
+ const maxLines = Math.min(surface.lines.length, layout.childRows);
510
+ const baseRow = Math.max(0, layout.childRows - maxLines);
511
+ let out = "";
512
+ for (let i = 0; i < maxLines; i++) {
513
+ const text = surface.lines[surface.lines.length - maxLines + i];
514
+ const padded = padOrClip(text, layout.columns);
515
+ out += `\x1b[${baseRow + i + 1};1H\x1b[2K\x1b[0m${padded}`;
516
+ }
517
+ return out;
518
+ }
519
+ renderMessages(layout) {
520
+ if (layout.warningRows === 0 || layout.warningStartRow === undefined)
521
+ return "";
522
+ const messages = this.bufferOutput.snapshot();
523
+ if (messages.length === 0)
524
+ return "";
525
+ // Show the newest messages when the buffer has more than the strip
526
+ // can hold. The strip is sized to `layout.warningRows`, capped at 3
527
+ // by `computeTerminalLayout`.
528
+ const slice = messages.slice(-layout.warningRows);
529
+ let out = "";
530
+ for (let i = 0; i < slice.length; i++) {
531
+ const text = formatOrchestrationMessage(slice[i]);
532
+ const padded = padOrClip(text, layout.columns);
533
+ out += `\x1b[${layout.warningStartRow + i};1H\x1b[2K\x1b[0m${padded}`;
534
+ }
535
+ return out;
536
+ }
537
+ handleResize() {
538
+ if (!this.isActive)
539
+ return;
540
+ this.layout = this.computeLayout();
541
+ if (this.vt)
542
+ this.vt.resize(this.layout.childCols, this.layout.childRows);
543
+ if (this.childHandle) {
544
+ this.childHandle.resize(this.layout.childCols, this.layout.childRows);
545
+ }
546
+ this.scheduleRender();
547
+ }
548
+ computeLayout() {
549
+ const columns = this.stdout.columns ?? 120;
550
+ const rows = this.stdout.rows ?? 30;
551
+ // Layout policy lives here, not in StatusBar.reservedRows. The status
552
+ // row is reserved whenever a status bar is attached and we have a TTY
553
+ // — `computeTerminalLayout` enforces the rows >= 2 rule. The warning
554
+ // strip height tracks the current buffer size (capped at 3 by the
555
+ // layout function).
556
+ const statusEnabled = this.statusBar !== undefined && this.stdout.isTTY === true;
557
+ const warningRows = this.bufferOutput.snapshot().length;
558
+ return computeTerminalLayout({ columns, rows, statusEnabled, warningRows });
559
+ }
560
+ /**
561
+ * Buffer-change hook. Recomputes layout — the warning strip grows or
562
+ * shrinks with buffered message count — and propagates child-viewport
563
+ * size changes to the virtual terminal and the attached child PTY
564
+ * before scheduling a coalesced repaint.
565
+ */
566
+ handleOutputChange() {
567
+ const next = this.computeLayout();
568
+ const prev = this.layout;
569
+ this.layout = next;
570
+ if (prev !== undefined
571
+ && (prev.childCols !== next.childCols || prev.childRows !== next.childRows)) {
572
+ this.vt?.resize(next.childCols, next.childRows);
573
+ this.childHandle?.resize(next.childCols, next.childRows);
574
+ }
575
+ this.scheduleRender();
576
+ }
577
+ }
578
+ function isHostParentUiMode(mode) {
579
+ return typeof mode.getSurface === "function";
580
+ }
581
+ /**
582
+ * Map a surface-relative cursor position to a 1-based screen position.
583
+ *
584
+ * When the surface fits inside the child rows, the entire surface paints
585
+ * starting at row `childRows - lines.length + 1` (1-based) and the cursor
586
+ * row maps directly. When the surface overflows, the host paints only the
587
+ * trailing window — `lines.slice(-childRows)` — at the top of the host
588
+ * region. The cursor row is meaningful only when it falls inside that
589
+ * window; otherwise the visible position is undefined and the host hides
590
+ * the cursor instead of clamping to a wrong row.
591
+ *
592
+ * Returns 1-based `{ row, col }` (so callers can paste into `\x1b[r;cH`)
593
+ * when the cursor is visible, or `undefined` when it's outside the
594
+ * visible window.
595
+ */
596
+ export function mapSurfaceCursorToScreen(layout, surface) {
597
+ if (!surface.cursor)
598
+ return undefined;
599
+ const total = surface.lines.length;
600
+ if (total === 0)
601
+ return undefined;
602
+ const childRows = layout.childRows;
603
+ const visible = Math.min(total, childRows);
604
+ const firstVisible = total - visible; // surface index of the first painted line
605
+ const offsetInWindow = surface.cursor.row - firstVisible;
606
+ if (offsetInWindow < 0 || offsetInWindow >= visible) {
607
+ return undefined;
608
+ }
609
+ // The painted block sits at the bottom of the host region when it fits,
610
+ // and occupies rows 1..visible when it overflows (the trailing window).
611
+ const baseRow = total <= childRows
612
+ ? childRows - total
613
+ : 0;
614
+ const screenRow = baseRow + offsetInWindow + 1; // 1-based
615
+ const screenCol = Math.min(Math.max(1, surface.cursor.col + 1), Math.max(1, layout.columns));
616
+ return { row: screenRow, col: screenCol };
617
+ }
618
+ function padOrClip(text, width) {
619
+ const vis = visibleLength(text);
620
+ if (vis === width)
621
+ return text;
622
+ if (vis < width)
623
+ return text + " ".repeat(width - vis);
624
+ let out = "";
625
+ let count = 0;
626
+ let i = 0;
627
+ while (i < text.length && count < width) {
628
+ if (text[i] === "\x1b" && text[i + 1] === "[") {
629
+ const m = text.slice(i).match(/^\x1b\[[0-9;]*m/);
630
+ if (m) {
631
+ out += m[0];
632
+ i += m[0].length;
633
+ continue;
634
+ }
635
+ }
636
+ out += text[i];
637
+ count += 1;
638
+ i += 1;
639
+ }
640
+ return out;
641
+ }
642
+ //# sourceMappingURL=host.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host.js","sourceRoot":"","sources":["../../src/terminal/host.ts"],"names":[],"mappings":"AAAA,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