Documentation
¶
Overview ¶
Package brain is the stage 2 router of one Codex home (plan decision M6). It runs the route engine for the home's edge over the link socket, serves control protocol v2 as a kind=brain endpoint in the registry, and follows the main threads of the home's shared Codex daemon: it resumes each one to get its notifications and cwd, mirrors routes into the Codex footers, and unsubscribes from threads whose TUI is gone so the daemon can unload them. A lost daemon connection is redialed, and every thread is resubscribed and its footer resynced.
A restarted brain starts with no learned state (plan M11). The user's intent (pauses, manual holds, pending pins) is kept in intent.json and reloaded; an unreadable file pauses the home and flags it as state lost. Each thread's mode override is kept in the mode store. Each resumed thread is seeded with the route Codex reports and held there until a reply measures its cache; so is a thread whose request, already deep in a conversation, arrives before its resume.
Index ¶
Constants ¶
const IdleAfter = 10 * time.Minute
IdleAfter is how long a followed thread may go without a turn, a settings event or a routed request before the brain takes its TUI for gone and unsubscribes, so the daemon can unload it. The daemon keeps a thread left by /new loaded for a long time, so the brain cannot wait for an unload.
Variables ¶
This section is empty.
Functions ¶
func EndpointID ¶
EndpointID is the registry id of a home's brain. It is stable, so a restarted brain replaces its own entry.
Types ¶
type Brain ¶
type Brain struct {
// contains filtered or unexported fields
}
Brain is one home's running brain.
func Start ¶
Start makes the home's state dir, serves control v2 and the link socket, registers the endpoint and starts following the daemon, which need not be up yet.
func (*Brain) Close ¶
func (b *Brain) Close()
Close stops the brain. The registry entry goes first, so panels stop listing it; then the link (the edge forwards unchanged), the daemon connection and the control socket.
func (*Brain) OnDecision ¶
OnDecision queues a routed thread's footer write. It never blocks.
func (*Brain) OnSnapshot ¶
OnSnapshot passes a thread's snapshot to the control socket.
type Options ¶
type Options struct {
Home home.Home
Version string
// Deps carry the engine's config, catalog, classifier, logger and clock.
// The brain overwrites Home, Sink, Cwd, HoldUnseeded and the intent
// fields (Intent, IntentLost, SaveIntent).
Deps route.Deps
// Getenv reads XDG_STATE_HOME and HOME (state dir and registry) and
// TMPDIR (short socket paths).
Getenv func(string) string
// Daemon is the daemon socket; empty means appserver.DaemonSocket of
// Home.Path.
Daemon string
// Dialer reaches the daemon; nil means appserver.WebSocket.
Dialer appserver.Dialer
// Models reloads the catalog Deps.Catalog reads when Codex rewrites the
// home's models cache; each decide checks it. Nil never reloads.
Models *catalog.CacheWatch
// Idle and Sweep override IdleAfter and the idle check's period; tests
// only.
Idle, Sweep time.Duration
}
Options configure a Brain.