The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 22:00 UTC
feat(clients): every PR +/- shows its code, tests, and docs split, without the hover wait (#22255)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Theo Browne committed
Oct 20, 2026 at 02:52 UTC
962428df104d1958ff58a3b205e64a07117e7781
13 files changed
+195
-39
apps/mobile/src/features/pull-requests/PullRequestFiles.tsx
+1
@@ -29,6 +29,7 @@ const BREAKDOWN_LABELS = {
29
tests: "Tests",
30
mocks: "Mocks",
31
generated: "Generated",
32
+ docs: "Docs",
33
} satisfies Record<keyof NonNullable<PullRequestChangeBreakdown>, string>;
34
35
function PullRequestChangeBreakdownLine(props: {
apps/server/src/pullRequest/pullRequestChangeBreakdown.test.ts
+2
@@ -12,6 +12,7 @@ describe("toChangeBreakdown", () => {
12
{ path: "src/b.ts", additions: 5, deletions: 1 },
13
{ path: "src/a.test.ts", additions: 40, deletions: 0 },
14
{ path: "pnpm-lock.yaml", additions: 300, deletions: 120 },
15
+ { path: "README.md", additions: 7, deletions: 3 },
16
],
17
}),
18
).toEqual({
@@ -19,6 +20,7 @@ describe("toChangeBreakdown", () => {
20
tests: { additions: 40, deletions: 0 },
21
mocks: { additions: 0, deletions: 0 },
22
generated: { additions: 300, deletions: 120 },
23
+ docs: { additions: 7, deletions: 3 },
24
});
25
});
26
apps/server/src/pullRequest/pullRequestChangeBreakdown.ts
+7
-1
@@ -5,7 +5,13 @@ import type { ProviderFileStats } from "@t3tools/source-control-core/server/Pull
5
export function toChangeBreakdown(stats: ProviderFileStats): PullRequestChangeBreakdown {
6
if (stats.truncated) return null;
7
const empty = () => ({ additions: 0, deletions: 0 });
8
- const breakdown = { code: empty(), tests: empty(), mocks: empty(), generated: empty() };
8
+ const breakdown = {
9
+ code: empty(),
10
+ tests: empty(),
11
+ mocks: empty(),
12
+ generated: empty(),
13
+ docs: empty(),
14
+ };
15
for (const file of stats.files) {
16
const bucket = breakdown[classifyChangedFile(file.path)];
17
bucket.additions += file.additions;
apps/web/src/components/chat/ThreadDetailsPrRow.browser.test.tsx
+41
-1
@@ -12,6 +12,7 @@ import { AsyncResult } from "effect/reactivity";
12
import { act } from "react";
13
import { createRoot, type Root } from "react-dom/client";
14
import { afterEach, beforeEach, expect, it, vi } from "vite-plus/test";
15
+import { userEvent } from "vite-plus/test/browser";
16
17
const state = vi.hoisted(() => ({
18
status: "success" as PullRequestCheck["status"],
@@ -26,7 +27,14 @@ const state = vi.hoisted(() => ({
27
28
vi.mock(import("~/state/entities"), async (importOriginal) => ({
29
...(await importOriginal()),
29
- useServerConfigs: (() => new Map()) as never,
30
+ // Rows render a pull request only with a project, so this does not reach tests that pass none.
31
+ useServerConfigs: (() =>
32
+ new Map([
33
+ [
34
+ EnvironmentId.make("environment"),
35
+ { environment: { capabilities: { pullRequests: true } } },
36
+ ],
37
+ ])) as never,
38
}));
39
const queryData = () => ({
40
projectId: ProjectId.make("project"),
@@ -58,6 +66,16 @@ vi.mock(import("~/state/query"), async (importOriginal) => ({
66
select(AsyncResult.success(queryData()))) as never,
67
useEnvironmentQueryIsNewer: () => true,
68
useEnvironmentQueryRefresh: () => ({ refresh: vi.fn(), isPending: () => false }),
69
+ useEnvironmentQuery: (() => ({
70
+ data: {
71
+ code: { additions: 1, deletions: 0 },
72
+ tests: { additions: 0, deletions: 0 },
73
+ mocks: { additions: 0, deletions: 0 },
74
+ generated: { additions: 0, deletions: 0 },
75
+ docs: { additions: 7, deletions: 3 },
76
+ },
77
+ isPending: false,
78
+ })) as never,
79
}));
80
vi.mock(import("../pullRequest/usePullRequestActions"), async (importOriginal) => ({
81
...(await importOriginal()),
@@ -231,3 +249,25 @@ it("shows the current checkout recovery detail when fixing checks fails and is r
249
second.detail,
250
]);
251
});
252
+
253
+it("splits the change by file kind in the hover card", async () => {
254
+ act(() =>
255
+ root.render(
256
+ <ThreadDetailsPrRow
257
+ environmentId={EnvironmentId.make("environment")}
258
+ pr={null}
259
+ number={1}
260
+ reference={{ repository: "owner/repo", number: 1 }}
261
+ status={null}
262
+ project={{ id: ProjectId.make("project"), repositoryIdentity: null } as never}
263
+ label="Test PR"
264
+ openAriaLabel="Open PR"
265
+ onOpen={vi.fn()}
266
+ />,
267
+ ),
268
+ );
269
+ await act(() => userEvent.hover(container.querySelector('button[aria-label="Open PR"]')!));
270
+ await expect
271
+ .poll(() => document.querySelector('[data-slot="tooltip-popup"][data-open]')?.textContent)
272
+ .toMatch(/Docs\+7-3/);
273
+});
apps/web/src/components/chat/ThreadDetailsPrRow.tsx
+8
@@ -1,3 +1,4 @@
1
+import { PullRequestChangeBreakdownRows } from "../pullRequest/PullRequestChangeBreakdownStat";
2
import { ThreadDetailsControl } from "./ThreadDetailsControl";
3
import { PullRequestGlyph } from "../pullRequest/pullRequestIcons";
4
import { selectEnvironmentQueryData } from "@t3tools/client-runtime/state/runtime";
@@ -292,6 +293,13 @@ export function ThreadDetailsPrRow({
293
<PullRequestDiffStat additions={detail.additions} deletions={detail.deletions} />
294
</div>
295
</div>
296
+ {reference !== null && (detail.additions > 0 || detail.deletions > 0) ? (
297
+ <PullRequestChangeBreakdownRows
298
+ environmentId={environmentId}
299
+ reference={reference}
300
+ className="pl-5 text-foreground/75"
301
+ />
302
+ ) : null}
303
</div>
304
</div>
305
</TooltipPopup>
apps/web/src/components/pullRequest/PullRequestChangeBreakdownStat.tsx
+62
-25
@@ -13,12 +13,15 @@ const KIND_LABELS = {
13
tests: "Tests",
14
mocks: "Mocks",
15
generated: "Generated",
16
+ docs: "Docs",
17
} satisfies Record<keyof NonNullable<PullRequestChangeBreakdown>, string>;
18
19
+type DiffTotals = { additions: number; deletions: number };
20
+
21
/**
22
* The pull request's diff stat, with a hover split into code, tests, mocks, and generated files.
20
- * The split is read on first pointer or focus intent, so a page nobody hovers costs the host
21
- * nothing.
23
+ * In lists the split is read on first pointer or focus intent, so rows nobody hovers cost the
24
+ * host nothing. A view of one pull request passes `eager` so the split is ready before the hover.
25
*/
26
export function PullRequestChangeBreakdownStat({
27
environmentId,
@@ -26,14 +29,16 @@ export function PullRequestChangeBreakdownStat({
29
additions,
30
deletions,
31
className,
32
+ eager = false,
33
}: {
34
environmentId: EnvironmentId;
35
reference: PullRequestRef;
36
additions: number;
37
deletions: number;
38
className: string;
39
+ eager?: boolean;
40
}) {
36
- const [requested, setRequested] = useState(false);
41
+ const [requested, setRequested] = useState(eager);
42
const query = useEnvironmentQuery(
43
requested ? pullRequestEnvironment.changeBreakdown({ environmentId, input: reference }) : null,
44
);
@@ -56,21 +61,7 @@ export function PullRequestChangeBreakdownStat({
61
/>
62
{breakdown ? (
63
<TooltipPopup side="bottom">
59
- <div className="grid grid-cols-[auto_auto_auto] gap-x-4 gap-y-1 py-0.5 font-mono tabular-nums">
60
- {(Object.keys(KIND_LABELS) as Array<keyof typeof KIND_LABELS>).map((kind) => {
61
- const { additions, deletions } = breakdown[kind];
62
- return additions === 0 && deletions === 0 ? null : (
63
- <BreakdownRow
64
- key={kind}
65
- label={KIND_LABELS[kind]}
66
- additions={additions}
67
- deletions={deletions}
68
- />
69
- );
70
- })}
71
- <div className="col-span-3 border-t border-border" />
72
- <BreakdownRow label="Total" additions={additions} deletions={deletions} />
73
- </div>
64
+ <ChangeBreakdownGrid breakdown={breakdown} total={{ additions, deletions }} />
65
</TooltipPopup>
66
) : query.isPending ? (
67
<TooltipPopup side="bottom">Loading breakdown</TooltipPopup>
@@ -79,15 +70,61 @@ export function PullRequestChangeBreakdownStat({
70
);
71
}
72
82
-function BreakdownRow({
83
- label,
84
- additions,
85
- deletions,
73
+/**
74
+ * The split shown inline, for surfaces that already sit behind a hover, such as the thread
75
+ * details card. It reads on mount, so it costs the host a request only once the card opens.
76
+ */
77
+export function PullRequestChangeBreakdownRows({
78
+ environmentId,
79
+ reference,
80
+ className,
81
}: {
87
- label: string;
88
- additions: number;
89
- deletions: number;
82
+ environmentId: EnvironmentId;
83
+ reference: PullRequestRef;
84
+ className: string;
85
}) {
86
+ const query = useEnvironmentQuery(
87
+ pullRequestEnvironment.changeBreakdown({ environmentId, input: reference }),
88
+ );
89
+ if (!query.data) return null;
90
+ return (
91
+ <div className={className}>
92
+ <ChangeBreakdownGrid breakdown={query.data} />
93
+ </div>
94
+ );
95
+}
96
+
97
+function ChangeBreakdownGrid({
98
+ breakdown,
99
+ total,
100
+}: {
101
+ breakdown: NonNullable<PullRequestChangeBreakdown>;
102
+ total?: DiffTotals;
103
+}) {
104
+ return (
105
+ <div className="grid grid-cols-[auto_auto_auto] justify-start gap-x-4 gap-y-1 py-0.5 font-mono tabular-nums">
106
+ {(Object.keys(KIND_LABELS) as Array<keyof typeof KIND_LABELS>).map((kind) => {
107
+ const { additions, deletions } = breakdown[kind];
108
+ return additions === 0 && deletions === 0 ? null : (
109
+ <BreakdownRow
110
+ key={kind}
111
+ label={KIND_LABELS[kind]}
112
+ additions={additions}
113
+ deletions={deletions}
114
+ />
115
+ );
116
+ })}
117
+ {total ? (
118
+ <>
119
+ <div className="col-span-3 border-t border-border" />
120
+ <BreakdownRow label="Total" additions={total.additions} deletions={total.deletions} />
121
+ </>
122
+ ) : null}
123
+ </div>
124
+ );
125
+}
126
+
127
+function BreakdownRow({ label, additions, deletions }: DiffTotals & { label: string }) {
128
return (
129
<>
130
<span className="font-sans">{label}</span>
apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx
+2
@@ -2436,6 +2436,7 @@ export function PullRequestDetailPanel({
2436
additions={detail.additions}
2437
deletions={detail.deletions}
2438
className="shrink-0 font-mono text-2xs"
2439
+ eager
2440
/>
2441
</span>
2442
</div>
@@ -2612,6 +2613,7 @@ export function PullRequestDetailPanel({
2613
additions={detail.additions}
2614
deletions={detail.deletions}
2615
className="shrink-0 font-mono text-xs"
2616
+ eager
2617
/>
2618
}
2619
/>
apps/web/src/components/pullRequest/PullRequestRow.tsx
+10
-6
@@ -1,6 +1,7 @@
1
import type { PullRequestAction } from "@t3tools/contracts";
2
import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
3
import { SearchIcon } from "lucide-react";
4
+import { PullRequestChangeBreakdownStat } from "./PullRequestChangeBreakdownStat";
5
import { PullRequestStackPopover } from "./PullRequestStackPopover";
6
import {
7
PullRequestSpeedActions,
@@ -22,11 +23,7 @@ import {
23
PullRequestRowGlyph,
24
PullRequestRowLines,
25
} from "./PullRequestListRow";
25
-import {
26
- PullRequestDiffStat,
27
- PullRequestLabelChip,
28
- PullRequestReviewDecisionGlyph,
29
-} from "./pullRequestPresentation";
26
+import { PullRequestLabelChip, PullRequestReviewDecisionGlyph } from "./pullRequestPresentation";
27
28
const LABEL_SLOTS = [
29
{ overflow: "@xl/pr-row-meta:hidden" },
@@ -186,7 +183,14 @@ function PullRequestRowImpl({
183
}
184
/>
185
) : null}
189
- <PullRequestDiffStat
186
+ <PullRequestChangeBreakdownStat
187
+ environmentId={entry.environmentId}
188
+ reference={{
189
+ projectId: entry.projectId,
190
+ host: entry.host,
191
+ repository: entry.repository,
192
+ number: entry.number,
193
+ }}
194
additions={entry.additions}
195
deletions={entry.deletions}
196
className="font-mono"
apps/web/src/components/pullRequest/ThreadPullRequestsPanel.tsx
+21
-5
@@ -29,6 +29,7 @@ import { findProjectForChangeRequest, useOpenPrLink } from "~/lib/openPullReques
29
import { cn } from "~/lib/utils";
30
import { useShortcutModifierState } from "~/shortcutModifierState";
31
import { useProjects, useServerConfigs, useThreadShell } from "~/state/entities";
32
+import { PullRequestChangeBreakdownStat } from "./PullRequestChangeBreakdownStat";
33
import { PullRequestsUnavailableState } from "./PullRequestsUnavailableState";
34
import { threadEnvironment } from "~/state/threads";
35
import { useAtomCommand } from "~/state/use-atom-command";
@@ -209,11 +210,26 @@ function LinkRowImpl({
210
) : null
211
}
212
status={
212
- <PullRequestDiffStat
213
- additions={snapshot?.additions ?? 0}
214
- deletions={snapshot?.deletions ?? 0}
215
- className="font-mono"
216
- />
213
+ projectId === null ? (
214
+ <PullRequestDiffStat
215
+ additions={snapshot?.additions ?? 0}
216
+ deletions={snapshot?.deletions ?? 0}
217
+ className="font-mono"
218
+ />
219
+ ) : (
220
+ <PullRequestChangeBreakdownStat
221
+ environmentId={threadRef.environmentId}
222
+ reference={{
223
+ projectId,
224
+ host: link.host,
225
+ repository: link.repository,
226
+ number: link.number,
227
+ }}
228
+ additions={snapshot?.additions ?? 0}
229
+ deletions={snapshot?.deletions ?? 0}
230
+ className="font-mono"
231
+ />
232
+ )
233
}
234
meta={
235
<>
packages/contracts/src/pullRequest.test.ts
+24
@@ -5,6 +5,7 @@ import { describe, expect, it } from "vite-plus/test";
5
import {
6
PullRequestActionInput,
7
PullRequestCapabilities,
8
+ PullRequestChangeBreakdown,
9
PullRequestDetail,
10
PullRequestFilesViewedResult,
11
PullRequestListInput,
@@ -18,6 +19,9 @@ import {
19
20
const decodeListResult = Schema.decodeUnknownSync(Schema.toCodecJson(PullRequestListResult));
21
const decodeDetail = Schema.decodeUnknownSync(Schema.toCodecJson(PullRequestDetail));
22
+const decodeChangeBreakdown = Schema.decodeUnknownSync(
23
+ Schema.toCodecJson(PullRequestChangeBreakdown),
24
+);
25
const decodeListInput = Schema.decodeUnknownSync(PullRequestListInput);
26
const decodeReviewerRequest = Schema.decodeUnknownSync(PullRequestReviewerRequestInput);
27
const decodeAction = Schema.decodeUnknownSync(Schema.toCodecJson(PullRequestActionInput));
@@ -423,3 +427,23 @@ describe("naming the file a tick belongs to", () => {
427
).toThrow();
428
});
429
});
430
+
431
+describe("PullRequestChangeBreakdown", () => {
432
+ it("reads a breakdown from a server that predates the docs kind", () => {
433
+ const line = { additions: 1, deletions: 0 };
434
+ expect(
435
+ decodeChangeBreakdown({
436
+ code: line,
437
+ tests: line,
438
+ mocks: line,
439
+ generated: line,
440
+ }),
441
+ ).toEqual({
442
+ code: line,
443
+ tests: line,
444
+ mocks: line,
445
+ generated: line,
446
+ docs: { additions: 0, deletions: 0 },
447
+ });
448
+ });
449
+});
packages/contracts/src/pullRequest.ts
+5
@@ -1,4 +1,5 @@
1
import * as Schema from "effect/Schema";
2
+import * as Effect from "effect/Effect";
3
import * as HttpServerRespondable from "effect/http/HttpServerRespondable";
4
import * as HttpServerResponse from "effect/http/HttpServerResponse";
5
@@ -698,6 +699,10 @@ export const PullRequestChangeBreakdown = Schema.NullOr(
699
tests: PullRequestLineCount,
700
mocks: PullRequestLineCount,
701
generated: PullRequestLineCount,
702
+ // Servers from before the docs split send no key; their docs lines sit in `code`.
703
+ docs: PullRequestLineCount.pipe(
704
+ Schema.withDecodingDefault(Effect.succeed({ additions: 0, deletions: 0 })),
705
+ ),
706
}),
707
);
708
export type PullRequestChangeBreakdown = typeof PullRequestChangeBreakdown.Type;
packages/shared/src/changedFileKind.test.ts
+6
@@ -36,6 +36,12 @@ describe("classifyChangedFile", () => {
36
["src/routeTree.gen.ts", "generated"],
37
["src/__generated__/types.ts", "generated"],
38
["dist/app.min.js", "generated"],
39
+ ["README.md", "docs"],
40
+ ["docs/internals/overview.mdx", "docs"],
41
+ ["NOTES.txt", "docs"],
42
+ ["requirements-dev.txt", "code"],
43
+ ["CMakeLists.txt", "code"],
44
+ ["tests/README.md", "tests"],
45
] as const)("%s is %s", (path, kind) => {
46
expect(classifyChangedFile(path)).toBe(kind);
47
});
packages/shared/src/changedFileKind.ts
+6
-1
@@ -58,10 +58,14 @@ const TEST_DIRS = new Set([
58
"tests",
59
]);
60
61
+const DOCS_NAME = /\.(md|mdx|markdown|rst|adoc|txt)$/i;
62
+// Plain-text files that tools read as config or input, not prose.
63
+const NOT_DOCS_NAME = /^(requirements.*|constraints.*|CMakeLists|robots|llms)\.txt$/i;
64
+
65
/**
66
* Sorts a changed file by its path alone, using common naming conventions. Lockfiles and build
67
* output count as generated, and test support (mocks, fixtures, snapshots) is kept apart from the
64
- * tests themselves, so a reviewer can see how much of a change is logic.
68
+ * tests themselves, and prose (Markdown, plain text) is its own kind, so a reviewer can see how much of a change is logic.
69
*/
70
export function classifyChangedFile(path: string): ChangedFileKind {
71
const segments = path.replaceAll("\\", "/").split("/");
@@ -72,5 +76,6 @@ export function classifyChangedFile(path: string): ChangedFileKind {
76
return "generated";
77
if (MOCK_NAME.test(name) || inDir(MOCK_DIRS)) return "mocks";
78
if (TEST_NAME.test(name) || CLASS_TEST_NAME.test(name) || inDir(TEST_DIRS)) return "tests";
79
+ if (DOCS_NAME.test(name) && !NOT_DOCS_NAME.test(name)) return "docs";
80
return "code";
81
}