Skip to content

team-telnyx/ai / providers/claude/plugins/telnyx-platform/skills/telnyx-twilio-migration

telnyx-twilio-migration

Unverified

Migrate from Twilio to Telnyx. Orchestrates a complete 6-phase migration: discovery, planning, setup, code migration, validation, and cleanup. Covers voice (TwiML to TeXML, Call Control API), messaging, WebRTC, SIP trunking, verify, fax, video, IoT, number lookup, and porting. Includes automated scanners, validation scripts, and integration tests.

FileKindSize
SKILL.mdskill md43.3 KB
references/account-setup-guide.mdmarkdown17.8 KB
references/error-code-mapping.mdmarkdown11.0 KB
references/fax-migration.mdmarkdown14.7 KB
references/iot-migration.mdmarkdown17.9 KB
references/lookup-migration.mdmarkdown14.3 KB
references/messaging-migration.mdmarkdown36.5 KB
references/mobile-sdk-migration.mdmarkdown38.6 KB
references/number-porting.mdmarkdown17.0 KB
references/numbers-migration.mdmarkdown21.1 KB
references/product-mapping.mdmarkdown6.7 KB
references/sdk-api-details/10dlc.mdmarkdown9.8 KB
references/sdk-api-details/ai-assistants.mdmarkdown5.8 KB
references/sdk-api-details/messaging.mdmarkdown16.1 KB
references/sdk-api-details/numbers.mdmarkdown10.1 KB
references/sdk-api-details/voice.mdmarkdown9.6 KB
references/sip-trunking-migration.mdmarkdown18.1 KB
references/texml-verbs.mdmarkdown43.7 KB
references/unsupported-products.mdmarkdown3.5 KB
references/verify-migration.mdmarkdown18.4 KB
references/video-migration.mdmarkdown20.6 KB
references/voice-migration.mdmarkdown37.2 KB
references/webhook-migration.mdmarkdown20.3 KB
references/webrtc-migration.mdmarkdown50.0 KB
scripts/lint-telnyx-correctness.shexecutablescript31.4 KB
scripts/migration-state.shexecutablescript7.3 KB
scripts/post-test-diagnostic.shexecutablescript18.9 KB
scripts/preflight-check.shexecutablescript13.4 KB
scripts/run-discovery.shexecutablescript7.7 KB
scripts/run-validation.shexecutablescript13.1 KB
scripts/scan-twilio-deep.pyexecutablescript64.8 KB
scripts/scan-twilio-usage.shexecutablescript29.1 KB
scripts/test-migration/smoke-test.shexecutablescript10.0 KB
scripts/test-migration/test-fax.shexecutablescript8.7 KB
scripts/test-migration/test-lookup.shexecutablescript5.5 KB
scripts/test-migration/test-messaging.shexecutablescript18.8 KB
scripts/test-migration/test-sip.shexecutablescript29.6 KB
scripts/test-migration/test-verify.shexecutablescript13.6 KB
scripts/test-migration/test-voice.shexecutablescript22.4 KB
scripts/test-migration/test-webhooks-local.pyexecutablescript9.7 KB
scripts/test-migration/test-webrtc.shexecutablescript24.0 KB
scripts/test-migration/webhook-receiver.pyexecutablescript11.8 KB
scripts/validate-migration.shexecutablescript31.1 KB
scripts/validate-texml.shexecutablescript61.4 KB
sdk-reference/curl/10dlc.mdmarkdown25.8 KB
sdk-reference/curl/account-access.mdmarkdown15.6 KB
sdk-reference/curl/account-management.mdmarkdown9.5 KB
sdk-reference/curl/account-notifications.mdmarkdown11.0 KB
sdk-reference/curl/account-reports.mdmarkdown45.5 KB
sdk-reference/curl/account.mdmarkdown8.1 KB
sdk-reference/curl/ai-assistants.mdmarkdown34.3 KB
sdk-reference/curl/ai-inference.mdmarkdown34.5 KB
sdk-reference/curl/fax.mdmarkdown19.8 KB
sdk-reference/curl/iot.mdmarkdown49.4 KB
sdk-reference/curl/messaging-hosted.mdmarkdown23.3 KB
sdk-reference/curl/messaging-profiles.mdmarkdown14.2 KB
sdk-reference/curl/messaging.mdmarkdown29.1 KB
sdk-reference/curl/missions.mdmarkdown23.5 KB
sdk-reference/curl/networking.mdmarkdown39.8 KB
sdk-reference/curl/numbers-compliance.mdmarkdown30.2 KB
sdk-reference/curl/numbers-config.mdmarkdown29.7 KB
sdk-reference/curl/numbers-services.mdmarkdown12.6 KB
sdk-reference/curl/numbers.mdmarkdown24.0 KB
sdk-reference/curl/oauth.mdmarkdown15.6 KB
sdk-reference/curl/porting-in.mdmarkdown35.1 KB
sdk-reference/curl/porting-out.mdmarkdown9.8 KB
sdk-reference/curl/sip-integrations.mdmarkdown27.5 KB
sdk-reference/curl/sip.mdmarkdown47.6 KB
sdk-reference/curl/storage.mdmarkdown4.2 KB
sdk-reference/curl/texml.mdmarkdown31.4 KB
sdk-reference/curl/verify.mdmarkdown13.2 KB
sdk-reference/curl/video.mdmarkdown17.2 KB
sdk-reference/curl/voice-advanced.mdmarkdown32.8 KB
sdk-reference/curl/voice-conferencing.mdmarkdown41.6 KB
sdk-reference/curl/voice-gather.mdmarkdown14.7 KB
sdk-reference/curl/voice-media.mdmarkdown17.8 KB
sdk-reference/curl/voice-streaming.mdmarkdown13.3 KB
sdk-reference/curl/voice.mdmarkdown37.6 KB
sdk-reference/curl/webrtc.mdmarkdown6.5 KB
sdk-reference/go/10dlc.mdmarkdown29.0 KB
sdk-reference/go/account-access.mdmarkdown17.0 KB
sdk-reference/go/account-management.mdmarkdown9.9 KB
sdk-reference/go/account-notifications.mdmarkdown12.4 KB
sdk-reference/go/account-reports.mdmarkdown31.5 KB
sdk-reference/go/account.mdmarkdown9.1 KB
sdk-reference/go/ai-assistants.mdmarkdown37.7 KB
sdk-reference/go/ai-inference.mdmarkdown27.1 KB
sdk-reference/go/fax.mdmarkdown20.2 KB
sdk-reference/go/iot.mdmarkdown51.3 KB
sdk-reference/go/messaging-hosted.mdmarkdown24.5 KB
sdk-reference/go/messaging-profiles.mdmarkdown15.2 KB
sdk-reference/go/messaging.mdmarkdown30.1 KB
sdk-reference/go/missions.mdmarkdown26.9 KB
sdk-reference/go/networking.mdmarkdown42.5 KB
sdk-reference/go/numbers-compliance.mdmarkdown28.2 KB
sdk-reference/go/numbers-config.mdmarkdown29.5 KB
sdk-reference/go/numbers-services.mdmarkdown14.1 KB
sdk-reference/go/numbers.mdmarkdown26.7 KB
sdk-reference/go/oauth.mdmarkdown11.7 KB
sdk-reference/go/porting-in.mdmarkdown41.1 KB
sdk-reference/go/porting-out.mdmarkdown10.9 KB
sdk-reference/go/sip-integrations.mdmarkdown32.3 KB
sdk-reference/go/sip.mdmarkdown49.1 KB
sdk-reference/go/storage.mdmarkdown4.8 KB
sdk-reference/go/texml.mdmarkdown35.7 KB
sdk-reference/go/verify.mdmarkdown14.4 KB
sdk-reference/go/video.mdmarkdown18.6 KB
sdk-reference/go/voice-advanced.mdmarkdown33.2 KB
sdk-reference/go/voice-conferencing.mdmarkdown42.3 KB
sdk-reference/go/voice-gather.mdmarkdown14.5 KB
sdk-reference/go/voice-media.mdmarkdown18.1 KB
sdk-reference/go/voice-streaming.mdmarkdown13.5 KB
sdk-reference/go/voice.mdmarkdown39.2 KB
sdk-reference/go/webrtc.mdmarkdown7.5 KB
sdk-reference/java/10dlc.mdmarkdown31.3 KB
sdk-reference/java/account-access.mdmarkdown18.5 KB
sdk-reference/java/account-management.mdmarkdown11.1 KB
sdk-reference/java/account-notifications.mdmarkdown14.3 KB
sdk-reference/java/account-reports.mdmarkdown36.5 KB
sdk-reference/java/account.mdmarkdown10.3 KB
sdk-reference/java/ai-assistants.mdmarkdown39.2 KB
sdk-reference/java/ai-inference.mdmarkdown30.7 KB
sdk-reference/java/fax.mdmarkdown21.5 KB
sdk-reference/java/iot.mdmarkdown57.5 KB
sdk-reference/java/messaging-hosted.mdmarkdown28.4 KB
sdk-reference/java/messaging-profiles.mdmarkdown15.7 KB
sdk-reference/java/messaging.mdmarkdown32.2 KB
sdk-reference/java/missions.mdmarkdown31.6 KB
sdk-reference/java/networking.mdmarkdown47.1 KB
sdk-reference/java/numbers-compliance.mdmarkdown31.1 KB
sdk-reference/java/numbers-config.mdmarkdown32.2 KB
sdk-reference/java/numbers-services.mdmarkdown15.9 KB
sdk-reference/java/numbers.mdmarkdown28.4 KB
sdk-reference/java/oauth.mdmarkdown13.0 KB
sdk-reference/java/porting-in.mdmarkdown46.2 KB
sdk-reference/java/porting-out.mdmarkdown11.9 KB
sdk-reference/java/sip-integrations.mdmarkdown38.1 KB
sdk-reference/java/sip.mdmarkdown51.9 KB
sdk-reference/java/storage.mdmarkdown5.7 KB
sdk-reference/java/texml.mdmarkdown41.3 KB
sdk-reference/java/verify.mdmarkdown16.0 KB
sdk-reference/java/video.mdmarkdown20.3 KB
sdk-reference/java/voice-advanced.mdmarkdown35.0 KB
sdk-reference/java/voice-conferencing.mdmarkdown46.0 KB
sdk-reference/java/voice-gather.mdmarkdown16.1 KB
sdk-reference/java/voice-media.mdmarkdown19.5 KB
sdk-reference/java/voice-streaming.mdmarkdown14.7 KB
sdk-reference/java/voice.mdmarkdown40.8 KB
sdk-reference/java/webrtc.mdmarkdown8.5 KB
sdk-reference/javascript/10dlc.mdmarkdown28.5 KB
sdk-reference/javascript/account-access.mdmarkdown15.9 KB
sdk-reference/javascript/account-management.mdmarkdown9.6 KB
sdk-reference/javascript/account-notifications.mdmarkdown11.7 KB
sdk-reference/javascript/account-reports.mdmarkdown29.3 KB
sdk-reference/javascript/account.mdmarkdown8.7 KB
sdk-reference/javascript/ai-assistants.mdmarkdown37.5 KB
sdk-reference/javascript/ai-inference.mdmarkdown24.4 KB
sdk-reference/javascript/fax.mdmarkdown19.9 KB
sdk-reference/javascript/iot.mdmarkdown47.4 KB
sdk-reference/javascript/messaging-hosted.mdmarkdown22.4 KB
sdk-reference/javascript/messaging-profiles.mdmarkdown14.8 KB
sdk-reference/javascript/messaging.mdmarkdown29.7 KB
sdk-reference/javascript/missions.mdmarkdown23.8 KB
sdk-reference/javascript/networking.mdmarkdown39.3 KB
sdk-reference/javascript/numbers-compliance.mdmarkdown25.9 KB
sdk-reference/javascript/numbers-config.mdmarkdown28.3 KB
sdk-reference/javascript/numbers-services.mdmarkdown13.0 KB
sdk-reference/javascript/numbers.mdmarkdown26.1 KB
sdk-reference/javascript/oauth.mdmarkdown10.8 KB
sdk-reference/javascript/porting-in.mdmarkdown37.4 KB
sdk-reference/javascript/porting-out.mdmarkdown10.2 KB
sdk-reference/javascript/sip-integrations.mdmarkdown28.5 KB
sdk-reference/javascript/sip.mdmarkdown47.4 KB
sdk-reference/javascript/storage.mdmarkdown4.5 KB
sdk-reference/javascript/texml.mdmarkdown31.9 KB
sdk-reference/javascript/verify.mdmarkdown13.3 KB
sdk-reference/javascript/video.mdmarkdown17.2 KB
sdk-reference/javascript/voice-advanced.mdmarkdown32.6 KB
sdk-reference/javascript/voice-conferencing.mdmarkdown40.4 KB
sdk-reference/javascript/voice-gather.mdmarkdown14.3 KB
sdk-reference/javascript/voice-media.mdmarkdown17.8 KB
sdk-reference/javascript/voice-streaming.mdmarkdown13.4 KB
sdk-reference/javascript/voice.mdmarkdown39.4 KB
sdk-reference/javascript/webrtc.mdmarkdown7.2 KB
sdk-reference/python/10dlc.mdmarkdown28.5 KB
sdk-reference/python/account-access.mdmarkdown15.0 KB
sdk-reference/python/account-management.mdmarkdown9.1 KB
sdk-reference/python/account-notifications.mdmarkdown10.9 KB
sdk-reference/python/account-reports.mdmarkdown28.1 KB
sdk-reference/python/account.mdmarkdown8.1 KB
sdk-reference/python/ai-assistants.mdmarkdown37.3 KB
sdk-reference/python/ai-inference.mdmarkdown23.4 KB
sdk-reference/python/fax.mdmarkdown19.5 KB
sdk-reference/python/iot.mdmarkdown45.3 KB
sdk-reference/python/messaging-hosted.mdmarkdown21.7 KB
sdk-reference/python/messaging-profiles.mdmarkdown14.1 KB
sdk-reference/python/messaging.mdmarkdown29.4 KB
sdk-reference/python/missions.mdmarkdown23.2 KB
sdk-reference/python/networking.mdmarkdown37.1 KB
sdk-reference/python/numbers-compliance.mdmarkdown24.6 KB

scripts/post-test-diagnostic.sh

View on GitHub
#!/usr/bin/env bash
#
# post-test-diagnostic.sh — Run after a migration test to capture diagnostics for skill improvement
#
# Usage: bash post-test-diagnostic.sh <project-root> [--agent-output <file>]
#
# Arguments:
#   <project-root>              Path to the migrated project
#   --agent-output <file>       Optional: file containing the agent's terminal output (copy-paste from session)
#
# Output: Writes a diagnostic report to <project-root>/SKILL-DIAGNOSTIC.json
#         Also prints a human-readable summary to stdout
#
# This captures what went WRONG with the skill (not just what Twilio code remains).
# Share the output JSON when reporting skill issues.

set -euo pipefail

# --- Colors ---
# shellcheck disable=SC2034  # BLUE reserved for info lines; kept for palette consistency
if [ -t 1 ]; then
  RED='\033[0;31m' YELLOW='\033[0;33m' GREEN='\033[0;32m' BLUE='\033[0;34m' BOLD='\033[1m' NC='\033[0m'
else
  RED='' YELLOW='' GREEN='' BLUE='' BOLD='' NC=''
fi

# --- Args ---
PROJECT_ROOT=""
AGENT_OUTPUT=""

while [ $# -gt 0 ]; do
  case "$1" in
    --agent-output) AGENT_OUTPUT="$2"; shift 2 ;;
    --help|-h)
      echo "Usage: bash post-test-diagnostic.sh <project-root> [--agent-output <file>]"
      echo ""
      echo "Run after a migration test to capture diagnostics for skill improvement."
      echo "Share the output SKILL-DIAGNOSTIC.json when reporting issues."
      exit 0 ;;
    *) PROJECT_ROOT="$1"; shift ;;
  esac
