Documentation
¶
Overview ¶
Package acp implements yottacode as an Agent Client Protocol (ACP) server — a long-lived process hosting N concurrent sessions over one stdio JSON-RPC connection, so yottacode is embeddable in editors that speak ACP (Zed, JetBrains, and others). See roadmap/acp-adapter.md for the full design.
Session construction reuses internal/agentruntime.Builder, the same world-building path internal/oneshot and internal/tui use — this package is protocol plumbing and event/permission translation on top of that shared core, not a fourth copy of it.
Index ¶
- type Server
- func (s *Server) Authenticate(ctx context.Context, params coderacp.AuthenticateRequest) (coderacp.AuthenticateResponse, error)
- func (s *Server) Cancel(_ context.Context, params coderacp.CancelNotification) error
- func (s *Server) CloseSession(ctx context.Context, params coderacp.CloseSessionRequest) (coderacp.CloseSessionResponse, error)
- func (s *Server) Initialize(_ context.Context, _ coderacp.InitializeRequest) (coderacp.InitializeResponse, error)
- func (s *Server) ListSessions(_ context.Context, _ coderacp.ListSessionsRequest) (coderacp.ListSessionsResponse, error)
- func (s *Server) LoadSession(ctx context.Context, params coderacp.LoadSessionRequest) (coderacp.LoadSessionResponse, error)
- func (s *Server) Logout(_ context.Context, _ coderacp.LogoutRequest) (coderacp.LogoutResponse, error)
- func (s *Server) NewSession(ctx context.Context, params coderacp.NewSessionRequest) (coderacp.NewSessionResponse, error)
- func (s *Server) Prompt(ctx context.Context, params coderacp.PromptRequest) (coderacp.PromptResponse, error)
- func (s *Server) ResumeSession(_ context.Context, _ coderacp.ResumeSessionRequest) (coderacp.ResumeSessionResponse, error)
- func (s *Server) SetConnection(conn *coderacp.AgentSideConnection)
- func (s *Server) SetSessionConfigOption(_ context.Context, params coderacp.SetSessionConfigOptionRequest) (coderacp.SetSessionConfigOptionResponse, error)
- func (s *Server) SetSessionMode(_ context.Context, params coderacp.SetSessionModeRequest) (coderacp.SetSessionModeResponse, error)
- func (s *Server) Shutdown(ctx context.Context)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Server ¶
type Server struct {
// BaseOpts carries process-level defaults (model, provider, API key,
// reasoning effort, search flags, etc.) resolved from flags/env
// before the acp server starts. ACP's session/new has no equivalent
// of yottacode's CLI flags — the client only ever supplies cwd and
// mcpServers — so every session's SessionSpec is seeded from this.
BaseOpts cli.ChatOptions
// contains filtered or unexported fields
}
Server implements coderacp.Agent (and coderacp.AgentLoader) on behalf of yottacode. One Server hosts every session for the process's lifetime; the reader/writer/framing discipline that makes that safe over a single stdio pair is coderacp.AgentSideConnection's job, not this package's — see roadmap/acp-adapter.md's Concurrency section.
func NewServer ¶
func NewServer(baseOpts cli.ChatOptions) *Server
NewServer constructs a Server. BaseOpts should already be fully resolved (cli.Resolve applied) by the caller, mirroring how cmd/yottacode/main.go resolves opts before calling oneshot.Run/tui.Run.
func (*Server) Authenticate ¶
func (s *Server) Authenticate(ctx context.Context, params coderacp.AuthenticateRequest) (coderacp.AuthenticateResponse, error)
Authenticate dispatches by MethodId. openai-chatgpt and vertex-adc are the two Agent Auth methods actually expected to arrive here — github-copilot uses Terminal Auth, which bypasses this RPC by design (see authMethods above); a client that calls it anyway gets an explanatory error rather than a silent no-op.
func (*Server) Cancel ¶
Cancel looks up the session and cancels its in-flight turn, if any — the agent loop already handles context cancellation and emits TurnInterrupted, preserving history (see internal/agent/loop.go). session/cancel is a notification (no response), so an unknown session id is silently ignored rather than erroring: the client may have raced a cancel against a session that already closed.
func (*Server) CloseSession ¶
func (s *Server) CloseSession(ctx context.Context, params coderacp.CloseSessionRequest) (coderacp.CloseSessionResponse, error)
CloseSession cancels any in-flight turn, waits (bounded) for it to actually finish so persistence never races the turn goroutine's writes to rt.Session, exports SubagentTasks, saves gated on HasExchange — mirroring internal/tui/run.go's own exit sequence exactly (sess.SubagentTasks = subagentTasks.Export(); save only if HasExchange()) — and removes the session from the registry.
func (*Server) Initialize ¶
func (s *Server) Initialize(_ context.Context, _ coderacp.InitializeRequest) (coderacp.InitializeResponse, error)
Initialize negotiates protocol version and capabilities. Exactly once, before anything else, per the ACP spec.
AuthMethods matters beyond protocol correctness: the ACP Registry requires a non-empty list here (CI-verified — see roadmap/acp-adapter.md's Phase 2 notes) with at least one method of type "agent" or "terminal". See auth.go for both implementations.
func (*Server) ListSessions ¶
func (s *Server) ListSessions(_ context.Context, _ coderacp.ListSessionsRequest) (coderacp.ListSessionsResponse, error)
ListSessions is not advertised (no sessionCapabilities.list) and not implemented in v1.
func (*Server) LoadSession ¶
func (s *Server) LoadSession(ctx context.Context, params coderacp.LoadSessionRequest) (coderacp.LoadSessionResponse, error)
LoadSession resumes a persisted session by id — session/load becomes session.Load via SessionSpec.Resume, same as the TUI's --continue.
func (*Server) Logout ¶
func (s *Server) Logout(_ context.Context, _ coderacp.LogoutRequest) (coderacp.LogoutResponse, error)
Logout is not meaningful without ACP-level authentication.
func (*Server) NewSession ¶
func (s *Server) NewSession(ctx context.Context, params coderacp.NewSessionRequest) (coderacp.NewSessionResponse, error)
NewSession creates a session via agentruntime.Builder and registers it.
func (*Server) Prompt ¶
func (s *Server) Prompt(ctx context.Context, params coderacp.PromptRequest) (coderacp.PromptResponse, error)
Prompt appends the user's message and hosts one turn of agent.Turn, draining its event channel into session/update notifications (events.go) and bridging ApprovalNeeded/PathTrustElevationNeeded into session/request_permission round trips (permissions.go). Mirrors internal/tui/model.go's own turn-hosting pattern (turnCtx/turnCancel, buffered events(64)/decisions(1)/errCh(1), a recover()-guarded goroutine that closes events) — the one difference is that ACP's session/prompt is a request that blocks until the turn completes, so the draining loop lives directly in this method rather than being driven by an external event loop.
func (*Server) ResumeSession ¶
func (s *Server) ResumeSession(_ context.Context, _ coderacp.ResumeSessionRequest) (coderacp.ResumeSessionResponse, error)
ResumeSession is not advertised (no sessionCapabilities.resume) — v1 supports the same resume path via LoadSession instead.
func (*Server) SetConnection ¶
func (s *Server) SetConnection(conn *coderacp.AgentSideConnection)
SetConnection wires the connection the Server uses for outbound calls (session/update, session/request_permission). Must be called before any inbound request can be serviced — cmd/yottacode/acp.go does this immediately after constructing the connection, mirroring coder/acp-go-sdk's own example/agent pattern (SetAgentConnection).
func (*Server) SetSessionConfigOption ¶
func (s *Server) SetSessionConfigOption(_ context.Context, params coderacp.SetSessionConfigOptionRequest) (coderacp.SetSessionConfigOptionResponse, error)
SetSessionConfigOption dispatches by ConfigId, extracted from whichever of the request's Boolean/ValueId variants is set. Mutates the same rt.Adapter/rt.Cfg.Adapter/rt.AgentTool fields a live Prompt call reads throughout a turn — claimTurn/releaseTurn (the same guard acpSession.prompt uses to reject a second concurrent session/prompt, see session.go) keeps this from racing an in-flight turn, since neither of those fields is otherwise synchronized.
func (*Server) SetSessionMode ¶
func (s *Server) SetSessionMode(_ context.Context, params coderacp.SetSessionModeRequest) (coderacp.SetSessionModeResponse, error)
SetSessionMode maps an ACP mode selection onto yottacode's mode states. The wire-level plumbing for this (the RPC itself) is provided by coder/acp-go-sdk; only the mapping table and the state transition are ours — see roadmap/acp-adapter.md §Permissions Mode mapping.
func (*Server) Shutdown ¶
Shutdown cancels and persists every still-registered session — called once at process exit (stdin EOF / client disconnect) so a client that disconnects without individually closing each session doesn't silently drop unsaved state. Reuses CloseSession's own logic per session rather than duplicating it. Sessions close concurrently, not one after another: cmd/yottacode/acp.go bounds ctx with a single process-wide acpShutdownTimeout, and closing N sessions sequentially (each already able to spend up to closeSessionDrainTimeout draining its own turn) could multiply past that shared deadline instead of sharing it.