Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions afs/local-fs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { globStream } from "glob";
import { z } from "zod";
import { searchWithRipgrep } from "./utils/ripgrep.js";

const LIST_MAX_LIMIT = 50;
const LIST_MAX_LIMIT = 1000;

export interface LocalFSOptions {
name?: string;
Expand Down Expand Up @@ -48,7 +48,8 @@ export class LocalFS implements AFSModule {
const limit = Math.min(options?.limit || LIST_MAX_LIMIT, LIST_MAX_LIMIT);
const basePath = join(this.options.localPath, path);

const pattern = options?.recursive ? "**/*" : "*";
const pattern =
options?.recursive || (options?.maxDepth && options.maxDepth > 1) ? "**/*" : "*";

const abortController = new AbortController();

Expand Down
42 changes: 36 additions & 6 deletions packages/core/src/prompt/skills/afs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,26 @@ export async function getAFSSkills(afs: AFS): Promise<Agent[]> {
FunctionAgent.from({
name: "afs_list",
description:
"Browse directory contents in the AFS like filesystem ls/tree command - shows files and folders in the specified path",
"Get a tree view of directory contents in the AFS - shows hierarchical structure of files and folders",
inputSchema: z.object({
path: z.string().describe("The directory path to browse (e.g., '/', '/docs', '/src')"),
options: z
.object({
recursive: z.boolean().optional().describe("Whether to list files recursively"),
maxDepth: z.number().optional().describe("Maximum depth to list files"),
limit: z.number().optional().describe("Maximum number of entries to return"),
maxDepth: z.number().optional().describe("Maximum depth to display in the tree view"),
})
.optional(),
}),
process: async (input) => {
const result = await afs.list(input.path, input.options);
const { list, message } = await afs.list(input.path, input.options);

const result = buildTreeView(list);

return {
status: "success",
tool: "afs_list",
options: input.options,
...result,
message,
result,
};
},
}),
Expand Down Expand Up @@ -122,3 +123,32 @@ export async function getAFSSkills(afs: AFS): Promise<Agent[]> {
}),
];
}

function buildTreeView(entries: { path: string }[]): string {
const tree: Record<string, any> = {};

for (const entry of entries) {
const parts = entry.path.split("/").filter(Boolean);
let current = tree;

for (const part of parts) {
if (!current[part]) {
current[part] = {};
}
current = current[part];
}
}

function renderTree(node: Record<string, any>, prefix = ""): string {
let result = "";
const keys = Object.keys(node);
keys.forEach((key, index) => {
const isLast = index === keys.length - 1;
result += `${prefix}${isLast ? "└── " : "├── "}${key}\n`;
result += renderTree(node[key], `${prefix}${isLast ? " " : "│ "}`);
});
return result;
}

return renderTree(tree);
}
12 changes: 2 additions & 10 deletions packages/core/test/prompt/prompt-builder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ test("PromptBuilder should build with afs correctly", async () => {
"tools": [
{
"function": {
"description": "Browse directory contents in the AFS like filesystem ls/tree command - shows files and folders in the specified path",
"description": "Get a tree view of directory contents in the AFS - shows hierarchical structure of files and folders",
"name": "afs_list",
"parameters": {
"$schema": "http://json-schema.org/draft-07/schema#",
Expand All @@ -669,18 +669,10 @@ test("PromptBuilder should build with afs correctly", async () => {
"options": {
"additionalProperties": false,
"properties": {
"limit": {
"description": "Maximum number of entries to return",
"type": "number",
},
"maxDepth": {
"description": "Maximum depth to list files",
"description": "Maximum depth to display in the tree view",
"type": "number",
},
"recursive": {
"description": "Whether to list files recursively",
"type": "boolean",
},
},
"required": [],
"type": "object",
Expand Down
14 changes: 3 additions & 11 deletions packages/core/test/prompt/skills/afs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,18 @@ test("getAFSSkills should return all AFS skills", async () => {
).toMatchInlineSnapshot(`
[
{
"description": "Browse directory contents in the AFS like filesystem ls/tree command - shows files and folders in the specified path",
"description": "Get a tree view of directory contents in the AFS - shows hierarchical structure of files and folders",
"inputSchema": {
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": true,
"properties": {
"options": {
"additionalProperties": false,
"properties": {
"limit": {
"description": "Maximum number of entries to return",
"type": "number",
},
"maxDepth": {
"description": "Maximum depth to list files",
"description": "Maximum depth to display in the tree view",
"type": "number",
},
"recursive": {
"description": "Whether to list files recursively",
"type": "boolean",
},
},
"type": "object",
},
Expand Down Expand Up @@ -193,10 +185,10 @@ test("AFS'skill list should invoke afs.list", async () => {
assert(list);
expect(await list.invoke({ path: "/foo/bar", options: { maxDepth: 2 } })).toMatchInlineSnapshot(`
{
"list": [],
"options": {
"maxDepth": 2,
},
"result": "",
"status": "success",
"tool": "afs_list",
}
Expand Down
Loading