< Summary

Information
Class: UIBlazor.Agents.BuiltInAgent
Assembly: UIBlazor
File(s): /home/runner/work/InvAit/InvAit/UIBlazor/Agents/BuiltInAgent.cs
Tag: 71_26091983037
Line coverage
96%
Covered lines: 368
Uncovered lines: 15
Coverable lines: 383
Total lines: 389
Line coverage: 96%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%1196.08%

File(s)

/home/runner/work/InvAit/InvAit/UIBlazor/Agents/BuiltInAgent.cs

#LineLine coverage
 1using UIBlazor.Services;
 2
 3namespace UIBlazor.Agents;
 4
 645public class BuiltInAgent(IVsBridge vsBridge, ISkillService skillService, IInternalExecutor internalExecutor)
 6{
 647    public IReadOnlyList<Tool> Tools =
 648    [
 649        // File operations
 6410        new()
 6411        {
 6412            Name = BuiltInToolEnum.ReadFiles,
 6413            DisplayName = SharedResource.ToolReadFiles,
 6414            Category = ToolCategory.ReadFiles,
 6415            Description = "Request to read the contents of one or more files. File path can be relative or absolute.",
 6416            ExampleToSystemMessage = $"""
 6417                                     SYNTAX EXAMPLES:
 6418                                     C:\user\project\src\file.cs [L100:C50] — Starts at line 100, includes 50 lines.
 6419                                     C:\user\project\src\file.cs [L100] — Starts at line 100, goes to the end.
 6420                                     src\file.cs — Includes the entire file. Relative path.
 6421
 6422                                     OPTIONAL PARAMETERS:
 6423                                     Use the following format at the end of the file path: [Lstart_line:Cline_count]
 6424                                     L[start_line]: A 1-based start line. (e.g., L100). Default: first line.
 6425                                     C[line_count]: The number of lines to include. (e.g., C50). Default: until the end 
 6426
 6427                                     For example, to read a specific range, from 100 to 150 line:
 6428                                     <function name="{BuiltInToolEnum.ReadFiles}">
 6429                                     C:\user\project\large_file.cs [L100:C50]
 6430                                     </function>
 6431
 6432                                     Example to read the entire files (up to 7 at once):
 6433                                     <function name="{BuiltInToolEnum.ReadFiles}">
 6434                                     C:\user\project\file.cs
 6435                                     \fil2.cs [L550]
 6436                                     \fil3.cs [L100:C50]
 6437                                     </function>
 6438                                     """,
 6439            NativeTool = BuiltInToolDefs.MapMethodToTool(typeof(BuiltInToolDefs).GetMethod(nameof(BuiltInToolDefs.ReadFi
 140            ExecuteAsync = (args, c) => vsBridge.ExecuteToolAsync(BuiltInToolEnum.ReadFiles, args, c)
 6441        },
 6442        new()
 6443        {
 6444            Name = BuiltInToolEnum.ReadOpenFile,
 6445            DisplayName = SharedResource.ToolReadOpenFile,
 6446            Category = ToolCategory.ReadFiles,
 6447            Description = $"""
 6448                          To view the user's currently open file, use the {BuiltInToolEnum.ReadOpenFile} tool.
 6449                          The tool returns the absolute file path and its line-numbered content (e.g. "1 | const x = 1")
 6450                          If the user is asking about a file and you don't see any code, use this to check the current f
 6451                          """,
 6452            ExampleToSystemMessage = $"""
 6453                                     For example
 6454                                     <function name="{BuiltInToolEnum.ReadOpenFile}"></function>
 6455                                     """,
 056            ExecuteAsync = (args, c) => vsBridge.ExecuteToolAsync(BuiltInToolEnum.ReadOpenFile, args, c)
 6457        },
 6458        new()
 6459        {
 6460            Name = BuiltInToolEnum.CreateFile,
 6461            DisplayName = SharedResource.ToolCreateFile,
 6462            Category = ToolCategory.WriteFiles,
 6463            Description = """
 6464                          To create a NEW file with the relative or absolute filepath and new contents.
 6465                          Note: The old file will be overwritten if it exists.
 6466                          Use this when you need to make large changes to a single file and it's easier to recreate it.
 6467                          """,
 6468            ExampleToSystemMessage = $"""
 6469                                     For example, to create a file located at 'C:\user\project\file.cs', you would respo
 6470                                     <function name="{BuiltInToolEnum.CreateFile}">
 6471                                     C:\user\project\file.cs
 6472                                     Contents of the file.
 6473                                     And second line of this file.
 6474                                     </function>
 6475                                     """,
 076            ExecuteAsync = (args, c) => vsBridge.ExecuteToolAsync(BuiltInToolEnum.CreateFile, args, c)
 6477        },
 6478        new()
 6479        {
 6480            Name = BuiltInToolEnum.ApplyDiff,
 6481            DisplayName = SharedResource.ToolApplyDiff,
 6482            Category = ToolCategory.WriteFiles,
 6483            Description = $"""
 6484                Performs precise, surgical modifications to a file using SEARCH/REPLACE blocks.
 6485                Use this tool to modify existing code with 100% accuracy.
 6486
 6487                STRUCTURE:
 6488                [file_path]
 6489                <<<<<<< SEARCH [:start_line:]
 6490                [exact content to find]
 6491                =======
 6492                [new content to replace with]
 6493                >>>>>>> REPLACE
 6494
 6495                OPTIONAL PARAMETERS:
 6496                - :start_line:: A hint for the line number to speed up searching. Example: `<<<<<<< SEARCH :10:`
 6497
 6498                CRITICAL RULES:
 6499                1. EXACT MATCH: The SEARCH block must match the file content exactly (including spaces, tabs, and indent
 64100                2. BREVITY: Keep each SEARCH block under 15 lines. If the change is larger, use multiple consecutive SEA
 64101                3. EFFICIENCY: Combine all related changes for a single file into one {BuiltInToolEnum.ApplyDiff} call w
 64102                4. INTEGRITY: Ensure syntax balance (brackets, quotes) is maintained after the replacement.
 64103                5. UNCERTAINTY: If you don't have the exact text, you MUST use {BuiltInToolEnum.ReadFiles} first.
 64104                """,
 64105            ExampleToSystemMessage = $"""
 64106                                     For example:
 64107                                     <function name="{BuiltInToolEnum.ApplyDiff}">
 64108                                     C:\path\to\file.cs
 64109                                     <<<<<<< SEARCH :10:
 64110                                     old code
 64111                                     =======
 64112                                     new code
 64113                                     >>>>>>> REPLACE
 64114                                     </function>
 64115
 64116                                     Example for multi replacments in one file:
 64117                                     <function name="{BuiltInToolEnum.ApplyDiff}">
 64118                                     C:\path\to\file.cs
 64119                                     <<<<<<< SEARCH
 64120                                     old code
 64121                                     =======
 64122                                     new code
 64123                                     >>>>>>> REPLACE
 64124
 64125                                     <<<<<<< SEARCH :40:
 64126                                         var z = "old code";
 64127                                     =======
 64128                                         // this is new code
 64129                                         var isNew = true;
 64130                                         var z = isNew ? "new code" : "old code";
 64131                                     >>>>>>> REPLACE
 64132                                     </function>
 64133                                     """,
 64134            NativeTool = BuiltInToolDefs.MapMethodToTool(typeof(BuiltInToolDefs).GetMethod(nameof(BuiltInToolDefs.ApplyD
 1135            ExecuteAsync = (args, c) => vsBridge.ExecuteToolAsync(BuiltInToolEnum.ApplyDiff, args, c)
 64136        },
 64137
 64138        // Search and navigation
 64139        new()
 64140        {
 64141            Name = BuiltInToolEnum.SearchFiles,
 64142            DisplayName = SharedResource.ToolSearchFiles,
 64143            Category = ToolCategory.ReadFiles,
 64144            Description = "To return a list of files with patches in solution directory based on a search regex pattern,
 64145            ExampleToSystemMessage = $"""
 64146                                     For example:
 64147                                     <function name="{BuiltInToolEnum.SearchFiles}">
 64148                                     ^.*\.cs$
 64149                                     </function>
 64150                                     """,
 0151            ExecuteAsync = (args, c) => vsBridge.ExecuteToolAsync(BuiltInToolEnum.SearchFiles, args, c)
 64152        },
 64153        new()
 64154        {
 64155            Name = BuiltInToolEnum.GrepSearch,
 64156            DisplayName = SharedResource.ToolGrepSearch,
 64157            Category = ToolCategory.ReadFiles,
 64158            Description = "To perform a grep search within the project, call the grep_search tool with the regex pattern
 64159            ExampleToSystemMessage = $"""
 64160                                     For example:
 64161                                     <function name="{BuiltInToolEnum.GrepSearch}">
 64162                                     ^.*?main_services.*
 64163                                     </function>
 64164                                     """,
 0165            ExecuteAsync = (args, c) => vsBridge.ExecuteToolAsync(BuiltInToolEnum.GrepSearch, args, c)
 64166        },
 64167        new()
 64168        {
 64169            Name = BuiltInToolEnum.Dir,
 64170            DisplayName = SharedResource.ToolDir,
 64171            Category = ToolCategory.ReadFiles,
 64172            Description = "To list files and folders in a given directory, call this tool with \"dirPath\" and \"recursi
 64173            ExampleToSystemMessage = $"""
 64174                                     For example:
 64175                                     <function name="{BuiltInToolEnum.Dir}">
 64176                                     C:\path\to\dir
 64177                                     false
 64178                                     </function>
 64179                                     """,
 0180            ExecuteAsync = (args, c) => vsBridge.ExecuteToolAsync(BuiltInToolEnum.Dir, args, c)
 64181        },
 64182
 64183        // Project and build
 64184        new()
 64185        {
 64186            Name = BuiltInToolEnum.Build,
 64187            DisplayName = SharedResource.ToolBuild,
 64188            Category = ToolCategory.ReadFiles,
 64189            Description = "To build solution in Visual Studio. With action - Build, Rebuild or Clean. When any errors re
 64190            ExampleToSystemMessage = $"""
 64191                                     For example:
 64192                                     <function name="{BuiltInToolEnum.Build}">
 64193                                     build
 64194                                     </function>
 64195                                     """,
 0196            ExecuteAsync = (args, c) => vsBridge.ExecuteToolAsync(BuiltInToolEnum.Build, args, c)
 64197        },
 64198        new()
 64199        {
 64200            Name = BuiltInToolEnum.RunTests,
 64201            DisplayName = SharedResource.ToolRunTests,
 64202            Category = ToolCategory.ReadFiles,
 64203            Description = "To run all tests in solution. When any errors returns errors list. Note: the solution build w
 64204            ExampleToSystemMessage = $"""
 64205                                     For example:
 64206                                     <function name="{BuiltInToolEnum.RunTests}">
 64207                                     </function>
 64208                                     """,
 0209            ExecuteAsync = (args, c) => vsBridge.ExecuteToolAsync(BuiltInToolEnum.RunTests, args, c)
 64210        },
 64211        new()
 64212        {
 64213            Name = BuiltInToolEnum.GetErrors,
 64214            DisplayName = SharedResource.ToolGetErrors,
 64215            Category = ToolCategory.ReadFiles,
 64216            Description = "To get error list of current solution and current file from Visual Studio.",
 64217            ExampleToSystemMessage = $"""
 64218                                     For example:
 64219                                     <function name="{BuiltInToolEnum.GetErrors}"></function>
 64220                                     """,
 0221            ExecuteAsync = (args, c) => vsBridge.ExecuteToolAsync(BuiltInToolEnum.GetErrors)
 64222        },
 64223        new()
 64224        {
 64225            Name = BuiltInToolEnum.GetProjectInfo,
 64226            DisplayName = SharedResource.ToolGetProjectInfo,
 64227            Category = ToolCategory.ReadFiles,
 64228            Description = "Get information about the solution and projects. Returns list of projects, their types, targe
 64229            ExampleToSystemMessage = $"""
 64230                                     For example:
 64231                                     <function name="{BuiltInToolEnum.GetProjectInfo}"></function>
 64232                                     """,
 0233            ExecuteAsync = (args, c) => vsBridge.ExecuteToolAsync(BuiltInToolEnum.GetProjectInfo, args, c)
 64234        },
 64235        new()
 64236        {
 64237            Name = BuiltInToolEnum.GetSolutionStructure,
 64238            DisplayName = SharedResource.ToolGetSolutionStructure,
 64239            Category = ToolCategory.ReadFiles,
 64240            Description = "Get a tree-like structure of the entire solution, including projects, folders, and files.",
 64241            ExampleToSystemMessage = $"""
 64242                                     For example:
 64243                                     <function name="{BuiltInToolEnum.GetSolutionStructure}"></function>
 64244                                     """,
 0245            ExecuteAsync = (args, c) => vsBridge.ExecuteToolAsync(BuiltInToolEnum.GetSolutionStructure)
 64246        },
 64247
 64248        // Execution
 64249        new()
 64250        {
 64251            Name = BuiltInToolEnum.Bash,
 64252            DisplayName = SharedResource.ToolExec,
 64253            Category = ToolCategory.Execution,
 64254            Description = """
 64255                          To run a shell command (Git Bash).
 64256                          The shell is stateless. Avoid using single quotes inside your commands if possible.
 64257                          When suggesting subsequent shell commands ALWAYS format them in shell command blocks.
 64258                          Do NOT perform actions requiring special/admin privileges.
 64259                          Choose terminal commands and scripts optimized for win32 and x64.
 64260                          """,
 64261            ExampleToSystemMessage = $"""
 64262                                      For example:
 64263                                      <function name="{BuiltInToolEnum.Bash}">
 64264                                      git diff HEAD
 64265                                      </function>
 64266                                      """,
 1267            ExecuteAsync = (args, c) => vsBridge.ExecuteToolAsync(BuiltInToolEnum.Bash, args, c)
 64268        },
 64269
 64270        // Git operations
 64271        new()
 64272        {
 64273            Name = BuiltInToolEnum.GitStatus,
 64274            DisplayName = SharedResource.ToolGitStatus,
 64275            Category = ToolCategory.ReadFiles,
 64276            Description = "Check git status of the current repository.",
 64277            ExampleToSystemMessage = $"""
 64278                                     For example:
 64279                                     <function name="{BuiltInToolEnum.GitStatus}">
 64280                                     </function>
 64281                                     """,
 0282            ExecuteAsync = (args, c) => vsBridge.ExecuteToolAsync(BuiltInToolEnum.GitStatus, args, c)
 64283        },
 64284        new()
 64285        {
 64286            Name = BuiltInToolEnum.GitLog,
 64287            DisplayName = SharedResource.ToolGitLog,
 64288            Category = ToolCategory.ReadFiles,
 64289            Description = "View git commit history with changed files in commits. Can specify number of commits to displ
 64290            ExampleToSystemMessage = $"""
 64291                                     For example:
 64292                                     <function name="{BuiltInToolEnum.GitLog}">
 64293                                     10
 64294                                     </function>
 64295                                     """,
 0296            ExecuteAsync = (args, c) => vsBridge.ExecuteToolAsync(BuiltInToolEnum.GitLog, args, c)
 64297        },
 64298        new()
 64299        {
 64300            Name = BuiltInToolEnum.GitDiff,
 64301            DisplayName = SharedResource.ToolGitDiff,
 64302            Category = ToolCategory.ReadFiles,
 64303            Description = "View full git diff for specific commit or HEAD.",
 64304            ExampleToSystemMessage = $"""
 64305                                     For example:
 64306                                     <function name="{BuiltInToolEnum.GitDiff}">
 64307                                     87b9cdf
 64308                                     </function>
 64309                                     """,
 0310            ExecuteAsync = (args, c) => vsBridge.ExecuteToolAsync(BuiltInToolEnum.GitDiff, args, c)
 64311        },
 64312        new()
 64313        {
 64314            Name = BasicEnum.SwitchMode,
 64315            DisplayName = SharedResource.ToolSwitchMode,
 64316            Category = ToolCategory.ModeSwitch,
 64317            Description = "Switch the current application mode. Available modes: Chat, Agent, Plan. Use this when you ne
 64318            ExampleToSystemMessage = $"""
 64319                                     For example, to switch to Agent mode:
 64320                                     <function name="{BasicEnum.SwitchMode}">
 64321                                     Agent
 64322                                     </function>
 64323                                     """,
 0324            ExecuteAsync = (args, c) => internalExecutor.ExecuteToolAsync(BasicEnum.SwitchMode, args, c)
 64325        },
 64326
 64327        // Skills
 64328        new()
 64329        {
 64330            Name = BasicEnum.ReadSkillContent,
 64331            DisplayName = SharedResource.ToolReadSkillContent,
 64332            Category = ToolCategory.ReadFiles,
 64333            Description = """
 64334                          Load the full content of a skill when you need detailed instructions.
 64335                          Skills are pre-listed in your system prompt with name and description.
 64336                          Use this tool only when you determine a skill is relevant to the current task.
 64337                          For parameter use skill name.
 64338                          """,
 64339            ExampleToSystemMessage = $"""
 64340                                     For example, to load a specific skill:
 64341                                     <function name="{BasicEnum.ReadSkillContent}">
 64342                                     Example skill name
 64343                                     </function>
 64344                                     """,
 64345            ExecuteAsync = skillService.LoadSkillContentMarkDownAsync
 64346        },
 64347        new()
 64348        {
 64349            Name = BuiltInToolEnum.DeleteFile,
 64350            DisplayName = SharedResource.ToolDeleteFile,
 64351            Category = ToolCategory.DeleteFiles,
 64352            Description = "To delete a file, use this tool with the relative or absolute filepath.",
 64353            ExampleToSystemMessage = $"""
 64354                                     For example, to delete a file located at 'path\\to\\file.cs', you would respond wit
 64355                                     <function name="{BuiltInToolEnum.DeleteFile}">
 64356                                     C:\path\to\file.cs
 64357                                     </function>
 64358                                     """,
 0359            ExecuteAsync = (args, c) => vsBridge.ExecuteToolAsync(BuiltInToolEnum.DeleteFile, args, c)
 64360        },
 64361
 64362        // TODO
 64363        // User interaction
 64364        //new()
 64365        //{
 64366        //    Name = BasicEnum.AskUser,
 64367        //    DisplayName = SharedResource.ToolAskUser,
 64368        //    Category = ToolCategory.ReadFiles,
 64369        //    Description = """
 64370        //                  Ask the user a question and present options for them to choose from.
 64371        //                  Use this when you need clarification or user input to proceed.
 64372        //                  The user can select one of the provided options or enter their own answer.
 64373        //                  Parameters:
 64374        //                  - question: The question to ask the user - first line
 64375        //                  - options: A list of options for the user to choose from (one per line)
 64376        //                  """,
 64377        //    ExampleToSystemMessage = $"""
 64378        //                             For example, to ask which file to open:
 64379        //                             <function name="{BasicEnum.AskUser}">
 64380        //                             Which file would you like me to open?
 64381        //                             src/main.cs
 64382        //                             src/utils.cs
 64383        //                             src/config.cs
 64384        //                             </function>
 64385        //                             """,
 64386        //    ExecuteAsync = (args, c) => internalExecutor.ExecuteToolAsync(BasicEnum.AskUser, args, c)
 64387        //}
 64388    ];
 389}