Repository navigation
feat: Phase 2 — Token Budget Manager and model limits - #4
Conversation
- Reject non-positive effective budgets instead of emitting nonsense limits - Truncate low-signal files first (snapshots, tests, generated), largest first within groups - Working copies via dataclasses.replace; identity-keyed index handles duplicate paths - Reuse last token count instead of a final paid recount - Document BudgetDecision aliasing contract and note semantics
- Document why ignore_globs and _is_low_signal stay separate mechanisms - Test whole low-signal group truncates before any normal file, in order - Test many guard-skipped small files collectively fall through to chunking
|
Follow-up fixes on top of the Phase 2 implementation, from the review round plus three clarification questions. Two commits:
Gate: 92 pytest green, |
…, and fix mixed chunking note
|
Follow-up review fixes addressing the pre-merge review items and audit findings: 1. Truncation policy decision record & simplification (Option A)
2. Anti-inflation guard &
3.
4. Domain typed exception
Gate: 97 pytest passed, |
- Reject negative reserved_output_tokens, default_template_overhead, and per-call template_overhead - BudgetDecision docstring now matches copy-all implementation on truncate paths
|
Follow-up commit addressing opencode's review findings:
Gate: 98 pytest passed, |
…d orchestrator consolidation - #1 (Blocker): Fail loud with exit code 1 on git errors, budget cap breaches, and gh CLI errors across pr-summary and changelog CLI commands. - #2: Prevent duplicate printing when no changes/commits exist by early returning None. - #3: Route diagnostic warnings, budget alerts, and error messages to stderr console (err_console) to keep stdout clean for Unix piping. - #4: Correctly parse and surface breaking changes (exclamation mark and BREAKING CHANGE: footers) in conventional commits and templates. - #5: Bump changelog template to version 2, including from_ref..to_ref range and explicit release headers. - #6: Support --title (-t) flag in pr-summary and propagate gh pr create failures. - #7: Remove dead head argument from fallback PR summary. - #8: Consolidate duplicate budget checking, safe telemetry recording, and heuristic token counters into orchestrator.py. - #9: Enforce strict type hints with CommitLogEntry in fallback.py.
Summary
Implements Phase 2: Token Budget Manager for
gitmateaccording toplan.md,AGENTS.md, and agreed design decisions.Key Deliverables
TokenCounterProtocol &GeminiTokenCounter:TokenCounterpure Python Protocol (count_tokens(text: str, model: str) -> int) decorated with@runtime_checkable.GeminiTokenCounterwraps Google GenAI SDK (google-genai), using caller-passed credentials (SecretStore) rather than ambientos.environ.TokenBudgetError,TokenCountError, andNoApiKeyError.Budget Decision Engine (
TokenBudgetManager):99092\text{effective_budget} = \text{context_window} - \text{reserved_output_tokens} - \text{template_overhead}99092
BudgetStrategy):FITS: full diff fits within budget.TRUNCATED: candidate files sorted by patch size descending are truncated with[patch omitted for size: +A/-D lines]until diff fits.NEEDS_CHUNKING: signals Phase 3 to execute chunked summarization when diff metadata alone exceeds budget.BudgetDecisionretains the original, untruncatedFileDiffs inomitted_diffsso Phase 3 can chunk without re-reading git.len(patch_text) <= len(note).Model Limits & Config:
DEFAULT_MODEL_CONTEXT_WINDOWS).max_context_tokensandreserved_output_tokens(with validation inload_config/save_config).UnknownModelErrorraised if a model's context window cannot be resolved and no override is provided.DEFAULT_TEMPLATE_OVERHEAD = 500tokens configured for Phase 2, ready for exact template token counts in Phase 4.Testing & Verification:
FakeTokenCounterand mocked GenAI client (zero real network/API calls).mypy src tests --strictandruff check .pass cleanly.