daemon

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

Package daemon provides the AgentComms daemon configuration.

Package daemon provides the AgentComms daemon that serves as the communication hub.

Index

Constants

View Source
const (
	ErrCodeInvalidRequest = -32600
	ErrCodeMethodNotFound = -32601
	ErrCodeInvalidParams  = -32602
	ErrCodeInternal       = -32603
	ErrCodeNotFound       = -32604
)

Error codes.

View Source
const (
	MethodPing         = "ping"
	MethodStatus       = "status"
	MethodAgents       = "agents"
	MethodSend         = "send"
	MethodInterrupt    = "interrupt"
	MethodEvents       = "events"
	MethodReply        = "reply"
	MethodChannels     = "channels"
	MethodAgentMessage = "agent_message"
)

Method names.

Variables

This section is empty.

Functions

func DefaultSocketPath

func DefaultSocketPath() string

DefaultSocketPath returns the default socket path.

func IsDaemonRunning

func IsDaemonRunning(socketPath string) bool

IsDaemonRunning checks if the daemon is running by attempting to connect.

Types

type AgentConfig

type AgentConfig struct {
	// ID is the unique agent identifier.
	ID string `yaml:"id"`

	// Type is the agent type (tmux, process).
	Type string `yaml:"type"`

	// TmuxSession is the tmux session name (for type=tmux).
	TmuxSession string `yaml:"tmux_session"`

	// TmuxPane is the tmux pane identifier (for type=tmux).
	TmuxPane string `yaml:"tmux_pane"`
}

AgentConfig defines an agent and its tmux target.

type AgentInfo

type AgentInfo struct {
	ID     string `json:"id"`
	Type   string `json:"type"`
	Target string `json:"target"` // e.g., "tmux:session:pane"
	Status string `json:"status"` // "online" or "offline"
}

AgentInfo contains information about a registered agent.

type AgentMessageParams

type AgentMessageParams struct {
	// FromAgentID is the source agent sending the message.
	FromAgentID string `json:"from_agent_id"`

	// ToAgentID is the destination agent to receive the message.
	ToAgentID string `json:"to_agent_id"`

	// Message is the text content to send.
	Message string `json:"message"`
}

AgentMessageParams are the parameters for the agent_message method. This sends a message FROM one agent TO another agent.

type AgentMessageResult

type AgentMessageResult struct {
	EventID   string `json:"event_id"`
	Delivered bool   `json:"delivered"`
}

AgentMessageResult is the response for the agent_message method.

type AgentsResult

type AgentsResult struct {
	Agents []AgentInfo `json:"agents"`
}

AgentsResult is the response for the agents method.

type ChannelInfo

type ChannelInfo struct {
	ChannelID string `json:"channel_id"`
	AgentID   string `json:"agent_id"`
	Provider  string `json:"provider"`
}

ChannelInfo contains information about a mapped channel.

type ChannelMapping

type ChannelMapping struct {
	// ChannelID is the full channel identifier (provider:chatid).
	ChannelID string `yaml:"channel_id"`

	// AgentID is the target agent ID.
	AgentID string `yaml:"agent_id"`
}

ChannelMapping maps a chat channel to an agent. ChannelID format: "provider:chatid" (e.g., "discord:123456789")

type ChannelsResult

type ChannelsResult struct {
	Channels []ChannelInfo `json:"channels"`
}

ChannelsResult is the response for the channels method.

type ChatConfig

type ChatConfig struct {
	// Discord configuration (optional).
	Discord *DiscordConfig `yaml:"discord"`

	// Telegram configuration (optional).
	Telegram *TelegramConfig `yaml:"telegram"`

	// WhatsApp configuration (optional).
	WhatsApp *WhatsAppConfig `yaml:"whatsapp"`

	// Channels maps chat channels to agents.
	Channels []ChannelMapping `yaml:"channels"`
}

ChatConfig holds configuration for all chat providers.

type ChatSender

type ChatSender interface {
	SendMessage(ctx context.Context, channelID, content string) error
}

ChatSender is the interface for sending outbound chat messages.

type Client

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

Client provides access to the daemon via Unix socket.

func DefaultClient

func DefaultClient() *Client

DefaultClient creates a client using the default socket path.

func NewClient

func NewClient(socketPath string) *Client

NewClient creates a new daemon client.

func (*Client) AgentMessage

func (c *Client) AgentMessage(_ context.Context, fromAgentID, toAgentID, message string) (*AgentMessageResult, error)

AgentMessage sends a message from one agent to another.

func (*Client) Agents

func (c *Client) Agents(_ context.Context) (*AgentsResult, error)

Agents returns the list of registered agents.

func (*Client) Channels

