agent

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: MIT Imports: 12 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 agent describes the coding agents Flockdeck can run in a pane.

A pane is either a shell or an agent, and an agent is a Spec -- a program to run, or an API to talk to -- together with the model it was asked for. Every Claude-specific decision Flockdeck once made in line is a field here, so that a second agent is a table entry rather than another branch.

Index

Constants

View Source
const ConfigName = "agents.json"

ConfigName is the file, in Flockdeck's state directory, where the user's own agents and defaults live. It is read fresh every time the catalog is asked for, so editing it by hand takes effect without a restart.

View Source
const ConfigVersion = 1

ConfigVersion is the schema version written into that file. Nothing rejects a file for its version: an agent list is additive, and refusing to start with somebody's agents because a newer build wrote a 2 into it would be a poor trade for a field nothing reads.

View Source
const DefaultAgentID = "claude"

DefaultAgentID is the agent a pane gets when nothing -- not the pane, not the project, not the user's defaults -- has said which one it wants. It is Claude because that is what every pane was before agents were a choice, and a saved layout from that build has to come back exactly as it went away.

View Source
const KeysName = "keys.json"

KeysName is the file internal/creds keeps API keys in. It is named here only so that availability can ask whether one is set before creds exists.

Variables

View Source
var KeyProbe = keyIsSet

KeyProbe reports whether an API agent has a key available. It is a variable because key resolution belongs to internal/creds, which imports this package for Spec and so cannot be imported back from it; creds installs its own from an init if it wants to. The default below asks the same two questions creds does -- the environment, then the key store -- but only ever asks whether there is a key, never what it is.

Functions

func Available

func Available(s Spec) bool

Available reports whether a spec can be started here, remembering the answer for probeTTL.

func BuildArgv

func BuildArgv(s Spec, resume bool, t Tokens) []string

BuildArgv turns a Spec into the argv for one pane. The first element is the program; resolving it on PATH is the caller's job.

An argument that is exactly "{{prompt}}" and expands to something beginning with a dash is preceded by "--", because the opening task is free to begin with one -- "-p is not what I meant, use ..." -- and without it the CLI reads the task as an option it does not have and the pane dies on the spot.

func ConfigPath

func ConfigPath() (string, error)

ConfigPath returns where agents.json lives.

func NeedsNoKey

func NeedsNoKey(s Spec) bool

NeedsNoKey reports whether an endpoint can be talked to without one. A model server on this machine -- Ollama, LM Studio, vLLM -- almost never asks for a key, and refusing to offer it until somebody invents one to store would be obtuse.

func ProbeAll

func ProbeAll(specs []Spec) map[string]bool

ProbeAll returns availability for a whole catalog, keyed by id, which is what the picker and the startup probe both want.

func Refresh

func Refresh()

Refresh forgets what was probed, so the next look is a fresh one. The picker opening is the moment worth spending that on: it is where somebody who has just installed an agent goes to find it.

func SetDefaults

func SetDefaults(dir, project string, d Defaults) error

SetDefaults records the agent and model to use where nothing else says. An empty project sets them for the whole installation; a project path sets them for that project alone, which is the picker's "set as default for this project".

func WriteConfig

func WriteConfig(dir string, f *File) error

WriteConfig replaces agents.json in a directory.

The write is atomic, because this file is the user's own: a half-written one left behind by an interrupted save would lose every agent they had defined, and would do it at the moment Flockdeck was closing rather than somewhere they could see it happen.

Types

type APISpec

type APISpec struct {
	// Wire is the request shape: "anthropic", "openai" or "gemini". An
	// OpenAI-compatible endpoint -- Ollama, LM Studio, vLLM, a gateway -- is
	// "openai" with a BaseURL of its own.
	Wire string `json:"wire,omitempty"`
	// BaseURL is the endpoint root; empty means the vendor's own.
	BaseURL string `json:"baseURL,omitempty"`
	// KeyEnv names the environment variables a key may arrive in, tried in
	// order before Flockdeck's own key store.
	KeyEnv []string `json:"keyEnv,omitempty"`
}

APISpec describes an HTTP model API for the built-in chat client.

type Arg

type Arg struct {
	// Value is one argument, with tokens expanded. Empty when Args is set.
	Value string `json:"value,omitempty"`
	// If names a token; the group is used only when that token has a value.
	If string `json:"if,omitempty"`
	// Args is the group.
	Args []Arg `json:"args,omitempty"`
}

Arg is one entry in a Spec's argument list: a literal, or a group used only when a token has a value.

The group is what keeps an option with its value: dropping "{{model}}" alone from ["--model", "{{model}}"] would leave the flag behind to swallow the next argument as its value.

func Group

func Group(token string, values ...string) Arg

func Lit

func Lit(v string) Arg

