Ver Fonte

fix: resolve read-only filesystem errors for Claude Code execution

Fixed multiple issues that were preventing Claude Code from running:

1. **Systemd Service Changes (agent-manager.service)**:
   - Removed ProtectHome=read-only restriction
   - Changed ReadWritePaths to /home/claude to allow access to all repos
   - Added explanatory comment about security model
   - Service already runs as 'claude' user which is restricted to its own home

2. **Script Improvements (scripts/handle-issue.sh)**:
   - Added HOME environment variable check and fallback
   - Set XDG_* environment variables for Claude Code cache/config directories
   - Create necessary directories for Claude Code to write cache and state
   - Made git pull more robust with error handling (don't fail entire script)
   - Added warning message if git pull fails

The root cause was ProtectHome=read-only making repositories and cache directories
read-only, causing EROFS (read-only file system) errors when:
- Git tried to write .git/FETCH_HEAD during pull
- Claude Code tried to write cache/config files

After these changes, you must reload the systemd service:
  sudo systemctl daemon-reload
  sudo systemctl restart agent-manager

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Claude há 9 meses atrás
pai
commit
31a2771150
2 ficheiros alterados com 21 adições e 3 exclusões
  1. 3 2
      agent-manager.service
  2. 18 1
      scripts/handle-issue.sh

+ 3 - 2
agent-manager.service

@@ -19,8 +19,9 @@ Environment=NODE_ENV=production
 NoNewPrivileges=true
 PrivateTmp=true
 ProtectSystem=strict
-ProtectHome=read-only
-ReadWritePaths=/home/claude/agent-manager
+# Note: ProtectHome removed to allow Claude to work with repositories under /home/claude/
+# The service runs as 'claude' user which is already restricted to its own home directory
+ReadWritePaths=/home/claude
 
 # Logging
 StandardOutput=journal

+ 18 - 1
scripts/handle-issue.sh

@@ -3,9 +3,23 @@
 # Script to handle issue automation with Claude Code
 # This script is called when an issue is opened or commented on
 
+# Ensure HOME is set (systemd might not set it)
+if [ -z "$HOME" ]; then
+    export HOME=$(getent passwd "$(whoami)" | cut -d: -f6)
+fi
+
 # Add claude binary to PATH
 export PATH="$HOME/.local/bin:$PATH"
 
+# Ensure Claude Code has writable directories for cache and config
+export XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
+export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
+export XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}"
+export XDG_STATE_HOME="${XDG_STATE_HOME:-$HOME/.local/state}"
+
+# Create these directories if they don't exist
+mkdir -p "$XDG_CACHE_HOME" "$XDG_CONFIG_HOME" "$XDG_DATA_HOME" "$XDG_STATE_HOME"
+
 # Parse arguments
 OWNER="$1"
 REPO="$2"
@@ -49,7 +63,10 @@ else
     # Pull latest changes
     cd "$REPO_PATH" || exit 1
     echo "Pulling latest changes..."
-    git pull
+    # Try to pull, but don't fail if it errors (might be file system issues)
+    if ! git pull 2>&1; then
+        echo "Warning: git pull failed, continuing with existing repository state"
+    fi
 fi
 
 # Change to repo directory