Tip: Separate planning from applying when you rename
Recommendation
Call plan_rename() first, inspect the RenamePlan it returns, and only call apply_rename() once you are satisfied with the proposed FileEdit hunks and FileMove entries.
Why it sticks: apply_rename() writes to disk and refreshes the corpus in one step — there is no dry-run flag, so the plan object is your only preview window.
Tradeoff: The plan reflects the corpus state at the moment you called plan_rename(). If the corpus changes between planning and applying — for example, another save flushes new templates — apply_rename() raises RenameError: File {...} drifted from the planned base; rebuild plan. You will need to rebuild the plan. Keep the gap between the two calls short.
How to use it
-
Compute the plan:
from attune_rag.editor import plan_rename, ReferenceKind plan = plan_rename(corpus, old="my-alias", new="better-alias", kind=ReferenceKind.ALIAS) -
Review what will change before committing:
import json print(json.dumps(plan.to_dict(), indent=2))plan.editslists everyFileEditwith its diffhunks;plan.moveslists anyFileMovepath changes. -
Apply only when the plan looks correct:
from attune_rag.editor import apply_rename changed_paths = apply_rename(corpus, plan)apply_rename()returns the list of paths it touched. If aRenameCollisionErroris raised, the proposednewname already exists somewhere in the corpus — pick a different name and rebuild the plan.
Source files
src/attune_rag/editor/rename.pysrc/attune_rag/editor/__init__.py
Tags: editor, rename, refactor, template