done

if [ -z "$PROJECT_ROOT" ] || [ ! -d "$PROJECT_ROOT" ]; then
  echo "Error: provide a valid project root directory" >&2
  echo "Usage: bash post-test-diagnostic.sh <project-root>" >&2
  exit 1
fi

PROJECT_ROOT=$(cd "$PROJECT_ROOT" && pwd)
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"

echo ""
echo -e "${BOLD}Post-Test Diagnostic${NC}"
echo "==================="
echo "  Project: $PROJECT_ROOT"
echo ""

# --- 1. Project metadata ---
echo -e "${BOLD}1. Project metadata${NC}"

LANGUAGES=""
[ -f "$PROJECT_ROOT/package.json" ] && LANGUAGES="$LANGUAGES javascript"
[ -f "$PROJECT_ROOT/Podfile" ] || [ -f "$PROJECT_ROOT/Package.swift" ] && LANGUAGES="$LANGUAGES swift"
find "$PROJECT_ROOT" -maxdepth 3 -name "build.gradle*" -print -quit 2>/dev/null | grep -q . && LANGUAGES="$LANGUAGES kotlin/java"
[ -f "$PROJECT_ROOT/pubspec.yaml" ] && LANGUAGES="$LANGUAGES dart"
[ -f "$PROJECT_ROOT/requirements.txt" ] || [ -f "$PROJECT_ROOT/Pipfile" ] || [ -f "$PROJECT_ROOT/pyproject.toml" ] && LANGUAGES="$LANGUAGES python"
[ -f "$PROJECT_ROOT/Gemfile" ] && LANGUAGES="$LANGUAGES ruby"
[ -f "$PROJECT_ROOT/go.mod" ] && LANGUAGES="$LANGUAGES go"
LANGUAGES=$(echo "$LANGUAGES" | xargs)

