pi-ext bugabingas pi extensions
owned by bugabinga
README Source History Refs Reviews Compare Notes Search Review guide CI runs feat(ultra): expand agent metadata rows
df437242cb67c43669de2693b6a7d86da6d98426
Oliver Jan Krylow <oliver@bugabinga.net > · 12 Jul 2026
unsigned
Browse files Compare with HEAD
Changed files (7) Diff layout Auto Unified Split
extensions/ultra/README.md Modified +3 / −0 text lines
65 65 If a run is aborted, the next run of the same workflow name, cwd, and args reuses completed matching steps and runs the missing/changed steps.If a run is aborted, the next run of the same workflow name, cwd, and args reuses completed matching steps and runs the missing/changed steps.66 66 A completed run marks its journal complete, so later runs start fresh.A completed run marks its journal complete, so later runs start fresh.
68 + Expanded workflow tool output renders each sub-agent as a multiline block: identity/status, resolved model metadata, elapsed time and reported tokens, then latest action.69 + Configured tiers are shown as `tier → provider/model`; collapsed output remains summary-only.68 71 Workflow results include aggregate token and cost usage from completed sub-agent turns when the provider reports it.Workflow results include aggregate token and cost usage from completed sub-agent turns when the provider reports it.69 72 The final JSON contains `tokenUsage` with `input`, `output`, `total`, `cacheRead`, `cacheWrite`, and `cost`.The final JSON contains `tokenUsage` with `input`, `output`, `total`, `cacheRead`, `cacheWrite`, and `cost`.extensions/ultra/__tests__/progress.test.ts Modified +32 / −0 text lines
267 267 expect (s.phase).toBe ("verify" ); expect (s.phase).toBe ("verify" );
270 + it ("retains model, timing, and usage metadata across later events" , () => {285 + model: "openai/gpt-5-mini" ,286 + thinkingLevel: "low" ,289 + pe ({ agentId: "a" , phase: "p1" , kind: "delta" , text: "x" }),290 + pe ({ agentId: "a" , phase: "p1" , kind: "end" , status: "done" , usage }),293 + expect (s.rows [0 ]).toMatchObject ({295 + model: "openai/gpt-5-mini" ,296 + thinkingLevel: "low" ,270 302 it ("binds per-agent controls from the event onto the row" , () => { it ("binds per-agent controls from the event onto the row" , () => {271 303 const controls: AgentControls = { steer: vi.fn (), abort: vi.fn () }; const controls: AgentControls = { steer: vi.fn (), abort: vi.fn () };272 304 const s = fold ([ const s = fold ([extensions/ultra/__tests__/runner.test.ts Modified +25 / −4 text lines
417 417 expect (result.reason).toBe ("completion failed: socket hang up" ); expect (result.reason).toBe ("completion failed: socket hang up" );420 - it ("emits coarse start/end with no-op controls" , async () => {420 + it ("emits coarse start/end with model metadata, usage, and no-op controls" , async () => {427 + cost: { total: 0.1 },421 429 const completeFn = vi.fn ( const completeFn = vi.fn (422 - async (): Promise <CompleteResponse > => ({ text : ' { "verdict": "ok" } ' } ) , 430 + async (): Promise <CompleteResponse > => ({431 + text: '{ "verdict": "ok" }' ,424 435 const drivers = makeDrivers ({ completeFn }); const drivers = makeDrivers ({ completeFn });425 436 const events: UltraProgressEvent [] = []; const events: UltraProgressEvent [] = [];427 438 const result = await runStep ( const result = await runStep (439 + { ... toollessStep, model: "small" },429 440 makeCtx (), makeCtx (),431 - baseOpts ( { onProgress : (e) => events.push (e) } ) ,443 + modelTiers: { small: "openai/gpt-5-mini:low" },444 + onProgress : (e) => events.push (e),434 448 expect (result.ok).toBe (true ); expect (result.ok).toBe (true );435 449 expect (events.map ((e) => e.kind)).toEqual (["start" , "end" ]); expect (events.map ((e) => e.kind)).toEqual (["start" , "end" ]);
450 + expect (events[0 ]).toMatchObject ({452 + model: "openai/gpt-5-mini" ,453 + thinkingLevel: "low" ,454 + startedAt: expect.any (Number ),456 + expect (events[1 ].usage).toEqual (result.usage);436 457 for (const e of events) { for (const e of events) {437 458 expect (e.agentId).toBe ("review#0" ); expect (e.agentId).toBe ("review#0" );438 459 expect (e.phase).toBe ("review" ); expect (e.phase).toBe ("review" );extensions/ultra/__tests__/ui.test.ts Modified +45 / −0 text lines
173 173 expect (out).not.toContain ("SECRET-TRANSCRIPT-BODY" ); expect (out).not.toContain ("SECRET-TRANSCRIPT-BODY" );
176 + it ("expanded: renders each agent as identity plus model, usage, and action lines" , () => {177 + const s = stateFrom ([183 + model: "openai/gpt-5-mini" ,184 + thinkingLevel: "low" ,185 + startedAt: Date .now () - 18_000 ,192 + text: "docs/phase-1.html" ,209 + const lines = renderTool (s, { expanded: true , isPartial: false }, 100 );210 + const out = lines.join ("\n" );212 + expect (out).toContain ("plan#0 · done" );213 + expect (out).toContain ("├ model" );214 + expect (out).toContain ("small → openai/gpt-5-mini · low" );215 + expect (out).toContain ("├ usage" );216 + expect (out).toContain ("2.1k tokens" );217 + expect (out).toContain ("└ action" );218 + expect (out).toContain ("read docs/phase-1.html" );176 221 it ("never emits bodies when expanded=false (sentinels absent collapsed, present expanded)" , () => { it ("never emits bodies when expanded=false (sentinels absent collapsed, present expanded)" , () => {177 222 const collapsed = toolText (scripted, { expanded: false , isPartial: false }); const collapsed = toolText (scripted, { expanded: false , isPartial: false });178 223 const expanded = toolText (scripted, { expanded: true , isPartial: false }); const expanded = toolText (scripted, { expanded: true , isPartial: false });extensions/ultra/progress.ts Modified +19 / −0 text lines
13 13 import type { AgentSessionEvent } from "@earendil-works/pi-coding-agent" ;import type { AgentSessionEvent } from "@earendil-works/pi-coding-agent" ;
14 + import type { TokenUsage } from "./runner.ts" ;15 + import type { ThinkingLevel } from "./spec.ts" ;54 56 text?: string; text?: string;56 58 status?: string; status?: string;
63 + thinkingLevel?: ThinkingLevel;58 67 controls?: AgentControls; controls?: AgentControls;222 231 status : AgentStatus; status : AgentStatus;224 233 action : string; action : string;
236 + thinkingLevel?: ThinkingLevel;226 240 controls?: AgentControls; controls?: AgentControls;371 385 phase : event .phase, phase : event .phase,
388 + tier : event .tier ?? base.tier,389 + model : event .model ?? base.model,390 + thinkingLevel : event .thinkingLevel ?? base.thinkingLevel,391 + startedAt : event .startedAt ?? base.startedAt,392 + usage : event .usage ?? base.usage,374 393 controls : event .controls ?? base.controls, controls : event .controls ?? base.controls,extensions/ultra/runner.ts Modified +52 / −5 text lines
251 251 return { model: match[1 ], thinkingLevel: match[2 ] as ThinkingLevel }; return { model: match[1 ], thinkingLevel: match[2 ] as ThinkingLevel };
254 + function requestedTier (step: Step ): string | undefined {255 + return step.model && isModelTierName (step.model) ? step.model : undefined ;260 + fallback: string | undefined ,261 + ): string | undefined {262 + if (model && typeof model === "object" ) {263 + const value = model as { provider?: unknown ; id?: unknown };264 + if (typeof value.provider === "string" && typeof value.id === "string" )265 + return `${value.provider}/${value. id }` ;266 + if (typeof value.id === "string" ) return fallback ?? value.id ;254 271 function resolveModelTier (step: Step , tiers: ModelTiers | undefined ): Step {function resolveModelTier (step: Step , tiers: ModelTiers | undefined ): Step {255 272 if (! step.model || ! isModelTierName (step.model)) return step; if (! step.model || ! isModelTierName (step.model)) return step;256 273 const tier = tiers?.[step.model]; const tier = tiers?.[step.model];410 427 drivers : StepDrivers, drivers : StepDrivers,411 428 opts : RunStepOptions, opts : RunStepOptions,412 429 ): Promise < RunStepResult> {): Promise < RunStepResult> {
430 + const tier = requestedTier (step);413 431 const resolvedStep = resolveModelTier (step, opts.modelTiers); const resolvedStep = resolveModelTier (step, opts.modelTiers);414 432 const schemaObj = resolveStepSchema (resolvedStep, opts); const schemaObj = resolveStepSchema (resolvedStep, opts);415 433 const validator = schemaObj const validator = schemaObj428 446 schemaObj, schemaObj,429 447 validator, validator,430 448 timeoutMs, timeoutMs,432 - : runCompleteStep (resolvedStep, drivers, opts, validator, timeoutMs);451 + : runCompleteStep (resolvedStep, drivers, opts, validator, timeoutMs, tier );440 459 opts : RunStepOptions, opts : RunStepOptions,441 460 validator : CompiledValidator | undefined , validator : CompiledValidator | undefined ,442 461 timeoutMs : number, timeoutMs : number,
462 + tier : string | undefined ,443 463 ): Promise < RunStepResult> {): Promise < RunStepResult> {444 - emitCompleteStart (opts);464 + const startedAt = Date .now ();446 465 const model = drivers.resolveModel (step.model); const model = drivers.resolveModel (step.model);
466 + emitCompleteStart (opts, {468 + model: modelLabel(model, step.model),469 + thinkingLevel: step.thinkingLevel,447 472 const auth = await drivers.resolveAuth (model); const auth = await drivers.resolveAuth (model);448 473 if (!auth.ok) { if (!auth.ok) {449 474 return finishComplete (opts, { return finishComplete (opts, {478 503 return finishComplete (opts, { ok: false , value: null , reason: lastReason }); return finishComplete (opts, { ok: false , value: null , reason: lastReason });481 - function emitCompleteStart (opts: RunStepOptions ): void {506 + function emitCompleteStart (507 + opts: RunStepOptions ,510 + "tier" | "model" | "thinkingLevel" | "startedAt" 482 513 opts.onProgress ?.({ opts.onProgress ?.({483 514 agentId: opts.agentId, agentId: opts.agentId,484 515 phase: opts.phase, phase: opts.phase,485 516 kind: "start" , kind: "start" ,486 518 controls: NOOP_CONTROLS, controls: NOOP_CONTROLS,498 530 kind : "end" , kind : "end" ,499 531 status : result.ok ? "done" : "dropped" , status : result.ok ? "done" : "dropped" ,500 532 text : result.ok ? undefined : result.reason, text : result.ok ? undefined : result.reason,
533 + usage : result.usage,501 534 controls : NOOP_CONTROLS, controls : NOOP_CONTROLS,503 536 return result; return result;622 655 schemaObj : object | undefined , schemaObj : object | undefined ,623 656 validator : CompiledValidator | undefined , validator : CompiledValidator | undefined ,624 657 timeoutMs : number, timeoutMs : number,
658 + tier : string | undefined ,625 659 ): Promise < RunStepResult> {): Promise < RunStepResult> {626 660 const { agentId, phase, onProgress } = opts; const { agentId, phase, onProgress } = opts;
661 + const startedAt = Date .now ();627 662 const model = drivers.resolveModel (step.model); const model = drivers.resolveModel (step.model);
665 + model: modelLabel (model, step.model),666 + thinkingLevel: step.thinkingLevel,683 724 usage = lastAssistantUsage ((event as { messages?: unknown }).messages); usage = lastAssistantUsage ((event as { messages?: unknown }).messages);685 726 const mapped = mapSessionEvent (event , agentId, phase); const mapped = mapSessionEvent (event , agentId, phase);686 - if (mapped) onProgress ?.({ ... mapped, controls });731 + usage: mapped.kind === "end" ? usage : undefined ,689 736 const guarded = await raceGuards ( const guarded = await raceGuards (extensions/ultra/ui.ts Modified +42 / −8 text lines
87 87 return state.workflowDescription; return state.workflowDescription;
90 + function compactTokens (tokens: number ): string {91 + if (tokens < 1000 ) return String (tokens);92 + const value = tokens / 1000 ;93 + return `${value >= 10 ? Math . round (value) : value. toFixed (1). replace (/\.0 $ /, "")}k` ;96 + function elapsed (startedAt: number ): string {97 + const seconds = Math .max (0 , Math .floor ((Date .now () - startedAt) / 1000 ));98 + if (seconds < 60 ) return `${seconds}s` ;99 + return `${ Math . floor (seconds / 60)}m ${seconds % 60}s` ;102 + function agentDetailLines (row: ReducerState ["rows" ][number ]): string [] {103 + const details: { label: string ; value: string }[] = [];104 + const model = row.tier105 + ? `${row.tier}${row.model ? ` → ${row.model}` : ""}` 107 + const modelValue = [model, row.thinkingLevel].filter (Boolean ).join (" · " );108 + if (modelValue) details.push ({ label: "model" , value: modelValue });109 + const usageValue = [110 + row.startedAt === undefined ? undefined : elapsed (row.startedAt),111 + row.usage ? `${ compactTokens (row.usage.total)} tokens` : undefined ,115 + if (usageValue) details.push ({ label: "usage" , value: usageValue });116 + if (row.action ) details.push ({ label: "action" , value: row.action });119 + `${index === details. length - 1 ? "└" : "├"} ${detail. label . padEnd (6)} ${detail. value }` ,90 123 function divider (label: string , width: number ): string {function divider (label: string , width: number ): string {91 124 const w = Math .max (1 , width); const w = Math .max (1 , width);92 125 const text = ` ${label} ` ; const text = ` ${label} ` ;119 152 function renderToolBoard (function renderToolBoard (136 169 return lines.map ((l) => fitLine (l, w)); return lines.map ((l) => fitLine (l, w));142 173 for (const row of state.rows ) { for (const row of state.rows ) {143 174 const icon = STATUS_ICON[row.status ]; const icon = STATUS_ICON[row.status ];144 - let line = `${icon} ${row.agentId} · ${row. status }` ;145 - if (row.action ) line += ` · ${row. action }` ;146 - lines.push (theme.fg ("dim " , fitLine (line , w)));176 + theme.fg ("dim" , fitLine (`${icon} ${row.agentId} · ${row. status }` , w)),178 + for (const detail of agentDetailLines (row)) {179 + lines.push (theme.fg ("muted " , fitLine (` ${ detail } ` , w)));149 183 return lines.map ((l) => fitLine (l, w)); return lines.map ((l) => fitLine (l, w));