Skip to content

refactor(diff): strip index headers from review prompts - #609

Merged
lizhengfeng101 merged 1 commit into
alibaba:mainfrom
amh1k:refactor/strip-diff-index-header
Jul 30, 2026
Merged

lizhengfeng101 merged 1 commit into
alibaba:mainfrom
amh1k:refactor/strip-diff-index-header

Conversation

@amh1k

@amh1k amh1k commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Description

Removes Git index <old-hash>..<new-hash> <mode> headers from per-file diffs embedded in LLM review prompts.

These headers contain Git object IDs and file modes that do not provide useful code-review context. The parser removes them only outside diff hunks, preserving all actual code content and existing diff metadata behavior.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactoring (no functional changes)
  • Documentation update
  • CI / Build / Tooling

How Has This Been Tested?

  • make test passes locally
  • Manual testing (describe below)

Additional focused verification:

go test ./internal/diff
go test ./internal/diff -run TestParseDiffText_StripsIndexHeadersFromPromptDiff
make check

Added regression coverage verifying that:

  • index headers are removed for multiple files.
  • Git diff headers remain.
  • +index ... source content inside a hunk remains intact.
  • New-file metadata still parses correctly.

Checklist

  • My code follows the project's coding style (go fmt, go vet)
  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective or my feature works
  • New and existing unit tests pass locally with my changes
  • I have updated the documentation accordingly (if applicable)
  • I have signed the CLA

Related Issues

Closes #606

@github-actions

Copy link
Copy Markdown
Contributor

✅ OpenCodeReview: No comments generated. Looks good to me.

@lizhengfeng101 lizhengfeng101 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lizhengfeng101
lizhengfeng101 merged commit d55f5e5 into alibaba:main Jul 30, 2026
8 checks passed
kall pushed a commit to kall/open-code-review that referenced this pull request Aug 14, 2026
ocr core diff selected files with the default extension and path filters
only, so a repo whose rule.json excluded a directory still saw those files
in core output while ocr review skipped them. The gap was structural: core
never accepted a FileFilter at all.

Thread the filter through CoreDiffOptions and consult it in the same order
the review path does -- an explicit user exclude wins over everything, an
explicit user include short-circuits the default extension and path
filters -- then apply the deleted check on whatever survives, which is how
internal/agent's preview composes the same two steps. Because the matching
itself lives in rules.FileFilter, gitignore-style negation, directory
patterns, brace expansion, and case-insensitive matching come along for
free rather than being reimplemented.

The command gains --rule and --exclude to match review, scan, and delegate.
Both go through rules.NewResolver and the shared CLI-exclude merge, neither
of which touches provider config, so the core group still needs no API key.

Parity is pinned by one table run twice: internal/diff checks it through
coreWhyExcluded and internal/agent checks the same cases through
whyExcluded, so a future ordering change fails one side instead of quietly
shipping two different reviewable-file sets. A separate golden test pins
that index headers stay stripped from the core JSON diff body (alibaba#609).
Githab-capibara added a commit to Githab-capibara/open-code-review that referenced this pull request Sep 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants