Feat/ai orchestrator token opt#23
Merged
Merged
Conversation
- Add spinner.start/stop aliases for plan module compatibility - Extract path from diff --git line as fallback in git parser - Defensive nil handling for file paths in prompt builder - Limit to max 10 concurrent AI calls with queue-based processing
Adds a tmp-file-backed progress tracker that CLI agents append to as they finish each file. The orchestrator polls every 250ms and emits on_progress(done, total) so plan and review spinners reflect real-time per-file progress. HTTP providers (anthropic, openai, ollama) are unaffected and continue using the existing per-batch on_batch_complete counter.
Pack diffs into batches by char budget (default 80 000 chars / 15 files) before sending to the AI provider. Amortises instruction overhead across files, cutting AI calls on large MRs to a fraction of the old per-file count. Review uses a tighter per-spec budget (40 000 / 8) because full file content is included alongside diffs. - Add lua/codereview/ai/batch.lua: M.build(diffs, opts) greedy packer - Add ai.batch_char_budget (80 000) and ai.batch_max_files (15) defaults - Orchestrator: replace 1-file-per-batch loop with batch.build(); per-spec overrides (spec.batch_char_budget / spec.batch_max_files) take priority - plan/prompt: add build_batch_plan_prompt(files, opts) - ai/prompt: add build_batch_review_prompt(review, files, contents, opts) - plan/init: swap build_prompt to batch variant; spinner counts files not batches - review/init: swap to batch variant; pre-fetch content per file in batch; ai_file_done() called N times (once per file in batch) - Tests: batch_spec (TDD), orchestrator_spec updated, integration_spec asserts 5 small files → 1 batch
…ss race, parser fallback)
- gitlab.lua: properly URL-encode file paths with spaces/special chars - file_filter.lua: fix glob_to_pat null-byte placeholder corruption The glob pattern `\0DBL\0` placeholder was interpreted by Lua's gsub as matching every position, corrupting patterns like `*.json` into garbage. Replaced with `<<<DBL>>>` string placeholder.
GitLab returns `description: null` for MRs with no description. By
default `vim.json.decode` maps JSON null to `vim.NIL` (userdata), which
is truthy — so existing `or ""` guards in `types.normalize_review` and
`format_mr_preview` passed it through unchanged, causing
`attempt to concatenate a userdata value` when the picker rendered the
preview.
Pass `{ luanil = { object = true, array = true } }` to all
`vim.json.decode` call sites so null becomes nil throughout. Existing
`~= vim.NIL` checks in github.lua remain correct (nil ~= vim.NIL).
Fixes #22
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.
Reduces AI review token usage and introduces a new
:CodeReviewPlancommand that reuses the same orchestration. Also fixes #22.:CodeReviewPlan(new):CodeReviewPlanuser command for AI-generated implementation plans from a branch diff.plan/reviewso both code paths share file filtering, batching, progress, and provider plumbing.Token optimization
cache_controlmarkers so prompt prefixes stay cacheable across runs.ai_skip_patternsvia.codereview.nvimdotfile, parsed in auth and merged into orchestrator + review init. Shared helper infile_filter.Bug fixes
fix(api): JSONnullfrom GitLab (e.g. empty MR description) now decodes to Luanilinstead ofvim.NILuserdata, fixing theattempt to concatenate a userdata valuecrash when opening:CodeReviewon a repo with several MRs. Fixes OpeningCodeReviewon repository with several merge requests fails with formatting #22.fix(ai): URL encoding and glob pattern matching bugs in skip-pattern handling.fix(ai): filtered-files spinner state, progress race, and parser fallback (from earlier code-review pass).fix(plan): handle nil paths and limit concurrent AI calls.