Files
Claude 291ac58217 feat(cleaner): empty groups, merge weights and LoRA spacing rules
Three prompt-syntax rules for WP Prompt Cleaner, run before whitespace so
the existing rules tidy the seams they leave:

- empty_groups drops (), [], ( , ), (:1.2) and groups left empty
- merge_weights folds nested ( ) weights into one group, ComfyUI-style
  (((a:1.1):1.2) -> (a:1.32)), and unwraps a weight of 1
- lora_spacing tidies <lora:...> tags and the space around them

Balanced turns on empty groups + LoRA spacing; aggressive adds merge
weights. The negative column follows the same presets.
2026-10-06 02:31:42 +00:00

40 lines
1012 B
Python

"""Shared types for the cleaner pipeline.
All rules are string-only — no upstream PIPELINE_CONTEXT dependency.
The cleaner operates purely on the prompt string + the user's widget
config (mode, intensity, rule overrides, blocklist).
"""
from __future__ import annotations
from typing import Any, Literal, TypedDict
RuleId = Literal[
"empty_groups",
"merge_weights",
"lora_spacing",
"whitespace",
"punctuation",
"dedupe_exact",
"fuzzy_dedupe",
"blocklist",
]
Mode = Literal["tags", "text"]
class RuleResult(TypedDict):
"""Return shape for every rule.
`text` is the transformed prompt. `stats` is a per-rule key/value
dict the pipeline collects into a RunReport — UI surfaces these
inline next to each active rule in the widget.
"""
text: str
stats: dict[str, Any]
# A RunReport is `{rule_id -> stats dict}`. Keep as a type alias rather
# than TypedDict so callers can iterate rule_ids dynamically.
RunReport = dict[RuleId, dict[str, Any]]