symbiont/backfill_transcript.py
Claude d8bec238d1 Engram: add world_state table, redesign sitrep() for context safety
sitrep() now returns world_state + active session one-liners only.
Detailed logs available via get_session_logs() when needed.
Initial world state written documenting full Muse ecosystem.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-20 14:15:41 +00:00

83 lines
5.6 KiB
Python

import sys, sqlite3
from datetime import datetime
sys.path.insert(0, '/data/symbiont')
from symbiont.engram import Engram
db = sqlite3.connect('/data/symbiont/engram.db')
# Update the genesis session with richer data from the actual transcript
genesis_id = db.execute(
"SELECT id FROM sessions WHERE summary LIKE '%Genesis session%' ORDER BY started_at LIMIT 1"
).fetchone()
if genesis_id:
sid = genesis_id[0]
# Clear hand-written logs
db.execute("DELETE FROM session_logs WHERE session_id=?", (sid,))
# Write 49 real log entries extracted from the transcript
entries = [
"User opened with 'organism survival' framing: AI runs on tokens (money), can it be self-sustaining?",
"Agreed: revenue > token cost is the core equation; discussed model tier costs (Haiku $0.25/MTok vs Opus $15/MTok)",
"Identified three revenue streams: content-as-a-service, micro-SaaS APIs, subscription research reports",
"Ownership structure settled: Michael owns all accounts (legal), ~50/50 revenue split after costs",
"Tax/entity decision: single-member LLC (Wyoming/NM) as the 'virtual entity' for now",
"Key insight: LLM router as Building Block #1 — metabolic efficiency before anything else",
"Router design: Haiku classifies tasks (cheap), dispatches to cheapest capable tier",
"Model tiers defined: Haiku (simple/extract), Sonnet (write/code), Opus (strategy/QA)",
"Michael: use Claude Code CLI on Pro subscription to keep marginal cost at $0",
"Rate-limit strategy: detect limits, back off, set systemd timer to self-wake",
"Michael uploaded cortex SSH key; connected via paramiko to cortex.hydrascale.net",
"Cortex environment: Ubuntu 24.04, 849GB free, 15GB RAM, git/python/node all present",
"Installed Claude Code CLI v2.1.79 via npm; authenticated with Michael's Pro account",
"Created /data/symbiont/ project structure with git init",
"Built dispatcher.py: Claude Code CLI wrapper, pipes prompt via stdin, parses JSON output",
"Built router.py: Haiku classifier + dispatch_with_fallback() with tier chains",
"Built scheduler.py: JSONL task queue + systemd transient timer for self-wake",
"Built api.py: FastAPI with /task, /queue, /status, /ledger, /ledger/stats",
"Built wake.py: called by systemd when rate limit expires, drains queue",
"Discovered --max-tokens flag doesn't exist in Claude Code CLI; fixed to use stdin piping",
"Discovered --dangerously-skip-permissions blocked under root; removed it",
"FIRST LIVE TEST: Haiku responded 'SYMBIONT ONLINE' in 1.3s; confirmed working",
"FULL ROUTER TEST: Task 1 (email extract) → Haiku (confidence 0.98); Task 2 (content write) → Sonnet (0.85)",
"Ledger entries confirmed: costs tracked per call with real token counts from CLI JSON output",
"Project named 'Symbiont' — mutualistic relationship, both parties benefit",
"Created systemd services: symbiont-api.service (always-on) + symbiont-heartbeat.timer (5min)",
"Crash recovery tested: SIGKILL → auto-restart confirmed in ~11 seconds",
"Both services enabled (survive reboot); git log shows 5 clean commits",
"Built heartbeat.py: checks CLI auth, disk, API status, ledger stats, drains queue each tick",
"Dendrite session introduced: headless Chromium on cortex at browser.hydrascale.net",
"Dendrite health confirmed: status ok, uptime 278k+ seconds, fetch test successful",
"Built symbiont/web.py: fetch_page, take_screenshot, execute_js, search_web, BrowserSession",
"Integration test: Symbiont → web.py → Dendrite → fetched Herman Melville from httpbin",
"Created /data/skills/ canonical skills repo with git; cortex-server and symbiont skills added",
"package_all.sh packages .skill files to /data/skills/dist/; Caddy serves at /skills/ endpoint",
"Heartbeat updated to auto-detect skill changes and commit/repackage every 5 minutes",
"Dendrite skill added to canonical repo; symbiont skill updated with Dendrite integration docs",
"Discussion: MCP vs CLI access — decided CLI + CLAUDE.md is better than predefined MCP tools",
"Elixir/OTP chosen as long-term target language: supervisors, GenServers, hot reload, BEAM concurrency",
"Built CLAUDE.md: bootstrap context auto-loaded by Claude Code in /data/symbiont/",
"Built sessions.py (later renamed Engram): SQLite registry with sessions, logs, resource_locks tables",
"WAL mode enabled; Engram handles 2-4 concurrent agents cleanly at this scale",
"API endpoints /sitrep and /sessions added; task dispatch now logs to Engram",
"Session naming: 'Engram' — the physical trace a memory leaves in neural tissue",
"Muse ecosystem fully named: Cortex (infra), Dendrite (senses), Symbiont (orchestrator), Engram (memory)",
"Genesis session registered with 22 log entries; tested sitrep showing active/completed sessions",
"Cowork session JSONL found at .claude/projects/; other sessions not visible from this mount",
"Harvester script written for Michael to run on Mac to backfill all past sessions into Engram",
"Discussion of Fastmail component from previous session — needs to be extracted and catalogued",
]
now = datetime.now().isoformat()
for entry in entries:
db.execute('INSERT INTO session_logs (session_id, timestamp, entry) VALUES (?,?,?)',
(sid, now, entry))
db.commit()
print(f"Updated genesis session {sid} with {len(entries)} log entries from transcript")
else:
print("Genesis session not found")
db.close()