@devries-cameron20 / t3code Mirror · read-only / commits / 0f36a11769
Fork 0

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 23, 15:30 UTC

refactor: format diff line counts through one shared helper (#17948)

maria committed Oct 10, 2026 at 22:13 UTC 0f36a1176921691440e4c5b790c33f439faab98c
13 files changed +84 -30
apps/mobile/src/features/review/ReviewSheet.tsx
+5 -2
@@ -1,4 +1,5 @@
1 import type { EnvironmentId, ThreadId } from "@t3tools/contracts";
2 +import { formatDiffCount } from "@t3tools/client-runtime/diff-count";
3 import { useNavigation, type StaticScreenProps } from "@react-navigation/native";
4 import { nativeHeaderScrollEdgeEffects } from "../../native/StackHeader";
5 import { ScreenHeader } from "../../components/ScreenHeader";
@@ -282,9 +283,11 @@ const ReviewFileNavigatorRow = memo(function ReviewFileNavigatorRow(props: {
283 </Text>
284 <View className="mt-1 flex-row gap-2">
285 <Text className="text-2xs font-t3-bold text-adaptive-emerald-700-300">
285 - +{file.additions}
286 + +{formatDiffCount(file.additions)}
287 + </Text>
288 + <Text className="text-2xs font-t3-bold text-adaptive-rose-700-300">
289 + -{formatDiffCount(file.deletions)}
290 </Text>
287 - <Text className="text-2xs font-t3-bold text-adaptive-rose-700-300">-{file.deletions}</Text>
291 </View>
292 </Pressable>
293 );
apps/mobile/src/features/review/useReviewDiffData.ts
+7 -3
@@ -1,4 +1,5 @@
1 import { useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
2 +import { formatDiffCount } from "@t3tools/client-runtime/diff-count";
3
4 import { countReviewCommentContexts, parseReviewInlineComments } from "./reviewCommentSelection";
5 import { getCachedNativeReviewDiffData } from "./nativeReviewDiffAdapter";
@@ -109,12 +110,15 @@ export function formatHeaderDiffSummary(
110 } {
111 if (files) {
112 return {
112 - additions: `+${files.reduce((total, file) => total + file.additions, 0)}`,
113 - deletions: `-${files.reduce((total, file) => total + file.deletions, 0)}`,
113 + additions: `+${formatDiffCount(files.reduce((total, file) => total + file.additions, 0))}`,
114 + deletions: `-${formatDiffCount(files.reduce((total, file) => total + file.deletions, 0))}`,
115 };
116 }
117 if (parsedDiff.kind !== "files") return { additions: null, deletions: null };
117 - return { additions: `+${parsedDiff.additions}`, deletions: `-${parsedDiff.deletions}` };
118 + return {
119 + additions: `+${formatDiffCount(parsedDiff.additions)}`,
120 + deletions: `-${formatDiffCount(parsedDiff.deletions)}`,
121 + };
122 }
123
124 export function useReviewDiffData(input: {
apps/mobile/src/features/threads/git/GitCommitSheet.tsx
+7 -5
@@ -1,6 +1,7 @@
1 import { useNavigation, type StaticScreenProps } from "@react-navigation/native";
2 import { useCallback, useState } from "react";
3 import { Platform, Pressable, ScrollView, useWindowDimensions, View } from "react-native";
4 +import { formatDiffCount } from "@t3tools/client-runtime/diff-count";
5 import { useSafeAreaInsets } from "react-native-safe-area-context";
6
7 import { AndroidSheetHeader } from "../../../components/AndroidScreenHeader";
@@ -134,7 +135,8 @@ export function GitCommitSheet(_props: GitCommitSheetProps) {
135 Files
136 </Text>
137 <Text className="text-foreground-muted text-xs leading-normal">
137 - {selectedFiles.length} selected · +{selectedInsertions} / -{selectedDeletions}
138 + {selectedFiles.length} selected · +{formatDiffCount(selectedInsertions)} / -
139 + {formatDiffCount(selectedDeletions)}
140 </Text>
141 </View>
142 <View className="flex-row items-center gap-2">
@@ -171,10 +173,10 @@ export function GitCommitSheet(_props: GitCommitSheetProps) {
173 {file.path}
174 </Text>
175 <Text className="text-xs font-t3-bold text-adaptive-emerald-700-300">
174 - +{file.insertions}
176 + +{formatDiffCount(file.insertions)}
177 </Text>
178 <Text className="text-xs font-t3-bold text-adaptive-rose-700-300">
177 - -{file.deletions}
179 + -{formatDiffCount(file.deletions)}
180 </Text>
181 </View>
182 ))}
@@ -250,10 +252,10 @@ export function GitCommitSheet(_props: GitCommitSheetProps) {
252 </View>
253 <View className="items-end gap-1">
254 <Text className="text-xs font-t3-bold text-adaptive-emerald-700-300">
253 - +{file.insertions}
255 + +{formatDiffCount(file.insertions)}
256 </Text>
257 <Text className="text-xs font-t3-bold text-adaptive-rose-700-300">
256 - -{file.deletions}
258 + -{formatDiffCount(file.deletions)}
259 </Text>
260 </View>
261 </View>
apps/mobile/src/lib/threadActivityInspector.ts
+6 -2
@@ -1,5 +1,6 @@
1 import type { V2ItemSupport } from "@t3tools/client-runtime/state/item-support";
2 import { toolItemForDisplay } from "@t3tools/client-runtime/work-log/presentation";
3 +import { formatDiffCount } from "@t3tools/client-runtime/diff-count";
4 import type { ThreadId } from "@t3tools/contracts";
5 import { formatDuration } from "@t3tools/shared/orchestrationTiming";
6 import * as DateTime from "effect/DateTime";
@@ -160,7 +161,7 @@ export function buildThreadActivityInspector(
161 if (item.additions !== undefined || item.deletions !== undefined) {
162 fields.push({
163 label: "Changes",
163 - value: `+${item.additions ?? 0} −${item.deletions ?? 0}`,
164 + value: `+${formatDiffCount(item.additions ?? 0)} −${formatDiffCount(item.deletions ?? 0)}`,
165 });
166 }
167 break;
@@ -206,7 +207,10 @@ export function buildThreadActivityInspector(
207 blocks,
208 "Files",
209 item.files
209 - .map((file) => `${file.path} +${file.additions} −${file.deletions} ${file.kind}`)
210 + .map(
211 + (file) =>
212 + `${file.path} +${formatDiffCount(file.additions)} −${formatDiffCount(file.deletions)} ${file.kind}`,
213 + )
214 .join("\n"),
215 );
216 break;
apps/web/src/components/GitActionsControl.test.ts
+3 -1
@@ -80,7 +80,9 @@ vi.mock("~/state/query", () => ({
80 isDefaultRef: false,
81 hasPrimaryRemote: true,
82 hasWorkingTreeChanges: true,
83 - workingTree: { files: [{ path: "file.ts", status: "modified" }] },
83 + workingTree: {
84 + files: [{ path: "file.ts", status: "modified", insertions: 1, deletions: 0 }],
85 + },
86 },
87 error: null,
88 }),
apps/web/src/components/GitActionsControl.tsx
+9 -6
@@ -125,6 +125,7 @@ import {
125 } from "./chat/threadDetailsPanelStyles";
126 import { getSourceControlPresentation, sourceControlIcon } from "~/sourceControlPresentation";
127 import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
128 +import { formatDiffCount } from "@t3tools/client-runtime/diff-count";
129 import { useOpenLink } from "~/browser/useOpenLink";
130
131 interface GitActionsControlProps {
@@ -1910,8 +1911,10 @@ export default function GitActionsControl({
1911 <FileDiffIcon className={THREAD_DETAILS_PANEL_ICON_CLASS} aria-hidden />
1912 <span className={cn("flex-1 text-left", THREAD_DETAILS_PANEL_LABEL_CLASS)}>Changes</span>
1913 <span className="flex items-center gap-1 font-mono text-2xs tabular-nums">
1913 - <span className="text-success">+{changesTotals?.insertions ?? 0}</span>
1914 - <span className="text-destructive">-{changesTotals?.deletions ?? 0}</span>
1914 + <span className="text-success">+{formatDiffCount(changesTotals?.insertions ?? 0)}</span>
1915 + <span className="text-destructive">
1916 + -{formatDiffCount(changesTotals?.deletions ?? 0)}
1917 + </span>
1918 </span>
1919 </ThreadDetailsControl>
1920 ) : null}
@@ -2021,11 +2024,11 @@ export default function GitActionsControl({
2024 ) : (
2025 <>
2026 <span className="text-diff-addition">
2024 - +{file.insertions}
2027 + +{formatDiffCount(file.insertions)}
2028 </span>
2029 <span className="text-muted-foreground"> / </span>
2030 <span className="text-diff-deletion">
2028 - -{file.deletions}
2031 + -{formatDiffCount(file.deletions)}
2032 </span>
2033 </>
2034 )}
@@ -2039,11 +2042,11 @@ export default function GitActionsControl({
2042 </div>
2043 <div className="flex justify-end font-mono">
2044 <span className="text-diff-addition">
2042 - +{selectedFiles.reduce((sum, f) => sum + f.insertions, 0)}
2045 + +{formatDiffCount(selectedFiles.reduce((sum, f) => sum + f.insertions, 0))}
2046 </span>
2047 <span className="text-muted-foreground"> / </span>
2048 <span className="text-diff-deletion">
2046 - -{selectedFiles.reduce((sum, f) => sum + f.deletions, 0)}
2049 + -{formatDiffCount(selectedFiles.reduce((sum, f) => sum + f.deletions, 0))}
2050 </span>
2051 </div>
2052 </div>
apps/web/src/components/Sidebar.tsx
+7 -2
@@ -33,6 +33,7 @@ import {
33 threadWokeAt,
34 } from "@t3tools/client-runtime/state/thread-settled";
35 import { createInboxReturnTracker } from "@t3tools/client-runtime/state/thread-inbox";
36 +import { formatDiffCount } from "@t3tools/client-runtime/diff-count";
37 import {
38 resolveSettledThreadTimestamp,
39 sortSettledThreads,
@@ -2186,8 +2187,12 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
2187 {prBadge}
2188 {diff ? (
2189 <span className="shrink-0 font-mono">
2189 - <span className="text-diff-addition-foreground">+{diff.insertions}</span>{" "}
2190 - <span className="text-diff-deletion-foreground">−{diff.deletions}</span>
2190 + <span className="text-diff-addition-foreground">
2191 + +{formatDiffCount(diff.insertions)}
2192 + </span>{" "}
2193 + <span className="text-diff-deletion-foreground">
2194 + −{formatDiffCount(diff.deletions)}
2195 + </span>
2196 </span>
2197 ) : null}
2198 <span
apps/web/src/components/chat/V2ItemInspector.tsx
+3 -2
@@ -11,6 +11,7 @@ import {
11 turnItemOutputImages,
12 turnItemOutputText,
13 } from "@t3tools/client-runtime/work-log/item-detail";
14 +import { formatDiffCount } from "@t3tools/client-runtime/diff-count";
15 import { ExternalLinkIcon, GitBranchIcon, RotateCcwIcon } from "lucide-react";
16 import { memo, Suspense, use, useMemo } from "react";
17
@@ -261,8 +262,8 @@ export const V2ItemInspector = memo(function V2ItemInspector(props: V2ItemInspec
262 </span>
263 {item.additions !== undefined || item.deletions !== undefined ? (
264 <span>
264 - <span className="text-success">+{item.additions ?? 0}</span>{" "}
265 - <span className="text-destructive">-{item.deletions ?? 0}</span>
265 + <span className="text-success">+{formatDiffCount(item.additions ?? 0)}</span>{" "}
266 + <span className="text-destructive">-{formatDiffCount(item.deletions ?? 0)}</span>
267 </span>
268 ) : null}
269 {item.runId !== null ? (
apps/web/src/components/pullRequest/pullRequestPresentation.tsx
+3 -2
@@ -9,6 +9,7 @@ import type {
9 PullRequestReviewDecision,
10 PullRequestState,
11 } from "@t3tools/contracts";
12 +import { formatDiffCount } from "@t3tools/client-runtime/diff-count";
13 import {
14 CircleCheckIcon,
15 CircleDashedIcon,
@@ -524,8 +525,8 @@ export function PullRequestDiffStat({
525 }
526 return (
527 <span className={cn("inline-flex items-baseline gap-1 tabular-nums", className)}>
527 - <span className="text-diff-addition-foreground">+{additions.toLocaleString()}</span>
528 - <span className="text-diff-deletion">-{deletions.toLocaleString()}</span>
528 + <span className="text-diff-addition-foreground">+{formatDiffCount(additions)}</span>
529 + <span className="text-diff-deletion">-{formatDiffCount(deletions)}</span>
530 </span>
531 );
532 }
packages/client-runtime/package.json
+4
@@ -383,6 +383,10 @@
383 "types": "./src/device/duoControl.ts",
384 "default": "./src/device/duoControl.ts"
385 },
386 + "./diff-count": {
387 + "types": "./src/diffCount.ts",
388 + "default": "./src/diffCount.ts"
389 + },
390 "./mcp-apps": {
391 "types": "./src/mcpApps/host.ts",
392 "default": "./src/mcpApps/host.ts"
packages/client-runtime/src/diffCount.ts new
+6
@@ -0,0 +1,6 @@
1 +const DIFF_COUNT_FORMAT = new Intl.NumberFormat();
2 +
3 +/** Formats a diff line count with the viewer's digit grouping, so `83065` reads `83,065`. */
4 +export function formatDiffCount(count: number): string {
5 + return DIFF_COUNT_FORMAT.format(count);
6 +}
patches/@pierre%2Fdiffs@1.5.2.patch
+19
@@ -970,6 +970,25 @@ index 84c7915..d1930bf 100644
970 if (hasCustomHeader) managedOptions.renderCustomHeader = noopRender;
971 if (hasGutterRenderer) managedOptions.renderGutterUtility = noopRender;
972 if (hasCodeViewHeader) managedOptions.renderCodeViewHeader = noopRender;
973 +diff --git a/dist/utils/createFileHeaderElement.js b/dist/utils/createFileHeaderElement.js
974 +index 39fe30e..600442e 100644
975 +--- a/dist/utils/createFileHeaderElement.js
976 ++++ b/dist/utils/createFileHeaderElement.js
977 +@@ -73,12 +73,12 @@ function createMetadataElement(fileDiff) {
978 + }
979 + if (deletions > 0 || additions === 0) children.push(createHastElement({
980 + tagName: "span",
981 +- children: [createTextNodeElement(`-${deletions}`)],
982 ++ children: [createTextNodeElement(`-${deletions.toLocaleString()}`)],
983 + properties: { "data-deletions-count": "" }
984 + }));
985 + if (additions > 0 || deletions === 0) children.push(createHastElement({
986 + tagName: "span",
987 +- children: [createTextNodeElement(`+${additions}`)],
988 ++ children: [createTextNodeElement(`+${additions.toLocaleString()}`)],
989 + properties: { "data-additions-count": "" }
990 + }));
991 + }
992 diff --git a/package.json b/package.json
993 index d9dc7b5..3c37bae 100644
994 --- a/package.json
pnpm-lock.yaml
+5 -5
@@ -151,7 +151,7 @@ patchedDependencies:
151 '@opencode/client@2.0.23': f725d6e6d9af0d56dc6ed71b863518fbfc751af1773cff2311209d2c404cf4cd
152 '@opencode/protocol@2.0.23': 17a82f6c2c98fd0371e786c211a4fbdaaba403577a25733e5e99a0c25a16a685
153 '@opencode/schema@2.0.23': 650f1b8602789407c010861284272dcb6bd6de01ec6a75bf3c0904a0e7596d59
154 - '@pierre/diffs@1.5.2': b33a575eb1382270ed0df956307e4b6ffe4b8e4349cefeb43e14f648c0fdc3b0
154 + '@pierre/diffs@1.5.2': 298e94372dbd51846a4e26ece2ecc3e22eb1f94b0450b1f1a9c6fec127809be7
155 '@react-native-ai/apple@0.12.0': 2d09870c2848d185cb05b53ed823a46e12dba519324d8dd8e584e28731990f9d
156 '@react-native-menu/menu@2.0.0': a4866ecfcd44f318043de839d20110c17e14909004900f002ffe12050376f2ba
157 '@react-navigation/native-stack@7.17.6': d2d52f3776e30765519748fd5e177592dc3b9cc778c52fb00e02674dfa9042c5
@@ -331,7 +331,7 @@ importers:
331 version: 1.9.1
332 '@pierre/diffs':
333 specifier: 'catalog:'
334 - version: 1.5.2(patch_hash=b33a575eb1382270ed0df956307e4b6ffe4b8e4349cefeb43e14f648c0fdc3b0)(@shikijs/themes@4.2.0)(react-dom@19.3.0(react@19.3.0))(react@19.3.0)
334 + version: 1.5.2(patch_hash=298e94372dbd51846a4e26ece2ecc3e22eb1f94b0450b1f1a9c6fec127809be7)(@shikijs/themes@4.2.0)(react-dom@19.3.0(react@19.3.0))(react@19.3.0)
335 '@react-native-ai/apple':
336 specifier: 0.12.0
337 version: 0.12.0(patch_hash=2d09870c2848d185cb05b53ed823a46e12dba519324d8dd8e584e28731990f9d)(react-native@0.88.0-rc.3(@babel/core@7.29.7)(@react-native/metro-config@0.88.0-rc.3(@babel/core@7.29.7)(bufferutil@4.1.0)(utf-8-validate@6.0.6))(@types/react@19.3.0)(bufferutil@4.1.0)(react@19.3.0)(utf-8-validate@6.0.6))
@@ -783,7 +783,7 @@ importers:
783 version: 1.8.0
784 '@pierre/diffs':
785 specifier: 'catalog:'
786 - version: 1.5.2(patch_hash=b33a575eb1382270ed0df956307e4b6ffe4b8e4349cefeb43e14f648c0fdc3b0)(@shikijs/themes@4.3.0)(react-dom@19.2.6(react@19.2.6))(react@19.2.6)
786 + version: 1.5.2(patch_hash=298e94372dbd51846a4e26ece2ecc3e22eb1f94b0450b1f1a9c6fec127809be7)(@shikijs/themes@4.3.0)(react-dom@19.2.6(react@19.2.6))(react@19.2.6)
787 '@pierre/trees':
788 specifier: 1.0.0-beta.6
789 version: 1.0.0-beta.6(@pierre/theme@1.1.0)(@shikijs/themes@4.3.0)(react-dom@19.2.6(react@19.2.6))(react@19.2.6)(shiki@4.2.0)
@@ -15726,7 +15726,7 @@ snapshots:
15726 tslib: 2.8.1
15727 webcrypto-core: 1.9.2
15728
15729 - '@pierre/diffs@1.5.2(patch_hash=b33a575eb1382270ed0df956307e4b6ffe4b8e4349cefeb43e14f648c0fdc3b0)(@shikijs/themes@4.2.0)(react-dom@19.3.0(react@19.3.0))(react@19.3.0)':
15729 + '@pierre/diffs@1.5.2(patch_hash=298e94372dbd51846a4e26ece2ecc3e22eb1f94b0450b1f1a9c6fec127809be7)(@shikijs/themes@4.2.0)(react-dom@19.3.0(react@19.3.0))(react@19.3.0)':
15730 dependencies:
15731 '@pierre/theme': 2.0.0
15732 '@pierre/theming': 1.0.1(@pierre/theme@2.0.0)(@shikijs/themes@4.2.0)(react-dom@19.3.0(react@19.3.0))(react@19.3.0)(shiki@4.2.0)
@@ -15741,7 +15741,7 @@ snapshots:
15741 transitivePeerDependencies:
15742 - '@shikijs/themes'
15743
15744 - '@pierre/diffs@1.5.2(patch_hash=b33a575eb1382270ed0df956307e4b6ffe4b8e4349cefeb43e14f648c0fdc3b0)(@shikijs/themes@4.3.0)(react-dom@19.2.6(react@19.2.6))(react@19.2.6)':
15744 + '@pierre/diffs@1.5.2(patch_hash=298e94372dbd51846a4e26ece2ecc3e22eb1f94b0450b1f1a9c6fec127809be7)(@shikijs/themes@4.3.0)(react-dom@19.2.6(react@19.2.6))(react@19.2.6)':
15745 dependencies:
15746 '@pierre/theme': 2.0.0
15747 '@pierre/theming': 1.0.1(@pierre/theme@2.0.0)(@shikijs/themes@4.3.0)(react-dom@19.2.6(react@19.2.6))(react@19.2.6)(shiki@4.2.0)