actor

package
v0.0.0-...-75ec8e3 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultRPZURL = "https://raw.githubusercontent.com/hagezi/dns-blocklists/refs/heads/main/rpz/tif.txt"

DefaultRPZURL is the default RPZ blocklist URL

View Source
const MirrorRPZURL = "https://codeberg.org/hagezi/mirror2/raw/branch/main/dns-blocklists/rpz/tif.txt"

MirrorRPZURL is the mirror URL for the RPZ blocklist

Variables

View Source
var SystemEventBus = NewEventBus(1000)

SystemEventBus is the global event bus instance for the actor system

Functions

func DebugHealthScenario

func DebugHealthScenario()

DebugHealthScenario shows what's happening in the test

func DeleteSessionViaActor

func DeleteSessionViaActor(ctx context.Context, storageRef *ActorRef, workingDir, sessionID string) error

DeleteSession removes a session from persistent storage

func GenerateSessionName

func GenerateSessionName(baseName string) string

GenerateSessionName generates a session name with timestamp

func GetMostRecentSessionViaActor

func GetMostRecentSessionViaActor(ctx context.Context, storageRef *ActorRef, workingDir string) (*session.Session, error)

GetMostRecentSessionViaActor gets the most recently updated session for a workspace

func ListSessionsViaActor

func ListSessionsViaActor(ctx context.Context, storageRef *ActorRef, workingDir string) ([]session.SessionMetadata, error)

ListSessions returns all sessions for a workspace

func LoadSessionViaActor

func LoadSessionViaActor(ctx context.Context, storageRef *ActorRef, workingDir, sessionID string) (*session.Session, error)

LoadSession loads a session from persistent storage

func PublishEvent

func PublishEvent(eventType EventType, source, sessionID string, data map[string]interface{})

PublishEvent is a convenience function to publish an event to the system event bus

func SaveSessionViaActor

func SaveSessionViaActor(ctx context.Context, storageRef *ActorRef, session *session.Session, name string) error

SaveSession saves a session to persistent storage

func StartAutoSaveViaActor

func StartAutoSaveViaActor(ctx context.Context, storageRef *ActorRef, session *session.Session, name string) error

StartAutoSaveViaActor starts automatic saving for a session

func StopAutoSaveViaActor

func StopAutoSaveViaActor(ctx context.Context, storageRef *ActorRef) error

StopAutoSaveViaActor stops automatic saving for the current session

Types

type Actor

type Actor interface {
	// Receive processes incoming messages
	Receive(ctx context.Context, msg Message) error
	// Start starts the actor
	Start(ctx context.Context) error
	// Stop stops the actor gracefully
	Stop(ctx context.Context) error
	// ID returns the actor's unique identifier
	ID() string
}

Actor represents an actor in the actor model

type ActorEventPublisher

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

ActorEventPublisher provides actors with an easy way to publish events

func NewActorEventPublisher

func NewActorEventPublisher(actorID, sessionID string) *ActorEventPublisher

NewActorEventPublisher creates a new event publisher for an actor

func (*ActorEventPublisher) Publish

func (p *ActorEventPublisher) Publish(eventType EventType, data map[string]interface{})

Publish publishes an event to the system event bus

func (*ActorEventPublisher) PublishAuthorization

func (p *ActorEventPublisher) PublishAuthorization(authID, toolName, reason string, parameters map[string]interface{})

PublishAuthorization publishes an authorization request event

func (*ActorEventPublisher) PublishError

func (p *ActorEventPublisher) PublishError(code, message string)

PublishError publishes an error event

func (*ActorEventPublisher) PublishMessage

func (p *ActorEventPublisher) PublishMessage(role, content string)

PublishMessage publishes a chat message event

func (*ActorEventPublisher) PublishProgress

func (p *ActorEventPublisher) PublishProgress(message string, ephemeral bool)

PublishProgress publishes a progress update event

func (*ActorEventPublisher) PublishQuestion

func (p *ActorEventPublisher) PublishQuestion(questionID, question string, multiMode bool)

PublishQuestion publishes a question request event

func (*ActorEventPublisher) PublishStatus

func (p *ActorEventPublisher) PublishStatus(status string, details map[string]interface{})

PublishStatus publishes a status update event

func (*ActorEventPublisher) PublishToolCall

func (p *ActorEventPublisher) PublishToolCall(toolID, toolName string, parameters map[string]interface{})

PublishToolCall publishes a tool call event

func (*ActorEventPublisher) PublishToolResult

func (p *ActorEventPublisher) PublishToolResult(toolID, result, errorMsg string)

PublishToolResult publishes a tool result event

func (*ActorEventPublisher) WithSession

func (p *ActorEventPublisher) WithSession(sessionID string) *ActorEventPublisher

WithSession returns a new publisher with a different session ID

type ActorRef

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

ActorRef is a reference to an actor for sending messages

func NewActorRef

func NewActorRef(id string, actor Actor, mailboxSize int, opts ...ActorRefOption) *ActorRef

NewActorRef creates a new actor reference with the given ID, actor implementation, mailbox size, and optional configuration options.

func (*ActorRef) EventPublisher

func (ref *ActorRef) EventPublisher() *ActorEventPublisher

EventPublisher returns the actor's event publisher for sending events to frontends

func (*ActorRef) ID

func (ref *ActorRef) ID() string

ID returns the actor's ID

func (*ActorRef) Send

func (ref *ActorRef) Send(msg Message) error

Send sends a message to the actor (non-blocking)

func (*ActorRef) SetSessionID

