Skip to main content

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:
ActivationEvent
Triggered when any language file is opened in the editor
ActivationEvent
Triggered when VS Code finishes its startup sequence
ActivationEvent
Triggered when the workspace contains specific files (e.g., evals.env)
Usage:

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
Hook into deactivation:

User Interaction Events

Button Click Events

The extension provides event handlers for sidebar button interactions:
() => Promise<void>
Triggered when the new task (+) button is clicked
() => Promise<void>
Triggered when the MCP Servers button is clicked
() => Promise<void>
Triggered when the History button is clicked
() => Promise<void>
Triggered when the Settings button is clicked
() => Promise<void>
Triggered when the Account button is clicked
() => Promise<void>
Triggered when the Worktrees button is clicked
() => Promise<void>
Triggered when the HAI Tasks button is clicked
Example:

Webview Events

(preserveEditorFocus?: boolean) => void
Shows the HAI Build webview sidebarParameters:
  • preserveEditorFocus - When true, shows webview without forcing focus away from editor
(content: string) => Promise<void>
Adds content to the chat input fieldParameters:
  • content - The text to add to the input
Example:

State Management Events

Secret Storage Events

The extension listens for changes to secure credential storage: Event Handler:
string
The key of the secret that changed (e.g., cline:clineAccountId)
Use cases:
  • 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:
Watched directories:
  • .clinerules/ - Local Cline rules
  • Custom hook directories

URI Handling Events

The extension registers a URI handler for deep linking: Event Handler:
vscode.Uri
The deep link URI that was opened (e.g., vscode://presidio-inc.hai-build-code-generator/task?id=123)
Supported URI paths:
  • /task - Open a specific task by ID

Telemetry Events

The extension tracks various user interactions for analytics:

Button Click Tracking

string
Identifier for the button that was clicked
string
ULID of the current task (if applicable)

Slash Command Usage

string
ULID of the current task
string
Name of the slash command (e.g., ‘newtask’, ‘smol’, ‘my-workflow’)
'builtin' | 'mcp_prompt' | '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 diagnostics
  • vscode.CodeActionKind.RefactorExtract - Extract refactoring (Explain)
  • vscode.CodeActionKind.RefactorRewrite - Rewrite refactoring (Improve)
Triggered when:
  • User right-clicks on code
  • User opens the quick fix menu (Ctrl/Cmd + .)
  • Diagnostics (errors/warnings) are present
Available actions:
CodeAction
Kind: QuickFixAdds selected code and diagnostics to chat
CodeAction
Kind: RefactorExtractRequests an explanation of the selected code
CodeAction
Kind: RefactorRewriteRequests AI suggestions to improve the code
CodeAction
Kind: 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:
Command
Replies to a comment threadWhen enabled: commentController == hai-ai-review && !commentIsEmpty
Command
Adds the comment thread to HAI Build chatWhen enabled: commentController == hai-ai-review

Development Mode Events

Development mode events are only available when IS_DEV === true

File Watcher for Hot Reload

In development mode, the extension watches for source file changes: Event Handler:
Watched pattern: 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:
() => void
Removes legacy API key storage
(context) => Promise<void>
Migrates custom instructions to global Cline rules (one-time)
(context) => Promise<void>
Migrates welcome view state based on existing API keys (one-time)
(context) => Promise<void>
Migrates workspace storage back to global storage (reverting previous migration)
(context) => Promise<void>
Ensures taskHistory.json exists and migrates legacy state (one-time)
(context) => Promise<void>
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:
Events:
  • 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

Always verify the HAI Build extension is installed and activated before attempting to use its API:
Extension activation might fail. Always handle errors:
When registering event listeners, always add them to your extension’s subscriptions:
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