@aednzxy/smith-tui 0.0.0-stage → 0.1.0

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 (80) hide show
  1. package/README.md +160 -2
  2. package/dist/app/commands.js +58 -0
  3. package/dist/app/commands.js.map +1 -0
  4. package/dist/app/controller.js +5129 -0
  5. package/dist/app/controller.js.map +1 -0
  6. package/dist/app/state.js +266 -0
  7. package/dist/app/state.js.map +1 -0
  8. package/dist/cli.js +154 -0
  9. package/dist/cli.js.map +1 -0
  10. package/dist/client/config.js +110 -0
  11. package/dist/client/config.js.map +1 -0
  12. package/dist/client/http.js +796 -0
  13. package/dist/client/http.js.map +1 -0
  14. package/dist/client/reducer.js +623 -0
  15. package/dist/client/reducer.js.map +1 -0
  16. package/dist/client/session-start.js +39 -0
  17. package/dist/client/session-start.js.map +1 -0
  18. package/dist/client/shell-ws.js +126 -0
  19. package/dist/client/shell-ws.js.map +1 -0
  20. package/dist/client/types.js +22 -0
  21. package/dist/client/types.js.map +1 -0
  22. package/dist/client/ws.js +233 -0
  23. package/dist/client/ws.js.map +1 -0
  24. package/dist/engine/color.js +142 -0
  25. package/dist/engine/color.js.map +1 -0
  26. package/dist/engine/editor.js +350 -0
  27. package/dist/engine/editor.js.map +1 -0
  28. package/dist/engine/input.js +351 -0
  29. package/dist/engine/input.js.map +1 -0
  30. package/dist/engine/screen.js +513 -0
  31. package/dist/engine/screen.js.map +1 -0
  32. package/dist/engine/terminal.js +163 -0
  33. package/dist/engine/terminal.js.map +1 -0
  34. package/dist/format/diff.js +85 -0
  35. package/dist/format/diff.js.map +1 -0
  36. package/dist/format/markdown.js +438 -0
  37. package/dist/format/markdown.js.map +1 -0
  38. package/dist/format/questions.js +78 -0
  39. package/dist/format/questions.js.map +1 -0
  40. package/dist/format/sessions.js +310 -0
  41. package/dist/format/sessions.js.map +1 -0
  42. package/dist/format/time.js +217 -0
  43. package/dist/format/time.js.map +1 -0
  44. package/dist/format/tools.js +169 -0
  45. package/dist/format/tools.js.map +1 -0
  46. package/dist/format/vt.js +233 -0
  47. package/dist/format/vt.js.map +1 -0
  48. package/dist/index.js +24 -0
  49. package/dist/index.js.map +1 -0
  50. package/dist/theme/palettes.js +1651 -0
  51. package/dist/theme/palettes.js.map +1 -0
  52. package/dist/views/activity-view.js +212 -0
  53. package/dist/views/activity-view.js.map +1 -0
  54. package/dist/views/auth-view.js +85 -0
  55. package/dist/views/auth-view.js.map +1 -0
  56. package/dist/views/boards-view.js +163 -0
  57. package/dist/views/boards-view.js.map +1 -0
  58. package/dist/views/chat-view.js +626 -0
  59. package/dist/views/chat-view.js.map +1 -0
  60. package/dist/views/compute-view.js +281 -0
  61. package/dist/views/compute-view.js.map +1 -0
  62. package/dist/views/files-skills-view.js +209 -0
  63. package/dist/views/files-skills-view.js.map +1 -0
  64. package/dist/views/fleet-view.js +282 -0
  65. package/dist/views/fleet-view.js.map +1 -0
  66. package/dist/views/inspector-view.js +612 -0
  67. package/dist/views/inspector-view.js.map +1 -0
  68. package/dist/views/memory-view.js +316 -0
  69. package/dist/views/memory-view.js.map +1 -0
  70. package/dist/views/modals-view.js +709 -0
  71. package/dist/views/modals-view.js.map +1 -0
  72. package/dist/views/notes-view.js +133 -0
  73. package/dist/views/notes-view.js.map +1 -0
  74. package/dist/views/select-agent-view.js +153 -0
  75. package/dist/views/select-agent-view.js.map +1 -0
  76. package/dist/views/settings-view.js +538 -0
  77. package/dist/views/settings-view.js.map +1 -0
  78. package/dist/views/shell-layout.js +802 -0
  79. package/dist/views/shell-layout.js.map +1 -0
  80. package/package.json +46 -4
