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

Method execute

packages/core/src/tools/ls.ts:131–260  ·  view source on GitHub ↗

* Executes the LS operation with the given parameters * @returns Result of the LS operation

(_signal: AbortSignal)

Source from the content-addressed store, hash-verified

129 * @returns Result of the LS operation
130 */
131 async execute(_signal: AbortSignal): Promise<ToolResult> {
132 try {
133 const stats = fs.statSync(this.params.path);
134 if (!stats) {
135 // fs.statSync throws on non-existence, so this check might be redundant
136 // but keeping for clarity. Error message adjusted.
137 return this.errorResult(
138 `Error: Directory not found or inaccessible: ${this.params.path}`,
139 `Directory not found or inaccessible.`,
140 );
141 }
142 if (!stats.isDirectory()) {
143 return this.errorResult(
144 `Error: Path is not a directory: ${this.params.path}`,
145 `Path is not a directory.`,
146 );
147 }
148
149 const files = fs.readdirSync(this.params.path);
150
151 const defaultFileIgnores =
152 this.config.getFileFilteringOptions() ?? DEFAULT_FILE_FILTERING_OPTIONS;
153
154 const fileFilteringOptions = {
155 respectGitIgnore:
156 this.params.file_filtering_options?.respect_git_ignore ??
157 defaultFileIgnores.respectGitIgnore,
158 respectAnusIgnore:
159 this.params.file_filtering_options?.respect_anus_ignore ??
160 defaultFileIgnores.respectAnusIgnore,
161 };
162
163 // Get centralized file discovery service
164
165 const fileDiscovery = this.config.getFileService();
166
167 const entries: FileEntry[] = [];
168 let gitIgnoredCount = 0;
169 let anusIgnoredCount = 0;
170
171 if (files.length === 0) {
172 // Changed error message to be more neutral for LLM
173 return {
174 llmContent: `Directory ${this.params.path} is empty.`,
175 returnDisplay: `Directory is empty.`,
176 };
177 }
178
179 for (const file of files) {
180 if (this.shouldIgnore(file, this.params.ignore)) {
181 continue;
182 }
183
184 const fullPath = path.join(this.params.path, file);
185 const relativePath = path.relative(
186 this.config.getTargetDir(),
187 fullPath,
188 );

Callers

nothing calls this directly

Calls 7

errorResultMethod · 0.95
shouldIgnoreMethod · 0.95
getFileServiceMethod · 0.80
getTargetDirMethod · 0.80
shouldGitIgnoreFileMethod · 0.80
shouldAnusIgnoreFileMethod · 0.80

Tested by

no test coverage detected