How Does the Image‑Generation Gate (Line‑Art) Determine if Existing Images Are Sufficient?

The line‑art gate declares existing images sufficient when at least one file referenced in a view's source_paths exists and is readable; otherwise it fails validation or falls back to text‑to‑image generation.

In the handsomestWei/patent-disclosure-skill repository, the image‑generation gate (line‑art) controls whether line‑art workflows proceed with existing reference images or synthesize new ones. This decision logic lives in tools/shared/design_lineart_gate.py and operates through a strict two‑phase validation system that checks file existence before any image processing begins.

Validation Phase: Checking Source Image Availability

The gate's primary method, run_check, enforces the sufficiency rule during the validation phase. It loads the design_lineart_brief and invokes validate_brief to inspect every defined view.

For each view, the gate examines the source_paths list:

  • Each path is resolved to an absolute path via _resolve_path
  • The gate verifies whether the file exists on disk
  • If no path exists, it records a specific error: "views[i] 源图不存在: …"
  • If none of the listed images are readable, it adds the aggregated error: "views[i] 无任何可读源图"【lines 89‑101】

The entire check returns ok: false whenever any view lacks at least one usable reference image. This hard failure prevents downstream processing from attempting operations on missing files.

Job‑Preparation Phase: Building Work Units from Valid Images

Once validation passes, build_jobs constructs executable job specifications. This phase performs a second, pragmatic resolution of source_paths:


# From tools/shared/design_lineart_gate.py, lines 25-30

for raw_path in view.get("source_paths", []):
    resolved = _resolve_path(case_dir, str(raw_path))
    if resolved.is_file():
        job["source_paths"].append(str(resolved))

Only paths that point to actual files are retained. Views with an empty resolved list after this filtering will trigger the fallback behavior in subsequent pipeline stages.

Fallback Behavior When No Images Are Sufficient

The gate itself does not generate images—it prepares the job structure that enables generation decisions downstream. When a view's resolved list is empty, the later image‑generation logic falls back to text‑to‑image (txt2img) synthesis.

The prompt for this synthesis is assembled automatically only when no explicit gen_prompt is supplied【lines 33‑44】:


# Conceptual flow from the gate's build_jobs logic

if not job["source_paths"] and not view.get("gen_prompt"):
    job["gen_prompt"] = auto_assemble_prompt(view)

This ensures the pipeline never stalls: sufficient images enable img2img reference‑based generation, while their absence triggers prompt‑driven creation.

Running the Line‑Art Gate as a CLI Tool

The module exposes direct command‑line interfaces for inspection and job preparation.

Validate a case directory exclusively for source‑image sufficiency:

python tools/shared/design_lineart_gate.py --case-dir outputs/my_case --check

# Output: JSON report with "ok": true/false and per‑view error details

Prepare jobs after successful validation:

python tools/shared/design_lineart_gate.py --case-dir outputs/my_case --prepare-jobs

# Creates: lineart_assist/design_lineart_jobs.json

Each generated job contains:

  • source_paths: filtered list of verified existing images
  • gen_prompt: auto‑generated when no images are found
  • output_path: destination for the final line‑art PNG

Core Decision Logic in Python

The gate's sufficiency test can be replicated directly:

from pathlib import Path
from tools.shared.design_lineart_gate import _resolve_path

def has_sufficient_images(case_dir: Path, view: dict) -> bool:
    """
    Determine if a view has at least one readable source image.
    Mirrors the gate's internal validation logic.
    """
    for raw in view.get("source_paths") or []:
        if _resolve_path(case_dir, str(raw)).is_file():
            return True
    return False

This function returns True exactly when the gate would permit progression—establishing the same existence‑and‑readability criterion.

Key Source Files in the Repository

File Purpose
tools/shared/design_lineart_gate.py Core implementation: run_check, validate_brief, build_jobs, and _resolve_path
tests/shared/test_design_lineart_gate.py Unit tests verifying behavior across present, missing, and partially‑available source images
references/schemas/design_lineart_brief.schema.yaml JSON Schema defining valid brief structure for gate consumption
prompts/shared/image_gen.md Documentation of automatic txt2img prompts used in fallback scenarios

Summary

  • Existence check: The gate requires at least one file in source_paths to resolve to a readable path
  • Strict validation: Any view failing this check causes ok: false and halts processing
  • Dual path filtering: Validation and job‑preparation both resolve and verify, ensuring no stale references propagate
  • Graceful degradation: Empty source lists trigger automatic prompt generation for pure text‑to‑image synthesis
  • Pipeline integration: The gate's output jobs explicitly separate img2img (reference‑based) from txt2img (prompt‑based) execution paths

Frequently Asked Questions

What happens if some source images exist but others are missing?

The gate accepts a view as sufficient when any listed image is readable. Missing paths are silently excluded during job preparation; the pipeline proceeds with whatever valid references remain.

Can the gate be bypassed to force text‑to‑image generation?

Yes—by ensuring no source_paths entries resolve to existing files and omitting any explicit gen_prompt, the gate will produce jobs with empty source lists and auto‑assembled prompts, triggering downstream txt2img logic.

How does _resolve_path handle relative paths?

The helper resolves paths relative to the specified case_dir, converting them to absolute filesystem locations before existence checks. This anchors all references to the case directory structure.

Where are validation errors surfaced for debugging?

Errors are embedded in the JSON output from run_check, with per‑view messages indicating specific missing files or complete source‑image absence. Unit tests in tests/shared/test_design_lineart_gate.py demonstrate expected error formats.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →