Skip to content

AgriciDaniel/banana-claude / skills/banana

banana

Verified

Plan, generate, edit, compare, and review images with Google Gemini (Nano Banana) image models, with an exact plan and explicit approval before every paid call. Use when the user asks to create or edit an image, picture, photo, illustration, logo, thumbnail, poster, banner, product shot, mockup, character sheet, infographic, or diagram; keep a character or product consistent across images; add exact text to an image; or compare image models.

FileKindSize
SKILL.mdskill md17.4 KB
references/cost-tracking.mdmarkdown13.2 KB
references/gemini-models.mdmarkdown18.5 KB
references/mcp-tools.mdmarkdown22.3 KB
references/models.jsonconfig29.2 KB
references/post-processing.mdmarkdown18.7 KB
references/presets.mdmarkdown8.9 KB
references/prompt-engineering.mdmarkdown20.2 KB
references/review-and-recovery.mdmarkdown8.4 KB
scripts/approval_store.pyexecutablescript22.6 KB
scripts/banana_core.pyexecutablescript183.8 KB
scripts/batch.pyexecutablescript5.5 KB
scripts/cost_tracker.pyexecutablescript117.7 KB
scripts/doctor.pyexecutablescript5.5 KB
scripts/edit.pyexecutablescript4.7 KB
scripts/generate.pyexecutablescript5.7 KB
scripts/legacy_cleanup.pyexecutablescript93.4 KB
scripts/mcp_server.pyexecutablescript42.9 KB
scripts/portfolio.pyexecutablescript20.9 KB
scripts/presets.pyexecutablescript128.1 KB
scripts/typeset.pyexecutablescript23.9 KB

scripts/batch.py

View on GitHub
#!/usr/bin/env python3
"""Validate a CSV and produce a costed variation plan.

This utility does not submit a Gemini Batch API job and never calls a network.
Google's true Batch API is asynchronous and uses generateContent jobs.
"""

from __future__ import annotations

import argparse
import csv
import io
import json
import sys
from pathlib import Path
from typing import Any

from banana_core import (
    MAX_PROMPT_CHARS,
    BananaError,
    SecretSafeArgumentParser,
    _read_regular_file_bounded,
    estimate_image_cost,
    get_model,
    normalize_image_size,
    validate_approval_text,
    validate_aspect_ratio,
)

HARD_MAX_ROWS = 100
MAX_CSV_BYTES = 5 * 1024 * 1024


def build_parser() -> argparse.ArgumentParser:
    parser = SecretSafeArgumentParser(description="Validate a CSV image variation plan")
    parser.add_argument("--csv", required=True)
    parser.add_argument(
        "--max-count", type=int, default=20, help="Accepted row ceiling, maximum 100"
    )
    parser.add_argument(
        "--provider-batch",
        action="store_true",
        help="Estimate Google's asynchronous Batch pricing",
    )
    return parser


def plan_csv(path: Path, *, max_count: int, provider_batch: bool) -> dict[str, Any]:
    if max_count < 1 or max_count > HARD_MAX_ROWS:
        raise BananaError(
            "invalid_max_count", f"--max-count must be between 1 and {HARD_MAX_ROWS}."
        )
    if not path.is_file():
        raise BananaError("csv_not_found", f"CSV file not found: {path}")
    raw = _read_regular_file_bounded(
        path,
        max_bytes=MAX_CSV_BYTES,
        unreadable_code="csv_not_found",
        oversized_code="csv_too_large",
        label="CSV",
    )

    rows: list[dict[str, Any]] = []
    errors: list[str] = []
    try:
        text = raw.decode("utf-8-sig")
        with io.StringIO(text, newline="") as handle:
            reader = csv.DictReader(handle)
            if not reader.fieldnames or "prompt" not in reader.fieldnames:
                raise BananaError(
                    "missing_prompt_column", "CSV must contain a 'prompt' column."
                )
            for line_number, row in enumerate(reader, start=2):
                if len(rows) >= max_count:
                    errors.append(
                        f"Line {line_number}: row ceiling of {max_count} exceeded"
                    )
                    continue
                prompt = (row.get("prompt") or "").strip()
                model = (row.get("model") or "gemini-nano-banana-2.1").strip()
                ratio = (row.get("ratio") or "1:1").strip()
                requested_size = (row.get("resolution") or "auto").strip()
                preset = (row.get("preset") or "").strip()
                if not prompt:
                    errors.append(f"Line {line_number}: missing prompt")
                    continue
                if preset:
                    errors.append(
                        f"Line {line_number}: presets require agent-side brief compilation before CSV planning"
                    )
                    continue
                try:
                    prompt = validate_approval_text(
                        prompt,
                        field=f"Line {line_number} prompt",
                        max_length=MAX_PROMPT_CHARS,
                        multiline=True,
                    )
                    selected, info = get_model(model)
                    size = normalize_image_size(requested_size, info)
                    ratio = validate_aspect_ratio(ratio, info)
                    cost = estimate_image_cost(selected, size, batch=provider_batch)
                except BananaError as exc:
                    errors.append(f"Line {line_number}: {exc.message}")
                    continue
                rows.append(
                    {
                        "line": line_number,
                        "prompt": prompt,
                        "model": selected,
                        "aspect_ratio": ratio,
                        "image_size": size,
                        "estimated_image_output_usd": cost,
                        "image_output_rate_usd": cost,
                        "estimate_basis": "nominal_one_output",
                    }
                )
    except (csv.Error, UnicodeDecodeError) as exc:
        raise BananaError("csv_parse_error", f"Could not parse CSV: {exc}") from exc

    if errors:
        raise BananaError("csv_validation_failed", "; ".join(errors[:20]))
    return {
        "network_called": False,
        "kind": "variation_plan",
        "provider_batch": provider_batch,
        "execution": "not_submitted",
        "rows": rows,
        "total_count": len(rows),
        "estimated_image_output_usd": round(
            sum(row["estimated_image_output_usd"] for row in rows), 4
        ),
        "estimate_basis": "nominal_one_output_per_planned_request",
        "estimate_is_invoice_cap": False,
        "output_count_uncertain": True,
        "estimate_excludes": [
            "input tokens",
            "text and thinking output",
            "Google Search queries",
        ],
    }


def main() -> int:
    args = build_parser().parse_args()
    try:
        result = plan_csv(
            Path(args.csv).expanduser().resolve(),
            max_count=args.max_count,
            provider_batch=args.provider_batch,
        )
        print(json.dumps(result, indent=2, ensure_ascii=False))
        return 0
    except BananaError as exc:
        print(json.dumps(exc.as_dict()), file=sys.stderr)
        return 1


if __name__ == "__main__":
    raise SystemExit(main())
receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementationStars: 322kUpdated Claude CodeCodexVerifiedInstall
requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirementsStars: 322kUpdated Claude CodeCodexVerifiedInstall
using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallbackStars: 322kUpdated Claude CodeCodexVerifiedInstall
verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions alwaysStars: 322kUpdated Claude CodeCodexVerifiedInstall