Skip to content

Commit 5365ddc

Browse files
committed
Remove exists() from Runtime interface, use shared utility
Per review feedback, the Runtime interface should be minimal. The exists() method can be implemented as a utility function using stat(). Changes: - Remove exists() from Runtime interface - Remove implementations from LocalRuntime and SSHRuntime - Create fileExists() utility in src/utils/runtime/fileExists.ts - Update file_edit_insert.ts to use the utility function This keeps the Runtime interface minimal while providing the same functionality through a shared utility.
1 parent af2b330 commit 5365ddc

File tree

5 files changed

+19
-32
lines changed

5 files changed

+19
-32
lines changed

src/runtime/LocalRuntime.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -214,13 +214,4 @@ export class LocalRuntime implements Runtime {
214214
);
215215
}
216216
}
217-
218-
async exists(path: string): Promise<boolean> {
219-
try {
220-
await fs.access(path);
221-
return true;
222-
} catch {
223-
return false;
224-
}
225-
}
226217
}

src/runtime/Runtime.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,6 @@ export interface Runtime {
8585
* @throws RuntimeError if path does not exist or cannot be accessed
8686
*/
8787
stat(path: string): Promise<FileStat>;
88-
89-
/**
90-
* Check if path exists
91-
* @param path Absolute or relative path to check
92-
* @returns True if path exists, false otherwise
93-
*/
94-
exists(path: string): Promise<boolean>;
9588
}
9689

9790
/**

src/runtime/SSHRuntime.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -332,18 +332,4 @@ export class SSHRuntime implements Runtime {
332332
});
333333
});
334334
}
335-
336-
async exists(path: string): Promise<boolean> {
337-
await this.ensureConnected();
338-
339-
if (!this.sftpClient) {
340-
throw new RuntimeErrorClass("SFTP client not connected", "network");
341-
}
342-
343-
return new Promise((resolve) => {
344-
this.sftpClient!.stat(path, (err) => {
345-
resolve(!err);
346-
});
347-
});
348-
}
349335
}

src/services/tools/file_edit_insert.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { TOOL_DEFINITIONS } from "@/utils/tools/toolDefinitions";
66
import { validatePathInCwd, WRITE_DENIED_PREFIX } from "./fileCommon";
77
import { executeFileEditOperation } from "./file_edit_operation";
88
import { RuntimeError } from "@/runtime/Runtime";
9+
import { fileExists } from "@/utils/runtime/fileExists";
910

1011
/**
1112
* File edit insert tool factory for AI assistant
@@ -43,9 +44,9 @@ export const createFileEditInsertTool: ToolFactory = (config: ToolConfiguration)
4344
: path.resolve(config.cwd, file_path);
4445

4546
// Check if file exists using runtime
46-
const fileExists = await config.runtime.exists(resolvedPath);
47+
const exists = await fileExists(config.runtime, resolvedPath);
4748

48-
if (!fileExists) {
49+
if (!exists) {
4950
if (!create) {
5051
return {
5152
success: false,

src/utils/runtime/fileExists.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import type { Runtime } from "@/runtime/Runtime";
2+
3+
/**
4+
* Check if a path exists using runtime.stat()
5+
* @param runtime Runtime instance to use
6+
* @param path Path to check
7+
* @returns True if path exists, false otherwise
8+
*/
9+
export async function fileExists(runtime: Runtime, path: string): Promise<boolean> {
10+
try {
11+
await runtime.stat(path);
12+
return true;
13+
} catch {
14+
return false;
15+
}
16+
}

0 commit comments

Comments
 (0)