func (ref *ActorRef) SetSessionID(sessionID string)

SetSessionID sets the session ID for event publishing

func (*ActorRef) Start

func (ref *ActorRef) Start(ctx context.Context) error

Start starts the actor's message processing loop

func (*ActorRef) Stop

func (ref *ActorRef) Stop(ctx context.Context) error

Stop stops the actor gracefully

type ActorRefOption

type ActorRefOption func(*ActorRef)

NewActorRef creates a new actor reference

func WithSequentialProcessing

func WithSequentialProcessing() ActorRefOption

WithSequentialProcessing forces the actor to process messages synchronously when sent. This disables the internal run loop and makes Send block until Receive returns.

type AuthorizationPayload

type AuthorizationPayload struct {
	// ToolName is the name of the tool requesting authorization
	ToolName string
	// Parameters are the tool's parameters
	Parameters map[string]interface{}
	// Reason explains why authorization is needed
	Reason string
	// SuggestedPrefix is a command prefix suggested for permanent authorization
	SuggestedPrefix string
	// SuggestedDomain is a domain pattern suggested for permanent authorization
	SuggestedDomain string
	// IsCommandAuth indicates this is a shell command authorization
	IsCommandAuth bool
	// IsDomainAuth indicates this is a network domain authorization
	IsDomainAuth bool
}

AuthorizationPayload contains data for authorization requests

type BlocklistDownloader

type BlocklistDownloader interface {
	// DownloadBlocklist downloads the blocklist from the configured URL
	DownloadBlocklist(ctx context.Context, url string) (io.ReadCloser, error)

	// GetLastModified returns the last modified time of the blocklist (if available)
	GetLastModified(ctx context.Context, url string) (time.Time, error)

	// IsHealthy returns true if the downloader is functioning properly
	IsHealthy() bool
}

BlocklistDownloader defines the interface for downloading blocklists

type BlocklistDownloaderConfig

type BlocklistDownloaderConfig struct {
	HTTPClient HTTPClient
	Timeout    time.Duration
	UserAgent  string
}

BlocklistDownloaderConfig holds configuration for a blocklist downloader

func DefaultBlocklistDownloaderConfig

func DefaultBlocklistDownloaderConfig() BlocklistDownloaderConfig

DefaultBlocklistDownloaderConfig returns the default configuration

type BlocklistStats

type BlocklistStats struct {
	DomainCount     int
	LastUpdated     time.Time
	BlocklistURL    string
	RefreshInterval time.Duration
	TTL             time.Duration
	Expired         bool
	CacheEnabled    bool
	CacheDir        string // Empty if cache is disabled
}

BlocklistStats contains statistics about the domain blocklist

type BlocklistStatsResponse

type BlocklistStatsResponse struct {
	DomainCount     int
	LastUpdated     time.Time
	BlocklistURL    string
	RefreshInterval time.Duration
	TTL             time.Duration
	Expired         bool
	CacheEnabled    bool
	CacheDir        string // Empty if cache is disabled
}

BlocklistStatsResponse contains statistics about the current blocklist

type CounterMessage

type CounterMessage struct{}

CounterMessage is used for counting operations

func (*CounterMessage) Type

func (m *CounterMessage) Type() string

type DomainBlockRequest

type DomainBlockRequest struct {
	Domain     string
	ResponseCh chan DomainBlockResponse
}

DomainBlockRequest asks whether a domain is blocked

func (DomainBlockRequest) Type

func (DomainBlockRequest) Type() string

type DomainBlockResponse

type DomainBlockResponse struct {
	Blocked bool
	Reason  string
}

DomainBlockResponse contains the result of a domain block check

type DomainBlockerActor

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

DomainBlockerActor handles domain blocking based on RPZ lists

func NewDomainBlockerActor

func NewDomainBlockerActor(id string, config DomainBlockerConfig) *DomainBlockerActor

NewDomainBlockerActor creates a new domain blocker actor

func (*DomainBlockerActor) GetDownloader

func (a *DomainBlockerActor) GetDownloader() BlocklistDownloader

GetDownloader returns the blocklist downloader (for testing)

func (*DomainBlockerActor) ID

func (a *DomainBlockerActor) ID() string

ID returns the actor's ID

func (*DomainBlockerActor) IsDomainBlocked

func (a *DomainBlockerActor) IsDomainBlocked(domain string) (bool, string)

IsDomainBlocked checks if a domain is in the blocklist

func (*DomainBlockerActor) IsInitialized

func (a *DomainBlockerActor) IsInitialized() bool

IsInitialized returns true if the blocklist has been initialized

func (*DomainBlockerActor) ParseRPZResponse

func (a *DomainBlockerActor) ParseRPZResponse(body io.Reader) ([]string, error)

parseRPZResponse parses an RPZ format response and extracts domains

func (*DomainBlockerActor) Receive

func (a *DomainBlockerActor) Receive(ctx context.Context, msg Message) error

Receive handles incoming messages

func (*DomainBlockerActor) Start

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

Start initializes the actor and starts background loading of the blocklist

func (*DomainBlockerActor) Stop

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

Stop stops the actor and cancels any ongoing operations

type DomainBlockerClient

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

DomainBlockerClient provides a convenient interface for interacting with the domain blocker actor

func NewDomainBlockerClient

func NewDomainBlockerClient(actorRef *ActorRef) *DomainBlockerClient

NewDomainBlockerClient creates a new client for the domain blocker actor

func (*DomainBlockerClient) GetStats

GetStats returns current blocklist statistics

func (*DomainBlockerClient) IsDomainBlocked

