Stage diffs: clean Git files take their baseline from the index blob

On a large Git workspace the 32 MiB retained-text budget was spent
alphabetically on files that never change, so small late edits were
recorded with no_patch. The stage-start snapshot now keeps text only for
files dirty or untracked at start; a clean tracked file keeps its hash and
stage-0 index blob id. When it changes or is deleted, the after capture
reads that blob in one `git cat-file --batch` and uses it only if its
SHA-256 matches the start read, so stage commits/resets do not move the
baseline and filters or assume-unchanged never yield a wrong patch. The
after capture shares unchanged files' representation instead of spending
budget on them again.

FileChange gains no_patch_reason (binary, file_size, budget, lines,
evidence_size, git_status, baseline). Non-Git workspaces keep their
behaviour.
This commit is contained in:
2026-11-04 17:08:01 +00:00
parent 6870c81960
commit 70391b17c2
7 changed files with 506 additions and 40 deletions
+6 -7
View File
@@ -210,8 +210,8 @@ func TestUISkipPartialCaptureNeverSkips(t *testing.T) {
// TestUISkipOverBudgetGitWorkspaceRunsModel is the run-236 regression: in a Git
// workspace whose text exceeds the snapshot budget, a stage edits one .tsx file
// sorted after the budget is exhausted. The capture must list that file
// (without a patch) and the next stage, which declares `skipped`, must run its
// sorted after the budget would be exhausted. The capture must list that file
// (now with its patch: clean files spend no budget) and the next stage, which declares `skipped`, must run its
// model rather than be auto-routed with "no recorded file changes".
func TestUISkipOverBudgetGitWorkspaceRunsModel(t *testing.T) {
if _, err := exec.LookPath("git"); err != nil {
@@ -244,13 +244,12 @@ func TestUISkipOverBudgetGitWorkspaceRunsModel(t *testing.T) {
git("commit", "-qm", "fixture")
detail, visited, verdictCalls := runUISkipIn(t, uiReviewerSource(true), map[string]string{"implement": target}, dir)
capture := detail.Steps[0].FileChanges
if capture == nil || len(capture.Files) != 1 || capture.Files[0].Path != target || !capture.Files[0].NoPatch {
t.Fatalf("over-budget capture did not list the edited file: %+v", capture)
// Clean tracked files take their baseline from Git, so the budget no longer
// runs out and the edited file keeps a full patch.
if capture == nil || capture.Status != "complete" || len(capture.Files) != 1 || capture.Files[0].Path != target || capture.Files[0].NoPatch || !strings.Contains(capture.Files[0].Patch, "+implement") {
t.Fatalf("over-budget capture did not patch the edited file: %+v", capture)
}
assertModelRan(t, detail, visited, verdictCalls)
if len(detail.Warnings) == 0 {
t.Fatal("partial capture produced no run-level warning")
}
}
// TestUISkipOptOut proves auto_skip=false makes a `skipped` stage run its model