feat: Lyra's journal — permanent thought record + a knowing journal note
Her reflections/metacognition were capped rolling windows (6/5), so older thoughts were lost for good. Now everything she produces is also appended to a permanent, append-only journal; the capped lists stay as her working-memory window for context. - memory: journal table + add_journal_entry/list_journal - reflect(): persists every committed reflection + critique to the journal, and the examine step gains a "journal" field — a deliberate, first-person note she writes for herself (her knowing journaling), tagged by source (dream/manual) - web: /journal diary view (kind filters, grouped by day) + /journal/data; linked from /self - tests assert reflections + metacognition land in the journal Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -132,6 +132,15 @@ def create_app() -> FastAPI:
|
||||
state = await asyncio.to_thread(self_state.reflect)
|
||||
return {"ok": True, "mood": state.get("mood")}
|
||||
|
||||
@app.get("/journal")
|
||||
async def journal_page() -> FileResponse:
|
||||
"""Lyra's journal — the permanent, append-only record of her thoughts."""
|
||||
return FileResponse(str(_STATIC / "journal.html"))
|
||||
|
||||
@app.get("/journal/data")
|
||||
async def journal_data(limit: int = 300) -> dict:
|
||||
return {"entries": memory.list_journal(limit=limit)}
|
||||
|
||||
@app.get("/stream/logs")
|
||||
async def stream_logs(request: Request) -> StreamingResponse:
|
||||
"""Live activity feed: replay the recent buffer, then stream new events."""
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
|
||||
<meta name="theme-color" content="#0b0d12" />
|
||||
<title>Lyra — Journal</title>
|
||||
<style>
|
||||
:root {
|
||||
--bg: #0b0d12; --bg-elev: #141821; --bg-line: #11141b; --border: #232936;
|
||||
--text: #e6e9ef; --fade: #8b93a7; --accent: #7aa2ff;
|
||||
--reflection: #5ad1a0; --metacognition: #c08bff; --journal: #ffcf6b;
|
||||
}
|
||||
* { box-sizing: border-box; }
|
||||
html, body {
|
||||
margin: 0; min-height: 100%; background: var(--bg); color: var(--text);
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
||||
-webkit-text-size-adjust: 100%;
|
||||
}
|
||||
header {
|
||||
position: sticky; top: 0; z-index: 10; background: var(--bg-elev);
|
||||
border-bottom: 1px solid var(--border); padding: env(safe-area-inset-top) 14px 0;
|
||||
}
|
||||
.topbar { display: flex; align-items: center; gap: 10px; padding: 13px 0 10px; flex-wrap: wrap; }
|
||||
.topbar h1 { font-size: 1.05rem; margin: 0; font-weight: 600; }
|
||||
.topbar a.back { color: var(--accent); text-decoration: none; font-size: .95rem; }
|
||||
.count { margin-left: auto; color: var(--fade); font-size: .8rem; }
|
||||
.chips { display: flex; gap: 6px; flex-wrap: wrap; padding-bottom: 10px; }
|
||||
.chip {
|
||||
font-size: .8rem; padding: 6px 12px; border-radius: 999px;
|
||||
border: 1px solid var(--border); background: var(--bg-line); color: var(--fade);
|
||||
cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent;
|
||||
}
|
||||
.chip.active { color: var(--text); border-color: var(--accent); background: #1b2333; }
|
||||
|
||||
main { max-width: 720px; margin: 0 auto; padding: 14px 14px 48px; }
|
||||
.day { color: var(--fade); font-size: .8rem; text-transform: uppercase; letter-spacing: .5px;
|
||||
margin: 22px 0 8px; padding-bottom: 6px; border-bottom: 1px solid var(--bg-line); }
|
||||
.day:first-child { margin-top: 4px; }
|
||||
|
||||
.entry { display: flex; gap: 11px; padding: 10px 2px; }
|
||||
.rail { flex: none; width: 4px; border-radius: 3px; background: var(--fade); }
|
||||
.entry.k-reflection .rail { background: var(--reflection); }
|
||||
.entry.k-metacognition .rail { background: var(--metacognition); }
|
||||
.entry.k-journal .rail { background: var(--journal); }
|
||||
.body { flex: 1; }
|
||||
.meta { display: flex; gap: 8px; align-items: baseline; margin-bottom: 3px; flex-wrap: wrap; }
|
||||
.kind { font-size: .66rem; text-transform: uppercase; letter-spacing: .5px; font-weight: 700; }
|
||||
.entry.k-reflection .kind { color: var(--reflection); }
|
||||
.entry.k-metacognition .kind { color: var(--metacognition); }
|
||||
.entry.k-journal .kind { color: var(--journal); }
|
||||
.time { color: var(--fade); font-size: .72rem; }
|
||||
.src { color: var(--fade); font-size: .68rem; opacity: .7; }
|
||||
.text { font-size: .98rem; line-height: 1.55; }
|
||||
.empty { color: var(--fade); text-align: center; padding: 44px 16px; }
|
||||
.hidden { display: none !important; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<div class="topbar">
|
||||
<h1>📔 Lyra · Journal</h1>
|
||||
<a class="back" href="/self">← Mind</a>
|
||||
<a class="back" href="/">Chat</a>
|
||||
<span class="count" id="count"></span>
|
||||
</div>
|
||||
<div class="chips" id="chips">
|
||||
<span class="chip active" data-kind="all">all</span>
|
||||
<span class="chip active" data-kind="journal">journal</span>
|
||||
<span class="chip active" data-kind="reflection">reflections</span>
|
||||
<span class="chip active" data-kind="metacognition">metacognition</span>
|
||||
</div>
|
||||
</header>
|
||||
<main id="root"><p class="empty" id="boot">Opening her journal…</p></main>
|
||||
|
||||
<script>
|
||||
const root = document.getElementById('root');
|
||||
const countEl = document.getElementById('count');
|
||||
const active = new Set(['journal', 'reflection', 'metacognition']);
|
||||
let entries = [];
|
||||
|
||||
function esc(s){ const d=document.createElement('div'); d.textContent = s==null?'':String(s); return d.innerHTML; }
|
||||
function dayKey(iso){ return new Date(iso).toLocaleDateString([], {weekday:'long', month:'short', day:'numeric', year:'numeric'}); }
|
||||
function clockt(iso){ return new Date(iso).toLocaleTimeString([], {hour:'2-digit', minute:'2-digit'}); }
|
||||
|
||||
document.getElementById('chips').addEventListener('click', (e) => {
|
||||
const chip = e.target.closest('.chip'); if (!chip) return;
|
||||
const k = chip.dataset.kind;
|
||||
if (k === 'all') {
|
||||
const turnOn = !chip.classList.contains('active');
|
||||
document.querySelectorAll('.chip').forEach(c => c.classList.toggle('active', turnOn));
|
||||
active.clear(); if (turnOn) ['journal','reflection','metacognition'].forEach(x => active.add(x));
|
||||
} else {
|
||||
if (active.has(k)) { active.delete(k); chip.classList.remove('active'); }
|
||||
else { active.add(k); chip.classList.add('active'); }
|
||||
document.querySelector('.chip[data-kind="all"]').classList.toggle('active', active.size === 3);
|
||||
}
|
||||
render();
|
||||
});
|
||||
|
||||
function render(){
|
||||
const shown = entries.filter(e => active.has(e.kind));
|
||||
countEl.textContent = `${shown.length} entr${shown.length === 1 ? 'y' : 'ies'}`;
|
||||
if (!shown.length) { root.innerHTML = '<p class="empty">Nothing here yet. Her reflections and notes will collect as she thinks.</p>'; return; }
|
||||
let html = '', lastDay = null;
|
||||
for (const e of shown) {
|
||||
const d = dayKey(e.created_at);
|
||||
if (d !== lastDay) { html += `<div class="day">${esc(d)}</div>`; lastDay = d; }
|
||||
html += `<div class="entry k-${esc(e.kind)}">
|
||||
<div class="rail"></div>
|
||||
<div class="body">
|
||||
<div class="meta">
|
||||
<span class="kind">${esc(e.kind)}</span>
|
||||
<span class="time">${esc(clockt(e.created_at))}</span>
|
||||
${e.source ? `<span class="src">via ${esc(e.source)}</span>` : ''}
|
||||
</div>
|
||||
<div class="text">${esc(e.content)}</div>
|
||||
</div>
|
||||
</div>`;
|
||||
}
|
||||
root.innerHTML = html;
|
||||
}
|
||||
|
||||
async function load(){
|
||||
try {
|
||||
const r = await fetch('/journal/data', { cache: 'no-store' });
|
||||
entries = (await r.json()).entries || [];
|
||||
render();
|
||||
} catch (e) {
|
||||
root.innerHTML = '<p class="empty">Couldn\'t open her journal. Is the server up?</p>';
|
||||
}
|
||||
}
|
||||
load();
|
||||
setInterval(load, 20000);
|
||||
document.addEventListener('visibilitychange', () => { if (!document.hidden) load(); });
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -70,6 +70,7 @@
|
||||
<span class="dot" id="dot"></span>
|
||||
<h1>🧠 Lyra · Mind</h1>
|
||||
<a class="back" href="/">← Chat</a>
|
||||
<a class="back" href="/journal" title="Her permanent journal">📔 Journal</a>
|
||||
<a class="back" href="/logs" target="_blank" rel="noopener" title="Watch the live log">logs ↗</a>
|
||||
<button id="reflectBtn" title="Make her reflect now (draft → self-critique → revise). Watch it in /logs.">↻ Reflect now</button>
|
||||
<span class="updated" id="updated">—</span>
|
||||
|
||||
Reference in New Issue
Block a user