Forked from soumyajit7038/python-tools
Project Files
src / tools / editPythonFile.ts
import { tool } from "@lmstudio/sdk";
import { z } from "zod";
import { editPythonFile } from "../utils/pythonFileEditor";
import { getToolDefinition } from "../utils/toolRegistry";
const TOOL_DEFINITION = getToolDefinition("edit_python_file");
export const editPythonFileTool = tool({
name: TOOL_DEFINITION.name,
description: `${TOOL_DEFINITION.description} This performs exact string replacement and does not use regex.`,
parameters: {
filePath: z.string().min(1).max(500).describe("Python file path relative to workspace or absolute inside workspace."),
find: z.string().min(1).describe("Exact text to find."),
replace: z.string().describe("Replacement text."),
replaceAll: z.boolean().optional().describe("Whether to replace all matches (up to the configured safety limit)."),
backup: z.boolean().optional().describe("Whether to create a .bak backup file before editing. Defaults to true."),
},
implementation: async ({ filePath, find, replace, replaceAll, backup }) => {
return await editPythonFile({
filePath,
find,
replace,
replaceAll: replaceAll ?? false,
backup: backup ?? true,
});
},
});