From bfa0224711dd56ca53acb03e9d51ff3a85cc3581 Mon Sep 17 00:00:00 2001 From: maxime Date: Mon, 16 Nov 2026 17:53:09 +0100 Subject: [PATCH] optimize: compare.py for the regressions and the complexity; the upgrader prunes the rules it touched Co-Authored-By: Claude Opus 5.5 --- .claude/skills/optimize/SKILL.md | 9 +++++---- instructions/upgrader-detectors.md | 10 +++++++--- instructions/validator-detectors.md | 5 +++-- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/.claude/skills/optimize/SKILL.md b/.claude/skills/optimize/SKILL.md index 48861ab..49955e9 100644 --- a/.claude/skills/optimize/SKILL.md +++ b/.claude/skills/optimize/SKILL.md @@ -32,6 +32,7 @@ Derived from `/request.json`: - sensors: `python3 /bench/sensors.py --from --to ` - range score (the goal): `python3 /bench/score.py --labels /.jsonl --from --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 /bench/regression.py ` +- compare (the regressions and the complexity of two benchmarks): `python3 /bench/compare.py ` The measures of a step: ` > /range-.txt 2>&1` and ` > /benchmark-.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: . Evidence: station , range → (UTC); labels /.jsonl; families ; context . Checks: events: (before: run it); sensors: (before: run it); range: (before: /range-before.txt); benchmark: (before: /benchmark-before.txt). Base: . Files already modified: . Output folder: . Write /modification.md. INSTRUCTIONS: instructions/upgrader-detectors.md.` - It commits each fix it keeps, message `improve: S`, with its benchmark `/benchmark-S.txt`. +2. **Upgrader**, a single pass: `Target: . Evidence: station , range → (UTC); labels /.jsonl; families ; context . Checks: events: (before: run it); sensors: (before: run it); range: (before: /range-before.txt); benchmark: (before: /benchmark-before.txt); compare: . Base: . Files already modified: . Output folder: . Write /modification.md. INSTRUCTIONS: instructions/upgrader-detectors.md.` + It commits each fix it keeps, message `improve: S`, with its benchmark `/benchmark-S.txt`; each rule its pruning removes is a fix of its own. Verdict `nothing to change`, or no fix commit (`git -C log --format=%h --grep ': S[0-9]*$' ..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: . Modification: /modification.md. Base: . Checks: range: ; before: /range-before.txt; after: /range-after.txt; benchmark: ; before: /benchmark-before.txt; after: /benchmark-after.txt; after each fix: /benchmark-S*.txt; events, for any station: python3 /scripts/categories.py --from --to . Families: . Output: /validation.md. INSTRUCTIONS: instructions/validator-detectors.md.` +4. **Validator**, which reads neither the diagnosis nor the detail of the modification: `Target: . Modification: /modification.md. Base: . Checks: range: ; before: /range-before.txt; after: /range-after.txt; benchmark: ; before: /benchmark-before.txt; after: /benchmark-after.txt; after each fix: /benchmark-S*.txt; compare: ; events, for any station: python3 /scripts/categories.py --from --to . Families: . Output: /validation.md. INSTRUCTIONS: instructions/validator-detectors.md.` - `keep`: go to part 2. - `remove`: for each fix of the `**Remove**:` line, its commits (`git -C log --format=%h --grep ': S$' ..HEAD`), from the most recent: `git -C revert --no-edit `, then `git -C commit --amend -m "improve: S removed" -m "Co-Authored-By: Claude Opus 5.5 "`. A conflict: `git -C revert --abort`, and do as for `cancel`. - `cancel`, or anything else: `git -C revert --no-commit ..HEAD && git -C commit -m "improve: modification cancelled" -m "Co-Authored-By: Claude Opus 5.5 "` (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 ` /benchmark-before.txt /benchmark-.txt`: the `Total` lines first, then the other changed lines, then its last line (regressions, complexity before → end) ## What changed ; the upgrader's verdict, the validator's diff --git a/instructions/upgrader-detectors.md b/instructions/upgrader-detectors.md index df7be74..8e6a970 100644 --- a/instructions/upgrader-detectors.md +++ b/instructions/upgrader-detectors.md @@ -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` (`/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`, 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 (`/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 (`/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 `` 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. diff --git a/instructions/validator-detectors.md b/instructions/validator-detectors.md index 87b025e..bb32937 100644 --- a/instructions/validator-detectors.md +++ b/instructions/validator-detectors.md @@ -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 `/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 `/CLAUDE.md`, the range's station included. A `REGRESSION` line you do not count as one (an exception of `/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