tools.go

  1package proto
  2
  3// The wire schema for per-tool permission parameters is owned by the
  4// tool itself, not duplicated here. We alias the canonical types so
  5// there is exactly one source of truth and so values survive a
  6// round-trip across the client/server boundary as the same Go type
  7// the UI asserts on.
  8import "github.com/charmbracelet/crush/internal/agent/tools"
  9
 10// ToolResponseType represents the type of tool response.
 11type ToolResponseType string
 12
 13const (
 14	ToolResponseTypeText  ToolResponseType = "text"
 15	ToolResponseTypeImage ToolResponseType = "image"
 16)
 17
 18// ToolResponse represents a response from a tool.
 19type ToolResponse struct {
 20	Type     ToolResponseType `json:"type"`
 21	Content  string           `json:"content"`
 22	Metadata string           `json:"metadata,omitempty"`
 23	IsError  bool             `json:"is_error"`
 24}
 25
 26const BashToolName = "bash"
 27
 28// BashParams represents the parameters for the bash tool.
 29type BashParams struct {
 30	Command string `json:"command"`
 31	Timeout int    `json:"timeout"`
 32}
 33
 34// BashPermissionsParams represents the permission parameters for the bash tool.
 35type BashPermissionsParams = tools.BashPermissionsParams
 36
 37// BashResponseMetadata represents the metadata for a bash tool response.
 38type BashResponseMetadata struct {
 39	StartTime        int64  `json:"start_time"`
 40	EndTime          int64  `json:"end_time"`
 41	Output           string `json:"output"`
 42	WorkingDirectory string `json:"working_directory"`
 43}
 44
 45// DiagnosticsParams represents the parameters for the diagnostics tool.
 46type DiagnosticsParams struct {
 47	FilePath string `json:"file_path"`
 48}
 49
 50const DownloadToolName = "download"
 51
 52// DownloadParams represents the parameters for the download tool.
 53type DownloadParams struct {
 54	URL      string `json:"url"`
 55	FilePath string `json:"file_path"`
 56	Timeout  int    `json:"timeout,omitempty"`
 57}
 58
 59// DownloadPermissionsParams represents the permission parameters for the download tool.
 60type DownloadPermissionsParams = tools.DownloadPermissionsParams
 61
 62const EditToolName = "edit"
 63
 64// EditParams represents the parameters for the edit tool.
 65type EditParams struct {
 66	FilePath   string `json:"file_path"`
 67	OldString  string `json:"old_string"`
 68	NewString  string `json:"new_string"`
 69	ReplaceAll bool   `json:"replace_all,omitempty"`
 70}
 71
 72// EditPermissionsParams represents the permission parameters for the edit tool.
 73type EditPermissionsParams = tools.EditPermissionsParams
 74
 75// EditResponseMetadata represents the metadata for an edit tool response.
 76type EditResponseMetadata struct {
 77	Additions  int    `json:"additions"`
 78	Removals   int    `json:"removals"`
 79	OldContent string `json:"old_content,omitempty"`
 80	NewContent string `json:"new_content,omitempty"`
 81}
 82
 83const FetchToolName = "fetch"
 84
 85// FetchParams represents the parameters for the fetch tool.
 86type FetchParams struct {
 87	URL     string `json:"url"`
 88	Format  string `json:"format"`
 89	Timeout int    `json:"timeout,omitempty"`
 90}
 91
 92// FetchPermissionsParams represents the permission parameters for the fetch tool.
 93type FetchPermissionsParams = tools.FetchPermissionsParams
 94
 95// AgenticFetchToolName is the name of the agentic_fetch tool.
 96const AgenticFetchToolName = tools.AgenticFetchToolName
 97
 98// AgenticFetchPermissionsParams represents the permission parameters for the
 99// agentic_fetch tool.
