fix: deduplicate formatDuration into shared format-utils (#989)

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
TÂCHES 2026-03-17 17:06:06 -06:00 committed by GitHub
parent 8877e01083
commit 2bdcabfbfc
7 changed files with 7 additions and 17 deletions

View file

@ -1803,7 +1803,7 @@ async function handleDryRun(ctx: ExtensionCommandContext, basePath: string): Pro
const { getLedger, getProjectTotals, formatCost, formatTokenCount, loadLedgerFromDisk } = await import("./metrics.js");
const { loadEffectiveGSDPreferences: loadPrefs } = await import("./preferences.js");
const { formatDuration } = await import("./history.js");
const { formatDuration } = await import("../shared/format-utils.js");
const ledger = getLedger();
const units = ledger?.units ?? loadLedgerFromDisk(basePath)?.units ?? [];

View file

@ -25,7 +25,7 @@ import type {
VisualizerMilestone,
VisualizerSlice,
} from './visualizer-data.js';
import { formatDuration } from './history.js';
import { formatDuration } from '../shared/format-utils.js';
import { formatCost, formatTokenCount } from './metrics.js';
// ─── Public API ────────────────────────────────────────────────────────────────

View file

@ -10,7 +10,7 @@ import {
} from "./metrics.js";
import type { UnitMetrics } from "./metrics.js";
import { gsdRoot } from "./paths.js";
import { formatDuration } from "./history.js";
import { formatDuration } from "../shared/format-utils.js";
/**
* Write an export file directly, without requiring an ExtensionCommandContext.

View file

@ -27,7 +27,7 @@ import { deriveState } from "./state.js";
import { isAutoActive } from "./auto.js";
import { loadPrompt } from "./prompt-loader.js";
import { gsdRoot } from "./paths.js";
import { formatDuration } from "./history.js";
import { formatDuration } from "../shared/format-utils.js";
import { getAutoWorktreePath } from "./auto-worktree.js";
// ─── Types ────────────────────────────────────────────────────────────────────

View file

@ -2,6 +2,7 @@
// Human-readable display of past auto-mode unit executions.
import type { ExtensionCommandContext } from "@gsd/pi-coding-agent";
import { formatDuration } from "../shared/format-utils.js";
import {
getLedger, getProjectTotals, formatCost, formatTokenCount,
aggregateBySlice, aggregateByPhase, aggregateByModel, loadLedgerFromDisk,
@ -128,18 +129,6 @@ function showModelBreakdown(units: UnitMetrics[], ctx: ExtensionCommandContext):
// ─── Formatting helpers ──────────────────────────────────────────────────────
export function formatDuration(ms: number): string {
if (ms < 1000) return `${ms}ms`;
const secs = Math.floor(ms / 1000);
if (secs < 60) return `${secs}s`;
const mins = Math.floor(secs / 60);
const remSecs = secs % 60;
if (mins < 60) return `${mins}m ${remSecs}s`;
const hours = Math.floor(mins / 60);
const remMins = mins % 60;
return `${hours}h ${remMins}m`;
}
function formatRelativeTime(timestamp: number): string {
const diff = Date.now() - timestamp;
if (diff < 60_000) return "just now";

View file

@ -18,7 +18,7 @@ import { writeFileSync, readFileSync, mkdirSync, existsSync } from 'node:fs';
import { join, basename } from 'node:path';
import { gsdRoot } from './paths.js';
import { formatCost, formatTokenCount } from './metrics.js';
import { formatDuration } from './history.js';
import { formatDuration } from '../shared/format-utils.js';
// ─── Types ────────────────────────────────────────────────────────────────────

View file

@ -11,6 +11,7 @@ import { truncateToWidth, visibleWidth } from "@gsd/pi-tui";
/** Format a millisecond duration as a compact human-readable string. */
export function formatDuration(ms: number): string {
if (ms < 1000) return `${ms}ms`;
const s = Math.floor(ms / 1000);
if (s < 60) return `${s}s`;
const m = Math.floor(s / 60);