From 84c1fc1af9c18dd54b832dbf24e3a65ea5350402 Mon Sep 17 00:00:00 2001 From: ualtinok <94532+ualtinok@users.noreply.github.com> Date: Wed, 18 Nov 2026 01:12:33 +0100 Subject: [PATCH 01/26] mason: freeze withdrawals for provably gone tasks Reuse startup recovery's PID/start-time probe and Linux scope adoption without changing recovery's existing boolean decisions. Missing-registry withdrawals freeze only after a terminal record or proven process death; live and uncheckable identities remain refused. Keep withdraw_incomplete and its current detail unchanged: pinned tool-provider 0.15.10 does not classify transient as retryable. Retry-code changes await an upstream provider contract update. Co-authored-by: alfonso-aft <289616620+alfonso-aft@users.noreply.github.com> --- crates/aft/src/bash_background/process.rs | 103 ++++++++++++--- crates/aft/src/bash_background/registry.rs | 100 +++++++++++---- crates/aft/src/db/bash_tasks.rs | 17 +-- crates/aft/src/subc/tool_provider.rs | 138 +++++++++++++++++++-- 4 files changed, 303 insertions(+), 55 deletions(-) diff --git a/crates/aft/src/bash_background/process.rs b/crates/aft/src/bash_background/process.rs index 9ea2f84ba2..05a6543345 100644 --- a/crates/aft/src/bash_background/process.rs +++ b/crates/aft/src/bash_background/process.rs @@ -1044,20 +1044,40 @@ pub fn terminate_pid(pid: u32) { .status(); } -#[cfg(unix)] +/// A failed identity probe is not evidence that a task has stopped. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub(crate) enum ProcessLiveness { + Gone, + Alive, + Unknown, +} + pub fn is_process_alive(pid: u32) -> bool { + probe_process(pid).1 +} + +// The second value is recovery's boolean: OS probe errors remain false. +// A live PID with an unreadable start time is kept alive by the recorded probe below. +#[cfg(unix)] +fn probe_process(pid: u32) -> (ProcessLiveness, bool) { let Ok(pid) = i32::try_from(pid) else { - return false; + return (ProcessLiveness::Unknown, false); }; if pid <= 0 { - return false; + return (ProcessLiveness::Unknown, false); + } + if unsafe { libc::kill(pid, 0) == 0 } { + return (ProcessLiveness::Alive, true); + } + match std::io::Error::last_os_error().raw_os_error() { + Some(libc::EPERM) => (ProcessLiveness::Alive, true), + Some(libc::ESRCH) => (ProcessLiveness::Gone, false), + _ => (ProcessLiveness::Unknown, false), } - (unsafe { libc::kill(pid, 0) == 0 }) - || std::io::Error::last_os_error().raw_os_error() == Some(libc::EPERM) } #[cfg(windows)] -pub fn is_process_alive(pid: u32) -> bool { +fn probe_process(pid: u32) -> (ProcessLiveness, bool) { use std::ffi::c_void; type Handle = *mut c_void; @@ -1073,18 +1093,30 @@ pub fn is_process_alive(pid: u32) -> bool { const STILL_ACTIVE: u32 = 0x103; if pid == 0 { - return false; + return (ProcessLiveness::Unknown, false); } unsafe { let handle = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, pid); if handle.is_null() { - return false; + // Windows reports ERROR_INVALID_PARAMETER for a nonexistent PID. + let state = if std::io::Error::last_os_error().raw_os_error() == Some(87) { + ProcessLiveness::Gone + } else { + ProcessLiveness::Unknown + }; + return (state, false); } let mut exit_code = 0; - let ok = GetExitCodeProcess(handle, &mut exit_code) != 0 && exit_code == STILL_ACTIVE; + let state = if GetExitCodeProcess(handle, &mut exit_code) == 0 { + ProcessLiveness::Unknown + } else if exit_code == STILL_ACTIVE { + ProcessLiveness::Alive + } else { + ProcessLiveness::Gone + }; let _ = CloseHandle(handle); - ok + (state, state == ProcessLiveness::Alive) } } @@ -1697,14 +1729,55 @@ mod tests { /// On platforms without process start-time inspection, a live PID is protected; /// deleting a live task is worse than temporarily retaining a recycled PID. pub fn is_recorded_process_alive(pid: u32, task_started_at_ms: u64) -> bool { + recorded_process_probe(pid, task_started_at_ms).1 +} + +pub(crate) fn recorded_process_liveness(pid: u32, task_started_at_ms: u64) -> ProcessLiveness { + recorded_process_probe(pid, task_started_at_ms).0 +} + +fn recorded_process_probe(pid: u32, task_started_at_ms: u64) -> (ProcessLiveness, bool) { + recorded_process_probe_with(probe_process(pid), task_started_at_ms, || { + crate::root_cache::process_start_time_ms(pid) + }) +} + +fn recorded_process_probe_with( + probe: (ProcessLiveness, bool), + task_started_at_ms: u64, + start_time: impl FnOnce() -> Option, +) -> (ProcessLiveness, bool) { const PROCESS_START_GRACE_MS: u64 = 30_000; - if !is_process_alive(pid) { - return false; + if !probe.1 { + return probe; + } + match start_time() { + None => (ProcessLiveness::Unknown, true), + Some(started_at_ms) + if started_at_ms <= task_started_at_ms.saturating_add(PROCESS_START_GRACE_MS) => + { + (ProcessLiveness::Alive, true) + } + Some(_) => (ProcessLiveness::Gone, false), + } +} + +#[test] +fn recorded_process_probe_preserves_recovery_decisions() { + use ProcessLiveness::{Alive, Gone, Unknown}; + for (probe, start, expected) in [ + ((Gone, false), None, (Gone, false)), + ((Unknown, false), None, (Unknown, false)), + ((Alive, true), None, (Unknown, true)), + ((Alive, true), Some(31_000), (Alive, true)), + ((Alive, true), Some(31_001), (Gone, false)), + ] { + assert_eq!( + recorded_process_probe_with(probe, 1_000, || start), + expected + ); } - crate::root_cache::process_start_time_ms(pid).is_none_or(|started_at_ms| { - started_at_ms <= task_started_at_ms.saturating_add(PROCESS_START_GRACE_MS) - }) } #[cfg(target_os = "linux")] #[test] diff --git a/crates/aft/src/bash_background/registry.rs b/crates/aft/src/bash_background/registry.rs index 1ad86e441a..e65d7c843e 100644 --- a/crates/aft/src/bash_background/registry.rs +++ b/crates/aft/src/bash_background/registry.rs @@ -4408,6 +4408,68 @@ impl BgTaskRegistry { .any(|pid| is_recorded_process_alive(pid, metadata.started_at)) } + /// Unlike replay, withdrawal needs proof of death before storing a stopped answer. + pub(crate) fn unregistered_task_process_liveness( + &self, + metadata: &PersistedTask, + ) -> super::process::ProcessLiveness { + use super::process::{recorded_process_liveness, ProcessLiveness}; + + if metadata.remote.is_some() { + return ProcessLiveness::Unknown; + } + let pids = Self::persisted_task_recorded_pids(metadata); + if pids.is_empty() { + return ProcessLiveness::Unknown; + } + let mut gone = true; + for pid in pids { + match recorded_process_liveness(pid, metadata.started_at) { + ProcessLiveness::Gone => {} + ProcessLiveness::Unknown => return ProcessLiveness::Unknown, + ProcessLiveness::Alive => gone = false, + } + } + #[cfg(target_os = "linux")] + if !gone && metadata.mode == BgMode::Pipes { + // Reuse replay's exact child/scope identity validation. A failed + // adoption says nothing about whether the task has stopped. + if self.recover_persisted_task_scope(metadata).is_err() { + return ProcessLiveness::Unknown; + } + } + if gone { + ProcessLiveness::Gone + } else { + ProcessLiveness::Alive + } + } + + #[cfg(target_os = "linux")] + fn recover_persisted_task_scope( + &self, + metadata: &PersistedTask, + ) -> Result, String> { + use super::task_scope::{lookup_state, ScopeLookup}; + + let Some(pid) = metadata.child_pid else { + return Ok(None); + }; + let answer = if let Some(start) = metadata.child_start_time_ms { + self.inner + .task_scopes + .adopt(&metadata.task_id, pid, start)? + } else { + match lookup_state(&metadata.task_id)? { + ScopeLookup::Present(_) => { + return Err("task scope replay has no exact child identity".into()) + } + other => other, + } + }; + Ok(Some(answer)) + } + /// The task's recorded child and process group leader, in that order. fn persisted_task_recorded_pids(metadata: &PersistedTask) -> Vec { let group_leader = metadata.pgid.and_then(|pid| u32::try_from(pid).ok()); @@ -8389,33 +8451,19 @@ impl BgTaskRegistry { let alive = if alive && metadata.mode == BgMode::Pipes && metadata.remote.is_none() { let recovered = (|| -> Result<(), String> { - if let Some(pid) = metadata.child_pid { - let answer = if let Some(start) = metadata.child_start_time_ms { + if let Some(super::task_scope::ScopeLookup::Present(scope)) = + self.recover_persisted_task_scope(&metadata)? + { + if let Some(policy) = metadata.memory_policy.as_mut() { + let monitor = super::memory_limit::Monitor::recover_task_scope( + policy.mib, &scope, + ); + *policy = monitor.policy.clone(); self.inner - .task_scopes - .adopt(&metadata.task_id, pid, start)? - } else { - match super::task_scope::lookup_state(&metadata.task_id)? { - super::task_scope::ScopeLookup::Present(_) => { - return Err( - "task scope replay has no exact child identity".into() - ) - } - other => other, - } - }; - if let super::task_scope::ScopeLookup::Present(scope) = answer { - if let Some(policy) = metadata.memory_policy.as_mut() { - let monitor = super::memory_limit::Monitor::recover_task_scope( - policy.mib, &scope, - ); - *policy = monitor.policy.clone(); - self.inner - .memory_monitors - .lock() - .unwrap_or_else(|error| error.into_inner()) - .insert(metadata.task_id.clone(), monitor); - } + .memory_monitors + .lock() + .unwrap_or_else(|error| error.into_inner()) + .insert(metadata.task_id.clone(), monitor); } } Ok(()) diff --git a/crates/aft/src/db/bash_tasks.rs b/crates/aft/src/db/bash_tasks.rs index dbef4c75c8..863d789a29 100644 --- a/crates/aft/src/db/bash_tasks.rs +++ b/crates/aft/src/db/bash_tasks.rs @@ -541,18 +541,21 @@ pub(crate) fn find_bash_task_session( .optional() } -/// Whether the persisted record of `task_id` says its process has stopped: -/// completed, failed, killed or timed out. A missing row, or one still -/// starting, running, being killed or of unknown fate, is not stopped. -pub(crate) fn bash_task_stopped(conn: &Connection, task_id: &str) -> rusqlite::Result { +/// Task IDs remain unique across the harnesses and sessions of a project root. +pub(crate) fn bash_task_by_id( + conn: &Connection, + task_id: &str, +) -> rusqlite::Result> { conn.query_row( - "SELECT status IN ('completed','failed','killed','timed_out') FROM bash_tasks + "SELECT harness, session_id, task_id, project_key, command, cwd, status, + exit_code, pid, pgid, started_at, completed_at, stdout_path, stderr_path, + compressed, timeout_ms, completion_delivered, output_bytes, metadata + FROM bash_tasks WHERE task_id = ?1 LIMIT 1", params![task_id], - |row| row.get(0), + map_bash_task_row, ) .optional() - .map(|stopped| stopped.unwrap_or(false)) } const SESSION_TASKS_SQL: &str = diff --git a/crates/aft/src/subc/tool_provider.rs b/crates/aft/src/subc/tool_provider.rs index 5ae75b7738..5a5a0efcc8 100644 --- a/crates/aft/src/subc/tool_provider.rs +++ b/crates/aft/src/subc/tool_provider.rs @@ -2221,9 +2221,9 @@ fn freeze_withdraw_answer( /// Stop a withdrawn running call's task through `ctx`'s task registry (each /// project root has its own), then store the withdraw's answer. When that -/// registry does not hold the task, the answer is stored only if the task's -/// record shows it has already stopped; otherwise nothing is stored and the -/// withdraw is refused as retryable. +/// registry does not hold the task, its persisted process identity must prove +/// it stopped, or its record must already be terminal. An uncheckable identity +/// leaves the answer unfrozen so withdrawal can be retried. fn kill_withdrawn_call( ctx: &crate::context::AppContext, kill: &WithdrawKill, @@ -2237,10 +2237,19 @@ fn kill_withdrawn_call( } return freeze_withdraw_answer(ctx, kill); } - let stopped = ctx.db().is_some_and(|db| { - db.lock().ok().is_some_and(|conn| { - crate::db::bash_tasks::bash_task_stopped(&conn, &kill.task).unwrap_or(false) - }) + let record = ctx.db().and_then(|db| { + let conn = db.lock().ok()?; + crate::db::bash_tasks::bash_task_by_id(&conn, &kill.task) + .ok() + .flatten() + }); + let stopped = record.is_some_and(|row| { + matches!( + row.status.as_str(), + "completed" | "failed" | "killed" | "timed_out" + ) || ctx.bash_background().unregistered_task_process_liveness( + &crate::bash_background::persistence::PersistedTask::from(row), + ) == crate::bash_background::process::ProcessLiveness::Gone }); if stopped { return freeze_withdraw_answer(ctx, kill); @@ -10990,6 +10999,121 @@ mod ledger_terminal_tests { use crate::db::call_ledger::Key; use crate::subc::{control_flags, route_key, Frame, FrameType, PersistentCancelSignal}; + fn unregistered_withdraw_fixture( + pid: Option, + pgid: Option, + ) -> ( + tempfile::TempDir, + std::sync::Arc, + WithdrawKill, + ) { + use crate::db::call_ledger::{self as ledger, State}; + let dir = tempfile::tempdir().unwrap(); + let ctx = crate::subc::test_support::test_ctx(); + let db = std::sync::Arc::new(std::sync::Mutex::new( + crate::db::open(&dir.path().join("aft.db")).unwrap(), + )); + ctx.set_db(db.clone()); + let key = Key { + carrier: "carrier".into(), + call_key: "running".into(), + }; + let task = "bash-0123456789abcdef"; + let conn = db.lock().unwrap(); + ledger::admit(&conn, &key, "digest", None, State::DispatchStarted).unwrap(); + ledger::link_task(&conn, &key, task).unwrap(); + conn.execute( + "INSERT INTO bash_tasks(harness,session_id,task_id,project_key,command,cwd,status,started_at,pid,pgid,metadata) VALUES('h','s',?1,'elsewhere','sleep','cwd','running',?2,?3,?4,'{}')", + rusqlite::params![task, ledger::now_ms(), pid, pgid], + ) + .unwrap(); + let ledger::Withdrawal::Answer { + body, + kill_task: Some(task), + .. + } = ledger::withdraw(&conn, &key, None, 100, usize::MAX).unwrap() + else { + panic!("a running linked call must name its task to kill"); + }; + assert!(!ctx.bash_background().holds_task(&task)); + (dir, ctx, WithdrawKill { key, task, body }) + } + + #[cfg(unix)] + #[test] + fn withdraw_unregistered_gone_process_freezes_identical_answer() { + use crate::db::call_ledger as ledger; + let mut child = std::process::Command::new("sh") + .args(["-c", "exit 0"]) + .spawn() + .unwrap(); + let pid = child.id(); + child.wait().unwrap(); + let (_dir, ctx, kill) = unregistered_withdraw_fixture(Some(pid), None); + let db = ctx.db().unwrap(); + assert_eq!(kill_withdrawn_call(&ctx, &kill).unwrap(), kill.body); + let conn = db.lock().unwrap(); + let row = ledger::get(&conn, &kill.key).unwrap().unwrap(); + assert_eq!(row.withdraw_answer.as_deref(), Some(kill.body.as_slice())); + // Even a later conflicting process snapshot cannot change the frozen reply. + conn.execute( + "UPDATE bash_tasks SET pid=?1 WHERE task_id=?2", + rusqlite::params![std::process::id(), kill.task], + ) + .unwrap(); + let ledger::Withdrawal::Answer { + body, kill_task, .. + } = ledger::withdraw(&conn, &kill.key, None, 200, usize::MAX).unwrap() + else { + panic!("a retry must return the frozen answer"); + }; + assert_eq!(body, kill.body); + assert!(kill_task.is_none()); + } + + #[test] + fn withdraw_unregistered_live_process_keeps_answer_unfrozen() { + use crate::db::call_ledger as ledger; + let (_dir, ctx, kill) = unregistered_withdraw_fixture(Some(std::process::id()), None); + let refused = kill_withdrawn_call(&ctx, &kill).unwrap_err(); + assert_eq!(refused.code, "withdraw_incomplete"); + assert_eq!( + refused.detail, + Some(json!({"retryable": true, "task_id": kill.task})) + ); + assert_eq!(refused.message, format!( + "the withdrawn call's task {} could not be stopped: no bound project root holds the task; retry tool.withdraw", + kill.task + )); + assert!(crate::bash_background::process::is_process_alive( + std::process::id() + )); + let db = ctx.db().unwrap(); + assert!(ledger::get(&db.lock().unwrap(), &kill.key) + .unwrap() + .unwrap() + .withdraw_answer + .is_none()); + } + + #[test] + fn withdraw_unregistered_unknown_identity_keeps_answer_unfrozen() { + use crate::db::call_ledger as ledger; + let (_dir, ctx, kill) = unregistered_withdraw_fixture(Some(0), None); + let refused = kill_withdrawn_call(&ctx, &kill).unwrap_err(); + assert_eq!(refused.code, "withdraw_incomplete"); + assert_eq!( + refused.detail, + Some(json!({"retryable": true, "task_id": kill.task})) + ); + let db = ctx.db().unwrap(); + assert!(ledger::get(&db.lock().unwrap(), &kill.key) + .unwrap() + .unwrap() + .withdraw_answer + .is_none()); + } + /// A withdraw whose running call could not be stopped stores no answer /// and is refused as retryable, so a retry tries again. Once the task's /// record shows it stopped, the answer is stored and returned. From b05dfebf39ebf4ec3dc9f3a8a62d325b6c0c3560 Mon Sep 17 00:00:00 2001 From: ualtinok <94532+ualtinok@users.noreply.github.com> Date: Wed, 18 Nov 2026 01:35:34 +0100 Subject: [PATCH 02/26] mason: confirm recorded task scopes are empty before freezing withdrawal Saved runtime or task-scope memory policy proves the task acquired a Linux scope. After its recorded PIDs are gone, reuse scope lookup and inspect cgroup.events before freezing: absent or empty scopes are stopped; populated, uncheckable, or unreachable scopes remain refused. Existing recovery decisions and refusal wire shape remain unchanged. Add deterministic file-backed withdrawal cases for absent, empty, populated, unknown and failed scope observations, including runtime-only scope acquisition. Co-authored-by: alfonso-aft <289616620+alfonso-aft@users.noreply.github.com> --- crates/aft/src/bash_background/registry.rs | 56 ++++++++ crates/aft/src/subc/tool_provider.rs | 143 ++++++++++++++++++++- 2 files changed, 196 insertions(+), 3 deletions(-) diff --git a/crates/aft/src/bash_background/registry.rs b/crates/aft/src/bash_background/registry.rs index e65d7c843e..8e152639e4 100644 --- a/crates/aft/src/bash_background/registry.rs +++ b/crates/aft/src/bash_background/registry.rs @@ -4431,6 +4431,15 @@ impl BgTaskRegistry { } } #[cfg(target_os = "linux")] + if gone + && (metadata.task_scope_runtime_ms.is_some() + || metadata.memory_policy.as_ref().is_some_and(|policy| { + policy.kind == super::memory_limit::MemoryPolicy::TASK_SCOPE_MEMORY_KIND + })) + { + return Self::unregistered_task_scope_liveness(metadata); + } + #[cfg(target_os = "linux")] if !gone && metadata.mode == BgMode::Pipes { // Reuse replay's exact child/scope identity validation. A failed // adoption says nothing about whether the task has stopped. @@ -4445,6 +4454,53 @@ impl BgTaskRegistry { } } + #[cfg(target_os = "linux")] + fn unregistered_task_scope_liveness( + metadata: &PersistedTask, + ) -> super::process::ProcessLiveness { + use super::process::ProcessLiveness; + use super::task_scope::{lookup_local, lookup_state, LocalScopeLookup, ScopeLookup}; + + let recorded = metadata + .memory_policy + .as_ref() + .filter(|policy| { + policy.kind == super::memory_limit::MemoryPolicy::TASK_SCOPE_MEMORY_KIND + }) + .and_then(|policy| policy.cgroup.as_deref()); + let scope = match lookup_local(&metadata.task_id, recorded) { + Ok(LocalScopeLookup::Absent) => return ProcessLiveness::Gone, + Ok(LocalScopeLookup::Present(scope)) => scope, + Ok(LocalScopeLookup::Unknown) => match lookup_state(&metadata.task_id) { + Ok(ScopeLookup::Absent) => return ProcessLiveness::Gone, + Ok(ScopeLookup::Present(scope)) => scope, + Ok(ScopeLookup::Unreachable) | Err(_) => return ProcessLiveness::Unknown, + }, + Err(_) => return ProcessLiveness::Unknown, + }; + // A scope can retain descendants after its recorded leader has exited. + // cgroup.events includes child cgroups, unlike a direct PID listing. + match fs::read_to_string(scope.cgroup().join("cgroup.events")) { + Ok(events) if events.lines().any(|line| line == "populated 0") => ProcessLiveness::Gone, + Ok(events) if events.lines().any(|line| line == "populated 1") => { + log::warn!( + "withdrawn call task {} still has descendants in scope {}", + metadata.task_id, + scope.cgroup().display() + ); + ProcessLiveness::Alive + } + Err(error) if error.kind() == std::io::ErrorKind::NotFound => { + // The scope may have disappeared between lookup and reading its events. + match scope.cgroup().try_exists() { + Ok(false) => ProcessLiveness::Gone, + _ => ProcessLiveness::Unknown, + } + } + _ => ProcessLiveness::Unknown, + } + } + #[cfg(target_os = "linux")] fn recover_persisted_task_scope( &self, diff --git a/crates/aft/src/subc/tool_provider.rs b/crates/aft/src/subc/tool_provider.rs index 5a5a0efcc8..d701c2557b 100644 --- a/crates/aft/src/subc/tool_provider.rs +++ b/crates/aft/src/subc/tool_provider.rs @@ -11040,15 +11040,21 @@ mod ledger_terminal_tests { } #[cfg(unix)] - #[test] - fn withdraw_unregistered_gone_process_freezes_identical_answer() { - use crate::db::call_ledger as ledger; + fn exited_withdraw_process_pid() -> u32 { let mut child = std::process::Command::new("sh") .args(["-c", "exit 0"]) .spawn() .unwrap(); let pid = child.id(); child.wait().unwrap(); + pid + } + + #[cfg(unix)] + #[test] + fn withdraw_unregistered_gone_process_freezes_identical_answer() { + use crate::db::call_ledger as ledger; + let pid = exited_withdraw_process_pid(); let (_dir, ctx, kill) = unregistered_withdraw_fixture(Some(pid), None); let db = ctx.db().unwrap(); assert_eq!(kill_withdrawn_call(&ctx, &kill).unwrap(), kill.body); @@ -11071,6 +11077,137 @@ mod ledger_terminal_tests { assert!(kill_task.is_none()); } + #[cfg(target_os = "linux")] + fn unregistered_scoped_withdraw_fixture( + events: Option<&str>, + ) -> ( + tempfile::TempDir, + std::sync::Arc, + WithdrawKill, + std::path::PathBuf, + ) { + let (dir, ctx, kill) = + unregistered_withdraw_fixture(Some(exited_withdraw_process_pid()), None); + let cgroup = dir + .path() + .join(format!("user@{}.service", unsafe { libc::geteuid() })) + .join("aft.slice") + .join(format!("aft-task-{}.scope", kill.task)); + if let Some(events) = events { + std::fs::create_dir_all(&cgroup).unwrap(); + std::fs::write(cgroup.join("cgroup.events"), events).unwrap(); + } + let db = ctx.db().unwrap(); + let conn = db.lock().unwrap(); + let row = crate::db::bash_tasks::bash_task_by_id(&conn, &kill.task) + .unwrap() + .unwrap(); + let mut metadata = crate::bash_background::persistence::PersistedTask::from(row); + metadata.memory_policy = serde_json::from_value(json!({ + "mib": 64, + "kind": "Linux task scope memory.max", + "cgroup": cgroup, + })) + .unwrap(); + conn.execute( + "UPDATE bash_tasks SET metadata=?1 WHERE task_id=?2", + rusqlite::params![serde_json::to_string(&metadata).unwrap(), kill.task], + ) + .unwrap(); + (dir, ctx, kill, cgroup) + } + + #[cfg(target_os = "linux")] + fn assert_scoped_withdraw_incomplete(ctx: &crate::context::AppContext, kill: &WithdrawKill) { + use crate::db::call_ledger as ledger; + let refused = kill_withdrawn_call(ctx, kill).unwrap_err(); + assert_eq!(refused.code, "withdraw_incomplete"); + assert_eq!( + refused.detail, + Some(json!({"retryable": true, "task_id": kill.task})) + ); + let db = ctx.db().unwrap(); + assert!(ledger::get(&db.lock().unwrap(), &kill.key) + .unwrap() + .unwrap() + .withdraw_answer + .is_none()); + } + + #[cfg(target_os = "linux")] + #[test] + fn withdraw_unregistered_recorded_scope_empty_or_absent_freezes_answer() { + use crate::db::call_ledger as ledger; + for events in [None, Some("populated 0\n")] { + let (_dir, ctx, kill, _cgroup) = unregistered_scoped_withdraw_fixture(events); + assert_eq!(kill_withdrawn_call(&ctx, &kill).unwrap(), kill.body); + let db = ctx.db().unwrap(); + let conn = db.lock().unwrap(); + let ledger::Withdrawal::Answer { + body, kill_task, .. + } = ledger::withdraw(&conn, &kill.key, None, 200, usize::MAX).unwrap() + else { + panic!("a retry must return the frozen answer"); + }; + assert_eq!(body, kill.body); + assert!(kill_task.is_none()); + } + } + + #[cfg(target_os = "linux")] + #[test] + fn withdraw_unregistered_recorded_scope_populated_keeps_answer_unfrozen() { + let (_dir, ctx, kill, _cgroup) = + unregistered_scoped_withdraw_fixture(Some("populated 1\n")); + assert_scoped_withdraw_incomplete(&ctx, &kill); + } + + #[cfg(target_os = "linux")] + #[test] + fn withdraw_unregistered_recorded_runtime_scope_keeps_descendants_unfrozen() { + let (dir, ctx, kill, _cgroup) = unregistered_scoped_withdraw_fixture(Some("populated 1\n")); + let db = ctx.db().unwrap(); + { + let conn = db.lock().unwrap(); + let row = crate::db::bash_tasks::bash_task_by_id(&conn, &kill.task) + .unwrap() + .unwrap(); + let mut metadata = crate::bash_background::persistence::PersistedTask::from(row); + metadata.memory_policy = None; + metadata.task_scope_runtime_ms = Some(60_000); + conn.execute( + "UPDATE bash_tasks SET metadata=?1 WHERE task_id=?2", + rusqlite::params![serde_json::to_string(&metadata).unwrap(), kill.task], + ) + .unwrap(); + } + let current = dir.path().join(format!( + "user@{}.service/app.slice/module.service", + unsafe { libc::geteuid() } + )); + crate::bash_background::task_scope::with_local_recovery_fixture_for_test(current, || { + assert_scoped_withdraw_incomplete(&ctx, &kill); + }); + } + + #[cfg(target_os = "linux")] + #[test] + fn withdraw_unregistered_recorded_scope_lookup_error_keeps_answer_unfrozen() { + let (_dir, ctx, kill, cgroup) = unregistered_scoped_withdraw_fixture(Some("populated 0\n")); + std::fs::remove_dir_all(&cgroup).unwrap(); + // A self-referencing link makes try_exists fail, rather than report absence. + std::os::unix::fs::symlink(cgroup.file_name().unwrap(), &cgroup).unwrap(); + assert!(cgroup.try_exists().is_err()); + assert_scoped_withdraw_incomplete(&ctx, &kill); + } + + #[cfg(target_os = "linux")] + #[test] + fn withdraw_unregistered_recorded_scope_unconfirmed_population_keeps_answer_unfrozen() { + let (_dir, ctx, kill, _cgroup) = unregistered_scoped_withdraw_fixture(Some("")); + assert_scoped_withdraw_incomplete(&ctx, &kill); + } + #[test] fn withdraw_unregistered_live_process_keeps_answer_unfrozen() { use crate::db::call_ledger as ledger; From d47f1d6dc6f4ba97ab38d5331498b1b2266671c5 Mon Sep 17 00:00:00 2001 From: ualtinok <94532+ualtinok@users.noreply.github.com> Date: Wed, 18 Nov 2026 01:55:57 +0100 Subject: [PATCH 03/26] mason: extract withdrawal liveness checks from task registry Keep the registry within its pinned hand-written line limit by moving the missing-registry identity and scope helpers into a sibling impl module. Preserve withdrawal and startup recovery behavior; leave only the module connection and shared recovery call in registry.rs. No size pins are raised. Co-authored-by: alfonso-aft <289616620+alfonso-aft@users.noreply.github.com> --- crates/aft/src/bash_background/registry.rs | 120 +---------------- .../src/bash_background/withdraw_liveness.rs | 121 ++++++++++++++++++ 2 files changed, 123 insertions(+), 118 deletions(-) create mode 100644 crates/aft/src/bash_background/withdraw_liveness.rs diff --git a/crates/aft/src/bash_background/registry.rs b/crates/aft/src/bash_background/registry.rs index 8e152639e4..5a012f3407 100644 --- a/crates/aft/src/bash_background/registry.rs +++ b/crates/aft/src/bash_background/registry.rs @@ -85,6 +85,8 @@ mod lifecycle_scope; mod scope_runtime; #[path = "scope_spawn.rs"] mod scope_spawn; +#[path = "withdraw_liveness.rs"] +mod withdraw_liveness; use scope_spawn::spawn_detached_child; struct UncommittedLayout<'a> { @@ -4408,124 +4410,6 @@ impl BgTaskRegistry { .any(|pid| is_recorded_process_alive(pid, metadata.started_at)) } - /// Unlike replay, withdrawal needs proof of death before storing a stopped answer. - pub(crate) fn unregistered_task_process_liveness( - &self, - metadata: &PersistedTask, - ) -> super::process::ProcessLiveness { - use super::process::{recorded_process_liveness, ProcessLiveness}; - - if metadata.remote.is_some() { - return ProcessLiveness::Unknown; - } - let pids = Self::persisted_task_recorded_pids(metadata); - if pids.is_empty() { - return ProcessLiveness::Unknown; - } - let mut gone = true; - for pid in pids { - match recorded_process_liveness(pid, metadata.started_at) { - ProcessLiveness::Gone => {} - ProcessLiveness::Unknown => return ProcessLiveness::Unknown, - ProcessLiveness::Alive => gone = false, - } - } - #[cfg(target_os = "linux")] - if gone - && (metadata.task_scope_runtime_ms.is_some() - || metadata.memory_policy.as_ref().is_some_and(|policy| { - policy.kind == super::memory_limit::MemoryPolicy::TASK_SCOPE_MEMORY_KIND - })) - { - return Self::unregistered_task_scope_liveness(metadata); - } - #[cfg(target_os = "linux")] - if !gone && metadata.mode == BgMode::Pipes { - // Reuse replay's exact child/scope identity validation. A failed - // adoption says nothing about whether the task has stopped. - if self.recover_persisted_task_scope(metadata).is_err() { - return ProcessLiveness::Unknown; - } - } - if gone { - ProcessLiveness::Gone - } else { - ProcessLiveness::Alive - } - } - - #[cfg(target_os = "linux")] - fn unregistered_task_scope_liveness( - metadata: &PersistedTask, - ) -> super::process::ProcessLiveness { - use super::process::ProcessLiveness; - use super::task_scope::{lookup_local, lookup_state, LocalScopeLookup, ScopeLookup}; - - let recorded = metadata - .memory_policy - .as_ref() - .filter(|policy| { - policy.kind == super::memory_limit::MemoryPolicy::TASK_SCOPE_MEMORY_KIND - }) - .and_then(|policy| policy.cgroup.as_deref()); - let scope = match lookup_local(&metadata.task_id, recorded) { - Ok(LocalScopeLookup::Absent) => return ProcessLiveness::Gone, - Ok(LocalScopeLookup::Present(scope)) => scope, - Ok(LocalScopeLookup::Unknown) => match lookup_state(&metadata.task_id) { - Ok(ScopeLookup::Absent) => return ProcessLiveness::Gone, - Ok(ScopeLookup::Present(scope)) => scope, - Ok(ScopeLookup::Unreachable) | Err(_) => return ProcessLiveness::Unknown, - }, - Err(_) => return ProcessLiveness::Unknown, - }; - // A scope can retain descendants after its recorded leader has exited. - // cgroup.events includes child cgroups, unlike a direct PID listing. - match fs::read_to_string(scope.cgroup().join("cgroup.events")) { - Ok(events) if events.lines().any(|line| line == "populated 0") => ProcessLiveness::Gone, - Ok(events) if events.lines().any(|line| line == "populated 1") => { - log::warn!( - "withdrawn call task {} still has descendants in scope {}", - metadata.task_id, - scope.cgroup().display() - ); - ProcessLiveness::Alive - } - Err(error) if error.kind() == std::io::ErrorKind::NotFound => { - // The scope may have disappeared between lookup and reading its events. - match scope.cgroup().try_exists() { - Ok(false) => ProcessLiveness::Gone, - _ => ProcessLiveness::Unknown, - } - } - _ => ProcessLiveness::Unknown, - } - } - - #[cfg(target_os = "linux")] - fn recover_persisted_task_scope( - &self, - metadata: &PersistedTask, - ) -> Result, String> { - use super::task_scope::{lookup_state, ScopeLookup}; - - let Some(pid) = metadata.child_pid else { - return Ok(None); - }; - let answer = if let Some(start) = metadata.child_start_time_ms { - self.inner - .task_scopes - .adopt(&metadata.task_id, pid, start)? - } else { - match lookup_state(&metadata.task_id)? { - ScopeLookup::Present(_) => { - return Err("task scope replay has no exact child identity".into()) - } - other => other, - } - }; - Ok(Some(answer)) - } - /// The task's recorded child and process group leader, in that order. fn persisted_task_recorded_pids(metadata: &PersistedTask) -> Vec { let group_leader = metadata.pgid.and_then(|pid| u32::try_from(pid).ok()); diff --git a/crates/aft/src/bash_background/withdraw_liveness.rs b/crates/aft/src/bash_background/withdraw_liveness.rs new file mode 100644 index 0000000000..bf3629f290 --- /dev/null +++ b/crates/aft/src/bash_background/withdraw_liveness.rs @@ -0,0 +1,121 @@ +use super::super::process::{recorded_process_liveness, ProcessLiveness}; +#[cfg(target_os = "linux")] +use super::super::{ + memory_limit::MemoryPolicy, + task_scope::{lookup_local, lookup_state, LocalScopeLookup, ScopeLookup}, +}; +#[cfg(target_os = "linux")] +use super::BgMode; +use super::{BgTaskRegistry, PersistedTask}; +#[cfg(target_os = "linux")] +use std::fs; + +impl BgTaskRegistry { + /// Withdrawal needs proof of death before freezing a missing-registry task's answer. + pub(crate) fn unregistered_task_process_liveness( + &self, + metadata: &PersistedTask, + ) -> ProcessLiveness { + if metadata.remote.is_some() { + return ProcessLiveness::Unknown; + } + let pids = Self::persisted_task_recorded_pids(metadata); + if pids.is_empty() { + return ProcessLiveness::Unknown; + } + let mut gone = true; + for pid in pids { + match recorded_process_liveness(pid, metadata.started_at) { + ProcessLiveness::Gone => {} + ProcessLiveness::Unknown => return ProcessLiveness::Unknown, + ProcessLiveness::Alive => gone = false, + } + } + #[cfg(target_os = "linux")] + if gone + && (metadata.task_scope_runtime_ms.is_some() + || metadata + .memory_policy + .as_ref() + .is_some_and(|policy| policy.kind == MemoryPolicy::TASK_SCOPE_MEMORY_KIND)) + { + return Self::unregistered_task_scope_liveness(metadata); + } + #[cfg(target_os = "linux")] + if !gone && metadata.mode == BgMode::Pipes { + // Validate the recorded child identity and scope membership. A failed + // adoption says nothing about whether the task has stopped. + if self.recover_persisted_task_scope(metadata).is_err() { + return ProcessLiveness::Unknown; + } + } + if gone { + ProcessLiveness::Gone + } else { + ProcessLiveness::Alive + } + } + + #[cfg(target_os = "linux")] + fn unregistered_task_scope_liveness(metadata: &PersistedTask) -> ProcessLiveness { + let recorded = metadata + .memory_policy + .as_ref() + .filter(|policy| policy.kind == MemoryPolicy::TASK_SCOPE_MEMORY_KIND) + .and_then(|policy| policy.cgroup.as_deref()); + let scope = match lookup_local(&metadata.task_id, recorded) { + Ok(LocalScopeLookup::Absent) => return ProcessLiveness::Gone, + Ok(LocalScopeLookup::Present(scope)) => scope, + Ok(LocalScopeLookup::Unknown) => match lookup_state(&metadata.task_id) { + Ok(ScopeLookup::Absent) => return ProcessLiveness::Gone, + Ok(ScopeLookup::Present(scope)) => scope, + Ok(ScopeLookup::Unreachable) | Err(_) => return ProcessLiveness::Unknown, + }, + Err(_) => return ProcessLiveness::Unknown, + }; + // A scope can retain descendants after its recorded leader has exited. + // cgroup.events includes child cgroups, unlike a direct PID listing. + match fs::read_to_string(scope.cgroup().join("cgroup.events")) { + Ok(events) if events.lines().any(|line| line == "populated 0") => ProcessLiveness::Gone, + Ok(events) if events.lines().any(|line| line == "populated 1") => { + log::warn!( + "withdrawn call task {} still has descendants in scope {}", + metadata.task_id, + scope.cgroup().display() + ); + ProcessLiveness::Alive + } + Err(error) if error.kind() == std::io::ErrorKind::NotFound => { + // The scope may have disappeared between lookup and reading its events. + match scope.cgroup().try_exists() { + Ok(false) => ProcessLiveness::Gone, + _ => ProcessLiveness::Unknown, + } + } + _ => ProcessLiveness::Unknown, + } + } + + #[cfg(target_os = "linux")] + pub(super) fn recover_persisted_task_scope( + &self, + metadata: &PersistedTask, + ) -> Result, String> { + let Some(pid) = metadata.child_pid else { + return Ok(None); + }; + let answer = if let Some(start) = metadata.child_start_time_ms { + self.inner + .task_scopes + .adopt(&metadata.task_id, pid, start)? + } else { + match lookup_state(&metadata.task_id)? { + ScopeLookup::Present(_) => { + return Err("task scope replay has no exact child identity".into()) + } + other => other, + } + }; + Ok(Some(answer)) + } +} From dbe94679a5a2067be10fd76ff9d13e5c1e013672 Mon Sep 17 00:00:00 2001 From: ualtinok <94532+ualtinok@users.noreply.github.com> Date: Wed, 18 Nov 2026 02:04:09 +0100 Subject: [PATCH 04/26] mason: lower registry size pin after liveness extraction The size gate requires exact downward pins after a split. Record 19058 hand-written registry lines, below the previous 19070 pin; no pin is raised. Co-authored-by: alfonso-aft <289616620+alfonso-aft@users.noreply.github.com> --- scripts/file-size-pins.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/file-size-pins.json b/scripts/file-size-pins.json index 42edf94c48..3f2b21a436 100644 --- a/scripts/file-size-pins.json +++ b/scripts/file-size-pins.json @@ -1,6 +1,6 @@ { "crates/aft/src/bash_background/registry.rs": { - "lines": 19070, + "lines": 19058, "reason": "Split registry lifecycle and persistence by area pending; AFT crate split lane." }, "crates/aft/src/bash_background/remote_tests.rs": { From be678a789e413c5f2d8f845699c7b3f4bded9013 Mon Sep 17 00:00:00 2001 From: ualtinok <94532+ualtinok@users.noreply.github.com> Date: Wed, 18 Nov 2026 01:21:04 +0100 Subject: [PATCH 05/26] mason: retain announced display pull records across restarts Persist frozen pull bytes before publishing a wake, with protected count/byte bounds and bounded expiry sweeps. Keep the optional delivery cache outside numbered schema migrations so schema 29 and its reader floor remain compatible with rollback builds. Existing route admission and discovered-reader checks precede both memory and durable reads. Clarify the existing empty-after-restart outbox test as a memory-only invariant; the new service test separately proves durable recovery and publish ordering. Co-authored-by: alfonso-aft <289616620+alfonso-aft@users.noreply.github.com> --- crates/aft/src/db/compression_events.rs | 7 + crates/aft/src/db/display_records.rs | 173 +++++++++++ crates/aft/src/db/display_records/tests.rs | 151 ++++++++++ crates/aft/src/db/mod.rs | 4 + crates/aft/src/late_result_bus/display.rs | 51 ++-- crates/aft/src/list_surfaces.rs | 6 + crates/aft/src/subc/mod.rs | 6 +- crates/aft/src/subc/rich_ui/display.rs | 75 ++++- crates/aft/src/subc/rich_ui/display/store.rs | 63 ++++ crates/aft/src/subc/rich_ui/display/tests.rs | 301 ++++++++++++++++++- crates/aft/src/subc/rich_ui/outbox/reads.rs | 3 +- docs/tool-display.md | 30 +- 12 files changed, 818 insertions(+), 52 deletions(-) create mode 100644 crates/aft/src/db/display_records.rs create mode 100644 crates/aft/src/db/display_records/tests.rs create mode 100644 crates/aft/src/subc/rich_ui/display/store.rs diff --git a/crates/aft/src/db/compression_events.rs b/crates/aft/src/db/compression_events.rs index 5887b60ba6..f86adb8e91 100644 --- a/crates/aft/src/db/compression_events.rs +++ b/crates/aft/src/db/compression_events.rs @@ -1221,6 +1221,13 @@ pub fn maybe_spawn_retention( &db, i64::try_from(now).unwrap_or(i64::MAX), ); + if let Ok(conn) = db.try_lock() { + if let Err(error) = crate::db::display_records::sweep( + &conn, i64::try_from(now).unwrap_or(i64::MAX), + ) { + crate::slog_warn!("display record retention failed: {error}"); + } + } IN_FLIGHT.store(false, Ordering::Release); }) { diff --git a/crates/aft/src/db/display_records.rs b/crates/aft/src/db/display_records.rs new file mode 100644 index 0000000000..715e0d96c6 --- /dev/null +++ b/crates/aft/src/db/display_records.rs @@ -0,0 +1,173 @@ +//! Frozen display.read replies committed before their bus wakes. +use rusqlite::{params, Connection, OptionalExtension}; + +pub(crate) const MAX_RECORDS: usize = 192; +pub(crate) const MAX_BYTES: usize = 16 * 1024 * 1024; +const SWEEP_LIMIT: usize = 64; + +pub(crate) const CACHE_DDL: &str = r#" +CREATE TABLE IF NOT EXISTS display_records ( + record_id TEXT NOT NULL PRIMARY KEY, + pull_bytes BLOB NOT NULL, + announced_at_ms INTEGER NOT NULL, + wake_acked_at_ms INTEGER +); +CREATE INDEX IF NOT EXISTS idx_display_records_expiry ON display_records ( + CASE WHEN wake_acked_at_ms IS NULL THEN announced_at_ms + 86400000 + ELSE wake_acked_at_ms + 600000 END +); +"#; + +const EXPIRY: &str = "CASE WHEN wake_acked_at_ms IS NULL THEN announced_at_ms + 86400000 ELSE wake_acked_at_ms + 600000 END"; + +pub(super) fn install(conn: &Connection) -> rusqlite::Result<()> { + // This optional delivery cache is outside the numbered schema: no older + // reader touches it, and losing it costs only a display pull. Keep these + // statements idempotent if a later numbered migration adopts the table. + conn.execute_batch(CACHE_DDL)?; + sweep(conn, now_ms())?; + Ok(()) +} + +pub(crate) fn now_ms() -> i64 { + std::time::SystemTime::now() + .duration_since(std::time::UNIX_EPOCH) + .unwrap_or_default() + .as_millis() + .min(i64::MAX as u128) as i64 +} + +fn available(conn: &Connection) -> rusqlite::Result { + if conn.is_readonly(rusqlite::DatabaseName::Main)? { + return Ok(false); + } + conn.query_row( + "SELECT EXISTS(SELECT 1 FROM sqlite_master WHERE type='table' AND name='display_records')", + [], + |row| row.get(0), + ) +} + +/// Reclaim one bounded page without loading any tool output into memory. +pub(crate) fn sweep(conn: &Connection, now_ms: i64) -> rusqlite::Result { + if !available(conn)? { + return Ok(0); + } + let rows = conn + .prepare(&format!( + "SELECT record_id, length(pull_bytes) FROM display_records + WHERE {EXPIRY} < ?1 ORDER BY {EXPIRY}, record_id LIMIT ?2" + ))? + .query_map(params![now_ms, SWEEP_LIMIT], |row| { + Ok((row.get::<_, String>(0)?, row.get::<_, usize>(1)?)) + })? + .collect::>>()?; + let (mut count, mut bytes) = (0, 0); + for (id, size) in &rows { + let deleted = conn.execute( + &format!("DELETE FROM display_records WHERE record_id=?1 AND {EXPIRY} < ?2"), + params![id, now_ms], + )?; + count += deleted; + bytes += deleted * size; + } + if count > 0 { + log::info!("display store eviction: reason=expired count={count} bytes={bytes}"); + } + Ok(count) +} + +/// False means protected capacity is full: the caller must defer the wake, +/// without interfering with the independent display.write push. +pub(crate) fn persist( + conn: &Connection, + id: &str, + bytes: &[u8], + now_ms: i64, +) -> rusqlite::Result { + if !available(conn)? { + log::warn!( + "display store deferral: reason=unavailable count=1 bytes={}", + bytes.len() + ); + return Ok(false); + } + let tx = conn.unchecked_transaction()?; + sweep(&tx, now_ms)?; + let existing: Option> = tx + .query_row( + "SELECT pull_bytes FROM display_records WHERE record_id=?1", + [id], + |row| row.get(0), + ) + .optional()?; + if let Some(existing) = existing { + if existing != bytes { + log::warn!( + "display store deferral: reason=conflicting_bytes count=1 bytes={}", + bytes.len() + ); + tx.commit()?; + return Ok(false); + } + } else { + let (mut count, mut used): (usize, usize) = tx.query_row( + "SELECT count(*), coalesce(sum(length(pull_bytes)),0) FROM display_records", + [], + |row| Ok((row.get(0)?, row.get(1)?)), + )?; + // Expired pages may remain after the first bounded sweep. Reclaim only + // as many pages as admission needs; protected rows are never victims. + while (count >= MAX_RECORDS || used.saturating_add(bytes.len()) > MAX_BYTES) + && sweep(&tx, now_ms)? > 0 + { + (count, used) = tx.query_row( + "SELECT count(*), coalesce(sum(length(pull_bytes)),0) FROM display_records", + [], + |row| Ok((row.get(0)?, row.get(1)?)), + )?; + } + if count >= MAX_RECORDS || used.saturating_add(bytes.len()) > MAX_BYTES { + log::warn!("display store deferral: reason=protected_capacity count={count} bytes={used} incoming_bytes={}", bytes.len()); + tx.commit()?; + return Ok(false); + } + } + // Each publish attempt gets a fresh unacknowledged window. An uncertain + // publish result must not shorten protection for a wake the bus accepted. + tx.execute( + "INSERT INTO display_records(record_id,pull_bytes,announced_at_ms,wake_acked_at_ms) + VALUES (?1,?2,?3,NULL) + ON CONFLICT(record_id) DO UPDATE SET announced_at_ms=excluded.announced_at_ms, + wake_acked_at_ms=NULL", + params![id, bytes, now_ms], + )?; + tx.commit()?; + Ok(true) +} + +pub(crate) fn acknowledged(conn: &Connection, id: &str, now_ms: i64) -> rusqlite::Result<()> { + let updated = conn.execute( + "UPDATE display_records SET wake_acked_at_ms=?2 WHERE record_id=?1", + params![id, now_ms], + )?; + if updated != 1 { + return Err(rusqlite::Error::QueryReturnedNoRows); + } + Ok(()) +} + +pub(crate) fn read(conn: &Connection, id: &str, now_ms: i64) -> rusqlite::Result>> { + if !available(conn)? { + return Ok(None); + } + conn.query_row( + &format!("SELECT pull_bytes FROM display_records WHERE record_id=?1 AND {EXPIRY} >= ?2"), + params![id, now_ms], + |row| row.get(0), + ) + .optional() +} + +#[cfg(test)] +mod tests; diff --git a/crates/aft/src/db/display_records/tests.rs b/crates/aft/src/db/display_records/tests.rs new file mode 100644 index 0000000000..590988a43d --- /dev/null +++ b/crates/aft/src/db/display_records/tests.rs @@ -0,0 +1,151 @@ +use super::*; + +fn database() -> Connection { + let conn = Connection::open_in_memory().unwrap(); + conn.execute_batch(CACHE_DDL).unwrap(); + conn +} + +#[test] +fn display_read_store_ack_window_is_inclusive_and_unacked_survives_twenty_four_hours() { + let conn = database(); + let now = 1_000_000; + assert!(persist(&conn, "acked", b"exact bytes", now).unwrap()); + acknowledged(&conn, "acked", now + 100).unwrap(); + assert_eq!( + read(&conn, "acked", now + 600_100).unwrap(), + Some(b"exact bytes".to_vec()) + ); + assert!(read(&conn, "acked", now + 600_101).unwrap().is_none()); + assert!(persist(&conn, "unacked", b"pending", now).unwrap()); + assert!(read(&conn, "unacked", now + 600_101).unwrap().is_some()); + assert!(read(&conn, "unacked", now + 86_400_000).unwrap().is_some()); + assert!(read(&conn, "unacked", now + 86_400_001).unwrap().is_none()); + assert_eq!(sweep(&conn, now + 86_400_001).unwrap(), 2); +} + +#[test] +fn display_read_store_defers_count_and_byte_pressure_without_evicting_protected_rows() { + let now = 1_000_000; + for size in [1, MAX_BYTES / 2] { + let conn = database(); + let count = if size == 1 { MAX_RECORDS } else { 2 }; + let bytes = vec![b'x'; size]; + for index in 0..count { + assert!(persist(&conn, &index.to_string(), &bytes, now).unwrap()); + acknowledged(&conn, &index.to_string(), now).unwrap(); + } + assert!(!persist(&conn, "deferred", b"new", now + 1).unwrap()); + assert_eq!(read(&conn, "0", now + 1).unwrap(), Some(bytes.clone())); + assert!(read(&conn, "deferred", now + 1).unwrap().is_none()); + assert!(persist(&conn, "deferred", b"new", now + 600_001).unwrap()); + assert_eq!( + read(&conn, "deferred", now + 600_001).unwrap(), + Some(b"new".to_vec()) + ); + } +} + +#[test] +fn display_read_store_sweep_bounds_each_page_and_retry_preserves_first_bytes() { + let conn = database(); + for index in 0..MAX_RECORDS { + assert!(persist(&conn, &index.to_string(), b"first", 0).unwrap()); + } + assert!(!persist(&conn, "0", b"replacement", 10).unwrap()); + assert!(persist(&conn, "0", b"first", 20).unwrap()); + assert_eq!( + read(&conn, "0", 86_400_001).unwrap(), + Some(b"first".to_vec()) + ); + assert_eq!(sweep(&conn, 86_400_001).unwrap(), SWEEP_LIMIT); + let remaining: usize = conn + .query_row("SELECT count(*) FROM display_records", [], |row| row.get(0)) + .unwrap(); + assert_eq!(remaining, MAX_RECORDS - SWEEP_LIMIT); +} + +#[test] +fn display_read_cache_fresh_upgrade_and_rollback_keep_schema29_and_reader_floor() { + let dir = tempfile::tempdir().unwrap(); + let path = dir.path().join("aft.db"); + let fresh = crate::db::open(&path).unwrap(); + assert_eq!(crate::db::schema_version(&fresh), 29); + assert!(available(&fresh).unwrap()); + // Model an existing schema-29 database that predates the optional cache. + fresh.execute_batch("DROP TABLE display_records").unwrap(); + fresh + .execute( + "INSERT INTO host_state(key,value,updated_at) VALUES ('rollback','kept',0)", + [], + ) + .unwrap(); + drop(fresh); + assert!(crate::reader_floor::prepare(dir.path()).is_empty()); + let floor_path = crate::reader_floor::floor_path(dir.path()); + let floor_before = std::fs::read(&floor_path).unwrap(); + let upgraded = crate::db::open(&path).unwrap(); + let now = now_ms(); + assert!(persist(&upgraded, "retained", b"opaque pull bytes", now).unwrap()); + assert_eq!(crate::db::schema_version(&upgraded), 29); + assert_eq!(std::fs::read(&floor_path).unwrap(), floor_before); + drop(upgraded); + // The rollback build uses these unchanged version checks. It never needs + // to know or interpret the optional display cache to open the database. + let mut rollback = Connection::open(&path).unwrap(); + assert_eq!(crate::db::peek_schema_version(&path), Some(29)); + assert_eq!( + crate::db::run_migrations_supported(&mut rollback, 29).unwrap(), + 29 + ); + assert_eq!( + rollback + .query_row( + "SELECT value FROM host_state WHERE key='rollback'", + [], + |row| row.get::<_, String>(0) + ) + .unwrap(), + "kept" + ); + assert_eq!( + read(&rollback, "retained", now).unwrap(), + Some(b"opaque pull bytes".to_vec()) + ); + assert_eq!(std::fs::read(&floor_path).unwrap(), floor_before); +} + +#[test] +fn display_read_cache_absent_or_readonly_is_memory_only_without_errors() { + let absent = Connection::open_in_memory().unwrap(); + assert!(read(&absent, "any", 0).unwrap().is_none()); + assert!(!persist(&absent, "any", b"bytes", 0).unwrap()); + assert_eq!(sweep(&absent, i64::MAX).unwrap(), 0); + let dir = tempfile::tempdir().unwrap(); + let path = dir.path().join("aft.db"); + let conn = Connection::open(&path).unwrap(); + conn.execute_batch(CACHE_DDL).unwrap(); + assert!(persist(&conn, "any", b"bytes", 0).unwrap()); + drop(conn); + let readonly = + Connection::open_with_flags(&path, rusqlite::OpenFlags::SQLITE_OPEN_READ_ONLY).unwrap(); + assert!(read(&readonly, "any", 0).unwrap().is_none()); + assert!(!persist(&readonly, "new", b"bytes", 0).unwrap()); + assert_eq!(sweep(&readonly, i64::MAX).unwrap(), 0); +} + +#[test] +fn display_read_cache_writable_open_sweeps_only_one_expired_page() { + let dir = tempfile::tempdir().unwrap(); + let path = dir.path().join("aft.db"); + let conn = crate::db::open(&path).unwrap(); + for index in 0..MAX_RECORDS { + assert!(persist(&conn, &index.to_string(), b"expired", 0).unwrap()); + } + drop(conn); + let reopened = crate::db::open(&path).unwrap(); + let remaining: usize = reopened + .query_row("SELECT count(*) FROM display_records", [], |row| row.get(0)) + .unwrap(); + assert_eq!(remaining, MAX_RECORDS - SWEEP_LIMIT); +} diff --git a/crates/aft/src/db/mod.rs b/crates/aft/src/db/mod.rs index b3600f395c..c6dc2044e9 100644 --- a/crates/aft/src/db/mod.rs +++ b/crates/aft/src/db/mod.rs @@ -25,6 +25,7 @@ pub mod compression_events; #[cfg(any(debug_assertions, feature = "test-timing-hooks"))] pub(crate) mod contention_probe; pub(crate) mod deferred_checkpoint; +pub(crate) mod display_records; pub(crate) mod gh_speech; pub mod github_read_cache; pub mod remote_exec; @@ -687,6 +688,7 @@ pub(crate) fn open_with_mode(path: &Path, mode: OpenMode) -> Result Result(()) })(); @@ -1232,6 +1235,7 @@ mod tests { "rich_ui_templates", "rich_ui_cursor_key", "rich_ui_session_presets", + "display_records", ]; const EXPECTED_INDEXES: &[&str] = &[ diff --git a/crates/aft/src/late_result_bus/display.rs b/crates/aft/src/late_result_bus/display.rs index 4231287a1c..b138306f88 100644 --- a/crates/aft/src/late_result_bus/display.rs +++ b/crates/aft/src/late_result_bus/display.rs @@ -123,35 +123,38 @@ fn body(id: &str) -> Result, &'static str> { } pub(super) async fn publish_one(client: &BusClient) { - let Some(id) = crate::subc::rich_ui::display::with_outbox(|outbox| { - outbox.reads.due(std::time::Instant::now()) + let Some((id, pull_bytes)) = crate::subc::rich_ui::display::with_outbox(|outbox| { + let now = std::time::Instant::now(); + let id = outbox.reads.due(now)?; + let bytes = outbox.reads.read(&id, now)?; + Some((id, bytes)) }) .flatten() else { return; }; - let result = match body(&id) { - Ok(bytes) => tokio::time::timeout( - super::IO_TIMEOUT, - client.publish_event( - DISPLAY_RECORD_READY_EVENT, - DISPLAY_RECORD_READY_VERSION as u32, - None, - &id, - bytes, - ), - ) - .await - .map_err(|_| "display_bus_timeout") - .and_then(|result| { - result - .map(|_| ()) - .map_err(|error| super::error_code(&error)) - }), - Err(code) => { - completed(&id, Err(code)); - return; + let result = crate::subc::rich_ui::display::announce(id.clone(), pull_bytes, async { + match body(&id) { + Ok(bytes) => tokio::time::timeout( + super::IO_TIMEOUT, + client.publish_event( + DISPLAY_RECORD_READY_EVENT, + DISPLAY_RECORD_READY_VERSION as u32, + None, + &id, + bytes, + ), + ) + .await + .map_err(|_| "display_bus_timeout") + .and_then(|result| { + result + .map(|_| ()) + .map_err(|error| super::error_code(&error)) + }), + Err(code) => Err(code), } - }; + }) + .await; completed(&id, result); } diff --git a/crates/aft/src/list_surfaces.rs b/crates/aft/src/list_surfaces.rs index 57d78edba6..d0a92b91b9 100644 --- a/crates/aft/src/list_surfaces.rs +++ b/crates/aft/src/list_surfaces.rs @@ -509,6 +509,12 @@ pub static EXCLUSIONS: &[ExclusionEntry] = &[ location_or_primitive: "LATE_RESULTS_PAGE_MAX (256), SQL LIMIT cap + 1, take(cap), max_body", reason: "tool-provider protocol feed pagination uses entries, cursor and more, not an AFT ListEnvelope; the existing 256-entry limit and encoded reply-byte bound retain continuation through the shared cursor", }, + ExclusionEntry { + file: "db/display_records.rs", + enclosing_item: "sweep, persist", + location_or_primitive: "SWEEP_LIMIT, SQL LIMIT, MAX_RECORDS, MAX_BYTES", + reason: "Durable display pull retention bounds housekeeping pages and stored output, not a tool result list; protected capacity defers wakes without truncating or evicting promised records.", + }, ExclusionEntry { file: "db/access_grants.rs", enclosing_item: "saved_scope_batch", diff --git a/crates/aft/src/subc/mod.rs b/crates/aft/src/subc/mod.rs index a3d2f2f969..8c0be0ff36 100644 --- a/crates/aft/src/subc/mod.rs +++ b/crates/aft/src/subc/mod.rs @@ -5483,7 +5483,11 @@ where } }); } - rich_ui::display::start(connection_file_path.to_path_buf()); + rich_ui::display::start( + connection_file_path.to_path_buf(), + shared_app.clone(), + storage_dir.join("aft.db"), + ); runner_notices::install(connection_file_path.to_path_buf()); let push_senders = PushSenders { lossy_tx, diff --git a/crates/aft/src/subc/rich_ui/display.rs b/crates/aft/src/subc/rich_ui/display.rs index c8beedace9..99784b1ac7 100644 --- a/crates/aft/src/subc/rich_ui/display.rs +++ b/crates/aft/src/subc/rich_ui/display.rs @@ -18,12 +18,14 @@ use subc_protocol::Principal; pub(super) mod counters; mod diagnostics; +mod store; use counters::{count, Counter::*}; struct Writer { outbox: Mutex, wake: tokio::sync::mpsc::Sender<()>, limits: Mutex, + store: store::Store, } static SENDER: OnceLock = OnceLock::new(); static CALLS: LazyLock>>>> = @@ -709,7 +711,7 @@ pub(crate) fn reply( } } -pub(crate) fn start(connection_file: PathBuf) { +pub(crate) fn start(connection_file: PathBuf, app: Arc, database: PathBuf) { if display_switch().is_err() { count(StartDisabled); return; @@ -728,6 +730,7 @@ pub(crate) fn start(connection_file: PathBuf) { outbox: Mutex::new(Outbox::new()), wake, limits: Mutex::new(outbox::ceilings()), + store: store::Store::new(app, database), }) .is_err() { @@ -1173,6 +1176,28 @@ pub(crate) fn with_outbox(f: impl FnOnce(&mut Outbox) -> T) -> Option { Some(f(&mut outbox)) } +pub(crate) async fn announce( + id: String, + bytes: Vec, + publish: impl std::future::Future>, +) -> Result<(), &'static str> { + let writer = SENDER.get().ok_or("display_store_not_started")?; + announce_retained(writer, id, bytes, publish).await +} + +async fn announce_retained( + writer: &Writer, + id: String, + bytes: Vec, + publish: impl std::future::Future>, +) -> Result<(), &'static str> { + if !writer.store.persist(id.clone(), bytes).await? { + return Err("display_store_deferred"); + } + publish.await?; + writer.store.acknowledged(id).await +} + pub(crate) fn check_reader( principal: Option<&Principal>, discovered: Option<&str>, @@ -1195,27 +1220,51 @@ pub(crate) async fn read( if !matches!(principal, Some(Principal::Reserved { .. })) { return check_reader(principal, None).map(|_| Vec::new()); } - if SENDER.get().is_none() { - return Err(cortexkit_role_tool_display::not_ready()); - } + let writer = SENDER + .get() + .ok_or_else(cortexkit_role_tool_display::not_ready)?; let discovered = crate::late_result_bus::display_reader()?; - check_reader(principal, discovered.as_deref())?; - with_outbox(|outbox| read_retained(outbox, arguments, Instant::now())) - .ok_or_else(cortexkit_role_tool_display::not_ready)? + read_for_reader( + writer, + principal, + discovered.as_deref(), + arguments, + Instant::now(), + crate::db::display_records::now_ms(), + ) + .await } -fn read_retained( - outbox: &Outbox, +async fn read_for_reader( + writer: &Writer, + principal: Option<&Principal>, + discovered: Option<&str>, arguments: Value, now: Instant, + now_ms: i64, ) -> Result, subc_protocol::ErrorBody> { - use cortexkit_role_tool_display::{DisplayRead, InvalidParams, DISPLAY_RECORD_UNKNOWN}; + check_reader(principal, discovered)?; + let request = read_request(arguments)?; + let memory = writer + .outbox + .try_lock() + .map_err(|_| cortexkit_role_tool_display::not_ready())? + .reads + .read(&request.record_id, now); + if let Some(bytes) = memory { + return Ok(bytes); + } + writer.store.read(request.record_id, now_ms).await +} + +fn read_request( + arguments: Value, +) -> Result { + use cortexkit_role_tool_display::{DisplayRead, InvalidParams}; let request: DisplayRead = serde_json::from_value(arguments).map_err(|_| InvalidParams::new("record_id").refusal())?; request.validate().map_err(|error| error.refusal())?; - outbox.reads.read(&request.record_id, now).ok_or_else(|| { - subc_protocol::ErrorBody::new(DISPLAY_RECORD_UNKNOWN, "display record is unknown") - }) + Ok(request) } #[cfg(test)] diff --git a/crates/aft/src/subc/rich_ui/display/store.rs b/crates/aft/src/subc/rich_ui/display/store.rs new file mode 100644 index 0000000000..2746b2728a --- /dev/null +++ b/crates/aft/src/subc/rich_ui/display/store.rs @@ -0,0 +1,63 @@ +//! Database work for display delivery runs off the async executor and reply path. +use std::path::PathBuf; +use std::sync::Arc; + +use crate::context::App; +use crate::db::display_records; + +pub(super) struct Store { + app: Arc, + database: PathBuf, +} + +impl Store { + pub(super) fn new(app: Arc, database: PathBuf) -> Self { + Self { app, database } + } + + async fn run( + &self, + action: impl FnOnce(&rusqlite::Connection) -> rusqlite::Result + Send + 'static, + ) -> Result { + let app = self.app.clone(); + let database = self.database.clone(); + tokio::task::spawn_blocking(move || { + let db = app.open_db(&database).map_err(|_| "display_store_open")?; + let conn = db.try_lock().map_err(|_| "display_store_busy")?; + action(&conn).map_err(|_| "display_store_query") + }) + .await + .map_err(|_| "display_store_worker")? + } + + pub(super) async fn persist(&self, id: String, bytes: Vec) -> Result { + self.run(move |conn| display_records::persist(conn, &id, &bytes, display_records::now_ms())) + .await + } + + pub(super) async fn acknowledged(&self, id: String) -> Result<(), &'static str> { + self.run(move |conn| display_records::acknowledged(conn, &id, display_records::now_ms())) + .await + } + + pub(super) async fn read( + &self, + id: String, + at_ms: i64, + ) -> Result, subc_protocol::ErrorBody> { + match self + .run(move |conn| display_records::read(conn, &id, at_ms)) + .await + { + Ok(Some(bytes)) => Ok(bytes), + Ok(None) => Err(subc_protocol::ErrorBody::new( + cortexkit_role_tool_display::DISPLAY_RECORD_UNKNOWN, + "display record is unknown", + )), + Err(code) => { + log::warn!("display pull store unavailable: {code}"); + Err(cortexkit_role_tool_display::not_ready()) + } + } + } +} diff --git a/crates/aft/src/subc/rich_ui/display/tests.rs b/crates/aft/src/subc/rich_ui/display/tests.rs index b6a780f682..df326fb232 100644 --- a/crates/aft/src/subc/rich_ui/display/tests.rs +++ b/crates/aft/src/subc/rich_ui/display/tests.rs @@ -29,13 +29,25 @@ fn display_read_authorizes_only_the_single_attested_display_module() { } } -#[test] -fn display_read_unknown_and_invalid_ids_have_contract_refusals() { - let outbox = Outbox::new(); +#[tokio::test] +async fn display_read_unknown_and_invalid_ids_have_contract_refusals() { + let dir = tempfile::tempdir().unwrap(); + let writer = test_writer(dir.path().join("aft.db")); + let reader = Principal::Reserved { + module_id: "reader".into(), + }; assert_eq!( - read_retained(&outbox, json!({"record_id":"missing"}), Instant::now()) - .unwrap_err() - .code, + read_for_reader( + &writer, + Some(&reader), + Some("reader"), + json!({"record_id":"missing"}), + Instant::now(), + 0 + ) + .await + .unwrap_err() + .code, cortexkit_role_tool_display::DISPLAY_RECORD_UNKNOWN ); for arguments in [ @@ -43,7 +55,16 @@ fn display_read_unknown_and_invalid_ids_have_contract_refusals() { json!({"record_id":"bad id"}), json!({"record_id":"ok","extra":1}), ] { - let error = read_retained(&outbox, arguments, Instant::now()).unwrap_err(); + let error = read_for_reader( + &writer, + Some(&reader), + Some("reader"), + arguments, + Instant::now(), + 0, + ) + .await + .unwrap_err(); assert_eq!(error.code, cortexkit_role_tool_display::INVALID_PARAMS); assert_eq!(error.detail.unwrap()["field"], "record_id"); } @@ -531,6 +552,7 @@ fn blocked_display_and_full_wake_queue_never_delay_a_reply() { outbox: Mutex::new(Outbox::new()), wake, limits: Mutex::new(outbox::ceilings()), + store: store::Store::new(crate::context::App::default_shared(), PathBuf::new()), }; let identity = Identity { runner: Principal::Reserved { @@ -956,3 +978,268 @@ fn a_running_hold_preserves_observed_remote_execution() { assert_eq!(writes[0].body["target"], "linux"); assert!(writes[0].body.get("endReason").is_none()); } + +fn test_writer(database: PathBuf) -> Writer { + let (wake, _receiver) = tokio::sync::mpsc::channel(1); + Writer { + outbox: Mutex::new(Outbox::new()), + wake, + limits: Mutex::new(outbox::ceilings()), + store: store::Store::new(crate::context::App::default_shared(), database), + } +} + +#[tokio::test] +async fn display_read_restart_reopens_identical_frozen_bytes_and_preserves_reader_denial() { + let dir = tempfile::tempdir().unwrap(); + let path = dir.path().join("aft.db"); + let writer = test_writer(path.clone()); + let now = Instant::now(); + let (id, expected) = { + let mut outbox = writer.outbox.lock().unwrap(); + assert!(outbox.admit( + Identity { + runner: Principal::Reserved { + module_id: "runner".into() + }, + call_key: "restart:call".into(), + schema_pin: "pin:1".into(), + }, + DisplayKind::Detail, + json!({"nested":{"text":"original output: é \\n", "number":1.5},"rows":[1,2,3]}), + &outbox::ceilings(), + now, + )); + let id = outbox.reads.due(now).unwrap(); + let bytes = outbox.reads.read(&id, now).unwrap(); + (id, bytes) + }; + announce_retained(&writer, id.clone(), expected.clone(), async { + // The bus may expose the wake immediately: its first observer must + // already be able to fetch the committed, byte-identical pull reply. + let conn = rusqlite::Connection::open(&path).unwrap(); + let (bytes, ack): (Vec, Option) = conn + .query_row( + "SELECT pull_bytes,wake_acked_at_ms FROM display_records WHERE record_id=?1", + [&id], + |row| Ok((row.get(0)?, row.get(1)?)), + ) + .unwrap(); + assert_eq!(bytes, expected); + assert_eq!(ack, None); + Ok(()) + }) + .await + .unwrap(); + writer + .outbox + .lock() + .unwrap() + .reads + .published(&id, true, now); + drop(writer); + let reopened = crate::db::open(&path).unwrap(); + let ack: i64 = reopened + .query_row( + "SELECT wake_acked_at_ms FROM display_records WHERE record_id=?1", + [&id], + |row| row.get(0), + ) + .unwrap(); + drop(reopened); + // A fresh service has no process-local copies or replay queue. + let restarted = test_writer(path); + assert!(restarted + .outbox + .lock() + .unwrap() + .reads + .read(&id, now) + .is_none()); + let reader = Principal::Reserved { + module_id: "reader".into(), + }; + let args = json!({"record_id":id}); + assert_eq!( + read_for_reader( + &restarted, + Some(&reader), + Some("reader"), + args.clone(), + now, + ack + 600_000 + ) + .await + .unwrap(), + expected + ); + assert_eq!( + read_for_reader( + &restarted, + Some(&reader), + Some("reader"), + args.clone(), + now, + ack + 600_001 + ) + .await + .unwrap_err() + .code, + cortexkit_role_tool_display::DISPLAY_RECORD_UNKNOWN + ); + let other = Principal::Reserved { + module_id: "other".into(), + }; + for principal in [&other, &Principal::Direct, &Principal::Unverified] { + assert_eq!( + read_for_reader( + &restarted, + Some(principal), + Some("reader"), + args.clone(), + now, + ack + 1 + ) + .await + .unwrap_err() + .code, + cortexkit_role_tool_display::DISPLAY_READ_DENIED + ); + } + assert_eq!( + read_for_reader(&restarted, Some(&reader), None, args, now, ack + 1) + .await + .unwrap_err() + .code, + cortexkit_role_tool_display::DISPLAY_READ_DENIED + ); +} + +#[tokio::test] +async fn display_read_memory_hit_never_opens_the_store() { + let dir = tempfile::tempdir().unwrap(); + // A directory cannot be opened as a SQLite database. A memory hit must + // still succeed, without depending on the durable fallback's availability. + let writer = test_writer(dir.path().to_path_buf()); + let now = Instant::now(); + let (id, bytes) = { + let mut outbox = writer.outbox.lock().unwrap(); + assert!(outbox.admit( + Identity { + runner: Principal::Reserved { + module_id: "runner".into() + }, + call_key: "memory:call".into(), + schema_pin: "pin:1".into() + }, + DisplayKind::Record, + json!({"durationMs":1,"outcome":"success"}), + &outbox::ceilings(), + now + )); + let id = outbox.reads.due(now).unwrap(); + let bytes = outbox.reads.read(&id, now).unwrap(); + (id, bytes) + }; + let reader = Principal::Reserved { + module_id: "reader".into(), + }; + assert_eq!( + read_for_reader( + &writer, + Some(&reader), + Some("reader"), + json!({"record_id":id}), + now, + 0 + ) + .await + .unwrap(), + bytes + ); +} + +#[tokio::test] +async fn display_read_protected_capacity_defers_wake_but_never_blocks_push() { + let dir = tempfile::tempdir().unwrap(); + let path = dir.path().join("aft.db"); + let now = crate::db::display_records::now_ms(); + let conn = crate::db::open(&path).unwrap(); + for index in 0..crate::db::display_records::MAX_RECORDS { + assert!(crate::db::display_records::persist( + &conn, + &format!("protected:{index}"), + b"first", + now + ) + .unwrap()); + } + drop(conn); + let writer = test_writer(path.clone()); + let at = Instant::now(); + let (id, bytes) = { + let mut outbox = writer.outbox.lock().unwrap(); + assert!(outbox.admit( + Identity { + runner: Principal::Reserved { + module_id: "runner".into() + }, + call_key: "deferred:call".into(), + schema_pin: "pin:1".into() + }, + DisplayKind::Record, + json!({"durationMs":1,"outcome":"success"}), + &outbox::ceilings(), + at + )); + let id = outbox.reads.due(at).unwrap(); + let bytes = outbox.reads.read(&id, at).unwrap(); + (id, bytes) + }; + let published = std::sync::atomic::AtomicBool::new(false); + let result = announce_retained(&writer, id.clone(), bytes, async { + published.store(true, std::sync::atomic::Ordering::Relaxed); + Ok(()) + }) + .await; + assert_eq!(result, Err("display_store_deferred")); + assert!( + !published.load(std::sync::atomic::Ordering::Relaxed), + "a wake must not publish without durable capacity" + ); + assert!( + writer.outbox.lock().unwrap().pop_due(at).is_some(), + "push ownership is independent of a deferred wake" + ); + let conn = rusqlite::Connection::open(path).unwrap(); + assert_eq!( + conn.query_row("SELECT count(*) FROM display_records", [], |row| row + .get::<_, usize>(0)) + .unwrap(), + crate::db::display_records::MAX_RECORDS + ); + assert!(crate::db::display_records::read(&conn, &id, now) + .unwrap() + .is_none()); +} + +#[tokio::test] +async fn display_read_uncertain_publish_keeps_an_unacked_durable_copy() { + let dir = tempfile::tempdir().unwrap(); + let path = dir.path().join("aft.db"); + let writer = test_writer(path.clone()); + assert_eq!( + announce_retained(&writer, "uncertain".into(), b"frozen".to_vec(), async { + Err("display_bus_timeout") + }) + .await, + Err("display_bus_timeout") + ); + let conn = rusqlite::Connection::open(path).unwrap(); + let (attempt, ack): (i64, Option) = conn.query_row("SELECT announced_at_ms,wake_acked_at_ms FROM display_records WHERE record_id='uncertain'", [], |row| Ok((row.get(0)?,row.get(1)?))).unwrap(); + assert_eq!(ack, None); + assert_eq!( + crate::db::display_records::read(&conn, "uncertain", attempt + 600_001).unwrap(), + Some(b"frozen".to_vec()) + ); +} diff --git a/crates/aft/src/subc/rich_ui/outbox/reads.rs b/crates/aft/src/subc/rich_ui/outbox/reads.rs index b006e397e3..878586f5b6 100644 --- a/crates/aft/src/subc/rich_ui/outbox/reads.rs +++ b/crates/aft/src/subc/rich_ui/outbox/reads.rs @@ -1,4 +1,5 @@ //! Process-local pull copies, independent of ownership during a push attempt. +//! Announced records also have a protected database fallback in display::store. use std::collections::HashMap; use std::time::{Duration, Instant}; @@ -295,7 +296,7 @@ mod tests { } #[test] - fn display_read_restart_has_no_records_or_replay() { + fn display_read_restart_has_no_memory_records_or_replay() { let now = Instant::now(); let mut outbox = Outbox::new(); let id = admit(&mut outbox, "call:1", DisplayKind::Record, now); diff --git a/docs/tool-display.md b/docs/tool-display.md index e6c7a44a96..d2fa2ee9de 100644 --- a/docs/tool-display.md +++ b/docs/tool-display.md @@ -6,10 +6,28 @@ delaying tool replies. AFT also announces each record on the CortexKit bus; the display server can fetch the same data with `display.read` after receiving that wake. Existing pushes remain unchanged. -Records remain readable throughout push delivery and for at least ten minutes -after the wake is acknowledged. Bounded-memory pressure can evict older records -earlier, and discarded optional details become unavailable immediately. Expired, -evicted or discarded records return `display_record_unknown`. +Before announcing a record, AFT commits the exact `display.read` reply bytes to +its private `aft.db` delivery cache. Reads check memory first, then that cache, +under the existing route checks: the caller must be the daemon-attested module +uniquely declaring `tool-display/v1`, on an admitted management route rather than +a project-free or ordinary tool route. Restarting AFT does not lose an announced +record's durable read window. -Nothing is stored on disk. A restart loses all retained display records; reads -of those identifiers return `display_record_unknown` and no wakes are replayed. +Acknowledged wakes protect their records through ten minutes after the bus +acknowledgement. Unacknowledged wakes, including uncertain publish outcomes, +protect their records for 24 hours after the latest attempted announcement. +Memory may retain a record longer while its push remains live. Expired or +never-retained identifiers return `display_record_unknown`; no wakes are replayed +from the cache after restart. + +The durable cache holds at most 192 records and 16 MiB of pull bytes. AFT reclaims +expired rows first and never evicts protected rows. When protected records fill +the cache, AFT defers new wake announcements and logs the deferred count and byte +usage; existing `display.write` pushes continue independently. Bounded expiry +sweeps run on writable database opens and the regular retention tick. Read-only +or older databases without the optional cache use memory only. + +This optional cache adds no numbered database migration and changes neither +`schema_version` nor the reader floor (the per-store minimum format versions a +build must support to open the storage root). Older AFT builds ignore the cache, so rolling +back remains a binary swap. From 2d4d596ecbb506d74c7ce075d6b2c20bffbb3d75 Mon Sep 17 00:00:00 2001 From: ualtinok <94532+ualtinok@users.noreply.github.com> Date: Wed, 18 Nov 2026 01:32:19 +0100 Subject: [PATCH 06/26] mason: fix display cache schema-version test helper Co-authored-by: alfonso-aft <289616620+alfonso-aft@users.noreply.github.com> --- crates/aft/src/db/display_records/tests.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/aft/src/db/display_records/tests.rs b/crates/aft/src/db/display_records/tests.rs index 590988a43d..a71d90aaaa 100644 --- a/crates/aft/src/db/display_records/tests.rs +++ b/crates/aft/src/db/display_records/tests.rs @@ -70,7 +70,7 @@ fn display_read_cache_fresh_upgrade_and_rollback_keep_schema29_and_reader_floor( let dir = tempfile::tempdir().unwrap(); let path = dir.path().join("aft.db"); let fresh = crate::db::open(&path).unwrap(); - assert_eq!(crate::db::schema_version(&fresh), 29); + assert_eq!(crate::db::current_schema_version(&fresh).unwrap(), 29); assert!(available(&fresh).unwrap()); // Model an existing schema-29 database that predates the optional cache. fresh.execute_batch("DROP TABLE display_records").unwrap(); @@ -87,7 +87,7 @@ fn display_read_cache_fresh_upgrade_and_rollback_keep_schema29_and_reader_floor( let upgraded = crate::db::open(&path).unwrap(); let now = now_ms(); assert!(persist(&upgraded, "retained", b"opaque pull bytes", now).unwrap()); - assert_eq!(crate::db::schema_version(&upgraded), 29); + assert_eq!(crate::db::current_schema_version(&upgraded).unwrap(), 29); assert_eq!(std::fs::read(&floor_path).unwrap(), floor_before); drop(upgraded); // The rollback build uses these unchanged version checks. It never needs From f57d63c1bdaced4a19045a84f3a3b56b276941f9 Mon Sep 17 00:00:00 2001 From: ualtinok <94532+ualtinok@users.noreply.github.com> Date: Wed, 18 Nov 2026 02:16:10 +0100 Subject: [PATCH 07/26] mason: wait for display store locks and prove sustained deferrals Blocking database work waits for the process-wide connection mutex instead of refusing ordinary contention; pull reads also wait for the brief outbox lock. Poisoned locks still refuse. Reply-side optional enqueue stays nonblocking. Wake completion already uses ReadCache backoff rather than the push outbox's eight-attempt budget. Document the separation and extend the capacity regression to twelve deferrals followed by successful publication after one protected row expires, asserting the push attempt count remains zero. Co-authored-by: alfonso-aft <289616620+alfonso-aft@users.noreply.github.com> --- crates/aft/src/late_result_bus/display.rs | 2 + crates/aft/src/subc/rich_ui/display.rs | 2 +- crates/aft/src/subc/rich_ui/display/store.rs | 2 +- crates/aft/src/subc/rich_ui/display/tests.rs | 79 +++++++++++++++----- 4 files changed, 66 insertions(+), 19 deletions(-) diff --git a/crates/aft/src/late_result_bus/display.rs b/crates/aft/src/late_result_bus/display.rs index b138306f88..aab3932d24 100644 --- a/crates/aft/src/late_result_bus/display.rs +++ b/crates/aft/src/late_result_bus/display.rs @@ -159,6 +159,8 @@ pub(super) async fn publish_one(client: &BusClient) { } fn completed(id: &str, result: Result<(), &'static str>) { + // Wake backoff is separate from Outbox::retry's push attempt budget. + // A full store may defer a wake indefinitely without exhausting its pushes. crate::subc::rich_ui::display::with_outbox(|outbox| { outbox .reads diff --git a/crates/aft/src/subc/rich_ui/display.rs b/crates/aft/src/subc/rich_ui/display.rs index 99784b1ac7..434ff9f761 100644 --- a/crates/aft/src/subc/rich_ui/display.rs +++ b/crates/aft/src/subc/rich_ui/display.rs @@ -1247,7 +1247,7 @@ async fn read_for_reader( let request = read_request(arguments)?; let memory = writer .outbox - .try_lock() + .lock() .map_err(|_| cortexkit_role_tool_display::not_ready())? .reads .read(&request.record_id, now); diff --git a/crates/aft/src/subc/rich_ui/display/store.rs b/crates/aft/src/subc/rich_ui/display/store.rs index 2746b2728a..da8af4176d 100644 --- a/crates/aft/src/subc/rich_ui/display/store.rs +++ b/crates/aft/src/subc/rich_ui/display/store.rs @@ -23,7 +23,7 @@ impl Store { let database = self.database.clone(); tokio::task::spawn_blocking(move || { let db = app.open_db(&database).map_err(|_| "display_store_open")?; - let conn = db.try_lock().map_err(|_| "display_store_busy")?; + let conn = db.lock().map_err(|_| "display_store_poisoned")?; action(&conn).map_err(|_| "display_store_query") }) .await diff --git a/crates/aft/src/subc/rich_ui/display/tests.rs b/crates/aft/src/subc/rich_ui/display/tests.rs index df326fb232..5044ed9b9b 100644 --- a/crates/aft/src/subc/rich_ui/display/tests.rs +++ b/crates/aft/src/subc/rich_ui/display/tests.rs @@ -1160,7 +1160,7 @@ async fn display_read_memory_hit_never_opens_the_store() { } #[tokio::test] -async fn display_read_protected_capacity_defers_wake_but_never_blocks_push() { +async fn display_read_protected_capacity_retries_past_eight_deferrals_then_announces() { let dir = tempfile::tempdir().unwrap(); let path = dir.path().join("aft.db"); let now = crate::db::display_records::now_ms(); @@ -1196,22 +1196,31 @@ async fn display_read_protected_capacity_defers_wake_but_never_blocks_push() { let bytes = outbox.reads.read(&id, at).unwrap(); (id, bytes) }; - let published = std::sync::atomic::AtomicBool::new(false); - let result = announce_retained(&writer, id.clone(), bytes, async { - published.store(true, std::sync::atomic::Ordering::Relaxed); - Ok(()) - }) - .await; - assert_eq!(result, Err("display_store_deferred")); - assert!( - !published.load(std::sync::atomic::Ordering::Relaxed), - "a wake must not publish without durable capacity" - ); - assert!( - writer.outbox.lock().unwrap().pop_due(at).is_some(), - "push ownership is independent of a deferred wake" - ); - let conn = rusqlite::Connection::open(path).unwrap(); + let published = std::sync::atomic::AtomicUsize::new(0); + let mut retry_at = at; + for _ in 0..12 { + assert_eq!( + writer.outbox.lock().unwrap().reads.due(retry_at), + Some(id.clone()) + ); + let result = announce_retained(&writer, id.clone(), bytes.clone(), async { + published.fetch_add(1, std::sync::atomic::Ordering::Relaxed); + Ok(()) + }) + .await; + assert_eq!(result, Err("display_store_deferred")); + // Use the same wake-only completion path as the bus publisher; it + // reschedules the read copy without spending a push delivery attempt. + writer + .outbox + .lock() + .unwrap() + .reads + .published(&id, result.is_ok(), retry_at); + retry_at += Duration::from_secs(60); + } + assert_eq!(published.load(std::sync::atomic::Ordering::Relaxed), 0); + let conn = rusqlite::Connection::open(&path).unwrap(); assert_eq!( conn.query_row("SELECT count(*) FROM display_records", [], |row| row .get::<_, usize>(0)) @@ -1221,6 +1230,42 @@ async fn display_read_protected_capacity_defers_wake_but_never_blocks_push() { assert!(crate::db::display_records::read(&conn, &id, now) .unwrap() .is_none()); + // Let exactly one protected row expire; every other row is still protected. + crate::db::display_records::acknowledged( + &conn, + "protected:0", + crate::db::display_records::now_ms() - 600_001, + ) + .unwrap(); + drop(conn); + assert_eq!( + writer.outbox.lock().unwrap().reads.due(retry_at), + Some(id.clone()) + ); + let result = announce_retained(&writer, id.clone(), bytes.clone(), async { + published.fetch_add(1, std::sync::atomic::Ordering::Relaxed); + Ok(()) + }) + .await; + assert_eq!(result, Ok(())); + writer + .outbox + .lock() + .unwrap() + .reads + .published(&id, result.is_ok(), retry_at); + assert_eq!(published.load(std::sync::atomic::Ordering::Relaxed), 1); + assert!(writer.outbox.lock().unwrap().reads.due(retry_at).is_none()); + let push = writer.outbox.lock().unwrap().pop_due(retry_at).unwrap(); + assert_eq!( + push.attempts, 0, + "wake deferrals never consume push attempts" + ); + let conn = rusqlite::Connection::open(path).unwrap(); + assert_eq!( + crate::db::display_records::read(&conn, &id, crate::db::display_records::now_ms()).unwrap(), + Some(bytes) + ); } #[tokio::test] From 4f7cebebaa825426f437231e725e0c939ef9ed09 Mon Sep 17 00:00:00 2001 From: ualtinok <94532+ualtinok@users.noreply.github.com> Date: Wed, 18 Nov 2026 02:33:45 +0100 Subject: [PATCH 08/26] mason: derive display startup paths inside display module Borrow startup inputs and derive the aft.db path in display::start, restoring the central subc module's pinned hand-written line budget without raising its limit. Co-authored-by: alfonso-aft <289616620+alfonso-aft@users.noreply.github.com> --- crates/aft/src/subc/mod.rs | 6 +----- crates/aft/src/subc/rich_ui/display.rs | 6 +++--- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/crates/aft/src/subc/mod.rs b/crates/aft/src/subc/mod.rs index 8c0be0ff36..e1eeaff625 100644 --- a/crates/aft/src/subc/mod.rs +++ b/crates/aft/src/subc/mod.rs @@ -5483,11 +5483,7 @@ where } }); } - rich_ui::display::start( - connection_file_path.to_path_buf(), - shared_app.clone(), - storage_dir.join("aft.db"), - ); + rich_ui::display::start(connection_file_path, &shared_app, &storage_dir); runner_notices::install(connection_file_path.to_path_buf()); let push_senders = PushSenders { lossy_tx, diff --git a/crates/aft/src/subc/rich_ui/display.rs b/crates/aft/src/subc/rich_ui/display.rs index 434ff9f761..12ff39b2f6 100644 --- a/crates/aft/src/subc/rich_ui/display.rs +++ b/crates/aft/src/subc/rich_ui/display.rs @@ -711,7 +711,7 @@ pub(crate) fn reply( } } -pub(crate) fn start(connection_file: PathBuf, app: Arc, database: PathBuf) { +pub(crate) fn start(connection_file: &Path, app: &Arc, storage_dir: &Path) { if display_switch().is_err() { count(StartDisabled); return; @@ -730,14 +730,14 @@ pub(crate) fn start(connection_file: PathBuf, app: Arc, dat outbox: Mutex::new(Outbox::new()), wake, limits: Mutex::new(outbox::ceilings()), - store: store::Store::new(app, database), + store: store::Store::new(app.clone(), storage_dir.join("aft.db")), }) .is_err() { count(StartExisting); return; } - tokio::spawn(send_loop(connection_file, receiver)); + tokio::spawn(send_loop(connection_file.to_path_buf(), receiver)); count(Started); } From f27f64bc30c26e2a303b73fcfbd098c416dce648 Mon Sep 17 00:00:00 2001 From: ualtinok <94532+ualtinok@users.noreply.github.com> Date: Wed, 18 Nov 2026 09:34:49 +0100 Subject: [PATCH 09/26] mason: support storage leases on older Linux kernels (#1468) Co-authored-by: alfonso-aft <289616620+alfonso-aft@users.noreply.github.com> --- .../next/issue-1468-old-kernel-mount-id.md | 1 + .../bash_background/linux_mount_identity.rs | 109 ++++++++++++++++++ crates/aft/src/bash_background/persistence.rs | 44 +++---- 3 files changed, 125 insertions(+), 29 deletions(-) create mode 100644 .alfonso/release-notes/next/issue-1468-old-kernel-mount-id.md create mode 100644 crates/aft/src/bash_background/linux_mount_identity.rs diff --git a/.alfonso/release-notes/next/issue-1468-old-kernel-mount-id.md b/.alfonso/release-notes/next/issue-1468-old-kernel-mount-id.md new file mode 100644 index 0000000000..f9980d0f04 --- /dev/null +++ b/.alfonso/release-notes/next/issue-1468-old-kernel-mount-id.md @@ -0,0 +1 @@ +Fixed AFT startup on older Linux kernels, including RHEL 8, while preserving storage lease mount-boundary checks. diff --git a/crates/aft/src/bash_background/linux_mount_identity.rs b/crates/aft/src/bash_background/linux_mount_identity.rs new file mode 100644 index 0000000000..e597eb2633 --- /dev/null +++ b/crates/aft/src/bash_background/linux_mount_identity.rs @@ -0,0 +1,109 @@ +use std::fs::{self, File}; +use std::io; +use std::os::fd::AsRawFd; + +// Including the source in equality makes a mixed-source comparison refuse. +#[derive(Debug, PartialEq, Eq)] +pub(super) enum MountIdentity { + Statx(u64), + Fdinfo(u64), +} + +pub(super) fn file_mount_identity(file: &File) -> io::Result { + mount_identity_from_statx(file, statx_mount_id(file)) +} + +fn statx_mount_id(file: &File) -> io::Result> { + let mut stat = std::mem::MaybeUninit::::zeroed(); + // The glibc statx wrapper requires glibc 2.28, newer than the release binary requires. + if unsafe { + libc::syscall( + libc::SYS_statx, + file.as_raw_fd(), + c"".as_ptr(), + libc::AT_EMPTY_PATH | libc::AT_SYMLINK_NOFOLLOW, + libc::STATX_MNT_ID, + stat.as_mut_ptr(), + ) + } != 0 + { + return Err(io::Error::last_os_error()); + } + let stat = unsafe { stat.assume_init() }; + Ok((stat.stx_mask & libc::STATX_MNT_ID != 0).then_some(stat.stx_mnt_id)) +} + +fn mount_identity_from_statx( + file: &File, + statx: io::Result>, +) -> io::Result { + match statx { + Ok(Some(id)) => return Ok(MountIdentity::Statx(id)), + Ok(None) => {} + Err(error) if error.raw_os_error() == Some(libc::ENOSYS) => {} + Err(error) => return Err(error), + } + + // fdinfo reports the mountinfo ID for the open descriptor. Unlike + // name_to_handle_at, it also works on filesystems without export support. + fs::read(format!("/proc/self/fdinfo/{}", file.as_raw_fd())) + .ok() + .and_then(|data| parse_fdinfo_mount_id(&data)) + .map(MountIdentity::Fdinfo) + .ok_or_else(|| io::Error::other("kernel cannot verify repair mount boundary")) +} + +fn parse_fdinfo_mount_id(data: &[u8]) -> Option { + let mut fields = data + .split(|&byte| byte == b'\n') + .filter_map(|line| line.strip_prefix(b"mnt_id:")); + let value = std::str::from_utf8(fields.next()?) + .ok()? + .trim_matches([' ', '\t']); + if fields.next().is_some() || value.is_empty() || !value.bytes().all(|b| b.is_ascii_digit()) { + return None; + } + value.parse().ok() +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn linux_mount_identity_parses_exactly_one_decimal_fdinfo_mount_id() { + assert_eq!( + parse_fdinfo_mount_id(b"pos:\t0\nflags:\t0100000\nmnt_id:\t42\nino:\t7\n"), + Some(42) + ); + for invalid in [ + &b"pos:\t0\n"[..], + b"mnt_id:\t42\nmnt_id:\t42\n", + b"mnt_id:\tabc\n", + b"mnt_id:\t18446744073709551616\n", + b"mnt_id:\t+42\n", + b"mnt_id:\t\n", + ] { + assert_eq!(parse_fdinfo_mount_id(invalid), None, "{invalid:?}"); + } + } + + #[test] + fn linux_mount_identity_falls_back_to_fdinfo_without_mixing_sources() { + let dir = tempfile::tempdir().unwrap(); + let first = File::open(dir.path()).unwrap(); + let second = File::create(dir.path().join("child")).unwrap(); + let statx = file_mount_identity(&first).unwrap(); + let MountIdentity::Statx(id) = statx else { + panic!("this test requires statx mount IDs to verify the fallback"); + }; + + let missing_mask = mount_identity_from_statx(&first, Ok(None)).unwrap(); + let missing_syscall = + mount_identity_from_statx(&second, Err(io::Error::from_raw_os_error(libc::ENOSYS))) + .unwrap(); + assert_eq!(missing_mask, MountIdentity::Fdinfo(id)); + assert_eq!(missing_mask, missing_syscall); + assert_ne!(statx, missing_mask); + } +} diff --git a/crates/aft/src/bash_background/persistence.rs b/crates/aft/src/bash_background/persistence.rs index 47e73abfbd..6f6923636d 100644 --- a/crates/aft/src/bash_background/persistence.rs +++ b/crates/aft/src/bash_background/persistence.rs @@ -8,6 +8,14 @@ pub(crate) use scope_records::{ }; pub use scope_records::{read_task_at, write_task}; +#[cfg(target_os = "linux")] +#[path = "linux_mount_identity.rs"] +mod linux_mount_identity; +#[cfg(target_os = "linux")] +use linux_mount_identity::MountIdentity; +#[cfg(not(target_os = "linux"))] +type MountIdentity = (u64, Vec); + #[cfg(unix)] use std::ffi::CString; use std::ffi::{OsStr, OsString}; @@ -739,9 +747,12 @@ impl PinnedDir { } result } - fn repair_mount_identity(&self) -> io::Result<(u64, Vec)> { + fn repair_mount_identity(&self) -> io::Result { #[cfg(test)] if let Some(mount) = REPAIR_MOUNTS.with(|ids| ids.borrow().get(self.path()).copied()) { + #[cfg(target_os = "linux")] + return Ok(MountIdentity::Statx(mount)); + #[cfg(not(target_os = "linux"))] return Ok((mount, Vec::new())); } file_mount_identity(&self.file) @@ -1683,35 +1694,10 @@ fn file_identity(file: &File) -> io::Result<(u64, u64)> { } } -fn file_mount_identity(file: &File) -> io::Result<(u64, Vec)> { +fn file_mount_identity(file: &File) -> io::Result { #[cfg(target_os = "linux")] { - let mut stat = std::mem::MaybeUninit::::zeroed(); - // Call statx through syscall(2), not glibc's wrapper: the wrapper only - // exists from glibc 2.28, and the Linux release binary is linked - // against an older glibc so it runs on older distributions. A kernel - // without statx fails with ENOSYS, which refuses the repair like any - // other unverifiable mount boundary. - if unsafe { - libc::syscall( - libc::SYS_statx, - file.as_raw_fd(), - c"".as_ptr(), - libc::AT_EMPTY_PATH | libc::AT_SYMLINK_NOFOLLOW, - libc::STATX_MNT_ID, - stat.as_mut_ptr(), - ) - } != 0 - { - return Err(io::Error::last_os_error()); - } - let stat = unsafe { stat.assume_init() }; - if stat.stx_mask & libc::STATX_MNT_ID == 0 { - return Err(io::Error::other( - "kernel cannot verify repair mount boundary", - )); - } - Ok((stat.stx_mnt_id, Vec::new())) + linux_mount_identity::file_mount_identity(file) } #[cfg(target_os = "macos")] { @@ -4078,7 +4064,7 @@ fn repair_errno_location() -> *mut libc::c_int { struct RepairPolicy<'a> { device: u64, - mount: (u64, Vec), + mount: MountIdentity, protected: &'a [(u64, u64)], /// Stop at a symlink or special file instead of unlinking it. Used when a /// tree is removed without a complete validation walk first. From eab3d590113b2b373261c52ca691c0fdd148a5ec Mon Sep 17 00:00:00 2001 From: ualtinok <94532+ualtinok@users.noreply.github.com> Date: Wed, 18 Nov 2026 09:52:14 +0100 Subject: [PATCH 10/26] mason: ratchet the storage persistence file size pin Co-authored-by: alfonso-aft <289616620+alfonso-aft@users.noreply.github.com> --- scripts/file-size-pins.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/file-size-pins.json b/scripts/file-size-pins.json index 3f2b21a436..1c0c7d2de7 100644 --- a/scripts/file-size-pins.json +++ b/scripts/file-size-pins.json @@ -64,7 +64,7 @@ "reason": "Split checkout lifecycle and storage pending; AFT crate split lane." }, "crates/aft/src/bash_background/persistence.rs": { - "lines": 6429, + "lines": 6415, "reason": "Split background-task persistence responsibilities pending; AFT crate split lane." }, "crates/aft/src/bash_background/remote.rs": { From a6ce024093fe04c86a2d04c0fb1cdf0c7cf0b76e Mon Sep 17 00:00:00 2001 From: ualtinok <94532+ualtinok@users.noreply.github.com> Date: Wed, 18 Nov 2026 12:28:42 +0100 Subject: [PATCH 11/26] shells: admit the person's desktop app paired from another computer Callosum relays a desktop app paired to this computer as reserved:callosum with a fed-app: harness. It gets the same view-only shells operations as the person's phone. Other federated harnesses stay refused. Co-authored-by: alfonso-aft <289616620+alfonso-aft@users.noreply.github.com> --- crates/aft/src/subc/shells/admission.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/crates/aft/src/subc/shells/admission.rs b/crates/aft/src/subc/shells/admission.rs index a56357ce96..5df986f97f 100644 --- a/crates/aft/src/subc/shells/admission.rs +++ b/crates/aft/src/subc/shells/admission.rs @@ -38,6 +38,8 @@ pub(super) fn caller_kind( match harness { Some(harness) if harness.starts_with("fed-phone:") => "phone", Some(harness) if harness.starts_with("fed-sim:") => "simulator", + // A desktop app reaching this computer from another one. + Some(harness) if harness.starts_with("fed-app:") => "remote-app", _ => "desktop", } } @@ -52,7 +54,8 @@ pub(in crate::subc) fn operator_refusal(body: &Value) -> ErrorBody { error } -/// Federated agent routes must never inherit the phone operator's authority. +/// Federated agent routes must never inherit the operator's authority: only +/// the person's own paired phone, simulator or desktop app may view shells. /// Keep this predicate shared by route admission and request dispatch. pub(in crate::subc) fn operator( principal: Option<&Principal>, @@ -63,8 +66,11 @@ pub(in crate::subc) fn operator( && (matches!(principal, Some(Principal::Direct)) && !harness.is_some_and(crate::subc::harness_forces_untrusted) || matches!(principal, Some(Principal::Reserved { module_id }) if module_id == "callosum") - && harness - .is_some_and(|h| h.starts_with("fed-phone:") || h.starts_with("fed-sim:"))) + && harness.is_some_and(|h| { + h.starts_with("fed-phone:") + || h.starts_with("fed-sim:") + || h.starts_with("fed-app:") + })) } pub(in crate::subc) fn operator_required() -> ErrorBody { @@ -155,8 +161,10 @@ mod tests { (Some(&direct), Some("fed:facade"), false), (Some(&callosum), Some("fed-phone:person"), true), (Some(&callosum), Some("fed-sim:person"), true), + (Some(&callosum), Some("fed-app:person"), true), (Some(&callosum), Some("fed-computer:person"), false), (Some(&callosum), Some("fed-unknown:person"), false), + (Some(&callosum), Some("fed-application:person"), false), (Some(&callosum), Some("callosum-self"), false), (Some(&callosum), None, false), (None, Some("fed-phone:person"), false), From ca2b92b62658f0d5433efe42484ee2134ea166cb Mon Sep 17 00:00:00 2001 From: ualtinok <94532+ualtinok@users.noreply.github.com> Date: Wed, 18 Nov 2026 12:38:54 +0100 Subject: [PATCH 12/26] mason: install ONNX Runtime from NuGet Read only the pinned platform library and ZIP metadata by default. Keep the existing cache paths, aliases, and legacy macOS pin. Replace whole-archive extraction and copy fixture tests with coverage for the ranged download, atomic failure cleanup, and cache aliases and permissions, since archives no longer supply filesystem paths. Co-authored-by: alfonso-aft <289616620+alfonso-aft@users.noreply.github.com> --- .../next/onnxruntime-nuget-source.md | 1 + crates/aft/src/ort_pin.rs | 74 +-- .../src/__tests__/async-maintenance.test.ts | 30 +- .../src/__tests__/onnx-cleanup.test.ts | 118 +---- .../__tests__/onnx-concurrent-install.test.ts | 227 +++++++-- .../src/__tests__/onnx-loadability.test.ts | 2 +- .../src/__tests__/private-storage.test.ts | 13 +- packages/aft-bridge/src/onnx-nuget.ts | 299 ++++++++++++ packages/aft-bridge/src/onnx-runtime.ts | 443 +++--------------- 9 files changed, 600 insertions(+), 607 deletions(-) create mode 100644 .alfonso/release-notes/next/onnxruntime-nuget-source.md create mode 100644 packages/aft-bridge/src/onnx-nuget.ts diff --git a/.alfonso/release-notes/next/onnxruntime-nuget-source.md b/.alfonso/release-notes/next/onnxruntime-nuget-source.md new file mode 100644 index 0000000000..3e9377c364 --- /dev/null +++ b/.alfonso/release-notes/next/onnxruntime-nuget-source.md @@ -0,0 +1 @@ +Restore automatic setup for local meaning search by downloading only the ONNX Runtime library your platform needs from Microsoft's NuGet package. diff --git a/crates/aft/src/ort_pin.rs b/crates/aft/src/ort_pin.rs index 8c128a4b1f..d3bf414369 100644 --- a/crates/aft/src/ort_pin.rs +++ b/crates/aft/src/ort_pin.rs @@ -9,8 +9,8 @@ //! the `com.apple.security.cs.disable-library-validation` entitlement. Hardened //! runtime is what keeps other processes of the same user from attaching a //! debugger and reading the module's launch secret; the entitlement is needed -//! because Microsoft's library carries no Team ID and library validation would -//! refuse it. With library validation off, the loader no longer checks who +//! because library validation would refuse a library that does not carry AFT's +//! Team ID. With library validation off, the loader no longer checks who //! signed the file, so without this pin any same-user process could replace //! the downloaded library and run its code inside AFT. //! @@ -91,12 +91,12 @@ use crate::semantic_index::ONNX_RUNTIME_MISSING_PREFIX; /// Environment variable naming the ONNX Runtime library to load. pub const ORT_DYLIB_PATH_ENV: &str = "ORT_DYLIB_PATH"; -/// One ONNX Runtime library build AFT's installer downloads. +/// One ONNX Runtime library build AFT accepts without an override. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct PinnedOrtLibrary { /// ONNX Runtime release version. pub version: &'static str, - /// Microsoft's release asset the library comes from. + /// Microsoft's package or legacy release asset the library comes from. pub asset: &'static str, /// Path of the library inside that asset. pub library: &'static str, @@ -106,15 +106,13 @@ pub struct PinnedOrtLibrary { /// The ONNX Runtime libraries AFT accepts without an operator override. /// -/// Each entry is the main library inside the release asset that -/// `packages/aft-bridge/src/onnx-runtime.ts` downloads (`ORT_PLATFORM_MAP`, -/// `ORT_VERSION`), fetched from -/// `https://github.com/microsoft/onnxruntime/releases/download/v1.24.4/` -/// and hashed after extraction. On Linux `lib/libonnxruntime.so` is a symlink -/// chain ending at `libonnxruntime.so.1.24.4`; the hash is of the file it -/// resolves to, which is what the installer copies and what a load maps. -/// The installer checks the same hashes (`librarySha256`) before it publishes -/// a download. Bumping `ORT_VERSION` there means adding the new builds here. +/// The installer in `packages/aft-bridge/src/onnx-runtime.ts` downloads and +/// checks the main libraries under `runtimes//native/` in Microsoft's +/// `Microsoft.ML.OnnxRuntime` NuGet package from `api.nuget.org`. The other +/// four NuGet libraries match the previous GitHub release builds byte for +/// byte. On macOS the NuGet library is signed by Microsoft; the pin for the +/// previous macOS build keeps existing managed caches usable. +/// Bumping the installer's `ORT_VERSION` means adding the new builds here. /// /// Every entry is accepted on every platform: a library built for another /// platform cannot load anyway, and all of them are genuine Microsoft builds. @@ -127,26 +125,32 @@ pub const PINNED_ORT_LIBRARIES: &[PinnedOrtLibrary] = &[ }, PinnedOrtLibrary { version: "1.24.4", - asset: "onnxruntime-linux-x64-1.24.4.tgz", - library: "onnxruntime-linux-x64-1.24.4/lib/libonnxruntime.so", + asset: "microsoft.ml.onnxruntime.1.24.4.nupkg", + library: "runtimes/osx-arm64/native/libonnxruntime.dylib", + sha256: "0db33e160224e480c17932799d1dfaea59853b8e722b57bf61932c87e03586f0", + }, + PinnedOrtLibrary { + version: "1.24.4", + asset: "microsoft.ml.onnxruntime.1.24.4.nupkg", + library: "runtimes/linux-x64/native/libonnxruntime.so", sha256: "d132535d051344ff5c64c9c200004150559049a81ed330eb4422c1962fb6b7e4", }, PinnedOrtLibrary { version: "1.24.4", - asset: "onnxruntime-linux-aarch64-1.24.4.tgz", - library: "onnxruntime-linux-aarch64-1.24.4/lib/libonnxruntime.so", + asset: "microsoft.ml.onnxruntime.1.24.4.nupkg", + library: "runtimes/linux-arm64/native/libonnxruntime.so", sha256: "52b2a0e75e79468404284fec38ad5ee1a7a996232274f5e1b84f3e793fb07554", }, PinnedOrtLibrary { version: "1.24.4", - asset: "onnxruntime-win-x64-1.24.4.zip", - library: "onnxruntime-win-x64-1.24.4/lib/onnxruntime.dll", + asset: "microsoft.ml.onnxruntime.1.24.4.nupkg", + library: "runtimes/win-x64/native/onnxruntime.dll", sha256: "b95efb2113b603bbbf3f191061c5516a871ed546893c820e4f3b7b6c358dbf2a", }, PinnedOrtLibrary { version: "1.24.4", - asset: "onnxruntime-win-arm64-1.24.4.zip", - library: "onnxruntime-win-arm64-1.24.4/lib/onnxruntime.dll", + asset: "microsoft.ml.onnxruntime.1.24.4.nupkg", + library: "runtimes/win-arm64/native/onnxruntime.dll", sha256: "724d81ac50b11bfaa01ab3ce01b99fb6734a4b762259a8be4395ca662ce99fe6", }, ]; @@ -1126,6 +1130,7 @@ mod tests { .collect(); let mut rust_pins: Vec<&str> = PINNED_ORT_LIBRARIES .iter() + .filter(|library| library.asset.ends_with(".nupkg")) .map(|library| library.sha256) .collect(); let mut installer_sorted = installer_pins.clone(); @@ -1136,25 +1141,32 @@ mod tests { #[test] fn pinned_list_covers_every_platform_the_installer_downloads() { - for asset in [ - "onnxruntime-osx-arm64-1.24.4.tgz", - "onnxruntime-linux-x64-1.24.4.tgz", - "onnxruntime-linux-aarch64-1.24.4.tgz", - "onnxruntime-win-x64-1.24.4.zip", - "onnxruntime-win-arm64-1.24.4.zip", + for library in [ + "runtimes/osx-arm64/native/libonnxruntime.dylib", + "runtimes/linux-x64/native/libonnxruntime.so", + "runtimes/linux-arm64/native/libonnxruntime.so", + "runtimes/win-x64/native/onnxruntime.dll", + "runtimes/win-arm64/native/onnxruntime.dll", ] { let entry = PINNED_ORT_LIBRARIES .iter() - .find(|library| library.asset == asset) - .unwrap_or_else(|| panic!("no pin for {asset}")); - assert_eq!(entry.sha256.len(), 64, "{asset}"); + .find(|entry| entry.library == library) + .unwrap_or_else(|| panic!("no pin for {library}")); + assert_eq!(entry.sha256.len(), 64, "{library}"); assert!( entry .sha256 .bytes() .all(|byte| byte.is_ascii_digit() || (b'a'..=b'f').contains(&byte)), - "{asset}: pins are lowercase hex" + "{library}: pins are lowercase hex" ); } } + + #[test] + fn accepts_the_legacy_macos_cache_hash() { + assert!(PINNED_ORT_LIBRARIES.iter().any(|entry| { + entry.sha256 == "872533f130f1839a5bc01788ddb4f75c83a189763441ba1178788ed965449289" + })); + } } diff --git a/packages/aft-bridge/src/__tests__/async-maintenance.test.ts b/packages/aft-bridge/src/__tests__/async-maintenance.test.ts index 436c7112ac..8ef4f08168 100644 --- a/packages/aft-bridge/src/__tests__/async-maintenance.test.ts +++ b/packages/aft-bridge/src/__tests__/async-maintenance.test.ts @@ -3,37 +3,9 @@ import { execFileSync } from "node:child_process"; import { mkdtempSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; -import { __test__ } from "../onnx-runtime.js"; import { execTarExtraction, windowsTarExecutable } from "../tar-executable.js"; -test("ONNX zip extraction yields while the extractor owns the work", async () => { - const dir = mkdtempSync(join(tmpdir(), "aft-zip-async-")); - try { - const file = join(dir, "library.txt"); - const archive = join(dir, "ort.zip"); - // A stored ZIP containing library.txt, independent of a zip writer on PATH. - writeFileSync( - archive, - Buffer.from( - "UEsDBBQAAAAAAOcIS131Lkh4DQAAAA0AAAALAAAAbGlicmFyeS50eHRsaWJyYXJ5IGJ5dGVzUEsBAhQDFAAAAAAA5whLXfUuSHgNAAAADQAAAAsAAAAAAAAAAAAAAIABAAAAAGxpYnJhcnkudHh0UEsFBgAAAAABAAEAOQAAADYAAAAAAA==", - "base64", - ), - ); - const extraction = __test__.extractZipArchive(archive, dir); - let settled = false; - void extraction.then(() => { - settled = true; - }); - for (let i = 0; i < 10; i++) await Promise.resolve(); - expect(settled).toBe(false); - await extraction; - expect(readFileSync(file, "utf8")).toBe("library bytes"); - } finally { - rmSync(dir, { recursive: true, force: true }); - } -}); - -test("private ONNX tar extraction yields and preserves private member permissions", async () => { +test("private tar extraction yields and preserves private member permissions", async () => { const dir = mkdtempSync(join(tmpdir(), "aft-tar-async-")); try { const file = join(dir, "library.txt"); diff --git a/packages/aft-bridge/src/__tests__/onnx-cleanup.test.ts b/packages/aft-bridge/src/__tests__/onnx-cleanup.test.ts index 6f6884db9d..f053dcead8 100644 --- a/packages/aft-bridge/src/__tests__/onnx-cleanup.test.ts +++ b/packages/aft-bridge/src/__tests__/onnx-cleanup.test.ts @@ -16,7 +16,6 @@ import { afterEach, beforeEach, describe, expect, test } from "bun:test"; import { existsSync, - lstatSync, mkdirSync, mkdtempSync, readFileSync, @@ -32,7 +31,7 @@ const { cleanupAbandonedOnnxAttempts, ORT_VERSION, ONNX_INSTALLED_META_FILE } = const { cleanupAbandonedStagingDirs, cleanupIncompleteTargetIfUnowned, - copyOnnxLibraries, + stageOnnxLibrary, acquireLock, releaseLock, } = __onnxTest__; @@ -150,108 +149,23 @@ describe("cleanupAbandonedOnnxAttempts", () => { expect(existsSync(ortDir)).toBe(false); }); - test("copies libraries into a target directory that does not exist yet", () => { - // The installer stages into a fresh `/install` directory that nothing - // else creates; copying into it used to fail with ENOENT on copyfile. - const extractedDir = join(workDir, "extracted-fresh-target"); - const targetDir = join(workDir, "staging", "install"); - mkdirSync(extractedDir, { recursive: true }); - writeFileSync(join(extractedDir, "libonnxruntime.so"), "binary"); - - copyOnnxLibraries( - { assetName: "onnxruntime-test", libName: "libonnxruntime.so", archiveType: "tgz" }, - extractedDir, - targetDir, - ["libonnxruntime.so"], - [], - ); - - expect(existsSync(join(targetDir, "libonnxruntime.so"))).toBe(true); - }); - - test("required ONNX library copy failure removes partial target and throws", () => { - const extractedDir = join(workDir, "extracted"); - const targetDir = join(workDir, "target"); - mkdirSync(extractedDir, { recursive: true }); - mkdirSync(targetDir, { recursive: true }); - writeFileSync(join(targetDir, "leftover"), "partial install"); - - expect(() => - copyOnnxLibraries( - { assetName: "onnxruntime-test", libName: "libonnxruntime.so", archiveType: "tgz" }, - extractedDir, - targetDir, - ["libonnxruntime.so"], - [], - () => { - throw new Error("copy failed"); - }, - ), - ).toThrow("copy failed"); - - expect(existsSync(targetDir)).toBe(false); - }); - - test("missing required ONNX library after optional copies removes partial target", () => { - const extractedDir = join(workDir, "extracted-missing"); - const targetDir = join(workDir, "target-missing"); - mkdirSync(extractedDir, { recursive: true }); - mkdirSync(targetDir, { recursive: true }); - - expect(() => - copyOnnxLibraries( - { assetName: "onnxruntime-test", libName: "libonnxruntime.so", archiveType: "tgz" }, - extractedDir, - targetDir, - [], - [], - ), - ).toThrow("Required ONNX Runtime library missing"); - - expect(existsSync(targetDir)).toBe(false); - }); - - test("rejects required symlinks that would escape the target directory after re-home", () => { - const extractedDir = join(workDir, "extracted-escape"); - const targetDir = join(workDir, "target-escape"); - mkdirSync(extractedDir, { recursive: true }); - mkdirSync(targetDir, { recursive: true }); - writeFileSync(join(extractedDir, "libonnxruntime.so.1.24.4"), "binary"); - - expect(() => - copyOnnxLibraries( - { assetName: "onnxruntime-test", libName: "libonnxruntime.so", archiveType: "tgz" }, - extractedDir, - targetDir, - ["libonnxruntime.so.1.24.4"], - [{ name: "libonnxruntime.so", target: "../.aft-onnx-installing" }], - ), - ).toThrow("points outside install dir"); - - expect(existsSync(targetDir)).toBe(false); - }); - test.skipIf(process.platform === "win32")( - "allows same-directory versioned ONNX symlinks during re-home", - () => { - const extractedDir = join(workDir, "extracted-legit-symlink"); - const targetDir = join(workDir, "target-legit-symlink"); - mkdirSync(extractedDir, { recursive: true }); - mkdirSync(targetDir, { recursive: true }); - writeFileSync(join(extractedDir, "libonnxruntime.so.1.24.4"), "binary"); - - copyOnnxLibraries( - { assetName: "onnxruntime-test", libName: "libonnxruntime.so", archiveType: "tgz" }, - extractedDir, - targetDir, - ["libonnxruntime.so.1.24.4"], - [{ name: "libonnxruntime.so", target: "libonnxruntime.so.1.24.4" }], + "stages the Linux and macOS runtime under the existing library filenames", + async () => { + const linux = join(workDir, "staging", "linux"); + const mac = join(workDir, "staging", "mac"); + await stageOnnxLibrary(linux, "libonnxruntime.so", Buffer.from("linux runtime")); + await stageOnnxLibrary(mac, "libonnxruntime.dylib", Buffer.from("mac runtime")); + + expect(readlinkSync(join(linux, "libonnxruntime.so"))).toBe("libonnxruntime.so.1"); + expect(readlinkSync(join(linux, "libonnxruntime.so.1"))).toBe( + `libonnxruntime.so.${ORT_VERSION}`, ); - - const installedLink = join(targetDir, "libonnxruntime.so"); - expect(lstatSync(installedLink).isSymbolicLink()).toBe(true); - expect(readlinkSync(installedLink)).toBe("libonnxruntime.so.1.24.4"); - expect(existsSync(installedLink)).toBe(true); + expect(readFileSync(join(linux, "libonnxruntime.so"), "utf8")).toBe("linux runtime"); + expect(readlinkSync(join(mac, "libonnxruntime.dylib"))).toBe( + `libonnxruntime.${ORT_VERSION}.dylib`, + ); + expect(readFileSync(join(mac, "libonnxruntime.dylib"), "utf8")).toBe("mac runtime"); }, ); diff --git a/packages/aft-bridge/src/__tests__/onnx-concurrent-install.test.ts b/packages/aft-bridge/src/__tests__/onnx-concurrent-install.test.ts index d2265f2f2f..64eb23a9a5 100644 --- a/packages/aft-bridge/src/__tests__/onnx-concurrent-install.test.ts +++ b/packages/aft-bridge/src/__tests__/onnx-concurrent-install.test.ts @@ -7,27 +7,19 @@ * time, and two OpenCode windows can start together. Every one of those * starts asks for the runtime. The install must happen once, each waiting * caller must end up with the installed runtime (not a "skipped" null), and - * no attempt may break another. The archive is served from a local HTTP - * server so the real download, extract, copy and publish path runs: `fetch` - * is wrapped to send the GitHub release URL to that server instead. + * no attempt may break another. A local HTTP server serves a NuGet fixture so + * the real download, ZIP reader, and cache publication path runs. */ import { afterEach, beforeEach, describe, expect, test } from "bun:test"; -import { execFileSync, spawn } from "node:child_process"; +import { spawn } from "node:child_process"; import { createHash } from "node:crypto"; -import { - existsSync, - mkdirSync, - mkdtempSync, - readdirSync, - readFileSync, - rmSync, - writeFileSync, -} from "node:fs"; +import { existsSync, mkdtempSync, readdirSync, readFileSync, rmSync } from "node:fs"; import { createServer, type Server } from "node:http"; import type { AddressInfo } from "node:net"; import { tmpdir } from "node:os"; import { join, resolve } from "node:path"; +import { deflateRawSync } from "node:zlib"; import * as bridge from "../index.js"; const { resolveOnnxRuntime, ORT_VERSION } = bridge.__onnxTest__; @@ -35,61 +27,137 @@ const { resolveOnnxRuntime, ORT_VERSION } = bridge.__onnxTest__; /** Read through the namespace so a missing export fails only the tests that use it. */ const getOnnxRuntimeInstallFailure = (): string | null => bridge.getOnnxRuntimeInstallFailure(); -const LIB_NAME = "libonnxruntime.so"; -const ASSET_NAME = `onnxruntime-fake-${ORT_VERSION}`; +const LIB_NAME = "onnxruntime.dll"; +const RID = "win-x64"; +const PACKAGE_URL = `https://api.nuget.org/v3-flatcontainer/microsoft.ml.onnxruntime/${ORT_VERSION}/microsoft.ml.onnxruntime.${ORT_VERSION}.nupkg`; const FAKE_LIBRARY = "fake onnx runtime library"; -// The installer refuses a library whose sha256 is not the pinned one for its -// asset, so the fake asset pins the fake library's own hash. const PLATFORM_INFO = { - assetName: ASSET_NAME, + rid: RID, libName: LIB_NAME, - archiveType: "tgz" as const, librarySha256: createHash("sha256").update(FAKE_LIBRARY).digest("hex"), }; let workDir: string; let server: Server; let archiveUrl: string; -let requests = 0; +let archive: ReturnType; +let mode: "full" | "range" | "short" | "oversized"; +let requests: string[]; +let bytesSent: number; const realFetch = globalThis.fetch; -/** Send ONNX Runtime release downloads to `target`; pass everything else through. */ -function routeReleaseDownloadsTo(target: string): typeof fetch { +function routePackageDownloadsTo(target: string): typeof fetch { return ((input: string | URL | Request, init?: RequestInit) => { const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url; - if (url.startsWith("https://github.com/microsoft/onnxruntime/releases/download/")) { + if (url === PACKAGE_URL) { return realFetch(target, init); } return realFetch(input, init); }) as typeof fetch; } -function buildFakeArchive(dir: string): Buffer { - const pkgRoot = join(dir, "pkg"); - const libDir = join(pkgRoot, ASSET_NAME, "lib"); - mkdirSync(libDir, { recursive: true }); - writeFileSync(join(libDir, LIB_NAME), FAKE_LIBRARY); - const archivePath = join(dir, "archive.tgz"); - execFileSync("tar", ["czf", archivePath, "-C", pkgRoot, ASSET_NAME]); - return readFileSync(archivePath); +function crc32(bytes: Buffer): number { + let state = 0xffffffff; + for (const byte of bytes) { + state ^= byte; + for (let i = 0; i < 8; i++) state = (state >>> 1) ^ (state & 1 ? 0xedb88320 : 0); + } + return (state ^ 0xffffffff) >>> 0; +} + +function buildFakeArchive(method = 8, flags = 0) { + const files: Buffer[] = []; + const central: Buffer[] = []; + let offset = 0; + let libraryEnd = 0; + let headerEnd = 0; + for (const [path, data, compression, entryFlags] of [ + [`runtimes/${RID}/native/${LIB_NAME}`, Buffer.from(FAKE_LIBRARY), method, flags], + ["runtimes/unrelated/native/unused.so", Buffer.alloc(128 * 1024), 0, 0], + ] as const) { + const name = Buffer.from(path); + const payload = compression === 8 ? deflateRawSync(data) : data; + const crc = crc32(data); + const local = Buffer.alloc(30); + local.writeUInt32LE(0x04034b50); + local.writeUInt16LE(20, 4); + local.writeUInt16LE(entryFlags, 6); + local.writeUInt16LE(compression, 8); + local.writeUInt32LE(crc, 14); + local.writeUInt32LE(payload.length, 18); + local.writeUInt32LE(data.length, 22); + local.writeUInt16LE(name.length, 26); + const entry = Buffer.alloc(46); + entry.writeUInt32LE(0x02014b50); + entry.writeUInt16LE(20, 4); + local.copy(entry, 6, 4, 30); + entry.writeUInt32LE(offset, 42); + files.push(local, name, payload); + central.push(entry, name); + if (offset === 0) headerEnd = local.length; + offset += local.length + name.length + payload.length; + if (files.length === 3) libraryEnd = offset; + } + const directory = Buffer.concat(central); + const end = Buffer.alloc(22); + end.writeUInt32LE(0x06054b50); + end.writeUInt16LE(2, 8); + end.writeUInt16LE(2, 10); + end.writeUInt32LE(directory.length, 12); + end.writeUInt32LE(offset, 16); + return { + bytes: Buffer.concat([...files, directory, end]), + centralStart: offset, + centralEnd: offset + directory.length, + headerEnd, + libraryEnd, + }; } beforeEach(async () => { workDir = mkdtempSync(join(tmpdir(), "aft-onnx-concurrent-")); - const archive = buildFakeArchive(workDir); - requests = 0; - server = createServer((_req, res) => { - requests++; - // Hold the response briefly so concurrent attempts overlap the download. - setTimeout(() => { - res.writeHead(200, { "content-length": String(archive.length) }); - res.end(archive); - }, 300); + archive = buildFakeArchive(); + mode = "full"; + requests = []; + bytesSent = 0; + server = createServer((req, res) => { + const range = req.headers.range ?? ""; + requests.push(range); + const { bytes } = archive; + if (mode === "full" || mode === "oversized") { + // Hold the response briefly so concurrent attempts overlap the download. + setTimeout(() => { + if (mode === "oversized") { + res.writeHead(200, { "content-length": 201 * 1024 * 1024 }); + res.end(); + return; + } + res.writeHead(200, { "content-length": bytes.length }); + bytesSent += bytes.length; + res.end(bytes); + }, 300); + return; + } + const match = /^bytes=(\d*)-(\d+)$/.exec(range); + if (!match) { + res.writeHead(416).end(); + return; + } + const start = match[1] ? Number(match[1]) : Math.max(0, bytes.length - Number(match[2])); + const end = match[1] ? Number(match[2]) : bytes.length - 1; + const short = mode === "short" && start === archive.headerEnd; + const body = bytes.subarray(start, end + (short ? 0 : 1)); + res.writeHead(206, { + "content-range": `bytes ${start}-${end}/${bytes.length}`, + ...(short ? { "transfer-encoding": "chunked" } : { "content-length": body.length }), + }); + bytesSent += body.length; + res.end(body); }); await new Promise((done) => server.listen(0, "127.0.0.1", done)); const { port } = server.address() as AddressInfo; - archiveUrl = `http://127.0.0.1:${port}/archive.tgz`; - globalThis.fetch = routeReleaseDownloadsTo(archiveUrl); + archiveUrl = `http://127.0.0.1:${port}/runtime.nupkg`; + globalThis.fetch = routePackageDownloadsTo(archiveUrl); }); afterEach(async () => { @@ -121,7 +189,7 @@ function installInChildProcess(storageDir: string): Promise { const realFetch = globalThis.fetch; globalThis.fetch = (input, init) => { const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url; - return url.startsWith("https://github.com/microsoft/onnxruntime/releases/download/") + return url === ${JSON.stringify(PACKAGE_URL)} ? realFetch(${JSON.stringify(archiveUrl)}, init) : realFetch(input, init); }; @@ -152,12 +220,14 @@ function installInChildProcess(storageDir: string): Promise { } describe("concurrent ONNX Runtime installs", () => { - test("a single install publishes the runtime", async () => { + test("publishes the runtime from a server that ignores Range", async () => { const storageDir = join(workDir, "storage-single"); const result = await resolveOnnxRuntime(storageDir, seams()); expectInstalled(storageDir, result); - expect(requests).toBe(1); + expect(requests).toHaveLength(1); + expect(requests[0]).toMatch(/^bytes=-\d+$/); + expect(bytesSent).toBe(archive.bytes.length); }); test("two installs in one process both get the runtime from a single download", async () => { @@ -169,7 +239,7 @@ describe("concurrent ONNX Runtime installs", () => { expectInstalled(storageDir, first); expectInstalled(storageDir, second); - expect(requests).toBe(1); + expect(requests).toHaveLength(1); expect(getOnnxRuntimeInstallFailure()).toBeNull(); }); @@ -182,13 +252,13 @@ describe("concurrent ONNX Runtime installs", () => { expectInstalled(storageDir, inProcess); expect(child).toBe(join(storageDir, "onnxruntime", ORT_VERSION)); - expect(requests).toBe(1); + expect(requests).toHaveLength(1); }, 30_000); test("a failed install reports why", async () => { const storageDir = join(workDir, "storage-failing"); // Port 1 has no listener, so the download itself fails. - globalThis.fetch = routeReleaseDownloadsTo("http://127.0.0.1:1/archive.tgz"); + globalThis.fetch = routePackageDownloadsTo("http://127.0.0.1:1/runtime.nupkg"); const result = await resolveOnnxRuntime(storageDir, seams()); expect(result).toBeNull(); @@ -197,6 +267,7 @@ describe("concurrent ONNX Runtime installs", () => { }); test("a download whose library is not the pinned build is never installed", async () => { + mode = "range"; const storageDir = join(workDir, "storage-tampered"); const pinnedElsewhere = { ...PLATFORM_INFO, librarySha256: "0".repeat(64) }; const result = await resolveOnnxRuntime(storageDir, seams(pinnedElsewhere)); @@ -208,3 +279,63 @@ describe("concurrent ONNX Runtime installs", () => { expect(readdirSync(join(storageDir, "onnxruntime"))).toEqual([]); }); }); + +describe("ONNX Runtime NuGet byte ranges", () => { + test("downloads only the deflated native entry and ZIP metadata with Range", async () => { + mode = "range"; + const storageDir = join(workDir, "storage-deflated"); + expectInstalled(storageDir, await resolveOnnxRuntime(storageDir, seams())); + expect(requests).toHaveLength(4); + expect(requests[0]).toMatch(/^bytes=-\d+$/); + expect(requests.slice(1)).toEqual([ + `bytes=${archive.centralStart}-${archive.centralEnd - 1}`, + `bytes=0-${archive.headerEnd - 1}`, + `bytes=${archive.headerEnd}-${archive.libraryEnd - 1}`, + ]); + expect(bytesSent).toBeLessThan(archive.bytes.length); + }); + + test("publishes a stored native entry read with Range", async () => { + mode = "range"; + archive = buildFakeArchive(0); + const storageDir = join(workDir, "storage-stored"); + expectInstalled(storageDir, await resolveOnnxRuntime(storageDir, seams())); + expect(requests).toHaveLength(4); + }); + + test("rejects a short Range response without publishing a runtime", async () => { + mode = "short"; + const storageDir = join(workDir, "storage-short"); + expect(await resolveOnnxRuntime(storageDir, seams())).toBeNull(); + expect(getOnnxRuntimeInstallFailure()).toContain("short download body"); + expect(readdirSync(join(storageDir, "onnxruntime"))).toEqual([]); + }); + + test("rejects an oversized full-package response before downloading its body", async () => { + mode = "oversized"; + const storageDir = join(workDir, "storage-oversized"); + expect(await resolveOnnxRuntime(storageDir, seams())).toBeNull(); + expect(getOnnxRuntimeInstallFailure()).toContain("download exceeds 209715200 bytes"); + expect(readdirSync(join(storageDir, "onnxruntime"))).toEqual([]); + }); + + test("rejects encrypted entries before reading their payload", async () => { + mode = "range"; + archive = buildFakeArchive(8, 1); + const storageDir = join(workDir, "storage-encrypted"); + expect(await resolveOnnxRuntime(storageDir, seams())).toBeNull(); + expect(getOnnxRuntimeInstallFailure()).toContain("encrypted ZIP entries"); + expect(requests).toHaveLength(2); + expect(readdirSync(join(storageDir, "onnxruntime"))).toEqual([]); + }); + + test("rejects a ZIP64 central directory marker", async () => { + mode = "range"; + archive.bytes.writeUInt32LE(0xffffffff, archive.centralEnd + 16); + const storageDir = join(workDir, "storage-zip64"); + expect(await resolveOnnxRuntime(storageDir, seams())).toBeNull(); + expect(getOnnxRuntimeInstallFailure()).toContain("ZIP64 packages"); + expect(requests).toHaveLength(1); + expect(readdirSync(join(storageDir, "onnxruntime"))).toEqual([]); + }); +}); diff --git a/packages/aft-bridge/src/__tests__/onnx-loadability.test.ts b/packages/aft-bridge/src/__tests__/onnx-loadability.test.ts index a4e88502ce..0e1dc9417e 100644 --- a/packages/aft-bridge/src/__tests__/onnx-loadability.test.ts +++ b/packages/aft-bridge/src/__tests__/onnx-loadability.test.ts @@ -130,7 +130,7 @@ describe("detectOnnxVersion", () => { }); describe.skipIf(process.platform === "win32")("ONNX Runtime resolution order", () => { - const platformInfo = { assetName: "onnxruntime-test", libName: LIB, archiveType: "tgz" as const }; + const platformInfo = { rid: "osx-arm64", libName: LIB, librarySha256: "unused" }; function systemRuntime(dependency: string): string { const dir = join(workDir, "homebrew", "lib"); diff --git a/packages/aft-bridge/src/__tests__/private-storage.test.ts b/packages/aft-bridge/src/__tests__/private-storage.test.ts index 0eaed93a2c..42f438aba5 100644 --- a/packages/aft-bridge/src/__tests__/private-storage.test.ts +++ b/packages/aft-bridge/src/__tests__/private-storage.test.ts @@ -73,17 +73,10 @@ test.skipIf(process.platform === "win32")( const extracted = join(root, "migration", "extract"); privateMkdirSync(extracted); execTarExtractionSync(["xf", archive, "-C", extracted], 2_000, true); - __onnxTest__.copyOnnxLibraries( - { - libName: "library.so", - assetName: "fixture", - archiveType: "tgz", - librarySha256: "fixture", - }, - source, + await __onnxTest__.stageOnnxLibrary( join(root, "onnxruntime", "fixture"), - ["library.so"], - [], + "onnxruntime.dll", + Buffer.from("library"), ); expect(__onnxTest__.acquireLock(join(root, "onnxruntime", "install.lock"))).toBe(true); const paths = [root]; diff --git a/packages/aft-bridge/src/onnx-nuget.ts b/packages/aft-bridge/src/onnx-nuget.ts new file mode 100644 index 0000000000..5acf550813 --- /dev/null +++ b/packages/aft-bridge/src/onnx-nuget.ts @@ -0,0 +1,299 @@ +import { type FileHandle, open } from "node:fs/promises"; +import { createInflateRaw } from "node:zlib"; +import { PRIVATE_FILE_MODE } from "./private-storage.js"; + +const MAX_PACKAGE_BYTES = 200 * 1024 * 1024; +const MAX_DIRECTORY_BYTES = 4 * 1024 * 1024; +const MAX_COMPRESSED_BYTES = 64 * 1024 * 1024; +const MAX_LIBRARY_BYTES = 128 * 1024 * 1024; +const END_SIZE = 22; +const ZIP64_LOCATOR_SIZE = 20; +const ZIP_TAIL_BYTES = END_SIZE + 0xffff + ZIP64_LOCATOR_SIZE; +const CENTRAL_HEADER_SIZE = 46; +const LOCAL_HEADER_SIZE = 30; + +async function readBody( + response: Response, + cap: number, + expected: number | undefined, + consume: (chunk: Uint8Array, offset: number) => void | Promise, +): Promise { + const reader = response.body?.getReader(); + if (!reader) throw new Error("download response has no body"); + let size = 0; + let finished = false; + try { + if (expected !== undefined && expected > cap) { + throw new Error(`download exceeds ${cap} bytes`); + } + const lengthHeader = response.headers.get("content-length"); + if (lengthHeader !== null) { + const length = Number(lengthHeader); + if (!/^\d+$/.test(lengthHeader) || !Number.isSafeInteger(length) || length > cap) { + throw new Error(`download exceeds ${cap} bytes or has invalid Content-Length`); + } + if (expected !== undefined && length !== expected) { + throw new Error(`incorrect download Content-Length: expected ${expected}, got ${length}`); + } + expected = length; + } + while (true) { + const { done, value } = await reader.read(); + if (done) break; + const next = size + value.byteLength; + if (next > (expected ?? cap)) throw new Error("download body exceeds its byte limit"); + await consume(value, size); + size = next; + } + if (expected !== undefined && size !== expected) { + throw new Error(`short download body: expected ${expected} bytes, got ${size}`); + } + finished = true; + return size; + } finally { + if (!finished) await reader.cancel().catch(() => {}); + reader.releaseLock(); + } +} + +function rangeBounds(start: number | null, count: number, total: number) { + const first = start ?? Math.max(0, total - count); + const last = start === null ? total - 1 : first + count - 1; + if (first > last || last >= total) throw new Error("ZIP range lies outside the package"); + return { first, last, size: last - first + 1 }; +} + +async function readFileRange(file: FileHandle, first: number, size: number): Promise { + const bytes = Buffer.alloc(size); + let offset = 0; + while (offset < size) { + const { bytesRead } = await file.read(bytes, offset, size - offset, first + offset); + if (!bytesRead) throw new Error("short ZIP file read"); + offset += bytesRead; + } + return bytes; +} + +/** Read one named native library without extracting any other NuGet package entries. */ +export async function readOnnxNugetLibrary( + url: string, + entryName: string, + fallbackPath: string, +): Promise { + let total: number | undefined; + let fullPackage: FileHandle | undefined; + const signal = AbortSignal.timeout(3 * 60 * 1000); + + async function readRange(start: number | null, count: number): Promise { + if (!fullPackage) { + const range = start === null ? `bytes=-${count}` : `bytes=${start}-${start + count - 1}`; + const response = await fetch(url, { + headers: { Range: range, "Accept-Encoding": "identity" }, + signal, + }); + try { + const encoding = response.headers.get("content-encoding"); + if (encoding && encoding.toLowerCase() !== "identity") { + throw new Error(`unexpected download Content-Encoding: ${encoding}`); + } + if (response.status === 206) { + const contentRange = /^bytes (\d+)-(\d+)\/(\d+)$/.exec( + response.headers.get("content-range") ?? "", + ); + const length = Number(contentRange?.[3]); + if (!Number.isSafeInteger(length) || length <= 0 || length >= 0xffffffff) { + throw new Error("invalid download Content-Range or ZIP64 package"); + } + const { first, last, size } = rangeBounds(start, count, length); + if ( + Number(contentRange?.[1]) !== first || + Number(contentRange?.[2]) !== last || + (total !== undefined && total !== length) + ) { + throw new Error("download Content-Range does not match requested ZIP bytes"); + } + total = length; + const bytes = Buffer.alloc(size); + await readBody(response, size, size, (chunk, offset) => { + bytes.set(chunk, offset); + }); + return bytes; + } + + if (response.status !== 200) { + throw new Error(`download failed (HTTP ${response.status})`); + } + // Servers that ignore Range may send the entire package. Spool it to disk + // so the fallback does not keep all platforms' libraries in memory. + fullPackage = await open(fallbackPath, "wx+", PRIVATE_FILE_MODE); + const file = fullPackage; + const size = await readBody(response, MAX_PACKAGE_BYTES, total, (chunk) => + file.writeFile(chunk), + ); + total = size; + } catch (cause) { + await response.body?.cancel().catch(() => {}); + throw cause; + } + } + + if (total === undefined) throw new Error("missing ZIP package size"); + const { first, size } = rangeBounds(start, count, total); + return readFileRange(fullPackage, first, size); + } + + try { + const tail = await readRange(null, ZIP_TAIL_BYTES); + if (total === undefined) throw new Error("missing ZIP package size"); + const directory = locateDirectory(tail, total); + const central = await readRange(directory.offset, directory.size); + const entry = locateEntry(central, directory.entries, Buffer.from(entryName)); + return await readEntry(readRange, entry, directory.offset); + } finally { + await fullPackage?.close(); + } +} + +function locateDirectory(tail: Buffer, total: number) { + for (let end = tail.length - END_SIZE; end >= 0; end--) { + if ( + tail.readUInt32LE(end) !== 0x06054b50 || + tail.readUInt16LE(end + 20) !== tail.length - end - END_SIZE + ) { + continue; + } + const disk = tail.readUInt16LE(end + 4); + const directoryDisk = tail.readUInt16LE(end + 6); + const diskEntries = tail.readUInt16LE(end + 8); + const entries = tail.readUInt16LE(end + 10); + const size = tail.readUInt32LE(end + 12); + const offset = tail.readUInt32LE(end + 16); + if ( + (end >= ZIP64_LOCATOR_SIZE && tail.readUInt32LE(end - ZIP64_LOCATOR_SIZE) === 0x07064b50) || + entries === 0xffff || + size === 0xffffffff || + offset === 0xffffffff + ) { + throw new Error("ZIP64 packages are not supported"); + } + if (disk !== 0 || directoryDisk !== 0 || diskEntries !== entries) { + throw new Error("multi-disk ZIP packages are not supported"); + } + if ( + entries === 0 || + size < entries * CENTRAL_HEADER_SIZE || + size > MAX_DIRECTORY_BYTES || + offset + size !== total - tail.length + end + ) { + throw new Error("invalid ZIP central directory bounds"); + } + return { entries, size, offset }; + } + throw new Error("ZIP end of central directory not found"); +} + +function checkEntryFields(extra: Buffer, flags: number, ...values: number[]): void { + if (flags & 0x2041) throw new Error("encrypted ZIP entries are not supported"); + if (values.includes(0xffffffff)) throw new Error("ZIP64 entries are not supported"); + for (let offset = 0; offset < extra.length; ) { + if (offset + 4 > extra.length) throw new Error("invalid ZIP extra field"); + if (extra.readUInt16LE(offset) === 1) throw new Error("ZIP64 entries are not supported"); + offset += 4 + extra.readUInt16LE(offset + 2); + if (offset > extra.length) throw new Error("invalid ZIP extra field"); + } +} + +interface ZipEntry { + name: Buffer; + flags: number; + method: number; + compressedSize: number; + size: number; + offset: number; +} + +function locateEntry(central: Buffer, entries: number, name: Buffer): ZipEntry { + let match: ZipEntry | undefined; + let cursor = 0; + for (let index = 0; index < entries; index++) { + const headerEnd = cursor + CENTRAL_HEADER_SIZE; + if (headerEnd > central.length || central.readUInt32LE(cursor) !== 0x02014b50) { + throw new Error("invalid ZIP central directory header"); + } + const flags = central.readUInt16LE(cursor + 8); + const method = central.readUInt16LE(cursor + 10); + const compressedSize = central.readUInt32LE(cursor + 20); + const size = central.readUInt32LE(cursor + 24); + const nameEnd = headerEnd + central.readUInt16LE(cursor + 28); + const extraEnd = nameEnd + central.readUInt16LE(cursor + 30); + const next = extraEnd + central.readUInt16LE(cursor + 32); + const disk = central.readUInt16LE(cursor + 34); + const offset = central.readUInt32LE(cursor + 42); + if (next > central.length || disk !== 0) throw new Error("invalid ZIP central directory entry"); + checkEntryFields(central.subarray(nameEnd, extraEnd), flags, size, compressedSize, offset); + if (central.subarray(headerEnd, nameEnd).equals(name)) { + if (match) throw new Error(`duplicate ZIP entry: ${name.toString()}`); + match = { name, flags, method, compressedSize, size, offset }; + } + cursor = next; + } + if (cursor !== central.length) throw new Error("invalid ZIP central directory size"); + if (!match) throw new Error(`missing ZIP entry: ${name.toString()}`); + return match; +} + +async function readEntry( + readRange: (start: number, count: number) => Promise, + entry: ZipEntry, + directoryOffset: number, +): Promise { + const { name, flags, method, compressedSize, size, offset } = entry; + if (method !== 0 && method !== 8) throw new Error(`unsupported ZIP compression method ${method}`); + if ( + compressedSize === 0 || + compressedSize > MAX_COMPRESSED_BYTES || + size === 0 || + size > MAX_LIBRARY_BYTES || + (method === 0 && size !== compressedSize) + ) { + throw new Error("invalid ZIP library size"); + } + const headerEnd = offset + LOCAL_HEADER_SIZE; + if (headerEnd + name.length + compressedSize > directoryOffset) { + throw new Error("ZIP library overlaps the central directory"); + } + const header = await readRange(offset, LOCAL_HEADER_SIZE); + const localCompressedSize = header.readUInt32LE(18); + const localSize = header.readUInt32LE(22); + const nameSize = header.readUInt16LE(26); + const metadataSize = nameSize + header.readUInt16LE(28); + if ( + header.readUInt32LE(0) !== 0x04034b50 || + header.readUInt16LE(6) !== flags || + header.readUInt16LE(8) !== method || + // With a data descriptor, the sizes come from the central directory. + (!(flags & 8) && (localCompressedSize !== compressedSize || localSize !== size)) || + nameSize !== name.length || + headerEnd + metadataSize + compressedSize > directoryOffset + ) { + throw new Error("invalid ZIP library header"); + } + const bytes = await readRange(headerEnd, metadataSize + compressedSize); + if (!bytes.subarray(0, nameSize).equals(name)) throw new Error("incorrect local ZIP entry name"); + checkEntryFields(bytes.subarray(nameSize, metadataSize), flags, localSize, localCompressedSize); + const compressed = bytes.subarray(metadataSize); + if (method === 0) return compressed; + + const output = Buffer.alloc(size); + const inflate = createInflateRaw(); + inflate.end(compressed); + let written = 0; + for await (const chunk of inflate) { + if (written + chunk.length > size) + throw new Error("inflated ZIP library exceeds declared size"); + output.set(chunk, written); + written += chunk.length; + } + if (written !== size) throw new Error("short inflated ZIP library"); + return output; +} diff --git a/packages/aft-bridge/src/onnx-runtime.ts b/packages/aft-bridge/src/onnx-runtime.ts index 1d4691d047..8bc5f12c70 100644 --- a/packages/aft-bridge/src/onnx-runtime.ts +++ b/packages/aft-bridge/src/onnx-runtime.ts @@ -1,28 +1,19 @@ /** * Auto-download and manage ONNX Runtime shared library for semantic search. * - * Downloads the CPU-only ONNX Runtime from Microsoft's GitHub releases. + * Downloads the CPU-only ONNX Runtime from Microsoft's Microsoft.ML.OnnxRuntime + * NuGet package. * The library is cached in the storage directory alongside semantic index data. * - * Security hardening: an earlier implementation used `curl` with no size cap, - * no archive containment validation, no install lock, and no integrity - * verification — an install path that bypassed every defense the LSP GitHub - * installer already had. This brings ONNX onto the same security floor: - * - * - Streaming size cap via fetch + ReadableStream transformer (`MAX_DOWNLOAD_BYTES`). - * - Streaming SHA-256 of the downloaded archive, persisted in `.aft-onnx-installed`. - * - Atomic O_EXCL install lock with PID-aware stale-lock recovery. - * - Containment-checked extraction: every file under the staging dir - * must be inside the staging root, no symlinks allowed before move. - * - Total extracted size cap (`MAX_EXTRACT_BYTES`) to defeat decompression - * bombs. - * - TOFU verification: if `.aft-onnx-installed` already records a hash for - * this version, refuse to use a binary that doesn't match. + * Bounded HTTP Range reads retrieve just the selected native library. Archive + * entries never control filesystem paths. An atomic install lock serializes + * publication, and the library must match a built-in SHA-256 pin before it is + * published. Later resolutions check the hash recorded in `.aft-onnx-installed`. * * Supported platforms: * - macOS ARM64 (osx-arm64) * - Linux x64 (linux-x64) - * - Linux ARM64 (linux-aarch64) + * - Linux ARM64 (linux-arm64) * - Windows x64 (win-x64) * - Windows ARM64 (win-arm64) * @@ -32,12 +23,8 @@ import { randomBytes } from "node:crypto"; import { - chmodSync, closeSync, - copyFileSync, - createWriteStream, existsSync, - lstatSync, openSync, readdirSync, readFileSync, @@ -50,44 +37,23 @@ import { unlinkSync, writeFileSync, } from "node:fs"; -import { basename, dirname, isAbsolute, join, relative, resolve, win32 } from "node:path"; -import { Readable } from "node:stream"; -import { pipeline } from "node:stream/promises"; +import { writeFile } from "node:fs/promises"; +import { basename, isAbsolute, join, resolve, win32 } from "node:path"; import { error, log, warn } from "./active-logger.js"; import { cachedFileSha256, sha256File, writeStampedFileDigest } from "./binary-identity.js"; -import { execFile, execFileSync } from "./child-process.js"; +import { execFileSync } from "./child-process.js"; +import { readOnnxNugetLibrary } from "./onnx-nuget.js"; import { probeOnnxRuntimeLoadable } from "./onnx-probe.js"; -import { relativePathEscapesRoot } from "./path-display.js"; import { withPathPrepended } from "./path-env.js"; import { PLATFORM_ARCH_MAP } from "./platform.js"; -import { - openPrivateStorageDir, - PRIVATE_DIRECTORY_MODE, - PRIVATE_FILE_MODE, - privateCopyFileSync, - privateMkdirSync, -} from "./private-storage.js"; -import { execTarExtraction } from "./tar-executable.js"; +import { openPrivateStorageDir, PRIVATE_FILE_MODE, privateMkdirSync } from "./private-storage.js"; const ORT_VERSION = "1.24.4"; -const ORT_REPO = "microsoft/onnxruntime"; - -// Streaming + extraction size caps. -// -// ONNX Runtime archives are around 60–80 MB on most platforms and 250 MB -// extracted (Windows ships extra debug binaries). 256 MB and 1 GiB give -// generous headroom while preventing a malicious or corrupted CDN response -// from filling the user's disk. Same numbers as the GitHub LSP installer. -const MAX_DOWNLOAD_BYTES = 256 * 1024 * 1024; -const MAX_EXTRACT_BYTES = 1 * 1024 * 1024 * 1024; +const ORT_PACKAGE_URL = `https://api.nuget.org/v3-flatcontainer/microsoft.ml.onnxruntime/${ORT_VERSION}/microsoft.ml.onnxruntime.${ORT_VERSION}.nupkg`; const ONNX_LOCK_FILE = ".aft-onnx-installing"; const ONNX_INSTALLED_META_FILE = ".aft-onnx-installed"; -// 5 minutes is well under any reasonable real download time (60–80 MB archive -// on a working connection) but short enough that a SIGKILL'd plugin process -// recovers fast on the next launch. Previously 30 min — that left users -// blocked for a very long time after closing OpenCode mid-download (issue -// reports of "blackscreen on launch then ONNX broken"). +// Leave time for a bounded download, but recover quickly if the installer dies. const STALE_LOCK_MS = 5 * 60 * 1000; // How long a caller waits for another install (in this process or another // one) to finish before giving up. The lock turns reclaimable after @@ -96,61 +62,49 @@ const STALE_LOCK_MS = 5 * 60 * 1000; const LOCK_WAIT_MS = 2 * STALE_LOCK_MS; const LOCK_POLL_MS = 1000; -/** Map (process.platform, process.arch) → ONNX Runtime asset name + library filename */ +/** Map (process.platform, process.arch) to the NuGet runtime ID and library. */ interface OrtPlatformInfo { - assetName: string; + rid: string; libName: string; - archiveType: "tgz" | "zip"; - /** - * sha256 of `/lib/` inside the release archive (symlinks - * followed). A download whose library hashes differently is never installed. - */ + /** SHA-256 of `runtimes//native/` inside the NuGet package. */ librarySha256: string; } -// Pinned library hashes, taken from the exact assets this installer fetches: -// https://github.com/microsoft/onnxruntime/releases/download/v1.24.4/.{tgz,zip}, -// extracted, then `shasum -a 256 /lib/`. The Rust side refuses -// to load any other build unless the operator names it with ORT_DYLIB_PATH, so -// these must stay identical to `PINNED_ORT_LIBRARIES` in -// crates/aft/src/ort_pin.rs (a Rust test checks that). Bumping ORT_VERSION -// means re-deriving every hash in both places. +// Pins are of the exact entries extracted from Microsoft's Microsoft.ML.OnnxRuntime +// NuGet package (ORT_PACKAGE_URL). Keep the NuGet pins in crates/aft/src/ort_pin.rs +// identical; a Rust test checks them. The Rust loader also accepts the older +// macOS tarball build so existing managed caches continue working. const ORT_PLATFORM_MAP: Record> = { darwin: { arm64: { - assetName: `onnxruntime-osx-arm64-${ORT_VERSION}`, + rid: "osx-arm64", libName: "libonnxruntime.dylib", - archiveType: "tgz", - librarySha256: "872533f130f1839a5bc01788ddb4f75c83a189763441ba1178788ed965449289", + librarySha256: "0db33e160224e480c17932799d1dfaea59853b8e722b57bf61932c87e03586f0", }, // x64 not available from Microsoft — users need brew install onnxruntime }, linux: { x64: { - assetName: `onnxruntime-linux-x64-${ORT_VERSION}`, + rid: "linux-x64", libName: "libonnxruntime.so", - archiveType: "tgz", librarySha256: "d132535d051344ff5c64c9c200004150559049a81ed330eb4422c1962fb6b7e4", }, arm64: { - assetName: `onnxruntime-linux-aarch64-${ORT_VERSION}`, + rid: "linux-arm64", libName: "libonnxruntime.so", - archiveType: "tgz", librarySha256: "52b2a0e75e79468404284fec38ad5ee1a7a996232274f5e1b84f3e793fb07554", }, }, win32: { x64: { - assetName: `onnxruntime-win-x64-${ORT_VERSION}`, + rid: "win-x64", libName: "onnxruntime.dll", - archiveType: "zip", librarySha256: "b95efb2113b603bbbf3f191061c5516a871ed546893c820e4f3b7b6c358dbf2a", }, arm64: { - assetName: `onnxruntime-win-arm64-${ORT_VERSION}`, + rid: "win-arm64", libName: "onnxruntime.dll", - archiveType: "zip", librarySha256: "724d81ac50b11bfaa01ab3ce01b99fb6734a4b762259a8be4395ca662ce99fe6", }, }, @@ -208,7 +162,7 @@ export function getManualInstallHint(): string { * Resolution order: * 1. Cached in storageDir/onnxruntime// (with TOFU verification) * 2. System install (brew, apt, etc.) - * 3. Auto-download from GitHub releases (if platform supported) + * 3. Auto-download from the NuGet package (if platform supported) * 4. null (user needs manual install) */ export async function ensureOnnxRuntime(storageDir: string): Promise { @@ -508,18 +462,6 @@ function parseOnnxVersionFromDirectoryPath(value: string): string | null { return null; } -function isPathInsideRoot(root: string, candidate: string): boolean { - const rel = relative(root, candidate); - return ( - rel === "" || - (!rel.startsWith("../") && - !rel.startsWith("..\\") && - rel !== ".." && - !isAbsolute(rel) && - !win32.isAbsolute(rel)) - ); -} - /** * Detect the version of an ONNX Runtime install by walking the directory's * library-file suffixes. Microsoft ships `libonnxruntime.so.1.24.4` and @@ -789,142 +731,11 @@ function findSystemOnnxRuntime(libName?: string, searchPathsOverride?: string[]) return unknownVersionPaths[0] ?? null; } -/** - * Streaming download with size cap. Mirrors the hardened path in - * `lsp-github-install.ts:downloadFile` so ONNX gets the same defenses - * the LSP installer already has. - * - * The URL is hardcoded to `https://github.com/${ORT_REPO}/...` so we don't - * need a hostname allowlist — the constant cannot be attacker-influenced. - */ -async function downloadFileWithCap(url: string, destPath: string): Promise { - const controller = new AbortController(); - const timeout = setTimeout(() => controller.abort(), 300_000); - try { - const res = await fetch(url, { - headers: { accept: "application/octet-stream" }, - redirect: "follow", - signal: controller.signal, - }); - if (!res.ok || !res.body) { - throw new Error(`download failed (HTTP ${res.status})`); - } - - const advertised = Number.parseInt(res.headers.get("content-length") ?? "", 10); - if (Number.isFinite(advertised) && advertised > MAX_DOWNLOAD_BYTES) { - throw new Error(`Content-Length ${advertised} exceeds max ${MAX_DOWNLOAD_BYTES}`); - } - - privateMkdirSync(dirname(destPath)); - - let bytesWritten = 0; - const guard = new TransformStream({ - transform(chunk, transformController) { - bytesWritten += chunk.byteLength; - if (bytesWritten > MAX_DOWNLOAD_BYTES) { - transformController.error( - new Error( - `download exceeded ${MAX_DOWNLOAD_BYTES} bytes after streaming (server lied about size or sent unbounded body)`, - ), - ); - return; - } - transformController.enqueue(chunk); - }, - }); - - const guarded = res.body.pipeThrough(guard); - // biome-ignore lint/suspicious/noExplicitAny: ReadableStream→Node stream conversion - const nodeStream = Readable.fromWeb(guarded as any); - await pipeline(nodeStream, createWriteStream(destPath, { mode: PRIVATE_FILE_MODE }), { - signal: controller.signal, - }); - } catch (err) { - try { - unlinkSync(destPath); - } catch { - // partial file may not exist — fine - } - throw err; - } finally { - clearTimeout(timeout); - } -} - -/** - * Validate that every file/dir under `stagingRoot` is contained inside it - * AND that the total extracted bytes do not exceed `MAX_EXTRACT_BYTES`. - * - * zip-slip + symlink containment + decompression-bomb - * defense. tar and unzip both can produce paths like `../../etc/passwd`; - * Windows tar.exe and unzip can also produce symlinks that point outside - * the destination. We walk the tree post-extraction and reject anything - * suspicious before moving files into the final cache. - */ -function validateExtractedTree(stagingRoot: string): void { - const realRoot = realpathSync(stagingRoot); - let totalBytes = 0; - - const walk = (dir: string): void => { - const entries = readdirSync(dir); - for (const entry of entries) { - const fullPath = join(dir, entry); - const lst = lstatSync(fullPath); - - if (lst.isSymbolicLink()) { - // Symlinks must be either rejected outright or contained. Tarballs - // from Microsoft's official ONNX Runtime release ship with versioned - // .so symlinks (libonnxruntime.so → libonnxruntime.so.1.24.4), so - // we cannot simply reject all of them. Instead resolve the link - // target (relative to the symlink's directory) and verify it stays - // inside the staging root. - const linkTarget = readlinkSync(fullPath); - const resolvedTarget = resolve(dirname(fullPath), linkTarget); - const rel = relative(realRoot, resolvedTarget); - // A target inside realRoot yields a relative path. If `relative()` - // returns an absolute path it escaped the root — on POSIX (`/...`) or - // across Windows drives (`D:\...`, where the win32 check is essential). - if (relativePathEscapesRoot(rel) || win32.isAbsolute(rel)) { - throw new Error( - `extracted symlink ${fullPath} points outside staging root: ${linkTarget}`, - ); - } - continue; - } - - const rel = relative(realRoot, fullPath); - if (relativePathEscapesRoot(rel) || win32.isAbsolute(rel)) { - throw new Error(`extracted entry ${fullPath} escapes staging root`); - } - - if (lst.isDirectory()) { - if (process.platform !== "win32") chmodSync(fullPath, PRIVATE_DIRECTORY_MODE); - walk(fullPath); - continue; - } - - if (lst.isFile()) { - if (process.platform !== "win32") chmodSync(fullPath, PRIVATE_FILE_MODE); - totalBytes += lst.size; - if (totalBytes > MAX_EXTRACT_BYTES) { - throw new Error( - `extracted size ${totalBytes} exceeds max ${MAX_EXTRACT_BYTES} (decompression bomb defense)`, - ); - } - } - } - }; - - walk(realRoot); -} - -/** Download and extract ONNX Runtime from GitHub releases */ +/** Download the pinned native library from Microsoft's NuGet package. */ async function downloadOnnxRuntime( info: OrtPlatformInfo, targetDir: string, ): Promise { - const url = `https://github.com/${ORT_REPO}/releases/download/v${ORT_VERSION}/${info.assetName}.${info.archiveType === "tgz" ? "tgz" : "zip"}`; - log(`Downloading ONNX Runtime v${ORT_VERSION} for ${process.platform}/${process.arch}...`); // Keep every unverified byte under the version-scoped staging directory. @@ -935,88 +746,27 @@ async function downloadOnnxRuntime( // bytes so two attempts in one process (separate module instances loaded in // the same millisecond) can never share a staging dir. const tmpDir = `${targetDir}.tmp.${process.pid}.${Date.now().toString(36)}${randomBytes(4).toString("hex")}`; - const extractionRoot = join(tmpDir, "extract"); const stagedInstallDir = join(tmpDir, "install"); try { - privateMkdirSync(extractionRoot); - const archivePath = join(tmpDir, `onnxruntime.${info.archiveType}`); - - // Download with a streaming size cap. - await downloadFileWithCap(url, archivePath); - - // Hash the archive for TOFU. - const archiveSha256 = await sha256File(archivePath); - log(`ONNX Runtime archive sha256=${archiveSha256}`); - - if (info.archiveType === "tgz") { - await execTarExtraction(["xzf", archivePath, "-C", extractionRoot], 120_000, true); - } else { - await extractZipArchive(archivePath, extractionRoot); - } - - // Drop the archive itself before validation so it doesn't double-count - // toward the extracted-size budget. - try { - unlinkSync(archivePath); - } catch { - // ignore - } - - // Containment + size-bomb check. - validateExtractedTree(extractionRoot); - - // Find and copy the library file. - const extractedDir = join(extractionRoot, info.assetName, "lib"); - if (!existsSync(extractedDir)) { - throw new Error(`Expected directory not found: ${extractedDir}`); - } - - // Copy all library files (main + versioned symlinks). - // On Linux, .so files are often symlinks (libonnxruntime.so → libonnxruntime.so.1.24.4). - // Process real files first, then recreate symlinks in the target directory to avoid - // ENOENT when renaming a symlink whose target was already moved. - const libFiles = readdirSync(extractedDir).filter( - (f) => f.startsWith("libonnxruntime") || f.startsWith("onnxruntime"), + privateMkdirSync(tmpDir); + const entryName = `runtimes/${info.rid}/native/${info.libName}`; + const bytes = await readOnnxNugetLibrary( + ORT_PACKAGE_URL, + entryName, + join(tmpDir, "runtime.nupkg"), ); + await stageOnnxLibrary(stagedInstallDir, info.libName, bytes); - // Separate real files from symlinks - const realFiles: string[] = []; - const symlinks: Array<{ name: string; target: string }> = []; - for (const libFile of libFiles) { - const src = join(extractedDir, libFile); - try { - const stat = lstatSync(src); - log( - `ORT extract: ${libFile} — isSymlink=${stat.isSymbolicLink()}, isFile=${stat.isFile()}, size=${stat.size}`, - ); - if (stat.isSymbolicLink()) { - symlinks.push({ name: libFile, target: readlinkSync(src) }); - } else { - realFiles.push(libFile); - } - } catch (e) { - log(`ORT extract: ${libFile} — stat failed: ${e}`); - realFiles.push(libFile); - } - } - - copyOnnxLibraries(info, extractedDir, stagedInstallDir, realFiles, symlinks); - - // Persist the installed version, archive SHA-256, and main-library hash so - // future sessions can verify the runtime against the first installation. - // Hash the actual main library because steady-state resolution checks it. const libPath = join(stagedInstallDir, info.libName); const libHash = await sha256File(libPath); - // A corrupted or tampered download must never be published: AFT would - // refuse to load it anyway, and a published copy would shadow a retry. if (libHash !== info.librarySha256) { throw new Error( `onnx runtime library hash mismatch at ${libPath}: sha256 ${libHash}, ` + - `expected the pinned ${info.librarySha256} for ${info.assetName}`, + `expected the pinned ${info.librarySha256} for ${entryName}`, ); } - writeOnnxInstalledMeta(stagedInstallDir, ORT_VERSION, libHash, archiveSha256); + writeOnnxInstalledMeta(stagedInstallDir, ORT_VERSION, libHash); publishOnnxRuntime(stagedInstallDir, targetDir); writeStampedFileDigest(join(targetDir, info.libName), libHash); @@ -1066,96 +816,24 @@ function publishOnnxRuntime(stagedInstallDir: string, targetDir: string): void { } } -function copyOnnxLibraries( - info: OrtPlatformInfo, - extractedDir: string, - targetDir: string, - realFiles: string[], - symlinks: Array<{ name: string; target: string }>, - copyFile: typeof copyFileSync = copyFileSync, -): void { - const requiredLibs = new Set([info.libName]); - - // The installer passes a fresh staging directory that does not exist yet. - // Without this, every copy fails with ENOENT on the destination path and - // no managed install can ever succeed. - privateMkdirSync(targetDir); - - // Copy real files first. Required library failures are fatal; optional extra - // libraries stay best-effort so one unusual sidecar does not block install. - for (const libFile of realFiles) { - const src = join(extractedDir, libFile); - const dst = join(targetDir, libFile); - try { - if (copyFile === copyFileSync) privateCopyFileSync(src, dst); - else copyFile(src, dst); - if (process.platform !== "win32") { - chmodSync(dst, PRIVATE_FILE_MODE); - } - } catch (copyErr) { - if (requiredLibs.has(libFile)) { - rmSync(targetDir, { recursive: true, force: true }); - throw copyErr; - } - log(`ORT extract: failed to copy optional ${libFile}: ${copyErr}`); - } - } - - // Recreate symlinks in target directory. If the required library is a - // symlink, failures must be fatal for the same reason as required copies. - const targetRoot = realpathSync(targetDir); - for (const link of symlinks) { - const dst = join(targetDir, link.name); - try { - unlinkSync(dst); // remove if exists from a previous partial install - } catch { - // ignore - } - - const dstForContainment = join(targetRoot, link.name); - const resolvedTarget = resolve(dirname(dstForContainment), link.target); - if (!isPathInsideRoot(targetRoot, resolvedTarget)) { - const message = `ONNX Runtime symlink ${link.name} points outside install dir: ${link.target}`; - if (requiredLibs.has(link.name)) { - rmSync(targetDir, { recursive: true, force: true }); - throw new Error(message); - } - log(`ORT extract: skipping optional symlink ${link.name}: ${message}`); - continue; - } - - try { - symlinkSync(link.target, dst); - } catch (symlinkErr) { - if (requiredLibs.has(link.name)) { - rmSync(targetDir, { recursive: true, force: true }); - throw symlinkErr; - } - log(`ORT extract: failed to symlink optional ${link.name}: ${symlinkErr}`); - } - } - - const requiredPath = join(targetDir, info.libName); - if (!existsSync(requiredPath)) { - rmSync(targetDir, { recursive: true, force: true }); - throw new Error(`Required ONNX Runtime library missing after install: ${requiredPath}`); - } -} - -async function extractZipArchive(archivePath: string, destinationDir: string): Promise { - if (process.platform === "win32") { - // Avoid PowerShell and PATH-resolved GNU tar. System32 bsdtar accepts - // drive-letter paths and direct argv execution adds no shell parser. - await execTarExtraction(["-xf", archivePath, "-C", destinationDir], 120_000); - return; +async function stageOnnxLibrary(dir: string, libName: string, bytes: Buffer): Promise { + privateMkdirSync(dir); + // The NuGet entry is unversioned. Preserve the old release archive's Unix + // filenames and symlink chains using only the one pinned library. + const versionedName = + libName === "libonnxruntime.so" + ? `${libName}.${ORT_VERSION}` + : libName === "libonnxruntime.dylib" + ? `libonnxruntime.${ORT_VERSION}.dylib` + : libName; + await writeFile(join(dir, versionedName), bytes, { mode: PRIVATE_FILE_MODE, flag: "wx" }); + if (libName === "libonnxruntime.so") { + const abiName = `${libName}.${ORT_VERSION.split(".")[0]}`; + symlinkSync(versionedName, join(dir, abiName)); + symlinkSync(abiName, join(dir, libName)); + } else if (versionedName !== libName) { + symlinkSync(versionedName, join(dir, libName)); } - - await new Promise((resolve, reject) => { - execFile("unzip", ["-q", archivePath, "-d", destinationDir], { timeout: 120_000 }, (error) => { - if (error) reject(error); - else resolve(); - }); - }); } /* ─────────────────────────── install metadata ─────────────────────────── */ @@ -1169,18 +847,12 @@ interface OnnxInstalledMeta { archiveSha256?: string; } -function writeOnnxInstalledMeta( - installDir: string, - version: string, - sha256: string | null, - archiveSha256: string, -): void { +function writeOnnxInstalledMeta(installDir: string, version: string, sha256: string | null): void { try { const meta: OnnxInstalledMeta = { version, installedAt: new Date().toISOString(), ...(sha256 ? { sha256 } : {}), - archiveSha256, }; writeFileSync(join(installDir, ONNX_INSTALLED_META_FILE), JSON.stringify(meta), { encoding: "utf8", @@ -1359,11 +1031,10 @@ export function cleanupOnnxRuntime(storageDir: string): void { * an actual ONNX download. Don't use from production code. */ export const __test__ = { - extractZipArchive, cleanupAbandonedOnnxAttempts, cleanupAbandonedStagingDirs, cleanupIncompleteTargetIfUnowned, - copyOnnxLibraries, + stageOnnxLibrary, resolveCachedOnnxRuntimeDir, ORT_VERSION, ONNX_INSTALLED_META_FILE, From f1b0a29cd40e57ab290ee189bf3453b172bf9680 Mon Sep 17 00:00:00 2001 From: ualtinok <94532+ualtinok@users.noreply.github.com> Date: Wed, 18 Nov 2026 12:53:44 +0100 Subject: [PATCH 13/26] mason: fetch benchmark ONNX Runtime from NuGet Co-authored-by: alfonso-aft <289616620+alfonso-aft@users.noreply.github.com> --- benchmarks/aft-search/Dockerfile | 13 +++++++------ benchmarks/codegraph-replication/Dockerfile | 12 ++++++------ benchmarks/codegraph-vs-aft-agent/Dockerfile | 12 ++++++------ .../codegraph-vs-aft-retrieval/Dockerfile.aft | 12 ++++++------ benchmarks/settle-time/Dockerfile | 12 ++++++------ .../semantic-embed-rss-linux.Dockerfile | 19 +++++++++---------- scripts/telemetry/index-matrix/README.md | 12 ++++++------ 7 files changed, 46 insertions(+), 46 deletions(-) diff --git a/benchmarks/aft-search/Dockerfile b/benchmarks/aft-search/Dockerfile index 820ae422c7..2f4bbfa546 100644 --- a/benchmarks/aft-search/Dockerfile +++ b/benchmarks/aft-search/Dockerfile @@ -4,6 +4,7 @@ RUN apt-get update \ && apt-get install -y --no-install-recommends \ ca-certificates \ curl \ + unzip \ git \ python3 \ python3-venv \ @@ -16,14 +17,14 @@ RUN set -eux; \ arch="$(uname -m)"; \ case "$arch" in \ x86_64|amd64) ort_arch="x64" ;; \ - aarch64|arm64) ort_arch="aarch64" ;; \ + aarch64|arm64) ort_arch="arm64" ;; \ *) echo "Unsupported ONNX Runtime arch: $arch" >&2; exit 1 ;; \ esac; \ - url="https://github.com/microsoft/onnxruntime/releases/download/v${ORT_VERSION}/onnxruntime-linux-${ort_arch}-${ORT_VERSION}.tgz"; \ - mkdir -p /opt/onnxruntime; \ - curl -fsSL "$url" -o /tmp/onnxruntime.tgz; \ - tar -xzf /tmp/onnxruntime.tgz -C /opt/onnxruntime --strip-components=1; \ - rm /tmp/onnxruntime.tgz + url="https://api.nuget.org/v3-flatcontainer/microsoft.ml.onnxruntime/${ORT_VERSION}/microsoft.ml.onnxruntime.${ORT_VERSION}.nupkg"; \ + mkdir -p /opt/onnxruntime/lib; \ + curl -fsSL "$url" -o /tmp/onnxruntime.nupkg; \ + unzip -p /tmp/onnxruntime.nupkg "runtimes/linux-${ort_arch}/native/libonnxruntime.so" > /opt/onnxruntime/lib/libonnxruntime.so; \ + rm /tmp/onnxruntime.nupkg ENV ORT_DYLIB_PATH="/opt/onnxruntime/lib/libonnxruntime.so" ENV LD_LIBRARY_PATH="/opt/onnxruntime/lib" diff --git a/benchmarks/codegraph-replication/Dockerfile b/benchmarks/codegraph-replication/Dockerfile index 4e5bef24d1..b36d373a86 100644 --- a/benchmarks/codegraph-replication/Dockerfile +++ b/benchmarks/codegraph-replication/Dockerfile @@ -18,14 +18,14 @@ RUN set -eux; \ arch="$(uname -m)"; \ case "$arch" in \ x86_64|amd64) ort_arch="x64" ;; \ - aarch64|arm64) ort_arch="aarch64" ;; \ + aarch64|arm64) ort_arch="arm64" ;; \ *) echo "Unsupported ONNX Runtime arch: $arch" >&2; exit 1 ;; \ esac; \ - url="https://github.com/microsoft/onnxruntime/releases/download/v${ORT_VERSION}/onnxruntime-linux-${ort_arch}-${ORT_VERSION}.tgz"; \ - mkdir -p /opt/onnxruntime; \ - curl -fsSL "$url" -o /tmp/onnxruntime.tgz; \ - tar -xzf /tmp/onnxruntime.tgz -C /opt/onnxruntime --strip-components=1; \ - rm /tmp/onnxruntime.tgz + url="https://api.nuget.org/v3-flatcontainer/microsoft.ml.onnxruntime/${ORT_VERSION}/microsoft.ml.onnxruntime.${ORT_VERSION}.nupkg"; \ + mkdir -p /opt/onnxruntime/lib; \ + curl -fsSL "$url" -o /tmp/onnxruntime.nupkg; \ + unzip -p /tmp/onnxruntime.nupkg "runtimes/linux-${ort_arch}/native/libonnxruntime.so" > /opt/onnxruntime/lib/libonnxruntime.so; \ + rm /tmp/onnxruntime.nupkg ENV ORT_DYLIB_PATH="/opt/onnxruntime/lib/libonnxruntime.so" ENV LD_LIBRARY_PATH="/opt/onnxruntime/lib" ENV PATH="/root/.bun/bin:${PATH}" diff --git a/benchmarks/codegraph-vs-aft-agent/Dockerfile b/benchmarks/codegraph-vs-aft-agent/Dockerfile index dd414c6b45..60f6ff9f6f 100644 --- a/benchmarks/codegraph-vs-aft-agent/Dockerfile +++ b/benchmarks/codegraph-vs-aft-agent/Dockerfile @@ -24,14 +24,14 @@ RUN set -eux; \ arch="$(uname -m)"; \ case "$arch" in \ x86_64|amd64) ort_arch="x64" ;; \ - aarch64|arm64) ort_arch="aarch64" ;; \ + aarch64|arm64) ort_arch="arm64" ;; \ *) echo "Unsupported ONNX Runtime arch: $arch" >&2; exit 1 ;; \ esac; \ - url="https://github.com/microsoft/onnxruntime/releases/download/v${ORT_VERSION}/onnxruntime-linux-${ort_arch}-${ORT_VERSION}.tgz"; \ - mkdir -p /opt/onnxruntime; \ - curl -fsSL "$url" -o /tmp/onnxruntime.tgz; \ - tar -xzf /tmp/onnxruntime.tgz -C /opt/onnxruntime --strip-components=1; \ - rm /tmp/onnxruntime.tgz + url="https://api.nuget.org/v3-flatcontainer/microsoft.ml.onnxruntime/${ORT_VERSION}/microsoft.ml.onnxruntime.${ORT_VERSION}.nupkg"; \ + mkdir -p /opt/onnxruntime/lib; \ + curl -fsSL "$url" -o /tmp/onnxruntime.nupkg; \ + unzip -p /tmp/onnxruntime.nupkg "runtimes/linux-${ort_arch}/native/libonnxruntime.so" > /opt/onnxruntime/lib/libonnxruntime.so; \ + rm /tmp/onnxruntime.nupkg ENV ORT_DYLIB_PATH="/opt/onnxruntime/lib/libonnxruntime.so" ENV LD_LIBRARY_PATH="/opt/onnxruntime/lib" ENV PATH="/root/.bun/bin:/root/.opencode/bin:${PATH}" diff --git a/benchmarks/codegraph-vs-aft-retrieval/Dockerfile.aft b/benchmarks/codegraph-vs-aft-retrieval/Dockerfile.aft index 6b1cb535c3..3fcd32e8fc 100644 --- a/benchmarks/codegraph-vs-aft-retrieval/Dockerfile.aft +++ b/benchmarks/codegraph-vs-aft-retrieval/Dockerfile.aft @@ -17,14 +17,14 @@ RUN set -eux; \ arch="$(uname -m)"; \ case "$arch" in \ x86_64|amd64) ort_arch="x64" ;; \ - aarch64|arm64) ort_arch="aarch64" ;; \ + aarch64|arm64) ort_arch="arm64" ;; \ *) echo "Unsupported ONNX Runtime arch: $arch" >&2; exit 1 ;; \ esac; \ - url="https://github.com/microsoft/onnxruntime/releases/download/v${ORT_VERSION}/onnxruntime-linux-${ort_arch}-${ORT_VERSION}.tgz"; \ - mkdir -p /opt/onnxruntime; \ - curl -fsSL "$url" -o /tmp/onnxruntime.tgz; \ - tar -xzf /tmp/onnxruntime.tgz -C /opt/onnxruntime --strip-components=1; \ - rm /tmp/onnxruntime.tgz + url="https://api.nuget.org/v3-flatcontainer/microsoft.ml.onnxruntime/${ORT_VERSION}/microsoft.ml.onnxruntime.${ORT_VERSION}.nupkg"; \ + mkdir -p /opt/onnxruntime/lib; \ + curl -fsSL "$url" -o /tmp/onnxruntime.nupkg; \ + unzip -p /tmp/onnxruntime.nupkg "runtimes/linux-${ort_arch}/native/libonnxruntime.so" > /opt/onnxruntime/lib/libonnxruntime.so; \ + rm /tmp/onnxruntime.nupkg ENV ORT_DYLIB_PATH="/opt/onnxruntime/lib/libonnxruntime.so" ENV LD_LIBRARY_PATH="/opt/onnxruntime/lib" ENV PATH="/root/.bun/bin:${PATH}" diff --git a/benchmarks/settle-time/Dockerfile b/benchmarks/settle-time/Dockerfile index a88dba6748..913bcf1a22 100644 --- a/benchmarks/settle-time/Dockerfile +++ b/benchmarks/settle-time/Dockerfile @@ -18,14 +18,14 @@ RUN set -eux; \ arch="$(uname -m)"; \ case "$arch" in \ x86_64|amd64) ort_arch="x64" ;; \ - aarch64|arm64) ort_arch="aarch64" ;; \ + aarch64|arm64) ort_arch="arm64" ;; \ *) echo "Unsupported ONNX Runtime arch: $arch" >&2; exit 1 ;; \ esac; \ - url="https://github.com/microsoft/onnxruntime/releases/download/v${ORT_VERSION}/onnxruntime-linux-${ort_arch}-${ORT_VERSION}.tgz"; \ - mkdir -p /opt/onnxruntime; \ - curl -fsSL "$url" -o /tmp/onnxruntime.tgz; \ - tar -xzf /tmp/onnxruntime.tgz -C /opt/onnxruntime --strip-components=1; \ - rm /tmp/onnxruntime.tgz + url="https://api.nuget.org/v3-flatcontainer/microsoft.ml.onnxruntime/${ORT_VERSION}/microsoft.ml.onnxruntime.${ORT_VERSION}.nupkg"; \ + mkdir -p /opt/onnxruntime/lib; \ + curl -fsSL "$url" -o /tmp/onnxruntime.nupkg; \ + unzip -p /tmp/onnxruntime.nupkg "runtimes/linux-${ort_arch}/native/libonnxruntime.so" > /opt/onnxruntime/lib/libonnxruntime.so; \ + rm /tmp/onnxruntime.nupkg ENV ORT_DYLIB_PATH="/opt/onnxruntime/lib/libonnxruntime.so" ENV LD_LIBRARY_PATH="/opt/onnxruntime/lib" diff --git a/docs/investigations/scripts/semantic-embed-rss-linux.Dockerfile b/docs/investigations/scripts/semantic-embed-rss-linux.Dockerfile index 836a08f96c..7cd67071fa 100644 --- a/docs/investigations/scripts/semantic-embed-rss-linux.Dockerfile +++ b/docs/investigations/scripts/semantic-embed-rss-linux.Dockerfile @@ -16,6 +16,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ git \ procps \ curl \ + unzip \ ca-certificates \ && rm -rf /var/lib/apt/lists/* @@ -25,22 +26,20 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ # and ORT_DYLIB_PATH is the documented explicit override so the resolver # short-circuits rather than searching the tree. # -# The version and asset naming follow packages/aft-bridge/src/onnx-runtime.ts, +# The version and NuGet runtime IDs follow packages/aft-bridge/src/onnx-runtime.ts, # which is the source of truth for what AFT expects. ARG ORT_VERSION=1.24.4 RUN set -eux; \ case "$(dpkg --print-architecture)" in \ amd64) ort_arch=x64 ;; \ - arm64) ort_arch=aarch64 ;; \ - *) echo "no ONNX Runtime asset for $(dpkg --print-architecture)" >&2; exit 1 ;; \ + arm64) ort_arch=arm64 ;; \ + *) echo "no ONNX Runtime library for $(dpkg --print-architecture)" >&2; exit 1 ;; \ esac; \ - asset="onnxruntime-linux-${ort_arch}-${ORT_VERSION}"; \ - curl -fsSL -o /tmp/ort.tgz \ - "https://github.com/microsoft/onnxruntime/releases/download/v${ORT_VERSION}/${asset}.tgz"; \ - mkdir -p /opt/onnxruntime; \ - tar -xzf /tmp/ort.tgz -C /opt/onnxruntime --strip-components=1; \ - rm /tmp/ort.tgz; \ - ls /opt/onnxruntime/lib/libonnxruntime.so* + curl -fsSL -o /tmp/ort.nupkg \ + "https://api.nuget.org/v3-flatcontainer/microsoft.ml.onnxruntime/${ORT_VERSION}/microsoft.ml.onnxruntime.${ORT_VERSION}.nupkg"; \ + mkdir -p /opt/onnxruntime/lib; \ + unzip -p /tmp/ort.nupkg "runtimes/linux-${ort_arch}/native/libonnxruntime.so" > /opt/onnxruntime/lib/libonnxruntime.so; \ + rm /tmp/ort.nupkg ENV ORT_DYLIB_PATH=/opt/onnxruntime/lib/libonnxruntime.so RUN git config --global user.email "harness@test.invalid" && \ diff --git a/scripts/telemetry/index-matrix/README.md b/scripts/telemetry/index-matrix/README.md index dedb34ec61..b6c8606c99 100644 --- a/scripts/telemetry/index-matrix/README.md +++ b/scripts/telemetry/index-matrix/README.md @@ -43,11 +43,11 @@ not download the runtime. Install the public pinned x86-64 runtime: ```sh mkdir -p target/index-matrix/runtime cd target/index-matrix/runtime -curl -fL --retry 3 https://github.com/microsoft/onnxruntime/releases/download/v1.24.4/onnxruntime-linux-x64-1.24.4.tgz -o runtime.tgz -# Recorded official archive SHA-256 (Linux x86-64): -printf '%s %s\n' 3a211fbea252c1e66290658f1b735b772056149f28321e71c308942cdb54b747 runtime.tgz | sha256sum -c - -tar -xzf runtime.tgz -export ORT_DYLIB_PATH="$PWD/onnxruntime-linux-x64-1.24.4/lib/libonnxruntime.so" +curl -fL --retry 3 https://api.nuget.org/v3-flatcontainer/microsoft.ml.onnxruntime/1.24.4/microsoft.ml.onnxruntime.1.24.4.nupkg -o runtime.nupkg +unzip -p runtime.nupkg runtimes/linux-x64/native/libonnxruntime.so > libonnxruntime.so +# Pinned SHA-256 of the Linux x86-64 library: +printf '%s %s\n' d132535d051344ff5c64c9c200004150559049a81ed330eb4422c1962fb6b7e4 libonnxruntime.so | sha256sum -c - +export ORT_DYLIB_PATH="$PWD/libonnxruntime.so" cd ../../.. ``` @@ -235,7 +235,7 @@ Example on the dedicated server, from `/root/aft`: systemd-run --unit=aft-index-matrix --collect \ --property=WorkingDirectory=/root/aft --property=KillSignal=SIGINT \ --property=TimeoutStopSec=60 \ - --setenv=ORT_DYLIB_PATH=/root/onnx/onnxruntime-linux-x64-1.24.4/lib/libonnxruntime.so \ + --setenv=ORT_DYLIB_PATH=/root/onnx/libonnxruntime.so \ /usr/bin/python3 scripts/telemetry/index-matrix/matrix.py \ --revision meaning-nine-v2.1 --results /root/aft/target/index-matrix/full-matrix -- \ --aft-binary /root/aft-default --shape-binary /root/aft-shape \ From 19aea4837058198f44e1695255bf43673dac717a Mon Sep 17 00:00:00 2001 From: ualtinok <94532+ualtinok@users.noreply.github.com> Date: Wed, 18 Nov 2026 12:53:52 +0100 Subject: [PATCH 14/26] mason: propose revised manual ONNX Runtime links User-facing text only. Hold this commit for Ufuk's approval; the installer and internal recipe commits do not depend on it. Co-authored-by: alfonso-aft <289616620+alfonso-aft@users.noreply.github.com> --- crates/aft/src/semantic_index.rs | 3 ++- docs/tools.md | 2 +- packages/aft-bridge/src/onnx-runtime.ts | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/aft/src/semantic_index.rs b/crates/aft/src/semantic_index.rs index 885d134c8c..c672c3c900 100644 --- a/crates/aft/src/semantic_index.rs +++ b/crates/aft/src/semantic_index.rs @@ -4710,7 +4710,8 @@ pub(crate) fn format_ort_version_mismatch(version: &str, lib_name: &str) -> Stri changes to '{}'.\n\ 2. Remove the old library and restart (AFT auto-downloads the correct version on next start):\n\ {}\n\ - 3. Or install ONNX Runtime 1.24 system-wide: https://github.com/microsoft/onnxruntime/releases/tag/v1.24.0\n\ + 3. Or install ONNX Runtime 1.24 system-wide: https://onnxruntime.ai/ \ + (Microsoft NuGet package: https://www.nuget.org/packages/Microsoft.ML.OnnxRuntime/1.24.4)\n\ 4. Run `npx @cortexkit/aft doctor` for full diagnostics.", version, lib_name, diff --git a/docs/tools.md b/docs/tools.md index 058d46b13c..c3ccb03133 100644 --- a/docs/tools.md +++ b/docs/tools.md @@ -975,7 +975,7 @@ for prose. **Install ONNX Runtime:** - **macOS:** `brew install onnxruntime` - **Linux (Debian/Ubuntu):** `apt install libonnxruntime` -- **Linux (other):** Download from [ONNX Runtime releases](https://github.com/microsoft/onnxruntime/releases) +- **Linux (other):** Extract your architecture's native library from the [Microsoft.ML.OnnxRuntime 1.24.4 NuGet package](https://www.nuget.org/packages/Microsoft.ML.OnnxRuntime/1.24.4). - **Windows:** `winget install Microsoft.ONNXRuntime` Without ONNX Runtime, all other AFT tools work normally — only `aft_search` is unavailable. diff --git a/packages/aft-bridge/src/onnx-runtime.ts b/packages/aft-bridge/src/onnx-runtime.ts index 8bc5f12c70..af5bfc0b77 100644 --- a/packages/aft-bridge/src/onnx-runtime.ts +++ b/packages/aft-bridge/src/onnx-runtime.ts @@ -150,9 +150,9 @@ export function getManualInstallHint(): string { return "brew install onnxruntime"; } if (process.platform === "linux") { - return "apt install libonnxruntime or download from https://github.com/microsoft/onnxruntime/releases"; + return "apt install libonnxruntime or extract the native library from https://www.nuget.org/packages/Microsoft.ML.OnnxRuntime/1.24.4"; } - return "Download from https://github.com/microsoft/onnxruntime/releases"; + return "Install ONNX Runtime 1.24 from https://onnxruntime.ai/ or extract the native library from https://www.nuget.org/packages/Microsoft.ML.OnnxRuntime/1.24.4"; } /** From b49af650812d8ac22c788658d928d9ac2e7da6fe Mon Sep 17 00:00:00 2001 From: ualtinok <94532+ualtinok@users.noreply.github.com> Date: Wed, 18 Nov 2026 13:24:01 +0100 Subject: [PATCH 15/26] test: name the synthetic cgroup mount in the withdraw recovery fixture Batch 17 made the local-recovery fixture take an explicit mount, so recovery never probes the host's cgroup tree. The withdraw test that came in alongside it still used the removed single-path form. Co-authored-by: alfonso-aft <289616620+alfonso-aft@users.noreply.github.com> --- crates/aft/src/subc/tool_provider.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/crates/aft/src/subc/tool_provider.rs b/crates/aft/src/subc/tool_provider.rs index d701c2557b..181ad6351c 100644 --- a/crates/aft/src/subc/tool_provider.rs +++ b/crates/aft/src/subc/tool_provider.rs @@ -11185,9 +11185,13 @@ mod ledger_terminal_tests { "user@{}.service/app.slice/module.service", unsafe { libc::geteuid() } )); - crate::bash_background::task_scope::with_local_recovery_fixture_for_test(current, || { - assert_scoped_withdraw_incomplete(&ctx, &kill); - }); + crate::bash_background::task_scope::with_local_recovery_mount_for_test( + current, + dir.path().to_path_buf(), + || { + assert_scoped_withdraw_incomplete(&ctx, &kill); + }, + ); } #[cfg(target_os = "linux")] From 9547be47cac650e3523d73ee3b4d2bfb6f1ee4fc Mon Sep 17 00:00:00 2001 From: ualtinok <94532+ualtinok@users.noreply.github.com> Date: Wed, 18 Nov 2026 15:42:01 +0100 Subject: [PATCH 16/26] semantic_index: move the ONNX Runtime mismatch wording into its own module The approved install-hint wording added a line to semantic_index.rs, which is past its size pin. The two wording helpers now live in semantic_index/ort_hint.rs and the pin drops to the file's new size. Co-authored-by: alfonso-aft <289616620+alfonso-aft@users.noreply.github.com> --- crates/aft/src/semantic_index.rs | 39 ++-------------------- crates/aft/src/semantic_index/ort_hint.rs | 40 +++++++++++++++++++++++ scripts/file-size-pins.json | 2 +- 3 files changed, 43 insertions(+), 38 deletions(-) create mode 100644 crates/aft/src/semantic_index/ort_hint.rs diff --git a/crates/aft/src/semantic_index.rs b/crates/aft/src/semantic_index.rs index c672c3c900..f18293130e 100644 --- a/crates/aft/src/semantic_index.rs +++ b/crates/aft/src/semantic_index.rs @@ -4682,43 +4682,8 @@ fn extract_version_from_filename(name: &str) -> Option { re.find(name).map(|m| m.as_str().to_string()) } -fn suggest_removal_command(lib_path: &str) -> String { - if lib_path.starts_with("/usr/local/lib") - || lib_path == "libonnxruntime.so" - || lib_path == "libonnxruntime.dylib" - { - #[cfg(target_os = "linux")] - return " sudo rm /usr/local/lib/libonnxruntime* && sudo ldconfig".to_string(); - #[cfg(target_os = "macos")] - return " sudo rm /usr/local/lib/libonnxruntime*".to_string(); - } - format!(" rm '{}'", lib_path) -} - -/// Build the user-facing error message for an incompatible ONNX Runtime -/// install. Extracted as a pure helper so we can unit-test the wording -/// stability — the auto-fix recommendation must always come first because -/// it's the only safe option, and the system-rm step must remain present -/// because some users prefer the system-wide cleanup path. -pub(crate) fn format_ort_version_mismatch(version: &str, lib_name: &str) -> String { - format!( - "ONNX Runtime version mismatch: found v{} at '{}', but AFT requires v1.20+. \ - Solutions:\n\ - 1. Auto-fix (recommended): run `npx @cortexkit/aft doctor --fix`. \ - This downloads AFT-managed ONNX Runtime v1.24 into AFT's storage and \ - configures the bridge to load it instead of the system library — no \ - changes to '{}'.\n\ - 2. Remove the old library and restart (AFT auto-downloads the correct version on next start):\n\ - {}\n\ - 3. Or install ONNX Runtime 1.24 system-wide: https://onnxruntime.ai/ \ - (Microsoft NuGet package: https://www.nuget.org/packages/Microsoft.ML.OnnxRuntime/1.24.4)\n\ - 4. Run `npx @cortexkit/aft doctor` for full diagnostics.", - version, - lib_name, - lib_name, - suggest_removal_command(lib_name), - ) -} +mod ort_hint; +pub(crate) use ort_hint::format_ort_version_mismatch; pub fn is_onnx_runtime_unavailable(message: &str) -> bool { if message diff --git a/crates/aft/src/semantic_index/ort_hint.rs b/crates/aft/src/semantic_index/ort_hint.rs new file mode 100644 index 0000000000..7231d5a223 --- /dev/null +++ b/crates/aft/src/semantic_index/ort_hint.rs @@ -0,0 +1,40 @@ +//! Wording for the ONNX Runtime version-mismatch error, kept apart from the +//! embedding engine so the user-facing text has one home. + +fn suggest_removal_command(lib_path: &str) -> String { + if lib_path.starts_with("/usr/local/lib") + || lib_path == "libonnxruntime.so" + || lib_path == "libonnxruntime.dylib" + { + #[cfg(target_os = "linux")] + return " sudo rm /usr/local/lib/libonnxruntime* && sudo ldconfig".to_string(); + #[cfg(target_os = "macos")] + return " sudo rm /usr/local/lib/libonnxruntime*".to_string(); + } + format!(" rm '{}'", lib_path) +} + +/// Build the user-facing error message for an incompatible ONNX Runtime +/// install. Extracted as a pure helper so we can unit-test the wording +/// stability — the auto-fix recommendation must always come first because +/// it's the only safe option, and the system-rm step must remain present +/// because some users prefer the system-wide cleanup path. +pub(crate) fn format_ort_version_mismatch(version: &str, lib_name: &str) -> String { + format!( + "ONNX Runtime version mismatch: found v{} at '{}', but AFT requires v1.20+. \ + Solutions:\n\ + 1. Auto-fix (recommended): run `npx @cortexkit/aft doctor --fix`. \ + This downloads AFT-managed ONNX Runtime v1.24 into AFT's storage and \ + configures the bridge to load it instead of the system library — no \ + changes to '{}'.\n\ + 2. Remove the old library and restart (AFT auto-downloads the correct version on next start):\n\ + {}\n\ + 3. Or install ONNX Runtime 1.24 system-wide: https://onnxruntime.ai/ \ + (Microsoft NuGet package: https://www.nuget.org/packages/Microsoft.ML.OnnxRuntime/1.24.4)\n\ + 4. Run `npx @cortexkit/aft doctor` for full diagnostics.", + version, + lib_name, + lib_name, + suggest_removal_command(lib_name), + ) +} diff --git a/scripts/file-size-pins.json b/scripts/file-size-pins.json index 1c0c7d2de7..bb73c1c48d 100644 --- a/scripts/file-size-pins.json +++ b/scripts/file-size-pins.json @@ -32,7 +32,7 @@ "reason": "Split semantic search command responsibilities pending; AFT crate split lane." }, "crates/aft/src/semantic_index.rs": { - "lines": 10608, + "lines": 10574, "reason": "Split semantic indexing by area pending; AFT crate split lane." }, "crates/aft/src/parser.rs": { From ad48fd39b1b4bc80677e2ba47f1f32c4d7ce0b05 Mon Sep 17 00:00:00 2001 From: ualtinok <94532+ualtinok@users.noreply.github.com> Date: Wed, 18 Nov 2026 15:18:38 +0100 Subject: [PATCH 17/26] mason: read extended federated route stamps Pin subc-protocol to 0.37.4, which requires subc-config 0.1.1. Exercise wire binds for app and computer peers with and without the new optional metadata. Both must retain project-free admission without changing policy. Co-authored-by: alfonso-aft <289616620+alfonso-aft@users.noreply.github.com> --- Cargo.lock | 8 ++-- crates/aft/Cargo.toml | 2 +- .../aft/tests/integration/subc_detach_test.rs | 48 +++++++++++++++++++ 3 files changed, 53 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f16b6d08cf..71ce8a1bd2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5203,9 +5203,9 @@ dependencies = [ [[package]] name = "subc-config" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "701a3c1b6e06ed0fcec46bb155b09ed194c9d4871aefade0447eb67eebd6c324" +checksum = "b7f5bd0130cdf088277a309ee2786940a04bd37af17f7a95b5b21e62b75c2f67" dependencies = [ "regex", "ryu", @@ -5312,9 +5312,9 @@ dependencies = [ [[package]] name = "subc-protocol" -version = "0.37.2" +version = "0.37.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6358a80bda1927e234a7d3c8750e2c7e67913af5355eaa971bb97ad012df2b57" +checksum = "8223340be699cb9e743edb3cfa3e45889d2cd1bfce5892c627e666f40e923933" dependencies = [ "base64 0.22.1", "serde", diff --git a/crates/aft/Cargo.toml b/crates/aft/Cargo.toml index 2ea2f011fb..330efeabf4 100644 --- a/crates/aft/Cargo.toml +++ b/crates/aft/Cargo.toml @@ -279,7 +279,7 @@ cortexkit-bus-client = "=0.1.2" cortexkit-bus-naming = "=0.4.6" async-nats = { version = "0.50", default-features = false, features = ["jetstream", "ring"] } jsonschema = { version = "0.33", default-features = false } -subc-protocol = "=0.37.2" +subc-protocol = "=0.37.4" subc-control = "=0.41.0" subc-transport = "=0.18.0" subc-client-rs = "=0.41.0" diff --git a/crates/aft/tests/integration/subc_detach_test.rs b/crates/aft/tests/integration/subc_detach_test.rs index ffd530951a..6b5858ec2b 100644 --- a/crates/aft/tests/integration/subc_detach_test.rs +++ b/crates/aft/tests/integration/subc_detach_test.rs @@ -1832,6 +1832,10 @@ fn scope_project_case_034( assert_eq!(error["detail"]["source"], "scope_workdir"); } else { assert_eq!(ack.header.ty, FrameType::Response, "{}", frame_body(&ack)); + assert_eq!( + serde_json::from_slice::(&ack.body).unwrap(), + ModuleControlResponse::RouteBindAck {}, + ); for (corr, body) in [ (20, json!({"name":"read", "preset":"head", "arguments":{"path":"marker.txt"}})), (21, json!({"name":"grep", "preset":"head", "arguments":{"pattern":"scope_project_034_marker", "path":"."}})), @@ -1947,6 +1951,50 @@ fn subc_034_project_missing_scope_workdir_uses_daemon_filled_root() { ); } +#[test] +fn subc_federated_bind_metadata_does_not_change_project_admission() { + for (harness, peer_class) in [ + ("fed-app:person", "app"), + ("fed-computer:person", "computer"), + ] { + for extended in [false, true] { + scope_project_case_034( + |_, _| { + let principal = json!({"kind":"reserved", "module_id":"callosum"}); + let mut facts = json!({ + "peer_class": peer_class, + "peer_fingerprint": "a".repeat(32), + "pairing_id": "pairing", + "peer_name": "Peer", + "remote_claim": {"kind":"run", "agent_id":"agent"}, + }); + if extended { + // Use the wire values from subc-protocol's federated roundtrip test. + facts["origin_principal"] = + json!({"kind":"reserved", "module_id":"origin-module"}); + facts["project"] = json!({"project_id":"project", "root_key":{"kind":"remote", "key":"owner/repo"}}); + facts["peer_box_id"] = json!("0123456789abcdef".repeat(2)); + facts["remote_claim"]["run_id"] = json!("run-1"); + } + json!({ + "op": "route.bind", "route_channel": ROUTE_CHANNEL, "epoch": 1, + "target": {"kind":"tool_provider", "module_id":"aft"}, + "identity": {"harness":harness, "session":SESSION_ID}, + "principal": principal, + "scope": { + "owner": principal, "ref": "peer", "scope_epoch": 1, + "kind": "federated", "owner_authorized": false, + "attributes": {"federated":facts}, + }, + }) + }, + None, + true, + ); + } + } +} + #[test] fn subc_034_project_unscoped_project_free_route_refuses_files_but_serves_catalog() { scope_project_case_034( From 32460caf7b4d5ffca48e5f4b9986b2bd383cab30 Mon Sep 17 00:00:00 2001 From: ualtinok <94532+ualtinok@users.noreply.github.com> Date: Wed, 18 Nov 2026 15:46:46 +0100 Subject: [PATCH 18/26] docs: exactness gate jobs request 32 GB, the build-server cap Co-authored-by: alfonso-aft <289616620+alfonso-aft@users.noreply.github.com> --- scripts/telemetry/callgraph-exactness/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/telemetry/callgraph-exactness/README.md b/scripts/telemetry/callgraph-exactness/README.md index a67ebf8fe7..ef6615de4e 100644 --- a/scripts/telemetry/callgraph-exactness/README.md +++ b/scripts/telemetry/callgraph-exactness/README.md @@ -8,7 +8,9 @@ Do not refresh the matrix pins to make an exactness failure disappear. ## Build the reference and candidate Run from the repository root on the build server. Use one -`linux,16c,64gb,net` job at a time. Commit the candidate before submitting the job. +`linux,16c,32gb,net` job at a time (build-server jobs are capped at 32 GB; a +project whose comparison needs more runs on a rented machine). Commit the +candidate before submitting the job. `build.py` archives the named source revision and overlays only the test probe, its feature-gated module declarations, the feature-gated negative-control hook, and the dead-code comparison entry point. It does **not** copy today's resolver From d02666295b3b42308ac245270883f94a76117b3e Mon Sep 17 00:00:00 2001 From: ualtinok <94532+ualtinok@users.noreply.github.com> Date: Wed, 18 Nov 2026 15:06:45 +0100 Subject: [PATCH 19/26] mason: mark AFT's read-only tools and enforce fork_id calls (tool-provider 0.15.12) Bump cortexkit-role-tool-provider to 0.15.12 and its conformance kit to 0.15.13 (0.15.11 pins tool-provider 0.15.10). llm-runner stays at 0.8.53, which accepts tool-provider ^0.15.7. Every catalog now marks read, grep, glob, search, outline, zoom, callgraph, ast_search and conflicts with `read_only: true`, under every name a preset or plugin serves them. The contract sends the mark without any request opt-in, so every catalog digest changes; the goldens are regenerated. The mark promises that AFT honours `fork_id` (tool.call section of the contract), so a fork call is now admitted before anything runs: a malformed marker is refused `invalid_request {field: "fork_id"}` and a fork call to an unmarked tool `fork_call_refused {tool, reason: "not_read_only"}`. A marked tool runs under AskRoute::Fork on routes that could ask the person, so an access question becomes `fork_call_refused {tool, reason: "approval_required"}`, sent as the role's ERROR, and no card is raised. A fork call sends no code-search nudge to the head. Calls without `fork_id` are unchanged. The codemode refusal moves from AppContext::answer_ask into access_policy::unasked_refusal unchanged, and provider_shell_selector moves to subc/bash.rs, to keep the pinned context.rs and subc/mod.rs within their size pins; both pins are lowered to their new counts. The notice-template samples are published, so aft-notice-templates-v1 stays byte for byte as it was. The regenerated catalogs, now carrying the marks and new digests, go in a new aft-notice-templates-v1.1 with its own README and SHA256SUMS, and AFT's sample test now checks v1.1. Co-authored-by: alfonso-aft <289616620+alfonso-aft@users.noreply.github.com> --- Cargo.lock | 8 +- crates/aft/Cargo.toml | 6 +- crates/aft/src/access_policy.rs | 55 +- crates/aft/src/context.rs | 14 +- crates/aft/src/subc/bash.rs | 11 + crates/aft/src/subc/bash_selector_tests.rs | 2 +- crates/aft/src/subc/fork_call.rs | 104 ++ crates/aft/src/subc/fork_call_tests.rs | 212 +++ crates/aft/src/subc/mod.rs | 35 +- crates/aft/src/subc/tool_provider.rs | 125 +- crates/aft/src/subc/wire.rs | 16 + .../tests/fixtures/tool_provider_catalog.json | 218 ++- .../tool_provider_catalog_presets.json | 139 +- .../fixtures/tool_provider_conformance.json | 14 +- crates/aft/tests/tool_provider_conformance.rs | 37 + scripts/file-size-pins.json | 4 +- .../aft-notice-templates-v1.1/README.md | 10 + .../aft-notice-templates-v1.1/SHA256SUMS | 7 + .../head.catalog.json | 1268 ++++++++++++++++ .../aft-notice-templates-v1.1/head.sends.json | 88 ++ .../reader.catalog.json | 482 ++++++ .../reader.sends.json | 46 + .../worker.catalog.json | 1333 +++++++++++++++++ .../worker.sends.json | 88 ++ 24 files changed, 4219 insertions(+), 103 deletions(-) create mode 100644 crates/aft/src/subc/fork_call.rs create mode 100644 crates/aft/src/subc/fork_call_tests.rs create mode 100644 test-vectors/aft-notice-templates-v1.1/README.md create mode 100644 test-vectors/aft-notice-templates-v1.1/SHA256SUMS create mode 100644 test-vectors/aft-notice-templates-v1.1/head.catalog.json create mode 100644 test-vectors/aft-notice-templates-v1.1/head.sends.json create mode 100644 test-vectors/aft-notice-templates-v1.1/reader.catalog.json create mode 100644 test-vectors/aft-notice-templates-v1.1/reader.sends.json create mode 100644 test-vectors/aft-notice-templates-v1.1/worker.catalog.json create mode 100644 test-vectors/aft-notice-templates-v1.1/worker.sends.json diff --git a/Cargo.lock b/Cargo.lock index 71ce8a1bd2..391d85818b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1206,9 +1206,9 @@ dependencies = [ [[package]] name = "cortexkit-role-tool-provider" -version = "0.15.10" +version = "0.15.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f2e13ef1a5fad31eabb8153d428798b8ce7f8be4143cbb540730ba2317a679a" +checksum = "22919ed36ffc8e253eb3bcc576a02eca9669cf58841f47544de4ee9f2a7c97e8" dependencies = [ "cortexkit-bus-naming", "cortexkit-role-tool-display", @@ -1221,9 +1221,9 @@ dependencies = [ [[package]] name = "cortexkit-role-tool-provider-conformance" -version = "0.15.11" +version = "0.15.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29dab37d9a5b3ab4109b77c00465b314114589fc861c3858ddb2912cf23f166d" +checksum = "6b0cf924b4e30d8d14fade1b20df10a0ee86948c6efe4def40d3f2998fe112e8" dependencies = [ "async-trait", "cortexkit-role-harness", diff --git a/crates/aft/Cargo.toml b/crates/aft/Cargo.toml index 330efeabf4..2eb1cd59c9 100644 --- a/crates/aft/Cargo.toml +++ b/crates/aft/Cargo.toml @@ -268,7 +268,7 @@ markup5ever_rcdom = "0.38" # the protocol's control bodies must agree on the wire-v2 epoch envelope. Tokio # runs only at the --subc transport edge; AFT's command core stays synchronous. cortexkit-persona = "=0.3.0" -cortexkit-role-tool-provider = "=0.15.10" +cortexkit-role-tool-provider = "=0.15.12" cortexkit-role-llm-runner = "=0.8.53" cortexkit-role-tool-display = "=0.1.9" cortexkit-role-agent-data = "=0.2.4" @@ -322,8 +322,8 @@ windows-sys = { version = "0.61", features = [ [dev-dependencies] cortexkit-test-support = "=0.1.14" graphql-parser = "0.4.1" -cortexkit-role-tool-provider-conformance = "=0.15.11" -cortexkit-role-tool-provider = { version = "=0.15.10", features = ["test-vectors"] } +cortexkit-role-tool-provider-conformance = "=0.15.13" +cortexkit-role-tool-provider = { version = "=0.15.12", features = ["test-vectors"] } cortexkit-role-agent-data = { version = "=0.2.4", features = ["test-vectors"] } cortexkit-role-harness = "=0.1.0" async-trait = "0.1" diff --git a/crates/aft/src/access_policy.rs b/crates/aft/src/access_policy.rs index 4aee3b1edc..4c67ec43e7 100644 --- a/crates/aft/src/access_policy.rs +++ b/crates/aft/src/access_policy.rs @@ -203,11 +203,56 @@ pub(crate) enum AskRoute { /// naming the permission and the path. Allow and deny decisions are /// unaffected. Unavailable, + /// A fork call (tool-provider/v1 `fork_id`) to the read-only tool `tool`: + /// it must never ask the person, so an `ask` refuses with + /// `fork_call_refused {tool, reason: "approval_required"}` and no card is + /// raised. Allow and deny decisions are unaffected. + Fork { tool: String }, } /// Refusal for a codemode call that would need a permission ask. pub(crate) const PERMISSION_ASK_UNAVAILABLE: &str = "permission_ask_unavailable"; +/// The refusal for an `ask` on a route that cannot put the question to anyone: +/// [`AskRoute::Unavailable`] (a codemode program) or [`AskRoute::Fork`]. Any +/// other route answers `None`. +pub(crate) fn unasked_refusal( + route: &AskRoute, + req_id: &str, + original: &Path, + identity: &Path, + operation: AccessOperation, +) -> Option { + match route { + AskRoute::Unavailable => { + let verb = match operation { + AccessOperation::Read => "read", + AccessOperation::Write => "write", + }; + Some(crate::protocol::Response::error_with_data( + req_id, + PERMISSION_ASK_UNAVAILABLE, + format!( + "{verb} access to '{}' needs permission, and a codemode program can't ask for it", + original.display() + ), + serde_json::json!({"permission": operation, "resource": identity}), + )) + } + AskRoute::Fork { tool } => { + let error = + cortexkit_role_tool_provider::errors::fork_call_refused(tool, "approval_required"); + Some(crate::protocol::Response::error_with_data( + req_id, + &error.code, + error.message, + serde_json::json!({"detail": error.detail}), + )) + } + _ => None, + } +} + #[path = "access_policy_plugin.rs"] pub(crate) mod plugin; pub(crate) mod prefrontal; @@ -374,14 +419,20 @@ pub(crate) const ACCESS_ASK_REQUIRED: &str = "access_ask_required"; /// with, then retries) or a worker call held for consent through Cingulate /// (`access_ask_required`). A handler that folds errors into a phase failure /// or a batch entry must return such a response unchanged, or nobody can be -/// asked and the call can never run. +/// asked and the call can never run. A fork call's refusal in place of an ask +/// (`fork_call_refused`) is kept whole the same way, so the caller gets the +/// refusal rather than a partial result. pub(crate) fn is_access_request(response: &crate::protocol::Response) -> bool { matches!( response .data .get("code") .and_then(serde_json::Value::as_str), - Some(crate::protocol::ERROR_PERMISSION_REQUIRED | ACCESS_ASK_REQUIRED) + Some( + crate::protocol::ERROR_PERMISSION_REQUIRED + | ACCESS_ASK_REQUIRED + | cortexkit_role_tool_provider::errors::FORK_CALL_REFUSED + ) ) } diff --git a/crates/aft/src/context.rs b/crates/aft/src/context.rs index 850192f759..631fe6b94f 100644 --- a/crates/aft/src/context.rs +++ b/crates/aft/src/context.rs @@ -11881,16 +11881,14 @@ impl AppContext { confinement::note_ask(); use crate::access_policy::{AskRoute, GrantKind}; let route = crate::access_policy::current_ask_route(); + // Codemode programs and fork calls cannot put a question to anyone. + if let Some(refusal) = + crate::access_policy::unasked_refusal(&route, req_id, original, identity, operation) + { + return Err(refusal); + } match &route { AskRoute::Lowered => return Ok(()), - AskRoute::Unavailable => { - return Err(crate::protocol::Response::error_with_data( - req_id, crate::access_policy::PERMISSION_ASK_UNAVAILABLE, - format!("{} access to '{}' needs permission, and a codemode program can't ask for it", - match operation { crate::access_policy::AccessOperation::Read => "read", crate::access_policy::AccessOperation::Write => "write" }, original.display()), - serde_json::json!({"permission":operation,"resource":identity}), - )); - } AskRoute::Deny => { let root = self.config().project_root.clone().unwrap_or_default(); return Err(path_error_response(req_id, original, &root)); diff --git a/crates/aft/src/subc/bash.rs b/crates/aft/src/subc/bash.rs index 04d9675996..1146fcea97 100644 --- a/crates/aft/src/subc/bash.rs +++ b/crates/aft/src/subc/bash.rs @@ -1264,6 +1264,16 @@ fn bash_settings_from_translated(args: &serde_json::Map) -> BashT } } +pub(super) fn provider_shell_selector(name: &str, args: &mut serde_json::Map) { + // The public selector distinguishes PowerShell from the default bash; + // `shell: "bash"` is not part of the bash tool's argument grammar. + if name == "powershell" { + args.insert("shell".into(), json!("powershell")); + } else { + args.remove("shell"); + } +} + pub(super) fn prepare_bash_elicitation_plan( arguments: &Value, project_root: &Path, @@ -3467,6 +3477,7 @@ fn log_runon_refusal(route: RouteChannel, session: &str, response: &Response) { crate::access_policy::AskRoute::Deny => "deny", crate::access_policy::AskRoute::Consent { .. } => "consent", crate::access_policy::AskRoute::Unavailable => "unavailable", + crate::access_policy::AskRoute::Fork { .. } => "fork", }; crate::slog_info!( "runon refused: session={:?} route={} request={:?} grant_scope={:?} grant_denial={:?} ask_route={} classification={} code={} reason={:?}", diff --git a/crates/aft/src/subc/bash_selector_tests.rs b/crates/aft/src/subc/bash_selector_tests.rs index 8b1859a161..724b514f67 100644 --- a/crates/aft/src/subc/bash_selector_tests.rs +++ b/crates/aft/src/subc/bash_selector_tests.rs @@ -616,7 +616,7 @@ async fn cancelled_wait_names_its_task_once_and_delivers_its_completion_after_re #[test] fn exec_remote_v1_powershell_keeps_its_only_supported_selector() { let mut args = serde_json::Map::new(); - provider_shell_selector("powershell", &mut args); + bash::provider_shell_selector("powershell", &mut args); assert_eq!(args.get("shell"), Some(&json!("powershell"))); } diff --git a/crates/aft/src/subc/fork_call.rs b/crates/aft/src/subc/fork_call.rs new file mode 100644 index 0000000000..4c36915359 --- /dev/null +++ b/crates/aft/src/subc/fork_call.rs @@ -0,0 +1,104 @@ +//! Fork calls (the tool-provider/v1 `fork_id` marker). A runner's fork of a +//! head session, such as a voice call, may call only the tools AFT's catalog +//! marks `read_only`. Such a call must change no state the person, the head or +//! another session can see, and must never ask the person anything: whatever +//! would raise an approval card is refused instead. +//! +//! [`admit`] checks the marker and the tool before anything runs. While a +//! marked tool runs, an access question is answered by +//! [`crate::access_policy::AskRoute::Fork`], which refuses instead of asking, +//! and [`reply_refusal`] turns that refusal into the role's `ERROR` reply. + +use cortexkit_role_tool_provider::{call, errors}; +use serde_json::Value; +use subc_protocol::ErrorBody; + +use crate::access_policy::AskRoute; + +/// The tools AFT marks `read_only` in every catalog, by the bare names its +/// presets serve. The plugin spellings of the same tools (`aft_search`, +/// `ast_grep_search`, ...) are read-only too. Each of them only reads code or +/// git state. `inspect` is left out because it can start language servers, +/// and `safety` because it restores files. +pub(crate) const READ_ONLY_TOOLS: &[&str] = &[ + "read", + "grep", + "glob", + "search", + "outline", + "zoom", + "callgraph", + "ast_search", + "conflicts", +]; + +/// Whether the tool a call names, under any name a catalog or plugin gives +/// it, is one AFT marks read-only. +pub(super) fn read_only(name: &str) -> bool { + crate::tool_gate::canonical_tool_name(name).is_some_and(|canonical| { + READ_ONLY_TOOLS + .iter() + .any(|tool| crate::tool_gate::canonical_tool_name(tool) == Some(canonical)) + }) +} + +/// Admit a route request's fork marker before anything else runs. +/// +/// Returns the tool a valid fork call names, spelled as the caller spelled +/// it (the name its refusals carry), or `None` when the request is not a fork +/// call. Only tool calls are checked; other operations are left as they were. +/// A malformed marker is refused `invalid_request {field: "fork_id"}`, and a +/// fork call to a tool AFT does not mark read-only is refused +/// `fork_call_refused {tool, reason: "not_read_only"}`. +pub(super) fn admit(envelope: &Value) -> Result, ErrorBody> { + let name = match envelope.get("op").and_then(Value::as_str) { + None | Some("tool.call") => envelope.get("name").and_then(Value::as_str), + Some(_) => None, + }; + let Some(name) = name.filter(|name| !super::tool_provider::recognized_operation(name)) else { + return Ok(None); + }; + if call::fork_id(envelope)?.is_none() { + return Ok(None); + } + // Whether the call would ask the person is only known while it runs; + // `ask_route` refuses it at that point instead. + call::check_fork_call(envelope, name, read_only(name), false)?; + Ok(Some(name.to_owned())) +} + +/// The ask route a call runs under. A fork call on a route that could ask the +/// person (a plugin prompt, a reverse elicitation or the consent service) +/// gets [`AskRoute::Fork`], which refuses instead. Routes that never ask keep +/// their own answer, and every call without a marker keeps its route. +pub(super) fn ask_route(fork_tool: Option<&str>, route: AskRoute) -> AskRoute { + match (fork_tool, &route) { + ( + Some(tool), + AskRoute::Plugin { .. } | AskRoute::Elicitation { .. } | AskRoute::Consent { .. }, + ) => AskRoute::Fork { + tool: tool.to_owned(), + }, + _ => route, + } +} + +/// The role `ERROR` for a tool response that [`AskRoute::Fork`] refused, or +/// `None` for any other response. The refusal is rebuilt with the role's own +/// constructor, so its bytes match what the contract pins. +pub(super) fn reply_refusal(response: &crate::protocol::Response) -> Option { + if response.success + || response.data.get("code").and_then(Value::as_str) != Some(errors::FORK_CALL_REFUSED) + { + return None; + } + let detail = response.data.get("detail")?; + Some(errors::fork_call_refused( + detail.get("tool")?.as_str()?, + detail.get("reason")?.as_str()?, + )) +} + +#[cfg(test)] +#[path = "fork_call_tests.rs"] +mod tests; diff --git a/crates/aft/src/subc/fork_call_tests.rs b/crates/aft/src/subc/fork_call_tests.rs new file mode 100644 index 0000000000..ae67f2efc8 --- /dev/null +++ b/crates/aft/src/subc/fork_call_tests.rs @@ -0,0 +1,212 @@ +use serde_json::{json, Value}; + +use super::*; +use crate::access_policy::{ask_route_guard, AskRoute}; +use crate::subc::tool_provider::{self, CatalogPreset}; + +/// The role's published fork-call samples. +fn vectors() -> Value { + let (_, text) = cortexkit_role_tool_provider::vectors::FILES + .iter() + .find(|(file, _)| *file == "fork-calls.json") + .expect("the role ships its fork-call samples"); + serde_json::from_str(text).unwrap() +} + +#[test] +fn every_catalog_marks_exactly_the_read_only_tools() { + for preset in CatalogPreset::ALL { + for (runon, revision_reads) in [(false, false), (true, false), (false, true)] { + for tool in tool_provider::tools_for_session(preset, &[], true, runon, revision_reads) { + assert_eq!( + tool.read_only, + READ_ONLY_TOOLS.contains(&tool.name.as_str()), + "{} in the {} preset", + tool.name, + preset.name() + ); + } + } + // The served reply spells some tools differently per preset; the mark + // follows the tool, and `false` is never sent. + let reply = tool_provider::catalog(json!({"preset": preset.name()}), &[], true).unwrap(); + for tool in reply["tools"].as_array().unwrap() { + let name = tool["name"].as_str().unwrap(); + let expected = read_only(name).then_some(&Value::Bool(true)); + assert_eq!(tool.get("read_only"), expected, "{name}"); + } + } + let head: Vec = + tool_provider::tools_for_session(CatalogPreset::Head, &[], true, false, false) + .into_iter() + .filter(|tool| tool.read_only) + .map(|tool| tool.name) + .collect::>() + .into_iter() + .collect(); + let mut expected = READ_ONLY_TOOLS.to_vec(); + expected.sort_unstable(); + assert_eq!(head, expected); +} + +#[test] +fn plugin_spellings_of_marked_tools_are_read_only_and_nothing_else_is() { + for name in [ + "read", + "aft_search", + "aft_outline", + "aft_zoom", + "aft_callgraph", + "ast_grep_search", + "aft_conflicts", + ] { + assert!(read_only(name), "{name}"); + } + for name in [ + "inspect", + "aft_inspect", + "safety", + "aft_safety", + "edit", + "write", + "apply_patch", + "bash", + "bash_status", + "ast_replace", + "ast_grep_replace", + "delete", + "unknown", + ] { + assert!(!read_only(name), "{name}"); + } +} + +#[test] +fn admission_follows_the_published_samples() { + let vectors = vectors(); + assert_eq!(admit(&vectors["call"]).unwrap(), Some("read".to_owned())); + let unmarked = &vectors["refusals"][0]; + let refused = admit(&unmarked["call"]).unwrap_err(); + assert_eq!(serde_json::to_value(&refused).unwrap(), unmarked["error"]); + for spelling in ["aft_outline", "ast_grep_search"] { + let call = json!({"name": spelling, "arguments": {}, "fork_id": "fork:1"}); + assert_eq!(admit(&call).unwrap().as_deref(), Some(spelling)); + } + let refused = + admit(&json!({"name": "aft_inspect", "arguments": {}, "fork_id": "fork:1"})).unwrap_err(); + assert_eq!( + refused.detail, + Some(json!({"tool": "aft_inspect", "reason": "not_read_only"})) + ); + for malformed in [json!(null), json!(7), json!(""), json!("has space")] { + let call = json!({"name": "read", "arguments": {}, "fork_id": malformed}); + let refused = admit(&call).unwrap_err(); + assert_eq!(errors::invalid_request_field(&refused), Some("fork_id")); + } +} + +#[test] +fn requests_without_a_fork_call_are_left_alone() { + for body in [ + json!({"name": "edit", "arguments": {}}), + json!({"op": "tool.call", "name": "bash", "arguments": {}}), + // Only tool calls carry the marker; other operations ignore it. + json!({"op": "tool.catalog", "fork_id": "not valid"}), + json!({"name": "tool.withdraw", "fork_id": 7}), + ] { + assert_eq!(admit(&body).unwrap(), None, "{body}"); + } +} + +#[test] +fn only_routes_that_could_ask_become_fork_routes() { + let owner = std::sync::Arc::new(()); + let asking = [ + AskRoute::Plugin { + scope: crate::access_policy::plugin::Scope::new(&owner, "head"), + once: Vec::new(), + }, + AskRoute::Elicitation { once: Vec::new() }, + AskRoute::Consent { + once: Vec::new(), + launch: None, + }, + ]; + for route in asking { + assert_eq!( + ask_route(Some("read"), route.clone()), + AskRoute::Fork { + tool: "read".into() + } + ); + assert_eq!(ask_route(None, route.clone()), route); + } + for route in [AskRoute::Lowered, AskRoute::Deny, AskRoute::Unavailable] { + assert_eq!(ask_route(Some("read"), route.clone()), route); + } +} + +/// The real access check: a read the plugin route would ask about is refused +/// on a fork route with the published refusal, while reads that need no +/// question still run. +#[test] +fn a_fork_route_refuses_what_would_ask_and_allows_the_rest() { + let dir = tempfile::tempdir_in(crate::test_support::manifest_dir()).unwrap(); + let base = dir.path().canonicalize().unwrap(); + let root = base.join("root"); + let outside = base.join("outside"); + for path in [&root, &outside] { + std::fs::create_dir(path).unwrap(); + } + std::fs::write(root.join("inside.txt"), "inside").unwrap(); + std::fs::write(outside.join("protected.txt"), "outside").unwrap(); + let mut config = crate::config_resolve::resolve_config(&[crate::config_resolve::ConfigTier { + tier: "user".into(), + source: "/fixture/user/aft.jsonc".into(), + doc: "{}".into(), + }]) + .config; + config.project_root = Some(root.clone()); + config.storage_dir = Some(base.join("store")); + config.backup.enabled = Some(false); + let ctx = crate::context::AppContext::new(Box::new(crate::language::StubProvider), config); + let outside_read = |ctx: &crate::context::AppContext| { + ctx.validate_read_path("fork", "head", &outside.join("protected.txt")) + }; + + let owner = std::sync::Arc::new(()); + { + let _route = ask_route_guard(Some(AskRoute::Plugin { + scope: crate::access_policy::plugin::Scope::new(&owner, "head"), + once: Vec::new(), + })); + let asked = outside_read(&ctx).unwrap_err(); + assert!( + crate::access_policy::is_access_request(&asked), + "the probe must be one the plugin route asks about: {:?}", + asked.data + ); + } + + let _route = ask_route_guard(Some(AskRoute::Fork { + tool: "read".into(), + })); + let refused = outside_read(&ctx).unwrap_err(); + assert!(crate::access_policy::is_access_request(&refused)); + let error = reply_refusal(&refused).expect("a fork refusal"); + assert_eq!( + serde_json::to_value(&error).unwrap(), + vectors()["refusals"][1]["error"] + ); + assert!(ctx + .validate_read_path("fork", "head", &root.join("inside.txt")) + .is_ok()); +} + +#[test] +fn only_fork_refusals_become_role_errors() { + let other = crate::protocol::Response::error("id", "path_outside_root", "outside"); + assert_eq!(reply_refusal(&other), None); + let success = crate::protocol::Response::success("id", json!({"code": "fork_call_refused"})); + assert_eq!(reply_refusal(&success), None); +} diff --git a/crates/aft/src/subc/mod.rs b/crates/aft/src/subc/mod.rs index e1eeaff625..b35ae7b706 100644 --- a/crates/aft/src/subc/mod.rs +++ b/crates/aft/src/subc/mod.rs @@ -227,6 +227,7 @@ mod diagnostics_findings; // fields, so they live under `subc` rather than the public `secret` types. mod drain; mod flow_read; +mod fork_call; mod health; mod installed_routes; use installed_routes::{insert_route_channel, remove_route_channel}; @@ -11192,9 +11193,12 @@ async fn handle_tool_call_with_capabilities( if let Some(error) = occipital_session_refusal(&identity, &envelope) { return send_provider_error(tx, metrics, frame, error).await; } - if let Err(error) = carrier_read_only::admit(&identity, &envelope) { - return send_provider_error(tx, metrics, frame, error).await; - } + let fork_tool = match carrier_read_only::admit(&identity, &envelope) + .and_then(|()| fork_call::admit(&envelope)) + { + Ok(tool) => tool, + Err(error) => return send_provider_error(tx, metrics, frame, error).await, + }; if envelope .get("name") .and_then(Value::as_str) @@ -11435,7 +11439,7 @@ async fn handle_tool_call_with_capabilities( .expect("admission validated arguments"); args.insert("foreground_orchestrate".into(), json!(true)); args.insert("block_to_completion".into(), json!(true)); - provider_shell_selector(&call.name, args); + bash::provider_shell_selector(&call.name, args); } RouteRequest::ToolCall(ToolCallRequest { name: call.name, @@ -11656,6 +11660,7 @@ async fn handle_tool_call_with_capabilities( let request_id = format!("subc-{}-{}", frame.header.channel, frame.header.corr); format_context.runner_notice = runner_notices::code_search_notice(&identity, call_key.as_deref().unwrap_or(&request_id)) + .filter(|_| fork_tool.is_none()) .map(|notice| notice.with_preset(role)); // Pin the response ID only for the fixture's exact probe inputs. Other // calls and frame correlation keep their ordinary identities; all native @@ -12169,12 +12174,14 @@ async fn handle_tool_call_with_capabilities( let _grants = crate::access_policy::scope_grants_guard( access_grants::scope_grants_denial(&identity_for_run), ); - let _ask_route = - crate::access_policy::ask_route_guard(Some(access_grants::ask_route_for_call( + let _ask_route = crate::access_policy::ask_route_guard(Some(fork_call::ask_route( + fork_tool.as_deref(), + access_grants::ask_route_for_call( &identity_for_run, &bare_name_for_run, &arguments, - ))); + ), + ))); if matches!( crate::access_policy::current_ask_route(), crate::access_policy::AskRoute::Plugin { .. } @@ -12576,8 +12583,10 @@ async fn handle_tool_call_with_capabilities( approved_io_window: None, reply_deadline: reply_budget.deadline, }; + let ask_route = + access_grants::ask_route_for_call(&identity, &plain_run.bare_name, &plain_run.arguments); let job = plain_run.job( - access_grants::ask_route_for_call(&identity, &plain_run.bare_name, &plain_run.arguments), + fork_call::ask_route(fork_tool.as_deref(), ask_route), phase_trace, tool_call_tx, ); @@ -13229,16 +13238,6 @@ enum BgEventsOp { BgEvents, } -fn provider_shell_selector(name: &str, args: &mut serde_json::Map) { - // The public selector distinguishes PowerShell from the default bash; - // `shell: "bash"` is not part of the bash tool's argument grammar. - if name == "powershell" { - args.insert("shell".into(), json!("powershell")); - } else { - args.remove("shell"); - } -} - /// A tool call as AFT decodes it from a route `REQUEST` body. /// /// This is AFT's own type rather than `subc_protocol::tool_call::ToolCallRequest` diff --git a/crates/aft/src/subc/tool_provider.rs b/crates/aft/src/subc/tool_provider.rs index 181ad6351c..9d84bf1bcd 100644 --- a/crates/aft/src/subc/tool_provider.rs +++ b/crates/aft/src/subc/tool_provider.rs @@ -613,6 +613,9 @@ fn catalog_entry( if *restrict_replace { entry.result_ops = Some(vec!["prepend".into(), "append".into()]); } + if super::fork_call::READ_ONLY_TOOLS.contains(&name) { + entry = entry.with_read_only(); + } entry } @@ -5215,7 +5218,7 @@ mod tests { use crate::subc::runner_notices::notice_templates::{self as notices, Notice, Target}; use sha2::{Digest, Sha256}; let mut files = BTreeMap::new(); - files.insert("README.md".into(), "# AFT notice templates v1\n\nOpt-in `tool.catalog` replies and example `session.send` requests for each preset.\nThe examples use a fixed clock (1700000000000 ms), call key and cleared delivery\nmode; real sends use the current clock and the runner's declared modes.\nTemplate digests use llm-runner's RFC 8785 SHA-256 helper.\n\nRegenerate with `cargo test -p agent-file-tools --lib regenerate_notice_template_vectors -- --ignored`.\nThe `notice_template_vectors_match_samples` test regenerates in memory and compares every byte.\n".into()); + files.insert("README.md".into(), "# AFT notice templates v1.1\n\nThe same opt-in `tool.catalog` replies and example `session.send` requests as\n`aft-notice-templates-v1` (see its README for the fixed clock, call key and\ndelivery mode they use), except that every catalog now carries the\ntool-provider 0.15.12 `read_only: true` mark on the tools AFT marks read-only.\nThe mark is always sent, so each catalog's `generation` and `catalog_digest`\nchange; the `*.sends.json` files are unchanged. v1 stays as published.\nRegenerate with `cargo test -p agent-file-tools --lib regenerate_notice_template_vectors -- --ignored`;\n`notice_template_vectors_match_samples` compares every byte.\n".into()); for preset in ["head", "worker", "reader"] { let reply = catalog( json!({"preset": preset, "notice_templates": true}), @@ -5276,7 +5279,7 @@ mod tests { #[test] fn notice_template_vectors_match_samples() { let root = std::path::Path::new(crate::test_support::manifest_dir()) - .join("../../test-vectors/aft-notice-templates-v1"); + .join("../../test-vectors/aft-notice-templates-v1.1"); for (path, expected) in notice_template_vectors() { assert_eq!( std::fs::read_to_string(root.join(&path)).unwrap(), @@ -5290,7 +5293,7 @@ mod tests { #[ignore = "explicit sample regeneration, not a verification gate"] fn regenerate_notice_template_vectors() { let root = std::path::Path::new(crate::test_support::manifest_dir()) - .join("../../test-vectors/aft-notice-templates-v1"); + .join("../../test-vectors/aft-notice-templates-v1.1"); std::fs::create_dir_all(&root).unwrap(); for (path, text) in notice_template_vectors() { std::fs::write(root.join(path), text).unwrap(); @@ -7642,6 +7645,122 @@ pub(in crate::subc) mod route_tests { } } + /// The role's published fork-call samples. + fn fork_call_vectors() -> Value { + let (_, text) = cortexkit_role_tool_provider::vectors::FILES + .iter() + .find(|(file, _)| *file == "fork-calls.json") + .expect("the role ships its fork-call samples"); + serde_json::from_str(text).unwrap() + } + + /// A tool-provider/v1 route whose access questions go to an OpenCode + /// plugin prompt, so an outside read on it would normally ask the person. + fn plugin_prompt_v1_identity(root: &crate::path_identity::ProjectRootId) -> RouteIdentity { + RouteIdentity(Arc::new(RouteIdentityData { + output_scope: Default::default(), + root: root.clone(), + project_root: root.as_path().into(), + harness: "opencode".into(), + session: "head-session".into(), + role: RouteRole::ToolProviderV1, + trust: BindTrust::FirstParty, + spawn_principal: AuthenticatedPrincipal::FirstParty, + consumer_elicitation_capable: false, + held_reply: false, + held_update: false, + call_keepalive: false, + call_yield: false, + tool_result_body: false, + disabled_tools: Arc::new(Vec::new()), + scope: None, + run_scope: std::sync::OnceLock::new(), + call_mode: subc_protocol::call_mode::CallMode::Classic, + made_tool_call: AtomicBool::new(false), + run_owner: None, + })) + } + + /// Records the ask route a call ran under, then answers as the access + /// policy answers a read outside the project: a route that cannot ask + /// refuses, any other route reads. + fn outside_read_dispatch(request: crate::protocol::RawRequest, _: &AppContext) -> Response { + use crate::access_policy::AskRoute; + let route = crate::access_policy::current_ask_route(); + let label = match &route { + AskRoute::Plugin { .. } => "plugin".to_owned(), + AskRoute::Fork { tool } => format!("fork:{tool}"), + other => format!("{other:?}"), + }; + *LAST_DISPATCH.lock().unwrap() = Some(json!(label)); + let outside = std::path::Path::new("/outside/protected.txt"); + crate::access_policy::unasked_refusal( + &route, + &request.id, + outside, + outside, + crate::access_policy::AccessOperation::Read, + ) + .unwrap_or_else(|| Response::success(request.id, json!({"text": "found"}))) + } + + async fn fork_exchange(body: Value) -> (FrameType, Value, Option) { + let (_dir, root) = test_support::test_root("fork-calls"); + *LAST_DISPATCH.lock().unwrap() = None; + let reply = exchange_with_actor( + body, + plugin_prompt_v1_identity(&root), + test_support::test_ctx(), + &Arc::new(DispatchPathMetrics::new()), + outside_read_dispatch, + ) + .await; + let dispatched = LAST_DISPATCH.lock().unwrap().take(); + ( + reply.header.ty, + serde_json::from_slice(&reply.body).unwrap(), + dispatched, + ) + } + + /// A call without `fork_id` runs exactly as before, under its route's + /// own prompt. A fork call to a marked tool runs under a route that + /// refuses instead of asking, answered with the role's ERROR, and a fork + /// call to an unmarked tool or with a malformed marker never runs. The + /// refusals are compared with the role's published samples. + #[tokio::test] + async fn fork_calls_refuse_instead_of_asking_and_plain_calls_are_unchanged() { + let _guard = EXCHANGE_LOCK.lock().await; + let vectors = fork_call_vectors(); + let [unmarked, needs_consent] = [&vectors["refusals"][0], &vectors["refusals"][1]]; + assert_eq!(unmarked["name"], "unmarked"); + assert_eq!(needs_consent["name"], "needs consent"); + + let plain = + json!({"op": "tool.call", "name": "read", "arguments": {"path": "protected.txt"}}); + let (ty, body, dispatched) = fork_exchange(plain).await; + assert_eq!(ty, FrameType::Response, "{body}"); + assert_eq!(dispatched, Some(json!("plugin"))); + + let (ty, body, dispatched) = fork_exchange(needs_consent["call"].clone()).await; + assert_eq!(ty, FrameType::Error, "{body}"); + assert_eq!(body, needs_consent["error"]); + assert_eq!(dispatched, Some(json!("fork:read"))); + + let (ty, body, dispatched) = fork_exchange(unmarked["call"].clone()).await; + assert_eq!(ty, FrameType::Error, "{body}"); + assert_eq!(body, unmarked["error"]); + assert_eq!(dispatched, None, "an unmarked tool must not run"); + + let mut malformed = vectors["call"].clone(); + malformed["fork_id"] = json!("not valid"); + let (ty, body, dispatched) = fork_exchange(malformed).await; + assert_eq!(ty, FrameType::Error, "{body}"); + let error: ErrorBody = serde_json::from_value(body).unwrap(); + assert_eq!(errors::invalid_request_field(&error), Some("fork_id")); + assert_eq!(dispatched, None, "a malformed marker must not run"); + } + #[tokio::test] async fn occipital_refuses_future_tools_by_default() { let (_dir, root) = test_support::test_root("occipital-future-tool"); diff --git a/crates/aft/src/subc/wire.rs b/crates/aft/src/subc/wire.rs index 6252232d74..ac02c367c5 100644 --- a/crates/aft/src/subc/wire.rs +++ b/crates/aft/src/subc/wire.rs @@ -1299,6 +1299,22 @@ pub(super) fn build_tool_response_frame_with_limit( policy: impl Into, max_body_len: usize, ) -> Result { + // A fork call refused in place of an access question is answered with the + // role's ERROR, like a refusal at admission, never with a tool result. + if let Some(error) = super::fork_call::reply_refusal(&result.response) { + let body = serde_json::to_vec(&error).map_err(SubcError::Json)?; + return Frame::build_with_version( + ver, + FrameType::Error, + flags, + route.channel, + route.epoch, + corr, + body, + ) + .map(WriterFrame::plain) + .map_err(SubcError::FrameBuild); + } let _alloc_label = crate::alloc_trace::scope(crate::alloc_trace::Label::FRAME_ENCODE, None); let policy = policy.into(); let mut capped; diff --git a/crates/aft/tests/fixtures/tool_provider_catalog.json b/crates/aft/tests/fixtures/tool_provider_catalog.json index 0839b6e599..cf54f4b499 100644 --- a/crates/aft/tests/fixtures/tool_provider_catalog.json +++ b/crates/aft/tests/fixtures/tool_provider_catalog.json @@ -16,8 +16,8 @@ "version": "0.58.1" }, "reply": { - "generation": "1a6260325dfb15cb44eb505aaaa60f457fda643f7188c63d451360bf30caa794", - "catalog_digest": "1a6260325dfb15cb44eb505aaaa60f457fda643f7188c63d451360bf30caa794", + "generation": "97bdadf0fd7628e0562f03251ae0250307affa1d02aaf3b381fdfbc957698f6d", + "catalog_digest": "97bdadf0fd7628e0562f03251ae0250307affa1d02aaf3b381fdfbc957698f6d", "tools": [ { "name": "status", @@ -119,6 +119,7 @@ } }, { + "read_only": true, "name": "read", "schema_digest": "f9ef88233ec21e9968187fd84526076c5853cb62d8397721b76ae8bd0a229f00", "semantics": 1, @@ -317,6 +318,7 @@ } }, { + "read_only": true, "name": "grep", "schema_digest": "0f7a077fe3aee4e28d4cdebb8093776db34692c342ef3b67c3b9e49fe7c31f19", "semantics": 1, @@ -356,6 +358,7 @@ } }, { + "read_only": true, "name": "glob", "schema_digest": "f0710f894a9c43ff7709e5f5cb63c37f7cda4e969840379f728a6d55f353a659", "semantics": 1, @@ -386,6 +389,7 @@ } }, { + "read_only": true, "name": "search", "schema_digest": "c01cfa3965f768c100253bb0d59285149d4883f5fa46d7b511cc98e0a7efb70e", "semantics": 1, @@ -435,6 +439,7 @@ } }, { + "read_only": true, "name": "outline", "schema_digest": "264536293f3baca10d5e6b695baf9a29f71ea74b7e4241ceaed26e3b46e165cf", "semantics": 1, @@ -481,6 +486,7 @@ } }, { + "read_only": true, "name": "zoom", "schema_digest": "0c709b2d562766296a0e4601b4a16304488d2ffff6e8ac4ccfc4b68e1fe9be39", "semantics": 1, @@ -607,6 +613,7 @@ } }, { + "read_only": true, "name": "callgraph", "schema_digest": "cc1143512feeca2585bd922ab9047a00ef2496807a1307dac19e9047ae4e86de", "semantics": 1, @@ -679,6 +686,7 @@ } }, { + "read_only": true, "name": "conflicts", "schema_digest": "702d9af7c4449b1601b49d0b7d7573d150aa564430f9fc0c39e7af1dcea92d0c", "semantics": 1, @@ -703,6 +711,7 @@ } }, { + "read_only": true, "name": "ast_search", "schema_digest": "96463c1682f4d87f5216797bb29cc474cd88690a8c9469f1824d9d4b9faa0b35", "semantics": 1, @@ -1230,8 +1239,8 @@ "version": "0.58.1" }, "reply": { - "generation": "c975177882c32a675bcd22afbbbc39683c1692657164ac3f4cf46307a39f0641", - "catalog_digest": "c975177882c32a675bcd22afbbbc39683c1692657164ac3f4cf46307a39f0641", + "generation": "55dca5ad51c8fcbfe801db8af6f87a029d89ecf53318105661345f7bc3320ba2", + "catalog_digest": "55dca5ad51c8fcbfe801db8af6f87a029d89ecf53318105661345f7bc3320ba2", "tools": [ { "name": "status", @@ -1333,6 +1342,7 @@ } }, { + "read_only": true, "name": "read", "schema_digest": "f9ef88233ec21e9968187fd84526076c5853cb62d8397721b76ae8bd0a229f00", "semantics": 1, @@ -1531,6 +1541,7 @@ } }, { + "read_only": true, "name": "grep", "schema_digest": "0f7a077fe3aee4e28d4cdebb8093776db34692c342ef3b67c3b9e49fe7c31f19", "semantics": 1, @@ -1570,6 +1581,7 @@ } }, { + "read_only": true, "name": "glob", "schema_digest": "f0710f894a9c43ff7709e5f5cb63c37f7cda4e969840379f728a6d55f353a659", "semantics": 1, @@ -1600,6 +1612,7 @@ } }, { + "read_only": true, "name": "search", "schema_digest": "c01cfa3965f768c100253bb0d59285149d4883f5fa46d7b511cc98e0a7efb70e", "semantics": 1, @@ -1649,6 +1662,7 @@ } }, { + "read_only": true, "name": "outline", "schema_digest": "264536293f3baca10d5e6b695baf9a29f71ea74b7e4241ceaed26e3b46e165cf", "semantics": 1, @@ -1695,6 +1709,7 @@ } }, { + "read_only": true, "name": "zoom", "schema_digest": "0c709b2d562766296a0e4601b4a16304488d2ffff6e8ac4ccfc4b68e1fe9be39", "semantics": 1, @@ -1821,6 +1836,7 @@ } }, { + "read_only": true, "name": "callgraph", "schema_digest": "cc1143512feeca2585bd922ab9047a00ef2496807a1307dac19e9047ae4e86de", "semantics": 1, @@ -1893,6 +1909,7 @@ } }, { + "read_only": true, "name": "conflicts", "schema_digest": "702d9af7c4449b1601b49d0b7d7573d150aa564430f9fc0c39e7af1dcea92d0c", "semantics": 1, @@ -1917,6 +1934,7 @@ } }, { + "read_only": true, "name": "ast_search", "schema_digest": "96463c1682f4d87f5216797bb29cc474cd88690a8c9469f1824d9d4b9faa0b35", "semantics": 1, @@ -2446,8 +2464,8 @@ "version": "0.58.1" }, "reply": { - "generation": "0f574858db05bf2f045c392160aded657dc29b9d1bd78b797a4660f96e980bcd", - "catalog_digest": "0f574858db05bf2f045c392160aded657dc29b9d1bd78b797a4660f96e980bcd", + "generation": "06ec2fc15c4b4c17290c89080e4f0d414828a7521a444a94ccced4b2a86c27e1", + "catalog_digest": "06ec2fc15c4b4c17290c89080e4f0d414828a7521a444a94ccced4b2a86c27e1", "tools": [ { "name": "status", @@ -2467,6 +2485,7 @@ } }, { + "read_only": true, "name": "read", "schema_digest": "f9ef88233ec21e9968187fd84526076c5853cb62d8397721b76ae8bd0a229f00", "semantics": 1, @@ -2665,6 +2684,7 @@ } }, { + "read_only": true, "name": "grep", "schema_digest": "0f7a077fe3aee4e28d4cdebb8093776db34692c342ef3b67c3b9e49fe7c31f19", "semantics": 1, @@ -2704,6 +2724,7 @@ } }, { + "read_only": true, "name": "glob", "schema_digest": "f0710f894a9c43ff7709e5f5cb63c37f7cda4e969840379f728a6d55f353a659", "semantics": 1, @@ -2734,6 +2755,7 @@ } }, { + "read_only": true, "name": "search", "schema_digest": "c01cfa3965f768c100253bb0d59285149d4883f5fa46d7b511cc98e0a7efb70e", "semantics": 1, @@ -2783,6 +2805,7 @@ } }, { + "read_only": true, "name": "outline", "schema_digest": "264536293f3baca10d5e6b695baf9a29f71ea74b7e4241ceaed26e3b46e165cf", "semantics": 1, @@ -2829,6 +2852,7 @@ } }, { + "read_only": true, "name": "zoom", "schema_digest": "0c709b2d562766296a0e4601b4a16304488d2ffff6e8ac4ccfc4b68e1fe9be39", "semantics": 1, @@ -2955,6 +2979,7 @@ } }, { + "read_only": true, "name": "callgraph", "schema_digest": "cc1143512feeca2585bd922ab9047a00ef2496807a1307dac19e9047ae4e86de", "semantics": 1, @@ -3027,6 +3052,7 @@ } }, { + "read_only": true, "name": "conflicts", "schema_digest": "702d9af7c4449b1601b49d0b7d7573d150aa564430f9fc0c39e7af1dcea92d0c", "semantics": 1, @@ -3051,6 +3077,7 @@ } }, { + "read_only": true, "name": "ast_search", "schema_digest": "96463c1682f4d87f5216797bb29cc474cd88690a8c9469f1824d9d4b9faa0b35", "semantics": 1, @@ -3579,8 +3606,8 @@ "version": "0.58.1" }, "reply": { - "generation": "d9cf7a22b5d12824e58c8d56789bee90d86337ebb15e36327b798b70aed5a9c1", - "catalog_digest": "d9cf7a22b5d12824e58c8d56789bee90d86337ebb15e36327b798b70aed5a9c1", + "generation": "739a85f8ea852546036fa6cae707cdcfebee20fcb6aa4b7b2feb49064e74f207", + "catalog_digest": "739a85f8ea852546036fa6cae707cdcfebee20fcb6aa4b7b2feb49064e74f207", "tools": [ { "name": "status", @@ -3682,6 +3709,7 @@ } }, { + "read_only": true, "name": "read", "schema_digest": "f9ef88233ec21e9968187fd84526076c5853cb62d8397721b76ae8bd0a229f00", "semantics": 1, @@ -3880,6 +3908,7 @@ } }, { + "read_only": true, "name": "grep", "schema_digest": "0f7a077fe3aee4e28d4cdebb8093776db34692c342ef3b67c3b9e49fe7c31f19", "semantics": 1, @@ -3919,6 +3948,7 @@ } }, { + "read_only": true, "name": "glob", "schema_digest": "f0710f894a9c43ff7709e5f5cb63c37f7cda4e969840379f728a6d55f353a659", "semantics": 1, @@ -3949,6 +3979,7 @@ } }, { + "read_only": true, "name": "search", "schema_digest": "c01cfa3965f768c100253bb0d59285149d4883f5fa46d7b511cc98e0a7efb70e", "semantics": 1, @@ -3998,6 +4029,7 @@ } }, { + "read_only": true, "name": "zoom", "schema_digest": "0c709b2d562766296a0e4601b4a16304488d2ffff6e8ac4ccfc4b68e1fe9be39", "semantics": 1, @@ -4124,6 +4156,7 @@ } }, { + "read_only": true, "name": "callgraph", "schema_digest": "cc1143512feeca2585bd922ab9047a00ef2496807a1307dac19e9047ae4e86de", "semantics": 1, @@ -4196,6 +4229,7 @@ } }, { + "read_only": true, "name": "conflicts", "schema_digest": "702d9af7c4449b1601b49d0b7d7573d150aa564430f9fc0c39e7af1dcea92d0c", "semantics": 1, @@ -4220,6 +4254,7 @@ } }, { + "read_only": true, "name": "ast_search", "schema_digest": "96463c1682f4d87f5216797bb29cc474cd88690a8c9469f1824d9d4b9faa0b35", "semantics": 1, @@ -4748,8 +4783,8 @@ "version": "0.58.1" }, "reply": { - "generation": "534e2c2de7beecd204c7a6a10757ac83dc20c768a208e21dc7ba4229bfdcc77b", - "catalog_digest": "534e2c2de7beecd204c7a6a10757ac83dc20c768a208e21dc7ba4229bfdcc77b", + "generation": "49de630b0f06dbee029628561f1d9f9570f5ae193f806e41575f8b310ccb1a68", + "catalog_digest": "49de630b0f06dbee029628561f1d9f9570f5ae193f806e41575f8b310ccb1a68", "tools": [ { "name": "status", @@ -4851,6 +4886,7 @@ } }, { + "read_only": true, "name": "read", "schema_digest": "f9ef88233ec21e9968187fd84526076c5853cb62d8397721b76ae8bd0a229f00", "semantics": 1, @@ -5049,6 +5085,7 @@ } }, { + "read_only": true, "name": "grep", "schema_digest": "0f7a077fe3aee4e28d4cdebb8093776db34692c342ef3b67c3b9e49fe7c31f19", "semantics": 1, @@ -5088,6 +5125,7 @@ } }, { + "read_only": true, "name": "glob", "schema_digest": "f0710f894a9c43ff7709e5f5cb63c37f7cda4e969840379f728a6d55f353a659", "semantics": 1, @@ -5118,6 +5156,7 @@ } }, { + "read_only": true, "name": "outline", "schema_digest": "264536293f3baca10d5e6b695baf9a29f71ea74b7e4241ceaed26e3b46e165cf", "semantics": 1, @@ -5164,6 +5203,7 @@ } }, { + "read_only": true, "name": "zoom", "schema_digest": "0c709b2d562766296a0e4601b4a16304488d2ffff6e8ac4ccfc4b68e1fe9be39", "semantics": 1, @@ -5290,6 +5330,7 @@ } }, { + "read_only": true, "name": "callgraph", "schema_digest": "cc1143512feeca2585bd922ab9047a00ef2496807a1307dac19e9047ae4e86de", "semantics": 1, @@ -5362,6 +5403,7 @@ } }, { + "read_only": true, "name": "conflicts", "schema_digest": "702d9af7c4449b1601b49d0b7d7573d150aa564430f9fc0c39e7af1dcea92d0c", "semantics": 1, @@ -5386,6 +5428,7 @@ } }, { + "read_only": true, "name": "ast_search", "schema_digest": "96463c1682f4d87f5216797bb29cc474cd88690a8c9469f1824d9d4b9faa0b35", "semantics": 1, @@ -5915,8 +5958,8 @@ "version": "0.58.1" }, "reply": { - "generation": "cb61c1e59d3855e9fd9740254f0c0bf3c6f78d167d7063027a0a6596ad6048ab", - "catalog_digest": "cb61c1e59d3855e9fd9740254f0c0bf3c6f78d167d7063027a0a6596ad6048ab", + "generation": "41028d4bf9abd24ef34bafc1a427aece96c824457fb8d2241c94a9a7aa96866a", + "catalog_digest": "41028d4bf9abd24ef34bafc1a427aece96c824457fb8d2241c94a9a7aa96866a", "tools": [ { "name": "status", @@ -6018,6 +6061,7 @@ } }, { + "read_only": true, "name": "read", "schema_digest": "f9ef88233ec21e9968187fd84526076c5853cb62d8397721b76ae8bd0a229f00", "semantics": 1, @@ -6216,6 +6260,7 @@ } }, { + "read_only": true, "name": "grep", "schema_digest": "0f7a077fe3aee4e28d4cdebb8093776db34692c342ef3b67c3b9e49fe7c31f19", "semantics": 1, @@ -6255,6 +6300,7 @@ } }, { + "read_only": true, "name": "glob", "schema_digest": "f0710f894a9c43ff7709e5f5cb63c37f7cda4e969840379f728a6d55f353a659", "semantics": 1, @@ -6285,6 +6331,7 @@ } }, { + "read_only": true, "name": "search", "schema_digest": "c01cfa3965f768c100253bb0d59285149d4883f5fa46d7b511cc98e0a7efb70e", "semantics": 1, @@ -6334,6 +6381,7 @@ } }, { + "read_only": true, "name": "zoom", "schema_digest": "0c709b2d562766296a0e4601b4a16304488d2ffff6e8ac4ccfc4b68e1fe9be39", "semantics": 1, @@ -6400,6 +6448,7 @@ } }, { + "read_only": true, "name": "callgraph", "schema_digest": "cc1143512feeca2585bd922ab9047a00ef2496807a1307dac19e9047ae4e86de", "semantics": 1, @@ -6472,6 +6521,7 @@ } }, { + "read_only": true, "name": "conflicts", "schema_digest": "702d9af7c4449b1601b49d0b7d7573d150aa564430f9fc0c39e7af1dcea92d0c", "semantics": 1, @@ -6496,6 +6546,7 @@ } }, { + "read_only": true, "name": "ast_search", "schema_digest": "96463c1682f4d87f5216797bb29cc474cd88690a8c9469f1824d9d4b9faa0b35", "semantics": 1, @@ -7024,8 +7075,8 @@ "version": "0.58.1" }, "reply": { - "generation": "d73a71754a2b6ad7e3cb9eedd7ac3ae7183f4eadbb654075645bc401b7526c77", - "catalog_digest": "d73a71754a2b6ad7e3cb9eedd7ac3ae7183f4eadbb654075645bc401b7526c77", + "generation": "36b9bafc12e61b7413a8535ccdf1b61abea121c1f0fb7613d0dc55ed8acb591b", + "catalog_digest": "36b9bafc12e61b7413a8535ccdf1b61abea121c1f0fb7613d0dc55ed8acb591b", "tools": [ { "name": "status", @@ -7127,6 +7178,7 @@ } }, { + "read_only": true, "name": "read", "schema_digest": "f9ef88233ec21e9968187fd84526076c5853cb62d8397721b76ae8bd0a229f00", "semantics": 1, @@ -7325,6 +7377,7 @@ } }, { + "read_only": true, "name": "grep", "schema_digest": "0f7a077fe3aee4e28d4cdebb8093776db34692c342ef3b67c3b9e49fe7c31f19", "semantics": 1, @@ -7364,6 +7417,7 @@ } }, { + "read_only": true, "name": "glob", "schema_digest": "f0710f894a9c43ff7709e5f5cb63c37f7cda4e969840379f728a6d55f353a659", "semantics": 1, @@ -7394,6 +7448,7 @@ } }, { + "read_only": true, "name": "outline", "schema_digest": "264536293f3baca10d5e6b695baf9a29f71ea74b7e4241ceaed26e3b46e165cf", "semantics": 1, @@ -7440,6 +7495,7 @@ } }, { + "read_only": true, "name": "zoom", "schema_digest": "0c709b2d562766296a0e4601b4a16304488d2ffff6e8ac4ccfc4b68e1fe9be39", "semantics": 1, @@ -7506,6 +7562,7 @@ } }, { + "read_only": true, "name": "callgraph", "schema_digest": "cc1143512feeca2585bd922ab9047a00ef2496807a1307dac19e9047ae4e86de", "semantics": 1, @@ -7578,6 +7635,7 @@ } }, { + "read_only": true, "name": "conflicts", "schema_digest": "702d9af7c4449b1601b49d0b7d7573d150aa564430f9fc0c39e7af1dcea92d0c", "semantics": 1, @@ -7602,6 +7660,7 @@ } }, { + "read_only": true, "name": "ast_search", "schema_digest": "96463c1682f4d87f5216797bb29cc474cd88690a8c9469f1824d9d4b9faa0b35", "semantics": 1, @@ -8130,8 +8189,8 @@ "version": "0.58.1" }, "reply": { - "generation": "17c82349e9954d927482c4bd4bc91e406629b5d67dbb3d72e8375f73a5e58b8e", - "catalog_digest": "17c82349e9954d927482c4bd4bc91e406629b5d67dbb3d72e8375f73a5e58b8e", + "generation": "84baab7eae2f6450049604f363ddf99fe445c0ae4dcec9d5c2253371ae1b571c", + "catalog_digest": "84baab7eae2f6450049604f363ddf99fe445c0ae4dcec9d5c2253371ae1b571c", "tools": [ { "name": "status", @@ -8233,6 +8292,7 @@ } }, { + "read_only": true, "name": "read", "schema_digest": "f9ef88233ec21e9968187fd84526076c5853cb62d8397721b76ae8bd0a229f00", "semantics": 1, @@ -8431,6 +8491,7 @@ } }, { + "read_only": true, "name": "grep", "schema_digest": "0f7a077fe3aee4e28d4cdebb8093776db34692c342ef3b67c3b9e49fe7c31f19", "semantics": 1, @@ -8470,6 +8531,7 @@ } }, { + "read_only": true, "name": "glob", "schema_digest": "f0710f894a9c43ff7709e5f5cb63c37f7cda4e969840379f728a6d55f353a659", "semantics": 1, @@ -8500,6 +8562,7 @@ } }, { + "read_only": true, "name": "search", "schema_digest": "c01cfa3965f768c100253bb0d59285149d4883f5fa46d7b511cc98e0a7efb70e", "semantics": 1, @@ -8609,6 +8672,7 @@ } }, { + "read_only": true, "name": "callgraph", "schema_digest": "cc1143512feeca2585bd922ab9047a00ef2496807a1307dac19e9047ae4e86de", "semantics": 1, @@ -8681,6 +8745,7 @@ } }, { + "read_only": true, "name": "conflicts", "schema_digest": "702d9af7c4449b1601b49d0b7d7573d150aa564430f9fc0c39e7af1dcea92d0c", "semantics": 1, @@ -8705,6 +8770,7 @@ } }, { + "read_only": true, "name": "ast_search", "schema_digest": "96463c1682f4d87f5216797bb29cc474cd88690a8c9469f1824d9d4b9faa0b35", "semantics": 1, @@ -9233,8 +9299,8 @@ "version": "0.58.1" }, "reply": { - "generation": "28b9be1058b178c5b8757918b515d815265fe257f279c859d56df87187c31f5e", - "catalog_digest": "28b9be1058b178c5b8757918b515d815265fe257f279c859d56df87187c31f5e", + "generation": "ab97e13bf4b392423b98f940bb9657feba6cc0c504dae6c950fb9ac71cdc5c40", + "catalog_digest": "ab97e13bf4b392423b98f940bb9657feba6cc0c504dae6c950fb9ac71cdc5c40", "tools": [ { "name": "status", @@ -9336,6 +9402,7 @@ } }, { + "read_only": true, "name": "read", "schema_digest": "f9ef88233ec21e9968187fd84526076c5853cb62d8397721b76ae8bd0a229f00", "semantics": 1, @@ -9534,6 +9601,7 @@ } }, { + "read_only": true, "name": "grep", "schema_digest": "0f7a077fe3aee4e28d4cdebb8093776db34692c342ef3b67c3b9e49fe7c31f19", "semantics": 1, @@ -9573,6 +9641,7 @@ } }, { + "read_only": true, "name": "glob", "schema_digest": "f0710f894a9c43ff7709e5f5cb63c37f7cda4e969840379f728a6d55f353a659", "semantics": 1, @@ -9603,6 +9672,7 @@ } }, { + "read_only": true, "name": "outline", "schema_digest": "264536293f3baca10d5e6b695baf9a29f71ea74b7e4241ceaed26e3b46e165cf", "semantics": 1, @@ -9709,6 +9779,7 @@ } }, { + "read_only": true, "name": "callgraph", "schema_digest": "cc1143512feeca2585bd922ab9047a00ef2496807a1307dac19e9047ae4e86de", "semantics": 1, @@ -9781,6 +9852,7 @@ } }, { + "read_only": true, "name": "conflicts", "schema_digest": "702d9af7c4449b1601b49d0b7d7573d150aa564430f9fc0c39e7af1dcea92d0c", "semantics": 1, @@ -9805,6 +9877,7 @@ } }, { + "read_only": true, "name": "ast_search", "schema_digest": "96463c1682f4d87f5216797bb29cc474cd88690a8c9469f1824d9d4b9faa0b35", "semantics": 1, @@ -10330,8 +10403,8 @@ "version": "0.58.1" }, "reply": { - "generation": "81cd3bde5d7ab44f6065690e0b390d766d0d49a63ce179eeb40c72c6c8b2644a", - "catalog_digest": "81cd3bde5d7ab44f6065690e0b390d766d0d49a63ce179eeb40c72c6c8b2644a", + "generation": "dc8a586da625ee2da056eb6faac6fcacfb1c06b9ecfc81a1d9bd2187039a5e39", + "catalog_digest": "dc8a586da625ee2da056eb6faac6fcacfb1c06b9ecfc81a1d9bd2187039a5e39", "tools": [ { "name": "status", @@ -10507,6 +10580,7 @@ } }, { + "read_only": true, "name": "read", "schema_digest": "f9ef88233ec21e9968187fd84526076c5853cb62d8397721b76ae8bd0a229f00", "semantics": 1, @@ -10705,6 +10779,7 @@ } }, { + "read_only": true, "name": "grep", "schema_digest": "0f7a077fe3aee4e28d4cdebb8093776db34692c342ef3b67c3b9e49fe7c31f19", "semantics": 1, @@ -10744,6 +10819,7 @@ } }, { + "read_only": true, "name": "glob", "schema_digest": "f0710f894a9c43ff7709e5f5cb63c37f7cda4e969840379f728a6d55f353a659", "semantics": 1, @@ -10774,6 +10850,7 @@ } }, { + "read_only": true, "name": "search", "schema_digest": "c01cfa3965f768c100253bb0d59285149d4883f5fa46d7b511cc98e0a7efb70e", "semantics": 1, @@ -10823,6 +10900,7 @@ } }, { + "read_only": true, "name": "outline", "schema_digest": "264536293f3baca10d5e6b695baf9a29f71ea74b7e4241ceaed26e3b46e165cf", "semantics": 1, @@ -10869,6 +10947,7 @@ } }, { + "read_only": true, "name": "zoom", "schema_digest": "0c709b2d562766296a0e4601b4a16304488d2ffff6e8ac4ccfc4b68e1fe9be39", "semantics": 1, @@ -10995,6 +11074,7 @@ } }, { + "read_only": true, "name": "callgraph", "schema_digest": "cc1143512feeca2585bd922ab9047a00ef2496807a1307dac19e9047ae4e86de", "semantics": 1, @@ -11067,6 +11147,7 @@ } }, { + "read_only": true, "name": "conflicts", "schema_digest": "702d9af7c4449b1601b49d0b7d7573d150aa564430f9fc0c39e7af1dcea92d0c", "semantics": 1, @@ -11091,6 +11172,7 @@ } }, { + "read_only": true, "name": "ast_search", "schema_digest": "96463c1682f4d87f5216797bb29cc474cd88690a8c9469f1824d9d4b9faa0b35", "semantics": 1, @@ -11619,8 +11701,8 @@ "version": "0.58.1" }, "reply": { - "generation": "877ae77fd3d58188edaf3784030dc8a43359d1170ac2760e458922b1f5d342cd", - "catalog_digest": "877ae77fd3d58188edaf3784030dc8a43359d1170ac2760e458922b1f5d342cd", + "generation": "42b0d3cfed5c19377b5f7bc9c6cf3ea269986f7a795cfa80dad5df22d0bfa3fc", + "catalog_digest": "42b0d3cfed5c19377b5f7bc9c6cf3ea269986f7a795cfa80dad5df22d0bfa3fc", "tools": [ { "name": "status", @@ -11796,6 +11878,7 @@ } }, { + "read_only": true, "name": "read", "schema_digest": "f9ef88233ec21e9968187fd84526076c5853cb62d8397721b76ae8bd0a229f00", "semantics": 1, @@ -11994,6 +12077,7 @@ } }, { + "read_only": true, "name": "grep", "schema_digest": "0f7a077fe3aee4e28d4cdebb8093776db34692c342ef3b67c3b9e49fe7c31f19", "semantics": 1, @@ -12033,6 +12117,7 @@ } }, { + "read_only": true, "name": "glob", "schema_digest": "f0710f894a9c43ff7709e5f5cb63c37f7cda4e969840379f728a6d55f353a659", "semantics": 1, @@ -12063,6 +12148,7 @@ } }, { + "read_only": true, "name": "search", "schema_digest": "c01cfa3965f768c100253bb0d59285149d4883f5fa46d7b511cc98e0a7efb70e", "semantics": 1, @@ -12112,6 +12198,7 @@ } }, { + "read_only": true, "name": "outline", "schema_digest": "264536293f3baca10d5e6b695baf9a29f71ea74b7e4241ceaed26e3b46e165cf", "semantics": 1, @@ -12158,6 +12245,7 @@ } }, { + "read_only": true, "name": "zoom", "schema_digest": "0c709b2d562766296a0e4601b4a16304488d2ffff6e8ac4ccfc4b68e1fe9be39", "semantics": 1, @@ -12284,6 +12372,7 @@ } }, { + "read_only": true, "name": "callgraph", "schema_digest": "cc1143512feeca2585bd922ab9047a00ef2496807a1307dac19e9047ae4e86de", "semantics": 1, @@ -12356,6 +12445,7 @@ } }, { + "read_only": true, "name": "conflicts", "schema_digest": "702d9af7c4449b1601b49d0b7d7573d150aa564430f9fc0c39e7af1dcea92d0c", "semantics": 1, @@ -12380,6 +12470,7 @@ } }, { + "read_only": true, "name": "ast_search", "schema_digest": "96463c1682f4d87f5216797bb29cc474cd88690a8c9469f1824d9d4b9faa0b35", "semantics": 1, @@ -12910,8 +13001,8 @@ "version": "0.58.1" }, "reply": { - "generation": "142ba5cd13829bee1e24c62f17cbb76405aeef66958ff9178c3bc4f1c30d6f44", - "catalog_digest": "142ba5cd13829bee1e24c62f17cbb76405aeef66958ff9178c3bc4f1c30d6f44", + "generation": "620e6ad226ebdf1877d24ec0711f9afe2a5359263d1808629e7fa0af6cb134c7", + "catalog_digest": "620e6ad226ebdf1877d24ec0711f9afe2a5359263d1808629e7fa0af6cb134c7", "tools": [ { "name": "status", @@ -13005,6 +13096,7 @@ } }, { + "read_only": true, "name": "read", "schema_digest": "f9ef88233ec21e9968187fd84526076c5853cb62d8397721b76ae8bd0a229f00", "semantics": 1, @@ -13203,6 +13295,7 @@ } }, { + "read_only": true, "name": "grep", "schema_digest": "0f7a077fe3aee4e28d4cdebb8093776db34692c342ef3b67c3b9e49fe7c31f19", "semantics": 1, @@ -13242,6 +13335,7 @@ } }, { + "read_only": true, "name": "glob", "schema_digest": "f0710f894a9c43ff7709e5f5cb63c37f7cda4e969840379f728a6d55f353a659", "semantics": 1, @@ -13272,6 +13366,7 @@ } }, { + "read_only": true, "name": "search", "schema_digest": "c01cfa3965f768c100253bb0d59285149d4883f5fa46d7b511cc98e0a7efb70e", "semantics": 1, @@ -13321,6 +13416,7 @@ } }, { + "read_only": true, "name": "outline", "schema_digest": "264536293f3baca10d5e6b695baf9a29f71ea74b7e4241ceaed26e3b46e165cf", "semantics": 1, @@ -13367,6 +13463,7 @@ } }, { + "read_only": true, "name": "zoom", "schema_digest": "0c709b2d562766296a0e4601b4a16304488d2ffff6e8ac4ccfc4b68e1fe9be39", "semantics": 1, @@ -13493,6 +13590,7 @@ } }, { + "read_only": true, "name": "callgraph", "schema_digest": "cc1143512feeca2585bd922ab9047a00ef2496807a1307dac19e9047ae4e86de", "semantics": 1, @@ -13565,6 +13663,7 @@ } }, { + "read_only": true, "name": "conflicts", "schema_digest": "702d9af7c4449b1601b49d0b7d7573d150aa564430f9fc0c39e7af1dcea92d0c", "semantics": 1, @@ -13589,6 +13688,7 @@ } }, { + "read_only": true, "name": "ast_search", "schema_digest": "96463c1682f4d87f5216797bb29cc474cd88690a8c9469f1824d9d4b9faa0b35", "semantics": 1, @@ -14118,8 +14218,8 @@ "version": "0.58.1" }, "reply": { - "generation": "d08fc228070cdf70dc41745a5274dc325bad21c1d481131bc651c586853bddbc", - "catalog_digest": "d08fc228070cdf70dc41745a5274dc325bad21c1d481131bc651c586853bddbc", + "generation": "5d4d3ed34a10e7a4dd8612144f564c1deca6def33e149507a5255d3037c6deea", + "catalog_digest": "5d4d3ed34a10e7a4dd8612144f564c1deca6def33e149507a5255d3037c6deea", "tools": [ { "name": "status", @@ -14295,6 +14395,7 @@ } }, { + "read_only": true, "name": "read", "schema_digest": "f9ef88233ec21e9968187fd84526076c5853cb62d8397721b76ae8bd0a229f00", "semantics": 1, @@ -14493,6 +14594,7 @@ } }, { + "read_only": true, "name": "grep", "schema_digest": "0f7a077fe3aee4e28d4cdebb8093776db34692c342ef3b67c3b9e49fe7c31f19", "semantics": 1, @@ -14532,6 +14634,7 @@ } }, { + "read_only": true, "name": "glob", "schema_digest": "f0710f894a9c43ff7709e5f5cb63c37f7cda4e969840379f728a6d55f353a659", "semantics": 1, @@ -14562,6 +14665,7 @@ } }, { + "read_only": true, "name": "search", "schema_digest": "c01cfa3965f768c100253bb0d59285149d4883f5fa46d7b511cc98e0a7efb70e", "semantics": 1, @@ -14611,6 +14715,7 @@ } }, { + "read_only": true, "name": "zoom", "schema_digest": "0c709b2d562766296a0e4601b4a16304488d2ffff6e8ac4ccfc4b68e1fe9be39", "semantics": 1, @@ -14737,6 +14842,7 @@ } }, { + "read_only": true, "name": "callgraph", "schema_digest": "cc1143512feeca2585bd922ab9047a00ef2496807a1307dac19e9047ae4e86de", "semantics": 1, @@ -14809,6 +14915,7 @@ } }, { + "read_only": true, "name": "conflicts", "schema_digest": "702d9af7c4449b1601b49d0b7d7573d150aa564430f9fc0c39e7af1dcea92d0c", "semantics": 1, @@ -14833,6 +14940,7 @@ } }, { + "read_only": true, "name": "ast_search", "schema_digest": "96463c1682f4d87f5216797bb29cc474cd88690a8c9469f1824d9d4b9faa0b35", "semantics": 1, @@ -15362,8 +15470,8 @@ "version": "0.58.1" }, "reply": { - "generation": "44a9239e90b2e929c7319dd9da858cccb108aa1fd634c1ef73c1c56c4fa7d7f6", - "catalog_digest": "44a9239e90b2e929c7319dd9da858cccb108aa1fd634c1ef73c1c56c4fa7d7f6", + "generation": "c64d7e132efe14d0fe133df4c5e0d7aee0205a3876df28af40154c76c46e4b77", + "catalog_digest": "c64d7e132efe14d0fe133df4c5e0d7aee0205a3876df28af40154c76c46e4b77", "tools": [ { "name": "status", @@ -15539,6 +15647,7 @@ } }, { + "read_only": true, "name": "read", "schema_digest": "f9ef88233ec21e9968187fd84526076c5853cb62d8397721b76ae8bd0a229f00", "semantics": 1, @@ -15737,6 +15846,7 @@ } }, { + "read_only": true, "name": "grep", "schema_digest": "0f7a077fe3aee4e28d4cdebb8093776db34692c342ef3b67c3b9e49fe7c31f19", "semantics": 1, @@ -15776,6 +15886,7 @@ } }, { + "read_only": true, "name": "glob", "schema_digest": "f0710f894a9c43ff7709e5f5cb63c37f7cda4e969840379f728a6d55f353a659", "semantics": 1, @@ -15806,6 +15917,7 @@ } }, { + "read_only": true, "name": "outline", "schema_digest": "264536293f3baca10d5e6b695baf9a29f71ea74b7e4241ceaed26e3b46e165cf", "semantics": 1, @@ -15852,6 +15964,7 @@ } }, { + "read_only": true, "name": "zoom", "schema_digest": "0c709b2d562766296a0e4601b4a16304488d2ffff6e8ac4ccfc4b68e1fe9be39", "semantics": 1, @@ -15978,6 +16091,7 @@ } }, { + "read_only": true, "name": "callgraph", "schema_digest": "cc1143512feeca2585bd922ab9047a00ef2496807a1307dac19e9047ae4e86de", "semantics": 1, @@ -16050,6 +16164,7 @@ } }, { + "read_only": true, "name": "conflicts", "schema_digest": "702d9af7c4449b1601b49d0b7d7573d150aa564430f9fc0c39e7af1dcea92d0c", "semantics": 1, @@ -16074,6 +16189,7 @@ } }, { + "read_only": true, "name": "ast_search", "schema_digest": "96463c1682f4d87f5216797bb29cc474cd88690a8c9469f1824d9d4b9faa0b35", "semantics": 1, @@ -16604,8 +16720,8 @@ "version": "0.58.1" }, "reply": { - "generation": "d6b048ff5619064e90ba1fbc7f567da16556962d64532f8be3069fb0d4c128a2", - "catalog_digest": "d6b048ff5619064e90ba1fbc7f567da16556962d64532f8be3069fb0d4c128a2", + "generation": "ef517c0071890f8b35f96a07adae546fd4328b9b7a732f51f4141bfd25d23639", + "catalog_digest": "ef517c0071890f8b35f96a07adae546fd4328b9b7a732f51f4141bfd25d23639", "tools": [ { "name": "status", @@ -16781,6 +16897,7 @@ } }, { + "read_only": true, "name": "read", "schema_digest": "f9ef88233ec21e9968187fd84526076c5853cb62d8397721b76ae8bd0a229f00", "semantics": 1, @@ -16979,6 +17096,7 @@ } }, { + "read_only": true, "name": "grep", "schema_digest": "0f7a077fe3aee4e28d4cdebb8093776db34692c342ef3b67c3b9e49fe7c31f19", "semantics": 1, @@ -17018,6 +17136,7 @@ } }, { + "read_only": true, "name": "glob", "schema_digest": "f0710f894a9c43ff7709e5f5cb63c37f7cda4e969840379f728a6d55f353a659", "semantics": 1, @@ -17048,6 +17167,7 @@ } }, { + "read_only": true, "name": "search", "schema_digest": "c01cfa3965f768c100253bb0d59285149d4883f5fa46d7b511cc98e0a7efb70e", "semantics": 1, @@ -17097,6 +17217,7 @@ } }, { + "read_only": true, "name": "zoom", "schema_digest": "0c709b2d562766296a0e4601b4a16304488d2ffff6e8ac4ccfc4b68e1fe9be39", "semantics": 1, @@ -17163,6 +17284,7 @@ } }, { + "read_only": true, "name": "callgraph", "schema_digest": "cc1143512feeca2585bd922ab9047a00ef2496807a1307dac19e9047ae4e86de", "semantics": 1, @@ -17235,6 +17357,7 @@ } }, { + "read_only": true, "name": "conflicts", "schema_digest": "702d9af7c4449b1601b49d0b7d7573d150aa564430f9fc0c39e7af1dcea92d0c", "semantics": 1, @@ -17259,6 +17382,7 @@ } }, { + "read_only": true, "name": "ast_search", "schema_digest": "96463c1682f4d87f5216797bb29cc474cd88690a8c9469f1824d9d4b9faa0b35", "semantics": 1, @@ -17788,8 +17912,8 @@ "version": "0.58.1" }, "reply": { - "generation": "87ffb8642e7b7cb831d917147d5c019cfcb5d632ebc6ed0e36b5fafc91291587", - "catalog_digest": "87ffb8642e7b7cb831d917147d5c019cfcb5d632ebc6ed0e36b5fafc91291587", + "generation": "fc87f1c4453657a874869ec6e4bb1e07f4aeb772c064ebae61666bfe7e7061da", + "catalog_digest": "fc87f1c4453657a874869ec6e4bb1e07f4aeb772c064ebae61666bfe7e7061da", "tools": [ { "name": "status", @@ -17965,6 +18089,7 @@ } }, { + "read_only": true, "name": "read", "schema_digest": "f9ef88233ec21e9968187fd84526076c5853cb62d8397721b76ae8bd0a229f00", "semantics": 1, @@ -18163,6 +18288,7 @@ } }, { + "read_only": true, "name": "grep", "schema_digest": "0f7a077fe3aee4e28d4cdebb8093776db34692c342ef3b67c3b9e49fe7c31f19", "semantics": 1, @@ -18202,6 +18328,7 @@ } }, { + "read_only": true, "name": "glob", "schema_digest": "f0710f894a9c43ff7709e5f5cb63c37f7cda4e969840379f728a6d55f353a659", "semantics": 1, @@ -18232,6 +18359,7 @@ } }, { + "read_only": true, "name": "outline", "schema_digest": "264536293f3baca10d5e6b695baf9a29f71ea74b7e4241ceaed26e3b46e165cf", "semantics": 1, @@ -18278,6 +18406,7 @@ } }, { + "read_only": true, "name": "zoom", "schema_digest": "0c709b2d562766296a0e4601b4a16304488d2ffff6e8ac4ccfc4b68e1fe9be39", "semantics": 1, @@ -18344,6 +18473,7 @@ } }, { + "read_only": true, "name": "callgraph", "schema_digest": "cc1143512feeca2585bd922ab9047a00ef2496807a1307dac19e9047ae4e86de", "semantics": 1, @@ -18416,6 +18546,7 @@ } }, { + "read_only": true, "name": "conflicts", "schema_digest": "702d9af7c4449b1601b49d0b7d7573d150aa564430f9fc0c39e7af1dcea92d0c", "semantics": 1, @@ -18440,6 +18571,7 @@ } }, { + "read_only": true, "name": "ast_search", "schema_digest": "96463c1682f4d87f5216797bb29cc474cd88690a8c9469f1824d9d4b9faa0b35", "semantics": 1, @@ -18969,8 +19101,8 @@ "version": "0.58.1" }, "reply": { - "generation": "60dfa135c363e83cb1df92d6f24c077796151a4e623565292ae636209365b7f5", - "catalog_digest": "60dfa135c363e83cb1df92d6f24c077796151a4e623565292ae636209365b7f5", + "generation": "5bb098407453a67fa99ba3d349448e656482526387146e243fea5c227e750dc4", + "catalog_digest": "5bb098407453a67fa99ba3d349448e656482526387146e243fea5c227e750dc4", "tools": [ { "name": "status", @@ -19146,6 +19278,7 @@ } }, { + "read_only": true, "name": "read", "schema_digest": "f9ef88233ec21e9968187fd84526076c5853cb62d8397721b76ae8bd0a229f00", "semantics": 1, @@ -19344,6 +19477,7 @@ } }, { + "read_only": true, "name": "grep", "schema_digest": "0f7a077fe3aee4e28d4cdebb8093776db34692c342ef3b67c3b9e49fe7c31f19", "semantics": 1, @@ -19383,6 +19517,7 @@ } }, { + "read_only": true, "name": "glob", "schema_digest": "f0710f894a9c43ff7709e5f5cb63c37f7cda4e969840379f728a6d55f353a659", "semantics": 1, @@ -19413,6 +19548,7 @@ } }, { + "read_only": true, "name": "search", "schema_digest": "c01cfa3965f768c100253bb0d59285149d4883f5fa46d7b511cc98e0a7efb70e", "semantics": 1, @@ -19522,6 +19658,7 @@ } }, { + "read_only": true, "name": "callgraph", "schema_digest": "cc1143512feeca2585bd922ab9047a00ef2496807a1307dac19e9047ae4e86de", "semantics": 1, @@ -19594,6 +19731,7 @@ } }, { + "read_only": true, "name": "conflicts", "schema_digest": "702d9af7c4449b1601b49d0b7d7573d150aa564430f9fc0c39e7af1dcea92d0c", "semantics": 1, @@ -19618,6 +19756,7 @@ } }, { + "read_only": true, "name": "ast_search", "schema_digest": "96463c1682f4d87f5216797bb29cc474cd88690a8c9469f1824d9d4b9faa0b35", "semantics": 1, @@ -20147,8 +20286,8 @@ "version": "0.58.1" }, "reply": { - "generation": "7697f9b51555a8b71f41bdb5fc6d626fa68fb6bc62ae1c94b34657eecfb9725a", - "catalog_digest": "7697f9b51555a8b71f41bdb5fc6d626fa68fb6bc62ae1c94b34657eecfb9725a", + "generation": "f4d803038bf414aa1f9d6bc03a2ca21b65c8e91ca5530da8860411d6694f9706", + "catalog_digest": "f4d803038bf414aa1f9d6bc03a2ca21b65c8e91ca5530da8860411d6694f9706", "tools": [ { "name": "status", @@ -20324,6 +20463,7 @@ } }, { + "read_only": true, "name": "read", "schema_digest": "f9ef88233ec21e9968187fd84526076c5853cb62d8397721b76ae8bd0a229f00", "semantics": 1, @@ -20522,6 +20662,7 @@ } }, { + "read_only": true, "name": "grep", "schema_digest": "0f7a077fe3aee4e28d4cdebb8093776db34692c342ef3b67c3b9e49fe7c31f19", "semantics": 1, @@ -20561,6 +20702,7 @@ } }, { + "read_only": true, "name": "glob", "schema_digest": "f0710f894a9c43ff7709e5f5cb63c37f7cda4e969840379f728a6d55f353a659", "semantics": 1, @@ -20591,6 +20733,7 @@ } }, { + "read_only": true, "name": "outline", "schema_digest": "264536293f3baca10d5e6b695baf9a29f71ea74b7e4241ceaed26e3b46e165cf", "semantics": 1, @@ -20697,6 +20840,7 @@ } }, { + "read_only": true, "name": "callgraph", "schema_digest": "cc1143512feeca2585bd922ab9047a00ef2496807a1307dac19e9047ae4e86de", "semantics": 1, @@ -20769,6 +20913,7 @@ } }, { + "read_only": true, "name": "conflicts", "schema_digest": "702d9af7c4449b1601b49d0b7d7573d150aa564430f9fc0c39e7af1dcea92d0c", "semantics": 1, @@ -20793,6 +20938,7 @@ } }, { + "read_only": true, "name": "ast_search", "schema_digest": "96463c1682f4d87f5216797bb29cc474cd88690a8c9469f1824d9d4b9faa0b35", "semantics": 1, diff --git a/crates/aft/tests/fixtures/tool_provider_catalog_presets.json b/crates/aft/tests/fixtures/tool_provider_catalog_presets.json index c09bdf00fe..4dce3ac331 100644 --- a/crates/aft/tests/fixtures/tool_provider_catalog_presets.json +++ b/crates/aft/tests/fixtures/tool_provider_catalog_presets.json @@ -10,8 +10,8 @@ "disabled_tools": [], "powershell_available": false, "reply": { - "generation": "87b3d585c5e7fa30fd31ab09e22d4fb7c4778090f1336b6a7bb24d4fafc08ba4", - "catalog_digest": "87b3d585c5e7fa30fd31ab09e22d4fb7c4778090f1336b6a7bb24d4fafc08ba4", + "generation": "a91a426d38746f509bc621c2ab504f0ea480be13f87ee42b52f002f09205b09e", + "catalog_digest": "a91a426d38746f509bc621c2ab504f0ea480be13f87ee42b52f002f09205b09e", "tools": [ { "name": "status", @@ -113,6 +113,7 @@ } }, { + "read_only": true, "name": "read", "schema_digest": "f9ef88233ec21e9968187fd84526076c5853cb62d8397721b76ae8bd0a229f00", "semantics": 1, @@ -311,6 +312,7 @@ } }, { + "read_only": true, "name": "grep", "schema_digest": "0f7a077fe3aee4e28d4cdebb8093776db34692c342ef3b67c3b9e49fe7c31f19", "semantics": 1, @@ -350,6 +352,7 @@ } }, { + "read_only": true, "name": "glob", "schema_digest": "f0710f894a9c43ff7709e5f5cb63c37f7cda4e969840379f728a6d55f353a659", "semantics": 1, @@ -380,6 +383,7 @@ } }, { + "read_only": true, "name": "search", "schema_digest": "c01cfa3965f768c100253bb0d59285149d4883f5fa46d7b511cc98e0a7efb70e", "semantics": 1, @@ -429,6 +433,7 @@ } }, { + "read_only": true, "name": "outline", "schema_digest": "264536293f3baca10d5e6b695baf9a29f71ea74b7e4241ceaed26e3b46e165cf", "semantics": 1, @@ -475,6 +480,7 @@ } }, { + "read_only": true, "name": "zoom", "schema_digest": "0c709b2d562766296a0e4601b4a16304488d2ffff6e8ac4ccfc4b68e1fe9be39", "semantics": 1, @@ -601,6 +607,7 @@ } }, { + "read_only": true, "name": "callgraph", "schema_digest": "cc1143512feeca2585bd922ab9047a00ef2496807a1307dac19e9047ae4e86de", "semantics": 1, @@ -673,6 +680,7 @@ } }, { + "read_only": true, "name": "conflicts", "schema_digest": "702d9af7c4449b1601b49d0b7d7573d150aa564430f9fc0c39e7af1dcea92d0c", "semantics": 1, @@ -697,6 +705,7 @@ } }, { + "read_only": true, "name": "ast_search", "schema_digest": "96463c1682f4d87f5216797bb29cc474cd88690a8c9469f1824d9d4b9faa0b35", "semantics": 1, @@ -1279,8 +1288,8 @@ "disabled_tools": [], "powershell_available": true, "reply": { - "generation": "e50c068a871ff3fac578280b624bffe06f86f2c430a3d2e5735cc98c749206d7", - "catalog_digest": "e50c068a871ff3fac578280b624bffe06f86f2c430a3d2e5735cc98c749206d7", + "generation": "54abe96577ce8c0d5ccf626d25aad4839fefab7b9d22d8851ef91ebc33e08d0d", + "catalog_digest": "54abe96577ce8c0d5ccf626d25aad4839fefab7b9d22d8851ef91ebc33e08d0d", "tools": [ { "name": "status", @@ -1456,6 +1465,7 @@ } }, { + "read_only": true, "name": "read", "schema_digest": "f9ef88233ec21e9968187fd84526076c5853cb62d8397721b76ae8bd0a229f00", "semantics": 1, @@ -1654,6 +1664,7 @@ } }, { + "read_only": true, "name": "grep", "schema_digest": "0f7a077fe3aee4e28d4cdebb8093776db34692c342ef3b67c3b9e49fe7c31f19", "semantics": 1, @@ -1693,6 +1704,7 @@ } }, { + "read_only": true, "name": "glob", "schema_digest": "f0710f894a9c43ff7709e5f5cb63c37f7cda4e969840379f728a6d55f353a659", "semantics": 1, @@ -1723,6 +1735,7 @@ } }, { + "read_only": true, "name": "search", "schema_digest": "c01cfa3965f768c100253bb0d59285149d4883f5fa46d7b511cc98e0a7efb70e", "semantics": 1, @@ -1772,6 +1785,7 @@ } }, { + "read_only": true, "name": "outline", "schema_digest": "264536293f3baca10d5e6b695baf9a29f71ea74b7e4241ceaed26e3b46e165cf", "semantics": 1, @@ -1818,6 +1832,7 @@ } }, { + "read_only": true, "name": "zoom", "schema_digest": "0c709b2d562766296a0e4601b4a16304488d2ffff6e8ac4ccfc4b68e1fe9be39", "semantics": 1, @@ -1944,6 +1959,7 @@ } }, { + "read_only": true, "name": "callgraph", "schema_digest": "cc1143512feeca2585bd922ab9047a00ef2496807a1307dac19e9047ae4e86de", "semantics": 1, @@ -2016,6 +2032,7 @@ } }, { + "read_only": true, "name": "conflicts", "schema_digest": "702d9af7c4449b1601b49d0b7d7573d150aa564430f9fc0c39e7af1dcea92d0c", "semantics": 1, @@ -2040,6 +2057,7 @@ } }, { + "read_only": true, "name": "ast_search", "schema_digest": "96463c1682f4d87f5216797bb29cc474cd88690a8c9469f1824d9d4b9faa0b35", "semantics": 1, @@ -2623,10 +2641,11 @@ "disabled_tools": [], "powershell_available": false, "reply": { - "generation": "34f9c1db13de0fa4d9aefbf1b6be686edf2bfb433b1805b9b85552e685076332", - "catalog_digest": "34f9c1db13de0fa4d9aefbf1b6be686edf2bfb433b1805b9b85552e685076332", + "generation": "754cb96898c96ed805ce339cbdcce893a67a10e8850d005222b71a53d2cd647d", + "catalog_digest": "754cb96898c96ed805ce339cbdcce893a67a10e8850d005222b71a53d2cd647d", "tools": [ { + "read_only": true, "name": "read", "schema_digest": "f9ef88233ec21e9968187fd84526076c5853cb62d8397721b76ae8bd0a229f00", "semantics": 1, @@ -2683,6 +2702,7 @@ } }, { + "read_only": true, "name": "grep", "schema_digest": "0f7a077fe3aee4e28d4cdebb8093776db34692c342ef3b67c3b9e49fe7c31f19", "semantics": 1, @@ -2722,6 +2742,7 @@ } }, { + "read_only": true, "name": "glob", "schema_digest": "f0710f894a9c43ff7709e5f5cb63c37f7cda4e969840379f728a6d55f353a659", "semantics": 1, @@ -2752,6 +2773,7 @@ } }, { + "read_only": true, "name": "search", "schema_digest": "c01cfa3965f768c100253bb0d59285149d4883f5fa46d7b511cc98e0a7efb70e", "semantics": 1, @@ -2801,6 +2823,7 @@ } }, { + "read_only": true, "name": "outline", "schema_digest": "264536293f3baca10d5e6b695baf9a29f71ea74b7e4241ceaed26e3b46e165cf", "semantics": 1, @@ -2847,6 +2870,7 @@ } }, { + "read_only": true, "name": "zoom", "schema_digest": "0c709b2d562766296a0e4601b4a16304488d2ffff6e8ac4ccfc4b68e1fe9be39", "semantics": 1, @@ -2973,6 +2997,7 @@ } }, { + "read_only": true, "name": "callgraph", "schema_digest": "cc1143512feeca2585bd922ab9047a00ef2496807a1307dac19e9047ae4e86de", "semantics": 1, @@ -3076,10 +3101,11 @@ "disabled_tools": [], "powershell_available": true, "reply": { - "generation": "34f9c1db13de0fa4d9aefbf1b6be686edf2bfb433b1805b9b85552e685076332", - "catalog_digest": "34f9c1db13de0fa4d9aefbf1b6be686edf2bfb433b1805b9b85552e685076332", + "generation": "754cb96898c96ed805ce339cbdcce893a67a10e8850d005222b71a53d2cd647d", + "catalog_digest": "754cb96898c96ed805ce339cbdcce893a67a10e8850d005222b71a53d2cd647d", "tools": [ { + "read_only": true, "name": "read", "schema_digest": "f9ef88233ec21e9968187fd84526076c5853cb62d8397721b76ae8bd0a229f00", "semantics": 1, @@ -3136,6 +3162,7 @@ } }, { + "read_only": true, "name": "grep", "schema_digest": "0f7a077fe3aee4e28d4cdebb8093776db34692c342ef3b67c3b9e49fe7c31f19", "semantics": 1, @@ -3175,6 +3202,7 @@ } }, { + "read_only": true, "name": "glob", "schema_digest": "f0710f894a9c43ff7709e5f5cb63c37f7cda4e969840379f728a6d55f353a659", "semantics": 1, @@ -3205,6 +3233,7 @@ } }, { + "read_only": true, "name": "search", "schema_digest": "c01cfa3965f768c100253bb0d59285149d4883f5fa46d7b511cc98e0a7efb70e", "semantics": 1, @@ -3254,6 +3283,7 @@ } }, { + "read_only": true, "name": "outline", "schema_digest": "264536293f3baca10d5e6b695baf9a29f71ea74b7e4241ceaed26e3b46e165cf", "semantics": 1, @@ -3300,6 +3330,7 @@ } }, { + "read_only": true, "name": "zoom", "schema_digest": "0c709b2d562766296a0e4601b4a16304488d2ffff6e8ac4ccfc4b68e1fe9be39", "semantics": 1, @@ -3426,6 +3457,7 @@ } }, { + "read_only": true, "name": "callgraph", "schema_digest": "cc1143512feeca2585bd922ab9047a00ef2496807a1307dac19e9047ae4e86de", "semantics": 1, @@ -3530,8 +3562,8 @@ "powershell_available": false, "remote_runs": true, "reply": { - "generation": "2aa3c95ee1d36d80bf1c8a3d85343465c06e39664e6a980e95258ec30bd164e3", - "catalog_digest": "2aa3c95ee1d36d80bf1c8a3d85343465c06e39664e6a980e95258ec30bd164e3", + "generation": "15c017b29b8bdb0f77ebda55a775d5a345f30f452a3bfdf7556125006874fce8", + "catalog_digest": "15c017b29b8bdb0f77ebda55a775d5a345f30f452a3bfdf7556125006874fce8", "tools": [ { "name": "status", @@ -3645,6 +3677,7 @@ } }, { + "read_only": true, "name": "read", "schema_digest": "f9ef88233ec21e9968187fd84526076c5853cb62d8397721b76ae8bd0a229f00", "semantics": 1, @@ -3843,6 +3876,7 @@ } }, { + "read_only": true, "name": "grep", "schema_digest": "0f7a077fe3aee4e28d4cdebb8093776db34692c342ef3b67c3b9e49fe7c31f19", "semantics": 1, @@ -3882,6 +3916,7 @@ } }, { + "read_only": true, "name": "glob", "schema_digest": "f0710f894a9c43ff7709e5f5cb63c37f7cda4e969840379f728a6d55f353a659", "semantics": 1, @@ -3912,6 +3947,7 @@ } }, { + "read_only": true, "name": "search", "schema_digest": "c01cfa3965f768c100253bb0d59285149d4883f5fa46d7b511cc98e0a7efb70e", "semantics": 1, @@ -3961,6 +3997,7 @@ } }, { + "read_only": true, "name": "outline", "schema_digest": "264536293f3baca10d5e6b695baf9a29f71ea74b7e4241ceaed26e3b46e165cf", "semantics": 1, @@ -4007,6 +4044,7 @@ } }, { + "read_only": true, "name": "zoom", "schema_digest": "0c709b2d562766296a0e4601b4a16304488d2ffff6e8ac4ccfc4b68e1fe9be39", "semantics": 1, @@ -4133,6 +4171,7 @@ } }, { + "read_only": true, "name": "callgraph", "schema_digest": "cc1143512feeca2585bd922ab9047a00ef2496807a1307dac19e9047ae4e86de", "semantics": 1, @@ -4205,6 +4244,7 @@ } }, { + "read_only": true, "name": "conflicts", "schema_digest": "702d9af7c4449b1601b49d0b7d7573d150aa564430f9fc0c39e7af1dcea92d0c", "semantics": 1, @@ -4229,6 +4269,7 @@ } }, { + "read_only": true, "name": "ast_search", "schema_digest": "96463c1682f4d87f5216797bb29cc474cd88690a8c9469f1824d9d4b9faa0b35", "semantics": 1, @@ -4812,8 +4853,8 @@ "powershell_available": true, "remote_runs": true, "reply": { - "generation": "dfe09c908969770cda7b9a063adbad1d0907e3f91b11c6fa49c73020086ecf75", - "catalog_digest": "dfe09c908969770cda7b9a063adbad1d0907e3f91b11c6fa49c73020086ecf75", + "generation": "70986d8c7bab9d7ddcdcfbf84813a14195ffdb56034302e7f45886113da83e8c", + "catalog_digest": "70986d8c7bab9d7ddcdcfbf84813a14195ffdb56034302e7f45886113da83e8c", "tools": [ { "name": "status", @@ -5001,6 +5042,7 @@ } }, { + "read_only": true, "name": "read", "schema_digest": "f9ef88233ec21e9968187fd84526076c5853cb62d8397721b76ae8bd0a229f00", "semantics": 1, @@ -5199,6 +5241,7 @@ } }, { + "read_only": true, "name": "grep", "schema_digest": "0f7a077fe3aee4e28d4cdebb8093776db34692c342ef3b67c3b9e49fe7c31f19", "semantics": 1, @@ -5238,6 +5281,7 @@ } }, { + "read_only": true, "name": "glob", "schema_digest": "f0710f894a9c43ff7709e5f5cb63c37f7cda4e969840379f728a6d55f353a659", "semantics": 1, @@ -5268,6 +5312,7 @@ } }, { + "read_only": true, "name": "search", "schema_digest": "c01cfa3965f768c100253bb0d59285149d4883f5fa46d7b511cc98e0a7efb70e", "semantics": 1, @@ -5317,6 +5362,7 @@ } }, { + "read_only": true, "name": "outline", "schema_digest": "264536293f3baca10d5e6b695baf9a29f71ea74b7e4241ceaed26e3b46e165cf", "semantics": 1, @@ -5363,6 +5409,7 @@ } }, { + "read_only": true, "name": "zoom", "schema_digest": "0c709b2d562766296a0e4601b4a16304488d2ffff6e8ac4ccfc4b68e1fe9be39", "semantics": 1, @@ -5489,6 +5536,7 @@ } }, { + "read_only": true, "name": "callgraph", "schema_digest": "cc1143512feeca2585bd922ab9047a00ef2496807a1307dac19e9047ae4e86de", "semantics": 1, @@ -5561,6 +5609,7 @@ } }, { + "read_only": true, "name": "conflicts", "schema_digest": "702d9af7c4449b1601b49d0b7d7573d150aa564430f9fc0c39e7af1dcea92d0c", "semantics": 1, @@ -5585,6 +5634,7 @@ } }, { + "read_only": true, "name": "ast_search", "schema_digest": "96463c1682f4d87f5216797bb29cc474cd88690a8c9469f1824d9d4b9faa0b35", "semantics": 1, @@ -6168,8 +6218,8 @@ "disabled_tools": [], "powershell_available": false, "reply": { - "generation": "31f607caad910ad5e638f61e67ea4eb105b81c6e875cecf05890215dbe9e124d", - "catalog_digest": "31f607caad910ad5e638f61e67ea4eb105b81c6e875cecf05890215dbe9e124d", + "generation": "5fe0c8895ecaf0a6469b94732f2db6cda45f3106210775a5207a15f71cf266d9", + "catalog_digest": "5fe0c8895ecaf0a6469b94732f2db6cda45f3106210775a5207a15f71cf266d9", "tools": [ { "name": "status", @@ -6271,6 +6321,7 @@ } }, { + "read_only": true, "name": "read", "schema_digest": "f9ef88233ec21e9968187fd84526076c5853cb62d8397721b76ae8bd0a229f00", "semantics": 1, @@ -6469,6 +6520,7 @@ } }, { + "read_only": true, "name": "grep", "schema_digest": "0f7a077fe3aee4e28d4cdebb8093776db34692c342ef3b67c3b9e49fe7c31f19", "semantics": 1, @@ -6508,6 +6560,7 @@ } }, { + "read_only": true, "name": "glob", "schema_digest": "f0710f894a9c43ff7709e5f5cb63c37f7cda4e969840379f728a6d55f353a659", "semantics": 1, @@ -6538,6 +6591,7 @@ } }, { + "read_only": true, "name": "search", "schema_digest": "c01cfa3965f768c100253bb0d59285149d4883f5fa46d7b511cc98e0a7efb70e", "semantics": 1, @@ -6587,6 +6641,7 @@ } }, { + "read_only": true, "name": "outline", "schema_digest": "264536293f3baca10d5e6b695baf9a29f71ea74b7e4241ceaed26e3b46e165cf", "semantics": 1, @@ -6633,6 +6688,7 @@ } }, { + "read_only": true, "name": "zoom", "schema_digest": "0c709b2d562766296a0e4601b4a16304488d2ffff6e8ac4ccfc4b68e1fe9be39", "semantics": 1, @@ -6759,6 +6815,7 @@ } }, { + "read_only": true, "name": "callgraph", "schema_digest": "cc1143512feeca2585bd922ab9047a00ef2496807a1307dac19e9047ae4e86de", "semantics": 1, @@ -6831,6 +6888,7 @@ } }, { + "read_only": true, "name": "conflicts", "schema_digest": "702d9af7c4449b1601b49d0b7d7573d150aa564430f9fc0c39e7af1dcea92d0c", "semantics": 1, @@ -6855,6 +6913,7 @@ } }, { + "read_only": true, "name": "ast_search", "schema_digest": "96463c1682f4d87f5216797bb29cc474cd88690a8c9469f1824d9d4b9faa0b35", "semantics": 1, @@ -7371,8 +7430,8 @@ "disabled_tools": [], "powershell_available": true, "reply": { - "generation": "d6c53aa22c6cf2fbf86a4f28aa122c892a3bfba589217da339273478227776fc", - "catalog_digest": "d6c53aa22c6cf2fbf86a4f28aa122c892a3bfba589217da339273478227776fc", + "generation": "7ddde2e17017d03560285880c724f1a067698382ec4507674ecbced6b62f1213", + "catalog_digest": "7ddde2e17017d03560285880c724f1a067698382ec4507674ecbced6b62f1213", "tools": [ { "name": "status", @@ -7548,6 +7607,7 @@ } }, { + "read_only": true, "name": "read", "schema_digest": "f9ef88233ec21e9968187fd84526076c5853cb62d8397721b76ae8bd0a229f00", "semantics": 1, @@ -7746,6 +7806,7 @@ } }, { + "read_only": true, "name": "grep", "schema_digest": "0f7a077fe3aee4e28d4cdebb8093776db34692c342ef3b67c3b9e49fe7c31f19", "semantics": 1, @@ -7785,6 +7846,7 @@ } }, { + "read_only": true, "name": "glob", "schema_digest": "f0710f894a9c43ff7709e5f5cb63c37f7cda4e969840379f728a6d55f353a659", "semantics": 1, @@ -7815,6 +7877,7 @@ } }, { + "read_only": true, "name": "search", "schema_digest": "c01cfa3965f768c100253bb0d59285149d4883f5fa46d7b511cc98e0a7efb70e", "semantics": 1, @@ -7864,6 +7927,7 @@ } }, { + "read_only": true, "name": "outline", "schema_digest": "264536293f3baca10d5e6b695baf9a29f71ea74b7e4241ceaed26e3b46e165cf", "semantics": 1, @@ -7910,6 +7974,7 @@ } }, { + "read_only": true, "name": "zoom", "schema_digest": "0c709b2d562766296a0e4601b4a16304488d2ffff6e8ac4ccfc4b68e1fe9be39", "semantics": 1, @@ -8036,6 +8101,7 @@ } }, { + "read_only": true, "name": "callgraph", "schema_digest": "cc1143512feeca2585bd922ab9047a00ef2496807a1307dac19e9047ae4e86de", "semantics": 1, @@ -8108,6 +8174,7 @@ } }, { + "read_only": true, "name": "conflicts", "schema_digest": "702d9af7c4449b1601b49d0b7d7573d150aa564430f9fc0c39e7af1dcea92d0c", "semantics": 1, @@ -8132,6 +8199,7 @@ } }, { + "read_only": true, "name": "ast_search", "schema_digest": "96463c1682f4d87f5216797bb29cc474cd88690a8c9469f1824d9d4b9faa0b35", "semantics": 1, @@ -8655,8 +8723,8 @@ "disabled_tools": [], "powershell_available": false, "reply": { - "generation": "413ad3baf6484ec32ae63df39479397a4321159132b351699d91217795752401", - "catalog_digest": "413ad3baf6484ec32ae63df39479397a4321159132b351699d91217795752401", + "generation": "5cc075df495707259abe0bc542b47f340e3d1fb53bc1a223fd01bde2844ce236", + "catalog_digest": "5cc075df495707259abe0bc542b47f340e3d1fb53bc1a223fd01bde2844ce236", "tools": [ { "name": "bash", @@ -8741,6 +8809,7 @@ } }, { + "read_only": true, "name": "read", "schema_digest": "f9ef88233ec21e9968187fd84526076c5853cb62d8397721b76ae8bd0a229f00", "semantics": 1, @@ -8824,6 +8893,7 @@ } }, { + "read_only": true, "name": "grep", "schema_digest": "0f7a077fe3aee4e28d4cdebb8093776db34692c342ef3b67c3b9e49fe7c31f19", "semantics": 1, @@ -8863,6 +8933,7 @@ } }, { + "read_only": true, "name": "glob", "schema_digest": "f0710f894a9c43ff7709e5f5cb63c37f7cda4e969840379f728a6d55f353a659", "semantics": 1, @@ -8893,6 +8964,7 @@ } }, { + "read_only": true, "name": "aft_search", "schema_digest": "c01cfa3965f768c100253bb0d59285149d4883f5fa46d7b511cc98e0a7efb70e", "semantics": 1, @@ -8942,6 +9014,7 @@ } }, { + "read_only": true, "name": "aft_outline", "schema_digest": "264536293f3baca10d5e6b695baf9a29f71ea74b7e4241ceaed26e3b46e165cf", "semantics": 1, @@ -8988,6 +9061,7 @@ } }, { + "read_only": true, "name": "aft_zoom", "schema_digest": "0c709b2d562766296a0e4601b4a16304488d2ffff6e8ac4ccfc4b68e1fe9be39", "semantics": 1, @@ -9114,6 +9188,7 @@ } }, { + "read_only": true, "name": "aft_callgraph", "schema_digest": "cc1143512feeca2585bd922ab9047a00ef2496807a1307dac19e9047ae4e86de", "semantics": 1, @@ -9186,6 +9261,7 @@ } }, { + "read_only": true, "name": "aft_conflicts", "schema_digest": "702d9af7c4449b1601b49d0b7d7573d150aa564430f9fc0c39e7af1dcea92d0c", "semantics": 1, @@ -9210,6 +9286,7 @@ } }, { + "read_only": true, "name": "ast_grep_search", "schema_digest": "96463c1682f4d87f5216797bb29cc474cd88690a8c9469f1824d9d4b9faa0b35", "semantics": 1, @@ -9782,8 +9859,8 @@ "disabled_tools": [], "powershell_available": false, "reply": { - "generation": "cafb946fb29c080c242f3c9313805664d8de5ba6cf92f1516fc3637cc5fdd231", - "catalog_digest": "cafb946fb29c080c242f3c9313805664d8de5ba6cf92f1516fc3637cc5fdd231", + "generation": "a47a88a9232f0a0452f502095bc8fd7d9703d105e932b7c0cc40e592872f95fc", + "catalog_digest": "a47a88a9232f0a0452f502095bc8fd7d9703d105e932b7c0cc40e592872f95fc", "tools": [ { "name": "bash", @@ -9868,6 +9945,7 @@ } }, { + "read_only": true, "name": "read", "schema_digest": "f9ef88233ec21e9968187fd84526076c5853cb62d8397721b76ae8bd0a229f00", "semantics": 1, @@ -10039,6 +10117,7 @@ } }, { + "read_only": true, "name": "grep", "schema_digest": "0f7a077fe3aee4e28d4cdebb8093776db34692c342ef3b67c3b9e49fe7c31f19", "semantics": 1, @@ -10078,6 +10157,7 @@ } }, { + "read_only": true, "name": "glob", "schema_digest": "f0710f894a9c43ff7709e5f5cb63c37f7cda4e969840379f728a6d55f353a659", "semantics": 1, @@ -10108,6 +10188,7 @@ } }, { + "read_only": true, "name": "aft_search", "schema_digest": "c01cfa3965f768c100253bb0d59285149d4883f5fa46d7b511cc98e0a7efb70e", "semantics": 1, @@ -10157,6 +10238,7 @@ } }, { + "read_only": true, "name": "aft_outline", "schema_digest": "264536293f3baca10d5e6b695baf9a29f71ea74b7e4241ceaed26e3b46e165cf", "semantics": 1, @@ -10203,6 +10285,7 @@ } }, { + "read_only": true, "name": "aft_zoom", "schema_digest": "0c709b2d562766296a0e4601b4a16304488d2ffff6e8ac4ccfc4b68e1fe9be39", "semantics": 1, @@ -10329,6 +10412,7 @@ } }, { + "read_only": true, "name": "aft_callgraph", "schema_digest": "cc1143512feeca2585bd922ab9047a00ef2496807a1307dac19e9047ae4e86de", "semantics": 1, @@ -10401,6 +10485,7 @@ } }, { + "read_only": true, "name": "aft_conflicts", "schema_digest": "702d9af7c4449b1601b49d0b7d7573d150aa564430f9fc0c39e7af1dcea92d0c", "semantics": 1, @@ -10425,6 +10510,7 @@ } }, { + "read_only": true, "name": "ast_grep_search", "schema_digest": "96463c1682f4d87f5216797bb29cc474cd88690a8c9469f1824d9d4b9faa0b35", "semantics": 1, @@ -11001,8 +11087,8 @@ "hashline": true }, "reply": { - "generation": "9fcd4b3cc0353aae51825982bc424a785059cc1af219c410114d7a2e809f1417", - "catalog_digest": "9fcd4b3cc0353aae51825982bc424a785059cc1af219c410114d7a2e809f1417", + "generation": "f2c857219f222c7f358036bc1337a0d84272a108334f5ce929b9bf546a61fd14", + "catalog_digest": "f2c857219f222c7f358036bc1337a0d84272a108334f5ce929b9bf546a61fd14", "tools": [ { "name": "bash", @@ -11087,6 +11173,7 @@ } }, { + "read_only": true, "name": "read", "schema_digest": "f9ef88233ec21e9968187fd84526076c5853cb62d8397721b76ae8bd0a229f00", "semantics": 1, @@ -11204,6 +11291,7 @@ } }, { + "read_only": true, "name": "grep", "schema_digest": "0f7a077fe3aee4e28d4cdebb8093776db34692c342ef3b67c3b9e49fe7c31f19", "semantics": 1, @@ -11243,6 +11331,7 @@ } }, { + "read_only": true, "name": "glob", "schema_digest": "f0710f894a9c43ff7709e5f5cb63c37f7cda4e969840379f728a6d55f353a659", "semantics": 1, @@ -11273,6 +11362,7 @@ } }, { + "read_only": true, "name": "aft_search", "schema_digest": "c01cfa3965f768c100253bb0d59285149d4883f5fa46d7b511cc98e0a7efb70e", "semantics": 1, @@ -11322,6 +11412,7 @@ } }, { + "read_only": true, "name": "aft_outline", "schema_digest": "264536293f3baca10d5e6b695baf9a29f71ea74b7e4241ceaed26e3b46e165cf", "semantics": 1, @@ -11368,6 +11459,7 @@ } }, { + "read_only": true, "name": "aft_zoom", "schema_digest": "0c709b2d562766296a0e4601b4a16304488d2ffff6e8ac4ccfc4b68e1fe9be39", "semantics": 1, @@ -11494,6 +11586,7 @@ } }, { + "read_only": true, "name": "aft_callgraph", "schema_digest": "cc1143512feeca2585bd922ab9047a00ef2496807a1307dac19e9047ae4e86de", "semantics": 1, @@ -11566,6 +11659,7 @@ } }, { + "read_only": true, "name": "aft_conflicts", "schema_digest": "702d9af7c4449b1601b49d0b7d7573d150aa564430f9fc0c39e7af1dcea92d0c", "semantics": 1, @@ -11590,6 +11684,7 @@ } }, { + "read_only": true, "name": "ast_grep_search", "schema_digest": "96463c1682f4d87f5216797bb29cc474cd88690a8c9469f1824d9d4b9faa0b35", "semantics": 1, diff --git a/crates/aft/tests/fixtures/tool_provider_conformance.json b/crates/aft/tests/fixtures/tool_provider_conformance.json index fb9f6602fb..8eca668f76 100644 --- a/crates/aft/tests/fixtures/tool_provider_conformance.json +++ b/crates/aft/tests/fixtures/tool_provider_conformance.json @@ -2,9 +2,9 @@ "registry_artifacts": [ { "name": "cortexkit-role-tool-provider", - "version": "0.15.10", + "version": "0.15.12", "source": "registry+https://github.com/rust-lang/crates.io-index", - "checksum": "0f2e13ef1a5fad31eabb8153d428798b8ce7f8be4143cbb540730ba2317a679a", + "checksum": "22919ed36ffc8e253eb3bcc576a02eca9669cf58841f47544de4ee9f2a7c97e8", "dependency_kind": "normal", "release_tag": "cortexkit-role-tool-provider-v0.13.0" }, @@ -17,9 +17,9 @@ }, { "name": "cortexkit-role-tool-provider-conformance", - "version": "0.15.11", + "version": "0.15.13", "source": "registry+https://github.com/rust-lang/crates.io-index", - "checksum": "29dab37d9a5b3ab4109b77c00465b314114589fc861c3858ddb2912cf23f166d", + "checksum": "6b0cf924b4e30d8d14fade1b20df10a0ee86948c6efe4def40d3f2998fe112e8", "dependency_kind": "dev", "release_tag": "cortexkit-role-tool-provider-conformance-v0.13.1" }, @@ -136,6 +136,7 @@ "catalog_schemas_flat", "catalog_schemas_portable", "catalog_notice_templates", + "fork_calls_honour_marker", "catalog_reply_valid", "system_text_digests_match_text", "system_text_preflight_digest_stable", @@ -236,6 +237,7 @@ "catalog_schemas_flat", "catalog_schemas_portable", "catalog_notice_templates", + "fork_calls_honour_marker", "catalog_reply_valid", "system_text_digests_match_text", "system_text_preflight_digest_stable", @@ -337,6 +339,7 @@ "catalog_schemas_flat", "catalog_schemas_portable", "catalog_notice_templates", + "fork_calls_honour_marker", "catalog_reply_valid", "system_text_digests_match_text", "system_text_preflight_digest_stable", @@ -437,6 +440,7 @@ "catalog_schemas_flat", "catalog_schemas_portable", "catalog_notice_templates", + "fork_calls_honour_marker", "catalog_reply_valid", "system_text_digests_match_text", "system_text_preflight_digest_stable", @@ -538,6 +542,7 @@ "catalog_schemas_flat", "catalog_schemas_portable", "catalog_notice_templates", + "fork_calls_honour_marker", "catalog_reply_valid", "system_text_digests_match_text", "system_text_preflight_digest_stable", @@ -632,6 +637,7 @@ "catalog_schemas_flat", "catalog_schemas_portable", "catalog_notice_templates", + "fork_calls_honour_marker", "catalog_reply_valid", "system_text_digests_match_text", "system_text_preflight_digest_stable", diff --git a/crates/aft/tests/tool_provider_conformance.rs b/crates/aft/tests/tool_provider_conformance.rs index cb39e2f03a..50fb0f2bb4 100644 --- a/crates/aft/tests/tool_provider_conformance.rs +++ b/crates/aft/tests/tool_provider_conformance.rs @@ -3595,6 +3595,43 @@ impl ToolProviderSubject for Subject { ("status".into(), json!({})) } } + /// The result probes cover every tool AFT marks read-only; the runner + /// sends only those. One more read names a file outside the project, + /// which a route that can ask would ask about. + fn fork_calls(&self) -> Vec { + let mut probes = result_probes(); + probes.push(("read".into(), json!({"path": "../fork-outside.txt"}))); + probes + } + /// The project's files (each path with its length and content hash) and + /// the number of permission questions the stand-in has received. + async fn fork_observable_state(&self, handle: &Process) -> Result { + fn walk(dir: &Path, base: &Path, files: &mut BTreeMap) { + let Ok(entries) = std::fs::read_dir(dir) else { + return; + }; + for entry in entries.flatten() { + let path = entry.path(); + if path.is_dir() { + walk(&path, base, files); + } else if let Ok(bytes) = std::fs::read(&path) { + use std::hash::{Hash, Hasher}; + let mut hasher = std::collections::hash_map::DefaultHasher::new(); + bytes.hash(&mut hasher); + let relative = path.strip_prefix(base).unwrap_or(&path); + files.insert( + relative.display().to_string(), + format!("{}:{:x}", bytes.len(), hasher.finish()), + ); + } + } + } + let project = handle.root.join("project"); + let mut files = BTreeMap::new(); + walk(&project, &project, &mut files); + let questions = self.stand_in.asks.lock().unwrap().len(); + Ok(json!({"files": files, "questions": questions})) + } fn tool_result_v1_calls(&self) -> Vec { let tools = self.served_tools.lock().unwrap(); let tools = tools diff --git a/scripts/file-size-pins.json b/scripts/file-size-pins.json index bb73c1c48d..03534f8dba 100644 --- a/scripts/file-size-pins.json +++ b/scripts/file-size-pins.json @@ -12,11 +12,11 @@ "reason": "Split bridge integration tests by tool family pending; AFT crate split lane." }, "crates/aft/src/subc/mod.rs": { - "lines": 13377, + "lines": 13376, "reason": "Split daemon orchestration by area pending; AFT crate split lane." }, "crates/aft/src/context.rs": { - "lines": 12519, + "lines": 12517, "reason": "Split workspace context responsibilities pending; AFT crate split lane." }, "crates/aft/src/lsp/manager.rs": { diff --git a/test-vectors/aft-notice-templates-v1.1/README.md b/test-vectors/aft-notice-templates-v1.1/README.md new file mode 100644 index 0000000000..aa8e1e5a7a --- /dev/null +++ b/test-vectors/aft-notice-templates-v1.1/README.md @@ -0,0 +1,10 @@ +# AFT notice templates v1.1 + +The same opt-in `tool.catalog` replies and example `session.send` requests as +`aft-notice-templates-v1` (see its README for the fixed clock, call key and +delivery mode they use), except that every catalog now carries the +tool-provider 0.15.12 `read_only: true` mark on the tools AFT marks read-only. +The mark is always sent, so each catalog's `generation` and `catalog_digest` +change; the `*.sends.json` files are unchanged. v1 stays as published. +Regenerate with `cargo test -p agent-file-tools --lib regenerate_notice_template_vectors -- --ignored`; +`notice_template_vectors_match_samples` compares every byte. diff --git a/test-vectors/aft-notice-templates-v1.1/SHA256SUMS b/test-vectors/aft-notice-templates-v1.1/SHA256SUMS new file mode 100644 index 0000000000..4827a25faa --- /dev/null +++ b/test-vectors/aft-notice-templates-v1.1/SHA256SUMS @@ -0,0 +1,7 @@ +abe1d1b21e7d10c3ca8a43f2473c81b5453e30c0cf6b17ba3fe139209dabd43b README.md +ed2382a95264195e359c7881ff58d3e66e6f2eb0e425034beabf65d45d8e4d23 head.catalog.json +491eacc7123161f297a836485ed9615aa580a813ac9389e37b958899a583628c head.sends.json +d9d5b2bbef6e650222b7252428141f023f23b5487a1713b203c86cf04b51e0dd reader.catalog.json +ea5d386c9177b0e3997e7b38a65ee178f29ac63839bcb909becd21b9075a01e6 reader.sends.json +02f179e5d6e5e143c455620ab9f9a36587d7db4f88f947cef2f0427007ec7b52 worker.catalog.json +90ec6d07524eb05dab7aaa58fa8a500d2067e8e28d18677a1aa01cd792c0d32c worker.sends.json diff --git a/test-vectors/aft-notice-templates-v1.1/head.catalog.json b/test-vectors/aft-notice-templates-v1.1/head.catalog.json new file mode 100644 index 0000000000..f3f5185f8f --- /dev/null +++ b/test-vectors/aft-notice-templates-v1.1/head.catalog.json @@ -0,0 +1,1268 @@ +{ + "generation": "42b9517ae66d286a8307266b16140e59a8055b4673cd2647914386bebef7e279", + "catalog_digest": "42b9517ae66d286a8307266b16140e59a8055b4673cd2647914386bebef7e279", + "tools": [ + { + "name": "status", + "schema_digest": "99334726611ccf58a148b0814696bfa6fe08c1b2d027e946beccf5a74331c9aa", + "semantics": 1, + "modes": [ + "classic", + "codemode" + ], + "result_format": "tool-result/v1", + "capabilities": [], + "description": "Show AFT status, index health, cache usage, and runtime details", + "input_schema": { + "type": "object", + "properties": {}, + "additionalProperties": false + } + }, + { + "name": "bash", + "schema_digest": "da852fe71bf96fc7597ea7236d99a23f311dbd1d32f6ef026259c7140a70fc0a", + "semantics": 2, + "modes": [ + "classic", + "codemode" + ], + "result_ops": [ + "prepend", + "append" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "shell.exec/v1", + "call.yield/v1" + ], + "description": "Execute shell commands. Output is compressed by default; pass compressed: false for raw output. Piped commands run verbatim and show the pipeline's output; for AFT's test/build summary, run the runner without | head, | tail, or | grep. Pipeline-failure notes cover single top-level pipelines only; multi-statement commands (`a; b | c; d`) are not instrumented, so masked failures inside them still need explicit exit-code checks. Commands run in the foreground and return inline; wait: true blocks until a long command finishes instead of auto-promoting (it blocks up to bash.worker_wait_max_ms, 30 minutes by default, then reports the command is still running; watch again to keep waiting); Any new message detaches this wait. Set `bash.detach_on_user_message: false` to keep it blocking; even then, a message containing the literal `&detach` forces detachment, and the token is stripped before delivery and the rest of the message is preserved; a token-only message becomes `(requested background detach)`. Use it when you need the result before doing anything else; keep it off otherwise so auto-promote can remind you while you work. Use background: true yourself ONLY when you have other work to do while it runs, and any work that doesn't need this command's result counts; the task keeps running after the call returns, a completion reminder arrives when it exits, and bash_status reports its state and output. Use bash({wait:true}) instead when the result is needed before anything else. Do not change or delete files a background command uses until it finishes. A `nohup … &` launch still holds the call if the child keeps stdout/stderr; redirect both or use background:true. pty: true runs interactive programs (REPLs, TUIs), implies background, and is driven with bash_status({ outputMode: \"screen\" }) plus bash_write. Finished output expires after the task is 24 hours old and its completion has been delivered; under project-root restrictions, only the starting session can read output outside the project—copy cited lines into your report. `timeout` starts after spawn and kills the Unix process group (exit 124; Windows uses taskkill /T /F); processes that leave the group survive.\n\nDO NOT use bash for code search or code exploration. If you are about to run grep, rg, sed, awk, find, or cat through bash to locate or read code: STOP — use the grep tool, read, outline, or zoom instead. When a list is cut, the reply ends with `shown N of M () · narrow: `; absence of that line means the list is complete.", + "reply": { + "max_ms": 2040000 + }, + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "command": { + "description": "Shell command to execute. Supports pipes, redirection, and normal shell syntax.", + "type": "string" + }, + "timeout": { + "description": "Hard kill cap in milliseconds (positive integer). In the default foreground mode when wait is false, a command that exceeds the configured wait window is promoted to background and gets a completion reminder when it exits; wait:true disables promotion and remains inline until completion, timeout, or bash.worker_wait_max_ms. A background task with no timeout is killed after 30 minutes; pass a longer timeout for long jobs.", + "type": "integer", + "minimum": 1, + "maximum": 9007199254740991 + }, + "workdir": { + "description": "Working directory for command execution. Relative paths resolve through the bridge; defaults to the current tool context/project root when omitted.", + "type": "string" + }, + "description": { + "description": "Short 5-10 word human-readable summary shown in OpenCode UI metadata instead of raw shell syntax.", + "type": "string" + }, + "wait": { + "description": "When true, run in the foreground without auto-promoting and wait until the command finishes or reaches its timeout (at most bash.worker_wait_max_ms, 30 minutes by default; the command then keeps running in the background and the reply says how to keep waiting); Any new message detaches this wait. Set `bash.detach_on_user_message: false` to keep it blocking; even then, a message containing the literal `&detach` forces detachment, and the token is stripped before delivery and the rest of the message is preserved; a token-only message becomes `(requested background detach)`. Use only when you know the result is required before doing anything else.", + "type": "boolean" + }, + "sandbox": { + "description": "Request one-command approval to run unsandboxed on the host; use only when native sandboxing blocks required work, and note that it is a no-op when sandboxing is disabled.", + "type": "string", + "const": "host" + }, + "background": { + "description": "When true, spawn the command in the background and return a taskId for bash_status/bash_kill instead of waiting for completion. Defaults to false. A background task with no timeout is killed after 30 minutes; pass a longer timeout for long jobs.", + "type": "boolean" + }, + "compressed": { + "description": "When true or omitted, return compressed output with noisy terminal control sequences reduced. Set to false for raw output.", + "type": "boolean" + }, + "pty": { + "description": "When true, spawn the command in a real PTY for interactive programs (python/node/bash REPLs, vim). Implies background: true automatically. Inspect with bash_status({ taskId, outputMode: \"screen\" }) and drive interactively with bash_write — its input accepts either a string OR an array like [ \"iHello\", { key: \"esc\" }, \":wq\", { key: \"enter\" } ] for atomic text+key sequences.", + "type": "boolean" + }, + "ptyRows": { + "description": "PTY terminal height in rows — ignored when pty is false. Defaults to 24 when pty: true. Minimum 1, maximum 60.", + "type": "integer", + "minimum": 1, + "maximum": 60 + }, + "ptyCols": { + "description": "PTY terminal width in columns — ignored when pty is false. Defaults to 80 when pty: true. Minimum 1, maximum 140.", + "type": "integer", + "minimum": 1, + "maximum": 140 + } + }, + "required": [ + "command" + ] + } + }, + { + "read_only": true, + "name": "read", + "schema_digest": "f9ef88233ec21e9968187fd84526076c5853cb62d8397721b76ae8bd0a229f00", + "semantics": 1, + "modes": [ + "classic", + "codemode", + "flow" + ], + "result_ops": [ + "prepend", + "append" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "code.read/v1" + ], + "description": "Read file contents or list directory entries.\n\nUse either startLine/endLine OR offset/limit to read a section of a file or sorted directory listing.\n\nBehavior:\n- Returns line-numbered content (e.g., \"1: const x = 1\")\n- Lines longer than 2000 characters are truncated\n- Output capped at 50KB\n- Binary files are auto-detected and return a size-only message\n- Supported images (PNG, JPEG, GIF, WebP) and PDFs are returned as tool attachments; range arguments are ignored for media\n- Directories return sorted entries with trailing / for subdirectories; offset is 1-based, limit defaults to and is capped at 1000 entries. Enumeration stops at 10,000 entries; partial listings carry a shown/total trailer.\n\nExamples:\n Read full file: { \"path\": \"src/app.ts\" }\n Read lines 50-100: { \"path\": \"src/app.ts\", \"startLine\": 50, \"endLine\": 100 }\n Read 30 lines from line 200: { \"path\": \"src/app.ts\", \"offset\": 200, \"limit\": 30 }\n List directory: { \"path\": \"src/\" }\n", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "path": { + "description": "Path to file or directory (absolute or relative to project root)", + "type": "string" + }, + "startLine": { + "description": "1-based line or directory entry to start reading from", + "type": "integer", + "minimum": 1, + "maximum": 9007199254740991 + }, + "endLine": { + "description": "1-based line or directory entry to stop reading at (inclusive)", + "type": "integer", + "minimum": 1, + "maximum": 9007199254740991 + }, + "limit": { + "description": "Max lines (default: 2000) or directory entries (default and cap: 1000) to return", + "type": "integer", + "minimum": 1, + "maximum": 9007199254740991 + }, + "offset": { + "description": "1-based line or directory entry to start reading from (use with limit). Ignored if startLine is provided", + "type": "integer", + "minimum": 1, + "maximum": 9007199254740991 + } + }, + "required": [ + "path" + ] + } + }, + { + "name": "write", + "schema_digest": "e4b3deed1a39fc2a5b990b319b17e1f19c84c891a770c219d97d9cdefe6181cf", + "semantics": 1, + "modes": [ + "classic", + "codemode" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "code.edit/v1" + ], + "description": "Write content to a file, creating it and parent directories automatically. Use `path` for the file location. Existing files are backed up before overwriting (undo via safety). Auto-formats when the project has a formatter configured. Use it to create files or replace whole contents; for partial edits, use the `edit` tool. Write very large new files in parts: a single call can exceed the model's output limit and is then aborted with empty arguments.", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "path": { + "description": "Path to the file to write (absolute or relative to project root)", + "type": "string" + }, + "content": { + "description": "The full content to write to the file; for issue://N / pr://N, the comment body to post", + "type": "string" + } + }, + "required": [ + "path", + "content" + ] + } + }, + { + "name": "edit", + "schema_digest": "20dfe0eb13e87c68a0d54412e2e9605a3c1ce7935d36acf1c6df8e8660609ef8", + "semantics": 1, + "modes": [ + "classic", + "codemode" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "code.edit/v1" + ], + "description": "Edit a file by finding and replacing text, or by targeting named symbols. To write or overwrite a whole file, use the `write` tool — `edit` requires an explicit edit mode and will not silently overwrite a file from `content` alone.\n\n**Modes** (determined by which parameters you provide):\n\nProvide exactly one mode per call: appendContent, edits[], or symbol plus content. `symbol` and `content` are only meaningful together; a call carrying one without the other is incomplete. Mixing modes or providing none is rejected — there is no implicit \"write\" fallback. To edit multiple files, make parallel `edit` calls in one response.\n\n1. **Append** — pass `path` + `appendContent`\n Appends text to the end of a file, creating it if it does not exist.\n Example: `{ \"path\": \"notes.txt\", \"appendContent\": \"new line\\n\" }`\n\n2. **Batch edits** — pass `path` + `edits` array\n Multiple edits in one file atomically. Each edit is either:\n - `{ \"oldString\": \"old\", \"newString\": \"new\" }` — find/replace\n - `{ \"oldString\": \"old\", \"newString\": \"new\", \"replaceAll\": true }` — replace every match\n - `{ \"startLine\": 5, \"endLine\": 7, \"content\": \"new lines\" }` — replace line range (1-based, both inclusive)\n Set content to empty string to delete lines.\n\n3. **Symbol replace** — pass `path` + `symbol` + `content`\n Replaces an entire named symbol (function, class, type).\n Includes decorators, attributes, and doc comments in the replacement range.\n Example: `{ \"path\": \"src/app.ts\", \"symbol\": \"handleRequest\", \"content\": \"function handleRequest() { ... }\" }`\n\n4. **Find and replace** — put `oldString` and optional `newString` in an item of `edits[]`\n Finds the exact text in `oldString` and replaces it with `newString`.\n Supports fuzzy matching (handles whitespace differences automatically).\n If multiple matches exist, specify `occurrence` or set `replaceAll: true` in that item.\n\n5. **Replace all occurrences** — add `replaceAll: true` to a find/replace item.\n\n6. **Select specific occurrence** — add `occurrence: N` to a find/replace item (1-based).\n When multiple matches exist, select the Nth one (1 = first, 2 = second, etc.).\n\n**Behavior:**\n- Backs up files before editing (recoverable via safety undo)\n- Auto-formats using project formatter if configured\n- Tree-sitter syntax validation on all edits\n- Symbol replace includes decorators, attributes, and doc comments in range\n- Response is a compact server-rendered summary; before/after diff details are attached as UI metadata when available.", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "path": { + "description": "Path to the file to edit (absolute or relative to project root)", + "type": "string" + }, + "symbol": { + "description": "Named symbol to replace; only meaningful together with `content`. A call carrying one without the other is incomplete.", + "type": "string" + }, + "content": { + "description": "Replacement content for symbol mode; only meaningful together with `symbol`. A call carrying one without the other is incomplete. For whole-file writes, use the `write` tool.", + "type": "string" + }, + "appendContent": { + "description": "Text to append to the end of path; creates the file if needed", + "type": "string" + }, + "edits": { + "description": "Batch edits — non-empty array of { oldString, newString }, { oldString, newString, replaceAll: true }, or { startLine, endLine, content } objects", + "minItems": 1, + "type": "array", + "items": { + "type": "object", + "properties": { + "oldString": { + "description": "Text to find for a batch find/replace edit", + "type": "string" + }, + "newString": { + "description": "Replacement text for a batch find/replace edit", + "type": "string" + }, + "replaceAll": { + "description": "Replace every occurrence for this batch item", + "type": "boolean" + }, + "occurrence": { + "description": "1-based occurrence for this batch item (1 = first match)", + "type": "integer", + "minimum": 1, + "maximum": 9007199254740991 + }, + "startLine": { + "description": "1-based start line for a batch line-range edit", + "type": "integer", + "minimum": 1, + "maximum": 9007199254740991 + }, + "endLine": { + "description": "1-based end line for a batch line-range edit", + "type": "integer", + "minimum": 1, + "maximum": 9007199254740991 + }, + "content": { + "description": "Replacement text for a batch line-range edit", + "type": "string" + } + } + } + } + }, + "required": [ + "path" + ] + } + }, + { + "name": "apply_patch", + "schema_digest": "fa62c9797e5d14436714f5630d15815d2adc1185023a3dcba3f3ed20fc9f0548", + "semantics": 1, + "modes": [ + "classic", + "codemode" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "code.edit/v1" + ], + "description": "Use the `apply_patch` tool to edit files. Your patch language is a stripped‑down, file‑oriented diff format designed to be easy to parse and safe to apply. You can think of it as a high‑level envelope:\n\n*** Begin Patch\n[ one or more file sections ]\n*** End Patch\n\nWithin that envelope, you get a sequence of file operations.\nYou MUST include a header to specify the action you are taking.\nEach operation starts with one of three headers:\n\n*** Add File: - create a new file. Every following line is a + line (the initial contents).\n*** Delete File: - remove an existing file. Nothing follows.\n*** Update File: - patch an existing file in place (optionally with a rename).\n*** Move to: - after update file header, renames the file.\n\n\nExample patch:\n\n```\n*** Begin Patch\n*** Add File: hello.txt\n+Hello world\n*** Update File: src/app.py\n*** Move to: src/main.py\n@@ def greet():\n-print(\"Hi\")\n+print(\"Hello, world!\")\n*** Delete File: obsolete.txt\n*** End Patch\n```\n\n**Behavior:**\n- Per-file commit: each file's edits apply independently. If a later file fails, earlier successful changes are kept. Use `safety` undo if you need to revert the applied changes.\n- Files are backed up before modification\n- Parent directories are created automatically for new files\n- Fuzzy matching for context anchors (handles whitespace and Unicode differences)\n\n**It is important to remember:**\n\n- You must include a header with your intended action (Add/Delete/Update)\n- You must prefix new lines with `+` even when creating a new file\n\nEdits return as soon as the write completes unless `lsp.diagnostics_on_edit` requests legacy sync-wait behavior. Call `inspect` afterward to check diagnostics across a batch of edits.", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "patchText": { + "description": "The full patch text including Begin/End markers", + "type": "string" + } + }, + "required": [ + "patchText" + ] + } + }, + { + "read_only": true, + "name": "grep", + "schema_digest": "0f7a077fe3aee4e28d4cdebb8093776db34692c342ef3b67c3b9e49fe7c31f19", + "semantics": 1, + "modes": [ + "classic", + "codemode", + "flow" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "code.search/v1" + ], + "description": "Search file contents using regular expressions. Returns matching lines with file paths and line numbers (no surrounding context lines — use `read` for that). Always case-sensitive. Lockfiles, generated and minified files, logs and command output, and JSON data files are counted, not printed, unless `path` or `include` names them; the reply lists them with the value to pass. Long lines are shown as a window around the match. A large result starts with matching lines per file and a 40-line first page; pass `offset` to page. When a list is cut, the reply ends with `shown N of M () · narrow: `; absence of that line means the list is complete.", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "pattern": { + "type": "string" + }, + "include": { + "type": "string" + }, + "path": { + "type": "string" + }, + "offset": { + "description": "Rows of shown results to skip; follow the next offset the reply names.", + "type": "integer", + "minimum": 0, + "maximum": 100000 + } + }, + "required": [ + "pattern" + ] + } + }, + { + "read_only": true, + "name": "glob", + "schema_digest": "f0710f894a9c43ff7709e5f5cb63c37f7cda4e969840379f728a6d55f353a659", + "semantics": 1, + "modes": [ + "classic", + "codemode", + "flow" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "code.search/v1" + ], + "description": "Find files matching a glob pattern. Returns matching file paths sorted by modification time. When a list is cut, the reply ends with `shown N of M () · narrow: `; absence of that line means the list is complete.", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "pattern": { + "type": "string" + }, + "path": { + "type": "string" + } + }, + "required": [ + "pattern" + ] + } + }, + { + "read_only": true, + "name": "search", + "schema_digest": "c01cfa3965f768c100253bb0d59285149d4883f5fa46d7b511cc98e0a7efb70e", + "semantics": 1, + "modes": [ + "classic", + "codemode", + "flow" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "code.search/v1" + ], + "description": "Search code with one tool: concepts, identifiers, error strings, regex, literals, and filenames are auto-routed to the right engine and returned ranked. For conceptual 'how does X work' queries, phrase a full natural-language sentence — the semantic lane is NL-aware and matches intent against docstrings and comments ('how does the ORM build and execute a query', 'where is rate limiting handled'), not just keywords. Exact names, strings, and regex stay terse ('^export', 'Cargo.lock').\n\nWhen you know a name or string that must appear, put it in `pattern` (a regex, grep syntax, case-sensitive) and keep the question in `query`: both are ranked together, and the reply's first line says how many files the pattern matched and where it is defined. Example: query 'how is the config file loaded', pattern 'load_config|ConfigLoader'. `pattern` alone ranks the files it matches, definitions first.\n\nUse `offset` to continue a ranked result list from a zero-based position.\n\nWhen a list is cut, the reply ends with `shown N of M () · narrow: `; absence of that line means the list is complete.", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "query": { + "description": "Concept, regex, literal text, filename, or capability to find. Examples: 'fuzzy match with whitespace tolerance', '^export', 'Cargo.lock'. Optional when `pattern` is given.", + "type": "string" + }, + "pattern": { + "description": "Regex (grep syntax, case-sensitive) for names or text that must appear, e.g. 'load_config|ConfigLoader'. Ranked with `query` when both are given.", + "type": "string" + }, + "topK": { + "description": "Number of results (default: 10, max: 50)", + "type": "integer", + "minimum": 1, + "maximum": 50 + }, + "offset": { + "description": "Zero-based result offset (default: 0, max: 100000).", + "type": "integer", + "minimum": 0, + "maximum": 100000 + }, + "includeTests": { + "description": "Include test files (*.test.*, *_test.rs, __tests__/, …) plus test-support, fixture, mock, snapshot, and corpus files. Defaults to false.", + "type": "boolean" + }, + "path": { + "description": "Only set this to search a different project or plain folder (absolute or ~ path). Omit it for the current configured workspace, including non-Git workspace roots; this is not a subdirectory filter. Unindexed external folders use a bounded lexical fallback; filesystem roots, home and its ancestors are refused.", + "type": "string" + } + } + } + }, + { + "read_only": true, + "name": "outline", + "schema_digest": "264536293f3baca10d5e6b695baf9a29f71ea74b7e4241ceaed26e3b46e165cf", + "semantics": 1, + "modes": [ + "classic", + "codemode", + "flow" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "code.outline/v1" + ], + "description": "Structural outline of source code, documentation files, or remote URLs. For code, returns symbols (functions, classes, types) with line ranges. For Markdown and HTML, returns heading hierarchy. Use this to explore structure before reading specific sections with zoom. With `files: true`, the outline is breadth-first with directory rollups; drill in by outlining a subdirectory. Rows show language, symbol count, and line count.\n\nFor understanding a specific feature, prefer search + zoom on named symbols; use outline on a whole directory only for high-level structure mapping. zoom with `callgraph:true` gives one-level forward calls-out; use callgraph only for reverse callers or multi-level traces.\n\nPass a single `target`:\n • file path → outline that file (with signatures)\n • directory path → outline source files under it\n • URL (http:// or https://) → fetch and outline a remote HTML/Markdown document\n • array of paths → outline multiple files in one call; with files:true, every path must be a directory\n\nWhen a list is cut, the reply ends with `shown N of M () · narrow: `; absence of that line means the list is complete.", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "target": { + "description": "What to outline: a file path, directory path, URL, or array of paths. The mode is auto-detected: URLs by `http://`/`https://` prefix, directories by stat, arrays as multi-file.", + "anyOf": [ + { + "type": "string" + }, + { + "type": "array", + "items": { + "type": "string" + } + } + ] + }, + "files": { + "description": "Directory-only mode: when true, target must be a directory or array of directories and the result is a breadth-first file tree with directory rollups plus language, symbol, and line counts.", + "type": "boolean" + }, + "includeTests": { + "description": "Directory outline only: include test files. Defaults to false; tests are hidden.", + "type": "boolean" + } + }, + "required": [ + "target" + ] + } + }, + { + "read_only": true, + "name": "zoom", + "schema_digest": "0c709b2d562766296a0e4601b4a16304488d2ffff6e8ac4ccfc4b68e1fe9be39", + "semantics": 1, + "modes": [ + "classic", + "codemode", + "flow" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "code.outline/v1" + ], + "description": "Inspect code symbols or documentation sections. Pass lookups in `batch: [{ target, symbols }]`; a single lookup is a one-entry batch. Mix files and URLs in one batch, for example `batch: [{ target: \"src/app.ts\", symbols: \"run\" }, { target: \"https://example.com/docs\", symbols: \"Overview\" }]`. Each target is auto-detected as a file path or an HTTP/HTTPS URL. `symbols` is a string or string array. Markdown and HTML lookups return the section under the heading. Top-level `contextLines` and `callgraph` apply to every entry; callgraph adds calls-out and called-by annotations. Each failed lookup reports its own error line.", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "batch": { + "description": "One or more lookups; entries may mix file paths and URLs", + "minItems": 1, + "type": "array", + "items": { + "type": "object", + "properties": { + "target": { + "description": "File path (absolute or project-relative) or HTTP/HTTPS URL, auto-detected; issue://N or pr://N when GitHub reads are enabled", + "type": "string" + }, + "symbols": { + "description": "Symbol name for code or heading text for Markdown/HTML; a string or array of strings", + "anyOf": [ + { + "type": "string" + }, + { + "type": "array", + "items": { + "type": "string" + } + } + ] + } + }, + "required": [ + "target", + "symbols" + ] + } + }, + "contextLines": { + "description": "Lines of context before/after each symbol (default: 3)", + "type": "integer", + "minimum": 1, + "maximum": 9007199254740991 + }, + "callgraph": { + "description": "Include call-graph annotations for every entry (default: false)", + "type": "boolean" + } + }, + "required": [ + "batch" + ] + } + }, + { + "name": "inspect", + "schema_digest": "4e189e7662dd08cec4e8696bc215b3742a0ca5a5dd037de744f523c3707596aa", + "semantics": 1, + "modes": [ + "classic", + "codemode" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "code.diagnostics/v1" + ], + "description": "Codebase health inspection that waits for current analysis. FRESH means the reported analysis is current. PARTIAL means some diagnostics are unknown; the header names the analyzer, reason, and retry guidance. INTERRUPTED means the request stopped without a fresh snapshot; retry inspect. PHASE-FAILED means inspection could not finish; address the reported reason and retry, or narrow the scope. `sections` selects drill-down detail. Scoped requests collect diagnostics when sections is omitted or includes 'diagnostics' or 'all'; sections that leave diagnostics out skip diagnostics work. Unscoped requests keep warm diagnostics. Categories switched off in `inspect.categories` are not computed or refreshed, render as off, and never make the header PARTIAL.\n\nUse `scope=` to narrow all findings, counts, and examples to those paths. Cross-boundary duplicates are labeled as groups touching the scope. Scope also limits Rust analyzer startup to the Cargo workspaces owning those paths when diagnostics are requested. Files without an authoritative diagnostic report remain named gaps (complete: false), not a clean result.\n\nUse when: starting work on unfamiliar code, after multi-edit batches to check diagnostics, before a refactor, before review, or to verify cleanup completeness.\n\nTreat `dead_code` as a hint, not proof: reachability is call-based, so symbols reached only via method dispatch or referenced only in type position may be false positives — verify before deleting.\n\nWhen a list is cut, the reply ends with `shown N of M () · narrow: `; absence of that line means the list is complete.", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "sections": { + "description": "Categories to include in detailed drill-down (e.g. 'todos' or ['todos', 'dead_code', 'cycles']). Use 'all' for every active category. Omit for summary-only mode. With scope, listing sections without 'diagnostics' (or 'all') skips diagnostics work; omitting sections keeps diagnostics. Other categories are verified regardless of sections.", + "anyOf": [ + { + "type": "string" + }, + { + "type": "array", + "items": { + "type": "string" + } + } + ] + }, + "scope": { + "description": "Restrict returned results to paths under this scope (one path, or an array of paths — not a space-separated list; file or directory; absolute or relative to project root). `scope=` narrows results. Scoped requests collect diagnostics for the scoped files and report coverage gaps, unless sections lists other categories and leaves out 'diagnostics'.", + "anyOf": [ + { + "type": "string" + }, + { + "type": "array", + "items": { + "type": "string" + } + } + ] + }, + "offset": { + "description": "Rows to skip independently in each drill-down list. Default 0; follow next_offset in each list envelope.", + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + }, + "topK": { + "description": "Max drill-down items per category. Default 20, max 100.", + "type": "integer", + "exclusiveMinimum": 0, + "maximum": 100 + } + } + } + }, + { + "read_only": true, + "name": "callgraph", + "schema_digest": "cc1143512feeca2585bd922ab9047a00ef2496807a1307dac19e9047ae4e86de", + "semantics": 1, + "modes": [ + "classic", + "codemode", + "flow" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "code.callgraph/v1" + ], + "description": "Answer code-relationship questions from a real call graph — instead of grep + read chains. Reach for this whenever the question is about how symbols connect: who calls X, what X calls, what breaks if X changes, how execution reaches X, or how a value flows.\n\nUse zoom with `callgraph:true` for one-level forward calls-out while reading source. Use callgraph only for reverse callers or multi-level traces so you do not double-fetch the same relationships.\n\nOps:\n- 'callers': Find all call sites of a symbol. Use before renaming or changing a function's signature.\n- 'impact': What breaks if a symbol changes — affected callers with signatures and entry-point status (blast radius). Use before a risky edit.\n- 'call_tree': What a function calls (forward traversal). Use to understand a function's dependencies before modifying it.\n- 'trace_to': How execution reaches a function: each path of callers runs back to a root, labelled main, test, attribute, public API, or no caller found. Use to understand context around deeply-nested code.\n- 'trace_to_symbol': Shortest call path from one symbol to another. Requires 'toSymbol'. If multiple targets match, the error returns candidate files; retry with 'toPath' to disambiguate.\n- 'trace_data': Follow a value through variable assignments and function parameters across files. Requires 'symbol' (scope to trace from) and 'expression'.\n\nAll ops require both 'path' and 'symbol'. 'expression' is additionally required for trace_data; 'toSymbol' for trace_to_symbol.\n\nMarkers: ~ = edge resolved by name only (may point at the wrong same-named symbol); [unresolved] = callee not resolved to a definition, so the location shown is the call site. Unmarked edges are resolved exactly. By default, unresolved external/stdlib leaf calls in call_tree are collapsed into one summary per parent; pass includeUnresolved=true to show every unresolved edge individually.\n\nWhen a list is cut, the reply ends with `shown N of M () · narrow: `; absence of that line means the list is complete.\n", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "op": { + "description": "Navigation operation", + "type": "string", + "enum": [ + "call_tree", + "callers", + "trace_to", + "trace_to_symbol", + "impact", + "trace_data" + ] + }, + "path": { + "description": "Path to the source file containing the symbol (absolute or relative to project root)", + "type": "string" + }, + "symbol": { + "description": "Name of the symbol to analyze", + "type": "string" + }, + "depth": { + "description": "Max traversal depth (default: call_tree=5, callers=1, trace_to=10, trace_to_symbol=10 capped at 16, impact=5, trace_data=5)", + "type": "integer", + "minimum": 1, + "maximum": 9007199254740991 + }, + "expression": { + "description": "Expression to track through data flow (required for trace_data op)", + "type": "string" + }, + "toSymbol": { + "description": "Target symbol name for trace_to_symbol; the returned path ends at this symbol", + "type": "string" + }, + "toPath": { + "description": "Optional target file for trace_to_symbol; required when toSymbol exists in multiple files", + "type": "string" + }, + "includeTests": { + "description": "Include test files in callers/paths. Defaults to false; tests are hidden.", + "type": "boolean" + }, + "includeUnresolved": { + "description": "Show every unresolved external/stdlib call individually. Defaults to false; unresolved leaf calls are collapsed into one summary per parent.", + "type": "boolean" + } + }, + "required": [ + "op", + "path", + "symbol" + ] + } + }, + { + "read_only": true, + "name": "conflicts", + "schema_digest": "702d9af7c4449b1601b49d0b7d7573d150aa564430f9fc0c39e7af1dcea92d0c", + "semantics": 1, + "modes": [ + "classic", + "codemode" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "aft:git.conflicts/v1" + ], + "description": "Show all git merge conflicts across the repository — returns line-numbered conflict regions with context for every conflicted file in a single call. Conflicts are discovered from the git repository's top level. By default it inspects the session's project repository; pass `path` to inspect a different repository or git worktree (e.g. where a rebase/merge is running).", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "path": { + "description": "Optional path inside the git repository or worktree to inspect (absolute or relative to project root). Conflicts are discovered from that repository's top level. Defaults to the session project root.", + "type": "string" + } + } + } + }, + { + "read_only": true, + "name": "ast_search", + "schema_digest": "96463c1682f4d87f5216797bb29cc474cd88690a8c9469f1824d9d4b9faa0b35", + "semantics": 1, + "modes": [ + "classic", + "codemode" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "aft:code.ast_grep/v1" + ], + "description": "Search code patterns across filesystem using AST-aware matching. Supports 11 languages.\n\nUse meta-variables: $VAR matches a single AST node, $$$ matches multiple nodes (variadic).\nIMPORTANT: Patterns must be complete AST nodes (valid code fragments).\nFor functions, include params and body: 'export async function $NAME($$$) { $$$ }' not just 'export async function $NAME'.\n\nExamples: pattern='console.log($MSG)' lang='typescript', pattern='async function $NAME($$$) { $$$ }' lang='javascript', pattern='def $FUNC($$$): $$$' lang='python', pattern='Writeln($MSG);' lang='pascal', pattern='$X <- $Y' lang='r', pattern='[obj foo:$ARG]' lang='objc'", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "pattern": { + "description": "AST pattern with meta-variables ($VAR, $$$). Must be complete AST node.", + "type": "string" + }, + "lang": { + "description": "Target language", + "type": "string", + "enum": [ + "typescript", + "tsx", + "javascript", + "python", + "rust", + "go", + "cuda", + "metal", + "pascal", + "r", + "objc" + ] + }, + "paths": { + "description": "Paths to search (default: ['.'])", + "type": "array", + "items": { + "type": "string" + } + }, + "globs": { + "description": "Include/exclude globs (prefix ! to exclude)", + "type": "array", + "items": { + "type": "string" + } + }, + "contextLines": { + "description": "Number of context lines to show around each match", + "type": "integer", + "minimum": 1, + "maximum": 9007199254740991 + } + }, + "required": [ + "pattern", + "lang" + ] + } + }, + { + "name": "ast_replace", + "schema_digest": "86703537e883e53529c1045ee962ec1b062401108112606deffb16ff847892c9", + "semantics": 1, + "modes": [ + "classic", + "codemode" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "aft:code.ast_grep/v1" + ], + "description": "Replace code patterns across filesystem with AST-aware rewriting. Applies changes by default — set dryRun=true to preview.\n\nUse meta-variables in the rewrite pattern to preserve matched content from the pattern.\nIMPORTANT: Patterns must be complete AST nodes (valid code fragments).\n\nExample: pattern='console.log($MSG)' rewrite='logger.info($MSG)' lang='typescript' — replaces all console.log calls with logger.info across TypeScript files.\n\n**Warning: This tool modifies files directly.** Use dryRun=true to preview (shows per-file unified diff, capped at 8KB). Consider creating a safety checkpoint before bulk replacements.", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "pattern": { + "description": "AST pattern with meta-variables ($VAR, $$$). Must be complete AST node.", + "type": "string" + }, + "rewrite": { + "description": "Replacement pattern (can use $VAR from pattern)", + "type": "string" + }, + "lang": { + "description": "Target language", + "type": "string", + "enum": [ + "typescript", + "tsx", + "javascript", + "python", + "rust", + "go", + "cuda", + "metal", + "pascal", + "r", + "objc" + ] + }, + "paths": { + "description": "Paths to search (default: ['.'])", + "type": "array", + "items": { + "type": "string" + } + }, + "globs": { + "description": "Include/exclude globs (prefix ! to exclude)", + "type": "array", + "items": { + "type": "string" + } + }, + "dryRun": { + "description": "Preview changes without applying (default: false)", + "type": "boolean" + } + }, + "required": [ + "pattern", + "rewrite", + "lang" + ] + } + }, + { + "name": "delete", + "schema_digest": "07bc6db89f72b9f24d4386fe7f68607d66aaddb420215fcc2ed6d57ec478fc6f", + "semantics": 1, + "modes": [ + "classic", + "codemode" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "code.files/v1" + ], + "description": "Delete one or more files (or directories).\n\nEach file is backed up before deletion — use safety undo to recover any of them. A recursive delete backs up the whole tree: directories (empty ones too, with their permissions), file contents, hard links (relinked by undo) and symlinks (the link itself, never its target; restored exactly, even when dangling). Sockets are deleted but undo does not restore them, and a file hard-linked to paths outside the tree comes back as an independent copy; both are reported as warnings. Refused before anything is deleted: mount points of another filesystem, named pipes, device nodes, and symlinks undo cannot recreate exactly (non-UTF-8 target, or on Windows). Paths under the system temp directory are never backed up, so only mount points are refused there. The deleted file's contents stay in the undo store until its retention expires. A recursive delete whose backup would record more than 2,000 entries (files, directories and links) or copy 100 MiB in one call is refused before anything is deleted; delete such a tree in smaller pieces, or use bash `rm -rf` when no undo is needed. Directory deletion requires recursive: true. Without it, passing a directory returns an error.\n\nPartial success is allowed: deletable files are deleted; failed ones are reported in `skipped_files` with `complete: false`.", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "files": { + "description": "Paths to delete (one or more). May include directories when recursive=true.", + "minItems": 1, + "type": "array", + "items": { + "type": "string" + } + }, + "recursive": { + "description": "Required to delete a directory and its contents. Defaults to false; passing a directory without this returns an error.", + "type": "boolean" + } + }, + "required": [ + "files" + ] + } + }, + { + "name": "move", + "schema_digest": "f48d7c918c2557edb16221599142aee3d8fb52c2564866cdc37d4591ee5c1dad", + "semantics": 1, + "modes": [ + "classic", + "codemode" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "code.files/v1" + ], + "description": "Move or rename a file. Creates an undo backup before moving. Creates parent directories for destination automatically\nNote: This moves/renames whole files at the OS level; it does not relocate an individual symbol or rewrite imports.", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "path": { + "description": "Source file path to move (absolute or relative to project root)", + "type": "string" + }, + "destination": { + "description": "Destination file path (absolute or relative to project root)", + "type": "string" + } + }, + "required": [ + "path", + "destination" + ] + } + }, + { + "name": "import", + "schema_digest": "b52e0484b4abdaeb843b9738de9fd6927e229ca0337cacb87fb1e2cdcf24cbf4", + "semantics": 1, + "modes": [ + "classic", + "codemode" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "aft:code.imports/v1" + ], + "description": "Language-aware import management. Supports TS, JS, TSX, Python, Rust, Go, Solidity, Java, C#, PHP, Kotlin, Scala, Swift, Ruby, Lua, C, C++, Perl, and Vue.\n\nOps:\n- 'add': Add an import. Auto-detects group (stdlib/external/internal), deduplicates. Requires 'module'. Optional 'names', 'defaultImport', 'typeOnly'.\n- 'remove': Remove an import or a specific named import. Requires 'module'. Provide 'removeName' to remove a single named import; omit to remove the entire import.\n- 'organize': Re-sort and re-group all imports by language convention, deduplicate. Requires only 'path'. Use safety checkpoint/undo for recovery before broad cleanup.", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "op": { + "description": "Import operation", + "type": "string", + "enum": [ + "add", + "remove", + "organize" + ] + }, + "path": { + "description": "Path to the file (absolute or relative to project root)", + "type": "string" + }, + "module": { + "description": "Module path (required for add, remove — e.g. 'react', './utils', 'std::fmt')", + "type": "string" + }, + "names": { + "description": "Named imports to add. Each entry uses the language's native named-import text, including per-name aliasing where the language uses `as` (e.g. ['useState', 'debounce as db'], Solidity ['ERC20', 'IERC20 as IToken']).", + "type": "array", + "items": { + "type": "string" + } + }, + "defaultImport": { + "description": "Default import name, ES only (e.g. 'React')", + "type": "string" + }, + "namespace": { + "description": "Namespace binding: `import * as ns from 'mod'` (ES), `import * as N from \"./X.sol\"` (Solidity).", + "type": "string" + }, + "alias": { + "description": "Whole-module alias. Solidity: `import \"./X.sol\" as X` (module=path, alias=X).", + "type": "string" + }, + "modifiers": { + "description": "Statement-level modifier tokens, language-validated: Java/C# 'static'; C# 'global'/'unsafe'; Java/Kotlin/Scala 'wildcard'; Swift '@testable'. Unsupported tokens for the file's language return a clear error.", + "type": "array", + "items": { + "type": "string" + } + }, + "importKind": { + "description": "Symbol-kind-specific import: PHP 'function'/'const'; Swift 'struct'/'class'/'enum'/'protocol'/'func'; Scala 'given'.", + "type": "string" + }, + "typeOnly": { + "description": "Type-only import (TS only, default: false)", + "type": "boolean" + }, + "removeName": { + "description": "Named import to remove for 'remove' op; omit to remove entire import", + "type": "string" + }, + "validate": { + "description": "Validation level: 'syntax' (default) or 'full'. Syntax = tree-sitter parse check only. Full = also runs LSP type-checking (slower, catches more errors)", + "type": "string", + "enum": [ + "syntax", + "full" + ] + } + }, + "required": [ + "op", + "path" + ] + } + }, + { + "name": "safety", + "schema_digest": "15decddce4704d6bee2980603562727f50089c5abeb1f39a40aed33ce67bff54", + "semantics": 1, + "modes": [ + "classic", + "codemode" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "aft:safety/v1" + ], + "description": "File safety and recovery operations.\n\nPer-file undo stack is capped at 20 entries (oldest evicted).\n\nOps:\n- 'undo': Undo the entire last tool call when 'path' is omitted (typical), or undo the last edit to one file when 'path' is provided. Note: pops from the undo stack (irreversible, no redo). Use 'history' to inspect per-file history before undoing.\n- 'history': List all edit snapshots for a file. Requires 'path'.\n- 'checkpoint': Save a named snapshot (on disk across restarts; expires in 14 days; may contain secrets). Explicit files may be untracked/gitignored; omit for backup-tracked files. Requires 'name'.\n- 'restore': Restore files to a previously saved checkpoint. Optional 'path'/'files' scopes the restore; omitted scope restores the whole checkpoint. Requires 'name'.\n- 'list': List all available named checkpoints. No extra params needed.\n- 'purge': Permanently delete this session's undo backups and checkpoint copies of 'path' (a file, or everything under a directory); cannot be undone.\n\nEach op requires specific parameters — see parameter descriptions for requirements.\n\nUse checkpoint before risky multi-file changes. Use undo for quick single-file rollback.", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "op": { + "description": "Safety operation", + "type": "string", + "enum": [ + "undo", + "history", + "checkpoint", + "restore", + "list", + "purge" + ] + }, + "path": { + "description": "File path (required for history, optional for undo, optional for checkpoint — snapshots only that file when files is omitted, optional for restore — restores only that file, required for purge — a file or directory). Absolute or relative to project root", + "type": "string" + }, + "name": { + "description": "Checkpoint name (required for checkpoint, restore)", + "type": "string" + }, + "files": { + "description": "Specific files to include in checkpoint, or to restore from a checkpoint (optional; restore without path/files restores the whole checkpoint; explicit checkpoint files may be untracked or gitignored)", + "type": "array", + "items": { + "type": "string" + } + } + }, + "required": [ + "op" + ] + } + }, + { + "name": "bash_status", + "schema_digest": "d6a69ca626fb7e4e733a2e253e23deec542462ec598c417265f2846303c16f1c", + "semantics": 1, + "modes": [ + "classic", + "codemode" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "shell.exec/v1" + ], + "description": "Read-only snapshot of a background or PTY bash task's current state and output; a remote job ID works too. Returns immediately and never waits; the task keeps running, and a completion reminder arrives when it exits.", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "taskId": { + "description": "Background task ID returned by bash({ background: true }), e.g. bash-6b454047a1c39ded, or its remote job ID.", + "type": "string" + }, + "outputOffset": { + "description": "Read a bounded stdout/PTY byte page from this offset; returns masked text and the next byte offset.", + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + }, + "stderrOffset": { + "description": "Read a bounded stderr byte page from this offset; returns masked text and the next byte offset.", + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + }, + "outputMode": { + "description": "PTY output rendering mode. Defaults to screen for PTY tasks and preserves existing behavior for piped tasks when omitted.", + "type": "string", + "enum": [ + "screen", + "raw", + "both" + ] + } + }, + "required": [ + "taskId" + ] + } + }, + { + "name": "bash_kill", + "schema_digest": "96f37c924532b6490161c9f1075beb7ae617aaa659dc32fa324835125163373e", + "semantics": 1, + "modes": [ + "classic", + "codemode" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "shell.exec/v1" + ], + "description": "Terminate a running background bash task spawned with bash({ background: true }); a remote job ID works too. Returns confirmation of kill or an error if the task already finished.", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "taskId": { + "description": "Background task ID returned by bash({ background: true }), e.g. bash-6b454047a1c39ded, or its remote job ID.", + "type": "string" + } + }, + "required": [ + "taskId" + ] + } + }, + { + "name": "bash_write", + "schema_digest": "d5dd71a3c339a699a8a07a4f411e98c10210a04d47f6bfc10415e950f59c4496", + "semantics": 1, + "modes": [ + "classic", + "codemode" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "shell.exec/v1" + ], + "description": "Write input bytes to a running PTY bash task. PTY-only; check bash_status reports mode: \"pty\" first. Input is either a string (verbatim bytes) or an array mixing strings and { key: \"esc\" | \"enter\" | \"up\" | \"ctrl-c\" | ... } objects for atomic text+key sequences such as [ \"iHello\", { key: \"esc\" }, \":wq\", { key: \"enter\" } ]. Named keys cover enter/return/tab/space/backspace/esc/escape, arrows, home/end/page-up/page-down/delete/insert, f1..f12, and ctrl-a..ctrl-z. Maximum 1 MiB per call (post-expansion).", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "taskId": { + "description": "Background PTY task ID returned by bash({ pty: true, background: true }).", + "type": "string" + }, + "input": { + "description": "Either a string of verbatim bytes (e.g. 'print(1)\\n') OR an array mixing strings and { key: '' } objects for atomic text+key sequences. Example: [ 'iHello', { key: 'esc' }, ':wq', { key: 'enter' } ].", + "anyOf": [ + { + "type": "string" + }, + { + "type": "array", + "items": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "object", + "properties": { + "key": { + "description": "Named control key, e.g. 'esc', 'enter', 'up', 'ctrl-c'. Case-insensitive.", + "type": "string" + } + }, + "required": [ + "key" + ] + } + ] + } + } + ] + } + }, + "required": [ + "taskId", + "input" + ] + } + } + ], + "notice_templates": [ + { + "id": "aft.bash.code_search", + "text": "DO NOT search code by running grep/rg in {shell} — it is unindexed, unranked, and serial. {redirect}", + "slots": { + "redirect": { + "type": "enum", + "values": [ + "Use the `aft_search` tool instead (it auto-routes concepts, identifiers, regex, and literals).", + "Use the `grep` tool instead (indexed and ranked)." + ] + }, + "shell": { + "type": "enum", + "values": [ + "bash", + "shell" + ] + } + } + }, + { + "id": "aft.bash.prefer_tool", + "text": "Prefer `{tool}` tool over {shell}.", + "slots": { + "shell": { + "type": "enum", + "values": [ + "bash", + "shell" + ] + }, + "tool": { + "type": "enum", + "values": [ + "glob", + "read", + "edit" + ] + } + } + }, + { + "id": "aft.repeat_call.identical", + "text": "This call ran {count} times with the same arguments and the same output in {span} s. It is not returning anything new. {instruction}", + "slots": { + "count": { + "type": "integer", + "min": 2, + "max": 1000 + }, + "instruction": { + "type": "enum", + "values": [ + "If you are waiting on a task or CI run, use a background task with a watch (or the background handle you already hold) and end the turn. If you are already watching, let the watch return before calling again.", + "The turn must end now with no further tool call. If you are waiting on a task or CI run, use a background task with a watch (or the background handle you already hold) and end the turn. If you are already watching, let the watch return before calling again.", + "If you are waiting on a task or CI run, wait with a watch on its background task (for example bash_watch on the task ID you already hold) instead of repeating this call. If you are already watching, let the watch return before calling again.", + "Stop now: make no further call with these arguments. If you are waiting on a task or CI run, wait with a watch on its background task (for example bash_watch on the task ID you already hold) instead of repeating this call. If you are already watching, let the watch return before calling again.", + "If you are waiting on a task or CI run, use bash_status on the task ID you already hold to inspect it, or bash_kill to stop it, instead of repeating this call.", + "Stop now: make no further call with these arguments. If you are waiting on a task or CI run, use bash_status on the task ID you already hold to inspect it, or bash_kill to stop it, instead of repeating this call." + ] + }, + "span": { + "type": "integer", + "min": 0, + "max": 86400 + } + } + }, + { + "id": "aft.repeat_call.drifting", + "text": "This call ran {count} times with the same arguments in {span} s, and only its output drifts (for example, a timestamp). {instruction}", + "slots": { + "count": { + "type": "integer", + "min": 2, + "max": 1000 + }, + "instruction": { + "type": "enum", + "values": [ + "If you are waiting on a task or CI run, use a background task with a watch (or the background handle you already hold) and end the turn. If you are already watching, let the watch return before calling again.", + "The turn must end now with no further tool call. If you are waiting on a task or CI run, use a background task with a watch (or the background handle you already hold) and end the turn. If you are already watching, let the watch return before calling again.", + "If you are waiting on a task or CI run, wait with a watch on its background task (for example bash_watch on the task ID you already hold) instead of repeating this call. If you are already watching, let the watch return before calling again.", + "Stop now: make no further call with these arguments. If you are waiting on a task or CI run, wait with a watch on its background task (for example bash_watch on the task ID you already hold) instead of repeating this call. If you are already watching, let the watch return before calling again.", + "If you are waiting on a task or CI run, use bash_status on the task ID you already hold to inspect it, or bash_kill to stop it, instead of repeating this call.", + "Stop now: make no further call with these arguments. If you are waiting on a task or CI run, use bash_status on the task ID you already hold to inspect it, or bash_kill to stop it, instead of repeating this call." + ] + }, + "span": { + "type": "integer", + "min": 0, + "max": 86400 + } + } + } + ], + "capabilities": { + "late_results": true + } +} diff --git a/test-vectors/aft-notice-templates-v1.1/head.sends.json b/test-vectors/aft-notice-templates-v1.1/head.sends.json new file mode 100644 index 0000000000..a098d6bfbc --- /dev/null +++ b/test-vectors/aft-notice-templates-v1.1/head.sends.json @@ -0,0 +1,88 @@ +[ + { + "method": "session.send", + "params": { + "send_id": "aft:nudge:aft.bash.code_search:example-call", + "delivery": [ + "turn_system_cleared", + "tool_result" + ], + "dedupe_key": "aft:nudge:aft.bash.code_search", + "expires_at_ms": 1700000060000, + "template": { + "id": "aft.bash.code_search", + "digest": "e452d83cb806745d329e900d1f3514ca18a85041bfd3447fc1dfb8f100d60cbc", + "slots": { + "shell": "bash", + "redirect": "Use the `aft_search` tool instead (it auto-routes concepts, identifiers, regex, and literals)." + } + }, + "notice": true + } + }, + { + "method": "session.send", + "params": { + "send_id": "aft:nudge:aft.bash.prefer_tool:example-call", + "delivery": [ + "turn_system_cleared", + "tool_result" + ], + "dedupe_key": "aft:nudge:aft.bash.prefer_tool", + "expires_at_ms": 1700000060000, + "template": { + "id": "aft.bash.prefer_tool", + "digest": "3d406a218b3d6d9a37a134c4cf5293559837b014187f2efb03bb448f7d455663", + "slots": { + "tool": "read", + "shell": "bash" + } + }, + "notice": true + } + }, + { + "method": "session.send", + "params": { + "send_id": "aft:nudge:aft.repeat_call.identical:example-call", + "delivery": [ + "turn_system_cleared", + "tool_result" + ], + "dedupe_key": "aft:nudge:aft.repeat_call.identical", + "expires_at_ms": 1700000060000, + "template": { + "id": "aft.repeat_call.identical", + "digest": "5ad948cda47d6ccacb45ea7279d425d0d821bc2eee060fefab7862b2820a1c03", + "slots": { + "count": 3, + "span": 42, + "instruction": "If you are waiting on a task or CI run, use a background task with a watch (or the background handle you already hold) and end the turn. If you are already watching, let the watch return before calling again." + } + }, + "notice": true + } + }, + { + "method": "session.send", + "params": { + "send_id": "aft:nudge:aft.repeat_call.drifting:example-call", + "delivery": [ + "turn_system_cleared", + "tool_result" + ], + "dedupe_key": "aft:nudge:aft.repeat_call.drifting", + "expires_at_ms": 1700000060000, + "template": { + "id": "aft.repeat_call.drifting", + "digest": "eb8733fe3db66d83a310fbe43f6e976ddc4b35d3243794e3fe7ed07af32df9c7", + "slots": { + "count": 3, + "span": 42, + "instruction": "If you are waiting on a task or CI run, use a background task with a watch (or the background handle you already hold) and end the turn. If you are already watching, let the watch return before calling again." + } + }, + "notice": true + } + } +] diff --git a/test-vectors/aft-notice-templates-v1.1/reader.catalog.json b/test-vectors/aft-notice-templates-v1.1/reader.catalog.json new file mode 100644 index 0000000000..dc6ee257a1 --- /dev/null +++ b/test-vectors/aft-notice-templates-v1.1/reader.catalog.json @@ -0,0 +1,482 @@ +{ + "generation": "091a4bc00a0738c67f628c4b51e561878ce30543f4efcae490ac212f7991c94c", + "catalog_digest": "091a4bc00a0738c67f628c4b51e561878ce30543f4efcae490ac212f7991c94c", + "tools": [ + { + "read_only": true, + "name": "read", + "schema_digest": "f9ef88233ec21e9968187fd84526076c5853cb62d8397721b76ae8bd0a229f00", + "semantics": 1, + "modes": [ + "classic", + "codemode", + "flow" + ], + "result_ops": [ + "prepend", + "append" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "code.read/v1" + ], + "description": "Read file contents or list directory entries.\n\nUse either startLine/endLine OR offset/limit to read a section of a file or sorted directory listing.\n\nBehavior:\n- Returns line-numbered content (e.g., \"1: const x = 1\")\n- Lines longer than 2000 characters are truncated\n- Output capped at 50KB\n- Binary files are auto-detected and return a size-only message\n- Supported images (PNG, JPEG, GIF, WebP) and PDFs are returned as tool attachments; range arguments are ignored for media\n- Directories return sorted entries with trailing / for subdirectories; offset is 1-based, limit defaults to and is capped at 1000 entries. Enumeration stops at 10,000 entries; partial listings carry a shown/total trailer.\n\nExamples:\n Read full file: { \"path\": \"src/app.ts\" }\n Read lines 50-100: { \"path\": \"src/app.ts\", \"startLine\": 50, \"endLine\": 100 }\n Read 30 lines from line 200: { \"path\": \"src/app.ts\", \"offset\": 200, \"limit\": 30 }\n List directory: { \"path\": \"src/\" }\n", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "path": { + "description": "Path to file or directory (absolute or relative to project root)", + "type": "string" + }, + "startLine": { + "description": "1-based line or directory entry to start reading from", + "type": "integer", + "minimum": 1, + "maximum": 9007199254740991 + }, + "endLine": { + "description": "1-based line or directory entry to stop reading at (inclusive)", + "type": "integer", + "minimum": 1, + "maximum": 9007199254740991 + }, + "limit": { + "description": "Max lines (default: 2000) or directory entries (default and cap: 1000) to return", + "type": "integer", + "minimum": 1, + "maximum": 9007199254740991 + }, + "offset": { + "description": "1-based line or directory entry to start reading from (use with limit). Ignored if startLine is provided", + "type": "integer", + "minimum": 1, + "maximum": 9007199254740991 + } + }, + "required": [ + "path" + ] + } + }, + { + "read_only": true, + "name": "grep", + "schema_digest": "0f7a077fe3aee4e28d4cdebb8093776db34692c342ef3b67c3b9e49fe7c31f19", + "semantics": 1, + "modes": [ + "classic", + "codemode", + "flow" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "code.search/v1" + ], + "description": "Search file contents using regular expressions. Returns matching lines with file paths and line numbers (no surrounding context lines — use `read` for that). Always case-sensitive. Lockfiles, generated and minified files, logs and command output, and JSON data files are counted, not printed, unless `path` or `include` names them; the reply lists them with the value to pass. Long lines are shown as a window around the match. A large result starts with matching lines per file and a 40-line first page; pass `offset` to page. When a list is cut, the reply ends with `shown N of M () · narrow: `; absence of that line means the list is complete.", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "pattern": { + "type": "string" + }, + "include": { + "type": "string" + }, + "path": { + "type": "string" + }, + "offset": { + "description": "Rows of shown results to skip; follow the next offset the reply names.", + "type": "integer", + "minimum": 0, + "maximum": 100000 + } + }, + "required": [ + "pattern" + ] + } + }, + { + "read_only": true, + "name": "glob", + "schema_digest": "f0710f894a9c43ff7709e5f5cb63c37f7cda4e969840379f728a6d55f353a659", + "semantics": 1, + "modes": [ + "classic", + "codemode", + "flow" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "code.search/v1" + ], + "description": "Find files matching a glob pattern. Returns matching file paths sorted by modification time. When a list is cut, the reply ends with `shown N of M () · narrow: `; absence of that line means the list is complete.", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "pattern": { + "type": "string" + }, + "path": { + "type": "string" + } + }, + "required": [ + "pattern" + ] + } + }, + { + "read_only": true, + "name": "search", + "schema_digest": "c01cfa3965f768c100253bb0d59285149d4883f5fa46d7b511cc98e0a7efb70e", + "semantics": 1, + "modes": [ + "classic", + "codemode", + "flow" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "code.search/v1" + ], + "description": "Search code with one tool: concepts, identifiers, error strings, regex, literals, and filenames are auto-routed to the right engine and returned ranked. For conceptual 'how does X work' queries, phrase a full natural-language sentence — the semantic lane is NL-aware and matches intent against docstrings and comments ('how does the ORM build and execute a query', 'where is rate limiting handled'), not just keywords. Exact names, strings, and regex stay terse ('^export', 'Cargo.lock').\n\nWhen you know a name or string that must appear, put it in `pattern` (a regex, grep syntax, case-sensitive) and keep the question in `query`: both are ranked together, and the reply's first line says how many files the pattern matched and where it is defined. Example: query 'how is the config file loaded', pattern 'load_config|ConfigLoader'. `pattern` alone ranks the files it matches, definitions first.\n\nUse `offset` to continue a ranked result list from a zero-based position.\n\nWhen a list is cut, the reply ends with `shown N of M () · narrow: `; absence of that line means the list is complete.", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "query": { + "description": "Concept, regex, literal text, filename, or capability to find. Examples: 'fuzzy match with whitespace tolerance', '^export', 'Cargo.lock'. Optional when `pattern` is given.", + "type": "string" + }, + "pattern": { + "description": "Regex (grep syntax, case-sensitive) for names or text that must appear, e.g. 'load_config|ConfigLoader'. Ranked with `query` when both are given.", + "type": "string" + }, + "topK": { + "description": "Number of results (default: 10, max: 50)", + "type": "integer", + "minimum": 1, + "maximum": 50 + }, + "offset": { + "description": "Zero-based result offset (default: 0, max: 100000).", + "type": "integer", + "minimum": 0, + "maximum": 100000 + }, + "includeTests": { + "description": "Include test files (*.test.*, *_test.rs, __tests__/, …) plus test-support, fixture, mock, snapshot, and corpus files. Defaults to false.", + "type": "boolean" + }, + "path": { + "description": "Only set this to search a different project or plain folder (absolute or ~ path). Omit it for the current configured workspace, including non-Git workspace roots; this is not a subdirectory filter. Unindexed external folders use a bounded lexical fallback; filesystem roots, home and its ancestors are refused.", + "type": "string" + } + } + } + }, + { + "read_only": true, + "name": "outline", + "schema_digest": "264536293f3baca10d5e6b695baf9a29f71ea74b7e4241ceaed26e3b46e165cf", + "semantics": 1, + "modes": [ + "classic", + "codemode", + "flow" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "code.outline/v1" + ], + "description": "Structural outline of source code, documentation files, or remote URLs. For code, returns symbols (functions, classes, types) with line ranges. For Markdown and HTML, returns heading hierarchy. Use this to explore structure before reading specific sections with zoom. With `files: true`, the outline is breadth-first with directory rollups; drill in by outlining a subdirectory. Rows show language, symbol count, and line count.\n\nFor understanding a specific feature, prefer search + zoom on named symbols; use outline on a whole directory only for high-level structure mapping. zoom with `callgraph:true` gives one-level forward calls-out; use callgraph only for reverse callers or multi-level traces.\n\nPass a single `target`:\n • file path → outline that file (with signatures)\n • directory path → outline source files under it\n • URL (http:// or https://) → fetch and outline a remote HTML/Markdown document\n • array of paths → outline multiple files in one call; with files:true, every path must be a directory\n\nWhen a list is cut, the reply ends with `shown N of M () · narrow: `; absence of that line means the list is complete.", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "target": { + "description": "What to outline: a file path, directory path, URL, or array of paths. The mode is auto-detected: URLs by `http://`/`https://` prefix, directories by stat, arrays as multi-file.", + "anyOf": [ + { + "type": "string" + }, + { + "type": "array", + "items": { + "type": "string" + } + } + ] + }, + "files": { + "description": "Directory-only mode: when true, target must be a directory or array of directories and the result is a breadth-first file tree with directory rollups plus language, symbol, and line counts.", + "type": "boolean" + }, + "includeTests": { + "description": "Directory outline only: include test files. Defaults to false; tests are hidden.", + "type": "boolean" + } + }, + "required": [ + "target" + ] + } + }, + { + "read_only": true, + "name": "zoom", + "schema_digest": "0c709b2d562766296a0e4601b4a16304488d2ffff6e8ac4ccfc4b68e1fe9be39", + "semantics": 1, + "modes": [ + "classic", + "codemode", + "flow" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "code.outline/v1" + ], + "description": "Inspect code symbols or documentation sections. Pass lookups in `batch: [{ target, symbols }]`; a single lookup is a one-entry batch. Mix files and URLs in one batch, for example `batch: [{ target: \"src/app.ts\", symbols: \"run\" }, { target: \"https://example.com/docs\", symbols: \"Overview\" }]`. Each target is auto-detected as a file path or an HTTP/HTTPS URL. `symbols` is a string or string array. Markdown and HTML lookups return the section under the heading. Top-level `contextLines` and `callgraph` apply to every entry; callgraph adds calls-out and called-by annotations. Each failed lookup reports its own error line.", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "batch": { + "description": "One or more lookups; entries may mix file paths and URLs", + "minItems": 1, + "type": "array", + "items": { + "type": "object", + "properties": { + "target": { + "description": "File path (absolute or project-relative) or HTTP/HTTPS URL, auto-detected; issue://N or pr://N when GitHub reads are enabled", + "type": "string" + }, + "symbols": { + "description": "Symbol name for code or heading text for Markdown/HTML; a string or array of strings", + "anyOf": [ + { + "type": "string" + }, + { + "type": "array", + "items": { + "type": "string" + } + } + ] + } + }, + "required": [ + "target", + "symbols" + ] + } + }, + "contextLines": { + "description": "Lines of context before/after each symbol (default: 3)", + "type": "integer", + "minimum": 1, + "maximum": 9007199254740991 + }, + "callgraph": { + "description": "Include call-graph annotations for every entry (default: false)", + "type": "boolean" + } + }, + "required": [ + "batch" + ] + } + }, + { + "name": "inspect", + "schema_digest": "4e189e7662dd08cec4e8696bc215b3742a0ca5a5dd037de744f523c3707596aa", + "semantics": 1, + "modes": [ + "classic", + "codemode" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "code.diagnostics/v1" + ], + "description": "Codebase health inspection that waits for current analysis. FRESH means the reported analysis is current. PARTIAL means some diagnostics are unknown; the header names the analyzer, reason, and retry guidance. INTERRUPTED means the request stopped without a fresh snapshot; retry inspect. PHASE-FAILED means inspection could not finish; address the reported reason and retry, or narrow the scope. `sections` selects drill-down detail. Scoped requests collect diagnostics when sections is omitted or includes 'diagnostics' or 'all'; sections that leave diagnostics out skip diagnostics work. Unscoped requests keep warm diagnostics. Categories switched off in `inspect.categories` are not computed or refreshed, render as off, and never make the header PARTIAL.\n\nUse `scope=` to narrow all findings, counts, and examples to those paths. Cross-boundary duplicates are labeled as groups touching the scope. Scope also limits Rust analyzer startup to the Cargo workspaces owning those paths when diagnostics are requested. Files without an authoritative diagnostic report remain named gaps (complete: false), not a clean result.\n\nUse when: starting work on unfamiliar code, after multi-edit batches to check diagnostics, before a refactor, before review, or to verify cleanup completeness.\n\nTreat `dead_code` as a hint, not proof: reachability is call-based, so symbols reached only via method dispatch or referenced only in type position may be false positives — verify before deleting.\n\nWhen a list is cut, the reply ends with `shown N of M () · narrow: `; absence of that line means the list is complete.", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "sections": { + "description": "Categories to include in detailed drill-down (e.g. 'todos' or ['todos', 'dead_code', 'cycles']). Use 'all' for every active category. Omit for summary-only mode. With scope, listing sections without 'diagnostics' (or 'all') skips diagnostics work; omitting sections keeps diagnostics. Other categories are verified regardless of sections.", + "anyOf": [ + { + "type": "string" + }, + { + "type": "array", + "items": { + "type": "string" + } + } + ] + }, + "scope": { + "description": "Restrict returned results to paths under this scope (one path, or an array of paths — not a space-separated list; file or directory; absolute or relative to project root). `scope=` narrows results. Scoped requests collect diagnostics for the scoped files and report coverage gaps, unless sections lists other categories and leaves out 'diagnostics'.", + "anyOf": [ + { + "type": "string" + }, + { + "type": "array", + "items": { + "type": "string" + } + } + ] + }, + "offset": { + "description": "Rows to skip independently in each drill-down list. Default 0; follow next_offset in each list envelope.", + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + }, + "topK": { + "description": "Max drill-down items per category. Default 20, max 100.", + "type": "integer", + "exclusiveMinimum": 0, + "maximum": 100 + } + } + } + }, + { + "read_only": true, + "name": "callgraph", + "schema_digest": "cc1143512feeca2585bd922ab9047a00ef2496807a1307dac19e9047ae4e86de", + "semantics": 1, + "modes": [ + "classic", + "codemode", + "flow" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "code.callgraph/v1" + ], + "description": "Answer code-relationship questions from a real call graph — instead of grep + read chains. Reach for this whenever the question is about how symbols connect: who calls X, what X calls, what breaks if X changes, how execution reaches X, or how a value flows.\n\nUse zoom with `callgraph:true` for one-level forward calls-out while reading source. Use callgraph only for reverse callers or multi-level traces so you do not double-fetch the same relationships.\n\nOps:\n- 'callers': Find all call sites of a symbol. Use before renaming or changing a function's signature.\n- 'impact': What breaks if a symbol changes — affected callers with signatures and entry-point status (blast radius). Use before a risky edit.\n- 'call_tree': What a function calls (forward traversal). Use to understand a function's dependencies before modifying it.\n- 'trace_to': How execution reaches a function: each path of callers runs back to a root, labelled main, test, attribute, public API, or no caller found. Use to understand context around deeply-nested code.\n- 'trace_to_symbol': Shortest call path from one symbol to another. Requires 'toSymbol'. If multiple targets match, the error returns candidate files; retry with 'toPath' to disambiguate.\n- 'trace_data': Follow a value through variable assignments and function parameters across files. Requires 'symbol' (scope to trace from) and 'expression'.\n\nAll ops require both 'path' and 'symbol'. 'expression' is additionally required for trace_data; 'toSymbol' for trace_to_symbol.\n\nMarkers: ~ = edge resolved by name only (may point at the wrong same-named symbol); [unresolved] = callee not resolved to a definition, so the location shown is the call site. Unmarked edges are resolved exactly. By default, unresolved external/stdlib leaf calls in call_tree are collapsed into one summary per parent; pass includeUnresolved=true to show every unresolved edge individually.\n\nWhen a list is cut, the reply ends with `shown N of M () · narrow: `; absence of that line means the list is complete.\n", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "op": { + "description": "Navigation operation", + "type": "string", + "enum": [ + "call_tree", + "callers", + "trace_to", + "trace_to_symbol", + "impact", + "trace_data" + ] + }, + "path": { + "description": "Path to the source file containing the symbol (absolute or relative to project root)", + "type": "string" + }, + "symbol": { + "description": "Name of the symbol to analyze", + "type": "string" + }, + "depth": { + "description": "Max traversal depth (default: call_tree=5, callers=1, trace_to=10, trace_to_symbol=10 capped at 16, impact=5, trace_data=5)", + "type": "integer", + "minimum": 1, + "maximum": 9007199254740991 + }, + "expression": { + "description": "Expression to track through data flow (required for trace_data op)", + "type": "string" + }, + "toSymbol": { + "description": "Target symbol name for trace_to_symbol; the returned path ends at this symbol", + "type": "string" + }, + "toPath": { + "description": "Optional target file for trace_to_symbol; required when toSymbol exists in multiple files", + "type": "string" + }, + "includeTests": { + "description": "Include test files in callers/paths. Defaults to false; tests are hidden.", + "type": "boolean" + }, + "includeUnresolved": { + "description": "Show every unresolved external/stdlib call individually. Defaults to false; unresolved leaf calls are collapsed into one summary per parent.", + "type": "boolean" + } + }, + "required": [ + "op", + "path", + "symbol" + ] + } + } + ], + "notice_templates": [ + { + "id": "aft.repeat_call.identical", + "text": "This call ran {count} times with the same arguments and the same output in {span} s. It is not returning anything new. {instruction}", + "slots": { + "count": { + "type": "integer", + "min": 2, + "max": 1000 + }, + "instruction": { + "type": "enum", + "values": [ + "If you are waiting on a task or CI run, use a background task with a watch (or the background handle you already hold) and end the turn. If you are already watching, let the watch return before calling again.", + "The turn must end now with no further tool call. If you are waiting on a task or CI run, use a background task with a watch (or the background handle you already hold) and end the turn. If you are already watching, let the watch return before calling again." + ] + }, + "span": { + "type": "integer", + "min": 0, + "max": 86400 + } + } + }, + { + "id": "aft.repeat_call.drifting", + "text": "This call ran {count} times with the same arguments in {span} s, and only its output drifts (for example, a timestamp). {instruction}", + "slots": { + "count": { + "type": "integer", + "min": 2, + "max": 1000 + }, + "instruction": { + "type": "enum", + "values": [ + "If you are waiting on a task or CI run, use a background task with a watch (or the background handle you already hold) and end the turn. If you are already watching, let the watch return before calling again.", + "The turn must end now with no further tool call. If you are waiting on a task or CI run, use a background task with a watch (or the background handle you already hold) and end the turn. If you are already watching, let the watch return before calling again." + ] + }, + "span": { + "type": "integer", + "min": 0, + "max": 86400 + } + } + } + ], + "capabilities": { + "late_results": true + } +} diff --git a/test-vectors/aft-notice-templates-v1.1/reader.sends.json b/test-vectors/aft-notice-templates-v1.1/reader.sends.json new file mode 100644 index 0000000000..a2a7337005 --- /dev/null +++ b/test-vectors/aft-notice-templates-v1.1/reader.sends.json @@ -0,0 +1,46 @@ +[ + { + "method": "session.send", + "params": { + "send_id": "aft:nudge:aft.repeat_call.identical:example-call", + "delivery": [ + "turn_system_cleared", + "tool_result" + ], + "dedupe_key": "aft:nudge:aft.repeat_call.identical", + "expires_at_ms": 1700000060000, + "template": { + "id": "aft.repeat_call.identical", + "digest": "e871541e2807aec7ef9fa2411bc6d978063be62ed4b6546ba77d738b245e44cd", + "slots": { + "count": 3, + "span": 42, + "instruction": "If you are waiting on a task or CI run, use a background task with a watch (or the background handle you already hold) and end the turn. If you are already watching, let the watch return before calling again." + } + }, + "notice": true + } + }, + { + "method": "session.send", + "params": { + "send_id": "aft:nudge:aft.repeat_call.drifting:example-call", + "delivery": [ + "turn_system_cleared", + "tool_result" + ], + "dedupe_key": "aft:nudge:aft.repeat_call.drifting", + "expires_at_ms": 1700000060000, + "template": { + "id": "aft.repeat_call.drifting", + "digest": "05079c3e7e514f58e6901ae44bf0a7e3b064f53ba8857ab54e938a9b83f16ec9", + "slots": { + "count": 3, + "span": 42, + "instruction": "If you are waiting on a task or CI run, use a background task with a watch (or the background handle you already hold) and end the turn. If you are already watching, let the watch return before calling again." + } + }, + "notice": true + } + } +] diff --git a/test-vectors/aft-notice-templates-v1.1/worker.catalog.json b/test-vectors/aft-notice-templates-v1.1/worker.catalog.json new file mode 100644 index 0000000000..2d0cdf4419 --- /dev/null +++ b/test-vectors/aft-notice-templates-v1.1/worker.catalog.json @@ -0,0 +1,1333 @@ +{ + "generation": "cd1337fd0e37fcec1d149ae42cbb8527bb29b1a4cb6a7c98de3572bc4644ba32", + "catalog_digest": "cd1337fd0e37fcec1d149ae42cbb8527bb29b1a4cb6a7c98de3572bc4644ba32", + "tools": [ + { + "name": "status", + "schema_digest": "99334726611ccf58a148b0814696bfa6fe08c1b2d027e946beccf5a74331c9aa", + "semantics": 1, + "modes": [ + "classic", + "codemode" + ], + "result_format": "tool-result/v1", + "capabilities": [], + "description": "Show AFT status, index health, cache usage, and runtime details", + "input_schema": { + "type": "object", + "properties": {}, + "additionalProperties": false + } + }, + { + "name": "bash", + "schema_digest": "da852fe71bf96fc7597ea7236d99a23f311dbd1d32f6ef026259c7140a70fc0a", + "semantics": 2, + "modes": [ + "classic", + "codemode" + ], + "result_ops": [ + "prepend", + "append" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "shell.exec/v1", + "call.yield/v1" + ], + "description": "Execute shell commands. Output is compressed by default; pass compressed: false for raw output. Piped commands run verbatim and show the pipeline's output; for AFT's test/build summary, run the runner without | head, | tail, or | grep. Pipeline-failure notes cover single top-level pipelines only; multi-statement commands (`a; b | c; d`) are not instrumented, so masked failures inside them still need explicit exit-code checks. Commands run in the foreground and return inline; wait: true blocks until a long command finishes instead of auto-promoting (it blocks up to bash.worker_wait_max_ms, 30 minutes by default, then reports the command is still running; watch again to keep waiting); Any new message detaches this wait. Set `bash.detach_on_user_message: false` to keep it blocking; even then, a message containing the literal `&detach` forces detachment, and the token is stripped before delivery and the rest of the message is preserved; a token-only message becomes `(requested background detach)`. Use it when you need the result before doing anything else; keep it off otherwise so a long command moves to the background while you work. Use background: true yourself ONLY when you have other work to do while it runs, and any work that doesn't need this command's result counts; then wait on it with bash_watch before you report a result: a background task never wakes you, and a watch without a timeout waits up to the worker wait limit (`bash.worker_wait_max_ms`, 30 minutes by default), then reports it is still running; watch again to keep waiting. Never background a command and immediately bash_watch it (that wastes a turn for what foreground returns in one); never loop bash_status to wait. Do not change or delete files a background command uses until it finishes. A `nohup … &` launch still holds the call if the child keeps stdout/stderr; redirect both or use background:true. pty: true runs interactive programs (REPLs, TUIs), implies background, and is driven with bash_status({ outputMode: \"screen\" }) plus bash_write. Finished output expires after the task is 24 hours old and its completion has been delivered; under project-root restrictions, only the starting session can read output outside the project—copy cited lines into your report. `timeout` starts after spawn and kills the Unix process group (exit 124; Windows uses taskkill /T /F); processes that leave the group survive.\n\nDO NOT use bash for code search or code exploration. If you are about to run grep, rg, sed, awk, find, or cat through bash to locate or read code: STOP — use the grep tool, read, outline, or zoom instead. When a list is cut, the reply ends with `shown N of M () · narrow: `; absence of that line means the list is complete.", + "reply": { + "max_ms": 2040000 + }, + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "command": { + "description": "Shell command to execute. Supports pipes, redirection, and normal shell syntax.", + "type": "string" + }, + "timeout": { + "description": "Hard kill cap in milliseconds (positive integer). In the default foreground mode when wait is false, a command that exceeds the configured wait window moves to the background as a task that won't wake you, so wait on it with bash_watch; wait:true disables promotion and remains inline until completion, the timeout, or the worker wait limit. A background task with no timeout is killed after 30 minutes; pass a longer timeout for long jobs.", + "type": "integer", + "minimum": 1, + "maximum": 9007199254740991 + }, + "workdir": { + "description": "Working directory for command execution. Relative paths resolve through the bridge; defaults to the current tool context/project root when omitted.", + "type": "string" + }, + "description": { + "description": "Short 5-10 word human-readable summary shown in OpenCode UI metadata instead of raw shell syntax.", + "type": "string" + }, + "wait": { + "description": "When true, run in the foreground without auto-promoting and wait until the command finishes or reaches its timeout (at most bash.worker_wait_max_ms, 30 minutes by default; the command then keeps running in the background and the reply says how to keep waiting); Any new message detaches this wait. Set `bash.detach_on_user_message: false` to keep it blocking; even then, a message containing the literal `&detach` forces detachment, and the token is stripped before delivery and the rest of the message is preserved; a token-only message becomes `(requested background detach)`. Use only when you know the result is required before doing anything else.", + "type": "boolean" + }, + "sandbox": { + "description": "Request one-command approval to run unsandboxed on the host; use only when native sandboxing blocks required work, and note that it is a no-op when sandboxing is disabled.", + "type": "string", + "const": "host" + }, + "background": { + "description": "When true, spawn the command in the background and return a taskId for bash_status/bash_kill instead of waiting for completion. Defaults to false. A background task with no timeout is killed after 30 minutes; pass a longer timeout for long jobs.", + "type": "boolean" + }, + "compressed": { + "description": "When true or omitted, return compressed output with noisy terminal control sequences reduced. Set to false for raw output.", + "type": "boolean" + }, + "pty": { + "description": "When true, spawn the command in a real PTY for interactive programs (python/node/bash REPLs, vim). Implies background: true automatically. Inspect with bash_status({ taskId, outputMode: \"screen\" }) and drive interactively with bash_write — its input accepts either a string OR an array like [ \"iHello\", { key: \"esc\" }, \":wq\", { key: \"enter\" } ] for atomic text+key sequences.", + "type": "boolean" + }, + "ptyRows": { + "description": "PTY terminal height in rows — ignored when pty is false. Defaults to 24 when pty: true. Minimum 1, maximum 60.", + "type": "integer", + "minimum": 1, + "maximum": 60 + }, + "ptyCols": { + "description": "PTY terminal width in columns — ignored when pty is false. Defaults to 80 when pty: true. Minimum 1, maximum 140.", + "type": "integer", + "minimum": 1, + "maximum": 140 + } + }, + "required": [ + "command" + ] + } + }, + { + "read_only": true, + "name": "read", + "schema_digest": "f9ef88233ec21e9968187fd84526076c5853cb62d8397721b76ae8bd0a229f00", + "semantics": 1, + "modes": [ + "classic", + "codemode", + "flow" + ], + "result_ops": [ + "prepend", + "append" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "code.read/v1" + ], + "description": "Read file contents or list directory entries.\n\nUse either startLine/endLine OR offset/limit to read a section of a file or sorted directory listing.\n\nBehavior:\n- Returns line-numbered content (e.g., \"1: const x = 1\")\n- Lines longer than 2000 characters are truncated\n- Output capped at 50KB\n- Binary files are auto-detected and return a size-only message\n- Supported images (PNG, JPEG, GIF, WebP) and PDFs are returned as tool attachments; range arguments are ignored for media\n- Directories return sorted entries with trailing / for subdirectories; offset is 1-based, limit defaults to and is capped at 1000 entries. Enumeration stops at 10,000 entries; partial listings carry a shown/total trailer.\n\nExamples:\n Read full file: { \"path\": \"src/app.ts\" }\n Read lines 50-100: { \"path\": \"src/app.ts\", \"startLine\": 50, \"endLine\": 100 }\n Read 30 lines from line 200: { \"path\": \"src/app.ts\", \"offset\": 200, \"limit\": 30 }\n List directory: { \"path\": \"src/\" }\n", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "path": { + "description": "Path to file or directory (absolute or relative to project root)", + "type": "string" + }, + "startLine": { + "description": "1-based line or directory entry to start reading from", + "type": "integer", + "minimum": 1, + "maximum": 9007199254740991 + }, + "endLine": { + "description": "1-based line or directory entry to stop reading at (inclusive)", + "type": "integer", + "minimum": 1, + "maximum": 9007199254740991 + }, + "limit": { + "description": "Max lines (default: 2000) or directory entries (default and cap: 1000) to return", + "type": "integer", + "minimum": 1, + "maximum": 9007199254740991 + }, + "offset": { + "description": "1-based line or directory entry to start reading from (use with limit). Ignored if startLine is provided", + "type": "integer", + "minimum": 1, + "maximum": 9007199254740991 + } + }, + "required": [ + "path" + ] + } + }, + { + "name": "write", + "schema_digest": "e4b3deed1a39fc2a5b990b319b17e1f19c84c891a770c219d97d9cdefe6181cf", + "semantics": 1, + "modes": [ + "classic", + "codemode" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "code.edit/v1" + ], + "description": "Write content to a file, creating it and parent directories automatically. Use `path` for the file location. Existing files are backed up before overwriting (undo via safety). Auto-formats when the project has a formatter configured. Use it to create files or replace whole contents; for partial edits, use the `edit` tool. Write very large new files in parts: a single call can exceed the model's output limit and is then aborted with empty arguments.", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "path": { + "description": "Path to the file to write (absolute or relative to project root)", + "type": "string" + }, + "content": { + "description": "The full content to write to the file; for issue://N / pr://N, the comment body to post", + "type": "string" + } + }, + "required": [ + "path", + "content" + ] + } + }, + { + "name": "edit", + "schema_digest": "20dfe0eb13e87c68a0d54412e2e9605a3c1ce7935d36acf1c6df8e8660609ef8", + "semantics": 1, + "modes": [ + "classic", + "codemode" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "code.edit/v1" + ], + "description": "Edit a file by finding and replacing text, or by targeting named symbols. To write or overwrite a whole file, use the `write` tool — `edit` requires an explicit edit mode and will not silently overwrite a file from `content` alone.\n\n**Modes** (determined by which parameters you provide):\n\nProvide exactly one mode per call: appendContent, edits[], or symbol plus content. `symbol` and `content` are only meaningful together; a call carrying one without the other is incomplete. Mixing modes or providing none is rejected — there is no implicit \"write\" fallback. To edit multiple files, make parallel `edit` calls in one response.\n\n1. **Append** — pass `path` + `appendContent`\n Appends text to the end of a file, creating it if it does not exist.\n Example: `{ \"path\": \"notes.txt\", \"appendContent\": \"new line\\n\" }`\n\n2. **Batch edits** — pass `path` + `edits` array\n Multiple edits in one file atomically. Each edit is either:\n - `{ \"oldString\": \"old\", \"newString\": \"new\" }` — find/replace\n - `{ \"oldString\": \"old\", \"newString\": \"new\", \"replaceAll\": true }` — replace every match\n - `{ \"startLine\": 5, \"endLine\": 7, \"content\": \"new lines\" }` — replace line range (1-based, both inclusive)\n Set content to empty string to delete lines.\n\n3. **Symbol replace** — pass `path` + `symbol` + `content`\n Replaces an entire named symbol (function, class, type).\n Includes decorators, attributes, and doc comments in the replacement range.\n Example: `{ \"path\": \"src/app.ts\", \"symbol\": \"handleRequest\", \"content\": \"function handleRequest() { ... }\" }`\n\n4. **Find and replace** — put `oldString` and optional `newString` in an item of `edits[]`\n Finds the exact text in `oldString` and replaces it with `newString`.\n Supports fuzzy matching (handles whitespace differences automatically).\n If multiple matches exist, specify `occurrence` or set `replaceAll: true` in that item.\n\n5. **Replace all occurrences** — add `replaceAll: true` to a find/replace item.\n\n6. **Select specific occurrence** — add `occurrence: N` to a find/replace item (1-based).\n When multiple matches exist, select the Nth one (1 = first, 2 = second, etc.).\n\n**Behavior:**\n- Backs up files before editing (recoverable via safety undo)\n- Auto-formats using project formatter if configured\n- Tree-sitter syntax validation on all edits\n- Symbol replace includes decorators, attributes, and doc comments in range\n- Response is a compact server-rendered summary; before/after diff details are attached as UI metadata when available.", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "path": { + "description": "Path to the file to edit (absolute or relative to project root)", + "type": "string" + }, + "symbol": { + "description": "Named symbol to replace; only meaningful together with `content`. A call carrying one without the other is incomplete.", + "type": "string" + }, + "content": { + "description": "Replacement content for symbol mode; only meaningful together with `symbol`. A call carrying one without the other is incomplete. For whole-file writes, use the `write` tool.", + "type": "string" + }, + "appendContent": { + "description": "Text to append to the end of path; creates the file if needed", + "type": "string" + }, + "edits": { + "description": "Batch edits — non-empty array of { oldString, newString }, { oldString, newString, replaceAll: true }, or { startLine, endLine, content } objects", + "minItems": 1, + "type": "array", + "items": { + "type": "object", + "properties": { + "oldString": { + "description": "Text to find for a batch find/replace edit", + "type": "string" + }, + "newString": { + "description": "Replacement text for a batch find/replace edit", + "type": "string" + }, + "replaceAll": { + "description": "Replace every occurrence for this batch item", + "type": "boolean" + }, + "occurrence": { + "description": "1-based occurrence for this batch item (1 = first match)", + "type": "integer", + "minimum": 1, + "maximum": 9007199254740991 + }, + "startLine": { + "description": "1-based start line for a batch line-range edit", + "type": "integer", + "minimum": 1, + "maximum": 9007199254740991 + }, + "endLine": { + "description": "1-based end line for a batch line-range edit", + "type": "integer", + "minimum": 1, + "maximum": 9007199254740991 + }, + "content": { + "description": "Replacement text for a batch line-range edit", + "type": "string" + } + } + } + } + }, + "required": [ + "path" + ] + } + }, + { + "name": "apply_patch", + "schema_digest": "fa62c9797e5d14436714f5630d15815d2adc1185023a3dcba3f3ed20fc9f0548", + "semantics": 1, + "modes": [ + "classic", + "codemode" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "code.edit/v1" + ], + "description": "Use the `apply_patch` tool to edit files. Your patch language is a stripped‑down, file‑oriented diff format designed to be easy to parse and safe to apply. You can think of it as a high‑level envelope:\n\n*** Begin Patch\n[ one or more file sections ]\n*** End Patch\n\nWithin that envelope, you get a sequence of file operations.\nYou MUST include a header to specify the action you are taking.\nEach operation starts with one of three headers:\n\n*** Add File: - create a new file. Every following line is a + line (the initial contents).\n*** Delete File: - remove an existing file. Nothing follows.\n*** Update File: - patch an existing file in place (optionally with a rename).\n*** Move to: - after update file header, renames the file.\n\n\nExample patch:\n\n```\n*** Begin Patch\n*** Add File: hello.txt\n+Hello world\n*** Update File: src/app.py\n*** Move to: src/main.py\n@@ def greet():\n-print(\"Hi\")\n+print(\"Hello, world!\")\n*** Delete File: obsolete.txt\n*** End Patch\n```\n\n**Behavior:**\n- Per-file commit: each file's edits apply independently. If a later file fails, earlier successful changes are kept. Use `safety` undo if you need to revert the applied changes.\n- Files are backed up before modification\n- Parent directories are created automatically for new files\n- Fuzzy matching for context anchors (handles whitespace and Unicode differences)\n\n**It is important to remember:**\n\n- You must include a header with your intended action (Add/Delete/Update)\n- You must prefix new lines with `+` even when creating a new file\n\nEdits return as soon as the write completes unless `lsp.diagnostics_on_edit` requests legacy sync-wait behavior. Call `inspect` afterward to check diagnostics across a batch of edits.", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "patchText": { + "description": "The full patch text including Begin/End markers", + "type": "string" + } + }, + "required": [ + "patchText" + ] + } + }, + { + "read_only": true, + "name": "grep", + "schema_digest": "0f7a077fe3aee4e28d4cdebb8093776db34692c342ef3b67c3b9e49fe7c31f19", + "semantics": 1, + "modes": [ + "classic", + "codemode", + "flow" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "code.search/v1" + ], + "description": "Search file contents using regular expressions. Returns matching lines with file paths and line numbers (no surrounding context lines — use `read` for that). Always case-sensitive. Lockfiles, generated and minified files, logs and command output, and JSON data files are counted, not printed, unless `path` or `include` names them; the reply lists them with the value to pass. Long lines are shown as a window around the match. A large result starts with matching lines per file and a 40-line first page; pass `offset` to page. When a list is cut, the reply ends with `shown N of M () · narrow: `; absence of that line means the list is complete.", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "pattern": { + "type": "string" + }, + "include": { + "type": "string" + }, + "path": { + "type": "string" + }, + "offset": { + "description": "Rows of shown results to skip; follow the next offset the reply names.", + "type": "integer", + "minimum": 0, + "maximum": 100000 + } + }, + "required": [ + "pattern" + ] + } + }, + { + "read_only": true, + "name": "glob", + "schema_digest": "f0710f894a9c43ff7709e5f5cb63c37f7cda4e969840379f728a6d55f353a659", + "semantics": 1, + "modes": [ + "classic", + "codemode", + "flow" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "code.search/v1" + ], + "description": "Find files matching a glob pattern. Returns matching file paths sorted by modification time. When a list is cut, the reply ends with `shown N of M () · narrow: `; absence of that line means the list is complete.", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "pattern": { + "type": "string" + }, + "path": { + "type": "string" + } + }, + "required": [ + "pattern" + ] + } + }, + { + "read_only": true, + "name": "search", + "schema_digest": "c01cfa3965f768c100253bb0d59285149d4883f5fa46d7b511cc98e0a7efb70e", + "semantics": 1, + "modes": [ + "classic", + "codemode", + "flow" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "code.search/v1" + ], + "description": "Search code with one tool: concepts, identifiers, error strings, regex, literals, and filenames are auto-routed to the right engine and returned ranked. For conceptual 'how does X work' queries, phrase a full natural-language sentence — the semantic lane is NL-aware and matches intent against docstrings and comments ('how does the ORM build and execute a query', 'where is rate limiting handled'), not just keywords. Exact names, strings, and regex stay terse ('^export', 'Cargo.lock').\n\nWhen you know a name or string that must appear, put it in `pattern` (a regex, grep syntax, case-sensitive) and keep the question in `query`: both are ranked together, and the reply's first line says how many files the pattern matched and where it is defined. Example: query 'how is the config file loaded', pattern 'load_config|ConfigLoader'. `pattern` alone ranks the files it matches, definitions first.\n\nUse `offset` to continue a ranked result list from a zero-based position.\n\nWhen a list is cut, the reply ends with `shown N of M () · narrow: `; absence of that line means the list is complete.", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "query": { + "description": "Concept, regex, literal text, filename, or capability to find. Examples: 'fuzzy match with whitespace tolerance', '^export', 'Cargo.lock'. Optional when `pattern` is given.", + "type": "string" + }, + "pattern": { + "description": "Regex (grep syntax, case-sensitive) for names or text that must appear, e.g. 'load_config|ConfigLoader'. Ranked with `query` when both are given.", + "type": "string" + }, + "topK": { + "description": "Number of results (default: 10, max: 50)", + "type": "integer", + "minimum": 1, + "maximum": 50 + }, + "offset": { + "description": "Zero-based result offset (default: 0, max: 100000).", + "type": "integer", + "minimum": 0, + "maximum": 100000 + }, + "includeTests": { + "description": "Include test files (*.test.*, *_test.rs, __tests__/, …) plus test-support, fixture, mock, snapshot, and corpus files. Defaults to false.", + "type": "boolean" + }, + "path": { + "description": "Only set this to search a different project or plain folder (absolute or ~ path). Omit it for the current configured workspace, including non-Git workspace roots; this is not a subdirectory filter. Unindexed external folders use a bounded lexical fallback; filesystem roots, home and its ancestors are refused.", + "type": "string" + } + } + } + }, + { + "read_only": true, + "name": "outline", + "schema_digest": "264536293f3baca10d5e6b695baf9a29f71ea74b7e4241ceaed26e3b46e165cf", + "semantics": 1, + "modes": [ + "classic", + "codemode", + "flow" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "code.outline/v1" + ], + "description": "Structural outline of source code, documentation files, or remote URLs. For code, returns symbols (functions, classes, types) with line ranges. For Markdown and HTML, returns heading hierarchy. Use this to explore structure before reading specific sections with zoom. With `files: true`, the outline is breadth-first with directory rollups; drill in by outlining a subdirectory. Rows show language, symbol count, and line count.\n\nFor understanding a specific feature, prefer search + zoom on named symbols; use outline on a whole directory only for high-level structure mapping. zoom with `callgraph:true` gives one-level forward calls-out; use callgraph only for reverse callers or multi-level traces.\n\nPass a single `target`:\n • file path → outline that file (with signatures)\n • directory path → outline source files under it\n • URL (http:// or https://) → fetch and outline a remote HTML/Markdown document\n • array of paths → outline multiple files in one call; with files:true, every path must be a directory\n\nWhen a list is cut, the reply ends with `shown N of M () · narrow: `; absence of that line means the list is complete.", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "target": { + "description": "What to outline: a file path, directory path, URL, or array of paths. The mode is auto-detected: URLs by `http://`/`https://` prefix, directories by stat, arrays as multi-file.", + "anyOf": [ + { + "type": "string" + }, + { + "type": "array", + "items": { + "type": "string" + } + } + ] + }, + "files": { + "description": "Directory-only mode: when true, target must be a directory or array of directories and the result is a breadth-first file tree with directory rollups plus language, symbol, and line counts.", + "type": "boolean" + }, + "includeTests": { + "description": "Directory outline only: include test files. Defaults to false; tests are hidden.", + "type": "boolean" + } + }, + "required": [ + "target" + ] + } + }, + { + "read_only": true, + "name": "zoom", + "schema_digest": "0c709b2d562766296a0e4601b4a16304488d2ffff6e8ac4ccfc4b68e1fe9be39", + "semantics": 1, + "modes": [ + "classic", + "codemode", + "flow" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "code.outline/v1" + ], + "description": "Inspect code symbols or documentation sections. Pass lookups in `batch: [{ target, symbols }]`; a single lookup is a one-entry batch. Mix files and URLs in one batch, for example `batch: [{ target: \"src/app.ts\", symbols: \"run\" }, { target: \"https://example.com/docs\", symbols: \"Overview\" }]`. Each target is auto-detected as a file path or an HTTP/HTTPS URL. `symbols` is a string or string array. Markdown and HTML lookups return the section under the heading. Top-level `contextLines` and `callgraph` apply to every entry; callgraph adds calls-out and called-by annotations. Each failed lookup reports its own error line.", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "batch": { + "description": "One or more lookups; entries may mix file paths and URLs", + "minItems": 1, + "type": "array", + "items": { + "type": "object", + "properties": { + "target": { + "description": "File path (absolute or project-relative) or HTTP/HTTPS URL, auto-detected; issue://N or pr://N when GitHub reads are enabled", + "type": "string" + }, + "symbols": { + "description": "Symbol name for code or heading text for Markdown/HTML; a string or array of strings", + "anyOf": [ + { + "type": "string" + }, + { + "type": "array", + "items": { + "type": "string" + } + } + ] + } + }, + "required": [ + "target", + "symbols" + ] + } + }, + "contextLines": { + "description": "Lines of context before/after each symbol (default: 3)", + "type": "integer", + "minimum": 1, + "maximum": 9007199254740991 + }, + "callgraph": { + "description": "Include call-graph annotations for every entry (default: false)", + "type": "boolean" + } + }, + "required": [ + "batch" + ] + } + }, + { + "name": "inspect", + "schema_digest": "4e189e7662dd08cec4e8696bc215b3742a0ca5a5dd037de744f523c3707596aa", + "semantics": 1, + "modes": [ + "classic", + "codemode" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "code.diagnostics/v1" + ], + "description": "Codebase health inspection that waits for current analysis. FRESH means the reported analysis is current. PARTIAL means some diagnostics are unknown; the header names the analyzer, reason, and retry guidance. INTERRUPTED means the request stopped without a fresh snapshot; retry inspect. PHASE-FAILED means inspection could not finish; address the reported reason and retry, or narrow the scope. `sections` selects drill-down detail. Scoped requests collect diagnostics when sections is omitted or includes 'diagnostics' or 'all'; sections that leave diagnostics out skip diagnostics work. Unscoped requests keep warm diagnostics. Categories switched off in `inspect.categories` are not computed or refreshed, render as off, and never make the header PARTIAL.\n\nUse `scope=` to narrow all findings, counts, and examples to those paths. Cross-boundary duplicates are labeled as groups touching the scope. Scope also limits Rust analyzer startup to the Cargo workspaces owning those paths when diagnostics are requested. Files without an authoritative diagnostic report remain named gaps (complete: false), not a clean result.\n\nUse when: starting work on unfamiliar code, after multi-edit batches to check diagnostics, before a refactor, before review, or to verify cleanup completeness.\n\nTreat `dead_code` as a hint, not proof: reachability is call-based, so symbols reached only via method dispatch or referenced only in type position may be false positives — verify before deleting.\n\nWhen a list is cut, the reply ends with `shown N of M () · narrow: `; absence of that line means the list is complete.", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "sections": { + "description": "Categories to include in detailed drill-down (e.g. 'todos' or ['todos', 'dead_code', 'cycles']). Use 'all' for every active category. Omit for summary-only mode. With scope, listing sections without 'diagnostics' (or 'all') skips diagnostics work; omitting sections keeps diagnostics. Other categories are verified regardless of sections.", + "anyOf": [ + { + "type": "string" + }, + { + "type": "array", + "items": { + "type": "string" + } + } + ] + }, + "scope": { + "description": "Restrict returned results to paths under this scope (one path, or an array of paths — not a space-separated list; file or directory; absolute or relative to project root). `scope=` narrows results. Scoped requests collect diagnostics for the scoped files and report coverage gaps, unless sections lists other categories and leaves out 'diagnostics'.", + "anyOf": [ + { + "type": "string" + }, + { + "type": "array", + "items": { + "type": "string" + } + } + ] + }, + "offset": { + "description": "Rows to skip independently in each drill-down list. Default 0; follow next_offset in each list envelope.", + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + }, + "topK": { + "description": "Max drill-down items per category. Default 20, max 100.", + "type": "integer", + "exclusiveMinimum": 0, + "maximum": 100 + } + } + } + }, + { + "read_only": true, + "name": "callgraph", + "schema_digest": "cc1143512feeca2585bd922ab9047a00ef2496807a1307dac19e9047ae4e86de", + "semantics": 1, + "modes": [ + "classic", + "codemode", + "flow" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "code.callgraph/v1" + ], + "description": "Answer code-relationship questions from a real call graph — instead of grep + read chains. Reach for this whenever the question is about how symbols connect: who calls X, what X calls, what breaks if X changes, how execution reaches X, or how a value flows.\n\nUse zoom with `callgraph:true` for one-level forward calls-out while reading source. Use callgraph only for reverse callers or multi-level traces so you do not double-fetch the same relationships.\n\nOps:\n- 'callers': Find all call sites of a symbol. Use before renaming or changing a function's signature.\n- 'impact': What breaks if a symbol changes — affected callers with signatures and entry-point status (blast radius). Use before a risky edit.\n- 'call_tree': What a function calls (forward traversal). Use to understand a function's dependencies before modifying it.\n- 'trace_to': How execution reaches a function: each path of callers runs back to a root, labelled main, test, attribute, public API, or no caller found. Use to understand context around deeply-nested code.\n- 'trace_to_symbol': Shortest call path from one symbol to another. Requires 'toSymbol'. If multiple targets match, the error returns candidate files; retry with 'toPath' to disambiguate.\n- 'trace_data': Follow a value through variable assignments and function parameters across files. Requires 'symbol' (scope to trace from) and 'expression'.\n\nAll ops require both 'path' and 'symbol'. 'expression' is additionally required for trace_data; 'toSymbol' for trace_to_symbol.\n\nMarkers: ~ = edge resolved by name only (may point at the wrong same-named symbol); [unresolved] = callee not resolved to a definition, so the location shown is the call site. Unmarked edges are resolved exactly. By default, unresolved external/stdlib leaf calls in call_tree are collapsed into one summary per parent; pass includeUnresolved=true to show every unresolved edge individually.\n\nWhen a list is cut, the reply ends with `shown N of M () · narrow: `; absence of that line means the list is complete.\n", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "op": { + "description": "Navigation operation", + "type": "string", + "enum": [ + "call_tree", + "callers", + "trace_to", + "trace_to_symbol", + "impact", + "trace_data" + ] + }, + "path": { + "description": "Path to the source file containing the symbol (absolute or relative to project root)", + "type": "string" + }, + "symbol": { + "description": "Name of the symbol to analyze", + "type": "string" + }, + "depth": { + "description": "Max traversal depth (default: call_tree=5, callers=1, trace_to=10, trace_to_symbol=10 capped at 16, impact=5, trace_data=5)", + "type": "integer", + "minimum": 1, + "maximum": 9007199254740991 + }, + "expression": { + "description": "Expression to track through data flow (required for trace_data op)", + "type": "string" + }, + "toSymbol": { + "description": "Target symbol name for trace_to_symbol; the returned path ends at this symbol", + "type": "string" + }, + "toPath": { + "description": "Optional target file for trace_to_symbol; required when toSymbol exists in multiple files", + "type": "string" + }, + "includeTests": { + "description": "Include test files in callers/paths. Defaults to false; tests are hidden.", + "type": "boolean" + }, + "includeUnresolved": { + "description": "Show every unresolved external/stdlib call individually. Defaults to false; unresolved leaf calls are collapsed into one summary per parent.", + "type": "boolean" + } + }, + "required": [ + "op", + "path", + "symbol" + ] + } + }, + { + "read_only": true, + "name": "conflicts", + "schema_digest": "702d9af7c4449b1601b49d0b7d7573d150aa564430f9fc0c39e7af1dcea92d0c", + "semantics": 1, + "modes": [ + "classic", + "codemode" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "aft:git.conflicts/v1" + ], + "description": "Show all git merge conflicts across the repository — returns line-numbered conflict regions with context for every conflicted file in a single call. Conflicts are discovered from the git repository's top level. By default it inspects the session's project repository; pass `path` to inspect a different repository or git worktree (e.g. where a rebase/merge is running).", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "path": { + "description": "Optional path inside the git repository or worktree to inspect (absolute or relative to project root). Conflicts are discovered from that repository's top level. Defaults to the session project root.", + "type": "string" + } + } + } + }, + { + "read_only": true, + "name": "ast_search", + "schema_digest": "96463c1682f4d87f5216797bb29cc474cd88690a8c9469f1824d9d4b9faa0b35", + "semantics": 1, + "modes": [ + "classic", + "codemode" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "aft:code.ast_grep/v1" + ], + "description": "Search code patterns across filesystem using AST-aware matching. Supports 11 languages.\n\nUse meta-variables: $VAR matches a single AST node, $$$ matches multiple nodes (variadic).\nIMPORTANT: Patterns must be complete AST nodes (valid code fragments).\nFor functions, include params and body: 'export async function $NAME($$$) { $$$ }' not just 'export async function $NAME'.\n\nExamples: pattern='console.log($MSG)' lang='typescript', pattern='async function $NAME($$$) { $$$ }' lang='javascript', pattern='def $FUNC($$$): $$$' lang='python', pattern='Writeln($MSG);' lang='pascal', pattern='$X <- $Y' lang='r', pattern='[obj foo:$ARG]' lang='objc'", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "pattern": { + "description": "AST pattern with meta-variables ($VAR, $$$). Must be complete AST node.", + "type": "string" + }, + "lang": { + "description": "Target language", + "type": "string", + "enum": [ + "typescript", + "tsx", + "javascript", + "python", + "rust", + "go", + "cuda", + "metal", + "pascal", + "r", + "objc" + ] + }, + "paths": { + "description": "Paths to search (default: ['.'])", + "type": "array", + "items": { + "type": "string" + } + }, + "globs": { + "description": "Include/exclude globs (prefix ! to exclude)", + "type": "array", + "items": { + "type": "string" + } + }, + "contextLines": { + "description": "Number of context lines to show around each match", + "type": "integer", + "minimum": 1, + "maximum": 9007199254740991 + } + }, + "required": [ + "pattern", + "lang" + ] + } + }, + { + "name": "ast_replace", + "schema_digest": "86703537e883e53529c1045ee962ec1b062401108112606deffb16ff847892c9", + "semantics": 1, + "modes": [ + "classic", + "codemode" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "aft:code.ast_grep/v1" + ], + "description": "Replace code patterns across filesystem with AST-aware rewriting. Applies changes by default — set dryRun=true to preview.\n\nUse meta-variables in the rewrite pattern to preserve matched content from the pattern.\nIMPORTANT: Patterns must be complete AST nodes (valid code fragments).\n\nExample: pattern='console.log($MSG)' rewrite='logger.info($MSG)' lang='typescript' — replaces all console.log calls with logger.info across TypeScript files.\n\n**Warning: This tool modifies files directly.** Use dryRun=true to preview (shows per-file unified diff, capped at 8KB). Consider creating a safety checkpoint before bulk replacements.", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "pattern": { + "description": "AST pattern with meta-variables ($VAR, $$$). Must be complete AST node.", + "type": "string" + }, + "rewrite": { + "description": "Replacement pattern (can use $VAR from pattern)", + "type": "string" + }, + "lang": { + "description": "Target language", + "type": "string", + "enum": [ + "typescript", + "tsx", + "javascript", + "python", + "rust", + "go", + "cuda", + "metal", + "pascal", + "r", + "objc" + ] + }, + "paths": { + "description": "Paths to search (default: ['.'])", + "type": "array", + "items": { + "type": "string" + } + }, + "globs": { + "description": "Include/exclude globs (prefix ! to exclude)", + "type": "array", + "items": { + "type": "string" + } + }, + "dryRun": { + "description": "Preview changes without applying (default: false)", + "type": "boolean" + } + }, + "required": [ + "pattern", + "rewrite", + "lang" + ] + } + }, + { + "name": "delete", + "schema_digest": "07bc6db89f72b9f24d4386fe7f68607d66aaddb420215fcc2ed6d57ec478fc6f", + "semantics": 1, + "modes": [ + "classic", + "codemode" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "code.files/v1" + ], + "description": "Delete one or more files (or directories).\n\nEach file is backed up before deletion — use safety undo to recover any of them. A recursive delete backs up the whole tree: directories (empty ones too, with their permissions), file contents, hard links (relinked by undo) and symlinks (the link itself, never its target; restored exactly, even when dangling). Sockets are deleted but undo does not restore them, and a file hard-linked to paths outside the tree comes back as an independent copy; both are reported as warnings. Refused before anything is deleted: mount points of another filesystem, named pipes, device nodes, and symlinks undo cannot recreate exactly (non-UTF-8 target, or on Windows). Paths under the system temp directory are never backed up, so only mount points are refused there. The deleted file's contents stay in the undo store until its retention expires. A recursive delete whose backup would record more than 2,000 entries (files, directories and links) or copy 100 MiB in one call is refused before anything is deleted; delete such a tree in smaller pieces, or use bash `rm -rf` when no undo is needed. Directory deletion requires recursive: true. Without it, passing a directory returns an error.\n\nPartial success is allowed: deletable files are deleted; failed ones are reported in `skipped_files` with `complete: false`.", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "files": { + "description": "Paths to delete (one or more). May include directories when recursive=true.", + "minItems": 1, + "type": "array", + "items": { + "type": "string" + } + }, + "recursive": { + "description": "Required to delete a directory and its contents. Defaults to false; passing a directory without this returns an error.", + "type": "boolean" + } + }, + "required": [ + "files" + ] + } + }, + { + "name": "move", + "schema_digest": "f48d7c918c2557edb16221599142aee3d8fb52c2564866cdc37d4591ee5c1dad", + "semantics": 1, + "modes": [ + "classic", + "codemode" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "code.files/v1" + ], + "description": "Move or rename a file. Creates an undo backup before moving. Creates parent directories for destination automatically\nNote: This moves/renames whole files at the OS level; it does not relocate an individual symbol or rewrite imports.", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "path": { + "description": "Source file path to move (absolute or relative to project root)", + "type": "string" + }, + "destination": { + "description": "Destination file path (absolute or relative to project root)", + "type": "string" + } + }, + "required": [ + "path", + "destination" + ] + } + }, + { + "name": "import", + "schema_digest": "b52e0484b4abdaeb843b9738de9fd6927e229ca0337cacb87fb1e2cdcf24cbf4", + "semantics": 1, + "modes": [ + "classic", + "codemode" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "aft:code.imports/v1" + ], + "description": "Language-aware import management. Supports TS, JS, TSX, Python, Rust, Go, Solidity, Java, C#, PHP, Kotlin, Scala, Swift, Ruby, Lua, C, C++, Perl, and Vue.\n\nOps:\n- 'add': Add an import. Auto-detects group (stdlib/external/internal), deduplicates. Requires 'module'. Optional 'names', 'defaultImport', 'typeOnly'.\n- 'remove': Remove an import or a specific named import. Requires 'module'. Provide 'removeName' to remove a single named import; omit to remove the entire import.\n- 'organize': Re-sort and re-group all imports by language convention, deduplicate. Requires only 'path'. Use safety checkpoint/undo for recovery before broad cleanup.", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "op": { + "description": "Import operation", + "type": "string", + "enum": [ + "add", + "remove", + "organize" + ] + }, + "path": { + "description": "Path to the file (absolute or relative to project root)", + "type": "string" + }, + "module": { + "description": "Module path (required for add, remove — e.g. 'react', './utils', 'std::fmt')", + "type": "string" + }, + "names": { + "description": "Named imports to add. Each entry uses the language's native named-import text, including per-name aliasing where the language uses `as` (e.g. ['useState', 'debounce as db'], Solidity ['ERC20', 'IERC20 as IToken']).", + "type": "array", + "items": { + "type": "string" + } + }, + "defaultImport": { + "description": "Default import name, ES only (e.g. 'React')", + "type": "string" + }, + "namespace": { + "description": "Namespace binding: `import * as ns from 'mod'` (ES), `import * as N from \"./X.sol\"` (Solidity).", + "type": "string" + }, + "alias": { + "description": "Whole-module alias. Solidity: `import \"./X.sol\" as X` (module=path, alias=X).", + "type": "string" + }, + "modifiers": { + "description": "Statement-level modifier tokens, language-validated: Java/C# 'static'; C# 'global'/'unsafe'; Java/Kotlin/Scala 'wildcard'; Swift '@testable'. Unsupported tokens for the file's language return a clear error.", + "type": "array", + "items": { + "type": "string" + } + }, + "importKind": { + "description": "Symbol-kind-specific import: PHP 'function'/'const'; Swift 'struct'/'class'/'enum'/'protocol'/'func'; Scala 'given'.", + "type": "string" + }, + "typeOnly": { + "description": "Type-only import (TS only, default: false)", + "type": "boolean" + }, + "removeName": { + "description": "Named import to remove for 'remove' op; omit to remove entire import", + "type": "string" + }, + "validate": { + "description": "Validation level: 'syntax' (default) or 'full'. Syntax = tree-sitter parse check only. Full = also runs LSP type-checking (slower, catches more errors)", + "type": "string", + "enum": [ + "syntax", + "full" + ] + } + }, + "required": [ + "op", + "path" + ] + } + }, + { + "name": "safety", + "schema_digest": "15decddce4704d6bee2980603562727f50089c5abeb1f39a40aed33ce67bff54", + "semantics": 1, + "modes": [ + "classic", + "codemode" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "aft:safety/v1" + ], + "description": "File safety and recovery operations.\n\nPer-file undo stack is capped at 20 entries (oldest evicted).\n\nOps:\n- 'undo': Undo the entire last tool call when 'path' is omitted (typical), or undo the last edit to one file when 'path' is provided. Note: pops from the undo stack (irreversible, no redo). Use 'history' to inspect per-file history before undoing.\n- 'history': List all edit snapshots for a file. Requires 'path'.\n- 'checkpoint': Save a named snapshot (on disk across restarts; expires in 14 days; may contain secrets). Explicit files may be untracked/gitignored; omit for backup-tracked files. Requires 'name'.\n- 'restore': Restore files to a previously saved checkpoint. Optional 'path'/'files' scopes the restore; omitted scope restores the whole checkpoint. Requires 'name'.\n- 'list': List all available named checkpoints. No extra params needed.\n- 'purge': Permanently delete this session's undo backups and checkpoint copies of 'path' (a file, or everything under a directory); cannot be undone.\n\nEach op requires specific parameters — see parameter descriptions for requirements.\n\nUse checkpoint before risky multi-file changes. Use undo for quick single-file rollback.", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "op": { + "description": "Safety operation", + "type": "string", + "enum": [ + "undo", + "history", + "checkpoint", + "restore", + "list", + "purge" + ] + }, + "path": { + "description": "File path (required for history, optional for undo, optional for checkpoint — snapshots only that file when files is omitted, optional for restore — restores only that file, required for purge — a file or directory). Absolute or relative to project root", + "type": "string" + }, + "name": { + "description": "Checkpoint name (required for checkpoint, restore)", + "type": "string" + }, + "files": { + "description": "Specific files to include in checkpoint, or to restore from a checkpoint (optional; restore without path/files restores the whole checkpoint; explicit checkpoint files may be untracked or gitignored)", + "type": "array", + "items": { + "type": "string" + } + } + }, + "required": [ + "op" + ] + } + }, + { + "name": "bash_status", + "schema_digest": "d6a69ca626fb7e4e733a2e253e23deec542462ec598c417265f2846303c16f1c", + "semantics": 1, + "modes": [ + "classic", + "codemode" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "shell.exec/v1" + ], + "description": "Read-only snapshot of a background or PTY bash task's current state and output; a remote job ID works too. Returns immediately. Never waits. One look to check on a task is fine — never loop it to wait for completion. To wait, use bash_watch.", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "taskId": { + "description": "Background task ID returned by bash({ background: true }), e.g. bash-6b454047a1c39ded, or its remote job ID.", + "type": "string" + }, + "outputOffset": { + "description": "Read a bounded stdout/PTY byte page from this offset; returns masked text and the next byte offset.", + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + }, + "stderrOffset": { + "description": "Read a bounded stderr byte page from this offset; returns masked text and the next byte offset.", + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + }, + "outputMode": { + "description": "PTY output rendering mode. Defaults to screen for PTY tasks and preserves existing behavior for piped tasks when omitted.", + "type": "string", + "enum": [ + "screen", + "raw", + "both" + ] + } + }, + "required": [ + "taskId" + ] + } + }, + { + "name": "bash_watch", + "schema_digest": "f311ed43521271004ef01a1c1a87c8bb7b0bb38985b3bf02410061681f7dc935", + "semantics": 2, + "result_format": "tool-result/v1", + "capabilities": [ + "shell.exec/v1", + "call.yield/v1" + ], + "description": "Watch a background bash task and wait until it exits or prints a pattern; a remote job ID works too. Sync waits default to 30s in a main session (max `bash.watch_sync_max_ms`, 120s by default); in a delegated session a sync wait without a timeout waits up to the worker wait limit (`bash.worker_wait_max_ms`, 30 minutes by default), then reports it is still running; watch again to keep waiting. An explicit timeout never exceeds that worker limit. A background task never wakes you, so wait on it before you report a result. Call bash_watch again to keep waiting; don't report a result until the command finishes. Never loop bash_status to wait.", + "reply": { + "max_ms": 2040000 + }, + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "taskId": { + "description": "Background task ID returned by bash({ background: true }), or its remote job ID.", + "type": "string" + }, + "pattern": { + "description": "Substring or regex pattern. Optional in sync mode; required with background:true. Sync substring watches keep only the overlap tail needed for boundary matches; sync regex watches use a 64 KB rolling output window.", + "anyOf": [ + { + "type": "string" + }, + { + "type": "object", + "properties": { + "regex": { + "type": "string" + } + }, + "required": [ + "regex" + ] + } + ] + }, + "background": { + "description": "Accepted for compatibility. This watch always waits: a delegated session gets no async notification, so background: true waits up to the worker wait limit like a watch without a timeout.", + "type": "boolean" + }, + "timeoutMs": { + "description": "Sync-only timeout in milliseconds. In a main session: default 30000, max `bash.watch_sync_max_ms` (120000 by default). In a delegated session: omit it to wait up to the worker wait limit (`bash.worker_wait_max_ms`, 30 minutes by default), after which the watch reports the command is still running; a value you pass is clamped to that worker limit.", + "type": "integer", + "minimum": 1, + "maximum": 1800000 + }, + "deliver": { + "description": "Rejected: this watch always waits synchronously; deliver requires background:true with an async notification channel.", + "type": "string", + "const": "each_line" + }, + "once": { + "description": "Accepted for compatibility; only an async watch reads it.", + "type": "boolean" + } + }, + "required": [ + "taskId" + ] + } + }, + { + "name": "bash_kill", + "schema_digest": "96f37c924532b6490161c9f1075beb7ae617aaa659dc32fa324835125163373e", + "semantics": 1, + "modes": [ + "classic", + "codemode" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "shell.exec/v1" + ], + "description": "Terminate a running background bash task spawned with bash({ background: true }); a remote job ID works too. Returns confirmation of kill or an error if the task already finished.", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "taskId": { + "description": "Background task ID returned by bash({ background: true }), e.g. bash-6b454047a1c39ded, or its remote job ID.", + "type": "string" + } + }, + "required": [ + "taskId" + ] + } + }, + { + "name": "bash_write", + "schema_digest": "d5dd71a3c339a699a8a07a4f411e98c10210a04d47f6bfc10415e950f59c4496", + "semantics": 1, + "modes": [ + "classic", + "codemode" + ], + "result_format": "tool-result/v1", + "capabilities": [ + "shell.exec/v1" + ], + "description": "Write input bytes to a running PTY bash task. PTY-only; check bash_status reports mode: \"pty\" first. Input is either a string (verbatim bytes) or an array mixing strings and { key: \"esc\" | \"enter\" | \"up\" | \"ctrl-c\" | ... } objects for atomic text+key sequences such as [ \"iHello\", { key: \"esc\" }, \":wq\", { key: \"enter\" } ]. Named keys cover enter/return/tab/space/backspace/esc/escape, arrows, home/end/page-up/page-down/delete/insert, f1..f12, and ctrl-a..ctrl-z. Maximum 1 MiB per call (post-expansion).", + "input_schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "taskId": { + "description": "Background PTY task ID returned by bash({ pty: true, background: true }).", + "type": "string" + }, + "input": { + "description": "Either a string of verbatim bytes (e.g. 'print(1)\\n') OR an array mixing strings and { key: '' } objects for atomic text+key sequences. Example: [ 'iHello', { key: 'esc' }, ':wq', { key: 'enter' } ].", + "anyOf": [ + { + "type": "string" + }, + { + "type": "array", + "items": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "object", + "properties": { + "key": { + "description": "Named control key, e.g. 'esc', 'enter', 'up', 'ctrl-c'. Case-insensitive.", + "type": "string" + } + }, + "required": [ + "key" + ] + } + ] + } + } + ] + } + }, + "required": [ + "taskId", + "input" + ] + } + } + ], + "notice_templates": [ + { + "id": "aft.bash.code_search", + "text": "DO NOT search code by running grep/rg in {shell} — it is unindexed, unranked, and serial. {redirect}", + "slots": { + "redirect": { + "type": "enum", + "values": [ + "Use the `search` tool instead (it auto-routes concepts, identifiers, regex, and literals).", + "Use the `grep` tool instead (indexed and ranked)." + ] + }, + "shell": { + "type": "enum", + "values": [ + "bash", + "shell" + ] + } + } + }, + { + "id": "aft.bash.prefer_tool", + "text": "Prefer `{tool}` tool over {shell}.", + "slots": { + "shell": { + "type": "enum", + "values": [ + "bash", + "shell" + ] + }, + "tool": { + "type": "enum", + "values": [ + "glob", + "read", + "edit" + ] + } + } + }, + { + "id": "aft.repeat_call.identical", + "text": "This call ran {count} times with the same arguments and the same output in {span} s. It is not returning anything new. {instruction}", + "slots": { + "count": { + "type": "integer", + "min": 2, + "max": 1000 + }, + "instruction": { + "type": "enum", + "values": [ + "If you are waiting on a task or CI run, use a background task with a watch (or the background handle you already hold) and end the turn. If you are already watching, let the watch return before calling again.", + "The turn must end now with no further tool call. If you are waiting on a task or CI run, use a background task with a watch (or the background handle you already hold) and end the turn. If you are already watching, let the watch return before calling again.", + "If you are waiting on a task or CI run, wait with a watch on its background task (for example bash_watch on the task ID you already hold) instead of repeating this call. If you are already watching, let the watch return before calling again.", + "Stop now: make no further call with these arguments. If you are waiting on a task or CI run, wait with a watch on its background task (for example bash_watch on the task ID you already hold) instead of repeating this call. If you are already watching, let the watch return before calling again.", + "If you are waiting on a task or CI run, use bash_status on the task ID you already hold to inspect it, or bash_kill to stop it, instead of repeating this call.", + "Stop now: make no further call with these arguments. If you are waiting on a task or CI run, use bash_status on the task ID you already hold to inspect it, or bash_kill to stop it, instead of repeating this call." + ] + }, + "span": { + "type": "integer", + "min": 0, + "max": 86400 + } + } + }, + { + "id": "aft.repeat_call.drifting", + "text": "This call ran {count} times with the same arguments in {span} s, and only its output drifts (for example, a timestamp). {instruction}", + "slots": { + "count": { + "type": "integer", + "min": 2, + "max": 1000 + }, + "instruction": { + "type": "enum", + "values": [ + "If you are waiting on a task or CI run, use a background task with a watch (or the background handle you already hold) and end the turn. If you are already watching, let the watch return before calling again.", + "The turn must end now with no further tool call. If you are waiting on a task or CI run, use a background task with a watch (or the background handle you already hold) and end the turn. If you are already watching, let the watch return before calling again.", + "If you are waiting on a task or CI run, wait with a watch on its background task (for example bash_watch on the task ID you already hold) instead of repeating this call. If you are already watching, let the watch return before calling again.", + "Stop now: make no further call with these arguments. If you are waiting on a task or CI run, wait with a watch on its background task (for example bash_watch on the task ID you already hold) instead of repeating this call. If you are already watching, let the watch return before calling again.", + "If you are waiting on a task or CI run, use bash_status on the task ID you already hold to inspect it, or bash_kill to stop it, instead of repeating this call.", + "Stop now: make no further call with these arguments. If you are waiting on a task or CI run, use bash_status on the task ID you already hold to inspect it, or bash_kill to stop it, instead of repeating this call." + ] + }, + "span": { + "type": "integer", + "min": 0, + "max": 86400 + } + } + } + ], + "capabilities": { + "late_results": true + } +} diff --git a/test-vectors/aft-notice-templates-v1.1/worker.sends.json b/test-vectors/aft-notice-templates-v1.1/worker.sends.json new file mode 100644 index 0000000000..23f5be105b --- /dev/null +++ b/test-vectors/aft-notice-templates-v1.1/worker.sends.json @@ -0,0 +1,88 @@ +[ + { + "method": "session.send", + "params": { + "send_id": "aft:nudge:aft.bash.code_search:example-call", + "delivery": [ + "turn_system_cleared", + "tool_result" + ], + "dedupe_key": "aft:nudge:aft.bash.code_search", + "expires_at_ms": 1700000060000, + "template": { + "id": "aft.bash.code_search", + "digest": "43f3caebf95698c12db9681aeeb90600f1cf8664b6b7cc282f4ef9499071c9ad", + "slots": { + "shell": "bash", + "redirect": "Use the `search` tool instead (it auto-routes concepts, identifiers, regex, and literals)." + } + }, + "notice": true + } + }, + { + "method": "session.send", + "params": { + "send_id": "aft:nudge:aft.bash.prefer_tool:example-call", + "delivery": [ + "turn_system_cleared", + "tool_result" + ], + "dedupe_key": "aft:nudge:aft.bash.prefer_tool", + "expires_at_ms": 1700000060000, + "template": { + "id": "aft.bash.prefer_tool", + "digest": "3d406a218b3d6d9a37a134c4cf5293559837b014187f2efb03bb448f7d455663", + "slots": { + "tool": "read", + "shell": "bash" + } + }, + "notice": true + } + }, + { + "method": "session.send", + "params": { + "send_id": "aft:nudge:aft.repeat_call.identical:example-call", + "delivery": [ + "turn_system_cleared", + "tool_result" + ], + "dedupe_key": "aft:nudge:aft.repeat_call.identical", + "expires_at_ms": 1700000060000, + "template": { + "id": "aft.repeat_call.identical", + "digest": "5ad948cda47d6ccacb45ea7279d425d0d821bc2eee060fefab7862b2820a1c03", + "slots": { + "count": 3, + "span": 42, + "instruction": "If you are waiting on a task or CI run, wait with a watch on its background task (for example bash_watch on the task ID you already hold) instead of repeating this call. If you are already watching, let the watch return before calling again." + } + }, + "notice": true + } + }, + { + "method": "session.send", + "params": { + "send_id": "aft:nudge:aft.repeat_call.drifting:example-call", + "delivery": [ + "turn_system_cleared", + "tool_result" + ], + "dedupe_key": "aft:nudge:aft.repeat_call.drifting", + "expires_at_ms": 1700000060000, + "template": { + "id": "aft.repeat_call.drifting", + "digest": "eb8733fe3db66d83a310fbe43f6e976ddc4b35d3243794e3fe7ed07af32df9c7", + "slots": { + "count": 3, + "span": 42, + "instruction": "If you are waiting on a task or CI run, wait with a watch on its background task (for example bash_watch on the task ID you already hold) instead of repeating this call. If you are already watching, let the watch return before calling again." + } + }, + "notice": true + } + } +] From 7a9c53c41bf5846442209bc58b04e3eedc1bc9d4 Mon Sep 17 00:00:00 2001 From: ualtinok <94532+ualtinok@users.noreply.github.com> Date: Wed, 18 Nov 2026 17:27:03 +0100 Subject: [PATCH 20/26] mason: disable automatic Git maintenance in publication fixture Git 2.54 may launch overlapping detached repacks when the fixture quickly commits a copy of the entire checkout and then a train edit. Keep maintenance disabled only in this disposable repository. Check the Git trace of a fixture commit so the regression does not depend on winning the repack race. Co-authored-by: alfonso-aft <289616620+alfonso-aft@users.noreply.github.com> --- .../__tests__/governed-publication.test.ts | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/packages/opencode-plugin/src/__tests__/governed-publication.test.ts b/packages/opencode-plugin/src/__tests__/governed-publication.test.ts index 7424b2b1fe..ec95245301 100644 --- a/packages/opencode-plugin/src/__tests__/governed-publication.test.ts +++ b/packages/opencode-plugin/src/__tests__/governed-publication.test.ts @@ -17,11 +17,12 @@ import { delimiter, dirname, join, resolve } from "node:path"; const root = resolve(import.meta.dir, "../../../.."); const gate = "scripts/release-gate-v049.mjs"; const manifest = "v0.49-agent-surface-manifest.json"; +const maintenanceTrace = ".git/fixture-maintenance.jsonl"; const surfaceA = "packages/opencode-plugin/src/tools/reading.ts"; const surfaceB = "packages/pi-plugin/src/tools/reading.ts"; let fixture: string; -function command(cwd: string, program: string, args: string[]) { +function command(cwd: string, program: string, args: string[], env: NodeJS.ProcessEnv = {}) { const result = spawnSync( program, program === "git" ? ["-c", `safe.directory=${cwd}`, ...args] : args, @@ -30,6 +31,7 @@ function command(cwd: string, program: string, args: string[]) { encoding: "utf8", env: { ...process.env, + ...env, BUN_BIN: process.execPath, GIT_CONFIG_GLOBAL: "/dev/null", GIT_CONFIG_NOSYSTEM: "1", @@ -81,6 +83,9 @@ beforeAll(() => { git("config", "user.name", "Publication test"); git("config", "user.email", "publication-test@example.invalid"); git("config", "commit.gpgsign", "false"); + // Rapid fixture commits can launch overlapping detached repacks, making + // objects unreadable while the publication gate checks their ancestry. + git("config", "maintenance.auto", "false"); // Use a sparse, distinct previous-release fixture so the tests work in a // shallow checkout. Production gates still require the real release tag. for (const [path, bytes] of [ @@ -91,7 +96,13 @@ beforeAll(() => { writeFileSync(join(fixture, path), bytes); } git("add", "."); - git("commit", "--allow-empty", "-qm", "previous-release surface bytes"); + const initial = command( + fixture, + "git", + ["commit", "--allow-empty", "-qm", "previous-release surface bytes"], + { GIT_TRACE2_EVENT: join(fixture, maintenanceTrace) }, + ); + expect(initial.status, initial.output).toBe(0); git("tag", "v0.48.1"); const tracked = command(root, "git", ["ls-files", "-z"]); expect(tracked.status, tracked.output).toBe(0); @@ -126,6 +137,19 @@ afterAll(() => { }); describe("governed publication", () => { + test("fixture commits do not start automatic Git maintenance", () => { + const trace = readFileSync(join(fixture, maintenanceTrace), "utf8").trim(); + const events = trace.split("\n").map((line) => JSON.parse(line)); + expect(events).toContainEqual(expect.objectContaining({ event: "cmd_name", name: "commit" })); + const maintenance = events.filter( + (entry) => + entry.event === "child_start" && + entry.argv?.includes("--auto") && + (entry.argv.includes("maintenance") || entry.argv.includes("gc")), + ); + expect(maintenance).toEqual([]); + }); + test("independent trains merge without generated commits or regeneration", () => { for (const [branch, path] of [ ["train/first", surfaceA], From f577d56af3647192d277411510e0a185f199d94c Mon Sep 17 00:00:00 2001 From: ualtinok <94532+ualtinok@users.noreply.github.com> Date: Wed, 18 Nov 2026 18:03:14 +0100 Subject: [PATCH 21/26] test: pin subc-protocol 0.37.4 in launch provenance tests; confine catalog golden gains read_only marks The 0.37.4 bump changes the wire crate version AFT reports in HELLO provenance, and tool-provider 0.15.12 marks the read tools read_only in the confined catalog. Regenerated on Linux with AFT_REGENERATE_CONFINE_VECTORS=1; only catalog-reply.json changed (four read_only marks and its digest). Co-authored-by: alfonso-aft <289616620+alfonso-aft@users.noreply.github.com> --- crates/aft/src/launch_nonce.rs | 8 ++++---- crates/aft/tests/fixtures/confine/catalog-reply.json | 8 ++++++-- crates/aft/tests/integration/subc_launch_nonce_test.rs | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/crates/aft/src/launch_nonce.rs b/crates/aft/src/launch_nonce.rs index c836b4e4b3..59b6b1d162 100644 --- a/crates/aft/src/launch_nonce.rs +++ b/crates/aft/src/launch_nonce.rs @@ -261,7 +261,7 @@ mod tests { let declared = build_facts(Some("not-a-git-sha")) .with_launch_nonce_source(Some(LaunchNonceSource::Fd)); assert_eq!(declared.build_git_sha, None); - assert_eq!(declared.wire_crate_version.as_deref(), Some("0.37.2")); + assert_eq!(declared.wire_crate_version.as_deref(), Some("0.37.4")); assert_eq!(declared.launch_nonce_source, Some(LaunchNonceSource::Fd)); } @@ -270,7 +270,7 @@ mod tests { let _serial = serial(); let _none = install_for_tests(None); let assert_build_facts = |declared: &ManifestProvenance| { - assert_eq!(declared.wire_crate_version.as_deref(), Some("0.37.2")); + assert_eq!(declared.wire_crate_version.as_deref(), Some("0.37.4")); assert_eq!( declared.build_git_sha, None, "the library has no binary startup revision" @@ -299,7 +299,7 @@ mod tests { ); assert_eq!( declaration.declared().wire_crate_version.as_deref(), - Some("0.37.2") + Some("0.37.4") ); assert!(!declaration.initialize(Some(&"b".repeat(40)))); assert_eq!( @@ -316,7 +316,7 @@ mod tests { assert_eq!(declaration.declared().build_git_sha, None); assert_eq!( declaration.declared().wire_crate_version.as_deref(), - Some("0.37.2") + Some("0.37.4") ); } diff --git a/crates/aft/tests/fixtures/confine/catalog-reply.json b/crates/aft/tests/fixtures/confine/catalog-reply.json index 04e900d393..c5d3df0f99 100644 --- a/crates/aft/tests/fixtures/confine/catalog-reply.json +++ b/crates/aft/tests/fixtures/confine/catalog-reply.json @@ -1,8 +1,9 @@ { - "generation": "59ff402e31959b3612048411ed521bda1926786a71bd418768992ed53a3c5700", - "catalog_digest": "59ff402e31959b3612048411ed521bda1926786a71bd418768992ed53a3c5700", + "generation": "b3f4d9f56b21f491aeebf8c00d1cf08007a8e915edef85ca7d1290f5443d63e3", + "catalog_digest": "b3f4d9f56b21f491aeebf8c00d1cf08007a8e915edef85ca7d1290f5443d63e3", "tools": [ { + "read_only": true, "name": "read", "schema_digest": "f9ef88233ec21e9968187fd84526076c5853cb62d8397721b76ae8bd0a229f00", "semantics": 1, @@ -59,6 +60,7 @@ } }, { + "read_only": true, "name": "grep", "schema_digest": "0f7a077fe3aee4e28d4cdebb8093776db34692c342ef3b67c3b9e49fe7c31f19", "semantics": 1, @@ -98,6 +100,7 @@ } }, { + "read_only": true, "name": "glob", "schema_digest": "f0710f894a9c43ff7709e5f5cb63c37f7cda4e969840379f728a6d55f353a659", "semantics": 1, @@ -128,6 +131,7 @@ } }, { + "read_only": true, "name": "aft_outline", "schema_digest": "264536293f3baca10d5e6b695baf9a29f71ea74b7e4241ceaed26e3b46e165cf", "semantics": 1, diff --git a/crates/aft/tests/integration/subc_launch_nonce_test.rs b/crates/aft/tests/integration/subc_launch_nonce_test.rs index 5f8c99908c..0439e585e0 100644 --- a/crates/aft/tests/integration/subc_launch_nonce_test.rs +++ b/crates/aft/tests/integration/subc_launch_nonce_test.rs @@ -167,7 +167,7 @@ fn subc_module_reads_the_pipe_nonce_and_no_child_inherits_it() { assert_eq!( manifest["provenance"]["wire_crate_version"], - json!("0.37.2") + json!("0.37.4") ); // Binary builders may provide a revision explicitly. Ordinary Cargo // builds omit it; the nonce and child checks do not depend on provenance. From 6395f5604f614b4f89f7f7be0e34b2e10b7bc00e Mon Sep 17 00:00:00 2001 From: ualtinok <94532+ualtinok@users.noreply.github.com> Date: Wed, 18 Nov 2026 18:04:38 +0100 Subject: [PATCH 22/26] bench: batch 18 search-quality descriptor (engine_unwired: semantic_index.rs ONNX install and hint move only) Co-authored-by: alfonso-aft <289616620+alfonso-aft@users.noreply.github.com> --- .../ci-speed-post066-batch-18.json | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 benchmarks/aft-search/slice-descriptors/ci-speed-post066-batch-18.json diff --git a/benchmarks/aft-search/slice-descriptors/ci-speed-post066-batch-18.json b/benchmarks/aft-search/slice-descriptors/ci-speed-post066-batch-18.json new file mode 100644 index 0000000000..e9b3bbc32a --- /dev/null +++ b/benchmarks/aft-search/slice-descriptors/ci-speed-post066-batch-18.json @@ -0,0 +1,102 @@ +{ + "slice_class": "engine_unwired", + "targeted_mechanism": "none", + "kind": "harness", + "fixtures": [ + "crates/aft/src/semantic_index.rs", + "crates/aft/tests/integration/tool_call_parity_test.rs" + ], + "pattern_counts": { + "followup-census:910002": { + "candidate_files": { + "before": 3, + "after": 6 + }, + "files_examined": { + "before": 3, + "after": 6 + } + }, + "followup-census:910003": { + "candidate_files": { + "before": 972, + "after": 860 + }, + "files_examined": { + "before": 972, + "after": 860 + } + }, + "followup-census:910004": { + "candidate_files": { + "before": 972, + "after": 860 + }, + "files_examined": { + "before": 972, + "after": 860 + } + }, + "followup-census:910005": { + "candidate_files": { + "before": 194, + "after": 141 + }, + "files_examined": { + "before": 194, + "after": 141 + } + }, + "followup-census:910010": { + "candidate_files": { + "before": 6, + "after": 19 + }, + "files_examined": { + "before": 6, + "after": 19 + } + }, + "followup-census:910011": { + "candidate_files": { + "before": 942, + "after": 729 + }, + "files_examined": { + "before": 942, + "after": 729 + } + }, + "followup-census:910012": { + "candidate_files": { + "before": 1031, + "after": 730 + }, + "files_examined": { + "before": 1031, + "after": 730 + } + }, + "followup-census:910013": { + "candidate_files": { + "before": 908, + "after": 45 + }, + "files_examined": { + "before": 908, + "after": 45 + } + }, + "followup-census:910014": { + "candidate_files": { + "before": 1011, + "after": 24 + }, + "files_examined": { + "before": 1011, + "after": 24 + } + } + }, + "note": "Batch 18's only ranking-fence change is in semantic_index.rs, and it doesn't touch ranking. ONNX Runtime now installs from Microsoft's NuGet package (the GitHub download is gone), and the runtime-mismatch hint text moved into its own submodule with the approved new links. No embedding, chunking or scoring code changed, and no tool-call parity fixture changed. Every ranked row must remain byte-equal. The declared pattern-count transitions are inherited, not caused by this batch: the committed reference still records the older pattern-lane counts for nine followup-census rows, and main produces the new ones. They are the transitions ci-speed-post066-batch-17.json declared." +} From 9beec4479ff1bdf79781a9b0831cad5fdd9d1eca Mon Sep 17 00:00:00 2001 From: ualtinok <94532+ualtinok@users.noreply.github.com> Date: Wed, 18 Nov 2026 18:53:03 +0100 Subject: [PATCH 23/26] sandbox: let macOS workers run the build-slot launcher and follow sibling links Batch 17 limited a macOS worker's reads in the worker pool to its own checkout. Two things the worker system places beside every checkout broke: - The build-slot launcher (worktrees/.build-slots/prefrontal-build-slot), which every worktree's Cargo config names as the rustc wrapper. The exact grant for it expected `.root`/`.cache` files beside it, matched nothing in the launcher's real layout, and granted nothing, so every Rust build in a Mac mason failed with "Operation not permitted". The launcher's directory is now read recursively (the wrapper itself is still listed exactly, which the strict profile's RUSTC_WRAPPER restore looks for), and only its queue and slot locks are writable. The directory goes in a new `read_dirs` list, kept out of the shell write-deny list so the lock grants inside it hold. - The sibling-repository links in the checkout's container folder (`../subconscious`). Their targets were readable, but the lookup stopped at the link in the denied container. Each link's own metadata is now readable; the sandbox still checks the target, so a link into another worker's checkout reads nothing. The launcher code moves to sandbox_spawn/build_slots.rs, and the sandbox_spawn.rs pin drops from 10797 to 10719. Native macOS worker_jail test covers prefrontal's real layout, a sibling link and a link into another worker; 156 Linux sandbox tests and the Windows check pass. Co-authored-by: alfonso-aft <289616620+alfonso-aft@users.noreply.github.com> --- crates/aft/src/sandbox_spawn.rs | 172 +---------------- crates/aft/src/sandbox_spawn/build_slots.rs | 183 +++++++++++++++++++ crates/aft/src/sandbox_spawn/worker_reads.rs | 79 +++++++- crates/aft/tests/worker_jail.rs | 33 +++- scripts/file-size-pins.json | 2 +- 5 files changed, 298 insertions(+), 171 deletions(-) create mode 100644 crates/aft/src/sandbox_spawn/build_slots.rs diff --git a/crates/aft/src/sandbox_spawn.rs b/crates/aft/src/sandbox_spawn.rs index b33dd7aaf0..a09885a99c 100644 --- a/crates/aft/src/sandbox_spawn.rs +++ b/crates/aft/src/sandbox_spawn.rs @@ -62,6 +62,10 @@ mod settings_grants; mod task_temp; #[cfg(unix)] mod worker_reads; +#[cfg(unix)] +mod build_slots; +#[cfg(unix)] +use build_slots::add_build_slot_grants; pub(crate) use requirement::{resolve_command_sandbox_spawn, SandboxRequirement}; #[cfg(unix)] use settings_grants::absolute_env_path; @@ -1971,7 +1975,7 @@ fn build_native_profile( policy .private_stores .read_allow - .extend(jail.read_only.iter().cloned()); + .extend(jail.read_only.iter().chain(&jail.read_dirs).cloned()); policy .private_stores .read_allow @@ -2840,6 +2844,11 @@ struct WorkerJailGrants { files: Vec, /// Cargo configuration, .rust-build-seeds, and immutable compiler launcher files. read_only: Vec, + /// Directories read recursively but left out of the shell's write-deny + /// list, because exact `files` grants inside them must stay writable: the + /// build-slot launcher's directory, whose lock files a build opens. They + /// sit in a private store, whose own deny already blocks other writes. + read_dirs: Vec, } /// Cargo's lock and global-cache tracking files at the root of CARGO_HOME. The @@ -2940,93 +2949,6 @@ fn worker_jail_grants( grants } -/// Retain only the operator-configured `prefrontal-build-slot` launcher and its -/// `rustc-lowprio-direct` companion: they take a slot lock and compile inside -/// the sandbox rather than asking a shared server. The Cargo configuration and -/// launcher files must be outside every model-writable worktree. -#[cfg(unix)] -fn add_build_slot_grants( - wrapper: &Path, - project_roots: &[PathBuf], - policy: &crate::access_policy::AccessPolicy, - grants: &mut WorkerJailGrants, -) { - let Ok(wrapper) = canonicalize_profile_candidate(wrapper) else { - return; - }; - if wrapper.file_name() != Some(OsStr::new("prefrontal-build-slot")) - || !profile_candidate_is_file(&wrapper) - { - return; - } - let Some(dir) = wrapper.parent() else { - return; - }; - if project_roots - .iter() - .any(|root| root.starts_with(dir) || dir.starts_with(root)) - || !policy - .private_stores - .deny - .iter() - .any(|deny| dir.starts_with(deny) && dir != deny) - { - return; - } - let paths = [ - wrapper.clone(), - dir.join("rustc-lowprio-direct"), - dir.join(".root"), - dir.join(".cache"), - dir.join("limit"), - ]; - let Ok(paths) = paths - .into_iter() - .map(|path| path.canonicalize()) - .collect::, _>>() - else { - return; - }; - if paths - .iter() - .any(|path| !profile_candidate_is_file(path) || !path.starts_with(dir)) - { - return; - } - let Some(limit) = std::fs::read_to_string(dir.join("limit")) - .ok() - .and_then(|value| value.trim().parse::().ok()) - .filter(|limit| (1..=256).contains(limit)) - else { - return; - }; - // Landlock's single-file grants require existing inodes. Provision only - // the configured queue and slot locks, never a writable directory grant. - // Include both endpoints so zero-based and one-based slot numbering work. - let locks = std::iter::once(dir.join("queue.lock")) - .chain((0..=limit).map(|slot| dir.join(format!("{slot}.lock")))); - let mut files = Vec::new(); - for path in locks { - if std::fs::symlink_metadata(&path) - .is_ok_and(|metadata| !metadata.is_file() || metadata.file_type().is_symlink()) - { - return; - } - if std::fs::OpenOptions::new() - .write(true) - .create(true) - .truncate(false) - .open(&path) - .is_err() - { - return; - } - files.push(path); - } - grants.files.extend(files); - grants.read_only.extend(paths); -} - /// A linked worktree's own Git directory and its main repository's shared /// object, ref and log stores: what `git add` and `git commit` write. The /// shared `config`, hooks, `info` and other worktrees' entries are left out. @@ -10849,80 +10771,6 @@ mod policy_tests { assert!(bound.is_ok(), "cannot bind {}: {bound:?}", socket.display()); } - #[cfg(unix)] - #[test] - fn worker_build_slot_grants_are_exact_and_reject_model_writable_launchers() { - let dir = tempfile::tempdir().unwrap(); - let home = dir.path().canonicalize().unwrap(); - let store = home.join(".local/share/cortexkit"); - let project = store.join("alfonso/worktrees/container/own"); - let slots = store.join("operator/build-slots"); - for path in [&project, &slots] { - std::fs::create_dir_all(path).unwrap(); - } - for name in [ - "prefrontal-build-slot", - "rustc-lowprio-direct", - ".root", - ".cache", - ] { - std::fs::write(slots.join(name), "operator-owned").unwrap(); - } - std::fs::write(slots.join("limit"), "2\n").unwrap(); - let policy = crate::access_policy::AccessPolicy::from_config( - &crate::config::Config::default(), - &store.join("aft"), - vec![project.clone()], - &home, - ); - let mut grants = WorkerJailGrants::default(); - add_build_slot_grants( - &slots.join("prefrontal-build-slot"), - &[project.clone()], - &policy, - &mut grants, - ); - assert_eq!( - grants.files, - ["queue.lock", "0.lock", "1.lock", "2.lock"].map(|name| slots.join(name)) - ); - assert_eq!(grants.read_only.len(), 5); - assert!(grants.roots.is_empty() && grants.caches.is_empty()); - assert!(grants - .read_only - .iter() - .all(|path| path.is_file() && path.parent() == Some(slots.as_path()))); - let mut refused = WorkerJailGrants::default(); - add_build_slot_grants( - &slots.join("prefrontal-build-slot"), - &[slots.clone()], - &policy, - &mut refused, - ); - assert_eq!( - refused, - WorkerJailGrants::default(), - "a model-writable launcher must never be pinned" - ); - #[cfg(unix)] - { - std::fs::remove_file(slots.join(".root")).unwrap(); - std::fs::write(home.join("secret"), "secret").unwrap(); - std::os::unix::fs::symlink(home.join("secret"), slots.join(".root")).unwrap(); - add_build_slot_grants( - &slots.join("prefrontal-build-slot"), - &[project], - &policy, - &mut refused, - ); - assert_eq!( - refused, - WorkerJailGrants::default(), - "a sibling symlink must not widen the read exception" - ); - } - } - fn context(project_root: PathBuf) -> AppContext { AppContext::new( Box::new(crate::parser::TreeSitterProvider::new()), diff --git a/crates/aft/src/sandbox_spawn/build_slots.rs b/crates/aft/src/sandbox_spawn/build_slots.rs new file mode 100644 index 0000000000..bb0065d20c --- /dev/null +++ b/crates/aft/src/sandbox_spawn/build_slots.rs @@ -0,0 +1,183 @@ +//! Read and lock grants for the operator-configured `prefrontal-build-slot` +//! rustc wrapper, which jailed workers run for every Rust build. + +use std::ffi::OsStr; +use std::path::{Path, PathBuf}; + +use super::{canonicalize_profile_candidate, profile_candidate_is_file, WorkerJailGrants}; + +/// Retain only the operator-configured `prefrontal-build-slot` launcher's +/// directory: the launcher and its `rustc-lowprio-direct` companion take a +/// slot lock and compile inside the sandbox rather than asking a shared +/// server. The Cargo configuration and launcher directory must be outside +/// every model-writable worktree and inside a private store, where no jailed +/// shell can write. +/// +/// The directory is read recursively rather than file by file: the launcher +/// reads its own metadata files (named by the launcher, such as +/// `prefrontal-build-slot.root`), and an exact list that drifts from the +/// launcher's layout fails every Rust build in a jailed worker. The sandbox +/// checks a symlink's target, so a link inside the directory grants nothing +/// outside it. Only the queue and slot locks are writable, file by file, so +/// the directory goes in `read_dirs`, not in the write-denied `read_only`. +pub(super) fn add_build_slot_grants( + wrapper: &Path, + project_roots: &[PathBuf], + policy: &crate::access_policy::AccessPolicy, + grants: &mut WorkerJailGrants, +) { + let Ok(wrapper) = canonicalize_profile_candidate(wrapper) else { + return; + }; + if wrapper.file_name() != Some(OsStr::new("prefrontal-build-slot")) + || !profile_candidate_is_file(&wrapper) + { + return; + } + let Some(dir) = wrapper.parent() else { + return; + }; + if project_roots + .iter() + .any(|root| root.starts_with(dir) || dir.starts_with(root)) + || !policy + .private_stores + .deny + .iter() + .any(|deny| dir.starts_with(deny) && dir != deny) + { + return; + } + let paths = [ + wrapper.clone(), + dir.join("rustc-lowprio-direct"), + dir.join("limit"), + ]; + let Ok(paths) = paths + .into_iter() + .map(|path| path.canonicalize()) + .collect::, _>>() + else { + return; + }; + if paths + .iter() + .any(|path| !profile_candidate_is_file(path) || !path.starts_with(dir)) + { + return; + } + let Some(limit) = std::fs::read_to_string(dir.join("limit")) + .ok() + .and_then(|value| value.trim().parse::().ok()) + .filter(|limit| (1..=256).contains(limit)) + else { + return; + }; + // Landlock's single-file grants require existing inodes. Provision only + // the configured queue and slot locks, never a writable directory grant. + // Include both endpoints so zero-based and one-based slot numbering work. + let locks = std::iter::once(dir.join("queue.lock")) + .chain((0..=limit).map(|slot| dir.join(format!("{slot}.lock")))); + let mut files = Vec::new(); + for path in locks { + if std::fs::symlink_metadata(&path) + .is_ok_and(|metadata| !metadata.is_file() || metadata.file_type().is_symlink()) + { + return; + } + if std::fs::OpenOptions::new() + .write(true) + .create(true) + .truncate(false) + .open(&path) + .is_err() + { + return; + } + files.push(path); + } + grants.files.extend(files); + // The wrapper's own path also goes in exactly: a strict sandbox empties + // RUSTC_WRAPPER and restores only a `prefrontal-build-slot` path it finds + // listed read-only (see the sandboxed child environment). + grants.read_only.push(wrapper.clone()); + grants.read_dirs.push(dir.to_path_buf()); +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn worker_build_slot_grants_read_the_launcher_directory_and_reject_model_writable_launchers() { + let dir = tempfile::tempdir().unwrap(); + let home = dir.path().canonicalize().unwrap(); + let store = home.join(".local/share/cortexkit"); + let project = store.join("alfonso/worktrees/container/own"); + // Prefrontal's layout: the launcher sits beside the worktree + // containers and names its own metadata files after itself. + let slots = store.join("alfonso/worktrees/.build-slots"); + for path in [&project, &slots] { + std::fs::create_dir_all(path).unwrap(); + } + for name in [ + "prefrontal-build-slot", + "rustc-lowprio-direct", + "prefrontal-build-slot.root", + "prefrontal-build-slot.cache", + ] { + std::fs::write(slots.join(name), "operator-owned").unwrap(); + } + std::fs::write(slots.join("limit"), "2\n").unwrap(); + let policy = crate::access_policy::AccessPolicy::from_config( + &crate::config::Config::default(), + &store.join("aft"), + vec![project.clone()], + &home, + ); + let mut grants = WorkerJailGrants::default(); + add_build_slot_grants( + &slots.join("prefrontal-build-slot"), + &[project.clone()], + &policy, + &mut grants, + ); + assert_eq!( + grants.files, + ["queue.lock", "0.lock", "1.lock", "2.lock"].map(|name| slots.join(name)) + ); + assert_eq!(grants.read_only, [slots.join("prefrontal-build-slot")]); + assert_eq!(grants.read_dirs, [slots.clone()]); + assert!(grants.roots.is_empty() && grants.caches.is_empty()); + let mut refused = WorkerJailGrants::default(); + add_build_slot_grants( + &slots.join("prefrontal-build-slot"), + &[slots.clone()], + &policy, + &mut refused, + ); + assert_eq!( + refused, + WorkerJailGrants::default(), + "a model-writable launcher must never be pinned" + ); + #[cfg(unix)] + { + std::fs::remove_file(slots.join("rustc-lowprio-direct")).unwrap(); + std::fs::write(home.join("secret"), "secret").unwrap(); + std::os::unix::fs::symlink(home.join("secret"), slots.join("rustc-lowprio-direct")) + .unwrap(); + add_build_slot_grants( + &slots.join("prefrontal-build-slot"), + &[project], + &policy, + &mut refused, + ); + assert_eq!( + refused, + WorkerJailGrants::default(), + "a companion that links outside the launcher directory must not be pinned" + ); + } + } +} diff --git a/crates/aft/src/sandbox_spawn/worker_reads.rs b/crates/aft/src/sandbox_spawn/worker_reads.rs index 4f7c93fdf0..1a3689e618 100644 --- a/crates/aft/src/sandbox_spawn/worker_reads.rs +++ b/crates/aft/src/sandbox_spawn/worker_reads.rs @@ -142,7 +142,9 @@ pub(super) fn worker_target_roots( /// Adds a macOS worker's read-only exceptions above its own checkout to a data /// policy: the exact Cargo and container files, and the `.rust-build-seeds` /// directories (prebuilt dependency outputs a new worktree's build copies from) -/// read recursively. Each path is also denied for writing. +/// read recursively. Each path is also denied for writing. The links beside +/// the checkout get metadata reads only, so lookups can follow them (see +/// [`worker_container_links`]). #[cfg(any(target_os = "macos", test))] #[cfg_attr(not(target_os = "macos"), allow(dead_code))] pub(super) fn grant_worker_pool_reads( @@ -157,6 +159,57 @@ pub(super) fn grant_worker_pool_reads( let dirs = worker_pool_read_dirs(home, roots); stores.read_allow.extend(dirs.iter().cloned()); write_deny.extend(dirs); + stores + .read_metadata_allow + .extend(worker_container_links(home, roots)); +} + +/// How many entries of a container folder are examined for links. A +/// container holds one repository's worktrees and the links beside them, so +/// this bound only stops a pathological folder from slowing every launch. +#[cfg(any(target_os = "macos", test))] +const CONTAINER_ENTRY_LIMIT: usize = 4096; + +/// The symbolic links in each checkout's container folder, such as the +/// sibling-repository links the worker system places beside every worktree +/// (`../subconscious`). The container is denied, so a lookup through a link +/// stops at the link itself unless its own metadata is readable. Granting the +/// link's metadata grants nothing else: the sandbox still checks the link's +/// target, so a link into another worker's checkout or a protected folder +/// stays unreadable. +#[cfg(any(target_os = "macos", test))] +fn worker_container_links(home: &Path, roots: &[PathBuf]) -> Vec { + let mut links = Vec::new(); + for data in [ + Some(home.join(".local/share")), + absolute_env_path("XDG_DATA_HOME"), + ] + .into_iter() + .flatten() + { + let Ok(pool) = canonicalize_profile_candidate(&data.join("cortexkit/alfonso/worktrees")) + else { + continue; + }; + for root in roots { + let Some(container) = root.parent().filter(|dir| dir.starts_with(&pool)) else { + continue; + }; + let Ok(entries) = std::fs::read_dir(container) else { + continue; + }; + links.extend( + entries + .take(CONTAINER_ENTRY_LIMIT) + .filter_map(Result::ok) + .filter(|entry| entry.file_type().is_ok_and(|kind| kind.is_symlink())) + .map(|entry| entry.path()), + ); + } + } + links.sort_unstable(); + links.dedup(); + links } /// Every name a jailed worker may read in its checkout's container folder: @@ -213,6 +266,30 @@ mod tests { assert!(dirs.iter().all(|dir| !files.contains(dir))); } + #[test] + fn worker_container_links_lists_only_links_beside_pool_checkouts() { + let dir = tempfile::tempdir().unwrap(); + let home = dir.path().canonicalize().unwrap(); + let pool = home.join(".local/share/cortexkit/alfonso/worktrees"); + let container = pool.join("hash-a"); + let own = container.join("own"); + std::fs::create_dir_all(&own).unwrap(); + std::fs::create_dir(container.join("other-worker")).unwrap(); + std::fs::write(container.join("plain-file"), "not a link").unwrap(); + let sibling = home.join("Work/sibling"); + std::fs::create_dir_all(&sibling).unwrap(); + std::os::unix::fs::symlink(&sibling, container.join("sibling")).unwrap(); + std::os::unix::fs::symlink(home.join("missing"), container.join("dangling")).unwrap(); + // A checkout outside the pool gets nothing, even with links beside it. + let outside = home.join("outside/own"); + std::fs::create_dir_all(&outside).unwrap(); + std::os::unix::fs::symlink(&sibling, home.join("outside/sibling")).unwrap(); + assert_eq!( + worker_container_links(&home, &[own, outside]), + [container.join("dangling"), container.join("sibling")] + ); + } + #[test] fn worker_targets_inside_the_pool_require_operator_configuration() { let dir = tempfile::tempdir().unwrap(); diff --git a/crates/aft/tests/worker_jail.rs b/crates/aft/tests/worker_jail.rs index 2f4ed7cc94..5d2a7ae893 100644 --- a/crates/aft/tests/worker_jail.rs +++ b/crates/aft/tests/worker_jail.rs @@ -3031,15 +3031,17 @@ async fn worker_jail_operator_build_slot_and_container_reads() { let cargo_config = container.join(".cargo/config.toml"); let budget = container.join(".cargo/alfonso-test-threads"); let seeds = container.join(".rust-build-seeds"); - let slots = jail.data.join("cortexkit/prefrontal-core/build-slots"); + // Prefrontal's layout: the launcher sits beside the worktree containers + // and names its metadata files after itself. + let slots = jail.data.join("cortexkit/alfonso/worktrees/.build-slots"); for path in [cargo_config.parent().unwrap(), &seeds, &slots] { std::fs::create_dir_all(path).unwrap(); } std::fs::write(&budget, "2\n").unwrap(); std::fs::write(seeds.join("seed"), "build-seed").unwrap(); for (name, value) in [ - (".root", "slot-root"), - (".cache", "slot-cache"), + ("prefrontal-build-slot.root", "slot-root"), + ("prefrontal-build-slot.cache", "slot-cache"), ("limit", "2\n"), ] { std::fs::write(slots.join(name), value).unwrap(); @@ -3050,8 +3052,8 @@ async fn worker_jail_operator_build_slot_and_container_reads() { r#"#!/usr/bin/env python3 import fcntl, os, pathlib, sys base = pathlib.Path(__file__).parent -assert (base / '.root').read_text() == 'slot-root' -assert (base / '.cache').read_text() == 'slot-cache' +assert (base / 'prefrontal-build-slot.root').read_text() == 'slot-root' +assert (base / 'prefrontal-build-slot.cache').read_text() == 'slot-cache' assert (base / 'limit').read_text().strip() == '2' with (base / 'queue.lock').open('a') as queue, (base / '0.lock').open('a') as slot: fcntl.flock(queue, fcntl.LOCK_EX) @@ -3095,6 +3097,23 @@ with (base / 'queue.lock').open('a') as queue, (base / '0.lock').open('a') as sl )).await; assert!(read.contains("CONTAINER_2"), "{read}"); assert!(read.contains("build-seed"), "{read}"); + // The worker system links sibling repositories beside every worktree. A + // lookup must follow such a link to a readable checkout, while a link into + // another worker's checkout still reads nothing. + std::fs::write(jail.main.join("sibling-readable.txt"), "sibling-ok").unwrap(); + std::os::unix::fs::symlink(&jail.main, container.join("main-link")).unwrap(); + let other_worker = container.parent().unwrap().join("fedcba9876543210/other"); + std::fs::create_dir_all(&other_worker).unwrap(); + std::fs::write(other_worker.join("private.txt"), "other-worker").unwrap(); + std::os::unix::fs::symlink(&other_worker, container.join("other-link")).unwrap(); + // Each command's sandbox profile is built when it starts, so it sees the + // links created above. + let linked = jail + .bash("cat ../main-link/sibling-readable.txt && echo LINK_$((1+1))") + .await; + assert!(linked.contains("sibling-ok") && linked.contains("LINK_2"), "{linked}"); + let other = jail.bash("cat ../other-link/private.txt").await; + assert!(!other.contains("other-worker"), "{other}"); let built = jail.bash(&cargo_build(&jail, "", "BUILD_SLOT")).await; eprintln!("Native build-slot output:\n{built}"); assert!(built.contains("BUILD_SLOT_2"), "{built}"); @@ -3115,8 +3134,8 @@ with (base / 'queue.lock').open('a') as queue, (base / '0.lock').open('a') as sl for path in [ &wrapper, &slots.join("rustc-lowprio-direct"), - &slots.join(".root"), - &slots.join(".cache"), + &slots.join("prefrontal-build-slot.root"), + &slots.join("prefrontal-build-slot.cache"), &slots.join("limit"), &cargo_config, &budget, diff --git a/scripts/file-size-pins.json b/scripts/file-size-pins.json index 03534f8dba..ab36071928 100644 --- a/scripts/file-size-pins.json +++ b/scripts/file-size-pins.json @@ -24,7 +24,7 @@ "reason": "Split language-server lifecycle and requests pending; AFT crate split lane." }, "crates/aft/src/sandbox_spawn.rs": { - "lines": 10797, + "lines": 10719, "reason": "Split sandbox spawning by platform pending; AFT crate split lane." }, "crates/aft/src/commands/semantic_search/mod.rs": { From 8659802aa4dd161bc317da026a2e731e63123b5d Mon Sep 17 00:00:00 2001 From: ualtinok <94532+ualtinok@users.noreply.github.com> Date: Wed, 18 Nov 2026 19:13:13 +0100 Subject: [PATCH 24/26] mason: handle collected task scopes and isolate reconnect polling Treat a cgroup.kill write returning ENODEV as an already-stopped scope only when the cgroup directory is gone. Preserve existing kill refusals and surface syscall diagnostics on failure. The running-withdraw path still signals the process group before attempting the scope kill. Keep the connection-loss control-frame assertions on the closing socket and on reconnect. Use production polling on reconnect so scheduled polling before route installation cannot masquerade as a scope-end action queued at EOF. Co-authored-by: alfonso-aft <289616620+alfonso-aft@users.noreply.github.com> --- crates/aft/src/bash_background/scope_kill.rs | 75 +++++++++++++++++++ .../aft/src/bash_background/scope_runtime.rs | 7 +- crates/aft/src/bash_background/task_scope.rs | 24 +++--- crates/aft/tests/scope_end_kill.rs | 26 +++++-- crates/aft/tests/tool_provider_conformance.rs | 5 +- 5 files changed, 115 insertions(+), 22 deletions(-) create mode 100644 crates/aft/src/bash_background/scope_kill.rs diff --git a/crates/aft/src/bash_background/scope_kill.rs b/crates/aft/src/bash_background/scope_kill.rs new file mode 100644 index 0000000000..ece17f489d --- /dev/null +++ b/crates/aft/src/bash_background/scope_kill.rs @@ -0,0 +1,75 @@ +use std::fs::{File, OpenOptions}; +use std::io::{self, Write}; +use std::path::Path; + +pub(super) fn kill(cgroup: &Path) -> io::Result<()> { + kill_with(cgroup, |file| file.write_all(b"1")) +} + +fn kill_with(cgroup: &Path, write: impl FnOnce(&mut File) -> io::Result<()>) -> io::Result<()> { + let existed_before = cgroup.try_exists(); + let (phase, result, collection_errno) = match OpenOptions::new() + .write(true) + .open(cgroup.join("cgroup.kill")) + { + Ok(mut file) => ("write", write(&mut file), libc::ENODEV), + Err(error) => ("open", Err(error), libc::ENOENT), + }; + let Err(error) = result else { return Ok(()) }; + let exists_after = cgroup.try_exists(); + // The process-group kill can empty the scope first. If systemd removes the + // scope while cgroup.kill is open, the write can fail with ENODEV. + if error.raw_os_error() == Some(collection_errno) && matches!(exists_after, Ok(false)) { + return Ok(()); + } + log::warn!( + "task scope kill {phase} failed for {}: {error} (errno={:?}, existed before={existed_before:?}, exists after={exists_after:?})", + cgroup.display(), + error.raw_os_error(), + ); + Err(error) +} + +#[cfg(test)] +mod tests { + use super::*; + use std::fs; + + #[test] + fn task_scope_kill_accepts_collection_between_open_and_write() { + let root = tempfile::tempdir().unwrap(); + let scope = root.path().join("scope"); + fs::create_dir(&scope).unwrap(); + fs::write(scope.join("cgroup.kill"), "0").unwrap(); + kill_with(&scope, |_| { + fs::remove_dir_all(&scope).unwrap(); + Err(io::Error::from_raw_os_error(libc::ENODEV)) + }) + .unwrap(); + } + + #[test] + fn task_scope_kill_does_not_treat_enodev_alone_as_collection() { + let root = tempfile::tempdir().unwrap(); + fs::write(root.path().join("cgroup.kill"), "0").unwrap(); + let error = kill_with(root.path(), |_| { + Err(io::Error::from_raw_os_error(libc::ENODEV)) + }) + .unwrap_err(); + assert_eq!(error.raw_os_error(), Some(libc::ENODEV)); + } + + #[test] + fn task_scope_kill_preserves_other_write_errors_even_if_scope_disappears() { + let root = tempfile::tempdir().unwrap(); + let scope = root.path().join("scope"); + fs::create_dir(&scope).unwrap(); + fs::write(scope.join("cgroup.kill"), "0").unwrap(); + let error = kill_with(&scope, |_| { + fs::remove_dir_all(&scope).unwrap(); + Err(io::Error::from_raw_os_error(libc::EACCES)) + }) + .unwrap_err(); + assert_eq!(error.kind(), io::ErrorKind::PermissionDenied); + } +} diff --git a/crates/aft/src/bash_background/scope_runtime.rs b/crates/aft/src/bash_background/scope_runtime.rs index 9cfcce9dde..ce8e02ff8f 100644 --- a/crates/aft/src/bash_background/scope_runtime.rs +++ b/crates/aft/src/bash_background/scope_runtime.rs @@ -290,10 +290,13 @@ impl BgTaskRegistry { .ok() .map(|state| state.metadata.clone()) } - Err(_) => { + Err(error) => { + log::warn!( + "task scope kill could not read metadata for {task_id}: {error}" + ); return Err(format!( "task scope aft-task-{task_id}.scope could not be killed" - )) + )); } }; if let Some(metadata) = metadata { diff --git a/crates/aft/src/bash_background/task_scope.rs b/crates/aft/src/bash_background/task_scope.rs index e90a62d3fc..1f2631d102 100644 --- a/crates/aft/src/bash_background/task_scope.rs +++ b/crates/aft/src/bash_background/task_scope.rs @@ -3,6 +3,10 @@ pub(crate) use linux::*; #[cfg(not(target_os = "linux"))] pub(crate) use unsupported::*; +#[cfg(target_os = "linux")] +#[path = "scope_kill.rs"] +mod scope_kill; + #[cfg(target_os = "linux")] mod linux { use super::super::HardKill; @@ -166,9 +170,12 @@ mod linux { match lookup_local(task_id, recorded)? { LocalScopeLookup::Present(handle) => Ok(Some(handle)), LocalScopeLookup::Absent => Ok(None), - LocalScopeLookup::Unknown => Err(format!( - "task scope aft-task-{task_id}.scope could not be killed" - )), + LocalScopeLookup::Unknown => { + log::warn!("task scope kill could not locate the cgroup for {task_id}"); + Err(format!( + "task scope aft-task-{task_id}.scope could not be killed" + )) + } } } @@ -1135,16 +1142,7 @@ mod linux { events.lock().unwrap().push("scope-kill"); } }); - match std::fs::OpenOptions::new() - .write(true) - .open(self.cgroup.join("cgroup.kill")) - { - Ok(mut file) => file.write_all(b"1"), - Err(e) if e.kind() == io::ErrorKind::NotFound && !self.cgroup.try_exists()? => { - Ok(()) - } - Err(e) => Err(e), - } + super::scope_kill::kill(&self.cgroup) } pub(crate) fn stop(&self) -> Result<(), String> { stop_unit_with(&self.manager, &self.unit) diff --git a/crates/aft/tests/scope_end_kill.rs b/crates/aft/tests/scope_end_kill.rs index 74bd81b279..2ddb8f6e2a 100644 --- a/crates/aft/tests/scope_end_kill.rs +++ b/crates/aft/tests/scope_end_kill.rs @@ -147,6 +147,10 @@ fn startup_debug_logs(directory: &Path) -> String { impl Daemon { async fn spawn(root: &Path, ops: &[&str]) -> Self { + Self::spawn_with_scope_poll(root, ops, Some("500")).await + } + + async fn spawn_with_scope_poll(root: &Path, ops: &[&str], poll_ms: Option<&str>) -> Self { let config = root.join("project/.cortexkit"); std::fs::create_dir_all(&config).unwrap(); std::fs::write( @@ -194,11 +198,14 @@ impl Daemon { .env_remove("SUBC_LAUNCH_NONCE") .env_remove("AFT_STORAGE_DIR") .env("AFT_TEST_DISABLE_FILE_WATCHER", "1") - .env("AFT_TEST_SCOPE_POLL_MS", "500") .env("AFT_TEST_SCOPE_DESCRIBE_TIMEOUT_MS", "200") .stdin(Stdio::null()) .stdout(Stdio::null()) .stderr(Stdio::from(std::fs::File::create(&stderr_path).unwrap())); + match poll_ms { + Some(ms) => command.env("AFT_TEST_SCOPE_POLL_MS", ms), + None => command.env_remove("AFT_TEST_SCOPE_POLL_MS"), + }; for (variable, directory) in [ ("XDG_CONFIG_HOME", "config"), ("XDG_DATA_HOME", "data"), @@ -1449,8 +1456,11 @@ async fn connection_loss_detaches_without_queueing_or_killing() { "principal":"reserved:broca", "harness":"runner", "session":"session-1", }) ); + let is_control = + |frame: &Frame| frame.header.ty == FrameType::Request && frame.header.channel == 0; + // Already received frames cannot have been triggered by the EOF below. + while daemon.frames.try_recv().is_ok() {} daemon.writer.shutdown().await.unwrap(); - daemon.reader.abort(); let until = tokio::time::Instant::now() + Duration::from_secs(10); while daemon.child.try_wait().unwrap().is_none() { assert!( @@ -1460,9 +1470,15 @@ async fn connection_loss_detaches_without_queueing_or_killing() { tokio::time::sleep(Duration::from_millis(20)).await; } assert!(daemon.controls.is_empty()); + assert!(daemon + .next_matching(Duration::from_millis(700), is_control) + .await + .is_none()); assert_eq!(task_metadata(&root)[0].1["status"], "running"); drop(daemon); - let mut daemon = Daemon::spawn(&root, &["scope.describe"]).await; + // The fast fixture poll can query restored work before its route is bound. + // Use production timing so this window tests queued work, not periodic polling. + let mut daemon = Daemon::spawn_with_scope_poll(&root, &["scope.describe"], None).await; daemon .bind(1, 1, "broca", Some(stamp("owner", 1)), false) .await; @@ -1474,9 +1490,7 @@ async fn connection_loss_detaches_without_queueing_or_killing() { .assert_foreign_task_is_concealed(task["task_id"].as_str().unwrap(), "session-1") .await; assert!(daemon - .next_matching(Duration::from_millis(700), |frame| frame.header.ty - == FrameType::Request - && frame.header.channel == 0) + .next_matching(Duration::from_millis(700), is_control) .await .is_none()); daemon diff --git a/crates/aft/tests/tool_provider_conformance.rs b/crates/aft/tests/tool_provider_conformance.rs index 50fb0f2bb4..50c2b7fd80 100644 --- a/crates/aft/tests/tool_provider_conformance.rs +++ b/crates/aft/tests/tool_provider_conformance.rs @@ -2898,7 +2898,10 @@ async fn s2_withdraw_of_a_running_keyed_bash_kills_only_that_task() { "killed".into(), Some("withdrawn".into()) ), - ] + ], + "provider stderr:\n{}", + std::fs::read_to_string(root.join("daemon.stderr")) + .unwrap_or_else(|error| format!("cannot read provider stderr: {error}")) ); } From 039131e1d1702d9bb8132277f0d36e931770b50e Mon Sep 17 00:00:00 2001 From: ualtinok <94532+ualtinok@users.noreply.github.com> Date: Wed, 18 Nov 2026 19:35:16 +0100 Subject: [PATCH 25/26] style: rustfmt the macOS build-slot sandbox change Co-authored-by: alfonso-aft <289616620+alfonso-aft@users.noreply.github.com> --- crates/aft/src/sandbox_spawn.rs | 4 ++-- crates/aft/tests/worker_jail.rs | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/aft/src/sandbox_spawn.rs b/crates/aft/src/sandbox_spawn.rs index a09885a99c..f8d9c0cbd9 100644 --- a/crates/aft/src/sandbox_spawn.rs +++ b/crates/aft/src/sandbox_spawn.rs @@ -55,6 +55,8 @@ use crate::context::AppContext; use crate::sandbox_profile::resolved_env_deny_paths; use crate::sandbox_profile::SandboxProfile; +#[cfg(unix)] +mod build_slots; mod requirement; #[cfg(unix)] mod settings_grants; @@ -63,8 +65,6 @@ mod task_temp; #[cfg(unix)] mod worker_reads; #[cfg(unix)] -mod build_slots; -#[cfg(unix)] use build_slots::add_build_slot_grants; pub(crate) use requirement::{resolve_command_sandbox_spawn, SandboxRequirement}; #[cfg(unix)] diff --git a/crates/aft/tests/worker_jail.rs b/crates/aft/tests/worker_jail.rs index 5d2a7ae893..8d1d3bd140 100644 --- a/crates/aft/tests/worker_jail.rs +++ b/crates/aft/tests/worker_jail.rs @@ -3111,7 +3111,10 @@ with (base / 'queue.lock').open('a') as queue, (base / '0.lock').open('a') as sl let linked = jail .bash("cat ../main-link/sibling-readable.txt && echo LINK_$((1+1))") .await; - assert!(linked.contains("sibling-ok") && linked.contains("LINK_2"), "{linked}"); + assert!( + linked.contains("sibling-ok") && linked.contains("LINK_2"), + "{linked}" + ); let other = jail.bash("cat ../other-link/private.txt").await; assert!(!other.contains("other-worker"), "{other}"); let built = jail.bash(&cargo_build(&jail, "", "BUILD_SLOT")).await; From 4bc84ec62d8ac888717587d40561be32816d2c94 Mon Sep 17 00:00:00 2001 From: ualtinok <94532+ualtinok@users.noreply.github.com> Date: Wed, 18 Nov 2026 21:27:01 +0100 Subject: [PATCH 26/26] sandbox: grant the build-slot launcher on the relaxed worker profile too Workers run the relaxed sandbox profile by default, which builds its grants in build_relaxed_profile, separately from the strict path's worker_jail_grants. The previous fix added the build-slot launcher's directory and lock grants only on the strict path, and its native test ran strict, so real workers still couldn't read `.build-slots/` and every Rust build failed with "prefrontal-build-slot: Operation not permitted". Both paths now take the launcher grants from one function, build_slots::worker_build_slot_grants. The relaxed path adds them to its data policy as read exceptions (directory, launcher, locks), write exceptions (locks only), and a write deny on the launcher. The native macOS test runs the same build-slot and container checks under both profiles. Co-authored-by: alfonso-aft <289616620+alfonso-aft@users.noreply.github.com> --- crates/aft/src/sandbox_spawn.rs | 32 ++++++------ crates/aft/src/sandbox_spawn/build_slots.rs | 55 ++++++++++++++++++++- crates/aft/tests/worker_jail.rs | 17 ++++++- scripts/file-size-pins.json | 2 +- 4 files changed, 85 insertions(+), 21 deletions(-) diff --git a/crates/aft/src/sandbox_spawn.rs b/crates/aft/src/sandbox_spawn.rs index f8d9c0cbd9..3158b2cde0 100644 --- a/crates/aft/src/sandbox_spawn.rs +++ b/crates/aft/src/sandbox_spawn.rs @@ -64,8 +64,6 @@ mod settings_grants; mod task_temp; #[cfg(unix)] mod worker_reads; -#[cfg(unix)] -use build_slots::add_build_slot_grants; pub(crate) use requirement::{resolve_command_sandbox_spawn, SandboxRequirement}; #[cfg(unix)] use settings_grants::absolute_env_path; @@ -2209,6 +2207,14 @@ fn build_relaxed_profile( // protecting their control files or carving out sibling checkout denies. policy.absolute_floor = read_deny.clone(); policy.private_stores = stores.clone(); + // The macOS read limit hides the worker pool outside the worker's own + // checkout, and the build-slot launcher sits in that pool. + #[cfg(target_os = "macos")] + if worker_jail_active() { + let slots = build_slots::worker_build_slot_grants(home, roots, &policy); + build_slots::add_build_slot_reads(&slots, &mut stores, &mut write_deny); + policy.private_stores = stores.clone(); + } let write_grants = policy.shell_grants(crate::access_policy::AccessOperation::Write); let mut control_roots = roots.to_vec(); control_roots.extend(write_grants.iter().cloned()); @@ -2929,23 +2935,13 @@ fn worker_jail_grants( grants .roots .extend(worker_target_roots(home, project_roots, policy, &configs)); - for (config_path, base) in configs { - grants.read_only.push(config_path.clone()); - let Some(build) = cargo_build_settings(&config_path) else { - continue; - }; - if let Some(wrapper) = build.rustc_wrapper { - let wrapper = PathBuf::from(wrapper); - let wrapper = if wrapper.is_absolute() { - Some(wrapper) - } else { - base.as_ref().map(|base| base.join(wrapper)) - }; - if let Some(wrapper) = wrapper { - add_build_slot_grants(&wrapper, project_roots, policy, &mut grants); - } - } + for (config_path, _) in configs { + grants.read_only.push(config_path); } + let slots = build_slots::worker_build_slot_grants(home, project_roots, policy); + grants.files.extend(slots.files); + grants.read_only.extend(slots.read_only); + grants.read_dirs.extend(slots.read_dirs); grants } diff --git a/crates/aft/src/sandbox_spawn/build_slots.rs b/crates/aft/src/sandbox_spawn/build_slots.rs index bb0065d20c..079e508fda 100644 --- a/crates/aft/src/sandbox_spawn/build_slots.rs +++ b/crates/aft/src/sandbox_spawn/build_slots.rs @@ -4,7 +4,60 @@ use std::ffi::OsStr; use std::path::{Path, PathBuf}; -use super::{canonicalize_profile_candidate, profile_candidate_is_file, WorkerJailGrants}; +use super::{ + canonicalize_profile_candidate, cargo_build_settings, profile_candidate_is_file, + worker_cargo_configs, WorkerJailGrants, +}; + +/// Build-slot grants for every `prefrontal-build-slot` launcher that a Cargo +/// configuration above the worker's checkouts names as its rustc wrapper. +pub(super) fn worker_build_slot_grants( + home: &Path, + project_roots: &[PathBuf], + policy: &crate::access_policy::AccessPolicy, +) -> WorkerJailGrants { + let mut grants = WorkerJailGrants::default(); + for (config_path, base) in worker_cargo_configs(home, project_roots) { + let Some(wrapper) = cargo_build_settings(&config_path) + .and_then(|build| build.rustc_wrapper) + .map(PathBuf::from) + else { + continue; + }; + let wrapper = if wrapper.is_absolute() { + Some(wrapper) + } else { + base.map(|base| base.join(wrapper)) + }; + if let Some(wrapper) = wrapper { + add_build_slot_grants(&wrapper, project_roots, policy, &mut grants); + } + } + grants +} + +/// Adds build-slot grants to a relaxed profile's data policy. The relaxed +/// profile has no separate jail grant lists: the launcher's directory and +/// locks become read exceptions to the denied data folder, the locks also +/// write exceptions, and the launcher itself stays write-denied. +#[cfg(any(target_os = "macos", test))] +#[cfg_attr(not(target_os = "macos"), allow(dead_code))] +pub(super) fn add_build_slot_reads( + grants: &WorkerJailGrants, + stores: &mut crate::sandbox_profile::SandboxDataPolicy, + write_deny: &mut Vec, +) { + stores.read_allow.extend( + grants + .read_only + .iter() + .chain(&grants.read_dirs) + .chain(&grants.files) + .cloned(), + ); + stores.write_allow.extend(grants.files.iter().cloned()); + write_deny.extend(grants.read_only.iter().cloned()); +} /// Retain only the operator-configured `prefrontal-build-slot` launcher's /// directory: the launcher and its `rustc-lowprio-direct` companion take a diff --git a/crates/aft/tests/worker_jail.rs b/crates/aft/tests/worker_jail.rs index 8d1d3bd140..f38326e5b7 100644 --- a/crates/aft/tests/worker_jail.rs +++ b/crates/aft/tests/worker_jail.rs @@ -3026,7 +3026,22 @@ async fn worker_jail_operator_build_slot_and_container_reads() { if !native_available() { return; } - let mut jail = Jail::start().await; + operator_build_slot_and_container_reads(Jail::start().await).await; +} + +// Workers default to the relaxed profile, which builds its grants on a separate +// path from the strict one; the build-slot launcher must work under both. +#[cfg(target_os = "macos")] +#[tokio::test] +async fn worker_jail_relaxed_operator_build_slot_and_container_reads() { + if !native_available() { + return; + } + operator_build_slot_and_container_reads(Jail::relaxed(false).await).await; +} + +#[cfg(target_os = "macos")] +async fn operator_build_slot_and_container_reads(mut jail: Jail) { let container = jail.worktree.parent().unwrap().to_path_buf(); let cargo_config = container.join(".cargo/config.toml"); let budget = container.join(".cargo/alfonso-test-threads"); diff --git a/scripts/file-size-pins.json b/scripts/file-size-pins.json index ab36071928..e5f2a11c9b 100644 --- a/scripts/file-size-pins.json +++ b/scripts/file-size-pins.json @@ -24,7 +24,7 @@ "reason": "Split language-server lifecycle and requests pending; AFT crate split lane." }, "crates/aft/src/sandbox_spawn.rs": { - "lines": 10719, + "lines": 10715, "reason": "Split sandbox spawning by platform pending; AFT crate split lane." }, "crates/aft/src/commands/semantic_search/mod.rs": {