func (c *Client) Channels(_ context.Context) (*ChannelsResult, error)

Channels returns the list of mapped channels.

func (*Client) Close

func (c *Client) Close() error

Close closes the connection to the daemon.

func (*Client) Connect

func (c *Client) Connect() error

Connect establishes a connection to the daemon.

func (*Client) Events

func (c *Client) Events(_ context.Context, agentID string, limit int) (*EventsResult, error)

Events returns recent events for an agent.

func (*Client) EventsSince

func (c *Client) EventsSince(_ context.Context, agentID, sinceID string, limit int) (*EventsResult, error)

EventsSince returns events after a specific event ID.

func (*Client) Interrupt

func (c *Client) Interrupt(_ context.Context, agentID, reason string) (*InterruptResult, error)

Interrupt sends an interrupt signal to an agent.

func (*Client) IsConnected

func (c *Client) IsConnected() bool

IsConnected returns true if connected to the daemon.

func (*Client) Ping

func (c *Client) Ping(_ context.Context) error

Ping checks if the daemon is responsive.

func (*Client) Reply

func (c *Client) Reply(_ context.Context, channelID, message, agentID string) (*ReplyResult, error)

Reply sends a message from an agent to a chat channel.

func (*Client) Send

func (c *Client) Send(_ context.Context, agentID, message string) (*SendResult, error)

Send sends a message to an agent.

func (*Client) Status

func (c *Client) Status(_ context.Context) (*StatusResult, error)

Status returns the daemon status.

type Config

type Config struct {
	// DataDir is the directory for storing data (default: ~/.agentcomms).
	DataDir string

	// SocketPath is the Unix socket path for IPC.
	SocketPath string

	// Logger is the structured logger.
	Logger *slog.Logger
}

Config holds daemon configuration.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns the default daemon configuration.

type Daemon

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

Daemon is the AgentComms communication hub.

func New

func New(cfg *Config) *Daemon

New creates a new daemon with the given configuration.

func (*Daemon) Chat

func (d *Daemon) Chat() *transport.ChatTransport

Chat returns the chat transport for outbound messages.

func (*Daemon) Client

func (d *Daemon) Client() *ent.Client

Client returns the Ent client for database operations.

func (*Daemon) Router

func (d *Daemon) Router() *router.Router

Router returns the event router.

func (*Daemon) Start

func (d *Daemon) Start(ctx context.Context) error

Start starts the daemon.

func (*Daemon) Stop

func (d *Daemon) Stop() error

Stop stops the daemon.

type DaemonConfig

type DaemonConfig struct {
	// DataDir overrides the default data directory.
	DataDir string `yaml:"data_dir"`

	// LogLevel sets the logging level (debug, info, warn, error).
	LogLevel string `yaml:"log_level"`

	// Agents defines the available agents.
	Agents []AgentConfig `yaml:"agents"`

	// Chat holds chat provider configuration (omnichat).
	Chat *ChatConfig `yaml:"chat"`
}

DaemonConfig holds the daemon configuration loaded from config.yaml.

func DefaultDaemonConfig

func DefaultDaemonConfig() *DaemonConfig

DefaultDaemonConfig returns a DaemonConfig with sensible defaults.

func LoadDaemonConfig

func LoadDaemonConfig(dataDir string) (*DaemonConfig, error)

LoadDaemonConfig loads configuration from the config file. It looks for config.yaml in the data directory.

func (*DaemonConfig) FindAgentByChannel

func (c *DaemonConfig) FindAgentByChannel(channelID string) (string, bool)

FindAgentByChannel returns the agent ID for a chat channel. channelID format: "provider:chatid" (e.g., "discord:123456789")

func (*DaemonConfig) GetAgent

func (c *DaemonConfig) GetAgent(id string) (*AgentConfig, bool)

GetAgent returns the agent config by ID.

func (*DaemonConfig) HasChatProviders

func (c *DaemonConfig) HasChatProviders() bool

HasChatProviders returns true if any chat provider is configured.

func (*DaemonConfig) Validate

func (c *DaemonConfig) Validate() error

Validate checks the configuration for errors.

type DiscordConfig

type DiscordConfig struct {
	// Token is the Discord bot token.
	Token string `yaml:"token"`

	// GuildID is the Discord guild (server) ID for filtering.
	GuildID string `yaml:"guild_id"`
}

DiscordConfig holds Discord-specific configuration.

type ErrorInfo

type ErrorInfo struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

ErrorInfo contains error details.

type EventInfo

type EventInfo struct {
	ID        string         `json:"id"`
	AgentID   string         `json:"agent_id"`
	ChannelID string         `json:"channel_id"`
	Type      string         `json:"type"`
	Role      string         `json:"role"`
	Timestamp time.Time      `json:"timestamp"`
	Status    string         `json:"status"`
	Payload   map[string]any `json:"payload"`
}

