ESC
开源 10 分钟阅读

Show HN: Farol – 为PR审批者提供的风险地图工具

开发者发布开源工具Farol,为Pull Request审批者提供风险地图。它能根据真实编译器分析代码变更,识别高风险文件和契约破坏,帮助审查者高效审阅代码,提升代码质量与审查效率。

来源:Hacker News

  • Review attention goes where the risk is. A 40-file PR usually has two or three files that can actually hurt. farol ranks them, so the reviewer reads those closely and skims the rest with a clear conscience.
  • It follows the code, not the file names. farol builds a declaration graph with the real compilers (the TypeScript type checker, go/types, Python’s ast). A change to formatPrice lists the twelve pages that render it, not “1 file changed”.
  • Contract breaks are caught before clients are. Removed response fields, new required parameters, changed types in GraphQL, FastAPI, Go handlers and gRPC, with the services that call each endpoint.
  • Review the whole PR, or just what changed since your last look. Every push gets two reports: the full pull request, and only the commits since the previous push. After a round of fixes, the reviewer checks the new commits instead of starting over.
  • It uses what your CI already has. Coverage, lint, security and audit reports become diff coverage and findings on the changed lines. Nothing runs twice.
  • Fail closed. When farol cannot read part of a change, it says so (unknown) and asks for a careful review. It never calls something safe because it did not understand it.
  • Built for the human in the loop. Mark files as reviewed, mark pages as behind a feature flag, check off findings, and paste the result back in the PR as a record of what was reviewed.

Contents

Get started

You need Node.js 22+ and git (plus go for Go projects, python3 3.11+ for Python ones). Nothing to install: run farol with npx @winninjs/farol.

1. Describe your project in a farol.config.json at its root. One line is enough to start; pick your stack:

2. Check what farol sees: the pages, endpoints, jobs and scripts it found.

npx @winninjs/farol routes

3. Analyze a branch against its target and open the report.

npx @winninjs/farol analyze –base origin/main –head HEAD –out farol.json npx @winninjs/farol html –in farol.json –out farol.html && open farol.html # xdg-open on Linux

Example: a React app with React Router

cd path/to/your/react-app
echo '{ "routes": { "file": "src/routes.tsx" } }' > farol.config.json

npx @winninjs/farol routes # lists your pages: "/", "/products", "/settings"…
git checkout my-feature-branch
npx @winninjs/farol analyze --base origin/main --head HEAD --out farol.json
npx @winninjs/farol html --in farol.json --out farol.html && open farol.html

The report already shows the verdict, the score, the files to start with, the pages the change reaches and what to test by hand. Next steps: add your coverage, lint and audit reports and run farol on every PR with the recipe for your stack. Every option is in the reference and, per stack, in examples/README.md.

Running it often? npm install --global @winninjs/farol gives you a plain farol command.

Each recipe has three parts: the farol.config.json to commit, the reports to produce, and the GitHub Actions workflow. The workflows in examples/ are complete and share one shape:

Pin the action to a commit once it works for you: winnin/farol/action@<sha> # main as of <date>.

examples/README.md goes deeper for each stack: every configuration key, CLI parameter and action input, and how to check a setup.

React Router route tables (object and JSX forms, lazy routes, split route modules), reach per declaration.

{ “routes”: { “file”: “src/routes.tsx” }, “roles”: { “global”: [“src/main.tsx”, “src/App.tsx”, “src/styles/global.css”, “package.json”, “vite.config.ts”] } }

npx vitest run --coverage.enabled --coverage.reporter=json --coverage.reportsDirectory=reports/coverage
npx eslint -f json -o reports/eslint.json <changed files>
npm audit --json > reports/audit.json # or pnpm audit --json

npx @winninjs/farol analyze --base origin/main --head HEAD \
 --coverage reports/coverage/coverage-final.json --eslint reports/eslint.json --audit reports/audit.json --out farol.json

CI: copy examples/workflow.yml to .github/workflows/farol.yml.

Set coverage.include: ['src/**/*.{ts,tsx}'] in the Vitest config so files no test loads are reported as untested. Split route trees go in routes.extraFiles; a fuller config is in examples/farol.config.json.

Pages Router and App Router: every page, API route, layout, _app/_document and middleware, read from the file names. Dynamic segments ([id]), catch-alls, route groups and parallel slots are understood.

