fix: remove prompt caching to enable hot reload of custom prompts

Remove caching from Auto Mode and Agent services to allow custom prompts
to take effect immediately without requiring app restart.

Changes:
- Auto Mode: Load prompts on every feature execution instead of caching
- Agent Service: Load prompts on every chat message instead of caching
- Remove unused class fields: planningPrompts, agentSystemPrompt

This makes custom prompts work consistently across all features:
✓ Auto Mode - hot reload enabled
✓ Agent Runner - hot reload enabled
✓ Backlog Plan - already had hot reload
✓ Enhancement - already had hot reload

Users can now modify prompts in Settings and see changes immediately
without restarting the app.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Stephan Rieche
2025-12-29 23:25:15 +01:00
parent bc0ef47323
commit ec3d78922e
2 changed files with 12 additions and 28 deletions

View File

@@ -76,7 +76,6 @@ export class AgentService {
private metadataFile: string;
private events: EventEmitter;
private settingsService: SettingsService | null = null;
private agentSystemPrompt: string | null = null;
constructor(dataDir: string, events: EventEmitter, settingsService?: SettingsService) {
this.stateDir = path.join(dataDir, 'agent-sessions');
@@ -784,12 +783,9 @@ export class AgentService {
}
private async getSystemPrompt(): Promise<string> {
// Load from settings if not already cached
if (!this.agentSystemPrompt) {
const prompts = await getPromptCustomization(this.settingsService, '[AgentService]');
this.agentSystemPrompt = prompts.agent.systemPrompt;
}
return this.agentSystemPrompt;
// Load from settings (no caching - allows hot reload of custom prompts)
const prompts = await getPromptCustomization(this.settingsService, '[AgentService]');
return prompts.agent.systemPrompt;
}
private generateId(): string {

View File

@@ -200,7 +200,6 @@ export class AutoModeService {
private config: AutoModeConfig | null = null;
private pendingApprovals = new Map<string, PendingApproval>();
private settingsService: SettingsService | null = null;
private planningPrompts: Record<string, string> | null = null;
constructor(events: EventEmitter, settingsService?: SettingsService) {
this.events = events;
@@ -1602,23 +1601,6 @@ Format your response as a structured markdown document.`;
return firstLine.substring(0, 57) + '...';
}
/**
* Load planning prompts from settings
*/
private async loadPlanningPrompts(): Promise<void> {
if (this.planningPrompts) {
return; // Already loaded
}
const prompts = await getPromptCustomization(this.settingsService, '[AutoMode]');
this.planningPrompts = {
lite: prompts.autoMode.planningLite,
lite_with_approval: prompts.autoMode.planningLiteWithApproval,
spec: prompts.autoMode.planningSpec,
full: prompts.autoMode.planningFull,
};
}
/**
* Get the planning prompt prefix based on feature's planning mode
*/
@@ -1629,8 +1611,14 @@ Format your response as a structured markdown document.`;
return ''; // No planning phase
}
// Load prompts if not already loaded
await this.loadPlanningPrompts();
// Load prompts from settings (no caching - allows hot reload of custom prompts)
const prompts = await getPromptCustomization(this.settingsService, '[AutoMode]');
const planningPrompts = {
lite: prompts.autoMode.planningLite,
lite_with_approval: prompts.autoMode.planningLiteWithApproval,
spec: prompts.autoMode.planningSpec,
full: prompts.autoMode.planningFull,
};
// For lite mode, use the approval variant if requirePlanApproval is true
let promptKey: string = mode;
@@ -1638,7 +1626,7 @@ Format your response as a structured markdown document.`;
promptKey = 'lite_with_approval';
}
const planningPrompt = this.planningPrompts![promptKey];
const planningPrompt = planningPrompts[promptKey];
if (!planningPrompt) {
return '';
}