|
|
|
@@ -17,6 +17,10 @@ from plan.ranking import variables
|
|
|
|
|
|
|
|
|
|
PROJECTS = ".claude-projects"
|
|
|
|
|
CONFIG = "config.toml"
|
|
|
|
|
# The folder of do-epic's machine-wide settings, which names no checkout. No project may use it as its key.
|
|
|
|
|
DO_EPIC = "do-epic"
|
|
|
|
|
# A Jira Cloud or Confluence Cloud site's address: only https, so the credentials are never sent in the clear.
|
|
|
|
|
SITE = r"https://[A-Za-z0-9.-]+(?::[0-9]+)?"
|
|
|
|
|
# Every path a project sets, by its role. Three readers, seated as the human who writes the config, picked the spelling from four candidates. They picked role names over file names, which a client's project doesn't share.
|
|
|
|
|
SETTINGS = ("plan", "working-rules", "decisions", "score-anchors", "comprehension-history", "reading-cost", "changelog", "goals-and-audience", "principles", "standards")
|
|
|
|
|
# They also picked a prefix over bare relative paths: each line says its own place, and a relative path with no prefix fails instead of landing somewhere by default.
|
|
|
|
@@ -177,7 +181,7 @@ def load(top: pathlib.Path, main: pathlib.Path, home: pathlib.Path) -> ProjectCo
|
|
|
|
|
top is the worktree that asks, and main itself outside a worktree. A `checkout:` path lands in top.
|
|
|
|
|
A config that cannot be read fails every project, since it may be the one that names main."""
|
|
|
|
|
named: list[tuple[pathlib.Path, dict[str, object]]] = []
|
|
|
|
|
for file in sorted((home / PROJECTS).glob(f"*/{CONFIG}")):
|
|
|
|
|
for file in configs(home):
|
|
|
|
|
config = read(file, home)
|
|
|
|
|
if isinstance(config, Failure):
|
|
|
|
|
return config
|
|
|
|
@@ -291,13 +295,13 @@ def name_of(value: object) -> str | None:
|
|
|
|
|
|
|
|
|
|
def epic_of(value: object) -> Epic | None:
|
|
|
|
|
"""The epic a setting's value spells; None where it spells none. Only https, so the credentials are never sent in the clear."""
|
|
|
|
|
spelt = isinstance(value, str) and re.fullmatch(rf"{JIRA}(https://[A-Za-z0-9.-]+(?::[0-9]+)?)/browse/([A-Z][A-Z0-9_]*-[0-9]+)", value)
|
|
|
|
|
spelt = isinstance(value, str) and re.fullmatch(rf"{JIRA}({SITE})/browse/([A-Z][A-Z0-9_]*-[0-9]+)", value)
|
|
|
|
|
return Epic(spelt.group(1), spelt.group(2)) if spelt else None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def page_of(value: object) -> Page | None:
|
|
|
|
|
"""The page a setting's value spells; None where it spells none. Only https, as for an epic."""
|
|
|
|
|
spelt = isinstance(value, str) and re.fullmatch(rf"{CONFLUENCE}(https://[A-Za-z0-9.-]+(?::[0-9]+)?)/wiki/spaces/[^/?#]+/pages/([0-9]+)(?:/[^/?#]*)?", value)
|
|
|
|
|
spelt = isinstance(value, str) and re.fullmatch(rf"{CONFLUENCE}({SITE})/wiki/spaces/[^/?#]+/pages/([0-9]+)(?:/[^/?#]*)?", value)
|
|
|
|
|
return Page(spelt.group(1), spelt.group(2), spelt.string) if spelt else None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -339,25 +343,37 @@ def lies_in(path: pathlib.Path, *places: pathlib.Path) -> bool:
|
|
|
|
|
def held(folder: pathlib.Path, home: pathlib.Path) -> ProjectConfig | Failure | None:
|
|
|
|
|
"""The config in folder, read as its project's main checkout reads it; None where folder is not a config's folder under home."""
|
|
|
|
|
# Matched on resolved paths, as git names a folder, so a config's folder reached through a symlink is still found.
|
|
|
|
|
file = next((file for file in (home / PROJECTS).glob(f"*/{CONFIG}") if file.parent.resolve() == folder.resolve()), None)
|
|
|
|
|
file = next((file for file in configs(home) if file.parent.resolve() == folder.resolve()), None)
|
|
|
|
|
if file is None:
|
|
|
|
|
return None
|
|
|
|
|
config = read(file, home)
|
|
|
|
|
return config if isinstance(config, Failure) else load(config[0], config[0], home)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def configs(home: pathlib.Path) -> list[pathlib.Path]:
|
|
|
|
|
"""Every project's config file under home, in key order. do-epic's is no project's."""
|
|
|
|
|
return sorted(file for file in (home / PROJECTS).glob(f"*/{CONFIG}") if file.parent.name != DO_EPIC)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def env_files(home: pathlib.Path) -> list[pathlib.Path]:
|
|
|
|
|
"""Every config's env-file, read without the checks load makes, so a config that fails them still keeps its credentials guarded; a config that cannot be read names none."""
|
|
|
|
|
configs = [read(file, home) for file in sorted((home / PROJECTS).glob(f"*/{CONFIG}"))]
|
|
|
|
|
return [path for config in configs if not isinstance(config, Failure) and (path := anywhere(config[1].get(ENV_FILE), home))]
|
|
|
|
|
"""Every config's env-file, do-epic's included, read without the checks load makes, so a config that fails them still keeps its credentials guarded; a config that cannot be read names none."""
|
|
|
|
|
values = [parsed(file) for file in (*configs(home), home / PROJECTS / DO_EPIC / CONFIG)]
|
|
|
|
|
return [path for found in values if not isinstance(found, Failure) and (path := anywhere(found.get(ENV_FILE), home))]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def parsed(file: pathlib.Path) -> dict[str, object] | Failure:
|
|
|
|
|
"""The TOML values file holds."""
|
|
|
|
|
try:
|
|
|
|
|
return tomllib.loads(file.read_text(encoding="utf-8"))
|
|
|
|
|
except (OSError, UnicodeDecodeError, tomllib.TOMLDecodeError) as failure:
|
|
|
|
|
return Failure(f"cannot read {file}: {failure}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def read(file: pathlib.Path, home: pathlib.Path) -> tuple[pathlib.Path, dict[str, object]] | Failure:
|
|
|
|
|
"""The checkout a config names, as an absolute path, and its other values."""
|
|
|
|
|
try:
|
|
|
|
|
values = tomllib.loads(file.read_text(encoding="utf-8"))
|
|
|
|
|
except (OSError, UnicodeDecodeError, tomllib.TOMLDecodeError) as failure:
|
|
|
|
|
return Failure(f"cannot read {file}: {failure}")
|
|
|
|
|
values = parsed(file)
|
|
|
|
|
if isinstance(values, Failure):
|
|
|
|
|
return values
|
|
|
|
|
checkout = anywhere(values.get("checkout"), home)
|
|
|
|
|
if checkout is None:
|
|
|
|
|
found = f"not {values['checkout']!r}" if "checkout" in values else "and is missing"
|
|
|
|
|