repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

polish ultra overlay transcript controls

bd79240074ca8beea0cbadc081dcb44ee01cd25b

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (4)

extensions/ultra/__tests__/progress.test.ts

Modified
147 147 expect(s).toMatchObject({ total: 0, done: 0, dropped: 0 });
150 + it("formats tool call rows from structured args and does not replace them with raw results", () => {
151 + const s = fold([
152 + pe({
153 + agentId: "a",
154 + phase: "p1",
155 + kind: "action",
156 + toolName: "bash",
157 + args: { command: "git status --short\nsecond line" },
158 + text: JSON.stringify({ command: "git status --short" }),
159 + }),
160 + pe({
161 + agentId: "a",
162 + phase: "p1",
163 + kind: "action",
164 + toolName: "bash",
165 + result: { content: [{ type: "text", text: "RAW RESULT" }] },
166 + text: "RAW RESULT",
167 + }),
168 + ]);
170 + expect(s.rows[0].action).toContain("bash $ git status --short");
171 + expect(s.rows[0].action).not.toContain("RAW RESULT");
172 + });
150 174 it("folds a scripted stream into one upserted row + transcript", () => {
151 175 const s = fold([
152 176 pe({ agentId: "a", phase: "p1", kind: "start" }),

extensions/ultra/__tests__/ui.test.ts

Modified
23 23 tab: "\t",
24 24 up: "\x1b[A",
25 25 down: "\x1b[B",
26 + altUp: "\x1bp",
27 + altDown: "\x1bn",
26 28 pageUp: "\x1b[5~",
27 29 pageDown: "\x1b[6~",
28 30 enter: "\r",
307 309 pe({ agentId: "a7", phase: "p", kind: "delta", text: `L${i}\n` }),
310 - expect(overlay.render(60)).toHaveLength(9);
312 + expect(overlay.render(60).length).toBeLessThanOrEqual(9);
313 315 it("renders transcript markdown with Pi's markdown renderer", () => {
321 323 expect(out).not.toContain("**bold**");
326 + it("renders transcript title as a compact divider header", () => {
327 + const { overlay } = makeOverlay({ rows: 16 });
328 + overlay.handleProgress(pe({ agentId: "a", phase: "p", kind: "start" }));
329 + const lines = overlay.render(50);
330 + const header = lines.find((l) => l.includes("transcript: a"));
331 + expect(header).toBeDefined();
332 + expect(header).toMatch(/─.*transcript: a.*─/);
333 + expect(lines.some((l) => l === "transcript: a")).toBe(false);
334 + });
336 + it("Alt+Up/Alt+Down scroll transcript when PageUp/PageDown is intercepted by the terminal", () => {
337 + const { overlay } = makeOverlay({ rows: 12 });
338 + overlay.handleProgress(pe({ agentId: "a", phase: "p", kind: "start" }));
339 + for (let i = 0; i < 10; i++) {
340 + overlay.handleProgress(
341 + pe({ agentId: "a", phase: "p", kind: "delta", text: `L${i}\n` }),
342 + );
344 + expect(overlay.render(40).join("\n")).toContain("L9");
345 + overlay.handleInput(K.altUp);
346 + let out = overlay.render(40).join("\n");
347 + expect(out).toContain("L0");
348 + expect(out).not.toContain("L9");
349 + overlay.handleInput(K.altDown);
350 + out = overlay.render(40).join("\n");
351 + expect(out).toContain("L9");
352 + });
324 354 it("follow-mode pins to the newest line until the user scrolls, then re-pins", () => {
325 355 // rows=12 with a 3-row safety margin leaves room for a transcript tail.
326 356 const { overlay } = makeOverlay({ rows: 12 });

extensions/ultra/progress.ts

Modified
77 77 return text.length > MAX_PREVIEW ? `${text.slice(0, MAX_PREVIEW)}…` : text;
80 +function isRecord(value: unknown): value is Record<string, unknown> {
81 + return typeof value === "object" && value !== null && !Array.isArray(value);
80 84 /** Short preview of a tool call's args for the board/transcript. */
81 85 function previewArgs(args: unknown): string {
82 86 if (args === undefined || args === null) return "";
83 87 return cap(stringify(args));
90 +function firstLine(value: unknown): string | undefined {
91 + return typeof value === "string" ? value.split("\n")[0]?.trim() : undefined;
94 +function conciseArgs(toolName: string | undefined, args: unknown): string {
95 + if (!toolName || !isRecord(args)) return previewArgs(args);
96 + switch (toolName) {
97 + case "bash": {
98 + const command = firstLine(args.command);
99 + return command ? `$ ${cap(command)}` : previewArgs(args);
101 + case "read":
102 + case "ls":
103 + return firstLine(args.path) ?? previewArgs(args);
104 + case "grep": {
105 + const pattern = firstLine(args.pattern);
106 + const path = firstLine(args.path);
107 + if (pattern && path) return `${pattern} in ${path}`;
108 + return pattern ?? path ?? previewArgs(args);
110 + case "find": {
111 + const pattern = firstLine(args.pattern);
112 + const path = firstLine(args.path);
113 + if (pattern && path) return `${pattern} in ${path}`;
114 + return pattern ?? path ?? previewArgs(args);
116 + default:
117 + return previewArgs(args);
87 122 * Short preview of a tool result. Prefers `result.details` — the validated
88 123 * structured-output payload path (P1) — falling back to `result.content`, then
248 283 /** The coarse board label for an `action` event. */
249 284 function actionLabel(event: UltraProgressEvent): string {
250 - const text = event.text ?? "";
285 + const text = event.args !== undefined ? conciseArgs(event.toolName, event.args) : event.text ?? "";
251 286 if (event.toolName)
252 287 return text ? `${event.toolName} ${text}` : event.toolName;
253 288 return text;
299 334 status = "running";
300 335 break;
301 336 case "action":
302 - action = actionLabel(event) || action;
337 + if (event.result === undefined || event.isError) action = actionLabel(event) || action;
303 338 break;
304 339 case "delta":
305 340 // Token deltas feed the transcript, not the board's latest-action line.

extensions/ultra/ui.ts

Modified
87 87 return state.workflowDescription;
90 +function divider(label: string, width: number): string {
91 + const w = Math.max(1, width);
92 + const text = ` ${label} `;
93 + if (text.length >= w) return fit(label, w);
94 + const left = Math.floor((w - text.length) / 2);
95 + const right = w - text.length - left;
96 + return `${"─".repeat(left)}${text}${"─".repeat(right)}`;
90 99 /** The collapsed expand hint. Guarded: `keyHint` needs an initialised theme. */
91 100 function expandHint(): string {
347 356 this.focusBy(1, false);
348 357 } else if (matchesKey(data, "up")) {
349 358 this.focusBy(-1, false);
350 - } else if (matchesKey(data, "pageUp") || matchesKey(data, "ctrl+u")) {
359 + } else if (
360 + matchesKey(data, "pageUp") ||
361 + matchesKey(data, "alt+up") ||
362 + matchesKey(data, "ctrl+u")
363 + ) {
351 364 this.scrollBy(-10);
352 - } else if (matchesKey(data, "pageDown") || matchesKey(data, "ctrl+d")) {
365 + } else if (
366 + matchesKey(data, "pageDown") ||
367 + matchesKey(data, "alt+down") ||
368 + matchesKey(data, "ctrl+d")
369 + ) {
353 370 this.scrollBy(10);
354 371 } else if (data === "s") {
355 372 this.openSteer();
523 540 lines.push(this.theme.fg(focused ? "accent" : "dim", fit(line, w)));
526 - lines.push(this.theme.fg("border", fit("─".repeat(w), w)));
528 543 const focusedRow = this.focusedRow();
529 544 lines.push(
530 545 this.theme.fg(
531 - "muted",
532 - fit(`transcript: ${focusedRow ? focusedRow.agentId : "—"}`, w),
546 + "border",
547 + divider(`transcript: ${focusedRow ? focusedRow.agentId : "—"}`, w),
563 578 this.theme.fg(
564 579 "dim",
566 - `Tab/↑↓ focus · PgUp/PgDn scroll (${follow}) · s steer · x abort · Esc quit`,
581 + `Tab/↑↓ focus · Alt+↑/↓ scroll (${follow}) · s steer · x abort · Esc quit`,