Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ OPENCLAW_ANTHROPIC_API_KEY=sk-ant-api03-your-key-here
OPENCLAW_GATEWAY_TOKEN=your-gateway-token-here
# OpenCode API key for OpenCode Go access via cliproxyapi
OPENCODE_API_KEY=your-opencode-api-key-here
# Paperclip database URL
DATABASE_URL=postgres://user:password@host:5432/paperclip
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ launchctl-tmux-session-logger: ## Restart tmux-session-logger launchd agent.
##@ Systemd Services (Linux)

.PHONY: systemctl
systemctl: systemctl-cliproxyapi systemctl-cliproxyapi-backup systemctl-code-syncer systemctl-docker-postgres systemctl-dotfiles-updater systemctl-make-updater systemctl-neverssl-keepalive systemctl-ollama systemctl-openclaw systemctl-tmux-session-logger ## Restart all systemd user services.
systemctl: systemctl-cliproxyapi systemctl-cliproxyapi-backup systemctl-code-syncer systemctl-docker-postgres systemctl-dotfiles-updater systemctl-make-updater systemctl-neverssl-keepalive systemctl-ollama systemctl-openclaw systemctl-paperclip systemctl-tmux-session-logger ## Restart all systemd user services.

.PHONY: systemctl-cliproxyapi
systemctl-cliproxyapi: ## Restart cliproxyapi systemd user service.
Expand Down Expand Up @@ -873,6 +873,16 @@ systemctl-openclaw: ## Restart OpenClaw gateway systemd user service.
fi
@echo "✅ openclaw restarted"

.PHONY: systemctl-paperclip
systemctl-paperclip: ## Restart Paperclip systemd user service.
@echo "🔄 Restarting paperclip..."
@if [ "$(DETECTED_HOST)" = "kyber" ] || [ "$(HOST)" = "kyber" ]; then \
systemctl --user daemon-reload; \
systemctl --user restart paperclip.service; \
else \
echo "Skipping paperclip.service (host not kyber)"; \
fi
@echo "✅ paperclip restarted"

.PHONY: systemctl-tmux-session-logger
systemctl-tmux-session-logger: ## Restart tmux-session-logger systemd timer and service.
Expand Down
373 changes: 370 additions & 3 deletions bun.lock

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions config/claude/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,10 @@
executable = true;
force = true;
};

home.file.".claude/hooks/auto-switch.sh" = {
source = ./hooks/auto-switch.sh;
executable = true;
force = true;
};
}
14 changes: 7 additions & 7 deletions config/claude/hooks/auto-switch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@

set -euo pipefail

# Require cswap
if ! command -v cswap &>/dev/null; then
# Require cswap and jq
if ! command -v cswap &>/dev/null || ! command -v jq &>/dev/null; then
exit 0
fi

# Require at least 2 managed accounts
ACCOUNT_COUNT=$(cswap --list 2>/dev/null | grep -c '^\s*[0-9]' || echo 0)
ACCOUNT_COUNT=$(cswap --list 2>/dev/null | grep -c '^[[:space:]]*[0-9]' || printf '0')

Copilot AI Apr 5, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grep -c prints 0 even when it exits with status 1 (no matches). With || printf '0', that can yield a value like 0\n0, which then breaks the numeric -lt test under set -e. Prefer ACCOUNT_COUNT=$(cswap --list 2>/dev/null | grep -c '^[[:space:]]*[0-9]' || true) and then default ACCOUNT_COUNT=${ACCOUNT_COUNT:-0} if needed.

Suggested change
ACCOUNT_COUNT=$(cswap --list 2>/dev/null | grep -c '^[[:space:]]*[0-9]' || printf '0')
ACCOUNT_COUNT=$(cswap --list 2>/dev/null | grep -c '^[[:space:]]*[0-9]' || true)
ACCOUNT_COUNT=${ACCOUNT_COUNT:-0}

Copilot uses AI. Check for mistakes.
if [ "$ACCOUNT_COUNT" -lt 2 ]; then
exit 0
fi

# Read hook input from stdin
INPUT=$(cat)
ERROR=$(echo "$INPUT" | jq -r '.error // empty' 2>/dev/null) || true
ERROR_DETAILS=$(echo "$INPUT" | jq -r '.error_details // empty' 2>/dev/null) || true
ERROR=$(printf '%s' "$INPUT" | jq -r '.error // empty' 2>/dev/null) || true
ERROR_DETAILS=$(printf '%s' "$INPUT" | jq -r '.error_details // empty' 2>/dev/null) || true

