code

package
v0.12.19 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2026 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AgentModeID      = "agent"
	PlanModeID       = "plan"
	UnattendedModeID = "unattended"
)
View Source
const BuiltinAgentName = "wingman"

Variables

View Source
var (
	ErrTurnInProgress = agent.ErrTurnInProgress
	ErrEmptyInput     = agent.ErrEmptyInput
)
View Source
var (
	// ErrNoActiveTurn means a steer lost the active-turn boundary race.
	ErrNoActiveTurn = errors.New("no active turn")
	// ErrTurnNotSteerable means the active backend turn rejects same-turn input.
	ErrTurnNotSteerable = errors.New("active turn is not steerable")
	// ErrInputNotQueued means a queue mutation targeted a non-queued input.
	ErrInputNotQueued = errors.New("turn input is not queued")
	// ErrDuplicateInput means an input ID is already live in the session.
	ErrDuplicateInput = errors.New("turn input id already exists")
	// ErrInvalidIntent means the input requested an unsupported routing mode.
	ErrInvalidIntent = errors.New("invalid turn input intent")
)

Functions

func HasAgentsConfig added in v0.8.3

func HasAgentsConfig() bool

func SessionIDFromContext added in v0.7.0

func SessionIDFromContext(ctx context.Context) string

func SessionsDir added in v0.6.9

func SessionsDir(workingDir string) string

func UnattendedElicitation added in v0.12.7

func UnattendedElicitation(req tool.ElicitRequest) tool.ElicitResult

UnattendedElicitation resolves questions without UI. Defaults win, followed by the first (recommended) option; required free-text questions are declined rather than answered with fabricated input.

func WithSessionID added in v0.7.0

func WithSessionID(ctx context.Context, sid string) context.Context

Types

type Agent

type Agent interface {
	Name() string

	Workspace() *Workspace

	Models(sessionID string) (available []model.Model, current string)

	SetModel(ctx context.Context, sessionID, id string) error

	Effort(sessionID string) (current string, options []string)

	SetEffort(ctx context.Context, sessionID, value string) error

	Modes(sessionID string) (available []Mode, current string)

	SetMode(ctx context.Context, sessionID, modeID string) error

	ListSessions(ctx context.Context) ([]SessionInfo, error)

	NewSession(ctx context.Context) (string, error)

	LoadSession(ctx context.Context, id string) error

	DeleteSession(ctx context.Context, id string) error

	Messages(sessionID string) []agent.Message

	Usage(sessionID string) agent.Usage

	// Send starts one turn and returns its event stream. Immediate validation
	// and busy-session failures are returned directly; errors that happen after
	// the turn starts are yielded by the stream. Send never queues implicitly.
	// Once Send returns successfully, the agent owns input and callers may reuse
	// or mutate their slice.
	Send(ctx context.Context, sessionID string, input []agent.Content) (iter.Seq2[agent.Message, error], error)

	Cancel(sessionID string)

	Close() error
}

type AgentDef added in v0.7.0

type AgentDef struct {
	Name string `json:"name"`

	Command string `json:"command"`

	Args []string `json:"args,omitempty"`

	Env map[string]string `json:"env,omitempty"`
}

func LoadAgents added in v0.7.0

func LoadAgents() ([]AgentDef, error)

type Command added in v0.12.0

type Command struct {
	Name        string
	Description string
	InputHint   string
}

type CommandProvider added in v0.12.0

type CommandProvider interface {
	Commands(sessionID string) []Command
}

CommandProvider exposes agent-defined slash commands for clients that can present command discovery alongside their own local commands.

type HistorySnapshot added in v0.12.9

type HistorySnapshot struct {
	Messages []agent.Message
	Revision uint64
}

HistorySnapshot is an atomic view of a session's retained messages. Revision changes only when existing history is rewritten (for example by compaction), not when messages are appended normally.

type HistorySnapshotProvider added in v0.12.9

type HistorySnapshotProvider interface {
	HistorySnapshot(sessionID string) HistorySnapshot
}

HistorySnapshotProvider lets UIs distinguish an append from a history rewrite. Agents without rewrite behavior may continue to expose Messages.

type HistoryVersion added in v0.12.9

type HistoryVersion struct {
	Revision     uint64
	MessageCount int
}

HistoryVersion is a cheap discriminator for retained history. Revision changes on rewrites; MessageCount changes on ordinary appends.

type HistoryVersionProvider added in v0.12.9

type HistoryVersionProvider interface {
	HistoryVersion(sessionID string) HistoryVersion
}

HistoryVersionProvider lets polling UIs avoid cloning a complete history snapshot when neither its length nor rewrite revision changed.

type Mode added in v0.8.0

type Mode struct {
	ID          string
	Name        string
	Description string
}

func UnattendedMode added in v0.12.7

func UnattendedMode() Mode

type SessionInfo added in v0.7.0

type SessionInfo struct {
	ID        string
	Title     string
	UpdatedAt time.Time
}

type SessionLoadStreamer added in v0.8.8

type SessionLoadStreamer interface {
	LoadSessionStream(ctx context.Context, id string) iter.Seq2[[]agent.Message, error]
}

