MCPcopy Create free account
hub / github.com/vercel/examples / rename_folder

Function rename_folder

python/vibe-coding-ide/backend/src/agent/tools/fs_ops.py:274–343  ·  view source on GitHub ↗

Rename or move a folder and all contained files. Behavior: - Rewrites affected file paths by replacing prefix old_path with new_path. - Does not update imports or references; follow up with edit_code() as needed. Args: old_path: Existing folder path. new_path: New f

(
    ctx: RunContextWrapper[IDEContext], old_path: str, new_path: str
)

Source from the content-addressed store, hash-verified

272
273@function_tool
274async def rename_folder(
275 ctx: RunContextWrapper[IDEContext], old_path: str, new_path: str
276) -> str:
277 """Rename or move a folder and all contained files.
278
279 Behavior:
280 - Rewrites affected file paths by replacing prefix old_path with new_path.
281 - Does not update imports or references; follow up with edit_code() as needed.
282
283 Args:
284 old_path: Existing folder path.
285 new_path: New folder path.
286 Returns:
287 JSON string describing the rename.
288 """
289 tool_id = f"tc_{len(ctx.context.events) + 1}"
290 args = {"old_path": old_path, "new_path": new_path}
291 ctx.context.events.append(
292 {
293 "phase": "started",
294 "tool_id": tool_id,
295 "name": "rename_folder",
296 "arguments": args,
297 }
298 )
299
300 old_norm = old_path.rstrip("/")
301 new_norm = new_path.rstrip("/")
302 moved = 0
303 next_project: dict[str, str] = {}
304 deleted_paths: list[str] = []
305 created_paths: list[str] = []
306 for path, content in ctx.context.project.items():
307 if path == old_norm or path.startswith(old_norm + "/"):
308 suffix = path[len(old_norm) :]
309 new_file_path = (new_norm + suffix).lstrip("/")
310 next_project[new_file_path] = content
311 moved += 1
312 deleted_paths.append(path)
313 created_paths.append(new_file_path)
314 else:
315 next_project[path] = content
316 ctx.context.project = next_project
317
318 # best-effort autosync to running sandboxes
319 output = {
320 "old_path": old_path,
321 "new_path": new_path,
322 "renamed": True,
323 "moved_files": moved,
324 }
325 try:
326 await autosync_after_fs_change(
327 ctx,
328 created_or_updated=created_paths,
329 deleted_files=deleted_paths,
330 deleted_dirs=[old_norm],
331 )

Callers

nothing calls this directly

Calls 1

autosync_after_fs_changeFunction · 0.90

Tested by

no test coverage detected