{
  "name": "WF-006-script-generation",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "*/30 * * * *"
            }
          ]
        }
      },
      "id": "c60600000-0006-0006-0006-000000000001",
      "name": "Schedule 30min",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        240,
        400
      ]
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "SELECT v.* FROM v_assets_ready_for_scripts v WHERE NOT EXISTS (SELECT 1 FROM scripts s WHERE s.asset_id = v.id AND s.platform = 'youtube_long') LIMIT 1",
        "options": {}
      },
      "id": "c60600000-0006-0006-0006-000000000002",
      "name": "Poll Asset Needing Scripts",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        460,
        400
      ],
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "conditions": [
            {
              "leftValue": "={{ $json.id }}",
              "rightValue": "",
              "operator": {
                "type": "any",
                "operation": "exists"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "c60600000-0006-0006-0006-000000000003",
      "name": "Has Asset?",
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2.2,
      "position": [
        680,
        400
      ]
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "SELECT pv.system_prompt, pv.user_prompt_template, pv.model_params FROM prompt_versions pv JOIN prompts p ON p.id = pv.prompt_id WHERE p.name = 'script_youtube_long' AND pv.version = p.current_version AND p.is_active = true LIMIT 1",
        "options": {}
      },
      "id": "c60600000-0006-0006-0006-000000000004",
      "name": "Load Long Prompt",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        900,
        300
      ],
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const prompt = $input.item.json;\nconst asset = $('Has Asset?').item.json;\n\nconst formatList = (arr) => (arr || []).map(x => '- ' + (x.content || x.text || JSON.stringify(x))).join('\\n');\nconst longCta = (asset.cta_variations || []).find(c => c.platform === 'youtube_long') || {};\nconst curiosityHook = (asset.hook_variations || []).find(h => h.type === 'curiosity-gap') || (asset.hook_variations || [])[0] || {};\n\nconst userPrompt = (prompt.user_prompt_template || '')\n  .replace('{{ topic.title }}', asset.topic_title || '')\n  .replace('{{ asset.core_premise }}', asset.core_premise || '')\n  .replace('{{ asset.hook_variations[0].text }}', (asset.hook_variations || [])[0]?.text || '')\n  .replace('{{ asset.story_arc.setup }}', asset.story_arc?.setup || '')\n  .replace('{{ asset.story_arc.inciting_incident }}', asset.story_arc?.inciting_incident || '')\n  .replace('{{ asset.story_arc.climax }}', asset.story_arc?.climax || '')\n  .replace('{{ asset.story_arc.resolution }}', asset.story_arc?.resolution || '')\n  .replace('{{ asset.story_arc.key_takeaway }}', asset.story_arc?.key_takeaway || '')\n  .replace('{{ asset.facts | format_list }}', formatList(asset.facts))\n  .replace('{{ asset.statistics | format_list }}', formatList(asset.statistics))\n  .replace('{{ asset.quotes | format_list }}', formatList(asset.quotes))\n  .replace('{{ asset.cta_variations[youtube_long].text }}', longCta.text || '');\n\nreturn [{\n  json: {\n    asset_id: asset.id,\n    channel_id: asset.channel_id,\n    topic_title: asset.topic_title,\n    system_prompt: prompt.system_prompt,\n    user_prompt: userPrompt,\n    task_type: 'script_generate',\n    output_format: 'text',\n    max_tokens: (prompt.model_params && prompt.model_params.max_tokens) || 3500,\n    temperature: (prompt.model_params && prompt.model_params.temperature) ?? 0.7,\n    workflow_name: 'WF-006-script-generation'\n  }\n}];"
      },
      "id": "c60600000-0006-0006-0006-000000000005",
      "name": "Build Long Prompt",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1120,
        300
      ]
    },
    {
      "parameters": {
        "workflowId": {
          "__rl": true,
          "value": "2673a82a-e155-4d0c-85b4-92922b74849d",
          "mode": "id"
        },
        "options": {}
      },
      "id": "c60600000-0006-0006-0006-000000000006",
      "name": "Call SUB-001 Long",
      "type": "n8n-nodes-base.executeWorkflow",
      "typeVersion": 1.1,
      "position": [
        1340,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "const r = $input.item.json;\nconst ctx = $('Build Long Prompt').item.json;\nconst text = (r.response_text || '').trim();\nconst wordCount = text ? text.split(/\\s+/).length : 0;\nconst valid = r.success && wordCount >= 500 && wordCount <= 1800;\n\nreturn [{\n  json: {\n    valid,\n    success: r.success,\n    word_count: wordCount,\n    script_text: text,\n    asset_id: ctx.asset_id,\n    channel_id: ctx.channel_id,\n    topic_title: ctx.topic_title,\n    provider_used: r.provider_name || null,\n    generation_cost_usd: r.cost_usd || 0,\n    error: r.success ? null : r.error\n  }\n}];"
      },
      "id": "c60600000-0006-0006-0006-000000000007",
      "name": "Validate Long Script",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1560,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "leftValue": "={{ $json.valid }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "c60600000-0006-0006-0006-000000000008",
      "name": "Long Valid?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1780,
        300
      ]
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "=INSERT INTO scripts (asset_id, channel_id, platform, title, script_text, word_count, status, provider_used, generation_cost_usd) VALUES ({{ $json.asset_id }}, {{ $json.channel_id }}, 'youtube_long', $q${{ $json.topic_title || 'Untitled' }}$q$, $q${{ $json.script_text }}$q$, {{ $json.word_count }}, 'approved', $q${{ $json.provider_used || 'unknown' }}$q$, {{ $json.generation_cost_usd }}) RETURNING id",
        "options": {}
      },
      "id": "c60600000-0006-0006-0006-000000000009",
      "name": "Insert Long Script",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        2000,
        220
      ],
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "return [{ json: {\n  workflow_name: 'WF-006-script-generation',\n  execution_id: String($execution.id),\n  node_name: 'Validate Long Script',\n  error_type: 'validation_failed',\n  error_message: `youtube_long script failed validation: ${$json.error || ('word_count ' + $json.word_count + ' out of range')}`,\n  payload: { asset_id: $json.asset_id }\n} }];"
      },
      "id": "c60600000-0006-0006-0006-000000000010",
      "name": "Build DLQ Payload Long",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        2000,
        380
      ]
    },
    {
      "parameters": {
        "workflowId": {
          "__rl": true,
          "value": "sub002-dead-letter-queue-0000000",
          "mode": "id"
        },
        "options": {}
      },
      "id": "c60600000-0006-0006-0006-000000000011",
      "name": "Log to SUB-002 Long",
      "type": "n8n-nodes-base.executeWorkflow",
      "typeVersion": 1.1,
      "position": [
        2220,
        380
      ]
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "SELECT pv.system_prompt, pv.user_prompt_template, pv.model_params FROM prompt_versions pv JOIN prompts p ON p.id = pv.prompt_id WHERE p.name = 'script_youtube_short' AND pv.version = p.current_version AND p.is_active = true LIMIT 1",
        "options": {}
      },
      "id": "c60600000-0006-0006-0006-000000000012",
      "name": "Load Short Prompt",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        2440,
        300
      ],
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const prompt = $input.item.json;\nconst asset = $('Has Asset?').item.json;\n\nconst shortCta = (asset.cta_variations || []).find(c => c.platform === 'youtube_short') || {};\nconst curiosityHook = (asset.hook_variations || []).find(h => h.type === 'curiosity-gap') || (asset.hook_variations || [])[0] || {};\nconst firstStat = (asset.statistics || [])[0] || {};\n\nconst userPrompt = (prompt.user_prompt_template || '')\n  .replace('{{ topic.title }}', asset.topic_title || '')\n  .replace(\"{{ asset.hook_variations | find(type='curiosity-gap') | .text }}\", curiosityHook.text || '')\n  .replace('{{ asset.story_arc.key_takeaway }}', asset.story_arc?.key_takeaway || '')\n  .replace('{{ asset.statistics[0].content }}', firstStat.content || '')\n  .replace('{{ asset.cta_variations[youtube_short].text }}', shortCta.text || '');\n\nreturn [{\n  json: {\n    asset_id: asset.id,\n    channel_id: asset.channel_id,\n    topic_title: asset.topic_title,\n    system_prompt: prompt.system_prompt,\n    user_prompt: userPrompt,\n    task_type: 'script_generate',\n    output_format: 'text',\n    max_tokens: (prompt.model_params && prompt.model_params.max_tokens) || 500,\n    temperature: (prompt.model_params && prompt.model_params.temperature) ?? 0.6,\n    workflow_name: 'WF-006-script-generation'\n  }\n}];"
      },
      "id": "c60600000-0006-0006-0006-000000000013",
      "name": "Build Short Prompt",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        2660,
        300
      ]
    },
    {
      "parameters": {
        "workflowId": {
          "__rl": true,
          "value": "2673a82a-e155-4d0c-85b4-92922b74849d",
          "mode": "id"
        },
        "options": {}
      },
      "id": "c60600000-0006-0006-0006-000000000014",
      "name": "Call SUB-001 Short",
      "type": "n8n-nodes-base.executeWorkflow",
      "typeVersion": 1.1,
      "position": [
        2880,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "const r = $input.item.json;\nconst ctx = $('Build Short Prompt').item.json;\nconst text = (r.response_text || '').trim();\nconst wordCount = text ? text.split(/\\s+/).length : 0;\nconst valid = r.success && wordCount >= 120 && wordCount <= 180;\n\nreturn [{\n  json: {\n    valid,\n    success: r.success,\n    word_count: wordCount,\n    script_text: text,\n    asset_id: ctx.asset_id,\n    channel_id: ctx.channel_id,\n    topic_title: ctx.topic_title,\n    provider_used: r.provider_name || null,\n    generation_cost_usd: r.cost_usd || 0,\n    error: r.success ? null : r.error\n  }\n}];"
      },
      "id": "c60600000-0006-0006-0006-000000000015",
      "name": "Validate Short Script",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        3100,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "leftValue": "={{ $json.valid }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "c60600000-0006-0006-0006-000000000016",
      "name": "Short Valid?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        3320,
        300
      ]
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "=INSERT INTO scripts (asset_id, channel_id, platform, title, script_text, word_count, status, provider_used, generation_cost_usd) VALUES ({{ $json.asset_id }}, {{ $json.channel_id }}, 'youtube_short', $q${{ $json.topic_title || 'Untitled' }}$q$, $q${{ $json.script_text }}$q$, {{ $json.word_count }}, 'approved', $q${{ $json.provider_used || 'unknown' }}$q$, {{ $json.generation_cost_usd }}) RETURNING id",
        "options": {}
      },
      "id": "c60600000-0006-0006-0006-000000000017",
      "name": "Insert Short Script",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        3540,
        220
      ],
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "=INSERT INTO workflow_logs (workflow_name, execution_id, status, input_summary, output_summary) VALUES ('WF-006-script-generation', '{{ $execution.id }}', 'completed', '{{ JSON.stringify({ asset_id: $('Validate Short Script').item.json.asset_id }) }}'::jsonb, '{{ JSON.stringify({ long_words: $('Validate Long Script').item.json.word_count, short_words: $('Validate Short Script').item.json.word_count }) }}'::jsonb)",
        "options": {}
      },
      "id": "c60600000-0006-0006-0006-000000000018",
      "name": "Log Result Success",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        3760,
        220
      ],
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "return [{ json: {\n  workflow_name: 'WF-006-script-generation',\n  execution_id: String($execution.id),\n  node_name: 'Validate Short Script',\n  error_type: 'validation_failed',\n  error_message: `youtube_short script failed validation: ${$json.error || ('word_count ' + $json.word_count + ' out of range')}`,\n  payload: { asset_id: $json.asset_id }\n} }];"
      },
      "id": "c60600000-0006-0006-0006-000000000019",
      "name": "Build DLQ Payload Short",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        3540,
        380
      ]
    },
    {
      "parameters": {
        "workflowId": {
          "__rl": true,
          "value": "sub002-dead-letter-queue-0000000",
          "mode": "id"
        },
        "options": {}
      },
      "id": "c60600000-0006-0006-0006-000000000020",
      "name": "Log to SUB-002 Short",
      "type": "n8n-nodes-base.executeWorkflow",
      "typeVersion": 1.1,
      "position": [
        3760,
        380
      ]
    },
    {
      "parameters": {
        "jsCode": "const v = $input.item.json;\nconst base = $('Build Long Prompt').item.json;\n\nconst gapNote = v.word_count < 500\n  ? `it was only ${v.word_count} words \u2014 expand it with more B-roll detail, facts, and statistics until it reaches the target`\n  : `it was ${v.word_count} words \u2014 trim it down to fit the target`;\n\nconst correctivePrompt = base.user_prompt +\n  `\\n\\nPrevious attempt failed: ${v.error || ('word_count ' + v.word_count + ' out of the required 500-1800 range')}. Rewrite the FULL script from scratch \u2014 ${gapNote}. Requirement is strictly 500-1800 words total, do not stop early.`;\n\nreturn [{\n  json: {\n    asset_id: base.asset_id,\n    channel_id: base.channel_id,\n    topic_title: base.topic_title,\n    system_prompt: base.system_prompt,\n    user_prompt: correctivePrompt,\n    task_type: 'script_generate',\n    output_format: 'text',\n    max_tokens: base.max_tokens,\n    temperature: base.temperature,\n    workflow_name: 'WF-006-script-generation'\n  }\n}];"
      },
      "id": "c60600000-0006-0006-0006-000000000020",
      "name": "Build Corrective Prompt Long",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1780,
        420
      ]
    },
    {
      "parameters": {
        "workflowId": {
          "__rl": true,
          "value": "2673a82a-e155-4d0c-85b4-92922b74849d",
          "mode": "id"
        },
        "options": {}
      },
      "id": "c60600000-0006-0006-0006-000000000021",
      "name": "Call SUB-001 Long Pass2",
      "type": "n8n-nodes-base.executeWorkflow",
      "typeVersion": 1.1,
      "position": [
        2000,
        420
      ]
    },
    {
      "parameters": {
        "jsCode": "const r = $input.item.json;\nconst ctx = $('Build Corrective Prompt Long').item.json;\nconst text = (r.response_text || '').trim();\nconst wordCount = text ? text.split(/\\s+/).length : 0;\nconst valid = r.success && wordCount >= 500 && wordCount <= 1800;\n\nreturn [{\n  json: {\n    valid,\n    success: r.success,\n    word_count: wordCount,\n    script_text: text,\n    asset_id: ctx.asset_id,\n    channel_id: ctx.channel_id,\n    topic_title: ctx.topic_title,\n    provider_used: r.provider_name || null,\n    generation_cost_usd: r.cost_usd || 0,\n    error: r.success ? null : r.error\n  }\n}];"
      },
      "id": "c60600000-0006-0006-0006-000000000022",
      "name": "Validate Long Script Pass2",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        2220,
        420
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "leftValue": "={{ $json.valid }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "c60600000-0006-0006-0006-000000000023",
      "name": "Long Valid Pass2?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        2440,
        420
      ]
    },
    {
      "parameters": {
        "jsCode": "const v = $input.item.json;\nconst base = $('Build Short Prompt').item.json;\n\nconst gapNote = v.word_count < 120\n  ? `it was only ${v.word_count} words \u2014 expand it slightly`\n  : `it was ${v.word_count} words \u2014 trim it down to fit the target`;\n\nconst correctivePrompt = base.user_prompt +\n  `\\n\\nPrevious attempt failed: ${v.error || ('word_count ' + v.word_count + ' out of the required 120-180 range')}. Rewrite the FULL script from scratch \u2014 ${gapNote}. Requirement is strictly 120-180 words total.`;\n\nreturn [{\n  json: {\n    asset_id: base.asset_id,\n    channel_id: base.channel_id,\n    topic_title: base.topic_title,\n    system_prompt: base.system_prompt,\n    user_prompt: correctivePrompt,\n    task_type: 'script_generate',\n    output_format: 'text',\n    max_tokens: base.max_tokens,\n    temperature: base.temperature,\n    workflow_name: 'WF-006-script-generation'\n  }\n}];"
      },
      "id": "c60600000-0006-0006-0006-000000000024",
      "name": "Build Corrective Prompt Short",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1780,
        780
      ]
    },
    {
      "parameters": {
        "workflowId": {
          "__rl": true,
          "value": "2673a82a-e155-4d0c-85b4-92922b74849d",
          "mode": "id"
        },
        "options": {}
      },
      "id": "c60600000-0006-0006-0006-000000000025",
      "name": "Call SUB-001 Short Pass2",
      "type": "n8n-nodes-base.executeWorkflow",
      "typeVersion": 1.1,
      "position": [
        2000,
        780
      ]
    },
    {
      "parameters": {
        "jsCode": "const r = $input.item.json;\nconst ctx = $('Build Corrective Prompt Short').item.json;\nconst text = (r.response_text || '').trim();\nconst wordCount = text ? text.split(/\\s+/).length : 0;\nconst valid = r.success && wordCount >= 120 && wordCount <= 180;\n\nreturn [{\n  json: {\n    valid,\n    success: r.success,\n    word_count: wordCount,\n    script_text: text,\n    asset_id: ctx.asset_id,\n    channel_id: ctx.channel_id,\n    topic_title: ctx.topic_title,\n    provider_used: r.provider_name || null,\n    generation_cost_usd: r.cost_usd || 0,\n    error: r.success ? null : r.error\n  }\n}];"
      },
      "id": "c60600000-0006-0006-0006-000000000026",
      "name": "Validate Short Script Pass2",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        2220,
        780
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "leftValue": "={{ $json.valid }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "c60600000-0006-0006-0006-000000000027",
      "name": "Short Valid Pass2?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        2440,
        780
      ]
    }
  ],
  "connections": {
    "Schedule 30min": {
      "main": [
        [
          {
            "node": "Poll Asset Needing Scripts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Poll Asset Needing Scripts": {
      "main": [
        [
          {
            "node": "Has Asset?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Has Asset?": {
      "main": [
        [
          {
            "node": "Load Long Prompt",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Load Long Prompt": {
      "main": [
        [
          {
            "node": "Build Long Prompt",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Long Prompt": {
      "main": [
        [
          {
            "node": "Call SUB-001 Long",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Call SUB-001 Long": {
      "main": [
        [
          {
            "node": "Validate Long Script",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate Long Script": {
      "main": [
        [
          {
            "node": "Long Valid?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Long Valid?": {
      "main": [
        [
          {
            "node": "Insert Long Script",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Build Corrective Prompt Long",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Insert Long Script": {
      "main": [
        [
          {
            "node": "Load Short Prompt",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build DLQ Payload Long": {
      "main": [
        [
          {
            "node": "Log to SUB-002 Long",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Load Short Prompt": {
      "main": [
        [
          {
            "node": "Build Short Prompt",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Short Prompt": {
      "main": [
        [
          {
            "node": "Call SUB-001 Short",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Call SUB-001 Short": {
      "main": [
        [
          {
            "node": "Validate Short Script",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate Short Script": {
      "main": [
        [
          {
            "node": "Short Valid?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Short Valid?": {
      "main": [
        [
          {
            "node": "Insert Short Script",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Build Corrective Prompt Short",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Insert Short Script": {
      "main": [
        [
          {
            "node": "Log Result Success",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log to SUB-002 Short": {
      "main": []
    },
    "Build Corrective Prompt Long": {
      "main": [
        [
          {
            "node": "Call SUB-001 Long Pass2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Call SUB-001 Long Pass2": {
      "main": [
        [
          {
            "node": "Validate Long Script Pass2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate Long Script Pass2": {
      "main": [
        [
          {
            "node": "Long Valid Pass2?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Long Valid Pass2?": {
      "main": [
        [
          {
            "node": "Insert Long Script",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Build DLQ Payload Long",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Corrective Prompt Short": {
      "main": [
        [
          {
            "node": "Call SUB-001 Short Pass2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Call SUB-001 Short Pass2": {
      "main": [
        [
          {
            "node": "Validate Short Script Pass2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate Short Script Pass2": {
      "main": [
        [
          {
            "node": "Short Valid Pass2?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Short Valid Pass2?": {
      "main": [
        [
          {
            "node": "Insert Short Script",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Build DLQ Payload Short",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "id": "wf006-script-generation-0000000"
}