Lit is one literal argument, and Group a set of them used only when a token has a value. They are shorthand for writing a catalog by hand.

type Caps

type Caps struct {
	// Hooks reports lifecycle events to Flockdeck, so the pane's status is known
	// rather than inferred from what it prints.
	Hooks bool `json:"hooks,omitempty"`
	// Resume reattaches a conversation by id, which is what makes restoring a
	// layout more than cosmetic.
	Resume bool `json:"resume,omitempty"`
	// Transcript records what was said somewhere Flockdeck can read it: where a
	// fan-out finds a plan, and the history overlay finds a conversation.
	Transcript bool `json:"transcript,omitempty"`
	// Trust has a per-directory trust question Flockdeck can answer ahead of a
	// fan-out, so that twelve fresh worktrees do not each stop on it.
	Trust bool `json:"trust,omitempty"`
	// Context is how the pane briefing reaches the agent.
	Context ContextMode `json:"context,omitempty"`
}

Caps says which of Flockdeck's facilities an agent supports. Everything Flockdeck does beyond drawing a terminal is gated on one of these, so an agent that supports none of it still works -- it is a terminal with a program in it.

type Catalog

type Catalog struct {
	// Specs are every agent, in picker order and including hidden ones.
	Specs []Spec
	// Defaults apply where a project has nothing to say.
	Defaults Defaults
	// Projects are the per-project defaults, keyed as the user wrote them.
	Projects map[string]Defaults
	// Notice is empty unless the user's file could not be used in full. It is
	// something for the interface to show, never a reason not to start: a
	// mistyped agents.json leaves somebody with the built-in agents, not with
	// an application that will not open.
	Notice string
}

Catalog is the agents this run can offer: the built-ins with the user's agents.json merged over them, together with the defaults from that file.

func Load

func Load() *Catalog

Load reads the catalog from Flockdeck's state directory.

It never fails. Where the state directory itself cannot be found there is nowhere for an agents.json to be, and the built-ins are the whole answer.

func LoadFrom

func LoadFrom(dir string) *Catalog

LoadFrom reads the catalog from a named directory, which is what the tests use and what a future --state-dir would use.

func Merge

func Merge(f *File) *Catalog

Merge overlays a parsed agents.json on the built-in catalog.

A user entry whose id is a built-in's is merged field by field over it: a field the user set wins, a field they left out keeps the built-in's answer. That is why the entries arrive as raw JSON -- it is the only way left, by then, to tell "" the user wrote from "" the decoder filled in.

func (*Catalog) DefaultsFor

func (c *Catalog) DefaultsFor(project string) Defaults

DefaultsFor returns the agent and model a project starts panes with: its own entry where it has one, otherwise the installation's.

func (*Catalog) Find

func (c *Catalog) Find(id string) (Spec, bool)

Find returns the spec with an id.

func (*Catalog) Resolve

func (c *Catalog) Resolve(project, agentID, model string) (Spec, string, bool)

Resolve answers what a new pane should start: the spec and the model id.

Both arguments are what the pane asked for and may be empty, which is the ordinary case -- splitting with the default agent is one keystroke and asks for nothing. A restored pane is not resolved this way: it recorded its agent and model when it was created, and Find is what gives those back to it, because a default changed since then must not quietly move a conversation onto another model.

The last return is false only when the catalog holds no usable agent at all, which takes a user file that hides every built-in.

func (*Catalog) StripEnv

func (c *Catalog) StripEnv() []string

StripEnv is every variable any agent in the catalog wants taken out of a pane's environment, in the order the entries give them and without duplicates.

It is the union rather than the chosen agent's own list because the markers each of these tools leaves behind say "you are running inside me", and a Codex pane opened from inside a Claude session is no more a child of it than a Claude pane is. A pane is a clean top-level session whatever is running in it.

func (*Catalog) Visible

func (c *Catalog) Visible() []Spec

Visible returns the agents the picker offers, which is everything not hidden. Unavailable agents are still here: somebody who has not installed Codex should still learn that Flockdeck would run it.

type ContextMode

type ContextMode string

ContextMode is how a pane's briefing -- which pane it is, who else is working -- reaches the agent running in it.

const (
	// ContextHook answers the agent's own session-start hook with the
	// briefing, which is the only way it survives a compaction.
	ContextHook ContextMode = "hook"
	// ContextPrompt puts the briefing in front of the opening prompt, for an
	// agent with no hooks to answer.
	ContextPrompt ContextMode = "prompt"
	// ContextNone leaves the agent unbriefed.
	ContextNone ContextMode = "none"
)

type Defaults

type Defaults struct {
	Agent string `json:"agent,omitempty"`
	Model string `json:"model,omitempty"`
}

Defaults are the agent and model chosen when a pane asks for neither: once for the whole installation, and once per project for somebody who works in two repositories that want different agents.

type File

