Make FS paths configurable

This commit is contained in:
Alex Gleason committed 2025-10-23 14:50:05 -05:00
1 parent f89a481c9c
commit d75bd386aa
43 files changed
+393 -124

No files matched your search

+7 -3
View File
@@ -15,6 +15,8 @@ interface TextEditorStrReplaceParams {
export class TextEditorStrReplaceTool implements Tool<TextEditorStrReplaceParams> {
private fs: JSRuntimeFS;
private cwd: string;
private projectsPath: string;
private tmpPath: string;
readonly description = "Replace a string in a file with a new string";
@@ -27,17 +29,19 @@ export class TextEditorStrReplaceTool implements Tool<TextEditorStrReplaceParams
),
});
constructor(fs: JSRuntimeFS, cwd: string) {
constructor(fs: JSRuntimeFS, cwd: string, options?: { projectsPath?: string; tmpPath?: string }) {
this.fs = fs;
this.cwd = cwd;
this.projectsPath = options?.projectsPath || '/projects';
this.tmpPath = options?.tmpPath || '/tmp';
}
async execute(args: TextEditorStrReplaceParams): Promise<string> {
const { path, old_str, new_str, normalize_whitespace = true } = args;
// Check write permissions
if (!isWriteAllowed(path, this.cwd)) {
throw new Error(createWriteAccessDeniedError(path, undefined, this.cwd));
if (!isWriteAllowed(path, this.cwd, { projectsPath: this.projectsPath, tmpPath: this.tmpPath })) {
throw new Error(createWriteAccessDeniedError(path, undefined, this.cwd, { projectsPath: this.projectsPath, tmpPath: this.tmpPath }));
}
// Ban editing dependencies in package.json
+5 -3
View File
@@ -13,6 +13,7 @@ interface TextEditorViewParams {
export class TextEditorViewTool implements Tool<TextEditorViewParams> {
private fs: JSRuntimeFS;
private cwd: string;
private projectsPath: string;
readonly description = "View the contents of a text file or directory";
@@ -28,9 +29,10 @@ export class TextEditorViewTool implements Tool<TextEditorViewParams> {
),
});
constructor(fs: JSRuntimeFS, cwd: string) {
constructor(fs: JSRuntimeFS, cwd: string, options?: { projectsPath?: string }) {
this.fs = fs;
this.cwd = cwd;
this.projectsPath = options?.projectsPath || '/projects';
}
async execute(args: TextEditorViewParams): Promise<string> {
@@ -52,9 +54,9 @@ export class TextEditorViewTool implements Tool<TextEditorViewParams> {
const stats = await this.fs.stat(absolutePath);
if (stats.isDirectory()) {
// Special handling for /projects directory - only show project directories, not their contents
// Special handling for projects directory - only show project directories, not their contents
const normalizedPath = absolutePath.replace(/\/$/, ''); // Remove trailing slash
if (normalizedPath === '/projects') {
if (normalizedPath === this.projectsPath) {
const tree = await this.generateDirectoryTree(absolutePath, "", 1); // Only show immediate children
return tree;
}
+7 -3
View File
@@ -13,6 +13,8 @@ interface TextEditorWriteParams {
export class TextEditorWriteTool implements Tool<TextEditorWriteParams> {
private fs: JSRuntimeFS;
private cwd: string;
private projectsPath: string;
private tmpPath: string;
readonly description = "Create or overwrite a file with new content";
@@ -23,17 +25,19 @@ export class TextEditorWriteTool implements Tool<TextEditorWriteParams> {
file_text: z.string().describe("Content to write to the file"),
});
constructor(fs: JSRuntimeFS, cwd: string) {
constructor(fs: JSRuntimeFS, cwd: string, options?: { projectsPath?: string; tmpPath?: string }) {
this.fs = fs;
this.cwd = cwd;
this.projectsPath = options?.projectsPath || '/projects';
this.tmpPath = options?.tmpPath || '/tmp';
}
async execute(args: TextEditorWriteParams): Promise<string> {
const { path, file_text } = args;
// Check write permissions
if (!isWriteAllowed(path, this.cwd)) {
throw new Error(createWriteAccessDeniedError(path, undefined, this.cwd));
if (!isWriteAllowed(path, this.cwd, { projectsPath: this.projectsPath, tmpPath: this.tmpPath })) {
throw new Error(createWriteAccessDeniedError(path, undefined, this.cwd, { projectsPath: this.projectsPath, tmpPath: this.tmpPath }));
}
if (