Analyze Changes
Perform a three-level code review analysis and return curated suggestions.
Tools
This skill includes a scripts/git-diff-lines script that annotates git diff output with explicit OLD and NEW line numbers. Each subagent should invoke it by name (git-diff-lines) — the orchestrating agent must ensure the script's directory is on PATH (e.g., via PATH="<skill-dir>/scripts:$PATH").
1. Gather context
Determine what's being reviewed:
- Local changes:
git diff --name-only HEADfor changed files. - PR changes: Determine the merge base (
git merge-base main HEAD), then diff against it. Get PR title and description if available. - If the user specifies a different diff range, use that.
Collect:
- The list of changed files
- PR metadata (title, description, author) if applicable
- Whether this is local or PR mode
- Any custom review instructions the user provided
2. Get analysis prompts
Obtain the prompt instructions for each analysis level. Use the tier argument (default: balanced).
If get_analysis_prompt is in your available tools (i.e., the pair-review MCP server is connected):
- Call
get_analysis_promptfor each level you will run:level1,level2, and (unlessskipLevel3is true)level3 - Call
get_analysis_promptwithpromptType: "orchestration"for the orchestration step - Pass the user's
tierargument to each call - Pass any custom review instructions (from the
customInstructionsargument, or gathered from user context in Step 1) as thecustomInstructionsparameter — this injects them into the rendered prompt - These return the full prompt text to use as Task agent instructions
Otherwise (standalone mode — no MCP connection):
- Read the static reference files from this skill's
references/directory:references/level1-{tier}.mdreferences/level2-{tier}.mdreferences/level3-{tier}.md(unlessskipLevel3)references/orchestration-{tier}.md
3. Run analysis levels in parallel
Launch two or three Task agents simultaneously (subagent_type: "general-purpose"), depending on skipLevel3. Each task must:
- Use the prompt obtained in Step 2 as its core instructions
- Use the
git-diff-linesscript to get the annotated diff - Analyze the changes per its framework
- Return valid JSON (no markdown wrapping) with the schema defined in the prompt
Pass each task the following context in its prompt:
- The analysis prompt from Step 2
- Review type (local or PR)
- The list of changed files
- PR title and description (if PR mode)
- Instructions to invoke
git-diff-lines(ensure the script's directory is onPATH)
Level 1 — Analyze changes in isolation (diff only)
Level 2 — Analyze changes in file context (full files)
Level 3 — Analyze changes in codebase context (architecture, dependencies) — skip if skipLevel3 is true
4. Orchestrate results
Launch one more Task agent (subagent_type: "general-purpose") that:
- Uses the orchestration prompt from Step 2 as its core instructions
- Receives the JSON output from all completed levels (pass empty
[]for Level 3 if skipped) - Merges, deduplicates, and curates suggestions
- Returns final curated JSON
5. Push results to server
Push the orchestrated JSON to the pair-review web UI so suggestions appear inline. This step does not require MCP — it uses a direct HTTP POST with a fallback to http://localhost:7247 when the MCP get_server_info tool is unavailable.
-
Determine server URL:
- If the
get_server_infoMCP tool is available, call it and use theurlfield - Otherwise, try reading the port from config:
cat ~/.pair-review/config.json 2>/dev/null | jq -r '.port // empty' - If neither works, default to
http://localhost:7247
- If the
-
Build the POST body from the orchestrated output:
- For local mode: set
path(absolute working directory frompwd) andheadSha(fromgit rev-parse HEAD) - For PR mode: set
repo(owner/repo) andprNumber - Include
provider,model,summary,suggestions, andfileLevelSuggestionsfrom the orchestrated JSON
- For local mode: set
-
POST via
curlto${SERVER_URL}/api/analysis-results:curl -s --connect-timeout 3 --max-time 10 \ -X POST "${SERVER_URL}/api/analysis-results" \ -H "Content-Type: application/json" \ -d @- <<'PAYLOAD' { ... } PAYLOADA successful import returns HTTP 201 with
{ runId, reviewId, totalSuggestions, status: "completed" }. -
Graceful degradation: If the request fails (server not running, timeout, etc.), log a short warning and continue to the Report step. The push is best-effort.
-
Note in the report whether results were successfully pushed to the pair-review UI.
6. Report
Present the curated suggestions to the user, organized by file. For each suggestion:
- File and line reference
- Type (bug, improvement, security, etc.)
- Title and description
- Suggested fix (if applicable)
- Confidence level
