<note>Before making changes</note>
think_about_task_adherence
<note>When task seems complete</note>
think_about_whether_you_are_done
</example>
</concept>
</concepts>
<patterns>
<pattern name="explore_file">
<description>Systematically explore file structure from high-level to detailed</description>
<example>
<step>Step 1: Get top-level overview</step>
get_symbols_overview relative_path="src/main.ts" depth=0
<step>Step 2: Explore class members</step>
get_symbols_overview relative_path="src/main.ts" depth=1
<step>Step 3: Get specific implementation</step>
find_symbol name_path_pattern="MyClass/myMethod" include_body=true
</example>
</pattern>
<pattern name="trace_dependencies">
<description>Trace symbol dependencies and callers</description>
<example>
<step>Step 1: Locate the symbol</step>
find_symbol name_path_pattern="processData" relative_path="src/processor.ts"
<step>Step 2: Find all callers</step>
find_referencing_symbols name_path="processData" relative_path="src/processor.ts"
<step>Step 3: Recursively trace for full dependency graph</step>
<note>Repeat steps 1-2 for each caller to build complete dependency tree</note>
</example>
</pattern>
<pattern name="safe_refactoring">
<description>Refactor with full impact analysis</description>
<example>
<step>Step 1: Understand current implementation</step>
find_symbol name_path_pattern="MyClass/oldMethod" include_body=true
<step>Step 2: Identify all usages</step>
find_referencing_symbols name_path="MyClass/oldMethod" relative_path="src/myclass.ts"
<step>Step 3: Perform the change</step>
replace_symbol_body name_path="MyClass/oldMethod" relative_path="src/myclass.ts" body="..."
<step>Step 4: Update references if interface changed</step>
<note>If method signature changed, update all calling sites identified in step 2</note>
</example>
</pattern>
<pattern name="pattern_search">
<description>Search for patterns with appropriate scope</description>
<example>
<note>Search only in code files</note>
search_for_pattern substring_pattern="TODO:" restrict_search_to_code_files=true
<note>Search in all files including configs</note>
search_for_pattern substring_pattern="api-key" restrict_search_to_code_files=false
<note>Include context around matches</note>
search_for_pattern substring_pattern="function.\*async" context_lines_before=2 context_lines_after=3
</example>
</pattern>
<pattern name="memory_workflow">
<description>Use memories to maintain consistency across tasks</description>
<example>
<note>Before implementation</note>
list_memories # Check what patterns exist
read_memory "typescript-patterns" # Load relevant patterns
<note>During implementation</note>
<note>Follow the patterns loaded from memory</note>
<note>After implementation</note>
write_memory "api-client-pattern" "HTTP client pattern using fetch with retry logic..."
</example>
</pattern>
<decision_tree name="tool_selection"> <question>What type of operation is needed?</question> <branch condition="Symbol lookup">Use find_symbol with name_path_pattern</branch> <branch condition="File structure overview">Use get_symbols_overview with appropriate depth</branch> <branch condition="Find references">Use find_referencing_symbols</branch> <branch condition="Pattern search">Use search_for_pattern with regex</branch> <branch condition="Refactor symbol">Use replace_symbol_body</branch> <branch condition="Rename symbol">Use rename_symbol for consistent updates</branch> <branch condition="Add code">Use insert_before_symbol or insert_after_symbol</branch> <branch condition="Check patterns">Use list_memories then read_memory</branch> <branch condition="Record patterns">Use write_memory</branch> </decision_tree> </patterns>
<anti_patterns> <avoid name="reading_entire_files"> <description>Reading entire files when only specific symbols are needed</description> <instead>Use get_symbols_overview for file structure and find_symbol with include_body for specific implementations</instead> </avoid>
<avoid name="unscoped_searches"> <description>Searching entire codebase when scope is known</description> <instead>Use relative_path parameter to restrict search to known files or directories</instead> </avoid> <avoid name="ignoring_memories"> <description>Implementing features without checking existing patterns</description> <instead>Always check list_memories and read_memory before implementation</instead> </avoid> <avoid name="manual_refactoring"> <description>Manually updating symbol references across files</description> <instead>Use rename_symbol for consistent renaming with automatic reference updates</instead> </avoid> <avoid name="excessive_depth"> <description>Using high depth values unnecessarily in get_symbols_overview</description> <instead>Start with depth=0, then incrementally increase if needed</instead> </avoid> </anti_patterns> <workflow> <phase name="prepare"> <objective>Prepare for effective Serena tool usage</objective> <step>1. Check list_memories for existing patterns</step> <step>2. Identify target symbols or files</step> <step>3. Choose appropriate tool based on decision_tree</step> </phase> <phase name="execute"> <objective>Execute Serena operations efficiently</objective> <step>1. Start with get_symbols_overview for file structure</step> <step>2. Use find_symbol with include_body for details</step> <step>3. Use find_referencing_symbols for dependencies</step> </phase> <phase name="verify"> <objective>Verify results and record patterns</objective> <step>1. Call think_about_collected_information after searches</step> <step>2. Record new patterns with write_memory</step> <step>3. Call think_about_whether_you_are_done when complete</step> </phase> </workflow><best_practices> <practice priority="critical">Always check memories with list_memories and read_memory before implementing new features</practice> <practice priority="critical">Use symbol operations (get_symbols_overview, find_symbol) over reading entire files</practice> <practice priority="high">Restrict searches by relative_path when scope is known to improve performance</practice> <practice priority="high">Use substring_matching for uncertain symbol names to broaden search results</practice> <practice priority="high">Record new patterns and conventions with write_memory for future reference</practice> <practice priority="medium">Use context_lines parameters in search_for_pattern to understand surrounding code</practice> <practice priority="medium">Verify symbol changes with find_referencing_symbols before refactoring</practice> </best_practices>
<rules priority="critical"> <rule>Always check memories before implementing new features</rule> <rule>Use symbol operations over reading entire files</rule> <rule>Call think_about_collected_information after non-trivial search sequences</rule> <rule>Call think_about_task_adherence before making code changes</rule> </rules> <rules priority="standard"> <rule>Restrict searches by relative_path when scope is known</rule> <rule>Use substring_matching for uncertain symbol names</rule> <rule>Record new patterns with write_memory</rule> <rule>Call think_about_whether_you_are_done when task appears complete</rule> </rules><related_agents> <agent name="design">Uses Serena for architecture analysis and pattern discovery</agent> <agent name="code-quality">Uses Serena for complexity analysis and refactoring</agent> <agent name="bug">Uses Serena for tracing dependencies and impact analysis</agent> <agent name="execute">Uses Serena for symbol-level operations and memory management</agent> <agent name="security">Uses Serena for vulnerability detection and security pattern analysis</agent> <agent name="database">Uses Serena for schema analysis and query optimization</agent> <agent name="performance">Uses Serena for performance bottleneck identification and optimization</agent> <agent name="test">Uses Serena for test coverage analysis and test generation</agent> </related_agents>
<error_escalation> <level severity="low"> <example>Symbol not found with exact match</example> <action>Note in report, proceed</action> </level> <level severity="medium"> <example>Memory file not found</example> <action>Document issue, use AskUserQuestion for clarification</action> </level> <level severity="high"> <example>Conflicting information in memories</example> <action>STOP, present options to user</action> </level> <level severity="critical"> <example>Memory corruption or invalid state</example> <action>BLOCK operation, require explicit user acknowledgment</action> </level> </error_escalation>
<related_skills> <skill name="investigation-patterns">Investigation methodology using Serena tools</skill> <skill name="nix-ecosystem">Nix patterns stored in Serena memories</skill> <skill name="typescript-ecosystem">TypeScript patterns stored in Serena memories</skill> <skill name="golang-ecosystem">Go patterns stored in Serena memories</skill> <skill name="rust-ecosystem">Rust patterns stored in Serena memories</skill> <skill name="common-lisp-ecosystem">Common Lisp patterns stored in Serena memories</skill> <skill name="emacs-ecosystem">Emacs patterns stored in Serena memories</skill> </related_skills>
<constraints> <must>Check memories before implementing new features</must> <must>Use symbol operations over reading entire files</must> <must>Restrict searches by relative_path when scope is known</must> <avoid>Reading entire files when symbol operations suffice</avoid> <avoid>Unscoped searches across entire codebase</avoid> <avoid>Ignoring existing memory patterns</avoid> </constraints>
微信扫一扫