# Bash Tool

Use the `bash` tool to execute shell commands. You must provide:
1. `command`: The bash command to execute
2. `suggested_prefixes`: Array of prefixes, one per command segment

## Supported Command Types

**Auto-approved** (if prefix is in the allow list):
- Single commands: `kubectl get pods -n default`
- Pipes (`|`): `kubectl get pods | grep Running | head -5`
- AND operator (`&&`): `kubectl get pods && kubectl get services`
- OR operator (`||`): `kubectl get pods || echo 'no pods found'`
- Semicolon (`;`): `kubectl get pods; kubectl get services`
- Background (`&`): `sleep 5 & echo done`
- Environment variables: `echo $HOME`, `ls ${HOME}/projects`

**Requires user approval** - Scripts and complex constructs:
- `for` loops: `for i in 1 2 3; do echo $i; done`
- `while` loops: `while read line; do echo "$line"; done < file`
- `until` loops: `until false; do echo running; done`
- `if` statements: `if [ -f file ]; then cat file; fi`
- `case` statements: `case $x in 1) echo one;; esac`
- Command substitution: `echo $(whoami)` or `` echo `whoami` ``
- Process substitution: `diff <(cat file1) <(cat file2)`

When you need loops, conditionals, or subshells to accomplish a task, go ahead and use them. The user will be prompted to approve before execution.

## Command Structure

When constructing commands, **place parameter values at the end** so that prefixes can match effectively:
- Good: `kubectl scale deployment nginx -n prod --replicas=3` (prefix `kubectl scale deployment nginx -n prod` matches)
- Bad: `kubectl scale --replicas=3 deployment nginx -n prod` (prefix won't match)

General principle: identifiers first (what you're targeting), parameter values last (how you're affecting it).

## Prefix Guidelines

For each command segment (separated by `|`, `&&`, `||`, `;`, `&`), provide a `suggested_prefixes` entry based on the operation type:

### Read-only operations
Use the **shortest prefix that commits to read-only behavior**.
- `kubectl get pods -n default` → `kubectl get`
- `cat /var/log/app.log` → `cat`
- `grep error file.txt` → `grep`
- `kubectl get pods | grep error | head -10` → `["kubectl get", "grep", "head"]`

### Mixed operations (can branch to read OR write)
Use a **longer prefix that specifies the read-only branch**.
- `kubectl config view` → `kubectl config view` (not `kubectl config`, which could also do `set`)
- `git remote -v` → `git remote -v` (not `git remote`, which could also do `add/remove`)

### Destructive/write operations
Include the **full target identification** (action + resource type + resource name + namespace), but **exclude parameter values**.
- `kubectl delete pod my-pod -n default` → `kubectl delete pod my-pod -n default`
- `kubectl scale deployment nginx --replicas=3` → `kubectl scale deployment nginx`
- `kubectl scale deployment nginx -n prod --replicas=3` → `kubectl scale deployment nginx -n prod`
- `rm /tmp/file.txt` → `rm /tmp/file.txt`

### Scripts (loops, conditionals, subshells)
Provide prefixes for the **key operations** inside the script:
- `for pod in pod1 pod2; do kubectl logs $pod; done` → `["kubectl logs"]`
- `if [ -f /tmp/test ]; then cat /tmp/test; fi` → `["cat"]`
- `echo $(kubectl get pods -o name)` → `["kubectl get"]`

## Allowed Commands

Commands matching these prefixes will execute immediately without prompting:
{% if config and config.allow %}
{% for prefix in config.allow %}
- `{{ prefix }}`
{% endfor %}
{% else %}
- (No commands pre-approved - all commands require user approval)
{% endif %}

## Blocked Commands

These commands are blocked and cannot be executed:
{% if config and config.deny %}
{% for prefix in config.deny %}
- `{{ prefix }}`
{% endfor %}
{% endif %}
- `sudo` (always blocked)
- `su` (always blocked)
