MCPcopy Create free account
hub / github.com/anus-dev/ANUS / getDirectoryContextString

Function getDirectoryContextString

packages/core/src/utils/environmentContext.ts:17–45  ·  view source on GitHub ↗
(
  config: Config,
)

Source from the content-addressed store, hash-verified

15 * @returns {Promise<string>} A promise that resolves to the directory context string.
16 */
17export async function getDirectoryContextString(
18 config: Config,
19): Promise<string> {
20 const workspaceContext = config.getWorkspaceContext();
21 const workspaceDirectories = workspaceContext.getDirectories();
22
23 const folderStructures = await Promise.all(
24 workspaceDirectories.map((dir) =>
25 getFolderStructure(dir, {
26 fileService: config.getFileService(),
27 }),
28 ),
29 );
30
31 const folderStructure = folderStructures.join('\n');
32
33 let workingDirPreamble: string;
34 if (workspaceDirectories.length === 1) {
35 workingDirPreamble = `I'm currently working in the directory: ${workspaceDirectories[0]}`;
36 } else {
37 const dirList = workspaceDirectories.map((dir) => ` - ${dir}`).join('\n');
38 workingDirPreamble = `I'm currently working in the following directories:\n${dirList}`;
39 }
40
41 return `${workingDirPreamble}
42Here is the folder structure of the current working directories:
43
44${folderStructure}`;
45}
46
47/**
48 * Retrieves environment-related information to be included in the chat context.

Callers 3

getEnvironmentContextFunction · 0.85
addDirectoryContextMethod · 0.85

Calls 4

getFolderStructureFunction · 0.85
getWorkspaceContextMethod · 0.80
getDirectoriesMethod · 0.80
getFileServiceMethod · 0.80

Tested by

no test coverage detected