pub struct PtyHandle { /* private fields */ }Expand description
Handle to a PTY
Implementations§
Source§impl PtyHandle
impl PtyHandle
Sourcepub async fn spawn_command(&self, cmd: CommandBuilder) -> Result<()>
pub async fn spawn_command(&self, cmd: CommandBuilder) -> Result<()>
Spawn a command in the PTY
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Check if child process is running
Sourcepub async fn read_with_timeout(&self, timeout_ms: u64) -> Result<Vec<u8>>
pub async fn read_with_timeout(&self, timeout_ms: u64) -> Result<Vec<u8>>
Read data from PTY with timeout (for testing)
Sourcepub async fn spawn_claude(
&self,
prompt: &str,
working_dir: &Path,
max_turns: Option<u32>,
) -> Result<()>
pub async fn spawn_claude( &self, prompt: &str, working_dir: &Path, max_turns: Option<u32>, ) -> Result<()>
Spawn Claude Code in the PTY with –dangerously-skip-permissions flag
This method launches Claude CLI in a PTY session for true parallel multi-agent execution. Each call creates an independent Claude process that can run concurrently with others.
§Arguments
prompt- The prompt/instruction to send to Claudeworking_dir- Working directory for the Claude sessionmax_turns- Maximum number of conversation turns (default: 1 for single task)
§Example
use ai_session::core::pty::PtyHandle;
use std::path::Path;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let pty = PtyHandle::new(24, 80)?;
pty.spawn_claude("Create a hello world function", Path::new("/tmp"), Some(3)).await?;
// Read output with timeout
let output = pty.read_with_timeout(30000).await?;
println!("Claude output: {}", String::from_utf8_lossy(&output));
Ok(())
}Sourcepub async fn spawn_claude_and_wait(
&self,
prompt: &str,
working_dir: &Path,
max_turns: Option<u32>,
timeout_ms: u64,
) -> Result<String>
pub async fn spawn_claude_and_wait( &self, prompt: &str, working_dir: &Path, max_turns: Option<u32>, timeout_ms: u64, ) -> Result<String>
Spawn Claude Code and wait for completion, returning the output
This is a convenience method that spawns Claude, waits for it to finish, and returns the collected output.
§Arguments
prompt- The prompt/instruction to send to Claudeworking_dir- Working directory for the Claude sessionmax_turns- Maximum number of conversation turnstimeout_ms- Timeout in milliseconds to wait for completion
Sourcepub async fn spawn_claude_with_session(
&self,
prompt: &str,
working_dir: &Path,
session_id: &str,
max_turns: Option<u32>,
) -> Result<()>
pub async fn spawn_claude_with_session( &self, prompt: &str, working_dir: &Path, session_id: &str, max_turns: Option<u32>, ) -> Result<()>
Spawn Claude Code with a specific session ID for later resumption
This method allows you to specify a session ID that can be used later
with resume_claude to continue the conversation.
§Arguments
prompt- The prompt/instruction to send to Claudeworking_dir- Working directory for the Claude sessionsession_id- UUID to use as the Claude session IDmax_turns- Maximum number of conversation turns
§Example
use ai_session::core::pty::PtyHandle;
use std::path::Path;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let pty = PtyHandle::new(24, 80)?;
let session_id = "2c4e029f-3411-442a-b24c-33001c78cd14";
// Start a new session with specific ID
pty.spawn_claude_with_session(
"Create a hello world function",
Path::new("/tmp"),
session_id,
Some(3),
).await?;
// Later, resume the same session
let pty2 = PtyHandle::new(24, 80)?;
pty2.resume_claude(session_id, Path::new("/tmp")).await?;
Ok(())
}Sourcepub async fn resume_claude(
&self,
session_id: &str,
working_dir: &Path,
) -> Result<()>
pub async fn resume_claude( &self, session_id: &str, working_dir: &Path, ) -> Result<()>
Resume a Claude Code session by session ID
This method resumes a previous Claude conversation using the session ID that was used when the session was created.
§Arguments
session_id- The Claude session ID to resumeworking_dir- Working directory for the Claude session
§Example
use ai_session::core::pty::PtyHandle;
use std::path::Path;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let pty = PtyHandle::new(24, 80)?;
// Resume a previous session
pty.resume_claude(
"2c4e029f-3411-442a-b24c-33001c78cd14",
Path::new("/tmp"),
).await?;
Ok(())
}Sourcepub async fn resume_claude_with_prompt(
&self,
session_id: &str,
prompt: &str,
working_dir: &Path,
max_turns: Option<u32>,
) -> Result<()>
pub async fn resume_claude_with_prompt( &self, session_id: &str, prompt: &str, working_dir: &Path, max_turns: Option<u32>, ) -> Result<()>
Resume a Claude Code session interactively with a new prompt
This method resumes a previous Claude conversation and sends a new prompt.
§Arguments
session_id- The Claude session ID to resumeprompt- New prompt to send to the resumed sessionworking_dir- Working directory for the Claude sessionmax_turns- Maximum number of conversation turns
Auto Trait Implementations§
impl Freeze for PtyHandle
impl RefUnwindSafe for PtyHandle
impl Send for PtyHandle
impl Sync for PtyHandle
impl Unpin for PtyHandle
impl UnwindSafe for PtyHandle
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.