diff --git a/docs/architecture/08-crosscutting-concepts.md b/docs/architecture/08-crosscutting-concepts.md index 878bcd9..9e0010b 100644 --- a/docs/architecture/08-crosscutting-concepts.md +++ b/docs/architecture/08-crosscutting-concepts.md @@ -49,6 +49,7 @@ below. "No improvement shown" does not mean "no worse". | Change-task churn, files and lines | relative % | 15 | 30 | | Security probe pass rate (from round 3) | percentage points | 2 | 9 | | Data-protection probe pass rate (from round 3) | percentage points | 10 | 30 | +| App code, lines and files (from round 5) | relative % | 20 | 40 | - An adherence gain counts only if pass rate held. Following rules while breaking the app is not an improvement. @@ -595,8 +596,13 @@ its mean and interval and counts as neither a win nor a fail. - **Better downward:** every static-analysis count, cognitive and cyclomatic complexity, tokens, turns, wall time, cost, files, lines, artifacts nobody asked for, change-task churn, axe violations, HTML errors. +- **Better downward, against a band:** from round 5, app code's lines and + files. A rise whose whole interval stays inside the margin of section 8.1.2 + reads as held; only one wholly past it reads as worse. - **Neutral, reported without a verdict:** maintainability index, - instability. + instability, test code's lines, from round 5 the source lines and files + that app code replaces, and before round 5 app code's rows, so an earlier + round rescored reads as it was reported. ### 8.7.3 What the report prints diff --git a/docs/architecture/09-architecture-decisions.md b/docs/architecture/09-architecture-decisions.md index 65c5514..560267d 100644 --- a/docs/architecture/09-architecture-decisions.md +++ b/docs/architecture/09-architecture-decisions.md @@ -62,6 +62,7 @@ that mentions the design means the document these chapters replaced. | 2026-10-27 | Each round names its builder models in its registration, and none comes from the vendor of the rounds' judge | The models are a knob a round sets, not a fixed list. A builder from the judge's vendor would bring back the self-preference the cross-check once answered, which no longer runs | — | | 2026-10-27 | Round 5 runs block A alone, at K = 15 with no escalation, each block starting one arm later; adherence is held within 8 pp, and H2 reads the mean over pairs of trials. Blocks B and C wait for a later round | The report's rules, run on round 3's per-trial noise, decide almost nothing at K = 3: H1 is supported in 29 % of rounds when true, and a chance "worse" turns up in 36 %. At K = 15 those are 73 % and 12 %. On round 4's noise, B and C would contradict block A by chance at any affordable K | — | | 2026-10-28 | A template change runs the baseline and the candidate head to head in the candidate's round, with one contrast, `candidate − baseline`, and no `none` arm; round 3 stays a reference without a verdict | A contrast pairing trials from different rounds gets no verdict, so round 3 as the baseline could decide nothing. Two arms answer "is the trim free" at the least cost | — | +| 2026-10-28 | From round 5, size reads app code's lines and files against a band of 20 %, smallest change 40 %; test lines are reported without a verdict; docs and configuration leave size; committed generated files count as artifacts nobody asked for | A better solution is often a little bigger, with tests and layering. Round 4's source lines missed templates, and its file count was mostly docs, templates and committed bytecode | — | ¹ This agrees with Anthropic's guidance on context engineering, which asks for the smallest set of high-signal tokens: [Effective context engineering for AI diff --git a/docs/primer.md b/docs/primer.md index f7be3ba..0b8478e 100644 --- a/docs/primer.md +++ b/docs/primer.md @@ -156,7 +156,7 @@ own, in any order. | **Attack probes** | 11 security attacks and 3 personal-data checks, each set read as its own pass rate | passed, of 11 and of 3 | | **Judge's scores** | The blind judge reads the code three times and scores design, readability, maintainability, security and data protection | 1 to 5 | | **Conventions** | Code tools check a 13-item checklist, such as lint, types and test coverage | met, of 13 | -| **Size** | The lines and files the agent wrote | lines | +| **Size** | The lines and files of app code the agent wrote, tests counted apart. A small rise reads as held | lines | | **Cost** | The dollars, turns and minutes the run took | $ | ### 4.4 Reading the result diff --git a/docs/rounds/README.md b/docs/rounds/README.md index 65dfa3b..93c5a9f 100644 --- a/docs/rounds/README.md +++ b/docs/rounds/README.md @@ -8,7 +8,7 @@ trial of that round has run. The rules every round shares are in | Round | Registered | Asks | | ----- | ---------- | ---- | | [Round 4](round-4.md) | Before its first trial, after round 3 | Does a file supply what a thin spec leaves out, and help a weaker model more | -| [Round 5](round-5.md) | 2026-10-26, amended 2026-10-27 | Which way of delivering the rules gives the best and most consistent code | +| [Round 5](round-5.md) | 2026-10-26, amended 2026-10-27 and 2026-10-28 | Which way of delivering the rules gives the best and most consistent code | ## Reports diff --git a/docs/rounds/round-5.md b/docs/rounds/round-5.md index 02a003e..2b3f029 100644 --- a/docs/rounds/round-5.md +++ b/docs/rounds/round-5.md @@ -3,7 +3,8 @@ Registered in the design on 2026-10-26, before any round-5 trial ran, and amended twice on 2026-10-27, still before any trial: once to change the judge, and once to size the round from the noise of rounds 3 and 4 (#38). Moved here -unchanged but for its links. +unchanged but for its links, and amended on 2026-10-28, still before any trial, +to read code size as app code and test code (#39). ## 13. Round 5: how the rules are delivered @@ -170,3 +171,26 @@ from build to build rather than from re-reading one app, so more blocks, not mor readings, buy the precision. Nothing in this section changes once a round-5 trial has run. + +### 13.6 Code size + +Amended on 2026-10-28 (#39), before any round-5 trial. Round 5 reads size as app +code and test code, against a band, in place of source lines and files: + +| Row | What it counts | Direction | Margin | Smallest change that matters | +| --- | --- | --- | --- | --- | +| App code, lines | The app's Python outside its tests, with its templates, styles and scripts | down | 20 % relative | 40 % | +| App code, files | The same files | down | 20 % relative | 40 % | +| Test code, lines | Python under a `tests` directory or named `test_*.py`, `*_test.py` or `conftest.py` | none | — | — | + +- An app-code row is **held** where the whole interval sits below the margin, + even above zero, and **worse** only where it sits wholly past it. +- Docs and configuration count toward no size. +- Committed bytecode, caches, databases and coverage data count as artifacts + nobody asked for. +- Source lines and files are still printed, without a verdict. + +Why: a better solution is often a little bigger, with tests, error handling and +layering, so a small rise should not read as worse. In round 4's trees, tests +were 10 to 40 % of the Python lines, and docs, templates and config outnumbered +the app's modules, so the old rows measured neither code nor bulk cleanly. diff --git a/tests/efficacy/report.py b/tests/efficacy/report.py index 5aba73b..bd77b5d 100644 --- a/tests/efficacy/report.py +++ b/tests/efficacy/report.py @@ -133,6 +133,23 @@ # a round can afford rules out a loss of less than one. ROUND5_MARGINS = dict(MARGINS, adherence=("8 pp", 0.08, ABSOLUTE)) +# Round 5 reads app code's size against a band rather than zero. A better +# solution is often a little bigger, with layering and error handling, so a +# rise inside the margin reads as held and only one wholly past it as worse. +ROUND5_MARGINS.update((key, ("20 % relative", 0.20, RELATIVE)) + for key in ("app_lines", "app_files")) +BANDED = ("app_lines", "app_files") + +# The size rows round 5 replaces with app code. Source lines miss templates +# and count tests kept in the package; files count docs and configuration. +# They are still printed, without a verdict, so nothing reads them twice. +SUPERSEDED_IN_ROUND5 = ("source_lines", "tracked_files") + +# The app-code rows decide from round 5 on. An earlier round rescored by the +# current scorer carries them too, but was registered on source lines and +# files, so it prints them without a verdict and reads as it was reported. +FROM_ROUND5 = ("app_lines", "app_files") + # The practical thresholds that can owe the one # escalation to K = 5. Only a primary dimension triggers it, so no other # metric's threshold is carried here, where something could come to read it. @@ -365,6 +382,12 @@ def pattern_count(trial, verdict): lambda t: metric_value(t, "scope", "source_lines")), ("tracked_files", "Files", DOWN, lambda t: metric_value(t, "scope", "tracked_files")), + ("app_lines", "App code, lines", DOWN, + lambda t: metric_value(t, "scope", "app_lines")), + ("app_files", "App code, files", DOWN, + lambda t: metric_value(t, "scope", "app_files")), + ("test_lines", "Test code, lines", NEUTRAL, + lambda t: metric_value(t, "scope", "test_lines")), ("unasked_artifacts", "Artifacts nobody asked for", DOWN, lambda t: metric_value(t, "scope", "unasked_artifacts")), @@ -498,6 +521,22 @@ def bca_interval(differences, seed): DISAGREE_VERDICT = "no verdict: the two judges disagree on its direction" +def banded_verdict(interval, direction, margin): + """Better, worse, held or no improvement shown, where a loss inside + `margin`, in the metric's own units, reads as held rather than worse.""" + low, high = interval.get("low"), interval.get("high") + if low is None or high is None: + return "not computed" + loss_low, loss_high = (-high, -low) if direction == UP else (low, high) + if loss_high < 0: + return "better" + if loss_low > margin: + return "worse" + if loss_high <= margin: + return "held" + return "no improvement shown" + + def verdict(interval, direction): """Better, worse, or no improvement shown — read against the direction.""" low, high = interval.get("low"), interval.get("high") @@ -705,8 +744,11 @@ def crossed_labels(trials): def collect(trials, metrics=METRICS): """Metric values by metric, arm and trial index.""" + superseded = SUPERSEDED_IN_ROUND5 if is_round5(trials) else FROM_ROUND5 table = {} for key, label, direction, accessor in metrics: + if key in superseded: + direction = NEUTRAL row = {} for name, trial in sorted(trials.items()): try: @@ -750,12 +792,18 @@ def contrasts(table, seed, crossed=(), margins=None): interval = bca_interval(pairs, seed) observed = [value for value in right.values() if value is not None] across = label in crossed + read = verdict(interval, entry["direction"]) + band = (margins or MARGINS).get(key) + if key in BANDED and band and observed and statistics.fmean( + observed): + read = banded_verdict(interval, entry["direction"], + band[1] * abs(statistics.fmean( + observed))) per_contrast[label] = { "pairs": pairs, "mean": round(statistics.fmean(pairs), 4), "interval": interval, - "verdict": (CROSSING_VERDICT if across - else verdict(interval, entry["direction"])), + "verdict": CROSSING_VERDICT if across else read, "non_inferior": None if across else non_inferior( key, interval, entry["direction"], statistics.fmean(observed) if observed else None, @@ -1592,7 +1640,12 @@ def score(wins, fails): # The arm every file arm is read against: the bare agent. BARE = "none" -SIZE = (("lines", "source_lines"), ("files", "tracked_files")) + +# Code size, by the rows earlier rounds read and the app-code rows round 5 +# reads. A run gives a verdict on one pair only: round 5 reports the earlier +# rows without one, and earlier rounds have no app-code scores. +SIZE = (("lines", "source_lines"), ("files", "tracked_files"), + ("lines", "app_lines"), ("files", "app_files")) COUNTED = ("no", "one", "two", "three", "four", "five") NOT_MEASURED = "not measured" @@ -2048,6 +2101,8 @@ def size_cell(table, results, name): only the ones the interval separated.""" parts, measured = [], False for word, key in SIZE: + if key not in results: + continue cell = share_cell(table, results, key, name, None) measured = measured or cell != NOT_MEASURED if cell not in (None, NOT_MEASURED): @@ -2061,7 +2116,7 @@ def reads_cell(answered, results, name): """One phrase from the answer and the size and cost verdicts.""" if answered == "Not measured": return NOT_MEASURED - bulk = any(results[key][name]["verdict"] == "worse" for _, key in SIZE) + bulk = any(read_as(results, name, key, "worse") for _, key in SIZE) if answered == "Yes": return "quality, %s bulk" % ("with" if bulk else "no") added = (["bulk"] if bulk else []) + ( @@ -2093,6 +2148,7 @@ def reading(answers, lengths): # the follow-up change's churn, and what the judge read — each phrase said # only where its metric was read better or worse. STRUCTURE = (("more files", "tracked_files"), ("more code", "source_lines"), + ("more files", "app_files"), ("more code", "app_lines"), ("more public names beyond the spec", "surface_extra")) EFFORT = (("turns", "turns"), ("tokens", "output_tokens"), ("time", "wall_seconds"), ("cost", "cost_usd")) @@ -2110,7 +2166,7 @@ def reading(answers, lengths): def read_as(results, name, key, verdict): - return results[key][name]["verdict"] == verdict + return results.get(key, {}).get(name, {}).get("verdict") == verdict def counted(n): @@ -2513,7 +2569,9 @@ def contrast_cell(contrast, verdicts=True): return body verdict_text = contrast["verdict"] inferiority = contrast.get("non_inferior") - if inferiority and verdict_text == "no improvement shown": + if inferiority and verdict_text == "held": + verdict_text += " within %s" % inferiority["margin"] + elif inferiority and verdict_text == "no improvement shown": verdict_text += (", preserved within %s" % inferiority["margin"] if inferiority["within"] else ", not preserved within %s" % inferiority["margin"]) @@ -2678,6 +2736,57 @@ def lost_checks(): and "no run record" in unrecorded_row[0]["reason"])] +def band_checks(seed): + """App code's size reads against a band: a rise inside the margin is + held, only one wholly past it worse; round 5 reports the rows it + supersedes without a verdict, and an earlier round keeps them.""" + + # A margin of 20 lines: the loss side of each interval, for a metric that + # improves downward, placed against it. + checks = [(label, banded_verdict({"low": low, "high": high}, DOWN, 20) + == expected, banded_verdict({"low": low, "high": high}, + DOWN, 20)) + for label, low, high, expected in ( + ("a rise inside the band is held", 5, 15, "held"), + ("a band that holds zero is held", -5, 10, "held"), + ("a fall wholly below zero is better", -10, -2, "better"), + ("a rise wholly past the band is worse", 25, 40, "worse"), + ("one that straddles the band is undecided", 10, 30, + "no improvement shown"))] + + # Skills writes 10 % more app code than none in every block, and twice the + # files of a tree that also holds docs. + def trial(app, files): + return {"scores": {"scope": {"value": { + "app_lines": app, "app_files": 10, "source_lines": app, + "tracked_files": files}}}} + trials = {} + for index in (1, 2, 3, 4, 5, 6): + trials["none-%d" % index] = trial(1000 + index, 20) + trials["skills-%d" % index] = trial(1100 + index + index % 2, 40) + results = contrasts(collect(trials), seed, (), ROUND5_MARGINS) + app = results["app_lines"]["skills-none"]["verdict"] + files = results["tracked_files"]["skills-none"]["verdict"] + earlier = {name.replace("skills", "full"): value + for name, value in trials.items()} + reread = contrasts(collect(earlier), seed) + kept = reread["tracked_files"]["full-none"] + later = reread["app_lines"]["full-none"]["verdict"] + shares = size_cell(collect(earlier), reread, "full-none") + checks.extend([ + ("an earlier round rescored prints app code without a verdict", + later == "reported without a verdict", later), + ("and names each size share once", + shares == "lines +10 %, files +100 %", + shares), + ("round 5 reads a 10 % rise in app code as held", app == "held", app), + ("round 5 reports the files it supersedes without a verdict", + files == "reported without a verdict", files), + ("an earlier round still reads its files row", kept["verdict"] + == "worse", kept["verdict"])]) + return checks + + def registration_checks(): """A round is refused when its registration landed on the main branch after its first trial, has not landed, is changed and not committed, or @@ -3531,6 +3640,7 @@ def self_test(seed): checks.extend(cross_checks(seed)) checks.extend(exclusion_checks()) checks.extend(round5_checks()) + checks.extend(band_checks(seed)) checks.extend(failed_build_checks()) checks.extend(record_checks()) checks.extend((label, ok, ok) for label, ok in reach_checks()) diff --git a/tests/efficacy/score.py b/tests/efficacy/score.py index 2f21b33..2b556db 100644 --- a/tests/efficacy/score.py +++ b/tests/efficacy/score.py @@ -20,6 +20,7 @@ import argparse import datetime +import fnmatch import glob import io import json @@ -74,6 +75,24 @@ UNASKED = ("CHANGELOG", "ADR", "DECISIONS", "PLAYBOOK", "ONBOARDING", "JOURNAL", "ROADMAP", "CONTRIBUTING") +# Files a trial committed that running the code wrote, not the agent: caches, +# bytecode, environments, build output, databases and coverage data. Each is +# matched against every part of a tracked path, and each counts as an artifact +# nobody asked for. +GENERATED = ("__pycache__", "*.pyc", "*.pyo", ".pytest_cache", ".ruff_cache", + ".mypy_cache", "venv", ".venv", "node_modules", "build", "dist", + "*.egg-info", "*.sqlite", "*.sqlite3", "*.db", ".coverage", + ".coverage.*", "coverage.xml", "htmlcov") + +# App code is what the application runs or serves: its Python, templates, +# styles and scripts. Docs and configuration are not code a change has to +# move through, so they count toward no size. +APP_SUFFIXES = (".py", ".html", ".jinja", ".jinja2", ".j2", ".css", ".js") + +# Test code is a Python file under a tests directory, or named as pytest +# collects it, wherever it sits. +TEST_DIRECTORIES = ("tests", "test") + TOOL_TIMEOUT = 900 @@ -961,8 +980,26 @@ def clean(key): total_items=len(items)) +def kind_of(name): + """A tracked path's kind: "generated", "test", "app", or None for docs + and configuration.""" + parts = name.split("/") + base = parts[-1] + if any(fnmatch.fnmatch(part, pattern) for part in parts + for pattern in GENERATED): + return "generated" + if base.endswith(".py") and ( + any(part in TEST_DIRECTORIES for part in parts[:-1]) + or base.startswith("test_") or base.endswith("_test.py") + or base == "conftest.py"): + return "test" + if base.endswith(APP_SUFFIXES): + return "app" + return None + + def scope(workspace, roots): - """Files, lines, and artifacts nobody asked for.""" + """Files, lines, app and test code, and artifacts nobody asked for.""" tracked = run(["git", "-C", workspace, "ls-files"], timeout=120) if tracked["failed"] or tracked["status"] != 0: return absent("the workspace is not a readable git checkout: %s" @@ -971,10 +1008,24 @@ def scope(workspace, roots): unasked = [name for name in files if any(token in os.path.basename(name).upper() for token in UNASKED)] + kinds = {"app": [], "test": [], "generated": []} + for name in files: + kind = kind_of(name) + if kind: + kinds[kind].append(name) + unasked = sorted(set(unasked) | set(kinds["generated"])) + + def lines(names): + return count_source([os.path.join(workspace, *name.split("/")) + for name in names])["lines"] + source = count_source(roots) return measured({"tracked_files": len(files), "source_files": source["files"], "source_lines": source["lines"], + "app_files": len(kinds["app"]), + "app_lines": lines(kinds["app"]), + "test_lines": lines(kinds["test"]), "unasked_artifacts": len(unasked)}, unasked=unasked) @@ -1626,6 +1677,42 @@ def coverage_checks(scratch): ] +def scope_checks(scratch): + """Size splits a tree's tracked files into app code, test code and + generated files, and leaves docs and configuration out.""" + tree = os.path.join(scratch, "scope", "tree") + planted = {"src/tariff/app.py": "a\nb\nc\n", + "src/tariff/templates/invoice.html": "
\n
\n", + "src/tariff/test_rules.py": "t\n", + "tests/conftest.py": "c\n", + "tests/test_app.py": "x\ny\nz\n", + "src/tariff/__pycache__/app.cpython-312.pyc": "b\n", + "tariff.db": "rows\n", + "CHANGELOG.md": "notes\n", + "README.md": "read\nme\n", + "pyproject.toml": "[project]\n"} + for name, text in planted.items(): + target = os.path.join(tree, *name.split("/")) + os.makedirs(os.path.dirname(target), exist_ok=True) + with io.open(target, "w", encoding="utf-8") as handle: + handle.write(text) + run(["git", "-C", tree, "init", "-q"], timeout=60) + run(["git", "-C", tree, "add", "-f", "."], timeout=60) + value = scope(tree, [os.path.join(tree, "src", "tariff")])["value"] or {} + return [ + ("app code is the app's Python and templates, not its tests", + (value.get("app_files"), value.get("app_lines")) == (2, 5)), + ("test code is a tests directory or a pytest name, anywhere", + value.get("test_lines") == 5), + ("committed bytecode and a database are artifacts nobody asked for", + value.get("unasked_artifacts") == 3), + ("docs and configuration count toward no size", + value.get("tracked_files") == 10 + and kind_of("README.md") is None + and kind_of("pyproject.toml") is None), + ] + + def python_files_checks(scratch): """The trial's Python files are what its Git state would commit, and a listing that fails is missing rather than empty.""" @@ -1672,7 +1759,8 @@ def self_test(): + lock_checks() + html_checks() + readonly_checks(scratch) + lock_source_checks(scratch) + unrun_checks(scratch) + claim_checks(scratch) + security_checks(scratch) - + coverage_checks(scratch) + python_files_checks(scratch)) + + coverage_checks(scratch) + python_files_checks(scratch) + + scope_checks(scratch)) venv = create_venv(os.path.join(scratch, "venv")) checks += boot_checks(scratch, venv)