adapter

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBackendList = errors.New("list shared session backend")

ErrBackendList marks a ListAll failure of the shared session backend itself, as opposed to a partial per-adapter failure whose surviving results are still returned.

Functions

func ClassifyPane

func ClassifyPane(paneAlive bool) (State, ProcLiveness)

ClassifyPane maps a pane's process liveness to the session lifecycle state. We deliberately do not inspect pane content: these agents render full-screen TUIs, so a capture is dominated by chrome (footer, status line, input box) rather than a clean log, which made any text-scraped state or activity summary unreliable. State is grounded only in whether the pane PID is alive.

func ShellJoin

func ShellJoin(args []string) string

ShellJoin renders argv as a single /bin/sh command string with every value POSIX single-quote escaped. The native backend execs agent argv directly — no shell anywhere on the dispatch path — so this survives only for the command-alias fallback, where the user's interactive shell must resolve an alias/function that LookPath cannot see (shellAliasCommand).

Types

type Agent

type Agent struct {
	NameValue        string
	DisplayNameValue string
	Candidates       []CommandCandidate
	YoloArgs         []string
	Backend          Backend
	Terminal         ProviderTerminalPolicy
	SessionArgs      func(req ResumeRequest, activity string) []string
	// PrepareLaunch runs after cwd and canonical session-name resolution.
	// Preparation args run first; legacy SessionArgs are appended after them.
	// Preparation identity overrides ProviderSession, which overrides the
	// request's stored identity. Core UAM env keys cannot be overridden.
	PrepareLaunch PrepareLaunchFunc
	// ProviderSession optionally reports the provider-side session id that
	// the launched agent will use (e.g. the uuid claude was seeded with via
	// --session-id), or "" when unknown. It is persisted so a later resume
	// can target the exact provider session (F-resume).
	ProviderSession       func(req ResumeRequest, activity string) string
	LiveProviderSessionID func(sessionName string) (string, error)
	ResumeKindFor         func(req ResumeRequest) ResumeKind
	SkipPromptOnResume    bool
	// contains filtered or unexported fields
}

Agent adapts one provider CLI (claude, codex, ...) onto the shared session backend. It was previously named TmuxAgent; the lifecycle contract is unchanged, only the backend is now uam's own session hosts.

func NewAgent

func NewAgent(name, display string, candidates []CommandCandidate, yoloArgs []string, backend Backend) *Agent

func (*Agent) Attach

func (a *Agent) Attach(id string) (AttachSpec, error)

func (*Agent) Available

func (a *Agent) Available() (bool, string)

func (*Agent) Dispatch

func (a *Agent) Dispatch(ctx context.Context, req DispatchRequest) (Session, error)

func (*Agent) DisplayName

func (a *Agent) DisplayName() string

func (*Agent) HasSession

func (a *Agent) HasSession(ctx context.Context, id string) bool

func (*Agent) List

func (a *Agent) List(ctx context.Context) ([]Session, error)

func (*Agent) ListFromSnapshot

func (a *Agent) ListFromSnapshot(ctx context.Context, infos []session.Info) ([]Session, error)

ListFromSnapshot filters a shared backend snapshot for this provider. The registry uses it to scan the runtime directory once per refresh while custom adapters that only implement List retain their existing behavior.

func (*Agent) Name

func (a *Agent) Name() string

func (*Agent) Resume

func (a *Agent) Resume(ctx context.Context, req ResumeRequest) (Session, error)

func (*Agent) ResumeKind

func (a *Agent) ResumeKind(req ResumeRequest) ResumeKind

func (*Agent) Stop

func (a *Agent) Stop(ctx context.Context, id string) error

func (*Agent) TerminalPolicy

func (a *Agent) TerminalPolicy() ProviderTerminalPolicy

type AgentAdapter

type AgentAdapter interface {
	Name() string
	DisplayName() string
	Available() (bool, string)
	Dispatch(ctx Context, req DispatchRequest) (Session, error)
	List(ctx Context) ([]Session, error)
	Attach(id string) (AttachSpec, error)
	Stop(ctx Context, id string) error
}

type AttachProfileSnapshot

type AttachProfileSnapshot struct {
	Selected      string
	Effective     string
	Mouse         string
	ControlPrefix string
	BackDetach    bool
}

