Overview
The HAI Build Code Generator extension provides various events and hooks that allow you to integrate with and extend its functionality. These events are triggered at different stages of the extension lifecycle and user interactions.Extension Lifecycle Events
Extension Activation
The extension activates when specific events occur:Triggered when any language file is opened in the editor
Triggered when VS Code finishes its startup sequence
Triggered when the workspace contains specific files (e.g.,
evals.env)Extension Deactivation
When the extension deactivates, cleanup operations are performed:- Disposes of non-VS Code-specific services (via
tearDown()) - Disposes of VS Code-specific services (comment controllers, watchers, etc.)
- Cleans up registered commands and subscriptions
User Interaction Events
Button Click Events
The extension provides event handlers for sidebar button interactions:Triggered when the new task (+) button is clicked
Triggered when the MCP Servers button is clicked
Triggered when the History button is clicked
Triggered when the Settings button is clicked
Triggered when the Account button is clicked
Triggered when the Worktrees button is clicked
Triggered when the HAI Tasks button is clicked
Webview Events
Shows the HAI Build webview sidebarParameters:
preserveEditorFocus- When true, shows webview without forcing focus away from editor
Adds content to the chat input fieldParameters:
content- The text to add to the input
State Management Events
Secret Storage Events
The extension listens for changes to secure credential storage: Event Handler:The key of the secret that changed (e.g.,
cline:clineAccountId)- Cross-window authentication sync
- Credential updates
- Logout propagation
Workspace Change Events
The extension tracks workspace folder changes for hook discovery: Event Handler:File System Events
Hook Discovery Watcher
The extension watches for changes to hook files: File System Watcher:.clinerules/- Local Cline rules- Custom hook directories
URI Handling Events
Deep Link Handler
The extension registers a URI handler for deep linking: Event Handler:The deep link URI that was opened (e.g.,
vscode://presidio-inc.hai-build-code-generator/task?id=123)/task- Open a specific task by ID
Telemetry Events
The extension tracks various user interactions for analytics:Button Click Tracking
Identifier for the button that was clicked
ULID of the current task (if applicable)
Slash Command Usage
ULID of the current task
Name of the slash command (e.g., ‘newtask’, ‘smol’, ‘my-workflow’)
Category of the slash command
Code Action Events
The extension provides code actions that appear in the editor:Code Action Provider
Supported kinds:vscode.CodeActionKind.QuickFix- Quick fixes for diagnosticsvscode.CodeActionKind.RefactorExtract- Extract refactoring (Explain)vscode.CodeActionKind.RefactorRewrite- Rewrite refactoring (Improve)
- User right-clicks on code
- User opens the quick fix menu (Ctrl/Cmd + .)
- Diagnostics (errors/warnings) are present
Kind:
QuickFixAdds selected code and diagnostics to chatKind:
RefactorExtractRequests an explanation of the selected codeKind:
RefactorRewriteRequests AI suggestions to improve the codeKind:
QuickFix (preferred)Only appears when diagnostics are present. Attempts to fix errors/warnings.Comment Thread Events
The extension provides a comment controller for AI code review:Review Comment Controller
Controller ID:hai-ai-review
Available commands:
Replies to a comment threadWhen enabled:
commentController == hai-ai-review && !commentIsEmptyAdds the comment thread to HAI Build chatWhen enabled:
commentController == hai-ai-reviewDevelopment Mode Events
Development mode events are only available when
IS_DEV === trueFile Watcher for Hot Reload
In development mode, the extension watches for source file changes: Event Handler:src/**/* in the development workspace folder
Action: Automatically reloads VS Code window when source files change
Storage Migration Events
The extension performs storage migrations on activation: Migration functions:Removes legacy API key storage
Migrates custom instructions to global Cline rules (one-time)
Migrates welcome view state based on existing API keys (one-time)
Migrates workspace storage back to global storage (reverting previous migration)
Ensures taskHistory.json exists and migrates legacy state (one-time)
Cleans up MCP marketplace catalog from global state (moved to disk cache)
Hook Discovery Events
The extension uses a cache system for performance optimization: Cache initialization:- File creation in hook directories
- File changes in hook directories
- File deletion in hook directories
- Workspace folder changes
Custom Event Integration
To integrate with HAI Build events in your own extension:Listen to Extension Activation
Trigger HAI Build Commands
Access the Controller API
Best Practices
Check extension availability
Check extension availability
Always verify the HAI Build extension is installed and activated before attempting to use its API:
Handle activation failures
Handle activation failures
Extension activation might fail. Always handle errors:
Dispose event listeners
Dispose event listeners
When registering event listeners, always add them to your extension’s subscriptions:
Use telemetry responsibly
Use telemetry responsibly
If you’re integrating with HAI Build’s telemetry, ensure you:
- Follow privacy guidelines
- Respect user’s telemetry settings
- Only track meaningful interactions
See Also
Commands
Complete VS Code commands reference
Slash Commands
In-chat slash commands