Read a storage-backed text file, return empty string if missing.
(key: str, max_chars: int = 3000)
| 13 | settings = get_settings() |
| 14 | |
| 15 | async def _read_file_safe(key: str, max_chars: int = 3000) -> str: |
| 16 | """Read a storage-backed text file, return empty string if missing.""" |
| 17 | storage = get_storage_backend() |
| 18 | if not await storage.exists(key) or not await storage.is_file(key): |
| 19 | return "" |
| 20 | try: |
| 21 | content = (await storage.read_text(key, encoding="utf-8", errors="replace")).strip() |
| 22 | if len(content) > max_chars: |
| 23 | content = content[:max_chars] + "\n...(truncated)" |
| 24 | return content |
| 25 | except Exception: |
| 26 | return "" |
| 27 | |
| 28 | |
| 29 | def _parse_skill_frontmatter(content: str, filename: str) -> tuple[str, str]: |
no test coverage detected