Documentation
¶
Overview ¶
Package subprocess carries the JSON-RPC 2.0 wire protocol used for host-to-plugin communication over stdio. These types are consumed by both the host (for encoding requests / decoding responses) and by the plugin side of the SDK (server.go / subprocess.Serve).
Communication is host-initiated: the host sends JSON-RPC requests on the subprocess's stdin, and reads responses from its stdout. The subprocess does not initiate requests — all registrations are declarative via the plugin/load response.
Index ¶
- Constants
- Variables
- func EncodeHookHandleBatchParams(v HookHandleBatchParams) ([]byte, error)
- func EncodeHookHandleBatchResult(v HookHandleBatchResult) ([]byte, error)
- func EncodeHookHandleParams(v HookHandleParams) ([]byte, error)
- func EncodeHookHandleResult(v HookHandleResult) ([]byte, error)
- func GrantSetFromContext(ctx context.Context) (capability.GrantSet, bool)
- func Log() plugin.Logger
- func Serve(p Plugin) error
- func ServeWithOptions(p Plugin, options ServeOptions) error
- func ValidateHookBatchRequest(p HookHandleBatchParams, notification bool) error
- func ValidateHookBatchResultFor(p HookHandleBatchParams, r HookHandleBatchResult) error
- func ValidateHookDTO(name string, raw []byte) error
- func ValidateHookRequest(p HookHandleParams, notification bool) error
- func ValidateHookResultFor(p HookHandleParams, r HookHandleResult) error
- func ValidateHostRPCDTO(name string, data []byte) error
- func ValidateInitResult(p InitParams, r InitResult) error
- func ValidateRPCControlDTO(name string, raw []byte, directional bool) error
- type AdmissionLimits
- type ApplicationErrorResponse
- type BindingID
- type BindingsRenewArgs
- type BindingsRenewParams
- type BindingsRenewResult
- type CRUDHandler
- type CRUDListResult
- type CRUDParams
- type CRUDResult
- type CacheHelper
- type CancelParams
- type CancelReason
- type CapabilityRequest
- type CommandExecParams
- type CommandExecResult
- type CommandHandler
- type CommandRequest
- type CommandResult
- type ConfigReader
- type DataHelper
- type DeadlineExceededError
- type EgressRequestArgs
- type EgressRequestParams
- type EgressRequestResult
- type EventHandleParams
- type EventHandleResult
- type EventHandler
- type EventRequest
- type EventResult
- type EventsPublishArgs
- type EventsPublishParams
- type EventsPublishResult
- type ForwardContext
- type FrameLimits
- type FrameTooLargeError
- type GrantsRenewParams
- type GrantsRenewResult
- type GrantsRenewalHandler
- type HTTPHandler
- type HTTPRequest
- type HTTPResponse
- type HealthChecker
- type HealthResult
- type HealthStatus
- type HookErrorData
- type HookFailure
- type HookHandleBatchParams
- type HookHandleBatchResult
- type HookHandleParams
- type HookHandleResult
- type HookHandler
- type HookScope
- type HookTrace
- type HookValidationError
- type HooksProfile
- type HostClient
- func (h *HostClient) BindingsRenew(ctx context.Context, a BindingsRenewArgs) (r BindingsRenewResult, err error)
- func (h *HostClient) EgressRequest(ctx context.Context, a EgressRequestArgs) (r EgressRequestResult, err error)
- func (h *HostClient) EventsPublish(ctx context.Context, a EventsPublishArgs) (r EventsPublishResult, err error)
- func (h *HostClient) Log(ctx context.Context, a HostLogArgs) (r LogResult, err error)
- func (h *HostClient) MCPCallTool(ctx context.Context, a MCPCallToolArgs) (*MCPToolCall, error)
- func (h *HostClient) MCPCancelCall(ctx context.Context, a MCPCancelCallArgs) (r MCPCancelCallResult, err error)
- func (h *HostClient) MCPListTools(ctx context.Context, a MCPListToolsArgs) (r MCPListToolsResult, err error)
- func (h *HostClient) ReadonlyQuery(ctx context.Context, a ReadonlyQueryArgs) (r ReadonlyQueryResult, err error)
- func (h *HostClient) SecretsGet(ctx context.Context, a SecretsGetArgs) (SecretValue, error)
- func (h *HostClient) StorageDelete(ctx context.Context, a StorageDeleteArgs) (r StorageDeleteResult, err error)
- func (h *HostClient) StorageGet(ctx context.Context, a StorageGetArgs) (r StorageGetResult, err error)
- func (h *HostClient) StoragePut(ctx context.Context, a StoragePutArgs) (r StoragePutResult, err error)
- type HostInfo
- type HostLogArgs
- type HostRPCError
- type HostRPCErrorData
- type HostRPCHeader
- type HostRPCLogField
- type HostRPCRemainingBudgets
- type HostRPCRequestOwner
- type HostRPCValidationError
- type HostServiceLimits
- type HostServices
- type IdentityAware
- type InitError
- type InitFailureCode
- type InitParams
- func (p *InitParams) HasCapability(name string) bool
- func (p InitParams) MarshalJSON() ([]byte, error)
- func (p *InitParams) ResolvedCacheDir() (string, error)
- func (p *InitParams) ResolvedDataDir() (string, error)
- func (p *InitParams) UnmarshalJSON(data []byte) error
- func (p InitParams) Validate() error
- type InitResult
- type LoadParams
- type LoadResult
- type LogParams
- type LogResult
- type MCPCallRequest
- type MCPCallResult
- type MCPCallToolArgs
- type MCPCallToolParams
- type MCPCallToolResult
- type MCPCancelCallArgs
- type MCPCancelCallParams
- type MCPCancelCallResult
- type MCPHandler
- type MCPListToolsArgs
- type MCPListToolsParams
- type MCPListToolsResult
- type MCPTool
- type MCPToolCall
- type MigrateParams
- type MigrateResult
- type Migrator
- type ParentCall
- type Plugin
- type PluginRPCErrorData
- type QueueLimits
- type RPCError
- type RPCID
- type RPCRequest
- type RPCResponse
- type RPCTransportError
- type ReadonlyQueryArgs
- type ReadonlyQueryParams
- type ReadonlyQueryResult
- type ReverseContext
- type SecretValue
- type SecretsGetArgs
- type SecretsGetParams
- type SecretsGetResult
- type ServeOptions
- type SkippedRegistration
- type StorageDeleteArgs
- type StorageDeleteParams
- type StorageDeleteResult
- type StorageGetArgs
- type StorageGetParams
- type StorageGetResult
- type StoragePutArgs
- type StoragePutParams
- type StoragePutResult
- type TransportCancelledError
Constants ¶
const ( // Lifecycle methods. MethodInit = "plugin/init" MethodLoad = "plugin/load" MethodUnload = "plugin/unload" MethodHealth = "plugin/health" // Runtime methods (host -> plugin). MethodCommandExecute = "command/execute" MethodEventHandle = "event/handle" MethodHookHandle = "hook/handle" MethodHookHandleBatch = "hook/handle_batch" MethodCRUDCreate = "crud/create" MethodCRUDRead = "crud/read" MethodCRUDUpdate = "crud/update" MethodCRUDDelete = "crud/delete" MethodCRUDList = "crud/list" // MCP methods (host -> plugin). MethodListTools = "mcp/list_tools" // MethodMCPCallTool is sent when an MCP tool provided by the plugin // is invoked. The plugin responds with an MCPCallResult carrying // tool output and any emitted envelopes. MethodMCPCallTool = "mcp/call_tool" // MethodHTTPHandle is sent when an HTTP route registered by the // plugin is hit. The plugin responds with an HTTPResponse. // Streaming is not supported on this path — use SSE envelopes via // EventHandleResult instead. MethodHTTPHandle = "http/handle" // MethodMigrate is sent at plugin load time when the plugin's // installed manifest version differs from the declared version. // Plugins that don't implement migration should return an empty // MigrateResult. MethodMigrate = "plugin/migrate" )
const ( ErrCodeParse = -32700 ErrCodeInvalidRequest = -32600 ErrCodeMethodNotFound = -32601 ErrCodeInvalidParams = -32602 ErrCodeInternal = -32603 // Application-level error codes (plugin-specific). ErrCodeNotFound = -32000 ErrCodeConflict = -32001 ErrCodeValidation = -32002 ErrCodeCancelled = -32003 // pre-hook cancellation )
const ControlHandlerSlots = 2
const DefaultFrameBytes = 8 * 1024 * 1024
DefaultFrameBytes includes the terminating LF and any accepted CR.
const DefaultQueueFrames = 32
const DefaultQueuedWriteBytes = 8 * 1024 * 1024
const DefaultShutdownTimeout = 5 * time.Second
DefaultShutdownTimeout bounds drain, cleanup and flush together.
const DefaultWriteTimeout = 5 * time.Second
DefaultWriteTimeout bounds one whole transport write, independently of EOF.
const ForwardHandlerSlots = 16
const GrantsRenewalVersion = 1
const HooksProfileVersion = 1
HooksProfileVersion is acknowledged when Init offers it and the plugin implements HookHandler.
const MaxHookBatchItems = 64
const MaxHookDTOBytes = 1 << 20
const MaxHostRPCDTOBytes = 1 << 20
MaxHostRPCDTOBytes caps each encoded params/result DTO, including base64 text.
const MethodGrantsRenew = "plugin/grants/renew"
const ProtocolVersion = 2
ProtocolVersion is the current wire-protocol version negotiated during the plugin/init handshake. Host and plugin must agree exactly.
const ReverseHandlerSlots = 8
const TerminalCreditBytes = 1024
Variables ¶
var ErrFrameUTF8 = errors.New("subprocess: input frame is not valid UTF-8")
var ErrNoDataDir = errors.New("subprocess: InitParams.DataDir not set by host")
ErrNoDataDir is returned by InitParams.ResolvedDataDir when the host did not provide a DataDir. Valid protocol-2 Init requires it; direct helper callers may still have an incomplete value.
var ErrShutdownTimeout = errors.New("subprocess: shutdown incomplete: deadline exceeded")
ErrShutdownTimeout means drain, cleanup or output flushing did not finish. It is a transport/cleanup failure, not the plugin's hook-veto cancellation.
var ErrTruncatedFrame = errors.New("subprocess: truncated input frame without LF")
var ErrWriteTimeout = errors.New("subprocess: stdout write deadline exceeded")
Functions ¶
func EncodeHookHandleBatchParams ¶
func EncodeHookHandleBatchParams(v HookHandleBatchParams) ([]byte, error)
EncodeHookHandleBatchParams validates and preserves opaque payload literals.
func EncodeHookHandleBatchResult ¶
func EncodeHookHandleBatchResult(v HookHandleBatchResult) ([]byte, error)
EncodeHookHandleBatchResult validates and preserves opaque payload literals.
func EncodeHookHandleParams ¶
func EncodeHookHandleParams(v HookHandleParams) ([]byte, error)
EncodeHookHandleParams validates and preserves opaque payload literals.
func EncodeHookHandleResult ¶
func EncodeHookHandleResult(v HookHandleResult) ([]byte, error)
EncodeHookHandleResult validates and preserves opaque payload literals.
func GrantSetFromContext ¶
func GrantSetFromContext(ctx context.Context) (capability.GrantSet, bool)
GrantSetFromContext returns the current detached SDK discovery snapshot. It is not permission. Existing calls retain their original finite deadlines.
func Log ¶
Log returns the package-level logger. It is safe to call before Serve() has initialized logging; pre-init calls write to a discard sink rather than panicking.
func Serve ¶
Serve runs the JSON-RPC server loop against a plugin, reading requests from stdin and writing responses to stdout.
The lifecycle is:
- Serve installs a signal handler for SIGTERM/SIGINT so a host- initiated shutdown triggers Unload before the process exits.
- Serve reads newline-delimited JSON requests from stdin. Each request is dispatched in its own goroutine with panic recovery.
- Unknown methods return ErrCodeMethodNotFound.
- Explicit unload, stdin EOF or a shutdown signal fences new work, cancels/drains admitted work, then calls Unload at most once and returns. The default shutdown budget is five seconds; see ServeWithOptions.
The Plugin must implement the minimum Init/Load/Unload contract. Optional capability interfaces (CommandHandler, EventHandler, CRUDHandler, HealthChecker, Migrator, MCPHandler, HTTPHandler, IdentityAware) are detected via type assertion at startup.
A plugin main typically looks like:
func main() {
if err := subprocess.Serve(&myPlugin{}); err != nil {
os.Exit(1)
}
}
func ServeWithOptions ¶
func ServeWithOptions(p Plugin, options ServeOptions) error
ServeWithOptions shares one shutdown path for unload, EOF and cancellation. Only runtime-owned stdin/stdout may be closed to interrupt pending I/O.
func ValidateHookBatchRequest ¶
func ValidateHookBatchRequest(p HookHandleBatchParams, notification bool) error
func ValidateHookBatchResultFor ¶
func ValidateHookBatchResultFor(p HookHandleBatchParams, r HookHandleBatchResult) error
func ValidateHookDTO ¶
ValidateHookDTO validates raw tokens before decoding erases field presence, duplicates, integer form or exact casing. Payload is opaque and may be null.
func ValidateHookRequest ¶
func ValidateHookRequest(p HookHandleParams, notification bool) error
ValidateHookRequest selects request or notification semantics explicitly. Callers must derive notification from ABSENT id, never null or zero.
func ValidateHookResultFor ¶
func ValidateHookResultFor(p HookHandleParams, r HookHandleResult) error
func ValidateHostRPCDTO ¶
ValidateHostRPCDTO accepts only the closed structural DTO vocabulary. It validates JSON, not authority, service dispatch, or transport correlation. Host-owned opaque query/tool schemas must be checked by their owners.
func ValidateInitResult ¶
func ValidateInitResult(p InitParams, r InitResult) error
ValidateInitResult checks agreement; hosts additionally check expected plugin identity/version and whether their required service profiles were accepted.
Types ¶
type AdmissionLimits ¶
type AdmissionLimits struct{ Forward, Reverse, Control int }
AdmissionLimits narrow connection-local handler ceilings. Zero uses the default. Accepted offers may narrow these further, never widen them.
type ApplicationErrorResponse ¶
type ApplicationErrorResponse struct {
JSONRPC string `json:"jsonrpc"`
ID capability.RequestID `json:"id"`
Error HostRPCError `json:"error"`
}
ApplicationErrorResponse retains positive profile correlation separately from the broader base JSON-RPC ID domain. Data.RequestID must equal ID.
func (ApplicationErrorResponse) MarshalJSON ¶
func (v ApplicationErrorResponse) MarshalJSON() ([]byte, error)
func (*ApplicationErrorResponse) UnmarshalJSON ¶
func (v *ApplicationErrorResponse) UnmarshalJSON(data []byte) error
func (ApplicationErrorResponse) Validate ¶
func (v ApplicationErrorResponse) Validate() error
type BindingID ¶
type BindingID string
BindingID is an opaque host-issued reference, never an SDK-minted credential.
type BindingsRenewArgs ¶
type BindingsRenewParams ¶
type BindingsRenewParams struct {
GrantID string `json:"grant_id"`
Context ReverseContext `json:"context"`
RequestedLeaseMS uint64 `json:"requested_lease_ms"`
}
func (BindingsRenewParams) MarshalJSON ¶
func (v BindingsRenewParams) MarshalJSON() ([]byte, error)
func (*BindingsRenewParams) UnmarshalJSON ¶
func (v *BindingsRenewParams) UnmarshalJSON(data []byte) error
func (BindingsRenewParams) Validate ¶
func (v BindingsRenewParams) Validate() error
type BindingsRenewResult ¶
type BindingsRenewResult struct {
BindingID BindingID `json:"binding_id"`
ExpiresAt string `json:"expires_at"`
RemainingBudgets HostRPCRemainingBudgets `json:"remaining_budgets"`
}
func (BindingsRenewResult) MarshalJSON ¶
func (v BindingsRenewResult) MarshalJSON() ([]byte, error)
func (*BindingsRenewResult) UnmarshalJSON ¶
func (v *BindingsRenewResult) UnmarshalJSON(data []byte) error
func (BindingsRenewResult) Validate ¶
func (v BindingsRenewResult) Validate() error
type CRUDHandler ¶
type CRUDHandler interface {
Create(ctx context.Context, resourceType string, data map[string]interface{}) (map[string]interface{}, error)
Read(ctx context.Context, resourceType, id string) (map[string]interface{}, error)
Update(ctx context.Context, resourceType, id string, data map[string]interface{}) (map[string]interface{}, error)
Delete(ctx context.Context, resourceType, id string) error
List(ctx context.Context, resourceType string, filters map[string]interface{}) ([]map[string]interface{}, error)
}
CRUDHandler is implemented by plugins that own a resource type with Create/Read/Update/Delete/List semantics.
type CRUDListResult ¶
type CRUDListResult struct {
Items []json.RawMessage `json:"items"`
}
CRUDListResult is returned for crud/list.
type CRUDParams ¶
type CRUDParams struct {
Context *ForwardContext `json:"context,omitempty"`
ResourceType string `json:"resource_type"`
ID string `json:"id,omitempty"` // for read/update/delete
Data map[string]interface{} `json:"data,omitempty"` // for create/update
Filters map[string]interface{} `json:"filters,omitempty"` // for list
}
CRUDParams is sent for all crud/* methods.
func (CRUDParams) MarshalJSON ¶
func (p CRUDParams) MarshalJSON() ([]byte, error)
CRUD fields are operation-dependent, but a supplied empty object is present. omitempty on a map would erase it and violate create/update's required data.
type CRUDResult ¶
type CRUDResult struct {
Data json.RawMessage `json:"data"`
}
CRUDResult is returned for crud/create, crud/read, crud/update.
type CacheHelper ¶
type CacheHelper interface {
// CacheDir returns the absolute path of the plugin's cache directory.
CacheDir() string
// CachePath returns a path under CacheDir, joined with filepath.Join.
CachePath(elem ...string) string
// EnsureCacheDir creates the plugin's cache directory if it does
// not exist, with 0o755 permissions.
EnsureCacheDir() error
}
CacheHelper exposes the plugin's writable cache directory. The cache may be wiped by the host at any time; plugins must not rely on cache contents surviving a restart. Cache lives on the same filesystem as DataDir so atomic renames work for both.
func NewCacheHelper ¶
func NewCacheHelper(dir string) CacheHelper
NewCacheHelper returns a CacheHelper rooted at the given directory.
type CancelParams ¶
type CancelParams struct {
RequestOwner HostRPCRequestOwner `json:"request_owner"`
ID RPCID `json:"id"`
Reason CancelReason `json:"reason"`
}
func (CancelParams) MarshalJSON ¶
func (v CancelParams) MarshalJSON() ([]byte, error)
func (*CancelParams) UnmarshalJSON ¶
func (v *CancelParams) UnmarshalJSON(b []byte) error
type CancelReason ¶
type CancelReason string
const ( CallerCancelled CancelReason = "caller_cancelled" DeadlineExpired CancelReason = "deadline_exceeded" ParentCancelled CancelReason = "parent_cancelled" ConnectionClosing CancelReason = "connection_closing" )
type CapabilityRequest ¶
type CapabilityRequest struct {
// Name identifies the capability in the host's vocabulary. The SDK
// treats it as an opaque string.
Name string `json:"name"`
// Reason is a human-readable justification, surfaced to whoever
// reviews or approves the plugin.
Reason string `json:"reason,omitempty"`
// Optional marks a capability the plugin can run without. A plugin
// that sets this must degrade when the capability is not granted
// rather than fail to load.
Optional bool `json:"optional,omitempty"`
// Metadata is host-defined detail about the request — a scope, a
// path, a narrowing of any kind. Opaque to the SDK.
Metadata json.RawMessage `json:"metadata,omitempty"`
}
CapabilityRequest is a capability a plugin asks its host for.
Name is an open string whose meaning belongs to the host, and Metadata is opaque JSON the host interprets according to its own descriptor schema. This declaration alone grants no authority.
Declaration belongs in the host's manifest rather than in plugin code, so that what a plugin asks for is reviewable before the plugin runs. A host embeds this type in its own manifest schema, decides what to allow, and reports the outcome back over the existing handshake in InitParams.Grants.
A plugin that lies in its manifest is bounded by what the host grants, not by what it claimed. The declaration is an input to the host's decision, not a guarantee on its own.
type CommandExecParams ¶
type CommandExecParams struct {
Context *ForwardContext `json:"context,omitempty"`
Name string `json:"name"`
SessionID string `json:"session_id"`
Args string `json:"args"`
// Identity is an opaque, host-verified identity value for this
// call. See InitParams.Identity.
Identity json.RawMessage `json:"identity,omitempty"`
}
CommandExecParams is sent to the plugin for command/execute.
type CommandExecResult ¶
type CommandExecResult struct {
Action string `json:"action"` // "message", "noop", "error"
Content string `json:"content,omitempty"`
Envelopes []plugin.EnvelopeOut `json:"envelopes,omitempty"`
}
CommandExecResult is returned by the plugin for command/execute.
type CommandHandler ¶
type CommandHandler interface {
Command(ctx context.Context, req CommandRequest) (CommandResult, error)
}
CommandHandler is implemented by plugins that handle slash commands.
type CommandRequest ¶
type CommandRequest struct {
Name string
SessionID string
Args string
// Identity is the opaque, host-verified identity value from the
// wire request, if any. See IdentityAware.
Identity json.RawMessage
}
CommandRequest is passed to a plugin's Command handler.
type CommandResult ¶
type CommandResult struct {
Action string // "message", "noop", "error"
Content string // message body (for "message" action)
Envelopes []plugin.EnvelopeOut // optional envelopes to emit alongside the message
}
CommandResult is returned by a plugin's Command handler.
type ConfigReader ¶
type ConfigReader interface {
// String returns the value for key, or the empty string if missing.
String(key string) string
// Bool returns the value for key parsed as a boolean
// (strconv.ParseBool rules). Returns false if missing or unparseable.
Bool(key string) bool
// Int returns the value for key parsed as a signed integer. Returns
// 0 if missing or unparseable.
Int(key string) int
// Secret returns the value for key and records it with the logger's
// secret tracker so subsequent SDK logs redact it in message text,
// structured values and canonical base64-encoded bytes. Use this for
// API keys, tokens, and other sensitive strings.
Secret(key string) string
// Required returns the value for key and an error if the key is
// missing or blank.
Required(key string) (string, error)
// Has reports whether the key is present in the resolved config.
Has(key string) bool
}
ConfigReader exposes resolved plugin configuration to plugin code. The host resolves config via its precedence rules (plugin_settings DB -> env var -> plugin.yaml default -> zero value) before passing the map through InitParams.Config. ConfigReader is the SDK-level view of that resolved map.
func NewConfigReader ¶
func NewConfigReader(values map[string]string) ConfigReader
NewConfigReader wraps a resolved config map and the package-level secret tracker so Secret lookups feed into log redaction.
type DataHelper ¶
type DataHelper interface {
// DataDir returns the absolute path of the plugin's data directory.
// Plugins may create subdirectories under it.
DataDir() string
// DataPath returns a path under DataDir, joined with filepath.Join.
DataPath(elem ...string) string
// EnsureDataDir creates the plugin's data directory if it does not
// exist, with 0o755 permissions.
EnsureDataDir() error
}
DataHelper exposes the plugin's writable data directory. Data written here survives plugin updates and reinstalls — it is the "user owns this" tier. The SDK deliberately does not expose a SQLite or KV helper; plugins that need durable structured storage should open their own database file under DataDir().
func NewDataHelper ¶
func NewDataHelper(dir string) DataHelper
NewDataHelper returns a DataHelper rooted at the given directory. Typically called from a plugin's Init method with a path derived from InitParams (e.g., filepath.Join(params.PluginDir, "data")).
type DeadlineExceededError ¶
type DeadlineExceededError struct{}
func (*DeadlineExceededError) Error ¶
func (*DeadlineExceededError) Error() string
type EgressRequestArgs ¶
type EgressRequestArgs struct {
GrantID, Method, URL string
Headers *[]HostRPCHeader
BodyBase64, OperationKey *string
}
type EgressRequestParams ¶
type EgressRequestParams struct {
GrantID string `json:"grant_id"`
Context ReverseContext `json:"context"`
Method string `json:"method"`
URL string `json:"url"`
Headers *[]HostRPCHeader `json:"headers,omitempty"`
BodyBase64 *string `json:"body_base64,omitempty"`
OperationKey *string `json:"operation_key,omitempty"`
}
func (EgressRequestParams) MarshalJSON ¶
func (v EgressRequestParams) MarshalJSON() ([]byte, error)
func (*EgressRequestParams) UnmarshalJSON ¶
func (v *EgressRequestParams) UnmarshalJSON(data []byte) error
func (EgressRequestParams) Validate ¶
func (v EgressRequestParams) Validate() error
type EgressRequestResult ¶
type EgressRequestResult struct {
Status uint64 `json:"status"`
Headers []HostRPCHeader `json:"headers"`
BodyBase64 string `json:"body_base64"`
OperationKey *string `json:"operation_key,omitempty"`
}
func (EgressRequestResult) MarshalJSON ¶
func (v EgressRequestResult) MarshalJSON() ([]byte, error)
func (*EgressRequestResult) UnmarshalJSON ¶
func (v *EgressRequestResult) UnmarshalJSON(data []byte) error
func (EgressRequestResult) Validate ¶
func (v EgressRequestResult) Validate() error
type EventHandleParams ¶
type EventHandleParams struct {
Context *ForwardContext `json:"context,omitempty"`
Type string `json:"type"`
Source string `json:"source"`
Data map[string]interface{} `json:"data"`
SessionID string `json:"session_id,omitempty"`
PreHook bool `json:"pre_hook"` // true if host expects cancel/allow response
// Identity is an opaque, host-verified identity value for this
// call. See InitParams.Identity.
Identity json.RawMessage `json:"identity,omitempty"`
}
EventHandleParams is sent to the plugin for event/handle.
func (EventHandleParams) MarshalJSON ¶
func (p EventHandleParams) MarshalJSON() ([]byte, error)
MarshalJSON emits the required event data object even when the host supplied a nil map. The receiver is copied; the caller's map is not changed.
type EventHandleResult ¶
type EventHandleResult struct {
Cancel bool `json:"cancel,omitempty"` // true to cancel a pre-hook action
Reason string `json:"reason,omitempty"`
Envelopes []plugin.EnvelopeOut `json:"envelopes,omitempty"`
}
EventHandleResult is returned by the plugin for event/handle.
type EventHandler ¶
type EventHandler interface {
EventHandle(ctx context.Context, req EventRequest) (EventResult, error)
}
EventHandler is implemented by plugins that subscribe to host events.
type EventRequest ¶
type EventRequest struct {
Type string
Source string
Data map[string]interface{}
SessionID string
PreHook bool // true if the host expects a cancel/allow response
// Identity is the opaque, host-verified identity value from the
// wire request, if any. See IdentityAware.
Identity json.RawMessage
}
EventRequest is passed to a plugin's EventHandle handler.
type EventResult ¶
type EventResult struct {
Cancel bool
Reason string
Envelopes []plugin.EnvelopeOut
}
EventResult is returned by a plugin's EventHandle handler.
type EventsPublishArgs ¶
type EventsPublishArgs struct {
GrantID, EventName string
Payload json.RawMessage
OperationKey string
}
type EventsPublishParams ¶
type EventsPublishParams struct {
GrantID string `json:"grant_id"`
Context ReverseContext `json:"context"`
EventName string `json:"event_name"`
Payload json.RawMessage `json:"payload"`
OperationKey string `json:"operation_key"`
}
func (EventsPublishParams) MarshalJSON ¶
func (v EventsPublishParams) MarshalJSON() ([]byte, error)
func (*EventsPublishParams) UnmarshalJSON ¶
func (v *EventsPublishParams) UnmarshalJSON(data []byte) error
func (EventsPublishParams) Validate ¶
func (v EventsPublishParams) Validate() error
type EventsPublishResult ¶
type EventsPublishResult struct {
OperationKey string `json:"operation_key"`
Accepted bool `json:"accepted"`
EventID string `json:"event_id"`
}
func (EventsPublishResult) MarshalJSON ¶
func (v EventsPublishResult) MarshalJSON() ([]byte, error)
func (*EventsPublishResult) UnmarshalJSON ¶
func (v *EventsPublishResult) UnmarshalJSON(data []byte) error
func (EventsPublishResult) Validate ¶
func (v EventsPublishResult) Validate() error
type ForwardContext ¶
type ForwardContext struct {
BindingID *BindingID `json:"binding_id,omitempty"`
TimeoutMS uint32 `json:"timeout_ms"`
}
func ForwardContextFromContext ¶
func ForwardContextFromContext(ctx context.Context) (ForwardContext, bool)
ForwardContextFromContext returns host-provided invocation metadata. It does not authorize a binding or enforce a deadline; those remain host policy.
func (ForwardContext) MarshalJSON ¶
func (v ForwardContext) MarshalJSON() ([]byte, error)
func (*ForwardContext) UnmarshalJSON ¶
func (v *ForwardContext) UnmarshalJSON(data []byte) error
func (ForwardContext) Validate ¶
func (v ForwardContext) Validate() error
type FrameLimits ¶
type FrameLimits struct{ InputBytes, OutputBytes int }
FrameLimits may narrow the symmetric implementation ceilings. Zero uses the default. Limits apply before Init and do not activate optional profiles.
type FrameTooLargeError ¶
FrameTooLargeError carries bounded transport metadata, never frame contents.
func (*FrameTooLargeError) Error ¶
func (e *FrameTooLargeError) Error() string
type GrantsRenewParams ¶
type GrantsRenewParams struct {
RenewalVersion int `json:"renewal_version"`
Sequence uint64 `json:"sequence"`
Incarnation capability.RuntimeIdentity `json:"incarnation"`
Grants capability.GrantSet `json:"grants"`
Context ForwardContext `json:"context"`
}
GrantsRenewParams is host initiated. It requires a request ID and an actual acknowledged response, never a notification. Sequence starts at one and is never reused on a connection, including after a failed attempt.
func (GrantsRenewParams) MarshalJSON ¶
func (p GrantsRenewParams) MarshalJSON() ([]byte, error)
func (*GrantsRenewParams) UnmarshalJSON ¶
func (p *GrantsRenewParams) UnmarshalJSON(raw []byte) error
func (GrantsRenewParams) Validate ¶
func (p GrantsRenewParams) Validate() error
type GrantsRenewResult ¶
type GrantsRenewResult struct {
RenewalVersion int `json:"renewal_version"`
Sequence uint64 `json:"sequence"`
Incarnation capability.RuntimeIdentity `json:"incarnation"`
}
func (GrantsRenewResult) MarshalJSON ¶
func (r GrantsRenewResult) MarshalJSON() ([]byte, error)
func (*GrantsRenewResult) UnmarshalJSON ¶
func (r *GrantsRenewResult) UnmarshalJSON(raw []byte) error
func (GrantsRenewResult) Validate ¶
func (r GrantsRenewResult) Validate() error
type GrantsRenewalHandler ¶
type GrantsRenewalHandler interface {
GrantsRenewed(context.Context, capability.GrantSet) error
}
GrantsRenewalHandler opts into acknowledged discovery updates. Implementations atomically replace their own cached grant metadata, respect ctx cancellation, and must not infer authority from it. Any failed/uncertain update fences the connection; hosts revoke and stop it rather than retrying a possibly applied update.
type HTTPHandler ¶
type HTTPHandler interface {
HTTPHandle(ctx context.Context, req HTTPRequest) (HTTPResponse, error)
}
HTTPHandler is implemented by plugins that service host-registered HTTP routes. The host dispatches http/handle requests here. Streaming is not supported on this path — emit SSE envelopes via command or event results instead.
type HTTPRequest ¶
type HTTPRequest struct {
Context *ForwardContext `json:"context,omitempty"`
Method string `json:"method"`
Path string `json:"path"`
// RawPath preserves optional escaped separators from URL.RawPath.
RawPath string `json:"raw_path,omitempty"`
// RawQuery preserves the encoded query, including repeated and empty values.
RawQuery string `json:"raw_query,omitempty"`
Query map[string]string `json:"query,omitempty"`
Headers map[string]string `json:"headers,omitempty"`
Body []byte `json:"body,omitempty"`
SessionID string `json:"session_id,omitempty"`
// Identity carries the same opaque, host-verified value as the
// other dispatch paths' Identity field (see InitParams.Identity).
// Headers can already carry a raw Authorization header, but that
// forces an HTTPHandler to parse and interpret it itself; Identity
// gives a plugin implementing both HTTPHandler and IdentityAware
// the caller's identity the same pre-verified way regardless of
// which dispatch method delivered the call.
Identity json.RawMessage `json:"identity,omitempty"`
}
HTTPRequest is sent to the plugin for http/handle when a registered plugin route is hit. Streaming is not supported on this path; use SSE envelopes via EventHandleResult instead.
type HTTPResponse ¶
type HTTPResponse struct {
Status int `json:"status"`
Headers map[string]string `json:"headers,omitempty"`
Body []byte `json:"body,omitempty"`
}
HTTPResponse is returned by the plugin for http/handle.
type HealthChecker ¶
type HealthChecker interface {
Health(ctx context.Context) (HealthStatus, error)
}
HealthChecker is implemented by plugins that expose a health endpoint for the host's periodic health check. If not implemented, the host's health probe treats the plugin as healthy-by-default.
type HealthResult ¶
HealthResult is returned by plugin/health.
type HealthStatus ¶
HealthResult mirrors the wire HealthResult but is promoted to the SDK surface so plugin authors never import the wire package directly. Health check payload returned by a plugin's Health method.
type HookErrorData ¶
type HookErrorData struct {
Contract string `json:"contract"`
Code string `json:"code"`
Field *string `json:"field,omitempty"`
}
HookErrorData is the hooks/1 structural refusal contract. It never signals a deliberate veto; those are successful RPC results with structured status.
func (HookErrorData) MarshalJSON ¶
func (v HookErrorData) MarshalJSON() ([]byte, error)
func (*HookErrorData) UnmarshalJSON ¶
func (v *HookErrorData) UnmarshalJSON(b []byte) error
func (HookErrorData) Validate ¶
func (v HookErrorData) Validate() error
type HookFailure ¶
HookFailure is operational failure data, never an engine sentinel.
func (HookFailure) MarshalJSON ¶
func (v HookFailure) MarshalJSON() ([]byte, error)
func (*HookFailure) UnmarshalJSON ¶
func (v *HookFailure) UnmarshalJSON(b []byte) error
func (HookFailure) Validate ¶
func (v HookFailure) Validate() error
type HookHandleBatchParams ¶
type HookHandleBatchParams struct {
Items []HookHandleParams `json:"items"`
}
func DecodeHookHandleBatchParams ¶
func DecodeHookHandleBatchParams(raw []byte) (HookHandleBatchParams, error)
func (HookHandleBatchParams) MarshalJSON ¶
func (v HookHandleBatchParams) MarshalJSON() ([]byte, error)
func (*HookHandleBatchParams) UnmarshalJSON ¶
func (v *HookHandleBatchParams) UnmarshalJSON(b []byte) error
func (HookHandleBatchParams) Validate ¶
func (v HookHandleBatchParams) Validate() error
type HookHandleBatchResult ¶
type HookHandleBatchResult struct {
Items []HookHandleResult `json:"items"`
}
func DecodeHookHandleBatchResult ¶
func DecodeHookHandleBatchResult(raw []byte) (HookHandleBatchResult, error)
func (HookHandleBatchResult) MarshalJSON ¶
func (v HookHandleBatchResult) MarshalJSON() ([]byte, error)
func (*HookHandleBatchResult) UnmarshalJSON ¶
func (v *HookHandleBatchResult) UnmarshalJSON(b []byte) error
func (HookHandleBatchResult) Validate ¶
func (v HookHandleBatchResult) Validate() error
type HookHandleParams ¶
type HookHandleParams struct {
InvocationID string `json:"invocation_id"`
CatalogVersion string `json:"catalog_version"`
Hook string `json:"hook"`
SchemaDigest string `json:"schema_digest"`
Kind string `json:"kind"`
Mode string `json:"mode"`
Scope HookScope `json:"scope"`
Context ForwardContext `json:"context"`
Payload json.RawMessage `json:"payload"`
Metadata map[string]string `json:"metadata"`
Deadline string `json:"deadline"`
AggregateBudgetMS uint32 `json:"aggregate_budget_ms"`
Depth uint32 `json:"depth"`
Trace HookTrace `json:"trace"`
RootInvocationID string `json:"root_invocation_id"`
ParentInvocationID *string `json:"parent_invocation_id,omitempty"`
}
func DecodeHookHandleParams ¶
func DecodeHookHandleParams(raw []byte) (HookHandleParams, error)
func (HookHandleParams) MarshalJSON ¶
func (v HookHandleParams) MarshalJSON() ([]byte, error)
func (*HookHandleParams) UnmarshalJSON ¶
func (v *HookHandleParams) UnmarshalJSON(b []byte) error
func (HookHandleParams) Validate ¶
func (v HookHandleParams) Validate() error
type HookHandleResult ¶
type HookHandleResult struct {
InvocationID string `json:"invocation_id"`
Status string `json:"status"`
Payload json.RawMessage `json:"payload,omitempty"`
Reason *string `json:"reason,omitempty"`
Error *HookFailure `json:"error,omitempty"`
}
HookHandleResult is flat on the wire. ValidateHookResultFor enforces its status branch and correlation with the originating request.
func DecodeHookHandleResult ¶
func DecodeHookHandleResult(raw []byte) (HookHandleResult, error)
func (HookHandleResult) MarshalJSON ¶
func (v HookHandleResult) MarshalJSON() ([]byte, error)
func (*HookHandleResult) UnmarshalJSON ¶
func (v *HookHandleResult) UnmarshalJSON(b []byte) error
func (HookHandleResult) Validate ¶
func (v HookHandleResult) Validate() error
type HookHandler ¶
type HookHandler interface {
HookHandle(context.Context, HookHandleParams) (HookHandleResult, error)
}
HookHandler opts into hooks/1 when the host offers it during Init. Hook calls receive no host client; reverse callbacks are negotiated separately.
type HookScope ¶
type HookScope struct {
Incarnation capability.RuntimeIdentity `json:"incarnation"`
RegistrationID string `json:"registration_id"`
}
HookScope carries host-issued metadata, not authority. Hosts fence the live registration and binding; the SDK checks only structure and incarnation.
func (HookScope) MarshalJSON ¶
func (*HookScope) UnmarshalJSON ¶
type HookTrace ¶
type HookTrace struct {
TraceID string `json:"trace_id"`
SpanID string `json:"span_id"`
ParentSpanID *string `json:"parent_span_id,omitempty"`
}
func (HookTrace) MarshalJSON ¶
func (*HookTrace) UnmarshalJSON ¶
type HookValidationError ¶
type HookValidationError struct{ Field, Reason string }
HookValidationError contains safe field metadata, never rejected values.
func (*HookValidationError) Error ¶
func (e *HookValidationError) Error() string
type HooksProfile ¶
type HooksProfile struct {
HooksProfileVersion int `json:"hooks_profile_version"`
}
HooksProfile offers the independent hooks protocol. Serve requires HookHandler to acknowledge it.
func (*HooksProfile) UnmarshalJSON ¶
func (h *HooksProfile) UnmarshalJSON(data []byte) error
type HostClient ¶
type HostClient struct {
// contains filtered or unexported fields
}
HostClient is an SDK-owned request-scoped client. Authors obtain it from HostClientFromContext, never implement it or construct it. Later service methods may be added to this same type. Production availability requires negotiated reverse opt-in.
func HostClientFromContext ¶
func HostClientFromContext(ctx context.Context) (*HostClient, bool)
HostClientFromContext is unavailable in base and hooks-only connections. A cached client never grants a new request or connection any authority.
func (*HostClient) BindingsRenew ¶
func (h *HostClient) BindingsRenew(ctx context.Context, a BindingsRenewArgs) (r BindingsRenewResult, err error)
func (*HostClient) EgressRequest ¶
func (h *HostClient) EgressRequest(ctx context.Context, a EgressRequestArgs) (r EgressRequestResult, err error)
func (*HostClient) EventsPublish ¶
func (h *HostClient) EventsPublish(ctx context.Context, a EventsPublishArgs) (r EventsPublishResult, err error)
func (*HostClient) Log ¶
func (h *HostClient) Log(ctx context.Context, a HostLogArgs) (r LogResult, err error)
func (*HostClient) MCPCallTool ¶
func (h *HostClient) MCPCallTool(ctx context.Context, a MCPCallToolArgs) (*MCPToolCall, error)
func (*HostClient) MCPCancelCall ¶
func (h *HostClient) MCPCancelCall(ctx context.Context, a MCPCancelCallArgs) (r MCPCancelCallResult, err error)
func (*HostClient) MCPListTools ¶
func (h *HostClient) MCPListTools(ctx context.Context, a MCPListToolsArgs) (r MCPListToolsResult, err error)
func (*HostClient) ReadonlyQuery ¶
func (h *HostClient) ReadonlyQuery(ctx context.Context, a ReadonlyQueryArgs) (r ReadonlyQueryResult, err error)
func (*HostClient) SecretsGet ¶
func (h *HostClient) SecretsGet(ctx context.Context, a SecretsGetArgs) (SecretValue, error)
func (*HostClient) StorageDelete ¶
func (h *HostClient) StorageDelete(ctx context.Context, a StorageDeleteArgs) (r StorageDeleteResult, err error)
func (*HostClient) StorageGet ¶
func (h *HostClient) StorageGet(ctx context.Context, a StorageGetArgs) (r StorageGetResult, err error)
func (*HostClient) StoragePut ¶
func (h *HostClient) StoragePut(ctx context.Context, a StoragePutArgs) (r StoragePutResult, err error)
type HostLogArgs ¶
type HostLogArgs struct {
GrantID, Level, Message string
Fields *[]HostRPCLogField
}
type HostRPCError ¶
type HostRPCError struct {
Code int `json:"code"`
Message string `json:"message"`
Data HostRPCErrorData `json:"data"`
}
HostRPCError is the bounded application failure, distinct from InitError. Hosts supply safe messages; the SDK never constructs one from backend errors.
func (HostRPCError) Error ¶
func (v HostRPCError) Error() string
func (HostRPCError) MarshalJSON ¶
func (v HostRPCError) MarshalJSON() ([]byte, error)
func (*HostRPCError) UnmarshalJSON ¶
func (v *HostRPCError) UnmarshalJSON(data []byte) error
func (HostRPCError) Validate ¶
func (v HostRPCError) Validate() error
type HostRPCErrorData ¶
type HostRPCErrorData capability.RPCErrorData
HostRPCErrorData uses the capability leaf's exact field types and vocabulary. Its transport codec adds closed-object/raw-token checks before leaf validation.
func (HostRPCErrorData) MarshalJSON ¶
func (v HostRPCErrorData) MarshalJSON() ([]byte, error)
func (*HostRPCErrorData) UnmarshalJSON ¶
func (v *HostRPCErrorData) UnmarshalJSON(data []byte) error
func (HostRPCErrorData) Validate ¶
func (v HostRPCErrorData) Validate() error
type HostRPCHeader ¶
func (HostRPCHeader) MarshalJSON ¶
func (v HostRPCHeader) MarshalJSON() ([]byte, error)
func (*HostRPCHeader) UnmarshalJSON ¶
func (v *HostRPCHeader) UnmarshalJSON(data []byte) error
func (HostRPCHeader) Validate ¶
func (v HostRPCHeader) Validate() error
type HostRPCLogField ¶
type HostRPCLogField struct {
Name string `json:"name"`
Value json.RawMessage `json:"value"`
}
func (HostRPCLogField) MarshalJSON ¶
func (v HostRPCLogField) MarshalJSON() ([]byte, error)
func (*HostRPCLogField) UnmarshalJSON ¶
func (v *HostRPCLogField) UnmarshalJSON(data []byte) error
func (HostRPCLogField) Validate ¶
func (v HostRPCLogField) Validate() error
type HostRPCRemainingBudgets ¶
type HostRPCRemainingBudgets struct {
TimeoutMS uint32 `json:"timeout_ms"`
Bytes *uint64 `json:"bytes,omitempty"`
Effects *uint64 `json:"effects,omitempty"`
Tokens *uint64 `json:"tokens,omitempty"`
}
func (HostRPCRemainingBudgets) MarshalJSON ¶
func (v HostRPCRemainingBudgets) MarshalJSON() ([]byte, error)
func (*HostRPCRemainingBudgets) UnmarshalJSON ¶
func (v *HostRPCRemainingBudgets) UnmarshalJSON(data []byte) error
func (HostRPCRemainingBudgets) Validate ¶
func (v HostRPCRemainingBudgets) Validate() error
type HostRPCRequestOwner ¶
type HostRPCRequestOwner string
HostRPCRequestOwner identifies the initiating direction in the host ledger.
const ( HostRPCOwnerHost HostRPCRequestOwner = "host" HostRPCOwnerPlugin HostRPCRequestOwner = "plugin" )
type HostRPCValidationError ¶
type HostRPCValidationError struct{ Field, Reason string }
HostRPCValidationError contains safe field metadata, never rejected values. It is a structural failure; RPC adapters decide whether to emit -32602.
func (*HostRPCValidationError) Error ¶
func (e *HostRPCValidationError) Error() string
type HostServiceLimits ¶
type HostServiceLimits struct {
HostToPluginInflight uint32 `json:"host_to_plugin_inflight"`
PluginToHostInflight uint32 `json:"plugin_to_host_inflight"`
HostGlobalInflight uint32 `json:"host_global_inflight"`
ControlSlots uint32 `json:"control_slots"`
MaxFrameBytes uint32 `json:"max_frame_bytes"`
MaxQueuedWriteBytes uint32 `json:"max_queued_write_bytes"`
WriteTimeoutMS uint32 `json:"write_timeout_ms"`
MaxDepth uint32 `json:"max_depth"`
MethodTimeoutMS map[string]uint32 `json:"method_timeout_ms"`
}
type HostServices ¶
type HostServices struct {
ReverseRPCVersion int `json:"reverse_rpc_version"`
Incarnation capability.RuntimeIdentity `json:"incarnation"`
Methods []string `json:"methods"`
Limits HostServiceLimits `json:"limits"`
}
HostServices is an availability offer, never an authorization grant.
func (*HostServices) UnmarshalJSON ¶
func (h *HostServices) UnmarshalJSON(data []byte) error
func (HostServices) Validate ¶
func (h HostServices) Validate() error
type IdentityAware ¶
type IdentityAware interface {
Identity(ctx context.Context, identity json.RawMessage)
}
IdentityAware is implemented by plugins that want to be told the opaque identity value a host has already verified for the current caller. plugin-sdk never parses, validates, or picks a token scheme for this value — it is a courier, not an authority; verification happens entirely on the host side.
Serve calls Identity once after a successful Init when InitParams.Identity is non-empty (the connection-level identity for this subprocess), and again before each Command/EventHandle/ MCPCallTool/HTTPHandle dispatch whose own request carries a non-empty Identity — a single inprocess-mode subprocess can still serve calls on behalf of different verified callers over its lifetime, so a per-call Identity is not assumed to match Init's. Serve never calls Identity with an empty value: a plugin that implements IdentityAware but whose host never populates Identity sees no calls at all.
A plugin that doesn't implement IdentityAware is completely unaffected — the Identity field remains directly readable off CommandRequest / EventRequest / MCPCallRequest / HTTPRequest for a plugin that would rather inspect it inline instead.
type InitError ¶
type InitError struct {
Code InitFailureCode
Field string
Expected, Received int
}
InitError is structural handshake failure, not a host application error. It excludes rejected values and is available to errors.As callers.
type InitFailureCode ¶
type InitFailureCode string
const ( InitInvalid InitFailureCode = "invalid_init" InitProtocolMismatch InitFailureCode = "protocol_mismatch" InitCapabilityContractMismatch InitFailureCode = "capability_contract_mismatch" InitProfileMismatch InitFailureCode = "profile_mismatch" )
type InitParams ¶
type InitParams struct {
Context *ForwardContext `json:"context,omitempty"`
PluginDir string `json:"plugin_dir"`
DataDir string `json:"data_dir"`
CacheDir string `json:"cache_dir"`
Config map[string]string `json:"config"`
LogLevel string `json:"log_level"`
HostInfo HostInfo `json:"host_info"`
CapabilityContract int `json:"capability_contract"`
Incarnation capability.RuntimeIdentity `json:"incarnation"`
Grants capability.GrantSet `json:"grants"`
GrantsRenewalVersion *int `json:"grants_renewal_version,omitempty"`
// Identity is an optional opaque verified courier, never incarnation identity
// or an implicit initiating caller for subsequent requests.
Identity json.RawMessage `json:"identity,omitempty"`
HostServices *HostServices `json:"host_services,omitempty"`
HooksProfile *HooksProfile `json:"hooks_profile,omitempty"`
}
InitParams is sent by the host during plugin/init.
func (*InitParams) HasCapability ¶
func (p *InitParams) HasCapability(name string) bool
HasCapability is discovery-only: false means no grant with this name. A present grant still requires current host authorization at execution time.
func (InitParams) MarshalJSON ¶
func (p InitParams) MarshalJSON() ([]byte, error)
func (*InitParams) ResolvedCacheDir ¶
func (p *InitParams) ResolvedCacheDir() (string, error)
ResolvedCacheDir returns the host-provided CacheDir. If the host did not populate it, it falls back to os.TempDir(). The returned error is currently always nil; the signature returns error to allow future validation without breaking callers.
func (*InitParams) ResolvedDataDir ¶
func (p *InitParams) ResolvedDataDir() (string, error)
ResolvedDataDir returns the host-provided DataDir, or ErrNoDataDir if the host did not populate it. Plugins should treat an error here as fatal for any persistence path; there is no safe fallback for data.
func (*InitParams) UnmarshalJSON ¶
func (p *InitParams) UnmarshalJSON(data []byte) error
func (InitParams) Validate ¶
func (p InitParams) Validate() error
type InitResult ¶
type InitResult struct {
ID string `json:"id"`
Name string `json:"name"`
Version string `json:"version"`
Description string `json:"description"`
Protocol int `json:"protocol"`
CapabilityContract int `json:"capability_contract"`
GrantsRenewalVersion *int `json:"grants_renewal_version,omitempty"`
ReverseRPCVersion *int `json:"reverse_rpc_version,omitempty"`
HooksProfileVersion *int `json:"hooks_profile_version,omitempty"`
}
InitResult acknowledges the base contract and any selected optional profiles. Serve owns acknowledgements: hooks requires an offer/handler, reverse an offer/opt-in.
func (InitResult) MarshalJSON ¶
func (r InitResult) MarshalJSON() ([]byte, error)
func (*InitResult) UnmarshalJSON ¶
func (r *InitResult) UnmarshalJSON(data []byte) error
func (InitResult) Validate ¶
func (r InitResult) Validate() error
type LoadParams ¶
type LoadParams struct {
Context *ForwardContext `json:"context,omitempty"`
}
LoadParams is sent by the host during plugin/load (currently empty, reserved).
type LoadResult ¶
type LoadResult struct {
// SkippedRegistrations lists any declared registrations the plugin
// explicitly declined at load time. Informational — the host does
// NOT fall back to yaml-only for these; it logs and proceeds.
SkippedRegistrations []SkippedRegistration `json:"skipped_registrations,omitempty"`
}
LoadResult is the plugin's acknowledgement of plugin/load. As of v0.2.0, declarative registrations (commands, slots, components, keybindings, config schema, event subscriptions, CRUD resources) are yaml-authoritative — the host reads them from plugin.yaml and applies them directly. Plugins no longer return these fields at runtime.
The only payload a plugin may return is SkippedRegistrations — a list of yaml-declared registrations the plugin declines at load time (e.g. a command that depends on optional config the plugin couldn't resolve). The host logs these and proceeds without the skipped registrations; there is no yaml fallback path.
type LogParams ¶
type LogParams struct {
GrantID string `json:"grant_id"`
Context ReverseContext `json:"context"`
Level string `json:"level"`
Message string `json:"message"`
Fields *[]HostRPCLogField `json:"fields,omitempty"`
}
func (LogParams) MarshalJSON ¶
func (*LogParams) UnmarshalJSON ¶
type LogResult ¶
type LogResult struct {
Accepted bool `json:"accepted"`
}
func (LogResult) MarshalJSON ¶
func (*LogResult) UnmarshalJSON ¶
type MCPCallRequest ¶
type MCPCallRequest struct {
Context *ForwardContext `json:"context,omitempty"`
ToolName string `json:"tool_name"`
Arguments map[string]interface{} `json:"arguments"`
SessionID string `json:"session_id,omitempty"`
// Identity is an opaque, host-verified identity value for this
// call. See InitParams.Identity.
Identity json.RawMessage `json:"identity,omitempty"`
}
MCPCallRequest is sent to the plugin for mcp/call_tool when a tool provided by the plugin is invoked.
func (MCPCallRequest) MarshalJSON ¶
func (p MCPCallRequest) MarshalJSON() ([]byte, error)
MarshalJSON emits the required tool arguments object for a nil map.
type MCPCallResult ¶
type MCPCallResult struct {
// Content is the tool's structured or textual output, JSON-encoded.
Content json.RawMessage `json:"content"`
// IsError signals the tool returned a user-visible error (not an
// RPC-level error — use the standard RPC error for transport issues).
IsError bool `json:"is_error,omitempty"`
// Envelopes emitted alongside the tool result.
Envelopes []plugin.EnvelopeOut `json:"envelopes,omitempty"`
}
MCPCallResult is returned by the plugin for mcp/call_tool.
type MCPCallToolArgs ¶
type MCPCallToolArgs struct {
GrantID, ServerID, ToolName, ToolBinding string
Arguments json.RawMessage
OperationKey *string
}
type MCPCallToolParams ¶
type MCPCallToolParams struct {
GrantID string `json:"grant_id"`
Context ReverseContext `json:"context"`
ServerID string `json:"server_id"`
ToolName string `json:"tool_name"`
ToolBinding string `json:"tool_binding"`
Arguments json.RawMessage `json:"arguments"`
OperationKey *string `json:"operation_key,omitempty"`
}
func (MCPCallToolParams) MarshalJSON ¶
func (v MCPCallToolParams) MarshalJSON() ([]byte, error)
func (*MCPCallToolParams) UnmarshalJSON ¶
func (v *MCPCallToolParams) UnmarshalJSON(data []byte) error
func (MCPCallToolParams) Validate ¶
func (v MCPCallToolParams) Validate() error
type MCPCallToolResult ¶
type MCPCallToolResult struct {
Content []json.RawMessage `json:"content"`
IsError bool `json:"is_error"`
StructuredContent json.RawMessage `json:"structured_content,omitempty"`
OperationKey *string `json:"operation_key,omitempty"`
}
func (MCPCallToolResult) MarshalJSON ¶
func (v MCPCallToolResult) MarshalJSON() ([]byte, error)
func (*MCPCallToolResult) UnmarshalJSON ¶
func (v *MCPCallToolResult) UnmarshalJSON(data []byte) error
func (MCPCallToolResult) Validate ¶
func (v MCPCallToolResult) Validate() error
type MCPCancelCallArgs ¶
type MCPCancelCallArgs struct {
GrantID string
Call *MCPToolCall
}
type MCPCancelCallParams ¶
type MCPCancelCallParams struct {
GrantID string `json:"grant_id"`
Context ReverseContext `json:"context"`
TargetCallID uint64 `json:"target_call_id"`
}
func (MCPCancelCallParams) MarshalJSON ¶
func (v MCPCancelCallParams) MarshalJSON() ([]byte, error)
func (*MCPCancelCallParams) UnmarshalJSON ¶
func (v *MCPCancelCallParams) UnmarshalJSON(data []byte) error
func (MCPCancelCallParams) Validate ¶
func (v MCPCancelCallParams) Validate() error
type MCPCancelCallResult ¶
type MCPCancelCallResult struct {
Accepted bool `json:"accepted"`
AlreadyTerminal bool `json:"already_terminal"`
}
func (MCPCancelCallResult) MarshalJSON ¶
func (v MCPCancelCallResult) MarshalJSON() ([]byte, error)
func (*MCPCancelCallResult) UnmarshalJSON ¶
func (v *MCPCancelCallResult) UnmarshalJSON(data []byte) error
func (MCPCancelCallResult) Validate ¶
func (v MCPCancelCallResult) Validate() error
type MCPHandler ¶
type MCPHandler interface {
MCPCallTool(ctx context.Context, req MCPCallRequest) (MCPCallResult, error)
}
MCPHandler is implemented by plugins that expose MCP tools. The host dispatches mcp/call_tool requests here when a tool registered via plugin.yaml is invoked. Tool registration itself is declarative; the handler services runtime invocations only.
type MCPListToolsArgs ¶
type MCPListToolsParams ¶
type MCPListToolsParams struct {
GrantID string `json:"grant_id"`
Context ReverseContext `json:"context"`
ServerID string `json:"server_id"`
Cursor *string `json:"cursor,omitempty"`
}
func (MCPListToolsParams) MarshalJSON ¶
func (v MCPListToolsParams) MarshalJSON() ([]byte, error)
func (*MCPListToolsParams) UnmarshalJSON ¶
func (v *MCPListToolsParams) UnmarshalJSON(data []byte) error
func (MCPListToolsParams) Validate ¶
func (v MCPListToolsParams) Validate() error
type MCPListToolsResult ¶
type MCPListToolsResult struct {
ServerID string `json:"server_id"`
Tools []MCPTool `json:"tools"`
NextCursor *string `json:"next_cursor,omitempty"`
}
func (MCPListToolsResult) MarshalJSON ¶
func (v MCPListToolsResult) MarshalJSON() ([]byte, error)
func (*MCPListToolsResult) UnmarshalJSON ¶
func (v *MCPListToolsResult) UnmarshalJSON(data []byte) error
func (MCPListToolsResult) Validate ¶
func (v MCPListToolsResult) Validate() error
type MCPTool ¶
type MCPTool struct {
ToolName string `json:"tool_name"`
Description *string `json:"description,omitempty"`
InputSchema json.RawMessage `json:"input_schema"`
OutputSchema json.RawMessage `json:"output_schema,omitempty"`
Effect string `json:"effect"`
ToolBinding string `json:"tool_binding"`
}
MCPTool metadata and tool_binding are issued and pinned by the host.
func (MCPTool) MarshalJSON ¶
func (*MCPTool) UnmarshalJSON ¶
type MCPToolCall ¶
type MCPToolCall struct {
// contains filtered or unexported fields
}
MCPToolCall is SDK-owned. Start with MCPCallTool, then Wait(ctx); no public ID.
func (*MCPToolCall) Wait ¶
func (c *MCPToolCall) Wait(ctx context.Context) (MCPCallToolResult, error)
Wait's context narrows waiting only; the start context owns call lifetime. Use MCPCancelCall for acknowledged host cancellation.
type MigrateParams ¶
type MigrateParams struct {
Context *ForwardContext `json:"context,omitempty"`
FromVersion string `json:"from_version"` // installed manifest version
ToVersion string `json:"to_version"` // target manifest version
DataDir string `json:"data_dir"` // convenience — same value passed via InitParams
}
MigrateParams is sent to the plugin for plugin/migrate when the installed manifest version differs from the declared version.
type MigrateResult ¶
type MigrateResult struct {
Notes []string `json:"notes,omitempty"` // optional migration log for the host to surface
}
MigrateResult is returned by the plugin for plugin/migrate. An empty result is equivalent to "no-op migration succeeded". Plugins that don't implement migration should return an empty MigrateResult.
type Migrator ¶
Migrator is implemented by plugins that need to run schema migrations on version upgrades. The host calls Migrate before Load when the on-disk version differs from the installed version. Returning a nil error is equivalent to a no-op migration.
type ParentCall ¶
type ParentCall struct {
RequestOwner HostRPCRequestOwner `json:"request_owner"`
ID uint64 `json:"id"`
}
func (ParentCall) MarshalJSON ¶
func (v ParentCall) MarshalJSON() ([]byte, error)
func (*ParentCall) UnmarshalJSON ¶
func (v *ParentCall) UnmarshalJSON(data []byte) error
func (ParentCall) Validate ¶
func (v ParentCall) Validate() error
type Plugin ¶
type Plugin interface {
Init(ctx context.Context, params InitParams) (InitResult, error)
Load(ctx context.Context) (LoadResult, error)
Unload(ctx context.Context) error
}
Plugin is the minimum contract a subprocess plugin must satisfy. Metadata (ID/Name/Version/Description/Protocol) is returned by Init rather than by separate getter methods to keep the subprocess plugin shape distinct from the in-process plugin.Plugin interface.
type PluginRPCErrorData ¶
type PluginRPCErrorData struct {
Contract string `json:"contract"`
Code capability.Code `json:"code"`
EffectState capability.EffectState `json:"effect_state"`
Retryable bool `json:"retryable"`
}
PluginRPCErrorData is a closed base-domain transport failure. The enclosing RPCID supplies correlation; no positive request_id is fabricated.
func (PluginRPCErrorData) MarshalJSON ¶
func (v PluginRPCErrorData) MarshalJSON() ([]byte, error)
func (*PluginRPCErrorData) UnmarshalJSON ¶
func (v *PluginRPCErrorData) UnmarshalJSON(b []byte) error
type QueueLimits ¶
type QueueLimits struct{ Frames, Bytes int }
QueueLimits narrow each independent writer lane. Queued bytes can reach twice Bytes, plus one in-progress frame bounded by FrameLimits.OutputBytes.
type RPCError ¶
type RPCError struct {
Code int `json:"code"`
Message string `json:"message"`
Data any `json:"data,omitempty"`
}
RPCError is a JSON-RPC 2.0 error object.
func HookRPCError ¶
HookRPCError maps structural/lifecycle errors to standard JSON-RPC codes. It does not map engine sentinels, backend text, -32003 or -32010 to a veto.
type RPCID ¶
type RPCID struct {
// contains filtered or unexported fields
}
RPCID is a string or a JavaScript-safe integer. Its zero value denotes an absent request ID, or the null ID of an error response. NumberID(0) is a request ID, not a notification. Decoding never rounds numeric IDs.
func (RPCID) MarshalJSON ¶
func (*RPCID) UnmarshalJSON ¶
type RPCRequest ¶
type RPCRequest struct {
JSONRPC string `json:"jsonrpc"`
ID RPCID `json:"id,omitempty"` // zero value for notifications
Method string `json:"method"`
Params any `json:"params,omitempty"`
}
RPCRequest is a JSON-RPC 2.0 request sent from host to plugin.
func (RPCRequest) MarshalJSON ¶
func (r RPCRequest) MarshalJSON() ([]byte, error)
MarshalJSON omits only an absent ID; numeric zero and empty strings survive.
func (*RPCRequest) UnmarshalJSON ¶
func (r *RPCRequest) UnmarshalJSON(data []byte) error
type RPCResponse ¶
type RPCResponse struct {
JSONRPC string `json:"jsonrpc"`
ID RPCID `json:"id"`
Result json.RawMessage `json:"result,omitempty"`
Error *RPCError `json:"error,omitempty"`
}
RPCResponse is a JSON-RPC 2.0 response from plugin to host.
type RPCTransportError ¶
type RPCTransportError struct {
Failure capability.Error
// contains filtered or unexported fields
}
RPCTransportError retains safe classification separately from the local cause. Helpers serialize Failure only; a transport never copies Cause into wire data.
func (*RPCTransportError) Error ¶
func (e *RPCTransportError) Error() string
func (*RPCTransportError) Unwrap ¶
func (e *RPCTransportError) Unwrap() error
type ReadonlyQueryArgs ¶
type ReadonlyQueryArgs struct {
GrantID, Resource string
SchemaVersion uint32
Params json.RawMessage
}
type ReadonlyQueryParams ¶
type ReadonlyQueryParams struct {
GrantID string `json:"grant_id"`
Context ReverseContext `json:"context"`
Resource string `json:"resource"`
SchemaVersion uint32 `json:"schema_version"`
Params json.RawMessage `json:"params"`
}
func (ReadonlyQueryParams) MarshalJSON ¶
func (v ReadonlyQueryParams) MarshalJSON() ([]byte, error)
func (*ReadonlyQueryParams) UnmarshalJSON ¶
func (v *ReadonlyQueryParams) UnmarshalJSON(data []byte) error
func (ReadonlyQueryParams) Validate ¶
func (v ReadonlyQueryParams) Validate() error
type ReadonlyQueryResult ¶
type ReadonlyQueryResult struct {
Resource string `json:"resource"`
SchemaVersion uint32 `json:"schema_version"`
Data json.RawMessage `json:"data"`
}
func (ReadonlyQueryResult) MarshalJSON ¶
func (v ReadonlyQueryResult) MarshalJSON() ([]byte, error)
func (*ReadonlyQueryResult) UnmarshalJSON ¶
func (v *ReadonlyQueryResult) UnmarshalJSON(data []byte) error
func (ReadonlyQueryResult) Validate ¶
func (v ReadonlyQueryResult) Validate() error
type ReverseContext ¶
type ReverseContext struct {
BindingID BindingID `json:"binding_id"`
TimeoutMS uint32 `json:"timeout_ms"`
ParentCall ParentCall `json:"parent_call"`
}
func (ReverseContext) MarshalJSON ¶
func (v ReverseContext) MarshalJSON() ([]byte, error)
func (*ReverseContext) UnmarshalJSON ¶
func (v *ReverseContext) UnmarshalJSON(data []byte) error
func (ReverseContext) Validate ¶
func (v ReverseContext) Validate() error
type SecretValue ¶
SecretValue is an owned byte copy, registered for SDK redaction before return. ExpiresAt is host metadata, not a local cache renewal or permission grant.
type SecretsGetArgs ¶
type SecretsGetArgs struct{ GrantID, SecretRef string }
type SecretsGetParams ¶
type SecretsGetParams struct {
GrantID string `json:"grant_id"`
Context ReverseContext `json:"context"`
SecretRef string `json:"secret_ref"`
}
func (SecretsGetParams) MarshalJSON ¶
func (v SecretsGetParams) MarshalJSON() ([]byte, error)
func (*SecretsGetParams) UnmarshalJSON ¶
func (v *SecretsGetParams) UnmarshalJSON(data []byte) error
func (SecretsGetParams) Validate ¶
func (v SecretsGetParams) Validate() error
type SecretsGetResult ¶
type SecretsGetResult struct {
ValueBase64 string `json:"value_base64"`
ExpiresAt string `json:"expires_at"`
}
func (SecretsGetResult) MarshalJSON ¶
func (v SecretsGetResult) MarshalJSON() ([]byte, error)
func (*SecretsGetResult) UnmarshalJSON ¶
func (v *SecretsGetResult) UnmarshalJSON(data []byte) error
func (SecretsGetResult) Validate ¶
func (v SecretsGetResult) Validate() error
type ServeOptions ¶
type ServeOptions struct {
// ReverseRPC explicitly opts into a valid offered reverse/1 profile.
ReverseRPC bool
Input io.Reader
Output io.Writer
Context context.Context
ShutdownTimeout time.Duration
FrameLimits FrameLimits
QueueLimits QueueLimits
AdmissionLimits AdmissionLimits
WriteTimeout time.Duration
}
ServeOptions controls one connection. Zero values select stdin/stdout, background context and DefaultShutdownTimeout. Injected I/O remains owned by the caller: close it to release any Read/Write still blocked after shutdown. Serve cannot interrupt arbitrary injected I/O or kill callback goroutines.
type SkippedRegistration ¶
type SkippedRegistration struct {
// Kind identifies the registration category, e.g. "command",
// "slot", "component", "keybinding", "event", "crud", "mcp_server".
Kind string `json:"kind"`
// ID is the registration identifier from plugin.yaml.
ID string `json:"id"`
// Reason is a human-readable cause, surfaced in host logs.
Reason string `json:"reason"`
}
SkippedRegistration is a runtime opt-out for a yaml-declared registration.
type StorageDeleteArgs ¶
type StorageDeleteArgs struct{ GrantID, Key, ExpectedRevision, OperationKey string }
type StorageDeleteParams ¶
type StorageDeleteParams struct {
GrantID string `json:"grant_id"`
Context ReverseContext `json:"context"`
Key string `json:"key"`
ExpectedRevision string `json:"expected_revision"`
OperationKey string `json:"operation_key"`
}
func (StorageDeleteParams) MarshalJSON ¶
func (v StorageDeleteParams) MarshalJSON() ([]byte, error)
func (*StorageDeleteParams) UnmarshalJSON ¶
func (v *StorageDeleteParams) UnmarshalJSON(data []byte) error
func (StorageDeleteParams) Validate ¶
func (v StorageDeleteParams) Validate() error
type StorageDeleteResult ¶
type StorageDeleteResult struct {
OperationKey string `json:"operation_key"`
Deleted bool `json:"deleted"`
Revision string `json:"revision"`
}
func (StorageDeleteResult) MarshalJSON ¶
func (v StorageDeleteResult) MarshalJSON() ([]byte, error)
func (*StorageDeleteResult) UnmarshalJSON ¶
func (v *StorageDeleteResult) UnmarshalJSON(data []byte) error
func (StorageDeleteResult) Validate ¶
func (v StorageDeleteResult) Validate() error
type StorageGetArgs ¶
type StorageGetArgs struct{ GrantID, Key string }
Helper arguments contain only explicit grant selection and business input. Existing Params DTOs remain the single wire contract.
type StorageGetParams ¶
type StorageGetParams struct {
GrantID string `json:"grant_id"`
Context ReverseContext `json:"context"`
Key string `json:"key"`
}
func (StorageGetParams) MarshalJSON ¶
func (v StorageGetParams) MarshalJSON() ([]byte, error)
func (*StorageGetParams) UnmarshalJSON ¶
func (v *StorageGetParams) UnmarshalJSON(data []byte) error
func (StorageGetParams) Validate ¶
func (v StorageGetParams) Validate() error
type StorageGetResult ¶
type StorageGetResult struct {
Found bool `json:"found"`
Value json.RawMessage `json:"value,omitempty"`
Revision *string `json:"revision,omitempty"`
}
func (StorageGetResult) MarshalJSON ¶
func (v StorageGetResult) MarshalJSON() ([]byte, error)
func (*StorageGetResult) UnmarshalJSON ¶
func (v *StorageGetResult) UnmarshalJSON(data []byte) error
func (StorageGetResult) Validate ¶
func (v StorageGetResult) Validate() error
type StoragePutArgs ¶
type StoragePutArgs struct {
GrantID, Key string
Value json.RawMessage
ExpectedRevision *string
OperationKey string
}
type StoragePutParams ¶
type StoragePutParams struct {
GrantID string `json:"grant_id"`
Context ReverseContext `json:"context"`
Key string `json:"key"`
Value json.RawMessage `json:"value"`
ExpectedRevision *string `json:"expected_revision"`
OperationKey string `json:"operation_key"`
}
func (StoragePutParams) MarshalJSON ¶
func (v StoragePutParams) MarshalJSON() ([]byte, error)
func (*StoragePutParams) UnmarshalJSON ¶
func (v *StoragePutParams) UnmarshalJSON(data []byte) error
func (StoragePutParams) Validate ¶
func (v StoragePutParams) Validate() error
type StoragePutResult ¶
type StoragePutResult struct {
OperationKey string `json:"operation_key"`
Revision string `json:"revision"`
}
func (StoragePutResult) MarshalJSON ¶
func (v StoragePutResult) MarshalJSON() ([]byte, error)
func (*StoragePutResult) UnmarshalJSON ¶
func (v *StoragePutResult) UnmarshalJSON(data []byte) error
func (StoragePutResult) Validate ¶
func (v StoragePutResult) Validate() error
type TransportCancelledError ¶
type TransportCancelledError struct{ Reason CancelReason }
RPC transport cancellation is distinct from the hook-veto sentinel.
func (*TransportCancelledError) Error ¶
func (e *TransportCancelledError) Error() string
Source Files
¶
- admission.go
- admission_limits.go
- capability.go
- config.go
- correlation.go
- data.go
- envelope.go
- frame_encode.go
- framing.go
- grants_renewal.go
- hooks_dispatch.go
- hooks_errors.go
- hooks_types.go
- hooks_validate.go
- host_client.go
- host_client_lease.go
- host_client_mcp.go
- hostrpc_errors.go
- hostrpc_types.go
- hostrpc_validate.go
- init_contract.go
- log.go
- log_redaction.go
- negotiation.go
- payload.go
- protocol.go
- publication.go
- publication_cancel.go
- request_control.go
- request_deadline.go
- runtime.go
- server.go
- types.go
- types_sdk.go
Directories
¶
| Path | Synopsis |
|---|---|
|
Package subprocesstest provides an in-process test harness for subprocess plugins.
|
Package subprocesstest provides an in-process test harness for subprocess plugins. |