# Phase 01.0.5: CLI Availability Check [MANDATORY] (STORY-129)

**Purpose:** Verify devforgeai-validate CLI is installed before attempting CLI-based validations. Provides graceful fallback when CLI not available.

**When to execute:** After Phase 01.0 (Project Root Validation), before Phase 01.1 (Git Validation)

**Token Cost:** ~100 tokens

**Implementation:**

```bash
# Check if devforgeai-validate CLI is available
if ! command -v devforgeai-validate &> /dev/null; then
    CLI_AVAILABLE=false
    echo "WARN: devforgeai-validate CLI not installed"
    echo "  - Hook checks will be skipped"
    echo "  - Manual validation required"
else
    CLI_AVAILABLE=true
    DEVFORGEAI_VERSION=$(devforgeai-validate --version 2>/dev/null || echo "unknown")
    echo "✓ devforgeai-validate CLI: $DEVFORGEAI_VERSION"
fi

# Store for downstream use
$CLI_AVAILABLE = CLI_AVAILABLE
```

**Downstream Impact:**

When `CLI_AVAILABLE=false`, the following steps SKIP CLI calls:

| Step | CLI Command | Skip Message |
|------|-------------|--------------|
| Phase 01.X | `devforgeai-validate check-hooks` | "Skipping: CLI-based hook checks (CLI not available)" |
| Phase 06/07 | `devforgeai-validate validate-dod` | "Skipping: CLI DoD validation (CLI not available)" |
| Phase 01.5 | `devforgeai-validate validate-context` | "Skipping: CLI context validation (CLI not available)" |

**Fallback Validation When CLI Not Available:**

## Manual Validation Patterns (Claude Code Terminal Tools)

**Hook Eligibility (replaces devforgeai-validate check-hooks):**
```
Grep(pattern="operation: dev", path="src/devforgeai/config/hooks.yaml", output_mode="count")
If count > 0: Hooks enabled for dev operation
```

**DoD Validation (replaces devforgeai-validate validate-dod):**
```
Grep(pattern="^\\s*-\\s*\\[[ x]\\]", path="$STORY_FILE", output_mode="count")
Count represents number of DoD checkbox items
```

**Context Validation (replaces devforgeai-validate validate-context):**
```
For each context file, verify exists:
- Read(file_path="devforgeai/specs/context/tech-stack.md")
- Read(file_path="devforgeai/specs/context/source-tree/governance.json")
- Read(file_path="devforgeai/specs/context/dependencies.md")
- Read(file_path="devforgeai/specs/context/coding-standards.md")
- Read(file_path="devforgeai/specs/context/architecture-constraints.md")
- Read(file_path="devforgeai/specs/context/anti-patterns.md")

If ANY Read fails: Context incomplete - run /create-system-architecture
```

**Risks When CLI Validation Skipped:**

| Skipped Validation | Risk | Mitigation |
|-------------------|------|------------|
| Hook checks | Hooks may not trigger | Fallback Grep pattern detects hook config |
| DoD validation | Format errors may pass | Fallback regex validates checkboxes exist |
| Context validation | Missing files may not be detected early | Fallback Read validates 6 files exist |

**Success:** `CLI_AVAILABLE` variable set for downstream steps to check.

**Failure:** N/A - this step always succeeds (produces warning, never blocks).
