Project Overview
HAI Build Code Generator is a VS Code extension built on top of Cline that enhances AI-assisted development with additional features like HAI Tasks, Experts, and intelligent file indexing.Technology Stack
- Language: TypeScript
- Runtime: Node.js 20.x
- Extension Host: VS Code Extension API (^1.84.0)
- Frontend: React (webview-ui)
- Build Tool: esbuild
- Testing: Mocha, Playwright
- Protocol Buffers: For data serialization and gRPC communication
Directory Structure
Core Components
Extension Host (src/core)
The main extension logic runs in the VS Code extension host process. Key components include: Controller Layer- Manages the extension lifecycle
- Handles communication between VS Code and the AI models
- Coordinates task execution and file operations
- Integrates with various LLM providers (Anthropic, OpenAI, Google, AWS Bedrock, etc.)
- Handles authentication and API communication
- Manages rate limiting and error handling
- Code indexing and semantic search
- File identification and relevance scoring
- Embedding model integration
- HAI Tasks integration with Specif AI
- Task execution and lifecycle management
- User story and task tracking
Webview UI (webview-ui/)
The frontend is built with React and communicates with the extension host via VS Code’s webview API:- Settings Interface: Configure LLMs, embedding models, and preferences
- Chat Interface: Interact with the AI assistant
- HAI Tasks View: Manage and execute AI-generated tasks
- Experts Interface: Create and manage custom domain experts
- MCP Marketplace: Browse and install MCP servers
Protocol Buffers
The project uses Protocol Buffers for:- State serialization and persistence
- gRPC communication for standalone mode
- Type-safe data contracts between components
Data Flow
Key Features Architecture
HAI Tasks
- Tasks are generated by Specif AI or created manually
- Stored in the extension’s global state
- Displayed in the dedicated HAI Tasks webview
- Executed via the controller layer with full context
Experts System
- Built-in experts (read-only): .NET, Terraform, Node.js, Go
- Custom experts stored in
.hai-experts/folder:metadata.json: Expert metadata and document linksprompt.md: Expert guidelinesdocs/: Processed reference documents
- Integrated into the system prompt during code generation
Code Indexing
- Background indexing of workspace files
- Embedding generation using configured provider
- Vector storage for semantic search
- Relevant file identification during task execution
MCP Integration
- Model Context Protocol support for extensibility
- Marketplace for discovering and installing MCP servers
- OAuth handling for MCP server authentication
- Tool integration into the AI assistant workflow
Testing Architecture
Unit Tests
- Located in
src/__tests__/and component__tests__/folders - Run with Mocha and Node’s test runner
- Focus on individual component logic
Integration Tests
- Test extension functionality within VS Code
- Use
@vscode/test-electronfor running tests - Verify API integrations and file operations
E2E Tests
- Playwright-based tests in
src/test/e2e/ - Simulate real user interactions
- Test complete workflows from UI to execution
- Mock API server for backend testing
Build Process
- Protocol Buffers: Generated first via
npm run protos - Type Checking: TypeScript compilation without emit
- Webview Build: React app bundled separately
- Extension Bundle: esbuild bundles the extension code
- Packaging: VSCE packages everything into a .vsix file
Extension Points
Hooks
Custom hook system for extending functionality without modifying core code.Slash Commands
Extensible command system for chat interactions.MCP Servers
Extend capabilities through the Model Context Protocol.State Management
- Global State: VS Code’s global state for cross-workspace data
- Workspace State: Workspace-specific configuration
- Protocol Buffer State: Serialized state for standalone mode
- Indexing State: Code index and embedding metadata
Next Steps
Contributing Guidelines
Learn best practices for contributing
Testing Guide
Learn how to test your changes