func (c *DomainBlockerClient) IsDomainBlocked(ctx context.Context, domain string) (bool, string, error)

IsDomainBlocked checks if a domain is blocked

func (*DomainBlockerClient) RefreshBlocklist

func (c *DomainBlockerClient) RefreshBlocklist(ctx context.Context) (bool, int, error)

RefreshBlocklist forces a refresh of the blocklist

type DomainBlockerConfig

type DomainBlockerConfig struct {
	BlocklistURL    string
	RefreshInterval time.Duration
	TTL             time.Duration // TTL for the blocklist, after which it's considered stale
	CacheDir        string        // Directory to cache blocklist files
	Downloader      BlocklistDownloader
	HTTPClient      *http.Client // Deprecated: use Downloader instead
}

DomainBlockerConfig holds configuration for the domain blocker actor

type DomainBlockerMessage

type DomainBlockerMessage interface {
	Type() string
	// contains filtered or unexported methods
}

DomainBlockerMessage represents different message types for the domain blocker actor

type ErrorMessage

type ErrorMessage struct{}

ErrorMessage is used to trigger errors

func (*ErrorMessage) Type

func (m *ErrorMessage) Type() string

type Event

type Event struct {
	// Type is the event type
	Type EventType `json:"type"`
	// Source is the actor ID that published the event
	Source string `json:"source"`
	// SessionID is the session this event belongs to (if applicable)
	SessionID string `json:"session_id,omitempty"`
	// Data contains the event payload (type-specific)
	Data map[string]interface{} `json:"data"`
	// Timestamp is when the event was created
	Timestamp time.Time `json:"timestamp"`
}

Event represents an event that can be published by actors and consumed by frontends

type EventBus

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

EventBus is a publish-subscribe system for actor events It allows actors to publish events without knowing about subscribers, and frontends to subscribe to events without knowing about publishers.

func NewEventBus

func NewEventBus(bufferSize int) *EventBus

NewEventBus creates a new event bus with the specified buffer size

func (*EventBus) Close

func (eb *EventBus) Close()

Close shuts down the event bus

func (*EventBus) Publish

func (eb *EventBus) Publish(event Event)

Publish sends an event to all subscribers

func (*EventBus) PublishSync

func (eb *EventBus) PublishSync(event Event)

PublishSync sends an event synchronously (blocks until handlers complete)

func (*EventBus) Subscribe

func (eb *EventBus) Subscribe(eventType EventType, handler EventHandler)

Subscribe registers a handler for a specific event type

func (*EventBus) SubscribeAll

func (eb *EventBus) SubscribeAll(handler EventHandler)

SubscribeAll registers a handler that receives all events

func (*EventBus) Unsubscribe

func (eb *EventBus) Unsubscribe(eventType EventType, handler EventHandler)

Unsubscribe removes a handler for a specific event type

type EventHandler

type EventHandler func(event Event)

EventHandler is a function that handles events

type EventType

type EventType string

EventType represents the type of event being published

const (
	// EventTypeProgress indicates a progress update event
	EventTypeProgress EventType = "progress"
	// EventTypeMessage indicates a chat message event
	EventTypeMessage EventType = "message"
	// EventTypeToolCall indicates a tool execution event
	EventTypeToolCall EventType = "tool_call"
	// EventTypeToolResult indicates a tool execution result event
	EventTypeToolResult EventType = "tool_result"
	// EventTypeAuthorization indicates an authorization request event
	EventTypeAuthorization EventType = "authorization"
	// EventTypeQuestion indicates a question request event
	EventTypeQuestion EventType = "question"
	// EventTypeStatus indicates a status update event
	EventTypeStatus EventType = "status"
	// EventTypeError indicates an error event
	EventTypeError EventType = "error"
	// EventTypeSession indicates a session-related event
	EventTypeSession EventType = "session"
)

type GetBlocklistStatsRequest

type GetBlocklistStatsRequest struct {
	ResponseCh chan BlocklistStatsResponse
}

GetBlocklistStatsRequest requests current blocklist statistics

func (GetBlocklistStatsRequest) Type

type HTTPBlocklistDownloader

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

HTTPBlocklistDownloader implements BlocklistDownloader using HTTP

func NewHTTPBlocklistDownloader

func NewHTTPBlocklistDownloader(config BlocklistDownloaderConfig) *HTTPBlocklistDownloader

NewHTTPBlocklistDownloader creates a new HTTP blocklist downloader

func (*HTTPBlocklistDownloader) DownloadBlocklist

func (h *HTTPBlocklistDownloader) DownloadBlocklist(ctx context.Context, url string) (io.ReadCloser, error)

DownloadBlocklist downloads the blocklist from the specified URL

func (*HTTPBlocklistDownloader) GetLastModified

func (h *HTTPBlocklistDownloader) GetLastModified(ctx context.Context, url string) (time.Time, error)

GetLastModified returns the last modified time of the blocklist

func (*HTTPBlocklistDownloader) IsHealthy

func (h *HTTPBlocklistDownloader) IsHealthy() bool

IsHealthy returns true if the downloader is functioning properly

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient defines the interface for HTTP clients (for testing)

type HealthCheckActor

type HealthCheckActor interface {
	Actor

	// GetHealthMetrics returns current health metrics
	GetHealthMetrics() HealthMetrics

	// IsHealthy returns true if the actor is considered healthy
	IsHealthy() bool
}

HealthCheckActor extends the Actor interface with health check capabilities

type HealthCheckRequest

type HealthCheckRequest struct {
	ResponseChan chan HealthCheckResponse
}

