Setting up chat rules in SourceCraft Code Assistant

Warning

This feature is only available in Visual Studio Code.

You can specify the rules Code Assistant must comply with when processing a request. For example, you may want the code to be written in Python in accordance with quality guidelines.

You can use a preset rule, edit one, or add your own custom rule.

Rules are set for a specific request to the chat and are not saved for all further requests. To apply a rule to all requests, add the alwaysApply: true parameter to its settings.

Note

The interface language of the Visual Studio Code plugin depends on the selected IDE language.

Using rules

  1. Click SourceCraft Code Assistant in the editor’s left panel.

    If you have many plugins, the chat button may be hidden in the menu.

    Alternatively, use Ctrl + L in Windows/Linux or Command + L in macOS.

  2. In the message input window, click or enter @ and select Rules.
  3. View rule descriptions:
    • Hover over a rule to view its brief description.
    • To view the full text of the rule, click next to it.
  4. Select the rule.

The rule will be displayed in the menu.

Editing a preset rule

  1. In the message input window, click or enter @ and select Rules.

  2. Next to the rule you want to edit, click .

  3. In the file that opens, edit the rule parameters in the section separated by ---:

    • name: Rule name you can use to find the rule in the Rules menu.
    • description: Brief description to display when you hover over the rule.
    • alwaysApply: Defines whether to include the rule to the default context (true or false). It will be displayed in the menu, and you can delete it. Default: false.

    If you do not specify the name and description parameters, they will be generated from the file name and the first lines of the rule.

  4. Edit the rule text and save the changes.

Adding a custom rule

  1. In the message input window, click or enter @ and select Rules.

  2. Click Add rule.

  3. In the file that opens, fill in the rule parameters in the section separated by ---.

    • name: Rule name you can use to find the rule in the Rules menu.
    • description: Brief description to display when you hover over the rule.
    • alwaysApply: Defines whether to include the rule to the default context (true or false). It will be displayed in the menu, and you can delete it. Default: false.

    If you do not specify the name and description parameters, they will be generated from the file name and the first lines of the rule.

  4. Add the rule text and save the file.

The rule file will be saved at <project_directory>/.codeassistant/rules/<filename>.mdc.

You can also manually add rule files with the .md and .mdc extensions to the specified directory and its subdirectories.

.mdc files support a section for the rule name and description where you can also indicate whether to include the rule to the context by default:

---
name: Enter your rule name
description: Enter your rule description
alwaysApply: false
---

See also