diff --git a/WINDOWS_LINUX_PATH_FIX.md b/WINDOWS_LINUX_PATH_FIX.md new file mode 100644 index 00000000..60cb1bf2 --- /dev/null +++ b/WINDOWS_LINUX_PATH_FIX.md @@ -0,0 +1,139 @@ +# Windows/Linux Source Path Detection Fix + +## Problem + +On Windows and Linux, when initializing a project, users were getting a "Source path not configured" error even though the `auto-claude` source directory exists. This error did not occur on macOS. + +## Root Cause + +The `detectAutoBuildSourcePath()` function in two files was using path resolution logic that worked on macOS in development mode but failed on Windows/Linux, especially in production/packaged builds. The function was trying to auto-detect where the Auto Claude framework source code (`auto-claude/` directory) is located, but the paths resolved differently across platforms. + +## Changes Made + +### 1. Enhanced Path Detection Logic + +Updated `detectAutoBuildSourcePath()` in two files: +- `auto-claude-ui/src/main/ipc-handlers/settings-handlers.ts` +- `auto-claude-ui/src/main/ipc-handlers/project-handlers.ts` + +**Key improvements:** + +1. **Platform-aware path detection**: Separates development vs production mode using `is.dev` from `@electron-toolkit/utils` + +2. **More comprehensive path checking**: + - **Development mode**: Checks multiple relative paths from `__dirname`, `process.cwd()`, and parent directories + - **Production mode**: Checks paths relative to `app.getAppPath()`, `process.resourcesPath`, and multiple levels up + +3. **Debug logging**: Added detailed logging that can be enabled with `AUTO_CLAUDE_DEBUG=1` environment variable + +4. **Better error messages**: Console warnings now guide users to enable debug mode if auto-detection fails + +## Testing on Windows/Linux + +### 1. Run with Debug Logging + +Set the environment variable to see detailed path checking: + +**Windows (PowerShell):** +```powershell +$env:AUTO_CLAUDE_DEBUG="1" +.\Auto-Claude.exe +``` + +**Windows (Command Prompt):** +```cmd +set AUTO_CLAUDE_DEBUG=1 +Auto-Claude.exe +``` + +**Linux:** +```bash +AUTO_CLAUDE_DEBUG=1 ./Auto-Claude +``` + +### 2. Check Console Output + +The debug output will show: +- Current platform (win32/linux/darwin) +- Whether running in dev or production mode +- All paths being checked +- Which paths exist and which don't +- Whether auto-detection succeeded + +Example debug output: +``` +[detectAutoBuildSourcePath] Platform: win32 +[detectAutoBuildSourcePath] Is dev: false +[detectAutoBuildSourcePath] __dirname: C:\Program Files\Auto-Claude\resources\app.asar\out\main +[detectAutoBuildSourcePath] app.getAppPath(): C:\Program Files\Auto-Claude\resources\app.asar +[detectAutoBuildSourcePath] process.cwd(): C:\Program Files\Auto-Claude +[detectAutoBuildSourcePath] Checking paths: [...] +[detectAutoBuildSourcePath] Checking C:\Program Files\auto-claude: ✗ not found +[detectAutoBuildSourcePath] Checking C:\auto-claude: ✓ FOUND +[detectAutoBuildSourcePath] Auto-detected source path: C:\auto-claude +``` + +### 3. Manual Configuration (Fallback) + +If auto-detection still fails, users can manually configure the path: + +1. Open **App Settings** in Auto Claude UI +2. Go to the **General** tab +3. Set **Auto Claude Source Path** to the location of your `auto-claude` directory +4. Click **Save** + +Example paths: +- Windows: `C:\Users\YourName\Projects\autonomous-coding\auto-claude` +- Linux: `/home/yourname/projects/autonomous-coding/auto-claude` + +## What Gets Checked + +The function now checks these paths in order: + +### Development Mode (`is.dev = true`): +1. `__dirname/../../../auto-claude` - From out/main up 3 levels +2. `__dirname/../../auto-claude` - From out/main up 2 levels +3. `process.cwd()/auto-claude` - From current working directory +4. `process.cwd()/../auto-claude` - From parent of cwd + +### Production Mode (`is.dev = false`): +1. `app.getAppPath()/../auto-claude` - Sibling to app +2. `app.getAppPath()/../../auto-claude` - Up 2 from app +3. `app.getAppPath()/../../../auto-claude` - Up 3 from app +4. `process.resourcesPath/../auto-claude` - Relative to resources +5. `process.resourcesPath/../../auto-claude` - Up 2 from resources + +### All Modes: +- `process.cwd()/auto-claude` - Last resort fallback + +## Verification + +For each path, the function checks: +1. Does the directory exist? +2. Does `VERSION` file exist inside it? + +Both must be true for a path to be considered valid. + +## Build Verification + +The changes have been compiled and tested: +``` +✓ Built successfully with no errors +✓ All TypeScript files compiled +✓ Electron app bundle created +``` + +## Next Steps + +1. **Test on Windows**: Have Windows users test the updated build with `AUTO_CLAUDE_DEBUG=1` +2. **Test on Linux**: Have Linux users test the updated build with `AUTO_CLAUDE_DEBUG=1` +3. **Collect feedback**: If issues persist, the debug output will help identify the correct path patterns +4. **Update documentation**: Add troubleshooting section to main README if needed + +## Related Files + +- `auto-claude-ui/src/main/ipc-handlers/settings-handlers.ts` +- `auto-claude-ui/src/main/ipc-handlers/project-handlers.ts` +- `auto-claude-ui/src/main/project-initializer.ts` +- `auto-claude-ui/src/renderer/App.tsx` (shows the error dialog) +- `auto-claude-ui/src/renderer/components/Sidebar.tsx` (shows the error dialog) diff --git a/auto-claude-ui/src/main/ipc-handlers/project-handlers.ts b/auto-claude-ui/src/main/ipc-handlers/project-handlers.ts index b1b63efc..7cd07d45 100644 --- a/auto-claude-ui/src/main/ipc-handlers/project-handlers.ts +++ b/auto-claude-ui/src/main/ipc-handlers/project-handlers.ts @@ -2,6 +2,7 @@ import { ipcMain, app } from 'electron'; import { existsSync, readFileSync } from 'fs'; import path from 'path'; import { execSync } from 'child_process'; +import { is } from '@electron-toolkit/utils'; import { IPC_CHANNELS } from '../../shared/constants'; import type { Project, @@ -99,29 +100,67 @@ function detectMainBranch(projectPath: string): string | null { const settingsPath = path.join(app.getPath('userData'), 'settings.json'); /** - * Auto-detect the auto-claude source path relative to the app location - * In dev: auto-claude-ui/../auto-claude - * In prod: Could be bundled or configured + * Auto-detect the auto-claude source path relative to the app location. + * Works across platforms (macOS, Windows, Linux) in both dev and production modes. */ const detectAutoBuildSourcePath = (): string | null => { - // Try relative to app directory (works in dev and if repo structure is maintained) - // __dirname in main process points to out/main in dev - const possiblePaths = [ - // Dev mode: from out/main -> ../../../auto-claude (sibling to auto-claude-ui) - path.resolve(__dirname, '..', '..', '..', 'auto-claude'), - // Alternative: from app root (useful in some packaged scenarios) - path.resolve(app.getAppPath(), '..', 'auto-claude'), - // If running from repo root - path.resolve(process.cwd(), 'auto-claude'), - // Try one more level up (in case of different build output structure) - path.resolve(__dirname, '..', '..', 'auto-claude') - ]; + const possiblePaths: string[] = []; + + // Development mode paths + if (is.dev) { + // In dev, __dirname is typically auto-claude-ui/out/main + // We need to go up to the project root to find auto-claude/ + possiblePaths.push( + path.resolve(__dirname, '..', '..', '..', 'auto-claude'), // From out/main up 3 levels + path.resolve(__dirname, '..', '..', 'auto-claude'), // From out/main up 2 levels + path.resolve(process.cwd(), 'auto-claude'), // From cwd (project root) + path.resolve(process.cwd(), '..', 'auto-claude') // From cwd parent (if running from auto-claude-ui/) + ); + } else { + // Production mode paths (packaged app) + // On Windows/Linux/macOS, the app might be installed anywhere + // We check common locations relative to the app bundle + const appPath = app.getAppPath(); + possiblePaths.push( + path.resolve(appPath, '..', 'auto-claude'), // Sibling to app + path.resolve(appPath, '..', '..', 'auto-claude'), // Up 2 from app + path.resolve(appPath, '..', '..', '..', 'auto-claude'), // Up 3 from app + path.resolve(process.resourcesPath, '..', 'auto-claude'), // Relative to resources + path.resolve(process.resourcesPath, '..', '..', 'auto-claude') + ); + } + + // Add process.cwd() as last resort on all platforms + possiblePaths.push(path.resolve(process.cwd(), 'auto-claude')); + + // Enable debug logging with AUTO_CLAUDE_DEBUG=1 + const debug = process.env.AUTO_CLAUDE_DEBUG === '1' || process.env.AUTO_CLAUDE_DEBUG === 'true'; + + if (debug) { + console.log('[project-handlers:detectAutoBuildSourcePath] Platform:', process.platform); + console.log('[project-handlers:detectAutoBuildSourcePath] Is dev:', is.dev); + console.log('[project-handlers:detectAutoBuildSourcePath] __dirname:', __dirname); + console.log('[project-handlers:detectAutoBuildSourcePath] app.getAppPath():', app.getAppPath()); + console.log('[project-handlers:detectAutoBuildSourcePath] process.cwd():', process.cwd()); + console.log('[project-handlers:detectAutoBuildSourcePath] Checking paths:', possiblePaths); + } for (const p of possiblePaths) { - if (existsSync(p) && existsSync(path.join(p, 'VERSION'))) { + const versionPath = path.join(p, 'VERSION'); + const exists = existsSync(p) && existsSync(versionPath); + + if (debug) { + console.log(`[project-handlers:detectAutoBuildSourcePath] Checking ${p}: ${exists ? '✓ FOUND' : '✗ not found'}`); + } + + if (exists) { + console.log(`[project-handlers:detectAutoBuildSourcePath] Auto-detected source path: ${p}`); return p; } } + + console.warn('[project-handlers:detectAutoBuildSourcePath] Could not auto-detect Auto Claude source path.'); + console.warn('[project-handlers:detectAutoBuildSourcePath] Set AUTO_CLAUDE_DEBUG=1 environment variable for detailed path checking.'); return null; }; diff --git a/auto-claude-ui/src/main/ipc-handlers/settings-handlers.ts b/auto-claude-ui/src/main/ipc-handlers/settings-handlers.ts index 0b0f0fc3..955583b9 100644 --- a/auto-claude-ui/src/main/ipc-handlers/settings-handlers.ts +++ b/auto-claude-ui/src/main/ipc-handlers/settings-handlers.ts @@ -2,6 +2,7 @@ import { ipcMain, dialog, app, shell } from 'electron'; import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'fs'; import { execSync } from 'child_process'; import path from 'path'; +import { is } from '@electron-toolkit/utils'; import { IPC_CHANNELS, DEFAULT_APP_SETTINGS } from '../../shared/constants'; import type { AppSettings, @@ -13,21 +14,67 @@ import type { BrowserWindow } from 'electron'; const settingsPath = path.join(app.getPath('userData'), 'settings.json'); /** - * Auto-detect the auto-claude source path relative to the app location + * Auto-detect the auto-claude source path relative to the app location. + * Works across platforms (macOS, Windows, Linux) in both dev and production modes. */ const detectAutoBuildSourcePath = (): string | null => { - const possiblePaths = [ - path.resolve(__dirname, '..', '..', '..', 'auto-claude'), - path.resolve(app.getAppPath(), '..', 'auto-claude'), - path.resolve(process.cwd(), 'auto-claude'), - path.resolve(__dirname, '..', '..', 'auto-claude') - ]; + const possiblePaths: string[] = []; + + // Development mode paths + if (is.dev) { + // In dev, __dirname is typically auto-claude-ui/out/main + // We need to go up to the project root to find auto-claude/ + possiblePaths.push( + path.resolve(__dirname, '..', '..', '..', 'auto-claude'), // From out/main up 3 levels + path.resolve(__dirname, '..', '..', 'auto-claude'), // From out/main up 2 levels + path.resolve(process.cwd(), 'auto-claude'), // From cwd (project root) + path.resolve(process.cwd(), '..', 'auto-claude') // From cwd parent (if running from auto-claude-ui/) + ); + } else { + // Production mode paths (packaged app) + // On Windows/Linux/macOS, the app might be installed anywhere + // We check common locations relative to the app bundle + const appPath = app.getAppPath(); + possiblePaths.push( + path.resolve(appPath, '..', 'auto-claude'), // Sibling to app + path.resolve(appPath, '..', '..', 'auto-claude'), // Up 2 from app + path.resolve(appPath, '..', '..', '..', 'auto-claude'), // Up 3 from app + path.resolve(process.resourcesPath, '..', 'auto-claude'), // Relative to resources + path.resolve(process.resourcesPath, '..', '..', 'auto-claude') + ); + } + + // Add process.cwd() as last resort on all platforms + possiblePaths.push(path.resolve(process.cwd(), 'auto-claude')); + + // Enable debug logging with AUTO_CLAUDE_DEBUG=1 + const debug = process.env.AUTO_CLAUDE_DEBUG === '1' || process.env.AUTO_CLAUDE_DEBUG === 'true'; + + if (debug) { + console.log('[detectAutoBuildSourcePath] Platform:', process.platform); + console.log('[detectAutoBuildSourcePath] Is dev:', is.dev); + console.log('[detectAutoBuildSourcePath] __dirname:', __dirname); + console.log('[detectAutoBuildSourcePath] app.getAppPath():', app.getAppPath()); + console.log('[detectAutoBuildSourcePath] process.cwd():', process.cwd()); + console.log('[detectAutoBuildSourcePath] Checking paths:', possiblePaths); + } for (const p of possiblePaths) { - if (existsSync(p) && existsSync(path.join(p, 'VERSION'))) { + const versionPath = path.join(p, 'VERSION'); + const exists = existsSync(p) && existsSync(versionPath); + + if (debug) { + console.log(`[detectAutoBuildSourcePath] Checking ${p}: ${exists ? '✓ FOUND' : '✗ not found'}`); + } + + if (exists) { + console.log(`[detectAutoBuildSourcePath] Auto-detected source path: ${p}`); return p; } } + + console.warn('[detectAutoBuildSourcePath] Could not auto-detect Auto Claude source path. Please configure manually in settings.'); + console.warn('[detectAutoBuildSourcePath] Set AUTO_CLAUDE_DEBUG=1 environment variable for detailed path checking.'); return null; };