statemanager

package
v0.183.0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type StateManager

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

StateManager provides centralized state management with proper synchronization

func NewStateManager

func NewStateManager(debugMode bool) *StateManager

NewStateManager creates a new state manager

func (*StateManager) AddQueuedMessage

func (sm *StateManager) AddQueuedMessage(message sdk.Message, requestID string)

AddQueuedMessage adds a message to the input queue

func (*StateManager) AreAllAgentsReady

func (sm *StateManager) AreAllAgentsReady() bool

AreAllAgentsReady returns true if all agents are ready

func (*StateManager) BroadcastEvent

func (sm *StateManager) BroadcastEvent(event agentdomain.ChatEvent)

BroadcastEvent publishes an event to the EventBridge for external consumers

func (*StateManager) ClearAgentReadiness

func (sm *StateManager) ClearAgentReadiness()

ClearAgentReadiness clears the agent readiness state

func (*StateManager) ClearApprovalUIState

func (sm *StateManager) ClearApprovalUIState()

ClearApprovalUIState clears the approval UI state

func (*StateManager) ClearComputerUsePauseState

func (sm *StateManager) ClearComputerUsePauseState()

ClearComputerUsePauseState clears the pause state

func (*StateManager) ClearFileSelectionState

func (sm *StateManager) ClearFileSelectionState()

ClearFileSelectionState clears the file selection state

func (*StateManager) ClearLastClickCoordinates

func (sm *StateManager) ClearLastClickCoordinates()

ClearLastClickCoordinates clears the stored click coordinates

func (*StateManager) ClearLastFocusedApp

func (sm *StateManager) ClearLastFocusedApp()

ClearLastFocusedApp clears the stored focused app

func (*StateManager) ClearMessageEditState

func (sm *StateManager) ClearMessageEditState()

ClearMessageEditState clears the message edit state

func (*StateManager) ClearPlanApprovalUIState

func (sm *StateManager) ClearPlanApprovalUIState()

ClearPlanApprovalUIState clears the plan approval UI state

func (*StateManager) ClearQueuedMessages

func (sm *StateManager) ClearQueuedMessages()

ClearQueuedMessages clears all queued messages

func (*StateManager) ClearUserQuestionUIState

func (sm *StateManager) ClearUserQuestionUIState()

ClearUserQuestionUIState clears the AskUserQuestion form state

func (*StateManager) CompleteCurrentTool

func (sm *StateManager) CompleteCurrentTool(result *agentdomain.ToolExecutionResult) error

CompleteCurrentTool marks the current tool as completed

func (*StateManager) CycleAgentMode

func (sm *StateManager) CycleAgentMode() agentdomain.AgentMode

CycleAgentMode cycles to the next agent mode

func (*StateManager) EndChatSession

func (sm *StateManager) EndChatSession()

EndChatSession ends the current chat session

func (*StateManager) EndToolExecution

func (sm *StateManager) EndToolExecution()

EndToolExecution ends the current tool execution session

func (*StateManager) FailCurrentTool

func (sm *StateManager) FailCurrentTool(result *agentdomain.ToolExecutionResult) error

FailCurrentTool marks the current tool as failed

func (*StateManager) GetAgentMode

func (sm *StateManager) GetAgentMode() agentdomain.AgentMode

GetAgentMode returns the current agent mode

func (*StateManager) GetAgentReadiness

func (sm *StateManager) GetAgentReadiness() *tui.AgentReadinessState

GetAgentReadiness returns the current agent readiness state

func (*StateManager) GetApprovalUIState

func (sm *StateManager) GetApprovalUIState() *agentdomain.ApprovalUIState

GetApprovalUIState returns the current approval UI state

func (*StateManager) GetChatSession

func (sm *StateManager) GetChatSession() *agentdomain.ChatSession

GetChatSession returns the current chat session (read-only)

func (*StateManager) GetCurrentView

func (sm *StateManager) GetCurrentView() tui.ViewState

GetCurrentView returns the current view state

func (*StateManager) GetDimensions

func (sm *StateManager) GetDimensions() (int, int)

GetDimensions returns the current UI dimensions

func (*StateManager) GetEventBridge

func (sm *StateManager) GetEventBridge() agentdomain.EventBridge

GetEventBridge returns the event bridge for control event forwarding

func (*StateManager) GetFileSelectionState

func (sm *StateManager) GetFileSelectionState() *tui.FileSelectionState

GetFileSelectionState returns the current file selection state

func (*StateManager) GetLastClickCoordinates

func (sm *StateManager) GetLastClickCoordinates() (x, y int)

