How hadriansecurity/openhack works
1. What this repository is
- openhack is a Python 3.9+ command-line tool and workflow framework for source-guided security review.
- It is not a service; the “system” is a file-based workspace under runs/<target>/<run-id>/ plus agent prompt files and schemas that drive a human-approved, checkpointed review loop.
2. Top-level architecture
- The repository is split into four main planes:
- src/openhack/: core runtime, CLI, validators, and run-state logic.
- agents/: Markdown agent definitions for reconnaissance, scenario routing, and expert review.
- templates/ and config/: prompt/result templates and JSON schema contracts.
- runs/: generated per-run artifacts and audit state, gitignored and treated as durable workflow storage.
3. Execution model
- The CLI is the primary entry point (src/openhack/cli.py, __main__.py).
- Each command advances one checkpoint in a run: initialize, recon, scenario routing, scenario execution, finding triage, summarize, validate.
- The harness or operator supplies the model execution environment; openhack supplies the durable workflow state, prompt generation, validation, and artifact materialization.
4. Run workspace as the core boundary
- Every run is isolated under runs/<target>/<run-id>/.
- The workspace contains the cloned target source, recon outputs, scenario backlog, finished scenario results, finding candidates, triage decisions, final findings, and logs.
- This boundary is important: all later phases derive from files in that run directory rather than from in-memory model context.
5. Workflow data flow
- The pipeline is intentionally narrow:
- recon items → routing units → scenarios → scenario results → finding candidates → triage decisions → findings.
- Recon discovers surfaces; routing clusters them into reviewable units; the scenario router turns those units into scoped work items; expert agents verify or reject them; triage independently decides which verified candidates become final findings.
6. Core runtime modules
- src/openhack/run.py, paths.py, models.py, schemas.py, and results.py define run metadata, path handling, typed records, and schema-backed artifacts.
- backlog.py, scenarios.py, triage.py, queue.py, and summary.py implement the lifecycle around scenario backlogs, candidate queues, triage queues, and resume summaries.
- validate.py and coverage.py enforce integrity, prompt hashes, coverage expectations, and consistency across generated artifacts.
7. Reconnaissance subsystem
- src/openhack/recon.py, inventory.py, inventory_patterns.py, request_boundaries.py, router_context.py, and routing_units.py support source reconnaissance and surface normalization.
- Recon writes compact artifacts such as recon items, routes, inputs, sinks, exposures, request boundaries, coverage gaps, and routing units.
- src/openhack/semgrep_recon.py optionally enriches recon with bundled Semgrep rules from config/semgrep/openhack-recon.yml; these hits are treated as hints, not findings.
8. Agent registry and orchestration
- agents/orchestration/ defines the workflow roles: run orchestration, scenario routing, and finding triage.
- agents/reconnaissance/ contains source-recon guidance for discovering review surfaces.
- agents/experts/ contains 12 OWASP/MITRE-aligned expert families, each represented as a compact Markdown manifest that states ownership, signals, false positives, and handoff guidance.
- src/openhack/registry.py and expert_scope.py bind these manifests into a selectable expert scope for a run.
9. Prompting and artifact templates
- templates/ holds the prompt and result shapes for scenario routing, scenario review, finding triage, and findings.
- These templates keep agent I/O stable and machine-checkable.
- config/*.json provides schema contracts for scenario results, finding candidates, triage decisions, and scenario/router outputs, making the file-based workflow validateable across phases.
10. Logging, auditability, and resume
- src/openhack/log.py and scripts/commands/log-event.py support append-only event tracing.
- Each command emits structured records into run logs and trace files so the run can be audited and resumed deterministically.
- summarize-run derives the next checkpoint from the filesystem state, which is the key recovery boundary after interruption.
11. Scripts vs. library
- scripts/commands/ contains thin command implementations for operational tasks like initializing runs, rendering prompts, recording results, and validating runs.
- The reusable logic lives in src/openhack/, while the scripts act as CLI-facing adapters over that library.
- This separation matters for architecture: the command layer is orchestration, not business logic.
12. Operational and packaging boundaries
- The project is distributed as an editable, workspace-first Python package via pyproject.toml and setup.py.
- The repository root itself is part of the runtime contract because agents/, config/, templates/, and runs/ are read as workspace data.
- OPENHACK_ROOT exists to relocate that workspace boundary when the CLI is invoked externally.
13. Validation and CI
- validate-run is the central integrity gate for schemas, prompt hashes, coverage, and materialization consistency.
- .github/workflows/ci.yml provides repository-level automation, but the system’s main correctness model is local run validation rather than a long-running backend service.
14. What an architecture diagram should emphasize
- The key diagram should show a stateful, file-backed pipeline with human approval gates between phases.
- The important boundaries are: target source checkout, recon normalization, router backlog generation, per-scenario expert review, independent triage, and final finding materialization.
- The major external dependency is the source repository under review; the rest of the system is local Python tooling plus optional Semgrep enrichment and the surrounding model harness.
Main entry points: runs Run workspace · backlog.py Workflow core · recon.py Recon engine · cli.py CLI
Components 23
Core runtime
Python CLI, run state, and validation logic.
- CLI · Primary command entrypoint and command dispatch.
src/openhack/cli.py - Module main · Package execution entrypoint.
src/openhack/__main__.py - Run state · Run metadata, paths, typed records, and artifact models.
src/openhack/run.py - Workflow core · Backlog, scenarios, triage, queueing, and resume summary.
src/openhack/backlog.py - Recon engine · Source reconnaissance, normalization, and routing unit generation.
src/openhack/recon.py - Inventory · Source inventory and pattern extraction.
src/openhack/inventory.py - Routing units · Normalizes recon outputs into reviewable routing units.
src/openhack/routing_units.py - Validation · Schema, prompt hash, coverage, and materialization validation.
src/openhack/validate.py - Expert registry · Binds agent manifests into selectable expert scope.
src/openhack/registry.py - Semgrep hints · Optional recon enrichment from bundled Semgrep rules.
src/openhack/semgrep_recon.py
Agents
Markdown agent roles used by the workflow.
- Orchestrator · Run orchestration manifest.
agents/orchestration/orchestrator.md - Scenario router · Manifest for routing recon units into scenarios.
agents/orchestration/scenario-router.md - Finding triage · Manifest for deciding which verified candidates become findings.
agents/orchestration/finding-triage.md - Recon guide · Source reconnaissance guidance.
agents/reconnaissance/source-recon.md - Expert families · OWASP/MITRE-aligned expert manifests for scenario review.
agents/experts
Contracts
Prompt templates and JSON schemas that stabilize file-based I/O.
- Scenario prompt · Prompt contract for routing and scenario review.
templates/scenario-prompt.md - Triage prompt · Prompt contract for finding triage.
templates/finding-triage-prompt.md - JSON schemas · Machine-checkable schemas for scenarios, results, candidates, triage, and findings.
config/scenario-schema.json
Run workspace
Per-run durable artifacts under runs/<target>/<run-id>/.
- Run workspace · Per-run isolated filesystem state under runs/<target>/<run-id>/.
runs - Scenario results · Finished scenario outputs and review evidence.
runs - Triage decisions · Independent accept/reject decisions for verified candidates.
runs - Findings · Materialized final findings and audit state.
runs
External target
Source repository under review and optional recon enrichment.
- Target source · Source repository under review, cloned into the run workspace.
Connections 23
- Module main → CLI: launches · Package entrypoint invokes the CLI.
- CLI → Run state: loads · Commands resolve run metadata and paths.
- CLI → Workflow core: advances · Each command advances one checkpoint in the workflow.
- Workflow core → Recon engine: starts · Initial checkpoint prepares reconnaissance artifacts.
- Recon engine → Inventory: discovers · Recon discovers source surfaces and patterns.
- Recon engine → Routing units: normalizes · Recon output is compacted into routing units.
- Recon engine → Semgrep hints: enriches · Optional Semgrep hits add hints to recon.
- Routing units → Scenario router: guided by · Scenario routing uses the routing agent manifest.
- Scenario router → Scenario prompt: uses · Routing and review prompts define the scenario I/O shape.
- Expert registry → Expert families: selects · Registry binds expert manifests into a run scope.
- Workflow core → Expert registry: scopes · Workflow determines which experts are available.
- Workflow core → Scenario results: writes · Scenario execution materializes results in the workspace.
- Scenario results → Triage decisions: feeds · Verified scenario outputs become candidate inputs for triage.
- Finding triage → Triage prompt: uses · Triage is driven by a dedicated prompt contract.
- Triage decisions → Findings: promotes · Accepted decisions become final findings.
- JSON schemas → Validation: checked by · Validation enforces schema and artifact consistency.
- Run workspace → Target source: contains · Run workspace holds the cloned target source.
- Run workspace → Scenario results: stores · Workspace persists intermediate scenario artifacts.
- Run workspace → Triage decisions: stores · Workspace persists triage state.
- Run workspace → Findings: stores · Workspace persists final findings and audit state.
- Validation → Run workspace: verifies · Validation checks the filesystem-backed run state.
- Recon guide → Recon engine: guides · Recon guidance shapes surface discovery.
- Orchestrator → Workflow core: coordinates · Orchestration manifest maps the workflow roles.