How kalilakshman/ai-security-agent- works
Purpose and Entry Points
security-ai is a Python 3.12 CLI orchestrator for authorized security assessments. It converts a target and profile into a policy-governed tool workflow, preserves evidence, analyzes results, and emits reports. The primary command surface and optional interactive dashboard are in app/cli.py, app/main.py, and app/ui.py.
Orchestration and Workflow Planning
The core control plane builds a dependency-aware assessment plan from target context, available capabilities, and profile settings. Planning is separated from execution so plan can inspect a workflow without invoking tools. Key stages reside in core/planner.py, core/workflow.py, and core/scheduler.py.
Mandatory Security Boundary
Scope and authorization constraints are enforced before tool execution and apply to locally registered tools and MCP-exposed capabilities. This is the critical guardrail boundary intended to prevent an LLM or caller from directly bypassing target-policy checks. Primary implementation paths are core/policy.py, core/interfaces.py, and core/mcp/policy.py.
Execution, Resilience, and Evidence
The executor runs planned steps independently with concurrency, timeout/retry handling, and resumable atomic checkpoints; individual tool failures retain partial scan progress rather than aborting the overall assessment. Raw tool output is then normalized and analyzed into findings that distinguish evidence from interpretation. See core/executor.py, core/checkpoint.py, and core/analyzer.py.
Tool Integration and Extensibility
Two integration styles expose scanner capabilities: adapter implementations for tools/services such as Nmap, ZAP, Metasploit, and tshark; and native plugins for command-line scanners such as Nikto, Nuclei, and Gobuster. Registries and base contracts provide discovery metadata to the planner and CLI. Paths: core/adapters/base.py, core/adapters/registry.py, plugins/base.py, plugins/manager.py.
LLM and MCP External Boundaries
The planner can use provider-independent LLM clients backed by OpenRouter, OpenAI-compatible APIs, or local Ollama. MCP support registers external stdio or HTTP/SSE JSON-RPC servers, discovers tools, applies policy, and routes calls through a gateway. These are external trust and availability boundaries: core/llm/factory.py, core/llm/openrouter.py, core/mcp/gateway.py, core/mcp/client.py.
Persistence, Reporting, and Runtime
Assessment history and structured records persist through SQLAlchemy, with SQLite indicated by the CLI workflow. Report renderers transform normalized results into Markdown, HTML, and PDF outputs. Runtime configuration is YAML/environment-driven; deployment supports Docker Compose and a Docker image. Paths: memory/database.py, memory/models.py, reports/markdown.py, reports/html.py, reports/pdf.py, config/config.yaml, docker-compose.yml.
Main entry points: planner.py Assessment planner · executor.py Resilient executor · policy.py Scope & authorization · workflow.py Workflow model
Components 22
Command Surface
- CLI commands · Starts assessments and supports plan-only inspection.
app/cli.py - Interactive dashboard
app/ui.py - Runtime configuration
config/config.yaml
Assessment Control Plane
- Assessment planner · Builds a dependency-aware plan from target, profile, and capabilities.
core/planner.py - Workflow model
core/workflow.py - Step scheduler
core/scheduler.py - Scope & authorization · Guards every local and MCP capability invocation.
core/policy.py - Tool interfaces
core/interfaces.py - Resilient executor · Runs independent steps with timeout, retry, and partial-progress retention.
core/executor.py - Atomic checkpoints
core/checkpoint.py
Tool & External Integrations
- Adapter registry · Discovers service and scanner adapters for planning.
core/adapters/registry.py - Adapter contracts
core/adapters/base.py - Plugin manager
plugins/manager.py - Plugin contracts
plugins/base.py - Local scanners & services · Adapters and plugins expose Nmap, ZAP, Metasploit, Nikto, Nuclei, and Gobuster.
- LLM provider factory
core/llm/factory.py - OpenRouter client
core/llm/openrouter.py - MCP policy gateway · Routes policy-checked MCP tool calls.
core/mcp/gateway.py - MCP client · Connects to stdio or HTTP/SSE MCP servers.
core/mcp/client.py
Evidence, Records & Reports
- Evidence analyzer · Separates raw evidence from interpreted findings.
core/analyzer.py - Assessment records · Stores assessment history and structured records, including SQLite-backed runs.
memory/database.py - Report renderers
reports/markdown.py
Connections 23
- CLI commands → Assessment planner: creates plan
- Interactive dashboard → Assessment planner: starts assessment
- Runtime configuration → Assessment planner: profiles
- Assessment planner → Workflow model: builds
- Workflow model → Step scheduler: dependencies
- Step scheduler → Resilient executor: ready steps
- Assessment planner → Adapter registry: available capabilities
- Assessment planner → Plugin manager: available capabilities
- Adapter registry → Adapter contracts: registers
- Plugin manager → Plugin contracts: loads
- Adapter contracts → Local scanners & services: implements
- Plugin contracts → Local scanners & services: implements
- Assessment planner → LLM provider factory: optional planning aid
- LLM provider factory → OpenRouter client: selects provider
- Resilient executor → Scope & authorization: authorizes invocation
- Scope & authorization → Local scanners & services: permits scoped calls
- Resilient executor → MCP policy gateway: MCP invocation
- MCP policy gateway → MCP client: policy-checked routing
- MCP client → Scope & authorization: discovered capabilities governed
- Resilient executor → Atomic checkpoints: save/resume
- Resilient executor → Evidence analyzer: raw outputs
- Evidence analyzer → Assessment records: findings and evidence
- Assessment records → Report renderers: assessment records