# Check if the error is rate-limit related
case "${ERROR}${ERROR_DETAILS}" in
*rate_limit*|*rate-limit*|*rate\ limit*|*overloaded*|*too_many_requests*|*429*|*quota*|*capacity*)
echo "[$(date)] Auto-switching Claude account due to rate limit" >&2
*rate_limit* | *rate-limit* | *rate\ limit* | *overloaded* | *too_many_requests* | *429* | *quota* | *capacity*)
printf '[%s] Auto-switching Claude account due to rate limit\n' "$(date)" >&2
cswap --switch 2>&1 | head -5 >&2
;;
esac
1 change: 1 addition & 0 deletions config/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ in
./llm
./openclaw
./omp
./paperclip
./opencode
./pi
./serena
Expand Down
23 changes: 23 additions & 0 deletions config/paperclip/config.template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"$meta": {
"version": 1,
"updatedAt": "2026-04-04T00:00:00.000Z",
"source": "configure"
},
"database": {
"mode": "__DATABASE_MODE__",
"connectionString": "__DATABASE_CONNECTION_STRING__"
},
"logging": {
"mode": "file"
},
"server": {
"deploymentMode": "__DEPLOYMENT_MODE__",
"exposure": "private",
"host": "__HOST__",
"port": 3100,
"allowedHostnames": [
"__ALLOWED_HOSTNAME__"
]
}
}
28 changes: 28 additions & 0 deletions config/paperclip/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
config,
pkgs,
inputs,
...
}:
let
inherit (inputs) host;
homeDir = config.home.homeDirectory;
instanceDir = "${homeDir}/.paperclip/instances/default";

setupScript = pkgs.replaceVars ./hydrate.sh {
instance_dir = instanceDir;
template = "${./config.template.json}";
sed = "${pkgs.gnused}/bin/sed";
database_mode = if host.isKyber then "postgres" else "embedded-postgres";
database_connection_string = "";
deployment_mode = if host.isKyber then "authenticated" else "local_trusted";
host = if host.isKyber then "0.0.0.0" else "127.0.0.1";
allowed_hostname = if host.isKyber then "paperclip.shunkakinoki.com" else "";
is_kyber = if host.isKyber then "true" else "false";
Comment on lines +15 to +21

Copilot AI Apr 5, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On kyber, database_mode is set to postgres but database_connection_string is substituted as an empty string. If DATABASE_URL is not present in ${HOME}/dotfiles/.env, this will hydrate an invalid config (and the DB provisioning block will be skipped). Either provide a sensible default connection string for kyber or fail fast when @is_kyber@ is true and DATABASE_URL is unset.

Copilot uses AI. Check for mistakes.
};
in
{
home.activation.paperclipConfig = config.lib.dag.entryAfter [ "writeBoundary" ] ''
${pkgs.bash}/bin/bash ${setupScript} || true
'';
}
41 changes: 41 additions & 0 deletions config/paperclip/hydrate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bash
set -euo pipefail

INSTANCE_DIR="@instance_dir@"
CONFIG="${INSTANCE_DIR}/config.json"
TEMPLATE="@template@"
ENV_FILE="${HOME}/dotfiles/.env"

# Source .env if it exists (for DATABASE_URL)
if [ -f "$ENV_FILE" ]; then
set -a
# shellcheck source=/dev/null
. "$ENV_FILE"
set +a
fi

mkdir -p "${INSTANCE_DIR}"

# Use DATABASE_URL from env if set, otherwise use the Nix default
DB_CONNECTION="${DATABASE_URL:-@database_connection_string@}"

@sed@ \
-e "s|__DATABASE_MODE__|@database_mode@|g" \
-e "s|__DATABASE_CONNECTION_STRING__|${DB_CONNECTION}|g" \
-e "s|__DEPLOYMENT_MODE__|@deployment_mode@|g" \
-e "s|__HOST__|@host@|g" \
-e "s|__ALLOWED_HOSTNAME__|@allowed_hostname@|g" \
"$TEMPLATE" >"$CONFIG"
Comment on lines +20 to +28

Copilot AI Apr 5, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DB_CONNECTION is interpolated directly into a sed replacement. If the connection string contains &, |, or backslashes (or other sed-special chars), the generated JSON can be corrupted (e.g. & expands to the matched text). Consider escaping the replacement string before sed substitution, or generate config.json via jq (parse template and set fields) to avoid fragile string replacement.

Copilot uses AI. Check for mistakes.
chmod 600 "$CONFIG"

