Documentation
¶
Overview ¶
Package coder 提供从 opencode 迁移的编码类工具(bash / edit / view / write / patch / glob / grep / ls / fetch / sourcegraph / diagnostics)。
迁移约定:
- 全部实现 gobrave 的 tool.Tool(Definition + Execute),可直接注册进 tool.Registry;
- 工具的依赖(文件历史 / LSP 客户端 / 工作目录 / 会话 ID)在执行期从 ctx 读取, 因此工具本身无状态,可在注册表里单例复用;
- 权限请求与 opencode internal/llm/tools 对齐:工具在真正读写 / 执行前自行调用 tool.RequirePermission,由 ctx 中的 PermissionRequester 桥接到 Runtime。
Index ¶
- Constants
- func All(deps Deps) []tool.Tool
- func NewBash(deps Deps) tool.Tool
- func NewDiagnostics(deps Deps) tool.Tool
- func NewEdit(deps Deps) tool.Tool
- func NewFetch(deps Deps) tool.Tool
- func NewGlob() tool.Tool
- func NewGrep() tool.Tool
- func NewLs() tool.Tool
- func NewPatch(deps Deps) tool.Tool
- func NewSourcegraph() tool.Tool
- func NewView(deps Deps) tool.Tool
- func NewWrite(deps Deps) tool.Tool
- type BashOutput
- type BashParams
- type BashPermissionsParams
- type Deps
- type DiagnosticsParams
- type EditParams
- type EditPermissionsParams
- type EditResponseMetadata
- type FetchParams
- type FileReadStatus
- type GlobParams
- type GlobResponseMetadata
- type GrepParams
- type GrepResponseMetadata
- type LSPClientProvider
- type LSParams
- type LSResponseMetadata
- type LineScanner
- type PatchParams
- type PatchResponseMetadata
- type SourcegraphParams
- type SourcegraphResponseMetadata
- type ToolResponse
- type TreeNode
- type ViewParams
- type WriteParams
- type WritePermissionsParams
- type WriteResponseMetadata
Constants ¶
const ( BashToolName = "bash" DefaultTimeout = 1 * 60 * 1000 // 1 minute in milliseconds MaxTimeout = 10 * 60 * 1000 // 10 minutes in milliseconds MaxOutputLength = 30000 )
const ( LSToolName = "ls" MaxLSFiles = 1000 )
const ( ViewToolName = "view" MaxReadSize = 250 * 1024 DefaultReadLimit = 2000 MaxLineLength = 2000 )
const (
DiagnosticsToolName = "diagnostics"
)
const (
EditToolName = "edit"
)
const (
FetchToolName = "fetch"
)
const (
GlobToolName = "glob"
)
const (
GrepToolName = "grep"
)
const (
PatchToolName = "patch"
)
const (
SourcegraphToolName = "sourcegraph"
)
const (
WriteToolName = "write"
)
Variables ¶
This section is empty.
Functions ¶
func All ¶
All 返回全部 coder 工具。新增工具时在此追加即可自动接入各 Provider。 All 返回全部 coder 工具。静态依赖(文件历史 / LSP)由 container 在构建期注入。
func NewBash ¶
NewBash 返回 bash 工具(持久 shell 会话中执行命令)。
实际执行位置由 container.bash_execution_mode 决定:host(默认)走宿主机持久 shell, container 走用户的容器模板终端(container.bash_container_template_id)。Agent 对此 无感知:工具入参与返回结构完全一致,不需要传入任何容器相关信息。
func NewDiagnostics ¶
NewDiagnostics 返回 diagnostics 工具(读取 LSP 诊断结果)。
Types ¶
type BashOutput ¶
type BashOutput struct {
Output string `json:"output"`
Metadata struct {
StartTime int64 `json:"start_time"`
EndTime int64 `json:"end_time"`
} `json:"metadata"`
}
BashOutput 是 bash 工具的结果(回传给模型)。
type BashParams ¶
BashParams 是 bash 工具的入参。
type BashPermissionsParams ¶
BashPermissionsParams 是 bash 工具授权请求携带的参数(对齐 opencode)。
type Deps ¶
type Deps struct {
// History 是会话内文件版本历史服务(edit / write / patch 记录版本)。
History agentinterfaces.HistoryService
// LSP 是 LSP 客户端提供者(diagnostics / view / edit / write / patch 读取诊断)。
//
// 以「提供者」而不是客户端 map 注入:Clients() 在每次执行时取当前快照,
// 避免工具在构造期就把客户端集合固化下来。
LSP LSPClientProvider
// Config 是进程配置快照,供需要出站网络的工具(如 fetch)读取代理设置。
// 为 nil 或未配置代理时直连(不读取环境变量)。
Config *config.Config
// ContainerShell 是容器终端的最小服务(bash 在 container 模式下使用)。
//
// 为 nil 时 bash 一律在宿主机执行:仓库级单元测试等没有容器运行时的场景
// 不必装配它。bash 用哪种执行位置由 container.bash_execution_mode 决定。
ContainerShell hostshell.ContainerShellService
}
Deps 是 coder 工具集的进程级静态依赖,由 container 在构建工具注册表时一次性装配。
与 builtin.Deps 一样,这些依赖通过构造函数注入,而不是每次执行时从 context 读取: 工具依赖对编译器可见、可单测,provider 侧也无需维护逐能力的注入清单。
type DiagnosticsParams ¶
type DiagnosticsParams struct {
FilePath string `json:"file_path"`
}
DiagnosticsParams 是 diagnostics 工具的入参。
type EditParams ¶
type EditPermissionsParams ¶
type EditResponseMetadata ¶
type FetchParams ¶
type FileReadStatus ¶
type FileReadStatus struct {
// Read 表示本进程内是否读取过该文件(进程重启后为 false)。
Read bool
// Modified 表示读取之后文件内容被外部改动过。
Modified bool
// LastRead 是最后一次读取时间(未读过时为零值)。
LastRead time.Time
// ModTime 是文件当前的修改时间(mtime 可能因 NFS 服务端时钟而超前)。
ModTime time.Time
// Detail 是判定细节,便于日志 / 排障。
Detail string
}
FileReadStatus 描述文件相对"最后一次读取"的状态。
func CheckFileRead ¶
func CheckFileRead(path string, info os.FileInfo) FileReadStatus
CheckFileRead 判断 path 是否已读过且读后未被改动。
info 为调用方已有的 os.FileInfo,可为 nil(内部自行 Stat)。 判定优先使用内容快照(size + sha256),因此不受 NFS mtime 时钟偏差影响; 快照不可用(文件过大 / 读取失败)时退化为 size + 带容忍窗口的 mtime 比较。
type GlobParams ¶
type GlobResponseMetadata ¶
type GrepParams ¶
type GrepResponseMetadata ¶
type LSPClientProvider ¶
LSPClientProvider 抽象「提供当前 LSP 客户端集合」的能力。
*lspmanager.Manager 直接满足该接口,避免 coder 包依赖 manager 的具体类型。
type LSResponseMetadata ¶
type LineScanner ¶
type LineScanner struct {
// contains filtered or unexported fields
}
func NewLineScanner ¶
func NewLineScanner(r io.Reader) *LineScanner
func (*LineScanner) Err ¶
func (s *LineScanner) Err() error
func (*LineScanner) Scan ¶
func (s *LineScanner) Scan() bool
func (*LineScanner) Text ¶
func (s *LineScanner) Text() string
type PatchParams ¶
type PatchParams struct {
PatchText string `json:"patch_text"`
}
type PatchResponseMetadata ¶
type SourcegraphParams ¶
type ToolResponse ¶
type ToolResponse struct {
// Content 回传给模型的文本。
Content string
// IsError 表示这次调用失败(模型可据此纠正)。
IsError bool
}
ToolResponse 是工具内部产生的文本结果。
func NewTextErrorResponse ¶
func NewTextErrorResponse(content string) ToolResponse
NewTextErrorResponse 构造失败结果。
func WithResponseMetadata ¶
func WithResponseMetadata(response ToolResponse, _ any) ToolResponse
WithResponseMetadata 兼容 opencode 的调用形式;元信息不参与模型回传,直接忽略。
type ViewParams ¶
type ViewParams struct {
FilePath string `json:"file_path"`
Offset int `json:"offset"`
Limit int `json:"limit"`
}
ViewParams 是 view 工具的入参。