agentruntime

package
v1.3.61 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ActivateCurrentSelection

func ActivateCurrentSelection(cfg *config.Config, vendor, endpoint, model string) (*config.ResolvedEndpoint, provider.Provider, error)

func AppendProjectionEvent

func AppendProjectionEvent(store *tunnel.ProjectionStore, msg tunnel.GatewayMessage) error

func ApplyProjectMemoryToAgent

func ApplyProjectMemoryToAgent(agentInst *agent.Agent, workingDir string) ([]string, error)

func ApplyProviderToAgent

func ApplyProviderToAgent(agentInst *agent.Agent, prov provider.Provider, resolved *config.ResolvedEndpoint)

func ApplyResolvedLimitsToAgent

func ApplyResolvedLimitsToAgent(agentInst *agent.Agent, resolved *config.ResolvedEndpoint)

func ApplyTunnelStateUpdate

func ApplyTunnelStateUpdate(broker *tunnel.Broker, update TunnelStateUpdate)

func ApprovalDecisionFromTunnel

func ApprovalDecisionFromTunnel(decision string) permission.Decision

func AttachTunnelBroker

func AttachTunnelBroker(broker *tunnel.Broker, cfg TunnelAttachConfig)

func BuildAskUserAnswer

func BuildAskUserAnswer(question tool.AskUserQuestion, selectedIDs []string, freeform string) tool.AskUserAnswer

func BuildAskUserResponseFromTunnel

func BuildAskUserResponseFromTunnel(req tool.AskUserRequest, status string, answers []tunnel.AskUserAnswer) tool.AskUserResponse

func BuildInteractivePermissionPolicy

func BuildInteractivePermissionPolicy(cfg *config.Config, workingDir string, bypass bool) permission.PermissionPolicy

func BuildInteractiveSystemPrompt

func BuildInteractiveSystemPrompt(
	cfg *config.Config,
	workingDir string,
	mode permission.PermissionMode,
	registry *tool.Registry,
	commandMgr *commands.Manager,
	globalAutoMem *memory.AutoMemory,
	projectAutoMem *memory.AutoMemory,
	gitStatus string,
) string

func BuildInteractiveSystemPromptWithPromptRefs

func BuildInteractiveSystemPromptWithPromptRefs(
	cfg *config.Config,
	workingDir string,
	mode permission.PermissionMode,
	registry *tool.Registry,
	commandMgr *commands.Manager,
	globalAutoMem *memory.AutoMemory,
	projectAutoMem *memory.AutoMemory,
	gitStatus string,
) (string, []string)

func BuildMCPSkillCommands

func BuildMCPSkillCommands(snapshots []tool.MCPServerSnapshot) []*commands.Command

func BuildSkillsSystemPrompt

func BuildSkillsSystemPrompt(skills []*commands.Command) string

func BuildSkillsSystemPromptWithPromptRefs

func BuildSkillsSystemPromptWithPromptRefs(skills []*commands.Command) (string, []string)

func BuildTunnelAskUserAnswers

func BuildTunnelAskUserAnswers(resp tool.AskUserResponse) []tunnel.AskUserAnswer

func BuildTunnelAskUserQuestions

func BuildTunnelAskUserQuestions(req tool.AskUserRequest) []tunnel.AskUserQuestion

func CancelledAskUserResponse

func CancelledAskUserResponse(req toolpkg.AskUserRequest) toolpkg.AskUserResponse

func HydrateProjectionReplayFromSessionLedger

func HydrateProjectionReplayFromSessionLedger(store *tunnel.ProjectionStore, ses *session.Session, replay []tunnel.GatewayMessage) ([]tunnel.GatewayMessage, error)

func NewACPClientManager

func NewACPClientManager(
	workingDir string,
	policy permission.PermissionPolicy,
	approvalHandler func(context.Context, string, string) permission.Decision,
) *acpclient.ClientManager

func NewConfigAccess

func NewConfigAccess(cfg *config.Config, workingDir string) *configAccess

