Vastly improved debug tool and related instructions
Accompanying simulation test Cleanup - A single source of truth for parameter descriptions
This commit is contained in:
@@ -14,17 +14,22 @@ from systemprompts import ANALYZE_PROMPT
|
||||
|
||||
from .base import BaseTool, ToolRequest
|
||||
|
||||
# Field descriptions to avoid duplication between Pydantic and JSON schema
|
||||
ANALYZE_FIELD_DESCRIPTIONS = {
|
||||
"files": "Files or directories to analyze (must be absolute paths)",
|
||||
"prompt": "What to analyze or look for",
|
||||
"analysis_type": "Type of analysis to perform",
|
||||
"output_format": "How to format the output",
|
||||
}
|
||||
|
||||
|
||||
class AnalyzeRequest(ToolRequest):
|
||||
"""Request model for analyze tool"""
|
||||
|
||||
files: list[str] = Field(..., description="Files or directories to analyze (must be absolute paths)")
|
||||
prompt: str = Field(..., description="What to analyze or look for")
|
||||
analysis_type: Optional[str] = Field(
|
||||
None,
|
||||
description="Type of analysis: architecture|performance|security|quality|general",
|
||||
)
|
||||
output_format: Optional[str] = Field("detailed", description="Output format: summary|detailed|actionable")
|
||||
files: list[str] = Field(..., description=ANALYZE_FIELD_DESCRIPTIONS["files"])
|
||||
prompt: str = Field(..., description=ANALYZE_FIELD_DESCRIPTIONS["prompt"])
|
||||
analysis_type: Optional[str] = Field(None, description=ANALYZE_FIELD_DESCRIPTIONS["analysis_type"])
|
||||
output_format: Optional[str] = Field("detailed", description=ANALYZE_FIELD_DESCRIPTIONS["output_format"])
|
||||
|
||||
|
||||
class AnalyzeTool(BaseTool):
|
||||
@@ -50,12 +55,12 @@ class AnalyzeTool(BaseTool):
|
||||
"files": {
|
||||
"type": "array",
|
||||
"items": {"type": "string"},
|
||||
"description": "Files or directories to analyze (must be absolute paths)",
|
||||
"description": ANALYZE_FIELD_DESCRIPTIONS["files"],
|
||||
},
|
||||
"model": self.get_model_field_schema(),
|
||||
"prompt": {
|
||||
"type": "string",
|
||||
"description": "What to analyze or look for",
|
||||
"description": ANALYZE_FIELD_DESCRIPTIONS["prompt"],
|
||||
},
|
||||
"analysis_type": {
|
||||
"type": "string",
|
||||
@@ -66,13 +71,13 @@ class AnalyzeTool(BaseTool):
|
||||
"quality",
|
||||
"general",
|
||||
],
|
||||
"description": "Type of analysis to perform",
|
||||
"description": ANALYZE_FIELD_DESCRIPTIONS["analysis_type"],
|
||||
},
|
||||
"output_format": {
|
||||
"type": "string",
|
||||
"enum": ["summary", "detailed", "actionable"],
|
||||
"default": "detailed",
|
||||
"description": "How to format the output",
|
||||
"description": ANALYZE_FIELD_DESCRIPTIONS["output_format"],
|
||||
},
|
||||
"temperature": {
|
||||
"type": "number",
|
||||
|
||||
@@ -14,31 +14,29 @@ from systemprompts import CHAT_PROMPT
|
||||
|
||||
from .base import BaseTool, ToolRequest
|
||||
|
||||
# Field descriptions to avoid duplication between Pydantic and JSON schema
|
||||
CHAT_FIELD_DESCRIPTIONS = {
|
||||
"prompt": (
|
||||
"Your thorough, expressive question with as much context as possible. Remember: you're talking to "
|
||||
"another Claude assistant who has deep expertise and can provide nuanced insights. Include your "
|
||||
"current thinking, specific challenges, background context, what you've already tried, and what "
|
||||
"kind of response would be most helpful. The more context and detail you provide, the more "
|
||||
"valuable and targeted the response will be."
|
||||
),
|
||||
"files": "Optional files for context (must be absolute paths)",
|
||||
"images": (
|
||||
"Optional images for visual context. Useful for UI discussions, diagrams, visual problems, "
|
||||
"error screens, or architectural mockups."
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
class ChatRequest(ToolRequest):
|
||||
"""Request model for chat tool"""
|
||||
|
||||
prompt: str = Field(
|
||||
...,
|
||||
description=(
|
||||
"Your thorough, expressive question with as much context as possible. Remember: you're talking to "
|
||||
"another Claude assistant who has deep expertise and can provide nuanced insights. Include your "
|
||||
"current thinking, specific challenges, background context, what you've already tried, and what "
|
||||
"kind of response would be most helpful. The more context and detail you provide, the more "
|
||||
"valuable and targeted the response will be."
|
||||
),
|
||||
)
|
||||
files: Optional[list[str]] = Field(
|
||||
default_factory=list,
|
||||
description="Optional files for context (must be absolute paths)",
|
||||
)
|
||||
images: Optional[list[str]] = Field(
|
||||
default_factory=list,
|
||||
description=(
|
||||
"Optional images for visual context. Useful for UI discussions, diagrams, visual problems, "
|
||||
"error screens, or architectural mockups."
|
||||
),
|
||||
)
|
||||
prompt: str = Field(..., description=CHAT_FIELD_DESCRIPTIONS["prompt"])
|
||||
files: Optional[list[str]] = Field(default_factory=list, description=CHAT_FIELD_DESCRIPTIONS["files"])
|
||||
images: Optional[list[str]] = Field(default_factory=list, description=CHAT_FIELD_DESCRIPTIONS["images"])
|
||||
|
||||
|
||||
class ChatTool(BaseTool):
|
||||
@@ -65,26 +63,17 @@ class ChatTool(BaseTool):
|
||||
"properties": {
|
||||
"prompt": {
|
||||
"type": "string",
|
||||
"description": (
|
||||
"Your thorough, expressive question with as much context as possible. Remember: you're "
|
||||
"talking to another Claude assistant who has deep expertise and can provide nuanced "
|
||||
"insights. Include your current thinking, specific challenges, background context, what "
|
||||
"you've already tried, and what kind of response would be most helpful. The more context "
|
||||
"and detail you provide, the more valuable and targeted the response will be."
|
||||
),
|
||||
"description": CHAT_FIELD_DESCRIPTIONS["prompt"],
|
||||
},
|
||||
"files": {
|
||||
"type": "array",
|
||||
"items": {"type": "string"},
|
||||
"description": "Optional files for context (must be absolute paths)",
|
||||
"description": CHAT_FIELD_DESCRIPTIONS["files"],
|
||||
},
|
||||
"images": {
|
||||
"type": "array",
|
||||
"items": {"type": "string"},
|
||||
"description": (
|
||||
"Optional images for visual context. Useful for UI discussions, diagrams, visual "
|
||||
"problems, error screens, or architectural mockups."
|
||||
),
|
||||
"description": CHAT_FIELD_DESCRIPTIONS["images"],
|
||||
},
|
||||
"model": self.get_model_field_schema(),
|
||||
"temperature": {
|
||||
|
||||
@@ -23,6 +23,28 @@ from systemprompts import CODEREVIEW_PROMPT
|
||||
|
||||
from .base import BaseTool, ToolRequest
|
||||
|
||||
# Field descriptions to avoid duplication between Pydantic and JSON schema
|
||||
CODEREVIEW_FIELD_DESCRIPTIONS = {
|
||||
"files": "Code files or directories to review (must be absolute paths)",
|
||||
"prompt": (
|
||||
"User's summary of what the code does, expected behavior, constraints, and review objectives. "
|
||||
"IMPORTANT: Before using this tool, Claude should first perform its own preliminary review - "
|
||||
"examining the code structure, identifying potential issues, understanding the business logic, "
|
||||
"and noting areas of concern. Include Claude's initial observations about code quality, potential "
|
||||
"bugs, architectural patterns, and specific areas that need deeper scrutiny. This dual-perspective "
|
||||
"approach (Claude's analysis + external model's review) provides more comprehensive feedback and "
|
||||
"catches issues that either reviewer might miss alone."
|
||||
),
|
||||
"images": (
|
||||
"Optional images of architecture diagrams, UI mockups, design documents, or visual references "
|
||||
"for code review context"
|
||||
),
|
||||
"review_type": "Type of review to perform",
|
||||
"focus_on": "Specific aspects to focus on, or additional context that would help understand areas of concern",
|
||||
"standards": "Coding standards to enforce",
|
||||
"severity_filter": "Minimum severity level to report",
|
||||
}
|
||||
|
||||
|
||||
class CodeReviewRequest(ToolRequest):
|
||||
"""
|
||||
@@ -33,39 +55,13 @@ class CodeReviewRequest(ToolRequest):
|
||||
review focus and standards.
|
||||
"""
|
||||
|
||||
files: list[str] = Field(
|
||||
...,
|
||||
description="Code files or directories to review (must be absolute paths)",
|
||||
)
|
||||
prompt: str = Field(
|
||||
...,
|
||||
description=(
|
||||
"User's summary of what the code does, expected behavior, constraints, and review objectives. "
|
||||
"IMPORTANT: Before using this tool, Claude should first perform its own preliminary review - "
|
||||
"examining the code structure, identifying potential issues, understanding the business logic, "
|
||||
"and noting areas of concern. Include Claude's initial observations about code quality, potential "
|
||||
"bugs, architectural patterns, and specific areas that need deeper scrutiny. This dual-perspective "
|
||||
"approach (Claude's analysis + external model's review) provides more comprehensive feedback and "
|
||||
"catches issues that either reviewer might miss alone."
|
||||
),
|
||||
)
|
||||
images: Optional[list[str]] = Field(
|
||||
None,
|
||||
description=(
|
||||
"Optional images of architecture diagrams, UI mockups, design documents, or visual references "
|
||||
"for code review context"
|
||||
),
|
||||
)
|
||||
review_type: str = Field("full", description="Type of review: full|security|performance|quick")
|
||||
focus_on: Optional[str] = Field(
|
||||
None,
|
||||
description=("Specific aspects to focus on, or additional context that would help understand areas of concern"),
|
||||
)
|
||||
standards: Optional[str] = Field(None, description="Coding standards or guidelines to enforce")
|
||||
severity_filter: str = Field(
|
||||
"all",
|
||||
description="Minimum severity to report: critical|high|medium|low|all",
|
||||
)
|
||||
files: list[str] = Field(..., description=CODEREVIEW_FIELD_DESCRIPTIONS["files"])
|
||||
prompt: str = Field(..., description=CODEREVIEW_FIELD_DESCRIPTIONS["prompt"])
|
||||
images: Optional[list[str]] = Field(None, description=CODEREVIEW_FIELD_DESCRIPTIONS["images"])
|
||||
review_type: str = Field("full", description=CODEREVIEW_FIELD_DESCRIPTIONS["review_type"])
|
||||
focus_on: Optional[str] = Field(None, description=CODEREVIEW_FIELD_DESCRIPTIONS["focus_on"])
|
||||
standards: Optional[str] = Field(None, description=CODEREVIEW_FIELD_DESCRIPTIONS["standards"])
|
||||
severity_filter: str = Field("all", description=CODEREVIEW_FIELD_DESCRIPTIONS["severity_filter"])
|
||||
|
||||
|
||||
class CodeReviewTool(BaseTool):
|
||||
@@ -103,52 +99,37 @@ class CodeReviewTool(BaseTool):
|
||||
"files": {
|
||||
"type": "array",
|
||||
"items": {"type": "string"},
|
||||
"description": "Code files or directories to review (must be absolute paths)",
|
||||
"description": CODEREVIEW_FIELD_DESCRIPTIONS["files"],
|
||||
},
|
||||
"model": self.get_model_field_schema(),
|
||||
"prompt": {
|
||||
"type": "string",
|
||||
"description": (
|
||||
"User's summary of what the code does, expected behavior, constraints, and review "
|
||||
"objectives. IMPORTANT: Before using this tool, Claude should first perform its own "
|
||||
"preliminary review - examining the code structure, identifying potential issues, "
|
||||
"understanding the business logic, and noting areas of concern. Include Claude's initial "
|
||||
"observations about code quality, potential bugs, architectural patterns, and specific "
|
||||
"areas that need deeper scrutiny. This dual-perspective approach (Claude's analysis + "
|
||||
"external model's review) provides more comprehensive feedback and catches issues that "
|
||||
"either reviewer might miss alone."
|
||||
),
|
||||
"description": CODEREVIEW_FIELD_DESCRIPTIONS["prompt"],
|
||||
},
|
||||
"images": {
|
||||
"type": "array",
|
||||
"items": {"type": "string"},
|
||||
"description": (
|
||||
"Optional images of architecture diagrams, UI mockups, design documents, or visual "
|
||||
"references for code review context"
|
||||
),
|
||||
"description": CODEREVIEW_FIELD_DESCRIPTIONS["images"],
|
||||
},
|
||||
"review_type": {
|
||||
"type": "string",
|
||||
"enum": ["full", "security", "performance", "quick"],
|
||||
"default": "full",
|
||||
"description": "Type of review to perform",
|
||||
"description": CODEREVIEW_FIELD_DESCRIPTIONS["review_type"],
|
||||
},
|
||||
"focus_on": {
|
||||
"type": "string",
|
||||
"description": (
|
||||
"Specific aspects to focus on, or additional context that would help understand "
|
||||
"areas of concern"
|
||||
),
|
||||
"description": CODEREVIEW_FIELD_DESCRIPTIONS["focus_on"],
|
||||
},
|
||||
"standards": {
|
||||
"type": "string",
|
||||
"description": "Coding standards to enforce",
|
||||
"description": CODEREVIEW_FIELD_DESCRIPTIONS["standards"],
|
||||
},
|
||||
"severity_filter": {
|
||||
"type": "string",
|
||||
"enum": ["critical", "high", "medium", "low", "all"],
|
||||
"default": "all",
|
||||
"description": "Minimum severity level to report",
|
||||
"description": CODEREVIEW_FIELD_DESCRIPTIONS["severity_filter"],
|
||||
},
|
||||
"temperature": {
|
||||
"type": "number",
|
||||
|
||||
172
tools/debug.py
172
tools/debug.py
@@ -14,22 +14,49 @@ from systemprompts import DEBUG_ISSUE_PROMPT
|
||||
|
||||
from .base import BaseTool, ToolRequest
|
||||
|
||||
# Field descriptions to avoid duplication between Pydantic and JSON schema
|
||||
DEBUG_FIELD_DESCRIPTIONS = {
|
||||
"prompt": (
|
||||
"Issue description. Include what you can provide: "
|
||||
"error messages, symptoms, when it occurs, steps to reproduce, environment details, "
|
||||
"recent changes, and any other relevant information. Mention any previous attempts at fixing this issue, "
|
||||
"including any past fix that was in place but has now regressed. "
|
||||
"The more context available, the better the analysis. "
|
||||
"SYSTEMATIC INVESTIGATION: Claude MUST begin by thinking hard and performing a thorough investigation using a systematic approach. "
|
||||
"First understand the issue, find the code that may be causing it or code that is breaking, as well as any related code that could have caused this as a side effect. "
|
||||
"Claude MUST maintain detailed investigation notes in a DEBUGGING_{issue_description}.md file within the project folder, "
|
||||
"updating it as it performs step-by-step analysis of the code, trying to determine the actual root cause and understanding how a minimal, appropriate fix can be found. "
|
||||
"This file MUST contain functions, methods, files visited OR determined to be part of the problem. Claude MUST update this and remove any references that it finds to be irrelevant during its investigation. "
|
||||
"Once complete, Claude MUST provide Zen's debug tool with this file passed into the files parameter. "
|
||||
"It is ESSENTIAL that this detailed work is performed by Claude before sharing all the relevant details with its development assistant. This will greatly help in zeroing in on the root cause."
|
||||
),
|
||||
"findings": (
|
||||
"Claude MUST first perform its own investigation, gather its findings and analysis. Include: steps taken to analyze the issue, "
|
||||
"code patterns discovered, initial hypotheses formed, any relevant classes/functions/methods examined, "
|
||||
"and any preliminary conclusions. This provides context for the assistant model's analysis."
|
||||
),
|
||||
"files": (
|
||||
"Essential files for debugging - ONLY include files that are directly related to the issue, "
|
||||
"contain the problematic code, or are necessary for understanding the root cause. "
|
||||
"This can include any relevant log files, error description documents, investigation documents, "
|
||||
"claude's own findings as a document, related code that may help with analysis."
|
||||
"DO NOT include every file scanned during investigation (must be absolute paths)."
|
||||
),
|
||||
"error_context": "Stack trace, snippet from logs, or additional error context. For very large text you MUST instead"
|
||||
"save the context as a temporary file within the project folder and share it as an absolute file path"
|
||||
"reference to the files parameter.",
|
||||
"images": "Optional images showing error screens, UI issues, logs displays, or visual debugging information",
|
||||
}
|
||||
|
||||
|
||||
class DebugIssueRequest(ToolRequest):
|
||||
"""Request model for debug tool"""
|
||||
|
||||
prompt: str = Field(..., description="Error message, symptoms, or issue description")
|
||||
error_context: Optional[str] = Field(None, description="Stack trace, logs, or additional error context")
|
||||
files: Optional[list[str]] = Field(
|
||||
None,
|
||||
description="Files or directories that might be related to the issue (must be absolute paths)",
|
||||
)
|
||||
images: Optional[list[str]] = Field(
|
||||
None,
|
||||
description="Optional images showing error screens, UI issues, logs displays, or visual debugging information",
|
||||
)
|
||||
runtime_info: Optional[str] = Field(None, description="Environment, versions, or runtime information")
|
||||
previous_attempts: Optional[str] = Field(None, description="What has been tried already")
|
||||
prompt: str = Field(..., description=DEBUG_FIELD_DESCRIPTIONS["prompt"])
|
||||
findings: Optional[str] = Field(None, description=DEBUG_FIELD_DESCRIPTIONS["findings"])
|
||||
files: Optional[list[str]] = Field(None, description=DEBUG_FIELD_DESCRIPTIONS["files"])
|
||||
error_context: Optional[str] = Field(None, description=DEBUG_FIELD_DESCRIPTIONS["error_context"])
|
||||
images: Optional[list[str]] = Field(None, description=DEBUG_FIELD_DESCRIPTIONS["images"])
|
||||
|
||||
|
||||
class DebugIssueTool(BaseTool):
|
||||
@@ -40,15 +67,35 @@ class DebugIssueTool(BaseTool):
|
||||
|
||||
def get_description(self) -> str:
|
||||
return (
|
||||
"DEBUG & ROOT CAUSE ANALYSIS - Expert debugging for complex issues with 1M token capacity. "
|
||||
"DEBUG & ROOT CAUSE ANALYSIS - Expert debugging for complex issues with systematic investigation support. "
|
||||
"Use this when you need to debug code, find out why something is failing, identify root causes, "
|
||||
"trace errors, or diagnose issues. "
|
||||
"IMPORTANT: Share diagnostic files liberally! The model can handle up to 1M tokens, so include: "
|
||||
"large log files, full stack traces, memory dumps, diagnostic outputs, multiple related files, "
|
||||
"entire modules, test results, configuration files - anything that might help debug the issue. "
|
||||
"Claude should proactively use this tool whenever debugging is needed and share comprehensive "
|
||||
"file paths rather than snippets. Include error messages, stack traces, logs, and ALL relevant "
|
||||
"code files as absolute paths. The more context, the better the debugging analysis. "
|
||||
"SYSTEMATIC INVESTIGATION WORKFLOW: "
|
||||
"Claude MUST begin by thinking hard and performing a thorough investigation using a systematic approach. "
|
||||
"First understand the issue, find the code that may be causing it or code that is breaking, as well as any related code that could have caused this as a side effect. "
|
||||
"Claude MUST maintain detailed investigation notes while it performs its analysis, "
|
||||
"updating it as it performs step-by-step analysis of the code, trying to determine the actual root cause and understanding how a minimal, appropriate fix can be found. "
|
||||
"This file MUST contain functions, methods, files visited OR determined to be part of the problem. Claude MUST update this and remove any references that it finds to be irrelevant during its investigation. "
|
||||
"Once complete, Claude MUST provide Zen's debug tool with this file passed into the files parameter. "
|
||||
"1. INVESTIGATE SYSTEMATICALLY: Claude MUST think and use a methodical approach to trace through error reports, "
|
||||
"examine code, and gather evidence step by step "
|
||||
"2. DOCUMENT FINDINGS: Maintain detailed investigation notes to "
|
||||
"keep the user informed during its initial investigation. This investigation MUST be shared with this tool for the assistant "
|
||||
"to be able to help more effectively. "
|
||||
"3. USE TRACER TOOL: For complex method calls, class references, or side effects use Zen's tracer tool and include its output as part of the "
|
||||
"prompt or additional context "
|
||||
"4. COLLECT EVIDENCE: Document important discoveries and validation attempts "
|
||||
"5. PROVIDE COMPREHENSIVE FINDINGS: Pass complete findings to this tool for expert analysis "
|
||||
"INVESTIGATION METHODOLOGY: "
|
||||
"- Start with error messages/symptoms and work backwards to root cause "
|
||||
"- Examine code flow and identify potential failure points "
|
||||
"- Use tracer tool for complex method interactions and dependencies if and as needed but continue with the investigation after using it "
|
||||
"- Test hypotheses against actual code and logs and confirm the idea holds "
|
||||
"- Document everything systematically "
|
||||
"ESSENTIAL FILES ONLY: Include only files (documents, code etc) directly related to the issue. "
|
||||
"Focus on quality over quantity for assistant model analysis. "
|
||||
"STRUCTURED OUTPUT: Assistant models return JSON responses with hypothesis "
|
||||
"ranking, evidence correlation, and actionable fixes. "
|
||||
"Choose thinking_mode based on issue complexity: 'low' for simple errors, "
|
||||
"'medium' for standard debugging (default), 'high' for complex system issues, "
|
||||
"'max' for extremely challenging bugs requiring deepest analysis. "
|
||||
@@ -61,30 +108,26 @@ class DebugIssueTool(BaseTool):
|
||||
"properties": {
|
||||
"prompt": {
|
||||
"type": "string",
|
||||
"description": "Error message, symptoms, or issue description",
|
||||
"description": DEBUG_FIELD_DESCRIPTIONS["prompt"],
|
||||
},
|
||||
"model": self.get_model_field_schema(),
|
||||
"error_context": {
|
||||
"findings": {
|
||||
"type": "string",
|
||||
"description": "Stack trace, logs, or additional error context",
|
||||
"description": DEBUG_FIELD_DESCRIPTIONS["findings"],
|
||||
},
|
||||
"files": {
|
||||
"type": "array",
|
||||
"items": {"type": "string"},
|
||||
"description": "Files or directories that might be related to the issue (must be absolute paths)",
|
||||
"description": DEBUG_FIELD_DESCRIPTIONS["files"],
|
||||
},
|
||||
"error_context": {
|
||||
"type": "string",
|
||||
"description": DEBUG_FIELD_DESCRIPTIONS["error_context"],
|
||||
},
|
||||
"images": {
|
||||
"type": "array",
|
||||
"items": {"type": "string"},
|
||||
"description": "Optional images showing error screens, UI issues, logs displays, or visual debugging information",
|
||||
},
|
||||
"runtime_info": {
|
||||
"type": "string",
|
||||
"description": "Environment, versions, or runtime information",
|
||||
},
|
||||
"previous_attempts": {
|
||||
"type": "string",
|
||||
"description": "What has been tried already",
|
||||
"description": DEBUG_FIELD_DESCRIPTIONS["images"],
|
||||
},
|
||||
"temperature": {
|
||||
"type": "number",
|
||||
@@ -164,15 +207,12 @@ class DebugIssueTool(BaseTool):
|
||||
# Build context sections
|
||||
context_parts = [f"=== ISSUE DESCRIPTION ===\n{request.prompt}\n=== END DESCRIPTION ==="]
|
||||
|
||||
if request.findings:
|
||||
context_parts.append(f"\n=== CLAUDE'S INVESTIGATION FINDINGS ===\n{request.findings}\n=== END FINDINGS ===")
|
||||
|
||||
if request.error_context:
|
||||
context_parts.append(f"\n=== ERROR CONTEXT/STACK TRACE ===\n{request.error_context}\n=== END CONTEXT ===")
|
||||
|
||||
if request.runtime_info:
|
||||
context_parts.append(f"\n=== RUNTIME INFORMATION ===\n{request.runtime_info}\n=== END RUNTIME ===")
|
||||
|
||||
if request.previous_attempts:
|
||||
context_parts.append(f"\n=== PREVIOUS ATTEMPTS ===\n{request.previous_attempts}\n=== END ATTEMPTS ===")
|
||||
|
||||
# Add relevant files if provided
|
||||
if request.files:
|
||||
# Use centralized file processing logic
|
||||
@@ -183,7 +223,9 @@ class DebugIssueTool(BaseTool):
|
||||
self._actually_processed_files = processed_files
|
||||
|
||||
if file_content:
|
||||
context_parts.append(f"\n=== RELEVANT CODE ===\n{file_content}\n=== END CODE ===")
|
||||
context_parts.append(
|
||||
f"\n=== ESSENTIAL FILES FOR DEBUGGING ===\n{file_content}\n=== END ESSENTIAL FILES ==="
|
||||
)
|
||||
|
||||
full_context = "\n".join(context_parts)
|
||||
|
||||
@@ -211,15 +253,55 @@ Focus on finding the root cause and providing actionable solutions."""
|
||||
|
||||
return full_prompt
|
||||
|
||||
def format_response(self, response: str, request: DebugIssueRequest, model_info: Optional[dict] = None) -> str:
|
||||
"""Format the debugging response"""
|
||||
# Get the friendly model name
|
||||
model_name = "the model"
|
||||
def _get_model_name(self, model_info: Optional[dict]) -> str:
|
||||
"""Extract friendly model name from model info."""
|
||||
if model_info and model_info.get("model_response"):
|
||||
model_name = model_info["model_response"].friendly_name or "the model"
|
||||
return model_info["model_response"].friendly_name or "the model"
|
||||
return "the model"
|
||||
|
||||
def _generate_systematic_next_steps(self, model_name: str) -> str:
|
||||
"""Generate next steps for systematic investigation completion."""
|
||||
return f"""**Expert Analysis Complete**
|
||||
|
||||
{model_name} has analyzed your systematic investigation findings.
|
||||
|
||||
**Next Steps:**
|
||||
1. **UPDATE INVESTIGATION DOCUMENT**: Add the expert analysis to your DEBUGGING_*.md file
|
||||
2. **REVIEW HYPOTHESES**: Examine the ranked hypotheses and evidence validation
|
||||
3. **IMPLEMENT FIXES**: Apply recommended minimal fixes in order of likelihood
|
||||
4. **VALIDATE CHANGES**: Test each fix thoroughly to ensure no regressions
|
||||
5. **DOCUMENT RESOLUTION**: Update investigation document with final resolution"""
|
||||
|
||||
def _generate_standard_analysis_steps(self, model_name: str) -> str:
|
||||
"""Generate next steps for standard analysis completion."""
|
||||
return f"""**Expert Analysis Complete**
|
||||
|
||||
{model_name} has analyzed your investigation findings.
|
||||
|
||||
**Next Steps:**
|
||||
1. **REVIEW HYPOTHESES**: Examine the ranked hypotheses and evidence
|
||||
2. **IMPLEMENT FIXES**: Apply recommended minimal fixes in order of likelihood
|
||||
3. **VALIDATE CHANGES**: Test each fix thoroughly to ensure no regressions"""
|
||||
|
||||
def _generate_general_analysis_steps(self, model_name: str) -> str:
|
||||
"""Generate next steps for general analysis responses."""
|
||||
return f"""**Analysis from {model_name}**
|
||||
|
||||
**Next Steps:** Continue your systematic investigation based on the guidance provided, then return
|
||||
with comprehensive findings for expert analysis."""
|
||||
|
||||
def format_response(self, response: str, request: DebugIssueRequest, model_info: Optional[dict] = None) -> str:
|
||||
"""Format the debugging response for Claude to present to user"""
|
||||
# The base class automatically handles structured responses like 'clarification_required'
|
||||
# and 'analysis_complete' via SPECIAL_STATUS_MODELS, so we only handle normal text responses here
|
||||
|
||||
model_name = self._get_model_name(model_info)
|
||||
|
||||
# For normal text responses, provide general guidance
|
||||
next_steps = self._generate_general_analysis_steps(model_name)
|
||||
|
||||
return f"""{response}
|
||||
|
||||
---
|
||||
|
||||
**Next Steps:** Evaluate {model_name}'s recommendations, synthesize the best fix considering potential regressions, and if the root cause has been clearly identified, proceed with implementing the potential fixes."""
|
||||
{next_steps}"""
|
||||
|
||||
@@ -284,20 +284,6 @@ class TraceComplete(BaseModel):
|
||||
state_access: Optional[list[StateAccess]] = Field(default_factory=list, description="State access information")
|
||||
|
||||
|
||||
# Registry mapping status strings to their corresponding Pydantic models
|
||||
SPECIAL_STATUS_MODELS = {
|
||||
"clarification_required": ClarificationRequest,
|
||||
"full_codereview_required": FullCodereviewRequired,
|
||||
"focused_review_required": FocusedReviewRequired,
|
||||
"test_sample_needed": TestSampleNeeded,
|
||||
"more_tests_required": MoreTestsRequired,
|
||||
"refactor_analysis_complete": RefactorAnalysisComplete,
|
||||
"trace_complete": TraceComplete,
|
||||
"resend_prompt": ResendPromptRequest,
|
||||
"code_too_large": CodeTooLargeRequest,
|
||||
}
|
||||
|
||||
|
||||
class DiagnosticHypothesis(BaseModel):
|
||||
"""A debugging hypothesis with context and next steps"""
|
||||
|
||||
@@ -321,3 +307,51 @@ class StructuredDebugResponse(BaseModel):
|
||||
default_factory=list,
|
||||
description="Additional files or information that would help with analysis",
|
||||
)
|
||||
|
||||
|
||||
class DebugHypothesis(BaseModel):
|
||||
"""A debugging hypothesis with detailed analysis"""
|
||||
|
||||
name: str = Field(..., description="Name/title of the hypothesis")
|
||||
confidence: Literal["High", "Medium", "Low"] = Field(..., description="Confidence level")
|
||||
root_cause: str = Field(..., description="Technical explanation of the root cause")
|
||||
evidence: str = Field(..., description="Logs or code clues supporting this hypothesis")
|
||||
correlation: str = Field(..., description="How symptoms map to the cause")
|
||||
validation: str = Field(..., description="Quick test to confirm the hypothesis")
|
||||
minimal_fix: str = Field(..., description="Smallest change to resolve the issue")
|
||||
regression_check: str = Field(..., description="Why this fix is safe")
|
||||
file_references: list[str] = Field(default_factory=list, description="File:line format for exact locations")
|
||||
|
||||
|
||||
class DebugAnalysisComplete(BaseModel):
|
||||
"""Complete debugging analysis with systematic investigation tracking"""
|
||||
|
||||
status: Literal["analysis_complete"] = "analysis_complete"
|
||||
investigation_id: str = Field(..., description="Auto-generated unique ID for this investigation")
|
||||
summary: str = Field(..., description="Brief description of the problem and its impact")
|
||||
investigation_steps: list[str] = Field(..., description="Steps taken during the investigation")
|
||||
hypotheses: list[DebugHypothesis] = Field(..., description="Ranked hypotheses with detailed analysis")
|
||||
key_findings: list[str] = Field(..., description="Important discoveries made during analysis")
|
||||
immediate_actions: list[str] = Field(..., description="Steps to take regardless of which hypothesis is correct")
|
||||
recommended_tools: list[str] = Field(default_factory=list, description="Additional tools recommended for analysis")
|
||||
prevention_strategy: Optional[str] = Field(
|
||||
None, description="Targeted measures to prevent this exact issue from recurring"
|
||||
)
|
||||
investigation_summary: str = Field(
|
||||
..., description="Comprehensive summary of the complete investigation process and conclusions"
|
||||
)
|
||||
|
||||
|
||||
# Registry mapping status strings to their corresponding Pydantic models
|
||||
SPECIAL_STATUS_MODELS = {
|
||||
"clarification_required": ClarificationRequest,
|
||||
"full_codereview_required": FullCodereviewRequired,
|
||||
"focused_review_required": FocusedReviewRequired,
|
||||
"test_sample_needed": TestSampleNeeded,
|
||||
"more_tests_required": MoreTestsRequired,
|
||||
"refactor_analysis_complete": RefactorAnalysisComplete,
|
||||
"trace_complete": TraceComplete,
|
||||
"resend_prompt": ResendPromptRequest,
|
||||
"code_too_large": CodeTooLargeRequest,
|
||||
"analysis_complete": DebugAnalysisComplete,
|
||||
}
|
||||
|
||||
@@ -30,6 +30,19 @@ from .base import BaseTool, ToolRequest
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
# Field descriptions to avoid duplication between Pydantic and JSON schema
|
||||
REFACTOR_FIELD_DESCRIPTIONS = {
|
||||
"files": "Code files or directories to analyze for refactoring opportunities (must be absolute paths)",
|
||||
"prompt": "Description of refactoring goals, context, and specific areas of focus",
|
||||
"refactor_type": "Type of refactoring analysis to perform",
|
||||
"focus_areas": "Specific areas to focus on (e.g., 'performance', 'readability', 'maintainability', 'security')",
|
||||
"style_guide_examples": (
|
||||
"Optional existing code files to use as style/pattern reference (must be absolute paths). "
|
||||
"These files represent the target coding style and patterns for the project."
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
class RefactorRequest(ToolRequest):
|
||||
"""
|
||||
Request model for the refactor tool.
|
||||
@@ -38,28 +51,14 @@ class RefactorRequest(ToolRequest):
|
||||
the refactoring analysis process.
|
||||
"""
|
||||
|
||||
files: list[str] = Field(
|
||||
...,
|
||||
description="Code files or directories to analyze for refactoring opportunities (must be absolute paths)",
|
||||
)
|
||||
prompt: str = Field(
|
||||
...,
|
||||
description="Description of refactoring goals, context, and specific areas of focus",
|
||||
)
|
||||
files: list[str] = Field(..., description=REFACTOR_FIELD_DESCRIPTIONS["files"])
|
||||
prompt: str = Field(..., description=REFACTOR_FIELD_DESCRIPTIONS["prompt"])
|
||||
refactor_type: Literal["codesmells", "decompose", "modernize", "organization"] = Field(
|
||||
..., description="Type of refactoring analysis to perform"
|
||||
)
|
||||
focus_areas: Optional[list[str]] = Field(
|
||||
None,
|
||||
description="Specific areas to focus on (e.g., 'performance', 'readability', 'maintainability', 'security')",
|
||||
..., description=REFACTOR_FIELD_DESCRIPTIONS["refactor_type"]
|
||||
)
|
||||
focus_areas: Optional[list[str]] = Field(None, description=REFACTOR_FIELD_DESCRIPTIONS["focus_areas"])
|
||||
style_guide_examples: Optional[list[str]] = Field(
|
||||
None,
|
||||
description=(
|
||||
"Optional existing code files to use as style/pattern reference (must be absolute paths). "
|
||||
"These files represent the target coding style and patterns for the project. "
|
||||
"Particularly useful for 'modernize' and 'organization' refactor types."
|
||||
),
|
||||
None, description=REFACTOR_FIELD_DESCRIPTIONS["style_guide_examples"]
|
||||
)
|
||||
|
||||
|
||||
@@ -92,30 +91,27 @@ class RefactorTool(BaseTool):
|
||||
"files": {
|
||||
"type": "array",
|
||||
"items": {"type": "string"},
|
||||
"description": "Code files or directories to analyze for refactoring opportunities (must be absolute paths)",
|
||||
"description": REFACTOR_FIELD_DESCRIPTIONS["files"],
|
||||
},
|
||||
"model": self.get_model_field_schema(),
|
||||
"prompt": {
|
||||
"type": "string",
|
||||
"description": "Description of refactoring goals, context, and specific areas of focus",
|
||||
"description": REFACTOR_FIELD_DESCRIPTIONS["prompt"],
|
||||
},
|
||||
"refactor_type": {
|
||||
"type": "string",
|
||||
"enum": ["codesmells", "decompose", "modernize", "organization"],
|
||||
"description": "Type of refactoring analysis to perform",
|
||||
"description": REFACTOR_FIELD_DESCRIPTIONS["refactor_type"],
|
||||
},
|
||||
"focus_areas": {
|
||||
"type": "array",
|
||||
"items": {"type": "string"},
|
||||
"description": "Specific areas to focus on (e.g., 'performance', 'readability', 'maintainability', 'security')",
|
||||
"description": REFACTOR_FIELD_DESCRIPTIONS["focus_areas"],
|
||||
},
|
||||
"style_guide_examples": {
|
||||
"type": "array",
|
||||
"items": {"type": "string"},
|
||||
"description": (
|
||||
"Optional existing code files to use as style/pattern reference (must be absolute paths). "
|
||||
"These files represent the target coding style and patterns for the project."
|
||||
),
|
||||
"description": REFACTOR_FIELD_DESCRIPTIONS["style_guide_examples"],
|
||||
},
|
||||
"thinking_mode": {
|
||||
"type": "string",
|
||||
|
||||
Reference in New Issue
Block a user