Generic platform points for the `diff-viewer` and `commits` plugins (ai-agent-plugins): a `conversation.tab` slot (Thread | Changes N) with setTab/openTab/closeTab/reply bridges; stackable + pullOut tool cards and match.hasReport; `pathShims` (a git PATH shim for every harness) with out-of-band reports (lab: /api/plugin-reports, worker: outbox `report`); `conversations.reports` and `diff.read` hub bridges; ui.pages[].opens for Project/Service "Recent commits". The core commit card, Changes view, diff page and review store are gone; bash_diff.py keeps bashDiff only. Legacy gitCommits / commit-line parsing stays for past transcripts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
100 lines
4.0 KiB
Python
100 lines
4.0 KiB
Python
"""``diff.read`` — core's diff engines as hub bridges (since 2026-11-27, when
|
|
the Changes tab, the commit card and the full-page diff views left the core
|
|
for the ``diff-viewer`` and ``commits`` plugins).
|
|
|
|
The engines stay core's (``backend/diff/*``, ``conversations/commits.py``,
|
|
legacy ``gitCommits`` parsing included); these bridges call the very route
|
|
functions of ``diff/routes.py``, as the caller — so a guest is held exactly as
|
|
there (``_viewed_by``: their granted projects only; ``_repo_allowed``: a
|
|
``project:<slug>`` they can view). The caller's own conversations only.
|
|
|
|
``AIA_TOOLS_URL/plugins/<id>/hub/diff/…``:
|
|
|
|
* ``GET conversations/{cid}/commits`` → ``/api/conversation-commits``
|
|
(``ConversationCommits``);
|
|
* ``GET conversations/{cid}/commit?sha=&root=`` → one commit's ``DiffResult``
|
|
(``root``: the repo root a shim report named — a commit core never saw);
|
|
* ``GET conversations/{cid}/uncommitted?stats=0|1`` →
|
|
``/api/conversation-uncommitted-diff``;
|
|
* ``GET conversations/{cid}/aggregate`` → ``/api/conversation-diff``;
|
|
* ``GET commit?repo=<token>&sha=`` → ``/api/commit-diff``.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from fastapi import APIRouter, HTTPException, Request
|
|
from starlette.concurrency import run_in_threadpool
|
|
|
|
router = APIRouter(include_in_schema=False)
|
|
|
|
CAP = "diff.read"
|
|
_BASE = "/proxy/tools/plugins/{pid}/hub/diff"
|
|
|
|
|
|
async def _run(request: Request, pid: str, fn, *args, **kwargs):
|
|
"""``fn(deps, caller, …)`` of diff/routes.py as the bridge's caller; an
|
|
``HTTPException`` becomes the bridges' JSON error."""
|
|
from plugins.hubbridge import _caller_for_who, _check_cap
|
|
from plugins.proxyroutes import _error
|
|
deps, who, _rec, err = _check_cap(request, pid, CAP)
|
|
if err:
|
|
return err
|
|
caller = _caller_for_who(deps, who)
|
|
if caller is None:
|
|
return _error(403, "unknown user", "auth")
|
|
|
|
def call():
|
|
return fn(deps, caller, *args, **kwargs)
|
|
|
|
try:
|
|
return await run_in_threadpool(call)
|
|
except HTTPException as e:
|
|
d = e.detail
|
|
msg = d.get("message") if isinstance(d, dict) else str(d)
|
|
kind = (d.get("kind") if isinstance(d, dict) else None) or (
|
|
"not_found" if e.status_code == 404 else "error")
|
|
return _error(e.status_code, msg or "error", kind)
|
|
|
|
|
|
def _conv_id(deps, cid: str) -> str:
|
|
"""A conversation id, or a session id's newest conversation (what the
|
|
routes take)."""
|
|
from plugins.hubchecks import locate
|
|
hit = locate(deps, cid)
|
|
return hit[0] if hit else cid
|
|
|
|
|
|
@router.get(_BASE + "/conversations/{cid}/commits")
|
|
async def hub_diff_commits(pid: str, cid: str, request: Request):
|
|
from diff import routes as dr
|
|
return await _run(request, pid, lambda deps, caller: dr.conversation_commits(
|
|
deps, caller, _conv_id(deps, cid)))
|
|
|
|
|
|
@router.get(_BASE + "/conversations/{cid}/commit")
|
|
async def hub_diff_commit(pid: str, cid: str, request: Request, sha: str = "",
|
|
root: str | None = None):
|
|
from diff import routes as dr
|
|
return await _run(request, pid, lambda deps, caller: dr.conversation_commit_diff(
|
|
deps, caller, _conv_id(deps, cid), sha, root=root or None))
|
|
|
|
|
|
@router.get(_BASE + "/conversations/{cid}/uncommitted")
|
|
async def hub_diff_uncommitted(pid: str, cid: str, request: Request, stats: int = 0):
|
|
from diff import routes as dr
|
|
return await _run(request, pid, lambda deps, caller: dr.conversation_uncommitted_diff(
|
|
deps, caller, _conv_id(deps, cid), stats=bool(stats)))
|
|
|
|
|
|
@router.get(_BASE + "/conversations/{cid}/aggregate")
|
|
async def hub_diff_aggregate(pid: str, cid: str, request: Request):
|
|
from diff import routes as dr
|
|
return await _run(request, pid, lambda deps, caller: dr.conversation_diff(
|
|
deps, caller, _conv_id(deps, cid)))
|
|
|
|
|
|
@router.get(_BASE + "/commit")
|
|
async def hub_diff_repo_commit(pid: str, request: Request, repo: str = "", sha: str = ""):
|
|
from diff import routes as dr
|
|
return await _run(request, pid, lambda deps, caller: dr.commit_diff(caller, repo, sha))
|