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
3 changes: 2 additions & 1 deletion bt-daemon/src/agents/antigravity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ impl Agent for Antigravity {
impl Register for Antigravity {
fn register(self: Arc<Self>, registrar: &mut Registrar) {
registrar.setup.insert(self.clone());
registrar.translate.insert(self);
registrar.translate.insert(self.clone());
registrar.import.insert(self);
}
}
3 changes: 2 additions & 1 deletion bt-daemon/src/agents/claude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ impl Register for Claude {
fn register(self: Arc<Self>, registrar: &mut Registrar) {
registrar.setup.insert(self.clone());
registrar.run.insert(self.clone());
registrar.translate.insert(self);
registrar.translate.insert(self.clone());
registrar.import.insert(self);
}
}
3 changes: 2 additions & 1 deletion bt-daemon/src/agents/codex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ impl Register for Codex {
fn register(self: Arc<Self>, registrar: &mut Registrar) {
registrar.setup.insert(self.clone());
registrar.run.insert(self.clone());
registrar.translate.insert(self);
registrar.translate.insert(self.clone());
registrar.import.insert(self);
}
}
3 changes: 2 additions & 1 deletion bt-daemon/src/agents/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ impl Register for Cursor {
fn register(self: Arc<Self>, registrar: &mut Registrar) {
registrar.setup.insert(self.clone());
registrar.run.insert(self.clone());
registrar.translate.insert(self);
registrar.translate.insert(self.clone());
registrar.import.insert(self);
}
}
2 changes: 2 additions & 0 deletions bt-daemon/src/agents/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub(crate) use pi::Pi;

use crate::managed_run::ManagedRun;
use crate::setup::Setup;
use crate::transcript_import::TranscriptImport;
use crate::translate::TranslatorFactory;
use std::sync::{Arc, OnceLock};

Expand Down Expand Up @@ -85,6 +86,7 @@ pub(crate) struct Registrar {
pub setup: Agents<dyn Setup>,
pub run: Agents<dyn ManagedRun>,
pub translate: Agents<dyn TranslatorFactory>,
pub import: Agents<dyn TranscriptImport>,
}

pub(crate) trait Register {
Expand Down
47 changes: 41 additions & 6 deletions bt-daemon/src/transcript_import/antigravity.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use super::{envelope, validate_session_id};
use super::{
envelope, validate_session_id, IncrementalRecords, TailSession, TranscriptImport,
TranscriptLayout,
};
use crate::wire::Envelope;
use anyhow::bail;
use serde_json::{json, Value};
Expand All @@ -7,14 +10,36 @@ use std::path::{Path, PathBuf};

const TRANSCRIPT_NAME: &str = "transcript_full.jsonl";

impl TranscriptImport for crate::agents::Antigravity {
fn discover(&self, home: &Path) -> anyhow::Result<Vec<PathBuf>> {
layout(roots(home)).discover()
}

fn find(&self, home: &Path, session_id: &str) -> anyhow::Result<PathBuf> {
layout(roots(home)).find(session_id)
}

fn tail(&self) -> Box<dyn TailSession> {
Box::new(Tail::default())
}
}

#[derive(Default)]
pub(super) struct Tail {
emitted: usize,
stopped: bool,
}

impl Tail {
pub(super) fn poll(
impl TailSession for Tail {
fn envelopes(
&mut self,
path: &Path,
records: &IncrementalRecords,
) -> anyhow::Result<Vec<Envelope>> {
envelopes(path, &records.values, &records.end_offsets)
}

fn poll(
&mut self,
events: Vec<Envelope>,
_len: u64,
Expand All @@ -36,11 +61,21 @@ impl Tail {
}
}

pub(super) fn roots(home: &Path) -> Vec<PathBuf> {
/// The transcript layout under these roots.
pub(super) fn layout(roots: Vec<PathBuf>) -> TranscriptLayout {
TranscriptLayout {
display_name: crate::agents::Agent::identity(&crate::agents::Antigravity).display_name,
roots,
session_id: transcript_session_id,
filename_matches,
}
}

fn roots(home: &Path) -> Vec<PathBuf> {
vec![home.join(".gemini/antigravity-cli/brain")]
}

pub(super) fn transcript_session_id(path: &Path) -> Option<String> {
fn transcript_session_id(path: &Path) -> Option<String> {
if path.file_name().and_then(|name| name.to_str()) != Some(TRANSCRIPT_NAME) {
return None;
}
Expand All @@ -54,7 +89,7 @@ pub(super) fn transcript_session_id(path: &Path) -> Option<String> {
is_transcript_path(path, session_id).then(|| session_id.to_owned())
}

pub(super) fn filename_matches(path: &Path, session_id: &str) -> bool {
fn filename_matches(path: &Path, session_id: &str) -> bool {
validate_session_id(session_id).is_ok() && is_transcript_path(path, session_id)
}

Expand Down
50 changes: 44 additions & 6 deletions bt-daemon/src/transcript_import/claude.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::{
envelope, file_session_id, find_jsonl_files, read_complete_jsonl_records, read_jsonl_records,
string_at, timestamp_bounds, timestamp_ms, validate_session_id,
string_at, timestamp_bounds, timestamp_ms, validate_session_id, IncrementalRecords,
TailSession, TranscriptImport, TranscriptLayout,
};
use crate::wire::Envelope;
use anyhow::bail;
Expand All @@ -9,6 +10,20 @@ use std::collections::{HashMap, HashSet};
use std::io::BufRead;
use std::path::{Path, PathBuf};

impl TranscriptImport for crate::agents::Claude {
fn discover(&self, home: &Path) -> anyhow::Result<Vec<PathBuf>> {
layout(roots(home)).discover()
}

fn find(&self, home: &Path, session_id: &str) -> anyhow::Result<PathBuf> {
layout(roots(home)).find(session_id)
}

fn tail(&self) -> Box<dyn TailSession> {
Box::new(Tail::default())
}
}

#[derive(Default)]
pub(super) struct Tail {
started: bool,
Expand All @@ -17,8 +32,21 @@ pub(super) struct Tail {
last_len: u64,
}

impl Tail {
pub(super) fn poll(
impl TailSession for Tail {
fn envelopes(
&mut self,
path: &Path,
records: &IncrementalRecords,
) -> anyhow::Result<Vec<Envelope>> {
envelopes(
path,
&records.values,
&records.end_offsets,
records.read_offset,
)
}

fn poll(
&mut self,
events: Vec<Envelope>,
len: u64,
Expand Down Expand Up @@ -76,7 +104,7 @@ impl Tail {
}
}

pub(super) fn transcript_session_id(path: &Path) -> Option<String> {
fn transcript_session_id(path: &Path) -> Option<String> {
let file = std::fs::File::open(path).ok()?;
for line in std::io::BufReader::new(file).lines().map_while(Result::ok) {
let Ok(record) = serde_json::from_str::<Value>(&line) else {
Expand All @@ -93,14 +121,24 @@ pub(super) fn transcript_session_id(path: &Path) -> Option<String> {
None
}

pub(super) fn roots(home: &Path) -> Vec<PathBuf> {
/// The transcript layout under these roots.
pub(super) fn layout(roots: Vec<PathBuf>) -> TranscriptLayout {
TranscriptLayout {
display_name: crate::agents::Agent::identity(&crate::agents::Claude).display_name,
roots,
session_id: transcript_session_id,
filename_matches,
}
}

fn roots(home: &Path) -> Vec<PathBuf> {
let claude_home = std::env::var_os("CLAUDE_CONFIG_DIR")
.map(PathBuf::from)
.unwrap_or_else(|| home.join(".claude"));
vec![claude_home.join("projects")]
}

pub(super) fn filename_matches(path: &Path, session_id: &str) -> bool {
fn filename_matches(path: &Path, session_id: &str) -> bool {
path.file_name().and_then(|name| name.to_str()) == Some(&format!("{session_id}.jsonl"))
}

Expand Down
45 changes: 39 additions & 6 deletions bt-daemon/src/transcript_import/codex.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::{
envelope, file_session_id, find_jsonl_files, read_jsonl_records, string_at, timestamp_bounds,
timestamp_ms, validate_session_id,
timestamp_ms, validate_session_id, IncrementalRecords, TailSession, TranscriptImport,
TranscriptLayout,
};
use crate::wire::Envelope;
use anyhow::bail;
Expand All @@ -9,15 +10,37 @@ use std::collections::{HashMap, HashSet};
use std::io::BufRead;
use std::path::{Path, PathBuf};

impl TranscriptImport for crate::agents::Codex {
fn discover(&self, home: &Path) -> anyhow::Result<Vec<PathBuf>> {
layout(roots(home)).discover()
}

fn find(&self, home: &Path, session_id: &str) -> anyhow::Result<PathBuf> {
layout(roots(home)).find(session_id)
}

fn tail(&self) -> Box<dyn TailSession> {
Box::new(Tail::default())
}
}

#[derive(Default)]
pub(super) struct Tail {
started: bool,
checkpoints: usize,
last_len: u64,
}

impl Tail {
pub(super) fn poll(
impl TailSession for Tail {
fn envelopes(
&mut self,
path: &Path,
records: &IncrementalRecords,
) -> anyhow::Result<Vec<Envelope>> {
envelopes(path, &records.values)
}

fn poll(
&mut self,
events: Vec<Envelope>,
len: u64,
Expand Down Expand Up @@ -64,7 +87,7 @@ impl Tail {
}
}

pub(super) fn transcript_session_id(path: &Path) -> Option<String> {
fn transcript_session_id(path: &Path) -> Option<String> {
let file = std::fs::File::open(path).ok()?;
for line in std::io::BufReader::new(file).lines().map_while(Result::ok) {
let Ok(record) = serde_json::from_str::<Value>(&line) else {
Expand All @@ -85,7 +108,17 @@ pub(super) fn transcript_session_id(path: &Path) -> Option<String> {
None
}

pub(super) fn roots(home: &Path) -> Vec<PathBuf> {
/// The transcript layout under these roots.
pub(super) fn layout(roots: Vec<PathBuf>) -> TranscriptLayout {
TranscriptLayout {
display_name: crate::agents::Agent::identity(&crate::agents::Codex).display_name,
roots,
session_id: transcript_session_id,
filename_matches,
}
}

fn roots(home: &Path) -> Vec<PathBuf> {
let codex_home = std::env::var_os("CODEX_HOME")
.map(PathBuf::from)
.unwrap_or_else(|| home.join(".codex"));
Expand All @@ -95,7 +128,7 @@ pub(super) fn roots(home: &Path) -> Vec<PathBuf> {
]
}

pub(super) fn filename_matches(path: &Path, session_id: &str) -> bool {
fn filename_matches(path: &Path, session_id: &str) -> bool {
path.file_name()
.and_then(|name| name.to_str())
.is_some_and(|name| name.ends_with(&format!("{session_id}.jsonl")))
Expand Down
Loading
Loading