acp

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: MIT Imports: 17 Imported by: 0

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

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

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

func (s *Server) Cancel(_ context.Context, params coderacp.CancelNotification) error

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

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

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

ListSessions is not advertised (no sessionCapabilities.list) and not implemented in v1.

func (*Server) LoadSession

LoadSession resumes a persisted session by id — session/load becomes session.Load via SessionSpec.Resume, same as the TUI's --continue.

func (*Server) Logout

Logout is not meaningful without ACP-level authentication.

func (*Server) NewSession

NewSession creates a session via agentruntime.Builder and registers it.

func (*Server) Prompt

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

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

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

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

func (s *Server) Shutdown(ctx context.Context)

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.

Jump to

Keyboard shortcuts

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