omp packages

@theakshits/pi-open-codereview0.2.0

Open Code Review (ocr) for pi: review, scan, delegate, fix, loop, config, rules, viewer and PR workflows

GitHub Actions Published 3 days ago MIT ~0 downloads/mo

Untested on omp

This is a pi package. No one has reported whether it works on omp yet. If you try it, add your result below.

Did it work for you?

Result

One report per person. A new report replaces your old one.

Reports 0

No reports yet.

Readme

pi-open-codereview

pi-open-codereview icon

CI license: MIT node >= 22.19 npm: not published yet

Open Code Review (ocr) inside pi: a separately configured reviewer for your diff, whole-file scans, safe auto-fixes, a fix-and-re-review loop, in-pi config/rule inspection, the session viewer, and GitHub PR / GitLab MR review — locally, without adopting a PR-time review bot.

  • A real second reviewer, when you want one. ocr_review uses the provider and model configured in ocr, which can differ from the model that wrote the change. ocr_delegate is the opposite trade-off: ocr's deterministic pipeline (file discovery, diff/range resolution, rule resolution) with the active pi model doing the reviewing, no second API key. Only the first is independent.
  • No shell strings. Every ocr/git/gh/glab/npm call receives a structured argument array; refs, paths and enum flags are validated before use.
  • No truncated results. Reviews are captured through --output <file> and parsed as JSON; the chat gets a concise, severity-ranked summary.
  • No surprises. Installing the ocr binary requires an explicit confirmation; PR comments need an explicit confirmation; the extension never rewrites ~/.opencodereview/config.json on its own.

Requirements

Tool Version Notes
node >= 22.19.0 pi's minimum; .node-version pins 26.13.1
ocr >= 1.14 npm i -g @alibaba-group/open-code-review
LLM access one provider ocr auth login, or a provider API key in ocr
git >= 2.41 checked on every workflow that reads history
gh / glab optional only for /ocr-pr

OCR_BIN overrides the binary name/path (default ocr). OCR_DEBUG=1 writes one structured JSON diagnostic line per external call to stderr. ocr itself is documented at https://open-codereview.ai/.

Install

# works today — from GitHub
pi install git:github.com/TheAkshitS/pi-open-codereview

# works today — from a local checkout
pi install ./pi-open-codereview

# only after the first npm publish — not on the registry yet
pi install npm:@theakshits/pi-open-codereview

# quick, no-install trial
pi -e ./pi-open-codereview/src/index.ts

The package is not on the npm registry yet: npm view @theakshits/pi-open-codereview version returns 404. Use the git or local install above; the npm line starts working once the first release is published by hand (see docs/development.md).

pi reads the pi.extensions / pi.skills manifest in package.json; the bundled skill is available as /skill:open-codereview.

Quickstart

You need pi and the ocr binary. The extension offers to install ocr on first use (npm i -g @alibaba-group/open-code-review); it never installs without asking. Run the first two lines in a terminal, the rest inside pi:

pi install git:github.com/TheAkshitS/pi-open-codereview   # terminal
ocr auth login                                            # terminal; or set a provider key
/ocr-config test                                          # in pi: confirm the provider works
/ocr-review --preview                                     # in pi: free, file list only
/ocr-review                                               # in pi: the actual review

A provider key set outside ocr auth login works too, for example /ocr-config set providers.anthropic.api_key "$ANTHROPIC_API_KEY".

Demo

No recording is checked in yet. A short capture — install, then the two review commands — is coming; until then the quickstart above is the tour.

What it costs

  • --preview (or preview: true) makes no LLM call and costs nothing.
  • ocr_review, ocr_scan, ocr_loop and /ocr-pr call the provider configured in ocr; that provider bills you at its own rates.
  • ocr_delegate calls no OCR provider. The review runs on the active pi model and is billed wherever that model is billed.
  • Budget flags (--timeout, --max-tokens, --max-tokens-budget, --max-tools) are forwarded to ocr; once forwarded, ocr enforces them.
  • Fixes are local edits, but each review round in /ocr-loop is another provider call. Posting an existing review as PR comments adds no LLM call.

Privacy

  • This extension adds no telemetry, analytics or phone-home of its own.
  • Source code and diffs leave the machine only where a run sends them: to the provider configured in ocr for ocr_* LLM runs, or to the active pi model for delegate. --preview sends no code to a model.
  • --output <file> writes review data, including code snippets, to that path; treat the file like the diff it came from.
  • /ocr-pr --post sends the formatted review to GitHub or GitLab, and only after the confirmation dialog.
  • Provider settings and credentials are owned by ocr (config at ~/.opencodereview/config.json); /ocr-config redacts secrets unless --reveal is passed.

Why not X?

