Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.
Default diffs to working changes (#3974)
Jake Leventhal38e0bb07bb24
diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsxindex 77951e707..69292e7e6 100644--- a/apps/web/src/components/ChatView.tsx+++ b/apps/web/src/components/ChatView.tsx@@ -2252,12 +2252,13 @@ function ChatViewContent(props: ChatViewProps) {worktreePath: activeThread?.worktreePath ?? null,}): null;+ const gitStatusCwd = activeThread?.worktreePath ?? gitCwd;const gitStatusQuery = useEnvironmentQuery(- gitCwd === null+ gitStatusCwd === null? null: vcsEnvironment.status({environmentId,- input: { cwd: gitCwd },+ input: { cwd: gitStatusCwd },}),);const keybindings = useAtomValue(primaryServerKeybindingsAtom);@@ -2291,6 +2292,9 @@ function ChatViewContent(props: ChatViewProps) {terminalUiLaunchContext?.threadId === activeThreadId ? terminalUiLaunchContext : null;// Default true while loading to avoid toolbar flicker.const isGitRepo = gitStatusQuery.data?.isRepo ?? true;+ const initialDiffPanelGitScope =+ gitStatusQuery.data?.hasWorkingTreeChanges === true ? "unstaged" : "branch";+ const diffPanelGitStatusResolutionKey = gitStatusQuery.data ? "resolved" : "pending";const terminalShortcutLabelOptions = useMemo(() => ({context: {@@ -5136,7 +5140,12 @@ function ChatViewContent(props: ChatViewProps) {/>) : activeRightPanelSurface?.kind === "diff" ? (<Suspense fallback={null}>- <DiffPanel mode="embedded" composerDraftTarget={composerDraftTarget} />+ <DiffPanel+ key={`${activeThreadKey}:${diffPanelGitStatusResolutionKey}`}+ mode="embedded"+ composerDraftTarget={composerDraftTarget}+ initialGitScope={initialDiffPanelGitScope}+ /></Suspense>) : activeRightPanelSurface?.kind === "plan" ? (<PlanSidebardiff --git a/apps/web/src/components/DiffPanel.tsx b/apps/web/src/components/DiffPanel.tsxindex cbcd36ce0..5cb2a1cfd 100644--- a/apps/web/src/components/DiffPanel.tsx+++ b/apps/web/src/components/DiffPanel.tsx@@ -178,13 +178,19 @@ const DIFF_PANEL_UNSAFE_CSS = `interface DiffPanelProps {mode?: DiffPanelMode;composerDraftTarget: ScopedThreadRef | DraftId;+ initialGitScope: "branch" | "unstaged";}export { DiffWorkerPoolProvider } from "./DiffWorkerPoolProvider";-export default function DiffPanel({ mode = "inline", composerDraftTarget }: DiffPanelProps) {+export default function DiffPanel({+ mode = "inline",+ composerDraftTarget,+ initialGitScope: initialGitScopeProp,+}: DiffPanelProps) {const { resolvedTheme } = useTheme();const settings = useClientSettings();+ const [initialGitScope] = useState(initialGitScopeProp);const [diffRenderMode, setDiffRenderMode] = useState<DiffRenderMode>("stacked");const [wordWrap, setWordWrap] = useState(settings.wordWrap);const [diffIgnoreWhitespace, setDiffIgnoreWhitespace] = useState(settings.diffIgnoreWhitespace);@@ -199,9 +205,6 @@ export default function DiffPanel({ mode = "inline", composerDraftTarget }: Diffstrict: false,select: (params) => resolveThreadRouteRef(params),});- const diffSelection = useDiffPanelStore((state) =>- selectThreadDiffPanelSelection(state.byThreadKey, routeThreadRef),- );const activeThreadId = routeThreadRef?.threadId ?? null;const activeThread = useThread(routeThreadRef);const activeProjectId = activeThread?.projectId ?? null;@@ -229,6 +232,13 @@ export default function DiffPanel({ mode = "inline", composerDraftTarget }: Diff}): null,);+ const diffSelection = useDiffPanelStore((state) =>+ selectThreadDiffPanelSelection(+ state.byThreadKey,+ routeThreadRef,+ initialGitScope === "unstaged",+ ),+ );const isGitRepo = gitStatusQuery.data?.isRepo ?? true;const { turnDiffSummaries, inferredCheckpointTurnCountByTurnId } =useTurnDiffSummaries(activeThread);diff --git a/apps/web/src/diffPanelStore.test.ts b/apps/web/src/diffPanelStore.test.tsindex 64846e8e9..607b7c8d5 100644--- a/apps/web/src/diffPanelStore.test.ts+++ b/apps/web/src/diffPanelStore.test.ts@@ -9,12 +9,26 @@ const THREAD_REF = scopeThreadRef(EnvironmentId.make("environment-1"), ThreadId.describe("diffPanelStore", () => {beforeEach(() => useDiffPanelStore.setState({ byThreadKey: {}, branchBaseRefByThreadKey: {} }));- it("defaults each thread to branch changes with automatic base selection", () => {+ it("defaults each thread to branch changes when the working tree is clean", () => {expect(selectThreadDiffPanelSelection(useDiffPanelStore.getState().byThreadKey, THREAD_REF),).toEqual({ kind: "branch", baseRef: null });});+ it("defaults each thread to working changes when the working tree is dirty", () => {+ expect(+ selectThreadDiffPanelSelection(useDiffPanelStore.getState().byThreadKey, THREAD_REF, true),+ ).toEqual({ kind: "unstaged" });+ });++ it("preserves an explicit scope selection when the working tree state changes", () => {+ useDiffPanelStore.getState().selectGitScope(THREAD_REF, "branch");++ expect(+ selectThreadDiffPanelSelection(useDiffPanelStore.getState().byThreadKey, THREAD_REF, true),+ ).toEqual({ kind: "branch", baseRef: null });+ });+it("clears incompatible selection fields when changing scopes", () => {const store = useDiffPanelStore.getState();store.selectTurn(THREAD_REF, TurnId.make("turn-1"), "src/app.ts");diff --git a/apps/web/src/diffPanelStore.ts b/apps/web/src/diffPanelStore.tsindex c946b286d..56b5ad23f 100644--- a/apps/web/src/diffPanelStore.ts+++ b/apps/web/src/diffPanelStore.ts@@ -11,6 +11,7 @@ export type DiffPanelSelection =| { kind: "turn"; turnId: TurnId; filePath: string | null; revealRequestId: number };const DEFAULT_SELECTION: DiffPanelSelection = { kind: "branch", baseRef: null };+const DEFAULT_WORKING_TREE_SELECTION: DiffPanelSelection = { kind: "unstaged" };interface DiffPanelStoreState {byThreadKey: Record<string, DiffPanelSelection>;@@ -133,7 +134,11 @@ export const useDiffPanelStore = create<DiffPanelStoreState>()(export function selectThreadDiffPanelSelection(byThreadKey: Record<string, DiffPanelSelection>,ref: ScopedThreadRef | null | undefined,+ hasWorkingTreeChanges = false,): DiffPanelSelection {if (!ref) return DEFAULT_SELECTION;- return byThreadKey[scopedThreadKey(ref)] ?? DEFAULT_SELECTION;+ return (+ byThreadKey[scopedThreadKey(ref)] ??+ (hasWorkingTreeChanges ? DEFAULT_WORKING_TREE_SELECTION : DEFAULT_SELECTION)+ );}