in codex-cli/src/utils/file-system-suggestions.ts [20:59]
export function getFileSystemSuggestions(
pathPrefix: string,
): Array<FileSystemSuggestion> {
if (!pathPrefix) {
return [];
}
try {
const sep = path.sep;
const hasTilde = pathPrefix === "~" || pathPrefix.startsWith("~" + sep);
const expanded = hasTilde
? path.join(os.homedir(), pathPrefix.slice(1))
: pathPrefix;
const normalized = path.normalize(expanded);
const isDir = pathPrefix.endsWith(path.sep);
const base = path.basename(normalized);
const dir =
normalized === "." && !pathPrefix.startsWith("." + sep) && !hasTilde
? process.cwd()
: path.dirname(normalized);
const readDir = isDir ? path.join(dir, base) : dir;
return fs
.readdirSync(readDir)
.filter((item) => isDir || item.startsWith(base))
.map((item) => {
const fullPath = path.join(readDir, item);
const isDirectory = fs.statSync(fullPath).isDirectory();
return {
path: isDirectory ? path.join(fullPath, sep) : fullPath,
isDirectory,
};
});
} catch {
return [];
}
}