Alternative What it is How this differs
CodeRabbit / Greptile / Qodo PR-time review SaaS Reviews workspace changes, a range or one commit before you push, with your own provider; PR posting is optional.
Cursor Bugbot PR review inside Cursor Runs inside pi with any model pi supports; no Cursor subscription required.
Asking the same agent to re-read Manual same-model review ocr_review can use a separately configured model; delegate is an explicit same-model sanity check, not a second opinion.
ocr CLI alone Terminal-first, no pi integration Adds pi tools and slash commands, the findings navigator, conservative fix/loop, and confirmed PR posting.

Review independence

Path Reviewer Independent?
ocr_review / ocr_scan provider and model configured in ocr Yes, when it differs from the model that wrote the change.
ocr_delegate the active pi model No. Same-model sanity check: useful before hand-off, not independent.

/ocr-pr reuses the ocr_review path, so it inherits the first row.

Commands

Command What it does
/ocr … Unified router: explicit subcommands or natural language.
/ocr-review Review workspace changes, a ref range or one commit.
/ocr-review-delegate ocr discovers files/rules/diff; pi's model reviews.
/ocr-scan Scan whole files (no diff needed).
/ocr-fix Apply high-confidence fixes in the workspace.
/ocr-loop Fix → re-review → verify, up to 5 rounds.
/ocr-config Show/set/unset ocr config and run ocr llm test.
/ocr-rules Show effective rules or scaffold .opencodereview/rule.json.
/ocr-viewer Start ocr viewer (reusing a running one) and return its URL.
/ocr-pr Review a PR/MR, optionally post line-level comments.
/ocr-setup Read-only doctor: binary, git, auth, config, rules.
/ocr-auth Auth status, provider/model lists; prints the login command.
/ocr-sessions List saved sessions and resume one.

/ocr routing

/ocr review focusing on auth bypass and race conditions
/ocr scan the whole repo for hardcoded secrets
/ocr fix the high severity findings on this branch
/ocr loop until clean
/ocr config show
/ocr rules check src/auth/session.ts
/ocr pr 1234
/ocr setup
/ocr auth status
/ocr sessions

An explicit subcommand (review, scan, fix, loop, config, rules, viewer, pr, delegate, setup, auth, sessions) is used verbatim; otherwise the request is routed by keywords and free text becomes --background context. /ocr <anything else> is treated as a review — except when the first positional looks like a file path without --from/--to/--commit (e.g. /ocr src/auth.ts), which hints /ocr-scan --path <path> instead.

flowchart TD
  cmd["/ocr* slash command"] -->|text| infer["args.ts inferSubcommand<br/>explicit subcommand wins, else keywords"]
  infer --> parse["args.ts parseFlags<br/>typed flags, never a shell string"]
  tool["ocr_* tool call"] -->|typed params| action
  parse --> action["actions.ts<br/>one action per command"]
  action --> mode["modes.ts<br/>review · scan · delegate · fix · loop"]
  mode --> cli["cli.ts<br/>argv array"]
  cli --> bin[("ocr binary")]
  mode --> ui["ui.ts<br/>summary, navigator, fix report"]
  ui --> turn["pi turn<br/>content + details"]

Review examples

/ocr-review                                   # staged + unstaged + untracked
/ocr-review --from main                       # branch vs main (merge-base)
/ocr-review --from origin/main --to HEAD --effort high
/ocr-review -c HEAD~1 --analysis              # one commit + impact analysis
/ocr-review -b "billing rewrite: no schema changes allowed"
/ocr-review --preview                         # file list only, no LLM call
/ocr-review --confidence all                  # include medium/low
/ocr-review --resume 8a2e2b5d-f1e0-479e-8ea6-b7f531107281
/ocr-review --output .ocr/review.json         # keep the full JSON

Scan examples

/ocr-scan
/ocr-scan --path src/auth,src/db
/ocr-scan --exclude '**/generated/*,**/testdata/*'
/ocr-scan --preview

ocr scan in 1.14.x has no --effort or ref flags; the command exposes the flags the binary actually supports.

Delegate example

/ocr-review-delegate --from main

Runs only deterministic ocr commands:

  1. ocr delegate preview --format json → reviewable files + mode/repository.
  2. ocr delegate rule --format json -- <paths…> → resolved rules (chunked).
  3. git show/git diff/untracked content → a bounded diff (200 KB cap).

The result is a review packet written for the active model: file list, resolved rules, diff, and instructions. No OCR LLM call, no API key.

Fix and loop

/ocr-fix                                  # high-confidence fixes
/ocr-fix --include-low-confidence         # everything ocr proposed
/ocr-fix --dry-run                        # show the plan, write nothing
/ocr-fix --path src/auth --scan           # fix from a full-file scan
/ocr-loop --max-rounds 4
/ocr-loop --path src --mode scan