TOTAL_FILES=$(find "$PROJECT_ROOT" -type f \
  \( -name node_modules -o -name .git -o -name vendor -o -name __pycache__ \
     -o -name venv -o -name .venv -o -name dist -o -name build -o -name Pods \) -prune \
  -o -type f -print 2>/dev/null | wc -l | tr -d ' ')

echo "  Languages: ${LANGUAGES:-unknown}"
echo "  Files: $TOTAL_FILES"

# --- 2. Residual Twilio references (the core signal) ---
echo ""
echo -e "${BOLD}2. Residual Twilio references${NC}"

TWILIO_FILES=$(grep -rl -i "twilio" "$PROJECT_ROOT" \
  --include="*.py" --include="*.js" --include="*.ts" --include="*.tsx" --include="*.jsx" \
  --include="*.rb" --include="*.go" --include="*.java" --include="*.kt" --include="*.swift" \
  --include="*.dart" --include="*.php" --include="*.cs" --include="*.xml" --include="*.yaml" \
  --include="*.yml" --include="*.json" --include="*.md" --include="*.txt" --include="*.sh" \
  --exclude-dir=node_modules --exclude-dir=.git --exclude-dir=vendor --exclude-dir=__pycache__ \
  --exclude-dir=venv --exclude-dir=.venv --exclude-dir=build --exclude-dir=dist --exclude-dir=Pods \
  --exclude="package-lock.json" --exclude="yarn.lock" --exclude="pnpm-lock.yaml" \
  --exclude="Gemfile.lock" --exclude="Pipfile.lock" --exclude="go.sum" \
  --exclude="twilio-scan.json" --exclude="twilio-deep-scan.json" \
  --exclude="migration-state.json" --exclude="MIGRATION-PLAN.md" --exclude="MIGRATION-REPORT.md" \
  --exclude="SKILL-DIAGNOSTIC.json" \
  2>/dev/null || true)

TWILIO_FILE_COUNT=$(echo "$TWILIO_FILES" | sed '/^$/d' | wc -l | tr -d ' ')

