#!/bin/bash

# Agent 1: Syntax Analyzer
# Finds all syntax errors in the provisioning codebase
# Token-efficient: ~1500 tokens total

echo "🔍 Launching Syntax Analyzer Agent..."

# Create knowledge bundle for agent
KNOWLEDGE=$(cat << 'EOF'
# Syntax Analysis Task

## Find These Patterns:
1. $"(get-provisioning-X)? | default "") " → Missing outer parentheses
2. ^$"(get-provisioning-name))" → Extra parentheses
3. Broken function calls in expressions
4. Missing parentheses in command substitution

## Focus Areas:
- core/nulib/servers/*.nu
- core/nulib/main_provisioning/*.nu
- core/nulib/lib_provisioning/utils/*.nu
- core/nulib/taskservs/*.nu

## Output Format:
```json
{
  "syntax_errors": [
    {"file": "path/to/file.nu", "line": 55, "error": "missing parentheses", "pattern": "$\"(get-function)?"},
    ...
  ],
  "files_checked": 45,
  "total_errors": 12
}
```

## Test Command:
Use: nu --ide-check FILE_PATH
EOF
)

# Launch Claude Code agent
claude-code task \
  --description "Find syntax errors in provisioning codebase" \
  --prompt "$KNOWLEDGE

TASK: Analyze .nu files for syntax errors
SCOPE: Core provisioning modules (servers, main_provisioning, utils, taskservs)
OUTPUT: JSON report with file paths, line numbers, and error types" \
  --type "general-purpose" \
  > .migration/state/syntax_analysis.json

echo "✅ Syntax analysis complete. Results in .migration/state/syntax_analysis.json"
echo "📊 Run: cat .migration/state/syntax_analysis.json | jq"