HealthCheckRequest is a message to request health check of an actor

func (HealthCheckRequest) Type

func (HealthCheckRequest) Type() string

type HealthCheckResponse

type HealthCheckResponse struct {
	Report HealthReport
	Error  error
}

HealthCheckResponse contains the health assessment of an actor

type HealthCheckable

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

HealthCheckable provides a default health check implementation for actors

func NewHealthCheckable

func NewHealthCheckable(id string, mailbox chan Message, metricsProvider func() interface{}) *HealthCheckable

NewHealthCheckable creates a new health checkable component

func (*HealthCheckable) GenerateHealthReport

func (h *HealthCheckable) GenerateHealthReport() HealthReport

GenerateHealthReport creates a complete health report

func (*HealthCheckable) GetHealthMetrics

func (h *HealthCheckable) GetHealthMetrics() HealthMetrics

GetHealthMetrics returns current health metrics

func (*HealthCheckable) HealthCheckHandler

func (h *HealthCheckable) HealthCheckHandler(ctx context.Context, msg Message) error

HealthCheckHandler processes health check requests

func (*HealthCheckable) IsHealthy

func (h *HealthCheckable) IsHealthy() bool

IsHealthy returns true if the actor is considered healthy

func (*HealthCheckable) RecordActivity

func (h *HealthCheckable) RecordActivity()

RecordActivity updates the last activity timestamp

func (*HealthCheckable) RecordError

func (h *HealthCheckable) RecordError(err error)

RecordError records an error occurrence

type HealthMetrics

type HealthMetrics struct {
	// Message queue metrics
	MailboxDepth    int     `json:"mailbox_depth"`
	MailboxCapacity int     `json:"mailbox_capacity"`
	MailboxUsage    float64 `json:"mailbox_usage"` // percentage

	// Activity metrics
	LastActivityTime time.Time     `json:"last_activity_time"`
	StartTime        time.Time     `json:"start_time"`
	Uptime           time.Duration `json:"uptime"`

	// Error metrics
	ErrorCount   int64     `json:"error_count"`
	LastError    time.Time `json:"last_error,omitempty"`
	LastErrorMsg string    `json:"last_error_msg,omitempty"`

	// Actor-specific metrics
	CustomMetrics interface{} `json:"custom_metrics,omitempty"`
}

HealthMetrics contains health-related metrics for an actor

type HealthReport

type HealthReport struct {
	ActorID   string        `json:"actor_id"`
	Status    HealthStatus  `json:"status"`
	Metrics   HealthMetrics `json:"metrics"`
	Message   string        `json:"message"` // Human-readable description
	Timestamp time.Time     `json:"timestamp"`
}

HealthReport contains the complete health assessment of an actor

type HealthStatus

type HealthStatus string

HealthStatus represents the health status of an actor

const (
	HealthStatusHealthy   HealthStatus = "healthy"
	HealthStatusDegraded  HealthStatus = "degraded"
	HealthStatusUnhealthy HealthStatus = "unhealthy"
	HealthStatusUnknown   HealthStatus = "unknown"
)

type InteractionType

type InteractionType int

InteractionType identifies the kind of user interaction

const (
	// InteractionTypeAuthorization is for tool/command authorization requests
	InteractionTypeAuthorization InteractionType = iota
	// InteractionTypePlanningQuestion is for questions during planning phase
	InteractionTypePlanningQuestion
	// InteractionTypeUserInputSingle is for single text input from user
	InteractionTypeUserInputSingle
	// InteractionTypeUserInputMultiple is for multiple choice questions
	InteractionTypeUserInputMultiple
)

func (InteractionType) String

func (t InteractionType) String() string

String returns a human-readable name for the interaction type

type Message

type Message interface {
	Type() string
}

Message represents a message sent between actors

type MockHTTPClient

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

MockHTTPClient implements HTTPClient for testing

func NewMockHTTPClient

func NewMockHTTPClient() *MockHTTPClient

NewMockHTTPClient creates a new mock HTTP client

func (*MockHTTPClient) ClearError

func (m *MockHTTPClient) ClearError(url string)

ClearError clears a mock error for a URL

func (*MockHTTPClient) Do

func (m *MockHTTPClient) Do(req *http.Request) (*http.Response, error)

Do implements the HTTPClient interface

func (*MockHTTPClient) GetCallCount

func (m *MockHTTPClient) GetCallCount(url string) int

GetCallCount returns the number of times a URL was called

func (*MockHTTPClient) SetError

func (m *MockHTTPClient) SetError(url string, err error)

SetError sets a mock error for a URL

func (*MockHTTPClient) SetResponse

func (m *MockHTTPClient) SetResponse(url string, response *MockHTTPResponse)

SetResponse sets a mock response for a URL

type MockHTTPResponse

type MockHTTPResponse struct {
	StatusCode int
	Body       io.ReadCloser
	Header     http.Header
}

MockHTTPResponse represents a mock HTTP response for testing

type NonInteractiveHandler

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

NonInteractiveHandler handles user interactions in non-interactive mode (CLI). It auto-responds based on pre-configured rules without user input.

func NewNonInteractiveHandler

func NewNonInteractiveHandler(opts *NonInteractiveOptions) *NonInteractiveHandler

NewNonInteractiveHandler creates a new non-interactive handler

func (*NonInteractiveHandler) HandleInteraction

HandleInteraction processes a user interaction request

func (*NonInteractiveHandler) Mode

func (h *NonInteractiveHandler) Mode() string

Mode returns the handler mode name

func (*NonInteractiveHandler) SupportsInteraction

