Implementation:0xSteph Pentest ai plan phases
| 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'}")