@enricai/barnacle

中文文档
1.21.6发布于 2026/11/13MITTypeScriptESM + CJS近 30 天下载 5170

Barnacle turns any website into an API. POST a structured payload to a typed endpoint and Barnacle drives a browser session through the target site, returning a structured result.

原始使用文档
文档目录11 节
  1. How it works
  2. Usage
  3. Prerequisites
  4. Install
  5. Dev
  6. Build for production
  7. Try it
  8. Commands
  9. Writing a plugin
  10. Reference
  11. License

Barnacle

Barnacle turns any website into an API. Point it at a site, describe the user flow, and it generates a plugin backed by direct HTTP calls with automatic browser fallback — no scraping code to maintain by hand.

How it works

Point Barnacle at a site, describe the user flow in plain English, and run three recon commands. Barnacle drives a real browser through the flow, captures every API call, replays them with plain HTTP to prove which ones work without a browser, probes rate-limit ceilings, and generates a complete plugin — Zod schemas inferred from captured JSON, load-bearing headers, rate-limit ceiling, hot-path HTTP client, and Stagehand browser fallback. Register the plugin in one line; Barnacle handles sessions, retries, fallback routing, audit persistence, and response envelope wrapping.

PhaseWhat runsWhat you get
1 — Browser reconpnpm run recon:browserEvery API call the site makes, captured to <run-dir>/graphql/*.json
2–3 — HTTP replay + probingpnpm run recon:httpProof each endpoint works without a browser; rate-limit ceiling; static fixtures
4 — Plugin generationpnpm run recon:generateA complete plugin: Zod schemas, headers, Bottleneck config, hot-path client, Stagehand fallback
5+ — Runtimepnpm startDirect HTTP hot path, automatic browser fallback, nightly smoke test, drift detection

See docs/architecture.md for the design rationale and docs/playbook.md for the full step-by-step guide to adding a new site.

Usage

Prerequisites

  • Node.js 22.19+
  • pnpm 10.4.1
  • A Browserbase account (BROWSERBASE_API_KEY + BROWSERBASE_PROJECT_ID) for managed browser sessions — the default provider. A Steel account (STEEL_API_KEY) is an alternative via SCRAPER_PROVIDER=steel
  • An Anthropic key (ANTHROPIC_API_KEY) for Stagehand's LLM calls, or AWS Bedrock (USE_BEDROCK=true + AWS credentials) — see docs/configuration.md for details

Install

pnpm install
cp .env.example .env   # fill in BROWSERBASE_API_KEY + BROWSERBASE_PROJECT_ID (or STEEL_API_KEY for SCRAPER_PROVIDER=steel) and either ANTHROPIC_API_KEY or Bedrock creds

Generating and hashing an API key, plus the full env-var reference, live in docs/configuration.md.

Dev

pnpm run dev

Build for production

pnpm run build
pnpm start

Try it

With the dev server running, confirm it's up:

curl -s http://localhost:3000/health | jq .

Barnacle boots with the built-in plugins registered (see BUILTIN_SITE_PLUGINS in src/plugins/discover.ts). Each registered plugin exposes POST /v1/<siteId>/run; every response uses the same envelope shape ({ status, ...pluginData }) so clients share a single parser. See docs/plugin-authoring.md#endpoints for the full endpoint reference.

Commands

CommandWhat it does
pnpm run devtsx watch --env-file=.env src/server.ts with hot reload
pnpm run buildcompile to dist/ (tsc + path alias rewriting + copy fixtures)
pnpm startnode dist/server.js
pnpm run typecheckstrict TS noEmit
pnpm run lint / lint:fixBiome
pnpm run testVitest unit + integration
pnpm test src/scraper/fixtures.test.tsRun a single test file (NEVER use -- before the filter)
pnpm run test:watchVitest in watch mode
pnpm run test:coverageVitest with v8 coverage report
pnpm run formatBiome format write
pnpm run recon:browserPhase 1 — drive browser + capture API calls
pnpm run recon:httpPhases 2–3 — replay, introspect, probe rate limits
pnpm run recon:generate -- --site-id <id>Phase 4 — generate complete plugin from artifacts
pnpm run recon:summarize -- --site-id <id>Phase 4 (optional) — write human-readable findings doc
pnpm run recon:heal -- --site-id <id> --url <url>Self-heal a failing recon flow without modifying the source file
pnpm run smoke -- --site <id> --payload '...'Phase 6 — run nightly drift-detection smoke test
pnpm run judge:llm -- --calls-ndjson <path> --call-type <type>Score captured LLM calls on a three-dimensional rubric
pnpm run heal:llm -- --verdict-path <path> --call-type <type>Self-heal a failing prompt template

Writing a plugin

A site plugin is a single TypeScript module that satisfies SitePlugin<TInput, TOutput> from src/site-plugin.ts — a meta block, an optional executeHttp hot path, and a Stagehand execute fallback. pnpm run recon:generate writes this structure for you. Plugins can also be config-only JSON manifests with no TypeScript at all. Full reference in docs/plugin-authoring.md.

Reference

License

MIT © Enricai

Contributions welcome — see CONTRIBUTING.md.

版本与发布记录

@enricai/barnacle 共发布 146 个版本,首次发布于 2026/07/15;过去 12 个月发布了 146 个版本。

版本发布日期距今
1.21.6latest2026/11/131 天前
1.21.52026/11/121 天前
1.21.42026/11/113 天前
1.21.32026/11/085 天前
1.21.22026/11/076 天前
1.21.12026/11/076 天前

关于 @enricai/barnacle 的常见问题

@enricai/barnacle 是什么?

Barnacle turns any website into an API. POST a structured payload to a typed endpoint and Barnacle drives a browser session through the target site, returning a structured result.

如何安装 @enricai/barnacle?

在项目目录运行 npm install @enricai/barnacle,或使用 pnpm add / yarn add / bun add。

@enricai/barnacle 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@enricai/barnacle 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@enricai/barnacle 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.19.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@enricai/barnacle 可以商用吗?

@enricai/barnacle 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@enricai/barnacle 的下载量有多少?

根据 npm 官方下载统计,@enricai/barnacle 在 2026/10/14 – 2026/11/12 这 30 天内被下载 5,170 次,日均约 172 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@enricai/barnacle 还在维护吗?

最新版本 1.21.6 发布于 2026/11/13(1 天前);至今共发布 146 个版本,其中过去 12 个月发布了 146 个;首次发布于 2026/07/15。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。