Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

refactor(ui): split the shared and web components this week grew (#3551)

Raghav Chamadiya4c108d4f8174
diff --git a/packages/ui/src/chat/message-actions.tsx b/packages/ui/src/chat/message-actions.tsx
index db9e23942..efaad9c57 100644
--- a/packages/ui/src/chat/message-actions.tsx
+++ b/packages/ui/src/chat/message-actions.tsx
@@ -40,42 +40,16 @@ export function MessageActions({
if (editing) {
return (
- <form
- className="mt-2 w-full space-y-2"
- onSubmit={(event) => {
- event.preventDefault();
- const text = draft.trim();
- if (text) void onEditAndResend?.(text);
+ <MessageEditForm
+ draft={draft}
+ setDraft={setDraft}
+ onSubmit={(text) => onEditAndResend?.(text)}
+ onCancel={() => {
+ setDraft(message.text);
setEditing(false);
}}
- >
- <textarea
- autoFocus
- value={draft}
- onChange={(event) => setDraft(event.target.value)}
- aria-label="Edit message"
- className="min-h-20 w-full resize-y rounded-2xl border border-[var(--color-border-default)] bg-[var(--color-bg-surface)] px-4 py-2.5 text-base leading-relaxed text-[var(--color-text-primary)] !outline-none focus:border-[var(--color-border-hover)] focus-visible:ring-2 focus-visible:ring-[var(--color-accent-primary)]"
- />
- <div className="flex justify-end gap-2">
- <button
- type="button"
- onClick={() => {
- setDraft(message.text);
- setEditing(false);
- }}
- className="inline-flex h-8 items-center rounded-full px-3 text-xs text-[var(--color-text-secondary)] hover:bg-[var(--color-bg-elevated)] hover:text-[var(--color-text-primary)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent-primary)]"
- >
- Cancel
- </button>
- <button
- type="submit"
- aria-label="Fork and resend"
- className="inline-flex h-8 items-center rounded-full bg-[var(--color-accent-fill)] px-3 text-xs font-medium text-[var(--color-text-on-accent)] hover:bg-[var(--color-accent-fill-hover)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent-primary)] focus-visible:ring-offset-2 focus-visible:ring-offset-[var(--color-bg-root)]"
- >
- Send
- </button>
- </div>
- </form>
+ onDone={() => setEditing(false)}
+ />
);
}
@@ -87,22 +61,7 @@ export function MessageActions({
return (
<div className="mt-2 space-y-1.5">
- {error && (
- <div role="alert" className="flex flex-wrap items-center gap-x-2 gap-y-1 text-sm">
- <span aria-hidden className="h-1.5 w-1.5 shrink-0 rounded-full bg-[var(--color-error)]" />
- <span className="min-w-0 text-[var(--color-text-secondary)] [overflow-wrap:anywhere]">{error}</span>
- {onRetry && (
- <button
- type="button"
- onClick={() => void onRetry()}
- className="inline-flex h-8 items-center gap-1.5 rounded-md px-2 text-xs font-medium text-[var(--color-text-secondary)] hover:bg-[var(--color-bg-elevated)] hover:text-[var(--color-text-primary)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent-primary)]"
- >
- <RotateCcw aria-hidden className="h-3.5 w-3.5" />
- Retry
- </button>
- )}
- </div>
- )}
+ {error && <ErrorNotice error={error} onRetry={onRetry} />}
{message.text && (
<div
role="group"
@@ -123,24 +82,126 @@ export function MessageActions({
>
{copied ? <Check aria-hidden className="h-3.5 w-3.5" /> : <Copy aria-hidden className="h-3.5 w-3.5" />}
</button>
- {message.role === "assistant" && onRetry && !error && (
- <button type="button" className={ICON_BUTTON} onClick={() => void onRetry()} aria-label="Retry" title="Retry">
- <RotateCcw aria-hidden className="h-3.5 w-3.5" />
- </button>
- )}
- {message.role === "user" && message.serverId && onEditAndResend && (
- <button
- type="button"
- className={ICON_BUTTON}
- onClick={() => setEditing(true)}
- aria-label="Edit and resend"
- title="Edit and resend"
- >
- <Pencil aria-hidden className="h-3.5 w-3.5" />
- </button>
- )}
+ <FollowUpButtons
+ message={message}
+ error={error}
+ onRetry={onRetry}
+ onEditAndResend={onEditAndResend}
+ onEdit={() => setEditing(true)}
+ />
</div>
)}
</div>
);
}
+
+function MessageEditForm({
+ draft,
+ setDraft,
+ onSubmit,
+ onCancel,
+ onDone,
+}: {
+ draft: string;
+ setDraft: (text: string) => void;
+ onSubmit: (text: string) => void | Promise<void>;
+ onCancel: () => void;
+ onDone: () => void;
+}) {
+ return (
+ <form
+ className="mt-2 w-full space-y-2"
+ onSubmit={(event) => {
+ event.preventDefault();
+ const text = draft.trim();
+ if (text) void onSubmit(text);
+ onDone();
+ }}
+ >
+ <textarea
+ autoFocus
+ value={draft}
+ onChange={(event) => setDraft(event.target.value)}
+ aria-label="Edit message"
+ className="min-h-20 w-full resize-y rounded-2xl border border-[var(--color-border-default)] bg-[var(--color-bg-surface)] px-4 py-2.5 text-base leading-relaxed text-[var(--color-text-primary)] !outline-none focus:border-[var(--color-border-hover)] focus-visible:ring-2 focus-visible:ring-[var(--color-accent-primary)]"
+ />
+ <div className="flex justify-end gap-2">
+ <button
+ type="button"
+ onClick={onCancel}
+ className="inline-flex h-8 items-center rounded-full px-3 text-xs text-[var(--color-text-secondary)] hover:bg-[var(--color-bg-elevated)] hover:text-[var(--color-text-primary)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent-primary)]"
+ >
+ Cancel
+ </button>
+ <button
+ type="submit"
+ aria-label="Fork and resend"
+ className="inline-flex h-8 items-center rounded-full bg-[var(--color-accent-fill)] px-3 text-xs font-medium text-[var(--color-text-on-accent)] hover:bg-[var(--color-accent-fill-hover)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent-primary)] focus-visible:ring-offset-2 focus-visible:ring-offset-[var(--color-bg-root)]"
+ >
+ Send
+ </button>
+ </div>
+ </form>
+ );
+}
+
+function ErrorNotice({
+ error,
+ onRetry,
+}: {
+ error: string;
+ onRetry: (() => void | Promise<void>) | undefined;
+}) {
+ return (
+ <div role="alert" className="flex flex-wrap items-center gap-x-2 gap-y-1 text-sm">
+ <span aria-hidden className="h-1.5 w-1.5 shrink-0 rounded-full bg-[var(--color-error)]" />
+ <span className="min-w-0 text-[var(--color-text-secondary)] [overflow-wrap:anywhere]">{error}</span>
+ {onRetry && (
+ <button
+ type="button"
+ onClick={() => void onRetry()}
+ className="inline-flex h-8 items-center gap-1.5 rounded-md px-2 text-xs font-medium text-[var(--color-text-secondary)] hover:bg-[var(--color-bg-elevated)] hover:text-[var(--color-text-primary)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent-primary)]"
+ >
+ <RotateCcw aria-hidden className="h-3.5 w-3.5" />
+ Retry
+ </button>
+ )}
+ </div>
+ );
+}
+
+/** Retry under an answer, edit-and-resend under a saved question. */
+function FollowUpButtons({
+ message,
+ error,
+ onRetry,
+ onEditAndResend,
+ onEdit,
+}: {
+ message: ChatUIMessage;
+ error: string | null | undefined;
+ onRetry: (() => void | Promise<void>) | undefined;
+ onEditAndResend: ((text: string) => void | Promise<void>) | undefined;
+ onEdit: () => void;
+}) {
+ return (
+ <>
+ {message.role === "assistant" && onRetry && !error && (
+ <button type="button" className={ICON_BUTTON} onClick={() => void onRetry()} aria-label="Retry" title="Retry">
+ <RotateCcw aria-hidden className="h-3.5 w-3.5" />
+ </button>
+ )}
+ {message.role === "user" && message.serverId && onEditAndResend && (
+ <button
+ type="button"
+ className={ICON_BUTTON}
+ onClick={onEdit}
+ aria-label="Edit and resend"
+ title="Edit and resend"
+ >
+ <Pencil aria-hidden className="h-3.5 w-3.5" />
+ </button>
+ )}
+ </>
+ );
+}
diff --git a/packages/ui/src/decisions/decisions-table.tsx b/packages/ui/src/decisions/decisions-table.tsx
index 30f04fb70..7da1d1f7e 100644
--- a/packages/ui/src/decisions/decisions-table.tsx
+++ b/packages/ui/src/decisions/decisions-table.tsx
@@ -110,43 +110,7 @@ export function DecisionsTable({
header: "Title",
priority: 1,
cellClassName: "min-w-[200px] max-w-[520px]",
- render: (d) => (
- <div className="min-w-0">
- <span className="flex min-w-0 items-center gap-1.5">
- <Link
- href={`${prefix}/decisions/${d.id}`}
- className="font-medium text-[var(--color-text-primary)] hover:text-[var(--color-accent-primary)] hover:underline truncate"
- title={stripMarkdown(d.title)}
- >
- {stripMarkdown(d.title)}
- </Link>
- {d.verification && d.verification !== "exact" && (
- <VerificationBadge verification={d.verification} iconOnly />
- )}
- </span>
- {d.evidence_preview?.source_quote && (
- <p
- className="mt-0.5 truncate text-xs italic text-[var(--color-text-tertiary)]"
- title={`${d.evidence_preview.source_quote}${
- d.evidence_preview.evidence_file
- ? ` — ${d.evidence_preview.evidence_file}${
- d.evidence_preview.evidence_line != null
- ? `:${d.evidence_preview.evidence_line}`
- : ""
- }`
- : ""
- }`}
- >
- “{d.evidence_preview.source_quote}”
- {(d.evidence_count ?? 0) > 1 && (
- <span className="ml-1 not-italic">
- +{(d.evidence_count ?? 0) - 1} more
- </span>
- )}
- </p>
- )}
- </div>
- ),
+ render: (d) => renderTitleCell(d, `${prefix}/decisions/${d.id}`, Link),
},
{
key: "status",
@@ -181,26 +145,7 @@ export function DecisionsTable({
key: "tags",
header: "Tags",
priority: 3,
- render: (d) => (
- <div className="flex flex-wrap gap-x-2 gap-y-0.5">
- {d.tags.slice(0, 3).map((tag) => (
- <span
- key={tag}
- className="font-mono text-xs text-[var(--color-text-tertiary)]"
- >
- {tag}
- </span>
- ))}
- {d.tags.length > 3 && (
- <span
- className="font-mono text-xs tabular-nums text-[var(--color-text-tertiary)]"
- title={d.tags.slice(3).join(", ")}
- >
- +{d.tags.length - 3}
- </span>
- )}
- </div>
- ),
+ render: renderTagsCell,
},
{
key: "staleness",
@@ -219,52 +164,13 @@ export function DecisionsTable({
// expired because the files they cite happened to change. Red is
// reserved for health bands; this is a count, so it reads as one, in
// mono like every other machine-produced figure.
- render: (d) => {
- const s = describeRecordStaleness(d);
- return (
- <span
- className={
- s.kind === "moved"
- ? "font-mono text-xs tabular-nums text-[var(--color-text-secondary)]"
- : "font-mono text-xs tabular-nums text-[var(--color-text-tertiary)]"
- }
- title={s.sentence}
- >
- {s.short}
- </span>
- );
- },
+ render: renderStalenessCell,
},
];
- const filtersActive =
- filters.status !== "all" ||
- filters.source !== "all" ||
- (filters.scope ?? "all") !== "all";
-
- const empty =
- isLoading ? undefined : error ? (
- <ApiError
- title="Couldn't load decisions"
- message="An error occurred while fetching decisions."
- {...(onRetry ? { onRetry } : {})}
- />
- ) : filtersActive ? (
- <EmptyState
- tone="filtered"
- title="No decisions match these filters"
- action={{
- label: "Clear filters",
- onClick: () =>
- onFiltersChange({ ...filters, status: "all", source: "all", scope: "all" }),
- }}
- />
- ) : (
- <EmptyState
- title="No decisions yet"
- description="Decisions are inferred from pull requests, commits and agent sessions, or you can record one yourself."
- />
- );
+ const empty = isLoading
+ ? undefined
+ : renderEmpty(error, filters, onFiltersChange, onRetry);
return (
<div className="space-y-4">
@@ -322,3 +228,117 @@ export function DecisionsTable({
</div>
);
}
+
+function renderTitleCell(d: DecisionRecord, href: string, Link: React.ElementType) {
+ return (
+ <div className="min-w-0">
+ <span className="flex min-w-0 items-center gap-1.5">
+ <Link
+ href={href}
+ className="font-medium text-[var(--color-text-primary)] hover:text-[var(--color-accent-primary)] hover:underline truncate"
+ title={stripMarkdown(d.title)}
+ >
+ {stripMarkdown(d.title)}
+ </Link>
+ {d.verification && d.verification !== "exact" && (
+ <VerificationBadge verification={d.verification} iconOnly />
+ )}
+ </span>
+ {d.evidence_preview?.source_quote && (
+ <p
+ className="mt-0.5 truncate text-xs italic text-[var(--color-text-tertiary)]"
+ title={`${d.evidence_preview.source_quote}${
+ d.evidence_preview.evidence_file
+ ? ` — ${d.evidence_preview.evidence_file}${
+ d.evidence_preview.evidence_line != null
+ ? `:${d.evidence_preview.evidence_line}`
+ : ""
+ }`
+ : ""
+ }`}
+ >
+ “{d.evidence_preview.source_quote}”
+ {(d.evidence_count ?? 0) > 1 && (
+ <span className="ml-1 not-italic">
+ +{(d.evidence_count ?? 0) - 1} more
+ </span>
+ )}
+ </p>
+ )}
+ </div>
+ );
+}
+
+function renderTagsCell(d: DecisionRecord) {
+ return (
+ <div className="flex flex-wrap gap-x-2 gap-y-0.5">
+ {d.tags.slice(0, 3).map((tag) => (
+ <span
+ key={tag}
+ className="font-mono text-xs text-[var(--color-text-tertiary)]"
+ >
+ {tag}
+ </span>
+ ))}
+ {d.tags.length > 3 && (
+ <span
+ className="font-mono text-xs tabular-nums text-[var(--color-text-tertiary)]"
+ title={d.tags.slice(3).join(", ")}
+ >
+ +{d.tags.length - 3}
+ </span>
+ )}
+ </div>
+ );
+}
+
+function renderStalenessCell(d: DecisionRecord) {
+ const s = describeRecordStaleness(d);
+ return (
+ <span
+ className={
+ s.kind === "moved"
+ ? "font-mono text-xs tabular-nums text-[var(--color-text-secondary)]"
+ : "font-mono text-xs tabular-nums text-[var(--color-text-tertiary)]"
+ }
+ title={s.sentence}
+ >
+ {s.short}
+ </span>
+ );
+}
+
+function renderEmpty(
+ error: unknown,
+ filters: DecisionsTableFilters,
+ onFiltersChange: (filters: DecisionsTableFilters) => void,
+ onRetry: (() => void) | undefined,
+) {
+ const filtersActive =
+ filters.status !== "all" ||
+ filters.source !== "all" ||
+ (filters.scope ?? "all") !== "all";
+
+ return error ? (
+ <ApiError
+ title="Couldn't load decisions"
+ message="An error occurred while fetching decisions."
+ {...(onRetry ? { onRetry } : {})}
+ />
+ ) : filtersActive ? (
+ <EmptyState
+ tone="filtered"
+ title="No decisions match these filters"
+ action={{
+ label: "Clear filters",
+ onClick: () =>
+ onFiltersChange({ ...filters, status: "all", source: "all", scope: "all" }),
+ }}
+ />
+ ) : (
+ <EmptyState
+ title="No decisions yet"
+ description="Decisions are inferred from pull requests, commits and agent sessions, or you can record one yourself."
+ />
+ );
+}
diff --git a/packages/ui/src/shared/empty-state.tsx b/packages/ui/src/shared/empty-state.tsx
index dc5acd04c..04c19d4ad 100644
--- a/packages/ui/src/shared/empty-state.tsx
+++ b/packages/ui/src/shared/empty-state.tsx
@@ -151,36 +151,7 @@ export function EmptyState({
const compact = (size ?? (tone === "filtered" ? "compact" : "default")) === "compact";
const isError = tone === "error";
- let mark: React.ReactNode = null;
- if (tone === "positive") {
- mark = <PositiveMark size={compact ? "sm" : "md"} />;
- } else if (isError) {
- mark = icon ? (
- <span
- aria-hidden
- className={cn(
- "inline-flex shrink-0 text-[var(--color-error)]",
- compact ? "[&_svg]:h-4 [&_svg]:w-4" : "[&_svg]:h-5 [&_svg]:w-5",
- )}
- >
- {icon}
- </span>
- ) : (
- <span aria-hidden className="h-1.5 w-1.5 shrink-0 rounded-full bg-[var(--color-error)]" />
- );
- } else if (icon && tone !== "filtered") {
- mark = (
- <span
- aria-hidden
- className={cn(
- "inline-flex shrink-0 text-[var(--color-text-tertiary)]",
- compact ? "[&_svg]:h-4 [&_svg]:w-4" : "[&_svg]:h-5 [&_svg]:w-5",
- )}
- >
- {icon}
- </span>
- );
- }
+ const mark = stateMark(tone, icon, compact);
if (compact) {
return (
@@ -228,14 +199,56 @@ export function EmptyState({
)}
</div>
{children}
- {(action || secondaryAction) && (
- <div className="flex flex-wrap items-center justify-center gap-2">
- {action && (
- <ActionButton action={action} variant={tone === "neutral" ? "default" : "outline"} />
- )}
- {secondaryAction && <ActionButton action={secondaryAction} variant="ghost" />}
- </div>
+ {(action || secondaryAction) && renderActions(action, secondaryAction, tone)}
+ </div>
+ );
+}
+
+/** The leading mark: a check for positive, a red icon or dot for error, else the tinted icon. */
+function stateMark(tone: EmptyStateTone, icon: React.ReactNode, compact: boolean): React.ReactNode {
+ if (tone === "positive") {
+ return <PositiveMark size={compact ? "sm" : "md"} />;
+ } else if (tone === "error") {
+ return icon ? (
+ <span
+ aria-hidden
+ className={cn(
+ "inline-flex shrink-0 text-[var(--color-error)]",
+ compact ? "[&_svg]:h-4 [&_svg]:w-4" : "[&_svg]:h-5 [&_svg]:w-5",
+ )}
+ >
+ {icon}
+ </span>
+ ) : (
+ <span aria-hidden className="h-1.5 w-1.5 shrink-0 rounded-full bg-[var(--color-error)]" />
+ );
+ } else if (icon && tone !== "filtered") {
+ return (
+ <span
+ aria-hidden
+ className={cn(
+ "inline-flex shrink-0 text-[var(--color-text-tertiary)]",
+ compact ? "[&_svg]:h-4 [&_svg]:w-4" : "[&_svg]:h-5 [&_svg]:w-5",
+ )}
+ >
+ {icon}
+ </span>
+ );
+ }
+ return null;
+}
+
+function renderActions(
+ action: EmptyStateAction | undefined,
+ secondaryAction: EmptyStateAction | undefined,
+ tone: EmptyStateTone,
+) {
+ return (
+ <div className="flex flex-wrap items-center justify-center gap-2">
+ {action && (
+ <ActionButton action={action} variant={tone === "neutral" ? "default" : "outline"} />
)}
+ {secondaryAction && <ActionButton action={secondaryAction} variant="ghost" />}
</div>
);
}
diff --git a/packages/ui/src/shared/release-notice.tsx b/packages/ui/src/shared/release-notice.tsx
index ed28d8332..9ac175ad6 100644
--- a/packages/ui/src/shared/release-notice.tsx
+++ b/packages/ui/src/shared/release-notice.tsx
@@ -59,7 +59,7 @@ export function ReleaseNotice({
dismissLabel,
className,
}: ReleaseNoticeProps) {
- const storageKey = id ? STORAGE_PREFIX + id + (version ? `:v${version}` : "") : null;
+ const storageKey = dismissalKey(id, version);
const hostOwned = !!onDismiss || !storageKey;
// Start dismissed so it does not flash in before the stored answer is read.
const [dismissed, setDismissed] = React.useState(!hostOwned);
@@ -75,12 +75,6 @@ export function ReleaseNotice({
if (dismissed) return null;
- const lead = title ? (
- <>
- <span className="font-medium text-[var(--color-text-primary)]">{title}</span>{" "}
- </>
- ) : null;
-
const dismiss = () => {
if (onDismiss) return onDismiss();
try {
@@ -99,24 +93,44 @@ export function ReleaseNotice({
{...(action ? { action } : {})}
{...(className ? { className } : {})}
>
- {detail ? (
- <details className="group/release">
- <summary className="cursor-pointer list-none rounded focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent-primary)]">
- {lead}
- {children}{" "}
- <span className="text-[var(--color-accent-primary)] underline-offset-2 hover:underline">
- <span className="group-open/release:hidden">{detailLabel}</span>
- <span className="hidden group-open/release:inline">{hideLabel}</span>
- </span>
- </summary>
- <div className="mt-1.5">{detail}</div>
- </details>
- ) : (
- <>
- {lead}
- {children}
- </>
- )}
+ {renderBody(title, children, detail, detailLabel, hideLabel)}
</DismissibleNotice>
);
}
+
+function dismissalKey(id: string | undefined, version: string | null | undefined): string | null {
+ return id ? STORAGE_PREFIX + id + (version ? `:v${version}` : "") : null;
+}
+
+function renderBody(
+ title: React.ReactNode,
+ children: React.ReactNode,
+ detail: React.ReactNode,
+ detailLabel: string,
+ hideLabel: string,
+) {
+ const lead = title ? (
+ <>
+ <span className="font-medium text-[var(--color-text-primary)]">{title}</span>{" "}
+ </>
+ ) : null;
+
+ return detail ? (
+ <details className="group/release">
+ <summary className="cursor-pointer list-none rounded focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent-primary)]">
+ {lead}
+ {children}{" "}
+ <span className="text-[var(--color-accent-primary)] underline-offset-2 hover:underline">
+ <span className="group-open/release:hidden">{detailLabel}</span>
+ <span className="hidden group-open/release:inline">{hideLabel}</span>
+ </span>
+ </summary>
+ <div className="mt-1.5">{detail}</div>
+ </details>
+ ) : (
+ <>
+ {lead}
+ {children}
+ </>
+ );
+}
diff --git a/packages/web/src/app/repos/[id]/overview/page.tsx b/packages/web/src/app/repos/[id]/overview/page.tsx
index e144e4890..e2e264dcb 100644
--- a/packages/web/src/app/repos/[id]/overview/page.tsx
+++ b/packages/web/src/app/repos/[id]/overview/page.tsx
@@ -19,6 +19,7 @@ import {
type OverviewRoutes,
type RepoIdentityMeta,
} from "@repowise-dev/ui/overview";
+import type { OverviewSummaryResponse } from "@repowise-dev/types/overview";
import {
formatDateTime,
formatLOC,
@@ -43,6 +44,29 @@ async function safeFetch<T>(fn: () => Promise<T>): Promise<T | null> {
* the initial HTML instead of waterfalling in after paint. */
const COMMIT_LIMIT = 6;
+/** The header's chips: language, branch, head commit, size and last sync. */
+function identityMeta(
+ summary: OverviewSummaryResponse,
+ totalNloc: number | null,
+ lastActivityAt: string | null | undefined,
+): RepoIdentityMeta[] {
+ const meta: RepoIdentityMeta[] = [];
+ const primaryLanguage = summary.languages[0]?.language;
+ if (primaryLanguage) meta.push({ label: primaryLanguage, dot: true });
+ meta.push({ label: summary.repo.default_branch, mono: true });
+ if (summary.repo.head_commit) meta.push({ label: summary.repo.head_commit.slice(0, 7), mono: true });
+ if (totalNloc != null) {
+ meta.push({ label: `${formatLOC(totalNloc)} lines`, mono: true });
+ }
+ if (lastActivityAt) {
+ meta.push({
+ label: `synced ${formatRelativeTime(lastActivityAt)}`,
+ title: formatDateTime(lastActivityAt),
+ });
+ }
+ return meta;
+}
+
/**
* The local dashboard's repo Overview.
*
@@ -80,20 +104,7 @@ export default async function OverviewPage({ params }: Props) {
const lastActivityAt = sync.last_sync_at ?? sync.last_resync_at ?? health.last_indexed_at;
// ── Identity ───────────────────────────────────────────────────────────
- const meta: RepoIdentityMeta[] = [];
- const primaryLanguage = summary.languages[0]?.language;
- if (primaryLanguage) meta.push({ label: primaryLanguage, dot: true });
- meta.push({ label: repo.default_branch, mono: true });
- if (repo.head_commit) meta.push({ label: repo.head_commit.slice(0, 7), mono: true });
- if (totalNloc != null) {
- meta.push({ label: `${formatLOC(totalNloc)} lines`, mono: true });
- }
- if (lastActivityAt) {
- meta.push({
- label: `synced ${formatRelativeTime(lastActivityAt)}`,
- title: formatDateTime(lastActivityAt),
- });
- }
+ const meta = identityMeta(summary, totalNloc, lastActivityAt);
// Priced by the server; no rates means the dialog shows no estimate.
const active = providers?.active;
diff --git a/packages/web/src/components/risk/security-tab.tsx b/packages/web/src/components/risk/security-tab.tsx
index 7a7466c45..cdc2c1b5f 100644
--- a/packages/web/src/components/risk/security-tab.tsx
+++ b/packages/web/src/components/risk/security-tab.tsx
@@ -82,26 +82,7 @@ export function SecurityTab({ repoId }: { repoId: string }) {
showFile(data);
};
- const labels = useMemo<SecurityPostureLabels>(
- () => ({
- figure: t("posture.figure"),
- figureHint: t("posture.figureHint"),
- unit: (total, capped) =>
- capped ? t("posture.unitCapped", { total }) : t("posture.unit", { count: total }),
- sentence: (c) =>
- c.source === 0
- ? t("posture.sentenceNoSource", { count: c.elsewhere })
- : [
- t("posture.sentenceSource", { count: c.source, high: c.sourceHigh }),
- c.elsewhere ? t("posture.sentenceElsewhere", { count: c.elsewhere }) : "",
- ]
- .filter(Boolean)
- .join(" "),
- scanned: (when) => t("posture.scanned", { when }),
- scanTimeUnknown: t("posture.scanTimeUnknown"),
- }),
- [t],
- );
+ const labels = usePostureLabels();
const scannedAt = summary?.scanned_at ?? null;
const scannedAgo = scannedAt ? formatRelativeTime(scannedAt) : null;
@@ -123,35 +104,17 @@ export function SecurityTab({ repoId }: { repoId: string }) {
} else if (list.length === 0) {
// Green only when the scan is known to have run; an unknown scan time
// with nothing listed is "not scanned yet", not good news.
- body = scannedAgo ? (
- <EmptyState
- tone="positive"
- title={t("posture.clearTitle")}
- description={t("posture.clearBody", { when: scannedAgo })}
- />
- ) : (
- <EmptyState title={t("posture.notScannedTitle")} description={t("posture.notScannedBody")} />
- );
+ body = <SecurityEmpty scannedAgo={scannedAgo} />;
} else {
body = (
- <>
- <SecurityPosture findings={list} scannedAgo={scannedAgo} capped={capped} labels={labels} />
- <OverviewSection title={t("allFindings")} description={t("description")}>
- <SecurityFindingsTable
- findings={list}
- onSelect={handleSelect}
- onGeneratePrompt={setPromptFinding}
- />
- {capped && (
- <p className="text-xs text-[var(--color-text-tertiary)]">
- {t("posture.capped", { count: LIMIT })}
- </p>
- )}
- </OverviewSection>
- <OverviewSection title={t("posture.byDirectory")} description={t("posture.byDirectoryBody")}>
- <SeverityDirectoryMatrix findings={list} />
- </OverviewSection>
- </>
+ <SecurityFindingsBody
+ list={list}
+ scannedAgo={scannedAgo}
+ capped={capped}
+ labels={labels}
+ onSelect={handleSelect}
+ onGeneratePrompt={setPromptFinding}
+ />
);
}
@@ -186,3 +149,78 @@ export function SecurityTab({ repoId }: { repoId: string }) {
</div>
);
}
+
+function usePostureLabels(): SecurityPostureLabels {
+ const t = useTranslations("risk");
+ return useMemo<SecurityPostureLabels>(
+ () => ({
+ figure: t("posture.figure"),
+ figureHint: t("posture.figureHint"),
+ unit: (total, capped) =>
+ capped ? t("posture.unitCapped", { total }) : t("posture.unit", { count: total }),
+ sentence: (c) =>
+ c.source === 0
+ ? t("posture.sentenceNoSource", { count: c.elsewhere })
+ : [
+ t("posture.sentenceSource", { count: c.source, high: c.sourceHigh }),
+ c.elsewhere ? t("posture.sentenceElsewhere", { count: c.elsewhere }) : "",
+ ]
+ .filter(Boolean)
+ .join(" "),
+ scanned: (when) => t("posture.scanned", { when }),
+ scanTimeUnknown: t("posture.scanTimeUnknown"),
+ }),
+ [t],
+ );
+}
+
+function SecurityEmpty({ scannedAgo }: { scannedAgo: string | null }) {
+ const t = useTranslations("risk");
+ return scannedAgo ? (
+ <EmptyState
+ tone="positive"
+ title={t("posture.clearTitle")}
+ description={t("posture.clearBody", { when: scannedAgo })}
+ />
+ ) : (
+ <EmptyState title={t("posture.notScannedTitle")} description={t("posture.notScannedBody")} />
+ );
+}
+
+function SecurityFindingsBody({
+ list,
+ scannedAgo,
+ capped,
+ labels,
+ onSelect,
+ onGeneratePrompt,
+}: {
+ list: SecurityFinding[];
+ scannedAgo: string | null;
+ capped: boolean;
+ labels: SecurityPostureLabels;
+ onSelect: (f: SecurityFinding) => void;
+ onGeneratePrompt: (f: SecurityFinding) => void;
+}) {
+ const t = useTranslations("risk");
+ return (
+ <>
+ <SecurityPosture findings={list} scannedAgo={scannedAgo} capped={capped} labels={labels} />
+ <OverviewSection title={t("allFindings")} description={t("description")}>
+ <SecurityFindingsTable
+ findings={list}
+ onSelect={onSelect}
+ onGeneratePrompt={onGeneratePrompt}
+ />
+ {capped && (
+ <p className="text-xs text-[var(--color-text-tertiary)]">
+ {t("posture.capped", { count: LIMIT })}
+ </p>
+ )}
+ </OverviewSection>
+ <OverviewSection title={t("posture.byDirectory")} description={t("posture.byDirectoryBody")}>
+ <SeverityDirectoryMatrix findings={list} />
+ </OverviewSection>
+ </>
+ );
+}