Add code-reviewer SDK example#21
Open
yurekami wants to merge 1 commit intocursor:mainfrom
Open
Conversation
A small CLI that turns a git diff into a structured code review. Streams a Cursor SDK agent (default model claude-4.6-sonnet-high) over a three-dot diff, validates a JSON schema (summary + comments[] with file/line/severity/category/suggestion), and exits non-zero on findings at or above a configurable severity so it can gate CI.
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.
Summary
sdk/code-reviewerexample: a small CLI that turns agit diffinto a structured code review by streaming a Cursor SDK agent over the diff and validating a strict JSON schema (summary+comments[]withfile,line,severity,category,comment,suggestion).base...head) so it reviews only the work onhead, matching what reviewers see on a GitHub PR.--fail-onseverity (defaulthigh), so it can drop in as a CI gate.claude-4.6-sonnet-high, overridable via--model/$CURSOR_MODEL. Conventions and boilerplate matchsdk/quickstart(pnpm, TS, ESM, top-level await, strict tsconfig, Node ≥22).README.mdto link the new example.What it demonstrates
{...}slice fallback) and full schema validation before use.Agent.create({ local: { cwd } }): configurable refs, model, severity threshold, JSON or human output, and exit codes (0clean,1findings,2operational error).git, not a repo, unknown ref, diff too large) instead of leaking raw stderr.Test plan
pnpm installandpnpm typecheckfromsdk/code-reviewer— clean.pnpm buildthennode dist/index.js --help— prints usage, exits 0.code-reviewer: <message>and exit 2):--frobnicate)--fail-on bogus--max-diff-bytes -5CURSOR_API_KEY--cwdpointed at a non-git directory--baseset to a non-existent refNotes
pnpm-lock.yamlis committed to match the other examples undersdk/.claude-4.6-sonnet-highandclaude-4.6-opus-max(verified against the regex insdk/app-builder/src/lib/app-builder/server.ts); the README mentions both Claude and the existingcomposer-2/gpt-5.3-codexids so users can swap freely.Note
Low Risk
Adds a new standalone SDK example CLI (plus its lockfile) without modifying existing runtime code paths; primary risk is maintenance/CI noise from the large
pnpm-lock.yamland external model/CLI behavior.Overview
Adds a new
sdk/code-reviewerexample: a Node/TypeScript CLI that runsgit diff base...head, streams the diff to a Cursor SDK agent with a strict JSON-only prompt, defensively extracts/parses the response, validates it against asummary+comments[]schema, and exits non-zero based on a configurable severity threshold for CI gating.Updates the top-level
README.mdto link this new example, and includes the example’s build tooling (package.json,tsconfig.json, workspace config) and pinned dependencies (pnpm-lock.yaml).Reviewed by Cursor Bugbot for commit c583e54. Bugbot is set up for automated code reviews on this repo. Configure here.