optimize: compare.py for the regressions and the complexity; the upgrader prunes the rules it touched

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
maximeandClaude Opus 5.5 committed 2026-11-16 17:53:09 +01:00
1 parent 2a96d54844
commit bfa0224711
3 files changed
+15 -9

No files matched your search

+5 -4
View File
@@ -32,6 +32,7 @@ Derived from `<ANALYSIS>/request.json`:
- sensors: `python3 <DETECTORS>/bench/sensors.py <STATION> --from <FROM> --to <TO>`
- range score (the goal): `python3 <DETECTORS>/bench/score.py <STATION> --labels <LABELS>/<station>.jsonl --from <FROM> --to <TO>`; it exits with an error if no label touches the range: note it in the summary, touch nothing in the detectors and go to part 2.
- benchmark (the non-regression, about 1 min): `python3 <DETECTORS>/bench/regression.py <REFERENCE>`
- compare (the regressions and the complexity of two benchmarks): `python3 <DETECTORS>/bench/compare.py <before.txt> <after.txt>`
The measures of a step: `<range score> > <OUT>/range-<step>.txt 2>&1` and `<benchmark> > <OUT>/benchmark-<step>.txt 2>&1`.
@@ -46,11 +47,11 @@ Each agent is called with the Agent tool, its `subagent_type` (`agents:upgrader`
### Part 1: the detectors
1. **Measures before**: step `before`.
2. **Upgrader**, a single pass: `Target: <DETECTORS>. Evidence: station <STATION>, range <FROM> → <TO> (UTC); labels <LABELS>/<station>.jsonl; families <FAMILIES>; context <CONTEXT>. Checks: events: <events> (before: run it); sensors: <sensors> (before: run it); range: <range score> (before: <OUT>/range-before.txt); benchmark: <benchmark> (before: <OUT>/benchmark-before.txt). Base: <base>. Files already modified: <list | none>. Output folder: <OUT>. Write <OUT>/modification.md. INSTRUCTIONS: instructions/upgrader-detectors.md.`
It commits each fix it keeps, message `improve: S<n>`, with its benchmark `<OUT>/benchmark-S<n>.txt`.
2. **Upgrader**, a single pass: `Target: <DETECTORS>. Evidence: station <STATION>, range <FROM> → <TO> (UTC); labels <LABELS>/<station>.jsonl; families <FAMILIES>; context <CONTEXT>. Checks: events: <events> (before: run it); sensors: <sensors> (before: run it); range: <range score> (before: <OUT>/range-before.txt); benchmark: <benchmark> (before: <OUT>/benchmark-before.txt); compare: <compare>. Base: <base>. Files already modified: <list | none>. Output folder: <OUT>. Write <OUT>/modification.md. INSTRUCTIONS: instructions/upgrader-detectors.md.`
It commits each fix it keeps, message `improve: S<n>`, with its benchmark `<OUT>/benchmark-S<n>.txt`; each rule its pruning removes is a fix of its own.
Verdict `nothing to change`, or no fix commit (`git -C <DETECTORS> log --format=%h --grep ': S[0-9]*$' <base>..HEAD` empty): go to part 2.
3. **Measures after**: step `after`.
4. **Validator**, which reads neither the diagnosis nor the detail of the modification: `Target: <DETECTORS>. Modification: <OUT>/modification.md. Base: <base>. Checks: range: <range score>; before: <OUT>/range-before.txt; after: <OUT>/range-after.txt; benchmark: <benchmark>; before: <OUT>/benchmark-before.txt; after: <OUT>/benchmark-after.txt; after each fix: <OUT>/benchmark-S*.txt; events, for any station: python3 <DETECTORS>/scripts/categories.py <station folder> --from <from> --to <to>. Families: <FAMILIES>. Output: <OUT>/validation.md. INSTRUCTIONS: instructions/validator-detectors.md.`
4. **Validator**, which reads neither the diagnosis nor the detail of the modification: `Target: <DETECTORS>. Modification: <OUT>/modification.md. Base: <base>. Checks: range: <range score>; before: <OUT>/range-before.txt; after: <OUT>/range-after.txt; benchmark: <benchmark>; before: <OUT>/benchmark-before.txt; after: <OUT>/benchmark-after.txt; after each fix: <OUT>/benchmark-S*.txt; compare: <compare>; events, for any station: python3 <DETECTORS>/scripts/categories.py <station folder> --from <from> --to <to>. Families: <FAMILIES>. Output: <OUT>/validation.md. INSTRUCTIONS: instructions/validator-detectors.md.`
- `keep`: go to part 2.
- `remove`: for each fix of the `**Remove**:` line, its commits (`git -C <DETECTORS> log --format=%h --grep ': S<n>$' <base>..HEAD`), from the most recent: `git -C <DETECTORS> revert --no-edit <commit>`, then `git -C <DETECTORS> commit --amend -m "improve: S<n> removed" -m "Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>"`. A conflict: `git -C <DETECTORS> revert --abort`, and do as for `cancel`.
- `cancel`, or anything else: `git -C <DETECTORS> revert --no-commit <base>..HEAD && git -C <DETECTORS> commit -m "improve: modification cancelled" -m "Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>"` (only what the fix commits changed; files already modified stay as they are).
@@ -78,7 +79,7 @@ Always, whatever part 1 gave (a stop in part 1 does not stop part 2).
the range score, before → end, one line per family (found, correct)
## Elsewhere
the `Total` line of each family, before → end; then the other changed lines (station, family), before → end
the output of `<compare> <OUT>/benchmark-before.txt <OUT>/benchmark-<end>.txt`: the `Total` lines first, then the other changed lines, then its last line (regressions, complexity before → end)
## What changed
<per fix kept, one sentence from "What changed" of the modification>; the upgrader's verdict, the validator's
+7 -3
View File
@@ -18,20 +18,24 @@ An analyst has analysed a range of a station where the detectors perform poorly.
Compare, event by event and label by label: correct; wrong family; extra (flagged by the detectors, without a label); wrong bounds (late, too early, too wide); wrong sensors (the event's, by the sensors check, against those the description names); missing. A few measurements of gap at the bounds are not a defect. Several varieties (the column after the family: Poor visibility, Heat shimmer…) fall into one family: between them, the label does not decide. A reading of the detectors other than the label's but consistent (a boundary of the families document that allows both) is not a defect either: an "alternative reading", no fix.
Fixes to try first: a significant event missed or badly bounded before a small nuisance. The simplest first, for the detectors, ends with: as a last resort, a new variety (a `label`) in the family's detector.
Fixes to try first: a significant event missed or badly bounded before a small nuisance. The simplest first: widen or remove a rule before adding one; a new constant or more than 20 code lines must earn at least 1 point on a family `Total` (`<Target>/CLAUDE.md`, "Simple first"); as a last resort, a new variety (a `label`) in the family's detector.
## The pruning
After your fixes, and even when you fixed nothing: each rule of the detectors you touched (or, without a fix, of the detector the diagnosis blames most) is tried without it, on a copy in your working folder, one rule per copy, the benchmarks in the background, then `compare` against the benchmark of the last committed state. A removal with no regression is kept: a fix of its own (`S<n>`, its benchmark, its line of `thresholds.md` removed). A removal with a regression is not committed: say the rule and the regression.
## The checks
- **events**: before and after each fix, with `2>&1`.
- **range**: the range score, what you make rise, without losing a whole event. A hole has no measurement: it only counts its two bounds; for a hole, read the events check. Do not aim for 100 %.
- **benchmark**: all lines of all stations, against the benchmark of the last committed state (the benchmark before, or that of your previous kept fix); before your output, the whole against the benchmark before. A regression (`<Target>/CLAUDE.md`): rework your change before committing it, or drop the fix. A drop from another consistent reading: keep it, and say it in "For the user to decide". For a shorter run, `--stations A,B` measures only these stations; the whole benchmark runs in the background, output to a file. To try a variant without touching the repository, copy the target in your working folder: the copy's scripts measure the copy, with the same arguments.
- **benchmark**: all lines of all stations, through `compare` (its `REGRESSION` lines and the complexity), against the benchmark of the last committed state (the benchmark before, or that of your previous kept fix); before your output, the whole against the benchmark before. A regression (`<Target>/CLAUDE.md`): rework your change before committing it, or drop the fix. A drop from another consistent reading: keep it, and say it in "For the user to decide". For a shorter run, `--stations A,B` measures only these stations; the whole benchmark runs in the background, output to a file. To try a variant without touching the repository, copy the target in your working folder: the copy's scripts measure the copy, with the same arguments.
## Your output
On top of the skeleton of your trade:
- `## Diagnosis` opens with `<station, range, cadence>` and the table `| Family | labelled | found | flagged | wrongly |`, then one line per event or label: its judgement and why; same judgement and cause grouped.
- After `## Checks`: `## Before / after on the range` (the changed lines of the two outputs of the events check; the range score before → after, per family) and `## Benchmark` (the lines that changed, station and family, before → after, then the changed lines of the `Total` block).
- After `## Checks`: `## Pruning` (one line per rule tried: removed, its commit, or kept, the regression its removal makes); `## Before / after on the range` (the changed lines of the two outputs of the events check; the range score before → after, per family) and `## Benchmark` (the output of `compare` against the benchmark before, as it is).
- "For the user to decide": a reading of the detectors other than the labels', kept: the labels (id, station, moment, family), the detectors' reading, what it changes in the benchmark. "Limits": the label (id, bounds, family), what it would take to see it (image…); a label the context says is wrong (id).
Times in UTC. The orchestrator reads the `**Verdict**` line as it is.
+3 -2
View File
@@ -15,12 +15,13 @@ The upgrader has just adapted the detectors to better find the events of a singl
## What you judge, for the detectors
- Regressions: station by station and family by family, the range's station included, by the definition of `<Target>/CLAUDE.md`. A drop you do not count as a regression goes to "Reservations".
- Regressions: `compare` before → after, and before → after each fix in order (it says which fix makes a station go back); its `REGRESSION` lines are those of `<Target>/CLAUDE.md`, the range's station included. A `REGRESSION` line you do not count as one (an exception of `<Target>/CLAUDE.md`, "Not a regression") goes to "Reservations", with the labels (id).
- Complexity: the last line of `compare`. A fix that adds a constant or more than 20 code lines without 1 point on a family `Total` means remove; a fix that removes code without a regression (the pruning) is kept, even without a gain.
- A range gain of nothing or almost, at the price of one more rule, means cancel (or remove for the fix in question); a rule removed is better than a rule added.
## Your output
On top of the skeleton of your trade: `## The range` (the range score before → after, per family), placed before `## Checks`; under `## Checks`, the non-regression: the lines that changed, station and family, before → after, then the changed lines of the `Total` block. "Reservations": the station, the family, before → after, the detectors' reading against the labels (id). Times in UTC.
On top of the skeleton of your trade: `## The range` (the range score before → after, per family), placed before `## Checks`; under `## Checks`, the non-regression: the output of `compare` before → after, as it is. "Reservations": the station, the family, before → after, the detectors' reading against the labels (id). Times in UTC.
## Your answer