From 0a224de92ff91e1b7bc6224b6a456f4d659ce7c6 Mon Sep 17 00:00:00 2001 From: RaghavChamadiya Date: Sun, 22 Nov 2026 23:14:58 +0530 Subject: [PATCH 1/8] feat(api-client): build the evidence and report clients over a host's request createRuntimeEvidenceApi and createFirstLookApi take a request function and the route root, so an app with its own fetch layer and routes reuses the paths, query names and types instead of keeping a second client. The existing functions are those factories over apiRequest with the /api/repos/{id} roots, so every URL and signature stays the same. --- packages/api-client/src/client.ts | 36 ++++++++ packages/api-client/src/reports.test.ts | 77 +++++++++++++++++ packages/api-client/src/reports.ts | 80 ++++++++--------- .../api-client/src/runtime-evidence.test.ts | 70 ++++++++++----- packages/api-client/src/runtime-evidence.ts | 85 ++++++++++--------- 5 files changed, 246 insertions(+), 102 deletions(-) create mode 100644 packages/api-client/src/reports.test.ts diff --git a/packages/api-client/src/client.ts b/packages/api-client/src/client.ts index 51597e79b4..a1f18267fd 100644 --- a/packages/api-client/src/client.ts +++ b/packages/api-client/src/client.ts @@ -275,4 +275,40 @@ export async function apiDelete( return handleResponse(res); } +/** A write's method and body, for the APIs built on `ApiRequest`. */ +export interface ApiRequestInit { + method: "POST" | "PUT"; + /** JSON text, so a host's own fetch wrapper can send it unchanged. */ + body?: string; +} + +/** + * The one request primitive the `create*Api` factories need: a path relative + * to the host's API base, its query already on it. A host with its own fetch + * layer (auth, timeouts, errors) passes its wrapper; this package passes + * `apiRequest`. + */ +export type ApiRequest = (path: string, init?: ApiRequestInit) => Promise; + +/** `ApiRequest` over this client's base URL, token and fetch. */ +export function apiRequest(path: string, init?: ApiRequestInit): Promise { + if (!init) return apiGet(path); + return init.method === "PUT" + ? apiPut(path, undefined, init) + : apiPost(path, undefined, init); +} + +/** *path* with the defined *params* as its query, encoded as `apiGet` encodes them. */ +export function withQuery( + path: string, + params: Record, +): string { + const query = new URLSearchParams(); + for (const [k, v] of Object.entries(params)) { + if (v !== undefined && v !== null) query.set(k, String(v)); + } + const text = query.toString(); + return text ? `${path}?${text}` : path; +} + export { buildHeaders }; diff --git a/packages/api-client/src/reports.test.ts b/packages/api-client/src/reports.test.ts new file mode 100644 index 0000000000..73c13172c6 --- /dev/null +++ b/packages/api-client/src/reports.test.ts @@ -0,0 +1,77 @@ +import { afterEach, describe, expect, it } from "vitest"; + +import { configureApiClient, createAdapterFetch, type ApiRequestInit } from "./client"; +import { + createFirstLookApi, + firstLookMarkdownPath, + getFirstLook, + getFirstLookPrompt, + markFirstLookItem, + rewriteFirstLook, +} from "./reports"; + +function serve() { + const sent: { url: string; method?: string | undefined; body?: string }[] = []; + configureApiClient({ + baseUrl: "http://127.0.0.1:7337", + fetch: createAdapterFetch(async (url, init) => { + sent.push({ + url: url.replace("http://127.0.0.1:7337", ""), + method: init.method, + ...(init.body !== undefined ? { body: init.body } : {}), + }); + return { status: 200, ok: true, headers: {}, text: "{}" }; + }), + }); + return sent; +} + +const ROOT = "/api/repos/r1/reports/first-look"; + +describe("repo report requests", () => { + afterEach(() => configureApiClient({ baseUrl: "" })); + + it("reads the report and its prompts with the flavor and target", async () => { + const sent = serve(); + await getFirstLook("r1", { flavor: "cursor" }); + await getFirstLookPrompt("r1", { section: "security" }, "generic"); + await getFirstLookPrompt("r1", null, "generic"); + expect(sent).toEqual([ + { url: `${ROOT}?flavor=cursor`, method: "GET" }, + { url: `${ROOT}/prompt?flavor=generic§ion=security`, method: "GET" }, + { url: `${ROOT}/prompt?flavor=generic`, method: "GET" }, + ]); + }); + + it("writes a mark and a rewrite", async () => { + const sent = serve(); + await markFirstLookItem("r1", "sec/1", { status: "done" }); + await rewriteFirstLook("r1", { flavor: "generic" }); + expect(sent).toEqual([ + { url: `${ROOT}/items/sec%2F1/mark`, method: "PUT", body: '{"status":"done"}' }, + { url: `${ROOT}/rewrite?flavor=generic`, method: "POST" }, + ]); + expect(firstLookMarkdownPath("r1")).toBe(`${ROOT}/export.md`); + }); + + it("builds a host's client over its own request and routes", async () => { + const calls: [string, ApiRequestInit | undefined][] = []; + const api = createFirstLookApi( + async (path: string, init?: ApiRequestInit) => { + calls.push([path, init]); + return {} as T; + }, + (id) => `/snapshots/${id}/report`, + ); + await api.getFirstLook("s1"); + await api.markFirstLookItem("s1", "a", { status: "ack", reason: "known" }); + expect(calls).toEqual([ + ["/snapshots/s1/report", undefined], + [ + "/snapshots/s1/report/items/a/mark", + { method: "PUT", body: '{"status":"ack","reason":"known"}' }, + ], + ]); + expect(api.firstLookMarkdownPath("s1")).toBe("/snapshots/s1/report/export.md"); + }); +}); diff --git a/packages/api-client/src/reports.ts b/packages/api-client/src/reports.ts index f4156c6621..6943cd2b6e 100644 --- a/packages/api-client/src/reports.ts +++ b/packages/api-client/src/reports.ts @@ -4,50 +4,50 @@ import type { FirstLookMarkResponse, FirstLookPage, } from "@repowise-dev/types/first-look"; -import { apiGet, apiPost, apiPut } from "./client"; +import { apiRequest, withQuery, type ApiRequest } from "./client"; -const firstLook = (repoId: string) => `/api/repos/${repoId}/reports/first-look`; +/** + * The repo report requests over *request*, under *base*: the report root for + * a repository (`/api/repos/{id}/reports/first-look` here). A host with its + * own fetch layer and routes builds its client from this, so paths, query + * names and types stay in one place. + */ +export function createFirstLookApi(request: ApiRequest, base: (repoId: string) => string) { + return { + /** The repo report now, each item's status against the first look, and the open items' prompt for `flavor`. */ + getFirstLook: (repoId: string, opts: { flavor?: AgentPromptFlavor } = {}) => + request(withQuery(base(repoId), { flavor: opts.flavor })), -/** The repo report now, each item's status against the first look, and the open items' prompt for `flavor`. */ -export async function getFirstLook( - repoId: string, - opts: { flavor?: AgentPromptFlavor } = {}, -): Promise { - return apiGet(firstLook(repoId), { flavor: opts.flavor }); -} + /** One item's prompt, one section's, or the whole report's (null), rendered by core for `flavor`. */ + getFirstLookPrompt: ( + repoId: string, + target: { item: string } | { section: string } | null, + flavor: AgentPromptFlavor, + ) => + request(withQuery(`${base(repoId)}/prompt`, { flavor, ...(target ?? {}) })), -/** One item's prompt, one section's, or the whole report's (null), rendered by core for `flavor`. */ -export async function getFirstLookPrompt( - repoId: string, - target: { item: string } | { section: string } | null, - flavor: AgentPromptFlavor, -): Promise { - return apiGet(`${firstLook(repoId)}/prompt`, { flavor, ...(target ?? {}) }); -} + /** Done, acknowledged, a false positive or snoozed: what `repowise mark` records. */ + markFirstLookItem: (repoId: string, itemId: string, body: FirstLookMarkRequest) => + request(`${base(repoId)}/items/${encodeURIComponent(itemId)}/mark`, { + method: "PUT", + body: JSON.stringify(body), + }), -/** Done, acknowledged, a false positive or snoozed: what `repowise mark` records. */ -export async function markFirstLookItem( - repoId: string, - itemId: string, - body: FirstLookMarkRequest, -): Promise { - return apiPut( - `${firstLook(repoId)}/items/${encodeURIComponent(itemId)}/mark`, - body, - ); -} + /** The report as a Markdown download, relative to the API base. */ + firstLookMarkdownPath: (repoId: string) => `${base(repoId)}/export.md`, -/** The report as a Markdown download, relative to the API base. */ -export function firstLookMarkdownPath(repoId: string): string { - return `${firstLook(repoId)}/export.md`; + /** Write the report again with the repository's model: one call. */ + rewriteFirstLook: (repoId: string, opts: { flavor?: AgentPromptFlavor } = {}) => + request(withQuery(`${base(repoId)}/rewrite`, { flavor: opts.flavor }), { + method: "POST", + }), + }; } -/** Write the report again with the repository's model: one call. */ -export async function rewriteFirstLook( - repoId: string, - opts: { flavor?: AgentPromptFlavor } = {}, -): Promise { - return apiPost(`${firstLook(repoId)}/rewrite`, undefined, undefined, { - flavor: opts.flavor, - }); -} +export const { + getFirstLook, + getFirstLookPrompt, + markFirstLookItem, + firstLookMarkdownPath, + rewriteFirstLook, +} = createFirstLookApi(apiRequest, (repoId) => `/api/repos/${repoId}/reports/first-look`); diff --git a/packages/api-client/src/runtime-evidence.test.ts b/packages/api-client/src/runtime-evidence.test.ts index 7c1dbca8c4..d16c7170c2 100644 --- a/packages/api-client/src/runtime-evidence.test.ts +++ b/packages/api-client/src/runtime-evidence.test.ts @@ -1,41 +1,65 @@ -import { beforeEach, describe, expect, it, vi } from "vitest"; +import { afterEach, describe, expect, it } from "vitest"; -const apiGet = vi.fn(); -vi.mock("./client", () => ({ - apiGet: (...args: unknown[]) => apiGet(...args), -})); +import { configureApiClient, createAdapterFetch, type ApiRequest } from "./client"; +import { + createRuntimeEvidenceApi, + getEvidenceTests, + getMeasured, + getMeasuredFunctions, +} from "./runtime-evidence"; -import { getEvidenceTests, getMeasured, getMeasuredFunctions } from "./runtime-evidence"; +function serve() { + const sent: string[] = []; + configureApiClient({ + baseUrl: "http://127.0.0.1:7337", + fetch: createAdapterFetch(async (url) => { + sent.push(url.replace("http://127.0.0.1:7337", "")); + return { status: 200, ok: true, headers: {}, text: "{}" }; + }), + }); + return sent; +} describe("runtime evidence requests", () => { - beforeEach(() => { - apiGet.mockReset(); - apiGet.mockResolvedValue({}); - }); + afterEach(() => configureApiClient({ baseUrl: "" })); it("sends the run and limit under the server's names", async () => { + const sent = serve(); await getMeasured("repo", { runId: "r1", limit: 0 }); - expect(apiGet).toHaveBeenCalledWith("/api/repos/repo/evidence/measured", { - run_id: "r1", - limit: 0, - }); + expect(sent).toEqual(["/api/repos/repo/evidence/measured?run_id=r1&limit=0"]); }); it("asks for one function or one file", async () => { + const sent = serve(); await getMeasuredFunctions("repo", { symbolId: "src/a.py::f" }); - expect(apiGet).toHaveBeenLastCalledWith("/api/repos/repo/evidence/functions", { - symbol_id: "src/a.py::f", - file: undefined, - }); await getMeasuredFunctions("repo", { file: "src/a.py" }); - expect(apiGet).toHaveBeenLastCalledWith("/api/repos/repo/evidence/functions", { - symbol_id: undefined, - file: "src/a.py", - }); + expect(sent).toEqual([ + "/api/repos/repo/evidence/functions?symbol_id=src%2Fa.py%3A%3Af", + "/api/repos/repo/evidence/functions?file=src%2Fa.py", + ]); }); it("asks for the slowest tests with a limit", async () => { + const sent = serve(); await getEvidenceTests("repo", { limit: 10 }); - expect(apiGet).toHaveBeenCalledWith("/api/repos/repo/evidence/tests", { limit: 10 }); + await getEvidenceTests("repo"); + expect(sent).toEqual(["/api/repos/repo/evidence/tests?limit=10", "/api/repos/repo/evidence/tests"]); + }); + + it("builds a host's client over its own request and routes", async () => { + const paths: string[] = []; + const request: ApiRequest = async (path: string) => { + paths.push(path); + return {} as T; + }; + const api = createRuntimeEvidenceApi(request, (id) => `/snapshots/${id}/evidence`); + await api.getEvidenceStatus("s1"); + await api.listEvidenceRuns("s1"); + await api.getMeasured("s1", { limit: 5 }); + expect(paths).toEqual([ + "/snapshots/s1/evidence/status", + "/snapshots/s1/evidence/runs", + "/snapshots/s1/evidence/measured?limit=5", + ]); }); }); diff --git a/packages/api-client/src/runtime-evidence.ts b/packages/api-client/src/runtime-evidence.ts index c02a6ae459..df108cf8b3 100644 --- a/packages/api-client/src/runtime-evidence.ts +++ b/packages/api-client/src/runtime-evidence.ts @@ -9,7 +9,7 @@ import type { MeasuredResponse, SuiteCostResponse, } from "@repowise-dev/types/runtime-evidence"; -import { apiGet } from "./client"; +import { apiRequest, withQuery, type ApiRequest } from "./client"; export type { EvidenceRunSummary, @@ -28,46 +28,53 @@ export type { SuiteCostResponse, } from "@repowise-dev/types/runtime-evidence"; -/** The newest run of every workload, and whether anything is ranked. */ -export async function getEvidenceStatus(repoId: string): Promise { - return apiGet(`/api/repos/${repoId}/evidence/status`); -} +/** + * The runtime-evidence requests over *request*, under *base*: the evidence + * root for a repository (`/api/repos/{id}/evidence` here). A host with its own + * fetch layer and routes builds its client from this, so paths, query names + * and types stay in one place. + */ +export function createRuntimeEvidenceApi(request: ApiRequest, base: (repoId: string) => string) { + return { + /** The newest run of every workload, and whether anything is ranked. */ + getEvidenceStatus: (repoId: string) => + request(`${base(repoId)}/status`), -/** Every stored run, newest first. */ -export async function listEvidenceRuns(repoId: string): Promise { - return apiGet(`/api/repos/${repoId}/evidence/runs`); -} + /** Every stored run, newest first. */ + listEvidenceRuns: (repoId: string) => request(`${base(repoId)}/runs`), -/** Each workload's newest run with its ranked functions; `runId` keeps one run. */ -export async function getMeasured( - repoId: string, - opts: { - runId?: string; - /** Rows per run, 0-100; the server defaults to 10. */ - limit?: number; - } = {}, -): Promise { - return apiGet(`/api/repos/${repoId}/evidence/measured`, { - run_id: opts.runId, - limit: opts.limit, - }); -} + /** Each workload's newest run with its ranked functions; `runId` keeps one run. */ + getMeasured: ( + repoId: string, + opts: { + runId?: string; + /** Rows per run, 0-100; the server defaults to 10. */ + limit?: number; + } = {}, + ) => + request( + withQuery(`${base(repoId)}/measured`, { run_id: opts.runId, limit: opts.limit }), + ), -/** The measured view of one function or of every function in a file. */ -export async function getMeasuredFunctions( - repoId: string, - target: { symbolId: string; file?: never } | { file: string; symbolId?: never }, -): Promise { - return apiGet(`/api/repos/${repoId}/evidence/functions`, { - symbol_id: target.symbolId, - file: target.file, - }); -} + /** The measured view of one function or of every function in a file. */ + getMeasuredFunctions: ( + repoId: string, + target: { symbolId: string; file?: never } | { file: string; symbolId?: never }, + ) => + request( + withQuery(`${base(repoId)}/functions`, { symbol_id: target.symbolId, file: target.file }), + ), -/** The slowest timed tests and the test time per production file, from stored JUnit timings. */ -export async function getEvidenceTests( - repoId: string, - opts: { limit?: number } = {}, -): Promise { - return apiGet(`/api/repos/${repoId}/evidence/tests`, { limit: opts.limit }); + /** The slowest timed tests and the test time per production file, from stored JUnit timings. */ + getEvidenceTests: (repoId: string, opts: { limit?: number } = {}) => + request(withQuery(`${base(repoId)}/tests`, { limit: opts.limit })), + }; } + +export const { + getEvidenceStatus, + listEvidenceRuns, + getMeasured, + getMeasuredFunctions, + getEvidenceTests, +} = createRuntimeEvidenceApi(apiRequest, (repoId) => `/api/repos/${repoId}/evidence`); From 9381a39dbfd1c4b7dad36e26dd3fb19fa8093bee Mon Sep 17 00:00:00 2001 From: RaghavChamadiya Date: Sun, 22 Nov 2026 23:54:45 +0530 Subject: [PATCH 2/8] feat(ui): a copy callback on the decisions hero and a host body for usage DecisionAgentHero takes onCopy("prompt" | "review_all"), called when either copy button is clicked, so a host counts the handoff without reading the button label. RepowiseUsage takes children in place of the token figures and table, for a host that bills from a ledger and records no tokens; fallback stays for loading and errors. --- .../decisions/decision-agent-prompts.test.tsx | 17 +++++++++++++++ .../__tests__/savings/savings-page.test.tsx | 19 +++++++++++++++++ .../src/decisions/decision-agent-prompts.tsx | 16 +++++++++++++- packages/ui/src/savings/repowise-usage.tsx | 21 ++++++++++++++++--- 4 files changed, 69 insertions(+), 4 deletions(-) diff --git a/packages/ui/__tests__/decisions/decision-agent-prompts.test.tsx b/packages/ui/__tests__/decisions/decision-agent-prompts.test.tsx index e9a904f5de..315f681c49 100644 --- a/packages/ui/__tests__/decisions/decision-agent-prompts.test.tsx +++ b/packages/ui/__tests__/decisions/decision-agent-prompts.test.tsx @@ -140,6 +140,23 @@ describe("DecisionAgentHero", () => { expect(screen.getByRole("button", { name: "Copy prompt for your agent" })).toBeInTheDocument(); }); + it("tells the host which prompt was copied", async () => { + Object.assign(navigator, { clipboard: { writeText: vi.fn(async () => undefined) } }); + const onCopy = vi.fn(); + render( + , + ); + + fireEvent.click(screen.getByRole("button", { name: "Copy prompt for your agent" })); + fireEvent.click(screen.getByRole("button", { name: "Review all records" })); + + await waitFor(() => expect(onCopy.mock.calls).toEqual([["prompt"], ["review_all"]])); + }); + it("hides the whole-queue button when the host has no text for it", () => { const none = render(); expect(screen.queryByRole("button", { name: "Review all records" })).toBeNull(); diff --git a/packages/ui/__tests__/savings/savings-page.test.tsx b/packages/ui/__tests__/savings/savings-page.test.tsx index b320d039e9..bff31d94c6 100644 --- a/packages/ui/__tests__/savings/savings-page.test.tsx +++ b/packages/ui/__tests__/savings/savings-page.test.tsx @@ -240,6 +240,25 @@ describe("SavingsPageBody, partial states", () => { }); }); +describe("RepowiseUsage, host body", () => { + it("shows the host's own spend in place of the token figures and grouping", () => { + renderBody({ + savings: undefined, + usage: { + summary: spend, + rows: undefined, + grouping: "operation", + onGroupingChange: () => {}, + children:

Ledger: 12 credits

, + }, + }); + expect(screen.getByText(copy.usageTitle)).toBeTruthy(); + expect(screen.getByText("Ledger: 12 credits")).toBeTruthy(); + expect(screen.queryByText(copy.inputTokens)).toBeNull(); + expect(screen.queryByRole("radiogroup")).toBeNull(); + }); +}); + describe("SavingsPageBody, empty states", () => { it("fresh: nothing recorded and no spend", () => { renderBody({ diff --git a/packages/ui/src/decisions/decision-agent-prompts.tsx b/packages/ui/src/decisions/decision-agent-prompts.tsx index fb63b864a6..cb92eac041 100644 --- a/packages/ui/src/decisions/decision-agent-prompts.tsx +++ b/packages/ui/src/decisions/decision-agent-prompts.tsx @@ -104,6 +104,12 @@ export interface DecisionAgentHeroProps { readOnlyNote?: string; /** Lines of the prompt shown in the preview well. */ previewLines?: number; + /** + * Called when the person clicks a copy button: `prompt` for the main one, + * `review_all` for the secondary. Lets a host count the handoff without + * reading the button's label. + */ + onCopy?: (which: "prompt" | "review_all") => void; className?: string; } @@ -143,6 +149,7 @@ export function DecisionAgentHero({ reviewAll, readOnlyNote, previewLines = 6, + onCopy, className, }: DecisionAgentHeroProps) { const headingId = React.useId(); @@ -164,6 +171,7 @@ export function DecisionAgentHero({ } const copy = async () => { + onCopy?.("prompt"); let ok = true; try { await navigator.clipboard.writeText(prompt.text); @@ -213,7 +221,13 @@ export function DecisionAgentHero({ {result === "copied" ? : } {copyLabel} - + {reviewAll?.text ? ( + reviewAll.text} + label={reviewAll.label} + onClick={() => onCopy?.("review_all")} + /> + ) : null} {handoff} {result === "copied" ? copiedLabel : result === "failed" ? failedLabel : ""} diff --git a/packages/ui/src/savings/repowise-usage.tsx b/packages/ui/src/savings/repowise-usage.tsx index 49d99e7725..892a66d272 100644 --- a/packages/ui/src/savings/repowise-usage.tsx +++ b/packages/ui/src/savings/repowise-usage.tsx @@ -18,6 +18,13 @@ export interface RepowiseUsageProps { onGroupingChange: (grouping: SpendGrouping) => void; /** Rendered in place of the figures while the host loads or after it failed. */ fallback?: React.ReactNode; + /** + * The host's own account of its spend, in place of the token figures and + * table, for a host that bills from a ledger and records no tokens. The + * grouping control goes with the table. On the savings page, + * `summary.total_calls` still decides whether the section shows at all. + */ + children?: React.ReactNode; } /** @@ -26,7 +33,15 @@ export interface RepowiseUsageProps { * subscription or machine says so instead of printing $0.00, and a window * with no calls says Repowise cost nothing. */ -export function RepowiseUsage({ copy, summary, rows, grouping, onGroupingChange, fallback }: RepowiseUsageProps) { +export function RepowiseUsage({ + copy, + summary, + rows, + grouping, + onGroupingChange, + fallback, + children, +}: RepowiseUsageProps) { return (
@@ -34,7 +49,7 @@ export function RepowiseUsage({ copy, summary, rows, grouping, onGroupingChange,

{copy.usageTitle}

{copy.usageSub}

- {summary && summary.total_calls > 0 && !fallback && ( + {summary && summary.total_calls > 0 && !fallback && !children && ( label={copy.usageGroupLabel} value={grouping} @@ -46,7 +61,7 @@ export function RepowiseUsage({ copy, summary, rows, grouping, onGroupingChange, /> )} - {fallback ?? (summary ? : null)} + {fallback ?? children ?? (summary ? : null)}
); } From 0bf82489604398d5b1b9daa53b21ddcb652919dc Mon Sep 17 00:00:00 2001 From: RaghavChamadiya Date: Mon, 23 Nov 2026 00:00:10 +0530 Subject: [PATCH 3/8] fix(ui): a false usage body keeps the token figures --- .../ui/__tests__/savings/savings-page.test.tsx | 17 ++++++++++++++++- packages/ui/src/savings/repowise-usage.tsx | 6 ++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/packages/ui/__tests__/savings/savings-page.test.tsx b/packages/ui/__tests__/savings/savings-page.test.tsx index bff31d94c6..637ea1f3d6 100644 --- a/packages/ui/__tests__/savings/savings-page.test.tsx +++ b/packages/ui/__tests__/savings/savings-page.test.tsx @@ -255,7 +255,22 @@ describe("RepowiseUsage, host body", () => { expect(screen.getByText(copy.usageTitle)).toBeTruthy(); expect(screen.getByText("Ledger: 12 credits")).toBeTruthy(); expect(screen.queryByText(copy.inputTokens)).toBeNull(); - expect(screen.queryByRole("radiogroup")).toBeNull(); + expect(screen.queryByRole("radiogroup", { name: copy.usageGroupLabel })).toBeNull(); + }); + + it("keeps the token figures when a conditional body renders false", () => { + const hasLedger = false; + renderBody({ + usage: { + summary: spend, + rows, + grouping: "operation", + onGroupingChange: () => {}, + children: hasLedger &&

Ledger

, + }, + }); + expect(screen.getAllByText(copy.inputTokens).length).toBeGreaterThan(0); + expect(screen.getByRole("radiogroup", { name: copy.usageGroupLabel })).toBeTruthy(); }); }); diff --git a/packages/ui/src/savings/repowise-usage.tsx b/packages/ui/src/savings/repowise-usage.tsx index 892a66d272..780387335d 100644 --- a/packages/ui/src/savings/repowise-usage.tsx +++ b/packages/ui/src/savings/repowise-usage.tsx @@ -42,6 +42,8 @@ export function RepowiseUsage({ fallback, children, }: RepowiseUsageProps) { + // `{hasLedger && }` passes false: no host body, so the figures show. + const hostBody = children || null; return (
@@ -49,7 +51,7 @@ export function RepowiseUsage({

{copy.usageTitle}

{copy.usageSub}

- {summary && summary.total_calls > 0 && !fallback && !children && ( + {summary && summary.total_calls > 0 && !fallback && !hostBody && ( label={copy.usageGroupLabel} value={grouping} @@ -61,7 +63,7 @@ export function RepowiseUsage({ /> )} - {fallback ?? children ?? (summary ? : null)} + {fallback ?? hostBody ?? (summary ? : null)}
); } From 2f992814b978c444e8c19ab484ca8e964d882c08 Mon Sep 17 00:00:00 2001 From: RaghavChamadiya Date: Mon, 23 Nov 2026 00:18:24 +0530 Subject: [PATCH 4/8] fix(ui): run the hero's onCopy after the copy, and say when the usage section shows --- packages/ui/src/decisions/decision-agent-prompts.tsx | 3 ++- packages/ui/src/savings/repowise-usage.tsx | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/ui/src/decisions/decision-agent-prompts.tsx b/packages/ui/src/decisions/decision-agent-prompts.tsx index cb92eac041..62c60c792e 100644 --- a/packages/ui/src/decisions/decision-agent-prompts.tsx +++ b/packages/ui/src/decisions/decision-agent-prompts.tsx @@ -171,7 +171,6 @@ export function DecisionAgentHero({ } const copy = async () => { - onCopy?.("prompt"); let ok = true; try { await navigator.clipboard.writeText(prompt.text); @@ -181,6 +180,8 @@ export function DecisionAgentHero({ setResult(ok ? "copied" : "failed"); if (timer.current) clearTimeout(timer.current); timer.current = setTimeout(() => setResult(null), 2400); + // After the copy and its feedback, so a host callback that throws cannot stop either. + onCopy?.("prompt"); }; return ( diff --git a/packages/ui/src/savings/repowise-usage.tsx b/packages/ui/src/savings/repowise-usage.tsx index 780387335d..505076773c 100644 --- a/packages/ui/src/savings/repowise-usage.tsx +++ b/packages/ui/src/savings/repowise-usage.tsx @@ -21,8 +21,9 @@ export interface RepowiseUsageProps { /** * The host's own account of its spend, in place of the token figures and * table, for a host that bills from a ledger and records no tokens. The - * grouping control goes with the table. On the savings page, - * `summary.total_calls` still decides whether the section shows at all. + * grouping control goes with the table. With no savings recorded, + * `SavingsPageBody` shows the section only when `summary.total_calls` is + * above zero; with savings it always shows. */ children?: React.ReactNode; } From 430e1687ce5ac35c8a2d8f7fa54801aa09eda4ff Mon Sep 17 00:00:00 2001 From: RaghavChamadiya Date: Mon, 23 Nov 2026 00:18:54 +0530 Subject: [PATCH 5/8] test(ui): wait for the main copy before the review-all one --- packages/ui/__tests__/decisions/decision-agent-prompts.test.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ui/__tests__/decisions/decision-agent-prompts.test.tsx b/packages/ui/__tests__/decisions/decision-agent-prompts.test.tsx index 315f681c49..6d83ab3d48 100644 --- a/packages/ui/__tests__/decisions/decision-agent-prompts.test.tsx +++ b/packages/ui/__tests__/decisions/decision-agent-prompts.test.tsx @@ -152,8 +152,8 @@ describe("DecisionAgentHero", () => { ); fireEvent.click(screen.getByRole("button", { name: "Copy prompt for your agent" })); + await waitFor(() => expect(onCopy.mock.calls).toEqual([["prompt"]])); fireEvent.click(screen.getByRole("button", { name: "Review all records" })); - await waitFor(() => expect(onCopy.mock.calls).toEqual([["prompt"], ["review_all"]])); }); From 6432f53852e40fc60f00e15b678a0222f3c58971 Mon Sep 17 00:00:00 2001 From: RaghavChamadiya Date: Mon, 23 Nov 2026 01:14:05 +0530 Subject: [PATCH 6/8] fix(types): a measured hotspot's evidence row has no finding id --- packages/types/src/health.ts | 3 +- .../health/performance-view.test.tsx | 39 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/packages/types/src/health.ts b/packages/types/src/health.ts index 0c7634eac5..882544688c 100644 --- a/packages/types/src/health.ts +++ b/packages/types/src/health.ts @@ -414,7 +414,8 @@ export interface PerformanceOpportunityFix { } export interface PerformanceOpportunityEvidence { - finding_id: string; + /** Null for a measured hotspot, which comes from runtime evidence, not a static finding. */ + finding_id: string | null; file_path: string; biomarker_type: string; function_name: string | null; diff --git a/packages/ui/__tests__/health/performance-view.test.tsx b/packages/ui/__tests__/health/performance-view.test.tsx index 6d97daa980..d3e8951950 100644 --- a/packages/ui/__tests__/health/performance-view.test.tsx +++ b/packages/ui/__tests__/health/performance-view.test.tsx @@ -832,6 +832,45 @@ describe("PerformanceView measured hotspot drawer", () => { }); }); +describe("PerformanceView measured hotspot with no static finding", () => { + it("renders an evidence row whose finding_id is null", async () => { + const measurement = 'Measured: rank 2 of repo code in entry_point "cli serve" (8% self), 1d old'; + const hotspot = opportunity({ + opportunity_id: "perf2_hotspot_null", + biomarker_type: "measured_hotspot", + boundary_kind: null, + intervention_symbol: "src/b.py::serve", + observations_total: 0, + evidence: [ + { + finding_id: null, + file_path: "src/b.py", + biomarker_type: "measured_hotspot", + function_name: "serve", + line_start: null, + line_end: null, + reason: measurement, + path: [], + provenance: "measured", + }, + ], + }); + const one = page({ items: [hotspot], total: 1, next_offset: null }); + render( + one, + getPerformanceOpportunity: undefined, + getMeasuredFunctions: undefined, + })} + />, + ); + await openFirstRow(); + expect(await screen.findByText("Runs that measured it")).toBeTruthy(); + expect(screen.getByText(measurement)).toBeTruthy(); + }); +}); + describe("PerformanceView drawer siblings", () => { it("names a preferred sibling's fix as the stronger one", async () => { const withSiblings = page({ From 5b91bd99459dbc098d91eaaf8f1dc93e7b4eccee Mon Sep 17 00:00:00 2001 From: RaghavChamadiya Date: Mon, 23 Nov 2026 01:17:40 +0530 Subject: [PATCH 7/8] docs(ui): say a usage host body needs counted calls with no savings --- packages/ui/src/savings/repowise-usage.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/ui/src/savings/repowise-usage.tsx b/packages/ui/src/savings/repowise-usage.tsx index 505076773c..1c53ca2a29 100644 --- a/packages/ui/src/savings/repowise-usage.tsx +++ b/packages/ui/src/savings/repowise-usage.tsx @@ -23,7 +23,9 @@ export interface RepowiseUsageProps { * table, for a host that bills from a ledger and records no tokens. The * grouping control goes with the table. With no savings recorded, * `SavingsPageBody` shows the section only when `summary.total_calls` is - * above zero; with savings it always shows. + * above zero, so a host body there needs a `summary` that counts its + * charges as calls; with zero, the page shows its fresh state and the host + * renders its own account beside it. With savings the section always shows. */ children?: React.ReactNode; } From 37b15183423b3122ab9442470f7a7c36e098d1a4 Mon Sep 17 00:00:00 2001 From: RaghavChamadiya Date: Mon, 23 Nov 2026 01:29:33 +0530 Subject: [PATCH 8/8] fix(ui): the repo report names the sections it could not collect FirstLookReport dropped report.unavailable, so a section core could not read looked like one with nothing found. It now lists each one under "Not in this report" with core's reason, linked through hrefFor where the shell has the section's page, or through an optional unavailableHref. Nothing renders when every section was read. --- .../report/first-look-report.test.tsx | 26 +++++++ packages/ui/src/report/first-look/copy.ts | 6 ++ .../report/first-look/first-look-report.tsx | 67 +++++++++++++++++++ .../ui/src/report/first-look/sections.tsx | 9 ++- packages/web/messages/en.json | 2 + packages/web/messages/zh-CN.json | 2 + .../src/components/reports/first-look-copy.ts | 2 + 7 files changed, 112 insertions(+), 2 deletions(-) diff --git a/packages/ui/__tests__/report/first-look-report.test.tsx b/packages/ui/__tests__/report/first-look-report.test.tsx index 3ae0078de2..06adc33fd9 100644 --- a/packages/ui/__tests__/report/first-look-report.test.tsx +++ b/packages/ui/__tests__/report/first-look-report.test.tsx @@ -137,6 +137,32 @@ function renderReport(props: Partial[0]> = {} afterEach(() => vi.restoreAllMocks()); +describe("FirstLookReport, sections it could not collect", () => { + const unavailable = { ownership: "No checkout to read history from.", coverage: "No coverage report stored." }; + + it("names each one with its reason and links the ones the shell has a page for", () => { + renderReport({ report: report({ unavailable }) }); + const block = screen.getByRole("heading", { name: "Not in this report" }).closest("section")!; + expect(within(block).getByText("No checkout to read history from.")).toBeInTheDocument(); + expect(within(block).getByText("No coverage report stored.")).toBeInTheDocument(); + expect(within(block).getAllByRole("link").map((a) => a.getAttribute("href"))).toEqual(["/r/ownership"]); + }); + + it("takes the host's page for a section", () => { + renderReport({ + report: report({ unavailable }), + unavailableHref: (section) => (section === "coverage" ? "/host/coverage" : null), + }); + const block = screen.getByRole("heading", { name: "Not in this report" }).closest("section")!; + expect(within(block).getAllByRole("link").map((a) => a.getAttribute("href"))).toEqual(["/host/coverage"]); + }); + + it("adds nothing when every section was read", () => { + renderReport(); + expect(screen.queryByRole("heading", { name: "Not in this report" })).toBeNull(); + }); +}); + describe("FirstLookReport", () => { it("reads as one document: strip, Start here, then sections in report order", () => { const { container } = renderReport(); diff --git a/packages/ui/src/report/first-look/copy.ts b/packages/ui/src/report/first-look/copy.ts index 3f7060c3e1..69e74df5b8 100644 --- a/packages/ui/src/report/first-look/copy.ts +++ b/packages/ui/src/report/first-look/copy.ts @@ -50,6 +50,10 @@ export interface FirstLookCopy { countOf: (n: string, total: string) => string; /** "{n} more in the app". */ moreInApp: (n: string) => string; + /** Heading over the sections the report could not collect. */ + notInReport: string; + /** "Open Security", the link to an uncollected section's page. */ + openSection: (title: string) => string; linesCovered: string; branchesCovered: string; /** Compact table headings. */ @@ -152,6 +156,8 @@ export const FIRST_LOOK_COPY_EN: FirstLookCopy = { copyItemPrompt: "Copy prompt for this item", countOf: (n, total) => `${n} of ${total}`, moreInApp: (n) => `${n} more in the app`, + notInReport: "Not in this report", + openSection: (title) => `Open ${title}`, linesCovered: "lines covered", branchesCovered: "branches covered", table: { diff --git a/packages/ui/src/report/first-look/first-look-report.tsx b/packages/ui/src/report/first-look/first-look-report.tsx index b8aa5b188e..051e6c20fe 100644 --- a/packages/ui/src/report/first-look/first-look-report.tsx +++ b/packages/ui/src/report/first-look/first-look-report.tsx @@ -17,6 +17,7 @@ import { FIRST_LOOK_COPY_EN, type FirstLookCopy } from "./copy"; import { PAIRED, isClosed, progress, resolvedBySection, stripValue, type Progress } from "./living"; import { ReportSection, + sectionHref, sectionIcon, type FirstLookHrefFor, type LinkLike, @@ -30,6 +31,12 @@ export interface FirstLookReportProps { /** The living report: rebuilt from the index, compared with the first look. */ report: FirstLookLivingReport; hrefFor: FirstLookHrefFor; + /** + * The page for a section the report could not collect (`report.unavailable`). + * Omitted, the section's route key goes through `hrefFor`; null leaves the + * line without a link. + */ + unavailableHref?: (section: string) => string | null; /** Where the top bar's back link goes. */ overviewHref: string; /** The prompt for an item, a section, or the whole report (null). */ @@ -196,6 +203,58 @@ function Footer({ ); } +/** + * The sections the report could not collect, each with core's reason, so an + * absent section never reads as "nothing found". Nothing when all were read. + */ +function Unavailable({ + report, + copy, + title, + href, + Link, +}: { + report: FirstLookLivingReport; + copy: FirstLookCopy; + title: (key: string) => string; + href: (section: string) => string | null; + Link: LinkLike; +}) { + const entries = Object.entries(report.unavailable ?? {}); + if (!entries.length) return null; + return ( +
+

+ {copy.notInReport} +

+
    + {entries.map(([key, reason]) => { + const name = title(key); + const to = href(key); + return ( +
  • + {name} + {reason} + {to ? ( + + {copy.openSection(name)} + + + ) : null} +
  • + ); + })} +
+
+ ); +} + type Rewrite = { onRewrite: () => void; cost: number | null; running: boolean } | null; /** Who wrote the wording, and the way to have the model write it again. */ @@ -250,6 +309,7 @@ function Toast({ message }: { message: string | null }) { export function FirstLookReport({ report, hrefFor, + unavailableHref, overviewHref, loadPrompt, promptFlavor = "generic", @@ -345,6 +405,13 @@ export function FirstLookReport({ {report.sections.map((s) => (paired && PAIRED.includes(s.key) ? null : renderSection(s.key)))} {paired ?
{PAIRED.map(renderSection)}
: null} + sectionHref(key, hrefFor))} + Link={Link} + />