# Categorize: source code vs docs vs config vs test
SRC_TWILIO="" TEST_TWILIO="" DOC_TWILIO="" CONFIG_TWILIO=""
while IFS= read -r f; do
  [ -z "$f" ] && continue
  rel=$(echo "$f" | sed "s|$PROJECT_ROOT/||")
  # shellcheck disable=SC2221,SC2222  # bash case is case-sensitive: *test* and *Test* are distinct
  case "$rel" in
    *test*|*Test*|*spec*|*Spec*|*__tests__*) TEST_TWILIO="$TEST_TWILIO$rel"$'\n' ;;
    *.md|*.txt|*.rst|README*|CONTRIBUTING*|CHANGELOG*|LICENSE*) DOC_TWILIO="$DOC_TWILIO$rel"$'\n' ;;
    *.json|*.yaml|*.yml|*.toml|*.cfg|*.ini|*.env*|*config*|*Config*) CONFIG_TWILIO="$CONFIG_TWILIO$rel"$'\n' ;;
    *) SRC_TWILIO="$SRC_TWILIO$rel"$'\n' ;;
  esac
done <<< "$TWILIO_FILES"

SRC_COUNT=$(echo "$SRC_TWILIO" | sed '/^$/d' | wc -l | tr -d ' ')
TEST_COUNT=$(echo "$TEST_TWILIO" | sed '/^$/d' | wc -l | tr -d ' ')
DOC_COUNT=$(echo "$DOC_TWILIO" | sed '/^$/d' | wc -l | tr -d ' ')
CONFIG_COUNT=$(echo "$CONFIG_TWILIO" | sed '/^$/d' | wc -l | tr -d ' ')

echo "  Total files with 'twilio': $TWILIO_FILE_COUNT"
echo "    Source code: $SRC_COUNT"
echo "    Test files:  $TEST_COUNT"
echo "    Docs:        $DOC_COUNT"
echo "    Config:      $CONFIG_COUNT"

if [ "$SRC_COUNT" -gt 0 ]; then
  echo -e "  ${RED}ISSUE${NC}  Source files still reference Twilio — migration incomplete"
fi
if [ "$TEST_COUNT" -gt 0 ]; then
  echo -e "  ${RED}ISSUE${NC}  Test files still reference Twilio — tests not migrated"
fi

# --- 3. Twilio directory names ---
echo ""
echo -e "${BOLD}3. Directory names with 'twilio'${NC}"

TWILIO_DIRS=$(find "$PROJECT_ROOT" -mindepth 1 \
  \( -name node_modules -o -name .git -o -name vendor -o -name __pycache__ \
     -o -name venv -o -name .venv -o -name dist -o -name build -o -name Pods \) -prune \
  -o -type d -iname '*twilio*' -print 2>/dev/null || true)
TWILIO_DIR_COUNT=$(echo "$TWILIO_DIRS" | sed '/^$/d' | wc -l | tr -d ' ')

if [ "$TWILIO_DIR_COUNT" -gt 0 ] && [ -n "$(echo "$TWILIO_DIRS" | sed '/^$/d')" ]; then
  echo -e "  ${RED}ISSUE${NC}  $TWILIO_DIR_COUNT directory name(s) still contain 'twilio':"
  echo "$TWILIO_DIRS" | sed '/^$/d' | while read -r d; do
    echo "    $(echo "$d" | sed "s|$PROJECT_ROOT/||")"
  done
else
  TWILIO_DIR_COUNT=0
  echo -e "  ${GREEN}PASS${NC}  No directories named with 'twilio'"
fi

# --- 4. Telnyx SDK presence ---
echo ""
echo -e "${BOLD}4. Telnyx SDK adoption${NC}"

TELNYX_IMPORTS=$(grep -rl -i "telnyx" "$PROJECT_ROOT" \
  --include="*.py" --include="*.js" --include="*.ts" --include="*.tsx" --include="*.jsx" \
  --include="*.rb" --include="*.go" --include="*.java" --include="*.kt" --include="*.swift" \
  --include="*.dart" \
  --exclude-dir=node_modules --exclude-dir=.git --exclude-dir=vendor --exclude-dir=__pycache__ \
  --exclude-dir=venv --exclude-dir=.venv --exclude-dir=build --exclude-dir=dist --exclude-dir=Pods \
  2>/dev/null || true)
TELNYX_FILE_COUNT=$(echo "$TELNYX_IMPORTS" | sed '/^$/d' | wc -l | tr -d ' ')

echo "  Files referencing 'telnyx': $TELNYX_FILE_COUNT"
if [ "$TELNYX_FILE_COUNT" -eq 0 ]; then
  echo -e "  ${RED}ISSUE${NC}  No Telnyx references found — migration may not have started"
else
  echo -e "  ${GREEN}PASS${NC}  Telnyx SDK present in codebase"
fi

# --- 5. Migration state ---
echo ""
echo -e "${BOLD}5. Migration state file${NC}"

STATE_FILE="$PROJECT_ROOT/migration-state.json"
if [ -f "$STATE_FILE" ]; then
  echo -e "  ${GREEN}FOUND${NC}  migration-state.json"
  if command -v python3 &>/dev/null; then
    python3 -c "
import json, sys
with open('$STATE_FILE') as f:
    state = json.load(f)
