diff --git a/core/context/providers/FolderContextProvider.ts b/core/context/providers/FolderContextProvider.ts
index 42df6ab34..b4d2e0e09 100644
--- a/core/context/providers/FolderContextProvider.ts
+++ b/core/context/providers/FolderContextProvider.ts
@@ -35,7 +35,7 @@ class FolderContextProvider extends BaseContextProvider {
const folders = await walkDirs(
args.ide,
{
- onlyDirs: true,
+ include: "dirs",
source: "load submenu items - folder",
},
workspaceDirs,
diff --git a/core/context/providers/RepoMapContextProvider.ts b/core/context/providers/RepoMapContextProvider.ts
index 6a2db46fa..575e7af4b 100644
--- a/core/context/providers/RepoMapContextProvider.ts
+++ b/core/context/providers/RepoMapContextProvider.ts
@@ -54,7 +54,7 @@ class RepoMapContextProvider extends BaseContextProvider {
const folders = await walkDirs(
args.ide,
{
- onlyDirs: true,
+ include: "dirs",
source: "load submenu items - repo map",
},
workspaceDirs,
diff --git a/core/indexing/walkDir.test.ts b/core/indexing/walkDir.test.ts
index 399a24875..50acba4ed 100644
--- a/core/indexing/walkDir.test.ts
+++ b/core/indexing/walkDir.test.ts
@@ -97,7 +97,7 @@ describe("walkDir functions", () => {
);
});
- it("should handle onlyDirs option", async () => {
+ it("should handle include option", async () => {
addToTestDir([
"src/",
["src/file1.ts", "content1"],
@@ -109,7 +109,7 @@ describe("walkDir functions", () => {
(await testIde.getWorkspaceDirs())[0],
testIde,
{
- onlyDirs: true,
+ include: "dirs",
},
);
diff --git a/core/indexing/walkDir.ts b/core/indexing/walkDir.ts
index 2c70006a8..04e45a3ca 100644
--- a/core/indexing/walkDir.ts
+++ b/core/indexing/walkDir.ts
@@ -10,10 +10,11 @@ import {
} from "./ignore";
export interface WalkerOptions {
- onlyDirs?: boolean;
+ include?: "dirs" | "files" | "both";
returnRelativeUrisPaths?: boolean;
source?: string;
overrideDefaultIgnores?: Ignore;
+ recursive?: boolean;
}
type Entry = [string, FileType];
@@ -195,7 +196,7 @@ class DFSWalker {
if (this.entryIsDirectory(entry)) {
relPath = `${relPath}/`;
} else {
- if (this.options.onlyDirs) {
+ if (this.options.include === "dirs") {
continue;
}
}
@@ -221,19 +222,22 @@ class DFSWalker {
}
if (this.entryIsDirectory(entry)) {
- stack.push({
- walkableEntry,
- ignoreContexts,
- });
- if (this.options.onlyDirs) {
- // when onlyDirs is enabled the walker will only return directory names
+ if (this.options.recursive) {
+ stack.push({
+ walkableEntry,
+ ignoreContexts,
+ });
+ }
+ if (this.options.include !== "files") {
+ // if yielding dirs or both, walker includes relative paths
+ const trailingSlash = this.options.include === "dirs" ? "" : "/";
if (this.options.returnRelativeUrisPaths) {
- yield walkableEntry.relativeUriPath;
+ yield walkableEntry.relativeUriPath + trailingSlash;
} else {
- yield walkableEntry.uri;
+ yield walkableEntry.uri + trailingSlash;
}
}
- } else {
+ } else if (this.options.include !== "dirs") {
if (this.options.returnRelativeUrisPaths) {
yield walkableEntry.relativeUriPath;
} else {
@@ -257,8 +261,9 @@ class DFSWalker {
}
const defaultOptions: WalkerOptions = {
- onlyDirs: false,
+ include: "files",
returnRelativeUrisPaths: false,
+ recursive: true,
};
export async function* walkDirAsync(
diff --git a/core/tools/builtIn.ts b/core/tools/builtIn.ts
index 268cbb9a8..fa76358c9 100644
--- a/core/tools/builtIn.ts
+++ b/core/tools/builtIn.ts
@@ -3,10 +3,14 @@ export enum BuiltInToolNames {
ReadCurrentlyOpenFile = "builtin_read_currently_open_file",
CreateNewFile = "builtin_create_new_file",
RunTerminalCommand = "builtin_run_terminal_command",
- ViewSubdirectory = "builtin_view_subdirectory",
- ViewRepoMap = "builtin_view_repo_map",
ExactSearch = "builtin_exact_search",
SearchWeb = "builtin_search_web",
ViewDiff = "builtin_view_diff",
+ LSTool = "builtin_ls",
+
+ // excluded from allTools for now
+ ViewRepoMap = "builtin_view_repo_map",
+ ViewSubdirectory = "builtin_view_subdirectory",
}
+
export const BUILT_IN_GROUP_NAME = "Built-In";
diff --git a/core/tools/callTool.ts b/core/tools/callTool.ts
index 8d4b1f1b3..25c56507c 100644
--- a/core/tools/callTool.ts
+++ b/core/tools/callTool.ts
@@ -5,13 +5,12 @@ import { BuiltInToolNames } from "./builtIn";
import { createNewFileImpl } from "./implementations/createNewFile";
import { exactSearchImpl } from "./implementations/exactSearch";
+import { lsToolImpl } from "./implementations/lsTool";
import { readCurrentlyOpenFileImpl } from "./implementations/readCurrentlyOpenFile";
import { readFileImpl } from "./implementations/readFile";
import { runTerminalCommandImpl } from "./implementations/runTerminalCommand";
import { searchWebImpl } from "./implementations/searchWeb";
import { viewDiffImpl } from "./implementations/viewDiff";
-import { viewRepoMapImpl } from "./implementations/viewRepoMap";
-import { viewSubdirectoryImpl } from "./implementations/viewSubdirectory";
async function callHttpTool(
url: string,
@@ -149,12 +148,14 @@ export async function callTool(
return await searchWebImpl(args, extras);
case BuiltInToolNames.ViewDiff:
return await viewDiffImpl(args, extras);
- case BuiltInToolNames.ViewRepoMap:
- return await viewRepoMapImpl(args, extras);
- case BuiltInToolNames.ViewSubdirectory:
- return await viewSubdirectoryImpl(args, extras);
+ case BuiltInToolNames.LSTool:
+ return await lsToolImpl(args, extras);
case BuiltInToolNames.ReadCurrentlyOpenFile:
return await readCurrentlyOpenFileImpl(args, extras);
+ // case BuiltInToolNames.ViewRepoMap:
+ // return await viewRepoMapImpl(args, extras);
+ // case BuiltInToolNames.ViewSubdirectory:
+ // return await viewSubdirectoryImpl(args, extras);
default:
return await callToolFromUri(uri, args, extras);
}
diff --git a/core/tools/definitions/lsTool.ts b/core/tools/definitions/lsTool.ts
new file mode 100644
index 000000000..6b6e96498
--- /dev/null
+++ b/core/tools/definitions/lsTool.ts
@@ -0,0 +1,33 @@
+import { Tool } from "../..";
+
+import { BUILT_IN_GROUP_NAME, BuiltInToolNames } from "../builtIn";
+
+export const lsTool: Tool = {
+ type: "function",
+ displayTitle: "LS Tool",
+ wouldLikeTo: "list files and folders in {{{ dirPath }}}",
+ isCurrently: "listing files and folders in {{{ dirPath }}}",
+ hasAlready: "listed files and folders in {{{ dirPath }}}",
+ readonly: true,
+ group: BUILT_IN_GROUP_NAME,
+ function: {
+ name: BuiltInToolNames.LSTool,
+ description: "List files and folders in a given directory",
+ parameters: {
+ type: "object",
+ required: ["dirPath", "recursive"],
+ properties: {
+ dirPath: {
+ type: "string",
+ description:
+ "The directory path relative to the root of the project. Always use forward slash paths like '/'. rather than e.g. '.'",
+ },
+ recursive: {
+ type: "boolean",
+ description:
+ "If true, lists files and folders recursively. To prevent unexpected large results, use this sparingly",
+ },
+ },
+ },
+ },
+};
diff --git a/core/tools/implementations/lsTool.ts b/core/tools/implementations/lsTool.ts
new file mode 100644
index 000000000..4a7f8bcb5
--- /dev/null
+++ b/core/tools/implementations/lsTool.ts
@@ -0,0 +1,31 @@
+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,
+ },
+ ];
+};
diff --git a/core/tools/index.ts b/core/tools/index.ts
index c27860a6f..eea4ee79b 100644
--- a/core/tools/index.ts
+++ b/core/tools/index.ts
@@ -1,21 +1,24 @@
import { createNewFileTool } from "./definitions/createNewFile";
import { exactSearchTool } from "./definitions/exactSearch";
+import { lsTool } from "./definitions/lsTool";
import { readCurrentlyOpenFileTool } from "./definitions/readCurrentlyOpenFile";
import { readFileTool } from "./definitions/readFile";
import { runTerminalCommandTool } from "./definitions/runTerminalCommand";
import { searchWebTool } from "./definitions/searchWeb";
import { viewDiffTool } from "./definitions/viewDiff";
-import { viewRepoMapTool } from "./definitions/viewRepoMap";
-import { viewSubdirectoryTool } from "./definitions/viewSubdirectory";
export const allTools = [
readFileTool,
createNewFileTool,
runTerminalCommandTool,
- viewSubdirectoryTool,
- viewRepoMapTool,
+
exactSearchTool,
searchWebTool,
viewDiffTool,
readCurrentlyOpenFileTool,
+
+ lsTool,
+ // replacing with ls tool for now
+ // viewSubdirectoryTool,
+ // viewRepoMapTool,
];
diff --git a/gui/src/components/mainInput/Lump/sections/SelectedSection.tsx b/gui/src/components/mainInput/Lump/sections/SelectedSection.tsx
index 28dc37c28..4b133e77d 100644
--- a/gui/src/components/mainInput/Lump/sections/SelectedSection.tsx
+++ b/gui/src/components/mainInput/Lump/sections/SelectedSection.tsx
@@ -4,7 +4,7 @@ import { MCPSection } from "./MCPSection";
import { ModelsSection } from "./ModelsSection";
import { PromptsSection } from "./PromptsSection";
import { RulesSection } from "./RulesSection";
-import { ToolsSection } from "./ToolsSection";
+import { ToolPoliciesSection } from "./tool-policies/ToolPoliciesSection";
interface SelectedSectionProps {
selectedSection: string | null;
@@ -23,7 +23,7 @@ export function SelectedSection(props: SelectedSectionProps) {
case "context":
return