mirror of
https://github.com/agent0ai/agent-zero.git
synced 2026-05-18 23:45:49 +00:00
Add the _time_travel core plugin with Agent Zero-owned shadow Git snapshots, history/diff/preview/travel/revert APIs, capture hooks, and canvas plus floating window UI surfaces for /a0/usr workspaces. Wire generic file-browser mutation hooks for UI edits, update modal backdrop handling, remove the legacy _diff_viewer plugin, and replace Diff Viewer tests with focused Time Travel coverage. Inspired by Space Agent :-)
70 lines
2.6 KiB
Python
70 lines
2.6 KiB
Python
from helpers.api import ApiHandler, Input, Output, Request
|
|
from helpers.file_browser import FileBrowser
|
|
from helpers import runtime, extension
|
|
from api import get_work_dir_files
|
|
import posixpath
|
|
|
|
|
|
class RenameWorkDirFile(ApiHandler):
|
|
async def process(self, input: Input, request: Request) -> Output:
|
|
try:
|
|
action = input.get("action", "rename")
|
|
new_name = (input.get("newName", "") or "").strip()
|
|
if not new_name:
|
|
return {"error": "New name is required"}
|
|
|
|
current_path = input.get("currentPath", "")
|
|
|
|
if action == "create-folder":
|
|
parent_path = input.get("parentPath", current_path)
|
|
if not parent_path:
|
|
return {"error": "Parent path is required"}
|
|
res = await runtime.call_development_function(
|
|
create_folder, parent_path, new_name
|
|
)
|
|
changed_paths = [posixpath.join(str(parent_path).rstrip("/"), new_name)]
|
|
else:
|
|
file_path = input.get("path", "")
|
|
if not file_path:
|
|
return {"error": "Path is required"}
|
|
if not file_path.startswith("/"):
|
|
file_path = f"/{file_path}"
|
|
res = await runtime.call_development_function(
|
|
rename_item, file_path, new_name
|
|
)
|
|
changed_paths = [
|
|
file_path,
|
|
posixpath.join(posixpath.dirname(file_path), new_name),
|
|
]
|
|
|
|
if res:
|
|
await extension.call_extensions_async(
|
|
"workdir_file_mutation_after",
|
|
agent=None,
|
|
data={
|
|
"action": action,
|
|
"path": changed_paths[-1],
|
|
"paths": changed_paths,
|
|
"current_path": current_path,
|
|
},
|
|
)
|
|
result = await runtime.call_development_function(
|
|
get_work_dir_files.get_files, current_path
|
|
)
|
|
return {"data": result}
|
|
|
|
error_msg = "Failed to create folder" if action == "create-folder" else "Rename failed"
|
|
return {"error": error_msg}
|
|
|
|
except Exception as e:
|
|
return {"error": str(e)}
|
|
|
|
|
|
async def rename_item(file_path: str, new_name: str) -> bool:
|
|
browser = FileBrowser()
|
|
return browser.rename_item(file_path, new_name)
|
|
|
|
|
|
async def create_folder(parent_path: str, folder_name: str) -> bool:
|
|
browser = FileBrowser()
|
|
return browser.create_folder(parent_path, folder_name)
|