Commit Graph

143 Commits

Author SHA1 Message Date
Li Liu 6e31ec33ac test: drop obsolete summaries assertion after summary-step removal
The per-reviewer summary step was removed in 0f03726, dropping the
summaries field from DebateResult, but this test still asserted on it
and failed. Remove the stale assertion.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-26 14:28:30 -07:00
Li Liu f94808969f feat: add --fail-fast option to abort review/discuss on any reviewer failure
By default the orchestrator is resilient: a single reviewer (or context
gatherer) failure is logged and the round continues with the survivors,
aborting only when all reviewers fail.

The new --fail-fast flag flips to strict mode — any reviewer or
context-gathering failure re-throws immediately and terminates the
whole flow. Wired through the review and discuss commands via
OrchestratorOptions.failFast, with a regression test and README docs.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-26 14:24:03 -07:00
Li Liu 0f0372656d refactor: remove redundant per-reviewer summary step before final conclusion
The summarizer now generates the final conclusion directly from the full
debate conversation history, eliminating the intermediate step where each
reviewer was asked to summarize their own points. This saves one round of
API calls per reviewer without losing information.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-03 14:56:47 +08:00
Li Liu 5ff7f2ea1a feat: add verified conclusion step that cross-checks summary against actual code
After the summarizer produces the final conclusion, a new verification step
re-examines it against the original PR diff/code to confirm correctness,
flag false positives, catch missed issues, and produce an authoritative
verified final conclusion.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 19:32:08 +08:00
Li Liu 91d0b2388f feat: support specifying models for CLI providers via colon syntax
Allow CLI providers (claude-code, codex-cli, gemini-cli, qwen-code) to
accept a model override using colon syntax (e.g., `claude-code:claude-opus-4-6`).
Display the model name alongside reviewer IDs in review and discuss output.
Update default Gemini API model to gemini-3.1-pro-preview.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 18:28:24 +08:00
Li Liu 62b61eb3e0 fix: handle large PR diffs that exceed GitHub's 20k line limit
gh pr diff returns HTTP 406 for PRs with >20,000 lines of diff.
Added fallback: fetch full diff via commit diff API endpoint (no line
limit), split into per-file sections, prioritize core files over tests,
and truncate to 15k lines to fit model context windows.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 18:20:59 +08:00
Li Liu aec6f67509 feat: add general discussion phase before issue-by-issue review
Introduce an optional General Discussion phase for PR reviews that sits
between review completion and the issue-by-issue comment loop. Users can
select participants, ask general questions, and resolve issues inline
(/post, /skip, /edit, /discuss, /issues) so only remaining issues flow
into the per-issue loop.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-16 17:39:11 +08:00
Li Liu b78cf9cc24 fix: strengthen language enforcement by injecting instructions into system prompt prefix
Move language instructions from user message suffix to system prompt prefix
where LLMs give them higher weight. Add langPrefix/withLang() to orchestrator
so all reviewer/analyzer/summarizer calls get the language requirement.
Also wire discuss command to use config.defaults.language instead of only
following user input language.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 11:19:20 +08:00
Li Liu 8a8dab1ec4 fix: improve inline PR comment placement with content-based matching and full diff fallback
- Add extractDiffLineRanges() to include valid line ranges in structurizer prompt
- Add content-based matching (extractCodeFromBody + findLineByContent) as fallback
- Add full diff fallback via gh api when per-file patches are null
- Widen nearest-line threshold from 20 to 50 for better coverage

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 18:12:23 +08:00
Li Liu ad7f0d1e0c fix: auto-select all reviewers in non-TTY mode to prevent hanging
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 13:58:52 +08:00
Li Liu 4fe80c808c chore: move typescript to devDependencies, remove unused readline package
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 13:58:11 +08:00
Li Liu 613c1b479c fix: add SIGKILL fallback after SIGTERM timeout in CLI providers
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 13:57:24 +08:00
Li Liu 64dd42a045 fix: add retry with backoff to all CLI providers and Gemini streaming
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 13:57:04 +08:00
Li Liu 5df0e65e5e feat: pre-flight check for CLI binaries with friendly error messages
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 13:55:12 +08:00
Li Liu c2d0f583af fix: register exit handler to clean up temp prompt files
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 13:55:09 +08:00
Li Liu 6bc75ca3ea fix: single reviewer failure no longer terminates entire review session
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 13:53:05 +08:00
Li Liu 38ff61471a fix: prevent command injection in history-collector via spawnSync
Replace execSync with spawnSync in getFileHistory() and getPRDetails()
to prevent shell injection through file paths and PR numbers. Add input
validation for prNumber (must be a positive integer).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 13:51:12 +08:00
Li Liu 9a6aaca563 fix: prevent command injection in reference-collector via spawnSync
Replace execSync with spawnSync in findReferences() to prevent shell
injection through malicious symbol names in PR diffs. Use -F (fixed-string)
and -e flags for safe argument passing to ripgrep.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 13:51:08 +08:00
Li Liu b541b509d7 fix: improve inline PR comment placement with near-line matching
When the AI reviewer references a line not exactly in a diff hunk,
find the nearest valid diff line (within 20 lines) and post inline
there instead of falling back to file-level. Also constrain the
structurizer prompt to only reference files actually in the diff.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-04 23:29:14 +08:00
Buqian Zheng 14a6f42a8e fix: allow round-1 convergence and stop spinner before round output (#9)
- Allow convergence check on round 1: independent reviewers reaching
  the same conclusions is valid convergence
- Adapt convergence prompt to distinguish independent reviews (round 1)
  from cross-examined reviews (round 2+)
- Stop any running spinner in onRoundComplete before printing round
  results to prevent terminal output artifacts

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-04 00:30:31 +08:00
Li Liu 87abf873cd fix: handle large PR review failures in CLI providers
- Add stdin EPIPE error handlers to prevent unhandled exception crashes
  when child processes exit before reading all input
- Clear CLAUDECODE env var to avoid nested session detection when
  running from within Claude Code
- Write large prompts (>100KB) to temp files instead of stdin to bypass
  CLI prompt size limits; CLI tools read the file via their built-in
  file access capabilities
- Capture stderr in claude-code streaming mode for better error reporting

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-03 21:40:11 +08:00
Buqian Zheng 7156c3a5ed fix: stdin resume after ora spinner, Ctrl+C handling, diff filtering, and context gatherer i18n (#8)
- Fix readline hanging after ora spinner pauses stdin: add process.stdin.resume()
  before rl.question() at all spinner→input transition points across review, discuss,
  and interactive modules
- Fix Ctrl+C not working during analysis/debate: replace silent flag-only SIGINT
  handler with double-press-to-force-exit pattern; add InterruptedError + checkpoint
  checks in orchestrator between analysis, debate rounds, and summarization
- Add diff filtering: new diff-filter utility with built-in patterns for generated
  files (*.pb.go, vendor/**, lockfiles, etc.) and user-configurable diff_exclude
- Add language support to context gatherer: pass config.defaults.language to
  ContextGatherer so System Context section respects language setting

Signed-off-by: Buqian Zheng <zhengbuqian@gmail.com>
2026-03-02 21:58:58 +08:00
Li Liu a472b45323 feat: add post-review discussion phase, comment style prompt, /skip, and language config
- Add interactivePostReviewDiscussion() for chatting with any role after review conclusion
- Show all roles (reviewers + analyzer + summarizer) in comment discussion picker
- Add comment style prompt before issue loop to style-guide first-gen comments
- Add /skip and /drop to abandon issues mid-discussion
- Add defaults.language config for localized output (e.g. language: zh)
- Expose getAnalyzer() and getSummarizer() from orchestrator
- Share reviewer sessions across discussion and comment phases

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Li Liu <li.liu@zilliz.com>
2026-03-02 12:09:10 +08:00
Li Liu c11554c781 feat: add --no-post flag to skip GitHub comment flow
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Li Liu <li.liu@zilliz.com>
2026-02-27 08:53:20 +00:00
Li Liu 22cfae3347 fix: pass prompt via stdin instead of args to avoid E2BIG on large diffs
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Li Liu <li.liu@zilliz.com>
2026-02-27 08:29:19 +00:00
ChrisPan bf896593b3 feat: add custom API base URL support for all API providers (#6)
Allow users to configure `base_url` per provider to connect to
compatible third-party endpoints (Azure OpenAI, Ollama, vLLM, one-api,
etc.). All four API providers (Anthropic, OpenAI, Gemini, MiniMax) now
accept an optional `base_url` in config which is passed through to
their respective SDKs.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-26 22:55:17 +08:00
Li Liu 20dba4f0f3 fix: resolve correct upstream repo when reviewing PRs from a fork
When a bare PR number is given while in a fork's local clone, the code
now uses `gh pr view` to resolve the actual upstream repo before falling
back to git remote detection. This prevents 404 errors when posting
review comments on PRs that live on the upstream repository.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 22:52:37 +08:00
Li Liu aabf5924e7 fix: require exhaustive file-by-file review to eliminate partial findings
Reviewer prompts previously allowed LLMs to stop after finding a handful
of issues. Now every round demands systematic coverage of all changed
files/functions, and debate rounds additionally require reviewers to
identify what others missed.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 17:16:15 +08:00
Li Liu 2b0e1ba711 refactor: comprehensive codebase improvements across 7 phases
Phase A - Quick fixes:
- Remove debug logging that leaked prompt content (qwen-code)
- Fix orchestrator session leak with try/finally cleanup
- CJK-aware token estimation for better accuracy
- Issue parser validation (line > 0, endLine >= line, non-empty fields)
- Improved similarity matching with stop words filtering and description weight

Phase B - Medium fixes:
- Add retry utility with exponential backoff for API providers
- Config validation at load time (required fields, empty API key warnings)
- GitHub PR comment deduplication (skip already-posted comments)
- Ctrl+C graceful exit for interactive comment review

Phase C - Structured logging:
- Logger class with debug/info/warn/error levels (MAGPIE_LOG_LEVEL env var)

Phase D - Type safety:
- Replace `any` types with proper types across discuss.ts, review.ts,
  issue-parser.ts, commenter.ts, repo-orchestrator.ts, history-collector.ts

Phase E - Session helper extraction:
- CliSessionHelper class shared by 4 CLI providers, reducing duplication

Phase F - Split review.ts (1991 → 6 files):
- review.ts (command + action), interactive.ts, repo-review.ts,
  session-cmds.ts, utils.ts, types.ts

Phase G - Tests:
- 6 new test files (retry, logger, session-helper, issue-parser-enhanced,
  loader-validation, orchestrator-session)
- Fix pre-existing test failures (commenter, anthropic)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-25 22:46:46 +08:00
Li Liu fe080cd8e1 feat: prompt user before fallback when inline comment placement fails
Classify comments against PR diff before posting. When comments cannot
be placed inline (line not in diff), show user the fallback plan and
offer choices: post all with fallback, inline only, retry as inline,
or skip.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-25 21:03:28 +08:00
Li Liu 5083785500 fix: post review comments as inline code annotations instead of global PR comments
Use GitHub Reviews API to batch-post comments as a proper code review.
Parse PR diff to determine valid line placements, with three-level
fallback: inline (exact line) → file-level (attached to file) → global.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-25 21:00:20 +08:00
Li Liu 28c1d460c7 feat: add disappearing placeholder hint for discussion input
Show a dim "Enter to end discussion" hint at the input prompt that
automatically clears when the user starts typing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-25 20:36:03 +08:00
Li Liu 79e30b082a feat: persistent reviewer sessions in post-processing discussion
Maintain a single session per reviewer across all issue discussions,
so that context (PR diff, gathered context, debate history) is sent
once at session start and subsequent issues use --resume for
claude-code provider. This enables cross-issue context sharing and
eliminates cold-start overhead per issue.

- Add ReviewerSessionState interface and session management helpers
- buildInitialSessionContext: rich first message with full PR context
- getOrCreateSession: lazy session creation with provider startSession
- Use DebateResult type instead of inline type for better type safety
- Wrap discussion flow in try/finally to guarantee session cleanup
- Synthetic assistant reply after initial context to maintain
  user/assistant alternation for API-based providers

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-25 20:34:22 +08:00
Li Liu 99ee72433a fix: support cross-repo PR comment posting via --repo flag
When reviewing a PR from a different repository using a full GitHub URL,
the commenter commands (gh pr view, gh pr comment) defaulted to the
current directory's git remote, causing "Could not resolve PullRequest"
errors. Now extracts owner/repo from the PR URL and passes --repo flag.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-25 20:06:07 +08:00
Li Liu 0f7b85cc5b feat: add regenerate option for post-discussion comments
After discuss generates a comment, users can now press [r] to
regenerate with custom instructions (e.g. "more concise", "add code
example"). Supports unlimited regeneration cycles with full
conversation context preserved.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-25 19:48:03 +08:00
Li Liu 8b35dbecbf docs: update README with new providers, post-processing, and debug mode
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 21:27:52 +08:00
Li Liu 1efe5165c7 fix: post inline comments per-line instead of one big review
Rewrote commenter to post each issue as an individual inline comment
on the specific line via GitHub PR comments API. If the line is not
in the diff, falls back to a regular PR comment with file:line context.
Previously used batch PR review API where one invalid line would fail
the entire batch.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 21:22:31 +08:00
Li Liu dda200a8a9 feat: auto-explain issues on discuss + progress tracking
- Discussion mode ('d') now auto-sends first message asking the
  reviewer to explain the issue in detail (where, why, how to fix)
  before user interaction begins
- Progress bar shows running tally: posted/edited/discussed/skipped
  counts displayed on each issue header

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 21:17:28 +08:00
Li Liu 4beed0fd9c fix: ora discardStdin kills process during interactive discussion
Root cause: ora's default discardStdin=true calls process.stdin.pause()
when spinner stops. This makes the stdin handle inactive in libuv, and
since readline's question() does not call resume(), the event loop sees
no active handles and the process exits silently. Only affects TTY
environments (stdinDiscarder checks isTTY).

Fix: use discardStdin:false on all ora spinners that coexist with
readline, plus explicit process.stdin.resume() safety net.

Also includes:
- Multi-turn discussion with conversation history and debate context
- AI-generated final comments after discussion
- unhandledRejection guard for async generator cleanup
- Pre-fetch PR diff so API-only models get the code
- Solo review/discuss support (min 1 reviewer, skip convergence)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 21:15:11 +08:00
Li Liu 52577cfce1 fix: add stream cleanup to anthropic/openai providers
- AnthropicProvider: stream.abort() in finally block ensures HTTP
  connection is released even if consumer breaks early
- OpenAIProvider: stream.controller.abort() for same reason
- GeminiProvider: document that consuming all chunks is sufficient

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 21:14:57 +08:00
Li Liu fe9257ebcc feat: add mock, qwen-code, minimax providers
- MockProvider for debug mode: supports MAGPIE_MOCK_DELAY,
  MAGPIE_MOCK_RESPONSE, MAGPIE_MOCK_FILE env vars; echoes input by default
- QwenCodeProvider: wraps qwen-code CLI (OAuth-based)
- MiniMaxProvider: API-based provider using MiniMax-M2.5
- config.mock top-level flag: when true, all models route to MockProvider
- model prefix matching: mock, mock1, mock2 etc. all map to mock provider

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 21:14:49 +08:00
Li Liu c54f1e1149 feat: add session support for Codex CLI provider
Use `codex exec --json` and `codex exec resume <thread_id>` to maintain
multi-turn conversation state, matching Claude and Gemini CLI behavior.
In debate rounds, only the last message is sent instead of full history.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 00:50:51 +08:00
Li Liu cea0cb758c fix: rich issue descriptions + fix discuss flow in post-processing
1. Structurizer now requests comprehensive markdown descriptions with
   original code quotes, impact analysis, and fix rationale — suitable
   for GitHub PR comments.

2. Fix discuss (d) silently skipping: raisedBy was stripped by
   parseReviewerOutput, defaulting to ['summarizer'] which matched no
   reviewer. Now preserved through parsing pipeline, with fallback to
   first available reviewer.

3. Issue display now renders markdown via marked() for proper formatting.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 15:07:00 +08:00
Li Liu e40eb6afc8 fix: disable tools for structurizer to prevent code modification instead of JSON extraction
When extracting structured issues from review text, Claude Code with
--dangerously-skip-permissions would interpret file paths and fix suggestions
as instructions to modify code, producing "All fixes applied..." instead of
JSON. Fix by passing --tools "" to disable all tools for the structurizer call.

Also: end summarizer session before structurization for clean non-session call,
make issue-parser more lenient (accept raw JSON objects, optional verdict/summary).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 00:04:31 +08:00
Li Liu 6afc9a9498 fix: flush analysis buffer before displaying system context
The analysis content was still buffered when onContextGathered fired,
causing the context section to appear before the analysis text.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 21:45:28 +08:00
Li Liu 0673274030 refactor: always use AI to extract structured issues, never parse reviewer JSON
Reviewer output format is not under our control. Instead of trying to
parse JSON blocks from reviewer messages (which may not match our schema),
always use the summarizer to extract structured issues from the review
discussion text. This is more robust and removes any dependency on
reviewer prompt configuration.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 21:39:27 +08:00
Li Liu f265dacea7 feat: auto-structurize review issues when reviewers don't output JSON
When reviewers don't include structured JSON blocks in their output,
the summarizer is called to extract issues from the unstructured review
text into the standard JSON format. This ensures the per-issue
interactive post-processing flow always works for PR reviews.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 21:37:25 +08:00
Li Liu 4070d2ec70 fix: add role label to session names + fallback post-processing
1. Session names now include explicit role: "reviewer:gemini" instead of
   just "gemini", matching analyzer/summarizer pattern
2. PR post-processing no longer requires structured JSON issues. When
   reviewers don't output JSON blocks, offers to post the final
   conclusion as a general PR comment instead.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 21:33:59 +08:00
Li Liu 6ca7a14f54 fix: prevent context gatherer output from interleaving with analysis stream
Move onContextGathered callback to after Promise.all resolves, so context
displays after analysis finishes streaming. Work is still parallel, only
the display is sequential.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 21:28:09 +08:00
Li Liu 3a2ea02062 fix: add anti-preamble instruction to analyzer prompt
Prevents AI from outputting chatty preamble like "Here's my analysis"
before the actual content.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 21:25:47 +08:00