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:

  1. Select the most appropriate tool based on your prompt.
  2. Suggest the tool and its parameters for your approval.
  3. Apply the approved tool and show you the results.
  4. Repeat this process until your task is complete.

Tool reference

Tool name Description Category
read_file Reads file contents with line numbers. Read
search_files Searches for text or regex patterns in files. Read
list_files Lists files and directories in a specified location. Read
list_code_definition_names Gets a list of code definitions, e.g., classes or functions. Read
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
web_fetch Gets the content of a web page or text resource by URL Browser
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

Getting content by URL using web_fetch

web_fetch runs a GET request against the specified URL and returns the text content of the resource. It automatically converts HTML pages to Markdown, while returning JSON and other text formats without conversion. Long content may get truncated.

The tool supports the following parameters:

  • url: Resource URL stating the protocol, e.g., https://example.com. This is a required setting.
  • render: Page rendering method. The default value of false is suitable for pages whose content can be accessed without executing JavaScript. If true, the page gets loaded in a headless browser, which is suitable for websites with dynamic content. This is an optional parameter.

web_fetch is for reading only and does not allow you to click buttons, fill out forms, or perform other interactive actions. Use browser_action for scenarios like that.

Example of using tools

Here is a typical tool workflow:

  1. The user types a prompt in the chat: Create a file named greeting.js that prints a welcome message.

  2. Code Assistant proposes the write_to_file tool.

    <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>
    
  3. The user clicks Save in the chat interface.

  4. 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.