{
  "name": "CTO End — Technical Quality & Delivery",
  "description": null,
  "active": false,
  "isArchived": false,
  "nodes": [
    {
      "parameters": {
        "httpMethod": "GET",
        "path": "cto-end",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "39f5dd87-2835-485c-ab73-fcec882ac302",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        240,
        120
      ],
      "webhookId": "<<REPLACE_ME>>"
    },
    {
      "parameters": {
        "jsCode": "// Routine Notes API key. Set RN_API_KEY in n8n env or replace inline.\nconst apiKey = $env.RN_API_KEY || '<<REPLACE_ME>>';\nreturn { apiKey };"
      },
      "id": "d6e6ba20-d210-44ad-8a0a-575b0c288054",
      "name": "API Key",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        480,
        120
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://aicivz8c3l.execute-api.ap-south-1.amazonaws.com/dev/mcp/call",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            },
            {
              "name": "Authorization",
              "value": "=Bearer {{ $('API Key').first().json.apiKey }}"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"jsonrpc\": \"2.0\",\n  \"method\": \"tools/call\",\n  \"params\": {\n    \"name\": \"graphql_query\",\n    \"arguments\": {\n      \"query\": \"query GetGoalItemById($id: ID!) { goalItemById(id: $id) { id body contribution status tags deadline reward } }\",\n      \"variables\": { \"id\": \"{{ $('Webhook').item.json.query.goal_id }}\" }\n    }\n  },\n  \"id\": 1\n}",
        "options": {}
      },
      "id": "b4eba42c-1479-4fae-baf4-63688e7c12ab",
      "name": "Get Goal",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        720,
        120
      ]
    },
    {
      "parameters": {
        "jsCode": "// Unwrap the MCP JSON-RPC envelope into the goal object.\nconst text = $input.first().json.result.content[0].text;\nconst data = JSON.parse(text);\nreturn { json: data.data ? data.data : data };"
      },
      "id": "37ae558f-3b88-4367-95f3-4475ea4c65d5",
      "name": "Parse Goal",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        960,
        120
      ]
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "af9499b0-bf51-47d7-87cd-cfe8e0c1e589",
                    "leftValue": "={{ $json.goalItemById.tags }}",
                    "rightValue": "area:cto:tech",
                    "operator": {
                      "type": "array",
                      "operation": "contains",
                      "rightType": "any"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "tech"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "1a9526ba-86f2-40bc-ade8-91040c26a82d",
                    "leftValue": "={{ $json.goalItemById.tags }}",
                    "rightValue": "area:cto:delivery",
                    "operator": {
                      "type": "array",
                      "operation": "contains",
                      "rightType": "any"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "delivery"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "7a62b1b6-95c2-4147-8194-ce4b786e832e",
                    "leftValue": "={{ $json.goalItemById.tags }}",
                    "rightValue": "area:cto:skills",
                    "operator": {
                      "type": "array",
                      "operation": "contains",
                      "rightType": "any"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "skills"
            }
          ]
        },
        "options": {
          "fallbackOutput": "extra"
        }
      },
      "id": "70ae97f9-600c-4af7-94de-5b9b1d507b05",
      "name": "Route Subrole",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3,
      "position": [
        1200,
        120
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.perplexity.ai/chat/completions",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            },
            {
              "name": "Authorization",
              "value": "Bearer <<REPLACE_ME>>"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"model\": \"sonar-pro\",\n  \"messages\": [\n    { \"role\": \"system\", \"content\": \"You are the CTO tech agent in a Personal Operating System. Focus on: certification/tech-stack relevance and a ranked action plan. Reflect on completion and close the loop for the end of the routine. Be concrete and concise; return plain prose the user can act on today.\" },\n    { \"role\": \"user\", \"content\": {{ JSON.stringify($('Parse Goal').item.json.goalItemById.body) }} }\n  ]\n}",
        "options": {}
      },
      "id": "e0e0b500-1027-49b7-971b-5b612bb29b68",
      "name": "tech agent",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1440,
        120
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "<<REPLACE_ME>>",
          "name": "<<REPLACE_ME>> (was: <<REPLACE_ME>> (perplexity key))"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.perplexity.ai/chat/completions",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            },
            {
              "name": "Authorization",
              "value": "Bearer <<REPLACE_ME>>"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"model\": \"sonar-pro\",\n  \"messages\": [\n    { \"role\": \"system\", \"content\": \"You are the CTO delivery agent in a Personal Operating System. Focus on: delivery velocity, the biggest time-sink, and one quality risk. Reflect on completion and close the loop for the end of the routine. Be concrete and concise; return plain prose the user can act on today.\" },\n    { \"role\": \"user\", \"content\": {{ JSON.stringify($('Parse Goal').item.json.goalItemById.body) }} }\n  ]\n}",
        "options": {}
      },
      "id": "9089aa20-fabc-47d0-9ee7-ad25e645ccb8",
      "name": "delivery agent",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1440,
        300
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "<<REPLACE_ME>>",
          "name": "<<REPLACE_ME>> (was: <<REPLACE_ME>> (perplexity key))"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.perplexity.ai/chat/completions",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            },
            {
              "name": "Authorization",
              "value": "Bearer <<REPLACE_ME>>"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"model\": \"sonar-pro\",\n  \"messages\": [\n    { \"role\": \"system\", \"content\": \"You are the CTO skills agent in a Personal Operating System. Focus on: the one skill whose improvement most reduces delivery time. Reflect on completion and close the loop for the end of the routine. Be concrete and concise; return plain prose the user can act on today.\" },\n    { \"role\": \"user\", \"content\": {{ JSON.stringify($('Parse Goal').item.json.goalItemById.body) }} }\n  ]\n}",
        "options": {}
      },
      "id": "ed92f65a-21ab-40fa-a50c-5fa59875fdfe",
      "name": "skills agent",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1440,
        480
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "<<REPLACE_ME>>",
          "name": "<<REPLACE_ME>> (was: <<REPLACE_ME>> (perplexity key))"
        }
      }
    },
    {
      "parameters": {
        "numberInputs": 3
      },
      "id": "9babe70d-6ba2-4d8e-9a6b-26a90f1c7e77",
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3,
      "position": [
        1680,
        120
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://aicivz8c3l.execute-api.ap-south-1.amazonaws.com/dev/mcp/call",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            },
            {
              "name": "Authorization",
              "value": "=Bearer {{ $('API Key').first().json.apiKey }}"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"jsonrpc\": \"2.0\",\n  \"method\": \"tools/call\",\n  \"params\": {\n    \"name\": \"graphql_query\",\n    \"arguments\": {\n      \"query\": \"mutation UpdateGoalItemContribution($id: ID!, $contribution: String!) { updateGoalItemContribution(id: $id, contribution: $contribution) { id body contribution status } }\",\n      \"variables\": {\n        \"id\": \"{{ $('Webhook').item.json.query.goal_id }}\",\n        \"contribution\": {{ JSON.stringify($json.choices ? $json.choices[0].message.content : ($json.message || '')) }}\n      }\n    }\n  },\n  \"id\": 2\n}",
        "options": {}
      },
      "id": "7f68dd0c-1182-4f42-9303-03ac47813869",
      "name": "Update Goal",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1920,
        120
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ { \"ok\": true, \"goal_id\": $('Webhook').item.json.query.goal_id } }}",
        "options": {}
      },
      "id": "8104eaad-fa97-4ff1-9c27-af1471f94c06",
      "name": "Respond to Webhook",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        2160,
        120
      ]
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "API Key",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "API Key": {
      "main": [
        [
          {
            "node": "Get Goal",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Goal": {
      "main": [
        [
          {
            "node": "Parse Goal",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Goal": {
      "main": [
        [
          {
            "node": "Route Subrole",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Route Subrole": {
      "main": [
        [
          {
            "node": "tech agent",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "delivery agent",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "skills agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "tech agent": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "delivery agent": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "skills agent": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 2
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "Update Goal",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update Goal": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "pinData": null,
  "tags": [
    {
      "updatedAt": "2026-05-31T13:28:56.856Z",
      "createdAt": "2026-05-31T13:28:56.856Z",
      "id": "B5wTB3QARoUnrLGa",
      "name": "pillar:cto"
    },
    {
      "updatedAt": "2026-05-31T13:28:52.809Z",
      "createdAt": "2026-05-31T13:28:52.809Z",
      "id": "kLQMuII6E7BC8apU",
      "name": "evolution"
    },
    {
      "updatedAt": "2026-05-31T13:28:52.950Z",
      "createdAt": "2026-05-31T13:28:52.950Z",
      "id": "vkEv2UGPNBfyH74Y",
      "name": "phase:end"
    }
  ]
}