MCPcopy
hub / github.com/Doorman11991/smallcode / getSmartListing

Function getSmartListing

src/tools/file_tree.js:163–176  ·  view source on GitHub ↗

* Get a ranked file listing for injection into the model. * * @param {string} rootDir - Directory to list * @param {string} taskHint - User task for bonus scoring * @param {object} opts * @param {number} opts.max - Max files to return (default SMALLCODE_FILETREE_MAX)

(rootDir, taskHint, opts = {})

Source from the content-addressed store, hash-verified

161 * @param {number} opts.max - Max files to return (default SMALLCODE_FILETREE_MAX)
162 */
163function getSmartListing(rootDir, taskHint, opts = {}) {
164 const max = opts.max || MAX_FILES;
165 const entries = scoredFileListing(rootDir, taskHint, opts);
166
167 let sorted;
168 if (SORT_MODE === 'mtime') {
169 sorted = entries.sort((a, b) => b.mtime - a.mtime);
170 } else {
171 // score desc, then mtime desc as tiebreaker
172 sorted = entries.sort((a, b) => b.score !== a.score ? b.score - a.score : b.mtime - a.mtime);
173 }
174
175 return sorted.slice(0, max);
176}
177
178/**
179 * Format a file listing for the model. Returns a compact string.

Callers

nothing calls this directly

Calls 1

scoredFileListingFunction · 0.85

Tested by

no test coverage detected