Skip to content

Commit fca3fde

Browse files
committed
Improve content budget utilization
1 parent ff613e4 commit fca3fde

3 files changed

Lines changed: 23 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ Semantic Versioning.
77

88
## [Unreleased]
99

10+
### Fixed
11+
- Use unused full-content budget for snippets so content fills available budget.
12+
- Apply per-file snippet cap only when the snippet pool is tight.
13+
1014
## [0.3.0] - 2026-02-03
1115

1216
### Added

src/packer/mod.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,8 @@ fn pack_impl(
480480
let snippet_limit = remaining.saturating_sub(full_limit);
481481

482482
let mut full_budget = make_budget_like(budget.target, full_limit);
483-
let mut snippet_budget = make_budget_like(budget.target, snippet_limit);
483+
let mut snippet_budget_limit = snippet_limit;
484+
let mut snippet_budget = make_budget_like(budget.target, snippet_budget_limit);
484485

485486
let max_full_units = units_from_tokens(config.content.max_full_tokens, budget.target);
486487
let max_snippet_units =
@@ -555,6 +556,16 @@ fn pack_impl(
555556
}
556557
}
557558

559+
// If full-content pool went unused (e.g. files exceed max_full_tokens),
560+
// roll the unused budget into the snippet pool.
561+
if !full_budget.is_exhausted() {
562+
let extra = full_budget.remaining();
563+
if extra > 0 {
564+
snippet_budget_limit = snippet_budget_limit.saturating_add(extra);
565+
snippet_budget = make_budget_like(budget.target, snippet_budget_limit);
566+
}
567+
}
568+
558569
let total_remaining = remaining_candidates.len();
559570
for (idx, candidate) in remaining_candidates.into_iter().enumerate() {
560571
if budget.is_exhausted() || snippet_budget.is_exhausted() {
@@ -571,7 +582,11 @@ fn pack_impl(
571582
per_file_limit = 1;
572583
}
573584
if max_snippet_units > 0 {
574-
per_file_limit = per_file_limit.min(max_snippet_units);
585+
let max_total = max_snippet_units.saturating_mul(files_left);
586+
// Only enforce the per-file cap when the snippet pool is tight.
587+
if snippet_budget.remaining() <= max_total {
588+
per_file_limit = per_file_limit.min(max_snippet_units);
589+
}
575590
}
576591
let max_units = per_file_limit
577592
.min(snippet_budget.remaining())

tests/edge_cases.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,8 +474,8 @@ fn test_spine_budget_truncation() {
474474
false,
475475
false,
476476
);
477-
assert!(output.contains("this_is_a_very_long_filename_alpha.rs"));
478-
assert!(!output.contains("this_is_a_very_long_filename_gamma.rs"));
477+
assert!(output.contains("a:{this_is_a_very_long_filename_alpha.rs"));
478+
assert!(!output.contains("c:{this_is_a_very_long_filename_gamma.rs"));
479479
}
480480

481481
#[test]

0 commit comments

Comments
 (0)