Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ history.

### Added

- DynamicGroup workflow conversion, row editing and validation, including row
templates in node discovery and the widget catalog. Refuse incompatible saved
widget layouts and ambiguous names instead of editing a different widget.

- `comfy deploy cancel [PATH] [--deployment <name|id>]` ends the update a
deployment waits on and keeps it serving the release it served; `--json`
names the update it ended in `cancelledUpdate`, and nothing waiting exits 0
Expand Down
3 changes: 2 additions & 1 deletion comfy_cli/command/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1384,7 +1384,8 @@ def widget_catalog_cmd(
{
"code": "object_info_stale",
"message": f"served from cache ({_stale['source']}): {_stale['reason']}",
}
},
*payload.get("warnings", []),
]

if select is not None:
Expand Down
7 changes: 5 additions & 2 deletions comfy_cli/command/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -844,15 +844,18 @@ def _resolve_template_models(wf: Any, input_path: str | None) -> dict[str, Any]:
"""
if not isinstance(wf, dict) or not (input_path or os.environ.get("COMFY_OBJECT_INFO_FILE")):
return {}
from comfy_cli.cql.engine import Graph
from comfy_cli.cql.engine import DynamicGroupBindingError, Graph
from comfy_cli.cql.loader import resilient_load_object_info
from comfy_cli.model_variants import resolve_workflow_models

try:
graph = Graph.from_object_info(resilient_load_object_info(input_path=input_path))
except Exception as e: # noqa: BLE001 — a missing catalog only skips the check
return {"model_check_skipped": f"could not load object_info: {e}"}
subs, unavailable = resolve_workflow_models(wf, graph)
try:
subs, unavailable = resolve_workflow_models(wf, graph)
except DynamicGroupBindingError as e:
return {"model_check_skipped": f"could not bind saved widgets: {e}"}
notes: dict[str, Any] = {}
if subs:
notes["model_substitutions"] = subs
Expand Down
465 changes: 442 additions & 23 deletions comfy_cli/cql/engine.py

Large diffs are not rendered by default.

46 changes: 42 additions & 4 deletions comfy_cli/cql/widget_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@
fresh selection seeds them with — what the frontend does on a selection change
(``dynamicWidgets.ts``), and what a converter needs to handle any other key.

Dynamic groups publish a row-count controller in ``widget_order`` and a
``dynamic_groups`` map containing each template's relative widget names,
defaults, and min/max. Replace the default row span with the saved count when
mapping positional values; the controller itself is never a prompt input.
A class whose DynamicGroup schema the CLI refuses is left out of ``types`` and
named in a ``dynamic_group_unsupported`` warning instead.

SHAPE (``envelope/1`` ``data`` of ``comfy nodes widget-catalog``)::

{
Expand Down Expand Up @@ -82,22 +89,34 @@
CATALOG_VERSION_PREFIX = "sha256:"


def build_types(graph) -> dict[str, dict[str, Any]]:
def build_types(graph, skipped: dict[str, str] | None = None) -> dict[str, dict[str, Any]]:
"""The ``types`` map: one entry per class the graph knows, in class order.

Every class gets an entry, including widget-less ones (``VAEDecode`` →
``{"widget_order": []}``). A missing entry and an empty order are different
statements — "I have never heard of this class" vs. "this class has no
widgets" — and a converter must be able to tell them apart.

