summaryrefslogtreecommitdiffhomepage
path: root/internal/llm/agent/tools.go
blob: 157b5bf5972446d685287158d8a996821dac974e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package agent

import (
	"context"

	"github.com/sst/opencode/internal/history"
	"github.com/sst/opencode/internal/llm/tools"
	"github.com/sst/opencode/internal/lsp"
	"github.com/sst/opencode/internal/message"
	"github.com/sst/opencode/internal/permission"
	"github.com/sst/opencode/internal/session"
)

func PrimaryAgentTools(
	permissions permission.Service,
	sessions session.Service,
	messages message.Service,
	history history.Service,
	lspClients map[string]*lsp.Client,
) []tools.BaseTool {
	ctx := context.Background()
	mcpTools := GetMcpTools(ctx, permissions)

	// Create the list of tools
	toolsList := []tools.BaseTool{
		tools.NewBashTool(permissions),
		tools.NewEditTool(lspClients, permissions, history),
		tools.NewFetchTool(permissions),
		tools.NewGlobTool(),
		tools.NewGrepTool(),
		tools.NewLsTool(),
		tools.NewViewTool(lspClients),
		tools.NewPatchTool(lspClients, permissions, history),
		tools.NewWriteTool(lspClients, permissions, history),
		tools.NewDiagnosticsTool(lspClients),
		tools.NewDefinitionTool(lspClients),
		tools.NewReferencesTool(lspClients),
		tools.NewDocSymbolsTool(lspClients),
		tools.NewWorkspaceSymbolsTool(lspClients),
		tools.NewCodeActionTool(lspClients),
		NewAgentTool(sessions, messages, lspClients),
	}

	// Create a map of tools for the batch tool
	toolsMap := make(map[string]tools.BaseTool)
	for _, tool := range toolsList {
		toolsMap[tool.Info().Name] = tool
	}

	// Add the batch tool with access to all other tools
	toolsList = append(toolsList, tools.NewBatchTool(toolsMap))

	return append(toolsList, mcpTools...)
}

func TaskAgentTools(lspClients map[string]*lsp.Client) []tools.BaseTool {
	// Create the list of tools
	toolsList := []tools.BaseTool{
		tools.NewGlobTool(),
		tools.NewGrepTool(),
		tools.NewLsTool(),
		tools.NewViewTool(lspClients),
		tools.NewDefinitionTool(lspClients),
		tools.NewReferencesTool(lspClients),
		tools.NewDocSymbolsTool(lspClients),
		tools.NewWorkspaceSymbolsTool(lspClients),
	}

	// Create a map of tools for the batch tool
	toolsMap := make(map[string]tools.BaseTool)
	for _, tool := range toolsList {
		toolsMap[tool.Info().Name] = tool
	}

	// Add the batch tool with access to all other tools
	toolsList = append(toolsList, tools.NewBatchTool(toolsMap))

	return toolsList
}