Implement AI Agent Hooks interface for VSCode extension integration#40
Merged
bomanaps merged 2 commits intoPatrick-Ehimen:mainfrom Nov 20, 2025
Merged
Implement AI Agent Hooks interface for VSCode extension integration#40bomanaps merged 2 commits intoPatrick-Ehimen:mainfrom
bomanaps merged 2 commits intoPatrick-Ehimen:mainfrom
Conversation
Reviewer's GuideThis PR adds a new AI agent hooks interface and implementation to the VSCode extension, integrates it into the extension lifecycle, updates core exports, and provides tests and documentation to verify the new functionality. Sequence diagram for AI agent executing a command via hookssequenceDiagram
participant AI_Agent
participant VSCodeExtension as "LighthouseVSCodeExtension"
participant AIHooks as "AIAgentHooksImpl"
participant ExtensionCore
AI_Agent->>VSCodeExtension: getAIAgentHooks()
VSCodeExtension->>AIHooks: return aiHooks
AI_Agent->>AIHooks: onAICommand(command, params)
AIHooks->>ExtensionCore: getAICommandHandler()
AIHooks->>ExtensionCore: getAIContext()
AIHooks->>ExtensionCore: handleCommand(aiCommand)
ExtensionCore-->>AIHooks: AICommandResult
AIHooks-->>AI_Agent: result.data
Sequence diagram for registering and executing a custom AI functionsequenceDiagram
participant AI_Agent
participant AIHooks as "AIAgentHooksImpl"
participant ExtensionCore
AI_Agent->>AIHooks: registerAIFunction(name, handler)
AIHooks->>ExtensionCore: getAICommandHandler()
AIHooks->>ExtensionCore: registerHandler(name, handler)
AI_Agent->>AIHooks: onAICommand(name, params)
AIHooks->>AIHooks: customHandlers.get(name)
AIHooks->>AIHooks: handler(aiCommand)
AIHooks-->>AI_Agent: result.data
Sequence diagram for subscribing to progress updates via AI Agent HookssequenceDiagram
participant AI_Agent
participant AIHooks as "AIAgentHooksImpl"
participant ExtensionCore
AI_Agent->>AIHooks: onProgress(callback)
AIHooks->>AIHooks: add callback to progressCallbacks
AIHooks->>ExtensionCore: getProgressStreamer()
ExtensionCore-->>AIHooks: activeStreams
AIHooks->>AI_Agent: callback(progress)
Class diagram for new AI Agent Hooks interface and implementationclassDiagram
class AIAgentHooks {
<<interface>>
+onAICommand(command: string, params: Record<string, unknown>): Promise<unknown>
+getWorkspaceContext(): Promise<WorkspaceContext>
+registerAIFunction(name: string, handler: AICommandHandlerFunction): void
+onProgress(callback: (progress: ProgressUpdate) => void): () => void
}
class AIAgentHooksImpl {
+constructor(extensionCore: ExtensionCore)
+onAICommand(command: string, params: Record<string, unknown>): Promise<unknown>
+getWorkspaceContext(): Promise<WorkspaceContext>
+registerAIFunction(name: string, handler: AICommandHandlerFunction): void
+onProgress(callback: (progress: ProgressUpdate) => void): () => void
+dispose(): void
-progressCallbacks: Set<(progress: ProgressUpdate) => void>
-customHandlers: Map<string, AICommandHandlerFunction>
-progressCheckInterval: NodeJS.Timeout | null
-setupProgressListener(): void
-getAIContext(): Promise<AIContext>
}
AIAgentHooksImpl --|> AIAgentHooks
AIAgentHooksImpl o-- ExtensionCore
ExtensionCore <.. WorkspaceContext
ExtensionCore <.. ProgressUpdate
ExtensionCore <.. AICommand
ExtensionCore <.. AICommandResult
ExtensionCore <.. AICommandHandlerFunction
ExtensionCore <.. AIContext
Class diagram for LighthouseVSCodeExtension integration of AI Agent HooksclassDiagram
class LighthouseVSCodeExtension {
-aiHooks: AIAgentHooks
+getAIAgentHooks(): AIAgentHooks
+dispose(): Promise<void>
+constructor(context: vscode.ExtensionContext)
}
LighthouseVSCodeExtension o-- AIAgentHooks
LighthouseVSCodeExtension o-- AIAgentHooksImpl
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey there - I've reviewed your changes - here's some feedback:
- Instead of polling
extensionCore.getProgressStreamer()every 500ms, consider exposing an event emitter or callback API in ExtensionCore to drive progress updates more efficiently and avoid intervals. - The inline generation of agentId and session info in
getAIContextmakes testing and session reuse harder—consider moving context creation into a configurable factory or allowing overrides for deterministic tests. - The large manual verification docs and scripts in the extension package could be moved to a separate dev‐only docs directory or trimmed, so the shipped extension remains focused and lightweight.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Instead of polling `extensionCore.getProgressStreamer()` every 500ms, consider exposing an event emitter or callback API in ExtensionCore to drive progress updates more efficiently and avoid intervals.
- The inline generation of agentId and session info in `getAIContext` makes testing and session reuse harder—consider moving context creation into a configurable factory or allowing overrides for deterministic tests.
- The large manual verification docs and scripts in the extension package could be moved to a separate dev‐only docs directory or trimmed, so the shipped extension remains focused and lightweight.
## Individual Comments
### Comment 1
<location> `packages/vscode-extension/src/ai/ai-agent-hooks.ts:111-118` </location>
<code_context>
+ /**
+ * Register a custom AI-accessible function
+ */
+ registerAIFunction(name: string, handler: AICommandHandlerFunction): void {
+ // Store custom handler
+ this.customHandlers.set(name, handler);
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Potential for handler name collisions in registerAIFunction.
Warn or prevent overwriting if a handler with the same name already exists.
```suggestion
registerAIFunction(name: string, handler: AICommandHandlerFunction): void {
// Prevent overwriting existing handler
if (this.customHandlers.has(name)) {
console.warn(
`[AI Agent] Handler with name "${name}" already exists. Registration skipped to prevent overwriting.`
);
return;
}
// Store custom handler
this.customHandlers.set(name, handler);
// Also register with ExtensionCore's AI command handler for consistency
const aiCommandHandler = this.extensionCore.getAICommandHandler();
aiCommandHandler.registerHandler(name, handler);
}
```
</issue_to_address>
### Comment 2
<location> `packages/vscode-extension/src/ai/ai-agent-hooks.ts:173` </location>
<code_context>
+ /**
+ * Get AI context for commands
+ */
+ private async getAIContext(): Promise<AIContext> {
+ const now = new Date();
+ return {
</code_context>
<issue_to_address>
**suggestion (bug_risk):** AIContext agentId and sessionId generation may cause collisions.
Date.now() may generate duplicate IDs if multiple instances are created simultaneously. Use a more reliable unique ID method if these values are critical for tracking or persistence.
Suggested implementation:
```typescript
return {
agentId: `agent-${crypto.randomUUID()}`,
agentType: AgentType.CUSTOM,
session: {
sessionId: `session-${crypto.randomUUID()}`,
startTime: now,
lastActivity: now,
duration: 0,
interactionCount: 0,
context: {},
},
```
If `crypto.randomUUID()` is not available in your runtime, you may need to use a UUID library such as `uuid` (npm package). In that case, import and use `v4()` from `uuid` instead.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request
Description
Type of change
Checklist
Related Issues
Screenshots (if applicable)
Summary by Sourcery
Introduce AI Agent Hooks interface into the VSCode extension to enable programmatic AI interactions, exposing methods for executing commands, retrieving context, registering custom functions, and monitoring progress.
New Features:
Enhancements:
Documentation:
Tests: