From 65769ee31183cd1e1049321c2fb42296f03bf4b5 Mon Sep 17 00:00:00 2001 From: jaeone94 <89377375+jaeone94@users.noreply.github.com> Date: Mon, 5 Oct 2026 20:43:30 +0900 Subject: [PATCH 01/10] fix: preserve DynamicGroup rows in headless workflows --- CHANGELOG.md | 3 + comfy_cli/cql/engine.py | 191 +++++++++++++- comfy_cli/cql/widget_catalog.py | 18 ++ comfy_cli/schemas/widget_catalog.json | 16 +- comfy_cli/workflow_to_api.py | 29 ++- tests/comfy_cli/fixtures/dynamic_group.json | 272 ++++++++++++++++++++ tests/comfy_cli/fixtures/dynamic_group.md | 16 ++ tests/comfy_cli/test_dynamic_group.py | 207 +++++++++++++++ 8 files changed, 739 insertions(+), 13 deletions(-) create mode 100644 tests/comfy_cli/fixtures/dynamic_group.json create mode 100644 tests/comfy_cli/fixtures/dynamic_group.md create mode 100644 tests/comfy_cli/test_dynamic_group.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 42540738a..45a435242 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,9 @@ history. ### Added +- DynamicGroup workflow conversion, row editing and validation, including row + templates in node discovery and the widget catalog. + - `--select` takes gjson row queries: `items.#()#` keeps the elements that match and `items.#()` is the first one, with `==` `!=` `<` `<=` `>` `>=` `%` (glob) `!%` against a quoted string, number, `true`, `false` or diff --git a/comfy_cli/cql/engine.py b/comfy_cli/cql/engine.py index c58e4b42b..7abd62471 100644 --- a/comfy_cli/cql/engine.py +++ b/comfy_cli/cql/engine.py @@ -276,6 +276,10 @@ def is_autogrow(self) -> bool: ``images.image0``, ``images.image1``, … one per connection.""" return self.type.startswith("COMFY_AUTOGROW") + @property + def is_dynamic_group(self) -> bool: + return self.type == "COMFY_DYNAMICGROUP_V3" + @property def is_dynamic_combo(self) -> bool: """V3 dynamic combo (e.g. ``COMFY_DYNAMICCOMBO_V3``): the schema declares @@ -993,7 +997,7 @@ def _is_link( return False # A dynamic combo is a widget port even when its options block is missing # or malformed — the frontend always renders the selector inline. - if _is_dynamic_combo_type(type_id): + if _is_dynamic_combo_type(type_id) or type_id == "COMFY_DYNAMICGROUP_V3": return False if type_id in _FRONTEND_DOM_WIDGET_TYPES and not force_input: return False @@ -1975,7 +1979,15 @@ def validate_workflow(self, workflow: dict[str, Any]) -> dict[str, Any]: dyn_errors, dyn_warnings, dyn_valid_keys, dyn_unresolved = _check_dynamic_combos( node_id, class_type, m, node_inputs ) + group_errors: list[dict] = [] + group_warnings: list[dict] = [] + for group in (p for p in m.inputs if p.is_dynamic_group): + e, w, _ = _check_dynamic_group(node_id, class_type, group, node_inputs) + group_errors.extend(e) + group_warnings.extend(w) for input_name, value in node_inputs.items(): + if input_name in port_by_name and port_by_name[input_name].is_dynamic_group: + continue if ( "." in input_name and input_name.split(".", 1)[0] in dyn_port_names @@ -2289,6 +2301,7 @@ def _structural(finding: dict, _node_id: str = node_id, _declared: bool = declar # silently lose its dangling_edge error with nothing standing in # for it. warnings.extend(dyn_warnings) + warnings.extend(group_warnings) # Required-presence checks apply only to output-reachable nodes: the # server prunes unreachable nodes without validating them, so # enforcing required inputs on a disconnected node over-rejects a @@ -2299,6 +2312,7 @@ def _structural(finding: dict, _node_id: str = node_id, _declared: bool = declar errors.extend(_check_autogrow_required(node_id, autogrow_ports, autogrow_seen, node_data)) errors.extend(_check_required_present(node_id, m, node_data)) errors.extend(dyn_errors) + errors.extend(group_errors) # No-outputs check: the server rejects any prompt with zero output # nodes (execution.py:1155-1162, prompt_no_outputs) — including an @@ -2503,6 +2517,8 @@ def _widget_default(p: Port) -> Any: """The value a fresh node carries for widget port ``p`` — a dynamic combo's first key, else the schema default, else the first choice, else the DOM-widget placeholder, else ``None``.""" + if p.is_dynamic_group: + return p.options.min or 0 if p.dynamic_options: return p.enum_values[0] if p.enum_values else None if p.options.default is not None: @@ -2539,6 +2555,12 @@ def _input_payload(p: Port, depth: int) -> dict[str, Any]: "default": p.options.default, }, } + if p.is_dynamic_group: + entry["dynamic_group"] = { + "template": p.options.template, + "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, + } if p.is_autogrow: lo, hi = p.autogrow_limits template = p.autogrow_element_template or {} @@ -2756,6 +2778,61 @@ def _validate_catalog_value( return errors, warnings +def _check_dynamic_group( + node_id: str, class_type: str, port: Port, present: dict +) -> tuple[list[dict], list[dict], set[str]]: + errors: list[dict] = [] + warnings: list[dict] = [] + valid_keys: set[str] = set() + fields = _dynamic_group_fields(port) + field_names = {field.name for field in fields} + rows: set[int] = set() + maximum = port.options.max if port.options.max is not None else 20 + minimum = port.options.min if port.options.min is not None else 0 + for key in present: + if not key.startswith(f"{port.name}."): + continue + index, separator, field = key[len(port.name) + 1 :].partition(".") + if ( + not separator + or not index.isascii() + or not index.isdecimal() + or (len(index) > 1 and index.startswith("0")) + or field not in field_names + or len(index) > len(str(maximum)) + or int(index) >= maximum + ): + errors.append( + { + "node_id": node_id, + "field": key, + "code": "invalid_dynamic_group_input", + "message": f"expected {port.name}..