From 34f22876ab9e15e9f14300a8c21cd7109800d1ab Mon Sep 17 00:00:00 2001 From: haoyuren <13851610112@163.com> Date: Fri, 4 Sep 2026 22:26:49 -0500 Subject: Fix main-document switching end to end; stable project-independent MCP path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Main document: the app never called Overleaf's official settings endpoint, so "Set as main document" only changed renderer state and agents had no way to switch at all — compiles kept using the old root. Now: - Right-click Set as main and the new set_main_file MCP tool both POST /project/:id/settings {rootDocId} (web parity, persists project-wide) - Handle the rootDocUpdated broadcast: update the project snapshot, the renderer state, and rewrite CLAUDE.md/AGENTS.md — the guide's stale "Main file" line was teaching agents to compile the old root via main_file overrides - Compile root resolution uses the sync bridge's live maps, so docs created mid-session resolve correctly (agent guide too) MCP server location: Codex stores its MCP registration globally, and the per-project path went stale when the project temp dir was cleaned up ("connection closed" on handshake). The bundled server now installs to ~/.lattex/lattex-mcp.mjs (project-independent, refreshed on connect; the esbuild bundle since the raw source can't resolve node_modules from there) and resolves the project at runtime: $LATTEX_PROJECT_DIR, cwd + ancestors, legacy script location, then single live project in tmpdir. Register once, works for every project. Co-Authored-By: Claude Fable 5 --- src/preload/index.ts | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/preload') diff --git a/src/preload/index.ts b/src/preload/index.ts index 116e8e2..1b8ebce 100644 --- a/src/preload/index.ts +++ b/src/preload/index.ts @@ -177,6 +177,13 @@ const api = { ipcRenderer.invoke('overleaf:removeProjectsFromTag', tagId, projectIds) as Promise<{ success: boolean; message?: string }>, overleafSetProjectState: (projectId: string, action: 'archive' | 'unarchive' | 'trash' | 'untrash' | 'delete' | 'leave') => ipcRenderer.invoke('overleaf:setProjectState', projectId, action) as Promise<{ success: boolean; message?: string }>, + overleafSetRootDoc: (projectId: string, docId: string) => + ipcRenderer.invoke('overleaf:setRootDoc', projectId, docId) as Promise<{ success: boolean; message?: string }>, + onProjectRootDocUpdated: (cb: (docId: string) => void) => { + const handler = (_e: Electron.IpcRendererEvent, docId: string) => cb(docId) + ipcRenderer.on('project:rootDocUpdated', handler) + return () => { ipcRenderer.removeListener('project:rootDocUpdated', handler) } + }, overleafRenameProject: (projectId: string, newName: string) => ipcRenderer.invoke('overleaf:renameProject', projectId, newName) as Promise<{ success: boolean; message?: string }>, overleafCloneProject: (projectId: string, projectName: string, tags?: string[]) => -- cgit v1.2.3