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

client

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package client is the secret-free side of a product: it dials the console socket of a project and profile and calls the console's JSON-RPC methods. A product's CLI client commands and MCP server are built on it.

A call carries no client-side timeout: a request waits for the human as long as the console allows. The caller's context is the only way to abandon a call, and abandoning one closes the connection, which the console sees as "client gone".

Index

Constants

This section is empty.

Variables

View Source
var ErrConsoleClosed = errors.New("the console closed the connection")

ErrConsoleClosed means the console closed the connection before answering (the session ended, or the console stopped).

View Source
var ErrNoConsole = errors.New("no console is running")

ErrNoConsole means no console listens for the profile. Errors that match it are *NoConsoleError values carrying the command the human must run.

Functions

func ShellQuote

func ShellQuote(s string) string

ShellQuote quotes s for a POSIX shell when it holds anything beyond letters, digits and ./_-+:,@%=.

func SocketPath

func SocketPath(p kit.Product, cwd, profile string) (string, error)

SocketPath is p's console socket of profile for the project of cwd. The console computes the same path: in the shared socket directory when the machine separates the console from the agent (sysconf), in the user's runtime directory otherwise.

func StartCommand

func StartCommand(p kit.Product, profile, project string) string

StartCommand is the exact command that starts p's console for profile (left out when empty) on project (left out when "": the user config).

Types

type Client

type Client struct {
	// Name identifies the client in the hello handshake (the product's
	// name when empty).
	Name string
	// ConsoleVersion is the console's version, known after the first call.
	ConsoleVersion string
	// contains filtered or unexported fields
}

Client is one connection to a console. Calls are serialised.

func Dial

func Dial(p kit.Product, cwd, profile string) (*Client, error)

Dial connects to p's console of profile for the project of cwd. It returns a *NoConsoleError (matching ErrNoConsole) when none is running. The hello handshake happens on the first call, under that call's context.

func (*Client) Call

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

Call sends one request and decodes its result into result (nil to ignore it). A console error is returned as *ipc.RPCError. Numbers in result decode as json.Number when result holds interface values.

func (*Client) Close

func (c *Client) Close() error

Close closes the connection.

func (*Client) LastDeadline

func (c *Client) LastDeadline() *time.Time

LastDeadline is the deadline of the last call's context, nil when it had none (tests check that approval calls carry none).

func (*Client) Profile

func (c *Client) Profile() string

Profile is the profile this client talks to.

type NoConsoleError

type NoConsoleError struct {
	Product kit.Product
	Profile string
	// Project is the project root of the client's directory, "" outside
	// any project. The console must serve the same project.
	Project string
	Socket  string
	Err     error
}

NoConsoleError reports a missing console and how to start it.

func (*NoConsoleError) Command

func (e *NoConsoleError) Command() string

Command is the exact command that starts the missing console.

func (*NoConsoleError) Error

func (e *NoConsoleError) Error() string

func (*NoConsoleError) Hint

func (e *NoConsoleError) Hint() string

Hint tells the agent what to ask of the user. Inside a project, only a console started on that project serves the agent, so the hint names it; outside one, the hint asks for the project's directory, since the console runs in the product's account and reads the profiles from the project's config.

func (*NoConsoleError) Is

func (e *NoConsoleError) Is(target error) bool

Is makes errors.Is(err, ErrNoConsole) true.

func (*NoConsoleError) Unwrap

func (e *NoConsoleError) Unwrap() error

Jump to

Keyboard shortcuts

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