from pathlib import Path import json,shutil,datetime,hashlib,os,urllib.request,subprocess,concurrent.futures R=Path.cwd();D=R/'docs/hel-892/animate-document-evidence';F=D.parent/'animate-reference';D.mkdir(exist_ok=True);F.mkdir(exist_ok=True) P='example_ComfyUI_workflows/6-动作迁移/Wan2.2_Animate_SAM3-人物迁移-动作迁移-长视频循环(KJ流).json';g=json.loads((R/P).read_bytes());now=datetime.datetime.now(datetime.timezone.utc).isoformat();rows=[] rep={'wanrole':'animate','WanAnimatePlus角色迁移':'Wan22AnimateSAM3长视频','example_ComfyUI_workflows/6-动作迁移/Wan2.1_Scail-2_角色迁移_WanAnimatePlus_v4.2.json':P,'457e924a61ab4a1c392736585b9379a4c4d3b396':'457e924a61ab4a1c392736585b9379a4c4d3b396','f80346473a275758d1b7bcfdc4924de9193eff8c':'457e924a61ab4a1c392736585b9379a4c4d3b396'} for p in (D.parent/'wanrole-document-evidence').glob('*.py'): s=p.read_text() for a,b in rep.items():s=s.replace(a,b) (D/p.name).write_text(s) for n in ['run-wanrole-document.py','wanrole-document-server.py','wanrole-document.mjs']: s=(R/'e2e'/n).read_text() for a,b in rep.items():s=s.replace(a,b) (R/'e2e'/n.replace('wanrole','animate')).write_text(s) def reuse(folder,oldid,newid,files=None): source=D.parent/folder;records=json.loads((source/'sources.json').read_bytes());records=records.get('sources',[])if isinstance(records,dict)else records for e in records: if e.get('id')!=oldid or files is not None and e['file']not in files:continue e=dict(e);oldlocal=e['local_file'];name=newid+'__'+e['file'].replace('/','__');raw=(source/oldlocal).read_bytes();assert hashlib.sha256(raw).hexdigest()==e['sha256'];(F/name).write_bytes(raw);e.update(id=newid,local_file=name,reverified_at=now,reuse_from=folder+'/'+oldlocal) lic=e.get('license_file','未知:原记录未载') if not lic.startswith('未知'): dst=newid+'__license-source'+Path(lic).suffix;(F/dst).write_bytes((source/lic).read_bytes());e['license_file']=dst for key in ['identity_root','canonical_identity_record']: if e.get(key):e[key]=os.path.relpath((source/e[key]).resolve(),F) rows.append(e) reuse('wanrole-reference','core0359','core0359');reuse('singleloop-reference','core0357','core0357');reuse('zimage-photo-reference','core051','core051') for key in ['videohelpersuite-0edce8ef','videohelpersuite-8e4d7947','kjnodes-37659859','kjnodes-468fcc86']:reuse('wanrole-reference',key,key) reuse('wantalk-reference','kj136','kj136');reuse('singleloop-reference','vhs','vhspkg');reuse('zimage-qwen-reference','easy','easy134');reuse('portrait-master-reference','cr','cr');reuse('qwen21-alpha-reference','frontend','frontend') # Exact same-tree LiteGraph identities from the already audited frontend closure. meta=json.loads((D.parent/'qwen21-alpha-reference/sources.json').read_bytes())['sources'] print('frontend companions',[(e['id'],e['file'])for e in meta if 'lite' in e['id'].lower()],flush=True) for key in sorted({e['id']for e in meta if 'lite' in e['id'].lower()}):reuse('qwen21-alpha-reference',key,key) cnrs=sorted({n.get('properties',{}).get('cnr_id')for n in g['nodes']} - {None}) def registry(cnr): url='https://api.comfy.org/nodes/'+cnr try: with urllib.request.urlopen(url,timeout=40)as response:raw=response.read() (F/('registry-'+cnr+'.json')).write_bytes(raw);return cnr,json.loads(raw) except Exception as e:return cnr,{'error':str(e)} with concurrent.futures.ThreadPoolExecutor(max_workers=4)as pool: regs=dict(pool.map(registry,cnrs)) print('REGISTRY',[(k,v.get('repository',v.get('error')))for k,v in regs.items()],flush=True) (F/'sources.json').write_text(json.dumps({'sources':rows},ensure_ascii=False,indent=2)+'\n') print('REUSED',len(rows),flush=True)