|
| 1 | +# How to Verify AI Agent Hooks Work |
| 2 | + |
| 3 | +## Quick Verification Steps |
| 4 | + |
| 5 | +### 1. Build Check |
| 6 | + |
| 7 | +```bash |
| 8 | +# From root directory |
| 9 | +pnpm --filter lighthouse-extension run build |
| 10 | +pnpm --filter lighthouse-extension run build:tsc |
| 11 | +``` |
| 12 | + |
| 13 | +If builds succeed, the hooks are properly integrated. |
| 14 | + |
| 15 | +### 2. Type Check |
| 16 | + |
| 17 | +```bash |
| 18 | +pnpm --filter lighthouse-extension run build:tsc |
| 19 | +``` |
| 20 | + |
| 21 | +No TypeScript errors = hooks are correctly typed. |
| 22 | + |
| 23 | +### 3. Test in VSCode Extension Host |
| 24 | + |
| 25 | +#### Option A: Unit Test (Run existing extension test) |
| 26 | + |
| 27 | +```bash |
| 28 | +pnpm --filter lighthouse-extension run test -- extension.test.ts |
| 29 | +``` |
| 30 | + |
| 31 | +Look for the "AI Agent Hooks" test section - it verifies: |
| 32 | + |
| 33 | +- Hooks are exposed via `getAIAgentHooks()` |
| 34 | +- All 4 methods are available |
| 35 | +- Workspace context can be retrieved |
| 36 | + |
| 37 | +#### Option B: Manual Verification in VSCode |
| 38 | + |
| 39 | +1. **Package the extension:** |
| 40 | + |
| 41 | + ```bash |
| 42 | + cd packages/vscode-extension |
| 43 | + npm run package |
| 44 | + ``` |
| 45 | + |
| 46 | +2. **Install in VSCode:** |
| 47 | + - Open VSCode |
| 48 | + - Go to Extensions view |
| 49 | + - Install from VSIX file |
| 50 | + |
| 51 | +3. **Open Developer Console:** |
| 52 | + - Press `Cmd+Shift+P` (Mac) or `Ctrl+Shift+P` (Windows/Linux) |
| 53 | + - Type "Developer: Toggle Developer Tools" |
| 54 | + - Go to Console tab |
| 55 | + |
| 56 | +4. **Test the hooks:** |
| 57 | + |
| 58 | + ```javascript |
| 59 | + // Get the extension instance |
| 60 | + const ext = vscode.extensions.getExtension("lighthouse-web3.lighthouse-storage-for-vscode"); |
| 61 | + if (ext && ext.isActive) { |
| 62 | + const extension = ext.exports?.extension; |
| 63 | + |
| 64 | + // Get AI hooks |
| 65 | + const aiHooks = extension?.getAIAgentHooks(); |
| 66 | + |
| 67 | + // Test getWorkspaceContext |
| 68 | + const context = await aiHooks?.getWorkspaceContext(); |
| 69 | + console.log("Workspace context:", context); |
| 70 | + |
| 71 | + // Test onProgress |
| 72 | + const unsubscribe = aiHooks?.onProgress((progress) => { |
| 73 | + console.log("Progress update:", progress); |
| 74 | + }); |
| 75 | + |
| 76 | + // Test onAICommand (workspace context command) |
| 77 | + const result = await aiHooks?.onAICommand("lighthouse.workspace.context", {}); |
| 78 | + console.log("Command result:", result); |
| 79 | + |
| 80 | + // Cleanup |
| 81 | + unsubscribe?.(); |
| 82 | + } |
| 83 | + ``` |
| 84 | +
|
| 85 | +### 4. Programmatic Test Script |
| 86 | +
|
| 87 | +Create a test file `test-hooks-manual.ts`: |
| 88 | +
|
| 89 | +```typescript |
| 90 | +import { createExtensionCore } from "@lighthouse-tooling/extension-core"; |
| 91 | +import { AIAgentHooksImpl } from "./src/ai/ai-agent-hooks"; |
| 92 | + |
| 93 | +async function testAIAgentHooks() { |
| 94 | + console.log("Testing AI Agent Hooks...\n"); |
| 95 | + |
| 96 | + // Set API key |
| 97 | + process.env.LIGHTHOUSE_API_KEY = "test-key"; |
| 98 | + |
| 99 | + // Create extension core |
| 100 | + const extensionCore = createExtensionCore(); |
| 101 | + await extensionCore.initialize(); |
| 102 | + |
| 103 | + // Create AI hooks |
| 104 | + const aiHooks = new AIAgentHooksImpl(extensionCore); |
| 105 | + |
| 106 | + try { |
| 107 | + // Test 1: getWorkspaceContext |
| 108 | + console.log("Test 1: getWorkspaceContext()"); |
| 109 | + const context = await aiHooks.getWorkspaceContext(); |
| 110 | + console.log("✓ Workspace context retrieved:", !!context); |
| 111 | + console.log(" - Project path:", context.projectPath || "N/A"); |
| 112 | + console.log(" - Files:", context.files?.length || 0); |
| 113 | + console.log(""); |
| 114 | + |
| 115 | + // Test 2: onAICommand |
| 116 | + console.log("Test 2: onAICommand()"); |
| 117 | + const result = await aiHooks.onAICommand("lighthouse.workspace.context", {}); |
| 118 | + console.log("✓ Command executed successfully:", !!result); |
| 119 | + console.log(""); |
| 120 | + |
| 121 | + // Test 3: registerAIFunction |
| 122 | + console.log("Test 3: registerAIFunction()"); |
| 123 | + let customFuncCalled = false; |
| 124 | + aiHooks.registerAIFunction("test.custom", async (cmd) => { |
| 125 | + customFuncCalled = true; |
| 126 | + return { success: true, data: { message: "Custom function called" } }; |
| 127 | + }); |
| 128 | + const customResult = await aiHooks.onAICommand("test.custom", {}); |
| 129 | + console.log("✓ Custom function registered and called:", customFuncCalled); |
| 130 | + console.log(""); |
| 131 | + |
| 132 | + // Test 4: onProgress |
| 133 | + console.log("Test 4: onProgress()"); |
| 134 | + let progressReceived = false; |
| 135 | + const unsubscribe = aiHooks.onProgress((progress) => { |
| 136 | + progressReceived = true; |
| 137 | + console.log(" Progress update received:", progress.title || "N/A"); |
| 138 | + }); |
| 139 | + console.log("✓ Progress callback registered"); |
| 140 | + unsubscribe(); |
| 141 | + console.log("✓ Unsubscribe function works"); |
| 142 | + console.log(""); |
| 143 | + |
| 144 | + console.log("✅ All tests passed!"); |
| 145 | + } catch (error) { |
| 146 | + console.error("❌ Test failed:", error); |
| 147 | + } finally { |
| 148 | + aiHooks.dispose(); |
| 149 | + await extensionCore.dispose(); |
| 150 | + } |
| 151 | +} |
| 152 | + |
| 153 | +testAIAgentHooks(); |
| 154 | +``` |
| 155 | +
|
| 156 | +Run with: |
| 157 | +
|
| 158 | +```bash |
| 159 | +ts-node packages/vscode-extension/test-hooks-manual.ts |
| 160 | +``` |
| 161 | +
|
| 162 | +### 5. Check Build Output |
| 163 | +
|
| 164 | +Verify hooks are in the built code: |
| 165 | +
|
| 166 | +```bash |
| 167 | +grep -i "getAIAgentHooks\|AIAgentHooks" packages/vscode-extension/dist/extension.js |
| 168 | +``` |
| 169 | +
|
| 170 | +Should show: |
| 171 | +
|
| 172 | +- `getAIAgentHooks()` method |
| 173 | +- `AIAgentHooksImpl` class |
| 174 | +- Import statements |
| 175 | +
|
| 176 | +### 6. Lint Check |
| 177 | +
|
| 178 | +```bash |
| 179 | +pnpm --filter lighthouse-extension run lint |
| 180 | +``` |
| 181 | +
|
| 182 | +Should only show warnings (not errors) - errors mean something is broken. |
| 183 | +
|
| 184 | +## Expected Results |
| 185 | +
|
| 186 | +✅ **All good if:** |
| 187 | +
|
| 188 | +- Build succeeds without errors |
| 189 | +- TypeScript compilation succeeds |
| 190 | +- `getAIAgentHooks()` returns an object with 4 methods |
| 191 | +- No runtime errors when calling hook methods |
| 192 | +- Progress callbacks can be registered/unregistered |
| 193 | +
|
| 194 | +❌ **Something wrong if:** |
| 195 | +
|
| 196 | +- Build fails |
| 197 | +- TypeScript errors |
| 198 | +- Methods are undefined |
| 199 | +- Runtime errors when using hooks |
0 commit comments