[tasks.default]
alias = "check"

[tasks.check]
description = "Run fmt + clippy + test (same as CI)"
dependencies = ["fmt-check", "clippy", "test"]

[tasks.fmt-check]
description = "Check formatting"
command = "cargo"
args = ["fmt", "--all", "--", "--check"]

[tasks.fmt]
description = "Apply formatting"
command = "cargo"
args = ["fmt", "--all"]

[tasks.clippy]
description = "Run clippy with warnings as errors"
command = "cargo"
args = ["clippy", "--all-targets", "--", "-D", "warnings"]

[tasks.test]
description = "Run all tests"
command = "cargo"
args = ["test"]

[tasks.install]
description = "Install rvpm from local source (respects Cargo.lock via --locked)"
command = "cargo"
args = ["install", "--path", ".", "--locked"]

[tasks.publish-dry]
description = "Dry-run crates.io publish"
command = "cargo"
args = ["publish", "--dry-run", "--allow-dirty"]

[tasks.hook-install]
description = "Install git pre-push hook that runs 'cargo make check'"
script_runner = "@duckscript"
script = '''
hook_dir = set ".git/hooks"
hook_file = set "${hook_dir}/pre-push"
mkdir ${hook_dir}
hook_content = set "#!/bin/sh\n# Installed by: cargo make hook-install\ncargo make check"
writefile ${hook_file} ${hook_content}
echo "Installed pre-push hook -> ${hook_file}"
'''

# ─── vhs / demo GIF regeneration ───────────────────────────────────────
# Native vhs on Windows hangs on `Set Theme`, so we ship a Docker image
# (vhs + rvpm + claude/gemini/codex CLIs) and drive it from cargo-make.
#
# Windows prerequisites: Docker Engine inside WSL2 (Docker Desktop is not
# required); these tasks shell out via `wsl -- docker ...`. To forward the
# AI API key from PowerShell into WSL, add this to your $PROFILE once:
#   $env:WSLENV += ":GEMINI_API_KEY/u:ANTHROPIC_API_KEY/u:OPENAI_API_KEY/u"
# Linux / macOS: a real `docker` on PATH is enough.

[tasks.vhs-build]
description = "Build the rvpm-vhs Docker image (~5 min first time, cached after)"
cwd = "vhs"
command = "docker"
args = ["build", "-t", "rvpm-vhs", "."]

[tasks.vhs-build.windows]
command = "wsl"
args = ["--", "docker", "build", "-t", "rvpm-vhs", "."]

[tasks.vhs-regen]
description = "Regenerate vhs/demo.gif (or another tape via `cargo make vhs-regen <tape>`)"
dependencies = ["vhs-build"]
cwd = "vhs"
command = "bash"
args = ["regen.sh", "${@}"]

[tasks.vhs-regen.windows]
command = "wsl"
args = ["--", "bash", "regen.sh", "${@}"]
