agent-zero/plugins/_diff_viewer/api/diff.py
Alessandro 58a5f8276b Add right canvas diff viewer
Adds the core _diff_viewer plugin for viewing staged, unstaged, and untracked working-tree changes in the right canvas and window modal.

Includes context-aware workspace resolution, safe read-only Git collection, zero-line .gitkeep filtering, unified diff rendering, and focused diff collection tests.
2026-04-26 23:52:24 +02:00

29 lines
1.3 KiB
Python

from __future__ import annotations
from helpers import files, projects, settings
from helpers.api import ApiHandler, Request, Response
from plugins._diff_viewer.helpers.diff import collect_workspace_diff
class Diff(ApiHandler):
async def process(self, input: dict, request: Request) -> dict | Response:
context_id = str(input.get("context_id") or "").strip()
workspace_path, display_path = self._resolve_workspace(context_id)
return collect_workspace_diff(
workspace_path,
context_id=context_id,
display_path=display_path,
)
def _resolve_workspace(self, context_id: str) -> tuple[str, str]:
if context_id:
context = self.use_context(context_id)
project_name = projects.get_context_project_name(context)
if project_name:
project_path = projects.get_project_folder(project_name)
display_path = files.normalize_a0_path(project_path)
return files.fix_dev_path(display_path), display_path
configured = str(settings.get_settings().get("workdir_path") or "")
display_path = configured or files.normalize_a0_path(files.get_abs_path("usr/workdir"))
return files.fix_dev_path(display_path), display_path