MCPcopy
hub / github.com/wshobson/agents / write

Method write

tools/adapters/base.py:423–434  ·  view source on GitHub ↗

Write `content` to `self.output_root / rel_path`, creating parent dirs. Refuses to write outside `self.output_root` (catches `..` segments and absolute paths).

(self, rel_path: str | Path, content: str)

Source from the content-addressed store, hash-verified

421 # ── Shared utilities ──────────────────────────────────────────────────
422
423 def write(self, rel_path: str | Path, content: str) -> Path:
424 """Write `content` to `self.output_root / rel_path`, creating parent dirs.
425
426 Refuses to write outside `self.output_root` (catches `..` segments and absolute paths).
427 """
428 target = (self.output_root / rel_path).resolve()
429 root = self.output_root.resolve()
430 if not target.is_relative_to(root):
431 raise ValueError(f"refusing to write outside output_root: {target} (root={root})")
432 target.parent.mkdir(parents=True, exist_ok=True)
433 target.write_text(content, encoding="utf-8")
434 return target
435
436 def write_bytes(self, rel_path: str | Path, content: bytes) -> Path:
437 """Binary counterpart of `write` — for mirroring non-UTF-8 reference assets."""

Callers 15

_emit_skillMethod · 0.80
_emit_agentMethod · 0.80
_emit_commandMethod · 0.80
_emit_plugin_entryMethod · 0.80
emit_globalMethod · 0.80
_emit_skillMethod · 0.80
_emit_agentMethod · 0.80
emit_globalMethod · 0.80
_emit_skillMethod · 0.80
_emit_agentMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected