Skip to main content

allot_shared/
platform.rs

1//! What differs between operating systems: executable names, the processes Claude Code and
2//! consoles show up as, where the home directory comes from, and how paths are spelled and
3//! compared.
4
5/// `name` with the executable suffix of the target OS.
6macro_rules! exe {
7    ($name:literal) => {
8        if cfg!(windows) {
9            concat!($name, ".exe")
10        } else {
11            $name
12        }
13    };
14}
15
16/// Suffix of executable file names: `.exe` on Windows, empty elsewhere.
17pub const EXE_SUFFIX: &str = std::env::consts::EXE_SUFFIX;
18
19/// The `allot` CLI's executable.
20pub const CLI_EXE: &str = exe!("allot");
21
22/// The daemon's executable.
23pub const DAEMON_EXE: &str = exe!("allotd");
24
25/// The MCP server's executable.
26pub const MCP_EXE: &str = exe!("allot-mcp");
27
28/// The coordinator's own executables, which binding skips and a kill never touches.
29pub const ALLOT_BINARIES: [&str; 3] = [CLI_EXE, DAEMON_EXE, MCP_EXE];
30
31/// Process names of a Claude Code session, the parent of its commands and MCP servers.
32pub const SESSION_ROOTS: &[&str] = &[exe!("claude")];
33
34/// Console hosts the OS starts beside console programs; never a command itself.
35pub const CONSOLE_HOSTS: &[&str] = if cfg!(windows) { &["conhost.exe"] } else { &[] };
36
37/// The environment variable that holds the user's home directory.
38pub const HOME_VAR: &str = if cfg!(windows) { "USERPROFILE" } else { "HOME" };
39
40/// The data directory as messages to the user spell it.
41pub const DATA_DIR_TEXT: &str = if cfg!(windows) {
42    r"%USERPROFILE%\.allot"
43} else {
44    "~/.allot"
45};
46
47/// The daemon's log file as messages to the user spell it.
48pub const DAEMON_LOG_TEXT: &str = if cfg!(windows) {
49    r"%USERPROFILE%\.allot\logsllotd.log"
50} else {
51    "~/.allot/logs/allotd.log"
52};
53
54/// How the target OS spells and compares paths.
55pub const PATH_STYLE: PathStyle = if cfg!(windows) {
56    PathStyle::Windows
57} else if cfg!(target_os = "macos") {
58    PathStyle::Macos
59} else {
60    PathStyle::Linux
61};
62
63/// How an OS spells and compares paths.
64#[derive(Debug, Clone, Copy, PartialEq, Eq)]
65pub enum PathStyle {
66    /// Backslashes, drive letters, letter case ignored.
67    Windows,
68    /// Slashes, letter case ignored, as on the default APFS volumes.
69    Macos,
70    /// Slashes, letter case significant; also every other Unix.
71    Linux,
72}
73
74impl PathStyle {
75    /// Whether two paths that differ only in letter case name the same file.
76    pub const fn ignores_case(self) -> bool {
77        matches!(self, Self::Windows | Self::Macos)
78    }
79}