Documentation
¶
Index ¶
- Variables
- func CommandExec(ctx context.Context, args map[string]any) (any, error)
- func FileEdit(ctx context.Context, args map[string]any) (any, error)
- func FileList(ctx context.Context, args map[string]any) (any, error)
- func FileRead(ctx context.Context, args map[string]any) (any, error)
- func FileSearch(ctx context.Context, args map[string]any) (any, error)
- func FileWrite(ctx context.Context, args map[string]any) (any, error)
- func GetWorkDir() string
- func GetWorkDirTool(ctx context.Context, args map[string]any) (any, error)
- func RegisterAll(registry *ToolRegistry) []string
- func RegisterAllWithBrowser(registry *ToolRegistry) []string
- func RegisterCommandTools(registry *ToolRegistry)
- func RegisterEnvTools(registry *ToolRegistry)
- func RegisterFileEditTools(registry *ToolRegistry)
- func RegisterFileTools(registry *ToolRegistry)
- func RegisterUserConfigTools(registry *ToolRegistry)
- func RegisterWebTools(registry *ToolRegistry)
- func UserConfig(ctx context.Context, args map[string]any) (any, error)
- func WebBrowse(ctx context.Context, args map[string]any) (any, error)
- func WebFetch(ctx context.Context, args map[string]any) (any, error)
- type ChromiumManager
- type Config
- type HookID
- type PromptLoader
- func (pl *PromptLoader) LoadAGENTS() (string, error)
- func (pl *PromptLoader) LoadAll() (string, []string, error)
- func (pl *PromptLoader) LoadByName(name string) (string, error)
- func (pl *PromptLoader) LoadCLAUDE() (string, error)
- func (pl *PromptLoader) LoadCursorRules() (string, error)
- func (pl *PromptLoader) LoadFile(filename string) (string, error)
- func (pl *PromptLoader) LoadWithDefaults() (string, []string, error)
- func (pl *PromptLoader) ReplaceVariables(content string, vars map[string]string) string
- type RegisteredTool
- type ToolHandler
- type ToolMetadata
- type ToolOption
- func WithAuthor(author string) ToolOption
- func WithCategory(cat string) ToolOption
- func WithParameters(params map[string]any) ToolOption
- func WithPermission(perm ToolPermission) ToolOption
- func WithTags(tags ...string) ToolOption
- func WithTimeout(timeout time.Duration) ToolOption
- func WithVersion(version string) ToolOption
- type ToolPermission
- type ToolRegistry
- func (r *ToolRegistry) AddAfterExecuteHook(hook func(ctx context.Context, toolName string, result schema.ToolResult, ...)) HookID
- func (r *ToolRegistry) AddBeforeExecuteHook(hook func(ctx context.Context, toolName string, args map[string]any) error) HookID
- func (r *ToolRegistry) AddOnRegisterHook(hook func(tool *RegisteredTool)) HookID
- func (r *ToolRegistry) AddOnUnregisterHook(hook func(toolName string)) HookID
- func (r *ToolRegistry) Disable(toolName string) error
- func (r *ToolRegistry) Enable(toolName string) error
- func (r *ToolRegistry) Execute(ctx context.Context, call schema.ToolCall) schema.ToolResult
- func (r *ToolRegistry) ExecuteBatch(ctx context.Context, calls []schema.ToolCall) []schema.ToolResult
- func (r *ToolRegistry) Get(toolName string) (*RegisteredTool, bool)
- func (r *ToolRegistry) GetAllTools() []*RegisteredTool
- func (r *ToolRegistry) GetByCategory(category string) []*RegisteredTool
- func (r *ToolRegistry) GetByPermission(perm ToolPermission) []*RegisteredTool
- func (r *ToolRegistry) GetByTag(tag string) []*RegisteredTool
- func (r *ToolRegistry) GetEnabledTools() []schema.Tool
- func (r *ToolRegistry) MustRegister(meta ToolMetadata, handler ToolHandler)
- func (r *ToolRegistry) Register(meta ToolMetadata, handler ToolHandler) error
- func (r *ToolRegistry) RegisterSimple(name, description string, handler ToolHandler, opts ...ToolOption) error
- func (r *ToolRegistry) RemoveAfterExecuteHook(id HookID)
- func (r *ToolRegistry) RemoveBeforeExecuteHook(id HookID)
- func (r *ToolRegistry) RemoveOnRegisterHook(id HookID)
- func (r *ToolRegistry) RemoveOnUnregisterHook(id HookID)
- func (r *ToolRegistry) ToToolMessages(results []schema.ToolResult) []*schema.Message
- func (r *ToolRegistry) Unregister(toolName string) error
- func (r *ToolRegistry) Update(toolName string, meta ToolMetadata, handler ToolHandler) error
Constants ¶
This section is empty.
Variables ¶
var ChromiumDataDir = "./data/chromium-browser"
ChromiumDataDir 下载的 Chromium 存放目录,可在 init 时修改
var (
ConfigDBPath = "./user_config.db" // 可在 init 时修改
)
Functions ¶
func CommandExec ¶ added in v1.1.0
func FileSearch ¶ added in v1.1.0
func GetWorkDirTool ¶
GetWorkDirTool 工具:返回当前工作目录
func RegisterAll ¶ added in v1.1.0
func RegisterAll(registry *ToolRegistry) []string
RegisterAll 一键注册所有内置工具 自动检测环境,跳过不可用的工具
func RegisterAllWithBrowser ¶ added in v1.1.0
func RegisterAllWithBrowser(registry *ToolRegistry) []string
RegisterAllWithBrowser 强制注册所有工具(包括浏览器工具) 即使 Chrome 不可用也注册,首次使用时会自动下载
func RegisterCommandTools ¶ added in v1.1.0
func RegisterCommandTools(registry *ToolRegistry)
func RegisterFileEditTools ¶ added in v1.1.0
func RegisterFileEditTools(registry *ToolRegistry)
func RegisterFileTools ¶ added in v1.1.0
func RegisterFileTools(registry *ToolRegistry)
func RegisterUserConfigTools ¶
func RegisterUserConfigTools(registry *ToolRegistry)
func RegisterWebTools ¶
func RegisterWebTools(registry *ToolRegistry)
Types ¶
type ChromiumManager ¶
type ChromiumManager struct {
// contains filtered or unexported fields
}
ChromiumManager 管理 Chrome/Chromium 二进制文件 查找优先级:系统已安装 > 已缓存下载 > 自动下载(需校验)
func NewChromiumManager ¶
func NewChromiumManager(dataDir string) *ChromiumManager
func (*ChromiumManager) ChromePath ¶
func (m *ChromiumManager) ChromePath() (string, error)
ChromePath 获取可用的 Chrome/Chromium 可执行文件路径
type Config ¶
type PromptLoader ¶
type PromptLoader struct {
// contains filtered or unexported fields
}
PromptLoader 通用 Markdown 配置加载器 支持从目录加载任意 .md 文件,以及业界标准的 AGENTS.md
func NewPromptLoader ¶
func NewPromptLoader(configDir string) *PromptLoader
func (*PromptLoader) LoadAGENTS ¶ added in v1.1.0
func (pl *PromptLoader) LoadAGENTS() (string, error)
LoadAGENTS 加载 AGENTS.md(业界标准的 Agent 指令文件) 搜索顺序:configDir/AGENTS.md
func (*PromptLoader) LoadAll ¶ added in v1.1.0
func (pl *PromptLoader) LoadAll() (string, []string, error)
LoadAll 加载所有可用的指令文件,合并为一个 prompt 搜索优先级:AGENTS.md > CLAUDE.md > .cursor/rules/ 返回合并后的内容和实际加载到的文件名列表
func (*PromptLoader) LoadByName ¶ added in v1.1.0
func (pl *PromptLoader) LoadByName(name string) (string, error)
LoadByName 按名称加载(自动加 .md 后缀)
func (*PromptLoader) LoadCLAUDE ¶ added in v1.1.0
func (pl *PromptLoader) LoadCLAUDE() (string, error)
LoadCLAUDE 加载 CLAUDE.md(Claude Code 标准指令文件)
func (*PromptLoader) LoadCursorRules ¶ added in v1.1.0
func (pl *PromptLoader) LoadCursorRules() (string, error)
LoadCursorRules 加载 .cursor/rules/ 目录下的规则文件
func (*PromptLoader) LoadFile ¶ added in v1.1.0
func (pl *PromptLoader) LoadFile(filename string) (string, error)
LoadFile 加载指定文件名的内容
func (*PromptLoader) LoadWithDefaults ¶ added in v1.1.0
func (pl *PromptLoader) LoadWithDefaults() (string, []string, error)
LoadWithDefaults 加载所有可用指令文件,附加工作目录变量替换
func (*PromptLoader) ReplaceVariables ¶
func (pl *PromptLoader) ReplaceVariables(content string, vars map[string]string) string
ReplaceVariables 替换模板变量(如 {{work_dir}})
type RegisteredTool ¶
type RegisteredTool struct {
Metadata ToolMetadata
Handler ToolHandler
RegisteredAt time.Time
UpdatedAt time.Time
UseCount int64
}
RegisteredTool 注册后的工具
type ToolHandler ¶
ToolHandler 工具执行函数签名
type ToolMetadata ¶
type ToolMetadata struct {
Name string `json:"name"`
Description string `json:"description"`
Parameters any `json:"parameters"`
Permission ToolPermission `json:"permission"`
Category string `json:"category"`
Version string `json:"version"`
Author string `json:"author"`
Tags []string `json:"tags"`
Requires []string `json:"requires,omitempty"`
Timeout time.Duration `json:"timeout"`
Enabled bool `json:"enabled"`
Config map[string]any `json:"config,omitempty"`
}
ToolMetadata 工具元数据
type ToolPermission ¶
type ToolPermission int
ToolPermission 工具权限级别
const ( // PermReadOnly 只读权限(安全,无副作用) PermReadOnly ToolPermission = iota // PermReadWrite 读写权限(可能修改状态) PermReadWrite // PermDangerous 危险权限(可能破坏数据/系统) PermDangerous )
func (ToolPermission) String ¶
func (p ToolPermission) String() string
type ToolRegistry ¶
type ToolRegistry struct {
// contains filtered or unexported fields
}
ToolRegistry 动态工具注册中心
func (*ToolRegistry) AddAfterExecuteHook ¶
func (r *ToolRegistry) AddAfterExecuteHook(hook func(ctx context.Context, toolName string, result schema.ToolResult, duration time.Duration)) HookID
AddAfterExecuteHook 注册 afterExecute 钩子,返回 ID
func (*ToolRegistry) AddBeforeExecuteHook ¶
func (r *ToolRegistry) AddBeforeExecuteHook(hook func(ctx context.Context, toolName string, args map[string]any) error) HookID
AddBeforeExecuteHook 注册 beforeExecute 钩子,返回 ID
func (*ToolRegistry) AddOnRegisterHook ¶
func (r *ToolRegistry) AddOnRegisterHook(hook func(tool *RegisteredTool)) HookID
AddOnRegisterHook 注册 onRegister 钩子,返回 ID
func (*ToolRegistry) AddOnUnregisterHook ¶
func (r *ToolRegistry) AddOnUnregisterHook(hook func(toolName string)) HookID
AddOnUnregisterHook 注册 onUnregister 钩子,返回 ID
func (*ToolRegistry) Execute ¶
func (r *ToolRegistry) Execute(ctx context.Context, call schema.ToolCall) schema.ToolResult
Execute 执行工具(带生命周期钩子)
func (*ToolRegistry) ExecuteBatch ¶
func (r *ToolRegistry) ExecuteBatch(ctx context.Context, calls []schema.ToolCall) []schema.ToolResult
ExecuteBatch 批量执行 ExecuteBatch 并行执行多个工具调用(带并发限制)
func (*ToolRegistry) Get ¶
func (r *ToolRegistry) Get(toolName string) (*RegisteredTool, bool)
Get 获取工具
func (*ToolRegistry) GetAllTools ¶
func (r *ToolRegistry) GetAllTools() []*RegisteredTool
GetAllTools 获取所有工具
func (*ToolRegistry) GetByCategory ¶
func (r *ToolRegistry) GetByCategory(category string) []*RegisteredTool
GetByCategory 按分类获取
func (*ToolRegistry) GetByPermission ¶
func (r *ToolRegistry) GetByPermission(perm ToolPermission) []*RegisteredTool
GetByPermission 按权限级别获取
func (*ToolRegistry) GetByTag ¶
func (r *ToolRegistry) GetByTag(tag string) []*RegisteredTool
GetByTag 按标签搜索
func (*ToolRegistry) GetEnabledTools ¶
func (r *ToolRegistry) GetEnabledTools() []schema.Tool
GetEnabledTools 获取所有启用的工具 Schema(发给模型用)
func (*ToolRegistry) MustRegister ¶
func (r *ToolRegistry) MustRegister(meta ToolMetadata, handler ToolHandler)
MustRegister 注册工具,失败 panic
func (*ToolRegistry) Register ¶
func (r *ToolRegistry) Register(meta ToolMetadata, handler ToolHandler) error
Register 动态注册工具
func (*ToolRegistry) RegisterSimple ¶ added in v1.1.0
func (r *ToolRegistry) RegisterSimple(name, description string, handler ToolHandler, opts ...ToolOption) error
RegisterSimple 简化注册:只需 name、description、handler,其余用默认值 默认:PermReadOnly、category="dynamic"、timeout=30s
func (*ToolRegistry) RemoveAfterExecuteHook ¶
func (r *ToolRegistry) RemoveAfterExecuteHook(id HookID)
RemoveAfterExecuteHook 移除 afterExecute 钩子
func (*ToolRegistry) RemoveBeforeExecuteHook ¶
func (r *ToolRegistry) RemoveBeforeExecuteHook(id HookID)
RemoveBeforeExecuteHook 移除 beforeExecute 钩子
func (*ToolRegistry) RemoveOnRegisterHook ¶
func (r *ToolRegistry) RemoveOnRegisterHook(id HookID)
RemoveOnRegisterHook 移除 onRegister 钩子
func (*ToolRegistry) RemoveOnUnregisterHook ¶
func (r *ToolRegistry) RemoveOnUnregisterHook(id HookID)
RemoveOnUnregisterHook 移除 onUnregister 钩子
func (*ToolRegistry) ToToolMessages ¶
func (r *ToolRegistry) ToToolMessages(results []schema.ToolResult) []*schema.Message
ToToolMessages 将 ToolResult 转成 Message
func (*ToolRegistry) Unregister ¶
func (r *ToolRegistry) Unregister(toolName string) error
Unregister 注销工具
func (*ToolRegistry) Update ¶
func (r *ToolRegistry) Update(toolName string, meta ToolMetadata, handler ToolHandler) error
Update 更新工具