Skip to main content

systemprompt_cli/
paths.rs

1//! Resolved filesystem paths the CLI operates against.
2//!
3//! Copyright (c) systemprompt.io — Business Source License 1.1.
4//! See <https://systemprompt.io> for licensing details.
5
6use std::path::PathBuf;
7
8use systemprompt_cloud::ProjectContext;
9use systemprompt_cloud::paths::{CloudPath, get_cloud_paths};
10
11#[derive(Debug)]
12pub struct ResolvedPaths {
13    project_ctx: ProjectContext,
14    has_local_dir: bool,
15}
16
17impl ResolvedPaths {
18    pub fn discover() -> Self {
19        let project_ctx = ProjectContext::discover();
20        let has_local_dir = project_ctx.systemprompt_dir().exists();
21        Self {
22            project_ctx,
23            has_local_dir,
24        }
25    }
26
27    pub fn sessions_dir(&self) -> PathBuf {
28        if self.has_local_dir {
29            self.project_ctx.sessions_dir()
30        } else {
31            let cloud_paths = get_cloud_paths();
32            cloud_paths.resolve(CloudPath::SessionsDir)
33        }
34    }
35
36    pub fn tenants_path(&self) -> PathBuf {
37        if self.has_local_dir {
38            self.project_ctx.local_tenants()
39        } else {
40            let cloud_paths = get_cloud_paths();
41            cloud_paths.resolve(CloudPath::Tenants)
42        }
43    }
44
45    pub fn profiles_dir(&self) -> PathBuf {
46        self.project_ctx.profiles_dir()
47    }
48}