From 4a40539ece60272a02cbd266628901663d1c9bbb Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Thu, 3 Dec 2026 19:32:30 +0000 Subject: [PATCH] Chat turn diffs: leave out the harness home inside the folder (CLAUDE_CONFIG_DIR) Co-Authored-By: Claude Opus 5.5 --- internal/server/chat_turn_diff.go | 38 +++++++++++++++++++ .../server/chat_turn_diff_harness_test.go | 26 +++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 internal/server/chat_turn_diff_harness_test.go diff --git a/internal/server/chat_turn_diff.go b/internal/server/chat_turn_diff.go index dcc8b96e..d7680a1a 100644 --- a/internal/server/chat_turn_diff.go +++ b/internal/server/chat_turn_diff.go @@ -11,6 +11,7 @@ import ( "git.a-wan.net/alan/pipelines/internal/filediff" "git.a-wan.net/alan/pipelines/internal/protocol" + "git.a-wan.net/alan/pipelines/internal/stage" ) // Per-turn chat diffs (protocol/chat_turn_diff.go). The hub snapshots the @@ -193,6 +194,10 @@ func (h *chatHub) finishTurnDiff(sessionID string, capture *chatTurnCapture, end return } changes := filediff.Compare(capture.baseline, after) + // The harness's own home inside the folder (CLAUDE_CONFIG_DIR, e.g. a + // per-project .claude-profile) changes on every turn; it is not the + // operator's work. + changes = withoutHarnessState(changes, capture.dir, stage.HarnessStateDirs(workspaceEnv(ctx, capture.dir))) summary, ok := chatTurnDiffSummary(capture, ended, changes) if !ok { return @@ -292,3 +297,36 @@ func handleChatTurnDiff(ctx context.Context, request protocol.Message, hub *chat Changes: &changes, }}) } + +// withoutHarnessState drops the files under any of dirs that lie inside +// workspace; the rest of changes is kept as it was. +func withoutHarnessState(changes *protocol.StageFileChanges, workspace string, dirs []string) *protocol.StageFileChanges { + if changes == nil { + return nil + } + var prefixes []string + for _, dir := range dirs { + if rel, ok := workspaceRelative(workspace, dir); ok && rel != "." { + prefixes = append(prefixes, rel+"/") + } + } + if len(prefixes) == 0 { + return changes + } + kept := changes.Files[:0:0] + for _, file := range changes.Files { + inside := false + for _, prefix := range prefixes { + if strings.HasPrefix(file.Path+"/", prefix) { + inside = true + break + } + } + if !inside { + kept = append(kept, file) + } + } + filtered := *changes + filtered.Files = kept + return &filtered +} diff --git a/internal/server/chat_turn_diff_harness_test.go b/internal/server/chat_turn_diff_harness_test.go new file mode 100644 index 00000000..0729abf5 --- /dev/null +++ b/internal/server/chat_turn_diff_harness_test.go @@ -0,0 +1,26 @@ +package server + +import ( + "testing" + + "git.a-wan.net/alan/pipelines/internal/protocol" +) + +func TestTurnDiffDropsTheHarnessHomeInsideTheFolder(t *testing.T) { + changes := &protocol.StageFileChanges{Status: "complete", Files: []protocol.FileChange{ + {Path: ".claude-profile/.claude.json"}, + {Path: ".claude-profile/projects/x/1.jsonl"}, + {Path: ".claude-profile-notes.md"}, + {Path: "src/app.py"}, + }} + got := withoutHarnessState(changes, "/w/caplens", []string{"/w/caplens/.claude-profile", "/home/me/.claude"}) + if len(got.Files) != 2 || got.Files[0].Path != ".claude-profile-notes.md" || got.Files[1].Path != "src/app.py" { + t.Fatalf("files = %+v", got.Files) + } + if len(changes.Files) != 4 { + t.Fatalf("input changed: %+v", changes.Files) + } + if same := withoutHarnessState(changes, "/w/caplens", []string{"/home/me/.claude"}); same != changes { + t.Fatal("no harness dir inside the folder should keep the changes as they are") + } +}