Skip to main content

muster/domain/port/
agent_session_store.rs

1use std::path::PathBuf;
2
3use crate::domain::{
4    agent_session::{
5        AgentProcessId, AgentProcessStartToken, AgentSession, AgentSessionId, AgentSessionState,
6        NativeSessionId,
7    },
8    config::ConfigError,
9    process::AgentTool,
10};
11
12/// Persists agent-session identity and history across TUI lifetimes.
13pub trait AgentSessionStore {
14    /// Loads sessions in history order, oldest first.
15    ///
16    /// # Errors
17    /// Returns a [`ConfigError`] when the state file cannot be read or parsed.
18    fn sessions(&self) -> Result<Vec<AgentSession>, ConfigError>;
19
20    /// Returns the durable state-file location inherited by provider hooks.
21    ///
22    /// # Errors
23    /// Returns a [`ConfigError`] when the state location cannot be resolved.
24    fn state_file_path(&self) -> Result<Option<PathBuf>, ConfigError>;
25
26    /// Inserts or replaces a session and makes it the newest history entry.
27    ///
28    /// # Errors
29    /// Returns a [`ConfigError`] when the state file cannot be updated.
30    fn upsert(&self, session: &AgentSession) -> Result<(), ConfigError>;
31
32    /// Changes a session's open/closed state and moves it to the end of history.
33    ///
34    /// # Errors
35    /// Returns a [`ConfigError`] when the state file cannot be updated.
36    fn set_state(&self, id: &AgentSessionId, state: AgentSessionState) -> Result<(), ConfigError>;
37
38    /// Binds a session to the process currently launched on its behalf.
39    ///
40    /// # Errors
41    /// Returns a [`ConfigError`] when the session cannot be updated.
42    fn set_owner_process_id(
43        &self,
44        id: &AgentSessionId,
45        process_id: AgentProcessId,
46        process_start_token: Option<AgentProcessStartToken>,
47        wrapper_process_id: Option<AgentProcessId>,
48    ) -> Result<(), ConfigError>;
49
50    /// Records the latest identity reported by the session's owning provider.
51    /// Same-provider conversation changes replace the previous identity.
52    ///
53    /// # Errors
54    /// Returns a [`ConfigError`] when the state file cannot be updated or the
55    /// lifecycle event comes from a different provider.
56    fn capture_native_id(
57        &self,
58        id: &AgentSessionId,
59        provider: AgentTool,
60        process_id: AgentProcessId,
61        parent_process_id: Option<AgentProcessId>,
62        native_id: NativeSessionId,
63    ) -> Result<(), ConfigError>;
64}