| 58 | |
| 59 | // @spec WFD-001 — Configurable local workspace discovery |
| 60 | export function buildWorkspaceFileListCommand( |
| 61 | options: WorkspaceFileDiscovery, |
| 62 | ): string { |
| 63 | const patterns = options.excludedPatterns.map((pattern) => { |
| 64 | if (!pattern.includes("/")) return `-name ${shellQuote(pattern)}`; |
| 65 | const relative = pattern.startsWith("./") ? pattern : `./${pattern}`; |
| 66 | return `-path ${shellQuote(relative)}`; |
| 67 | }); |
| 68 | const prune = patterns.length |
| 69 | ? `-type d \\( ${patterns.join(" -o ")} \\) -prune -o ` |
| 70 | : ""; |
| 71 | const types = options.includeSymlinks |
| 72 | ? "\\( -type f -o \\( -type l -exec test -f {} \\; \\) \\)" |
| 73 | : "-type f"; |
| 74 | // Fetch one extra path to distinguish truncation from an exact-size result. |
| 75 | const limit = |
| 76 | options.maxFiles > 0 ? ` | head -n ${options.maxFiles + 1}` : ""; |
| 77 | return `find . ${prune}${types} -print 2>/dev/null | sort${limit}`; |
| 78 | } |
| 79 | |
| 80 | export function parseWorkspaceFileList(stdout: string, maxFiles: number) { |
| 81 | const paths = Array.from( |