diff --git a/apps/server/src/lib/sdk-options.ts b/apps/server/src/lib/sdk-options.ts index 85dc3eb3..e7fc3578 100644 --- a/apps/server/src/lib/sdk-options.ts +++ b/apps/server/src/lib/sdk-options.ts @@ -173,18 +173,6 @@ function buildClaudeMdOptions(config: CreateSdkOptionsConfig): { result.systemPrompt.append = config.systemPrompt; } - console.log( - '[SDK Options] CLAUDE.md auto-loading enabled:', - JSON.stringify( - { - systemPrompt: result.systemPrompt, - settingSources: result.settingSources, - }, - null, - 2 - ) - ); - return result; } diff --git a/apps/server/src/lib/settings-helpers.ts b/apps/server/src/lib/settings-helpers.ts index 9bf48361..477c81ec 100644 --- a/apps/server/src/lib/settings-helpers.ts +++ b/apps/server/src/lib/settings-helpers.ts @@ -15,7 +15,7 @@ import type { SettingsService } from '../services/settings-service.js'; */ export async function getAutoLoadClaudeMdSetting( projectPath: string, - settingsService?: SettingsService, + settingsService?: SettingsService | null, logPrefix = '[SettingsHelper]' ): Promise { if (!settingsService) { @@ -40,6 +40,6 @@ export async function getAutoLoadClaudeMdSetting( return result; } catch (error) { console.error(`${logPrefix} Failed to load autoLoadClaudeMd setting:`, error); - return false; + throw error; } } diff --git a/apps/server/src/services/agent-service.ts b/apps/server/src/services/agent-service.ts index e25efebe..e5402424 100644 --- a/apps/server/src/services/agent-service.ts +++ b/apps/server/src/services/agent-service.ts @@ -17,6 +17,7 @@ import { ProviderFactory } from '../providers/provider-factory.js'; import { createChatOptions, validateWorkingDirectory } from '../lib/sdk-options.js'; import { PathNotAllowedError } from '@automaker/platform'; import type { SettingsService } from './settings-service.js'; +import { getAutoLoadClaudeMdSetting } from '../lib/settings-helpers.js'; interface Message { id: string; @@ -190,7 +191,11 @@ export class AgentService { const effectiveWorkDir = workingDirectory || session.workingDirectory; // Load autoLoadClaudeMd setting (project setting takes precedence over global) - const autoLoadClaudeMd = await this.getAutoLoadClaudeMdSetting(effectiveWorkDir); + const autoLoadClaudeMd = await getAutoLoadClaudeMdSetting( + effectiveWorkDir, + this.settingsService, + '[AgentService]' + ); // Load project context files (CLAUDE.md, CODE_QUALITY.md, etc.) // Note: When autoLoadClaudeMd is enabled, SDK handles CLAUDE.md loading via settingSources @@ -604,37 +609,6 @@ You have full access to the codebase and can: - Execute tests and builds`; } - /** - * Get the autoLoadClaudeMd setting, with project settings taking precedence over global. - * Returns false if settings service is not available. - */ - private async getAutoLoadClaudeMdSetting(projectPath: string): Promise { - if (!this.settingsService) { - console.log('[AgentService] SettingsService not available, autoLoadClaudeMd disabled'); - return false; - } - - try { - // Check project settings first (takes precedence) - const projectSettings = await this.settingsService.getProjectSettings(projectPath); - if (projectSettings.autoLoadClaudeMd !== undefined) { - console.log( - `[AgentService] autoLoadClaudeMd from project settings: ${projectSettings.autoLoadClaudeMd}` - ); - return projectSettings.autoLoadClaudeMd; - } - - // Fall back to global settings - const globalSettings = await this.settingsService.getGlobalSettings(); - const result = globalSettings.autoLoadClaudeMd ?? false; - console.log(`[AgentService] autoLoadClaudeMd from global settings: ${result}`); - return result; - } catch (error) { - console.error('[AgentService] Failed to load autoLoadClaudeMd setting:', error); - return false; - } - } - private generateId(): string { return `msg_${Date.now()}_${Math.random().toString(36).substring(2, 11)}`; } diff --git a/apps/server/src/services/auto-mode-service.ts b/apps/server/src/services/auto-mode-service.ts index af9ef746..83fb3feb 100644 --- a/apps/server/src/services/auto-mode-service.ts +++ b/apps/server/src/services/auto-mode-service.ts @@ -32,6 +32,7 @@ import { } from '../lib/sdk-options.js'; import { FeatureLoader } from './feature-loader.js'; import type { SettingsService } from './settings-service.js'; +import { getAutoLoadClaudeMdSetting } from '../lib/settings-helpers.js'; const execAsync = promisify(exec); @@ -1100,7 +1101,11 @@ Format your response as a structured markdown document.`; const provider = ProviderFactory.getProviderForModel(analysisModel); // Load autoLoadClaudeMd setting - const autoLoadClaudeMd = await this.getAutoLoadClaudeMdSetting(projectPath); + const autoLoadClaudeMd = await getAutoLoadClaudeMdSetting( + projectPath, + this.settingsService, + '[AutoMode]' + ); // Use createCustomOptions for centralized SDK configuration with CLAUDE.md support const sdkOptions = createCustomOptions({ @@ -1797,7 +1802,11 @@ This mock response was generated because AUTOMAKER_MOCK_AGENT=true was set. } // Load autoLoadClaudeMd setting (project setting takes precedence over global) - const autoLoadClaudeMd = await this.getAutoLoadClaudeMdSetting(finalProjectPath); + const autoLoadClaudeMd = await getAutoLoadClaudeMdSetting( + finalProjectPath, + this.settingsService, + '[AutoMode]' + ); // Build SDK options using centralized configuration for feature implementation const sdkOptions = createAutoModeOptions({ @@ -2515,35 +2524,4 @@ Begin implementing task ${task.id} now.`; } }); } - - /** - * Get the autoLoadClaudeMd setting, with project settings taking precedence over global. - * Returns false if settings service is not available. - */ - private async getAutoLoadClaudeMdSetting(projectPath: string): Promise { - if (!this.settingsService) { - console.log('[AutoMode] SettingsService not available, autoLoadClaudeMd disabled'); - return false; - } - - try { - // Check project settings first (takes precedence) - const projectSettings = await this.settingsService.getProjectSettings(projectPath); - if (projectSettings.autoLoadClaudeMd !== undefined) { - console.log( - `[AutoMode] autoLoadClaudeMd from project settings: ${projectSettings.autoLoadClaudeMd}` - ); - return projectSettings.autoLoadClaudeMd; - } - - // Fall back to global settings - const globalSettings = await this.settingsService.getGlobalSettings(); - const result = globalSettings.autoLoadClaudeMd ?? false; - console.log(`[AutoMode] autoLoadClaudeMd from global settings: ${result}`); - return result; - } catch (error) { - console.error('[AutoMode] Failed to load autoLoadClaudeMd setting:', error); - return false; - } - } }