MCPcopy Create free account
hub / github.com/Ishabdullah/Codey-v2 / write

Method write

core/filesystem.py:168–216  ·  view source on GitHub ↗

Write file content. Creates parent directories if they don't exist. Enforces checkpoint for core file modifications. Args: path: Path to file (relative to workspace or absolute) content: Content to write Returns: Success

(self, path: Union[str, Path], content: str)

Source from the content-addressed store, hash-verified

166 raise FilesystemAccessError(f"Failed to read {path}: {e}")
167
168 def write(self, path: Union[str, Path], content: str) -> str:
169 """
170 Write file content.
171
172 Creates parent directories if they don't exist.
173 Enforces checkpoint for core file modifications.
174
175 Args:
176 path: Path to file (relative to workspace or absolute)
177 content: Content to write
178
179 Returns:
180 Success message with file path
181
182 Raises:
183 FilesystemAccessError: If file cannot be written
184 """
185 try:
186 path = self._validate_path(path)
187
188 # Check if modifying Codey's own code (requires checkpoint)
189 is_core = _is_core_file(str(path))
190 if is_core:
191 info(f"Writing to core Codey file: {path}")
192 # Enforce checkpoint before core file writes
193 self._require_checkpoint(path)
194
195 # Create parent directories
196 path.parent.mkdir(parents=True, exist_ok=True)
197
198 # Snapshot existing file so /undo works for write_file too
199 if path.exists():
200 _snapshot(str(path))
201
202 # Write content
203 path.write_text(content, encoding='utf-8')
204
205 try:
206 rel = path.relative_to(self.workspace)
207 except ValueError:
208 rel = path
209 msg = f"Written {rel}"
210 success(msg)
211 return msg
212
213 except FilesystemAccessError:
214 raise
215 except Exception as e:
216 raise FilesystemAccessError(f"Failed to write {path}: {e}")
217
218 def patch(self, path: Union[str, Path], old_str: str, new_str: str) -> str:
219 """

Callers 15

handle_commandFunction · 0.45
tool_write_fileFunction · 0.45
tool_patch_fileFunction · 0.45
append_fileFunction · 0.45
startMethod · 0.45
_handle_clientMethod · 0.45
appendMethod · 0.45
run_agentFunction · 0.45

Calls 6

_validate_pathMethod · 0.95
_require_checkpointMethod · 0.95
infoFunction · 0.90
successFunction · 0.90
existsMethod · 0.80