@aednzxy/smith-tui 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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 +47 -4
@@ -0,0 +1,802 @@
1
+ // Calm single-pane TUI chrome:
2
+ // - 1-line Top Context Bar (Agent › Title / Section + live status & model)
3
+ // - Optional Bottom Drawer (Logs / Container Shell / Background)
4
+ // - 1-line Contextual Key-Hint Footer with Mode Pill
5
+ // - Helix-style Floating `g` Go-To Which-Key Menu
6
+ // - Crisp Bottom-Right Toast notifications
7
+ import { effectiveAgentRole, WORKSPACE_SECTION_LABELS, } from '../app/state.js';
8
+ import { ansi } from '../engine/color.js';
9
+ import { stringWidth, truncateWidth } from '../engine/screen.js';
10
+ import { mergeConversations } from '../format/sessions.js';
11
+ import { formatDurationMs, formatUsd } from '../format/time.js';
12
+ export function computeShellRegions(state) {
13
+ const topH = 1;
14
+ const statusH = 1;
15
+ const showBottom = state.bottomPanelVisible && state.mode === 'agent' && state.activeSection === 'chats' && state.height >= 18;
16
+ const bottomH = showBottom ? Math.min(14, Math.max(7, Math.floor((state.height - topH - statusH) * 0.34))) : 0;
17
+ const contentH = Math.max(4, state.height - topH - statusH - bottomH);
18
+ return {
19
+ topBar: { x: 0, y: 0, w: state.width, h: topH },
20
+ content: { x: 0, y: topH, w: state.width, h: contentH },
21
+ bottomPanel: showBottom
22
+ ? { x: 0, y: topH + contentH, w: state.width, h: bottomH }
23
+ : null,
24
+ statusBar: { x: 0, y: state.height - statusH, w: state.width, h: statusH },
25
+ };
26
+ }
27
+ export function renderTopBar(buf, rect, state, theme, cb) {
28
+ const bg = theme.chrome;
29
+ buf.fill(rect, { fg: theme.paper, bg });
30
+ const y = rect.y;
31
+ // ── Right-aligned calm status & controls (drawn first so left title truncates cleanly) ──
32
+ let rx = rect.x + rect.w - 1;
33
+ const drawRight = (text, style, action, gap = 2) => {
34
+ const w = stringWidth(text);
35
+ if (rx - w <= rect.x + 22)
36
+ return false;
37
+ rx -= w;
38
+ buf.drawText(rx, y, text, { fg: style.fg, bg: style.bg ?? bg, bold: style.bold, dim: style.dim });
39
+ if (action) {
40
+ state.hitRegions.push({ rect: { x: rx, y, w, h: 1 }, action });
41
+ }
42
+ rx -= gap;
43
+ return true;
44
+ };
45
+ const inboxCount = state.fleet.inboxItems.length;
46
+ if (state.mode === 'agent' && state.activeAgentDir) {
47
+ const slice = state.slices.get(state.activeAgentDir);
48
+ // Live working indicator or connection warning
49
+ if (slice?.inFlight && slice.turnStartedAt) {
50
+ const secs = Math.max(0, Math.floor((Date.now() - Date.parse(slice.turnStartedAt)) / 1000));
51
+ const spin = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧'][state.tick % 8];
52
+ const phase = slice.turnPhase === 'memory_flush' ? 'Memory' : 'Working';
53
+ drawRight(`${spin} ${phase} ${formatDurationMs(secs * 1000)}`, { fg: theme.accent, bold: true });
54
+ }
55
+ else if (slice && slice.socketStatus !== 'connected') {
56
+ const statusWord = slice.socketStatus === 'migration_pending'
57
+ ? 'Migration'
58
+ : slice.socketStatus === 'reconnecting'
59
+ ? 'Reconnecting'
60
+ : slice.socketStatus === 'connecting'
61
+ ? 'Connecting'
62
+ : 'Offline';
63
+ const statusColor = slice.socketStatus === 'disconnected' ? theme.red : theme.amber;
64
+ drawRight(`○ ${statusWord}`, { fg: statusColor, bold: true });
65
+ }
66
+ // Context utilization (when non-zero)
67
+ if (slice && slice.contextLimit && slice.contextLimit > 0 && slice.contextTokens > 0) {
68
+ const pct = Math.min(100, Math.round((slice.contextTokens / slice.contextLimit) * 100));
69
+ const pctColor = pct >= 90 ? theme.red : pct >= 80 ? theme.amber : theme.muted;
70
+ drawRight(`ctx ${pct}%`, { fg: pctColor, dim: pct < 80 });
71
+ }
72
+ // Current model + effort (clickable -> Model Picker)
73
+ if (slice && state.activeSection === 'chats') {
74
+ const rawModel = slice.draftMode
75
+ ? slice.draftModel === 'auto'
76
+ ? 'Auto'
77
+ : (slice.draftModel || slice.defaultModel).split('/').pop() ?? ''
78
+ : slice.sessionSelection === 'auto'
79
+ ? `Auto (${(slice.sessionModel || slice.defaultModel).split('/').pop() ?? 'auto'})`
80
+ : (slice.sessionModel || slice.defaultModel).split('/').pop() ?? '';
81
+ if (rawModel) {
82
+ let effTag = '';
83
+ if (slice.draftMode) {
84
+ if (slice.draftThinking && slice.draftThinking !== 'off') {
85
+ effTag = ` · ${slice.draftThinking}${slice.draftSpeed === 'fast' ? '⚡' : ''}`;
86
+ }
87
+ else if (slice.draftSpeed === 'fast') {
88
+ effTag = ' · ⚡';
89
+ }
90
+ }
91
+ else {
92
+ const eff = slice.effectiveReasoning;
93
+ effTag = eff && eff.thinking !== 'off' ? ` · ${eff.thinking}${eff.speed === 'fast' ? '⚡' : ''}` : '';
94
+ }
95
+ drawRight(`${rawModel}${effTag}`, { fg: theme.muted }, cb.openModelPicker);
96
+ }
97
+ }
98
+ // Fleet Needs-you pill (clickable -> Fleet Inbox)
99
+ if (inboxCount > 0) {
100
+ drawRight(` ● ${inboxCount} needs you `, { fg: theme.amber, bg: theme.amberTint ?? theme.panel, bold: true }, cb.openFleet, 2);
101
+ }
102
+ }
103
+ else {
104
+ const serverStr = `${state.server.host}:${state.server.gatewayPort}`;
105
+ drawRight(`● ${serverStr}`, { fg: theme.muted, dim: true });
106
+ if (inboxCount > 0 && state.mode !== 'fleet') {
107
+ drawRight(` ● ${inboxCount} needs you `, { fg: theme.amber, bg: theme.amberTint ?? theme.panel, bold: true }, cb.openFleet, 2);
108
+ }
109
+ }
110
+ // ── Left-aligned breadcrumb / active context ──
111
+ let x = rect.x + 1;
112
+ const maxLeftX = Math.max(x + 12, rx);
113
+ if (state.mode === 'agent' && state.activeAgentDir) {
114
+ const agent = state.agents.find((a) => a.dirName === state.activeAgentDir);
115
+ const slice = state.slices.get(state.activeAgentDir);
116
+ const idColor = theme.agentColor(agent?.color ?? state.activeAgentDir);
117
+ const name = truncateWidth(agent?.name ?? state.activeAgentDir, 18);
118
+ const dotColor = !agent?.running
119
+ ? theme.muted
120
+ : slice?.socketStatus === 'connected'
121
+ ? theme.green
122
+ : slice?.socketStatus === 'disconnected'
123
+ ? theme.red
124
+ : theme.amber;
125
+ const agentTag = `● ${name}`;
126
+ const agentW = stringWidth(agentTag);
127
+ buf.drawText(x, y, '● ', { fg: dotColor, bg });
128
+ buf.drawText(x + 2, y, name, { fg: idColor, bg, bold: true });
129
+ x += agentW;
130
+ buf.drawText(x, y, ' › ', { fg: theme.muted, bg, dim: true });
131
+ x += 3;
132
+ const titleAvail = Math.max(6, maxLeftX - x);
133
+ if (state.activeSection === 'chats') {
134
+ const merged = slice ? mergeConversations(slice.wsSessions, slice.httpSessions, slice.readState) : [];
135
+ const activeConv = slice && !slice.draftMode && slice.selectedSessionId
136
+ ? merged.find((c) => c.sessionId === slice.selectedSessionId) ?? null
137
+ : null;
138
+ const title = slice?.draftMode
139
+ ? slice.draftBoardCard
140
+ ? `New card chat: ${slice.draftBoardCard.cardTitle ?? slice.draftBoardCard.cardId}`
141
+ : slice.draftParent
142
+ ? `New child: ${slice.draftParent.title ?? slice.draftParent.sessionId}`
143
+ : 'New conversation'
144
+ : activeConv?.title ?? slice?.sessionName ?? (slice?.selectedSessionId ?? 'No conversation');
145
+ const wakeMark = activeConv?.nextWakeAt ? ' ◷' : '';
146
+ const fullTitle = truncateWidth(title, Math.max(4, titleAvail - stringWidth(wakeMark)));
147
+ buf.drawText(x, y, fullTitle, { fg: theme.paper, bg, bold: true });
148
+ if (wakeMark) {
149
+ buf.drawText(x + stringWidth(fullTitle), y, wakeMark, { fg: theme.cyan, bg });
150
+ }
151
+ state.hitRegions.push({
152
+ rect: { x, y, w: Math.min(titleAvail, stringWidth(fullTitle) + stringWidth(wakeMark)), h: 1 },
153
+ action: cb.openChatsPicker,
154
+ });
155
+ }
156
+ else {
157
+ const secLabel = WORKSPACE_SECTION_LABELS[state.activeSection];
158
+ buf.drawText(x, y, secLabel, { fg: theme.accent, bg, bold: true });
159
+ state.hitRegions.push({ rect: { x, y, w: stringWidth(secLabel), h: 1 }, action: cb.toggleGotoMenu });
160
+ x += stringWidth(secLabel);
161
+ if (maxLeftX - x >= 16) {
162
+ buf.drawText(x + 2, y, 'Esc → Chats', { fg: theme.muted, bg, dim: true });
163
+ }
164
+ }
165
+ return;
166
+ }
167
+ if (state.mode === 'fleet') {
168
+ buf.drawText(x, y, '◆ Fleet', { fg: theme.accent, bg, bold: true });
169
+ x += 9;
170
+ const tabs = [
171
+ { id: 'inbox', label: `Inbox${inboxCount > 0 ? ` (${inboxCount})` : ''}` },
172
+ { id: 'overview', label: 'Overview' },
173
+ { id: 'cost', label: 'Spend' },
174
+ { id: 'attention', label: 'Attention' },
175
+ ];
176
+ for (let i = 0; i < tabs.length; i++) {
177
+ const t = tabs[i];
178
+ const active = state.fleet.tab === t.id;
179
+ const text = ` ${i + 1} ${t.label} `;
180
+ const w = stringWidth(text);
181
+ if (x + w > maxLeftX)
182
+ break;
183
+ buf.drawText(x, y, text, {
184
+ fg: active ? theme.accent : theme.muted,
185
+ bg: active ? theme.accentTint ?? theme.panel : bg,
186
+ bold: active,
187
+ });
188
+ state.hitRegions.push({ rect: { x, y, w, h: 1 }, action: () => { state.fleet.tab = t.id; } });
189
+ x += w + 1;
190
+ }
191
+ return;
192
+ }
193
+ if (state.mode === 'compute') {
194
+ buf.drawText(x, y, '◆ Compute', { fg: theme.accent, bg, bold: true });
195
+ x += 11;
196
+ const tabs = [
197
+ { id: 'pulse', label: 'Pulse' },
198
+ { id: 'machines', label: 'Machines' },
199
+ { id: 'workloads', label: 'Workloads' },
200
+ { id: 'problems', label: 'Problems' },
201
+ ];
202
+ for (let i = 0; i < tabs.length; i++) {
203
+ const t = tabs[i];
204
+ const active = state.compute.tab === t.id;
205
+ const text = ` ${i + 1} ${t.label} `;
206
+ const w = stringWidth(text);
207
+ if (x + w > maxLeftX)
208
+ break;
209
+ buf.drawText(x, y, text, {
210
+ fg: active ? theme.accent : theme.muted,
211
+ bg: active ? theme.accentTint ?? theme.panel : bg,
212
+ bold: active,
213
+ });
214
+ state.hitRegions.push({ rect: { x, y, w, h: 1 }, action: () => { state.compute.tab = t.id; } });
215
+ x += w + 1;
216
+ }
217
+ return;
218
+ }
219
+ if (state.mode === 'settings') {
220
+ buf.drawText(x, y, '◆ Settings', { fg: theme.accent, bg, bold: true });
221
+ x += 12;
222
+ if (maxLeftX - x > 14) {
223
+ buf.drawTruncated(x, y, 'Preferences & Platform', maxLeftX - x, { fg: theme.muted, bg });
224
+ }
225
+ }
226
+ }
227
+ export function renderBottomPanel(buf, rect, state, theme, cb) {
228
+ buf.fill(rect, { fg: theme.paper, bg: theme.field });
229
+ buf.drawHLine(rect.x, rect.y, rect.w, {
230
+ fg: state.focusedPane === 'bottom' ? theme.accent : theme.hairline,
231
+ bg: theme.panel,
232
+ });
233
+ const tabY = rect.y;
234
+ let tx = rect.x + 1;
235
+ const tabs = [
236
+ { id: 'logs', label: 'Logs' },
237
+ { id: 'shell', label: 'Shell' },
238
+ { id: 'background', label: 'Background' },
239
+ ];
240
+ for (const t of tabs) {
241
+ const active = state.bottomPanelTab === t.id;
242
+ const txt = ` ${t.label} `;
243
+ const w = stringWidth(txt);
244
+ buf.drawText(tx, tabY, txt, {
245
+ fg: active ? theme.accent : theme.muted,
246
+ bg: active ? theme.accentTint ?? theme.panel : theme.panel,
247
+ bold: active,
248
+ });
249
+ state.hitRegions.push({ rect: { x: tx, y: tabY, w, h: 1 }, action: () => cb.selectBottomTab(t.id) });
250
+ tx += w + 1;
251
+ }
252
+ const hint = state.bottomPanelTab === 'shell' ? ' ^G full PTY · ^` hide ' : ' ^` hide ';
253
+ const hintW = stringWidth(hint);
254
+ if (rect.w > tx - rect.x + hintW + 2) {
255
+ buf.drawText(rect.x + rect.w - hintW - 1, tabY, hint, { fg: theme.muted, bg: theme.panel, dim: true });
256
+ if (state.bottomPanelTab === 'shell') {
257
+ state.hitRegions.push({
258
+ rect: { x: rect.x + rect.w - hintW, y: tabY, w: 12, h: 1 },
259
+ action: cb.attachFullShell,
260
+ });
261
+ }
262
+ }
263
+ const bodyRect = { x: rect.x + 1, y: rect.y + 1, w: Math.max(1, rect.w - 2), h: Math.max(1, rect.h - 1) };
264
+ const dir = state.activeAgentDir;
265
+ if (!dir)
266
+ return;
267
+ if (state.bottomPanelTab === 'logs') {
268
+ const sec = state.sectionData.get(dir);
269
+ const lines = sec?.logLines ?? [];
270
+ if (lines.length === 0) {
271
+ buf.drawTruncated(bodyRect.x, bodyRect.y + 1, 'Waiting for live agent logs…', bodyRect.w, { fg: theme.muted, bg: theme.field });
272
+ return;
273
+ }
274
+ const start = Math.max(0, lines.length - bodyRect.h);
275
+ for (let i = 0; i < bodyRect.h && start + i < lines.length; i++) {
276
+ const line = lines[start + i];
277
+ const fg = line.includes('[error]') || line.includes('Error') || line.includes('ERR')
278
+ ? theme.red
279
+ : line.includes('[tools]') || line.includes('[MCP]')
280
+ ? theme.magenta
281
+ : line.includes('[agent]')
282
+ ? theme.cyan
283
+ : line.includes('[API]')
284
+ ? theme.green
285
+ : theme.muted;
286
+ buf.drawTruncated(bodyRect.x, bodyRect.y + i, line, bodyRect.w, { fg, bg: theme.field });
287
+ }
288
+ return;
289
+ }
290
+ if (state.bottomPanelTab === 'shell') {
291
+ const shell = state.shells.get(dir);
292
+ if (!state.account?.shellAccess) {
293
+ buf.drawTruncated(bodyRect.x, bodyRect.y + 1, 'Container shell requires an admin account.', bodyRect.w, { fg: theme.amber, bg: theme.field });
294
+ return;
295
+ }
296
+ if (!shell || shell.status === 'idle' || shell.status === 'connecting') {
297
+ buf.drawTruncated(bodyRect.x, bodyRect.y + 1, 'Connecting to container shell… (Ctrl+G for full-screen PTY)', bodyRect.w, { fg: theme.amber, bg: theme.field });
298
+ return;
299
+ }
300
+ if (shell.status === 'error' || shell.status === 'closed') {
301
+ buf.drawTruncated(bodyRect.x, bodyRect.y + 1, shell.errorMessage ?? 'Shell disconnected. Press r to reconnect.', bodyRect.w, { fg: theme.red, bg: theme.field });
302
+ return;
303
+ }
304
+ const grid = shell.vt.getGrid();
305
+ for (let row = 0; row < Math.min(bodyRect.h, grid.length); row++) {
306
+ const vtRow = grid[row];
307
+ for (let col = 0; col < Math.min(bodyRect.w, vtRow.length); col++) {
308
+ const c = vtRow[col];
309
+ buf.setCell(bodyRect.x + col, bodyRect.y + row, c.ch, {
310
+ fg: c.fg !== null ? ansi(c.fg) : theme.paper,
311
+ bg: c.bg !== null ? ansi(c.bg) : theme.field,
312
+ bold: c.bold,
313
+ inverse: c.inverse,
314
+ });
315
+ }
316
+ }
317
+ if (state.focusedPane === 'bottom' && !state.modal) {
318
+ buf.cursor = {
319
+ x: bodyRect.x + Math.min(bodyRect.w - 1, shell.vt.cursorX),
320
+ y: bodyRect.y + Math.min(bodyRect.h - 1, shell.vt.cursorY),
321
+ visible: true,
322
+ };
323
+ }
324
+ return;
325
+ }
326
+ const slice = state.slices.get(dir);
327
+ const bgWidget = slice?.widgets.find((w) => w.payload.kind === 'background');
328
+ if (!bgWidget || bgWidget.payload.kind !== 'background' || bgWidget.payload.processes.length === 0) {
329
+ buf.drawTruncated(bodyRect.x, bodyRect.y + 1, 'No background processes in this conversation.', bodyRect.w, { fg: theme.muted, bg: theme.field });
330
+ return;
331
+ }
332
+ let y = bodyRect.y;
333
+ for (const proc of bgWidget.payload.processes) {
334
+ if (y >= bodyRect.y + bodyRect.h)
335
+ break;
336
+ const stateColor = proc.state === 'running' ? theme.green : proc.state === 'killed' ? theme.red : theme.muted;
337
+ buf.drawTruncated(bodyRect.x, y, `● ${proc.state.toUpperCase()} ${proc.command}`, bodyRect.w, { fg: stateColor, bg: theme.field, bold: true });
338
+ y += 1;
339
+ for (const tail of proc.tailLines.slice(-3)) {
340
+ if (y >= bodyRect.y + bodyRect.h)
341
+ break;
342
+ buf.drawTruncated(bodyRect.x + 2, y, tail, bodyRect.w - 2, { fg: theme.muted, bg: theme.field });
343
+ y += 1;
344
+ }
345
+ }
346
+ }
347
+ function getFooterState(state, theme, cb) {
348
+ // Active modal takes precedence
349
+ if (state.modal) {
350
+ switch (state.modal.kind) {
351
+ case 'chats':
352
+ return {
353
+ pill: ' CHATS ',
354
+ pillFg: theme.onAccent,
355
+ pillBg: theme.accent,
356
+ hints: [
357
+ { key: '↑/↓', label: 'move' },
358
+ { key: 'PgUp/Dn', label: 'page' },
359
+ { key: 'Enter', label: 'open' },
360
+ { key: 'Tab', label: 'filter' },
361
+ { key: '^N', label: 'new' },
362
+ { key: '^P', label: 'pin' },
363
+ { key: '^D', label: 'arch' },
364
+ { key: 'Esc', label: 'close' },
365
+ ],
366
+ };
367
+ case 'inspector':
368
+ return {
369
+ pill: ' INSPECT ',
370
+ pillFg: theme.onAccent,
371
+ pillBg: theme.cyan,
372
+ hints: [
373
+ { key: '1-9/0/b', label: 'tab' },
374
+ { key: '[/]', label: 'prev/next' },
375
+ { key: 'j/k', label: 'move' },
376
+ { key: 'Enter', label: 'open' },
377
+ { key: 'r', label: 'refresh' },
378
+ { key: 'Esc', label: 'close' },
379
+ ],
380
+ };
381
+ case 'palette':
382
+ return {
383
+ pill: ' PALETTE ',
384
+ pillFg: theme.onAccent,
385
+ pillBg: theme.accent,
386
+ hints: [
387
+ { key: '↑/↓', label: 'move' },
388
+ { key: 'Enter', label: 'run' },
389
+ { key: 'Esc', label: 'close' },
390
+ ],
391
+ };
392
+ case 'editor':
393
+ return {
394
+ pill: ' EDITOR ',
395
+ pillFg: theme.onAccent,
396
+ pillBg: theme.accent,
397
+ hints: [
398
+ { key: '^S', label: 'save' },
399
+ { key: 'Esc', label: 'close' },
400
+ ],
401
+ };
402
+ default:
403
+ return {
404
+ pill: ` ${state.modal.kind.toUpperCase()} `,
405
+ pillFg: theme.onAccent,
406
+ pillBg: theme.accent,
407
+ hints: [
408
+ { key: 'Tab', label: 'next' },
409
+ { key: '↑/↓', label: 'move' },
410
+ { key: 'Enter', label: 'confirm' },
411
+ { key: 'Esc', label: 'close' },
412
+ ],
413
+ };
414
+ }
415
+ }
416
+ // Helix-style g Go-To menu active
417
+ if (state.gotoMenuOpen) {
418
+ return {
419
+ pill: ' GO TO ',
420
+ pillFg: theme.onAccent,
421
+ pillBg: theme.magenta,
422
+ hints: [
423
+ { key: 'c', label: 'chats' },
424
+ { key: 'i', label: 'inspect' },
425
+ { key: 'b', label: 'boards' },
426
+ { key: 'n', label: 'notes' },
427
+ { key: 'm', label: 'memory' },
428
+ { key: 'f', label: 'fleet' },
429
+ { key: 'w', label: 'compute' },
430
+ { key: ',', label: 'settings' },
431
+ { key: 'Esc', label: 'cancel' },
432
+ ],
433
+ };
434
+ }
435
+ // Fleet / Compute / Global Settings
436
+ if (state.mode === 'fleet') {
437
+ return {
438
+ pill: ' FLEET ',
439
+ pillFg: theme.onAccent,
440
+ pillBg: theme.accent,
441
+ hints: [
442
+ { key: '1-4', label: 'tab' },
443
+ { key: 'j/k', label: 'select' },
444
+ { key: 'Enter', label: 'open' },
445
+ { key: 'r', label: 'refresh' },
446
+ { key: 'g', label: 'go to', action: cb.toggleGotoMenu },
447
+ { key: '^K', label: 'palette', action: cb.openPalette },
448
+ { key: 'Esc', label: 'back' },
449
+ ],
450
+ };
451
+ }
452
+ if (state.mode === 'compute') {
453
+ return {
454
+ pill: ' COMPUTE ',
455
+ pillFg: theme.onAccent,
456
+ pillBg: theme.cyan,
457
+ hints: [
458
+ { key: '1-4', label: 'tab' },
459
+ { key: 'j/k', label: 'select' },
460
+ { key: 'Enter', label: 'logs' },
461
+ { key: 'W/D/S', label: 'node' },
462
+ { key: 'x', label: 'cancel' },
463
+ { key: 'g', label: 'go to', action: cb.toggleGotoMenu },
464
+ { key: 'Esc', label: 'back' },
465
+ ],
466
+ };
467
+ }
468
+ if (state.mode === 'settings') {
469
+ return {
470
+ pill: ' SETTINGS ',
471
+ pillFg: theme.onAccent,
472
+ pillBg: theme.accent,
473
+ hints: [
474
+ { key: 'Tab', label: state.globalSettings.focus === 'nav' ? 'body' : 'tabs' },
475
+ { key: 'j/k', label: 'move' },
476
+ { key: '←/→', label: 'palette' },
477
+ { key: 'Space', label: 'toggle' },
478
+ { key: 'x', label: 'revoke' },
479
+ { key: 'g', label: 'go to', action: cb.toggleGotoMenu },
480
+ { key: 'Esc', label: 'back' },
481
+ ],
482
+ };
483
+ }
484
+ // Agent views
485
+ if (state.mode === 'agent') {
486
+ if (state.activeSection === 'chats') {
487
+ if (state.focusedPane === 'decision') {
488
+ return {
489
+ pill: ' DECISION ',
490
+ pillFg: theme.onAccent,
491
+ pillBg: theme.amber,
492
+ hints: [
493
+ { key: '1-9', label: 'pick' },
494
+ { key: '↑/↓', label: 'move' },
495
+ { key: 'Space', label: 'toggle' },
496
+ { key: 'Enter', label: 'send' },
497
+ { key: 'n', label: 'note' },
498
+ { key: 'x', label: 'dismiss' },
499
+ { key: 'Tab', label: 'compose', action: cb.enterInsertMode },
500
+ ],
501
+ };
502
+ }
503
+ if (state.chatMode === 'insert') {
504
+ const slice = state.activeAgentDir ? state.slices.get(state.activeAgentDir) : undefined;
505
+ return {
506
+ pill: ' INSERT ',
507
+ pillFg: theme.onAccent,
508
+ pillBg: theme.accent,
509
+ hints: [
510
+ { key: 'Enter', label: slice?.inFlight ? 'queue' : 'send' },
511
+ { key: 'Esc', label: 'browse', action: cb.enterBrowseMode },
512
+ ...(slice?.inFlight ? [{ key: '^X', label: 'stop' }] : []),
513
+ { key: '^T', label: 'chats', action: cb.openChatsPicker },
514
+ { key: '^O', label: 'model', action: cb.openModelPicker },
515
+ { key: '^\\', label: 'inspect', action: cb.openInspectorOverlay },
516
+ { key: '^K', label: 'palette', action: cb.openPalette },
517
+ ],
518
+ };
519
+ }
520
+ // BROWSE mode (calm keyboard command mode)
521
+ const browseSlice = state.activeAgentDir ? state.slices.get(state.activeAgentDir) : undefined;
522
+ return {
523
+ pill: ' BROWSE ',
524
+ pillFg: theme.paper,
525
+ pillBg: theme.panel,
526
+ hints: [
527
+ { key: 'c', label: 'compose', action: cb.enterInsertMode },
528
+ { key: 'j/k', label: 'scroll' },
529
+ { key: 's', label: 'chats', action: cb.openChatsPicker },
530
+ { key: 'i', label: 'inspect', action: cb.openInspectorOverlay },
531
+ { key: 'g', label: 'go to', action: cb.toggleGotoMenu },
532
+ { key: 'm', label: 'model', action: cb.openModelPicker },
533
+ ...(browseSlice?.inFlight ? [{ key: 'X', label: 'stop' }] : [{ key: 'o', label: 'tools' }]),
534
+ { key: '?', label: 'help', action: cb.openHelp },
535
+ ],
536
+ };
537
+ }
538
+ // Secondary agent sections
539
+ switch (state.activeSection) {
540
+ case 'boards':
541
+ return {
542
+ pill: ' BOARDS ',
543
+ pillFg: theme.onAccent,
544
+ pillBg: theme.accent,
545
+ hints: [
546
+ { key: 'h/l', label: 'lanes' },
547
+ { key: 'j/k', label: 'cards' },
548
+ { key: 'b', label: 'board' },
549
+ { key: 'Enter', label: 'detail' },
550
+ { key: 'm/M', label: 'move' },
551
+ { key: 'n', label: 'new' },
552
+ { key: 'a', label: 'chat' },
553
+ { key: 'g', label: 'go to', action: cb.toggleGotoMenu },
554
+ { key: 'Esc', label: 'chats' },
555
+ ],
556
+ };
557
+ case 'notes':
558
+ return {
559
+ pill: ' NOTES ',
560
+ pillFg: theme.onAccent,
561
+ pillBg: theme.accent,
562
+ hints: [
563
+ { key: 'j/k', label: 'select' },
564
+ { key: 'n', label: 'new' },
565
+ { key: 'e', label: 'edit' },
566
+ { key: 'p', label: 'pin' },
567
+ { key: '/', label: 'search' },
568
+ { key: 'x', label: 'trash' },
569
+ { key: 'g', label: 'go to', action: cb.toggleGotoMenu },
570
+ { key: 'Esc', label: 'chats' },
571
+ ],
572
+ };
573
+ case 'files':
574
+ return {
575
+ pill: ' FILES ',
576
+ pillFg: theme.onAccent,
577
+ pillBg: theme.accent,
578
+ hints: [
579
+ { key: 'j/k', label: 'select' },
580
+ { key: 'Enter', label: 'open' },
581
+ { key: 'Bksp', label: 'up' },
582
+ { key: 'e', label: 'edit' },
583
+ { key: 'n', label: 'new' },
584
+ { key: 'r', label: 'refresh' },
585
+ { key: 'g', label: 'go to', action: cb.toggleGotoMenu },
586
+ { key: 'Esc', label: 'chats' },
587
+ ],
588
+ };
589
+ case 'skills':
590
+ return {
591
+ pill: ' SKILLS ',
592
+ pillFg: theme.onAccent,
593
+ pillBg: theme.accent,
594
+ hints: [
595
+ { key: 'j/k', label: 'select' },
596
+ { key: 'n', label: 'new' },
597
+ { key: 'e', label: 'edit' },
598
+ { key: 'x', label: 'delete' },
599
+ { key: 'r', label: 'refresh' },
600
+ { key: 'g', label: 'go to', action: cb.toggleGotoMenu },
601
+ { key: 'Esc', label: 'chats' },
602
+ ],
603
+ };
604
+ case 'memory':
605
+ return {
606
+ pill: ' MEMORY ',
607
+ pillFg: theme.onAccent,
608
+ pillBg: theme.accent,
609
+ hints: [
610
+ { key: '1-4', label: 'tab' },
611
+ { key: 'j/k', label: 'select' },
612
+ { key: 'Tab', label: 'pane' },
613
+ { key: 'Enter', label: 'open' },
614
+ { key: 'e', label: 'edit' },
615
+ { key: 'n/d', label: 'upkeep' },
616
+ { key: 'g', label: 'go to', action: cb.toggleGotoMenu },
617
+ { key: 'Esc', label: 'chats' },
618
+ ],
619
+ };
620
+ case 'activity':
621
+ return {
622
+ pill: ' ACTIVITY ',
623
+ pillFg: theme.onAccent,
624
+ pillBg: theme.accent,
625
+ hints: [
626
+ { key: '1-3', label: 'tab' },
627
+ { key: 'j/k', label: 'scroll' },
628
+ { key: '/', label: 'filter' },
629
+ { key: 'r', label: 'refresh' },
630
+ { key: 'g', label: 'go to', action: cb.toggleGotoMenu },
631
+ { key: 'Esc', label: 'chats' },
632
+ ],
633
+ };
634
+ case 'settings':
635
+ return {
636
+ pill: ' AGENT CFG ',
637
+ pillFg: theme.onAccent,
638
+ pillBg: theme.accent,
639
+ hints: [
640
+ { key: 'j/k', label: 'subject' },
641
+ { key: 's', label: 'start/stop' },
642
+ { key: 'R', label: 'restart' },
643
+ { key: 'e', label: 'YAML' },
644
+ { key: 't', label: 'shell' },
645
+ { key: 'g', label: 'go to', action: cb.toggleGotoMenu },
646
+ { key: 'Esc', label: 'chats' },
647
+ ],
648
+ };
649
+ }
650
+ }
651
+ return {
652
+ pill: ' SMITH ',
653
+ pillFg: theme.onAccent,
654
+ pillBg: theme.accent,
655
+ hints: [{ key: '?', label: 'help', action: cb.openHelp }],
656
+ };
657
+ }
658
+ export function renderStatusBar(buf, rect, state, theme, cb) {
659
+ const bg = theme.chrome;
660
+ buf.fill(rect, { fg: theme.muted, bg });
661
+ const y = rect.y;
662
+ const footer = getFooterState(state, theme, cb);
663
+ // Right-aligned compact meta (cost in active chat, else account name)
664
+ let rightStr = '';
665
+ if (state.mode === 'agent' && state.activeAgentDir && state.activeSection === 'chats') {
666
+ const slice = state.slices.get(state.activeAgentDir);
667
+ if (slice && slice.totalCostUsd > 0) {
668
+ rightStr = formatUsd(slice.totalCostUsd);
669
+ }
670
+ }
671
+ if (!rightStr && state.account?.user.display_name) {
672
+ rightStr = state.account.user.display_name;
673
+ }
674
+ const rw = rightStr ? stringWidth(rightStr) + 2 : 0;
675
+ const maxHintX = rect.x + rect.w - rw - 1;
676
+ // Left: Mode Pill
677
+ let x = rect.x;
678
+ buf.drawText(x, y, footer.pill, { fg: footer.pillFg, bg: footer.pillBg, bold: true });
679
+ x += stringWidth(footer.pill) + 1;
680
+ // Middle: Contextual clickable key hints
681
+ for (const h of footer.hints) {
682
+ const kw = stringWidth(h.key);
683
+ const lw = stringWidth(h.label);
684
+ const segW = kw + 1 + lw;
685
+ if (x + segW > maxHintX)
686
+ break;
687
+ buf.drawText(x, y, h.key, { fg: theme.accent, bg, bold: true });
688
+ buf.drawText(x + kw + 1, y, h.label, { fg: theme.muted, bg });
689
+ if (h.action) {
690
+ state.hitRegions.push({ rect: { x, y, w: segW, h: 1 }, action: h.action });
691
+ }
692
+ x += segW + 2;
693
+ }
694
+ // Right meta
695
+ if (rightStr && rect.w - rw > x) {
696
+ buf.drawText(rect.x + rect.w - stringWidth(rightStr) - 1, y, rightStr, { fg: theme.muted, bg, dim: true });
697
+ }
698
+ }
699
+ export function getGotoEntries(state, cb) {
700
+ const dir = state.activeAgentDir ?? state.agents[0]?.dirName ?? null;
701
+ const role = dir ? effectiveAgentRole(state.account, dir) : 'blocked';
702
+ const isOwner = role === 'owner';
703
+ const agentEntries = [];
704
+ if (dir) {
705
+ agentEntries.push({ key: 'c', label: 'Chats', run: () => cb.selectSection('chats') });
706
+ if (isOwner) {
707
+ agentEntries.push({ key: 'b', label: 'Boards', run: () => cb.selectSection('boards') });
708
+ agentEntries.push({ key: 'n', label: 'Notes', run: () => cb.selectSection('notes') });
709
+ agentEntries.push({ key: 'd', label: 'Files', run: () => cb.selectSection('files') });
710
+ agentEntries.push({ key: 's', label: 'Skills', run: () => cb.selectSection('skills') });
711
+ agentEntries.push({ key: 'm', label: 'Memory', run: () => cb.selectSection('memory') });
712
+ agentEntries.push({ key: 'v', label: 'Activity', run: () => cb.selectSection('activity') });
713
+ agentEntries.push({ key: '.', label: 'Agent cfg', run: () => cb.selectSection('settings') });
714
+ }
715
+ }
716
+ const globalEntries = [
717
+ ...(dir ? [{ key: 'i', label: 'Inspector', run: cb.openInspectorOverlay }] : []),
718
+ { key: 'f', label: 'Fleet', run: cb.openFleet },
719
+ { key: 'w', label: 'Compute', run: cb.openCompute },
720
+ ...(dir && state.account?.shellAccess ? [{ key: 't', label: 'Shell', run: cb.attachFullShell }] : []),
721
+ { key: ',', label: 'Settings', run: cb.openGlobalSettings },
722
+ { key: 'p', label: 'Palette', run: cb.openPalette },
723
+ { key: '?', label: 'Help', run: cb.openHelp },
724
+ ];
725
+ return { agent: agentEntries, global: globalEntries };
726
+ }
727
+ export function renderGotoMenu(buf, state, theme, cb) {
728
+ if (!state.gotoMenuOpen || state.modal)
729
+ return;
730
+ const { agent, global } = getGotoEntries(state, cb);
731
+ const rows = Math.max(agent.length, global.length);
732
+ const hasTwoCols = agent.length > 0;
733
+ const colW = 16;
734
+ const w = Math.min(buf.width - 2, hasTwoCols ? colW * 2 + 5 : colW + 4);
735
+ const h = Math.min(buf.height - 3, rows + 3);
736
+ const x = Math.max(1, buf.width - w - 1);
737
+ const y = Math.max(1, buf.height - h - 1);
738
+ const bg = theme.overlay ?? theme.panel;
739
+ buf.drawBox({ x, y, w, h }, { fg: theme.magenta, bg }, {
740
+ fillStyle: { fg: theme.paper, bg },
741
+ title: 'Go to',
742
+ titleStyle: { fg: theme.magenta, bg, bold: true },
743
+ rightLabel: 'Esc',
744
+ });
745
+ // Subtle column headings
746
+ if (hasTwoCols) {
747
+ buf.drawText(x + 2, y + 1, 'Workspace', { fg: theme.muted, bg, dim: true });
748
+ buf.drawText(x + 2 + colW + 1, y + 1, 'Global', { fg: theme.muted, bg, dim: true });
749
+ }
750
+ else {
751
+ buf.drawText(x + 2, y + 1, 'Global', { fg: theme.muted, bg, dim: true });
752
+ }
753
+ for (let i = 0; i < rows && y + 2 + i < y + h - 1; i++) {
754
+ const ry = y + 2 + i;
755
+ if (hasTwoCols && i < agent.length) {
756
+ const e = agent[i];
757
+ buf.drawText(x + 2, ry, e.key, { fg: theme.accent, bg, bold: true });
758
+ buf.drawTruncated(x + 5, ry, e.label, colW - 3, { fg: theme.paper, bg });
759
+ state.hitRegions.push({
760
+ rect: { x: x + 2, y: ry, w: colW, h: 1 },
761
+ action: () => {
762
+ state.gotoMenuOpen = false;
763
+ e.run();
764
+ },
765
+ });
766
+ }
767
+ if (i < global.length) {
768
+ const e = global[i];
769
+ const gx = hasTwoCols ? x + 2 + colW + 1 : x + 2;
770
+ buf.drawText(gx, ry, e.key, { fg: theme.cyan, bg, bold: true });
771
+ buf.drawTruncated(gx + 3, ry, e.label, colW - 3, { fg: theme.paper, bg });
772
+ state.hitRegions.push({
773
+ rect: { x: gx, y: ry, w: colW, h: 1 },
774
+ action: () => {
775
+ state.gotoMenuOpen = false;
776
+ e.run();
777
+ },
778
+ });
779
+ }
780
+ }
781
+ }
782
+ export function renderToast(buf, state, theme) {
783
+ const toast = state.toast;
784
+ if (!toast || Date.now() > toast.expiresAt)
785
+ return;
786
+ const fg = toast.tone === 'red'
787
+ ? theme.red
788
+ : toast.tone === 'amber'
789
+ ? theme.amber
790
+ : toast.tone === 'green'
791
+ ? theme.green
792
+ : theme.accent;
793
+ const icon = toast.tone === 'red' ? '✗' : toast.tone === 'amber' ? '!' : toast.tone === 'green' ? '✓' : '●';
794
+ const bg = theme.overlay ?? theme.panel;
795
+ const text = ` ${icon} ${truncateWidth(toast.text, Math.min(64, buf.width - 6))} `;
796
+ const w = stringWidth(text);
797
+ const x = Math.max(1, buf.width - w - 1);
798
+ const y = 1;
799
+ buf.fill({ x, y, w, h: 1 }, { fg, bg });
800
+ buf.drawText(x, y, text, { fg, bg, bold: true }, w);
801
+ }
802
+ //# sourceMappingURL=shell-layout.js.map