Chat turn diffs: leave out the harness home inside the folder (CLAUDE_CONFIG_DIR)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user