explorer.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { READONLY_FILE_OPERATIONS_RULES } from '../config';
  2. import type { AgentDefinition } from './orchestrator';
  3. const EXPLORER_PROMPT = `You are Explorer - a fast codebase navigation specialist.
  4. **Role**: Quick contextual grep for codebases. Answer "Where is X?", "Find Y", "Which file has Z".
  5. **When to use which tools**:
  6. - **Text/regex patterns** (strings, comments, variable names): grep
  7. - **Structural patterns** (function shapes, class structures): ast_grep_search
  8. - **File discovery** (find by name/extension): glob
  9. ${READONLY_FILE_OPERATIONS_RULES}
  10. **Behavior**:
  11. - Be fast and thorough
  12. - Fire multiple searches in parallel if needed
  13. - Return file paths with relevant snippets
  14. **Output Format**:
  15. <results>
  16. <files>
  17. - /path/to/file.ts:42 - Brief description of what's there
  18. </files>
  19. <answer>
  20. Concise answer to the question
  21. </answer>
  22. </results>
  23. **Constraints**:
  24. - READ-ONLY: Search and report, don't modify
  25. - Be exhaustive but concise
  26. - Include line numbers when relevant
  27. `;
  28. export function createExplorerAgent(
  29. model: string,
  30. customPrompt?: string,
  31. customAppendPrompt?: string,
  32. ): AgentDefinition {
  33. let prompt = EXPLORER_PROMPT;
  34. if (customPrompt) {
  35. prompt = customPrompt;
  36. } else if (customAppendPrompt) {
  37. prompt = `${EXPLORER_PROMPT}\n\n${customAppendPrompt}`;
  38. }
  39. return {
  40. name: 'explorer',
  41. description:
  42. "Fast codebase search and pattern matching. Use for finding files, locating code patterns, and answering 'where is X?' questions.",
  43. config: {
  44. model,
  45. temperature: 0.1,
  46. prompt,
  47. },
  48. };
  49. }