@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
@@ -3,185 +3,227 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.measureTuiLiveFrameHeight = measureTuiLiveFrameHeight;
7
6
  exports.renderTuiUiFrame = renderTuiUiFrame;
8
- exports.renderTuiLiveFrame = renderTuiLiveFrame;
7
+ exports.renderTranscriptPagerFrame = renderTranscriptPagerFrame;
8
+ exports.moveTuiPromptVisualCursor = moveTuiPromptVisualCursor;
9
9
  const string_width_1 = __importDefault(require("string-width"));
10
10
  const frame_1 = require("../tui-core/frame");
11
11
  const style_1 = require("../tui-core/style");
12
12
  const grapheme_1 = require("../runtime/composer/grapheme");
13
+ const layout_1 = require("../runtime/composer/layout");
13
14
  const ui_view_model_1 = require("../runtime/ui-view-model");
14
15
  const format_1 = require("../services/format");
15
- const state_1 = require("./state");
16
16
  const transcript_layout_1 = require("./transcript-layout");
17
+ const transcript_pager_1 = require("./transcript-pager");
17
18
  const chrome_view_model_1 = require("./chrome-view-model");
18
- const pixel_mascot_1 = require("./pixel-mascot");
19
- const MIN_WIDTH = 24;
20
- const MIN_HEIGHT = 8;
21
- const PROMPT_BORDER_ROWS = 2;
22
- const MAX_TIMELINE_ROWS = 6;
19
+ const PROMPT_PREFIX = '› ';
20
+ const MAX_PROMPT_ROWS = 6;
23
21
  const MAX_COMPOSER_PICKER_ROWS = 6;
24
- const STATUS_ROWS = 1;
25
22
  const ACTIVITY_SPINNER = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧'];