products = state.get('products', {})
for name, info in products.items():
    status = info.get('status', 'unknown')
    files = len(info.get('files_migrated', []))
    print(f'    {name}: {status} ({files} files)')
phases = state.get('phases', {})
for phase, info in phases.items():
    status = info.get('status', 'unknown')
    print(f'    Phase {phase}: {status}')
" 2>/dev/null || echo "    (could not parse)"
  fi
else
  echo -e "  ${YELLOW}WARN${NC}  No migration-state.json — agent may not have tracked state"
fi

# --- 6. Lint script results ---
echo ""
echo -e "${BOLD}6. Lint results${NC}"

LINT_SCRIPT="$SCRIPT_DIR/lint-telnyx-correctness.sh"
LINT_JSON=""
if [ -f "$LINT_SCRIPT" ]; then
  SCAN_ARG=""
  [ -f "$PROJECT_ROOT/twilio-scan.json" ] && SCAN_ARG="--scan-json $PROJECT_ROOT/twilio-scan.json"
  LINT_JSON=$(bash "$LINT_SCRIPT" --json $SCAN_ARG "$PROJECT_ROOT" 2>/dev/null || echo "")
  if [ -n "$LINT_JSON" ]; then
    LINT_ISSUES=$(echo "$LINT_JSON" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('issues',0))" 2>/dev/null || echo "?")
    LINT_WARNS=$(echo "$LINT_JSON" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('warnings',0))" 2>/dev/null || echo "?")
    LINT_PASSES=$(echo "$LINT_JSON" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('passes',0))" 2>/dev/null || echo "?")
    echo "  Issues: $LINT_ISSUES  Warnings: $LINT_WARNS  Passes: $LINT_PASSES"

    # Show issue details
    echo "$LINT_JSON" | python3 -c "
