34 lines
2.0 KiB
Python
34 lines
2.0 KiB
Python
#!/usr/bin/env python3
|
|
from pathlib import Path
|
|
import sys, json, shutil
|
|
root=Path(sys.argv[1]) if len(sys.argv)>1 else Path.cwd()
|
|
report={'root':str(root),'created':[],'needs_codex_binding':[]}
|
|
patch_dir=root/'runtime_patches'
|
|
patch_dir.mkdir(exist_ok=True)
|
|
guard=patch_dir/'attachment_reference_route_guard.py'
|
|
guard.write_text('''# AIOS v5 route guard
|
|
IMAGE_EXT={".jpg",".jpeg",".png",".webp",".gif"}
|
|
FILE_EXT={".pdf",".doc",".docx",".xls",".xlsx",".ppt",".pptx",".txt",".csv",".md",".zip",".rar",".7z"}
|
|
def classify_message(message_type="text", filename="", mime="", content=""):
|
|
t=(message_type or "").lower(); f=(filename or content or "").lower(); m=(mime or "").lower()
|
|
if t in ("image","photo","quote_image") or m.startswith("image/") or any(f.endswith(x) for x in IMAGE_EXT): return "vision"
|
|
if t in ("file","quote_file") or any(f.endswith(x) for x in FILE_EXT) or (m and not m.startswith("image/")): return "file"
|
|
return "text"
|
|
def expose_route_proof(role, debug=False):
|
|
return bool(debug and role == "owner")
|
|
''', encoding='utf-8')
|
|
report['created'].append(str(guard))
|
|
patterns=['hasHermesReferenceContext','findHermesReferencedMediaItem','cached_image_expired']
|
|
for f in list(root.rglob('*.py'))+list(root.rglob('*.js'))+list(root.rglob('*.ts')):
|
|
if 'runtime_patches' in str(f) or 'source-baseline' in str(f): continue
|
|
try: txt=f.read_text(encoding='utf-8', errors='ignore')
|
|
except Exception: continue
|
|
if any(p in txt for p in patterns):
|
|
backup=f.with_suffix(f.suffix+'.v5guard.bak')
|
|
if not backup.exists(): shutil.copy2(f, backup)
|
|
if 'AIOS_V5_ROUTE_GUARD_REVIEW_REQUIRED' not in txt:
|
|
f.write_text(txt+'\n\n# AIOS_V5_ROUTE_GUARD_REVIEW_REQUIRED: bind runtime_patches.attachment_reference_route_guard.classify_message before Vision routing.\n', encoding='utf-8')
|
|
report['needs_codex_binding'].append(str(f))
|
|
(root/'runtime_patches'/'v5_patch_report.json').write_text(json.dumps(report,ensure_ascii=False,indent=2), encoding='utf-8')
|
|
print(json.dumps(report,ensure_ascii=False,indent=2))
|