{
  "name": "Vorlux AI | AI Code Review",
  "nodes": [
    {
      "id": "dd28c1e3-5431-4412-a773-8e06d5bf575f",
      "name": "PR Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        220,
        300
      ],
      "webhookId": "aad3fa49-b8d7-4585-b6fc-e8edf1db2e7e",
      "parameters": {
        "httpMethod": "POST",
        "path": "code-review",
        "options": {
          "responseMode": "lastNode"
        }
      }
    },
    {
      "id": "16d79dca-ced9-4542-ad0f-cd100197cae2",
      "name": "Fetch Diff",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        460,
        300
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const d = $input.first().json.body || $input.first().json;return [{json: {prNumber: d.number, title: d.title || d.pull_request?.title, diff: d.diff || d.pull_request?.body || '', repo: d.repository?.full_name || 'j4cobo87-blip/vorlux-hub', author: d.sender?.login || d.author || 'unknown'}}];"
      }
    },
    {
      "id": "17c20777-18fd-4435-a2be-a824be42e81b",
      "name": "AI Review",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        700,
        300
      ],
      "parameters": {
        "method": "POST",
        "url": "={{$env.VORLUX_HUB_URL}}/api/orchestrator/execute",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"agentId\":\"dev-agent\",\"action\":\"code_review\",\"params\":{\"diff\":{{ JSON.stringify($json.diff.substring(0, 10000)) }},\"title\":\"{{ $json.title }}\",\"checkpoints\":[\"security\",\"performance\",\"readability\",\"best_practices\",\"error_handling\"]}}",
        "options": {
          "timeout": 120000
        }
      },
      "notes": "Dev agent reviews code changes against 5 quality dimensions"
    },
    {
      "id": "33f363be-4532-4da5-8357-0609e4ea4673",
      "name": "Format Review",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        940,
        300
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const review = $input.first().json.data?.result || 'No review generated';const pr = $node['Fetch Diff'].json;return [{json: {prNumber: pr.prNumber, title: pr.title, author: pr.author, repo: pr.repo, review, approved: !review.toLowerCase().includes('critical') && !review.toLowerCase().includes('security issue')}}];"
      }
    },
    {
      "id": "845ab67f-cf9f-45c9-be44-7f0f8d0fed03",
      "name": "Post Discord",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1180,
        200
      ],
      "parameters": {
        "method": "POST",
        "url": "={{$env.DISCORD_OPS_WEBHOOK}}",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"embeds\":[{\"title\":\"{{ $json.approved ? \"\u2705\" : \"\u26a0\ufe0f\" }} Code Review: {{ $json.title }}\",\"description\":\"PR #{{ $json.prNumber }} by {{ $json.author }}\\n\\n{{ $json.review.substring(0, 1000) }}\",\"color\":{{ $json.approved ? 5763719 : 16776960 }}}]}",
        "options": {
          "timeout": 10000
        }
      }
    },
    {
      "id": "ab43249a-eb43-498e-a2e3-c32ad2889b2b",
      "name": "Respond",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        1180,
        400
      ],
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify({reviewed: true, approved: $json.approved}) }}"
      }
    }
  ],
  "connections": {
    "PR Webhook": {
      "main": [
        [
          {
            "node": "Fetch Diff",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Diff": {
      "main": [
        [
          {
            "node": "AI Review",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Review": {
      "main": [
        [
          {
            "node": "Format Review",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Review": {
      "main": [
        [
          {
            "node": "Post Discord",
            "type": "main",
            "index": 0
          },
          {
            "node": "Respond",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "saveManualExecutions": true,
    "saveExecutionProgress": true
  }
}