---
description: Verify AI-generated code for hallucinations and patterns (M10)
argument-hint: "[project-path]"
allowed-tools: Bash, Read, Write, Glob, Grep
---

Run AI code verification on a project to detect AI-generated code patterns and hallucinations.

## Steps

1. **Validate project path**
   - Default to `.` if no argument provided
   - Confirm the path exists

2. **Load AI verify config**
   - Look for `.vaspera/ai-verify.yaml`
   - If not found, use default configuration

3. **Run AI code verification**
   - Use `ai_code_verify` MCP tool
   - Scan for AI generation patterns
   - Check for hallucinated imports and APIs
   - Score files for AI likelihood

4. **Present pattern analysis**
   ```
   AI Pattern Analysis
   ===================
   Files scanned: 42
   
   Patterns by Confidence:
   ┌────────────┬───────┐
   │ Confidence │ Count │
   ├────────────┼───────┤
   │ High       │ 3     │
   │ Medium     │ 8     │
   │ Low        │ 15    │
   └────────────┴───────┘
   
   Top Files by AI Likelihood:
   - src/components/ChatBot.tsx (85%)
   - src/utils/helpers.ts (62%)
   - src/api/generate.ts (45%)
   ```

5. **Present hallucination findings**
   ```
   Hallucination Check
   ===================
   
   Critical Issues:
   - [CRITICAL] src/api/client.ts:12
     Package "react-native-awesome-button" does not exist
     → This is a known hallucinated package name
   
   High Severity:
   - [HIGH] src/utils/format.ts:5
     Import "./nonexistent-helper" does not resolve
     → Create the file or fix the import path
   
   Medium Severity:
   - [MEDIUM] src/components/Legacy.tsx:23
     "componentWillMount" deprecated since React 16.3
     → Replace with componentDidMount or useEffect
   ```

6. **Present scores**
   ```
   AI Code Verification Scores
   ===========================
   
   ┌────────────────────┬────────┬─────────────────────────────┐
   │ Metric             │ Score  │ Description                 │
   ├────────────────────┼────────┼─────────────────────────────┤
   │ Detection Score    │ 85/100 │ Lower AI likelihood = better│
   │ Hallucination Score│ 92/100 │ Fewer hallucinations = better│
   │ Review Score       │ 78/100 │ Fewer reviews needed = better│
   ├────────────────────┼────────┼─────────────────────────────┤
   │ Overall Score      │ 86/100 │ Weighted average            │
   └────────────────────┴────────┴─────────────────────────────┘
   
   Certification Level: 🟢 APPROVED
   → Code verified, minimal AI hallucinations detected
   ```

7. **List changes requiring review**
   ```
   Changes Requiring Human Review
   ==============================
   
   CRITICAL (must review):
   1. src/api/client.ts
      - Fabricated package import
      - AI likelihood: 95%
   
   HIGH (should review):
   2. src/components/ChatBot.tsx
      - Multiple AI generation markers
      - AI likelihood: 85%
   
   MEDIUM (optional review):
   3. src/utils/helpers.ts
      - TODO placeholder patterns
      - AI likelihood: 62%
   ```

## Config Format

Config is defined in `.vaspera/ai-verify.yaml`:

```yaml
detection:
  checkPatterns: true      # Look for AI code patterns
  checkComments: true      # Check for AI-indicating comments
  checkImports: true       # Verify imports exist
  checkMetadata: true      # Check for AI tool metadata

hallucination:
  checkImports: true       # Verify import paths resolve
  checkApis: true          # Check for deprecated/non-existent APIs
  checkVersions: true      # Verify API versions
  packageRegistry: npm     # npm, pypi, or crates

review:
  requireForConfidence: medium  # high, medium, or low
  requireForHallucinations: true
  autoApproveBelow: 30     # Auto-approve files below this AI likelihood %

exclude:
  - node_modules
  - dist
  - "*.test.*"
  - "*.spec.*"
```

## MCP Tools Used

- `ai_code_verify` — Full AI code verification
- `ai_code_quick` — Quick check for single file
- `ai_code_patterns` — Scan for AI patterns only
- `ai_code_hallucinations` — Check for hallucinations only
- `ai_code_config_generate` — Create sample config

## Scoring Breakdown

| Dimension | Weight | Description |
|-----------|--------|-------------|
| Detection | 30% | How likely code is AI-generated |
| Hallucination | 50% | Presence of non-existent imports/APIs |
| Review | 20% | Percentage requiring human review |

## Certification Levels

| Score | Level | Meaning |
|-------|-------|---------|
| 90-100 | CERTIFIED | Ship confidently |
| 70-89 | APPROVED | Ship with monitoring |
| 40-69 | REVIEW_REQUIRED | Fix hallucinations first |
| 0-39 | BLOCKED | Critical issues present |

## Important

- High AI likelihood doesn't mean the code is bad
- Focus on hallucinations (non-existent imports/APIs)
- Review critical and high priority changes manually
- Use `--files` to check specific changed files only
