Skill Spotlight: Serena for Semantic Code Navigation and Refactors

Skill Spotlight: Serena for Semantic Code Navigation and Refactors

In Short

Use Serena for semantic code navigation when a refactor depends on understanding which symbol a caller actually references. Start with a definition and its callers, agree on one change, then inspect the diff and run focused checks. Repeated syntax changes may justify a separate codemod after the affected code is understood.

The official Serena repository describes symbol-level retrieval and editing exposed through MCP. Its current documentation also announces a v2 REPL interface, so follow setup instructions for your installed version rather than copying an older tool-call recipe. This spotlight proposes a starter workflow; it does not report a benchmark or a tested repository migration.

Who this is for

This article is for maintainers and coding-agent operators reviewing changes across an unfamiliar repository. A good first task is a private helper rename or a small API adaptation with known tests. Avoid making your first experiment a public API migration with downstream consumers you cannot inspect.

The useful output is a review packet: baseline commit, target symbol, affected paths, proposed patch, check results, and unresolved references. Put it beside the branch so another maintainer can reproduce the decision without reading the entire agent conversation.

Starter workflow

  1. Set the boundary. Create an isolated branch or worktree and record its baseline commit. Choose one package and one intended behavior. For example, adapt internal callers of validate(input) to accept an explicit rules object while preserving existing validation outcomes. List generated directories, dependencies, and unrelated packages as excluded paths.
  2. Prove navigation works. Configure Serena using the current upstream instructions for your client and language backend. Ask it to locate the target definition and one caller that you already know. Compare those answers with the files before trusting a broader reference inventory. Stop and repair project configuration if the known caller is missing.
  3. Build the reference inventory. Save the definition path, callers, tests, and import or export boundaries. Supplement semantic results with text searches for configuration keys, documentation, and dynamically constructed names. Classify each occurrence as intended to change, explicitly excluded, or requiring investigation. Treat unresolved references as open questions.
  4. Choose one edit mechanism. Use the available symbol-aware operation for a focused change. If many JavaScript or TypeScript sites need the same syntax transformation, consider a small jscodeshift transform instead. The official jscodeshift README documents parser selection and dry-run/print options. Preview only the approved paths; do not assume a recursive directory argument respects your exclusions automatically.
  5. Review before expanding. Inspect representative positive and negative examples: an intended call, a similarly named unrelated function, an alias, and a nested expression. If a template rewrite fits better, the official Comby repository demonstrates structural matching and describes interactive review. Require evidence that each matched shape belongs to the intended API.
  6. Validate and hand off. Apply the reviewed change locally, inspect the complete diff, and run the repository’s relevant tests and type checks. Recheck references to the old form. Record skipped checks and unexplained matches. Give the maintainer a patch and evidence before seeking approval to merge.
Stage Evidence to retain Stop condition
Locate symbols Definition and known caller Known reference missing
Trace references Scoped occurrence inventory Ownership unresolved
Preview changes Diff and negative examples Unrelated matches change
Test and review Check results and maintainer decision Behavior unverified
A text-based refactor review map: keep evidence at every handoff before widening the change.

Recommended ASE skills

What to watch

Symbol awareness does not establish behavioral equivalence. Reflection, string-based registration, external consumers, and generated code can leave gaps in a reference inventory. A clean rename or passing local test cannot resolve an uninspected downstream contract.

Keep the first pass small enough to inspect every changed hunk. Require an explanation when the actual file count differs from the preview. Save tool versions and parser settings with the patch, and investigate formatting churn that obscures the intended edit. These are proposed review controls, not guarantees supplied by any tool.

FAQ

Does Serena replace the coding agent?

No. Serena supplies tools; the agent still plans and coordinates the work. Give that agent a bounded objective and require reviewable evidence before expanding scope.

Should every refactor use a codemod?

No. Start with the smallest understandable edit. A codemod becomes useful when a repeated transformation has explicit matching rules and representative fixtures, including examples that must remain unchanged.

What should block the handoff?

Missing known references, unexplained diff changes, failing relevant checks, or an unresolved public contract should block acceptance. Record the exact uncertainty and the next check needed so the maintainer can make a concrete decision.