Small joys: Codex audit #2 fixes (route resolution, noindex, sense/tone, exclude-current re-pick)

- Admin joy item route moved to /api/admin/joys/{kind}/items/{item_id} so the
  /add and /repick verbs resolve to their own routes instead of 422-ing as a
  non-int item id (the launch blocker). Frontend mutate URL updated to match.
- Re-pick now excludes the currently-shown item: the endpoint reads today's
  daily pool_id and passes it as `avoid`, so "Re-pick today" yields a different
  item. Added `avoid` to pick_daily/_candidates across wotd/quote/onthisday.
- WOTD sense selection: the LLM now proposes word + intended part of speech, and
  _lookup prefers that sense (fixes "serene" returning the archaic noun).
- On This Day tone prompt tightened to favor genuinely uplifting events and
  exclude merely procedural/political-administrative ones.
- Caddy @hidden now also noindexes /word /quote /onthisday /admin (+ .html).
- Regression tests: add/repick resolve (401 not 422), add/feature/block/delete,
  re-pick excludes current; WOTD pos-preference + proposal parsing units.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
jay
2026-06-22 20:19:02 -04:00
parent 3bde6534e9
commit 84b1fb514f
9 changed files with 217 additions and 51 deletions
+26 -15
View File
@@ -62,10 +62,15 @@ def _llm_keep(client, candidates: list[dict]) -> list[dict]:
keep the keyword-passed set (never lose the day to a model hiccup)."""
lines = [f"{i}: {c['text']}" for i, c in enumerate(candidates)]
user = (
"These are 'on this day' history events. Return the indices of the ones with a "
"POSITIVE or NEUTRAL, uplifting tone — discoveries, inventions, firsts, achievements, "
"peace, the arts, science, exploration, culture, milestones. EXCLUDE anything about "
"war, violence, disasters, death, or tragedy.\n\n" + "\n".join(lines) +
"These are 'on this day' history events. Return the indices of the ones that are "
"GENUINELY UPLIFTING — a reader should feel a small lift of wonder, hope, or delight. "
"Keep: discoveries, inventions, scientific breakthroughs, the arts and culture, "
"exploration, human achievement, acts of courage or kindness, milestones of progress "
"(rights won, things built, records set). EXCLUDE war, violence, disasters, death, or "
"tragedy, AND exclude merely procedural or political-administrative events that carry no "
"warmth (a coronation or accession, a treaty signing, an election, a law passed, a "
"boundary or office change). When unsure whether something is truly uplifting, leave it "
"out.\n\n" + "\n".join(lines) +
'\n\nReply with JSON only, exactly: {"keep": [<indices>]}'
)
txt = client.chat_text([{"role": "user", "content": user}])
@@ -115,23 +120,29 @@ def harvest(conn: sqlite3.Connection, md: str | None = None, client=None) -> dic
return {"md": md, "fetched": len(events), "kept": len(kept), "added": after - before, "pool": after}
def _candidates(conn: sqlite3.Connection, md: str) -> list[int]:
def _candidates(conn: sqlite3.Connection, md: str, avoid: int | None = None) -> list[int]:
"""The pick pool for a date: if admin has featured any, pick only among those;
otherwise the N least-recently-shown."""
otherwise the N least-recently-shown. `avoid` drops a specific id (admin re-pick)
unless it's the only option."""
featured = conn.execute(
"SELECT id FROM onthisday_pool WHERE md=? AND blocked=0 AND featured=1 ORDER BY id", (md,)
).fetchall()
if featured:
return [r[0] for r in featured]
rows = conn.execute(
"SELECT id FROM onthisday_pool WHERE md=? AND blocked=0 "
"ORDER BY shown_at IS NOT NULL, shown_at, id LIMIT ?",
(md, _NO_REPEAT_POOL),
).fetchall()
return [r[0] for r in rows]
ids = [r[0] for r in featured]
else:
rows = conn.execute(
"SELECT id FROM onthisday_pool WHERE md=? AND blocked=0 "
"ORDER BY shown_at IS NOT NULL, shown_at, id LIMIT ?",
(md, _NO_REPEAT_POOL),
).fetchall()
ids = [r[0] for r in rows]
if avoid is not None:
ids = [i for i in ids if i != avoid] or ids
return ids
def pick_daily(conn: sqlite3.Connection, feature_date: str | None = None, force: bool = False) -> dict | None:
def pick_daily(conn: sqlite3.Connection, feature_date: str | None = None, force: bool = False,
avoid: int | None = None) -> dict | None:
"""Pick + cache today's fact. Idempotent (skips if today's done unless force).
Returns the stored row, or None if the pool has nothing for today's date."""
feature_date = feature_date or local_today()
@@ -139,7 +150,7 @@ def pick_daily(conn: sqlite3.Connection, feature_date: str | None = None, force:
existing = conn.execute("SELECT * FROM daily_onthisday WHERE feature_date=?", (feature_date,)).fetchone()
if existing and not force:
return dict(existing)
ids = _candidates(conn, md)
ids = _candidates(conn, md, avoid)
if not ids:
return None
pick_id = daily.seeded_order(ids, feature_date)[0]