Skip to content

Commit 24323cb

Browse files
committed
fix: deduct tier header tokens from budget in _build_package
The '### Relevant files' and '### Depends on' headers plus their trailing blank lines were appended without subtracting their token cost from remaining. Three unaccounted headers compound to ~30-40 tokens of budget overrun. Now each tier deducts header_cost before iterating entries. Skipped singleton accessor nitpick: dependency_analyzer.py, style_analyzer.py, and dna_extractor.py are all plain classes instantiated in dependencies.py -- no get_*() accessor pattern exists in the project. ContextAssembler already matches.
1 parent 6301f99 commit 24323cb

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

backend/services/context_assembler.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,10 @@ def _build_package(
237237

238238
# Tier 1: Relevant files (highest priority)
239239
if found_files and remaining > 50:
240-
tier_lines = ["### Relevant files"]
240+
header = "### Relevant files"
241+
header_cost = _estimate_tokens(header) + 1 # +1 for trailing blank line
242+
remaining -= header_cost
243+
tier_lines = [header]
241244
for r in search_results:
242245
fp = r.get("file_path", "")
243246
name = r.get("qualified_name", r.get("name", ""))
@@ -257,7 +260,10 @@ def _build_package(
257260

258261
# Tier 2: Dependency files
259262
if dep_files and remaining > 50:
260-
tier_lines = ["### Depends on"]
263+
header = "### Depends on"
264+
header_cost = _estimate_tokens(header) + 1
265+
remaining -= header_cost
266+
tier_lines = [header]
261267
for fp in dep_files[:10]:
262268
entry = f"- `{fp}`"
263269
entry_tokens = _estimate_tokens(entry)

0 commit comments

Comments
 (0)