---
name: check-version
description: Verify version alignment between package.json and documentation
context: fork
agent: Explore
model: haiku
allowed-tools: Read, Glob, Grep, Bash
---

## Current state (auto-injected)
- Package version: !`node -p "require('./package.json').version" 2>/dev/null || echo "no package.json"`

<objective>
Verify that the version in `package.json` is aligned with all documentation files in `.documentation/`.
Use before releases or as part of release process to ensure documentation is up-to-date.
</objective>

<quick_start>
```bash
/check-version            # Check version alignment (interactive)
/check-version:fix        # Auto-update all doc files
/check-version:report     # Detailed report without prompts
```
</quick_start>

<subcommands>

| Command | Description |
|---------|-------------|
| `/check-version` | Check alignment, prompt to fix if mismatches |
| `/check-version:fix` | Auto-update documentation versions |
| `/check-version:report` | Detailed report without prompts |

</subcommands>

<workflow>

## Step 1: Read Package Version

```bash
PKG_VERSION=$(cat package.json | grep -oP '"version":\s*"\K[^"]+' | head -1)
echo "Package version: $PKG_VERSION"
```

## Step 2: Scan Documentation Files

```bash
echo "Scanning documentation files..."

for file in .documentation/*.html; do
  if [ -f "$file" ]; then
    DOC_VERSION=$(grep -oP 'version-badge">v?\K[^<]+' "$file" | head -1)
    if [ -n "$DOC_VERSION" ]; then
      FILENAME=$(basename "$file")
      DOC_VERSION_CLEAN=${DOC_VERSION#v}

      if [ "$DOC_VERSION_CLEAN" = "$PKG_VERSION" ]; then
        echo "OK $FILENAME: v$DOC_VERSION_CLEAN"
      else
        echo "MISMATCH $FILENAME: v$DOC_VERSION_CLEAN (expected v$PKG_VERSION)"
      fi
    fi
  fi
done
```

## Step 3: Generate Report

Display results:
```
================================================================================
                    VERSION ALIGNMENT CHECK
================================================================================

Package version: vX.Y.Z
Documentation files checked: N
Mismatches found: M

STATUS: PASSED | FAILED
================================================================================
```

## Step 4: Handle Mismatches (Interactive)

If mismatches detected, ask user:

```yaml
questions:
  - header: "Fix versions"
    question: "Des fichiers de documentation ont des versions obsoletes. Voulez-vous les mettre a jour automatiquement?"
    options:
      - label: "Oui, mettre a jour (Recommended)"
        description: "Met a jour tous les fichiers avec la version actuelle"
      - label: "Non, ignorer"
        description: "Continuer sans corriger les versions"
    multiSelect: false
```

</workflow>

<fix_command>

## /check-version:fix

Auto-update all documentation files:

```bash
PKG_VERSION=$(cat package.json | grep -oP '"version":\s*"\K[^"]+' | head -1)

echo "Updating documentation to v$PKG_VERSION..."

UPDATED_COUNT=0

for file in .documentation/*.html; do
  if [ -f "$file" ]; then
    DOC_VERSION=$(grep -oP 'version-badge">v?\K[^<]+' "$file" | head -1)
    if [ -n "$DOC_VERSION" ]; then
      DOC_VERSION_CLEAN=${DOC_VERSION#v}
      if [ "$DOC_VERSION_CLEAN" != "$PKG_VERSION" ]; then
        sed -i "s/version-badge\">v[^<]*/version-badge\">v$PKG_VERSION/" "$file"
        UPDATED_COUNT=$((UPDATED_COUNT + 1))
        echo "UPDATED $(basename "$file"): v$DOC_VERSION_CLEAN -> v$PKG_VERSION"
      fi
    fi
  fi
done

echo ""
if [ "$UPDATED_COUNT" -gt 0 ]; then
  echo "OK $UPDATED_COUNT file(s) updated"
  echo ""
  echo "Next steps:"
  echo "  1. Review changes: git diff .documentation/"
  echo "  2. Commit: /gitflow commit"
fi
```

</fix_command>

<report_command>

## /check-version:report

Detailed report without prompts:

```
================================================================================
         VERSION ALIGNMENT DETAILED REPORT
================================================================================

Package: @atlashub/smartstack-cli
Current version: vX.Y.Z

---------------------------------------------------------------------
FILE                          | DOC VERSION | STATUS
---------------------------------------------------------------------
guide.html                    | vX.Y.Z      | OK
api-reference.html            | vX.Y.Y      | MISMATCH
---------------------------------------------------------------------
```

</report_command>

<gitflow_integration>

This skill is automatically called during `/gitflow finish` for release branches.

If mismatches detected during release finish:
- Warning displayed
- User prompted to fix with `/check-version:fix`
- Release blocked until versions aligned

</gitflow_integration>

<files_checked>

- `.documentation/*.html` - All HTML documentation files
- Pattern: `<span class="version-badge">vX.Y.Z</span>`

</files_checked>

<exit_codes>

| Code | Meaning |
|------|---------|
| 0 | All versions aligned |
| 1 | Mismatches detected (blocking for releases) |

</exit_codes>

<success_criteria>
- All version references compared against package.json version
- Mismatches clearly listed with file path and current vs expected values
- Exit code 0 when aligned, exit code 1 when mismatched
- Fix subcommand updates all references successfully
</success_criteria>
