.. _Protecting Code:

Protecting Code
===============

To avoid sending sensitive information to an LLM, you can use the AI Assistant protect file. Each line in the protect file defines a pattern, specifying which files should or should not be protected. **Content from protected files will be omitted from @snippet and #symbol expansion.**

.. attention::
   
 Content that is pasted or manually entered into the chat will **not** be safeguarded by this mechanism.


AI Assistant looks for the protect file in:

-  **<project>/.dvt/ai/protect**.


Pattern Format
~~~~~~~~~~~~~~

Patterns match against either absolute or relative paths. Those beginning with a ``/`` on Linux and MacOS, or a drive specifier on Windows, will match against the absolute path. All other patterns will match against the project relative path.

.. list-table::
   :widths: 20 80
   
   * - ``*``
     - Matches zero or more characters without crossing directory boundaries.
   * - ``**``
     - Matches zero or more characters crossing directory boundaries.
   * - ``?``
     - Matches exactly one character.
   * - ``[ ]``
     - Matches a single character out of a set of characters. For example, ``[abc]`` matches ``a``, ``b``, or ``c``. 

       Hyphen ``-`` may be used to specify a range. For example, ``[a-z]`` matches from ``a`` to ``z`` (inclusive).

       Exclamation mark ``!`` at the beginning of a set may be used for negation. For example, ``[!a-c]`` matches any character except ``a``, ``b``, or ``c``.
   * - ``{pattern1,pattern2}``
     - Groups patterns separated by comma ``,``. Groups cannot be nested.
   * - ``\``
     - Escapes one of the following characters: ``*``, ``?``, ``\``, ``[``, ``]``, ``{``, ``}``, if a file or directory name contains them. This only applies to paths on **Unix-like systems**. On Windows, ``\`` is used as separator in file paths.
   * - ``$VAR or ${VAR}``
     - Expands to environment variable value.
   * - ``!pattern``
     - Negates the pattern. Any matching path protected by a previous pattern will become unprotected again.
   * - ``#comment``
     - Comment lines and empty lines are ignored.


Examples
~~~~~~~~

1. Protect files from specific directories and their descendants:

   .. code-block:: text
      
      # protect all files from a specific directory relative to the project root
      lib/ip1/rtl/**
      
      # protect all files from a specific directory in the filesystem
      /path/to/ip/store/ip1/rtl/**
      
      # protect all files in any directory named 'secret'
      **/secret/**

      # protect all files in the user home directory
      $HOME/**


2. Protect everything except files inside a specific directory and its descendants:
   
   .. code-block:: text

      # protect all files
      **

      # do not protect files inside 'public' directory
      !/path/to/public/**
      

3. Protect all files except those with specific extensions:

   .. code-block:: text

      # protect all files
      **

      # do not protect files with these extensions
      !**/*.{sv,svh}