type AttachSpec

type AttachSpec struct {
	Argv    []string
	Profile AttachProfileSnapshot
}

type BackDetachPolicy

type BackDetachPolicy string

BackDetachPolicy is a provider's default for the attach client's quick detach (Ctrl+Left while the input box is empty detaches). The gesture assumes Ctrl+Left is a no-op at an empty prompt; providers that bind it to their own UI (pane or tab navigation) disable the default. Profiles and session overrides still take precedence either way.

const (
	// BackDetachDefault leaves the quick detach enabled (the zero value).
	BackDetachDefault BackDetachPolicy = ""
	// BackDetachDisabled turns the quick detach off unless a profile or
	// override explicitly enables it.
	BackDetachDisabled BackDetachPolicy = "disabled"
)

type Backend

type Backend interface {
	CreateProviderSession(ctx context.Context, spec session.CreateSpec) error
	SetSessionLabel(ctx context.Context, name, label string) error
	List(ctx context.Context) ([]session.Info, error)
	Capture(ctx context.Context, name string, lines int) (string, error)
	SendLine(ctx context.Context, name, text string) error
	// SendPrompt types the initial prompt once the provider has taken the
	// terminal, so a starting TUI receives it as keys rather than a cooked line.
	SendPrompt(ctx context.Context, name, text string) error
	Kill(ctx context.Context, name string) error
	HasSession(ctx context.Context, name string) bool
	AttachArgv(name string) ([]string, error)
}

Backend is the session-management surface an Agent drives: create / list / capture / input / kill / attach against uam's native session hosts (internal/session.Client in production, fakes in tests).

type CommandCandidate

type CommandCandidate struct {
	Display string
	Args    []string
}

type Context

type Context = context.Context

type DispatchRequest

type DispatchRequest struct {
	Prompt          string
	Cwd             string
	Mode            string
	Name            string
	CommandAlias    string
	ScrollbackLines int
}

type HasSessionAdapter

type HasSessionAdapter interface {
	HasSession(ctx Context, id string) bool
}

HasSessionAdapter reports whether the agent's underlying session for id is still live. Optional: Service.Stop probes it after a failed kill to avoid deleting/flagging a record whose process is still running (F04). Agent implements it for free, so every provider inherits it.

type KeyProtocolPolicy

type KeyProtocolPolicy string
const KeyProtocolNative KeyProtocolPolicy = "native"

type LaunchPreparation

type LaunchPreparation struct {
	Command           []string
	ExtraArgs         []string
	Env               map[string]string
	ProviderSessionID string
	// InitialPrompt bypasses terminal input and is inherited by the provider
	// command as fd 3. Agent closes its copy after creating the session.
	InitialPrompt *os.File
}

LaunchPreparation is provider-owned launch metadata computed after the canonical backend identity and cwd are known, but before any session is created. Slices and maps are copied by Agent before use.

type OuterScreenPolicy

type OuterScreenPolicy string
const (
	OuterScreenUAM     OuterScreenPolicy = "uam"
	OuterScreenPrimary OuterScreenPolicy = "primary"
)

type PRRef

type PRRef struct {
	URL    string
	Owner  string
	Repo   string
	Number int
	Status PRStatus
}

func ExtractPR

func ExtractPR(text string) *PRRef

type PRStatus

type PRStatus string
const (
	PRNone   PRStatus = "None"
	PROpen   PRStatus = "Open"
	PRMerged PRStatus = "Merged"
	PRClosed PRStatus = "Closed"
	PRDraft  PRStatus = "Draft"
)

type PrepareLaunchFunc

type PrepareLaunchFunc func(ctx Context, req ResumeRequest, activity, sessionName, cwd string) (LaunchPreparation, error)

type ProcLiveness

type ProcLiveness string
const (
	Alive  ProcLiveness = "Alive"
	Exited ProcLiveness = "Exited"
)

type ProviderIdentity

type ProviderIdentity string
const (
	ProviderClaude   ProviderIdentity = "claude"
	ProviderCodex    ProviderIdentity = "codex"
	ProviderCopilot  ProviderIdentity = "copilot"
	ProviderHermes   ProviderIdentity = "hermes"
	ProviderOMP      ProviderIdentity = "omp"
	ProviderOpenCode ProviderIdentity = "opencode"
)

