From 7934d152deee9018f6f306cac24c745eec902781 Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 10 Aug 2025 21:19:43 -0400 Subject: [PATCH] address feedback --- src/tools/edit.test.ts | 3 ++- src/tools/multiEdit.ts | 13 ++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/tools/edit.test.ts b/src/tools/edit.test.ts index 8dbb5e2fc..1ad8f7d23 100644 --- a/src/tools/edit.test.ts +++ b/src/tools/edit.test.ts @@ -2,7 +2,7 @@ import * as fs from "fs"; import { describe, it, expect, beforeEach, afterEach, vi } from "vitest"; -import { editTool, markFileAsRead } from "./edit.js"; +import { editTool, markFileAsRead, readFilesSet } from "./edit.js"; // Mock the dependencies vi.mock("../telemetry/telemetryService.js"); @@ -38,6 +38,7 @@ describe("editTool", () => { afterEach(() => { vi.clearAllMocks(); + readFilesSet.clear(); }); describe("preprocess", () => { diff --git a/src/tools/multiEdit.ts b/src/tools/multiEdit.ts index 566599f94..de46e00f6 100644 --- a/src/tools/multiEdit.ts +++ b/src/tools/multiEdit.ts @@ -1,4 +1,5 @@ import * as fs from "fs"; +import * as path from "path"; import { telemetryService } from "../telemetry/telemetryService.js"; import { @@ -6,7 +7,7 @@ import { getLanguageFromFilePath, } from "../telemetry/utils.js"; -import { readFilesSet } from "./edit.js"; +import { readFilesSet, markFileAsRead } from "./edit.js"; import { Tool } from "./types.js"; import { generateDiff } from "./writeFile.js"; @@ -132,6 +133,9 @@ If you want to create a new file, use: if (!file_path) { throw new Error("file_path is required"); } + if (!path.isAbsolute(file_path)) { + throw new Error("file_path must be an absolute path"); + } if (!edits || !Array.isArray(edits) || edits.length === 0) { throw new Error( "edits array is required and must contain at least one edit", @@ -159,7 +163,7 @@ If you want to create a new file, use: if (isCreatingNewFile) { // For new file creation, check if parent directory exists - const parentDir = file_path.substring(0, file_path.lastIndexOf("/")); + const parentDir = path.dirname(file_path); if (parentDir && !fs.existsSync(parentDir)) { throw new Error(`Parent directory does not exist: ${parentDir}`); } @@ -282,8 +286,3 @@ If you want to create a new file, use: } }, }; - -// Export function to mark file as read (to maintain consistency with edit tool) -export function markFileAsRead(filePath: string) { - readFilesSet.add(filePath); -}