{
  "name": "Mycroft - Patent Intelligence System",
  "nodes": [
    {
      "parameters": {},
      "id": "36796694-2ce7-4f10-9b68-334a1d6bc586",
      "name": "Manual Trigger",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -1408,
        -48
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "78db0104-55a2-4142-bb82-370d63d9bdf5",
              "name": "github_repo_url",
              "value": "https://github.com/Humanitariansai/Mycroft",
              "type": "string"
            },
            {
              "id": "985331f1-aa8c-4888-aae7-d29cbde21a6c",
              "name": "scripts_path",
              "value": "Core_Components/Patents_Analysis_Agent",
              "type": "string"
            },
            {
              "id": "4731832b-6c7e-4517-8d89-6add5414aebd",
              "name": "temp_dir",
              "value": "/tmp",
              "type": "string"
            },
            {
              "id": "c2ff31ae-dd77-4d02-b3b0-a26898280d06",
              "name": "days_back",
              "value": "100",
              "type": "string"
            },
            {
              "id": "a8f92e1b-3c4d-4f2a-9b8e-7d5f6e8a9c2b",
              "name": "api_key",
              "value": "=api_key",
              "type": "string"
            },
            {
              "id": "b9c83f2c-4d5e-5f3a-0c9f-8e6g7f9a0d3c",
              "name": "notify_email",
              "value": "=email",
              "type": "string"
            },
            {
              "id": "g4h38k7h-9i0j-0k8f-5h4k-3j1l2k4f5i8h",
              "name": "from_email",
              "value": "user@example.com",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "e7fcddeb-9c67-4ec9-879d-428cba3de0b3",
      "name": "Set Variables",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -1184,
        -48
      ]
    },
    {
      "parameters": {
        "command": "=cd {{ $json.temp_dir }} && rm -rf patent_intelligence && git clone {{ $json.github_repo_url }} patent_intelligence"
      },
      "id": "1297fd8b-a17b-4316-a837-cc1b75b82548",
      "name": "Setup Github Repo",
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        -960,
        -48
      ]
    },
    {
      "parameters": {
        "jsCode": "const config = $node['Set Variables'].json;\n\nconst repoDir = `${config.temp_dir}/patent_intelligence`;\nconst scriptsDir = `${config.temp_dir}/patent_intelligence/${config.scripts_path}`;\nconst outputDir = `${config.temp_dir}/patent_output`;\n\nreturn [{\n  json: {\n    ...config,\n    repo_dir: repoDir,\n    scripts_dir: scriptsDir,\n    output_dir: outputDir,\n    clone_success: true\n  }\n}];"
      },
      "id": "404ec7e7-923c-4b1d-870c-0dedc2d75f53",
      "name": "Set Path Variables",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -736,
        -48
      ]
    },
    {
      "parameters": {
        "command": "=rm -rf {{ $json.output_dir }} && mkdir -p {{ $json.output_dir }}/data && cd {{ $json.scripts_dir }} && python3 -m pip install -r requirements.txt --user --quiet"
      },
      "id": "87038452-92b6-4d45-97f9-af7a02298daa",
      "name": "Setup Environment and Output Directories",
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        -512,
        -144
      ]
    },
    {
      "parameters": {
        "command": "=cd {{ $json.scripts_dir }} && python3 patent_fetcher.py --days_back {{ $json.days_back }} --output {{ $json.output_dir }}/data/patents_recent.csv --api_key {{ $json.api_key }}"
      },
      "id": "131aeb56-7a1a-4cbb-bdad-c1a540c27ecf",
      "name": "Extract Patents",
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        -512,
        48
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 1
          },
          "conditions": [
            {
              "id": "e5f6g7h8-i9j0-1234-efgh-567890123457",
              "leftValue": "={{ $node['Extract Patents'].json.exitCode }}",
              "rightValue": 0,
              "operator": {
                "type": "number",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "1566b758-5a8e-4187-ae6e-a8f7dbafdff1",
      "name": "Check Extraction Success",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        -288,
        48
      ]
    },
    {
      "parameters": {
        "command": "=cd {{ $node['Set Path Variables'].json.scripts_dir }} && python3 patent_processor.py {{ $node['Set Path Variables'].json.output_dir }}/data/patents_recent.csv --output {{ $node['Set Path Variables'].json.output_dir }}/data/processed_patents_recent.csv"
      },
      "id": "60784149-7cb6-4956-94d8-c55e17ee3a85",
      "name": "Process Patents",
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        -64,
        -48
      ]
    },
    {
      "parameters": {
        "filePath": "={{ $node['Set Path Variables'].json.output_dir }}/data/processed_patents_recent.csv"
      },
      "id": "a76bce76-7b91-4742-a39a-d3a59b398f5a",
      "name": "Read Processed Data",
      "type": "n8n-nodes-base.readBinaryFile",
      "typeVersion": 1,
      "position": [
        160,
        0
      ]
    },
    {
      "parameters": {
        "filePath": "={{ $node['Set Path Variables'].json.output_dir }}/data/processed_patents_recent_metrics.json",
        "dataPropertyName": "metrics"
      },
      "id": "6e67dbf1-5c3a-4df1-aa5b-f001963ac8a0",
      "name": "Read Metrics",
      "type": "n8n-nodes-base.readBinaryFile",
      "typeVersion": 1,
      "position": [
        160,
        -192
      ]
    },
    {
      "parameters": {
        "fromEmail": "={{ $node['Set Path Variables'].json.from_email }}",
        "toEmail": "={{ $node['Set Path Variables'].json.notify_email }}",
        "subject": "=Patent Intelligence Report - {{ $now.toFormat('yyyy-MM-dd') }}",
        "text": "=Worflow executed succesfully.",
        "options": {
          "attachments": "data, metrics",
          "allowUnauthorizedCerts": false
        }
      },
      "id": "596d2212-8d88-4a4c-af56-ed020c75b349",
      "name": "Send Report Email",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2,
      "position": [
        416,
        -64
      ]
    },
    {
      "parameters": {
        "fromEmail": "={{ $json.from_email }}",
        "toEmail": "={{ $json.notify_email }}",
        "subject": "Patent Intelligence Error - {{ $json.patent_year }}",
        "text": "The workflow has failed.",
        "options": {
          "allowUnauthorizedCerts": false
        }
      },
      "id": "3b21e856-0483-4821-aab2-def2c555afdb",
      "name": "Error Notification",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2,
      "position": [
        -64,
        144
      ]
    },
    {
      "parameters": {
        "command": "=rm -rf {{ $node['Set Path Variables'].json.repo_dir }} && echo \"🧹 Repository cleanup completed\""
      },
      "id": "7654bc8b-bc53-44b3-8b71-38b9e90bc896",
      "name": "Cleanup Repository",
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        640,
        -64
      ]
    },
    {
      "parameters": {
        "command": "=rm -rf {{ $json.repo_dir }} && echo \"Error cleanup completed\""
      },
      "id": "e891925a-a752-4ffb-b807-6d9e62b871e1",
      "name": "Cleanup Repository Error",
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        160,
        144
      ]
    },
    {
      "id": "a5a13667-16c4-5c04-beaf-490f98afbe71",
      "name": "Publication · Overview and setup",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -2208,
        -192
      ],
      "parameters": {
        "content": "# Mycroft - Patent Intelligence System\n\n## Purpose and structure\nThis folder contains the **Mycroft - Patent Intelligence System** workflow. Its executable nodes use `code`, `emailSend`, `executeCommand`, `if`, `manualTrigger`, `readBinaryFile`, `set`. The table and connection map below are derived from the JSON, not an inferred guarantee of behavior.\n\n## Setup\nImport inactive. Configure your own credentials and replace REPLACE_WITH_* values. Review external destinations and Code nodes before running.\n\n## Entry points\nManual Trigger\n\n## Verification\nSanitized source candidate; not runtime-tested. This overview is generated from node metadata. Read the folder README for the connection map, credential types, and license.\n\n## Attribution\nNik Bear Brown; rights confirmed 2026-10-19\nMIT; preserve source notices.",
        "width": 700,
        "height": 800,
        "color": 1
      }
    }
  ],
  "connections": {
    "Manual Trigger": {
      "main": [
        [
          {
            "node": "Set Variables",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Variables": {
      "main": [
        [
          {
            "node": "Setup Github Repo",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Setup Github Repo": {
      "main": [
        [
          {
            "node": "Set Path Variables",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Path Variables": {
      "main": [
        [
          {
            "node": "Setup Environment and Output Directories",
            "type": "main",
            "index": 0
          },
          {
            "node": "Extract Patents",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Patents": {
      "main": [
        [
          {
            "node": "Check Extraction Success",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Extraction Success": {
      "main": [
        [
          {
            "node": "Process Patents",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Error Notification",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Process Patents": {
      "main": [
        [
          {
            "node": "Read Metrics",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Processed Data": {
      "main": [
        [
          {
            "node": "Send Report Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Metrics": {
      "main": [
        [
          {
            "node": "Read Processed Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Report Email": {
      "main": [
        [
          {
            "node": "Cleanup Repository",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Error Notification": {
      "main": [
        [
          {
            "node": "Cleanup Repository Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Setup Environment and Output Directories": {
      "main": [
        []
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  }
}
