Coverage for astrocyte/harness/paths.py: 96%
23 statements
« prev ^ index » next coverage.py v7.15.0, created at 2026-10-29 22:10 +0000
« prev ^ index » next coverage.py v7.15.0, created at 2026-10-29 22:10 +0000
1"""Where a local Astrocyte install keeps its config and data.
3One definition shared by ``astrocyte-mcp``, ``astrocyte setup`` and
4``astrocyte doctor``, so the server, the installer and the checker can never
5disagree about which file is "the" config.
6"""
8from __future__ import annotations
10import os
11from pathlib import Path
13CONFIG_ENV = "ASTROCYTE_CONFIG"
16def config_path() -> Path:
17 """``$ASTROCYTE_CONFIG``, else ``$XDG_CONFIG_HOME/astrocyte/astrocyte.yaml``
18 (``~/.config/astrocyte/astrocyte.yaml``)."""
19 if explicit := os.environ.get(CONFIG_ENV):
20 return Path(explicit).expanduser()
21 base = os.environ.get("XDG_CONFIG_HOME") or "~/.config"
22 return Path(base).expanduser() / "astrocyte" / "astrocyte.yaml"
25def data_dir() -> Path:
26 """``$XDG_DATA_HOME/astrocyte`` (``~/.local/share/astrocyte``)."""
27 base = os.environ.get("XDG_DATA_HOME") or "~/.local/share"
28 return Path(base).expanduser() / "astrocyte"
31def database_path() -> Path:
32 return data_dir() / "astrocyte.db"
35def state_dir() -> Path:
36 """``$XDG_STATE_HOME/astrocyte`` (``~/.local/state/astrocyte``): the agent
37 daemon's socket, lock, capture spool, per-session offsets and logs."""
38 base = os.environ.get("XDG_STATE_HOME") or "~/.local/state"
39 return Path(base).expanduser() / "astrocyte"
42def agentd_endpoint() -> Path:
43 """Where a TCP daemon (Windows) publishes its port and token."""
44 return state_dir() / "agentd.json"
47def agentd_socket() -> Path:
48 # Kept short: AF_UNIX paths are capped at ~104 bytes on macOS.
49 return state_dir() / "agentd.sock"
52def spool_dir() -> Path:
53 return state_dir() / "spool"