agent

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const IdleTimeout = time.Hour
View Source
const MaxFrame = 8 << 20
View Source
const ProtocolVersion = 2

Variables

View Source
var ErrDenied = errors.New("agent approval denied or canceled")
View Source
var ErrProtocol = errors.New("incompatible agent protocol; stop the old agent and retry")

Functions

func Connect

func Connect(ctx context.Context, endpoint string, start bool) (net.Conn, error)

func CurrentTerminal

func CurrentTerminal() string

func Detach

func Detach(cmd *exec.Cmd)

func Dial

func Dial(ctx context.Context, endpoint string) (net.Conn, error)

func Endpoint

func Endpoint() (string, error)

func Listen

func Listen(endpoint string) (net.Listener, error)

func ReadFrame

func ReadFrame(r io.Reader, value any) error

func Requester

func Requester(pid int) string

Requester is best-effort display context, never authorization evidence. Only executable names are inspected: process arguments may contain credentials.

func ResourceApproval

func ResourceApproval(account, command, requester, id, name string) (string, string)

ResourceApproval keeps the resource name first so long account/URI labels cannot hide it. Dialog backends sanitize all displayed text before rendering.

func Serve

func Serve(ctx context.Context, listener net.Listener, handler Handler) error

Serve serializes commands and all session lifecycle operations. Connections are bounded; slow/abandoned clients cannot retain a session or refresh its lease.

func Text

func Text(s string) string

Text removes terminal controls and bounds untrusted server/command descriptions.

func WriteFrame

func WriteFrame(w io.Writer, value any) error

Types

type Dialog

type Dialog struct {
	Backend     string
	Pinentry    string
	Terminal    string
	PID         int
	Environment []string
}

func (Dialog) Ask

func (d Dialog) Ask(ctx context.Context, title, prompt string, secret bool) (string, error)

func (Dialog) Confirm

func (d Dialog) Confirm(ctx context.Context, title, prompt string) error

func (Dialog) Select

func (d Dialog) Select(ctx context.Context, title, prompt string, choices []string) (int, error)

Select requires a controlling terminal even when a desktop is available. An unattended helper must cancel ambiguous lookups rather than choose an account.

type Handler

type Handler interface {
	Run(context.Context, Request, io.Reader, io.Writer, io.Writer) (Message, error)
	Control(context.Context, Request) (Message, error)
	Expire(context.Context)
	Close(context.Context)
}

type Message

type Message struct {
	Kind        string
	Data        []byte   `json:",omitempty"`
	Error       string   `json:",omitempty"`
	Status      []Status `json:",omitempty"`
	Environment []string `json:",omitempty"`
	Args        []string `json:",omitempty"`
}

Message multiplexes command output and interactive input without consuming stdin before the command actually asks for it.

func Exchange

func Exchange(ctx context.Context, conn net.Conn, req Request, in io.Reader, out, errOut io.Writer) (Message, error)

Exchange never retries an admitted command: a broken connection may follow a successful write. Input is read only after an explicit request from the agent.

type Request

type Request struct {
	Terminal    string
	PID         int
	Version     int
	Action      string
	Args        []string
	Settings    map[string]any
	Directory   string
	Environment []string
	Dialog      string
	Pinentry    string
}

Request travels only over owner-restricted local IPC, never a network listener.

func (Request) Validate

func (r Request) Validate() error

type Sessions

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

Sessions is owned by the serialized dispatcher. Status never extends a lease.

func NewSessions

func NewSessions(now func() time.Time) *Sessions

func (*Sessions) Close

func (s *Sessions) Close(ctx context.Context)

func (*Sessions) Expire

func (s *Sessions) Expire(ctx context.Context)

func (*Sessions) Lock

func (s *Sessions) Lock(ctx context.Context, key string)

func (*Sessions) Put

func (s *Sessions) Put(key string, close func(context.Context))

func (*Sessions) Status

func (s *Sessions) Status() []Status

func (*Sessions) Touch

func (s *Sessions) Touch(key string) bool

type Status

type Status struct {
	Account string    `json:"account"`
	Expires time.Time `json:"expires"`
}

Jump to

Keyboard shortcuts

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