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 24, 20:15 UTC
Default diffs to working changes (#3974)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Jake Leventhal committed
Jul 18, 2026 at 07:17 UTC
38e0bb07bb24894524f1502ac0487c5ea4ff85de
4 files changed
+47
-9
apps/web/src/components/ChatView.tsx
+12
-3
@@ -2252,12 +2252,13 @@ function ChatViewContent(props: ChatViewProps) {
2252
worktreePath: activeThread?.worktreePath ?? null,
2253
})
2254
: null;
2255
+ const gitStatusCwd = activeThread?.worktreePath ?? gitCwd;
2256
const gitStatusQuery = useEnvironmentQuery(
2256
- gitCwd === null
2257
+ gitStatusCwd === null
2258
? null
2259
: vcsEnvironment.status({
2260
environmentId,
2260
- input: { cwd: gitCwd },
2261
+ input: { cwd: gitStatusCwd },
2262
}),
2263
);
2264
const keybindings = useAtomValue(primaryServerKeybindingsAtom);
@@ -2291,6 +2292,9 @@ function ChatViewContent(props: ChatViewProps) {
2292
terminalUiLaunchContext?.threadId === activeThreadId ? terminalUiLaunchContext : null;
2293
// Default true while loading to avoid toolbar flicker.
2294
const isGitRepo = gitStatusQuery.data?.isRepo ?? true;
2295
+ const initialDiffPanelGitScope =
2296
+ gitStatusQuery.data?.hasWorkingTreeChanges === true ? "unstaged" : "branch";
2297
+ const diffPanelGitStatusResolutionKey = gitStatusQuery.data ? "resolved" : "pending";
2298
const terminalShortcutLabelOptions = useMemo(
2299
() => ({
2300
context: {
@@ -5136,7 +5140,12 @@ function ChatViewContent(props: ChatViewProps) {
5140
/>
5141
) : activeRightPanelSurface?.kind === "diff" ? (
5142
<Suspense fallback={null}>
5139
- <DiffPanel mode="embedded" composerDraftTarget={composerDraftTarget} />
5143
+ <DiffPanel
5144
+ key={`${activeThreadKey}:${diffPanelGitStatusResolutionKey}`}
5145
+ mode="embedded"
5146
+ composerDraftTarget={composerDraftTarget}
5147
+ initialGitScope={initialDiffPanelGitScope}
5148
+ />
5149
</Suspense>
5150
) : activeRightPanelSurface?.kind === "plan" ? (
5151
<PlanSidebar
apps/web/src/components/DiffPanel.tsx
+14
-4
@@ -178,13 +178,19 @@ const DIFF_PANEL_UNSAFE_CSS = `
178
interface DiffPanelProps {
179
mode?: DiffPanelMode;
180
composerDraftTarget: ScopedThreadRef | DraftId;
181
+ initialGitScope: "branch" | "unstaged";
182
}
183
184
export { DiffWorkerPoolProvider } from "./DiffWorkerPoolProvider";
185
185
-export default function DiffPanel({ mode = "inline", composerDraftTarget }: DiffPanelProps) {
186
+export default function DiffPanel({
187
+ mode = "inline",
188
+ composerDraftTarget,
189
+ initialGitScope: initialGitScopeProp,
190
+}: DiffPanelProps) {
191
const { resolvedTheme } = useTheme();
192
const settings = useClientSettings();
193
+ const [initialGitScope] = useState(initialGitScopeProp);
194
const [diffRenderMode, setDiffRenderMode] = useState<DiffRenderMode>("stacked");
195
const [wordWrap, setWordWrap] = useState(settings.wordWrap);
196
const [diffIgnoreWhitespace, setDiffIgnoreWhitespace] = useState(settings.diffIgnoreWhitespace);
@@ -199,9 +205,6 @@ export default function DiffPanel({ mode = "inline", composerDraftTarget }: Diff
205
strict: false,
206
select: (params) => resolveThreadRouteRef(params),
207
});
202
- const diffSelection = useDiffPanelStore((state) =>
203
- selectThreadDiffPanelSelection(state.byThreadKey, routeThreadRef),
204
- );
208
const activeThreadId = routeThreadRef?.threadId ?? null;
209
const activeThread = useThread(routeThreadRef);
210
const activeProjectId = activeThread?.projectId ?? null;
@@ -229,6 +232,13 @@ export default function DiffPanel({ mode = "inline", composerDraftTarget }: Diff
232
})
233
: null,
234
);
235
+ const diffSelection = useDiffPanelStore((state) =>
236
+ selectThreadDiffPanelSelection(
237
+ state.byThreadKey,
238
+ routeThreadRef,
239
+ initialGitScope === "unstaged",
240
+ ),
241
+ );
242
const isGitRepo = gitStatusQuery.data?.isRepo ?? true;
243
const { turnDiffSummaries, inferredCheckpointTurnCountByTurnId } =
244
useTurnDiffSummaries(activeThread);
apps/web/src/diffPanelStore.test.ts
+15
-1
@@ -9,12 +9,26 @@ const THREAD_REF = scopeThreadRef(EnvironmentId.make("environment-1"), ThreadId.
9
describe("diffPanelStore", () => {
10
beforeEach(() => useDiffPanelStore.setState({ byThreadKey: {}, branchBaseRefByThreadKey: {} }));
11
12
- it("defaults each thread to branch changes with automatic base selection", () => {
12
+ it("defaults each thread to branch changes when the working tree is clean", () => {
13
expect(
14
selectThreadDiffPanelSelection(useDiffPanelStore.getState().byThreadKey, THREAD_REF),
15
).toEqual({ kind: "branch", baseRef: null });
16
});
17
18
+ it("defaults each thread to working changes when the working tree is dirty", () => {
19
+ expect(
20
+ selectThreadDiffPanelSelection(useDiffPanelStore.getState().byThreadKey, THREAD_REF, true),
21
+ ).toEqual({ kind: "unstaged" });
22
+ });
23
+
24
+ it("preserves an explicit scope selection when the working tree state changes", () => {
25
+ useDiffPanelStore.getState().selectGitScope(THREAD_REF, "branch");
26
+
27
+ expect(
28
+ selectThreadDiffPanelSelection(useDiffPanelStore.getState().byThreadKey, THREAD_REF, true),
29
+ ).toEqual({ kind: "branch", baseRef: null });
30
+ });
31
+
32
it("clears incompatible selection fields when changing scopes", () => {
33
const store = useDiffPanelStore.getState();
34
store.selectTurn(THREAD_REF, TurnId.make("turn-1"), "src/app.ts");
apps/web/src/diffPanelStore.ts
+6
-1
@@ -11,6 +11,7 @@ export type DiffPanelSelection =
11
| { kind: "turn"; turnId: TurnId; filePath: string | null; revealRequestId: number };
12
13
const DEFAULT_SELECTION: DiffPanelSelection = { kind: "branch", baseRef: null };
14
+const DEFAULT_WORKING_TREE_SELECTION: DiffPanelSelection = { kind: "unstaged" };
15
16
interface DiffPanelStoreState {
17
byThreadKey: Record<string, DiffPanelSelection>;
@@ -133,7 +134,11 @@ export const useDiffPanelStore = create<DiffPanelStoreState>()(
134
export function selectThreadDiffPanelSelection(
135
byThreadKey: Record<string, DiffPanelSelection>,
136
ref: ScopedThreadRef | null | undefined,
137
+ hasWorkingTreeChanges = false,
138
): DiffPanelSelection {
139
if (!ref) return DEFAULT_SELECTION;
138
- return byThreadKey[scopedThreadKey(ref)] ?? DEFAULT_SELECTION;
140
+ return (
141
+ byThreadKey[scopedThreadKey(ref)] ??
142
+ (hasWorkingTreeChanges ? DEFAULT_WORKING_TREE_SELECTION : DEFAULT_SELECTION)
143
+ );
144
}