From 2c6a5686966f3811df39afce155d6c2d359d859d Mon Sep 17 00:00:00 2001 From: Ajinkya Kharatkar Date: Thu, 15 Oct 2026 07:37:11 +0530 Subject: [PATCH] Fixed the hardcoded project root path --- apps/desktop/src/ipc.ts | 2 ++ apps/desktop/src/main.ts | 7 ++++++- apps/desktop/src/preload.ts | 3 ++- apps/server/src/mock.ts | 9 ++++++++- apps/web/src/env.ts | 2 ++ apps/web/src/wm/instances.ts | 7 ++++++- apps/web/vite.config.ts | 5 +++++ 7 files changed, 31 insertions(+), 4 deletions(-) diff --git a/apps/desktop/src/ipc.ts b/apps/desktop/src/ipc.ts index 1b0f60de..1f3daf28 100644 --- a/apps/desktop/src/ipc.ts +++ b/apps/desktop/src/ipc.ts @@ -1,2 +1,4 @@ /** Synchronous IPC: the renderer reads the app server's RPC URL once, at load. */ export const SERVER_CHANNEL = "codework:server"; +/** Synchronous IPC: the renderer reads the default workspace root once, at load. */ +export const ROOT_CHANNEL = "codework:root"; diff --git a/apps/desktop/src/main.ts b/apps/desktop/src/main.ts index 390d174d..e78071f8 100644 --- a/apps/desktop/src/main.ts +++ b/apps/desktop/src/main.ts @@ -1,8 +1,13 @@ -import { app, BrowserWindow, net, protocol } from "electron"; +import { app, BrowserWindow, ipcMain, net, protocol } from "electron"; import { readFile, stat } from "node:fs/promises"; import path from "node:path"; +import { ROOT_CHANNEL } from "./ipc.ts"; import { startServer } from "./server.ts"; +ipcMain.on(ROOT_CHANNEL, (event) => { + event.returnValue = process.env.CODEWORK_ROOT ?? path.resolve(app.getAppPath(), app.isPackaged ? ".." : "../.."); +}); + const SCHEME = app.isPackaged ? "codework" : "codework-dev"; const HOST = "app"; const APP_URL = `${SCHEME}://${HOST}/`; diff --git a/apps/desktop/src/preload.ts b/apps/desktop/src/preload.ts index f829c408..50e8e2b4 100644 --- a/apps/desktop/src/preload.ts +++ b/apps/desktop/src/preload.ts @@ -1,8 +1,9 @@ import { contextBridge, ipcRenderer } from "electron"; -import { SERVER_CHANNEL } from "./ipc.ts"; +import { ROOT_CHANNEL, SERVER_CHANNEL } from "./ipc.ts"; contextBridge.exposeInMainWorld("desktopBridge", { platform: process.platform, // Main creates the window only after the server is ready, so this is set. server: ipcRenderer.sendSync(SERVER_CHANNEL) as string, + root: ipcRenderer.sendSync(ROOT_CHANNEL) as string, }); diff --git a/apps/server/src/mock.ts b/apps/server/src/mock.ts index 27e9c2eb..00279aef 100644 --- a/apps/server/src/mock.ts +++ b/apps/server/src/mock.ts @@ -1,7 +1,13 @@ +import path from "node:path"; +import { fileURLToPath } from "node:url"; import type { Message, Project, Session } from "./contract.ts"; // Stand-in data until the server talks to the harness. +const repoRoot = + process.env.CODEWORK_ROOT ?? + path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../.."); + const hour = 60 * 60 * 1000; const now = Date.now(); @@ -27,8 +33,9 @@ const sessions: readonly Session[] = [ { id: "s6", project: "notes", title: "Weekly plan", updated: now - 72 * hour }, ].map((session) => ({ ...session, messages: conversation(session.title.toLowerCase()) })); + const roots = [ - { id: "codework", name: "codework", path: "~/Developer/codeworksh/codework" }, + { id: "codework", name: "codework", path: repoRoot }, { id: "webwm", name: "webwm", path: "~/Developer/codeworksh/webwm" }, { id: "notes", name: "notes", path: "~/Documents/notes" }, ]; diff --git a/apps/web/src/env.ts b/apps/web/src/env.ts index 4282a7b0..79a7fb63 100644 --- a/apps/web/src/env.ts +++ b/apps/web/src/env.ts @@ -4,6 +4,8 @@ declare global { platform: string; /** The app server's RPC WebSocket URL. */ server: string; + /** The default workspace root directory. */ + root?: string; }; } } diff --git a/apps/web/src/wm/instances.ts b/apps/web/src/wm/instances.ts index 0304b7f5..1b68d9e1 100644 --- a/apps/web/src/wm/instances.ts +++ b/apps/web/src/wm/instances.ts @@ -33,6 +33,11 @@ export interface Desk { // Tag bits of the workspaces the database is seeded with: Main, Code, Notes. const [main, code, notes] = [tagBit(0), tagBit(1), tagBit(2)]; +const defaultRoot = + (typeof window !== "undefined" && window.desktopBridge?.root) || + (import.meta.env.VITE_PROJECT_ROOT as string) || + ""; + // Hardcoded until instances live in SQLite. Tile order follows this list, so // Files is the master on Main and Projects on Code; Chat and Terminal sit on // two workspaces at once. @@ -41,7 +46,7 @@ const seed: readonly Instance[] = [ id: "files", kind: "codework:explorer", tags: main, - props: { root: "/Users/sanchitrk/Developer/codeworksh/codework" }, + props: { root: defaultRoot }, }, { id: "projects", kind: "codework:projects", tags: code, props: {} }, { id: "chat", kind: "codework:placeholder", title: "Chat", tags: main | code, props: {} }, diff --git a/apps/web/vite.config.ts b/apps/web/vite.config.ts index 857a8eb0..eb4b4034 100644 --- a/apps/web/vite.config.ts +++ b/apps/web/vite.config.ts @@ -17,4 +17,9 @@ export default defineConfig({ // Pinned so the desktop shell can proxy to a fixed address; `localhost` // may bind IPv6-only, which Electron's 127.0.0.1 lookup then misses. server: { host: "127.0.0.1", port: 5173, strictPort: true }, + define: { + "import.meta.env.VITE_PROJECT_ROOT": JSON.stringify( + process.env.CODEWORK_ROOT ?? fileURLToPath(new URL("../..", import.meta.url)), + ), + }, });