Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

103 changes: 103 additions & 0 deletions packages/plugin-sdk/src/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20485,6 +20485,109 @@ export const contracts: {
},
resources: {},
},
hostPermissions: {
mode: 'query',
input: {
$schema: 'https://json-schema.org/draft/2020-12/schema',
title: 'HostPermissionsRead',
type: 'object',
properties: {
grant: {
anyOf: [
{
$ref: '#/$defs/SystemPermissionGrant',
},
{
type: 'null',
},
],
},
},
additionalProperties: false,
$defs: {
SystemPermissionGrant: {
description:
'A macOS privacy grant (TCC) that the Host process itself needs before native\nComputer Use can run. This is operating-system state the user changes in\nSystem Settings, not a Maka grant; the Host observes it and commits the outcome.',
oneOf: [
{
description: 'System Settings > Privacy & Security > Accessibility.',
type: 'string',
const: 'accessibility',
},
{
description:
'System Settings > Privacy & Security > Screen & System Audio Recording.',
type: 'string',
const: 'screen_recording',
},
],
},
},
},
output: {
$schema: 'https://json-schema.org/draft/2020-12/schema',
title: 'HostPermissions',
type: 'object',
properties: {
stateDomain: {
type: 'string',
},
supported: {
type: 'boolean',
},
application: {
type: 'string',
},
bundlePath: {
type: ['string', 'null'],
},
grants: {
type: 'array',
items: {
$ref: '#/$defs/HostGrantState',
},
},
},
additionalProperties: false,
required: ['stateDomain', 'supported', 'application', 'bundlePath', 'grants'],
$defs: {
HostGrantState: {
type: 'object',
properties: {
grant: {
$ref: '#/$defs/SystemPermissionGrant',
},
effective: {
type: 'boolean',
},
pendingHost: {
type: 'boolean',
},
},
additionalProperties: false,
required: ['grant', 'effective'],
},
SystemPermissionGrant: {
description:
'A macOS privacy grant (TCC) that the Host process itself needs before native\nComputer Use can run. This is operating-system state the user changes in\nSystem Settings, not a Maka grant; the Host observes it and commits the outcome.',
oneOf: [
{
description: 'System Settings > Privacy & Security > Accessibility.',
type: 'string',
const: 'accessibility',
},
{
description:
'System Settings > Privacy & Security > Screen & System Audio Recording.',
type: 'string',
const: 'screen_recording',
},
],
},
},
},
resources: {},
},
import: {
mode: 'mutation',
input: {
Expand Down
24 changes: 24 additions & 0 deletions packages/plugin-sdk/src/generated/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,12 @@ export type AgentHistoryRequestsOutput_AgentHistoryRequestRetry =
kind: 'cancelled';
[k: string]: unknown | undefined;
};
/**
* A macOS privacy grant (TCC) that the Host process itself needs before native
* Computer Use can run. This is operating-system state the user changes in
* System Settings, not a Maka grant; the Host observes it and commits the outcome.
*/
export type AgentHostPermissionsOutput_SystemPermissionGrant = 'accessibility' | 'screen_recording';
export type AgentLoadHistoryCheckpointOutput_AgentCheckpointLoadState =
| {
kind: 'preparing';
Expand Down Expand Up @@ -3686,6 +3692,19 @@ export interface ServiceMethods {
[k: string]: unknown | undefined;
};
};
hostPermissions: {
mode: 'query';
input: {
grant?: Runtime.SystemPermissionGrant | null;
};
output: {
stateDomain: string;
supported: boolean;
application: string;
bundlePath: string | null;
grants: AgentHostPermissionsOutput_HostGrantState[];
};
};
import: {
mode: 'mutation';
input: Runtime.AgentImportChange;
Expand Down Expand Up @@ -6416,6 +6435,11 @@ export interface AgentHistoryRequestsOutput_ModelUsage {
reasoning_tokens?: number | null;
[k: string]: unknown | undefined;
}
export interface AgentHostPermissionsOutput_HostGrantState {
grant: AgentHostPermissionsOutput_SystemPermissionGrant;
effective: boolean;
pendingHost?: boolean;
}
export interface AgentLoadHistoryCheckpointOutput_AgentHistoryCheckpointHead {
revision: string;
manifest: AgentLoadHistoryCheckpointOutput_AgentHistoryCheckpointObject;
Expand Down
21 changes: 17 additions & 4 deletions platform/computer-use/src/desktop/worker/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use std::{

#[derive(Clone, Copy)]
pub(crate) enum MacRole {
PermissionStatus,
PermissionStatus(Option<SystemPermissionGrant>),
PermissionRequest(SystemPermissionGrant),
ListApps,
ListWindows { pid: Option<u32> },
Expand All @@ -43,7 +43,13 @@ pub(crate) enum MacRole {
impl MacRole {
fn arguments(self) -> Vec<OsString> {
let arguments = match self {
Self::PermissionStatus => vec!["--macos-permission-status"],
Self::PermissionStatus(None) => vec!["--macos-permission-status"],
Self::PermissionStatus(Some(SystemPermissionGrant::Accessibility)) => {
vec!["--macos-permission-status", "accessibility"]
}
Self::PermissionStatus(Some(SystemPermissionGrant::ScreenRecording)) => {
vec!["--macos-permission-status", "screen_recording"]
}
Self::PermissionRequest(SystemPermissionGrant::Accessibility) => {
vec!["--macos-permission-request", "accessibility"]
}
Expand All @@ -63,7 +69,14 @@ impl MacRole {
fn parse(arguments: &[OsString]) -> Option<Result<Self, String>> {
let first = arguments.first()?.to_str()?;
let role = match first {
"--macos-permission-status" if arguments.len() == 1 => Self::PermissionStatus,
"--macos-permission-status" if arguments.len() == 1 => Self::PermissionStatus(None),
"--macos-permission-status" if arguments.len() == 2 => {
Self::PermissionStatus(Some(match arguments[1].to_str() {
Some("accessibility") => SystemPermissionGrant::Accessibility,
Some("screen_recording") => SystemPermissionGrant::ScreenRecording,
_ => return Some(Err("Unsupported status grant".into())),
}))
}
"--macos-list-apps" if arguments.len() == 1 => Self::ListApps,
"--macos-list-windows" if arguments.len() == 1 => Self::ListWindows { pid: None },
"--macos-list-windows" if arguments.len() == 2 => {
Expand Down Expand Up @@ -213,7 +226,7 @@ fn read_output(mut input: impl Read, limit: usize) -> io::Result<Vec<u8>> {
pub(super) fn bootstrap(arguments: &[OsString]) -> Option<ExitCode> {
let role = MacRole::parse(arguments)?;
let result = role.and_then(|role| match role {
MacRole::PermissionStatus => crate::system_permission::process::finite_status(),
MacRole::PermissionStatus(only) => crate::system_permission::process::finite_status(only),
MacRole::PermissionRequest(grant) => {
watch_request_owner()?;
crate::system_permission::process::finite_request(grant)
Expand Down
22 changes: 22 additions & 0 deletions platform/computer-use/src/system_permission.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,28 @@ pub fn required(command: &Command) -> &'static [SystemPermissionGrant] {
}
}

/// Effective state in the serving Host compared with a fresh process of the same identity.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PermissionState {
Missing,
Effective,
PendingHost,
}

pub fn states(
required: &[SystemPermissionGrant],
) -> Result<Vec<(SystemPermissionGrant, PermissionState)>, String> {
#[cfg(all(feature = "native-desktop", target_os = "macos"))]
{
process::states(required)
}
#[cfg(not(all(feature = "native-desktop", target_os = "macos")))]
{
let _ = required;
Ok(Vec::new())
}
}

/// Whether this Host can observe and request macOS privacy grants.
pub const fn supported() -> bool {
cfg!(all(feature = "native-desktop", target_os = "macos"))
Expand Down
77 changes: 64 additions & 13 deletions platform/computer-use/src/system_permission/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,12 @@ struct Grants {
}

impl Grants {
fn read() -> Self {
fn read(only: Option<SystemPermissionGrant>) -> Self {
Self {
accessibility: tcc::raw_present(Grant::Accessibility),
screen_recording: tcc::raw_present(Grant::ScreenRecording),
accessibility: only != Some(SystemPermissionGrant::ScreenRecording)
&& tcc::raw_present(Grant::Accessibility),
screen_recording: only != Some(SystemPermissionGrant::Accessibility)
&& tcc::raw_present(Grant::ScreenRecording),
}
}

Expand Down Expand Up @@ -145,23 +147,58 @@ pub(super) fn missing(
if required.is_empty() {
return Ok(Vec::new());
}
missing_from_states(states(required)?)
}

pub(super) fn states(
required: &[SystemPermissionGrant],
) -> Result<Vec<(SystemPermissionGrant, super::PermissionState)>, String> {
let expected = Subject::current()?;
let value =
macos_finite(MacRole::PermissionStatus, &|| false).map_err(|error| error.to_string())?;
let value = macos_finite(
MacRole::PermissionStatus(match required {
[grant] => Some(*grant),
_ => None,
}),
&|| false,
)
.map_err(|error| error.to_string())?;
let observed = decode(value, &expected)?;
missing_from_snapshot(required, &observed, |grant| tcc::raw_present(grant.into()))
Ok(classify(required, &observed, |grant| {
tcc::raw_present(grant.into())
}))
}

fn missing_from_snapshot(
fn classify(
required: &[SystemPermissionGrant],
observed: &Snapshot,
mut main_present: impl FnMut(SystemPermissionGrant) -> bool,
) -> Vec<(SystemPermissionGrant, super::PermissionState)> {
use super::PermissionState::*;
required
.iter()
.map(|&grant| {
(
grant,
if !observed.grants.present(grant) {
Missing
} else if main_present(grant) {
Effective
} else {
PendingHost
},
)
})
.collect()
}

fn missing_from_states(
states: Vec<(SystemPermissionGrant, super::PermissionState)>,
) -> Result<Vec<SystemPermissionGrant>, String> {
let mut missing = Vec::new();
for &grant in required {
if !observed.grants.present(grant) {
for (grant, state) in states {
if state == super::PermissionState::Missing {
missing.push(grant);
} else if !main_present(grant) {
} else if state == super::PermissionState::PendingHost {
return Err(format!(
"system_permission_state_disagreement: {} is granted to a fresh process but not effective in Host PID {}",
Grant::from(grant).code(),
Expand All @@ -183,11 +220,11 @@ pub(crate) fn request(
Ok(())
}

pub(crate) fn finite_status() -> Result<Value, String> {
pub(crate) fn finite_status(only: Option<SystemPermissionGrant>) -> Result<Value, String> {
let subject = Subject::finite_child()?;
serde_json::to_value(Snapshot {
subject,
grants: Grants::read(),
grants: Grants::read(only),
})
.map_err(|error| error.to_string())
}
Expand All @@ -200,7 +237,7 @@ pub(crate) fn finite_request(grant: SystemPermissionGrant) -> Result<Value, Stri
}
serde_json::to_value(Snapshot {
subject,
grants: Grants::read(),
grants: Grants::read(None),
})
.map_err(|error| error.to_string())
}
Expand All @@ -210,6 +247,13 @@ mod tests {
use super::*;
use SystemPermissionGrant::{Accessibility, ScreenRecording};

fn missing_from_snapshot(
required: &[SystemPermissionGrant],
observed: &Snapshot,
main: impl FnMut(SystemPermissionGrant) -> bool,
) -> Result<Vec<SystemPermissionGrant>, String> {
missing_from_states(classify(required, observed, main))
}
#[test]
fn fresh_grants_require_host_confirmation_without_probing_denied_grants() {
let directory = tempfile::tempdir().unwrap();
Expand Down Expand Up @@ -246,6 +290,13 @@ mod tests {
})
.unwrap();
assert_eq!(missing, [ScreenRecording]);
assert_eq!(
classify(&[Accessibility, ScreenRecording], &observed, |_| false),
[
(Accessibility, super::super::PermissionState::PendingHost),
(ScreenRecording, super::super::PermissionState::Missing)
]
);
let error = missing_from_snapshot(&[Accessibility], &observed, |_| false).unwrap_err();
assert!(error.contains("system_permission_state_disagreement: accessibility"));
}
Expand Down
1 change: 1 addition & 0 deletions platform/host-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ publish.workspace = true
cap-std.workspace = true
rusqlite.workspace = true
hex.workspace = true
maka-computer-use.workspace = true
maka-agent-facts.workspace = true
maka-packages.workspace = true
maka-capabilities.workspace = true
Expand Down
10 changes: 10 additions & 0 deletions platform/host-runtime/src/application/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,16 @@ impl Host {
)
.await
}
Request::RequestComputerPermission { grant } => {
authority.local()?;
let stop = self.accept_closed.clone();
let result = tokio::task::spawn_blocking(move || {
maka_computer_use::system_permission::request(&[grant], &|| stop.is_cancelled())
})
.await
.map_err(|error| error.to_string())?;
wire::write(&mut output, &Response::ComputerPermissionRequested(result)).await
}
Request::RemoteAccessStatus { invite_id } => {
authority.local()?;
wire::write(
Expand Down
Loading
Loading