#!/usr/bin/env just

scdoc := env_var_or_default("SCDOC", "scdoc")

# Show all available recipes
default:
    @just --list

# Run tests
test:
    cargo test --all-targets --all-features

# Check code formatting
fmt:
    cargo fmt --all -- --check

# Fix code formatting
fmt-fix:
    cargo fmt

# Run clippy with standard settings
clippy:
    cargo clippy -- -D warnings

# Run clippy with pedantic and strict settings
clippy-pedantic:
    cargo clippy --all-targets --all-features -- -W clippy::pedantic -W clippy::nursery -W clippy::all -D warnings

# Build the project
build:
    cargo build

# Build for release
release:
    cargo build --release

# Regenerate the checked-in man page from its authoritative scdoc source
man:
    mkdir -p docs/man
    SOURCE_DATE_EPOCH=1783641600 {{ scdoc }} < docs/man/textcon.1.scd > docs/man/textcon.1.raw
    sed '1s/^\.\\" Generated by scdoc .*/.\\" Generated by scdoc/' < docs/man/textcon.1.raw > docs/man/textcon.1
    rm docs/man/textcon.1.raw

# Prove the man page is current and valid
man-check:
    mkdir -p target/man
    SOURCE_DATE_EPOCH=1783641600 {{ scdoc }} < docs/man/textcon.1.scd > target/man/textcon.1.raw
    sed '1s/^\.\\" Generated by scdoc .*/.\\" Generated by scdoc/' < target/man/textcon.1.raw > target/man/textcon.1
    rm target/man/textcon.1.raw
    cmp docs/man/textcon.1 target/man/textcon.1
    mandoc -Tascii docs/man/textcon.1 > /dev/null

# Validate the source-only AI-agent skill and deterministic helper
skill-check:
    python3 -m unittest discover -s tests_py

# Run all verification steps
verify: fmt clippy-pedantic test man-check skill-check
