| | | 1 | | using UIBlazor.Services; |
| | | 2 | | |
| | | 3 | | namespace UIBlazor.Agents; |
| | | 4 | | |
| | 16 | 5 | | public class BuiltInAgent(IVsBridge vsBridge, ISkillService skillService) |
| | | 6 | | { |
| | 16 | 7 | | public IReadOnlyList<Tool> Tools = |
| | 16 | 8 | | [ |
| | 16 | 9 | | // File operations |
| | 16 | 10 | | new() |
| | 16 | 11 | | { |
| | 16 | 12 | | Name = BuiltInToolEnum.ReadFiles, |
| | 16 | 13 | | DisplayName = SharedResource.ToolReadFiles, |
| | 16 | 14 | | Category = ToolCategory.ReadFiles, |
| | 16 | 15 | | Description = "Request to read the contents of one or more files. Use start_line and line_count to read spec |
| | 16 | 16 | | ExampleToSystemMessage = $""" |
| | 16 | 17 | | For example, to read a specific range: |
| | 16 | 18 | | <function name="{BuiltInToolEnum.ReadFiles}"> |
| | 16 | 19 | | path/to/large_file.cs |
| | 16 | 20 | | start_line |
| | 16 | 21 | | 100 |
| | 16 | 22 | | line_count |
| | 16 | 23 | | 50 |
| | 16 | 24 | | </function> |
| | 16 | 25 | | |
| | 16 | 26 | | Or to read the entire file: |
| | 16 | 27 | | <function name="{BuiltInToolEnum.ReadFiles}"> |
| | 16 | 28 | | path/to/file.cs |
| | 16 | 29 | | path/to/file2.cs |
| | 16 | 30 | | </function> |
| | 16 | 31 | | """, |
| | 1 | 32 | | ExecuteAsync = (args) => vsBridge.ExecuteToolAsync(BuiltInToolEnum.ReadFiles, args) |
| | 16 | 33 | | }, |
| | 16 | 34 | | new() |
| | 16 | 35 | | { |
| | 16 | 36 | | Name = BuiltInToolEnum.ReadOpenFile, |
| | 16 | 37 | | DisplayName = SharedResource.ToolReadOpenFile, |
| | 16 | 38 | | Category = ToolCategory.ReadFiles, |
| | 16 | 39 | | Description = $""" |
| | 16 | 40 | | To view the user's currently open file, use the {BuiltInToolEnum.ReadOpenFile} tool. |
| | 16 | 41 | | The tool returns the absolute file path and its line-numbered content (e.g. "1 | const x = 1") |
| | 16 | 42 | | If the user is asking about a file and you don't see any code, use this to check the current f |
| | 16 | 43 | | """, |
| | 16 | 44 | | ExampleToSystemMessage = $""" |
| | 16 | 45 | | For example |
| | 16 | 46 | | <function name="{BuiltInToolEnum.ReadOpenFile}"></function> |
| | 16 | 47 | | """, |
| | 0 | 48 | | ExecuteAsync = (args) => vsBridge.ExecuteToolAsync(BuiltInToolEnum.ReadOpenFile, args) |
| | 16 | 49 | | }, |
| | 16 | 50 | | new() |
| | 16 | 51 | | { |
| | 16 | 52 | | Name = BuiltInToolEnum.CreateFile, |
| | 16 | 53 | | DisplayName = SharedResource.ToolCreateFile, |
| | 16 | 54 | | Category = ToolCategory.WriteFiles, |
| | 16 | 55 | | Description = "To create a NEW file with the relative or absolute filepath and new contents.", |
| | 16 | 56 | | ExampleToSystemMessage = $""" |
| | 16 | 57 | | For example, to create a file located at 'path\to\file.cs', you would respond with: |
| | 16 | 58 | | <function name="{BuiltInToolEnum.CreateFile}"> |
| | 16 | 59 | | \path\to\file.cs |
| | 16 | 60 | | Contents of the file. |
| | 16 | 61 | | And second line of this file. |
| | 16 | 62 | | </function> |
| | 16 | 63 | | """, |
| | 0 | 64 | | ExecuteAsync = (args) => vsBridge.ExecuteToolAsync(BuiltInToolEnum.CreateFile, args) |
| | 16 | 65 | | }, |
| | 16 | 66 | | new() |
| | 16 | 67 | | { |
| | 16 | 68 | | Name = BuiltInToolEnum.ApplyDiff, |
| | 16 | 69 | | DisplayName = SharedResource.ToolApplyDiff, |
| | 16 | 70 | | Category = ToolCategory.WriteFiles, |
| | 16 | 71 | | Description = $""" |
| | 16 | 72 | | Request to apply PRECISE, TARGETED modifications to an existing file by searching for specific |
| | 16 | 73 | | You can perform multiple distinct search and replace operations within a single `{BuiltInToolE |
| | 16 | 74 | | The SEARCH section must exactly match existing content including whitespace and indentation. |
| | 16 | 75 | | If you're not confident in the exact content to search for, use the {BuiltInToolEnum.ReadFiles |
| | 16 | 76 | | When applying the diffs, be extra careful to remember to change any closing brackets or other |
| | 16 | 77 | | ALWAYS make as many changes in a single '{BuiltInToolEnum.ApplyDiff}' request as possible usin |
| | 16 | 78 | | An optional ":start_line:". The search will be 5 lines up and down. |
| | 16 | 79 | | """, |
| | 16 | 80 | | ExampleToSystemMessage = $""" |
| | 16 | 81 | | For example: |
| | 16 | 82 | | <function name="{BuiltInToolEnum.ApplyDiff}"> |
| | 16 | 83 | | C:\path\to\file.cs |
| | 16 | 84 | | :start_line:10 |
| | 16 | 85 | | <<<<<<< SEARCH |
| | 16 | 86 | | old code |
| | 16 | 87 | | ======= |
| | 16 | 88 | | new code |
| | 16 | 89 | | >>>>>>> REPLACE |
| | 16 | 90 | | </function> |
| | 16 | 91 | | |
| | 16 | 92 | | <function name="{BuiltInToolEnum.ApplyDiff}"> |
| | 16 | 93 | | C:\path\to\file222.cs |
| | 16 | 94 | | <<<<<<< SEARCH |
| | 16 | 95 | | old code |
| | 16 | 96 | | ======= |
| | 16 | 97 | | new code |
| | 16 | 98 | | >>>>>>> REPLACE |
| | 16 | 99 | | |
| | 16 | 100 | | :start_line:40 |
| | 16 | 101 | | <<<<<<< SEARCH |
| | 16 | 102 | | var z = "old code"; |
| | 16 | 103 | | ======= |
| | 16 | 104 | | var isNew = true; |
| | 16 | 105 | | var z = isNew ? "new code" : "old code"; |
| | 16 | 106 | | >>>>>>> REPLACE |
| | 16 | 107 | | </function> |
| | 16 | 108 | | """, |
| | 1 | 109 | | ExecuteAsync = (args) => vsBridge.ExecuteToolAsync(BuiltInToolEnum.ApplyDiff, args) |
| | 16 | 110 | | }, |
| | 16 | 111 | | |
| | 16 | 112 | | // Search and navigation |
| | 16 | 113 | | new() |
| | 16 | 114 | | { |
| | 16 | 115 | | Name = BuiltInToolEnum.SearchFiles, |
| | 16 | 116 | | DisplayName = SharedResource.ToolSearchFiles, |
| | 16 | 117 | | Category = ToolCategory.ReadFiles, |
| | 16 | 118 | | Description = "To return a list of files with patches in solution directory based on a search regex pattern, |
| | 16 | 119 | | ExampleToSystemMessage = $""" |
| | 16 | 120 | | For example: |
| | 16 | 121 | | <function name="{BuiltInToolEnum.SearchFiles}"> |
| | 16 | 122 | | ^.*\.cs$ |
| | 16 | 123 | | </function> |
| | 16 | 124 | | """, |
| | 0 | 125 | | ExecuteAsync = (args) => vsBridge.ExecuteToolAsync(BuiltInToolEnum.SearchFiles, args) |
| | 16 | 126 | | }, |
| | 16 | 127 | | new() |
| | 16 | 128 | | { |
| | 16 | 129 | | Name = BuiltInToolEnum.GrepSearch, |
| | 16 | 130 | | DisplayName = SharedResource.ToolGrepSearch, |
| | 16 | 131 | | Category = ToolCategory.ReadFiles, |
| | 16 | 132 | | Description = "To perform a grep search within the project, call the grep_search tool with the regex pattern |
| | 16 | 133 | | ExampleToSystemMessage = $""" |
| | 16 | 134 | | For example: |
| | 16 | 135 | | <function name="{BuiltInToolEnum.GrepSearch}"> |
| | 16 | 136 | | ^.*?main_services.* |
| | 16 | 137 | | </function> |
| | 16 | 138 | | """, |
| | 0 | 139 | | ExecuteAsync = (args) => vsBridge.ExecuteToolAsync(BuiltInToolEnum.GrepSearch, args) |
| | 16 | 140 | | }, |
| | 16 | 141 | | new() |
| | 16 | 142 | | { |
| | 16 | 143 | | Name = BuiltInToolEnum.Dir, |
| | 16 | 144 | | DisplayName = SharedResource.ToolDir, |
| | 16 | 145 | | Category = ToolCategory.ReadFiles, |
| | 16 | 146 | | Description = "To list files and folders in a given directory, call this tool with \"dirPath\" and \"recursi |
| | 16 | 147 | | ExampleToSystemMessage = $""" |
| | 16 | 148 | | For example: |
| | 16 | 149 | | <function name="{BuiltInToolEnum.Dir}"> |
| | 16 | 150 | | C:\path\to\dir |
| | 16 | 151 | | false |
| | 16 | 152 | | </function> |
| | 16 | 153 | | """, |
| | 0 | 154 | | ExecuteAsync = (args) => vsBridge.ExecuteToolAsync(BuiltInToolEnum.Dir, args) |
| | 16 | 155 | | }, |
| | 16 | 156 | | |
| | 16 | 157 | | // Project and build |
| | 16 | 158 | | new() |
| | 16 | 159 | | { |
| | 16 | 160 | | Name = BuiltInToolEnum.Build, |
| | 16 | 161 | | DisplayName = SharedResource.ToolBuild, |
| | 16 | 162 | | Category = ToolCategory.Execution, |
| | 16 | 163 | | Description = "To build solution in Visual Studio. With action - Build, Rebuild or Clean. When any errors re |
| | 16 | 164 | | ExampleToSystemMessage = $""" |
| | 16 | 165 | | For example: |
| | 16 | 166 | | <function name="{BuiltInToolEnum.Build}"> |
| | 16 | 167 | | build |
| | 16 | 168 | | </function> |
| | 16 | 169 | | """, |
| | 0 | 170 | | ExecuteAsync = (args) => vsBridge.ExecuteToolAsync(BuiltInToolEnum.Build, args) |
| | 16 | 171 | | }, |
| | 16 | 172 | | new() |
| | 16 | 173 | | { |
| | 16 | 174 | | Name = BuiltInToolEnum.GetErrors, |
| | 16 | 175 | | DisplayName = SharedResource.ToolGetErrors, |
| | 16 | 176 | | Category = ToolCategory.ReadFiles, |
| | 16 | 177 | | Description = "To get error list of current solution and current file from Visual Studio.", |
| | 16 | 178 | | ExampleToSystemMessage = $""" |
| | 16 | 179 | | For example: |
| | 16 | 180 | | <function name="{BuiltInToolEnum.GetErrors}"></function> |
| | 16 | 181 | | """, |
| | 0 | 182 | | ExecuteAsync = (args) => vsBridge.ExecuteToolAsync(BuiltInToolEnum.GetErrors) |
| | 16 | 183 | | }, |
| | 16 | 184 | | new() |
| | 16 | 185 | | { |
| | 16 | 186 | | Name = BuiltInToolEnum.GetProjectInfo, |
| | 16 | 187 | | DisplayName = SharedResource.ToolGetProjectInfo, |
| | 16 | 188 | | Category = ToolCategory.ReadFiles, |
| | 16 | 189 | | Description = "Get information about the solution and projects. Returns list of projects, their types, targe |
| | 16 | 190 | | ExampleToSystemMessage = $""" |
| | 16 | 191 | | For example: |
| | 16 | 192 | | <function name="{BuiltInToolEnum.GetProjectInfo}"></function> |
| | 16 | 193 | | """, |
| | 0 | 194 | | ExecuteAsync = (args) => vsBridge.ExecuteToolAsync(BuiltInToolEnum.GetProjectInfo, args) |
| | 16 | 195 | | }, |
| | 16 | 196 | | new() |
| | 16 | 197 | | { |
| | 16 | 198 | | Name = BuiltInToolEnum.GetSolutionStructure, |
| | 16 | 199 | | DisplayName = SharedResource.ToolGetSolutionStructure, |
| | 16 | 200 | | Category = ToolCategory.ReadFiles, |
| | 16 | 201 | | Description = "Get a tree-like structure of the entire solution, including projects, folders, and files.", |
| | 16 | 202 | | ExampleToSystemMessage = $""" |
| | 16 | 203 | | For example: |
| | 16 | 204 | | <function name="{BuiltInToolEnum.GetSolutionStructure}"></function> |
| | 16 | 205 | | """, |
| | 0 | 206 | | ExecuteAsync = (args) => vsBridge.ExecuteToolAsync(BuiltInToolEnum.GetSolutionStructure) |
| | 16 | 207 | | }, |
| | 16 | 208 | | |
| | 16 | 209 | | // Execution |
| | 16 | 210 | | new() |
| | 16 | 211 | | { |
| | 16 | 212 | | Name = BuiltInToolEnum.Exec, |
| | 16 | 213 | | DisplayName = SharedResource.ToolExec, |
| | 16 | 214 | | Category = ToolCategory.Execution, |
| | 16 | 215 | | Description = """ |
| | 16 | 216 | | To run a terminal command, use the execute_command tool in |
| | 16 | 217 | | The shell is not stateful and will not remember any previous commands. |
| | 16 | 218 | | When a command is run in the background ALWAYS suggest using shell commands to stop it; NEVER |
| | 16 | 219 | | When suggesting subsequent shell commands ALWAYS format them in shell command blocks. |
| | 16 | 220 | | Do NOT perform actions requiring special/admin privileges. |
| | 16 | 221 | | Choose terminal commands and scripts optimized for win32 and x64. |
| | 16 | 222 | | You can also optionally include the waitForCompletion argument set to false to run the command |
| | 16 | 223 | | """, |
| | 16 | 224 | | ExampleToSystemMessage = $""" |
| | 16 | 225 | | For example, to see the git log, you could respond with: |
| | 16 | 226 | | <function name="{BuiltInToolEnum.Exec}"> |
| | 16 | 227 | | dotnet restore |
| | 16 | 228 | | </function> |
| | 16 | 229 | | """, |
| | 1 | 230 | | ExecuteAsync = (args) => vsBridge.ExecuteToolAsync(BuiltInToolEnum.Exec, args) |
| | 16 | 231 | | }, |
| | 16 | 232 | | |
| | 16 | 233 | | // Git operations |
| | 16 | 234 | | new() |
| | 16 | 235 | | { |
| | 16 | 236 | | Name = BuiltInToolEnum.GitStatus, |
| | 16 | 237 | | DisplayName = SharedResource.ToolGitStatus, |
| | 16 | 238 | | Category = ToolCategory.ReadFiles, |
| | 16 | 239 | | Description = "Check git status of the current repository. Shows modified, staged, and untracked files.", |
| | 16 | 240 | | ExampleToSystemMessage = $""" |
| | 16 | 241 | | For example: |
| | 16 | 242 | | <function name="{BuiltInToolEnum.GitStatus}"></function> |
| | 16 | 243 | | """, |
| | 0 | 244 | | ExecuteAsync = (args) => vsBridge.ExecuteToolAsync(BuiltInToolEnum.GitStatus, args) |
| | 16 | 245 | | }, |
| | 16 | 246 | | new() |
| | 16 | 247 | | { |
| | 16 | 248 | | Name = BuiltInToolEnum.GitLog, |
| | 16 | 249 | | DisplayName = SharedResource.ToolGitLog, |
| | 16 | 250 | | Category = ToolCategory.ReadFiles, |
| | 16 | 251 | | Description = "View git commit history. Can specify number of commits to display.", |
| | 16 | 252 | | ExampleToSystemMessage = $""" |
| | 16 | 253 | | For example: |
| | 16 | 254 | | <function name="{BuiltInToolEnum.GitLog}"> |
| | 16 | 255 | | 10 |
| | 16 | 256 | | </function> |
| | 16 | 257 | | """, |
| | 0 | 258 | | ExecuteAsync = (args) => vsBridge.ExecuteToolAsync(BuiltInToolEnum.GitLog, args) |
| | 16 | 259 | | }, |
| | 16 | 260 | | new() |
| | 16 | 261 | | { |
| | 16 | 262 | | Name = BuiltInToolEnum.GitDiff, |
| | 16 | 263 | | DisplayName = SharedResource.ToolGitDiff, |
| | 16 | 264 | | Category = ToolCategory.ReadFiles, |
| | 16 | 265 | | Description = "View git diff for files. Can compare working directory with staged or specific commits.", |
| | 16 | 266 | | ExampleToSystemMessage = $""" |
| | 16 | 267 | | For example: |
| | 16 | 268 | | <function name="{BuiltInToolEnum.GitDiff}"> |
| | 16 | 269 | | false |
| | 16 | 270 | | </function> |
| | 16 | 271 | | """, |
| | 0 | 272 | | ExecuteAsync = (args) => vsBridge.ExecuteToolAsync(BuiltInToolEnum.GitDiff, args) |
| | 16 | 273 | | }, |
| | 16 | 274 | | new() |
| | 16 | 275 | | { |
| | 16 | 276 | | Name = BuiltInToolEnum.GitBranch, |
| | 16 | 277 | | DisplayName = SharedResource.ToolGitBranches, |
| | 16 | 278 | | Category = ToolCategory.ReadFiles, |
| | 16 | 279 | | Description = "List git branches or get current branch information.", |
| | 16 | 280 | | ExampleToSystemMessage = $""" |
| | 16 | 281 | | For example: |
| | 16 | 282 | | <function name="{BuiltInToolEnum.GitBranch}"></function> |
| | 16 | 283 | | """, |
| | 0 | 284 | | ExecuteAsync = (args) => vsBridge.ExecuteToolAsync(BuiltInToolEnum.GitBranch, args) |
| | 16 | 285 | | }, |
| | 16 | 286 | | new() |
| | 16 | 287 | | { |
| | 16 | 288 | | Name = BasicEnum.SwitchMode, |
| | 16 | 289 | | DisplayName = SharedResource.ToolSwitchMode, |
| | 16 | 290 | | Category = ToolCategory.ModeSwitch, |
| | 16 | 291 | | Description = "Switch the current application mode. Available modes: Chat, Agent, Plan. Use this when you ne |
| | 16 | 292 | | ExampleToSystemMessage = $""" |
| | 16 | 293 | | For example, to switch to Agent mode: |
| | 16 | 294 | | <function name="{BasicEnum.SwitchMode}"> |
| | 16 | 295 | | Agent |
| | 16 | 296 | | </function> |
| | 16 | 297 | | """, |
| | 16 | 298 | | // TODO тут нужен другой класс, например internalToolExec и туда же отправить браузер |
| | 0 | 299 | | ExecuteAsync = (args) => vsBridge.ExecuteToolAsync(BasicEnum.SwitchMode, args) |
| | 16 | 300 | | }, |
| | 16 | 301 | | |
| | 16 | 302 | | // Skills |
| | 16 | 303 | | new() |
| | 16 | 304 | | { |
| | 16 | 305 | | Name = BasicEnum.ReadSkillContent, |
| | 16 | 306 | | DisplayName = SharedResource.ToolReadSkillContent, |
| | 16 | 307 | | Category = ToolCategory.ReadFiles, |
| | 16 | 308 | | Description = """ |
| | 16 | 309 | | Load the full content of a skill when you need detailed instructions. |
| | 16 | 310 | | Skills are pre-listed in your system prompt with name and description. |
| | 16 | 311 | | Use this tool only when you determine a skill is relevant to the current task. |
| | 16 | 312 | | For parameter use skill name. |
| | 16 | 313 | | """, |
| | 16 | 314 | | ExampleToSystemMessage = $""" |
| | 16 | 315 | | For example, to load a specific skill: |
| | 16 | 316 | | <function name="{BasicEnum.ReadSkillContent}"> |
| | 16 | 317 | | ExampleSkillNameForWriteTests |
| | 16 | 318 | | </function> |
| | 16 | 319 | | """, |
| | 0 | 320 | | ExecuteAsync = (args) => skillService.LoadSkillContentMarkDownAsync(args) |
| | 16 | 321 | | }, |
| | 16 | 322 | | new() |
| | 16 | 323 | | { |
| | 16 | 324 | | Name = BuiltInToolEnum.DeleteFile, |
| | 16 | 325 | | DisplayName = SharedResource.ToolDeleteFile, |
| | 16 | 326 | | Category = ToolCategory.DeleteFiles, |
| | 16 | 327 | | Description = "To delete a file, use this tool with the relative or absolute filepath.", |
| | 16 | 328 | | ExampleToSystemMessage = $""" |
| | 16 | 329 | | For example, to delete a file located at 'path\\to\\file.cs', you would respond wit |
| | 16 | 330 | | <function name="{BuiltInToolEnum.DeleteFile}"> |
| | 16 | 331 | | C:\path\to\file.cs |
| | 16 | 332 | | </function> |
| | 16 | 333 | | """, |
| | 0 | 334 | | ExecuteAsync = (args) => vsBridge.ExecuteToolAsync(BuiltInToolEnum.DeleteFile, args) |
| | 16 | 335 | | } |
| | 16 | 336 | | ]; |
| | | 337 | | } |