diff --git a/package.json b/package.json index dc20316..02204f6 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/agent.ts b/src/agent.ts index 87800fd..a55edd9 100644 --- a/src/agent.ts +++ b/src/agent.ts @@ -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(/
\s*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 ''; diff --git a/tests/localPathPreflight.test.ts b/tests/localPathPreflight.test.ts index f019ee4..340d66c 100644 --- a/tests/localPathPreflight.test.ts +++ b/tests/localPathPreflight.test.ts @@ -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 프로젝트 지식을 만들었습니다.', + '
', + '2nd Brain Trace: 사용함', + 'Project_Logs/2026-04-25-Datacollector_Fix.md', + '## Second Brain Debug JSON', + '{"path":"Datacollector"}', + '
' + ].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'); + }); });