ipc

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package ipc provides inter-process communication between agentmgr CLI and helper.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotConnected   = errors.New("not connected to server")
	ErrServerClosed   = errors.New("server is closed")
	ErrTimeout        = errors.New("operation timed out")
	ErrInvalidMessage = errors.New("invalid message format")
)

Common errors

Functions

func DefaultSocketPath

func DefaultSocketPath() string

DefaultSocketPath returns the default IPC socket/pipe path for the current platform.

Types

type Client

type Client interface {
	// Connect establishes a connection to the server.
	Connect(ctx context.Context) error

	// Disconnect closes the connection.
	Disconnect() error

	// Send sends a message and waits for a response.
	Send(ctx context.Context, msg *Message) (*Message, error)

	// SendAsync sends a message without waiting for a response.
	SendAsync(msg *Message) error

	// Subscribe registers a callback for notifications.
	Subscribe(callback func(*Message))

	// IsConnected returns true if connected to the server.
	IsConnected() bool
}

Client represents an IPC client.

func NewClient

func NewClient(address string) Client

NewClient creates a new IPC client appropriate for the current platform.

func NewUnixClient

func NewUnixClient(socketPath string) Client

NewUnixClient creates a new Unix socket client.

type ErrorResponse

type ErrorResponse struct {
	Code    string `json:"code"`
	Message string `json:"message"`
	Details string `json:"details,omitempty"`
}

ErrorResponse is the payload for error responses.

type GetAgentRequest

type GetAgentRequest struct {
	Key string `json:"key"`
}

GetAgentRequest is the payload for get_agent requests.

type GetAgentResponse

type GetAgentResponse struct {
	Agent *agent.Installation `json:"agent,omitempty"`
}

GetAgentResponse is the payload for get_agent responses.

type Handler

type Handler interface {
	HandleMessage(ctx context.Context, msg *Message) (*Message, error)
}

Handler processes incoming IPC messages.

type HandlerFunc

type HandlerFunc func(ctx context.Context, msg *Message) (*Message, error)

HandlerFunc is a function adapter for Handler.

func (HandlerFunc) HandleMessage

func (f HandlerFunc) HandleMessage(ctx context.Context, msg *Message) (*Message, error)

HandleMessage implements Handler.

type InstallAgentRequest

type InstallAgentRequest struct {
	AgentID string              `json:"agent_id"`
	Method  agent.InstallMethod `json:"method"`
	Global  bool                `json:"global"`
}

InstallAgentRequest is the payload for install_agent requests.

type InstallAgentResponse

type InstallAgentResponse struct {
	Installation *agent.Installation `json:"installation"`
	Success      bool                `json:"success"`
	Message      string              `json:"message,omitempty"`
}

InstallAgentResponse is the payload for install_agent responses.

type ListAgentsRequest

type ListAgentsRequest struct {
	Filter *agent.Filter `json:"filter,omitempty"`
}

ListAgentsRequest is the payload for list_agents requests.

type ListAgentsResponse

type ListAgentsResponse struct {
	Agents []agent.Installation `json:"agents"`
	Total  int                  `json:"total"`
}

ListAgentsResponse is the payload for list_agents responses.

type Message

type Message struct {
	ID        string          `json:"id"`
	Type      MessageType     `json:"type"`
	Timestamp time.Time       `json:"timestamp"`
	Payload   json.RawMessage `json:"payload,omitempty"`
}

Message represents an IPC message between CLI and helper.

func NewMessage

func NewMessage(msgType MessageType, payload interface{}) (*Message, error)

NewMessage creates a new message with the given type and payload.

func (*Message) DecodePayload

func (m *Message) DecodePayload(target interface{}) error

DecodePayload decodes the message payload into the target struct.

type MessageType

type MessageType string

MessageType defines the type of IPC message.

const (
	// Request types
	MessageTypeListAgents     MessageType = "list_agents"
	MessageTypeGetAgent       MessageType = "get_agent"
	MessageTypeInstallAgent   MessageType = "install_agent"
	MessageTypeUpdateAgent    MessageType = "update_agent"
	MessageTypeUninstallAgent MessageType = "uninstall_agent"
	MessageTypeRefreshCatalog MessageType = "refresh_catalog"
	MessageTypeCheckUpdates   MessageType = "check_updates"
	MessageTypeGetStatus      MessageType = "get_status"
	MessageTypeShutdown       MessageType = "shutdown"

	// Response types
	MessageTypeSuccess  MessageType = "success"
	MessageTypeError    MessageType = "error"
	MessageTypeProgress MessageType = "progress"

	// Notification types (helper -> CLI)
	MessageTypeUpdateAvailable MessageType = "update_available"
	MessageTypeAgentInstalled  MessageType = "agent_installed"
	MessageTypeAgentUpdated    MessageType = "agent_updated"
	MessageTypeAgentRemoved    MessageType = "agent_removed"
)

type ProgressResponse

type ProgressResponse struct {
	Operation string  `json:"operation"`
	Progress  float64 `json:"progress"` // 0.0 to 1.0
	Message   string  `json:"message,omitempty"`
}

ProgressResponse is the payload for progress updates.

type Server

type Server interface {
	// Start begins listening for connections.
	Start(ctx context.Context) error

	// Stop gracefully shuts down the server.
	Stop(ctx context.Context) error

	// SetHandler sets the message handler.
	SetHandler(handler Handler)

	// IsRunning returns true if the server is running.
	IsRunning() bool

	// Address returns the server's address (socket path or pipe name).
	Address() string
}

Server represents an IPC server.

func NewServer

func NewServer(address string) Server

NewServer creates a new IPC server appropriate for the current platform.

func NewUnixServer

func NewUnixServer(socketPath string) Server

NewUnixServer creates a new Unix socket server.

type StatusResponse

type StatusResponse struct {
	Running            bool      `json:"running"`
	PID                int       `json:"pid"`
	Uptime             int64     `json:"uptime_seconds"`
	AgentCount         int       `json:"agent_count"`
	UpdatesAvailable   int       `json:"updates_available"`
	LastCatalogRefresh time.Time `json:"last_catalog_refresh"`
	LastUpdateCheck    time.Time `json:"last_update_check"`
}

StatusResponse is the payload for get_status responses.

type UninstallAgentRequest

type UninstallAgentRequest struct {
	Key string `json:"key"`
}

UninstallAgentRequest is the payload for uninstall_agent requests.

type UpdateAgentRequest

type UpdateAgentRequest struct {
	Key string `json:"key"`
}

UpdateAgentRequest is the payload for update_agent requests.

type UpdateAgentResponse

type UpdateAgentResponse struct {
	Installation *agent.Installation `json:"installation"`
	FromVersion  string              `json:"from_version"`
	ToVersion    string              `json:"to_version"`
	Success      bool                `json:"success"`
	Message      string              `json:"message,omitempty"`
}

UpdateAgentResponse is the payload for update_agent responses.

type UpdateAvailableNotification

type UpdateAvailableNotification struct {
	AgentID     string `json:"agent_id"`
	AgentName   string `json:"agent_name"`
	FromVersion string `json:"from_version"`
	ToVersion   string `json:"to_version"`
	Changelog   string `json:"changelog,omitempty"`
}

UpdateAvailableNotification is sent when an update is detected.

Jump to

Keyboard shortcuts

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