From 0edd7235cd861ef77d4ceb37a594ae65df52624b Mon Sep 17 00:00:00 2001 From: Clawd Date: Sat, 28 Feb 2026 15:35:00 -0800 Subject: Add session-specific artifacts, CLAUDE.md, and git worktree support - Store artifacts in .claude-flow/sessions/{sessionId}/ - Each session now has isolated research.md and plan.md - Concurrent sessions no longer conflict - Add CLAUDE.md support for shared codebase documentation - Add git worktree creation on session start - Add git commit/status IPC handlers - Update all artifact APIs to be session-specific - Remove artifact clearing on new session (no longer needed) --- src/main/ipc/handlers.ts | 86 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 79 insertions(+), 7 deletions(-) (limited to 'src/main/ipc') 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"; import * as sessions from "../db/sessions"; import * as claude from "../claude"; import type { UserPermissionMode } from "../claude/phases"; +import * as git from "../git/worktree"; export function registerIpcHandlers(mainWindow: BrowserWindow): void { // Projects @@ -18,12 +19,42 @@ export function registerIpcHandlers(mainWindow: BrowserWindow): void { ipcMain.handle("sessions:list", (_, projectId: string) => sessions.listSessions(projectId) ); - ipcMain.handle("sessions:create", (_, projectId: string, name: string) => - sessions.createSession(projectId, name) - ); - ipcMain.handle("sessions:delete", (_, id: string) => - sessions.deleteSession(id) - ); + + ipcMain.handle("sessions:create", async (_, projectId: string, name: string) => { + const session = sessions.createSession(projectId, name); + const project = projects.getProject(projectId); + + if (project && git.isGitRepo(project.path)) { + try { + // Create git worktree for this session + git.createWorktree(project.path, session.id); + } catch (error) { + console.error("Failed to create worktree:", error); + // Continue without worktree - not fatal + } + } + + return session; + }); + + ipcMain.handle("sessions:delete", (_, id: string) => { + const session = sessions.getSession(id); + if (session) { + const project = projects.getProject(session.project_id); + if (project) { + // Clean up worktree if exists + try { + git.removeWorktree(project.path, id); + } catch { + // Worktree might not exist, that's ok + } + // Clean up session artifacts + claude.clearSessionArtifacts(project.path, id); + } + } + sessions.deleteSession(id); + }); + ipcMain.handle("sessions:get", (_, id: string) => sessions.getSession(id)); // Messages @@ -92,7 +123,31 @@ export function registerIpcHandlers(mainWindow: BrowserWindow): void { } ); - // Artifacts + // Session Artifacts (new session-specific API) + ipcMain.handle( + "artifact:readSession", + (_, projectPath: string, sessionId: string, filename: string) => { + return claude.readSessionArtifact(projectPath, sessionId, filename); + } + ); + + ipcMain.handle( + "artifact:writeSession", + (_, projectPath: string, sessionId: string, filename: string, content: string) => { + claude.writeSessionArtifact(projectPath, sessionId, filename, content); + } + ); + + // CLAUDE.md + ipcMain.handle("claudemd:read", (_, projectPath: string) => { + return claude.readClaudeMd(projectPath); + }); + + ipcMain.handle("claudemd:write", (_, projectPath: string, content: string) => { + claude.writeClaudeMd(projectPath, content); + }); + + // Legacy artifact API (for backward compatibility) ipcMain.handle( "artifact:read", (_, projectPath: string, filename: string) => { @@ -107,6 +162,23 @@ export function registerIpcHandlers(mainWindow: BrowserWindow): void { } ); + // Git + ipcMain.handle("git:isRepo", (_, projectPath: string) => { + return git.isGitRepo(projectPath); + }); + + ipcMain.handle("git:worktreeInfo", (_, projectPath: string, sessionId: string) => { + return git.getWorktreeInfo(projectPath, sessionId); + }); + + ipcMain.handle("git:commit", (_, worktreePath: string, message: string, files?: string[]) => { + git.commitChanges(worktreePath, message, files); + }); + + ipcMain.handle("git:hasChanges", (_, worktreePath: string) => { + return git.hasUncommittedChanges(worktreePath); + }); + // Dialogs ipcMain.handle("dialog:selectDirectory", async () => { const result = await dialog.showOpenDialog(mainWindow, { -- cgit v1.2.3