control

package
v0.13.1 Latest Latest
Warning

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

Go to latest
Published: May 26, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrRuntimeNotFound = errors.New("runtime not found")

Functions

This section is empty.

Types

type ControlServer

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

func NewServer

func NewServer(state *ControlState) *ControlServer

func (*ControlServer) BeginPermissionClaim

func (s *ControlServer) BeginPermissionClaim(requestID string) (<-chan PermissionAnswer, bool)

BeginPermissionClaim registers a new permission claim for requestID and returns the answer channel plus true. If a claim is already in flight it returns nil, false — the caller must not overwrite an active claim.

func (*ControlServer) ConsumeInterrupt

func (s *ControlServer) ConsumeInterrupt() string

func (*ControlServer) DequeuePrompt

func (s *ControlServer) DequeuePrompt() string

func (*ControlServer) EndPermissionClaim

func (s *ControlServer) EndPermissionClaim(requestID string)

func (*ControlServer) HasClients

func (s *ControlServer) HasClients() bool

HasClients reports whether the control plane has at least one connected client capable of answering control RPCs. Returns false when no socket is bound (e.g. --http-debug without --control-socket) or when no client has dialed in yet. Used to gate features that should defer to fallbacks (file-handler permissions) when nothing on the socket can answer.

func (*ControlServer) HasPendingPermission

func (s *ControlServer) HasPendingPermission() bool

HasPendingPermission reports whether a permission claim is currently registered. Used by tests to verify claims are cleaned up after timeout.

func (*ControlServer) InterruptChan

func (s *ControlServer) InterruptChan() <-chan struct{}

InterruptChan returns the channel that closes when an interrupt fires. Idempotent: returns the same channel until ResetInterrupt is called.

func (*ControlServer) InterruptPrompt

func (s *ControlServer) InterruptPrompt(text string, keepQueue bool)

func (*ControlServer) PublishEvent

func (s *ControlServer) PublishEvent(event events.Event)

func (*ControlServer) QueuePrompt

func (s *ControlServer) QueuePrompt(text string)

func (*ControlServer) ResetInterrupt

func (s *ControlServer) ResetInterrupt()

ResetInterrupt closes the current interrupt channel (if any) and creates a fresh one. Call this between turns to re-arm the interrupt signal.

func (*ControlServer) SetCancelFunc

func (s *ControlServer) SetCancelFunc(fn func())

func (*ControlServer) SetStableHandler

func (s *ControlServer) SetStableHandler(h StableHandler)

func (*ControlServer) Start

func (s *ControlServer) Start(socketPath string) error

func (*ControlServer) Stop

func (s *ControlServer) Stop()

func (*ControlServer) SubscribeEvents

func (s *ControlServer) SubscribeEvents(ctx context.Context) <-chan events.Event

type ControlState

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

func NewState

func NewState(runID, runLabel string, maxRetries int) *ControlState

func (*ControlState) Snapshot

func (s *ControlState) Snapshot() Snapshot

func (*ControlState) Update

func (s *ControlState) Update(fn func(*Snapshot))

type HTTPDebugServer

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

func NewHTTPDebugServer

func NewHTTPDebugServer(addr string, control *ControlServer) (*HTTPDebugServer, error)

func (*HTTPDebugServer) SetStableAdapter

func (h *HTTPDebugServer) SetStableAdapter(a StableAdapter)

SetStableAdapter wires a StableAdapter into the debug server so that per-runtime endpoints are active. The supervisor calls this immediately after NewHTTPDebugServer; CLI mode never calls it. Passing nil is a no-op.

func (*HTTPDebugServer) Start

func (h *HTTPDebugServer) Start() error

func (*HTTPDebugServer) Stop

func (h *HTTPDebugServer) Stop(ctx context.Context) error

type Notification

type Notification struct {
	JSONRPC string `json:"jsonrpc"`
	Method  string `json:"method"`
	Params  any    `json:"params,omitempty"`
}

type PermissionAnswer

type PermissionAnswer struct {
	RequestID string `json:"request_id"`
	OptionID  string `json:"option_id"`
}

type Request

type Request struct {
	JSONRPC string          `json:"jsonrpc"`
	ID      any             `json:"id,omitempty"`
	Method  string          `json:"method"`
	Params  json.RawMessage `json:"params,omitempty"`
}

type RespError

type RespError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    any    `json:"data,omitempty"`
}

type Response

type Response struct {
	JSONRPC string     `json:"jsonrpc"`
	ID      any        `json:"id"`
	Result  any        `json:"result,omitempty"`
	Error   *RespError `json:"error,omitempty"`
}

type Snapshot

type Snapshot struct {
	SessionID         string         `json:"session_id,omitempty"`
	RunID             string         `json:"run_id,omitempty"`
	RunLabel          string         `json:"run_label,omitempty"`
	Phase             string         `json:"phase,omitempty"`
	PhaseLabel        string         `json:"phase_label,omitempty"`
	LastEvent         string         `json:"last_event,omitempty"`
	RetryAttempt      int            `json:"retry_attempt,omitempty"`
	MaxRetries        int            `json:"max_retries,omitempty"`
	PendingPermission bool           `json:"pending_permission"`
	Permission        map[string]any `json:"permission,omitempty"`
	StartedAt         int64          `json:"started_at"`
	UpdatedAt         int64          `json:"updated_at"`
	TurnState         string         `json:"turn_state,omitempty"`
}

type StableAdapter

type StableAdapter interface {
	// HTTPRuntimeStatus returns the runtime snapshot for the given runtimeID.
	// Returns ErrRuntimeNotFound if the runtime ID does not exist.  Other
	// errors indicate operational failures and should map to 500.
	HTTPRuntimeStatus(runtimeID string) (any, error)
	// HTTPCancelRuntime cancels the named runtime.  Returns ErrRuntimeNotFound
	// if the runtime ID does not exist.  Other errors indicate operational
	// failures and should map to 500.
	HTTPCancelRuntime(runtimeID string) error
}

StableAdapter is the minimal interface that HTTPDebugServer needs to serve per-runtime endpoints in stable mode. The supervisor implements this; CLI mode passes nil (no adapter wired).

Method names are prefixed with HTTP to avoid shadowing the StableHandler methods on *Supervisor which carry the same logical names but different signatures (e.g. RuntimeStatus returns (any, error) there).

type StableHandler

type StableHandler interface {
	Spawn(params json.RawMessage) (any, error)
	List() any
	Shutdown(mode string) error
	RuntimeStatus(runtimeID string) (any, error)
	RuntimeCancel(runtimeID string) error
	RuntimePrompt(runtimeID, text string) error
	RuntimeAnswerPermission(runtimeID, requestID, optionID string) error
	RuntimeInterruptAndPrompt(runtimeID, text string, keepQueue bool) error
}

Jump to

Keyboard shortcuts

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