delete_lines
Remove specific line ranges from files in Godot projects to clean up code or remove unwanted sections by specifying start and end positions.
Instructions
Delete a range of lines from a file. Line numbers are 1-based.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Path to the file | |
| start | Yes | First line to delete (1-based) | |
| end | Yes | Last line to delete (1-based, inclusive) |
Implementation Reference
- src/tools/file-tools.ts:286-326 (handler)The implementation of the delete_lines tool, which reads a file, splits its content into lines, uses splice to remove the specified range, writes the updated content back, and emits a change event.
name: "delete_lines", description: "Delete a range of lines from a file. Line numbers are 1-based.", schema: { path: z.string().describe("Path to the file"), start: z.number().int().min(1).describe("First line to delete (1-based)"), end: z.number().int().min(1).describe("Last line to delete (1-based, inclusive)"), }, handler: async (ctx) => { const { path, start, end } = ctx.args; validatePath(path); try { const content = readFileSync(path, "utf-8"); const lines = content.split("\n"); if (start < 1 || end > lines.length || start > end) { return makeTextResponse({ error: `Invalid line range: ${start}-${end} (file has ${lines.length} lines)`, data: null, }); } const deleted = lines.splice(start - 1, end - start + 1); writeFileSync(path, lines.join("\n"), "utf-8"); await eventBus.emit("file:changed", { path, type: "modified", }); return makeTextResponse({ data: { deletedLines: deleted.length, path }, metadata: { source: "fallback" }, }); } catch (err) { return makeTextResponse({ error: `Failed to delete lines: ${(err as Error).message}`, data: null, }); } }, },