MCPcopy
hub / github.com/abi/screenshot-to-code / _create_file

Method _create_file

backend/agent/tools/runtime.py:98–129  ·  view source on GitHub ↗
(self, args: Dict[str, Any])

Source from the content-addressed store, hash-verified

96 )
97
98 def _create_file(self, args: Dict[str, Any]) -> ToolExecutionResult:
99 path = ensure_str(args.get("path") or self.file_state.path or "index.html")
100 content = ensure_str(args.get("content"))
101 if not content:
102 return ToolExecutionResult(
103 ok=False,
104 result={"error": "create_file requires non-empty content"},
105 summary={"error": "Missing content"},
106 )
107
108 extracted = extract_html_content(content)
109 self.file_state.path = path
110 self.file_state.content = extracted or content
111
112 summary = {
113 "path": self.file_state.path,
114 "contentLength": len(self.file_state.content),
115 "preview": summarize_text(self.file_state.content, 320),
116 }
117 result = {
118 "content": f"Successfully created file at {self.file_state.path}.",
119 "details": {
120 "path": self.file_state.path,
121 "contentLength": len(self.file_state.content),
122 },
123 }
124 return ToolExecutionResult(
125 ok=True,
126 result=result,
127 summary=summary,
128 updated_content=self.file_state.content,
129 )
130
131 @staticmethod
132 def _generate_diff(old_content: str, new_content: str, path: str) -> Dict[str, Any]:

Callers 1

executeMethod · 0.95

Calls 5

ensure_strFunction · 0.90
ToolExecutionResultClass · 0.90
extract_html_contentFunction · 0.90
summarize_textFunction · 0.90
getMethod · 0.80

Tested by

no test coverage detected