Configuration Files

View configuration files used by the AI Agent. These files are read-only - modify the source files and redeploy to make changes.

Static Files

5

Runtime Configs

2

Files Found

3

Total Size

16.8 KB

Available Files

entrypoint.sh

5.8 KB

claude-hook.sh

4.3 KB

Dockerfile

Missing

appsettings.json

6.8 KB

docker-compose.yml

Missing

entrypoint.sh
Docker container startup script - configures SSH, Git, Claude CLI, MCP servers, and hooks
bash
Docker
174 lines
01/21/2026 14:03
/app/entrypoint.sh
#!/bin/bash
set -e

# Fix ownership of mounted volumes (running as root initially)
echo "[entrypoint] Fixing volume permissions..."
chown -R agent:agent /workspaces /home/agent /app/logs 2>/dev/null || true

# Setup SSH if keys are provided via volume mount
if [ -d "/ssh-keys" ] && [ "$(ls -A /ssh-keys 2>/dev/null)" ]; then
    echo "[entrypoint] Configuring SSH keys..."
    cp -r /ssh-keys/* /home/agent/.ssh/ 2>/dev/null || true
    chmod 700 /home/agent/.ssh
    chmod 600 /home/agent/.ssh/* 2>/dev/null || true
    chown -R agent:agent /home/agent/.ssh
fi

# Configure git for agent user
echo "[entrypoint] Configuring git..."
su - agent -c "git config --global user.email '[email protected]'"
su - agent -c "git config --global user.name 'AI Agent'"
su - agent -c "git config --global safe.directory '*'"

# Claude CLI configuration directory and subdirectories
echo "[entrypoint] Setting up Claude CLI directories..."
mkdir -p /home/agent/.claude/projects /home/agent/.claude/shell-snapshots /home/agent/.claude/todos

# Setup hook scripts
echo "[entrypoint] Setting up Claude Code hooks..."
mkdir -p /app/hooks
if [ -f "/app/claude-hook.sh" ]; then
    cp /app/claude-hook.sh /app/hooks/claude-hook.sh
    chmod +x /app/hooks/claude-hook.sh
    chown agent:agent /app/hooks/claude-hook.sh
    echo "[entrypoint] Hook script installed at /app/hooks/claude-hook.sh"
fi

# Configure MCP server connection using Claude CLI
MCP_URL="${MCP_SERVER_URL:-http://localhost:6800/mcp}"

echo "[entrypoint] Configuring AIAgent MCP server..."
echo "[entrypoint] MCP URL: $MCP_URL"

# Use claude mcp add command - the official and most reliable way
# First remove existing aiagent config if force reconfiguration is requested
if [ "${FORCE_MCP_CONFIG:-false}" = "true" ]; then
    echo "[entrypoint] Force MCP config enabled, removing existing aiagent server..."
    su - agent -c "claude mcp remove aiagent" 2>/dev/null || true
fi

# Check if aiagent is already configured
if su - agent -c "claude mcp list" 2>/dev/null | grep -q "aiagent"; then
    echo "[entrypoint] aiagent MCP server already configured"
else
    echo "[entrypoint] Adding aiagent MCP server via CLI..."
    su - agent -c "claude mcp add --transport http aiagent '$MCP_URL'"
    echo "[entrypoint] aiagent MCP server added successfully"
fi

echo "[entrypoint] MCP configuration complete"
echo "[entrypoint] Verifying MCP servers:"
su - agent -c "claude mcp list"

# Configure Claude Code hooks
# Hooks call our API for context injection, pattern enforcement, and knowledge base
HOOKS_API="${HOOKS_API_URL:-http://localhost:6800}"
SETTINGS_FILE="/home/agent/.claude/settings.json"

echo "[entrypoint] Configuring Claude Code hooks..."

if [ "${ENABLE_HOOKS:-true}" = "true" ] && [ -f "/app/hooks/claude-hook.sh" ]; then
    # Check if hooks are already configured
    if [ -f "$SETTINGS_FILE" ] && grep -q '"hooks"' "$SETTINGS_FILE" 2>/dev/null; then
        if [ "${FORCE_HOOKS_CONFIG:-false}" = "true" ]; then
            echo "[entrypoint] Reconfiguring hooks (FORCE_HOOKS_CONFIG=true)..."
        else
            echo "[entrypoint] Hooks already configured, skipping..."
        fi
    fi

    # Create or update settings.json with hooks configuration
    if [ ! -f "$SETTINGS_FILE" ] || [ "${FORCE_HOOKS_CONFIG:-false}" = "true" ]; then
        echo "[entrypoint] Writing hooks configuration to $SETTINGS_FILE"
        cat > "$SETTINGS_FILE" << 'HOOKS_EOF'
{
  "hooks": {
    "SessionStart": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "HOOKS_API_URL=\"$HOOKS_API\" PERSONA_CODE=\"$PERSONA_CODE\" /app/hooks/claude-hook.sh session-start",
            "timeout": 30
          }
        ]
      }
    ],
    "UserPromptSubmit": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "HOOKS_API_URL=\"$HOOKS_API\" PERSONA_CODE=\"$PERSONA_CODE\" /app/hooks/claude-hook.sh prompt",
            "timeout": 10
          }
        ]
      }
    ],
    "PreToolUse": [
      {
        "matcher": "*",
        "hooks": [
          {
            "type": "command",
            "command": "HOOKS_API_URL=\"$HOOKS_API\" PERSONA_CODE=\"$PERSONA_CODE\" /app/hooks/claude-hook.sh pre-tool",
            "timeout": 10
          }
        ]
      }
    ],
    "PostToolUse": [
      {
        "matcher": "Write|Edit|Bash",
        "hooks": [
          {
            "type": "command",
            "command": "HOOKS_API_URL=\"$HOOKS_API\" PERSONA_CODE=\"$PERSONA_CODE\" /app/hooks/claude-hook.sh post-tool",
            "timeout": 10
          }
        ]
      }
    ],
    "Stop": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "HOOKS_API_URL=\"$HOOKS_API\" PERSONA_CODE=\"$PERSONA_CODE\" /app/hooks/claude-hook.sh stop",
            "timeout": 10
          }
        ]
      }
    ],
    "Setup": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "HOOKS_API_URL=\"$HOOKS_API\" PERSONA_CODE=\"$PERSONA_CODE\" /app/hooks/claude-hook.sh setup",
            "timeout": 30
          }
        ]
      }
    ]
  }
}
HOOKS_EOF
        # Replace placeholder with actual API URL
        sed -i "s|\$HOOKS_API|$HOOKS_API|g" "$SETTINGS_FILE"
        chown agent:agent "$SETTINGS_FILE"
        echo "[entrypoint] Hooks configuration complete"
    fi
else
    echo "[entrypoint] Hooks disabled or hook script not found, skipping..."
fi

# Ignore errors from files we can't change (e.g., git pack files from host)
chown -R agent:agent /home/agent/.claude 2>/dev/null || echo "[entrypoint] Warning: Some .claude files couldn't be chowned (this is usually OK)"
chmod -R 755 /home/agent/.claude 2>/dev/null || true

echo "[entrypoint] Starting AI Agent application..."

# Switch to agent user and run the application
exec gosu agent dotnet AppKit.Tools.AIAgent.dll