type File struct {
	Version  int                 `json:"version"`
	Defaults Defaults            `json:"defaults,omitempty"`
	Projects map[string]Defaults `json:"projects,omitempty"`
	Agents   []json.RawMessage   `json:"agents,omitempty"`
	// Extra is every other top-level key the file held. It is kept so that
	// writing a default back from the picker cannot quietly delete something a
	// later build, or the user, put there.
	Extra map[string]json.RawMessage `json:"-"`
}

File is agents.json as it is written on disk.

The agents are kept as the raw JSON they were written as, rather than as Specs, because merging them over the built-ins has to tell a field the user set from a field they left out -- and once decoded into a struct the two look exactly alike.

func ReadConfig

func ReadConfig(dir string) (*File, error)

ReadConfig reads agents.json from a directory. A file that is not there is not an error -- it is the ordinary case, and means nothing but the built-ins.

func (File) MarshalJSON

func (f File) MarshalJSON() ([]byte, error)

func (*File) UnmarshalJSON

func (f *File) UnmarshalJSON(data []byte) error

type Model

type Model struct {
	ID   string `json:"id"`             // what the CLI or the API is given
	Name string `json:"name,omitempty"` // what the picker shows
	Note string `json:"note,omitempty"` // a few words on when to reach for it
}

Model is one model a Spec can be asked for.

type Patterns

type Patterns struct {
	// Waiting matches a line that means the agent is blocked on the user: a
	// permission question, a confirmation, an editor prompt.
	Waiting []string `json:"waiting,omitempty"`
	// Idle matches a line that means it has finished and is at its prompt.
	Idle []string `json:"idle,omitempty"`
}

Patterns recognise, in what an agent prints, the two states its own lifecycle would have reported. They are used only when Caps.Hooks is false.

type Runner

type Runner string

Runner is how a Spec is started.

const (
	// RunnerCLI runs an external command in the pane's pseudo-terminal.
	RunnerCLI Runner = "cli"
	// RunnerAPI runs Flockdeck's own chat client in the pane, talking directly to
	// a model API. The command is `flockdeck chat`; the Spec says which endpoint.
	RunnerAPI Runner = "api"
)

type Spec

type Spec struct {
	ID     string `json:"id"`
	Name   string `json:"name"`
	Runner Runner `json:"runner,omitempty"`
	// Exe is the command to look for on PATH, for a CLI runner.
	Exe string `json:"exe,omitempty"`
	// Args is the argument list; ResumeArgs replaces it when a conversation is
	// being reattached rather than started.
	Args       []Arg `json:"args,omitempty"`
	ResumeArgs []Arg `json:"resumeArgs,omitempty"`
	// Models are what the picker offers. DefaultModel is taken when nothing is
	// chosen; empty leaves the choice to the agent, which is how a CLI keeps
	// whatever it was configured with.
	Models       []Model `json:"models,omitempty"`
	DefaultModel string  `json:"defaultModel,omitempty"`
	// Env is added to the pane's environment; StripEnv is removed from it,
	// which is how the markers of the session Flockdeck was launched from are kept
	// from making every pane look like a nested child of it.
	Env      []string `json:"env,omitempty"`
	StripEnv []string `json:"stripEnv,omitempty"`
	API      APISpec  `json:"api,omitempty"`
	Caps     Caps     `json:"caps,omitempty"`
	Patterns Patterns `json:"patterns,omitempty"`
	// Install is what to tell somebody who picked an agent their machine does
	// not have.
	Install string `json:"install,omitempty"`
	// NoDashDash suppresses the "--" that otherwise guards an opening prompt
	// beginning with a dash.
	NoDashDash bool `json:"noDashDash,omitempty"`
	// Hidden keeps a built-in out of the picker without removing it.
	Hidden bool `json:"hidden,omitempty"`
}

Spec is one agent Flockdeck can run.

func Builtins

func Builtins() []Spec

Builtins returns a fresh copy of the built-in specs, in the order the picker shows them: Claude first because it is the default, then the other command-line agents, then the API runners that need no CLI at all.

The copy is fresh on every call because the catalog merges the user's file over these entries in place, and a shared slice would carry one run's agents.json into the next read of the built-ins.

type Tokens

type Tokens struct {
	Session  string // the pane id, which is also the conversation id
	Model    string
	Settings string // a generated settings file, for an agent that takes one
	Prompt   string // the opening task; empty when there is none
	Cwd      string
	Pane     string
}

Tokens are the values an argument list may refer to. A token with no value removes the group it appears in.

func (Tokens) Expand

func (t Tokens) Expand(s string) string

Expand replaces every {{token}} in s with its value.

func (Tokens) Value

func (t Tokens) Value(name string) string

Value returns the token named by an `if`, or by "{{name}}".

Jump to

Keyboard shortcuts

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