Repository navigation
fix: auto-diff budgets --max-tokens per file with the real tokenizer (#20 B14) - #67
Merged
Merged
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Notice accounting and fallback truncation can still violate the token budget, while signature truncation can remain undisclosed.
2 open findings
What changed in this PR
Updates auto-diff rendering to apply real tokenizer-based per-file budgets.
Changes:
- Shares file-budget fitting with the standard renderer.
- Adds clamping and omission reporting.
- Adds integration coverage and changelog documentation.
| File | Description |
|---|---|
src/lib.rs |
Applies budgeting to auto-diff output. |
src/markdown.rs |
Extracts shared budget-fitting logic. |
tests/test_autodiff_budget.rs |
Tests budgets, encodings, fences, and omissions. |
CHANGELOG.md |
Documents the auto-diff fix. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Part of #20 (B14). generate_markdown_with_diff now renders each file section through diff_file_section, budgets it with the shared fit_chunk_to_budget (extracted from render_truncated_to_fit, behavior unchanged), clamps the crossing file, and reports omitted files. The old byte cut remains only as a safety net when the header/diff/tree alone exceed the budget. Tests: tests/test_autodiff_budget.rs (in-process run_with_args + binary): real token count <= budget in o200k and cl100k, balanced fences, clamp marker, omitted count, large budget = no-op. Fails on master.