@aliou/pi-processes 0.4.7 → 0.6.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 (51) hide show
  1. package/README.md +83 -13
  2. package/package.json +10 -4
  3. package/src/commands/clear/command.ts +14 -0
  4. package/src/commands/clear/index.ts +1 -0
  5. package/src/commands/completions.ts +38 -0
  6. package/src/commands/dock/command.ts +29 -0
  7. package/src/commands/dock/index.ts +1 -0
  8. package/src/commands/index.ts +26 -327
  9. package/src/commands/kill/command.ts +69 -0
  10. package/src/commands/kill/index.ts +1 -0
  11. package/src/commands/logs/command.ts +47 -0
  12. package/src/commands/logs/index.ts +1 -0
  13. package/src/commands/pick-process.ts +34 -0
  14. package/src/commands/pin/command.ts +33 -0
  15. package/src/commands/pin/index.ts +1 -0
  16. package/src/commands/processes/command.ts +39 -0
  17. package/src/commands/processes/index.ts +1 -0
  18. package/src/commands/settings/apply-setting-change.ts +72 -0
  19. package/src/commands/settings/build-sections.ts +160 -0
  20. package/src/commands/settings/command.ts +20 -0
  21. package/src/commands/settings/index.ts +1 -0
  22. package/src/components/log-dock-component.ts +238 -0
  23. package/src/components/log-file-viewer.ts +317 -0
  24. package/src/components/log-overlay-component.ts +555 -0
  25. package/src/components/process-picker-component.ts +14 -2
  26. package/src/components/processes-component.ts +41 -21
  27. package/src/config.ts +38 -1
  28. package/src/constants/index.ts +1 -0
  29. package/src/constants/types.ts +7 -1
  30. package/src/hooks/background-blocker.ts +66 -0
  31. package/src/hooks/index.ts +15 -3
  32. package/src/hooks/process-end.ts +3 -30
  33. package/src/hooks/widget/index.ts +2 -0
  34. package/src/hooks/widget/setup.ts +168 -0
  35. package/src/hooks/{widget.ts → widget/status-widget.ts} +27 -68
  36. package/src/hooks/widget/types.ts +21 -0
  37. package/src/index.ts +9 -3
  38. package/src/manager.ts +61 -9
  39. package/src/tools/actions/index.ts +5 -0
  40. package/src/tools/actions/write.ts +87 -0
  41. package/src/tools/index.ts +82 -14
  42. package/src/utils/command-executor.test.ts +2 -1
  43. package/src/utils/command-executor.ts +1 -1
  44. package/src/utils/keybindings.ts +76 -0
  45. package/src/utils/shell-utils.ts +133 -0
  46. package/src/commands/settings-command.ts +0 -157
  47. package/src/components/log-stream-component.ts +0 -149
  48. package/src/test/test-exit-crash.sh +0 -19
  49. package/src/test/test-exit-failure.sh +0 -17
  50. package/src/test/test-exit-success.sh +0 -16
  51. package/src/test/test-output.sh +0 -28
