| 1 | # file_browser.py DOX |
| 2 | |
| 3 | ## Purpose |
| 4 | |
| 5 | - Own the `file_browser.py` helper module. |
| 6 | - This module builds safe file-browser views over allowed filesystem roots. |
| 7 | - Keep this file-level DOX profile synchronized with `file_browser.py` because this directory is intentionally flat. |
| 8 | |
| 9 | ## Ownership |
| 10 | |
| 11 | - `file_browser.py` owns the runtime implementation. |
| 12 | - `file_browser.py.dox.md` owns durable notes about responsibilities, contracts, side effects, and verification for that implementation. |
| 13 | - Classes: |
| 14 | - `FileBrowser` (no explicit base class) |
| 15 | - `save_file_b64(self, current_path: str, filename: str, base64_content: str)` |
| 16 | - `save_files(self, files: List, current_path: str=...) -> Tuple[List[str], List[str]]` |
| 17 | - `delete_file(self, file_path: str) -> bool` |
| 18 | - `rename_item(self, file_path: str, new_name: str) -> bool` |
| 19 | - `move_items(self, file_paths: List[str], destination_path: str) -> List[str]` |
| 20 | - `create_folder(self, parent_path: str, folder_name: str) -> bool` |
| 21 | - `save_text_file(self, file_path: str, content: str) -> bool` |
| 22 | - `get_files(self, current_path: str=...) -> Dict` |
| 23 | - `get_full_path(self, file_path: str, allow_dir: bool=...) -> str` |
| 24 | |
| 25 | ## Runtime Contracts |
| 26 | |
| 27 | - Helper modules own reusable framework APIs and must preserve public callers unless all callers, tests, and docs are updated together. |
| 28 | - Update this file whenever public functions, classes, persistence behavior, path/security assumptions, side effects, or cross-module contracts change. |
| 29 | - Observed side-effect areas: filesystem reads, filesystem writes, filesystem deletion, subprocess/runtime control, settings/state persistence. |
| 30 | - Imported dependency areas include: `base64`, `datetime`, `helpers`, `helpers.localization`, `helpers.print_style`, `helpers.security`, `os`, `pathlib`, `shutil`, `subprocess`, `typing`. |
| 31 | |
| 32 | ## Key Concepts |
| 33 | |
| 34 | - Important called helpers/classes observed in the source: `Path`, `files.get_abs_path`, `self._get_file_extension`, `file.seek`, `file.tell`, `resolve`, `os.makedirs`, `os.path.exists`, `full_path.with_name`, `new_path.exists`, `os.rename`, `target_dir.exists`, `filename.rsplit.lower`, `subprocess.run`, `result.stdout.strip.split`, `self._get_files_via_ls`, `files.exists`, `ValueError`, `str.startswith`, `file.write`. |
| 35 | - Multi-item moves validate every source and target before renaming, reject collisions and directory self-nesting, preserve symlink objects, and best-effort roll back earlier renames if a later rename fails. |
| 36 | - Keep request/response, tool, or helper semantics documented here at the same time as source changes. |
| 37 | |
| 38 | ## Work Guidance |
| 39 | |
| 40 | - Preserve public helper APIs used by core code and plugins unless every caller is updated. |
| 41 | - Keep path, auth, secret, persistence, network, and subprocess behavior explicit and bounded. |
| 42 | - Prefer adding cohesive helper functions here only when behavior is reused across modules. |
| 43 | |
| 44 | ## Verification |
| 45 | |
| 46 | - Run targeted tests for changed helper behavior; run security regressions for auth, filesystem, WebSocket, tunnel, upload, or secret-handling helpers. |
| 47 | - Related tests observed by source search: |
| 48 | - `tests/test_download_toast_regressions.py` |
| 49 | - `tests/test_office_document_store.py` |
| 50 | - `tests/test_file_browser_navigation.py` |
| 51 | |
| 52 | ## Child DOX Index |
| 53 | |
| 54 | No child DOX files. |