This file provides guidance and context to AI coding agents working on the vscode-ai-chat-analyzer extension. The extension analyzes AI chat responses and suggests updates to AGENTS.md files based on accuracy metrics.
The VS Code AI Chat Analyzer is a Visual Studio Code extension designed to:
- Analyze an AI chat for a single accuracy after completion
- Parse and understand AGENTS.md files in workspace folders
- Generate suggestions for improving AGENTS.md content based on the chat and the accuacy
- Update AGENTS.md files based on analysis results (reinforce accurate behavior, mitigate inaccurate chats)
- Help maintain high-quality AI agent documentation
The extension provides an interactive chat participant for natural language feedback:
- User invokes
@agentsfeedbackwith feedback text or slash command - Chat participant extracts conversation history from previous turns
- References (
#file,#selection) are resolved and included - Command-specific prefixes are applied (for
/learn,/stop,/remember) - AI analyzer generates suggestions based on feedback and AGENTS.md context
- User selects which suggestions to apply via QuickPick UI
- Selected suggestions are appended to AGENTS.md
The extension also captures upvote/downvote feedback:
- User interacts with the chat participant and gives feedback (upvote/downvote)
- Feedback is converted to accuracy: Upvote → 0.9, Downvote → 0.3
- Single
ChatResponseis created and passed through the analysis pipeline - AI analyzer generates suggestions based on the single response and AGENTS.md context
- User selects which suggestions to apply via QuickPick UI
- Selected suggestions are appended to AGENTS.md
Purpose: Registers VS Code commands, chat participant, and feedback handlers
Chat Participant: vscode-ai-chat-analyzer.feedback (invoked as @agentsfeedback)
- Creates a chat participant for natural language feedback
- Supports slash commands:
/learn,/stop,/remember,/show - Reads conversation history from previous
@agentsfeedbackturns - Processes
#file,#selection, and other VS Code references - Registers
onDidReceiveFeedbackhandler for upvote/downvote events - Converts binary feedback to accuracy scores (Helpful = 0.9, Unhelpful = 0.3)
- Creates a single
ChatResponsefrom feedback metadata - Delegates to
SuggestionProviderfor analysis
Slash Commands:
/learn <instruction>: Reinforce positive patterns (prefixes with "POSITIVE PATTERN TO REINFORCE")/stop <instruction>: Correct bad behaviors (prefixes with "NEGATIVE BEHAVIOR TO STOP")/remember <instruction>: Add project-specific rules (prefixes with "PROJECT-SPECIFIC RULE TO REMEMBER")/show: Display current AGENTS.md content without modification
Factory Functions:
createAnalyzer(): ReturnsISuggestionAnalyzerbased onaiChatAnalyzer.analyzerconfigcreateSuggestionProvider(): Sets up provider with parser, updater, and analyzer
Manual Command: vscode-ai-chat-analyzer.analyzeChat
- Alternative manual input method for testing
- Prompts user for chat response text via input box
- Allows selection of accuracy level
- Useful for testing without actual chat interaction
Purpose: Generate AGENTS.md suggestions using different LLM backends
Interface: ISuggestionAnalyzer
interface ISuggestionAnalyzer {
analyzeSuggestions(
analysisReport: { totalResponses: number; accurateResponses: number; accuracyRate: number; lowAccuracyResponses?: any[] },
agentsData: any,
chatResponses: ChatResponse[]
): Promise<Suggestion[]>;
}Implementations:
CopilotSuggestionAnalyzer: Uses VS Code Language Model API with GitHub CopilotLMStudioSuggestionAnalyzer: Uses local LM Studio server via HTTPFakeSuggestionAnalyzer: Returns mock suggestions for testing
PromptBuilder (promptBuilder.ts):
- Builds system and user prompts for LLM-based suggestion generation
- Includes few-shot examples for better suggestion quality
- Enforces token limits (~4096)
Purpose: Calculates accuracy metrics from responses
Note: Currently processes single responses wrapped in an array. The aggregate metrics (totalResponses, accurateResponses, accuracyRate) have limited value with single responses but provide structure for potential future batch processing.
Usage (current single-response pattern):
const analyzer = new ChatAnalyzer();
const report = analyzer.analyzeResponses([
{ text: chatContent, accuracy: 0.9 } // Single response
]);
// Returns: { totalResponses: 1, accurateResponses: 1, accuracyRate: 1, lowAccuracyResponses: [] }Purpose: Coordinates analysis and suggestion generation
Key Methods:
generateSuggestions(chatResponses): Runs ChatAnalyzer, parses AGENTS.md, calls analyzerupdateAgentsMd(suggestions): Applies selected suggestions via AgentsMdUpdater
Purpose: User interface for selecting suggestions to apply
Key Functions:
showSuggestionSelection(suggestions): Multi-select QuickPick with Select All/Deselect AllshowUpdateSuccess(count): Confirmation message after applying suggestions
Purpose: Parses AGENTS.md files to extract agent information
Key Functionality:
- Reads AGENTS.md file from filesystem
- Parses markdown structure (headers as agent names)
- Extracts agent responses/guidance from content
- Provides structured access via
getAgentsData()
Purpose: Updates AGENTS.md files by appending new suggestions
interface ChatResponse {
id: string;
content: string;
accuracy: number; // 0-1 scale (0.9 for upvote, 0.3 for downvote)
}interface Suggestion {
id: string;
text: string; // The actual suggestion content
description?: string; // Short description for UI
reasoning?: string; // Detailed reasoning shown in QuickPick detail
}interface ISuggestionAnalyzer {
analyzeSuggestions(
analysisReport: { totalResponses: number; accurateResponses: number; accuracyRate: number; lowAccuracyResponses?: any[] },
agentsData: any,
chatResponses: ChatResponse[]
): Promise<Suggestion[]>;
}interface AgentInfo {
name: string;
expectedResponses: string[];
lastUpdated: Date;
}
interface AnalysisReport {
agent: AgentInfo;
responses: ChatResponse[];
suggestions: string[];
}-
Understanding Accuracy Thresholds:
- High accuracy: ≥0.8
- Medium accuracy: 0.5-0.8
- Low accuracy: <0.5
-
AGENTS.md File Structure:
- Headers (
#) denote agent names - Content under headers represents agent guidance
- Parser extracts structure for programmatic access
- Headers (
-
Error Handling:
- Always check for workspace folder existence
- Handle missing AGENTS.md gracefully
- Provide clear error messages to users
-
Testing:
- Test suite located in
test/suite/ - Run tests with
npm test - Coverage includes:
- ChatAnalyzer accuracy calculations
- Extension activation and registration
- Chat participant registration
- Slash command handling (
/learn,/stop,/remember,/show) - Command prefix generation
- Conversation history extraction
- Reference processing
- Feedback-to-accuracy conversion logic (upvote/downvote)
- Command registration verification
- Test suite located in
- Update
ChatAnalyzer.analyzeResponses()return type - Add new calculation logic
- Update tests in
test/suite/chatAnalyzer.test.ts - Consider UI presentation in extension.ts
- Update
AgentsMdParser.parseAgents()parsing logic - Update
Agentinterface if structure changes - Update
AgentsMdUpdaterto match new format - Add tests for new format parsing
- Register in
package.jsonundercontributes.commands - Add to
activationEventsif needed - Implement command handler in
extension.ts - Add corresponding tests
- VS Code Extension API (^1.60.0)
- TypeScript (^4.4.3)
- Mocha (^11.7.5) - Test framework
- Chai (^4.3.4) - Assertion library
- @vscode/test-electron (^2.1.0) - VS Code testing utilities
# Compile TypeScript
npm run compile
# Watch mode for development
npm run watch
# Run tests
npm test
# Package extension (requires @vscode/vsce)
vsce package- Feedback-based accuracy scoring (binary: upvote vs downvote)
- Basic AGENTS.md parsing (header-based only)
- Limited feedback data (only captures final vote, not intermediate states)
- No historical trend analysis across multiple sessions
- Granular Feedback: ✅ IMPLEMENTED - Natural language feedback via
@agentsfeedbackchat participant - Advanced Parsing: Support more complex AGENTS.md formats (lists, code blocks, etc.)
- Context Capture: ✅ IMPLEMENTED - Includes chat context (prompt, conversation history) in analysis
- Historical Tracking: Store analysis history and identify patterns over time
- Multi-file Support: Handle multiple AGENTS.md files in monorepos
- UI Enhancements: Add webview for rich analysis visualization and feedback history
- Smart Suggestions: Use AI to generate specific improvement recommendations
- A/B Testing: Compare different agent response strategies based on feedback
vscode-ai-chat-analyzer/
├── src/
│ ├── extension.ts # Main entry point, chat participant, commands
│ ├── chatAnalyzer.ts # Response analysis and accuracy metrics
│ ├── agentsMdParser.ts # AGENTS.md file parser
│ ├── agentsMdUpdater.ts # AGENTS.md file updater
│ ├── suggestionProvider.ts # Coordinates analysis pipeline
│ ├── suggestionUi.ts # QuickPick UI for suggestion selection
│ ├── analyzers/
│ │ ├── copilotAnalyzer.ts # GitHub Copilot LLM analyzer
│ │ ├── lmStudioAnalyzer.ts # LM Studio local LLM analyzer
│ │ ├── FakeSuggestionAnalyzer.ts # Mock analyzer for testing
│ │ └── promptBuilder.ts # Prompt construction for LLMs
│ └── types/
│ └── index.ts # TypeScript type definitions
├── test/
│ ├── runTest.ts # Test runner setup
│ ├── suite/
│ │ ├── index.ts # Unit test suite configuration
│ │ ├── chatAnalyzer.test.ts # ChatAnalyzer tests
│ │ ├── copilotAnalyzer.test.ts # Copilot analyzer tests
│ │ ├── lmStudioAnalyzer.test.ts # LM Studio analyzer tests
│ │ ├── promptBuilder.test.ts # PromptBuilder tests
│ │ └── extension.test.ts # Extension tests
│ └── integration/
│ ├── index.ts # Integration test configuration
│ ├── runIntegrationTest.ts # Integration test runner
│ ├── analyzer.integration.test.ts # General analyzer tests
│ ├── copilot.integration.test.ts # Copilot integration tests
│ ├── lmstudio.integration.test.ts # LM Studio integration tests
│ └── fake.integration.test.ts # Fake analyzer integration tests
├── package.json # Extension manifest
├── tsconfig.json # TypeScript configuration
├── AGENTS.md # This file - AI agent guidance
├── LOCAL_DEV.md # Local development instructions
└── README.md # User documentation
When working on this extension, consider these questions:
-
Should aggregate metrics be removed from single-response flow?
- Current: ChatAnalyzer calculates totalResponses, accuracyRate for arrays of 1
- Consider simplifying for single-response focus
-
How should different feedback types influence suggestions?
- Upvote (0.9): Reinforce the behavior that worked
- Downvote (0.3): Identify and correct problematic patterns
-
Should the extension support batch analysis?
- Historical accumulation of feedback over time
- Periodic analysis of patterns across sessions
-
What metadata should AGENTS.md track?
- Timestamps, version history, accuracy trends?
-
How to handle conflicts when updating AGENTS.md?
- Manual review, auto-merge, or version control integration?
- Publisher: Keep-Social-Dev
- Repository: vscode-ai-chat-analyzer
- License: MIT
When contributing, ensure:
- Tests pass (
npm test) - Code compiles without errors (
npm run compile) - Documentation is updated
- AGENTS.md reflects any new patterns or components