GetLastClickCoordinates returns the coordinates of the last click

func (*StateManager) GetLastFocusedApp

func (sm *StateManager) GetLastFocusedApp() string

GetLastFocusedApp returns the application ID of the last focused application

func (*StateManager) GetMessageEditState

func (sm *StateManager) GetMessageEditState() *tui.MessageEditState

GetMessageEditState returns the current message edit state

func (*StateManager) GetPausedRequestID

func (sm *StateManager) GetPausedRequestID() string

GetPausedRequestID returns the request ID of the paused execution

func (*StateManager) GetPlanApprovalUIState

func (sm *StateManager) GetPlanApprovalUIState() *agentdomain.PlanApprovalUIState

GetPlanApprovalUIState returns the current plan approval UI state

func (*StateManager) GetPreviousView

func (sm *StateManager) GetPreviousView() tui.ViewState

GetPreviousView returns the previous view state

func (*StateManager) GetQueuedMessages

func (sm *StateManager) GetQueuedMessages() []convdomain.QueuedMessage

GetQueuedMessages returns the current queued messages

func (*StateManager) GetRetryStatus

func (sm *StateManager) GetRetryStatus() *agentdomain.RetryStatus

GetRetryStatus returns a copy of the current retry status, or nil when the connection is healthy. Besides explicit reconnect attempts (set by the agent's reconnect loop), it synthesizes a zero-attempt status when a streaming session has produced no chunks for stallThreshold - the render tick calls this on every frame, so a stalled connection surfaces without any timer of its own. A synthesized status has Attempt == 0. Terminal sessions never report a status, so a stale explicit retry can't outlive the turn it belonged to (the input field is disabled while this returns non-nil).

func (*StateManager) GetTodos

func (sm *StateManager) GetTodos() []agentdomain.TodoItem

GetTodos returns the current todo list

func (*StateManager) GetToolExecution

func (sm *StateManager) GetToolExecution() *agentdomain.ToolExecutionSession

GetToolExecution returns the current tool execution session (read-only)

func (*StateManager) GetUserQuestionUIState

func (sm *StateManager) GetUserQuestionUIState() *agentdomain.UserQuestionUIState

GetUserQuestionUIState returns the current AskUserQuestion form state

func (*StateManager) InitializeAgentReadiness

func (sm *StateManager) InitializeAgentReadiness(totalAgents int)

InitializeAgentReadiness initializes the agent readiness tracking

func (*StateManager) IsAgentBusy

func (sm *StateManager) IsAgentBusy() bool

IsAgentBusy returns true if the agent is currently processing a request

func (*StateManager) IsComputerUsePaused

func (sm *StateManager) IsComputerUsePaused() bool

IsComputerUsePaused returns whether computer use is currently paused

func (*StateManager) IsDebugMode

func (sm *StateManager) IsDebugMode() bool

IsDebugMode returns whether debug mode is enabled

func (*StateManager) IsEditingMessage

func (sm *StateManager) IsEditingMessage() bool

IsEditingMessage returns true if currently editing a message

func (*StateManager) PopQueuedMessage

func (sm *StateManager) PopQueuedMessage() *convdomain.QueuedMessage

PopQueuedMessage removes and returns the first message from the queue (FIFO order)

func (*StateManager) RecoverFromInconsistentState

func (sm *StateManager) RecoverFromInconsistentState() error

RecoverFromInconsistentState attempts to recover from an inconsistent state

func (*StateManager) RemoveAgent

func (sm *StateManager) RemoveAgent(name string)

RemoveAgent removes an agent from the readiness tracking

func (*StateManager) SetAgentError

func (sm *StateManager) SetAgentError(name string, err error)

SetAgentError sets an error for a specific agent

func (*StateManager) SetAgentMode

func (sm *StateManager) SetAgentMode(mode agentdomain.AgentMode)

SetAgentMode sets the agent mode

func (*StateManager) SetChatPending

func (sm *StateManager) SetChatPending()

SetChatPending marks the agent as busy before the chat actually starts. This prevents race conditions where messages might not be queued between the time we decide to start a chat and when StartChatSession is called.

Promotes to "pending" if there is no existing chat session OR if the existing session is in a terminal status (Completed/Error/Cancelled/Idle). Terminal sessions are leftovers from a prior chat that hasn't been GC'd yet; treating them as "in progress" would make IsAgentBusy() return false here but true for a subsequent caller that just won the SetChatPending race, which is exactly the window the chat-mode async rollover relies on for queueing.

func (*StateManager) SetComputerUsePaused

func (sm *StateManager) SetComputerUsePaused(paused bool, requestID string)

SetComputerUsePaused sets the paused state for computer use

func (*StateManager) SetDebugMode

func (sm *StateManager) SetDebugMode(enabled bool)

SetDebugMode enables or disables debug mode

func (*StateManager) SetDimensions

func (sm *StateManager) SetDimensions(width, height int)

SetDimensions updates the UI dimensions

func (*StateManager) SetEventBridge

func (sm *StateManager) SetEventBridge(bridge agentdomain.EventBridge)

SetEventBridge sets the event bridge for multicasting events to external consumers

func (*StateManager) SetFileSelectedIndex

func (sm *StateManager) SetFileSelectedIndex(index int)

SetFileSelectedIndex sets the selected file index

func (*StateManager) SetLastClickCoordinates

func (sm *StateManager) SetLastClickCoordinates(x, y int)

SetLastClickCoordinates stores the coordinates of the last click

func (*StateManager) SetLastFocusedApp

func (sm *StateManager) SetLastFocusedApp(appID string)

SetLastFocusedApp stores the application ID of the last focused application

func (*StateManager) SetMessageEditState

func (sm *StateManager) SetMessageEditState(state *tui.MessageEditState)

SetMessageEditState sets the message edit state

func (*StateManager) SetPlanApprovalSelectedIndex

func (sm *StateManager) SetPlanApprovalSelectedIndex(index int)

SetPlanApprovalSelectedIndex sets the plan approval selection index

func (*StateManager) SetRetryStatus

func (sm *StateManager) SetRetryStatus(status *agentdomain.RetryStatus)

SetRetryStatus updates the retry status on the current chat session. Called by the agent's reconnect loop to provide visual feedback in the status bar while it is reconnecting after a failure.

func (*StateManager) SetStallThreshold

func (sm *StateManager) SetStallThreshold(threshold time.Duration)

SetStallThreshold sets how long a streaming session may go without chunks before GetRetryStatus reports it as reconnecting. Zero or negative disables stall detection.

func (*StateManager) SetTodos

func (sm *StateManager) SetTodos(todos []agentdomain.TodoItem)

SetTodos sets the todo list

func (*StateManager) SetupApprovalUIState

func (sm *StateManager) SetupApprovalUIState(toolCall *sdk.ChatCompletionMessageToolCall, responseChan chan agentdomain.ApprovalAction)

SetupApprovalUIState initializes approval UI state

func (*StateManager) SetupFileSelection

func (sm *StateManager) SetupFileSelection(files []string)

SetupFileSelection initializes file selection state

func (*StateManager) SetupPlanApprovalUIState

func (sm *StateManager) SetupPlanApprovalUIState(planContent, planID string, responseChan chan agentdomain.PlanApprovalAction)

SetupPlanApprovalUIState initializes plan approval UI state

func (*StateManager) SetupUserQuestionUIState

func (sm *StateManager) SetupUserQuestionUIState(questions []agentdomain.UserQuestion, responseChan chan []agentdomain.UserQuestionAnswer)

SetupUserQuestionUIState initializes the AskUserQuestion form state

func (*StateManager) StartChatSession

func (sm *StateManager) StartChatSession(requestID, model string, eventChan <-chan agentdomain.ChatEvent) error

StartChatSession starts a new chat session

func (*StateManager) StartToolExecution

func (sm *StateManager) StartToolExecution(toolCalls []sdk.ChatCompletionMessageToolCall) error

StartToolExecution starts a new tool execution session

func (*StateManager) TouchChatActivity

func (sm *StateManager) TouchChatActivity()

TouchChatActivity records stream output on the current session, clearing any retry status and resetting the stall clock.

func (*StateManager) TransitionToView

func (sm *StateManager) TransitionToView(newView tui.ViewState) error

TransitionToView transitions to a new view with validation and logging

func (*StateManager) UpdateAgentPullProgress

func (sm *StateManager) UpdateAgentPullProgress(name string, done, total int)

UpdateAgentPullProgress updates the image pull layer counts for a specific agent

func (*StateManager) UpdateAgentStatus

func (sm *StateManager) UpdateAgentStatus(name string, state agentdomain.AgentState, message string, url string, image string)

UpdateAgentStatus updates the status of a specific agent

func (*StateManager) UpdateChatStatus

func (sm *StateManager) UpdateChatStatus(status agentdomain.ChatStatus) error

UpdateChatStatus updates the chat session status with validation

func (*StateManager) UpdateFileSearchQuery

func (sm *StateManager) UpdateFileSearchQuery(query string)

UpdateFileSearchQuery updates the file search query

Jump to

Keyboard shortcuts

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