1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//! Persona API — multi-persona management.
//!
//! `PersonaApi` is the thin public surface over `PersonaManager`.
//! RFC-039 completion: the manager owns persistence (`StateStore`) and
//! intent-engine re-seeding (callback) internally, so this API is a
//! pass-through — no caller can accidentally skip persist or re-seed.
use crate::persona::Persona;
use crate::persona::PersonaManager;
use std::sync::Arc;
/// Persona management system calls.
pub struct PersonaApi {
pub(crate) persona_manager: Arc<PersonaManager>,
}
impl PersonaApi {
/// Create a new PersonaApi.
pub fn new(persona_manager: Arc<PersonaManager>) -> Self {
Self { persona_manager }
}
/// Underlying `Arc<PersonaManager>` for boot-time wiring.
pub fn manager(&self) -> Arc<PersonaManager> {
Arc::clone(&self.persona_manager)
}
/// List all personas.
pub fn list(&self) -> Vec<Persona> {
self.persona_manager.store().list_all()
}
/// Get persona by ID.
pub fn get(&self, id: &str) -> Option<Persona> {
self.persona_manager.store().get(id)
}
/// Create a new persona (in-memory only; call `persist` after).
pub fn create(&self, persona: Persona) {
self.persona_manager.store().register(persona);
}
/// Update a persona (in-memory only; call `persist` after).
pub fn update(&self, id: &str, persona: Persona) -> anyhow::Result<()> {
self.persona_manager.store().update(id, persona)
}
/// Delete a persona (in-memory only; call `persist` after).
pub fn delete(&self, id: &str) -> anyhow::Result<()> {
self.persona_manager.store().delete(id)
}
/// Get active persona.
pub fn active(&self) -> Option<Persona> {
self.persona_manager.get_active_persona()
}
/// Get active persona ID.
pub fn active_id(&self) -> Option<String> {
self.persona_manager.active_persona_id()
}
/// Set active persona — persists to disk and re-seeds the intent engine
/// automatically (via `PersonaManager::set_active`).
pub async fn set_active(&self, id: &str) -> anyhow::Result<Option<String>> {
self.persona_manager.set_active(id).await
}
/// Persist the full persona registry to `StateStore`.
/// Call this after `create`/`update`/`delete` mutations so the in-memory
/// state matches the on-disk state.
pub async fn persist(&self) -> anyhow::Result<()> {
self.persona_manager.persist().await
}
/// Get persona count.
pub fn count(&self) -> usize {
self.persona_manager.store().len()
}
/// List enabled personas.
pub fn list_enabled(&self) -> Vec<Persona> {
self.persona_manager.store().list_enabled()
}
}