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

Function rename_file

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

Rename or move a file. Behavior: - Moves content from old_path to new_path; may overwrite if destination exists. - Does not automatically update imports/references; follow up with edit_code(). Args: old_path: Current file path. new_path: Destination path. Return

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

Source from the content-addressed store, hash-verified

106
107@function_tool
108async def rename_file(
109 ctx: RunContextWrapper[IDEContext], old_path: str, new_path: str
110) -> str:
111 """Rename or move a file.
112
113 Behavior:
114 - Moves content from old_path to new_path; may overwrite if destination exists.
115 - Does not automatically update imports/references; follow up with edit_code().
116
117 Args:
118 old_path: Current file path.
119 new_path: Destination path.
120 Returns:
121 JSON string describing the rename or an error.
122 """
123 tool_id = f"tc_{len(ctx.context.events) + 1}"
124 args = {"old_path": old_path, "new_path": new_path}
125 ctx.context.events.append(
126 {
127 "phase": "started",
128 "tool_id": tool_id,
129 "name": "rename_file",
130 "arguments": args,
131 }
132 )
133
134 if old_path not in ctx.context.project:
135 output = {
136 "error": f"File not found: {old_path}",
137 "old_path": old_path,
138 "new_path": new_path,
139 }
140 else:
141 content = ctx.context.project[old_path]
142 overwritten = new_path in ctx.context.project
143 if overwritten:
144 # Overwrite destination
145 ctx.context.project[new_path] = content
146 else:
147 ctx.context.project[new_path] = content
148 del ctx.context.project[old_path]
149 # best-effort autosync to running sandboxes
150 output = {
151 "old_path": old_path,
152 "new_path": new_path,
153 "renamed": True,
154 **({"overwritten": True} if overwritten else {}),
155 }
156 try:
157 await autosync_after_fs_change(
158 ctx, created_or_updated=[new_path], deleted_files=[old_path]
159 )
160 except Exception:
161 pass
162
163 ctx.context.events.append(
164 {
165 "phase": "completed",

Callers

nothing calls this directly

Calls 1

autosync_after_fs_changeFunction · 0.90

Tested by

no test coverage detected