Help us shape the future of Go! Take the 2026 Go Developer Survey

control

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package control is the local API between the awp daemon and its clients (the CLI, the MCP server, harness hooks): newline-delimited JSON over a Unix socket that only the owning user can open.

A request is one line, {"method": "...", "params": {...}}. A plain call gets one reply line, {"result": ...} or {"error": "..."}. A streaming call gets {"event": ...} lines until either side closes.

Index

Constants

View Source
const SocketName = "awp.sock"

SocketName is the control socket's file name inside the awp home.

Variables

View Source
var ErrNoDaemon = errors.New("awp daemon is not running")

ErrNoDaemon means nothing is listening on the control socket.

Functions

func Serve

func Serve(ctx context.Context, home string, h Handler) error

Serve accepts control connections on the socket in home until ctx ends.

func SocketPath

func SocketPath(home string) (string, error)

SocketPath is where the daemon for home listens. Unix socket paths are limited in length, so a home that is too deep (common in sandboxes) gets its socket in the user's private runtime directory instead, named by a hash of the home path. Daemon and clients compute the same path.

Types

type Client

type Client struct {
	Home string
}

Client calls a daemon.

func (*Client) Call

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

Call makes one call and decodes the result into out (if non-nil).

func (*Client) Running

func (c *Client) Running() bool

Running reports whether a daemon answers on the socket.

func (*Client) Stream

func (c *Client) Stream(ctx context.Context, method string, params any, fn func(json.RawMessage) error) error

Stream makes a streaming call, passing each event to fn until fn returns an error, ctx ends or the daemon ends the stream.

type Handler

type Handler interface {
	Call(ctx context.Context, method string, params json.RawMessage) (any, error)
	Stream(ctx context.Context, method string, params json.RawMessage, emit func(any) error) (bool, error)
}

Handler serves calls. Stream methods write events with emit until ctx is done or they return.

type Reply

type Reply struct {
	Result json.RawMessage `json:"result,omitempty"`
	Event  json.RawMessage `json:"event,omitempty"`
	Error  string          `json:"error,omitempty"`
}

Reply is a call's answer, or one event of a stream.

type Request

type Request struct {
	Method string          `json:"method"`
	Params json.RawMessage `json:"params,omitempty"`
}

Request is one call.

Jump to

Keyboard shortcuts

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