Documentation
¶
Index ¶
- Constants
- Variables
- func BashTool(runner *interp.Runner, historyManager *history.HistoryManager, ...) string
- func CreateFileTool(runner *interp.Runner, logger *zap.Logger, params map[string]any) string
- func EditFileTool(runner *interp.Runner, logger *zap.Logger, params map[string]any) string
- func ExtractCommands(command string) ([]string, error)
- func GenerateCommandPrefixes(command string) []string
- func GenerateCommandRegex(command string) string
- func GenerateCompoundCommandRegex(command string) ([]string, error)
- func GeneratePreselectionPattern(prefix string) string
- func GenerateSpecificCommandRegex(command string) string
- func GrepFileTool(runner *interp.Runner, logger *zap.Logger, params map[string]any) string
- func ValidateCompoundCommand(command string, patterns []string) (bool, error)
- func ViewDirectoryTool(runner *interp.Runner, logger *zap.Logger, params map[string]any) string
- func ViewFileTool(runner *interp.Runner, logger *zap.Logger, params map[string]any) string
- type PermissionAtom
- type PermissionsCompletionProvider
- type PermissionsMenuState
Constants ¶
const LINES_TO_READ = 100
const (
MAX_DEPTH = 2
)
const MAX_VIEW_SIZE = 16 * 1024 * 4 // roughly 16k tokens
Variables ¶
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"` }{}), }, }
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"` }{}), }, }
var DoneToolDefinition = openai.Tool{ Type: "function", Function: &openai.FunctionDefinition{ Name: "done", Description: `Confirm that the current user request is done.`, }, }
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"` }{}), }, }
var GrepFileToolDefinition = openai.Tool{ Type: "function", Function: &openai.FunctionDefinition{ Name: "grep_file", Description: "Search for a pattern (regex) in a file and return matching lines with line numbers. Similar to grep command.", Parameters: utils.GenerateJsonSchema(struct { Path string `json:"path" description:"Absolute path to the file to search" required:"true"` Pattern string `json:"pattern" description:"Regular expression pattern to search for" required:"true"` ContextLines int `` /* 143-byte string literal not displayed */ }{}), }, }
var ShowPermissionsMenu = showPermissionsMenuImpl
ShowPermissionsMenu is a package-level variable that can be mocked in tests By default, it points to the real implementation
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"` }{}), }, }
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 CreateFileTool ¶
func EditFileTool ¶
func ExtractCommands ¶
ExtractCommands parses a shell command and extracts all individual commands from compound statements (semicolons, &&, ||, pipes, subshells, etc.)
func GenerateCommandPrefixes ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 GrepFileTool ¶ added in v0.34.0
func ValidateCompoundCommand ¶
ValidateCompoundCommand checks if all individual commands in a compound command are approved by the given regex patterns
func ViewDirectoryTool ¶
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