import sys, json
d = json.load(sys.stdin)
for check in d.get('checks', []):
    if check.get('status') == 'issue':
        print(f\"    ISSUE: {check.get('name', '?')} — {check.get('message', check.get('fix', '?'))}\")
    elif check.get('status') == 'warn':
        print(f\"    WARN:  {check.get('name', '?')} — {check.get('message', check.get('fix', '?'))}\")
" 2>/dev/null || true
  else
    echo "  (lint script failed to produce output)"
  fi
else
  echo "  (lint script not found)"
fi

# --- 7. Validate script results ---
echo ""
echo -e "${BOLD}7. Validate results${NC}"

VALIDATE_SCRIPT="$SCRIPT_DIR/validate-migration.sh"
VALIDATE_JSON=""
if [ -f "$VALIDATE_SCRIPT" ]; then
  SCAN_ARG=""
  [ -f "$PROJECT_ROOT/twilio-scan.json" ] && SCAN_ARG="--scan-json $PROJECT_ROOT/twilio-scan.json"
  VALIDATE_JSON=$(bash "$VALIDATE_SCRIPT" --json $SCAN_ARG "$PROJECT_ROOT" 2>/dev/null || echo "")
  if [ -n "$VALIDATE_JSON" ]; then
    VAL_FAILS=$(echo "$VALIDATE_JSON" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('fail_count',0))" 2>/dev/null || echo "?")
    VAL_WARNS=$(echo "$VALIDATE_JSON" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('warn_count',0))" 2>/dev/null || echo "?")
    VAL_PASSES=$(echo "$VALIDATE_JSON" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('pass_count',0))" 2>/dev/null || echo "?")
    echo "  Fails: $VAL_FAILS  Warnings: $VAL_WARNS  Passes: $VAL_PASSES"

    echo "$VALIDATE_JSON" | python3 -c "
import sys, json
d = json.load(sys.stdin)
for check in d.get('checks', []):
    if check.get('status') == 'FAIL':
        print(f\"    FAIL: {check.get('name', '?')}\")
    elif check.get('status') == 'WARN':
        print(f\"    WARN: {check.get('name', '?')}\")
" 2>/dev/null || true
  else
    echo "  (validate script failed to produce output)"
  fi
else
  echo "  (validate script not found)"
fi

# --- 8. Agent behavior signals (from agent output if provided) ---
echo ""
echo -e "${BOLD}8. Agent behavior signals${NC}"

TOTAL_MESSAGES=0 TOTAL_TOOL_CALLS=0 DEFERRED_COUNT=0

# List available transcripts if none specified
if [ -z "$AGENT_OUTPUT" ]; then
  CLAUDE_PROJECT_DIR="$HOME/.claude/projects"
  if [ -d "$CLAUDE_PROJECT_DIR" ]; then
    RECENT_JSONLS=$(find "$CLAUDE_PROJECT_DIR" -maxdepth 2 -name "*.jsonl" -not -path "*/subagents/*" -type f 2>/dev/null | xargs ls -t 2>/dev/null | head -5 || true)
    if [ -n "$RECENT_JSONLS" ]; then
      echo "  No --agent-output specified. Recent transcripts:"
      echo "$RECENT_JSONLS" | while IFS= read -r f; do
        SIZE=$(wc -l < "$f" 2>/dev/null | tr -d ' ')
        MOD=$(stat -f "%Sm" -t "%Y-%m-%d %H:%M" "$f" 2>/dev/null || stat -c "%y" "$f" 2>/dev/null | cut -d. -f1 || echo "?")
        echo "    $f  ($SIZE lines, $MOD)"
      done
      echo ""
      echo "  Re-run with: --agent-output <path-to-jsonl>"
    fi
  fi
fi

AGENT_ANALYSIS_FILE=$(mktemp)
if [ -n "$AGENT_OUTPUT" ] && [ -f "$AGENT_OUTPUT" ]; then
  echo "  Analyzing: $(basename "$AGENT_OUTPUT")"

  python3 - "$AGENT_OUTPUT" "$AGENT_ANALYSIS_FILE" << 'PYEOF'
import json, sys, re, os

transcript_path = sys.argv[1]
output_file = sys.argv[2]

total_messages = 0
total_tool_calls = 0
deferred_lines = []
texts = []

if transcript_path.endswith('.jsonl'):
    for line in open(transcript_path):
        try:
            msg = json.loads(line)
            if msg.get('type') == 'assistant':
                total_messages += 1
                for block in msg.get('message', {}).get('content', []):
                    if isinstance(block, dict):
                        if block.get('type') == 'text':
                            texts.append(block['text'])
                        elif block.get('type') == 'tool_use':
                            total_tool_calls += 1
        except:
            pass
else:
    texts = [open(transcript_path).read()]

defer_pattern = re.compile(
    r'.*(manual.{0,20}step|remaining.{0,20}step|defer(?:red|ring)|TODO.{0,10}manual|left as.{0,20}exercise|out of scope).*',
    re.IGNORECASE
)
for text in texts:
    for line in text.split('\n'):
        stripped = line.strip()
        if stripped and defer_pattern.match(stripped):
            if not stripped.startswith(('#', '//', '```', '*', '-')):
                deferred_lines.append(stripped)

result = {
    'total_messages': total_messages,
    'total_tool_calls': total_tool_calls,
    'deferred_count': len(deferred_lines),
    'deferred_items': deferred_lines[:20],
}

with open(output_file, 'w') as f:
    json.dump(result, f)
PYEOF

  if [ -f "$AGENT_ANALYSIS_FILE" ]; then
    TOTAL_MESSAGES=$(python3 -c "import json; print(json.load(open('$AGENT_ANALYSIS_FILE')).get('total_messages',0))" 2>/dev/null || echo "0")
    TOTAL_TOOL_CALLS=$(python3 -c "import json; print(json.load(open('$AGENT_ANALYSIS_FILE')).get('total_tool_calls',0))" 2>/dev/null || echo "0")
    DEFERRED_COUNT=$(python3 -c "import json; print(json.load(open('$AGENT_ANALYSIS_FILE')).get('deferred_count',0))" 2>/dev/null || echo "0")

    echo "  Agent messages: $TOTAL_MESSAGES"
    echo "  Tool calls: $TOTAL_TOOL_CALLS"

    if [ "$DEFERRED_COUNT" -gt 0 ]; then
      echo -e "  ${YELLOW}WARN${NC}  Agent deferred $DEFERRED_COUNT item(s) — check if these should have been migrated:"
      python3 -c "
import json
for item in json.load(open('$AGENT_ANALYSIS_FILE')).get('deferred_items',[])[:5]:
    print(f'    {item}')
" 2>/dev/null || true
    else
      echo -e "  ${GREEN}PASS${NC}  No deferred items detected"
    fi
  else
    echo "  (could not analyze transcript)"
  fi
else
  echo "  No agent output found"
  echo "  Tip: run again after the Claude Code session ends — the transcript will be auto-detected"
fi

# --- 9. Git diff summary (if git repo) ---
echo ""
echo -e "${BOLD}9. Git changes${NC}"

if [ -d "$PROJECT_ROOT/.git" ]; then
  FILES_CHANGED=$(cd "$PROJECT_ROOT" && git diff --shortstat HEAD~1 2>/dev/null || git diff --shortstat 2>/dev/null || echo "")
  if [ -n "$FILES_CHANGED" ]; then
    echo "  $FILES_CHANGED"
  else
    echo "  (no git changes detected — agent may not have committed)"
  fi
else
  echo "  (not a git repo)"
fi

# --- Write JSON report ---
echo ""
echo -e "${BOLD}Writing diagnostic report...${NC}"

OUTPUT_FILE="$PROJECT_ROOT/SKILL-DIAGNOSTIC.json"

# Write all data to temp files, then let python assemble the JSON safely
SRC_TWILIO_FILE=$(mktemp)
TEST_TWILIO_FILE=$(mktemp)
TWILIO_DIRS_FILE=$(mktemp)
LINT_FILE=$(mktemp)
VALIDATE_FILE=$(mktemp)

echo "$SRC_TWILIO" | sed '/^$/d' > "$SRC_TWILIO_FILE"
echo "$TEST_TWILIO" | sed '/^$/d' > "$TEST_TWILIO_FILE"
echo "$TWILIO_DIRS" | sed '/^$/d' | sed "s|$PROJECT_ROOT/||g" > "$TWILIO_DIRS_FILE"
echo "$LINT_JSON" > "$LINT_FILE"
echo "$VALIDATE_JSON" > "$VALIDATE_FILE"

python3 - "$OUTPUT_FILE" "$PROJECT_ROOT" "$LANGUAGES" \
  "$TOTAL_FILES" "$TWILIO_FILE_COUNT" "$SRC_COUNT" "$TEST_COUNT" "$DOC_COUNT" "$CONFIG_COUNT" \
  "$TWILIO_DIR_COUNT" "$TELNYX_FILE_COUNT" \
  "$TOTAL_MESSAGES" "$TOTAL_TOOL_CALLS" "$DEFERRED_COUNT" \
  "$SRC_TWILIO_FILE" "$TEST_TWILIO_FILE" "$TWILIO_DIRS_FILE" \
  "$LINT_FILE" "$VALIDATE_FILE" "$AGENT_ANALYSIS_FILE" << 'PYEOF'
import json, sys

args = sys.argv[1:]
output_file = args[0]
project_root = args[1]

def read_lines(path):
    try:
        return [l.strip() for l in open(path) if l.strip()]
    except:
        return []

def read_json(path):
    try:
        content = open(path).read().strip()
        if content:
            return json.loads(content)
    except:
        pass
    return None

def safe_int(val):
    try:
        return int(val)
    except:
        return 0

report = {
    'version': '1.0',
    'project_root': project_root,
    'languages': args[2].split(),
    'total_files': safe_int(args[3]),
    'residual_twilio': {
        'total': safe_int(args[4]),
        'source': safe_int(args[5]),
        'test': safe_int(args[6]),
        'docs': safe_int(args[7]),
        'config': safe_int(args[8]),
        'source_files': read_lines(args[14]),
        'test_files': read_lines(args[15]),
    },
    'twilio_directories': {
        'count': safe_int(args[9]),
        'paths': read_lines(args[16]),
    },
    'telnyx_adoption': {
        'files_with_telnyx': safe_int(args[10]),
    },
    'agent': {
        'messages': safe_int(args[11]),
        'tool_calls': safe_int(args[12]),
        'deferred_count': safe_int(args[13]),
    },
}

# Add agent deferred items
agent_data = read_json(args[19])
if agent_data:
    report['agent']['deferred_items'] = agent_data.get('deferred_items', [])

# Add lint results
lint_data = read_json(args[17])
if lint_data:
    report['lint'] = lint_data

# Add validate results
validate_data = read_json(args[18])
if validate_data:
    report['validate'] = validate_data

with open(output_file, 'w') as f:
    json.dump(report, f, indent=2)

print(f'  Written to: {output_file}')
PYEOF

WRITE_OK=$?
rm -f "$SRC_TWILIO_FILE" "$TEST_TWILIO_FILE" "$TWILIO_DIRS_FILE" "$LINT_FILE" "$VALIDATE_FILE" "$AGENT_ANALYSIS_FILE" 2>/dev/null

if [ "$WRITE_OK" -ne 0 ]; then
  echo "  (failed to write JSON — check python3)"
fi

# --- Summary ---
echo ""
echo "==================="
echo -e "${BOLD}Summary${NC}"
TOTAL_ISSUES=0
[ "$SRC_COUNT" -gt 0 ] && echo -e "  ${RED}!!${NC}  $SRC_COUNT source files still reference Twilio" && TOTAL_ISSUES=$((TOTAL_ISSUES + 1))
[ "$TEST_COUNT" -gt 0 ] && echo -e "  ${RED}!!${NC}  $TEST_COUNT test files still reference Twilio" && TOTAL_ISSUES=$((TOTAL_ISSUES + 1))
[ "$TWILIO_DIR_COUNT" -gt 0 ] && echo -e "  ${RED}!!${NC}  $TWILIO_DIR_COUNT directories still named with 'twilio'" && TOTAL_ISSUES=$((TOTAL_ISSUES + 1))
[ "$TELNYX_FILE_COUNT" -eq 0 ] && echo -e "  ${RED}!!${NC}  No Telnyx references found at all" && TOTAL_ISSUES=$((TOTAL_ISSUES + 1))
[ "$DEFERRED_COUNT" -gt 0 ] && echo -e "  ${YELLOW}!!${NC}  Agent deferred $DEFERRED_COUNT item(s)" && TOTAL_ISSUES=$((TOTAL_ISSUES + 1))

if [ "$TOTAL_ISSUES" -eq 0 ]; then
  echo -e "  ${GREEN}All clear${NC} — no obvious skill issues detected"
fi

echo ""
echo "Share SKILL-DIAGNOSTIC.json when reporting skill issues."
echo ""
finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the workStars: 322kUpdated Claude CodeCodexVerifiedInstall
systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixesStars: 322kUpdated Claude CodeCodexVerifiedInstall
test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation codeStars: 322kUpdated Claude CodeCodexVerifiedInstall
skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.Stars: 198kUpdated Claude CodeCodexVerifiedInstall