From 9e4aebb3ff03dbf1e559b9f396b666f11d6b09f2 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Thu, 22 Oct 2026 01:03:03 +0200 Subject: [PATCH] =?UTF-8?q?Answer=20prose=20round=201:=200=20=F0=9F=94=B4,?= =?UTF-8?q?=204=20=F0=9F=9F=A1;=20fix=20this=5Fchunks's=20and=20segments's?= =?UTF-8?q?=20cases,=20move=20the=20decision's=20validity=20to=20its=20fir?= =?UTF-8?q?st=20paragraph,=20name=20ladder.py=20and=20reflow=20the=20help,?= =?UTF-8?q?=20trim=20the=20README=20sentence?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- bin/loop_claude/loop/main.py | 138 ++++++++++++++--------------- bin/rule_hook/override_log.py | 32 +++++++ bin/shell_command.py | 4 +- bin/transcript_archive/__init__.py | 4 +- bin/transcript_archive/write.py | 2 +- docs/decisions.md | 6 +- 7 files changed, 111 insertions(+), 77 deletions(-) diff --git a/README.md b/README.md index 68086061..7ee48994 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,7 @@ Install puts only `loop-claude` on `PATH`; call the others by their path, such a - `metric-bench [history]` benches cheap static metrics of a project's Python against the places its comprehension history names as hardest; `metric-bench --help` states the metrics and the scores. - `rank_todo.py [--check] [todo.md]` scores and ranks a project's `todo.md`; `rank_todo.py --help` states the format. - `reading-cost [--reset] [record]` appends a figure for each chunk `loop-claude` finished to a project's `docs/reading-cost.md`, and says whether the figures rise; `reading-cost --help` states the measure. -- `review-replay ` replays a review pass's archived rounds from the projects run on the model, on the code each reviewed, and prints the lowest rung below the project's that, like each rung above it, finds every 🔴 and 🟡 the project's rung finds again; `review-replay --help` states the replay. Every machine is a sandbox (Install), which matters here: each replayed reviewer skips every permission prompt, stability-reviewer has Bash, and an archived prompt may name paths on the host. +- `review-replay ` replays a review pass's archived rounds from the projects run on the model, on the code each reviewed, and prints the lowest rung below the project's that, like each rung above it, finds every 🔴 and 🟡 the project's rung finds again; `review-replay --help` states the replay. Each replayed reviewer skips every permission prompt, stability-reviewer has Bash, and an archived prompt may name paths on the host. - `rule-hook [overrides]` blocks a tool call that breaks a rule a program can check, unless the call overrides the rule; `settings.json` → `hooks` runs it before each Bash, Edit, MultiEdit, Write and Agent call, and `rule-hook --help` states the rules and the override. - `score-outcomes [L E I S]` lists the finished items whose guessed scores sit nearest the given ones, and the shipped items the project's `docs/score-anchors.md` names for each level of L, E and I, each with what its chunk measured; then the median outcome at each guessed R and S, and how well L, E and I each order the chunks by review rounds and 🔴 findings; `score-outcomes --help` states the measures. - `settings_filter.py` is git's clean filter for `settings.json`: it drops `"model"` and sorts the keys. `.gitattributes` sets the filter `settings` on `settings.json`, and Install's `git config` line makes this script that filter. diff --git a/bin/loop_claude/loop/main.py b/bin/loop_claude/loop/main.py index fc268615..c0ae2495 100644 --- a/bin/loop_claude/loop/main.py +++ b/bin/loop_claude/loop/main.py @@ -39,10 +39,10 @@ facts itself. Each project has one session, named "A loop-claude", where is the checkout's path relative to ~/code, or to / outside it. The session is deleted when its chunk finishes. At every interrupt, and as every cycle ends, Ctrl-C and a failure included, the session's transcript is -copied to $LOOP_CLAUDE_TRANSCRIPTS///.jsonl (default -~/.claude/loop-claude-transcripts), with an outcomes file beside it: the verdict, any answer the -judge quoted, each judge reply the loop rejected, and why the loop stopped. The layout, and when a -copy is replaced, are in bin/transcript_archive/__init__.py. +copied into a folder per chunk under $LOOP_CLAUDE_TRANSCRIPTS/ (default root +~/.claude/loop-claude-transcripts), named by its hash, with an outcomes file beside it: the task, +then each verdict, quoted answer, rejected judge reply, step-up and stop, each opened by its UTC +time. The layout, and when a copy is replaced, are in bin/transcript_archive/__init__.py. Every claude loop-claude starts runs the project's model, saved per in ~/.claude/loop-claude-models.json and read each cycle, unless routing, below, puts the worker, @@ -52,94 +52,94 @@ for the worker and the session /talk opens; with both set, nothing is asked. Routing: the worker's rung -Where that model is on the routing ladder (bin/model_routing/ladder.py), the worker and the -session /talk opens run on one of the ladder's rungs: a model at an effort. As a chunk starts, it is routed -on the item chunk-preflight names, read from todo.md on the default branch as the preflight just -fetched it (chunk_pick.chunk_item). That item is the earliest release's top item that does not wait, -but only where that release is the next one: the earliest after the newest vX.Y.Z tag that todo.md -has named at that tag or since, skipping a release its ## Renamed section marks renamed, or, where -no tag names a version, the earliest release. Otherwise no item routes the chunk. An item waits -while it is marked question, or while an item that blocks it is still in the table. The item's L -picks the worker's rung, stepping from the model's cheapest rung by WORKER_STEPS in +Where the project's model is on the routing ladder (bin/model_routing/ladder.py), the worker and the +session /talk opens run on one of the ladder's rungs: a model at an effort. As a chunk starts, it is +routed on the item chunk-preflight names, read from todo.md on the default branch as the preflight +just fetched it (chunk_pick.chunk_item). That item is the earliest release's top item that does not +wait, but only where that release is the next one: the earliest after the newest vX.Y.Z tag that +todo.md has named at that tag or since, skipping a release its ## Renamed section marks renamed, or, +where no tag names a version, the earliest release. Otherwise no item routes the chunk. An item +waits while it is marked question, or while an item that blocks it is still in the table. The item's +L picks the worker's rung, stepping from the model's cheapest rung by WORKER_STEPS in bin/model_routing/ladder.py, below it for a low L; without such an item, or with its L, E or I unscored, the chunk runs on the model's cheapest rung. Routing: the reviewers' rung -The item's E + I picks the reviewers' rung, stepping up from the cheapest rung by REVIEW_STEPS there, -never below the worker's rung. Where it steps none and the worker runs no higher than the cheapest -rung, a pass REPLAYED there names runs on the rung it names, the lowest a review-replay run found -finding what the cheapest rung finds, even below the worker's. +The routed item's E + I picks the reviewers' rung, stepping up from the cheapest rung by +REVIEW_STEPS in bin/model_routing/ladder.py, never below the worker's rung. Where it steps none and +the worker runs no higher than the cheapest rung, a pass REPLAYED in that file names runs on the +rung it names, the lowest a review-replay run found finding what the cheapest rung finds, even below +the worker's. Routing: what the worker's prompts say -The worker's first prompt names the rung and the item, and asks the -worker to name each item the chunk takes, with its L and E + I, and to count the item's size again -once it has read the code (prompts.recount). The prompt names the rung of each review that runs on -a rung other than the worker's: the reviewers' rung or the replay's for each pass's reviewer, and -the cheapest rung for each comprehension seat and the security pass. It also names the reviewers' rung -each higher E + I picks, so the worker reviews an item it takes in on that rung in the same run. -When the worker runs below the cheapest rung, the prompt has it launch each subagent that files or -scores todo.md items on the rung subagent-rung --plan prints. The prompt after -each unfinished verdict says this again, since a step-up may have moved the worker. A reviewer or -seat that rules the work below standard may ask to rerun one rung up; each prompt names that rung. -loop-claude hands the worker's claude its own rung, the project's and the reviews' E + I, in -LOOP_CLAUDE_WORKER_RUNG, LOOP_CLAUDE_PROJECT_RUNG and LOOP_CLAUDE_ESCAPE_AND_IMPACT, and rule-hook -refuses a review launched below the rung those pick for it. +The worker's first prompt names the rung and the item, and asks the worker to name each item the +chunk takes, with its L and E + I, and to count the item's size again once it has read the code +(prompts.recount). The prompt names the rung of each review that runs on a rung other than the +worker's: the reviewers' rung or the replay's for each pass's reviewer, and the cheapest rung for +each comprehension seat and the security pass. It also names the reviewers' rung each higher E + I +picks, so the worker reviews an item it takes in on that rung in the same run. When the worker runs +below the cheapest rung, the prompt has it launch each subagent that files or scores todo.md items +on the rung subagent-rung --plan prints. The prompt after each unfinished verdict says this again, +since a step-up may have moved the worker. A reviewer or seat that rules the work below standard may +ask to rerun one rung up; each prompt names that rung. loop-claude hands the worker's claude its own +rung, the project's and the reviews' E + I, in LOOP_CLAUDE_WORKER_RUNG, LOOP_CLAUDE_PROJECT_RUNG and +LOOP_CLAUDE_ESCAPE_AND_IMPACT, and rule-hook refuses a review launched below the rung those pick for +it. Routing: step-ups -The judge reports the highest L and the -highest E + I the worker states for an item it takes in. The next cycle steps the worker up to the -rung that L picks, never down, and the reviewers to the rung picked by the higher of two: that -E + I, or the routed item's (Route.reviewed_on in bin/model_routing/route.py). A level off its -scale counts as none. Every second unfinished verdict on a chunk steps it up one rung -(routing.stepped). So does an unfinished verdict on a worker that ended its run asking for a -higher rung, once the judge quotes the transcript showing that the escalation trigger it named -fired (~/.claude/CLAUDE.md → "Working with the codebase" lists them). An interrupt or a quoted answer -with such a quote steps the rung as it comes in, before the human is asked or the worker resumes -(routing.stepped_by_ruling). Each such step marks how many transcript entries the session held, -and from then on the judge must quote the worker's own lines after that mark, where it reads a -[step] line. Each step on an escalation stops two rungs above the rung the chunk's item picks, and the worker's prompts -offer it only while the worker is below that limit. +The judge reports the highest L and the highest E + I the worker states for an item it takes in. The +next cycle steps the worker up to the rung that L picks, never down, and the reviewers to the rung +picked by the higher of two: that E + I, or the routed item's (Route.reviewed_on in +bin/model_routing/route.py). A level off its scale counts as none. Every second unfinished verdict +on a chunk steps it up one rung (routing.stepped). So does an unfinished verdict on a worker that +ended its run asking for a higher rung, once the judge quotes the transcript showing that the +escalation trigger it named fired (~/.claude/CLAUDE.md → "Working with the codebase" lists them). An +interrupt or a quoted answer with such a quote steps the rung as it comes in, before the human is +asked or the worker resumes (routing.stepped_by_ruling). Each such step marks how many transcript +entries the session held, and from then on the judge must quote the worker's own lines after that +mark, where it reads a [step] line. Each step on an escalation stops two rungs above the rung the +chunk's item picks, and the worker's prompts offer it only while the worker is below that limit. Routing: the archive and reruns -Each finished or unfinished verdict, interrupt, -quoted answer, stop and step-up in the archive names the worker's rung, with the item, L and E + I -that routed the chunk, any taken-in E + I that picks a higher review rung (archived as a step-up -too), and the mark. A rerun resumes an open chunk on the latest -route named there, and counts its unfinished verdicts afresh. A rung no longer on the ladder, or -below the one its item's L picks, is dropped, and the chunk is routed afresh from todo.md. So is a -chunk whose archived line names an R + C, as loop-claude wrote before it routed on L. A todo.md or +Each finished or unfinished verdict, interrupt, quoted answer, stop and step-up in the archive names +the worker's rung, with the item, L and E + I that routed the chunk, any taken-in E + I that picks a +higher review rung (archived as a step-up too), and the mark. A rerun resumes an open chunk on the +latest route named there, and counts its unfinished verdicts afresh. A rung no longer on the ladder, +or below the one its item's L picks, is dropped, and the chunk is routed afresh from todo.md. So is +a chunk whose archived line names an R + C, as loop-claude wrote before it routed on L. A todo.md or an archive that cannot be read or parsed is said on stderr, and the chunk is routed without it. -Judge rung +Routing: the judge's rung -The judge of a model listed in JUDGE_REPLAYED (bin/loop_claude/routing.py) runs on the rung that -the reviewers' E + I (Route.reviewed_on) picks for a review from that model. It never runs below the +The judge of a model listed in JUDGE_REPLAYED (bin/loop_claude/routing.py) runs on the rung that the +reviewers' E + I (Route.reviewed_on) picks for a review from that model. It never runs below the model's cheapest rung, and runs on it when no item routed the chunk or was taken in. Its rung stays put when the worker steps up. A model is listed once judge-replay found its cheapest rung returning every verdict the reference judge reproduced. Any other model's judge runs at the effort its settings give. -Routing figures +Routing: the figures -Counting the cycles a verdict closed across all projects in the archive, the first loop to close -one 20 or more cycles after the last measurement measures every finished chunk there, with no model -run: tokens by project, subagent type, rung and the tool whose results they took in, and, for each -chunk a todo.md item routed, grouped by the rung it started on: its review rounds past each pass's -first, its unfinished verdicts and its subagents' rungs. It writes them to routing-figures.md at the archive's root. They call for a -routing change when chunks routed onto a rung took more review rounds or unfinished verdicts than -chunks routed onto the next rung up, each rung with 5 chunks or more, or when the reports of 5 or -more subagents of one type were longer than the tool results they read. Each call not raised before -is an interrupt: claude, on the project's model, on the terminal in ~/.claude, asked to put the -calls to the human. Once that claude ends, the calls are listed in routing-calls-raised.md beside the -figures, and not raised again. Off a terminal, the calls are said on stderr, the loop goes on, and -they are raised again at the next measurement. A line `- Reset` in -routing-calls-raised.md restarts both: the figures count only chunks that finished after it, and a -call raised before it may be raised again. A chunk that cannot be read is skipped and named in the -figures; figures that cannot be measured or written are said on stderr, and the loop goes on. +Counting the cycles a verdict closed across all projects in the archive, the first loop to close one +20 or more cycles after the last measurement measures every finished chunk there, with no model run: +tokens by project, subagent type, rung and the tool whose results they took in, and, for each chunk +a todo.md item routed, grouped by the rung it started on: its review rounds past each pass's first, +its unfinished verdicts and its subagents' rungs. It writes them to routing-figures.md at the +archive's root. They call for a routing change when chunks routed onto a rung took more review +rounds or unfinished verdicts than chunks routed onto the next rung up, each rung with 5 chunks or +more, or when the reports of 5 or more subagents of one type were longer than the tool results they +read. Each call not raised before is an interrupt: claude, on the project's model, on the terminal +in ~/.claude, asked to put the calls to the human. Once that claude ends, the calls are listed in +routing-calls-raised.md beside the figures, and not raised again. Off a terminal, the calls are said +on stderr, the loop goes on, and they are raised again at the next measurement. A line +`- Reset` in routing-calls-raised.md restarts both: the figures count only chunks that +finished after it, and a call raised before it may be raised again. A chunk that cannot be read is skipped and +named in the figures; figures that cannot be measured or written are said on stderr, and the loop +goes on. A change to bin/loop-claude or any bin/**/*.py takes effect at the next cycle boundary, once loop-claude --help succeeds: the loop reloads into the edited script. diff --git a/bin/rule_hook/override_log.py b/bin/rule_hook/override_log.py index ee6f417b..9669128e 100644 --- a/bin/rule_hook/override_log.py +++ b/bin/rule_hook/override_log.py @@ -13,6 +13,38 @@ from utc_stamp import utc LOG = "rule-overrides.tsv" +@dataclasses.dataclass(frozen=True) +class LogLine: + """One line of the log, its fields tab-separated in this order.""" + at: str + branch: str + # The commit checked out when the override let its call through; empty on a branch with no commit yet. + commit: str + rule: str + reason: str + what: str + + def line(self) -> str: + return "\t".join(" ".join(field.split()) for field in dataclasses.astuple(self)) + "\n" + + +def parsed_entry(line: str) -> LogLine | None: + fields = line.rstrip("\n").split("\t") + return LogLine(*fields) if len(fields) == len(dataclasses.fields(LogLine)) else None + + +def this_chunks(entry: LogLine, reflog: set[str], branch: str, on_default: typing.Callable[[str], bool]) -> bool: + """Whether the override is the current branch's: its commit is in the branch's reflog, which holds every commit the branch has had. So: + - an override logged at c1 still counts after an amend or a rebase replaced c1 with c2; + - one logged under the branch's old name counts after `git branch -m`, which carries the reflog over; + - one logged on another branch, at a commit this reflog lacks, doesn't count; + - one logged at a default-branch commit, such as the one the branch started from, sits in the reflogs of other branches too, so it counts only under this branch's own name; + - one logged before any commit existed, with an empty commit, counts on every branch.""" + if entry.commit == "": + return True + return entry.commit in reflog and (entry.branch == branch or not on_default(entry.commit)) + + @dataclasses.dataclass(frozen=True) class LogLine: """One line of the log, its fields tab-separated in this order.""" diff --git a/bin/shell_command.py b/bin/shell_command.py index 34997b02..6fe84ce8 100644 --- a/bin/shell_command.py +++ b/bin/shell_command.py @@ -29,12 +29,14 @@ def simple_commands(command: str, cwd: str, home: str) -> list[Simple]: def segments(command: str) -> list[list[str]]: - """The command's simple commands as lists of words, split at ; & | ( ) and line breaks. Shell forms it does not parse: + """The command's simple commands as lists of words, split at ; & | ( ) < > and line breaks, without redirect targets. Shell forms it does not parse: - a quoted string is one word, so `bash -c "git commit"` and `echo "$(git commit)"` hide the inner command; - a backtick substitution stays inside its words, while `$(git commit)` outside quotes splits into the `$` and a command of its own; - a keyword or a brace opens its command's words, so `then git commit` reads as the command `then`; + - a redirect splits a command in two, so `git > out commit` reads as `git` and `commit`; - `<(...)` and `<<<` read as redirects, so the word after them is dropped as the target; - a file descriptor before a redirect, as in `2>&1`, stays a word; + - a heredoc's body is dropped; - variables, aliases and functions are not expanded; - a line with an unbalanced quote yields nothing.""" text = uncommented(HEREDOC.sub(lambda heredoc: heredoc.group(0).split("\n", 1)[0], command)) diff --git a/bin/transcript_archive/__init__.py b/bin/transcript_archive/__init__.py index 673222bb..8bbb36e1 100644 --- a/bin/transcript_archive/__init__.py +++ b/bin/transcript_archive/__init__.py @@ -12,8 +12,8 @@ - .jsonl is a copy of the session's transcript, named by the hash of its bytes, so each distinct transcript is kept once. - .outcomes.md sits beside the copy and holds the task, then each outcome opened by its UTC time (outcomes.py). -- session/ holds every other file named after the session, such as the subagents' transcripts, which - Claude Code keeps in a folder beside the transcript. A file there is replaced only by a version that +- session/ holds every other file of the session, such as the subagents' transcripts, which Claude + Code keeps in a folder named after the session, beside the transcript. A file there is replaced only by a version that grew from it. A file Claude Code rewrote whole lands beside its copy as . (write.copy_for). diff --git a/bin/transcript_archive/write.py b/bin/transcript_archive/write.py index 29582e48..f147dbe5 100644 --- a/bin/transcript_archive/write.py +++ b/bin/transcript_archive/write.py @@ -12,7 +12,7 @@ from utc_stamp import utc def archive(project_archive: pathlib.Path, path: str, task: str, outcome: str, at: float) -> Failure | None: - """Keeps the transcript at path, its outcomes file and its session's files in project_archive, in the layout this package's docstring gives; the failure that stopped it, or None.""" + """Keeps the transcript at path, its outcomes file and its session's files in project_archive, in the layout this package's docstring gives; the failure that stopped it, or None. The outcome is stamped and appended to the outcomes file, which opens with the task only when the copy is new.""" try: with open(path, "rb") as handle: raw = handle.read() diff --git a/docs/decisions.md b/docs/decisions.md index 949e8ae0..3a2bf1b3 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -136,7 +136,7 @@ Valid while the ladder orders its rungs by competence. ## todo.md: one table of items, scored by the formula it states, held to its bar and ranked by `bin/rank_todo.py`, which ranks each blocker above the items it blocks; each achieve goal weighs by its position, code health first and four times as heavy while the comprehension panel's overall is under 7.0 or unmeasured, then README.md's goals; the table's order is the plan's only order -2026-10-02, lilleman. Serves goal 1: findings were filed faster than chunks closed them, so the plan grew without telling what mattered. Each item is scored as `~/.claude/rules/todo-items.md` says; this repo's formula counts value highest and size least. The format is mandatory in every project, as the premises are (goal 1.3); the formula and bar are each project's own. +2026-10-02, lilleman. Serves goal 1: findings were filed faster than chunks closed them, so the plan grew without telling what mattered. Each item is scored as `~/.claude/rules/todo-items.md` says; this repo's formula counts value highest and size least. The format is mandatory in every project, as the premises are (goal 1.3); the formula and bar are each project's own. A script ranks the table so a re-rank after each addition or edit is deterministic and cheap. Valid while one human sets the bar and reads the ranking, and while the items marked `principle` stay few enough to rank. 2026-10-02, lilleman, on the bar. An item under the bar is not kept; this repo's bar started at 10 and was set to 9 the same day. An Exempt cell keeps a row past the bar where a rule needs it kept. @@ -144,11 +144,11 @@ Valid while the ladder orders its rungs by competence. 2026-10-02, lilleman, on re-raising findings. A finding under the bar is recorded nowhere, so a later review may raise it again, and the run rescores it. That costs one scoring; a ledger of dropped findings would regrow the list the bar caps. larv-review's "Round cap" → "Done" counts a finding named under the bar as settled, so one raised again holds no pass open. -2026-10-02, lilleman, on the gate check. `rank_todo.py --check` is part of larv-review's gate, since only a check keeps the stored Score from going stale. A script ranks the table so a re-rank after each addition or edit is deterministic and cheap. +2026-10-02, lilleman, on the gate check. `rank_todo.py --check` is part of larv-review's gate, since only a check keeps the stored Score from going stale. 2026-10-02, lilleman, on the `principle` exemption. A 🟡 against a technical principle is exempt as `principle`, because its audience value scores low and the bar would drop every one. A 🟢 against a principle is scored like any other finding. -2026-10-08, lilleman, on the goal weights: the goal weights in `todo.md` depart from an even spread by position, which would weigh goal 4, leaking nothing, at 0.11. Valid while one human sets the bar and reads the ranking, and while the items marked `principle` stay few enough to rank. +2026-10-08, lilleman, on the goal weights: the weights in `todo.md` depart from an even spread by position, which would weigh goal 4, leaking nothing, at 0.11. 2026-10-15, lilleman: the scores get a researched method, which `todo.md` items 149 and 151 build, after PR #283 shipped the ranking, PR #296 the risk scores and PR #298 the anchors each project names for each level in `docs/score-anchors.md`; the evidence is in `docs/scoring-and-goals-research.md`. R becomes L + E + I − 2: the chance the change holds a defect, set first by its size; the chance the defect escapes tests, review and monitoring; and the worst impact dimension, each about ×10 per level. I5, irreversible, holds R at 7 or more, and I4 at 5 or more, since a severe enough consequence outranks how unlikely it is. C goes from every table and tool: what it scored beyond size, spread and novelty, which L already holds, is complexity, which adds almost nothing once size is accounted for. Items rank by value per cost, V / 2^S, and V sums each cited achieve goal's weight times how far the item moves it. A goes, and the Audience says whose value the goals serve. R stays out of the ranking and sets how carefully an item is done; an item that lowers risk scores it as value. Each release fills by priority up to a capacity it states, in place of the bar. Each README goal is `maintain`, which vetoes an item that breaks it, or `achieve`, with a signal, a counter-signal and a one-line reason, as this README's Goals now mark them; each project keeps settled decisions to test its goals against. Each part of this method holds once the item that builds it ships. 2026-10-16, lilleman: a task's L and E + I pick its rungs in place of R, as `routing: one ladder` records.