diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index df1b05b4b..552b9ac35 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -78,10 +78,12 @@ jobs: path: apps/ui/playwright-report/ retention-days: 7 - - name: Upload test results + - name: Upload test results (screenshots, traces, videos) uses: actions/upload-artifact@v4 - if: failure() + if: always() with: name: test-results - path: apps/ui/test-results/ + path: | + apps/ui/test-results/ retention-days: 7 + if-no-files-found: ignore diff --git a/apps/server/src/lib/auth.ts b/apps/server/src/lib/auth.ts index 3120d5125..0a4b53892 100644 --- a/apps/server/src/lib/auth.ts +++ b/apps/server/src/lib/auth.ts @@ -262,7 +262,7 @@ export function getSessionCookieOptions(): { return { httpOnly: true, // JavaScript cannot access this cookie secure: process.env.NODE_ENV === 'production', // HTTPS only in production - sameSite: 'strict', // Only sent for same-site requests (CSRF protection) + sameSite: 'lax', // Sent for same-site requests and top-level navigations, but not cross-origin fetch/XHR maxAge: SESSION_MAX_AGE_MS, path: '/', }; diff --git a/apps/server/src/lib/codex-auth.ts b/apps/server/src/lib/codex-auth.ts new file mode 100644 index 000000000..965885bc0 --- /dev/null +++ b/apps/server/src/lib/codex-auth.ts @@ -0,0 +1,98 @@ +/** + * Shared utility for checking Codex CLI authentication status + * + * Uses 'codex login status' command to verify authentication. + * Never assumes authenticated - only returns true if CLI confirms. + */ + +import { spawnProcess, getCodexAuthPath } from '@automaker/platform'; +import { findCodexCliPath } from '@automaker/platform'; +import * as fs from 'fs'; + +const CODEX_COMMAND = 'codex'; +const OPENAI_API_KEY_ENV = 'OPENAI_API_KEY'; + +export interface CodexAuthCheckResult { + authenticated: boolean; + method: 'api_key_env' | 'cli_authenticated' | 'none'; +} + +/** + * Check Codex authentication status using 'codex login status' command + * + * @param cliPath Optional CLI path. If not provided, will attempt to find it. + * @returns Authentication status and method + */ +export async function checkCodexAuthentication( + cliPath?: string | null +): Promise { + console.log('[CodexAuth] checkCodexAuthentication called with cliPath:', cliPath); + + const resolvedCliPath = cliPath || (await findCodexCliPath()); + const hasApiKey = !!process.env[OPENAI_API_KEY_ENV]; + + console.log('[CodexAuth] resolvedCliPath:', resolvedCliPath); + console.log('[CodexAuth] hasApiKey:', hasApiKey); + + // Debug: Check auth file + const authFilePath = getCodexAuthPath(); + console.log('[CodexAuth] Auth file path:', authFilePath); + try { + const authFileExists = fs.existsSync(authFilePath); + console.log('[CodexAuth] Auth file exists:', authFileExists); + if (authFileExists) { + const authContent = fs.readFileSync(authFilePath, 'utf-8'); + console.log('[CodexAuth] Auth file content:', authContent.substring(0, 500)); // First 500 chars + } + } catch (error) { + console.log('[CodexAuth] Error reading auth file:', error); + } + + // If CLI is not installed, cannot be authenticated + if (!resolvedCliPath) { + console.log('[CodexAuth] No CLI path found, returning not authenticated'); + return { authenticated: false, method: 'none' }; + } + + try { + console.log('[CodexAuth] Running: ' + resolvedCliPath + ' login status'); + const result = await spawnProcess({ + command: resolvedCliPath || CODEX_COMMAND, + args: ['login', 'status'], + cwd: process.cwd(), + env: { + ...process.env, + TERM: 'dumb', // Avoid interactive output + }, + }); + + console.log('[CodexAuth] Command result:'); + console.log('[CodexAuth] exitCode:', result.exitCode); + console.log('[CodexAuth] stdout:', JSON.stringify(result.stdout)); + console.log('[CodexAuth] stderr:', JSON.stringify(result.stderr)); + + // Check both stdout and stderr for "logged in" - Codex CLI outputs to stderr + const combinedOutput = (result.stdout + result.stderr).toLowerCase(); + const isLoggedIn = combinedOutput.includes('logged in'); + console.log('[CodexAuth] isLoggedIn (contains "logged in" in stdout or stderr):', isLoggedIn); + + if (result.exitCode === 0 && isLoggedIn) { + // Determine auth method based on what we know + const method = hasApiKey ? 'api_key_env' : 'cli_authenticated'; + console.log('[CodexAuth] Authenticated! method:', method); + return { authenticated: true, method }; + } + + console.log( + '[CodexAuth] Not authenticated. exitCode:', + result.exitCode, + 'isLoggedIn:', + isLoggedIn + ); + } catch (error) { + console.log('[CodexAuth] Error running command:', error); + } + + console.log('[CodexAuth] Returning not authenticated'); + return { authenticated: false, method: 'none' }; +} diff --git a/apps/server/src/lib/sdk-options.ts b/apps/server/src/lib/sdk-options.ts index 426cf73d2..4d3e670f3 100644 --- a/apps/server/src/lib/sdk-options.ts +++ b/apps/server/src/lib/sdk-options.ts @@ -16,7 +16,6 @@ */ import type { Options } from '@anthropic-ai/claude-agent-sdk'; -import os from 'os'; import path from 'path'; import { resolveModelString } from '@automaker/model-resolver'; import { createLogger } from '@automaker/utils'; @@ -31,6 +30,68 @@ import { } from '@automaker/types'; import { isPathAllowed, PathNotAllowedError, getAllowedRootDirectory } from '@automaker/platform'; +/** + * Result of sandbox compatibility check + */ +export interface SandboxCompatibilityResult { + /** Whether sandbox mode can be enabled for this path */ + enabled: boolean; + /** Optional message explaining why sandbox is disabled */ + message?: string; +} + +/** + * Check if a working directory is compatible with sandbox mode. + * Some paths (like cloud storage mounts) may not work with sandboxed execution. + * + * @param cwd - The working directory to check + * @param sandboxRequested - Whether sandbox mode was requested by settings + * @returns Object indicating if sandbox can be enabled and why not if disabled + */ +export function checkSandboxCompatibility( + cwd: string, + sandboxRequested: boolean +): SandboxCompatibilityResult { + if (!sandboxRequested) { + return { enabled: false }; + } + + const resolvedCwd = path.resolve(cwd); + + // Check for cloud storage paths that may not be compatible with sandbox + const cloudStoragePatterns = [ + // macOS mounted volumes + /^\/Volumes\/GoogleDrive/i, + /^\/Volumes\/Dropbox/i, + /^\/Volumes\/OneDrive/i, + /^\/Volumes\/iCloud/i, + // macOS home directory + /^\/Users\/[^/]+\/Google Drive/i, + /^\/Users\/[^/]+\/Dropbox/i, + /^\/Users\/[^/]+\/OneDrive/i, + /^\/Users\/[^/]+\/Library\/Mobile Documents/i, // iCloud + // Linux home directory + /^\/home\/[^/]+\/Google Drive/i, + /^\/home\/[^/]+\/Dropbox/i, + /^\/home\/[^/]+\/OneDrive/i, + // Windows + /^C:\\Users\\[^\\]+\\Google Drive/i, + /^C:\\Users\\[^\\]+\\Dropbox/i, + /^C:\\Users\\[^\\]+\\OneDrive/i, + ]; + + for (const pattern of cloudStoragePatterns) { + if (pattern.test(resolvedCwd)) { + return { + enabled: false, + message: `Sandbox disabled: Cloud storage path detected (${resolvedCwd}). Sandbox mode may not work correctly with cloud-synced directories.`, + }; + } + } + + return { enabled: true }; +} + /** * Validate that a working directory is allowed by ALLOWED_ROOT_DIRECTORY. * This is the centralized security check for ALL AI model invocations. @@ -57,139 +118,6 @@ export function validateWorkingDirectory(cwd: string): void { } } -/** - * Known cloud storage path patterns where sandbox mode is incompatible. - * - * The Claude CLI sandbox feature uses filesystem isolation that conflicts with - * cloud storage providers' virtual filesystem implementations. This causes the - * Claude process to exit with code 1 when sandbox is enabled for these paths. - * - * Affected providers (macOS paths): - * - Dropbox: ~/Library/CloudStorage/Dropbox-* - * - Google Drive: ~/Library/CloudStorage/GoogleDrive-* - * - OneDrive: ~/Library/CloudStorage/OneDrive-* - * - iCloud Drive: ~/Library/Mobile Documents/ - * - Box: ~/Library/CloudStorage/Box-* - * - * Note: This is a known limitation when using cloud storage paths. - */ - -/** - * macOS-specific cloud storage patterns that appear under ~/Library/ - * These are specific enough to use with includes() safely. - */ -const MACOS_CLOUD_STORAGE_PATTERNS = [ - '/Library/CloudStorage/', // Dropbox, Google Drive, OneDrive, Box on macOS - '/Library/Mobile Documents/', // iCloud Drive on macOS -] as const; - -/** - * Generic cloud storage folder names that need to be anchored to the home directory - * to avoid false positives (e.g., /home/user/my-project-about-dropbox/). - */ -const HOME_ANCHORED_CLOUD_FOLDERS = [ - 'Google Drive', // Google Drive on some systems - 'Dropbox', // Dropbox on Linux/alternative installs - 'OneDrive', // OneDrive on Linux/alternative installs -] as const; - -/** - * Check if a path is within a cloud storage location. - * - * Cloud storage providers use virtual filesystem implementations that are - * incompatible with the Claude CLI sandbox feature, causing process crashes. - * - * Uses two detection strategies: - * 1. macOS-specific patterns (under ~/Library/) - checked via includes() - * 2. Generic folder names - anchored to home directory to avoid false positives - * - * @param cwd - The working directory path to check - * @returns true if the path is in a cloud storage location - */ -export function isCloudStoragePath(cwd: string): boolean { - const resolvedPath = path.resolve(cwd); - // Normalize to forward slashes for consistent pattern matching across platforms - let normalizedPath = resolvedPath.split(path.sep).join('/'); - // Remove Windows drive letter if present (e.g., "C:/Users" -> "/Users") - // This ensures Unix paths in tests work the same on Windows - normalizedPath = normalizedPath.replace(/^[A-Za-z]:/, ''); - - // Check macOS-specific patterns (these are specific enough to use includes) - if (MACOS_CLOUD_STORAGE_PATTERNS.some((pattern) => normalizedPath.includes(pattern))) { - return true; - } - - // Check home-anchored patterns to avoid false positives - // e.g., /home/user/my-project-about-dropbox/ should NOT match - const home = os.homedir(); - for (const folder of HOME_ANCHORED_CLOUD_FOLDERS) { - const cloudPath = path.join(home, folder); - let normalizedCloudPath = cloudPath.split(path.sep).join('/'); - // Remove Windows drive letter if present - normalizedCloudPath = normalizedCloudPath.replace(/^[A-Za-z]:/, ''); - // Check if resolved path starts with the cloud storage path followed by a separator - // This ensures we match ~/Dropbox/project but not ~/Dropbox-archive or ~/my-dropbox-tool - if ( - normalizedPath === normalizedCloudPath || - normalizedPath.startsWith(normalizedCloudPath + '/') - ) { - return true; - } - } - - return false; -} - -/** - * Result of sandbox compatibility check - */ -export interface SandboxCheckResult { - /** Whether sandbox should be enabled */ - enabled: boolean; - /** If disabled, the reason why */ - disabledReason?: 'cloud_storage' | 'user_setting'; - /** Human-readable message for logging/UI */ - message?: string; -} - -/** - * Determine if sandbox mode should be enabled for a given configuration. - * - * Sandbox mode is automatically disabled for cloud storage paths because the - * Claude CLI sandbox feature is incompatible with virtual filesystem - * implementations used by cloud storage providers (Dropbox, Google Drive, etc.). - * - * @param cwd - The working directory - * @param enableSandboxMode - User's sandbox mode setting - * @returns SandboxCheckResult with enabled status and reason if disabled - */ -export function checkSandboxCompatibility( - cwd: string, - enableSandboxMode?: boolean -): SandboxCheckResult { - // User has explicitly disabled sandbox mode - if (enableSandboxMode === false) { - return { - enabled: false, - disabledReason: 'user_setting', - }; - } - - // Check for cloud storage incompatibility (applies when enabled or undefined) - if (isCloudStoragePath(cwd)) { - return { - enabled: false, - disabledReason: 'cloud_storage', - message: `Sandbox mode auto-disabled: Project is in a cloud storage location (${cwd}). The Claude CLI sandbox feature is incompatible with cloud storage filesystems. To use sandbox mode, move your project to a local directory.`, - }; - } - - // Sandbox is compatible and enabled (true or undefined defaults to enabled) - return { - enabled: true, - }; -} - /** * Tool presets for different use cases */ @@ -272,55 +200,31 @@ export function getModelForUseCase( /** * Base options that apply to all SDK calls + * AUTONOMOUS MODE: Always bypass permissions for fully autonomous operation */ function getBaseOptions(): Partial { return { - permissionMode: 'acceptEdits', + permissionMode: 'bypassPermissions', + allowDangerouslySkipPermissions: true, }; } /** - * MCP permission options result + * MCP options result */ -interface McpPermissionOptions { - /** Whether tools should be restricted to a preset */ - shouldRestrictTools: boolean; - /** Options to spread when MCP bypass is enabled */ - bypassOptions: Partial; +interface McpOptions { /** Options to spread for MCP servers */ mcpServerOptions: Partial; } /** * Build MCP-related options based on configuration. - * Centralizes the logic for determining permission modes and tool restrictions - * when MCP servers are configured. * * @param config - The SDK options config - * @returns Object with MCP permission settings to spread into final options + * @returns Object with MCP server settings to spread into final options */ -function buildMcpOptions(config: CreateSdkOptionsConfig): McpPermissionOptions { - const hasMcpServers = config.mcpServers && Object.keys(config.mcpServers).length > 0; - // Default to true for autonomous workflow. Security is enforced when adding servers - // via the security warning dialog that explains the risks. - const mcpAutoApprove = config.mcpAutoApproveTools ?? true; - const mcpUnrestricted = config.mcpUnrestrictedTools ?? true; - - // Determine if we should bypass permissions based on settings - const shouldBypassPermissions = hasMcpServers && mcpAutoApprove; - // Determine if we should restrict tools (only when no MCP or unrestricted is disabled) - const shouldRestrictTools = !hasMcpServers || !mcpUnrestricted; - +function buildMcpOptions(config: CreateSdkOptionsConfig): McpOptions { return { - shouldRestrictTools, - // Only include bypass options when MCP is configured and auto-approve is enabled - bypassOptions: shouldBypassPermissions - ? { - permissionMode: 'bypassPermissions' as const, - // Required flag when using bypassPermissions mode - allowDangerouslySkipPermissions: true, - } - : {}, // Include MCP servers if configured mcpServerOptions: config.mcpServers ? { mcpServers: config.mcpServers } : {}, }; @@ -422,18 +326,9 @@ export interface CreateSdkOptionsConfig { /** Enable auto-loading of CLAUDE.md files via SDK's settingSources */ autoLoadClaudeMd?: boolean; - /** Enable sandbox mode for bash command isolation */ - enableSandboxMode?: boolean; - /** MCP servers to make available to the agent */ mcpServers?: Record; - /** Auto-approve MCP tool calls without permission prompts */ - mcpAutoApproveTools?: boolean; - - /** Allow unrestricted tools when MCP servers are enabled */ - mcpUnrestrictedTools?: boolean; - /** Extended thinking level for Claude models */ thinkingLevel?: ThinkingLevel; } @@ -554,7 +449,6 @@ export function createSuggestionsOptions(config: CreateSdkOptionsConfig): Option * - Full tool access for code modification * - Standard turns for interactive sessions * - Model priority: explicit model > session model > chat default - * - Sandbox mode controlled by enableSandboxMode setting (auto-disabled for cloud storage) * - When autoLoadClaudeMd is true, uses preset mode and settingSources for CLAUDE.md loading */ export function createChatOptions(config: CreateSdkOptionsConfig): Options { @@ -573,24 +467,12 @@ export function createChatOptions(config: CreateSdkOptionsConfig): Options { // Build thinking options const thinkingOptions = buildThinkingOptions(config.thinkingLevel); - // Check sandbox compatibility (auto-disables for cloud storage paths) - const sandboxCheck = checkSandboxCompatibility(config.cwd, config.enableSandboxMode); - return { ...getBaseOptions(), model: getModelForUseCase('chat', effectiveModel), maxTurns: MAX_TURNS.standard, cwd: config.cwd, - // Only restrict tools if no MCP servers configured or unrestricted is disabled - ...(mcpOptions.shouldRestrictTools && { allowedTools: [...TOOL_PRESETS.chat] }), - // Apply MCP bypass options if configured - ...mcpOptions.bypassOptions, - ...(sandboxCheck.enabled && { - sandbox: { - enabled: true, - autoAllowBashIfSandboxed: true, - }, - }), + allowedTools: [...TOOL_PRESETS.chat], ...claudeMdOptions, ...thinkingOptions, ...(config.abortController && { abortController: config.abortController }), @@ -605,7 +487,6 @@ export function createChatOptions(config: CreateSdkOptionsConfig): Options { * - Full tool access for code modification and implementation * - Extended turns for thorough feature implementation * - Uses default model (can be overridden) - * - Sandbox mode controlled by enableSandboxMode setting (auto-disabled for cloud storage) * - When autoLoadClaudeMd is true, uses preset mode and settingSources for CLAUDE.md loading */ export function createAutoModeOptions(config: CreateSdkOptionsConfig): Options { @@ -621,24 +502,12 @@ export function createAutoModeOptions(config: CreateSdkOptionsConfig): Options { // Build thinking options const thinkingOptions = buildThinkingOptions(config.thinkingLevel); - // Check sandbox compatibility (auto-disables for cloud storage paths) - const sandboxCheck = checkSandboxCompatibility(config.cwd, config.enableSandboxMode); - return { ...getBaseOptions(), model: getModelForUseCase('auto', config.model), maxTurns: MAX_TURNS.maximum, cwd: config.cwd, - // Only restrict tools if no MCP servers configured or unrestricted is disabled - ...(mcpOptions.shouldRestrictTools && { allowedTools: [...TOOL_PRESETS.fullAccess] }), - // Apply MCP bypass options if configured - ...mcpOptions.bypassOptions, - ...(sandboxCheck.enabled && { - sandbox: { - enabled: true, - autoAllowBashIfSandboxed: true, - }, - }), + allowedTools: [...TOOL_PRESETS.fullAccess], ...claudeMdOptions, ...thinkingOptions, ...(config.abortController && { abortController: config.abortController }), @@ -656,7 +525,6 @@ export function createCustomOptions( config: CreateSdkOptionsConfig & { maxTurns?: number; allowedTools?: readonly string[]; - sandbox?: { enabled: boolean; autoAllowBashIfSandboxed?: boolean }; } ): Options { // Validate working directory before creating options @@ -671,22 +539,17 @@ export function createCustomOptions( // Build thinking options const thinkingOptions = buildThinkingOptions(config.thinkingLevel); - // For custom options: use explicit allowedTools if provided, otherwise use preset based on MCP settings + // For custom options: use explicit allowedTools if provided, otherwise default to readOnly const effectiveAllowedTools = config.allowedTools ? [...config.allowedTools] - : mcpOptions.shouldRestrictTools - ? [...TOOL_PRESETS.readOnly] - : undefined; + : [...TOOL_PRESETS.readOnly]; return { ...getBaseOptions(), model: getModelForUseCase('default', config.model), maxTurns: config.maxTurns ?? MAX_TURNS.maximum, cwd: config.cwd, - ...(effectiveAllowedTools && { allowedTools: effectiveAllowedTools }), - ...(config.sandbox && { sandbox: config.sandbox }), - // Apply MCP bypass options if configured - ...mcpOptions.bypassOptions, + allowedTools: effectiveAllowedTools, ...claudeMdOptions, ...thinkingOptions, ...(config.abortController && { abortController: config.abortController }), diff --git a/apps/server/src/lib/settings-helpers.ts b/apps/server/src/lib/settings-helpers.ts index 9a322994a..a56efbc61 100644 --- a/apps/server/src/lib/settings-helpers.ts +++ b/apps/server/src/lib/settings-helpers.ts @@ -55,34 +55,6 @@ export async function getAutoLoadClaudeMdSetting( } } -/** - * Get the enableSandboxMode setting from global settings. - * Returns false if settings service is not available. - * - * @param settingsService - Optional settings service instance - * @param logPrefix - Prefix for log messages (e.g., '[AgentService]') - * @returns Promise resolving to the enableSandboxMode setting value - */ -export async function getEnableSandboxModeSetting( - settingsService?: SettingsService | null, - logPrefix = '[SettingsHelper]' -): Promise { - if (!settingsService) { - logger.info(`${logPrefix} SettingsService not available, sandbox mode disabled`); - return false; - } - - try { - const globalSettings = await settingsService.getGlobalSettings(); - const result = globalSettings.enableSandboxMode ?? false; - logger.info(`${logPrefix} enableSandboxMode from global settings: ${result}`); - return result; - } catch (error) { - logger.error(`${logPrefix} Failed to load enableSandboxMode setting:`, error); - throw error; - } -} - /** * Filters out CLAUDE.md from context files when autoLoadClaudeMd is enabled * and rebuilds the formatted prompt without it. diff --git a/apps/server/src/providers/claude-provider.ts b/apps/server/src/providers/claude-provider.ts index 50e378beb..92b0fdf76 100644 --- a/apps/server/src/providers/claude-provider.ts +++ b/apps/server/src/providers/claude-provider.ts @@ -70,14 +70,6 @@ export class ClaudeProvider extends BaseProvider { const maxThinkingTokens = getThinkingTokenBudget(thinkingLevel); // Build Claude SDK options - // AUTONOMOUS MODE: Always bypass permissions for fully autonomous operation - const hasMcpServers = options.mcpServers && Object.keys(options.mcpServers).length > 0; - const defaultTools = ['Read', 'Write', 'Edit', 'Glob', 'Grep', 'Bash', 'WebSearch', 'WebFetch']; - - // AUTONOMOUS MODE: Always bypass permissions and allow unrestricted tools - // Only restrict tools when no MCP servers are configured - const shouldRestrictTools = !hasMcpServers; - const sdkOptions: Options = { model, systemPrompt, @@ -85,10 +77,9 @@ export class ClaudeProvider extends BaseProvider { cwd, // Pass only explicitly allowed environment variables to SDK env: buildEnv(), - // Only restrict tools if explicitly set OR (no MCP / unrestricted disabled) - ...(allowedTools && shouldRestrictTools && { allowedTools }), - ...(!allowedTools && shouldRestrictTools && { allowedTools: defaultTools }), - // AUTONOMOUS MODE: Always bypass permissions and allow dangerous operations + // Pass through allowedTools if provided by caller (decided by sdk-options.ts) + ...(allowedTools && { allowedTools }), + // AUTONOMOUS MODE: Always bypass permissions for fully autonomous operation permissionMode: 'bypassPermissions', allowDangerouslySkipPermissions: true, abortController, @@ -98,8 +89,6 @@ export class ClaudeProvider extends BaseProvider { : {}), // Forward settingSources for CLAUDE.md file loading ...(options.settingSources && { settingSources: options.settingSources }), - // Forward sandbox configuration - ...(options.sandbox && { sandbox: options.sandbox }), // Forward MCP servers configuration ...(options.mcpServers && { mcpServers: options.mcpServers }), // Extended thinking configuration diff --git a/apps/server/src/providers/codex-provider.ts b/apps/server/src/providers/codex-provider.ts index f4a071d01..dffc850fd 100644 --- a/apps/server/src/providers/codex-provider.ts +++ b/apps/server/src/providers/codex-provider.ts @@ -15,6 +15,7 @@ import { getDataDirectory, getCodexConfigDir, } from '@automaker/platform'; +import { checkCodexAuthentication } from '../lib/codex-auth.js'; import { formatHistoryAsText, extractTextFromContent, @@ -963,11 +964,21 @@ export class CodexProvider extends BaseProvider { } async detectInstallation(): Promise { + console.log('[CodexProvider.detectInstallation] Starting...'); + const cliPath = await findCodexCliPath(); const hasApiKey = !!process.env[OPENAI_API_KEY_ENV]; const authIndicators = await getCodexAuthIndicators(); const installed = !!cliPath; + console.log('[CodexProvider.detectInstallation] cliPath:', cliPath); + console.log('[CodexProvider.detectInstallation] hasApiKey:', hasApiKey); + console.log( + '[CodexProvider.detectInstallation] authIndicators:', + JSON.stringify(authIndicators) + ); + console.log('[CodexProvider.detectInstallation] installed:', installed); + let version = ''; if (installed) { try { @@ -977,19 +988,29 @@ export class CodexProvider extends BaseProvider { cwd: process.cwd(), }); version = result.stdout.trim(); - } catch { + console.log('[CodexProvider.detectInstallation] version:', version); + } catch (error) { + console.log('[CodexProvider.detectInstallation] Error getting version:', error); version = ''; } } - return { + // Determine auth status - always verify with CLI, never assume authenticated + console.log('[CodexProvider.detectInstallation] Calling checkCodexAuthentication...'); + const authCheck = await checkCodexAuthentication(cliPath); + console.log('[CodexProvider.detectInstallation] authCheck result:', JSON.stringify(authCheck)); + const authenticated = authCheck.authenticated; + + const result = { installed, path: cliPath || undefined, version: version || undefined, - method: 'cli', + method: 'cli' as const, // Installation method hasApiKey, - authenticated: authIndicators.hasOAuthToken || authIndicators.hasApiKey || hasApiKey, + authenticated, }; + console.log('[CodexProvider.detectInstallation] Final result:', JSON.stringify(result)); + return result; } getAvailableModels(): ModelDefinition[] { @@ -1001,94 +1022,68 @@ export class CodexProvider extends BaseProvider { * Check authentication status for Codex CLI */ async checkAuth(): Promise { + console.log('[CodexProvider.checkAuth] Starting auth check...'); + const cliPath = await findCodexCliPath(); const hasApiKey = !!process.env[OPENAI_API_KEY_ENV]; const authIndicators = await getCodexAuthIndicators(); + console.log('[CodexProvider.checkAuth] cliPath:', cliPath); + console.log('[CodexProvider.checkAuth] hasApiKey:', hasApiKey); + console.log('[CodexProvider.checkAuth] authIndicators:', JSON.stringify(authIndicators)); + // Check for API key in environment if (hasApiKey) { + console.log('[CodexProvider.checkAuth] Has API key, returning authenticated'); return { authenticated: true, method: 'api_key' }; } // Check for OAuth/token from Codex CLI if (authIndicators.hasOAuthToken || authIndicators.hasApiKey) { + console.log( + '[CodexProvider.checkAuth] Has OAuth token or API key in auth file, returning authenticated' + ); return { authenticated: true, method: 'oauth' }; } - // CLI is installed but not authenticated + // CLI is installed but not authenticated via indicators - try CLI command + console.log('[CodexProvider.checkAuth] No indicators found, trying CLI command...'); if (cliPath) { try { + // Try 'codex login status' first (same as checkCodexAuthentication) + console.log('[CodexProvider.checkAuth] Running: ' + cliPath + ' login status'); const result = await spawnProcess({ command: cliPath || CODEX_COMMAND, - args: ['auth', 'status', '--json'], + args: ['login', 'status'], cwd: process.cwd(), + env: { + ...process.env, + TERM: 'dumb', + }, }); - // If auth command succeeds, we're authenticated - if (result.exitCode === 0) { + console.log('[CodexProvider.checkAuth] login status result:'); + console.log('[CodexProvider.checkAuth] exitCode:', result.exitCode); + console.log('[CodexProvider.checkAuth] stdout:', JSON.stringify(result.stdout)); + console.log('[CodexProvider.checkAuth] stderr:', JSON.stringify(result.stderr)); + + // Check both stdout and stderr - Codex CLI outputs to stderr + const combinedOutput = (result.stdout + result.stderr).toLowerCase(); + const isLoggedIn = combinedOutput.includes('logged in'); + console.log('[CodexProvider.checkAuth] isLoggedIn:', isLoggedIn); + + if (result.exitCode === 0 && isLoggedIn) { + console.log('[CodexProvider.checkAuth] CLI says logged in, returning authenticated'); return { authenticated: true, method: 'oauth' }; } - } catch { - // Auth command failed, not authenticated + } catch (error) { + console.log('[CodexProvider.checkAuth] Error running login status:', error); } } + console.log('[CodexProvider.checkAuth] Not authenticated'); return { authenticated: false, method: 'none' }; } - /** - * Deduplicate text blocks in Codex assistant messages - * - * Codex can send: - * 1. Duplicate consecutive text blocks (same text twice in a row) - * 2. A final accumulated block containing ALL previous text - * - * This method filters out these duplicates to prevent UI stuttering. - */ - private deduplicateTextBlocks( - content: Array<{ type: string; text?: string }>, - lastTextBlock: string, - accumulatedText: string - ): { content: Array<{ type: string; text?: string }>; lastBlock: string; accumulated: string } { - const filtered: Array<{ type: string; text?: string }> = []; - let newLastBlock = lastTextBlock; - let newAccumulated = accumulatedText; - - for (const block of content) { - if (block.type !== 'text' || !block.text) { - filtered.push(block); - continue; - } - - const text = block.text; - - // Skip empty text - if (!text.trim()) continue; - - // Skip duplicate consecutive text blocks - if (text === newLastBlock) { - continue; - } - - // Skip final accumulated text block - // Codex sends one large block containing ALL previous text at the end - if (newAccumulated.length > 100 && text.length > newAccumulated.length * 0.8) { - const normalizedAccum = newAccumulated.replace(/\s+/g, ' ').trim(); - const normalizedNew = text.replace(/\s+/g, ' ').trim(); - if (normalizedNew.includes(normalizedAccum.slice(0, 100))) { - // This is the final accumulated block, skip it - continue; - } - } - - // This is a valid new text block - newLastBlock = text; - newAccumulated += text; - filtered.push(block); - } - - return { content: filtered, lastBlock: newLastBlock, accumulated: newAccumulated }; - } - /** * Get the detected CLI path (public accessor for status endpoints) */ diff --git a/apps/server/src/routes/auth/index.ts b/apps/server/src/routes/auth/index.ts index 575000a87..e4ff2c453 100644 --- a/apps/server/src/routes/auth/index.ts +++ b/apps/server/src/routes/auth/index.ts @@ -229,12 +229,13 @@ export function createAuthRoutes(): Router { await invalidateSession(sessionToken); } - // Clear the cookie - res.clearCookie(cookieName, { - httpOnly: true, - secure: process.env.NODE_ENV === 'production', - sameSite: 'strict', - path: '/', + // Clear the cookie by setting it to empty with immediate expiration + // Using res.cookie() with maxAge: 0 is more reliable than clearCookie() + // in cross-origin development environments + res.cookie(cookieName, '', { + ...getSessionCookieOptions(), + maxAge: 0, + expires: new Date(0), }); res.json({ diff --git a/apps/server/src/routes/auto-mode/routes/follow-up-feature.ts b/apps/server/src/routes/auto-mode/routes/follow-up-feature.ts index 1ed14c39c..bd9c480d0 100644 --- a/apps/server/src/routes/auto-mode/routes/follow-up-feature.ts +++ b/apps/server/src/routes/auto-mode/routes/follow-up-feature.ts @@ -31,7 +31,9 @@ export function createFollowUpFeatureHandler(autoModeService: AutoModeService) { // Start follow-up in background // followUpFeature derives workDir from feature.branchName autoModeService - .followUpFeature(projectPath, featureId, prompt, imagePaths, useWorktrees ?? true) + // Default to false to match run-feature/resume-feature behavior. + // Worktrees should only be used when explicitly enabled by the user. + .followUpFeature(projectPath, featureId, prompt, imagePaths, useWorktrees ?? false) .catch((error) => { logger.error(`[AutoMode] Follow up feature ${featureId} error:`, error); }) diff --git a/apps/server/src/routes/claude/index.ts b/apps/server/src/routes/claude/index.ts index 239499f90..20816bbc6 100644 --- a/apps/server/src/routes/claude/index.ts +++ b/apps/server/src/routes/claude/index.ts @@ -13,7 +13,10 @@ export function createClaudeRoutes(service: ClaudeUsageService): Router { // Check if Claude CLI is available first const isAvailable = await service.isAvailable(); if (!isAvailable) { - res.status(503).json({ + // IMPORTANT: This endpoint is behind Automaker session auth already. + // Use a 200 + error payload for Claude CLI issues so the UI doesn't + // interpret it as an invalid Automaker session (401/403 triggers logout). + res.status(200).json({ error: 'Claude CLI not found', message: "Please install Claude Code CLI and run 'claude login' to authenticate", }); @@ -26,12 +29,13 @@ export function createClaudeRoutes(service: ClaudeUsageService): Router { const message = error instanceof Error ? error.message : 'Unknown error'; if (message.includes('Authentication required') || message.includes('token_expired')) { - res.status(401).json({ + // Do NOT use 401/403 here: that status code is reserved for Automaker session auth. + res.status(200).json({ error: 'Authentication required', message: "Please run 'claude login' to authenticate", }); } else if (message.includes('timed out')) { - res.status(504).json({ + res.status(200).json({ error: 'Command timed out', message: 'The Claude CLI took too long to respond', }); diff --git a/apps/server/src/routes/codex/index.ts b/apps/server/src/routes/codex/index.ts index 34412256a..4a2db951b 100644 --- a/apps/server/src/routes/codex/index.ts +++ b/apps/server/src/routes/codex/index.ts @@ -13,7 +13,10 @@ export function createCodexRoutes(service: CodexUsageService): Router { // Check if Codex CLI is available first const isAvailable = await service.isAvailable(); if (!isAvailable) { - res.status(503).json({ + // IMPORTANT: This endpoint is behind Automaker session auth already. + // Use a 200 + error payload for Codex CLI issues so the UI doesn't + // interpret it as an invalid Automaker session (401/403 triggers logout). + res.status(200).json({ error: 'Codex CLI not found', message: "Please install Codex CLI and run 'codex login' to authenticate", }); @@ -26,18 +29,19 @@ export function createCodexRoutes(service: CodexUsageService): Router { const message = error instanceof Error ? error.message : 'Unknown error'; if (message.includes('not authenticated') || message.includes('login')) { - res.status(401).json({ + // Do NOT use 401/403 here: that status code is reserved for Automaker session auth. + res.status(200).json({ error: 'Authentication required', message: "Please run 'codex login' to authenticate", }); } else if (message.includes('not available') || message.includes('does not provide')) { // This is the expected case - Codex doesn't provide usage stats - res.status(503).json({ + res.status(200).json({ error: 'Usage statistics not available', message: message, }); } else if (message.includes('timed out')) { - res.status(504).json({ + res.status(200).json({ error: 'Command timed out', message: 'The Codex CLI took too long to respond', }); diff --git a/apps/server/src/routes/context/routes/describe-file.ts b/apps/server/src/routes/context/routes/describe-file.ts index 8ecb60fd0..60c115bbe 100644 --- a/apps/server/src/routes/context/routes/describe-file.ts +++ b/apps/server/src/routes/context/routes/describe-file.ts @@ -232,7 +232,6 @@ File: ${fileName}${truncated ? ' (truncated)' : ''}`; maxTurns: 1, allowedTools: [], autoLoadClaudeMd, - sandbox: { enabled: true, autoAllowBashIfSandboxed: true }, thinkingLevel, // Pass thinking level for extended thinking }); diff --git a/apps/server/src/routes/context/routes/describe-image.ts b/apps/server/src/routes/context/routes/describe-image.ts index 4b4c281da..bd288cc04 100644 --- a/apps/server/src/routes/context/routes/describe-image.ts +++ b/apps/server/src/routes/context/routes/describe-image.ts @@ -394,14 +394,13 @@ export function createDescribeImageHandler( maxTurns: 1, allowedTools: [], autoLoadClaudeMd, - sandbox: { enabled: true, autoAllowBashIfSandboxed: true }, thinkingLevel, // Pass thinking level for extended thinking }); logger.info( `[${requestId}] SDK options model=${sdkOptions.model} maxTurns=${sdkOptions.maxTurns} allowedTools=${JSON.stringify( sdkOptions.allowedTools - )} sandbox=${JSON.stringify(sdkOptions.sandbox)}` + )}` ); const promptGenerator = (async function* () { diff --git a/apps/server/src/routes/features/routes/update.ts b/apps/server/src/routes/features/routes/update.ts index 830fb21a2..2e960a625 100644 --- a/apps/server/src/routes/features/routes/update.ts +++ b/apps/server/src/routes/features/routes/update.ts @@ -10,11 +10,14 @@ import { getErrorMessage, logError } from '../common.js'; export function createUpdateHandler(featureLoader: FeatureLoader) { return async (req: Request, res: Response): Promise => { try { - const { projectPath, featureId, updates } = req.body as { - projectPath: string; - featureId: string; - updates: Partial; - }; + const { projectPath, featureId, updates, descriptionHistorySource, enhancementMode } = + req.body as { + projectPath: string; + featureId: string; + updates: Partial; + descriptionHistorySource?: 'enhance' | 'edit'; + enhancementMode?: 'improve' | 'technical' | 'simplify' | 'acceptance'; + }; if (!projectPath || !featureId || !updates) { res.status(400).json({ @@ -24,7 +27,13 @@ export function createUpdateHandler(featureLoader: FeatureLoader) { return; } - const updated = await featureLoader.update(projectPath, featureId, updates); + const updated = await featureLoader.update( + projectPath, + featureId, + updates, + descriptionHistorySource, + enhancementMode + ); res.json({ success: true, feature: updated }); } catch (error) { logError(error, 'Update feature failed'); diff --git a/apps/server/src/routes/settings/routes/update-global.ts b/apps/server/src/routes/settings/routes/update-global.ts index 6072f2372..aafbc5b1b 100644 --- a/apps/server/src/routes/settings/routes/update-global.ts +++ b/apps/server/src/routes/settings/routes/update-global.ts @@ -11,7 +11,7 @@ import type { Request, Response } from 'express'; import type { SettingsService } from '../../../services/settings-service.js'; import type { GlobalSettings } from '../../../types/settings.js'; -import { getErrorMessage, logError } from '../common.js'; +import { getErrorMessage, logError, logger } from '../common.js'; /** * Create handler factory for PUT /api/settings/global @@ -32,6 +32,18 @@ export function createUpdateGlobalHandler(settingsService: SettingsService) { return; } + // Minimal debug logging to help diagnose accidental wipes. + if ('projects' in updates || 'theme' in updates || 'localStorageMigrated' in updates) { + const projectsLen = Array.isArray((updates as any).projects) + ? (updates as any).projects.length + : undefined; + logger.info( + `Update global settings request: projects=${projectsLen ?? 'n/a'}, theme=${ + (updates as any).theme ?? 'n/a' + }, localStorageMigrated=${(updates as any).localStorageMigrated ?? 'n/a'}` + ); + } + const settings = await settingsService.updateGlobalSettings(updates); res.json({ diff --git a/apps/server/src/routes/setup/routes/codex-status.ts b/apps/server/src/routes/setup/routes/codex-status.ts index fee782da8..84f2c3f40 100644 --- a/apps/server/src/routes/setup/routes/codex-status.ts +++ b/apps/server/src/routes/setup/routes/codex-status.ts @@ -19,6 +19,12 @@ export function createCodexStatusHandler() { const provider = new CodexProvider(); const status = await provider.detectInstallation(); + // Derive auth method from authenticated status and API key presence + let authMethod = 'none'; + if (status.authenticated) { + authMethod = status.hasApiKey ? 'api_key_env' : 'cli_authenticated'; + } + res.json({ success: true, installed: status.installed, @@ -26,7 +32,7 @@ export function createCodexStatusHandler() { path: status.path || null, auth: { authenticated: status.authenticated || false, - method: status.method || 'cli', + method: authMethod, hasApiKey: status.hasApiKey || false, }, installCommand, diff --git a/apps/server/src/routes/worktree/routes/diffs.ts b/apps/server/src/routes/worktree/routes/diffs.ts index 801dd5148..75f43d7f5 100644 --- a/apps/server/src/routes/worktree/routes/diffs.ts +++ b/apps/server/src/routes/worktree/routes/diffs.ts @@ -11,9 +11,10 @@ import { getGitRepositoryDiffs } from '../../common.js'; export function createDiffsHandler() { return async (req: Request, res: Response): Promise => { try { - const { projectPath, featureId } = req.body as { + const { projectPath, featureId, useWorktrees } = req.body as { projectPath: string; featureId: string; + useWorktrees?: boolean; }; if (!projectPath || !featureId) { @@ -24,6 +25,19 @@ export function createDiffsHandler() { return; } + // If worktrees aren't enabled, don't probe .worktrees at all. + // This avoids noisy logs that make it look like features are "running in worktrees". + if (useWorktrees === false) { + const result = await getGitRepositoryDiffs(projectPath); + res.json({ + success: true, + diff: result.diff, + files: result.files, + hasChanges: result.hasChanges, + }); + return; + } + // Git worktrees are stored in project directory const worktreePath = path.join(projectPath, '.worktrees', featureId); @@ -41,7 +55,11 @@ export function createDiffsHandler() { }); } catch (innerError) { // Worktree doesn't exist - fallback to main project path - logError(innerError, 'Worktree access failed, falling back to main project'); + const code = (innerError as NodeJS.ErrnoException | undefined)?.code; + // ENOENT is expected when a feature has no worktree; don't log as an error. + if (code && code !== 'ENOENT') { + logError(innerError, 'Worktree access failed, falling back to main project'); + } try { const result = await getGitRepositoryDiffs(projectPath); diff --git a/apps/server/src/routes/worktree/routes/file-diff.ts b/apps/server/src/routes/worktree/routes/file-diff.ts index 82ed79bd1..4d29eb26b 100644 --- a/apps/server/src/routes/worktree/routes/file-diff.ts +++ b/apps/server/src/routes/worktree/routes/file-diff.ts @@ -15,10 +15,11 @@ const execAsync = promisify(exec); export function createFileDiffHandler() { return async (req: Request, res: Response): Promise => { try { - const { projectPath, featureId, filePath } = req.body as { + const { projectPath, featureId, filePath, useWorktrees } = req.body as { projectPath: string; featureId: string; filePath: string; + useWorktrees?: boolean; }; if (!projectPath || !featureId || !filePath) { @@ -29,6 +30,12 @@ export function createFileDiffHandler() { return; } + // If worktrees aren't enabled, don't probe .worktrees at all. + if (useWorktrees === false) { + res.json({ success: true, diff: '', filePath }); + return; + } + // Git worktrees are stored in project directory const worktreePath = path.join(projectPath, '.worktrees', featureId); @@ -57,7 +64,11 @@ export function createFileDiffHandler() { res.json({ success: true, diff, filePath }); } catch (innerError) { - logError(innerError, 'Worktree file diff failed'); + const code = (innerError as NodeJS.ErrnoException | undefined)?.code; + // ENOENT is expected when a feature has no worktree; don't log as an error. + if (code && code !== 'ENOENT') { + logError(innerError, 'Worktree file diff failed'); + } res.json({ success: true, diff: '', filePath }); } } catch (error) { diff --git a/apps/server/src/services/agent-service.ts b/apps/server/src/services/agent-service.ts index 1a45c1ade..3fdbd6a6f 100644 --- a/apps/server/src/services/agent-service.ts +++ b/apps/server/src/services/agent-service.ts @@ -22,7 +22,6 @@ import { PathNotAllowedError } from '@automaker/platform'; import type { SettingsService } from './settings-service.js'; import { getAutoLoadClaudeMdSetting, - getEnableSandboxModeSetting, filterClaudeMdFromContext, getMCPServersFromSettings, getPromptCustomization, @@ -246,12 +245,6 @@ export class AgentService { '[AgentService]' ); - // Load enableSandboxMode setting (global setting only) - const enableSandboxMode = await getEnableSandboxModeSetting( - this.settingsService, - '[AgentService]' - ); - // Load MCP servers from settings (global setting only) const mcpServers = await getMCPServersFromSettings(this.settingsService, '[AgentService]'); @@ -281,7 +274,6 @@ export class AgentService { systemPrompt: combinedSystemPrompt, abortController: session.abortController!, autoLoadClaudeMd, - enableSandboxMode, thinkingLevel: effectiveThinkingLevel, // Pass thinking level for Claude models mcpServers: Object.keys(mcpServers).length > 0 ? mcpServers : undefined, }); @@ -305,7 +297,6 @@ export class AgentService { abortController: session.abortController!, conversationHistory: conversationHistory.length > 0 ? conversationHistory : undefined, settingSources: sdkOptions.settingSources, - sandbox: sdkOptions.sandbox, // Pass sandbox configuration sdkSessionId: session.sdkSessionId, // Pass SDK session ID for resuming mcpServers: Object.keys(mcpServers).length > 0 ? mcpServers : undefined, // Pass MCP servers configuration }; diff --git a/apps/server/src/services/auto-mode-service.ts b/apps/server/src/services/auto-mode-service.ts index 992dda10d..302d773c5 100644 --- a/apps/server/src/services/auto-mode-service.ts +++ b/apps/server/src/services/auto-mode-service.ts @@ -47,7 +47,6 @@ import type { SettingsService } from './settings-service.js'; import { pipelineService, PipelineService } from './pipeline-service.js'; import { getAutoLoadClaudeMdSetting, - getEnableSandboxModeSetting, filterClaudeMdFromContext, getMCPServersFromSettings, getPromptCustomization, @@ -1314,7 +1313,6 @@ Format your response as a structured markdown document.`; allowedTools: sdkOptions.allowedTools as string[], abortController, settingSources: sdkOptions.settingSources, - sandbox: sdkOptions.sandbox, // Pass sandbox configuration thinkingLevel: analysisThinkingLevel, // Pass thinking level }; @@ -1784,9 +1782,13 @@ Format your response as a structured markdown document.`; // Apply dependency-aware ordering const { orderedFeatures } = resolveDependencies(pendingFeatures); + // Get skipVerificationInAutoMode setting + const settings = await this.settingsService?.getGlobalSettings(); + const skipVerification = settings?.skipVerificationInAutoMode ?? false; + // Filter to only features with satisfied dependencies const readyFeatures = orderedFeatures.filter((feature: Feature) => - areDependenciesSatisfied(feature, allFeatures) + areDependenciesSatisfied(feature, allFeatures, { skipVerification }) ); return readyFeatures; @@ -2074,9 +2076,6 @@ This mock response was generated because AUTOMAKER_MOCK_AGENT=true was set. ? options.autoLoadClaudeMd : await getAutoLoadClaudeMdSetting(finalProjectPath, this.settingsService, '[AutoMode]'); - // Load enableSandboxMode setting (global setting only) - const enableSandboxMode = await getEnableSandboxModeSetting(this.settingsService, '[AutoMode]'); - // Load MCP servers from settings (global setting only) const mcpServers = await getMCPServersFromSettings(this.settingsService, '[AutoMode]'); @@ -2088,7 +2087,6 @@ This mock response was generated because AUTOMAKER_MOCK_AGENT=true was set. model: model, abortController, autoLoadClaudeMd, - enableSandboxMode, mcpServers: Object.keys(mcpServers).length > 0 ? mcpServers : undefined, thinkingLevel: options?.thinkingLevel, }); @@ -2131,7 +2129,6 @@ This mock response was generated because AUTOMAKER_MOCK_AGENT=true was set. abortController, systemPrompt: sdkOptions.systemPrompt, settingSources: sdkOptions.settingSources, - sandbox: sdkOptions.sandbox, // Pass sandbox configuration mcpServers: Object.keys(mcpServers).length > 0 ? mcpServers : undefined, // Pass MCP servers configuration thinkingLevel: options?.thinkingLevel, // Pass thinking level for extended thinking }; @@ -2214,9 +2211,23 @@ This mock response was generated because AUTOMAKER_MOCK_AGENT=true was set. }, WRITE_DEBOUNCE_MS); }; + // Heartbeat logging so "silent" model calls are visible. + // Some runs can take a while before the first streamed message arrives. + const streamStartTime = Date.now(); + let receivedAnyStreamMessage = false; + const STREAM_HEARTBEAT_MS = 15_000; + const streamHeartbeat = setInterval(() => { + if (receivedAnyStreamMessage) return; + const elapsedSeconds = Math.round((Date.now() - streamStartTime) / 1000); + logger.info( + `Waiting for first model response for feature ${featureId} (${elapsedSeconds}s elapsed)...` + ); + }, STREAM_HEARTBEAT_MS); + // Wrap stream processing in try/finally to ensure timeout cleanup on any error/abort try { streamLoop: for await (const msg of stream) { + receivedAnyStreamMessage = true; // Log raw stream event for debugging appendRawEvent(msg); @@ -2733,6 +2744,7 @@ Implement all the changes described in the plan above.`; } } } finally { + clearInterval(streamHeartbeat); // ALWAYS clear pending timeouts to prevent memory leaks // This runs on success, error, or abort if (writeTimeout) { diff --git a/apps/server/src/services/codex-usage-service.ts b/apps/server/src/services/codex-usage-service.ts index 3697f5c96..6af128806 100644 --- a/apps/server/src/services/codex-usage-service.ts +++ b/apps/server/src/services/codex-usage-service.ts @@ -1,5 +1,6 @@ -import { spawn } from 'child_process'; import * as os from 'os'; +import { findCodexCliPath } from '@automaker/platform'; +import { checkCodexAuthentication } from '../lib/codex-auth.js'; export interface CodexRateLimitWindow { limit: number; @@ -40,21 +41,16 @@ export interface CodexUsageData { export class CodexUsageService { private codexBinary = 'codex'; private isWindows = os.platform() === 'win32'; + private cachedCliPath: string | null = null; /** * Check if Codex CLI is available on the system */ async isAvailable(): Promise { - return new Promise((resolve) => { - const checkCmd = this.isWindows ? 'where' : 'which'; - const proc = spawn(checkCmd, [this.codexBinary]); - proc.on('close', (code) => { - resolve(code === 0); - }); - proc.on('error', () => { - resolve(false); - }); - }); + // Prefer our platform-aware resolver over `which/where` because the server + // process PATH may not include npm global bins (nvm/fnm/volta/pnpm). + this.cachedCliPath = await findCodexCliPath(); + return Boolean(this.cachedCliPath); } /** @@ -84,29 +80,9 @@ export class CodexUsageService { * Check if Codex is authenticated */ private async checkAuthentication(): Promise { - return new Promise((resolve) => { - const proc = spawn(this.codexBinary, ['login', 'status'], { - env: { - ...process.env, - TERM: 'dumb', // Avoid interactive output - }, - }); - - let output = ''; - - proc.stdout.on('data', (data) => { - output += data.toString(); - }); - - proc.on('close', (code) => { - // Check if output indicates logged in - const isLoggedIn = output.toLowerCase().includes('logged in'); - resolve(code === 0 && isLoggedIn); - }); - - proc.on('error', () => { - resolve(false); - }); - }); + // Use the cached CLI path if available, otherwise fall back to finding it + const cliPath = this.cachedCliPath || (await findCodexCliPath()); + const authCheck = await checkCodexAuthentication(cliPath); + return authCheck.authenticated; } } diff --git a/apps/server/src/services/feature-loader.ts b/apps/server/src/services/feature-loader.ts index 562ccc669..93cff796a 100644 --- a/apps/server/src/services/feature-loader.ts +++ b/apps/server/src/services/feature-loader.ts @@ -4,7 +4,7 @@ */ import path from 'path'; -import type { Feature } from '@automaker/types'; +import type { Feature, DescriptionHistoryEntry } from '@automaker/types'; import { createLogger } from '@automaker/utils'; import * as secureFs from '../lib/secure-fs.js'; import { @@ -274,6 +274,16 @@ export class FeatureLoader { featureData.imagePaths ); + // Initialize description history with the initial description + const initialHistory: DescriptionHistoryEntry[] = []; + if (featureData.description && featureData.description.trim()) { + initialHistory.push({ + description: featureData.description, + timestamp: new Date().toISOString(), + source: 'initial', + }); + } + // Ensure feature has required fields const feature: Feature = { category: featureData.category || 'Uncategorized', @@ -281,6 +291,7 @@ export class FeatureLoader { ...featureData, id: featureId, imagePaths: migratedImagePaths, + descriptionHistory: initialHistory, }; // Write feature.json @@ -292,11 +303,18 @@ export class FeatureLoader { /** * Update a feature (partial updates supported) + * @param projectPath - Path to the project + * @param featureId - ID of the feature to update + * @param updates - Partial feature updates + * @param descriptionHistorySource - Source of description change ('enhance' or 'edit') + * @param enhancementMode - Enhancement mode if source is 'enhance' */ async update( projectPath: string, featureId: string, - updates: Partial + updates: Partial, + descriptionHistorySource?: 'enhance' | 'edit', + enhancementMode?: 'improve' | 'technical' | 'simplify' | 'acceptance' ): Promise { const feature = await this.get(projectPath, featureId); if (!feature) { @@ -313,11 +331,28 @@ export class FeatureLoader { updatedImagePaths = await this.migrateImages(projectPath, featureId, updates.imagePaths); } + // Track description history if description changed + let updatedHistory = feature.descriptionHistory || []; + if ( + updates.description !== undefined && + updates.description !== feature.description && + updates.description.trim() + ) { + const historyEntry: DescriptionHistoryEntry = { + description: updates.description, + timestamp: new Date().toISOString(), + source: descriptionHistorySource || 'edit', + ...(descriptionHistorySource === 'enhance' && enhancementMode ? { enhancementMode } : {}), + }; + updatedHistory = [...updatedHistory, historyEntry]; + } + // Merge updates const updatedFeature: Feature = { ...feature, ...updates, ...(updatedImagePaths !== undefined ? { imagePaths: updatedImagePaths } : {}), + descriptionHistory: updatedHistory, }; // Write back to file diff --git a/apps/server/src/services/settings-service.ts b/apps/server/src/services/settings-service.ts index 94bdce249..151546553 100644 --- a/apps/server/src/services/settings-service.ts +++ b/apps/server/src/services/settings-service.ts @@ -153,14 +153,6 @@ export class SettingsService { const storedVersion = settings.version || 1; let needsSave = false; - // Migration v1 -> v2: Force enableSandboxMode to false for existing users - // Sandbox mode can cause issues on some systems, so we're disabling it by default - if (storedVersion < 2) { - logger.info('Migrating settings from v1 to v2: disabling sandbox mode'); - result.enableSandboxMode = false; - needsSave = true; - } - // Migration v2 -> v3: Convert string phase models to PhaseModelEntry objects // Note: migratePhaseModels() handles the actual conversion for both v1 and v2 formats if (storedVersion < 3) { @@ -170,6 +162,16 @@ export class SettingsService { needsSave = true; } + // Migration v3 -> v4: Add onboarding/setup wizard state fields + // Older settings files never stored setup state in settings.json (it lived in localStorage), + // so default to "setup complete" for existing installs to avoid forcing re-onboarding. + if (storedVersion < 4) { + if (settings.setupComplete === undefined) result.setupComplete = true; + if (settings.isFirstRun === undefined) result.isFirstRun = false; + if (settings.skipClaudeSetup === undefined) result.skipClaudeSetup = false; + needsSave = true; + } + // Update version if any migration occurred if (needsSave) { result.version = SETTINGS_VERSION; @@ -264,25 +266,79 @@ export class SettingsService { const settingsPath = getGlobalSettingsPath(this.dataDir); const current = await this.getGlobalSettings(); + + // Guard against destructive "empty array/object" overwrites. + // During auth transitions, the UI can briefly have default/empty state and accidentally + // sync it, wiping persisted settings (especially `projects`). + const sanitizedUpdates: Partial = { ...updates }; + let attemptedProjectWipe = false; + + const ignoreEmptyArrayOverwrite = (key: K): void => { + const nextVal = sanitizedUpdates[key] as unknown; + const curVal = current[key] as unknown; + if ( + Array.isArray(nextVal) && + nextVal.length === 0 && + Array.isArray(curVal) && + curVal.length > 0 + ) { + delete sanitizedUpdates[key]; + } + }; + + const currentProjectsLen = Array.isArray(current.projects) ? current.projects.length : 0; + if ( + Array.isArray(sanitizedUpdates.projects) && + sanitizedUpdates.projects.length === 0 && + currentProjectsLen > 0 + ) { + attemptedProjectWipe = true; + delete sanitizedUpdates.projects; + } + + ignoreEmptyArrayOverwrite('trashedProjects'); + ignoreEmptyArrayOverwrite('projectHistory'); + ignoreEmptyArrayOverwrite('recentFolders'); + ignoreEmptyArrayOverwrite('aiProfiles'); + ignoreEmptyArrayOverwrite('mcpServers'); + ignoreEmptyArrayOverwrite('enabledCursorModels'); + + // Empty object overwrite guard + if ( + sanitizedUpdates.lastSelectedSessionByProject && + typeof sanitizedUpdates.lastSelectedSessionByProject === 'object' && + !Array.isArray(sanitizedUpdates.lastSelectedSessionByProject) && + Object.keys(sanitizedUpdates.lastSelectedSessionByProject).length === 0 && + current.lastSelectedSessionByProject && + Object.keys(current.lastSelectedSessionByProject).length > 0 + ) { + delete sanitizedUpdates.lastSelectedSessionByProject; + } + + // If a request attempted to wipe projects, also ignore theme changes in that same request. + if (attemptedProjectWipe) { + delete sanitizedUpdates.theme; + } + const updated: GlobalSettings = { ...current, - ...updates, + ...sanitizedUpdates, version: SETTINGS_VERSION, }; // Deep merge keyboard shortcuts if provided - if (updates.keyboardShortcuts) { + if (sanitizedUpdates.keyboardShortcuts) { updated.keyboardShortcuts = { ...current.keyboardShortcuts, - ...updates.keyboardShortcuts, + ...sanitizedUpdates.keyboardShortcuts, }; } // Deep merge phaseModels if provided - if (updates.phaseModels) { + if (sanitizedUpdates.phaseModels) { updated.phaseModels = { ...current.phaseModels, - ...updates.phaseModels, + ...sanitizedUpdates.phaseModels, }; } @@ -523,8 +579,26 @@ export class SettingsService { } } + // Parse setup wizard state (previously stored in localStorage) + let setupState: Record = {}; + if (localStorageData['automaker-setup']) { + try { + const parsed = JSON.parse(localStorageData['automaker-setup']); + setupState = parsed.state || parsed; + } catch (e) { + errors.push(`Failed to parse automaker-setup: ${e}`); + } + } + // Extract global settings const globalSettings: Partial = { + setupComplete: + setupState.setupComplete !== undefined ? (setupState.setupComplete as boolean) : false, + isFirstRun: setupState.isFirstRun !== undefined ? (setupState.isFirstRun as boolean) : true, + skipClaudeSetup: + setupState.skipClaudeSetup !== undefined + ? (setupState.skipClaudeSetup as boolean) + : false, theme: (appState.theme as GlobalSettings['theme']) || 'dark', sidebarOpen: appState.sidebarOpen !== undefined ? (appState.sidebarOpen as boolean) : true, chatHistoryOpen: (appState.chatHistoryOpen as boolean) || false, @@ -537,6 +611,10 @@ export class SettingsService { appState.enableDependencyBlocking !== undefined ? (appState.enableDependencyBlocking as boolean) : true, + skipVerificationInAutoMode: + appState.skipVerificationInAutoMode !== undefined + ? (appState.skipVerificationInAutoMode as boolean) + : false, useWorktrees: (appState.useWorktrees as boolean) || false, showProfilesOnly: (appState.showProfilesOnly as boolean) || false, defaultPlanningMode: diff --git a/apps/server/tests/unit/lib/auth.test.ts b/apps/server/tests/unit/lib/auth.test.ts index 70f50def2..8708062f6 100644 --- a/apps/server/tests/unit/lib/auth.test.ts +++ b/apps/server/tests/unit/lib/auth.test.ts @@ -277,7 +277,7 @@ describe('auth.ts', () => { const options = getSessionCookieOptions(); expect(options.httpOnly).toBe(true); - expect(options.sameSite).toBe('strict'); + expect(options.sameSite).toBe('lax'); expect(options.path).toBe('/'); expect(options.maxAge).toBeGreaterThan(0); }); diff --git a/apps/server/tests/unit/lib/sdk-options.test.ts b/apps/server/tests/unit/lib/sdk-options.test.ts index b442ae1d1..029cd8fa5 100644 --- a/apps/server/tests/unit/lib/sdk-options.test.ts +++ b/apps/server/tests/unit/lib/sdk-options.test.ts @@ -1,161 +1,15 @@ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; -import os from 'os'; describe('sdk-options.ts', () => { let originalEnv: NodeJS.ProcessEnv; - let homedirSpy: ReturnType; beforeEach(() => { originalEnv = { ...process.env }; vi.resetModules(); - // Spy on os.homedir and set default return value - homedirSpy = vi.spyOn(os, 'homedir').mockReturnValue('/Users/test'); }); afterEach(() => { process.env = originalEnv; - homedirSpy.mockRestore(); - }); - - describe('isCloudStoragePath', () => { - it('should detect Dropbox paths on macOS', async () => { - const { isCloudStoragePath } = await import('@/lib/sdk-options.js'); - expect(isCloudStoragePath('/Users/test/Library/CloudStorage/Dropbox-Personal/project')).toBe( - true - ); - expect(isCloudStoragePath('/Users/test/Library/CloudStorage/Dropbox/project')).toBe(true); - }); - - it('should detect Google Drive paths on macOS', async () => { - const { isCloudStoragePath } = await import('@/lib/sdk-options.js'); - expect( - isCloudStoragePath('/Users/test/Library/CloudStorage/GoogleDrive-user@gmail.com/project') - ).toBe(true); - }); - - it('should detect OneDrive paths on macOS', async () => { - const { isCloudStoragePath } = await import('@/lib/sdk-options.js'); - expect(isCloudStoragePath('/Users/test/Library/CloudStorage/OneDrive-Personal/project')).toBe( - true - ); - }); - - it('should detect iCloud Drive paths on macOS', async () => { - const { isCloudStoragePath } = await import('@/lib/sdk-options.js'); - expect( - isCloudStoragePath('/Users/test/Library/Mobile Documents/com~apple~CloudDocs/project') - ).toBe(true); - }); - - it('should detect home-anchored Dropbox paths', async () => { - const { isCloudStoragePath } = await import('@/lib/sdk-options.js'); - expect(isCloudStoragePath('/Users/test/Dropbox')).toBe(true); - expect(isCloudStoragePath('/Users/test/Dropbox/project')).toBe(true); - expect(isCloudStoragePath('/Users/test/Dropbox/nested/deep/project')).toBe(true); - }); - - it('should detect home-anchored Google Drive paths', async () => { - const { isCloudStoragePath } = await import('@/lib/sdk-options.js'); - expect(isCloudStoragePath('/Users/test/Google Drive')).toBe(true); - expect(isCloudStoragePath('/Users/test/Google Drive/project')).toBe(true); - }); - - it('should detect home-anchored OneDrive paths', async () => { - const { isCloudStoragePath } = await import('@/lib/sdk-options.js'); - expect(isCloudStoragePath('/Users/test/OneDrive')).toBe(true); - expect(isCloudStoragePath('/Users/test/OneDrive/project')).toBe(true); - }); - - it('should return false for local paths', async () => { - const { isCloudStoragePath } = await import('@/lib/sdk-options.js'); - expect(isCloudStoragePath('/Users/test/projects/myapp')).toBe(false); - expect(isCloudStoragePath('/home/user/code/project')).toBe(false); - expect(isCloudStoragePath('/var/www/app')).toBe(false); - }); - - it('should return false for relative paths not in cloud storage', async () => { - const { isCloudStoragePath } = await import('@/lib/sdk-options.js'); - expect(isCloudStoragePath('./project')).toBe(false); - expect(isCloudStoragePath('../other-project')).toBe(false); - }); - - // Tests for false positive prevention - paths that contain cloud storage names but aren't cloud storage - it('should NOT flag paths that merely contain "dropbox" in the name', async () => { - const { isCloudStoragePath } = await import('@/lib/sdk-options.js'); - // Projects with dropbox-like names - expect(isCloudStoragePath('/home/user/my-project-about-dropbox')).toBe(false); - expect(isCloudStoragePath('/Users/test/projects/dropbox-clone')).toBe(false); - expect(isCloudStoragePath('/Users/test/projects/Dropbox-backup-tool')).toBe(false); - // Dropbox folder that's NOT in the home directory - expect(isCloudStoragePath('/var/shared/Dropbox/project')).toBe(false); - }); - - it('should NOT flag paths that merely contain "Google Drive" in the name', async () => { - const { isCloudStoragePath } = await import('@/lib/sdk-options.js'); - expect(isCloudStoragePath('/Users/test/projects/google-drive-api-client')).toBe(false); - expect(isCloudStoragePath('/home/user/Google Drive API Tests')).toBe(false); - }); - - it('should NOT flag paths that merely contain "OneDrive" in the name', async () => { - const { isCloudStoragePath } = await import('@/lib/sdk-options.js'); - expect(isCloudStoragePath('/Users/test/projects/onedrive-sync-tool')).toBe(false); - expect(isCloudStoragePath('/home/user/OneDrive-migration-scripts')).toBe(false); - }); - - it('should handle different home directories correctly', async () => { - // Change the mocked home directory - homedirSpy.mockReturnValue('/home/linuxuser'); - const { isCloudStoragePath } = await import('@/lib/sdk-options.js'); - - // Should detect Dropbox under the Linux home directory - expect(isCloudStoragePath('/home/linuxuser/Dropbox/project')).toBe(true); - // Should NOT detect Dropbox under the old home directory (since home changed) - expect(isCloudStoragePath('/Users/test/Dropbox/project')).toBe(false); - }); - }); - - describe('checkSandboxCompatibility', () => { - it('should return enabled=false when user disables sandbox', async () => { - const { checkSandboxCompatibility } = await import('@/lib/sdk-options.js'); - const result = checkSandboxCompatibility('/Users/test/project', false); - expect(result.enabled).toBe(false); - expect(result.disabledReason).toBe('user_setting'); - }); - - it('should return enabled=false for cloud storage paths even when sandbox enabled', async () => { - const { checkSandboxCompatibility } = await import('@/lib/sdk-options.js'); - const result = checkSandboxCompatibility( - '/Users/test/Library/CloudStorage/Dropbox-Personal/project', - true - ); - expect(result.enabled).toBe(false); - expect(result.disabledReason).toBe('cloud_storage'); - expect(result.message).toContain('cloud storage'); - }); - - it('should return enabled=true for local paths when sandbox enabled', async () => { - const { checkSandboxCompatibility } = await import('@/lib/sdk-options.js'); - const result = checkSandboxCompatibility('/Users/test/projects/myapp', true); - expect(result.enabled).toBe(true); - expect(result.disabledReason).toBeUndefined(); - }); - - it('should return enabled=true when enableSandboxMode is undefined for local paths', async () => { - const { checkSandboxCompatibility } = await import('@/lib/sdk-options.js'); - const result = checkSandboxCompatibility('/Users/test/project', undefined); - expect(result.enabled).toBe(true); - expect(result.disabledReason).toBeUndefined(); - }); - - it('should return enabled=false for cloud storage paths when enableSandboxMode is undefined', async () => { - const { checkSandboxCompatibility } = await import('@/lib/sdk-options.js'); - const result = checkSandboxCompatibility( - '/Users/test/Library/CloudStorage/Dropbox-Personal/project', - undefined - ); - expect(result.enabled).toBe(false); - expect(result.disabledReason).toBe('cloud_storage'); - }); }); describe('TOOL_PRESETS', () => { @@ -325,19 +179,15 @@ describe('sdk-options.ts', () => { it('should create options with chat settings', async () => { const { createChatOptions, TOOL_PRESETS, MAX_TURNS } = await import('@/lib/sdk-options.js'); - const options = createChatOptions({ cwd: '/test/path', enableSandboxMode: true }); + const options = createChatOptions({ cwd: '/test/path' }); expect(options.cwd).toBe('/test/path'); expect(options.maxTurns).toBe(MAX_TURNS.standard); expect(options.allowedTools).toEqual([...TOOL_PRESETS.chat]); - expect(options.sandbox).toEqual({ - enabled: true, - autoAllowBashIfSandboxed: true, - }); }); it('should prefer explicit model over session model', async () => { - const { createChatOptions, getModelForUseCase } = await import('@/lib/sdk-options.js'); + const { createChatOptions } = await import('@/lib/sdk-options.js'); const options = createChatOptions({ cwd: '/test/path', @@ -358,41 +208,6 @@ describe('sdk-options.ts', () => { expect(options.model).toBe('claude-sonnet-4-20250514'); }); - - it('should not set sandbox when enableSandboxMode is false', async () => { - const { createChatOptions } = await import('@/lib/sdk-options.js'); - - const options = createChatOptions({ - cwd: '/test/path', - enableSandboxMode: false, - }); - - expect(options.sandbox).toBeUndefined(); - }); - - it('should enable sandbox by default when enableSandboxMode is not provided', async () => { - const { createChatOptions } = await import('@/lib/sdk-options.js'); - - const options = createChatOptions({ - cwd: '/test/path', - }); - - expect(options.sandbox).toEqual({ - enabled: true, - autoAllowBashIfSandboxed: true, - }); - }); - - it('should auto-disable sandbox for cloud storage paths', async () => { - const { createChatOptions } = await import('@/lib/sdk-options.js'); - - const options = createChatOptions({ - cwd: '/Users/test/Library/CloudStorage/Dropbox-Personal/project', - enableSandboxMode: true, - }); - - expect(options.sandbox).toBeUndefined(); - }); }); describe('createAutoModeOptions', () => { @@ -400,15 +215,11 @@ describe('sdk-options.ts', () => { const { createAutoModeOptions, TOOL_PRESETS, MAX_TURNS } = await import('@/lib/sdk-options.js'); - const options = createAutoModeOptions({ cwd: '/test/path', enableSandboxMode: true }); + const options = createAutoModeOptions({ cwd: '/test/path' }); expect(options.cwd).toBe('/test/path'); expect(options.maxTurns).toBe(MAX_TURNS.maximum); expect(options.allowedTools).toEqual([...TOOL_PRESETS.fullAccess]); - expect(options.sandbox).toEqual({ - enabled: true, - autoAllowBashIfSandboxed: true, - }); }); it('should include systemPrompt when provided', async () => { @@ -433,62 +244,6 @@ describe('sdk-options.ts', () => { expect(options.abortController).toBe(abortController); }); - - it('should not set sandbox when enableSandboxMode is false', async () => { - const { createAutoModeOptions } = await import('@/lib/sdk-options.js'); - - const options = createAutoModeOptions({ - cwd: '/test/path', - enableSandboxMode: false, - }); - - expect(options.sandbox).toBeUndefined(); - }); - - it('should enable sandbox by default when enableSandboxMode is not provided', async () => { - const { createAutoModeOptions } = await import('@/lib/sdk-options.js'); - - const options = createAutoModeOptions({ - cwd: '/test/path', - }); - - expect(options.sandbox).toEqual({ - enabled: true, - autoAllowBashIfSandboxed: true, - }); - }); - - it('should auto-disable sandbox for cloud storage paths', async () => { - const { createAutoModeOptions } = await import('@/lib/sdk-options.js'); - - const options = createAutoModeOptions({ - cwd: '/Users/test/Library/CloudStorage/Dropbox-Personal/project', - enableSandboxMode: true, - }); - - expect(options.sandbox).toBeUndefined(); - }); - - it('should auto-disable sandbox for cloud storage paths even when enableSandboxMode is not provided', async () => { - const { createAutoModeOptions } = await import('@/lib/sdk-options.js'); - - const options = createAutoModeOptions({ - cwd: '/Users/test/Library/CloudStorage/Dropbox-Personal/project', - }); - - expect(options.sandbox).toBeUndefined(); - }); - - it('should auto-disable sandbox for iCloud paths', async () => { - const { createAutoModeOptions } = await import('@/lib/sdk-options.js'); - - const options = createAutoModeOptions({ - cwd: '/Users/test/Library/Mobile Documents/com~apple~CloudDocs/project', - enableSandboxMode: true, - }); - - expect(options.sandbox).toBeUndefined(); - }); }); describe('createCustomOptions', () => { @@ -499,13 +254,11 @@ describe('sdk-options.ts', () => { cwd: '/test/path', maxTurns: 10, allowedTools: ['Read', 'Write'], - sandbox: { enabled: true }, }); expect(options.cwd).toBe('/test/path'); expect(options.maxTurns).toBe(10); expect(options.allowedTools).toEqual(['Read', 'Write']); - expect(options.sandbox).toEqual({ enabled: true }); }); it('should use defaults when optional params not provided', async () => { @@ -517,20 +270,6 @@ describe('sdk-options.ts', () => { expect(options.allowedTools).toEqual([...TOOL_PRESETS.readOnly]); }); - it('should include sandbox when provided', async () => { - const { createCustomOptions } = await import('@/lib/sdk-options.js'); - - const options = createCustomOptions({ - cwd: '/test/path', - sandbox: { enabled: true, autoAllowBashIfSandboxed: false }, - }); - - expect(options.sandbox).toEqual({ - enabled: true, - autoAllowBashIfSandboxed: false, - }); - }); - it('should include systemPrompt when provided', async () => { const { createCustomOptions } = await import('@/lib/sdk-options.js'); diff --git a/apps/server/tests/unit/providers/claude-provider.test.ts b/apps/server/tests/unit/providers/claude-provider.test.ts index 38e1bf4c8..a02d3b5a1 100644 --- a/apps/server/tests/unit/providers/claude-provider.test.ts +++ b/apps/server/tests/unit/providers/claude-provider.test.ts @@ -79,7 +79,7 @@ describe('claude-provider.ts', () => { }); }); - it('should use default allowed tools when not specified', async () => { + it('should not include allowedTools when not specified (caller decides via sdk-options)', async () => { vi.mocked(sdk.query).mockReturnValue( (async function* () { yield { type: 'text', text: 'test' }; @@ -95,37 +95,8 @@ describe('claude-provider.ts', () => { expect(sdk.query).toHaveBeenCalledWith({ prompt: 'Test', - options: expect.objectContaining({ - allowedTools: ['Read', 'Write', 'Edit', 'Glob', 'Grep', 'Bash', 'WebSearch', 'WebFetch'], - }), - }); - }); - - it('should pass sandbox configuration when provided', async () => { - vi.mocked(sdk.query).mockReturnValue( - (async function* () { - yield { type: 'text', text: 'test' }; - })() - ); - - const generator = provider.executeQuery({ - prompt: 'Test', - cwd: '/test', - sandbox: { - enabled: true, - autoAllowBashIfSandboxed: true, - }, - }); - - await collectAsyncGenerator(generator); - - expect(sdk.query).toHaveBeenCalledWith({ - prompt: 'Test', - options: expect.objectContaining({ - sandbox: { - enabled: true, - autoAllowBashIfSandboxed: true, - }, + options: expect.not.objectContaining({ + allowedTools: expect.anything(), }), }); }); diff --git a/apps/server/tests/unit/services/settings-service.test.ts b/apps/server/tests/unit/services/settings-service.test.ts index ff09b8174..3a0c6d774 100644 --- a/apps/server/tests/unit/services/settings-service.test.ts +++ b/apps/server/tests/unit/services/settings-service.test.ts @@ -144,6 +144,33 @@ describe('settings-service.ts', () => { expect(updated.keyboardShortcuts.agent).toBe(DEFAULT_GLOBAL_SETTINGS.keyboardShortcuts.agent); }); + it('should not overwrite non-empty projects with an empty array (data loss guard)', async () => { + const initial: GlobalSettings = { + ...DEFAULT_GLOBAL_SETTINGS, + theme: 'solarized' as GlobalSettings['theme'], + projects: [ + { + id: 'proj1', + name: 'Project 1', + path: '/tmp/project-1', + lastOpened: new Date().toISOString(), + }, + ] as any, + }; + const settingsPath = path.join(testDataDir, 'settings.json'); + await fs.writeFile(settingsPath, JSON.stringify(initial, null, 2)); + + const updated = await settingsService.updateGlobalSettings({ + projects: [], + theme: 'light', + } as any); + + expect(updated.projects.length).toBe(1); + expect((updated.projects as any)[0]?.id).toBe('proj1'); + // Theme should be preserved in the same request if it attempted to wipe projects + expect(updated.theme).toBe('solarized'); + }); + it('should create data directory if it does not exist', async () => { const newDataDir = path.join(os.tmpdir(), `new-data-dir-${Date.now()}`); const newService = new SettingsService(newDataDir); diff --git a/apps/ui/playwright.config.ts b/apps/ui/playwright.config.ts index ba0b34821..f301fa30b 100644 --- a/apps/ui/playwright.config.ts +++ b/apps/ui/playwright.config.ts @@ -53,7 +53,9 @@ export default defineConfig({ process.env.AUTOMAKER_API_KEY || 'test-api-key-for-e2e-tests', // Hide the API key banner to reduce log noise AUTOMAKER_HIDE_API_KEY: 'true', - // No ALLOWED_ROOT_DIRECTORY restriction - allow all paths for testing + // Explicitly unset ALLOWED_ROOT_DIRECTORY to allow all paths for testing + // (prevents inheriting /projects from Docker or other environments) + ALLOWED_ROOT_DIRECTORY: '', // Simulate containerized environment to skip sandbox confirmation dialogs IS_CONTAINERIZED: 'true', }, diff --git a/apps/ui/scripts/setup-e2e-fixtures.mjs b/apps/ui/scripts/setup-e2e-fixtures.mjs index 62de432fb..e6009fd48 100644 --- a/apps/ui/scripts/setup-e2e-fixtures.mjs +++ b/apps/ui/scripts/setup-e2e-fixtures.mjs @@ -3,9 +3,11 @@ /** * Setup script for E2E test fixtures * Creates the necessary test fixture directories and files before running Playwright tests + * Also resets the server's settings.json to a known state for test isolation */ import * as fs from 'fs'; +import * as os from 'os'; import * as path from 'path'; import { fileURLToPath } from 'url'; @@ -16,6 +18,9 @@ const __dirname = path.dirname(__filename); const WORKSPACE_ROOT = path.resolve(__dirname, '../../..'); const FIXTURE_PATH = path.join(WORKSPACE_ROOT, 'test/fixtures/projectA'); const SPEC_FILE_PATH = path.join(FIXTURE_PATH, '.automaker/app_spec.txt'); +const SERVER_SETTINGS_PATH = path.join(WORKSPACE_ROOT, 'apps/server/data/settings.json'); +// Create a shared test workspace directory that will be used as default for project creation +const TEST_WORKSPACE_DIR = path.join(os.tmpdir(), 'automaker-e2e-workspace'); const SPEC_CONTENT = ` Test Project A @@ -27,10 +32,154 @@ const SPEC_CONTENT = ` `; +// Clean settings.json for E2E tests - no current project so localStorage can control state +const E2E_SETTINGS = { + version: 4, + setupComplete: true, + isFirstRun: false, + skipClaudeSetup: false, + theme: 'dark', + sidebarOpen: true, + chatHistoryOpen: false, + kanbanCardDetailLevel: 'standard', + maxConcurrency: 3, + defaultSkipTests: true, + enableDependencyBlocking: true, + skipVerificationInAutoMode: false, + useWorktrees: true, + showProfilesOnly: false, + defaultPlanningMode: 'skip', + defaultRequirePlanApproval: false, + defaultAIProfileId: null, + muteDoneSound: false, + phaseModels: { + enhancementModel: { model: 'sonnet' }, + fileDescriptionModel: { model: 'haiku' }, + imageDescriptionModel: { model: 'haiku' }, + validationModel: { model: 'sonnet' }, + specGenerationModel: { model: 'opus' }, + featureGenerationModel: { model: 'sonnet' }, + backlogPlanningModel: { model: 'sonnet' }, + projectAnalysisModel: { model: 'sonnet' }, + suggestionsModel: { model: 'sonnet' }, + }, + enhancementModel: 'sonnet', + validationModel: 'opus', + enabledCursorModels: ['auto', 'composer-1'], + cursorDefaultModel: 'auto', + keyboardShortcuts: { + board: 'K', + agent: 'A', + spec: 'D', + context: 'C', + settings: 'S', + profiles: 'M', + terminal: 'T', + toggleSidebar: '`', + addFeature: 'N', + addContextFile: 'N', + startNext: 'G', + newSession: 'N', + openProject: 'O', + projectPicker: 'P', + cyclePrevProject: 'Q', + cycleNextProject: 'E', + addProfile: 'N', + splitTerminalRight: 'Alt+D', + splitTerminalDown: 'Alt+S', + closeTerminal: 'Alt+W', + tools: 'T', + ideation: 'I', + githubIssues: 'G', + githubPrs: 'R', + newTerminalTab: 'Alt+T', + }, + aiProfiles: [ + { + id: 'profile-heavy-task', + name: 'Heavy Task', + description: + 'Claude Opus with Ultrathink for complex architecture, migrations, or deep debugging.', + model: 'opus', + thinkingLevel: 'ultrathink', + provider: 'claude', + isBuiltIn: true, + icon: 'Brain', + }, + { + id: 'profile-balanced', + name: 'Balanced', + description: 'Claude Sonnet with medium thinking for typical development tasks.', + model: 'sonnet', + thinkingLevel: 'medium', + provider: 'claude', + isBuiltIn: true, + icon: 'Scale', + }, + { + id: 'profile-quick-edit', + name: 'Quick Edit', + description: 'Claude Haiku for fast, simple edits and minor fixes.', + model: 'haiku', + thinkingLevel: 'none', + provider: 'claude', + isBuiltIn: true, + icon: 'Zap', + }, + { + id: 'profile-cursor-refactoring', + name: 'Cursor Refactoring', + description: 'Cursor Composer 1 for refactoring tasks.', + provider: 'cursor', + cursorModel: 'composer-1', + isBuiltIn: true, + icon: 'Sparkles', + }, + ], + // Default test project using the fixture path - tests can override via route mocking if needed + projects: [ + { + id: 'e2e-default-project', + name: 'E2E Test Project', + path: FIXTURE_PATH, + lastOpened: new Date().toISOString(), + }, + ], + trashedProjects: [], + currentProjectId: 'e2e-default-project', + projectHistory: [], + projectHistoryIndex: 0, + lastProjectDir: TEST_WORKSPACE_DIR, + recentFolders: [], + worktreePanelCollapsed: false, + lastSelectedSessionByProject: {}, + autoLoadClaudeMd: false, + skipSandboxWarning: true, + codexAutoLoadAgents: false, + codexSandboxMode: 'workspace-write', + codexApprovalPolicy: 'on-request', + codexEnableWebSearch: false, + codexEnableImages: true, + codexAdditionalDirs: [], + mcpServers: [], + enableSandboxMode: false, + mcpAutoApproveTools: true, + mcpUnrestrictedTools: true, + promptCustomization: {}, + localStorageMigrated: true, +}; + function setupFixtures() { console.log('Setting up E2E test fixtures...'); console.log(`Workspace root: ${WORKSPACE_ROOT}`); console.log(`Fixture path: ${FIXTURE_PATH}`); + console.log(`Test workspace dir: ${TEST_WORKSPACE_DIR}`); + + // Create test workspace directory for project creation tests + if (!fs.existsSync(TEST_WORKSPACE_DIR)) { + fs.mkdirSync(TEST_WORKSPACE_DIR, { recursive: true }); + console.log(`Created test workspace directory: ${TEST_WORKSPACE_DIR}`); + } // Create fixture directory const specDir = path.dirname(SPEC_FILE_PATH); @@ -43,6 +192,15 @@ function setupFixtures() { fs.writeFileSync(SPEC_FILE_PATH, SPEC_CONTENT); console.log(`Created fixture file: ${SPEC_FILE_PATH}`); + // Reset server settings.json to a clean state for E2E tests + const settingsDir = path.dirname(SERVER_SETTINGS_PATH); + if (!fs.existsSync(settingsDir)) { + fs.mkdirSync(settingsDir, { recursive: true }); + console.log(`Created directory: ${settingsDir}`); + } + fs.writeFileSync(SERVER_SETTINGS_PATH, JSON.stringify(E2E_SETTINGS, null, 2)); + console.log(`Reset server settings: ${SERVER_SETTINGS_PATH}`); + console.log('E2E test fixtures setup complete!'); } diff --git a/apps/ui/src/app.tsx b/apps/ui/src/app.tsx index 47dbc6471..31a71e850 100644 --- a/apps/ui/src/app.tsx +++ b/apps/ui/src/app.tsx @@ -3,7 +3,7 @@ import { RouterProvider } from '@tanstack/react-router'; import { createLogger } from '@automaker/utils/logger'; import { router } from './utils/router'; import { SplashScreen } from './components/splash-screen'; -import { useSettingsMigration } from './hooks/use-settings-migration'; +import { useSettingsSync } from './hooks/use-settings-sync'; import { useCursorStatusInit } from './hooks/use-cursor-status-init'; import './styles/global.css'; import './styles/theme-imports'; @@ -32,10 +32,14 @@ export default function App() { } }, []); - // Run settings migration on startup (localStorage -> file storage) - const migrationState = useSettingsMigration(); - if (migrationState.migrated) { - logger.info('Settings migrated to file storage'); + // Settings are now loaded in __root.tsx after successful session verification + // This ensures a unified flow: verify session → load settings → redirect + // We no longer block router rendering here - settings loading happens in __root.tsx + + // Sync settings changes back to server (API-first persistence) + const settingsSyncState = useSettingsSync(); + if (settingsSyncState.error) { + logger.error('Settings sync error:', settingsSyncState.error); } // Initialize Cursor CLI status at startup diff --git a/apps/ui/src/components/dialogs/file-browser-dialog.tsx b/apps/ui/src/components/dialogs/file-browser-dialog.tsx index ce09f63b3..53c20daa5 100644 --- a/apps/ui/src/components/dialogs/file-browser-dialog.tsx +++ b/apps/ui/src/components/dialogs/file-browser-dialog.tsx @@ -11,10 +11,10 @@ import { import { Button } from '@/components/ui/button'; import { PathInput } from '@/components/ui/path-input'; import { Kbd, KbdGroup } from '@/components/ui/kbd'; -import { getJSON, setJSON } from '@/lib/storage'; import { getDefaultWorkspaceDirectory, saveLastProjectDirectory } from '@/lib/workspace-config'; import { useOSDetection } from '@/hooks'; import { apiPost } from '@/lib/api-fetch'; +import { useAppStore } from '@/store/app-store'; interface DirectoryEntry { name: string; @@ -40,28 +40,8 @@ interface FileBrowserDialogProps { initialPath?: string; } -const RECENT_FOLDERS_KEY = 'file-browser-recent-folders'; const MAX_RECENT_FOLDERS = 5; -function getRecentFolders(): string[] { - return getJSON(RECENT_FOLDERS_KEY) ?? []; -} - -function addRecentFolder(path: string): void { - const recent = getRecentFolders(); - // Remove if already exists, then add to front - const filtered = recent.filter((p) => p !== path); - const updated = [path, ...filtered].slice(0, MAX_RECENT_FOLDERS); - setJSON(RECENT_FOLDERS_KEY, updated); -} - -function removeRecentFolder(path: string): string[] { - const recent = getRecentFolders(); - const updated = recent.filter((p) => p !== path); - setJSON(RECENT_FOLDERS_KEY, updated); - return updated; -} - export function FileBrowserDialog({ open, onOpenChange, @@ -78,20 +58,20 @@ export function FileBrowserDialog({ const [loading, setLoading] = useState(false); const [error, setError] = useState(''); const [warning, setWarning] = useState(''); - const [recentFolders, setRecentFolders] = useState([]); - // Load recent folders when dialog opens - useEffect(() => { - if (open) { - setRecentFolders(getRecentFolders()); - } - }, [open]); + // Use recent folders from app store (synced via API) + const recentFolders = useAppStore((s) => s.recentFolders); + const setRecentFolders = useAppStore((s) => s.setRecentFolders); + const addRecentFolder = useAppStore((s) => s.addRecentFolder); - const handleRemoveRecent = useCallback((e: React.MouseEvent, path: string) => { - e.stopPropagation(); - const updated = removeRecentFolder(path); - setRecentFolders(updated); - }, []); + const handleRemoveRecent = useCallback( + (e: React.MouseEvent, path: string) => { + e.stopPropagation(); + const updated = recentFolders.filter((p) => p !== path); + setRecentFolders(updated); + }, + [recentFolders, setRecentFolders] + ); const browseDirectory = useCallback(async (dirPath?: string) => { setLoading(true); diff --git a/apps/ui/src/components/dialogs/sandbox-rejection-screen.tsx b/apps/ui/src/components/dialogs/sandbox-rejection-screen.tsx index 2e830f15a..1e057836f 100644 --- a/apps/ui/src/components/dialogs/sandbox-rejection-screen.tsx +++ b/apps/ui/src/components/dialogs/sandbox-rejection-screen.tsx @@ -5,34 +5,16 @@ * Prompts them to either restart the app in a container or reload to try again. */ -import { useState } from 'react'; -import { createLogger } from '@automaker/utils/logger'; -import { ShieldX, RefreshCw, Container, Copy, Check } from 'lucide-react'; - -const logger = createLogger('SandboxRejectionScreen'); +import { ShieldX, RefreshCw } from 'lucide-react'; import { Button } from '@/components/ui/button'; -const DOCKER_COMMAND = 'npm run dev:docker'; - export function SandboxRejectionScreen() { - const [copied, setCopied] = useState(false); - const handleReload = () => { // Clear the rejection state and reload sessionStorage.removeItem('automaker-sandbox-denied'); window.location.reload(); }; - const handleCopy = async () => { - try { - await navigator.clipboard.writeText(DOCKER_COMMAND); - setCopied(true); - setTimeout(() => setCopied(false), 2000); - } catch (err) { - logger.error('Failed to copy:', err); - } - }; - return (
@@ -49,32 +31,10 @@ export function SandboxRejectionScreen() {

-
-
- -
-

Run in Docker (Recommended)

-

- Run Automaker in a containerized sandbox environment: -

-
- {DOCKER_COMMAND} - -
-
-
-
+

+ For safer operation, consider running Automaker in Docker. See the README for + instructions. +

-
-

- For safer operation, consider running Automaker in Docker: -

-
- {DOCKER_COMMAND} - -
-
+

+ For safer operation, consider running Automaker in Docker. See the README for + instructions. +

diff --git a/apps/ui/src/components/views/board-view.tsx b/apps/ui/src/components/views/board-view.tsx index 41be0c256..c0000b858 100644 --- a/apps/ui/src/components/views/board-view.tsx +++ b/apps/ui/src/components/views/board-view.tsx @@ -90,6 +90,7 @@ export function BoardView() { setWorktrees, useWorktrees, enableDependencyBlocking, + skipVerificationInAutoMode, isPrimaryWorktreeBranch, getPrimaryWorktreeBranch, setPipelineConfig, @@ -733,10 +734,17 @@ export function BoardView() { }, []); useEffect(() => { + logger.info( + '[AutoMode] Effect triggered - isRunning:', + autoMode.isRunning, + 'hasProject:', + !!currentProject + ); if (!autoMode.isRunning || !currentProject) { return; } + logger.info('[AutoMode] Starting auto mode polling loop for project:', currentProject.path); let isChecking = false; let isActive = true; // Track if this effect is still active @@ -756,6 +764,14 @@ export function BoardView() { try { // Double-check auto mode is still running before proceeding if (!isActive || !autoModeRunningRef.current || !currentProject) { + logger.debug( + '[AutoMode] Skipping check - isActive:', + isActive, + 'autoModeRunning:', + autoModeRunningRef.current, + 'hasProject:', + !!currentProject + ); return; } @@ -763,6 +779,12 @@ export function BoardView() { // Use ref to get the latest running tasks without causing effect re-runs const currentRunning = runningAutoTasksRef.current.length + pendingFeaturesRef.current.size; const availableSlots = maxConcurrency - currentRunning; + logger.debug( + '[AutoMode] Checking features - running:', + currentRunning, + 'available slots:', + availableSlots + ); // No available slots, skip check if (availableSlots <= 0) { @@ -770,10 +792,12 @@ export function BoardView() { } // Filter backlog features by the currently selected worktree branch - // This logic mirrors use-board-column-features.ts for consistency + // This logic mirrors use-board-column-features.ts for consistency. + // HOWEVER: auto mode should still run even if the user is viewing a non-primary worktree, + // so we fall back to "all backlog features" when none are visible in the current view. // Use ref to get the latest features without causing effect re-runs const currentFeatures = hookFeaturesRef.current; - const backlogFeatures = currentFeatures.filter((f) => { + const backlogFeaturesInView = currentFeatures.filter((f) => { if (f.status !== 'backlog') return false; const featureBranch = f.branchName; @@ -797,7 +821,25 @@ export function BoardView() { return featureBranch === currentWorktreeBranch; }); + const backlogFeatures = + backlogFeaturesInView.length > 0 + ? backlogFeaturesInView + : currentFeatures.filter((f) => f.status === 'backlog'); + + logger.debug( + '[AutoMode] Features - total:', + currentFeatures.length, + 'backlog in view:', + backlogFeaturesInView.length, + 'backlog total:', + backlogFeatures.length + ); + if (backlogFeatures.length === 0) { + logger.debug( + '[AutoMode] No backlog features found, statuses:', + currentFeatures.map((f) => f.status).join(', ') + ); return; } @@ -807,12 +849,25 @@ export function BoardView() { ); // Filter out features with blocking dependencies if dependency blocking is enabled - const eligibleFeatures = enableDependencyBlocking - ? sortedBacklog.filter((f) => { - const blockingDeps = getBlockingDependencies(f, currentFeatures); - return blockingDeps.length === 0; - }) - : sortedBacklog; + // NOTE: skipVerificationInAutoMode means "ignore unmet dependency verification" so we + // should NOT exclude blocked features in that mode. + const eligibleFeatures = + enableDependencyBlocking && !skipVerificationInAutoMode + ? sortedBacklog.filter((f) => { + const blockingDeps = getBlockingDependencies(f, currentFeatures); + if (blockingDeps.length > 0) { + logger.debug('[AutoMode] Feature', f.id, 'blocked by deps:', blockingDeps); + } + return blockingDeps.length === 0; + }) + : sortedBacklog; + + logger.debug( + '[AutoMode] Eligible features after dep check:', + eligibleFeatures.length, + 'dependency blocking enabled:', + enableDependencyBlocking + ); // Start features up to available slots const featuresToStart = eligibleFeatures.slice(0, availableSlots); @@ -821,6 +876,13 @@ export function BoardView() { return; } + logger.info( + '[AutoMode] Starting', + featuresToStart.length, + 'features:', + featuresToStart.map((f) => f.id).join(', ') + ); + for (const feature of featuresToStart) { // Check again before starting each feature if (!isActive || !autoModeRunningRef.current || !currentProject) { @@ -828,8 +890,9 @@ export function BoardView() { } // Simplified: No worktree creation on client - server derives workDir from feature.branchName - // If feature has no branchName and primary worktree is selected, assign primary branch - if (currentWorktreePath === null && !feature.branchName) { + // If feature has no branchName, assign it to the primary branch so it can run consistently + // even when the user is viewing a non-primary worktree. + if (!feature.branchName) { const primaryBranch = (currentProject.path ? getPrimaryWorktreeBranch(currentProject.path) : null) || 'main'; @@ -879,6 +942,7 @@ export function BoardView() { getPrimaryWorktreeBranch, isPrimaryWorktreeBranch, enableDependencyBlocking, + skipVerificationInAutoMode, persistFeatureUpdate, ]); diff --git a/apps/ui/src/components/views/board-view/board-header.tsx b/apps/ui/src/components/views/board-view/board-header.tsx index 21f30bf2f..fb9f38c29 100644 --- a/apps/ui/src/components/views/board-view/board-header.tsx +++ b/apps/ui/src/components/views/board-view/board-header.tsx @@ -1,13 +1,15 @@ +import { useState } from 'react'; import { HotkeyButton } from '@/components/ui/hotkey-button'; import { Button } from '@/components/ui/button'; import { Slider } from '@/components/ui/slider'; import { Switch } from '@/components/ui/switch'; import { Label } from '@/components/ui/label'; -import { Plus, Bot, Wand2 } from 'lucide-react'; +import { Plus, Bot, Wand2, Settings2 } from 'lucide-react'; import { KeyboardShortcut } from '@/hooks/use-keyboard-shortcuts'; import { UsagePopover } from '@/components/usage-popover'; import { useAppStore } from '@/store/app-store'; import { useSetupStore } from '@/store/setup-store'; +import { AutoModeSettingsDialog } from './dialogs/auto-mode-settings-dialog'; interface BoardHeaderProps { projectName: string; @@ -38,8 +40,11 @@ export function BoardHeader({ addFeatureShortcut, isMounted, }: BoardHeaderProps) { + const [showAutoModeSettings, setShowAutoModeSettings] = useState(false); const apiKeys = useAppStore((state) => state.apiKeys); const claudeAuthStatus = useSetupStore((state) => state.claudeAuthStatus); + const skipVerificationInAutoMode = useAppStore((state) => state.skipVerificationInAutoMode); + const setSkipVerificationInAutoMode = useAppStore((state) => state.setSkipVerificationInAutoMode); const codexAuthStatus = useSetupStore((state) => state.codexAuthStatus); // Claude usage tracking visibility logic @@ -101,9 +106,25 @@ export function BoardHeader({ onCheckedChange={onAutoModeToggle} data-testid="auto-mode-toggle" /> + )} + {/* Auto Mode Settings Dialog */} + + + + +
+

Version History

+

+ Click a version to restore it +

+
+
+ {[...(feature.descriptionHistory || [])] + .reverse() + .map((entry: DescriptionHistoryEntry, index: number) => { + const isCurrentVersion = entry.description === editingFeature.description; + const date = new Date(entry.timestamp); + const formattedDate = date.toLocaleDateString(undefined, { + month: 'short', + day: 'numeric', + hour: '2-digit', + minute: '2-digit', + }); + const sourceLabel = + entry.source === 'initial' + ? 'Original' + : entry.source === 'enhance' + ? `Enhanced (${entry.enhancementMode || 'improve'})` + : 'Edited'; + + return ( + + ); + })} +
+
+ + )}
diff --git a/apps/ui/src/components/views/board-view/hooks/use-board-actions.ts b/apps/ui/src/components/views/board-view/hooks/use-board-actions.ts index d94c1c56b..30d9a93e8 100644 --- a/apps/ui/src/components/views/board-view/hooks/use-board-actions.ts +++ b/apps/ui/src/components/views/board-view/hooks/use-board-actions.ts @@ -24,7 +24,12 @@ interface UseBoardActionsProps { runningAutoTasks: string[]; loadFeatures: () => Promise; persistFeatureCreate: (feature: Feature) => Promise; - persistFeatureUpdate: (featureId: string, updates: Partial) => Promise; + persistFeatureUpdate: ( + featureId: string, + updates: Partial, + descriptionHistorySource?: 'enhance' | 'edit', + enhancementMode?: 'improve' | 'technical' | 'simplify' | 'acceptance' + ) => Promise; persistFeatureDelete: (featureId: string) => Promise; saveCategory: (category: string) => Promise; setEditingFeature: (feature: Feature | null) => void; @@ -80,6 +85,7 @@ export function useBoardActions({ moveFeature, useWorktrees, enableDependencyBlocking, + skipVerificationInAutoMode, isPrimaryWorktreeBranch, getPrimaryWorktreeBranch, } = useAppStore(); @@ -221,7 +227,9 @@ export function useBoardActions({ priority: number; planningMode?: PlanningMode; requirePlanApproval?: boolean; - } + }, + descriptionHistorySource?: 'enhance' | 'edit', + enhancementMode?: 'improve' | 'technical' | 'simplify' | 'acceptance' ) => { const finalBranchName = updates.branchName || undefined; @@ -265,7 +273,7 @@ export function useBoardActions({ }; updateFeature(featureId, finalUpdates); - persistFeatureUpdate(featureId, finalUpdates); + persistFeatureUpdate(featureId, finalUpdates, descriptionHistorySource, enhancementMode); if (updates.category) { saveCategory(updates.category); } @@ -806,12 +814,14 @@ export function useBoardActions({ // Sort by priority (lower number = higher priority, priority 1 is highest) // Features with blocking dependencies are sorted to the end const sortedBacklog = [...backlogFeatures].sort((a, b) => { - const aBlocked = enableDependencyBlocking - ? getBlockingDependencies(a, features).length > 0 - : false; - const bBlocked = enableDependencyBlocking - ? getBlockingDependencies(b, features).length > 0 - : false; + const aBlocked = + enableDependencyBlocking && !skipVerificationInAutoMode + ? getBlockingDependencies(a, features).length > 0 + : false; + const bBlocked = + enableDependencyBlocking && !skipVerificationInAutoMode + ? getBlockingDependencies(b, features).length > 0 + : false; // Blocked features go to the end if (aBlocked && !bBlocked) return 1; @@ -823,14 +833,14 @@ export function useBoardActions({ // Find the first feature without blocking dependencies const featureToStart = sortedBacklog.find((f) => { - if (!enableDependencyBlocking) return true; + if (!enableDependencyBlocking || skipVerificationInAutoMode) return true; return getBlockingDependencies(f, features).length === 0; }); if (!featureToStart) { toast.info('No eligible features', { description: - 'All backlog features have unmet dependencies. Complete their dependencies first.', + 'All backlog features have unmet dependencies. Complete their dependencies first (or enable "Skip verification requirement" in Auto Mode settings).', }); return; } @@ -847,6 +857,7 @@ export function useBoardActions({ isPrimaryWorktreeBranch, getPrimaryWorktreeBranch, enableDependencyBlocking, + skipVerificationInAutoMode, ]); const handleArchiveAllVerified = useCallback(async () => { diff --git a/apps/ui/src/components/views/board-view/hooks/use-board-persistence.ts b/apps/ui/src/components/views/board-view/hooks/use-board-persistence.ts index 4a25de7ed..826f4d7c4 100644 --- a/apps/ui/src/components/views/board-view/hooks/use-board-persistence.ts +++ b/apps/ui/src/components/views/board-view/hooks/use-board-persistence.ts @@ -15,7 +15,12 @@ export function useBoardPersistence({ currentProject }: UseBoardPersistenceProps // Persist feature update to API (replaces saveFeatures) const persistFeatureUpdate = useCallback( - async (featureId: string, updates: Partial) => { + async ( + featureId: string, + updates: Partial, + descriptionHistorySource?: 'enhance' | 'edit', + enhancementMode?: 'improve' | 'technical' | 'simplify' | 'acceptance' + ) => { if (!currentProject) return; try { @@ -25,7 +30,13 @@ export function useBoardPersistence({ currentProject }: UseBoardPersistenceProps return; } - const result = await api.features.update(currentProject.path, featureId, updates); + const result = await api.features.update( + currentProject.path, + featureId, + updates, + descriptionHistorySource, + enhancementMode + ); if (result.success && result.feature) { updateFeature(result.feature.id, result.feature); } diff --git a/apps/ui/src/components/views/board-view/worktree-panel/worktree-panel.tsx b/apps/ui/src/components/views/board-view/worktree-panel/worktree-panel.tsx index 0f4a1765d..e0030d094 100644 --- a/apps/ui/src/components/views/board-view/worktree-panel/worktree-panel.tsx +++ b/apps/ui/src/components/views/board-view/worktree-panel/worktree-panel.tsx @@ -1,8 +1,8 @@ -import { useState, useEffect, useRef } from 'react'; +import { useEffect, useRef } from 'react'; import { Button } from '@/components/ui/button'; import { GitBranch, Plus, RefreshCw, PanelLeftOpen, PanelLeftClose } from 'lucide-react'; import { cn, pathsEqual } from '@/lib/utils'; -import { getItem, setItem } from '@/lib/storage'; +import { useAppStore } from '@/store/app-store'; import type { WorktreePanelProps, WorktreeInfo } from './types'; import { useWorktrees, @@ -14,8 +14,6 @@ import { } from './hooks'; import { WorktreeTab } from './components'; -const WORKTREE_PANEL_COLLAPSED_KEY = 'worktree-panel-collapsed'; - export function WorktreePanel({ projectPath, onCreateWorktree, @@ -85,17 +83,11 @@ export function WorktreePanel({ features, }); - // Collapse state with localStorage persistence - const [isCollapsed, setIsCollapsed] = useState(() => { - const saved = getItem(WORKTREE_PANEL_COLLAPSED_KEY); - return saved === 'true'; - }); - - useEffect(() => { - setItem(WORKTREE_PANEL_COLLAPSED_KEY, String(isCollapsed)); - }, [isCollapsed]); + // Collapse state from store (synced via API) + const isCollapsed = useAppStore((s) => s.worktreePanelCollapsed); + const setWorktreePanelCollapsed = useAppStore((s) => s.setWorktreePanelCollapsed); - const toggleCollapsed = () => setIsCollapsed((prev) => !prev); + const toggleCollapsed = () => setWorktreePanelCollapsed(!isCollapsed); // Periodic interval check (5 seconds) to detect branch changes on disk // Reduced from 1s to 5s to minimize GPU/CPU usage from frequent re-renders diff --git a/apps/ui/src/components/views/context-view.tsx b/apps/ui/src/components/views/context-view.tsx index ab33dbe8f..41dc38169 100644 --- a/apps/ui/src/components/views/context-view.tsx +++ b/apps/ui/src/components/views/context-view.tsx @@ -496,6 +496,14 @@ export function ContextView() { setNewMarkdownContent(''); } catch (error) { logger.error('Failed to create markdown:', error); + // Close dialog and reset state even on error to avoid stuck dialog + setIsCreateMarkdownOpen(false); + setNewMarkdownName(''); + setNewMarkdownDescription(''); + setNewMarkdownContent(''); + toast.error('Failed to create markdown file', { + description: error instanceof Error ? error.message : 'Unknown error occurred', + }); } }; diff --git a/apps/ui/src/components/views/logged-out-view.tsx b/apps/ui/src/components/views/logged-out-view.tsx new file mode 100644 index 000000000..3239a9bd1 --- /dev/null +++ b/apps/ui/src/components/views/logged-out-view.tsx @@ -0,0 +1,29 @@ +import { useNavigate } from '@tanstack/react-router'; +import { Button } from '@/components/ui/button'; +import { LogOut } from 'lucide-react'; + +export function LoggedOutView() { + const navigate = useNavigate(); + + return ( +
+
+
+
+ +
+

You’ve been logged out

+

+ Your session expired, or the server restarted. Please log in again. +

+
+ +
+ +
+
+
+ ); +} diff --git a/apps/ui/src/components/views/login-view.tsx b/apps/ui/src/components/views/login-view.tsx index c619f1f29..445bd9376 100644 --- a/apps/ui/src/components/views/login-view.tsx +++ b/apps/ui/src/components/views/login-view.tsx @@ -1,50 +1,363 @@ /** * Login View - Web mode authentication * - * Prompts user to enter the API key shown in server console. - * On successful login, sets an HTTP-only session cookie. + * Uses a state machine for clear, maintainable flow: + * + * States: + * checking_server → server_error (after 5 retries) + * checking_server → awaiting_login (401/unauthenticated) + * checking_server → checking_setup (authenticated) + * awaiting_login → logging_in → login_error | checking_setup + * checking_setup → redirecting */ -import { useState } from 'react'; +import { useReducer, useEffect, useRef } from 'react'; import { useNavigate } from '@tanstack/react-router'; -import { login } from '@/lib/http-api-client'; +import { login, getHttpApiClient, getServerUrlSync } from '@/lib/http-api-client'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; -import { KeyRound, AlertCircle, Loader2 } from 'lucide-react'; +import { KeyRound, AlertCircle, Loader2, RefreshCw, ServerCrash } from 'lucide-react'; import { useAuthStore } from '@/store/auth-store'; import { useSetupStore } from '@/store/setup-store'; -export function LoginView() { - const navigate = useNavigate(); - const setAuthState = useAuthStore((s) => s.setAuthState); - const setupComplete = useSetupStore((s) => s.setupComplete); - const [apiKey, setApiKey] = useState(''); - const [error, setError] = useState(null); - const [isLoading, setIsLoading] = useState(false); +// ============================================================================= +// State Machine Types +// ============================================================================= - const handleSubmit = async (e: React.FormEvent) => { - e.preventDefault(); - setError(null); - setIsLoading(true); +type State = + | { phase: 'checking_server'; attempt: number } + | { phase: 'server_error'; message: string } + | { phase: 'awaiting_login'; apiKey: string; error: string | null } + | { phase: 'logging_in'; apiKey: string } + | { phase: 'checking_setup' } + | { phase: 'redirecting'; to: string }; + +type Action = + | { type: 'SERVER_CHECK_RETRY'; attempt: number } + | { type: 'SERVER_ERROR'; message: string } + | { type: 'AUTH_REQUIRED' } + | { type: 'AUTH_VALID' } + | { type: 'UPDATE_API_KEY'; value: string } + | { type: 'SUBMIT_LOGIN' } + | { type: 'LOGIN_ERROR'; message: string } + | { type: 'REDIRECT'; to: string } + | { type: 'RETRY_SERVER_CHECK' }; + +const initialState: State = { phase: 'checking_server', attempt: 1 }; + +// ============================================================================= +// State Machine Reducer +// ============================================================================= + +function reducer(state: State, action: Action): State { + switch (action.type) { + case 'SERVER_CHECK_RETRY': + return { phase: 'checking_server', attempt: action.attempt }; + + case 'SERVER_ERROR': + return { phase: 'server_error', message: action.message }; + + case 'AUTH_REQUIRED': + return { phase: 'awaiting_login', apiKey: '', error: null }; + + case 'AUTH_VALID': + return { phase: 'checking_setup' }; + + case 'UPDATE_API_KEY': + if (state.phase !== 'awaiting_login') return state; + return { ...state, apiKey: action.value }; + + case 'SUBMIT_LOGIN': + if (state.phase !== 'awaiting_login') return state; + return { phase: 'logging_in', apiKey: state.apiKey }; + + case 'LOGIN_ERROR': + if (state.phase !== 'logging_in') return state; + return { phase: 'awaiting_login', apiKey: state.apiKey, error: action.message }; + + case 'REDIRECT': + return { phase: 'redirecting', to: action.to }; + + case 'RETRY_SERVER_CHECK': + return { phase: 'checking_server', attempt: 1 }; + + default: + return state; + } +} + +// ============================================================================= +// Constants +// ============================================================================= + +const MAX_RETRIES = 5; +const BACKOFF_BASE_MS = 400; + +// ============================================================================= +// Imperative Flow Logic (runs once on mount) +// ============================================================================= + +/** + * Check auth status without triggering side effects. + * Unlike the httpClient methods, this does NOT call handleUnauthorized() + * which would navigate us away to /logged-out. + * + * Relies on HTTP-only session cookie being sent via credentials: 'include'. + * + * Returns: { authenticated: true } or { authenticated: false } + * Throws: on network errors (for retry logic) + */ +async function checkAuthStatusSafe(): Promise<{ authenticated: boolean }> { + const serverUrl = getServerUrlSync(); + + const response = await fetch(`${serverUrl}/api/auth/status`, { + credentials: 'include', // Send HTTP-only session cookie + signal: AbortSignal.timeout(5000), + }); + + // Any response means server is reachable + const data = await response.json(); + return { authenticated: data.authenticated === true }; +} + +/** + * Check if server is reachable and if we have a valid session. + */ +async function checkServerAndSession( + dispatch: React.Dispatch, + setAuthState: (state: { isAuthenticated: boolean; authChecked: boolean }) => void, + signal?: AbortSignal +): Promise { + for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) { + // Return early if the component has unmounted + if (signal?.aborted) { + return; + } + + dispatch({ type: 'SERVER_CHECK_RETRY', attempt }); try { - const result = await login(apiKey.trim()); - if (result.success) { - // Mark as authenticated for this session (cookie-based auth) + const result = await checkAuthStatusSafe(); + + // Return early if the component has unmounted + if (signal?.aborted) { + return; + } + + if (result.authenticated) { + // Server is reachable and we're authenticated setAuthState({ isAuthenticated: true, authChecked: true }); + dispatch({ type: 'AUTH_VALID' }); + return; + } + + // Server is reachable but we need to login + dispatch({ type: 'AUTH_REQUIRED' }); + return; + } catch (error: unknown) { + // Network error - server is not reachable + console.debug(`Server check attempt ${attempt}/${MAX_RETRIES} failed:`, error); - // After auth, determine if setup is needed or go to app - navigate({ to: setupComplete ? '/' : '/setup' }); - } else { - setError(result.error || 'Invalid API key'); + if (attempt === MAX_RETRIES) { + // Return early if the component has unmounted + if (!signal?.aborted) { + dispatch({ + type: 'SERVER_ERROR', + message: 'Unable to connect to server. Please check that the server is running.', + }); + } + return; } - } catch (err) { - setError('Failed to connect to server'); - } finally { - setIsLoading(false); + + // Exponential backoff before retry + const backoffMs = BACKOFF_BASE_MS * Math.pow(2, attempt - 1); + await new Promise((resolve) => setTimeout(resolve, backoffMs)); + } + } +} + +async function checkSetupStatus( + dispatch: React.Dispatch, + signal?: AbortSignal +): Promise { + const httpClient = getHttpApiClient(); + + try { + const result = await httpClient.settings.getGlobal(); + + // Return early if aborted + if (signal?.aborted) { + return; } + + if (result.success && result.settings) { + // Check the setupComplete field from settings + // This is set to true when user completes the setup wizard + const setupComplete = (result.settings as { setupComplete?: boolean }).setupComplete === true; + + // IMPORTANT: Update the Zustand store BEFORE redirecting + // Otherwise __root.tsx routing effect will override our redirect + // because it reads setupComplete from the store (which defaults to false) + useSetupStore.getState().setSetupComplete(setupComplete); + + dispatch({ type: 'REDIRECT', to: setupComplete ? '/' : '/setup' }); + } else { + // No settings yet = first run = need setup + useSetupStore.getState().setSetupComplete(false); + dispatch({ type: 'REDIRECT', to: '/setup' }); + } + } catch { + // Return early if aborted + if (signal?.aborted) { + return; + } + // If we can't get settings, go to setup to be safe + useSetupStore.getState().setSetupComplete(false); + dispatch({ type: 'REDIRECT', to: '/setup' }); + } +} + +async function performLogin( + apiKey: string, + dispatch: React.Dispatch, + setAuthState: (state: { isAuthenticated: boolean; authChecked: boolean }) => void +): Promise { + try { + const result = await login(apiKey.trim()); + + if (result.success) { + setAuthState({ isAuthenticated: true, authChecked: true }); + dispatch({ type: 'AUTH_VALID' }); + } else { + dispatch({ type: 'LOGIN_ERROR', message: result.error || 'Invalid API key' }); + } + } catch { + dispatch({ type: 'LOGIN_ERROR', message: 'Failed to connect to server' }); + } +} + +// ============================================================================= +// Component +// ============================================================================= + +export function LoginView() { + const navigate = useNavigate(); + const setAuthState = useAuthStore((s) => s.setAuthState); + const [state, dispatch] = useReducer(reducer, initialState); + const retryControllerRef = useRef(null); + + // Run initial server/session check on mount. + // IMPORTANT: Do not "run once" via a ref guard here. + // In React StrictMode (dev), effects mount -> cleanup -> mount. + // If we abort in cleanup and also skip the second run, we'll get stuck forever on "Connecting...". + useEffect(() => { + const controller = new AbortController(); + checkServerAndSession(dispatch, setAuthState, controller.signal); + + return () => { + controller.abort(); + retryControllerRef.current?.abort(); + }; + }, [setAuthState]); + + // When we enter checking_setup phase, check setup status + useEffect(() => { + if (state.phase === 'checking_setup') { + const controller = new AbortController(); + checkSetupStatus(dispatch, controller.signal); + + return () => { + controller.abort(); + }; + } + }, [state.phase]); + + // When we enter redirecting phase, navigate + useEffect(() => { + if (state.phase === 'redirecting') { + navigate({ to: state.to }); + } + }, [state.phase, state.phase === 'redirecting' ? state.to : null, navigate]); + + // Handle login form submission + const handleSubmit = (e: React.FormEvent) => { + e.preventDefault(); + if (state.phase !== 'awaiting_login' || !state.apiKey.trim()) return; + + dispatch({ type: 'SUBMIT_LOGIN' }); + performLogin(state.apiKey, dispatch, setAuthState); + }; + + // Handle retry button for server errors + const handleRetry = () => { + // Abort any previous retry request + retryControllerRef.current?.abort(); + + dispatch({ type: 'RETRY_SERVER_CHECK' }); + const controller = new AbortController(); + retryControllerRef.current = controller; + checkServerAndSession(dispatch, setAuthState, controller.signal); }; + // ============================================================================= + // Render based on current state + // ============================================================================= + + // Checking server connectivity + if (state.phase === 'checking_server') { + return ( +
+
+ +

+ Connecting to server + {state.attempt > 1 ? ` (attempt ${state.attempt}/${MAX_RETRIES})` : '...'} +

+
+
+ ); + } + + // Server unreachable after retries + if (state.phase === 'server_error') { + return ( +
+
+
+ +
+
+

Server Unavailable

+

{state.message}

+
+ +
+
+ ); + } + + // Checking setup status after auth + if (state.phase === 'checking_setup' || state.phase === 'redirecting') { + return ( +
+
+ +

+ {state.phase === 'checking_setup' ? 'Loading settings...' : 'Redirecting...'} +

+
+
+ ); + } + + // Login form (awaiting_login or logging_in) + const isLoggingIn = state.phase === 'logging_in'; + const apiKey = state.phase === 'awaiting_login' ? state.apiKey : state.apiKey; + const error = state.phase === 'awaiting_login' ? state.error : null; + return (
@@ -70,8 +383,8 @@ export function LoginView() { type="password" placeholder="Enter API key..." value={apiKey} - onChange={(e) => setApiKey(e.target.value)} - disabled={isLoading} + onChange={(e) => dispatch({ type: 'UPDATE_API_KEY', value: e.target.value })} + disabled={isLoggingIn} autoFocus className="font-mono" data-testid="login-api-key-input" @@ -88,10 +401,10 @@ export function LoginView() { +
+
+
+ ); +} diff --git a/apps/ui/src/components/views/settings-view/account/index.ts b/apps/ui/src/components/views/settings-view/account/index.ts new file mode 100644 index 000000000..ecaeaa492 --- /dev/null +++ b/apps/ui/src/components/views/settings-view/account/index.ts @@ -0,0 +1 @@ +export { AccountSection } from './account-section'; diff --git a/apps/ui/src/components/views/settings-view/api-keys/api-keys-section.tsx b/apps/ui/src/components/views/settings-view/api-keys/api-keys-section.tsx index f4289a4d3..088f3ddf2 100644 --- a/apps/ui/src/components/views/settings-view/api-keys/api-keys-section.tsx +++ b/apps/ui/src/components/views/settings-view/api-keys/api-keys-section.tsx @@ -1,7 +1,7 @@ import { useAppStore } from '@/store/app-store'; import { useSetupStore } from '@/store/setup-store'; import { Button } from '@/components/ui/button'; -import { Key, CheckCircle2, Settings, Trash2, Loader2 } from 'lucide-react'; +import { Key, CheckCircle2, Trash2, Loader2 } from 'lucide-react'; import { ApiKeyField } from './api-key-field'; import { buildProviderConfigs } from '@/config/api-providers'; import { SecurityNotice } from './security-notice'; @@ -10,20 +10,13 @@ import { cn } from '@/lib/utils'; import { useState, useCallback } from 'react'; import { getElectronAPI } from '@/lib/electron'; import { toast } from 'sonner'; -import { useNavigate } from '@tanstack/react-router'; export function ApiKeysSection() { const { apiKeys, setApiKeys } = useAppStore(); - const { - claudeAuthStatus, - setClaudeAuthStatus, - codexAuthStatus, - setCodexAuthStatus, - setSetupComplete, - } = useSetupStore(); + const { claudeAuthStatus, setClaudeAuthStatus, codexAuthStatus, setCodexAuthStatus } = + useSetupStore(); const [isDeletingAnthropicKey, setIsDeletingAnthropicKey] = useState(false); const [isDeletingOpenaiKey, setIsDeletingOpenaiKey] = useState(false); - const navigate = useNavigate(); const { providerConfigParams, handleSave, saved } = useApiKeyManagement(); @@ -86,12 +79,6 @@ export function ApiKeysSection() { } }, [apiKeys, setApiKeys, setCodexAuthStatus]); - // Open setup wizard - const openSetupWizard = useCallback(() => { - setSetupComplete(false); - navigate({ to: '/setup' }); - }, [setSetupComplete, navigate]); - return (
- - {apiKeys.anthropic && (
- -
- onEnableSandboxModeChange(checked === true)} - className="mt-1" - data-testid="enable-sandbox-mode-checkbox" - /> -
- -

- Run bash commands in an isolated sandbox environment for additional security. - - Note: On some systems, enabling sandbox mode may cause the agent to hang without - responding. If you experience issues, try disabling this option. - -

-
-
); diff --git a/apps/ui/src/components/views/settings-view/cli-status/codex-cli-status.tsx b/apps/ui/src/components/views/settings-view/cli-status/codex-cli-status.tsx index 3e267a722..fb7af4143 100644 --- a/apps/ui/src/components/views/settings-view/cli-status/codex-cli-status.tsx +++ b/apps/ui/src/components/views/settings-view/cli-status/codex-cli-status.tsx @@ -1,24 +1,237 @@ +import { Button } from '@/components/ui/button'; +import { CheckCircle2, AlertCircle, RefreshCw, XCircle } from 'lucide-react'; +import { cn } from '@/lib/utils'; import type { CliStatus } from '../shared/types'; -import { CliStatusCard } from './cli-status-card'; +import type { CodexAuthStatus } from '@/store/setup-store'; import { OpenAIIcon } from '@/components/ui/provider-icon'; interface CliStatusProps { status: CliStatus | null; + authStatus?: CodexAuthStatus | null; isChecking: boolean; onRefresh: () => void; } -export function CodexCliStatus({ status, isChecking, onRefresh }: CliStatusProps) { +function getAuthMethodLabel(method: string): string { + switch (method) { + case 'api_key': + return 'API Key'; + case 'api_key_env': + return 'API Key (Environment)'; + case 'cli_authenticated': + case 'oauth': + return 'CLI Authentication'; + default: + return method || 'Unknown'; + } +} + +function SkeletonPulse({ className }: { className?: string }) { + return
; +} + +function CodexCliStatusSkeleton() { + return ( +
+
+
+
+ + +
+ +
+
+ +
+
+
+ {/* Installation status skeleton */} +
+ +
+ + + +
+
+ {/* Auth status skeleton */} +
+ +
+ + +
+
+
+
+ ); +} + +export function CodexCliStatus({ status, authStatus, isChecking, onRefresh }: CliStatusProps) { + if (!status) return ; + return ( - +
+
+
+
+
+ +
+

Codex CLI

+
+ +
+

+ Codex CLI powers OpenAI models for coding and automation workflows. +

+
+
+ {status.success && status.status === 'installed' ? ( +
+
+
+ +
+
+

Codex CLI Installed

+
+ {status.method && ( +

+ Method: {status.method} +

+ )} + {status.version && ( +

+ Version: {status.version} +

+ )} + {status.path && ( +

+ Path: {status.path} +

+ )} +
+
+
+ {/* Authentication Status */} + {authStatus?.authenticated ? ( +
+
+ +
+
+

Authenticated

+
+

+ Method:{' '} + {getAuthMethodLabel(authStatus.method)} +

+
+
+
+ ) : ( +
+
+ +
+
+

Not Authenticated

+

+ Run codex login{' '} + or set an API key to authenticate. +

+
+
+ )} + + {status.recommendation && ( +

{status.recommendation}

+ )} +
+ ) : ( +
+
+
+ +
+
+

Codex CLI Not Detected

+

+ {status.recommendation || + 'Install Codex CLI to unlock OpenAI models with tool support.'} +

+
+
+ {status.installCommands && ( +
+

Installation Commands:

+
+ {status.installCommands.npm && ( +
+

+ npm +

+ + {status.installCommands.npm} + +
+ )} + {status.installCommands.macos && ( +
+

+ macOS/Linux +

+ + {status.installCommands.macos} + +
+ )} + {status.installCommands.windows && ( +
+

+ Windows (PowerShell) +

+ + {status.installCommands.windows} + +
+ )} +
+
+ )} +
+ )} +
+
); } diff --git a/apps/ui/src/components/views/settings-view/components/settings-navigation.tsx b/apps/ui/src/components/views/settings-view/components/settings-navigation.tsx index 1083b10db..fd3b4f077 100644 --- a/apps/ui/src/components/views/settings-view/components/settings-navigation.tsx +++ b/apps/ui/src/components/views/settings-view/components/settings-navigation.tsx @@ -1,6 +1,7 @@ import { cn } from '@/lib/utils'; import type { Project } from '@/lib/electron'; import type { NavigationItem } from '../config/navigation'; +import { GLOBAL_NAV_ITEMS, PROJECT_NAV_ITEMS } from '../config/navigation'; import type { SettingsViewId } from '../hooks/use-settings-view'; interface SettingsNavigationProps { @@ -10,33 +11,95 @@ interface SettingsNavigationProps { onNavigate: (sectionId: SettingsViewId) => void; } -export function SettingsNavigation({ - navItems, - activeSection, - currentProject, +function NavButton({ + item, + isActive, onNavigate, -}: SettingsNavigationProps) { +}: { + item: NavigationItem; + isActive: boolean; + onNavigate: (sectionId: SettingsViewId) => void; +}) { + const Icon = item.icon; return ( -