# peg/rampart architecture

> Architecture diagram of the GitHub repository peg/rampart, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/peg/rampart
- Repository: https://github.com/peg/rampart

## Overview

#### 1. Purpose and executable entry points
Rampart is a local, model-free security control plane for AI-agent actions. It intercepts actions at supported host boundaries, evaluates YAML policy, returns allow/ask/deny, and records decisions in a tamper-evident audit trail. The primary Go executable is `cmd/rampart/main.go`; command registration and orchestration live in `cmd/rampart/cli/root.go` and the command-specific files under `cmd/rampart/cli/`.

#### 2. CLI lifecycle and managed integration setup
The CLI is both the operator interface and integration installer. `protect` detects/configures supported agents, while `setup` writes and validates host-specific hooks, plugins, or service configuration; `verify`, `status`, and `doctor` distinguish installed configuration from verified runtime behavior. Key paths: `cmd/rampart/cli/protect.go`, `cmd/rampart/cli/setup.go`, `cmd/rampart/cli/verify.go`.

#### 3. Policy evaluation boundary
Adapters normalize host-visible actions into the engine’s policy model. The engine loads built-in, user, and optionally project policy; matches tool, command, path, network, and temporal conditions; then produces a decision. Multiple represented targets are evaluated independently and the most restrictive outcome wins. Policy persistence, locking, and rate limiting are part of the enforcement boundary. Key paths: `internal/engine/engine.go`, `internal/engine/matcher.go`, `internal/engine/policy.go`.

#### 4. Native hooks, adapters, and fallback interception
Integration-specific hook handlers translate Claude, Codex, Copilot, Cursor, Gemini, Cline, Antigravity, MCP, and OpenClaw host protocols into policy evaluations and host-compatible responses. OpenClaw is delivered as an embedded JavaScript plugin; Hermes is an embedded Python plugin. For non-native agents, the CLI provides a cooperative shell wrapper and a C `LD_PRELOAD`/process-preload boundary with explicit coverage limits. Key paths: `cmd/rampart/cli/hook.go`, `cmd/rampart/cli/hook_openclaw.go`, `internal/plugin/openclaw/index.js`.

#### 5. Approval and identity-owned state
An `ask` decision creates approval state that is bound to the requesting credential/session rather than merely a broadly reusable ID. Native-capable integrations can own the human interaction in their host UI; CLI and service paths expose pending, approve, and deny operations where safe. Session, token, and secure ownership mechanisms protect this authorization state across OS platforms. Key paths: `internal/approval/store.go`, `internal/session/manager.go`, `internal/token/store.go`.

#### 6. Audit, evidence, reporting, and notifications
Every decision can be redacted and persisted as a hash-chained local audit record; readers, verification, rotation, and recovery links support evidence inspection. Audit data can be exported or rendered into compliance/HTML reports, emitted as CEF/syslog, and followed live. Approval and policy events may notify Slack, Discord, Microsoft Teams, or OpenClaw, while webhook actions support external automation. Key paths: `internal/audit/record.go`, `internal/audit/verify.go`, `internal/notify/notifier.go`.

#### 7. Long-running service, dashboard, and external interfaces
`rampart serve` runs a local HTTP control plane with authentication, policy reload, evaluation, approval, audit, rule, metrics, SSE, and webhook endpoints. It serves an embedded dashboard and can be installed/managed as a background service on Unix or Windows. MCP support is a JSON-RPC stdio proxy that correlates requests/responses and enforces policy before forwarding to command-launched MCP servers. Public embedding surfaces include a Go SDK and a separate Python SDK. Key paths: `internal/proxy/server.go`, `internal/mcp/proxy.go`, `pkg/sdk/engine.go`.

#### 8. Distribution and policy supply
The repository builds a Go binary and container image, with install scripts for Unix and Windows. Shipped baseline, profile, and community policies are embedded for offline use; a policy registry supports discovery and synchronization. Runtime dependencies are predominantly local filesystem, OS process/service APIs, and agent-host protocols; network use is optional for registry sync, webhooks, notifications, syslog, and operator-selected MCP servers. Key paths: `policies/embed.go`, `registry/registry.json`, `Dockerfile`.

Main entry points: [`internal/engine/engine.go`](https://github.com/peg/rampart/blob/main/internal/engine/engine.go) (Policy engine), [`internal/proxy/server.go`](https://github.com/peg/rampart/blob/main/internal/proxy/server.go) (Local HTTP control plane), [`cmd/rampart/cli/setup.go`](https://github.com/peg/rampart/blob/main/cmd/rampart/cli/setup.go) (Protect & setup), [`internal/audit/record.go`](https://github.com/peg/rampart/blob/main/internal/audit/record.go) (Tamper-evident audit)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Operator &amp; Deployment"]
  node_binary{{"Rampart binary<br/>Go executable<br/>[main.go]"}}
  node_cli["CLI orchestration<br/>Cobra CLI<br/>[root.go]"]
  node_setup["Protect &amp; setup<br/>integration installer<br/>[setup.go]"]
  node_verify["Verify runtime<br/>CLI verification<br/>[verify.go]"]
  node_distribution["Binary &amp; container distribution<br/>release artifact"]
end

subgraph group_enforcement["Enforcement Core"]
  node_policy_supply["Embedded policy supply<br/>policy catalog<br/>[embed.go]"]
  node_registry[("Policy registry<br/>sync catalog<br/>[registry.json]")]
  node_engine{{"Policy engine<br/>decision engine<br/>[engine.go]"}}
  node_matcher["Rule matcher<br/>policy matcher<br/>[matcher.go]"]
  node_policy_state[("Policy state &amp; limits<br/>persistence boundary<br/>[policy.go]")]
end

subgraph group_integrations["Host Integrations"]
  node_native_hooks["Native host hooks<br/>protocol adapters<br/>[hook.go]"]
  node_openclaw["OpenClaw plugin<br/>embedded JavaScript plugin<br/>[index.js]"]
  node_fallback["Fallback interception<br/>shell and preload boundary"]
  node_mcp["MCP proxy<br/>JSON-RPC stdio proxy<br/>[proxy.go]"]
end

subgraph group_control["Control Plane"]
  node_approvals[("Approval store<br/>ownership-bound authorization<br/>[store.go]")]
  node_sessions[("Session &amp; token state<br/>secure identity state<br/>[manager.go]")]
  node_service["Local HTTP control plane<br/>HTTP service<br/>[server.go]"]
  node_dashboard["Embedded dashboard<br/>operator UI"]
  node_sdk["Go SDK<br/>embedding API<br/>[engine.go]"]
end

subgraph group_evidence["Evidence &amp; External Outputs"]
  node_audit[("Tamper-evident audit<br/>hash-chained evidence store<br/>[record.go]")]
  node_audit_verify["Audit verification<br/>evidence verifier<br/>[verify.go]"]
  node_reporting["Reports &amp; exports<br/>compliance output"]
  node_notifications["Notifications &amp; webhooks<br/>external automation<br/>[notifier.go]"]
end

node_binary -->|"starts"| node_cli
node_cli -->|"runs"| node_setup
node_cli -->|"runs"| node_verify
node_setup -->|"installs"| node_native_hooks
node_setup -->|"configures"| node_openclaw
node_setup -->|"enables"| node_fallback
node_verify -.->|"checks runtime behavior"| node_native_hooks
node_native_hooks -->|"normalized actions"| node_engine
node_openclaw -->|"host protocol actions"| node_native_hooks
node_fallback -->|"intercepted actions"| node_engine
node_mcp -->|"evaluates requests"| node_engine
node_policy_supply -->|"loads defaults"| node_engine
node_registry -.->|"syncs optional policies"| node_policy_supply
node_engine -->|"evaluates conditions"| node_matcher
node_engine -->|"reads policy and limits"| node_policy_state
node_engine -->|"creates ask state"| node_approvals
node_sessions -->|"binds requester ownership"| node_approvals
node_engine -->|"records decisions"| node_audit
node_engine -.->|"emits policy events"| node_notifications
node_approvals -.->|"emits approval events"| node_notifications
node_service -->|"evaluation API"| node_engine
node_service -->|"pending and resolution API"| node_approvals
node_service -->|"audit API"| node_audit
node_service -->|"serves"| node_dashboard
node_sdk -->|"embeds"| node_engine
node_audit -->|"verifies chain"| node_audit_verify
node_audit -->|"exports evidence"| node_reporting
node_distribution -->|"packages"| node_binary

click node_binary "https://github.com/peg/rampart/blob/main/cmd/rampart/main.go"
click node_cli "https://github.com/peg/rampart/blob/main/cmd/rampart/cli/root.go"
click node_setup "https://github.com/peg/rampart/blob/main/cmd/rampart/cli/setup.go"
click node_verify "https://github.com/peg/rampart/blob/main/cmd/rampart/cli/verify.go"
click node_policy_supply "https://github.com/peg/rampart/blob/main/policies/embed.go"
click node_registry "https://github.com/peg/rampart/blob/main/registry/registry.json"
click node_engine "https://github.com/peg/rampart/blob/main/internal/engine/engine.go"
click node_matcher "https://github.com/peg/rampart/blob/main/internal/engine/matcher.go"
click node_policy_state "https://github.com/peg/rampart/blob/main/internal/engine/policy.go"
click node_native_hooks "https://github.com/peg/rampart/blob/main/cmd/rampart/cli/hook.go"
click node_openclaw "https://github.com/peg/rampart/blob/main/internal/plugin/openclaw/index.js"
click node_mcp "https://github.com/peg/rampart/blob/main/internal/mcp/proxy.go"
click node_approvals "https://github.com/peg/rampart/blob/main/internal/approval/store.go"
click node_sessions "https://github.com/peg/rampart/blob/main/internal/session/manager.go"
click node_service "https://github.com/peg/rampart/blob/main/internal/proxy/server.go"
click node_audit "https://github.com/peg/rampart/blob/main/internal/audit/record.go"
click node_audit_verify "https://github.com/peg/rampart/blob/main/internal/audit/verify.go"
click node_notifications "https://github.com/peg/rampart/blob/main/internal/notify/notifier.go"
click node_sdk "https://github.com/peg/rampart/blob/main/pkg/sdk/engine.go"
click node_distribution "https://github.com/peg/rampart/blob/main/Dockerfile"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_binary,node_cli,node_setup,node_verify,node_distribution toneBlue
class node_policy_supply,node_registry,node_engine,node_matcher,node_policy_state toneAmber
class node_native_hooks,node_openclaw,node_fallback,node_mcp toneMint
class node_approvals,node_sessions,node_service,node_dashboard,node_sdk toneRose
class node_audit,node_audit_verify,node_reporting,node_notifications toneIndigo
```

## Components

### Operator & Deployment

- [Rampart binary](https://github.com/peg/rampart/blob/main/cmd/rampart/main.go): Go executable · Local security control-plane entry point. · `cmd/rampart/main.go`
- [CLI orchestration](https://github.com/peg/rampart/blob/main/cmd/rampart/cli/root.go): Cobra CLI · `cmd/rampart/cli/root.go`
- [Protect & setup](https://github.com/peg/rampart/blob/main/cmd/rampart/cli/setup.go): integration installer · Detects agents and writes validated host configuration. · `cmd/rampart/cli/setup.go`
- [Verify runtime](https://github.com/peg/rampart/blob/main/cmd/rampart/cli/verify.go): CLI verification · Separates installed configuration from observed runtime behavior. · `cmd/rampart/cli/verify.go`
- [Binary & container distribution](https://github.com/peg/rampart/blob/main/Dockerfile): release artifact · Go binary, container image, and platform install scripts. · `Dockerfile`

### Enforcement Core

- [Embedded policy supply](https://github.com/peg/rampart/blob/main/policies/embed.go): policy catalog · Offline baseline, profile, and community policies. · `policies/embed.go`
- [Policy registry](https://github.com/peg/rampart/blob/main/registry/registry.json): sync catalog · Optional policy discovery and synchronization source. · `registry/registry.json`
- [Policy engine](https://github.com/peg/rampart/blob/main/internal/engine/engine.go): decision engine · Loads policy and returns allow, ask, or deny. · `internal/engine/engine.go`
- [Rule matcher](https://github.com/peg/rampart/blob/main/internal/engine/matcher.go): policy matcher · Matches tool, command, path, network, and temporal conditions. · `internal/engine/matcher.go`
- [Policy state & limits](https://github.com/peg/rampart/blob/main/internal/engine/policy.go): persistence boundary · Policy persistence, locking, and rate limiting. · `internal/engine/policy.go`

### Host Integrations

- [Native host hooks](https://github.com/peg/rampart/blob/main/cmd/rampart/cli/hook.go): protocol adapters · Normalizes supported agent protocols and returns host-compatible decisions. · `cmd/rampart/cli/hook.go`
- [OpenClaw plugin](https://github.com/peg/rampart/blob/main/internal/plugin/openclaw/index.js): embedded JavaScript plugin · `internal/plugin/openclaw/index.js`
- **Fallback interception**: shell and preload boundary · Cooperative shell wrapper plus LD_PRELOAD/process-preload coverage.
- [MCP proxy](https://github.com/peg/rampart/blob/main/internal/mcp/proxy.go): JSON-RPC stdio proxy · Enforces before forwarding to command-launched MCP servers. · `internal/mcp/proxy.go`

### Control Plane

- [Approval store](https://github.com/peg/rampart/blob/main/internal/approval/store.go): ownership-bound authorization · Ask state is bound to requesting credential or session. · `internal/approval/store.go`
- [Session & token state](https://github.com/peg/rampart/blob/main/internal/session/manager.go): secure identity state · `internal/session/manager.go`
- [Local HTTP control plane](https://github.com/peg/rampart/blob/main/internal/proxy/server.go): HTTP service · Evaluation, approval, audit, policy, metrics, SSE, and webhook endpoints. · `internal/proxy/server.go`
- **Embedded dashboard**: operator UI
- [Go SDK](https://github.com/peg/rampart/blob/main/pkg/sdk/engine.go): embedding API · `pkg/sdk/engine.go`

### Evidence & External Outputs

- [Tamper-evident audit](https://github.com/peg/rampart/blob/main/internal/audit/record.go): hash-chained evidence store · Redacts and persists decision records with verification support. · `internal/audit/record.go`
- [Audit verification](https://github.com/peg/rampart/blob/main/internal/audit/verify.go): evidence verifier · `internal/audit/verify.go`
- **Reports & exports**: compliance output · Renders exports, HTML reports, CEF, syslog, and live streams.
- [Notifications & webhooks](https://github.com/peg/rampart/blob/main/internal/notify/notifier.go): external automation · Sends approval and policy events to selected integrations. · `internal/notify/notifier.go`

## Connections

- Rampart binary → CLI orchestration: starts
- CLI orchestration → Protect & setup: runs
- CLI orchestration → Verify runtime: runs
- Protect & setup → Native host hooks: installs
- Protect & setup → OpenClaw plugin: configures
- Protect & setup → Fallback interception: enables
- Verify runtime → Native host hooks: checks runtime behavior
- Native host hooks → Policy engine: normalized actions
- OpenClaw plugin → Native host hooks: host protocol actions
- Fallback interception → Policy engine: intercepted actions
- MCP proxy → Policy engine: evaluates requests
- Embedded policy supply → Policy engine: loads defaults
- Policy registry → Embedded policy supply: syncs optional policies
- Policy engine → Rule matcher: evaluates conditions
- Policy engine → Policy state & limits: reads policy and limits
- Policy engine → Approval store: creates ask state
- Session & token state → Approval store: binds requester ownership
- Policy engine → Tamper-evident audit: records decisions
- Policy engine → Notifications & webhooks: emits policy events
- Approval store → Notifications & webhooks: emits approval events
- Local HTTP control plane → Policy engine: evaluation API
- Local HTTP control plane → Approval store: pending and resolution API
- Local HTTP control plane → Tamper-evident audit: audit API
- Local HTTP control plane → Embedded dashboard: serves
- Go SDK → Policy engine: embeds
- Tamper-evident audit → Audit verification: verifies chain
- Tamper-evident audit → Reports & exports: exports evidence
- Binary & container distribution → Rampart binary: packages
