Compare commits

..
2 Commits
Author SHA1 Message Date
moosecrap 6c33951c81 Symbolic link handling 2026-09-22 12:53:29 -07:00
moosecrap 73a06f3c94 Home directory handling 2026-09-22 12:51:28 -07:00
2 changed files with 30 additions and 12 deletions
+13 -4
View File
@@ -19,7 +19,7 @@ async def handle(args: Dict[str, Any]):
if not path_str: if not path_str:
raise ToolError("Missing path argument") raise ToolError("Missing path argument")
path = Path(path_str) path = Path(path_str).expanduser()
if not path.is_dir(): if not path.is_dir():
raise ToolError(f"{path_str} is not a directory.") raise ToolError(f"{path_str} is not a directory.")
@@ -48,17 +48,26 @@ async def handle(args: Dict[str, Any]):
output = [] output = []
for item in paged_items: for item in paged_items:
mtime_rel = format_relative_time(item["mtime"]) mtime_rel = format_relative_time(item["mtime"])
# Handle symbolic links in the display name
display_name = item["name"]
if item.get("is_link"):
target = item["target"]
is_broken = not item["path"].exists()
broken_str = " (BROKEN)" if is_broken else ""
display_name = f"{item['name']} -> {target}{broken_str}"
if item["is_dir"]: if item["is_dir"]:
try: try:
count = len(list(item["path"].iterdir())) count = len(list(item["path"].iterdir()))
info = f"{count} items" info = f"{count} items"
except: except:
info = "0 items" info = "0 items"
output.append(f"[DIR] {item['name']} | {info} | {mtime_rel}") output.append(f"[DIR] {display_name} | {info} | {mtime_rel}")
else: else:
size_kb = item["size"] / 1024 size_kb = item["size"] / 1024
output.append(f" {item['name']} | {size_kb:.1f}KB | {mtime_rel}") output.append(f" {display_name} | {size_kb:.1f}KB | {mtime_rel}")
header = f"Listing of {path_str}\nPage {effective_page} of {total_pages} ({total_items} total items). Showing {start_idx+1}-{min(end_idx, total_items)}." header = f"Listing of {path}\nPage {effective_page} of {total_pages} ({total_items} total items). Showing {start_idx+1}-{min(end_idx, total_items)}."
return [{"type": "text", "text": f"{header}\n\n" + "\n".join(output)}] return [{"type": "text", "text": f"{header}\n\n" + "\n".join(output)}]
+11 -2
View File
@@ -61,14 +61,23 @@ def get_file_info_list(path: Path, extensions: Optional[tuple] = None) -> List[D
if extensions and not entry.name.lower().endswith(extensions): if extensions and not entry.name.lower().endswith(extensions):
continue continue
stats = entry.stat() try:
stats = entry.lstat()
is_link = entry.is_symlink()
target = str(entry.readlink()) if is_link else None
items.append({ items.append({
"name": entry.name, "name": entry.name,
"path": entry, "path": entry,
"mtime": stats.st_mtime, "mtime": stats.st_mtime,
"size": stats.st_size, "size": stats.st_size,
"is_dir": entry.is_dir() "is_dir": entry.is_dir(),
"is_link": is_link,
"target": target
}) })
except Exception:
# Skip items that are completely inaccessible
continue
except Exception as e: except Exception as e:
raise ToolError(f"Error accessing directory {path}: {e}") raise ToolError(f"Error accessing directory {path}: {e}")