# Create paperclip database on k8s postgres if needed
# @is_kyber@ is substituted by Nix replaceVars
# shellcheck disable=SC2050
if [ "@is_kyber@" = "true" ] && [ -n "$DB_CONNECTION" ]; then
if command -v psql >/dev/null 2>&1; then
DB_BASE="${DB_CONNECTION%/*}/postgres"
if ! psql "$DB_BASE" -tAc "SELECT 1 FROM pg_database WHERE datname='paperclip'" 2>/dev/null | grep -q 1; then
psql "$DB_BASE" -c "CREATE DATABASE paperclip" 2>/dev/null && echo "Created paperclip database" >&2
fi
fi
fi
1 change: 1 addition & 0 deletions home-manager/modules/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
./bin-shells
./cargo-globals
./openclaw
./paperclip
./local-binaries
./local-scripts
./npm-globals
Expand Down
13 changes: 13 additions & 0 deletions home-manager/modules/npm-globals/install-npm-globals.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,17 @@ if [ -n "$DEPS" ]; then
bun install --global $DEPS 2>/dev/null || true
fi

# Apply dependency overrides to the global install
# Bun's flat hoisting can resolve incompatible versions (e.g. pino@10 vs pino-http@10.5)
OVERRIDES=$(jq -c '.overrides // empty' "$PACKAGE_JSON" 2>/dev/null || true)
if [ -n "$OVERRIDES" ]; then
GLOBAL_PKG="${HOME}/.bun/install/global/package.json"
if [ -f "$GLOBAL_PKG" ]; then
jq --argjson overrides "$OVERRIDES" '.overrides = $overrides' "$GLOBAL_PKG" >"${GLOBAL_PKG}.tmp" &&
mv "${GLOBAL_PKG}.tmp" "$GLOBAL_PKG"
(cd "${HOME}/.bun/install/global" && bun install 2>/dev/null || true)
echo "Applied dependency overrides to global install"
fi
fi

