Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,18 @@ then authenticate and enable tracing. For example:

```bash
bt login
bt trace enable claude --project my-coding-agent
bt trace install claude --project my-coding-agent
```

Replace `claude` with your agent's CLI name below. Restart the agent after
setup and follow any plugin or hook trust prompts.
installation and follow any plugin or hook trust prompts. To opt a Git repository
in or out independently, run `bt trace enable claude --scope project` or
`bt trace disable claude --scope project` inside it. The repository's `.braintrust.json` applies to every agent; its settings
override user settings, and `bt trace run` overrides both.

## Supported agents

All six support `bt trace enable`, `update`, `disable`, and `doctor`.
All support `bt trace install`, `enable`, `update`, `disable`, and `doctor`.

| Agent and setup guide | CLI name | One-off traced run | Import / live attach | Distribution |
|---|---|---|---|---|
Expand Down Expand Up @@ -77,7 +80,7 @@ bt trace disable claude

`doctor` shows which configuration is in use and whether the running tracing
daemon can authenticate it. `status` reports trace delivery.
`update` keeps your settings; `disable` removes the plugin and its settings.
`disable` pauses tracing and keeps your settings. Use `enable` to resume; it also sets up tracing when needed or when you pass new settings. Use `uninstall` to remove the plugin and its settings.

For command hooks, `bt trace hook` exits nonzero when it cannot capture an
event. Exit `0` means the daemon accepted the event into its journal; delivery
Expand Down
65 changes: 58 additions & 7 deletions bt-daemon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,53 @@ or `bt trace doctor <agent>` for configuration, authentication, and recent
session diagnostics. Hook exit codes can be observed by the caller while the
coding agent decides whether to continue its turn.

## Project-scoped tracing

Each developer installs the agent integration once. To trace only repositories
that opt in, install it with tracing disabled by default:

```bash
bt trace install claude --disable --project my-default-project
```

A repository owner can configure tracing from anywhere inside the Git repository:

```bash
bt trace install claude --scope project --project my-repository-project
bt trace disable claude --scope project
bt trace enable claude --scope project
bt trace uninstall claude --scope project
```

Project install writes `.braintrust.json` at the Git repository root. The same
file applies to every coding-agent integration. It contains the tracing switch
and explicitly supplied settings; commit it to share the opt-in. Each developer
still needs a user-level installation and usable credentials. Credentials are
never stored in project files. Project-scoped uninstall deletes the entire shared
`.braintrust.json`; user-level installations and settings remain in place.

Project settings overlay user settings recursively: missing fields inherit,
objects merge by field, arrays append, and explicit scalar values replace
inherited values. Tags are deduplicated. Project span plugins are run after
user-level plugins, and their paths are relative to `.braintrust.json`:

```bash
bt trace install claude --scope project --plugin ./scripts/redact.mjs
```

Use `--no-inherit-plugins` to run only the project's plugins; use
`--inherit-plugins` to restore the default. A project configuration can execute
the JavaScript plugins it names when tracing runs, so review them before using
tracing in a repository.

Managed `bt trace run` takes precedence over both scopes. For example,
`bt trace run codex --inherit` starts from user and project settings before
applying invocation options; `--no-inherit-plugins` replaces the inherited
plugin chain for that invocation. `bt trace doctor <agent>` shows the current
repository's effective configuration. For multi-root Cursor and Antigravity
workspaces, the first root with a project file supplies the settings. `setup`
remains an alias for `install`.

## Per-agent plugin settings

Each coding agent reads an independent non-credential `braintrust.json` file:
Expand Down Expand Up @@ -146,7 +193,7 @@ Register both transforms persistently for ordinary Codex sessions. The
redactor runs first and its returned span becomes the tagger's input:

```bash
bt trace enable codex --plugin ./redact.mjs --plugin ./tag-ci.mjs
bt trace install codex --plugin ./redact.mjs --plugin ./tag-ci.mjs
```

`run` and `import` plugins apply only to that command. They replace, rather than
Expand Down Expand Up @@ -228,12 +275,12 @@ or provide it for one invocation with `bt trace run`. Both accept
`--additional-metadata` or `BRAINTRUST_ADDITIONAL_METADATA`:

```bash
bt trace enable claude --additional-metadata '{"team":"platform"}'
bt trace install claude --additional-metadata '{"team":"platform"}'
BRAINTRUST_ADDITIONAL_METADATA='{"ci":true,"run_id":"'"$JOB_ID"'"}' \
bt trace run codex -- "summarize this change"
```

`bt trace enable`, `bt trace run`, and `bt trace import` are explicit,
`bt trace install`, `bt trace run`, and `bt trace import` are explicit,
user-invoked commands, so all three accept routing (profile, organization,
project, destination) and `additional_metadata` from either a flag or the
matching `BRAINTRUST_*` environment variable, with the flag winning if both
Expand All @@ -251,7 +298,7 @@ span produced by a route. The option is available on persistent setup, one-off
runs, and transcript imports.

```bash
bt trace enable claude --tag ci --tag release-validation
bt trace install claude --tag ci --tag release-validation
bt trace run codex --tag ci -- "summarize this change"
bt trace import claude session-id --tag historical-import
```
Expand All @@ -263,9 +310,13 @@ one of those commands:
BRAINTRUST_TAGS=ci,release-validation bt trace run codex -- "summarize this change"
```

Use `bt trace disable <agent>` to remove the installed tracing plugin and its
Braintrust settings. `bt trace setup <agent>` remains an alias for `bt trace
enable <agent>` for backwards compatibility.
Use `bt trace disable <agent>` to pause tracing while keeping the plugin and settings.
Use `bt trace enable <agent>` to resume. If there is no saved configuration, or you provide
explicit configuration options, `enable` runs installation and reports the result. Environment
defaults do not change an existing configuration during a plain `enable`.
Use `bt trace uninstall <agent>` to remove
the plugin and its Braintrust settings. Use `bt trace install <agent>` to install or
change the configuration.

## Build and test

Expand Down
10 changes: 8 additions & 2 deletions bt-daemon/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,9 @@ impl ImportArgs {
#[derive(Debug, Clone, Args)]
#[command(trailing_var_arg = true)]
pub struct RunArgs {
/// Inherit user and project tracing settings for this invocation.
#[arg(long)]
pub inherit: bool,
/// Coding agent to launch.
#[arg(value_enum)]
pub source: RunSource,
Expand All @@ -309,8 +312,11 @@ pub struct RunArgs {
/// Tag applied to each root span for this invocation. May be repeated or comma-separated.
#[arg(long = "tag", env = "BRAINTRUST_TAGS", value_delimiter = ',')]
pub tags: Vec<String>,
/// JavaScript span transform for this invocation. Repeat to compose an
/// isolated transform chain; persistent setup plugins are not included.
/// Replace inherited span plugins instead of appending to them.
#[arg(long)]
pub no_inherit_plugins: bool,
/// JavaScript span transform for this invocation. With --inherit, these
/// follow inherited plugins unless --no-inherit-plugins is supplied.
#[arg(long, value_name = "PATH")]
pub plugin: Vec<PathBuf>,
/// Arguments forwarded verbatim to the coding agent.
Expand Down
2 changes: 1 addition & 1 deletion bt-daemon/src/codex_hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub(crate) async fn activate() -> anyhow::Result<()> {
});
anyhow::ensure!(
installed,
"Codex tracing plugin is not installed and enabled; rerun `bt trace enable codex`"
"Codex tracing plugin is not installed and enabled; rerun `bt trace install codex`"
);
let hooks = request(
&mut stdin,
Expand Down
Loading
Loading