type ProviderTerminalPolicy

type ProviderTerminalPolicy struct {
	Identity    ProviderIdentity
	OuterScreen OuterScreenPolicy
	KeyProtocol KeyProtocolPolicy
	BackDetach  BackDetachPolicy
}

func (ProviderTerminalPolicy) Validate

func (p ProviderTerminalPolicy) Validate() error

type Registry

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

func NewRegistry

func NewRegistry(adapters []AgentAdapter) *Registry

func NewRegistryWithBackend

func NewRegistryWithBackend(backend Backend, adapters []AgentAdapter) *Registry

NewRegistryWithBackend records the backend shared by production adapters so ListAll can enumerate it once and fan the immutable snapshot out by provider.

func (*Registry) Default

func (r *Registry) Default(preferred string) AgentAdapter

func (*Registry) DisabledReasons

func (r *Registry) DisabledReasons() map[string]string

func (*Registry) Enabled

func (r *Registry) Enabled() []AgentAdapter

func (*Registry) Get

func (r *Registry) Get(name string) (AgentAdapter, bool)

func (*Registry) ListAll

func (r *Registry) ListAll(ctx Context) ([]Session, error)

ListAll returns every enabled provider's sessions. Production adapters share one backend snapshot; custom adapters without snapshot support fall back to their ordinary List implementation. Partial results survive adapter errors.

type ResumableAdapter

type ResumableAdapter interface {
	Resume(ctx Context, req ResumeRequest) (Session, error)
}

type ResumeKind

type ResumeKind string
const (
	ResumeExact       ResumeKind = "exact"
	ResumeHeuristic   ResumeKind = "heuristic"
	ResumeUnsupported ResumeKind = "unsupported"
)

type ResumeKindAdapter

type ResumeKindAdapter interface {
	ResumeKind(ResumeRequest) ResumeKind
}

type ResumeRequest

type ResumeRequest struct {
	ID              string
	Name            string
	CommandAlias    string
	ScrollbackLines int
	Prompt          string
	Cwd             string
	Mode            string
	SessionName     string
	// ProviderSessionID is the persisted provider-side session id, when one
	// was recorded at dispatch; providers that support exact resume use it
	// instead of their "most recent" heuristic.
	ProviderSessionID string
	CreatedAt         time.Time
	// ExecutablePath is transient launch metadata populated by Agent only
	// after alias validation and PATH resolution. Preparation hooks may probe
	// it; it is never persisted.
	ExecutablePath string
}

type Session

type Session struct {
	ID           string
	AgentType    string
	CommandAlias string
	DisplayName  string
	Prompt       string
	Cwd          string
	SessionName  string
	// ProviderSessionID is the agent CLI's own session identifier, recorded
	// when the provider lets uam seed or learn it (e.g. claude --session-id).
	// It upgrades resume from "most recent conversation in this cwd" to an
	// exact-session resume.
	ProviderSessionID string
	State             State
	ProcAlive         ProcLiveness
	LastChange        time.Time
	CreatedAt         time.Time
	PR                *PRRef
	Pinned            bool
	Group             string
	SortIndex         int
	// ExitCode is the agent process's exit status from its most recent close
	// (-1 when it died on a signal), recorded by the session host. Nil while
	// the session is live or when no exit has been observed.
	ExitCode *int
	// Closed mirrors store.StatusClosedByUser: explicit UAM stop/restart reason
	// metadata retained for compatibility. Dashboard lifecycle grouping uses
	// ProcAlive, so every exited process is STOPPED regardless of this flag.
	Closed bool
}

type State

type State string

State is the lifecycle bucket for a managed session. We deliberately keep only two values: anything richer (working / needs-input / completed) requires text-scraping the pane and produced more false positives than real signal. The pane content drives the activity summary line instead; the State here is grounded in the pane PID being alive or not.

const (
	Active    State = "Active"
	Completed State = "Completed"
	Failed    State = "Failed"
)

type TerminalPolicyAdapter

type TerminalPolicyAdapter interface {
	TerminalPolicy() ProviderTerminalPolicy
}

Directories

Path Synopsis
Package adaptertest provides a recording fake of adapter.Backend for tests.
Package adaptertest provides a recording fake of adapter.Backend for tests.

Jump to

Keyboard shortcuts

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