Read file content. Args: path: Path to file (relative to workspace or absolute) Returns: File content as string Raises: FilesystemAccessError: If file cannot be read
(self, path: Union[str, Path])
| 131 | ) |
| 132 | |
| 133 | def read(self, path: Union[str, Path]) -> str: |
| 134 | """ |
| 135 | Read file content. |
| 136 | |
| 137 | Args: |
| 138 | path: Path to file (relative to workspace or absolute) |
| 139 | |
| 140 | Returns: |
| 141 | File content as string |
| 142 | |
| 143 | Raises: |
| 144 | FilesystemAccessError: If file cannot be read |
| 145 | """ |
| 146 | try: |
| 147 | path = self._validate_path(path) |
| 148 | |
| 149 | if not path.exists(): |
| 150 | raise FilesystemAccessError(f"File not found: {path}") |
| 151 | |
| 152 | if not path.is_file(): |
| 153 | raise FilesystemAccessError(f"Not a file: {path}") |
| 154 | |
| 155 | content = path.read_text(encoding='utf-8') |
| 156 | try: |
| 157 | rel = path.relative_to(self.workspace) |
| 158 | except ValueError: |
| 159 | rel = path |
| 160 | info(f"Read {rel} ({len(content)} chars)") |
| 161 | return content |
| 162 | |
| 163 | except FilesystemAccessError: |
| 164 | raise |
| 165 | except Exception as e: |
| 166 | raise FilesystemAccessError(f"Failed to read {path}: {e}") |
| 167 | |
| 168 | def write(self, path: Union[str, Path], content: str) -> str: |
| 169 | """ |