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 plan phases

From Leeroopedia
Knowledge Sources
Domains Security_Testing, Methodology
Last Updated 2026-10-23 12:00 GMT

Overview

Concrete phase planner that walks a playbook's phases honoring dependency chains and gating conditions, returning a plan of which phases will run and why.

Description

plan_phases walks a Playbook's phases in order and determines which will run. A phase is skipped if:

  • Dependency skipped: A phase in its depends_on list was itself skipped
  • Condition false: Its condition expression evaluates to False against the current findings

Returns a list of tuples: (Phase, will_run: bool, reason: str). This supports a dry-run mode that shows what would execute before committing.

The eval_condition function evaluates condition expressions using a sandboxed AST walker (no eval against user input). Supported expressions:

  • `has_finding(severity='high')`, `has_finding(category='web')`
  • `count_findings(severity='high') > 2`
  • `any_finding()`
  • `phase_ran('recon')`, `phase_skipped('recon')`
  • Boolean ops: and, or, not, parentheses, comparisons

Usage

Import this when you need to:

  • Plan which playbook phases will run before executing
  • Evaluate playbook condition expressions
  • Implement a dry-run / preview mode

Code Reference

Source Location

  • Repository: pentest-ai
  • File: engine/playbook.py, engine/playbook_conditions.py

Signature

def plan_phases(
    playbook: Playbook,
    findings: list[dict[str, Any]] | None = None,
) -> list[tuple[Phase, bool, str]]:
    """Return [(phase, will_run, reason), ...] — honours conditions + depends_on."""

def eval_condition(expr: str, ctx: ConditionContext) -> bool:
    """Evaluate a condition expression. Raises ConditionError on invalid input."""

@dataclass
class ConditionContext:
    findings: list[dict[str, Any]] = field(default_factory=list)
    phase_results: dict[str, bool] = field(default_factory=dict)

Import

from engine.playbook import plan_phases
from engine.playbook_conditions import eval_condition, ConditionContext

I/O Contract

Inputs

Name Type Required Description
playbook Playbook Yes The playbook to plan
findings None No Current findings for condition evaluation

Outputs

Name Type Description
returns Each entry: (phase, will_run, reason)

Usage Examples

Planning Phases (Dry Run)

from engine.playbook import load_playbook, plan_phases

pb = load_playbook("playbooks/builtin/web-app-quick.yaml")
plan = plan_phases(pb, findings=current_findings)
for phase, will_run, reason in plan:
    status = "RUN" if will_run else "SKIP"
    print(f"  [{status}] {phase.id}: {reason or 'will execute'}")

Related Pages

Implements Principle

Requires Environment

Page Connections

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