Version 2.48.0 Release: Smart History Sanitization for Context Optimization
This commit is contained in:
+1
-1
@@ -2,7 +2,7 @@
|
||||
"name": "g1nation",
|
||||
"displayName": "G1nation",
|
||||
"description": "High-performance autonomous local AI coding agent for VS Code. Features vectorized inference, asynchronous task management, and 100% offline processing.",
|
||||
"version": "2.47.0",
|
||||
"version": "2.48.0",
|
||||
"publisher": "connectailab",
|
||||
"license": "MIT",
|
||||
"icon": "assets/icon.png",
|
||||
|
||||
+25
-1
@@ -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 '';
|
||||
|
||||
@@ -204,4 +204,35 @@ describe('local project path preflight', () => {
|
||||
expect(followup).toContain('src/agent.ts');
|
||||
expect(followup).toContain('recently generated project knowledge record');
|
||||
});
|
||||
|
||||
it('removes old Second Brain trace details from assistant history before model requests', () => {
|
||||
const context: any = {
|
||||
globalStorageUri: { fsPath: path.join(root, '.storage') },
|
||||
workspaceState: stateStore(),
|
||||
globalState: stateStore()
|
||||
};
|
||||
const agent = new AgentExecutor(context) as any;
|
||||
const history = [
|
||||
{ role: 'user', content: 'ConnectAI 지식 만들어줘' },
|
||||
{
|
||||
role: 'assistant',
|
||||
content: [
|
||||
'## 간단 요약',
|
||||
'ConnectAI 프로젝트 지식을 만들었습니다.',
|
||||
'<details>',
|
||||
'<summary>2nd Brain Trace: 사용함</summary>',
|
||||
'Project_Logs/2026-04-25-Datacollector_Fix.md',
|
||||
'## Second Brain Debug JSON',
|
||||
'{"path":"Datacollector"}',
|
||||
'</details>'
|
||||
].join('\n')
|
||||
}
|
||||
];
|
||||
|
||||
const requestHistory = agent.buildRequestHistory(history);
|
||||
|
||||
expect(requestHistory[1].content).toContain('ConnectAI 프로젝트 지식을 만들었습니다');
|
||||
expect(requestHistory[1].content).not.toContain('Datacollector');
|
||||
expect(requestHistory[1].content).not.toContain('2nd Brain Trace');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user