@@ -0,0 +1,626 @@
1
+ // Calm single-pane Chats workspace view:
2
+ // - Rich Streaming Transcript (Markdown, Syntax highlighting, Reasoning, Per-tool renderers, Diffs, Queued actions, Paging)
3
+ // - Interactive Parked Question (`ask_user`) Decision Card (Single, Multi, Groups, Note, Dismiss)
4
+ // - Sleek Prompt-Rule Composer + Slash Command Autocomplete Popup
5
+ import { filterSlashCommands } from '../app/commands.js';
6
+ import { stringWidth, wrapParagraph } from '../engine/screen.js';
7
+ import { renderMarkdown } from '../format/markdown.js';
8
+ import { parseQuestionChoices } from '../format/questions.js';
9
+ import { mergeConversations } from '../format/sessions.js';
10
+ import { formatClock, formatDurationMs, resolveTimeZone } from '../format/time.js';
11
+ import { renderToolCall } from '../format/tools.js';
12
+ export function renderChatMainPane(buf, rect, state, slice, theme, cb) {
13
+ buf.fill(rect, { fg: theme.paper, bg: theme.field });
14
+ buf.pushClip(rect);
15
+ const tz = resolveTimeZone(state.account?.user.timezone);
16
+ const merged = mergeConversations(slice.wsSessions, slice.httpSessions, slice.readState);
17
+ const activeConv = !slice.draftMode && slice.selectedSessionId
18
+ ? merged.find((c) => c.sessionId === slice.selectedSessionId) ?? null
19
+ : null;
20
+ // Full-width terminal canvas (2ch subtle side margins, like Claude Code / OpenCode)
21
+ const colW = Math.max(24, rect.w - 4);
22
+ const colX = rect.x + 2;
23
+ // ── 1. Calculate Composer + Decision Card heights from bottom up ──
24
+ const composerInnerW = Math.max(12, colW - 3); // 2ch prompt prefix ("› ") + 1ch breathing room
25
+ const composerLayout = state.composer.layout(composerInnerW);
26
+ const composerInnerH = Math.min(6, Math.max(1, composerLayout.lines.length));
27
+ // 1 rule line + N input lines + 1 bottom breathing line (or compact 0 when very short)
28
+ const bottomPad = rect.h >= 12 ? 1 : 0;
29
+ const composerH = 1 + composerInnerH + bottomPad;
30
+ const hasDecision = Boolean(activeConv?.awaitingQuestion);
31
+ const parsedChoices = hasDecision ? parseQuestionChoices(activeConv?.awaitingChoices) : { mode: 'none' };
32
+ const decisionH = hasDecision ? computeDecisionHeight(activeConv.awaitingQuestion, parsedChoices, state.decision.noteOpen, Math.floor(rect.h * 0.42)) : 0;
33
+ const composerY = rect.y + rect.h - composerH;
34
+ const decisionY = composerY - decisionH;
35
+ const topPad = rect.h >= 14 ? 1 : 0;
36
+ const transcriptRect = {
37
+ x: rect.x,
38
+ y: rect.y + topPad,
39
+ w: rect.w,
40
+ h: Math.max(2, decisionY - (rect.y + topPad)),
41
+ };
42
+ // ── 2. Render Transcript ──
43
+ renderTranscript(buf, transcriptRect, state, slice, activeConv, theme, tz, cb);
44
+ // ── 3. Render Decision Card if conversation is parked on ask_user ──
45
+ if (hasDecision && decisionH > 0 && activeConv) {
46
+ renderDecisionCard(buf, { x: colX, y: decisionY, w: colW, h: decisionH }, state, activeConv, parsedChoices, theme, cb);
47
+ }
48
+ // ── 4. Render Sleek Claude-Code / OpenCode Prompt Separator Composer ──
49
+ const composerFocused = state.focusedPane === 'composer' && state.chatMode === 'insert';
50
+ const composerRect = { x: colX, y: composerY, w: colW, h: composerH };
51
+ const ruleColor = slice.inFlight
52
+ ? theme.amber
53
+ : composerFocused
54
+ ? theme.accent
55
+ : theme.hairline;
56
+ buf.drawHLine(colX, composerY, colW, { fg: ruleColor, bg: theme.field });
57
+ // Subtle inline status tag on the rule (right-aligned)
58
+ const ruleStatus = slice.inFlight
59
+ ? slice.stopping
60
+ ? ' Stopping… '
61
+ : ' ^X stop · Enter queue '
62
+ : state.chatMode === 'browse'
63
+ ? ' BROWSE · c compose '
64
+ : slice.draftMode
65
+ ? ' New chat · / commands '
66
+ : '';
67
+ if (ruleStatus && colW > stringWidth(ruleStatus) + 8) {
68
+ const sx = colX + colW - stringWidth(ruleStatus);
69
+ buf.drawText(sx, composerY, ruleStatus, {
70
+ fg: slice.inFlight ? theme.amber : theme.muted,
71
+ bg: theme.field,
72
+ bold: slice.inFlight,
73
+ dim: !slice.inFlight,
74
+ });
75
+ if (slice.inFlight && !slice.stopping) {
76
+ state.hitRegions.push({ rect: { x: sx, y: composerY, w: 10, h: 1 }, action: cb.stopTurn });
77
+ }
78
+ }
79
+ // Prompt glyph + input lines
80
+ const promptY = composerY + 1;
81
+ const promptGlyph = composerFocused ? '› ' : '· ';
82
+ buf.drawText(colX, promptY, promptGlyph, {
83
+ fg: composerFocused ? theme.accent : theme.muted,
84
+ bg: theme.field,
85
+ bold: composerFocused,
86
+ });
87
+ const textX = colX + 2;
88
+ if (state.composer.value.length === 0) {
89
+ const placeholder = state.chatMode === 'browse'
90
+ ? 'Press c or Enter to compose…'
91
+ : slice.inFlight
92
+ ? 'Queue a follow-up, or /steer to interrupt…'
93
+ : 'Ask anything, or type / for commands…';
94
+ buf.drawTruncated(textX, promptY, placeholder, composerInnerW, {
95
+ fg: theme.muted,
96
+ bg: theme.field,
97
+ dim: true,
98
+ });
99
+ if (composerFocused && !state.modal && !state.gotoMenuOpen) {
100
+ buf.cursor = { x: textX, y: promptY, visible: true };
101
+ }
102
+ }
103
+ else {
104
+ const startLine = Math.max(0, composerLayout.cursorRow - composerInnerH + 1);
105
+ for (let i = 0; i < composerInnerH && startLine + i < composerLayout.lines.length; i++) {
106
+ if (i > 0) {
107
+ buf.drawText(colX, promptY + i, ' ', { fg: theme.muted, bg: theme.field });
108
+ }
109
+ buf.drawText(textX, promptY + i, composerLayout.lines[startLine + i], { fg: theme.paper, bg: theme.field }, composerInnerW);
110
+ }
111
+ if (composerFocused && !state.modal && !state.gotoMenuOpen) {
112
+ buf.cursor = {
113
+ x: textX + Math.min(composerInnerW - 1, composerLayout.cursorCol),
114
+ y: promptY + (composerLayout.cursorRow - startLine),
115
+ visible: true,
116
+ };
117
+ }
118
+ }
119
+ state.hitRegions.push({
120
+ rect: composerRect,
121
+ action: () => {
122
+ state.chatMode = 'insert';
123
+ cb.focusPane('composer');
124
+ },
125
+ });
126
+ // Slash palette floating right above composer rule
127
+ if (composerFocused && state.composer.value.startsWith('/') && !state.composer.value.includes(' ') && !state.modal && !state.gotoMenuOpen) {
128
+ const matches = filterSlashCommands(state.composer.value).slice(0, 8);
129
+ if (matches.length > 0 && composerY >= 5) {
130
+ const popH = matches.length + 2;
131
+ const popY = Math.max(rect.y + 1, composerY - popH);
132
+ const popW = Math.min(colW, 74);
133
+ const popRect = { x: colX, y: popY, w: popW, h: popH };
134
+ buf.drawBox(popRect, { fg: theme.accent, bg: theme.overlay ?? theme.panel }, { fillStyle: { fg: theme.paper, bg: theme.overlay ?? theme.panel }, title: 'Slash commands' });
135
+ const selIdx = Math.max(0, Math.min(matches.length - 1, state.slashSelectedIdx));
136
+ for (let i = 0; i < matches.length; i++) {
137
+ const cmd = matches[i];
138
+ const sel = i === selIdx;
139
+ const rowBg = sel ? theme.accentTint ?? theme.panel : theme.overlay ?? theme.panel;
140
+ buf.fill({ x: popRect.x + 1, y: popRect.y + 1 + i, w: popRect.w - 2, h: 1 }, { fg: theme.paper, bg: rowBg });
141
+ buf.drawText(popRect.x + 2, popRect.y + 1 + i, cmd.name, { fg: sel ? theme.accent : theme.paper, bg: rowBg, bold: sel }, 14);
142
+ buf.drawTruncated(popRect.x + 16, popRect.y + 1 + i, cmd.hint, popRect.w - 18, { fg: theme.muted, bg: rowBg });
143
+ }
144
+ }
145
+ }
146
+ buf.popClip();
147
+ }
148
+ function renderTranscript(buf, rect, state, slice, activeConv, theme, tz, cb) {
149
+ state.hitRegions.push({
150
+ rect,
151
+ action: () => {
152
+ state.chatMode = 'browse';
153
+ cb.focusPane('main');
154
+ },
155
+ onWheel: cb.scrollTranscript,
156
+ });
157
+ if (slice.migrationPending) {
158
+ buf.drawTruncated(rect.x + 2, rect.y + 1, '! Account migration in progress on this agent — retrying automatically.', rect.w - 4, {
159
+ fg: theme.amber,
160
+ bg: theme.field,
161
+ bold: true,
162
+ });
163
+ return;
164
+ }
165
+ if (!slice.selectedSessionId && !slice.draftMode) {
166
+ buf.drawTruncated(rect.x + 3, rect.y + 2, 'Press Ctrl+T (or Esc then s) to pick a conversation, or Ctrl+N to start a new chat.', rect.w - 6, {
167
+ fg: theme.muted,
168
+ bg: theme.field,
169
+ });
170
+ return;
171
+ }
172
+ const contentW = Math.max(24, rect.w - 4);
173
+ const marginX = rect.x + 2;
174
+ const lines = [];
175
+ if (slice.hasOlderHistory) {
176
+ lines.push({
177
+ segments: [
178
+ {
179
+ text: slice.loadingOlderHistory ? ' Loading older messages…' : ' ↑ Load older history (press L or click)',
180
+ style: { fg: theme.accent, bg: theme.field, bold: true },
181
+ },
182
+ ],
183
+ clickAction: cb.loadOlderHistory,
184
+ });
185
+ lines.push({ segments: [] });
186
+ }
187
+ if (slice.messages.length === 0 && !slice.streaming) {
188
+ lines.push({ segments: [] });
189
+ if (slice.draftMode) {
190
+ const agentColor = theme.agentColor(state.agents.find((a) => a.dirName === slice.dir)?.color ?? slice.dir);
191
+ const heading = slice.draftBoardCard
192
+ ? `New card chat: ${slice.draftBoardCard.cardTitle ?? slice.draftBoardCard.cardId}`
193
+ : slice.draftParent
194
+ ? `New child chat: ${slice.draftParent.title ?? slice.draftParent.sessionId}`
195
+ : `New chat with ${slice.agentName}`;
196
+ lines.push({ segments: [{ text: heading, style: { fg: agentColor, bg: theme.field, bold: true } }] });
197
+ lines.push({
198
+ segments: [
199
+ {
200
+ text: 'Type a message below to begin — nothing is saved until you send.',
201
+ style: { fg: theme.muted, bg: theme.field },
202
+ },
203
+ ],
204
+ });
205
+ lines.push({
206
+ segments: [
207
+ {
208
+ text: 'Ctrl+T conversations · Ctrl+O model · / commands · Esc g navigate',
209
+ style: { fg: theme.muted, bg: theme.field, dim: true },
210
+ },
211
+ ],
212
+ });
213
+ }
214
+ else {
215
+ lines.push({ segments: [{ text: 'No messages yet. Type below to start chatting.', style: { fg: theme.muted, bg: theme.field } }] });
216
+ }
217
+ }
218
+ for (const msg of slice.messages) {
219
+ const msgLines = getHistoryMessageLines(msg, contentW, state, slice, theme, tz, cb);
220
+ for (const ml of msgLines)
221
+ lines.push(ml);
222
+ }
223
+ // Live streaming turn
224
+ if (slice.streaming) {
225
+ const spin = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧'][state.tick % 8];
226
+ const secs = Math.max(0, Math.floor((Date.now() - Date.parse(slice.streaming.startedAt)) / 1000));
227
+ const agentColor = theme.agentColor(state.agents.find((a) => a.dirName === slice.dir)?.color ?? slice.dir);
228
+ lines.push({
229
+ segments: [
230
+ { text: `${spin} ${slice.agentName}`, style: { fg: agentColor, bg: theme.field, bold: true } },
231
+ { text: ` ${slice.streaming.phase === 'memory_flush' ? 'Saving memory…' : 'Streaming'} · ${formatDurationMs(secs * 1000)}`, style: { fg: theme.muted, bg: theme.field } },
232
+ ],
233
+ });
234
+ for (const part of slice.streaming.parts) {
235
+ if (part.type === 'reasoning') {
236
+ if (state.showReasoning && part.text.trim()) {
237
+ const preview = part.text.trim().split('\n').slice(-6);
238
+ lines.push({ segments: [{ text: ' ┄ Thinking', style: { fg: theme.muted, bg: theme.field, italic: true } }] });
239
+ for (const pl of preview) {
240
+ for (const wl of wrapParagraph(pl, contentW - 4)) {
241
+ lines.push({ segments: [{ text: ` │ ${wl}`, style: { fg: theme.muted, bg: theme.field, italic: true, dim: true } }] });
242
+ }
243
+ }
244
+ }
245
+ }
246
+ else if (part.type === 'tool') {
247
+ for (const tl of renderToolCall(part.call, contentW - 2, theme, { expanded: state.expandToolDetails || !part.call.done, bg: theme.field })) {
248
+ lines.push(tl);
249
+ }
250
+ }
251
+ else if (part.type === 'text' && part.text) {
252
+ for (const ml of renderMarkdown(part.text, contentW, theme, theme.field)) {
253
+ lines.push(ml);
254
+ }
255
+ }
256
+ }
257
+ lines.push({ segments: [] });
258
+ }
259
+ // Inline notices (compaction, context warnings, errors)
260
+ for (const n of slice.notices.slice(-4)) {
261
+ const color = n.tone === 'red' ? theme.red : n.tone === 'amber' ? theme.amber : n.tone === 'green' ? theme.green : theme.accent;
262
+ lines.push({
263
+ segments: [
264
+ { text: '● ', style: { fg: color, bg: theme.field, bold: true } },
265
+ { text: n.text, style: { fg: color, bg: theme.field } },
266
+ ],
267
+ });
268
+ }
269
+ state.transcriptTotalLines = lines.length;
270
+ const maxScroll = Math.max(0, lines.length - rect.h);
271
+ state.transcriptScroll = Math.max(0, Math.min(maxScroll, state.transcriptScroll));
272
+ const startIdx = Math.max(0, lines.length - rect.h - state.transcriptScroll);
273
+ for (let i = 0; i < rect.h && startIdx + i < lines.length; i++) {
274
+ const line = lines[startIdx + i];
275
+ const y = rect.y + i;
276
+ if (line.bg) {
277
+ buf.fill({ x: marginX, y, w: contentW, h: 1 }, { fg: theme.paper, bg: line.bg });
278
+ }
279
+ buf.drawSegments(marginX, y, line.segments, contentW);
280
+ if (line.clickAction) {
281
+ state.hitRegions.push({ rect: { x: marginX, y, w: contentW, h: 1 }, action: line.clickAction });
282
+ }
283
+ }
284
+ // Scrollbar + "scrolled up" cue
285
+ buf.drawScrollbar(rect, lines.length, rect.h, startIdx, { fg: theme.hairline, bg: theme.field }, { fg: state.focusedPane === 'main' ? theme.accent : theme.muted, bg: theme.field });
286
+ if (state.transcriptScroll > 0 && rect.h >= 3) {
287
+ const cue = ` ↓ ${state.transcriptScroll} lines below (End) `;
288
+ const cx = rect.x + rect.w - stringWidth(cue) - 2;
289
+ buf.drawText(cx, rect.y + rect.h - 1, cue, { fg: theme.onAccent, bg: theme.accent, bold: true });
290
+ state.hitRegions.push({
291
+ rect: { x: cx, y: rect.y + rect.h - 1, w: stringWidth(cue), h: 1 },
292
+ action: () => {
293
+ state.transcriptScroll = 0;
294
+ },
295
+ });
296
+ }
297
+ // Suppress unused variable warning for activeConv (used for future badge extensions)
298
+ void activeConv;
299
+ }
300
+ const messageLinesCache = new WeakMap();
301
+ function getHistoryMessageLines(msg, contentW, state, slice, theme, tz, cb) {
302
+ // Queued messages carry a per-render callback; skip caching only for active queued items
303
+ const cacheable = msg.queueState !== 'queued';
304
+ const cacheKey = cacheable
305
+ ? `${contentW}|${state.showReasoning ? 1 : 0}|${state.expandToolDetails ? 1 : 0}|${theme.palette}|${theme.mode}|${tz}|${slice.agentName}|${msg.text?.length ?? 0}|${msg.parts?.length ?? 0}|${msg.queueState ?? ''}`
306
+ : '';
307
+ if (cacheable) {
308
+ const hit = messageLinesCache.get(msg);
309
+ if (hit && hit.key === cacheKey)
310
+ return hit.lines;
311
+ }
312
+ const out = [];
313
+ appendHistoryMessageLines(out, msg, contentW, state, slice, theme, tz, cb);
314
+ if (cacheable) {
315
+ messageLinesCache.set(msg, { key: cacheKey, lines: out });
316
+ }
317
+ return out;
318
+ }
319
+ function appendHistoryMessageLines(lines, msg, contentW, state, slice, theme, tz, cb) {
320
+ if (msg.listenTurn)
321
+ return; // Internal listening turn seed hidden per ADR 185
322
+ const clock = formatClock(msg.createdAt, tz);
323
+ // Notice / interrupted / compaction rows
324
+ if (msg.notice) {
325
+ const toneColor = msg.notice.kind === 'error' ? theme.red : theme.amber;
326
+ lines.push({
327
+ segments: [
328
+ { text: '● ', style: { fg: toneColor, bg: theme.field, bold: true } },
329
+ { text: msg.notice.text, style: { fg: toneColor, bg: theme.field } },
330
+ { text: ` ${clock}`, style: { fg: theme.muted, bg: theme.field, dim: true } },
331
+ ],
332
+ });
333
+ lines.push({ segments: [] });
334
+ return;
335
+ }
336
+ if (msg.kind === 'compaction') {
337
+ lines.push({
338
+ segments: [
339
+ { text: '┄ Context compacted ', style: { fg: theme.amber, bg: theme.field, bold: true } },
340
+ { text: `· ${clock}`, style: { fg: theme.muted, bg: theme.field } },
341
+ ],
342
+ });
343
+ lines.push({ segments: [] });
344
+ return;
345
+ }
346
+ if (msg.role === 'user') {
347
+ const isSelf = msg.userId === undefined || msg.userId === null || msg.userId === state.account?.user.id;
348
+ const sender = msg.transcript
349
+ ? 'Transcript (Listen)'
350
+ : msg.conversationDelivery
351
+ ? `Conversation delivery (${msg.conversationDelivery.items.map((it) => it.kind).join(', ') || 'update'})`
352
+ : msg.triggerSource && msg.triggerSource !== 'tui' && msg.triggerSource !== 'app' && msg.triggerSource !== 'web' && msg.triggerSource !== 'ios' && msg.triggerSource !== 'chat'
353
+ ? `${msg.triggerSource}`
354
+ : isSelf
355
+ ? 'You'
356
+ : msg.displayName ?? 'Member';
357
+ const bubbleBg = msg.queueState === 'queued' ? theme.amberTint ?? theme.panel : theme.accentTint ?? theme.panel;
358
+ const headerSegs = [
359
+ { text: '▎ ', style: { fg: msg.queueState === 'queued' ? theme.amber : theme.accent, bg: bubbleBg, bold: true } },
360
+ { text: sender, style: { fg: msg.queueState === 'queued' ? theme.amber : theme.accent, bg: bubbleBg, bold: true } },
361
+ ...(msg.queueState ? [{ text: ` [${msg.queueState}]`, style: { fg: theme.amber, bg: bubbleBg, bold: true } }] : []),
362
+ { text: ` ${clock}`, style: { fg: theme.muted, bg: bubbleBg, dim: true } },
363
+ ];
364
+ lines.push({ bg: bubbleBg, segments: headerSegs });
365
+ const bodyText = msg.text || '';
366
+ for (const para of bodyText.replace(/\r\n/g, '\n').split('\n')) {
367
+ for (const wl of wrapParagraph(para, Math.max(10, contentW - 4))) {
368
+ lines.push({
369
+ bg: bubbleBg,
370
+ segments: [
371
+ { text: '▎ ', style: { fg: msg.queueState === 'queued' ? theme.amber : theme.accent, bg: bubbleBg } },
372
+ { text: wl, style: { fg: theme.paper, bg: bubbleBg } },
373
+ ],
374
+ });
375
+ }
376
+ }
377
+ // Attachments on user message
378
+ for (const part of msg.parts ?? []) {
379
+ if (part.type === 'attachment') {
380
+ lines.push({
381
+ bg: bubbleBg,
382
+ segments: [
383
+ { text: '▎ ', style: { fg: theme.accent, bg: bubbleBg } },
384
+ { text: `📎 ${part.artifact.filename ?? part.artifact.id} (${part.artifact.mediaType})`, style: { fg: theme.cyan, bg: bubbleBg } },
385
+ ],
386
+ });
387
+ }
388
+ }
389
+ // Action row for queued messages (Send now / Delete)
390
+ if (msg.queueState === 'queued' && msg.id !== undefined) {
391
+ const mid = msg.id;
392
+ lines.push({
393
+ bg: bubbleBg,
394
+ segments: [
395
+ { text: '▎ ', style: { fg: theme.amber, bg: bubbleBg } },
396
+ { text: '[Send now]', style: { fg: theme.green, bg: bubbleBg, bold: true } },
397
+ { text: ' queued', style: { fg: theme.muted, bg: bubbleBg, dim: true } },
398
+ ],
399
+ clickAction: () => cb.sendQueuedNow(mid),
400
+ });
401
+ }
402
+ lines.push({ segments: [] });
403
+ return;
404
+ }
405
+ // Assistant row
406
+ const agentColor = theme.agentColor(state.agents.find((a) => a.dirName === slice.dir)?.color ?? slice.dir);
407
+ const routeBadge = msg.routing
408
+ ? ` · ${msg.routing.model.split('/').pop()}${msg.routing.tier ? ` (${msg.routing.tier})` : ''}`
409
+ : '';
410
+ const durBadge = msg.durationMs ? ` · ${formatDurationMs(msg.durationMs)}` : '';
411
+ const headerLabel = msg.origin
412
+ ? `Subagent · ${msg.origin.taskPreview ?? msg.origin.profile ?? msg.origin.agentSessionId}`
413
+ : slice.agentName;
414
+ lines.push({
415
+ segments: [
416
+ { text: headerLabel, style: { fg: agentColor, bg: theme.field, bold: true } },
417
+ { text: ` ${clock}${durBadge}${routeBadge}`, style: { fg: theme.muted, bg: theme.field, dim: true } },
418
+ ],
419
+ });
420
+ if (msg.parts && msg.parts.length > 0) {
421
+ for (const part of msg.parts) {
422
+ if (part.type === 'reasoning') {
423
+ if (state.showReasoning && part.text.trim()) {
424
+ const rLines = part.text.trim().split('\n');
425
+ const preview = state.expandToolDetails ? rLines.slice(0, 20) : rLines.slice(0, 3);
426
+ lines.push({ segments: [{ text: ' ┄ Reasoning', style: { fg: theme.muted, bg: theme.field, italic: true } }] });
427
+ for (const rl of preview) {
428
+ for (const wl of wrapParagraph(rl, contentW - 4)) {
429
+ lines.push({ segments: [{ text: ` │ ${wl}`, style: { fg: theme.muted, bg: theme.field, italic: true, dim: true } }] });
430
+ }
431
+ }
432
+ if (rLines.length > preview.length) {
433
+ lines.push({ segments: [{ text: ` │ … ${rLines.length - preview.length} more lines (/tools to expand)`, style: { fg: theme.muted, bg: theme.field, dim: true } }] });
434
+ }
435
+ }
436
+ }
437
+ else if (part.type === 'tool') {
438
+ for (const tl of renderToolCall({
439
+ toolId: part.toolId,
440
+ toolName: part.toolName,
441
+ input: part.input,
442
+ output: part.output,
443
+ isError: part.isError,
444
+ done: true,
445
+ }, contentW - 2, theme, { expanded: state.expandToolDetails, bg: theme.field })) {
446
+ lines.push(tl);
447
+ }
448
+ }
449
+ else if (part.type === 'widget') {
450
+ lines.push({
451
+ segments: [
452
+ { text: ' ◆ Widget: ', style: { fg: theme.cyan, bg: theme.field, bold: true } },
453
+ { text: part.summary, style: { fg: theme.paper, bg: theme.field } },
454
+ ],
455
+ });
456
+ }
457
+ else if (part.type === 'attachment') {
458
+ lines.push({
459
+ segments: [
460
+ { text: ` 📎 ${part.artifact.filename ?? part.artifact.id}`, style: { fg: theme.cyan, bg: theme.field } },
461
+ { text: ` (${part.artifact.mediaType})`, style: { fg: theme.muted, bg: theme.field } },
462
+ ],
463
+ });
464
+ }
465
+ else if (part.type === 'text' && part.text) {
466
+ for (const ml of renderMarkdown(part.text, contentW, theme, theme.field)) {
467
+ lines.push(ml);
468
+ }
469
+ }
470
+ }
471
+ }
472
+ else if (msg.text) {
473
+ for (const ml of renderMarkdown(msg.text, contentW, theme, theme.field)) {
474
+ lines.push(ml);
475
+ }
476
+ }
477
+ lines.push({ segments: [] });
478
+ }
479
+ function computeDecisionHeight(question, parsed, noteOpen, maxH) {
480
+ const qLines = Math.min(3, Math.max(1, question.split('\n').length));
481
+ const choiceLines = parsed.mode === 'single' || parsed.mode === 'multi'
482
+ ? Math.min(6, parsed.choices.length) + (parsed.mode === 'multi' ? 1 : 0)
483
+ : parsed.mode === 'groups'
484
+ ? Math.min(8, parsed.groups.reduce((acc, g) => acc + 1 + g.choices.length, 0)) + 1
485
+ : 1;
486
+ const raw = 3 + qLines + choiceLines + (noteOpen ? 2 : 0);
487
+ return Math.max(5, Math.min(Math.max(6, maxH), raw));
488
+ }
489
+ function renderDecisionCard(buf, rect, state, conv, parsed, theme, cb) {
490
+ const focused = state.focusedPane === 'decision';
491
+ const bg = theme.amberTint ?? theme.panel;
492
+ buf.drawBox(rect, { fg: focused ? theme.amber : theme.hairline, bg }, {
493
+ fillStyle: { fg: theme.paper, bg },
494
+ title: conv.awaitingInferred ? 'Likely asking for your input' : 'Needs your decision',
495
+ titleStyle: { fg: theme.amber, bg, bold: true },
496
+ rightLabel: 'Tab/↑↓ choose · Enter send · x dismiss',
497
+ rightStyle: { fg: theme.muted, bg },
498
+ });
499
+ const innerX = rect.x + 2;
500
+ const innerW = Math.max(8, rect.w - 4);
501
+ let y = rect.y + 1;
502
+ const maxY = rect.y + rect.h - 1;
503
+ // Question text (wrapped up to 3 lines)
504
+ const qWrapped = wrapParagraph((conv.awaitingQuestion ?? '').replace(/\s+/g, ' ').trim(), innerW);
505
+ for (const ql of qWrapped.slice(0, 3)) {
506
+ if (y >= maxY)
507
+ break;
508
+ buf.drawTruncated(innerX, y, ql, innerW, { fg: theme.paper, bg, bold: true });
509
+ y += 1;
510
+ }
511
+ if (parsed.mode === 'none') {
512
+ if (y < maxY) {
513
+ buf.drawTruncated(innerX, y, 'Reply in the composer below, or click [Dismiss].', innerW - 12, { fg: theme.muted, bg });
514
+ const dx = innerX + innerW - 11;
515
+ buf.drawText(dx, y, ' Dismiss ', { fg: theme.muted, bg: theme.sunken ?? bg });
516
+ state.hitRegions.push({ rect: { x: dx, y, w: 9, h: 1 }, action: cb.dismissQuestion });
517
+ }
518
+ return;
519
+ }
520
+ if (parsed.mode === 'single') {
521
+ for (let i = 0; i < parsed.choices.length && y < maxY - (state.decision.noteOpen ? 2 : 0); i++) {
522
+ const c = parsed.choices[i];
523
+ const sel = focused && !state.decision.noteOpen && state.decision.cursor === i;
524
+ const rowBg = sel ? theme.accent : theme.panel;
525
+ const fg = sel ? theme.onAccent : theme.paper;
526
+ buf.fill({ x: innerX, y, w: innerW, h: 1 }, { fg, bg: rowBg });
527
+ buf.drawTruncated(innerX + 1, y, `${i + 1}. ${c.label}`, innerW - 2, { fg, bg: rowBg, bold: sel });
528
+ state.hitRegions.push({
529
+ rect: { x: innerX, y, w: innerW, h: 1 },
530
+ action: () => cb.sendChoiceAnswer(c.value),
531
+ });
532
+ y += 1;
533
+ }
534
+ if (state.decision.noteOpen && y < maxY) {
535
+ renderDecisionNoteInput(buf, innerX, y, innerW, state, theme, focused);
536
+ }
537
+ return;
538
+ }
539
+ if (parsed.mode === 'multi') {
540
+ const reserve = state.decision.noteOpen ? 2 : 1;
541
+ for (let i = 0; i < parsed.choices.length && y < maxY - reserve; i++) {
542
+ const c = parsed.choices[i];
543
+ const checked = state.decision.selectedMulti.has(c.value);
544
+ const sel = focused && !state.decision.noteOpen && state.decision.cursor === i;
545
+ const rowBg = sel ? theme.accentTint ?? theme.overlay : bg;
546
+ buf.fill({ x: innerX, y, w: innerW, h: 1 }, { fg: theme.paper, bg: rowBg });
547
+ buf.drawTruncated(innerX + 1, y, `${checked ? '[✓]' : '[ ]'} ${c.label}`, innerW - 2, {
548
+ fg: checked ? theme.green : theme.paper,
549
+ bg: rowBg,
550
+ bold: sel,
551
+ });
552
+ state.hitRegions.push({
553
+ rect: { x: innerX, y, w: innerW, h: 1 },
554
+ action: () => {
555
+ if (state.decision.selectedMulti.has(c.value))
556
+ state.decision.selectedMulti.delete(c.value);
557
+ else
558
+ state.decision.selectedMulti.add(c.value);
559
+ cb.focusPane('decision');
560
+ },
561
+ });
562
+ y += 1;
563
+ }
564
+ if (state.decision.noteOpen && y < maxY) {
565
+ renderDecisionNoteInput(buf, innerX, y, innerW, state, theme, focused);
566
+ y += 1;
567
+ }
568
+ if (y < maxY) {
569
+ const count = state.decision.selectedMulti.size;
570
+ buf.drawText(innerX, y, `Space toggle · n note · Enter send (${count} selected)`, { fg: theme.muted, bg });
571
+ }
572
+ return;
573
+ }
574
+ // Grouped choices
575
+ const reserve = state.decision.noteOpen ? 2 : 1;
576
+ let flatIdx = 0;
577
+ for (const g of parsed.groups) {
578
+ if (y >= maxY - reserve)
579
+ break;
580
+ const picked = state.decision.selectedGroups.get(g.label);
581
+ buf.drawTruncated(innerX, y, `${g.label}${picked ? `: ${picked}` : ''}`, innerW, { fg: theme.amber, bg, bold: true });
582
+ y += 1;
583
+ for (const c of g.choices) {
584
+ if (y >= maxY - reserve)
585
+ break;
586
+ const active = picked === c.value;
587
+ const sel = focused && !state.decision.noteOpen && state.decision.cursor === flatIdx;
588
+ const rowBg = sel ? theme.accentTint ?? theme.overlay : bg;
589
+ buf.drawTruncated(innerX + 2, y, `${active ? '●' : '○'} ${c.label}`, innerW - 2, {
590
+ fg: active ? theme.green : theme.paper,
591
+ bg: rowBg,
592
+ bold: sel || active,
593
+ });
594
+ const idxCopy = flatIdx;
595
+ state.hitRegions.push({
596
+ rect: { x: innerX, y, w: innerW, h: 1 },
597
+ action: () => {
598
+ state.decision.cursor = idxCopy;
599
+ state.decision.selectedGroups.set(g.label, c.value);
600
+ cb.focusPane('decision');
601
+ },
602
+ });
603
+ flatIdx++;
604
+ y += 1;
605
+ }
606
+ }
607
+ if (state.decision.noteOpen && y < maxY) {
608
+ renderDecisionNoteInput(buf, innerX, y, innerW, state, theme, focused);
609
+ y += 1;
610
+ }
611
+ if (y < maxY) {
612
+ buf.drawText(innerX, y, `Space select · n note · Enter submit${parsed.allowSkip ? ' · s skip all' : ''}`, { fg: theme.muted, bg });
613
+ }
614
+ }
615
+ function renderDecisionNoteInput(buf, x, y, w, state, theme, focused) {
616
+ const inBg = theme.sunken ?? theme.field;
617
+ buf.fill({ x, y, w, h: 1 }, { fg: theme.paper, bg: inBg });
618
+ const prefix = 'Note: ';
619
+ const win = state.decision.noteEditor.singleLineWindow(Math.max(6, w - prefix.length - 1));
620
+ buf.drawText(x, y, prefix, { fg: theme.amber, bg: inBg, bold: true });
621
+ buf.drawText(x + prefix.length, y, win.text, { fg: theme.paper, bg: inBg }, Math.max(4, w - prefix.length));
622
+ if (focused && !state.modal && !state.gotoMenuOpen) {
623
+ buf.cursor = { x: x + prefix.length + win.cursorCol, y, visible: true };
624
+ }
625
+ }
626
+ //# sourceMappingURL=chat-view.js.map