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 ¶
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).
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 ¶
ShellQuote quotes s for a POSIX shell when it holds anything beyond letters, digits and ./_-+:,@%=.
func SocketPath ¶
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.
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 ¶
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 ¶
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) LastDeadline ¶
LastDeadline is the deadline of the last call's context, nil when it had none (tests check that approval calls carry none).
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