Validation in the analysis: labels.jsonl carries review and says whether the analysis is validated (also in the sidebar list); Validate writes it there then submits; a page edit or removal is mirrored there; a resubmission keeps the ids of unchanged labels

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
maximeandClaude Opus 5.5 committed 2026-11-17 12:01:23 +01:00
1 parent effcf8fdcb
commit ce0200a97a
3 files changed
+94 -42

No files matched your search

+40 -32
View File
@@ -5,7 +5,8 @@ labeling/auto/analyses/<STATION>_<start>_<end>/ its labels (labels.jsonl) and a
next to it); at the end, the server submits its labels to labeling/auto/<STATION>.jsonl, marked with their analysis (field
`analysis`). Then the user can write to it: the same session resumes (`claude -p --resume`), and its labels, if they
change, replace those it had submitted. "Validate labels": the user agrees with all the labels of the analysis, each gets
`review`, the date (labeling/README.md); labels the analyst changes afterwards are submitted again without it.
`review`, the date (labeling/README.md), in labels.jsonl, then submitted; the analysis is validated when all the labels of
its labels.jsonl have it. A label changed afterwards, by the analyst or in the page, loses it.
On a finished analysis, "Optimize" launches `/optimize` in Optimizer (optimizer/, the skill that, from the analysis, improves
the detectors on its range, its labels as truth, then brings the analyst's scripts into the reading tools, tools/); one
optimization at a time, no analysis or message meanwhile; the summary of the session
@@ -122,7 +123,8 @@ def message(name, body):
log.write(line)
a["lines"] += digest(line)
prompt = (f"{text}\n\n(If you change your labels, rewrite {out.relative_to(station.ROOT)}/labels.jsonl in full, the "
"server will submit them again; if the diagnosis changes, update report.md.)")
"server will submit them again; a label you change loses its review field; if the diagnosis changes, update "
"report.md.)")
threading.Thread(target=work, args=(name, out, prompt, session.read_text()), daemon=True).start()
return {}
@@ -148,27 +150,34 @@ def digest(line):
return out
def _labels(out):
"""The labels of the analysis, its labels.jsonl."""
f = out / "labels.jsonl"
return [json.loads(l) for l in f.read_text(encoding="utf-8").split("\n") if l.strip()] if f.exists() else []
def submit(st, name, out):
"""The labels of the analysis into labeling/auto/<STATION>.jsonl, with their id and the name of the analysis; if the
analyst changed them since the last submission, they replace those it had submitted -> their number."""
"""The labels of the analysis into labeling/auto/<STATION>.jsonl, with their id, their review and the name of the
analysis; if they changed since the last submission, they replace those it had submitted, an unchanged label keeping
its id -> their number."""
labels, copy = out / "labels.jsonl", out / "work" / "submitted.jsonl"
text = labels.read_text(encoding="utf-8") if labels.exists() else ""
new = []
for l in text.split("\n"):
if l.strip():
e = json.loads(l)
label = {k: e[k] for k in ("start", "end", "family", "description") if k in e}
station.checked(label)
new.append(label | {"analysis": name})
for e in _labels(out):
label = {k: e[k] for k in (*station.CORE, "review") if k in e}
station.checked(label)
new.append(label | {"analysis": name})
if copy.exists() and copy.read_text(encoding="utf-8") == text:
return len(new)
# ponytail: removed then put back, the labels of the analysis lose the edits made in the page; keeping them would
# require matching them one by one
with lock:
f = station.label_file(st, "auto") # the other lines stay as they are
kept = [l for l in (f.read_text(encoding="utf-8").split("\n") if f.exists() else [])
if l.strip() and json.loads(l).get("analysis") != name]
station.ids.assign(st, [json.loads(l) for l in kept] + new)
lines = [l for l in (f.read_text(encoding="utf-8").split("\n") if f.exists() else []) if l.strip()]
kept = [l for l in lines if json.loads(l).get("analysis") != name]
ids = {station.core(e): e["id"] for l in lines if (e := json.loads(l)).get("analysis") == name and "id" in e}
for e in new:
if station.core(e) in ids:
e["id"] = ids.pop(station.core(e))
station.ids.assign(st, [json.loads(l) for l in kept] + new, removed=ids.values())
temp = f.with_name(f.name + ".tmp")
temp.write_text("".join(l + "\n" for l in kept + [json.dumps(e, ensure_ascii=False) for e in new]), encoding="utf-8")
os.replace(temp, f)
@@ -187,31 +196,30 @@ def state(name):
analyses[name] = {"state": "done" if (out / "report.md").exists() else "interrupted", "lines": lines,
"submitted": None, "station": request["station"], "request": request}
a, r = analyses[name], out / "report.md"
labels = [e for e in station.read(a["station"], "auto") if e.get("analysis") == name]
validated = max(e["review"] for e in labels) if labels and all(e.get("review") for e in labels) else None
return {"name": name, "state": a["state"], "lines": a["lines"], "submitted": a["submitted"], "validated": validated,
return {"name": name, "state": a["state"], "lines": a["lines"], "submitted": a["submitted"],
"validated": _validated(name),
"report": int(r.stat().st_mtime) if r.exists() else None,
"dialogue": (out / "work" / "session").exists(), "request": a["request"], "optimization": optimization(name)}
def _validated(name):
"""The date the user validated the labels of the analysis (the last), or None if one of its labels.jsonl is not."""
its = _labels(FOLDER / name)
return max(e["review"] for e in its) if its and all(e.get("review") for e in its) else None
def validate(name):
"""The "Validate labels" button: the user agrees with all the labels of the finished analysis -> their number."""
a = state(name)
if a["state"] != "done":
raise station.Refusal("only a finished analysis can be validated")
today = datetime.now(timezone.utc).strftime("%Y-%m-%d")
with lock:
f = station.label_file(a["request"]["station"], "auto") # the other lines stay as they are
lines, n = f.read_text(encoding="utf-8").split("\n") if f.exists() else [], 0
for i, l in enumerate(lines):
if l.strip() and (e := json.loads(l)).get("analysis") == name:
lines[i], n = json.dumps(e | {"review": today}, ensure_ascii=False), n + 1
if not n:
raise station.Refusal(f"no label of this analysis in labeling/auto/{f.name}")
temp = f.with_name(f.name + ".tmp")
temp.write_text("\n".join(lines), encoding="utf-8")
os.replace(temp, f)
return {"validated": n}
out, today = FOLDER / name, datetime.now(timezone.utc).strftime("%Y-%m-%d")
labels = _labels(out)
if not labels:
raise station.Refusal("no label in this analysis")
station.write(out / "labels.jsonl", [e | {"review": e.get("review") or today} for e in labels])
analyses[name]["submitted"] = submit(a["request"]["station"], name, out)
return {"validated": len(labels)}
def list_analyses():
@@ -222,7 +230,7 @@ def list_analyses():
name = d.parent.name
a = analyses.get(name) or {"state": "done" if (d.parent / "report.md").exists() else "interrupted",
"request": json.loads(d.read_text(encoding="utf-8"))}
out.append({"name": name, "state": a["state"]} | a["request"])
out.append({"name": name, "state": a["state"], "validated": _validated(name)} | a["request"])
return out