Skip to content

Commit 6334d02

Browse files
committed
Share formatElapsed and drop status-bar IIFE
Reuse the in-flight indicator duration formatter for the agents strip and completed-agents label so three near-copies do not drift. Compute completedAgentsLabel once above the return instead of an IIFE spread.
1 parent bb86e83 commit 6334d02

3 files changed

Lines changed: 7 additions & 27 deletions

File tree

‎src/tui/app.tsx‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,8 @@ export function App({
578578
providerCatalog,
579579
extraChromeRows,
580580
});
581+
582+
const completedAgentsLabel = formatCompletedAgentsLabel(subAgentSessions?.list() ?? []);
581583
const { leftWidth, visibleRows, effectiveOverlayRows, permissionsOverlayRows } = layout;
582584
// Text wraps and renders inside the gutter so prose never touches the edges.
583585
const contentWidth = Math.max(8, leftWidth - TEXT_GUTTER * 2);
@@ -1325,10 +1327,7 @@ export function App({
13251327
)}
13261328
<Box marginTop={1}>
13271329
<StatusBar
1328-
{...(() => {
1329-
const agentsLabel = formatCompletedAgentsLabel(subAgentSessions?.list() ?? []);
1330-
return agentsLabel !== undefined ? { completedAgentsLabel: agentsLabel } : {};
1331-
})()}
1330+
{...(completedAgentsLabel !== undefined ? { completedAgentsLabel } : {})}
13321331
mcpCount={mcpStatus.connected.length}
13331332
model={model}
13341333
cwd={cwd}

‎src/tui/components/agents-strip.tsx‎

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { Task } from "../../agent/tasks.js";
44
import type { SubAgentSession, SubAgentSessionStatus } from "../../subagent/session-store.js";
55
import { color } from "../theme.js";
66
import { describeToolCall } from "../tool-formatter.js";
7+
import { formatElapsed } from "./in-flight-indicator.js";
78

89
export type AgentsStripProps = {
910
sessions: readonly SubAgentSession[];
@@ -318,7 +319,7 @@ export function formatSessionLabel(session: SubAgentSession): string {
318319
// (completed sub-agent times, not a live tick for in-flight sessions).
319320
const duration =
320321
session.finishedAt !== undefined && session.finishedAt >= session.startedAt
321-
? formatStripDuration(session.finishedAt - session.startedAt)
322+
? formatElapsed(session.finishedAt - session.startedAt)
322323
: undefined;
323324
const durationSuffix = duration !== undefined ? ` · ${duration}` : "";
324325
if (session.status === "running" && session.currentToolName !== null) {
@@ -341,16 +342,6 @@ export function formatSessionLabel(session: SubAgentSession): string {
341342
return `${session.agentId}: ${session.description}${tool}${durationSuffix}`;
342343
}
343344

344-
function formatStripDuration(ms: number): string {
345-
const totalSec = Math.max(0, Math.floor(ms / 1000));
346-
const hours = Math.floor(totalSec / 3600);
347-
const minutes = Math.floor((totalSec % 3600) / 60);
348-
const seconds = totalSec % 60;
349-
if (hours > 0) return `${hours}h ${minutes}m`;
350-
if (minutes > 0) return `${minutes}m ${seconds}s`;
351-
return `${seconds}s`;
352-
}
353-
354345
function summaryCounts(sessions: readonly SubAgentSession[]): string {
355346
const running = sessions.filter((s) => s.status === "running").length;
356347
const done = sessions.filter((s) => s.status === "done").length;

‎src/tui/components/status-bar.tsx‎

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -148,18 +148,8 @@ export function planStatusBarLayout(args: StatusBarLayoutArgs): StatusBarLayout
148148
};
149149
}
150150

151-
export function formatElapsed(elapsedMs: number): string {
152-
const totalSeconds = Math.floor(elapsedMs / 1000);
153-
if (totalSeconds < 60) return `${totalSeconds}s`;
154-
155-
const seconds = totalSeconds % 60;
156-
const totalMinutes = Math.floor(totalSeconds / 60);
157-
if (totalMinutes < 60) return `${totalMinutes}m ${seconds}s`;
158-
159-
const minutes = totalMinutes % 60;
160-
const hours = Math.floor(totalMinutes / 60);
161-
return `${hours}h ${minutes}m ${seconds}s`;
162-
}
151+
export { formatElapsed } from "./in-flight-indicator.js";
152+
import { formatElapsed } from "./in-flight-indicator.js";
163153

164154
// Slim footer: brand anchors the bottom-left; completed sub-agent timing sits
165155
// beside it when any worker has finished this session. MCP health sits on the

0 commit comments

Comments
 (0)