-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlocal_tools.py
More file actions
265 lines (237 loc) · 8.36 KB
/
Copy pathlocal_tools.py
File metadata and controls
265 lines (237 loc) · 8.36 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
"""
Copyright (c) 2025 Xpander, Inc. All rights reserved.
"""
from typing import Dict, Any, Optional
import sandbox
# === Local Tool Wrappers ===
def git_clone(repo_url: str, branch: Optional[str] = None) -> Dict[str, Any]:
"""
Clone a Git repository into the sandbox.
Args:
repo_url (str): URL of the Git repository to clone.
branch (Optional[str]): Optional branch to clone (default: main branch).
Returns:
Dict[str, Any]: Dictionary with clone status and message.
"""
return sandbox.git_clone(repo_url, branch)
def describe_folders_and_files() -> Dict[str, Any]:
"""
List all files and folders in the sandbox in a tree structure.
Returns:
Dict[str, Any]: Dictionary with tree structure of files and folders.
"""
return sandbox.describe_folders_and_files()
def edit_file(file_path: str, content: str) -> Dict[str, Any]:
"""
Edit a file in the sandbox with provided content.
Args:
file_path (str): Path to the file to edit.
content (str): New content for the file.
Returns:
Dict[str, Any]: Dictionary with edit status and message.
"""
if file_path.endswith('.py'):
content = content.replace('\\"\\"\\"', '"""')
return sandbox.edit_file(file_path, content)
def new_file(file_path: str, content: str) -> Dict[str, Any]:
"""
Create a new file in the sandbox with provided content.
Args:
file_path (str): Path to the file to create.
content (str): Content for the new file.
Returns:
Dict[str, Any]: Dictionary with creation status and message.
"""
if file_path.endswith('.py'):
content = content.replace('\\"\\"\\"', '"""')
return sandbox.new_file(file_path, content)
def read_file(file_path: str) -> Dict[str, Any]:
"""
Read a file from the sandbox.
Args:
file_path (str): Path to the file to read.
Returns:
Dict[str, Any]: Dictionary with file content and status.
"""
return sandbox.read_file(file_path)
def commit(message: str, branch_name: str, repository: Optional[str] = None) -> Dict[str, Any]:
"""
Commit changes and push to a new branch.
Args:
message (str): Commit message.
branch_name (str): Name of the branch to create and push to.
repository (Optional[str]): Name of the repository to commit to (if not specified, uses the first found).
Returns:
Dict[str, Any]: Dictionary with commit status and message.
"""
return sandbox.commit(message, branch_name, repository)
def git_switch_branch(branch: str, path: str) -> Dict[str, Any]:
"""
Switch to a different Git branch in the given sandbox path.
Args:
branch (str): Branch to switch to.
path (str): Path to the Git working directory (sandbox).
Returns:
Dict[str, Any]: Dictionary with switch status and message.
"""
return sandbox.git_switch_branch(branch, path)
# === Local Tools Declarations ===
local_tools = [
{
"declaration": {
"type": "function",
"function": {
"name": "git_clone",
"description": "Clone a Git repository into the sandbox",
"parameters": {
"type": "object",
"properties": {
"repo_url": {
"type": "string",
"description": "URL of the Git repository to clone"
}
},
"required": ["repo_url"]
}
}
},
"fn": git_clone
},
{
"declaration": {
"type": "function",
"function": {
"name": "describe_folders_and_files",
"description": "List all files and folders in the sandbox in a tree structure",
"parameters": {
"type": "object",
"properties": {},
"required": []
}
}
},
"fn": describe_folders_and_files
},
{
"declaration": {
"type": "function",
"function": {
"name": "edit_file",
"description": "Edit a file in the sandbox",
"parameters": {
"type": "object",
"properties": {
"file_path": {
"type": "string",
"description": "Path to the file to edit"
},
"content": {
"type": "string",
"description": "New content for the file"
}
},
"required": ["file_path", "content"]
}
}
},
"fn": edit_file
},
{
"declaration": {
"type": "function",
"function": {
"name": "new_file",
"description": "Create a new file in the sandbox",
"parameters": {
"type": "object",
"properties": {
"file_path": {
"type": "string",
"description": "Path to the file to create"
},
"content": {
"type": "string",
"description": "Content for the new file"
}
},
"required": ["file_path", "content"]
}
}
},
"fn": new_file
},
{
"declaration": {
"type": "function",
"function": {
"name": "read_file",
"description": "Read a file from the sandbox",
"parameters": {
"type": "object",
"properties": {
"file_path": {
"type": "string",
"description": "Path to the file to read"
}
},
"required": ["file_path"]
}
}
},
"fn": read_file
},
{
"declaration": {
"type": "function",
"function": {
"name": "commit",
"description": "Commit changes and push to a new branch",
"parameters": {
"type": "object",
"properties": {
"message": {
"type": "string",
"description": "Commit message"
},
"branch_name": {
"type": "string",
"description": "Name of the branch to create and push to"
},
"repository": {
"type": "string",
"description": "Name of the repository to commit to (optional)"
}
},
"required": ["message", "branch_name"]
}
}
},
"fn": commit
},
{
"declaration": {
"type": "function",
"function": {
"name": "git_switch_branch",
"description": "Switch to a different Git branch in the sandbox. ONLY when continuing work on existing branch. never when creating a new branch",
"parameters": {
"type": "object",
"properties": {
"branch": {
"type": "string",
"description": "Name of the Git branch to switch to (EXISTING BRANCH ONLY!)"
},
"path": {
"type": "string",
"description": "Path to the Git working directory (sandbox)"
}
},
"required": ["branch", "path"]
}
}
},
"fn": git_switch_branch
}
]
local_tools_list = [tool['declaration'] for tool in local_tools]
local_tools_by_name = {tool['declaration']['function']['name']: tool['fn'] for tool in local_tools}