/ scripts / init-code-review-queue.sh
init-code-review-queue.sh
 1  #!/bin/sh
 2  # init-code-review-queue.sh — Seed the code review queue in security-first priority order.
 3  #
 4  # Output: logs/code-review-queue.json
 5  #
 6  # Run once to initialize. Re-run with --reset to restart the review from scratch.
 7  # The orchestrator reads this queue 1 file per cycle via the code_review batch type.
 8  #
 9  # Priority order:
10  #   1. Security-critical: src/payment/, src/inbound/, src/outreach/email.js, load-env
11  #   2. Pipeline core: src/stages/, proposal-generator-v2.js, src/cron.js
12  #   3. Utilities: src/utils/
13  #   4. Remaining: src/reports/, src/cli/, other src/
14  
15  set -e
16  cd "$(dirname "$0")/.."
17  
18  QUEUE_FILE="logs/code-review-queue.json"
19  
20  if [ -f "$QUEUE_FILE" ] && [ "$1" != "--reset" ]; then
21    echo "Queue already exists at $QUEUE_FILE"
22    echo "Use --reset to reinitialize from scratch."
23    echo ""
24    current=$(node -e "const q=JSON.parse(require('fs').readFileSync('$QUEUE_FILE','utf8'));console.log('Files: '+q.files.length+', reviewed: '+q.reviewed+', remaining: '+(q.files.length-q.next_index))" 2>/dev/null || echo "unknown")
25    echo "Current status: $current"
26    exit 0
27  fi
28  
29  echo "Building code review queue (security-first order)..."
30  
31  # Collect files in priority buckets
32  # Exclude: src/agents/ (being replaced), node_modules, test files
33  find_src() {
34    find "src/$1" -name "*.js" ! -path "*/node_modules/*" ! -path "*/agents/*" 2>/dev/null | sort
35  }
36  
37  # Priority 1: Security-critical files
38  P1=""
39  P1="$P1 $(find src/payment -name "*.js" 2>/dev/null | sort | tr '\n' ' ')"
40  P1="$P1 $(find src/inbound -name "*.js" 2>/dev/null | sort | tr '\n' ' ')"
41  P1="$P1 $(find src/outreach -name "email.js" 2>/dev/null | sort | tr '\n' ' ')"
42  P1="$P1 src/utils/load-env.js"
43  
44  # Priority 2: Pipeline core
45  P2=""
46  P2="$P2 $(find src/stages -name "*.js" 2>/dev/null | sort | tr '\n' ' ')"
47  P2="$P2 src/proposal-generator-v2.js"
48  P2="$P2 src/cron.js"
49  
50  # Priority 3: Remaining outreach + utils
51  P3=""
52  P3="$P3 $(find src/outreach -name "*.js" ! -name "email.js" 2>/dev/null | sort | tr '\n' ' ')"
53  P3="$P3 $(find src/utils -name "*.js" 2>/dev/null | sort | tr '\n' ' ')"
54  
55  # Priority 4: Everything else in src/ (excluding agents/, already-covered paths)
56  P4=""
57  P4="$P4 $(find src -name "*.js" ! -path "*/agents/*" ! -path "*/stages/*" ! -path "*/payment/*" ! -path "*/inbound/*" ! -path "*/outreach/*" ! -path "*/utils/*" 2>/dev/null | sort | tr '\n' ' ')"
58  
59  # Merge, deduplicate, filter to actual files
60  all_files=$(printf '%s\n' $P1 $P2 $P3 $P4 | \
61    grep '\.js$' | \
62    grep -v '^$' | \
63    sort -u)
64  
65  # Convert to JSON array (preserve priority order by sorting after dedup is wrong — rebuild)
66  # Re-apply priority order: P1 first, then P2, P3, P4, dedup later entries
67  ordered_files=$(printf '%s\n' $P1 $P2 $P3 $P4 | \
68    grep '\.js$' | \
69    grep -v '^$' | \
70    awk '!seen[$0]++')
71  
72  # Build JSON
73  count=$(echo "$ordered_files" | grep -c '.' 2>/dev/null || echo "0")
74  
75  json=$(echo "$ordered_files" | node -e "
76    let lines = '';
77    process.stdin.on('data', d => lines += d);
78    process.stdin.on('end', () => {
79      const files = lines.trim().split('\n').filter(Boolean);
80      const queue = { files, next_index: 0, reviewed: 0, created_at: new Date().toISOString() };
81      process.stdout.write(JSON.stringify(queue, null, 2));
82    });
83  ")
84  
85  printf '%s\n' "$json" > "$QUEUE_FILE"
86  echo "Queue initialized: $count files → $QUEUE_FILE"
87  echo "Security-critical first: src/payment/, src/inbound/, src/outreach/email.js, load-env.js"
88  echo "Run 'node scripts/claude-batch.js code_review' to verify first item."