acp

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package acp is the wire side of the Agent Client Protocol: JSON-RPC 2.0 messages, one per line, read from the client on standard input and written to it on standard output. What the messages mean is the caller's (cmd/kvit-coder/acp.go); this package only carries them.

Requests from the client are handled each on its own goroutine, so a session/cancel, or the answer to a question this side asked, is read while a prompt is still running. Responses and notifications are written whole, one at a time.

Index

Constants

View Source
const (
	CodeParseError     = -32700
	CodeInvalidRequest = -32600
	CodeMethodNotFound = -32601
	CodeInvalidParams  = -32602
	CodeInternalError  = -32603
)

The JSON-RPC error codes this side sends.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

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

Conn is one connection to a client.

func NewConn

func NewConn(r io.Reader, w io.Writer, h Handler) *Conn

NewConn makes a connection reading r and writing w.

func (*Conn) Call

func (c *Conn) Call(ctx context.Context, method string, params any, result any) error

Call sends a request and waits for its answer, which is decoded into result when that is not nil. It gives up when ctx is done.

func (*Conn) Notify

func (c *Conn) Notify(method string, params any) error

Notify sends a notification.

func (*Conn) Serve

func (c *Conn) Serve(ctx context.Context) error

Serve reads messages until the input ends or ctx is done. Requests still being handled then are told through their context and waited for, so a prompt that was running writes down what it did before Serve returns.

type Error

type Error struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    any    `json:"data,omitempty"`
}

Error is a JSON-RPC error, sent as the answer to a request or received as one.

func Errorf

func Errorf(code int, format string, args ...any) *Error

Errorf makes an error with a code.

func (*Error) Error

func (e *Error) Error() string

type Handler

type Handler interface {
	HandleRequest(ctx context.Context, method string, params json.RawMessage) (any, error)
	HandleNotification(method string, params json.RawMessage)
}

Handler answers what the client sends. HandleRequest returns the result to send back, or an error; an *Error keeps its code and any other error is sent as an internal error with its text. HandleNotification has nothing to answer.

Jump to

Keyboard shortcuts

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