MCPcopy Create free account
hub / github.com/OpenRaiser/NanoResearch / read_code_context

Function read_code_context

nanoresearch/agents/code_editor.py:104–124  ·  view source on GitHub ↗

Read all code files in the directory, return list of {path, content}.

(code_dir: Path)

Source from the content-addressed store, hash-verified

102
103
104def read_code_context(code_dir: Path) -> list[dict[str, str]]:
105 """Read all code files in the directory, return list of {path, content}."""
106 files: list[dict[str, str]] = []
107 for fp in sorted(code_dir.rglob("*")):
108 if not fp.is_file():
109 continue
110 if ".code_backups" in fp.parts or "__pycache__" in fp.parts:
111 continue
112 if fp.suffix not in _CODE_EXTENSIONS:
113 continue
114 try:
115 content = fp.read_text(encoding="utf-8", errors="replace")
116 if len(content) > _MAX_FILE_SIZE:
117 content = content[:_MAX_FILE_SIZE] + "\n... [truncated]"
118 files.append({
119 "path": str(fp.relative_to(code_dir)),
120 "content": content,
121 })
122 except Exception:
123 continue
124 return files
125
126
127def _format_code_context(files: list[dict[str, str]]) -> str:

Callers 3

code_editFunction · 0.90
preview_instructionMethod · 0.85
apply_instructionMethod · 0.85

Calls 2

read_textMethod · 0.80
appendMethod · 0.80

Tested by

no test coverage detected