@orion-agents/orion-code 0.4.7 → 0.4.9

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 (142) hide show
  1. package/CHANGELOG.md +17 -1
  2. package/README.md +8 -9
  3. package/README.zh-CN.md +8 -8
  4. package/dist/acp/session-updates.js +1 -0
  5. package/dist/cli.js +42 -3
  6. package/dist/commands/session-command-handlers.js +8 -3
  7. package/dist/commands/system-commands.js +3 -3
  8. package/dist/commands/types.d.ts +3 -0
  9. package/dist/framework/loop-progress.js +3 -1
  10. package/dist/framework/query.d.ts +6 -8
  11. package/dist/framework/query.js +39 -76
  12. package/dist/framework/tool-serializer.d.ts +12 -0
  13. package/dist/framework/tool-serializer.js +35 -0
  14. package/dist/framework/tool.d.ts +2 -0
  15. package/dist/framework/verification-command.d.ts +21 -0
  16. package/dist/framework/verification-command.js +53 -4
  17. package/dist/harness/context-harness.d.ts +3 -9
  18. package/dist/harness/context-harness.js +43 -163
  19. package/dist/harness/ledger.js +2 -1
  20. package/dist/harness/state.d.ts +3 -0
  21. package/dist/harness/state.js +37 -4
  22. package/dist/harness/task-checklist.d.ts +1 -1
  23. package/dist/harness/task-checklist.js +1 -1
  24. package/dist/harness/types.d.ts +1 -0
  25. package/dist/harness/verification.js +5 -4
  26. package/dist/print-ui/delivery.d.ts +15 -0
  27. package/dist/print-ui/delivery.js +131 -0
  28. package/dist/print-ui/event-stream.d.ts +6 -1
  29. package/dist/print-ui/event-stream.js +56 -10
  30. package/dist/print-ui/launch.d.ts +5 -0
  31. package/dist/print-ui/launch.js +66 -9
  32. package/dist/runtime/agent-loop.d.ts +3 -1
  33. package/dist/runtime/agent-loop.js +26 -41
  34. package/dist/runtime/agent-runtime-controller.d.ts +4 -1
  35. package/dist/runtime/agent-runtime-controller.js +36 -22
  36. package/dist/runtime/agent-runtime-runner.d.ts +4 -0
  37. package/dist/runtime/agent-runtime-runner.js +9 -0
  38. package/dist/runtime/builtin-tool-provider.js +6 -5
  39. package/dist/runtime/composer/layout.d.ts +1 -1
  40. package/dist/runtime/composer/layout.js +5 -5
  41. package/dist/runtime/core-tools/descriptors.d.ts +1 -1
  42. package/dist/runtime/core-tools/descriptors.js +39 -1
  43. package/dist/runtime/first-party-core-provider.js +1 -0
  44. package/dist/runtime/first-party-tool-services.js +10 -0
  45. package/dist/runtime/goal-lifecycle-v2.js +5 -0
  46. package/dist/runtime/goal-runtime-coordinator.js +6 -2
  47. package/dist/runtime/goals/evidence.js +2 -0
  48. package/dist/runtime/legacy-thread-materializer.d.ts +7 -0
  49. package/dist/runtime/legacy-thread-materializer.js +32 -6
  50. package/dist/runtime/orion-runtime-v1.d.ts +2 -1
  51. package/dist/runtime/orion-runtime-v1.js +34 -6
  52. package/dist/runtime/product-bootstrap.d.ts +2 -0
  53. package/dist/runtime/product-bootstrap.js +1 -0
  54. package/dist/runtime/product-orion-runtime.d.ts +2 -1
  55. package/dist/runtime/product-orion-runtime.js +7 -2
  56. package/dist/runtime/rich-text/layout.d.ts +3 -1
  57. package/dist/runtime/rich-text/layout.js +37 -22
  58. package/dist/runtime/shell-process-sessions.d.ts +41 -0
  59. package/dist/runtime/shell-process-sessions.js +258 -0
  60. package/dist/runtime/step-snapshot.js +61 -11
  61. package/dist/runtime/subagents/presets.d.ts +1 -1
  62. package/dist/runtime/subagents/presets.js +1 -0
  63. package/dist/runtime/task-context-recovery.js +14 -3
  64. package/dist/runtime/task-context-service.d.ts +2 -6
  65. package/dist/runtime/task-context-service.js +3 -12
  66. package/dist/runtime/thread-event-store.d.ts +3 -0
  67. package/dist/runtime/thread-event-store.js +35 -22
  68. package/dist/runtime/thread-session-index.d.ts +15 -3
  69. package/dist/runtime/thread-session-index.js +152 -45
  70. package/dist/runtime/thread-session-view.js +1 -1
  71. package/dist/runtime/thread-ui-adapter.d.ts +1 -1
  72. package/dist/runtime/thread-ui-adapter.js +23 -5
  73. package/dist/runtime/tool-gateway.d.ts +1 -0
  74. package/dist/runtime/tool-gateway.js +1 -0
  75. package/dist/runtime/tool-transcript-entry.d.ts +8 -1
  76. package/dist/runtime/tool-transcript-entry.js +35 -7
  77. package/dist/runtime/ui-events.d.ts +10 -0
  78. package/dist/runtime/verification-feedback.d.ts +4 -0
  79. package/dist/runtime/verification-feedback.js +61 -0
  80. package/dist/services/global-config.d.ts +1 -1
  81. package/dist/services/global-config.js +2 -0
  82. package/dist/services/llm.d.ts +3 -0
  83. package/dist/services/llm.js +48 -4
  84. package/dist/terminal-ui/raw-editor.js +2 -1
  85. package/dist/tools/bash_security.d.ts +1 -24
  86. package/dist/tools/bash_security.js +7 -124
  87. package/dist/tools/core/exec-command.js +51 -42
  88. package/dist/tools/core/index.d.ts +2 -1
  89. package/dist/tools/core/index.js +4 -1
  90. package/dist/tools/core/process-session.d.ts +2 -0
  91. package/dist/tools/core/process-session.js +54 -0
  92. package/dist/tools/todo.js +9 -13
  93. package/dist/tui-core/frame.d.ts +2 -0
  94. package/dist/tui-core/frame.js +19 -0
  95. package/dist/tui-core/input-parser.d.ts +4 -1
  96. package/dist/tui-core/input-parser.js +22 -0
  97. package/dist/tui-ui/chrome-view-model.d.ts +0 -2
  98. package/dist/tui-ui/chrome-view-model.js +54 -56
  99. package/dist/tui-ui/launch.js +133 -202
  100. package/dist/tui-ui/layout.d.ts +16 -41
  101. package/dist/tui-ui/layout.js +408 -295
  102. package/dist/tui-ui/render-scheduler.d.ts +2 -5
  103. package/dist/tui-ui/render-scheduler.js +10 -10
  104. package/dist/tui-ui/response-clipboard.d.ts +17 -0
  105. package/dist/tui-ui/response-clipboard.js +201 -0
  106. package/dist/tui-ui/runner.d.ts +65 -80
  107. package/dist/tui-ui/runner.js +545 -738
  108. package/dist/tui-ui/session-picker-preview.d.ts +8 -0
  109. package/dist/tui-ui/session-picker-preview.js +119 -0
  110. package/dist/tui-ui/session-picker.d.ts +20 -0
  111. package/dist/tui-ui/session-picker.js +42 -0
  112. package/dist/tui-ui/state.d.ts +34 -81
  113. package/dist/tui-ui/state.js +155 -288
  114. package/dist/tui-ui/terminal-image.d.ts +3 -7
  115. package/dist/tui-ui/terminal-image.js +18 -47
  116. package/dist/tui-ui/terminal-viewport.d.ts +55 -0
  117. package/dist/tui-ui/terminal-viewport.js +221 -0
  118. package/dist/tui-ui/transcript-layout.d.ts +5 -0
  119. package/dist/tui-ui/transcript-layout.js +43 -28
  120. package/dist/tui-ui/transcript-pager.d.ts +39 -0
  121. package/dist/tui-ui/transcript-pager.js +278 -0
  122. package/dist/tui-ui/transcript-tool-output.d.ts +16 -0
  123. package/dist/tui-ui/transcript-tool-output.js +102 -0
  124. package/dist/utils/bounded-file.d.ts +4 -0
  125. package/dist/utils/bounded-file.js +30 -0
  126. package/dist/utils/command-process.d.ts +4 -0
  127. package/dist/utils/command-process.js +23 -0
  128. package/dist/utils/shell-command.d.ts +29 -0
  129. package/dist/utils/shell-command.js +185 -0
  130. package/docs/cli-guide.md +50 -6
  131. package/npm-shrinkwrap.json +115 -15
  132. package/package.json +4 -1
  133. package/dist/tui-ui/inline-surface.d.ts +0 -191
  134. package/dist/tui-ui/inline-surface.js +0 -644
  135. package/dist/tui-ui/input-ownership.d.ts +0 -46
  136. package/dist/tui-ui/input-ownership.js +0 -74
  137. package/dist/tui-ui/transcript-inspector-layout.d.ts +0 -9
  138. package/dist/tui-ui/transcript-inspector-layout.js +0 -107
  139. package/dist/tui-ui/transcript-inspector-surface.d.ts +0 -18
  140. package/dist/tui-ui/transcript-inspector-surface.js +0 -91
  141. package/dist/tui-ui/transcript-inspector.d.ts +0 -36
  142. package/dist/tui-ui/transcript-inspector.js +0 -129
