pi-ext bugabingas pi extensions
owned by bugabinga
README Source History Refs Compare Notes Search feat(ultra): show planned workflow agents
d166551b06f4ba0babc1fd00ccb9ed955000e4af
Oliver Jan Krylow <oliver@bugabinga.net > · 13 Jul 2026
unsigned
Browse files Compare with HEAD
Changed files (10) extensions/ultra/README.md Modified 70 70 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.
71 71 A completed run marks its journal complete, so later runs start fresh.
73 - 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.
74 - Configured tiers are shown as `tier → provider/model`; collapsed output remains summary-only.
73 + Expanded workflow tool output renders every phase from the start and each known sub-agent as a multiline block.
74 + Known agents appear queued before launch; dynamic fan-outs show `agents not planned yet`; conditional phases show `conditional` until their selectors resolve.
75 + Rows then transition through queued, running, done, dropped, or skipped without disappearing.
76 + Verified Nerd Font icons reinforce each state while text labels preserve meaning without glyph support.
77 + Configured tiers are shown as `tier → provider/model`; collapsed output remains counts-only.
76 79 Workflow results include aggregate token and cost usage from completed sub-agent turns when the provider reports it.
77 80 The final JSON contains `tokenUsage` with `input`, `output`, `total`, `cacheRead`, `cacheWrite`, and `cost`.
extensions/ultra/__tests__/engine.test.ts Modified 135 + describe (
"runWorkflow — planned progress" , ()
=> {
136 + it (
"publishes every phase before agents launch and resolves exact agent ids" ,
async ()
=> {
137 + const events
: UltraProgressEvent []
= [];
138 + const fr
= fakeRunner ((args)
=> {
139 + args.
onProgress ?.({
140 + agentId: args.agentId,
144 + return { ok:
true , value: args.item
?? "one-result" };
148 + { id:
"one" , kind:
"single" , step: { prompt:
"one" } },
153 + step: { prompt:
"{item}" },
158 + over:
"{one.results}" ,
159 + step: { prompt:
"{item}" },
164 + when:
"{args.enabled}" ,
165 + step: { prompt:
"conditional" },
172 + { enabled:
false },
174 + stepRunner: fr.runner,
175 + onProgress : (event)
=> events.
push (
event ),
179 + expect (events[
0 ]).
toEqual ({
182 + { phase:
"one" , status:
"resolved" , agentIds: [
"one#0" ] },
185 + status:
"resolved" ,
186 + agentIds: [
"literal#0" ,
"literal#1" ],
188 + { phase:
"dynamic" , status:
"agents-pending" , agentIds: [] },
190 + phase:
"conditional" ,
191 + status:
"condition-pending" ,
196 + for (
const phase
of [
"one" ,
"literal" ,
"dynamic" ]) {
197 + const resolved
= events.
findIndex (
199 + event .kind
=== "phase" && 200 + event .phase
=== phase
&& 201 + event .
status === "resolved" ,
203 + const started
= events.
findIndex (
204 + (event)
=> event .kind
=== "start" && event .phase
=== phase,
206 + expect (resolved).
toBeGreaterThan (
0 );
207 + expect (started).
toBeGreaterThan (resolved);
208 + expect (events).
toContainEqual (
209 + expect.
objectContaining ({ kind:
"phase" , phase, status:
"done" }),
212 + expect (events).
toContainEqual ({
214 + phase:
"conditional" ,
220 + (event)
=> event .kind
=== "start" && event .phase
=== "conditional" ,
225 + it (
"publishes resolved and done transitions for an empty fanout" ,
async ()
=> {
226 + const events
: UltraProgressEvent []
= [];
230 + { id:
"empty" , kind:
"fanout" , over: [], step: { prompt:
"x" } },
235 + stepRunner:
fakeRunner (()
=> ({ ok:
true , value:
1 })).runner,
236 + onProgress : (event)
=> events.
push (
event ),
240 + expect (events).
toContainEqual ({
243 + status:
"resolved" ,
246 + expect (events).
toContainEqual ({
174 298 it (
"runs a phase when its selector resolves to a non-empty value" ,
async ()
=> {
299 + const events
: UltraProgressEvent []
= [];
175 300 const fr
= fakeRunner (()
=> ({ ok:
true , value:
"ran" }));
187 312 const res
= await runWorkflow (
189 314 { enabled:
true },
190 - baseDeps ({ stepRunner: fr.runner }),
316 + stepRunner: fr.runner,
317 + onProgress : (event)
=> events.
push (
event ),
193 321 expect (fr.calls).
toHaveLength (
1 );
322 + expect (events[
0 ]).
toEqual ({
326 + phase:
"conditional" ,
327 + status:
"condition-pending" ,
332 + expect (events).
toContainEqual ({
334 + phase:
"conditional" ,
335 + status:
"resolved" ,
336 + agentIds: [
"conditional#0" ],
338 + expect (events).
toContainEqual ({
340 + phase:
"conditional" ,
342 + agentIds: [
"conditional#0" ],
194 344 expect (res.phases[
0 ]).
toEqual ({
195 345 id:
"conditional" ,
541 691 describe (
"runWorkflow — abort" , ()
=> {
542 - it (
"aborting mid-phase stops the pool, surfaces partial counts, and emits no end for un-launched agents" ,
async ()
=> {
692 + it (
"aborting mid-phase stops the pool, surfaces partial counts, and drops un-launched agents" ,
async ()
=> {
543 693 const controller
= new AbortController ();
544 694 const events
: UltraProgressEvent []
= [];
545 695 const fr
= fakeRunner (
async (args)
=> {
572 722 expect (res.phases[
0 ].ran).
toBe (
2 );
573 723 expect (res.phases[
0 ].ok).
toBe (
2 );
574 724 expect (res.phases[
0 ].dropped).
toBe (
4 );
576 - const endIds
= events.
filter ((e)
=> e.kind
=== "end" ).
map ((e)
=> e.agentId);
577 - expect (endIds).not.
toContain (
"f#2" );
578 - expect (endIds).not.
toContain (
"f#5" );
725 + const endIds
= events
726 + .
filter ((event)
=> event .kind
=== "end" )
727 + .
map ((event)
=> event .agentId);
728 + expect (endIds).
toContain (
"f#2" );
729 + expect (endIds).
toContain (
"f#5" );
581 732 it (
"a pre-aborted signal launches no steps and reports every item dropped" ,
async ()
=> {
extensions/ultra/__tests__/progress.test.ts Modified 144 144 expect (s.transcripts).
toEqual ({});
145 145 expect (s.phases).
toEqual ([]);
146 146 expect (s.phase).
toBeUndefined ();
147 - expect (s).
toMatchObject ({ total:
0 , done:
0 , dropped:
0 });
147 + expect (s).
toMatchObject ({
157 + it (
"seeds queued agents and pending phases from a workflow plan" , ()
=> {
158 + const s
= reduceProgress (
initialReducerState (), {
163 + status:
"resolved" ,
164 + agentIds: [
"research#0" ],
166 + { phase:
"verify" , status:
"agents-pending" , agentIds: [] },
169 + status:
"condition-pending" ,
173 + }
as unknown as UltraProgressEvent );
175 + expect (s.phases.
map ((phase)
=> phase.phase)).
toEqual ([
180 + expect (s.
rows ).
toEqual ([
181 + expect.
objectContaining ({
182 + agentId:
"research#0" ,
186 + expect (s.phase).
toBeUndefined ();
187 + expect (s).
toMatchObject ({
197 + it (
"resolves pending agents before start and transitions queued to running" , ()
=> {
198 + const planned
= reduceProgress (
initialReducerState (), {
200 + phases: [{ phase:
"verify" , status:
"agents-pending" , agentIds: [] }],
201 + }
as unknown as UltraProgressEvent );
202 + const resolved
= reduceProgress (planned, {
205 + status:
"resolved" ,
206 + agentIds: [
"verify#0" ,
"verify#1" ],
207 + }
as unknown as UltraProgressEvent );
209 + expect (resolved.
rows .
map ((row)
=> row.
status )).
toEqual ([
213 + expect (resolved).
toMatchObject ({ queued:
2 , running:
0 , later:
0 });
214 + const running
= reduceProgress (
216 + pe ({ agentId:
"verify#0" , phase:
"verify" , kind:
"start" }),
218 + expect (running.
rows .
map ((row)
=> row.
status )).
toEqual ([
222 + expect (running).
toMatchObject ({ queued:
1 , running:
1 , later:
0 });
225 + it (
"removes provisional agent rows when a phase is skipped" , ()
=> {
226 + const planned
= reduceProgress (
initialReducerState (), {
229 + { phase:
"publish" , status:
"resolved" , agentIds: [
"publish#0" ] },
231 + }
as unknown as UltraProgressEvent );
232 + const skipped
= reduceProgress (planned, {
237 + }
as unknown as UltraProgressEvent );
239 + expect (skipped.
rows ).
toEqual ([]);
240 + expect (skipped.phases[
0 ]).
toMatchObject ({
244 + expect (skipped).
toMatchObject ({ total:
0 , queued:
0 , later:
0 });
150 247 it (
"formats tool call rows from structured args and does not replace them with raw results" , ()
=> {
220 317 expect (s.transcripts.a).
toContain (
"hello world" );
221 318 expect (s.transcripts.a).
toContain (
"read" );
222 319 expect (s).
toMatchObject ({ total:
1 , done:
1 , dropped:
0 });
223 - expect (s.phases).
toEqual ([
"p1" ]);
320 + expect (s.phases.
map ((phase)
=> phase.phase)).
toEqual ([
"p1" ]);
224 321 expect (s.phase).
toBe (
"p1" );
263 360 pe ({ agentId:
"a" , phase:
"review" , kind:
"end" , status:
"done" }),
264 361 pe ({ agentId:
"v0" , phase:
"verify" , kind:
"start" }),
266 - expect (s.phases).
toEqual ([
"review" ,
"verify" ]);
363 + expect (s.phases.
map ((phase)
=> phase.phase)).
toEqual ([
"review" ,
"verify" ]);
267 364 expect (s.phase).
toBe (
"verify" );
extensions/ultra/__tests__/ui.test.ts Modified 104 104 expect (out).
toContain (
"Review the diff from every angle." );
107 + it (
"renders the complete icon-led planned-work vocabulary in phase order" , ()
=> {
108 + const s
= stateFrom ([
112 + { phase:
"done" , status:
"resolved" , agentIds: [
"done#0" ] },
113 + { phase:
"active" , status:
"resolved" , agentIds: [
"active#0" ] },
114 + { phase:
"queued" , status:
"resolved" , agentIds: [
"queued#0" ] },
115 + { phase:
"verify" , status:
"agents-pending" , agentIds: [] },
118 + status:
"condition-pending" ,
121 + { phase:
"skip" , status:
"skipped" , agentIds: [] },
122 + { phase:
"failed" , status:
"resolved" , agentIds: [
"failed#0" ] },
124 + }
as unknown as UltraProgressEvent ,
125 + pe ({ agentId:
"done#0" , phase:
"done" , kind:
"start" }),
126 + pe ({ agentId:
"done#0" , phase:
"done" , kind:
"end" , status:
"done" }),
127 + pe ({ agentId:
"active#0" , phase:
"active" , kind:
"start" }),
128 + pe ({ agentId:
"failed#0" , phase:
"failed" , kind:
"start" }),
130 + agentId:
"failed#0" ,
136 + const expanded
= toolText (s, { expanded:
true , isPartial:
true });
138 + for (
const icon
of [
"" ,
"" ,
"" ,
"" ,
"" ,
"" ])
139 + expect (expanded).
toContain (icon);
140 + for (
const label
of [
144 + "agents not planned yet" ,
149 + expect (expanded).
toContain (label);
150 + expect (expanded.
indexOf (
"done#0" )).
toBeLessThan (
151 + expanded.
indexOf (
"active#0" ),
153 + expect (expanded.
indexOf (
"active#0" )).
toBeLessThan (
154 + expanded.
indexOf (
"queued#0" ),
157 + const collapsed
= toolText (s, { expanded:
false , isPartial:
true });
158 + expect (collapsed).
toContain (
"1 active" );
159 + expect (collapsed).
toContain (
"1 queued" );
160 + expect (collapsed).
toContain (
"2 later" );
161 + expect (collapsed).not.
toContain (
"done#0" );
107 164 it (
"truncation keeps ellipsis in the surrounding style span" , ()
=> {
108 165 const s
= stateFrom ([
109 166 pe ({ agentId:
"scan#0" , phase:
"scan" , kind:
"start" }),
326 383 expect (out).
toContain (
"Review the diff from every angle." );
386 + it (
"shows planning placeholders but skips them during focus navigation" , ()
=> {
387 + const { overlay }
= makeOverlay ({ rows:
24 });
388 + overlay.
handleProgress ({
391 + { phase:
"a" , status:
"resolved" , agentIds: [
"a#0" ] },
392 + { phase:
"pending" , status:
"agents-pending" , agentIds: [] },
393 + { phase:
"b" , status:
"resolved" , agentIds: [
"b#0" ] },
397 + let out
= overlay.
render (
80 ).
join (
"\n" );
398 + expect (out).
toContain (
"agents not planned yet" );
399 + expect (out).
toContain (
"transcript: a#0" );
400 + overlay.
handleInput (K.down);
401 + out
= overlay.
render (
80 ).
join (
"\n" );
402 + expect (out).
toContain (
"transcript: b#0" );
329 405 it (
"focusing agent k shows its deltas and not the others'" , ()
=> {
330 406 const { overlay }
= makeOverlay ({ rows:
24 });
331 407 for (
const id
of [
"a" ,
"b" ,
"c" ]) {
extensions/ultra/__tests__/wire.test.ts Modified 1 1 import { describe, expect, it, vi }
from "vitest" ;
2 - import type { UltraProgressEvent }
from "../progress.ts" ;
2 + import type { AgentProgressEvent, UltraProgressEvent }
from "../progress.ts" ;
3 3 import type { DiscoveredWorkflow, WorkflowSpec }
from "../spec.ts" ;
5 5 completeWorkflowNames,
213 213 describe (
"makeToolProgressSink" , ()
=> {
214 - const ev = (over
: Partial <
UltraProgressEvent >)
: UltraProgressEvent => ({
214 + const ev = (over
: Partial <
AgentProgressEvent >)
: AgentProgressEvent => ({
221 + it (
"publishes all planned phases and queued agents on the first update" , ()
=> {
222 + const onUpdate
= vi.
fn ();
223 + const { sink }
= makeToolProgressSink (onUpdate);
224 + const plan
: UltraProgressEvent = {
227 + { phase:
"one" , status:
"resolved" , agentIds: [
"one#0" ] },
228 + { phase:
"verify" , status:
"agents-pending" , agentIds: [] },
234 + const first
= onUpdate.mock.calls[
0 ][
0 ];
236 + first.details.phases.
map ((phase
: { phase
: string })
=> phase.phase),
237 + ).
toEqual ([
"one" ,
"verify" ]);
238 + expect (first.details.
rows ).
toEqual ([
239 + expect.
objectContaining ({ agentId:
"one#0" , status:
"queued" }),
241 + expect (first.
content [
0 ].
text ).
toContain (
"1 queued" );
242 + expect (first.
content [
0 ].
text ).
toContain (
"1 later" );
221 245 it (
"calls onUpdate with { content, details: reducerState } on every event, accumulating" , ()
=> {
222 246 const onUpdate
= vi.
fn ();
223 247 const { sink, getState }
= makeToolProgressSink (onUpdate);
extensions/ultra/engine.ts Modified 32 27 } from
"./interp.ts" ;
33 28 import { isAborted, mapWithConcurrency }
from "./pool.ts" ;
34 - import type { AgentControls, UltraProgressEvent }
from "./progress.ts" ;
33 + }
from "./progress.ts" ;
35 34 import type { RunStepResult, StepRunner, TokenUsage }
from "./runner.ts" ;
36 35 import type { Phase, Step, WorkflowSpec }
from "./spec.ts" ;
114 113 const tokenUsage
= zeroUsage ();
115 114 const steeredBox
= { value:
false };
116 115 const forward
= makeForwarder (deps, steeredBox);
116 + forward ({ kind:
"plan" , phases:
planPhases (spec) });
118 118 for (
const phase
of spec.phases) {
120 120 phase.when
!== undefined && 121 121 ! phaseEnabled (
resolveSelector (phase.when, { args, results }))
123 129 results[phase.
id ]
= [];
124 130 phaseResults[phase.
id ]
= [];
125 131 phases.
push ({ id: phase.
id , ran:
0 , ok:
0 , dropped:
0 });
134 140 step :
resolveStep (phase.step, { args, results, item }),
142 + const agentIds
= resolved.
map ((_, index)
=> `${phase. id }#${index}` );
146 + status:
"resolved" ,
137 150 const cap
= phase.concurrency
?? deps.concurrency;
138 151 const slots
= await mapWithConcurrency (
156 169 onProgress : forward,
158 171 if (res.ok)
await deps.journal?.
set (key, res);
182 194 const values
: unknown []
= [];
183 195 const outcomeSlots
: PhaseSlotResult []
= [];
184 - for (
const slot
of slots) {
196 + for (
const [index, slot]
of slots.
entries ()) {
185 197 if (
isAborted (slot)) {
199 + agentId:
`${phase. id }#${index}` ,
187 206 values.
push (
null );
188 207 outcomeSlots.
push ({ ok:
false , value:
null , reason:
"aborted" });
208 227 results[phase.
id ]
= values;
209 228 phaseResults[phase.
id ]
= outcomeSlots;
210 229 phases.
push ({ id: phase.
id , ran, ok, dropped });
262 + function planPhases (spec
: WorkflowSpec )
: PlannedPhase [] {
263 + return spec.phases.
map ((phase)
=> {
264 + if (phase.when
!== undefined ) {
267 + status:
"condition-pending" ,
271 + if (phase.kind
=== "single" ) {
274 + status:
"resolved" ,
275 + agentIds: [
`${phase. id }#0` ],
278 + if (
Array .
isArray (phase.over)) {
281 + status:
"resolved" ,
282 + agentIds: phase.over.
map ((_, index)
=> `${phase. id }#${index}` ),
285 + return { phase: phase.
id , status:
"agents-pending" , agentIds: [] };
237 289 function zeroUsage ()
: TokenUsage {
291 343 return (event)
=> {
292 344 const sink
= deps.onProgress;
293 345 if (
! sink)
return ;
294 - if (
event .controls) {
346 + if (
"controls" in event && event .controls) {
295 347 sink ({
... event , controls:
wrapControls (
event .controls, steeredBox) });
extensions/ultra/progress.ts Modified 22 - export type ProgressKind = "start" | "action" | "delta" | "end" ;
22 + export type AgentProgressKind = "start" | "action" | "delta" | "end" ;
39 39 * directly by the runner
/ engine (coarse start
/ end, dropped items).
`controls` 40 40 * is attached by the runner, never by
`mapSessionEvent` .
42 - export interface UltraProgressEvent {
42 + export interface AgentProgressEvent {
45 + kind
: AgentProgressKind ;
67 67 controls
?: AgentControls;
70 + export type PhasePlanStatus = 73 + | "condition-pending" 77 + export interface PlannedPhase {
79 + status
: PhasePlanStatus ;
80 + agentIds
: readonly string [];
83 + export type UltraProgressEvent = 84 + | AgentProgressEvent 85 + | { kind
: "plan" ; phases
: readonly PlannedPhase [] }
86 + | ({ kind
: "phase" }
& PlannedPhase );
74 92 const MAX_PREVIEW
= 120 ;
172 190 event : AgentSessionEvent,
175 - ): UltraProgressEvent
| null {
193 + ): AgentProgressEvent
| null {
176 194 const base
= { agentId, phase }
as const ;
178 196 switch (
event .
type ) {
225 - export type AgentStatus = "running" | "done" | "dropped" ;
243 + export type AgentStatus = "queued" | "running" | "done" | "dropped" ;
228 246 export interface AgentRow {
241 259 controls
?: AgentControls;
251 263 export interface ProgressMeta {
252 264 workflowName
?: string ;
253 265 workflowDescription
?: string ;
271 283 transcripts : Readonly
< Record
< string, string
>> ;
272 284 transcriptItems : Readonly
< Record
< string, readonly TranscriptItem[]
>> ;
274 - phases : readonly string[];
286 + phases : readonly PlannedPhase[];
276 288 phase : string
| undefined ;
294 310 phase :
undefined ,
310 - function actionLabel (event
: UltraProgressEvent )
: string {
329 + function actionLabel (event
: AgentProgressEvent )
: string {
312 331 event .args
!== undefined 313 332 ? conciseArgs (
event .toolName,
event .args)
323 - function transcriptText (event
: UltraProgressEvent )
: string {
342 + function transcriptText (event
: AgentProgressEvent )
: string {
324 343 switch (
event .kind) {
326 345 return event .
text ?? "" ;
336 - function transcriptItem (event
: UltraProgressEvent )
: TranscriptItem | undefined {
355 + function transcriptItem (event
: AgentProgressEvent )
: TranscriptItem | undefined {
337 356 if (
event .kind
=== "delta" )
return { kind:
"text" , text:
event .
text ?? "" };
338 357 if (
event .kind
!== "action" || ! event .toolName)
return undefined ;
339 358 const fallback
= actionLabel (
event );
351 370 function nextRow (
352 371 prev
: AgentRow | undefined ,
353 - event
: UltraProgressEvent ,
372 + event
: AgentProgressEvent ,
355 374 const base
: AgentRow = prev
?? {
356 375 agentId:
event .agentId,
413 + function queuedRow (agentId
: string , phase
: string )
: AgentRow {
414 + return { agentId, phase, status:
"queued" , action:
"" };
417 + function withCounts (
420 + "total" | "queued" | "running" | "done" | "dropped" | "later" 427 + for (
const row
of state.
rows ) {
428 + if (row.
status === "queued" ) queued
++ ;
429 + else if (row.
status === "running" ) running
++ ;
430 + else if (row.
status === "done" ) done
++ ;
433 + const later
= state.phases.
filter (
435 + phase.
status === "agents-pending" || phase.
status === "condition-pending" ,
439 + total: state.
rows .
length ,
449 + state
: ReducerState ,
450 + phases
: readonly PlannedPhase [],
452 + const planned
= phases.
map ((phase)
=> ({
454 + agentIds: [
... phase.agentIds],
456 + return withCounts ({
460 + rows: planned.
flatMap ((phase)
=> 461 + phase.agentIds.
map ((agentId)
=> queuedRow (agentId, phase.phase)),
466 + function applyPhase (
467 + state
: ReducerState ,
468 + event
: Extract <
UltraProgressEvent , { kind
: "phase" }>,
471 + phase:
event .phase,
472 + status:
event .
status ,
473 + agentIds: [
... event .agentIds],
475 + const phases
= state.phases.
some ((entry)
=> entry.phase
=== event .phase)
476 + ? state.phases.
map ((entry)
=> (entry.phase
=== event .phase
? phase
: entry))
477 + : [
... state.phases, phase];
478 + const keep
= new Set (
event .agentIds);
479 + const rows
= state.
rows .
filter (
480 + (row)
=> row.phase
!== event .phase
|| keep.
has (row.agentId),
482 + for (
const agentId
of event .agentIds) {
483 + if (
! rows.
some ((row)
=> row.agentId
=== agentId))
484 + rows.
push (
queuedRow (agentId,
event .phase));
486 + return withCounts ({
489 + phase:
event .phase,
400 498 export function reduceProgress (
401 499 state
: ReducerState ,
402 500 event
: UltraProgressEvent ,
403 501 )
: ReducerState {
404 - const idx
= state.
rows .
findIndex ((r)
=> r.agentId
=== event .agentId);
502 + if (
event .kind
=== "plan" )
return applyPlan (state,
event .phases);
503 + if (
event .kind
=== "phase" )
return applyPhase (state,
event );
505 + const idx
= state.
rows .
findIndex ((row)
=> row.agentId
=== event .agentId);
405 506 const prev
= idx
>= 0 ? state.
rows [idx]
: undefined ;
406 507 const row
= nextRow (prev,
event );
409 - ? state.
rows .
map ((r, i)
=> (i
=== idx
? row
: r))
510 + ? state.
rows .
map ((entry, i)
=> (i
=== idx
? row
: entry))
410 511 : [
... state.
rows , row];
412 513 const added
= transcriptText (
event );
429 530 : state.transcriptItems;
431 - const phases
= state.phases.
includes (
event .phase)
532 + const phases
= state.phases.
some ((phase)
=> phase.phase
=== event .phase)
433 - : [
... state.phases,
event .phase];
537 + phase:
event .phase,
538 + status:
"resolved" as const ,
539 + agentIds: [
event .agentId],
437 - for (
const r
of rows) {
438 - if (r.
status === "done" ) done
++ ;
439 - else if (r.
status === "dropped" ) dropped
++ ;
543 + return withCounts ({
443 544 workflowName: state.workflowName,
444 545 workflowDescription: state.workflowDescription,
449 550 phase :
event .phase,
450 - total : rows.
length ,
extensions/ultra/runner.ts Modified 32 32 import type { AgentSessionEvent }
from "@earendil-works/pi-coding-agent" ;
34 34 type AgentControls,
35 + type AgentProgressEvent,
36 37 type UltraProgressEvent,
37 38 }
from "./progress.ts" ;
485 486 function emitCompleteStart (
486 487 opts
: RunStepOptions ,
488 - UltraProgressEvent ,
489 + AgentProgressEvent ,
489 490 "tier" | "model" | "thinkingLevel" | "startedAt" extensions/ultra/ui.ts Modified 36 36 type AgentControls ,
38 38 initialReducerState,
41 42 type TranscriptItem ,
49 50 const STATUS_ICON
: Record <
AgentStatus ,
string >
= {
58 + "agents-pending" :
"" ,
59 + "condition-pending" :
"" ,
55 63 const RESET
= /\x1b\[0m/ g ;
57 65 function fitLine (text
: string , width
: number )
: string {
60 68 return text.
includes (
"\x1b" )
? out
: out.
replace (RESET,
"" );
64 72 function phaseCounter (state
: ReducerState )
: string {
65 73 if (state.phases.
length === 0 )
return "" ;
66 - const idx
= state.phase
? state.phases.
indexOf (state.phase)
+ 1 : 0 ;
74 + const idx
= state.phase
75 + ? state.phases.
findIndex ((phase)
=> phase.phase
=== state.phase)
+ 1 67 77 return `phase ${idx}/${state.phases. length }` ;
71 81 function summaryLine (state
: ReducerState )
: string {
72 82 const parts
: string []
= [];
73 83 const pc
= phaseCounter (state);
74 84 if (pc) parts.
push (pc);
75 85 parts.
push (
`${state.done}/${state.total} done` );
86 + if (state.running
> 0 ) parts.
push (
`${state.running} active` );
87 + if (state.queued
> 0 ) parts.
push (
`${state.queued} queued` );
88 + if (state.later
> 0 )
89 + parts.
push (
`${state.later} later phase${state.later === 1 ? "" : "s"}` );
76 90 if (state.dropped
> 0 ) parts.
push (
`${state.dropped}✗` );
77 91 return parts.
join (
" · " );
140 + | { kind
: "agent" ; row
: ReducerState [
"rows" ][
number ] }
141 + | { kind
: "phase" ; phase
: PlannedPhase };
143 + function displayRows (state
: ReducerState )
: DisplayRow [] {
144 + const out
: DisplayRow []
= [];
145 + const seen
= new Set <
string >();
146 + for (
const phase
of state.phases) {
147 + const rows
= state.
rows .
filter ((row)
=> row.phase
=== phase.phase);
149 + phase.
status === "agents-pending" || 150 + phase.
status === "condition-pending" || 151 + phase.
status === "skipped" || 152 + (phase.
status === "done" && rows.
length === 0 )
154 + out.
push ({ kind:
"phase" , phase });
157 + for (
const row
of rows) {
158 + seen.
add (row.agentId);
159 + out.
push ({ kind:
"agent" , row });
162 + for (
const row
of state.
rows ) {
163 + if (
! seen.
has (row.agentId)) out.
push ({ kind:
"agent" , row });
168 + function phaseLabel (phase
: PlannedPhase )
: string {
169 + switch (phase.
status ) {
170 + case "agents-pending" :
171 + return `${PHASE_ICON[phase. status ]} ${phase.phase} · agents not planned yet` ;
172 + case "condition-pending" :
173 + return `${PHASE_ICON[phase. status ]} ${phase.phase} · conditional` ;
175 + return `${PHASE_ICON[phase. status ]} ${phase.phase} · skipped` ;
177 + return ` ${phase.phase} · done · no agents` ;
179 + return phase.phase;
183 + function phaseDetail (phase
: PlannedPhase )
: string | undefined {
184 + if (phase.
status === "agents-pending" )
185 + return "earlier results determine which agents are needed" ;
186 + if (phase.
status === "condition-pending" )
187 + return "earlier results determine whether this phase runs" ;
191 + function queuedDetail (state
: ReducerState , phase
: string )
: string {
192 + return state.phase
=== phase
193 + ? "waiting for concurrency slot" 194 + : "starts when phase begins" ;
125 197 function divider (label
: string , width
: number )
: string {
126 198 const w
= Math .
max (
1 , width);
127 199 const text
= ` ${label} ` ;
171 243 return lines.
map ((l)
=> fitLine (l, w));
175 - for (
const row
of state.
rows ) {
247 + for (
const display
of displayRows (state)) {
248 + if (display.kind
=== "phase" ) {
249 + lines.
push (theme.
fg (
"dim" ,
fitLine (
phaseLabel (display.phase), w)));
250 + const detail
= phaseDetail (display.phase);
251 + if (detail) lines.
push (theme.
fg (
"muted" ,
fitLine (
` └ ${detail}` , w)));
254 + const { row }
= display;
176 255 const icon
= STATUS_ICON[row.
status ];
178 - theme.
fg (
"dim" ,
fitLine (
`${icon} ${row.agentId} · ${row. status }` , w)),
256 + let identity
= `${icon} ${row.agentId} · ${row. status }` ;
257 + if (row.
status === "queued" )
258 + identity
+= ` · ${ queuedDetail (state, row.phase)}` ;
259 + lines.
push (theme.
fg (
"dim" ,
fitLine (identity, w)));
180 260 for (
const detail
of agentDetailLines (row)) {
181 261 lines.
push (theme.
fg (
"muted" ,
fitLine (
` ${detail}` , w)));
220 300 function asReducerState (details
: unknown )
: ReducerState {
221 301 const d
= details
as Partial <
ReducerState >
| null | undefined ;
222 - return d
&& Array .
isArray (d.phases)
&& Array .
isArray (d.
rows )
302 + const phaseStatuses
: readonly string []
= [
305 + "condition-pending" ,
309 + const agentStatuses
: readonly string []
= [
315 + const phasesValid
= 316 + Array .
isArray (d?.phases)
&& 319 + typeof phase
=== "object" && 321 + typeof phase.phase
=== "string" && 322 + phaseStatuses.
includes (phase.
status )
&& 323 + Array .
isArray (phase.agentIds)
&& 324 + phase.agentIds.
every ((agentId
: unknown )
=> typeof agentId
=== "string" ),
327 + Array .
isArray (d?.
rows )
&& 330 + typeof row
=== "object" && 332 + typeof row.agentId
=== "string" && 333 + typeof row.phase
=== "string" && 334 + agentStatuses.
includes (row.
status ),
336 + return d
&& phasesValid
&& rowsValid
223 337 ? (d
as ReducerState )
224 338 : initialReducerState ();
386 500 const now
= this.
now ();
389 - const force
= event .kind
=== "end" ;
503 + const force
= event .kind
=== "end" || event .kind
=== "phase" ;
390 504 if (force
|| now
- this.lastRenderAt
>= this.throttleMs) {
391 505 this.lastRenderAt
= now;
392 506 this.
host .
requestRender ();
579 693 const maxLines
= Math .
max (
1 , this.
host .terminal.
rows - 3 );
580 694 const fixedAfterRows
= 3 ;
581 - const maxAgentRows
= Math .
min (
695 + const display
= displayRows (state);
696 + const maxWorkRows
= Math .
min (
583 698 Math .
max (
0 , maxLines
- lines.
length - fixedAfterRows),
700 + const focusedId
= this.
focusedRow ()?.agentId;
701 + const focusedDisplay
= display.
findIndex (
702 + (item)
=> item.kind
=== "agent" && item.row.agentId
=== focusedId,
586 - maxAgentRows
>= state.
rows .
length 705 + maxWorkRows
>= display.
length 589 - Math .
max (
0 , this.focusIndex
- Math .
floor (maxAgentRows
/ 2 )),
590 - Math .
max (
0 , state.
rows .
length - maxAgentRows),
708 + Math .
max (
0 , focusedDisplay
- Math .
floor (maxWorkRows
/ 2 )),
709 + Math .
max (
0 , display.
length - maxWorkRows),
593 - .
slice (rowStart, rowStart
+ maxAgentRows)
594 - .
forEach ((row, offset)
=> {
595 - const i
= rowStart
+ offset;
596 - const focused
= i
=== this.focusIndex;
597 - const marker
= focused
? "▶" : " " ;
598 - const icon
= STATUS_ICON[row.
status ];
599 - let line
= `${marker} ${icon} ${row.agentId} · ${row. status }` ;
600 - if (row.
action ) line
+= ` · ${row. action }` ;
601 - lines.
push (this.theme.
fg (focused
? "accent" : "dim" ,
fitLine (line, w)));
711 + for (
const item
of display.
slice (rowStart, rowStart
+ maxWorkRows)) {
712 + if (item.kind
=== "phase" ) {
714 + this.theme.
fg (
"dim" ,
fitLine (
` ${ phaseLabel (item.phase)}` , w)),
716 + const detail
= phaseDetail (item.phase);
718 + lines.
push (this.theme.
fg (
"muted" ,
fitLine (
` └ ${detail}` , w)));
721 + const { row }
= item;
722 + const focused
= row.agentId
=== focusedId;
723 + const marker
= focused
? "▶" : " " ;
724 + const icon
= STATUS_ICON[row.
status ];
725 + let line
= `${marker} ${icon} ${row.agentId} · ${row. status }` ;
726 + if (row.
status === "queued" )
727 + line
+= ` · ${ queuedDetail (state, row.phase)}` ;
728 + if (row.
action ) line
+= ` · ${row. action }` ;
729 + lines.
push (this.theme.
fg (focused
? "accent" : "dim" ,
fitLine (line, w)));
604 732 const focusedRow
= this.
focusedRow ();
extensions/ultra/wire.ts Modified 171 171 * `renderResult` ; this
`content` is just the textual fallback).
*/ 172 172 function summarize (state
: ReducerState )
: string {
173 173 const phase
= state.phase
? `${state.phase}: ` : "" ;
174 - return `${phase}${state.done}/${state.total} done${state.dropped ? `, ${state.dropped} dropped` : ""}` ;
175 + `${phase}${state.done}/${state.total} done` ,
176 + state.running
? `${state.running} active` : "" ,
177 + state.queued
? `${state.queued} queued` : "" ,
178 + state.later
? `${state.later} later` : "" ,
179 + state.dropped
? `${state.dropped} dropped` : "" ,
201 - state
= reduceProgress (state, {
... event , controls:
undefined });
210 + "agentId" in event ? {
... event , controls:
undefined }
: event ;
211 + state
= reduceProgress (state, safe);
203 213 content: [{ type:
"text" , text:
summarize (state) }],