26
- /**
27
- * Compute a dynamic layout budget for the given terminal height and prompt.
28
- *
29
- * The prompt box grows with the number of prompt lines (multi-line prompts get
30
- * a taller box); the timeline strip appears only when there is activity to show
31
- * (tools running / subtasks). Remaining rows go to the transcript, which is the
32
- * scrollable history region. For a single-line prompt with no activity this
33
- * collapses to the original fixed layout (prompt = 3 rows at the bottom).
34
- */
35
- function computeBudget(height, state) {
36
- const activityRows = state.processing ? 1 : 0;
37
- const timelineCount = countTimelineEntries(state);
38
- const totalPromptLines = Math.max(1, state.prompt.value.split('\n').length);
39
- const maxPromptLines = Math.max(1, height - PROMPT_BORDER_ROWS - STATUS_ROWS - activityRows);
40
- const promptLineCount = Math.min(totalPromptLines, maxPromptLines);
41
- const promptRows = PROMPT_BORDER_ROWS + promptLineCount;
42
- const maxTimelineRows = Math.max(0, height - promptRows - STATUS_ROWS - activityRows);
43
- const timelineRows = timelineCount > 0 ? Math.min(MAX_TIMELINE_ROWS, timelineCount, maxTimelineRows) : 0;
44
- const transcriptRows = maxTimelineRows - timelineRows;
45
- return { promptLineCount, promptRows, timelineRows, activityRows, transcriptRows };
46
- }
47
- function countTimelineEntries(state) {
48
- return activeSubtaskTimelineEntries(state).length + activeToolStarts(state).length;
23
+ /** Keep the editable row and activity visible, then allocate the popup or passive footer. */
24
+ function computeBudget(height, state, visualPromptRows, picker) {
25
+ const activityRows = Number(state.processing && height > 1);
26
+ const available = height - activityRows;
27
+ const minHistory = picker
28
+ ? Number(available > 2 && state.transcript.length > 0)
29
+ : Number(available > 1 && (state.transcript.length > 0 || !!state.overlay));
30
+ const bottomRows = available - minHistory;
31
+ const footerRows = picker
32
+ ? Math.min(bottomRows - 1, MAX_COMPOSER_PICKER_ROWS, Math.max(1, Math.floor(height / 2)), Math.max(1, picker.items.length + Number(picker.type === 'files')))
33
+ : Number(bottomRows > 1);
34
+ const promptRows = Math.min(visualPromptRows, MAX_PROMPT_ROWS, Math.max(1, Math.floor(height / 2)), bottomRows - footerRows);
35
+ const queueRows = picker
36
+ ? 0
37
+ : Math.max(0, Math.min(2, state.followupQueue.items.length, bottomRows - promptRows - footerRows));
38
+ return {
39
+ promptRows,
40
+ activityRows,
41
+ queueRows,
42
+ footerRows,
43
+ transcriptRows: available - promptRows - footerRows - queueRows,
44
+ };
49
45
  }
50
46
  function activeToolStarts(state) {
51
47
  const finishedCallIds = new Set(state.runtimeToolEvents.filter(event => event.type === 'finished').map(event => event.callId));
52
48
  return state.runtimeToolEvents.filter(event => event.type === 'started' && !finishedCallIds.has(event.callId));
53
49
  }
54
- function activeSubtaskTimelineEntries(state) {
55
- return state.subtaskTimeline.filter(entry => entry.state === 'queued' || entry.state === 'running');
56
- }
57
- /**
58
- * Measure the cursor-owned live block. Idle TUI state stays compact like an
59
- * ordinary shell prompt. Composer pickers draw into this same block, so opening
60
- * one does not allocate terminal rows or advance native scrollback.
61
- */
62
- function measureTuiLiveFrameHeight(state, width, maxHeight, options = {}) {
63
- const safeWidth = Math.max(MIN_WIDTH, Math.floor(width));
64
- const transcriptWidth = resolveTranscriptWidth(safeWidth, options.transcriptWidth);
65
- const safeMaxHeight = Math.max(MIN_HEIGHT, Math.floor(maxHeight));
66
- if (state.overlay && state.overlay.type !== 'commands' && state.overlay.type !== 'files') {
67
- return safeMaxHeight;
68
- }
69
- const budget = computeBudget(safeMaxHeight, state);
70
- const fixedRows = safeMaxHeight - budget.transcriptRows;
71
- const transcriptRows = state.transcript
72
- .slice(state.queuedTranscriptCount)
73
- .reduce((count, entry) => count + layoutRecord(entry, transcriptWidth, options).length, 0);
74
- return Math.min(safeMaxHeight, Math.max(MIN_HEIGHT, fixedRows + transcriptRows));
75
- }
76
50
  function renderTuiUiFrame(state, options) {
77
- const width = Math.max(MIN_WIDTH, Math.floor(options.width));
78
- const height = Math.max(MIN_HEIGHT, Math.floor(options.height));
79
- const frame = (0, frame_1.createTuiFrame)(width, height);
80
- const budget = computeBudget(height, state);
81
- // Honour an explicit cap on the transcript region (used by a test to pin a
82
- // small tail); otherwise the whole transcript region is used.
51
+ const frame = (0, frame_1.createTuiFrame)(options.width, options.height);
52
+ const theme = options.theme ?? style_1.DEFAULT_THEME;
53
+ const overlay = state.overlay;
54
+ if (overlay?.type === 'permission') {
55
+ renderPermissionPicker(frame, overlay, theme);
56
+ (0, frame_1.setFrameCursor)(frame, 0, 0, false);
57
+ return frame;
58
+ }
59
+ if (overlay?.type === 'sessions') {
60
+ renderSessionPicker(frame, state, overlay, theme);
61
+ return frame;
62
+ }
63
+ if (overlay?.type === 'queue') {
64
+ renderFollowupQueue(frame, state, overlay, theme);
65
+ return frame;
66
+ }
67
+ const picker = overlay?.type === 'commands' || overlay?.type === 'files' ? overlay : null;
68
+ const prompt = layoutPrompt(state.prompt.value, state.prompt.cursor, frame.width);
69
+ const budget = computeBudget(frame.height, state, prompt.lines.length, picker);
83
70
  const transcriptRows = Math.max(0, Math.min(options.maxTranscriptRows ?? budget.transcriptRows, budget.transcriptRows));
84
- const promptTop = height - budget.promptRows;
85
- const statusRow = promptTop - 1;
86
- const activityRow = statusRow - budget.activityRows;
87
- const timelineTop = activityRow - budget.timelineRows;
88
- renderTranscript(frame, state, 0, transcriptRows, options);
89
- if (budget.timelineRows > 0)
90
- renderTimeline(frame, state, timelineTop, budget.timelineRows, options.theme);
91
- renderStatus(frame, state, statusRow, options);
92
- renderPrompt(frame, state, promptTop, width, budget.promptLineCount, options.theme);
93
- renderOverlay(frame, state.overlay, activityRow, timelineTop, options.theme ?? style_1.DEFAULT_THEME);
94
- if (budget.activityRows)
95
- renderActivity(frame, state, activityRow, options);
71
+ const footerTop = frame.height - budget.footerRows;
72
+ const promptTop = footerTop - budget.promptRows;
73
+ const pager = options.transcriptPager ?? new transcript_pager_1.TranscriptPager();
74
+ const fullPicker = overlay && !picker;
75
+ if (fullPicker) {
76
+ renderOverlay(frame, overlay, budget.transcriptRows);
77
+ }
78
+ else {
79
+ if (!state.transcript.length && options.startupRows) {
80
+ options.startupRows.slice(0, transcriptRows).forEach((row, index) => {
81
+ let available = frame.width;
82
+ const clipped = [];
83
+ for (const span of row) {
84
+ const text = truncateCells(span.text, available);
85
+ if (text.length === 0)
86
+ break;
87
+ clipped.push({ ...span, text });
88
+ available -= (0, string_width_1.default)(text);
89
+ }
90
+ (0, transcript_layout_1.writeStyledRowToFrame)(frame, index, clipped);
91
+ });
92
+ }
93
+ else {
94
+ const toolOutputMode = options.toolOutputMode ?? state.toolOutputViewMode;
95
+ renderTranscript(frame, state, 0, transcriptRows, { ...options, toolOutputMode }, pager, {
96
+ layoutExploration: toolOutputMode === 'full'
97
+ ? undefined
98
+ : (counts, width) => layoutExplorationGroup(counts, width, theme),
99
+ });
100
+ }
101
+ }
102
+ if (budget.queueRows) {
103
+ renderFollowupPreview(frame, state, budget.transcriptRows, budget.queueRows, theme);
104
+ }
105
+ if (budget.activityRows) {
106
+ renderActivity(frame, state, budget.transcriptRows + budget.queueRows, options);
107
+ }
108
+ renderPrompt(frame, state, prompt, promptTop, budget.promptRows, theme);
109
+ if (budget.footerRows) {
110
+ if (picker)
111
+ renderComposerPicker(frame, picker, footerTop, budget.footerRows, theme);
112
+ else
113
+ renderStatus(frame, state, footerTop, options, !pager.isFollowing, budget.queueRows > 0);
114
+ }
96
115
  return frame;
97
116
  }
98
- /**
99
- * Render the live-region frame for InlineTerminalSurface.
100
- *
101
- * This frame owns the reflowable transcript tail, timeline, overlay, status,
102
- * and prompt. Older entries leave this frame once queued for native scrollback.
103
- *
104
- * The frame height should be sized to fill the terminal viewport's bottom band
105
- * (see InlineTerminalSurface.getLiveBandRows); the dynamic budget allocates the
106
- * band rows between transcript / timeline / status / prompt.
107
- */
108
- function renderTuiLiveFrame(state, options) {
109
- const width = Math.max(MIN_WIDTH, Math.floor(options.width));
110
- const height = Math.max(MIN_HEIGHT, Math.floor(options.height));
111
- const frame = (0, frame_1.createTuiFrame)(width, height);
112
- const budget = computeBudget(height, state);
113
- const promptTop = height - budget.promptRows;
114
- const statusRow = promptTop - 1;
115
- const activityRow = statusRow - budget.activityRows;
116
- const timelineTop = activityRow - budget.timelineRows;
117
- renderLiveTranscript(frame, state, 0, budget.transcriptRows, options);
118
- if (budget.timelineRows > 0)
119
- renderTimeline(frame, state, timelineTop, budget.timelineRows, options.theme);
120
- renderStatus(frame, state, statusRow, options);
121
- renderPrompt(frame, state, promptTop, width, budget.promptLineCount, options.theme);
122
- renderOverlay(frame, state.overlay, activityRow, timelineTop, options.theme ?? style_1.DEFAULT_THEME);
123
- if (budget.activityRows)
124
- renderActivity(frame, state, activityRow, options);
117
+ /** The full transcript view reads the same records as the chat viewport. */
118
+ function renderTranscriptPagerFrame(state, options) {
119
+ const frame = (0, frame_1.createTuiFrame)(options.width, options.height);
120
+ const theme = options.theme ?? style_1.DEFAULT_THEME;
121
+ const tail = activeToolStarts(state).map(event => ({
122
+ id: `running-tool:${event.callId}`,
123
+ role: 'tool',
124
+ content: '',
125
+ finalized: false,
126
+ revision: 1,
127
+ toolActivity: {
128
+ state: 'running',
129
+ name: event.name,
130
+ detail: '',
131
+ command: event.command,
132
+ body: '',
133
+ callId: event.callId,
134
+ seq: event.sequence,
135
+ },
136
+ }));
137
+ const pageOptions = {
138
+ head: options.olderRecords,
139
+ tail,
140
+ hasEarlier: options.hasEarlierRecords,
141
+ onVisibleRecord: options.onVisibleRecord,
142
+ };
143
+ const historyLayout = {
144
+ ...options,
145
+ layoutTranscriptRecord: options.layoutTranscriptRecord ??
146
+ ((entry, width) => (0, transcript_layout_1.layoutTranscriptEntry)(entry, { width, theme, history: true })),
147
+ };
148
+ if (frame.height > 2) {
149
+ (0, frame_1.writeFrameText)(frame, 0, 0, ellipsizeCells('Transcript', frame.width), theme.brand);
150
+ renderTranscript(frame, state, 1, frame.height - 2, historyLayout, options.transcriptPager, pageOptions);
151
+ }
152
+ else {
153
+ renderTranscript(frame, state, 0, frame.height, historyLayout, options.transcriptPager, pageOptions);
154
+ }
155
+ if (frame.height > 2) {
156
+ let navigation = 'PgUp/PgDn scroll';
157
+ if (options.loadingEarlierRecords)
158
+ navigation = 'Loading earlier messages…';
159
+ else if (options.transcriptPager.nearStart)
160
+ navigation = 'PgUp load earlier';
161
+ (0, frame_1.writeFrameText)(frame, frame.height - 1, 0, ellipsizeCells(`${navigation} · Ctrl+T close`, frame.width), theme.statusText);
162
+ }
163
+ (0, frame_1.setFrameCursor)(frame, 0, 0, false);
125
164
  return frame;
126
165
  }
127
- /** Render (live) transcript entries into [startRow, startRow + maxRows). */
128
- function renderLiveTranscript(frame, state, startRow, maxRows, options) {
166
+ function renderTranscript(frame, state, startRow, maxRows, options, pager, pageOptions) {
129
167
  const width = resolveTranscriptWidth(frame.width, options.transcriptWidth);
130
- const rows = state.transcript
131
- .slice(state.queuedTranscriptCount)
132
- .flatMap(entry => layoutRecord(entry, width, options));
133
- const visible = rows.slice(Math.max(0, rows.length - maxRows));
134
- visible.forEach((row, index) => {
135
- (0, transcript_layout_1.writeStyledRowToFrame)(frame, startRow + index, row);
136
- });
168
+ const rows = pager.rows(state.transcript, width, maxRows, (entry, columns) => layoutRecord(entry, columns, options), pageOptions);
169
+ rows.forEach((row, index) => (0, transcript_layout_1.writeStyledRowToFrame)(frame, startRow + index, row));
137
170
  }
138
- function renderTranscript(frame, state, startRow, maxRows, options) {
139
- const width = resolveTranscriptWidth(frame.width, options.transcriptWidth);
140
- const records = [...(0, state_1.staticTuiTranscriptRecords)(state), ...(0, state_1.liveTuiTranscriptRecords)(state)];
141
- const rows = records.flatMap(entry => layoutRecord(entry, width, options));
142
- const visible = rows.slice(Math.max(0, rows.length - maxRows));
143
- visible.forEach((row, index) => {
144
- (0, transcript_layout_1.writeStyledRowToFrame)(frame, startRow + index, row);
145
- });
171
+ function layoutExplorationGroup({ reads, searches, listings }, width, theme) {
172
+ const calls = reads + searches + listings;
173
+ const label = `• Explored ${calls} calls`;
174
+ const labelWidth = (0, string_width_1.default)(label);
175
+ const labelStyle = theme.toolName ?? theme.assistantText;
176
+ if (width < labelWidth) {
177
+ const compact = `Explored ${calls}`;
178
+ const text = ellipsizeCells((0, string_width_1.default)(compact) <= width ? compact : `${calls} calls`, width);
179
+ return [[{ text, style: labelStyle }]];
180
+ }
181
+ const details = [
182
+ reads && `${reads} ${reads === 1 ? 'read' : 'reads'}`,
183
+ searches && `${searches} ${searches === 1 ? 'search' : 'searches'}`,
184
+ listings && `${listings} ${listings === 1 ? 'listing' : 'listings'}`,
185
+ ].filter(Boolean);
186
+ return [
187
+ [
188
+ { text: label, style: labelStyle },
189
+ {
190
+ text: ellipsizeCells(` · ${details.join(' · ')}`, width - labelWidth),
191
+ style: theme.toolMeta ?? theme.muted,
192
+ },
193
+ ],
194
+ ];
146
195
  }
147
196
  /** Render the activity timeline (subtasks + running tools) just above status. */
148
- function renderTimeline(frame, state, top, maxRows, theme) {
149
- const items = [];
150
- for (const t of activeSubtaskTimelineEntries(state)) {
151
- const mark = t.state === 'running' ? '▶' : '◦';
152
- const label = t.summary ?? t.objective ?? t.role;
153
- const sequence = state.subtaskTimeline.findIndex(entry => entry.taskId === t.taskId) + 1;
154
- items.push(`${mark} #${sequence} ${t.role} · ${truncateCells(label, 34)} · ${t.state}`);
155
- }
156
- for (const e of activeToolStarts(state)) {
157
- items.push(`⚙ #${e.sequence} ${e.command ?? e.name} running`);
158
- }
159
- const visible = items.slice(-maxRows);
160
- visible.forEach((line, index) => {
161
- (0, frame_1.writeFrameText)(frame, top + index, 0, truncateCells(line, frame.width), theme?.activityRunning);
162
- });
163
- }
164
- function renderStatus(frame, state, row, options) {
197
+ function renderStatus(frame, state, row, options, readingHistory, queuePreviewVisible) {
165
198
  if (row < 0)
166
199
  return;
167
200
  const chrome = (0, chrome_view_model_1.createTuiChromeViewModel)(state, options.statusLine);
168
201
  const mode = chrome.segments.find(segment => segment.id === 'mode');
169
202
  const secondary = chrome.segments
170
- .filter(segment => segment.id !== 'mode')
203
+ .filter(segment => segment.id !== 'mode' && (!queuePreviewVisible || segment.id !== 'queue'))
171
204
  .sort((a, b) => b.priority - a.priority);
172
205
  const theme = options.theme ?? style_1.DEFAULT_THEME;
173
- const separator = ' │ ';
206
+ const separator = ' · ';
174
207
  const separatorWidth = (0, string_width_1.default)(separator);
208
+ const width = frame.width;
175
209
  let column = 0;
176
210
  const write = (text, style) => {
177
211
  (0, frame_1.writeFrameText)(frame, row, column, text, style);
178
212
  column += (0, string_width_1.default)(text);
179
213
  };
180
214
  if (mode)
181
- write(ellipsizeCells(mode.label, frame.width), segmentStyle(mode, theme, state));
215
+ write(ellipsizeCells(mode.label, width), segmentStyle(mode, theme, state));
216
+ if (readingHistory) {
217
+ const hint = width >= 30 ? 'History · PgDn' : 'History';
218
+ if (column + separatorWidth + (0, string_width_1.default)(hint) <= width) {
219
+ if (column > 0)
220
+ write(separator, theme.statusText);
221
+ write(hint, theme.statusText);
222
+ }
223
+ }
182
224
  // Claim space for compact labels before letting any single long label expand.
183
225
  // A model name or Goal objective must not crowd out the current phase or queue.
184
- let remaining = frame.width - column;
226
+ let remaining = width - column;
185
227
  const visible = secondary.flatMap(segment => {
186
228
  const label = singleLine(segment.label);
187
229
  const compact = segment.compactLabel
@@ -208,71 +250,101 @@ function renderStatus(frame, state, row, options) {
208
250
  write(separator, theme.statusText);
209
251
  write(text, segmentStyle(segment, theme, state));
210
252
  }
211
- if (!state.processing && options.mascot !== false && frame.width >= 48) {
212
- const badge = `${separator}${(0, pixel_mascot_1.pixelHunterBadge)(chrome.pose, options.animationFrame)}`;
213
- if (column + (0, string_width_1.default)(badge) <= frame.width)
214
- write(badge, theme.mascot);
215
- }
216
253
  }
217
254
  function renderActivity(frame, state, row, options) {
218
255
  const theme = options.theme ?? style_1.DEFAULT_THEME;
219
- if (state.overlay?.type === 'permission') {
220
- (0, frame_1.writeFrameText)(frame, row, 0, '◇ Waiting for approval', theme.warning);
221
- return;
222
- }
223
256
  const spinner = ACTIVITY_SPINNER[(options.animationFrame ?? 0) % ACTIVITY_SPINNER.length];
224
- const phase = state.statusState.activeTools > 0
225
- ? 'Running tools'
226
- : state.statusState.activeSubtasks > 0
257
+ const tools = activeToolStarts(state);
258
+ const currentTool = tools.at(-1);
259
+ const currentAgent = state.subtaskTimeline.find(entry => entry.state === 'running');
260
+ const phase = tools.length > 0
261
+ ? `Running tools${tools.length > 1 ? ` ${tools.length}` : ''}`
262
+ : currentAgent
227
263
  ? 'Running agents'
228
264
  : 'Working';
229
- const label = `${spinner} ${phase} · Esc to interrupt`;
230
- (0, frame_1.writeFrameText)(frame, row, 0, truncateCells(label, frame.width), theme.activityRunning);
265
+ const heading = `${spinner} ${phase}`;
266
+ const elapsed = options.activityElapsedSeconds;
267
+ const full = `${heading} · ${elapsed === undefined ? '' : `${formatElapsed(elapsed)} · `}Esc to interrupt`;
268
+ const shortcut = ' · Esc';
269
+ if ((0, string_width_1.default)(full) > frame.width) {
270
+ const compact = frame.width > (0, string_width_1.default)(shortcut)
271
+ ? `${ellipsizeCells(heading, frame.width - (0, string_width_1.default)(shortcut))}${shortcut}`
272
+ : truncateCells(heading, frame.width);
273
+ (0, frame_1.writeFrameText)(frame, row, 0, compact, theme.activityRunning);
274
+ return;
275
+ }
276
+ (0, frame_1.writeFrameText)(frame, row, 0, full, theme.activityRunning);
277
+ const label = currentTool
278
+ ? [currentTool.name, currentTool.command].filter(Boolean).join(' · ')
279
+ : (currentAgent?.summary ?? currentAgent?.objective ?? currentAgent?.role);
280
+ const column = (0, string_width_1.default)(full);
281
+ const detailWidth = frame.width - column - 3;
282
+ if (label && detailWidth >= 8) {
283
+ (0, frame_1.writeFrameText)(frame, row, column, ` · ${ellipsizeCells(singleLine(label), detailWidth)}`, theme.statusText);
284
+ }
285
+ }
286
+ function formatElapsed(seconds) {
287
+ if (seconds < 60)
288
+ return `${seconds}s`;
289
+ if (seconds < 3600)
290
+ return `${Math.floor(seconds / 60)}m ${seconds % 60}s`;
291
+ return `${Math.floor(seconds / 3600)}h ${Math.floor((seconds % 3600) / 60)}m`;
231
292
  }
232
293
  function singleLine(value) {
233
294
  return (0, style_1.sanitizeTerminalText)(value).replace(/\s+/gu, ' ').trim();
234
295
  }
235
- /**
236
- * Render a bounded prompt viewport. The underlying prompt value is never
237
- * truncated; only the lines around the cursor are painted when the terminal is
238
- * too short to show the full multi-line value.
239
- */
240
- function renderPrompt(frame, state, top, width, visibleLineCount, theme) {
241
- const value = state.prompt.value;
242
- const lines = value.split('\n');
243
- const innerWidth = Math.max(0, width - 2);
244
- const { line: cursorLine, col: cursorCol } = lineColOfCursor(value, state.prompt.cursor);
245
- const viewportStart = Math.max(0, Math.min(cursorLine - Math.floor((visibleLineCount - 1) / 2), lines.length - visibleLineCount));
246
- const viewportLines = lines.slice(viewportStart, viewportStart + visibleLineCount);
247
- const resolvedTheme = theme ?? style_1.DEFAULT_THEME;
248
- const borderStyle = promptModeStyle(state, resolvedTheme);
249
- // The frame reserves four cells for the border and prompt marker, and one
250
- // trailing blank cell so the cursor can sit after the last painted grapheme.
251
- const bodyWidth = Math.max(0, innerWidth - 4);
252
- let cursorColumn = 4;
253
- (0, frame_1.writeFrameText)(frame, top, 0, `┌${'─'.repeat(innerWidth)}┐`, borderStyle);
254
- for (let i = 0; i < viewportLines.length; i++) {
255
- const absoluteLine = viewportStart + i;
256
- let text;
257
- if (absoluteLine === cursorLine) {
258
- const viewport = promptLineViewport(viewportLines[i], cursorCol, bodyWidth);
259
- text = viewport.text;
260
- cursorColumn += viewport.cursorCells;
261
- }
262
- else {
263
- text = ellipsizeCells(viewportLines[i], bodyWidth);
264
- }
265
- const contentRow = top + 1 + i;
266
- (0, frame_1.writeFrameText)(frame, contentRow, 0, '│', borderStyle);
267
- (0, frame_1.writeFrameText)(frame, contentRow, 1, ' ');
268
- if (absoluteLine === 0)
269
- (0, frame_1.writeFrameText)(frame, contentRow, 2, '›', borderStyle);
270
- (0, frame_1.writeFrameText)(frame, contentRow, 3, ' ');
271
- (0, frame_1.writeFrameText)(frame, contentRow, 4, text, resolvedTheme.userText);
272
- (0, frame_1.writeFrameText)(frame, contentRow, width - 1, '│', borderStyle);
273
- }
274
- (0, frame_1.writeFrameText)(frame, top + 1 + viewportLines.length, 0, `└${'─'.repeat(innerWidth)}┘`, borderStyle);
275
- (0, frame_1.setFrameCursor)(frame, top + 1 + cursorLine - viewportStart, cursorColumn, true);
296
+ function layoutPrompt(value, cursor, width) {
297
+ const textStart = width >= 5 ? (0, string_width_1.default)(PROMPT_PREFIX) : 0;
298
+ // Leave a cell for the caret at the end of a full line when the viewport allows it.
299
+ const reservedColumns = textStart + Number(textStart > 0);
300
+ const lines = (0, layout_1.getPromptVisualLines)(value.replace(/\t/gu, ' '), width, reservedColumns);
301
+ const offset = (0, grapheme_1.floorGraphemeBoundary)(value, cursor);
302
+ let cursorRow = lines.length - 1;
303
+ while (cursorRow > 0 && lines[cursorRow].start > offset)
304
+ cursorRow -= 1;
305
+ const line = lines[cursorRow];
306
+ const cursorColumn = (0, string_width_1.default)(line.content.slice(0, offset - line.start));
307
+ return { lines, cursorRow, cursorColumn, textStart };
308
+ }
309
+ /** Move within the displayed draft before Up/Down hands off to input history. */
310
+ function moveTuiPromptVisualCursor(value, cursor, width, direction) {
311
+ const { lines, cursorRow, cursorColumn } = layoutPrompt(value, cursor, width);
312
+ const targetRow = cursorRow + direction;
313
+ const target = lines[targetRow];
314
+ if (!target)
315
+ return undefined;
316
+ const hasSoftBoundary = lines[targetRow + 1]?.start === target.end;
317
+ let column = 0;
318
+ let offset = target.start;
319
+ for (const part of (0, grapheme_1.segmentGraphemes)(target.content)) {
320
+ const end = part.index + part.segment.length;
321
+ const nextColumn = column + (0, string_width_1.default)(part.segment);
322
+ // One offset at a soft wrap belongs to the next row. Walking up onto
323
+ // that offset would leave the cursor in the current row.
324
+ if (nextColumn > cursorColumn || (hasSoftBoundary && end === target.content.length))
325
+ break;
326
+ column = nextColumn;
327
+ offset = target.start + end;
328
+ }
329
+ return (0, grapheme_1.floorGraphemeBoundary)(value, offset);
330
+ }
331
+ /** Draw a caret-bearing window of the visual rows without changing the draft. */
332
+ function renderPrompt(frame, state, prompt, top, visibleCount, theme) {
333
+ const { lines, cursorRow, cursorColumn, textStart } = prompt;
334
+ const first = Math.max(0, Math.min(cursorRow - Math.floor((visibleCount - 1) / 2), lines.length - visibleCount));
335
+ const background = theme.userBackground?.background;
336
+ const markerStyle = { ...promptModeStyle(state, theme), background };
337
+ const inputStyle = { ...theme.userText, background };
338
+ const fillStyle = { background };
339
+ lines.slice(first, first + visibleCount).forEach((line, index) => {
340
+ const row = top + index;
341
+ for (const cell of frame.rows[row])
342
+ cell.style = fillStyle;
343
+ if (index === 0 && textStart > 0)
344
+ (0, frame_1.writeFrameText)(frame, row, 0, PROMPT_PREFIX, markerStyle);
345
+ (0, frame_1.writeFrameText)(frame, row, textStart, truncateCells(line.content, frame.width - textStart), inputStyle);
346
+ });
347
+ (0, frame_1.setFrameCursor)(frame, top + cursorRow - first, textStart + cursorColumn, true);
276
348
  }
277
349
  function promptModeStyle(state, theme) {
278
350
  if (state.goal)
@@ -305,67 +377,9 @@ function segmentStyle(segment, theme, state) {
305
377
  return theme?.statusText;
306
378
  }
307
379
  }
308
- function promptLineViewport(value, cursor, width) {
309
- if (width <= 0)
310
- return { text: '', cursorCells: 0 };
311
- const graphemes = (0, grapheme_1.segmentGraphemes)(value);
312
- const rightIndex = graphemes.findIndex(part => part.index + part.segment.length > cursor);
313
- const boundary = rightIndex < 0 ? value.length : graphemes[rightIndex].index;
314
- const after = value.slice(boundary);
315
- const rightBudget = Math.min((0, string_width_1.default)(after), Math.ceil(width / 3));
316
- const beforeBudget = width - rightBudget;
317
- let left = value.slice(0, boundary);
318
- let cursorCells = (0, string_width_1.default)(left);
319
- if (cursorCells > beforeBudget) {
320
- cursorCells = 1;
321
- let start = rightIndex < 0 ? graphemes.length : rightIndex;
322
- while (start > 0) {
323
- const cells = (0, string_width_1.default)(graphemes[start - 1].segment);
324
- if (cursorCells + cells > beforeBudget)
325
- break;
326
- cursorCells += cells;
327
- start--;
328
- }
329
- left = `…${value.slice(graphemes[start]?.index ?? boundary, boundary)}`;
330
- }
331
- return {
332
- text: `${left}${ellipsizeCells(after, width - cursorCells)}`,
333
- cursorCells,
334
- };
335
- }
336
- function renderOverlay(frame, overlay, maxRows, transcriptRows, theme) {
380
+ function renderOverlay(frame, overlay, maxRows) {
337
381
  if (!overlay || maxRows <= 0)
338
382
  return;
339
- if (overlay.type === 'commands' || overlay.type === 'files') {
340
- renderComposerPicker(frame, overlay, transcriptRows, theme);
341
- return;
342
- }
343
- if (overlay.type === 'sessions') {
344
- const request = overlay.request;
345
- const visibleCount = Math.max(0, Math.min(maxRows - 1, request.maxVisibleItems ?? maxRows - 1, request.sessions.length));
346
- const start = sessionPickerStartIndex(overlay.selectedIndex, visibleCount, request.sessions.length);
347
- const visibleSessions = request.sessions.slice(start, start + visibleCount);
348
- const rows = [
349
- `Sessions: ${request.title} (${overlay.selectedIndex + 1}/${request.sessions.length})`,
350
- ...visibleSessions.map((session, offset) => {
351
- const index = start + offset;
352
- const marker = index === overlay.selectedIndex ? '›' : ' ';
353
- const label = session.name || session.taskSummary || session.id.slice(0, 8);
354
- const size = (0, format_1.formatBytes)(session.historySizeBytes ?? 0);
355
- const messages = `${session.messageCount ?? 0} msgs`;
356
- const project = request.showProject ? ` ${session.projectPath}` : '';
357
- return `${marker} ${String(index + 1).padStart(2, ' ')} ${session.id.slice(0, 8)} ${label} ${messages} ${size} ${session.model}${project}`;
358
- }),
359
- ].map(row => truncateCells(row, frame.width));
360
- rows.slice(0, maxRows).forEach((line, index) => {
361
- (0, frame_1.writeFrameText)(frame, index, 0, line);
362
- });
363
- // Clear any remaining transcript rows below overlay content
364
- for (let i = rows.length; i < maxRows; i++) {
365
- (0, frame_1.writeFrameText)(frame, i, 0, '');
366
- }
367
- return;
368
- }
369
383
  if (overlay.type === 'model') {
370
384
  const request = overlay.request;
371
385
  const pickerState = (0, ui_view_model_1.createModelPickerState)({ ...request, visibleStart: 0 });
@@ -422,43 +436,157 @@ function renderOverlay(frame, overlay, maxRows, transcriptRows, theme) {
422
436
  }
423
437
  return;
424
438
  }
425
- if (overlay.type === 'permission') {
426
- const picker = (0, ui_view_model_1.createPermissionDecisionPickerState)(overlay.request);
427
- const rows = [
428
- `Tool Permission: ${overlay.request.name}`,
429
- ...picker.visibleItems.map((item, index) => {
430
- const marker = index === overlay.selectedIndex ? '›' : ' ';
431
- return `${marker} ${item.label}${item.description ? ` — ${item.description}` : ''}`;
432
- }),
433
- 'Enter select y allow once n/Esc deny',
434
- ].map(row => truncateCells(row, frame.width));
435
- rows.slice(0, maxRows).forEach((line, index) => {
436
- (0, frame_1.writeFrameText)(frame, index, 0, line);
437
- });
438
- // Clear any remaining transcript rows below overlay content
439
- for (let i = rows.length; i < maxRows; i++) {
440
- (0, frame_1.writeFrameText)(frame, i, 0, '');
441
- }
442
- return;
443
- }
444
439
  if (overlay.type === 'shortcuts') {
445
440
  const rows = [
446
441
  'Orion Pixel · Shortcuts',
447
- '/ commands @ files ? help Ctrl+O tools',
442
+ '/ commands @ files ? help Ctrl+O copy reply',
448
443
  'Enter send/steer Tab complete/queue Shift+Tab cycle mode',
449
- 'Esc cancel/stop Ctrl+O tools Ctrl+R history',
450
- 'Ctrl+R history Ctrl+E editor Ctrl+L redraw Ctrl+D exit',
451
- 'Ctrl+C interrupt / twice exits /goal clear leaves Goal mode',
444
+ 'Ctrl+T transcript PgUp/PgDn scroll',
445
+ 'Esc stop Ctrl+R history Ctrl+E editor Ctrl+L redraw',
446
+ '/resume find sessions /queue manage Alt+↑ edit last queued',
447
+ 'Ctrl+C interrupt / twice exits Ctrl+D exit',
452
448
  ].map(row => truncateCells(row, frame.width));
453
449
  rows.slice(0, maxRows).forEach((line, index) => {
454
450
  (0, frame_1.writeFrameText)(frame, index, 0, line);
455
451
  });
456
452
  }
457
453
  }
458
- function renderComposerPicker(frame, overlay, endRow, theme) {
459
- const availableRows = Math.min(endRow, MAX_COMPOSER_PICKER_ROWS);
460
- if (availableRows <= 0)
454
+ function renderSessionPicker(frame, state, { query, matches, preview, request, selectedIndex }, theme) {
455
+ const headingRows = Number(frame.height >= 3);
456
+ const hintRows = Number(frame.height >= 5);
457
+ const bodyStart = headingRows + 1;
458
+ const bodyRows = frame.height - bodyStart - hintRows;
459
+ const active = matches[selectedIndex];
460
+ if (headingRows) {
461
+ const position = active ? selectedIndex + 1 : 0;
462
+ writeModalLine(frame, 0, `Sessions: ${request.title} (${position}/${matches.length})`, theme.brand);
463
+ }
464
+ if (hintRows) {
465
+ writeModalLine(frame, frame.height - 1, '↑↓ select · Enter resume · Esc close', theme.statusText);
466
+ }
467
+ const visualQuery = layoutPrompt(query.value, query.cursor, frame.width);
468
+ renderPrompt(frame, state, visualQuery, headingRows, 1, theme);
469
+ if (!query.value && frame.width > visualQuery.textStart) {
470
+ (0, frame_1.writeFrameText)(frame, headingRows, visualQuery.textStart, ellipsizeCells('Search sessions', frame.width - visualQuery.textStart), { ...theme.statusText, background: theme.userBackground?.background });
471
+ }
472
+ if (!active) {
473
+ if (bodyRows)
474
+ writeModalLine(frame, bodyStart, 'No matching sessions.', theme.statusText);
461
475
  return;
476
+ }
477
+ const previewRows = bodyRows >= 3 ? Math.min(4, Math.floor(bodyRows / 2)) : 0;
478
+ const count = Math.min(matches.length, request.maxVisibleItems ?? 10, bodyRows - previewRows);
479
+ const start = pickerStartIndex(selectedIndex, count, matches.length);
480
+ matches.slice(start, start + count).forEach((session, offset) => {
481
+ const index = start + offset;
482
+ const selected = index === selectedIndex;
483
+ const marker = selected ? '›' : ' ';
484
+ const label = session.name || session.taskSummary || session.id.slice(0, 8);
485
+ const project = request.showProject ? ` ${session.projectPath}` : '';
486
+ const metadata = `${session.messageCount ?? 0} msgs ${(0, format_1.formatBytes)(session.historySizeBytes ?? 0)} ${session.model}${project}`;
487
+ const text = frame.width < 36
488
+ ? `${marker} ${label}`
489
+ : `${marker} ${String(index + 1).padStart(2, ' ')} ${session.id.slice(0, 8)} ${label} ${metadata}`;
490
+ writeModalLine(frame, bodyStart + offset, text, selected ? theme.brand : theme.statusText);
491
+ });
492
+ if (!previewRows)
493
+ return;
494
+ const previewStart = bodyStart + count;
495
+ const heading = preview?.length
496
+ ? 'Preview'
497
+ : preview === undefined
498
+ ? 'Preview · loading…'
499
+ : 'Preview · no recent messages';
500
+ writeModalLine(frame, previewStart, heading, theme.brand);
501
+ if (preview?.length) {
502
+ preview.slice(Math.max(0, preview.length - previewRows + 1)).forEach((message, index) => {
503
+ const role = message.role === 'user' ? 'You' : 'Orion';
504
+ writeModalLine(frame, previewStart + index + 1, `${role} · ${message.text}`, theme.statusText);
505
+ });
506
+ }
507
+ else if (active.taskSummary && active.taskSummary !== active.name && previewRows >= 2) {
508
+ writeModalLine(frame, previewStart + 1, active.taskSummary, theme.statusText);
509
+ }
510
+ }
511
+ function renderFollowupPreview(frame, state, top, rows, theme) {
512
+ const { items, limit } = state.followupQueue;
513
+ items.slice(0, rows).forEach((item, index) => {
514
+ const label = index === 0 ? `Next turn ${items.length}/${limit} · ` : ' 2. ';
515
+ writeModalLine(frame, top + index, label + item.text, theme.queueBadge ?? theme.statusText);
516
+ });
517
+ }
518
+ function renderFollowupQueue(frame, state, { editor, selectedIndex, notice }, theme) {
519
+ const { items, limit } = state.followupQueue;
520
+ if (editor) {
521
+ const headingRows = Number(frame.height >= 2);
522
+ const hintRows = Number(frame.height >= 3);
523
+ const { value, cursor } = editor.draft;
524
+ const prompt = layoutPrompt(value, cursor, frame.width);
525
+ const inputRows = Math.min(prompt.lines.length, MAX_PROMPT_ROWS, frame.height - headingRows - hintRows);
526
+ if (headingRows)
527
+ writeModalLine(frame, 0, 'Edit queued message', theme.brand);
528
+ renderPrompt(frame, state, prompt, headingRows, inputRows, theme);
529
+ if (hintRows) {
530
+ const current = items.find(item => item.id === editor.itemId);
531
+ const status = notice ??
532
+ (current?.revision !== editor.revision ? 'Message already sent or changed.' : undefined);
533
+ const hint = status ?? 'Enter save · Ctrl+J newline · Esc back';
534
+ writeModalLine(frame, headingRows + inputRows, hint, status ? theme.warning : theme.statusText);
535
+ }
536
+ return;
537
+ }
538
+ const headingRows = Number(frame.height >= 2);
539
+ const hintRows = Number(frame.height >= 4);
540
+ const count = Math.min(8, items.length, frame.height - headingRows - hintRows);
541
+ const start = pickerStartIndex(selectedIndex, count, items.length);
542
+ if (headingRows)
543
+ writeModalLine(frame, 0, `Queue · Next turn (${items.length}/${limit})`, theme.brand);
544
+ items.slice(start, start + count).forEach((item, offset) => {
545
+ const index = start + offset;
546
+ const selected = index === selectedIndex;
547
+ const marker = selected ? '›' : ' ';
548
+ writeModalLine(frame, headingRows + offset, `${marker} ${index + 1}. ${item.text}`, selected ? theme.brand : theme.statusText);
549
+ });
550
+ if (!items.length && headingRows < frame.height) {
551
+ writeModalLine(frame, headingRows, 'No messages queued.', theme.statusText);
552
+ }
553
+ if (hintRows) {
554
+ const hint = notice || 'Enter edit · [ ] move · Del remove · Esc close';
555
+ writeModalLine(frame, frame.height - 1, hint, notice ? theme.warning : theme.statusText);
556
+ }
557
+ (0, frame_1.setFrameCursor)(frame, 0, 0, false);
558
+ }
559
+ function writeModalLine(frame, row, text, style) {
560
+ const line = (0, style_1.sanitizeTerminalText)(text)
561
+ .replace(/[\r\n\t]+/gu, ' ')
562
+ .trimEnd();
563
+ (0, frame_1.writeFrameText)(frame, row, 0, ellipsizeCells(line, frame.width), style);
564
+ }
565
+ function renderPermissionPicker(frame, overlay, theme) {
566
+ const picker = (0, ui_view_model_1.createPermissionDecisionPickerState)(overlay.request);
567
+ const headingRows = Number(frame.height > 1);
568
+ const hintRows = Number(frame.height >= picker.visibleItems.length + 2);
569
+ const visibleCount = Math.min(picker.visibleItems.length, frame.height - headingRows - hintRows);
570
+ const start = pickerStartIndex(overlay.selectedIndex, visibleCount, picker.visibleItems.length);
571
+ if (headingRows) {
572
+ const heading = `Tool Permission: ${singleLine(overlay.request.name)}`;
573
+ (0, frame_1.writeFrameText)(frame, 0, 0, ellipsizeCells(heading, frame.width), theme.modePermission);
574
+ }
575
+ picker.visibleItems.slice(start, start + visibleCount).forEach((item, index) => {
576
+ const selected = start + index === overlay.selectedIndex;
577
+ const marker = selected ? '›' : ' ';
578
+ const label = `${marker} ${item.label}${item.description ? ` — ${item.description}` : ''}`;
579
+ const row = headingRows + index;
580
+ const style = selected ? theme.pickerSelected : undefined;
581
+ if (selected)
582
+ (0, frame_1.writeFrameText)(frame, row, 0, ' '.repeat(frame.width), style);
583
+ (0, frame_1.writeFrameText)(frame, row, 0, ellipsizeCells(label, frame.width), style);
584
+ });
585
+ if (hintRows) {
586
+ (0, frame_1.writeFrameText)(frame, headingRows + visibleCount, 0, ellipsizeCells('Enter select · y allow once · Esc deny', frame.width), theme.statusText);
587
+ }
588
+ }
589
+ function renderComposerPicker(frame, overlay, top, availableRows, theme) {
462
590
  const rows = [];
463
591
  if (overlay.type === 'files' && availableRows > 1) {
464
592
  const query = singleLine(overlay.query);
@@ -487,10 +615,10 @@ function renderComposerPicker(frame, overlay, endRow, theme) {
487
615
  });
488
616
  }
489
617
  rows.forEach(({ text, selected }, index) => {
490
- const row = endRow - rows.length + index;
618
+ const row = top + index;
491
619
  const style = selected ? theme.pickerSelected : undefined;
492
- // Overwrite the entire row, including continuation cells from wide characters.
493
- (0, frame_1.writeFrameText)(frame, row, 0, ' '.repeat(frame.width), style);
620
+ if (selected)
621
+ (0, frame_1.writeFrameText)(frame, row, 0, ' '.repeat(frame.width), style);
494
622
  (0, frame_1.writeFrameText)(frame, row, 0, ellipsizeCells(text, frame.width), style);
495
623
  });
496
624
  }
@@ -542,19 +670,4 @@ function ellipsizeCells(value, width) {
542
670
  return '';
543
671
  return (0, string_width_1.default)(value) <= width ? value : `${truncateCells(value, width - 1)}…`;
544
672
  }
545
- /** Map an absolute character cursor to {line, col} within a multi-line value. */
546
- function lineColOfCursor(value, cursor) {
547
- const lines = value.split('\n');
548
- const safeCursor = Math.max(0, Math.min(cursor, value.length));
549
- let offset = 0;
550
- for (let i = 0; i < lines.length; i++) {
551
- const lineLen = lines[i].length;
552
- if (safeCursor <= offset + lineLen) {
553
- return { line: i, col: safeCursor - offset };
554
- }
555
- offset += lineLen + 1; // +1 for the newline separator
556
- }
557
- const last = lines.length - 1;
558
- return { line: last, col: lines[last].length };
559
- }
560
673
  //# sourceMappingURL=layout.js.map