type TurnEvent added in v0.10.9

type TurnEvent struct {
	SessionID string
	InputID   string
	State     TurnInputState
	Intent    TurnInputIntent
	Position  int
	// StreamEvent carries a transport lifecycle boundary separately from
	// conversational messages.
	StreamEvent agent.StreamEvent
	// Message is only valid for the duration of the synchronous event handler.
	// Handlers that retain it must copy its content.
	Message *agent.Message
	Err     error
	// Executed is true only for the primary input whose Agent.Send call ended.
	// Steered and removed queued inputs also receive terminal states but must not
	// trigger turn-finalization side effects such as checkpoints.
	Executed bool
}

type TurnFeatureProvider added in v0.10.9

type TurnFeatureProvider interface {
	TurnFeatures(sessionID string) TurnFeatures
}

TurnFeatureProvider advertises optional in-turn behavior. FIFO follow-up queueing is supplied by TurnManager for every Agent; providers only need to advertise behavior that must be implemented by the backend itself.

type TurnFeatures added in v0.10.9

type TurnFeatures struct {
	Steer bool `json:"steer"`
}

type TurnInput added in v0.10.9

type TurnInput struct {
	ID      string
	Content []agent.Content
	Intent  TurnInputIntent
}

type TurnInputIntent added in v0.10.9

type TurnInputIntent string
const (
	TurnInputFollowUp TurnInputIntent = "follow_up"
	TurnInputSteer    TurnInputIntent = "steer"
)

type TurnInputSnapshot added in v0.10.9

type TurnInputSnapshot struct {
	ID       string
	State    TurnInputState
	Intent   TurnInputIntent
	Position int
}

type TurnInputState added in v0.10.9

type TurnInputState string
const (
	TurnInputQueued    TurnInputState = "queued"
	TurnInputActive    TurnInputState = "active"
	TurnInputSteered   TurnInputState = "steered"
	TurnInputCompleted TurnInputState = "completed"
	TurnInputCancelled TurnInputState = "cancelled"
	TurnInputFailed    TurnInputState = "failed"
)

type TurnManager added in v0.10.9

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

TurnManager provides the session-level execution semantics shared by the web UI and other multi-turn clients. It guarantees one Agent.Send call per session at a time, supplies a FIFO follow-up queue for every backend, and uses native steering only when the backend explicitly supports it.

func NewTurnManager added in v0.10.9

func NewTurnManager(ctx context.Context, a Agent, handler func(TurnEvent)) *TurnManager

func (*TurnManager) CancelAll added in v0.10.9

func (m *TurnManager) CancelAll(sessionID string)

CancelAll interrupts the active turn and cancels every queued follow-up.

func (*TurnManager) CancelCurrent added in v0.10.9

func (m *TurnManager) CancelCurrent(sessionID string)

CancelCurrent interrupts the active turn and pauses queued follow-ups.

func (*TurnManager) ClearQueue added in v0.10.9

func (m *TurnManager) ClearQueue(sessionID string)

func (*TurnManager) Close added in v0.10.9

func (m *TurnManager) Close()

func (*TurnManager) Features added in v0.10.9

func (m *TurnManager) Features(sessionID string) TurnFeatures

func (*TurnManager) RemoveQueued added in v0.10.9

func (m *TurnManager) RemoveQueued(sessionID, inputID string) error

func (*TurnManager) ReplaceQueued added in v0.10.9

func (m *TurnManager) ReplaceQueued(sessionID, inputID string, replacement TurnInput) error

func (*TurnManager) Resume added in v0.10.9

func (m *TurnManager) Resume(sessionID string) bool

func (*TurnManager) SetHandler added in v0.10.9

func (m *TurnManager) SetHandler(handler func(TurnEvent))

func (*TurnManager) Snapshot added in v0.10.9

func (m *TurnManager) Snapshot(sessionID string) TurnSnapshot

func (*TurnManager) Submit added in v0.10.9

func (m *TurnManager) Submit(ctx context.Context, sessionID string, input TurnInput) (TurnInputSnapshot, error)

Submit accepts an input exactly once. A steer that loses a turn-boundary race automatically becomes a FIFO follow-up instead of being discarded.

type TurnSnapshot added in v0.10.9

type TurnSnapshot struct {
	Inputs   []TurnInputSnapshot
	Paused   bool
	Features TurnFeatures
}

type TurnSteerer added in v0.10.9

type TurnSteerer interface {
	Steer(ctx context.Context, sessionID string, input TurnInput) error
}

TurnSteerer injects input into the currently active turn. ErrNoActiveTurn and ErrTurnNotSteerable ask TurnManager to preserve the input as a FIFO follow-up; other errors are returned to the caller. Implementations must not mutate input and must copy its content if they retain it after Steer returns.

type UI

type UI interface {
	Elicit(ctx context.Context, req tool.ElicitRequest) (tool.ElicitResult, error)
	Confirm(ctx context.Context, message string) (bool, error)
}

type Workspace added in v0.6.9

