A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.
Rust agentagent-orchestrationaiai-agentsclaude-codecodexcoding-agentlinuxmacosmultiplayermultiplexerrustterminalterminal-emulatorterminal-multiplexertmuxtuiweztermwindows
feat(mux-server): report the macOS permissions panes get
RoversX1df16a689313
diff --git a/Cargo.lock b/Cargo.lockindex c592cd61..08000960 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -5880,6 +5880,17 @@ dependencies = ["objc2-foundation",]+[[package]]+name = "objc2-av-foundation"+version = "0.3.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "478ae33fcac9df0a18db8302387c666b8ef08a3e2d62b510ca4fc278a384b6c0"+dependencies = [+ "bitflags 2.13.1",+ "objc2",+ "objc2-foundation",+]+[[package]]name = "objc2-core-foundation"version = "0.3.2"@@ -12215,6 +12226,8 @@ dependencies = ["metrics","mux","nix 0.29.0",+ "objc2-av-foundation",+ "objc2-core-graphics","passfd","portable-pty","procinfo",diff --git a/Cargo.toml b/Cargo.tomlindex 89d6de86..f25a4a2f 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -298,6 +298,7 @@ num-traits = {version="0.2", default-features=false }objc = "0.2"objc2 = "0.6"objc2-app-kit = { version = "0.3", default-features = false, features = ["std", "NSApplication", "NSDockTile", "NSResponder"] }+objc2-av-foundation = { version = "0.3", default-features = false, features = ["std", "AVCaptureDevice", "AVMediaFormat"] }objc2-core-graphics = "0.3"objc2-foundation = "0.3"objc2-user-notifications = "0.3"diff --git a/wezterm-mux-server-impl/Cargo.toml b/wezterm-mux-server-impl/Cargo.tomlindex 7020fbdd..68663797 100644--- a/wezterm-mux-server-impl/Cargo.toml+++ b/wezterm-mux-server-impl/Cargo.toml@@ -59,6 +59,8 @@ nix = { workspace = true, features = ["socket", "user"] }rustix = { version = "1.1.2", features = ["net", "termios", "fs", "process", "event"] }[target.'cfg(target_os = "macos")'.dependencies]+objc2-av-foundation.workspace = true+objc2-core-graphics.workspace = trueprocinfo.workspace = true[target."cfg(windows)".dependencies]diff --git a/wezterm-mux-server-impl/src/lib.rs b/wezterm-mux-server-impl/src/lib.rsindex c1d40bc5..713e28cd 100644--- a/wezterm-mux-server-impl/src/lib.rs+++ b/wezterm-mux-server-impl/src/lib.rs@@ -15,6 +15,7 @@ pub mod session_import;pub mod local;pub mod pki;mod plugin_relay;+pub mod privacy;mod private_file;mod sent_images;pub mod sessionhandler;diff --git a/wezterm-mux-server-impl/src/privacy.rs b/wezterm-mux-server-impl/src/privacy.rsnew file mode 100644index 00000000..63a8c4fd--- /dev/null+++ b/wezterm-mux-server-impl/src/privacy.rs@@ -0,0 +1,204 @@+//! What macOS privacy permissions the programs in a pane get (macOS).+//!+//! macOS grants them to whoever it holds responsible for a process: for+//! everything in a pane, the server that spawned the pane's shell, which is+//! responsible for itself (`exec_as_own_tcc_identity` in the server binary).+//! The GUI cannot read another program's permissions, so the server binary+//! answers for itself: run with [`REPORT_OPTION`], it takes on its own+//! identity as a server does, reports, and exits. Asking never makes macOS+//! ask the person anything.++use serde::{Deserialize, Serialize};+use std::path::Path;++/// What the GUI runs the server binary with to ask.+pub const REPORT_OPTION: &str = "--privacy-status";+/// What that run re-executes itself with once it is responsible for+/// itself, and only then reports.+pub const REPORT_AS_SELF_OPTION: &str = "--privacy-status-as-self";++#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]+#[serde(rename_all = "snake_case")]+pub enum PrivacyStatus {+ Granted,+ /// Not granted, where macOS does not tell refused from never asked+ /// (Full Disk Access, screen recording), or where a profile or Screen+ /// Time keeps it from being granted.+ NotGranted,+ /// Refused when macOS asked.+ Denied,+ /// Never asked for: macOS asks the first time a program wants it.+ NotAsked,+ /// Could not be told, such as when the file it is told by is missing.+ #[default]+ Unknown,+}++#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]+pub struct PrivacyReport {+ pub full_disk_access: PrivacyStatus,+ /// Screen & System Audio Recording.+ pub screen_recording: PrivacyStatus,+ /// Unknown when read from a server binary older than these two.+ #[serde(default)]+ pub microphone: PrivacyStatus,+ #[serde(default)]+ pub camera: PrivacyStatus,+}++/// Which stage of a report this run of the server binary is, if any.+#[derive(Debug, Clone, Copy, PartialEq, Eq)]+pub enum Request {+ /// Take on the server's own identity, then report.+ TakeIdentity,+ /// Report as this process stands.+ Report,+}++pub fn requested() -> Option<Request> {+ match std::env::args_os().nth(1)?.to_str()? {+ REPORT_OPTION => Some(Request::TakeIdentity),+ REPORT_AS_SELF_OPTION => Some(Request::Report),+ _ => None,+ }+}++/// Print this process's report as one line of JSON.+pub fn print_report() {+ match serde_json::to_string(&probe()) {+ Ok(json) => println!("{json}"),+ Err(err) => eprintln!("privacy report: {err:#}"),+ }+}++/// The permissions this process gets, as it stands.+pub fn probe() -> PrivacyReport {+ PrivacyReport {+ full_disk_access: full_disk_access(),+ screen_recording: screen_recording(),+ microphone: capture_access(CaptureDevice::Microphone),+ camera: capture_access(CaptureDevice::Camera),+ }+}++/// Full Disk Access has no question to ask, so it is told by opening a file+/// only it lets a program open: the person's own privacy database.+fn full_disk_access() -> PrivacyStatus {+ let Some(home) = std::env::var_os("HOME") else {+ return PrivacyStatus::Unknown;+ };+ full_disk_access_by(+ &Path::new(&home).join("Library/Application Support/com.apple.TCC/TCC.db"),+ )+}++fn full_disk_access_by(witness: &Path) -> PrivacyStatus {+ match std::fs::File::open(witness) {+ Ok(_) => PrivacyStatus::Granted,+ Err(err) if err.kind() == std::io::ErrorKind::PermissionDenied => {+ PrivacyStatus::NotGranted+ }+ Err(_) => PrivacyStatus::Unknown,+ }+}++#[cfg(target_os = "macos")]+fn screen_recording() -> PrivacyStatus {+ if objc2_core_graphics::CGPreflightScreenCaptureAccess() {+ PrivacyStatus::Granted+ } else {+ PrivacyStatus::NotGranted+ }+}++#[cfg(not(target_os = "macos"))]+fn screen_recording() -> PrivacyStatus {+ PrivacyStatus::Unknown+}++#[derive(Debug, Clone, Copy, PartialEq, Eq)]+enum CaptureDevice {+ Microphone,+ Camera,+}++/// Microphone and camera access, as AVFoundation tells it without asking.+#[cfg(target_os = "macos")]+fn capture_access(device: CaptureDevice) -> PrivacyStatus {+ use objc2_av_foundation::{+ AVAuthorizationStatus, AVCaptureDevice, AVMediaTypeAudio, AVMediaTypeVideo,+ };+ // SAFETY: both media types are AVFoundation's own constant strings, set+ // once it is loaded (this binary links it) and never changed, and+ // `authorizationStatusForMediaType:` takes exactly these two. The only+ // misuse Apple documents is another media type, which would throw.+ let status = unsafe {+ let media_type = match device {+ CaptureDevice::Microphone => AVMediaTypeAudio,+ CaptureDevice::Camera => AVMediaTypeVideo,+ };+ match media_type {+ Some(media_type) => AVCaptureDevice::authorizationStatusForMediaType(media_type),+ None => return PrivacyStatus::Unknown,+ }+ };+ match status {+ AVAuthorizationStatus::Authorized => PrivacyStatus::Granted,+ AVAuthorizationStatus::Denied => PrivacyStatus::Denied,+ AVAuthorizationStatus::NotDetermined => PrivacyStatus::NotAsked,+ AVAuthorizationStatus::Restricted => PrivacyStatus::NotGranted,+ _ => PrivacyStatus::Unknown,+ }+}++#[cfg(not(target_os = "macos"))]+fn capture_access(_device: CaptureDevice) -> PrivacyStatus {+ PrivacyStatus::Unknown+}++#[cfg(test)]+mod tests {+ use super::*;++ #[test]+ fn a_missing_witness_is_unknown_not_refused() {+ let dir = tempfile::tempdir().unwrap();+ assert_eq!(+ full_disk_access_by(&dir.path().join("TCC.db")),+ PrivacyStatus::Unknown+ );+ }++ #[test]+ fn a_readable_witness_means_granted() {+ let dir = tempfile::tempdir().unwrap();+ let witness = dir.path().join("TCC.db");+ std::fs::write(&witness, b"").unwrap();+ assert_eq!(full_disk_access_by(&witness), PrivacyStatus::Granted);+ }++ #[test]+ fn the_report_reads_back_as_written() {+ let report = PrivacyReport {+ full_disk_access: PrivacyStatus::NotGranted,+ screen_recording: PrivacyStatus::Granted,+ microphone: PrivacyStatus::NotAsked,+ camera: PrivacyStatus::Denied,+ };+ let json = serde_json::to_string(&report).unwrap();+ assert_eq!(+ json,+ r#"{"full_disk_access":"not_granted","screen_recording":"granted","microphone":"not_asked","camera":"denied"}"#+ );+ assert_eq!(serde_json::from_str::<PrivacyReport>(&json).unwrap(), report);+ }++ #[test]+ fn an_older_server_leaves_the_microphone_and_camera_unknown() {+ let report: PrivacyReport =+ serde_json::from_str(r#"{"full_disk_access":"granted","screen_recording":"not_granted"}"#)+ .unwrap();+ assert_eq!(report.microphone, PrivacyStatus::Unknown);+ assert_eq!(report.camera, PrivacyStatus::Unknown);+ }+}diff --git a/wezterm-mux-server/src/main.rs b/wezterm-mux-server/src/main.rsindex cb9d521b..86a99b6b 100644--- a/wezterm-mux-server/src/main.rs+++ b/wezterm-mux-server/src/main.rs@@ -103,6 +103,30 @@ fn main() {if let Some(watch) = wezterm_mux_server_impl::hold::requested() {wezterm_mux_server_impl::hold::run(&watch, env_bootstrap::setup_logger);}+ // The GUI asking what macOS lets the programs in panes do: answer with+ // the identity a server has, which the launcher's is not, and exit.+ #[cfg(target_os = "macos")]+ {+ use wezterm_mux_server_impl::privacy;+ match privacy::requested() {+ Some(privacy::Request::TakeIdentity) => {+ let err = match std::env::current_exe() {+ Ok(exe) => daemonize::exec_as_own_tcc_identity(+ exe.as_os_str(),+ &[privacy::REPORT_AS_SELF_OPTION.into()],+ ),+ Err(err) => err,+ };+ eprintln!("privacy report: could not take the server's identity: {err:#}");+ std::process::exit(1);+ }+ Some(privacy::Request::Report) => {+ privacy::print_report();+ std::process::exit(0);+ }+ None => {}+ }+ }thinkterm_import_herdr::register().expect("register built-in session importer");if let Some(result) = thinkterm_import::maybe_run_helper() {std::process::exit(if result.is_ok() { 0 } else { 1 });