tools

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package tools is the coding tools of pi-durable: read, write, edit and bash over an execution environment. Nothing installs them automatically.

Ports packages/durable/src/tools/index.ts.

Index

Constants

This section is empty.

Variables

View Source
var CodingTools = &durable.Extension{
	Name:  "coding-tools",
	Tools: []*durable.ToolRegistration{CreateReadTool(), CreateWriteTool(), CreateEditTool(), CreateBashTool(nil)},
}

CodingTools is the extension of read, write, edit, and bash.

Functions

func CreateBashTool

func CreateBashTool(options *BashToolOptions) *durable.ToolRegistration

CreateBashTool creates the bash tool. It runs a command through the environment's shell. Its output streams to api.Output, where the Harness keeps the tail within the default limits; the result content is that retained output. The retained window goes to the environment, which may omit output outside it and report how much it omitted, so dropped counts stay exact. Output beyond the limits is spilled to a file whose path is reported as a diagnostic. A nonzero exit or timeout returns an error, which makes an error result that still carries the output and diagnostics.

func CreateEditTool

func CreateEditTool() *durable.ToolRegistration

CreateEditTool creates the edit tool: exact-text replacement in one file.

func CreateReadTool

func CreateReadTool() *durable.ToolRegistration

CreateReadTool creates the read tool. It reads text files. Remarks about truncation and continuation are diagnostics; the content is only file text.

func CreateWriteTool

func CreateWriteTool() *durable.ToolRegistration

CreateWriteTool creates the write tool: it writes a file, creating it and its parent directories.

func GenerateDiffString

func GenerateDiffString(oldContent, newContent string) (diff string, firstChangedLine int)

GenerateDiffString returns the line-numbered display diff and the first changed line number in the new file, byte-identical to upstream generateDiffString with the default 4 lines of context. A returned firstChangedLine of 0 means there was no change (upstream `undefined`).

func GenerateUnifiedPatch

func GenerateUnifiedPatch(path, oldStr, newStr string) string

GenerateUnifiedPatch returns a unified diff for path byte-identical to upstream's generateUnifiedPatch with the default 4 lines of context.

Types

type BashExecution

type BashExecution struct {
	Command    string
	Cwd        string
	Env        map[string]string
	InheritEnv bool
}

BashExecution is the command a bash call is about to run; BashPrepare may change any of it.

type BashPrepare

type BashPrepare func(ctx context.Context, execution *BashExecution, api durable.ToolExecutionApi) error

BashPrepare adjusts a bash execution before it runs, with the call's api. An error fails the call.

type BashToolInput

type BashToolInput struct {
	Command string `json:"command"`
	// Timeout is in seconds; nil has no timeout.
	Timeout *float64 `json:"timeout,omitempty"`
}

BashToolInput is the arguments of the bash tool.

type BashToolOptions

type BashToolOptions struct {
	// CommandPrefix is prepended, with a newline, to every command.
	CommandPrefix string
	Prepare       BashPrepare
}

BashToolOptions configure the bash tool.

type Edit

type Edit struct {
	OldText string `json:"oldText"`
	NewText string `json:"newText"`
}

Edit is one replacement of an edit call: OldText must match one region of the original file.

type EditToolDetails

type EditToolDetails struct {
	Diff             string `json:"diff"`
	Patch            string `json:"patch"`
	FirstChangedLine int    `json:"firstChangedLine,omitempty"`
}

EditToolDetails are the details of an edit result: the display diff, the unified patch, and the first changed line in the new file.

type EditToolInput

type EditToolInput struct {
	Path  string `json:"path"`
	Edits []Edit `json:"edits"`
}

EditToolInput is the arguments of the edit tool.

type ReadToolDetails

type ReadToolDetails struct {
	Truncation *ReadTruncation `json:"truncation,omitempty"`
}

ReadToolDetails are the details of a read result that was truncated.

type ReadToolInput

type ReadToolInput struct {
	Path   string   `json:"path"`
	Offset *float64 `json:"offset,omitempty"`
	Limit  *float64 `json:"limit,omitempty"`
}

ReadToolInput is the arguments of the read tool. Offset and Limit are JSON numbers, which need not be whole.

type ReadTruncation

type ReadTruncation struct {
	Truncated             bool                `json:"truncated"`
	TruncatedBy           durable.TruncatedBy `json:"truncatedBy"`
	TotalLines            int                 `json:"totalLines"`
	TotalBytes            int                 `json:"totalBytes"`
	OutputLines           int                 `json:"outputLines"`
	OutputBytes           int                 `json:"outputBytes"`
	LastLinePartial       bool                `json:"lastLinePartial"`
	FirstLineExceedsLimit bool                `json:"firstLineExceedsLimit"`
	MaxLines              int                 `json:"maxLines"`
	MaxBytes              int                 `json:"maxBytes"`
}

ReadTruncation is how the shown text was cut; the text itself is the result content. It is a TruncationResult without its Content.

type WriteToolInput

type WriteToolInput struct {
	Path    string `json:"path"`
	Content string `json:"content"`
}

WriteToolInput is the arguments of the write tool.

Jump to

Keyboard shortcuts

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