#!/bin/bash # TypeScript-based issue handler using Claude Agent SDK # This script replaces the old bash-based Claude Code implementation # Ensure HOME is set (systemd might not set it) if [ -z "$HOME" ]; then export HOME=$(getent passwd "$(whoami)" | cut -d: -f6) fi # Add NODE 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" PUSHER="$3" ISSUE_NUMBER="$4" ISSUE_TITLE="$5" ISSUE_BODY="$6" ISSUE_ACTION="$7" COMMENT_BODY="$8" ASSIGNEE="$9" # Exit if pusher is claude (avoid loops) if [ "$PUSHER" = "claude" ]; then echo "Pusher is claude, skipping automation to avoid loops" exit 0 fi # Exit if issue is not assigned to claude if [ "$ASSIGNEE" != "claude" ]; then echo "Issue not assigned to claude (assignee: $ASSIGNEE), skipping" exit 0 fi # Determine repo path REPO_PATH="$HOME/$REPO" # Check if repo exists, if not clone it if [ ! -d "$REPO_PATH" ]; then echo "Repository not found at $REPO_PATH, cloning..." mkdir -p "$HOME" GIT_URL="ssh://git@207.154.220.231:10022/$OWNER/$REPO.git" git clone "$GIT_URL" "$REPO_PATH" if [ $? -ne 0 ]; then echo "Failed to clone repository" exit 1 fi echo "Repository cloned successfully" else echo "Repository found at $REPO_PATH" # Pull latest changes cd "$REPO_PATH" || exit 1 echo "Pulling latest changes..." # 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 cd "$REPO_PATH" || exit 1 echo "Working directory: $(pwd)" echo "Calling Claude Agent SDK TypeScript client..." echo "---" # Get the path to the agent-manager directory AGENT_MANAGER_DIR="/data/agent-manager" # Call the TypeScript client node "$AGENT_MANAGER_DIR/client/dist/index.js" \ "$OWNER" \ "$REPO" \ "$PUSHER" \ "$ISSUE_NUMBER" \ "$ISSUE_TITLE" \ "$ISSUE_BODY" \ "$ISSUE_ACTION" \ "${COMMENT_BODY:-}" \ "${ASSIGNEE:-}" EXIT_CODE=$? echo "---" echo "Claude Agent SDK execution completed (exit code: $EXIT_CODE)" exit $EXIT_CODE