Documentation
¶
Index ¶
- Constants
- func BuildCommonArgs(config Config, opts CommonOptions) []string
- func FormatEnv(key, value string) string
- func GetCleanEnv(ctx context.Context) ([]string, error)
- func InvalidateDiscoveryCache()
- func IsValidPermissionMode(mode string) bool
- func MergeEnv(base []string, custom []string) []string
- func StreamToStdin(ctx context.Context, stdin io.WriteCloser, messages <-chan any) error
- type Agent
- func (a *Agent) Execute(ctx context.Context, prompt string, opts agentboot.ExecutionOptions) (agentboot.ExecutionHandle, error)
- func (a *Agent) GetDefaultFormat() agentboot.OutputFormat
- func (a *Agent) IsAvailable() bool
- func (a *Agent) SetCLIPath(path string)
- func (a *Agent) SetDefaultFormat(format agentboot.OutputFormat)
- func (a *Agent) SetSkipPermissions(enabled bool)
- func (a *Agent) Type() agentboot.AgentType
- type AssistantMessage
- type CLIDiscovery
- type CLIVariant
- type CancelRequestBuilder
- type CommonOptions
- type Config
- type ContentBlock
- type ControlManager
- func (m *ControlManager) Close() error
- func (m *ControlManager) HandleCancel(cancelID string)
- func (m *ControlManager) HandleControlMessage(data map[string]interface{}) error
- func (m *ControlManager) HandleResponse(resp ControlResponse)
- func (m *ControlManager) IsClosed() bool
- func (m *ControlManager) RegisterCancelController(id string, cancel context.CancelFunc)
- func (m *ControlManager) SendRequest(ctx context.Context, req ControlRequest, stdin io.Writer) (ControlResponse, error)
- func (m *ControlManager) SendRequestAsync(req ControlRequest, stdin io.Writer) error
- func (m *ControlManager) SetRequestTimeout(d time.Duration)
- func (m *ControlManager) UnregisterCancelController(id string)
- type ControlRequest
- type ControlResponse
- type Driver
- func (d *Driver) IsAvailable() bool
- func (d *Driver) Prepare(ctx context.Context, prompt string, opts agentboot.ExecutionOptions) (*agentboot.LaunchSpec, error)
- func (d *Driver) SetCLIPath(path string)
- func (d *Driver) SetForceAvailable(v bool)
- func (d *Driver) SetSkipPermissions(enabled bool)
- func (d *Driver) Type() agentboot.AgentType
- type Formatter
- type InputJSONDelta
- type Launcher
- func (l *Launcher) Execute(ctx context.Context, prompt string, opts agentboot.ExecutionOptions) (agentboot.ExecutionHandle, error)
- func (l *Launcher) ExecuteWithTimeout(ctx context.Context, prompt string, timeout time.Duration, ...) (agentboot.ExecutionHandle, error)
- func (l *Launcher) GetControlManager() *ControlManager
- func (l *Launcher) GetDefaultFormat() agentboot.OutputFormat
- func (l *Launcher) GetDiscovery() *CLIDiscovery
- func (l *Launcher) Interrupt(ctx context.Context, stdin io.WriteCloser, reason string) error
- func (l *Launcher) IsAvailable() bool
- func (l *Launcher) SendPermissionRequest(ctx context.Context, req agentboot.PermissionRequest, stdin io.WriteCloser) (agentboot.PermissionResult, error)
- func (l *Launcher) SetCLIPath(path string)
- func (l *Launcher) SetDefaultFormat(format agentboot.OutputFormat)
- func (l *Launcher) SetSkipPermissions(enabled bool)
- func (l *Launcher) Type() agentboot.AgentType
- type Message
- type MessageAccumulator
- func (a *MessageAccumulator) AddEvent(event common.Event) ([]Message, bool, bool)
- func (a *MessageAccumulator) GetAssistantMessages() []*AssistantMessage
- func (a *MessageAccumulator) GetMessages() []Message
- func (a *MessageAccumulator) GetMessagesByType(msgType string) []Message
- func (a *MessageAccumulator) GetSessionID() string
- func (a *MessageAccumulator) GetToolUses() map[string]*PendingToolUse
- func (a *MessageAccumulator) Reset()
- type MessageDelta
- type PendingToolUse
- type PermissionDenial
- type PermissionMode
- type PermissionRequestBuilder
- type ResultMessage
- type StreamEvent
- type StreamEventMessage
- type StreamPromptBuilder
- func (b *StreamPromptBuilder) Add(msg map[string]interface{}) error
- func (b *StreamPromptBuilder) AddText(text string) error
- func (b *StreamPromptBuilder) AddUserMessage(content string) error
- func (b *StreamPromptBuilder) Close() chan any
- func (b *StreamPromptBuilder) IsClosed() bool
- func (b *StreamPromptBuilder) Messages() chan any
- type StreamReader
- type StreamWriter
- type SystemMessage
- type TextBlock
- type TextDelta
- type TextFormatter
- type ThinkingBlock
- type ToolCallInfo
- type ToolResultContentBlock
- type ToolResultMessage
- type ToolUseBlock
- type ToolUseMessage
- type Transport
- func (t *Transport) AccumulateMessage(ev common.Event) []any
- func (t *Transport) Classify(ev common.Event) (agentboot.EventKind, agentboot.StreamEvent)
- func (t *Transport) EncodeControlResponse(reqID string, resp agentboot.ControlResponse, originalInput map[string]any) any
- func (t *Transport) SetExecutionContext(sessionID, chatID, platform, botUUID string)
- type UnknownBlock
- type UsageInfo
- type UserMessage
Constants ¶
const ( // Environment variable names EnvClaudePath = "CLAUDE_CLI_PATH" EnvUseBundled = "CLAUDE_USE_BUNDLED" EnvUseGlobal = "CLAUDE_USE_GLOBAL" EnvClaudeHome = "CLAUDE_HOME" EnvBunEnv = "BUN_INSTALL" EnvNodePath = "NODE_PATH" EnvBunVersions = "BUN_VERSIONS" EnvBunInstall = "BUN_INSTALL" // Default paths DefaultBundledPathLinux = "/opt/claude-code/dist/claude" DefaultBundledPathDarwin = "/Applications/Claude.app/Contents/MacOS/claude" DefaultBundledPathWindows = `C:\Program Files\Claude\claude.exe` // Claude version for bundled fallback DefaultBundledVersion = "1.0.0" )
const ( SDKTextMessage = "text" SDKSystemMessage = "system" SDKAssistantMessage = "assistant" SDKUserMessage = "user" SDKToolUseMessage = "tool_use" SDKToolResultMessage = "tool_result" SDKResultMessage = "result" SDKStreamEventMessage = "stream_event" SDKControlRequestMessage = "control_request" SDKUserMessageReplayMessage = "user_message_replay" SDKPartialAssistantMessage = "partial_assistant" SDKCompactBoundaryMessage = "compact_boundary" SDKStatusMessage = "status" SDKLocalCommandOutputMessage = "local_command_output" SDKHookStartedMessage = "hook_started" SDKHookProgressMessage = "hook_progress" SDKHookResponseMessage = "hook_response" SDKToolProgressMessage = "tool_progress" SDKAuthStatusMessage = "auth_status" SDKTaskNotificationMessage = "task_notification" SDKTaskStartedMessage = "task_started" SDKTaskProgressMessage = "task_progress" SDKFilesPersistedMessage = "files_persisted" SDKToolUseSummaryMessage = "tool_use_summary" SDKRateLimitMessage = "rate_limit" SDKPromptSuggestionMessage = "prompt_suggestion" )
MessageType constants for Claude Code stream JSON all of these types defined in python sdk: https://platform.claude.com/docs/en/agent-sdk/python#message-types or TypeScript sdk: https://platform.claude.com/docs/en/agent-sdk/typescript#message-types type SDKMessage =
| SDKAssistantMessage | SDKUserMessage | SDKUserMessageReplay | SDKResultMessage | SDKSystemMessage | SDKPartialAssistantMessage | SDKCompactBoundaryMessage | SDKStatusMessage | SDKLocalCommandOutputMessage | SDKHookStartedMessage | SDKHookProgressMessage | SDKHookResponseMessage | SDKToolProgressMessage | SDKAuthStatusMessage | SDKTaskNotificationMessage | SDKTaskStartedMessage | SDKTaskProgressMessage | SDKFilesPersistedEvent | SDKToolUseSummaryMessage | SDKRateLimitEvent | SDKPromptSuggestionMessage;
const ( SystemSubtypeInit = "init" SystemSubtypeTaskCompleted = "task_completed" )
System message subtypes
const ( AssistantErrorAuthFailed = "authentication_failed" AssistantErrorBilling = "billing_error" AssistantErrorRateLimit = "rate_limit" AssistantErrorInvalidRequest = "invalid_request" AssistantErrorServer = "server_error" AssistantErrorMaxTokens = "max_output_tokens" AssistantErrorUnknown = "unknown" )
assistant message error ref: https://platform.claude.com/docs/en/agent-sdk/python#assistant-message-error
const ( ControlMsgTypeResponse = "control_response" ControlMsgTypeCancelNotification = "cancel_notification" ControlMsgTypeCancelRequest = "control_cancel_request" )
Control message types
const ( ControlRequestSubtypeCanUseTool = "can_use_tool" ControlRequestSubtypeInterrupt = "interrupt" )
Control request subtypes
const ( ControlRequestTypePermission = "permission" ControlRequestTypeCancel = "cancel" )
Control request types
const ( ResultSubtypeSuccess = "success" ResultSubtypeError = "error" )
Result subtypes
const ( ContentBlockTypeText = "text" ContentBlockTypeToolUse = "tool_use" ContentBlockTypeThinking = "thinking" ContentBlockTypeToolResult = "tool_result" )
Content block types
const SDKControlPrefix = "control_"
Variables ¶
This section is empty.
Functions ¶
func BuildCommonArgs ¶
func BuildCommonArgs(config Config, opts CommonOptions) []string
BuildCommonArgs builds CLI arguments shared between Launcher and QueryLauncher This follows the original query_launcher.go behavior where config and opts arguments are added independently (both can be present).
func GetCleanEnv ¶
GetCleanEnv is a convenience function for getting clean environment
func InvalidateDiscoveryCache ¶
func InvalidateDiscoveryCache()
InvalidateDiscoveryCache invalidates the global discovery cache
func IsValidPermissionMode ¶
IsValidPermissionMode checks if a permission mode is valid for Claude CLI
func MergeEnv ¶
MergeEnv merges custom environment variables with base environment Custom variables override base ones with the same key
func StreamToStdin ¶
StreamToStdin streams messages to the stdin of a running process
Types ¶
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
Agent implements the agentboot.Agent interface for Claude Code. Internally it uses Driver (process setup) + Transport (protocol) + agentboot.Runner (execution).
func NewAgentWithConfig ¶ added in v0.260507.1
NewAgentWithConfig creates a Claude agent with full Claude-specific config.
func NewAgentWithFactory ¶ added in v0.260507.1
NewAgentWithFactory creates a Claude agent that uses the supplied process.Factory instead of the OS exec factory. Tests inject a factory from agentboot/claude/fixture to substitute the claude binary with a scripted in-memory process while keeping the real driver and transport on the code path.
The driver's binary-availability check is forced to true since tests don't want to spawn the real claude binary.
func (*Agent) Execute ¶
func (a *Agent) Execute(ctx context.Context, prompt string, opts agentboot.ExecutionOptions) (agentboot.ExecutionHandle, error)
Execute runs the Claude agent and returns an agentboot.ExecutionHandle. The runner injects the per-execution routing context into the transport internally; callers consume handle.Events() for streaming output and respond to control events via handle.Respond.
func (*Agent) GetDefaultFormat ¶
func (a *Agent) GetDefaultFormat() agentboot.OutputFormat
GetDefaultFormat returns the current default format.
func (*Agent) IsAvailable ¶
IsAvailable checks if Claude Code is available.
func (*Agent) SetCLIPath ¶
SetCLIPath sets an explicit CLI path.
func (*Agent) SetDefaultFormat ¶
func (a *Agent) SetDefaultFormat(format agentboot.OutputFormat)
SetDefaultFormat sets the default output format.
func (*Agent) SetSkipPermissions ¶
SetSkipPermissions enables or disables skip permissions mode.
type AssistantMessage ¶
type AssistantMessage struct {
Type string `json:"type"`
Message anthropic.Message `json:"message"`
ParentToolUseID *string `json:"parent_tool_use_id,omitempty"`
SessionID string `json:"session_id"`
UUID string `json:"uuid"`
Timestamp time.Time `json:"timestamp,omitempty"`
Error string `json:"error,omitempty"`
}
AssistantMessage represents assistant messages with content blocks
func (*AssistantMessage) GetRawData ¶
func (m *AssistantMessage) GetRawData() map[string]interface{}
GetRawData implements Message
func (*AssistantMessage) GetTimestamp ¶
func (m *AssistantMessage) GetTimestamp() time.Time
GetTimestamp implements Message
func (*AssistantMessage) GetType ¶
func (m *AssistantMessage) GetType() string
GetType implements Message
func (*AssistantMessage) IsError ¶
func (m *AssistantMessage) IsError() bool
IsError returns true if the assistant message contains an error
type CLIDiscovery ¶
type CLIDiscovery struct {
// contains filtered or unexported fields
}
CLIDiscovery handles Claude CLI path discovery and version checking
func NewCLIDiscovery ¶
func NewCLIDiscovery() *CLIDiscovery
NewCLIDiscovery creates a new CLI discovery instance
func (*CLIDiscovery) FindClaudeCLI ¶
func (d *CLIDiscovery) FindClaudeCLI(ctx context.Context) (*CLIVariant, error)
FindClaudeCLI finds the best available Claude CLI installation
func (*CLIDiscovery) GetCleanEnv ¶
func (d *CLIDiscovery) GetCleanEnv(ctx context.Context) ([]string, error)
GetCleanEnv returns a clean environment for running Claude CLI
func (*CLIDiscovery) InvalidateCache ¶
func (d *CLIDiscovery) InvalidateCache()
InvalidateCache clears the cached CLI variant
type CLIVariant ¶
type CLIVariant struct {
Path string
Version string
Source string // "global", "bundled", "custom", "env"
}
CLIVariant represents a discovered Claude CLI installation
func FindClaudeCLI ¶
func FindClaudeCLI(ctx context.Context) (*CLIVariant, error)
type CancelRequestBuilder ¶
type CancelRequestBuilder struct {
// contains filtered or unexported fields
}
CancelRequestBuilder builds cancel control requests
func NewCancelRequestBuilder ¶
func NewCancelRequestBuilder() *CancelRequestBuilder
NewCancelRequestBuilder creates a new cancel request builder
func (*CancelRequestBuilder) Build ¶
func (b *CancelRequestBuilder) Build() ControlRequest
Build creates the control request
func (*CancelRequestBuilder) WithCancel ¶
func (b *CancelRequestBuilder) WithCancel(id string) *CancelRequestBuilder
WithCancel sets the cancel ID
func (*CancelRequestBuilder) WithReason ¶
func (b *CancelRequestBuilder) WithReason(reason string) *CancelRequestBuilder
WithReason sets the cancellation reason
func (*CancelRequestBuilder) WithRequestID ¶
func (b *CancelRequestBuilder) WithRequestID(id string) *CancelRequestBuilder
WithRequestID sets the request ID
type CommonOptions ¶
type CommonOptions struct {
Model string
FallbackModel string
MaxTurns int
CustomSystemPrompt string
AppendSystemPrompt string
ContinueConversation bool
Resume string
AllowedTools []string
DisallowedTools []string
MCPServers map[string]interface{}
StrictMcpConfig bool
PermissionMode string
SettingsPath string
// PermissionPromptTool specifies the tool for permission prompts (e.g., "stdio")
PermissionPromptTool string
}
CommonOptions represents per-execution options that can override config
type Config ¶
type Config struct {
// Stream Options
EnableStreamJSON bool `json:"enable_stream_json"`
StreamBufferSize int `json:"stream_buffer_size"`
// Execution Timeout
// DefaultExecutionTimeout is the default timeout for agent execution
DefaultExecutionTimeout time.Duration `json:"default_execution_timeout,omitempty"`
// Model Selection
Model string `json:"model,omitempty"`
FallbackModel string `json:"fallback_model,omitempty"`
// MaxTurns limits the number of agentic turns
MaxTurns int `json:"max_turns,omitempty"`
// System Prompt Options
CustomSystemPrompt string `json:"custom_system_prompt,omitempty"`
// AppendSystemPrompt adds additional system prompt content
AppendSystemPrompt string `json:"append_system_prompt,omitempty"`
// Conversation Continuation
ContinueConversation bool `json:"continue_conversation,omitempty"`
// ResumeSessionID resumes a specific session
ResumeSessionID string `json:"resume_session_id,omitempty"`
// Tool Filtering
AllowedTools []string `json:"allowed_tools,omitempty"`
DisallowedTools []string `json:"disallowed_tools,omitempty"`
// Permission Handling
PermissionMode PermissionMode `json:"permission_mode,omitempty"`
// Configuration Paths
SettingsPath string `json:"settings_path,omitempty"`
// MCP Server Configuration
// MCPServers maps server names to their configurations
MCPServers map[string]interface{} `json:"mcp_servers,omitempty"`
// StrictMcpConfig enables strict MCP configuration validation
StrictMcpConfig bool `json:"strict_mcp_config,omitempty"`
// Custom Environment Variables
// CustomEnv allows passing additional environment variables to the Claude CLI
CustomEnv []string `json:"custom_env,omitempty"`
// CLI Path Override
// CLIPath explicitly sets the path to the Claude CLI executable
CLIPath string `json:"cli_path,omitempty"`
// UseBundled forces use of the bundled Claude CLI
UseBundled bool `json:"use_bundled,omitempty"`
// UseGlobal forces use of the global Claude CLI
UseGlobal bool `json:"use_global,omitempty"`
}
Config holds Claude-specific configuration
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a config with sensible defaults
func (*Config) WithContinue ¶
WithContinue returns a new config configured for continuing a conversation
func (*Config) WithResume ¶
WithResume returns a new config configured for resuming a session
type ContentBlock ¶
type ContentBlock interface {
GetContentType() string
}
ContentBlock types
func UnmarshalContentBlock ¶
func UnmarshalContentBlock(data []byte) (ContentBlock, error)
UnmarshalContentBlock unmarshals a content block from JSON
type ControlManager ¶
type ControlManager struct {
// contains filtered or unexported fields
}
ControlManager manages control request/response lifecycle
func NewControlManager ¶
func NewControlManager() *ControlManager
NewControlManager creates a new control manager
func (*ControlManager) Close ¶
func (m *ControlManager) Close() error
Close closes the control manager and cleans up resources
func (*ControlManager) HandleCancel ¶
func (m *ControlManager) HandleCancel(cancelID string)
HandleCancel handles a cancel notification from Claude
func (*ControlManager) HandleControlMessage ¶
func (m *ControlManager) HandleControlMessage(data map[string]interface{}) error
HandleControlMessage processes a raw control message from the event stream
func (*ControlManager) HandleResponse ¶
func (m *ControlManager) HandleResponse(resp ControlResponse)
HandleResponse processes a control response from Claude
func (*ControlManager) IsClosed ¶
func (m *ControlManager) IsClosed() bool
IsClosed returns true if the manager is closed
func (*ControlManager) RegisterCancelController ¶
func (m *ControlManager) RegisterCancelController(id string, cancel context.CancelFunc)
RegisterCancelController registers a cancel controller for an operation
func (*ControlManager) SendRequest ¶
func (m *ControlManager) SendRequest(ctx context.Context, req ControlRequest, stdin io.Writer) (ControlResponse, error)
SendRequest sends a control request and waits for a response
func (*ControlManager) SendRequestAsync ¶
func (m *ControlManager) SendRequestAsync(req ControlRequest, stdin io.Writer) error
SendRequestAsync sends a control request without waiting for response
func (*ControlManager) SetRequestTimeout ¶
func (m *ControlManager) SetRequestTimeout(d time.Duration)
SetRequestTimeout sets the timeout for control requests
func (*ControlManager) UnregisterCancelController ¶
func (m *ControlManager) UnregisterCancelController(id string)
UnregisterCancelController removes a cancel controller
type ControlRequest ¶
type ControlRequest struct {
RequestID string `json:"request_id"`
Type string `json:"type"` // e.g., "permission", "cancel"
Request map[string]interface{} `json:"request"`
}
ControlRequest represents a control request sent to Claude
func (*ControlRequest) GetRawData ¶
func (m *ControlRequest) GetRawData() map[string]interface{}
GetRawData implements Message
func (*ControlRequest) GetTimestamp ¶
func (m *ControlRequest) GetTimestamp() time.Time
GetTimestamp implements Message
func (*ControlRequest) GetType ¶
func (m *ControlRequest) GetType() string
GetType implements Message
type ControlResponse ¶
type ControlResponse struct {
RequestID string `json:"request_id"`
Type string `json:"type"` // e.g., "permission_response", "cancel_response"
Response map[string]interface{} `json:"response"`
}
ControlResponse represents a control response received from Claude
type Driver ¶ added in v0.260507.1
type Driver struct {
// contains filtered or unexported fields
}
Driver implements agentboot.AgentDriver for Claude Code CLI. It is responsible for binary discovery, CLI argument construction, and environment preparation. It does NOT communicate with the running process.
func (*Driver) IsAvailable ¶ added in v0.260507.1
IsAvailable checks whether the Claude Code CLI binary is present and usable.
func (*Driver) Prepare ¶ added in v0.260507.1
func (d *Driver) Prepare(ctx context.Context, prompt string, opts agentboot.ExecutionOptions) (*agentboot.LaunchSpec, error)
Prepare builds a LaunchSpec for the given prompt and execution options.
func (*Driver) SetCLIPath ¶ added in v0.260507.1
SetCLIPath overrides the path to the Claude CLI binary.
func (*Driver) SetForceAvailable ¶ added in v0.260507.1
SetForceAvailable bypasses binary-presence checks. Tests inject a process.Factory that does not spawn the real claude binary; in that case IsAvailable should return true regardless of what's on disk.
func (*Driver) SetSkipPermissions ¶ added in v0.260507.1
SetSkipPermissions enables or disables the --dangerously-skip-permissions flag.
type InputJSONDelta ¶
InputJSONDelta represents incremental tool input JSON
type Launcher ¶
type Launcher struct {
// contains filtered or unexported fields
}
Launcher is the legacy entry point for Claude Code CLI execution. Internally it now delegates to Driver + Transport + agentboot.Runner.
Prefer using NewAgentWithConfig for new code. Launcher is retained for backward compatibility with existing callers (examples, integration tests).
func NewLauncher ¶
NewLauncher creates a new Claude launcher.
func (*Launcher) Execute ¶
func (l *Launcher) Execute(ctx context.Context, prompt string, opts agentboot.ExecutionOptions) (agentboot.ExecutionHandle, error)
Execute runs Claude Code and returns an agentboot.ExecutionHandle.
func (*Launcher) ExecuteWithTimeout ¶
func (l *Launcher) ExecuteWithTimeout( ctx context.Context, prompt string, timeout time.Duration, opts agentboot.ExecutionOptions, ) (agentboot.ExecutionHandle, error)
ExecuteWithTimeout runs Claude Code with a specific timeout and returns an agentboot.ExecutionHandle.
func (*Launcher) GetControlManager ¶
func (l *Launcher) GetControlManager() *ControlManager
GetControlManager returns the ControlManager (for Interrupt / SendPermissionRequest).
func (*Launcher) GetDefaultFormat ¶
func (l *Launcher) GetDefaultFormat() agentboot.OutputFormat
GetDefaultFormat returns the current default format.
func (*Launcher) GetDiscovery ¶
func (l *Launcher) GetDiscovery() *CLIDiscovery
GetDiscovery returns the CLI discovery instance.
func (*Launcher) Interrupt ¶
Interrupt sends an interrupt/cancel request to a running Claude process.
func (*Launcher) IsAvailable ¶
IsAvailable checks if Claude Code CLI is available.
func (*Launcher) SendPermissionRequest ¶
func (l *Launcher) SendPermissionRequest(ctx context.Context, req agentboot.PermissionRequest, stdin io.WriteCloser) (agentboot.PermissionResult, error)
SendPermissionRequest sends a permission request and waits for the response.
func (*Launcher) SetCLIPath ¶
SetCLIPath sets an explicit path to the Claude CLI binary.
func (*Launcher) SetDefaultFormat ¶
func (l *Launcher) SetDefaultFormat(format agentboot.OutputFormat)
SetDefaultFormat sets the default output format.
func (*Launcher) SetSkipPermissions ¶
SetSkipPermissions enables or disables the dangerously-skip-permissions flag.
type Message ¶
type Message interface {
GetType() string
GetTimestamp() time.Time
GetRawData() map[string]interface{}
}
Message is the interface for all Claude message types
type MessageAccumulator ¶
type MessageAccumulator struct {
// contains filtered or unexported fields
}
MessageAccumulator collects related events into complete messages
func NewMessageAccumulator ¶
func NewMessageAccumulator() *MessageAccumulator
NewMessageAccumulator creates a new message accumulator
func (*MessageAccumulator) AddEvent ¶
AddEvent adds a parsed event and returns any newly complete messages Returns: (newMessages, hasResult, resultSuccess)
func (*MessageAccumulator) GetAssistantMessages ¶
func (a *MessageAccumulator) GetAssistantMessages() []*AssistantMessage
GetAssistantMessages returns all assistant messages
func (*MessageAccumulator) GetMessages ¶
func (a *MessageAccumulator) GetMessages() []Message
GetMessages returns all accumulated messages
func (*MessageAccumulator) GetMessagesByType ¶
func (a *MessageAccumulator) GetMessagesByType(msgType string) []Message
GetMessagesByType returns messages of a specific type
func (*MessageAccumulator) GetSessionID ¶
func (a *MessageAccumulator) GetSessionID() string
GetSessionID returns the session ID if available
func (*MessageAccumulator) GetToolUses ¶
func (a *MessageAccumulator) GetToolUses() map[string]*PendingToolUse
GetToolUses returns all tool uses with their results
func (*MessageAccumulator) Reset ¶
func (a *MessageAccumulator) Reset()
Reset clears the accumulator state
type MessageDelta ¶
type MessageDelta struct {
Type string `json:"type"`
StopReason string `json:"stop_reason,omitempty"`
Usage *UsageInfo `json:"usage,omitempty"`
}
MessageDelta represents message-level updates
type PendingToolUse ¶
type PendingToolUse struct {
ToolUseID string
ToolUse *ToolUseBlock
Result *ToolResultMessage
Complete bool
}
PendingToolUse tracks a tool_use waiting for its result
type PermissionDenial ¶
PermissionDenial represents a denied permission request
type PermissionMode ¶
type PermissionMode string
PermissionMode defines how permission requests are handled These values must match Claude Code CLI's --permission-mode options
const ( // PermissionModeDefault uses the default permission behavior (asks for permissions) PermissionModeDefault PermissionMode = "default" // PermissionModeAuto auto-approves permissions (equivalent to bypassPermissions) PermissionModeAuto PermissionMode = "auto" // PermissionModeDontAsk doesn't ask for permissions PermissionModeDontAsk PermissionMode = "dontAsk" // PermissionModeBypassPermissions bypasses all permission checks PermissionModeBypassPermissions PermissionMode = "bypassPermissions" // PermissionModeAcceptEdits accepts edit operations PermissionModeAcceptEdits PermissionMode = "acceptEdits" // PermissionModePlan enables plan mode PermissionModePlan PermissionMode = "plan" )
type PermissionRequestBuilder ¶
type PermissionRequestBuilder struct {
// contains filtered or unexported fields
}
PermissionRequestBuilder builds permission control requests
func NewPermissionRequestBuilder ¶
func NewPermissionRequestBuilder() *PermissionRequestBuilder
NewPermissionRequestBuilder creates a new permission request builder
func (*PermissionRequestBuilder) Build ¶
func (b *PermissionRequestBuilder) Build() ControlRequest
Build creates the control request
func (*PermissionRequestBuilder) WithRequestID ¶
func (b *PermissionRequestBuilder) WithRequestID(id string) *PermissionRequestBuilder
WithRequestID sets the request ID
func (*PermissionRequestBuilder) WithTool ¶
func (b *PermissionRequestBuilder) WithTool(name string, input map[string]interface{}) *PermissionRequestBuilder
WithTool sets the tool name and input
type ResultMessage ¶
type ResultMessage struct {
Type string `json:"type"`
SubType string `json:"subtype,omitempty"`
Result string `json:"result,omitempty"`
TotalCostUSD float64 `json:"total_cost_usd,omitempty"`
IsError bool `json:"is_error,omitempty"`
DurationMS int64 `json:"duration_ms,omitempty"`
DurationAPIMS int64 `json:"duration_api_ms,omitempty"`
NumTurns int `json:"num_turns,omitempty"`
Usage UsageInfo `json:"usage,omitempty"`
SessionID string `json:"session_id,omitempty"`
PermissionDenials []PermissionDenial `json:"permission_denials,omitempty"`
Timestamp time.Time `json:"timestamp,omitempty"`
}
ResultMessage represents the final result message
func (*ResultMessage) GetRawData ¶
func (m *ResultMessage) GetRawData() map[string]interface{}
GetRawData implements Message
func (*ResultMessage) GetTimestamp ¶
func (m *ResultMessage) GetTimestamp() time.Time
GetTimestamp implements Message
func (*ResultMessage) IsSuccess ¶
func (m *ResultMessage) IsSuccess() bool
IsSuccess returns true if the result indicates success
type StreamEvent ¶
type StreamEvent struct {
Type string `json:"type"` // content_block_delta, content_block_start, etc.
Index int `json:"index,omitempty"`
Delta interface{} `json:"delta,omitempty"` // TextDelta, InputJSONDelta, etc.
}
StreamEvent represents a streaming event
type StreamEventMessage ¶
type StreamEventMessage struct {
Type string `json:"type"`
Event StreamEvent `json:"event"`
SessionID string `json:"session_id,omitempty"`
Timestamp time.Time `json:"timestamp,omitempty"`
}
StreamEventMessage represents real-time streaming delta events
func (*StreamEventMessage) GetRawData ¶
func (m *StreamEventMessage) GetRawData() map[string]interface{}
GetRawData implements Message
func (*StreamEventMessage) GetTimestamp ¶
func (m *StreamEventMessage) GetTimestamp() time.Time
GetTimestamp implements Message
func (*StreamEventMessage) GetType ¶
func (m *StreamEventMessage) GetType() string
GetType implements Message
type StreamPromptBuilder ¶
type StreamPromptBuilder struct {
// contains filtered or unexported fields
}
StreamPromptBuilder helps build stream prompts
func NewStreamPromptBuilder ¶
func NewStreamPromptBuilder() *StreamPromptBuilder
NewStreamPromptBuilder creates a new stream prompt builder
func (*StreamPromptBuilder) Add ¶
func (b *StreamPromptBuilder) Add(msg map[string]interface{}) error
Add adds a message to the stream
func (*StreamPromptBuilder) AddText ¶
func (b *StreamPromptBuilder) AddText(text string) error
AddText adds a text message to the stream
func (*StreamPromptBuilder) AddUserMessage ¶
func (b *StreamPromptBuilder) AddUserMessage(content string) error
AddUserMessage adds a user message to the stream
func (*StreamPromptBuilder) Close ¶
func (b *StreamPromptBuilder) Close() chan any
Close closes the stream and returns the channel for use as stdin input.
func (*StreamPromptBuilder) IsClosed ¶
func (b *StreamPromptBuilder) IsClosed() bool
IsClosed returns true if the builder is closed
func (*StreamPromptBuilder) Messages ¶
func (b *StreamPromptBuilder) Messages() chan any
Messages returns the underlying message channel.
type StreamReader ¶
type StreamReader struct {
// contains filtered or unexported fields
}
StreamReader reads line-delimited JSON from a reader
func NewStreamReader ¶
func NewStreamReader(r io.Reader) *StreamReader
NewStreamReader creates a new stream reader
func (*StreamReader) Next ¶
func (r *StreamReader) Next() (map[string]interface{}, error)
Next reads the next JSON object from the stream
func (*StreamReader) ReadAll ¶
func (r *StreamReader) ReadAll() ([]map[string]interface{}, error)
ReadAll reads all remaining objects from the stream
type StreamWriter ¶
type StreamWriter struct {
// contains filtered or unexported fields
}
StreamWriter writes line-delimited JSON to a writer
func NewStreamWriter ¶
func NewStreamWriter(w io.Writer) *StreamWriter
NewStreamWriter creates a new stream writer
func (*StreamWriter) Write ¶
func (w *StreamWriter) Write(data map[string]interface{}) error
Write writes a JSON object to the stream
type SystemMessage ¶
type SystemMessage struct {
Type string `json:"type"`
SubType string `json:"subtype,omitempty"`
SessionID string `json:"session_id"`
Timestamp time.Time `json:"timestamp"`
// Subagent task fields (populated when SubType is task_started/task_notification/task_completed)
Description string `json:"description,omitempty"`
Prompt string `json:"prompt,omitempty"`
TaskID string `json:"task_id,omitempty"`
TaskType string `json:"task_type,omitempty"`
ToolUseID string `json:"tool_use_id,omitempty"`
}
SystemMessage represents system/init messages
func (*SystemMessage) GetRawData ¶
func (m *SystemMessage) GetRawData() map[string]interface{}
GetRawData implements Message
func (*SystemMessage) GetTimestamp ¶
func (m *SystemMessage) GetTimestamp() time.Time
GetTimestamp implements Message
type TextBlock ¶
TextBlock represents text content
func (*TextBlock) GetContentType ¶
GetContentType implements ContentBlock
type TextFormatter ¶
type TextFormatter struct {
IncludeTimestamp bool
Verbose bool
ShowToolDetails bool
// contains filtered or unexported fields
}
TextFormatter implements Formatter using built-in formatting
func NewTextFormatter ¶
func NewTextFormatter() *TextFormatter
NewTextFormatter creates a new text formatter
func (*TextFormatter) Format ¶
func (f *TextFormatter) Format(msg Message) string
Format formats a message
func (*TextFormatter) SetIncludeTimestamp ¶
func (f *TextFormatter) SetIncludeTimestamp(include bool)
SetIncludeTimestamp sets whether to include timestamps in output
func (*TextFormatter) SetShowToolDetails ¶
func (f *TextFormatter) SetShowToolDetails(show bool)
SetShowToolDetails sets whether to show tool details
func (*TextFormatter) SetVerbose ¶
func (f *TextFormatter) SetVerbose(verbose bool)
SetVerbose sets verbose mode for detailed output
type ThinkingBlock ¶
ThinkingBlock represents reasoning/thinking content
func (*ThinkingBlock) GetContentType ¶
func (b *ThinkingBlock) GetContentType() string
GetContentType implements ContentBlock
type ToolCallInfo ¶
type ToolCallInfo struct {
CallID string `json:"call_id"`
ToolName string `json:"tool_name"`
Input interface{} `json:"input"`
Result interface{} `json:"result"`
Completed bool `json:"completed"`
}
ToolCallInfo represents a tool call
type ToolResultContentBlock ¶
type ToolResultContentBlock struct {
Type string `json:"type"`
ToolUseID string `json:"tool_use_id"`
Content string `json:"content"`
IsError bool `json:"is_error,omitempty"`
}
ToolResultContentBlock represents tool result content (within message content array)
func (*ToolResultContentBlock) GetContentType ¶
func (b *ToolResultContentBlock) GetContentType() string
GetContentType implements ContentBlock
type ToolResultMessage ¶
type ToolResultMessage struct {
Type string `json:"type"`
Output string `json:"output,omitempty"` // String output
Content []ContentBlock `json:"content,omitempty"` // Or structured content
ToolUseID string `json:"tool_use_id"`
IsError bool `json:"is_error,omitempty"`
SessionID string `json:"session_id,omitempty"`
Timestamp time.Time `json:"timestamp,omitempty"`
}
ToolResultMessage represents a tool result message
func (*ToolResultMessage) GetRawData ¶
func (m *ToolResultMessage) GetRawData() map[string]interface{}
GetRawData implements Message
func (*ToolResultMessage) GetTimestamp ¶
func (m *ToolResultMessage) GetTimestamp() time.Time
GetTimestamp implements Message
func (*ToolResultMessage) GetType ¶
func (m *ToolResultMessage) GetType() string
GetType implements Message
type ToolUseBlock ¶
type ToolUseBlock struct {
Type string `json:"type"`
ID string `json:"id"`
Name string `json:"name"`
Input map[string]interface{} `json:"input"`
}
ToolUseBlock represents a tool use invocation
func (*ToolUseBlock) GetContentType ¶
func (b *ToolUseBlock) GetContentType() string
GetContentType implements ContentBlock
type ToolUseMessage ¶
type ToolUseMessage struct {
Type string `json:"type"`
Name string `json:"name"`
Input map[string]interface{} `json:"input"`
ToolUseID string `json:"tool_use_id"`
SessionID string `json:"session_id,omitempty"`
Timestamp time.Time `json:"timestamp,omitempty"`
}
ToolUseMessage represents a standalone tool use message (from stream)
func (*ToolUseMessage) GetRawData ¶
func (m *ToolUseMessage) GetRawData() map[string]interface{}
GetRawData implements Message
func (*ToolUseMessage) GetTimestamp ¶
func (m *ToolUseMessage) GetTimestamp() time.Time
GetTimestamp implements Message
func (*ToolUseMessage) GetType ¶
func (m *ToolUseMessage) GetType() string
GetType implements Message
type Transport ¶ added in v0.260507.1
type Transport struct {
// contains filtered or unexported fields
}
Transport implements agentboot.AgentTransport for the Claude Code CLI.
It is pure: it parses common.Event values into classifications and accumulated messages, and encodes control responses into the wire shape Claude expects on stdin. It performs no IO and owns no goroutines; the runner drives the lifecycle.
func NewTransport ¶ added in v0.260507.1
func NewTransport() *Transport
NewTransport creates a new Claude Transport.
func (*Transport) AccumulateMessage ¶ added in v0.260507.1
AccumulateMessage feeds the event to the per-agent accumulator and returns 0+ rich claude.Message values for the runner to wrap as MessageEvents. Implements agentboot.AgentTransport.
func (*Transport) Classify ¶ added in v0.260507.1
Classify reports the kind of event and, for control events, the parsed StreamEvent ready to emit on the handle. Implements agentboot.AgentTransport.
func (*Transport) EncodeControlResponse ¶ added in v0.260507.1
func (t *Transport) EncodeControlResponse(reqID string, resp agentboot.ControlResponse, originalInput map[string]any) any
EncodeControlResponse converts a agentboot.ControlResponse into the wire payload Claude expects on stdin. Implements agentboot.AgentTransport.
func (*Transport) SetExecutionContext ¶ added in v0.260507.1
SetExecutionContext injects routing metadata before an execution begins. Implements agentboot.AgentTransport.
type UnknownBlock ¶
type UnknownBlock struct {
Data map[string]interface{}
}
UnknownBlock represents an unrecognized content block
func (*UnknownBlock) GetContentType ¶
func (b *UnknownBlock) GetContentType() string
GetContentType implements ContentBlock
type UsageInfo ¶
type UsageInfo struct {
InputTokens int `json:"input_tokens"`
CacheCreationInputTokens int `json:"cache_creation_input_tokens,omitempty"`
CacheReadInputTokens int `json:"cache_read_input_tokens,omitempty"`
OutputTokens int `json:"output_tokens"`
}
UsageInfo contains token usage statistics
type UserMessage ¶
type UserMessage struct {
Type string `json:"type"`
Message string `json:"message"`
ParentToolUseID *string `json:"parent_tool_use_id,omitempty"`
SessionID string `json:"session_id,omitempty"`
Timestamp time.Time `json:"timestamp,omitempty"`
}
UserMessage represents user messages
func (*UserMessage) GetRawData ¶
func (m *UserMessage) GetRawData() map[string]interface{}
GetRawData implements Message
func (*UserMessage) GetTimestamp ¶
func (m *UserMessage) GetTimestamp() time.Time
GetTimestamp implements Message