Summarise large edit diffs and label the card with file and stat
The chat edit diff card rendered every line of an edit, so the >400-line fallback flooded the transcript with thousands of Text nodes on a phone; it also showed only the tool name, not the file, on the expanded panel. - ChatFormat.toolEditDiff keeps the first MAX_RENDERED_DIFF_LINES (200) lines and puts the remainder in the new ToolDiff.omitted, while the +N/-M counts continue to describe the whole edit. - DiffView prints "… N more changed lines not shown" first so the truncation is visible without scrolling. - The expanded panel header now shows the edited file name and the shared green/red DiffStat, matching the collapsed chip. - ChatFormatTest pins omitted = 0 for a small edit and the true counts, 200-line cap and omitted = 300 for an oversized one. - android/README.md records the change and its evidence.
This commit is contained in:
@@ -2664,3 +2664,56 @@ Evidence (macOS, Gradle 9.7.1, `ANDROID_HOME=/Users/alan/Library/Android/sdk`):
|
||||
|
||||
Not verified in this pass: the live brokered server (separate lane), streaming
|
||||
against real OpenCode, and attachments — unchanged from the passes above.
|
||||
|
||||
## Edit diffs: file name, stat and large-edit summarisation (16 Oct 2026)
|
||||
|
||||
The edit diff card already derived its lines, but three things the task calls for
|
||||
were missing or wrong. `android/` only; no new dependency (still just the declared
|
||||
`material-icons-extended`), no Pipelines server/Go/installer/Docker file touched,
|
||||
no run started from the app, and `emulator-5556` only (lane A's `emulator-5554`
|
||||
was never addressed).
|
||||
|
||||
- **The file name and `+N -M` are on the card, not just the chip.** The expanded
|
||||
panel header showed the tool name (`edit`); it now shows the edited file (as the
|
||||
chip already did) and the shared green/red `DiffStat`, so the diff names its file
|
||||
and its counts wherever it is read.
|
||||
- **Very large edits are summarised, not flooded.** A diff longer than
|
||||
`MAX_RENDERED_DIFF_LINES` (200) kept *every* line — the >400-line fallback
|
||||
rendered `old + new` in full, thousands of `Text` nodes in a scrolling `Column`
|
||||
on a phone. `ChatFormat.toolEditDiff` now keeps the first 200 lines and carries
|
||||
the rest in the new `ToolDiff.omitted`; `DiffView` prints
|
||||
`… N more changed lines not shown` **first**, so the truncation is visible
|
||||
without scrolling. The `+N -M` counts still describe the whole edit, never the
|
||||
rendered prefix.
|
||||
|
||||
Evidence (macOS, JDK 17, Gradle 9.7.1 `--offline`,
|
||||
`ANDROID_HOME=/Users/alan/Library/Android/sdk`):
|
||||
|
||||
- `gradle :app:testDebugUnitTest :app:assembleDebug` → `BUILD SUCCESSFUL`; the
|
||||
JUnit XML totals **254 tests, 0 failures, 0 errors, 0 skipped** (new
|
||||
`toolEditDiffSummarisesAnOversizedEditInsteadOfRenderingEveryLine`, which
|
||||
asserts the true `+250 -250` counts, the 200-line render cap and
|
||||
`omitted = 300`; the small-edit test now also pins `omitted = 0`).
|
||||
- The rebuilt debug APK was installed on `emulator-5556` only and driven against
|
||||
`.diff_check/chat_stub_diff.py` (the `.tool_calls_check/chat_stub_tools.py`
|
||||
`/connect` WebSocket double plus a 300-line edit whose intersection with the
|
||||
cap must summarise; stdlib double, test scaffolding, not the app). Captures were
|
||||
validated with `android/scripts/capture_png.sh -s emulator-5556`:
|
||||
`03_diff_small.png` shows the small edit card — `src/layout.kt +2 -2 300ms`,
|
||||
then red `- val gap = 4.dp` / `- val inset = 1.dp` and green
|
||||
`+ val gap = 6.dp` / `+ val inset = 2.dp` in monospace — and
|
||||
`05_diff_summarised.png` shows `src/big.kt +100 -100 150ms` over
|
||||
`… 200 more changed lines not shown` and the interleaved context/`-`/`+` lines.
|
||||
`uiautomator dump` confirms the same nodes; `adb -s emulator-5556 logcat -d`
|
||||
held 0 `FATAL EXCEPTION` and 0 `E AndroidRuntime` during the sweep.
|
||||
- **APK publish.** `app-debug.apk` (18,220,501 bytes, sha256
|
||||
`7cfca9c40361d4f1871bc61da20aec8c918637f8e085b8eb534d134b3cb8fe00`) copied to
|
||||
`~/.local/share/pipelines/data/artifacts/133/1/pipelines-debug-wip-291cec2.apk`;
|
||||
`curl -I http://10.0.0.75:8080/artifacts/133/1/pipelines-debug-wip-291cec2.apk`
|
||||
returned `HTTP/1.1 200 OK`, `Content-Type: application/vnd.android.package-archive`,
|
||||
`Content-Length: 18220501`, and a streamed `GET | shasum -a 256` matched.
|
||||
|
||||
Not verified in this pass: the live brokered server (separate lane), streaming
|
||||
against real OpenCode, and attachments — unchanged from the passes above.
|
||||
`:app:lintDebug` still cannot run here (the Gradle JVM's `25.0.4.1` version
|
||||
string is rejected by AGP 8.7.2 lint), unchanged from the slices above.
|
||||
|
||||
@@ -107,14 +107,28 @@ enum class DiffKind { CONTEXT, ADD, REMOVE }
|
||||
|
||||
data class DiffLine(val kind: DiffKind, val text: String)
|
||||
|
||||
/** A synthesised edit diff: the file, the `+N -M` counts and the ordered lines. */
|
||||
data class ToolDiff(val file: String, val added: Int, val removed: Int, val lines: List<DiffLine>)
|
||||
/**
|
||||
* A synthesised edit diff: the file, the true `+N -M` counts and the ordered
|
||||
* lines. [omitted] is how many diff lines are not in [lines] because the edit was
|
||||
* too large to render in full (0 when the whole diff is shown); the counts always
|
||||
* describe the whole edit, never just the rendered prefix.
|
||||
*/
|
||||
data class ToolDiff(
|
||||
val file: String,
|
||||
val added: Int,
|
||||
val removed: Int,
|
||||
val lines: List<DiffLine>,
|
||||
val omitted: Int = 0,
|
||||
)
|
||||
|
||||
/**
|
||||
* Derives a unified diff for an `edit`-family tool call from its
|
||||
* `oldString`/`newString` arguments. The brokered protocol carries no diff field
|
||||
* (research report §2.5), so the +/- view is synthesised here instead. Returns
|
||||
* null for any other tool, so non-edit calls keep the INPUT/OUTPUT panel.
|
||||
* (research report §2.5), so the +/- view is synthesised here instead. A diff
|
||||
* longer than [MAX_RENDERED_DIFF_LINES] is summarised — only that many lines are
|
||||
* kept, with [ToolDiff.omitted] carrying the rest — so a very large edit cannot
|
||||
* flood the transcript on a phone. Returns null for any other tool, so non-edit
|
||||
* calls keep the INPUT/OUTPUT panel.
|
||||
*/
|
||||
internal fun toolEditDiff(input: JsonElement?): ToolDiff? {
|
||||
val obj = input as? JsonObject ?: return null
|
||||
@@ -126,7 +140,8 @@ internal fun toolEditDiff(input: JsonElement?): ToolDiff? {
|
||||
file = obj.stringOrNull("filePath", "file_path", "file").orEmpty(),
|
||||
added = lines.count { it.kind == DiffKind.ADD },
|
||||
removed = lines.count { it.kind == DiffKind.REMOVE },
|
||||
lines = lines,
|
||||
lines = lines.take(MAX_RENDERED_DIFF_LINES),
|
||||
omitted = (lines.size - MAX_RENDERED_DIFF_LINES).coerceAtLeast(0),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -177,4 +192,12 @@ private fun lineDiff(old: List<String>, new: List<String>): List<DiffLine> {
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* How many diff lines are rendered before the remainder is summarised. Small
|
||||
* enough to stay readable on a phone, large enough that ordinary edits are
|
||||
* always shown in full. [MAX_DIFF_LINES] is the larger algorithm guard that
|
||||
* bounds the quadratic LCS table.
|
||||
*/
|
||||
internal const val MAX_RENDERED_DIFF_LINES = 200
|
||||
|
||||
private const val MAX_DIFF_LINES = 400
|
||||
|
||||
@@ -821,12 +821,13 @@ private fun ToolPanel(part: ChatPart, onDismiss: () -> Unit, modifier: Modifier
|
||||
tint = if (failed) MaterialTheme.colorScheme.error else MaterialTheme.colorScheme.primary,
|
||||
)
|
||||
Text(
|
||||
text = toolLabel(part),
|
||||
text = diff?.file?.takeIf { it.isNotBlank() } ?: toolLabel(part),
|
||||
style = MaterialTheme.typography.labelLarge,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
modifier = Modifier.weight(1f),
|
||||
)
|
||||
diff?.let { DiffStat(it) }
|
||||
toolDurationMillis(part)?.let {
|
||||
Text(formatToolDuration(it), style = MaterialTheme.typography.labelMedium, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
}
|
||||
@@ -887,6 +888,18 @@ private fun DiffView(diff: ToolDiff) {
|
||||
.verticalScroll(rememberScrollState())
|
||||
.padding(horizontal = CHAT_GUTTER, vertical = CHAT_ITEM_GAP),
|
||||
) {
|
||||
if (diff.omitted > 0) {
|
||||
// A very large edit is summarised rather than rendered in full, so
|
||||
// the card stays short and readable on a phone. The note sits first
|
||||
// so the truncation is visible without scrolling to the end.
|
||||
Text(
|
||||
text = "… ${diff.omitted} more changed " +
|
||||
(if (diff.omitted == 1) "line" else "lines") + " not shown",
|
||||
style = MaterialTheme.typography.labelSmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
modifier = Modifier.padding(bottom = CHAT_ITEM_GAP),
|
||||
)
|
||||
}
|
||||
diff.lines.forEach { line ->
|
||||
val (symbol, color) = when (line.kind) {
|
||||
DiffKind.ADD -> "+" to added
|
||||
|
||||
@@ -87,6 +87,8 @@ class ChatFormatTest {
|
||||
assertEquals("/tmp/a.txt", diff.file)
|
||||
assertEquals(2, diff.added)
|
||||
assertEquals(1, diff.removed)
|
||||
// A small edit is shown whole, nothing summarised.
|
||||
assertEquals(0, diff.omitted)
|
||||
assertEquals(
|
||||
listOf(
|
||||
DiffLine(DiffKind.CONTEXT, "one"),
|
||||
@@ -99,6 +101,30 @@ class ChatFormatTest {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun toolEditDiffSummarisesAnOversizedEditInsteadOfRenderingEveryLine() {
|
||||
// Wholly disjoint old/new blocks: every line is a change, so the full diff
|
||||
// is twice the block size — far past what a phone should render.
|
||||
val changed = MAX_RENDERED_DIFF_LINES + 50
|
||||
val old = (1..changed).joinToString("\n") { "old $it" }
|
||||
val new = (1..changed).joinToString("\n") { "new $it" }
|
||||
val diff = toolEditDiff(
|
||||
JsonObject(
|
||||
mapOf(
|
||||
"filePath" to JsonPrimitive("/tmp/big.txt"),
|
||||
"oldString" to JsonPrimitive(old),
|
||||
"newString" to JsonPrimitive(new),
|
||||
),
|
||||
),
|
||||
)!!
|
||||
// The stat still describes the whole edit...
|
||||
assertEquals(changed, diff.added)
|
||||
assertEquals(changed, diff.removed)
|
||||
// ...but only a readable prefix is rendered, the rest counted as omitted.
|
||||
assertEquals(MAX_RENDERED_DIFF_LINES, diff.lines.size)
|
||||
assertEquals(2 * changed - MAX_RENDERED_DIFF_LINES, diff.omitted)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun toolEditDiffIsNullForNonEdits() {
|
||||
assertNull(toolEditDiff(null))
|
||||
|
||||
Reference in New Issue
Block a user