NewConfigAccess creates a ConfigAccess backed by the given config.

func NewSkillTool

func NewSkillTool(
	commandMgr *commands.Manager,
	mcpMgr *plugin.MCPManager,
	prov provider.Provider,
	registry *tool.Registry,
	agentFactory func(provider.Provider, interface{}, string, int) subagent.AgentRunner,
	workingDir string,
	onUsage func(provider.TokenUsage),
) tool.SkillTool

func NewSubAgentManager

func NewSubAgentManager(
	subCfg config.SubAgentConfig,
	registry *tool.Registry,
	prov provider.Provider,
	workingDir string,
	onUsage func(provider.TokenUsage),
	agentFactory func(provider.Provider, interface{}, string, int) subagent.AgentRunner,
) *subagent.Manager

func NewSwarmManager

func NewSwarmManager(
	cfg config.SwarmConfig,
	prov provider.Provider,
	registry *tool.Registry,
	onUsage func(provider.TokenUsage),
	factory func(provider.Provider, interface{}, string, int) swarm.AgentRunner,
	toolBuilder func([]string) interface{},
) *swarm.Manager

func PrepareProjectionReplay

func PrepareProjectionReplay(store *tunnel.ProjectionStore, ses *session.Session) (uint64, []tunnel.GatewayMessage, error)

func ProjectionAuthorityEpoch

func ProjectionAuthorityEpoch(store *tunnel.ProjectionStore, sessionID string) (uint64, error)

func ProjectionReplay

func ProjectionReplay(store *tunnel.ProjectionStore, sessionID string) ([]tunnel.GatewayMessage, error)

func PublishShareState

func PublishShareState(broker *tunnel.Broker, sessionID string, snapshot tunnel.BrokerSnapshot, replay []tunnel.GatewayMessage, reset bool) bool

func PushTunnelApprovalRequest

func PushTunnelApprovalRequest(broker *tunnel.Broker, requestID, toolName, input string, update TunnelStateUpdate)

func PushTunnelApprovalResult

func PushTunnelApprovalResult(broker *tunnel.Broker, requestID, decision string, update TunnelStateUpdate)

func PushTunnelAskUserRequest

func PushTunnelAskUserRequest(broker *tunnel.Broker, requestID string, req tool.AskUserRequest, update TunnelStateUpdate)

func PushTunnelAskUserResponse

func PushTunnelAskUserResponse(broker *tunnel.Broker, requestID string, response tool.AskUserResponse, update TunnelStateUpdate)

func PushTunnelSubagentEvent

func PushTunnelSubagentEvent(currentBroker func() *tunnel.Broker, markSpawned func(string) bool, sa *subagent.SubAgent)

func PushTunnelSubagentReasoning

func PushTunnelSubagentReasoning(currentBroker func() *tunnel.Broker, agentID, text string)

func PushTunnelSubagentText

func PushTunnelSubagentText(currentBroker func() *tunnel.Broker, agentID, text string)

func PushTunnelSubagentToolCall

func PushTunnelSubagentToolCall(currentBroker func() *tunnel.Broker, agentID, toolID, toolName, displayName, args, detail string)

func PushTunnelSubagentToolResult

func PushTunnelSubagentToolResult(currentBroker func() *tunnel.Broker, agentID, toolID, toolName, displayName, detail, result string, isError bool)

func PushTunnelSwarmEvent

func PushTunnelSwarmEvent(
	currentBroker func() *tunnel.Broker,
	mgr *swarm.Manager,
	ev swarm.Event,
	displayName func(string, string) string,
	detail func(string, string) string,
)

func RegisterDelegateTool

func RegisterDelegateTool(
	registry *tool.Registry,
	mgr *acpclient.ClientManager,
	subMgrFn func() *subagent.Manager,
	workingDir string,
	workingDirFn func() string,
)

func ResolveCurrentSelection

func ResolveCurrentSelection(cfg *config.Config) (*config.ResolvedEndpoint, provider.Provider, error)

func ResolveTunnelApproval

