from pathlib import Path
p=Path('/opt/struktur/social-media-agent/codex_image_qa.py'); s=p.read_text()
old='TRUSTED_WORKSPACE = Path(os.environ.get("SMA_CODEX_WORKSPACE", "/opt/struktur/social-media-agent/.codex-workspace")).resolve()\nCRITERIA = ('
new='TRUSTED_WORKSPACE = Path(os.environ.get("SMA_CODEX_WORKSPACE", "/opt/struktur/social-media-agent/.codex-workspace")).resolve()\nNEGATIVE_REGRESSIONS = Path("/opt/struktur/social-media-agent/media_references/technically_rejected/negative_regressions.json")\nCRITERIA = ('
assert s.count(old)==1; s=s.replace(old,new)
old='''def run_image_qa(image_path: Path, topic: str, post_text: str = "", *, timeout: int = 600) -> dict[str, Any]:'''
new='''def _apply_negative_regression(result: dict[str, Any], image_path: Path) -> dict[str, Any]:
if not NEGATIVE_REGRESSIONS.is_file():
return result
digest = hashlib.sha256(image_path.read_bytes()).hexdigest()
for item in json.loads(NEGATIVE_REGRESSIONS.read_text(encoding="utf-8")):
if item.get("sha256") == digest:
for criterion in item.get("forced_fail_criteria", []):
if criterion in CRITERIA:
result[criterion] = "FAIL"
result["overall"] = "FAIL"
result.setdefault("failure_reasons", []).append(item.get("reason", "Bekannte negative Regression."))
result["negative_regression"] = item.get("package_id", "")
break
return result
def run_image_qa(image_path: Path, topic: str, post_text: str = "", *, timeout: int = 600) -> dict[str, Any]:'''
assert s.count(old)==1; s=s.replace(old,new)
old=''' result = parse_qa_response(completed.stdout)
result["image_path"] = str(image_path)'''
new=''' result = parse_qa_response(completed.stdout)
result = _apply_negative_regression(result, image_path)
result["image_path"] = str(image_path)'''
assert s.count(old)==1; s=s.replace(old,new)
# Explicitly strengthen the cable requirement in the existing prompt.
old='''(2) Cable/probe continuity: Wo beginnt und endet jede Leitung? Ist jeder Anschluss vollständig oder logisch nachvollziehbar? Leitung aus Wand, Boden, Decke, Möbel oder Körper, abgeschnittene/schwebende/verschmolzene oder funktionslose Leitung: FAIL.'''
new='''(2) Cable/probe continuity: Prüfe ausschließlich FAIL-CLOSED. Wo beginnt und endet jede Leitung? Ist der komplette physische Verlauf sichtbar oder eindeutig logisch nachvollziehbar? Ist Anfang und Ende funktional plausibel? Leitung aus Wand, Boden, Decke, Möbel oder Körper, verdeckter/verschmolzener Anschluss, abgeschnittene/schwebende/unklare oder funktionslose Leitung: FAIL. Fotorealistische Gesamtwirkung darf keine unklare Leitung zu PASS aufwerten.'''
assert s.count(old)==1; s=s.replace(old,new)
p.write_text(s); print('patched cable regression guard')