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
use std::path::PathBuf;
use crate::domain::{
agent_session::{
AgentProcessId, AgentProcessStartToken, AgentSession, AgentSessionId, AgentSessionState,
NativeSessionId,
},
config::ConfigError,
process::AgentTool,
};
/// Persists agent-session identity and history across TUI lifetimes.
pub trait AgentSessionStore {
/// Loads sessions in history order, oldest first.
///
/// # Errors
/// Returns a [`ConfigError`] when the state file cannot be read or parsed.
fn sessions(&self) -> Result<Vec<AgentSession>, ConfigError>;
/// Returns the durable state-file location inherited by provider hooks.
///
/// # Errors
/// Returns a [`ConfigError`] when the state location cannot be resolved.
fn state_file_path(&self) -> Result<Option<PathBuf>, ConfigError>;
/// Inserts or replaces a session and makes it the newest history entry.
///
/// # Errors
/// Returns a [`ConfigError`] when the state file cannot be updated.
fn upsert(&self, session: &AgentSession) -> Result<(), ConfigError>;
/// Changes a session's open/closed state and moves it to the end of history.
///
/// # Errors
/// Returns a [`ConfigError`] when the state file cannot be updated.
fn set_state(&self, id: &AgentSessionId, state: AgentSessionState) -> Result<(), ConfigError>;
/// Binds a session to the process currently launched on its behalf.
///
/// # Errors
/// Returns a [`ConfigError`] when the session cannot be updated.
fn set_owner_process_id(
&self,
id: &AgentSessionId,
process_id: AgentProcessId,
process_start_token: Option<AgentProcessStartToken>,
wrapper_process_id: Option<AgentProcessId>,
) -> Result<(), ConfigError>;
/// Records the latest identity reported by the session's owning provider.
/// Same-provider conversation changes replace the previous identity.
///
/// # Errors
/// Returns a [`ConfigError`] when the state file cannot be updated or the
/// lifecycle event comes from a different provider.
fn capture_native_id(
&self,
id: &AgentSessionId,
provider: AgentTool,
process_id: AgentProcessId,
parent_process_id: Option<AgentProcessId>,
native_id: NativeSessionId,
) -> Result<(), ConfigError>;
}