MCPcopy
hub / github.com/dataelement/Clawith / _read_file_safe

Function _read_file_safe

backend/app/services/agent_context.py:15–26  ·  view source on GitHub ↗

Read a storage-backed text file, return empty string if missing.

(key: str, max_chars: int = 3000)

Source from the content-addressed store, hash-verified

13settings = get_settings()
14
15async 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
29def _parse_skill_frontmatter(content: str, filename: str) -> tuple[str, str]:

Callers 1

build_agent_contextFunction · 0.85

Calls 4

get_storage_backendFunction · 0.90
read_textMethod · 0.80
existsMethod · 0.45
is_fileMethod · 0.45

Tested by

no test coverage detected