Skip to content

lasagnastack.io

lasagnastack.io

Shared output-path conventions and JSON helpers for all pipeline stages.

Each stage writes its output to a predictable location under output_dir so that intermediate results can be inspected, replayed, and debugged independently.

Layout

output_dir/ .cache/ Gemini response cache (keyed by clip hash + model) normalised/ Stage 1 — 480×854 H.264 clips for analysis inventories/ Stage 2 — ClipInventory JSON per source clip cut_list.json Stage 3 — CutList JSON critique/ Stage 4 — CritiqueResult JSON per iteration iteration_0.json ... draft/ Stage 5 — CapCut draft folder (written by pyCapCut)

read_json

read_json(schema: type[_T], path: Path) -> _T

Read a JSON file and validate it against a Pydantic schema.

Source code in src/lasagnastack/io.py
def read_json(schema: type[_T], path: Path) -> _T:
    """Read a JSON file and validate it against a Pydantic schema."""
    return schema.model_validate_json(path.read_text())

write_json

write_json(data: BaseModel | list, path: Path) -> None

Write a Pydantic model or list of models to a JSON file, creating parents.

Source code in src/lasagnastack/io.py
def write_json(data: BaseModel | list, path: Path) -> None:
    """Write a Pydantic model or list of models to a JSON file, creating parents."""
    path.parent.mkdir(parents=True, exist_ok=True)
    if isinstance(data, list):
        serialised = [
            item.model_dump(by_alias=True) if isinstance(item, BaseModel) else item
            for item in data
        ]
        path.write_text(json.dumps(serialised, indent=2))
    else:
        path.write_text(data.model_dump_json(indent=2, by_alias=True))

write_post_caption

write_post_caption(output_dir: Path, caption: str) -> None

Write the Instagram post caption as a plain-text file.

Source code in src/lasagnastack/io.py
def write_post_caption(output_dir: Path, caption: str) -> None:
    """Write the Instagram post caption as a plain-text file."""
    path = post_caption_path(output_dir)
    path.parent.mkdir(parents=True, exist_ok=True)
    path.write_text(caption, encoding="utf-8")