Keep configs in ~/.config/build-release/ and tool state in ~/.local/state/build-release/, under XDG_* where set
CI / tests (pull_request) Successful in 6m34s

This commit is contained in:
2026-12-03 18:56:28 +01:00
parent 20c83f861f
commit 1ca2c8efe0
142 changed files with 1095 additions and 933 deletions
+34 -8
View File
@@ -12,10 +12,14 @@ RELEASE_ROOT = pathlib.Path(__file__).resolve().parents[2]
# The Claude home: Claude Code's own folder, with its settings and transcripts. A release is deployed into it, so its CLAUDE.md, rules/ and agents/ are read from it.
CLAUDE_HOME = ".claude"
# The config folder, which holds one folder per project, and do-epic's.
CONFIG_FOLDER = ".claude-projects"
# The state folder, which holds one folder per tool.
STATE_FOLDER = ".local/state"
# The setup's own folder under each of the two below.
SETUP = "build-release"
# Where the config folder is, unless the variable XDG_CONFIG_HOME names another place.
CONFIG_HOME = ".config"
XDG_CONFIG_HOME = "XDG_CONFIG_HOME"
# Where the state folder is, unless the variable XDG_STATE_HOME names another place.
STATE_HOME = ".local/state"
XDG_STATE_HOME = "XDG_STATE_HOME"
# Only a claude started through this has the tools on PATH. One a person starts by hand lacks them, as their shell does: the plan keeps short names such as `wait-for` out of a person's shell. README.md → Tools says how to call a tool there.
@@ -28,9 +32,26 @@ def with_release_tools(env: Mapping[str, str]) -> dict[str, str]:
return {**env, "PATH": f"{tools}{os.pathsep}{rest}" if rest else tools}
def config_folder(env: Mapping[str, str], home: pathlib.Path) -> pathlib.Path:
"""The config folder, which a person writes and backs up: one folder per project, do-epic's, and the model of each project."""
# The models file is here though the tools write it: it holds a person's choice per project, and is backed up with the configs.
return xdg_folder(env.get(XDG_CONFIG_HOME), home / CONFIG_HOME) / SETUP
def state_folder(env: Mapping[str, str], home: pathlib.Path) -> pathlib.Path:
"""The state folder of a tool that honours `XDG_STATE_HOME`."""
return pathlib.Path(env.get("XDG_STATE_HOME") or home / STATE_FOLDER)
"""The state folder, which the tools write: one folder per tool."""
# Every tool keeps its state here, none beside it, so that deleting this folder removes all the state the setup wrote.
return xdg_folder(env.get(XDG_STATE_HOME), home / STATE_HOME) / SETUP
# The XDG Base Directory Specification calls a relative path in one of its variables invalid, to be ignored: https://specifications.freedesktop.org/basedir-spec/latest/
def xdg_folder(named: str | None, default: pathlib.Path) -> pathlib.Path:
return pathlib.Path(named) if named and os.path.isabs(named) else default
def without_xdg_folders(env: Mapping[str, str]) -> dict[str, str]:
"""env without the person's own config and state folders, so that both lie under the home folder a caller names."""
return {name: value for name, value in env.items() if name not in (XDG_CONFIG_HOME, XDG_STATE_HOME)}
@dataclasses.dataclass(frozen=True)
@@ -39,18 +60,23 @@ class Paths:
claude_dir: pathlib.Path
# The development clone of this setup, where a change to it is made: claude_dir holds only a release, docs/decisions.md → `deploy:`.
config_clone: pathlib.Path
config_folder: pathlib.Path
home: pathlib.Path
model_catalog: pathlib.Path
models_file: pathlib.Path
state_folder: pathlib.Path
def paths_from(home: pathlib.Path) -> Paths:
def paths_from(home: pathlib.Path, env: Mapping[str, str]) -> Paths:
claude = home / CLAUDE_HOME
config = config_folder(env, home)
return Paths(
claude_code_transcripts=claude / "projects",
claude_dir=claude,
config_clone=home / "code" / "claude-config",
config_folder=config,
home=home,
model_catalog=claude / "cache" / "model-catalog",
models_file=claude / "loop-claude-models.json",
models_file=config / "models.json",
state_folder=state_folder(env, home),
)