diff --git a/apps/renderer/index.html b/apps/renderer/index.html index c2c8793a7c..d8fd8a14ea 100644 --- a/apps/renderer/index.html +++ b/apps/renderer/index.html @@ -3,7 +3,7 @@ - Electron Todo + CodeThing
diff --git a/apps/renderer/src/App.tsx b/apps/renderer/src/App.tsx index a525c7caeb..c8bc6e7f07 100644 --- a/apps/renderer/src/App.tsx +++ b/apps/renderer/src/App.tsx @@ -3,8 +3,10 @@ import { useEffect, useMemo, useRef } from "react"; import ChatView from "./components/ChatView"; import DiffPanel from "./components/DiffPanel"; import Sidebar from "./components/Sidebar"; +import { DEFAULT_MODEL } from "./model-logic"; import { readNativeApi } from "./session-logic"; import { StoreProvider, useStore } from "./store"; +import { onServerWelcome } from "./wsNativeApi"; function EventRouter() { const api = useMemo(() => readNativeApi(), []); @@ -25,6 +27,60 @@ function EventRouter() { return null; } +function AutoProjectBootstrap() { + const { state, dispatch } = useStore(); + + useEffect(() => { + return onServerWelcome((payload) => { + // Don't create duplicate projects for the same cwd + const existing = state.projects.find((p) => p.cwd === payload.cwd); + if (existing) { + // If there are threads, ensure one is active + const existingThread = state.threads.find( + (t) => t.projectId === existing.id, + ); + if (existingThread && !state.activeThreadId) { + dispatch({ + type: "SET_ACTIVE_THREAD", + threadId: existingThread.id, + }); + } + return; + } + + // Create project + thread from server cwd + const projectId = crypto.randomUUID(); + dispatch({ + type: "ADD_PROJECT", + project: { + id: projectId, + name: payload.projectName, + cwd: payload.cwd, + model: DEFAULT_MODEL, + expanded: true, + }, + }); + dispatch({ + type: "ADD_THREAD", + thread: { + id: crypto.randomUUID(), + codexThreadId: null, + projectId, + title: "New thread", + model: DEFAULT_MODEL, + session: null, + messages: [], + events: [], + error: null, + createdAt: new Date().toISOString(), + }, + }); + }); + }, [state.projects, state.threads, state.activeThreadId, dispatch]); + + return null; +} + function Layout() { const api = useMemo(() => readNativeApi(), []); const { state } = useStore(); @@ -32,10 +88,9 @@ function Layout() { if (!api) { return (
-

- Native bridge unavailable. Launch through Electron. + Connecting to CodeThing server...

@@ -45,6 +100,7 @@ function Layout() { return (
+ {state.diffOpen && } diff --git a/apps/renderer/src/components/ChatView.tsx b/apps/renderer/src/components/ChatView.tsx index 3463a6bd73..4f23757f64 100644 --- a/apps/renderer/src/components/ChatView.tsx +++ b/apps/renderer/src/components/ChatView.tsx @@ -14,6 +14,7 @@ import { } from "react"; import { EDITORS, type EditorId } from "@acme/contracts"; +import { isElectron } from "../env"; import { buildBootstrapInput } from "../historyBootstrap"; import { DEFAULT_MODEL, @@ -537,7 +538,7 @@ export default function ChatView() { if (!activeThread) { return (
-
+ {isElectron &&
}

Select a thread or create a new one to get started.

@@ -550,7 +551,7 @@ export default function ChatView() { return (
{/* Top bar */} -
+

{activeThread.title} diff --git a/apps/renderer/src/components/DiffPanel.tsx b/apps/renderer/src/components/DiffPanel.tsx index 344691d5c9..6a546c848f 100644 --- a/apps/renderer/src/components/DiffPanel.tsx +++ b/apps/renderer/src/components/DiffPanel.tsx @@ -1,3 +1,4 @@ +import { isElectron } from "../env"; import { useStore } from "../store"; export default function DiffPanel() { @@ -6,7 +7,7 @@ export default function DiffPanel() { return (