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
- Variables
- func FilterEnv(base []string, extra map[string]string) []string
- func MapPath(sandbox, home, agentPath string, follow func() string) (string, error)
- func PermissionChoice(run bool, opts []sdk.PermissionOption) (optionID string, cancelled bool)
- func PickMode(kind, current string, available []string) (mode string, set, stop bool)
- func QuoteCommand(cmd string, args []string) string
- func ShellQuote(s string) string
- func SkipApproval(id string) bool
- func TrimTail(s string, limit int) string
- type AuthChoice
- type AuthRequiredError
- type Config
- type EnvRunner
- type Files
- type PlanLine
- type Resource
- type Session
- func (s *Session) Authenticate(ctx context.Context, methodID string) error
- func (s *Session) Close() error
- func (s *Session) CreateTerminal(ctx context.Context, p sdk.CreateTerminalRequest) (sdk.CreateTerminalResponse, error)
- func (s *Session) Diagnostics() string
- func (s *Session) KillTerminal(ctx context.Context, p sdk.KillTerminalRequest) (sdk.KillTerminalResponse, error)
- func (s *Session) Prompt(ctx context.Context, text string, resources []Resource) (string, error)
- func (s *Session) ReadTextFile(ctx context.Context, p sdk.ReadTextFileRequest) (sdk.ReadTextFileResponse, error)
- func (s *Session) ReleaseTerminal(ctx context.Context, p sdk.ReleaseTerminalRequest) (sdk.ReleaseTerminalResponse, error)
- func (s *Session) RequestPermission(ctx context.Context, p sdk.RequestPermissionRequest) (sdk.RequestPermissionResponse, error)
- func (s *Session) Sandbox() string
- func (s *Session) SessionUpdate(ctx context.Context, n sdk.SessionNotification) error
- func (s *Session) SetModel(ctx context.Context, value string) error
- func (s *Session) Stop() error
- func (s *Session) TerminalOutput(ctx context.Context, p sdk.TerminalOutputRequest) (sdk.TerminalOutputResponse, error)
- func (s *Session) WaitForTerminalExit(ctx context.Context, p sdk.WaitForTerminalExitRequest) (sdk.WaitForTerminalExitResponse, error)
- func (s *Session) WriteTextFile(ctx context.Context, p sdk.WriteTextFileRequest) (sdk.WriteTextFileResponse, error)
- type ToolView
- type Update
Constants ¶
const ProtocolVersion = sdk.ProtocolVersionNumber
ProtocolVersion is the only ACP version SSHYard speaks.
Variables ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
ShellQuote quotes one argument for a POSIX shell.
func SkipApproval ¶
SkipApproval reports whether a mode id would let the agent act without SSHYard's approval.
Types ¶
type AuthChoice ¶
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 Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session is one agent process and one ACP connection.
func Start ¶
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 ¶
Authenticate logs in with an agent-type method and retries session/new once. A second call fails.
func (*Session) Close ¶
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 (s *Session) CreateTerminal(ctx context.Context, p sdk.CreateTerminalRequest) (sdk.CreateTerminalResponse, error)
func (*Session) Diagnostics ¶
Diagnostics is the bounded stderr tail. It is never parsed as protocol.
func (*Session) KillTerminal ¶
func (s *Session) KillTerminal(ctx context.Context, p sdk.KillTerminalRequest) (sdk.KillTerminalResponse, error)
func (*Session) Prompt ¶
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 (s *Session) ReadTextFile(ctx context.Context, p sdk.ReadTextFileRequest) (sdk.ReadTextFileResponse, error)
func (*Session) ReleaseTerminal ¶
func (s *Session) ReleaseTerminal(ctx context.Context, p sdk.ReleaseTerminalRequest) (sdk.ReleaseTerminalResponse, error)
func (*Session) RequestPermission ¶
func (s *Session) RequestPermission(ctx context.Context, p sdk.RequestPermissionRequest) (sdk.RequestPermissionResponse, error)
func (*Session) SessionUpdate ¶
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) Stop ¶
Stop cancels the turn, answers every pending permission request with Cancelled, and stops running terminals. The process keeps running.
func (*Session) TerminalOutput ¶
func (s *Session) TerminalOutput(ctx context.Context, p sdk.TerminalOutputRequest) (sdk.TerminalOutputResponse, error)
func (*Session) WaitForTerminalExit ¶
func (s *Session) WaitForTerminalExit(ctx context.Context, p sdk.WaitForTerminalExitRequest) (sdk.WaitForTerminalExitResponse, error)
func (*Session) WriteTextFile ¶
func (s *Session) WriteTextFile(ctx context.Context, p sdk.WriteTextFileRequest) (sdk.WriteTextFileResponse, error)