xai-rust 0.1.1

Rust SDK for the xAI API (Grok models)
Documentation
set windows-shell := ["powershell.exe", "-NoLogo", "-Command"]
DOCS_SOURCE := "https://docs.x.ai/overview"
DOCS_SOURCE_LLMS := "https://docs.x.ai/llms.txt"
COVERAGE_IGNORE_FILENAME_REGEX := 'cache[/\\]cargo[/\\](registry|git)|examples|\\.cargo|rustup|[\\/]+target[\\/]|[\\/]external[\\/]|[\\/]legacy[\\/]'
RELEASE_PARITY_PYTHON_SOURCE := "external/xai-sdk-python/src"

ci-fast: hygiene fmt lint build test-quick
ci-deep: ci-fast test-full coverage security docs
pre-commit: ci-fast coverage-75
release-gate:
    # Deprecated alias. Use `just release-readiness` for the canonical local readiness check.
    pwsh -NoProfile -ExecutionPolicy Bypass -Command 'Write-Host "DEPRECATED: release-gate is now a compatibility alias. Use release-readiness."'
    just release-readiness

release-gate-log:
    # Deprecated alias retained for compatibility. Use `just release-evidence` instead.
    pwsh -NoProfile -ExecutionPolicy Bypass -Command 'Write-Host "DEPRECATED: release-gate-log is now a compatibility alias. Use release-evidence for canonical evidence capture."'
    just release-evidence

release-evidence:
    pwsh -NoProfile -ExecutionPolicy Bypass -File scripts/release_evidence_pack.ps1

release-evidence-target target-repo:
    pwsh -NoProfile -ExecutionPolicy Bypass -File scripts/release_evidence_pack.ps1 -TargetRepo "{{target-repo}}"

release-evidence-target-dry-run target-repo:
    pwsh -NoProfile -ExecutionPolicy Bypass -File scripts/release_evidence_pack.ps1 -TargetRepo "{{target-repo}}" -DryRun

release-local:
    pwsh -NoProfile -ExecutionPolicy Bypass -File scripts/release_publish_local.ps1

release-local-dry-run:
    pwsh -NoProfile -ExecutionPolicy Bypass -File scripts/release_publish_local.ps1 -DryRun

release-local-no-parity:
    pwsh -NoProfile -ExecutionPolicy Bypass -File scripts/release_publish_local.ps1 -SkipParity

release-local-verified:
    pwsh -NoProfile -ExecutionPolicy Bypass -File scripts/release_evidence_pack.ps1 -OutputDir output/release-evidence -OutputPrefix release-local-verified
    pwsh -NoProfile -ExecutionPolicy Bypass -File scripts/release_publish_local.ps1 -SkipPreflight

release-local-verified-dry-run:
    pwsh -NoProfile -ExecutionPolicy Bypass -File scripts/release_evidence_pack.ps1 -OutputDir output/release-evidence -OutputPrefix release-local-verified-dry-run -DryRun
    pwsh -NoProfile -ExecutionPolicy Bypass -File scripts/release_publish_local.ps1 -DryRun -SkipPreflight

release-local-migrate target-repo:
    pwsh -NoProfile -ExecutionPolicy Bypass -File scripts/export_local_release_kit.ps1 -TargetRepo "{{target-repo}}"

release-local-migrate-dry-run target-repo:
    pwsh -NoProfile -ExecutionPolicy Bypass -File scripts/export_local_release_kit.ps1 -TargetRepo "{{target-repo}}" -DryRun

release-local-migrate-verify target-repo:
    pwsh -NoProfile -ExecutionPolicy Bypass -File scripts/verify_local_publish_kit.ps1 -TargetRepo "{{target-repo}}"

release-readiness:
    pwsh -NoProfile -ExecutionPolicy Bypass -File scripts/release_readiness_audit.ps1

release-readiness-target target-repo:
    pwsh -NoProfile -ExecutionPolicy Bypass -File scripts/release_readiness_audit.ps1 -TargetRepo "{{target-repo}}"

package-list:
    cargo package --list --allow-dirty --locked

publish-dry-run:
    cargo publish --dry-run --allow-dirty --locked


hygiene:
    pwsh -NoProfile -ExecutionPolicy Bypass -File scripts/hygiene.ps1

# === Rust ===
fmt:
    cargo fmt --all --check

lint:
    cargo clippy --all-targets --all-features -- -D warnings
    cargo machete

build:
    cargo build --all-targets --all-features --locked

test:
    cargo test --all-features

test-quick:
    cargo nextest run --locked --retries 0

test-full:
    cargo nextest run --all-features --locked --retries 0

