From 31b8edb4c97bb10bbd9d5304949d70111350e16b Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Wed, 18 Nov 2026 09:51:12 +0100 Subject: [PATCH] Read do-epic's machine-wide settings and repo rule, and refuse to start while either is missing or misspelt --- bin/project_config/main.py | 2 ++ bin/project_config/settings.py | 38 ++++++++++++++++------- bin/project_config/test_project_config.py | 15 +++++++++ docs/reading-cost.md | 17 ++++++++++ 4 files changed, 61 insertions(+), 11 deletions(-) diff --git a/bin/project_config/main.py b/bin/project_config/main.py index 6b3e0120..02eeb8e0 100644 --- a/bin/project_config/main.py +++ b/bin/project_config/main.py @@ -128,6 +128,8 @@ Jira project's key before {id}, as here for the key ABC: The chunk for the issue ABC-123 is then on the branch ABC-123, in the worktree -ABC-123, and its commits and pull request are titled "ABC-123 - …". +`~/.claude-projects/do-epic/` holds do-epic's machine-wide settings, not a project's, so no project may use `do-epic` as its key and project-config reads nothing from that folder. + Exit 1, naming each fault on stderr, where no config names the checkout, or its config leaves out a setting, names an unknown one, misspells a path, a language or a template, sets `wait-for-approval` or `tooling-on-host` to anything but true or false, sets `notifier` to anything but mattermost or slack or diff --git a/bin/project_config/settings.py b/bin/project_config/settings.py index dca9390c..be902cd7 100644 --- a/bin/project_config/settings.py +++ b/bin/project_config/settings.py @@ -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" diff --git a/bin/project_config/test_project_config.py b/bin/project_config/test_project_config.py index 7a07c131..a369e1da 100644 --- a/bin/project_config/test_project_config.py +++ b/bin/project_config/test_project_config.py @@ -91,6 +91,13 @@ class LoadTest(ConfigCase): self.assertEqual(found.paths["standards"], self.home / ".claude" / "skills" / "larv-review" / "standards") self.assertEqual(tuple(found.paths), SETTINGS) + def test_the_do_epic_folder_is_no_projects_config_so_it_needs_no_checkout(self) -> None: + self.write("do-epic", 'jira-url = "https://acme.atlassian.net"\n') + self.write("acme", CLIENT) + found = load(self.checkout, self.checkout, self.home) + assert isinstance(found, ProjectConfig), found + self.assertEqual(found.key, "acme") + def test_a_plan_spelt_as_a_jira_epic_is_no_path(self) -> None: self.write("acme", JIRA_CLIENT) found = load(self.checkout, self.checkout, self.home) @@ -578,6 +585,10 @@ class HeldTest(ConfigCase): (elsewhere / "config.toml").write_text(CLIENT, encoding="utf-8") self.assertIsNone(held(elsewhere, self.home), "a config.toml outside ~/.claude-projects/") + def test_the_do_epic_folder_holds_no_projects_config(self) -> None: + folder = self.write("do-epic", CLIENT) + self.assertIsNone(held(folder, self.home)) + def test_a_configs_folder_reached_through_a_symlink_holds_its_config(self) -> None: target = self.home / "kept" / "acme" target.mkdir(parents=True) @@ -595,6 +606,10 @@ class EnvFilesTest(ConfigCase): self.write("none", CLIENT) self.assertEqual(env_files(self.home), [self.home / "acme.env", pathlib.Path("/srv/other.env")]) + def test_lists_do_epics_env_file_though_its_config_names_no_checkout(self) -> None: + self.write("do-epic", 'env-file = "~/jira.env"\n') + self.assertEqual(env_files(self.home), [self.home / "jira.env"]) + class ToolTest(ConfigCase): def test_prints_a_jira_plan_as_the_config_spells_it(self) -> None: diff --git a/docs/reading-cost.md b/docs/reading-cost.md index 62d3cdb1..731c705c 100644 --- a/docs/reading-cost.md +++ b/docs/reading-cost.md @@ -2570,3 +2570,20 @@ Read most (opens and searches): - `bin/failure.py` 1 - `bin/markdown_section/test_markdown_section.py` 1 - `bin/run-tests` 1 + +## Reading cost, chunk 4655673a30a9, finished 2026-11-17T11:46:22Z + +111449 new input tokens before the first commit. + +Read most (opens and searches): + +- `bin/review_replay/test_review_replay.py` 6 +- `README.md` 2 +- `bin/review_replay/main.py` 2 +- `bin/review_replay/replay.py` 2 +- `docs/decisions.md` 2 +- `CHANGELOG.md` 1 +- `bin/review_replay/omit_comparison.py` 1 +- `bin/rung_replay/archive.py` 1 +- `bin/rung_replay/search.py` 1 +- `bin/rung_replay/test_rung_replay.py` 1