feat: thought loop — Lyra's threaded, surfaceable train of thought

Built from her own 6-19 idea: a continuing train of thought she keeps across
days, organized into threads she returns to, that she can bring TO Brian and
that his feedback advances or closes. Where the dream cycle's reflect() gives
isolated, overwriting reflections, the thought loop adds continuity (threads),
surfacing (#6 — she leads with a thought when Brian returns after a gap), and a
feedback loop (his reply folds in next pass).

- lyra/thoughts.py: thought_threads + thoughts tables; think() with
  new/continue/respond modes; salience-gated maybe_surface(); record_response()
  feedback; lazy-schema _c() mirroring poker.
- dream.py: curiosity stage advances the loop after reflecting (error-isolated).
- chat.py: build_messages surfaces the top thread after a >=90min gap, once.
- web: /thoughts feed (page + data + respond + status routes), thoughts.html,
  nav 💭 entry. lyra-think entry point. Every thought also lands in her journal.
- clock.gap_seconds(); tests/test_thoughts.py (8 tests). Full suite 58 passing.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-21 07:05:15 +00:00
parent debb553fe9
commit 5176c706b6
9 changed files with 833 additions and 4 deletions
+10 -2
View File
@@ -25,7 +25,7 @@ import argparse
import time
from datetime import datetime, timezone
from lyra import config, era, logbus, memory, narrative, profile, self_state, summary
from lyra import config, era, logbus, memory, narrative, profile, self_state, summary, thoughts
from lyra.llm import Backend
from lyra.summary import SUMMARIZE_AFTER
@@ -98,10 +98,18 @@ def dream_cycle(backend: Backend | None = None, force: bool = False) -> dict:
actions.append("integrated knowledge (profile/eras/narrative)")
drives["coherence"] = 0.0
# --- curiosity: reflect and evolve the self ---
# --- curiosity: reflect and evolve the self, then advance the thought loop ---
if force or drives["curiosity"] >= THRESHOLD:
self_state.reflect(backend=backend, source="dream") # writes state + journal itself
actions.append("reflected")
# Thinking, continued: advance one threaded train of thought. reflect()
# just refreshed her self-state, so the thought is grounded in it. A bad
# think pass shouldn't sink the cycle.
try:
rep = thoughts.think(backend=backend, source="dream")
actions.append(f"thought ({rep['mode']})" if rep else "thought (no parse)")
except Exception as exc:
logbus.log("error", "thought loop failed", error=str(exc)[:200])
drives["curiosity"] = CURIOSITY_FLOOR
if not actions: