--- name: wf-improve description: Automatic session that improves the detectors from an analysis of the Data page of Diagnostic-app (labeling/auto/analyses//) — the upgrader diagnoses and fixes, the validator judges; the goal, detectors closer to the analysis's labels on its range, without overfitting; the safeguard, the benchmark on all stations and all families of labeling/auto/. Started by the "Optimiser les détecteurs" button of the app (claude -p --plugin-dir detectors), or by the user, /detectors:wf-improve . argument-hint: "" --- # wf-improve: the detectors from an analysis You are the orchestrator. You run in the **working repository** (Diagnostic-app, the current folder): `labeling/` (the labels, the truth; the analyses), `data/` (the stations' data), `agent-tools/`. The **detectors** repository is mounted there as `detectors/` (a submodule): the detectors (`detectors/scripts/`), their threshold registry `detectors/thresholds.md`, the session tools (`detectors/skills/wf-improve/scripts/`) and the sessions (`detectors/wf-improve/`). Two git repositories, then: what touches the detectors is committed in `detectors/` (`git -C detectors …`), the analysis in the working repository. The user chose a range where the detectors satisfy them poorly; the analyst analysed it in the Data page: a report (`rapport.md`) and labels, added to `labeling/auto/.jsonl`. The user reviewed it, and starting this session is their agreement: there is no other validation. The goal: detectors **closer to the analysis's labels on its range**, by a small step, **without overfitting**: they do a little better there, and the benchmark on all stations and families of `labeling/auto/` stays good. You call the agents in order, pass on their outputs and commit. **You judge nothing yourself**: you only read the verdict lines. **You ask the user no question**: the session runs alone to the end. ## 1. Setup - Argument: the name of an analysis, a folder of `labeling/auto/analyses/` (e.g. `NORDEND_2026-11-04T2112_2026-11-07T1412`); a path to this folder counts as its name. `ANALYSIS` = the name, `A` = `labeling/auto/analyses/`. Without `/demande.json`, or without `detectors/.claude-plugin/plugin.json`: say so and stop, without a commit. - From `/demande.json` (written by the app, French keys): `STATION`, `début`, `fin` (UTC). `FROM` = the day of `début`, `TO` = the day after the day of `fin` (YYYY-MM-DD): the range of the commands, in whole days. - `SESSION` = `date -u +%Y-%m-%dT%H%MZ`; session folder `detectors/wf-improve/_/`, below ``. - **Commits**: in both repositories, the branch must be `main` (`git branch --show-current` and `git -C detectors branch --show-current`), otherwise say so and stop; a detached submodule (no branch): `git -C detectors checkout main` first, if it has no change. You always commit by path (`git add && git commit -m "" -- `, or with `git -C detectors`, paths relative to `detectors/`), never `git add -A`, `git stash` or `git checkout` outside your paths: another session may be working in these repositories. Before each commit, the branch; if it is no longer `main`, commit nothing more and go to the summary. Each message ends with an empty line then `Co-Authored-By: Claude Opus 5.5 `. You push nothing. - **Step 0, the analysis in git**: the app does not commit; if `git status --porcelain -- labeling/auto/.jsonl` shows something, commit these two paths in the working repository (`git add` respects `.gitignore`: `travail/` stays out), message `wf-improve : labels of the analysis`. Then note the **session base**: `git -C detectors rev-parse HEAD`. - `git -C detectors status --porcelain` and `git status --porcelain -- labeling/auto/ labeling/familles.md` (`familles.md`: the families, one per detector, that the benchmark counts): files already modified stay as they are, neither committed nor reverted; list them under "Errors" of the summary (the measures run on them). Take this reading again before the validator and before the summary, with the re-pumped data (`find -L data/ -name '*.csv' -newer /benchmark-before.txt | cut -d/ -f2 | sort -u`): a file changed during the session by another session (a label touched up in the Data page, for example) goes under "Errors"; before the validator, then rerun the benchmark before at the session base (in a `mktemp -d` folder: `git -C detectors archive --prefix=detectors/ | tar -x -C `, links to `data/`, `labeling/` and `agent-tools/` of the working repository, then `python3 /detectors/skills/wf-improve/scripts/regression.py`) into `/benchmark-before-rerun.txt`, and add to the validator's request: `Changed during the session: ; benchmark before rerun: /benchmark-before-rerun.txt.` **The two measures** of the session, at each step: - **the benchmark**, the non-regression: `python3 detectors/skills/wf-improve/scripts/regression.py > /benchmark-.txt 2>&1` (about 3 min). The score per family and per instant on each station of `labeling/auto/`, then their `Total`; - **the range score**, the goal: `python3 detectors/skills/wf-improve/scripts/score.py data/ --from --to > /range-.txt 2>&1`. The labels of `labeling/auto/.jsonl` touching the range (the analysis's included), the truth of the session, against the detectors, per family. It exits with an error if no label touches the range: note it under "Errors" and go to the summary without touching the detectors. **Commands**, given as they are to the agents: the events, `python3 detectors/scripts/categories.py data/ --from --to `; the sensors, `python3 detectors/skills/wf-improve/scripts/sensors.py data/ --from --to `. For the validator only, which looks at all stations, the events command with ``, `` and `` to fill from the header of the station's block in the benchmark: `python3 detectors/scripts/categories.py data/ --from --to `. ## 2. In order Each agent is called with the Agent tool and its `subagent_type` (those of this plugin: `detectors:upgrader`, `detectors:validator`) and the request below, nothing else, except a user instruction given at launch: add it as it is to the agents' request (`User instruction: …`) and note it in the summary; it comes before their instructions, not before their file scope. A verdict is read by `grep '^\*\*Verdict\*\*:' `; what goes with it ("Reservations" of the validator) does not change what follows, it goes to the summary. The goal: detectors that do better, not perfect; another reading than the labels', consistent, is allowed. Session commits (the session folder, the detectors, `thresholds.md`) are made in `detectors/`: `git -C detectors add && git -C detectors commit -m "" -- `. 1. **Measures before**: step `before`, so `/benchmark-before.txt` and `/range-before.txt`. Commit `wf-improve/_/`, message `wf-improve : benchmark`. 2. **Upgrader**, a single pass: `Analysis: /. Station: , range → (UTC). Events command: . Sensors command: . Range score: python3 detectors/skills/wf-improve/scripts/score.py data/ --from --to (before: /range-before.txt). Benchmark before: /benchmark-before.txt, to rerun with python3 detectors/skills/wf-improve/scripts/regression.py. Session folder: . Files already modified at the start of the session: . Write /modification.md.` The upgrader commits each fix it keeps itself, in `detectors/`, with its benchmark `/benchmark-S.txt`, message `wf-improve : S`: the validator can thus have a single one removed. Then the measures, step `after`, in `/benchmark-after.txt` and `/range-after.txt`. Commit of the session folder, message `wf-improve : modification ()`. No fix kept (verdict `nothing to change`, or no `, S` commit: `git -C detectors log --format=%h --grep ': S[0-9]*$' ..HEAD`): go to the summary. 3. **Validator**, which reads neither the diagnosis nor the detail of the modification: `Analysis: . Modification: /modification.md. Benchmark: /benchmark-before.txt → /benchmark-after.txt, to rerun with python3 detectors/skills/wf-improve/scripts/regression.py; after each fix: /benchmark-S*.txt. Range score: /range-before.txt → /range-after.txt. Events command: . Base (in detectors/): . Write /validation.md.` Commit of the session folder, message `wf-improve : validator ()`. - `keep`: go to the summary. - `remove`: for each fix of the `**Remove**:` line, its session commits (`git -C detectors log --format=%h --grep ': S$' ..HEAD`), from the most recent to the oldest: `git -C detectors revert --no-edit `, then amend its message so that it ends with the `Co-Authored-By` line (`git -C detectors commit --amend -m "wf-improve : S removed" -m "Co-Authored-By: Claude Opus 5.5 "`). A conflict: `git -C detectors revert --abort`, and do as for `cancel`. Then go to the summary. - `cancel`, or any other word: `git -C detectors checkout -- 'scripts/*.py' thresholds.md` (without the files already modified noted in §1; `skills/wf-improve/` is not touched), commit of these paths, message `wf-improve : modification cancelled`. An output missing or without a readable verdict: note it, put the detectors back as for `cancel` if they changed, go to the summary. Do not rerun an agent more than once. ## 3. Summary The measures, step `end`, in `/benchmark-end.txt` and `/range-end.txt`. `/summary.md`, which the Data page shows under the report: ```markdown # Optimisation: **Result**: modification kept | kept without S… | cancelled | none | error ## The analysis's range , → ; the range score, before → end, one line per family (found, correct) ## All stations the line of each family of the `Total`, before → end; then the other changed lines (station, family), before → end ## What changed ; the upgrader (verdict, n fixes), the validator (verdict) ## For the user to decide ## Not fixed <"Not fixed" of the modification; none> ## Errors ..HEAD`> ``` Commit, in `detectors/`, of the session folder, message `wf-improve : summary`. Then, in the working repository, the submodule at its new commit: `git add detectors && git commit -m "wf-improve : detectors" -- detectors`, if `git status --porcelain -- detectors` shows it changed. ## 4. Final answer In 4 lines at most: the `**Result**` line of the summary, the range score before → end (changed families), the `Total` before → end if it changed, the path of the summary. Nothing is pushed: the user pushes `detectors` so that everyone has the updated detectors, or cancels what they do not keep with `git -C detectors revert`.