Skip to content

refactor(diff): strip index header line from diff embedded in prompts #606

Closed

Description

@lizhengfeng101

Description

When diffs are embedded into LLM prompts for code review, the full git unified diff header is included. The index <hash>..<hash> [mode] line (e.g. index d2a6fb5..f5c9b00 100644) provides no value for code review — the SHA hashes and file mode are meaningless to the model and waste tokens.

Current format in prompt:

diff --git a/internal/viewer/static/style.css b/internal/viewer/static/style.css
index d2a6fb5..f5c9b00 100644
--- a/internal/viewer/static/style.css
+++ b/internal/viewer/static/style.css
@@ -3,7 +3,7 @@

Expected (after fix):

diff --git a/internal/viewer/static/style.css b/internal/viewer/static/style.css
--- a/internal/viewer/static/style.css
+++ b/internal/viewer/static/style.css
@@ -3,7 +3,7 @@

Scope

  • File: internal/diff/parser.go
  • Function: ParseDiffText
  • The index line should be skipped when building the Diff string field, but only outside hunks (inside a hunk, a content line starting with index is valid file content prefixed with +/-/ ).

Acceptance Criteria

  • Lines matching index prefix (outside hunk context) are excluded from model.Diff.Diff
  • Metadata parsing (e.g. new file mode, deleted file mode) still works correctly since index line is not used for those
  • Tests pass (make test)
  • Code check passes (make check)

Context

All diff content flows through a single pipeline: GetDiff → ParseDiffText → model.Diff.Diff → prompt template substitution (via {{diff}}). Stripping the line in ParseDiffText covers all downstream consumers (main task, plan task, review filter task).

This is a minimal change (~3 lines) with no risk to existing functionality.

Activity

  1. added
    enhancement
    good first issue
    on Jul 30, 2026
  2. amh1k commented on Jul 30, 2026

    @amh1k
    Contributor

    Would like to work on this

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

    enhancementgood first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions