Documentation
¶
Index ¶
- func CalculateCost(inputTokens, outputTokens, cacheRead, cacheWrite int64) float64
- func ExtractInstanceIDFromSession(sessionName string) string
- func ExtractSessionAndInstanceID(sessionName string) (sessionID, instanceID string)
- func FormatCost(cost float64) string
- func FormatTokens(tokens int64) string
- func ListClaudioTmuxSessions() ([]string, error)
- func ListSessionTmuxSessions(sessionID string) ([]string, error)
- type BellCallback
- type Detector
- type Manager
- func (m *Manager) AttachCommand() string
- func (m *Manager) ClearTimeout()
- func (m *Manager) CurrentMetrics() *ParsedMetrics
- func (m *Manager) CurrentState() WaitingState
- func (m *Manager) GetOutput() []byte
- func (m *Manager) ID() string
- func (m *Manager) LastActivityTime() time.Time
- func (m *Manager) PID() int
- func (m *Manager) Pause() error
- func (m *Manager) Paused() bool
- func (m *Manager) Reconnect() error
- func (m *Manager) Resize(width, height int) error
- func (m *Manager) Resume() error
- func (m *Manager) Running() bool
- func (m *Manager) SendInput(data []byte)
- func (m *Manager) SendKey(key string)
- func (m *Manager) SendLiteral(text string)
- func (m *Manager) SendPaste(text string)
- func (m *Manager) SessionName() string
- func (m *Manager) SetBellCallback(cb BellCallback)
- func (m *Manager) SetMetricsCallback(cb MetricsChangeCallback)
- func (m *Manager) SetStateCallback(cb StateChangeCallback)
- func (m *Manager) SetTimeoutCallback(cb TimeoutCallback)
- func (m *Manager) Start() error
- func (m *Manager) StartTime() *time.Time
- func (m *Manager) Stop() error
- func (m *Manager) TimedOut() (bool, TimeoutType)
- func (m *Manager) TmuxSessionExists() bool
- type ManagerConfig
- type MetricsChangeCallback
- type MetricsParser
- type PRWorkflow
- type PRWorkflowCallback
- type PRWorkflowConfig
- type ParsedMetrics
- type RingBuffer
- type StateChangeCallback
- type TimeoutCallback
- type TimeoutType
- type WaitingState
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CalculateCost ¶
CalculateCost estimates the cost based on token counts using Claude API pricing Pricing as of 2024 for Claude 3.5 Sonnet (the model used by Claude Code): - Input: $3.00 per 1M tokens - Output: $15.00 per 1M tokens - Cache read: $0.30 per 1M tokens - Cache write: $3.75 per 1M tokens
func ExtractInstanceIDFromSession ¶
ExtractInstanceIDFromSession extracts the instance ID from a claudio tmux session name. Supports both legacy format (claudio-{instanceID}) and new format (claudio-{sessionID}-{instanceID}). For PR workflow sessions (claudio-{id}-pr or claudio-{sessionID}-{id}-pr), removes the -pr suffix first.
func ExtractSessionAndInstanceID ¶
ExtractSessionAndInstanceID extracts both session ID and instance ID from a tmux session name. Returns (sessionID, instanceID). For legacy format, sessionID will be empty. For PR workflow sessions, removes the -pr suffix first.
func FormatCost ¶
FormatCost formats a cost value for display (e.g., "$0.42")
func FormatTokens ¶
FormatTokens formats a token count for display (e.g., "45.2K")
func ListClaudioTmuxSessions ¶
ListClaudioTmuxSessions returns a list of all tmux sessions with the claudio- prefix
func ListSessionTmuxSessions ¶
ListSessionTmuxSessions returns tmux sessions for a specific Claudio session. Filters by session ID prefix in the tmux session name.
Types ¶
type BellCallback ¶
type BellCallback func(instanceID string)
BellCallback is called when a terminal bell is detected in the tmux session
type Detector ¶
type Detector struct {
// contains filtered or unexported fields
}
Detector analyzes Claude's output to determine if it's waiting for user input
func (*Detector) Detect ¶
func (d *Detector) Detect(output []byte) WaitingState
Detect analyzes output and returns the detected waiting state It examines the last portion of output (most recent content) for patterns
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager handles a single Claude Code instance running in a tmux session
func NewManager ¶
NewManager creates a new instance manager with default configuration
func NewManagerWithConfig ¶
func NewManagerWithConfig(id, workdir, task string, cfg ManagerConfig) *Manager
NewManagerWithConfig creates a new instance manager with the given configuration. Uses legacy tmux naming (claudio-{instanceID}) for backwards compatibility.
func NewManagerWithSession ¶
func NewManagerWithSession(sessionID, id, workdir, task string, cfg ManagerConfig) *Manager
NewManagerWithSession creates a new instance manager with session-scoped tmux naming. The tmux session will be named claudio-{sessionID}-{instanceID} to prevent collisions when multiple Claudio sessions are running simultaneously.
func (*Manager) AttachCommand ¶
AttachCommand returns the command to attach to this instance's tmux session This allows users to attach directly if needed
func (*Manager) ClearTimeout ¶
func (m *Manager) ClearTimeout()
ClearTimeout resets the timeout state (for recovery/restart scenarios)
func (*Manager) CurrentMetrics ¶
func (m *Manager) CurrentMetrics() *ParsedMetrics
CurrentMetrics returns the currently parsed metrics
func (*Manager) CurrentState ¶
func (m *Manager) CurrentState() WaitingState
CurrentState returns the currently detected waiting state
func (*Manager) LastActivityTime ¶
LastActivityTime returns when the instance last had output activity
func (*Manager) Reconnect ¶
Reconnect attempts to reconnect to an existing tmux session This is used for session recovery after a restart
func (*Manager) Resize ¶
Resize changes the tmux pane dimensions This is useful when the display area changes (e.g., sidebar added/removed)
func (*Manager) SendLiteral ¶
SendLiteral sends literal text to the tmux session (no interpretation)
func (*Manager) SendPaste ¶
SendPaste sends pasted text to the tmux session with bracketed paste sequences This preserves the paste context for applications that support bracketed paste mode
func (*Manager) SessionName ¶
SessionName returns the tmux session name
func (*Manager) SetBellCallback ¶
func (m *Manager) SetBellCallback(cb BellCallback)
SetBellCallback sets a callback that will be invoked when a terminal bell is detected
func (*Manager) SetMetricsCallback ¶
func (m *Manager) SetMetricsCallback(cb MetricsChangeCallback)
SetMetricsCallback sets a callback that will be invoked when metrics are updated
func (*Manager) SetStateCallback ¶
func (m *Manager) SetStateCallback(cb StateChangeCallback)
SetStateCallback sets a callback that will be invoked when the detected state changes
func (*Manager) SetTimeoutCallback ¶
func (m *Manager) SetTimeoutCallback(cb TimeoutCallback)
SetTimeoutCallback sets a callback that will be invoked when a timeout is detected
func (*Manager) TimedOut ¶
func (m *Manager) TimedOut() (bool, TimeoutType)
TimedOut returns whether the instance has timed out and the type of timeout
func (*Manager) TmuxSessionExists ¶
TmuxSessionExists checks if the tmux session for this instance exists
type ManagerConfig ¶
type ManagerConfig struct {
OutputBufferSize int
CaptureIntervalMs int
TmuxWidth int
TmuxHeight int
ActivityTimeoutMinutes int // 0 = disabled
CompletionTimeoutMinutes int // 0 = disabled
StaleDetection bool // Enable repeated output detection
}
ManagerConfig holds configuration for instance management
func DefaultManagerConfig ¶
func DefaultManagerConfig() ManagerConfig
DefaultManagerConfig returns the default manager configuration
type MetricsChangeCallback ¶
type MetricsChangeCallback func(instanceID string, metrics *ParsedMetrics)
MetricsChangeCallback is called when metrics are updated
type MetricsParser ¶
type MetricsParser struct {
// contains filtered or unexported fields
}
MetricsParser extracts resource metrics from Claude Code output
func NewMetricsParser ¶
func NewMetricsParser() *MetricsParser
NewMetricsParser creates a new metrics parser
func (*MetricsParser) Parse ¶
func (p *MetricsParser) Parse(output []byte) *ParsedMetrics
Parse extracts metrics from Claude Code output text
type PRWorkflow ¶
type PRWorkflow struct {
// contains filtered or unexported fields
}
PRWorkflow manages the commit-push-PR workflow after an instance is stopped
func NewPRWorkflow ¶
func NewPRWorkflow(instanceID, workdir, branch, task string, cfg PRWorkflowConfig) *PRWorkflow
NewPRWorkflow creates a new PR workflow manager. Uses legacy tmux naming (claudio-{instanceID}-pr) for backwards compatibility.
func NewPRWorkflowWithSession ¶
func NewPRWorkflowWithSession(sessionID, instanceID, workdir, branch, task string, cfg PRWorkflowConfig) *PRWorkflow
NewPRWorkflowWithSession creates a new PR workflow manager with session-scoped tmux naming. The tmux session will be named claudio-{sessionID}-{instanceID}-pr to prevent collisions when multiple Claudio sessions are running simultaneously.
func (*PRWorkflow) GetOutput ¶
func (p *PRWorkflow) GetOutput() []byte
GetOutput returns the buffered output from the PR workflow
func (*PRWorkflow) Running ¶
func (p *PRWorkflow) Running() bool
Running returns whether the PR workflow is running
func (*PRWorkflow) SessionName ¶
func (p *PRWorkflow) SessionName() string
SessionName returns the tmux session name
func (*PRWorkflow) SetCallback ¶
func (p *PRWorkflow) SetCallback(cb PRWorkflowCallback)
SetCallback sets the completion callback
func (*PRWorkflow) Start ¶
func (p *PRWorkflow) Start() error
Start launches the PR workflow in a tmux session
func (*PRWorkflow) Stop ¶
func (p *PRWorkflow) Stop() error
Stop terminates the PR workflow tmux session
type PRWorkflowCallback ¶
PRWorkflowCallback is called when the PR workflow completes
type PRWorkflowConfig ¶
PRWorkflowConfig holds configuration for the PR workflow
type ParsedMetrics ¶
type ParsedMetrics struct {
InputTokens int64
OutputTokens int64
CacheRead int64
CacheWrite int64
Cost float64
APICalls int
}
ParsedMetrics holds metrics extracted from Claude Code output
type RingBuffer ¶
type RingBuffer struct {
// contains filtered or unexported fields
}
RingBuffer is a thread-safe ring buffer for output
func NewRingBuffer ¶
func NewRingBuffer(size int) *RingBuffer
NewRingBuffer creates a new ring buffer with the given capacity
func (*RingBuffer) Len ¶
func (r *RingBuffer) Len() int
Len returns the number of bytes in the buffer
type StateChangeCallback ¶
type StateChangeCallback func(instanceID string, state WaitingState)
StateChangeCallback is called when the detected waiting state changes
type TimeoutCallback ¶
type TimeoutCallback func(instanceID string, timeoutType TimeoutType)
TimeoutCallback is called when a timeout condition is detected
type TimeoutType ¶
type TimeoutType int
TimeoutType represents the type of timeout that occurred
const ( TimeoutActivity TimeoutType = iota // No activity for configured period TimeoutCompletion // Total runtime exceeded limit TimeoutStale // Repeated output detected (stuck in loop) )
type WaitingState ¶
type WaitingState int
WaitingState represents different types of waiting conditions Claude can be in
const ( // StateWorking means Claude is actively working (not waiting) StateWorking WaitingState = iota // StateWaitingPermission means Claude is asking for permission to perform an action StateWaitingPermission // StateWaitingQuestion means Claude is asking the user a question StateWaitingQuestion // StateWaitingInput means Claude is waiting for general input StateWaitingInput // StateCompleted means Claude has finished its task StateCompleted // StateError means Claude encountered an error StateError // StatePROpened means Claude opened a pull request (PR URL detected in output) StatePROpened )
func (WaitingState) IsWaiting ¶
func (s WaitingState) IsWaiting() bool
IsWaiting returns true if the state represents any waiting condition
func (WaitingState) String ¶
func (s WaitingState) String() string
String returns a human-readable string for the waiting state