Documentation
¶
Index ¶
- Constants
- func MergeEnvironment(base map[string]string, extra map[string]string) []string
- func NormalizeWaitError(prefix string, err error) error
- func ValidateInitializeResponse(request InitializeRequest, response InitializeResponse) error
- type InitializeRequest
- type InitializeResponse
- type LaunchConfig
- type LockedBuffer
- type Message
- type Process
- func (p *Process) CloseInput()
- func (p *Process) Done() <-chan struct{}
- func (p *Process) Forced() bool
- func (p *Process) Kill() error
- func (p *Process) Shutdown(timeout time.Duration) error
- func (p *Process) StderrBuffer() *LockedBuffer
- func (p *Process) Stdin() io.WriteCloser
- func (p *Process) Stdout() io.ReadCloser
- func (p *Process) Wait() error
- type RequestError
- type Transport
Constants ¶
const (
// MaxMessageSize bounds the encoded JSON-RPC message size accepted by the transport.
MaxMessageSize = 10 * 1024 * 1024
)
Variables ¶
This section is empty.
Functions ¶
func MergeEnvironment ¶
MergeEnvironment returns the current environment with base and extra assignments appended.
func NormalizeWaitError ¶
NormalizeWaitError wraps subprocess wait errors with a caller-provided prefix.
func ValidateInitializeResponse ¶
func ValidateInitializeResponse(request InitializeRequest, response InitializeResponse) error
ValidateInitializeResponse checks the negotiated protocol version and capability subset.
Types ¶
type InitializeRequest ¶
type InitializeRequest struct {
ProtocolVersion string `json:"protocol_version"`
SupportedProtocolVersions []string `json:"supported_protocol_versions,omitempty"`
GrantedCapabilities []string `json:"granted_capabilities,omitempty"`
}
InitializeRequest describes the protocol version and capability contract offered by the host.
type InitializeResponse ¶
type InitializeResponse struct {
ProtocolVersion string `json:"protocol_version"`
AcceptedCapabilities []string `json:"accepted_capabilities,omitempty"`
}
InitializeResponse describes the negotiated protocol version and accepted capability contract.
func Initialize ¶
func Initialize( ctx context.Context, transport *Transport, requestID json.RawMessage, request InitializeRequest, ) (InitializeResponse, error)
Initialize sends an initialize request and validates the selected protocol version.
type LaunchConfig ¶
type LaunchConfig struct {
Command []string
Env []string
WorkingDir string
WaitDelay time.Duration
WaitErrorPrefix string
SignalGracePeriod time.Duration
}
LaunchConfig describes how to start and manage a subprocess.
type LockedBuffer ¶
type LockedBuffer struct {
// contains filtered or unexported fields
}
LockedBuffer is a concurrency-safe stderr capture buffer.
func (*LockedBuffer) String ¶
func (b *LockedBuffer) String() string
String returns the current buffer contents as a string.
type Message ¶
type Message struct {
JSONRPC string `json:"jsonrpc"`
ID *json.RawMessage `json:"id,omitempty"`
Method string `json:"method,omitempty"`
Params json.RawMessage `json:"params,omitempty"`
Result json.RawMessage `json:"result,omitempty"`
Error *RequestError `json:"error,omitempty"`
}
Message is a line-framed JSON-RPC 2.0 envelope.
type Process ¶
type Process struct {
// contains filtered or unexported fields
}
Process manages a spawned subprocess and its lifetime.
func Launch ¶
func Launch(ctx context.Context, cfg LaunchConfig) (*Process, error)
Launch starts a subprocess with the provided configuration.
func (*Process) CloseInput ¶
func (p *Process) CloseInput()
CloseInput closes the subprocess stdin pipe.
func (*Process) Done ¶
func (p *Process) Done() <-chan struct{}
Done returns a channel that closes when the subprocess exits.
func (*Process) Forced ¶
Forced reports whether shutdown escalated beyond cooperative stdin closure.
func (*Process) Shutdown ¶
Shutdown attempts cooperative exit first, then escalates to SIGTERM and SIGKILL.
func (*Process) StderrBuffer ¶
func (p *Process) StderrBuffer() *LockedBuffer
StderrBuffer returns the subprocess stderr capture buffer.
func (*Process) Stdin ¶
func (p *Process) Stdin() io.WriteCloser
Stdin returns the subprocess stdin pipe.
func (*Process) Stdout ¶
func (p *Process) Stdout() io.ReadCloser
Stdout returns the subprocess stdout pipe.
type RequestError ¶
type RequestError struct {
Code int `json:"code"`
Message string `json:"message"`
Data any `json:"data,omitempty"`
}
RequestError represents a JSON-RPC error object.
func NewInternalError ¶
func NewInternalError(data any) *RequestError
NewInternalError creates a JSON-RPC internal error.
func NewInvalidParams ¶
func NewInvalidParams(data any) *RequestError
NewInvalidParams creates a JSON-RPC invalid params error.
func NewInvalidRequest ¶
func NewInvalidRequest(data any) *RequestError
NewInvalidRequest creates a JSON-RPC invalid request error.
func NewMethodNotFound ¶
func NewMethodNotFound(method string) *RequestError
NewMethodNotFound creates a JSON-RPC method-not-found error.
func NewParseError ¶
func NewParseError(data any) *RequestError
NewParseError creates a JSON-RPC parse error.
func (*RequestError) Error ¶
func (e *RequestError) Error() string
Error returns a stable human-readable JSON-RPC error string.
type Transport ¶
type Transport struct {
// contains filtered or unexported fields
}
Transport reads and writes line-delimited JSON-RPC messages.
func NewTransport ¶
NewTransport constructs a line-delimited JSON-RPC transport.
func (*Transport) ReadMessage ¶
ReadMessage reads the next non-empty JSON-RPC message from the transport.
func (*Transport) WriteMessage ¶
WriteMessage writes one JSON-RPC message and appends a single trailing newline.