"""Static exact-declaration reference; parse source AST without executing plugins.""" import ast import copy import hashlib import json from pathlib import Path REPO = Path(__file__).resolve().parents[3] OUT = Path(__file__).resolve().parent REF = OUT.parent / "singleloop-reference" PATHS = [ "example_ComfyUI_workflows/5-数字人/Wan2.1_infinitetalk_音频驱动视频配音-单人for循环长视频(官流).json" ] BINDINGS = { "187": ("unknown", "", "SetNode"), "17": ("core0357", "nodes.py", "ConditioningZeroOut"), "188": ("unknown", "", "GetNode"), "195": ("unknown", "", "GetNode"), "193": ("unknown", "", "SetNode"), "192": ("unknown", "", "SetNode"), "194": ("unknown", "", "GetNode"), "199": ("unknown", "", "GetNode"), "198": ("unknown", "", "GetNode"), "168": ("core0367", "comfy_extras/nodes_custom_sampler.py", "KSamplerSelect"), "171": ("core0367", "comfy_extras/nodes_custom_sampler.py", "RandomNoise"), "169": ("core0367", "comfy_extras/nodes_custom_sampler.py", "CFGGuider"), "197": ("unknown", "", "SetNode"), "196": ("unknown", "", "SetNode"), "176": ("unknown", "", "SetNode"), "175": ("unknown", "", "SetNode"), "170": ("core0357", "comfy_extras/nodes_custom_sampler.py", "BasicScheduler"), "14": ("core0357", "nodes.py", "CLIPTextEncode"), "129": ("core051", "comfy_extras/nodes_wan.py", "WanInfiniteTalkToVideo"), "179": ("kjint", "nodes/nodes.py", "INTConstant"), "177": ("kjint", "nodes/nodes.py", "INTConstant"), "189": ("unknown", "", "GetNode"), "172": ("core051", "comfy_extras/nodes_custom_sampler.py", "SamplerCustomAdvanced"), "214": ("unknown", "", "GetNode"), "221": ("unknown", "", "GetNode"), "223": ("unknown", "", "GetNode"), "224": ("unknown", "", "GetNode"), "225": ("unknown", "", "GetNode"), "226": ("unknown", "", "GetNode"), "227": ("unknown", "", "GetNode"), "228": ("core0367", "comfy_extras/nodes_custom_sampler.py", "KSamplerSelect"), "231": ("core0357", "comfy_extras/nodes_custom_sampler.py", "BasicScheduler"), "181": ("unknown", "", "GetNode"), "180": ("unknown", "", "GetNode"), "184": ("unknown", "", "GetNode"), "186": ("unknown", "", "GetNode"), "242": ("unknown", "", "GetNode"), "218": ("unknown", "", "GetNode"), "219": ("unknown", "", "GetNode"), "222": ("unknown", "", "GetNode"), "243": ("unknown", "", "GetNode"), "210": ("unknown", "", "SetNode"), "251": ("unknown", "", "GetNode"), "191": ("unknown", "", "GetNode"), "250": ("unknown", "", "GetNode"), "182": ("unknown", "", "GetNode"), "220": ("unknown", "", "GetNode"), "249": ("unknown", "", "SetNode"), "232": ("core051", "comfy_extras/nodes_wan.py", "WanInfiniteTalkToVideo"), "235": ("unknown", "", "GetNode"), "236": ("unknown", "", "GetNode"), "259": ("core051", "comfy_extras/nodes_images.py", "ImageFromBatch"), "229": ("core0367", "comfy_extras/nodes_custom_sampler.py", "RandomNoise"), "230": ("core0367", "comfy_extras/nodes_custom_sampler.py", "CFGGuider"), "238": ("core051", "comfy_extras/nodes_custom_sampler.py", "SamplerCustomAdvanced"), "185": ("unknown", "", "SetNode"), "25": ("core0357", "comfy_extras/nodes_audio_encoder.py", "AudioEncoderEncode"), "239": ("core0110", "nodes.py", "CLIPVisionLoader"), "240": ("core0110", "nodes.py", "CLIPVisionEncode"), "241": ("unknown", "", "SetNode"), "183": ("unknown", "", "SetNode"), "262": ("audio", "src/crop.py", "AudioCrop"), "190": ("unknown", "", "SetNode"), "253": ("easy", "py/nodes/logic.py", "forLoopEnd"), "265": ("unknown", "", "GetNode"), "246": ("vhs", "videohelpersuite/nodes.py", "VideoCombine"), "245": ("vhs", "videohelpersuite/nodes.py", "VideoCombine"), "33": ("core0357", "nodes.py", "LoraLoaderModelOnly"), "112": ("core0367", "comfy_extras/nodes_model_patch.py", "ModelPatchLoader"), "26": ("core0357", "comfy_extras/nodes_audio_encoder.py", "AudioEncoderLoader"), "16": ("core0357", "nodes.py", "CLIPLoader"), "29": ("core0357", "nodes.py", "VAELoader"), "260": ("core051", "nodes.py", "ImageBatch"), "264": ("unknown", "", "SetNode"), "248": ("kjfloat", "nodes/nodes.py", "FloatConstant"), "256": ("kjint", "nodes/nodes.py", "INTConstant"), "266": ("core0150", "nodes.py", "VAEDecode"), "267": ("core0150", "nodes.py", "VAEDecode"), "252": ("easy", "py/nodes/logic.py", "forLoopStart"), "254": ("mathnew", "py/math_expression.py", "MathExpression"), "255": ("rgthree", "py/display_any.py", "RgthreeDisplayAny"), "212": ("mathold", "py/math_expression.py", "MathExpression"), "257": ("unknown", "", "SetNode"), "263": ("core0123", "comfy_extras/nodes_audio.py", "LoadAudio"), "32": ("core0357", "nodes.py", "LoadImage"), "209": ("cr", "nodes/nodes_core.py", "CR_PromptText"), "261": ("audio", "src/separation.py", "AudioSeparation"), "200": ("unknown", "", "GetNode"), "174": ("kjint", "nodes/nodes.py", "INTConstant"), "13": ("core0357", "nodes.py", "UNETLoader"), } LAYOUTS = { "187": ["position_0"], "17": [], "188": ["position_0"], "195": ["position_0"], "193": ["position_0"], "192": ["position_0"], "194": ["position_0"], "199": ["position_0"], "198": ["position_0"], "168": ["sampler_name"], "171": ["noise_seed", "control_after_generate"], "169": ["cfg"], "197": ["position_0"], "196": ["position_0"], "176": ["position_0"], "175": ["position_0"], "170": ["scheduler", "steps", "denoise"], "14": ["text"], "129": ["position_0", "position_1", "position_2", "position_3", "position_4", "position_5"], "179": ["value"], "177": ["value"], "189": ["position_0"], "172": [], "214": ["position_0"], "221": ["position_0"], "223": ["position_0"], "224": ["position_0"], "225": ["position_0"], "226": ["position_0"], "227": ["position_0"], "228": ["sampler_name"], "231": ["scheduler", "steps", "denoise"], "181": ["position_0"], "180": ["position_0"], "184": ["position_0"], "186": ["position_0"], "242": ["position_0"], "218": ["position_0"], "219": ["position_0"], "222": ["position_0"], "243": ["position_0"], "210": ["position_0"], "251": ["position_0"], "191": ["position_0"], "250": ["position_0"], "182": ["position_0"], "220": ["position_0"], "249": ["position_0"], "232": ["position_0", "position_1", "position_2", "position_3", "position_4", "position_5"], "235": ["position_0"], "236": ["position_0"], "259": ["batch_index", "length"], "229": ["noise_seed", "control_after_generate"], "230": ["cfg"], "238": [], "185": ["position_0"], "25": [], "239": ["clip_name"], "240": ["crop"], "241": ["position_0"], "183": ["position_0"], "262": ["start_time", "end_time"], "190": ["position_0"], "253": [], "265": ["position_0"], "33": ["lora_name", "strength_model"], "112": ["name"], "26": ["audio_encoder_name"], "16": ["clip_name", "type", "device"], "29": ["vae_name"], "260": [], "264": ["position_0"], "248": ["value"], "256": ["value"], "266": [], "267": [], "252": ["total"], "254": ["expression"], "255": ["position_0"], "212": ["expression"], "257": ["position_0"], "263": ["audio", "audioUI", "upload"], "32": ["image", "upload"], "209": ["prompt"], "261": ["chunk_fade_shape", "chunk_length", "chunk_overlap"], "200": ["position_0"], "174": ["value"], "13": ["unet_name", "weight_dtype"], } LABELS = { "value": "常量原保存值", "sampler_name": "采样器名称", "noise_seed": "本阶段独立种子缓存", "control_after_generate": "种子前端辅助保存", "cfg": "CFG缓存原类型", "scheduler": "调度器名称", "steps": "步数缓存", "denoise": "降噪缓存", "text": "完整文本缓存", "clip_name": "完整模型引用", "crop": "视觉裁切策略", "batch_index": "裁帧起点缓存(受625覆盖)", "length": "裁帧批长度缓存", "start_time": "裁音开始字符串", "end_time": "裁音结束字符串", "lora_name": "完整LoRA引用", "strength_model": "LoRA模型强度", "name": "完整patch引用", "audio_encoder_name": "完整音频编码模型引用", "type": "文本编码器类型", "device": "加载设备策略", "vae_name": "完整VAE引用", "total": "循环总数缓存(受621覆盖)", "expression": "完整原表达式(不求值)", "audio": "原音频文件引用", "audioUI": "原音频辅助null保存", "upload": "原上传辅助保存", "image": "原图像文件引用", "prompt": "完整原中文文本", "chunk_fade_shape": "分段淡化形状", "chunk_length": "分段长度", "chunk_overlap": "重叠参数原类型", "unet_name": "完整扩散模型引用", "weight_dtype": "权重类型策略", "frame_rate": "帧率缓存(外线覆盖)", "loop_count": "VHS额外循环次数", "filename_prefix": "文件名前缀", "format": "格式选择", "pix_fmt": "像素格式", "crf": "编码质量因子", "save_metadata": "元数据保存条件", "trim_to_audio": "按音轨裁切条件", "pingpong": "往返排列条件", "save_output": "输出目录保存条件", "videopreview": "完整历史对象(仅文本)", } def canonical(v): return json.dumps(v, ensure_ascii=False, sort_keys=True, separators=(",", ":")).encode() def node_schema(class_node): """Extract INPUT_TYPES expressions only, never interpret plugin code.""" method = next( ( m for m in class_node.body if isinstance(m, (ast.FunctionDef, ast.AsyncFunctionDef)) and m.name == "INPUT_TYPES" ), None, ) if method is None: method = next( ( m for m in class_node.body if isinstance(m, ast.FunctionDef) and m.name == "define_schema" ), None, ) if method is None: return {} schema = {} for call in ast.walk(method): if ( not isinstance(call, ast.Call) or not isinstance(call.func, ast.Attribute) or call.func.attr != "Input" ): continue if ( not call.args or not isinstance(call.args[0], ast.Constant) or not isinstance(call.args[0].value, str) ): continue default = next( (ast.unparse(k.value) for k in call.keywords if k.arg == "default"), "无显式default;动态选项由准确代码/目标决定", ) schema[call.args[0].value] = (default, ast.unparse(call)) return schema literals = {} for assignment in method.body: if isinstance(assignment, ast.Assign) and len(assignment.targets) == 1: target = assignment.targets[0] if isinstance(target, ast.Name): try: ast.literal_eval(assignment.value) except (ValueError, TypeError): continue literals[target.id] = assignment.value class LiteralNames(ast.NodeTransformer): def visit_Name(self, node): return copy.deepcopy(literals.get(node.id, node)) schema = {} for d in ast.walk(method): if not isinstance(d, ast.Dict): continue for k, v in zip(d.keys, d.values, strict=True): if ( isinstance(k, ast.Constant) and isinstance(k.value, str) and isinstance(v, ast.Tuple) ): default = "无显式default;动态枚举或首项依准确代码,目标选项未知" for opts in v.elts[1:]: if isinstance(opts, ast.Dict): for dk, dv in zip(opts.keys, opts.values, strict=True): if isinstance(dk, ast.Constant) and dk.value == "default": default = ast.unparse(dv) schema[k.value] = (default, ast.unparse(LiteralNames().visit(copy.deepcopy(v)))) return schema def build(index=0): raw = (REPO / PATHS[index]).read_bytes() g = json.loads(raw) prose = json.loads((OUT / "prose.json").read_bytes()) editorial = json.loads((OUT / "editorial.json").read_bytes()) manifest = json.loads((REF / "sources.json").read_bytes())["sources"] sources = [] trees = {} for e in manifest: data = (REF / e["local_file"]).read_bytes() assert hashlib.sha256(data).hexdigest() == e["sha256"] sources.append( dict( e, local_file="../singleloop-reference/" + e["local_file"], lines=[1, len(data.decode().splitlines())], claim="准确声明提交或锁定发布成员原文;仅静态读取,许可不等于模型素材授权,目标安装/恢复未知", ) ) if e["file"].endswith(".py"): trees[e["local_file"]] = ast.parse(data) fields = [] comments = [] bindings = [] empty = [] flow = [] schemas = {} refs = {} for ni, n in enumerate(g["nodes"]): nid = str(n["id"]) ptr = f"/nodes/{ni}" flow.append(nid + " 原节点完整保存 " + json.dumps(n, ensure_ascii=False)) if n["type"] in ["Note", "MarkdownNote"]: comments.append( dict( node_id=nid, pointer=ptr + "/widgets_values/0", text=n["widgets_values"][0], meaning=prose["notes"][nid], evidence=[], ) ) continue key, file, symbol = BINDINGS[nid] if key != "unknown": ei = next(i for i, e in enumerate(manifest) if e["id"] == key and e["file"] == file) entry = manifest[ei] cl = next( ( c for c in trees[entry["local_file"]].body if isinstance(c, ast.ClassDef) and c.name == symbol ), None, ) rs = [i for i, e in enumerate(manifest) if e["id"] == key] if cl is not None: sources.append( dict( sources[ei], lines=[cl.lineno, cl.end_lineno], claim=f"节点{nid}准确{key}类{symbol} schema与实现,非目标运行证明", ) ) rs.append(len(sources) - 1) schema = node_schema(cl) candidates = [dict(source=ei, symbol=symbol, lines=[cl.lineno, cl.end_lineno])] source_id = key else: schema = {} candidates = [] source_id = "unresolved-" + key else: schema, candidates, rs, cl = {}, [], [], None source_id = "unknown-no-version" schemas[nid] = schema refs[nid] = rs bindings.append( dict( node_id=nid, class_type=n["type"], source_version=n["properties"].get("ver", "未知:只有aux名称,无版本"), source_id=source_id, candidates=candidates, declared_provider=n["properties"].get("cnr_id"), implementation_verified=cl is not None, scope="无版本Set/Get仅名称意图,准确实现/schema/默认/副作用/恢复未知" if key == "unknown" else "准确类或选定入口范围未匹配分列;不认证全图转换或目标安装", ) ) effect = ( editorial[nid] + f" 原mode={n['mode']}" + ("旁路保存态,不模拟穿透/执行。" if n["mode"] == 4 else "活动保存态,不认证执行。") ) flow.append(effect) if n["widgets_values"] == []: empty.append( dict( node_id=nid, class_type=n["type"], pointer=ptr, scope="root", state="empty_list", named_state="missing", effect=effect, ) ) continue items = ( list(n["widgets_values"].items()) if isinstance(n["widgets_values"], dict) else list(zip(LAYOUTS[nid], n["widgets_values"], strict=True)) ) for j, (name, value) in enumerate(items): escaped = name.replace("~", "~0").replace("/", "~1") p = ( ptr + "/widgets_values/" + (escaped if isinstance(n["widgets_values"], dict) else str(j)) ) inp = next((i for i, x in enumerate(n["inputs"]) if x["name"] == name), None) known = name in schema if nid in ["245", "246"] and name in [ "pix_fmt", "crf", "save_metadata", "trim_to_audio", ]: format_schema = { "pix_fmt": ("首项yuv420p", "['yuv420p','yuv420p10le']"), "crf": ("19", "('INT', {'default':19,'min':0,'max':100,'step':1})"), "save_metadata": ("True", "('BOOLEAN', {'default':True})"), "trim_to_audio": ("False", "('BOOLEAN', {'default':False})"), } schema[name] = format_schema[name] known = True aux = ( (nid in ["171", "229"] and name == "control_after_generate") or (nid == "32" and name == "upload") or (nid in ["245", "246"] and name == "videopreview") or (nid == "255" and name == "position_0") ) linked = known and inp is not None and n["inputs"][inp].get("link") is not None role = ( "linked_override" if linked else "frontend_only" if aux else "schema_input" if known else "extra_saved" ) default, limits = schema.get( name, ( "未知:准确schema无该保存位置/类未核准,不由后版补值", "未知:额外保存或准确类未核准,不认证位置映射/枚举/恢复", ), ) unit = prose["units"].get( nid + "." + name, "无源码物理单位声明;按准确schema类型/枚举和原JSON类型分列" if known else "未知:此位置后端映射未核准,原类型不是物理单位", ) fields.append( dict( node_id=nid, definition_node_id=nid, scope="root", class_type=n["type"], field=name, label=LABELS.get(name, f"原保存位置{j}(未核后端映射)"), pointer=p, value=value, json_type=type(value).__name__, named_state="missing", input_pointer=f"{ptr}/inputs/{inp}" if known and inp is not None else "未知:无准确后端字段映射,不从原位置/同名/后版补实", input_name=name if known and inp is not None else None, type=limits, role=role, schema_default=default, limits=limits, unit=unit, effect=effect + " 无原具名保存,不补具名值/双指针。" + (" 源外线覆盖缓存意图按物理边记录,非运行结果。" if linked else "") + ( " 此额外保存不在准确schema;保留原值但不认证生效/恢复。" if not known and not aux else "" ), evidence=rs, execution_note="仅静态原数据与准确源码;未构造prompt或执行插件/模型/下载/随机/调度/采样/解码/裁音/分离/编码/清理,执行与转换资格不变。", ) ) flow += ["root 物理边 " + json.dumps(e, ensure_ascii=False) for e in g["links"]] flow += ["根附加保存属性 " + json.dumps(g["extra"], ensure_ascii=False)] + prose["steps"] assert len(fields) == 129 and len(bindings) == 90 and len(comments) == 5 and len(empty) == 8 return dict( source_path=PATHS[index], source_sha1=hashlib.sha1(raw).hexdigest(), source_sha256=hashlib.sha256(raw).hexdigest(), canonical_sha256=hashlib.sha256(canonical(g)).hexdigest(), notice="固定原件与准确声明版本的静态参考;42准确类/发布成员实例、129与232两个准确入口未匹配、46个无版本Set/Get实例,schema/端口差异保留,目标与运行效果未核对。", user_overview=prose["overview"], versions=prose["versions"], counts=dict( saved_fields=len(fields), root_saved_fields=len(fields), internal_saved_fields=0, linked_saved_fields=sum(f["role"] == "linked_override" for f in fields), boundary_saved_fields=0, frontend_only=sum(f["role"] == "frontend_only" for f in fields), source_nodes=95, root_nodes=95, internal_nodes=0, physical_edges=90, source_notes=5, saved_objects=2, history_objects=2, final_scalars=0, final_prompt_constructed=False, ), node_bindings=bindings, fields=fields, sources=sources, comments=comments, flow=flow, flow_evidence=[], zero_saved_nodes=empty, boundaries=[], steps=[prose["overview"]] + prose["steps"], )