cliagent

package
v0.7.53 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 27 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 cliagent runs agent turns through a coding-agent CLI (Claude Code, Codex, or any CLI provider definition that resumes its sessions) instead of a model API. The CLI owns the agent loop; Aviary exposes its tools to the CLI over MCP and receives the CLI's JSON event stream as backend-neutral events.

Index

Constants

View Source
const MCPServerName = "aviary"

MCPServerName is the name Aviary's MCP server is registered under in the CLI's MCP configuration. Tool calls against it are reported by Aviary's MCP boundary rather than mapped from the CLI's event stream.

View Source
const MCPToolTimeout = 30 * time.Minute

MCPToolTimeout is how long a CLI waits on one call to Aviary's MCP server. The CLIs give up on a tool call after 60 seconds by default, while tools such as project_issue_create run a whole gh-create (issue #710), so it covers the longest tool rather than the CLI's default.

View Source
const ModelPrefix = "cli/"

ModelPrefix is the provider prefix that selects a CLI backend in a model string such as "cli/claude/opus". A backend's own name selects it too, as in "claude/opus": each CLI is a provider in its own right.

Variables

This section is empty.

Functions

func ChatBackends added in v0.7.1

func ChatBackends(registry *clidefs.Registry) []string

ChatBackends lists, in sorted order, the providers in registry that can back a chat: those whose CLI resumes its own sessions.

func IsCLIModel

func IsCLIModel(model string) bool

IsCLIModel reports whether model selects a CLI backend, either as "cli/<backend>/<model>" or as "<backend>/<model>" for a backend in the CLI provider registry in force.

func RunCommandHook

func RunCommandHook(in io.Reader, out io.Writer, getenv func(string) string) error

RunCommandHook answers one Claude Code PreToolUse hook call read from in, with getenv supplying the hook's configuration. It writes a deny decision naming the responsible rule when the agent's Allowed Exec Commands refuse the command, as Aviary's own exec tool would, and nothing otherwise, which leaves the call to Claude's own permission check. A call it cannot check is refused rather than left to run.

Types

type Backend

type Backend string

Backend names the CLI provider definition a session runs through. Any definition in the CLI provider registry whose CLI resumes its own sessions can back a chat; claude and codex additionally get backends of their own that keep Aviary's MCP tools and system prompt in the CLI's native form.

const (
	Claude Backend = "claude"
	Codex  Backend = "codex"
)

Backends with their own session implementations.

func ParseModel

func ParseModel(model string) (Backend, string, error)

ParseModel splits "cli/<backend>/<model>" or "<backend>/<model>" into its backend and the model name passed to that CLI, resolving the backend in the CLI provider registry in force.

func ParseModelIn added in v0.7.1

func ParseModelIn(registry *clidefs.Registry, model string) (Backend, string, error)

ParseModelIn is ParseModel against an explicit registry, for config validation, which checks definitions before they are installed.

func (Backend) Binary

func (b Backend) Binary() string

Binary returns the executable the backend's definition runs.

func (Backend) Definition added in v0.7.1

func (b Backend) Definition() (clidefs.Definition, bool)

Definition returns b's CLI provider definition from the registry in force.

func (Backend) ServesAviaryTools added in v0.7.1

func (b Backend) ServesAviaryTools() bool

ServesAviaryTools reports whether the backend's CLI is pointed at Aviary's MCP server: claude and codex always are, and a CLI driven through its definition is when the definition's mcp block says how. One that declares none runs on its own tools alone.

func (Backend) Valid

func (b Backend) Valid() bool

Valid reports whether b names a provider in the CLI provider registry in force that can back a chat.

type CommandHook

type CommandHook struct {
	// Executable is the aviary binary that answers the hook.
	Executable string
	// Agent names the agent whose rules these are, for the refusal.
	Agent string
	// Rules are the agent's ordered Allowed Exec Commands, as written.
	Rules []string
}

