Skip to content

Commit a8b43ef

Browse files
bugerclaude
andauthored
fix: add anti-bash-for-code-exploration guidance and support promptType+customPrompt together (#490)
- Update bash tool description to explicitly forbid code exploration (grep, cat, find, etc.) - Add anti-bash instruction #7 to commonInstructions in getSystemMessage() - Add anti-bash guidance to Claude and Codex native system prompts - Support both promptType and customPrompt simultaneously: predefined prompt as base + custom wrapped in <custom-instructions> tag - When only customPrompt is set (no promptType), don't append commonInstructions since custom prompts are self-contained Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5d99115 commit a8b43ef

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

npm/src/agent/ProbeAgent.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2876,7 +2876,7 @@ ${searchToolDesc1}
28762876
- searchFiles: Find files by name patterns`;
28772877

28782878
if (this.enableBash) {
2879-
systemPrompt += `\n- bash: Execute bash commands for system operations`;
2879+
systemPrompt += `\n- bash: Execute bash commands for system operations (building, running tests, git, etc.). NEVER use bash for code exploration (no grep, cat, find, head, tail) — always use search and extract tools instead, they are faster and more accurate.`;
28802880
}
28812881

28822882
const searchGuidance1 = this.searchDelegate
@@ -2942,7 +2942,7 @@ ${searchToolDesc2}
29422942
- searchFiles: Find files by name patterns`;
29432943

29442944
if (this.enableBash) {
2945-
systemPrompt += `\n- bash: Execute bash commands for system operations`;
2945+
systemPrompt += `\n- bash: Execute bash commands for system operations (building, running tests, git, etc.). NEVER use bash for code exploration (no grep, cat, find, head, tail) — always use search and extract tools instead, they are faster and more accurate.`;
29462946
}
29472947

29482948
const searchGuidance2 = this.searchDelegate
@@ -3018,7 +3018,8 @@ Follow these instructions carefully:
30183018
3. You should always prefer the search tool for code-related questions.${this.searchDelegate ? ' Ask natural language questions — the search subagent handles keyword formulation and returns extracted code blocks. Use extract only to expand context or read full files.' : ' Search handles stemming and case variations automatically — do NOT try keyword variations manually. Read full files only if really necessary.'}
30193019
4. Ensure to get really deep and understand the full picture before answering.
30203020
5. Once the task is fully completed, use the attempt_completion tool to provide the final result.
3021-
6. ${this.searchDelegate ? 'Ask clear, specific questions when searching. Each search should target a distinct concept or question.' : 'Prefer concise and focused search queries. Use specific keywords and phrases to narrow down results.'}${this.allowEdit ? `
3021+
6. ${this.searchDelegate ? 'Ask clear, specific questions when searching. Each search should target a distinct concept or question.' : 'Prefer concise and focused search queries. Use specific keywords and phrases to narrow down results.'}
3022+
7. NEVER use bash for code exploration (no grep, cat, find, head, tail, awk, sed) — always use search and extract tools instead. Bash is only for system operations like building, running tests, or git commands.${this.allowEdit ? `
30223023
7. When modifying files, choose the appropriate tool:
30233024
- Use 'edit' for all code modifications:
30243025
* PREFERRED: Use start_line (and optionally end_line) for line-targeted editing — this is the safest and most precise approach.${this.hashLines ? ' Use the line:hash references from extract/search output (e.g. "42:ab") for integrity verification.' : ''} Always use extract first to see line numbers${this.hashLines ? ' and hashes' : ''}, then edit by line reference.
@@ -3035,22 +3036,30 @@ Follow these instructions carefully:
30353036
// Use predefined prompts from shared module (imported at top of file)
30363037
let systemMessage = '';
30373038

3038-
// Use custom prompt if provided
3039-
if (this.customPrompt) {
3039+
// Build system message from predefined prompt + optional custom prompt
3040+
if (this.customPrompt && this.promptType && predefinedPrompts[this.promptType]) {
3041+
// Both: use predefined as base, append custom wrapped in tag
3042+
systemMessage = "<role>" + predefinedPrompts[this.promptType] + "</role>";
3043+
systemMessage += commonInstructions;
3044+
systemMessage += "\n<custom-instructions>\n" + this.customPrompt + "\n</custom-instructions>";
3045+
if (this.debug) {
3046+
console.log(`[DEBUG] Using predefined prompt: ${this.promptType} + custom prompt`);
3047+
}
3048+
} else if (this.customPrompt) {
3049+
// Only custom prompt
30403050
systemMessage = "<role>" + this.customPrompt + "</role>";
30413051
if (this.debug) {
30423052
console.log(`[DEBUG] Using custom prompt`);
30433053
}
3044-
}
3045-
// Use predefined prompt if specified
3046-
else if (this.promptType && predefinedPrompts[this.promptType]) {
3054+
} else if (this.promptType && predefinedPrompts[this.promptType]) {
3055+
// Only predefined prompt
30473056
systemMessage = "<role>" + predefinedPrompts[this.promptType] + "</role>";
30483057
if (this.debug) {
30493058
console.log(`[DEBUG] Using predefined prompt: ${this.promptType}`);
30503059
}
30513060
systemMessage += commonInstructions;
30523061
} else {
3053-
// Use the default prompt (code explorer) if no prompt type is specified
3062+
// Default: code explorer
30543063
systemMessage = "<role>" + predefinedPrompts['code-explorer'] + "</role>";
30553064
if (this.debug) {
30563065
console.log(`[DEBUG] Using default prompt: code explorer`);

npm/src/tools/common.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export const searchDelegateDescription = 'Search code in the repository by askin
154154
export const queryDescription = 'Search code using ast-grep structural pattern matching. Use this tool to find specific code structures like functions, classes, or methods.';
155155
export const extractDescription = 'Extract code blocks from files based on file paths and optional line numbers. Use this tool to see complete context after finding relevant files. Line numbers from output can be used with edit start_line/end_line for precise editing.';
156156
export const delegateDescription = 'Automatically delegate big distinct tasks to specialized probe subagents within the agentic loop. Used by AI agents to break down complex requests into focused, parallel tasks.';
157-
export const bashDescription = 'Execute bash commands for system exploration and development tasks. Secure by default with built-in allow/deny lists.';
157+
export const bashDescription = 'Execute bash commands for system operations: building, running tests, git, package management, etc. NEVER use for code exploration (no grep, cat, find, head, tail) — use search and extract tools instead. Secure by default with built-in allow/deny lists.';
158158
export const analyzeAllDescription = 'Answer questions that require analyzing ALL matching data in the codebase. Use for aggregate questions like "What features exist?", "List all API endpoints", "Count TODO comments". The AI automatically plans the search strategy, processes all results via map-reduce, and synthesizes a comprehensive answer. WARNING: Slower than search - only use when you need complete coverage.';
159159

160160

0 commit comments

Comments
 (0)