brain

package
v0.13.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 22 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

func EndpointID(homeID string) string

EndpointID is the registry id of a home's brain. It is stable, so a restarted brain replaces its own entry.

func Run

func Run(ctx context.Context, o Options) error

Run starts a brain and serves until ctx ends.

Types

type Brain

type Brain struct {
	// contains filtered or unexported fields
}

Brain is one home's running brain.

func Start

func Start(o Options) (b *Brain, err error)

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

func (b *Brain) OnDecision(d route.Decision)

OnDecision queues a routed thread's footer write. It never blocks.

func (*Brain) OnSnapshot

func (b *Brain) OnSnapshot(s route.Snapshot)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL