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
Modified147 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", ()
=> {
157 + args: { command:
"git status --short\nsecond line" },
158 + text:
JSON.
stringify({ command:
"git status --short" }),
165 + result: { content: [{ type:
"text", text:
"RAW RESULT" }] },
166 + text:
"RAW RESULT",
170 + expect(s.
rows[
0].
action).
toContain(
"bash $ git status --short");
171 + expect(s.
rows[
0].
action).not.
toContain(
"RAW RESULT");
150 174 it(
"folds a scripted stream into one upserted row + transcript", ()
=> {
152 176 pe({ agentId:
"a", phase:
"p1", kind:
"start" }),
extensions/ultra/__tests__/ui.test.ts
Modified 27 29 pageDown:
"\x1b[6~",
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);
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` }),
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");
324 354 it(
"follow-mode pins to the newest line until the user scrolls, then re-pins", ()
=> {
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);
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);
98 + const command
= firstLine(args.command);
99 + return command
? `$ ${cap(command)}` : previewArgs(args);
103 + return firstLine(args.path)
?? previewArgs(args);
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);
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);
117 + return previewArgs(args);
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;
299 334 status
= "running";
302 - action
= actionLabel(
event)
|| action;
337 + if (
event.result
=== undefined || event.isError) action
= actionLabel(
event)
|| action;
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)}`;
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")) {
360 + matchesKey(data,
"pageUp")
|| 361 + matchesKey(data,
"alt+up")
|| 362 + matchesKey(data,
"ctrl+u")
351 364 this.
scrollBy(
-10);
352 - }
else if (
matchesKey(data,
"pageDown")
|| matchesKey(data,
"ctrl+d")) {
366 + matchesKey(data,
"pageDown")
|| 367 + matchesKey(data,
"alt+down")
|| 368 + matchesKey(data,
"ctrl+d")
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();
532 - fit(
`transcript: ${focusedRow ? focusedRow.agentId : "—"}`, w),
547 + divider(
`transcript: ${focusedRow ? focusedRow.agentId : "—"}`, w),
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`,