Skip to content
sbalagan22Public

About

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

BugTrap

Automated multi-agent code-review co-pilot for the "vibe-coding" era. Point it at a file, a pasted snippet, a GitHub PR, or a whole repository; specialized AI reviewers inspect the code, a coordinator reconciles their findings, and BugTrap returns a structured review with a clear safe-to-merge / blocked verdict — and can open a fix PR for you.

Built on Gemini → Vertex AI, Firebase/Firestore, and the GitHub API (Octokit), running entirely inside a single Next.js (App Router) app — there is no separate backend server.


The agents

BugTrap runs two specialist review agents, then a coordinator, plus an on-demand patch agent. All run gemini-2.5-flash through Vertex AI and return structured JSON (responseSchema-validated). Source: src/lib/agents.ts.

Agent Function What it does
Security runSecurityAgent Flags serious, exploitable vulnerabilities — SQL/command injection, path traversal, XSS, SSRF, auth bypass, unsafe deserialization, broken crypto, and hardcoded secrets (flagged by pattern, regardless of a "fake/test" label).
Bug / Correctness runCorrectnessAgent Flags genuine runtime bugs — off-by-one / out-of-bounds, null/undefined derefs, missing await, race conditions, infinite loops, clearly wrong logic. Receives the security findings as context.
Coordinator runCoordinatorAgent Synthesizes (does not concatenate): dedupes overlapping findings, resolves severity conflicts weighted by confidence, ranks worst-first, surfaces disagreements, and emits one verdict. Used by the paste/PR flow.
Patch runPatchAgent On demand, generates corrected code for a file's findings — backs "Suggest fix", per-file "Open PR", and "Fix all".

Major issues only. Both review agents are tuned to report only CRITICAL/HIGH findings, so the output stays signal-heavy. (There is no longer a separate readability agent — a readability field survives as a vestigial zero in the counts type only.)

The Markdown specs under agents/ describe the original agent-prompt design and predate the consolidation to two agents; the running prompts in src/lib/agents.ts are the source of truth.

Reliability

Each agent call retries on Vertex 429 RESOURCE_EXHAUSTED with exponential backoff, and empty/blocked/unparseable responses fail loudly (rather than silently degrading a file to "no findings"). Per-file scan concurrency is kept low to stay under quota. Agent timeout is 90s; if an agent still fails, the coordinator notes the gap and produces a verdict from the rest (graceful degradation).


Features

  • Four ways in — paste a file, paste a function, paste/point at a GitHub PR URL (/app), or scan an entire repository (/scan → /review/[reviewId]).
  • Live scan graph — a force-directed map of the repo streams in over SSE as files are scanned. Each file node shows its real language logo (devicon) at center, a finding ring, and security-shield / bug badges (both when a file has both); folders get a folder glyph. The verdict and progress update live.
  • IDE code panel — click any node or finding to open the file in a Monaco editor with findings decorated inline.
  • Suggest fix → Open PR — generate a corrected version of a file (patch agent), review it as a before/after diff, then commit it to a new branch and open a PR.
  • Fix all & open PR — generate fixes for every flagged file, review each before/after diff in a modal, then commit them all into one PR off the scanned branch.
  • PR review flow — for a GitHub PR, BugTrap fetches the diff, posts inline review comments, sets a commit status, and can open a fix PR.
  • Live companion webhook — a push/PR to a connected repo auto-rescans only the changed files and updates the review in Firestore (see below).
  • Persisted reviews — every scan is stored in Firestore and reachable by review id.

Getting started

npm install
npm run dev          # http://localhost:3000

Then open /scan to scan a public repo (no sign-in), or sign in with GitHub to scan private repos and open fix PRs.

Commands

Command Purpose
npm run dev Dev server
npm run lint ESLint
npx tsc --noEmit Typecheck
npm run build Production build (must pass clean)
npm run start Serve the production build

There is no test suite yet; the verify step for any change is npx tsc --noEmit && npm run build && npm run lint.


Architecture

src/
  app/
    page.tsx                       landing page
    app/page.tsx                   paste / PR review flow (coordinator verdict)
    scan/page.tsx                  repo picker + public-repo scan entry
    review/[reviewId]/page.tsx     live scan graph + code panel + fix-all
    api/
      scan/route.ts                SSE: stream a full-repo scan
      review/route.ts              paste/PR review (agents → coordinator → patch)
      patch/route.ts               generate a fix for one file's findings
      open-pr/route.ts             commit fixed file(s) → one PR off the scanned branch
      github/                      repos, tree, file, connect, webhook(+register)
  components/review/               graph, code panel, file tree, fix-all modal
  lib/
    agents.ts                      the 4 agents (security, correctness, coordinator, patch)
    gemini.ts                      Vertex AI client + model routing
    scan-runner.ts                 core scan engine (shared by SSE + webhook)
    scan-filter.ts                 which files are reviewable
    github.ts / octokit.ts         GitHub API helpers (incl. createScanFixPR)
    firestore.ts / firebase-admin.ts   persistence

Stack: Next.js (App Router) · React · TypeScript (strict) · Tailwind · Monaco editor · react-force-graph-2d · devicon · Google Gen AI SDK (Vertex AI) · Firebase Admin · Octokit.


GitHub push-webhook scan (live companion)

A push or PR (opened / synchronize) to a connected repo auto-rescans only the changed files through the review pipeline and updates the review in Firestore. It runs inside the Next.js app — there is no separate server.

GitHub push / PR
  → POST /api/github/webhook        verify HMAC (403 if bad) → ack 200 within ~10s
  → [after()] collect changed paths  added + modified (push) / PR files; source files only,
                                      capped so the scan finishes in-window
  → runScan({ onlyPaths })          src/lib/scan-runner.ts — security → correctness per file,
                                      low concurrency, all on Vertex AI
  → Firestore: reviews/{id} (+ files, findings)

The webhook is registered per repo via POST /api/github/webhook/register, which derives the callback URL from the request origin (works in preview and production without a PUBLIC_URL env var). Registration is idempotent and backs the connect-repo UI flow.

Persistence

  • reviews/{reviewId} — { uid, owner, repo, branch, status, totals, verdict, truncated, … }
  • reviews/{reviewId}/files/{id} and reviews/{reviewId}/findings/{id}

Verdict rolls up per file: blocked if any file has a CRITICAL/HIGH finding, else safe. No raw secret or file content is logged.


Environment

var purpose
GOOGLE_CLOUD_PROJECT, GOOGLE_CLOUD_LOCATION route all agent calls through Vertex AI
FIREBASE_CLIENT_EMAIL, FIREBASE_PRIVATE_KEY service-account credentials for Vertex auth + server-side Firestore writes (passed explicitly, so the same code runs locally and on a managed host)
GITHUB_TOKEN shared server token, used only for read-only access to public repos in the no-sign-in flow
per-user GitHub OAuth token stored server-side at users/{uid}; used to read private repos and open fix PRs
TUNED_MODEL_SECURITY / TUNED_MODEL_CORRECTNESS (optional) point an agent at a tuned Vertex model endpoint; falls back to gemini-2.5-flash

Never commit or log API keys, tokens, or PII — all secrets come from env vars.

Deploy note (Vercel): the post-ack webhook scan runs in after() within the route's maxDuration window; large pushes are capped so the scan can't be killed mid-run. The runtime service account needs roles/aiplatform.user.

About

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages