Skip to content

Add budget-aware pack compression guidance - #306

Merged
mohanagy merged 2 commits into
nextfrom
issue-297-pack-compression
May 25, 2026
Merged

mohanagy merged 2 commits into
nextfrom
issue-297-pack-compression

Conversation

@mohanagy

@mohanagy mohanagy commented May 25, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • make context-pack rendering compress selected nodes more aggressively under tight budgets
  • keep helper-like lexical matches out of implement-pack edit targets and surface them in negative guidance
  • document the new budget-aware compression and distractor guidance behavior

Closes #297

Summary by CodeRabbit

  • New Features

    • Implemented task-aware handling of helper and generated files in implementation packs—these are now marked as supporting context rather than primary edit targets.
    • Added budget-aware rendering that dynamically adjusts detail levels based on available token budget.
  • Documentation

    • Clarified format options: --format json for tool/script consumption, --format text for brief execution summaries.
    • Expanded guidance on adaptive context-pack representations and budget-aware compression.
  • Tests

    • Added test coverage for helper file handling in implementation packs.
    • Added test coverage for budget-based representation selection.

Review Change Stack

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented May 25, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

@mohanagy, we couldn't start this review because you've used your available PR reviews for now.

Your plan includes 10 reviews of capacity. Refill in 5 minutes and 1 second.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more review capacity refills, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than trial, open-source, and free plans. In all cases, review capacity refills continuously over time.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 476cda50-f7f6-4968-847d-3fa7e7c8ee4f

📥 Commits

Reviewing files that changed from the base of the PR and between eebe73b and b25127a.

📒 Files selected for processing (2)
  • src/runtime/implementation-pack.ts
  • tests/unit/implementation-pack.test.ts
📝 Walkthrough

Walkthrough

This PR implements token-budgeted pack compression and negative guidance per issue #297. It detects helper-like and distractor patterns, filters them from implementation edit paths while emitting negative guidance, applies budget-aware rendering to compress already-selected nodes, and adds corresponding test coverage and documentation.

Changes

Token-budgeted pack compression and negative guidance

Layer / File(s) Summary
Distractor detection and negative guidance emission
src/infrastructure/context-pack-command.ts, tests/unit/context-pack-command.test.ts
Introduces IMPLEMENTATION_DISTRACTOR_PATTERN regex matching helper/util/generated/build artifacts. Extends negativeGuidance() to scan implementation patterns and emit negative guidance instructing that matched source files be treated as supporting context rather than edit targets. Test fixture builder and new test case verify lexical helpers like context-pack-helper.ts are excluded from likely_edit_files and appear in negative_guidance.
Helper-like file filtering in implementation pack
src/runtime/implementation-pack.ts
Adds helperLikeFileContext() to detect files matching HELPER_PATTERN. Updates mergeLikelyEditFiles() to compute hasNonHelperWorkflowCenter, then excludes helper-like candidate centers and starter files when non-helper centers exist, filtering distractors in favor of workflow-relevant files.
Budget-aware rendering and compression
src/runtime/context-pack.ts, tests/unit/context-pack.test.ts
Implements resolutionForTaskBudget() to select between summary/signature/sketch modes based on token budget and node count, and canPreserveExplainDetail() to gate full-detail snippet preservation for explain tasks only when derived resolution is sketch. Updates renderCompiledContextPackNodes() to use budget-derived resolution and conditional detail preservation. Test verifies tighter budgets compress auth_controller from detail to non-detail and reduce overall token count.
Documentation updates
README.md
Clarifies task-aware negative_guidance for --task implement, documents --format json for tool consumption and --format text for brief execution. Expands "Adaptive context-pack representations" to explain adaptation as rendering-only layer (selection unchanged) and budget-aware compression preserving full detail for explain packs when budget allows.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • mohanagy/madar#279: Modifies context-pack-command and implementation-pack flow for task: 'implement', adding task-aware guidance retrieval that overlaps with this PR's negative guidance emission.
  • mohanagy/madar#302: Changes src/infrastructure/context-pack-command.ts output schema with Pack Schema v1 and --format envelope, directly overlapping in command output construction.
  • mohanagy/madar#304: Adds scored workflow_centers to drive likely_edit_files; this PR further filters helper-like centers during mergeLikelyEditFiles, extending the selection logic.

Poem

🐰 Context packs grow sleek with budget-aware compression,
Negative whispers guide which helpers to avoid,
Distraction patterns fade while workflow centers stay—
The renderer learns: sketch full, summarize tight,
Brief, bold, and focused: that's the madar way! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Add budget-aware pack compression guidance' accurately reflects the main change: implementing budget-aware compression for context packs and guidance improvements.
Description check ✅ Passed The description covers the three main changes (pack compression, helper-like guidance, documentation) and references the closed issue, but omits testing evidence per the template's checklist items.
Linked Issues check ✅ Passed The PR implementation addresses all key acceptance criteria: budget-aware compression with representation tiers, negative_guidance for distractors, helper-like file filtering, and test coverage for lexical helpers.
Out of Scope Changes check ✅ Passed All changes are directly within scope: README updates document new behavior, implementation adds budget-aware rendering and helper filtering, and tests verify the new functionality against requirements.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch issue-297-pack-compression

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/runtime/implementation-pack.ts`:
- Around line 565-567: The suppression of helper-like files (computed using
hasNonHelperWorkflowCenter and helperLikeFileContext) can accidentally drop
files that are explicitly named as edit targets; update mergeLikelyEditFiles to
accept an explicit-target escape hatch by passing retrieval.question from
buildImplementationPackGuidance into mergeLikelyEditFiles, then inside
mergeLikelyEditFiles detect when retrieval.question explicitly names a helper
file/symbol and skip the helper-like suppression for those explicit targets so
likely_edit_files preserves user-specified helper edits.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 28a5a25e-9710-4d85-aa69-4c1f8ae2259b

📥 Commits

Reviewing files that changed from the base of the PR and between 0325f15 and eebe73b.

📒 Files selected for processing (6)
  • README.md
  • src/infrastructure/context-pack-command.ts
  • src/runtime/context-pack.ts
  • src/runtime/implementation-pack.ts
  • tests/unit/context-pack-command.test.ts
  • tests/unit/context-pack.test.ts

Comment thread src/runtime/implementation-pack.ts Resolved
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@mohanagy
mohanagy merged commit c2e2b7b into next May 25, 2026
7 checks passed
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.

1 participant