echo "npm globals installation complete"
51 changes: 51 additions & 0 deletions home-manager/modules/paperclip/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
config,
lib,
inputs,
...
}:
let
inherit (inputs) host;
homeDir = config.home.homeDirectory;
in
# Only enable on kyber (server host)
lib.mkIf host.isKyber {
# Ensure Paperclip directories exist with correct permissions
home.activation.paperclipSetup = config.lib.dag.entryAfter [ "writeBoundary" ] ''
mkdir -p /tmp/paperclip

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This manual directory creation in /tmp can be removed if you adopt the RuntimeDirectory approach suggested for the systemd service below. Using a fixed directory name in /tmp can lead to permission conflicts or collision issues on multi-user systems.

mkdir -p ${homeDir}/.paperclip
chmod 700 ${homeDir}/.paperclip
Comment on lines +13 to +17

Copilot AI Apr 5, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logs are written to /tmp/paperclip/paperclip.log, but /tmp/paperclip is created without restrictive permissions. That can allow other local users to read logs or mount symlink attacks on the log path. Consider using systemd RuntimeDirectory/StateDirectory or at least chmod 700 /tmp/paperclip and ensure the log file is created with mode 600 in a non-world-writable directory.

Copilot uses AI. Check for mistakes.
'';

# Systemd service for Paperclip
systemd.user.services.paperclip = {
Unit = {
Description = "Paperclip AI agent orchestration platform";
After = [ "network-online.target" ];
Wants = [ "network-online.target" ];
};
Service = {
Type = "simple";
ExecStart = "${homeDir}/.bun/bin/paperclipai run --no-repair";
Restart = "always";
RestartSec = "5s";
Environment = [
"HOME=${homeDir}"
"HOST=0.0.0.0"
"PAPERCLIP_DEPLOYMENT_MODE=authenticated"
"PAPERCLIP_ALLOWED_HOSTNAMES=paperclip.shunkakinoki.com,172.17.0.1"
"PATH=${homeDir}/.local/bin:${homeDir}/.bun/bin:${homeDir}/.nix-profile/bin:${homeDir}/.local/share/pnpm:${homeDir}/.local/share/fnm/current/bin:${homeDir}/.npm-global/bin:/usr/local/bin:/usr/bin:/bin"
];
EnvironmentFile = [
"${homeDir}/dotfiles/.env"
"${homeDir}/.paperclip/instances/default/.env"

Copilot AI Apr 5, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EnvironmentFile entries are required by systemd unless prefixed with -. ${homeDir}/.paperclip/instances/default/.env is not created by this module/config hydration, so the service can fail to start on first run. Consider prefixing it with - to make it optional, or creating an empty file during activation.

Suggested change
"${homeDir}/.paperclip/instances/default/.env"
"-${homeDir}/.paperclip/instances/default/.env"

Copilot uses AI. Check for mistakes.
];
WorkingDirectory = "${homeDir}/.paperclip";
StandardOutput = "append:/tmp/paperclip/paperclip.log";
StandardError = "append:/tmp/paperclip/paperclip.log";
};
Comment on lines +27 to +46

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Instead of manually creating /tmp/paperclip and hardcoding log paths there, you can use systemd's RuntimeDirectory and the %t specifier (which resolves to $XDG_RUNTIME_DIR for user services). This is cleaner, avoids permission issues in shared /tmp environments, and ensures the directory is managed by systemd.

    Service = {
      Type = "simple";
      ExecStart = "${homeDir}/.bun/bin/paperclipai run --no-repair";
      Restart = "always";
      RestartSec = "5s";
      Environment = [
        "HOME=${homeDir}"
        "HOST=0.0.0.0"
        "PAPERCLIP_DEPLOYMENT_MODE=authenticated"
        "PAPERCLIP_ALLOWED_HOSTNAMES=paperclip.shunkakinoki.com,172.17.0.1"
        "PATH=${homeDir}/.local/bin:${homeDir}/.bun/bin:${homeDir}/.nix-profile/bin:${homeDir}/.local/share/pnpm:${homeDir}/.local/share/fnm/current/bin:${homeDir}/.npm-global/bin:/usr/local/bin:/usr/bin:/bin"
      ];
      EnvironmentFile = [
        "${homeDir}/dotfiles/.env"
        "${homeDir}/.paperclip/instances/default/.env"
      ];
      WorkingDirectory = "${homeDir}/.paperclip";
      RuntimeDirectory = "paperclip";
      StandardOutput = "append:%t/paperclip/paperclip.log";
      StandardError = "append:%t/paperclip/paperclip.log";
    };

Install = {
WantedBy = [ "default.target" ];
};
};
}
7 changes: 2 additions & 5 deletions home-manager/nix/nix.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@
"nix-command"
"flakes"
];
use-xdg-base-directories = true;
substituters = [
"https://cache.nixos.org"
extra-substituters = [
"https://cache.garnix.io"
"https://cloudtide.cachix.org"
"https://nix-community.cachix.org"
"https://yazi.cachix.org"
];
trusted-public-keys = [
"cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
extra-trusted-public-keys = [
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
"cache.garnix.io:CTFPyKSLcx5RMJKfLo5EEPUObbA78b0YQ2DTCJXqr9g="
"cloudtide.cachix.org-1:9NZ1Mah2+u8cd/CmVffFV23z5uFNpZSrhfgTt5fuN/4="
Expand Down
1 change: 1 addition & 0 deletions home-manager/services/docker-postgres/start-postgres.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ ensure_container() {
-p "${HOST_PORT}:${CONTAINER_PORT}" \
-e POSTGRES_DB=trails_api \
-e POSTGRES_PASSWORD=postgres \
-e POSTGRES_HOST_AUTH_METHOD=trust \

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-high high

Enabling POSTGRES_HOST_AUTH_METHOD=trust is a security risk when the database port is exposed to the host (line 47). It allows any user on the system to connect to the database without a password, effectively ignoring the POSTGRES_PASSWORD requirement. It is safer to remove this line and rely on password authentication.

Comment on lines 47 to +50

Copilot AI Apr 5, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting POSTGRES_HOST_AUTH_METHOD=trust disables password authentication and, combined with -p 5432:5432 (binds on all interfaces by default), exposes an unauthenticated Postgres instance to the network. Recommend removing POSTGRES_HOST_AUTH_METHOD=trust and relying on password auth, and/or binding the published port to localhost (e.g. 127.0.0.1:5432:5432) if this is only for local development.

Suggested change
-p "${HOST_PORT}:${CONTAINER_PORT}" \
-e POSTGRES_DB=trails_api \
-e POSTGRES_PASSWORD=postgres \
-e POSTGRES_HOST_AUTH_METHOD=trust \
-p "127.0.0.1:${HOST_PORT}:${CONTAINER_PORT}" \
-e POSTGRES_DB=trails_api \
-e POSTGRES_PASSWORD=postgres \

Copilot uses AI. Check for mistakes.
"$IMAGE"
log "Container '$CONTAINER_NAME' created and started"
fi
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"mcporter": "^0.8.1",
"open-composer": "^0.8.23",
"openclaw": "^2026.3.28",
"paperclipai": "^2026.403.0-canary.10",
"oxfmt": "^0.42.0",
"oxlint": "^1.57.0",
"portless": "^0.7.2",
Expand All @@ -66,6 +67,9 @@
"vite-plus": "^0.1.14",
"xcodebuildmcp": "^2.3.1"
},
"overrides": {
"pino": "9.14.0"
},
"trustedDependencies": [
"@anthropic-ai/claude-code",
"@augmentcode/auggie",
Expand Down Expand Up @@ -112,6 +116,7 @@
"mcporter",
"open-composer",
"openclaw",
"paperclipai",
"oxfmt",
"oxlint",
"portless",
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ tools = [
"aider-chat>=0.86.2",
"marker-pdf>=1.10.2",
"mistral-vibe>=2.7.0",
"claude-swap>=1.1.5",
"claude-swap>=0.7.1",
"ruff>=0.15.8",
]

Expand Down
Loading
Loading