Documentation
¶
Overview ¶
Package bashtool implements the M2 reference port of Claude Code's Bash tool. It executes a shell command via `bash -c` and returns the combined stdout/stderr.
This is a deliberately minimal port. The real BashTool ships ~10k LOC of pathValidation, bashSecurity, bashPermissions, sandbox routing, and run_in_background plumbing; that surface lands in M5 alongside the permission system. M2's BashTool is enough to round-trip a tool call through the agent loop with real subprocess execution.
Reference: src/tools/BashTool/BashTool.tsx (~157 KB), src/tools/BashTool/toolName.ts.
Index ¶
Constants ¶
const DefaultTimeout = 2 * time.Minute
DefaultTimeout matches the leaked TS reference (BashTool.tsx ~882 line `timeout: timeoutMs`) when no timeout argument is supplied: 2 minutes.
const MaxOutputBytes = 30000
MaxOutputBytes truncates combined stdout+stderr to keep tool_result blocks under typical context budgets. Matches the real BashTool's `maxResultSizeChars` of ~30000.
const MaxTimeout = 10 * time.Minute
MaxTimeout caps `timeout` so a runaway tool call can't hold the agent loop hostage. Real BashTool exposes 10 min.
Variables ¶
var SessionEnv map[string]string
SessionEnv is injected by the loop at startup from settings.Merged.Env. When non-nil, each subprocess inherits the base environment plus these vars.
Functions ¶
This section is empty.
Types ¶
type Input ¶
type Input struct {
Command string `json:"command"`
Timeout int `json:"timeout,omitempty"` // milliseconds
Description string `json:"description,omitempty"`
}
Input is the typed view of the JSON input.
type Tool ¶
type Tool struct{}
Tool implements the Bash tool.
func (*Tool) Description ¶
Description is the prompt text the model sees.
func (*Tool) InputSchema ¶
func (*Tool) InputSchema() json.RawMessage
InputSchema is the JSON Schema sent to the model.
func (*Tool) IsConcurrencySafe ¶
func (*Tool) IsConcurrencySafe(json.RawMessage) bool
IsConcurrencySafe: Bash is never concurrency-safe (commands may write to shared state).
func (*Tool) IsReadOnly ¶
func (*Tool) IsReadOnly(raw json.RawMessage) bool
IsReadOnly returns true for shell commands that are known to be read-only (ls, cat, echo, git log/status/diff/show, find, head, tail, wc, etc.). This prevents permission prompts for benign inspection commands, matching Claude Code's isReadOnlyBashCommand heuristic.