pi-ext
bugabingas pi extensions
owned by bugabinga
use native Pi tool rendering in ultra transcript
a82f049aa8239cc0da2f2ed28833293f4760a0d6
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
Browse filesCompare with HEAD
Changed files (3)
extensions/ultra/index.ts
Modified217 217 onRunAbort: ()
=> controller.
abort(),
218 218 workflowName: spec.
name,
219 219 workflowDescription: spec.
description,
extensions/ultra/progress.ts
Modified 43 43 kind: ProgressKind;
47 + toolCallId
?: string;
118 125 toolName:
event.toolName,
126 + toolCallId:
event.toolCallId,
119 128 text:
previewArgs(
event.args),
126 135 toolName:
event.toolName,
136 + toolCallId:
event.toolCallId,
137 + result:
event.result,
138 + isError:
event.isError,
127 139 text:
previewResult(
event.result),
128 140 status:
event.isError
? "error" : undefined,
174 186 workflowDescription
?: string;
189 +export type TranscriptItem = 190 + | { kind
: "text"; text
: string }
194 + toolCallId
?: string;
177 201 export interface ReducerState extends ProgressMeta {
178 202 rows
: readonly AgentRow[];
180 204 transcripts
: Readonly<
Record<
string,
string>>;
205 + transcriptItems
: Readonly<
Record<
string,
readonly TranscriptItem[]>>;
182 207 phases
: readonly string[];
197 222 workflowDescription: meta.workflowDescription,
225 + transcriptItems: {},
201 227 phase:
undefined,
270 +function transcriptItem(event
: UltraProgressEvent)
: TranscriptItem | undefined {
271 + if (
event.kind
=== "delta")
return { kind:
"text", text:
event.
text ?? "" };
272 + if (
event.kind
!== "action" || !event.toolName)
return undefined;
273 + const fallback
= actionLabel(
event);
276 + toolName:
event.toolName,
277 + toolCallId:
event.toolCallId,
279 + result:
event.result,
280 + isError:
event.isError,
244 285 function nextRow(
245 286 prev
: AgentRow | undefined,
246 287 event
: UltraProgressEvent,
304 345 : state.transcripts;
347 + const item
= transcriptItem(
event);
348 + const transcriptItems
= item
350 + ...state.transcriptItems,
351 + [
event.agentId]: [
...(state.transcriptItems[
event.agentId]
?? []), item],
353 + : state.transcriptItems;
306 355 const phases
= state.phases.
includes(
event.phase)
308 357 : [
...state.phases,
event.phase];
319 368 workflowDescription: state.workflowDescription,
323 373 phase:
event.phase,
324 374 total: rows.
length,
extensions/ultra/ui.ts
Modified 21 21 ToolRenderResultOptions,
22 22 } from
"@earendil-works/pi-coding-agent";
23 -import { getMarkdownTheme, keyHint }
from "@earendil-works/pi-coding-agent";
26 + ToolExecutionComponent,
27 +}
from "@earendil-works/pi-coding-agent";
29 34 }
from "@earendil-works/pi-tui";
31 36 type AgentControls,
33 38 initialReducerState,
41 + type TranscriptItem,
36 42 type UltraProgressEvent,
37 43 } from
"./progress.ts";
228 234 throttleMs
?: number;
229 235 workflowName
?: string;
230 236 workflowDescription
?: string;
233 242 const DEFAULT_THROTTLE_MS
= 80;
238 247 return new Markdown(text,
0,
0,
getMarkdownTheme()).
render(
Math.
max(
1, width));
250 +function normalizeToolResult(item
: TranscriptItem & { kind
: "tool" }) {
251 + const r
= item.result as
252 + | { content
?: unknown; details
?: unknown; isError
?: boolean }
254 + const content
= Array.
isArray(r?.
content)
255 + ? (r.
content as Array<{ type
: string; text
?: string; data
?: string; mimeType
?: string }>)
257 + ? [{ type:
"text", text: item.fallback }]
261 + details: r?.details,
262 + isError: item.isError
?? r?.isError
?? false,
261 286 private readonly
onRunAbort: ()
=> void;
262 287 private readonly
now: ()
=> number;
263 288 private readonly
throttleMs: number;
289 + private readonly
toolUi: TUI
| undefined;
290 + private readonly
cwd: string
| undefined;
265 292 constructor(options: UltraOverlayOptions) {
266 293 this.state
= initialReducerState({
272 299 this.onRunAbort
= options.onRunAbort;
273 300 this.now
= options.now
?? Date.now;
274 301 this.throttleMs
= options.throttleMs
?? DEFAULT_THROTTLE_MS;
302 + this.toolUi
= options.toolUi;
303 + this.cwd
= options.cwd;
451 + private
transcriptBodyLines(agentId: string
| undefined, width: number): string[] {
452 + if (
!agentId)
return [];
453 + const items
= this.state.transcriptItems[agentId];
454 + if (
!items
|| items.
length === 0) {
455 + return transcriptLines(this.state.transcripts[agentId]
?? "", width);
457 + const lines
: string[]
= [];
459 + const flushText = ()
=> {
461 + lines.
push(
...transcriptLines(text, width));
464 + for (
const item
of items) {
465 + if (item.kind
=== "text") {
470 + if (this.toolUi
&& this.cwd) {
471 + const tool
= new ToolExecutionComponent(
473 + item.toolCallId
?? `${agentId}-${lines.length}`,
480 + tool.
markExecutionStarted();
481 + tool.
setArgsComplete();
482 + if (item.result
!== undefined) tool.
updateResult(
normalizeToolResult(item));
483 + lines.
push(
...tool.
render(width));
484 + }
else if (item.fallback) {
485 + lines.
push(
...transcriptLines(
`> ${item.fallback}`, width));
424 494 render(width: number): string[] {
466 - const transcript
= focusedRow
467 - ? (state.transcripts[focusedRow.agentId]
?? "")
469 - const body
= transcriptLines(transcript, w
- 2);
536 + const body
= this.
transcriptBodyLines(focusedRow?.agentId, w
- 2);
472 539 const maxVisible
= Math.
max(
0, maxLines
- lines.
length - 1);