* fix: recover concept detail lost in resolver and harden analyzer parsing
Three shippability fixes for the v1 pipeline:
P2 (main): the Illustrious Resolver did exact-key KB lookup only, so any
compound concept the analyzer emits ("white summer dress", "black business
suit") missed and was dropped silently as SC0001. Add a deterministic
head-noun fallback (§17.2): on a miss, drop leading modifiers and look up the
longest remaining suffix ("white summer dress" -> "dress"). No tag/concept is
invented. Emits SC0019 (Concept Reduced) so the reduction is visible.
P1a: the analyzer required the entire model response to be a single JSON
document, so any surrounding prose ("Sure! Here is the scene:") failed parsing
and, with the prompt reused unchanged, every retry failed identically ->
empty output. Extract the first balanced top-level {...} object from
surrounding text (string-aware brace scan); the object bytes are unchanged and
must still validate, so this is unwrapping, not JSON repair.
P1b: the node's "raw" output was to_raw_json(result.data) -- a re-serialization
of the parsed Scene, so on failure it was empty and the model's actual text was
invisible. Capture the last raw model text in analyzer metadata and surface it
as the node's raw output.
Regenerated goldens: unknown_concepts "hologram jacket" now resolves to
"jacket" via head-noun fallback (intended).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* feat: add entry rating + resolver.include_nsfw gating
Foundations for the Danbooru-vocab KB: a per-entry `rating` (general|explicit,
default general) and a `resolver.include_nsfw` config flag (default false). The
resolver omits explicit-rated entries from lookup and expansion unless enabled,
so a gated concept is reported as unknown (SC0001). Schema, model, config, and
example config updated.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* feat: generate KB from embedded Danbooru vocab (188 -> 16.4k tags)
Replace the coverage ceiling of the 188-entry hand KB by importing a large,
validated Danbooru tag vocabulary. This is the fix for the core "detail loss"
symptom: compound concepts the analyzer emits ("red dress", "sunflower field",
"train station platform") are now real tags that resolve instead of being
dropped.
- scripts/build_vocab.py: one-time dev step that filters the Raffle node's
categorized tag dump (drops artist/character/copyright/attribution categories
and subjective adjectives, keeps only id-pattern-valid tags) into a committed,
self-contained snapshot at data/danbooru_vocab.txt (16.4k tags).
- scripts/generate_kb_from_vocab.py: additive, non-destructive generator. Writes
knowledge_base/gen_<category>.json, mapping the Raffle categories to the 19
canonical categories and tagging NSFW categories rating=explicit. Skips any tag
already defined as a hand-curated id/alias, so the curated canonicalization
(female + aliases) and expansions (school_uniform -> blazer, pleated_skirt) are
preserved and always win.
Result: 16.4k additive entries + 188 curated. Plain natural-language concepts
now resolve broadly via curated aliases + head-noun fallback with no analyzer
prompt change; NSFW gated behind resolver.include_nsfw; golden and dataset tests
stay green.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* style: ruff format build_vocab.py
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* fix(security): drop untrusted CLI path in build_vocab (SonarCloud S8707)
The --source CLI argument fed an untrusted path to the file system (taint).
The script is a one-time dev step; hard-code the source path constant instead.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
---------
Co-authored-by: kunail0804 <kunail0804@gmail.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
ComfyUI Scene Compiler
A deterministic prompt compiler for ComfyUI. Turn a plain-language scene description into structured, category-separated Illustrious tags — without an LLM inventing anything.
Status: Version 1 in development. This repository is spec-driven; the full design is documented in
MASTER_SPEC.mdand in the Wiki. Follow the Roadmap and issues for progress.
The idea
Most prompt-generation workflows ask a language model to write Danbooru tags directly:
Natural Language → LLM → Prompt
LLMs are bad at this. They invent clothing, poses, lighting, and environments that were never described, emit invalid tags, and return different output for identical input. Scene Compiler takes a different position:
The language model understands the scene. The compiler generates the prompt.
Prompt generation is treated as a compilation problem, not a text-generation problem. Language understanding happens once, up front; everything after it is deterministic and traceable.
Natural Language
→ Scene Analyzer → Scene JSON
→ Scene Validator → Validated Scene JSON
→ Resolver → Resolved Tags
→ Category Splitter → Category Map
→ Prompt Builder → Prompt Outputs
Only the Scene Analyzer uses an LLM, and only to understand language — never to produce tags. Every generated tag is looked up deterministically in a data-only Knowledge Base and stays fully traceable:
Natural Language → Scene JSON → Knowledge Base Entry → Resolved Tag → Prompt Output
Key principles
- Determinism first — same input + Knowledge Base + config → same output, always. No random seeds anywhere.
- No hallucinations — if it isn't in the description, it isn't in the output. Unknown concepts are reported, never guessed.
- Knowledge is data — every concept→tag mapping lives in the Knowledge Base, never in code.
- Traceability — every tag can be explained back to the sentence it came from.
- Separation of concerns — each stage does exactly one job and can be tested on its own.
- Nodes are interfaces — ComfyUI nodes are thin wrappers; all logic lives in the compiler package.
Version 1 targets the Illustrious model family only. The architecture is model-independent so future versions can add Pony, Flux, NoobAI, and others without changing the compiler core.
Nodes
Scene Compiler ships as a ComfyUI custom-node package. It is a toolbox, not a fixed workflow — every node can be used independently.
Pipeline nodes
| Node | Input | Output |
|---|---|---|
| Scene Analyzer | Natural language, model, temperature, timeout | Scene JSON |
| Scene Validator | Scene JSON | Validated Scene JSON |
| Resolver | Scene JSON, Knowledge Base | Resolved Tags |
| Category Splitter | Resolved Tags | Category Map |
| Prompt Builder | Category Map | One string per category (+ reserved Negative / Scene) |
Support nodes
- Debug Viewer — inspect any intermediate state (Scene JSON, Resolved Tags, categories, warnings, errors).
- Knowledge Base Loader — load the active Knowledge Base, with manual reload for development.
- Configuration Node — centralize compiler settings without editing workflows.
Installation
Not yet released. These are the intended install steps for Version 1.
Via ComfyUI Manager (recommended once published): search for Scene Compiler.
Manual:
cd ComfyUI/custom_nodes
git clone https://github.com/kunail0804/ComfyUI-Scene-Compiler.git
Then restart ComfyUI. The Scene Analyzer requires a local Ollama instance for language understanding; the rest of the pipeline runs fully offline.
Quick start
- Add a Scene Analyzer node and type a description, e.g. "A blonde girl wearing a white dress hugs a young man while walking in the rain."
- Connect Scene Analyzer → Scene Validator → Resolver → Category Splitter → Prompt Builder.
- Wire the Prompt Builder category outputs into your image-generation workflow (e.g. EasyIllustrious).
- Use the Debug Viewer on any connection to inspect the intermediate state.
Given the example above, the compiler extracts female, blonde hair,
white dress, male, the interaction hug, and environment rain — and
nothing else. It does not add eye colour, quality tags, or lighting that were
never described.
Documentation
Full documentation lives in the Wiki:
- Overview & Vision
- Architecture & Pipeline
- Data Model
- Scene JSON & Schemas
- Scene Analyzer
- Knowledge Base
- Resolver, Categories & Prompt Builder
- ComfyUI Nodes
- Configuration, Errors & Logging
- Development, Testing & Contributing
- Roadmap
- Glossary & Reference
The complete normative specification is MASTER_SPEC.md.
Roadmap
- Version 1 — Deterministic Compiler Foundation (in progress): the complete deterministic pipeline for Illustrious, plus Ollama integration, Knowledge Base, Debug Viewer, and regression tests.
- Version 2 — Semantic Resolution: Knowledge Base editor, semantic/embedding fallback search, localization, performance — determinism preserved.
- Version 3 — Extensible Compiler Platform: multi-model Resolvers, a plugin system, multiple Analyzer backends, and a standalone Compiler SDK.
See the Roadmap for details.
Contributing
Contributions are welcome — especially Knowledge Base entries. Please read the Development, Testing & Contributing guide first. Core rule: never hardcode knowledge, and never break determinism.
License
See LICENSE.