CLI Reference
Commands
axm-anvil move
Move top-level symbols (classes, functions, constants) between Python
files atomically. Wraps the MoveTool MCP tool.
axm-anvil move <from_file> <to_file> <symbols> [--dry-run] [--check] [--path <root>] [--shared-helpers <strategy>] [--reexport] [--rename '<json>'] [--insert-after <symbol>] [--no-include-helpers] [--side-effect-decorators '<csv>']
| Argument | Description |
|---|---|
from_file |
Source Python file path |
to_file |
Target Python file path |
symbols |
Comma-separated symbol names to move |
--dry-run |
Preview the move without writing files |
--check |
Simulate the move, including import-cycle detection, without writing. Fails with ImportCycleError if the move would introduce a new cycle |
--path |
Workspace root (default: .) |
--shared-helpers |
Strategy when a helper is used by both moved and remaining symbols: duplicate (default, copies the helper and emits a warning) or error (abort with SharedHelpersError) |
--reexport |
Leave callers untouched; inject from new_module import <Symbol> # re-export for backwards compat into the source module for gradual migration |
--rename |
JSON object string mapping old symbol names to new ones (e.g. '{"OldName": "NewName"}'). Renames moved definitions and rewrites all caller references to the new name. Incompatible with --reexport |
--insert-after |
Name of an existing top-level symbol in the target module; moved blocks are spliced immediately after it. Omitted (default) appends the blocks at the end of the target; naming an absent symbol appends at the end and records a warning on MovePlan.warnings. Imports and constants keep their historical placement regardless |
--include-helpers / --no-include-helpers |
Whether to copy transitively-referenced local helpers and constants into the target. --include-helpers (default) preserves the historical copy behaviour. --no-include-helpers leaves the moved code referencing those helpers without copying them, short-circuits the --shared-helpers classification, and records a include_helpers=False: not copied into target: <names> warning on MovePlan.warnings. Imports required by the moved code are always copied regardless |
--side-effect-decorators |
Comma-separated extra side-effect decorator dotted-names (e.g. 'mylib.register') that extend the built-in SIDE_EFFECT_DECORATORS whitelist. When a moved symbol carries a matching decorator, a non-blocking warning is recorded on MovePlan.warnings; the move always proceeds |
MCP Tools
MoveTool
Registered as ast_move via the axm.tools entry point. Accepts the
same fields as the CLI and returns a ToolResult with the move plan
(moved symbols, copied imports/constants, warnings).
MoveTool
Bases: AXMTool
Move top-level symbols between Python files atomically.
Registered as ast_move via the axm.tools entry point.
Delegates to :func:axm_anvil.core.move.move_symbols and adapts
exceptions into ToolResult(success=False).
Source code in packages/axm-anvil/src/axm_anvil/tools/move.py
| Python | |
|---|---|
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | |
name
property
Return tool name for registry lookup.
execute(*, path='.', symbols='', from_file='', to_file='', dry_run=False, shared_helpers='duplicate', shared_helpers_module=None, reexport=False, rename=None, check=False, insert_after=None, include_helpers=True, side_effect_decorators=None, **kwargs)
Move symbols (CSV) from from_file to to_file.
Parameters
path:
Workspace root used to resolve relative from_file / to_file
and to constrain caller updates.
symbols:
Comma-separated list of top-level symbol names to move. Empty
entries are ignored.
from_file:
Source Python file. Relative paths are resolved against path.
to_file:
Target Python file. Relative paths are resolved against path.
dry_run:
When True, compute the :class:MovePlan without writing.
shared_helpers:
Policy for helpers used by both moved and remaining symbols:
"duplicate", "extract", or "error".
shared_helpers_module:
Target module path used when shared_helpers="extract".
reexport:
When True, leave callers untouched and inject a re-export in
the source module. Incompatible with rename.
rename:
Optional JSON object string mapping old symbol names to new ones
(e.g. '{"OldName": "NewName"}'). Parsed to dict[str, str]
and forwarded to :func:move_symbols. Invalid JSON yields a
success=False result.
insert_after:
Optional name of a top-level symbol in the target module; moved
blocks are spliced immediately after it. When None blocks
append at the end; an absent name appends at the end with a
warning.
include_helpers:
When True (default) transitively-referenced local helpers and
constants are copied into the target. When False they are not
copied (a warning enumerates the un-copied names); imports are
still copied regardless.
side_effect_decorators:
Optional comma-separated list of extra side-effect decorator
dotted-names that extend the built-in SIDE_EFFECT_DECORATORS
whitelist. A moved symbol decorated with a matching decorator
yields a non-blocking warning on the plan.
Returns
ToolResult
success=True with a MovePlan summary on success; otherwise
success=False with a message describing the failure
(missing symbol, collision, shared helpers, validation error).
Source code in packages/axm-anvil/src/axm_anvil/tools/move.py
| Python | |
|---|---|
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | |
Python API
move_symbols
move_symbols(source_path, target_path, symbol_names, dry_run=False, workspace_root=None, shared_helpers='duplicate', shared_helpers_module=None, reexport=False, rename=None, check=False, strict=False, insert_after=None, include_helpers=True, side_effect_decorators=None)
Move top-level symbols from source_path to target_path.
Pipeline: parse → expand overloads → extract blocks → gather deps →
build new target (imports + constants + symbols) → remove from source
→ classify shared helpers → validate parseability → atomic write via
batch_edit → ruff fix.
shared_helpers selects the strategy when a helper is used by both a
moved symbol and a remaining source symbol: "duplicate" copies and
keeps the helper (emitting a warning); "error" aborts with
:class:SharedHelpersError; "extract" is reserved for Phase 3.
When reexport=True, callers are left untouched and a
from new_module import <names> # re-export for backwards compat line
is appended to the source module. Incompatible with rename=.
When check=True, the move is simulated (no files written) and any
newly introduced import cycle raises :class:ImportCycleError. A
normal (non-dry_run) write also performs this check; dry_run=True
alone preserves its historical "preview without enforcement" contract.
A requested name that is absent from the source module's top-level
symbols is skipped with a warning on :attr:MovePlan.warnings
rather than aborting the whole plan. Pass strict=True to restore
the legacy behaviour of raising :class:SymbolNotFoundError on the
first absent name.
insert_after controls where the moved blocks land in the target
module body: when it names an existing top-level symbol the blocks are
spliced immediately after it; when None (default) the blocks append
at the end (unchanged contract); when it names an absent symbol the
blocks append at the end and a warning is added to
:attr:MovePlan.warnings. Imports and constants keep their historical
placement regardless of insert_after.
include_helpers (default True) preserves the historical
behaviour of copying transitively-referenced local helpers and
constants into the target. When False those helpers/constants are
not copied (the moved code is left referencing them), a warning
enumerating the un-copied local helper names is added to
:attr:MovePlan.warnings, and the shared_helpers classification is
short-circuited (nothing is duplicated or extracted). Imports required
by the moved code are always copied regardless of this flag.
Source code in packages/axm-anvil/src/axm_anvil/core/move.py
| Python | |
|---|---|
2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 | |
MovePlan
MovePlan
dataclass
Result of a :func:move_symbols call.
Carries the rendered source and target texts, the names that were
actually moved, and the direct dependencies (imports, constants)
copied into the target. warnings aggregates non-fatal issues
such as ruff post-processing errors.
Source code in packages/axm-anvil/src/axm_anvil/core/plan.py
SIDE_EFFECT_DECORATORS
SIDE_EFFECT_DECORATORS = frozenset({'app.route', 'app.get', 'app.post', 'app.put', 'app.delete', 'app.patch', 'router.get', 'router.post', 'router.put', 'router.delete', 'router.patch', 'pytest.fixture', 'fixture', 'celery.task', 'app.task', 'shared_task', 'click.command', 'click.group', 'singledispatch', 'functools.singledispatch'})
module-attribute
The default whitelist of decorator dotted-names whose primary purpose is to
register the decorated symbol with an external registry as an import-time
side effect (e.g. app.route, pytest.fixture / bare fixture,
celery.task, click.command). When a moved FunctionDef/ClassDef
carries a matching decorator — in bare (@fixture), dotted
(@pytest.fixture), or call (@app.route("/x")) form — move_symbols
records a non-blocking warning on MovePlan.warnings noting that
registration may not run in the new module. The move is never blocked.
Callers extend the whitelist via the side_effect_decorators parameter of
move_symbols (or --side-effect-decorators on the CLI);
supplied entries are unioned with these defaults.
CallerRewrite
CallerRewrite
dataclass
One entry per caller import line rewritten by move_symbols. Populated
into MovePlan.callers_updated so downstream tooling (CLI output, MCP
response) can report every from old_module import … line that was
redirected to the new module.
SharedHelpersError
SharedHelpersError
Bases: Exception
Raised in error mode when shared helpers would be duplicated.
Source code in packages/axm-anvil/src/axm_anvil/core/plan.py
Raised by move_symbols when shared_helpers="error"
and at least one helper is transitively referenced by both a moved block
and a remaining source symbol. The exception's shared_helpers attribute
lists the offending helper names.
ImportCycleError
ImportCycleError
Bases: Exception
Raised when a move would introduce a new import cycle.
Source code in packages/axm-anvil/src/axm_anvil/core/plan.py
Raised by move_symbols when the requested move (or the
associated caller rewrites) would introduce a new import cycle into the
containing package. Pre-existing cycles are ignored. The exception is
raised when check=True or during a normal (non-dry-run) write. Pure
dry_run=True calls skip the raise to preserve the existing preview
contract.
SymbolNotFoundError
SymbolNotFoundError
A requested name that is absent from the source module's top-level
symbols (for example a test_basic method declared inside a Test*
class, or a name that simply does not exist) is skipped by default:
move_symbols drops it from the move and records a
skipped '<name>': not a top-level symbol in source entry on
MovePlan.warnings. The CLI and the ast_move MCP tool surface that
warning and still exit successfully. Pass strict=True to restore the
legacy behaviour of raising SymbolNotFoundError on the first absent
name. Names that are present continue to move exactly as before.
Auto-generated API reference is available under Python API.