list_files
Retrieve file structures from Alibaba Cloud Codeup repositories to navigate codebases, manage directories, and access project files using organization and repository identifiers.
Instructions
[Code Management] List file tree from a Codeup repository
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| organizationId | Yes | Organization ID, can be found in the basic information page of the organization admin console | |
| repositoryId | Yes | Repository ID or a combination of organization ID and repository name, for example: 2835387 or organizationId%2Frepo-name (Note: slashes need to be URL encoded as %2F) | |
| path | No | Specific path to query, for example to query files in the src/main directory | |
| ref | No | Reference name, usually branch name, can be branch name, tag name or commit SHA. If not provided, the default branch of the repository will be used, such as master | |
| type | No | File tree retrieval method: DIRECT - only get the current directory, default method; RECURSIVE - recursively find all files under the current path; FLATTEN - flat display (if it is a directory, recursively find until the subdirectory contains files or multiple directories) | RECURSIVE |
Implementation Reference
- tool-handlers/code-management.ts:125-137 (handler)Tool handler for 'list_files': parses arguments using ListFilesSchema and delegates to listFilesFunc, returns JSON stringified result.case "list_files": { const args = types.ListFilesSchema.parse(request.params.arguments); const fileList = await files.listFilesFunc( args.organizationId, args.repositoryId, args.path, args.ref, args.type ); return { content: [{ type: "text", text: JSON.stringify(fileList, null, 2) }], }; }
- tool-registry/code-management.ts:49-53 (registration)Registers the 'list_files' tool in the code-management registry with name, description, and input schema.{ name: "list_files", description: "[Code Management] List file tree from a Codeup repository", inputSchema: zodToJsonSchema(types.ListFilesSchema), },
- operations/codeup/types.ts:299-305 (schema)Defines the Zod input schema ListFilesSchema for the list_files tool parameters.export const ListFilesSchema = z.object({ organizationId: z.string().describe("Organization ID, can be found in the basic information page of the organization admin console"), repositoryId: z.string().describe("Repository ID or a combination of organization ID and repository name, for example: 2835387 or organizationId%2Frepo-name (Note: slashes need to be URL encoded as %2F)"), path: z.string().optional().describe("Specific path to query, for example to query files in the src/main directory"), ref: z.string().optional().describe("Reference name, usually branch name, can be branch name, tag name or commit SHA. If not provided, the default branch of the repository will be used, such as master"), type: z.string().default("RECURSIVE").optional().describe("File tree retrieval method: DIRECT - only get the current directory, default method; RECURSIVE - recursively find all files under the current path; FLATTEN - flat display (if it is a directory, recursively find until the subdirectory contains files or multiple directories)"), });
- operations/codeup/files.ts:263-314 (helper)Core helper function listFilesFunc that performs the API request to Codeup to list files/tree, handles repo ID encoding, builds URL with params, fetches and parses response.export async function listFilesFunc( organizationId: string, repositoryId: string, path?: string, ref?: string, type?: string // Possible values: DIRECT, RECURSIVE, FLATTEN ): Promise<z.infer<typeof FileInfoSchema>[]> { // 自动处理repositoryId中未编码的斜杠 let encodedRepoId = repositoryId; if (repositoryId.includes("/")) { // 发现未编码的斜杠,自动进行URL编码 const parts = repositoryId.split("/", 2); if (parts.length === 2) { const encodedRepoName = encodeURIComponent(parts[1]); // 移除编码中的+号(空格被编码为+,但我们需要%20) const formattedEncodedName = encodedRepoName.replace(/\+/g, "%20"); encodedRepoId = `${parts[0]}%2F${formattedEncodedName}`; } } const baseUrl = `/oapi/v1/codeup/organizations/${organizationId}/repositories/${encodedRepoId}/files/tree`; // 构建查询参数 const queryParams: Record<string, string | number | undefined> = {}; if (path) { queryParams.path = path; } if (ref) { queryParams.ref = ref; } if (type) { queryParams.type = type; } // 使用buildUrl函数构建包含查询参数的URL const url = buildUrl(baseUrl, queryParams); const response = await yunxiaoRequest(url, { method: "GET", }); // 确保响应是数组 if (!Array.isArray(response)) { return []; } // 解析每个文件信息对象 return response.map(fileInfo => FileInfoSchema.parse(fileInfo)); }