Files
gabrielvidalandClaude Opus 5.5 905a289b7f feat(diff): a conversation's commits are its own record, workers included
commitsAuto from the hook's gitCommits (else git's [branch sha] line), the
exact list on /api/conversation-commits (time window only for older lab
conversations that ran a committing command), one commit's diff on
/api/conversation-commit-diff (lab git, transcript patch, or the worker,
cached), the net diff per run of consecutive commits. The uncommitted replay
no longer counts files a merge rewrote. Parser v35.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 20:41:30 +02:00

134 lines
3.9 KiB
Python

"""The diff view (commit + conversation diffs)."""
from __future__ import annotations
from typing import Literal, Optional
from .base import Schema
__all__ = [
"CommitFileStat",
"CommitRef",
"DiffUnavailable",
"ConversationCommits",
"DiffLine",
"DiffHunk",
"FileDiff",
"WorktreeRef",
"DiffResult",
]
class CommitFileStat(Schema):
path: str
status: Literal["added", "deleted", "modified", "renamed"]
additions: int
deletions: int
binary: bool = False
class CommitRef(Schema):
sha: str
short: str
date: Optional[str] = None
author: Optional[str] = None
subject: str
additions: int
deletions: int
files: int
# repo token (project:<slug> | service:<slug> | super:_) of a lab commit;
# None for a worker's (its repo is on that machine: ``root``).
repo: Optional[str] = None
# ── a conversation's own commits (diff/convcommits.py) ──
# hook = recorded by the Bash hook (exact, patch in the transcript);
# output = git's `[branch sha]` line; window = the time-window guess.
source: Optional[Literal["hook", "output", "window"]] = None
branch: Optional[str] = None
parents: Optional[list[str]] = None
merge: Optional[bool] = None
# A push moved a remote-tracking ref to it (or past it). None = unknown.
pushed: Optional[bool] = None
# The checkout it was made in, as a path on the runner that ran it.
root: Optional[str] = None
worker: Optional[str] = None
toolUseId: Optional[str] = None
# The transcript's patch was capped: the diff comes from git / the worker.
truncated: Optional[bool] = None
# Another Bash call ran in the same repo meanwhile (may be another agent's).
shared: Optional[bool] = None
fileStats: Optional[list[CommitFileStat]] = None
class ConversationCommits(Schema):
id: str
commits: list[CommitRef]
repos: list[str]
filesChanged: int
additions: int
deletions: int
# True when the list is the session's own record; False = the time-window
# guess (a lab conversation from before the commit hook).
exact: Optional[bool] = None
# The worker it ran on (its commits' diffs come from that machine).
worker: Optional[str] = None
class DiffLine(Schema):
type: Literal["add", "del", "ctx"]
oldNo: Optional[int] = None
newNo: Optional[int] = None
text: str
class DiffHunk(Schema):
header: str
oldStart: int
oldLines: int
newStart: int
newLines: int
lines: list[DiffLine]
class FileDiff(Schema):
path: str
oldPath: Optional[str] = None
status: Literal["added", "deleted", "modified", "renamed"]
additions: int
deletions: int
binary: bool
truncated: bool
hunks: list[DiffHunk]
repo: Optional[str] = None
# Worktree directory this file was read from (worktree diffs only) — the
# blob route needs it to serve the right copy of an image.
wt: Optional[str] = None
# Net diff of a sleeping worker's commits: which commit's patch this is.
commit: Optional[str] = None
class WorktreeRef(Schema):
"""A live git worktree a conversation's diff was read from."""
dir: str
branch: Optional[str] = None
repo: str
class DiffResult(Schema):
title: str
subtitle: Optional[str] = None
files: list[FileDiff]
additions: int
deletions: int
commits: Optional[list[CommitRef]] = None
approx: Optional[bool] = None
# "worktree" when the changes were read with a real `git diff` from a live
# worktree; absent/"transcript" when replayed from the transcript's edits.
source: Optional[Literal["worktree", "transcript", "git", "worker"]] = None
worktrees: Optional[list[WorktreeRef]] = None
# Part of the diff couldn't be read (the worker asleep): why.
unavailable: Optional[DiffUnavailable] = None
class DiffUnavailable(Schema):
message: str
kind: str