"""
Utility modules for microdrama workflow (V4/V5).
"""
import os


def claude_env():
    """Return env dict for subprocess that calls claude CLI.

    Strips CLAUDECODE so nested sessions work when invoked from Claude Code.
    """
    env = os.environ.copy()
    env.pop("CLAUDECODE", None)
    return env
# V3 functions (reused)
from .metadata_utils_v3 import (
    get_session_id,
    save_metadata,
    load_metadata
)

from .path_utils_v3 import (
    update_current_symlink,
    ensure_dir,
    get_stage_dirs,
    get_next_iteration
)

# Generation log & logging
from .generation_log import (
    GenerationLogger,
    setup_generation_log
)

from .logging_v4 import (
    log_init,
    log_event
)

# V5 Pipeline modules
from .pipeline import (
    PIPELINE_STAGES,
    STAGE_DEPENDENCIES,
    load_pipeline,
    save_pipeline,
    find_next_stage,
    resolve_inputs,
    get_downstream_stages
)

from .iteration import (
    list_iterations,
    read_metadata,
    save_iteration_metadata,
    create_iteration_metadata,
    get_best_iteration
)

from .feedback_history_v5 import (
    get_feedback_history_for_claude
)

from .consistency import (
    validate_selection,
    find_invalidated_downstream
)

from .reference_tracking import (
    build_reference_record
)

from .image_utils import (
    scale_down_references
)

__all__ = [
    # Env
    "claude_env",
    # V3 reused
    "get_session_id",
    "update_current_symlink",
    "save_metadata",
    "load_metadata",
    "ensure_dir",
    "get_stage_dirs",
    "get_next_iteration",
    # Generation log & logging
    "GenerationLogger",
    "setup_generation_log",
    "log_init",
    "log_event",
    # V5 Pipeline
    "PIPELINE_STAGES",
    "STAGE_DEPENDENCIES",
    "load_pipeline",
    "save_pipeline",
    "find_next_stage",
    "resolve_inputs",
    "get_downstream_stages",
    # V5 Iteration
    "list_iterations",
    "read_metadata",
    "save_iteration_metadata",
    "create_iteration_metadata",
    "get_best_iteration",
    # V5 Feedback
    "get_feedback_history_for_claude",
    # V5 Consistency
    "validate_selection",
    "find_invalidated_downstream",
    # V5 Reference tracking
    "build_reference_record",
    # Image utilities
    "scale_down_references",
]
