�
Z�5i�B � �Z � d Z dZdZdZdZdZdZdZdZd Z d
Z
dZdZd
Z
dZdZdZdZdZdZdZdS )a`
Prompts for SGR (Schema-Guided Reasoning) code search.
Pipeline:
Step 0: Repo Context - understand repository
Step 1: Question Analysis - extract concepts
Step 2: Technical Terms - map concepts to code identifiers
Step 3: Search Planning - create search actions
Step 4: Result Interpretation - analyze results
Step 5: Final Answer - produce response
a/ You are a code repository analyst. Analyze the repository structure to understand:
1. PRIMARY LANGUAGE: What programming language is mainly used?
- Look at file extensions: .py (Python), .go (Go), .java (Java), .ts/.js (JavaScript/TypeScript)
- Check for package files: requirements.txt, go.mod, pom.xml, package.json
2. FRAMEWORK: What framework or library is this?
- Python web: Flask, FastAPI, Tornado, Pyramid
- JavaScript: Express, Koa, NestJS, React, Vue, Angular
- Go: Standard library, Echo, Fiber, Chi
- Java: Spring, Micronaut, Quarkus, Vert.x
- Or is it a standalone library/tool?
3. PROJECT TYPE:
- web_framework: HTTP server, REST API
- library: Reusable package/SDK
- cli_tool: Command-line application
- desktop_app: GUI application
- data_science: ML/Data processing
- game_engine: Graphics/Game
- other
4. KEY DIRECTORIES: Important folders for searching
- Look for: src/, lib/, core/, internal/, pkg/
- Look for: handlers/, controllers/, services/, models/
- Look for: utils/, helpers/, common/
5. FILE PATTERNS: Common patterns in this repo
- Test files: *_test.go, test_*.py, *.spec.ts
- Config files: *.yaml, *.json, *.toml
6. NAMING CONVENTIONS:
- snake_case vs camelCase vs PascalCase
- Prefix patterns: I for interfaces, _ for privatez�Repository path: {repo_path}
=== DIRECTORY STRUCTURE ===
{directory_listing}
{sample_files}
Based on the DETECTED information above, analyze this repository.
The file counts and dependencies are accurate - use them to determine the tech stack.a8 You are a code search expert analyzing a question about a codebase.
Your task: Extract HIGH-LEVEL CONCEPTS from the question.
Do NOT generate grep patterns yet - that's the next step.
Focus on understanding:
1. What CONCEPTS is the user asking about?
Examples of concepts (abstract ideas, not code):
- "authentication flow" - how users log in
- "caching mechanism" - how data is cached
- "event handling" - how events are processed
- "error propagation" - how errors bubble up
- "connection pooling" - how connections are reused
- "state management" - how state is stored/updated
- "request lifecycle" - how requests are processed
2. What PROBLEM is the user trying to solve?
- Summarize their goal in 1-2 sentences
3. What CODE do they need to find?
- Be specific: "the code that handles X"
4. What TYPE of question is this?
- how_it_works: Understanding implementation
- where_is_it: Finding specific code
- why_behavior: Explaining unexpected behavior
- how_to_use: API/usage questions
- debugging: Finding error handlingz_Repository: {repo_hint}
Question: {query}
Extract the concepts and intent from this question.u You are a code search expert generating search terms.
You have TWO sources of information:
1. The question concepts (what user wants to find)
2. ACTUAL directory/file structure from the repository
YOUR JOB: Match question concepts to REAL files/modules you see in the structure.
=== HOW TO EXTRACT TERMS ===
Look at the ACTUAL directory listing and extract terms from it:
1. FROM FOLDER NAMES:
- See "auth/" → use "auth" as search term
- See "cache/" → use "cache" as search term
- See "handlers/" → use "handler" as search term
- See "services/" → use "service" as search term
2. FROM FILE NAMES:
- See "user_manager.py" → use "user_manager", "Manager"
- See "connection_pool.go" → use "connection_pool", "Pool"
- See "EventBus.java" → use "EventBus", "Bus"
- See "rate_limiter.ts" → use "rate_limiter", "limiter"
3. FROM COMMON PATTERNS:
- Files ending in _service.py → search for "Service"
- Files ending in _handler.go → search for "Handler"
- Files ending in Controller.java → search for "Controller"
=== IMPORTANT RULES ===
DO NOT invent terms! Only use:
- Terms visible in the directory listing
- Common programming terms (service, handler, manager, factory, pool, cache)
- Keywords from the question itself
{naming_guide}u4 Repository: {repo_hint}
Primary language: {language}
All languages in repo: {languages_distribution}
Framework: {framework}
Question concepts: {concepts}
User wants to find: {what_to_find}
=== ACTUAL DIRECTORY STRUCTURE ===
{directory_structure}
=== FILES IN KEY DIRECTORIES ===
{files_listing}
TASK:
1. Look at the folder and file names above
2. Find names that relate to the question concepts
3. Use those names as search terms
4. Consider ALL languages - if question mentions bindings/wrappers, search in multiple language dirs
Example thought process:
- Question asks about "caching"
- I see "cache/" folder in the listing
- I'll use "cache" as a primary term
- I also see "redis_client.py" file
- I'll use "redis_client" as secondary term
- For "Python bindings" in C++ project → check both src/ and python/ap
Python naming conventions:
- Classes: PascalCase (UserManager, DataService, RequestHandler, CacheFactory)
- Functions/methods: snake_case (get_user, create_connection, process_request)
- Private: _underscore_prefix (_internal_state, _pool, _cache)
- Constants: UPPER_CASE (MAX_CONNECTIONS, DEFAULT_TIMEOUT)
- Modules: snake_case.py (user_service.py, data_manager.py)
a�
Go naming conventions:
- Exported (public): PascalCase (StartServer, HandleConnection, NewClient)
- Unexported (private): camelCase (parseRequest, validateInput, internalCache)
- Structs: PascalCase (Server, Client, Connection, Pool, Cache)
- Interfaces: PascalCase, often -er suffix (Reader, Writer, Handler, Processor)
- Files: lowercase.go or snake_case.go (server.go, http_client.go)
aS
Java naming conventions:
- Classes: PascalCase (UserController, OrderService, DataRepository)
- Interfaces: PascalCase, often I-prefix or -able suffix (IService, Cacheable)
- Methods: camelCase (findById, saveEntity, processRequest)
- Constants: UPPER_SNAKE_CASE (MAX_SIZE, DEFAULT_VALUE)
- Packages: lowercase.dots (com.example.service)
a6
Common naming patterns:
- Classes: Usually PascalCase (UserService, DataManager)
- Functions: camelCase or snake_case (getData, get_data)
- Private: underscore prefix (_private) or language modifier
- Constants: UPPER_CASE (MAX_VALUE)
- Common suffixes: Service, Manager, Handler, Factory, Pool, Cache, Store
a
Create a search plan using the technical terms identified.
You MUST create actions with ALL REQUIRED FIELDS filled in.
=== GREP ACTIONS ===
Search file contents. "pattern" is REQUIRED.
Fields:
- pattern: REQUIRED - regex to search (e.g., "QuerySet", "class.*Handler")
- path: optional - directory to search in
- glob: optional - file filter (e.g., "*.py")
- purpose: what you're looking for
=== READ_FILE ACTIONS ===
Read specific file. "file_path" is REQUIRED.
Fields:
- file_path: REQUIRED - path to file (e.g., "django/db/models/query.py")
- start_line/end_line: optional - line range
- purpose: why reading this file
=== LIST_DIR ACTIONS ===
Explore directory structure.
Fields:
- path: directory to list (default ".")
- max_depth: depth limit (default 2)
- purpose: what structure to discover
=== GLOB_SEARCH ACTIONS ===
Find files by name. "pattern" is REQUIRED.
Fields:
- pattern: REQUIRED - glob pattern (e.g., "*_handler.go", "*.qll")
- path: optional - directory to search in
- purpose: what files to find
=== STRATEGIES ===
- keyword_hunt: Search for unique terms directly (MOST COMMON)
- broad_to_narrow: Start wide, narrow down
- specific_file: Read known files directly
- structure_first: Explore directories first
- trace_flow: Follow code execution path
=== EXAMPLE OUTPUT ===
For question about "QuerySet lazy evaluation" with terms ["QuerySet", "_fetch_all", "query.py"]:
{{
"strategy": "keyword_hunt",
"grep_actions": [
{{
"pattern": "class QuerySet",
"path": "django/db/models/",
"purpose": "Find QuerySet class definition",
"expected_result": "Locate main QuerySet implementation"
}},
{{
"pattern": "_fetch_all|_result_cache",
"path": "django/db/models/",
"purpose": "Find lazy evaluation mechanism",
"expected_result": "Find where query results are cached"
}}
],
"read_file_actions": [
{{
"file_path": "django/db/models/query.py",
"purpose": "Read full QuerySet implementation",
"expected_result": "Understand __iter__ and lazy loading"
}}
],
"list_dir_actions": [],
"glob_search_actions": [],
"strategy_reasoning": "Using keyword_hunt because we have specific terms from the codebase"
}}
=== CRITICAL RULES ===
1. EVERY grep_actions item MUST have "pattern" filled in
2. EVERY read_file_actions item MUST have "file_path" filled in
3. EVERY glob_search_actions item MUST have "pattern" filled in
4. Use the PRIMARY terms provided - they come from actual files in the repo
5. Create 2-5 actions total across all action typesa� Question: {query}
=== TERMS TO USE (from actual repo files) ===
Primary terms: {primary_terms}
Secondary terms: {secondary_terms}
Regex patterns: {search_patterns}
=== LIKELY FILES/DIRECTORIES ===
{likely_files}
=== CONTEXT ===
Concepts: {concepts}
Question type: {question_type}
Create search actions. Remember:
- grep_actions MUST have "pattern"
- read_file_actions MUST have "file_path"
- glob_search_actions MUST have "pattern"
- Use the PRIMARY terms above as patternsa Create a search plan using the technical terms identified.
AVAILABLE TOOLS:
1. grep: Search file contents using regex pattern
REQUIRED params: {{"pattern": "<regex_pattern>"}}
OPTIONAL params: {{"path": "<dir>", "glob": "*.ext", "case_insensitive": true, "context_lines": 5, "files_only": true}}
Good patterns:
- Exact term: "ConnectionPool"
- Class definition: "class.*Service"
- Function definition: "def.*handle" or "func.*Process"
- Interface: "interface.*Handler"
- Import: "import.*cache"
2. read_file: Read file contents
REQUIRED params: {{"file_path": "<path>"}}
OPTIONAL params: {{"start_line": N, "end_line": M}}
3. list_dir: List directory structure
OPTIONAL params: {{"path": ".", "max_depth": 2}}
4. glob_search: Find files by name pattern
REQUIRED params: {{"pattern": "<glob_pattern>"}}
Examples: "*_service.py", "*Handler.java", "*_test.go"
STRATEGIES:
- keyword_hunt: Search for unique terms from the file listing
- broad_to_narrow: Start with folder name, then specific files
- structure_first: list_dir to find relevant folders
- specific_file: read_file if you know exact path
IMPORTANT:
- Start with PRIMARY terms - they came from actual files
- Use LIKELY FILES paths from the term extraction
- Create 1-5 initial actionsa Question: {query}
Technical Terms to search:
- Primary: {primary_terms}
- Secondary: {secondary_terms}
- Patterns: {search_patterns}
Likely files/directories: {likely_files}
Concepts: {concepts}
Question type: {question_type}
Create 1-5 search actions using the terms above.a Interpret the search result and decide next steps.
Analyze:
1. Did we find anything relevant to the question?
2. What are the key findings (files, functions, classes)?
3. What new search directions emerged?
4. How confident are we this is the right direction?
5. Do we need more searches or are we ready to answer?
EXTRACTING FINDINGS:
- Note COMPLETE file paths exactly as shown in the result (e.g., 'src/core/handlers/base.py' not just 'base.py')
- Note class/function names found
- Note any imports or references to other files
CONFIDENCE LEVELS:
- HIGH: Found the exact implementation, clear answer
- MEDIUM: Found related code, need to verify
- LOW: Found nothing or unrelated results
CRITICAL PATH REQUIREMENT:
- ALWAYS use the FULL file path including all directory prefixes
- NEVER shorten paths: use 'bin/hive-mind/memory.js' NOT 'memory.js'
- Copy the path EXACTLY as it appears in the search result
- Format findings as: 'full/path/to/file.py:line: description'
IMPORTANT:
- Be specific - mention exact file paths and function names
- If results are empty, suggest trying secondary terms
- Don't stop until you have concrete file pathsz�Question: {query}
Action executed: {tool}
Purpose: {purpose}
Parameters: {params}
Result:
{result}
Previous findings (last 5): {previous_findings}a� Generate a final answer based on the search results.
Include:
1. SUMMARY: Clear answer to the question (what code does what, where it is)
2. CODE LOCATIONS: Specific file paths with relevant functions/classes
3. REASONING CHAIN: Steps taken to find the answer
4. CONFIDENCE: How confident you are
5. POTENTIAL GAPS: What might have been missed
CRITICAL for CODE LOCATIONS (file_path field):
- Use COMPLETE file paths exactly as shown in the findings
- NEVER use just the filename: 'memory.js' is WRONG
- ALWAYS include directory prefix: 'bin/hive-mind/memory.js' is CORRECT
- Copy paths EXACTLY from the findings - do not shorten or modify them
- Only include files that were actually found in searches
- Include the relevant class/function names within each file
- Don't invent file paths that weren't in the findings
Example of CORRECT file_path: "src/core/handlers/base.py"
Example of WRONG file_path: "base.py" z�Question: {query}
Repository: {repo_hint}
Framework: {framework}
Technical terms searched: {technical_terms}
Search Iterations:
{iteration_summaries}
All Findings (last 25):
{findings}a� Decide whether to continue searching or generate the final answer.
Consider:
1. Have we found enough information to answer the question?
2. Are there promising leads we haven't followed?
3. Have we been searching too long without progress?
4. Did we reach HIGH confidence in any iteration?
CONTINUE SEARCHING if:
- Found file references but haven't read them
- Found a folder but haven't searched inside it
- Primary terms didn't work, try secondary terms
- Found imports pointing to other files
STOP SEARCHING if:
- Found the core implementation with HIGH confidence
- Searched 5+ iterations without progress
- All terms exhausted with no results
SPECIFYING NEXT ACTION - Use these FLAT FIELDS:
1. Set has_next_action=true
2. Set next_action_tool to one of: "grep", "read_file", "list_dir", "glob_search"
3. Fill the REQUIRED field for your tool:
For grep:
- grep_pattern: "your_search_term" (REQUIRED)
- grep_path: "src/core/" (optional)
For read_file:
- file_path: "src/handlers/base.py" (REQUIRED)
For list_dir:
- list_dir_path: "src/core/" (REQUIRED)
For glob_search:
- glob_pattern: "*.py" or "*handler*" (REQUIRED)
- glob_path: "src/" (optional)
4. Set next_action_purpose and next_action_expected
EXAMPLES:
- Grep for middleware: next_action_tool="grep", grep_pattern="middleware"
- Read a file: next_action_tool="read_file", file_path="src/handlers/base.py"
- List directory: next_action_tool="list_dir", list_dir_path="src/core/"
- Find files: next_action_tool="glob_search", glob_pattern="*handler*.py"
CRITICAL: If has_next_action=true, you MUST fill the required field or the action will fail!z�Question: {query}
Previous searches ({iteration_count} total):
{prev_summaries}
Current findings:
{findings}
Unexplored leads from previous iterations:
{unexplored_leads}
Iterations remaining: {remaining}N)�__doc__�REPO_CONTEXT_SYSTEM�REPO_CONTEXT_USER�QUESTION_ANALYSIS_SYSTEM�QUESTION_ANALYSIS_USER�TECHNICAL_TERMS_SYSTEM�TECHNICAL_TERMS_USER�NAMING_GUIDE_PYTHON�NAMING_GUIDE_GO�NAMING_GUIDE_JAVA�NAMING_GUIDE_DEFAULT�SEARCH_PLAN_SYSTEM�SEARCH_PLAN_USER�SEARCH_PLAN_SYSTEM_LEGACY�SEARCH_PLAN_USER_LEGACY�INTERPRET_RESULT_SYSTEM�INTERPRET_RESULT_USER�FINAL_ANSWER_SYSTEM�FINAL_ANSWER_USER�NEXT_ACTION_SYSTEM�NEXT_ACTION_USER� � �M/Users/mix0z/PycharmProjects/Semantic-Search-MCP/src/searchers/sgr/prompts.py�<module>r s� ��
�
� !9� �FY� �*� �<7� �$� �LJ� �:� ���� �� �L7� �\-� �,# � �J4� �&3� �< 3� � *� �*� �$.`� �`%� � � r