Help us shape the future of Go! Take the 2026 Go Developer Survey

tools

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 32 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidPatch 表示 apply_patch 输入不是受支持的 Begin/Add/Update/Delete/End patch 格式。
	ErrInvalidPatch = errors.New("invalid local workspace patch")
	// ErrPatchRejected 表示补丁格式有效,但目标状态、文件大小或完整行上下文不符合要求。
	ErrPatchRejected = errors.New("local workspace patch rejected")
)
View Source
var ErrUnsupportedFile = errors.New("read_file only reads regular UTF-8 text files or PNG/JPEG/GIF/WebP images; use bash to inspect other files")

ErrUnsupportedFile 表示 read_file 目标不是普通文件,或读取范围内的内容不是 UTF-8 文本或受支持的图片。

Functions

func GetCommandToolNames

func GetCommandToolNames() []string

GetCommandToolNames 返回五个命令工具的名称。

func NewApplyPatchTool

func NewApplyPatchTool(opt *ApplyPatchToolOpt) (executor.Tool, error)

NewApplyPatchTool 创建工作区中的补丁工具。

func NewCommandTools

func NewCommandTools(opt *CommandToolsOpt) ([]executor.Tool, error)

NewCommandTools 创建绑定同一环境和命令集合的五个命令工具。

func NewReadFileTool

func NewReadFileTool(opt *ReadFileToolOpt) (executor.Tool, error)

NewReadFileTool 校验配置并创建文件读取工具。

Types

type ApplyPatchToolOpt

type ApplyPatchToolOpt struct {
	// Workspace 是应用补丁的工作区;补丁路径以它的根目录为基准,只能修改工作区内的文件。
	Workspace workspace.Workspace
}

ApplyPatchToolOpt 保存补丁工具使用的工作区。

func NewApplyPatchToolOpt

func NewApplyPatchToolOpt(toolWorkspace workspace.Workspace) *ApplyPatchToolOpt

NewApplyPatchToolOpt 保存应用补丁的工作区。

type CommandResult

type CommandResult struct {
	CommandID string `json:"command_id"`
	Status    string `json:"status"`
	// ExitCode 只有 exited 有;被信号终止(含停止)时为 -1。
	ExitCode   *int   `json:"exit_code"`
	StopReason string `json:"stop_reason,omitempty"`
	// Error 是 failed 的原因,其他状态为空。
	Error      string `json:"error,omitempty"`
	Output     string `json:"output"`
	NextCursor uint64 `json:"next_cursor"`
	HasMore    bool   `json:"has_more"`
	Truncated  bool   `json:"truncated,omitempty"`
}

CommandResult 是 bash、read_command_output 结果的 content:命令当时的状态,和从 cursor 起的一页输出。 界面用 ParseCommandResult 从工具结果里取出它。

func ParseCommandResult

func ParseCommandResult(content json.RawMessage) (CommandResult, bool)

ParseCommandResult 解析 bash 或 read_command_output 的结果正文;不是命令结果时第二个返回值为 false。

func (CommandResult) IsFailed

func (r CommandResult) IsFailed() bool

IsFailed 命令是否失败?

type CommandToolsOpt

type CommandToolsOpt struct {
	// EnvironmentID 是命令所属的执行环境;查找、列出命令都只看这个环境。
	EnvironmentID string
	// Workspace 是启动命令的工作区;cwd 以它的根目录为基准。
	Workspace workspace.Workspace
	// TerminalManager 是本 Session 的命令集合,由 Session 持有。
	TerminalManager terminal.TerminalManager
}

CommandToolsOpt 保存五个命令工具共用的环境和命令集合。

func NewCommandToolsOpt

func NewCommandToolsOpt(environmentID string, environmentWorkspace workspace.Workspace, terminalManager terminal.TerminalManager) *CommandToolsOpt

NewCommandToolsOpt 保存命令所属环境、工作区和 Session 的命令集合。

type PatchFileChange

type PatchFileChange struct {
	Path         string
	Kind         PatchFileKind
	AddedLines   int
	DeletedLines int
	// Content 是新增文件的内容,每行以换行结尾;更新和删除为空。
	Content string
	// Sections 是更新文件的各段改动,顺序和补丁一致;新增和删除为空。
	Sections []PatchSection
}

PatchFileChange 是补丁中一个文件的操作、增删行数和内容;删除整个文件时补丁里只有路径,行数为 0,没有内容和改动段。

func GetPatchFileChanges

func GetPatchFileChanges(patch string) ([]PatchFileChange, error)

GetPatchFileChanges 解析补丁,按补丁顺序返回每个文件的操作、增删行数和内容。

type PatchFileKind

type PatchFileKind string

PatchFileKind 是补丁对一个文件的操作。

const (
	PatchFileAdd    PatchFileKind = "add"
	PatchFileUpdate PatchFileKind = "update"
	PatchFileDelete PatchFileKind = "delete"
)

type PatchSection

type PatchSection struct {
	// Header 是补丁里这一段的 "@@" 行("@@" 或 "@@ <定位文字>")。
	Header string
	// Lines 是这一段的上下文、删除、新增行,分别以 " "、"-"、"+" 开头,不含换行。
	Lines []string
}

PatchSection 是更新文件里的一段改动。

type ReadFileToolOpt

type ReadFileToolOpt struct {
	// Workspace 是读取文件的工作区;相对路径以它的根目录为基准。
	Workspace workspace.Workspace
	// MaxImageBytes 是交给模型的单张图片上限,超过就压缩;必须大于 0。
	MaxImageBytes int
}

ReadFileToolOpt 保存读取工作区和交给模型的图片大小上限。

func NewReadFileToolOpt

func NewReadFileToolOpt(toolWorkspace workspace.Workspace) *ReadFileToolOpt

NewReadFileToolOpt 保存读取工作区和默认图片大小上限。

func (*ReadFileToolOpt) WithMaxImageBytes

func (opt *ReadFileToolOpt) WithMaxImageBytes(maxImageBytes int) *ReadFileToolOpt

WithMaxImageBytes 设置单张图片大小上限并返回本配置。

Jump to

Keyboard shortcuts

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