agent

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

Package agent is the in-process code.Agent implementation. One Agent owns the workspace and all open sessions for that workspace; each session has its own *harness.Agent, transcript, and usage. The shared workspace surfaces MCP/LSP/Rewind through code.Workspace.

The pkg/agent import is aliased `harness` throughout to avoid collision with this package's own name.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildInstructions

func BuildInstructions(data prompt.SectionData) string

BuildInstructions composes the system prompt from a section-data snapshot.

func ReadProjectInstructions

func ReadProjectInstructions(wd string) string

ReadProjectInstructions is an uncached read for callers (TUI status bar, /init flows) that need the assembled block without a session.

Types

type Agent

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

Agent is the wingman in-process implementation of code.Agent. Model and effort are agent-wide (mirrors the previous server.s.model/s.effort design) and applied to every session's request via closures on the embedded harness.Config.

func New

func New(ws *code.Workspace, cfg *harness.Config, ui code.UI) *Agent

New constructs an in-process code.Agent rooted at the workspace.

func (*Agent) AutoSelectModel

func (a *Agent) AutoSelectModel(ctx context.Context)

AutoSelectModel picks a default model id from the upstream catalog when none has been set yet.

func (*Agent) Cancel

func (a *Agent) Cancel(id string)

func (*Agent) Close

func (a *Agent) Close() error

func (*Agent) DeleteSession

func (a *Agent) DeleteSession(_ context.Context, id string) error

func (*Agent) Effort

func (a *Agent) Effort() (string, []string)

func (*Agent) FetchUpstreamModels

func (a *Agent) FetchUpstreamModels(ctx context.Context)

FetchUpstreamModels populates the cache of upstream model ids so subsequent Models() calls can filter code.AvailableModels down to what the configured upstream actually serves. Call once at startup.

func (*Agent) HasSession

func (a *Agent) HasSession(id string) bool

HasSession reports whether the agent is tracking a session id in memory. Useful for the server's lazy-create check (don't restore state for a session that's already in memory).

func (*Agent) ListSessions

func (a *Agent) ListSessions(_ context.Context) ([]code.SessionInfo, error)

func (*Agent) LoadSession

func (a *Agent) LoadSession(_ context.Context, id string) error

func (*Agent) Messages

func (a *Agent) Messages(id string) []harness.Message

func (*Agent) Models

func (a *Agent) Models() ([]code.Model, string)

func (*Agent) Name

func (a *Agent) Name() string

func (*Agent) NewSession

func (a *Agent) NewSession(_ context.Context) (string, error)

NewSession mints a UUID and lazy-builds the in-memory state. Nothing is persisted to disk yet — that happens after the first Save().

func (*Agent) PlanMode

func (a *Agent) PlanMode(id string) bool

func (*Agent) Save

func (a *Agent) Save(id string) error

Save persists a session's transcript. Called after each turn by consumers that want chat to survive a restart. No-op if not loaded.

func (*Agent) Send

func (a *Agent) Send(ctx context.Context, id string, input []harness.Content) iter.Seq2[harness.Message, error]

func (*Agent) SessionsDir

func (a *Agent) SessionsDir() string

func (*Agent) SetEffort

func (a *Agent) SetEffort(_ context.Context, value string) error

func (*Agent) SetModel

func (a *Agent) SetModel(_ context.Context, id string) error

func (*Agent) SetPlanMode

func (a *Agent) SetPlanMode(id string, plan bool)

func (*Agent) SetUI

func (a *Agent) SetUI(ui code.UI)

SetUI installs the elicitation UI used by ask_user and shell-confirm hooks. Without a UI the agent falls back to accepted defaults (Confirm → true, Ask → ""); set one before the first turn if you want the user to be prompted. Safe to call concurrently.

func (*Agent) Tools

func (a *Agent) Tools(id string) []tool.Tool

Tools returns the snapshot tool list for a session (used by the TUI to enumerate tool names and check the Hidden flag for the help/picker menus). Returns nil for unknown ids.

func (*Agent) Usage

func (a *Agent) Usage(id string) harness.Usage

func (*Agent) Workspace

func (a *Agent) Workspace() *code.Workspace

Jump to

Keyboard shortcuts

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