Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | import * as vscode from 'vscode';
import { IExtensionContext } from '../interfaces/IExtensionContext';
import { ChatPanel } from '../ui/ChatPanel';
import { OperationMode } from '../types/OperationMode';
export function registerCommands(
context: vscode.ExtensionContext,
extensionContext: IExtensionContext
): void {
// Open Chat command
const openChatCommand = vscode.commands.registerCommand(
'claude-flow.openChat',
() => {
ChatPanel.createOrShow(extensionContext);
}
);
context.subscriptions.push(openChatCommand);
// Ask Claude command (with selected text)
const askClaudeCommand = vscode.commands.registerCommand(
'claude-flow.askClaude',
async () => {
const editor = vscode.window.activeTextEditor;
if (!editor) {
vscode.window.showErrorMessage('No active editor');
return;
}
const selection = editor.selection;
const selectedText = editor.document.getText(selection);
if (!selectedText) {
vscode.window.showInformationMessage('Please select some code to ask about');
return;
}
// Open chat panel
const chatPanel = ChatPanel.createOrShow(extensionContext);
// Create a session if needed
if (!extensionContext.chatManager.getActiveSession()) {
extensionContext.chatManager.createSession();
}
// Send the selected text with context
const language = editor.document.languageId;
const fileName = editor.document.fileName;
const prompt = `Please help me understand this ${language} code from ${fileName}:\n\n\`\`\`${language}\n${selectedText}\n\`\`\``;
await extensionContext.chatManager.sendMessage(prompt, OperationMode.Chat);
}
);
context.subscriptions.push(askClaudeCommand);
// Switch Mode command
const switchModeCommand = vscode.commands.registerCommand(
'claude-flow.switchMode',
async () => {
const modes = [
{ label: 'Chat', value: OperationMode.Chat, description: 'Simple Q&A interactions' },
{ label: 'Pair Programming', value: OperationMode.PairProgramming, description: 'Context-aware coding assistance' },
{ label: 'Code Review', value: OperationMode.CodeReview, description: 'Analyze code for improvements' },
{ label: 'Plan & Reflect', value: OperationMode.PlanReflect, description: 'Autonomous multi-step task execution' }
];
const selected = await vscode.window.showQuickPick(modes, {
placeHolder: 'Select an operation mode',
title: 'Claude Flow Mode'
});
if (selected) {
try {
await extensionContext.orchestratorManager.switchMode(selected.value);
vscode.window.showInformationMessage(`Switched to ${selected.label} mode`);
} catch (error) {
vscode.window.showErrorMessage(
`Failed to switch mode: ${error instanceof Error ? error.message : 'Unknown error'}`
);
}
}
}
);
context.subscriptions.push(switchModeCommand);
// Stop Execution command
const stopExecutionCommand = vscode.commands.registerCommand(
'claude-flow.stopExecution',
async () => {
try {
await extensionContext.orchestratorManager.stopExecution();
vscode.window.showInformationMessage('Execution stopped');
} catch (error) {
vscode.window.showErrorMessage(
`Failed to stop execution: ${error instanceof Error ? error.message : 'Unknown error'}`
);
}
}
);
context.subscriptions.push(stopExecutionCommand);
// Code Review command (review current file)
const codeReviewCommand = vscode.commands.registerCommand(
'claude-flow.reviewCode',
async () => {
const editor = vscode.window.activeTextEditor;
if (!editor) {
vscode.window.showErrorMessage('No active editor');
return;
}
const document = editor.document;
const code = document.getText();
const language = document.languageId;
const fileName = document.fileName;
// Open chat panel
ChatPanel.createOrShow(extensionContext);
// Create a session if needed
if (!extensionContext.chatManager.getActiveSession()) {
extensionContext.chatManager.createSession();
}
// Switch to code review mode
await extensionContext.orchestratorManager.switchMode(OperationMode.CodeReview);
// Send the code for review
const prompt = `Please review this ${language} code from ${fileName} and suggest improvements:\n\n\`\`\`${language}\n${code}\n\`\`\``;
await extensionContext.chatManager.sendMessage(prompt, OperationMode.CodeReview);
}
);
context.subscriptions.push(codeReviewCommand);
// Set API Key command
const setApiKeyCommand = vscode.commands.registerCommand(
'claude-flow.setApiKey',
async () => {
const apiKey = await vscode.window.showInputBox({
prompt: 'Enter your Anthropic Claude API Key',
password: true,
placeHolder: 'sk-ant-...'
});
if (apiKey) {
try {
await extensionContext.configManager.setApiKey(apiKey);
vscode.window.showInformationMessage('API key saved successfully');
// Reinitialize orchestrator with new key
await extensionContext.orchestratorManager.initialize({
apiKey,
model: extensionContext.configManager.getModel(),
maxTokens: extensionContext.configManager.getMaxTokens(),
memoryPath: extensionContext.memoryManager.getStoragePath()
});
} catch (error) {
vscode.window.showErrorMessage(
`Failed to save API key: ${error instanceof Error ? error.message : 'Unknown error'}`
);
}
}
}
);
context.subscriptions.push(setApiKeyCommand);
// Clear Chat History command
const clearChatCommand = vscode.commands.registerCommand(
'claude-flow.clearChat',
async () => {
const activeSession = extensionContext.chatManager.getActiveSession();
if (!activeSession) {
vscode.window.showInformationMessage('No active chat session');
return;
}
const confirm = await vscode.window.showWarningMessage(
'Are you sure you want to clear the chat history?',
'Yes',
'No'
);
if (confirm === 'Yes') {
extensionContext.chatManager.clearSession(activeSession);
vscode.window.showInformationMessage('Chat history cleared');
}
}
);
context.subscriptions.push(clearChatCommand);
} |