A fix is applied only when the finding has both existing_code and suggestion_code, the block matches exactly once (or unambiguously near the reported line), and the path stays inside the workspace. Everything else is reported as skipped with a reason—never guessed.

The loop fingerprints findings by path + category + normalised content, so line shifts do not look like new issues. Each round reports findings, fixes applied, resolved and newly introduced findings. After the last applied batch it runs a verification review and reports verified clean or the regressions.

flowchart TD
  start(["round 1 to maxRounds<br/>default 3, hard cap 5"]) --> review["review or scan"]
  review --> diff["diffFindings against the previous round<br/>fingerprint: path + category + normalised content"]
  diff --> fix["applyFixes<br/>high confidence, or all with includeLowConfidence"]
  fix --> decision{"loopDecision"}
  decision -->|nothing left| clean["stopped: clean"]
  decision -->|nothing fixable| unfixable["stopped: no fixable findings"]
  decision -->|round = maxRounds| capped["stopped: max rounds reached"]
  decision -->|otherwise| start
  clean --> verify{"did the last round apply a fix?"}
  unfixable --> verify
  capped --> verify
  verify -->|yes| check["verification review"]
  check --> verdict["verified clean, remaining, or newly introduced"]
  verify -->|no| report["per-round report"]

Config

/ocr-config                      # redacted view of ~/.opencodereview/config.json
/ocr-config --reveal             # show secrets
/ocr-config test                 # ocr llm test
/ocr-config set provider anthropic
/ocr-config set model claude-opus-4-6
/ocr-config set providers.anthropic.api_key "$ANTHROPIC_API_KEY"
/ocr-config unset providers.anthropic.url

Writes go through ocr config set|unset, so ocr stays the owner of its config format. show is read-only and redacts api_key/token/secret/auth_header.

Rules

/ocr-rules check src/auth/session.ts src/db/client.ts
/ocr-rules scaffold                       # ./.opencodereview/rule.json
/ocr-rules scaffold --scope global        # ~/.opencodereview/rule.json
/ocr-rules scaffold --overwrite

Precedence: --rule → ./.opencodereview/rule.json → ~/.opencodereview/rule.json → built-in system rules.

Viewer

/ocr-viewer
/ocr-viewer --addr localhost:3000
/ocr-viewer --open always
/ocr-viewer --stop

ocr viewer is a long-running server, so it is spawned detached (the one place we do not use pi.exec). It has no idle timeout of its own, so the launch is tracked: a second /ocr-viewer for the same address returns the viewer that is already running instead of leaking another one, --stop ends it, and quitting pi stops the viewers this session started. --stop signals a pid only while it still looks like ocr viewer, so a recycled pid is left alone. The command returns the URL, PID and log path; there is one log per address, overwritten on each start.

PR / MR

