16 KiB
PaperClip
Docker- and Caddy-based infrastructure for orchestrating AI agents with PaperClip, Hermes Agent, PostgreSQL, and AGE-encrypted secrets.
Overview
PaperClip is a platform for orchestrating AI agents operated via Docker Compose and Caddy. This repository provides the complete server bootstrap, reverse-proxy configuration, encrypted secret management, and runtime patches needed to deploy PaperClip, PostgreSQL 17, and Hermes Agent onto a fresh Linux host (such as a Hetzner CX23).
Internet (80/443)
│
▼
┌──────────────┐ paperclip-net (Docker internal)
│ Caddy ├───────────────────────────────────┐
│ (HTTPS/TLS) │ │
└──────┬───────┘ ▼
│ ┌─────────────────┐
│ │ Hermes Agent │
│ │ :8642 (Gateway) │
│ │ :9119 (Web UI) │
▼ └─────────────────┘
┌──────────────┐ ┌────────────────────┐
│ PaperClip ├─────────►│ PostgreSQL 17 │
│ :3100 │ │ :5432 │
│ (+hermes CLI)│ └────────────────────┘
└──────────────┘
All persistent service data is stored as host bind mounts under /opt/PaperClip-Data/ (with Caddy state/certs in named Docker volumes caddy_data and caddy_config).
Features
- Idempotent Master Deployment (
deploy_script.sh): Safe to re-run at any time; provisions system packages (docker,age,fail2ban), swap, timezone (Europe/Berlin), Docker log rotation, and cron jobs. - Automatic Maintenance Mode: Replaces Caddy fragments with an HTTP
503maintenance page while containers are stopped and updated, then restores production routing automatically. - AGE Secret Management: Keeps plaintext
.envfiles out of Git via.gitignoreand stores encrypted.env.ageandshared.env.agefiles in the repository. - Modular Service Discovery: Services in
services/<name>/are activated simply by placing aservice.enabledmarker file alongsidedocker-compose.ymland optionalservice.pre_start,service.init, and<name>.caddyfiles. - Hermes Agent Integration: Supports both
hermes_local(in-container CLI insidepaperclip_app) andhermes_gateway(standalonehermescontainer). - Multi-Provider LLM Workarounds & Runtime Patches: Automatically configures alternative OpenAI-compatible providers (MiniMax, OpenRouter, Mistral, Poe, Gemini) and applies runtime fixes for
spawn E2BIG, onboarding validation, MiniMax 429 rate-limit backoff, and staleissueIdforeign-key guards. - Push Notifications (
ntfy): Sends deployment status, errors, and initial PaperClip bootstrap CEO invite URLs tohttps://ntfy.orfel.de/PaperClip.
How It Works & Tech Stack
| Component | Image / Tool | Container Name | Purpose & Ports |
|---|---|---|---|
| Reverse Proxy | caddy:2-alpine |
caddy |
Terminates HTTPS (Let's Encrypt) on host ports 80 and 443; routes subdomains via *.caddy fragments |
| Application | ghcr.io/paperclipai/paperclip:latest |
paperclip_app |
PaperClip server & UI on internal port 3100 (https://paperclip.orfel.de) |
| Database | postgres:17-alpine |
paperclip-postgres |
PostgreSQL 17 database on internal port 5432 |
| Agent Runtime | nousresearch/hermes-agent:latest |
hermes |
Standalone Hermes Gateway (8642, https://hermes.paperclip.orfel.de) & UI (9119, https://hermes-ui.paperclip.orfel.de) |
| Secret Encryption | age |
— | Decrypts services/shared.env.age and services/<name>/.env.age using keys/age-key.txt |
| Host Hardening | fail2ban, ufw/swap, cron |
— | SSH brute-force protection, 4 GB /swapfile, weekly Monday 01:23 reboot + @reboot deploy |
Deployment Lifecycle (deploy_script.sh)
- Installs system updates, Docker Engine/Compose,
age, andfail2ban. - Configures Docker JSON log limits (
50m, max3files),fail2banSSH jail (maxretry = 5,bantime = 3600,findtime = 600), a4Gswap file, timezoneEurope/Berlin, and cron jobs (weekly reboot +@rebootgit reset & re-deploy). - Verifies or prompts interactively for the AGE private key (
keys/age-key.txt,chmod 600). - Pulls the latest repository changes and re-executes itself if updated.
- Ensures the external Docker network
paperclip-netexists and discovers active services (docker-compose.yml+service.enabled). - Stops deactivated services, enables Caddy maintenance mode, stops non-infrastructure containers, decrypts
.env.agefiles, runsservice.pre_starthooks, creates/opt/PaperClip-Data/*directories, pulls/builds images, starts all services, restores production Caddy fragments, prunes old images, and runsservice.inithooks.
DNS & IPv6-Only Host Support (services/caddy/resolv.conf)
Caddy mounts a custom resolv.conf containing both Docker's embedded DNS (127.0.0.11) for internal service discovery (paperclip_app, paperclip-postgres, hermes) and public IPv4/IPv6 resolvers (1.1.1.1, 8.8.8.8, 2606:4700:4700::1111) for Let's Encrypt ACME validation—avoiding Docker Compose's dns: option, which would overwrite 127.0.0.11.
Prerequisites & Installation
Prerequisites
- A Debian/Ubuntu Linux server with
root(sudo) access - DNS records pointing your domains (
paperclip.orfel.de,hermes.paperclip.orfel.de,hermes-ui.paperclip.orfel.de) to the server - The AGE private key matching
keys/age-public-key.txt
Server Bootstrap & Deployment
Clone the repository to /opt/PaperClip and run the master deployment script as root:
sudo mkdir -p /opt/PaperClip
sudo git clone https://git.orfel.de/Jannik/PaperClip.git /opt/PaperClip
sudo bash /opt/PaperClip/deploy_script.sh
During the first run, if /opt/PaperClip/keys/age-key.txt does not exist, the script prompts you to paste the AGE-SECRET-KEY-... private key (hidden input) and saves it with chmod 600.
Note
Once PaperClip starts,
services/paperclip/service.initrunsnpx paperclipai onboard --yes --bind lanandnpx paperclipai auth bootstrap-ceo, printing the bootstrap CEO invite URL to stdout and pushing it tohttps://ntfy.orfel.de/PaperClip.
Configuration
Encrypted Environment Files (AGE)
Plaintext .env files and **/age-key.txt are excluded via .gitignore. Instead, encrypted .age files are committed to Git:
| File | Contents | Scope |
|---|---|---|
services/shared.env(.age) |
Shared API keys (OPENROUTER_API_KEY, MISTRAL_API_KEY, MINIMAX_API_KEY, POE_API_KEY, GEMINI_API_KEY, HERMES_API_KEY) |
All services |
services/paperclip/.env(.age) |
Service-specific secrets (POSTGRES_PASSWORD, BETTER_AUTH_SECRET, optional OPENAI_* overrides) |
paperclip & paperclip-postgres |
services/hermes/.env(.age) |
Service-specific variables (OPENROUTER_API_KEY) |
hermes |
After modifying any plaintext .env file locally, re-encrypt it with the repository's public key (keys/age-public-key.txt):
# Shared API keys (all services)
age -r age1sa3q5qxl5dylld7v839m9lkv5h7l457wq4h40pt7kfmcfhcqkfjqspdjpn -o services/shared.env.age services/shared.env
# Service-specific (e.g. PaperClip)
age -r age1sa3q5qxl5dylld7v839m9lkv5h7l457wq4h40pt7kfmcfhcqkfjqspdjpn -o services/paperclip/.env.age services/paperclip/.env
Automatic Pre-Start Configuration (services/paperclip/service.pre_start)
Before containers start:
- If
BETTER_AUTH_SECRETis missing inservices/paperclip/.env, a random 32-byte hex secret (openssl rand -hex 32) is appended. - If neither
OPENAI_API_KEYnorANTHROPIC_API_KEYis set inservices/paperclip/.env,service.pre_startreadsservices/shared.envand automatically setsOPENAI_BASE_URLandOPENAI_API_KEYin priority order: MiniMax (https://api.minimax.io/v1) → OpenRouter (https://openrouter.ai/api/v1) → Mistral (https://api.mistral.ai/v1).
PaperClip Service Environment (services/paperclip/docker-compose.yml)
PAPERCLIP_DEPLOYMENT_MODE:authenticatedPAPERCLIP_DEPLOYMENT_EXPOSURE:publicPAPERCLIP_AUTH_BASE_URL_MODE:explicitPAPERCLIP_PUBLIC_URL:https://paperclip.orfel.deHERMES_GATEWAY_ALLOW_INSECURE_HTTP:1PAPERCLIP_OPENCODE_PROVIDERS: JSON configuration pre-registeringopenrouter,mistral,minimax, andpoemodels for OpenCode.
Host Data Directories & Volumes
| Host Path / Volume | Container Target | Purpose |
|---|---|---|
/opt/PaperClip-Data/paperclip |
/paperclip (paperclip_app) |
PaperClip home & instance configuration |
/opt/PaperClip-Data/paperclip-db |
/var/lib/postgresql/data (paperclip-postgres) |
PostgreSQL 17 data directory |
/opt/PaperClip-Data/paperclip-hermes-venv |
/opt/hermes-venv (paperclip_app) |
Python venv for in-container hermes CLI |
/opt/PaperClip-Data/paperclip-hermes-data |
/home/node/.hermes (paperclip_app) |
Hermes config & .env for node user (UID 1000) |
/opt/PaperClip-Data/hermes |
/opt/data (hermes) |
Standalone Hermes Agent data |
/opt/PaperClip-Data/caddy/fragments |
/etc/caddy/fragments:ro (caddy) |
Assembled *.caddy reverse-proxy snippets |
caddy_data, caddy_config |
/data, /config (caddy) |
Caddy TLS certificates & state |
Usage
1. LLM Onboarding Workaround (OpenRouter / Mistral / MiniMax)
PaperClip's initial onboarding UI expects an official OpenAI or Anthropic key. To use alternative providers:
- Store your provider key (e.g.,
OPENROUTER_API_KEY=sk-or-v1-...orMINIMAX_API_KEY=...) inservices/shared.env(and re-encrypt toshared.env.age) orservices/paperclip/.env. service.pre_startsetsOPENAI_API_KEYandOPENAI_BASE_URL, andservices/paperclip/patch_paperclip.jspatches/app/server/dist/routes/ai-connections.jsinside the container so validation queries$OPENAI_BASE_URL/modelsinstead of hardcodinghttps://api.openai.com/v1/models.- Open the bootstrap CEO invite link, reach "Connect a model", click OpenAI (API), paste your OpenRouter / Mistral / MiniMax key, and click Connect.
2. Hermes Agent Integration
Hermes Agent is configured automatically during deployment via services/hermes/setup_hermes.sh (invoked by both paperclip/service.init and hermes/service.init):
hermes_local(Recommended / Default):- In the PaperClip Dashboard → "Hire Agent"
- Select adapter
hermes_local - PaperClip executes the
hermesCLI directly insidepaperclip_app(using/opt/hermes-venvwithanthropic==0.87.0,--query-fileE2BIG patch viapatch_hermes_queryfile.py, and MiniMax M Plan HTTP 429 long retry backoff20s → 45s → 75s → 90s → 120s → 150sviapatch_hermes_retries.py). API keys are copied fromservices/shared.envto/home/node/.hermes/.env.
hermes_gateway(Standalone):- In the PaperClip Dashboard → "Hire Agent"
- Select adapter
Hermes Gateway - Gateway URL:
http://hermes:8642(internal) orhttps://hermes.paperclip.orfel.de
To re-run Hermes setup manually:
sudo bash /opt/PaperClip/services/hermes/setup_hermes.sh
3. Additional Adapters
- OpenCode: Pre-configured in
services/paperclip/docker-compose.yml(PAPERCLIP_OPENCODE_PROVIDERS). In "Hire Agent", chooseOpenCodeand enter a model such asopenrouter/anthropic/claude-sonnet-4-5,openrouter/deepseek/deepseek-r1,openrouter/google/gemini-2.5-pro, oropenrouter/openai/gpt-4o. - Gemini CLI: Automatically receives
GEMINI_API_KEYfromservices/shared.env. In "Hire Agent", chooseGemini CLI.
4. Adding a New Service & Subdomain
- Create
services/<name>/docker-compose.ymlattached to the externalpaperclip-netnetwork. - Add an empty
services/<name>/service.enabledfile. - Drop a
services/<name>/<name>.caddyfile:subdomain.orfel.de { reverse_proxy <container-name>:<port> } - Re-run
sudo bash /opt/PaperClip/deploy_script.sh.
Note
services/caddy/README.mdstill references/mnt/Jannik-Cloud-Volume-01/caddy/as a legacy path; the activedocker-compose.ymlanddeploy_script.shassemble fragments under/opt/PaperClip-Data/caddy/fragments.
5. Runtime Patches Applied by patch_paperclip.js
- Hermes
--query-file(execute.ts): Writes large prompts to/tmp/hermes-prompt-<runId>.txtinstead of passing them inargv(preventsspawn E2BIG). - Environment Size Guard (
server-utils.ts): Drops child environment variables exceeding32768bytes to preventE2BIG. - Custom Base URL (
ai-connections.js): HonorsOPENAI_BASE_URLduring model validation. - Terminal Provider Error Detection (
execute.ts): Surfaces fatal provider errors (API call failed after ... retries,Final error:,insufficient_balance_error) even when Hermes exits0. - Stale
issueIdGuard (workspace-operations.ts): Checks whetherinput.issueIdstill exists inissuesbefore inserting intoworkspace_operations, avoiding foreign-key failures on stale wake payloads.
Project Structure
PaperClip/
├── assets/
│ └── logo.png # Project logo
├── keys/
│ └── age-public-key.txt # AGE public key for encrypting .env files
├── services/
│ ├── shared.env.age # Encrypted shared API keys (all services)
│ ├── caddy/
│ │ ├── Caddyfile # Main Caddy config importing fragments/*.caddy
│ │ ├── docker-compose.yml # Caddy 2 Alpine container (ports 80/443)
│ │ ├── README.md # Caddy reverse proxy notes
│ │ ├── resolv.conf # Docker DNS (127.0.0.11) + public IPv4/IPv6 DNS
│ │ ├── service.enabled # Marks Caddy service as active
│ │ └── service.init # Ensures fragments dir & Caddyfile exist
│ ├── hermes/
│ │ ├── .env.age # Encrypted Hermes environment variables
│ │ ├── docker-compose.yml # Standalone Hermes Agent service
│ │ ├── hermes.caddy # Caddy routes for hermes & hermes-ui
│ │ ├── patch_hermes_queryfile.py # Adds --query-file support to hermes_cli
│ │ ├── patch_hermes_retries.py # Long 429 retry backoff for MiniMax M Plan
│ │ ├── service.enabled # Marks Hermes service as active
│ │ ├── service.init # Calls setup_hermes.sh with restart flag
│ │ └── setup_hermes.sh # Installs & configures Hermes CLI in paperclip_app
│ └── paperclip/
│ ├── .env.age # Encrypted Postgres password & auth secret
│ ├── docker-compose.yml # PaperClip app + Postgres 17
│ ├── paperclip.caddy # Caddy route for paperclip.orfel.de
│ ├── patch_paperclip.js # Runtime patches inside paperclip_app
│ ├── service.enabled # Marks PaperClip service as active
│ ├── service.pre_start # Generates BETTER_AUTH_SECRET & OPENAI_* overrides
│ └── service.init # Runs patches, onboarding, bootstrap-ceo & diagnostics
├── .gitignore # Excludes plaintext .env, age-key.txt, fragments, logs
├── contents.json # Repository metadata file
└── deploy_script.sh # Idempotent master server bootstrap & deploy script
License
Private / Internal Project
