From 5aecf9951c450d55c83e9e468f1b65aff9c09c5a Mon Sep 17 00:00:00 2001 From: Willow Sparks Date: Sat, 21 Nov 2026 02:05:49 +0000 Subject: [PATCH 1/4] feat(cli): delete saved sessions explicitly --- crates/pa-cli/src/command_registry.rs | 11 + crates/pa-cli/src/daemon_command.rs | 245 +++++++++++++++++- crates/pa-cli/src/daemon_session_list.rs | 23 ++ crates/pa-cli/src/sessions_table_format.rs | 94 ++++++- crates/pa-cli/tests/daemon_commands_e2e.rs | 223 +++++++++++++++- crates/pa-cli/tests/differential_cli.rs | 19 ++ .../native-sessions-delete-help.txt | 12 + .../native-sessions-help.txt | 11 + crates/pa-core/src/session/mod.rs | 1 + crates/pa-core/src/session/storage.rs | 181 +++++++++++++ crates/pa-core/src/session_engine/mod.rs | 5 +- 11 files changed, 805 insertions(+), 20 deletions(-) create mode 100644 crates/pa-cli/tests/fixtures/native-cli-contract/native-sessions-delete-help.txt create mode 100644 crates/pa-cli/tests/fixtures/native-cli-contract/native-sessions-help.txt create mode 100644 crates/pa-core/src/session/storage.rs diff --git a/crates/pa-cli/src/command_registry.rs b/crates/pa-cli/src/command_registry.rs index 39fe99d48..88f56ae02 100644 --- a/crates/pa-cli/src/command_registry.rs +++ b/crates/pa-cli/src/command_registry.rs @@ -66,6 +66,17 @@ pub const COMMAND_SPECS: &[CommandSpec] = &[ "-a, --all Include saved agents", "--json Print JSON", ]), + CommandSpec::new( + &["sessions", "delete"], + "sessions delete [--dry-run] ...", + "Delete saved sessions", + ) + .description( + "Removes each session's artifacts, kernel state, log, and info cache. A live session is \ + refused, and a list with any unknown or live id removes nothing.", + ) + .options(&["--dry-run Show what would be removed without deleting"]) + .examples(&["sessions delete 01a1fb6b-cd31-7694-a622-8cbd0fa54d8d"]), CommandSpec::new( &["attach"], "attach ", diff --git a/crates/pa-cli/src/daemon_command.rs b/crates/pa-cli/src/daemon_command.rs index 3c23393a1..27c20a691 100644 --- a/crates/pa-cli/src/daemon_command.rs +++ b/crates/pa-cli/src/daemon_command.rs @@ -3,16 +3,18 @@ //! request shaping, and output rendering. `schedule` maps to the internal //! `cron` command and `stop` to `kill`. +use std::fs; use std::path::{Path, PathBuf}; use anyhow::{anyhow, bail, Result}; +use pa_core::session::storage::{SessionStorage, SessionStorageSizes}; use pa_types::daemon::DaemonCommand; use serde_json::{json, Value}; use crate::daemon_client::DaemonClient; use crate::daemon_session_list::{ - format_session_list_table, get_session_summaries, live_session_summary, - matches_session_id_suffix, + format_bytes, format_session_list_table, get_session_summaries, live_session_summary, + matches_session_id_suffix, string_field, }; #[derive(Debug)] @@ -182,6 +184,9 @@ fn list_command(all: bool) -> DaemonCommand { /// The same list RPC as `prime-agent list`, rendered as the /// one-line-per-agent operator table. fn run_sessions(client: &mut DaemonClient, args: &[String], json: bool) -> Result<()> { + if args.first().map(String::as_str) == Some("delete") { + return run_sessions_delete(client, &args[1..], json); + } let mut all = false; for arg in args { if arg == "-a" || arg == "--all" { @@ -221,6 +226,212 @@ fn run_sessions(client: &mut DaemonClient, args: &[String], json: bool) -> Resul Ok(()) } +/// The `sessions delete` operands. +#[derive(Debug)] +struct DeleteArgs { + dry_run: bool, + ids: Vec, +} + +/// One preflighted deletion: the resolved storage and the sizes the command +/// reports. Every id is planned before the first unlink, so a bad id in the +/// list cannot leave the earlier ones half-gone. +struct PlannedDeletion { + id: String, + storage: SessionStorage, + sizes: SessionStorageSizes, +} + +fn parse_delete_args(args: &[String]) -> Result { + let mut dry_run = false; + let mut ids: Vec = Vec::new(); + for arg in args { + match arg.as_str() { + "--dry-run" => dry_run = true, + value if value.starts_with('-') => bail!("Unknown sessions delete option: {value}"), + value if !ids.iter().any(|id| id == value) => ids.push(value.to_string()), + _ => {} + } + } + if ids.is_empty() { + bail!("Missing session id. Run \"prime-agent help sessions delete\" for usage."); + } + Ok(DeleteArgs { dry_run, ids }) +} + +fn run_sessions_delete(client: &mut DaemonClient, args: &[String], json: bool) -> Result<()> { + let args = parse_delete_args(args)?; + let live_sessions = daemon_sessions(client.request(list_command(false))?)?; + let live: Vec = args + .ids + .iter() + .filter_map(|id| live_session_refusal(&live_sessions, id)) + .collect(); + if !live.is_empty() { + bail!("{}; nothing was deleted", live.join("; ")); + } + let catalog = daemon_sessions(client.request(list_command(true))?)?; + let planned: Vec = args + .ids + .iter() + .map(|id| plan_deletion(id, &catalog)) + .collect::>()?; + + if args.dry_run { + if json { + print_json(&deletion_json("wouldDelete", &planned)); + return Ok(()); + } + for plan in &planned { + println!( + "would delete: artifacts {}, kernel {}, log {}, cache {} \u{2014} {}", + format_bytes(plan.sizes.artifacts_excluding_kernel()), + format_bytes(plan.sizes.kernel), + format_bytes(plan.sizes.log), + format_bytes(plan.sizes.cache), + format_bytes(plan.sizes.total()), + ); + } + return Ok(()); + } + + for plan in &planned { + delete_storage(&plan.storage)?; + } + if json { + print_json(&deletion_json("deleted", &planned)); + return Ok(()); + } + for plan in &planned { + println!( + "deleted {} \u{2014} log {}, artifacts {}, kernel {}, {} freed", + short_session_id(&plan.id), + format_bytes(plan.sizes.log), + format_bytes(plan.sizes.artifacts_excluding_kernel()), + format_bytes(plan.sizes.kernel), + format_bytes(plan.sizes.total()), + ); + } + Ok(()) +} + +fn daemon_sessions(response: pa_types::daemon::DaemonResponse) -> Result> { + let data = require_success(response)?.unwrap_or(Value::Null); + match data.get("sessions").and_then(Value::as_array).cloned() { + Some(sessions) => Ok(sessions), + None => bail!("Daemon returned an invalid sessions response"), + } +} + +/// A refusal line when the id names a session the daemon still hosts. +fn live_session_refusal(live_sessions: &[Value], id: &str) -> Option { + let row = live_sessions + .iter() + .find(|row| row_matches_session_id(row, id))?; + Some(match row.get("workerPid").and_then(Value::as_u64) { + Some(pid) => format!("Session {id} is live in daemon pid {pid}"), + None => format!("Session {id} is live in a daemon"), + }) +} + +/// The id is the conversation log's stem; the active id and the session id are +/// accepted too so a live row can never hide behind an alias. +fn row_matches_session_id(row: &Value, id: &str) -> bool { + string_field(row, "sessionFile") + .and_then(|path| Path::new(path).file_stem()) + .and_then(|stem| stem.to_str()) + == Some(id) + || ["sessionId", "activeSessionId", "id"] + .iter() + .any(|field| string_field(row, field) == Some(id)) +} + +fn plan_deletion(id: &str, catalog: &[Value]) -> Result { + let row = catalog + .iter() + .find(|row| { + string_field(row, "sessionFile") + .and_then(|path| Path::new(path).file_stem()) + .and_then(|stem| stem.to_str()) + == Some(id) + }) + .ok_or_else(|| anyhow!("Session {id} does not exist"))?; + if let Some(pid) = row.get("workerPid").and_then(Value::as_u64) { + bail!("Session {id} is live in daemon pid {pid}; nothing was deleted"); + } + let session_file = + string_field(row, "sessionFile").ok_or_else(|| anyhow!("Session {id} does not exist"))?; + let storage = SessionStorage::for_log(session_file) + .ok_or_else(|| anyhow!("Session {id} does not exist"))?; + if !storage.log_path().exists() { + bail!("Session {id} does not exist"); + } + let sizes = storage.sizes(); + Ok(PlannedDeletion { + id: id.to_string(), + storage, + sizes, + }) +} + +/// The ticket's order: the artifact partition, then the kernel state it +/// contains, then the log, then the info cache. The log goes last, so an +/// interrupted delete leaves a session that still opens. +fn delete_storage(storage: &SessionStorage) -> Result<()> { + remove_artifacts(storage.artifacts_dir())?; + for path in storage.kernel_state_paths() { + remove_file_if_present(path)?; + } + remove_file_if_present(storage.log_path())?; + remove_file_if_present(storage.cache_path()) +} + +fn remove_artifacts(path: &Path) -> Result<()> { + match fs::symlink_metadata(path) { + Ok(metadata) if metadata.is_dir() => fs::remove_dir_all(path) + .map_err(|error| anyhow!("Failed to remove {}: {error}", path.display())), + Ok(_) => fs::remove_file(path) + .map_err(|error| anyhow!("Failed to remove {}: {error}", path.display())), + Err(error) if error.kind() == std::io::ErrorKind::NotFound => Ok(()), + Err(error) => Err(anyhow!("Failed to inspect {}: {error}", path.display())), + } +} + +fn remove_file_if_present(path: &Path) -> Result<()> { + match fs::symlink_metadata(path) { + Ok(metadata) if metadata.is_file() || metadata.file_type().is_symlink() => { + fs::remove_file(path) + .map_err(|error| anyhow!("Failed to remove {}: {error}", path.display())) + } + Ok(_) => bail!("Refusing to remove {}: it is not a file", path.display()), + Err(error) if error.kind() == std::io::ErrorKind::NotFound => Ok(()), + Err(error) => Err(anyhow!("Failed to inspect {}: {error}", path.display())), + } +} + +fn short_session_id(id: &str) -> &str { + id.get(..8).unwrap_or(id) +} + +fn deletion_json(key: &str, planned: &[PlannedDeletion]) -> Value { + let rows: Vec = planned + .iter() + .map(|plan| { + json!({ + "id": plan.id, + "logBytes": plan.sizes.log, + "artifactBytes": plan.sizes.artifacts_excluding_kernel(), + "kernelBytes": plan.sizes.kernel, + "cacheBytes": plan.sizes.cache, + "freedBytes": plan.sizes.total(), + }) + }) + .collect(); + let mut object = serde_json::Map::new(); + object.insert(key.to_string(), Value::Array(rows)); + Value::Object(object) +} + /// Match a name/id/session-id selector against the live session list, /// with unambiguous hex-suffix fallback. fn resolve_live_session_selector(client: &mut DaemonClient, selector: &str) -> Result { @@ -700,6 +911,36 @@ mod tests { assert!(no_target.is_err()); } + #[test] + fn delete_args_take_ids_in_order_and_reject_unknown_flags() { + let parsed = parse_delete_args(&args(&[ + "--dry-run", + "01a1fb6b-cd31-7694-a622-8cbd0fa54d8d", + "01a1fb6b-cd31-7694-a622-8cbd0fa54d8d", + "01a1fb6b-0000-0000-0000-000000000000", + ])) + .unwrap(); + assert!(parsed.dry_run); + assert_eq!( + parsed.ids, + vec![ + "01a1fb6b-cd31-7694-a622-8cbd0fa54d8d".to_string(), + "01a1fb6b-0000-0000-0000-000000000000".to_string(), + ] + ); + + assert_eq!( + parse_delete_args(&args(&["--all"])) + .unwrap_err() + .to_string(), + "Unknown sessions delete option: --all" + ); + assert_eq!( + parse_delete_args(&args(&[])).unwrap_err().to_string(), + "Missing session id. Run \"prime-agent help sessions delete\" for usage." + ); + } + #[test] fn cron_job_line_matches_captured_ts_golden() { let job = json!({ diff --git a/crates/pa-cli/src/daemon_session_list.rs b/crates/pa-cli/src/daemon_session_list.rs index 5806d28e2..df6963a6d 100644 --- a/crates/pa-cli/src/daemon_session_list.rs +++ b/crates/pa-cli/src/daemon_session_list.rs @@ -6,6 +6,9 @@ use std::time::{SystemTime, UNIX_EPOCH}; const DISPLAY_ID_LENGTH: usize = 12; +/// The byte units [`format_bytes`] scales through. +const BYTE_UNITS: [&str; 4] = ["KB", "MB", "GB", "TB"]; + /// Display order for the status column. const LIST_STATUS_ORDER: [&str; 3] = ["working", "idle", "archived"]; @@ -233,6 +236,26 @@ fn tail(value: &str, length: usize) -> String { } } +/// A byte count at the listing's scale: whole bytes below 1 KiB, then one +/// decimal below ten units and whole units above it. +#[must_use] +pub(crate) fn format_bytes(bytes: u64) -> String { + if bytes < 1024 { + return format!("{bytes} B"); + } + let mut value = bytes as f64 / 1024.0; + let mut unit = 0; + while value >= 1024.0 && unit + 1 < BYTE_UNITS.len() { + value /= 1024.0; + unit += 1; + } + let whole = value.round(); + if value >= 10.0 || (value - whole).abs() < 0.05 { + return format!("{whole:.0} {}", BYTE_UNITS[unit]); + } + format!("{value:.1} {}", BYTE_UNITS[unit]) +} + /// `s|m|h|d|w|y` bucketing from the modified timestamp. pub(crate) fn format_session_age(modified: Option<&str>, now_ms: u64) -> String { let Some(modified) = modified else { diff --git a/crates/pa-cli/src/sessions_table_format.rs b/crates/pa-cli/src/sessions_table_format.rs index 767ad9473..ceaf6211f 100644 --- a/crates/pa-cli/src/sessions_table_format.rs +++ b/crates/pa-cli/src/sessions_table_format.rs @@ -1,8 +1,11 @@ -//! The `prime-agent sessions` operator table: one line per agent — name, -//! status, activity, staleness, last error, usage — from the same daemon -//! `list` summaries, with the activity wording from the shared roster -//! branch table (color-free, like TS piped output). +//! The `prime-agent sessions` operator table: one line per agent — name, id, +//! status, activity, staleness, last error, usage, log size, artifact size — +//! from the same daemon `list` summaries, with the activity wording from the +//! shared roster branch table (color-free, like TS piped output). +use std::path::Path; + +use pa_core::session::storage::{SessionStorage, SessionStorageSizes}; use pa_tui::ansi::strip_ansi; use pa_tui::info_commands::js_to_fixed; use pa_tui::width::truncate_to_width; @@ -12,7 +15,7 @@ use pa_types::daemon::agent_roster::{ use serde_json::Value; use crate::daemon_session_list::{ - format_session_age, format_session_display_id, format_table, string_field, + format_bytes, format_session_age, format_session_display_id, format_table, string_field, }; /// Display-width cap for free-text cells so one long line never stretches the row; wide glyphs @@ -20,17 +23,29 @@ use crate::daemon_session_list::{ const MAX_CELL_CHARS: usize = 60; /// The sessions table's columns. -const SESSIONS_HEADERS: [&str; 6] = ["name", "status", "activity", "last heard", "error", "usage"]; +const SESSIONS_HEADERS: [&str; 9] = [ + "name", + "id", + "status", + "activity", + "last heard", + "error", + "usage", + "size", + "artifacts", +]; /// One-line-per-agent operator table for `prime-agent sessions`. pub(crate) fn format_sessions_table(sessions: &[&Value], now_ms: u64) -> String { let mut sorted = sessions.to_vec(); sorted.sort_by_key(|summary| sessions_sort_key(summary)); - let rows: Vec<[String; 6]> = sorted + let rows: Vec<[String; 9]> = sorted .iter() .map(|summary| { + let storage_sizes = session_storage_sizes(summary); [ truncate_cell(&session_name_cell(summary)), + session_id_cell(summary), sessions_status_label(summary).to_string(), truncate_cell(&session_activity_cell(summary)), // lastHeardFromAt is the supervisor's staleness mark, served only when a worker's @@ -38,6 +53,9 @@ pub(crate) fn format_sessions_table(sessions: &[&Value], now_ms: u64) -> String format_session_age(string_field(summary, "lastHeardFromAt"), now_ms), truncate_cell(&session_error_cell(summary).unwrap_or_default()), format_usage_cell(summary.get("usage")), + storage_sizes.map_or_else(String::new, |sizes| format_bytes(sizes.log)), + storage_sizes + .map_or_else(String::new, |sizes| format_bytes(sizes.artifact_directory)), ] }) .collect(); @@ -102,6 +120,23 @@ fn session_activity_cell(summary: &Value) -> String { .join(" \u{b7} ") } +/// The id cell: the conversation log's stem. Only a file-backed row has an +/// id, and that full id is what `sessions delete` accepts. +fn session_id_cell(summary: &Value) -> String { + string_field(summary, "sessionFile") + .and_then(|path| Path::new(path).file_stem()) + .and_then(|stem| stem.to_str()) + .unwrap_or_default() + .to_string() +} + +/// The size cells: the log file and the whole artifact partition, the same +/// figures the delete surface reports. +fn session_storage_sizes(summary: &Value) -> Option { + let path = string_field(summary, "sessionFile")?; + SessionStorage::for_log(path).map(|storage| storage.sizes()) +} + /// The name cell: names are user-provided; sanitize them and fall back /// to the display id when sanitizing leaves nothing. /// @@ -247,9 +282,13 @@ mod tests { /// The exact-row harness (TS `expectTable`): the rendered table must be the expected rows /// padded to their own widest cell. fn expect_table(case: &str, sessions: &[Value], expected_rows: &[[&str; 6]]) { + let expected_rows: Vec<[&str; 9]> = expected_rows + .iter() + .map(|row| [row[0], "", row[1], row[2], row[3], row[4], row[5], "", ""]) + .collect(); let rows: Vec<&Value> = sessions.iter().collect(); let table = format_sessions_table(&rows, NOW_MS); - let widths: [usize; 6] = std::array::from_fn(|column| { + let widths: [usize; 9] = std::array::from_fn(|column| { str_width(SESSIONS_HEADERS[column]).max( expected_rows .iter() @@ -258,7 +297,7 @@ mod tests { .unwrap_or(0), ) }); - let pad = |row: [&str; 6]| { + let pad = |row: [&str; 9]| { row.iter() .enumerate() .map(|(column, cell)| { @@ -455,6 +494,41 @@ mod tests { ); } + #[test] + fn byte_sizes_use_the_listing_scale() { + assert_eq!(format_bytes(0), "0 B"); + assert_eq!(format_bytes(1023), "1023 B"); + assert_eq!(format_bytes(1024), "1 KB"); + assert_eq!(format_bytes(5 * 1024), "5 KB"); + assert_eq!(format_bytes(2_200_000), "2.1 MB"); + assert_eq!(format_bytes(60 * 1024 * 1024), "60 MB"); + assert_eq!(format_bytes(3 * 1024 * 1024 * 1024), "3 GB"); + } + + #[test] + fn id_size_and_artifacts_cells_read_the_session_storage() { + let root = tempfile::tempdir().unwrap(); + let sessions = root.path().join("sessions"); + std::fs::create_dir_all(&sessions).unwrap(); + let id = "01a1fb6b-cd31-7694-a622-8cbd0fa54d8d"; + let log = sessions.join(format!("{id}.jsonl")); + std::fs::write(&log, vec![0_u8; 2048]).unwrap(); + let artifacts = root.path().join("session-artifacts").join(id); + std::fs::create_dir_all(&artifacts).unwrap(); + std::fs::write(artifacts.join("kernel-state.dill"), vec![0_u8; 1024]).unwrap(); + std::fs::write(artifacts.join("data.bin"), vec![0_u8; 4096]).unwrap(); + + let summary = make_summary(json!({ "sessionFile": log.to_string_lossy() })); + let rows: Vec<&Value> = vec![&summary]; + let table = format_sessions_table(&rows, NOW_MS); + let lines: Vec<&str> = table.lines().collect(); + assert!(lines[0].contains("size"), "{lines:?}"); + assert!(lines[0].contains("artifacts"), "{lines:?}"); + assert!(lines[1].contains(id), "{lines:?}"); + assert!(lines[1].contains("2 KB"), "{lines:?}"); + assert!(lines[1].contains("5 KB"), "{lines:?}"); + } + #[test] fn measures_wide_glyph_cells_by_display_width() { let sessions = [ @@ -469,7 +543,7 @@ mod tests { let lines: Vec<&str> = table.lines().collect(); // Scalar-length padding would misalign the CJK name; the recap cap counts display columns, // pair-safe. - assert!(lines[1].starts_with("中文 idle"), "{lines:?}"); + assert!(lines[1].starts_with("中文 idle"), "{lines:?}"); assert!( lines[2].contains(&format!("{}…", "\u{1f680}".repeat(29))), "{lines:?}" diff --git a/crates/pa-cli/tests/daemon_commands_e2e.rs b/crates/pa-cli/tests/daemon_commands_e2e.rs index 2a8970cae..a61f6f0fc 100644 --- a/crates/pa-cli/tests/daemon_commands_e2e.rs +++ b/crates/pa-cli/tests/daemon_commands_e2e.rs @@ -587,8 +587,8 @@ fn rust_daemon_cli_commands_end_to_end() { assert!(row.get(key).is_some(), "summary row must carry {key}"); } - // Golden: the sessions operator table over the live session (TS binary - // shape): the last-heard, activity, error, and usage cells stay empty for + // The sessions operator table adds the file-backed id and the size + // columns; the last-heard, activity, error, and usage cells stay empty for // a healthy idle session. let sessions_table = run_cli( &cli, @@ -602,11 +602,27 @@ fn rust_daemon_cli_commands_end_to_end() { "{}", stderr(&sessions_table) ); + let sessions_text = stdout(&sessions_table); + let sessions_header = sessions_text.lines().next().expect("header"); assert_eq!( - normalize(&stdout(&sessions_table)), - "name status activity last heard error usage\nparity idle\n", - "sessions table shape must match the TS golden" + sessions_header.split_whitespace().collect::>(), + [ + "name", + "id", + "status", + "activity", + "last", + "heard", + "error", + "usage", + "size", + "artifacts" + ], + "{sessions_text}" ); + let sessions_row = sessions_text.lines().nth(1).expect("live row"); + assert!(sessions_row.starts_with("parity"), "{sessions_text}"); + assert!(sessions_row.contains("idle"), "{sessions_text}"); // The sessions --json dump is the same list RPC data (the sessions // command reuses it). @@ -694,6 +710,203 @@ fn rust_daemon_cli_commands_end_to_end() { assert_eq!(stdout(&send_wake), "Sent to renamed\n"); } +/// The full session id behind one saved or live listing row. +fn session_file_stem(row: &Value) -> String { + Path::new(row["sessionFile"].as_str().expect("sessionFile")) + .file_stem() + .and_then(|stem| stem.to_str()) + .expect("session file stem") + .to_string() +} + +#[test] +fn sessions_delete_is_all_or_nothing_and_reports_the_freed_bytes() { + let dir = tempfile::TempDir::new().expect("temp dir"); + let agent_dir = dir.path().join("agent"); + let sessions = agent_dir.join("sessions"); + std::fs::create_dir_all(&sessions).expect("sessions dir"); + let socket = dir.path().join("daemon.sock"); + let cli = PathBuf::from(env!("CARGO_BIN_EXE_prime-agent")); + let daemon = spawn_daemon(&daemon_binary(), &socket, &agent_dir); + let socket_str = socket.to_string_lossy().to_string(); + + let script = dir.path().join("delete-script.json"); + std::fs::write(&script, json!({ "responses": [] }).to_string()).expect("write script"); + let (mut wire, _hello) = Wire::connect(&daemon.socket); + let keeper = create_session( + &mut wire, + "c-keeper", + "keeper", + dir.path(), + &sessions, + Some(&script), + ); + let doomed = create_session( + &mut wire, + "c-doomed", + "doomed", + dir.path(), + &sessions, + Some(&script), + ); + drop(wire); + + let sessions_json = || -> Value { + let output = run_cli( + &cli, + dir.path(), + &agent_dir, + &list_args(&socket_str, &["sessions", "--all", "--json"]), + ); + assert_eq!(output.status.code(), Some(0), "{}", stderr(&output)); + serde_json::from_str(&stdout(&output)).expect("valid sessions json") + }; + let rows = sessions_json(); + let rows = rows["sessions"].as_array().expect("session rows"); + let keeper_row = rows + .iter() + .find(|row| row["sessionName"] == "keeper") + .expect("keeper row"); + let doomed_row = rows + .iter() + .find(|row| row["sessionName"] == "doomed") + .expect("doomed row"); + let keeper_id = session_file_stem(keeper_row); + let doomed_id = session_file_stem(doomed_row); + let live_pid = keeper_row["workerPid"].as_u64().expect("live worker pid"); + let doomed_log = sessions.join(format!("{doomed_id}.jsonl")); + assert!(doomed_log.exists(), "created session log"); + + let stop = run_cli( + &cli, + dir.path(), + &agent_dir, + &list_args(&socket_str, &["stop", doomed.as_str()]), + ); + assert_eq!(stop.status.code(), Some(0), "{}", stderr(&stop)); + + let artifacts = agent_dir.join("session-artifacts").join(&doomed_id); + let _ = std::fs::remove_dir_all(&artifacts); + std::fs::create_dir_all(&artifacts).expect("artifact partition"); + std::fs::write(artifacts.join("data.bin"), [0_u8; 1]).expect("artifact file"); + std::fs::write(artifacts.join("kernel-state.dill"), [0_u8; 2]).expect("kernel state"); + std::fs::write(artifacts.join("kernel-state.json"), [0_u8; 1]).expect("kernel manifest"); + let cache = sessions.join(format!("{doomed_id}.info-cache.json")); + + let dry_run = run_cli( + &cli, + dir.path(), + &agent_dir, + &list_args( + &socket_str, + &["sessions", "delete", "--dry-run", doomed_id.as_str()], + ), + ); + assert_eq!(dry_run.status.code(), Some(0), "{}", stderr(&dry_run)); + let dry_text = stdout(&dry_run); + assert!( + dry_text.starts_with("would delete: artifacts 1 B, kernel 3 B, log "), + "{dry_text}" + ); + assert!(dry_text.contains(", cache "), "{dry_text}"); + assert!(doomed_log.exists(), "dry run removes nothing"); + assert!(artifacts.exists(), "dry run removes nothing"); + + let live = run_cli( + &cli, + dir.path(), + &agent_dir, + &list_args(&socket_str, &["sessions", "delete", keeper_id.as_str()]), + ); + assert_eq!(live.status.code(), Some(1)); + assert_eq!( + stderr(&live), + format!( + "Error: Session {keeper_id} is live in daemon pid {live_pid}; nothing was deleted\n" + ) + ); + + let mixed = run_cli( + &cli, + dir.path(), + &agent_dir, + &list_args( + &socket_str, + &["sessions", "delete", doomed_id.as_str(), keeper_id.as_str()], + ), + ); + assert_eq!(mixed.status.code(), Some(1)); + assert!( + stderr(&mixed).contains("is live in daemon pid"), + "{}", + stderr(&mixed) + ); + assert!(doomed_log.exists(), "a live id in the list removes nothing"); + assert!(artifacts.exists(), "a live id in the list removes nothing"); + + let unknown = run_cli( + &cli, + dir.path(), + &agent_dir, + &list_args( + &socket_str, + &[ + "sessions", + "delete", + doomed_id.as_str(), + "01a1fb6b-0000-0000-0000-000000000000", + ], + ), + ); + assert_eq!(unknown.status.code(), Some(1)); + assert_eq!( + stderr(&unknown), + "Error: Session 01a1fb6b-0000-0000-0000-000000000000 does not exist\n" + ); + assert!(doomed_log.exists(), "an unknown id removes nothing"); + assert!(artifacts.exists(), "an unknown id removes nothing"); + + let delete = run_cli( + &cli, + dir.path(), + &agent_dir, + &list_args(&socket_str, &["sessions", "delete", doomed_id.as_str()]), + ); + assert_eq!(delete.status.code(), Some(0), "{}", stderr(&delete)); + let delete_text = stdout(&delete); + assert!( + delete_text.starts_with(&format!("deleted {} \u{2014} log ", &doomed_id[..8])), + "{delete_text}" + ); + assert!(delete_text.ends_with(" freed\n"), "{delete_text}"); + assert!(!doomed_log.exists(), "log removed"); + assert!(!artifacts.exists(), "artifact partition removed"); + assert!(!cache.exists(), "info cache removed"); + assert!( + sessions.join(format!("{keeper_id}.jsonl")).exists(), + "the live session is untouched" + ); + let dry_total = dry_text + .trim() + .rsplit(" \u{2014} ") + .next() + .expect("dry total"); + let delete_total = delete_text + .trim() + .strip_suffix(" freed") + .and_then(|line| line.rsplit(", ").next()) + .expect("real total"); + assert_eq!(dry_total, delete_total, "dry run reports the real total"); + + let stop = run_cli( + &cli, + dir.path(), + &agent_dir, + &list_args(&socket_str, &["stop", keeper.as_str()]), + ); + assert_eq!(stop.status.code(), Some(0), "{}", stderr(&stop)); +} + #[test] fn cli_connect_error_matches_ts_golden() { let dir = tempfile::TempDir::new().expect("temp dir"); diff --git a/crates/pa-cli/tests/differential_cli.rs b/crates/pa-cli/tests/differential_cli.rs index a28c78093..132e3050d 100644 --- a/crates/pa-cli/tests/differential_cli.rs +++ b/crates/pa-cli/tests/differential_cli.rs @@ -33,6 +33,7 @@ const CORPUS: &[&[&str]] = &[ &["help", "agents"], &["help", "list"], &["help", "sessions"], + &["help", "sessions", "delete"], &["help", "attach"], &["help", "stop"], &["help", "rename"], @@ -515,6 +516,22 @@ fn declared_native_contract( ts.is_none_or(|ts| declared_output_matches(ts, 0, include_str!("fixtures/native-cli-contract/ts-update-help.txt"), "", roots)) && declared_output_matches(native, 0, include_str!("fixtures/native-cli-contract/native-update-help.txt"), "", roots), ), + // A fork-only child: the TS sessions help has no `delete` command, so + // only the native side has a declared shape to pin. + ["help", "sessions"] => Some(declared_output_matches( + native, + 0, + include_str!("fixtures/native-cli-contract/native-sessions-help.txt"), + "", + roots, + )), + ["help", "sessions", "delete"] => Some(declared_output_matches( + native, + 0, + include_str!("fixtures/native-cli-contract/native-sessions-delete-help.txt"), + "", + roots, + )), ["--mode", "rpc" | "daemon", "@file.txt"] => Some( ts.is_none_or(|ts| declared_output_matches(ts, 1, "", "Error: @file arguments are not supported in RPC or daemon mode\n", roots)) && declared_output_matches(native, 1, "", "Error: @file arguments are not supported in RPC, daemon, or ACP mode\n", roots), @@ -579,6 +596,8 @@ fn native_cli_contract_fixtures() { &["help"], &["help", "package"], &["help", "update"], + &["help", "sessions"], + &["help", "sessions", "delete"], &["--mode", "rpc", "@file.txt"], &["--mode", "daemon", "@file.txt"], &["model", "list", "--json"], diff --git a/crates/pa-cli/tests/fixtures/native-cli-contract/native-sessions-delete-help.txt b/crates/pa-cli/tests/fixtures/native-cli-contract/native-sessions-delete-help.txt new file mode 100644 index 000000000..54ce92c46 --- /dev/null +++ b/crates/pa-cli/tests/fixtures/native-cli-contract/native-sessions-delete-help.txt @@ -0,0 +1,12 @@ +Usage: + prime-agent sessions delete [--dry-run] ... + +Delete saved sessions. + +Removes each session's artifacts, kernel state, log, and info cache. A live session is refused, and a list with any unknown or live id removes nothing. + +Options: + --dry-run Show what would be removed without deleting + +Examples: + prime-agent sessions delete 01a1fb6b-cd31-7694-a622-8cbd0fa54d8d diff --git a/crates/pa-cli/tests/fixtures/native-cli-contract/native-sessions-help.txt b/crates/pa-cli/tests/fixtures/native-cli-contract/native-sessions-help.txt new file mode 100644 index 000000000..af98e93d2 --- /dev/null +++ b/crates/pa-cli/tests/fixtures/native-cli-contract/native-sessions-help.txt @@ -0,0 +1,11 @@ +Usage: + prime-agent sessions [--all] [--json] + +Show agent status, activity, and usage. + +Commands: + delete Delete saved sessions + +Options: + -a, --all Include saved agents + --json Print JSON diff --git a/crates/pa-core/src/session/mod.rs b/crates/pa-core/src/session/mod.rs index 100e480d1..90c132396 100644 --- a/crates/pa-core/src/session/mod.rs +++ b/crates/pa-core/src/session/mod.rs @@ -4,6 +4,7 @@ pub mod manager; pub mod manager_ext; pub mod metadata; pub mod read; +pub mod storage; pub mod tree; pub mod window; mod window_cache; diff --git a/crates/pa-core/src/session/storage.rs b/crates/pa-core/src/session/storage.rs new file mode 100644 index 000000000..5ff75d74b --- /dev/null +++ b/crates/pa-core/src/session/storage.rs @@ -0,0 +1,181 @@ +//! A session's on-disk storage: the conversation log, the artifact partition beside it, +//! the kernel snapshot inside that partition, and the info-cache sidecar. + +use std::fs; +use std::path::{Path, PathBuf}; + +use crate::kernel::{manifest_path_in, snapshot_path_in}; + +/// The byte footprint of one session's storage. +/// +/// `artifact_directory` is the whole partition, kernel state included. The +/// kernel snapshot is reported separately because the delete surface names it +/// as its own step; subtracting it from the partition keeps the reported +/// figures additive instead of counting it twice. +#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)] +pub struct SessionStorageSizes { + pub log: u64, + pub artifact_directory: u64, + pub kernel: u64, + pub cache: u64, +} + +impl SessionStorageSizes { + /// The artifact partition without the kernel snapshot it contains. + #[must_use] + pub fn artifacts_excluding_kernel(&self) -> u64 { + self.artifact_directory.saturating_sub(self.kernel) + } + + /// Every byte the delete frees, with the kernel snapshot counted once. + #[must_use] + pub fn total(&self) -> u64 { + self.log + .saturating_add(self.artifact_directory) + .saturating_add(self.cache) + } +} + +/// The files a saved session owns: `.jsonl`, `.info-cache.json`, the +/// `/session-artifacts/` partition, and the kernel snapshot files in +/// that partition. +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct SessionStorage { + log: PathBuf, + artifacts: PathBuf, + kernel_state: Vec, + cache: PathBuf, +} + +impl SessionStorage { + /// Resolve the storage beside a conversation log, or `None` when the log + /// has no id or no directory pair to hold the artifact partition. + #[must_use] + pub fn for_log(log: impl AsRef) -> Option { + let log = log.as_ref(); + let id = log + .file_stem() + .and_then(|stem| stem.to_str()) + .filter(|id| !id.is_empty())?; + let artifacts = log.parent()?.parent()?.join("session-artifacts").join(id); + let cache = log.with_file_name(format!("{id}.info-cache.json")); + let kernel_state = vec![snapshot_path_in(&artifacts), manifest_path_in(&artifacts)]; + Some(Self { + log: log.to_path_buf(), + artifacts, + kernel_state, + cache, + }) + } + + #[must_use] + pub fn log_path(&self) -> &Path { + &self.log + } + + #[must_use] + pub fn artifacts_dir(&self) -> &Path { + &self.artifacts + } + + #[must_use] + pub fn kernel_state_paths(&self) -> &[PathBuf] { + &self.kernel_state + } + + #[must_use] + pub fn cache_path(&self) -> &Path { + &self.cache + } + + /// Measure the storage. Missing paths measure zero, and symbolic links are + /// never followed: the delete removes the link, not its target. + #[must_use] + pub fn sizes(&self) -> SessionStorageSizes { + let artifact_directory = directory_bytes(&self.artifacts); + SessionStorageSizes { + log: file_bytes(&self.log), + artifact_directory, + kernel: self.kernel_state.iter().map(|path| file_bytes(path)).sum(), + cache: file_bytes(&self.cache), + } + } +} + +fn file_bytes(path: &Path) -> u64 { + fs::symlink_metadata(path) + .ok() + .filter(std::fs::Metadata::is_file) + .map_or(0, |metadata| metadata.len()) +} + +fn directory_bytes(path: &Path) -> u64 { + let Ok(entries) = fs::read_dir(path) else { + return 0; + }; + entries + .flatten() + .map(|entry| { + let path = entry.path(); + let Ok(metadata) = fs::symlink_metadata(&path) else { + return 0; + }; + if metadata.is_dir() { + directory_bytes(&path) + } else if metadata.is_file() { + metadata.len() + } else { + 0 + } + }) + .sum() +} + +#[cfg(test)] +mod tests { + use super::*; + + const ID: &str = "01a1fb6b-cd31-7694-a622-8cbd0fa54d8d"; + + #[test] + fn sizes_split_the_artifact_directory_from_its_kernel_snapshot() { + let root = tempfile::tempdir().unwrap(); + let sessions = root.path().join("sessions"); + let log = sessions.join(format!("{ID}.jsonl")); + fs::create_dir_all(&sessions).unwrap(); + fs::write(&log, [0u8; 3]).unwrap(); + let artifacts = root.path().join("session-artifacts").join(ID); + fs::create_dir_all(artifacts.join("sub")).unwrap(); + fs::write(artifacts.join("kernel-state.dill"), [0u8; 30]).unwrap(); + fs::write(artifacts.join("kernel-state.json"), [0u8; 5]).unwrap(); + fs::write(artifacts.join("data.bin"), [0u8; 100]).unwrap(); + fs::write(artifacts.join("sub").join("more.bin"), [0u8; 50]).unwrap(); + let cache = sessions.join(format!("{ID}.info-cache.json")); + fs::write(&cache, [0u8; 7]).unwrap(); + + let storage = SessionStorage::for_log(&log).expect("storage"); + assert_eq!(storage.log_path(), log.as_path()); + assert_eq!(storage.artifacts_dir(), artifacts.as_path()); + assert_eq!(storage.cache_path(), cache.as_path()); + assert_eq!( + storage.sizes(), + SessionStorageSizes { + log: 3, + artifact_directory: 185, + kernel: 35, + cache: 7, + } + ); + let sizes = storage.sizes(); + assert_eq!(sizes.artifacts_excluding_kernel(), 150); + assert_eq!(sizes.total(), 195); + } + + #[test] + fn absent_storage_measures_zero() { + let root = tempfile::tempdir().unwrap(); + let log = root.path().join("sessions").join(format!("{ID}.jsonl")); + let storage = SessionStorage::for_log(&log).expect("storage"); + assert_eq!(storage.sizes(), SessionStorageSizes::default()); + } +} diff --git a/crates/pa-core/src/session_engine/mod.rs b/crates/pa-core/src/session_engine/mod.rs index 5df99682b..e9be93a5e 100644 --- a/crates/pa-core/src/session_engine/mod.rs +++ b/crates/pa-core/src/session_engine/mod.rs @@ -818,9 +818,8 @@ pub(crate) fn session_message_to_loop(message: &SessionAgentMessage) -> Option`). #[must_use] pub fn session_artifact_dir_for_log(log: &std::path::Path) -> Option { - let id = log.file_stem()?.to_string_lossy().to_string(); - let artifacts_root = log.parent()?.parent()?.join("session-artifacts"); - Some(artifacts_root.join(id)) + crate::session::storage::SessionStorage::for_log(log) + .map(|storage| storage.artifacts_dir().to_path_buf()) } /// Rows that fail the conversion drop. -- knotmirror 0.0.1 From 57fdcc307de5357818c6d0332816d4ad809a604a Mon Sep 17 00:00:00 2001 From: Willow Sparks Date: Sat, 21 Nov 2026 02:30:36 +0000 Subject: [PATCH 2/4] test(cli): pin the native sessions table shape --- crates/pa-cli/tests/daemon_commands_e2e.rs | 149 +++++++++++++++++++-- 1 file changed, 141 insertions(+), 8 deletions(-) diff --git a/crates/pa-cli/tests/daemon_commands_e2e.rs b/crates/pa-cli/tests/daemon_commands_e2e.rs index a61f6f0fc..48d1dac97 100644 --- a/crates/pa-cli/tests/daemon_commands_e2e.rs +++ b/crates/pa-cli/tests/daemon_commands_e2e.rs @@ -420,6 +420,111 @@ impl CliPair { } } + /// The sessions operator table is a declared native extension (ticket #70): + /// Rust adds the file-backed `id`, `size`, and `artifacts` cells after the + /// TS columns. Compare the shared shape and the native cells instead of + /// byte equality. + fn compare_sessions_table(&self, failures: &mut Vec, args: &[&str], label: &str) { + let ts_out = run_cli(&self.ts, &self.dir, &self.ts_agent_dir, args); + let rs_out = run_cli(&self.rust, &self.dir, &self.rust_agent_dir, args); + let ts_text = stdout(&ts_out); + let rs_text = stdout(&rs_out); + let ts_header: Vec<&str> = ts_text + .lines() + .next() + .unwrap_or_default() + .split_whitespace() + .collect(); + let rs_header: Vec<&str> = rs_text + .lines() + .next() + .unwrap_or_default() + .split_whitespace() + .collect(); + let ts_columns = [ + "name", "status", "activity", "last", "heard", "error", "usage", + ]; + let rust_columns = [ + "name", + "id", + "status", + "activity", + "last", + "heard", + "error", + "usage", + "size", + "artifacts", + ]; + let mut problems = Vec::new(); + if ts_out.status.code() != Some(0) || !stderr(&ts_out).is_empty() { + problems.push(format!( + "ts exit {:?} stderr {:?}", + ts_out.status.code(), + stderr(&ts_out) + )); + } + if rs_out.status.code() != Some(0) || !stderr(&rs_out).is_empty() { + problems.push(format!( + "rs exit {:?} stderr {:?}", + rs_out.status.code(), + stderr(&rs_out) + )); + } + if ts_header != ts_columns { + problems.push(format!("ts header {ts_header:?}")); + } + if rs_header != rust_columns { + problems.push(format!("rs header {rs_header:?}")); + } + let ts_rows: Vec<&str> = ts_text + .lines() + .skip(1) + .filter(|line| !line.trim().is_empty()) + .collect(); + let rs_rows: Vec<&str> = rs_text + .lines() + .skip(1) + .filter(|line| !line.trim().is_empty()) + .collect(); + if ts_rows.len() != rs_rows.len() { + problems.push(format!( + "row count ts {} rs {}", + ts_rows.len(), + rs_rows.len() + )); + } + for (ts_row, rs_row) in ts_rows.iter().zip(&rs_rows) { + let ts_fields: Vec<&str> = ts_row.split_whitespace().collect(); + let fields: Vec<&str> = rs_row.split_whitespace().collect(); + let id_ok = fields + .get(1) + .is_some_and(|id| id.len() == 36 && id.chars().filter(|c| *c == '-').count() == 4); + if !id_ok { + problems.push(format!("row id {rs_row:?}")); + continue; + } + let tail = fields.len().saturating_sub(4); + let bytes_ok = fields.len() >= 6 + && matches!(fields[tail + 1], "B" | "KB" | "MB" | "GB" | "TB") + && matches!(fields[tail + 3], "B" | "KB" | "MB" | "GB" | "TB"); + if !bytes_ok { + problems.push(format!("row sizes {rs_row:?}")); + continue; + } + let mut shared = vec![fields[0]]; + shared.extend_from_slice(&fields[2..tail]); + if shared != ts_fields { + problems.push(format!( + "shared cells {shared:?} vs ts {ts_fields:?} in {rs_row:?}" + )); + } + } + if !problems.is_empty() { + failures.push(format!("{label}:\n {}", problems.join("\n "))); + } + } + /// JSON contains actual owner IDs and paths. Each CLI must preserve its own /// server's full payload rather than inventing cross-owner identities. fn compare_rpc_json( @@ -793,6 +898,39 @@ fn sessions_delete_is_all_or_nothing_and_reports_the_freed_bytes() { std::fs::write(artifacts.join("kernel-state.json"), [0_u8; 1]).expect("kernel manifest"); let cache = sessions.join(format!("{doomed_id}.info-cache.json")); + let table = run_cli( + &cli, + dir.path(), + &agent_dir, + &list_args(&socket_str, &["sessions", "--all"]), + ); + assert_eq!(table.status.code(), Some(0), "{}", stderr(&table)); + let table = stdout(&table); + assert_eq!( + table + .lines() + .next() + .unwrap_or_default() + .split_whitespace() + .collect::>(), + [ + "name", + "id", + "status", + "activity", + "last", + "heard", + "error", + "usage", + "size", + "artifacts" + ], + "{table}" + ); + for id in [&keeper_id, &doomed_id] { + assert!(table.contains(id.as_str()), "{table}"); + } + let dry_run = run_cli( &cli, dir.path(), @@ -1253,16 +1391,11 @@ fn ts_daemon_differential_cli_output() { ); // The sessions operator table (TS #2422): the same list RPC as the one-line table. - compare( - &mut failures, - &["sessions"], - &["sessions"], - "sessions table", - ); - compare( + // Ticket #70 adds the file-backed id/size/artifacts cells to the Rust table. + pair.compare_sessions_table(&mut failures, &["sessions"], "sessions table"); + pair.compare_sessions_table( &mut failures, &["sessions", "--all"], - &["sessions", "--all"], "sessions table --all", ); compare( -- knotmirror 0.0.1 From cb851dcbdcd52740eab1003ef8a6a121b773a28f Mon Sep 17 00:00:00 2001 From: Willow Sparks Date: Sat, 21 Nov 2026 02:33:42 +0000 Subject: [PATCH 3/4] test(cli): normalize the sessions table differential --- crates/pa-cli/tests/daemon_commands_e2e.rs | 8 +++++--- crates/pa-cli/tests/differential_cli.rs | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/crates/pa-cli/tests/daemon_commands_e2e.rs b/crates/pa-cli/tests/daemon_commands_e2e.rs index 48d1dac97..c0b89c00d 100644 --- a/crates/pa-cli/tests/daemon_commands_e2e.rs +++ b/crates/pa-cli/tests/daemon_commands_e2e.rs @@ -495,7 +495,9 @@ impl CliPair { )); } for (ts_row, rs_row) in ts_rows.iter().zip(&rs_rows) { - let ts_fields: Vec<&str> = ts_row.split_whitespace().collect(); + // Shared cells carry ages and unnamed display ids; fold them the + // same way `compare` does, but keep the native id check raw. + let ts_fields: Vec = ts_row.split_whitespace().map(normalize_token).collect(); let fields: Vec<&str> = rs_row.split_whitespace().collect(); let id_ok = fields .get(1) @@ -512,8 +514,8 @@ impl CliPair { problems.push(format!("row sizes {rs_row:?}")); continue; } - let mut shared = vec![fields[0]]; - shared.extend_from_slice(&fields[2..tail]); + let mut shared = vec![normalize_token(fields[0])]; + shared.extend(fields[2..tail].iter().copied().map(normalize_token)); if shared != ts_fields { problems.push(format!( "shared cells {shared:?} vs ts {ts_fields:?} in {rs_row:?}" diff --git a/crates/pa-cli/tests/differential_cli.rs b/crates/pa-cli/tests/differential_cli.rs index 132e3050d..23662b7d2 100644 --- a/crates/pa-cli/tests/differential_cli.rs +++ b/crates/pa-cli/tests/differential_cli.rs @@ -460,9 +460,11 @@ fn sandbox(prefix: &str) -> PathBuf { } // These are declared native contracts, not stream fallbacks. Help snapshots are -// derived from each command registry and its formatter. Native update/package -// behavior is documented in docs/legacy-upgrade-contract.md. args.rs tests pin -// bounded u32 and unknown-option validation; model list declares only [search], +// derived from each command registry and its formatter. The `sessions` table +// appends native id/size/artifacts cells; its daemon e2e compares shared cells. +// Native update/package behavior is documented in +// docs/legacy-upgrade-contract.md. args.rs tests pin bounded u32 and +// unknown-option validation; model list declares only [search], // not a --json option. ACP shares the native non-interactive @file rejection. // TypeScript reference: archive/typescript-2026-10-18, commit // 239dbe344fcaf671af9898906ff952be73995614. -- knotmirror 0.0.1 From eaa1bdf38ce3639a34db4a6b67005a0f3c130d75 Mon Sep 17 00:00:00 2001 From: Willow Sparks Date: Sat, 21 Nov 2026 02:33:42 +0000 Subject: [PATCH 4/4] docs(changes): note the sessions delete command --- .changes/sessions-delete.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .changes/sessions-delete.md diff --git a/.changes/sessions-delete.md b/.changes/sessions-delete.md new file mode 100644 index 000000000..6ee57c9db --- /dev/null +++ b/.changes/sessions-delete.md @@ -0,0 +1,2 @@ +- `prime-agent sessions delete [--dry-run] ...` removes a saved session's artifacts, kernel state, log, and info cache, refuses any live session, and removes nothing if any id in the list is live or unknown. +- `prime-agent sessions -a` shows each session's file-backed id, log size, and artifact directory size beside the existing status columns. -- knotmirror 0.0.1