Bench rebuilding a shipped feature: take its chunk's change out, tell Haiku the item's tagline, check with the tests the change holds

This commit is contained in:
2026-11-24 00:29:25 +01:00
parent c0445a26d7
commit 87726f9f0b
7 changed files with 222 additions and 35 deletions
+3 -3
View File
@@ -228,7 +228,7 @@ Install puts only `loop-claude` on `PATH`; call the others by their path, such a
- `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.
- `statusline.py` renders Claude Code's status line; `settings.json` → `statusLine` runs it.
- `subagent-rung [--plan] <model> <L>` prints the Agent tool's model and effort for a subagent's task, picked by its L from the project's model on the project's routing ladder, and with `--plan` never below the project's rung; `subagent-rung --help` states the rule.
- `task-bench --image <image> --test <shell text> [<options>]` plants bugs that the tests catch, in the Go and Python files that hold the places the comprehension seats found hardest, has Haiku fix each at the base and at the head, and prints how often the fix passes and what it took. It needs docker and a token from `claude setup-token`; `task-bench --help` says how it plants, runs and checks. It leaves a digest of why runs failed. With `--tasks features` it has Haiku build each feature in the folder the config names as `bench-tasks` instead, from its spec, and checks the build with acceptance tests Haiku never sees. With `--tasks data-sources` it has Haiku add each data source there: a folder that also holds `generate-register`, the seeded script whose made-up register Haiku imports. With `--record-figures`, a bench that finishes appends its figures over every task to the comprehension history. A scoring run starts the bench that way where the project's README documents its `task-bench` command. `task-bench gather` starts a claude on the project's rung, which files a plan item for each place the digest shows to be hard; then gather removes the bench's folder, digest and streams.
- `task-bench --image <image> --test <shell text> [<options>]` plants bugs that the tests catch, in the Go and Python files that hold the places the comprehension seats found hardest, has Haiku fix each at the base and at the head, and prints how often the fix passes and what it took. It needs docker and a token from `claude setup-token`; `task-bench --help` says how it plants, runs and checks. It leaves a digest of why runs failed. With `--tasks features` it has Haiku build each feature in the folder the config names as `bench-tasks` instead, from its spec, and checks the build with acceptance tests Haiku never sees. With `--tasks data-sources` it has Haiku add each data source there: a folder that also holds `generate-register`, the seeded script whose made-up register Haiku imports. With `--tasks shipped-features` it has Haiku rebuild features the project shipped: it takes each one's change out of the code, tells Haiku the tagline of the plan item, and checks the build with the tests that change holds. With `--record-figures`, a bench that finishes appends its figures over every task to the comprehension history. A scoring run starts the bench that way where the project's README documents its `task-bench` command. `task-bench gather` starts a claude on the project's rung, which files a plan item for each place the digest shows to be hard; then gather removes the bench's folder, digest and streams.
- `todo-item` reads and changes a project's plan, whatever holds it: `list` prints the items in the plan's order and `show <ID>` one item's row and detail; `add …` files an item under the next free ID, `edit <ID> …` sets an item's cells or detail, and `move <ID> --release <version>` sets an item's release; `finish <ID>` removes a finished item and adds the bullet passed with `--changelog` to `CHANGELOG.md`, except for a plan kept in Jira. Each change ranks a markdown plan. `todo-item --help` states the flags.
- `touch-predictions record <ID>...` appends what a chunk's items were predicted to touch, under `Touches:` in their details, beside the files and parts its branch touched, to the record the config names as `touch-predictions`; `touch-predictions --help` shows the spelling and how a part is named. `chunk-preflight` reads the same predictions to name the items that may start chunks at once.
- `wait-for <file> [<pattern>] [--timeout <seconds>]` waits until a file a background job writes holds a line matching the pattern, and prints it.
@@ -240,7 +240,7 @@ Install puts only `loop-claude` on `PATH`; call the others by their path, such a
- `adf_codec/` converts markdown to ADF, the rich text of Jira Cloud and Confluence, and back, in a throwaway container running a pinned `@larvit/adf-codec`. It builds the container's image inside a heavy slot.
- `agent_cycle/` runs one cycle (`run.py`): a headless claude worker, then the judge of its transcript. It also holds the interrupt, the tmux window and the routing of the worker's rung. The entry point that runs the cycles supplies the prompts and file names of its own workflow (`worker_prompts.py`), and reads which items a worker took in. `loop_claude` and `do_epic` drive it; `agent_cycle` doesn't import either.
- `atlassian/` holds what the Jira and Confluence backends share (`client.py`): one Atlassian account's credentials, the request both backends send, and each service's error messages. `jira.py` holds what every reader of Jira shares: a search read page by page, the key, fields, links and property of each issue it finds, checked for their shape, and the transition that finishes an issue, for `plan_store` and `do_epic`.
- `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.
- `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`, `routing_figures` and `task_bench`. It imports `reading_cost`'s record path.
- `chunk_driver/` holds what the entry points share. An entry point is a tool that drives chunks through `agent_cycle`: `loop_claude` and `do_epic` are the two. They share how a cycle starts (`cycle_start.py`) and closes (`chunk_run.py`), the claim on a checkout before a chunk starts in it (`claims.py`), the prompts every worker gets (`prompts.py`), and a checkout's premises, records and saved models (`project/`). It imports neither entry point, and `repo_checks` fails any package that imports one of the two. `agent_cycle` is the layer below it, and `repo_checks` fails `agent_cycle` where it imports `chunk_driver`, tests included.
- `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`.
@@ -278,7 +278,7 @@ Install puts only `loop-claude` on `PATH`; call the others by their path, such a
- `review_rules/` holds the larv-review rules that several tools apply: its passes, its review folder, its round commit titles and the comprehension history's format.
- `routing_figures/` measures loop-claude's archive, and each of its projects' default branches, for loop-claude's routing calls.
- `rung_replay/` holds what `judge_replay` and `review_replay` share: the parallel replay runner, the argument reader, the candidate rungs and the exits, and `judge_replay`'s rung search. It reads `agent_cycle`'s retry count and `chunk_driver`'s models file, and finds that file through `loop_state`'s paths. Its `archive.py` keeps each replay's runs and its report in a `replays/` folder of loop-claude's archive.
- `task_bench/` holds `task-bench`, which plants bugs in a project's Go and Python files, or takes the project's bench features or data sources, and has Haiku fix, build or add them in containers.
- `task_bench/` holds `task-bench`, which plants bugs in a project's Go and Python files, or takes the project's bench features, its data sources or the features its history shipped, and has Haiku fix, build or add them in containers. It imports `branch_chunks`, which says what each chunk shipped.
- `test_env.py` serves the tests.
- `text_files/` reads a Markdown file's `##` sections, quotes a passage and joins names into a list, reads the text piped into a command, stamps times in UTC, replaces a file in one step, private where it is new, and gzips a file beside its plain name, by which it reads it afterwards.
- `transcript_archive/` stores loop-claude's transcripts. Its `project_key.py` names each project's archive folder, loop-claude session and models-file entry.
+13 -6
View File
@@ -1,9 +1,10 @@
import pathlib
from branch_chunks.fixes import blamed, fixing_changes, FixingChange, removed_work, Traced, with_fixes
from branch_chunks.cut import BranchChunk, cut_branch, LOG, NOT_WORK, plan_revisions, shipped_by
from branch_chunks.cut import Branch, BranchChunk, cut_branch, LOG, NOT_WORK, plan_revisions, shipped_by
from failure import Failure
from git_cli.git_repo import git, Git, text_at
from plan.todo_table import Item
from project_config.main import located
from project_config.settings import ProjectConfig
from record_store.stores import store
@@ -37,6 +38,16 @@ def branch_chunks(default: str, run: Git, titles: templates.Titles) -> list[Bran
"""Each chunk on the default branch's first-parent line, newest first, with the todo.md items it shipped and the later chunks that fixed code it shipped.
titles holds the project's title templates, which each commit's title is read through. run must run git in the checkout's top: the diff names each path from the top, while blame and a pathspec read a path from the current directory."""
cut = cut_with_shipped(default, run, titles)
if isinstance(cut, Failure):
return cut
branch, shipped = cut
traced = traces(fixing_changes(branch, shipped), run)
return traced if isinstance(traced, Failure) else with_fixes(branch, shipped, traced)
def cut_with_shipped(default: str, run: Git, titles: templates.Titles) -> tuple[Branch, list[tuple[Item, ...]]] | Failure:
"""The default branch cut into chunks, and the todo.md items each chunk shipped, in the order of the branch's chunks, newest first. run and titles are branch_chunks' own."""
# The -- keeps a file named like the branch from making it ambiguous.
log = run(*LOG, default, "--")
if isinstance(log, Failure):
@@ -45,11 +56,7 @@ def branch_chunks(default: str, run: Git, titles: templates.Titles) -> list[Bran
if isinstance(branch, Failure):
return branch
plans = plans_at(plan_revisions(branch), run)
if isinstance(plans, Failure):
return plans
shipped = shipped_by(branch, plans)
traced = traces(fixing_changes(branch, shipped), run)
return traced if isinstance(traced, Failure) else with_fixes(branch, shipped, traced)
return plans if isinstance(plans, Failure) else (branch, shipped_by(branch, plans))
def plans_at(revisions: list[str], run: Git) -> dict[str, str] | Failure:
+56 -21
View File
@@ -1,9 +1,11 @@
r"""Measure how hard a project's code is to fix a bug in, or to build a feature in, at a base commit and at a head: plant bugs its
tests catch, have Haiku fix each several times at both, and print how often the fix passes and what it took. With --tasks features,
Haiku builds the project's bench features instead, and with --tasks data-sources it adds made-up data sources.
Haiku builds the project's bench features instead, with --tasks data-sources it adds made-up data sources, and with --tasks
shipped-features it rebuilds features the project shipped.
usage: task-bench --image <image> --test <shell text> [--base <ref>] [--head <ref>] [--prefix <shell text>] [--seed <n>] [--bugs <n>] [--runs <n>] [--record-figures]
task-bench --tasks features|data-sources --image <image> --test <shell text> [--base <ref>] [--head <ref>] [--runs <n>] [--record-figures]
task-bench --tasks shipped-features --image <image> --test <shell text> [--base <ref>] [--head <ref>] [--shipped <n>] [--runs <n>] [--record-figures]
task-bench gather
Run it in a checkout, under ~/.claude/bin/run-heavy, with a long-lived token in CLAUDE_CODE_OAUTH_TOKEN, which `claude setup-token`
@@ -78,6 +80,24 @@ with the committed data. A task counts, and a run passes, as for a feature; the
Haiku left it. Name the made-up publisher's country by a code no real data could carry: one ISO 3166-1 leaves to its users,
such as QZ, and never XK, which is Kosovo's in practice. The table has a row per data source and side.
--tasks shipped-features benches rebuilding features the project shipped, so nobody writes a task. A shipped feature is a chunk
on the base's first-parent history that took an item out of `todo.md`. A chunk is a merge commit with what it merged, or the
commits a rebase landed together, which share a commit time. A chunk with a commit whose title opens `Drop item <ID>:` took
that item out unbuilt, so it didn't ship it. The bench goes through the shipped features newest first, until --shipped of
them, 5 by default, count. For each:
- it takes the chunk's change out of a copy of each side's tree, as `git apply -R` does. The plan and the project's records stay
as the side holds them, since later chunks wrote on in them: the changelog, the decisions, the score anchors, the comprehension
history and the reading cost. So Haiku can read there what the changelog says of the feature;
- Haiku is told the tagline of the item, or of each item the chunk shipped, and nothing more;
- the acceptance tests are the test files the change touched, and its files under a `testdata` folder, each as the head holds it;
- the reference patch is the change itself.
With those, a shipped feature counts, and a build passes, as for a feature. The bench also passes over one whose change doesn't
come out of both trees cleanly, as where a later chunk rewrote its lines, and one whose change touched no test the head still
holds. The report says which and why. The table has a row per shipped feature and side, named by its items, as `item 7`.
The project's config must name the checkout, with the plan at `todo.md`, the comprehension history at
`docs/comprehension-history.md` and the reading cost at `docs/reading-cost.md`. --seed, --bugs and --prefix don't go with
--tasks shipped-features, and --shipped goes with no other kind.
It prints the base and the head, then a table: a row per bug and side with how many fixes passed and the medians, over the runs
that finished, of the input, cache-write, cache-read and output tokens, the turns, the wall time, and the reads and searches before
the run first opened the file the bug is in. The median of the reads leaves out a run that never opened that file. Then come a row
@@ -100,8 +120,8 @@ passed, so the pass rate's noise is unmeasured.
With --record-figures, a bench that finishes appends its figures to the project's comprehension history: an entry with the
table's header and its three All rows. The entry's heading gives the current UTC time, then `task-bench of <branch>: head
<commit> against base <commit>`, where <branch> is the branch checked out, whatever --head names. For a bench of
features the heading reads `task-bench features of <branch>: ...` instead, and for one of data sources `task-bench data-sources
of <branch>: ...`. No tool reads the entry as a ruling or a scoring run. The bench's last line says where the entry went. A bench that fails or stops doesn't record anything.
features the heading reads `task-bench features of <branch>: ...` instead, for one of data sources `task-bench data-sources
of <branch>: ...`, and for one of shipped features `task-bench shipped-features of <branch>: ...`. No tool reads the entry as a ruling or a scoring run. The bench's last line says where the entry went. A bench that fails or stops doesn't record anything.
`task-bench gather`, run in the same checkout, turns the digest into plan items. It starts a claude on the project's rung, the
cheapest rung of the model loop-claude runs the project on, with the digest and the prompt in gather-prompt.md beside this file.
@@ -112,12 +132,16 @@ Each bench empties its own folder first, and removes the folder every earlier be
not, unless a bench or a gather is using it. So gather a bench before the next one starts.
Exit 1, saying why, on an unknown or repeated argument, a missing --image or --test, a --seed, --bugs or --runs that is no whole
number from 1, a --tasks that is none of bugs, features and data-sources, or no token; and where git, docker or a mutation tool
number from 1, a --tasks that is none of bugs, features, data-sources and shipped-features, or no token; and where git, docker or a mutation tool
fails, the seats' places don't name any Go or Python file, the tests fail at a side without a bug, or no mutant becomes a bug. With --tasks
features or data-sources it exits 1 on a --seed, --bugs or --prefix; where no config names the checkout or its config sets no
`bench-tasks`, or the folder holds no task of that kind, one that lacks a part, or a `generate-register` that is no executable
file, each before docker runs; and where the tests fail at a side without the acceptance tests, or no task counts. Where the
API refuses a run, the bench stops there and exits 1 too, after the table of the runs that finished.
With --tasks shipped-features it exits 1 on a --seed, --bugs or --prefix, and on a --shipped that is no whole number from 1;
where no config names the checkout or its config keeps the plan or one of those two records elsewhere, or the base's history
shipped no item, each before docker runs; and where the tests fail at a side with every feature in, or no shipped feature
counts. A --shipped with another kind of task exits 1 too.
Where the API refuses a run, the bench stops there and exits 1 too, after the table of the runs that finished.
With --record-figures it also exits 1, saying why: before it plants a bug, where no config names the checkout or the history
cannot be read; and after the bench, where the history already holds that branch's bench of those two commits or cannot be
written. The folder then still holds the bench's results.
@@ -137,7 +161,7 @@ import time
import typing
import uuid
from task_bench.tasks import Asked, Bench, BUG, check_made, committed, Kind, KINDS, on_disk, Planned, Task, tests_in_copy
from task_bench.tasks import Asked, Bench, BUG, check_made, committed, Kind, KINDS, on_disk, Planned, SHIPPED, Task, tests_in_copy
from task_bench.planted_mutant import bug_at_sides, Mutant
from claude_code.reply import Claude
from task_bench.bench_folder import clear_left, held
@@ -151,6 +175,7 @@ from claude_code.entries import entry_from, json_objects
from mutate_changes.tool_process import failed, Ran, run_tool
from failure import Failure
from task_bench.feature_tasks import feature_tasks, Features, read_features
from task_bench.shipped_features import read_shipped, shipped_tasks, ShippedFeatures
from task_bench.figures import figures, Result, Side, SIDES, table
from git_cli import git_repo
from review_rules.review_folder import made_review_folder, REPORTS
@@ -158,17 +183,19 @@ from larv_review.history_commands import read_places
from task_bench.record_figures import recorded_bench
from run_heavy.capped_docker import SHARE_VARIABLE
USAGE = "usage: task-bench --image <image> --test <shell text> [--base <ref>] [--head <ref>] [--prefix <shell text>] [--seed <n>] [--bugs <n>] [--runs <n>] [--record-figures], or task-bench --tasks features|data-sources --image <image> --test <shell text> [--base <ref>] [--head <ref>] [--runs <n>] [--record-figures], or task-bench gather"
USAGE = "usage: task-bench --image <image> --test <shell text> [--base <ref>] [--head <ref>] [--prefix <shell text>] [--seed <n>] [--bugs <n>] [--runs <n>] [--record-figures], or task-bench --tasks features|data-sources --image <image> --test <shell text> [--base <ref>] [--head <ref>] [--runs <n>] [--record-figures], or task-bench --tasks shipped-features --image <image> --test <shell text> [--base <ref>] [--head <ref>] [--shipped <n>] [--runs <n>] [--record-figures], or task-bench gather"
# A panel of three readers, seated as the README's audience, picked these options on 2026-11-21, each 3 to 0.
OPTIONS = ("--base", "--bugs", "--head", "--image", "--prefix", "--record-figures", "--runs", "--seed", "--tasks", "--test")
# Such a panel picked --shipped on 2026-11-24, first for two of its three and second for the third, who would spell it out as
# --shipped-features: it names its kind as --bugs does, where --features would read as counting the bench features.
OPTIONS = ("--base", "--bugs", "--head", "--image", "--prefix", "--record-figures", "--runs", "--seed", "--shipped", "--tasks", "--test")
# The one option that takes no value.
RECORD = "--record-figures"
COUNTS = {"--bugs": "5", "--runs": "5", "--seed": "1"}
COUNTS = {"--bugs": "5", "--runs": "5", "--seed": "1", "--shipped": "5"}
TASKS = "--tasks"
# Opens the report's last line, which names the bench's folder.
KEPT = "The digest, and each run's result and stream, until `task-bench gather` files plan items from them or the next bench starts: "
# The options only a bench of bugs takes: two choose the bugs to plant, and --prefix runs the mutation tool.
OF_BUGS = ("--seed", "--bugs", "--prefix")
# The options only a bench of one kind takes. For bugs, two choose the bugs to plant, and --prefix runs the mutation tool.
ONLY_FOR = {"--seed": BUG, "--bugs": BUG, "--prefix": BUG, "--shipped": SHIPPED}
class Fixes(typing.NamedTuple):
@@ -221,12 +248,12 @@ def options(argv: list[str], env: typing.Mapping[str, str]) -> dict[str, str] |
return Failure(f"{name} is missing")
if given.setdefault(TASKS, "bugs") not in KINDS:
return Failure(f"{TASKS} takes {', '.join(list(KINDS)[:-1])} or {list(KINDS)[-1]}, not {given[TASKS]}")
of_features = KINDS[given[TASKS]] is not BUG
for name in OF_BUGS:
if of_features and name in given:
return Failure(f"{name} is for a bench of bugs, so it doesn't go with {TASKS} {given[TASKS]}")
kind = KINDS[given[TASKS]]
for name, only in ONLY_FOR.items():
if only is not kind and name in given:
return Failure(f"{name} is for a bench of {only.noun}s, so it doesn't go with {TASKS} {given[TASKS]}")
for name, default in COUNTS.items():
if of_features and name in OF_BUGS:
if ONLY_FOR.get(name, kind) is not kind:
continue
if not given.setdefault(name, default).isdecimal() or int(given[name]) < 1:
return Failure(f"{name} takes a whole number from 1, not {given[name]}")
@@ -243,9 +270,11 @@ def progress(line: str) -> None:
def bench(given: dict[str, str], env: typing.Mapping[str, str], read: typing.Callable[[pathlib.Path], str | Failure], home: pathlib.Path) -> list[str] | Failure:
"""The report of one bench of the checkout the process runs in, where `read` reads what `larv-review places` prints. It tells
its progress on stderr."""
# Only bugs are planted at the seats' places; features and data sources come from the project's folder. Each kind reads what it makes its tasks from before anything is copied or built,
# Only bugs are planted at the seats' places; features and data sources come from the project's folder, and shipped features from its history. Each kind reads what it makes its tasks from before anything is copied or built,
# so a fault there stops the bench at once.
tasks_from = read(home) if KINDS[given[TASKS]] is BUG else read_features(home, KINDS[given[TASKS]])
kind = KINDS[given[TASKS]]
# Shipped features are read from the base's history, once the base is known.
tasks_from = None if kind is SHIPPED else read(home) if kind is BUG else read_features(home, kind)
if isinstance(tasks_from, Failure):
return tasks_from
git = functools.partial(git_repo.git, env=env)
@@ -255,6 +284,10 @@ def bench(given: dict[str, str], env: typing.Mapping[str, str], read: typing.Cal
sides = commits(given, checkout, git)
if isinstance(sides, Failure):
return sides
if tasks_from is None:
tasks_from = read_shipped(home, checkout, sides["base"], git)
if isinstance(tasks_from, Failure):
return tasks_from
progress(f"task-bench: base {sides['base'][:12]}, head {sides['head'][:12]}.")
review = made_review_folder(checkout, home)
if isinstance(review, Failure):
@@ -267,10 +300,10 @@ def bench(given: dict[str, str], env: typing.Mapping[str, str], read: typing.Cal
return recorded_bench(run, folder, git, home, time.time) if RECORD in given else run()
def bench_in(folder: pathlib.Path, given: dict[str, str], env: typing.Mapping[str, str], tasks_from: str | Features, checkout: str, sides: dict[Side, str], git: Git) -> list[str] | Failure:
def bench_in(folder: pathlib.Path, given: dict[str, str], env: typing.Mapping[str, str], tasks_from: str | Features | ShippedFeatures, checkout: str, sides: dict[Side, str], git: Git) -> list[str] | Failure:
"""The report of a bench of the commits sides names, which empties folder and keeps its runs there. The bench plants bugs at
the places tasks_from names, where it is what `larv-review places` prints, and has Haiku build the features, or add the data
sources, it holds otherwise."""
the places tasks_from names, where it is what `larv-review places` prints, and has Haiku build the features, add the data
sources, or rebuild the shipped features, it holds otherwise."""
containers = Containers(docker_cli(env), f"task-bench-{uuid.uuid4().hex[:12]}", given["--test"], int(env.get(SHARE_VARIABLE) or MEMORY_MIB), f"{os.getuid()}:{os.getgid()}")
shutil.rmtree(folder, ignore_errors=True)
trees: dict[Side, str] = {}
@@ -282,6 +315,8 @@ def bench_in(folder: pathlib.Path, given: dict[str, str], env: typing.Mapping[st
planned: typing.Callable[[Bench], Planned | Failure] | Failure
if isinstance(tasks_from, Features):
asked, planned = Asked(KINDS[given[TASKS]], int(given["--runs"])), features_planner(tasks_from, checkout, trees)
elif isinstance(tasks_from, ShippedFeatures):
asked, planned = Asked(SHIPPED, int(given["--runs"])), functools.partial(shipped_tasks, shipped=tasks_from, count=int(given["--shipped"]))
else:
asked, planned = Asked(BUG, int(given["--runs"])), bugs_planner(given, env, tasks_from, trees["base"])
if isinstance(planned, Failure):
+142
View File
@@ -0,0 +1,142 @@
"""The features task-bench has Haiku rebuild: those the project shipped, read from its history rather than written for the bench.
A shipped feature is a chunk on the base's first-parent line that took an item out of the plan, as branch_chunks cuts that line.
The bench takes the chunk's change out of each side's tree and tells Haiku the item's tagline. From there it is a feature as
task_bench.feature_tasks has it: its reference patch is the chunk's change, and its acceptance tests are the tests that change
holds."""
import functools
import os
import pathlib
import shutil
import typing
from branch_chunks.read import cut_with_shipped, unsupported
from failure import Failure
from plan.todo_table import Item
from project_config.main import located
from project_config.settings import RECORDS
from task_bench.feature_tasks import ACCEPTANCE, Feature, PATCH, why_passed_over
from task_bench.figures import Side, SIDES
from task_bench.runs import of_tests
from task_bench.tasks import Bench, committed, on_disk, Planned, Task
from git_cli.git_repo import Git
# The options that keep the checkout's diff config out of a diff. A rename is written as a removal and an addition, which
# `git apply` takes whatever it would have detected.
PLAIN_DIFF = ("--no-color", "--no-ext-diff", "--no-textconv", "--no-renames", "--src-prefix=a/", "--dst-prefix=b/")
class Shipped(typing.NamedTuple):
"""A feature the project shipped: the name the report gives it, such as `item 7`, the tagline of each item its chunk took out
of the plan, a paragraph each, and the commits its chunk's change runs between."""
name: str
told: str
before: str
tip: str
class ShippedFeatures(typing.NamedTuple):
"""The features a project shipped, newest first, and the paths of its plan and its records, each from the checkout's top. A
chunk's change to those paths is no part of its feature."""
found: list[Shipped]
records: list[str]
def read_shipped(home: pathlib.Path, checkout: str, base: str, git: Git) -> ShippedFeatures | Failure:
"""The features that the project in checkout shipped on the first-parent line of the commit base. A Failure where no config
names the checkout, where it keeps its plan where branch_chunks doesn't read it, and where that line shipped no item."""
in_checkout = functools.partial(git, cwd=checkout)
config = located(checkout, home, in_checkout)
if isinstance(config, Failure):
return config
if why := unsupported(checkout, home, in_checkout):
return Failure(f"task-bench cannot tell what the project shipped: {why}")
cut = cut_with_shipped(base, in_checkout, config.titles)
if isinstance(cut, Failure):
return cut
branch, shipped = cut
found = [
# parse_row keeps a tagline in its two pairs of asterisks.
Shipped(named(items), "\n\n".join(item.tagline[2:-2] for item in items), chunk.before, chunk.tip)
for chunk, items in zip(branch.chunks, shipped)
if items and chunk.before
]
if not found:
return Failure("No chunk on the base's history took an item out of todo.md, so it holds no shipped feature to rebuild.")
return ShippedFeatures(found, [path for path in map(config.tracked, ("plan", *RECORDS)) if path])
def named(items: tuple[Item, ...]) -> str:
"""What the report calls the feature that shipped items: `item 7`, or `items 7, 8`."""
return f"item{'s' * (len(items) > 1)} {', '.join(str(item.id) for item in items)}"
def shipped_tasks(bench: Bench, shipped: ShippedFeatures, count: int) -> Planned | Failure:
"""The task of rebuilding each of the first count features of shipped that count at the bench's commits, numbered from 1, and
a line on each one passed over on the way. A Failure where none counts."""
noun = bench.asked.kind.noun
tasks: list[Task] = []
passed_over: list[str] = []
for feature in shipped.found:
if len(tasks) == count:
break
folder = bench.folder / "shipped-features" / "-".join(feature.name.replace(",", "").split())
taken_out = on_disk(f"take {feature.name} out of the trees in {folder}", lambda: without(bench, feature, shipped.records, folder))
why = taken_out if not isinstance(taken_out, TakenOut) else why_passed_over(bench, taken_out.trees, taken_out.feature)
if isinstance(why, Failure):
return why
if isinstance(taken_out, TakenOut) and why is None:
tasks.append(Task(len(tasks) + 1, feature.name, taken_out.trees, dict.fromkeys(SIDES, feature.told), acceptance=taken_out.feature.acceptance))
continue
shutil.rmtree(folder, ignore_errors=True)
passed_over.append(f"the {noun} {feature.name}: {why}.")
bench.say(f"task-bench: passed over {passed_over[-1]}")
if not tasks:
return Failure(f"None of the {len(shipped.found)} {noun}s on the base's history counts; the lines above say why.")
return Planned(tasks, [f"Passed over {line}" for line in passed_over], {})
class TakenOut(typing.NamedTuple):
"""A shipped feature taken out of the bench's trees: each side's tree without it, committed once, and the feature that
builds it there again."""
trees: dict[Side, str]
feature: Feature
def without(bench: Bench, shipped: Shipped, records: list[str], folder: pathlib.Path) -> TakenOut | str | Failure:
"""shipped taken out of a copy of each side's tree, under folder, where its patch and its acceptance tests go too; or why it
cannot be, which ends a sentence that opens with its name. A Failure where git fails.
Raises OSError where a file cannot be copied."""
change = (shipped.before, shipped.tip, "--", ".", *(f":(exclude,literal){path}" for path in records))
# A path that is not UTF-8 is replaced, so the head's tree doesn't hold it and it is left out.
names = bench.git("diff", "--name-only", "-z", *PLAIN_DIFF, *change, cwd=bench.checkout, errors="replace")
if isinstance(names, Failure):
return names
tests = [path for path in names.split("\x00") if path and of_tests(path) and os.path.lexists(os.path.join(bench.trees["head"], path))]
if not tests:
return "its change holds no test that the head holds"
patch, acceptance = folder / PATCH, folder / ACCEPTANCE
for path in tests:
os.makedirs(os.path.dirname(acceptance / path), exist_ok=True)
shutil.copy2(os.path.join(bench.trees["head"], path), acceptance / path, follow_symlinks=False)
# --binary writes a binary file's bytes, which `git apply` needs, and --output keeps git from decoding them.
diffed = bench.git("diff", "--binary", f"--output={patch}", *PLAIN_DIFF, *change, cwd=bench.checkout)
if isinstance(diffed, Failure):
return diffed
trees: dict[Side, str] = {}
for side in SIDES:
tree = str(folder / side)
shutil.copytree(bench.trees[side], tree, symlinks=True)
# In a repository of its own, the tree is where `git apply` reads the patch's paths from, whatever repository holds the
# bench's folder. git has run in this bench already, so a failure of the second command is the patch's.
if isinstance(made := bench.git("init", "--quiet", cwd=tree), Failure):
return made
if isinstance(bench.git("apply", "-R", str(patch), cwd=tree), Failure):
return f"its revert doesn't apply at the {side}"
if failure := committed(bench.git, tree):
return failure
trees[side] = tree
return TakenOut(trees, Feature(shipped.name, shipped.told, str(patch), str(acceptance)))
+6 -3
View File
@@ -1,4 +1,4 @@
"""What task-bench's three kinds of task share: a planted bug, a feature to build and a data source to add. They share the task itself, the bench it runs in, and the
"""What task-bench's four kinds of task share: a planted bug, a feature to build, a data source to add and a shipped feature to rebuild. They share the task itself, the bench it runs in, and the
steps that commit a task's tree and run the tests over a copy of one."""
import dataclasses
import pathlib
@@ -32,11 +32,14 @@ class Kind(typing.NamedTuple):
BUG = Kind("bug", "A test of this project fails with the message below. Find the bug in the code and fix it. Change no test.\n\n{told}", "a planted bug")
FEATURE = Kind("feature", "Build the feature below in this project.\n\n{told}", "a feature's acceptance tests")
DATA_SOURCE = Kind("data source", "Add the data source below to this project.\n\n{told}", "a data source's acceptance tests")
# What Haiku is asked is a feature's prompt: the feature is new to the tree Haiku gets.
SHIPPED = Kind("shipped feature", FEATURE.prompt, "a shipped feature taken out")
# By the value --tasks takes. A panel of three readers, seated as the README's audience, picked `--tasks features` on 2026-11-23,
# 3 to 0, over a bare `--features` and a `features` subcommand: it names what the bench runs, and the bugs as its other value.
# Such a panel picked `data-sources` the same day, 3 to 0, over `sources` and `imports`, which read as source code and as import
# statements.
KINDS = {"bugs": BUG, "features": FEATURE, "data-sources": DATA_SOURCE}
# statements. Such a panel picked `shipped-features` on 2026-11-24, 3 to 0, over `shipped`, `rebuilds`, `reverts` and `history`:
# it says what was shipped, and stands apart from the features someone wrote for the bench.
KINDS = {"bugs": BUG, "features": FEATURE, "data-sources": DATA_SOURCE, "shipped-features": SHIPPED}
@dataclasses.dataclass(frozen=True)
+1 -1
View File
@@ -288,7 +288,7 @@ class OptionsTest(unittest.TestCase):
def test_tasks_names_the_kind_of_task_and_bugs_is_the_default(self):
self.assertEqual(self.options()["--tasks"], "bugs")
self.assertEqual(self.options("--tasks", "features")["--tasks"], "features")
self.assertEqual(self.options("--tasks=chores").reason, "--tasks takes bugs, features or data-sources, not chores")
self.assertEqual(self.options("--tasks=chores").reason, "--tasks takes bugs, features, data-sources or shipped-features, not chores")
def test_features_run_5_times_at_each_side_by_default(self):
self.assertEqual(self.options("--tasks", "features")["--runs"], "5")
+1 -1
View File
@@ -218,7 +218,7 @@ class OptionsTest(unittest.TestCase):
def test_data_sources_is_a_kind_of_task_that_runs_5_times_at_each_side_by_default(self):
self.assertEqual(self.options("--tasks", "data-sources")["--runs"], "5")
self.assertEqual(self.options("--tasks", "sources").reason, "--tasks takes bugs, features or data-sources, not sources")
self.assertEqual(self.options("--tasks", "sources").reason, "--tasks takes bugs, features, data-sources or shipped-features, not sources")
self.assertIn(", or task-bench --tasks features|data-sources --image <image>", main.USAGE)
def test_the_options_that_choose_bugs_are_refused_with_data_sources(self):