@@ -0,0 +1,555 @@
1
+ /**
2
+ * LogOverlayComponent - tabbed log viewer as a floating overlay.
3
+ *
4
+ * Layout (CHROME_LINES = 7, logRows computed from terminal height):
5
+ *
6
+ * ╭──────────── Process Logs ─────────────╮
7
+ * │ [● backend] ✓ frontend ✗ worker │
8
+ * ├───────────────────────────────────────┤
9
+ * │ log line 1 │
10
+ * │ ... │
11
+ * ├───────────────────────────────────────┤
12
+ * │ /query 1/4 42% L50/120│
13
+ * │ ←/→ tab g/G j/k / n/N s f q │
14
+ * ╰───────────────────────────────────────╯
15
+ */
16
+
17
+ import type { Theme } from "@mariozechner/pi-coding-agent";
18
+ import {
19
+ type Component,
20
+ Input,
21
+ matchesKey,
22
+ type TUI,
23
+ truncateToWidth,
24
+ visibleWidth,
25
+ } from "@mariozechner/pi-tui";
26
+ import { LIVE_STATUSES, type ProcessInfo } from "../constants";
27
+ import type { ProcessManager } from "../manager";
28
+ import { LogFileViewer } from "./log-file-viewer";
29
+ import { statusIcon } from "./status-format";
30
+
31
+ // Lines that aren't log content: top border + tabs + divider + divider + status + footer + bottom border
32
+ const CHROME_LINES = 7;
33
+ const MIN_LOG_ROWS = 5;
34
+ const OVERLAY_FRACTION = 0.8;
35
+ const MAX_TAB_NAME = 12;
36
+
37
+ type OverlayMode = "normal" | "search-typing" | "search-active";
38
+
39
+ interface LogOverlayOptions {
40
+ tui: TUI;
41
+ theme: Theme;
42
+ manager: ProcessManager;
43
+ /** Pre-select this process on open. If absent, uses first in list. */
44
+ initialProcessId?: string;
45
+ done: () => void;
46
+ }
47
+
48
+ export class LogOverlayComponent implements Component {
49
+ private tui: TUI;
50
+ private theme: Theme;
51
+ private manager: ProcessManager;
52
+ private done: () => void;
53
+
54
+ private processes: ProcessInfo[] = [];
55
+ private tabIndex = 0;
56
+ private tabViewOffset = 0;
57
+
58
+ /** One LogFileViewer per process id, lazy-created on first visit. */
59
+ private viewers: Map<string, LogFileViewer> = new Map();
60
+
61
+ private mode: OverlayMode = "normal";
62
+ private searchInput: Input = new Input();
63
+
64
+ private timer: ReturnType<typeof setInterval> | null = null;
65
+ private unsubscribeManager: (() => void) | null = null;
66
+
67
+ constructor(opts: LogOverlayOptions) {
68
+ this.tui = opts.tui;
69
+ this.theme = opts.theme;
70
+ this.manager = opts.manager;
71
+ this.done = opts.done;
72
+
73
+ this.processes = this.sortProcesses(this.manager.list());
74
+
75
+ if (opts.initialProcessId) {
76
+ const idx = this.processes.findIndex(
77
+ (p) => p.id === opts.initialProcessId,
78
+ );
79
+ if (idx >= 0) this.tabIndex = idx;
80
+ }
81
+
82
+ this.unsubscribeManager = this.manager.onEvent(() => {
83
+ const next = this.manager.list();
84
+ // Auto-close when all processes have been cleared.
85
+ if (next.length === 0) {
86
+ this.close();
87
+ return;
88
+ }
89
+ this.processes = this.sortProcesses(next);
90
+ this.tabIndex = Math.min(this.tabIndex, this.processes.length - 1);
91
+ this.tui.requestRender();
92
+ });
93
+
94
+ this.timer = setInterval(() => {
95
+ this.tui.requestRender();
96
+ }, 300);
97
+
98
+ this.searchInput.onSubmit = (query) => {
99
+ const trimmed = query.trim();
100
+ if (trimmed) {
101
+ this.currentViewer()?.setSearch(trimmed);
102
+ this.mode = "search-active";
103
+ } else {
104
+ this.currentViewer()?.clearSearch();
105
+ this.mode = "normal";
106
+ }
107
+ this.tui.requestRender();
108
+ };
109
+
110
+ this.searchInput.onEscape = () => {
111
+ this.mode = "normal";
112
+ this.searchInput.setValue("");
113
+ this.tui.requestRender();
114
+ };
115
+ }
116
+
117
+ // ---------------------------------------------------------------------------
118
+ // Sorting
119
+ // ---------------------------------------------------------------------------
120
+
121
+ private sortProcesses(list: ProcessInfo[]): ProcessInfo[] {
122
+ const isLive = (p: ProcessInfo) => LIVE_STATUSES.has(p.status);
123
+ return [...list].sort((a, b) => {
124
+ const aLive = isLive(a) ? 1 : 0;
125
+ const bLive = isLive(b) ? 1 : 0;
126
+ if (bLive !== aLive) return bLive - aLive; // live first
127
+ return b.startTime - a.startTime; // most recent first within each group
128
+ });
129
+ }
130
+
131
+ // ---------------------------------------------------------------------------
132
+ // Viewer lifecycle
133
+ // ---------------------------------------------------------------------------
134
+
135
+ private getViewer(proc: ProcessInfo): LogFileViewer | null {
136
+ let viewer = this.viewers.get(proc.id);
137
+ if (!viewer) {
138
+ const logFiles = this.manager.getLogFiles(proc.id);
139
+ if (!logFiles) return null;
140
+ viewer = new LogFileViewer({
141
+ filePath: logFiles.combinedFile,
142
+ format: "combined",
143
+ theme: this.theme,
144
+ follow: false,
145
+ });
146
+ this.viewers.set(proc.id, viewer);
147
+ }
148
+ return viewer;
149
+ }
150
+
151
+ private currentProcess(): ProcessInfo | null {
152
+ return this.processes[this.tabIndex] ?? null;
153
+ }
154
+
155
+ private currentViewer(): LogFileViewer | null {
156
+ const proc = this.currentProcess();
157
+ if (!proc) return null;
158
+ return this.getViewer(proc) ?? null;
159
+ }
160
+
161
+ // ---------------------------------------------------------------------------
162
+ // Cleanup
163
+ // ---------------------------------------------------------------------------
164
+
165
+ private close(): void {
166
+ if (this.timer) {
167
+ clearInterval(this.timer);
168
+ this.timer = null;
169
+ }
170
+ this.unsubscribeManager?.();
171
+ this.unsubscribeManager = null;
172
+ this.done();
173
+ }
174
+
175
+ // ---------------------------------------------------------------------------
176
+ // Input
177
+ // ---------------------------------------------------------------------------
178
+
179
+ handleInput(data: string): boolean {
180
+ if (this.mode === "search-typing")
181
+ return this.handleSearchTypingInput(data);
182
+ if (this.mode === "search-active")
183
+ return this.handleSearchActiveInput(data);
184
+ return this.handleNormalInput(data);
185
+ }
186
+
187
+ private handleNormalInput(data: string): boolean {
188
+ const viewer = this.currentViewer();
189
+
190
+ if (matchesKey(data, "escape") || data === "q" || data === "Q") {
191
+ this.close();
192
+ return true;
193
+ }
194
+
195
+ if (data === "\t") {
196
+ this.nextTab();
197
+ return true;
198
+ }
199
+ if (matchesKey(data, "shift+tab")) {
200
+ this.prevTab();
201
+ return true;
202
+ }
203
+
204
+ if (!viewer) return true;
205
+
206
+ if (data === "g") {
207
+ viewer.scrollToTop();
208
+ this.tui.requestRender();
209
+ return true;
210
+ }
211
+ if (data === "G") {
212
+ viewer.scrollToBottom();
213
+ this.tui.requestRender();
214
+ return true;
215
+ }
216
+ if (matchesKey(data, "down") || data === "j") {
217
+ viewer.scrollBy(1);
218
+ this.tui.requestRender();
219
+ return true;
220
+ }
221
+ if (matchesKey(data, "up") || data === "k") {
222
+ viewer.scrollBy(-1);
223
+ this.tui.requestRender();
224
+ return true;
225
+ }
226
+ if (data === "f") {
227
+ viewer.toggleFollow();
228
+ this.tui.requestRender();
229
+ return true;
230
+ }
231
+ if (data === "s") {
232
+ viewer.cycleStreamFilter();
233
+ this.tui.requestRender();
234
+ return true;
235
+ }
236
+
237
+ if (data === "/") {
238
+ this.searchInput.setValue("");
239
+ this.mode = "search-typing";
240
+ this.tui.requestRender();
241
+ return true;
242
+ }
243
+ return true;
244
+ }
245
+
246
+ private handleSearchTypingInput(data: string): boolean {
247
+ // Delegate all editing to the Input component.
248
+ // onSubmit / onEscape are wired in the constructor and fire synchronously.
249
+ this.searchInput.handleInput(data);
250
+ this.tui.requestRender();
251
+ return true;
252
+ }
253
+
254
+ private handleSearchActiveInput(data: string): boolean {
255
+ if (matchesKey(data, "escape")) {
256
+ this.currentViewer()?.clearSearch();
257
+ this.mode = "normal";
258
+ this.searchInput.setValue("");
259
+ this.tui.requestRender();
260
+ return true;
261
+ }
262
+ if (data === "n") {
263
+ this.currentViewer()?.nextMatch();
264
+ this.tui.requestRender();
265
+ return true;
266
+ }
267
+ if (data === "N") {
268
+ this.currentViewer()?.prevMatch();
269
+ this.tui.requestRender();
270
+ return true;
271
+ }
272
+ if (data === "/") {
273
+ // Re-open typing with current query pre-filled.
274
+ const current = this.currentViewer()?.getSearchInfo()?.query ?? "";
275
+ this.searchInput.setValue(current);
276
+ this.mode = "search-typing";
277
+ this.tui.requestRender();
278
+ return true;
279
+ }
280
+ // All other keys: normal navigation (j/k, g/G, f, s, Tab, q, etc.)
281
+ return this.handleNormalInput(data);
282
+ }
283
+
284
+ private prevTab(): void {
285
+ if (this.processes.length === 0) return;
286
+ this.tabIndex =
287
+ (this.tabIndex - 1 + this.processes.length) % this.processes.length;
288
+ this.ensureTabVisible();
289
+ this.tui.requestRender();
290
+ }
291
+
292
+ private nextTab(): void {
293
+ if (this.processes.length === 0) return;
294
+ this.tabIndex = (this.tabIndex + 1) % this.processes.length;
295
+ this.ensureTabVisible();
296
+ this.tui.requestRender();
297
+ }
298
+
299
+ private ensureTabVisible(): void {
300
+ if (this.tabIndex < this.tabViewOffset) {
301
+ this.tabViewOffset = this.tabIndex;
302
+ }
303
+ this.tabViewOffset = Math.max(
304
+ 0,
305
+ Math.min(this.tabViewOffset, this.tabIndex),
306
+ );
307
+ }
308
+
309
+ // ---------------------------------------------------------------------------
310
+ // Rendering
311
+ // ---------------------------------------------------------------------------
312
+
313
+ render(width: number): string[] {
314
+ const totalRows = this.tui.terminal.rows ?? 24;
315
+ const logRows = Math.max(
316
+ MIN_LOG_ROWS,
317
+ Math.floor(totalRows * OVERLAY_FRACTION) - CHROME_LINES,
318
+ );
319
+
320
+ const theme = this.theme;
321
+ // innerWidth = space available for content inside "│ " and " │"
322
+ const innerWidth = width - 4;
323
+ const border = (s: string) => theme.fg("dim", s);
324
+ const accent = (s: string) => theme.fg("accent", s);
325
+ const dim = (s: string) => theme.fg("dim", s);
326
+
327
+ // Pad content to exactly innerWidth visible chars, then wrap in borders.
328
+ const pad = (s: string): string => {
329
+ const w = visibleWidth(s);
330
+ if (w > innerWidth) return truncateToWidth(s, innerWidth);
331
+ return s + " ".repeat(innerWidth - w);
332
+ };
333
+ const row = (content: string): string =>
334
+ `${border("│ ")}${pad(content)}${border(" │")}`;
335
+ const divider = (): string => border(`├${"─".repeat(width - 2)}┤`);
336
+
337
+ const lines: string[] = [];
338
+
339
+ // ── Top border with centered title ──────────────────────────────────────
340
+ const title = " Process Logs ";
341
+ const titleW = visibleWidth(title);
342
+ const sideTotal = Math.max(0, width - 2 - titleW);
343
+ const leftDash = Math.floor(sideTotal / 2);
344
+ const rightDash = sideTotal - leftDash;
345
+ lines.push(
346
+ border(`╭${"─".repeat(leftDash)}`) +
347
+ accent(title) +
348
+ border(`${"─".repeat(rightDash)}╮`),
349
+ );
350
+
351
+ // ── Tab bar ─────────────────────────────────────────────────────────────
352
+ lines.push(row(this.renderTabBar(innerWidth)));
353
+
354
+ // ── Divider ─────────────────────────────────────────────────────────────
355
+ lines.push(divider());
356
+
357
+ // ── Log content ─────────────────────────────────────────────────────────
358
+ const viewer = this.currentViewer();
359
+ if (!viewer || this.processes.length === 0) {
360
+ for (let i = 0; i < logRows; i++) {
361
+ lines.push(
362
+ row(i === Math.floor(logRows / 2) ? dim("No processes") : ""),
363
+ );
364
+ }
365
+ } else {
366
+ const contentLines = viewer.renderLines(innerWidth, logRows);
367
+ // Overlay "following" indicator at bottom-right of the content area.
368
+ if (viewer.isFollowing()) {
369
+ const indicator = theme.fg("accent", "following");
370
+ const indicatorW = visibleWidth(indicator);
371
+ const targetIdx = logRows - 1;
372
+ const line = contentLines[targetIdx] ?? "";
373
+ const truncated = truncateToWidth(line, innerWidth - indicatorW);
374
+ const truncW = visibleWidth(truncated);
375
+ contentLines[targetIdx] =
376
+ truncated +
377
+ " ".repeat(Math.max(0, innerWidth - truncW - indicatorW)) +
378
+ indicator;
379
+ }
380
+ for (let i = 0; i < logRows; i++) {
381
+ lines.push(row(contentLines[i] ?? ""));
382
+ }
383
+ }
384
+
385
+ // ── Divider ─────────────────────────────────────────────────────────────
386
+ lines.push(divider());
387
+
388
+ // ── Status bar ──────────────────────────────────────────────────────────
389
+ const statusContent = this.renderStatusContent(innerWidth, viewer);
390
+ lines.push(row(statusContent));
391
+
392
+ // ── Footer / keybindings ────────────────────────────────────────────────
393
+ lines.push(row(this.renderFooterContent(innerWidth)));
394
+
395
+ // ── Bottom border ───────────────────────────────────────────────────────
396
+ lines.push(border(`╰${"─".repeat(width - 2)}╯`));
397
+
398
+ return lines;
399
+ }
400
+
401
+ private renderTabBar(innerWidth: number): string {
402
+ if (this.processes.length === 0) {
403
+ return this.theme.fg("dim", "No processes");
404
+ }
405
+
406
+ const theme = this.theme;
407
+ const accent = (s: string) => theme.fg("accent", s);
408
+ const dim = (s: string) => theme.fg("dim", s);
409
+ const success = (s: string) => theme.fg("success", s);
410
+ const warning = (s: string) => theme.fg("warning", s);
411
+ const error = (s: string) => theme.fg("error", s);
412
+
413
+ const coloredIcon = (proc: ProcessInfo): string => {
414
+ const icon = statusIcon(proc.status, proc.success);
415
+ switch (proc.status) {
416
+ case "running":
417
+ return success(icon);
418
+ case "terminating":
419
+ case "terminate_timeout":
420
+ return warning(icon);
421
+ case "killed":
422
+ return error(icon);
423
+ case "exited":
424
+ return proc.success ? dim(icon) : error(icon);
425
+ default:
426
+ return dim(icon);
427
+ }
428
+ };
429
+
430
+ // Overflow indicators reserve 2 chars each.
431
+ const OVERFLOW_W = 2;
432
+ const SEP = " ";
433
+ const SEP_W = 2;
434
+
435
+ const hasLeft = this.tabViewOffset > 0;
436
+ let usedWidth = hasLeft ? OVERFLOW_W : 0;
437
+ const tabStrings: string[] = [];
438
+ let lastVisible = this.tabViewOffset - 1;
439
+
440
+ for (let i = this.tabViewOffset; i < this.processes.length; i++) {
441
+ const proc = this.processes[i];
442
+ if (!proc) continue;
443
+ const isActive = i === this.tabIndex;
444
+
445
+ const namePlain = proc.name.slice(0, MAX_TAB_NAME);
446
+ // Visible width of this tab: "icon name" plus brackets if active.
447
+ // Active: "[icon name]" = 1 + 1(icon) + 1(space) + nameLen + 1 = nameLen + 4
448
+ // Inactive: " icon name " = 1 + 1(icon) + 1(space) + nameLen + 1 = nameLen + 4 (same)
449
+ const tabW = 1 + 1 + 1 + namePlain.length + 1; // bracket + icon + space + name + bracket
450
+ const needed = tabStrings.length > 0 ? SEP_W + tabW : tabW;
451
+ const rightReserve = i < this.processes.length - 1 ? OVERFLOW_W : 0;
452
+
453
+ if (usedWidth + needed + rightReserve > innerWidth) break;
454
+
455
+ usedWidth += needed;
456
+ lastVisible = i;
457
+
458
+ const icon = coloredIcon(proc);
459
+ const name = isActive ? accent(namePlain) : dim(namePlain);
460
+ if (isActive) {
461
+ tabStrings.push(`${accent("[")}${icon} ${name}${accent("]")}`);
462
+ } else {
463
+ tabStrings.push(`${dim(" ")}${icon} ${name}${dim(" ")}`);
464
+ }
465
+ }
466
+
467
+ const hasRight = lastVisible < this.processes.length - 1;
468
+ const left = hasLeft ? dim("← ") : "";
469
+ const right = hasRight ? dim(" →") : "";
470
+
471
+ return left + tabStrings.join(SEP) + right;
472
+ }
473
+
474
+ private renderStatusContent(
475
+ innerWidth: number,
476
+ viewer: LogFileViewer | null,
477
+ ): string {
478
+ const theme = this.theme;
479
+ const dim = (s: string) => theme.fg("dim", s);
480
+
481
+ if (this.mode === "search-typing") {
482
+ // Input renders as "> <text>" — replace "> " with "/" for search prompt.
483
+ // Reserve innerWidth - 1 chars for Input so the "/" prefix fits.
484
+ const inputWidth = Math.max(1, innerWidth - 1);
485
+ const rendered = this.searchInput.render(inputWidth);
486
+ const inputLine = rendered[0] ?? "";
487
+ // Input always prefixes with "> " (2 plain chars, no ANSI before them).
488
+ const withSlash = dim("/") + inputLine.slice(2);
489
+ const w = visibleWidth(withSlash);
490
+ if (w >= innerWidth) return truncateToWidth(withSlash, innerWidth);
491
+ return withSlash + " ".repeat(Math.max(0, innerWidth - w));
492
+ }
493
+
494
+ if (!viewer) return "";
495
+ // LogFileViewer.renderStatusBar() returns a string padded to given width.
496
+ return viewer.renderStatusBar(innerWidth);
497
+ }
498
+
499
+ private renderFooterContent(innerWidth: number): string {
500
+ const theme = this.theme;
501
+ const dim = (s: string) => theme.fg("dim", s);
502
+ const accent = (s: string) => theme.fg("accent", s);
503
+
504
+ if (this.mode === "search-typing") {
505
+ const hint = `${dim("enter")} apply ${dim("esc")} cancel ${dim("ctrl+u")} clear`;
506
+ const w = visibleWidth(hint);
507
+ if (w >= innerWidth) return truncateToWidth(hint, innerWidth);
508
+ return hint + " ".repeat(innerWidth - w);
509
+ }
510
+
511
+ if (this.mode === "search-active") {
512
+ const hint =
513
+ `${dim("n")} next ` +
514
+ `${dim("N")} prev ` +
515
+ `${dim("/")} edit search ` +
516
+ `${dim("esc")} clear ` +
517
+ `${dim("j/k")} scroll ` +
518
+ `${dim("f")} follow ` +
519
+ `${dim("q")} quit`;
520
+ const w = visibleWidth(hint);
521
+ if (w >= innerWidth) return truncateToWidth(hint, innerWidth);
522
+ return hint + " ".repeat(innerWidth - w);
523
+ }
524
+
525
+ const viewer = this.currentViewer();
526
+ const streamFilter = viewer?.getStreamFilter() ?? "combined";
527
+ // Show stdout+stderr with only the active stream(s) highlighted.
528
+ const stdoutPart =
529
+ streamFilter === "combined" || streamFilter === "stdout"
530
+ ? accent("stdout")
531
+ : dim("stdout");
532
+ const stderrPart =
533
+ streamFilter === "combined" || streamFilter === "stderr"
534
+ ? accent("stderr")
535
+ : dim("stderr");
536
+ const streamIndicator = `${dim("s:")}${stdoutPart}${dim("+")}${stderrPart}`;
537
+
538
+ const footer =
539
+ `${dim("tab/shift+tab")} switch ` +
540
+ `${dim("g/G")} top/bot ` +
541
+ `${dim("j/k")} scroll ` +
542
+ `${dim("/")} search ` +
543
+ streamIndicator +
544
+ ` ${dim("f")} follow ` +
545
+ `${dim("q")} quit`;
546
+
547
+ const w = visibleWidth(footer);
548
+ if (w >= innerWidth) return truncateToWidth(footer, innerWidth);
549
+ return footer + " ".repeat(innerWidth - w);
550
+ }
551
+
552
+ invalidate(): void {
553
+ // No local cache.
554
+ }
555
+ }
@@ -4,7 +4,12 @@ import {
4
4
  renderPanelTitleLine,
5
5
  } from "@aliou/pi-utils-ui";
