Add smiley feedback collector with comment after a completed run (RBT-WP-0004-T12)
Some checks failed
CI Smoke / host-smoke (push) Successful in 1s
CI Smoke / container-smoke (push) Successful in 4s
Work Records / validate (push) Has been cancelled

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

Assistant: claude-code
Assistant-Model: sonnet
Assistant-Process: 295952@bnt-lap001
Assistant-Session: e93f64ad-516c-46eb-9666-aad8d300c477
This commit is contained in:
tegwick 2026-09-29 11:10:25 +02:00
parent 7d0249ed51
commit c17b43264d
6 changed files with 167 additions and 2 deletions

View file

@ -232,3 +232,33 @@ def exercise_update(run: Run, today: date | None = None) -> tuple[str, str]:
new = STATUS_LINE.sub(f"exercise_status: exercised {today.isoformat()} by {run.data['operator']}",
old, count=1)
return old, new
RATINGS = {"good": ":)", "neutral": ":|", "poor": ":("}
def add_feedback(run: Run, rating: str, comment: str = "") -> dict:
"""Record how the runbook felt. Allowed at any time; the latest entry is the current one."""
if rating not in RATINGS:
raise RunError(f"rating must be one of {', '.join(RATINGS)}")
entry = {"rating": rating, "comment": _clean(comment.strip(), "comment"),
"at": datetime.now(timezone.utc).isoformat(timespec="microseconds")} # sortable even within one second
run.data.setdefault("feedback", []).append(entry)
run.save()
return entry
def latest_feedback(run: Run) -> dict | None:
fb = run.data.get("feedback") or []
return fb[-1] if fb else None
def all_feedback(pack: Pack) -> list[dict]:
"""Latest feedback of every run of this pack, newest first."""
out = []
for rid in list_runs(pack):
r = load(pack, rid)
fb = latest_feedback(r)
if fb:
out.append({"run_id": rid, "operator": r.data["operator"], **fb})
return sorted(out, key=lambda x: x["at"], reverse=True)