100type AgenticFetchPermissionsParams = tools.AgenticFetchPermissionsParams
101
102const GlobToolName = "glob"
103
104// GlobParams represents the parameters for the glob tool.
105type GlobParams struct {
106	Pattern string `json:"pattern"`
107	Path    string `json:"path"`
108}
109
110// GlobResponseMetadata represents the metadata for a glob tool response.
111type GlobResponseMetadata struct {
112	NumberOfFiles int  `json:"number_of_files"`
113	Truncated     bool `json:"truncated"`
114}
115
116const GrepToolName = "grep"
117
118// GrepParams represents the parameters for the grep tool.
119type GrepParams struct {
120	Pattern     string `json:"pattern"`
121	Path        string `json:"path"`
122	Include     string `json:"include"`
123	LiteralText bool   `json:"literal_text"`
124}
125
126// GrepResponseMetadata represents the metadata for a grep tool response.
127type GrepResponseMetadata struct {
128	NumberOfMatches int  `json:"number_of_matches"`
129	Truncated       bool `json:"truncated"`
130}
131
132const LSToolName = "ls"
133
134// LSParams represents the parameters for the ls tool.
135type LSParams struct {
136	Path   string   `json:"path"`
137	Ignore []string `json:"ignore"`
138}
139
140// LSPermissionsParams represents the permission parameters for the ls tool.
141type LSPermissionsParams = tools.LSPermissionsParams
142
143// TreeNode represents a node in a directory tree.
144type TreeNode struct {
145	Name     string      `json:"name"`
146	Path     string      `json:"path"`
147	Type     string      `json:"type"`
148	Children []*TreeNode `json:"children,omitempty"`
149}
150
151// LSResponseMetadata represents the metadata for an ls tool response.
152type LSResponseMetadata struct {
153	NumberOfFiles int  `json:"number_of_files"`
154	Truncated     bool `json:"truncated"`
155}
156
157const MultiEditToolName = "multiedit"
158
159// MultiEditOperation represents a single edit operation in a multi-edit.
160type MultiEditOperation struct {
161	OldString  string `json:"old_string"`
162	NewString  string `json:"new_string"`
163	ReplaceAll bool   `json:"replace_all,omitempty"`
164}
165
166// MultiEditParams represents the parameters for the multi-edit tool.
167type MultiEditParams struct {
168	FilePath string               `json:"file_path"`
169	Edits    []MultiEditOperation `json:"edits"`
170}
171
172// MultiEditPermissionsParams represents the permission parameters for the multi-edit tool.
173type MultiEditPermissionsParams = tools.MultiEditPermissionsParams
174
175// MultiEditResponseMetadata represents the metadata for a multi-edit tool response.
176type MultiEditResponseMetadata struct {
177	Additions    int    `json:"additions"`
178	Removals     int    `json:"removals"`
179	OldContent   string `json:"old_content,omitempty"`
180	NewContent   string `json:"new_content,omitempty"`
181	EditsApplied int    `json:"edits_applied"`
182}
183
184const SourcegraphToolName = "sourcegraph"
185
186// SourcegraphParams represents the parameters for the sourcegraph tool.
187type SourcegraphParams struct {
188	Query         string `json:"query"`
189	Count         int    `json:"count,omitempty"`
190	ContextWindow int    `json:"context_window,omitempty"`
191	Timeout       int    `json:"timeout,omitempty"`
192}
193
194// SourcegraphResponseMetadata represents the metadata for a sourcegraph tool response.
195type SourcegraphResponseMetadata struct {
196	NumberOfMatches int  `json:"number_of_matches"`
197	Truncated       bool `json:"truncated"`
198}
199
200const ViewToolName = "view"
201
202// ViewParams represents the parameters for the view tool.
203type ViewParams struct {
204	FilePath string `json:"file_path"`
205	Offset   int    `json:"offset"`
206	Limit    int    `json:"limit"`
207}
208
209// ViewPermissionsParams represents the permission parameters for the view tool.
210type ViewPermissionsParams = tools.ViewPermissionsParams
211
212// ViewResponseMetadata represents the metadata for a view tool response.
213type ViewResponseMetadata struct {
214	FilePath string `json:"file_path"`
215	Content  string `json:"content"`
216}
217
218const WriteToolName = "write"
219
220// WriteParams represents the parameters for the write tool.
221type WriteParams struct {
222	FilePath string `json:"file_path"`
223	Content  string `json:"content"`
224}
225
226// WritePermissionsParams represents the permission parameters for the write tool.
227type WritePermissionsParams = tools.WritePermissionsParams
228
229// WriteResponseMetadata represents the metadata for a write tool response.
230type WriteResponseMetadata struct {
231	Diff      string `json:"diff"`
232	Additions int    `json:"additions"`
233	Removals  int    `json:"removals"`
234}