repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

feat(ultra): show workflow wall time

ec11ca2ae2fb3210eb9f3597e08fbec06a78d2cb

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (7)

extensions/ultra/__tests__/engine.test.ts

Modified
179 179 expect(events[0]).toEqual({
180 180 kind: "plan",
181 + startedAt: expect.any(Number),
181 182 phases: [
182 183 { phase: "one", status: "resolved", agentIds: ["one#0"] },
321 322 expect(fr.calls).toHaveLength(1);
322 323 expect(events[0]).toEqual({
323 324 kind: "plan",
325 + startedAt: expect.any(Number),
324 326 phases: [
326 328 phase: "conditional",

extensions/ultra/__tests__/progress.test.ts

Modified
157 157 it("seeds queued agents and pending phases from a workflow plan", () => {
158 158 const s = reduceProgress(initialReducerState(), {
159 159 kind: "plan",
160 + startedAt: 1000,
160 161 phases: [
162 163 phase: "research",
198 + it("starts wall time with the plan and freezes it when every phase settles", () => {
199 + vi.useFakeTimers();
200 + try {
201 + vi.setSystemTime(1000);
202 + const planned = reduceProgress(initialReducerState(), {
203 + kind: "plan",
204 + startedAt: 1000,
205 + phases: [{ phase: "one", status: "resolved", agentIds: ["one#0"] }],
206 + } as unknown as UltraProgressEvent);
207 + expect(planned.startedAt).toBe(1000);
208 + expect(planned.endedAt).toBeUndefined();
210 + vi.setSystemTime(61_000);
211 + const done = reduceProgress(planned, {
212 + kind: "phase",
213 + phase: "one",
214 + status: "done",
215 + agentIds: ["one#0"],
216 + } as unknown as UltraProgressEvent);
217 + expect(done.endedAt).toBe(61_000);
219 + vi.setSystemTime(121_000);
220 + const repeated = reduceProgress(done, {
221 + kind: "phase",
222 + phase: "one",
223 + status: "done",
224 + agentIds: ["one#0"],
225 + } as unknown as UltraProgressEvent);
226 + expect(repeated.endedAt).toBe(61_000);
227 + } finally {
228 + vi.useRealTimers();
230 + });
197 232 it("resolves pending agents before start and transitions queued to running", () => {
198 233 const planned = reduceProgress(initialReducerState(), {
199 234 kind: "plan",
235 + startedAt: 1000,
200 236 phases: [{ phase: "verify", status: "agents-pending", agentIds: [] }],
201 237 } as unknown as UltraProgressEvent);
202 238 const resolved = reduceProgress(planned, {
225 261 it("removes provisional agent rows when a phase is skipped", () => {
226 262 const planned = reduceProgress(initialReducerState(), {
227 263 kind: "plan",
264 + startedAt: 1000,
228 265 phases: [
229 266 { phase: "publish", status: "resolved", agentIds: ["publish#0"] },

extensions/ultra/__tests__/ui.test.ts

Modified
104 104 expect(out).toContain("Review the diff from every angle.");
107 + it("shows workflow wall time in the header and freezes it after completion", () => {
108 + vi.useFakeTimers();
109 + try {
110 + vi.setSystemTime(0);
111 + const planned = reduceProgress(initialReducerState(), {
112 + kind: "plan",
113 + startedAt: 0,
114 + phases: [{ phase: "one", status: "resolved", agentIds: ["one#0"] }],
115 + } as unknown as UltraProgressEvent);
116 + vi.setSystemTime(65_000);
117 + expect(toolText(planned, { expanded: false, isPartial: true })).toContain(
118 + "1m 5s elapsed",
119 + );
121 + const done = reduceProgress(planned, {
122 + kind: "phase",
123 + phase: "one",
124 + status: "done",
125 + agentIds: ["one#0"],
126 + } as unknown as UltraProgressEvent);
127 + vi.setSystemTime(125_000);
128 + const frozen = toolText(done, { expanded: true, isPartial: false });
129 + expect(frozen).toContain("1m 5s elapsed");
130 + expect(frozen).not.toContain("2m 5s elapsed");
131 + } finally {
132 + vi.useRealTimers();
134 + });
107 136 it("renders the complete icon-led planned-work vocabulary in phase order", () => {
108 137 const s = stateFrom([
110 139 kind: "plan",
140 + startedAt: Date.now(),
111 141 phases: [
112 142 { phase: "done", status: "resolved", agentIds: ["done#0"] },
113 143 { phase: "active", status: "resolved", agentIds: ["active#0"] },
387 417 const { overlay } = makeOverlay({ rows: 24 });
388 418 overlay.handleProgress({
389 419 kind: "plan",
420 + startedAt: Date.now(),
390 421 phases: [
391 422 { phase: "a", status: "resolved", agentIds: ["a#0"] },
392 423 { phase: "pending", status: "agents-pending", agentIds: [] },

extensions/ultra/__tests__/wire.test.ts

Modified
223 223 const { sink } = makeToolProgressSink(onUpdate);
224 224 const plan: UltraProgressEvent = {
225 225 kind: "plan",
226 + startedAt: 1000,
226 227 phases: [
227 228 { phase: "one", status: "resolved", agentIds: ["one#0"] },
228 229 { phase: "verify", status: "agents-pending", agentIds: [] },

extensions/ultra/engine.ts

Modified
113 113 const tokenUsage = zeroUsage();
114 114 const steeredBox = { value: false };
115 115 const forward = makeForwarder(deps, steeredBox);
116 - forward({ kind: "plan", phases: planPhases(spec) });
116 + forward({ kind: "plan", phases: planPhases(spec), startedAt: Date.now() });
118 118 for (const phase of spec.phases) {

extensions/ultra/progress.ts

Modified
83 83 export type UltraProgressEvent =
84 84 | AgentProgressEvent
85 - | { kind: "plan"; phases: readonly PlannedPhase[] }
85 + | { kind: "plan"; phases: readonly PlannedPhase[]; startedAt: number }
86 86 | ({ kind: "phase" } & PlannedPhase);
88 88 // ---------------------------------------------------------------------------
286 286 phases: readonly PlannedPhase[];
287 287 /** Current engine phase; initial planning does not select one. */
288 288 phase: string | undefined;
289 + startedAt: number | undefined;
290 + endedAt: number | undefined;
289 291 /** Known agents. */
290 292 total: number;
291 293 queued: number;
308 310 transcriptItems: {},
309 311 phases: [],
310 312 phase: undefined,
313 + startedAt: undefined,
314 + endedAt: undefined,
311 315 total: 0,
312 316 queued: 0,
313 317 running: 0,
434 438 (phase) =>
435 439 phase.status === "agents-pending" || phase.status === "condition-pending",
436 440 ).length;
441 + const settled =
442 + state.phases.length > 0 &&
443 + state.phases.every(
444 + (phase) => phase.status === "done" || phase.status === "skipped",
445 + );
437 446 return {
438 447 ...state,
448 + endedAt: settled ? (state.endedAt ?? Date.now()) : state.endedAt,
439 449 total: state.rows.length,
440 450 queued,
441 451 running,
448 458 function applyPlan(
449 459 state: ReducerState,
450 - phases: readonly PlannedPhase[],
460 + event: Extract<UltraProgressEvent, { kind: "plan" }>,
451 461 ): ReducerState {
452 - const planned = phases.map((phase) => ({
462 + const planned = event.phases.map((phase) => ({
453 463 ...phase,
454 464 agentIds: [...phase.agentIds],
457 467 ...state,
458 468 phases: planned,
459 469 phase: undefined,
470 + startedAt: event.startedAt,
471 + endedAt: undefined,
460 472 rows: planned.flatMap((phase) =>
461 473 phase.agentIds.map((agentId) => queuedRow(agentId, phase.phase)),
499 511 state: ReducerState,
500 512 event: UltraProgressEvent,
501 513 ): ReducerState {
502 - if (event.kind === "plan") return applyPlan(state, event.phases);
514 + if (event.kind === "plan") return applyPlan(state, event);
503 515 if (event.kind === "phase") return applyPhase(state, event);
505 517 const idx = state.rows.findIndex((row) => row.agentId === event.agentId);
548 560 transcriptItems,
549 561 phases,
550 562 phase: event.phase,
563 + startedAt: state.startedAt,
564 + endedAt: state.endedAt,

extensions/ultra/ui.ts

Modified
94 94 function headerLine(state: ReducerState): string {
95 - return ["ultra", state.workflowName, summaryLine(state)]
96 - .filter(Boolean)
97 - .join(" · ");
95 + const wallTime =
96 + state.startedAt === undefined
97 + ? undefined
98 + : `${elapsed(state.startedAt, state.endedAt)} elapsed`;
99 + return ["ultra", state.workflowName, wallTime].filter(Boolean).join(" · ");
100 102 function descriptionLine(state: ReducerState): string | undefined {
235 237 const runMark = options.isPartial ? "⏳ " : "";
236 238 lines.push(theme.fg("accent", fitLine(`${runMark}${headerLine(state)}`, w)));
239 + lines.push(theme.fg("muted", fitLine(summaryLine(state), w)));
237 240 const description = descriptionLine(state);
238 241 if (description) lines.push(theme.fg("muted", fitLine(description, w)));
686 689 const lines: string[] = [];
688 691 lines.push(this.theme.fg("accent", fitLine(headerLine(state), w)));
692 + lines.push(this.theme.fg("muted", fitLine(summaryLine(state), w)));
689 693 const description = descriptionLine(state);
690 694 if (description)
691 695 lines.push(this.theme.fg("muted", fitLine(description, w)));