Documentation
¶
Index ¶
- Constants
- Variables
- func BuildToolDefs(d *Dispatcher) []provider.ToolDefinition
- func NewDispatcherFactory(backupDir, sessionsDir string, permCfg *config.PermissionsConfig, ...) subagent.DispatcherFactory
- func SetVersion(v string)
- type Agent
- type AskUserQuestion
- type Bash
- type CodeComplexity
- type CodeMap
- type ComplexityReport
- type DevServer
- type Dispatcher
- func (d *Dispatcher) ApprovePermission(requestID int64, allowed bool, remember bool)
- func (d *Dispatcher) Execute(ctx context.Context, call types.ToolCall) (types.ToolResult, error)
- func (d *Dispatcher) GetTool(name string) (types.Tool, bool)
- func (d *Dispatcher) List() []string
- func (d *Dispatcher) QuestionRequestCh() chan QuestionRequest
- func (d *Dispatcher) QuestionResponseCh() chan QuestionResponse
- func (d *Dispatcher) Register(tool types.Tool) error
- func (d *Dispatcher) RequestCh() chan PermissionRequest
- func (d *Dispatcher) RespondQuestion(requestID int64, answer string)
- func (d *Dispatcher) SelectAgent(agent string) error
- func (d *Dispatcher) SetOutputStore(store *OutputStore)
- func (d *Dispatcher) SetPermission(toolName string, allowed bool)
- func (d *Dispatcher) SetSessionID(id string)
- func (d *Dispatcher) SetTodoWriteCallback(fn func(items []TodoItem))
- func (d *Dispatcher) Stop()
- func (d *Dispatcher) Unregister(name string)
- func (d *Dispatcher) UpdatePermissions(cfg *config.PermissionsConfig)
- type Edit
- type FileDelete
- type FileList
- type FileMove
- type FileRead
- type FileStat
- type FileWrite
- type Glob
- type Grep
- type HTTPCheck
- type MetricsTool
- type OutputStore
- type PackageStat
- type PermissionContext
- type PermissionRequest
- type PermissionResponse
- type PersistentPermissions
- type QuestionRequest
- type QuestionResponse
- type TodoItem
- type TodoWrite
- func (t *TodoWrite) Description() string
- func (t *TodoWrite) Execute(ctx context.Context, input types.ToolInput) (types.ToolResult, error)
- func (t *TodoWrite) Name() string
- func (t *TodoWrite) ParameterSchema() string
- func (t *TodoWrite) RiskLevel() types.RiskLevel
- func (t *TodoWrite) SetOnUpdate(fn func(items []TodoItem))
- func (t *TodoWrite) SetSessionID(id string)
- type WebFetch
- type WebSearch
Constants ¶
const ( BashKillGracePeriod = time.Duration(types.DefaultBashKillGraceSecs) * time.Second BashWaitTimeout = 30 * time.Second MaxBackupsPerFile = types.DefaultMaxBackupsPerFile DirPermission = types.DirPermission FilePermission = types.FilePermission MaxGlobResults = types.DefaultMaxGlobResults MaxGrepPatternLength = 1024 DefaultMaxGrepResults = types.DefaultMaxGrepResults MaxRedirects = types.DefaultWebfetchMaxRedirects DefaultTimeoutSecs = 30 MaxTimeoutSecs = 120 DNSCacheTTL = 5 * time.Minute MinLinesForFuzzy = 3 LevenshteinThreshold = 0.7 PermissionChannelBuffer = 8 QuestionChannelBuffer = 4 DefaultAgentName = "default" // Rate limiting: token bucket for tool execution. // Max 20 tools per second burst, sustained 10 tools/second. ToolRateLimitBurst = 20 ToolRateLimitPerSec = 10 // Per-risk-level rate limits (M6): dangerous tools get stricter limits. DangerousRateLimitBurst = 5 DangerousRateLimitPerSec = 2 // Max concurrent tool executions (M5): prevents resource exhaustion. MaxConcurrentTools = 8 DefaultSearchBaseURL = "https://search.sagibo.net" MaxSearchQueryLength = 500 DefaultMaxSearchResults = 5 MaxSearchResults = 10 DefaultOutputMaxLines = 2000 DefaultOutputMaxBytes = 51200 OutputRetentionDays = 7 )
const MaxAgentDepth = 2
MaxAgentDepth is the maximum nesting depth for subagents. Depth 0 is the root agent, depth 1 is a child, depth 2 is a grandchild. Going deeper is blocked to prevent runaway resource consumption.
Variables ¶
var Version atomic.Value
Version is the application version used in User-Agent headers. Set via SetVersion() from cmd/m31a/main.go.
Functions ¶
func BuildToolDefs ¶
func BuildToolDefs(d *Dispatcher) []provider.ToolDefinition
BuildToolDefs creates provider.ToolDefinition slices from a Dispatcher's registered tools. This is shared between the workflow engine and the autonomous agent loop to avoid duplicating tool schema logic.
func NewDispatcherFactory ¶
func NewDispatcherFactory(backupDir, sessionsDir string, permCfg *config.PermissionsConfig, manager *subagent.Manager, profiles map[string]config.SubagentProfileConfig) subagent.DispatcherFactory
NewDispatcherFactory returns a DispatcherFactory that creates a fresh tools.Dispatcher for each subagent workspace. The factory registers the Agent tool (with isChild=true) on every dispatcher so a subagent can spawn its own child, but forced-foreground to block runaway fan-out.
backupDir and sessionsDir are shared across all dispatchers; permCfg is reused verbatim so permission rules apply uniformly.
func SetVersion ¶
func SetVersion(v string)
SetVersion sets the application version for User-Agent headers.
Types ¶
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
Agent is a tool that spawns a parallel subagent to perform an independent task. The parent conversation receives the subagent's ID immediately and can continue issuing other tool calls while the subagent runs.
Background mode (default) returns the agent ID and delivers the final summary to the parent via SubagentEvent messages consumed by the TUI. Foreground mode (run_in_background=false) blocks until the subagent finishes and returns its summary as this tool's output.
func NewAgent ¶
func NewAgent(m *subagent.Manager, isChild bool, depth int, profiles map[string]config.SubagentProfileConfig) *Agent
NewAgent creates an Agent tool backed by the given manager.
func (*Agent) Description ¶
func (*Agent) ParameterSchema ¶
ParameterSchema returns the JSON schema exposed to the LLM.
type AskUserQuestion ¶
type AskUserQuestion struct {
// contains filtered or unexported fields
}
func NewAskUserQuestion ¶
func NewAskUserQuestion(requestCh chan QuestionRequest, responseCh chan QuestionResponse, pending *sync.Map) *AskUserQuestion
func (*AskUserQuestion) Description ¶
func (t *AskUserQuestion) Description() string
func (*AskUserQuestion) Execute ¶
func (t *AskUserQuestion) Execute(ctx context.Context, input types.ToolInput) (types.ToolResult, error)
func (*AskUserQuestion) Name ¶
func (t *AskUserQuestion) Name() string
func (*AskUserQuestion) ParameterSchema ¶
func (t *AskUserQuestion) ParameterSchema() string
ParameterSchema returns the JSON Schema for AskUserQuestion tool parameters.
func (*AskUserQuestion) RiskLevel ¶
func (t *AskUserQuestion) RiskLevel() types.RiskLevel
type Bash ¶
type Bash struct {
// contains filtered or unexported fields
}
func (*Bash) Description ¶
func (*Bash) ParameterSchema ¶
ParameterSchema returns the JSON Schema for Bash tool parameters.
type CodeComplexity ¶ added in v1.1.0
type CodeComplexity struct {
// contains filtered or unexported fields
}
CodeComplexity is a tool that analyzes the M31A Go codebase and returns a complexity report with file counts, line counts, top packages, top files, and a complexity score.
func NewCodeComplexity ¶ added in v1.1.0
func NewCodeComplexity(workDir string, skipDirs []string) *CodeComplexity
NewCodeComplexity creates a new CodeComplexity tool. skipDirs is an optional override; if nil, types.SkipDirs is used.
func (*CodeComplexity) Description ¶ added in v1.1.0
func (t *CodeComplexity) Description() string
func (*CodeComplexity) Execute ¶ added in v1.1.0
func (t *CodeComplexity) Execute(ctx context.Context, input types.ToolInput) (types.ToolResult, error)
func (*CodeComplexity) Name ¶ added in v1.1.0
func (t *CodeComplexity) Name() string
func (*CodeComplexity) ParameterSchema ¶ added in v1.1.0
func (t *CodeComplexity) ParameterSchema() string
func (*CodeComplexity) RiskLevel ¶ added in v1.1.0
func (t *CodeComplexity) RiskLevel() types.RiskLevel
type CodeMap ¶
type CodeMap struct {
// contains filtered or unexported fields
}
CodeMap is a tool that queries the codebase intelligence layer for import graph, symbol definitions, and relevant file discovery.
func NewCodeMap ¶
func (*CodeMap) Description ¶
func (*CodeMap) ParameterSchema ¶
type ComplexityReport ¶ added in v1.1.0
type ComplexityReport struct {
TotalFiles int
TotalLines int
Packages []PackageStat
Files []FileStat
Score string
}
ComplexityReport holds the results of a codebase complexity analysis.
type DevServer ¶ added in v1.3.0
type DevServer struct {
// contains filtered or unexported fields
}
func NewDevServer ¶ added in v1.3.0
func (*DevServer) Description ¶ added in v1.3.0
func (*DevServer) ParameterSchema ¶ added in v1.3.0
type Dispatcher ¶
type Dispatcher struct {
// contains filtered or unexported fields
}
func DefaultDispatcher ¶
func DefaultDispatcher(workDir, backupDir, sessionsDir string, cfg *config.PermissionsConfig) (*Dispatcher, error)
func NewDispatcher ¶
func NewDispatcher(cfg *config.PermissionsConfig) *Dispatcher
NewDispatcher creates a new Dispatcher with a background rate-limiter goroutine. The caller MUST call Stop() when the Dispatcher is no longer needed to prevent goroutine leaks (e.g., during session restart or app shutdown).
func (*Dispatcher) ApprovePermission ¶
func (d *Dispatcher) ApprovePermission(requestID int64, allowed bool, remember bool)
func (*Dispatcher) Execute ¶
func (d *Dispatcher) Execute(ctx context.Context, call types.ToolCall) (types.ToolResult, error)
func (*Dispatcher) List ¶
func (d *Dispatcher) List() []string
func (*Dispatcher) QuestionRequestCh ¶
func (d *Dispatcher) QuestionRequestCh() chan QuestionRequest
func (*Dispatcher) QuestionResponseCh ¶
func (d *Dispatcher) QuestionResponseCh() chan QuestionResponse
func (*Dispatcher) RequestCh ¶
func (d *Dispatcher) RequestCh() chan PermissionRequest
func (*Dispatcher) RespondQuestion ¶
func (d *Dispatcher) RespondQuestion(requestID int64, answer string)
RespondQuestion routes a question response to the per-request channel for the given request ID. Falls back to the shared channel if no per-request channel exists. This prevents cross-caller response routing (H-2).
func (*Dispatcher) SelectAgent ¶
func (d *Dispatcher) SelectAgent(agent string) error
func (*Dispatcher) SetOutputStore ¶ added in v1.3.0
func (d *Dispatcher) SetOutputStore(store *OutputStore)
SetOutputStore configures the output store for bounding tool output.
func (*Dispatcher) SetPermission ¶
func (d *Dispatcher) SetPermission(toolName string, allowed bool)
func (*Dispatcher) SetSessionID ¶
func (d *Dispatcher) SetSessionID(id string)
func (*Dispatcher) SetTodoWriteCallback ¶ added in v1.1.0
func (d *Dispatcher) SetTodoWriteCallback(fn func(items []TodoItem))
SetTodoWriteCallback sets the callback invoked after successful TodoWrite tool executions.
func (*Dispatcher) Stop ¶
func (d *Dispatcher) Stop()
Stop shuts down the rate limiter goroutine and ticker. Should be called when the Dispatcher is no longer needed (e.g., during app shutdown). C-12: Uses sync.Once to prevent TOCTOU race on concurrent calls.
func (*Dispatcher) Unregister ¶ added in v1.3.0
func (d *Dispatcher) Unregister(name string)
Unregister removes a tool by name. Used by profile-based filtering to strip tools that a subagent profile should not access.
func (*Dispatcher) UpdatePermissions ¶
func (d *Dispatcher) UpdatePermissions(cfg *config.PermissionsConfig)
UpdatePermissions hot-reloads the permission configuration.
type Edit ¶
type Edit struct {
// contains filtered or unexported fields
}
func (*Edit) Description ¶
func (*Edit) ParameterSchema ¶
ParameterSchema returns the JSON Schema for Edit tool parameters.
type FileDelete ¶
type FileDelete struct {
// contains filtered or unexported fields
}
func NewFileDelete ¶
func NewFileDelete(workDir, backupDir string) *FileDelete
func (*FileDelete) Description ¶
func (t *FileDelete) Description() string
func (*FileDelete) Execute ¶
func (t *FileDelete) Execute(ctx context.Context, input types.ToolInput) (types.ToolResult, error)
func (*FileDelete) Name ¶
func (t *FileDelete) Name() string
func (*FileDelete) ParameterSchema ¶
func (t *FileDelete) ParameterSchema() string
func (*FileDelete) RiskLevel ¶
func (t *FileDelete) RiskLevel() types.RiskLevel
type FileList ¶
type FileList struct {
// contains filtered or unexported fields
}
func NewFileList ¶
func (*FileList) Description ¶
func (*FileList) ParameterSchema ¶
type FileMove ¶
type FileMove struct {
// contains filtered or unexported fields
}
func NewFileMove ¶
func (*FileMove) Description ¶
func (*FileMove) ParameterSchema ¶
type FileRead ¶
type FileRead struct {
// contains filtered or unexported fields
}
func NewFileRead ¶
func (*FileRead) Description ¶
func (*FileRead) ParameterSchema ¶
ParameterSchema returns the JSON Schema for FileRead tool parameters.
type FileWrite ¶
type FileWrite struct {
// contains filtered or unexported fields
}
func NewFileWrite ¶
func (*FileWrite) Description ¶
func (*FileWrite) ParameterSchema ¶
ParameterSchema returns the JSON Schema for FileWrite tool parameters.
type Glob ¶
type Glob struct {
// contains filtered or unexported fields
}
func (*Glob) Description ¶
func (*Glob) ParameterSchema ¶
ParameterSchema returns the JSON Schema for Glob tool parameters.
type Grep ¶
type Grep struct {
// contains filtered or unexported fields
}
func (*Grep) Description ¶
func (*Grep) ParameterSchema ¶
ParameterSchema returns the JSON Schema for Grep tool parameters.
type HTTPCheck ¶ added in v1.3.0
type HTTPCheck struct {
// contains filtered or unexported fields
}
func NewHTTPCheck ¶ added in v1.3.0
func NewHTTPCheck() *HTTPCheck
func (*HTTPCheck) Description ¶ added in v1.3.0
func (*HTTPCheck) ParameterSchema ¶ added in v1.3.0
type MetricsTool ¶ added in v1.2.0
type MetricsTool struct {
// contains filtered or unexported fields
}
MetricsTool provides query access to session observability metrics. It supports four modes: summary, tool-stats, phase-stats, cost-report.
func NewMetricsTool ¶ added in v1.2.0
func NewMetricsTool(collector *metrics.Collector) *MetricsTool
NewMetricsTool creates a MetricsTool backed by the given collector.
func (*MetricsTool) Description ¶ added in v1.2.0
func (t *MetricsTool) Description() string
func (*MetricsTool) Execute ¶ added in v1.2.0
func (t *MetricsTool) Execute(ctx context.Context, input types.ToolInput) (types.ToolResult, error)
func (*MetricsTool) Name ¶ added in v1.2.0
func (t *MetricsTool) Name() string
func (*MetricsTool) ParameterSchema ¶ added in v1.2.0
func (t *MetricsTool) ParameterSchema() string
ParameterSchema returns the JSON Schema for Metrics tool parameters.
func (*MetricsTool) RiskLevel ¶ added in v1.2.0
func (t *MetricsTool) RiskLevel() types.RiskLevel
type OutputStore ¶ added in v1.3.0
type OutputStore struct {
// contains filtered or unexported fields
}
OutputStore bounds tool output to prevent single tool calls from consuming the entire context window. When output exceeds configured limits, the full output is saved to a managed directory and a head+tail preview is returned.
func NewOutputStore ¶ added in v1.3.0
func NewOutputStore(baseDir string, maxLines, maxBytes int) *OutputStore
NewOutputStore creates an OutputStore with the given limits. baseDir is the directory where truncated outputs are saved (e.g., ~/.m31a/tool-output/).
func (*OutputStore) Bound ¶ added in v1.3.0
func (s *OutputStore) Bound(output string) (string, string, bool)
Bound checks if the output exceeds configured limits. If so, it saves the full output to a file and returns a head+tail preview with a truncation marker. Returns (boundedOutput, savedPath, wasTruncated).
type PackageStat ¶ added in v1.1.0
PackageStat holds aggregate stats for a single package (directory).
type PermissionContext ¶
type PermissionContext struct {
RuleTool string // Tool name from the matched rule
RulePattern string // Pattern from the matched rule
RuleAction string // The action that triggered (allow/deny/ask)
Source string // Source of the decision: "rule", "agent_default", or "risk_level"
}
PermissionContext carries additional info about a matched rule for display in the permission modal.
type PermissionRequest ¶
type PermissionRequest struct {
ID int64 `json:"id"`
ToolName string `json:"tool_name"`
Command string `json:"command"`
RiskLevel types.RiskLevel `json:"risk_level"`
TimeoutSecs int `json:"timeout_secs"`
// Rule context (populated when a permission rule matched)
RuleTool string `json:"rule_tool,omitempty"`
RulePattern string `json:"rule_pattern,omitempty"`
RuleAction string `json:"rule_action,omitempty"`
}
type PermissionResponse ¶
type PersistentPermissions ¶ added in v1.3.0
type PersistentPermissions struct {
// contains filtered or unexported fields
}
PersistentPermissions manages saved permission rules that survive across sessions. Rules are scoped by project directory and stored in ~/.m31a/permissions.json.
func NewPersistentPermissions ¶ added in v1.3.0
func NewPersistentPermissions() *PersistentPermissions
NewPersistentPermissions creates a PersistentPermissions instance that reads/writes to ~/.m31a/permissions.json.
func (*PersistentPermissions) Load ¶ added in v1.3.0
func (p *PersistentPermissions) Load(projectDir string) []config.PermissionRule
Load reads persistent permission rules for the given project directory.
func (*PersistentPermissions) Remove ¶ added in v1.3.0
func (p *PersistentPermissions) Remove(projectDir string) error
Remove clears all persistent rules for the given project directory.
func (*PersistentPermissions) Save ¶ added in v1.3.0
func (p *PersistentPermissions) Save(projectDir string, rule config.PermissionRule) error
Save adds a permission rule for the given project directory and persists it.
type QuestionRequest ¶
type QuestionRequest struct {
ID int64
Question string
Header string
Options []string
AllowCustom bool
TimeoutSecs int
}
QuestionRequest represents a question sent from the tool to the TUI.
type QuestionResponse ¶
type QuestionResponse struct {
Answer string
}
QuestionResponse represents the user's answer from the TUI.
type TodoWrite ¶
type TodoWrite struct {
// contains filtered or unexported fields
}
func NewTodoWrite ¶
func (*TodoWrite) Description ¶
func (*TodoWrite) ParameterSchema ¶
ParameterSchema returns the JSON Schema for TodoWrite tool parameters.
func (*TodoWrite) SetOnUpdate ¶ added in v1.1.0
SetOnUpdate sets the callback invoked after successful todo writes.
func (*TodoWrite) SetSessionID ¶
type WebFetch ¶
type WebFetch struct {
// contains filtered or unexported fields
}
func NewWebFetch ¶
func (*WebFetch) Close ¶ added in v1.1.0
func (wf *WebFetch) Close()
Close releases idle connections held by the HTTP client's transport. Call this during shutdown to prevent connection leaks.
func (*WebFetch) Description ¶
func (*WebFetch) ParameterSchema ¶
ParameterSchema returns the JSON Schema for WebFetch tool parameters.
type WebSearch ¶
type WebSearch struct {
// contains filtered or unexported fields
}
func NewWebSearch ¶
func (*WebSearch) Close ¶ added in v1.0.2
func (t *WebSearch) Close()
Close releases idle connections held by the HTTP client's transport. Call this during shutdown to prevent connection leaks.
func (*WebSearch) Description ¶
func (*WebSearch) ParameterSchema ¶
Source Files
¶
- agent.go
- backup.go
- bash.go
- bash_unix.go
- codecomplexity.go
- codemap.go
- constants.go
- defaults.go
- devserver.go
- dispatcher.go
- edit.go
- filedelete.go
- filelist.go
- filemove.go
- fileread.go
- filewrite.go
- glob.go
- grep.go
- httpcheck.go
- interface.go
- metrics.go
- output_store.go
- permissions.go
- persistent_permissions.go
- prockill_unix.go
- question.go
- todo.go
- tooldefs.go
- webfetch.go
- websearch.go