bash.tpl 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. Executes bash commands with automatic background conversion for long-running tasks.
  2. <cross_platform>
  3. Uses mvdan/sh interpreter (Bash-compatible on all platforms including Windows).
  4. Use forward slashes for paths: "ls C:/foo/bar" not "ls C:\foo\bar".
  5. Common shell builtins and core utils available on Windows.
  6. </cross_platform>
  7. <execution_steps>
  8. 1. Directory Verification: If creating directories/files, use LS tool to verify parent exists
  9. 2. Security Check: Banned commands ({{ .BannedCommands }}) return error - explain to user. Safe read-only commands execute without prompts
  10. 3. Command Execution: Execute with proper quoting, capture output
  11. 4. Auto-Background: Commands exceeding 1 minute automatically move to background and return shell ID
  12. 5. Output Processing: Truncate if exceeds {{ .MaxOutputLength }} characters
  13. 6. Return Result: Include errors, metadata with <cwd></cwd> tags
  14. </execution_steps>
  15. <usage_notes>
  16. - Command required, working_dir optional (defaults to current directory)
  17. - IMPORTANT: Use Grep/Glob/Agent tools instead of 'find'/'grep'. Use View/LS tools instead of 'cat'/'head'/'tail'/'ls'
  18. - Chain with ';' or '&&', avoid newlines except in quoted strings
  19. - Each command runs in independent shell (no state persistence between calls)
  20. - Prefer absolute paths over 'cd' (use 'cd' only if user explicitly requests)
  21. </usage_notes>
  22. <background_execution>
  23. - Set run_in_background=true to run commands in a separate background shell
  24. - Returns a shell ID for managing the background process
  25. - Use job_output tool to view current output from background shell
  26. - Use job_kill tool to terminate a background shell
  27. - IMPORTANT: NEVER use `&` at the end of commands to run in background - use run_in_background parameter instead
  28. - Commands that should run in background:
  29. * Long-running servers (e.g., `npm start`, `python -m http.server`, `node server.js`)
  30. * Watch/monitoring tasks (e.g., `npm run watch`, `tail -f logfile`)
  31. * Continuous processes that don't exit on their own
  32. * Any command expected to run indefinitely
  33. - Commands that should NOT run in background:
  34. * Build commands (e.g., `npm run build`, `go build`)
  35. * Test suites (e.g., `npm test`, `pytest`)
  36. * Git operations
  37. * File operations
  38. * Short-lived scripts
  39. </background_execution>
  40. <git_commits>
  41. When user asks to create git commit:
  42. 1. Single message with three tool_use blocks (IMPORTANT for speed):
  43. - git status (untracked files)
  44. - git diff (staged/unstaged changes)
  45. - git log (recent commit message style)
  46. 2. Add relevant untracked files to staging. Don't commit files already modified at conversation start unless relevant.
  47. 3. Analyze staged changes in <commit_analysis> tags:
  48. - List changed/added files, summarize nature (feature/enhancement/bug fix/refactoring/test/docs)
  49. - Brainstorm purpose/motivation, assess project impact, check for sensitive info
  50. - Don't use tools beyond git context
  51. - Draft concise (1-2 sentences) message focusing on "why" not "what"
  52. - Use clear language, accurate reflection ("add"=new feature, "update"=enhancement, "fix"=bug fix)
  53. - Avoid generic messages, review draft
  54. 4. Create commit{{ if or (eq .Attribution.TrailerStyle "assisted-by") (eq .Attribution.TrailerStyle "co-authored-by")}} with attribution{{ end }} using HEREDOC:
  55. git commit -m "$(cat <<'EOF'
  56. Commit message here.
  57. {{ if .Attribution.GeneratedWith }}
  58. 💘 Generated with Crush
  59. {{ end}}
  60. {{if eq .Attribution.TrailerStyle "assisted-by" }}
  61. Assisted-by: {{ .ModelName }} via Crush
  62. {{ else if eq .Attribution.TrailerStyle "co-authored-by" }}
  63. Co-Authored-By: Crush <[email protected]>
  64. {{ end }}
  65. EOF
  66. )"
  67. 5. If pre-commit hook fails, retry ONCE. If fails again, hook preventing commit. If succeeds but files modified, MUST amend.
  68. 6. Run git status to verify.
  69. Notes: Use "git commit -am" when possible, don't stage unrelated files, NEVER update config, don't push, no -i flags, no empty commits, return empty response.
  70. </git_commits>
  71. <pull_requests>
  72. Use gh command for ALL GitHub tasks. When user asks to create PR:
  73. 1. Single message with multiple tool_use blocks (VERY IMPORTANT for speed):
  74. - git status (untracked files)
  75. - git diff (staged/unstaged changes)
  76. - Check if branch tracks remote and is up to date
  77. - git log and 'git diff main...HEAD' (full commit history from main divergence)
  78. 2. Create new branch if needed
  79. 3. Commit changes if needed
  80. 4. Push to remote with -u flag if needed
  81. 5. Analyze changes in <pr_analysis> tags:
  82. - List commits since diverging from main
  83. - Summarize nature of changes
  84. - Brainstorm purpose/motivation
  85. - Assess project impact
  86. - Don't use tools beyond git context
  87. - Check for sensitive information
  88. - Draft concise (1-2 bullet points) PR summary focusing on "why"
  89. - Ensure summary reflects ALL changes since main divergence
  90. - Clear, concise language
  91. - Accurate reflection of changes and purpose
  92. - Avoid generic summaries
  93. - Review draft
  94. 6. Create PR with gh pr create using HEREDOC:
  95. gh pr create --title "title" --body "$(cat <<'EOF'
  96. ## Summary
  97. <1-3 bullet points>
  98. ## Test plan
  99. [Checklist of TODOs...]
  100. {{ if .Attribution.GeneratedWith}}
  101. 💘 Generated with Crush
  102. {{ end }}
  103. EOF
  104. )"
  105. Important:
  106. - Return empty response - user sees gh output
  107. - Never update git config
  108. </pull_requests>
  109. <examples>
  110. Good: pytest /foo/bar/tests
  111. Bad: cd /foo/bar && pytest tests
  112. </examples>