tools

package
v0.32.0 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2026 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const LINES_TO_READ = 100
View Source
const (
	MAX_DEPTH = 2
)
View Source
const MAX_VIEW_SIZE = 16 * 1024 * 4 // roughly 16k tokens

Variables

View Source
var BashToolDefinition = openai.Tool{
	Type: "function",
	Function: &openai.FunctionDefinition{
		Name: "bash",
		Description: `Run a single-line command in a bash shell.
* When invoking this tool, the contents of the "command" parameter does NOT need to be XML-escaped.
* Avoid combining multiple bash commands into one using "&&", ";" or multiple lines. Instead, run each command separately.
* State is persistent across command calls and discussions with the user.`,
		Parameters: utils.GenerateJsonSchema(struct {
			Reason  string `json:"reason" description:"A concise reason for why you need to run this command" required:"true"`
			Command string `json:"command" description:"The bash command to run" required:"true"`
		}{}),
	},
}
View Source
var CreateFileToolDefinition = openai.Tool{
	Type: "function",
	Function: &openai.FunctionDefinition{
		Name:        "create_file",
		Description: `Create a file with the specified content.`,
		Parameters: utils.GenerateJsonSchema(struct {
			Path    string `json:"path" description:"Absolute path to the file" required:"true"`
			Content string `json:"content" description:"The content to write to the file" required:"true"`
		}{}),
	},
}
View Source
var DoneToolDefinition = openai.Tool{
	Type: "function",
	Function: &openai.FunctionDefinition{
		Name:        "done",
		Description: `Confirm that the current user request is done.`,
	},
}
View Source
var EditFileToolDefinition = openai.Tool{
	Type: "function",
	Function: &openai.FunctionDefinition{
		Name:        "edit_file",
		Description: `Edit the content of a file.`,
		Parameters: utils.GenerateJsonSchema(struct {
			Path   string `json:"path" description:"Absolute path to the file" required:"true"`
			OldStr string `` /* 152-byte string literal not displayed */
			NewStr string `json:"new_str" description:"The new string that will replace the old one" required:"true"`
		}{}),
	},
}
View Source
var ShowPermissionsMenu = showPermissionsMenuImpl

ShowPermissionsMenu is a package-level variable that can be mocked in tests By default, it points to the real implementation

View Source
var ViewDirectoryToolDefinition = openai.Tool{
	Type: "function",
	Function: &openai.FunctionDefinition{
		Name:        "view_directory",
		Description: `View the content in a directory up to 2 levels deep.`,
		Parameters: utils.GenerateJsonSchema(struct {
			Path string `json:"path" description:"Absolute path to the directory" required:"true"`
		}{}),
	},
}
View Source
var ViewFileToolDefinition = openai.Tool{
	Type: "function",
	Function: &openai.FunctionDefinition{
		Name:        "view_file",
		Description: fmt.Sprintf(`View the content of a text file, at most %d lines at a time. If the content is too large, tail will be truncated and replaced with <bish:truncated />.`, LINES_TO_READ),
		Parameters: utils.GenerateJsonSchema(struct {
			Path      string `json:"path" description:"Absolute path to the file" required:"true"`
			StartLine int    `` /* 196-byte string literal not displayed */
		}{}),
	},
}

Functions

func BashTool

func BashTool(runner *interp.Runner, historyManager *history.HistoryManager, logger *zap.Logger, sessionID string, params map[string]any) string

func CreateFileTool

func CreateFileTool(runner *interp.Runner, logger *zap.Logger, params map[string]any) string

func EditFileTool

func EditFileTool(runner *interp.Runner, logger *zap.Logger, params map[string]any) string

func ExtractCommands

func ExtractCommands(command string) ([]string, error)

ExtractCommands parses a shell command and extracts all individual commands from compound statements (semicolons, &&, ||, pipes, subshells, etc.)

func GenerateCommandPrefixes

func GenerateCommandPrefixes(command string) []string

GenerateCommandPrefixes generates limited prefixes of a command for permission atoms Returns 1-3 distinct options: base command, with first flag/arg, and full command (if different) Properly handles quoted arguments using shell parsing

func GenerateCommandRegex

func GenerateCommandRegex(command string) string

GenerateCommandRegex generates a regex pattern from a bash command The pattern is specific enough to match similar commands but general enough to be useful For example: - Command: "ls -la /tmp" → Regex: "^ls.*" - Command: "git status" → Regex: "^git status.*" - Command: "npm install package" → Regex: "^npm install.*"

func GenerateCompoundCommandRegex

func GenerateCompoundCommandRegex(command string) ([]string, error)

GenerateCompoundCommandRegex generates regex patterns for all commands in a compound command This is used when the user chooses "always allow" for a compound command

func GeneratePreselectionPattern

func GeneratePreselectionPattern(prefix string) string

GeneratePreselectionPattern generates the pattern that should be checked for pre-selection. This function determines what pattern in the authorized_commands file would correspond to this specific prefix being authorized.

The key insight is that we want literal matching: only the prefix that would generate the exact same pattern should be pre-selected.

For example: - Prefix "awk" should only be pre-selected if "^awk.*" is in the file - Prefix "awk -F'|'" should only be pre-selected if "^awk -F'|'.*" is in the file - Prefix "git status" should only be pre-selected if "^git status.*" is in the file

func GenerateSpecificCommandRegex

func GenerateSpecificCommandRegex(command string) string

GenerateSpecificCommandRegex creates a more specific regex pattern for a given command prefix. This is used for pre-selection in the permissions menu to ensure only exact matches are pre-selected. Unlike GenerateCommandRegex, this creates unique patterns for each specific prefix.

For example: - Command: "awk" → Regex: "^awk$" - Command: "awk -F'|'" → Regex: "^awk -F'|'.*" - Command: "awk -F'|' '{...}'" → Regex: "^awk -F'|' '{...}'.*"

func ValidateCompoundCommand

func ValidateCompoundCommand(command string, patterns []string) (bool, error)

ValidateCompoundCommand checks if all individual commands in a compound command are approved by the given regex patterns

func ViewDirectoryTool

func ViewDirectoryTool(runner *interp.Runner, logger *zap.Logger, params map[string]any) string

func ViewFileTool

func ViewFileTool(runner *interp.Runner, logger *zap.Logger, params map[string]any) string

Types

type PermissionAtom

type PermissionAtom struct {
	Command string // The command prefix (e.g., "ls", "ls --foo", "ls --foo bar")
	Enabled bool   // Whether this permission is enabled
	IsNew   bool   // Whether this is a new permission being added
}

PermissionAtom represents a single permission rule for a command prefix

func GetEnabledPermissions

func GetEnabledPermissions(state *PermissionsMenuState) []PermissionAtom

GetEnabledPermissions returns the list of enabled permission atoms

type PermissionsCompletionProvider

type PermissionsCompletionProvider struct {
	// contains filtered or unexported fields
}

PermissionsCompletionProvider implements shellinput.CompletionProvider for the permissions menu

func (*PermissionsCompletionProvider) GetCompletions

func (p *PermissionsCompletionProvider) GetCompletions(line string, pos int) []string

GetCompletions returns the permission atoms as completion suggestions

func (*PermissionsCompletionProvider) GetHelpInfo

func (p *PermissionsCompletionProvider) GetHelpInfo(line string, pos int) string

GetHelpInfo returns help information for the permissions menu

type PermissionsMenuState

type PermissionsMenuState struct {
	// contains filtered or unexported fields
}

PermissionsMenuState tracks the state of the permissions menu

Jump to

Keyboard shortcuts

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