Version 2.48.0 Release: Smart History Sanitization for Context Optimization

This commit is contained in:
g1nation
2026-05-03 01:28:32 +09:00
parent ecec7556da
commit 70e46ab279
3 changed files with 57 additions and 2 deletions
+25 -1
View File
@@ -301,7 +301,7 @@ export class AgentExecutor {
// 3. API Request Setup
const { ollamaUrl, defaultModel: configDefaultModel, timeout } = getConfig();
const actualModel = modelName || configDefaultModel;
const reqMessages = [...this.chatHistory];
const reqMessages = this.buildRequestHistory(this.chatHistory);
// Handle Vision Content Injection
// Merge text prompt with file content instead of replacing, so the user's message is never lost
@@ -773,6 +773,30 @@ export class AgentExecutor {
return /(아키텍처|구조|조사|분석|설계|흐름|모듈|역할|개선|architecture|structure|design|flow|module|investigate|analy[sz]e)/i.test(prompt);
}
private buildRequestHistory(history: ChatMessage[]): ChatMessage[] {
return history.map((message) => {
if (message.role !== 'assistant' || typeof message.content !== 'string') {
return message;
}
return {
...message,
content: this.sanitizeHistoryAssistantContent(message.content)
};
});
}
private sanitizeHistoryAssistantContent(content: string): string {
return content
.replace(/<details>\s*<summary>2nd Brain Trace:[\s\S]*?<\/details>/gi, '')
.replace(/## Second Brain Debug JSON[\s\S]*?(?=\n## |\n# |$)/gi, '')
.replace(/## Candidate records for this discussion[\s\S]*?(?=\n## |\n# |$)/gi, '')
.replace(/## 후보 기록[\s\S]*?(?=\n## |\n# |$)/gi, '')
.replace(/## 프로젝트 기록 검토[\s\S]*?(?=\n## |\n# |$)/gi, '')
.replace(/\n{3,}/g, '\n\n')
.trim();
}
private buildRecentProjectKnowledgeContext(prompt: string, rootPath: string): string {
if (!rootPath || !this.isProjectKnowledgeFollowupRequest(prompt)) {
return '';