Documentation
¶
Overview ¶
Package claude implements the Claude CLI process manager.
Package claude implements the Claude CLI process manager.
Package claude implements the Claude CLI process manager.
Package claude implements the Claude CLI process manager.
Index ¶
- func AppendBashToSession(workDir, sessionID, command, stdout, stderr string) error
- func DeleteAllSessions(repoPath string) (int, error)
- func DeleteSession(repoPath, sessionID string) error
- func GetSessionsDir(repoPath string) string
- type ANSIParser
- type Manager
- func (m *Manager) ClaudeSessionID() string
- func (m *Manager) CurrentPrompt() string
- func (m *Manager) GetPendingPTYPermission() *PTYPermissionPrompt
- func (m *Manager) GetPendingToolUse() (toolUseID, toolName string)
- func (m *Manager) HasPendingPermission() bool
- func (m *Manager) IsPTYMode() bool
- func (m *Manager) IsRunning() bool
- func (m *Manager) IsWaitingForInput() bool
- func (m *Manager) Kill() error
- func (m *Manager) PID() int
- func (m *Manager) SendPTYInput(input string) error
- func (m *Manager) SendResponse(toolUseID string, response string, isError bool) error
- func (m *Manager) SessionID() string
- func (m *Manager) SetLogDir(dir string)
- func (m *Manager) SetOnPTYComplete(callback func(sessionID string))
- func (m *Manager) SetSessionID(newID string)
- func (m *Manager) SetWorkDir(dir string)
- func (m *Manager) Start(ctx context.Context, prompt string) error
- func (m *Manager) StartWithPTY(ctx context.Context, prompt string, mode SessionMode, sessionID string, ...) error
- func (m *Manager) StartWithSession(ctx context.Context, prompt string, mode SessionMode, sessionID string, ...) error
- func (m *Manager) State() events.ClaudeState
- func (m *Manager) Stop(ctx context.Context) error
- func (m *Manager) WorkspaceID() string
- type PTYParser
- type PTYPermissionPrompt
- type PTYState
- type ParsedLine
- type PermissionType
- type PromptOption
- type SessionInfo
- type SessionMessage
- type SessionMode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendBashToSession ¶
AppendBashToSession writes bash command execution to a session JSONL file. This uses the same format as Claude Code for compatibility. Returns the UUIDs of the generated messages.
func DeleteAllSessions ¶
DeleteAllSessions deletes all session files for a repository.
func DeleteSession ¶
DeleteSession deletes a specific session file.
func GetSessionsDir ¶
GetSessionsDir exports the sessions directory path for a repo.
Types ¶
type ANSIParser ¶
type ANSIParser struct {
// contains filtered or unexported fields
}
ANSIParser handles terminal escape code processing. It can strip ANSI codes for clean text display or extract formatting info.
func (*ANSIParser) ContainsText ¶
func (p *ANSIParser) ContainsText(line, text string) bool
ContainsText checks if the line contains the given text (after stripping ANSI codes).
func (*ANSIParser) IsEmptyLine ¶
func (p *ANSIParser) IsEmptyLine(line string) bool
IsEmptyLine returns true if the line contains only whitespace or control codes.
func (*ANSIParser) ParseLine ¶
func (p *ANSIParser) ParseLine(raw string) *ParsedLine
ParseLine extracts clean text from a raw terminal line.
func (*ANSIParser) StripCodes ¶
func (p *ANSIParser) StripCodes(text string) string
StripCodes removes all ANSI escape codes and control characters from text.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager implements the ClaudeManager port interface.
func NewManager ¶
func NewManager(command string, args []string, timeoutMinutes int, hub ports.EventHub, skipPermissions bool, rotationConfig *config.LogRotationConfig) *Manager
NewManager creates a new Claude CLI manager (legacy constructor for backward compatibility).
func NewManagerWithContext ¶
func NewManagerWithContext(hub ports.EventHub, command string, args []string, timeoutMinutes int, skipPermissions bool, workDir, workspaceID, sessionID string, rotationConfig *config.LogRotationConfig) *Manager
NewManagerWithContext creates a new Claude CLI manager with workspace/session context. This is the preferred constructor for multi-workspace support.
func (*Manager) ClaudeSessionID ¶
ClaudeSessionID returns the current Claude CLI session ID.
func (*Manager) CurrentPrompt ¶
CurrentPrompt returns the current prompt if running.
func (*Manager) GetPendingPTYPermission ¶
func (m *Manager) GetPendingPTYPermission() *PTYPermissionPrompt
GetPendingPTYPermission returns the pending PTY permission prompt if any. Used when client reconnects to re-show the permission dialog.
func (*Manager) GetPendingToolUse ¶
GetPendingToolUse returns the pending tool use info if waiting for input.
func (*Manager) HasPendingPermission ¶
HasPendingPermission returns true if there's a pending permission request.
func (*Manager) IsWaitingForInput ¶
IsWaitingForInput returns true if Claude is waiting for user input.
func (*Manager) SendPTYInput ¶
SendPTYInput sends input to the PTY (for interactive responses). This allows remote clients to respond to permission prompts. For regular text input, a carriage return is automatically appended. For special keys (escape sequences, control characters), the input is sent as-is.
func (*Manager) SendResponse ¶
SendResponse sends a user response to Claude's stdin for interactive prompts.
func (*Manager) SetOnPTYComplete ¶
SetOnPTYComplete sets a callback that's called when PTY streaming finishes. Used by session manager to emit claude_message with stop_reason.
func (*Manager) SetSessionID ¶
SetSessionID updates the session ID for this manager. This is called when the real session ID is detected from Claude's session file. Thread-safe: uses mutex to protect concurrent access.
func (*Manager) SetWorkDir ¶
SetWorkDir sets the working directory for Claude CLI.
func (*Manager) StartWithPTY ¶
func (m *Manager) StartWithPTY(ctx context.Context, prompt string, mode SessionMode, sessionID string, yoloMode bool) error
StartWithPTY spawns Claude CLI with a pseudo-terminal for true interactive support. This allows permission prompts to work interactively from remote clients. The PTY makes Claude think it's running in a real terminal. If prompt is empty, Claude starts in interactive mode waiting for user input.
func (*Manager) StartWithSession ¶
func (m *Manager) StartWithSession(ctx context.Context, prompt string, mode SessionMode, sessionID string, permissionMode string) error
StartWithSession spawns Claude CLI with session control. permissionMode controls how Claude handles permissions: - "" or "default": Use skipPermissions config setting - "acceptEdits": Auto-accept file edits - "bypassPermissions": Skip all permission checks - "plan": Plan mode only
func (*Manager) State ¶
func (m *Manager) State() events.ClaudeState
State returns the current state.
func (*Manager) WorkspaceID ¶
WorkspaceID returns the workspace ID for this manager.
type PTYParser ¶
type PTYParser struct {
// contains filtered or unexported fields
}
PTYParser detects and parses interactive prompts from terminal output.
func (*PTYParser) IsWaitingForInput ¶
IsWaitingForInput returns true if in a state that requires user input.
func (*PTYParser) ProcessLine ¶
func (p *PTYParser) ProcessLine(rawLine string) (*PTYPermissionPrompt, PTYState)
ProcessLine processes a single line of PTY output. Returns a permission prompt if one is detected, nil otherwise.
type PTYPermissionPrompt ¶
type PTYPermissionPrompt struct {
Type PermissionType `json:"type"`
Target string `json:"target"` // filename or command
Description string `json:"description"` // full description
Preview string `json:"preview"` // file content preview or command
Options []PromptOption `json:"options"`
}
PTYPermissionPrompt represents a detected permission request.
type ParsedLine ¶
type ParsedLine struct {
RawText string `json:"raw_text"` // Original text with ANSI codes
CleanText string `json:"clean_text"` // Text with ANSI codes stripped
}
ParsedLine contains both raw and clean versions of a terminal line.
type PermissionType ¶
type PermissionType string
PermissionType identifies what Claude wants to do.
const ( PermissionTypeWriteFile PermissionType = "write_file" PermissionTypeEditFile PermissionType = "edit_file" PermissionTypeDeleteFile PermissionType = "delete_file" PermissionTypeBashCommand PermissionType = "bash_command" PermissionTypeMCP PermissionType = "mcp_tool" PermissionTypeTrustFolder PermissionType = "trust_folder" PermissionTypeUnknown PermissionType = "unknown" )
type PromptOption ¶
type PromptOption struct {
Key string `json:"key"` // "1", "2", "n", etc.
Label string `json:"label"` // "Yes", "Yes to all", "No"
Description string `json:"description,omitempty"` // optional extra info
Selected bool `json:"selected"` // true if this option has the cursor (❯)
}
PromptOption represents a choice in a permission prompt.
type SessionInfo ¶
type SessionInfo struct {
SessionID string `json:"session_id"`
Summary string `json:"summary"`
MessageCount int `json:"message_count"`
LastUpdated time.Time `json:"last_updated"`
Branch string `json:"branch,omitempty"`
}
SessionInfo represents information about a stored Claude session.
func ListSessions ¶
func ListSessions(repoPath string) ([]SessionInfo, error)
ListSessions returns all available sessions for a repository.
type SessionMessage ¶
type SessionMessage struct {
Type string `json:"type"`
UUID string `json:"uuid,omitempty"`
SessionID string `json:"session_id,omitempty"` // snake_case for API response
Timestamp string `json:"timestamp,omitempty"`
GitBranch string `json:"git_branch,omitempty"` // snake_case for API response
Message json.RawMessage `json:"message"`
}
SessionMessage represents a single message in a session for API response. Uses snake_case for consistency with WebSocket events.
func GetSessionMessages ¶
func GetSessionMessages(repoPath, sessionID string) ([]SessionMessage, error)
GetSessionMessages returns all messages for a specific session. Returns raw JSON messages to preserve token usage and other metadata.
type SessionMode ¶
type SessionMode string
SessionMode defines how to handle conversation sessions.
const ( // SessionModeNew starts a new conversation (default). SessionModeNew SessionMode = "new" // SessionModeContinue continues a conversation by session ID. // Requires session_id parameter. SessionModeContinue SessionMode = "continue" )