diff --git a/src/dash/api/trace.ts b/src/dash/api/trace.ts index 1186e1b8..c5d29a8b 100644 --- a/src/dash/api/trace.ts +++ b/src/dash/api/trace.ts @@ -119,14 +119,17 @@ const jobs: Source = { /** SQL that leaves out runs that also touched a hidden repo (one `?` per name). */ export const hiddenSql = (hidden: string[]): string => (hidden.length ? ` AND NOT EXISTS (SELECT 1 FROM agent_run_items x WHERE x.run_id = r.id AND x.repo IN (${hidden.map(() => "?").join(",")}))` : ""); -export const RUN_COLUMNS = `r.id, r.step, r.model, r.provider, r.state, r.started_at, r.ended_at, r.input_tokens, r.output_tokens, r.cost_usd, r.summary, r.job_id, +/** Prompts whose calls are named by what they do, not by the step that makes them. */ +const PROMPT_TITLES: Record = { "lint.reference.jev": "Reference lint", "lint.reference.haiku": "Reference lint" }; + +export const RUN_COLUMNS = `r.id, r.step, r.prompt_id, r.model, r.provider, r.state, r.started_at, r.ended_at, r.input_tokens, r.output_tokens, r.cost_usd, r.summary, r.job_id, COALESCE(a.label, r.account_id) AS label, (SELECT COUNT(*) FROM agent_run_tools t WHERE t.run_id = r.id) AS tools`; -export const runEvent = (r: { id: number; step: string; model: string; provider: string; state: string; started_at: string; ended_at: string | null; input_tokens: number | null; output_tokens: number | null; +export const runEvent = (r: { id: number; step: string; prompt_id: string; model: string; provider: string; state: string; started_at: string; ended_at: string | null; input_tokens: number | null; output_tokens: number | null; cost_usd: number | null; summary: string | null; label: string | null; tools: number; job_id: number | null }): Ev => ({ id: `run:${r.id}`, kind: "model-call", at: r.started_at, head: null, actor: model(r.model, "model"), - summary: `${stepTitle(r.step)}: ${r.state === "running" ? "running" : r.state === "failed" ? "failed" : clip(r.summary, 100) || "done"}`, + summary: `${PROMPT_TITLES[r.prompt_id] ?? stepTitle(r.step)}: ${r.state === "running" ? "running" : r.state === "failed" ? "failed" : clip(r.summary, 100) || "done"}`, ref: { runId: r.id, ...(r.job_id !== null ? { jobId: r.job_id } : {}) }, - call: { model: r.model, provider: r.provider, account: r.label, state: r.state, inputTokens: r.input_tokens, outputTokens: r.output_tokens, costUsd: r.cost_usd, toolCalls: r.tools, endedAt: r.ended_at }, + call: { promptId: r.prompt_id, step: stepTitle(r.step), model: r.model, provider: r.provider, account: r.label, state: r.state, inputTokens: r.input_tokens, outputTokens: r.output_tokens, costUsd: r.cost_usd, toolCalls: r.tools, endedAt: r.ended_at }, }); const modelCalls: Source = { diff --git a/web/src/api/mock/traceMock.ts b/web/src/api/mock/traceMock.ts index 4f4d5320..817516a3 100644 --- a/web/src/api/mock/traceMock.ts +++ b/web/src/api/mock/traceMock.ts @@ -8,6 +8,21 @@ export const at = (minAgo: number) => new Date(NOW - minAgo * 60_000).toISOStrin const H1 = "3f2a9c1d0e8b7a6f5e4d3c2b1a0f9e8d7c6b5a49"; const H2 = "9b8c7d6e5f4a3b2c1d0e9f8a7b6c5d4e3f2a1b0c"; +/** The reference lint of one review: one call per text of the review (ten for Jev, one for Haiku), all in job 55. */ +const LINT: TraceEvent[] = [ + ...Array.from({ length: 11 }, (_, i): TraceEvent => { + const haiku = i === 7; + return { + id: `run:${950 + i}`, kind: "model-call", at: at(12.9 - i * 0.07), head: H2, actor: { type: "model", name: haiku ? "haiku" : "jev" }, + summary: `Reference lint: ${haiku ? "clean" : i % 4 === 3 ? "refers to documentation" : "clean"}`, ref: { runId: 950 + i, jobId: 55 }, + call: { + promptId: haiku ? "lint.reference.haiku" : "lint.reference.jev", step: "Review pull requests", model: haiku ? "haiku" : "jev", provider: haiku ? "claude" : "jev", + account: haiku ? "Team account A" : "Jev", state: "done", inputTokens: haiku ? 1_100 : 900, outputTokens: haiku ? 40 : 12, costUsd: haiku ? 0.003 : 0, toolCalls: 0, endedAt: at(12.9 - i * 0.07 - 0.02), + }, + }; + }), +]; + export const EVENTS: TraceEvent[] = ([ { id: "plan:41", kind: "plan", at: at(4), head: H2, actor: { type: "step", name: "Planner" }, summary: "Plan reviewing → verifying, waiting for CI at 9b8c7d6", ref: { head: H2 } }, { id: "check:12", kind: "check", at: at(9), head: H2, actor: { type: "step", name: "Fix-up" }, summary: "Clippy on app-core: no findings", ref: { checkId: 12, runId: 902, head: H2 } }, @@ -15,7 +30,7 @@ export const EVENTS: TraceEvent[] = ([ { id: "audit:77", kind: "write", at: at(12), head: H2, actor: { type: "step", name: "AutoCraft" }, summary: "Posted review", ref: { auditRowid: 77, head: H2 } }, { id: "run:903", kind: "model-call", at: at(14), head: H2, actor: { type: "model", name: "opus" }, summary: "Review pull requests: take-fix with two fixes", ref: { runId: 903, jobId: 55 }, - call: { model: "opus", provider: "claude", account: "Team account B", state: "done", inputTokens: 48_200, outputTokens: 2_900, costUsd: 0.91, toolCalls: 7, endedAt: at(13) }, + call: { promptId: "review.opus", step: "Review pull requests", model: "opus", provider: "claude", account: "Team account B", state: "done", inputTokens: 48_200, outputTokens: 2_900, costUsd: 0.91, toolCalls: 7, endedAt: at(13) }, }, { id: "review:opus:5", kind: "review", at: at(13), head: H2, actor: { type: "model", name: "opus" }, summary: "Opus review: take with two fixes, not sure", ref: { reviewId: "opus:5", head: H2 } }, { id: "gh:push", kind: "github", at: at(30), head: H2, actor: { type: "person", name: "contributor" }, summary: "Pushed 9b8c7d6", ref: { head: H2 } }, @@ -23,10 +38,13 @@ export const EVENTS: TraceEvent[] = ([ { id: "decision:d9:asked", kind: "decision", at: at(95), head: H1, actor: { type: "step", name: "Ask decisions" }, summary: "Asked: Merge this fix?", ref: { decisionId: "designcraft#1484:merge" } }, { id: "run:901", kind: "model-call", at: at(120), head: H1, actor: { type: "model", name: "opus" }, summary: "Review pull requests: hold", ref: { runId: 901, jobId: 52 }, - call: { model: "opus", provider: "claude", account: "Team account C", state: "done", inputTokens: 51_000, outputTokens: 3_300, costUsd: 0.97, toolCalls: 11, endedAt: at(118) }, + call: { promptId: "review.opus", step: "Review pull requests", model: "opus", provider: "claude", account: "Team account C", state: "done", inputTokens: 51_000, outputTokens: 3_300, costUsd: 0.97, toolCalls: 11, endedAt: at(118) }, }, { id: "plan:38", kind: "plan", at: at(125), head: H1, actor: { type: "step", name: "Planner" }, summary: "Plan started as reviewing", ref: { head: H1 } }, - { id: "gh:opened", kind: "github", at: at(130), head: H1, actor: { type: "person", name: "contributor" }, summary: "Opened pull request on GitHub by contributor", ref: {} }, + { id: "gh:opened", kind: "github", at: at(400 * 1440), head: H1, actor: { type: "person", name: "contributor" }, summary: "Opened pull request on GitHub by contributor", ref: {} }, + { id: "gh:push0", kind: "github", at: at(6 * 1440 + 30), head: H1, actor: { type: "person", name: "contributor" }, summary: "Pushed 3f2a9c1", ref: { head: H1 } }, + { id: "comment:c1", kind: "github", at: at(1000), head: H1, actor: { type: "person", name: "maintainer" }, summary: "Posted a comment, 96 characters", ref: { commentId: "c1" } }, + ...LINT, ] as TraceEvent[]).sort((a, b) => (a.at < b.at ? 1 : a.at > b.at ? -1 : a.id < b.id ? 1 : -1)); const OFF_EVENTS: TraceEvent[] = [ @@ -65,7 +83,7 @@ export function traceRunDetail(id: number): AgentRunDetail | null { const c = e.call; const text = (n: number) => Array.from({ length: n }, (_, i) => `Line ${i + 1} of the model text for ${e.summary}.`).join("\n"); return { - id, jobId: e.ref.jobId ?? null, step: "opus-review", stage: 5, promptId: "opus-review", promptVersion: "a1b2c3d", provider: "claude", model: c.model, accountId: "b", accountLabel: c.account, + id, jobId: e.ref.jobId ?? null, step: "opus-review", stage: 5, promptId: c.promptId ?? "review.opus", promptVersion: "a1b2c3d", provider: "claude", model: c.model, accountId: "b", accountLabel: c.account, items: [], itemCount: 1, state: "done", startedAt: e.at, endedAt: c.endedAt, inputTokens: c.inputTokens, outputTokens: c.outputTokens, cacheReadTokens: null, cacheWriteTokens: null, costUsd: c.costUsd, summary: null, prompt: text(40), output: text(18), error: null, tools: TOOLS, }; diff --git a/web/src/api/types.ts b/web/src/api/types.ts index 3c0ea0a5..bb806981 100644 --- a/web/src/api/types.ts +++ b/web/src/api/types.ts @@ -1793,6 +1793,8 @@ export type TraceEvent = { ref: TraceRef; /** Model calls only. */ call?: { + /** The prompt the call ran; calls of one step and prompt family are grouped on the item page. */ + promptId?: string; /** The step's display name. */ step?: string; model: string; provider: string; account: string | null; state: string; inputTokens: number | null; outputTokens: number | null; costUsd: number | null; toolCalls: number; endedAt: string | null; }; diff --git a/web/src/lib/format.ts b/web/src/lib/format.ts index 92e3e4b7..aeebeecf 100644 --- a/web/src/lib/format.ts +++ b/web/src/lib/format.ts @@ -13,6 +13,26 @@ export function ago(isoTime: string, short = true): string { return `${v} ${word}${v === 1 ? "" : "s"} ago`; } +const MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; + +/** + * An event time for reading: "now", "12m ago", then the local clock time ("14:32") for the rest of today, + * "yesterday 14:32", "Nov 3 14:32" earlier this year and "Nov 3 2025" before that. Times in the future read as "now". + */ +export function eventTime(isoTime: string): string { + const t = Date.parse(isoTime); + const s = Math.max(0, (now() - t) / 1000); + if (s < 60) return "now"; + if (s < 3600) return `${Math.floor(s / 60)}m ago`; + const d = new Date(t), n = new Date(now()); + const midnight = (x: Date) => new Date(x.getFullYear(), x.getMonth(), x.getDate()).getTime(); + const days = Math.round((midnight(n) - midnight(d)) / 86400_000); + if (days <= 0) return clock(t); + if (days === 1) return `yesterday ${clock(t)}`; + const md = `${MONTHS[d.getMonth()]} ${d.getDate()}`; + return d.getFullYear() === n.getFullYear() ? `${md} ${clock(t)}` : `${md} ${d.getFullYear()}`; +} + export const num = (n: number) => n.toLocaleString("en"); export const pct = (a: number, b: number) => (b ? `${Math.round((a / b) * 100)}%` : "–"); diff --git a/web/src/lib/trace.ts b/web/src/lib/trace.ts index 6504e70d..85db9801 100644 --- a/web/src/lib/trace.ts +++ b/web/src/lib/trace.ts @@ -64,3 +64,44 @@ export const NEXT_LABEL: Record = { merge: "Merge", }; export const nextLabel = (kind: string) => NEXT_LABEL[kind] ?? kind.replace(/[-_]/g, " ").replace(/^./, (c) => c.toUpperCase()); + +export type TraceRow = { event: TraceEvent; calls?: undefined } | { event: TraceEvent; calls: TraceEvent[] }; + +/** Calls of one prompt close in time: no job id on both sides means "within five minutes". */ +const GROUP_GAP_MS = 5 * 60_000; +const family = (promptId: string) => (promptId.startsWith("lint.reference.") ? "lint.reference" : promptId); +const sameRun = (a: TraceEvent, b: TraceEvent) => { + if (!a.call?.promptId || !b.call?.promptId || a.call.step !== b.call.step || family(a.call.promptId) !== family(b.call.promptId)) return false; + if (a.ref.jobId !== undefined || b.ref.jobId !== undefined) return a.ref.jobId === b.ref.jobId; + return Math.abs(Date.parse(a.at) - Date.parse(b.at)) <= GROUP_GAP_MS; +}; + +/** Consecutive model calls of the same step and prompt (the reference lint runs once per review text) become one row; its `event` is the newest call and `calls` all of them, newest first. */ +export function groupCalls(events: TraceEvent[]): TraceRow[] { + const out: TraceRow[] = []; + for (const e of events) { + const last = out[out.length - 1]; + const prev = last && (last.calls ? last.calls[last.calls.length - 1]! : last.event); + if (last && prev && e.kind === "model-call" && prev.kind === "model-call" && sameRun(prev, e)) { + if (last.calls) last.calls.push(e); + else out[out.length - 1] = { event: last.event, calls: [last.event, e] }; + } else out.push({ event: e }); + } + return out; +} + +const modelName = (m: string) => m.charAt(0).toUpperCase() + m.slice(1); + +/** "Reference lint: 10 Jev calls, 1 Haiku call, $0.04". */ +export function callGroupSummary(calls: TraceEvent[]): string { + const counts = new Map(); + let cost = 0; + for (const c of calls) { + const m = modelName(c.call?.model ?? "model"); + counts.set(m, (counts.get(m) ?? 0) + 1); + cost += c.call?.costUsd ?? 0; + } + const title = calls[0]!.summary.split(": ")[0]!; + const parts = [...counts].sort((a, b) => b[1] - a[1]).map(([m, n]) => `${n} ${m} call${n === 1 ? "" : "s"}`); + return `${title}: ${parts.join(", ")}${cost > 0 ? `, $${cost.toFixed(cost < 0.1 ? 3 : 2)}` : ""}`; +} diff --git a/web/src/modules/accounts/views.tsx b/web/src/modules/accounts/views.tsx index 58d9a842..d1c7ff25 100644 --- a/web/src/modules/accounts/views.tsx +++ b/web/src/modules/accounts/views.tsx @@ -5,7 +5,7 @@ import { KeyIcon, PencilSimpleIcon } from "@phosphor-icons/react"; import { Dialog } from "radix-ui"; import { useApi, useQuery } from "../../api/client"; import type { ClaudeAccount } from "../../api/types"; -import { ago } from "../../lib/format"; +import { eventTime } from "../../lib/format"; import { useUser } from "../../shell/UserContext"; import { Badge } from "../../ui/atoms/Badge"; import { Button } from "../../ui/atoms/Button"; @@ -120,9 +120,9 @@ function Row({ a, operator, onChanged }: { a: ClaudeAccount; operator: boolean;
Login expires
{when(a.auth.expiresAt)}
Status read
-
{a.auth.checkedAt ? ago(a.auth.checkedAt, false) : "never"}
+
{a.auth.checkedAt ? eventTime(a.auth.checkedAt) : "never"}
Usage read
-
{a.usage.readAt ? ago(a.usage.readAt, false) : "never"}
+
{a.usage.readAt ? eventTime(a.usage.readAt) : "never"}
{operator && (
diff --git a/web/src/modules/admin/accessViews.tsx b/web/src/modules/admin/accessViews.tsx index 9642c853..2954e9b1 100644 --- a/web/src/modules/admin/accessViews.tsx +++ b/web/src/modules/admin/accessViews.tsx @@ -7,7 +7,8 @@ import { Badge } from "../../ui/atoms/Badge"; import { Button } from "../../ui/atoms/Button"; import { cn } from "../../ui/cn"; import { Count } from "../../ui/atoms/Heading"; -import { ago, day, when } from "../../lib/format"; +import { day, when } from "../../lib/format"; +import { TimeAgo } from "../../ui/atoms/TimeAgo"; import { useIsPhone } from "../../shell/useMedia"; import { Block } from "../../ui/molecules/Block"; import { ConfirmButton } from "../../ui/molecules/ConfirmButton"; @@ -215,7 +216,7 @@ function Sessions({ sessions }: { sessions: SessionInfo[] }) { {s.current && this session}
- {browser(s.userAgent)} · seen {ago(s.lastSeen, false)} + {browser(s.userAgent)} · seen
{revoke(s)} @@ -251,7 +252,7 @@ function Sessions({ sessions }: { sessions: SessionInfo[] }) { {when(s.createdAt)} - {ago(s.lastSeen, false)} + {when(s.expiresAt)} {revoke(s)} diff --git a/web/src/modules/admin/repoParts.tsx b/web/src/modules/admin/repoParts.tsx index 7bf87520..6b47bf70 100644 --- a/web/src/modules/admin/repoParts.tsx +++ b/web/src/modules/admin/repoParts.tsx @@ -2,7 +2,7 @@ import { useApi } from "../../api/client"; import type { TrackedRepo } from "../../api/types"; import { Badge } from "../../ui/atoms/Badge"; import { Button } from "../../ui/atoms/Button"; -import { ago, num } from "../../lib/format"; +import { num, eventTime } from "../../lib/format"; import { useUser } from "../../shell/UserContext"; import { ConfirmButton } from "../../ui/molecules/ConfirmButton"; import { Switch } from "../../ui/atoms/Switch"; @@ -134,7 +134,7 @@ export function PipelineSwitch({ r, write }: { r: TrackedRepo; write: Write }) { } export const synced = (r: TrackedRepo) => - r.syncedAt ? `${ago(r.syncedAt, false)}` : "never"; + r.syncedAt ? `${eventTime(r.syncedAt)}` : "never"; export const maybe = (n: number | null) => (n === null ? "–" : num(n)); /** The checks whose failure does not stop a merge: a list for everyone, with remove and add for operators. */ diff --git a/web/src/modules/agents/views.tsx b/web/src/modules/agents/views.tsx index 8f5c0387..37e780a6 100644 --- a/web/src/modules/agents/views.tsx +++ b/web/src/modules/agents/views.tsx @@ -7,7 +7,8 @@ import { CaretDownIcon, CaretRightIcon, XIcon } from "@phosphor-icons/react"; import { usePagedQuery, useQuery } from "../../api/client"; import type { AgentRun, AgentRunDetail, AgentRunFilter, AgentRunPage, AgentRunState } from "../../api/types"; import type { ViewProps } from "../../registry/types"; -import { ago, nowMs, num, span } from "../../lib/format"; +import { nowMs, num, span } from "../../lib/format"; +import { TimeAgo } from "../../ui/atoms/TimeAgo"; import { useNow } from "../../lib/useNow"; import { Badge, type Tone } from "../../ui/atoms/Badge"; import { Button } from "../../ui/atoms/Button"; @@ -141,7 +142,7 @@ function RecentRuns({ selected }: { selected?: number }) { - {ago(r.startedAt, true)} ago + ago @@ -219,7 +220,7 @@ function DetailBody({ id }: { id: number }) {
Started
- {ago(r.startedAt, false)} · {r.endedAt ? `took ${elapsed(r)}` : `running for ${elapsed(r)}`} + · {r.endedAt ? `took ${elapsed(r)}` : `running for ${elapsed(r)}`}
Tokens
diff --git a/web/src/modules/batch/views.tsx b/web/src/modules/batch/views.tsx index 51ce3dee..9e3a24ff 100644 --- a/web/src/modules/batch/views.tsx +++ b/web/src/modules/batch/views.tsx @@ -77,7 +77,7 @@ function Ci({ b }: { b: BatchDetail }) { if (b.prNumber === null) return null; const ci = b.ci; return ( - read : undefined}> + read : undefined}> {!ci ? (

No CI read yet.

) : ( diff --git a/web/src/modules/decisions/Conversation.tsx b/web/src/modules/decisions/Conversation.tsx index 333c54f3..ee03ef81 100644 --- a/web/src/modules/decisions/Conversation.tsx +++ b/web/src/modules/decisions/Conversation.tsx @@ -5,7 +5,8 @@ import type { ConversationCard, ConversationTurn, RepoName } from "../../api/typ import { Avatar } from "../../ui/atoms/Avatar"; import { Button } from "../../ui/atoms/Button"; import { Markdown } from "../../ui/molecules/Markdown"; -import { ago } from "../../lib/format"; +import { } from "../../lib/format"; +import { TimeAgo } from "../../ui/atoms/TimeAgo"; import { useNow } from "../../lib/useNow"; const message = (e: unknown) => (e instanceof Error ? e.message : String(e)); @@ -84,7 +85,7 @@ function Turn({ t, operator }: { t: ConversationTurn; operator: boolean }) {
  • {t.body} - {ago(t.at)} +
  • ); } @@ -93,7 +94,7 @@ function Turn({ t, operator }: { t: ConversationTurn; operator: boolean }) {
    {t.kind === "opus" ? "Opus" : t.login} - {ago(t.at)} +
    {t.kind === "opus" ? :

    {t.body}

    } @@ -181,7 +182,7 @@ function ActionCard({ a, operator }: { a: ConversationCard; operator: boolean }) ) : ( a.done.label )}{" "} - · {ago(a.done.at, false)} + · {a.by ? ` · ${a.by}` : ""}

    )} diff --git a/web/src/modules/decisions/DecisionDetail.tsx b/web/src/modules/decisions/DecisionDetail.tsx index 5be2ce87..2626dcd9 100644 --- a/web/src/modules/decisions/DecisionDetail.tsx +++ b/web/src/modules/decisions/DecisionDetail.tsx @@ -14,7 +14,8 @@ import { ConfirmButton, useWrite } from "../admin/parts"; import { Count } from "../../ui/atoms/Heading"; import { Markdown, Collapsible } from "../../ui/molecules/Markdown"; import { cn } from "../../ui/cn"; -import { ago } from "../../lib/format"; +import { } from "../../lib/format"; +import { TimeAgo } from "../../ui/atoms/TimeAgo"; import { ClaimPill, ClassifierLines, Disclosure, Facts, KindTag, RelatedList } from "./parts"; import { Refs } from "./Refs"; import { FeedbackBox } from "./FeedbackBox"; @@ -172,7 +173,7 @@ export function DecisionBody({ )} {!isBatch && } - asked {ago(d.askedAt)} ago + asked {!isBatch && ( @@ -200,7 +201,7 @@ export function DecisionBody({ AI summary - · {d.summaryBy} · {ago(d.summaryAt)} ago + · {d.summaryBy} ·

    @@ -384,7 +385,7 @@ export function AnsweredState({ d, canUndo }: { d: Decision; canUndo: boolean }) {label} by {d.answeredBy} - {d.adoptedOpinion ? `, using ${d.adoptedOpinion.login}'s answer` : ""} · {ago(d.answeredAt!)} ago{backlog ? "" : ` · ${d.appliedAt ? "applied" : "not applied yet"}`} + {d.adoptedOpinion ? `, using ${d.adoptedOpinion.login}'s answer` : ""} · {backlog ? "" : ` · ${d.appliedAt ? "applied" : "not applied yet"}`} {d.answerNote && “{d.answerNote}”} {backlog && canUndo && ( diff --git a/web/src/modules/decisions/InboxList.tsx b/web/src/modules/decisions/InboxList.tsx index f95e18ab..6adcf66e 100644 --- a/web/src/modules/decisions/InboxList.tsx +++ b/web/src/modules/decisions/InboxList.tsx @@ -8,7 +8,8 @@ import { useHotkeys, useShortcutHelp } from "../../shell/keyboard"; import { Count } from "../../ui/atoms/Heading"; import { Button } from "../../ui/atoms/Button"; import { cn } from "../../ui/cn"; -import { ago, ageDays } from "../../lib/format"; +import { ago, ageDays, when } from "../../lib/format"; +import { TimeAgo } from "../../ui/atoms/TimeAgo"; import { ItemRef } from "../../ui/molecules/ItemRef"; import { ClaimPill, KIND_ICON } from "./parts"; import { canActOn } from "./DecisionDetail"; @@ -135,8 +136,8 @@ function Row({ d, canUndo, active, checked, mine, onOpen, activeRef }: { d: Deci

    { if (e.target === e.currentTarget && (e.key === "Enter" || e.key === " ")) { e.preventDefault(); onOpen(); } }} className="min-w-0 flex-1 cursor-pointer rounded-none py-2 pr-3 text-left">
    {d.title} - - {ago(d.askedAt)} + +
    diff --git a/web/src/modules/decisions/Thread.tsx b/web/src/modules/decisions/Thread.tsx index 63e3ecdd..a7398ee8 100644 --- a/web/src/modules/decisions/Thread.tsx +++ b/web/src/modules/decisions/Thread.tsx @@ -5,7 +5,8 @@ import type { ViewProps } from "../../registry/types"; import { Avatar } from "../../ui/atoms/Avatar"; import { cn } from "../../ui/cn"; import { Count } from "../../ui/atoms/Heading"; -import { ago } from "../../lib/format"; +import { } from "../../lib/format"; +import { TimeAgo } from "../../ui/atoms/TimeAgo"; import { localActions, useDecisionList, usePinned, useSelection } from "./state"; import { scrollToWorkflow } from "./Workflow"; import { canAct, canComment } from "../../registry/permissions"; @@ -99,7 +100,7 @@ export function FeedbackList({ d, me, onUse, onRetract, compact }: { d: Decision {e.write ? "write" : "no write"} )} - {ago(e.at)} +
    {e.text &&

    {e.text}

    } diff --git a/web/src/modules/decisions/parts.tsx b/web/src/modules/decisions/parts.tsx index 3fc5cdaa..9534fca8 100644 --- a/web/src/modules/decisions/parts.tsx +++ b/web/src/modules/decisions/parts.tsx @@ -15,7 +15,8 @@ import { Avatar } from "../../ui/atoms/Avatar"; import { Kbd } from "../../ui/atoms/Kbd"; import { Count } from "../../ui/atoms/Heading"; import { cn } from "../../ui/cn"; -import { ago } from "../../lib/format"; +import { eventTime } from "../../lib/format"; +import { TimeAgo } from "../../ui/atoms/TimeAgo"; import { Refs } from "./Refs"; import { KIND_LABEL } from "./state"; import { useNow } from "../../lib/useNow"; @@ -44,11 +45,11 @@ export function ClaimPill({ claim, compact }: { claim: Decision["claim"]; compac useNow(); if (!claim) return null; return ( - + {!compact && ( - {claim.login} is viewing · {ago(claim.since)} + {claim.login} is viewing · )} diff --git a/web/src/modules/envs/views.tsx b/web/src/modules/envs/views.tsx index d79b572d..96e2bbf2 100644 --- a/web/src/modules/envs/views.tsx +++ b/web/src/modules/envs/views.tsx @@ -7,7 +7,8 @@ import { CheckIcon, CopyIcon, DownloadSimpleIcon, PencilSimpleIcon, PlusIcon, XI import { useApi, usePagedQuery, useQuery } from "../../api/client"; import type { BuildEnv, BuildSummary, BuildTask, BuildTaskDetail, Capabilities, EnvKind, Requires, TaskBatch, TaskFilter, TaskState } from "../../api/types"; import type { ViewProps } from "../../registry/types"; -import { ago, nowMs, num, span } from "../../lib/format"; +import { nowMs, num, span, eventTime } from "../../lib/format"; +import { TimeAgo } from "../../ui/atoms/TimeAgo"; import { useUser } from "../../shell/UserContext"; import { Badge, type Tone } from "../../ui/atoms/Badge"; import { Button } from "../../ui/atoms/Button"; @@ -155,7 +156,7 @@ function EnvCard({ e, operator }: { e: BuildEnv; operator: boolean }) {
    Worker
    {e.version ? `version ${e.version}` : "never connected"}
    Last seen
    -
    {e.lastSeenAt ? `${ago(e.lastSeenAt, false)}` : "never"}
    +
    {e.lastSeenAt ? `${eventTime(e.lastSeenAt)}` : "never"}
    {e.pausedReason && ( <>
    Paused
    @@ -373,8 +374,7 @@ function Tasks({ selected }: { selected?: number }) { - {ago(r.queuedAt, true)} - ago + @@ -454,7 +454,7 @@ function DetailBody({ id }: { id: number }) {
    Environment
    {t.envLabel ?? "not claimed yet"}
    Queued
    -
    {ago(t.queuedAt, false)}
    +
    Run time
    {duration(t)}
    Warm build
    @@ -474,7 +474,7 @@ function DetailBody({ id }: { id: number }) { {t.heartbeatAt && active && ( <>
    Heartbeat
    -
    {ago(t.heartbeatAt, false)}
    +
    )} diff --git a/web/src/modules/flow/Panel.tsx b/web/src/modules/flow/Panel.tsx index 62f473e3..cdc026f9 100644 --- a/web/src/modules/flow/Panel.tsx +++ b/web/src/modules/flow/Panel.tsx @@ -9,7 +9,8 @@ import { Slot } from "../../registry/Slot"; import { useUser } from "../../shell/UserContext"; import { Badge } from "../../ui/atoms/Badge"; import { cn } from "../../ui/cn"; -import { ago, num } from "../../lib/format"; +import { num } from "../../lib/format"; +import { TimeAgo } from "../../ui/atoms/TimeAgo"; import { JobBadge } from "../pipeline/views"; import { StageLimitRow } from "../pipeline/controls"; import { PromptCard } from "../prompts/views"; @@ -59,7 +60,7 @@ function StepBlock({ name, title }: { name: string; title: string }) { {j.summary ?? j.error ?? j.progress ?? "–"}
    - {ago(j.endedAt ?? j.startedAt ?? j.requestedAt)} ago · by {j.requestedBy} + · by {j.requestedBy} {j.usage?.costUsd ? ` · $${j.usage.costUsd.toFixed(2)}` : j.usage?.calls ? ` · ${num(j.usage.input + j.usage.output)} tokens` : ""} @@ -166,7 +167,7 @@ export function FlowPanel({ flow, node: n, onClose, onSelect }: { flow: Flow; no {n.facts.map((f) => (
    {f.label}
    -
    {/^\d{4}-\d\d-\d\dT/.test(f.value) ? `${ago(f.value)} ago` : f.value}
    +
    {/^\d{4}-\d\d-\d\dT/.test(f.value) ? <> : f.value}
    ))} diff --git a/web/src/modules/flow/views.tsx b/web/src/modules/flow/views.tsx index 2f85213f..b969e3ba 100644 --- a/web/src/modules/flow/views.tsx +++ b/web/src/modules/flow/views.tsx @@ -8,7 +8,8 @@ import type { Flow } from "../../api/types"; import type { ViewProps } from "../../registry/types"; import { useMedia } from "../../shell/useMedia"; import { RepoSelect } from "../../ui/molecules/RepoSelect"; -import { ago, num } from "../../lib/format"; +import { num } from "../../lib/format"; +import { TimeAgo } from "../../ui/atoms/TimeAgo"; import { ErrorLine, useUrlState } from "../admin/parts"; import { PipelineSwitch } from "../pipeline/controls"; import { Chart } from "./Chart"; @@ -87,8 +88,8 @@ export function FlowView(_: ViewProps) {

    Pipeline flow

    {flow && (

    - {num(open)} open items{repo ? ` in ${repo}` : ""} · last sync {flow.lastSync ? `${ago(flow.lastSync)} ago` : "never"} - {flow.countedAt && ` · counted ${ago(flow.countedAt)} ago`} + {num(open)} open items{repo ? ` in ${repo}` : ""} · last sync {flow.lastSync ? <> : "never"} + {flow.countedAt && <> · counted } {flow.uncounted > 0 && ` · ${num(flow.uncounted)} repos not counted yet`}

    )} diff --git a/web/src/modules/item/PrWork.tsx b/web/src/modules/item/PrWork.tsx index 32ce5d56..50e6a33a 100644 --- a/web/src/modules/item/PrWork.tsx +++ b/web/src/modules/item/PrWork.tsx @@ -10,7 +10,8 @@ import { Markdown } from "../../ui/molecules/Markdown"; import { useUser } from "../../shell/UserContext"; import { ConfirmButton, ErrorLine, useWrite } from "../admin/parts"; import { decisionPath } from "../../lib/links"; -import { ago, span } from "../../lib/format"; +import { span } from "../../lib/format"; +import { TimeAgo } from "../../ui/atoms/TimeAgo"; import { useNow } from "../../lib/useNow"; function Box({ title, aside, children }: { title: string; aside?: ReactNode; children: ReactNode }) { @@ -45,7 +46,7 @@ function Verify({ v }: { v: ItemVerification }) { {KIND[v.kind]} {v.headSha.slice(0, 7)} {!v.current && Older head} - {v.finishedAt ? `finished ${ago(v.finishedAt)} ago` : `planned ${ago(v.createdAt)} ago`} + {v.finishedAt ? <>finished : <>planned }

    {v.reason}

    {p && ( @@ -188,7 +189,7 @@ function Postmerge({ p, repo }: { p: ItemPostmerge; repo: string }) { {p.error ? No review : p.findings.length === 0 ? No findings : null} {p.error && {p.error}} {p.mergeSha.slice(0, 7)} - {ago(p.at)} ago + {p.earlier.length > 0 && (
    @@ -218,7 +219,7 @@ function Premerge({ rows }: { rows: ItemPremerge[] }) { {r.error ? No review : r.findings.length === 0 ? No findings : null} {r.error && {r.error} ({r.tries} {r.tries === 1 ? "try" : "tries"})} {r.model && {r.model}} - {ago(r.at)} ago +
    {r.findings.length > 0 && (
      @@ -259,7 +260,7 @@ function PatchChecks({ rows }: { rows: ItemPatchCheck[] }) { {c.verdict === "approve" ? "Approved" : "Rejected"} Opus check · round {c.round} {c.subject.slice(0, 7)} - {ago(c.createdAt)} ago + {c.reasons &&

      {c.reasons}

      } {c.problems.length > 0 && ( @@ -297,7 +298,7 @@ function Fixups({ rows }: { rows: ItemFixup[] }) { {f.fromHead.slice(0, 7)} {f.toHead && ` → ${f.toHead.slice(0, 7)}`} - {ago(f.createdAt)} ago + {f.reason &&

      {f.reason}

      } {f.files.length > 0 &&

      {f.files.join(", ")}

      } @@ -330,7 +331,7 @@ function Actions({ rows, repo, number }: { rows: ItemAction[]; repo: string; num {a.decisionId} - {ago(a.createdAt)} ago + {a.reason &&

      {a.reason}

      } diff --git a/web/src/modules/item/TracePanel.tsx b/web/src/modules/item/TracePanel.tsx index b4e416ed..c1544c84 100644 --- a/web/src/modules/item/TracePanel.tsx +++ b/web/src/modules/item/TracePanel.tsx @@ -8,7 +8,7 @@ import { TimelineEvent } from "../../ui/molecules/TimelineEvent"; import { TraceFilters } from "../../ui/molecules/TraceFilters"; import { HeadGroup } from "../../ui/organisms/HeadGroup"; import { TraceHeader } from "../../ui/organisms/TraceHeader"; -import { groupByHead, pushedBy, TRACE_KIND } from "../../lib/trace"; +import { callGroupSummary, groupByHead, groupCalls, pushedBy, TRACE_KIND } from "../../lib/trace"; import { TraceEventBody } from "./TraceEventBody"; const PAGE = 50; @@ -93,21 +93,41 @@ export function TracePanel({ repo, number, it }: { repo: string; number: number; {groups.length === 0 &&

      No events match.

      } {groups.map((g) => ( - {g.events.map((e) => ( - toggle(e.id)} - > - - - ))} + {groupCalls(g.events).map((r) => { + const row = (e: TraceEvent) => ( + toggle(e.id)} + > + + + ); + if (!r.calls) return row(r.event); + const gid = `group:${r.event.id}`; + return ( + c.id === hashEvent()) !== open.has(gid)} + onToggle={() => toggle(gid)} + flush + > +
        {r.calls.map(row)}
      +
      + ); + })}
      ))} diff --git a/web/src/modules/item/views.tsx b/web/src/modules/item/views.tsx index ea528806..931c6258 100644 --- a/web/src/modules/item/views.tsx +++ b/web/src/modules/item/views.tsx @@ -27,7 +27,8 @@ import { Badge, type Tone } from "../../ui/atoms/Badge"; import { PriorityBadge } from "../../ui/atoms/PriorityBadge"; import { Count } from "../../ui/atoms/Heading"; import { cn } from "../../ui/cn"; -import { ago, num } from "../../lib/format"; +import { num } from "../../lib/format"; +import { TimeAgo } from "../../ui/atoms/TimeAgo"; import { KindTag, tallyOf } from "../decisions/parts"; import { RecommendationLine } from "../../ui/molecules/RecommendationLine"; import { Markdown, Collapsible } from "../../ui/molecules/Markdown"; @@ -144,7 +145,7 @@ function Header({ it }: { it: Item }) { - {it.author} opened {ago(it.createdAt)} ago in {it.repo} + {it.author} opened in {it.repo} @@ -241,7 +242,7 @@ function Properties({ it }: { it: Item }) { ))} - {ago(it.updatedAt, false)} + ); @@ -300,7 +301,7 @@ function Verdicts({ cls }: { cls: Classification[] }) { {c.classifier} {c.typeLabel} want {c.want} - {ago(c.at)} + {c.reference &&
      Reference: {c.reference}
      }
      @@ -324,7 +325,7 @@ function Verdicts({ cls }: { cls: Classification[] }) { {cls.map((c) => ( - {c.classifier} {ago(c.at)} ago + {c.classifier} ))} @@ -401,7 +402,7 @@ export function ItemSide(props: ViewProps) {
      - {d.answer ? `answered ${ago(d.answeredAt!)} ago` : `waiting ${ago(d.askedAt)}`} + {d.answer ? <>answered : <>waiting }

      {d.question}

      {d.answer ? ( diff --git a/web/src/modules/items/views.tsx b/web/src/modules/items/views.tsx index ca53fce1..3bd9cd34 100644 --- a/web/src/modules/items/views.tsx +++ b/web/src/modules/items/views.tsx @@ -10,7 +10,8 @@ import type { ViewProps } from "../../registry/types"; import { Badge, type Tone } from "../../ui/atoms/Badge"; import { ItemRef } from "../../ui/molecules/ItemRef"; import { cn } from "../../ui/cn"; -import { ago, day, num, when } from "../../lib/format"; +import { day, num, when } from "../../lib/format"; +import { TimeAgo } from "../../ui/atoms/TimeAgo"; import { useIsPhone } from "../../shell/useMedia"; import { Block, ErrorLine, Page, Pager, selectCls, TextInput, useUrlState } from "../admin/parts"; import { useNow } from "../../lib/useNow"; @@ -331,7 +332,7 @@ function Table({ rows, byUs }: { rows: ItemListRow[]; byUs: boolean }) { {it.author} - {(byUs ? it.mergedAt : it.updatedAt) ? `${ago((byUs ? it.mergedAt : it.updatedAt)!)} ago` : "–"} + {(byUs ? it.mergedAt : it.updatedAt) ? <> : "–"} @@ -361,7 +362,7 @@ function Cards({ rows, byUs }: { rows: ItemListRow[]; byUs: boolean }) {
      {it.author} - {(byUs ? it.mergedAt : it.updatedAt) ? `${byUs ? "merged " : ""}${ago((byUs ? it.mergedAt : it.updatedAt)!)} ago` : ""} + {(byUs ? it.mergedAt : it.updatedAt) ? <>{byUs ? "merged " : ""} : ""}
      {it.snippet && it.snippet.field !== "title" && (
      diff --git a/web/src/modules/pipeline/controls.tsx b/web/src/modules/pipeline/controls.tsx index c60ff6bd..d51f6fa2 100644 --- a/web/src/modules/pipeline/controls.tsx +++ b/web/src/modules/pipeline/controls.tsx @@ -5,7 +5,8 @@ import { useEffect, useRef, useState } from "react"; import { PauseIcon, PlayIcon } from "@phosphor-icons/react"; import { useApi, useQuery } from "../../api/client"; import type { PipelineState, StageLimit } from "../../api/types"; -import { ago, dayResetLocal, num, when } from "../../lib/format"; +import { dayResetLocal, num, when } from "../../lib/format"; +import { TimeAgo } from "../../ui/atoms/TimeAgo"; import { useUser } from "../../shell/UserContext"; import { Badge } from "../../ui/atoms/Badge"; import { Button } from "../../ui/atoms/Button"; @@ -73,7 +74,7 @@ export function PipelineSwitch({ className }: { className?: string }) { {s.changedAt && ( {" "} - Switched {s.enabled ? "on" : "off"} by {s.changedBy ?? "unknown"} {ago(s.changedAt, false)} ({when(s.changedAt)}). + Switched {s.enabled ? "on" : "off"} by {s.changedBy ?? "unknown"} ({when(s.changedAt)}). )}
      diff --git a/web/src/modules/pipeline/views.tsx b/web/src/modules/pipeline/views.tsx index e67aed6c..b68eddd7 100644 --- a/web/src/modules/pipeline/views.tsx +++ b/web/src/modules/pipeline/views.tsx @@ -11,7 +11,8 @@ import { can } from "../../registry/permissions"; import { Badge, type Tone } from "../../ui/atoms/Badge"; import { Button } from "../../ui/atoms/Button"; import { cn } from "../../ui/cn"; -import { ago, num } from "../../lib/format"; +import { num, eventTime } from "../../lib/format"; +import { TimeAgo } from "../../ui/atoms/TimeAgo"; import { Block, ConfirmButton, ErrorLine, Page, useWrite, when } from "../admin/parts"; import { PilotPanel, PipelineSwitch, StageLimits } from "./controls"; import { useNow } from "../../lib/useNow"; @@ -49,7 +50,7 @@ const paramText = (p: JobParams) => function SyncRuns({ runs, last }: { runs: SyncRun[]; last: string | null }) { useNow(); return ( - + {runs.length === 0 ? (

      No sync runs recorded yet.

      ) : ( @@ -147,7 +148,7 @@ function Jobs({ selected }: { selected?: number }) { - {j.requestedBy} · {ago(j.requestedAt)} + {j.requestedBy} · {took(j.startedAt, j.endedAt)} @@ -178,7 +179,7 @@ function RunnerLine({ o }: { o: PipelineOverview }) { return ( - {o.runner.alive ? "Runner running" : o.runner.lastSeen ? `Runner not running since ${ago(o.runner.lastSeen, false)}: jobs wait until it starts` : "Runner not started: jobs wait until it starts"} + {o.runner.alive ? "Runner running" : o.runner.lastSeen ? `Runner not running since ${eventTime(o.runner.lastSeen)}: jobs wait until it starts` : "Runner not started: jobs wait until it starts"} {" · "} {o.counts.running} running, {o.counts.queued} queued diff --git a/web/src/modules/queue/mergeParts.tsx b/web/src/modules/queue/mergeParts.tsx index 8781320c..bc64b636 100644 --- a/web/src/modules/queue/mergeParts.tsx +++ b/web/src/modules/queue/mergeParts.tsx @@ -7,7 +7,8 @@ import type { BatchState, QueueBatch, QueueMergeRow, QueueRow, QueueState, Tier import { Badge, type Tone } from "../../ui/atoms/Badge"; import { ItemRef } from "../../ui/molecules/ItemRef"; import { cn } from "../../ui/cn"; -import { ago, when } from "../../lib/format"; +import { when } from "../../lib/format"; +import { TimeAgo } from "../../ui/atoms/TimeAgo"; import { useNow } from "../../lib/useNow"; import { batchPath, decisionPath } from "../../lib/links"; import { FastMark } from "./fastTrack"; @@ -76,7 +77,7 @@ export function BatchFacts({ b }: { b: QueueBatch }) { {b.baseSha.slice(0, 7)} - {ago(b.updatedAt)} ago + ); @@ -167,7 +168,7 @@ function ReviewText({ r }: { r: QueueRow }) { - reviewed {ago(r.reviewedAt)} ago + reviewed
      diff --git a/web/src/ui/atoms/TimeAgo.tsx b/web/src/ui/atoms/TimeAgo.tsx index 1ad6b0ad..3ab62d3b 100644 --- a/web/src/ui/atoms/TimeAgo.tsx +++ b/web/src/ui/atoms/TimeAgo.tsx @@ -1,12 +1,12 @@ -import { ago, when } from "../../lib/format"; +import { eventTime, when } from "../../lib/format"; import { useNow } from "../../lib/useNow"; -/** "3m" or "3 minutes ago"; re-renders as time passes. The tooltip shows the time in the viewer's time zone. */ -export function TimeAgo({ iso, short = true, className }: { iso: string; short?: boolean; className?: string }) { +/** An event time ("now", "12m ago", "14:32", "yesterday 14:32", "Nov 3 14:32"); re-renders as time passes. The tooltip shows the full time in the viewer's time zone. */ +export function TimeAgo({ iso, className }: { iso: string; className?: string }) { useNow(); return ( ); } diff --git a/web/src/ui/molecules/TimelineEvent.tsx b/web/src/ui/molecules/TimelineEvent.tsx index 6547cdae..8693822b 100644 --- a/web/src/ui/molecules/TimelineEvent.tsx +++ b/web/src/ui/molecules/TimelineEvent.tsx @@ -7,7 +7,7 @@ import { TimeAgo } from "../atoms/TimeAgo"; * One row of an event timeline: kind icon, summary, actor and time. The row is a disclosure button; * `children` are the expanded body and are only rendered while open. */ -export function TimelineEvent({ id, lead, Icon, at, actor, actorTone, summary, open, onToggle, children }: { +export function TimelineEvent({ id, lead, Icon, at, actor, actorTone, summary, open, onToggle, flush, children }: { id: string; /** A line above the row that is not part of the disclosure button (a link to the item, say). */ lead?: ReactNode; @@ -19,6 +19,8 @@ export function TimelineEvent({ id, lead, Icon, at, actor, actorTone, summary, o summary: string; open: boolean; onToggle: () => void; + /** The body holds rows of its own and needs no inset on the left. */ + flush?: boolean; children?: ReactNode; }) { const Caret = open ? CaretDownIcon : CaretRightIcon; @@ -42,7 +44,7 @@ export function TimelineEvent({ id, lead, Icon, at, actor, actorTone, summary, o
      - {open &&
      {children}
      } + {open &&
      {children}
      } ); } diff --git a/web/src/ui/organisms/TraceHeader.tsx b/web/src/ui/organisms/TraceHeader.tsx index ddbf2335..28965e5a 100644 --- a/web/src/ui/organisms/TraceHeader.tsx +++ b/web/src/ui/organisms/TraceHeader.tsx @@ -25,7 +25,7 @@ export function TraceHeader({ header, decisionHref }: { header: ItemTraceHeader;

      {now.state && {now.state}} {now.head && {shortSha(now.head)}} - {now.plannedAt && } + {now.plannedAt && }

      )} {now.reasons.length > 0 &&

      {now.reasons.join("; ")}

      } @@ -55,7 +55,7 @@ export function TraceHeader({ header, decisionHref }: { header: ItemTraceHeader; ))} {who.holds.map((h) => (

      - On hold by {h.by} + On hold by {h.by}

      ))}