Forked from soumyajit7038/python-tools
Project Files
src / tools / editPythonFileByLine.ts
import { tool } from "@lmstudio/sdk";
import { z } from "zod";
import { editPythonFileByLine } from "../utils/pythonFileEditor";
import { getToolDefinition } from "../utils/toolRegistry";
const TOOL_DEFINITION = getToolDefinition("edit_python_file_by_line");
export const editPythonFileByLineTool = tool({
name: TOOL_DEFINITION.name,
description: TOOL_DEFINITION.description,
parameters: {
filePath: z.string().min(1).max(500).describe("Python file path relative to workspace or absolute inside workspace."),
operation: z
.enum(["replace", "insert_before", "insert_after", "delete"])
.describe("Line-based edit operation."),
startLine: z.number().int().min(1).describe("1-based start line."),
endLine: z.number().int().min(1).optional().describe("Optional 1-based end line. Defaults to startLine."),
content: z.string().optional().describe("New content used by replace and insert operations."),
backup: z.boolean().optional().describe("Whether to create a .bak backup file before editing. Defaults to true."),
},
implementation: async ({ filePath, operation, startLine, endLine, content, backup }) => {
return await editPythonFileByLine({
filePath,
operation,
startLine,
...(endLine !== undefined ? { endLine } : {}),
...(content !== undefined ? { content } : {}),
backup: backup ?? true,
});
},
});