PaperClip Logo

PaperClip

Docker- and Caddy-based infrastructure for orchestrating AI agents with PaperClip, Hermes Agent, PostgreSQL, and AGE-encrypted secrets.

🇬🇧 English · 🇩🇪 Deutsch


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 503 maintenance page while containers are stopped and updated, then restores production routing automatically.
  • AGE Secret Management: Keeps plaintext .env files out of Git via .gitignore and stores encrypted .env.age and shared.env.age files in the repository.
  • Modular Service Discovery: Services in services/<name>/ are activated simply by placing a service.enabled marker file alongside docker-compose.yml and optional service.pre_start, service.init, and <name>.caddy files.
  • Hermes Agent Integration: Supports both hermes_local (in-container CLI inside paperclip_app) and hermes_gateway (standalone hermes container).
  • 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 stale issueId foreign-key guards.
  • Push Notifications (ntfy): Sends deployment status, errors, and initial PaperClip bootstrap CEO invite URLs to https://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)

  1. Installs system updates, Docker Engine/Compose, age, and fail2ban.
  2. Configures Docker JSON log limits (50m, max 3 files), fail2ban SSH jail (maxretry = 5, bantime = 3600, findtime = 600), a 4G swap file, timezone Europe/Berlin, and cron jobs (weekly reboot + @reboot git reset & re-deploy).
  3. Verifies or prompts interactively for the AGE private key (keys/age-key.txt, chmod 600).
  4. Pulls the latest repository changes and re-executes itself if updated.
  5. Ensures the external Docker network paperclip-net exists and discovers active services (docker-compose.yml + service.enabled).
  6. Stops deactivated services, enables Caddy maintenance mode, stops non-infrastructure containers, decrypts .env.age files, runs service.pre_start hooks, creates /opt/PaperClip-Data/* directories, pulls/builds images, starts all services, restores production Caddy fragments, prunes old images, and runs service.init hooks.

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.init runs npx paperclipai onboard --yes --bind lan and npx paperclipai auth bootstrap-ceo, printing the bootstrap CEO invite URL to stdout and pushing it to https://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:

  1. If BETTER_AUTH_SECRET is missing in services/paperclip/.env, a random 32-byte hex secret (openssl rand -hex 32) is appended.
  2. If neither OPENAI_API_KEY nor ANTHROPIC_API_KEY is set in services/paperclip/.env, service.pre_start reads services/shared.env and automatically sets OPENAI_BASE_URL and OPENAI_API_KEY in 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: authenticated
  • PAPERCLIP_DEPLOYMENT_EXPOSURE: public
  • PAPERCLIP_AUTH_BASE_URL_MODE: explicit
  • PAPERCLIP_PUBLIC_URL: https://paperclip.orfel.de
  • HERMES_GATEWAY_ALLOW_INSECURE_HTTP: 1
  • PAPERCLIP_OPENCODE_PROVIDERS: JSON configuration pre-registering openrouter, mistral, minimax, and poe models 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:

  1. Store your provider key (e.g., OPENROUTER_API_KEY=sk-or-v1-... or MINIMAX_API_KEY=...) in services/shared.env (and re-encrypt to shared.env.age) or services/paperclip/.env.
  2. service.pre_start sets OPENAI_API_KEY and OPENAI_BASE_URL, and services/paperclip/patch_paperclip.js patches /app/server/dist/routes/ai-connections.js inside the container so validation queries $OPENAI_BASE_URL/models instead of hardcoding https://api.openai.com/v1/models.
  3. 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):
    1. In the PaperClip Dashboard → "Hire Agent"
    2. Select adapter hermes_local
    3. PaperClip executes the hermes CLI directly inside paperclip_app (using /opt/hermes-venv with anthropic==0.87.0, --query-file E2BIG patch via patch_hermes_queryfile.py, and MiniMax M Plan HTTP 429 long retry backoff 20s → 45s → 75s → 90s → 120s → 150s via patch_hermes_retries.py). API keys are copied from services/shared.env to /home/node/.hermes/.env.
  • hermes_gateway (Standalone):
    1. In the PaperClip Dashboard → "Hire Agent"
    2. Select adapter Hermes Gateway
    3. Gateway URL: http://hermes:8642 (internal) or https://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", choose OpenCode and enter a model such as openrouter/anthropic/claude-sonnet-4-5, openrouter/deepseek/deepseek-r1, openrouter/google/gemini-2.5-pro, or openrouter/openai/gpt-4o.
  • Gemini CLI: Automatically receives GEMINI_API_KEY from services/shared.env. In "Hire Agent", choose Gemini CLI.

4. Adding a New Service & Subdomain

  1. Create services/<name>/docker-compose.yml attached to the external paperclip-net network.
  2. Add an empty services/<name>/service.enabled file.
  3. Drop a services/<name>/<name>.caddy file:
    subdomain.orfel.de {
        reverse_proxy <container-name>:<port>
    }
    
  4. Re-run sudo bash /opt/PaperClip/deploy_script.sh.

Note

services/caddy/README.md still references /mnt/Jannik-Cloud-Volume-01/caddy/ as a legacy path; the active docker-compose.yml and deploy_script.sh assemble 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>.txt instead of passing them in argv (prevents spawn E2BIG).
  • Environment Size Guard (server-utils.ts): Drops child environment variables exceeding 32768 bytes to prevent E2BIG.
  • Custom Base URL (ai-connections.js): Honors OPENAI_BASE_URL during 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 exits 0.
  • Stale issueId Guard (workspace-operations.ts): Checks whether input.issueId still exists in issues before inserting into workspace_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

This project's own code and configuration are dedicated to the public domain under CC0 1.0 Universal — see LICENSE.

External dependencies installed via package managers or Docker images retain their respective open-source licenses.

S
Description
Self-hosted Server-Infrastruktur (Docker, Caddy, PostgreSQL & Hermes Agent) zur Orchestrierung von PaperClipAI.
Readme CC0-1.0
1.8 GiB
0 Stars 1 Watchers 0 Forks
Languages
Shell 68.1%
Python 18%
JavaScript 13.9%