AgentSkillsCN

Setup Plugin Env

Bootstrap Jira 插件环境——创建虚拟环境、安装依赖项、验证环境配置。

SKILL.md
--- frontmatter
description: Bootstrap jira plugin environment - creates venv, installs dependencies, validates setup

Plugin Environment Setup Skill

This skill handles the bootstrap process for jira plugin commands.

Purpose

Creates .claude/cpr.sh (Claude Plugin Root resolver) if it doesn't exist, then runs the plugin's setup_env.sh script.

This solves the chicken-and-egg problem where:

  • We need to call setup_env.sh from the plugin directory
  • But ${CLAUDE_PLUGIN_ROOT} is unreliable (issue #9354)
  • So we can't find the plugin directory without a fallback mechanism

Task

ALWAYS run this bootstrap FIRST before doing anything else in jira commands.

Step 1: Check if bootstrap is needed

Check if .claude/cpr.sh already exists:

bash
if [ -f ".claude/cpr.sh" ]; then
    echo "✓ Plugin environment already bootstrapped"
    # Skip to Step 3
else
    echo "📦 Bootstrapping plugin environment..."
    # Continue to Step 2
fi

If .claude/cpr.sh exists: Skip directly to Step 3.

If .claude/cpr.sh does NOT exist: Continue to Step 2.


Step 2: Create .claude/cpr.sh (only if needed)

ONLY execute this step if Step 1 determined that .claude/cpr.sh does not exist.

Create the Claude Plugin Root resolver script:

CRITICAL: You MUST use the Bash tool to execute the exact command below. Do NOT use the Write tool. The heredoc must be executed by bash to prevent variable expansion.

The heredoc delimiter 'CPREOF' is quoted (single quotes) to prevent ${CLAUDE_PLUGIN_ROOT} from being expanded. This is intentional - we want the literal string ${CLAUDE_PLUGIN_ROOT} in the script, not its current value.

bash
mkdir -p .claude
cat << 'CPREOF' > .claude/cpr.sh
#!/bin/bash
#
# Claude Plugin Root (CPR) Resolver
# Locates the jira plugin directory
#

# Try CLAUDE_PLUGIN_ROOT first
if [ -n "${CLAUDE_PLUGIN_ROOT}" ] && [ -d "${CLAUDE_PLUGIN_ROOT}" ]; then
    echo "${CLAUDE_PLUGIN_ROOT}"
    exit 0
fi

# Fallback: Look up via jq
if command -v jq &> /dev/null; then
    PLUGIN_ROOT=$(jq -r '.plugins | to_entries[] | select(.key | contains("jira")) | .value[0].installPath' "${HOME}/.claude/plugins/installed_plugins.json" 2>/dev/null)
    if [ -n "$PLUGIN_ROOT" ] && [ -d "$PLUGIN_ROOT" ]; then
        echo "${PLUGIN_ROOT%/}"
        exit 0
    fi
fi

# Fallback: Python-based lookup
PLUGIN_ROOT=$(python3 -c "
import json
try:
    with open('${HOME}/.claude/plugins/installed_plugins.json') as f:
        plugins = json.load(f)['plugins']
        for key, value in plugins.items():
            if 'jira' in key:
                print(value[0]['installPath'].rstrip('/'))
                break
except: pass
" 2>/dev/null)

if [ -n "$PLUGIN_ROOT" ] && [ -d "$PLUGIN_ROOT" ]; then
    echo "$PLUGIN_ROOT"
    exit 0
fi

# Failed to find plugin
echo "Error: Could not locate jira plugin" >&2
exit 1
CPREOF

chmod +x .claude/cpr.sh

Verification:

bash
if [ -x ".claude/cpr.sh" ]; then
    echo "✓ Created .claude/cpr.sh successfully"
else
    echo "✗ Failed to create .claude/cpr.sh" >&2
    exit 1
fi

Step 3: Run setup_env.sh

Execute the plugin's environment setup script:

bash
PLUGIN_ROOT="$(.claude/cpr.sh)"

if [ -z "$PLUGIN_ROOT" ]; then
    echo "✗ Failed to locate plugin root" >&2
    exit 1
fi

if [ ! -f "$PLUGIN_ROOT/scripts/setup_env.sh" ]; then
    echo "✗ setup_env.sh not found in plugin directory" >&2
    exit 1
fi

# Run setup script
bash "$PLUGIN_ROOT/scripts/setup_env.sh"

Step 4: Verify environment

Check that the environment is ready:

bash
VENV_PATH=".claude/jira/venv"

if [ ! -d "$VENV_PATH" ]; then
    echo "✗ Virtual environment not created" >&2
    exit 1
fi

# Check if Python dependencies are installed
if ! "$VENV_PATH/bin/python" -c "import atlassian" 2>/dev/null; then
    PLUGIN_ROOT="$(.claude/cpr.sh)"
    echo "⚠ Dependencies may not be fully installed"
    echo "Try running: source $VENV_PATH/bin/activate && pip install -r $PLUGIN_ROOT/requirements.txt"
else
    echo "✓ jira plugin environment is ready!"
fi

Success Indicators

After running this skill, you should see:

  • ✓ .claude/cpr.sh created (or already exists)
  • ✓ Virtual environment created at .claude/jira/venv
  • ✓ Python dependencies installed
  • ✓ Plugin environment ready for commands

Troubleshooting

If bootstrap fails:

  1. Ensure Python 3.8+ is installed
  2. Check that the plugin is properly installed in Claude Code
  3. Verify write permissions in .claude/ directory
  4. Check internet connectivity for pip install

If dependencies fail to install:

bash
PLUGIN_ROOT="$(.claude/cpr.sh)"
source ".claude/jira/venv/bin/activate"
pip install -r "$PLUGIN_ROOT/requirements.txt" --verbose