repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

fix(ultra): freeze completed agent timers

1a0ca18a8766027fb1f1215f8879afba7e7005f3

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (3)

extensions/ultra/__tests__/ui.test.ts

Modified
218 218 expect(out).toContain("read docs/phase-1.html");
221 + it("freezes elapsed time when an agent ends", () => {
222 + vi.useFakeTimers();
223 + try {
224 + vi.setSystemTime(100_000);
225 + const s = stateFrom([
226 + pe({
227 + agentId: "plan#0",
228 + phase: "plan",
229 + kind: "start",
230 + startedAt: 0,
231 + }),
232 + pe({ agentId: "plan#0", phase: "plan", kind: "end", status: "done" }),
233 + ]);
234 + vi.setSystemTime(200_000);
236 + const out = toolText(s, { expanded: true, isPartial: false });
237 + expect(out).toContain("1m 40s");
238 + expect(out).not.toContain("3m 20s");
239 + } finally {
240 + vi.useRealTimers();
242 + });
221 244 it("never emits bodies when expanded=false (sentinels absent collapsed, present expanded)", () => {
222 245 const collapsed = toolText(scripted, { expanded: false, isPartial: false });
223 246 const expanded = toolText(scripted, { expanded: true, isPartial: false });

extensions/ultra/progress.ts

Modified
235 235 model?: string;
236 236 thinkingLevel?: ThinkingLevel;
237 237 startedAt?: number;
238 + endedAt?: number;
238 239 usage?: TokenUsage;
239 240 /** Live controls (command overlay only); absent on tool-less / tool-surface rows. */
240 241 controls?: AgentControls;
389 390 model: event.model ?? base.model,
390 391 thinkingLevel: event.thinkingLevel ?? base.thinkingLevel,
391 392 startedAt: event.startedAt ?? base.startedAt,
393 + endedAt: event.kind === "end" ? (base.endedAt ?? Date.now()) : base.endedAt,
392 394 usage: event.usage ?? base.usage,
393 395 controls: event.controls ?? base.controls,

extensions/ultra/ui.ts

Modified
93 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));
96 +function elapsed(startedAt: number, endedAt = Date.now()): string {
97 + const seconds = Math.max(0, Math.floor((endedAt - startedAt) / 1000));
98 98 if (seconds < 60) return `${seconds}s`;
99 99 return `${Math.floor(seconds / 60)}m ${seconds % 60}s`;
107 107 const modelValue = [model, row.thinkingLevel].filter(Boolean).join(" · ");
108 108 if (modelValue) details.push({ label: "model", value: modelValue });
109 109 const usageValue = [
110 - row.startedAt === undefined ? undefined : elapsed(row.startedAt),
110 + row.startedAt === undefined
111 + ? undefined
112 + : elapsed(row.startedAt, row.endedAt),
111 113 row.usage ? `${compactTokens(row.usage.total)} tokens` : undefined,
113 115 .filter(Boolean)