mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-05 09:33:07 +00:00
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:
@@ -173,18 +173,6 @@ function buildClaudeMdOptions(config: CreateSdkOptionsConfig): {
|
|||||||
result.systemPrompt.append = config.systemPrompt;
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import type { SettingsService } from '../services/settings-service.js';
|
|||||||
*/
|
*/
|
||||||
export async function getAutoLoadClaudeMdSetting(
|
export async function getAutoLoadClaudeMdSetting(
|
||||||
projectPath: string,
|
projectPath: string,
|
||||||
settingsService?: SettingsService,
|
settingsService?: SettingsService | null,
|
||||||
logPrefix = '[SettingsHelper]'
|
logPrefix = '[SettingsHelper]'
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
if (!settingsService) {
|
if (!settingsService) {
|
||||||
@@ -40,6 +40,6 @@ export async function getAutoLoadClaudeMdSetting(
|
|||||||
return result;
|
return result;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`${logPrefix} Failed to load autoLoadClaudeMd setting:`, error);
|
console.error(`${logPrefix} Failed to load autoLoadClaudeMd setting:`, error);
|
||||||
return false;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import { ProviderFactory } from '../providers/provider-factory.js';
|
|||||||
import { createChatOptions, validateWorkingDirectory } from '../lib/sdk-options.js';
|
import { createChatOptions, validateWorkingDirectory } from '../lib/sdk-options.js';
|
||||||
import { PathNotAllowedError } from '@automaker/platform';
|
import { PathNotAllowedError } from '@automaker/platform';
|
||||||
import type { SettingsService } from './settings-service.js';
|
import type { SettingsService } from './settings-service.js';
|
||||||
|
import { getAutoLoadClaudeMdSetting } from '../lib/settings-helpers.js';
|
||||||
|
|
||||||
interface Message {
|
interface Message {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -190,7 +191,11 @@ export class AgentService {
|
|||||||
const effectiveWorkDir = workingDirectory || session.workingDirectory;
|
const effectiveWorkDir = workingDirectory || session.workingDirectory;
|
||||||
|
|
||||||
// Load autoLoadClaudeMd setting (project setting takes precedence over global)
|
// 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.)
|
// Load project context files (CLAUDE.md, CODE_QUALITY.md, etc.)
|
||||||
// Note: When autoLoadClaudeMd is enabled, SDK handles CLAUDE.md loading via settingSources
|
// 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`;
|
- 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 {
|
private generateId(): string {
|
||||||
return `msg_${Date.now()}_${Math.random().toString(36).substring(2, 11)}`;
|
return `msg_${Date.now()}_${Math.random().toString(36).substring(2, 11)}`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import {
|
|||||||
} from '../lib/sdk-options.js';
|
} from '../lib/sdk-options.js';
|
||||||
import { FeatureLoader } from './feature-loader.js';
|
import { FeatureLoader } from './feature-loader.js';
|
||||||
import type { SettingsService } from './settings-service.js';
|
import type { SettingsService } from './settings-service.js';
|
||||||
|
import { getAutoLoadClaudeMdSetting } from '../lib/settings-helpers.js';
|
||||||
|
|
||||||
const execAsync = promisify(exec);
|
const execAsync = promisify(exec);
|
||||||
|
|
||||||
@@ -1100,7 +1101,11 @@ Format your response as a structured markdown document.`;
|
|||||||
const provider = ProviderFactory.getProviderForModel(analysisModel);
|
const provider = ProviderFactory.getProviderForModel(analysisModel);
|
||||||
|
|
||||||
// Load autoLoadClaudeMd setting
|
// 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
|
// Use createCustomOptions for centralized SDK configuration with CLAUDE.md support
|
||||||
const sdkOptions = createCustomOptions({
|
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)
|
// 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
|
// Build SDK options using centralized configuration for feature implementation
|
||||||
const sdkOptions = createAutoModeOptions({
|
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<boolean> {
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user