use agentbridge::{
adapters::generic_stdio::GenericStdioAdapter,
CliAdapter, ContextPacket,
};
use std::path::Path;
pub fn run(
from_cmd: &str,
to_cmd: &str,
save: Option<&str>,
) -> anyhow::Result<()> {
let src = GenericStdioAdapter::spawn("source", from_cmd, &[])?;
println!("Source adapter '{}' connected.", from_cmd);
let ctx: ContextPacket = src.snapshot_context().map_err(|e| anyhow::anyhow!("{e}"))?;
println!(
"Captured context: {} messages, {} files, {} artifacts.",
ctx.conversation.len(),
ctx.code_context.files.len(),
ctx.artifacts.len(),
);
if let Some(path) = save {
let bytes = ctx.to_bytes()?;
std::fs::write(path, &bytes)?;
println!("Context saved to {path}.");
}
let dst = GenericStdioAdapter::spawn("destination", to_cmd, &[])?;
println!("Destination adapter '{}' connected.", to_cmd);
dst.inject_context(&ctx).map_err(|e| anyhow::anyhow!("{e}"))?;
println!("Context successfully handed off to '{}'.", to_cmd);
Ok(())
}
pub fn run_from_file(context_path: &Path, to_cmd: &str) -> anyhow::Result<()> {
let bytes = std::fs::read(context_path)?;
let ctx = ContextPacket::from_bytes(&bytes)?;
println!(
"Loaded context from '{}': {} messages.",
context_path.display(),
ctx.conversation.len(),
);
let dst = GenericStdioAdapter::spawn("destination", to_cmd, &[])?;
dst.inject_context(&ctx).map_err(|e| anyhow::anyhow!("{e}"))?;
println!("Context injected into '{to_cmd}'.");
Ok(())
}