func (h *NonInteractiveHandler) SupportsInteraction(interactionType InteractionType) bool

SupportsInteraction indicates whether this handler can handle the given type. Non-interactive mode only handles authorization requests.

type NonInteractiveOptions

type NonInteractiveOptions struct {
	// DangerouslyAllowAll auto-approves all authorization requests
	DangerouslyAllowAll bool
	// AllowedCommands are command prefixes that are pre-authorized
	AllowedCommands []string
	// AllowedDomains are domain patterns that are pre-authorized for network access
	AllowedDomains []string
	// AllowedDirs are directory paths that are pre-authorized for write operations
	AllowedDirs []string
	// AllowedFiles are specific file paths that are pre-authorized for write operations
	AllowedFiles []string
	// AllowAllNetwork auto-approves all network operations
	AllowAllNetwork bool
	// RequireSandboxAuth requires authorization for every go_sandbox and shell call
	RequireSandboxAuth bool
}

NonInteractiveOptions configures the non-interactive handler behavior

type PlanningQuestionPayload

type PlanningQuestionPayload struct {
	// Question is the question text
	Question string
	// Context provides additional context for the question
	Context string
}

PlanningQuestionPayload contains data for planning phase questions

type QuestionWithOptions

type QuestionWithOptions struct {
	// Question is the question text
	Question string
	// Options are the available choices
	Options []string
	// AllowCustom indicates if custom text input is allowed
	AllowCustom bool
}

QuestionWithOptions represents a single question with its available options

type RefreshBlocklistRequest

type RefreshBlocklistRequest struct {
	ResponseCh chan RefreshBlocklistResponse
}

RefreshBlocklistRequest forces a refresh of the blocklist

func (RefreshBlocklistRequest) Type

type RefreshBlocklistResponse

type RefreshBlocklistResponse struct {
	Success     bool
	DomainCount int
	Error       string
}

RefreshBlocklistResponse contains the result of a blocklist refresh

type SessionHealthManager

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

SessionHealthManager manages health checks for all actors in a session

func NewSessionHealthManager

func NewSessionHealthManager(actorSystem *System, sessionID string) *SessionHealthManager

NewSessionHealthManager creates a new session health manager

func (*SessionHealthManager) Disable

func (shm *SessionHealthManager) Disable()

Disable stops health monitoring

func (*SessionHealthManager) Enable

func (shm *SessionHealthManager) Enable(checkInterval time.Duration)

Enable enables the health manager with specified check interval

func (*SessionHealthManager) GetActorHealth

func (shm *SessionHealthManager) GetActorHealth(ctx context.Context, actorID string) (HealthReport, error)

GetActorHealth returns health report for a specific actor

func (*SessionHealthManager) GetCheckInterval

func (shm *SessionHealthManager) GetCheckInterval() time.Duration

GetCheckInterval returns the current health check interval

func (*SessionHealthManager) HealthCheck

HealthCheck performs an immediate health check of all actors in the session

func (*SessionHealthManager) IsEnabled

func (shm *SessionHealthManager) IsEnabled() bool

IsEnabled returns true if health monitoring is enabled

func (*SessionHealthManager) SetCheckInterval

func (shm *SessionHealthManager) SetCheckInterval(interval time.Duration)

SetCheckInterval updates the health check interval

func (*SessionHealthManager) Stop

func (shm *SessionHealthManager) Stop()

Stop gracefully stops the health manager

type SessionHealthMetrics

type SessionHealthMetrics struct {
	TotalActors     int           `json:"total_actors"`
	HealthyActors   int           `json:"healthy_actors"`
	DegradedActors  int           `json:"degraded_actors"`
	UnhealthyActors int           `json:"unhealthy_actors"`
	UnknownActors   int           `json:"unknown_actors"`
	LastCheckTime   time.Time     `json:"last_check_time"`
	CheckDuration   time.Duration `json:"check_duration"`
}

SessionHealthMetrics contains session-level health metrics

type SessionHealthReport

type SessionHealthReport struct {
	SessionID      string                  `json:"session_id"`
	OverallStatus  HealthStatus            `json:"overall_status"`
	ActorReports   map[string]HealthReport `json:"actor_reports"`
	SessionMetrics SessionHealthMetrics    `json:"session_metrics"`
	Timestamp      time.Time               `json:"timestamp"`
	Issues         []string                `json:"issues,omitempty"`
}

SessionHealthReport contains health status of all actors in a session

type SessionStorageActor

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

SessionStorageActor handles persistent storage of session data

func NewSessionStorageActor

func NewSessionStorageActor(name string) (*SessionStorageActor, error)

func NewSessionStorageActorWithConfig

func NewSessionStorageActorWithConfig(name string, configFunc func() *config.AutoSaveConfig) (*SessionStorageActor, error)

func (*SessionStorageActor) GetHealthMetrics

func (a *SessionStorageActor) GetHealthMetrics() HealthMetrics

GetHealthMetrics returns current health metrics for session storage

func (*SessionStorageActor) ID

func (a *SessionStorageActor) ID() string

func (*SessionStorageActor) IsHealthy

func (a *SessionStorageActor) IsHealthy() bool

IsHealthy returns true if the session storage actor is healthy

func (*SessionStorageActor) Receive

func (a *SessionStorageActor) Receive(ctx context.Context, msg Message) error

func (*SessionStorageActor) Start

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

func (*SessionStorageActor) Stop

type SessionStorageDeleteMsg

type SessionStorageDeleteMsg struct {
	WorkingDir   string
	SessionID    string
	ResponseChan chan SessionStorageDeleteResponse
}

