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
//! Path resolution helpers — session storage root, etc.
use ;
use ProjectDirs;
/// Default session persistence root directory, resolved via the platform's standard
/// per-app state/data location (the `directories` crate):
/// - Linux: `$XDG_STATE_HOME/defect/sessions` (or `~/.local/state/defect/sessions`)
/// - macOS: `~/Library/Application Support/defect/sessions`
/// - Windows: `%LOCALAPPDATA%\defect\sessions`
///
/// On Linux `state_dir()` follows XDG; on macOS/Windows there is no separate state
/// directory, so we fall back to the per-app data directory.
///
/// # Errors
///
/// Returns an error when no home directory can be determined at all (e.g. a stripped
/// environment with no `HOME` on Unix or no profile dir on Windows) — in that case the
/// OS itself cannot tell us where per-user data belongs.
/// Session persistence root directory for `--local` sandbox mode:
/// `<repo-root>/.defect/sessions`.
///
/// The project root is detected via `.git` (same source as the project layer in the
/// config system); if no `.git` is found, falls back to `cwd/.defect/sessions` so that
/// sandbox directories without a repository can still be used.