/ocr-pr 1234
/ocr-pr https://github.com/org/repo/pull/1234
/ocr-pr 1234 --post
  1. Detects gh then glab.
  2. Resolves the PR/MR title, body, base and head refs.
  3. Fetches the head into refs/ocr/<tool>-<number>.
  4. Runs ocr with --from <remote>/<base> --to refs/ocr/… (matching the PR's remote slug, e.g. upstream on a fork, falling back to origin or bare <base>) and the PR title/body as --background.
  5. Formats findings as line-anchored comments.
  6. With --post, shows a confirmation dialog; only then posts.

For GitHub, posting uses gh api …/pulls/<n>/reviews with inline comments. For GitLab, posting uses glab mr note with the formatted review body (see Limitations).

Tools

Tool Purpose
ocr_review Review workspace / range / commit; preview for a dry run.
ocr_delegate Deterministic context + review packet for pi's model.
ocr_scan Whole-file scan with path scoping.
ocr_fix Plan proposed replacements; pass apply: true to write.
ocr_loop Fix-and-re-review; requires apply: true (it writes).
ocr_viewer Start or stop the WebUI and return the URL.
ocr_config Inspect/change config, test connectivity.
ocr_rules Effective rules / scaffold a rule file.
ocr_pr PR/MR review and confirmed posting.

All tools return { content, details, isError }; details carries structured findings, command arrays, session ids and output paths for follow-up turns.

A model-initiated fix never writes on its own: ocr_fix returns a plan unless called with apply: true, and ocr_loop refuses to run without it. With a UI, the tool also asks for confirmation before writing. Slash commands keep their explicit behavior (/ocr-fix writes, --dry-run plans).

Machine-readable output and CI

/ocr-review and /ocr-scan accept --sarif out.sarif (SARIF 2.1.0 for GitHub code scanning and the VS Code SARIF viewer) and --save-md out.md (the same severity-ranked report shown in chat). The tools expose the same options as sarif / saveMd. A failed export warns and keeps the review.

The extension itself is a pi surface, so CI reads ocr directly. The short version:

- run: npm i -g @alibaba-group/open-code-review
- run: ocr review --from origin/main --format sarif --output review.sarif
- uses: github/codeql-action/upload-sarif@v3
  with:
    sarif_file: review.sarif

ocr exits non-zero on operational failure, not on findings. Gate on severity with a small script that parses the JSON and exits 1; no GitHub App or hosted service is involved.

Interactive findings navigator

Commands accept --interactive (tools accept interactive: true). It opens a pi TUI selector grouped by severity/file/line:

  • inspect a finding (severity, category, reasoning, current/suggested code)
  • show the surrounding code with line numbers
  • pre-fill the editor with path:line
  • fix that finding, or all fixable findings, after a confirmation

Flag reference

Review and fix/loop scope:

Flag Meaning
--from, --to Ref range; ocr uses the merge-base.
-c, --commit Single commit vs its parent. Cannot combine with from/to.
-b, --background Business/requirement context.
-B, --background-file Context from a file.
--repo Repository root.
--concurrency Parallel subtasks, 1–64.
--max-git-procs Concurrent git subprocesses, 1–256.
--timeout ocr run budget in minutes.
--effort low|medium|high Review depth (review, loop, fix in review mode, PR).
--model, --provider Per-run override.
--exclude Comma-separated gitignore-style excludes.
--resume <id> Resume an interrupted session.
--rule <file> Rule file (highest precedence).
-o, --output <file> Keep the full JSON result.
--confidence high|all Finding filter; default high.
--all Same as --confidence all.
--interactive, --no-interactive Open (or suppress) the findings navigator.
--analysis Behaviour/impact/maintainer analysis (review).
-p, --preview File list only; no LLM call.
--max-tokens, --max-tokens-budget, --max-tools Budgets.
--no-filter Disable ocr's file filtering (review).
--progress off|phases|detail Live progress; detail adds tools. Default phases.
-h, --help Print command usage.

Scan adds --path, --batch none|by-language|by-directory, --no-plan, --no-dedup, --no-summary. Fix adds --path, --scan, --dry-run, --include-low-confidence. Loop adds --max-rounds (1–5, default 3), --no-stop-on-clean, --mode review|scan, --path, --scan, --include-low-confidence. Review and scan also accept --sarif <file> and --save-md <file>.

Behaviour guarantees

  • Non-zero exits, timeouts and signals become readable errors; a truncated run says so and shows the session id (--resume).
  • Missing ocr produces an install hint; commands ask before installing.
  • git < 2.41 is refused with the detected version.
  • JSON is always written via --output to a temp file, then read; a missing file falls back to stdout. A file the run did not touch is treated as stale, and your existing --output file is never deleted up front.
  • Requests use a structured argv array; refs, paths and enum flags are validated.
  • ocr outside the supported >=1.14 <2 range is refused with the detected version instead of failing deep inside a run.
  • Fixes resolve the parent directory with realpath and refuse a path that escapes through a symlink; writes use a random O_EXCL temp file, keep the original mode, apply bottom-up, and report per-file failures instead of discarding the batch.
  • Findings without a machine-applicable suggestion are never auto-fixed.
  • Config secrets are redacted unless --reveal is passed.
  • PR comments are never posted without a confirmation dialog; if GitHub rejects the inline comments, the review is retried once as a body-only comment.

Development

Dependencies are installed with pnpm; Vite+ (vp) formats, lints, typechecks and tests.

pnpm install            # install dependencies
vp run typecheck        # tsc --noEmit
vp check                # oxfmt + oxlint
vp check --fix          # auto-fix formatting and lint
vp test                 # Vitest; offline by default (fake ocr)
pnpm run test:pack      # pack tarball, verify shipped files, load in pi
vp run check            # typecheck, format, lint and test — the gate

Tests run offline by default using the committed process-boundary fakes (tests/fake-ocr.js, tests/fake-gh.js), needing no installed ocr or network. Run live binary suites with OCR_LIVE=1 vp test tests/integration.test.ts tests/tool.test.ts; LLM-dependent live checks skip themselves when ocr llm test fails (for example an expired local key).

See docs/toolchain.md, docs/development.md, docs/testing.md (full test suite index), and docs/invariants.md.

Limitations

  • ocr 1.14.x does not accept --effort on scan; the flag is rejected rather than silently ignored.
  • GitLab posting is a single MR note with line references; inline discussion positions via the GitLab API are not implemented.
  • ocr viewer is detached; in a sandbox without localhost access the URL is still returned and the log path is shown.
  • Session id recovery relies on ocr's printed --resume <uuid> hint, its JSON session_id / sessionId field, or a session: <uuid> line in the output.
  • The interactive navigator uses pi's built-in dialogs and widget APIs, not a custom pi-tui component; "jump to line" pre-fills the editor with path:line because pi has no direct file/line navigation API.