@braintrust/pi-extension

中文文档
2.2.2发布于 2026/10/29MITTypeScriptES Module零依赖构建来源已验证近 30 天下载 3.4万

Braintrust extension for pi. Includes automatic tracing for pi sessions, turns, LLM calls, and tool executions to Braintrust.

原始使用文档
文档目录7 节
  1. What gets traced
  2. Quickstart
  3. Compatibility
  4. Configuration
  5. Settings
  6. Manage tracing
  7. Local development

@braintrust/pi-extension

npm version

Trace Pi sessions in Braintrust. The extension sends events to the local bt daemon, which builds and uploads traces. Pi keeps running if tracing fails.

What gets traced

  • Session spans: one root span per Pi session with at least one turn
  • Turn spans: one span per user prompt / agent run
  • LLM spans: one span per model response inside a turn, with token usage, cache usage, reasoning tokens, estimated cost, time to first token, and the tool definitions available to that request. With a virtual model, the span names the physical model and thinking level that answered and records the selected virtual model as selected_model
  • Tool spans: one span per tool execution, including dynamically loaded tools. Tool calls that another tool makes, such as a codemode script's tools.<name>() calls, are nested under the calling tool's span
  • Compaction spans: one span per session compaction, including trigger/retry metadata when available
  • Branch summary spans: one span per summarized /tree navigation branch

Trace shape:

Session (task)
├── Turn 1 (task)
│   ├── anthropic/claude-sonnet-4 (llm)
│   │   ├── read: package.json (tool)
│   │   └── bash: pnpm test (tool)
│   └── anthropic/claude-sonnet-4 (llm)
├── Compaction (task)
├── Branch Summary (task)
└── Turn 2 (task)

Quickstart

Install Pi and the Braintrust CLI, then run:

bt login
bt trace enable pi --project my-coding-agent
pi

This installs the extension and saves its configuration. Use --profile or --org to choose a profile or organization. Restart Pi if it is already open. The footer shows tracing status and a link to the trace when available.

To install the npm extension separately, use pi install npm:@braintrust/pi-extension, then configure tracing with bt trace enable pi.

For one invocation without changing global tracing configuration:

bt trace run --project my-coding-agent pi -- -p "summarize this repository"

The bt trace run routing and metadata flags also accept their matching BRAINTRUST_* environment variables; a plain pi session's extension does not. Historical import and live attach are not supported for Pi. Upgrading an active session from the pre-daemon extension is supported: when its local legacy state file is still present, the daemon continues the existing Braintrust root and turn sequence. If that state was removed or is invalid, tracing safely starts a new daemon session instead.

Compatibility

CI runs a traced Pi session with the packed extension against the latest patch from each of the last five stable Pi release lines. The compatibility job resolves these versions on each run, including releases from Pi's former npm package name when needed.

Package detection prefers the running CLI to an extension-local peer dependency. Pi-compatible hosts are recognized by a piConfig field or a known package name, including Oh My Pi (@oh-my-pi/pi-coding-agent). The trace records the host package name in metadata.host_name and its version in metadata.pi_version.

Configuration

Settings load in this order, with later values taking precedence:

  1. Defaults
  2. ~/.pi/agent/braintrust.json
  3. .pi/braintrust.json in the project (or Pi's configured project config directory)
  4. bt trace run settings for that invocation

Example:

{
  "trace_to_braintrust": true,
  "route": {
    "auth": { "profile": "work", "org_name": "acme" },
    "destination": { "type": "project_logs", "project_name": "pi" },
    "additional_metadata": { "team": "platform" }
  }
}

Settings

Config keyDefaultPurpose
trace_to_braintrustfalseEnable tracing
route.auth.profile_idunsetSaved profile ID written by bt setup
route.auth.profiledefault bt profileSelect a profile by name
route.auth.org_nameprofile defaultSelect an organization
route.destinationproject logs in piSelect the trace destination
route.additional_metadataunsetAdd root-span metadata
route.flush_modeflush_on_turn_end in the default routeControl delivery flushing
show_uitrueShow the status indicator; override with BRAINTRUST_SHOW_UI
show_trace_linktrueShow the trace link; override with BRAINTRUST_SHOW_TRACE_LINK

Older files can still use top-level profile, org_name, project, and additional_metadata. For new files, use bt trace enable or the nested route format above. Include a destination when supplying a route.

Only the display settings read environment variables directly. Tracing settings come from these files or bt trace run. Credentials are managed by bt.

Provider request metadata is limited to model, thinking, output-limit, and tool-count settings. Full provider payloads and thinking signatures are omitted.

Manage tracing

bt trace doctor pi
bt trace status
bt trace update pi
bt trace disable pi

Local development

From the monorepo root, build the extension before loading it locally:

make build-pi
pi -e ./dist/pi/dist/index.mjs

This loads the extension for one run; it still needs an enabled Braintrust configuration. Run make validate-pi for package checks. See the contribution guide for source development instructions.

版本与发布记录

@braintrust/pi-extension 共发布 20 个版本,首次发布于 2026/04/08;过去 12 个月发布了 20 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.2.2latest2026/10/2910 天前
2.2.12026/10/2118 天前
2.2.02026/10/071 个月前
2.1.12026/09/241 个月前
2.1.02026/09/161 个月前
2.0.12026/09/101 个月前

关于 @braintrust/pi-extension 的常见问题

@braintrust/pi-extension 是什么?

Braintrust extension for pi. Includes automatic tracing for pi sessions, turns, LLM calls, and tool executions to Braintrust.

如何安装 @braintrust/pi-extension?

在项目目录运行 npm install @braintrust/pi-extension,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@earendil-works/pi-coding-agent(*)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@braintrust/pi-extension 支持 TypeScript 吗?

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

@braintrust/pi-extension 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@braintrust/pi-extension 可以商用吗?

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

@braintrust/pi-extension 的下载量有多少?

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

@braintrust/pi-extension 还在维护吗?

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