{
  "version": "3.16",
  "name": "ThemeCustomize",
  "description": "Customize project theme: regenerate .vth theme tokens and cascade-update all components that use theme references.",
  "sectionMerge": true,
  "registry": {
    "params": [
      "themeRequest(STRING)",
      "currentMeta(OBJECT)"
    ],
    "services": [],
    "apis": [],
    "components": [],
    "vars": [
      "$currentTheme(STRING)",
      "$newTheme(STRING)",
      "$affectedComponents(OBJECT)",
      "$updatedFiles(OBJECT)"
    ],
    "files": {
      "inputs": [
        ".vl-code/ProjectMeta.json",
        "Theme/*"
      ],
      "artifacts": [
        "Theme/*",
        "ExtComponents/*",
        "Sections/*"
      ]
    },
    "docs": {
      "1": "VL Syntax Rules",
      "101": "Agent-GenTheme-Prompt"
    }
  },
  "steps": [
    {
      "id": "LLM_010_AnalyzeTheme",
      "meta": {
        "title": "1. Analyze current theme and plan changes"
      },
      "in": {
        "docs": [
          "1"
        ],
        "max_tokens": 32768,
        "messages": [
          {
            "role": "user",
            "content": "Current ProjectMeta:"
          },
          {
            "role": "user",
            "content": "=currentMeta"
          },
          {
            "role": "user",
            "content": "Theme customization request:"
          },
          {
            "role": "user",
            "content": "=themeRequest"
          },
          {
            "role": "user",
            "content": "Analyze the current theme and plan the changes. Return JSON with: tokenChanges([{token, oldValue, newValue}]), affectedFiles([{file, reason}]), summary(STRING)."
          }
        ],
        "output_config": {
          "format": {
            "type": "json_object"
          }
        }
      },
      "out": {
        "$affectedComponents": "=_result.affectedFiles"
      },
      "next": "LLM_020_GenTheme"
    },
    {
      "id": "LLM_020_GenTheme",
      "meta": {
        "title": "2. Regenerate theme file"
      },
      "in": {
        "docs": [
          "1",
          "101"
        ],
        "max_tokens": 32768,
        "stream": true,
        "readFiles": [
          "=currentMeta.theme.file || currentMeta.config.themeFile || 'Theme/Theme.vth'"
        ],
        "messages": [
          {
            "role": "user",
            "content": "Current ProjectMeta:"
          },
          {
            "role": "user",
            "content": "=currentMeta"
          },
          {
            "role": "user",
            "content": "Theme customization request:"
          },
          {
            "role": "user",
            "content": "=themeRequest"
          },
          {
            "role": "user",
            "content": "Current theme file path:"
          },
          {
            "role": "user",
            "content": "=currentMeta.theme.file || currentMeta.config.themeFile || 'Theme/Theme.vth'"
          },
          {
            "role": "user",
            "content": "Generate the COMPLETE updated .vth theme file with the requested changes applied. Preserve unaffected tokens and structure.\n\nIMPORTANT: The file MUST start with '// VL_VERSION:3.7' as the first non-empty line."
          }
        ]
      },
      "out": {
        "$newTheme": "=_result",
        "/{currentMeta.theme.file || currentMeta.config.themeFile || 'Theme/Theme.vth'}": "=_result"
      },
      "next": "Branch_NeedCascade"
    },
    {
      "id": "Branch_NeedCascade",
      "meta": {
        "title": "3. Check if cascade updates needed"
      },
      "cases": [
        {
          "condition": "=$affectedComponents.length > 0",
          "next": "Loop_UpdateFiles"
        }
      ],
      "default": "Stop_Done"
    },
    {
      "id": "Loop_UpdateFiles",
      "meta": {
        "title": "3a. Cascade-update affected files"
      },
      "source": "=$affectedComponents",
      "children": [
        "LLM_030_UpdateFile"
      ],
      "next": "Stop_Done"
    },
    {
      "id": "LLM_030_UpdateFile",
      "meta": {
        "title": "Update: =_item.file"
      },
      "in": {
        "docs": [
          "1"
        ],
        "max_tokens": 32768,
        "stream": true,
        "readFiles": [
          "=_item.file"
        ],
        "messages": [
          {
            "role": "user",
            "content": "New Theme:"
          },
          {
            "role": "user",
            "content": "=$newTheme"
          },
          {
            "role": "user",
            "content": "Update this file to use the new theme tokens. Use sectionMerge semantics: preserve all unaffected logic/layout and only modify the theme-related parts that need changing."
          },
          {
            "role": "user",
            "content": "File: =_item.file"
          },
          {
            "role": "user",
            "content": "Reason: =_item.reason"
          },
          {
            "role": "user",
            "content": "Output the COMPLETE updated file. Preserve the existing file shape and start VL source files with '// VL_VERSION:3.7'."
          }
        ]
      },
      "out": {
        "/{_item.file}": "=_result"
      },
      "onError": "skip"
    },
    {
      "id": "Stop_Done",
      "meta": {
        "title": "Done — Theme customized"
      }
    }
  ]
}
