Skip to content

Commit 957cfc3

Browse files
committed
refactor(cli/exp_agents): remove dead gitChanges plumbing
The earlier fetchChatDiffContents refactor dropped the GetChatGitChanges dispatch from toggleDiffDrawerCmd, which orphaned the whole gitChangesMsg consumer chain. m.chat.gitChanges is never populated, so every downstream consumer worked against a permanently nil slice and resolvedChatDiffChanges always fell through to parseChatGitChangesFromUnifiedDiff. Drop: - gitChangesMsg struct and its chat handler branch - gitChanges field on chatViewModel and its reset in setChat - Draft/gitChangesMsg stale-generation test case - resolvedChatDiffChanges helper now that the parsed-from-diff path is the only one we ever hit - changes parameter from renderChatDiffSummary and renderDiffDrawer (both are now driven purely by the ChatDiffContents input) Callers and tests are updated accordingly. No behavior change: the diff drawer still derives its summary from the unified diff via parseChatGitChangesFromUnifiedDiff.
1 parent 28e2b66 commit 957cfc3

6 files changed

Lines changed: 10 additions & 44 deletions

File tree

cli/exp_agents_chat.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,6 @@ type chatViewModel struct {
304304
interrupting bool
305305

306306
diffStatus *codersdk.ChatDiffStatus
307-
gitChanges []codersdk.ChatGitChange
308307
diffContents *codersdk.ChatDiffContents
309308
diffErr error
310309

@@ -471,7 +470,6 @@ func (m *chatViewModel) setChat(chat codersdk.Chat) {
471470
m.activeChatID = chat.ID
472471
m.chatStatus = chat.Status
473472
m.diffStatus = chat.DiffStatus
474-
m.gitChanges = nil
475473
m.diffContents = nil
476474
m.diffErr = nil
477475
}
@@ -1168,17 +1166,6 @@ func (m chatViewModel) Update(msg tea.Msg) (chatViewModel, tea.Cmd) {
11681166
}
11691167
return m, nil
11701168

1171-
case gitChangesMsg:
1172-
if !m.matchesGeneration(msg.generation) {
1173-
return m, nil
1174-
}
1175-
if msg.err != nil {
1176-
m.diffErr = msg.err
1177-
return m, nil
1178-
}
1179-
m.gitChanges = msg.changes
1180-
return m, nil
1181-
11821169
case diffContentsMsg:
11831170
if !m.matchesGeneration(msg.generation) {
11841171
return m, nil

cli/exp_agents_cmds.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,6 @@ type (
5656
catalog codersdk.ChatModelsResponse
5757
err error
5858
}
59-
gitChangesMsg struct {
60-
generation uint64
61-
chatID uuid.UUID
62-
changes []codersdk.ChatGitChange
63-
err error
64-
}
6559
diffContentsMsg struct {
6660
generation uint64
6761
chatID uuid.UUID

cli/exp_agents_model.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ func (m expChatsTUIModel) diffOverlayView() string {
374374
case m.chat.diffErr != nil:
375375
return m.renderOverlay("Diff", m.styles.errorText.Render(wrapPreservingNewlines(m.chat.diffErr.Error(), contentWidth(m.width, 6))))
376376
case m.chat.diffContents != nil:
377-
return renderDiffDrawer(m.styles, *m.chat.diffContents, m.chat.gitChanges, m.width, m.height)
377+
return renderDiffDrawer(m.styles, *m.chat.diffContents, m.width, m.height)
378378
default:
379379
return m.renderOverlay("Diff", m.styles.dimmedText.Render("Loading diff…"))
380380
}
@@ -466,7 +466,7 @@ func (m expChatsTUIModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
466466
return m.updateChild(msg, viewChat)
467467
case chatsListedMsg:
468468
return m.updateChild(msg, viewList)
469-
case chatOpenedMsg, chatHistoryMsg, chatStreamEventMsg, messageSentMsg, chatCreatedMsg, chatInterruptedMsg, gitChangesMsg, diffContentsMsg:
469+
case chatOpenedMsg, chatHistoryMsg, chatStreamEventMsg, messageSentMsg, chatCreatedMsg, chatInterruptedMsg, diffContentsMsg:
470470
return m.updateChild(msg, viewChat)
471471
case modelsListedMsg:
472472
if msg.err != nil {

cli/exp_agents_render.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -310,13 +310,6 @@ func diffMetadataLines(diff codersdk.ChatDiffContents) []string {
310310
return lines
311311
}
312312

313-
func resolvedChatDiffChanges(diff codersdk.ChatDiffContents, changes []codersdk.ChatGitChange) []codersdk.ChatGitChange {
314-
if len(changes) > 0 {
315-
return changes
316-
}
317-
return parseChatGitChangesFromUnifiedDiff(diff)
318-
}
319-
320313
func parseChatGitChangesFromUnifiedDiff(diff codersdk.ChatDiffContents) []codersdk.ChatGitChange {
321314
rawDiff := sanitizeTerminalRenderableText(diff.Diff)
322315
if strings.TrimSpace(rawDiff) == "" {
@@ -551,8 +544,8 @@ func stripUnifiedDiffPrefix(path string) string {
551544
}
552545
}
553546

554-
func renderChatDiffSummary(diff codersdk.ChatDiffContents, changes []codersdk.ChatGitChange) string {
555-
changes = resolvedChatDiffChanges(diff, changes)
547+
func renderChatDiffSummary(diff codersdk.ChatDiffContents) string {
548+
changes := parseChatGitChangesFromUnifiedDiff(diff)
556549
if len(changes) == 0 {
557550
return "No changes detected."
558551
}
@@ -612,13 +605,13 @@ func styleUnifiedDiffLine(styles tuiStyles, line string) string {
612605
}
613606
}
614607

615-
func renderDiffDrawer(styles tuiStyles, diff codersdk.ChatDiffContents, changes []codersdk.ChatGitChange, width, height int) string {
608+
func renderDiffDrawer(styles tuiStyles, diff codersdk.ChatDiffContents, width, height int) string {
616609
innerWidth := contentWidth(width, 6)
617610
headerBits := []string{styles.title.Render("Diff")}
618611
if meta := diffMetadataLines(diff); len(meta) > 0 {
619612
headerBits = append(headerBits, styles.subtitle.Render(strings.Join(meta, " • ")))
620613
}
621-
summary := renderChatDiffSummary(diff, changes)
614+
summary := renderChatDiffSummary(diff)
622615
diffBody := renderStyledDiffBody(styles, diff.Diff)
623616
help := styles.helpText.Render("Esc to close")
624617
overhead := countRenderedLines(strings.Join(headerBits, "\n")) + countRenderedLines(summary) + countRenderedLines(help) + 4

cli/exp_agents_render_test.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -555,10 +555,9 @@ func TestExpAgentsRender(t *testing.T) {
555555
branch := "feature/chat-ui"
556556
prURL := "https://example.com/pulls/123"
557557
for _, tt := range []struct {
558-
name string
559-
diff codersdk.ChatDiffContents
560-
changes []codersdk.ChatGitChange
561-
assert func(t *testing.T, output string)
558+
name string
559+
diff codersdk.ChatDiffContents
560+
assert func(t *testing.T, output string)
562561
}{
563562
{name: "ShowsMetadataWhenPresent", diff: codersdk.ChatDiffContents{Branch: &branch, PullRequestURL: &prURL}, assert: func(t *testing.T, output string) {
564563
require.Contains(t, output, "Branch: feature/chat-ui")
@@ -576,7 +575,7 @@ func TestExpAgentsRender(t *testing.T) {
576575
t.Run(tt.name, func(t *testing.T) {
577576
t.Parallel()
578577
var output string
579-
require.NotPanics(t, func() { output = plainText(renderDiffDrawer(styles, tt.diff, tt.changes, 90, 20)) })
578+
require.NotPanics(t, func() { output = plainText(renderDiffDrawer(styles, tt.diff, 90, 20)) })
580579
tt.assert(t, output)
581580
})
582581
}
@@ -768,10 +767,6 @@ func TestExpAgentsRender(t *testing.T) {
768767
rawOutput := renderDiffDrawer(
769768
styles,
770769
codersdk.ChatDiffContents{Diff: "diff --git a/a.txt b/a.txt\n+safe\x1b]52;c;clipboard\x07line"},
771-
[]codersdk.ChatGitChange{{
772-
FilePath: "a.txt\x1b]52;c;clipboard\x07",
773-
ChangeType: "modified",
774-
}},
775770
90,
776771
20,
777772
)

cli/exp_agents_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,6 @@ func TestExpAgents(t *testing.T) {
603603
model.catalog = &catalog
604604
chat := testChat(codersdk.ChatStatusCompleted)
605605
model.chat.chat = &chat
606-
model.chat.gitChanges = []codersdk.ChatGitChange{}
607606

608607
updatedModel, cmd := model.Update(toggleDiffDrawerMsg{})
609608
updated, _ := mustTUIModelWithCmd(t, updatedModel, cmd)
@@ -837,7 +836,6 @@ func TestExpAgents(t *testing.T) {
837836
{name: "Draft/chatOpenedMsg", msg: chatOpenedMsg{generation: 1, chatID: uuid.New(), chat: testChat(codersdk.ChatStatusCompleted)}, draft: true},
838837
{name: "Draft/chatHistoryMsg", msg: chatHistoryMsg{generation: 1, chatID: uuid.New(), messages: []codersdk.ChatMessage{testMessage(1, codersdk.ChatMessageRoleUser, codersdk.ChatMessagePart{Type: codersdk.ChatMessagePartTypeText, Text: "hi"})}}, draft: true},
839838
{name: "Draft/chatStreamEventMsg", msg: chatStreamEventMsg{generation: 1, chatID: uuid.New(), event: testTextPartEvent("stale")}, draft: true},
840-
{name: "Draft/gitChangesMsg", msg: gitChangesMsg{generation: 1, chatID: uuid.New()}, draft: true},
841839
{name: "Draft/diffContentsMsg", msg: diffContentsMsg{generation: 1, chatID: uuid.New()}, draft: true},
842840
}
843841
for _, tt := range tests {
@@ -2094,7 +2092,6 @@ func TestExpAgents(t *testing.T) {
20942092
chat := testChat(codersdk.ChatStatusCompleted)
20952093
model.chat.setChat(chat)
20962094
model.chat.messages = overflowingMessages(10)
2097-
model.chat.gitChanges = []codersdk.ChatGitChange{}
20982095
diff := codersdk.ChatDiffContents{ChatID: chat.ID, Diff: "diff --git a/file b/file"}
20992096
model.chat.diffContents = &diff
21002097
model.chat.rebuildBlocks()

0 commit comments

Comments
 (0)