message

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package message defines JSON-RPC 2.0 message types.

Index

Constants

View Source
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.

View Source
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.

View Source
const Version = "2.0"

Version is the JSON-RPC protocol version.

Variables

This section is empty.

Functions

func ErrorCodeName

func ErrorCodeName(code int) string

ErrorCodeName returns a human-readable name for an error code.

func IsJSONRPC

func IsJSONRPC(data []byte) bool

IsJSONRPC checks if the given data looks like a JSON-RPC message. This is a quick heuristic check, not a full validation.

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

func ErrAgentAlreadyRunning(agentType string) *Error

ErrAgentAlreadyRunning creates an agent already running error.

func ErrAgentError

func ErrAgentError(agentType, message string) *Error

ErrAgentError creates an agent error with message.

func ErrAgentNotConfigured

func ErrAgentNotConfigured(agentType string) *Error

ErrAgentNotConfigured creates an agent not configured error.

func ErrAgentNotRunning

func ErrAgentNotRunning(agentType string) *Error

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

func ErrClaudeError(message string) *Error

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

func ErrFileNotFound(path string) *Error

ErrFileNotFound creates a file not found error.

func ErrFileTooLarge

func ErrFileTooLarge(path string, size, maxSize int64) *Error

ErrFileTooLarge creates a file too large error.

func ErrGitOperationFailed

func ErrGitOperationFailed(operation, message string) *Error

ErrGitOperationFailed creates a git operation failed error.

func ErrInternalError

func ErrInternalError(message string) *Error

ErrInternalError creates an internal error.

func ErrInvalidParams

func ErrInvalidParams(message string) *Error

ErrInvalidParams creates an invalid params error.

func ErrInvalidRequest

func ErrInvalidRequest(message string) *Error

ErrInvalidRequest creates an invalid request error.

func ErrMethodNotFound

func ErrMethodNotFound(method string) *Error

ErrMethodNotFound creates a method not found error.

func ErrNotAGitRepo

func ErrNotAGitRepo() *Error

ErrNotAGitRepo creates a not a git repository error.

func ErrParseError

func ErrParseError(message string) *Error

ErrParseError creates a parse error.

func ErrPathTraversal

func ErrPathTraversal(path string) *Error

ErrPathTraversal creates a path traversal error.

func ErrSessionNotFound

func ErrSessionNotFound(sessionID string) *Error

ErrSessionNotFound creates a session not found error.

func NewError

func NewError(code int, message string) *Error

NewError creates a new JSON-RPC error.

func NewErrorWithData

func NewErrorWithData(code int, message string, data interface{}) *Error

NewErrorWithData creates a new JSON-RPC error with additional data.

func (*Error) Error

func (e *Error) Error() string

Error implements the error interface.

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 NumberID

func NumberID(n int64) *ID

NumberID creates an ID from an integer.

func StringID

func StringID(s string) *ID

StringID creates an ID from a string.

func (*ID) IsNumber

func (id *ID) IsNumber() bool

IsNumber returns true if the ID is a number.

func (*ID) IsString

func (id *ID) IsString() bool

IsString returns true if the ID is a string.

func (*ID) MarshalJSON

func (id *ID) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*ID) String

func (id *ID) String() string

String returns the ID as a string (for logging/debugging).

func (*ID) UnmarshalJSON

func (id *ID) UnmarshalJSON(data []byte) error

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

func NewRequest(id *ID, method string, params interface{}) (*Request, error)

NewRequest creates a new JSON-RPC request.

func ParseRequest

func ParseRequest(data []byte) (*Request, error)

ParseRequest parses a JSON-RPC request from bytes.

func (*Request) IsNotification

func (r *Request) IsNotification() bool

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

func NewErrorResponse(id *ID, err *Error) *Response

NewErrorResponse creates an error JSON-RPC response.

func NewSuccessResponse

func NewSuccessResponse(id *ID, result interface{}) (*Response, error)

NewSuccessResponse creates a successful JSON-RPC response.

func ParseResponse

func ParseResponse(data []byte) (*Response, error)

ParseResponse parses a JSON-RPC response from bytes.

func (*Response) IsError

func (r *Response) IsError() bool

IsError returns true if this response contains an error.

Jump to

Keyboard shortcuts

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