56 lines
2.1 KiB
Python
56 lines
2.1 KiB
Python
"""Where the setup's folders are: the one module whose code resolves them. Prose and tests still spell them out."""
|
|
|
|
import dataclasses
|
|
from collections.abc import Mapping
|
|
import os
|
|
import pathlib
|
|
|
|
# The release root: the folder the running code ships in, with bin/, skills/ and agents/.
|
|
RELEASE_ROOT = pathlib.Path(__file__).resolve().parents[2]
|
|
|
|
# Each folder below is named relative to the person's home folder.
|
|
|
|
# The Claude home: Claude Code's own folder, with its settings and transcripts. A release is deployed into it, so the release's 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"
|
|
|
|
|
|
def with_release_tools(env: Mapping[str, str]) -> dict[str, str]:
|
|
"""env with the release's tools first on `PATH`: what every claude the loop starts runs in, so its Bash tool and its hooks find each tool by its bare name."""
|
|
tools = str(RELEASE_ROOT / "bin")
|
|
rest = env.get("PATH", "")
|
|
if rest.split(os.pathsep)[0] == tools:
|
|
return dict(env)
|
|
return {**env, "PATH": f"{tools}{os.pathsep}{rest}" if rest else tools}
|
|
|
|
|
|
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)
|
|
|
|
|
|
@dataclasses.dataclass(frozen=True)
|
|
class Paths:
|
|
claude_code_transcripts: pathlib.Path
|
|
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
|
|
home: pathlib.Path
|
|
model_catalog: pathlib.Path
|
|
models_file: pathlib.Path
|
|
|
|
|
|
def paths_from(home: pathlib.Path) -> Paths:
|
|
claude = home / CLAUDE_HOME
|
|
return Paths(
|
|
claude_code_transcripts=claude / "projects",
|
|
claude_dir=claude,
|
|
config_clone=home / "code" / "claude-config",
|
|
home=home,
|
|
model_catalog=claude / "cache" / "model-catalog",
|
|
models_file=claude / "loop-claude-models.json",
|
|
)
|