The core runtime — manages API communication, tool execution, authentication,
and streaming for all SynapsCLI binaries (chat, chatui, server, agent, watcher).
Registry of available tools. Maintains a name→tool map and a cached JSON schema
array that gets sent to the API. Thread-safe via Arc<RwLock<ToolRegistry>>.
Re-export epoch_millis from agent-core (moved there for the leaf crate split).
Current time as Unix epoch milliseconds. Panics only if system clock is before 1970.
Find a session by its assigned name (not partial ID).
Iterates session headers one file at a time and returns on first match,
avoiding a full directory scan when the named session appears early.
The limit most-recently-modified sessions (by file mtime), most-recent
first. Sorts the directory entries by mtime WITHOUT parsing, then reads only
the top limit headers — so /sessions is O(limit) reads instead of
O(#sessions). mtime is an exact proxy for updated_at (the file is rewritten
on every save).
Reference-counted shared message payload. Introduced at the runtime’s
inner boundary (T128 Slice 2) to enable clone-free fan-out of message
history through the stream loop and SessionEvent::MessageHistory.
Outer state (App/Session/ConversationState) remains Vec<Value> and
shims at the boundary — see Slice 5 for full conversion.