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.
Derive active thread from route and drop persisted selection
Julius Marminge1a315235b77d
diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsxindex 7169e1796..81b4e1fc0 100644--- a/apps/web/src/components/ChatView.tsx+++ b/apps/web/src/components/ChatView.tsx@@ -307,7 +307,9 @@ const ComposerCommandMenu = memo(function ComposerCommandMenu(props: {<Commandmode="none"onItemHighlighted={(highlightedValue) => {- props.onHighlightedItemChange(typeof highlightedValue === "string" ? highlightedValue : null);+ props.onHighlightedItemChange(+ typeof highlightedValue === "string" ? highlightedValue : null,+ );}}><div className="relative overflow-hidden rounded-xl border border-border/80 bg-popover/96 shadow-lg/8 backdrop-blur-xs">@@ -689,7 +691,7 @@ export default function ChatView({ threadId }: ChatViewProps) {);const keybindings = keybindingsQuery.data ?? EMPTY_KEYBINDINGS;const threadTerminalRuntimeEnv = useMemo(() => {- if (!activeProject) return {};+ if (!activeProject?.cwd) return {};return projectScriptRuntimeEnv({project: {cwd: activeProject.cwd,@@ -825,9 +827,7 @@ export default function ChatView({ threadId }: ChatViewProps) {}const targetCwd = options?.cwd ?? gitCwd ?? activeProject.cwd;const baseTerminalId =- activeThread.activeTerminalId ||- activeThread.terminalIds[0] ||- DEFAULT_THREAD_TERMINAL_ID;+ activeThread.activeTerminalId || activeThread.terminalIds[0] || DEFAULT_THREAD_TERMINAL_ID;const isBaseTerminalBusy = activeThread.runningTerminalIds.includes(baseTerminalId);const wantsNewTerminal = Boolean(options?.preferNewTerminal) || isBaseTerminalBusy;const shouldCreateNewTerminal =diff --git a/apps/web/src/components/GitActionsControl.logic.ts b/apps/web/src/components/GitActionsControl.logic.tsindex 50de7b6c5..a740d6472 100644--- a/apps/web/src/components/GitActionsControl.logic.ts+++ b/apps/web/src/components/GitActionsControl.logic.ts@@ -67,13 +67,13 @@ export function buildGitActionProgressStages(input: {return [...commitStages, pushStage, "Creating PR..."];}+const withDescription = (title: string, description: string | undefined) =>+ description ? { title, description } : { title };+export function summarizeGitResult(result: GitRunStackedActionResult): {title: string;description?: string;} {- const withDescription = (title: string, description: string | undefined) =>- description ? { title, description } : { title };-if (result.pr.status === "created" || result.pr.status === "opened_existing") {const prNumber = result.pr.number ? ` #${result.pr.number}` : "";const title = `${result.pr.status === "created" ? "Created PR" : "Opened PR"}${prNumber}`;diff --git a/apps/web/src/components/ui/toast.tsx b/apps/web/src/components/ui/toast.tsxindex 7b4879e9f..a8df9d0ac 100644--- a/apps/web/src/components/ui/toast.tsx+++ b/apps/web/src/components/ui/toast.tsx@@ -2,6 +2,7 @@import { Toast } from "@base-ui/react/toast";import { useEffect } from "react";+import { useRouterState } from "@tanstack/react-router";import {CircleAlertIcon,CircleCheckIcon,@@ -12,7 +13,6 @@ import {import { cn } from "~/lib/utils";import { buttonVariants } from "~/components/ui/button";-import { useStore } from "~/store";import { shouldHideCollapsedToastContent } from "./toast.logic";type ThreadToastData = {@@ -55,6 +55,21 @@ function shouldRenderForActiveThread(return toastThreadId === activeThreadId;}+function useActiveThreadIdFromRoute(): string | null {+ return useRouterState({+ select: (routerState) => {+ for (let index = routerState.matches.length - 1; index >= 0; index -= 1) {+ const params = routerState.matches[index]?.params as Record<string, unknown> | undefined;+ const threadId = params?.threadId;+ if (typeof threadId === "string" && threadId.length > 0) {+ return threadId;+ }+ }+ return null;+ },+ });+}+function ThreadToastVisibleAutoDismiss({toastId,dismissAfterVisibleMs,@@ -143,9 +158,8 @@ function ToastProvider({ children, position = "top-right", ...props }: ToastProv}function Toasts({ position = "top-right" }: { position: ToastPosition }) {- const { state } = useStore();const { toasts } = Toast.useToastManager<ThreadToastData>();- const activeThreadId = state.activeThreadId;+ const activeThreadId = useActiveThreadIdFromRoute();const isTop = position.startsWith("top");const visibleToasts = toasts.filter((toast) =>shouldRenderForActiveThread(toast.data, activeThreadId),@@ -292,9 +306,8 @@ function AnchoredToastProvider({ children, ...props }: Toast.Provider.Props) {}function AnchoredToasts() {- const { state } = useStore();const { toasts } = Toast.useToastManager<ThreadToastData>();- const activeThreadId = state.activeThreadId;+ const activeThreadId = useActiveThreadIdFromRoute();return (<Toast.Portal data-slot="toast-portal-anchored">diff --git a/apps/web/src/hooks/useTheme.ts b/apps/web/src/hooks/useTheme.tsindex 4099cdc91..6a0e61d2d 100644--- a/apps/web/src/hooks/useTheme.ts+++ b/apps/web/src/hooks/useTheme.ts@@ -28,6 +28,7 @@ function applyTheme(theme: Theme, suppressTransitions = false) {document.documentElement.classList.toggle("dark", isDark);if (suppressTransitions) {// Force a reflow so the no-transitions class takes effect before removal+ // oxlint-disable-next-line no-unused-expressionsdocument.documentElement.offsetHeight;requestAnimationFrame(() => {document.documentElement.classList.remove("no-transitions");diff --git a/apps/web/src/main.tsx b/apps/web/src/main.tsxindex e11b2d8c3..baa3fea4f 100644--- a/apps/web/src/main.tsx+++ b/apps/web/src/main.tsx@@ -2,7 +2,6 @@ import React from "react";import ReactDOM from "react-dom/client";import { QueryClient, QueryClientProvider } from "@tanstack/react-query";import { RouterProvider } from "@tanstack/react-router";-import { AnchoredToastProvider, ToastProvider } from "./components/ui/toast";import { createHashHistory, createRouter, createBrowserHistory } from "@tanstack/react-router";import { StoreProvider } from "./store";@@ -23,24 +22,21 @@ const router = createRouter({context: {queryClient,},-});--function App() {- return (+ Wrap: ({ children }) => (<QueryClientProvider client={queryClient}>- <StoreProvider>- <ToastProvider>- <AnchoredToastProvider>- <RouterProvider router={router} />- </AnchoredToastProvider>- </ToastProvider>- </StoreProvider>+ <StoreProvider>{children}</StoreProvider></QueryClientProvider>- );+ ),+});++declare module "@tanstack/react-router" {+ interface Register {+ router: typeof router;+ }}ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(<React.StrictMode>- <App />+ <RouterProvider router={router} /></React.StrictMode>,);diff --git a/apps/web/src/persistenceSchema.test.ts b/apps/web/src/persistenceSchema.test.tsindex 2b7b951c8..365625033 100644--- a/apps/web/src/persistenceSchema.test.ts+++ b/apps/web/src/persistenceSchema.test.ts@@ -106,7 +106,6 @@ describe("hydratePersistedState", () => {{ id: `group-${DEFAULT_THREAD_TERMINAL_ID}`, terminalIds: [DEFAULT_THREAD_TERMINAL_ID] },]);expect(hydrated?.threads[0]?.activeTerminalGroupId).toBe(`group-${DEFAULT_THREAD_TERMINAL_ID}`);- expect(hydrated?.activeThreadId).toBe("t-1");expect(hydrated?.runtimeMode).toBe("full-access");});@@ -442,7 +441,6 @@ describe("toPersistedState", () => {},],threads: [thread],- activeThreadId: "t-1",runtimeMode: "full-access",});diff --git a/apps/web/src/persistenceSchema.ts b/apps/web/src/persistenceSchema.tsindex 2f65a0f19..d2aeb3780 100644--- a/apps/web/src/persistenceSchema.ts+++ b/apps/web/src/persistenceSchema.ts@@ -90,7 +90,7 @@ const persistedThreadSchema = z.object({const persistedStateBodySchema = z.object({projects: z.array(persistedProjectSchema),threads: z.array(persistedThreadSchema),- activeThreadId: z.string().min(1).nullable(),+ activeThreadId: z.string().min(1).nullable().optional(),});const runtimeModeSchema = z.enum(["approval-required", "full-access"]);@@ -141,7 +141,6 @@ const persistedStateSchema = z.union([export interface PersistedStoreSnapshot {projects: Project[];threads: Thread[];- activeThreadId: string | null;runtimeMode: RuntimeMode;}@@ -332,15 +331,9 @@ export function hydratePersistedState(const threads = parsedState.data.threads.map((thread) => hydrateThread(thread, isLegacyPayload)).filter((thread) => projectIds.has(thread.projectId));- const hasActiveThread = Boolean(- parsedState.data.activeThreadId &&- threads.some((thread) => thread.id === parsedState.data.activeThreadId),- );-return {projects,threads,- activeThreadId: hasActiveThread ? parsedState.data.activeThreadId : (threads[0]?.id ?? null),runtimeMode:"runtimeMode" in parsedState.data ? parsedState.data.runtimeMode : DEFAULT_RUNTIME_MODE,};@@ -402,7 +395,6 @@ export function toPersistedState(: {}),})),})),- activeThreadId: state.activeThreadId,runtimeMode: state.runtimeMode,};}diff --git a/apps/web/src/routes/__root.tsx b/apps/web/src/routes/__root.tsxindex a80424217..33b578674 100644--- a/apps/web/src/routes/__root.tsx+++ b/apps/web/src/routes/__root.tsx@@ -1,12 +1,12 @@-import { Outlet, createRootRouteWithContext } from "@tanstack/react-router";+import { Outlet, createRootRouteWithContext, useParams } from "@tanstack/react-router";import { useEffect, useRef } from "react";import { QueryClient, useQueryClient } from "@tanstack/react-query";+import { AnchoredToastProvider, ToastProvider } from "../components/ui/toast";import { isElectron } from "../env";import { useNativeApi } from "../hooks/useNativeApi";import { invalidateGitQueries } from "../lib/gitReactQuery";import { DEFAULT_MODEL } from "../model-logic";-import { createThread } from "../threadFactory";import { useStore } from "../store";import { onServerWelcome } from "../wsNativeApi";@@ -30,12 +30,14 @@ function RootRouteView() {}return (- <>- <EventRouter />- <AutoProjectBootstrap />- <DesktopProjectBootstrap />- <Outlet />- </>+ <ToastProvider>+ <AnchoredToastProvider>+ <EventRouter />+ <AutoProjectBootstrap />+ <DesktopProjectBootstrap />+ <Outlet />+ </AnchoredToastProvider>+ </ToastProvider>);}@@ -44,6 +46,10 @@ function EventRouter() {const { dispatch } = useStore();const queryClient = useQueryClient();const activeAssistantItemRef = useRef<string | null>(null);+ const activeThreadId = useParams({+ strict: false,+ select: (params) => params.threadId,+ });useEffect(() => {if (!api) return;@@ -51,13 +57,15 @@ function EventRouter() {if (event.method === "turn/completed") {void invalidateGitQueries(queryClient);}+ if (!activeThreadId) return;dispatch({type: "APPLY_EVENT",event,activeAssistantItemRef,+ activeThreadId,});});- }, [api, dispatch, queryClient]);+ }, [activeThreadId, api, dispatch, queryClient]);useEffect(() => {if (!api) return;@@ -88,14 +96,6 @@ function AutoProjectBootstrap() {const existing = state.projects.find((project) => project.cwd === payload.cwd);if (existing) {bootstrappedRef.current = true;- // Ensure a thread is active- const existingThread = state.threads.find((thread) => thread.projectId === existing.id);- if (existingThread && !state.activeThreadId) {- dispatch({- type: "SET_ACTIVE_THREAD",- threadId: existingThread.id,- });- }dispatch({ type: "SET_THREADS_HYDRATED", hydrated: true });return;}@@ -115,13 +115,9 @@ function AutoProjectBootstrap() {scripts: [],},});- dispatch({- type: "ADD_THREAD",- thread: createThread(projectId),- });dispatch({ type: "SET_THREADS_HYDRATED", hydrated: true });});- }, [state.projects, state.threads, state.activeThreadId, dispatch]);+ }, [state.projects, dispatch]);return null;}diff --git a/apps/web/src/routes/_chat.$threadId.tsx b/apps/web/src/routes/_chat.$threadId.tsxindex 042fa0d37..066f657ea 100644--- a/apps/web/src/routes/_chat.$threadId.tsx+++ b/apps/web/src/routes/_chat.$threadId.tsx@@ -5,7 +5,7 @@ import ChatView from "../components/ChatView";import { useStore } from "../store";function ChatThreadRouteView() {- const { state, dispatch } = useStore();+ const { state } = useStore();const navigate = useNavigate();const { threadId } = Route.useParams();const threadExists = threadId ? state.threads.some((thread) => thread.id === threadId) : false;@@ -24,13 +24,7 @@ function ChatThreadRouteView() {void navigate({ to: "/", replace: true });return;}-- if (state.activeThreadId === threadId) {- return;- }-- dispatch({ type: "SET_ACTIVE_THREAD", threadId });- }, [dispatch, navigate, state.activeThreadId, state.threadsHydrated, threadExists, threadId]);+ }, [navigate, state.threadsHydrated, threadExists, threadId]);if (!threadId || !state.threadsHydrated || !threadExists) {return null;diff --git a/apps/web/src/routes/_chat.index.tsx b/apps/web/src/routes/_chat.index.tsxindex d8db92c20..5e70383c4 100644--- a/apps/web/src/routes/_chat.index.tsx+++ b/apps/web/src/routes/_chat.index.tsx@@ -1,82 +1,22 @@-import { createFileRoute, useNavigate } from "@tanstack/react-router";-import { type FormEvent, useMemo, useState } from "react";+import { createFileRoute } from "@tanstack/react-router";-import { Button } from "../components/ui/button";-import { Textarea } from "../components/ui/textarea";-import { createThread } from "../threadFactory";-import { truncateTitle } from "../truncateTitle";-import { useStore } from "../store";+import { isElectron } from "../env";function ChatIndexRouteView() {- const { state, dispatch } = useStore();- const navigate = useNavigate();- const [draft, setDraft] = useState("");- const defaultProject = state.projects[0] ?? null;- const canCreateThread = defaultProject !== null;-- const placeholder = useMemo(() => {- if (!canCreateThread) {- return "Add a project in the sidebar to start chatting.";- }- return "Start with a goal, bug report, or implementation idea...";- }, [canCreateThread]);-- const onCreateThread = (event: FormEvent<HTMLFormElement>) => {- event.preventDefault();- if (!defaultProject) return;-- const threadTitle = truncateTitle(draft);- const thread = createThread(- defaultProject.id,- threadTitle- ? { model: defaultProject.model, title: threadTitle }- : { model: defaultProject.model },- );-- dispatch({- type: "ADD_THREAD",- thread,- });-- setDraft("");-- void navigate({- to: "/$threadId",- params: { threadId: thread.id },- });- };-return (- <section className="flex min-h-0 min-w-0 flex-1 flex-col bg-background">- <div className="mx-auto flex h-full w-full max-w-3xl flex-col justify-center px-5 py-6">- <div className="mb-5">- <h1 className="text-xl font-semibold text-foreground">New chat</h1>- <p className="mt-1 text-sm text-muted-foreground/70">- Create a thread and continue in the full chat workspace.- </p>+ <div className="flex min-h-0 min-w-0 flex-1 flex-col bg-background text-muted-foreground/40">+ {isElectron && (+ <div className="drag-region flex h-[52px] shrink-0 items-center border-b border-border px-5">+ <span className="text-xs text-muted-foreground/50">No active thread</span></div>+ )}- <form onSubmit={onCreateThread} className="space-y-3">- <Textarea- value={draft}- onChange={(event) => setDraft(event.target.value)}- placeholder={placeholder}- className="min-h-36 resize-y"- disabled={!canCreateThread}- />- <div className="flex items-center justify-between">- <p className="text-xs text-muted-foreground/60">- {canCreateThread- ? "Create a thread first, then send your first prompt."- : "Projects are required before creating threads."}- </p>- <Button type="submit" disabled={!canCreateThread}>- Create thread- </Button>- </div>- </form>+ <div className="flex flex-1 items-center justify-center">+ <div className="text-center">+ <p className="text-sm">Select a thread or create a new one to get started.</p>+ </div></div>- </section>+ </div>);}diff --git a/apps/web/src/routes/_chat.tsx b/apps/web/src/routes/_chat.tsxindex d903f0605..427982e17 100644--- a/apps/web/src/routes/_chat.tsx+++ b/apps/web/src/routes/_chat.tsx@@ -1,5 +1,4 @@-import { Outlet, createFileRoute, useNavigate, useParams } from "@tanstack/react-router";-import { useEffect } from "react";+import { Outlet, createFileRoute } from "@tanstack/react-router";import DiffPanel from "../components/DiffPanel";import Sidebar from "../components/Sidebar";@@ -7,18 +6,6 @@ import { useStore } from "../store";function ChatRouteLayout() {const { state } = useStore();- const navigate = useNavigate();- const params = useParams({ strict: false });- const routeThreadId = typeof params.threadId === "string" ? params.threadId : null;-- useEffect(() => {- if (routeThreadId || !state.activeThreadId) return;- void navigate({- to: "/$threadId",- params: { threadId: state.activeThreadId },- replace: true,- });- }, [navigate, routeThreadId, state.activeThreadId]);return (<div className="flex h-screen overflow-hidden bg-background text-foreground isolate">diff --git a/apps/web/src/store.test.ts b/apps/web/src/store.test.tsindex 90a3a735e..f7c31a90f 100644--- a/apps/web/src/store.test.ts+++ b/apps/web/src/store.test.ts@@ -79,7 +79,6 @@ function makeState(thread: Thread): AppState {},],threads: [thread],- activeThreadId: thread.id,threadsHydrated: true,runtimeMode: "full-access",diffOpen: false,@@ -617,7 +616,6 @@ describe("store reducer thread continuity", () => {projectId: "project-old-b",}),],- activeThreadId: "thread-b",threadsHydrated: true,runtimeMode: "full-access",diffOpen: true,@@ -647,7 +645,6 @@ describe("store reducer thread continuity", () => {expect(next.threads).toHaveLength(1);expect(next.threads[0]?.id).toBe("thread-a");expect(next.threads[0]?.projectId).toBe("project-new-a");- expect(next.activeThreadId).toBe("thread-a");expect(next.diffOpen).toBe(false);expect(next.diffThreadId).toBeNull();expect(next.diffTurnId).toBeNull();@@ -675,7 +672,6 @@ describe("store reducer thread continuity", () => {},],threads: [makeThread({ id: "thread-a", projectId: "project-old-a" })],- activeThreadId: "thread-a",threadsHydrated: true,runtimeMode: "full-access",diffOpen: false,@@ -768,7 +764,6 @@ describe("store reducer thread continuity", () => {projectId: "project-2",}),],- activeThreadId: "thread-a",threadsHydrated: true,runtimeMode: "full-access",diffOpen: true,@@ -786,30 +781,12 @@ describe("store reducer thread continuity", () => {expect(next.projects[0]?.id).toBe("project-2");expect(next.threads).toHaveLength(1);expect(next.threads[0]?.id).toBe("thread-b");- expect(next.activeThreadId).toBe("thread-b");expect(next.diffOpen).toBe(false);expect(next.diffThreadId).toBeNull();expect(next.diffTurnId).toBeNull();expect(next.diffFilePath).toBeNull();});- it("marks the active thread as visited when selected", () => {- const state = makeState(- makeThread({- lastVisitedAt: "2000-01-01T00:00:00.000Z",- }),- );-- const next = reducer(state, {- type: "SET_ACTIVE_THREAD",- threadId: "thread-local-1",- });-- expect(next.activeThreadId).toBe("thread-local-1");- expect(next.threads[0]?.lastVisitedAt).toBeDefined();- expect(next.threads[0]?.lastVisitedAt).not.toBe("2000-01-01T00:00:00.000Z");- });-it("marks completion as seen immediately for the active thread", () => {const state = makeState(makeThread({@@ -831,6 +808,7 @@ describe("store reducer thread continuity", () => {payload: { turn: { id: "turn-1", status: "completed" } },}),activeAssistantItemRef: { current: null },+ activeThreadId: "thread-local-1",});expect(next.threads[0]?.latestTurnCompletedAt).toBe(completedAt);diff --git a/apps/web/src/store.ts b/apps/web/src/store.tsindex aa269c058..e70152247 100644--- a/apps/web/src/store.ts+++ b/apps/web/src/store.ts@@ -42,7 +42,6 @@ type Action =| { type: "TOGGLE_PROJECT"; projectId: string }| { type: "DELETE_PROJECT"; projectId: string }| { type: "ADD_THREAD"; thread: Thread }- | { type: "SET_ACTIVE_THREAD"; threadId: string }| { type: "TOGGLE_THREAD_TERMINAL"; threadId: string }| { type: "SET_THREAD_TERMINAL_OPEN"; threadId: string; open: boolean }| { type: "SET_THREAD_TERMINAL_HEIGHT"; threadId: string; height: number }@@ -68,6 +67,7 @@ type Action =type: "APPLY_EVENT";event: ProviderEvent;activeAssistantItemRef: { current: string | null };+ activeThreadId?: string | null;}| { type: "APPLY_TERMINAL_EVENT"; event: TerminalEvent }| { type: "UPDATE_SESSION"; threadId: string; session: ProviderSession }@@ -113,7 +113,6 @@ type Action =export interface AppState {projects: Project[];threads: Thread[];- activeThreadId: string | null;threadsHydrated: boolean;runtimeMode: RuntimeMode;diffOpen: boolean;@@ -137,7 +136,6 @@ const LEGACY_PERSISTED_STATE_KEYS = [const initialState: AppState = {projects: [],threads: [],- activeThreadId: null,threadsHydrated: false,runtimeMode: DEFAULT_RUNTIME_MODE,diffOpen: false,@@ -162,14 +160,10 @@ function readPersistedState(): AppState {if (!hydrated) return initialState;const threads = hydrated.threads.map((thread) => normalizeThreadTerminals(thread));- const activeThreadId = threads.some((thread) => thread.id === hydrated.activeThreadId)- ? hydrated.activeThreadId- : (threads[0]?.id ?? null);return {...hydrated,threads,- activeThreadId,threadsHydrated: threads.length > 0,diffOpen: false,diffThreadId: null,@@ -638,16 +632,12 @@ export function reducer(state: AppState, action: Action): AppState {});}).filter((thread): thread is Thread => thread !== null);- const activeThreadId = nextThreads.some((thread) => thread.id === state.activeThreadId)- ? state.activeThreadId- : (nextThreads[0]?.id ?? null);const diffState = resetDiffTargetIfMissing(state, nextThreads);return {...state,projects: nextProjects,threads: nextThreads,- activeThreadId,...diffState,};}@@ -667,16 +657,12 @@ export function reducer(state: AppState, action: Action): AppState {}const threads = state.threads.filter((thread) => thread.projectId !== action.projectId);- const activeThreadId = threads.some((thread) => thread.id === state.activeThreadId)- ? state.activeThreadId- : (threads[0]?.id ?? null);const diffState = resetDiffTargetIfMissing(state, threads);return {...state,projects,threads,- activeThreadId,...diffState,};}@@ -691,19 +677,6 @@ export function reducer(state: AppState, action: Action): AppState {return {...state,threads: [...state.threads, nextThread],- activeThreadId: action.thread.id,- };- }-- case "SET_ACTIVE_THREAD": {- const visitedAt = new Date().toISOString();- return {- ...state,- activeThreadId: action.threadId,- threads: updateThread(state.threads, action.threadId, (t) => ({- ...t,- lastVisitedAt: visitedAt,- })),};}@@ -926,7 +899,7 @@ export function reducer(state: AppState, action: Action): AppState {};case "APPLY_EVENT": {- const { event, activeAssistantItemRef } = action;+ const { event, activeAssistantItemRef, activeThreadId } = action;const target = findThreadBySessionId(state.threads, event.sessionId);if (!target) return state;if (shouldIgnoreForeignThreadEvent(target, event)) return state;@@ -959,7 +932,7 @@ export function reducer(state: AppState, action: Action): AppState {events: nextEvents,turnDiffSummaries,...updateTurnFields(t, event),- ...(event.method === "turn/completed" && t.id === state.activeThreadId+ ...(event.method === "turn/completed" && t.id === activeThreadId? { lastVisitedAt: event.createdAt }: {}),};@@ -1176,21 +1149,11 @@ export function reducer(state: AppState, action: Action): AppState {case "DELETE_THREAD": {const threads = state.threads.filter((t) => t.id !== action.threadId);- const activeThreadId =- state.activeThreadId === action.threadId ? (threads[0]?.id ?? null) : state.activeThreadId;- const shouldClearDiffTarget = state.diffThreadId === action.threadId;+ const diffState = resetDiffTargetIfMissing(state, threads);return {...state,threads,- activeThreadId,- ...(shouldClearDiffTarget- ? {- diffOpen: false,- diffThreadId: null,- diffTurnId: null,- diffFilePath: null,- }- : {}),+ ...diffState,};}diff --git a/apps/web/vite.config.js b/apps/web/vite.config.jsnew file mode 100644index 000000000..d1e1f6042--- /dev/null+++ b/apps/web/vite.config.js@@ -0,0 +1,41 @@+import tailwindcss from "@tailwindcss/vite";+import react from "@vitejs/plugin-react";+import { tanstackRouter } from "@tanstack/router-plugin/vite";+import { defineConfig } from "vite";+const port = Number(process.env.PORT ?? 5173);+export default defineConfig({+ plugins: [+ tanstackRouter(),+ react({+ babel: {+ plugins: [["babel-plugin-react-compiler", { target: "19" }]],+ },+ }),+ tailwindcss(),+ ],+ define: {+ // In dev mode, tell the web app where the WebSocket server lives+ "import.meta.env.VITE_WS_URL": JSON.stringify(process.env.VITE_WS_URL ?? ""),+ },+ experimental: {+ enableNativePlugin: true,+ },+ resolve: {+ tsconfigPaths: true,+ },+ server: {+ port,+ strictPort: true,+ hmr: {+ // Explicit config so Vite's HMR WebSocket connects reliably+ // inside Electron's BrowserWindow. Vite 8 uses console.debug for+ // connection logs — enable "Verbose" in DevTools to see them.+ protocol: "ws",+ host: "localhost",+ },+ },+ build: {+ outDir: "dist",+ emptyOutDir: true,+ },+});