Files
aigc-home/docs/hel-892/vhs-evidence/build_contract.py
T

144 lines
6.3 KiB
Python

"""Extract line references without importing upstream plugins or running JS."""
import ast
import json
from pathlib import Path
root = Path(__file__).resolve().parents[1] / "vhs-reference"
manifest = json.loads((root / "sources.json").read_bytes())
anchors = {
"web/js/VHS.core.js": [
"function useKVState",
"function addVAEOutputToggle",
"function addVAEInputToggle",
"function addDateFormatting",
"function initializeLoadFormat",
"function addUploadWidget",
"function addVideoPreview",
"function addFormatWidgets",
"async beforeRegisterNodeDef",
"VHSFLOAT(node",
"VHSINT(node",
],
"videohelpersuite/nodes.py": [
"def iterate_format",
"def get_video_formats",
"def apply_format_widgets",
"class VideoCombine",
'"VHS_VideoCombine": VideoCombine',
'"VHS_LoadVideo": LoadVideoUpload',
'"ui": {"gifs": [preview]}',
],
"videohelpersuite/load_video_nodes.py": [
"VHSLoadFormats =",
"def get_load_formats",
"class LoadVideoUpload",
"return (images, len(images), audio, video_info)",
],
"src/utils/executionUtil.ts": [
"// Store all widget values",
"// Store all node links",
],
"src/lib/litegraph/src/LGraphNode.ts": ["this.onConfigure?.(info)"],
"src/scripts/utils.ts": ["export function applyTextReplacements"],
"src/utils/litegraphUtil.ts": ["export function migrateWidgetsValues"],
"src/services/litegraphService.ts": ["function addInputs", "inputSpec.widgetType"],
}
for source in manifest["sources"]:
lines = (root / source["local_file"]).read_text().splitlines()
source["rule_locations"] = {}
for suffix, needles in anchors.items():
if source["local_file"].endswith(suffix):
for needle in needles:
indices = [i + 1 for i, line in enumerate(lines) if needle in line]
if indices:
source["rule_locations"][needle] = [indices[0], indices[0]]
(root / "sources.json").write_text(
json.dumps(manifest, ensure_ascii=False, indent=2) + "\n"
)
classes = []
for commit, filename, classname, registration in [
("4ee72c06", "nodes.py", "VideoCombine", 1034),
("85509813", "load_video_nodes.py", "LoadVideoUpload", 1026),
]:
local = f"{commit}/videohelpersuite/{filename}"
tree = ast.parse((root / local).read_bytes())
cls = next(
n for n in tree.body if isinstance(n, ast.ClassDef) and n.name == classname
)
method = next(
n
for n in cls.body
if isinstance(n, ast.FunctionDef) and n.name == "INPUT_TYPES"
)
classes.append(
{
"class": classname,
"source_file": local,
"definition_lines": [cls.lineno, cls.end_lineno],
"schema_lines": [method.lineno, method.end_lineno],
"schema_ast": ast.unparse(method),
"registration": {
"file": f"{commit}/videohelpersuite/nodes.py",
"line": registration,
},
}
)
contract = {
"authority": "pinned_public_reference_only_not_target_definition",
"classes": classes,
"frontend_versions": {
"1.37.11": "4bf6a1960028cc5cda57d48f9fb01a74dfaade43",
"1.48.6": "7b4172a243e0d43f1679c0be1c307560cd83c00d",
},
"verified_facts": {
"provider": "comfyui-videohelpersuite",
"combine_commit": "4ee72c065db22c9d96c2427954dc69e7b908444b",
"load_commit": "8550981384301e9bc5bfea83e5c2c75258102593",
"combine_dynamic_fields": ["pix_fmt", "crf", "save_metadata", "trim_to_audio"],
"combine_format_file": "4ee72c06/video_formats/h264-mp4.json",
"load_format": "AnimateDiff; built-in mapping shadows nodes.VHSLoadFormats same key",
"persisted_not_prompt": ["videopreview", "choose video to upload"],
"serialize_flags": "VHS onSerialize writes all widgets; graphToPrompt checks options.serialize",
"numeric_restore": "useKVState invokes callbacks. Only identity fixed points accepted. "
"AnimateDiff dimensions modulo 8; zero remains disabling. No callback/media execution.",
"legacy_arrays": "convDict six elements, save_image rename and force_size migration proven; "
"rejected because dynamic fields/default fallbacks not covered",
"filename_prefix": "scripts/utils wrapper calls rootGraph search-and-replace; "
"only literals without % or braces supported",
"extra_js": "videoinfo.js: getVideoMetadata and app.handleFile wrapper; no node serializers",
},
"explicit_reference_assumptions": {
"missing_frontend": "selected 1.37.11; explicit other versions rejected",
"named_mirror": "pinned core ignores widgets_values_named; typed equal mirror required; "
"UE/custom overrides unproven",
"unmodified_pinned_files_and_no_other_extensions": True,
"image_without_vae_only": True,
"no_batch_manager": True,
},
"unknown": [
"target installation/frontend/UE",
"input video file membership/access",
"ffmpeg/encoder availability",
"models/media",
"custom extension hooks",
"actual restored graph export equivalence/history",
],
"output_protocol": {
"combine_reference": "ui.gifs descriptors: filename,subfolder,type,format,frame_rate,workflow,"
"fullpath; result has one VHS_FILENAMES value (save_output, full-path list). Unfinished batch "
"has ui.unfinished_batch=[true] and empty result list.",
"downloadable": "gifs filename/subfolder/type is compatible reference shape. Internal full "
"paths are not download descriptors; no target history generated.",
"load_reference": "4 node-to-node results: IMAGE (LATENT with vae), frame count, AUDIO, "
"VHS_VIDEOINFO. No UI file descriptors. Lazy waveform/sample_rate is execution data.",
"existing_collection": "client.py collect_output_files handles gifs with file validation; "
"output_map/registry/worker unchanged, no new global trust or shared-chain changes",
"limits": "other codecs/formats, encoding, history, target media and custom paths unproved",
},
}
(root / "contract.json").write_text(
json.dumps(contract, ensure_ascii=False, indent=2) + "\n"
)
print(f"{len(manifest['sources'])} pinned sources")