continue-custom/core/tools/implementations/lsTool.ts
Dallin Romney f58469ffc9 lstool
2025-04-02 13:48:50 -07:00

31 lines
840 B
TypeScript

import { ToolImpl } from ".";
import { walkDir } from "../../indexing/walkDir";
import { resolveRelativePathInDir } from "../../util/ideUtils";
export const lsToolImpl: ToolImpl = async (args, extras) => {
const uri = await resolveRelativePathInDir(args.dirPath, extras.ide);
if (!uri) {
throw new Error(
`Directory ${args.dirPath} not found. Make sure to use forward-slash paths. Do not use e.g. "."`,
);
}
const entries = await walkDir(uri, extras.ide, {
returnRelativeUrisPaths: true,
include: "both",
recursive: args.recursive ?? false,
});
const content =
entries.length > 0
? entries.join("\n")
: `No files/folders found in ${args.dirPath}`;
return [
{
name: "File/folder list",
description: `Files/folders in ${args.dirPath}`,
content,
},
];
};