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

Function _safe_write

core/agent.py:552–568  ·  view source on GitHub ↗

Syntax-check (Python only), then write via safety layer.

(fname, code)

Source from the content-addressed store, hash-verified

550 _CODE_EXTS = ('.py', '.js', '.ts', '.html', '.css', '.json')
551
552 def _safe_write(fname, code):
553 """Syntax-check (Python only), then write via safety layer."""
554 if fname.endswith('.py'):
555 try:
556 from core.linter import check_syntax
557 if check_syntax(code.rstrip(), fname):
558 return False # syntax error — skip
559 except Exception:
560 pass
561 fpath = os.path.join(os.getcwd(), fname)
562 result = tool_write_file(fpath, code.rstrip() + '\n')
563 if result.startswith("[ERROR]") or result.startswith("[CANCELLED]"):
564 warning(f"Failed to write {fname} from peer: {result}")
565 return False
566 files_written.append(fname)
567 success(f"Written {fname} from peer review ({len(code)} chars)")
568 return True
569
570 # ── Primary: filename header immediately before a fenced code block ──────
571 _block_re = re.compile(

Callers 1

_auto_apply_peer_codeFunction · 0.85

Calls 5

check_syntaxFunction · 0.90
tool_write_fileFunction · 0.90
warningFunction · 0.90
successFunction · 0.90
appendMethod · 0.80

Tested by

no test coverage detected