From ff3accdc7618acc78e15dd6ebf1989a9b3b0048a Mon Sep 17 00:00:00 2001 From: sebseb7 Date: Tue, 12 Aug 2025 04:19:25 +0000 Subject: [PATCH] Refactor file listing in list_files.js to return structured objects for easier machine parsing and consistent output. Update sorting mechanism to ensure files are sorted by path before returning. --- tools/list_files.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/list_files.js b/tools/list_files.js index 1b91466..7c5c97d 100644 --- a/tools/list_files.js +++ b/tools/list_files.js @@ -160,7 +160,8 @@ export async function run(args) { if (!includeHidden && fileName.startsWith(".")) { return { cwd, files: [] }; } - return { cwd, files: JSON.stringify([[fileName, 'f', stat.size]]) }; + // Return structured object for easier machine parsing + return { cwd, files: [{ path: fileName, type: 'f', size: stat.size }] }; } // Handle non-directory case @@ -171,9 +172,13 @@ export async function run(args) { // Handle directory case try { const files = await listEntriesRecursive(resolvedBase, chrootResolved, depth === -1 ? Infinity : depth, includeHidden); + // Map to structured objects and sort by path for consistent output + const mapped = files + .map(([p, t, s]) => ({ path: p, type: t, size: s })) + .sort((a, b) => a.path.localeCompare(b.path)); return { cwd, - files: files.sort((a, b) => a[0].localeCompare(b[0])), // Sort for consistent output + files: mapped, }; } catch (err) { return { err: `Failed to list files: ${err?.message || String(err)}` };