func ResolveTunnelApproval(decision string, toolName string, setOverride func(string)) permission.Decision

func RestoreSessionIntoAgent

func RestoreSessionIntoAgent(agentInst *agent.Agent, ses *session.Session)

func RouteTunnelCommand

func RouteTunnelCommand(cmd tunnel.GatewayMessage, hooks TunnelCommandHooks)

func SaveAgentSessionSnapshot

func SaveAgentSessionSnapshot(store session.Store, ses *session.Session, agentInst *agent.Agent) error

func SaveSessionMessages

func SaveSessionMessages(store session.Store, ses *session.Session, messages []provider.Message) error

func ShareSnapshotMatches

func ShareSnapshotMatches(a, b tunnel.BrokerSnapshot) bool

func StartAsyncRelayModelLimitRefresh

func StartAsyncRelayModelLimitRefresh(cfg *config.Config, resolved *config.ResolvedEndpoint, agentInst *agent.Agent, onApplied func(relaycatalog.ResolveResponse))

func StopSharedTunnelGracefully

func StopSharedTunnelGracefully(sess *tunnel.Session, broker *tunnel.Broker, timeout time.Duration)

func TunnelDecisionFromApproval

func TunnelDecisionFromApproval(decision permission.Decision) string

func TunnelReasoningMsgID

func TunnelReasoningMsgID(messageID string) string

func TunnelSubagentReasoningID

func TunnelSubagentReasoningID(agentID string) string

func TunnelSubagentTextID

func TunnelSubagentTextID(agentID string) string

Types

type ApprovalRequest

type ApprovalRequest struct {
	ID       string
	ToolName string
	Input    string
}

type AskUserRequest

type AskUserRequest struct {
	ID      string
	Request toolpkg.AskUserRequest
}

type DesktopEmitterCallbacks

type DesktopEmitterCallbacks struct {
	TriggerTypingFn    func()
	EmitToolResultFn   func(toolName, rawArgs, result string, isError bool)
	EmitRoundSummaryFn func(text string, toolCalls, toolSuccesses, toolFailures int)
}

type DesktopMirrorCallbacks

type DesktopMirrorCallbacks struct {
	CurrentBroker   func() *tunnel.Broker
	EnsureMessageID func(*tunnel.Broker) string
	ReasoningMsgID  func(*tunnel.Broker) string
	MarkMainActive  func()
	FlushMainStream func(*tunnel.Broker, bool)
}

type DesktopStreamEmitter

type DesktopStreamEmitter interface {
	TriggerTyping()
	EmitToolResult(toolName, rawArgs, result string, isError bool)
	EmitRoundSummary(text string, toolCalls, toolSuccesses, toolFailures int)
}

func NewDesktopEmitterAdapter

func NewDesktopEmitterAdapter(callbacks DesktopEmitterCallbacks) DesktopStreamEmitter

type DesktopStreamMirror

type DesktopStreamMirror interface {
	PushText(text string)
	PushReasoning(chunk string)
	PushToolCall(toolID, toolName, displayName, rawArgs, detail string)
	PushToolResult(toolID, toolName, result string, isError bool)
	Flush(rotate bool)
	PushError(message string)
}

func NewDesktopMirrorAdapter

func NewDesktopMirrorAdapter(callbacks DesktopMirrorCallbacks) DesktopStreamMirror

type DesktopStreamSemantic

type DesktopStreamSemantic struct {
	Type       provider.StreamEventType
	Text       string
	ToolCall   *DesktopToolCallEvent
	ToolResult *DesktopToolResultEvent
	UsageData  map[string]interface{}
	ErrorText  string
}

type DesktopToolCallEvent

type DesktopToolCallEvent struct {
	ID          string
	Name        string
	RawArgs     string
	DisplayName string
	Detail      string
	Inline      string
}

type DesktopToolResultEvent

type DesktopToolResultEvent struct {
	ID      string
	Name    string
	RawArgs string
	Content string
	Preview string
	IsError bool
}

type IMRoundState

