diff --git a/web/src/app/(main)/chat/page.tsx b/web/src/app/(main)/chat/page.tsx index 33891ce5c..e9c65b902 100644 --- a/web/src/app/(main)/chat/page.tsx +++ b/web/src/app/(main)/chat/page.tsx @@ -56,36 +56,13 @@ import { useSideQuestions } from "@/hooks/use-side-questions"; import { mergeActivities } from "@/lib/activity-merge"; import { api } from "@/lib/api"; import { shouldSubmitOnKey, useChatSendMode } from "@/lib/chat-send-mode"; +import { formatBytes, formatTokens } from "@/lib/format"; import { getLocalStorageValue, removeLocalStorageValue, setLocalStorageValue } from "@/lib/local-storage.client"; import { isBtwCommand } from "@/lib/side-questions"; import type { Activity, Agent, ChatAttachment, Conversation, LLMProfile } from "@/lib/types"; import { cn } from "@/lib/utils"; import { intlLocale, t } from "@/i18n"; -// fmtBytes renders a human file size for attachment chips (mirrors transcript.tsx). -function fmtBytes(n: number): string { - if (n >= 1 << 20) return `${(n / (1 << 20)).toFixed(1)} MB`; - if (n >= 1 << 10) return `${(n / (1 << 10)).toFixed(1)} KB`; - return `${n} B`; -} - -// fmtTokens renders a compact token count (1234 → 1.2k, 2_000_000 → 2M). -function fmtTokens(n: number): string { - if (n >= 1_000_000) return `${(n / 1_000_000).toFixed(n >= 10_000_000 ? 0 : 1)}M`; - if (n >= 1000) return `${(n / 1000).toFixed(n >= 10000 ? 0 : 1)}k`; - return String(n); -} - -// fmtDuration renders an elapsed milliseconds span compactly (90s → 1m30s). -function fmtDuration(ms: number): string { - const s = Math.floor(ms / 1000); - if (s < 60) return `${s}s`; - const m = Math.floor(s / 60); - if (m < 60) return `${m}m${String(s % 60).padStart(2, "0")}s`; - const h = Math.floor(m / 60); - return `${h}h${String(m % 60).padStart(2, "0")}m`; -} - // HISTORY_PAGE is how many steps one history page loads: the latest page on open, // then one more page each time the user scrolls to the top. Kept modest so a long // thread stays snappy (only ~a page of rows is in the DOM until you scroll up). @@ -202,7 +179,7 @@ function Composer({ > {a.name} - {fmtBytes(a.size)} + {formatBytes(a.size)} {onRemoveAttachment && ( - {e.dir ? "—" : fmtSize(e.size)} + {e.dir ? "—" : formatBytes(e.size)} + + + {formatShortDateTime(e.mtime, { year: true, seconds: false })} - {fmtTime(e.mtime)}
{!e.dir && ( @@ -303,7 +290,7 @@ export default function WorkspacePage() { {edit.file.path} - {fmtSize(edit.file.size)} + {formatBytes(edit.file.size)} {edit.file.binary || edit.file.too_large ? ( diff --git a/web/src/app/(main)/system/intercept/page.tsx b/web/src/app/(main)/system/intercept/page.tsx index 106e773b6..56a8f1cd2 100644 --- a/web/src/app/(main)/system/intercept/page.tsx +++ b/web/src/app/(main)/system/intercept/page.tsx @@ -52,6 +52,7 @@ import { Card, CardContent } from "@/components/ui/card"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { intlLocale, t } from "@/i18n"; import { api } from "@/lib/api"; +import { formatTokens } from "@/lib/format"; import type { InterceptAction, InterceptRule, @@ -62,13 +63,6 @@ import type { Tool, } from "@/lib/types"; -// fmtTokens compacts token counts (1.2k / 3.4M) for approval usage stats. -function fmtTokens(n: number): string { - if (n >= 1_000_000) return (n / 1_000_000).toFixed(1) + "M"; - if (n >= 1000) return (n / 1000).toFixed(1) + "k"; - return String(n); -} - // tRich translates a sentence whose {placeholders} are rendered as React nodes (e.g. emphasised spans or code). function tRich(key: string, nodes: Record): React.ReactNode[] { return t(key) @@ -101,7 +95,11 @@ function JudgeSparkbars({ daily }: { daily: JudgeDayUsage[] }) { return (
@@ -342,10 +340,10 @@ function JudgeCard() {
- - - - + + + +
{usage.daily.length > 0 && (
diff --git a/web/src/app/(main)/system/skills/page.tsx b/web/src/app/(main)/system/skills/page.tsx index c289b75fd..099c9620d 100644 --- a/web/src/app/(main)/system/skills/page.tsx +++ b/web/src/app/(main)/system/skills/page.tsx @@ -41,21 +41,12 @@ import { SheetTitle, } from "@/components/ui/sheet"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; +import { formatShortDateTime } from "@/lib/format"; import { cn } from "@/lib/utils"; import { api } from "@/lib/api"; -import { intlLocale, t } from "@/i18n"; +import { t } from "@/i18n"; import type { Agent, SkillItem, MCPServer, SkillCall, MissingSkill } from "@/lib/types"; -function fmtTime(ts?: string) { - if (!ts) return t("Never called"); - return new Date(ts).toLocaleString(intlLocale, { - month: "2-digit", - day: "2-digit", - hour: "2-digit", - minute: "2-digit", - }); -} - // ── Tree node ────────────────────────────────────────────────────────────── interface TreeNode { name: string; @@ -264,7 +255,9 @@ function SkillsOverview({ className="flex w-full items-center gap-2 rounded px-1.5 py-1 text-left hover:bg-muted" > {s.name} - {fmtTime(s.last_used)} + + {formatShortDateTime(s.last_used, { seconds: false, empty: t("Never called") })} + ))}
@@ -738,7 +731,9 @@ export default function SkillsPage() {
{m.skill} {t("{count} calls", { count: m.calls })} - {fmtTime(m.last_used)} + + {formatShortDateTime(m.last_used, { seconds: false, empty: t("Never called") })} +
))}
@@ -804,7 +799,10 @@ export default function SkillsPage() { {s.calls > 0 && ( {s.calls} @@ -893,8 +891,14 @@ export default function SkillsPage() {

{t("Tasks covered")}

-

- {fmtTime(selectedSkill.last_used)} +

+ {formatShortDateTime(selectedSkill.last_used, { seconds: false, empty: t("Never called") })}

{t("Last called")}

@@ -917,7 +921,9 @@ export default function SkillsPage() {
{usageCalls.map((c, i) => (
- {fmtTime(c.ts)} + + {formatShortDateTime(c.ts, { seconds: false, empty: t("Never called") })} + {c.agent_key || "—"} {c.task_id > 0 ? t("Task #{id}", { id: c.task_id }) : c.session_id ? t("Chat session") : "—"} diff --git a/web/src/components/approval-records.tsx b/web/src/components/approval-records.tsx index 7441b513e..fd5a052f2 100644 --- a/web/src/components/approval-records.tsx +++ b/web/src/components/approval-records.tsx @@ -46,20 +46,10 @@ import type { InterceptReviewInput, InterceptRisk, } from "@/lib/types"; +import { formatShortDateTime } from "@/lib/format"; import { cn } from "@/lib/utils"; import { setVisibleInterval } from "@/lib/polling"; -import { intlLocale, t } from "@/i18n"; - -function fmtTime(value?: string) { - if (!value) return "—"; - return new Date(value).toLocaleString(intlLocale, { - month: "2-digit", - day: "2-digit", - hour: "2-digit", - minute: "2-digit", - second: "2-digit", - }); -} +import { t } from "@/i18n"; function source(row: InterceptApprovalRow) { if (row.decision_source) return row.decision_source; @@ -477,9 +467,9 @@ export function ApprovalDetail({
{t("Requested at")}
-
{fmtTime(row.created_at)}
+
{formatShortDateTime(row.created_at, { empty: "—" })}
{t("Decided at")}
-
{fmtTime(current.decided_at)}
+
{formatShortDateTime(current.decided_at, { empty: "—" })}
{t("Decided by")}
@@ -585,7 +575,7 @@ export function ApprovalDetail({

{t("Visible conversation context")}

{t('Conversation record excerpt saved at {time}. What the model actually used follows "Model review input".', { - time: fmtTime(audit.captured_at), + time: formatShortDateTime(audit.captured_at, { empty: "—" }), })}

{audit.context_truncated ? ( @@ -645,7 +635,11 @@ export function ApprovalDetail({
{t("Model review input SHA-256: {value}", { value: audit.model_input_digest })}
) : null} {audit.execution_ended_at ? ( -
{t("Result recorded at: {time}", { time: fmtTime(audit.execution_ended_at) })}
+
+ {t("Result recorded at: {time}", { + time: formatShortDateTime(audit.execution_ended_at, { empty: "—" }), + })} +
) : null}
@@ -805,10 +799,10 @@ function ApprovalTable({ - {fmtTime(row.created_at)} + {formatShortDateTime(row.created_at, { empty: "—" })} - {fmtTime(row.decided_at)} + {formatShortDateTime(row.decided_at, { empty: "—" })} {open ? ( diff --git a/web/src/components/http-code-block.tsx b/web/src/components/http-code-block.tsx index d21189363..b447656d2 100644 --- a/web/src/components/http-code-block.tsx +++ b/web/src/components/http-code-block.tsx @@ -6,17 +6,10 @@ import { toast } from "sonner"; import { Button } from "@/components/ui/button"; import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"; +import { httpStatusTone } from "@/lib/status"; import { cn, copyText } from "@/lib/utils"; import { t } from "@/i18n"; -export function statusTone(status: number) { - if (status >= 500) return "text-red-500"; - if (status >= 400) return "text-amber-500"; - if (status >= 300) return "text-blue-500"; - if (status >= 200) return "text-emerald-500"; - return "text-muted-foreground"; -} - function StartLine({ line }: { line: string }) { const response = /^(HTTP\/\S+)(\s+)(\d{3})(.*)$/.exec(line); if (response) { @@ -24,7 +17,7 @@ function StartLine({ line }: { line: string }) { <> {response[1]} {response[2]} - {response[3]} + {response[3]} {response[4]} ); diff --git a/web/src/components/transcript.tsx b/web/src/components/transcript.tsx index 44f2dd08c..6fac8558a 100644 --- a/web/src/components/transcript.tsx +++ b/web/src/components/transcript.tsx @@ -24,6 +24,7 @@ import { Button } from "@/components/ui/button"; import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible"; import { ApprovalDetail } from "@/components/approval-records"; import { reportsBashExit127 } from "@/lib/bash-exit-status"; +import { formatBytes } from "@/lib/format"; import type { Activity, InterceptPending } from "@/lib/types"; // ---- per-agent lane color (planner + work#1/#2/#3 …) --------------------------- @@ -565,18 +566,6 @@ function MessageBlock({ ); } -// UserRow renders a right-aligned chat bubble: either a human turn (the message you -// sent the main agent) or, in a worker session, the LLM-generated intent that leads -// it (intent=true) — same bubble, but a target icon instead of the human avatar. -// summary is a truncated first line, so the full message is pulled from the detail -// and shown in full (bubble is whitespace-pre-wrap, so long/multi-line text wraps). -// fmtBytes renders a human file size for attachment chips. -function fmtBytes(n: number): string { - if (n >= 1 << 20) return `${(n / (1 << 20)).toFixed(1)} MB`; - if (n >= 1 << 10) return `${(n / (1 << 10)).toFixed(1)} KB`; - return `${n} B`; -} - type MsgAttachment = { name: string; path: string; size: number }; // parseUserBody splits a user turn's body into text + attachments. The backend stores @@ -641,7 +630,7 @@ function UserRow({ step, intent, getDetail }: { step: Activity; intent?: boolean > {a.name} - {fmtBytes(a.size)} + {formatBytes(a.size)}
))} diff --git a/web/src/lib/format.ts b/web/src/lib/format.ts new file mode 100644 index 000000000..f623f9f1a --- /dev/null +++ b/web/src/lib/format.ts @@ -0,0 +1,55 @@ +// Shared display formatters (sizes, token counts, durations, timestamps), so every +// page renders the same value the same way. + +import { intlLocale } from "@/i18n"; + +const BYTE_UNITS = ["B", "KB", "MB", "GB"] as const; + +/** Human file size: 512 B, 1.5 KB, 3.2 MB, 2.0 GB. Missing or non-positive sizes render as `empty` (default "0 B"). */ +export function formatBytes(bytes: number | null | undefined, { empty = "0 B" }: { empty?: string } = {}): string { + if (bytes == null || !Number.isFinite(bytes) || bytes <= 0) return empty; + let value = bytes; + let unit = 0; + while (value >= 1024 && unit < BYTE_UNITS.length - 1) { + value /= 1024; + unit++; + } + return unit === 0 ? `${value} B` : `${value.toFixed(1)} ${BYTE_UNITS[unit]}`; +} + +/** Compact token count: 950, 1.2k, 25k, 1.5M, 12M (one decimal only below 10k / 10M). */ +export function formatTokens(n: number): string { + if (n >= 1_000_000) return `${(n / 1_000_000).toFixed(n >= 10_000_000 ? 0 : 1)}M`; + if (n >= 1000) return `${(n / 1000).toFixed(n >= 10_000 ? 0 : 1)}k`; + return String(n); +} + +/** Elapsed time from milliseconds: 42s, 3m05s, 2h07m. */ +export function formatDurationMs(ms: number): string { + const s = Math.floor(ms / 1000); + if (s < 60) return `${s}s`; + const m = Math.floor(s / 60); + if (m < 60) return `${m}m${String(s % 60).padStart(2, "0")}s`; + const h = Math.floor(m / 60); + return `${h}h${String(m % 60).padStart(2, "0")}m`; +} + +/** + * Short local timestamp: "11-26 14:03:22" (month-day hour:minute:second in the UI locale). + * `seconds: false` drops the seconds, `year: true` prefixes a 2-digit year, and a + * missing value renders as `empty`. + */ +export function formatShortDateTime( + value: string | number | null | undefined, + { seconds = true, year = false, empty = "" }: { seconds?: boolean; year?: boolean; empty?: string } = {}, +): string { + if (value == null || value === "") return empty; + return new Date(value).toLocaleString(intlLocale, { + ...(year ? { year: "2-digit" as const } : {}), + month: "2-digit", + day: "2-digit", + hour: "2-digit", + minute: "2-digit", + ...(seconds ? { second: "2-digit" as const } : {}), + }); +} diff --git a/web/src/lib/status.ts b/web/src/lib/status.ts index 725e03353..86c248daa 100644 --- a/web/src/lib/status.ts +++ b/web/src/lib/status.ts @@ -128,3 +128,12 @@ export type StatusDomain = keyof typeof maps; export function statusMeta(domain: StatusDomain, key: string): StatusMeta { return maps[domain][key] ?? { label: t(key), tone: "neutral" }; } + +// HTTP response status code → text colour (5xx red, 4xx amber, 3xx blue, 2xx green). +export function httpStatusTone(code: number): string { + if (code >= 500) return "text-red-500"; + if (code >= 400) return "text-amber-500"; + if (code >= 300) return "text-blue-500"; + if (code >= 200) return "text-emerald-500"; + return "text-muted-foreground"; +}