Skip to main content

aios_action/
offline_adapter.rs

1//! 纯离线、确定性的 `ActionAdapter` 实现。
2//!
3//! `OfflineAdapter` 不访问真实系统 / 网络 / Android,只返回确定性的
4//! `ActionOutcome`。它用于 replay、测试和 golden hash 生成。
5
6use aios_core::governance::{ActionAdapter, AuthorizedAction};
7use aios_spec::governance::{ActionOutcome, AdapterError};
8use aios_spec::intent::ActionType;
9
10/// 离线模拟 adapter。
11#[derive(Debug, Clone, Copy, Default)]
12pub struct OfflineAdapter;
13
14impl OfflineAdapter {
15    pub fn new() -> Self {
16        Self
17    }
18}
19
20impl ActionAdapter for OfflineAdapter {
21    fn name(&self) -> &'static str {
22        "offline"
23    }
24
25    fn execute(&self, authorized: &AuthorizedAction) -> Result<ActionOutcome, AdapterError> {
26        let action = authorized.action();
27        let action_type_name = format!("{:?}", action.action_type);
28        let target = action.target.clone();
29
30        let summary = match action.action_type {
31            ActionType::NoOp => "noop".to_string(),
32            ActionType::PreWarmProcess => {
33                format!(
34                    "simulate_prewarm:{}",
35                    target.as_deref().unwrap_or("unknown")
36                )
37            },
38            ActionType::PrefetchFile => {
39                format!("simulate_cache:{}", target.as_deref().unwrap_or("unknown"))
40            },
41            ActionType::KeepAlive => {
42                format!(
43                    "simulate_keepalive:{}",
44                    target.as_deref().unwrap_or("system")
45                )
46            },
47            ActionType::ReleaseMemory => {
48                format!("simulate_release:{}", target.as_deref().unwrap_or("system"))
49            },
50        };
51
52        Ok(ActionOutcome {
53            action_type: action_type_name,
54            target,
55            summary,
56            latency_us: 0,
57        })
58    }
59}