The one exception is a class whose DynamicGroup schema this CLI refuses: it
is left out, and the reason goes into ``skipped``. A consumer stores an
uncatalogued class's values opaquely and refuses writes to them, which is
safe; one unsupported custom node must not take down every other class.
Workflows that use the class still get the refusal from conversion and edits.
"""
# Imported inside the function: workflow_ops sits above cql in the import
# graph (it consumes cql.engine), so a module-level import here would make
# the dependency circular.
from comfy_cli.cql.engine import DynamicGroupBindingError, _dynamic_group_widgets, _widget_default
from comfy_cli.workflow_ops import INPUTCOUNT_WIDGET, inputcount_family_elements

types: dict[str, dict[str, Any]] = {}
for m in graph.all_nodes():
entry: dict[str, Any] = {"widget_order": list(graph.widget_order_default(m.id))}
try:
entry: dict[str, Any] = {"widget_order": list(graph.widget_order_default(m.id))}
except DynamicGroupBindingError as e:
if skipped is not None:
skipped[m.id] = str(e)
continue

# V3 autogrow (COMFY_AUTOGROW_V3): one declared input, one wire slot per
# connection (`images` → `images.image0`, `images.image1`, …). The
Expand All @@ -121,6 +140,18 @@ def build_types(graph) -> dict[str, dict[str, Any]]:
if combos:
entry["dynamic_combos"] = combos

groups = {
p.name: {
"min": p.options.min if p.options.min is not None else 0,
"max": p.options.max if p.options.max is not None else 20,
"widgets": [f.name for f in _dynamic_group_widgets(p)],
"defaults": {f.name: _widget_default(f) for f in _dynamic_group_widgets(p)},
}
for p in m.inputs
if p.is_dynamic_group
}
if groups:
entry["dynamic_groups"] = groups
types[m.id] = entry
return types

Expand All @@ -138,9 +169,16 @@ def catalog_version(types: dict[str, Any]) -> str:

def build_catalog(graph) -> dict[str, Any]:
"""The full emitted payload — ``types`` plus its pin and cardinality."""
types = build_types(graph)
return {
skipped: dict[str, str] = {}
types = build_types(graph, skipped)
payload: dict[str, Any] = {
"catalog_version": catalog_version(types),
"class_count": len(types),
"types": types,
}
if skipped:
payload["warnings"] = [
{"code": "dynamic_group_unsupported", "message": f"{class_type} left out: {reason}"}
for class_type, reason in skipped.items()
]
return payload
7 changes: 7 additions & 0 deletions comfy_cli/error_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,13 @@ class ErrorCode:
"Surfaced in `data.warnings[]` (not as an error envelope) so the command still succeeds.",
"re-run once the server/session is reachable to get a fresh schema",
),
ErrorCode(
"dynamic_group_unsupported",
"A node class has a DynamicGroup schema this CLI does not support, so `comfy nodes widget-catalog` "
"left it out of `types`. Consumers store that class's values opaquely and refuse widget writes to it. "
"Surfaced in `data.warnings[]` (not as an error envelope) so every other class is still published.",
"update comfy-cli, or leave the class's widgets unedited",
),
ErrorCode(
"description_ignored",
"`comfy workflow save --where local --description` was given a description, but the local "
Expand Down
9 changes: 8 additions & 1 deletion comfy_cli/model_variants.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import re
from typing import Any

from comfy_cli.cql.engine import _validate_dynamic_group_layout

#: Precision tags: a token that, on its own, names a numeric format.
_PRECISION_CORE = frozenset({"int4", "int8", "fp4", "fp8", "fp16", "fp32", "bf16", "nvfp4", "mxfp4"})

Expand Down Expand Up @@ -161,10 +163,15 @@ def resolve_workflow_models(workflow: dict, graph) -> tuple[list[dict], list[dic
"""
subs: list[dict] = []
unavailable: list[dict] = []
nodes = _workflow_nodes(workflow)
for node, _sg_id in nodes:
m = graph.node(str(node.get("type", "")))
if m is not None:
_validate_dynamic_group_layout(node, m)
# Per subgraph definition: (interior node id, widget) -> (old, new). An
# instance of that definition may carry the value as a promoted widget.
renamed: dict[str, dict[tuple[str, str], tuple[str, str]]] = {}
for node, sg_id in _workflow_nodes(workflow):
for node, sg_id in nodes:
for key, port, field, value in _model_widgets(node, graph):
if value in {str(o) for o in port.enum_values}:
continue
Expand Down
18 changes: 16 additions & 2 deletions comfy_cli/schemas/widget_catalog.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "comfy nodes widget-catalog",
"description": "The widget catalog: a derived projection of object_info giving, per node class, the positional order of its widgets (plus the grow families that mint slots). It is what a name<->index widget converter needs — notably the CRDT applier, which stores widget values by NAME while the workflow JSON stores them POSITIONALLY in widgets_values. It is NOT object_info: no types, defaults, enum choices, or descriptions.",
"description": "The widget catalog: a derived projection of object_info giving, per node class, the positional order of its widgets (plus the grow families that mint slots). It is what a name<->index widget converter needs — notably the CRDT applier, which stores widget values by NAME while the workflow JSON stores them POSITIONALLY in widgets_values. It is NOT object_info: it carries layout information and defaults for dynamic rows, not full validation schemas.",
"type": "object",
"properties": {
"catalog_version": {
Expand All @@ -24,6 +24,20 @@
"items": { "type": "string" },
"description": "Widget names in the exact positional order of the node's widgets_values array — index i in this list IS index i in widgets_values. Includes the synthetic 'control_after_generate' slot the frontend injects after a seed, dynamic-combo sub-widgets flattened as '<selector>.<sub>', and the trailing inputs frontend extensions inject ('upload' on media loaders, 'audioUI' on the audio family, 'image' on SaveGLB/Preview3D) so a widgets_values written by any frontend version decomposes. Computed by cql.engine.Graph.widget_order, the same call every set-widget in this CLI resolves against."
},
"dynamic_groups": {
"type": "object",
"description": "DynamicGroup controller name to row template. The controller stores a row count in workflow JSON and is omitted from prompts. Expand each row as '<controller>.<zero-based index>.<field>' immediately after the controller. The default widget_order includes min rows; replace that span for the saved count.",
"additionalProperties": {
"type": "object",
"properties": {
"min": { "type": "integer", "minimum": 0 },
"max": { "type": "integer", "minimum": 1 },
"widgets": { "type": "array", "items": { "type": "string" } },
"defaults": { "type": "object" }
},
"required": ["min", "max", "widgets", "defaults"]
}
},
"autogrow_templates": {
"type": "object",
"description": "Present only for classes with a COMFY_AUTOGROW_V3 input: base input name -> element-naming template. The schema's own template when object_info ships one, else the pluralization fallback the edit path applies ('images' -> prefix 'image'), so a consumer holding only the catalog can name grown slots without object_info.",
Expand Down Expand Up @@ -66,7 +80,7 @@
"warnings": {
"type": "array",
"items": { "type": "object" },
"description": "Non-fatal advisories; carries the 'object_info_stale' entry when stale is true."
"description": "Non-fatal advisories; carries the 'object_info_stale' entry when stale is true, and one 'dynamic_group_unsupported' entry per class left out of types because its DynamicGroup schema is not supported."
}
},
"required": ["catalog_version", "class_count", "types"]
Expand Down
86 changes: 71 additions & 15 deletions comfy_cli/workflow_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,14 @@
from typing import Any

from comfy_cli import layout
from comfy_cli.cql.engine import frontend_injected_widget_error, is_wildcard_type
from comfy_cli.cql.engine import (
DynamicGroupBindingError,
_dynamic_group_widgets,
_validate_dynamic_group_layout,
_widgets_as_positional,
frontend_injected_widget_error,
is_wildcard_type,
)

# New ids live in [2**40, 2**53): always large (never collides with small
# frontend counter ids), always inside JS Number.MAX_SAFE_INTEGER.
Expand Down Expand Up @@ -841,6 +848,20 @@ def _binding_address(workflow: dict, graph, node_id: Any) -> Any:
return int(bound) if bound.lstrip("-").isdigit() else bound


def _widget_schema_port(graph, class_type: str, widget: str):
m = graph.node(class_type)
if m is None:
return None
port = next((p for p in m.inputs if p.name == widget), None)
if port is None:
group = next((p for p in m.inputs if p.is_dynamic_group and widget.startswith(f"{p.name}.")), None)
if group is not None:
row, separator, _field = widget[len(group.name) + 1 :].partition(".")
if separator and row.isascii() and row.isdecimal() and (len(row) == 1 or not row.startswith("0")):
port = next((p for p in _dynamic_group_widgets(group, f"{group.name}.{row}") if p.name == widget), None)
return port


def _normalize_combo(graph, class_type: str, widget: str, value: Any) -> tuple[Any, dict | None]:
"""Rewrite a mangled model/COMBO value to the real option it means so the
model actually loads (e.g. ``checkpoints/wai-illustrious-sdxl.safetensors`` →
Expand All @@ -849,10 +870,7 @@ def _normalize_combo(graph, class_type: str, widget: str, value: Any) -> tuple[A
UNAMBIGUOUS match is rewritten; anything else is left untouched so validate's
``unknown_enum_value`` (with ``did_you_mean``) still fires.
"""
m = graph.node(class_type)
if m is None:
return value, None
port = next((p for p in m.inputs if p.name == widget), None)
port = _widget_schema_port(graph, class_type, widget)
if port is None:
return value, None
text = _string_widget_text(port, value)
Expand Down Expand Up @@ -2112,6 +2130,29 @@ def capture_recipe(workflow: dict, graph, name: str = "captured", lift: dict | N
by_id = {n["id"]: n for n in all_nodes}
nodes = [n for n in all_nodes if n.get("type") not in UI_ONLY_NODE_TYPES]
ui_nodes = [n for n in all_nodes if n.get("type") in UI_ONLY_NODE_TYPES]
group_entries = {}

for node in nodes:
m = graph.node(node.get("type", ""))
if m is None:
continue
try:
entries = _validate_dynamic_group_layout(node, m)
except DynamicGroupBindingError as e:
raise RecipeError(f"node {node['id']}: {e}") from e
if entries is not None:
group_names = {p.name for p in m.inputs if p.is_dynamic_group}
group_entries[node["id"]] = [e for e in entries if e.owner in group_names]
values = node.get("widgets_values")
if entries is not None and isinstance(values, dict):
missing = [
e.name
for e in group_entries[node["id"]]
if e.port is not None and e.port.raw_spec is not None and e.name not in values
]
if missing:
# add_node and resize materialize defaults; recipe ops cannot remove a saved field.
raise RecipeError(f"node {node['id']}: capture cannot preserve omitted DynamicGroup fields {missing}")

# Validate lift targets up front — no silently-ignored typos.
for (node_id, widget), _pname in lift.items():
Expand All @@ -2124,8 +2165,14 @@ def capture_recipe(workflow: dict, graph, name: str = "captured", lift: dict | N
)
# Editable names only: an injected slot (``upload``) owns a position
# but no value, and apply would refuse it anyway — say so up front.
if widget not in graph.editable_widget_names(node.get("type", "")):
node_type = node.get("type", "")
values = _widgets_as_positional(node.get("widgets_values"), graph, node_type)
if widget not in graph.editable_widget_names(node_type, values):
Comment thread
jaeone94 marked this conversation as resolved.
Resolved
raise RecipeError(f"--param target {node_id}.{widget!r}: not an editable widget on {node.get('type')}")
saved_values = node.get("widgets_values")
if isinstance(saved_values, dict) and widget not in saved_values:
if any(e.name == widget for e in group_entries.get(node_id, [])):
raise RecipeError(f"--param target {node_id}.{widget!r}: no saved DynamicGroup value to lift")

warnings: list[dict] = []
for n in ui_nodes:
Expand Down Expand Up @@ -2262,10 +2309,19 @@ def _trace(src_id: Any, src_slot: Any) -> tuple[Any, Any]:
ops.append(add)
from comfy_cli.cql import engine as _engine

widgets = _engine._widgets_as_positional(n.get("widgets_values"), graph, class_type)
saved_values = n.get("widgets_values")
widgets = _engine._widgets_as_positional(saved_values, graph, class_type)
order = graph.widget_order_for_node(class_type, widgets)
group_widgets = {e.name for e in group_entries.get(n["id"], [])}
defaults = graph.widget_defaults(class_type)
for i, wname in enumerate(order):
if (
wname in group_widgets
and isinstance(saved_values, dict)
and wname not in saved_values
and (str(n["id"]), wname) not in prim_feeds
):
continue
if i >= len(widgets) and (str(n["id"]), wname) not in prim_feeds:
continue
pname = lift.get((n["id"], wname))
Expand Down Expand Up @@ -2301,8 +2357,7 @@ def _trace(src_id: Any, src_slot: Any) -> tuple[Any, Any]:

def _widget_param_type(graph, class_type: str, widget: str) -> str:
"""Recipe param type for a widget, from its schema port type."""
m = graph.node(class_type)
port = next((p for p in (m.inputs if m else []) if p.name == widget), None)
port = _widget_schema_port(graph, class_type, widget)
t = (port.type if port else "").upper()
if t == "INT":
return "int"
Expand Down Expand Up @@ -3294,10 +3349,9 @@ def __init__(self, finding: dict):
def _validate_widget(graph, class_type: str, widget: str, value: Any) -> list[dict]:
"""Shape-validate a widget value (hard error) and collect catalog warnings
(soft — e.g. unknown COMBO option, out-of-range number)."""
m = graph.node(class_type)
if m is None:
return []
port = next((p for p in m.inputs if p.name == widget), None)
from comfy_cli.cql.engine import SEVERITY_ERROR

port = _widget_schema_port(graph, class_type, widget)
if port is None:
return []
err = port.validate_shape(value)
Expand All @@ -3308,8 +3362,6 @@ def _validate_widget(graph, class_type: str, widget: str, value: Any) -> list[di
# already refused these (`Graph._validate_catalog_value` puts them in
# `errors`); the edit path was the last surface still writing them and
# returning ok:true.
from comfy_cli.cql.engine import SEVERITY_ERROR

fatal = next((f for f in findings if f.get("severity") == SEVERITY_ERROR), None)
if fatal is not None:
raise FatalFindingError(fatal)
Expand Down Expand Up @@ -3456,6 +3508,10 @@ def _resolve_input_target(
the API converter reads the link and skips the widget by name.
"""
ins = node.get("inputs") or []
if graph is not None:
m = graph.node(node.get("type", ""))
if m is not None:
_validate_dynamic_group_layout(node, m)
# Promoted subgraph input (``57.width``): the definition declares it, so it
# is a link input on the instance even before the instance carries an
# ``inputs[]`` entry for it — the frontend rebuilds those from the
Expand Down
Loading
Loading