tools.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package agent
  2. import (
  3. "context"
  4. "github.com/sst/opencode/internal/history"
  5. "github.com/sst/opencode/internal/llm/tools"
  6. "github.com/sst/opencode/internal/lsp"
  7. "github.com/sst/opencode/internal/message"
  8. "github.com/sst/opencode/internal/permission"
  9. "github.com/sst/opencode/internal/session"
  10. )
  11. func PrimaryAgentTools(
  12. permissions permission.Service,
  13. sessions session.Service,
  14. messages message.Service,
  15. history history.Service,
  16. lspClients map[string]*lsp.Client,
  17. ) []tools.BaseTool {
  18. ctx := context.Background()
  19. mcpTools := GetMcpTools(ctx, permissions)
  20. // Create the list of tools
  21. toolsList := []tools.BaseTool{
  22. tools.NewBashTool(permissions),
  23. tools.NewEditTool(lspClients, permissions, history),
  24. tools.NewFetchTool(permissions),
  25. tools.NewGlobTool(),
  26. tools.NewGrepTool(),
  27. tools.NewLsTool(),
  28. tools.NewViewTool(lspClients),
  29. tools.NewPatchTool(lspClients, permissions, history),
  30. tools.NewWriteTool(lspClients, permissions, history),
  31. tools.NewDiagnosticsTool(lspClients),
  32. tools.NewDefinitionTool(lspClients),
  33. tools.NewReferencesTool(lspClients),
  34. tools.NewDocSymbolsTool(lspClients),
  35. tools.NewWorkspaceSymbolsTool(lspClients),
  36. tools.NewCodeActionTool(lspClients),
  37. NewAgentTool(sessions, messages, lspClients),
  38. }
  39. // Create a map of tools for the batch tool
  40. toolsMap := make(map[string]tools.BaseTool)
  41. for _, tool := range toolsList {
  42. toolsMap[tool.Info().Name] = tool
  43. }
  44. // Add the batch tool with access to all other tools
  45. toolsList = append(toolsList, tools.NewBatchTool(toolsMap))
  46. return append(toolsList, mcpTools...)
  47. }
  48. func TaskAgentTools(lspClients map[string]*lsp.Client) []tools.BaseTool {
  49. // Create the list of tools
  50. toolsList := []tools.BaseTool{
  51. tools.NewGlobTool(),
  52. tools.NewGrepTool(),
  53. tools.NewLsTool(),
  54. tools.NewViewTool(lspClients),
  55. tools.NewDefinitionTool(lspClients),
  56. tools.NewReferencesTool(lspClients),
  57. tools.NewDocSymbolsTool(lspClients),
  58. tools.NewWorkspaceSymbolsTool(lspClients),
  59. }
  60. // Create a map of tools for the batch tool
  61. toolsMap := make(map[string]tools.BaseTool)
  62. for _, tool := range toolsList {
  63. toolsMap[tool.Info().Name] = tool
  64. }
  65. // Add the batch tool with access to all other tools
  66. toolsList = append(toolsList, tools.NewBatchTool(toolsMap))
  67. return toolsList
  68. }