@@ -8,16 +8,13 @@ const util_1 = require("util");
8
8
  const ui_events_1 = require("../runtime/ui-events");
9
9
  const ui_view_model_1 = require("../runtime/ui-view-model");
10
10
  const runner_1 = require("./runner");
11
- const inline_surface_1 = require("./inline-surface");
11
+ const response_clipboard_1 = require("./response-clipboard");
12
+ const terminal_viewport_1 = require("./terminal-viewport");
12
13
  const tool_detail_repository_1 = require("../runtime/tool-detail-repository");
13
- const transcript_inspector_surface_1 = require("./transcript-inspector-surface");
14
14
  const child_process_1 = require("child_process");
15
15
  const terminal_image_1 = require("./terminal-image");
16
16
  const theme_1 = require("./theme");
17
- const DISABLE_BRACKETED_PASTE = '\x1b[?2004l';
18
- const SHOW_CURSOR = '\x1b[?25h';
19
- const ENABLE_AUTOWRAP = '\x1b[?7h';
20
- const EXIT_ALTERNATE_SCREEN = '\x1b[?1049l';
17
+ const session_picker_preview_1 = require("./session-picker-preview");
21
18
  async function launchTuiUI(runtime, options = {}) {
22
19
  const input = options.input ?? process.stdin;
23
20
  const output = options.output ?? process.stdout;
@@ -29,19 +26,15 @@ async function launchTuiUI(runtime, options = {}) {
29
26
  let controller;
30
27
  let surface;
31
28
  let stopping = false;
29
+ let rendererFailed = false;
30
+ let editorAbort;
32
31
  let settled = false;
33
32
  let resolveLaunch = null;
34
33
  // Once guard: shared cleanup promise so concurrent stop calls share one execution.
35
34
  let cleanupPromise = null;
36
35
  let restoreConsole = null;
37
36
  let unsubscribeRuntimeStore = null;
38
- const dimensions = () => {
39
- const size = readTtyDimensions(output);
40
- return {
41
- width: Math.max(24, size.width),
42
- height: Math.max(8, size.height),
43
- };
44
- };
37
+ const dimensions = () => readTtyDimensions(output);
45
38
  const finishLaunch = () => {
46
39
  if (settled)
47
40
  return;
@@ -69,7 +62,7 @@ async function launchTuiUI(runtime, options = {}) {
69
62
  /* best effort */
70
63
  }
71
64
  try {
72
- output.write(`${SHOW_CURSOR}${ENABLE_AUTOWRAP}${DISABLE_BRACKETED_PASTE}${EXIT_ALTERNATE_SCREEN}\n`);
65
+ output.write(terminal_viewport_1.TERMINAL_RESTORE);
73
66
  }
74
67
  catch {
75
68
  /* best effort */
@@ -91,11 +84,6 @@ async function launchTuiUI(runtime, options = {}) {
91
84
  if (cleanupPromise)
92
85
  return cleanupPromise;
93
86
  cleanupPromise = (async () => {
94
- // Clear any pending resize debounce timer.
95
- if (resizeDebounceTimer !== null) {
96
- clearTimeout(resizeDebounceTimer);
97
- resizeDebounceTimer = null;
98
- }
99
87
  // Remove listeners first to prevent re-entrancy.
100
88
  try {
101
89
  input.off('data', handleData);
@@ -116,107 +104,69 @@ async function launchTuiUI(runtime, options = {}) {
116
104
  /* ok */
117
105
  }
118
106
  try {
119
- process.off('SIGINT', handleSigint);
120
- }
121
- catch {
122
- /* ok */
123
- }
124
- try {
125
- process.off('SIGTERM', handleSigterm);
126
- }
127
- catch {
128
- /* ok */
129
- }
130
- try {
131
- process.off('SIGHUP', handleSighup);
107
+ process.off('unhandledRejection', onUnhandledRejection);
132
108
  }
133
109
  catch {
134
110
  /* ok */
135
111
  }
112
+ unsubscribeRuntimeStore?.();
113
+ unsubscribeRuntimeStore = null;
114
+ // Start cancellation promptly, but release the terminal even if an active tool is slow to stop.
115
+ const turnStopped = controller?.stopActiveTurn().catch(() => undefined);
116
+ const editorWasActive = Boolean(editorAbort);
117
+ editorAbort?.abort();
118
+ runner?.stop();
136
119
  try {
137
- process.off('unhandledRejection', onUnhandledRejection);
120
+ const history = rendererFailed || editorWasActive
121
+ ? undefined
122
+ : runner?.completedHistoryRows(dimensions().width);
123
+ await surface?.unmount(history);
138
124
  }
139
125
  catch {
140
- /* ok */
126
+ emergencyRestore();
141
127
  }
142
- unsubscribeRuntimeStore?.();
143
- unsubscribeRuntimeStore = null;
144
- // Stop active turn (controller may not exist if init failed).
145
- if (controller) {
128
+ finally {
129
+ // While replay is draining, VINTR in canonical mode can flush the shell's output queue.
146
130
  try {
147
- await controller.stopActiveTurn();
131
+ input.setRawMode?.(false);
148
132
  }
149
133
  catch {
150
- /* best effort — don't block cleanup */
134
+ /* best effort */
151
135
  }
152
- }
153
- if (runner) {
154
136
  try {
155
- await runner.closeModalSurface();
156
- await runner.flushTranscriptCommits();
137
+ input.pause();
157
138
  }
158
139
  catch {
159
140
  /* best effort */
160
141
  }
161
142
  }
162
- // Restore raw mode.
143
+ restoreConsole?.();
144
+ restoreConsole = null;
145
+ await turnStopped;
146
+ // Runtime shutdown follows terminal restoration and turn cancellation.
163
147
  try {
164
- if (typeof input.setRawMode === 'function') {
165
- input.setRawMode(false);
166
- }
148
+ await runtime.shutdown();
167
149
  }
168
150
  catch {
169
151
  /* best effort */
170
152
  }
171
153
  try {
172
- input.pause();
154
+ process.off('SIGINT', handleSigint);
173
155
  }
174
156
  catch {
175
- /* best effort */
176
- }
177
- // Stop scheduler before surface cleanup (prevents pending renders).
178
- if (runner) {
179
- try {
180
- runner.stop();
181
- }
182
- catch {
183
- /* best effort */
184
- }
185
- }
186
- // Flush surface queue to ensure all pending writes complete.
187
- if (surface) {
188
- try {
189
- await surface.flush();
190
- }
191
- catch {
192
- /* best effort */
193
- }
194
- }
195
- // Unmount surface (clears ephemeral live region only).
196
- if (surface) {
197
- try {
198
- await surface.unmount();
199
- }
200
- catch {
201
- /* best effort */
202
- }
157
+ /* ok */
203
158
  }
204
- restoreConsole?.();
205
- restoreConsole = null;
206
- // Restore terminal state: cursor, autowrap, bracketed paste.
207
- // NO alternate-screen exit, NO full clear, NO erasing committed scrollback.
208
159
  try {
209
- output.write(`${SHOW_CURSOR}${ENABLE_AUTOWRAP}${DISABLE_BRACKETED_PASTE}`);
160
+ process.off('SIGTERM', handleSigterm);
210
161
  }
211
162
  catch {
212
- /* best effort */
163
+ /* ok */
213
164
  }
214
- // Runtime shutdown last; preserves original exit code/signal semantics.
215
165
  try {
216
- await runtime.shutdown();
166
+ process.off('SIGHUP', handleSighup);
217
167
  }
218
168
  catch {
219
- /* best effort */
169
+ /* ok */
220
170
  }
221
171
  })();
222
172
  return cleanupPromise;
@@ -240,81 +190,28 @@ async function launchTuiUI(runtime, options = {}) {
240
190
  }
241
191
  finishLaunch();
242
192
  };
243
- /**
244
- * Handle renderer-layer errors. Emergency restore first, then report.
245
- */
246
193
  const failRenderer = (error) => {
247
194
  if (stopping)
248
195
  return;
249
196
  stopping = true;
250
- // Emergency restore independent of partially-constructed objects.
251
- emergencyRestore();
252
- // Report sanitized renderer-layer error to stderr.
253
- try {
254
- const message = error instanceof Error ? error.message : String(error);
255
- process.stderr.write(`\nTUI renderer error: ${message}\n`);
256
- }
257
- catch {
258
- /* best effort */
259
- }
260
- // Attempt full cleanup (may partially fail — that's ok).
261
- // Ensure finishLaunch() runs on both success and rejection so the error
262
- // path always completes and no unhandled promise rejection escapes.
197
+ rendererFailed = true;
263
198
  void cleanup()
264
- .catch(() => {
265
- // Cleanup failure must not mask the original renderer error.
266
- emergencyRestore();
267
- })
199
+ .catch(emergencyRestore)
268
200
  .finally(() => {
269
- finishLaunch();
270
- });
271
- };
272
- const consumeSessionPickerSelection = (inputValue) => {
273
- const overlay = runner.getState().overlay;
274
- if (overlay?.type !== 'sessions')
275
- return inputValue;
276
- runner.dispatch({ type: 'closeOverlay' });
277
- const request = overlay.request;
278
- const trimmed = inputValue.trim();
279
- if (!trimmed) {
280
- const selected = request.sessions[overlay.selectedIndex];
281
- if (!selected) {
282
- runner.events.append({ role: 'error', content: 'No session selected.' });
283
- return '';
201
+ try {
202
+ const message = error instanceof Error ? error.message : String(error);
203
+ process.stderr.write(`\nTUI renderer error: ${message}\n`);
284
204
  }
285
- return {
286
- type: 'select_session',
287
- sessionId: selected.id,
288
- allProjects: request.allProjects,
289
- source: 'picker',
290
- };
291
- }
292
- if (trimmed.startsWith('/'))
293
- return trimmed;
294
- const numeric = trimmed.match(/^#?(\d+)$/);
295
- if (numeric) {
296
- const index = Number(numeric[1]) - 1;
297
- const selected = request.sessions[index];
298
- if (!selected) {
299
- runner.events.append({ role: 'error', content: `No session at index ${numeric[1]}.` });
300
- return '';
205
+ catch {
206
+ /* best effort */
301
207
  }
302
- return {
303
- type: 'select_session',
304
- sessionId: selected.id,
305
- allProjects: request.allProjects,
306
- source: 'picker',
307
- };
308
- }
309
- return {
310
- type: 'select_session',
311
- sessionId: trimmed,
312
- allProjects: request.allProjects,
313
- source: 'picker',
314
- };
208
+ finally {
209
+ finishLaunch();
210
+ }
211
+ });
315
212
  };
316
213
  const submit = (rawInput) => {
317
- const selectedInput = consumeModelPickerSelection(consumeSessionPickerSelection(rawInput));
214
+ const selectedInput = consumeModelPickerSelection(rawInput);
318
215
  const runtimeInput = typeof selectedInput === 'string'
319
216
  ? { type: 'submit', text: selectedInput.trim(), source: 'composer' }
320
217
  : selectedInput;
@@ -332,8 +229,6 @@ async function launchTuiUI(runtime, options = {}) {
332
229
  }
333
230
  };
334
231
  const consumeModelPickerSelection = (inputValue) => {
335
- if (typeof inputValue !== 'string')
336
- return inputValue;
337
232
  const overlay = runner.getState().overlay;
338
233
  if (overlay?.type !== 'model')
339
234
  return inputValue;
@@ -391,25 +286,15 @@ async function launchTuiUI(runtime, options = {}) {
391
286
  runner.feedInput(chunk);
392
287
  }
393
288
  };
394
- let resizeDebounceTimer = null;
395
- const RESIZE_DEBOUNCE_MS = 100;
396
289
  const handleResize = () => {
397
290
  if (stopping)
398
291
  return;
399
- runner.beginResize(dimensions().width);
400
- if (resizeDebounceTimer !== null) {
401
- clearTimeout(resizeDebounceTimer);
402
- }
403
- resizeDebounceTimer = setTimeout(() => {
404
- resizeDebounceTimer = null;
405
- if (stopping)
406
- return;
407
- const { width, height } = dimensions();
408
- runner.resize(width, height);
409
- }, RESIZE_DEBOUNCE_MS);
292
+ const size = dimensions();
293
+ runner.resize(size.width, size.height);
410
294
  };
411
295
  const handleSigint = () => {
412
- handleCtrlC();
296
+ if (!stopping && !editorAbort)
297
+ handleCtrlC();
413
298
  };
414
299
  // SIGTERM/SIGHUP: direct cancel + cleanup (no "double Ctrl+C" product semantics).
415
300
  const handleSigterm = () => {
@@ -419,38 +304,22 @@ async function launchTuiUI(runtime, options = {}) {
419
304
  void stop();
420
305
  };
421
306
  try {
422
- // Primary-screen inline surface: no alternate screen (1049).
307
+ // The same alternate-screen viewport serves chat and all history views.
423
308
  const { width, height } = dimensions();
424
309
  const startupSnapshot = runtime.store.getSnapshot();
425
310
  const suppressColor = Object.prototype.hasOwnProperty.call(env, 'NO_COLOR') || env.FORCE_COLOR === '0';
426
- const renderMascot = (0, terminal_image_1.shouldRenderTuiMascot)({
427
- suppressColor,
428
- mascot: runtime.config.ui?.mascot,
429
- theme: runtime.config.ui?.theme,
430
- });
431
- output.write((0, terminal_image_1.renderTuiStartupBanner)({
432
- cwd: runtime.cwd,
433
- version: runtime.version,
434
- model: startupSnapshot.currentModel || runtime.config.model,
435
- terminalWidth: width,
436
- suppressColor,
437
- mascot: runtime.config.ui?.mascot,
438
- theme: runtime.config.ui?.theme,
439
- }));
440
- surface = new inline_surface_1.InlineTerminalSurface({ output });
441
- const inspectorSurface = new transcript_inspector_surface_1.TranscriptInspectorSurface(output);
442
- // Mount enters the same serialized queue as subsequent paints. Start it
443
- // synchronously so input listeners are installed in this turn; awaiting it
444
- // here creates a window where early keystrokes are dropped.
445
- void surface.mount(width, height).catch(error => failRenderer(error));
446
- // surface.mount() enables bracketed paste and hides cursor; no need for
447
- // redundant output.write of those sequences.
311
+ surface = new terminal_viewport_1.TerminalViewport({ output });
312
+ // Queue mount before the first paint without delaying input listener setup.
313
+ void surface.mount().catch(failRenderer);
448
314
  runner = new runner_1.TuiRunner({
449
315
  output,
450
316
  width,
451
317
  height,
452
318
  cwd: runtime.cwd,
453
319
  onSubmit: submit,
320
+ onSelectSession: (sessionId, allProjects) => controller.handle({ type: 'select_session', sessionId, allProjects, source: 'picker' })
321
+ .type === 'command_handled',
322
+ loadSessionPreview: session_picker_preview_1.loadSessionPickerPreview,
454
323
  onQueueSubmit: text => controller.handle({ type: 'queue_followup', text, source: 'composer' }).type ===
455
324
  'followup_queued',
456
325
  onCtrlC: handleCtrlC,
@@ -468,6 +337,29 @@ async function launchTuiUI(runtime, options = {}) {
468
337
  onQueueClear: () => {
469
338
  controller.handle({ type: 'manage_followup_queue', action: 'clear', source: 'command' });
470
339
  },
340
+ onQueueMutation: mutation => {
341
+ const { itemId, revision } = mutation;
342
+ try {
343
+ if (mutation.type === 'move') {
344
+ controller.moveFollowupQueueItem(itemId, revision, mutation.index);
345
+ }
346
+ else if (mutation.type === 'remove') {
347
+ controller.removeFollowupQueueItem(itemId, revision);
348
+ }
349
+ else {
350
+ const result = controller.editFollowupQueueItem(itemId, revision, mutation.text);
351
+ if (result.type === 'empty')
352
+ return 'Enter a message to save.';
353
+ if (result.type !== 'followup_queue_changed')
354
+ return 'Message exceeds the queue limit.';
355
+ }
356
+ }
357
+ catch (error) {
358
+ if (error instanceof agent_runtime_controller_1.FollowupQueueConflictError)
359
+ return 'Message already sent or changed.';
360
+ throw error;
361
+ }
362
+ },
471
363
  onPermissionDecision: (requestId, approved, scope) => {
472
364
  controller.handle({
473
365
  type: 'permission_decision',
@@ -488,32 +380,64 @@ async function launchTuiUI(runtime, options = {}) {
488
380
  theme: (0, theme_1.resolveTuiThemePreference)(runtime.config.ui?.theme ?? 'orion-pixel'),
489
381
  themeId: runtime.config.ui?.theme ?? 'orion-pixel',
490
382
  statusLine: runtime.config.ui?.statusLine,
491
- mascot: renderMascot,
383
+ startupRows: terminalWidth => (0, terminal_image_1.layoutTuiStartupBanner)({
384
+ cwd: runtime.cwd,
385
+ version: runtime.version,
386
+ terminalWidth,
387
+ suppressColor,
388
+ mascot: runtime.config.ui?.mascot,
389
+ theme: runtime.config.ui?.theme,
390
+ }),
492
391
  keymap: runtime.config.ui?.keymap,
493
392
  motion: runtime.config.ui?.motion,
494
393
  onSurfaceError: failRenderer,
495
394
  detailRepository: new tool_detail_repository_1.FileToolDetailRepository(),
496
- inspectorSurface,
395
+ copyToClipboard: markdown => (0, response_clipboard_1.copyResponseToClipboard)(markdown, {
396
+ env,
397
+ writeTerminal: sequence => surface.writeClipboardControl(sequence),
398
+ }),
497
399
  onOpenExternalEditor: async (filePath) => {
498
- await surface.suspend();
400
+ if (stopping)
401
+ return;
402
+ editorAbort = new AbortController();
499
403
  input.off('data', handleData);
500
404
  try {
405
+ await surface.suspend().catch(error => {
406
+ failRenderer(error);
407
+ throw error;
408
+ });
409
+ if (stopping)
410
+ return;
501
411
  if (typeof input.setRawMode === 'function')
502
412
  input.setRawMode(false);
503
413
  input.pause();
504
- await launchExternalEditor(filePath);
414
+ await launchExternalEditor(filePath, editorAbort.signal);
505
415
  }
506
416
  finally {
417
+ editorAbort = undefined;
507
418
  if (!stopping) {
508
- input.resume();
509
- if (typeof input.setRawMode === 'function')
510
- input.setRawMode(true);
511
- input.on('data', handleData);
512
- await surface.restore(() => null, dimensions().width, dimensions().height);
419
+ try {
420
+ await surface.restore();
421
+ const { width, height } = dimensions();
422
+ runner.resize(width, height);
423
+ runner.redraw();
424
+ if (typeof input.setRawMode === 'function')
425
+ input.setRawMode(true);
426
+ input.on('data', handleData);
427
+ input.resume();
428
+ }
429
+ catch (error) {
430
+ failRenderer(error);
431
+ throw error;
432
+ }
513
433
  }
514
434
  }
515
435
  },
516
436
  });
437
+ if (stopping) {
438
+ await cleanup();
439
+ return;
440
+ }
517
441
  restoreConsole = installTuiConsoleBridge(runner.events, () => stopping);
518
442
  const dispatchStatusSnapshot = (phase) => {
519
443
  const runtimeSnapshot = runtime.store.getSnapshot();
@@ -540,6 +464,7 @@ async function launchTuiUI(runtime, options = {}) {
540
464
  });
541
465
  controller = new agent_runtime_controller_1.AgentRuntimeController({
542
466
  runtime,
467
+ onRestoreTranscriptHistory: source => runner.setTranscriptHistorySource(source),
543
468
  events: runner.events,
544
469
  uiCapabilities: (0, ui_events_1.resolveUiRendererCapabilities)(undefined, 'tui'),
545
470
  uiRenderer: 'tui',
@@ -547,6 +472,8 @@ async function launchTuiUI(runtime, options = {}) {
547
472
  // OrionSessionRunner projects the durable Thread user item. A second
548
473
  // controller-owned optimistic append would render every submission twice.
549
474
  echoSubmittedInput: false,
475
+ revisionStatus: 'Steer received',
476
+ restartingStatus: 'Applying steer',
550
477
  runningStatus: () => dispatchStatusSnapshot('running'),
551
478
  readyStatus: () => dispatchStatusSnapshot('ready'),
552
479
  });
@@ -564,11 +491,15 @@ async function launchTuiUI(runtime, options = {}) {
564
491
  process.on('SIGHUP', handleSighup);
565
492
  process.on('unhandledRejection', onUnhandledRejection);
566
493
  await new Promise(resolve => {
567
- resolveLaunch = resolve;
494
+ if (settled)
495
+ resolve();
496
+ else
497
+ resolveLaunch = resolve;
568
498
  });
569
499
  }
570
500
  catch (error) {
571
501
  failRenderer(error);
502
+ await cleanup().catch(emergencyRestore);
572
503
  throw error;
573
504
  }
574
505
  }
@@ -618,14 +549,14 @@ function parseExternalEditorCommand(commandLine) {
618
549
  args.push(current);
619
550
  return args;
620
551
  }
621
- function launchExternalEditor(filePath) {
552
+ function launchExternalEditor(filePath, signal) {
622
553
  const editorCommand = process.env.VISUAL || process.env.EDITOR || 'vi';
623
554
  const [editor, ...editorArgs] = parseExternalEditorCommand(editorCommand);
624
555
  if (!editor) {
625
556
  return Promise.reject(new Error('$VISUAL/$EDITOR does not name an executable'));
626
557
  }
627
558
  return new Promise((resolve, reject) => {
628
- const child = (0, child_process_1.spawn)(editor, [...editorArgs, filePath], { stdio: 'inherit' });
559
+ const child = (0, child_process_1.spawn)(editor, [...editorArgs, filePath], { stdio: 'inherit', signal });
629
560
  child.once('error', reject);
630
561
  child.once('exit', (code, signal) => {
631
562
  if (code === 0) {
@@ -1,61 +1,36 @@
1
1
  import { type TuiFrame } from '../tui-core/frame';
2
2
  import { type StyledRow, type TuiTheme } from '../tui-core/style';
3
- import { type TuiTranscriptRecord, type TuiUiState } from './state';
3
+ import type { TuiTranscriptRecord, TuiUiState } from './state';
4
+ import { TranscriptPager } from './transcript-pager';
4
5
  import type { TuiStatusItem } from '../services/global-config';
5
6
  export type TranscriptRecordLayout = (entry: TuiTranscriptRecord, width: number) => StyledRow[];
6
7
  export interface TuiTranscriptLayoutOptions {
7
- /** Transcript content width; production uses the surface safe width. */
8
+ /** Optional width for transcript content within the viewport. */
8
9
  transcriptWidth?: number;
9
10
  theme?: TuiTheme;
10
11
  toolOutputMode?: 'adaptive' | 'collapsed' | 'full';
11
12
  /** Runner-provided cached layout. Pure render callers use the shared default. */
12
13
  layoutTranscriptRecord?: TranscriptRecordLayout;
13
14
  statusLine?: readonly TuiStatusItem[];
14
- mascot?: boolean;
15
15
  animationFrame?: number;
16
+ activityElapsedSeconds?: number;
16
17
  }
17
18
  export interface TuiLayoutOptions extends TuiTranscriptLayoutOptions {
18
19
  width: number;
19
20
  height: number;
20
21
  maxTranscriptRows?: number;
22
+ transcriptPager?: TranscriptPager;
23
+ startupRows?: readonly StyledRow[];
21
24
  }
22
- /**
23
- * Options for the live-region-only layout (renderTuiLiveFrame).
24
- * This function produces a frame for the inline surface's live region only,
25
- * containing the reflowable transcript tail, timeline, overlay, status, and
26
- * prompt. Entries queued for native scrollback are rendered separately.
27
- */
28
- export interface TuiLiveLayoutOptions extends TuiTranscriptLayoutOptions {
29
- width: number;
30
- /** Height of the live region (the inline surface bottom band). */
31
- height: number;
32
- }
33
- export interface TuiLayoutBudget {
34
- promptLineCount: number;
35
- /** Rows consumed by the prompt box (2 borders + N content lines). */
36
- promptRows: number;
37
- /** Rows consumed by the timeline strip (0 when there is no activity). */
38
- timelineRows: number;
39
- activityRows: number;
40
- /** Rows available for the (live) transcript region at the top. */
41
- transcriptRows: number;
42
- }
43
- /**
44
- * Measure the cursor-owned live block. Idle TUI state stays compact like an
45
- * ordinary shell prompt. Composer pickers draw into this same block, so opening
46
- * one does not allocate terminal rows or advance native scrollback.
47
- */
48
- export declare function measureTuiLiveFrameHeight(state: TuiUiState, width: number, maxHeight: number, options?: TuiTranscriptLayoutOptions): number;
49
25
  export declare function renderTuiUiFrame(state: TuiUiState, options: TuiLayoutOptions): TuiFrame;
50
- /**
51
- * Render the live-region frame for InlineTerminalSurface.
52
- *
53
- * This frame owns the reflowable transcript tail, timeline, overlay, status,
54
- * and prompt. Older entries leave this frame once queued for native scrollback.
55
- *
56
- * The frame height should be sized to fill the terminal viewport's bottom band
57
- * (see InlineTerminalSurface.getLiveBandRows); the dynamic budget allocates the
58
- * band rows between transcript / timeline / status / prompt.
59
- */
60
- export declare function renderTuiLiveFrame(state: TuiUiState, options: TuiLiveLayoutOptions): TuiFrame;
26
+ /** The full transcript view reads the same records as the chat viewport. */
27
+ export declare function renderTranscriptPagerFrame(state: TuiUiState, options: TuiLayoutOptions & {
28
+ transcriptPager: TranscriptPager;
29
+ onVisibleRecord?: (record: TuiTranscriptRecord) => void;
30
+ olderRecords?: readonly TuiTranscriptRecord[];
31
+ hasEarlierRecords?: boolean;
32
+ loadingEarlierRecords?: boolean;
33
+ }): TuiFrame;
34
+ /** Move within the displayed draft before Up/Down hands off to input history. */
35
+ export declare function moveTuiPromptVisualCursor(value: string, cursor: number, width: number, direction: -1 | 1): number | undefined;
61
36
  //# sourceMappingURL=layout.d.ts.map