diff --git a/README.md b/README.md index dc3493dd..d4fc0a09 100644 --- a/README.md +++ b/README.md @@ -286,7 +286,7 @@ Install puts only `loop-claude` on `PATH`; call the others by their path, such a - `e2e/` holds `do-epic-e2e`. - `loop_claude` runs `chunk-preflight` as a process of its own. - `loop_effects/` holds `Effects`: the processes, terminal, clock and git a tool reaches, injected so its tests can script them. loop-claude, do-epic, both replay tools and `reviewer-merge-trials`' driver use it. -- `loop_state/` holds where loop-claude and do-epic keep their files (`paths.py`), which `rung_replay` reads too. +- `loop_state/` holds `paths.py`, the one module under `bin/` that resolves the setup's folders: the release root, which is the folder the running code ships in, the Claude home, the config folder and the state folder. `repo_checks` fails another module under `bin/`, tests aside, that names one as a quoted path part, such as `".claude"`, or finds the release root from `__file__`. - `model_routing/` holds the shipped routing ladder (`routing-ladder.json`) and its steps (`ladder.py`), and reads a ladder from that file or a project's own (`ladder_file.py`), for loop-claude, `rule_hook`, `do_epic`, both replay tools and `subagent-rung`. It finds a project's config folder through `project_config`. It also holds the list prices, which `routing_figures` and `transcript_archive` read. - `notifier/` sends the human a DM through the notifier a project's config names, for `notify` and for loop-claude through `loop_effects`. Its backends are `mattermost.py` and `slack.py`. - `transcript_archive/` stores loop-claude's transcripts. Its `project_key.py` names each project's archive folder, loop-claude session and models-file entry. diff --git a/bin/chunk_driver/claims.py b/bin/chunk_driver/claims.py index e8837c80..54cd196a 100644 --- a/bin/chunk_driver/claims.py +++ b/bin/chunk_driver/claims.py @@ -9,10 +9,11 @@ import typing from failure import Failure from transcript_archive.project_key import project_key +from loop_state.paths import STATE_FOLDER from agent_cycle import tmux # Under the home folder, a folder per project key holds LOCK. -CLAIMS = ".local/state/loop-claude" +CLAIMS = f"{STATE_FOLDER}/loop-claude" # The file an entry point keeps locked with flock while it lists the windows of a project's chunks and starts new ones. Two loops whose chunks finish together then don't start a chunk twice, and do-epic, which holds the same lock, never starts a chunk in a checkout while loop-claude does. LOCK = "starting" # The flag that tells the entry point in a window its chunk, as `--chunk item-372` for loop-claude and `--chunk ABC-34 ABC-12` for do-epic. Nobody types it, so no panel picked it. diff --git a/bin/chunk_driver/doubles.py b/bin/chunk_driver/doubles.py index 239478e0..ef93b53b 100644 --- a/bin/chunk_driver/doubles.py +++ b/bin/chunk_driver/doubles.py @@ -12,5 +12,5 @@ from agent_cycle.doubles import WINDOW def a_loop(effects: Effects, **fields: typing.Any) -> Loop: """A loop in /r on effects, with fields in place of its defaults.""" home = pathlib.Path("/h") - defaults = {"root": "/r", "session": session.session_named("A proj a-driver", home / ".claude" / "projects"), "paths": paths.paths_from(home), "env": {}, "launcher": pathlib.Path("/b/a-driver"), "window": WINDOW} + defaults = {"root": "/r", "session": session.session_named("A proj a-driver", paths.paths_from(home).claude_code_transcripts), "paths": paths.paths_from(home), "env": {}, "launcher": pathlib.Path("/b/a-driver"), "window": WINDOW} return Loop(**{**defaults, **fields}, effects=effects) diff --git a/bin/chunk_driver/project/records.py b/bin/chunk_driver/project/records.py index 352e2d54..714183a3 100644 --- a/bin/chunk_driver/project/records.py +++ b/bin/chunk_driver/project/records.py @@ -1,5 +1,6 @@ import pathlib +from loop_state.paths import CLAUDE_HOME from failure import Failure from project_config.main import located from chunk_driver.project.text_file import read_utf8 @@ -15,7 +16,7 @@ HUMAN_RULES_FILE = "CLAUDE.md" HUMAN_RULE_DIR = "rules" # How the judge's prompt names the records above, in the order it reads them. RECORDS_NAMED = "the project's working rules and decisions, then the human's rules for every project" -HUMAN_RULE_NAMES = (f"~/.claude/{HUMAN_RULES_FILE}", f"~/.claude/{HUMAN_RULE_DIR}/", "the project's review standards") +HUMAN_RULE_NAMES = (f"~/{CLAUDE_HOME}/{HUMAN_RULES_FILE}", f"~/{CLAUDE_HOME}/{HUMAN_RULE_DIR}/", "the project's review standards") CONSEQUENCE = "the judge cannot read the records" @@ -55,5 +56,5 @@ def file_text(path: pathlib.Path) -> str | Failure: def named(rule: pathlib.Path, home: pathlib.Path, claude_dir: pathlib.Path) -> str: """rule's path as the human writes it: under ~/.claude, or ~/ for the rest of home, or else in full.""" if rule.is_relative_to(claude_dir): - return f"~/.claude/{rule.relative_to(claude_dir)}" + return f"~/{CLAUDE_HOME}/{rule.relative_to(claude_dir)}" return f"~/{rule.relative_to(home)}" if rule.is_relative_to(home) else str(rule) diff --git a/bin/chunk_pr/main.py b/bin/chunk_pr/main.py index 380fa8a1..7f8a9873 100644 --- a/bin/chunk_pr/main.py +++ b/bin/chunk_pr/main.py @@ -130,10 +130,11 @@ from forge.commands import Forge, forge_of, gitea, Run, runner from atlassian.jira import ISSUE_KEY from project_config.main import located from project_config.settings import ProjectConfig +from loop_state.paths import RELEASE_ROOT from plan_store.plans import says_no_item from project_config import templates -BIN = pathlib.Path(__file__).resolve().parents[1] +BIN = RELEASE_ROOT / "bin" # How long merge waits for a check to report before it takes a pull request without any as passed: CI queues its checks within seconds of a push, and merge may run right after one. NO_CHECKS_SECONDS = 60 # The file, in the git folder that every worktree of the checkout shares, that a merge keeps locked with flock for its turn: so every chunk of the project on this machine queues on it. diff --git a/bin/chunk_preflight/main.py b/bin/chunk_preflight/main.py index 03969a78..c1ed8dc5 100644 --- a/bin/chunk_preflight/main.py +++ b/bin/chunk_preflight/main.py @@ -111,10 +111,11 @@ from release_plan.next_chunk import NextChunk, NoItem, plan_name, planned from release_plan.release_standing import project_plan from project_config.settings import ProjectConfig from chunk_preflight.choices import pulls_command, worktree_add, worktree_on, worktrees +from loop_state.paths import RELEASE_ROOT from chunk_preflight.indentation import space_indented from project_config import templates -BIN = pathlib.Path(__file__).resolve().parents[1] +BIN = RELEASE_ROOT / "bin" # Each tool run in the item's worktree, {item} standing for the item's ID. TOOLS = (("rank_todo.py", "--check"), ("larv-review", "needs-scoring-run", "{item}"), ("reading-cost",), ("larv-review", "places")) # Seconds before a fetch, forge CLI or tool is stopped, so a hung one cannot keep the rest from printing; TIMEOUT_SETTING overrides it. diff --git a/bin/deploy_release/main.py b/bin/deploy_release/main.py index 43a4bcf7..ed173dc0 100644 --- a/bin/deploy_release/main.py +++ b/bin/deploy_release/main.py @@ -71,6 +71,7 @@ import sys import time from deploy_release.ci_script import ci_runner, CI_SECONDS, removed_container +from loop_state.paths import CLAUDE_HOME from deploy_release.cut import cut from deploy_release.patch import cut_patch from deploy_release.deploy import deploy @@ -88,7 +89,7 @@ def main(argv: list[str]) -> int: if len(rest) > 1 or rest[:1] and rest[0].startswith("-") or patching and (commits is None or commits.startswith("-")): print("deploy-release: usage: deploy-release [--cut | --cut-patch ] []", file=sys.stderr) return 1 - checkout = rest[0] if rest else str(pathlib.Path.home() / ".claude") + checkout = rest[0] if rest else str(pathlib.Path.home() / CLAUDE_HOME) if not cutting and commits is None: moved = deploy(checkout) if isinstance(moved, Failure): diff --git a/bin/deploy_release/test_deploy_release.py b/bin/deploy_release/test_deploy_release.py index b1737902..ef9b2140 100644 --- a/bin/deploy_release/test_deploy_release.py +++ b/bin/deploy_release/test_deploy_release.py @@ -54,6 +54,17 @@ class DeployRelease(unittest.TestCase): def head(self) -> str: return self.git(self.target, "describe", "--tags", "--exact-match", "HEAD").strip() + def test_moves_the_claude_home_where_no_checkout_is_named(self): + home = self.temp / "home" + home.mkdir() + self.target.rename(home / ".claude") + self.target = home / ".claude" + self.release("0.2.0", "- Second.\n", '{"theme": "dark"}\n') + + ran = subprocess.run([sys.executable, str(TOOL)], capture_output=True, env={**isolated_env(), "HOME": str(home)}, text=True) + + self.assertEqual((ran.returncode, self.head()), (0, "v0.2.0"), ran.stderr) + def test_moves_the_checkout_to_the_newest_tag_and_prints_each_newer_versions_changelog(self): self.release("0.2.0", "- Second.\n", '{"theme": "dark"}\n') self.release("0.3.0", "- Third: run `make thing` once.\n", '{"theme": "dark"}\n') diff --git a/bin/deploy_release/trace.py b/bin/deploy_release/trace.py index c164b8be..8a1288b8 100644 --- a/bin/deploy_release/trace.py +++ b/bin/deploy_release/trace.py @@ -4,6 +4,7 @@ import time import typing from failure import Failure +from loop_state.paths import state_folder from text_files import utc_stamp # Says that one step of a cut finished, as `saying` makes it. @@ -14,8 +15,7 @@ Clock = typing.Callable[[], float] def trace_folder(env: typing.Mapping[str, str], home: pathlib.Path) -> pathlib.Path: """The folder each cut keeps its trace in, under the state folder as run-heavy finds it.""" - state = env.get("XDG_STATE_HOME") or str(home / ".local" / "state") - return pathlib.Path(state) / "deploy-release" + return state_folder(env, home) / "deploy-release" def run_name(began: float, pid: int) -> str: diff --git a/bin/do_epic/e2e/scenario.py b/bin/do_epic/e2e/scenario.py index ebe0b5be..6a87f38b 100644 --- a/bin/do_epic/e2e/scenario.py +++ b/bin/do_epic/e2e/scenario.py @@ -6,6 +6,7 @@ import tempfile import typing from do_epic.repo_pick import CLAUDE_LABEL, HUMAN_LABEL +from loop_state.paths import CONFIG_FOLDER from project_config.settings import Epic, Finish from do_epic import epic_record, findings, finish from record_store.jira_description import EpicDescription @@ -55,7 +56,7 @@ class Machine: def machine_made(home: pathlib.Path, sandbox: Sandbox, launcher: pathlib.Path, env: typing.Mapping[str, str]) -> Machine | Failure: - folder = home / ".claude-projects" / "do-epic" + folder = home / CONFIG_FOLDER / "do-epic" folder.mkdir(parents=True) ladder = read_ladder(SHIPPED) if isinstance(ladder, Failure): diff --git a/bin/do_epic/main.py b/bin/do_epic/main.py index d0e33725..5eaec2c3 100644 --- a/bin/do_epic/main.py +++ b/bin/do_epic/main.py @@ -14,6 +14,7 @@ from chunk_driver.claims import CHUNK_FLAG from do_epic import chunk_prompt, dry_run, findings, finish, human_tasks, parent_moves, planning, scheduler, split, status from chunk_driver.chunk_run import ChunkRun, closed_cycle from do_epic.epic_run import chunks_started, EpicRun, planned_epic, POLL_SECONDS, real +from loop_state.paths import CLAUDE_HOME, Paths from do_epic.repo_pick import ClaudeWork, HumanTask, recorded, Repo from project_config.main import located as config_located from chunk_driver.project.records import CONSEQUENCE, read_records @@ -35,7 +36,6 @@ from do_epic.repos import locate from chunk_driver.this_loop import Loop from chunk_driver.project.model_choice import Models, overridden from do_epic.parking import parked_through -from loop_state.paths import Paths from chunk_driver.project.premises import read_premises from git_cli.git_repo import record_chunk_base from forge.commands import Run, runner @@ -75,7 +75,7 @@ A repo that is missing isn't cloned. Planning then stops there, so its writes ar {finish.HELP} The Jira site and its credentials are set in ~/.claude-projects/do-epic/config.toml.""" # Under the home folder, where a chunk's cycles are archived, a folder per epic. It is not loop-claude's archive, since that archive's readers, such as judge-replay and the routing figures, read loop-claude's prompts. -ARCHIVE = ".claude/do-epic-transcripts" +ARCHIVE = f"{CLAUDE_HOME}/do-epic-transcripts" # The flag that prints what each open issue does. STATUS_FLAG = "--status" # The flag that prints what planning and the scheduler would do, without doing it. diff --git a/bin/do_epic/planning.py b/bin/do_epic/planning.py index 147d0a50..12f1944a 100644 --- a/bin/do_epic/planning.py +++ b/bin/do_epic/planning.py @@ -9,6 +9,7 @@ import dataclasses import pathlib import re +from loop_state.paths import CLAUDE_HOME from do_epic.config import DoEpicConfig from loop_effects.effects import Effects, say from do_epic.backend.protocol import EpicIssue, EpicStore, no_scores @@ -29,7 +30,7 @@ FORMULA = re.compile(r"^`Score = ([^`]+)`$", re.M) # An epic item has no release, and ranking wants every item of one epic in the same one. NO_RELEASE = (0, 0, 0) # The rule every plan item is scored by, under the home folder, where each machine's setup keeps it. -RULE = ".claude/rules/todo-items.md" +RULE = f"{CLAUDE_HOME}/rules/todo-items.md" @dataclasses.dataclass(frozen=True) diff --git a/bin/do_epic/scheduler.py b/bin/do_epic/scheduler.py index 158d94e0..0e3db9c4 100644 --- a/bin/do_epic/scheduler.py +++ b/bin/do_epic/scheduler.py @@ -15,10 +15,11 @@ from text_files.markdown_text import listed from project_config.settings import PARALLEL_CHUNKS from do_epic.parked import parked_chunks from chunk_pr.approval import PARKS +from loop_state.paths import STATE_FOLDER from agent_cycle import tmux # Under the home folder, a folder per epic key holds the epic's lock file, which `claims.LOCK` names. A chunk without a repo works there. -STATE = ".local/state/do-epic" +STATE = f"{STATE_FOLDER}/do-epic" # Why a human's task with a live window waits, as the epic's status says. HUMAN_WAIT = "it is a human's task; do-epic polls Jira until you close it" diff --git a/bin/judge_replay/main.py b/bin/judge_replay/main.py index 48693f33..33ecb2e5 100644 --- a/bin/judge_replay/main.py +++ b/bin/judge_replay/main.py @@ -62,6 +62,7 @@ from rung_replay.search import AT_ONCE, first_reply, replayed from agent_cycle.judge import Brief, judge_archived, judge_once from judge_replay.replay import Case, case_from, Kind, report, reproduced, sample, verdict_kind from transcript_archive.project_key import checkout_of +from loop_state.paths import CLAUDE_HOME from loop_effects.effects import Effects from failure import Failure from judge_replay.offline import final_message, LEARNERS, offline_report, RULES, Sample @@ -167,7 +168,7 @@ def rule(case: Case, rung: Rung, home: pathlib.Path, effects: Effects) -> Kind | return verdict_kind(grounds) verdict: Verdict | Failure | Limited = first_reply(lambda: judge_archived(case.root, kept.prompt, grounds, len(entries), rung, LOOP_CLAUDE, effects)) return verdict if isinstance(verdict, Limited) else verdict_kind(verdict) - premises, records = read_premises(case.root, home), read_records(case.root, home, home / ".claude") + premises, records = read_premises(case.root, home), read_records(case.root, home, home / CLAUDE_HOME) if isinstance(premises, Failure): return verdict_kind(premises) if isinstance(records, Failure): diff --git a/bin/larv_review/scoring_setup.py b/bin/larv_review/scoring_setup.py index 38cdcdf1..46ba1c49 100644 --- a/bin/larv_review/scoring_setup.py +++ b/bin/larv_review/scoring_setup.py @@ -10,10 +10,11 @@ from git_cli.git_repo import git, Git from project_config.main import located from review_rules.review_folder import made_review_folder, review_folder from project_config.settings import ProjectConfig +from loop_state.paths import RELEASE_ROOT from review_rules.review_passes import SEAT_AGENT from record_store.stores import store -PANEL = pathlib.Path(__file__).resolve().parents[2] / "skills" / "comprehension-panel" +PANEL = RELEASE_ROOT / "skills" / "comprehension-panel" # The file name of each seat's prompt, its label in seat-prompts.md → "Backgrounds", and the heading of its report there. SEATS = ( ("junior-a", "Junior A", "Report: Junior A, Mid A and the maintainability senior"), diff --git a/bin/loop_state/paths.py b/bin/loop_state/paths.py index f9d52db2..66f8e302 100644 --- a/bin/loop_state/paths.py +++ b/bin/loop_state/paths.py @@ -1,6 +1,26 @@ +"""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 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 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: @@ -14,7 +34,7 @@ class Paths: def paths_from(home: pathlib.Path) -> Paths: - claude = home / ".claude" + claude = home / CLAUDE_HOME return Paths( claude_code_transcripts=claude / "projects", claude_dir=claude, diff --git a/bin/machine_load/slots.py b/bin/machine_load/slots.py index 1b8b77f7..6c6c0bc3 100644 --- a/bin/machine_load/slots.py +++ b/bin/machine_load/slots.py @@ -4,6 +4,8 @@ import os import pathlib import typing +from loop_state.paths import state_folder + CPUS_PER_SLOT = 4 # Seconds between tries while every slot is held; a slot frees as its command exits. POLL_SECONDS = 1 @@ -21,8 +23,7 @@ def slot_count(cpus: int | None) -> int: def slot_folder(env: typing.Mapping[str, str], home: pathlib.Path) -> pathlib.Path: - state = env.get("XDG_STATE_HOME") or str(home / ".local" / "state") - return pathlib.Path(state) / "run-heavy" + return state_folder(env, home) / "run-heavy" # Locks an open file, as fcntl.flock does. diff --git a/bin/project_config/doubles.py b/bin/project_config/doubles.py index 61a2a6b1..2784acdc 100644 --- a/bin/project_config/doubles.py +++ b/bin/project_config/doubles.py @@ -4,6 +4,7 @@ import subprocess import tempfile import unittest +from loop_state.paths import CONFIG_FOLDER from test_env import isolated_env CLIENT = """checkout = "~/code/acme-billing" @@ -25,7 +26,7 @@ JIRA_SCORING = 'jira-score-formula = "100 * V / (2**S + 8)"\njira-score-bar = 1\ def write_config(home: pathlib.Path, checkout: pathlib.Path, goals: str = "checkout:README.md") -> pathlib.Path: """A config under home that names checkout, every setting inside it but goals-and-audience; for the tests of each tool that reads the config.""" - folder = home / ".claude-projects" / checkout.name + folder = home / CONFIG_FOLDER / checkout.name folder.mkdir(parents=True, exist_ok=True) (folder / "config.toml").write_text(CLIENT.replace('"~/code/acme-billing"', f'"{checkout}"').replace('"folder:', '"checkout:').replace('"checkout:goals.md"', f'"{goals}"'), encoding="utf-8") return folder diff --git a/bin/project_config/settings.py b/bin/project_config/settings.py index 9e615af2..fa552ced 100644 --- a/bin/project_config/settings.py +++ b/bin/project_config/settings.py @@ -9,13 +9,14 @@ import re import tomllib import typing +from loop_state.paths import CONFIG_FOLDER from failure import Failure from plan.formula import parse_formula from plan.todo_table import SHAPE from project_config import templates from plan.ranking import variables -PROJECTS = ".claude-projects" +PROJECTS = CONFIG_FOLDER CONFIG = "config.toml" # 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" diff --git a/bin/project_record/main.py b/bin/project_record/main.py index 2b7bf087..4b3d80a5 100644 --- a/bin/project_record/main.py +++ b/bin/project_record/main.py @@ -36,11 +36,12 @@ from record_store.stores import FileStore, goals_store, local_file, RECORDS, Rec from git_cli.git_repo import git, Git from project_config.main import located from project_config.settings import ProjectConfig +from loop_state.paths import STATE_FOLDER # Not git's verbs, such as checkout and commit: those read as acting on the repo. COMMANDS = ("open", "save") # Where the copy of a record kept outside files goes, under the user's home, in a folder per project and worktree. -COPIES = ".local/state/project-record" +COPIES = f"{STATE_FOLDER}/project-record" # The goals file opens like a record, though it is a setting of its own. GOALS = "goals-and-audience" diff --git a/bin/repo_checks/__init__.py b/bin/repo_checks/__init__.py index ef6f24c1..ca061895 100644 --- a/bin/repo_checks/__init__.py +++ b/bin/repo_checks/__init__.py @@ -1,6 +1,6 @@ -import pathlib +from loop_state.paths import RELEASE_ROOT # Each module here checks a convention of the repo's own files, as a linter does, so it reads source or Markdown. technical-principles.md bans scanning source only in a test of a unit's behaviour. # The checkout root. -ROOT = pathlib.Path(__file__).resolve().parents[2] +ROOT = RELEASE_ROOT diff --git a/bin/repo_checks/test_paths_in_one_module.py b/bin/repo_checks/test_paths_in_one_module.py new file mode 100644 index 00000000..50243ed3 --- /dev/null +++ b/bin/repo_checks/test_paths_in_one_module.py @@ -0,0 +1,33 @@ +import re +import unittest + +from repo_checks import ROOT + +# The one module that may resolve the release root, the Claude home, the config folder and the state folder. +OWNER = "bin/loop_state/paths.py" + +# How code spells one of those folders itself, in place of asking OWNER. Prose such as help text, which names `~/.claude` to its reader, is not matched. +RESOLVED_ELSEWHERE = re.compile( + r"""["']\.claude["'/]""" + r"""|["']\.claude-projects["'/]""" + r"""|["']\.local["'/]""" + r"""|["']XDG_STATE_HOME["']""" + r"""|__file__\)\.resolve\(\)\.parents\[""" +) + + +class PathsInOneModule(unittest.TestCase): + def test_only_the_paths_module_resolves_the_setups_folders(self) -> None: + found = [ + f"{path.relative_to(ROOT)}:{number}" + for path in sorted((ROOT / "bin").rglob("*.py")) + if not path.name.startswith("test_") and path.relative_to(ROOT).as_posix() != OWNER + for number, line in enumerate(path.read_text(encoding="utf-8").splitlines(), 1) + if RESOLVED_ELSEWHERE.search(line) + ] + + self.assertEqual(found, []) + + +if __name__ == "__main__": + unittest.main() diff --git a/bin/review_rules/review_folder.py b/bin/review_rules/review_folder.py index 2b3450b1..be2491a1 100644 --- a/bin/review_rules/review_folder.py +++ b/bin/review_rules/review_folder.py @@ -4,9 +4,10 @@ import pathlib from failure import Failure from review_rules.round_titles import Findings, reported +from loop_state.paths import STATE_FOLDER # Why here: docs/decisions.md → `review: each reviewer under agents/ writes its full report into the chunk's review folder`. -REPORTS = ".local/state/larv-review" +REPORTS = f"{STATE_FOLDER}/larv-review" def review_folder(home: str, worktree: str) -> str: diff --git a/bin/review_rules/reviewer_context.py b/bin/review_rules/reviewer_context.py index 07b6dfc0..e7e1982e 100644 --- a/bin/review_rules/reviewer_context.py +++ b/bin/review_rules/reviewer_context.py @@ -3,6 +3,7 @@ import json import pathlib import re +from loop_state.paths import CLAUDE_HOME from failure import Failure from review_rules.review_passes import REVIEWERS from text_files.markdown_text import section @@ -13,7 +14,7 @@ SECTIONS = ("Shared goal", "Prose", "Vocabulary") def reviewer_context(home: pathlib.Path) -> str | Failure: """SECTIONS of the CLAUDE.md under home, as a reviewer is told them; a Failure where the file or a section is missing.""" - path = home / ".claude" / "CLAUDE.md" + path = home / CLAUDE_HOME / "CLAUDE.md" try: text = path.read_text(encoding="utf-8") except (OSError, UnicodeDecodeError) as failure: @@ -29,7 +30,7 @@ def starts_bare(agent: str, home: pathlib.Path) -> bool: if agent not in REVIEWERS.values(): return False try: - text = (home / ".claude" / "agents" / f"{agent}.md").read_text(encoding="utf-8") + text = (home / CLAUDE_HOME / "agents" / f"{agent}.md").read_text(encoding="utf-8") except (OSError, UnicodeDecodeError): return False frontmatter = text.split("---\n")[1] if text.startswith("---\n") else "" diff --git a/bin/rule_hook/env_file.py b/bin/rule_hook/env_file.py index 377fdd17..294de2d1 100644 --- a/bin/rule_hook/env_file.py +++ b/bin/rule_hook/env_file.py @@ -11,6 +11,7 @@ import typing from rule_hook.rules import Breach from rule_hook.call import Call, text +from loop_state.paths import CLAUDE_HOME from project_config.settings import env_files from rule_hook.folder_search import globbed, holds, ignored, searches from command_lines.shell_command import home_word, lexed, OPERATOR, resolved @@ -23,7 +24,7 @@ SEARCHES = "the command searches a folder holding {}, a file of credentials that def env_file_breaches(call: Call, home: str) -> list[Breach]: guarded: dict[str, pathlib.Path] = {} - for path in (pathlib.Path(home, ".claude", ".env"), *env_files(pathlib.Path(home))): + for path in (pathlib.Path(home, CLAUDE_HOME, ".env"), *env_files(pathlib.Path(home))): if path.is_file(): # Several configs may name one file: it is checked, and reported, once. guarded.setdefault(os.path.realpath(path), path) diff --git a/bin/rule_hook/reviewer_report.py b/bin/rule_hook/reviewer_report.py index 7f6ba792..63001fa4 100644 --- a/bin/rule_hook/reviewer_report.py +++ b/bin/rule_hook/reviewer_report.py @@ -1,13 +1,13 @@ """Refuse a reviewer's file call other than a Write of its report into the reports folder: skills/larv-review/review-findings.md → "Report".""" import os -import pathlib from rule_hook.rules import Breach from rule_hook.call import Call +from loop_state.paths import RELEASE_ROOT from review_rules.review_folder import REPORTS # Each agent under agents/, read from the folder, so an agent the routing tables miss is still confined. -AGENT_FILES = frozenset(path.stem for path in (pathlib.Path(__file__).resolve().parents[2] / "agents").glob("*.md")) +AGENT_FILES = frozenset(path.stem for path in (RELEASE_ROOT / "agents").glob("*.md")) def report_breaches(call: Call, path: str, home: str) -> list[Breach]: diff --git a/bin/rule_hook/todo_check.py b/bin/rule_hook/todo_check.py index e40c3082..06b233d0 100644 --- a/bin/rule_hook/todo_check.py +++ b/bin/rule_hook/todo_check.py @@ -11,10 +11,11 @@ from git_cli.git_repo import git from rule_hook.git import guarded_git from project_config.settings import held, ProjectConfig from project_config.main import located +from loop_state.paths import RELEASE_ROOT -# The checkout this hook runs from: bin/rule_hook/ sits two folders below it. -OWN = pathlib.Path(__file__).resolve().parents[2] +# The checkout this hook runs from. +OWN = RELEASE_ROOT # settings.json gives rule-hook 30 seconds; rank_todo.py --check takes about a tenth of one. OWN_CHECK_SECONDS = 20 diff --git a/bin/rule_hook/transcript_read.py b/bin/rule_hook/transcript_read.py index ba3009a3..a90794ea 100644 --- a/bin/rule_hook/transcript_read.py +++ b/bin/rule_hook/transcript_read.py @@ -5,6 +5,7 @@ import posixpath from rule_hook.rules import Breach from rule_hook.call import Call, text +from loop_state.paths import CLAUDE_HOME from command_lines.shell_command import resolved READS = "the call reads {}, a session transcript that holds every tool result of its session; print only the lines you need with grep or jq" @@ -14,6 +15,6 @@ def transcript_breaches(call: Call, home: str) -> list[Breach]: if call.tool != "Read": return [] path = resolved(call.cwd, text(call.given, "file_path"), home) - if path.endswith(".jsonl") and path.startswith(posixpath.join(home, ".claude", "projects") + "/"): + if path.endswith(".jsonl") and path.startswith(posixpath.join(home, CLAUDE_HOME, "projects") + "/"): return [Breach("transcript-read", READS.format(path), call.cwd)] return [] diff --git a/bin/run_tests/main.py b/bin/run_tests/main.py index b60a5271..8852356b 100644 --- a/bin/run_tests/main.py +++ b/bin/run_tests/main.py @@ -20,8 +20,9 @@ import tempfile import typing from machine_load.slots import CPUS_PER_SLOT +from loop_state.paths import RELEASE_ROOT -BIN = pathlib.Path(__file__).resolve().parents[1] +BIN = RELEASE_ROOT / "bin" # ci.sh runs this command, so its pins live here; README.md → Test's mutation and bench commands and task-bench-image/Dockerfile repeat the pytest pins, and bin/repo_checks/test_task_bench_image.py fails where one differs. The workers fill one heavy slot, since run-heavy grants one. PYTEST = ["uvx", "--python", shutil.which("python3") or sys.executable, "--with", "pytest-xdist==3.8.0", "pytest==9.2.0", "-n", str(CPUS_PER_SLOT)] SECTION = re.compile(r"^=+ (.+) =+$") diff --git a/bin/transcript_archive/location.py b/bin/transcript_archive/location.py index 195b9d2f..b9867c6f 100644 --- a/bin/transcript_archive/location.py +++ b/bin/transcript_archive/location.py @@ -2,6 +2,7 @@ import hashlib import pathlib import typing +from loop_state.paths import CLAUDE_HOME from claude_code.transcript import first_timestamped_line from transcript_archive.project_key import project_key @@ -11,7 +12,7 @@ FILE_SUFFIX = ".outcomes.md" def archive_root(home: pathlib.Path, env: typing.Mapping[str, str]) -> pathlib.Path: """Where loop-claude archives every project's chunks.""" - return pathlib.Path(env["LOOP_CLAUDE_TRANSCRIPTS"]).expanduser() if env.get("LOOP_CLAUDE_TRANSCRIPTS") else home / ".claude" / "loop-claude-transcripts" + return pathlib.Path(env["LOOP_CLAUDE_TRANSCRIPTS"]).expanduser() if env.get("LOOP_CLAUDE_TRANSCRIPTS") else home / CLAUDE_HOME / "loop-claude-transcripts" def project_archive(checkout_root: str, home: pathlib.Path, env: typing.Mapping[str, str]) -> pathlib.Path: diff --git a/todo.md b/todo.md index 8795d99b..c60581d3 100644 --- a/todo.md +++ b/todo.md @@ -12,10 +12,9 @@ | ID | Release | Blocked by | Exempt | Item | L | E | I | R | S | Moves | Score | |---|---|---|---|---|---|---|---|---|---|---|---| -| 480 | 0.18.0 | | owner | **Resolve every path the tools use in one module: the release root (the folder the running code ships in), the config folder, the state folder and the Claude home. Then only that module names `~/.claude`, and the loop still runs from `~/.claude`.** | 3 | 2 | 3 | 6 | 6 | 1.6 by 3, code health by 3 | 1.9 | -| 481 | 0.18.0 | 480 | owner | **Put the release's tools on `PATH` for every session the loop starts and every hook it runs, name them bare in the prose in place of `~/.claude/bin/`, and refuse the old spelling in new prose.** | 3 | 2 | 3 | 6 | 6 | 1.4 by 2, 2 by 2, code health by 2 | 1.5 | +| 481 | 0.18.0 | | owner | **Put the release's tools on `PATH` for every session the loop starts and every hook it runs, name them bare in the prose in place of `~/.claude/bin/`, and refuse the old spelling in new prose.** | 3 | 2 | 3 | 6 | 6 | 1.4 by 2, 2 by 2, code health by 2 | 1.5 | | 485 | 0.18.0 | 481 | owner | **Rename `loop-claude` to `build-release`, with no alias.** | 2 | 2 | 3 | 5 | 4 | 2 by 2, 6 by 2 | 0.8 | -| 484 | 0.18.0 | 480 | owner | **Keep project configs and this machine's rules in `~/.config/build-release/`, and transcripts and review reports in `~/.local/state/build-release/`, each under its `XDG_*` variable where set, read no old place, and have rule-hook guard the new ones.** | 3 | 2 | 4 | 7 | 6 | 2 by 4 | 0.4 | +| 484 | 0.18.0 | | owner | **Keep project configs and this machine's rules in `~/.config/build-release/`, and transcripts and review reports in `~/.local/state/build-release/`, each under its `XDG_*` variable where set, read no old place, and have rule-hook guard the new ones.** | 3 | 2 | 4 | 7 | 6 | 2 by 4 | 0.4 | | 575 | 0.18.0 | 484, 485 | owner | **Rename `do-epic` to `build-epic`, with no alias, and its config folder with it.** | 2 | 2 | 2 | 4 | 4 | 2 by 2, 6 by 1 | 0.6 | | 482 | 0.18.0 | 481 | owner | **Run the setup from a clone of a release by the path of its `bin/`, with no install step, and replace `deploy-release` with a command that moves that clone to the newest tag.** | 3 | 2 | 3 | 6 | 7 | 2 by 6 | 0.4 | | 483 | 0.18.0 | 482, 484 | owner | **Run every claude the loop starts in a Claude home that the commands generate under `~/.local/share/build-release/` and refresh when the clone's tag changes, with the enabled plugins installed there and the person signed in by `/login` in that home.** | 4 | 2 | 3 | 7 | 7 | 2 by 8 | 0.5 | @@ -110,143 +109,14 @@ ## Details -### 480. Resolve every path the tools use in one module: the release root (the folder the running code ships in), the config folder, the state folder and the Claude home. Then only that module names `~/.claude`, and the loop still runs from `~/.claude`. - -Part of the standalone-install plan lilleman approved on 2026-11-20. Today about 110 lines outside the tests, in some 54 files, name `~/.claude`; `bin/loop_state/paths.py` holds a few. This item changes no behaviour. - -Whether the prose in code that names `~/.claude`, such as help text, prompts and docstrings, changes here or in item 481 is not predictable, so the list holds it. Which tests change is not predictable either: the list holds each test that names one of these folders. - -Touches: - -- `bin/agent_cycle/hand_over.py`: `(module)` -- `bin/agent_cycle/interrupt.py`: `(module)` -- `bin/agent_cycle/judge.py`: `INTERRUPT_RULES`, `FINISHED_RULES` -- `bin/branch_chunks/fixes.py`: `(module)` -- `bin/chunk_driver/claims.py`: `CLAIMS` -- `bin/chunk_driver/cycle_start.py`: `setup_version` (small) -- `bin/chunk_driver/doubles.py`: `a_loop` -- `bin/chunk_driver/project/records.py`: `(module)`, `HUMAN_RULE_NAMES`, `named`, `read_records` -- `bin/chunk_driver/prompts.py`: `planning_launch`, `escalation` -- `bin/chunk_pr/main.py`: `(module)`, `BIN` -- `bin/chunk_preflight/facts.py`: `merge_lines`, `carried_lines`, `joining_details`, `bundled`, `unpredicted_lines` -- `bin/chunk_preflight/main.py`: `(module)`, `BIN`, `TOOLS` -- `bin/claude_code/output_limits.py`: `(module)` -- `bin/compress_archives/main.py`: `(module)` -- `bin/deploy_release/cut.py`: `(module)` -- `bin/deploy_release/main.py`: `(module)`, `main` -- `bin/deploy_release/patch.py`: `(module)` -- `bin/deploy_release/trace.py`: `trace_folder` -- `bin/do_epic/backend/jira.py`: `NO_FINISH` -- `bin/do_epic/chunk_prompt.py`: `CODE_HEALTH`, `FEEDBACK` -- `bin/do_epic/config.py`: `(module)`, `DoEpicConfig`, `load` -- `bin/do_epic/e2e/scenario.py`: `machine_made` -- `bin/do_epic/finish.py`: `task` -- `bin/do_epic/main.py`: `HELP`, `ARCHIVE`, `records_read` -- `bin/do_epic/planning.py`: `RULE` -- `bin/do_epic/ranking.py`: `MARK_IT` -- `bin/do_epic/repos.py`: `(module)`, `locate` (small) -- `bin/do_epic/scheduler.py`: `STATE` -- `bin/judge_replay/main.py`: `(module)`, `rule` -- `bin/larv_review/main.py`: `(module)` -- `bin/larv_review/scoring_setup.py`: `PANEL` -- `bin/loop_claude/chunk/fresh_prompt.py`: `AFTER_CODE_HEALTH`, `preflight_facts`, `preflight_failed` -- `bin/loop_claude/loop/main.py`: `next_cycle` (small) -- `bin/loop_claude/loop/routing_check.py`: `raise_calls` -- `bin/loop_claude/loop/usage.py`: `HELP` -- `bin/loop_state/paths.py`: `paths_from`, `Paths` -- `bin/machine_load/slots.py`: `slot_folder` -- `bin/metric_bench/main.py`: `main` -- `bin/model_routing/ladder_file.py`: `SHIPPED` (small) -- `bin/mutate_changes/main.py`: `(module)` -- `bin/notifier/main.py`: `(module)` -- `bin/plan/goals_file.py`: `(module)`, `ranked_goals`, `goal_weights` -- `bin/plan/ranking.py`: `RESHAPE` -- `bin/plan/todo_table.py`: `(module)` -- `bin/project_config/doubles.py`: `CLIENT`, `write_config` -- `bin/project_config/main.py`: `(module)` -- `bin/project_config/settings.py`: `(module)`, `PROJECTS`, `ProjectConfig`, `load`, `configs`, `env_files` -- `bin/project_record/main.py`: `(module)`, `COPIES` -- `bin/rank_todo.py`: `(module)` -- `bin/reading_cost/main.py`: `(module)` -- `bin/release_plan/next_chunk.py`: `planned` -- `bin/release_plan/release_standing.py`: `Upcoming`, `ReviewDue`, `unreleased_changes` -- `bin/repo_checks/__init__.py`: `ROOT` -- `bin/review_replay/main.py`: `(module)` -- `bin/review_rules/review_folder.py`: `REPORTS` -- `bin/review_rules/reviewer_context.py`: `(module)`, `reviewer_context`, `starts_bare`, `hook_reply` -- `bin/rule_hook/endless_wait.py`: `HOW` -- `bin/rule_hook/env_file.py`: `(module)`, `env_file_breaches`, `reaching` -- `bin/rule_hook/reviewer_report.py`: `AGENT_FILES` -- `bin/rule_hook/rules.py`: `RULES`, `command_breaches` -- `bin/rule_hook/todo_check.py`: `OWN` -- `bin/rule_hook/transcript_read.py`: `(module)`, `transcript_breaches` -- `bin/run_heavy/main.py`: `(module)` -- `bin/run_heavy/path_entry/docker`: `(module)` -- `bin/run_tests/main.py`: `BIN` -- `bin/score_outcomes/anchors.py`: `anchor_lines` -- `bin/score_outcomes/main.py`: `(module)` -- `bin/subagent_rung/main.py`: `(module)` -- `bin/task_bench/main.py`: `(module)` -- `bin/transcript_archive/__init__.py`: `(module)` -- `bin/transcript_archive/location.py`: `archive_root` -- `bin/agent_cycle/test_tmux.py`: `TmuxCommands` -- `bin/agent_cycle/test_worker.py`: `WorkerArgs` -- `bin/chunk_driver/project/test_model_choice.py`: `SavingAModel` -- `bin/chunk_driver/project/test_records.py`: `Records` -- `bin/chunk_driver/test_cycle_start.py`: `CycleStart` -- `bin/chunk_driver/test_prompts.py`: `ReviewLaunches`, `Escalation` -- `bin/chunk_preflight/test_chunk_preflight.py`: `ChunkPreflightTool`, `Render`, `EpicBranchWorktree`, `Plans`, `UnpredictedTest` -- `bin/command_patterns/test_command_patterns.py`: `Pattern`, `Main` -- `bin/compress_archives/test_compress_archives.py`: `Main` -- `bin/deploy_release/test_deploy_release.py`: `Cut`, `Trace` -- `bin/do_epic/backend/test_jira.py`: `Jira` -- `bin/do_epic/test_do_epic.py`: `ConfigTest` -- `bin/do_epic/test_findings.py`: `FindingsTest`, `FilingAFinding` -- `bin/do_epic/test_finish.py`: `ClosingTheEpic`, `TheFinishingChunk` -- `bin/do_epic/test_human_tasks.py`: `AHumanTaskThatBlocksAnIssue` -- `bin/do_epic/test_main.py`: `DoEpicTest`, `TheCommand`, `ACycleOfAChunkWithoutARepo`, `TheHumansRun`, `AChunksRun`, `AChunkWhosePullRequestWaitsOnAGate`, `AnEpicsWorkingBranch`, `TheDryRun` -- `bin/do_epic/test_planning.py`: `Planning` -- `bin/do_epic/test_ranking.py`: `RankedTest` -- `bin/do_epic/test_repos.py`: `LocateTest` -- `bin/do_epic/test_scheduler.py`: `StartingAnEpicsChunks` -- `bin/judge_replay/test_judge_replay.py`: `Main` -- `bin/larv_review/test_larv_review.py`: `LarvReviewTool` -- `bin/larv_review/test_scoring_setup.py`: `PrepareScoring` -- `bin/loop_claude/loop/test_chunk_windows.py`: `StartChunks` -- `bin/loop_claude/loop/test_main.py`: `WindowStarts`, `OwnLadder` -- `bin/loop_claude/loop/test_routing_check.py`: `RoutingCheck` -- `bin/loop_claude/test_black_box.py`: `FAKE_CLAUDE`, `Checkout`, `Premises`, `Cycles`, `Windows`, `Interrupt`, `Models` -- `bin/machine_load/test_machine_load.py`: `SlotFolder` -- `bin/notifier/test_notifier.py`: `Project` -- `bin/plan/test_ranking.py`: `Rank`, `CodeHealth` -- `bin/project_config/test_project_config.py`: `ConfigCase`, `LoadTest`, `HeldTest`, `ToolTest` -- `bin/project_record/test_project_record.py`: `COPIES`, `worktree_config`, `Pruned`, `BlackBox` -- `bin/reading_cost/test_reading_cost.py`: `ReadingCostTool` -- `bin/record_store/test_stores.py`: `Store`, `GoalsStore` -- `bin/repo_checks/test_gitignore.py`: `PRIVATE` -- `bin/repo_checks/test_reviewer_launches.py`: `ReviewerLaunches` -- `bin/review_replay/test_review_replay.py`: `Launch`, `Main` -- `bin/review_rules/test_review_folder.py`: `ReviewFolder` -- `bin/review_rules/test_review_passes.py`: `ReviewPasses` -- `bin/review_rules/test_reviewer_context.py`: `ReviewerContext`, `Reviewers` -- `bin/rule_hook/test_rule_hook.py`: `CommandBreaches`, `ReviewerRung`, `EnvFileRead`, `ReviewerReport`, `Hook`, `TodoRankCheck`, `TranscriptRead` -- `bin/score_outcomes/test_score_outcomes.py`: `Anchors`, `ScoreOutcomesTool` -- `bin/subagent_rung/test_subagent_rung.py`: `SubagentRung` -- `bin/task_bench/features/test_feature_tasks.py`: `CLAUDE`, `BenchOfTasksCase`, `FeatureBenchTest` -- `bin/task_bench/features/test_registers.py`: `CLAUDE` -- `bin/task_bench/figures/test_gather.py`: `GatherTest` -- `bin/task_bench/figures/test_record_figures.py`: `RecordFiguresTest` -- `bin/task_bench/test_task_bench.py`: `BenchTest` -- `bin/test_settings_filter.py`: `Checkout` -- `bin/transcript_archive/test_transcript_archive.py`: `Location` -- `README.md`: `#### Driving chunks` (small) - ### 481. Put the release's tools on `PATH` for every session the loop starts and every hook it runs, name them bare in the prose in place of `~/.claude/bin/`, and refuse the old spelling in new prose. Part of the standalone-install plan lilleman approved on 2026-11-20. About 50 places in `CLAUDE.md`, `rules/`, `skills/` and `agents/` name a tool by its path in `~/.claude/bin/`, and about 50 more in `bin/`, `README.md`, `settings.json`, `presentation/` and `reviewer-merge-trials/`. Keeping the tools on `PATH` only inside the loop's sessions keeps short names such as `wait-for` out of the human's shell. And prose that names no install folder works under every harness. Where the loop puts the tools on `PATH` is not predictable: the list names each place that starts a claude. Where the refusal of the old spelling lives, a rule-hook rule or a check under `bin/repo_checks/`, is not predictable either, so the list leaves its new file out. The code holds about 50 more such paths outside those four folders, in `bin/`, `README.md`, `settings.json`, `presentation/` and `reviewer-merge-trials/`. +Item 480 moved every folder the code resolves into `bin/loop_state/paths.py` and left the prose alone. So about 40 lines of help text, prompts and docstrings in `bin/` still name a file of the release that is no tool by its place under `~/.claude`, such as `~/.claude/CLAUDE.md` and `~/.claude/rules/todo-items.md`. They go wrong once the loop runs from a clone. This item's tagline doesn't cover them, and no other item does: whether they join this item or get one of their own is lilleman's call. + Touches: - `CLAUDE.md`: `## Working loop`, `## Prose` (small), `## Topic rules` (small), `## Working with the codebase`, `## Git, commits, and PRs` (small), `## Vocabulary` (small)