feat: proactive thoughts — auto-ping salient ones + daily digest

She was passive (thoughts piled up 'open'; Brian had to mine the feed). Now she
brings them to him:

- Live: a thought >= PING_AUTO_SALIENCE (0.8) auto-pings — _compose_reachout writes
  a short personal text in her voice (not a thought-dump), on a cooldown
  (PING_COOLDOWN_MIN=60, AUTO only; explicit reach-outs bypass), quiet hours respected.
- Daily: maybe_daily_digest() texts a once-per-local-day summary of what she's been
  turning over (after DIGEST_HOUR=18), run from the dream cycle.
- maybe_ping gains bypass_cooldown (her deliberate reach-outs always go through).

8 new/updated tests (auto-ping above/below bar, digest once-per-day, floor/cooldown
isolation). Suite 80 green, ruff clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-22 20:25:14 +00:00
parent cf4238911e
commit 149e9a6dd5
5 changed files with 133 additions and 9 deletions
+46
View File
@@ -250,6 +250,7 @@ def test_no_ping_without_a_reach_out_message(lyra, monkeypatch):
_, th, box = lyra
monkeypatch.setenv("NTFY_URL", "http://ntfy.test")
monkeypatch.setenv("PING_QUIET_HOURS", "0-0")
monkeypatch.setenv("PING_AUTO_SALIENCE", "1.1") # disable auto-ping to isolate reach_out path
sent = []
monkeypatch.setattr(th.notify, "push", lambda **k: (sent.append(k), True)[1])
# salient thought but she did NOT decide to tell him -> no ping (it's not a broadcast)
@@ -260,10 +261,55 @@ def test_no_ping_without_a_reach_out_message(lyra, monkeypatch):
assert th.think(force_mode="new")["pinged"] is False and sent == []
def test_auto_ping_on_salient_thought(lyra, monkeypatch):
_, th, box = lyra
monkeypatch.setenv("NTFY_URL", "http://ntfy.test")
monkeypatch.setenv("PING_QUIET_HOURS", "0-0")
monkeypatch.setenv("PING_AUTO_SALIENCE", "0.7")
monkeypatch.setenv("PING_COOLDOWN_MIN", "0")
sent = []
monkeypatch.setattr(th.notify, "push", lambda **k: (sent.append(k), True)[1])
monkeypatch.setattr(th, "_compose_reachout", lambda *a, **k: "Hey, been thinking about this.")
_gen(box, content="a genuinely salient thought", salience=0.9) # no explicit reach_out
r = th.think(force_mode="new")
assert r["pinged"] is True and sent and "thinking about" in sent[0]["message"]
def test_no_auto_ping_below_bar(lyra, monkeypatch):
_, th, box = lyra
monkeypatch.setenv("NTFY_URL", "http://ntfy.test")
monkeypatch.setenv("PING_QUIET_HOURS", "0-0")
monkeypatch.setenv("PING_AUTO_SALIENCE", "0.8")
sent = []
monkeypatch.setattr(th.notify, "push", lambda **k: (sent.append(k), True)[1])
_gen(box, content="a quieter musing", salience=0.5) # below auto bar, no reach_out
assert th.think(force_mode="new")["pinged"] is False and sent == []
def test_daily_digest_sends_once_per_day(lyra, monkeypatch):
_, th, box = lyra
monkeypatch.setenv("NTFY_URL", "http://ntfy.test")
monkeypatch.setenv("PING_QUIET_HOURS", "0-0")
monkeypatch.setenv("DIGEST_HOUR", "0") # any time qualifies
monkeypatch.setenv("PING_AUTO_SALIENCE", "1.1") # keep think() from pinging during setup
sent = []
monkeypatch.setattr(th.notify, "push", lambda **k: (sent.append(k), True)[1])
_gen(box, title="thread A", content="a", salience=0.5)
th.think(force_mode="new")
_gen(box, title="thread B", content="b", salience=0.5)
th.think(force_mode="new")
assert th.maybe_daily_digest() is True
assert sent and "thread" in sent[-1]["message"].lower()
sent.clear()
assert th.maybe_daily_digest() is False # already sent today
assert sent == []
def test_ping_salience_floor_is_optional(lyra, monkeypatch):
_, th, _ = lyra
monkeypatch.setenv("NTFY_URL", "http://ntfy.test")
monkeypatch.setenv("PING_QUIET_HOURS", "0-0")
monkeypatch.setenv("PING_COOLDOWN_MIN", "0") # isolate the salience floor from cooldown
sent = []
monkeypatch.setattr(th.notify, "push", lambda **k: (sent.append(k), True)[1])
# default floor 0.0 -> her decision (a message) is enough, any salience pings