---
name: open-code-review
description: >
  Performs AI-powered code review on Git changes using Alibaba Open Code
  Review (`ocr`). Use when the user asks to review current changes, staged or
  unstaged changes, a pull request, a branch comparison, a commit, or to review
  and fix high-confidence issues. Produces line-level review comments and can
  help apply fixes when explicitly requested.
license: Apache-2.0
compatibility: >
  Requires the `ocr` CLI installed with `npm install -g
  @alibaba-group/open-code-review` or a GitHub release binary. OCR must have
  its own LLM provider configured before first use.
metadata:
  author: pi-open-code-review maintainers
  homepage: https://github.com/alibaba/open-code-review
  version: "0.1.5"
---

# BTKS Open Code Review for Pi

Invoke [Open Code Review](https://github.com/alibaba/open-code-review) from Pi. This skill mirrors the Claude Code and Codex integrations: Pi orchestrates the user workflow, while the local `ocr` CLI performs the review with its own configured LLM backend.

## Prerequisites

Before running a review, the `/ocr` command checks the local environment:

```bash
ocr version
ocr llm test
```

If `ocr` is missing, the command attempts to install the official CLI:

```bash
npm install -g @alibaba-group/open-code-review
```

If automatic installation fails, ask the user to run the install command manually. If `ocr llm test` fails, ask the user to configure OCR. Do not invent or hardcode API keys.

## Preferred Pi Commands

Use the package slash command when available. The package intentionally exposes a single slash command, `/ocr`; `review`, `fix`, and `scan` are OCR workflow modes:

```text
/ocr review
/ocr review --from main --to feature-branch
/ocr review --commit abc123
/ocr fix --from main --to feature-branch
/ocr scan --path src
```

The extension command runs OCR with JSON agent output:

```bash
ocr review --format json --audience agent
```

or for scan mode:

```bash
ocr scan --format json --audience agent
```

If the extension command is unavailable, run the OCR command directly with Pi's shell tool.

## Workflow

### Step 1: Gather Business Context

Infer concise requirement or business context from the user's request, branch name, commit message, or nearby project docs. Pass useful context with `--background`:

```bash
ocr review --format json --audience agent --background "Adds rate limiting to login API"
```

### Step 2: Run Review

Choose the command from the user's intent:

| User intent | Command |
| --- | --- |
| Review current workspace changes | `/ocr review` |
| Review a branch against main | `/ocr review --from main --to <branch>` |
| Review a single commit | `/ocr review --commit <sha>` |
| Preview files without LLM calls | `/ocr review --preview` |
| Review and fix safe issues | `/ocr fix [same review flags]` |
| Audit whole files without a diff | `/ocr scan --path <path>` |
| Add business or requirement context | `/ocr review --background "context"` or `/ocr scan --background "context"` |

### Step 3: Classify Findings

Classify OCR comments before presenting them:

- High: security vulnerabilities, obvious bugs, crashes, data loss, concurrency hazards, or precise fixes with strong evidence.
- Medium: plausible correctness, performance, validation, maintainability, or edge-case issues that are worth human attention.
- Low: likely false positives, vague comments, style-only nits, or comments with insufficient evidence.

Display High and Medium findings grouped by priority. Discard Low findings unless the user asks for every OCR comment.

### Step 4: Fix Only When Requested

Only modify files when the user explicitly requested fixing, such as `/ocr fix` or "review and fix high-confidence issues".

When fixing:

- Apply only precise High and Medium findings.
- Leave ambiguous issues as notes.
- Keep edits scoped to the reviewed change.
- Run relevant tests or project checks after edits.
- Do not commit unless the user explicitly asks.

## Output Format

Summarize results like this:

```markdown
## Code Review Results

Files reviewed: N
Issues found: X high priority / Y medium priority

### High Priority

- `path/to/file.ts:42` - Brief issue summary
  Recommendation: concrete fix

### Medium Priority

- `path/to/file.go:88` - Brief issue summary
  Recommendation: concrete fix if available
```

If OCR finds no issues, say:

```text
Review complete - no issues found in N files.
```

## Notes

- OCR reviews untracked files in workspace mode.
- Use `--audience agent`; human progress output is noisy for Pi.
- Prefer `--format json` for machine-readable results.
- Preview commands can return text even when `--format json` is present; the Pi command displays that text directly.
- The `/ocr` command auto-installs the official OCR CLI when `ocr` is missing, matching the Codex plugin flow.
- OCR's LLM backend is independent from Pi's model provider.
- Custom rules are resolved by OCR in this order: `--rule`, project `.opencodereview/rule.json`, user `~/.opencodereview/rule.json`, built-in defaults.
