Commit Graph

5 Commits

Author SHA1 Message Date
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 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
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 76e0031527 fix: add PR number validation to prevent command injection
Validates that PR numbers are numeric-only in postPRReview and
getPRHeadSha before passing them to shell commands.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 20:00:27 +08:00
Li Liu 1625347559 feat: add GitHub PR comment posting utility
Add commenter module that builds GitHub PR review payloads from merged
issues. Issues with file+line become inline review comments, issues
without line info go into the review body. Includes gh CLI wrappers for
posting reviews and fetching PR head SHA.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 19:46:11 +08:00