func (SessionStorageDeleteMsg) Type

type SessionStorageDeleteResponse

type SessionStorageDeleteResponse struct {
	Err error
}

type SessionStorageGetMostRecentMsg

type SessionStorageGetMostRecentMsg struct {
	WorkingDir   string
	ResponseChan chan SessionStorageGetMostRecentResponse
}

func (SessionStorageGetMostRecentMsg) Type

type SessionStorageGetMostRecentResponse

type SessionStorageGetMostRecentResponse struct {
	Session *session.Session
	Err     error
}

type SessionStorageListMsg

type SessionStorageListMsg struct {
	WorkingDir   string
	ResponseChan chan SessionStorageListResponse
}

func (SessionStorageListMsg) Type

type SessionStorageListResponse

type SessionStorageListResponse struct {
	Sessions []session.SessionMetadata
	Err      error
}

type SessionStorageLoadMsg

type SessionStorageLoadMsg struct {
	WorkingDir   string
	SessionID    string
	ResponseChan chan SessionStorageLoadResponse
}

func (SessionStorageLoadMsg) Type

type SessionStorageLoadResponse

type SessionStorageLoadResponse struct {
	Session *session.Session
	Err     error
}

type SessionStorageSaveMsg

type SessionStorageSaveMsg struct {
	Session      *session.Session
	Name         string
	ResponseChan chan SessionStorageSaveResponse
}

func (SessionStorageSaveMsg) Type

type SessionStorageSaveResponse

type SessionStorageSaveResponse struct {
	Err error
}

type SessionStorageStartAutoSaveMsg

type SessionStorageStartAutoSaveMsg struct {
	Session      *session.Session
	Name         string
	ResponseChan chan SessionStorageStartAutoSaveResponse
}

func (SessionStorageStartAutoSaveMsg) Type

type SessionStorageStartAutoSaveResponse

type SessionStorageStartAutoSaveResponse struct {
	Err error
}

type SessionStorageStopAutoSaveMsg

type SessionStorageStopAutoSaveMsg struct {
	ResponseChan chan SessionStorageStopAutoSaveResponse
}

func (SessionStorageStopAutoSaveMsg) Type

type SessionStorageStopAutoSaveResponse

type SessionStorageStopAutoSaveResponse struct {
	Err error
}

type ShellActor

type ShellActor interface {
	Actor

	// ExecuteCommand executes a command using argv (synchronous, no shell parsing)
	ExecuteCommand(ctx context.Context, args []string, workingDir string, timeout time.Duration, stdin string) (string, string, int, error)

	// ExecuteCommandBackground executes a command in background using argv and returns job ID
	ExecuteCommandBackground(ctx context.Context, args []string, workingDir string) (string, int, error)

	// GetJobStatus returns the status of a background job
	GetJobStatus(ctx context.Context, jobID string) (running bool, exitCode int, stdout, stderr string, completed bool, err error)

	// WaitForJob waits for a background job to complete
	WaitForJob(ctx context.Context, jobID string) (exitCode int, stdout, stderr string, err error)

	// StopJob stops a background job
	StopJob(ctx context.Context, jobID string, signal string) error
}

ShellActor is an interface for shell execution actors

func NewShellActor

func NewShellActor(id string, sess *session.Session) ShellActor

NewShellActor creates a new shell actor

type ShellActorClient

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

ShellActorClient provides a client interface to the ShellActor

func NewShellActorClient

func NewShellActorClient(ref *ActorRef) *ShellActorClient

NewShellActorClient creates a new client for a ShellActor

func (*ShellActorClient) ExecuteCommand

func (c *ShellActorClient) ExecuteCommand(ctx context.Context, args []string, workingDir string, timeout time.Duration, stdin string) (string, string, int, error)

ExecuteCommand executes a command synchronously using argv (no shell parsing).

func (*ShellActorClient) ExecuteCommandBackground

func (c *ShellActorClient) ExecuteCommandBackground(ctx context.Context, args []string, workingDir string) (string, int, error)

ExecuteCommandBackground executes a command in background using argv and returns job ID

func (*ShellActorClient) GetJobStatus

func (c *ShellActorClient) GetJobStatus(ctx context.Context, jobID string) (bool, int, string, string, bool, error)

GetJobStatus returns the status of a background job

func (*ShellActorClient) StopJob

func (c *ShellActorClient) StopJob(ctx context.Context, jobID string, signal string) error

StopJob stops a background job

func (*ShellActorClient) WaitForJob

func (c *ShellActorClient) WaitForJob(ctx context.Context, jobID string) (int, string, string, error)

WaitForJob waits for a background job to complete

type ShellActorWithSandbox

type ShellActorWithSandbox interface {
	ShellActor
	// SetSandbox sets the landlock sandbox for the shell actor
	SetSandbox(sb *sandbox.LandlockSandbox)
}

ShellActorWithSandbox is an optional interface for shell actors that support sandboxing

type ShellActorWithShellTemp

type ShellActorWithShellTemp interface {
	ShellActor
	// SetShellTempDir sets the shell temp directory path
	SetShellTempDir(dir string)
}

ShellActorWithShellTemp is an optional interface for shell actors that support setting a shell temp directory (used to set SCRIPTSCHNELL_SHELL_TEMP env var)

type ShellExecuteRequest

type ShellExecuteRequest struct {
	Command    []string
	WorkingDir string
	Timeout    time.Duration
	Background bool
	Stdin      string
	ResponseCh chan ShellExecuteResponse
}

ShellExecuteRequest is a message to execute a shell command

func (ShellExecuteRequest) Type

func (m ShellExecuteRequest) Type() string

type ShellExecuteResponse

type ShellExecuteResponse struct {
	JobID    string
	PID      int
	ExitCode int
	Stdout   string
	Stderr   string
	Error    string
	Done     bool
	Message  string // For background jobs
}

ShellExecuteResponse contains the result of a shell execution

type ShellMessage

type ShellMessage interface {
	Type() string
}

ShellMessage represents different types of shell execution requests

type ShellStatusRequest

type ShellStatusRequest struct {
	JobID      string
	ResponseCh chan ShellStatusResponse
}

ShellStatusRequest is a message to check status of background jobs

func (ShellStatusRequest) Type

func (m ShellStatusRequest) Type() string

type ShellStatusResponse

type ShellStatusResponse struct {
	JobID     string
	PID       int
	Running   bool
	ExitCode  int
	Stdout    string
	Stderr    string
	Completed bool
	Error     string
}

ShellStatusResponse contains status information about a background job

type ShellStopRequest

type ShellStopRequest struct {
	JobID      string
	Signal     string // "SIGTERM" or "SIGKILL"
	ResponseCh chan ShellStopResponse
}

ShellStopRequest is a message to stop a background job

func (ShellStopRequest) Type

func (m ShellStopRequest) Type() string

type ShellStopResponse

type ShellStopResponse struct {
	Success bool
	Error   string
}

ShellStopResponse contains the result of stopping a job

type ShellWaitRequest

type ShellWaitRequest struct {
	JobID      string
	ResponseCh chan ShellWaitResponse
}

ShellWaitRequest is a message to wait for background job completion

func (ShellWaitRequest) Type

func (m ShellWaitRequest) Type() string

type ShellWaitResponse

type ShellWaitResponse struct {
	JobID    string
	ExitCode int
	Stdout   string
	Stderr   string
	Error    string
}

ShellWaitResponse contains the result of waiting for a job to complete

type System

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

System manages a collection of actors

func NewSystem

func NewSystem() *System

NewSystem creates a new actor system

func (*System) Get

func (s *System) Get(id string) (*ActorRef, bool)

Get retrieves an actor reference by ID

func (*System) GetActorHealth

func (s *System) GetActorHealth(ctx context.Context, actorID string) (HealthReport, error)

GetActorHealth returns the health report for a specific actor

func (*System) HealthCheck

func (s *System) HealthCheck(ctx context.Context) map[string]HealthReport

HealthCheck performs health checks on all actors in the system

func (*System) Spawn

func (s *System) Spawn(ctx context.Context, id string, actor Actor, mailboxSize int) (*ActorRef, error)

Spawn creates and starts a new actor

func (*System) SpawnWithOptions

func (s *System) SpawnWithOptions(ctx context.Context, id string, actor Actor, mailboxSize int, opts ...ActorRefOption) (*ActorRef, error)

SpawnWithOptions creates and starts a new actor with additional reference options.

func (*System) Stop

func (s *System) Stop(ctx context.Context, id string) error

Stop stops an actor by ID

func (*System) StopAll

func (s *System) StopAll(ctx context.Context) error

StopAll stops all actors in the system

type TestActor

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

TestActor is a simple actor implementation for testing

func NewTestActor

func NewTestActor(id string) *TestActor

func (*TestActor) GetReceiveCount

func (a *TestActor) GetReceiveCount() int32

func (*TestActor) GetReceivedMessages

func (a *TestActor) GetReceivedMessages() []Message

func (*TestActor) ID

func (a *TestActor) ID() string

func (*TestActor) Receive

func (a *TestActor) Receive(ctx context.Context, msg Message) error

func (*TestActor) SetReceiveHandler

func (a *TestActor) SetReceiveHandler(handler func(ctx context.Context, msg Message) error)

func (*TestActor) SetShouldError

func (a *TestActor) SetShouldError(val bool)

func (*TestActor) Start

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

func (*TestActor) Stop

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

func (*TestActor) WasStartCalled

func (a *TestActor) WasStartCalled() bool

func (*TestActor) WasStopCalled

func (a *TestActor) WasStopCalled() bool

type TestMessage

type TestMessage struct {
	ID      string
	Content string
}

TestMessage is a simple test message type

func (*TestMessage) Type

func (m *TestMessage) Type() string

type UserInputMultiplePayload

type UserInputMultiplePayload struct {
	// FormattedQuestions is the original formatted questions string
	FormattedQuestions string
	// ParsedQuestions contains the parsed structure for UI rendering
	ParsedQuestions []QuestionWithOptions
}

UserInputMultiplePayload contains data for multiple choice questions

type UserInputSinglePayload

type UserInputSinglePayload struct {
	// Question is the prompt/question to display
	Question string
	// Default is an optional default answer
	Default string
}

UserInputSinglePayload contains data for single text input requests

type UserInteractionAck

type UserInteractionAck struct {
	RequestID string
}

UserInteractionAck is sent by the handler when it has displayed the interaction UI

func (*UserInteractionAck) Type

func (m *UserInteractionAck) Type() string

Type returns the message type for the actor system

type UserInteractionActor

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

UserInteractionActor coordinates user interactions across modes. It receives interaction requests and dispatches them to the mode-specific handler.

func NewUserInteractionActor

func NewUserInteractionActor(id string, handler UserInteractionHandler) *UserInteractionActor

NewUserInteractionActor creates a new user interaction actor with the given handler.

func (*UserInteractionActor) GetMetrics

func (a *UserInteractionActor) GetMetrics() map[string]int64

GetMetrics returns current metrics

func (*UserInteractionActor) ID

func (a *UserInteractionActor) ID() string

ID returns the actor's unique identifier

func (*UserInteractionActor) Receive

func (a *UserInteractionActor) Receive(ctx context.Context, msg Message) error

Receive processes incoming messages

func (*UserInteractionActor) SetHandler

func (a *UserInteractionActor) SetHandler(handler UserInteractionHandler)

SetHandler updates the handler (useful for mode changes)

func (*UserInteractionActor) Start

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

Start initializes the actor

func (*UserInteractionActor) Stop

Stop gracefully shuts down the actor, cancelling any pending requests

type UserInteractionCancel

type UserInteractionCancel struct {
	RequestID string
	Reason    string
}

UserInteractionCancel is sent to cancel a pending interaction

func (*UserInteractionCancel) Type

func (m *UserInteractionCancel) Type() string

Type returns the message type for the actor system

type UserInteractionClient

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

UserInteractionClient provides typed access to the UserInteractionActor

func NewUserInteractionClient

func NewUserInteractionClient(ref *ActorRef) *UserInteractionClient

NewUserInteractionClient creates a new client for the user interaction actor

func (*UserInteractionClient) Acknowledge

func (c *UserInteractionClient) Acknowledge(requestID string) error

Acknowledge sends an acknowledgment that a dialog was displayed

func (*UserInteractionClient) Cancel

func (c *UserInteractionClient) Cancel(requestID string, reason string) error

Cancel sends a cancellation request for a pending interaction

func (*UserInteractionClient) RequestAuthorization

func (c *UserInteractionClient) RequestAuthorization(
	ctx context.Context,
	toolName string,
	params map[string]interface{},
	reason string,
	suggestedPrefix string,
	tabID int,
) (*UserInteractionResponse, error)

RequestAuthorization requests user authorization for a tool operation

func (*UserInteractionClient) RequestDomainAuthorization

func (c *UserInteractionClient) RequestDomainAuthorization(
	ctx context.Context,
	domain string,
	reason string,
	suggestedDomain string,
	tabID int,
) (*UserInteractionResponse, error)

RequestDomainAuthorization requests user authorization for network domain access

func (*UserInteractionClient) RequestMultipleAnswers

func (c *UserInteractionClient) RequestMultipleAnswers(
	ctx context.Context,
	formattedQuestions string,
	parsedQuestions []QuestionWithOptions,
	tabID int,
) (*UserInteractionResponse, error)

RequestMultipleAnswers requests answers to multiple questions from the user

func (*UserInteractionClient) RequestPlanningQuestion

func (c *UserInteractionClient) RequestPlanningQuestion(
	ctx context.Context,
	question string,
	questionContext string,
	tabID int,
) (*UserInteractionResponse, error)

RequestPlanningQuestion requests an answer to a planning phase question

func (*UserInteractionClient) RequestUserInput

func (c *UserInteractionClient) RequestUserInput(
	ctx context.Context,
	question string,
	defaultAnswer string,
	tabID int,
) (*UserInteractionResponse, error)

RequestUserInput requests single text input from the user

func (*UserInteractionClient) SetDefaultTimeout

func (c *UserInteractionClient) SetDefaultTimeout(timeout time.Duration)

SetDefaultTimeout sets the default timeout for requests

type UserInteractionHandler

type UserInteractionHandler interface {
	// HandleInteraction processes a user interaction request and returns a response.
	// Must return a response or error - should not block indefinitely.
	// The context can be used for cancellation.
	HandleInteraction(ctx context.Context, req *UserInteractionRequest) (*UserInteractionResponse, error)

	// Mode returns the interaction mode name (for logging/debugging)
	Mode() string

	// SupportsInteraction indicates whether this handler can handle the given type
	SupportsInteraction(interactionType InteractionType) bool
}

UserInteractionHandler is implemented by each mode (TUI, CLI, ACP) to handle user interactions in a mode-specific way.

type UserInteractionRequest

type UserInteractionRequest struct {
	// RequestID is a unique identifier for tracking this request
	RequestID string
	// InteractionType identifies what kind of interaction is needed
	InteractionType InteractionType
	// Payload contains type-specific data for the interaction
	Payload interface{}
	// RequestCtx is the context for cancellation
	RequestCtx context.Context
	// ResponseChan receives the response when the user completes the interaction
	ResponseChan chan *UserInteractionResponse
	// Timeout is the maximum time to wait for user response (0 = default)
	Timeout time.Duration
	// TabID is used in TUI mode to identify which tab requested the interaction
	TabID int
}

UserInteractionRequest is the message sent to request user interaction

func (*UserInteractionRequest) Type

func (m *UserInteractionRequest) Type() string

Type returns the message type for the actor system

type UserInteractionResponse

type UserInteractionResponse struct {
	// RequestID matches the request this is responding to
	RequestID string
	// Approved is used for authorization requests (true = approved, false = denied)
	Approved bool
	// Answer is used for single-answer questions
	Answer string
	// Answers is used for multiple questions (question -> answer mapping)
	Answers map[string]string
	// Cancelled indicates the user dismissed/cancelled the interaction
	Cancelled bool
	// TimedOut indicates the request timed out waiting for user
	TimedOut bool
	// Error contains any error that occurred during interaction handling
	Error error
	// Acknowledged confirms the handler received and displayed the request
	Acknowledged bool
}

UserInteractionResponse is the unified response format for all interaction types

Jump to

Keyboard shortcuts

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