From b93d3799c319971bbf81bf7b0d32bc2f0838561f Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Wed, 18 Nov 2026 10:28:39 +0100 Subject: [PATCH] Answer round 1: check the model against the ladder, keep faults together, fix prose --- README.md | 1 + bin/do_epic/config.py | 35 +++++++++++++++++++++------------- bin/do_epic/test_do_epic.py | 12 +++++++++++- bin/project_config/main.py | 5 +++-- bin/project_config/settings.py | 12 ++++++------ 5 files changed, 43 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 430fa690..88e3255e 100644 --- a/README.md +++ b/README.md @@ -213,6 +213,7 @@ Install puts only `loop-claude` on `PATH`; call the others by their path, such a - `branch_chunks/` cuts a default branch into chunks and finds, for each, the items it shipped and the later chunks that fixed its code, for `score_outcomes` and `routing_figures`. It imports `reading_cost`'s record path. - `command_lines/` reads a shell command: its simple commands, and a docker call's subcommand and memory limits, for `command_patterns`, `reading_cost`, `routing_figures`, `rule_hook` and `run_heavy`. - `deploy_release` imports `release_plan`'s `release_standing`. +- `do_epic` imports `project_config`'s settings and `model_routing`'s ladder file. - `forge/` tells a GitHub origin from a Gitea one and runs that forge's CLI (`commands.py`), and finds a pull request and waits for its checks (`pulls.py`), for `chunk_preflight`, `chunk_pr`, `deploy_release` and `larv_review`. - `git_cli/` runs git for every tool (`git_repo.py`), and reads the git calls in a shell command (`git_command.py`). - `judge_replay` imports `loop_claude`'s judge, verdicts, premises and records. diff --git a/bin/do_epic/config.py b/bin/do_epic/config.py index 8b223b3b..c38fba90 100644 --- a/bin/do_epic/config.py +++ b/bin/do_epic/config.py @@ -8,13 +8,19 @@ One pair per machine, the same for every epic (docs/decisions.md → `do-epic: d clone-folder = "~/code" language = "Swedish" -`jira-url` is the Jira site's address, only https. `env-file` is the file of Jira credentials, a path that starts with / or ~/ and lies outside `~/.claude-projects` and the clone folder, so that no git remote receives them. `repoless-model` is the model that works an epic item with no repo. `clone-folder` is the folder a missing repo is cloned into; `~/code` where left out. `language` is the default language of Jira text, by its English name; English where left out. `repo-rule.md` is prose that says how to tell an item's repo.""" +- `jira-url` is the Jira site's address: https, a host, and no path. +- `env-file` is the file of Jira credentials: a path that starts with / or ~/, outside `~/.claude-projects` and the clone folder, which are git checkouts or hold them. +- `repoless-model` is the model that works an epic item with no repo: a model on the routing ladder, `model_routing/routing-ladder.json`. +- `clone-folder` is the folder a missing repo is cloned into: a path that starts with / or ~/. `~/code` where left out. +- `language` is the default language of Jira text, by its English name. English where left out. +- `repo-rule.md` is prose that says how to tell an item's repo, and mustn't be blank.""" import dataclasses import pathlib import re from project_config.settings import anywhere, CONFIG, DO_EPIC, ENV_FILE, LANGUAGE, language_fault, lies_in, parsed, PROJECTS, SITE from failure import Failure +from model_routing.ladder_file import read_ladder, SHIPPED REPO_RULE = "repo-rule.md" # Three readers, seated as the human who writes this config, picked these spellings from four candidates each, 3-0: `jira-url` over `site`, `clone-folder` over `repos-folder` (which reads as the folder of repos that already exist) and `repoless-model` over `no-repo-model`. `env-file` and `language` keep the names a project's config gives them. @@ -23,8 +29,7 @@ REPOLESS_MODEL = "repoless-model" CLONE_FOLDER = "clone-folder" SETTINGS = (JIRA_URL, ENV_FILE, REPOLESS_MODEL) OPTIONAL = (CLONE_FOLDER, LANGUAGE) -# A model id as Claude Code takes it, such as claude-opus-5-5 or claude-sonnet-4-5-20250929. -MODEL_ID = re.compile(r"claude-[a-z]+-[0-9]+(?:-[0-9]+)*") +LISTED = f"The settings are {', '.join(SETTINGS)}, and optionally {' and '.join(OPTIONAL)}." @dataclasses.dataclass(frozen=True) @@ -39,16 +44,21 @@ class DoEpicConfig: repo_rule: str -def load(home: pathlib.Path) -> DoEpicConfig | Failure: - """The settings and the repo rule under home; a Failure naming each missing or misspelt one, so that do-epic refuses to start.""" +def load(home: pathlib.Path, ladder_file: pathlib.Path = SHIPPED) -> DoEpicConfig | Failure: + """The settings and the repo rule under home; a Failure naming each missing or misspelt one it finds, so that do-epic refuses to start.""" folder = home / PROJECTS / DO_EPIC values = parsed(folder / CONFIG) if isinstance(values, Failure): - return values + return Failure(f"{values.reason}. {LISTED}") + ladder = read_ladder(ladder_file) + if isinstance(ladder, Failure): + return ladder + models = sorted({rung.model for rung in ladder.rungs}) try: rule = (folder / REPO_RULE).read_text(encoding="utf-8") + unread = None except (OSError, UnicodeDecodeError) as failure: - return Failure(f"cannot read {folder / REPO_RULE}: {failure}") + rule, unread = "", f"cannot read {folder / REPO_RULE}: {failure}" clone_folder = anywhere(values.get(CLONE_FOLDER, "~/code"), home) env_file = anywhere(values.get(ENV_FILE), home) language = values.get(LANGUAGE, "English") @@ -59,14 +69,13 @@ def load(home: pathlib.Path) -> DoEpicConfig | Failure: *([f"`{JIRA_URL}` is {url!r}, not a site's https address without a path, such as \"https://acme.atlassian.net\""] if JIRA_URL in values and not (isinstance(url, str) and re.fullmatch(SITE, url)) else []), *([f"`{CLONE_FOLDER}` is {values[CLONE_FOLDER]!r}, not a path that starts with / or ~/"] if clone_folder is None else []), *([f"`{ENV_FILE}` is {values[ENV_FILE]!r}, not a path that starts with / or ~/"] if ENV_FILE in values and env_file is None else []), - # lies_in resolves both sides, so a symlink can't lead the file into a place it must stay out of. - *([f"`{ENV_FILE}` is {values[ENV_FILE]!r}, inside ~/{PROJECTS} or the clone folder, which a git remote may receive"] if env_file and lies_in(env_file, home / PROJECTS, *([clone_folder] if clone_folder else [])) else []), + *([f"`{ENV_FILE}` is {values[ENV_FILE]!r}, inside ~/{PROJECTS} or the clone folder, which hold git checkouts"] if env_file and lies_in(env_file, home / PROJECTS, *([clone_folder] if clone_folder else [])) else []), *([f"`{LANGUAGE}` is {language!r}, {fault}"] if LANGUAGE in values and (fault := language_fault(language)) else []), - *([f"`{REPOLESS_MODEL}` is {model!r}, not a model id such as \"claude-opus-5-5\""] if REPOLESS_MODEL in values and not (isinstance(model, str) and MODEL_ID.fullmatch(model)) else []), - *([f"`{REPO_RULE}` is blank"] if not rule.strip() else []), + *([f"`{REPOLESS_MODEL}` is {model!r}, not a model on the routing ladder: {', '.join(models)}"] if REPOLESS_MODEL in values and model not in models else []), + *([unread] if unread else [f"`{REPO_RULE}` is blank"] if not rule.strip() else []), ] if faults: - return Failure(f"{folder}: {'; '.join(faults)}. The settings are {', '.join(SETTINGS)}, and optionally {' and '.join(OPTIONAL)}.") - # faults names a missing or misspelt value of each type asserted here. + return Failure(f"{folder}: {'; '.join(faults)}. {LISTED}") + # Without a fault, each value above is present and of the type asserted here. assert clone_folder and env_file and isinstance(url, str) and isinstance(model, str) and isinstance(language, str) return DoEpicConfig(folder, url, env_file, clone_folder, language, model, rule) diff --git a/bin/do_epic/test_do_epic.py b/bin/do_epic/test_do_epic.py index 706a0f92..2f87a1d7 100644 --- a/bin/do_epic/test_do_epic.py +++ b/bin/do_epic/test_do_epic.py @@ -43,13 +43,16 @@ class ConfigTest(unittest.TestCase): assert isinstance(found, DoEpicConfig), found self.assertEqual((found.clone_folder, found.language), (pathlib.Path("/srv/repos"), "Brazilian Portuguese")) - def test_refuses_while_the_config_is_missing(self) -> None: + def test_refuses_while_the_config_is_missing_and_lists_the_settings(self) -> None: self.write(None) self.assertIn(f"cannot read {self.folder / 'config.toml'}", self.failure()) + self.assertIn("The settings are jira-url, env-file, repoless-model", self.failure()) def test_refuses_while_the_rule_is_missing_or_blank(self) -> None: self.write(rule=None) self.assertIn(f"cannot read {self.folder / 'repo-rule.md'}", self.failure()) + self.write(SETTINGS.replace("claude-opus-5-5", "x"), rule=None) + self.assertIn("`repoless-model` is 'x'", self.failure(), "a missing rule doesn't hide the settings' faults") self.write(rule=" \n") self.assertIn("`repo-rule.md` is blank", self.failure()) @@ -71,6 +74,7 @@ class ConfigTest(unittest.TestCase): ('clone-folder = "code"', "clone-folder"), ('language = "sv_SE"', "language"), ('repoless-model = "opus"', "repoless-model"), + ('repoless-model = "claude-opsu-5-5"', "repoless-model"), ): with self.subTest(line): self.write("\n".join([ln for ln in SETTINGS.splitlines() if not ln.startswith(name)] + [line])) @@ -86,6 +90,12 @@ class ConfigTest(unittest.TestCase): self.write(SETTINGS.replace("~/jira.env", "~/clones/jira.env") + 'clone-folder = "~/clones"\n') self.assertIn("`env-file` is", self.failure()) + def test_refuses_while_the_routing_ladder_cannot_be_read(self) -> None: + self.write() + found = load(self.home, self.home / "no-ladder.json") + assert isinstance(found, Failure), found + self.assertIn("no-ladder.json", found.reason) + def test_reports_every_fault_at_once(self) -> None: self.write('jira-url = "acme"\nrepoless-model = "x"\n') reason = self.failure() diff --git a/bin/project_config/main.py b/bin/project_config/main.py index 02eeb8e0..a7b824bf 100644 --- a/bin/project_config/main.py +++ b/bin/project_config/main.py @@ -6,6 +6,9 @@ Run inside a checkout, or a worktree of one. It finds the config that names the ~/.claude-projects//config.toml, and prints each setting and its absolute path, as in `plan: /home/me/code/acme/todo.md`. Given a setting, it prints only that setting's path. +`~/.claude-projects/do-epic/` holds do-epic's machine-wide settings, not a project's. It needs no `checkout`, +and project-config doesn't read anything from it, so no project may use `do-epic` as its key. + The config is TOML. `checkout` names the project's main checkout, and every setting in the example below is a path: "checkout:" inside the checkout, "folder:" inside the config's own folder, or one that starts with / or ~/. In a worktree, a "checkout:" path is the worktree's own file. @@ -128,8 +131,6 @@ 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 be902cd7..c72c7174 100644 --- a/bin/project_config/settings.py +++ b/bin/project_config/settings.py @@ -17,7 +17,7 @@ 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. +# The key of do-epic's machine-wide settings: the folder's config.toml has no `checkout`, so no project may use the 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]+)?" @@ -294,13 +294,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.""" + """The epic a setting's value spells; None where it spells none.""" 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.""" + """The page a setting's value spells; None where it spells none.""" 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 @@ -351,18 +351,18 @@ def held(folder: pathlib.Path, home: pathlib.Path) -> ProjectConfig | Failure | 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.""" + """Every project's config file under home, in key order. do-epic's machine-wide config is not a 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, 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.""" + """Every config's env-file, do-epic's included. Each is read without the checks load makes, so a config that fails them still keeps its credentials guarded. A config that can't be read doesn't name one.""" 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.""" + """The TOML values in file; a Failure where file can't be read or parsed.""" try: return tomllib.loads(file.read_text(encoding="utf-8")) except (OSError, UnicodeDecodeError, tomllib.TOMLDecodeError) as failure: