@adhdev/daemon-core 0.8.4 → 0.8.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -6915,6 +6915,37 @@ function resolveSafePath(requestedPath) {
6915
6915
  }
6916
6916
  return resolved;
6917
6917
  }
6918
+ function listDirectoryEntriesSafe(dirPath) {
6919
+ const entries = fs4.readdirSync(dirPath, { withFileTypes: true });
6920
+ const files = [];
6921
+ for (const entry of entries) {
6922
+ const entryPath = path6.join(dirPath, entry.name);
6923
+ try {
6924
+ if (entry.isDirectory()) {
6925
+ files.push({ name: entry.name, type: "directory" });
6926
+ continue;
6927
+ }
6928
+ if (entry.isFile()) {
6929
+ let size;
6930
+ try {
6931
+ size = fs4.statSync(entryPath).size;
6932
+ } catch {
6933
+ size = void 0;
6934
+ }
6935
+ files.push({ name: entry.name, type: "file", size });
6936
+ continue;
6937
+ }
6938
+ const stat = fs4.statSync(entryPath);
6939
+ files.push({
6940
+ name: entry.name,
6941
+ type: stat.isDirectory() ? "directory" : "file",
6942
+ size: stat.isFile() ? stat.size : void 0
6943
+ });
6944
+ } catch {
6945
+ }
6946
+ }
6947
+ return files;
6948
+ }
6918
6949
  async function handleFileRead(h, args) {
6919
6950
  try {
6920
6951
  const filePath = resolveSafePath(args?.path);
@@ -6937,19 +6968,20 @@ async function handleFileWrite(h, args) {
6937
6968
  async function handleFileList(h, args) {
6938
6969
  try {
6939
6970
  const dirPath = resolveSafePath(args?.path || ".");
6940
- const entries = fs4.readdirSync(dirPath, { withFileTypes: true });
6941
- const files = entries.map((e) => ({
6942
- name: e.name,
6943
- type: e.isDirectory() ? "directory" : "file",
6944
- size: e.isFile() ? fs4.statSync(path6.join(dirPath, e.name)).size : void 0
6945
- }));
6971
+ const files = listDirectoryEntriesSafe(dirPath);
6946
6972
  return { success: true, files, path: dirPath };
6947
6973
  } catch (e) {
6948
6974
  return { success: false, error: e.message };
6949
6975
  }
6950
6976
  }
6951
6977
  async function handleFileListBrowse(h, args) {
6952
- return handleFileList(h, args);
6978
+ try {
6979
+ const dirPath = resolveSafePath(args?.path || ".");
6980
+ const files = listDirectoryEntriesSafe(dirPath).filter((entry) => entry.type === "directory").sort((a, b) => a.name.localeCompare(b.name));
6981
+ return { success: true, files, path: dirPath };
6982
+ } catch (e) {
6983
+ return { success: false, error: e.message };
6984
+ }
6953
6985
  }
6954
6986
 
6955
6987
  // src/commands/stream-commands.ts