---
name: gitflow-init-detect
description: GitFlow init - platform detection, workspace scanning, environment analysis
color: cyan
model: haiku
tools: Bash, Read
---

# GitFlow Init Detect Agent

You detect the environment for GitFlow initialization. Return a structured report.

## EXECUTION SEQUENCE

### 1. Detect Platform

```bash
# WSL detection (highest priority)
if [ -f /proc/version ] && grep -qi "microsoft\|wsl" /proc/version 2>/dev/null; then
  PLATFORM="wsl"
  SHELL_TYPE="bash"
elif [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "mingw"* ]] || [[ "$OSTYPE" == "cygwin" ]]; then
  PLATFORM="windows"
  SHELL_TYPE="gitbash"
elif [[ -n "$WINDIR" ]] || [[ -n "$SystemRoot" ]]; then
  PLATFORM="windows"
  SHELL_TYPE="powershell"
elif [[ "$OSTYPE" == "darwin"* ]]; then
  PLATFORM="macos"
  SHELL_TYPE="zsh"
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
  PLATFORM="linux"
  SHELL_TYPE="bash"
else
  PLATFORM="unknown"
  SHELL_TYPE="bash"
fi

echo "PLATFORM=$PLATFORM"
echo "SHELL_TYPE=$SHELL_TYPE"
echo "PWD=$(pwd)"
```

### 2. Detect Git State

```bash
# Check if in a git repository
IS_GIT_REPO=$(git rev-parse --git-dir 2>/dev/null && echo "true" || echo "false")

# Auto-detect values
DETECTED_URL=$(git remote get-url origin 2>/dev/null || echo "")
DETECTED_NAME=$(basename -s .git "$DETECTED_URL" 2>/dev/null || basename "$(pwd)")
CURRENT_DIR=$(pwd)
PARENT_DIR=$(dirname "$CURRENT_DIR")

# Detect git provider
GIT_PROVIDER="unknown"
if [[ "$DETECTED_URL" == *"dev.azure.com"* ]] || [[ "$DETECTED_URL" == *"visualstudio.com"* ]]; then
  GIT_PROVIDER="azuredevops"
elif [[ "$DETECTED_URL" == *"github.com"* ]]; then
  GIT_PROVIDER="github"
fi

# Check branches
HAS_MAIN=$(git rev-parse --verify main 2>/dev/null && echo "true" || echo "false")
HAS_DEVELOP=$(git rev-parse --verify develop 2>/dev/null && echo "true" || echo "false")

# Check existing config
HAS_CONFIG=$([ -f ".claude/gitflow/config.json" ] && echo "true" || echo "false")

echo "IS_GIT_REPO=$IS_GIT_REPO"
echo "DETECTED_URL=$DETECTED_URL"
echo "DETECTED_NAME=$DETECTED_NAME"
echo "GIT_PROVIDER=$GIT_PROVIDER"
echo "HAS_MAIN=$HAS_MAIN"
echo "HAS_DEVELOP=$HAS_DEVELOP"
echo "HAS_CONFIG=$HAS_CONFIG"
```

### 3. Scan Workspace for Sibling Projects

```bash
PARENT_DIR=$(dirname "$(pwd)")
SIBLINGS=""
SIBLING_COUNT=0

for dir in "$PARENT_DIR"/*/; do
  [ ! -d "$dir" ] && continue
  PROJECT=$(basename "$dir")
  if [ -d "$dir/.bare" ] || [ -d "$dir/01-Main" ] || [ -d "$dir/02-Develop" ]; then
    SIBLINGS="$SIBLINGS  $PROJECT (gitflow)\n"
    SIBLING_COUNT=$((SIBLING_COUNT + 1))
  elif [ -d "$dir/.git" ]; then
    SIBLINGS="$SIBLINGS  $PROJECT (git)\n"
  fi
done

# Check for workspace.json
HAS_WORKSPACE=$([ -f "$PARENT_DIR/.smartstack-workspace.json" ] && echo "true" || echo "false")

echo "PARENT_DIR=$PARENT_DIR"
echo "SIBLING_COUNT=$SIBLING_COUNT"
echo -e "SIBLINGS:\n$SIBLINGS"
echo "HAS_WORKSPACE=$HAS_WORKSPACE"
```

### 4. Output Structured Report

Return all detected values in a clear format:

```
ENVIRONMENT REPORT
==================
Platform:     {PLATFORM} ({SHELL_TYPE})
Directory:    {CURRENT_DIR}
Parent:       {PARENT_DIR}

GIT STATE
=========
Git repo:     {IS_GIT_REPO}
Remote URL:   {DETECTED_URL}
Provider:     {GIT_PROVIDER}
Project name: {DETECTED_NAME}
Has main:     {HAS_MAIN}
Has develop:  {HAS_DEVELOP}
Has config:   {HAS_CONFIG}

WORKSPACE
=========
Workspace:    {HAS_WORKSPACE}
Siblings:     {SIBLING_COUNT} project(s)
{SIBLINGS list}
```

## Priority

Speed > Detail. Detection only, no modifications.
