acp

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: AGPL-3.0 Imports: 26 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 id that is a URI with a fragment is judged by the fragment only.
  • 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 (
	CategoryModel   = "model"
	CategoryThought = "thought_level"
)

Option categories the pane shows: the model and how much it thinks. The mode is SSHYard's to pin and is never offered.

View Source
const Instructions = `You are working on a remote server for a user of SSHYard, an SSH client. The host, user and working directory come with each request.
- Everything the user asks about is on that remote host, never on this computer. Your local working directory is an empty scratch folder that has nothing to do with the task: do not look at it or at any other local file.
- Run commands on the host only with the ` + RemoteServer + ` MCP server's ` + toolRun + ` tool, or the terminal the client provides. Read and write the host's files only with ` + toolRead + ` and ` + toolWrite + `, or the client's file tools. Paths are paths on the remote host; a relative path is relative to the working directory.
- Do not run local shell commands, search or list local files, use other MCP servers, or connect to the host yourself with ssh: SSHYard already holds the connection and you have no credentials.
- SSHYard checks every action and may ask the user first. When one is refused, do not try to reach the same result another way.`

Instructions tell the agent where it works. They go into its system prompt where it takes one, otherwise before the first request.

View Source
const ProtocolVersion = sdk.ProtocolVersionNumber

ProtocolVersion is the only ACP version SSHYard speaks.

View Source
const RemoteServer = "sshyard"

RemoteServer is the name of the MCP server that gives the agent the pane's host: its tools run commands and read and write files there, each through the pane's gate. Agents that run their own tools on this computer are pointed at it instead.

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 read-only: its work happens on the remote host through SSHYard, never on this computer. 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 RemoteTool added in v0.0.14

func RemoteTool(title string) bool

RemoteTool reports whether a tool call the agent shows is one of the remote tools, by its title.

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 Choice added in v0.0.14

type Choice struct {
	Value       string
	Name        string
	Description string
}

Choice is one value of an Option.

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)
	// contains filtered or unexported fields
}

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 Option added in v0.0.14

type Option struct {
	ID       string
	Name     string
	Category string
	Current  string
	Values   []Choice
}

Option is one of the agent's session settings with a list of values, as the agent reports it.

func Find added in v0.0.14

func Find(opts []Option, id string) (Option, bool)

Find is the option with this id.

func Probe added in v0.0.14

func Probe(ctx context.Context, cfg Config) ([]Option, error)

Probe starts the agent only to read its model and thinking selectors, then stops it. It needs no host: nothing is asked of the agent.

func (Option) Value added in v0.0.14

func (o Option) Value(v string) (Choice, bool)

Value is the choice with this value, if the option has it.

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) Options added in v0.0.14

func (s *Session) Options() []Option

Options are the agent's model and thinking selectors as last reported.

func (*Session) Prefer added in v0.0.14

func (s *Session) Prefer(ctx context.Context, want map[string]string) error

Prefer sets each selector to the value wanted for it, when the agent offers that value and it is not already set. A value no longer offered is skipped. The first failure stops and is returned.

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) SetOption added in v0.0.14

func (s *Session) SetOption(ctx context.Context, id, value string) ([]Option, error)

SetOption sets one of the agent's selectors to a value it offered and returns the selectors as they are now: a new model can change the thinking levels.

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.

func (ToolView) Local added in v0.0.14

func (v ToolView) Local() bool

Local says whether the agent ran the tool on this computer itself: a command or search that went neither through the client's terminal nor through the remote tools. Reads and edits reach the host through the client's file callbacks.

type Update

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

Update is one session event the UI can show. Kind is message, thought, tool, plan, mode, config, warning, notice or error. Unknown agent events are dropped. A notice's Text is a policy.AuditNotice code. A config update carries the agent's selectors as they are now.

Directories

Path Synopsis
Package detect finds ACP agents installed on this computer, so the user picks one instead of typing a command line.
Package detect finds ACP agents installed on this computer, so the user picks one instead of typing a command line.
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