# SPEC-EVENTS — session event registry & hash-chaining Every session appends to a local, hash-chained, append-only JSONL log: `.freestream/sessions//events.jsonl`. A session is therefore a **verifiable artifact**: tamper with any line and `verify()` fails. ## Chain format One JSON object per line: ```json {"seq": 3, "ts": 1759600000.123, "type": "session.status", "payload": {"status": "ready"}, "prev": "<64-hex sha256 of entry 2>", "hash": "<64-hex>"} ``` - `hash = sha256(canonical({"seq","ts","type","payload","prev"}))` where canonical = `json.dumps(sort_keys=True, separators=(",",":"))`. - First entry's `prev` is the 64-zero genesis hash. - `EventLog(path).verify() -> (ok, first_bad_seq)`; appending to a broken chain raises instead of extending a lie. ## Registry Types are namespaced. The initial registry: | Type | Emitted by | Payload | |---|---|---| | `session.requested` | CLI join | platform, driver, bot_name, voice, rung, meet_url | | `session.created` | CLI join | session_id, driver | | `session.status` | driver poll | status | | `session.ready` | CLI join | session_id | | `session.failed` | CLI join | status | | `session.timeout` | CLI join | — | | `driver.join_attempted` | driver | driver, platform | | `persona.rung_change` | avatar backend | from, to, reason | | `asr.partial` / `asr.final` | ASR loop | text, speaker, confidence | | `agent.speak` | MCP session.speak / bot | text | | `agent.action` | CharacterAgent | text — in-fiction physical actions, never spoken | | `agent.tool` | toolbelt | tool, args, ok, output — every terminal/file call, audited | | `asr.speculative` | speculative dispatch | text, seconds, audio_s — dispatched at ~300ms of silence | | `agent.speculative_canceled` | speculative turn | reason: speech_resumed (before playout) | | `turn.completed` | bot | total_s, asr_s, speculative, throttled_periods, throttled_ms | | `tts.synthesized` | persona | text, chars, backend | | `avatar.frame_clock` | avatar backend | fps, rung | | `persona.posture` | bot render loop | mode — idle/thinking/working/speaking on change | | `session.leave` | CLI leave | session_id | Rules: 1. Additions to the registry append; never repurpose or delete a type. 2. Payloads contain no raw audio or image bytes — references only (durations, paths, hashes of the bytes). 3. `asr.partial` entries are prunable: a compaction pass may drop them and re-issue a `log.compacted` entry, but the chain never breaks. 4. Logs are the replay input: a session log + the persona assets is a full deterministic replay of what the bot said and when.