EventInfo contains information about an event.

type EventsParams

type EventsParams struct {
	AgentID string `json:"agent_id"`
	Limit   int    `json:"limit,omitempty"`
	Since   string `json:"since,omitempty"` // Event ID to start after
}

EventsParams are the parameters for the events method.

type EventsResult

type EventsResult struct {
	Events []EventInfo `json:"events"`
}

EventsResult is the response for the events method.

type InterruptParams

type InterruptParams struct {
	AgentID string `json:"agent_id"`
	Reason  string `json:"reason,omitempty"`
}

InterruptParams are the parameters for the interrupt method.

type InterruptResult

type InterruptResult struct {
	EventID   string `json:"event_id"`
	Delivered bool   `json:"delivered"`
}

InterruptResult is the response for the interrupt method.

type PingResult

type PingResult struct {
	Pong bool `json:"pong"`
}

PingResult is the response for the ping method.

type ReplyParams

type ReplyParams struct {
	// ChannelID is the target channel (format: "provider:chatid").
	ChannelID string `json:"channel_id"`

	// Message is the text to send.
	Message string `json:"message"`

	// AgentID is the agent sending the message (for event tracking).
	AgentID string `json:"agent_id,omitempty"`
}

ReplyParams are the parameters for the reply method. This sends a message FROM an agent TO a chat channel.

type ReplyResult

type ReplyResult struct {
	EventID   string `json:"event_id"`
	Delivered bool   `json:"delivered"`
}

ReplyResult is the response for the reply method.

type Request

type Request struct {
	// ID is a unique request identifier for correlation.
	ID string `json:"id"`

	// Method is the RPC method name.
	Method string `json:"method"`

	// Params contains method-specific parameters.
	Params json.RawMessage `json:"params,omitempty"`
}

Request represents a client request to the daemon.

func NewRequest

func NewRequest(id, method string, params any) (*Request, error)

NewRequest creates a new request with the given method and params.

func (*Request) ParseParams

func (r *Request) ParseParams(target any) error

ParseParams unmarshals request params into the target struct.

type Response

type Response struct {
	// ID matches the request ID.
	ID string `json:"id"`

	// Result contains the method result (on success).
	Result json.RawMessage `json:"result,omitempty"`

	// Error contains error details (on failure).
	Error *ErrorInfo `json:"error,omitempty"`
}

Response represents a daemon response to a client.

func NewErrorResponse

func NewErrorResponse(id string, code int, message string) *Response

NewErrorResponse creates an error response.

func NewResponse

func NewResponse(id string, result any) (*Response, error)

NewResponse creates a successful response.

func (*Response) Err

func (r *Response) Err() error

Err returns an error if the response contains an error, nil otherwise.

func (*Response) IsError

func (r *Response) IsError() bool

IsError returns true if the response contains an error.

func (*Response) ParseResult

func (r *Response) ParseResult(target any) error

ParseResult unmarshals response result into the target struct.

type SendParams

type SendParams struct {
	AgentID string `json:"agent_id"`
	Message string `json:"message"`
}

SendParams are the parameters for the send method.

type SendResult

type SendResult struct {
	EventID   string `json:"event_id"`
	Delivered bool   `json:"delivered"`
}

SendResult is the response for the send method.

type Server

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

Server handles IPC requests over a Unix socket.

func NewServer

func NewServer(cfg ServerConfig) *Server

NewServer creates a new IPC server.

func (*Server) Start

func (s *Server) Start(ctx context.Context) error

Start starts the server and begins accepting connections.

func (*Server) Stop

func (s *Server) Stop() error

Stop stops the server.

type ServerConfig

type ServerConfig struct {
	SocketPath string
	Client     *ent.Client
	Router     *router.Router
	DaemonCfg  *DaemonConfig
	ChatSender ChatSender
	Providers  []string
	Logger     *slog.Logger
}

ServerConfig holds server configuration.

type StatusResult

type StatusResult struct {
	Running   bool      `json:"running"`
	StartedAt time.Time `json:"started_at"`
	Agents    int       `json:"agents"`
	Providers []string  `json:"providers"`
}

StatusResult is the response for the status method.

type TelegramConfig

type TelegramConfig struct {
	// Token is the Telegram bot token.
	Token string `yaml:"token"`
}

TelegramConfig holds Telegram-specific configuration.

type WhatsAppConfig

type WhatsAppConfig struct {
	// DBPath is the SQLite database path for session storage.
	DBPath string `yaml:"db_path"`
}

WhatsAppConfig holds WhatsApp-specific configuration.

Jump to

Keyboard shortcuts

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