type IMRoundState struct {
	ToolCalls     int
	ToolSuccesses int
	ToolFailures  int
	// contains filtered or unexported fields
}

IMRoundState tracks assistant text and tool counters for a single LLM turn. Filtering policy stays in the caller so different frontends can decide which tool events should count toward the round.

func (*IMRoundState) AppendText

func (s *IMRoundState) AppendText(text string)

func (*IMRoundState) NoteToolCall

func (s *IMRoundState) NoteToolCall()

func (*IMRoundState) NoteToolResult

func (s *IMRoundState) NoteToolResult(isError bool)

func (*IMRoundState) Reset

func (s *IMRoundState) Reset()

func (*IMRoundState) Text

func (s *IMRoundState) Text() string

type InteractionBroker

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

func NewInteractionBroker

func NewInteractionBroker() *InteractionBroker

func (*InteractionBroker) ApprovalCount

func (b *InteractionBroker) ApprovalCount() int

func (*InteractionBroker) AskUserCount

func (b *InteractionBroker) AskUserCount() int

func (*InteractionBroker) AwaitApproval

func (*InteractionBroker) AwaitAskUser

func (*InteractionBroker) CancelAll

func (b *InteractionBroker) CancelAll() ([]ApprovalRequest, []AskUserRequest)

func (*InteractionBroker) FirstPendingApproval

func (b *InteractionBroker) FirstPendingApproval() (ApprovalRequest, bool)

func (*InteractionBroker) FirstPendingAskUser

func (b *InteractionBroker) FirstPendingAskUser() (AskUserRequest, bool)

func (*InteractionBroker) PendingApproval

func (b *InteractionBroker) PendingApproval(id string) (ApprovalRequest, bool)

func (*InteractionBroker) PendingAskUser

func (b *InteractionBroker) PendingAskUser(id string) (AskUserRequest, bool)

func (*InteractionBroker) ResolveApproval

func (b *InteractionBroker) ResolveApproval(id string, decision permission.Decision) (ApprovalRequest, bool)

func (*InteractionBroker) ResolveAskUser

func (b *InteractionBroker) ResolveAskUser(id string, response toolpkg.AskUserResponse) (AskUserRequest, bool)

type InteractiveRuntimeCore

type InteractiveRuntimeCore struct {
	Registry       *tool.Registry
	MCPManager     *plugin.MCPManager
	PluginManager  *plugin.Manager
	AutoMemory     *memory.AutoMemory
	ProjectAutoMem *memory.AutoMemory
	SaveMemoryTool *tool.SaveMemoryTool
	StartupAssets  StartupAssets
	CommandManager *commands.Manager
	Tunnel         *TunnelHost // unified tunnel event management
	// contains filtered or unexported fields
}

func BuildInteractiveRuntimeCore

func BuildInteractiveRuntimeCore(cfg *config.Config, workingDir string, policy permission.PermissionPolicy) (*InteractiveRuntimeCore, error)

func (*InteractiveRuntimeCore) Close

func (c *InteractiveRuntimeCore) Close()

Close stops all background services. Call on shutdown.

func (*InteractiveRuntimeCore) MCPManagerCancel

func (c *InteractiveRuntimeCore) MCPManagerCancel() context.CancelFunc

