# BTKS Pi Open Code Review

BTKS Pi package for running [Alibaba Open Code Review](https://github.com/alibaba/open-code-review) from Pi with the same operating model as the Claude Code and Codex integrations.

OCR remains the review engine. Pi provides:

- an `open-code-review` skill for natural language review requests,
- one slash command, `/ocr`, for explicit review, fix, and scan workflows.

## Prerequisites

The `/ocr` command checks for the official OCR CLI before each run. If `ocr` is missing, it attempts to install it with:

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

OCR still needs its own LLM configuration before review can run:

```bash
ocr llm test
```

OCR uses its own LLM configuration. Installing this Pi package does not configure API keys and does not change Pi's model provider.

## Install

From npm:

```bash
pi install npm:pi-open-code-review
```

For local development from this checkout:

```bash
pi install D:\workspace\pi\pi-open-code-review
```

For a single trial run without adding it to settings:

```bash
pi -e D:\workspace\pi\pi-open-code-review
```

## Usage

Slash command:

```text
/ocr 帮我review一下还没提交的这些代码
/ocr 帮我review src/auth 代码，重点看安全问题
/ocr review
/ocr review --from main --to feature-branch
/ocr review --commit abc123
/ocr fix --from main --to feature-branch
/ocr scan --path src
```

`/ocr` is the only package-provided slash command. It supports both natural-language requests and precise OCR subcommands. `review`, `fix`, and `scan` are subcommands that map to OCR workflows rather than separate Pi commands.

Natural-language `/ocr` input is routed back to the Pi agent with the `open-code-review` skill, so the model can decide whether to run a workspace review, full-file scan, commit review, branch comparison, or fix workflow:

```text
/ocr 帮我review一下还没提交的这些代码
/ocr 看一下 src/auth 这块代码有没有安全问题
/ocr review一下这个分支和main相比的改动
```

Precise mode is still available when the text starts with `review`, `fix`, `scan`, or a flag such as `--commit`.

Natural language requests that mirror the Codex plugin:

```text
Use Open Code Review to review my current changes.
Use Open Code Review to review this branch against main.
Use Open Code Review to review and fix high-confidence issues.
```

The extension executes OCR with machine-readable output:

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

For scan mode:

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

## Behavior

- Default review checks staged, unstaged, and untracked workspace changes, matching OCR CLI behavior.
- If `ocr` is missing, `/ocr` attempts to install the official `@alibaba-group/open-code-review` CLI, matching the Codex plugin flow.
- Before review, `/ocr` runs `ocr llm test` and stops with setup guidance if OCR's model provider is not configured.
- `/ocr fix` means review first, then ask Pi to fix precise High and Medium findings.
- `/ocr review --preview` and `/ocr scan --preview` display OCR's text preview output instead of requiring JSON.
- `/ocr review` never edits files unless the user explicitly asks for fixing.
- `/ocr <natural language request>` asks the Pi agent to interpret the request with the `open-code-review` skill instead of parsing it as OCR flags.
- Low-confidence findings are filtered out by the skill rules unless the user asks for all comments.
- The package forwards a conservative allowlist of OCR flags to avoid accidental shell behavior.

## Pi Package Gallery

Pi's package gallery at <https://pi.dev/packages> lists public npm packages tagged with the `pi-package` keyword. This package includes that keyword and this Pi manifest:

```json
"pi": {
  "extensions": ["./extensions/open-code-review.js"],
  "skills": ["./skills"],
  "image": "https://raw.githubusercontent.com/alibaba/open-code-review/main/imgs/highlights-en.png"
}
```

The gallery may lag behind npm's download API. If npm shows downloads but Pi shows `0` or `not available`, treat npm as the source of truth and wait for Pi indexing or report the package from the Pi package page.

## Development

```bash
npm test
npm run test:pi
npm run pack:check
```

The core command-building logic is in `extensions/open-code-review-core.mjs`. The Pi command entrypoint is `extensions/open-code-review.js`.
