import fs from "fs"; import { RojoTool, RojoToolContext } from "./RojoTool"; import { resolveProjectPath } from "../../storage"; export class ListFilesTool extends RojoTool { readonly Definition = { type: "function", function: { name: "list_files", description: "List the files and subdirectories inside a directory.", parameters: { type: "object", properties: { path: { type: "string", description: "Path relative to the project root." }, }, required: [ "path" ], }, }, }; async execute( args: Record, ctx: RojoToolContext ): Promise { const full = resolveProjectPath( ctx.projectId, args.path as string ); if ( !full ) return { error: "Invalid path" }; if ( !fs.existsSync( full ) ) return { error: "Directory does not exist" }; const entries = fs.readdirSync( full, { withFileTypes: true } ); return entries.map( e => ( { name: e.name, type: e.isDirectory() ? "directory" : "file" } ) ); } }