acp

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: AGPL-3.0 Imports: 23 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package acp is SSHYard's client for one external local agent process speaking the Agent Client Protocol (github.com/coder/acp-go-sdk).

The agent process and every byte it sends are untrusted. Paths, sizes, enums and ids are checked here. Its reason, optionId, allow_always and mode requests never decide anything; the pane's policy.Gate does.

Decisions the spec leaves open (conservative):

  • A mode id skips approval when, with case and '-' / '_' removed, it contains bypass, fullaccess, auto, agent, acceptedits, alwaysapprove or skippermission. "agent" is the spec's word and also matches ids such as "my-agent".
  • An omitted terminal outputByteLimit is 1 MiB. A larger limit is clamped to 1 MiB. Zero keeps nothing.
  • At most two terminals run per session (the spec's command cap).
  • The child environment is a whitelist. DISPLAY and XDG_RUNTIME_DIR are not passed. SSH_AUTH_SOCK, SSH_AGENT_PID, SSHYARD_* and cloud credential variables are removed even if the agent config sets them.
  • A clipped tool reason is forwarded for display. The gate must ignore it.
  • A POSIX absolute path outside the sandbox is a remote path. A drive path, a relative path, or a path with a NUL byte is an error.
  • Clearing a file is not done with fs/write_text_file. The SDK rejects empty content (-32602). The agent clears with a terminal command, which is graded like any other command.

Merge points (do not invent a second path):

  • Gate: the app's App.newGate. This package never builds a gate.
  • Exec: policy.Exec. It has no environment. An implementation may also implement EnvRunner; otherwise LANG / LC_* / TERM are dropped.
  • Files: the Files interface matches A1's *remote.Files (sftpsvc.Version). Nil means "not connected yet" after Authorize.
  • Write diffs: agent.Unified.
  • policy.Action grading stays in internal/ai/policy (A1). Do not edit it.

Index

Constants

View Source
const ProtocolVersion = sdk.ProtocolVersionNumber

ProtocolVersion is the only ACP version SSHYard speaks.

Variables

View Source
var (
	// ErrProtocolVersion means the agent did not negotiate protocol version 1.
	ErrProtocolVersion = errors.New("agent protocol version is not 1")
	// ErrInterruptedSession requires restarting before another turn: ACP callbacks carry no turn identity.
	ErrInterruptedSession = errors.New("agent session was interrupted and must be restarted")
	// ErrUnsupportedAuth means the agent offered no agent-type login.
	ErrUnsupportedAuth = errors.New("unsupported authentication method")
)

Functions

func FilterEnv

func FilterEnv(base []string, extra map[string]string) []string

FilterEnv rebuilds a process environment. base is KEY=VALUE entries (os.Environ). extra is the agent's configured variables; denied names are still removed. extra wins on conflict. Order is base order, then extra names sorted.

func MapPath

func MapPath(sandbox, home, agentPath string, follow func() string) (string, error)

MapPath turns an agent path into a remote POSIX path. A path inside sandbox is rewritten under the remote working directory (follow, when it returns a POSIX absolute path, otherwise home). Any other POSIX absolute path is cleaned and returned as a remote path. Relative paths, drive paths, NUL bytes and over-long paths are rejected. The sandbox check uses filepath so Windows drive letters and case match.

func PermissionChoice

func PermissionChoice(run bool, opts []sdk.PermissionOption) (optionID string, cancelled bool)

PermissionChoice picks an option by kind, never by optionId. A run uses allow_once only. Anything else uses reject_once, then reject_always. allow_always is never chosen. With no usable option the outcome is cancelled.

func PickMode

func PickMode(kind, current string, available []string) (mode string, set, stop bool)

PickMode chooses the one session/set_mode call made after session/new. set is false when the current mode should be left alone. stop is true when the only modes skip approval: the session must not run.

codex always requests workspace-write. claude and grok are left as they are. custom prefers read-only, then plan, then default, then the first remaining mode that does not skip approval.

func QuoteCommand

func QuoteCommand(cmd string, args []string) string

QuoteCommand joins a command and its arguments as one safely quoted string. policy.Exec runs that string with sh -c; do not wrap it again.

func ShellQuote

func ShellQuote(s string) string

ShellQuote quotes one argument for a POSIX shell.

func SkipApproval

func SkipApproval(id string) bool

SkipApproval reports whether a mode id would let the agent act without SSHYard's approval.

func TrimTail

func TrimTail(s string, limit int) string

TrimTail keeps the last limit bytes, starting on a UTF-8 boundary. A non-positive limit keeps nothing.

Types

type AuthChoice

type AuthChoice struct {
	ID   string
	Name string
	Kind string // agent, env_var, terminal
}

AuthChoice is one login method the agent offered.

type AuthRequiredError

type AuthRequiredError struct {
	Methods []AuthChoice
}

AuthRequiredError means session/new refused with -32000 and at least one agent-type method. The Session is alive; call Authenticate, then Close when finished.

func (*AuthRequiredError) Error

func (e *AuthRequiredError) Error() string

type Config

type Config struct {
	Command    string
	Args       []string
	Env        map[string]string // the agent's own variables; still filtered
	BaseEnv    []string          // KEY=VALUE. Nil uses os.Environ.
	Type       string            // codex, claude, grok, custom
	Redact     bool              // mask outbound text sent to the external agent
	Gate       policy.Gate
	Files      Files
	Exec       policy.Exec
	RemoteHome string
	CwdFollow  func() string
	// OnUpdate is called from a background goroutine and must not block.
	OnUpdate func(Update)
}

Config starts one agent process for one pane.

type EnvRunner

type EnvRunner interface {
	RunEnv(ctx context.Context, cmd, dir string, env []string, stdout, stderr io.Writer) (exit int, err error)
}

EnvRunner is an optional extra on policy.Exec. That interface has no environment, and A1's runner does not implement this. When Exec does not, a terminal's LANG / LC_* / TERM variables are dropped.

type Files

type Files interface {
	ResolvePath(context.Context, string) (string, error)
	ReadContext(context.Context, string, int64) ([]byte, sftpsvc.Version, error)
	Read(path string) ([]byte, sftpsvc.Version, error)
	WriteContext(ctx context.Context, path string, data []byte, was sftpsvc.Version) (sftpsvc.Version, error)
}

Files is the remote file seam. A1's *remote.Files implements it: ReadContext and WriteContext use sftpsvc.Version, and a changed file returns sftpsvc.ErrChanged. Nil means the host is not connected yet; the gate still runs, and the call then fails.

type PlanLine

type PlanLine struct {
	Content  string
	Status   string
	Priority string
}

PlanLine is one entry of an agent plan.

type Resource

type Resource struct {
	URI  string
	Text string
}

Resource is an embedded prompt block.

type Session

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

Session is one agent process and one ACP connection.

func Start

func Start(ctx context.Context, cfg Config) (*Session, error)

Start launches the agent, initializes protocol version 1, and opens a session. A version mismatch or a failed session/new closes the process. AuthRequiredError leaves it running.

func (*Session) Authenticate

func (s *Session) Authenticate(ctx context.Context, methodID string) error

Authenticate logs in with an agent-type method and retries session/new once. A second call fails.

func (*Session) Close

func (s *Session) Close() error

Close cancels the process, closes its stdin, waits, then kills it and removes the sandbox. It is safe to call more than once.

func (*Session) CreateTerminal

func (*Session) Diagnostics

func (s *Session) Diagnostics() string

Diagnostics is the bounded stderr tail. It is never parsed as protocol.

func (*Session) KillTerminal

func (*Session) Prompt

func (s *Session) Prompt(ctx context.Context, text string, resources []Resource) (string, error)

Prompt sends text and embedded resources. The stop reason is the agent's. Cancelling ctx cancels the turn, answers pending permission requests, and stops running terminals.

func (*Session) ReadTextFile

func (*Session) ReleaseTerminal

func (*Session) Sandbox

func (s *Session) Sandbox() string

Sandbox is the empty directory the agent was started in.

func (*Session) SessionUpdate

func (s *Session) SessionUpdate(ctx context.Context, n sdk.SessionNotification) error

SessionUpdate only queues. A slow UI must not block the SDK read loop. The queue drops the oldest update when it is full.

func (*Session) SetModel

func (s *Session) SetModel(ctx context.Context, value string) error

SetModel selects the config option whose category is "model".

func (*Session) Stop

func (s *Session) Stop() error

Stop cancels the turn, answers every pending permission request with Cancelled, and stops running terminals. The process keeps running.

func (*Session) TerminalOutput

func (*Session) WriteTextFile

type ToolView

type ToolView struct {
	ID         string
	Title      string
	Kind       string
	Status     string
	Paths      []string
	Raw        string
	Diff       string
	TerminalID string
}

ToolView is a tool call or a later update to one.

type Update

type Update struct {
	Kind   string
	Text   string
	Tool   *ToolView
	Plan   []PlanLine
	Mode   string
	Config string
}

Update is one session event the UI can show. Kind is message, thought, tool, plan, mode, config, warning or error. Unknown agent events are dropped.

Directories

Path Synopsis
internal
fakeagent command
Command fakeagent is a scripted ACP agent for tests.
Command fakeagent is a scripted ACP agent for tests.

Jump to

Keyboard shortcuts

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