Documentation
¶
Overview ¶
Package message defines JSON-RPC 2.0 message types.
Index ¶
- Constants
- func ErrorCodeName(code int) string
- func IsJSONRPC(data []byte) bool
- type Error
- func ErrAgentAlreadyRunning(agentType string) *Error
- func ErrAgentError(agentType, message string) *Error
- func ErrAgentNotConfigured(agentType string) *Error
- func ErrAgentNotRunning(agentType string) *Error
- func ErrClaudeAlreadyRunning() *Error
- func ErrClaudeError(message string) *Error
- func ErrClaudeNotRunning() *Error
- func ErrFileNotFound(path string) *Error
- func ErrFileTooLarge(path string, size, maxSize int64) *Error
- func ErrGitOperationFailed(operation, message string) *Error
- func ErrInternalError(message string) *Error
- func ErrInvalidParams(message string) *Error
- func ErrInvalidRequest(message string) *Error
- func ErrMethodNotFound(method string) *Error
- func ErrNotAGitRepo() *Error
- func ErrParseError(message string) *Error
- func ErrPathTraversal(path string) *Error
- func ErrSessionNotFound(sessionID string) *Error
- func NewError(code int, message string) *Error
- func NewErrorWithData(code int, message string, data interface{}) *Error
- type ID
- type Notification
- type Request
- type Response
Constants ¶
const ( // ParseError indicates invalid JSON was received. ParseError = -32700 // InvalidRequest indicates the JSON is not a valid Request object. InvalidRequest = -32600 // MethodNotFound indicates the method does not exist. MethodNotFound = -32601 // InvalidParams indicates invalid method parameters. InvalidParams = -32602 // InternalError indicates an internal JSON-RPC error. InternalError = -32603 )
Standard JSON-RPC 2.0 error codes.
const ( // Agent errors (generic for any AI CLI) AgentAlreadyRunning = -32001 AgentNotRunning = -32002 AgentError = -32003 AgentNotConfigured = -32004 // Legacy aliases for backward compatibility ClaudeAlreadyRunning = AgentAlreadyRunning ClaudeNotRunning = AgentNotRunning ClaudeError = AgentError // Session errors SessionNotFound = -32010 SessionInvalid = -32011 // File errors FileNotFound = -32020 FileTooLarge = -32021 PathTraversal = -32022 FileReadError = -32023 DirectoryNotFound = -32024 // Git errors NotAGitRepo = -32030 GitOperationFailed = -32031 GitConflict = -32032 // Repository errors IndexNotReady = -32040 SearchError = -32041 IndexRebuildFail = -32042 )
cdev-specific error codes (-32001 to -32050). These are CLI-agnostic and work with Claude, Gemini, Codex, etc.
const Version = "2.0"
Version is the JSON-RPC protocol version.
Variables ¶
This section is empty.
Functions ¶
func ErrorCodeName ¶
ErrorCodeName returns a human-readable name for an error code.
Types ¶
type Error ¶
type Error struct {
Code int `json:"code"`
Message string `json:"message"`
Data json.RawMessage `json:"data,omitempty"`
}
Error represents a JSON-RPC 2.0 error.
func ErrAgentAlreadyRunning ¶
ErrAgentAlreadyRunning creates an agent already running error.
func ErrAgentError ¶
ErrAgentError creates an agent error with message.
func ErrAgentNotConfigured ¶
ErrAgentNotConfigured creates an agent not configured error.
func ErrAgentNotRunning ¶
ErrAgentNotRunning creates an agent not running error.
func ErrClaudeAlreadyRunning ¶
func ErrClaudeAlreadyRunning() *Error
ErrClaudeAlreadyRunning creates a claude already running error. Deprecated: Use ErrAgentAlreadyRunning instead.
func ErrClaudeError ¶
ErrClaudeError creates a claude error with message. Deprecated: Use ErrAgentError instead.
func ErrClaudeNotRunning ¶
func ErrClaudeNotRunning() *Error
ErrClaudeNotRunning creates a claude not running error. Deprecated: Use ErrAgentNotRunning instead.
func ErrFileNotFound ¶
ErrFileNotFound creates a file not found error.
func ErrFileTooLarge ¶
ErrFileTooLarge creates a file too large error.
func ErrGitOperationFailed ¶
ErrGitOperationFailed creates a git operation failed error.
func ErrInternalError ¶
ErrInternalError creates an internal error.
func ErrInvalidParams ¶
ErrInvalidParams creates an invalid params error.
func ErrInvalidRequest ¶
ErrInvalidRequest creates an invalid request error.
func ErrMethodNotFound ¶
ErrMethodNotFound creates a method not found error.
func ErrNotAGitRepo ¶
func ErrNotAGitRepo() *Error
ErrNotAGitRepo creates a not a git repository error.
func ErrPathTraversal ¶
ErrPathTraversal creates a path traversal error.
func ErrSessionNotFound ¶
ErrSessionNotFound creates a session not found error.
func NewErrorWithData ¶
NewErrorWithData creates a new JSON-RPC error with additional data.
type ID ¶
type ID struct {
// contains filtered or unexported fields
}
ID represents a JSON-RPC ID which can be string, number, or null. Per spec, ID can be a String, Number, or Null. We support string and int64.
func (*ID) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (*ID) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
type Notification ¶
type Notification struct {
JSONRPC string `json:"jsonrpc"`
Method string `json:"method"`
Params json.RawMessage `json:"params,omitempty"`
}
Notification represents a server-to-client notification (no ID, no response expected).
func NewNotification ¶
func NewNotification(method string, params interface{}) (*Notification, error)
NewNotification creates a new JSON-RPC notification.
type Request ¶
type Request struct {
JSONRPC string `json:"jsonrpc"`
ID *ID `json:"id,omitempty"`
Method string `json:"method"`
Params json.RawMessage `json:"params,omitempty"`
}
Request represents a JSON-RPC 2.0 request. If ID is nil, this is a notification (no response expected).
func NewRequest ¶
NewRequest creates a new JSON-RPC request.
func ParseRequest ¶
ParseRequest parses a JSON-RPC request from bytes.
func (*Request) IsNotification ¶
IsNotification returns true if this request is a notification (no ID).
type Response ¶
type Response struct {
JSONRPC string `json:"jsonrpc"`
ID *ID `json:"id"`
Result json.RawMessage `json:"result,omitempty"`
Error *Error `json:"error,omitempty"`
}
Response represents a JSON-RPC 2.0 response.
func NewErrorResponse ¶
NewErrorResponse creates an error JSON-RPC response.
func NewSuccessResponse ¶
NewSuccessResponse creates a successful JSON-RPC response.
func ParseResponse ¶
ParseResponse parses a JSON-RPC response from bytes.