Documentation
¶
Overview ¶
Package brain is conch's model-backed intelligence: it turns requests typed in the command bar into plans of conch actions, and summarises what agents are doing. The model sits behind a Provider, so Claude is the default but any backend can be plugged in.
Index ¶
Constants ¶
const ( ActStartTask = "start_task" // new branch + worktree + agent with a prompt ActStartAgent = "start_agent" // agent in an existing project/branch // ActStartTerminal is a shell in a project's checkout: asked for a // terminal, the brain once started an agent, having no other way. ActStartTerminal = "start_terminal" ActSend = "send" // type a message into a pane and press enter ActFocus = "focus" // show a pane ActClose = "close" // close a pane // ActShare hands one agent's conversation to another agent, new or // running; ActBroadcast sends one message to several agents at once. ActBroadcast = "broadcast" )
Action types.
const MaxRecent = 4
maxRecent is how many past requests the list offers.
Variables ¶
var ClaudeModels = []Model{ {ID: "opus", Label: "Opus (the newest)"}, {ID: "sonnet", Label: "Sonnet (the newest)"}, {ID: "haiku", Label: "Haiku (the newest)", Small: true}, {ID: "claude-fable-5-1", Label: "Claude Fable 5.1"}, {ID: "claude-opus-5-5", Label: "Claude Opus 5.5"}, {ID: "claude-sonnet-5-5", Label: "Claude Sonnet 5.5"}, {ID: "claude-haiku-5-5", Label: "Claude Haiku 5.5", Small: true}, }
ClaudeModels are what the Claude Code CLI takes for --model: its aliases, which follow the newest of each, then the models by name. The CLI has no way to list them, so this is the list; any other name still works, typed.
var ErrEmptyDiff = errors.New("there is nothing staged to write a message for")
ErrEmptyDiff is a request with nothing in it to describe.
var ErrNotConfigured = errors.New("brain not configured")
ErrNotConfigured means the provider lacks what it needs to run.
var Providers = []string{"claude", "anthropic", "openai"}
Providers lists the built-in provider names.
Functions ¶
func ProviderLabel ¶
ProviderLabel describes a provider for settings.
Types ¶
type Action ¶
type Action struct {
Type string `json:"type"`
Machine string `json:"machine,omitempty"`
Project string `json:"project,omitempty"` // project id
Branch string `json:"branch,omitempty"`
Base string `json:"base,omitempty"`
Agent string `json:"agent,omitempty"`
Prompt string `json:"prompt,omitempty"`
Pane string `json:"pane,omitempty"`
Text string `json:"text,omitempty"`
// ToPane is where a share goes when it continues in an agent that is
// already running; empty starts a new one.
ToPane string `json:"to_pane,omitempty"`
// Panes are a broadcast's recipients, all on Machine.
Panes []string `json:"panes,omitempty"`
}
Action is one step of a plan.
type AgentView ¶
type AgentView struct {
Agent string
State string
Title string
Branch string
Cwd string
Screen []string // visible terminal lines
}
AgentView is what the brain sees of one agent when summarising it.
type CommitMessage ¶ added in v0.1.9
CommitMessage is a subject and an optional body.
func WriteCommitMessage ¶ added in v0.1.9
func WriteCommitMessage(ctx context.Context, p Provider, diff, context string) (CommitMessage, error)
WriteCommitMessage asks the model for a message for diff. context, when not empty, is what the agent that made the change said it was doing.
func (CommitMessage) String ¶ added in v0.1.9
func (m CommitMessage) String() string
String is the message as git takes it: the subject, a blank line, the body.
type Counts ¶ added in v0.2.0
type Counts struct {
Agents int `json:"agents"`
Waiting int `json:"waiting"`
Working int `json:"working"`
Done int `json:"done"`
}
Counts are the agents on the world's online machines, by what they are doing.
func CountAgents ¶ added in v0.2.0
type Machine ¶
type Machine struct {
ID string `json:"id"`
Label string `json:"label"`
Online bool `json:"online"`
Agents []string `json:"installed_agents,omitempty"`
Projects []Project `json:"projects,omitempty"`
Panes []Pane `json:"panes,omitempty"`
}
Machine is a computer running a conch server.
func MachineFrom ¶
func MachineFrom(id, label string, online bool, agents []proto.AgentAvailability, projects []proto.ProjectInfo, panes []proto.PaneInfo, summaries map[string]string) Machine
MachineFrom describes a machine from its server's state. summaries maps pane ids to what the brain last said about them.
type Model ¶ added in v0.2.0
type Model struct {
ID string `json:"id"`
Label string `json:"label"`
// Small marks one suited to summaries: fast and cheap.
Small bool `json:"small,omitempty"`
}
Model is one model a provider offers, for Settings → Brain to list.
func Models ¶ added in v0.2.0
Models lists what the provider in cfg offers. The Claude Code CLI's are known; the Anthropic API and an OpenAI-compatible endpoint (Ollama, LM Studio, OpenAI) are asked. When asking fails the error says why, and the models returned are the ones known without asking, if any, so the list is never empty for want of a key.
type Pane ¶
type Pane struct {
ID string `json:"id"`
Name string `json:"name"`
Agent string `json:"agent,omitempty"`
State string `json:"state,omitempty"` // idle, working, blocked, done
Project string `json:"project,omitempty"`
Branch string `json:"branch,omitempty"`
Cwd string `json:"cwd"`
Summary string `json:"summary,omitempty"`
}
Pane is a terminal, possibly running an agent.
type Plan ¶
type Plan struct {
Reply string `json:"reply"`
Actions []Action `json:"actions"`
// Fast is a plan FastPlan made without the model.
Fast bool `json:"-"`
}
Plan is the brain's answer to a request: a reply for the user and the actions it proposes. Nothing runs until the user confirms.
func FastPlan ¶ added in v0.1.9
FastPlan answers the requests whose meaning is plain — show or close one pane, tell one agent or every agent something, what is waiting or working — from the world alone, without asking the model. A model call costs seconds (the Claude CLI starts a process for each), and these requests are most of what the bar is asked.
It answers only when there is exactly one reading: a name that matches two panes, or a pane and a project, or a message that talks about the agent in the third person ("check its tests") is left to the model, which can ask or rewrite it. A wrong fast answer costs a rejection and a second request — more than the model call it saved — so ok false is the default and every match has to earn its way out of it.
type Project ¶
type Project struct {
ID string `json:"id"`
Name string `json:"name"`
Path string `json:"path"`
Git bool `json:"git"`
Base string `json:"base,omitempty"`
Branches []string `json:"branches,omitempty"` // "name" or "name (worktree)"
}
Project is a repository or folder on a machine.
type Provider ¶
type Provider interface {
// Name identifies the provider, e.g. "claude".
Name() string
// Check reports why the provider can't be used (not installed, no key).
Check() error
Complete(ctx context.Context, req Request) (Response, error)
}
Provider is a model backend.
type Request ¶
type Request struct {
System string
Prompt string
Schema map[string]any
// Small asks for the provider's fast, cheap model (summaries).
Small bool
}
Request is one model call. With Schema set, the provider must return a JSON object matching it in Response.JSON.
type Response ¶
type Response struct {
Text string
JSON json.RawMessage
// CostUSD is what the call cost when the provider reports it.
CostUSD float64
}
Response is a model's answer.
type Suggestion ¶ added in v0.2.0
type Suggestion struct {
Text string `json:"text"` // the request, ending in "…" when it is to be finished
Note string `json:"note,omitempty"` // what it does or why it is offered
Recent bool `json:"recent,omitempty"`
}
Suggestion is one line of the list under an Ask request: something worth asking now, from what the agents are doing, or something asked before. A blank request box gave no hint of what conch can do. The TUI draws them, and `conch ask -suggest` hands them to the Mac app, so both offer the same things and say the same about what they cost.
func Matching ¶ added in v0.2.0
func Matching(opts []Suggestion, typed string) []Suggestion
Matching are the suggestions a typed request narrows the list to: those that contain it, other than the one it already is.
func Suggest ¶ added in v0.2.0
func Suggest(w World, here string, place, fast bool, history []string) []Suggestion
Suggest gives the suggestions for this moment, then the recent requests, newest first. here is the name of the agent selected, if one is; place says a project or branch is selected, which a vague "start an agent here" can rely on. fast is whether conch answers what it can without the model (no_fast_path turns it off), which decides what each one says it costs.
func (Suggestion) Fill ¶ added in v0.2.0
func (o Suggestion) Fill() bool
fill is an option that needs finishing — "tell codex to …" — and so is put in the box for the rest to be typed rather than asked as it is.
func (Suggestion) Stem ¶ added in v0.2.0
func (o Suggestion) Stem() string
stem is what an option puts in the request box.
type Summary ¶
type Summary struct {
Doing string `json:"doing"` // at most ~70 characters
Needs string `json:"needs"` // what the user must do; "" when nothing
}
Summary says what an agent is doing and what, if anything, it needs.
type World ¶
type World struct {
Machines []Machine `json:"machines"`
// Selected names what the user is looking at, e.g. "project api on
// local" — the default target for vague requests.
Selected string `json:"selected,omitempty"`
DefaultAgent string `json:"default_agent"`
}
World is what the brain knows when planning: every connected machine, its projects and panes, and what the user has selected.