Implementation:0xSteph Pentest ai Version Check
| Knowledge Sources | |
|---|---|
| Domains | CLI, Version_Management, Update_Nag |
| Last Updated | 2026-10-23 00:00 GMT |
Overview
Concrete tool for non-blocking startup version-check nag that compares the installed version against PyPI's latest, provided by the pentest-ai CLI module.
Description
The maybe_nag function checks if a newer version of ptai is available on PyPI and prints a Claude-Code-style update banner. It NEVER blocks scan startup: a daemon worker fetches the latest version from PyPI while the foreground waits up to 200ms. If the fetch doesn't complete in time, the nag is skipped this run but the cache is written so the next invocation benefits. Uses a 24-hour TTL cache. Hard skip when PTAI_SKIP_VERSION_CHECK=1, cache is fresh, or PyPI is unreachable. Airgapped users see no output and no error.
Usage
Import this function when you need to show an update-available nag at CLI startup. Called by ptai start and ptai doctor.
Code Reference
Source Location
- Repository: 0xSteph_Pentest_ai
- File: cli/_version_check.py
- Lines: 1-193
Signature
def maybe_nag(current: str, *, console: Any, deadline_ms: int = 200) -> None:
"""Best-effort nag. Never raises, never blocks more than deadline_ms."""
Import
from cli._version_check import maybe_nag
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| current | str | Yes | Currently installed version string |
| console | Any | Yes | Rich Console instance for output |
| deadline_ms | int | No | Foreground wait deadline (default: 200ms) |
| PTAI_SKIP_VERSION_CHECK | str (env) | No | Set to "1" to skip the check |
| PTAI_VERSION_OVERRIDE | str (env) | No | Test-only: pretend local version is something else |
Outputs
| Name | Type | Description |
|---|---|---|
| stdout | str | Update-available banner printed to console, or nothing |
Usage Examples
Nag at Startup
from rich.console import Console
from cli._version_check import maybe_nag
from importlib.metadata import version as _v
try:
current = _v("ptai")
except Exception:
current = "unknown"
console = Console()
maybe_nag(current, console=console)
# If update available, prints:
# [ptai 0.14.0] Update available: 0.14.0 -> 1.2.1
# Upgrade with: pipx upgrade ptai