How tools work in SourceCraft Code Assistant
Warning
This feature is only available in Visual Studio Code.
To interact with your code and environment, Code Assistant uses dedicated tools, i.e., specialized modules that perform specific actions such as reading files, making changes, running commands, or searching through code. These tools automate common development tasks requiring no manual effort.
Working with tools
In the chat interface, describe what you would like to do in natural language. Code Assistant will then:
- Select the most appropriate tool based on your prompt.
- Suggest the tool and its parameters for your approval.
- Apply the approved tool and show you the results.
- Repeat this process until your task is complete.
Tool reference
| Tool name | Description | Category |
|---|---|---|
read_file |
Reads file contents with line numbers. | Reads |
search_files |
Searches for text or regex patterns in files. | Reads |
list_files |
Lists files and directories in a specified location. | Reads |
list_code_definition_names |
Gets a list of code definitions, e.g., classes or functions. | Reads |
write_to_file |
Creates new files or overwrites existing ones. | Editor |
apply_diff |
Applies precise, targeted changes to specific parts of a file. | Editor |
execute_command |
Runs commands in the VS Code terminal. | Implementation |
browser_action |
Performs actions in a web browser. | Browser |
ask_followup_question |
Asks a follow-up question. | Workflow |
attempt_completion |
Signals the task is complete. | Workflow |
switch_mode |
Switches to a different operation mode. | Workflow |
new_task |
Creates a new subtask with a specified starting mode. | Workflow |
Example of using tools
Here is a typical tool workflow:
-
The user types a prompt in the chat:
Create a file named greeting.js that prints a welcome message. -
Code Assistant proposes the
write_to_filetool.<write_to_file> <path>greeting.js</path> <content> function greet(name) { console.log(`Hello, ${name}!`); } greet('World'); </content> <line_count>5</line_count> </write_to_file> -
The user clicks Save in the chat interface.
-
Code Assistant confirms the file has been created.
Tool safety and approval
Every tool invocation requires your explicit approval. When Code Assistant suggests a tool, you will see the following controls:
- Approve: Authorizes the action.
- Reject: Declines the proposed action.
- Auto-approve: Enables auto-approval for trusted actions. This is optional.
This security measure ensures you maintain full control over which files are modified, which commands are executed, and how your codebase evolves. Always carefully review tool proposals before approving them.