gui: review pane shows no diff when git emits colour codes
Summary
The review pane lists changed files with correct insertion and deletion counts, but shows no diff body. Each hunk header in the patch that GET /api/vcs/diff returns carries an ANSI colour prefix, and the pane accepts a patch only when a line starts with @@ .
Environment
- opencode version: 2.3.2
- OS: macOS (Darwin, arm64)
- Terminal: OpenCode desktop app
- Shell: Unavailable: the client does not use a shell for this path
- Install/channel: latest
- Active plugins: none related to the review pane
Reproduction
- Make a scratch repository and turn colour on:
git init demo
cd demo
git config user.email [email protected]
git config user.name you
git config color.ui always
printf 'one\n' > example.txt
git add example.txt
git commit -m init
printf 'one\ntwo\n' > example.txt
- Open the repository in opencode and open the review tab.
- The pane lists
example.txtwith+1 −0. - Select the file.
Expected Behavior
The pane shows the one added line.
Actual Behavior
The diff body is empty. GET /api/vcs/diff?location[directory]=…&mode=working&untracked=folders returns the patch with colour codes:
{
"file": "example.txt",
"patch": "\u001b[1mdiff --git c/example.txt w/example.txt\u001b[m\n\u001b[1m--- c/example.txt\u001b[m\n\u001b[1m+++ w/example.txt\u001b[m\n\u001b[36m@@ -1 +1,2 @@\u001b[m\n one\u001b[m\n\u001b[32m+\u001b[m\u001b[32mtwo\u001b[m\n",
"additions": 1,
"deletions": 0,
"status": "modified"
}
The client tests the patch for a bare hunk header before it keeps it (bundle: XU, called by wG):
function XU(e) {
if (e.additions === 0 && e.deletions === 0) return false;
const t = bV(e.file);
if (t === "image" || t === "audio") return false;
return !e.patch || !/^@@ /m.test(e.patch);
}
/^@@ /m cannot match ESC[36m@@ -1 +1,2 @@, so every row is treated as a row without a patch. The loader then returns undefined:
.then(t => (a.setQueryData(ye(e,n), t), wG(t,e)))
The counts still render, because the same response carries them and git computes them apart from colour.
With color.ui auto the same request returns the hunk without colour codes, the check passes, and the pane renders the diff.
Additional Context
- The server could pass
--no-color(or-c color.ui=false) to git. The client should also remove ANSI codes before it reads a patch, because a repository or a user config can set colour in other ways. - The same gate rejects a second payload. Turn mode calls
GET /api/session/{sessionID}/diff, which returns a patch of only the header lines (Index:,===,---,+++) with no@@hunk, while it reports a non-zero additions count. That mode also renders an empty body. - Frequency: always, when colour is on for piped output.
- Workaround:
git config --global color.ui auto.
Thanks for the precise report. I reproduced the server side of this on the released 2.3.2 CLI:
- In a scratch repo with
git config color.ui always, commitexample.txt, then add a line. - Run
opencode api --standalone get "/api/vcs/diff?location[directory]=…&mode=working&untracked=folders".
The returned patch has ANSI codes on every line, including the hunk header (\u001b[36m@@ -1 +1,2 @@\u001b[m), while additions: 1, deletions: 0 are correct. With color.ui auto the same request returns a plain patch. The script below reproduces it.
It still happens on the latest dev (b5e0abd) run from source: the git diff call that builds the patch doesn't turn colour off, and the GUI's diff code still looks for lines starting with a plain @@ .
I didn't watch the desktop or web review pane myself, and I haven't checked the turn-mode diff you mention (headers but no hunk). The API output above matches your description of why the pane comes up empty.
The workaround you found, git config --global color.ui auto, avoids it for now. A related symptom with different causes on Windows is tracked in #57441.
Reproduction script (repro.sh)
#!/usr/bin/env bash
# Reproduces #65075: /api/vcs/diff returns ANSI-coloured patches when git has color.ui=always.
# Usage: repro.sh [opencode command...] (default: opencode from PATH)
# From source: cd packages/cli && repro.sh bun --conditions=browser --preload=<repo>/packages/tui/node_modules/@opentui/solid/scripts/preload.js <repo>/packages/cli/src/index.ts
set -euo pipefail
OC=("${@:-opencode}")
DIR=$(mktemp -d /tmp/opencode/demo.XXXX)
# git setup runs in $DIR; opencode runs from the caller's directory
G() { git -C "$DIR" "$@"; }
G init -q .
G config user.email [email protected]
G config user.name you
G config color.ui always
printf 'one\n' > "$DIR/example.txt"
G add example.txt
G commit -qm init
printf 'one\ntwo\n' > "$DIR/example.txt"
"${OC[@]}" --version
# the first request after start-up can return an empty list; retry until the file shows up
for i in $(seq 1 10); do
"${OC[@]}" api --standalone get "/api/vcs/diff?location[directory]=$DIR&mode=working&untracked=folders" > /tmp/opencode/diff.json
grep -q example.txt /tmp/opencode/diff.json && break; sleep 1
done
cat /tmp/opencode/diff.json
echo
if grep -q '\\u001b\[36m@@' /tmp/opencode/diff.json; then echo "BUG: hunk header carries ANSI colour codes"; else echo "OK: no colour codes in hunk header"; fi
G config color.ui auto
sleep 2
"${OC[@]}" api --standalone get "/api/vcs/diff?location[directory]=$DIR&mode=working"
Run it: bash repro.sh
Taking this. The root cause is on the server side: both git paths that build patches let the user's colour setting through, so the ANSI codes are already in the patch text before any client parses it.
GET /api/vcs/diff(packages/core/src/plugin/vcs/git.ts) runsgit diffwith onlycore.*overrides, socolor.diff/color.uifrom the user's config applies.GET /api/session/{sessionID}/diff(packages/core/src/git.ts) diffs snapshot trees the same way, which is why turn mode also returns header lines only.
Both patches are parsed, never shown, so I will pass -c color.diff=false on those git invocations. The client-side ^@@ check then sees plain text without needing an ANSI strip. I'll add a regression test per path that sets color.diff = always in the repository config.