Commit d2896bc
authored
fix(code): fix truncated diff preview (#1235)
## problem
diff viewer is a little broken - mostly because sometimes the tool output is too large, causing the "diff preview content" to be something like this:
```
<persisted-output>
Output too large (110.7KB). Full output saved to: /Users/adambowker/Library/Application Support/@posthog/posthog-code-dev/claude/projects/-Users-adambowker-posthog/019ce8a1-8438-7365-af52-3e0d8a594eb2/tool-results/toolu_019XVYxMKKxpPvfecMUzFEwj.txt
Preview (first 2KB):
import './EditSurvey.scss'
import { DndContext } from '@dnd-kit/core'
import { SortableContext, verticalListSortingStrategy } from '@dnd-kit/sortable'
import { BindLogic, useActions, useMountedLogic, useValues } from 'kea'
...
</persisted-output>
```
when this happens, 1) it looks bad, 2) the stats are computed incorrectly as `+0 -0` , and 3) just means you can’t actually view the diff
also, the diff sometimes doesn't work if it's a delete-only, because we only check `newText` when rendering the diff
## changes
1. updates `EditToolView` to check `oldText || newText` to determine if there is a diff, instead of only `newText`
2. updates `toolInfoFromToolUse` to build the diff by:
1. first, check file content cache exists and is valid (old text exists in the content)
2. if missing or not valid, attempt to read the file contents from disk
3. if both of those fail, fall back to rendering fragment diff only, no context lines1 parent f16371e commit d2896bc
File tree
2 files changed
+52
-15
lines changed- apps/code/src/renderer/features/sessions/components/session-update
- packages/agent/src/adapters/claude/conversion
2 files changed
+52
-15
lines changedLines changed: 4 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
| 72 | + | |
72 | 73 | | |
73 | 74 | | |
74 | 75 | | |
| |||
98 | 99 | | |
99 | 100 | | |
100 | 101 | | |
101 | | - | |
| 102 | + | |
102 | 103 | | |
103 | 104 | | |
104 | 105 | | |
| |||
111 | 112 | | |
112 | 113 | | |
113 | 114 | | |
114 | | - | |
| 115 | + | |
115 | 116 | | |
116 | | - | |
| 117 | + | |
117 | 118 | | |
118 | 119 | | |
119 | 120 | | |
| |||
Lines changed: 48 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
| |||
179 | 180 | | |
180 | 181 | | |
181 | 182 | | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
194 | 199 | | |
195 | 200 | | |
196 | 201 | | |
| |||
759 | 764 | | |
760 | 765 | | |
761 | 766 | | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
762 | 798 | | |
763 | 799 | | |
764 | 800 | | |
| |||
0 commit comments