Implementation:AI Shell Team Aish PersistentPty start
| Knowledge Sources | |
|---|---|
| Domains | Terminal, Process_Management |
| Last Updated | 2026-10-29 00:00 GMT |
Overview
Concrete tool for starting a persistent bash session inside a pseudo-terminal with RC file injection and control pipe provided by the aish-pty crate.
= Description
The PersistentPty::start method creates a new persistent bash session. It writes an RC file to a temp file, creates a control pipe, opens a PTY pair via `openpty`, sets the master to non-blocking and close-on-exec, syncs terminal window size from stdin, and forks a child that runs bash with the RC file and the slave PTY end.
The RC file injects shell integration hooks (command tracking, prompt customization). The control pipe allows programmatic command injection. The child runs bash with `--rcfile` pointing to the injected RC file, so the user's `.bashrc` is not modified.
Usage
Call this method when starting or resuming a shell session. Pass the working directory and terminal dimensions from the session state.
Code Reference
Source Location
- Repository: aish
- File: crates/aish-pty/src/persistent.rs
Signature
impl PersistentPty {
pub fn start(cwd: &str, rows: u16, cols: u16) -> aish_core::Result<Self>
}
Import
use aish_pty::PersistentPty;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| cwd | &str | Yes | Working directory for the bash session |
| rows | u16 | Yes | Terminal height in rows |
| cols | u16 | Yes | Terminal width in columns |
Outputs
| Name | Type | Description |
|---|---|---|
| return | Result<PersistentPty> | PTY with master fd, control pipe, child pid; Err on fork/openpty failure |
Usage Examples
Starting a PTY Session
use aish_pty::PersistentPty;
let pty = PersistentPty::start("/home/user/project", 24, 80)?;
// Read output from the PTY
let mut buf = [0u8; 4096];
let n = pty.read(&mut buf)?;
// Send a command via the control pipe
pty.send_command("ls -la")?;