Serena
Use Serena as the first choice for understanding and editing existing codebases when the necessary tools are available.
What this skill is for
Use this skill when another agent needs to integrate Serena into its normal coding workflow instead of treating the repo as a pile of text files.
Aim for this behavior:
- - activate the project once
- inspect structure semantically before reading large files
- trace references before editing
- prefer symbol-scoped edits when possible
- fall back to normal file tools only when Serena is missing a capability or fails
For extra examples and trigger patterns, read references/integration-patterns.md.
Core workflow
- 1. Resolve the target project path.
- Call
serena_activate_project. - Start with structure discovery:
-
serena_project_overview
-
serena_find_symbol
-
serena_list_dir
-
serena_find_file
-
serena_session_status when you need to inspect active Serena sessions
- 4. Narrow scope with:
-
serena_find_references
-
serena_search_pattern
-
serena_read_symbol
-
serena_read_file
- 5. Prefer semantic edits when changing existing code:
-
serena_replace_symbol_body
-
serena_insert_before_symbol
-
serena_insert_after_symbol
-
serena_rename_symbol
- 6. Use broader edit tools only when symbol-scoped tools are not a good fit:
-
serena_replace_content
-
serena_create_text_file
- 7. Use
serena_execute_shell_command only as an advanced escape hatch when project-context shell execution is genuinely the right tool. - Use
serena_call_tool only when the normalized surface does not cover the needed Serena capability. - Fall back to ordinary file tools only when Serena cannot answer safely or reliably.
When Serena is worth the overhead
Prefer Serena when:
- - the project spans multiple files
- the user asks about references, call chains, or symbol relationships
- the user wants a precise edit to an existing class, function, method, or module
- reading whole files would be noisy or wasteful
- the repo already has real structure and semantic lookup is available
Skip or delay Serena when:
- - the task is a tiny one-file change and the target location is already obvious
- you are creating a brand-new file with little dependency on existing code
- Serena is unavailable or failing and direct file tools are simpler
- the user already provided the exact file region and semantic lookup adds no value
Tool preference order
For existing codebases, prefer this order:
- 1. INLINECODE19
- INLINECODE20 /
serena_find_symbol / INLINECODE22 - INLINECODE23 / INLINECODE24
- INLINECODE25 / INLINECODE26
- symbol-scoped edit tools
- broader Serena edit tools
- INLINECODE27 for session inspection/debugging
- INLINECODE28 only when semantic tools are not the right mechanism
- fallback to
read, edit, and exec only when needed
Integration guidance for agent authors
When you want another agent to use Serena well, instruct it to:
- - activate the project before semantic reads or edits
- inspect symbols and references before modifying code
- use normalized Serena tools first
- keep edits narrow and structured
- avoid whole-file rewrites when a symbol-scoped edit is possible
- treat passthrough as an escape hatch, not the default workflow
A good instruction pattern is:
Use Serena on the repo. Start with serena_activate_project, then narrow scope with serena_find_symbol, serena_find_references, and serena_read_symbol before editing.
Practical usage patterns
Understand a repo area
Use this sequence:
- 1. INLINECODE36
- INLINECODE37 or INLINECODE38
- INLINECODE39
- INLINECODE40
- INLINECODE41
Trace impact before changing code
Use this sequence:
- 1. INLINECODE42
- INLINECODE43
- INLINECODE44 if naming or text-level usage matters
- INLINECODE45 for the most relevant callers/callees
Make a targeted edit
Use this sequence:
- 1. locate the exact symbol
- read the symbol body
- inspect references if behavior changes could ripple outward
- choose the narrowest valid edit tool
- re-read the changed symbol or nearby references when confidence is low
Editing rules
- - Keep edits as narrow as possible.
- Prefer symbol-targeted edits over text replacement across a whole file.
- Prefer semantic rename over manual multi-file rename logic.
- Re-read the relevant symbol or references after a material edit when confidence is low.
- If semantic identity is ambiguous, do not guess; disambiguate using path or extra lookup.
- In read-only mode, do not attempt mutating Serena tools.
Safety and fallback behavior
If Serena fails:
- 1. Explain briefly what failed.
- Fall back to standard file-based workflow.
- Keep using the smallest possible read/edit scope.
- Do not pretend the semantic result was confirmed if it was not.
If a raw Serena passthrough tool is available:
- - use it only when the normalized tool surface does not cover the needed capability
- prefer stable normalized tools for repeated workflows
- avoid passthrough for routine actions that already have a clear normalized tool
Serena
在具备必要工具时,优先使用Serena来理解和编辑现有代码库。
该技能的用途
当其他智能体需要将Serena集成到其常规编码工作流中,而非将代码仓库视为一堆文本文件时,请使用此技能。
目标行为如下:
- - 一次性激活项目
- 在读取大文件前先进行语义结构检查
- 在编辑前先追踪引用
- 尽可能优先使用符号范围编辑
- 仅在Serena缺少某项能力或操作失败时,才回退到常规文件工具
更多示例和触发模式,请阅读references/integration-patterns.md。
核心工作流程
- 1. 解析目标项目路径。
- 调用serenaactivateproject。
- 从结构发现开始:
- serena
projectoverview
- serena
findsymbol
- serena
listdir
- serena
findfile
- 需要检查活跃的Serena会话时使用serena
sessionstatus
- 4. 使用以下工具缩小范围:
- serena
findreferences
- serena
searchpattern
- serena
readsymbol
- serena
readfile
- 5. 修改现有代码时优先使用语义编辑:
- serena
replacesymbol_body
- serena
insertbefore_symbol
- serena
insertafter_symbol
- serena
renamesymbol
- 6. 仅在符号范围工具不适用时使用更广泛的编辑工具:
- serena
replacecontent
- serena
createtext_file
- 7. 仅在项目上下文中执行shell命令确实是正确工具时,才使用serenaexecuteshellcommand作为高级逃生通道。
- 仅在标准化接口无法覆盖所需的Serena能力时,才使用serenacall_tool。
- 仅在Serena无法安全或可靠地回答时,才回退到普通文件工具。
何时值得使用Serena的开销
在以下情况下优先使用Serena:
- - 项目跨多个文件
- 用户询问关于引用、调用链或符号关系的问题
- 用户希望对现有类、函数、方法或模块进行精确编辑
- 读取整个文件会显得杂乱或浪费
- 代码仓库已有真实结构且语义查找可用
在以下情况下跳过或延迟使用Serena:
- - 任务是对单个小文件进行修改,且目标位置已明确
- 正在创建与现有代码依赖关系很少的全新文件
- Serena不可用或失败,直接使用文件工具更简单
- 用户已提供精确的文件区域,语义查找没有额外价值
工具优先级顺序
对于现有代码库,优先按此顺序:
- 1. serenaactivateproject
- serenaprojectoverview / serenafindsymbol / serenafindfile
- serenafindreferences / serenasearchpattern
- serenareadsymbol / serenareadfile
- 符号范围编辑工具
- 更广泛的Serena编辑工具
- serenasessionstatus用于会话检查/调试
- 仅在语义工具不是正确机制时使用serenaexecuteshell_command
- 仅在需要时回退到read、edit和exec
智能体作者集成指南
当您希望其他智能体良好使用Serena时,请指示它:
- - 在语义读取或编辑前激活项目
- 在修改代码前检查符号和引用
- 首先使用标准化的Serena工具
- 保持编辑范围狭窄且有结构
- 在可能进行符号范围编辑时避免全文件重写
- 将透传视为逃生通道,而非默认工作流
一个好的指令模式是:
在代码仓库上使用Serena。从serenaactivateproject开始,然后在编辑前使用serenafindsymbol、serenafindreferences和serenareadsymbol缩小范围。
实用使用模式
理解代码仓库区域
使用此序列:
- 1. serenaactivateproject
- serenafindfile或serenalistdir
- serenaprojectoverview
- serenafindsymbol
- serenareadsymbol
在修改代码前追踪影响
使用此序列:
- 1. serenafindsymbol
- serenafindreferences
- 如果命名或文本级使用重要,使用serenasearchpattern
- 对最相关的调用者/被调用者使用serenareadsymbol
进行目标编辑
使用此序列:
- 1. 定位精确符号
- 读取符号主体
- 如果行为变化可能向外扩散,检查引用
- 选择最窄的有效编辑工具
- 当信心不足时,重新读取已更改的符号或附近的引用
编辑规则
- - 保持编辑尽可能狭窄。
- 优先使用符号目标编辑而非整个文件的文本替换。
- 优先使用语义重命名而非手动多文件重命名逻辑。
- 在实质性编辑后信心不足时,重新读取相关符号或引用。
- 如果语义标识不明确,不要猜测;使用路径或额外查找进行消歧。
- 在只读模式下,不要尝试使用会修改数据的Serena工具。
安全与回退行为
如果Serena失败:
- 1. 简要说明失败原因。
- 回退到标准基于文件的工作流。
- 保持尽可能小的读取/编辑范围。
- 如果语义结果未被确认,不要假装已确认。
如果原始Serena透传工具可用:
- - 仅在标准化工具接口无法覆盖所需能力时使用
- 对于重复工作流,优先使用稳定的标准化工具
- 避免对已有明确标准化工具的常规操作使用透传