feedback: thumb up/down on logs + reviewer self-score 0-10
Two unrelated features bundled because they ship together and share
migration 0028.
Strategic-log feedback (thumb up/down):
- New strategic_log_feedback table with UNIQUE(log_id, user_id) so each
user has one vote per log, flippable in place (up -> down -> clear).
UI shows aggregate counts only.
- app/services/log_feedback.py: set_vote, get_counts, sign/verify
feedback tokens (same itsdangerous pattern as auth.sign_pending,
30-day TTL for email links).
- POST /api/log/{id}/feedback: web vote, auth required, returns counts
+ the requesting user's own vote.
- GET /feedback?token=...&vote=...: email-link target, no auth, signed
token encodes (user, log, vote), renders feedback_thanks.html.
- partials/log.html: thumbs row below content, JS-driven swap via the
POST endpoint. Dashboard latest-log card and /log page both render
this partial via htmx, so the buttons appear in all three surfaces.
- digest emails: a "How was today's read?" row above the unsub footer,
with signed-token URLs against the latest StrategicLog at send time.
Plain-text fallback included.
Reviewer self-score (0-10):
- _SYSTEM_PROMPT asks for an integer score with anchors (10 exemplary,
5 borderline, 0 unfit). Verdict gains score: int | None.
- Deterministic-layer hits get score=0 (hard rule, no nuance);
error rows get None; LLM rows get the model's score clamped 0..10.
- ReviewerVerdict.score, StrategicLog.reviewer_score, and
IndicatorSummary.reviewer_score all new SMALLINT NULL columns.
- ai_log_job + indicator_summary_job persist verdict.score onto their
content rows when committing the row alongside content.
Tests:
- tests/test_strategic_log_feedback.py: vote, flip, clear, aggregate
across users, invalid vote, token round-trip + tamper + garbage +
'clear' not signable for email path.
- tests/test_output_review.py: score parsing, clamping (>10, <0),
missing/non-numeric -> None, deterministic-layer score=0.
Full suite: 427 passed (was 412), 5 skipped, no regressions.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
f3ac65f8f7
commit
8946dee2e0
14 changed files with 962 additions and 14 deletions
|
|
@ -47,6 +47,7 @@ _DIGEST_HTML_TEMPLATE = """\
|
|||
</div>
|
||||
<div style="height:24px; line-height:24px; font-size:0;"> </div>
|
||||
<div style="border-top:1px solid {L_border};"></div>
|
||||
{feedback_row}
|
||||
<div style="height:14px; line-height:14px; font-size:0;"> </div>
|
||||
<div class="muted" style="font-size:11px; color:{L_muted};">
|
||||
<a href="{unsubscribe_url}" style="color:{L_accent};">Unsubscribe in one click</a>
|
||||
|
|
@ -70,6 +71,32 @@ def _strip_html_to_text(html_body: str) -> str:
|
|||
return text.strip()
|
||||
|
||||
|
||||
def _feedback_row_html(
|
||||
feedback_up_url: str | None,
|
||||
feedback_down_url: str | None,
|
||||
light_accent: str,
|
||||
light_muted: str,
|
||||
) -> str:
|
||||
"""Build the optional 'How was today's read?' row that sits between
|
||||
the digest content and the unsubscribe footer. Empty string when no
|
||||
feedback URLs were supplied (e.g. there's no latest log to vote on)."""
|
||||
if not feedback_up_url or not feedback_down_url:
|
||||
return ""
|
||||
return (
|
||||
'<div style="height:14px; line-height:14px; font-size:0;"> </div>'
|
||||
f'<div class="muted" style="font-size:12px; color:{light_muted};">'
|
||||
"How was today’s read? "
|
||||
f'<a href="{feedback_up_url}" '
|
||||
f'style="color:{light_accent}; text-decoration:none;">'
|
||||
"👍 Helpful</a>"
|
||||
" · "
|
||||
f'<a href="{feedback_down_url}" '
|
||||
f'style="color:{light_accent}; text-decoration:none;">'
|
||||
"👎 Not useful</a>"
|
||||
"</div>"
|
||||
)
|
||||
|
||||
|
||||
def render_digest_email(
|
||||
*,
|
||||
kind: str,
|
||||
|
|
@ -77,10 +104,17 @@ def render_digest_email(
|
|||
content_html: str,
|
||||
unsubscribe_url: str,
|
||||
settings_url: str,
|
||||
feedback_up_url: str | None = None,
|
||||
feedback_down_url: str | None = None,
|
||||
) -> tuple[str, str, str]:
|
||||
"""Returns (subject, text_body, html_body) for a digest email.
|
||||
|
||||
`kind` is "daily" or "weekly". Anything else raises ValueError."""
|
||||
`kind` is "daily" or "weekly". Anything else raises ValueError.
|
||||
|
||||
When ``feedback_up_url`` and ``feedback_down_url`` are both supplied,
|
||||
a small thumb up/down row is rendered above the unsubscribe footer.
|
||||
Both must be signed-token URLs pointing at /feedback (see
|
||||
``app.services.log_feedback.sign_feedback_token``)."""
|
||||
if kind == "daily":
|
||||
label = "Daily"
|
||||
subject = f"{branding.BRAND_NAME} · Daily — {date_str}"
|
||||
|
|
@ -90,6 +124,12 @@ def render_digest_email(
|
|||
else:
|
||||
raise ValueError(f"unknown digest kind: {kind!r}")
|
||||
|
||||
feedback_row = _feedback_row_html(
|
||||
feedback_up_url, feedback_down_url,
|
||||
light_accent=branding.LIGHT["accent"],
|
||||
light_muted=branding.LIGHT["muted"],
|
||||
)
|
||||
|
||||
html_body = _DIGEST_HTML_TEMPLATE.format(
|
||||
brand=branding.BRAND_NAME,
|
||||
brand_upper=branding.BRAND_NAME.upper(),
|
||||
|
|
@ -99,6 +139,7 @@ def render_digest_email(
|
|||
content_html=content_html,
|
||||
unsubscribe_url=unsubscribe_url,
|
||||
settings_url=settings_url,
|
||||
feedback_row=feedback_row,
|
||||
**{f"L_{k.replace('-', '_')}": v for k, v in branding.LIGHT.items()},
|
||||
**{f"D_{k.replace('-', '_')}": v for k, v in branding.DARK.items()},
|
||||
)
|
||||
|
|
@ -109,8 +150,16 @@ def render_digest_email(
|
|||
"",
|
||||
_strip_html_to_text(content_html),
|
||||
"",
|
||||
]
|
||||
if feedback_up_url and feedback_down_url:
|
||||
text_lines.extend([
|
||||
f"Was this read useful? Helpful: {feedback_up_url}",
|
||||
f" Not useful: {feedback_down_url}",
|
||||
"",
|
||||
])
|
||||
text_lines.extend([
|
||||
f"Unsubscribe: {unsubscribe_url}",
|
||||
f"Manage preferences: {settings_url}",
|
||||
]
|
||||
])
|
||||
text_body = "\n".join(text_lines)
|
||||
return subject, text_body, html_body
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue