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.

fix(ui): close contract gaps for hosts that deploy separately from the UI package (#3566)

Raghav Chamadiyaac1a447e7760
diff --git a/packages/types/src/dead-code.ts b/packages/types/src/dead-code.ts
index 696460695..2dfba3beb 100644
--- a/packages/types/src/dead-code.ts
+++ b/packages/types/src/dead-code.ts
@@ -119,8 +119,9 @@ export interface DeadCodeSummary {
total_lines: number;
by_kind: Record<string, number>;
/**
- * ISO 8601 UTC time dead-code analysis last ran. `null` or absent (older
- * servers) means never ran or unknown, which is not an all-clear.
+ * ISO 8601 UTC time dead-code analysis last ran. `null` means no run is
+ * recorded, which is not an all-clear. Absent means the host does not
+ * report it, and a zero then reads as clean.
*/
analyzed_at?: string | null;
}
diff --git a/packages/types/src/fix-first.ts b/packages/types/src/fix-first.ts
index e23e7a800..052d96e47 100644
--- a/packages/types/src/fix-first.ts
+++ b/packages/types/src/fix-first.ts
@@ -145,8 +145,11 @@ export interface FixFirstTotals {
eligible: number;
shown: number;
excluded: Record<FixExclusion, number>;
- /** Distinct functions with work kept out as `gated_off`: dormant, not gone. */
- dormant: number;
+ /**
+ * Distinct functions with work kept out as `gated_off`: dormant, not gone.
+ * Absent from a server that predates it.
+ */
+ dormant?: number;
}
/** The count vocabulary (`QueueCounts`) read on the whole Fix first queue. */
diff --git a/packages/types/src/health.ts b/packages/types/src/health.ts
index e3bbedd13..a7a6f9a37 100644
--- a/packages/types/src/health.ts
+++ b/packages/types/src/health.ts
@@ -654,7 +654,8 @@ export type PerformanceQueueExclusion =
export interface PerformanceDefaultQueue {
total: number;
- excluded: Record<PerformanceQueueExclusion, number>;
+ /** Per reason; a server that predates a reason leaves it out. */
+ excluded: Partial<Record<PerformanceQueueExclusion, number>>;
}
export interface PerformanceOpportunitySummary {
diff --git a/packages/ui/COMPONENT_CONTRACTS.md b/packages/ui/COMPONENT_CONTRACTS.md
index 0d27f413f..6393a40e8 100644
--- a/packages/ui/COMPONENT_CONTRACTS.md
+++ b/packages/ui/COMPONENT_CONTRACTS.md
@@ -217,8 +217,10 @@ Behaviour worth knowing:
- Optimistic row state lives here, not in the table, so resolving a row moves
the list with it and undo can put it back.
- Zero open findings: with `summary.analyzed_at` set, the lede reads "0 lines"
- with a positive all-clear and no sections; without it, a neutral "Not
- analysed yet" with a run button. Never green without a recorded run.
+ with a positive all-clear and no sections; with it `null` (no run recorded),
+ a neutral "Not analysed yet" with a run button. With the field absent (a
+ host that does not report runs), the all-clear shows without an "Analysed"
+ time; such a host should also set `analyzeDisabledReason`.
---
diff --git a/packages/ui/__tests__/dead-code/dead-code-lede.test.tsx b/packages/ui/__tests__/dead-code/dead-code-lede.test.tsx
index 5ca622f20..b29f6c702 100644
--- a/packages/ui/__tests__/dead-code/dead-code-lede.test.tsx
+++ b/packages/ui/__tests__/dead-code/dead-code-lede.test.tsx
@@ -1,6 +1,6 @@
import { describe, it, expect } from "vitest";
import { render, screen } from "@testing-library/react";
-import { DeadCodeLede } from "../../src/dead-code/dead-code-lede.js";
+import { AnalysedAt, DeadCodeLede } from "../../src/dead-code/dead-code-lede.js";
import type { DeadCodeSummary } from "@repowise-dev/types/dead-code";
const SUMMARY: DeadCodeSummary = {
@@ -40,6 +40,11 @@ describe("DeadCodeLede", () => {
expect(screen.getByText(/have no reachable caller/).textContent).not.toMatch(/Analysed/);
});
+ it("renders no time for a host that does not report one", () => {
+ const { container } = render(<AnalysedAt at={undefined} />);
+ expect(container).toBeEmptyDOMElement();
+ });
+
it("agrees in number for a single finding", () => {
render(
<DeadCodeLede
diff --git a/packages/ui/__tests__/dead-code/dead-code-view.test.tsx b/packages/ui/__tests__/dead-code/dead-code-view.test.tsx
index ba935337c..d20984b36 100644
--- a/packages/ui/__tests__/dead-code/dead-code-view.test.tsx
+++ b/packages/ui/__tests__/dead-code/dead-code-view.test.tsx
@@ -447,6 +447,21 @@ describe("DeadCodeView", () => {
await waitFor(() => expect(adapter.analyze).toHaveBeenCalledTimes(1));
});
+ it("calls a zero clean when the host does not report when analysis ran", async () => {
+ const unreported: DeadCodeSummary = { ...CLEAN };
+ delete unreported.analyzed_at;
+ const adapter = makeAdapter({
+ getSummary: vi.fn(async () => unreported),
+ listFindings: vi.fn(async () => []),
+ });
+ renderView(<DeadCodeView adapter={adapter} />);
+
+ expect(await screen.findByText("No dead code found")).toBeInTheDocument();
+ expect(screen.queryByText("Not analysed yet")).not.toBeInTheDocument();
+ expect(screen.queryByText(/Analysed /)).not.toBeInTheDocument();
+ expect(screen.getByRole("button", { name: "Re-analyze" })).toBeInTheDocument();
+ });
+
it("renders Re-analyze disabled with the host's reason beside it", async () => {
const adapter = makeAdapter({ analyzeDisabledReason: "This snapshot is read-only." });
renderView(<DeadCodeView adapter={adapter} />);
diff --git a/packages/ui/__tests__/overview/next-actions.test.tsx b/packages/ui/__tests__/overview/next-actions.test.tsx
index a15927df8..6684d752a 100644
--- a/packages/ui/__tests__/overview/next-actions.test.tsx
+++ b/packages/ui/__tests__/overview/next-actions.test.tsx
@@ -199,9 +199,35 @@ describe("the status sentence", () => {
expect(screen.getByText("Core wording, week.")).toBeInTheDocument();
});
- it("shows no sentence from a server that predates it", () => {
+ it("words the sentence locally for a view that carries no summary", () => {
+ const now = action({ id: "n", tier: "act_now", horizons: ["week"] });
+ render(<NextActions data={response([now], [action()])} hrefFor={() => null} />);
+ expect(
+ screen.getByText("1 thing worth doing in the week to Sep 28, the last indexed commit, 1 of them now."),
+ ).toBeInTheDocument();
+ fireEvent.click(screen.getByRole("radio", { name: /This quarter/ }));
+ expect(screen.getByText("1 thing worth doing this quarter.")).toBeInTheDocument();
+ });
+
+ it("names the anchor's own day whatever the offset or the viewer's timezone", () => {
+ for (const anchor of ["2026-09-28T23:30:00-07:00", "2026-09-28T00:15:00Z"]) {
+ const data = { ...response([action({ horizons: ["week"] })], []), anchor };
+ const { unmount } = render(<NextActions data={data} hrefFor={() => null} />);
+ expect(
+ screen.getByText("1 thing worth doing in the week to Sep 28, the last indexed commit."),
+ ).toBeInTheDocument();
+ unmount();
+ }
+ });
+
+ it("points to the other time frame when the open one is clear and no summary is sent", () => {
render(<NextActions data={response([], [action()])} hrefFor={() => null} />);
- expect(screen.queryByText(/worth doing|Nothing/)).toBeNull();
+ fireEvent.click(screen.getByRole("radio", { name: /This week/ }));
+ expect(
+ screen.getByText(
+ "Nothing needs you in the week to Sep 28, the last indexed commit. 1 thing is worth planning this quarter.",
+ ),
+ ).toBeInTheDocument();
});
});
diff --git a/packages/ui/__tests__/security/security.test.tsx b/packages/ui/__tests__/security/security.test.tsx
index a4855ce33..19944970e 100644
--- a/packages/ui/__tests__/security/security.test.tsx
+++ b/packages/ui/__tests__/security/security.test.tsx
@@ -3,6 +3,8 @@ import { render, screen, fireEvent, within } from "@testing-library/react";
import type { SecurityFinding } from "@repowise-dev/types";
import { SecurityFindingsTable } from "../../src/security/findings-table.js";
import { SeverityDirectoryMatrix } from "../../src/security/severity-directory-matrix.js";
+import { FindingsByDirectory } from "@repowise-dev/ui/security/findings-by-directory";
+import { FindingsByDirectory as FromBarrel } from "@repowise-dev/ui/security";
import {
SecurityPosture,
countSecurityFindings,
@@ -143,3 +145,12 @@ describe("SeverityDirectoryMatrix", () => {
expect(container).toBeEmptyDOMElement();
});
});
+
+describe("FindingsByDirectory (deprecated)", () => {
+ it("still resolves at its old subpath and renders the directory table", () => {
+ expect(FindingsByDirectory).toBe(SeverityDirectoryMatrix);
+ expect(FromBarrel).toBe(SeverityDirectoryMatrix);
+ render(<FindingsByDirectory findings={FINDINGS} depth={2} />);
+ expect(screen.getByRole("rowheader", { name: "src/app" })).toBeInTheDocument();
+ });
+});
diff --git a/packages/ui/__tests__/shared/theme-toggle.test.tsx b/packages/ui/__tests__/shared/theme-toggle.test.tsx
index c061dbf93..a9f02e1e9 100644
--- a/packages/ui/__tests__/shared/theme-toggle.test.tsx
+++ b/packages/ui/__tests__/shared/theme-toggle.test.tsx
@@ -102,6 +102,23 @@ describe("ThemeToggle theme default + persistence", () => {
).toBeInTheDocument();
});
+ it("names the theme in effect beside the icon only when asked", async () => {
+ const { rerender } = render(
+ <Harness>
+ <ThemeToggle />
+ </Harness>,
+ );
+ const button = await screen.findByRole("button", { name: "Switch to dark theme" });
+ expect(button).not.toHaveTextContent("Light");
+ rerender(
+ <Harness>
+ <ThemeToggle showLabel />
+ </Harness>,
+ );
+ const labelled = screen.getByRole("button", { name: "Light theme. Switch to dark theme" });
+ expect(labelled).toHaveTextContent("Light");
+ });
+
it("switches to the opposite theme on click", async () => {
render(
<Harness>
diff --git a/packages/ui/src/dead-code/dead-code-adapter.ts b/packages/ui/src/dead-code/dead-code-adapter.ts
index f49a03618..1f55ded99 100644
--- a/packages/ui/src/dead-code/dead-code-adapter.ts
+++ b/packages/ui/src/dead-code/dead-code-adapter.ts
@@ -46,6 +46,8 @@ export interface DeadCodeAdapter {
/**
* When set, Re-analyze renders disabled with this sentence beside it, for a
* host that cannot run a pass right now (a read-only snapshot, a plan limit).
+ * A host that cannot run analysis from the page, or that does not report
+ * `analyzed_at`, should set it, since the button cannot start a pass there.
*/
analyzeDisabledReason?: string;
patchFinding(
diff --git a/packages/ui/src/dead-code/dead-code-view.tsx b/packages/ui/src/dead-code/dead-code-view.tsx
index 017a8535c..e61743fd2 100644
--- a/packages/ui/src/dead-code/dead-code-view.tsx
+++ b/packages/ui/src/dead-code/dead-code-view.tsx
@@ -167,8 +167,10 @@ export function DeadCodeView({ adapter }: { adapter: DeadCodeAdapter }) {
fetched.length === 0 &&
(summary?.total_findings ?? 0) === 0 &&
(findings !== undefined || summary !== undefined);
- // Only a recorded run can call a zero clean; an unknown one is "not yet".
- const analyzed = Boolean(summary?.analyzed_at);
+ // A zero is clean only after a run. `null` is a host saying no run is
+ // recorded ("not yet"); an absent field is a host that does not report runs,
+ // where findings exist only once a pass has written them, so it reads as ran.
+ const analyzed = summary?.analyzed_at === undefined || Boolean(summary.analyzed_at);
// "Propose cleanup" opens the shared AI-prompt modal seeded with the safe
// list, with the same agent picker as every other AI action in the dashboard.
diff --git a/packages/ui/src/overview/next-actions.tsx b/packages/ui/src/overview/next-actions.tsx
index 98584add8..1ec60a172 100644
--- a/packages/ui/src/overview/next-actions.tsx
+++ b/packages/ui/src/overview/next-actions.tsx
@@ -60,8 +60,48 @@ export function renderActionTitle(title: string): ReactNode {
);
}
+// en-US grouping, as the server writes `{n:,}`, so a local sentence reads the same.
function plural(n: number, noun: string): string {
- return `${n.toLocaleString()} ${noun}${n === 1 ? "" : "s"}`;
+ return `${n.toLocaleString("en-US")} ${noun}${n === 1 ? "" : "s"}`;
+}
+
+const MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
+
+/** "Sep 28" from the anchor's own calendar day, never shifted into the viewer's timezone. */
+function anchorDay(iso: string | null): string | null {
+ const m = iso ? /^\d{4}-(\d{2})-(\d{2})/.exec(iso) : null;
+ const month = m ? MONTHS[Number(m[1]) - 1] : undefined;
+ return m && month ? `${month} ${Number(m[2])}` : null;
+}
+
+const workIn = (h: ActionsResponse["horizons"][ActionHorizonKey]) =>
+ (h.by_tier.act_now ?? 0) + (h.by_tier.plan ?? 0);
+
+/**
+ * The sentence for a view that carries no `summary` (a server that predates
+ * it). Same as the server's wording, from the same counts, so the line never
+ * goes blank. A view with `summary` always wins.
+ */
+function fallbackSummary(data: ActionsResponse, horizon: ActionHorizonKey): string {
+ const until = anchorDay(data.anchor);
+ const window =
+ horizon === "week"
+ ? until
+ ? `in the week to ${until}, the last indexed commit`
+ : "this week"
+ : "this quarter";
+ const work = workIn(data.horizons[horizon]);
+ if (work === 0) {
+ const other = workIn(data.horizons[horizon === "week" ? "quarter" : "week"]);
+ if (other === 0) return `Nothing stands out ${window}.`;
+ const tail =
+ horizon === "week"
+ ? `${other === 1 ? "is" : "are"} worth planning this quarter`
+ : "came up this week";
+ return `Nothing needs you ${window}. ${plural(other, "thing")} ${tail}.`;
+ }
+ const now = data.horizons[horizon].by_tier.act_now ?? 0;
+ return `${plural(work, "thing")} worth doing ${window}${now ? `, ${now} of them now` : ""}.`;
}
export function NextActions({
@@ -78,8 +118,7 @@ export function NextActions({
// "add a coverage report" is not a reason to show an empty week first.
// Counts come from `data` alone, like the sentence, so the two agree; both
// move when the host passes the re-read view after an answer.
- const work = (key: ActionHorizonKey) =>
- data ? (data.horizons[key].by_tier.act_now ?? 0) + (data.horizons[key].by_tier.plan ?? 0) : 0;
+ const work = (key: ActionHorizonKey) => (data ? workIn(data.horizons[key]) : 0);
const initial: ActionHorizonKey = work("week") === 0 && work("quarter") > 0 ? "quarter" : "week";
const [horizon, setHorizon] = useState<ActionHorizonKey>(initial);
const [expanded, setExpanded] = useState(false);
@@ -131,7 +170,7 @@ export function NextActions({
return (
<OverviewSection
title="Do next"
- description={data.summary?.[horizon] ?? ""}
+ description={data.summary?.[horizon] ?? fallbackSummary(data, horizon)}
action={
<Segmented
label="Time frame"
diff --git a/packages/ui/src/security/findings-by-directory.tsx b/packages/ui/src/security/findings-by-directory.tsx
new file mode 100644
index 000000000..d9a911f4b
--- /dev/null
+++ b/packages/ui/src/security/findings-by-directory.tsx
@@ -0,0 +1,15 @@
+// Old import path for one release, then removed. `SeverityDirectoryMatrix`
+// in `./severity-directory-matrix` takes the same `findings` and `depth` props.
+import {
+ SeverityDirectoryMatrix,
+ type SeverityDirectoryMatrixProps,
+} from "./severity-directory-matrix";
+
+/** @deprecated Use `SeverityDirectoryMatrixProps`. */
+export type FindingsByDirectoryProps = SeverityDirectoryMatrixProps;
+
+/**
+ * @deprecated Use `SeverityDirectoryMatrix`. This renders it: a plain count
+ * table of directory by severity, 14 rows by default, with no card or title.
+ */
+export const FindingsByDirectory = SeverityDirectoryMatrix;
diff --git a/packages/ui/src/security/index.ts b/packages/ui/src/security/index.ts
index 12149428e..acb0267a6 100644
--- a/packages/ui/src/security/index.ts
+++ b/packages/ui/src/security/index.ts
@@ -1,3 +1,4 @@
export * from "./findings-table";
+export * from "./findings-by-directory";
export * from "./posture";
export * from "./severity-directory-matrix";
diff --git a/packages/ui/src/shared/theme-toggle.tsx b/packages/ui/src/shared/theme-toggle.tsx
index 89a6c4d7b..2f2ebcf75 100644
--- a/packages/ui/src/shared/theme-toggle.tsx
+++ b/packages/ui/src/shared/theme-toggle.tsx
@@ -2,7 +2,7 @@
/**
* ThemeToggle: one icon button that shows the theme in effect and switches to
- * the other on click.
+ * the other on click. `showLabel` names that theme beside the icon.
*
* Relies on `next-themes` (a peer dependency of consumers) for state and
* persistence. Deliberately two-state, no "System" option. Consumers set
@@ -25,15 +25,21 @@ export interface ThemeToggleProps {
switchToLightLabel?: string;
/** Accepted for backwards compatibility; the control is always icon-only. */
compact?: boolean;
+ /** Name the theme in effect ("Light" or "Dark") beside the icon. Off by default. */
+ showLabel?: boolean;
className?: string;
}
+/** Shared by the labelled button and its placeholder, so nothing moves on mount. */
+const LABELLED_WIDTH = "min-w-[5rem]";
+
const BUTTON =
"inline-flex h-8 w-8 items-center justify-center rounded-md text-[var(--color-text-secondary)] transition-colors hover:bg-[var(--color-bg-wash-hover)] hover:text-[var(--color-text-primary)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent-primary)]";
export function ThemeToggle({
switchToDarkLabel = "Switch to dark theme",
switchToLightLabel = "Switch to light theme",
+ showLabel = false,
className,
}: ThemeToggleProps) {
const { theme, resolvedTheme, setTheme } = useTheme();
@@ -50,11 +56,19 @@ export function ThemeToggle({
}, [mounted, theme, setTheme]);
if (!mounted) {
- return <span aria-hidden className={cn("inline-block h-8 w-8", className)} />;
+ return (
+ <span
+ aria-hidden
+ className={cn("inline-block h-8", showLabel ? LABELLED_WIDTH : "w-8", className)}
+ />
+ );
}
const isDark = resolvedTheme === "dark";
- const label = isDark ? switchToLightLabel : switchToDarkLabel;
+ const current = isDark ? "Dark" : "Light";
+ const action = isDark ? switchToLightLabel : switchToDarkLabel;
+ // The accessible name starts with the visible text (WCAG 2.5.3).
+ const label = showLabel ? `${current} theme. ${action}` : action;
const Icon = isDark ? Moon : Sun;
return (
@@ -63,9 +77,10 @@ export function ThemeToggle({
aria-label={label}
title={label}
onClick={() => setTheme(isDark ? "light" : "dark")}
- className={cn(BUTTON, className)}
+ className={cn(BUTTON, showLabel && cn("w-auto gap-2 px-3", LABELLED_WIDTH), className)}
>
<Icon className="h-3.5 w-3.5 shrink-0" aria-hidden />
+ {showLabel && <span className="text-xs font-medium">{current}</span>}
</button>
);
}