insert_in_body
Insert a code snippet into a function or method body at the top, bottom, after an anchor, or before an anchor.
Instructions
Insert new_snippet inside a named function/method body. Pass EXACTLY ONE
of at, after, or before -- this one tool covers four placement
modes that used to be spread across three separate tools.
at="top": insert at the top of the body.
at="bottom": insert at the bottom of the body.
after=: insert immediately after a byte-identical anchor.
before=: insert immediately before a byte-identical anchor.
The anchor match (for after/before) is scoped to the target's body
and must be unique -- multiple matches raise an error telling you to
include more surrounding context. Caller is responsible for any
leading/trailing newlines and indentation in new_snippet.
Use this when: You're inserting new lines into a function body. Use
at="top"/at="bottom" for simple prepend/append, or after/before
for anchored insertion.
Don't use this when: You're replacing the whole body -> use
replace_function_body. You're adding a top-level symbol -> use
add_top_level. You're changing an existing snippet in the body ->
use replace_in_body.
Example (prepend): target="handle" new_snippet=' log("start")\n' at="top"
Example (append): target="handle" new_snippet=' log("end")\n' at="bottom"
Example (after anchor): target="handle" new_snippet=' metrics.incr("calls")\n' after=' validate(request)\n'
Example (before anchor): target="handle" new_snippet=' auth_check(request)\n' before=' validate(request)\n'
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | ||
| target | Yes | ||
| new_snippet | Yes | ||
| after | No | ||
| before | No | ||
| at | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |