agent-governance/bin/ledger-api
profit 77655c298c Initial commit: Agent Governance System Phase 8
Phase 8 Production Hardening with complete governance infrastructure:

- Vault integration with tiered policies (T0-T4)
- DragonflyDB state management
- SQLite audit ledger
- Pipeline DSL and templates
- Promotion/revocation engine
- Checkpoint system for session persistence
- Health manager and circuit breaker for fault tolerance
- GitHub/Slack integrations
- Architectural test pipeline with bug watcher, suggestion engine, council review
- Multi-agent chaos testing framework

Test Results:
- Governance tests: 68/68 passing
- E2E workflow: 16/16 passing
- Phase 2 Vault: 14/14 passing
- Integration tests: 27/27 passing

Coverage: 57.6% average across 12 phases

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-23 22:07:06 -05:00

90 lines
2.1 KiB
Bash
Executable File

#!/bin/bash
#
# Ledger API Service
# ==================
# Starts the FastAPI ledger service
#
# Usage:
# ledger-api Start on default port (8080)
# ledger-api --port 8081 Start on custom port
# ledger-api --no-auth Disable authentication
#
set -euo pipefail
LEDGER_DIR="/opt/agent-governance/ledger"
VENV_DIR="${LEDGER_DIR}/.venv"
# Parse arguments
PORT="${LEDGER_API_PORT:-8080}"
AUTH="true"
while [[ $# -gt 0 ]]; do
case $1 in
--port)
PORT="$2"
shift 2
;;
--no-auth)
AUTH="false"
shift
;;
--help|-h)
cat << 'EOF'
Ledger API Service
==================
Usage:
ledger-api Start on default port (8080)
ledger-api --port 8081 Start on custom port
ledger-api --no-auth Disable Vault authentication
Environment Variables:
LEDGER_API_PORT Port to listen on (default: 8080)
LEDGER_API_AUTH Require Vault auth (default: true)
VAULT_ADDR Vault address (default: https://127.0.0.1:8200)
Endpoints:
GET /health Health check
GET /docs Swagger documentation
GET /agents List agents
GET /violations List violations
GET /promotions List promotions
GET /stats Overall statistics
EOF
exit 0
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
done
# Create venv if needed
if [[ ! -d "${VENV_DIR}" ]]; then
echo "Creating virtual environment..."
python3 -m venv "${VENV_DIR}" 2>/dev/null || {
echo "Installing dependencies globally..."
pip3 install -q fastapi uvicorn pydantic
}
fi
# Activate venv if it exists
if [[ -d "${VENV_DIR}" ]]; then
source "${VENV_DIR}/bin/activate"
# Install dependencies if needed
if ! python3 -c "import fastapi" 2>/dev/null; then
echo "Installing dependencies..."
pip install -q -r "${LEDGER_DIR}/requirements.txt"
fi
fi
# Export config
export LEDGER_API_PORT="${PORT}"
export LEDGER_API_AUTH="${AUTH}"
# Run API
exec python3 "${LEDGER_DIR}/api.py"