Skip to content

Commit 35cc8a0

Browse files
committed
refactor: put tool descriptions in markdown files
Signed-off-by: Carlos Alexandro Becker <[email protected]>
1 parent d66dfa2 commit 35cc8a0

24 files changed

+776
-640
lines changed

internal/llm/tools/bash.go

Lines changed: 31 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package tools
22

33
import (
4+
"bytes"
45
"context"
6+
_ "embed"
57
"encoding/json"
68
"fmt"
9+
"html/template"
710
"strings"
811
"time"
912

@@ -43,6 +46,22 @@ const (
4346
BashNoOutput = "no output"
4447
)
4548

49+
//go:embed bash.md
50+
var bashDescription []byte
51+
52+
var bashDescriptionTpl = template.Must(
53+
template.New("bashDescription").
54+
Parse(string(bashDescription)),
55+
)
56+
57+
type bashDescriptionData struct {
58+
BannedCommands string
59+
MaxOutputLength int
60+
AttributionStep string
61+
AttributionExample string
62+
PRAttribution string
63+
}
64+
4665
var bannedCommands = []string{
4766
// Network/Download tools
4867
"alias",
@@ -163,150 +182,18 @@ git commit -m "$(cat <<'EOF'
163182
)"</example>`
164183
}
165184

166-
return fmt.Sprintf(`Executes a given bash command in a persistent shell session with optional timeout, ensuring proper handling and security measures.
167-
168-
CROSS-PLATFORM SHELL SUPPORT:
169-
* This tool uses a shell interpreter (mvdan/sh) that mimics the Bash language,
170-
so you should use Bash syntax in all platforms, including Windows.
171-
The most common shell builtins and core utils are available in Windows as
172-
well.
173-
* Make sure to use forward slashes (/) as path separators in commands, even on
174-
Windows. Example: "ls C:/foo/bar" instead of "ls C:\foo\bar".
175-
176-
Before executing the command, please follow these steps:
177-
178-
1. Directory Verification:
179-
- If the command will create new directories or files, first use the LS tool to verify the parent directory exists and is the correct location
180-
- For example, before running "mkdir foo/bar", first use LS to check that "foo" exists and is the intended parent directory
181-
182-
2. Security Check:
183-
- For security and to limit the threat of a prompt injection attack, some commands are limited or banned. If you use a disallowed command, you will receive an error message explaining the restriction. Explain the error to the User.
184-
- Verify that the command is not one of the banned commands: %s.
185-
186-
3. Command Execution:
187-
- After ensuring proper quoting, execute the command.
188-
- Capture the output of the command.
189-
190-
4. Output Processing:
191-
- If the output exceeds %d characters, output will be truncated before being returned to you.
192-
- Prepare the output for display to the user.
193-
194-
5. Return Result:
195-
- Provide the processed output of the command.
196-
- If any errors occurred during execution, include those in the output.
197-
- The result will also have metadata like the cwd (current working directory) at the end, included with <cwd></cwd> tags.
198-
199-
Usage notes:
200-
- The command argument is required.
201-
- You can specify an optional timeout in milliseconds (up to 600000ms / 10 minutes). If not specified, commands will timeout after 30 minutes.
202-
- VERY IMPORTANT: You MUST avoid using search commands like 'find' and 'grep'. Instead use Grep, Glob, or Agent tools to search. You MUST avoid read tools like 'cat', 'head', 'tail', and 'ls', and use FileRead and LS tools to read files.
203-
- When issuing multiple commands, use the ';' or '&&' operator to separate them. DO NOT use newlines (newlines are ok in quoted strings).
204-
- IMPORTANT: All commands share the same shell session. Shell state (environment variables, virtual environments, current directory, etc.) persist between commands. For example, if you set an environment variable as part of a command, the environment variable will persist for subsequent commands.
205-
- Try to maintain your current working directory throughout the session by using absolute paths and avoiding usage of 'cd'. You may use 'cd' if the User explicitly requests it.
206-
<good-example>
207-
pytest /foo/bar/tests
208-
</good-example>
209-
<bad-example>
210-
cd /foo/bar && pytest tests
211-
</bad-example>
212-
213-
# Committing changes with git
214-
215-
When the user asks you to create a new git commit, follow these steps carefully:
216-
217-
1. Start with a single message that contains exactly three tool_use blocks that do the following (it is VERY IMPORTANT that you send these tool_use blocks in a single message, otherwise it will feel slow to the user!):
218-
- Run a git status command to see all untracked files.
219-
- Run a git diff command to see both staged and unstaged changes that will be committed.
220-
- Run a git log command to see recent commit messages, so that you can follow this repository's commit message style.
221-
222-
2. Use the git context at the start of this conversation to determine which files are relevant to your commit. Add relevant untracked files to the staging area. Do not commit files that were already modified at the start of this conversation, if they are not relevant to your commit.
223-
224-
3. Analyze all staged changes (both previously staged and newly added) and draft a commit message. Wrap your analysis process in <commit_analysis> tags:
225-
226-
<commit_analysis>
227-
- List the files that have been changed or added
228-
- Summarize the nature of the changes (eg. new feature, enhancement to an existing feature, bug fix, refactoring, test, docs, etc.)
229-
- Brainstorm the purpose or motivation behind these changes
230-
- Do not use tools to explore code, beyond what is available in the git context
231-
- Assess the impact of these changes on the overall project
232-
- Check for any sensitive information that shouldn't be committed
233-
- Draft a concise (1-2 sentences) commit message that focuses on the "why" rather than the "what"
234-
- Ensure your language is clear, concise, and to the point
235-
- Ensure the message accurately reflects the changes and their purpose (i.e. "add" means a wholly new feature, "update" means an enhancement to an existing feature, "fix" means a bug fix, etc.)
236-
- Ensure the message is not generic (avoid words like "Update" or "Fix" without context)
237-
- Review the draft message to ensure it accurately reflects the changes and their purpose
238-
</commit_analysis>
239-
240-
%s
241-
242-
- In order to ensure good formatting, ALWAYS pass the commit message via a HEREDOC, a la this example:
243-
%s
244-
245-
5. If the commit fails due to pre-commit hook changes, retry the commit ONCE to include these automated changes. If it fails again, it usually means a pre-commit hook is preventing the commit. If the commit succeeds but you notice that files were modified by the pre-commit hook, you MUST amend your commit to include them.
246-
247-
6. Finally, run git status to make sure the commit succeeded.
248-
249-
Important notes:
250-
- When possible, combine the "git add" and "git commit" commands into a single "git commit -am" command, to speed things up
251-
- However, be careful not to stage files (e.g. with 'git add .') for commits that aren't part of the change, they may have untracked files they want to keep around, but not commit.
252-
- NEVER update the git config
253-
- DO NOT push to the remote repository
254-
- IMPORTANT: Never use git commands with the -i flag (like git rebase -i or git add -i) since they require interactive input which is not supported.
255-
- If there are no changes to commit (i.e., no untracked files and no modifications), do not create an empty commit
256-
- Ensure your commit message is meaningful and concise. It should explain the purpose of the changes, not just describe them.
257-
- Return an empty response - the user will see the git output directly
258-
259-
# Creating pull requests
260-
Use the gh command via the Bash tool for ALL GitHub-related tasks including working with issues, pull requests, checks, and releases. If given a Github URL use the gh command to get the information needed.
261-
262-
IMPORTANT: When the user asks you to create a pull request, follow these steps carefully:
263-
264-
1. Understand the current state of the branch. Remember to send a single message that contains multiple tool_use blocks (it is VERY IMPORTANT that you do this in a single message, otherwise it will feel slow to the user!):
265-
- Run a git status command to see all untracked files.
266-
- Run a git diff command to see both staged and unstaged changes that will be committed.
267-
- Check if the current branch tracks a remote branch and is up to date with the remote, so you know if you need to push to the remote
268-
- Run a git log command and 'git diff main...HEAD' to understand the full commit history for the current branch (from the time it diverged from the 'main' branch.)
269-
270-
2. Create new branch if needed
271-
272-
3. Commit changes if needed
273-
274-
4. Push to remote with -u flag if needed
275-
276-
5. Analyze all changes that will be included in the pull request, making sure to look at all relevant commits (not just the latest commit, but all commits that will be included in the pull request!), and draft a pull request summary. Wrap your analysis process in <pr_analysis> tags:
277-
278-
<pr_analysis>
279-
- List the commits since diverging from the main branch
280-
- Summarize the nature of the changes (eg. new feature, enhancement to an existing feature, bug fix, refactoring, test, docs, etc.)
281-
- Brainstorm the purpose or motivation behind these changes
282-
- Assess the impact of these changes on the overall project
283-
- Do not use tools to explore code, beyond what is available in the git context
284-
- Check for any sensitive information that shouldn't be committed
285-
- Draft a concise (1-2 bullet points) pull request summary that focuses on the "why" rather than the "what"
286-
- Ensure the summary accurately reflects all changes since diverging from the main branch
287-
- Ensure your language is clear, concise, and to the point
288-
- Ensure the summary accurately reflects the changes and their purpose (ie. "add" means a wholly new feature, "update" means an enhancement to an existing feature, "fix" means a bug fix, etc.)
289-
- Ensure the summary is not generic (avoid words like "Update" or "Fix" without context)
290-
- Review the draft summary to ensure it accurately reflects the changes and their purpose
291-
</pr_analysis>
292-
293-
6. Create PR using gh pr create with the format below. Use a HEREDOC to pass the body to ensure correct formatting.
294-
<example>
295-
gh pr create --title "the pr title" --body "$(cat <<'EOF'
296-
## Summary
297-
<1-3 bullet points>
298-
299-
## Test plan
300-
[Checklist of TODOs for testing the pull request...]
301-
302-
%s
303-
EOF
304-
)"
305-
</example>
306-
307-
Important:
308-
- Return an empty response - the user will see the gh output directly
309-
- Never update git config`, bannedCommandsStr, MaxOutputLength, attributionStep, attributionExample, prAttribution)
185+
var out bytes.Buffer
186+
if err := bashDescriptionTpl.Execute(&out, bashDescriptionData{
187+
BannedCommands: bannedCommandsStr,
188+
MaxOutputLength: MaxOutputLength,
189+
AttributionStep: attributionStep,
190+
AttributionExample: attributionExample,
191+
PRAttribution: prAttribution,
192+
}); err != nil {
193+
// this should never happen.
194+
panic("failed to execute bash description template: " + err.Error())
195+
}
196+
return out.String()
310197
}
311198

