Documentation
¶
Index ¶
- func CommandRiskLevel(command string) string
- func FormatApprovalNotification(toolName string, args map[string]any, riskLevel string, approved bool) string
- func RegisterActiveAgent(id string, a *agent.Agent)
- func UnregisterActiveAgent(id string)
- type AgentConfig
- type ApprovalDecision
- type ChannelSession
- type Config
- func (c *Config) GetDefaultModel(settingsModel string) string
- func (c *Config) GetDefaultProvider(settingsProvider string) string
- func (c *Config) GetListenAddr() string
- func (c *Config) GetPlatformWorkDir(platform string) string
- func (c *Config) GetWechatCredPath() string
- func (c *Config) GetWorkDir() string
- type CronConfig
- type Dispatcher
- func (d *Dispatcher) AgentManager() *agent.AgentManager
- func (d *Dispatcher) EnsureAgentManager() *agent.AgentManager
- func (d *Dispatcher) GetSession(key string) *ChannelSession
- func (d *Dispatcher) HandleMessage(ctx context.Context, msg messaging.InboundMessage) (string, error)
- func (d *Dispatcher) HandleWSMessage(ctx context.Context, connID, text string, eventCh chan<- agent.Event) error
- func (d *Dispatcher) ListSessions() []*ChannelSession
- func (d *Dispatcher) RegisterApproval(approvalID string) chan bool
- func (d *Dispatcher) RemoveSession(key string)
- func (d *Dispatcher) ResolveApproval(approvalID string, approved bool) bool
- func (d *Dispatcher) ResolveQuestion(questionID, answer string) bool
- func (d *Dispatcher) RotateSession(platform, userID string) error
- func (d *Dispatcher) SetCronScheduler(s *cron.Scheduler)
- type FeishuConfig
- type HooksConfig
- type MemoryConfig
- type Security
- type SecurityConfig
- type ServerConfig
- type WebhookConfig
- type WebhookHandler
- type WebhookRoute
- type WechatConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CommandRiskLevel ¶
CommandRiskLevel classifies the risk level of a bash command. Returns "low", "medium", or "high".
func FormatApprovalNotification ¶
func FormatApprovalNotification(toolName string, args map[string]any, riskLevel string, approved bool) string
FormatApprovalNotification formats a notification for medium/high risk tool calls.
func RegisterActiveAgent ¶
RegisterActiveAgent registers a running agent for question resolution.
func UnregisterActiveAgent ¶
func UnregisterActiveAgent(id string)
UnregisterActiveAgent removes an agent from the registry.
Types ¶
type AgentConfig ¶
type AgentConfig struct {
MaxTurns int `json:"max_turns"`
BudgetPressure bool `json:"budget_pressure"`
ContextPressure bool `json:"context_pressure"`
BudgetPressureThreshold float64 `json:"budget_pressure_threshold,omitempty"` // remaining ratio (0-1), default 0.20
ContextPressureThreshold float64 `json:"context_pressure_threshold,omitempty"` // usage ratio (0-1), default 0.55
}
AgentConfig defines agent behavior settings.
type ApprovalDecision ¶
ApprovalDecision represents the result of an approval check.
type ChannelSession ¶
type ChannelSession struct {
ID string // e.g. "channels/wechat/wxid_user1"
Platform string // "wechat", "feishu", "ws"
UserID string
WorkDir string
Manager *session.Manager
SandboxMgr *sandbox.Manager
Registry *tools.Registry
MCPClients []*mcp.Client // connected MCP clients (nil if none)
Mode string
LastUsed time.Time
// ForceCompact is a legacy/session flag consumed by the next agent run.
// The /compact command now executes compaction immediately.
ForceCompact bool
// contains filtered or unexported fields
}
ChannelSession holds state for a single channel user session.
func (*ChannelSession) Touch ¶
func (s *ChannelSession) Touch()
Touch updates the last-used timestamp.
type Config ¶
type Config struct {
Server ServerConfig `json:"server"`
DefaultProvider string `json:"default_provider,omitempty"`
DefaultModel string `json:"default_model,omitempty"`
MultiAgent bool `json:"multi_agent,omitempty"`
WebSearch bool `json:"web_search,omitempty"`
Browser bool `json:"browser,omitempty"`
A2AMaster bool `json:"a2a_master,omitempty"`
Sandbox bool `json:"sandbox,omitempty"`
Wechat WechatConfig `json:"wechat"`
Feishu FeishuConfig `json:"feishu"`
Webhooks WebhookConfig `json:"webhooks"`
Cron CronConfig `json:"cron"`
Memory MemoryConfig `json:"memory"`
Security SecurityConfig `json:"security"`
Hooks HooksConfig `json:"hooks"`
Agent AgentConfig `json:"agent"`
WorkDir string `json:"work_dir"`
}
Config holds messaging channel runtime configuration.
func (*Config) GetDefaultModel ¶
GetDefaultModel returns the effective default model. Priority: Config → Settings
func (*Config) GetDefaultProvider ¶
GetDefaultProvider returns the effective default provider. Priority: Config → Settings
func (*Config) GetListenAddr ¶
GetListenAddr returns the listen address string.
func (*Config) GetPlatformWorkDir ¶
GetPlatformWorkDir returns the work directory for a specific platform. Priority: platform work_dir → global work_dir → cwd
func (*Config) GetWechatCredPath ¶
GetWechatCredPath returns the wechat credentials path.
func (*Config) GetWorkDir ¶
GetWorkDir returns the resolved work directory. Falls back to current directory if not set.
type CronConfig ¶
type CronConfig struct {
Enabled bool `json:"enabled"`
Interval int `json:"interval,omitempty"` // seconds between checks (default 30)
}
CronConfig defines cron scheduler settings.
type Dispatcher ¶
type Dispatcher struct {
// contains filtered or unexported fields
}
Dispatcher routes messages to per-user agent sessions.
func NewDispatcher ¶
func NewDispatcher(cfg *Config, settings *config.Settings, version string, cronStore cron.CronStore, scheduler *cron.Scheduler) (*Dispatcher, error)
NewDispatcher creates a dispatcher with the given configuration.
func (*Dispatcher) AgentManager ¶
func (d *Dispatcher) AgentManager() *agent.AgentManager
AgentManager returns the dispatcher agent manager used by sub-agents and cron.
func (*Dispatcher) EnsureAgentManager ¶
func (d *Dispatcher) EnsureAgentManager() *agent.AgentManager
EnsureAgentManager creates the dispatcher agent manager if it is not already available.
func (*Dispatcher) GetSession ¶
func (d *Dispatcher) GetSession(key string) *ChannelSession
GetSession returns a session by key, or nil if not found.
func (*Dispatcher) HandleMessage ¶
func (d *Dispatcher) HandleMessage(ctx context.Context, msg messaging.InboundMessage) (string, error)
HandleMessage processes an inbound message from any platform.
func (*Dispatcher) HandleWSMessage ¶
func (d *Dispatcher) HandleWSMessage(ctx context.Context, connID, text string, eventCh chan<- agent.Event) error
HandleWSMessage processes a message from a WebSocket client.
func (*Dispatcher) ListSessions ¶
func (d *Dispatcher) ListSessions() []*ChannelSession
ListSessions returns all active session keys.
func (*Dispatcher) RegisterApproval ¶
func (d *Dispatcher) RegisterApproval(approvalID string) chan bool
RegisterApproval registers a pending approval and returns its channel.
func (*Dispatcher) RemoveSession ¶
func (d *Dispatcher) RemoveSession(key string)
RemoveSession removes a session from the pool.
func (*Dispatcher) ResolveApproval ¶
func (d *Dispatcher) ResolveApproval(approvalID string, approved bool) bool
ResolveApproval resolves a pending approval with the given decision.
func (*Dispatcher) ResolveQuestion ¶
func (d *Dispatcher) ResolveQuestion(questionID, answer string) bool
ResolveQuestion sends an answer to a currently running agent question.
func (*Dispatcher) RotateSession ¶
func (d *Dispatcher) RotateSession(platform, userID string) error
RotateSession archives the current session and creates a new one. Called when user sends /new.
func (*Dispatcher) SetCronScheduler ¶
func (d *Dispatcher) SetCronScheduler(s *cron.Scheduler)
SetCronScheduler updates the scheduler used by cron tools created for sessions.
type FeishuConfig ¶
type FeishuConfig struct {
Enabled bool `json:"enabled"`
AppID string `json:"app_id"`
AppSecret string `json:"app_secret"`
WorkDir string `json:"work_dir"`
AllowedUsers []string `json:"allowed_users"`
}
FeishuConfig defines Feishu (Lark) platform settings.
type HooksConfig ¶
type HooksConfig struct {
PreToolCall string `json:"pre_tool_call"`
PostToolCall string `json:"post_tool_call"`
}
HooksConfig defines shell hook scripts.
type MemoryConfig ¶
type MemoryConfig struct {
Enabled bool `json:"enabled"`
Path string `json:"path"` // empty = auto-discover .mothx/memory.md → <GLOBAL_DIR>/memory.md
}
MemoryConfig defines persistent memory settings.
type Security ¶
type Security struct {
// contains filtered or unexported fields
}
Security provides user whitelist validation and smart approval logic for messaging channel mode.
func (*Security) CheckUserAllowed ¶
CheckUserAllowed returns nil if the user is allowed on the given platform. Returns an error with reason if blocked.
func (*Security) CheckWorkDirAllowed ¶
CheckWorkDirAllowed returns nil if the working directory is allowed.
func (*Security) ShouldAutoApprove ¶
ShouldAutoApprove returns true if the tool call can be auto-approved in messaging channel mode. In messaging channel mode, bots run unattended so we need stricter auto-approval rules.
type SecurityConfig ¶
type SecurityConfig struct {
SmartApprovals bool `json:"smart_approvals"`
AllowedWorkDirs []string `json:"allowed_work_dirs"`
}
SecurityConfig defines security settings.
type ServerConfig ¶
type ServerConfig struct {
Port int `json:"port"`
Host string `json:"host"`
AuthToken string `json:"auth_token"`
}
ServerConfig defines the WebSocket runtime settings.
type WebhookConfig ¶
type WebhookConfig struct {
Enabled bool `json:"enabled"`
Secret string `json:"secret"`
Routes []WebhookRoute `json:"routes"`
}
WebhookConfig defines inbound webhook settings.
type WebhookHandler ¶
type WebhookHandler struct {
// contains filtered or unexported fields
}
WebhookHandler implements webhook.Handler by spawning agent tasks.
func NewWebhookHandler ¶
func NewWebhookHandler(dispatcher *Dispatcher, platforms map[string]messaging.Platform) *WebhookHandler
NewWebhookHandler creates a webhook handler that spawns agent tasks.
func (*WebhookHandler) HandleWebhookEvent ¶
func (h *WebhookHandler) HandleWebhookEvent(ctx context.Context, route webhook.RouteConfig, payload []byte) error
HandleWebhookEvent processes an incoming webhook event by spawning an agent task.
func (*WebhookHandler) SetPlatforms ¶
func (h *WebhookHandler) SetPlatforms(platforms map[string]messaging.Platform)
SetPlatforms replaces the platform map. Used to wire platforms after construction.