{ “routes”: { “adapter”: “next” }, “roles”: { “global”: [“next.config.*”, “package.json”] } }

pages/ and app/ are found in the project or in its src/; set "dir" when they live elsewhere. Reports and CI are the same as for React Router (Jest or Vitest coverage, ESLint, audit). In a monorepo whose tsconfig extends a workspace package ("extends": "tsconfig/nextjs.json"), install dependencies before analyzing, so the package is in node_modules.

File-based routing: every module calling createFileRoute('<id>') under the routes directory, with the root route, pathless layouts (_app) and parent routes as layouts of their children.

{ “routes”: { “adapter”: “tanstack-router”, “dir”: “src/routes” } }

Reports and CI are the same as for React Router.

GraphQL root operations (schema files and gql templates, per resolver) and Fastify/Express-style REST endpoints.

{ “surface”: “backend”, “backend”: { “graphql”: true, “rest”: true }, “roles”: { “global”: [“package.json”, “src/app.ts”] } }

Reports and CI are the same as for React Router: examples/workflow.yml. If resolvers reach data through an injected context (ctx.loaders.Brand.byId()), tell farol where the providers live: "backend": { "context": { "loaders": ["src/modules/*/loaders/index.ts"] } }.

chi, gin, echo and net/http routes, gRPC service methods and main binaries, reach per declaration with interface calls resolved to their implementations.

{ “language”: “go”, “surface”: “backend” }

go test -coverpkg=./... -coverprofile=reports/cover.out ./...
golangci-lint run --output.json.path=reports/golangci.json --issues-exit-code=0 ./... # enable gosec
govulncheck -json ./... > reports/govulncheck.json

npx @winninjs/farol analyze --base origin/main --head HEAD \
 --coverage reports/cover.out --eslint reports/golangci.json --audit reports/govulncheck.json --out farol.json

CI: copy examples/workflow-go.yml. farol reads modules offline, so the workflow runs go mod download for the base and the head first.

FastAPI and Flask routes (routers, blueprints, prefixes), Django URLs, MCP tools/resources/prompts, Celery tasks, Temporal workflows and activities, Prefect flows and __main__ scripts. farol parses your code; it never imports it.

{ “language”: “python”, “surface”: “backend”, “python”: { “roots”: [“src”, “.”] } }

pytest --cov=src --cov-report=json:reports/coverage.json
ruff check --output-format json --extend-select S --exit-zero . > reports/ruff.json # S = flake8-bandit
pip-audit --format json -o reports/pip-audit.json

npx @winninjs/farol analyze --base origin/main --head HEAD \
 --coverage reports/coverage.json --eslint reports/ruff.json --audit reports/pip-audit.json --out farol.json

CI: copy examples/workflow-python.yml (uses uv; swap in your installer).

Optional, and information only: it never changes the score. With it the report shows how much traffic each affected page or operation gets, its distinct production errors (linked to Datadog), the changed files that already throw errors, and the services that call each changed endpoint.

{ “datadog”: { “env”: “prod”, “rum”: { “applicationId”: “” }, “apm”: { “service”: “orders-api”, “operations”: [“fastapi.request”] } } }

DD_API_KEY=… DD_APP_KEY=… npx @winninjs/farol usage --out usage.json # last 14 days
npx @winninjs/farol analyze … --usage usage.json

CI: the example workflows have a farol-usage job: set the DD_API_KEY and DD_APP_KEY secrets and the repository variable FAROL_DATADOG=true. It reads Datadog once a day and never sees the PR’s code. Keys, scopes and matching rules are in the reference.

TypeScript / React frontends TypeScript / JavaScript backends Go Python

Entry points React Router route tables (object and JSX forms, lazy routes, split route modules); Next.js Pages and App Router (pages, API routes, layouts, middleware); TanStack Router file-based routes GraphQL root operations (schema files and gql templates) and REST endpoints (Fastify/Express style) chi, gin, echo and net/http routes; gRPC service methods; main binaries FastAPI and Flask routes (routers, blueprints, prefixes); Django URLs; MCP tools, resources and prompts; Celery tasks; Temporal workflows and activities; Prefect flows; __main__ scripts