type Workspace struct {
	Root        *os.Root
	RootPath    string
	MemoryPath  string
	ScratchPath string

	Skills []skill.Skill

	Plugins []plugin.Plugin

	MCP *mcp.Manager

	LSP     *lsp.Manager
	Changes *changes.Manager
	Graph   *graph.Engine
	// contains filtered or unexported fields
}

func NewWorkspace added in v0.6.9

func NewWorkspace(workDir string) (*Workspace, error)

func (*Workspace) ChangesFingerprint added in v0.12.6

func (w *Workspace) ChangesFingerprint(ctx context.Context) uint64

func (*Workspace) Close added in v0.6.9

func (w *Workspace) Close()

func (*Workspace) DefinitionLocations added in v0.12.12

func (w *Workspace) DefinitionLocations(ctx context.Context, filePath string, content *string, line, column int) ([]lsp.DefLocation, error)

DefinitionLocations resolves a position in a disk file or in-memory editor buffer using the language server associated with the file.

func (*Workspace) Diagnostics added in v0.6.9

func (*Workspace) Diff added in v0.12.6

func (w *Workspace) Diff(ctx context.Context, path string, layer changes.DiffLayer) (changes.FileDiff, error)

func (*Workspace) Diffs added in v0.6.9

func (w *Workspace) Diffs(ctx context.Context) ([]changes.FileDiff, error)

func (*Workspace) DocumentSymbolItems added in v0.12.12

func (w *Workspace) DocumentSymbolItems(ctx context.Context, filePath string, content *string) ([]lsp.DocumentSymbol, []lsp.SymbolInformation, error)

func (*Workspace) FileDiagnostics added in v0.12.12

func (w *Workspace) FileDiagnostics(ctx context.Context, filePath string, content *string) ([]lsp.Diagnostic, bool, error)

FileDiagnostics returns diagnostics for one disk file or in-memory editor buffer. The boolean is false when the server has not produced a result yet.

func (*Workspace) GitBranches added in v0.12.6

func (w *Workspace) GitBranches(ctx context.Context, refresh bool) ([]changes.GitBranch, string, error)

func (*Workspace) GitCheckoutBranch added in v0.12.6

func (w *Workspace) GitCheckoutBranch(ctx context.Context, name, remote string) error

func (*Workspace) GitCommit added in v0.12.6

func (w *Workspace) GitCommit(ctx context.Context, message string) (string, error)

func (*Workspace) GitCreateBranch added in v0.12.6

func (w *Workspace) GitCreateBranch(ctx context.Context, name string) error

func (*Workspace) GitPull added in v0.12.6

func (w *Workspace) GitPull(ctx context.Context) (string, error)

func (*Workspace) GitPush added in v0.12.6

func (w *Workspace) GitPush(ctx context.Context) (string, error)

func (*Workspace) GitStage added in v0.12.6

func (w *Workspace) GitStage(ctx context.Context, paths []string) error

func (*Workspace) GitStatus added in v0.12.6

func (w *Workspace) GitStatus(ctx context.Context) (changes.GitStatus, error)

func (*Workspace) GitUnstage added in v0.12.6

func (w *Workspace) GitUnstage(ctx context.Context, paths []string) error

func (*Workspace) HasChanges added in v0.12.6

func (w *Workspace) HasChanges() bool

func (*Workspace) HasLSP added in v0.10.3

func (w *Workspace) HasLSP() bool

func (*Workspace) HasNativeGit added in v0.12.6

func (w *Workspace) HasNativeGit() bool

func (*Workspace) HoverInformation added in v0.12.12

func (w *Workspace) HoverInformation(ctx context.Context, filePath string, content *string, line, column int) (string, error)

func (*Workspace) ImplementationLocations added in v0.12.12

func (w *Workspace) ImplementationLocations(ctx context.Context, filePath string, content *string, line, column int) ([]lsp.DefLocation, error)

func (*Workspace) InitMCP added in v0.6.9

func (w *Workspace) InitMCP(ctx context.Context) error

func (*Workspace) IsGitRepo added in v0.6.9

func (w *Workspace) IsGitRepo() bool

func (*Workspace) ManagedTools added in v0.7.0

func (w *Workspace) ManagedTools() (mcpTools, lspTools, graphTools []tool.Tool)

func (*Workspace) MemoryContent added in v0.6.9

func (w *Workspace) MemoryContent() string

func (*Workspace) ReferenceLocations added in v0.12.12

func (w *Workspace) ReferenceLocations(ctx context.Context, filePath string, content *string, line, column int) ([]lsp.DefLocation, error)

func (*Workspace) RevertChange added in v0.12.6

func (w *Workspace) RevertChange(ctx context.Context, path string) error

func (*Workspace) SyncProjectMode added in v0.6.9

func (w *Workspace) SyncProjectMode()

func (*Workspace) TypeDefinitionLocations added in v0.12.12

func (w *Workspace) TypeDefinitionLocations(ctx context.Context, filePath string, content *string, line, column int) ([]lsp.DefLocation, error)

func (*Workspace) WarmUp added in v0.6.9

func (w *Workspace) WarmUp()

func (*Workspace) WithEditDiagnostics added in v0.12.7

func (w *Workspace) WithEditDiagnostics(tools []tool.Tool) []tool.Tool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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