Co-Authored-By: Quentin Torroba <quentin.torroba@mistral.ai> Co-Authored-By: Michel Thomazo <michel.thomazo@mistral.ai> Co-Authored-By: Clément Drouin <clement.drouin@mistral.ai> Co-Authored-By: Vincent Guilloux <vincent.guilloux@mistral.ai> Co-Authored-By: Clément Siriex <clement.sirieix@mistral.ai> Co-Authored-By: Kim-Adeline Miguel <kimadeline.miguel@mistral.ai> Co-Authored-By: Thaddee Tyl <thaddee.tyl@gmail.com> Co-Authored-By: David Brochart <david.brochart@gmail.com> Co-Authored-By: Joseph Guhlin <joseph.guhlin@gmail.com> Co-Authored-By: Thomas Kenbeek <thomaskenbeek@gmail.com> Co-Authored-By: Remenby31 <baptiste.cruvellier31@gmail.com>
2.8 KiB
2.8 KiB
Use the bash tool to run one-off shell commands.
Key characteristics:
- Stateless: Each command runs independently in a fresh environment
Timeout:
- The
timeoutargument controls how long the command can run before being killed - When
timeoutis not specified (or set toNone), the config default is used - If a command is timing out, do not hesitate to increase the timeout using the
timeoutargument
IMPORTANT: Use dedicated tools if available instead of these bash commands:
File Operations - DO NOT USE:
cat filename→ Useread_file(path="filename")head -n 20 filename→ Useread_file(path="filename", limit=20)tail -n 20 filename→ Read with offset:read_file(path="filename", offset=<line_number>, limit=20)sed -n '100,200p' filename→ Useread_file(path="filename", offset=99, limit=101)less,more,vim,nano→ Useread_filewith offset/limit for navigationecho "content" > file→ Usewrite_file(path="file", content="content")echo "content" >> file→ Read first, thenwrite_filewith overwrite=true
Search Operations - DO NOT USE:
grep -r "pattern" .→ Usegrep(pattern="pattern", path=".")find . -name "*.py"→ Usebash("ls -la")for current dir orgrepwith appropriate patternag,ack,rgcommands → Use thegreptoollocate→ Usegreptool
File Modification - DO NOT USE:
sed -i 's/old/new/g' file→ Usesearch_replacetoolawkfor file editing → Usesearch_replacetool- Any in-place file editing → Use
search_replacetool
APPROPRIATE bash uses:
- System information:
pwd,whoami,date,uname -a - Directory listings:
ls -la,tree(if available) - Git operations:
git status,git log --oneline -10,git diff - Process info:
ps aux | grep process,top -n 1 - Network checks:
ping -c 1 google.com,curl -I https://example.com - Package management:
pip list,npm list - Environment checks:
env | grep VAR,which python - File metadata:
stat filename,file filename,wc -l filename
Example: Reading a large file efficiently
WRONG:
bash("cat large_file.txt") # May hit size limits
bash("head -1000 large_file.txt") # Inefficient
RIGHT:
# First chunk
read_file(path="large_file.txt", limit=1000)
# If was_truncated=true, read next chunk
read_file(path="large_file.txt", offset=1000, limit=1000)
Example: Searching for patterns
WRONG:
bash("grep -r 'TODO' src/") # Don't use bash for grep
bash("find . -type f -name '*.py' | xargs grep 'import'") # Too complex
RIGHT:
grep(pattern="TODO", path="src/")
grep(pattern="import", path=".")
Remember: Bash is best for quick system checks and git operations. For file operations, searching, and editing, always use the dedicated tools when they are available.