pub struct CommandCapture;Expand description
Command capture with durable NDJSON append.
Provides static methods for writing NDJSON lines to session files
with fsync after each write for crash safety. Each method opens
the file, writes a single NDJSON line, syncs to disk, and closes.
§File Format
{"type":"header","version":2,"id":"...","name":"...","shell":"bash",...}
{"type":"command","index":0,"command":"echo hello","cwd":"/home",...}
{"type":"command","index":1,"command":"ls -la","cwd":"/home",...}
{"type":"footer","ended_at":1234567890.123,"command_count":2,"status":"completed"}Implementations§
Source§impl CommandCapture
impl CommandCapture
Sourcepub fn write_header(path: &Path, header: &SessionHeader) -> Result<()>
pub fn write_header(path: &Path, header: &SessionHeader) -> Result<()>
Write the session header as the first line of the NDJSON file.
Creates the file (or truncates if exists) and writes the header
line followed by sync_all() for durability. Sets restrictive
permissions (0o600) to prevent other users from reading session data.
§Errors
Returns an error if file creation or writing fails.
Sourcepub fn append_command(path: &Path, command: &Command) -> Result<()>
pub fn append_command(path: &Path, command: &Command) -> Result<()>
Append a command as an NDJSON line to the session file.
Opens the file in append mode and writes a single command line
followed by sync_all() for durability.
§Errors
Returns an error if file opening or writing fails.
Write the session footer as the last line of the NDJSON file.
Opens the file in append mode and writes the footer line
followed by sync_all() for durability.
§Errors
Returns an error if file opening or writing fails.