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

1"""Where a local Astrocyte install keeps its config and data. 

2 

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""" 

7 

8from __future__ import annotations 

9 

10import os 

11from pathlib import Path 

12 

13CONFIG_ENV = "ASTROCYTE_CONFIG" 

14 

15 

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" 

23 

24 

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" 

29 

30 

31def database_path() -> Path: 

32 return data_dir() / "astrocyte.db" 

33 

34 

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" 

40 

41 

42def agentd_endpoint() -> Path: 

43 """Where a TCP daemon (Windows) publishes its port and token.""" 

44 return state_dir() / "agentd.json" 

45 

46 

47def agentd_socket() -> Path: 

48 # Kept short: AF_UNIX paths are capped at ~104 bytes on macOS. 

49 return state_dir() / "agentd.sock" 

50 

51 

52def spool_dir() -> Path: 

53 return state_dir() / "spool"