1- import { app , BrowserWindow , ipcMain } from "electron" ;
1+ import { app , BrowserWindow , ipcMain , dialog } from "electron" ;
22import * as pty from "node-pty" ;
33import * as os from "os" ;
4+ import { simpleGit } from "simple-git" ;
5+ import Store from "electron-store" ;
6+
7+ interface SessionConfig {
8+ projectDir : string ;
9+ parentBranch : string ;
10+ codingAgent : string ;
11+ }
412
513let mainWindow : BrowserWindow ;
614const sessions = new Map < string , pty . IPty > ( ) ;
15+ const store = new Store ( ) ;
16+
17+ // Open directory picker
18+ ipcMain . handle ( "select-directory" , async ( ) => {
19+ const result = await dialog . showOpenDialog ( mainWindow , {
20+ properties : [ "openDirectory" ] ,
21+ } ) ;
22+
23+ if ( result . canceled || result . filePaths . length === 0 ) {
24+ return null ;
25+ }
26+
27+ return result . filePaths [ 0 ] ;
28+ } ) ;
29+
30+ // Get git branches from directory
31+ ipcMain . handle ( "get-branches" , async ( _event , dirPath : string ) => {
32+ try {
33+ const git = simpleGit ( dirPath ) ;
34+ const branchSummary = await git . branch ( ) ;
35+ return branchSummary . all ;
36+ } catch ( error ) {
37+ console . error ( "Error getting branches:" , error ) ;
38+ return [ ] ;
39+ }
40+ } ) ;
741
842// Create new session
9- ipcMain . on ( "create-session" , ( event ) => {
43+ ipcMain . on ( "create-session" , ( event , config : SessionConfig ) => {
1044 const sessionId = `session-${ Date . now ( ) } ` ;
1145 const shell = os . platform ( ) === "darwin" ? "zsh" : "bash" ;
1246
1347 const ptyProcess = pty . spawn ( shell , [ ] , {
1448 name : "xterm-color" ,
1549 cols : 80 ,
1650 rows : 30 ,
17- cwd : process . env . HOME ,
51+ cwd : config . projectDir || process . env . HOME ,
1852 env : process . env ,
1953 } ) ;
2054
@@ -24,7 +58,7 @@ ipcMain.on("create-session", (event) => {
2458 mainWindow . webContents . send ( "session-output" , sessionId , data ) ;
2559 } ) ;
2660
27- event . reply ( "session-created" , sessionId ) ;
61+ event . reply ( "session-created" , sessionId , config ) ;
2862} ) ;
2963
3064// Handle session input
0 commit comments