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
28 changes: 28 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,34 @@ jobs:
run: cargo build --manifest-path bt-daemon/Cargo.toml --all-features --locked
- name: Test daemon
run: cargo test --manifest-path bt-daemon/Cargo.toml --all-features --locked
- name: Test legacy Grok and Grok Build TUI with mock inference
if: runner.os == 'macOS'
shell: bash
run: |
set -euo pipefail
make validate-grok
download_dir="$(mktemp -d "$RUNNER_TEMP/grok-compatibility.XXXXXX")"
trap 'rm -rf "$download_dir"' EXIT
test_grok() {
local version="$1" artifact="$2" sha="$3"
local target="$download_dir/$version"
mkdir "$target" &&
curl --fail --silent --show-error --location --retry 3 \
"https://x.ai/cli/$artifact.gz" -o "$target/grok.gz" &&
gzip -dc "$target/grok.gz" > "$target/grok" &&
printf '%s %s\n' "$sha" "$target/grok" | shasum -a 256 -c &&
chmod 755 "$target/grok" &&
BT_AGENT_INFERENCE_MODE=mock BT_AGENT_INGEST_MODE=mock \
GROK_BIN="$target/grok" GROK_TEST_VERSION="$version" GROK_TEST_PLUGIN_DIR="$PWD/dist/grok" \
cargo test --manifest-path bt-daemon/Cargo.toml --all-features --locked \
--test grok_integration -- --ignored --nocapture --exact grok_session_emits_traces
}
failed=0
test_grok 1.0.97 grok-1.0.97-macos-aarch64 \
0b42371fb80db63b310a90cfef4ddcdab960dcaaae8ee6a7d23e7d18e190ecd1 || failed=1
test_grok 2.0.6 unified/agent-host-2.0.6-macos-aarch64 \
32e4ea936bfbe4465b8bc8dc663e8c48c10f80b0496afb54bc323d15aaf1c2cd || failed=1
exit "$failed"
# `bt trace install/update codex` activation against the latest Codex,
# in an isolated CODEX_HOME. Needs no credentials.
- name: Check Codex hook activation contract
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ All support `bt trace install`, `enable`, `update`, `disable`, and `doctor`.
| [Google Antigravity](src/plugins/antigravity/content/README.md) | `antigravity` | — | Yes | [GitHub](https://github.com/braintrustdata/braintrust-antigravity-plugin) |
| [Claude Code](src/plugins/claude/content/README.md) | `claude` | Yes | Yes | [GitHub](https://github.com/braintrustdata/braintrust-claude-plugin) |
| [Codex](src/plugins/codex/content/README.md) | `codex` | Yes | Yes | [GitHub](https://github.com/braintrustdata/braintrust-codex-plugin) |
| [Cursor](src/plugins/cursor/content/README.md) | `cursor` | Yes | Yes, transcript-limited | [GitHub](https://github.com/braintrustdata/braintrust-cursor-extension) |
| [Grok](src/plugins/grok/content/README.md) | `grok` | — | — | [GitHub](https://github.com/braintrustdata/braintrust-grok-plugin) |
| [Grok Build desktop / Cursor](src/plugins/cursor/content/README.md) | `grok-build-desktop` (`cursor`) | Legacy Cursor CLI only | Yes, Cursor-format transcripts | [GitHub](https://github.com/braintrustdata/braintrust-cursor-extension) |
| [Grok Build TUI / legacy Grok](src/plugins/grok/content/README.md) | `grok-build` (`grok`) | — | — | [GitHub](https://github.com/braintrustdata/braintrust-grok-plugin) |
| [OpenCode](src/plugins/opencode/content/README.md) | `opencode` | Yes | — | [npm](https://www.npmjs.com/package/@braintrust/trace-opencode) |
| [Pi](src/plugins/pi/content/README.md) | `pi` | Yes | — | [npm](https://www.npmjs.com/package/@braintrust/pi-extension) |

Expand All @@ -64,7 +64,7 @@ bt trace run --project my-coding-agent claude -- -p "summarize this repository"
bt trace import claude SESSION_ID
bt trace import claude SESSION_ID --attach
bt trace run --project my-coding-agent cursor
bt trace import cursor SESSION_ID --attach
bt trace import grok-build-desktop SESSION_ID --attach
```

See the agent guides for limitations.
Expand Down
3 changes: 2 additions & 1 deletion bt-daemon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ Each coding agent reads an independent non-credential `braintrust.json` file:
- OpenCode: `$XDG_CONFIG_HOME/opencode/braintrust.json`, falling back to
`~/.config/opencode/braintrust.json`
- Pi: `~/.pi/agent/braintrust.json`
- Grok: `~/.grok/braintrust.json`
- Grok Build desktop (`cursor`): `~/.cursor/braintrust.json`
- Grok Build TUI (`grok`): `~/.grok/braintrust.json`
- Antigravity: `~/.gemini/config/braintrust.json`

`BRAINTRUST_DAEMON_CONFIG` can override the path for isolated tests and managed
Expand Down
2 changes: 1 addition & 1 deletion bt-daemon/src/agents/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub(crate) const IDENTITY: Identity = Identity {
id: "cursor",
source: "cursor",
aliases: &[],
display_name: "Cursor",
display_name: "Grok Build desktop",
};

impl Agent for Cursor {
Expand Down
5 changes: 4 additions & 1 deletion bt-daemon/src/agents/grok.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
use super::{Agent, Identity, Register, Registrar};
use std::sync::Arc;

mod hook_transcript;
pub(crate) use hook_transcript::HookTranscript;

pub(crate) struct Grok;

pub(crate) const IDENTITY: Identity = Identity {
id: "grok",
source: "grok",
aliases: &[],
display_name: "Grok",
display_name: "Grok Build TUI",
};

impl Agent for Grok {
Expand Down
43 changes: 43 additions & 0 deletions bt-daemon/src/agents/grok/hook_transcript.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use crate::transcript_mirror::GrokReferences;
use serde::Deserialize;
use std::path::Path;

/// Newer Grok versions send both path keys in one hook. Deserialize them
/// separately so sending both spellings does not invalidate the event.
#[derive(Deserialize)]
pub(crate) struct HookTranscript {
#[serde(rename = "transcriptPath")]
camel_case_path: Option<String>,
transcript_path: Option<String>,
#[serde(rename = "_bt_grok_transcript_mirrors")]
pub mirrors: Option<GrokReferences>,
}

impl HookTranscript {
pub fn decode(payload: &serde_json::Value) -> serde_json::Result<Self> {
Self::deserialize(payload)
}

pub fn path(&self) -> Option<&Path> {
self.camel_case_path
.as_deref()
.filter(|path| !path.is_empty())
.or(self.transcript_path.as_deref())
.filter(|path| !path.is_empty())
.map(Path::new)
}

pub fn is_agent_host(&self) -> bool {
// The unified CLI writes agent-transcripts/<session>/<session>.jsonl.
// Legacy Grok reports updates.jsonl or chat_history.jsonl instead.
self.path().is_some_and(|path| {
path.extension()
.is_some_and(|extension| extension == "jsonl")
&& path.parent().is_some_and(|dir| {
dir.file_name() == path.file_stem()
&& dir.parent().and_then(Path::file_name)
== Some(std::ffi::OsStr::new("agent-transcripts"))
})
})
}
}
2 changes: 1 addition & 1 deletion bt-daemon/src/agents/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub(crate) mod antigravity;
mod claude;
mod codex;
pub(crate) mod cursor;
mod grok;
pub(crate) mod grok;
mod muse;
mod opencode;
mod pi;
Expand Down
2 changes: 2 additions & 0 deletions bt-daemon/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ pub enum ImportSource {
Codex,
#[value(alias = "muse-code")]
Muse,
#[value(name = "grok-build-desktop", alias = "cursor")]
Cursor,
#[value(name = "claude", alias = "claude-code")]
Claude,
Expand Down Expand Up @@ -350,6 +351,7 @@ pub enum RunSource {
Codex,
#[value(alias = "muse-code")]
Muse,
/// Launch the legacy Cursor CLI.
Cursor,
#[value(name = "claude", alias = "claude-code")]
Claude,
Expand Down
11 changes: 6 additions & 5 deletions bt-daemon/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,13 +510,13 @@ const GROK_TERMINAL_SNAPSHOT_QUIET_PERIOD: std::time::Duration =
std::time::Duration::from_millis(10);

async fn hydrate_grok_transcript_references(data_dir: &std::path::Path, env: &mut Envelope) {
let Ok(fields) = TranscriptPayload::decode(&env.payload) else {
let Ok(fields) = crate::agents::grok::HookTranscript::decode(&env.payload) else {
return;
};
let Some(transcript) = fields.transcript_path.map(std::path::PathBuf::from) else {
if fields.is_agent_host() {
return;
};
let Some(session_dir) = transcript.parent() else {
}
let Some(session_dir) = fields.path().and_then(std::path::Path::parent) else {
return;
};
let mirror_session = crate::ids::session_namespace(&env.source, &env.session_id);
Expand Down Expand Up @@ -741,7 +741,8 @@ mod tests {
managed_run_id: None,
capture: None,
payload: serde_json::json!({
"transcriptPath": session.join("chat_history.jsonl")
"transcriptPath": session.join("chat_history.jsonl"),
"transcript_path": session.join("chat_history.jsonl")
}),
route: None,
config: None,
Expand Down
19 changes: 18 additions & 1 deletion bt-daemon/src/hook_executable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,28 @@ mod tests {

#[test]
fn delegation_preserves_input_arguments_streams_and_status() {
let current = std::env::current_exe().unwrap();
let tmp = tempfile::tempdir().unwrap();
let target = tmp
.path()
.join(format!("selected bt{}", std::env::consts::EXE_SUFFIX));
std::fs::copy(std::env::current_exe().unwrap(), &target).unwrap();
#[cfg(target_os = "linux")]
{
// A concurrent test's fork can inherit a write handle opened in
// this process and cause exec to fail with ETXTBSY. Let cp own the
// handle and wait for it to exit before launching the fixture.
let output = crate::subprocess::background_command("cp")
.arg("--")
.arg(&current)
.arg(&target)
.output()
.unwrap();
assert!(output.status.success(), "{output:?}");
std::fs::set_permissions(&target, std::fs::metadata(&current).unwrap().permissions())
.unwrap();
}
#[cfg(not(target_os = "linux"))]
std::fs::copy(&current, &target).unwrap();
let output = child(&target, false);
assert_eq!(output.status.code(), Some(23), "{output:?}");
let stdout = String::from_utf8_lossy(&output.stdout);
Expand Down
79 changes: 57 additions & 22 deletions bt-daemon/src/trace_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ pub enum DoctorAgent {
OpenCode,
Pi,
Antigravity,
#[value(name = "grok-build", alias = "grok")]
Grok,
#[value(name = "grok-build-desktop", alias = "cursor")]
Cursor,
}

Expand Down Expand Up @@ -183,9 +185,11 @@ pub enum SetupAgent {
OpenCode,
/// Install the published Pi tracing extension.
Pi,
/// Install the published Grok tracing plugin.
/// Install tracing for the Grok Build TUI and legacy Grok CLI.
#[command(name = "grok-build", visible_alias = "grok")]
Grok,
/// Install the published Cursor tracing plugin.
/// Install tracing for Grok Build desktop and legacy Cursor.
#[command(name = "grok-build-desktop", visible_alias = "cursor")]
Cursor,
/// Install the Google Antigravity tracing hooks.
Antigravity,
Expand Down Expand Up @@ -379,8 +383,20 @@ mod tests {
"antigravity",
"Google Antigravity",
),
("grok", DoctorAgent::Grok, "grok", "Grok"),
("cursor", DoctorAgent::Cursor, "cursor", "Cursor"),
("grok", DoctorAgent::Grok, "grok", "Grok Build TUI"),
("grok-build", DoctorAgent::Grok, "grok", "Grok Build TUI"),
(
"cursor",
DoctorAgent::Cursor,
"cursor",
"Grok Build desktop",
),
(
"grok-build-desktop",
DoctorAgent::Cursor,
"cursor",
"Grok Build desktop",
),
] {
let cli = Cli::try_parse_from(["bt", "doctor", agent]).unwrap();
assert!(matches!(
Expand Down Expand Up @@ -418,26 +434,45 @@ mod tests {
}

#[test]
fn grok_uses_shared_enable_and_disable_commands() {
{
let parsed = Cli::try_parse_from(["bt", "setup", "grok"]).unwrap();
assert!(matches!(
parsed.trace.command,
TraceCommand::Install(SetupArgs {
agent: SetupAgent::Grok,
..
})
));
fn grok_build_names_use_the_existing_setup_adapters_and_settings() {
for (old, new) in [("grok", "grok-build"), ("cursor", "grok-build-desktop")] {
for command in [
"install",
"setup",
"enable",
"disable",
"update",
"uninstall",
] {
for name in [old, new] {
let parsed = Cli::try_parse_from(["bt", command, name]).unwrap();
let agent = match parsed.trace.command {
TraceCommand::Install(args) => args.agent,
TraceCommand::Enable(args) => args.agent,
TraceCommand::Disable(args) | TraceCommand::Uninstall(args) => args.agent,
TraceCommand::Update(args) => args.agent,
other => panic!("unexpected command for {command} {name}: {other:?}"),
};
let identity = agent.identity();
assert_eq!(identity.id, old);
assert_eq!(identity.source, old);
}
}
}
}

let parsed = Cli::try_parse_from(["bt", "disable", "grok"]).unwrap();
assert!(matches!(
parsed.trace.command,
TraceCommand::Disable(DisableArgs {
agent: SetupAgent::Grok,
..
})
));
#[test]
fn desktop_import_names_use_the_cursor_transcript_source() {
for name in ["cursor", "grok-build-desktop"] {
let parsed =
Cli::try_parse_from(["bt", "import", name, "session-id", "--attach"]).unwrap();
let TraceCommand::Import(args) = parsed.trace.command else {
panic!("expected import command for {name}");
};
assert_eq!(args.source, crate::ImportSource::Cursor);
assert_eq!(args.source.identity().source, "cursor");
assert!(args.attach);
}
}

#[test]
Expand Down
4 changes: 1 addition & 3 deletions bt-daemon/src/transcript_mirror/payload.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{ClaudeChildReference, GrokReferences, Observation, Reference, Snapshot};
use super::{ClaudeChildReference, Observation, Reference, Snapshot};

/// Decode the known capture protocol once at the envelope boundary. Native
/// agent data remains in the raw journal and is decoded by its own translator.
Expand All @@ -15,8 +15,6 @@ pub(crate) struct TranscriptPayload {
pub mirror: Option<Reference>,
#[serde(rename = "_bt_claude_transcript_mirrors")]
pub claude_mirrors: Option<std::collections::BTreeMap<String, Reference>>,
#[serde(rename = "_bt_grok_transcript_mirrors")]
pub grok_mirrors: Option<GrokReferences>,
#[serde(rename = "_bt_transcript_observation")]
pub observation: Option<Observation>,
#[serde(rename = "_bt_transcript_snapshot")]
Expand Down
Loading
Loading