Skip to content

Work diff canvas breaks when the user's Git config sets diff.mnemonicPrefix, color.diff=always or diff.noprefix #279

Closed

Description

@NopeCharon

Expected and actual behavior / 实际现象与期望

The Work attempt diff (collect_git_delta in server/work_artifact_registry.py, and collect_diff in server/local_git.py for provider.diff without a ledger delta) should produce a standard a/ / b/ uncolored patch that parse_unified_diff can render, no matter how the user has configured git diff for their own terminal.

The patch commands only pass --no-ext-diff (and collect_diff not even that), so the user's diff configuration leaks into the machine-read patch:

  • diff.mnemonicPrefix=true (a commonly recommended setting) makes git diff HEAD emit c/ / w/ prefixes. The canvas then shows the file as w/src/app.py, and the real path from changed_files is appended as a second, hunk-less "modified" entry.
  • color.diff=always wraps every line in ANSI escapes (\x1b[1mdiff --git ...). No line matches a header or hunk, so the canvas shows only hunk-less entries from changed_files with 0 additions and 0 deletions, and the raw patch <pre> in the Work page shows escape codes.
  • diff.noprefix=true drops the prefixes, so diff --git lines no longer have the shape the parser expects.
  • diff.external is honored by collect_diff, so the patch returned by provider.diff can be any external tool's output.

Steps to reproduce / 复现步骤

In any Git workspace used for a Work attempt:

git config diff.mnemonicPrefix true      # or: git config color.diff always

Run an attempt that edits a tracked file (for example app.py), then open the attempt diff.

Actual (mnemonicPrefix): two entries, w/app.py with the hunks and app.py with none.
Actual (color.diff=always): one hunk-less entry app.py, additions == 0, deletions == 0.
Expected: one entry app.py with its hunks and counts.

The same can be seen directly:

git -c diff.mnemonicPrefix=true diff --no-ext-diff --unified=3 HEAD --   # diff --git c/app.py w/app.py

Relevant environment / 使用环境

Platform-independent; current main (fdd672e). Reproduced with Git 2.43 and 2.54. Affects any user whose global or repository Git config sets one of the options above.

Sanitized evidence / 错误信息或截图(请先脱敏)

git diff accepts --no-color --src-prefix=a/ --dst-prefix=b/ (and --no-ext-diff), which override these settings for a single command, so the Host can pin the format of the patches it parses without changing the user's configuration.

Related issues or fixes / 相关问题或修复

#274 / #275 fixed a different parser defect in the same diff canvas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions