How peg/rampart works
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: engine.go Policy engine · server.go Local HTTP control plane · setup.go Protect & setup · record.go Tamper-evident audit
Components 23
Operator & Deployment
- Rampart binary · Local security control-plane entry point.
cmd/rampart/main.go - CLI orchestration
cmd/rampart/cli/root.go - Protect & setup · Detects agents and writes validated host configuration.
cmd/rampart/cli/setup.go - Verify runtime · Separates installed configuration from observed runtime behavior.
cmd/rampart/cli/verify.go - Binary & container distribution · Go binary, container image, and platform install scripts.
Dockerfile
Enforcement Core
- Embedded policy supply · Offline baseline, profile, and community policies.
policies/embed.go - Policy registry · Optional policy discovery and synchronization source.
registry/registry.json - Policy engine · Loads policy and returns allow, ask, or deny.
internal/engine/engine.go - Rule matcher · Matches tool, command, path, network, and temporal conditions.
internal/engine/matcher.go - Policy state & limits · Policy persistence, locking, and rate limiting.
internal/engine/policy.go
Host Integrations
- Native host hooks · Normalizes supported agent protocols and returns host-compatible decisions.
cmd/rampart/cli/hook.go - OpenClaw plugin
internal/plugin/openclaw/index.js - Fallback interception · Cooperative shell wrapper plus LD_PRELOAD/process-preload coverage.
- MCP proxy · Enforces before forwarding to command-launched MCP servers.
internal/mcp/proxy.go
Control Plane
- Approval store · Ask state is bound to requesting credential or session.
internal/approval/store.go - Session & token state
internal/session/manager.go - Local HTTP control plane · Evaluation, approval, audit, policy, metrics, SSE, and webhook endpoints.
internal/proxy/server.go - Embedded dashboard
- Go SDK
pkg/sdk/engine.go
Evidence & External Outputs
- Tamper-evident audit · Redacts and persists decision records with verification support.
internal/audit/record.go - Audit verification
internal/audit/verify.go - Reports & exports · Renders exports, HTML reports, CEF, syslog, and live streams.
- Notifications & webhooks · Sends approval and policy events to selected integrations.
internal/notify/notifier.go
Connections 28
- 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