6
6
  import type { Theme } from "@mariozechner/pi-coding-agent";
7
- import { type Component, matchesKey } from "@mariozechner/pi-tui";
7
+ import {
8
+ type Component,
9
+ matchesKey,
10
+ truncateToWidth,
11
+ visibleWidth,
12
+ } from "@mariozechner/pi-tui";
8
13
  import type { ProcessInfo } from "../constants";
9
14
  import type { ProcessManager } from "../manager";
10
15
  import { statusIcon, statusLabel } from "./status-format";
@@ -111,7 +116,14 @@ export class ProcessPickerComponent implements Component {
111
116
  const dim = (s: string) => theme.fg("dim", s);
112
117
  const accent = (s: string) => theme.fg("accent", s);
113
118
 
114
- const padLine = createPanelPadder(width);
119
+ const innerWidth = width - 2;
120
+ const basePadLine = createPanelPadder(width);
121
+ const padLine = (content: string): string =>
122
+ basePadLine(
123
+ visibleWidth(content) > innerWidth
124
+ ? truncateToWidth(content, innerWidth)
125
+ : content,
126
+ );
115
127
 
116
128
  const lines: string[] = [];
117
129
  const processes = this.getProcesses();
@@ -4,7 +4,12 @@ import {
4
4
  renderPanelTitleLine,
5
5
  } from "@aliou/pi-utils-ui";
6
6
  import type { Theme } from "@mariozechner/pi-coding-agent";
7
- import { type Component, matchesKey, visibleWidth } from "@mariozechner/pi-tui";
7
+ import {
8
+ type Component,
9
+ matchesKey,
10
+ truncateToWidth,
11
+ visibleWidth,
12
+ } from "@mariozechner/pi-tui";
8
13
  import { configLoader } from "../config";
9
14
  import type { ProcessInfo } from "../constants";
10
15
  import type { ProcessManager } from "../manager";
@@ -214,7 +219,13 @@ export class ProcessesComponent implements Component {
214
219
  const processes = this.manager.list();
215
220
  const innerWidth = width - 2;
216
221
 
217
- const padLine = createPanelPadder(width);
222
+ const basePadLine = createPanelPadder(width);
223
+ const padLine = (content: string): string =>
224
+ basePadLine(
225
+ visibleWidth(content) > innerWidth
226
+ ? truncateToWidth(content, innerWidth)
227
+ : content,
228
+ );
218
229
 
219
230
  lines.push(renderPanelTitleLine("Background Processes", width, theme));
220
231
 
@@ -225,11 +236,18 @@ export class ProcessesComponent implements Component {
225
236
  lines.push(padLine(""));
226
237
  } else {
227
238
  const prefixWidth = 2;
228
- const idWidth = 9;
229
- const nameWidth = 15;
230
- const statusWidth = 18;
231
- const timeWidth = 8;
232
- const sizeWidth = 8;
239
+
240
+ // Responsive column widths based on available space
241
+ // Minimum widths: id=6, name=8, cmd=4, status=10, time=4, size=4 = ~40 chars minimum
242
+ const minTotalWidth = 40;
243
+ const scaleFactor =
244
+ innerWidth < minTotalWidth ? innerWidth / minTotalWidth : 1;
245
+
246
+ const idWidth = Math.max(6, Math.floor(9 * scaleFactor));
247
+ const nameWidth = Math.max(8, Math.floor(15 * scaleFactor));
248
+ const statusWidth = Math.max(10, Math.floor(18 * scaleFactor));
249
+ const timeWidth = Math.max(4, Math.floor(8 * scaleFactor));
250
+ const sizeWidth = Math.max(4, Math.floor(8 * scaleFactor));
233
251
 
234
252
  const hasProcessScroll = processes.length > maxVisibleProcesses;
235
253
  const headerSuffixText = hasProcessScroll
@@ -237,18 +255,16 @@ export class ProcessesComponent implements Component {
237
255
  : "";
238
256
  const headerSuffixLen = hasProcessScroll ? headerSuffixText.length : 0;
239
257
 
240
- // Reserve space for scroll suffix in the command column
241
- const cmdWidth = Math.max(
242
- 10,
243
- innerWidth -
244
- prefixWidth -
245
- idWidth -
246
- nameWidth -
247
- statusWidth -
248
- timeWidth -
249
- sizeWidth -
250
- headerSuffixLen,
251
- );
258
+ // Calculate command column width based on remaining space
259
+ const fixedWidth =
260
+ prefixWidth +
261
+ idWidth +
262
+ nameWidth +
263
+ statusWidth +
264
+ timeWidth +
265
+ sizeWidth +
266
+ headerSuffixLen;
267
+ const cmdWidth = Math.max(4, innerWidth - fixedWidth);
252
268
 
253
269
  lines.push(padLine(""));
254
270
  const header =
@@ -409,10 +425,14 @@ export class ProcessesComponent implements Component {
409
425
  const footerLeftLen = visibleWidth(footerLeft);
410
426
  const footerRightLen = visibleWidth(footerRight);
411
427
  const footerGap = Math.max(2, innerWidth - footerLeftLen - footerRightLen);
412
- const footer = footerLeft + " ".repeat(footerGap) + footerRight;
428
+ let footer = footerLeft + " ".repeat(footerGap) + footerRight;
429
+
430
+ // Truncate footer if it exceeds inner width (e.g., on very narrow terminals)
431
+ if (footerLeftLen + footerGap + footerRightLen > innerWidth) {
432
+ footer = truncateToWidth(footer, innerWidth);
433
+ }
413
434
 
414
435
  lines.push(padLine(footer));
415
- lines.push(renderPanelRule(width, theme));
416
436
 
417
437
  this.cachedLines = lines;
418
438
  this.cachedWidth = width;