Skip to main content

steer_workspace/
manager.rs

1use async_trait::async_trait;
2use serde::{Deserialize, Serialize};
3use std::sync::Arc;
4
5use crate::error::{EnvironmentManagerResult, WorkspaceManagerResult};
6use crate::{
7    EnvironmentId, EnvironmentInfo, RepoId, RepoInfo, Workspace, WorkspaceId, WorkspaceInfo,
8    WorkspaceStatus,
9};
10
11#[derive(Debug, Clone, Serialize, Deserialize)]
12pub struct CreateEnvironmentRequest {
13    pub root: Option<std::path::PathBuf>,
14    pub name: Option<String>,
15}
16
17#[derive(Debug, Clone, Serialize, Deserialize)]
18pub enum EnvironmentDeletePolicy {
19    Hard,
20    Soft,
21}
22
23#[derive(Debug, Clone, Serialize, Deserialize)]
24pub struct EnvironmentDescriptor {
25    pub environment_id: EnvironmentId,
26    pub root: std::path::PathBuf,
27}
28
29#[async_trait]
30pub trait EnvironmentManager: Send + Sync + std::fmt::Debug {
31    async fn create_environment(
32        &self,
33        request: CreateEnvironmentRequest,
34    ) -> EnvironmentManagerResult<EnvironmentDescriptor>;
35
36    async fn get_environment(
37        &self,
38        environment_id: EnvironmentId,
39    ) -> EnvironmentManagerResult<EnvironmentDescriptor>;
40
41    async fn delete_environment(
42        &self,
43        environment_id: EnvironmentId,
44        policy: EnvironmentDeletePolicy,
45    ) -> EnvironmentManagerResult<()>;
46
47    async fn environment_info(
48        &self,
49        environment_id: EnvironmentId,
50    ) -> EnvironmentManagerResult<EnvironmentInfo>;
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
54pub enum WorkspaceCreateStrategy {
55    JjWorkspace,
56    GitWorktree,
57}
58
59#[derive(Debug, Clone, Serialize, Deserialize)]
60pub struct CreateWorkspaceRequest {
61    pub repo_id: RepoId,
62    pub name: Option<String>,
63    pub parent_workspace_id: Option<WorkspaceId>,
64    pub strategy: WorkspaceCreateStrategy,
65}
66
67#[derive(Debug, Clone, Serialize, Deserialize)]
68pub struct ListWorkspacesRequest {
69    pub environment_id: EnvironmentId,
70}
71
72#[derive(Debug, Clone, Serialize, Deserialize)]
73pub struct DeleteWorkspaceRequest {
74    pub workspace_id: WorkspaceId,
75}
76
77#[async_trait]
78pub trait WorkspaceManager: Send + Sync + std::fmt::Debug {
79    async fn resolve_workspace(
80        &self,
81        path: &std::path::Path,
82    ) -> WorkspaceManagerResult<WorkspaceInfo>;
83
84    async fn create_workspace(
85        &self,
86        request: CreateWorkspaceRequest,
87    ) -> WorkspaceManagerResult<WorkspaceInfo>;
88
89    async fn list_workspaces(
90        &self,
91        request: ListWorkspacesRequest,
92    ) -> WorkspaceManagerResult<Vec<WorkspaceInfo>>;
93
94    async fn open_workspace(
95        &self,
96        workspace_id: WorkspaceId,
97    ) -> WorkspaceManagerResult<Arc<dyn Workspace>>;
98
99    async fn get_workspace_status(
100        &self,
101        workspace_id: WorkspaceId,
102    ) -> WorkspaceManagerResult<WorkspaceStatus>;
103
104    async fn delete_workspace(&self, request: DeleteWorkspaceRequest)
105    -> WorkspaceManagerResult<()>;
106}
107
108#[async_trait]
109pub trait RepoManager: Send + Sync + std::fmt::Debug {
110    async fn resolve_repo(
111        &self,
112        environment_id: EnvironmentId,
113        path: &std::path::Path,
114    ) -> WorkspaceManagerResult<RepoInfo>;
115
116    async fn list_repos(
117        &self,
118        environment_id: EnvironmentId,
119    ) -> WorkspaceManagerResult<Vec<RepoInfo>>;
120}