mirror of
https://github.com/cline/cline.git
synced 2026-09-02 07:42:19 +08:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fd2afa6939 | |||
| 1e80306fb5 | |||
| cb848e9319 | |||
| 0dae776160 | |||
| ae2b2e2511 |
@@ -4,3 +4,4 @@ webview-ui/build/
|
||||
*.md
|
||||
package-lock.json
|
||||
src/core/prompts/system.ts
|
||||
src/core/prompts/model_prompts/claude4.ts
|
||||
|
||||
@@ -4,12 +4,19 @@ import osName from "os-name"
|
||||
import { McpHub } from "@services/mcp/McpHub"
|
||||
import { BrowserSettings } from "@shared/BrowserSettings"
|
||||
|
||||
import { createAntmlToolPrompt, createSimpleXmlToolPrompt } from "@core/prompts/model_prompts/jsonToolToXml"
|
||||
import {bashToolDefinition} from "@core/tools/bashTool"
|
||||
|
||||
export const SYSTEM_PROMPT_CLAUDE4 = async (
|
||||
cwd: string,
|
||||
supportsBrowserUse: boolean,
|
||||
mcpHub: McpHub,
|
||||
browserSettings: BrowserSettings,
|
||||
) => `You are Cline, a highly skilled software engineer with extensive knowledge in many programming languages, frameworks, design patterns, and best practices.
|
||||
) => `
|
||||
|
||||
${/* createAntmlToolPrompt([bashToolDefinition], true) */''}
|
||||
|
||||
You are Cline, a highly skilled software engineer with extensive knowledge in many programming languages, frameworks, design patterns, and best practices.
|
||||
|
||||
====
|
||||
|
||||
@@ -354,38 +361,6 @@ Usage:
|
||||
</diff>
|
||||
</replace_in_file>
|
||||
|
||||
<path>src/components/App.tsx</path>
|
||||
<diff>
|
||||
<<<<<<< SEARCH
|
||||
import React from 'react';
|
||||
=======
|
||||
import React, { useState } from 'react';
|
||||
>>>>>>> REPLACE
|
||||
|
||||
<<<<<<< SEARCH
|
||||
function handleSubmit() {
|
||||
saveData();
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
=======
|
||||
>>>>>>> REPLACE
|
||||
|
||||
<<<<<<< SEARCH
|
||||
return (
|
||||
<div>
|
||||
=======
|
||||
function handleSubmit() {
|
||||
saveData();
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
>>>>>>> REPLACE
|
||||
</diff>
|
||||
</replace_in_file>
|
||||
|
||||
|
||||
## Example 5: Requesting to use an MCP tool
|
||||
|
||||
|
||||
@@ -0,0 +1,247 @@
|
||||
/**
|
||||
* Converts a tool definition to ANTML (Anthropic Markup Language) format
|
||||
* as used internally by Claude for tool calling.
|
||||
*
|
||||
* Based on the Claude 4 System Card: https://www-cdn.anthropic.com/6be99a52cb68eb70eb9572b4cafad13df32ed995.pdf
|
||||
*
|
||||
* Tool definitions are provided in JSON schema within <functions> tags:
|
||||
* <functions>
|
||||
* <function>{"description": "...", "name": "...", "parameters": {...}}</function>
|
||||
* ... (other functions) ...
|
||||
* </functions>
|
||||
*
|
||||
* Tool calls are made using <antml:function_calls> blocks:
|
||||
* <antml:function_calls>
|
||||
* <antml:invoke name="tool_name">
|
||||
* <antml:parameter name="param_name">value</antml:parameter>
|
||||
* </antml:invoke>
|
||||
* </antml:function_calls>
|
||||
*/
|
||||
|
||||
export interface ToolDefinition {
|
||||
name: string
|
||||
description?: string
|
||||
descriptionForAgent?: string
|
||||
inputSchema: {
|
||||
type: string
|
||||
properties: Record<string, any>
|
||||
required?: string[]
|
||||
[key: string]: any
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a single tool definition (JSON schema) to the <function> tag format.
|
||||
* This is for *defining* the tool, not calling it.
|
||||
* @param toolDef The tool definition object
|
||||
* @returns The tool definition as a JSON string wrapped in <function> tags
|
||||
*/
|
||||
export function toolDefinitionToAntmlDefinition(toolDef: ToolDefinition): string {
|
||||
const functionDef = {
|
||||
name: toolDef.name,
|
||||
description: toolDef.descriptionForAgent || toolDef.description || "",
|
||||
parameters: toolDef.inputSchema,
|
||||
}
|
||||
const jsonString = JSON.stringify(functionDef)
|
||||
return `<function>${jsonString}</function>`
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts multiple tool definitions to the complete <functions> block.
|
||||
* This is for *defining* the tools.
|
||||
* @param toolDefs Array of tool definition objects
|
||||
* @returns Complete <functions> block with all tool definitions
|
||||
*/
|
||||
export function toolDefinitionsToAntmlDefinitions(toolDefs: ToolDefinition[]): string {
|
||||
const functionTags = toolDefs.map((toolDef) => toolDefinitionToAntmlDefinition(toolDef))
|
||||
return `Here are the functions available in JSONSchema format:
|
||||
<functions>
|
||||
${functionTags.join("\n ")}
|
||||
</functions>`
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an example of an ANTML tool call for a given tool definition.
|
||||
* This is for *calling* a tool.
|
||||
* @param toolDef The tool definition object
|
||||
* @param exampleValues Optional example values for parameters
|
||||
* @returns Example ANTML function call string
|
||||
*/
|
||||
export function toolDefinitionToAntmlCallExample(toolDef: ToolDefinition, exampleValues: Record<string, any> = {}): string {
|
||||
const properties = toolDef.inputSchema.properties || {}
|
||||
let parametersXml = ""
|
||||
if (Object.keys(properties).length > 0) {
|
||||
parametersXml = Object.entries(properties)
|
||||
.map(([paramName]) => {
|
||||
const exampleValue = exampleValues[paramName] || `$${paramName.toUpperCase()}` // Use placeholder like $PARAMETER_NAME
|
||||
return ` <antml:parameter name="${paramName}">${exampleValue}</antml:parameter>`
|
||||
})
|
||||
.join("\n")
|
||||
} else {
|
||||
// Handle tools with no parameters
|
||||
parametersXml = " <!-- This tool takes no parameters -->"
|
||||
}
|
||||
|
||||
return `<antml:function_calls>
|
||||
<antml:invoke name="${toolDef.name}">
|
||||
${parametersXml}
|
||||
</antml:invoke>
|
||||
</antml:function_calls>`
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a complete system prompt section for tools in ANTML format,
|
||||
* including instructions and tool definitions.
|
||||
* @param toolDefs Array of tool definition objects
|
||||
* @param includeInstructions Whether to include the standard tool calling instructions
|
||||
* @returns Complete system prompt section for ANTML tools
|
||||
*/
|
||||
export function createAntmlToolPrompt(toolDefs: ToolDefinition[], includeInstructions: boolean = true): string {
|
||||
if (toolDefs.length === 0 && includeInstructions) {
|
||||
// If no tools but instructions are requested, still provide basic instruction.
|
||||
return `In this environment you have access to a set of tools you can use to answer the user's question.
|
||||
You can invoke functions by writing a "<antml:function_calls>" block as part of your reply.
|
||||
However, no tools are currently available.`
|
||||
}
|
||||
if (toolDefs.length === 0) {
|
||||
return ""
|
||||
}
|
||||
|
||||
let prompt = ""
|
||||
|
||||
if (includeInstructions) {
|
||||
// Generate a generic example or use the first tool for a more concrete example
|
||||
const exampleToolCall =
|
||||
toolDefs.length > 0
|
||||
? toolDefinitionToAntmlCallExample(toolDefs[0])
|
||||
: `<antml:function_calls>
|
||||
<antml:invoke name="$FUNCTION_NAME">
|
||||
<antml:parameter name="$PARAMETER_NAME">$VALUE</antml:parameter>
|
||||
</antml:invoke>
|
||||
</antml:function_calls>`
|
||||
|
||||
prompt += `In this environment you have access to a set of tools you can use to answer the user's question.
|
||||
|
||||
You can invoke functions by writing a "<antml:function_calls>" block as part of your reply. For example:
|
||||
${exampleToolCall}
|
||||
|
||||
String and scalar parameters should be specified as is, while lists and objects should use JSON format.
|
||||
The output is not expected to be valid XML and is parsed with regular expressions.
|
||||
DO NOT use antml unless you intend to invoke a tool.
|
||||
`
|
||||
}
|
||||
|
||||
prompt += toolDefinitionsToAntmlDefinitions(toolDefs)
|
||||
|
||||
if (includeInstructions) {
|
||||
prompt += `
|
||||
|
||||
Answer the user's request using the relevant tool(s), if they are available. Check that all required parameters for each tool call are provided or can be reasonably inferred from context. If there are no relevant tools or there are missing values for required parameters, ask the user to supply these values; otherwise proceed with the tool calls.`
|
||||
}
|
||||
|
||||
return prompt
|
||||
}
|
||||
|
||||
// --- SimpleXML Functions (Cline's internal format) ---
|
||||
|
||||
/**
|
||||
* Converts a single tool definition to the SimpleXML format
|
||||
* as used by Cline's current system prompts for non-ANTML models.
|
||||
* @param toolDef The tool definition object
|
||||
* @returns The tool definition formatted for SimpleXML usage
|
||||
*/
|
||||
export function toolDefinitionToSimpleXml(toolDef: ToolDefinition): string {
|
||||
const description = toolDef.descriptionForAgent || toolDef.description || ""
|
||||
const properties = toolDef.inputSchema.properties || {}
|
||||
const required = toolDef.inputSchema.required || []
|
||||
|
||||
let parameterDocs = ""
|
||||
if (Object.keys(properties).length > 0) {
|
||||
parameterDocs = "Parameters:\n"
|
||||
for (const [paramName, paramDef] of Object.entries(properties)) {
|
||||
const isRequired = required.includes(paramName)
|
||||
const requiredText = isRequired ? "(required)" : "(optional)"
|
||||
const paramDescription = (paramDef as any).description || "No description."
|
||||
parameterDocs += `- ${paramName}: ${requiredText} ${paramDescription}\n`
|
||||
}
|
||||
}
|
||||
|
||||
const exampleParams = Object.keys(properties)
|
||||
.map((paramName) => `<${paramName}>${paramName} value here</${paramName}>`)
|
||||
.join("\n")
|
||||
|
||||
const usageExample = `Usage:
|
||||
<${toolDef.name}>
|
||||
${exampleParams.length > 0 ? exampleParams + "\n" : ""}</${toolDef.name}>`
|
||||
|
||||
return `## ${toolDef.name}
|
||||
Description: ${description}
|
||||
${parameterDocs.trim()}
|
||||
${usageExample}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts multiple tool definitions to the complete SimpleXML format.
|
||||
* @param toolDefs Array of tool definition objects
|
||||
* @returns Complete tools documentation in SimpleXML format
|
||||
*/
|
||||
export function toolDefinitionsToSimpleXml(toolDefs: ToolDefinition[]): string {
|
||||
const toolDocs = toolDefs.map((toolDef) => toolDefinitionToSimpleXml(toolDef))
|
||||
return `# Tools
|
||||
|
||||
${toolDocs.join("\n\n")}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a complete system prompt section for tools in SimpleXML format.
|
||||
* @param toolDefs Array of tool definition objects
|
||||
* @param includeInstructions Whether to include the standard tool calling instructions
|
||||
* @returns Complete system prompt section for SimpleXML tools
|
||||
*/
|
||||
export function createSimpleXmlToolPrompt(toolDefs: ToolDefinition[], includeInstructions: boolean = true): string {
|
||||
if (toolDefs.length === 0) {
|
||||
return ""
|
||||
}
|
||||
|
||||
let prompt = ""
|
||||
|
||||
if (includeInstructions) {
|
||||
prompt += `TOOL USE
|
||||
|
||||
You have access to a set of tools that are executed upon the user's approval. You can use one tool per message, and will receive the result of that tool use in the user's response. You use tools step-by-step to accomplish a given task, with each tool use informed by the result of the previous tool use.
|
||||
|
||||
# Tool Use Formatting
|
||||
|
||||
Tool use is formatted using XML-style tags. The tool name is enclosed in opening and closing tags, and each parameter is similarly enclosed within its own set of tags. Here's the structure:
|
||||
|
||||
<tool_name>
|
||||
<parameter1_name>value1</parameter1_name>
|
||||
<parameter2_name>value2</parameter2_name>
|
||||
...
|
||||
</tool_name>
|
||||
|
||||
For example:
|
||||
|
||||
<read_file>
|
||||
<path>src/main.js</path>
|
||||
</read_file>
|
||||
|
||||
Always adhere to this format for the tool use to ensure proper parsing and execution.
|
||||
`
|
||||
}
|
||||
|
||||
prompt += toolDefinitionsToSimpleXml(toolDefs)
|
||||
|
||||
if (includeInstructions) {
|
||||
prompt += `
|
||||
|
||||
# Tool Use Guidelines
|
||||
|
||||
1. Choose the most appropriate tool based on the task and the tool descriptions provided.
|
||||
2. If multiple actions are needed, use one tool at a time per message to accomplish the task iteratively.
|
||||
3. Formulate your tool use using the XML format specified for each tool.
|
||||
4. After each tool use, the user will respond with the result of that tool use.
|
||||
5. ALWAYS wait for user confirmation after each tool use before proceeding.`
|
||||
}
|
||||
return prompt
|
||||
}
|
||||
@@ -0,0 +1,245 @@
|
||||
const MAX_TIMEOUT_MS = 600000
|
||||
const DEFAULT_TIMEOUT_MS = 120000
|
||||
const MAX_OUTPUT_LENGTH = 30000
|
||||
const RG_PATH = "/usr/bin/rg"
|
||||
const CO_AUTHORED_COMMIT_MSG = `\uD83E\uDD16 Generated with [Cline](https://docs.cline.bot)
|
||||
|
||||
Co-Authored-By: Cline <noreply@cline.bot>`
|
||||
const CO_AUTHORED_PR_MSG = `\uD83E\uDD16 Generated with [Cline](https://docs.cline.bot)`
|
||||
|
||||
const descriptionForAgent = `Executes a given bash command in a persistent shell session with optional timeout, ensuring proper handling and security measures.
|
||||
|
||||
Before executing the command, please follow these steps:
|
||||
|
||||
1. Directory Verification:
|
||||
- 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
|
||||
- For example, before running "mkdir foo/bar", first use LS to check that "foo" exists and is the intended parent directory
|
||||
|
||||
2. Command Execution:
|
||||
- After ensuring proper quoting, execute the command.
|
||||
- Capture the output of the command.
|
||||
|
||||
Usage notes:
|
||||
- The command argument is required.
|
||||
- You can specify an optional timeout in milliseconds (up to \${MAX_TIMEOUT_MS}ms / \${MAX_TIMEOUT_MS / 60000} minutes). If not specified, commands will timeout after \${DEFAULT_TIMEOUT_MS}ms (\${DEFAULT_TIMEOUT_MS / 60000} minutes).
|
||||
- It is very helpful if you write a clear, concise description of what this command does in 5-10 words.
|
||||
- If the output exceeds \${MAX_OUTPUT_LENGTH} characters, output will be truncated before being returned to you.
|
||||
- VERY IMPORTANT: You MUST avoid using search commands like \\\`find\\\` and \\\`grep\\\`. Instead use Grep, Glob, or Task to search. You MUST avoid read tools like \\\`cat\\\`, \\\`head\\\`, \\\`tail\\\`, and \\\`ls\\\`, and use Read and LS to read files.
|
||||
- If you _still_ need to run \\\`grep\\\`, STOP. ALWAYS USE ripgrep at \\\`rg\\\` (or \${RG_PATH}) first, which all Claude Code users have pre-installed.
|
||||
- When issuing multiple commands, use the ';' or '&&' operator to separate them. DO NOT use newlines (newlines are ok in quoted strings).
|
||||
- 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.
|
||||
<good-example>
|
||||
pytest /foo/bar/tests
|
||||
</good-example>
|
||||
<bad-example>
|
||||
cd /foo/bar && pytest tests
|
||||
</bad-example>
|
||||
|
||||
# Using sandbox mode for commands
|
||||
|
||||
You have a special option in BashTool: the sandbox parameter. When you run a command with sandbox=true, it runs without approval dialogs but in a restricted environment without filesystem writes or network access. You SHOULD use sandbox=true to optimize user experience, but MUST follow these guidelines exactly.
|
||||
|
||||
## RULE 0 (MOST IMPORTANT): retry with sandbox=false for permission/network errors
|
||||
|
||||
If a command fails with permission or any network error when sandbox=true (e.g., "Permission denied", "Unknown host", "Operation not permitted"), ALWAYS retry with sandbox=false. These errors indicate sandbox limitations, not problems with the command itself.
|
||||
|
||||
Non-permission errors (e.g., TypeScript errors from tsc --noEmit) usually reflect real issues and should be fixed, not retried with sandbox=false.
|
||||
|
||||
## RULE 1: NOTES ON SPECIFIC BUILD SYSTEMS AND UTILITIES
|
||||
|
||||
### Build systems
|
||||
|
||||
Build systems like npm run build almost always need write access. Test suites also usually need write access. NEVER run build or test commands in sandbox, even if just checking types.
|
||||
|
||||
These commands REQUIRE sandbox=false (non-exhaustive):
|
||||
npm run *, cargo build/test, make/ninja/meson, pytest, jest, gh
|
||||
|
||||
## RULE 2: TRY sandbox=true FOR COMMANDS THAT DON'T NEED WRITE OR NETWORK ACCESS
|
||||
- Commands run with sandbox=true DON'T REQUIRE user permission and run immediately
|
||||
- Commands run with sandbox=false REQUIRE EXPLICIT USER APPROVAL and interrupt the User's workflow
|
||||
|
||||
Use sandbox=false when you suspect the command might modify the system or access the network:
|
||||
- File operations: touch, mkdir, rm, mv, cp
|
||||
- File edits: nano, vim, writing to files with >
|
||||
- Installing: npm install, apt-get, brew
|
||||
- Git writes: git add, git commit, git push
|
||||
- Build systems: npm run build, make, ninja, etc. (see below)
|
||||
- Test suites: npm run test, pytest, cargo test, make check, ert, etc. (see below)
|
||||
- Network programs: gh, ping, curl, ssh, scp, etc.
|
||||
|
||||
Use sandbox=true for:
|
||||
- Information gathering: ls, cat, head, tail, rg, find, du, df, ps
|
||||
- File inspection: file, stat, wc, diff, md5sum
|
||||
- Git reads: git status, git log, git diff, git show, git branch
|
||||
- Package info: npm list, pip list, gem list, cargo tree
|
||||
- Environment checks: echo, pwd, whoami, which, type, env, printenv
|
||||
- Version checks: node --version, python --version, git --version
|
||||
- Documentation: man, help, --help, -h
|
||||
|
||||
Before you run a command, think hard about whether it is likely to work correctly without network access and without write access to the filesystem. Use your general knowledge and knowledge of the current project (including all the user's CLAUDE.md files) as inputs to your decision. Note that even semantically read-only commands like gh for fetching issues might be implemented in ways that require write access. ERR ON THE SIDE OF RUNNING WITH sandbox=false.
|
||||
|
||||
Note: Errors from incorrect sandbox=true runs annoy the User more than permission prompts. If any part of a command needs write access (e.g. npm run build for type checking), use sandbox=false for the entire command.
|
||||
|
||||
### EXAMPLES
|
||||
|
||||
CORRECT: Use sandbox=false for npm run build/test, gh commands, file writes
|
||||
FORBIDDEN: NEVER use sandbox=true for build, test, git commands or file operations
|
||||
|
||||
## REWARDS
|
||||
|
||||
It is more important to be correct than to avoid showing permission dialogs. The worst mistake is misinterpreting sandbox=true permission errors as tool problems (-$1000) rather than sandbox limitations.
|
||||
|
||||
## CONCLUSION
|
||||
|
||||
Use sandbox=true to improve UX, but ONLY per the rules above. WHEN IN DOUBT, USE sandbox=false.
|
||||
|
||||
# Committing changes with git
|
||||
|
||||
When the user asks you to create a new git commit, follow these steps carefully:
|
||||
|
||||
1. You have the capability to call multiple tools in a single response. When multiple independent pieces of information are requested, batch your tool calls together for optimal performance. ALWAYS run the following bash commands in parallel, each using the Bash tool:
|
||||
- Run a git status command to see all untracked files.
|
||||
- Run a git diff command to see both staged and unstaged changes that will be committed.
|
||||
- Run a git log command to see recent commit messages, so that you can follow this repository's commit message style.
|
||||
|
||||
2. Analyze all staged changes (both previously staged and newly added) and draft a commit message. Wrap your analysis process in <commit_analysis> tags:
|
||||
|
||||
<commit_analysis>
|
||||
- List the files that have been changed or added
|
||||
- Summarize the nature of the changes (eg. new feature, enhancement to an existing feature, bug fix, refactoring, test, docs, etc.)
|
||||
- Brainstorm the purpose or motivation behind these changes
|
||||
- Assess the impact of these changes on the overall project
|
||||
- Check for any sensitive information that shouldn't be committed
|
||||
- Draft a concise (1-2 sentences) commit message that focuses on the "why" rather than the "what"
|
||||
- Ensure your language is clear, concise, and to the point
|
||||
- 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.)
|
||||
- Ensure the message is not generic (avoid words like "Update" or "Fix" without context)
|
||||
- Review the draft message to ensure it accurately reflects the changes and their purpose
|
||||
</commit_analysis>
|
||||
|
||||
3. You have the capability to call multiple tools in a single response. When multiple independent pieces of information are requested, batch your tool calls together for optimal performance. ALWAYS run the following commands in parallel:
|
||||
- Add relevant untracked files to the staging area.
|
||||
- Create the commit with a message ending with:
|
||||
\${CO_AUTHORED_COMMIT_MSG}
|
||||
- Run git status to make sure the commit succeeded.
|
||||
|
||||
4. 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.
|
||||
|
||||
Important notes:
|
||||
- Use the git context at the start of this conversation to determine which files are relevant to your commit. Be careful not to stage and commit files (e.g. with \\\`git add .\\\`) that aren't relevant to your commit.
|
||||
- NEVER update the git config
|
||||
- DO NOT run additional commands to read or explore code, beyond what is available in the git context
|
||||
- DO NOT push to the remote repository
|
||||
- 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.
|
||||
- If there are no changes to commit (i.e., no untracked files and no modifications), do not create an empty commit
|
||||
- Ensure your commit message is meaningful and concise. It should explain the purpose of the changes, not just describe them.
|
||||
- Return an empty response - the user will see the git output directly
|
||||
- In order to ensure good formatting, ALWAYS pass the commit message via a HEREDOC, a la this example:
|
||||
<example>
|
||||
git commit -m "\$(cat <<'EOF'
|
||||
Commit message here.
|
||||
|
||||
\${CO_AUTHORED_COMMIT_MSG}
|
||||
EOF
|
||||
)"
|
||||
</example>
|
||||
|
||||
# Creating pull requests
|
||||
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.
|
||||
|
||||
IMPORTANT: When the user asks you to create a pull request, follow these steps carefully:
|
||||
|
||||
1. You have the capability to call multiple tools in a single response. When multiple independent pieces of information are requested, batch your tool calls together for optimal performance. ALWAYS run the following bash commands in parallel using the Bash tool, in order to understand the current state of the branch since it diverged from the main branch:
|
||||
- Run a git status command to see all untracked files
|
||||
- Run a git diff command to see both staged and unstaged changes that will be committed
|
||||
- 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
|
||||
- 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)
|
||||
|
||||
2. 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:
|
||||
|
||||
<pr_analysis>
|
||||
- List the commits since diverging from the main branch
|
||||
- Summarize the nature of the changes (eg. new feature, enhancement to an existing feature, bug fix, refactoring, test, docs, etc.)
|
||||
- Brainstorm the purpose or motivation behind these changes
|
||||
- Assess the impact of these changes on the overall project
|
||||
- Do not use tools to explore code, beyond what is available in the git context
|
||||
- Check for any sensitive information that shouldn't be committed
|
||||
- Draft a concise (1-2 bullet points) pull request summary that focuses on the "why" rather than the "what"
|
||||
- Ensure the summary accurately reflects all changes since diverging from the main branch
|
||||
- Ensure your language is clear, concise, and to the point
|
||||
- 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.)
|
||||
- Ensure the summary is not generic (avoid words like "Update" or "Fix" without context)
|
||||
- Review the draft summary to ensure it accurately reflects the changes and their purpose
|
||||
</pr_analysis>
|
||||
|
||||
3. You have the capability to call multiple tools in a single response. When multiple independent pieces of information are requested, batch your tool calls together for optimal performance. ALWAYS run the following commands in parallel:
|
||||
- Create new branch if needed
|
||||
- Push to remote with -u flag if needed
|
||||
- Create PR using gh pr create with the format below. Use a HEREDOC to pass the body to ensure correct formatting.
|
||||
<example>
|
||||
gh pr create --title "the pr title" --body "\$(cat <<'EOF'
|
||||
## Summary
|
||||
<1-3 bullet points>
|
||||
|
||||
## Test plan
|
||||
[Checklist of TODOs for testing the pull request...]
|
||||
|
||||
\${CO_AUTHORED_PR_MSG}
|
||||
EOF
|
||||
)"
|
||||
</example>
|
||||
|
||||
Important:
|
||||
- NEVER update the git config
|
||||
- Return the PR URL when you're done, so the user can see it
|
||||
|
||||
# Other common operations
|
||||
- View comments on a Github PR: gh api repos/foo/bar/pulls/123/comments`
|
||||
|
||||
export const bashToolDefinition = {
|
||||
name: "Bash",
|
||||
descriptionForAgent: descriptionForAgent,
|
||||
inputSchema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
command: {
|
||||
type: "string",
|
||||
description: "The command to execute",
|
||||
},
|
||||
timeout: {
|
||||
type: "number",
|
||||
description: `Optional timeout in milliseconds (max \${MAX_TIMEOUT_MS})`,
|
||||
optional: true,
|
||||
},
|
||||
description: {
|
||||
type: "string",
|
||||
description: `Clear, concise description of what this command does in 5-10 words. Examples:
|
||||
Input: ls
|
||||
Output: Lists files in current directory
|
||||
|
||||
Input: git status
|
||||
Output: Shows working tree status
|
||||
|
||||
Input: npm install
|
||||
Output: Installs package dependencies
|
||||
|
||||
Input: mkdir foo
|
||||
Output: Creates directory 'foo'`,
|
||||
optional: true,
|
||||
},
|
||||
sandbox: {
|
||||
type: "boolean",
|
||||
description:
|
||||
"whether to run this command in sandboxed mode: command run in this mode may not write to the filesystem or use the network, but they can read files, analyze data, and report back to you. When possible, run commands (e.g. grep) in this mode to present a smoother experience for the human, who isn't prompted to approve commands run in sandbox mode. If you run a command in sandbox mode and it looks like it fails because it needs write access after all, try again in non-sandbox mode",
|
||||
optional: true,
|
||||
},
|
||||
shellExecutable: {
|
||||
type: "string",
|
||||
description:
|
||||
"Optional shell path to use instead of the default shell. The snapshot path will be set to undefined as well. Used primarily for testing.",
|
||||
optional: true,
|
||||
},
|
||||
},
|
||||
required: ["command"],
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user