312199
func blockFuncs() []shell.BlockFunc {

internal/llm/tools/bash.md

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
Executes a given bash command in a persistent shell session with optional timeout, ensuring proper handling and security measures.
2+
3+
CROSS-PLATFORM SHELL SUPPORT:
4+
5+
- This tool uses a shell interpreter (mvdan/sh) that mimics the Bash language,
6+
so you should use Bash syntax in all platforms, including Windows.
7+
The most common shell builtins and core utils are available in Windows as
8+
well.
9+
- Make sure to use forward slashes (/) as path separators in commands, even on
10+
Windows. Example: "ls C:/foo/bar" instead of "ls C:\foo\bar".
11+
12+
Before executing the command, please follow these steps:
13+
14+
1. Directory Verification:
15+
16+
- If the command will create new directories or files, first use the LS tool to verify the parent directory exists and is the correct location
17+
- For example, before running "mkdir foo/bar", first use LS to check that "foo" exists and is the intended parent directory
18+
19+
2. Security Check:
20+
21+
- For security and to limit the threat of a prompt injection attack, some commands are limited or banned. If you use a disallowed command, you will receive an error message explaining the restriction. Explain the error to the User.
22+
- Verify that the command is not one of the banned commands: {{ .BannedCommands }}.
23+
24+
3. Command Execution:
25+
26+
- After ensuring proper quoting, execute the command.
27+
- Capture the output of the command.
28+
29+
4. Output Processing:
30+
31+
- If the output exceeds {{ .MaxOutputLength }} characters, output will be truncated before being returned to you.
32+
- Prepare the output for display to the user.
33+
34+
5. Return Result:
35+
36+
- Provide the processed output of the command.
37+
- If any errors occurred during execution, include those in the output.
38+
- The result will also have metadata like the cwd (current working directory) at the end, included with <cwd></cwd> tags.
39+
40+
Usage notes:
41+
42+
- The command argument is required.
43+
- You can specify an optional timeout in milliseconds (up to 600000ms / 10 minutes). If not specified, commands will timeout after 30 minutes.
44+
- VERY IMPORTANT: You MUST avoid using search commands like 'find' and 'grep'. Instead use Grep, Glob, or Agent tools to search. You MUST avoid read tools like 'cat', 'head', 'tail', and 'ls', and use FileRead and LS tools to read files.
45+
- When issuing multiple commands, use the ';' or '&&' operator to separate them. DO NOT use newlines (newlines are ok in quoted strings).
46+
- IMPORTANT: All commands share the same shell session. Shell state (environment variables, virtual environments, current directory, etc.) persist between commands. For example, if you set an environment variable as part of a command, the environment variable will persist for subsequent commands.
47+
- Try to maintain your current working directory throughout the session by using absolute paths and avoiding usage of 'cd'. You may use 'cd' if the User explicitly requests it.
48+
<good-example>
49+
pytest /foo/bar/tests
50+
</good-example>
51+
<bad-example>
52+
cd /foo/bar && pytest tests
53+
</bad-example>
54+
55+
# Committing changes with git
56+
57+
When the user asks you to create a new git commit, follow these steps carefully:
58+
59+
1. Start with a single message that contains exactly three tool_use blocks that do the following (it is VERY IMPORTANT that you send these tool_use blocks in a single message, otherwise it will feel slow to the user!):
60+
61+
- Run a git status command to see all untracked files.
62+
- Run a git diff command to see both staged and unstaged changes that will be committed.
63+
- Run a git log command to see recent commit messages, so that you can follow this repository's commit message style.
64+
65+
2. Use the git context at the start of this conversation to determine which files are relevant to your commit. Add relevant untracked files to the staging area. Do not commit files that were already modified at the start of this conversation, if they are not relevant to your commit.
66+
67+
3. Analyze all staged changes (both previously staged and newly added) and draft a commit message. Wrap your analysis process in <commit_analysis> tags:
68+
69+
<commit_analysis>
70+
71+
- List the files that have been changed or added
72+
- Summarize the nature of the changes (eg. new feature, enhancement to an existing feature, bug fix, refactoring, test, docs, etc.)
73+
- Brainstorm the purpose or motivation behind these changes
74+
- Do not use tools to explore code, beyond what is available in the git context
75+
- Assess the impact of these changes on the overall project
76+
- Check for any sensitive information that shouldn't be committed
77+
- Draft a concise (1-2 sentences) commit message that focuses on the "why" rather than the "what"
78+
- Ensure your language is clear, concise, and to the point
79+
- Ensure the message accurately reflects the changes and their purpose (i.e. "add" means a wholly new feature, "update" means an enhancement to an existing feature, "fix" means a bug fix, etc.)
80+
- Ensure the message is not generic (avoid words like "Update" or "Fix" without context)
81+
- Review the draft message to ensure it accurately reflects the changes and their purpose
82+
</commit_analysis>
83+
84+
{{ .AttributionStep }}
85+
86+
- In order to ensure good formatting, ALWAYS pass the commit message via a HEREDOC, a la this example:
87+
{{ .AttributionExample }}
88+
89+
5. If the commit fails due to pre-commit hook changes, retry the commit ONCE to include these automated changes. If it fails again, it usually means a pre-commit hook is preventing the commit. If the commit succeeds but you notice that files were modified by the pre-commit hook, you MUST amend your commit to include them.
90+
91+
6. Finally, run git status to make sure the commit succeeded.
92+
93+
Important notes:
94+
95+
- When possible, combine the "git add" and "git commit" commands into a single "git commit -am" command, to speed things up
96+
- However, be careful not to stage files (e.g. with 'git add .') for commits that aren't part of the change, they may have untracked files they want to keep around, but not commit.
97+
- NEVER update the git config
98+
- DO NOT push to the remote repository
99+
- IMPORTANT: Never use git commands with the -i flag (like git rebase -i or git add -i) since they require interactive input which is not supported.
100+
- If there are no changes to commit (i.e., no untracked files and no modifications), do not create an empty commit
101+
- Ensure your commit message is meaningful and concise. It should explain the purpose of the changes, not just describe them.
102+
- Return an empty response - the user will see the git output directly
103+
104+
# Creating pull requests
105+
106+
Use the gh command via the Bash tool for ALL GitHub-related tasks including working with issues, pull requests, checks, and releases. If given a Github URL use the gh command to get the information needed.
107+
108+
IMPORTANT: When the user asks you to create a pull request, follow these steps carefully:
109+
110+
1. Understand the current state of the branch. Remember to send a single message that contains multiple tool_use blocks (it is VERY IMPORTANT that you do this in a single message, otherwise it will feel slow to the user!):
111+
112+
- Run a git status command to see all untracked files.
113+
- Run a git diff command to see both staged and unstaged changes that will be committed.
114+
- Check if the current branch tracks a remote branch and is up to date with the remote, so you know if you need to push to the remote
115+
- Run a git log command and 'git diff main...HEAD' to understand the full commit history for the current branch (from the time it diverged from the 'main' branch.)
116+
117+
2. Create new branch if needed
118+
119+
3. Commit changes if needed
120+
121+
4. Push to remote with -u flag if needed
122+
123+
5. Analyze all changes that will be included in the pull request, making sure to look at all relevant commits (not just the latest commit, but all commits that will be included in the pull request!), and draft a pull request summary. Wrap your analysis process in <pr_analysis> tags:
124+
125+
<pr_analysis>
126+
127+
- List the commits since diverging from the main branch
128+
- Summarize the nature of the changes (eg. new feature, enhancement to an existing feature, bug fix, refactoring, test, docs, etc.)
129+
- Brainstorm the purpose or motivation behind these changes
130+
- Assess the impact of these changes on the overall project
131+
- Do not use tools to explore code, beyond what is available in the git context
132+
- Check for any sensitive information that shouldn't be committed
133+
- Draft a concise (1-2 bullet points) pull request summary that focuses on the "why" rather than the "what"
134+
- Ensure the summary accurately reflects all changes since diverging from the main branch
135+
- Ensure your language is clear, concise, and to the point
136+
- Ensure the summary accurately reflects the changes and their purpose (ie. "add" means a wholly new feature, "update" means an enhancement to an existing feature, "fix" means a bug fix, etc.)
137+
- Ensure the summary is not generic (avoid words like "Update" or "Fix" without context)
138+
- Review the draft summary to ensure it accurately reflects the changes and their purpose
139+
</pr_analysis>
140+
141+
6. Create PR using gh pr create with the format below. Use a HEREDOC to pass the body to ensure correct formatting.
142+
<example>
143+
gh pr create --title "the pr title" --body "$(cat <<'EOF'
144+
145+
## Summary
146+
147+
<1-3 bullet points>
148+
149+
## Test plan
150+
151+
[Checklist of TODOs for testing the pull request...]
152+
153+
{{ .PRAttribution }}
154+
EOF
155+
)"
156+
</example>
157+
158+
Important:
159+
160+
- Return an empty response - the user will see the gh output directly
161+
- Never update git config

0 commit comments

Comments
 (0)