CommandHook has Claude Code check every call to its shell tools against an agent's Allowed Exec Commands before running it, through a PreToolUse hook that runs Executable's "cli-hook" command. Claude's dontAsk mode still runs commands it classifies as read-only, such as "echo hi", with no allow rule covering them, so its own allow rules alone cannot narrow the shell to the agent's rules (#595).

type Event

type Event struct {
	Type      EventType
	Text      string
	SessionID string
	Tool      *ToolEvent
	Usage     *Usage
}

Event is a single event from a CLI turn.

type EventType

type EventType string

EventType identifies a backend-neutral CLI event.

const (
	// EventText carries a chunk of assistant text.
	EventText EventType = "text"
	// EventToolStart reports that the CLI started one of its own tools.
	EventToolStart EventType = "tool_start"
	// EventToolResult reports the result of one of the CLI's own tools.
	EventToolResult EventType = "tool_result"
	// EventSession reports the CLI-native session ID.
	EventSession EventType = "session"
	// EventUsage reports token usage and cost for the turn.
	EventUsage EventType = "usage"
)

EventType values.

type Options

type Options struct {
	Backend      Backend
	Model        string
	SystemPrompt string
	WorkDir      string
	// MCPURL and MCPToken point the CLI at Aviary's scoped MCP endpoint.
	// When MCPURL is empty the CLI gets no MCP servers at all.
	MCPURL   string
	MCPToken string
	// BuiltinTools enables the CLI's own shell, file-edit and web tools.
	// When false they are turned off and only Aviary's MCP tools remain.
	BuiltinTools bool
	// Approval are the CLI's native permission flags for the surface's
	// approval mode, as its CLI provider definition translates it. They are
	// always passed, so the user's own CLI settings never pick the mode.
	Approval []string
	// ExtraDir are the CLI's native arguments that add the agent's own
	// directory to the session's workspace scope beside WorkDir, as its CLI
	// provider definition declares them. They widen which directories are in
	// scope, never what the approval mode allows there.
	ExtraDir []string
	// Permissions are the CLI's native allow and deny arguments carrying the
	// agent's exec and filesystem rules, as its CLI provider definition
	// translates them for the approval mode.
	Permissions []string
	// RefusalNote, when set, is added to a CLI tool's error when the CLI's
	// own permission check refused the call, naming that layer.
	RefusalNote string
	// CommandHook, when set with BuiltinTools, has the CLI check each of its
	// shell tool calls against the agent's Allowed Exec Commands. Only
	// claude honors it.
	CommandHook *CommandHook
	// ResumeID is the CLI-native session ID to resume. Empty starts a new
	// session; the new ID is reported with an EventSession event.
	ResumeID string
	// NewSessionID, when set, is the ID Aviary assigns a new session, for a
	// definition whose session.assign is "aviary".
	NewSessionID string
	// Ephemeral runs without persisting the CLI session, so it cannot be
	// resumed later.
	Ephemeral bool
	// Binary overrides the executable path (tests).
	Binary string
	// Env is appended to the CLI's environment.
	Env []string
}

Options configures a CLI session. Options are fixed for the life of a session; changing any of them requires a new session.

type Result

type Result struct {
	// Text is the final assistant message.
	Text string
}

Result is the outcome of a completed turn.

type Session

type Session interface {
	// Send runs one turn. onEvent is called synchronously for every event.
	// Send returns once the CLI finishes the turn. Turns must not overlap.
	Send(ctx context.Context, turn Turn, onEvent func(Event)) (Result, error)
	// Close stops any process the session holds.
	Close() error
}

Session runs turns against one CLI conversation.

func NewSession

func NewSession(opts Options) (Session, error)

NewSession creates a session for opts.Backend. No process is started until the first Send.

type ToolEvent

type ToolEvent struct {
	ID     string
	Name   string
	Args   map[string]any
	Result string
	Error  string
}

ToolEvent describes a CLI built-in tool invocation.

type Turn

type Turn struct {
	Text string
	// MediaURLs are images attached to the message, as data URLs or remote
	// URLs.
	MediaURLs []string
}

Turn is one user message handed to the CLI.

type Usage

type Usage struct {
	InputTokens      int
	OutputTokens     int
	CacheReadTokens  int
	CacheWriteTokens int
	CostUSD          float64
}

Usage holds token counts and cost reported by the CLI.

Jump to

Keyboard shortcuts

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