Skip to main content

aios_action/
lib.rs

1//! # aios-action — authorized action execution layer
2//!
3//! Responsibility: receive `AuthorizedAction` values produced by
4//! `aios_core::action_lifecycle::ActionLifecycle` and execute low-risk
5//! operations behind the action boundary.
6//!
7//! Three sibling adapters implement `ActionAdapter`; `ActionLifecycle` injects
8//! exactly one at construction:
9//!
10//! - [`OfflineAdapter`] — deterministic, no I/O. The canonical replay / golden
11//!   adapter; the only one in the audit-hash path.
12//! - [`DefaultActionExecutor`] — desktop stub. Pure, deterministic `tracing`
13//!   stubs with no network or environment access.
14//! - [`AndroidAdapter`] — on-device. Forwards supported actions to the Android
15//!   localhost bridge over a request/response protocol and maps the device's
16//!   real result back honestly. Never in the hash path.
17
18use aios_core::governance::{ActionAdapter, AuthorizedAction};
19use aios_spec::governance::{ActionOutcome, AdapterError};
20use aios_spec::intent::ActionType;
21
22pub mod android_adapter;
23pub mod offline_adapter;
24pub use android_adapter::{AndroidAdapter, AndroidBridgeConfig};
25pub use offline_adapter::OfflineAdapter;
26
27/// Default action executor for desktop replay.
28///
29/// Implements `ActionAdapter`: it can only receive an `AuthorizedAction` from
30/// `ActionLifecycle`, never construct one itself. Behavior is pure and
31/// deterministic — no network, no environment reads — so it is safe in the
32/// golden-hash path alongside `OfflineAdapter`.
33pub struct DefaultActionExecutor;
34
35impl DefaultActionExecutor {
36    pub fn new() -> Self {
37        Self
38    }
39}
40
41impl Default for DefaultActionExecutor {
42    fn default() -> Self {
43        Self::new()
44    }
45}
46
47impl ActionAdapter for DefaultActionExecutor {
48    fn name(&self) -> &'static str {
49        "default"
50    }
51
52    fn execute(&self, authorized: &AuthorizedAction) -> Result<ActionOutcome, AdapterError> {
53        let action = authorized.action();
54        let action_name = format!("{:?}", action.action_type);
55
56        let summary = match action.action_type {
57            ActionType::PreWarmProcess => match action.target.as_deref() {
58                Some(target) => {
59                    tracing::info!(
60                        target = %target,
61                        urgency = ?action.urgency,
62                        "PreWarmProcess: stub (third-party prewarm is not implemented)"
63                    );
64                    "stub_prewarm".to_string()
65                },
66                None => {
67                    return Err(AdapterError::ExecutionError(
68                        "PreWarmProcess requires a target app".into(),
69                    ));
70                },
71            },
72            ActionType::PrefetchFile => {
73                tracing::info!(
74                    target = ?action.target,
75                    urgency = ?action.urgency,
76                    "PrefetchFile: stub (local desktop fallback)"
77                );
78                "stub_prefetch".to_string()
79            },
80            ActionType::KeepAlive => {
81                if let Some(ref target) = action.target {
82                    tracing::info!(
83                        target = %target,
84                        urgency = ?action.urgency,
85                        "KeepAlive: stub (Android-safe keepalive not wired here)"
86                    );
87                    format!("stub_keepalive:{target}")
88                } else {
89                    tracing::info!("KeepAlive: no target specified, skipping");
90                    "stub_keepalive:system".to_string()
91                }
92            },
93            ActionType::ReleaseMemory => {
94                tracing::info!(
95                    target = ?action.target,
96                    urgency = ?action.urgency,
97                    "ReleaseMemory: stub (Android-safe release not wired here)"
98                );
99                "stub_release_memory".to_string()
100            },
101            ActionType::NoOp => {
102                tracing::debug!("NoOp executed");
103                "noop".to_string()
104            },
105        };
106
107        Ok(ActionOutcome {
108            action_type: action_name,
109            target: action.target.clone(),
110            summary,
111            latency_us: 0,
112        })
113    }
114}