Implementation:0xSteph Pentest ai EventBus
| Knowledge Sources | |
|---|---|
| Domains | Events, PubSub, Engagement_Lifecycle |
| Last Updated | 2026-10-23 00:00 GMT |
Overview
Concrete tool for typed engagement event streaming with synchronous fan-out to subscribers, provided by the pentest-ai engine.
Description
The events module defines a closed set of frozen engagement event dataclasses (PhaseStarted, PhaseCompleted, PhaseFailed, ProbeFired, CandidateFound, VerdictChanged, ChainEdgeAdded, EngagementCompleted, EngagementFailed) and an EventBus with synchronous fan-out. Producers (orchestrator, probe driver, verifier) call bus.emit(event). Consumers (live TUI, HTML report, CI connectors) subscribe. Consumers never read producer internals, so the engine can change without breaking them.
Usage
Import this module when you need to emit or subscribe to engagement lifecycle events. Used by the orchestrator, TUI, and report generator.
Code Reference
Source Location
- Repository: 0xSteph_Pentest_ai
- File: engine/events.py
- Lines: 1-119
Signature
@dataclass(frozen=True)
class Event:
engagement_id: str
class PhaseStarted(Event): phase: str; percent: float = 0.0
class PhaseCompleted(Event): phase: str; percent: float = 0.0
class PhaseFailed(Event): phase: str; error: str = ""
class ProbeFired(Event): probe: str; target: str = ""
class CandidateFound(Event): finding_id: str; title: str = ""; severity: str = ""
class VerdictChanged(Event): finding_id: str; verdict: str = ""; oracle_kind: str = ""
class ChainEdgeAdded(Event): chain_id: str; src_finding_id: str = ""; dst_finding_id: str = ""
class EngagementCompleted(Event): ...
class EngagementFailed(Event): error: str = ""
class EventBus:
def subscribe(self, handler: Callable[[Event], None]) -> None: ...
def emit(self, event: Event) -> None: ...
Import
from engine.events import EventBus, PhaseStarted, CandidateFound, VerdictChanged, EngagementCompleted
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| event | Event (frozen dataclass) | Yes | Engagement event with engagement_id and type-specific fields |
| handler | Callable[[Event], None] | Yes (subscribe) | Callback invoked on each emitted event |
Outputs
| Name | Type | Description |
|---|---|---|
| fan-out | None | Each subscriber's handler is called synchronously |
Usage Examples
Emit and Subscribe
from engine.events import EventBus, PhaseStarted, CandidateFound, VerdictChanged
bus = EventBus()
# Subscribe a handler
def on_event(event):
if isinstance(event, CandidateFound):
print(f" New finding: {event.title}")
elif isinstance(event, VerdictChanged):
print(f" Verdict: {event.finding_id} -> {event.verdict}")
bus.subscribe(on_event)
# Emit events from the orchestrator
bus.emit(PhaseStarted(engagement_id="abc", phase="recon"))
bus.emit(CandidateFound(engagement_id="abc", finding_id="f1", title="SQLi", severity="critical"))
bus.emit(VerdictChanged(engagement_id="abc", finding_id="f1", verdict="verified"))