import * as vscode from 'vscode'; import * as cp from 'child_process'; export function activate(context: vscode.ExtensionContext) { console.log('Vaultace Security extension is now active!'); // Register commands const scanFileCommand = vscode.commands.registerCommand('vaultace.scanFile', () => { const editor = vscode.window.activeTextEditor; if (editor) { scanFile(editor.document.fileName); } }); const scanWorkspaceCommand = vscode.commands.registerCommand('vaultace.scanWorkspace', () => { if (vscode.workspace.workspaceFolders) { scanWorkspace(vscode.workspace.workspaceFolders[0].uri.fsPath); } }); const fixVulnerabilityCommand = vscode.commands.registerCommand('vaultace.fixVulnerability', () => { const editor = vscode.window.activeTextEditor; if (editor) { fixVulnerability(editor.document.fileName, editor.selection); } }); context.subscriptions.push(scanFileCommand, scanWorkspaceCommand, fixVulnerabilityCommand); // Auto-scan on file save const onSaveListener = vscode.workspace.onDidSaveTextDocument((document) => { const config = vscode.workspace.getConfiguration('vaultace'); if (config.get('autoScan')) { scanFile(document.fileName); } }); context.subscriptions.push(onSaveListener); } function scanFile(filePath: string) { vscode.window.withProgress({ location: vscode.ProgressLocation.Notification, title: "Vaultace: Scanning file...", cancellable: false }, async (progress) => { return new Promise((resolve) => { cp.exec(`vaultace scan "${filePath}" --format json`, (error, stdout, stderr) => { if (error) { vscode.window.showErrorMessage(`Vaultace scan failed: ${error.message}`); } else { try { const results = JSON.parse(stdout); showScanResults(results, filePath); } catch (e) { vscode.window.showInformationMessage('Vaultace: No vulnerabilities found'); } } resolve(); }); }); }); } function scanWorkspace(workspacePath: string) { vscode.window.withProgress({ location: vscode.ProgressLocation.Notification, title: "Vaultace: Scanning workspace...", cancellable: false }, async (progress) => { return new Promise((resolve) => { cp.exec(`vaultace scan "${workspacePath}" --remote`, (error, stdout, stderr) => { if (error) { vscode.window.showErrorMessage(`Vaultace workspace scan failed: ${error.message}`); } else { vscode.window.showInformationMessage('Vaultace: Workspace scan completed'); } resolve(); }); }); }); } function fixVulnerability(filePath: string, selection: vscode.Selection) { vscode.window.showQuickPick(['Auto-fix (AI)', 'Show recommendations', 'Manual fix'], { placeHolder: 'How would you like to fix this vulnerability?' }).then(choice => { if (choice === 'Auto-fix (AI)') { cp.exec(`vaultace fix auto "${filePath}"`, (error, stdout, stderr) => { if (error) { vscode.window.showErrorMessage(`Auto-fix failed: ${error.message}`); } else { vscode.window.showInformationMessage('Vulnerability fixed automatically'); } }); } }); } function showScanResults(results: any, filePath: string) { if (results.vulnerabilities && results.vulnerabilities.length > 0) { vscode.window.showWarningMessage( `Found ${results.vulnerabilities.length} vulnerabilities in ${path.basename(filePath)}`, 'Fix Now', 'View Details' ).then(choice => { if (choice === 'Fix Now') { vscode.commands.executeCommand('vaultace.fixVulnerability'); } }); } } export function deactivate() {}