| name | windsurf-webhooks-events |
| description | Build Windsurf extensions and integrate with VS Code extension API events. Use when this capability is needed. |
| metadata | {"author":"flight505"} |
Windsurf Extension Development & Events
Overview
Windsurf is built on VS Code and supports the full VS Code Extension API. Build custom extensions to track workspace events, integrate with external tools, and extend Cascade's capabilities. This skill covers extension development specific to the Windsurf environment.
Prerequisites
- Node.js 18+ and npm
- VS Code Extension API familiarity
yo and generator-code for scaffolding
- Windsurf IDE for testing
Instructions
Step 1: Scaffold Extension
npm install -g yo generator-code
yo code
Step 2: Track Workspace Events
import * as vscode from "vscode";
export function activate(context: vscode.ExtensionContext) {
console.log("Extension active in Windsurf");
const saveListener = vscode.workspace.onDidSaveTextDocument(
async (document) => {
const diagnostics = vscode.languages.getDiagnostics(document.uri);
const errors = diagnostics.filter(
(d) => d.severity === vscode.DiagnosticSeverity.Error
);
if (errors.length > 0) {
vscode.window.showWarningMessage(
`${document.fileName}: ${errors.length} error(s) after save`
);
}
}
);
const editorListener = vscode.window.onDidChangeActiveTextEditor(
(editor) => {
if (editor) {
const lang = editor.document.languageId;
const lines = editor.document.lineCount;
console.log(`Opened: ${editor.document.fileName} (${lang}, ${lines} lines)`);
}
}
);
const terminalListener = vscode.window.onDidWriteTerminalData((event) => {
if (event.data.includes("ERROR") || event.data.includes("FAIL")) {
vscode.window.showWarningMessage("Error detected in terminal output");
}
});
context.subscriptions.push(saveListener, editorListener, terminalListener);
}
Step 3: Send Events to External System
import * as vscode from "vscode";
interface WorkspaceEvent {
event: string;
file?: string;
language?: string;
timestamp: string;
metadata?: Record<string, unknown>;
}
async function sendEvent(event: WorkspaceEvent): Promise<void> {
const webhookUrl = vscode.workspace
.getConfiguration("windsurf-events")
.get<string>("webhookUrl");
if (!webhookUrl) return;
try {
await fetch(webhookUrl, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(event),
});
} catch (err) {
console.warn("Webhook delivery failed:", err);
}
}
debounceMap = <, .>();
(): {
key = ;
(debounceMap.(key));
debounceMap.(
key,
( {
(event);
debounceMap.(key);
}, delayMs)
);
}
Step 4: Extension package.json
{
"name": "windsurf-events",
"displayName": "Windsurf Events",
"version": "1.0.0",
"engines": { "vscode": "^1.85.0" },
"activationEvents": ["onStartupFinished"],
"main": "./dist/extension.js",
"contributes": {
"configuration": {
"title": "Windsurf Events",
"properties": {
"windsurf-events.webhookUrl": {
"type": "string",
"description": "URL to send workspace events to"
},
Step 5: Build and Install
npm run compile
npx vsce package
windsurf --install-extension windsurf-events-1.0.0.vsix
npx vsce publish
Step 6: Test in Windsurf
1. Open Extension Development Host: F5 in Windsurf
2. A new Windsurf window opens with extension loaded
3. Open a file, save it, trigger events
4. Check Output panel > "Windsurf Events" channel
5. Verify webhook delivery (use https://webhook.site for testing)
Error Handling
| Issue | Cause | Solution |
|---|
| Extension not activating | Wrong activationEvents | Use onStartupFinished for always-on |
| Webhook fails | Network/URL issue | Queue locally, retry with backoff |
| High CPU usage | Too many listeners | Debounce frequent events (saves, edits) |
| API incompatibility | Windsurf vs VS Code version | Pin engines.vscode version |
vsce package fails | Missing fields | Add publisher, repository, license |
Examples
Team Analytics Extension
vscode.languages.registerInlineCompletionItemProvider(
{ pattern: "**" },
{
provideInlineCompletionItems(document, position) {
console.log(`Completion at ${document.fileName}:${position.line}`);
return [];
}
}
);
Quick Test Webhook
npx -y webhook-relay -p 3456
Resources
Next Steps
For multi-environment setup, see windsurf-multi-env-setup.
Source: flight505/skill-forge — distributed by TomeVault.