coverage:
    cargo llvm-cov nextest --all-features --fail-under-lines 95 --ignore-filename-regex '{{COVERAGE_IGNORE_FILENAME_REGEX}}' --lcov --output-path lcov.info

coverage-75:
    cargo llvm-cov nextest --all-features --fail-under-lines 95 --ignore-filename-regex '{{COVERAGE_IGNORE_FILENAME_REGEX}}' --locked

security:
    cargo deny check advisories bans licenses sources
    cargo audit
    python scripts/enforce_advisory_policy.py

docs:
    $env:RUSTDOCFLAGS = '-D warnings'; cargo doc --all-features --no-deps

# === Node (workspace scan only if package.json exists) ===
fmt-frontend:
    pwsh -NoProfile -ExecutionPolicy Bypass -Command "$packages = Get-ChildItem -Path . -Recurse -Filter package.json -File | Where-Object { $_.FullName -notmatch '\\\\.git\\\\' }; if (-not $packages) { Write-Host 'No frontend projects found'; exit 0 }; foreach ($package in $packages) { $packageRoot = Split-Path $package.FullName -Parent; Set-Location $packageRoot; if (Get-Command pnpm -ErrorAction SilentlyContinue) { pnpm prettier --check . } elseif (Get-Command npx -ErrorAction SilentlyContinue) { npx prettier --check . } }"

lint-frontend:
    pwsh -NoProfile -ExecutionPolicy Bypass -Command "$packages = Get-ChildItem -Path . -Recurse -Filter package.json -File | Where-Object { $_.FullName -notmatch '\\\\.git\\\\' }; if (-not $packages) { Write-Host 'No frontend projects found'; exit 0 }; foreach ($package in $packages) { $packageRoot = Split-Path $package.FullName -Parent; Set-Location $packageRoot; if (Get-Command pnpm -ErrorAction SilentlyContinue) { pnpm eslint . } elseif (Get-Command npx -ErrorAction SilentlyContinue) { npx eslint . } }"

test-frontend:
    pwsh -NoProfile -ExecutionPolicy Bypass -Command "$packages = Get-ChildItem -Path . -Recurse -Filter package.json -File | Where-Object { $_.FullName -notmatch '\\\\.git\\\\' }; if (-not $packages) { Write-Host 'No frontend projects found'; exit 0 }; foreach ($package in $packages) { $packageRoot = Split-Path $package.FullName -Parent; Set-Location $packageRoot; if (Get-Command pnpm -ErrorAction SilentlyContinue) { pnpm test } elseif (Get-Command npm -ErrorAction SilentlyContinue) { npm test } }"

# === Python ===
fmt-python:
    uv run ruff format --check .

lint-python:
    uv run ruff check .

test-python:
    uv run pytest

parity-collect:
    python scripts/parity_check.py --docs-source {{DOCS_SOURCE}} --docs-source {{DOCS_SOURCE_LLMS}} --rust-root src/api --output output/parity collect

parity-verify:
    python scripts/parity_check.py --docs-source {{DOCS_SOURCE}} --docs-source {{DOCS_SOURCE_LLMS}} --rust-root src/api verify --artifacts output/parity

parity-verify-strict:
    python scripts/parity_check.py --docs-source {{DOCS_SOURCE}} --docs-source {{DOCS_SOURCE_LLMS}} --rust-root src/api --rust-surface-root src verify --artifacts output/parity --strict --strict-non-http

parity-test:
    python -m unittest tests.test_parity

parity-all:
    just parity-test
    just parity-collect
    just parity-verify

parity-all-strict:
    just parity-test
    just parity-collect
    just parity-verify-strict

parity-collect-python python_source:
    python scripts/parity_check.py --docs-source {{DOCS_SOURCE}} --docs-source {{DOCS_SOURCE_LLMS}} --rust-root src/api --python-source {{python_source}} --output output/parity collect

parity-verify-python python_source:
    python scripts/parity_check.py --docs-source {{DOCS_SOURCE}} --docs-source {{DOCS_SOURCE_LLMS}} --rust-root src/api --python-source {{python_source}} verify --artifacts output/parity

parity-verify-python-strict python_source:
    python scripts/parity_check.py --docs-source {{DOCS_SOURCE}} --docs-source {{DOCS_SOURCE_LLMS}} --rust-root src/api --rust-surface-root src --python-source {{python_source}} verify --artifacts output/parity --strict --strict-non-http

parity-all-python python_source:
    just parity-test
    just parity-collect-python {{python_source}}
    just parity-verify-python {{python_source}}

parity-all-python-strict python_source:
    just parity-test
    just parity-collect-python {{python_source}}
    just parity-verify-python-strict {{python_source}}