agent

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package agent consolidates program-specific knowledge for the supported coding agents (claude, aider, gemini, etc.).

Before this package, per-agent logic was scattered: recovery flag assembly in session/agent_restart.go, trust-prompt strings in session/tmux/tmux.go, and "is this a known program?" checks inline at call sites. Adapter consolidates those so that adding a new agent is a one-file change.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

type Adapter interface {
	// Name returns a stable short identifier (e.g. "claude").
	Name() string
	// Matches reports whether the given program command string is this
	// adapter's agent. Typically checks the basename of the first
	// whitespace-separated token.
	Matches(program string) bool
	// TrustPromptPatterns returns substrings that identify a trust
	// prompt for this agent. If any pattern is present in the pane
	// content, TrustPromptResponse() tells us how to respond.
	TrustPromptPatterns() []string
	// TrustPromptResponse tells us how to dismiss the trust prompt when
	// one is detected.
	TrustPromptResponse() TrustPromptAction
	// PendingPromptPattern returns the substring that indicates the
	// agent is blocked waiting for the user to answer a prompt. An
	// empty string disables auto-yes detection for this agent.
	PendingPromptPattern() string
	// ApplyRecoveryFlag returns the program string with recovery flags
	// appended (e.g. "claude --continue"). Idempotent: if the flag is
	// already present, the input is returned unchanged. Returns the
	// input unchanged if the adapter does not support recovery.
	ApplyRecoveryFlag(program string) string
	// ApplyRemoteControlFlag returns the program string with the agent's
	// remote-control flag appended (e.g. "claude --remote-control foo"),
	// using sessionName to name the remote session where the agent
	// supports naming. Idempotent: if a remote-control flag is already
	// present, the input is returned unchanged. Returns the input
	// unchanged for agents without a remote-control mode.
	ApplyRemoteControlFlag(program, sessionName string) string
	// ApplyPermissionModeFlag returns the program string with
	// "--permission-mode <mode>" inserted (e.g. "claude
	// --permission-mode acceptEdits"). mode == "" or "default" is a
	// no-op — Claude's own default already matches. Idempotent: if
	// --permission-mode is already present, the input is returned
	// unchanged. Returns the input unchanged for agents without a
	// permission-mode concept.
	ApplyPermissionModeFlag(program, mode string) string
	// ApplyModelFlag returns the program string with "--model <model>"
	// inserted (e.g. "claude --model opus"). model == "" or "default"
	// is a no-op — Claude's own default already matches. Idempotent: if
	// --model is already present, the input is returned unchanged.
	// Returns the input unchanged for agents without a model-selection
	// concept.
	ApplyModelFlag(program, model string) string
	// ApplyEffortFlag returns the program string with "--effort
	// <level>" inserted (e.g. "claude --effort high"). effort == "" or
	// "default" is a no-op — Claude's own default already matches.
	// Idempotent: if --effort is already present, the input is
	// returned unchanged. Returns the input unchanged for agents
	// without an effort-level concept.
	ApplyEffortFlag(program, effort string) string
}

Adapter describes a single supported agent's behavior: how to detect its prompts, how to dismiss them, and how to restart it.

The adapter is consulted from Instance and tmux code paths that previously inlined these strings. To add a new agent, implement this interface and register it in DefaultRegistry.

func Aider

func Aider() Adapter

Aider returns the adapter for the aider agent.

func Claude

func Claude() Adapter

Claude returns the adapter for the Claude Code agent.

func Default

func Default() Adapter

Default returns the fallback adapter used when no registered adapter matches. It disables agent-specific features (trust-prompt handling, auto-yes detection, recovery-flag insertion) and returns the program string unchanged.

func Gemini

func Gemini() Adapter

Gemini returns the adapter for the gemini agent.

type Registry

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

Registry is a prioritized list of adapters. Lookup returns the first Matches hit, or the fallback adapter if nothing matches. The fallback's Matches() is never consulted.

func DefaultRegistry

func DefaultRegistry() *Registry

DefaultRegistry returns the registry pre-populated with all built-in adapters and the fallback.

func NewRegistry

func NewRegistry(fallback Adapter, adapters ...Adapter) *Registry

NewRegistry builds a registry. fallback receives unknown programs and must implement Adapter with safe no-op behavior.

func (*Registry) Lookup

func (r *Registry) Lookup(program string) Adapter

Lookup returns the first adapter whose Matches() returns true, or the fallback.

type TrustPromptAction

type TrustPromptAction int

TrustPromptAction describes how to dismiss a trust/permission prompt. Each agent has its own expected response sequence.

const (
	// TrustPromptNone means no trust-prompt handling is needed.
	TrustPromptNone TrustPromptAction = iota
	// TrustPromptTapEnter responds with a single Enter keypress.
	TrustPromptTapEnter
	// TrustPromptTapDAndEnter responds with "d" followed by Enter — used by
	// agents that offer a "don't ask again" option on their trust screen.
	TrustPromptTapDAndEnter
)

Jump to

Keyboard shortcuts

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