449 lines
18 KiB
Python
449 lines
18 KiB
Python
"""Parse declarations without evaluating source or importing SDK/plugin code."""
|
|
|
|
import ast
|
|
import csv
|
|
import io
|
|
import json
|
|
|
|
from acquire import DOC, ROOT, save, sha, write
|
|
|
|
OLD = ROOT / "docs/hel-892/batch177-controlnet-provenance"
|
|
CLASSES = (
|
|
"AIO_Preprocessor",
|
|
"DepthAnythingPreprocessor",
|
|
"PreviewImage",
|
|
"LoadImage",
|
|
"Canny",
|
|
"ImageStitch",
|
|
"CannyEdgePreprocessor",
|
|
"AnyLineArtPreprocessor_aux",
|
|
"LineArtPreprocessor",
|
|
"AnimeLineArtPreprocessor",
|
|
"LineartStandardPreprocessor",
|
|
"DWPreprocessor",
|
|
"AnimalPosePreprocessor",
|
|
)
|
|
|
|
|
|
def literal(node):
|
|
try:
|
|
return ast.literal_eval(node)
|
|
except (ValueError, TypeError):
|
|
return {"unknown_expression": ast.unparse(node)}
|
|
|
|
|
|
def mapping(node):
|
|
assert isinstance(node, ast.Dict)
|
|
return {ast.literal_eval(k): v for k, v in zip(node.keys, node.values)}
|
|
|
|
|
|
def csv_save(name, rows):
|
|
stream = io.StringIO(newline="")
|
|
writer = csv.DictWriter(stream, fieldnames=list(rows[0]), lineterminator="\n")
|
|
writer.writeheader()
|
|
writer.writerows(
|
|
{key: json.dumps(value, ensure_ascii=False) for key, value in row.items()} for row in rows
|
|
)
|
|
write(name, stream.getvalue().encode())
|
|
|
|
|
|
def properties(cls):
|
|
attributes = {}
|
|
for item in cls.body:
|
|
if isinstance(item, ast.Assign):
|
|
for name in item.targets:
|
|
if isinstance(name, ast.Name) and name.id in (
|
|
"RETURN_TYPES",
|
|
"RETURN_NAMES",
|
|
"FUNCTION",
|
|
"OUTPUT_NODE",
|
|
"OUTPUT_IS_LIST",
|
|
):
|
|
attributes[name.id] = literal(item.value)
|
|
return attributes
|
|
|
|
|
|
def main():
|
|
identities = json.loads((DOC / "identities.json").read_text())
|
|
sources = {item["path"]: item for item in identities if item["state"] == "accepted"}
|
|
evidence = {}
|
|
core = {}
|
|
for path in ("nodes.py", "comfy_extras/nodes_canny.py", "comfy_extras/nodes_images.py"):
|
|
source = sources[path]
|
|
text = (DOC / source["file"]).read_text()
|
|
for cls in ast.parse(text).body:
|
|
if not isinstance(cls, ast.ClassDef) or cls.name not in (
|
|
"LoadImage",
|
|
"SaveImage",
|
|
"PreviewImage",
|
|
"Canny",
|
|
"ImageStitch",
|
|
):
|
|
continue
|
|
excerpt = "\n".join(text.splitlines()[cls.lineno - 1 : cls.end_lineno]) + "\n"
|
|
key = path + ":" + cls.name
|
|
evidence[key] = dict(
|
|
source=source,
|
|
lines=[cls.lineno, cls.end_lineno],
|
|
text=excerpt,
|
|
sha256=sha(excerpt.encode()),
|
|
evidence_kind="declaration AST/text only",
|
|
)
|
|
schema = {}
|
|
methods = {node.name: node for node in cls.body if isinstance(node, ast.FunctionDef)}
|
|
if "INPUT_TYPES" in methods:
|
|
returned = next(
|
|
node for node in methods["INPUT_TYPES"].body if isinstance(node, ast.Return)
|
|
)
|
|
for category, fields in mapping(returned.value).items():
|
|
for name, value in mapping(fields).items():
|
|
if category == "hidden":
|
|
schema[name] = dict(
|
|
type=literal(value), category=category, default_known=False
|
|
)
|
|
continue
|
|
assert isinstance(value, ast.Tuple)
|
|
first = value.elts[0]
|
|
config = literal(value.elts[1]) if len(value.elts) > 1 else {}
|
|
dynamic = not isinstance(first, ast.Constant)
|
|
schema[name] = dict(
|
|
type="COMBO" if dynamic else literal(first),
|
|
category=category,
|
|
default_known="default" in config,
|
|
**config,
|
|
)
|
|
if dynamic:
|
|
schema[name].update(
|
|
options=None,
|
|
dynamic_options=True,
|
|
unknown="runtime file enumeration not called",
|
|
declaration=ast.get_source_segment(text, value),
|
|
)
|
|
else:
|
|
returned = next(
|
|
node for node in methods["define_schema"].body if isinstance(node, ast.Return)
|
|
)
|
|
declaration = {item.arg: item.value for item in returned.value.keywords}
|
|
for call in declaration["inputs"].elts:
|
|
assert isinstance(call, ast.Call)
|
|
kind = call.func.value.attr
|
|
name = literal(call.args[0])
|
|
config = {item.arg: literal(item.value) for item in call.keywords}
|
|
optional = config.pop("optional", False)
|
|
schema[name] = dict(
|
|
type={
|
|
"Image": "IMAGE",
|
|
"Float": "FLOAT",
|
|
"Int": "INT",
|
|
"Combo": "COMBO",
|
|
"Boolean": "BOOLEAN",
|
|
}[kind],
|
|
category="optional" if optional else "required",
|
|
default_known="default" in config,
|
|
**config,
|
|
declaration=ast.get_source_segment(text, call),
|
|
)
|
|
core[cls.name] = dict(
|
|
class_name=cls.name,
|
|
source=sources[path],
|
|
schema=schema,
|
|
attributes=properties(cls),
|
|
bases=[ast.unparse(b) for b in cls.bases],
|
|
evidence=key,
|
|
loading="unknown",
|
|
layer="historical working source declaration",
|
|
)
|
|
core["PreviewImage"]["inherited_attributes"] = core["SaveImage"]["attributes"]
|
|
core["PreviewImage"]["base_evidence"] = core["SaveImage"]["evidence"]
|
|
for name in ("Canny", "ImageStitch"):
|
|
core[name]["declared_outputs"] = ["IMAGE"]
|
|
core[name]["sdk_layer"] = (
|
|
"canonical8010 text only; installation SDK not sampled; internal entry unavailable"
|
|
)
|
|
save("core-class-schema.json", core)
|
|
aux = json.loads((OLD / "class-schema-matrix.json").read_text())
|
|
aux = {k: aux[k] for k in CLASSES if k not in core}
|
|
save("reused-aux-schema.json", aux)
|
|
all_schemas = {
|
|
**{k: v["schema"] for k, v in aux.items()},
|
|
**{k: v["schema"] for k, v in core.items()},
|
|
}
|
|
old_fields = json.loads((OLD / "field-matrix.json").read_text())
|
|
original_path = old_fields[0]["original_document"]
|
|
original_bytes = (ROOT / original_path).read_bytes()
|
|
original = json.loads(original_bytes)
|
|
api_path = "docs/hel-892/supplied-api/01.api.json"
|
|
api_bytes = (ROOT / api_path).read_bytes()
|
|
api = json.loads(api_bytes)
|
|
matrix = []
|
|
for index, item in enumerate(old_fields):
|
|
current = original
|
|
for part in item["original_pointer"].strip("/").split("/"):
|
|
current = current[int(part)] if isinstance(current, list) else current[part]
|
|
assert type(current) is type(item["saved_value"]) and current == item["saved_value"]
|
|
if item["api_pointer"]:
|
|
assert api[item["node_id"]]["inputs"][item["field"]] == current
|
|
schema = all_schemas[item["class_type"]].get(item["field"])
|
|
differences = []
|
|
if schema is None:
|
|
differences.append("frontend cache only; not a node INPUT_TYPES field")
|
|
else:
|
|
if schema.get("default_known") and current != schema["default"]:
|
|
differences.append("saved differs from declaration default; preserve saved")
|
|
if isinstance(current, (int, float)) and not isinstance(current, bool):
|
|
for key, sign in (("min", -1), ("max", 1)):
|
|
if key in schema and (
|
|
(current < schema[key]) if sign == -1 else (current > schema[key])
|
|
):
|
|
differences.append("outside declared " + key)
|
|
if schema.get("options") is not None and current not in schema["options"]:
|
|
differences.append("not in literal declared options")
|
|
declaration_source = core.get(item["class_type"], {}).get("source")
|
|
if declaration_source is None:
|
|
declaration_source = aux[item["class_type"]]["source_proof"]
|
|
comparison_keys = (
|
|
"type",
|
|
"default",
|
|
"default_known",
|
|
"min",
|
|
"max",
|
|
"step",
|
|
"options",
|
|
"dynamic_options",
|
|
"advanced",
|
|
)
|
|
old_schema = item["schema"]
|
|
declaration_differences = []
|
|
if schema is not None and old_schema is not None:
|
|
for field in comparison_keys:
|
|
if schema.get(field) != old_schema.get(field):
|
|
declaration_differences.append(
|
|
dict(field=field, old=old_schema.get(field), current=schema.get(field))
|
|
)
|
|
cls_info = core.get(item["class_type"], aux.get(item["class_type"]))
|
|
declared_returns = cls_info.get(
|
|
"declared_outputs", cls_info.get("attributes", {}).get("RETURN_TYPES")
|
|
)
|
|
matrix.append(
|
|
dict(
|
|
index=index,
|
|
original_document=original_path,
|
|
original_sha256=sha(original_bytes),
|
|
original_pointer=item["original_pointer"],
|
|
node_id=item["node_id"],
|
|
class_type=item["class_type"],
|
|
field=item["field"],
|
|
saved_value=current,
|
|
recursive_type=item["recursive_type"],
|
|
api_pointer=item["api_pointer"],
|
|
api_sha256=sha(api_bytes),
|
|
schema=schema,
|
|
layer="8010 historical core declaration"
|
|
if item["class_type"] in core
|
|
else "exact177 aux1.1.5 declaration",
|
|
declaration_source=declaration_source,
|
|
differences=differences,
|
|
old177_schema=item["schema"],
|
|
schema_dictionary_equal_to_old177=schema == item["schema"],
|
|
declaration_differences_vs_old177=declaration_differences,
|
|
declared_returns=declared_returns,
|
|
default_is_not_saved_value=True,
|
|
current_loaded_schema="unknown",
|
|
real_output="unknown",
|
|
qualification="draft disabled unchecked; no release",
|
|
)
|
|
)
|
|
assert len(matrix) == 36 and sum(item["api_pointer"] is not None for item in matrix) == 34
|
|
node_rows = []
|
|
for node in original["nodes"]:
|
|
name = node["type"]
|
|
info = core.get(name, aux.get(name, {}))
|
|
attrs = info.get("inherited_attributes", info.get("attributes", {}))
|
|
node_rows.append(
|
|
dict(
|
|
node_id=str(node["id"]),
|
|
class_type=name,
|
|
original_properties=node.get("properties", {}),
|
|
original_saved_widgets=node.get("widgets_values", []),
|
|
declared_schema=all_schemas.get(name),
|
|
frontend_only=name == "Reroute",
|
|
declared_returns=info.get("declared_outputs", attrs.get("RETURN_TYPES")),
|
|
class_source=info.get("source", info.get("source_proof")),
|
|
current_loaded_schema="unknown",
|
|
actual_output="unknown",
|
|
mixed_original_version_is_not_host_identity=True,
|
|
)
|
|
)
|
|
save("node-matrix.json", node_rows)
|
|
csv_save("node-matrix.csv", node_rows)
|
|
save("parameter-matrix.json", matrix)
|
|
csv_save("parameter-matrix.csv", matrix)
|
|
selections = []
|
|
for node in original["nodes"]:
|
|
if node["type"] != "AIO_Preprocessor":
|
|
continue
|
|
selection, resolution = node["widgets_values"][:2]
|
|
selected = aux[selection]
|
|
selections.append(
|
|
dict(
|
|
node_id=str(node["id"]),
|
|
selected_class=selection,
|
|
saved_aio_resolution=resolution,
|
|
schema_defaults={
|
|
k: v.get("default", {"unknown": True}) for k, v in selected["schema"].items()
|
|
},
|
|
schema=selected["schema"],
|
|
declared_attributes=selected["attributes"],
|
|
function_defaults=selected["function_defaults"],
|
|
source_proof=selected["source_proof"],
|
|
aio_rule_evidence=aux["AIO_Preprocessor"]["class_excerpt"],
|
|
condition=(
|
|
"AIO builds defaults from selected schema then supplies "
|
|
"its saved image/resolution; not executed"
|
|
),
|
|
function_default_is_not_schema_default=True,
|
|
current_loaded_schema="unknown",
|
|
)
|
|
)
|
|
assert len(selections) == 8
|
|
save("aio-selection-matrix.json", selections)
|
|
csv_save("aio-selection-matrix.csv", selections)
|
|
for path, names in {
|
|
"server.py": {"node_info", "get_object_info", "get_object_info_node"},
|
|
"comfy_api/latest/_io.py": {
|
|
"GET_NODE_INFO_V1",
|
|
"GET_SCHEMA",
|
|
"FINALIZE_SCHEMA",
|
|
"INPUT_TYPES",
|
|
"get_v1_info",
|
|
"create_input_dict_v1",
|
|
"finalize",
|
|
"as_dict",
|
|
},
|
|
}.items():
|
|
text = (DOC / sources[path]["file"]).read_text()
|
|
for node in ast.walk(ast.parse(text)):
|
|
if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)) and node.name in names:
|
|
excerpt = "\n".join(text.splitlines()[node.lineno - 1 : node.end_lineno]) + "\n"
|
|
evidence[path + ":" + node.name + ":" + str(node.lineno)] = dict(
|
|
source=sources[path],
|
|
lines=[node.lineno, node.end_lineno],
|
|
text=excerpt,
|
|
sha256=sha(excerpt.encode()),
|
|
evidence_kind="static interface function text",
|
|
)
|
|
save("declaration-evidence.json", evidence)
|
|
policy = {}
|
|
for name in CLASSES:
|
|
schema = all_schemas[name]
|
|
policy[name] = dict(
|
|
fields=list(schema),
|
|
static_string_defaults={
|
|
key: value["default"]
|
|
for key, value in schema.items()
|
|
if isinstance(value.get("default"), str) and key not in ("image", "filename_prefix")
|
|
},
|
|
)
|
|
save("redaction-policy.json", policy)
|
|
requests = [
|
|
dict(
|
|
index=index + 1,
|
|
method="GET",
|
|
class_name=name,
|
|
url="http://192.168.200.12:8188/object_info/" + name,
|
|
response_cap=131072,
|
|
request_deadline_seconds=6,
|
|
)
|
|
for index, name in enumerate(CLASSES)
|
|
]
|
|
save(
|
|
"request-plan.json",
|
|
dict(
|
|
mode="plan only; no target requests",
|
|
executed_requests=0,
|
|
base_url="http://192.168.200.12:8188",
|
|
installation="/media/ComfyUI",
|
|
total_deadline_seconds=90,
|
|
requests=requests,
|
|
authorization=(
|
|
"requires separately coordinated user service window and "
|
|
"explicit approval file; not granted now"
|
|
),
|
|
prohibited=[
|
|
"full object_info",
|
|
"prompt/POST",
|
|
"SSH",
|
|
"discovery",
|
|
"retry/poll",
|
|
"redirect",
|
|
"asset/media access",
|
|
],
|
|
risk=(
|
|
"INPUT_TYPES/plugin calls and LoadImage filename enumeration; "
|
|
"unknown initialization/GPU effects"
|
|
),
|
|
),
|
|
)
|
|
save(
|
|
"approval-template.json",
|
|
dict(
|
|
approved_by="bbcc1179-3a55-48e7-a72e-c84cf79f41cb",
|
|
approval_comment_id="",
|
|
user_service_window_confirmed=False,
|
|
dynamic_calls_acknowledged=False,
|
|
base_url="http://192.168.200.12:8188",
|
|
classes=list(CLASSES),
|
|
starts_at_utc="",
|
|
expires_at_utc="",
|
|
),
|
|
)
|
|
save(
|
|
"interface-matrix.json",
|
|
[
|
|
dict(
|
|
route="GET /object_info/{node_class}",
|
|
allowed=True,
|
|
lines=[879, 885],
|
|
result="{class: node_info(class)} when registered; {} when missing",
|
|
error="uncaught node_info error reaches server layer; exact status not assumed",
|
|
),
|
|
dict(
|
|
route="GET /object_info",
|
|
allowed=False,
|
|
lines=[866, 877],
|
|
result="enumerates all registered classes; ensure_scan_started and cache_helper",
|
|
error="per-class errors logged; forbidden by this plan",
|
|
),
|
|
dict(
|
|
route="node_info V1",
|
|
allowed="only future approved call",
|
|
lines=[817, 864],
|
|
result="input/input_order/output/name etc; INPUT_TYPES twice",
|
|
error="dynamic file options and plugin code can run",
|
|
),
|
|
dict(
|
|
route="node_info V3",
|
|
allowed="only future approved call",
|
|
lines=[819, 820],
|
|
result=(
|
|
"GET_NODE_INFO_V1 -> GET_SCHEMA -> FINALIZE_SCHEMA -> "
|
|
"define_schema/finalize/get_v1_info"
|
|
),
|
|
error=(
|
|
"internal entry HTTP403; SDK installation bytes and "
|
|
"imported helpers not certified"
|
|
),
|
|
),
|
|
],
|
|
)
|
|
print(
|
|
(
|
|
"36 saved fields = 34 API + 2 frontend caches; 8 AIO selections; "
|
|
"13 exact planned GETs; target requests 0"
|
|
)
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|