Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:0xSteph Pentest ai Async Prompt

From Leeroopedia
Knowledge Sources
Domains Async, User_Input, CLI
Last Updated 2026-10-23 00:00 GMT

Overview

Concrete tool for async input with hard timeout that never blocks the agent loop, provided by the pentest-ai engine.

Description

The prompt_with_timeout function is an async wrapper around input() with a hard timeout. Used by the smart-install flow to ask "install X, Y, Z? [y/n]" without blocking forever. Honors sys.stdin.isatty() and PTAI_NON_INTERACTIVE env var so CI runs never hang. Returns the user's response or a default value on timeout, non-interactive mode, or EOF.

Usage

Import this function when you need to ask the user a yes/no or freeform question from within an async context with a timeout. Used by the install planner and HITL approval flow.

Code Reference

Source Location

Signature

def is_non_interactive() -> bool: ...

async def prompt_with_timeout(
    message: str,
    *,
    default: str,
    timeout_s: float = 30.0,
    title: str | None = None,
) -> str: ...

Import

from engine.async_prompt import prompt_with_timeout, is_non_interactive

I/O Contract

Inputs

Name Type Required Description
message str Yes Question to display
default str Yes Default response on timeout/EOF/non-interactive
timeout_s float No Hard timeout in seconds (default: 30.0)
title None No Panel heading for the prompt

Outputs

Name Type Description
response str User's stripped response, or default on timeout/EOF

Usage Examples

Prompt for Approval

import asyncio
from engine.async_prompt import prompt_with_timeout

answer = asyncio.run(prompt_with_timeout(
    "Install nmap, nuclei, and sqlmap? [y/n]",
    default="n",
    timeout_s=30.0,
    title="Smart Install",
))
if answer.lower() in ("y", "yes"):
    print("Installing...")

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment