diff options
Diffstat (limited to 'src/main/ipc')
| -rw-r--r-- | src/main/ipc/handlers.ts | 86 |
1 files changed, 79 insertions, 7 deletions
diff --git a/src/main/ipc/handlers.ts b/src/main/ipc/handlers.ts index ce95f4c..bc0d024 100644 --- a/src/main/ipc/handlers.ts +++ b/src/main/ipc/handlers.ts | |||
| @@ -3,6 +3,7 @@ import * as projects from "../db/projects"; | |||
| 3 | import * as sessions from "../db/sessions"; | 3 | import * as sessions from "../db/sessions"; |
| 4 | import * as claude from "../claude"; | 4 | import * as claude from "../claude"; |
| 5 | import type { UserPermissionMode } from "../claude/phases"; | 5 | import type { UserPermissionMode } from "../claude/phases"; |
| 6 | import * as git from "../git/worktree"; | ||
| 6 | 7 | ||
| 7 | export function registerIpcHandlers(mainWindow: BrowserWindow): void { | 8 | export function registerIpcHandlers(mainWindow: BrowserWindow): void { |
| 8 | // Projects | 9 | // Projects |
| @@ -18,12 +19,42 @@ export function registerIpcHandlers(mainWindow: BrowserWindow): void { | |||
| 18 | ipcMain.handle("sessions:list", (_, projectId: string) => | 19 | ipcMain.handle("sessions:list", (_, projectId: string) => |
| 19 | sessions.listSessions(projectId) | 20 | sessions.listSessions(projectId) |
| 20 | ); | 21 | ); |
| 21 | ipcMain.handle("sessions:create", (_, projectId: string, name: string) => | 22 | |
| 22 | sessions.createSession(projectId, name) | 23 | ipcMain.handle("sessions:create", async (_, projectId: string, name: string) => { |
| 23 | ); | 24 | const session = sessions.createSession(projectId, name); |
| 24 | ipcMain.handle("sessions:delete", (_, id: string) => | 25 | const project = projects.getProject(projectId); |
| 25 | sessions.deleteSession(id) | 26 | |
| 26 | ); | 27 | if (project && git.isGitRepo(project.path)) { |
| 28 | try { | ||
| 29 | // Create git worktree for this session | ||
| 30 | git.createWorktree(project.path, session.id); | ||
| 31 | } catch (error) { | ||
| 32 | console.error("Failed to create worktree:", error); | ||
| 33 | // Continue without worktree - not fatal | ||
| 34 | } | ||
| 35 | } | ||
| 36 | |||
| 37 | return session; | ||
| 38 | }); | ||
| 39 | |||
| 40 | ipcMain.handle("sessions:delete", (_, id: string) => { | ||
| 41 | const session = sessions.getSession(id); | ||
| 42 | if (session) { | ||
| 43 | const project = projects.getProject(session.project_id); | ||
| 44 | if (project) { | ||
| 45 | // Clean up worktree if exists | ||
| 46 | try { | ||
| 47 | git.removeWorktree(project.path, id); | ||
| 48 | } catch { | ||
| 49 | // Worktree might not exist, that's ok | ||
| 50 | } | ||
| 51 | // Clean up session artifacts | ||
| 52 | claude.clearSessionArtifacts(project.path, id); | ||
| 53 | } | ||
| 54 | } | ||
| 55 | sessions.deleteSession(id); | ||
| 56 | }); | ||
| 57 | |||
| 27 | ipcMain.handle("sessions:get", (_, id: string) => sessions.getSession(id)); | 58 | ipcMain.handle("sessions:get", (_, id: string) => sessions.getSession(id)); |
| 28 | 59 | ||
| 29 | // Messages | 60 | // Messages |
| @@ -92,7 +123,31 @@ export function registerIpcHandlers(mainWindow: BrowserWindow): void { | |||
| 92 | } | 123 | } |
| 93 | ); | 124 | ); |
| 94 | 125 | ||
| 95 | // Artifacts | 126 | // Session Artifacts (new session-specific API) |
| 127 | ipcMain.handle( | ||
| 128 | "artifact:readSession", | ||
| 129 | (_, projectPath: string, sessionId: string, filename: string) => { | ||
| 130 | return claude.readSessionArtifact(projectPath, sessionId, filename); | ||
| 131 | } | ||
| 132 | ); | ||
| 133 | |||
| 134 | ipcMain.handle( | ||
| 135 | "artifact:writeSession", | ||
| 136 | (_, projectPath: string, sessionId: string, filename: string, content: string) => { | ||
| 137 | claude.writeSessionArtifact(projectPath, sessionId, filename, content); | ||
| 138 | } | ||
| 139 | ); | ||
| 140 | |||
| 141 | // CLAUDE.md | ||
| 142 | ipcMain.handle("claudemd:read", (_, projectPath: string) => { | ||
| 143 | return claude.readClaudeMd(projectPath); | ||
| 144 | }); | ||
| 145 | |||
| 146 | ipcMain.handle("claudemd:write", (_, projectPath: string, content: string) => { | ||
| 147 | claude.writeClaudeMd(projectPath, content); | ||
| 148 | }); | ||
| 149 | |||
| 150 | // Legacy artifact API (for backward compatibility) | ||
| 96 | ipcMain.handle( | 151 | ipcMain.handle( |
| 97 | "artifact:read", | 152 | "artifact:read", |
| 98 | (_, projectPath: string, filename: string) => { | 153 | (_, projectPath: string, filename: string) => { |
| @@ -107,6 +162,23 @@ export function registerIpcHandlers(mainWindow: BrowserWindow): void { | |||
| 107 | } | 162 | } |
| 108 | ); | 163 | ); |
| 109 | 164 | ||
| 165 | // Git | ||
| 166 | ipcMain.handle("git:isRepo", (_, projectPath: string) => { | ||
| 167 | return git.isGitRepo(projectPath); | ||
| 168 | }); | ||
| 169 | |||
| 170 | ipcMain.handle("git:worktreeInfo", (_, projectPath: string, sessionId: string) => { | ||
| 171 | return git.getWorktreeInfo(projectPath, sessionId); | ||
| 172 | }); | ||
| 173 | |||
| 174 | ipcMain.handle("git:commit", (_, worktreePath: string, message: string, files?: string[]) => { | ||
| 175 | git.commitChanges(worktreePath, message, files); | ||
| 176 | }); | ||
| 177 | |||
| 178 | ipcMain.handle("git:hasChanges", (_, worktreePath: string) => { | ||
| 179 | return git.hasUncommittedChanges(worktreePath); | ||
| 180 | }); | ||
| 181 | |||
| 110 | // Dialogs | 182 | // Dialogs |
| 111 | ipcMain.handle("dialog:selectDirectory", async () => { | 183 | ipcMain.handle("dialog:selectDirectory", async () => { |
| 112 | const result = await dialog.showOpenDialog(mainWindow, { | 184 | const result = await dialog.showOpenDialog(mainWindow, { |