MCPManagerCancel returns the MCP cancel function for callers that need cleanup on exit (e.g. TUI's defer chain).

func (*InteractiveRuntimeCore) SetConfigAgent

func (c *InteractiveRuntimeCore) SetConfigAgent(ag *agent.Agent)

SetConfigAgent injects the agent into the config tool for provider hot-reload. Must be called after the agent is created. Without this, config changes to vendor/endpoint/model/api_key will persist to disk but won't take effect until the next session restart.

func (*InteractiveRuntimeCore) SetConfigUINotify

func (c *InteractiveRuntimeCore) SetConfigUINotify(fn func())

SetConfigUINotify sets an optional callback for UI refresh after provider changes.

func (*InteractiveRuntimeCore) StartBackgroundServices

func (c *InteractiveRuntimeCore) StartBackgroundServices()

StartBackgroundServices launches all background services: MCP connections, etc. Must be called after UI callbacks are set (SetConfigUINotify, MCP OnUpdate, etc.) so that status changes are forwarded to the UI layer.

type PendingMessage

type PendingMessage[T any] struct {
	Text   string
	Hidden bool
	Meta   T
}

type PendingQueue

type PendingQueue[T any] struct {
	// contains filtered or unexported fields
}

func NewPendingQueue

func NewPendingQueue[T any]() *PendingQueue[T]

func (*PendingQueue[T]) Clear

func (q *PendingQueue[T]) Clear()

func (*PendingQueue[T]) Consume

func (q *PendingQueue[T]) Consume() (PendingMessage[T], bool)

func (*PendingQueue[T]) ConsumePrefix

func (q *PendingQueue[T]) ConsumePrefix(match func(PendingMessage[T]) bool) []PendingMessage[T]

func (*PendingQueue[T]) Count

func (q *PendingQueue[T]) Count() int

func (*PendingQueue[T]) Enqueue

func (q *PendingQueue[T]) Enqueue(text string, hidden bool, meta T) int

func (*PendingQueue[T]) Snapshot

func (q *PendingQueue[T]) Snapshot() []PendingMessage[T]

func (*PendingQueue[T]) SnapshotTexts

func (q *PendingQueue[T]) SnapshotTexts() []string

type ProjectionBrokerState

type ProjectionBrokerState struct {
	AuthorityEpoch uint64
	Replay         []tunnel.GatewayMessage
}

func PrepareProjectionBroker

func PrepareProjectionBroker(broker *tunnel.Broker, store *tunnel.ProjectionStore, ses *session.Session, recorder func(tunnel.GatewayMessage)) (ProjectionBrokerState, error)

type SessionState

type SessionState struct {
	Session              *session.Session
	UsageTurnIndex       int
	LastMetricDigestTurn int
}

func AdoptSession

func AdoptSession(ses *session.Session) SessionState

func ClearSession

func ClearSession() SessionState

func EnsureSession

func EnsureSession(store session.Store, current *session.Session, vendor, endpoint, model, workspace string) (SessionState, bool, error)

func LoadSession

func LoadSession(store session.Store, id string) (SessionState, error)

type StartupAssets

type StartupAssets struct {
	AutoContent        string
	AutoFiles          []string
	ProjectAutoContent string
	CommandManager     *commands.Manager
}

func LoadInteractiveStartupAssets

func LoadInteractiveStartupAssets(
	workingDir string,
	autoMem *memory.AutoMemory,
	projectAutoMem *memory.AutoMemory,
) StartupAssets

type TunnelAttachConfig

type TunnelAttachConfig struct {
	ReplayProvider func() []tunnel.GatewayMessage
	SessionID      string
	AuthorityEpoch uint64
	SessionInfo    *tunnel.SessionInfoData
	Status         *tunnel.StatusData
	Activity       *string
}

type TunnelCommandHooks

type TunnelCommandHooks struct {
	OnUserMessage      func(data tunnel.MessageData)
	OnInterrupt        func()
	OnModeChange       func(data tunnel.ModeChangeData)
	OnApprovalResponse func(data tunnel.ApprovalResponseData)
	OnAskUserResponse  func(data tunnel.AskUserResponseData)
	OnLanguageChange   func(data tunnel.LanguageChangeData)
	OnThemeChange      func(data tunnel.ThemeChangeData)
	OnServerAck        func(messageID string)
}

type TunnelHost

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

TunnelHost provides unified tunnel stream management for all frontends. It owns the projection broker (for recording and replay) and optionally forwards events to an online broker (when a mobile Share is active).

func NewTunnelHost

func NewTunnelHost() *TunnelHost

NewTunnelHost creates a new TunnelHost with an offline projection broker.

func (*TunnelHost) AttachOnlineBroker

func (h *TunnelHost) AttachOnlineBroker(broker *tunnel.Broker)

AttachOnlineBroker connects an online tunnel broker (from a Share session). Events recorded by the projection broker will be forwarded to this broker.

func (*TunnelHost) AuthorityEpoch

func (h *TunnelHost) AuthorityEpoch() uint64

AuthorityEpoch returns the current projection authority epoch.

func (*TunnelHost) BindSession

func (h *TunnelHost) BindSession(ses *session.Session, store session.Store) ProjectionBrokerState

BindSession binds the tunnel host to a session for event recording. Call this when the session changes or is first created. Returns the projection broker state with replay events and authority epoch.

func (*TunnelHost) Close

func (h *TunnelHost) Close()

Close stops any active share gracefully and cleans up resources.

func (*TunnelHost) DetachOnlineBroker

func (h *TunnelHost) DetachOnlineBroker()

DetachOnlineBroker disconnects the online broker (Share stopped).

func (*TunnelHost) OnlineBroker

func (h *TunnelHost) OnlineBroker() *tunnel.Broker

OnlineBroker returns the current online broker, or nil.

func (*TunnelHost) PrepareOnlineShare

func (h *TunnelHost) PrepareOnlineShare(broker *tunnel.Broker) []tunnel.GatewayMessage

PrepareOnlineShare configures an online broker for a fresh Share session. This must be called after AttachOnlineBroker. It performs all the negotiation steps that TUI's handleTunnelStartMsg does:

  • SetEventRecorder(nil) — online broker should not record; projection broker does that
  • SetReplayProvider — provides canonical replay events from projection store
  • BindSession + SetAuthorityEpoch — binds online broker to current session
  • AnnounceActiveSession — tells relay which session is active

Returns the replay events so the caller can also ReplayEvents() if needed.

func (*TunnelHost) ProjectionBroker

func (h *TunnelHost) ProjectionBroker() *tunnel.Broker

ProjectionBroker returns the projection broker, or nil.

func (*TunnelHost) ProjectionStore

func (h *TunnelHost) ProjectionStore() *tunnel.ProjectionStore

ProjectionStore returns the projection store, or nil.

func (*TunnelHost) PushActivity

func (h *TunnelHost) PushActivity(activity string)

PushActivity pushes an activity update to the mobile client.

func (*TunnelHost) PushStatus

func (h *TunnelHost) PushStatus(status, message string)

PushStatus pushes a status update to the mobile client.

func (*TunnelHost) PushStreamEvent

func (h *TunnelHost) PushStreamEvent(ev provider.StreamEvent)

PushStreamEvent pushes a provider stream event through the tunnel. This is the main entry point called by the agent stream callback.

func (*TunnelHost) PushUserMessage

func (h *TunnelHost) PushUserMessage(text string)

PushUserMessage pushes a user message to the tunnel.

func (*TunnelHost) PushUserMessageData

func (h *TunnelHost) PushUserMessageData(data tunnel.MessageData)

PushUserMessageData pushes a user message with custom data to the tunnel.

func (*TunnelHost) ResetStreamState

func (h *TunnelHost) ResetStreamState()

ResetStreamState resets the stream state for a new chat turn.

func (*TunnelHost) TunnelEvents

func (h *TunnelHost) TunnelEvents() []tunnel.GatewayMessage

TunnelEvents returns the projection replay events for the current session.

type TunnelMainStream

type TunnelMainStream struct {
	MessageID     string
	NeedsFinalize bool
}

func EnsureTunnelMainStream

func EnsureTunnelMainStream(state TunnelMainStream, broker *tunnel.Broker) TunnelMainStream

func FlushTunnelMainStream

func FlushTunnelMainStream(state TunnelMainStream, broker *tunnel.Broker, force bool) TunnelMainStream

func MarkTunnelMainStreamActive

func MarkTunnelMainStreamActive(state TunnelMainStream) TunnelMainStream

type TunnelStateUpdate

type TunnelStateUpdate struct {
	HasStatus   bool
	Status      string
	StatusMsg   string
	HasActivity bool
	Activity    string
}

Jump to

Keyboard shortcuts

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