Reach precision per declaration (TypeScript type checker) per module, per resolver for GraphQL per declaration (go/types, interface calls resolved to implementations) per declaration (Python ast with local type inference)

Contract changes — GraphQL schema (breaking / dangerous / safe) Handler request and response types (net/http, chi, gin, echo); gRPC messages FastAPI parameters, body, response and Pydantic models

Dependencies package.json + npm/pnpm/yarn/bun lockfiles same go.mod + go.sum pyproject.toml (PEP 621, extras, groups, uv, Poetry), requirements.txt + uv.lock/poetry.lock/Pipfile.lock

Diff coverage Istanbul coverage-final.json (Vitest, Jest) same go test -coverprofile coverage.py JSON (pytest --cov)

Lint eslint -f json same golangci-lint JSON ruff JSON

Security built-in rules (XSS sinks, eval, hard-coded secrets, javascript: URLs…) same gosec (through golangci-lint) flake8-bandit (ruff S rules)

Vulnerabilities npm audit --json, pnpm audit --json same govulncheck -json pip-audit --format json

Suppressions eslint-disable, @ts-ignore, @ts-expect-error, as any… same //nolint, //lint:ignore, #nosec # noqa, # type: ignore, # nosec, # pragma: no cover…

Traffic and errors (optional) Datadog RUM page views and errors Datadog APM requests, error spans and callers same same

In every language: environment, infrastructure and CI files (.env*, Dockerfiles, compose, CI pipelines, helm, k8s, terraform…) in a section of their own; incremental analysis since any commit (--since); suggested reviewers from git blame and CODEOWNERS; reports as a GitHub comment, Markdown or a single-file HTML page.

farol produces two things: a PR comment with the verdict, the top files and a test checklist, and a single-file HTML report (linked from the comment) where the review happens. Here is what each part is for and how to use it.

What it tells you is how much of your time the PR deserves.

The score (0–100) is the chance that at least one risky item breaks something. Expand What adds to it to see each item and its points: the files by reach × untested share, findings, contract changes, dependencies. The verdict always comes with its reasons; read them before the diff.

The changed code files, riskiest first. Each row shows how many existing pages or operations run the file, its diff coverage, its findings and its own risk points; with Datadog, also its traffic and production errors. Open the inline diff: added lines no test runs are marked ○, lines with findings ⚠.

How to use it: review top-down and tick Mark as reviewed on each file. The score drops as you go, so you always know how much risk is left. Below it come the low-risk files to skim, environment/infrastructure/CI files (check their values per environment), and files that need no review (docs, lockfiles, tests).

On every page or operation row, and in a panel at the top: mark an entry point that is entirely behind a flag. Files that only flagged entry points use leave the review, labeled behind a flag rather than reviewed. Use it for work-in-progress features shipped dark, so the remaining score reflects what users will actually hit.

Every new and affected entry point, as a list or a tree by module. Opening one draws how the change reaches it, file by file. With Datadog each one shows its traffic share and its distinct errors, busiest first. Use it to judge blast radius: a change reaching 3 rarely used admin pages is not the same as one reaching the checkout.

Each endpoint whose request or response shape changed, as breaking (clients built for the base can fail), dangerous (they may misbehave) or safe (compatible additions), with the exact field and the calling services from Datadog. Use it to confirm every breaking change is intended and its clients are checked with clients.

The evidence behind the score: security findings on the changed lines (with a checked box each), added or bumped dependencies with known vulnerabilities, and diff coverage per file. A report that was not given shows as not verified, never as passing.

The new and affected pages or operations to try by hand, new ones first, then by the risk of the file that reaches them. The PR comment has it as a task list. Use it when you run the branch locally or on a preview environment. It follows your review: once every changed file behind an item is marked as reviewed, the item is marked too (✓ files reviewed), or 🚩 behind a flag. Its own checkbox, for the manual test, stays yours to tick.

Who should review: the people who wrote the code this PR changes (git blame, weighted by each file’s risk), plus CODEOWNERS. The PR’s own authors and bots are left out, and inactive people are labeled. Use it to request the person who knows the riskiest file, not just whoever is free.

A Markdown record of the review: the initial verdict and score, the score left now, the flagged entry points, the reviewed files, and the checked findings and contract changes. Copy as Markdown and paste it in the PR as your review comment, so the next person knows what was looked at.