claude

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package claude implements the Claude agent via the Claude SDK WebSocket server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

type Agent struct {
	// contains filtered or unexported fields
}

Agent implements the Agent interface for Claude.

func New

func New(cfg *agent.Config) *Agent

New creates a new Claude agent.

func (*Agent) Execute

func (a *Agent) Execute(ctx context.Context, msgs []*bridge.Message) (*agent.Result, error)

Execute sends messages to Claude and waits for a result.

func (*Agent) IsRunning

func (a *Agent) IsRunning() bool

IsRunning returns true if the agent is running.

func (*Agent) Name

func (a *Agent) Name() string

Name returns the agent name.

func (*Agent) SessionID

func (a *Agent) SessionID() string

SessionID returns the current session ID.

func (*Agent) SetMCPServerAddr

func (a *Agent) SetMCPServerAddr(addr string)

SetMCPServerAddr sets the MCP server address for bridge tools.

func (*Agent) Start

func (a *Agent) Start(ctx context.Context) error

Start initializes and starts the Claude agent process.

func (*Agent) Status

func (a *Agent) Status() *agent.Status

Status returns the current agent status.

func (*Agent) Stop

func (a *Agent) Stop(ctx context.Context) error

Stop gracefully stops the Claude agent.

type ControlApprovePayload

type ControlApprovePayload struct {
	RequestID string `json:"request_id"`
}

ControlApprovePayload approves a control request.

type ControlDenyPayload

type ControlDenyPayload struct {
	RequestID string `json:"request_id"`
	Reason    string `json:"reason,omitempty"`
}

ControlDenyPayload denies a control request.

type ControlRequestPayload

type ControlRequestPayload struct {
	RequestID   string `json:"request_id"`
	Type        string `json:"type"` // "command", "file_write", "file_edit", etc.
	Description string `json:"description"`
	Command     string `json:"command,omitempty"`
	FilePath    string `json:"file_path,omitempty"`
	Content     string `json:"content,omitempty"`
}

ControlRequestPayload is sent when Claude needs permission.

type ErrorPayload

type ErrorPayload struct {
	Code    string `json:"code"`
	Message string `json:"message"`
	Details string `json:"details,omitempty"`
}

ErrorPayload represents an error from Claude.

type InitPayload

type InitPayload struct {
	SessionID    string         `json:"session_id,omitempty"`
	WorkDir      string         `json:"work_dir"`
	Prompt       string         `json:"prompt,omitempty"`
	Model        string         `json:"model,omitempty"`
	MaxTokens    int            `json:"max_tokens,omitempty"`
	Tools        []string       `json:"tools,omitempty"`
	MCPServers   []MCPServer    `json:"mcp_servers,omitempty"`
	SystemPrompt string         `json:"system_prompt,omitempty"`
	Permissions  map[string]any `json:"permissions,omitempty"`
}

InitPayload is sent to initialize a Claude session.

type MCPServer

type MCPServer struct {
	Name    string            `json:"name"`
	Command string            `json:"command"`
	Args    []string          `json:"args,omitempty"`
	Env     map[string]string `json:"env,omitempty"`
}

MCPServer represents an MCP server configuration.

type Message

type Message struct {
	Type    MessageType     `json:"type"`
	Payload json.RawMessage `json:"payload,omitempty"`
}

Message is the base NDJSON message structure.

func DecodeMessage

func DecodeMessage(data []byte) (*Message, error)

DecodeMessage decodes a JSON message.

func NewMessage

func NewMessage(msgType MessageType, payload any) (*Message, error)

NewMessage creates a new message with the given type and payload.

func (*Message) DecodePayload

func (m *Message) DecodePayload(v any) error

DecodePayload decodes the message payload into the given type.

func (*Message) Encode

func (m *Message) Encode() ([]byte, error)

Encode encodes the message to JSON bytes.

type MessageType

type MessageType string

MessageType represents NDJSON message types from Claude SDK.

const (
	// Incoming from Claude
	TypeStreamEvent    MessageType = "stream_event"
	TypeResult         MessageType = "result"
	TypeControlRequest MessageType = "control_request"
	TypeError          MessageType = "error"

	// Outgoing to Claude
	TypeInit           MessageType = "init"
	TypeUserMessage    MessageType = "user_message"
	TypeControlApprove MessageType = "control_approve"
	TypeControlDeny    MessageType = "control_deny"
	TypeStop           MessageType = "stop"
)

type ResultPayload

type ResultPayload struct {
	SessionID  string         `json:"session_id"`
	Output     string         `json:"output"`
	ToolCalls  []ToolCall     `json:"tool_calls,omitempty"`
	Done       bool           `json:"done"`
	Error      string         `json:"error,omitempty"`
	Statistics *Statistics    `json:"statistics,omitempty"`
	Metadata   map[string]any `json:"metadata,omitempty"`
}

ResultPayload is the final result from Claude.

type Statistics

type Statistics struct {
	InputTokens  int           `json:"input_tokens"`
	OutputTokens int           `json:"output_tokens"`
	Duration     time.Duration `json:"duration"`
}

Statistics contains usage statistics.

type StreamEventPayload

type StreamEventPayload struct {
	Event     string          `json:"event"`
	Data      json.RawMessage `json:"data,omitempty"`
	Timestamp time.Time       `json:"timestamp,omitempty"`
}

StreamEventPayload represents streaming events from Claude.

type ToolCall

type ToolCall struct {
	ID        string          `json:"id"`
	Name      string          `json:"name"`
	Arguments json.RawMessage `json:"arguments"`
	Result    string          `json:"result,omitempty"`
	Error     string          `json:"error,omitempty"`
}

ToolCall represents a tool invocation by Claude.

type UserMessagePayload

type UserMessagePayload struct {
	Content string `json:"content"`
}

UserMessagePayload is sent to provide user input.

Jump to

Keyboard shortcuts

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