Sync repo to deployed state: SEO recovery, Publishing Desk, Play games, emoji picker

The deploy pipeline runs from the working tree, so a wave of shipped features
had never been committed. This snapshots git to what's actually running.

SEO impression recovery (live + verified):
- Duplicate /a/{id} now 301-redirect to their canonical twin instead of 404
  (a hard 404 silently dropped already-indexed URLs and tanked impressions).
- Dedup representative selection reworked: accepted/serveable -> established
  rep (URL stability) -> quality score, so an accepted page never retires to a
  rejected rep and an indexed canonical doesn't churn when a newer twin arrives.
- HEAD /a/{id} returns the same status as GET (api_route GET+HEAD) instead of
  falling through to the static mount and 404ing.
- `dedup --force-recluster`: cycle-locked, model-free re-cluster to re-apply the
  policy to the existing corpus (shared cycle_lock context manager).
- CLI honors GOODNEWS_DB for its default --db (was silently ignored).

Publishing Desk (admin tool to post highlights to X via Web Intents):
- publishing.py queue/rank/handle-resolution; admin UI; full searchable emoji
  picker (bundled data, no CDN) for the blurb editor.

Play games + site:
- Bloom (word-wheel), Memory Match, daily ritual set, Zen Den (dev-gated).
- English-only language gate; source prospecting; paywall + dedup hardening.

Tests: full suite green (349). Ignores tightened (node_modules, data/*.db).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
jay
2026-06-18 11:32:27 -04:00
parent 2dbe73430c
commit 89c0fbe1f6
66 changed files with 6138 additions and 109 deletions
+25 -3
View File
@@ -102,7 +102,8 @@ def cluster_duplicates(
(COALESCE(s.constructive_score,0) + COALESCE(s.agency_score,0)
+ COALESCE(s.human_benefit_score,0) + src.trust_score
- COALESCE(s.cortisol_score,0) - COALESCE(s.ragebait_score,0)
- COALESCE(s.pr_risk_score,0)) AS rank_score
- COALESCE(s.pr_risk_score,0)) AS rank_score,
COALESCE(s.accepted, 0) AS accepted
FROM articles a
JOIN article_embeddings e ON e.article_id = a.id
JOIN sources src ON src.id = a.source_id
@@ -114,7 +115,8 @@ def cluster_duplicates(
items = []
for r in rows:
vec = _unit(array("f", r["vector"]).tolist())
items.append({"id": r["id"], "ord": _day_ordinal(r["dt"]), "vec": vec, "score": r["rank_score"]})
items.append({"id": r["id"], "ord": _day_ordinal(r["dt"]), "vec": vec,
"score": r["rank_score"], "accepted": bool(r["accepted"])})
clusters: list[dict] = [] # {anchor_vec, anchor_ord, members:[item]}
for it in items:
@@ -130,6 +132,14 @@ def cluster_duplicates(
if not placed:
clusters.append({"anchor_vec": it["vec"], "anchor_ord": it["ord"], "members": [it]})
# Which articles are CURRENTLY a representative (something points at them)? Captured
# BEFORE we reset, so we can keep an established canonical stable across runs.
prior_reps = {
row[0] for row in conn.execute(
"SELECT DISTINCT duplicate_of FROM articles WHERE duplicate_of IS NOT NULL"
)
}
# Reset prior decisions for everything we considered, then re-apply.
considered = [it["id"] for it in items]
conn.executemany(
@@ -142,7 +152,19 @@ def cluster_duplicates(
if len(cl["members"]) < 2:
continue
dup_clusters += 1
rep = max(cl["members"], key=lambda m: (m["score"], -m["id"]))
# Representative priority (highest wins), in order:
# 1. accepted/serveable — an accepted page must never be retired to a REJECTED
# rep (that page would 404 with nothing to redirect to).
# 2. established rep — if a member is already the cluster's canonical, keep it,
# so an indexed URL doesn't churn when a newer twin arrives.
# 3. quality score — decides genuinely-new clusters.
# 4. -id — deterministic final tiebreak (older wins).
rep = max(cl["members"], key=lambda m: (
1 if m["accepted"] else 0,
1 if m["id"] in prior_reps else 0,
m["score"],
-m["id"],
))
for m in cl["members"]:
if m["id"] != rep["id"]:
conn.execute(