gate4agent_node_core/
managed_worktree.rs1use crate::protocol::{
4 ManagedWorktreeCleanupFailure, ManagedWorktreeLeaseId, ManagedWorktreeLeaseSnapshot,
5 ManagedWorktreeLeaseState, ManagedWorktreeRetention, NodeIncarnationId, SessionRecordId,
6 WorktreeProfileId, WorktreeProfileRevision, WorkspaceId,
7};
8use gate4agent_types::{AgentInstanceId, SessionGeneration};
9use serde::{Deserialize, Serialize};
10
11#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
12pub struct ManagedWorktreeSessionHolder {
13 pub incarnation_id: NodeIncarnationId,
14 pub instance_id: AgentInstanceId,
15 pub generation: SessionGeneration,
16}
17
18#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
19pub struct ManagedWorktreeLeaseRecord {
20 pub lease_id: ManagedWorktreeLeaseId,
21 pub source_workspace_id: WorkspaceId,
22 pub workspace_id: WorkspaceId,
23 pub profile_id: WorktreeProfileId,
24 pub profile_revision: WorktreeProfileRevision,
25 pub target_root: String,
26 pub branch: String,
27 pub base_commit: String,
28 pub expected_head: Option<String>,
29 pub retention: ManagedWorktreeRetention,
30 pub state: ManagedWorktreeLeaseState,
31 pub session_holders: Vec<ManagedWorktreeSessionHolder>,
32 pub record_holders: Vec<SessionRecordId>,
33 pub cleanup_failure: Option<ManagedWorktreeCleanupFailure>,
34 pub created_at_unix_ms: u64,
35 pub updated_at_unix_ms: u64,
36}
37
38impl ManagedWorktreeLeaseRecord {
39 pub fn snapshot(&self) -> ManagedWorktreeLeaseSnapshot {
40 ManagedWorktreeLeaseSnapshot {
41 lease_id: self.lease_id.clone(),
42 source_workspace_id: self.source_workspace_id.clone(),
43 workspace_id: self.workspace_id.clone(),
44 profile_id: self.profile_id.clone(),
45 profile_revision: self.profile_revision.clone(),
46 retention: self.retention,
47 state: self.state,
48 active_session_count: u16::try_from(self.session_holders.len()).unwrap_or(u16::MAX),
49 managed_record_count: u16::try_from(self.record_holders.len()).unwrap_or(u16::MAX),
50 cleanup_failure: self.cleanup_failure,
51 created_at_unix_ms: self.created_at_unix_ms,
52 updated_at_unix_ms: self.updated_at_unix_ms,
53 }
54 }
55
56 pub fn has_holders(&self) -> bool {
57 !self.session_holders.is_empty() || !self.record_holders.is_empty()
58 }
59}
60