insert_in_body
Insert new code lines inside a function or method body at the top, bottom, before, or after a unique anchor, using symbol-targeted edits instead of brittle search-and-replace.
Instructions
Insert new_snippet inside a function's body. Set exactly one of at,
after or before. at="top" goes after a Python docstring,
at="bottom" at body level after the last statement, and in an empty
body one level deeper than the function; at is refused for a body on
its signature's line (use replace_function_body).
An anchor is matched as replace_in_body matches a snippet and must be
unique. One that ends its line (after) or starts it (before) gets
new_snippet on lines of its own; after a line that opens a block (if x:, if (x) {), new lines go inside the block. A mid-line anchor gets
new_snippet byte for byte.
Use this when: adding lines to a body. Don't use this when: replacing the whole body (replace_function_body), changing existing lines (replace_in_body), or adding a top-level symbol (add_top_level).
Example (both written without indentation): target="handle" new_snippet='auth_check(request)' before='validate(request)'
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| at | No | 'top' or 'bottom' of the body; '' (default) leaves this mode unused. Other values are refused. | |
| after | No | Anchor in the body to insert after; '' (default) leaves this mode unused. | |
| before | No | Anchor in the body to insert before; '' (default) leaves this mode unused. | |
| target | Yes | Function or method name as list_symbols lists it, dotted for nesting ('LRUCache.get'); overloads take parameter types ('A.m(int)'). | |
| file_path | Yes | Absolute path to the source or config file. | |
| new_snippet | Yes | Text to insert. With at, re-indented as a block to the body's indentation; with after or before, indented like the anchor (as written when already at the file's indentation there). |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |