refactor: streamline auto-load CLAUDE.md setting retrieval

- Removed the private method for getting the autoLoadClaudeMd setting from AgentService and AutoModeService.
- Updated both services to utilize the new settings helper for retrieving the autoLoadClaudeMd setting, improving code reusability and clarity.
- Adjusted error handling in the settings helper to throw errors instead of returning false when the settings service is unavailable.
This commit is contained in:
Kacper
2025-12-24 22:48:02 +01:00
parent 3154121840
commit 99a19cb2a2
4 changed files with 19 additions and 79 deletions

View File

@@ -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<boolean> {
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)}`;
}