{
  "id": "zUgZJ1jOqP3cpvxp",
  "name": "14 - Daily Sweep (wakes the master agent)",
  "active": false,
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 9 * * *"
            }
          ]
        }
      },
      "id": "ds-trig",
      "name": "Daily 9am",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        200,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "const today=new Date().toISOString().slice(0,10);\nreturn [{json:{chatInput:'SWEEP MODE: review the pipeline now. Call plan_pipeline first. If it shows overdue follow-ups, call check_followups and use personalize_lead on any lead that looks ready for a fresh touch. Report back a short summary of what you did and why - do not skip leads silently.', sessionId:'sweep-'+today}}];"
      },
      "id": "ds-prompt",
      "name": "Build Sweep Prompt",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        420,
        300
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $env.N8N_INTERNAL_URL || 'http://localhost:5678' }}/webhook/cf5a1223-69a9-4458-a4c1-5513085884fe/chat",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ action: 'sendMessage', chatInput: $json.chatInput, sessionId: $json.sessionId }) }}",
        "options": {
          "response": {
            "response": {
              "responseFormat": "json"
            }
          }
        }
      },
      "id": "ds-call",
      "name": "Wake Master Agent",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        640,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "const fs=require('fs');\nconst logPath=(process.env.LEADS_DIR||'/data/leads')+'/sweep-log.txt';\nconst entry='--- '+new Date().toISOString()+' ---\\n'+JSON.stringify($json,null,2)+'\\n\\n';\nfs.appendFileSync(logPath,entry);\nreturn [{json:{logged:true,logPath}}];"
      },
      "id": "ds-log",
      "name": "Log Sweep Result",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        860,
        300
      ]
    }
  ],
  "connections": {
    "Daily 9am": {
      "main": [
        [
          {
            "node": "Build Sweep Prompt",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Sweep Prompt": {
      "main": [
        [
          {
            "node": "Wake Master Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wake Master Agent": {
      "main": [
        [
          {
            "node": "Log Sweep Result",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "errorWorkflow": "tier1errorhandl11"
  }
}